asc-community/AngouriMath

Simplify() question

pandrei1 opened this issue · 3 comments

Is there a way to simplify this expression?

Entity e = "(1/9 + 1 / 1.7522123893805313)*x";
var e1 = e.Simplify();
WriteLine(e1);

The output is "10.7522123893805313 * x / (1.7522123893805313 * 9)". This is correct, but I wished it was only a constant times x.

Thank you for your time. Great project!

Hi! In simple cases you can use e.Evaled:

image

You can also check out this method if you need to extract the coefficient by a certain variable (it tries to represent your function as an n-power polynomial and retrieve coefficients for you)

I see. However, the above expression is coming after a Simplify(). Here is a simple version of the code. The first one works perfectly, however the second one (which is the one I have) does not work. Should I first convert to string and then parse as Entity and use .Evaled?

Entity e = "(1/9 + 1 / 1.7522123893805313)*x";
WriteLine(e.Evaled);
WriteLine(e.Simplify().Evaled);

Thank you.

No, just use the second version. Don't apply simplify, just use Evaled. I'm honestly not entirely sure why Simplify didn't work as expected there. I'm not at home right now, but you can check if Alternate() method returns a desired result