mathnet/mathnet-symbolics

Rational.Simplify gets stuck in endless loop

mkruijver opened this issue · 3 comments

When attempting to simplify a fraction using Rational.Simplify, the library seems to get stuck in an endless loop:

var numerator = Infix.ParseOrThrow("0.1*x");
var denominator = Infix.ParseOrThrow("x+x^2");
var fraction = numerator / denominator;

var x = Infix.ParseOrThrow("x");
var simplified = Rational.Simplify(x, fraction); // hangs

There must be something wrong with how we handle approximations like 0.1 there. Indeed, when replacing 0.1*x with x/10 simplify returns 1/(10 + 10*x) as expected - but of course that's a very different expression and thus simplification problem. I guess the desired expression would be something along the lines of 0.1/(1.0 + x)?

This is fixed in v0.22.0. Thanks for reporting!

Thanks for the fix. The above example now works fine. Unfortunately I still experience problems with slightly different problems, e.g.:

var numerator = Infix.ParseOrThrow("a + a*b + a^2*b + a*b^2");
var denominator = Infix.ParseOrThrow("a + a*b + a^2*b + a^2");

var fraction = numerator / denominator;

var simplified1 = Rational.Simplify(Infix.ParseOrThrow("a"), fraction); // result is a long expression
var simplified2 = Rational.Simplify(Infix.ParseOrThrow("b"), simplified1); // does not seem to finish

For this (and also the earlier example) the exact output is not that important to me, however it is important in my use case that the software does not hang unexpectedly.