Arb oracle (python-flint) integration #
This module provides a small Lean wrapper around an external Arb/FLINT process:
- spawn
pythonto runNN/Floats/Arb/arb_oracle.py, - parse its JSON output,
- expose the result in a structured way (including an exact
Ratenclosure reconstructed from Arb'smid_rad_10expintegers).
Trust boundary: this is an oracle. The Lean side parses and packages the returned enclosure; the Arb computation is the external trusted producer behind that enclosure.
Notes on design #
We expose two layers:
- a raw layer returning
Lean.Json(runJson,runRequestJson), and - a typed layer with parsers and request-specific entrypoints (
parseResult,run,runExpr,runMLP).
The raw layer is useful for debugging and for experimenting with new request schemas, while the typed layer is nicer for examples and "certificate-like" workflows.
Unary interval queries #
Unary mode sends one function name and one input interval to Arb. It is the most direct interface
when a proof or example needs a certified enclosure for exp, log, tanh, or a related scalar
function.
For more general evaluation (expression ASTs / small MLPs), use the request API further below.
Unary interval query sent to the Python Arb oracle.
In words: evaluate func over the input interval [lo, hi] using Arb ball arithmetic at
the requested precision, and return a rigorous enclosure of the output.
Why endpoints are strings:
- we pass them straight through to Python/Arb without any intermediate parsing in Lean, and
- it avoids accidental loss of precision from
Floatparsing when writing examples.
- func : String
Unary function name (e.g.
"tanh","exp","log"). - lo : String
Lower endpoint of the input interval, as a decimal string.
- hi : String
Upper endpoint of the input interval, as a decimal string.
- precBits : Nat
Working precision (in bits) used inside Arb.
- digits : Nat
Number of decimal digits used in printed endpoints.
Instances For
Instances For
Typed result for a unary query.
We keep both:
- the raw decimal endpoints (
outLo/outHi) for logs, and - the exact
MidRad10Expball (outputBall) that can be converted into exactRatbounds.
- func : String
Echoed
funcname. - precBits : Nat
Working precision (bits) used by Arb.
- digits : Nat
Decimal digits used in printed endpoints.
- inputBall : MidRad10Exp
Input interval as an Arb ball (exact integer encoding).
- outputBall : MidRad10Exp
Output interval as an Arb ball (exact integer encoding).
- outLo : String
Lower endpoint as a decimal string (human-friendly).
- outHi : String
Upper endpoint as a decimal string (human-friendly).
Instances For
General request API (kind = "expr" / "mlp") #
The Python oracle supports JSON requests (see NN/Floats/Arb/arb_oracle.py):
kind = "expr": evaluate a small, whitelisted expression language over Arb balls.kind = "mlp": evaluate a small feedforward MLP given weights/biases/activations, over a box input.
These are still oracle calls; they let us move beyond one unary op while keeping the external computation boundary explicit.
Typed result for an expr request.
In words: an enclosure of a small expression AST evaluated over a box of interval variables.
- precBits : Nat
Working precision (bits) used by Arb.
- digits : Nat
Decimal digits used in printed endpoints.
- outputBall : MidRad10Exp
Output enclosure encoded as
mid_rad_10exp. - outLo : String
Lower decimal endpoint of the enclosure.
- outHi : String
Upper decimal endpoint of the enclosure.
Instances For
Relative path to the Python oracle entrypoint script (used in all invocation modes).
Instances For
Parse an Arb mid_rad_10exp object into MidRad10Exp.
In words: this reads the exact integer encoding of an interval ball. A negative radius is rejected, since it would describe a reversed interval.
Instances For
Convert a MidRad10Exp ball into an exact rational enclosure.
In words: if the payload encodes mid ± rad scaled by 10^exp, then
toRatBounds returns the pair
((mid - rad) * 10^exp, (mid + rad) * 10^exp) as exact rationals.
Instances For
Run a unary Query via the Python oracle and return the raw JSON payload.
This only checks that:
- the process exits successfully, and
- the output parses as JSON.
Use parseResult if you want the typed Result.
Instances For
Internal helper: parse a ball field (in mid_rad_10exp format) from an object.
This is used by both unary results and request-mode results.
Instances For
Internal helper: parse a ball plus decimal (lo, hi) endpoints from an object.
The oracle includes both:
Instances For
Parse a unary-mode JSON payload into a typed Result.
In words: if the JSON matches the schema emitted by arb_oracle.py --func ..., then
parseResult extracts the input/output enclosures and context parameters; otherwise it returns a
plain error message.
Instances For
Generate a fresh request filepath for an Arb oracle payload.
In words: use the current monotone time in milliseconds plus a random suffix to reduce collisions across concurrent processes.
Instances For
Run the oracle with a general --request <file.json> payload (returns raw JSON).
This is the entrypoint for the richer request schemas supported by arb_oracle.py, such as:
kind = "expr"(expression AST evaluation), andkind = "mlp"(small feedforward MLP evaluation).
This respects TORCHLEAN_ARB_PY (if set) to choose the Python executable.
Instances For
Parse an expr response payload into ExprResult.
In words: extract the output enclosure and context metadata from the response JSON.
Instances For
Run an expr request and parse the output interval.
In words: evaluate an expression AST over a box of interval variables using Arb ball arithmetic, returning an enclosure of the result.
Instances For
Run an mlp request (box input + layers) and parse the output vector intervals.
In words: run a small feedforward MLP using ball arithmetic, where the input is a box interval, and return per-output-coordinate enclosures.