Widen pseudo for numerical work: sized types, FLOAT32, exact built-ins, USE IEEE
Pseudo could say what a procedure computes only up to INTEGER and FLOAT, so it could not state what a Mojo or Python program with Int32, UInt8 or Float32 values will compute, and it had no words for rounding itself. - lang/parse: INT8..INT64, UINT8..UINT64, FLOAT32, FLOAT64 as types (INTEGER or FLOAT with a width, so every "whole number" rule accepts them); conversions written as Mojo writes them, INT32(X), FLOAT32(X); 1_000_000, 0xFF and 0b1010 literals; a type name as an argument (MAX_VALUE(INT8)); the USE line (USE IEEE now, library modules next). - check: widths and precisions never mix silently (mixed-width, mixed-precision); a literal takes the type of the sized value beside it, as in Mojo, and one that does not fit is an error before any run (literal-range); typing for every new built-in. - interp: a sized result, store, parameter, RETURN or conversion that does not fit stops the run (kind overflow), WRAP(X, T) wraps on purpose; FLOAT32 results are rounded to single precision; USE IEEE lets NaN and infinities flow. - numeric.js: exact helpers: FMA rounded once, EXACT(X) with every digit a FLOAT holds, ULP and NEXT_AFTER for both precisions, bit operations in two's complement. - Built-ins: ASIN ACOS ATAN SINH COSH TANH HYPOT POW CBRT EXPM1 LOG1P E TRUNC SIGN COPYSIGN CLAMP FMA IS_NAN IS_INF IS_FINITE INF NAN ULP NEXT_AFTER IS_CLOSE EXACT MAX_VALUE MIN_VALUE EPSILON GCD LCM BIT_AND BIT_OR BIT_XOR BIT_NOT SHIFT_LEFT SHIFT_RIGHT WRAP. They stay usable as names (a variable E, a FUNCTION GCD): the program's own wins. - vcgen: an overflow obligation on every sized result, then the range as a fact (also for sized parameters and loop-cut variables); FLOAT32 arithmetic as its own uninterpreted functions, constants rounded exactly, TOFLOAT32(v) otherwise; argument obligations for SQRT, the logarithms, ASIN/ACOS, LOG1P, CLAMP and the shifts; nothing proved under USE IEEE. - testing: the fuzzer tries the edges of a sized type and generates FLOAT32 values. - pseudo-to-mojo: Int8..Float32, conversions, the new built-ins through std.math (each name in the harvested index), a note where Mojo wraps. - Tests: numeric.test.mjs; corpus 49-52; prover fixtures int8-overflow, float32-store, ieee-nan; the reference documents every new form. Gate: 324 pass (core). New Mojo uses std.math names the interpreter has not been verified on (listed in sync-mojo's KNOWN_GAPS); they need pixi run mojo-verify on the network before the interpreter runs them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
24 files changed
+1271
-96
No files matched your search
@@ -20,6 +20,25 @@ The prover is three TypeScript modules under strict mode; the rest of the engine
|
||||
|
||||
"Proved" is about the notation's own number model. INTEGER is a whole number of any size and a FLOAT is a finite number whose rounding the prover does not see into. A run of the interpreter stops where a value leaves that model (a whole number past 2^53 − 1, a FLOAT that is not finite, a division by zero), so every run stays inside what a proof covers. The Mojo made from a program has other limits (a 64-bit `Int` that wraps, a `Float64` that becomes `inf` or `nan`), and a unit whose proof leans on the number model carries an `int-model` or `float-model` note saying so.
|
||||
|
||||
### Numbers
|
||||
|
||||
Pseudo is meant for numerical work, so its number model is stated exactly ([the reference](../src/common/reference.ts) shows every form with a runnable example):
|
||||
|
||||
| Type | Holds | When a result does not fit | The prover |
|
||||
|---|---|---|---|
|
||||
| `INTEGER` | A whole number of any size; a run holds it exactly to 2^53 − 1 | The run stops past 2^53 − 1 | Exact arithmetic of any size; an `int-model` note says the lab's and Mojo's limits are not part of the proof |
|
||||
| `INT8` … `INT64`, `UINT8` … `UINT64` | Two's complement or unsigned, n bits (64-bit types held exactly to 2^53 − 1 in this lab) | The run stops (kind `overflow`); `WRAP(X, T)` wraps on purpose (up to 32 bits) | Exact arithmetic plus an `overflow` obligation on every result, store, parameter, RETURN and conversion: "fits INT8". After it, the range is a fact. A sized parameter and a sized variable cut by a loop keep their range |
|
||||
| `FLOAT`, `FLOAT64` | IEEE 754 double | The run stops on infinity or NaN | `FLOAT+` and its kind are uninterpreted: the same operation on the same values gives the same result, nothing more |
|
||||
| `FLOAT32` | IEEE 754 single: every result rounded to 24 bits (`Math.fround`, exact for +, −, ×, ÷ of singles) | As FLOAT | Its own uninterpreted functions (`F32+`, ...); a constant is rounded exactly; a value that becomes a FLOAT32 is `TOFLOAT32(v)`, about which nothing is assumed |
|
||||
|
||||
Rules the checker holds: two different sized types never mix silently (`mixed-width`, `mixed-precision`; convert with `INT32(X)`, `FLOAT32(X)`); a numeric literal takes the type of the sized value beside it, as in Mojo, and a whole-number literal that does not fit is an error before any run (`literal-range`); INTEGER may go into a sized type (checked when it happens), never a different sized type.
|
||||
|
||||
`USE IEEE` lets NaN and the infinities flow as IEEE 754 says (SQRT(−1.0) is NaN, 1.0 / 0.0 is infinity; whole-number division by zero still stops). The prover's reasoning about numbers does not hold for those values, so in such a program nothing is marked proved, and each unit carries an `ieee` note.
|
||||
|
||||
The numerical built-ins (`HYPOT`, `EXPM1`, `LOG1P`, `FMA`, `ULP`, `NEXT_AFTER`, `EXACT`, `IS_CLOSE`, `MAX_VALUE`, the bit operations, ...) are exact or correctly rounded: `src/engines/pseudo/numeric.js` computes `FMA` with one rounding by exact binary arithmetic, `EXACT(X)` gives every decimal digit a FLOAT holds, and `ULP` and `NEXT_AFTER` step through the representation. Functions JavaScript has no exact version of (erf, gamma) are not built-ins; they belong in the library as verified pseudo. Built-ins that stop the run for some arguments (SQRT, the logarithms, ASIN and ACOS, LOG1P, CLAMP, the shifts) carry an `argument` obligation. The built-ins added for numerical work stay usable as names (a variable `E`, a `FUNCTION GCD`): the program's own definition wins (`SOFT_BUILTINS` in `lang.js`).
|
||||
|
||||
`tests/numeric.test.mjs` pins each rule; the corpus programs `49-sized-integers` to `52-elementary` show them in use.
|
||||
|
||||
### Soundness
|
||||
|
||||
A "proved" must be a proof. Two test files hold the prover to that, and a change to `logic.ts`, `solver.ts` or `vcgen.ts` must keep both green:
|
||||
@@ -36,6 +55,9 @@ When a soundness bug is found, add the program that shows it to `tests/prover/`
|
||||
| `fill-negative.pseudo`, `randint-empty.pseudo` | `FILL` and `RANDINT` assumed facts about arguments the interpreter checks by stopping, without asking whether they hold | An `argument` obligation, and guarded facts |
|
||||
| `float-overflow.pseudo` | The prover treats FLOAT as numbers (`Y == Y`), while a run went on with infinity and NaN | The interpreter stops on a FLOAT that is not finite |
|
||||
| `foreach-empty.pseudo` | The way out of `FOR EACH` kept "X is in the collection", false after zero passes over an empty list | The fact holds only inside a pass |
|
||||
| `int8-overflow.pseudo` | (a guard written with the sized types) Sized arithmetic treated as exact with no range would prove `X + 1` fits INT8 | Every sized result has an `overflow` obligation |
|
||||
| `float32-store.pseudo` | (a guard) A whole number stored in a FLOAT32 keeping its exact value would prove `X == N` for N = 16777217 | A value becoming a FLOAT32 is rounded (constants) or `TOFLOAT32(v)` |
|
||||
| `ieee-nan.pseudo` | (a guard) `X == X` for every number fails for NaN | Nothing is proved in a program that says `USE IEEE` |
|
||||
|
||||
In the app, an obligation the prover marks proved that a generated input breaks at the same place is shown as broken, not proved.
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
<!-- Written by tests/sync-coverage.test.mjs. Do not edit; rerun `npm test` to refresh. -->
|
||||
|
||||
Each translator in `src/sync/` is run over every exercise with pseudo (17), every program in `tests/corpus/` (48), and 17 one-construct fixtures (`tests/helpers/sync-programs.mjs`). 3 of the 82 have pseudo that does not read, by design (they teach the notation's error messages), and are left out below. That leaves **79 programs**.
|
||||
Each translator in `src/sync/` is run over every exercise with pseudo (17), every program in `tests/corpus/` (52), and 17 one-construct fixtures (`tests/helpers/sync-programs.mjs`). 3 of the 86 have pseudo that does not read, by design (they teach the notation's error messages), and are left out below. That leaves **83 programs**.
|
||||
|
||||
| From pseudo to | Says it completely | Says it with a gap or a checker error | Cannot say it |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| Mojo | 77 | 2 | 0 |
|
||||
| lingo | 31 | 0 | 48 |
|
||||
| matho | 3 | 0 | 76 |
|
||||
| Mojo | 80 | 3 | 0 |
|
||||
| lingo | 31 | 0 | 52 |
|
||||
| matho | 3 | 0 | 80 |
|
||||
|
||||
Mojo is a program-for-program translation that always produces something: a line with no faithful spelling becomes a visible `raise Error("not translated: pseudo line N")` and a warning. Lingo and matho must read back as the same program, so what they cannot say exactly they refuse, with the construct and its line, and the pane keeps its last good text.
|
||||
|
||||
@@ -16,7 +16,9 @@ Mojo is a program-for-program translation that always produces something: a line
|
||||
|
||||
These programs translate, with the listed lines left as a `raise Error`.
|
||||
|
||||
Nothing.
|
||||
| What it has no form for | Programs | Which |
|
||||
| --- | ---: | --- |
|
||||
| Programming+ could not translate this line into Mojo (the built-in EXACT, which Mojo's standard library has no function for). The generated code stops here with an error instead of guessing. | 1 | 50-float32.pseudo |
|
||||
|
||||
## Mojo: programs the translator refuses
|
||||
|
||||
@@ -30,7 +32,7 @@ English is read by `readSteps`, whose grammar has no sentence for these.
|
||||
|
||||
| What it has no form for | Programs | Which |
|
||||
| --- | ---: | --- |
|
||||
| steps outside a routine (every English step belongs to a routine) | 46 | 01-arithmetic.pseudo, 02-temperature.pseudo, 03-compound-interest.pseudo, 04-gcd-recursion.pseudo, and 42 more |
|
||||
| steps outside a routine (every English step belongs to a routine) | 50 | 01-arithmetic.pseudo, 02-temperature.pseudo, 03-compound-interest.pseudo, 04-gcd-recursion.pseudo, and 46 more |
|
||||
| a fixed-length ARRAY | 4 | ex:edit-distance, 05-primes-sieve.pseudo, 11-matrix-multiply.pseudo, 15-game-of-life.pseudo |
|
||||
| a BYREF parameter | 3 | 06-fibonacci-memo.pseudo, 10-insertion-sort.pseudo, 26-swap-byref.pseudo |
|
||||
| a HASHMAP whose values are not counts | 3 | ex:translate-codons, 13-stack-brackets.pseudo, 39-constants-codons.pseudo |
|
||||
@@ -62,7 +64,7 @@ An equation lowers to one `FUNCTION` that returns a value; a program with output
|
||||
|
||||
| What it has no form for | Programs | Which |
|
||||
| --- | ---: | --- |
|
||||
| steps outside a function (an equation is a function) | 42 | 01-arithmetic.pseudo, 02-temperature.pseudo, 03-compound-interest.pseudo, 04-gcd-recursion.pseudo, and 38 more |
|
||||
| steps outside a function (an equation is a function) | 46 | 01-arithmetic.pseudo, 02-temperature.pseudo, 03-compound-interest.pseudo, 04-gcd-recursion.pseudo, and 42 more |
|
||||
| a function that answers LIST (equations answer numbers) | 5 | ex:match, ex:match-proved, ex:match-off-by-one, ex:match-reset, and 1 more |
|
||||
| a function that answers STRING (equations answer numbers) | 5 | ex:revcomp, fixture:string-build, fixture:slice, fixture:case, and 1 more |
|
||||
| a function that answers BOOL (equations answer numbers) | 3 | ex:binary-search, fixture:early-return, fixture:forall |
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ The Prove tab reports every obligation in three statuses (`src/engines/pseudo/vc
|
||||
|
||||
| Shown | Earned by | Means | Does not mean |
|
||||
|---|---|---|---|
|
||||
| **Proved** | The built-in prover (`solver.ts`), on every path it examined, in a unit it examined completely | The claim follows from what is known, in the notation's number model: INTEGER as whole numbers of any size, FLOAT as finite numbers whose rounding is not seen into. The prover is sound (`tests/prover-soundness.test.mjs`) | That the Mojo made from the program has the same property. A 64-bit `Int` wraps and a `Float64` becomes `inf` or `nan`; the `int-model` and `float-model` notes say when a proof leans on the number model. A unit marked **partial** shows no claim as proved |
|
||||
| **Proved** | The built-in prover (`solver.ts`), on every path it examined, in a unit it examined completely | The claim follows from what is known, in the notation's number model: INTEGER as whole numbers of any size, the sized types (INT8 … UINT64) exactly, with an `overflow` obligation wherever a value could leave its range, FLOAT and FLOAT32 as finite numbers whose rounding is not seen into. The prover is sound (`tests/prover-soundness.test.mjs`). In a program that says `USE IEEE` nothing is marked proved | That the Mojo made from the program has the same property. A 64-bit `Int` wraps and a `Float64` becomes `inf` or `nan`; the `int-model` and `float-model` notes say when a proof leans on the number model. A unit marked **partial** shows no claim as proved |
|
||||
| **Broken** | A generated input (the fuzzer, seeded) or a run that breaks the claim at that place | There is an input for which the claim is false, and **Step through** shows it | Anything about other claims. A run outranks the prover: a proved obligation that an input breaks is shown as broken (and would be a soundness bug) |
|
||||
| **Open** | Neither of the above | The checker could not finish the argument, usually because a loop needs an INVARIANT | That the claim is false |
|
||||
| An invariant "the checker found on its own" | Inference in `vcgen.ts`, kept only at a fixed point | It holds on entry and survives every pass, and the proof used it | That it is the invariant a reader needs |
|
||||
|
||||
Reference in new issue
Block a user