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?

This is partially by design, although that doesn’t mean we cannot improve it.

In essence, integers and rationals are exact expressions which can be manipulated algebraically in a consistent way. Floating point numbers, however, are not. Originally Symbolics did not even support them. Expression like “1.5” used to be parsed into “3/2” and then handled normally, with the usual expected simplifications.

This was changed lately with the introduction of arbitrary real constants. But note that they are still not considered as “numbers”, but as special kind of constant, with a few additional automatic simplification rules. Admittedly the behavior is now not entirely consistent nor that helpful in practice. Looking back I’m not sure this was a good decision. Maybe we should provide an option on the infix parser?

thanks for your reply. I attached a sample project (without nuget-files) to this post, that shows some of the working- and not working combinations of Int, Rationals and Reals.

Is it possible to add an option that makes MathNet interpret all numbers as Real, so that the respective Terms are merged?
Ideally, I’d prefer this to not only work with parsed Strings, but also with “general” MathNet-Epressions. I assume that it is much more efficient to not having to parse all Expressions from Strings.