mathnet / mathnet-symbolics

Math.NET Symbolics
http://symbolics.mathdotnet.com
MIT License
341 stars 66 forks source link

Rational.Simplify and (2 - x)/(1 - x) vs (-2 + x)/(-1 + x) #32

Open dharmatech opened 7 years ago

dharmatech commented 7 years ago

Here's a simple Mathematica evaluation:

image

Note that l[f[x]] // Simplify returns the same expression as m[x] // Simplify.

Here's the equivalent in Symbolics/C#:

                Expression f(Expression x) => 2 - x;
                Expression g(Expression x) => 2 / x;
                Expression h(Expression x) => f(g(x));
                Expression l(Expression x) => g(h(x));
                Expression m(Expression x) => h(h(x));

                {
                    var x = Expression.Symbol("x");

                    Console.WriteLine(Infix.Format(Rational.Simplify(x, l(f(x)))));
                    Console.WriteLine(Infix.Format(Rational.Simplify(x, m(x))));
                }

It outputs the following:

(2 - x)/(1 - x)
(-2 + x)/(-1 + x)

Is there a simplification routine in Symbolics which will simplify both cases to the same expression?

Thanks!

(PS: I've been experimenting a bit with Symbolics in C# and its a really nice system. Thanks Christoph!)

cdrnet commented 7 years ago

I don't think we have anything simple to use, but agree that we should normalize (on Simplify - not automatic simplification). A rule could be that the leading coefficient of the numerator shall be positive.