mathjson-solver 2.2.0__tar.gz → 2.2.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.
Files changed (39) hide show
  1. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/CHANGELOG.md +31 -0
  2. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/PKG-INFO +19 -11
  3. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/README.md +13 -9
  4. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/docs/README.md +362 -12
  5. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/pyproject.toml +14 -2
  6. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/src/mathjson_solver/__main__.py +1118 -3
  7. mathjson_solver-2.2.1/tests/test_cortexjs_collections.py +156 -0
  8. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_cortexjs_compat.py +22 -1
  9. mathjson_solver-2.2.1/tests/test_cortexjs_constants_relations.py +47 -0
  10. mathjson_solver-2.2.1/tests/test_cortexjs_sets.py +68 -0
  11. mathjson_solver-2.2.1/tests/test_cortexjs_statistics.py +75 -0
  12. mathjson_solver-2.2.1/tests/test_cortexjs_strings.py +172 -0
  13. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_cortexjs_tier3.py +55 -0
  14. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/.gitignore +0 -0
  15. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/CODE_OF_CONDUCT.md +0 -0
  16. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/CONTRIBUTING.md +0 -0
  17. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/LICENSE +0 -0
  18. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/SECURITY.md +0 -0
  19. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/docs/integration-test-cases.md +0 -0
  20. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/src/mathjson_solver/__init__.py +0 -0
  21. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_TrapezoidalIntegratel.py +0 -0
  22. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_atindex.py +0 -0
  23. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_cumulative.py +0 -0
  24. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_datetime.py +0 -0
  25. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_equal.py +0 -0
  26. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_exceptions.py +0 -0
  27. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_extract_variables.py +0 -0
  28. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_findinterval.py +0 -0
  29. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_gail_model.py +0 -0
  30. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_interpolate.py +0 -0
  31. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_legacy_compat.py +0 -0
  32. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_range.py +0 -0
  33. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_reduce_simple.py +0 -0
  34. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_scalars.py +0 -0
  35. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_sets.py +0 -0
  36. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_simple_cases.py +0 -0
  37. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_slice.py +0 -0
  38. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_state_tuples_reduce.py +0 -0
  39. {mathjson_solver-2.2.0 → mathjson_solver-2.2.1}/tests/test_with_pytest.py +0 -0
