mathjson-solver 2.2.1__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/CHANGELOG.md +42 -0
  2. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/PKG-INFO +65 -45
  3. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/README.md +62 -44
  4. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/SECURITY.md +3 -2
  5. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/docs/README.md +521 -12
  6. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/pyproject.toml +9 -1
  7. mathjson_solver-2.4.0/src/mathjson_solver/__main__.py +1300 -0
  8. mathjson_solver-2.4.0/src/mathjson_solver/_arithmetic_constructs.py +219 -0
  9. mathjson_solver-2.4.0/src/mathjson_solver/_array_arithmetic_constructs.py +283 -0
  10. mathjson_solver-2.4.0/src/mathjson_solver/_array_helpers.py +55 -0
  11. mathjson_solver-2.4.0/src/mathjson_solver/_collection_constructs.py +819 -0
  12. mathjson_solver-2.4.0/src/mathjson_solver/_combinatorics.py +31 -0
  13. mathjson_solver-2.4.0/src/mathjson_solver/_combinatorics_constructs.py +87 -0
  14. mathjson_solver-2.4.0/src/mathjson_solver/_common.py +136 -0
  15. mathjson_solver-2.4.0/src/mathjson_solver/_comparison_constructs.py +114 -0
  16. mathjson_solver-2.4.0/src/mathjson_solver/_construct_shared.py +62 -0
  17. mathjson_solver-2.4.0/src/mathjson_solver/_control_flow_constructs.py +100 -0
  18. mathjson_solver-2.4.0/src/mathjson_solver/_core_constructs.py +64 -0
  19. mathjson_solver-2.4.0/src/mathjson_solver/_datetime_constructs.py +108 -0
  20. mathjson_solver-2.4.0/src/mathjson_solver/_exceptions.py +46 -0
  21. mathjson_solver-2.4.0/src/mathjson_solver/_functional_constructs.py +133 -0
  22. mathjson_solver-2.4.0/src/mathjson_solver/_interpolation.py +69 -0
  23. mathjson_solver-2.4.0/src/mathjson_solver/_number_theory.py +298 -0
  24. mathjson_solver-2.4.0/src/mathjson_solver/_number_theory_constructs.py +257 -0
  25. mathjson_solver-2.4.0/src/mathjson_solver/_special_function_constructs.py +166 -0
  26. mathjson_solver-2.4.0/src/mathjson_solver/_special_functions.py +157 -0
  27. mathjson_solver-2.4.0/src/mathjson_solver/_statistics_constructs.py +473 -0
  28. mathjson_solver-2.4.0/src/mathjson_solver/_string_constructs.py +364 -0
  29. mathjson_solver-2.4.0/src/mathjson_solver/_trig_constructs.py +34 -0
  30. mathjson_solver-2.4.0/tests/test_blacklist.py +74 -0
  31. mathjson_solver-2.4.0/tests/test_cortexjs_combinatorics.py +101 -0
  32. mathjson_solver-2.4.0/tests/test_cortexjs_core.py +71 -0
  33. mathjson_solver-2.4.0/tests/test_cortexjs_distributions.py +126 -0
  34. mathjson_solver-2.4.0/tests/test_cortexjs_number_theory.py +167 -0
  35. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_sets.py +29 -0
  36. mathjson_solver-2.4.0/tests/test_cortexjs_special_functions.py +167 -0
  37. mathjson_solver-2.4.0/tests/test_cortexjs_statistics.py +157 -0
  38. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_tier3.py +29 -0
  39. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_datetime.py +101 -0
  40. mathjson_solver-2.4.0/tests/test_scope_isolation.py +123 -0
  41. mathjson_solver-2.2.1/src/mathjson_solver/__main__.py +0 -2869
  42. mathjson_solver-2.2.1/tests/test_cortexjs_statistics.py +0 -75
  43. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/.gitignore +0 -0
  44. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/CODE_OF_CONDUCT.md +0 -0
  45. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/CONTRIBUTING.md +0 -0
  46. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/LICENSE +0 -0
  47. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/docs/integration-test-cases.md +0 -0
  48. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/src/mathjson_solver/__init__.py +0 -0
  49. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_TrapezoidalIntegratel.py +0 -0
  50. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_atindex.py +0 -0
  51. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_collections.py +0 -0
  52. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_compat.py +0 -0
  53. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_constants_relations.py +0 -0
  54. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cortexjs_strings.py +0 -0
  55. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_cumulative.py +0 -0
  56. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_equal.py +0 -0
  57. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_exceptions.py +0 -0
  58. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_extract_variables.py +0 -0
  59. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_findinterval.py +0 -0
  60. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_gail_model.py +0 -0
  61. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_interpolate.py +0 -0
  62. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_legacy_compat.py +0 -0
  63. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_range.py +0 -0
  64. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_reduce_simple.py +0 -0
  65. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_scalars.py +0 -0
  66. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_sets.py +0 -0
  67. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_simple_cases.py +0 -0
  68. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_slice.py +0 -0
  69. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_state_tuples_reduce.py +0 -0
  70. {mathjson_solver-2.2.1 → mathjson_solver-2.4.0}/tests/test_with_pytest.py +0 -0
