Adletec.Sonic 1.1.0-beta-3

This is a prerelease version of Adletec.Sonic.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Adletec.Sonic --version 1.1.0-beta-3                
NuGet\Install-Package Adletec.Sonic -Version 1.1.0-beta-3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Adletec.Sonic" Version="1.1.0-beta-3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Adletec.Sonic --version 1.1.0-beta-3                
#r "nuget: Adletec.Sonic, 1.1.0-beta-3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Adletec.Sonic as a Cake Addin
#addin nuget:?package=Adletec.Sonic&version=1.1.0-beta-3&prerelease

// Install Adletec.Sonic as a Cake Tool
#tool nuget:?package=Adletec.Sonic&version=1.1.0-beta-3&prerelease                

Jace.NET

Jace.NET is a high performance calculation engine for the .NET platform. It stands for "Just Another Calculation Engine".

Build Status

  • Build status (master)
  • Build status (dev)

What does it do?

Jace.NET can interprete and execute strings containing mathematical formulas. These formulas can rely on variables. If variables are used, values can be provided for these variables at execution time of the mathematical formula.

Jace can execute formulas in two modes: in interpreted mode and in a dynamic compilation mode. If dynamic compilation mode is used, Jace will create a dynamic method at runtime and will generate the necessary MSIL opcodes for native execution of the formula. If a formula is re-executed with other variables, Jace will take the dynamically generated method from its cache. It is recommended to use Jace in dynamic compilation mode.

Wiki

For detailed information how to use Jace.NET, please consult the wiki

Architecture

Jace.NET follows a design similar to most of the modern compilers. Interpretation and execution is done in a number of phases:

Tokenizing

During the tokenizing phase, the string is converted into the different kind of tokens: variables, operators and constants.

Abstract Syntax Tree Creation

During the abstract syntax tree creation phase, the tokenized input is converted into a hierarchical tree representing the mathematically formula. This tree unambiguously stores the mathematical calculations that must be executed.

Optimization

During the optimization phase, the abstract syntax tree is optimized for executing.

Interpreted Execution/Dynamic Compilation

In this phase the abstract syntax tree is executed in either interpreted mode or in dynamic compilation mode.

Examples

Jace.NET can be used in a couple of ways:

To directly execute a given mathematical formula using the provided variables:

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("var1*var2", variables);

To build a .NET Func accepting a dictionary as input containing the values for each variable:

CalculationEngine engine = new CalculationEngine();
Func<Dictionary<string, double>, double> formula = engine.Build("var1+2/(3*otherVariable)");

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2);
variables.Add("otherVariable", 4.2);
	
double result = formula(variables);

To build a typed .NET Func:

CalculationEngine engine = new CalculationEngine();
Func<int, double, double> formula = (Func<int, double, double>)engine.Formula("var1+2/(3*otherVariable)")
	.Parameter("var1", DataType.Integer)
    .Parameter("otherVariable", DataType.FloatingPoint)
    .Result(DataType.FloatingPoint)
    .Build();
	
double result = formula(2, 4.2);

Functions can be used inside the mathemical formulas. Jace.NET currently offers four functions accepting one argument (sin, cos, loge and log10) and one function accepting two arguments (logn).

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("logn(var1,var2)+4", variables);

Performance

Below you can find the results of Jace.NET benchmark that show its high performance calculation engine. Tests were done on an Intel i7 2640M laptop. 1000 random formulas were generated, each containing 3 variables and a number of constants (a mix of integers and floating point numbers). Each random generated formula was executed 10 000 times. So in total 10 000 000 calculations are done during the benchmark. You can find the benchmark application in "Jace.Benchmark" if you want to run it on your system.

  • Interpreted Mode : 00:00:06.7860119
  • Dynamic Compilation Mode: 00:00:02.5584045

Compatibility

If you are using Jace.NET inside a Unity project using IL2CPP you must use Jace.NET in interpreted mode due to limitations of IL2CPP with dynamic code generation.

More Information

For more information, you can read the following articles:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 10,281 2/9/2024
1.4.1 2,213 12/26/2023
1.4.0 476 11/28/2023
1.3.2 431 11/16/2023
1.3.1 417 11/12/2023
1.3.0 432 11/6/2023
1.2.0 507 9/20/2023
1.1.0 498 9/20/2023
1.1.0-beta-6 497 8/23/2023
1.1.0-beta-5 469 8/22/2023
1.1.0-beta-4 464 8/22/2023
1.1.0-beta-3 478 8/22/2023