Skip to content

Commit 53353cc

Browse files
Rafael-SOWNetclaude
andcommitted
Refuse factorize, nextprime, divisors, gradient, divergence and φ by name
Each was read as a product: factorize(360) was factorize * 360, nextprime(10) was nextprime * 10, divisors(12) was divisors * 12, gradient(x^2) was gradient * x ^ 2, divergence(x) was divergence * x, and φ(10) was φ * 10. The library has no node for any of them, so each call is now refused with what can be written today: MathS.NumberTheory.Factorize or Factorize() in C#, prime(primepi(n) + 1), divisorsigma(0, n) and divisorsigma(1, n), jacobian([f], [x, y]), trace(jacobian(F, [x, y])), and phi(n), which is Euler's totient; ϕ, the other glyph, is refused the same way. Each name without a bracket is still a variable. Two documentation comments were stale. MathS.Settings.Budget said the Gröbner solver was the only thing to honour it; the system solver's own ledger, the rewrite graph's transformations, MathS.AreEqual and the perfect-square proof that Factorize runs and Simplify offers as a candidate all do, and Simplify itself is not bounded by it. EquationSystem.Solve said only that it returns null; it throws NotSufficientlySupportedException when its budget runs out. Part of #2449 and #2182. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f439c0e commit 53353cc

13 files changed

Lines changed: 1526 additions & 1203 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ The calculus nodes and the binders — `derivative`, `integral`, `limit`, `sum`,
6161
names the node and says to compile `.Evaled` or `Simplify()` instead. The LINQ compiler said the bound variable was not
6262
among the arguments.
6363

