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[1]:= c=a b Out[1]:= a b (* by default M uses spaces to indicate multiplication, on input or output *) In[2]:= f = c+5 Out[2]:= 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[6]:= f = a b + 5 /. (a b) -> c Out[6]:= 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[20]:= Unprotect[Times] In[21]:= Times[a,b] ^= c In[22]:= Protect[Times] and now when you type In[23]:= f = a b + 5 you get Out[23]:= 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