gdp-wired 0.47.0 → 0.48.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 +15 -4
- package/dist/core/carry.d.ts +15 -0
- package/dist/core/carry.js +651 -0
- package/dist/core/cli.d.ts +3 -1
- package/dist/core/cli.js +28 -8
- package/dist/core/count-cases.d.ts +24 -0
- package/dist/core/count-cases.js +320 -0
- package/dist/core/count-cert-grow.d.ts +4 -0
- package/dist/core/count-cert-grow.js +37 -0
- package/dist/core/count-cert-transport.d.ts +3 -0
- package/dist/core/count-cert-transport.js +58 -0
- package/dist/core/count-completion.d.ts +9 -0
- package/dist/core/count-completion.js +27 -0
- package/dist/core/count-cubes.d.ts +8 -0
- package/dist/core/count-cubes.js +69 -0
- package/dist/core/count-demand.d.ts +37 -0
- package/dist/core/count-demand.js +361 -0
- package/dist/core/count-facts.d.ts +52 -0
- package/dist/core/count-facts.js +247 -0
- package/dist/core/count-focus-proof.d.ts +8 -0
- package/dist/core/count-focus-proof.js +140 -0
- package/dist/core/count-focused.d.ts +22 -0
- package/dist/core/count-focused.js +676 -0
- package/dist/core/count-ranges.d.ts +5 -0
- package/dist/core/count-ranges.js +65 -0
- package/dist/core/count-recovery/action-guard.d.ts +5 -0
- package/dist/core/count-recovery/action-guard.js +51 -0
- package/dist/core/count-recovery/boolean-core.d.ts +16 -0
- package/dist/core/count-recovery/boolean-core.js +258 -0
- package/dist/core/count-recovery/carried-case.d.ts +2 -0
- package/dist/core/count-recovery/carried-case.js +24 -0
- package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
- package/dist/core/count-recovery/conditional-check-cache.js +130 -0
- package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
- package/dist/core/count-recovery/conditional-cuts.js +318 -0
- package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
- package/dist/core/count-recovery/conditional-proof.js +306 -0
- package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
- package/dist/core/count-recovery/derivability-closure.js +533 -0
- package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
- package/dist/core/count-recovery/empty-count-source.js +40 -0
- package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
- package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
- package/dist/core/count-recovery/field-case.d.ts +5 -0
- package/dist/core/count-recovery/field-case.js +89 -0
- package/dist/core/count-recovery/field-demand.d.ts +46 -0
- package/dist/core/count-recovery/field-demand.js +47 -0
- package/dist/core/count-recovery/field-only.d.ts +3 -0
- package/dist/core/count-recovery/field-only.js +18 -0
- package/dist/core/count-recovery/fold-path.d.ts +6 -0
- package/dist/core/count-recovery/fold-path.js +35 -0
- package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
- package/dist/core/count-recovery/frame-lemmas.js +120 -0
- package/dist/core/count-recovery/guard-cases.d.ts +12 -0
- package/dist/core/count-recovery/guard-cases.js +138 -0
- package/dist/core/count-recovery/key-closure.d.ts +14 -0
- package/dist/core/count-recovery/key-closure.js +62 -0
- package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
- package/dist/core/count-recovery/leaf-allowance.js +7 -0
- package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
- package/dist/core/count-recovery/lift-count-proxies.js +175 -0
- package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
- package/dist/core/count-recovery/live-dependencies.js +76 -0
- package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
- package/dist/core/count-recovery/member-inclusions.js +168 -0
- package/dist/core/count-recovery/member-premises.d.ts +29 -0
- package/dist/core/count-recovery/member-premises.js +114 -0
- package/dist/core/count-recovery/natural-cases.d.ts +6 -0
- package/dist/core/count-recovery/natural-cases.js +59 -0
- package/dist/core/count-recovery/ops.d.ts +6 -0
- package/dist/core/count-recovery/ops.js +8 -0
- package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
- package/dist/core/count-recovery/pre-state-source.js +18 -0
- package/dist/core/count-recovery/rebase-path.d.ts +9 -0
- package/dist/core/count-recovery/rebase-path.js +70 -0
- package/dist/core/count-recovery/rename-proof.d.ts +2 -0
- package/dist/core/count-recovery/rename-proof.js +102 -0
- package/dist/core/count-recovery/row-cases.d.ts +16 -0
- package/dist/core/count-recovery/row-cases.js +291 -0
- package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
- package/dist/core/count-recovery/scalar-guards.js +291 -0
- package/dist/core/count-recovery/source-memo.d.ts +12 -0
- package/dist/core/count-recovery/source-memo.js +67 -0
- package/dist/core/count-select.d.ts +16 -0
- package/dist/core/count-select.js +24 -0
- package/dist/core/count-support.d.ts +598 -0
- package/dist/core/count-support.js +2080 -0
- package/dist/core/count-unions.d.ts +2 -0
- package/dist/core/count-unions.js +139 -0
- package/dist/core/count-witness-flags.d.ts +9 -0
- package/dist/core/count-witness-flags.js +37 -0
- package/dist/core/count-write-frames.d.ts +12 -0
- package/dist/core/count-write-frames.js +206 -0
- package/dist/core/counts.d.ts +20 -2
- package/dist/core/counts.js +807 -156
- package/dist/core/dsl.d.ts +50 -6
- package/dist/core/dsl.js +307 -65
- package/dist/core/effect.js +8 -1
- package/dist/core/exists.d.ts +1 -1
- package/dist/core/exists.js +80 -15
- package/dist/core/extract-check.d.ts +7 -1
- package/dist/core/extract-check.js +130 -13
- package/dist/core/extract-read.d.ts +22 -8
- package/dist/core/extract-read.js +29 -11
- package/dist/core/extract-shapes.js +122 -41
- package/dist/core/extract-standalone.js +53 -9
- package/dist/core/extract.js +9 -3
- package/dist/core/field-laws.d.ts +2 -0
- package/dist/core/field-laws.js +100 -0
- package/dist/core/finite-frontiers.d.ts +5 -0
- package/dist/core/finite-frontiers.js +116 -0
- package/dist/core/finite-houdini.d.ts +52 -0
- package/dist/core/finite-houdini.js +460 -0
- package/dist/core/finite-model.d.ts +13 -0
- package/dist/core/finite-model.js +68 -0
- package/dist/core/finite-tiny.d.ts +72 -0
- package/dist/core/finite-tiny.js +1052 -0
- package/dist/core/infer.d.ts +1 -1
- package/dist/core/infer.js +32 -9
- package/dist/core/laws.d.ts +2 -1
- package/dist/core/laws.js +47 -14
- package/dist/core/lemma-cuts.d.ts +38 -0
- package/dist/core/lemma-cuts.js +365 -0
- package/dist/core/machine.d.ts +39 -2
- package/dist/core/machine.js +240 -35
- package/dist/core/mutate.d.ts +55 -0
- package/dist/core/mutate.js +210 -0
- package/dist/core/native-domain.d.ts +6 -0
- package/dist/core/native-domain.js +114 -0
- package/dist/core/native-law.d.ts +3 -0
- package/dist/core/native-law.js +174 -0
- package/dist/core/quorum-laws.d.ts +5 -0
- package/dist/core/quorum-laws.js +239 -0
- package/dist/core/relational.js +10 -2
- package/dist/core/relevance.d.ts +4 -0
- package/dist/core/relevance.js +79 -0
- package/dist/core/runtime-wall.d.ts +3 -0
- package/dist/core/runtime-wall.js +4 -0
- package/dist/core/sample-step.d.ts +16 -0
- package/dist/core/sample-step.js +28 -0
- package/dist/core/source-check.d.ts +44 -0
- package/dist/core/source-check.js +126 -0
- package/dist/core/source-diagnostic.d.ts +1 -0
- package/dist/core/source-diagnostic.js +34 -0
- package/dist/core/support-budget.d.ts +2 -0
- package/dist/core/support-budget.js +6 -0
- package/dist/core/system.js +2 -0
- package/dist/core/wall.d.ts +6 -0
- package/dist/core/wall.js +23 -0
- package/dist/core/watch.js +4 -0
- package/dist/kernel/cdcl.d.ts +4 -0
- package/dist/kernel/cdcl.js +20 -5
- package/dist/kernel/kernel.d.ts +10 -0
- package/dist/kernel/kernel.js +56 -3
- package/dist/kernel/model-sequence.d.ts +2 -2
- package/dist/kernel/model-sequence.js +4 -3
- package/dist/kernel/model-values.d.ts +2 -0
- package/dist/kernel/model-values.js +60 -0
- package/dist/kernel/prove.d.ts +10 -0
- package/dist/kernel/prove.js +56 -8
- package/dist/kernel/prover-rows.d.ts +29 -0
- package/dist/kernel/prover-rows.js +114 -0
- package/dist/lean-kernel/emit.d.ts +39 -2
- package/dist/lean-kernel/emit.js +136 -24
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +13 -5
- package/dist/lean-kernel/library.js +4 -0
- package/dist/lean-kernel/qalpha.d.ts +7 -0
- package/dist/lean-kernel/qalpha.js +40 -0
- package/package.json +5 -1
package/dist/core/infer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Law, type Machine, type Request, type State } from './machine.js';
|
|
2
|
-
import { type StepLaw, type Verdict, proveRule } from './dsl.js';
|
|
2
|
+
import { type StepLaw, type Verdict, type proveRule } from './dsl.js';
|
|
3
3
|
type AnyRule = Parameters<typeof proveRule>[0];
|
|
4
4
|
type Env = Record<string, number>;
|
|
5
5
|
export type InferOptions = {
|
package/dist/core/infer.js
CHANGED
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
import { quietly } from "./cyclic.js";
|
|
35
35
|
import { bitIntersection, bitIntersects } from "./bitsets.js";
|
|
36
36
|
import { samplePredicates, sampleStateText } from "./sample-cache.js";
|
|
37
|
+
import { sampleStep } from "./sample-step.js";
|
|
37
38
|
import { all, any, atMost, carriedView, compileC, compileE, cpair, fastStep, divisorsIn, evalC, evalE, get, interpret, machineTerms, fnValue, modName, n, not, partsOf as tupleOf, plus, same, seeded, times, walk, withArithmetic, x } from "./machine.js";
|
|
38
|
-
import { bool,
|
|
39
|
+
import { bool, refuteModelByRuns, verdictOf } from "./dsl.js";
|
|
39
40
|
import { allowed, keysOf, linKey, watch } from "./watch.js";
|
|
40
41
|
import { clock, counted, fullWork, decideLaw, decideNote, machineKey, memoHits, withStrict, fullRate, grow, keyValue, lawInstances, proveLaw, proveLaws, proveSetFast, proveStepLaws, stepLawInstances, usedHyps, withDeadline, withModels, withTrees, withWall, withWork } from "../kernel/prove.js";
|
|
41
42
|
import { assumed, eachParts, obligations, plainOf, stepLawObligations, substC, tuple, tupleParts } from "../kernel/kernel.js";
|
|
@@ -1077,17 +1078,26 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
1077
1078
|
const prove = (ls, fast = false) => {
|
|
1078
1079
|
proofs++;
|
|
1079
1080
|
const { r: searchRule, m: mm } = forLaws(ls);
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1081
|
+
// Inference proves candidates about the mathematical model. Calling the public
|
|
1082
|
+
// source finalizer here rejects its invented (unbound) support laws before the
|
|
1083
|
+
// outer source proof can validate the user's laws. Keep kind/sum normalization,
|
|
1084
|
+
// and let the outer proveRule/proveSteps call enforce source validation once.
|
|
1085
|
+
const normalized = searchRule?.withSumsOf(ls, stepLaws);
|
|
1086
|
+
const model = normalized?.machine ?? mm;
|
|
1087
|
+
const given = normalized ? [...normalized.kindLaws().filter(k => !ls.some(l => l.name === k.name)), ...ls] : ls;
|
|
1088
|
+
const out = stepLaws.length ? proveStepLaws(model, given, stepLaws) : (fast ? proveSetFast : proveLaws)(model, given);
|
|
1083
1089
|
return verdictOf(out);
|
|
1084
1090
|
};
|
|
1085
1091
|
const stats = (samples, candidates, alive) => ({ samples, candidates, alive, proofs, ms: Math.round(performance.now() - t0), stopped: stop() });
|
|
1086
|
-
|
|
1092
|
+
// The old public prover's first pass also sampled reachable counterexamples.
|
|
1093
|
+
// Keep that negative model evidence without invoking a source finalizer.
|
|
1094
|
+
const refuted = !opts.first && !opts.cubes && rule ? refuteModelByRuns(rule, laws, stepLaws) : undefined;
|
|
1095
|
+
const first = opts.first ?? (refuted?.run ? { proven: false, checked: false, stuck: 'sat', ...refuted }
|
|
1096
|
+
: opts.cubes ? { proven: false, checked: false } : prove(laws));
|
|
1087
1097
|
if ((first.proven && first.checked) || first.run)
|
|
1088
1098
|
return { ...first, found: [], stats: stats(0, 0, 0) };
|
|
1089
1099
|
// --- runs ------------------------------------------------------------------------------------------------------------
|
|
1090
|
-
const run = interpret(m), rand = seeded(17), kinds = rule ? rule.kindsOfState() : [];
|
|
1100
|
+
const run = interpret(m), stepSample = sampleStep(m, run), rand = seeded(17), kinds = rule ? rule.kindsOfState() : [];
|
|
1091
1101
|
const given = rule ? [...rule.kindLaws().filter(k => !laws.some(l => l.name === k.name)), ...laws] : laws;
|
|
1092
1102
|
const randomParams = (bound, r = rand) => (rule ? rule.randomParams(r, bound) : Object.fromEntries(m.params.map(p => [p, r(bound + 1)])));
|
|
1093
1103
|
const randomInput = (params, bound, r = rand) => (rule ? rule.randomInput(r, bound, params)
|
|
@@ -1113,6 +1123,18 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
1113
1123
|
for (const st of opts.seen ?? [])
|
|
1114
1124
|
if (!m.params.length)
|
|
1115
1125
|
keep({ params: {}, st });
|
|
1126
|
+
// Initial scalar bounds come from exploration, not the later small-instance
|
|
1127
|
+
// cube filter. A supplied finite row set cannot replace that exploration for
|
|
1128
|
+
// counters or stored numeric inputs. Boolean control has no missing numeric
|
|
1129
|
+
// levels; keep the original walk for every other scalar transition.
|
|
1130
|
+
const boolControl = (e, key) => e.op === 'const' ? e.value === 0 || e.value === 1
|
|
1131
|
+
: e.op === 'var' ? e.name === key : e.op === 'if' && boolControl(e.then, key) && boolControl(e.else, key);
|
|
1132
|
+
const finiteControl = Object.entries(m.state).every(([key, initial]) => initial.op === 'const'
|
|
1133
|
+
&& (initial.value === 0 || initial.value === 1) && boolControl(m.step.state?.[key] ?? x(key), key));
|
|
1134
|
+
const supplied = !!opts.cubes && !!opts.rows?.length && finiteControl;
|
|
1135
|
+
if (supplied)
|
|
1136
|
+
for (const row of opts.rows)
|
|
1137
|
+
keep(row);
|
|
1116
1138
|
trace('start');
|
|
1117
1139
|
// Counted: `runs` requests tried at least, and on until as many states as the samples hold were offered (a trial offers
|
|
1118
1140
|
// its start at least), the trials at most `runs` or that many. Timed: `runsMs` of wall time.
|
|
@@ -1120,7 +1142,7 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
1120
1142
|
// runs the least, the engine's small instance its samples)
|
|
1121
1143
|
const relStep = domainStep(m);
|
|
1122
1144
|
const runsTimed = timed || opts.runsMs !== undefined, runsUntil = Math.min(wallUntil, performance.now() + (opts.runsMs ?? 500)), least = opts.runs ?? (relStep ? 2000 : Math.min(inferRuns, Math.max(2000, 4 * ms)));
|
|
1123
|
-
const moreRuns = (trial) => (runsTimed ? performance.now() < runsUntil : trial < (relStep ? 400 : Math.max(cap, least)) && (used.tries < least || offered < cap) && !stop());
|
|
1145
|
+
const moreRuns = (trial) => !supplied && (runsTimed ? performance.now() < runsUntil : trial < (relStep ? 400 : Math.max(cap, least)) && (used.tries < least || offered < cap) && !stop());
|
|
1124
1146
|
let trials = 0;
|
|
1125
1147
|
// (an assumption with "there exists", a value the request brings, may admit no request at a small bound, a multiple
|
|
1126
1148
|
// of 5 but 0, say: a trial whose steps moved nothing doubles the bound at once)
|
|
@@ -1172,9 +1194,10 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
1172
1194
|
next = n2;
|
|
1173
1195
|
}
|
|
1174
1196
|
else {
|
|
1175
|
-
|
|
1197
|
+
const sampled = stepSample(params, st, input);
|
|
1198
|
+
if (!sampled)
|
|
1176
1199
|
continue;
|
|
1177
|
-
next =
|
|
1200
|
+
next = sampled;
|
|
1178
1201
|
}
|
|
1179
1202
|
}
|
|
1180
1203
|
catch {
|
package/dist/core/laws.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ type Seg = {
|
|
|
25
25
|
call: true;
|
|
26
26
|
args?: string;
|
|
27
27
|
};
|
|
28
|
-
type X = {
|
|
28
|
+
export type X = {
|
|
29
29
|
k: 'num';
|
|
30
30
|
v: number;
|
|
31
31
|
} | {
|
|
@@ -38,6 +38,7 @@ type X = {
|
|
|
38
38
|
v: boolean;
|
|
39
39
|
} | {
|
|
40
40
|
k: 'null';
|
|
41
|
+
absence?: 'null' | 'undefined';
|
|
41
42
|
} | {
|
|
42
43
|
k: 'path';
|
|
43
44
|
head: string;
|
package/dist/core/laws.js
CHANGED
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
// in it, the same item, not an equal one), at every two (or three) at once
|
|
29
29
|
// mode == "closed", outcome == SLOW_ERROR, mode == :closed a choice by its value
|
|
30
30
|
import { Choice, Int, Str, Term, all, any, forall, no, not, yes } from "./dsl.js";
|
|
31
|
+
import { attachNativeLaw } from "./source-check.js";
|
|
32
|
+
import { nativeLaw } from "./native-law.js";
|
|
31
33
|
import { agreement, isolation, noninterference } from "./relational.js";
|
|
32
34
|
import { CalendarError, businessDays } from "./calendar.js";
|
|
33
35
|
export { businessDays } from "./calendar.js";
|
|
@@ -178,7 +180,7 @@ export function parse(s) {
|
|
|
178
180
|
if (['false', 'False'].includes(x))
|
|
179
181
|
return { k: 'bool', v: false };
|
|
180
182
|
if (['None', 'nil', 'null', 'undefined', 'NULL', 'nullptr'].includes(x))
|
|
181
|
-
return { k: 'null' };
|
|
183
|
+
return { k: 'null', ...(x === 'null' || x === 'undefined' ? { absence: x } : {}) };
|
|
182
184
|
if (!/^@?[A-Za-z_]/.test(x))
|
|
183
185
|
throw new LawError(`unexpected ${JSON.stringify(x)}`);
|
|
184
186
|
if (x === 'old' && peek() === '(') {
|
|
@@ -264,6 +266,10 @@ const calendarOf = (opts) => {
|
|
|
264
266
|
};
|
|
265
267
|
export function buildLaw(x, l, opts = {}) {
|
|
266
268
|
const strictOptional = x.model?.standalone === true;
|
|
269
|
+
const absence = {};
|
|
270
|
+
for (const r of Object.values(x.model?.results ?? {}))
|
|
271
|
+
if (r.k === 'maybe')
|
|
272
|
+
absence[r.missing] = r.null ? 'null' : 'undefined';
|
|
267
273
|
const names = namesWithClock(x), r = x.rule;
|
|
268
274
|
if (!r)
|
|
269
275
|
throw new LawError('the extraction has no rule');
|
|
@@ -272,15 +278,18 @@ export function buildLaw(x, l, opts = {}) {
|
|
|
272
278
|
const e = parse(l.expr);
|
|
273
279
|
// A first reading finds what the law reads: a request, a result, the failure or the state before make it a step law.
|
|
274
280
|
const cal = opts.clock === undefined ? undefined : calendarOf(opts);
|
|
275
|
-
const probe = { strictOptional, consts: x.consts, b: {}, a: {}, step: true, method: l.method, keys: new Map(), roles: new Set(), methods: new Set(), clock: opts.clock, cal };
|
|
281
|
+
const probe = { strictOptional, absence, consts: x.consts, b: {}, a: {}, step: true, method: l.method, keys: new Map(), roles: new Set(), methods: new Set(), clock: opts.clock, cal };
|
|
276
282
|
read(e, probe, names, true);
|
|
277
283
|
// (a law on a method, the line above it, is a law of its step: the state after it, old(x) before)
|
|
278
284
|
const step = !!l.method || ['input', 'answer', 'result', 'failed', 'clock', 'method', 'old'].some(k => probe.roles.has(k));
|
|
279
|
-
|
|
285
|
+
// An explicit binding is authoritative even when a name has only one owner.
|
|
286
|
+
if (l.method && [...probe.methods].some(method => method !== l.method))
|
|
287
|
+
throw new LawError(`the law is bound to ${l.method}, but reads a value belonging to ${[...probe.methods].join(', ')}`);
|
|
288
|
+
const method = l.method ?? (probe.methods.size === 1 ? [...probe.methods][0] : undefined);
|
|
280
289
|
if (probe.methods.size > 1)
|
|
281
290
|
throw new LawError(`it reads the arguments of ${[...probe.methods].join(' and ')}: a law of one step is about one method`);
|
|
282
291
|
const gate = step && method && names.some(n => n.role === 'method') ? method : undefined;
|
|
283
|
-
const body0 = (b, a, pins, bits) => read(e, { strictOptional, consts: x.consts, b, a, step, method, keys: new Map(), roles: new Set(), methods: new Set(), clock: opts.clock, cal, pins, ...(bits ? { bits } : {}) }, names, false);
|
|
292
|
+
const body0 = (b, a, pins, bits) => read(e, { strictOptional, absence, consts: x.consts, b, a, step, method, keys: new Map(), roles: new Set(), methods: new Set(), clock: opts.clock, cal, pins, ...(bits ? { bits } : {}) }, names, false);
|
|
284
293
|
// (a step law's bit tests: read once to count the keys they take, then at every value of them, the facts implying it)
|
|
285
294
|
const bitBody = (b, a) => {
|
|
286
295
|
const count = { ks: [], used: 0, hyps: [] };
|
|
@@ -295,10 +304,11 @@ export function buildLaw(x, l, opts = {}) {
|
|
|
295
304
|
};
|
|
296
305
|
// (a law of one step reads no function, so business days there pin each time's week to a key, ∀w. guard → law)
|
|
297
306
|
const body = (b, a) => (step && probe.roles.has('bdays') ? pinned(b, a, (bb, aa, p) => body0(bb, aa, p)) : bitBody(b, a));
|
|
307
|
+
const bind = (built) => { attachNativeLaw(x.rule, built.law, l.name, built.kind === 'step' ? gate ?? method : undefined, nativeLaw(e, opts, parse, { ...Object.fromEntries(names.filter(n => n.role === 'const' && n.value !== undefined).map(n => [n.code, n.value])), ...x.consts }, new Set(names.map(n => n.code.split('.')[0])))); return built; };
|
|
298
308
|
if (!step)
|
|
299
|
-
return { kind: 'law', law: r.law(l.name, (env) => (x.quiet ? env[x.quiet].eq(0).implies(body0(env, env)) : body0(env, env))) };
|
|
309
|
+
return bind({ kind: 'law', law: r.law(l.name, (env) => (x.quiet ? env[x.quiet].eq(0).implies(body0(env, env)) : body0(env, env))) });
|
|
300
310
|
const mname = names.find(n => n.role === 'method')?.rule;
|
|
301
|
-
return { kind: 'step', ...(gate ? { method: gate } : {}), law: r.stepLaw(l.name, (b, a) => body(b, a), gate ? (b) => b[mname].is(gate) : undefined) };
|
|
311
|
+
return bind({ kind: 'step', ...(gate ? { method: gate } : {}), law: r.stepLaw(l.name, (b, a) => body(b, a), gate ? (b) => b[mname].is(gate) : undefined) });
|
|
302
312
|
}
|
|
303
313
|
// A law of one step over business days: read once to find its times, then held at every week of each (a key, two for
|
|
304
314
|
// a time that may be below 0), under the guards that only each time's own week meets.
|
|
@@ -393,7 +403,7 @@ function val(e, c, names, dry) {
|
|
|
393
403
|
throw new LawError(`${e.text}: not a whole number of the clock's units`);
|
|
394
404
|
return { t: 'num', v: Int.of(e.v * c.clock) };
|
|
395
405
|
case 'bool': return { t: 'cond', v: e.v ? yes : no };
|
|
396
|
-
case 'null': return { t: 'null' };
|
|
406
|
+
case 'null': return { t: 'null', absence: e.absence };
|
|
397
407
|
case 'str':
|
|
398
408
|
if (e.holes)
|
|
399
409
|
throw new LawError('a string template outside a store\'s key');
|
|
@@ -454,8 +464,9 @@ function val(e, c, names, dry) {
|
|
|
454
464
|
// over the integers (a <= x // k is k·a <= x; a < x // k is k·(a + 1) <= x), so it needs no function, which a law
|
|
455
465
|
// of one step can't read)
|
|
456
466
|
const flip = { '<': '>', '<=': '>=', '>': '<', '>=': '<=', '==': '==', '!=': '!=' };
|
|
467
|
+
// Calendar operands retain strict optional checks throughout nested arithmetic.
|
|
457
468
|
if (flip[e.op] && (e.a.k === 'bdur' || e.b.k === 'bdur'))
|
|
458
|
-
return { t: 'cond', v: businessCompare(e, flip, c,
|
|
469
|
+
return { t: 'cond', v: businessCompare(e, flip, c, operand => val(operand, { ...c, strictOptional: true }, names, dry), dry) };
|
|
459
470
|
const divk = (x) => (x.k === 'bin' && x.op === '//' && (constOf(x.b) ?? 0) >= 1 ? x : undefined);
|
|
460
471
|
if (flip[e.op] && (divk(e.b) || divk(e.a))) {
|
|
461
472
|
// Inspect the original numerator before rewriting division into comparisons.
|
|
@@ -573,6 +584,8 @@ function businessCompare(e, flip, c, go, dry) {
|
|
|
573
584
|
throw new LawError(`${n.text}: business days need a calendar ([calendar] in gdp.toml: weekend = ["sat", "sun"], holidays = ["2026-12-25", ...], utc_offset = "-05:00")`);
|
|
574
585
|
c.roles.add('bdays');
|
|
575
586
|
const later = go(diff.a), earlier = go(diff.b);
|
|
587
|
+
if ([later, earlier].some(v => v.t === 'opt'))
|
|
588
|
+
throw new LawError(c.strictOptional ? 'arithmetic on an optional standalone value is not supported' : 'arithmetic on an optional value is not supported in calendar comparisons');
|
|
576
589
|
if (dry)
|
|
577
590
|
return yes;
|
|
578
591
|
const cal = c.cal, at = (x, v) => {
|
|
@@ -596,9 +609,13 @@ function businessCompare(e, flip, c, go, dry) {
|
|
|
596
609
|
// (a path's last name: a choice's value written as one, Outcome.SLOW_ERROR)
|
|
597
610
|
const lastName = (x) => (x.segs.length ? x.segs.at(-1).f : x.head);
|
|
598
611
|
const constOf = (x) => (x.k === 'num' ? x.v : x.k === 'un' && x.op === '-' && x.x.k === 'num' ? -x.x.v : undefined);
|
|
599
|
-
|
|
612
|
+
// Require the caller to choose source semantics, including on recursive unwrapping.
|
|
613
|
+
function compare(op, a, b, e, strictOptional) {
|
|
600
614
|
if (b.t === 'null' || a.t === 'null') {
|
|
615
|
+
const literal = a.t === 'null' ? a : b;
|
|
601
616
|
const o = a.t === 'null' ? b : a, none = o.t === 'opt' ? o.none : o.t === 'cell' ? not(o.rec.has) : undefined;
|
|
617
|
+
if (strictOptional && o.t === 'opt' && literal.absence && o.absence && literal.absence !== o.absence)
|
|
618
|
+
return op === '==' ? no : op === '!=' ? yes : fail(`${op} with None`);
|
|
602
619
|
if (!none)
|
|
603
620
|
throw new LawError(`${show(a.t === 'null' ? e.b : e.a)} is never None here (the rule holds no None for it)`);
|
|
604
621
|
return op === '==' ? none : op === '!=' ? not(none) : fail(`${op} with None`);
|
|
@@ -609,11 +626,11 @@ function compare(op, a, b, e, strictOptional = false) {
|
|
|
609
626
|
const av = a.t === 'opt' ? a.v : a, bv = b.t === 'opt' ? b.v : b;
|
|
610
627
|
const present = all(a.t === 'opt' ? not(a.none) : yes, b.t === 'opt' ? not(b.none) : yes);
|
|
611
628
|
if (op === '==' || op === '!=') {
|
|
612
|
-
const absent = a.t === 'opt' && b.t === 'opt' ? all(a.none, b.none) : no;
|
|
613
|
-
const equal = any(absent, av && bv ? all(present, compare('==', av, bv, e)) : no);
|
|
629
|
+
const absent = a.t === 'opt' && b.t === 'opt' && (!a.absence || !b.absence || a.absence === b.absence) ? all(a.none, b.none) : no;
|
|
630
|
+
const equal = any(absent, av && bv ? all(present, compare('==', av, bv, e, strictOptional)) : no);
|
|
614
631
|
return op === '==' ? equal : not(equal);
|
|
615
632
|
}
|
|
616
|
-
return av && bv ? all(present, compare(op, av, bv, e)) : no;
|
|
633
|
+
return av && bv ? all(present, compare(op, av, bv, e, strictOptional)) : no;
|
|
617
634
|
}
|
|
618
635
|
const un = (v) => (v.t === 'opt' && v.v ? v.v : v);
|
|
619
636
|
a = un(a);
|
|
@@ -625,8 +642,12 @@ function compare(op, a, b, e, strictOptional = false) {
|
|
|
625
642
|
const eq = (c) => (op === '==' ? c : op === '!=' ? not(c) : fail(`${op} of values that aren't numbers`));
|
|
626
643
|
if (a.t === 'choice' || b.t === 'choice') {
|
|
627
644
|
const [ch, o, ox] = a.t === 'choice' ? [a.v, b, e.b] : [b.v, a, e.a];
|
|
645
|
+
// Choice encodings are local to each domain: the same index can name
|
|
646
|
+
// different strings. In standalone laws compare common names, not indices.
|
|
628
647
|
if (o.t === 'choice')
|
|
629
|
-
return eq(
|
|
648
|
+
return eq(strictOptional
|
|
649
|
+
? any(...ch.values.filter(v => o.v.values.includes(v)).map(v => all(ch.is(v), o.v.is(v))))
|
|
650
|
+
: ch.eq(o.v));
|
|
630
651
|
const lit = o.t === 'lit' ? o.v : ox.k === 'path' ? lastName(ox) : undefined;
|
|
631
652
|
if (lit === undefined || !ch.values.includes(lit))
|
|
632
653
|
throw new LawError(`${show(ox)} isn't one of ${ch.values.join(', ')}`);
|
|
@@ -666,6 +687,18 @@ function path(e, c, names, dry) {
|
|
|
666
687
|
return DRY;
|
|
667
688
|
// (result and failed are the step's, unless the code has a name of its own so: a field named failed, read bare, is
|
|
668
689
|
// that field, as self.failed always is)
|
|
690
|
+
if (e.head === 'result' && e.segs[0] && 'f' in e.segs[0]) {
|
|
691
|
+
const field = `result.${e.segs[0].f}`, rs = names.filter(n => n.role === 'result' && n.code === field);
|
|
692
|
+
const hit = rs.find(n => n.method === c.method) ?? (rs.length === 1 ? rs[0] : undefined);
|
|
693
|
+
if (hit) {
|
|
694
|
+
c.roles.add('result');
|
|
695
|
+
if (hit.method)
|
|
696
|
+
c.methods.add(hit.method);
|
|
697
|
+
return rest(e.segs.slice(1), leaf(hit, c, dry), c, names, dry, e);
|
|
698
|
+
}
|
|
699
|
+
if (rs.length > 1)
|
|
700
|
+
throw new LawError(`${field}: name the method it belongs to`);
|
|
701
|
+
}
|
|
669
702
|
if ((e.head === 'result' || e.head === 'failed') && !names.some(n => n.code === e.head && n.role !== 'failed' && n.role !== 'result')) {
|
|
670
703
|
const n = e.head === 'failed' ? names.find(x => x.role === 'failed') : results(names, c);
|
|
671
704
|
if (!n)
|
|
@@ -781,7 +814,7 @@ function leaf(n, c, dry) {
|
|
|
781
814
|
const get = (r) => { if (!(r in env) && !(r in c.b))
|
|
782
815
|
throw new LawError(`${n.code}: ${r} isn't in the rule's environment here`); return r in env ? env[r] : c.b[r]; };
|
|
783
816
|
const v = n.rule ? wrap(get(n.rule)) : undefined;
|
|
784
|
-
return n.none ? { t: 'opt', none: get(n.none), ...(v ? { v } : {}) } : v;
|
|
817
|
+
return n.none ? { t: 'opt', none: get(n.none), absence: c.strictOptional ? c.absence?.[n.none] ?? 'undefined' : undefined, ...(v ? { v } : {}) } : v;
|
|
785
818
|
}
|
|
786
819
|
// The rest of a path: a map at a key (m[k], m.get(k)), a cell's field, has/contains/key? of a map.
|
|
787
820
|
function rest(segs, v, c, names, dry, e) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Goal, type LemmaCut, type Path, type Tree, leafConstraintsReusing as leafConstraints } from '../kernel/kernel.js';
|
|
2
|
+
export type ProofOrigin = {
|
|
3
|
+
goal: Goal;
|
|
4
|
+
tree: Tree;
|
|
5
|
+
path: Path;
|
|
6
|
+
};
|
|
7
|
+
export declare const proofOrigins: {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const proofOrigin: (tree: Tree) => ProofOrigin | undefined;
|
|
11
|
+
export declare const setProofOrigin: (tree: Tree, origin: ProofOrigin) => void;
|
|
12
|
+
export declare function rememberProofOrigin(out: Tree | undefined, part: Goal, tree: Tree, path: Path, whole: Goal): void;
|
|
13
|
+
type ProofRows = ReturnType<typeof leafConstraints>;
|
|
14
|
+
export declare function rememberProofRows(tree: Tree, goal: Goal, path: Path, rows: ProofRows): void;
|
|
15
|
+
export type SharedCuts = {
|
|
16
|
+
goal: Goal;
|
|
17
|
+
tree: Tree;
|
|
18
|
+
lemmas: LemmaCut[];
|
|
19
|
+
stats: {
|
|
20
|
+
before: number;
|
|
21
|
+
after: number;
|
|
22
|
+
cuts: number;
|
|
23
|
+
sourceHyps: number;
|
|
24
|
+
lemmaHyps: number;
|
|
25
|
+
mainNodes: number;
|
|
26
|
+
checkMs: number;
|
|
27
|
+
buildMs: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare function proposeLemmaCuts(goal: Goal, tree: Tree, options?: {
|
|
31
|
+
path?: Path;
|
|
32
|
+
until?: number;
|
|
33
|
+
minNodes?: number;
|
|
34
|
+
minimizeConditions?: boolean;
|
|
35
|
+
trace?: (event: Record<string, string | number | boolean>) => void;
|
|
36
|
+
}): SharedCuts | undefined;
|
|
37
|
+
export declare function shareLemmaCuts(goal: Goal, tree: Tree, options?: Parameters<typeof proposeLemmaCuts>[2]): SharedCuts | undefined;
|
|
38
|
+
export {};
|