Releases: AntonovAnton/math.evaluation
2.2.4
2.2.3
Improvements:
- The handling of the sign for the components of the complex number has been enhanced to account for cases such as zero, etc. #74
- Added benchmarks for complex numbers. #74
- Added support of the IIF function to the Programming Math Context (ProgrammingMathContext class). Conditional operation:
IIF(condition, valueIfTrue, valueIfFalse)
, where thevalueIfTrue
andvalueIfFalse
arguments are optional. #74
2.2.2
Fixes: #72
The Compile(this string mathString, IMathContext? context = null, IFormatProvider? provider = null)
extension method for the string
type without T parameters has been removed to avoid conflicts between the context argument and the parameters argument in other overload of the Compile
method.
Compilation without parameters doesn't make sense, anyway you still can use the MathExperssion.Compile()
method instead of the string extension method.
2.2.0 / Supports Complex numbers.
Improves:
Added support of complex numbers. #69
Complex numbers are written in the form a ± bi, where a is the real part and bi is the imaginary part.
Below is an example of evaluating a mathematical expression that contains complex numbers:
var expression = new MathExpression("sin(2 + 3i) * arctan(4i)/(1 - 6i)", new ComplexScientificMathContext());
var value = expression.EvaluateComplex();
Evaluation steps:
1: 3i = <0; 3>; 2: 2 + 3i = <2; 3>; 3: sin(2 + 3i) = <9.15449914691143; -4.168906959966565>; 4: 4i = <0; 4>; 5: arctan(4i) = <1.5707963267948966; 0.25541281188299525>; 6: sin(2 + 3i) * arctan(4i) = <15.444645882739138; -4.2103273709720295>; 7: 6i = <0; 6>; 8: 1 - 6i = <1; -6>; 9: sin(2 + 3i) * arctan(4i)/(1 - 6i) = <1.1001786515830083; 2.3907445385260218>; //completed
2.1.0
Improves:
Added the Evaluating event. #67
By using this event, you can debug or log the steps of a math expression's evaluation. This event is triggered at each step during the evaluation process. The following code demonstrates how to use to this event:
using var expression = new MathExpression("-3^4sin(-PI/2)", new ScientificMathContext());
expression.Evaluating += (object? sender, EvaluatingEventArgs args) =>
{
Console.WriteLine("{0}: {1} = {2};{3}",
args.Step,
args.MathString[args.Start..(args.End + 1)],
args.Value,
args.IsCompleted ? " //completed" : string.Empty);
};
var value = expression.Evaluate();
Output:
1: 3^4 = 81;
2: PI = 3.141592653589793;
3: PI/2 = 1.5707963267948966;
4: -PI/2 = -1.5707963267948966;
5: sin(-PI/2) = -1;
6: 3^4sin(-PI/2) = -81;
7: -3^4sin(-PI/2) = 81; //completed
NOTE: The Evaluating event is cleaned up in the Dispose method. So I recommend using the using statement to ensure proper disposal.
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
Added support for compiling mathematical expression strings into executable code, producing a delegate that represents the expression.
Example:
var fn = "ln(1/x1 + √(1/(x2*x2) + 1))"
.Compile(new { x1 = 0.0, x2 = 0.0 }, new ScientificMathContext());
var value = fn(new { x1 = -0.5, x2 = 0.5 });
This enhancement allows for efficient evaluation of complex mathematical expressions by converting them into callable delegates.
Added MathExpression class instead of the MathEvaluator class that combines evaluation and compilation. Static methods are removed.