uCalcSoftware 5.7.0-preview.4
dotnet add package uCalcSoftware --version 5.7.0-preview.4
NuGet\Install-Package uCalcSoftware -Version 5.7.0-preview.4
<PackageReference Include="uCalcSoftware" Version="5.7.0-preview.4" />
<PackageVersion Include="uCalcSoftware" Version="5.7.0-preview.4" />
<PackageReference Include="uCalcSoftware" />
paket add uCalcSoftware --version 5.7.0-preview.4
#r "nuget: uCalcSoftware, 5.7.0-preview.4"
#:package uCalcSoftware@5.7.0-preview.4
#addin nuget:?package=uCalcSoftware&version=5.7.0-preview.4&prerelease
#tool nuget:?package=uCalcSoftware&version=5.7.0-preview.4&prerelease
uCalc: The High-Performance Math Expression Evaluator and Token-Aware Text Transformation Engine
Homepage | Documentation | Online interactive examples | What's New | Release Notes | License
uCalc API Preview Release Notice: This preview documentation describes the intended behavior of the API. It is not fully accurate or complete. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes. Use of the preview version in your production code is not recommended.
uCalc is a suite of three components: a Fast Math Parser, a token-aware text Transformer, and a String library. They are powered by the same underlying advanced parser engine and designed to seamlessly integrate for sophisticated operations. The uCalc SDK is backed by extensive online documentation with numerous interactive examples.
Use uCalc to build spreadsheet calculation engines, dynamic report generators, static analysis/code refactoring tools, linters, game scripting environments, custom domain-specific languages (DSLs), and to perform data extraction, complex string building, markup language conversion, and more.
- uCalc Fast Math Parser lets you evaluate math expressions defined at runtime. It comes with many functions and operators, and lets you define your own as well, either at runtime, or by attaching them to functions in your source code. You can call the simple Eval() to evaluate an expression right away, or parse the expression once and evaluate it many times in a loop at optimal speeds. uCalc is easy to use, yet very powerful.
- uCalc Transformer is a smart, token-aware engine for searching, replacing, and restructuring text. Use it to parse structured or unstructured text alike. Not limited to character units, it understands units of text like quoted strings, whitespace, nested brackets, user-defined comment structures, etc., and shines where regex falls short. It supports advanced rewrite rules, while also being designed for human readability to make it simple to use.
- uCalc String Library is a smart, mutable string manipulation library that offers you live views into strings for surgical in-place editing of different parts of the string, respecting structural boundaries (for instance it can distinguish between alphanumeric symbols, quoted text, etc., or user defined units of text), using the same underlying token-aware parser as the transformer. Methods can be chained together fluently for easy deployment.
Runtimes for Windows (x86, x64, and ARM64), Linux (x64 and ARM64), macOS (Intel osx-64 and osx-ARM64 Apple Silicon), are carefully packaged into the same NuGet library. This allows for immediate plug-and-play integration without the hassle of setting up platform-specific plumbing.
Quick Start
Fast Math Parser
using uCalcSoftware;
var uc = new uCalc();
// 1. Expression Parser: Evaluate a simple math or string expression
uc.DefineVariable("n = 10");
uc.DefineFunction("Area(length, width) = length * width");
Console.WriteLine(uc.Eval("5 * Area(n, 6) / 2")); // Output: 150
uc.DefineVariable("FirstName = 'John'");
Console.WriteLine(uc.EvalStr("UCase(FirstName) + ' Doe'")); // Output: JOHN Doe
// 2. Evaluate an expression faster in a loop
var myVar = uc.DefineVariable("x");
var expr = uc.Parse("x * 2");
for (var i = 1; i <= 5; i++) {
myVar.Value(i);
Console.WriteLine($"When x is {i}, result is: {expr.Evaluate()}");
}
// Output:
// When x is 1, result is: 2
// ...
// When x is 5, result is: 10
Transformer
using uCalcSoftware;
// Transformer: Perform a basic find-and-replace to reformat a person's name
var t = new uCalc.Transformer();
t.FromTo("First Name: {first} [Middle Name: {middle}] Last Name: {last}", "Name: {last}, {first} {middle}");
Console.WriteLine(t.Transform("First Name: John-Paul Last Name: Doe")); // Output: Doe, John-Paul
Console.WriteLine(t.Transform("First Name: John Middle Name: Peter Last Name: Doe")); // Output: Doe, John Peter
String Library
using uCalcSoftware;
// String Library: Using a fluent, chainable operation to modify a subsection of text in-place within a string
var log = new uCalc.String("INFO: File-handling task. ERROR: File not found.");
log.After("ERROR: ").Replace("File", "Resource");
Console.WriteLine(log); // Output: INFO: File-handling task. ERROR: Resource not found.
Practical example: Creating a JSON minifier that takes a formatted string and removes all non-essential whitespace
using uCalcSoftware;
var t = new uCalc.Transformer();
// 1. Define rules to remove whitespace and newlines.
// The engine's default QuoteSensitive=true ensures whitespace inside strings is protected.
t.FromTo("{@Whitespace}", "");
t.FromTo("{@Newline}", "");
// 2. Define the formatted input string.
var formattedJson = """
{
"id": 123,
"name": "Example, with spaces",
"tags": [
"A",
"B"
]
}
""";
// 3. Run the transformation and print the result.
Console.WriteLine(t.Transform(formattedJson));
// Output: {"id":123,"name":"Example, with spaces","tags":["A","B"]}
Building an Equation Solver with the Parser and Transformer
using uCalcSoftware;
var uc = new uCalc();
static void EqSolveCb(uCalc.Callback cb) { // Callback based on the Bisection Method
var expr = cb.ArgExpr(1); // ByExpr: Unevaluated Expression object (lazy evaluation)
var a = cb.Arg(2); // Argument 2: Range Minimum
var b = cb.Arg(3); // Argument 3: Range Maximum
var variable = cb.ArgItem(4); // ByHandle: The variable Item object
// Helper to update the variable in the uCalc engine and evaluate the expression
double EvaluateAt(double val) {
variable.Value(val); // Push the new test value to the variable
return expr.Evaluate(); // Evaluate the pre-parsed expression
}
// Ensure f(a) < f(b) so we always know which direction to slide the bounds
if (EvaluateAt(b) < EvaluateAt(a)) (a, b) = (b, a); // C# tuple swap
var midpoint = 0.0;
var fMidpoint = 0.0;
// Bisection loop
for (int i = 0; i <= 100; i++) {
midpoint = (a + b) / 2;
fMidpoint = EvaluateAt(midpoint);
if (Math.Abs(fMidpoint) < 1e-7) break; // Stop if close enough to 0
// Narrow the bounds (compact logic!)
if (fMidpoint < 0) a = midpoint; else b = midpoint;
}
if (Math.Abs(fMidpoint) > 1e-5) cb.Error.Raise("No solution found in the given range.");
cb.Return(Math.Round(midpoint, 7)); // Return the final solved value
}
// 1. Define variables that might be used by the end-user
uc.DefineVariable("x");
uc.DefineVariable("MyVar");
// 2. Transformer converts `EqSolve(L = R)` into `EqSolve(L - (R))` & sets defaults before it hits the parser
var t = uc.ExpressionTransformer;
t.FromTo("EqSolve({L} = {R} [[,]for {var}][, {min}, {max}])",
"EqSolve({L} - ({R}), {min}{!min:-10000}, {max}{!max: 10000}, {var}{!var: x})");
// 3. Define the custom function signature
uc.DefineFunction("EqSolve(ByExpr eq, min, max, ByHandle variable)", EqSolveCb);
// --- Demo Executions ---
System.Collections.Generic.List<string> eqList = new() {
"EqSolve(x + 5 = 125)", // Using default range [-10000,10000]
"EqSolve(x^2 + 5 = 105)", // Picks one result from the default range
"EqSolve(x^2 + 5 = 105, 0, 100)", // Restricts to positive root
"EqSolve(x^2 + 5 = 105, -100, 0)", // Restricts to negative root
"EqSolve(x^2 + 1000 = 5)", // No existing solution
"EqSolve(40 + MyVar * 6 = 88, for MyVar)" // Uses custom variable 'MyVar' instead of 'x'
};
foreach(var eq in eqList) {
Console.WriteLine(uc.ExpressionTransformer.Transform(eq)); // Displays transformed expression
Console.WriteLine($"Result: {uc.EvalStr(eq)}"); // Returns result
}
Links
| Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. 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 | 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. |
-
.NETStandard 2.0
- No dependencies.
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 |
|---|---|---|
| 5.7.0-preview.4 | 30 | 8/20/2026 |
| 5.7.0-preview.3 | 65 | 8/14/2026 |
| 5.7.0-preview.2 | 53 | 8/7/2026 |
| 5.7.0-preview.1 | 64 | 7/30/2026 |
