2

I am using Infix.Parse to parse equations like

apples + oranges = 2
Expression aleft = Infix.ParseOrThrow("apples + oranges");
Expression aright = Infix.ParseOrThrow("2");

Sometimes I need to parse fractional values, like

2.5*tax + income = 30.5

But this throws a System.Exception

Error in ...
(2.5)
  ^
Expecting: infix operator or ')'

There must be a way to handle such expressions in mathdotnet, but I cannot find it in the documentation. Can someone help?

shyamupa
  • 1,528
  • 4
  • 16
  • 24

1 Answers1

2

Algebraic expressions can contain integers and rational numbers, but not floating-point numbers (neither in actual algebra nor in Math.NET Symbolics). You can either use a symbol until evaluation or use exact rational numbers instead.

However, one could argue that "30.5" can be interpreted as a shorthand for "305/10", or "61/2" after auto-simplification. We could consider to extend the parser to automatically do this interpretation, maybe with a setting to turn it on/off. Could you open an issue on GitHub for this? Thanks!

So, to answer the actual question, until we've extended the parser you'll have to use rational numbers instead, e.g. 25/10*tax + income, which gets auto-simplified to income + (5/2)*tax.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34