@@ -5,6 +5,37 @@ 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.2.1] - 2026-09-14
9
+
10
+ ### Fixed
11
+
12
+ - **`Which`** was aliased to `Switch` (value-equality dispatch: `["Switch", expr, default, [case, val], ...]`) instead of implementing CortexJS's actual flat condition/value chain, `["Which", cond1, val1, cond2, val2, ...]`. It now evaluates each `cond` in order and returns the `val` paired with the first truthy one, or `None` (CortexJS `Nothing`) if none match. If you were relying on the old `Switch`-shaped behavior, use `["Switch", ...]` directly.
13
+ - **`requires-python`** claimed `>=3.6`; the codebase has required Python 3.10 since before this release (a bare `X | Y` union type annotation with no `from __future__ import annotations`, which fails at import time on older versions), and CI has only ever tested 3.10/3.12. Corrected to `>=3.10`. The README's "Requirements: Python 3.7+" had the same problem and is corrected too.
14
+ - **`numpy`** is now declared as a proper optional extra (`integration = ["numpy"]` in `pyproject.toml`, `pip install mathjson-solver[integration]`) instead of an undeclared `try/except ImportError` dependency, and is installed in CI so `TrapezoidalIntegrate`'s tests run there.
15
+
16
+ ### Added
17
+
18
+ - **Bare `True`/`False` boolean literals** - CortexJS's boolean symbols (native JSON `true`/`false` already worked). Reserved: a solver parameter or local variable of the same name can't shadow them.
19
+ - **CortexJS collection functions**, all operating on `Array` and, where they take a function/predicate argument, accepting both the call-template and `Function`-lambda conventions already used by `Map`/`Filter`/`Reduce`:
20
+ - Slicing: `Take`, `Drop`, `TakeWhile`, `DropWhile`
21
+ - Searching: `Contains`, `IndexOf`, `IndexWhere`, `Find`, `CountIf`, `Position`
22
+ - Reordering: `RotateLeft`, `RotateRight`, `MaxBy`, `MinBy`, `ArgMax`, `ArgMin`, `Ordering`
23
+ - Transforming: `FlatMap`, `Scan`, `Differences`, `Fold` (function-first `Reduce`), `Dedup` (consecutive-only, unlike `Unique`)
24
+ - Editing: `Append` (alias for the existing `Appended`), `Insert`, `DeleteAt`, `ReplaceAt`
25
+ - Grouping: `Partition` (fixed chunk size), `Chunk` (fixed group count), `GroupBy`, `ChunkBy`, `Tally`
26
+ - **Basic set algebra** over `Array`: `Union` and `Intersection` (variadic, deduplicated, order-preserving), `SetMinus`, `SymmetricDifference`, and `Element`/`NotElement` (CortexJS's names for the existing `In`/`Not_in`).
27
+ - **`Second`, `Third`**: fixed-position element access alongside `First`/`Last`.
28
+ - **New constants:** `MachineEpsilon`, `CatalanConstant`, `EulerGamma`.
29
+ - **New relations:** `IdenticallyEqual` (like `StrictEqual`, but also requires the same Python type - `1` and `1.0` are `StrictEqual` but not `IdenticallyEqual`), `Congruent` (`["Congruent", a, b, modulus]`, i.e. `a ≡ b (mod modulus)`).
30
+ - **`Rational`, `Numerator`, `Denominator`.** `Rational(n, d)` evaluates to `n / d` (this solver has no rational-number type carried through arithmetic). `Numerator`/`Denominator` read a `Rational` node's declared `n`/`d` exactly when passed one directly; otherwise they reconstruct an approximate fraction from the numeric value.
31
+ - **More statistics:** `Mode`, `PopulationVariance`, `PopulationStandardDeviation`, `Quartiles`, `InterquartileRange`, `Covariance`, `Correlation`.
32
+ - **String functions:** `String`, `StringJoin`, `ToUpperCase`, `ToLowerCase`, `CaseFold`, `Trim`/`TrimStart`/`TrimEnd`, `StringSplit`, `StringReplace` (literal substring, not pattern-based), `StringCompare`, `Characters`/`GraphemeClusters` (Unicode code points, not full grapheme clusters), `Utf8`/`Utf16`/`UnicodeScalars` and their inverse `StringFrom`, `IntegerString`/`DigitsFrom` (base 2-36), `NumberFrom`. `StringRepeat`/`PadStart`/`PadEnd` are capped at 100,000 characters. `Join` stays `Array`-only (unlike CortexJS's polymorphic `Join`); `StringJoin` is the dedicated string name.
33
+ - **Pattern matching: `RegExp`, `IsMatch`, `StringMatch`, `StringMatchAll`**, backed by [RE2](https://github.com/google/re2) rather than Python's `re`, for a hard guarantee against catastrophic backtracking (ReDoS) - at the cost of no backreferences or lookahead/lookbehind. Requires the new `regex` extra: `pip install mathjson-solver[regex]` (installs [`google-re2`](https://pypi.org/project/google-re2/)). `RegExp` compiles a pattern (optional `i`/`m`/`s` flags) into a reusable value; `IsMatch`/`StringMatch`/`StringMatchAll` accept that value or a bare pattern string. `StringMatch`/`StringMatchAll` return `["Array", matched_text, start, end, ["Array", group, ...]]` per match (1-indexed `start`, exclusive `end`, matching this solver's other index conventions).
34
+
35
+ Not included: `Delimiter`, `Spacing`, `Annotated`, `Text`, `BaseForm` (LaTeX-rendering hints, not applicable to a headless evaluator); `Set`, `Tuple`, `Dictionary`, and unbounded-iteration collections (`Cycle`, `Iterate`, arbitrary-size `Repeat`/`Linspace`/`Tabulate`); domain-membership sets (`RealNumbers`, `Integers`, etc.).
36
+
37
+ [2.2.1]: https://github.com/LongenesisLtd/mathjson-solver/compare/v2.2.0...v2.2.1
38
+
8
39
  ## [2.2.0] - 2026-09-08
9
40
 
10
41
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mathjson-solver
3
- Version: 2.2.0
3
+ Version: 2.2.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
@@ -9,7 +9,11 @@ License-Expression: MIT
9
9
  License-File: LICENSE
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
- Requires-Python: >=3.6
12
+ Requires-Python: >=3.10
13
+ Provides-Extra: integration
14
+ Requires-Dist: numpy; extra == 'integration'
15
+ Provides-Extra: regex
16
+ Requires-Dist: google-re2; extra == 'regex'
13
17
  Description-Content-Type: text/markdown
14
18
 
15
19
  # MathJSON Solver
@@ -42,9 +46,11 @@ A reliable Python library for numerically evaluating mathematical expressions in
42
46
  pip install mathjson-solver
43
47
  ```
44
48
 
45
- **Requirements:** Python 3.7+
49
+ **Requirements:** Python 3.10+
46
50
 
47
- **Optional:** numpy (only required for `TrapezoidalIntegrate` function)
51
+ **Optional:**
52
+ - `pip install mathjson-solver[integration]` (installs numpy; only required for `TrapezoidalIntegrate`)
53
+ - `pip install mathjson-solver[regex]` (installs [google-re2](https://pypi.org/project/google-re2/); only required for `RegExp`/`IsMatch`/`StringMatch`/`StringMatchAll`)
48
54
 
49
55
  ## Quick Start
50
56
 
@@ -112,16 +118,18 @@ The library supports a comprehensive set of mathematical operations:
112
118
  * **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
113
119
  * **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
114
120
  * **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
115
- * **Comparison:** Equal, StrictEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual
116
- * **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
117
- * **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Variance, StandardDeviation, Length/Count
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
118
124
  * **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
119
- * **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended, First, Last, Rest, Most, Reverse, Sort, Unique, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct
120
- * **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch-Case/Which, Constants definition
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
121
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)
122
130
  * **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
123
- * **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc
124
- * **Integration:** TrapezoidalIntegrate (requires numpy), Interp, FindIntervalIndex, Variable references
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
125
133
  * **Advanced:** HasMatchingSublist for pattern matching
126
134
  * **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
127
135
 
@@ -28,9 +28,11 @@ A reliable Python library for numerically evaluating mathematical expressions in
28
28
  pip install mathjson-solver
29
29
  ```
30
30
 
31
- **Requirements:** Python 3.7+
31
+ **Requirements:** Python 3.10+
32
32
 
33
- **Optional:** numpy (only required for `TrapezoidalIntegrate` function)
33
+ **Optional:**
34
+ - `pip install mathjson-solver[integration]` (installs numpy; only required for `TrapezoidalIntegrate`)
35
+ - `pip install mathjson-solver[regex]` (installs [google-re2](https://pypi.org/project/google-re2/); only required for `RegExp`/`IsMatch`/`StringMatch`/`StringMatchAll`)
34
36
 
35
37
  ## Quick Start
36
38
 
@@ -98,16 +100,18 @@ The library supports a comprehensive set of mathematical operations:
98
100
  * **Arithmetic:** Add, Sum, Subtract, Multiply, Divide, Negate, Power, Square, Root, Sqrt, Abs, Round, Floor, Ceil
99
101
  * **Trigonometry:** Sin, Cos, Tan, Arcsin, Arccos, Arctan, Arctan2, Cot, Sec, Csc (+ inverses), Sinh, Cosh, Tanh, Coth, Sech, Csch (+ inverses), Hypot, Sinc
100
102
  * **Logarithms:** Log (base 10, or base b), Log2/Lb, Log10/Lg, Ln (natural log), LogOnePlus, Exp
101
- * **Comparison:** Equal, StrictEqual, NotEqual, Greater, GreaterEqual, Less, LessEqual
102
- * **Logic & Sets:** Any, All, Not, And, Or, Xor, Nand, Nor, Implies, Equivalent, In, NotIn, ContainsAnyOf, ContainsAllOf, ContainsNoneOf
103
- * **Statistics:** Average/Mean, Max, Min (both list and variadic forms), Median, Variance, StandardDeviation, Length/Count
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
104
106
  * **Functional Programming:** Map/StrictMap, Reduce, Filter, Product (all also accept CortexJS calling conventions, including `Function` lambdas)
105
- * **Arrays:** Array/List creation, GenerateRange, Range, AtIndex, At, Slice, Appended, First, Last, Rest, Most, Reverse, Sort, Unique, Join, Zip, IsEmpty, CumulativeSum, CumulativeProduct
106
- * **Control Flow:** If statements (Python pair form and CortexJS flat form), Switch-Case/Which, Constants definition
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
107
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)
108
112
  * **Date/Time:** Strptime, Strftime, Today, Now, TimeDelta functions (Weeks, Days, Hours, Minutes)
109
- * **Number Theory:** Chop, Mod, Clamp, GCD, LCM, Factorial, Binomial, IsPrime, Erf, Erfc
110
- * **Integration:** TrapezoidalIntegrate (requires numpy), Interp, FindIntervalIndex, Variable references
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
111
115
  * **Advanced:** HasMatchingSublist for pattern matching
112
116
  * **Constants:** Pi, Degrees, ExponentialE, GoldenRatio
113
117