开发者

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/开发者_StackOverflowx = (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!


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)  *)


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