       Re: Is mathematica able to transform formula

• To: mathgroup at smc.vnet.net
• Subject: [mg71891] Re: Is mathematica able to transform formula
• From: "Mark Westwood" <markc.westwood at gmail.com>
• Date: Sat, 2 Dec 2006 05:11:42 -0500 (EST)
• References: <ekp4gh\$28t\$1@smc.vnet.net>

```Hi Pujo

Mathematica will need some help from you.  One of the issues is that
Mathematica's expressions are one-way rewrite rules, they state that
the thing to the left of the = can be replaced wherever it occurs by
the thing to the right.  So you could write:

In:= c=a b
Out:= a b

(* by default M uses spaces to indicate multiplication, on input or
output *)

In:= f = c+5
Out:= 5+a b

(* M outputs expressions in canonical order, canonical according to M
that is *)

To do the sort of thing which I think you might be trying to achieve,
you should investigate Patterns and ReplaceAll and associated
functions. There are lot of good examples in the on-line Help.  For
example, one way to achieve what you want might be:

In:= f = a b + 5 /. (a b) -> c
Out:= 5+2c

but this isn't a lot of reward for all your typing.

To do what you apparently want to do, and make a replacement which runs
from right to left you could do something VERY DANGEROUS INDEED.  Try:

In:= Unprotect[Times]

In:= Times[a,b] ^= c

In:= Protect[Times]

and now when you type

In:= f = a b + 5

you get

Out:= 5 + c

Have a look in the documentation for Protect / Unprotect, UpValues and
DownValues, and read all the stuff which tells you why it is a VERY BAD
IDEA to such basic functionality of Mathematica.  Most of us only do
it, oh, just about every day :-).  A generally safer approach is to
define Unprotected functions of your own which do what you want and to
use them instead of altered core functions.

Good luck.

Mark Westwood

ajikoe at gmail.com wrote:
> Hello,
>
> I have a question:
> if I have a symbolic expression:
> f  = a * b + 5
> c = a * b
>
> Can Mathematica builds f = c + 5 for me ?
>
>
> Sincerely Yours,
> pujo

```

• Prev by Date: Re: NIntegrate that upper limit is infinite
• Next by Date: A serious error?
• Previous by thread: RE: Is mathematica able to transform formula
• Next by thread: Ask Mathematica to sub for a long expression