MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Transforming (x-y)^2 into (x-y)*(x-y) ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22606] Re: Transforming (x-y)^2 into (x-y)*(x-y) ?
  • From: "John Yellott" <jyellott at email.msn.com>
  • Date: Tue, 14 Mar 2000 22:46:22 -0500 (EST)
  • References: <8aek8k$3de@smc.vnet.net> <8aj3nf$mr2@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Harald and Axel,

Let me recommend HoldForm.  In addition to the advantages of Hold, HoldForm
is stripped from the output.

CForm[ (p+q)^2(x-y)^2u^2 /. f_^2->HoldForm[f*f] ]

yields:    (p + q)*(p + q)*(u*u)*((x - y)*(x - y))

whereas

CForm[ (p+q)^2(x-y)^2u^2 /. f_^2->Hold[f*f] ]

Produces:    Hold((p + q)*(p + q))*Hold(u*u)*Hold((x - y)*(x - y))

"Harald Giese" <giese at ifm.uni-hamburg.de> wrote in message
news:8aj3nf$mr2 at smc.vnet.net...
> 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)]
>
> 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
>





  • Prev by Date: Re: N with n-digit precision for 6<n<17
  • Next by Date: Re: magnification issue
  • Previous by thread: Re: Transforming (x-y)^2 into (x-y)*(x-y) ?
  • Next by thread: new MathSource polyhedra