gdp-wired 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
package/dist/core/dsl.js
CHANGED
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
// both runtimes do.
|
|
18
18
|
import { candidates, cone, searchCounted } from "./counts.js";
|
|
19
19
|
import { env as knobs } from "./solver.js";
|
|
20
|
-
import { argsKey, machineTerms, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
|
|
20
|
+
import { argsKey, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
|
|
21
21
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
22
|
-
import { ghostOf, proveSome, someHolds, substVars, substVarsE } from "./exists.js";
|
|
23
|
-
import { check, checkRecur, foldObligations, loopObligations, substC, sumMachine } from "../kernel/kernel.js";
|
|
24
|
-
import { certLoop, clock, counted, factsFor, fullRate, grow, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
|
|
22
|
+
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
23
|
+
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
24
|
+
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
|
|
25
25
|
import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
|
|
26
26
|
import { discover } from "./discover.js";
|
|
27
|
-
import { inferLaws } from "./infer.js";
|
|
27
|
+
import { inferLaws, inferRates } from "./infer.js";
|
|
28
28
|
import { findBoundedRun } from "./bmc.js";
|
|
29
29
|
import { conjunction, proveKInduction } from "./kind.js";
|
|
30
30
|
import { cycleLemmas, findLeadsTo, findRank } from "./cycles.js";
|
|
@@ -44,12 +44,6 @@ export const termOf = (t) => {
|
|
|
44
44
|
throw new TypeError('a natural is expected here; an integer or a decimal compares from its own side (x.atMost(n))');
|
|
45
45
|
return t.e;
|
|
46
46
|
};
|
|
47
|
-
// A natural-valued term. `minus` is truncated (a ∸ b), `times` multiplies by a constant, `mul` by another term (a
|
|
48
|
-
// product: the kernel proves with it, the GPU searches don't take it).
|
|
49
|
-
//
|
|
50
|
-
// Each term and condition may also carry its value (`val`, `ok`), computed beside its expression by plain JavaScript
|
|
51
|
-
// when every value it reads is known: what `crossCheck` compares with the expression the interpreter evaluates, so a
|
|
52
|
-
// builder that writes a different expression than it means is caught on concrete runs.
|
|
53
47
|
export class Term {
|
|
54
48
|
e;
|
|
55
49
|
val;
|
|
@@ -66,6 +60,22 @@ export class Term {
|
|
|
66
60
|
// constant has no such fact in linear arithmetic (x = y·q + r is a product of two unknowns), so it isn't offered.
|
|
67
61
|
modBy(k) { divisor(k, 'modBy'); return new Term({ op: 'get', map: modName(k), key: this.e }, this.val === undefined ? undefined : this.val % k); }
|
|
68
62
|
divBy(k) { divisor(k, 'divBy'); return new Term({ op: 'get', map: divName(k), key: this.e }, this.val === undefined ? undefined : Math.floor(this.val / k)); }
|
|
63
|
+
// On a tick of k (a constant k >= 1, a price's tick, a lot size): the multiple of k below (floorTo), above (ceilTo) or
|
|
64
|
+
// nearest (roundTo, a half by the mode: 'halfEven' Python's round, 'halfUp' JavaScript's and Java's Math.round,
|
|
65
|
+
// 'halfDown', 'halfAway' Go's and Rust's round; a natural's halfAway is its halfUp), each from divBy and modBy, so the
|
|
66
|
+
// kernel knows them by the same facts; and whether it is on one (onTick).
|
|
67
|
+
floorTo(k) { return this.divBy(k).times(k); }
|
|
68
|
+
ceilTo(k) { divisor(k, 'ceilTo'); return this.plus(k - 1).divBy(k).times(k); }
|
|
69
|
+
roundTo(k, mode = 'halfEven') {
|
|
70
|
+
divisor(k, 'roundTo');
|
|
71
|
+
if (mode === 'halfUp' || mode === 'halfAway')
|
|
72
|
+
return this.times(2).plus(k).divBy(2 * k).times(k);
|
|
73
|
+
if (mode === 'halfDown')
|
|
74
|
+
return this.times(2).plus(k - 1).divBy(2 * k).times(k);
|
|
75
|
+
const q = this.divBy(k), r2 = this.modBy(k).times(2);
|
|
76
|
+
return when(r2.lt(k), q, when(lit(k).lt(r2), q.plus(1), q.plus(q.modBy(2)))).times(k);
|
|
77
|
+
}
|
|
78
|
+
onTick(k) { return this.modBy(k).eq(0); }
|
|
69
79
|
lt(b) { return new Cond({ op: '<', a: this.e, b: termOf(b) }, both(this.val, valOf(b), (x, y) => x < y)); }
|
|
70
80
|
atMost(b) { return new Cond({ op: '<=', a: this.e, b: termOf(b) }, both(this.val, valOf(b), (x, y) => x <= y)); }
|
|
71
81
|
gt(b) { return new Cond({ op: '<', a: termOf(b), b: this.e }, both(this.val, valOf(b), (x, y) => x > y)); }
|
|
@@ -275,6 +285,24 @@ export class Int {
|
|
|
275
285
|
// the same remainder, and its quotient is x div k + neg, so both are the natural division of that one natural.
|
|
276
286
|
modBy(k) { divisor(k, 'modBy'); return add(this.pos, this.neg.times(k - 1)).modBy(k); }
|
|
277
287
|
divBy(k) { divisor(k, 'divBy'); return new Int(add(this.pos, this.neg.times(k - 1)).divBy(k), this.neg); }
|
|
288
|
+
// On a tick of k, as a natural's (Term.floorTo, ceilTo, roundTo, onTick), below 0 too: halfAway rounds a half away
|
|
289
|
+
// from 0 (up above it, down below it), halfUp toward +∞, halfDown toward −∞.
|
|
290
|
+
floorTo(k) { return this.divBy(k).times(k); }
|
|
291
|
+
ceilTo(k) { return this.negate().floorTo(k).negate(); }
|
|
292
|
+
roundTo(k, mode = 'halfEven') {
|
|
293
|
+
divisor(k, 'roundTo');
|
|
294
|
+
// (a half up: ⌊(2x + k) / 2k⌋·k; a half down: ⌈(2x − k) / 2k⌉·k, that is −⌊(k − 2x) / 2k⌋·k)
|
|
295
|
+
const up = () => this.times(2).plus(k).divBy(2 * k).times(k), down = () => Int.of(k).minus(this.times(2)).divBy(2 * k).times(k).negate();
|
|
296
|
+
if (mode === 'halfUp')
|
|
297
|
+
return up();
|
|
298
|
+
if (mode === 'halfDown')
|
|
299
|
+
return down();
|
|
300
|
+
if (mode === 'halfAway')
|
|
301
|
+
return when(this.isNegative, down(), up());
|
|
302
|
+
const q = this.divBy(k), r2 = this.modBy(k).times(2);
|
|
303
|
+
return when(r2.lt(k), q, when(lit(k).lt(r2), q.plus(1), q.plus(q.modBy(2)))).times(k);
|
|
304
|
+
}
|
|
305
|
+
onTick(k) { return this.modBy(k).eq(0); }
|
|
278
306
|
// |value|, and the value where it is not negative (0 below).
|
|
279
307
|
get abs() { return this.pos.minus(this.neg).plus(this.neg.minus(this.pos)); }
|
|
280
308
|
get clamped() { return this.pos.minus(this.neg); }
|
|
@@ -323,6 +351,13 @@ export class Decimal {
|
|
|
323
351
|
min(b) { return this.with(this.int.min(this.lift(b))); }
|
|
324
352
|
max(b) { return this.with(this.int.max(this.lift(b))); }
|
|
325
353
|
get isNegative() { return this.int.isNegative; }
|
|
354
|
+
// On a tick written in the decimal's own units (0.05 at 2 places is 5 cents): Int's floorTo, ceilTo, roundTo, onTick.
|
|
355
|
+
tick(t) { const n = scaledOf(t, this.places, 'a tick'); if (n < 1)
|
|
356
|
+
throw new RangeError(`a tick is positive, not ${t}`); return n; }
|
|
357
|
+
floorTo(t) { return this.with(this.int.floorTo(this.tick(t))); }
|
|
358
|
+
ceilTo(t) { return this.with(this.int.ceilTo(this.tick(t))); }
|
|
359
|
+
roundTo(t, mode = 'halfEven') { return this.with(this.int.roundTo(this.tick(t), mode)); }
|
|
360
|
+
onTick(t) { return this.int.onTick(this.tick(t)); }
|
|
326
361
|
}
|
|
327
362
|
const asNat = (name, raw) => {
|
|
328
363
|
if (typeof raw !== 'number' || !Number.isSafeInteger(raw) || raw < 0)
|
|
@@ -924,6 +959,37 @@ export class MapRef {
|
|
|
924
959
|
// The sum over every key of the cells, or of a term of the cell (the map starts where it is 0): exact, unbounded.
|
|
925
960
|
sum(of) { return sumOver(this.name, key => (of ? of(this.at(key)) : this.at(key)), !of); }
|
|
926
961
|
}
|
|
962
|
+
// A relation over sorts (`.relations({route: ['Node', 'Node', 'Node']})`): a set of tuples, a map keyed by tuples
|
|
963
|
+
// (core/machine.ts's tup), each cell 0 or 1. The kernel compares two tuples part by part, never by arithmetic, so the
|
|
964
|
+
// laws over relations are EPR's (the protocols' laws, as Ivy and mypyvy state them). One write per relation per step:
|
|
965
|
+
// a tuple added or removed, or the relation after the step as a set comprehension (`each`, or `union`), which writes
|
|
966
|
+
// many tuples at once.
|
|
967
|
+
export class RelRef {
|
|
968
|
+
name;
|
|
969
|
+
sorts;
|
|
970
|
+
constructor(name, sorts) {
|
|
971
|
+
this.name = name;
|
|
972
|
+
this.sorts = sorts;
|
|
973
|
+
}
|
|
974
|
+
key(xs) {
|
|
975
|
+
if (xs.length !== this.sorts.length)
|
|
976
|
+
throw new Error(`${this.name} relates ${this.sorts.length} (${this.sorts.join(', ')}), not ${xs.length}`);
|
|
977
|
+
return xs.length === 1 ? termOf(xs[0]) : tuple(xs.map(termOf));
|
|
978
|
+
}
|
|
979
|
+
// The cell at a tuple (0 or 1), and whether the tuple is in the relation.
|
|
980
|
+
at(...xs) { return new Term({ op: 'get', map: this.name, key: this.key(xs) }); }
|
|
981
|
+
has(...xs) { return this.at(...xs).atLeast(1); }
|
|
982
|
+
// The relation after the step: each tuple in it where f holds (its parts as f reads them).
|
|
983
|
+
each(f) {
|
|
984
|
+
const each = `k$${++boundCounter}`, n = this.sorts.length, k = v(each);
|
|
985
|
+
const parts = n === 1 ? [k] : Array.from({ length: n }, (_, i) => new Term(part(k.e, i, n)));
|
|
986
|
+
return { map: this.name, each, value: when(f(...parts), 1, 0).e };
|
|
987
|
+
}
|
|
988
|
+
// The relation with the tuples where f holds added; with one tuple added or removed where c holds.
|
|
989
|
+
union(f) { return this.each((...xs) => this.has(...xs).or(f(...xs))); }
|
|
990
|
+
add(xs, c = yes) { const key = this.key(xs); return { map: this.name, key, value: when(c, 1, new Term({ op: 'get', map: this.name, key })).e }; }
|
|
991
|
+
remove(xs, c = yes) { const key = this.key(xs); return { map: this.name, key, value: when(c, 0, new Term({ op: 'get', map: this.name, key })).e }; }
|
|
992
|
+
}
|
|
927
993
|
export class ListRef {
|
|
928
994
|
name;
|
|
929
995
|
len;
|
|
@@ -1289,7 +1355,9 @@ function swapE(e, from, to) {
|
|
|
1289
1355
|
case 'sub':
|
|
1290
1356
|
case 'min':
|
|
1291
1357
|
case 'max':
|
|
1292
|
-
case 'prod':
|
|
1358
|
+
case 'prod':
|
|
1359
|
+
case 'tup': return { ...e, a: swapE(e.a, from, to), b: swapE(e.b, from, to) };
|
|
1360
|
+
case 'proj': return { ...e, a: swapE(e.a, from, to) };
|
|
1293
1361
|
}
|
|
1294
1362
|
}
|
|
1295
1363
|
function perStep(c) {
|
|
@@ -1321,7 +1389,9 @@ function perStepE(e) {
|
|
|
1321
1389
|
case 'sub':
|
|
1322
1390
|
case 'min':
|
|
1323
1391
|
case 'max':
|
|
1324
|
-
case 'prod':
|
|
1392
|
+
case 'prod':
|
|
1393
|
+
case 'tup': return perStepE(e.a) ?? perStepE(e.b);
|
|
1394
|
+
case 'proj': return perStepE(e.a);
|
|
1325
1395
|
}
|
|
1326
1396
|
}
|
|
1327
1397
|
class Hoister {
|
|
@@ -1355,7 +1425,9 @@ class Hoister {
|
|
|
1355
1425
|
case 'sub':
|
|
1356
1426
|
case 'min':
|
|
1357
1427
|
case 'max':
|
|
1358
|
-
case 'prod':
|
|
1428
|
+
case 'prod':
|
|
1429
|
+
case 'tup': return { ...e, a: this.term(e.a, bound), b: this.term(e.b, bound) };
|
|
1430
|
+
case 'proj': return { ...e, a: this.term(e.a, bound) };
|
|
1359
1431
|
}
|
|
1360
1432
|
}
|
|
1361
1433
|
// A quantifier as a flag (or, with per-step truths inside, a condition over flags).
|
|
@@ -1600,6 +1672,8 @@ const recurJs = (name, args, zero, next, uses) => {
|
|
|
1600
1672
|
case 'min': return `Math.min(${js(e.a)}, ${js(e.b)})`;
|
|
1601
1673
|
case 'max': return `Math.max(${js(e.a)}, ${js(e.b)})`;
|
|
1602
1674
|
case 'if': return `(${jc(e.c)} ? ${js(e.then)} : ${js(e.else)})`;
|
|
1675
|
+
case 'tup':
|
|
1676
|
+
case 'proj': throw new Error('a recurrence takes no tuple key');
|
|
1603
1677
|
case 'get': {
|
|
1604
1678
|
const i = uses.findIndex(([u]) => u === e.map), args = uses[i][1].arity > 1 ? pairedArgs(e.key, uses[i][1].arity) : undefined;
|
|
1605
1679
|
return args ? `$g${i}(${args.map(js).join(', ')})` : `${fns.get(e.map)}(${js(e.key)})`;
|
|
@@ -1679,7 +1753,9 @@ const markedE = (e) => {
|
|
|
1679
1753
|
case 'sub':
|
|
1680
1754
|
case 'min':
|
|
1681
1755
|
case 'max':
|
|
1682
|
-
case 'prod':
|
|
1756
|
+
case 'prod':
|
|
1757
|
+
case 'tup': return { ...e, a: markedE(e.a), b: markedE(e.b) };
|
|
1758
|
+
case 'proj': return { ...e, a: markedE(e.a) };
|
|
1683
1759
|
}
|
|
1684
1760
|
};
|
|
1685
1761
|
const marked = (c) => c.op === 'flag' ? c : c.op === 'all' ? { ...c, c: marked(c.c) } : c.op === 'not' ? { op: 'not', x: marked(c.x) } : c.op === 'and' || c.op === 'or' ? { op: c.op, xs: c.xs.map(marked) } : { ...c, a: markedE(c.a), b: markedE(c.b) };
|
|
@@ -1714,9 +1790,10 @@ export class Rule {
|
|
|
1714
1790
|
const m = this.machine;
|
|
1715
1791
|
if (m.history)
|
|
1716
1792
|
return undefined;
|
|
1717
|
-
const have = new Set(Object.keys(m.sums ?? {})), more = new Set(this.spec.sumsRead ?? []);
|
|
1793
|
+
const have = new Set(Object.keys(m.sums ?? {})), more = new Set(this.spec.sumsRead ?? []), arity = mapArities(m);
|
|
1718
1794
|
for (const [map, init] of Object.entries(m.maps ?? {})) {
|
|
1719
|
-
|
|
1795
|
+
// (a map keyed by tuples has no sum read at one key: a sum's term reads its maps at the key alone)
|
|
1796
|
+
if (init !== 0 || !m.step.maps?.[map] || (m.inputMaps ?? []).includes(map) || (arity[map] ?? 1) > 1)
|
|
1720
1797
|
continue;
|
|
1721
1798
|
const name = new MapRef(map, 0).sum().e.name;
|
|
1722
1799
|
if (have.has(name))
|
|
@@ -1773,6 +1850,18 @@ export class Rule {
|
|
|
1773
1850
|
}
|
|
1774
1851
|
return this.with({ maps: [...this.spec.maps, ...maps], cells: [...(this.spec.cells ?? []), ...cells] });
|
|
1775
1852
|
}
|
|
1853
|
+
// Sorts: names for sets of identities (nodes, packets, values), unbounded, read only by equality; a relation's places
|
|
1854
|
+
// and a law's keys name theirs. Relations over them, each starting empty: `.relations({route: ['Node', 'Node']})`.
|
|
1855
|
+
sorts(...names) { return this.with({ sorts: [...(this.spec.sorts ?? []), ...names] }); }
|
|
1856
|
+
relations(x) {
|
|
1857
|
+
if (typeof x === 'function')
|
|
1858
|
+
return this.with({ relations: x });
|
|
1859
|
+
for (const [n, sorts] of Object.entries(x))
|
|
1860
|
+
for (const so of sorts)
|
|
1861
|
+
if (!(this.spec.sorts ?? []).includes(so))
|
|
1862
|
+
throw new Error(`relation ${n}: ${so} is no sort of ${this.spec.name} (.sorts(...) first)`);
|
|
1863
|
+
return this.with({ maps: [...this.spec.maps, ...Object.keys(x).map(n => [n, 0])], rels: [...(this.spec.rels ?? []), ...Object.entries(x).map(([n, so]) => [n, [...so]])] });
|
|
1864
|
+
}
|
|
1776
1865
|
// Integers (Int), each starting at an integer or at one over the params; kept as two naturals, <name> and <name>$neg.
|
|
1777
1866
|
ints(init) {
|
|
1778
1867
|
return this.state(Object.fromEntries(Object.entries(init).map(([n, x]) => [n, int.from(x)])));
|
|
@@ -1816,7 +1905,8 @@ export class Rule {
|
|
|
1816
1905
|
carries(...names) { return this.with({ carried: [...(this.spec.carried ?? []), ...names] }); }
|
|
1817
1906
|
// Counts (Machine.counts): `.counts({votes: env => ({below: env.size, body: (x, k) => env.Vote.at(k).eq(x.plus(1))})})`;
|
|
1818
1907
|
// each a map no step writes, at x the number of keys k below the bound where the body holds (or its sum), read by the
|
|
1819
|
-
// flags, the assumption and the step at the request's view, and by a law at the state.
|
|
1908
|
+
// flags, the assumption and the step at the request's view, and by a law at the state. With `base`, a count over two
|
|
1909
|
+
// parameters, read at the key base·a + b (b < base): `body: (a, k, b) => …`.
|
|
1820
1910
|
counts(cs) {
|
|
1821
1911
|
return this.with({ counts: [...(this.spec.counts ?? []), ...Object.entries(cs)] });
|
|
1822
1912
|
}
|
|
@@ -1888,7 +1978,6 @@ export class Rule {
|
|
|
1888
1978
|
return this.with({ leasts: [...(this.spec.leasts ?? []), ...Object.entries(defs)] });
|
|
1889
1979
|
}
|
|
1890
1980
|
keep(f) { return this.with({ keep: f }); }
|
|
1891
|
-
relations(f) { return this.with({ relations: f }); }
|
|
1892
1981
|
// Requests come in nondecreasing `order`; a record whose order plus `after` is at most the request's is dropped
|
|
1893
1982
|
// (the kernel proves it adds nothing to any query).
|
|
1894
1983
|
prune(order, after) { return this.with({ prune: { order, after: after } }); }
|
|
@@ -2158,6 +2247,8 @@ export class Rule {
|
|
|
2158
2247
|
// Maps and lists of a kind in place of their parts' maps (and a list's length), each part's map named by `at`.
|
|
2159
2248
|
composites(out, at, len) {
|
|
2160
2249
|
const init = new Map(this.spec.maps);
|
|
2250
|
+
for (const [n, sorts] of this.spec.rels ?? [])
|
|
2251
|
+
out[n] = new RelRef(at(n), sorts);
|
|
2161
2252
|
for (const [n, k] of this.spec.cells ?? []) {
|
|
2162
2253
|
for (const part of k.vars(n))
|
|
2163
2254
|
delete out[part];
|
|
@@ -2286,8 +2377,8 @@ export class Rule {
|
|
|
2286
2377
|
...(s.maps.length ? { maps: Object.fromEntries(s.maps) } : {}),
|
|
2287
2378
|
...(s.carried?.length ? { inputMaps: s.carried } : {}),
|
|
2288
2379
|
...(s.counts?.length ? { counts: Object.fromEntries(s.counts.map(([n, f]) => {
|
|
2289
|
-
const c = f(env), j = `${n}$x`, key = `${n}$k`, b = c.body(v(j), v(key));
|
|
2290
|
-
return [n, { j, key, below: termOf(c.below), body: b instanceof Cond ? { op: 'if', c: b.c, then: { op: 'const', value: 1 }, else: { op: 'const', value: 0 } } : termOf(b) }];
|
|
2380
|
+
const c = f(env), j = `${n}$x`, key = `${n}$k`, lo = `${n}$y`, b = c.body(v(j), v(key), v(lo));
|
|
2381
|
+
return [n, { j, key, below: termOf(c.below), body: b instanceof Cond ? { op: 'if', c: b.c, then: { op: 'const', value: 1 }, else: { op: 'const', value: 0 } } : termOf(b), ...(c.base ? { lo, base: c.base } : {}) }];
|
|
2291
2382
|
})) } : {}),
|
|
2292
2383
|
step: { ...(Object.keys(flags).length ? { flags } : {}), ...(Object.keys(state).length ? { state } : {}), ...(Object.keys(maps).length ? { maps } : {}) },
|
|
2293
2384
|
...(pre.length ? { pre: pre.length === 1 ? pre[0] : { op: 'and', xs: pre } } : {}),
|
|
@@ -2295,6 +2386,7 @@ export class Rule {
|
|
|
2295
2386
|
...(Object.keys(fns).length ? { fns } : {}),
|
|
2296
2387
|
...(facts.length ? { facts } : {}),
|
|
2297
2388
|
...(Object.keys(leasts).length ? { leasts } : {}),
|
|
2389
|
+
...(s.rels?.length ? { relations: Object.fromEntries(s.rels) } : {}),
|
|
2298
2390
|
};
|
|
2299
2391
|
if (s.record) {
|
|
2300
2392
|
const kinds = new Map(s.inputs);
|
|
@@ -2315,8 +2407,11 @@ export class Rule {
|
|
|
2315
2407
|
}
|
|
2316
2408
|
// (each sum a state variable from 0 the step never sets: sumMachine sets it, exact)
|
|
2317
2409
|
const sums = sumsIn(machineTerms(m), s.sumsRead ?? []);
|
|
2318
|
-
|
|
2410
|
+
const out = withArithmetic(sums ? { ...m, state: { ...m.state, ...Object.fromEntries(Object.keys(sums).map(n => [n, { op: 'const', value: 0 }])) }, sums } : m, [], s.arith ?? []);
|
|
2411
|
+
return s.ghost ? s.ghost(out) : out;
|
|
2319
2412
|
}
|
|
2413
|
+
// The same rule with ghosts its machine gains (the search's, over a law with "there exists" made plain: skolemOf).
|
|
2414
|
+
withGhosts(ghost) { return this.with({ ghost }); }
|
|
2320
2415
|
// --- the builders checked ------------------------------------------------------------------------------------------
|
|
2321
2416
|
// The builders against what they built, on concrete runs: random params and requests by their kinds (`pre` and
|
|
2322
2417
|
// `assume` met), and at every state each law's callback, each step law's, every flag and the step itself run again
|
|
@@ -2838,7 +2933,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2838
2933
|
&& facts.filter(readsParams).every(f => holds(f, params));
|
|
2839
2934
|
const cap = watchWork.n + perTrial * budget.trials;
|
|
2840
2935
|
try {
|
|
2841
|
-
const late = () => budget.until !== undefined && performance.now() > budget.until;
|
|
2936
|
+
const late = () => pastWall() || budget.until !== undefined && performance.now() > budget.until;
|
|
2842
2937
|
for (let trial = 0; trial < budget.trials && watchWork.n <= cap && !late(); trial++) {
|
|
2843
2938
|
// (`mixed`: the trials in turn at bounds 1 to 4, every fourth near)
|
|
2844
2939
|
const bound = budget.mixed ? 1 + trial % 4 : budget.bound, guided = guides, near = budget.mixed && trial % 4 ? undefined : budget.near;
|
|
@@ -2863,6 +2958,10 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2863
2958
|
for (const x of m.inputs)
|
|
2864
2959
|
if (near[x] !== undefined && typeof input[x] === 'number' && rand(2))
|
|
2865
2960
|
input[x] = near[x];
|
|
2961
|
+
if (near && budget.pool?.length)
|
|
2962
|
+
for (const x of m.inputs)
|
|
2963
|
+
if (typeof input[x] === 'number' && !rand(4))
|
|
2964
|
+
input[x] = budget.pool[rand(budget.pool.length)];
|
|
2866
2965
|
for (const g of guided) {
|
|
2867
2966
|
const set = g({ ...params, ...st.scalars }, st, rand, bound);
|
|
2868
2967
|
if (set && typeof input[set[0]] === 'number')
|
|
@@ -2886,7 +2985,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2886
2985
|
// variable of a kind is drawn as its kind draws (33 yes/nos drawn from 0..7 almost never make a lawful state).
|
|
2887
2986
|
const steps1 = stepLaws.filter(sl => (sl.steps ?? 1) === 1), given = withKinds(r, laws);
|
|
2888
2987
|
const wide = Object.keys(m.state).length + m.inputs.length >= 32, lawsHere = wide ? given : [], kinded = wide ? r.kindsOfState() : [];
|
|
2889
|
-
for (let trial = 0; budget.states !== false && !m.history && (steps1.length || lawsHere.length) && trial < budget.trials * 4 && watchWork.n <= cap; trial++) {
|
|
2988
|
+
for (let trial = 0; budget.states !== false && !m.history && (steps1.length || lawsHere.length) && trial < budget.trials * 4 && watchWork.n <= cap && !late(); trial++) {
|
|
2890
2989
|
const params = r.randomParams(rand, bound);
|
|
2891
2990
|
if (m.pre && !evalC(m.pre, params, { scalars: {}, maps: {} }, m) || !factsHold(params))
|
|
2892
2991
|
continue;
|
|
@@ -2937,11 +3036,25 @@ export function proveRule(r, laws, opts = {}) {
|
|
|
2937
3036
|
// (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
|
|
2938
3037
|
// each by its own budget, so the search would never start)
|
|
2939
3038
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined, given = () => (opts.fast ? proveSetFast : proveLaws)(r.machine, withKinds(r, laws));
|
|
2940
|
-
|
|
3039
|
+
// (a law with "there exists" about every key: half of it, as the plain search over its ghosts takes the law too; one
|
|
3040
|
+
// step goal of no_lost_keys' laws as given took 57 s of 60 choosing a witness term)
|
|
3041
|
+
// (an eighth where such a law binds several names: proveSome gives a ghost map to one bound name alone)
|
|
3042
|
+
const share = laws.some(l => (l.some?.length ?? 0) > 1 && l.forall) ? 8 : laws.some(l => l.some?.length && l.forall) ? 2 : 1;
|
|
3043
|
+
// Quantified witness preflight needs a counted allocation: a slow attempt must
|
|
3044
|
+
// not seed different memoized decisions. Other laws keep their existing budget;
|
|
3045
|
+
// inference's query rate is not calibrated for their whole-set preflight.
|
|
3046
|
+
const out = ms === undefined ? given() : withWall(performance.now() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withDeadline(clock() + ms / share, given)));
|
|
2941
3047
|
const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
2942
3048
|
return searched(r, laws, [], v, opts);
|
|
2943
3049
|
}
|
|
2944
3050
|
export function proveSteps(r, laws, stepLaws, opts = {}) {
|
|
3051
|
+
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3052
|
+
// From any state, the caller's budget includes preflight runs and all initial
|
|
3053
|
+
// goals, not a fresh budget per goal. Keep reachable-state search unchanged.
|
|
3054
|
+
return opts.from !== 'any' || ms === undefined ? proveStepsIn(r, laws, stepLaws, opts)
|
|
3055
|
+
: withWall(performance.now() + ms, () => proveStepsIn(r, laws, stepLaws, opts));
|
|
3056
|
+
}
|
|
3057
|
+
function proveStepsIn(r, laws, stepLaws, opts) {
|
|
2945
3058
|
r = r.withSumsOf(laws, stepLaws);
|
|
2946
3059
|
noting(r, laws, stepLaws);
|
|
2947
3060
|
const refuted = refuteByRuns(r, laws, stepLaws);
|
|
@@ -2994,10 +3107,29 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
2994
3107
|
if (deeper?.run)
|
|
2995
3108
|
return refutedVerdict(deeper);
|
|
2996
3109
|
}
|
|
3110
|
+
// (then, for a law of steps or one that divides by an hour or more (a clock's days), near it with its other values,
|
|
3111
|
+
// where it holds some past the small ones: a time the state keeps is one an earlier request gave)
|
|
3112
|
+
const m0 = r.machine, clocked = stepLaws.length > 0 || [...divisorsIn(laws.map(l => l.holds))].some(k => k >= 3600);
|
|
3113
|
+
const pool = clocked ? [...new Set(Object.entries(v.witness ?? {}).filter(([k, x]) => !m0.inputs.includes(k) && !m0.params.includes(k) && x > deeperBudget.bound).map(([, x]) => x))] : [];
|
|
3114
|
+
if (pool.length) {
|
|
3115
|
+
const deeper = refuteByRuns(r, laws, stepLaws, { ...deeperBudget, trials: 300, seed: 43, states: false, mixed: true, near: v.witness, pool, until: runsUntil });
|
|
3116
|
+
if (deeper?.run)
|
|
3117
|
+
return refutedVerdict(deeper);
|
|
3118
|
+
}
|
|
2997
3119
|
const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
|
|
2998
3120
|
// (the search's end on the wall too: kernel/prove.ts's withWall, past which every goal is unknown)
|
|
2999
3121
|
return withWall(performance.now() + Math.max(0, until - clock()), () => searchedUntil(r, laws, stepLaws, v, opts, until));
|
|
3000
3122
|
}
|
|
3123
|
+
// Two machines alike up to the names of the keys their quantified flags and writes at every key bind (the rule builds
|
|
3124
|
+
// fresh ones each time it is read): each bound name by its place of first binding.
|
|
3125
|
+
const sameMachine = (a, b) => {
|
|
3126
|
+
const canon = (m) => {
|
|
3127
|
+
const t = JSON.stringify(m), bs = [...new Set([...t.matchAll(/"(?:each|key)":"([^"]+)"|"keys":\[([^\]]*)\]/g)].flatMap(x => (x[1] ? [x[1]] : [...x[2].matchAll(/"([^"]+)"/g)].map(y => y[1]))))];
|
|
3128
|
+
const at = new Map(bs.map((x, i) => [x, `$b${i}`]));
|
|
3129
|
+
return t.replace(/"(name|each|key)":"([^"]+)"/g, (all, f, x) => (at.has(x) ? `"${f}":"${at.get(x)}"` : all)).replace(/"keys":\[([^\]]*)\]/g, (_all, xs) => `"keys":[${xs.replace(/"([^"]+)"/g, (a2, x) => (at.has(x) ? `"${at.get(x)}"` : a2))}]`);
|
|
3130
|
+
};
|
|
3131
|
+
return canon(a) === canon(b);
|
|
3132
|
+
};
|
|
3001
3133
|
function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
3002
3134
|
const any = opts.from === 'any';
|
|
3003
3135
|
// Bounded runs (core/bmc.ts): a law broken k steps from the start, a model of the kernel's k-step goal, the run taken
|
|
@@ -3049,7 +3181,8 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3049
3181
|
const fm = rule.machine, share = (until - clock() - tail) / 10;
|
|
3050
3182
|
fresh = withDeadline(clock() + share, () => freshLaws(fm, rule.kindLaws(), { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) }, { ms: share }));
|
|
3051
3183
|
if (fresh.length) {
|
|
3052
|
-
|
|
3184
|
+
// (counted, as the laws' own search: the same verdict on any machine)
|
|
3185
|
+
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given))), true);
|
|
3053
3186
|
if (out.proven && out.checked)
|
|
3054
3187
|
return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
|
|
3055
3188
|
}
|
|
@@ -3074,17 +3207,100 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3074
3207
|
}
|
|
3075
3208
|
// (the search's own wall ends where the tail begins: the last bounded runs keep it)
|
|
3076
3209
|
const tailAt = () => performance.now() + Math.max(0, until - tail - clock());
|
|
3077
|
-
|
|
3210
|
+
// (a law about every key with "there exists": the search over its plain form, the value at its ghost map's cell, the
|
|
3211
|
+
// ghosts' own laws beside it, on the rule with the ghosts (exists.ts's skolemOf), its verdict `back`'s; no join, whose
|
|
3212
|
+
// convex forms can't state a cell read at a key a ghost holds: the engine alone (the join's first whole-set query on
|
|
3213
|
+
// db_ae's plain laws took 234 counted s, past the budget, before the engine)
|
|
3214
|
+
const sk = !stepLaws.length && laws.some(l => l.some?.length && l.forall) ? skolemOf(rule.machine, laws) : undefined;
|
|
3215
|
+
const target = sk ? rule.withGhosts(sk.ghost) : rule, sought = sk?.laws ?? laws;
|
|
3216
|
+
// (the set the search proved, as it proved it, over the rule with the ghosts (its goals settled again where they stand),
|
|
3217
|
+
// the ghosts checked to be the original's (kernel.ts's ghostedOk): each law with "there exists" holds, its value at its
|
|
3218
|
+
// ghost map's cell (GhostMap.lean's forall_some_of_ghostmap); else proveSome's own proof of the laws as stated)
|
|
3219
|
+
// (the trees of the search's verdict are the ghosted machine's: no part of the ∃ verdict)
|
|
3220
|
+
const back = (over, found, fast = true) => {
|
|
3221
|
+
if (!sk)
|
|
3222
|
+
return {};
|
|
3223
|
+
// (a machine with sums or a history takes no ghost map (GhostMap.lean's SGhostedM is over SMachine): proveSome there)
|
|
3224
|
+
const ls = [...fresh.map(f => f.law), ...sought, ...found.map(f => f.law)], pm = over.withSumsOf(ls).machine;
|
|
3225
|
+
const plain = over === target && !pm.history && !Object.keys(pm.sums ?? {}).length ? proveRule(over, ls, { search: false, fast }) : undefined;
|
|
3226
|
+
// (the kernel's ∃ reading, GhostMap.lean's forall_some_of_ghostsubst: the plain laws proven of the original with all
|
|
3227
|
+
// the ghosts, each ∃ law's body with its witness term in place, the very law object proven (its keys with it: terra's
|
|
3228
|
+
// review, a law alike in name and body but about no key would prove less))
|
|
3229
|
+
const G = { orig: rule.machine, vars: {}, maps: sk.maps };
|
|
3230
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3231
|
+
console.error(`exists: back: plain ${plain ? `${plain.proven} ${plain.checked}` : 'none'}, machine ${sameMachine(over.machine, ghostedMachine(G))}`);
|
|
3232
|
+
if (plain?.proven && plain.checked && sameMachine(over.machine, ghostedMachine(G))
|
|
3233
|
+
&& laws.filter(l => l.some?.length).every(l => { const q = sk.plains[l.name]; return !!q && ls.includes(q.plain) && someOfGhostsOk(G, l, q.plain, q.sub); }))
|
|
3234
|
+
return { proven: true, checked: true, witnesses: sk.witnesses };
|
|
3235
|
+
// (proveSome over the original: the found laws that read no ghost map)
|
|
3236
|
+
const own = found.filter(f => Object.keys(sk.maps).every(mp => !JSON.stringify(f.law.holds).includes(`"map":${JSON.stringify(mp)}`)));
|
|
3237
|
+
const out = proveSome(rule.machine, [...withKinds(rule, laws), ...fresh.map(f => f.law), ...own.map(f => f.law)], { mapMs: Math.max(5_000, (until - clock()) / 2) });
|
|
3238
|
+
return { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
3239
|
+
};
|
|
3240
|
+
// (the plain law's candidate supports, exists.ts's ghostSupports: Houdini within half of what is left, each with the
|
|
3241
|
+
// rest assumed, the failing dropped, until none fails; then the set through `back`, the ∃ verdict as the search's)
|
|
3242
|
+
if (sk?.cands.length) {
|
|
3243
|
+
const tm = target.machine, hUntil = clock() + (until - clock()) / 2;
|
|
3244
|
+
const native = Object.values(sk.maps).some(g => !('each' in g.write) && g.write.key.op === 'tup');
|
|
3245
|
+
let keep = [...sk.cands];
|
|
3246
|
+
for (let round = 0; round < 8 && clock() < hUntil; round++) {
|
|
3247
|
+
const ls = withKinds(target, [...fresh.map(f => f.law), ...sought, ...keep]);
|
|
3248
|
+
const helpers = withKinds(target, [...fresh.map(f => f.law), ...keep]);
|
|
3249
|
+
const drop = keep.filter(c => {
|
|
3250
|
+
if (clock() >= hUntil)
|
|
3251
|
+
return true;
|
|
3252
|
+
const budget = Math.min(3_000, hUntil - clock());
|
|
3253
|
+
// Keep support selection deterministic on slow VMs, including native
|
|
3254
|
+
// tuple supports. Nested counted searches retain their existing clock.
|
|
3255
|
+
return counted(fullRate, () => {
|
|
3256
|
+
const end = clock() + budget;
|
|
3257
|
+
if (!native)
|
|
3258
|
+
return !withDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c))).proven;
|
|
3259
|
+
// Try local provenance before instantiating every witness. All three
|
|
3260
|
+
// attempts share the same existing support-query allocation.
|
|
3261
|
+
if (round === 0 && withDeadline(Math.min(end, clock() + 500), () => proveSetFast(tm, [c])).proven)
|
|
3262
|
+
return false;
|
|
3263
|
+
const local = witnessSupport(tm, helpers, c, Object.keys(sk.maps));
|
|
3264
|
+
if (withDeadline(Math.min(end, clock() + 1_000), () => proveLaw(tm, local, local.indexOf(c))).proven)
|
|
3265
|
+
return false;
|
|
3266
|
+
return !withDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c))).proven;
|
|
3267
|
+
}, true);
|
|
3268
|
+
});
|
|
3269
|
+
if (clock() >= hUntil)
|
|
3270
|
+
break;
|
|
3271
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3272
|
+
console.error(`exists: ghost supports round ${round}: ${keep.length} kept, ${drop.length} dropped: ${keep.map(c => c.name).join('; ').slice(0, 1500)}`);
|
|
3273
|
+
if (!drop.length) {
|
|
3274
|
+
for (const l of native ? sought : []) {
|
|
3275
|
+
const local = witnessSupport(tm, ls, l);
|
|
3276
|
+
if (local.length < ls.length)
|
|
3277
|
+
withDeadline(Math.min(hUntil, clock() + 3_000), () => proveLaw(tm, local, local.indexOf(l)));
|
|
3278
|
+
}
|
|
3279
|
+
const b = back(target, keep.map(law => ({ law })), native);
|
|
3280
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3281
|
+
console.error(`exists: ghost supports set: ${b.proven ? 'proven' : `${b.goal} ${b.stuck} ${b.why ?? ''}`}`);
|
|
3282
|
+
if (b.proven && b.checked) {
|
|
3283
|
+
const found = keep.map(law => ({ law, text: law.name }));
|
|
3284
|
+
return { ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3285
|
+
}
|
|
3286
|
+
break;
|
|
3287
|
+
}
|
|
3288
|
+
keep = keep.filter(c => !drop.includes(c));
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
const inf = withWall(tailAt(), () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ms, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) }));
|
|
3078
3292
|
if (!(inf.proven && inf.checked)) {
|
|
3079
3293
|
// The sum of each map the step writes (withMapSums): the search again over the rule with them, within half of what
|
|
3080
3294
|
// is left (at most 20 s), where a law of cells against a total needs one (no ERC20 balance past the supply).
|
|
3081
|
-
const summed =
|
|
3295
|
+
const summed = target.withMapSums();
|
|
3082
3296
|
if (summed && until - clock() - tail > 1000) {
|
|
3083
|
-
const inf2 = withWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...
|
|
3297
|
+
const inf2 = withWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, { ms: Math.min(20_000, (until - clock() - tail) / 2) }));
|
|
3084
3298
|
if (inf2.proven && inf2.checked) {
|
|
3085
3299
|
const { found, stats: _s2, ...verdict } = inf2;
|
|
3086
3300
|
void _s2;
|
|
3087
|
-
|
|
3301
|
+
const b = back(summed, found);
|
|
3302
|
+
if (!sk || (b.proven && b.checked))
|
|
3303
|
+
return { ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3088
3304
|
}
|
|
3089
3305
|
}
|
|
3090
3306
|
// (a step law's ghost: at most 10 s of it, as its goals cost more than the laws')
|
|
@@ -3095,7 +3311,10 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3095
3311
|
}
|
|
3096
3312
|
const { found, stats: _stats, ...verdict } = inf;
|
|
3097
3313
|
void _stats;
|
|
3098
|
-
|
|
3314
|
+
const b = back(target, found);
|
|
3315
|
+
if (sk && !(b.proven && b.checked))
|
|
3316
|
+
return { ...v, ...b, why: [v.why, 'the set found over the ghost maps is not proven with the laws as stated'].filter(Boolean).join('; ') };
|
|
3317
|
+
return { ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3099
3318
|
}
|
|
3100
3319
|
// A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
|
|
3101
3320
|
// then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// use (a semaphore never released past what was taken) as a law to prove of it.
|
|
19
19
|
import ts from 'typescript';
|
|
20
20
|
import * as dsl from "./dsl.js";
|
|
21
|
-
import { interpret,
|
|
21
|
+
import { interpret, seeded } from "./machine.js";
|
|
22
22
|
import { allowed } from "./watch.js";
|
|
23
23
|
import { bare as strip, memberName, refuse, text } from "./extract-read.js";
|
|
24
24
|
import { extractEffect } from "./effect.js";
|
|
@@ -500,7 +500,7 @@ export async function primitiveConforms(spec, effect, opts = {}) {
|
|
|
500
500
|
const E = effect, v4 = 'TxRef' in E, x = opts.x ?? primitiveRule(spec, E, opts.file ? { file: opts.file } : {});
|
|
501
501
|
if (!x.ok || !x.rule)
|
|
502
502
|
return { checked: 0, waited: 0, blocked: 0, interrupted: 0, failure: `the rule: ${x.refusals.map(f => f.what).join('; ')}` };
|
|
503
|
-
const r = x.rule, g = r.compiled(), interp = interpret(r.machine), rand =
|
|
503
|
+
const r = x.rule, g = r.compiled(), interp = interpret(r.machine), rand = seeded(opts.seed ?? 1);
|
|
504
504
|
const inputs = r.parts.inputs.map(([n]) => n).filter(n => n !== 'method');
|
|
505
505
|
const ops = spec.kind === 'queue' ? QUEUE_OPS(v4) : SEM_OPS;
|
|
506
506
|
const tick = () => new Promise(res => setTimeout(res, 0));
|
package/dist/core/effect.d.ts
CHANGED
|
@@ -48,10 +48,7 @@ export declare function withLemmas(x: Extraction, opts?: {
|
|
|
48
48
|
proven: string[];
|
|
49
49
|
unproven: string[];
|
|
50
50
|
};
|
|
51
|
-
export
|
|
52
|
-
params: Record<string, number>;
|
|
53
|
-
trace: Record<string, unknown>[];
|
|
54
|
-
}): string[];
|
|
51
|
+
export { fiberRun } from './fiber-run.js';
|
|
55
52
|
export declare function fromSchedule(source: string, opts: {
|
|
56
53
|
effect: Mod;
|
|
57
54
|
params?: string[];
|
package/dist/core/effect.js
CHANGED
|
@@ -910,21 +910,7 @@ function fibered(code, file, entry, E, opts) {
|
|
|
910
910
|
}
|
|
911
911
|
// A run of every fiber's rule as what each fiber does: starts a call (with its arguments), or takes the next step of the
|
|
912
912
|
// call it is in.
|
|
913
|
-
export
|
|
914
|
-
const fibers = x.fibers ?? [], r = x.rule;
|
|
915
|
-
const go = interpret(r.machine), ps = r.encodeParams(run.params), method = new Map(r.parts.inputs).get('method');
|
|
916
|
-
let st = go.init(ps);
|
|
917
|
-
return run.trace.map(q => {
|
|
918
|
-
const f = Number(q.fiber), pc = st.maps.__gdp_pc?.get(f) ?? 0, m = method ? method.decode('method', q) : x.model?.events[0]?.call ?? 'step';
|
|
919
|
-
st = go.step(ps, st, q);
|
|
920
|
-
if (pc === 0) {
|
|
921
|
-
const sp = fibers.find(s2 => s2.name === m), args = (x.names ?? []).filter(n => n.role === 'input' && n.method === m && n.rule in q).map(n => `${n.code.split('.').pop()} = ${String(q[n.rule])}`);
|
|
922
|
-
return `fiber ${f}: ${m}(${args.join(', ')})${sp ? `, its step 1 of ${sp.steps}` : ''}`;
|
|
923
|
-
}
|
|
924
|
-
const sp = fibers.find(s2 => pc > s2.base && pc <= s2.base + s2.steps);
|
|
925
|
-
return `fiber ${f}: ${sp.name}, its step ${pc - sp.base} of ${sp.steps}`;
|
|
926
|
-
});
|
|
927
|
-
}
|
|
913
|
+
export { fiberRun } from "./fiber-run.js";
|
|
928
914
|
const isSchedule = (s, e) => {
|
|
929
915
|
e = strip(e);
|
|
930
916
|
if (ts.isCallExpression(e) && ts.isPropertyAccessExpression(e.expression) && memberName(e.expression.name) === 'pipe' && !apiOf(s, e.expression))
|
package/dist/core/ex/reader.exs
CHANGED
|
@@ -22,6 +22,7 @@ defmodule GdpReader do
|
|
|
22
22
|
base = Path.basename(file)
|
|
23
23
|
Process.put(:base, base)
|
|
24
24
|
mods = modules(ast, [])
|
|
25
|
+
Process.put(:mods, mods)
|
|
25
26
|
# (no name: the file's one module, or its one GenServer or Agent: the entry inferred)
|
|
26
27
|
name = req["module"] || (case Enum.filter(mods, fn {_, b} -> length(mods) == 1 or Enum.any?(b, &match?({:use, _, [{:__aliases__, _, [k]} | _]} when k in [:GenServer, :Agent], &1)) end) do [{n, _}] -> n; _ -> "" end)
|
|
27
28
|
case Enum.find(mods, fn {n, _} -> n == name end) || Enum.find(mods, fn {n, _} -> String.ends_with?(n, "." <> name) end) do
|
|
@@ -105,6 +106,8 @@ defmodule GdpReader do
|
|
|
105
106
|
_ -> {struct_fields(kw), struct_init(kw)}
|
|
106
107
|
end
|
|
107
108
|
end
|
|
109
|
+
# (a plain module's state is its struct: with no defstruct, none the check can make)
|
|
110
|
+
defp state_of(:pure, nil, _), do: {[], fn q -> fn_of("#{q}.__init__", "new", [], [%{"s" => "no", "p" => "#{Process.get(:base)}:1:1", "why" => "#{q}: a plain module with no struct (defstruct) for its state"}]) end}
|
|
108
111
|
defp state_of(_, kw, _), do: {struct_fields(kw), struct_init(kw)}
|
|
109
112
|
defp struct_fields(nil), do: []
|
|
110
113
|
defp struct_fields(kw), do: Enum.map(kw, fn {k, v} -> {k, v}; k -> {k, nil} end)
|
|
@@ -310,7 +313,7 @@ defmodule GdpReader do
|
|
|
310
313
|
def expr({:-, m, [a]}), do: %{"e" => "neg", "x" => expr(a), "p" => p(m)}
|
|
311
314
|
def expr({:/, m, _} = x), do: %{"e" => "no", "why" => "#{text(x)}: a float division (the subset reads trunc(a / k), div and rem)", "p" => p(m)}
|
|
312
315
|
def expr({:if, m, [c, kw]}), do: %{"e" => "ite", "c" => expr(c), "a" => expr(single(kw[:do], m)), "b" => expr(single(kw[:else], m)), "p" => p(m)}
|
|
313
|
-
def expr({:%{}, m, [{:|, _, [s, kv]}]}), do: upd(expr(s), kv, m)
|
|
316
|
+
def expr({:%{}, m, [{:|, _, [s, kv]}]}), do: upd(expr(s), kv, m) |> Map.put("strict", true)
|
|
314
317
|
def expr({:%, m, [_, {:%{}, _, kv}]}), do: struct_new(kv, m)
|
|
315
318
|
def expr({:%{}, m, _} = x), do: %{"e" => "no", "why" => "#{text(x)}: a map literal (a state is updated: %{s | f: v})", "p" => p(m)}
|
|
316
319
|
def expr({{:., m, [v, f]}, km, []}) when is_atom(f) and not is_tuple(elem(v, 0)) and is_list(km), do: (if km[:no_parens], do: get(expr(v), f, m), else: call_expr(v, f, [], m))
|
|
@@ -345,12 +348,25 @@ defmodule GdpReader do
|
|
|
345
348
|
key == [:Map] and f == :put and match?([_, k, _] when is_atom(k), args) -> upd(expr(Enum.at(args, 0)), [{Enum.at(args, 1), Enum.at(args, 2)}], m)
|
|
346
349
|
key == [:Map] and f == :merge and match?([_, {:%{}, _, _}], args) -> upd(expr(Enum.at(args, 0)), elem(Enum.at(args, 1), 2), m)
|
|
347
350
|
key == [:Map] and f == :get and match?([_, k] when is_atom(k), args) -> get(expr(Enum.at(args, 0)), Enum.at(args, 1), m)
|
|
351
|
+
# (a module of the file, all of whose functions the reader sees, that defines no f of this arity: an UndefinedFunctionError)
|
|
352
|
+
is_list(key) and undefined?(Enum.map_join(key, ".", &to_string/1), f, length(args)) -> %{"e" => "no", "why" => "#{text(x)}: #{text(mod)} defines no #{f}/#{length(args)} (an UndefinedFunctionError where it runs)", "raises" => true, "p" => p(m)}
|
|
348
353
|
# (another module's code: at the boundary where it is inferred; its arguments are values, which it can't change)
|
|
349
354
|
is_atom(mod) or is_tuple(mod) and elem(mod, 0) == :__aliases__ -> %{"e" => "no", "why" => "#{text(x)}: another module's code", "p" => p(m), "ext" => "#{text(mod)}.#{f}", "names" => [], "patch" => %{"mod" => text(mod), "path" => [to_string(f)]}}
|
|
350
355
|
true -> %{"e" => "no", "why" => "#{text(x)}: a call outside the subset", "p" => p(m)}
|
|
351
356
|
end
|
|
352
357
|
end
|
|
353
358
|
|
|
359
|
+
defp undefined?(name, f, n) do
|
|
360
|
+
case List.keyfind(Process.get(:mods) || [], name, 0) do
|
|
361
|
+
{_, body} ->
|
|
362
|
+
# (only a module of plain definitions: use, defdelegate, a macro may define functions the reader doesn't see)
|
|
363
|
+
closed = Enum.all?(body, &match?({k, _, _} when k in [:def, :defp, :@, :defstruct, :defmodule, :alias, :require, :import, :defmacrop], &1))
|
|
364
|
+
arities = for {:def, _, [head | _]} <- body, {^f, args, _} <- [head_of(head)], do: {Enum.count(args, &(not match?({:\\, _, _}, &1))), length(args)}
|
|
365
|
+
closed and f not in [:module_info, :__info__, :__struct__] and not Enum.any?(arities, fn {lo, hi} -> n in lo..hi//1 end)
|
|
366
|
+
nil -> false
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
354
370
|
# --- types, inferred from the defaults and what the module puts in each field --------------------------------------
|
|
355
371
|
defp infer(fields, body) do
|
|
356
372
|
puts = collect(body, %{})
|