Mathematical expression evaluator which incorporates units of measure

469 Views Asked by At

Similar to this question but different. Lots of good answers there, but none do Units of Measure.

How about a .NET compatible (even through COM, if necessary) mathematical expression evaluator which incorporates units of measure?

I've tried NCalc for unitless expressions. I know F# can do it in code. Google Calculator is amazing but unavailable as a supported API and is inappropriate in its service-basis for this project.

Here's an interesting paper on the subject. It covers Units of Measure calculations but leaves out "additive constant" conversions such as Celsius to Fahrenheit (by their conclusion). And it brings up a good point about substance. "Gallons of gasoline" vs "gallons of milk". The units are the same, but the substance is different and so perhaps should be treated as different by the library. And with the right alchemist equations, how much milk with a gallon of gasoline yield? :-P

Is NCalc hookable to achieve this? How much work would be involved in enhancing NCalc otherwise? Are there any other .Net compatible libraries that can handle Units of Measure?

1

There are 1 best solutions below

0
On

FParsec seems interesting! It only helps with the expression parsing steps, but that seems like most of the battle. Supports compact, BNF-like definitions in F# and can provide high-quality error messages.

Dimensional Anaylsis is still a custom job, but with a properly parsed AST, would it be hard to implement?