How to get Mathematica to include user-defined functions in Simplify and FullSimplify?

Let's say that I have the relation r ^ 2 = x ^ 2 + y ^ 2. Now suppose that after the calculation I get the complex output of x and y, but which can theoretically be simplified using the above relation. How can I tell Mathematica about this?

I mean situations where replacement rules x ^ 2 + y ^ 2 β†’ r ^ 2 and using Simplify / FullSimplify with assumptions will not work, for example. if the output is x / y + y / x = (x ^ 2 + y ^ 2) / (xy) = r ^ 2 / (xy).

Simplification works very well with built-in functions, but not with certain functions! Therefore, I would like my functions to be treated as built-in functions!

+6
source share
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/(xy) *) 
+7
source

In the example you give

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

works. But I found out that in many cases such replacements do not work. The advice I once received was to replace this replacement with one that has a simpler LHS: x^2 -> r^2-y^2 (or even x->Sqrt[r^2-y^2] , if you know that the x and y values ​​allow this).

+2
source

Source: https://habr.com/ru/post/887495/


All Articles