I'm currently working on a project where I'd like to reduce/simplyfy mathematic expressions as far as possible.
On first look, MathNet.Symbolics seemed to provide everything that I need for this job.
However, I came across some problems for which I cannot figure out how to solve them by myself.
I want Expressions of the form
"x + 2 * x"
to be merged into
"3 * x"
This works as long as the factors are no double-Values (which I currently convert by using Expression.Real(value)).
Once they are incorporated, things get messy. Here is some Console Output for different Expressions.
Since I am a new user, I cannot upload the sample solution. Is there any other way that I can provide it to you?
Parsing Expression from string:
Expression A: "x + 2 * (3/4)*x"...
Expression B: "x + 2 * (0.75)*x"...
x + 1,5*x
Expression C: x + 1r * x
x + 1*x
Expression D: 1r * x + 1r * x
Expression E: 0.7r * x + 0.3r * x is not merged:
0,3*x + 0,7*x
Expression F: 0.5r * x + 0.5r * x is merged:
Expression G: (1/4)r * x + (3/4)r * x is not merged:
0,25*x + 0,75*x
Expression H: (1/2)r * x + (2/4)r * x is merged:
Expression I: (1r/2r) * x + (2r/4r) * x is not:
(1*x)/2 + (2*x)/4
Is there a way to reduce these Expressions to 2 * x (or simply x for the later ones)?
Ideally, I'd want all terms that contain the same symbol (e.g. "x"), to be merged into a single term.