Re: easy(?) question on manipulating expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg38629] Re: [mg38572] easy(?) question on manipulating expressions
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Wed, 1 Jan 2003 03:40:16 -0500 (EST)
- References: <200212270715.CAA01084@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Diligent Sp*m Avoider wrote: > > Let's say I have an equation a = (1+x) Sin[1+x], and I would like to set > a new variable b = (1+x). What do I have to tell Mathematica so that it > represents the first equation as a = b Sin[b]? > > Keep in mind that equation a may not be arrayed so simply; it might be > in the form Sin[1+x] + xSin[1+x] or worse; Mathematica will have to > search for ways to do the replacement with b. > > I've been browsing through The Mathematica Book, but I can't find any > discussion of this. > > Thank you in advance for any help. > > -Michael Stern One tactic uses PolynomialReduce. A previous response to this sort of question, with more detail, may be found at http://forums.wolfram.com/mathgroup/archive/2002/Jan/msg00354.html The code used therein is as below. replacementFunction[expr_,rep_,vars_] := If[ PolynomialQ[Numerator[expr],vars] && PolynomialQ[Denominator[expr],vars], PolynomialReduce[expr, rep, vars][[2]], expr] On your example it does pretty much what you would like. In[3]:= expr = Sin[1+x] + x*Sin[1+x]; In[4]:= InputForm[MapAll[replacementFunction[#, 1+x-b, x]&, expr]] Out[4]//InputForm= b*Sin[b] Daniel Lichtblau Wolfram research