mathjson-solver 1.20.2__tar.gz → 2.1.1__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.
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/.gitignore +6 -0
- mathjson_solver-2.1.1/CHANGELOG.md +62 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/PKG-INFO +16 -9
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/README.md +15 -8
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/docs/README.md +298 -26
- mathjson_solver-2.1.1/pyproject.toml +41 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/src/mathjson_solver/__main__.py +446 -29
- mathjson_solver-2.1.1/tests/test_cortexjs_compat.py +88 -0
- mathjson_solver-2.1.1/tests/test_cortexjs_tier3.py +158 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_simple_cases.py +5 -1
- mathjson_solver-1.20.2/.claude/settings.local.json +0 -7
- mathjson_solver-1.20.2/.github/ISSUE_TEMPLATE/bug_report.md +0 -25
- mathjson_solver-1.20.2/.github/workflows/python-app.yml +0 -33
- mathjson_solver-1.20.2/.github/workflows/test-coverage.yml +0 -51
- mathjson_solver-1.20.2/logo.png +0 -0
- mathjson_solver-1.20.2/logo.svg +0 -105
- mathjson_solver-1.20.2/pyproject.toml +0 -20
- mathjson_solver-1.20.2/untracked/activity_stuff.json +0 -2156
- mathjson_solver-1.20.2/untracked/ehab312.pdf +0 -0
- mathjson_solver-1.20.2/untracked/ehab312_supplementary_data/ehab312-suppl_data/Supplementary material_20210604_v2.docx +0 -0
- mathjson_solver-1.20.2/untracked/score2-op.json +0 -968
- mathjson_solver-1.20.2/untracked/score2.json +0 -976
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/CODE_OF_CONDUCT.md +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/CONTRIBUTING.md +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/LICENSE +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/SECURITY.md +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/docs/integration-test-cases.md +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/src/mathjson_solver/__init__.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_TrapezoidalIntegratel.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_atindex.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_cumulative.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_datetime.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_equal.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_exceptions.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_extract_variables.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_findinterval.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_gail_model.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_interpolate.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_range.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_reduce_simple.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_scalars.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_sets.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_slice.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_state_tuples_reduce.py +0 -0
- {mathjson_solver-1.20.2 → mathjson_solver-2.1.1}/tests/test_with_pytest.py +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## [2.1.1] - 2026-08-19
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed packaging: the sdist now only includes the intended package, tests, docs, and metadata files.
|
|
13
|
+
|
|
14
|
+
[2.1.1]: https://github.com/LongenesisLtd/mathjson-solver/compare/v2.1.0...v2.1.1
|
|
15
|
+
|
|
16
|
+
## [2.1.0] - 2026-08-19
|
|
17
|
+
|
|
18
|
+
Continues the CortexJS compatibility pass: `If`, `Map`, `Filter`, and `Reduce` now also accept CortexJS calling conventions, alongside the existing Python-specific forms.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **Correctness fix:** a locally-bound name (a `Constants` binding, a `Reduce` accumulator/current/index variable, or a `Function` parameter, see below) now correctly shadows a top-level solver parameter of the same name, instead of the global value silently winning. Previously `create_solver({"x": 5})` evaluating `["Constants", ["x", 100], ["Add", "x", 1]]` returned `6` instead of `101`. If you were unknowingly relying on the old (backwards) precedence, this will change your result.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **`Function`**: now a real CortexJS-style lambda, `["Function", body, param1, param2, ...]`. With no parameter names, `body` can reference its arguments via the anonymous placeholders `"_"` (first argument only) and `"_1"`, `"_2"`, ... Meant to be passed as the function argument to `Map`, `Filter`, and `Reduce`; evaluated on its own it returns unevaluated. (Previously a non-functional stub that always returned `0`.)
|
|
27
|
+
- **`If`**: now also accepts the CortexJS flat form, `["If", cond, then]` / `["If", cond, then, else]`, including the no-else form (returns `None`/CortexJS `Nothing` when the condition is false). The existing Python pair form, `["If", [cond, val], ..., else_val]`, is unchanged and detected automatically. (Note: a Python-form condition that is a bare parameter reference, e.g. `["If", ["my_flag", "yes"], "no"]`, is still correctly disambiguated — but wrapping such conditions in `IsTrue`/`IsFalse` remains the clearer style.)
|
|
28
|
+
- **`Map` / `StrictMap` / `Filter`**: the function argument can now be a `["Function", ...]` expression (see above), in addition to the existing call-template form (e.g. `["Square"]`).
|
|
29
|
+
- **`Reduce`**: now also accepts the CortexJS form, `["Reduce", collection, fn]` / `["Reduce", collection, fn, initial]`, where `fn` is applied as `fn(accumulator, current_item)` (call-template or `Function` form). Without an initial value, the first element seeds the accumulator. The existing 6-argument Python form (with named accumulator/current/index variables) is unchanged and detected automatically via argument count.
|
|
30
|
+
- **`Product`**: `["Product", array]` multiplies together the numeric elements of `array`.
|
|
31
|
+
|
|
32
|
+
[2.1.0]: https://github.com/LongenesisLtd/mathjson-solver/compare/v2.0.0...v2.1.0
|
|
33
|
+
|
|
34
|
+
## [2.0.0] - 2026-08-19
|
|
35
|
+
|
|
36
|
+
Steers the solver back towards greater compatibility with [CortexJS MathJSON](https://cortexjs.io/compute-engine/), adding aliases and constructs that were previously CortexJS-only.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- **BREAKING:** `Log` now matches CortexJS: `["Log", x]` is log base 10, and `["Log", x, b]` is log base `b`. Previously `Log` was natural log; use `Ln` for that.
|
|
41
|
+
- `Max` and `Min` now also accept a variadic (CortexJS) form, e.g. `["Max", 5, 2, -1]`, in addition to the existing single-array form.
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- CortexJS aliases: `Lb` (`Log2`), `Lg` (`Log10`), `List` (`Array`), `Mean` (`Average`), `Count` (`Length`), `Which` (`Switch`).
|
|
46
|
+
- New math functions: `LogOnePlus`, `Chop`, `Mod`, `Clamp`, `GCD`, `LCM`, `Factorial`, `Binomial`, `IsPrime`, `Erf`, `Erfc`.
|
|
47
|
+
- New logic functions: `Xor`, `Nand`, `Nor`, `Implies`, `Equivalent`.
|
|
48
|
+
- New trigonometric functions: `Arctan2`, `Cot`, `Sec`, `Csc`, `Arccot`, `Arcsec`, `Arccsc`, `Sinh`, `Cosh`, `Tanh`, `Coth`, `Sech`, `Csch`, `Arsinh`, `Arcosh`, `Artanh`, `Arcoth`, `Arsech`, `Arcsch`, `Hypot`, `Sinc`.
|
|
49
|
+
- New constants: `Degrees`, `ExponentialE`, `GoldenRatio`.
|
|
50
|
+
- New statistics: `Variance`, `StandardDeviation`.
|
|
51
|
+
- New array/collection functions: `First`, `Last`, `Rest`, `Most`, `Reverse`, `Sort`, `IsEmpty`, `Range` (CortexJS-compatible, distinct from `GenerateRange`), `Join`, `Unique`, `Zip`, `At` (1-indexed, distinct from `AtIndex`).
|
|
52
|
+
|
|
53
|
+
[2.0.0]: https://github.com/LongenesisLtd/mathjson-solver/compare/v1.20.2...v2.0.0
|
|
54
|
+
|
|
55
|
+
## [1.20.2] - 2026-08-18
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- Fix `extract_variables` for Constants (thanks [@nkimdwave](https://github.com/nkimdwave)!)
|
|
60
|
+
- Add missing functions to constructs in `extract_variables` (thanks [@nkimdwave](https://github.com/nkimdwave)!)
|
|
61
|
+
|
|
62
|
+
[1.20.2]: https://github.com/LongenesisLtd/mathjson-solver/compare/461bc00...v1.20.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mathjson-solver
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 2.1.1
|
|
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
|
|
@@ -18,6 +18,8 @@ Description-Content-Type: text/markdown
|
|
|
18
18
|
[](https://pepy.tech/projects/mathjson-solver)
|
|
19
19
|
[](https://www.python.org/downloads/)
|
|
20
20
|
|
|
21
|
+
> **Heads up:** Version 2 introduces a few breaking changes (see [CHANGELOG.md](CHANGELOG.md)) as part of steering back towards greater compatibility with [CortexJS MathJSON](https://cortexjs.io/compute-engine/). If you need to stay on the old behavior, bugfix releases for the 1.x line continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
|
|
22
|
+
|
|
21
23
|
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.
|
|
22
24
|
|
|
23
25
|
**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.
|
|
@@ -74,6 +76,10 @@ except MathJSONException as e:
|
|
|
74
76
|
solver(["Map", ["Array", 1, 2, 3, 4], ["Multiply"], 2]) # [2, 4, 6, 8]
|
|
75
77
|
solver(["Reduce", ["Array", 1, 2, 3, 4], 0, ["Add", "acc", "item"],
|
|
76
78
|
["Variable", "acc"], ["Variable", "item"], ["Variable", "i"]]) # 10
|
|
79
|
+
|
|
80
|
+
# CortexJS-style forms also work: a lambda via Function, and a 2-argument Reduce
|
|
81
|
+
solver(["Map", ["Array", 1, 2, 3, 4], ["Function", ["Multiply", "_", 2]]]) # [2, 4, 6, 8]
|
|
82
|
+
solver(["Reduce", ["Array", 1, 2, 3, 4], ["Add"]]) # 10
|
|
77
83
|
```
|
|
78
84
|
|
|
79
85
|
## Supported Operations
|
|
@@ -81,19 +87,20 @@ solver(["Reduce", ["Array", 1, 2, 3, 4], 0, ["Add", "acc", "item"],
|
|
|
81
87
|
The library supports a comprehensive set of mathematical operations:
|
|
82
88
|
|
|
83
89
|
* **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
|
|
84
|
-
* **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan
|
|
85
|
-
* **Logarithms:** Log, Log2, Log10, Exp
|
|
90
|
+
* **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
|
|
91
|
+
* **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
|
|
86
92
|
* **Comparison:** Equal, StrictEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual
|
|
87
|
-
* **Logic & Sets:** Any, All, Not, And, Or, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
|
|
88
|
-
* **Statistics:** Average, Max, Min, Median, Length
|
|
89
|
-
* **Functional Programming:** Map, Reduce, Filter
|
|
90
|
-
* **Arrays:** Array creation, GenerateRange, AtIndex, Slice, Appended, CumulativeSum, CumulativeProduct
|
|
91
|
-
* **Control Flow:** If statements, Switch-Case, Constants definition
|
|
93
|
+
* **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
|
|
94
|
+
* **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Variance, StandardDeviation, Length/Count
|
|
95
|
+
* **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
|
|
96
|
+
* **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended, First, Last, Rest, Most, Reverse, Sort, Unique, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct
|
|
97
|
+
* **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch-Case/Which, Constants definition
|
|
92
98
|
* **Type Conversion:** Int, Float, Str, IsDefined
|
|
93
99
|
* **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
|
|
100
|
+
* **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc
|
|
94
101
|
* **Integration:** TrapezoidalIntegrate (requires numpy), Interp, FindIntervalIndex, Variable references
|
|
95
102
|
* **Advanced:** HasMatchingSublist for pattern matching
|
|
96
|
-
* **Constants:** Pi
|
|
103
|
+
* **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
|
|
97
104
|
|
|
98
105
|
[View complete documentation with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
|
|
99
106
|
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://pepy.tech/projects/mathjson-solver)
|
|
5
5
|
[](https://www.python.org/downloads/)
|
|
6
6
|
|
|
7
|
+
> **Heads up:** Version 2 introduces a few breaking changes (see [CHANGELOG.md](CHANGELOG.md)) as part of steering back towards greater compatibility with [CortexJS MathJSON](https://cortexjs.io/compute-engine/). If you need to stay on the old behavior, bugfix releases for the 1.x line continue on the [`1.x` branch](https://github.com/LongenesisLtd/mathjson-solver/tree/1.x).
|
|
8
|
+
|
|
7
9
|
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.
|
|
8
10
|
|
|
9
11
|
**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.
|
|
@@ -60,6 +62,10 @@ except MathJSONException as e:
|
|
|
60
62
|
solver(["Map", ["Array", 1, 2, 3, 4], ["Multiply"], 2]) # [2, 4, 6, 8]
|
|
61
63
|
solver(["Reduce", ["Array", 1, 2, 3, 4], 0, ["Add", "acc", "item"],
|
|
62
64
|
["Variable", "acc"], ["Variable", "item"], ["Variable", "i"]]) # 10
|
|
65
|
+
|
|
66
|
+
# CortexJS-style forms also work: a lambda via Function, and a 2-argument Reduce
|
|
67
|
+
solver(["Map", ["Array", 1, 2, 3, 4], ["Function", ["Multiply", "_", 2]]]) # [2, 4, 6, 8]
|
|
68
|
+
solver(["Reduce", ["Array", 1, 2, 3, 4], ["Add"]]) # 10
|
|
63
69
|
```
|
|
64
70
|
|
|
65
71
|
## Supported Operations
|
|
@@ -67,19 +73,20 @@ solver(["Reduce", ["Array", 1, 2, 3, 4], 0, ["Add", "acc", "item"],
|
|
|
67
73
|
The library supports a comprehensive set of mathematical operations:
|
|
68
74
|
|
|
69
75
|
* **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
|
|
70
|
-
* **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan
|
|
71
|
-
* **Logarithms:** Log, Log2, Log10, Exp
|
|
76
|
+
* **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
|
|
77
|
+
* **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
|
|
72
78
|
* **Comparison:** Equal, StrictEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual
|
|
73
|
-
* **Logic & Sets:** Any, All, Not, And, Or, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
|
|
74
|
-
* **Statistics:** Average, Max, Min, Median, Length
|
|
75
|
-
* **Functional Programming:** Map, Reduce, Filter
|
|
76
|
-
* **Arrays:** Array creation, GenerateRange, AtIndex, Slice, Appended, CumulativeSum, CumulativeProduct
|
|
77
|
-
* **Control Flow:** If statements, Switch-Case, Constants definition
|
|
79
|
+
* **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
|
|
80
|
+
* **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Variance, StandardDeviation, Length/Count
|
|
81
|
+
* **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
|
|
82
|
+
* **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended, First, Last, Rest, Most, Reverse, Sort, Unique, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct
|
|
83
|
+
* **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch-Case/Which, Constants definition
|
|
78
84
|
* **Type Conversion:** Int, Float, Str, IsDefined
|
|
79
85
|
* **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
|
|
86
|
+
* **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc
|
|
80
87
|
* **Integration:** TrapezoidalIntegrate (requires numpy), Interp, FindIntervalIndex, Variable references
|
|
81
88
|
* **Advanced:** HasMatchingSublist for pattern matching
|
|
82
|
-
* **Constants:** Pi
|
|
89
|
+
* **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
|
|
83
90
|
|
|
84
91
|
[View complete documentation with examples →](https://github.com/LongenesisLtd/mathjson-solver/blob/main/docs/README.md)
|
|
85
92
|
|