This is a math expression parser written in C#, which evaluates mathematical expressions such as for example cos(x)-sin(x)+2 with given values.
Example usage:
// Import the assembly that contains the parser
using info.lundin.Math;
// some other imports
using System;
using System.Collections;
public class Test
{
public static void Main( String[] args )
{
// Instantiate the parser
ExpressionParser parser = new ExpressionParser();
// Create a hashtable to hold values
Hashtable h = new Hashtable();
// Add variables and values to hashtable
h.Add( "x", 1.ToString() );
h.Add( "y", 2.ToString() );
// Parse and write the result
double result = parser.Parse( "xcos(y)", h );
Console.WriteLine( Result: {0}, result );
}
}
The parser supports most common mathematical operators and functions such as:
Operators:
+, -, *, /, ^, %
Functions:
sqrt, sin, cos, tan, atan, acos, asin, acotan, exp, ln, 10log, fac, sinh, cosh, tanh, abs, ceil, floor, sfac, round, fpart.
Logical:
!, ==, !=, ||, &&, >, < , >=, <=

P LPosted Mar 7, 2012, 2:51 AM EST
Please download from www.lundin.info and not from this article that still has source from the year 2002!
veeresh diggiPosted Mar 6, 2012, 7:02 PM EST
Hi All, I am using info.lundin.Math.dll for parsing the expression like (X*4)/100 x is added to hash table like h.Add( "x", "100" ); But I am getting the error saying No value associated with x. could you please help me why I am getting this error, how do i need to resolve this Any help is appreciated. waiting for the feedback
Juan CarlosPosted Aug 4, 2011, 7:19 AM EDT
EXCELENTE
YiPosted Jun 3, 2011, 12:35 AM EDT
It's nice! And the parsing speed is super fast!!! As I tested, it is 6 times faster than Flee, another expression evaluator component.
worker dbPosted Oct 20, 2010, 6:32 AM EDT
Really great job. How about string expressions parser. For instance ("Jack" == "Jack") or ("C#" != "c#")
EricPosted Aug 1, 2010, 4:53 PM EDT
I tried about a half dozen math libraries, even pay ones, and this library was the ONLY ONE that worked under all circiumstances! Rather that I was using spaces or not (several choked on spaces), rather I was using multiple variables that did not exist in the actual formula (think blanket mass-variables and adding all to run differnet formulas every time), and the final piece that only your library supported: the ability to re-use variables more than once! Surpisingly, several other libraries did not allow that. I'm using in a C# 4.0 project. I noticed it was targeted for .net 1.0 when it was compiled. That's old! I've snag the code as well. Thank you again! If there was a "Donation" button, I would donate!
cizmeliPosted Dec 24, 2009, 10:37 PM EST
doesnt work for floating points
evgPosted Jun 20, 2009, 3:38 AM EDT
http://ssss35.blogspot.com/2009/06/math-parse-expressions-c-java.html
P LPosted May 18, 2009, 3:37 AM EDT
Please download the code from the authors website: http://www.lundin.info/mathparser.aspx It contains some updates and also the source code, however it has not been maintained since 2004. There are alternatives such as for example wrapping the JScript eval function using the jsc compiler in the .net framework.
ciptoPosted Jan 23, 2008, 10:13 PM EST
thank you lundin :D thisis what i need, to change from math expression string to double or the result thanks brother
Martin OrtizeditedPosted Oct 9, 2007, 10:01 AM EDTEdited Oct 9, 2007, 10:02 AM EDT
For example ExpressionParser parser = new ExpressionParser(); // Create a hashtable to hold values Hashtable h = new Hashtable(); // Add variables and values to hashtable h.Add("x", 1.ToString()); // BOOLEAN "TRUE" h.Add("y", 1.ToString()); // BOOLEAN "TRUE" h.Add("z", 0.ToString()); // BOOLEAN "FALSE" // Parse and write the result double result = parser.Parse("((x || y) && !z)", h); // YOUR BOOLEAN EXPRESSION.... IF result is 1.0 than expression evaluated to true, if it is 0.0 than expression evaluated to false
Martin OrtizPosted Oct 9, 2007, 9:55 AM EDT
Clean and simple to use....super great! thanks.
Vitor PereiraPosted Jun 22, 2007, 8:18 AM EDT
Expressions with decimal values are not allowed example: y = 2.0*Sin(x) is processed like y = 20*Sin(x) and y = 2,0*Sin(x) causes exception