Re: Transforming (x-y)^2 into (x-y)*(x-y) ?
- To: mathgroup at smc.vnet.net
- Subject: [mg22609] Re: Transforming (x-y)^2 into (x-y)*(x-y) ?
- From: Leszek Sczaniecki <lsczan at home.com>
- Date: Tue, 14 Mar 2000 22:46:24 -0500 (EST)
- Organization: @Home Network
- References: <8aek8k$3de@smc.vnet.net> <8aj3nf$mr2@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Harald Giese wrote: > Axel Kowald wrote: > > > > I use Mathematica 4 to generate some equations which I export as C code (CForm). > > > > I would like to force Mathematica to export expressions like (x-y)^2 as > > (x-y)*(x-y), but I don't know how to achieve this in Mathematica. I tried > > several combinations of Hold (and its variants) and t_^2 -> t*t, but so > > far I had no luck. > > > > Hi Axel, > > You need to insert Hold: > > In[13]:=(x - y)^2 /. t_^2 -> Hold[t*t] > Out[13]=Hold[(x - y) (x - y)] > Actually, HoldForm might be more appropriate. In[314]:= (x - y)^2 /. t_^2 -> HoldForm[t*t] Out[314]= (x - y) (x - y) --Leszek Sczaniecki > > Regards, > Harald > -- > > Harald Giese > Email: giese at dkrz.de > Phone: +49 (0)40 42838 5796; Fax: +49 (0)40 5605724 > Institut fuer Meereskunde der Universitaet Hamburg > (Institute of Oceanography of the University of Hamburg) > Troplowitzstrasse 7, D-22529 Hamburg