@@ -5,6 +5,48 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
+ ## [2.4.0] - 2026-12-02
9
+
10
+ ### Added
11
+
12
+ - **`DateDiffSeconds`, `DateDiffMinutes`, `DateDiffHours`, `DateDiffDays`, `DateDiffYears`** - `end - start` between two ISO date/datetime strings, as a number (negative if `end` precedes `start`). `DateDiffYears` returns complete calendar years (an age), with February 29 start dates completing their year on March 1 in non-leap years. Mixing timezone-aware and naive inputs raises an error.
13
+
14
+ ## [2.3.0] - 2026-09-21
15
+
16
+ ### Changed
17
+
18
+ - 2-3x faster evaluation on arithmetic- and `Reduce`-heavy expressions. No behavior change.
19
+
20
+ ### Fixed
21
+
22
+ - **`extract_variables` treated unrecognized constructs' arguments as free variables.** `["Color", "red"]` would report `"red"` as a parameter to supply, even though it's a literal argument to a construct this solver doesn't implement - not a variable reference. `extract_variables` now mirrors `f()`'s own fallback for an unrecognized construct (return the expression unchanged, never evaluating or substituting into its arguments): it's treated as opaque data, contributing no free variables, rather than recursed into. Applies to any unimplemented construct (`Color`, `Quantity`, etc.), not just specific names. The same treatment was extended to `Head`/`Tail`/`Hold`/`IsSame`/`Same` (new in this release, see below), which likewise never evaluate their arguments.
23
+
24
+ ### Added
25
+
26
+ - **More statistics:** `Skewness`, `Kurtosis` (sample-adjusted, matching Excel's `SKEW`/`KURT` and `scipy.stats.skew`/`kurtosis` with `bias=False`), `LinearRegression` (least-squares fit, returns `["Array", slope, intercept]`), `PolynomialFit` (least-squares fit of a given degree via the normal equations, no numpy dependency, returns `["Array", c0, c1, ..., cd]` - lowest degree first, the opposite order from `numpy.polyfit`). `PolynomialFit`'s degree is capped at 50.
27
+ - **Probability distributions:** `NormalDistribution`, `BinomialDistribution`, `PoissonDistribution`, `UniformDistribution`, `ExponentialDistribution`, queried via `PDF`/`CDF`/`Quantile` (e.g. `["CDF", ["NormalDistribution", 0, 1], 1.5]`), matching CortexJS's calling convention. `PDF` needs no optional dependency for any of the five, including the two discrete distributions (uses a log-space reformulation - the direct formula overflows a float well within realistic `n`). `Binomial`/`PoissonDistribution`'s `CDF`/`Quantile` use the already-shipped `GammaRegularized`/`BetaRegularized` identities and so require the `special-functions` extra; the other three distributions' `CDF`/`Quantile` don't need it either.
28
+ - **Number theory**, ~45 new functions:
29
+ - stdlib-based: `PowerMod`, `ModularInverse`, `IntegerSqrt`
30
+ - Factorization: `FactorInteger`, `PrimeFactors`, `PrimeNu`, `PrimeOmega`, `Radical`, `IsSquareFree`
31
+ - Divisors: `Divisors`, `Sigma0`, `Sigma1`, `SigmaMinus1`, `DivisorSigma`, `Divides`, `Totient`, `IsPerfectPower`
32
+ - Prime lookups (capped - `NthPrime`'s `n`/`NextPrime`'s `k` at 10,000, `NextPrime`'s starting value and every factorization-based function above at `10**12`, `PrimePi`'s `n` at 100,000; picked from measured worst-case timing, not guessed): `NthPrime`, `NextPrime`, `PrimePi`
33
+ - Modular structure: `ExtendedGCD`, `ChineseRemainder`, `CarmichaelLambda`, `JacobiSymbol`, `LegendreSymbol`, `MultiplicativeOrder`, `PrimitiveRoot`
34
+ - Sequences: `LucasL`, `CatalanNumber`, `BernoulliB` (exact, via `fractions.Fraction`; uses the B₁ = -1/2 convention), `ContinuedFraction`, `FromContinuedFraction`
35
+ - Digit manipulation (array form, alongside the existing string-based `IntegerString`/`DigitsFrom`): `IntegerDigits`, `DigitCount`, `DigitSum`, `FromDigits`
36
+ - Figurate numbers and predicates: `IsSquare`, `IsTriangular`, `IsPentagonal`, `IsOctahedral`, `IsCenteredSquare`, `IsPerfect`, `IsAbundant`, `IsHappy`
37
+
38
+ Not included: `RandomPrime` (nondeterminism, same reasoning as `Random`/`RandomChoice`/`RandomSample`).
39
+ - **`Subset`, `SubsetEqual`, `Superset`, `SupersetEqual`, `NotSubset`, `NotSuperset`** - proper/non-proper subset and superset tests over `Array`, matching CortexJS's Sets page.
40
+ - **`Interval`/`Open`, and range membership via `Element`/`In`** - `["Element", x, ["Interval", 0, 1]]` matches CortexJS's own convention for "x is in [0, 1]" exactly (`ce.parse("x \in [0, 1]").json` produces this same shape). Either endpoint can be wrapped in `["Open", endpoint]` to exclude it (e.g. `["Interval", 0, ["Open", 1]]` for the half-open `[0, 1)`); a bare endpoint is included (closed) by default. `In`/`Element` now recognize `Interval` as a domain alongside the existing `Array`/string support.
41
+ - **Special functions:** `Gamma`, `GammaLn` (`math.gamma`/`math.lgamma`), `Beta`, `Factorial2`, and verified iterative algorithms `ErfInv`, `LambertW`, `AGM`, `EllipticK`, `EllipticE` (the "parameter" convention `K(m)`/`E(m)`, `m = k²`), `Hypergeometric1F1`, `Hypergeometric2F1` (defining power series; `Hypergeometric1F1` capped at `|z| <= 500` and uses Kummer's transformation for `z < 0` to avoid catastrophic cancellation, `Hypergeometric2F1` restricted to `|z| < 1`, its actual radius of convergence). Not included: `JacobiTheta`, `DedekindEta` - `scipy.special` (see below) doesn't implement these either, so they'd need a from-scratch q-series with the same "subtly wrong across the domain" risk as any other naive truncated series.
42
+ - **`BesselJ`/`BesselY`/`BesselI`/`BesselK`, `AiryAi`/`AiryBi`/`AiryAiPrime`/`AiryBiPrime`, `Zeta`, `GammaRegularized`, `BetaRegularized`** - thin wrappers around `scipy.special`, behind a new optional `special-functions` extra (`pip install mathjson-solver[special-functions]`), same pattern as `integration`/`regex`. `GammaRegularized(a, z)` is the *upper* regularized incomplete gamma (`scipy`'s own `gammainc` is the lower form; this uses `gammaincc`); `BetaRegularized(x, a, b)` puts `x` first, unlike `scipy.special.betainc`'s `(a, b, x)`. Without the extra installed, these raise a clear `ImportError` naming the missing package.
43
+ - **Combinatorics:** `Choose` (alias for `Binomial`), `Fibonacci`, `Multinomial`, `Subfactorial`, `BellNumber`, and the enumeration functions `PowerSet`, `Permutations`, `Combinations`, `CartesianProduct` - the latter four have **no built-in output-size limit** (a set of `n` elements has `2^n` subsets, etc.); see the new `blacklist` parameter below for disabling them in deployments that accept untrusted expressions.
44
+ - **Core (structural introspection):** `Head`/`Tail` (operator name / argument list of a compound expression, read from the raw unevaluated tree), `Hold` (returns an argument unevaluated), `Identity`, `Type` (runtime kind of an evaluated value), `IsSame`/`Same` (structural, pre-evaluation equality - distinct from `Equal`/`StrictEqual`/`IdenticallyEqual`, which all compare evaluated values). Not included: CAS functions (`Evaluate`, `Expand`, `Simplify`, `Solve`, ...), mutable-state functions (`Declare`, `Assign`, `Assume`, ...), and LaTeX serialization (`Parse`, `Latex`, `Subscript`, ...) - same reasoning as elsewhere in this solver (no CAS, no mutable state, no rendering surface). `Error`/`IsError` also not included - this solver already has an established, different error model (`MathJSONException`).
45
+ - **`create_solver(parameters, blacklist=[...])`**: disables the named constructs for that solver instance, raising `MathJSONException` if an expression tries to use one, rather than evaluating it or silently ignoring it. An access-policy control, not a resource limiter - it doesn't make an enabled construct safe against pathological input (in particular, it's the recommended way to disable the four uncapped enumeration functions above for untrusted expression sources). A blacklisted name that isn't an actual construct has no effect (not validated against the known-construct list).
46
+ - **Type hints on the public API**: `create_solver`, `MathJSONException`, `extract_variables`, `translate_v1_mathjson` now have accurate parameter/return type hints, built on one shared `MathJSONExpression` alias for a MathJSON node (`str | int | float | bool | None | list[MathJSONExpression]`). The ~300 per-construct functions inside `create_solver`'s closure remain untyped - they operate on arbitrary runtime values by design (a construct can produce a `Fraction`, a `datetime.timedelta`, a compiled regex pattern, ...), so annotating each one wouldn't add real type safety.
47
+
48
+ [2.3.0]: https://github.com/LongenesisLtd/mathjson-solver/compare/v2.2.1...v2.3.0
49
+
8
50
  ## [2.2.1] - 2026-09-14
9
51
 
10
52
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mathjson-solver
3
- Version: 2.2.1
3
+ Version: 2.4.0
4
4
  Summary: Utilities for MathJSON evaluation
5
5
  Project-URL: Homepage, https://github.com/LongenesisLtd/mathjson-solver
6
6
  Project-URL: Bug Tracker, https://github.com/LongenesisLtd/mathjson-solver/issues
@@ -14,32 +14,45 @@ Provides-Extra: integration
14
14
  Requires-Dist: numpy; extra == 'integration'
15
15
  Provides-Extra: regex
16
16
  Requires-Dist: google-re2; extra == 'regex'
17
+ Provides-Extra: special-functions
18
+ Requires-Dist: scipy; extra == 'special-functions'
17
19
  Description-Content-Type: text/markdown
18
20
 
19
21
  # MathJSON Solver
20
22
 
21
23
  [![PyPI](https://img.shields.io/pypi/v/mathjson-solver.svg)](https://pypi.org/project/mathjson-solver/)
22
24
  [![PyPI Downloads](https://static.pepy.tech/badge/mathjson-solver/month)](https://pepy.tech/projects/mathjson-solver)
23
- [![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)
24
-
25
- > **Heads up:** Version 2 introduces a breaking change (see [CHANGELOG.md](CHANGELOG.md)) as part of steering back towards greater compatibility with [CortexJS MathJSON](https://cortexjs.io/compute-engine/): `Log` is now log base 10 instead of natural log. Stuck on pre-2.0.0 expressions but want the functions added in 2.x? Pass `legacy_v1=True` to `create_solver()` (see [Migrating from 1.x](#migrating-from-1x)) instead of hand-migrating every expression. Bugfix releases for the 1.x line also continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
25
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
26
26
 
27
27
  A reliable Python library for numerically evaluating mathematical expressions in MathJSON format. Perfect for applications that need to safely execute user-provided formulas, calculate dynamic equations, or process mathematical data.
28
28
 
29
29
  **What is MathJSON?** MathJSON represents mathematical expressions as JSON arrays, like `["Add", 1, 2, 3]` for 1+2+3. This format is safe, structured, and easy to generate programmatically.
30
30
 
31
+ Coming from 1.x? Version 2 changed `Log`'s meaning — see [Migrating from 1.x](#migrating-from-1x).
32
+
31
33
  ## Table of Contents
34
+ - [Use Cases](#use-cases)
32
35
  - [Installation](#installation)
33
36
  - [Quick Start](#quick-start)
34
- - [Migrating from 1.x](#migrating-from-1x)
35
37
  - [Supported Operations](#supported-operations)
38
+ - [Restricting Available Functions](#restricting-available-functions)
36
39
  - [Error Handling](#error-handling)
37
- - [Use Cases](#use-cases)
40
+ - [Migrating from 1.x](#migrating-from-1x)
38
41
  - [Testing](#testing)
39
42
  - [Community](#community)
40
43
  - [Contributing](#contributing)
41
44
  - [Related Projects](#related-projects)
42
45
 
46
+ ## Use Cases
47
+
48
+ **The core pattern:** if your Python backend accepts user-provided datapoints *and* user-provided math to apply to them, mathjson-solver is the engine for that — it evaluates the formula without needing to trust either the formula's author or the data's source. A survey platform is a natural fit: a survey and its "calculated answers" both come from the same untrusted party (the survey builder), the calculation runs against whatever the respondent enters, and the result has to be safe to compute no matter what either of them contains. The same shape covers pricing rules, scoring algorithms, and scientific or medical calculators wherever the formula itself isn't fixed at development time — our showcase example is a breast-cancer risk calculator implementing the [Gail model](https://github.com/LongenesisLtd/mathjson-solver/blob/main/tests/test_gail_model.py), numerical integration included, entirely in MathJSON.
49
+
50
+ * **Dynamic Formulas:** Let users create custom calculations in web applications
51
+ * **Scientific Computing:** Evaluate mathematical models with variable parameters
52
+ * **Business Logic:** Process complex pricing rules or scoring algorithms
53
+ * **Data Processing:** Apply mathematical transformations to datasets
54
+ * **Health Applications:** Calculate medical scores, dosages, or risk assessments
55
+
43
56
  ## Installation
44
57
 
45
58
  ```bash
@@ -51,6 +64,9 @@ pip install mathjson-solver
51
64
  **Optional:**
52
65
  - `pip install mathjson-solver[integration]` (installs numpy; only required for `TrapezoidalIntegrate`)
53
66
  - `pip install mathjson-solver[regex]` (installs [google-re2](https://pypi.org/project/google-re2/); only required for `RegExp`/`IsMatch`/`StringMatch`/`StringMatchAll`)
67
+ - `pip install mathjson-solver[special-functions]` (installs [scipy](https://scipy.org/); required for `BesselJ`/`BesselY`/`BesselI`/`BesselK`, `AiryAi`/`AiryBi`/`AiryAiPrime`/`AiryBiPrime`, `Zeta`, `GammaRegularized`, `BetaRegularized`, and `CDF`/`Quantile` on `BinomialDistribution`/`PoissonDistribution`)
68
+
69
+ Combine any of these by separating them with commas in one `pip install`, e.g. `pip install mathjson-solver[integration,regex,special-functions]` for all three at once.
54
70
 
55
71
  ## Quick Start
56
72
 
@@ -90,50 +106,37 @@ solver(["Map", ["Array", 1, 2, 3, 4], ["Function", ["Multiply", "_", 2]]]) # [2
90
106
  solver(["Reduce", ["Array", 1, 2, 3, 4], ["Add"]]) # 10
91
107
  ```
92
108
 
93
- ## Migrating from 1.x
94
-
95
- Version 2.0.0's only breaking change is `Log`: pre-2.0.0 it was always natural log, `["Log", x]` == `math.log(x)`. From 2.0.0 on it matches [CortexJS](https://cortexjs.io/compute-engine/) — `["Log", x]` is log base 10, `["Log", x, b]` is log base `b` — and natural log moved to `Ln`.
109
+ ## Supported Operations
96
110
 
97
- If you have existing expressions built for 1.x and don't want to hand-edit every `Log` node just to pick up functions added in 2.x (`Product`, the CortexJS forms of `If`/`Map`/`Filter`/`Reduce`, the new aliases, etc.), pass `legacy_v1=True` when creating the solver. It rewrites every `["Log", x]` to `["Ln", x]` before evaluating, so old expressions keep producing the same results without modification:
111
+ 338 MathJSON constructs across arithmetic, trigonometry, logarithms, comparisons, logic and sets, statistics and probability distributions, functional programming (Map/Reduce/Filter), arrays and collections, control flow, strings and RE2-backed pattern matching, date/time, number theory, special functions (Bessel/Airy/Gamma/elliptic-integral/hypergeometric families), combinatorics, and structural introspection.
98
112
 
99
113
  ```python
100
- solver = create_solver(parameters, legacy_v1=True)
101
- solver(["Log", 8]) # 2.0794... (natural log, matching pre-2.0.0 behavior)
114
+ ["Add", 1, 2, ["Multiply", 3, 4]] # 15
115
+ ["CDF", ["NormalDistribution", 0, 1], 1.96] # 0.975 (z-score to percentile)
116
+ ["Reduce", ["Array", 1, 2, 3, 4], ["Add"]] # 10
117
+ ["StringMatch", "patient-042", "[0-9]+"] # "042" at position 9-11
118
+ ["FactorInteger", 360] # [[2,3], [3,2], [5,1]] (2³·3²·5)
102
119
  ```
103
120
 
104
- You can also run the rewrite yourself and inspect or store the translated expression:
121
+ Three optional extras unlock specific functions — see [Installation](#installation) above: `regex` (RE2-backed pattern matching), `integration` (`TrapezoidalIntegrate`), `special-functions` (Bessel/Airy/Zeta/regularized gamma and beta, plus `CDF`/`Quantile` on the two discrete probability distributions).
122
+
123
+ [View the complete function reference with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
124
+
125
+ ## Restricting Available Functions
126
+
127
+ Pass `blacklist` to disable specific constructs for a solver instance — useful when evaluating expressions from a source you don't fully trust, or when your deployment simply doesn't want certain functions exposed:
105
128
 
106
129
  ```python
107
- from mathjson_solver import translate_v1_mathjson
130
+ solver = create_solver(parameters, blacklist=["PowerSet", "Permutations", "Combinations", "CartesianProduct"])
131
+ solver(["PowerSet", ["Array", 1, 2, 3]])
132
+ # Raises: MathJSONException: Problem in PowerSet. [...]. 'PowerSet' has been disabled in this solver instance.
108
133
 
109
- translate_v1_mathjson(["Add", ["Log", 8], 1]) # ["Add", ["Ln", 8], 1]
134
+ solver(["Add", 1, 2]) # unaffected constructs still work: 3.0
110
135
  ```
111
136
 
112
- `legacy_v1=True` only affects `Log`. Every other 1.x expression already evaluates identically on 2.x without any translation.
137
+ **This is an access-policy control, not a resource limiter.** Blacklisting a construct stops it from running at all; it doesn't make an *enabled* construct safe against pathological input. In particular, the enumeration functions (`PowerSet`, `Permutations`, `Combinations`, `CartesianProduct`) have no built-in output-size limit — `["PowerSet", ["Range", 30]]` will try to materialize over a billion subsets if you let it run. If you're evaluating expressions from an untrusted source, blacklist any construct whose worst-case cost you haven't reasoned about, rather than assuming everything implemented is safe by default for every threat model.
113
138
 
114
- ## Supported Operations
115
-
116
- The library supports a comprehensive set of mathematical operations:
117
-
118
- * **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
119
- * **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
120
- * **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
121
- * **Comparison:** Equal, StrictEqual, IdenticallyEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual, Congruent
122
- * **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In/Element, NotIn/NotElement, ContainsAnyOf, ContainsAllOf, ContainsNoneOf, bare `True`/`False` literals, Union, Intersection, SetMinus, SymmetricDifference (over arrays - no dedicated Set type)
123
- * **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Mode, Variance, StandardDeviation, PopulationVariance, PopulationStandardDeviation, Quartiles, InterquartileRange, Covariance, Correlation, Length/Count
124
- * **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
125
- * **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended/Append, First, Second, Third, Last, Rest, Most, Reverse, Sort, Unique, Dedup, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct, Take, Drop, TakeWhile, DropWhile, Contains, IndexOf, IndexWhere, Find, CountIf, Position, RotateLeft, RotateRight, MaxBy, MinBy, ArgMax, ArgMin, Ordering, FlatMap, Scan, Differences, Fold, Insert, DeleteAt, ReplaceAt, Partition, Chunk, GroupBy, ChunkBy, Tally
126
- * **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch/StrictSwitch (value-equality case dispatch), Which (CortexJS flat condition/value chain), Constants definition
127
- * **Type Conversion:** Int, Float, Str, IsDefined
128
- * **Strings:** String, StringJoin, ToUpperCase, ToLowerCase, CaseFold, Trim, TrimStart, TrimEnd, StringSplit, StringReplace, StringCompare, StringRepeat, PadStart, PadEnd, Characters/GraphemeClusters, Utf8, Utf16, UnicodeScalars, StringFrom, IntegerString, DigitsFrom, NumberFrom
129
- * **Pattern Matching (requires the optional `regex` extra, `pip install mathjson-solver[regex]`):** RegExp, IsMatch, StringMatch, StringMatchAll — backed by [RE2](https://github.com/google/re2) rather than Python's `re`, for a hard guarantee against catastrophic backtracking (no backreferences/lookaround, as a deliberate trade-off for that guarantee)
130
- * **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
131
- * **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc, Rational, Numerator, Denominator, MachineEpsilon, CatalanConstant, EulerGamma
132
- * **Integration (requires the optional `integration` extra, `pip install mathjson-solver[integration]`):** TrapezoidalIntegrate. Also in this group but with no extra dependency: Interp, FindIntervalIndex, Variable references
133
- * **Advanced:** HasMatchingSublist for pattern matching
134
- * **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
135
-
136
- [View complete documentation with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
139
+ A blacklisted name that isn't an actual construct (a typo, for instance) is silently ignored rather than rejected — `blacklist` isn't validated against the list of implemented constructs.
137
140
 
138
141
  ## Error Handling
139
142
 
@@ -157,13 +160,28 @@ except MathJSONException as e:
157
160
  print(f"Unsupported operation: {e}")
158
161
  ```
159
162
 
160
- ## Use Cases
163
+ ## Migrating from 1.x
161
164
 
162
- * **Dynamic Formulas:** Let users create custom calculations in web applications
163
- * **Scientific Computing:** Evaluate mathematical models with variable parameters
164
- * **Business Logic:** Process complex pricing rules or scoring algorithms
165
- * **Data Processing:** Apply mathematical transformations to datasets
166
- * **Health Applications:** Calculate medical scores, dosages, or risk assessments
165
+ > **Version 2 introduced a breaking change:** `Log` is now log base 10 instead of natural log (see [CHANGELOG.md](CHANGELOG.md)). Bugfix releases for the 1.x line continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
166
+
167
+ Version 2.0.0's only breaking change is `Log`: pre-2.0.0 it was always natural log, `["Log", x]` == `math.log(x)`. From 2.0.0 on it matches [CortexJS](https://cortexjs.io/compute-engine/) — `["Log", x]` is log base 10, `["Log", x, b]` is log base `b` — and natural log moved to `Ln`.
168
+
169
+ If you have existing expressions built for 1.x and don't want to hand-edit every `Log` node just to pick up functions added in 2.x (`Product`, the CortexJS forms of `If`/`Map`/`Filter`/`Reduce`, the new aliases, etc.), pass `legacy_v1=True` when creating the solver. It rewrites every `["Log", x]` to `["Ln", x]` before evaluating, so old expressions keep producing the same results without modification:
170
+
171
+ ```python
172
+ solver = create_solver(parameters, legacy_v1=True)
173
+ solver(["Log", 8]) # 2.0794... (natural log, matching pre-2.0.0 behavior)
174
+ ```
175
+
176
+ You can also run the rewrite yourself and inspect or store the translated expression:
177
+
178
+ ```python
179
+ from mathjson_solver import translate_v1_mathjson
180
+
181
+ translate_v1_mathjson(["Add", ["Log", 8], 1]) # ["Add", ["Ln", 8], 1]
182
+ ```
183
+
184
+ `legacy_v1=True` only affects `Log`. Every other 1.x expression already evaluates identically on 2.x without any translation.
167
185
 
168
186
  ## Testing
169
187
 
@@ -196,6 +214,8 @@ We welcome contributions! Please feel free to:
196
214
 
197
215
  We also created [`londec`](https://pypi.org/project/londec/) — evaluate tree-structured conditions against an ordered history of events. It uses mathjson-solver internally.
198
216
 
217
+ [`mathjson-tree-builder`](https://www.npmjs.com/package/mathjson-tree-builder) is a fully compatible frontend counterpart — a framework-agnostic, click-to-build editor for authoring MathJSON expressions in the browser.
218
+
199
219
  ## License
200
220
 
201
221
  [View license information](https://github.com/LongenesisLtd/mathjson-solver/blob/main/LICENSE)
@@ -2,26 +2,37 @@
2
2
 
3
3
  [![PyPI](https://img.shields.io/pypi/v/mathjson-solver.svg)](https://pypi.org/project/mathjson-solver/)
4
4
  [![PyPI Downloads](https://static.pepy.tech/badge/mathjson-solver/month)](https://pepy.tech/projects/mathjson-solver)
5
- [![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)
6
-
7
- > **Heads up:** Version 2 introduces a breaking change (see [CHANGELOG.md](CHANGELOG.md)) as part of steering back towards greater compatibility with [CortexJS MathJSON](https://cortexjs.io/compute-engine/): `Log` is now log base 10 instead of natural log. Stuck on pre-2.0.0 expressions but want the functions added in 2.x? Pass `legacy_v1=True` to `create_solver()` (see [Migrating from 1.x](#migrating-from-1x)) instead of hand-migrating every expression. Bugfix releases for the 1.x line also continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
8
6
 
9
7
  A reliable Python library for numerically evaluating mathematical expressions in MathJSON format. Perfect for applications that need to safely execute user-provided formulas, calculate dynamic equations, or process mathematical data.
10
8
 
11
9
  **What is MathJSON?** MathJSON represents mathematical expressions as JSON arrays, like `["Add", 1, 2, 3]` for 1+2+3. This format is safe, structured, and easy to generate programmatically.
12
10
 
11
+ Coming from 1.x? Version 2 changed `Log`'s meaning — see [Migrating from 1.x](#migrating-from-1x).
12
+
13
13
  ## Table of Contents
14
+ - [Use Cases](#use-cases)
14
15
  - [Installation](#installation)
15
16
  - [Quick Start](#quick-start)
16
- - [Migrating from 1.x](#migrating-from-1x)
17
17
  - [Supported Operations](#supported-operations)
18
+ - [Restricting Available Functions](#restricting-available-functions)
18
19
  - [Error Handling](#error-handling)
19
- - [Use Cases](#use-cases)
20
+ - [Migrating from 1.x](#migrating-from-1x)
20
21
  - [Testing](#testing)
21
22
  - [Community](#community)
22
23
  - [Contributing](#contributing)
23
24
  - [Related Projects](#related-projects)
24
25
 
26
+ ## Use Cases
27
+
28
+ **The core pattern:** if your Python backend accepts user-provided datapoints *and* user-provided math to apply to them, mathjson-solver is the engine for that — it evaluates the formula without needing to trust either the formula's author or the data's source. A survey platform is a natural fit: a survey and its "calculated answers" both come from the same untrusted party (the survey builder), the calculation runs against whatever the respondent enters, and the result has to be safe to compute no matter what either of them contains. The same shape covers pricing rules, scoring algorithms, and scientific or medical calculators wherever the formula itself isn't fixed at development time — our showcase example is a breast-cancer risk calculator implementing the [Gail model](https://github.com/LongenesisLtd/mathjson-solver/blob/main/tests/test_gail_model.py), numerical integration included, entirely in MathJSON.
29
+
30
+ * **Dynamic Formulas:** Let users create custom calculations in web applications
31
+ * **Scientific Computing:** Evaluate mathematical models with variable parameters
32
+ * **Business Logic:** Process complex pricing rules or scoring algorithms
33
+ * **Data Processing:** Apply mathematical transformations to datasets
34
+ * **Health Applications:** Calculate medical scores, dosages, or risk assessments
35
+
25
36
  ## Installation
26
37
 
27
38
  ```bash
@@ -33,6 +44,9 @@ pip install mathjson-solver
33
44
  **Optional:**
34
45
  - `pip install mathjson-solver[integration]` (installs numpy; only required for `TrapezoidalIntegrate`)
35
46
  - `pip install mathjson-solver[regex]` (installs [google-re2](https://pypi.org/project/google-re2/); only required for `RegExp`/`IsMatch`/`StringMatch`/`StringMatchAll`)
47
+ - `pip install mathjson-solver[special-functions]` (installs [scipy](https://scipy.org/); required for `BesselJ`/`BesselY`/`BesselI`/`BesselK`, `AiryAi`/`AiryBi`/`AiryAiPrime`/`AiryBiPrime`, `Zeta`, `GammaRegularized`, `BetaRegularized`, and `CDF`/`Quantile` on `BinomialDistribution`/`PoissonDistribution`)
48
+
49
+ Combine any of these by separating them with commas in one `pip install`, e.g. `pip install mathjson-solver[integration,regex,special-functions]` for all three at once.
36
50
 
37
51
  ## Quick Start
38
52
 
@@ -72,50 +86,37 @@ solver(["Map", ["Array", 1, 2, 3, 4], ["Function", ["Multiply", "_", 2]]]) # [2
72
86
  solver(["Reduce", ["Array", 1, 2, 3, 4], ["Add"]]) # 10
73
87
  ```
74
88
 
75
- ## Migrating from 1.x
76
-
77
- Version 2.0.0's only breaking change is `Log`: pre-2.0.0 it was always natural log, `["Log", x]` == `math.log(x)`. From 2.0.0 on it matches [CortexJS](https://cortexjs.io/compute-engine/) — `["Log", x]` is log base 10, `["Log", x, b]` is log base `b` — and natural log moved to `Ln`.
89
+ ## Supported Operations
78
90
 
79
- If you have existing expressions built for 1.x and don't want to hand-edit every `Log` node just to pick up functions added in 2.x (`Product`, the CortexJS forms of `If`/`Map`/`Filter`/`Reduce`, the new aliases, etc.), pass `legacy_v1=True` when creating the solver. It rewrites every `["Log", x]` to `["Ln", x]` before evaluating, so old expressions keep producing the same results without modification:
91
+ 338 MathJSON constructs across arithmetic, trigonometry, logarithms, comparisons, logic and sets, statistics and probability distributions, functional programming (Map/Reduce/Filter), arrays and collections, control flow, strings and RE2-backed pattern matching, date/time, number theory, special functions (Bessel/Airy/Gamma/elliptic-integral/hypergeometric families), combinatorics, and structural introspection.
80
92
 
81
93
  ```python
82
- solver = create_solver(parameters, legacy_v1=True)
83
- solver(["Log", 8]) # 2.0794... (natural log, matching pre-2.0.0 behavior)
94
+ ["Add", 1, 2, ["Multiply", 3, 4]] # 15
95
+ ["CDF", ["NormalDistribution", 0, 1], 1.96] # 0.975 (z-score to percentile)
96
+ ["Reduce", ["Array", 1, 2, 3, 4], ["Add"]] # 10
97
+ ["StringMatch", "patient-042", "[0-9]+"] # "042" at position 9-11
98
+ ["FactorInteger", 360] # [[2,3], [3,2], [5,1]] (2³·3²·5)
84
99
  ```
85
100
 
86
- You can also run the rewrite yourself and inspect or store the translated expression:
101
+ Three optional extras unlock specific functions — see [Installation](#installation) above: `regex` (RE2-backed pattern matching), `integration` (`TrapezoidalIntegrate`), `special-functions` (Bessel/Airy/Zeta/regularized gamma and beta, plus `CDF`/`Quantile` on the two discrete probability distributions).
102
+
103
+ [View the complete function reference with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
104
+
105
+ ## Restricting Available Functions
106
+
107
+ Pass `blacklist` to disable specific constructs for a solver instance — useful when evaluating expressions from a source you don't fully trust, or when your deployment simply doesn't want certain functions exposed:
87
108
 
88
109
  ```python
89
- from mathjson_solver import translate_v1_mathjson
110
+ solver = create_solver(parameters, blacklist=["PowerSet", "Permutations", "Combinations", "CartesianProduct"])
111
+ solver(["PowerSet", ["Array", 1, 2, 3]])
112
+ # Raises: MathJSONException: Problem in PowerSet. [...]. 'PowerSet' has been disabled in this solver instance.
90
113
 
91
- translate_v1_mathjson(["Add", ["Log", 8], 1]) # ["Add", ["Ln", 8], 1]
114
+ solver(["Add", 1, 2]) # unaffected constructs still work: 3.0
92
115
  ```
93
116
 
94
- `legacy_v1=True` only affects `Log`. Every other 1.x expression already evaluates identically on 2.x without any translation.
117
+ **This is an access-policy control, not a resource limiter.** Blacklisting a construct stops it from running at all; it doesn't make an *enabled* construct safe against pathological input. In particular, the enumeration functions (`PowerSet`, `Permutations`, `Combinations`, `CartesianProduct`) have no built-in output-size limit — `["PowerSet", ["Range", 30]]` will try to materialize over a billion subsets if you let it run. If you're evaluating expressions from an untrusted source, blacklist any construct whose worst-case cost you haven't reasoned about, rather than assuming everything implemented is safe by default for every threat model.
95
118
 
96
- ## Supported Operations
97
-
98
- The library supports a comprehensive set of mathematical operations:
99
-
100
- * **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
101
- * **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
102
- * **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
103
- * **Comparison:** Equal, StrictEqual, IdenticallyEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual, Congruent
104
- * **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In/Element, NotIn/NotElement, ContainsAnyOf, ContainsAllOf, ContainsNoneOf, bare `True`/`False` literals, Union, Intersection, SetMinus, SymmetricDifference (over arrays - no dedicated Set type)
105
- * **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Mode, Variance, StandardDeviation, PopulationVariance, PopulationStandardDeviation, Quartiles, InterquartileRange, Covariance, Correlation, Length/Count
106
- * **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
107
- * **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended/Append, First, Second, Third, Last, Rest, Most, Reverse, Sort, Unique, Dedup, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct, Take, Drop, TakeWhile, DropWhile, Contains, IndexOf, IndexWhere, Find, CountIf, Position, RotateLeft, RotateRight, MaxBy, MinBy, ArgMax, ArgMin, Ordering, FlatMap, Scan, Differences, Fold, Insert, DeleteAt, ReplaceAt, Partition, Chunk, GroupBy, ChunkBy, Tally
108
- * **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch/StrictSwitch (value-equality case dispatch), Which (CortexJS flat condition/value chain), Constants definition
109
- * **Type Conversion:** Int, Float, Str, IsDefined
110
- * **Strings:** String, StringJoin, ToUpperCase, ToLowerCase, CaseFold, Trim, TrimStart, TrimEnd, StringSplit, StringReplace, StringCompare, StringRepeat, PadStart, PadEnd, Characters/GraphemeClusters, Utf8, Utf16, UnicodeScalars, StringFrom, IntegerString, DigitsFrom, NumberFrom
111
- * **Pattern Matching (requires the optional `regex` extra, `pip install mathjson-solver[regex]`):** RegExp, IsMatch, StringMatch, StringMatchAll — backed by [RE2](https://github.com/google/re2) rather than Python's `re`, for a hard guarantee against catastrophic backtracking (no backreferences/lookaround, as a deliberate trade-off for that guarantee)
112
- * **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
113
- * **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc, Rational, Numerator, Denominator, MachineEpsilon, CatalanConstant, EulerGamma
114
- * **Integration (requires the optional `integration` extra, `pip install mathjson-solver[integration]`):** TrapezoidalIntegrate. Also in this group but with no extra dependency: Interp, FindIntervalIndex, Variable references
115
- * **Advanced:** HasMatchingSublist for pattern matching
116
- * **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
117
-
118
- [View complete documentation with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
119
+ A blacklisted name that isn't an actual construct (a typo, for instance) is silently ignored rather than rejected — `blacklist` isn't validated against the list of implemented constructs.
119
120
 
120
121
  ## Error Handling
121
122
 
@@ -139,13 +140,28 @@ except MathJSONException as e:
139
140
  print(f"Unsupported operation: {e}")
140
141
  ```
141
142
 
142
- ## Use Cases
143
+ ## Migrating from 1.x
143
144
 
144
- * **Dynamic Formulas:** Let users create custom calculations in web applications
145
- * **Scientific Computing:** Evaluate mathematical models with variable parameters
146
- * **Business Logic:** Process complex pricing rules or scoring algorithms
147
- * **Data Processing:** Apply mathematical transformations to datasets
148
- * **Health Applications:** Calculate medical scores, dosages, or risk assessments
145
+ > **Version 2 introduced a breaking change:** `Log` is now log base 10 instead of natural log (see [CHANGELOG.md](CHANGELOG.md)). Bugfix releases for the 1.x line continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
146
+
147
+ Version 2.0.0's only breaking change is `Log`: pre-2.0.0 it was always natural log, `["Log", x]` == `math.log(x)`. From 2.0.0 on it matches [CortexJS](https://cortexjs.io/compute-engine/) — `["Log", x]` is log base 10, `["Log", x, b]` is log base `b` — and natural log moved to `Ln`.
148
+
149
+ If you have existing expressions built for 1.x and don't want to hand-edit every `Log` node just to pick up functions added in 2.x (`Product`, the CortexJS forms of `If`/`Map`/`Filter`/`Reduce`, the new aliases, etc.), pass `legacy_v1=True` when creating the solver. It rewrites every `["Log", x]` to `["Ln", x]` before evaluating, so old expressions keep producing the same results without modification:
150
+
151
+ ```python
152
+ solver = create_solver(parameters, legacy_v1=True)
153
+ solver(["Log", 8]) # 2.0794... (natural log, matching pre-2.0.0 behavior)
154
+ ```
155
+
156
+ You can also run the rewrite yourself and inspect or store the translated expression:
157
+
158
+ ```python
159
+ from mathjson_solver import translate_v1_mathjson
160
+
161
+ translate_v1_mathjson(["Add", ["Log", 8], 1]) # ["Add", ["Ln", 8], 1]
162
+ ```
163
+
164
+ `legacy_v1=True` only affects `Log`. Every other 1.x expression already evaluates identically on 2.x without any translation.
149
165
 
150
166
  ## Testing
151
167
 
@@ -178,6 +194,8 @@ We welcome contributions! Please feel free to:
178
194
 
179
195
  We also created [`londec`](https://pypi.org/project/londec/) — evaluate tree-structured conditions against an ordered history of events. It uses mathjson-solver internally.
180
196
 
197
+ [`mathjson-tree-builder`](https://www.npmjs.com/package/mathjson-tree-builder) is a fully compatible frontend counterpart — a framework-agnostic, click-to-build editor for authoring MathJSON expressions in the browser.
198
+
181
199
  ## License
182
200
 
183
201
  [View license information](https://github.com/LongenesisLtd/mathjson-solver/blob/main/LICENSE)
@@ -5,8 +5,9 @@
5
5
 
6
6
  | Version | Supported |
7
7
  | ------- | ------------------ |
8
- | 1.20.x | :white_check_mark: |
9
- | < 1.20.x | :x: |
8
+ | 2.x | :white_check_mark: |
9
+ | 1.20.x | :white_check_mark: |
10
+ | < 1.20.x | :x: |
10
11
 
11
12
 
12
13
  ## Reporting a Vulnerability