Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force Mathematica to include user defined functions in Simplify and FullSimplify?

Let's say I have a relation r^2 = x^2 + y^2. Now suppose after a calculation i get a complicated output of x and y, but which could in theory be simplified a lot by using the above relation. How do I tell Mathematica to do that?

I'm referring to situations where replacement rules x^2+y^2 -> r^2 and using Simplify/FullSimplify with Assumptions won't work, e.g. if the output is x/y + y/x = (x^2+y^2)/(xy) = r^2/(xy).

Simplification works really well with built in functions but not with user defined functions! So essentially I would like my functions to be treated like the built in functions!

like image 549
H. Arponen Avatar asked May 07 '11 00:05

H. Arponen


2 Answers

I believe you are looking for TransformationFunctions.

f = # /. x^2 + y^2 -> r^2 &;

Simplify[x/y + y/x, TransformationFunctions -> {Automatic, f}]

(* Out=  r^2/(x y)  *)
like image 196
Mr.Wizard Avatar answered Sep 25 '22 07:09

Mr.Wizard


In the example you give

(x/y + y/x // Together) /. {x^2 + y^2 -> r^2}

==> r^2/(x y)

works. But I've learned that in many occasions replacements like this don't work. A tip I once got was to replace this replacement with one which has a more simpler LHS like: x^2 -> r^2-y^2 (or even x->Sqrt[r^2-y^2] if you know that the values of x and y allow this).

like image 39
Sjoerd C. de Vries Avatar answered Sep 23 '22 07:09

Sjoerd C. de Vries