mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-25 21:34:48 +00:00
Upgraded AngouriMath to v2.8.0 (#1235)
This commit is contained in:
1 parent
fae3ceb840
commit
506c06fbfc
24 files changed
+974
-105
No files matched your search
+12
-8
@@ -271,17 +271,19 @@ Logs name a mailbox and its ID, never a subject, a sender or recipient, a folder
|
||||
|
||||
Both tools read plain syntax, not LaTeX, which `CalculateTool.SYNTAX` describes for both schemas. The chat renders LaTeX, so each result carries a LaTeX version besides. `MathExpressionReader` parses with `ExplicitParsingOnly`: otherwise AngouriMath reads `x2` as `x^2` and `foo(3)` as `foo * 3`, and the model would get an answer to a question it did not ask. Before parsing, the reader refuses what AngouriMath reads differently from what a model means: `!=`, which AngouriMath reads as `a! = b`, while not-equal is `<>`; `|`, which means "divides"; the variable `oo`, while infinity is `+oo` or `-oo`; and more than one `=`. It shortens the parser's messages, which list over 1,000 characters of tokens, to the column and the cause.
|
||||
|
||||
Every decimal literal is the fraction it writes, so `0.1 + 0.2` is exactly `3/10` and `6.62607015e-34` is exactly `132521403/200000000000000000000000000000000000000000`. AngouriMath alone does that for some literals only: it downcasts while parsing, keeps `6.62607015e-34` an inexact decimal, and reads `1e-60` as `0`. Simplifying then drops an inexact decimal from a sum, so `1 + 1e-40` would be exactly `1`. The reader therefore parses without downcasting and without AngouriMath's cache of parsed expressions, and turns each literal into its fraction itself.
|
||||
AngouriMath 2.7.0 and 2.8.0 added about sixty functions, such as `zeta`, `det`, `primepi`, and `re`. The tools support three of them, since solving, integrating, and differentiating return them: `lambertw` (also `productlog`), `polygamma` (also `digamma`), and the incomplete gamma function `gamma(a, z)`. The reader refuses the others by name before parsing, `MathExpressionReader.UNSUPPORTED_FUNCTIONS`, because AngouriMath computes some of them while it parses, such as `det`, `dot`, or `jacobian` of a matrix written out, so nothing of them would be left to refuse afterward. After parsing, it refuses the new kinds of nodes, `MathExpressionReader.UNSUPPORTED_NODE_TYPES`, which also covers the three which come without a name: the double factorial `n!!`, the entry `A[1, 2]` of a matrix, and the product over a set, `product(f, x in S)`.
|
||||
|
||||
Every decimal literal is the fraction it writes, so `0.1 + 0.2` is exactly `3/10` and `6.62607015e-34` is exactly `132521403/200000000000000000000000000000000000000000`. AngouriMath alone does that for some literals only: it downcasts while parsing, keeps `6.62607015e-34` an inexact decimal, and reads `1e-60` as `0`. An inexact decimal leaves every value it takes part in inexact, and up to AngouriMath 2.6.0, simplifying even dropped it from a sum, so `1 + 1e-40` was exactly `1`. The reader therefore parses without downcasting and without AngouriMath's cache of parsed expressions, and turns each literal into its fraction itself.
|
||||
|
||||
AngouriMath computes `sum(f, k, a, b)` only in closed form, as for powers of `k`, so `sum(k, k, 1, 10^7)` takes no time, while `sum(1/k, k, 1, 1000)` has no value. Such a sum, an infinite one, or a matrix is refused by `NumericEvaluator` in its own words, since AngouriMath's message addresses a developer.
|
||||
|
||||
No text the model reads names AngouriMath: neither the instructions and schemas of the tools, nor a refusal or an issue. Where a sentence needs someone who computes, it says "the tool", as in "The tool found no closed form for this integral.": a model would take the name of the library for something it may call or look up. The tests of both tools check their definitions for it.
|
||||
No text the model reads names AngouriMath: neither the instructions and schemas of the tools, nor a refusal or an issue. Where a sentence needs someone who computes, it says "the tool", as in "The tool found no closed form for this integral.": a model would take the name of the library for something it may call or look up. The tests of both tools check their definitions for it. AngouriMath's own messages name it in three places the tools reach: where it refuses a function by name, as `trunc`, `MathExpressionReader` states only the name; where an integrand has no form to evaluate point by point, as with `gamma(a, z)`, `NumericEvaluator` words the refusal itself instead of asking to call `.Evaled`; and an `AngouriBugException`, which asks to report it to the library, becomes a message of `MathComputationService`. `MathExpressionReaderTests` tries every function of the parser for it.
|
||||
|
||||
### Honest Digits
|
||||
|
||||
A decimal shows only the digits the computation vouches for. `NumericEvaluator` evaluates twice, with 10 and with 20 guard digits, and keeps the digits in which both agree, because composite expressions lose a digit or two at the end. When fewer digits remain than were asked for, `issues` says so.
|
||||
|
||||
Tiny values need care, as with the Planck constant. By default, AngouriMath downcasts while evaluating, too, and takes a value such as `1.380649e-23 * 300` for the integer `0`. `NumericEvaluator.EvaluateAt` evaluates without downcasting. Then AngouriMath rounds a quotient to as many decimal places as the precision has digits, so the precision grows by the leading zeros of the smallest fraction and of the value, up to 1,000 digits. Simplifying, too, takes a tiny value for `0`: below about `1e-1000`, or near the precision where it evaluates a function. An exact `0` is therefore checked numerically. Rounding noise, as for `sin(pi)`, changes with the precision; a tiny value keeps its digits and is reported as a decimal instead. A `0` that remains after 1,000 digits without being exact comes with a note in `issues` that it may stand for a tiny value.
|
||||
Tiny values need care, as with the Planck constant. By default, AngouriMath downcasts and, at 30 digits, takes a value such as `1.380649e-23 * 300` for the integer `0`. `NumericEvaluator.EvaluateAt` evaluates without downcasting. Up to AngouriMath 2.6.0, a quotient was then rounded to as many decimal places as the precision has digits, so the precision grows by the leading zeros of the smallest fraction and of the value, up to 1,000 digits. Since 2.7.0, a computed value keeps its digits, and the growth stays as a safeguard. Simplifying takes a value below about `1e-1000` for `0`, and up to 2.6.0 also a tiny value near the precision where it evaluates a function. An exact `0` is therefore checked numerically. Rounding noise, as for `sin(pi)`, changes with the precision; a tiny value keeps its digits and is reported as a decimal instead. A `0` that remains after 1,000 digits without being exact comes with a note in `issues` that it may stand for a tiny value.
|
||||
|
||||
A definite integral always goes to `DoubleExponentialQuadrature`, never through an antiderivative, which gives wrong values when it jumps between the bounds, and never through `Evaled`, which turns constants into decimals even inside an integral it cannot solve. The quadrature works with doubles and estimates its error. The result is then `approximate`, with its `estimated_error`, and its digits drop to what the error allows, mostly 12 to 15. An integral which does not settle, or which has no finite value at a point, is refused rather than answered with a wrong number.
|
||||
|
||||
@@ -290,19 +292,21 @@ A definite integral always goes to `DoubleExponentialQuadrature`, never through
|
||||
A symbolic answer is only as good as the library which gave it, and AngouriMath changes answers between releases. `compute_symbolically` therefore checks each result numerically where it can, and reports `passed`, `failed`, or `not_possible` in `verification`:
|
||||
|
||||
- `simplify`, `expand`, and `factor`: the expression and the result are equal.
|
||||
- `differentiate`: each order agrees with a central difference of the order before, at 60 digits.
|
||||
- `differentiate`: each order agrees with a central difference of the order before, at 60 digits, and at one digit more for each power of ten by which the function exceeds its derivative, as for `100! + sin(x)`; the check of an antiderivative works the same way.
|
||||
- `integrate` without bounds: the derivative of the antiderivative is the integrand.
|
||||
- `integrate` with bounds: the value agrees with the quadrature.
|
||||
- `solve`: each solution satisfies the equation.
|
||||
- `limit`: not checked.
|
||||
|
||||
`NumericCheck` compares at six fixed sample points. They are exact rationals, so a polynomial is evaluated exactly, however much the terms of its expansion cancel; everything else is evaluated at 50 digits, without downcasting. Two values agree within a relative tolerance, so tiny values, such as those of a formula with physical constants, are still told apart. Against `0`, the tolerance is absolute, because terms which cancel leave their rounding noise. The points are fixed, so the same call always gets the same verdict. Parameters which AngouriMath brings into a solution, such as `n_1` for any integer, take integer values there. Where AngouriMath finds no closed form, `complete` is false, and `result` still holds the integral, the limit, or the equation.
|
||||
`NumericCheck` compares at six fixed sample points. They are exact rationals, so a polynomial is evaluated exactly, however much the terms of its expansion cancel; everything else is evaluated at 50 digits, without downcasting. Two values agree within a relative tolerance, so tiny values, such as those of a formula with physical constants, are still told apart. Against `0`, the tolerance is absolute, because terms which cancel leave their rounding noise. The points are fixed, so the same call always gets the same verdict. Where AngouriMath finds no closed form, `complete` is false, and `result` still holds the integral, the limit, or the equation.
|
||||
|
||||
An equation with infinitely many solutions, such as `sin(x) = 1/2`, may come back as a family: an indexed union such as `union({ pi / 6 + 2 * pi * n, pi - pi / 6 + 2 * pi * n }, n in ZZ)`, which binds its index `n`. `MathSolutions` takes such a set apart into its members, also when a family holds another one or a union joins families and finite sets. Each member of a family lists the values of its indices in `holds_for`, and, when every index may be 0, gives its solution for the index 0 in `at_index_0`, with its decimal: that is the one a model needs most often, such as the time in which a sum doubles. In the check, an index takes three integers of its set, such as -1, 0, and 1 for any integer, or -1, 1, and 2 for `ZZ \ { 0 }`.
|
||||
|
||||
### Limits
|
||||
|
||||
AngouriMath does not stop every computation when asked to: `9^9^9`, `(10^9)!`, and the expansion of `(x+y)^500` run on whatever the cancellation token says. `MathGuards` therefore refuses before computing what would take too long. That is a power or a factorial whose exact value would have more than 20,000 digits, estimated from the inside out, and a power of a sum with an exponent above 200, wherever AngouriMath may expand it. An expression has at most 2,000 characters, and a result at most 20,000.
|
||||
AngouriMath does not stop every computation when asked to: `(10^9)!` and the expansion of `(x+y)^500` run on whatever the cancellation token says, and so did `9^9^9` up to AngouriMath 2.6.0; since 2.7.0, a power of more than sixteen million bits is left written. `MathGuards` therefore refuses before computing what would take too long. That is a power or a factorial whose exact value would have more than 20,000 digits, estimated from the inside out, and a power of a sum with an exponent above 200, wherever AngouriMath may expand it. The same holds for the special functions which solving, integrating, and differentiating return: `MathGuards` refuses `polygamma` above the order 100, and `gamma(a, z)` for an absolute value of `z` above 1,000 or for an `a` outside the real numbers from -20 to 200, see `MathLimits` for the times measured. `NumericCheck` applies these limits at its sample points as well, through `MathGuards.CheckValueAtPoint`, because a value of a variable may make a factorial or a power too large there, as in `(10^6*x)!` or `x^100000`, or become the argument of a special function beyond its limits, as in `gamma(1/2, 10000*x)`; a point which would exceed them is left out. There, a sum counts the digits of its largest term only, so the long sums of an expansion still get checked. `lambertw` needs no limit. An expression has at most 2,000 characters, and a result at most 20,000.
|
||||
|
||||
`MathComputationService` runs every computation on a thread of its own with a stack of 64 MB. About 500 nested parentheses overflow the stack of a thread pool thread, and that ends the process. There, it switches off Newton's method for `solve`, whose inexact doubles would pass for exact solutions. It hands the cancellation to AngouriMath. The service has one slot, and a computation gets 10 seconds. The slot becomes free when the computation ends, not when the call gives up: a computation which does not stop holds up the next ones rather than taking more cores.
|
||||
`MathComputationService` runs every computation on a thread of its own with a stack of 64 MB. About 500 nested parentheses overflow the stack of a thread pool thread, and that ends the process. There, it switches off Newton's method for `solve`, whose inexact roots would pass for exact solutions. Since AngouriMath 2.7.0, this also switches off the Durand–Kerner iteration for polynomials, which never checks the cancellation token. It hands the cancellation to AngouriMath. The service has one slot, and a computation gets 10 seconds. The slot becomes free when the computation ends, not when the call gives up: a computation which does not stop holds up the next ones rather than taking more cores.
|
||||
|
||||
### Why There Is No Prompt Injection Filter
|
||||
|
||||
@@ -310,7 +314,7 @@ The tools open no path for content from outside AI Studio. A result holds the ex
|
||||
|
||||
### AngouriMath
|
||||
|
||||
`AngouriMathBehaviorTests` pins the behavior of AngouriMath which the tools build on, such as the traps of the parser, the digits of its functions, and the computations which ignore cancellation. The version is pinned exactly by `packages.lock.json`. Before raising it, read the release notes for silent breaking changes, and run these tests.
|
||||
`AngouriMathBehaviorTests` pins the behavior of AngouriMath which the tools build on, such as the traps of the parser, the digits of its functions, and the computations which ignore cancellation. The version is pinned exactly by `packages.lock.json`. Before raising it, read the release notes for silent breaking changes, and run these tests. Two of them list every function and operator of the parser and every kind of node: a new one fails them until it is decided on, either refused by `MathExpressionReader` or supported, with a guard in `MathGuards` where AngouriMath computes it without checking the cancellation token.
|
||||
|
||||
AngouriMath is marked as trimmable, so a published build of AI Studio contains only the parts of it which the trimmer saw being used, and `Trimming.props` suppresses the warnings about the others. The trim smoke test of `dotnet run -- verify` therefore lets both tools compute a few expressions in a trimmed build, see `MathematicsChecks` in `app/TrimSmokeTest`. When a tool starts to use another part of AngouriMath, such as a new operation, add a check there.
|
||||
|
||||
|
||||
Reference in new issue
Block a user