Re: Adding new rules to Simplify
- To: mathgroup at smc.vnet.net
- Subject: [mg56387] Re: Adding new rules to Simplify
- From: Peter Pein <petsie at arcor.de>
- Date: Sat, 23 Apr 2005 01:16:23 -0400 (EDT)
- References: <27457333.1114080708731.JavaMail.jakarta@nitrogen.mathforum.org> <d4al4s$iv0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
John Billingham wrote: > Here's another one! > > r1[x_ /; ! FreeQ[x, f]] := x /. f[y_] -> a[y]/b[y]; > r1[x_] := x; > > r2[x_ /; ! FreeQ[x, g]] := x /. g[y_] -> b[y]/a[y]; > r2[x_] := x; > > Simplify[f[X] g[X], TransformationFunctions -> {r1, r2}] > > gives > > f(X) g(X) > > > I would have hoped to get 1 here, particularly since > > r1[r2[f[X]g[X]]] > > gives me 1 as expected! > > So I tell it to Simplify using just two rules, the successive application of which gives 1, but Mathematica fails to simplify at all. > > What's going on here?? > > John > Hi John, Simplify doesn't apply r1 and r2 simultaneous. If Simplify applies e.g. r1 to f[x]g[x], this product becomes a[x]g[x]/b[x] which is assumed (correctly) to be more complex. You either have to use an own ComplexityFunction, or you use only one replacement r3: In[6]:= Simplify[h, TransformationFunctions -> {r1, r2}, ComplexityFunction -> (LeafCount[#1] + 10^6*Count[#1, f | g, Heads -> True] & )] Out[6]= 1 In[7]:= r3[expr:(p_.)*(f | g)[y_] + (q_.)] := expr /. {f -> (a[#1]/b[#1] & ), g -> (b[#1]/a[#1] & )} In[8]:= Simplify[h, TransformationFunctions -> {r3}] Out[8]= 1 -- Peter Pein Berlin