64+
### `factorize`, `nextprime`, `divisors`, `gradient`, `divergence` and `φ` are refused by name
65+
66+
**Not silent: these names followed by a bracket now throw `UnrecognizedFunctionParseException` where they were read as
67+
products.** `factorize(360)` was `factorize * 360` and simplified to `360 * factorize`. The library has no node for any
68+
of them, so each is refused with what to write today: in C#, `MathS.NumberTheory.Factorize(n)` for the prime factors of
69+
an integer and `Factorize()` to factor an expression; `prime(primepi(n) + 1)` for the least prime above `n`;
70+
`divisorsigma(0, n)` and `divisorsigma(1, n)` for the count and the sum of the divisors
71+
([#2449](https://github.com/asc-community/AngouriMath/issues/2449)); `jacobian([f], [x, y])` for a gradient and
72+
`trace(jacobian(F, [x, y]))` for a divergence ([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
73+
Euler's totient is `phi(n)`, and `φ(n)` and `ϕ(n)` are refused. Each name without a bracket is still a variable.
74+
75+
| Input | Was (2.7.0) | Now |
76+
|---|---|---|
77+
| `"factorize(360)".ToEntity()` | `factorize * 360` | throws `UnrecognizedFunctionParseException` |
78+
| `"nextprime(10)".ToEntity()` | `nextprime * 10` | throws `UnrecognizedFunctionParseException`: write `prime(primepi(n) + 1)` |
79+
| `"divisors(12)".ToEntity()` | `divisors * 12` | throws `UnrecognizedFunctionParseException`: write `divisorsigma(0, n)` or `divisorsigma(1, n)` |
80+
| `"φ(10)".ToEntity()` | `φ * 10` | throws `UnrecognizedFunctionParseException`: write `phi(n)` |
81+
| `"ϕ(10)".ToEntity()` | `ϕ * 10` | throws `UnrecognizedFunctionParseException`: write `phi(n)` |
82+
| `"gradient(x^2)".ToEntity()` | `gradient * x ^ 2` | throws `UnrecognizedFunctionParseException` |
83+
| `"divergence(x)".ToEntity()` | `divergence * x` | throws `UnrecognizedFunctionParseException` |
84+
| `"gradient(x^2*y, [x, y])".ToEntity()` | throws `UnhandledParseException` | throws `UnrecognizedFunctionParseException` |
85+
6486
---
6587

6688
## 2.7.0 — since 2.6.0

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6571,10 +6571,17 @@ internal static EDecimal DowncastingTolerance
65716571
/// (<a href="https://github.com/asc-community/AngouriMath/issues/373">#373</a>)
65726572
/// </para>
65736573
/// <para>
6574-
/// It is honoured only where an algorithm asks -- today that is the Gr&#246;bner
6575-
/// system solver. Everything else in the library bounds itself by ceilings of its
6576-
/// own that this does not reach, so setting it does not make an arbitrary call
6577-
/// bounded.
6574+
/// It is honoured only where an algorithm asks. Today that is the system solver --
6575+
/// its Gr&#246;bner path, and the ledger <see cref="Core.EquationSystem.Solve(Variable[])"/>
6576+
/// keeps over the whole call --, the rewrite graph wherever it runs:
6577+
/// <see cref="Core.Transformations.Transformation.EqualitySaturation(WorkBudget, Core.CostModel)"/>,
6578+
/// <see cref="Core.Transformations.Transformation.CanonicalizationOverGraph(WorkBudget)"/> and
6579+
/// <see cref="AreEqual(Entity, Entity, WorkBudget, Core.Transformations.Soundness, Core.Domain)"/>, and the proof that a written-out perfect
6580+
/// square is one, which <see cref="Entity.Factorize(int)"/> runs and
6581+
/// <see cref="Entity.Simplify(int)"/> offers as a candidate. <c>Simplify</c> itself
6582+
/// is not bounded by it, and nor is anything else in the library, each of which
6583+
/// bounds itself by ceilings of its own that this does not reach; so setting it does
6584+
/// not make an arbitrary call bounded.
65786585
/// </para>
65796586
/// </remarks>
65806587
/// <example>

‎Sources/AngouriMath/Core/Antlr/AngouriMath.g‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,17 @@ atom returns[Entity value]
719719
| 'factorial2(' args = function_arguments ')' { $value = NotAFunctionHere("factorial2", "the double factorial is the postfix n!!"); }
720720
| 'fractionalpart(' args = function_arguments ')' { $value = NotAFunctionHere("fractionalpart", "write x mod 1, which is in [0, 1)"); }
721721
| 'quotient(' args = function_arguments ')' { $value = NotAFunctionHere("quotient", "write floor(a / b)"); }
722+
/* Names another system calls a function and this library has no node for, each refused
723+
with what can be written today: factorize(360) was factorize * 360, and φ(10) was φ * 10.
724+
factorize, nextprime and divisors: https://github.com/asc-community/AngouriMath/issues/2449.
725+
gradient and divergence: https://github.com/asc-community/AngouriMath/issues/2182 */
726+
| 'factorize(' args = function_arguments ')' { $value = NotImplementedFunction("factorize", "factorization node yet; in C#, MathS.NumberTheory.Factorize(n) gives the prime factors of an integer and Factorize() factors an expression"); }
727+
| 'nextprime(' args = function_arguments ')' { $value = NotImplementedFunction("nextprime", "nextprime yet; prime(primepi(n) + 1) is the least prime greater than n"); }
728+
| 'divisors(' args = function_arguments ')' { $value = NotImplementedFunction("divisors", "set of divisors yet; divisorsigma(0, n) counts them and divisorsigma(1, n) is their sum"); }
729+
| 'gradient(' args = function_arguments ')' { $value = NotImplementedFunction("gradient", "gradient yet; jacobian([f], [x, y]) is the row of partial derivatives of f"); }
730+
| 'divergence(' args = function_arguments ')' { $value = NotImplementedFunction("divergence", "divergence yet; trace(jacobian(F, [x, y])) is the divergence of F"); }
731+
| 'φ(' args = function_arguments ')' { $value = NotAFunctionHere("φ", "Euler's totient is written phi(n)"); }
732+
| 'ϕ(' args = function_arguments ')' { $value = NotAFunctionHere("ϕ", "Euler's totient is written phi(n)"); }
722733
| 'domain(' args = function_arguments ')'
723734
{
724735
Assert("domain", 2, $args.list.Count);

‎Sources/AngouriMath/Core/Antlr/AngouriMath.interp‎

Lines changed: 15 additions & 1 deletion
Large diffs are not rendered by default.

‎Sources/AngouriMath/Core/Antlr/AngouriMath.tokens‎

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,21 @@ T__226=227
228228
T__227=228
229229
T__228=229
230230
T__229=230
231-
NEWLINE=231
232-
NUMBER=232
233-
SPECIALSET=233
234-
BOOLEAN=234
235-
NAN=235
236-
VARIABLE=236
237-
COMMENT=237
238-
WS=238
231+
T__230=231
232+
T__231=232
233+
T__232=233
234+
T__233=234
235+
T__234=235
236+
T__235=236
237+
T__236=237
238+
NEWLINE=238
239+
NUMBER=239
240+
SPECIALSET=240
241+
BOOLEAN=241
242+
NAN=242
243+
VARIABLE=243
244+
COMMENT=244
245+
WS=245
239246
'['=1
240247
']'=2
241248
'!'=3
@@ -462,8 +469,15 @@ WS=238
462469
'factorial2('=224
463470
'fractionalpart('=225
464471
'quotient('=226
465-
'domain('=227
466-
'piecewise('=228
467-
'apply('=229
468-
'lambda('=230
469-
'NaN'=235
472+
'factorize('=227
473+
'nextprime('=228
474+
'divisors('=229
475+
'gradient('=230
476+
'divergence('=231
477+
'φ('=232
478+
'ϕ('=233
479+
'domain('=234
480+
'piecewise('=235
481+
'apply('=236
482+
'lambda('=237
483+
'NaN'=242

0 commit comments

Comments
 (0)