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
@@ -0,0 +1,14 @@
|
||||
// Sized whole numbers: arithmetic that stays inside its type, wrapping only when asked, and conversions that check.
|
||||
// EXPECT: 255 0 255
|
||||
// EXPECT: 1500000000 -2 256
|
||||
// EXPECT: 8 14 6 255 1024 -4
|
||||
// EXPECT: 12 12 -128 2147483647
|
||||
DECLARE Count : UINT8 <- 250
|
||||
Count <- Count + 5
|
||||
OUTPUT Count, " ", WRAP(Count + 1, UINT8), " ", MAX_VALUE(UINT8)
|
||||
DECLARE Big : INT64 <- 3_000_000_000
|
||||
DECLARE Small : INT32
|
||||
Small <- INT32(Big DIV 2)
|
||||
OUTPUT Small, " ", INT16(-2.9), " ", 0xFF + 0b1
|
||||
OUTPUT BIT_AND(0b1100, 0b1010), " ", BIT_OR(12, 10), " ", BIT_XOR(12, 10), " ", BIT_NOT(UINT8(0)), " ", SHIFT_LEFT(1, 10), " ", SHIFT_RIGHT(-8, 1)
|
||||
OUTPUT GCD(84, 36), " ", LCM(4, 6), " ", MIN_VALUE(INT8), " ", MAX_VALUE(INT32)
|
||||
@@ -0,0 +1,20 @@
|
||||
// Single precision: every FLOAT32 result is rounded to 24 bits, and a literal next to a FLOAT32 is a FLOAT32.
|
||||
// EXPECT: 1.0000001 0.9999999999999999
|
||||
// EXPECT: TRUE FALSE
|
||||
// EXPECT: 0.100000001490116119384765625
|
||||
// EXPECT: 16777216.0 1.1920929e-7 1.1920929e-7
|
||||
// EXPECT: 5.551115123125783e-17 0.0
|
||||
// EXPECT: TRUE TRUE
|
||||
DECLARE X : FLOAT32 <- 0.1
|
||||
DECLARE Total32 : FLOAT32 <- 0.0
|
||||
DECLARE Total64 : FLOAT <- 0.0
|
||||
FOR I <- 0 TO 10
|
||||
Total32 <- Total32 + X
|
||||
Total64 <- Total64 + 0.1
|
||||
NEXT I
|
||||
OUTPUT Total32, " ", Total64
|
||||
OUTPUT X == 0.1, " ", FLOAT64(X) == 0.1
|
||||
OUTPUT EXACT(X)
|
||||
OUTPUT FLOAT32(16777217), " ", ULP(FLOAT32(1.0)), " ", EPSILON(FLOAT32)
|
||||
OUTPUT FMA(0.1, 10.0, -1.0), " ", 0.1 * 10.0 - 1.0
|
||||
OUTPUT IS_CLOSE(Total32, 1.0, 1e-6, 0.0), " ", IS_CLOSE(Total64, 1.0, 1e-15, 0.0)
|
||||
@@ -0,0 +1,12 @@
|
||||
// USE IEEE: NaN and the infinities flow through a calculation as IEEE 754 says, instead of stopping the run.
|
||||
// EXPECT: infinity -infinity not a number
|
||||
// EXPECT: TRUE TRUE FALSE TRUE
|
||||
// EXPECT: not a number -infinity FALSE
|
||||
USE IEEE
|
||||
DECLARE Zero : FLOAT <- 0.0
|
||||
DECLARE Inf : FLOAT
|
||||
Inf <- 1.0 / Zero
|
||||
DECLARE NotANumber : FLOAT <- Inf - Inf
|
||||
OUTPUT Inf, " ", -Inf, " ", NotANumber
|
||||
OUTPUT IS_INF(Inf), " ", IS_NAN(NotANumber), " ", NotANumber == NotANumber, " ", NotANumber != NotANumber
|
||||
OUTPUT SQRT(-1.0), " ", LOG(0.0), " ", IS_FINITE(MAX_VALUE(FLOAT64) * 2.0)
|
||||
@@ -0,0 +1,11 @@
|
||||
// Elementary functions for numerical work, and the accurate forms near 0.
|
||||
// EXPECT: 5.0 TRUE -3.0 1024.0
|
||||
// EXPECT: 1.00000000005e-10 1.000000082740371e-10 9.999999999500001e-11
|
||||
// EXPECT: -2.0 -1 -2.0 10 0.0
|
||||
// EXPECT: 3.142 3.142 0.0 0.0 2.718
|
||||
// EXPECT: TRUE 2.220446049250313e-16
|
||||
OUTPUT HYPOT(3.0, 4.0), " ", HYPOT(1e200, 1e200) > 1e200, " ", CBRT(-27.0), " ", POW(2.0, 10.0)
|
||||
OUTPUT EXPM1(1e-10), " ", EXP(1e-10) - 1.0, " ", LOG1P(1e-10)
|
||||
OUTPUT TRUNC(-2.7), " ", SIGN(-3), " ", COPYSIGN(2.0, -0.0), " ", CLAMP(15, 0, 10), " ", CLAMP(-0.5, 0.0, 1.0)
|
||||
OUTPUT ROUND(ASIN(1.0) * 2 * 1000) / 1000, " ", ROUND(ACOS(-1.0) * 1000) / 1000, " ", ATAN(0.0), " ", TANH(0.0), " ", ROUND(E() * 1000) / 1000
|
||||
OUTPUT NEXT_AFTER(1.0, 2.0) - 1.0 == EPSILON(FLOAT64), " ", ULP(1.0)
|
||||
@@ -0,0 +1,152 @@
|
||||
// Pseudo for numerical work: sized types, FLOAT32, conversions, the numerical built-ins, USE IEEE, and what the
|
||||
// prover may and may not say about them. The corpus programs 49 to 52 show the same features in use; this file
|
||||
// pins each rule on its own.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { studyOf, runPseudo, provePseudo } from '../dist/services/pseudo.js';
|
||||
import { fma, exactDecimal, nextAfter, ulp, roundDyadic, wrap } from '../dist/engines/pseudo/numeric.js';
|
||||
import { intRange, SIZED, formatFloat32 } from '../dist/engines/pseudo/lang.js';
|
||||
|
||||
const run = (src) => {
|
||||
const st = studyOf(src);
|
||||
assert.ok(st.ok, st.diagnostics.filter((d) => d.severity === 'error').map((d) => `L${d.line} ${d.id}: ${d.message}`).join(' | '));
|
||||
return runPseudo(st, {});
|
||||
};
|
||||
const out = (src) => { const r = run(src); assert.equal(r.error, null, r.error?.message); return r.output; };
|
||||
const errors = (src) => studyOf(src).diagnostics.filter((d) => d.severity === 'error').map((d) => d.id);
|
||||
|
||||
test('the sized types have the ranges of their names (64-bit types cut at what a run holds exactly)', () => {
|
||||
assert.deepEqual(intRange(SIZED.INT8), [-128, 127]);
|
||||
assert.deepEqual(intRange(SIZED.UINT16), [0, 65535]);
|
||||
assert.deepEqual(intRange(SIZED.INT32), [-2147483648, 2147483647]);
|
||||
assert.deepEqual(intRange(SIZED.UINT32), [0, 4294967295]);
|
||||
assert.deepEqual(intRange(SIZED.INT64), [-Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]);
|
||||
});
|
||||
|
||||
test('literals: underscores, hexadecimal and binary', () => {
|
||||
assert.deepEqual(out('OUTPUT 1_000_000, " ", 0xFF, " ", 0b1010, " ", 1_000.5'), ['1000000 255 10 1000.5']);
|
||||
assert.ok(errors('OUTPUT 1__0').includes('bad-number'));
|
||||
assert.ok(errors('OUTPUT 0xFG').includes('bad-number'));
|
||||
});
|
||||
|
||||
test('a sized result that leaves its range stops the run; WRAP wraps on purpose', () => {
|
||||
const r = run('DECLARE X : INT8 <- 127\nX <- X + 1\n');
|
||||
assert.equal(r.error?.kind, 'overflow');
|
||||
assert.equal(r.error.line, 2);
|
||||
assert.match(r.error.message, /INT8 holds -128 to 127/);
|
||||
assert.deepEqual(out('DECLARE X : INT8 <- 127\nOUTPUT WRAP(X + 1, INT8), " ", WRAP(-1, UINT8), " ", WRAP(70000, UINT16)'), ['-128 255 4464']);
|
||||
assert.equal(run('DECLARE U : UINT8 <- 0\nU <- U - 1\n').error?.kind, 'overflow');
|
||||
assert.equal(run('DECLARE X : INT8\nX <- -128\nX <- -X\n').error?.kind, 'overflow');
|
||||
});
|
||||
|
||||
test('storing, passing and returning check the range of the receiving type', () => {
|
||||
assert.equal(run('DECLARE N : INTEGER <- 300\nDECLARE B : UINT8\nB <- N\n').error?.kind, 'overflow');
|
||||
const src = 'FUNCTION Id(X : UINT8) RETURNS UINT8\n RETURN X\nENDFUNCTION\nDECLARE N : INTEGER <- 256\nOUTPUT Id(N)\n';
|
||||
const r = run(src);
|
||||
assert.equal(r.error?.kind, 'overflow');
|
||||
assert.match(r.error.message, /Parameter X of Id/);
|
||||
assert.equal(run('FUNCTION Big(N : INTEGER) RETURNS INT16\n RETURN N * 1000\nENDFUNCTION\nOUTPUT Big(40)\n').error?.kind, 'overflow');
|
||||
});
|
||||
|
||||
test('conversions: a FLOAT loses its fraction toward zero, and a value that does not fit stops the run', () => {
|
||||
assert.deepEqual(out('OUTPUT INT32(-2.9), " ", UINT8(200), " ", INT64(2.5e9), " ", FLOAT32(0.1) == FLOAT32(0.1)'), ['-2 200 2500000000 TRUE']);
|
||||
assert.deepEqual(errors('OUTPUT INT8(200)'), ['literal-range']); // a literal is checked before any run
|
||||
assert.equal(run('DECLARE N : INTEGER <- 200\nOUTPUT INT8(N)').error?.kind, 'overflow');
|
||||
assert.equal(run('DECLARE F : FLOAT <- 3.0e9\nOUTPUT INT32(F)').error?.kind, 'overflow');
|
||||
});
|
||||
|
||||
test('the checker: widths and precisions do not mix silently, and literals take the type beside them', () => {
|
||||
assert.deepEqual(errors('DECLARE A : INT8 <- 1\nDECLARE B : INT32 <- 2\nOUTPUT A + B'), ['mixed-width']);
|
||||
assert.deepEqual(errors('DECLARE A : FLOAT32 <- 1.0\nDECLARE B : FLOAT <- 2.0\nOUTPUT A * B'), ['mixed-precision']);
|
||||
assert.deepEqual(errors('DECLARE A : INT8\nA <- 300'), ['literal-range']);
|
||||
assert.deepEqual(errors('DECLARE A : INT8 <- 1\nDECLARE B : INT32 <- 2\nB <- A'), ['type']);
|
||||
assert.deepEqual(errors('DECLARE A : FLOAT32\nDECLARE D : FLOAT <- 0.5\nA <- D'), ['type']);
|
||||
assert.deepEqual(errors('DECLARE A : FLOAT32\nDECLARE D : FLOAT <- 0.5\nA <- FLOAT32(D)'), []);
|
||||
assert.deepEqual(errors('DECLARE A : FLOAT32\nA <- 0.1'), []);
|
||||
assert.deepEqual(errors('OUTPUT INT8'), ['type-as-value']);
|
||||
assert.deepEqual(errors('OUTPUT MAX_VALUE(INT64)'), ['exact-limit']);
|
||||
assert.deepEqual(errors('OUTPUT WRAP(5, UINT64)'), ['wrap-64']);
|
||||
assert.deepEqual(errors('DECLARE X : INTEGER <- 1\nOUTPUT EPSILON(INT32)'), ['type']);
|
||||
});
|
||||
|
||||
test('FLOAT32: results round to single precision, a literal next to one is a single, and it prints as the shortest decimal', () => {
|
||||
assert.deepEqual(out('DECLARE X : FLOAT32 <- 0.1\nOUTPUT X, " ", X == 0.1, " ", FLOAT64(X) == 0.1, " ", X + 0.2'), ['0.1 TRUE FALSE 0.3']);
|
||||
assert.deepEqual(out('DECLARE X : FLOAT32 <- 16777216.0\nOUTPUT X + 1.0, " ", FLOAT64(X) + 1.0'), ['16777216.0 16777217.0']);
|
||||
assert.equal(formatFloat32(Math.fround(0.1)), '0.1');
|
||||
assert.equal(formatFloat32(Math.fround(1 / 3)), '0.33333334');
|
||||
});
|
||||
|
||||
test('exact helpers: FMA rounds once, EXACT shows every digit, ULP and NEXT_AFTER step by one value', () => {
|
||||
assert.equal(fma(0.1, 10, -1), 5.551115123125783e-17);
|
||||
assert.equal(0.1 * 10 - 1, 0);
|
||||
assert.equal(fma(2, 3, 4), 10);
|
||||
assert.equal(fma(Math.fround(0.1), 10, -1, true), Math.fround(1.4901161193847656e-8));
|
||||
assert.equal(exactDecimal(0.1), '0.1000000000000000055511151231257827021181583404541015625');
|
||||
assert.equal(exactDecimal(-2.5), '-2.5');
|
||||
assert.equal(exactDecimal(1e21), '1000000000000000000000.0');
|
||||
assert.equal(exactDecimal(Number.MIN_VALUE).length, 1076); // 4.94...e-324 has 1074 digits after the point
|
||||
assert.equal(nextAfter(1, 2), 1 + Number.EPSILON);
|
||||
assert.equal(nextAfter(0, -1), -Number.MIN_VALUE);
|
||||
assert.equal(nextAfter(1, 2, true), 1 + 2 ** -23);
|
||||
assert.equal(ulp(1), Number.EPSILON);
|
||||
assert.equal(ulp(Number.MAX_VALUE), 2 ** 971);
|
||||
assert.equal(ulp(1, true), 2 ** -23);
|
||||
assert.equal(roundDyadic(3n, -1), 1.5);
|
||||
assert.equal(roundDyadic((1n << 54n) + 1n, 0), 2 ** 54); // ties and below round to even
|
||||
assert.equal(wrap(-129, 8, true), 127);
|
||||
assert.deepEqual(out('OUTPUT FMA(0.1, 10.0, -1.0), " ", ULP(1.0) == EPSILON(FLOAT64), " ", EXACT(0.5)'), ['5.551115123125783e-17 TRUE 0.5']);
|
||||
});
|
||||
|
||||
test('whole numbers bit by bit, two\'s complement for negative values', () => {
|
||||
assert.deepEqual(out('OUTPUT BIT_AND(-1, 255), " ", BIT_OR(-8, 1), " ", BIT_XOR(5, 3), " ", BIT_NOT(5), " ", BIT_NOT(UINT8(5))'), ['255 -7 6 -6 250']);
|
||||
assert.deepEqual(out('OUTPUT SHIFT_LEFT(3, 4), " ", SHIFT_RIGHT(-9, 1), " ", SHIFT_RIGHT(UINT8(255), 4), " ", GCD(-12, 18), " ", LCM(6, 8)'), ['48 -5 15 6 24']);
|
||||
assert.equal(run('DECLARE B : UINT8 <- 200\nOUTPUT SHIFT_LEFT(B, 1)').error?.kind, 'overflow');
|
||||
});
|
||||
|
||||
test('the limits of each type', () => {
|
||||
assert.deepEqual(out('OUTPUT MAX_VALUE(INT8), " ", MIN_VALUE(INT16), " ", MAX_VALUE(UINT32), " ", MIN_VALUE(UINT64)'), ['127 -32768 4294967295 0']);
|
||||
assert.deepEqual(out('OUTPUT MAX_VALUE(FLOAT64) > 1e308, " ", EPSILON(FLOAT64), " ", MAX_VALUE(FLOAT32)'), ['TRUE 2.220446049250313e-16 3.4028235e38']);
|
||||
});
|
||||
|
||||
test('domains: without USE IEEE the run stops where IEEE 754 would give NaN or an infinity; with it, the values flow', () => {
|
||||
for (const [e, kind] of [['SQRT(-1.0)', 'value'], ['LOG(0.0)', 'value'], ['ASIN(2.0)', 'value'], ['1.0 / 0.0', 'divide'], ['MAX_VALUE(FLOAT64) * 2.0', 'overflow'], ['INF()', 'overflow'], ['LOG1P(-1.0)', 'value']]) {
|
||||
assert.equal(run(`OUTPUT ${e}`).error?.kind, kind, e);
|
||||
}
|
||||
assert.deepEqual(out('USE IEEE\nOUTPUT SQRT(-1.0), " ", 1.0 / 0.0, " ", -1.0 / 0.0, " ", IS_NAN(NAN()), " ", NAN() == NAN()'), ['not a number infinity -infinity TRUE FALSE']);
|
||||
// whole-number division by zero still stops: IEEE 754 is about FLOAT values
|
||||
assert.equal(run('USE IEEE\nOUTPUT 1 DIV 0').error?.kind, 'divide');
|
||||
});
|
||||
|
||||
test('names: a program may still call its variable E or its function GCD, and its own definition wins', () => {
|
||||
assert.deepEqual(out('DECLARE E : FLOAT <- 2.0\nOUTPUT E * 2.0, " ", ROUND(E() * 100)'), ['4.0 272']);
|
||||
assert.deepEqual(out('FUNCTION GCD(A : INTEGER, B : INTEGER) RETURNS INTEGER\n RETURN 7\nENDFUNCTION\nOUTPUT GCD(12, 18)'), ['7']);
|
||||
assert.ok(errors('DECLARE LENGTH : INTEGER').includes('builtin-name'));
|
||||
assert.ok(errors('DECLARE INT8 : INTEGER').length > 0);
|
||||
});
|
||||
|
||||
test('the prover: sized arithmetic carries an overflow obligation; FLOAT32 is a function of its own; USE IEEE proves nothing', () => {
|
||||
const report = (src) => provePseudo(studyOf(src)).units.flatMap((u) => u.obligations.map((o) => ({ ...o, unit: u.name, notes: u.notes })));
|
||||
const guarded = report('FUNCTION Inc(X : INT8) RETURNS INT8\n REQUIRE X < 127\n RETURN X + 1\nENDFUNCTION\n');
|
||||
assert.deepEqual(guarded.filter((o) => o.kind === 'overflow').map((o) => o.status), ['proved']);
|
||||
const open = report('FUNCTION Inc(X : INT8) RETURNS INT8\n RETURN X + 1\nENDFUNCTION\n');
|
||||
assert.deepEqual(open.filter((o) => o.kind === 'overflow').map((o) => o.status), ['broken']); // the fuzzer tries 127
|
||||
const narrow = report('FUNCTION N(K : INTEGER) RETURNS UINT8\n REQUIRE 0 <= K AND K < 256\n RETURN K\nENDFUNCTION\n');
|
||||
assert.deepEqual(narrow.filter((o) => o.kind === 'overflow').map((o) => o.status), ['proved']);
|
||||
const loop = report('FUNCTION Count(N : UINT8) RETURNS UINT8\n DECLARE C : UINT8 <- 0\n FOR I <- 0 TO N\n INVARIANT C == I\n C <- C + 1\n NEXT I\n RETURN C\nENDFUNCTION\n');
|
||||
assert.ok(loop.filter((o) => o.kind === 'overflow').every((o) => o.status === 'proved'), JSON.stringify(loop.map((o) => [o.kind, o.status])));
|
||||
const half = report('FUNCTION Half(X : FLOAT32) RETURNS FLOAT32\n ENSURE RESULT == X / 2.0\n RETURN X / 2.0\nENDFUNCTION\n');
|
||||
assert.ok(half.find((o) => o.kind === 'ensure').status === 'proved');
|
||||
const roots = report('FUNCTION R(X : FLOAT) RETURNS FLOAT\n RETURN SQRT(X)\nENDFUNCTION\n');
|
||||
assert.deepEqual(roots.filter((o) => o.kind === 'argument').map((o) => o.status), ['broken']);
|
||||
const ieee = report('USE IEEE\nFUNCTION F(X : INTEGER) RETURNS INTEGER\n REQUIRE X > 0\n RETURN 10 DIV X\nENDFUNCTION\n');
|
||||
assert.ok(ieee.length && ieee.every((o) => o.status !== 'proved'));
|
||||
assert.ok(ieee[0].notes.some((n) => /USE IEEE/.test(n)));
|
||||
});
|
||||
|
||||
test('the fuzzer reaches the edges of a sized type and generates FLOAT32 values', async () => {
|
||||
const { checkProperties } = await import('../dist/engines/pseudo/testing.js');
|
||||
const st = studyOf('FUNCTION F(X : UINT8, Y : FLOAT32) RETURNS BOOL\n ASSERT X != 255\n ASSERT FLOAT32(Y) == Y\n RETURN TRUE\nENDFUNCTION\n');
|
||||
const fails = checkProperties(st.program.program, 'F', { count: 300 }).failures;
|
||||
assert.ok(fails.some((f) => f.kind === 'assert' && f.line === 2), 'X = 255 is never tried');
|
||||
assert.ok(!fails.some((f) => f.line === 3), 'a generated FLOAT32 is not a single');
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
// A whole number stored in a FLOAT32 is rounded to the nearest single:
|
||||
// 16777217 becomes 16777216. A rule that kept the INTEGER's value for the
|
||||
// FLOAT32 would prove this ASSERT, and the run breaks it.
|
||||
// MUST-NOT-PROVE: assert@8
|
||||
DECLARE N : INTEGER <- 16777217
|
||||
DECLARE X : FLOAT32
|
||||
X <- N
|
||||
ASSERT X == N
|
||||
@@ -0,0 +1,7 @@
|
||||
// With USE IEEE a FLOAT can be NaN, and NaN == NaN is FALSE. The prover's
|
||||
// rule that every number equals itself does not hold for NaN, so nothing in
|
||||
// a program that says USE IEEE may be marked proved.
|
||||
// MUST-NOT-PROVE: assert@7
|
||||
USE IEEE
|
||||
DECLARE X : FLOAT <- NAN()
|
||||
ASSERT X == X
|
||||
@@ -0,0 +1,7 @@
|
||||
// INT8 holds -128 to 127. X + 1 for X = 127 is 128, which does not fit, so
|
||||
// the run stops there. A rule that treated the sum as an exact whole number
|
||||
// with no range would prove it fits without a REQUIRE to guarantee it.
|
||||
// MUST-NOT-PROVE: overflow@6
|
||||
FUNCTION Inc(X : INT8) RETURNS INT8
|
||||
RETURN X + 1
|
||||
ENDFUNCTION
|
||||
@@ -7,7 +7,7 @@ import { studyOf } from '../dist/services/pseudo.js';
|
||||
import { readLingo } from '../dist/services/lingo.js';
|
||||
import { parseSpeco, toAscii, toMath } from '../dist/services/speco.js';
|
||||
import { parseAsm } from '../dist/services/asm.js';
|
||||
import { KEYWORDS, BUILTINS } from '../dist/engines/pseudo/lang.js';
|
||||
import { KEYWORDS, BUILTINS, SOFT_BUILTINS } from '../dist/engines/pseudo/lang.js';
|
||||
import { OPS } from '../dist/engines/asm86/interp.js';
|
||||
|
||||
test('every pseudocode statement example parses and checks', () => {
|
||||
@@ -109,7 +109,8 @@ test('every pseudo idiom runs and prints what its note says', async () => {
|
||||
const words = new Set(reserved.entries.map((e) => e.term));
|
||||
for (const k of KW) assert.ok(words.has(k), `reserved list misses keyword ${k}`);
|
||||
for (const k of Object.keys(CONTEXTUAL)) assert.ok(words.has(k), `reserved list misses ${k}`);
|
||||
for (const k of Object.keys(BI)) assert.ok(words.has(k), `reserved list misses built-in ${k}`);
|
||||
// the built-ins added for numerical work stay usable as names (a variable E, a FUNCTION GCD), so they are not listed
|
||||
for (const k of Object.keys(BI)) assert.ok(SOFT_BUILTINS.has(k) ? !words.has(k) : words.has(k), SOFT_BUILTINS.has(k) ? `${k} can be a name, so it is not reserved` : `reserved list misses built-in ${k}`);
|
||||
});
|
||||
|
||||
test('every matho example translates to pseudo that checks, and every refusal is refused', () => {
|
||||
|
||||
@@ -41,6 +41,10 @@ const KNOWN_GAPS = {
|
||||
'33-stops-div.pseudo': ['differs', 'dividing by zero stops the notation; a Float64 division in Mojo gives nan'],
|
||||
'44-parallel-race.pseudo': ['differs', 'the notation detects a data race in PARALLEL FOR; Mojo runs the passes in order and prints a result'],
|
||||
'45-parallel-neighbour-race.pseudo': ['differs', 'the notation detects a data race in PARALLEL FOR; Mojo runs the passes in order and prints a result'],
|
||||
'49-sized-integers.pseudo': ['declined', 'gcd and lcm from std.math are not run by the interpreter yet'],
|
||||
'50-float32.pseudo': ['gap', 'EXACT has no Mojo spelling: Mojo prints the shortest decimal that rounds back, never the exact value'],
|
||||
'51-ieee.pseudo': ['declined', 'isinf, isnan and inf[DType.float64]() are not run by the interpreter yet'],
|
||||
'52-elementary.pseudo': ['declined', 'hypot and the other math functions are not run by the interpreter yet'],
|
||||
'35-stops-unset.pseudo': ['checker', 'the pseudo reads a variable that was never given a value; the checker reports exactly that, as the compiler would'],
|
||||
'36-stops-counter.pseudo': ['checker', 'the pseudo reads a FOR counter after its loop, where it has no value; the checker reports exactly that'],
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user