Math.Net Symbolics: How to simplify an expression like: "0.0+1.0*x -2*y^1.0"

361 Views Asked by At

I'm looking for a method in Math.Net Symbolics that can eliminate terms that are not needed for UI purposes.

Since these expressions are generated automatically I can't control some of the artifacts it creates.

I noticed that Expand() flattens the expression tree which helps since my expressions tend to get pretty deep, but once I reach the expression in the title I can't find any other method to eliminate redundant operations such as "0 + ", "^ 1.0", "1 * x", "0 * x", "^ 0" etc...

If there's no method in Math.net Symbolics to do this, is it possible to extend it to implement such functionality?

Edit: Should have added an example (thank's Xerillio for the tip about floating numbers):

using Expr = MathNet.Symbolics.SymbolicExpression;
public static void Main()
{
    var c = (Expr)(double)0;
    var a = (Expr)(double)1;
    var x = Expr.Variable("X1");
    var ee = c + a * x.Pow(a);
    
    Console.WriteLine(ee);
}

With that example the result would be "0.0 + 1.0*X1^1.0", but using integers instead it becomes "X1" which was what I needed.

Thank you again Xerillio.

0

There are 0 best solutions below