Epsilon 1.2.0
dotnet add package Epsilon --version 1.2.0
NuGet\Install-Package Epsilon -Version 1.2.0
<PackageReference Include="Epsilon" Version="1.2.0" />
<PackageVersion Include="Epsilon" Version="1.2.0" />
<PackageReference Include="Epsilon" />
paket add Epsilon --version 1.2.0
#r "nuget: Epsilon, 1.2.0"
#:package Epsilon@1.2.0
#addin nuget:?package=Epsilon&version=1.2.0
#tool nuget:?package=Epsilon&version=1.2.0
![]()
Epsilon
Symbolic math for .NET. Parse formulas, simplify them exactly, differentiate, factor polynomials and find roots — with no dependencies beyond the .NET base library.
Expr f = ExprParser.Parse("x^3 - 2x^2 + x", "x");
f.Differentiate("x").Print(); // 3x^2 - 4x + 1
f.TryFactorReal("x").Factored.Print(); // (x - 1)^2 * x
Installation
dotnet add package Epsilon
Requires .NET 10. The package contains the core library; its namespace is Epsilon.Core.
Quick start
using Epsilon.Core;
Expr f = ExprParser.Parse("x^3 - 2x^2 + x", "x");
f.Evaluate(3); // 12
f.Differentiate("x").Print(); // 3x^2 - 4x + 1
f.Differentiate("x").ToLatex(); // 3x^{2} - 4x + 1
f.FindRealRoots(-10, 10); // [0, 1]
f.TryFactorReal("x").Factored.Print(); // (x - 1)^2 * x
Expressions can also be built with ordinary C# operators:
var x = new Variable("x");
(x * x + 3 * x - x).Simplify().Print(); // x^2 + 2x
(x.Pow(2) + 2 * x + 1).Print(); // x^2 + 2x + 1
Features
Exact arithmetic
Numbers are arbitrary-precision rationals, never floating point, so nothing is lost along the way:
ExprParser.Parse("0.1 + 0.2").Simplify().Print(); // 3/10
ExprParser.Parse("cos(3pi/4)").Simplify().Print(); // -sqrt(2) / 2
ExprParser.Parse("x^2 - 2").TryFactorReal("x").Factored.Print();
// (x + sqrt(2)) * (x - sqrt(2))
Factoring is exact as well: roots are rational or written with square roots, and a polynomial that can't be factored that way is left alone rather than approximated.
Simplification that respects the domain
Simplify folds constants, combines like terms and factors, cancels common factors and
applies identities such as sin(x)^2 + cos(x)^2 = 1. It never changes the value of an
expression where that expression is defined. Two modes decide what happens where it isn't:
Expr e = ExprParser.Parse("x/x");
e.Simplify().Print(); // 1 Generic (default): may become defined at x = 0
e.Simplify(SimplifyMode.Strict).Print(); // x / x Strict: keeps exactly the same domain
Expand multiplies out the brackets that Simplify keeps:
ExprParser.Parse("(x + 1)^2 - x^2").Expand().Print(); // 2x + 1
Assumptions
Tell the simplifier what you know about your variables to unlock rules that are only valid under conditions:
Expr s = ExprParser.Parse("sqrt(x^2)");
s.Simplify().Print(); // abs(x)
s.Simplify(Assumptions.None.AssumePositive("x")).Print(); // x
Contradictory assumptions (x > 0 and x < 0) are rejected with an error naming the variable.
Differentiation
Symbolic derivatives, partial derivatives included, returned already simplified:
ExprParser.Parse("x^2 * y + y^3").Differentiate("y").Print(); // 3y^2 + x^2
Root finding
All real roots in a range — including infinite ranges, double roots and roots on the edge of the domain — and complex roots via Newton's method:
ExprParser.Parse("sqrt(1 - x^2)").FindRealRoots(); // [-1, 1]
ExprParser.Parse("sin(x)").SolveNumerically(0.5, -4, 4);
// ≈ [-3.665, 0.524, 2.618]
ExprParser.Parse("x^2 + 1").FindComplexRoots(-2, 2, -2, 2); // ≈ [-i, i]
Points where the expression is undefined are never reported as roots.
Real and complex evaluation, text and LaTeX output
ExprParser.Parse("x*y + 1").Evaluate(("x", 2), ("y", 3)); // 7
ExprParser.Parse("sqrt(x)").EvaluateComplex(-4); // ≈ 2i
To evaluate many times, compile once: the delegate returns exactly the same values, up to 30 times faster.
var f = ExprParser.Parse("x*y + 1").Compile("x", "y");
f(2, 3); // 7
Print() writes compact text that Parse reads back; ToLatex() writes LaTeX.
Parser syntax
| Kind | Syntax |
|---|---|
| Operators | + - * / ^, parentheses, \|x\| for absolute value |
| Implicit multiplication | 2x, 2(x + 1), x y |
| Numbers | 12, 1.5, .5, 1e-5, 2.5E3 — always a decimal point, never a comma |
| Constants | pi (or π), e, i |
| Trigonometric | sin cos tan cot sec csc, asin acos atan |
| Hyperbolic | sinh cosh tanh coth sech csch, asinh acosh atanh |
| Other functions | exp ln sqrt abs sign floor ceiling round |
| Two arguments | min(a, b), max(a, b), log(x, base), nthroot(x, n) |
Without a list of variables, every single letter is a variable and xy means x*y. Pass
the names to allow longer ones and to catch typos:
ExprParser.Parse("theta^2 + 2t", "theta", "t").Print(); // theta^2 + 2t
ExprParser.Parse("sen(x)", "x");
// FormatException: Unknown identifier 'sen' at position 0. Declared variables: x.
Documentation
The guides cover every feature in detail: parsing, simplification, root finding and more; the API reference lists every public type and member. Before relying on something, check the known limitations; changes are listed in the changelog.
Design principles
- Exact first. Rationals instead of doubles; exact factoring or none at all.
- Never wrong, sometimes unsimplified. A rule that is only valid under a condition is applied only when the condition is known to hold — a missed simplification is always safer than an incorrect one.
- No dependencies. Only the .NET base library.
- Documented. Every public member has XML documentation for IntelliSense.
Roadmap
Planned for the core:
- Equation solver — symbolic solutions of
f(x) = g(x)with every branch:sin(x) = 1/2→π/6 + 2πk, 5π/6 + 2πk, verified by substitution, with a clearly marked numeric fallback. - Piecewise expressions (derivatives of
floor,min,max).
This package is the core of a family: linear algebra, calculus and transforms are built on it as separate packages. The order is in the repository roadmap.
License
MIT © Max Zakharov — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Epsilon:
| Package | Downloads |
|---|---|
|
Epsilon.LinearAlgebra
Linear algebra for the Epsilon symbolic math library: immutable matrices and vectors of expressions, exact rationals or doubles, and fixed-size vector and matrix value types (Vector2 to Vector4, Matrix2x2 to Matrix4x4) of float, double or any number type for games and graphics. Exact symbolic determinant, characteristic polynomial, inverse and solve without division; exact rational elimination; LU decomposition for doubles with singularity detection to working precision; QR, Cholesky, symmetric eigenvalue and singular value decompositions by accurate Jacobi methods, least squares for any shape (exact for rationals and expressions), the pseudo-inverse and the condition number. Vector geometry, transforms, quaternions with slerp, Euler angles in any axis order, translation-rotation-scale decomposition, camera view and projection matrices (right- and left-handed, any depth range, reverse-Z), a closed-form inverse that detects singular matrices, conversions to System.Numerics, blocks, ranges, powers and approximate equality. Symbolic formulas become fast code: matrices and vectors of expressions compile to delegates with exactly the values of Evaluate or to standalone C# source, with Jacobians and symbolic rotations and translations for kinematic chains and inverse kinematics. |
|
|
Epsilon.Calculus
Calculus for the Epsilon symbolic math library. Gradients, directional derivatives, divergence and curl, Hessians, Laplacians and the second-derivative test for functions of several variables, as vectors and matrices of expressions that compile to fast delegates. Exact antiderivatives from a table of integrals, by substitution, by parts, by partial fractions with Hermite's reduction (over the roots of cubic and quartic factors in radicals too), by Bioche's rules and t = tan(x/2) for rational functions of sin and cos, by t = exp(x) and by trigonometric and hyperbolic substitutions for square roots of quadratics. Numeric definite integrals by the tanh-sinh and exp-sinh rules over finite and infinite intervals, split at the singularities, kinks and peaks found in the expression, accurate at singular ends, and with divergent integrals reported instead of returned as numbers. |
GitHub repositories
This package is not used by any popular GitHub repositories.