gdp-wired 0.46.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.
Files changed (182) hide show
  1. package/README.md +18 -5
  2. package/dist/core/carry.d.ts +15 -0
  3. package/dist/core/carry.js +651 -0
  4. package/dist/core/cli.d.ts +4 -1
  5. package/dist/core/cli.js +31 -11
  6. package/dist/core/count-cases.d.ts +24 -0
  7. package/dist/core/count-cases.js +320 -0
  8. package/dist/core/count-cert-grow.d.ts +4 -0
  9. package/dist/core/count-cert-grow.js +37 -0
  10. package/dist/core/count-cert-transport.d.ts +3 -0
  11. package/dist/core/count-cert-transport.js +58 -0
  12. package/dist/core/count-completion.d.ts +9 -0
  13. package/dist/core/count-completion.js +27 -0
  14. package/dist/core/count-cubes.d.ts +8 -0
  15. package/dist/core/count-cubes.js +69 -0
  16. package/dist/core/count-demand.d.ts +37 -0
  17. package/dist/core/count-demand.js +361 -0
  18. package/dist/core/count-facts.d.ts +52 -0
  19. package/dist/core/count-facts.js +247 -0
  20. package/dist/core/count-focus-proof.d.ts +8 -0
  21. package/dist/core/count-focus-proof.js +140 -0
  22. package/dist/core/count-focused.d.ts +22 -0
  23. package/dist/core/count-focused.js +676 -0
  24. package/dist/core/count-ranges.d.ts +5 -0
  25. package/dist/core/count-ranges.js +65 -0
  26. package/dist/core/count-recovery/action-guard.d.ts +5 -0
  27. package/dist/core/count-recovery/action-guard.js +51 -0
  28. package/dist/core/count-recovery/boolean-core.d.ts +16 -0
  29. package/dist/core/count-recovery/boolean-core.js +258 -0
  30. package/dist/core/count-recovery/carried-case.d.ts +2 -0
  31. package/dist/core/count-recovery/carried-case.js +24 -0
  32. package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
  33. package/dist/core/count-recovery/conditional-check-cache.js +130 -0
  34. package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
  35. package/dist/core/count-recovery/conditional-cuts.js +318 -0
  36. package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
  37. package/dist/core/count-recovery/conditional-proof.js +306 -0
  38. package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
  39. package/dist/core/count-recovery/derivability-closure.js +533 -0
  40. package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
  41. package/dist/core/count-recovery/empty-count-source.js +40 -0
  42. package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
  43. package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
  44. package/dist/core/count-recovery/field-case.d.ts +5 -0
  45. package/dist/core/count-recovery/field-case.js +89 -0
  46. package/dist/core/count-recovery/field-demand.d.ts +46 -0
  47. package/dist/core/count-recovery/field-demand.js +47 -0
  48. package/dist/core/count-recovery/field-only.d.ts +3 -0
  49. package/dist/core/count-recovery/field-only.js +18 -0
  50. package/dist/core/count-recovery/fold-path.d.ts +6 -0
  51. package/dist/core/count-recovery/fold-path.js +35 -0
  52. package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
  53. package/dist/core/count-recovery/frame-lemmas.js +120 -0
  54. package/dist/core/count-recovery/guard-cases.d.ts +12 -0
  55. package/dist/core/count-recovery/guard-cases.js +138 -0
  56. package/dist/core/count-recovery/key-closure.d.ts +14 -0
  57. package/dist/core/count-recovery/key-closure.js +62 -0
  58. package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
  59. package/dist/core/count-recovery/leaf-allowance.js +7 -0
  60. package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
  61. package/dist/core/count-recovery/lift-count-proxies.js +175 -0
  62. package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
  63. package/dist/core/count-recovery/live-dependencies.js +76 -0
  64. package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
  65. package/dist/core/count-recovery/member-inclusions.js +168 -0
  66. package/dist/core/count-recovery/member-premises.d.ts +29 -0
  67. package/dist/core/count-recovery/member-premises.js +114 -0
  68. package/dist/core/count-recovery/natural-cases.d.ts +6 -0
  69. package/dist/core/count-recovery/natural-cases.js +59 -0
  70. package/dist/core/count-recovery/ops.d.ts +6 -0
  71. package/dist/core/count-recovery/ops.js +8 -0
  72. package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
  73. package/dist/core/count-recovery/pre-state-source.js +18 -0
  74. package/dist/core/count-recovery/rebase-path.d.ts +9 -0
  75. package/dist/core/count-recovery/rebase-path.js +70 -0
  76. package/dist/core/count-recovery/rename-proof.d.ts +2 -0
  77. package/dist/core/count-recovery/rename-proof.js +102 -0
  78. package/dist/core/count-recovery/row-cases.d.ts +16 -0
  79. package/dist/core/count-recovery/row-cases.js +291 -0
  80. package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
  81. package/dist/core/count-recovery/scalar-guards.js +291 -0
  82. package/dist/core/count-recovery/source-memo.d.ts +12 -0
  83. package/dist/core/count-recovery/source-memo.js +67 -0
  84. package/dist/core/count-select.d.ts +16 -0
  85. package/dist/core/count-select.js +24 -0
  86. package/dist/core/count-support.d.ts +598 -0
  87. package/dist/core/count-support.js +2080 -0
  88. package/dist/core/count-unions.d.ts +2 -0
  89. package/dist/core/count-unions.js +139 -0
  90. package/dist/core/count-witness-flags.d.ts +9 -0
  91. package/dist/core/count-witness-flags.js +37 -0
  92. package/dist/core/count-write-frames.d.ts +12 -0
  93. package/dist/core/count-write-frames.js +206 -0
  94. package/dist/core/counts.d.ts +20 -2
  95. package/dist/core/counts.js +807 -156
  96. package/dist/core/dsl.d.ts +50 -6
  97. package/dist/core/dsl.js +307 -65
  98. package/dist/core/effect-schema.d.ts +90 -0
  99. package/dist/core/effect-schema.js +500 -0
  100. package/dist/core/effect.d.ts +3 -7
  101. package/dist/core/effect.js +10 -65
  102. package/dist/core/exists.d.ts +1 -1
  103. package/dist/core/exists.js +80 -15
  104. package/dist/core/extract-check.d.ts +7 -1
  105. package/dist/core/extract-check.js +161 -19
  106. package/dist/core/extract-go-check.js +24 -4
  107. package/dist/core/extract-go.d.ts +7 -0
  108. package/dist/core/extract-go.js +29 -2
  109. package/dist/core/extract-read.d.ts +31 -9
  110. package/dist/core/extract-read.js +36 -11
  111. package/dist/core/extract-rs.js +58 -14
  112. package/dist/core/extract-shapes.d.ts +1 -0
  113. package/dist/core/extract-shapes.js +190 -27
  114. package/dist/core/extract-standalone.d.ts +3 -0
  115. package/dist/core/extract-standalone.js +265 -0
  116. package/dist/core/extract.d.ts +1 -0
  117. package/dist/core/extract.js +25 -5
  118. package/dist/core/field-laws.d.ts +2 -0
  119. package/dist/core/field-laws.js +100 -0
  120. package/dist/core/finite-frontiers.d.ts +5 -0
  121. package/dist/core/finite-frontiers.js +116 -0
  122. package/dist/core/finite-houdini.d.ts +52 -0
  123. package/dist/core/finite-houdini.js +460 -0
  124. package/dist/core/finite-model.d.ts +13 -0
  125. package/dist/core/finite-model.js +68 -0
  126. package/dist/core/finite-tiny.d.ts +72 -0
  127. package/dist/core/finite-tiny.js +1052 -0
  128. package/dist/core/infer.d.ts +1 -1
  129. package/dist/core/infer.js +32 -9
  130. package/dist/core/laws.d.ts +2 -1
  131. package/dist/core/laws.js +76 -19
  132. package/dist/core/lemma-cuts.d.ts +38 -0
  133. package/dist/core/lemma-cuts.js +365 -0
  134. package/dist/core/machine.d.ts +39 -2
  135. package/dist/core/machine.js +240 -35
  136. package/dist/core/mutate.d.ts +55 -0
  137. package/dist/core/mutate.js +210 -0
  138. package/dist/core/native-domain.d.ts +6 -0
  139. package/dist/core/native-domain.js +114 -0
  140. package/dist/core/native-law.d.ts +3 -0
  141. package/dist/core/native-law.js +174 -0
  142. package/dist/core/quorum-laws.d.ts +5 -0
  143. package/dist/core/quorum-laws.js +239 -0
  144. package/dist/core/relational.js +10 -2
  145. package/dist/core/relevance.d.ts +4 -0
  146. package/dist/core/relevance.js +79 -0
  147. package/dist/core/rs/Cargo.toml +1 -1
  148. package/dist/core/rs/src/main.rs +458 -9
  149. package/dist/core/runtime-wall.d.ts +3 -0
  150. package/dist/core/runtime-wall.js +4 -0
  151. package/dist/core/sample-step.d.ts +16 -0
  152. package/dist/core/sample-step.js +28 -0
  153. package/dist/core/source-check.d.ts +44 -0
  154. package/dist/core/source-check.js +126 -0
  155. package/dist/core/source-diagnostic.d.ts +1 -0
  156. package/dist/core/source-diagnostic.js +34 -0
  157. package/dist/core/support-budget.d.ts +2 -0
  158. package/dist/core/support-budget.js +6 -0
  159. package/dist/core/system.js +2 -0
  160. package/dist/core/wall.d.ts +6 -0
  161. package/dist/core/wall.js +23 -0
  162. package/dist/core/watch.js +4 -0
  163. package/dist/kernel/cdcl.d.ts +4 -0
  164. package/dist/kernel/cdcl.js +20 -5
  165. package/dist/kernel/kernel.d.ts +10 -0
  166. package/dist/kernel/kernel.js +56 -3
  167. package/dist/kernel/model-sequence.d.ts +2 -2
  168. package/dist/kernel/model-sequence.js +4 -3
  169. package/dist/kernel/model-values.d.ts +2 -0
  170. package/dist/kernel/model-values.js +60 -0
  171. package/dist/kernel/prove.d.ts +10 -0
  172. package/dist/kernel/prove.js +56 -8
  173. package/dist/kernel/prover-rows.d.ts +29 -0
  174. package/dist/kernel/prover-rows.js +114 -0
  175. package/dist/lean-kernel/emit.d.ts +39 -2
  176. package/dist/lean-kernel/emit.js +136 -24
  177. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  178. package/dist/lean-kernel/lean-terms.js +13 -5
  179. package/dist/lean-kernel/library.js +4 -0
  180. package/dist/lean-kernel/qalpha.d.ts +7 -0
  181. package/dist/lean-kernel/qalpha.js +40 -0
  182. package/package.json +5 -1
@@ -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 = {
@@ -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, proveRule, proveSteps, verdictOf } from "./dsl.js";
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
- if (searchRule)
1081
- return stepLaws.length ? proveSteps(searchRule, ls, stepLaws, { search: false }) : proveRule(searchRule, ls, { search: false, fast });
1082
- const out = stepLaws.length ? proveStepLaws(mm, ls, stepLaws) : (fast ? proveSetFast : proveLaws)(mm, ls);
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
- const first = opts.first ?? (opts.cubes ? { proven: false, checked: false } : prove(laws));
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
- if (!allowed(m, run, params, st, input))
1197
+ const sampled = stepSample(params, st, input);
1198
+ if (!sampled)
1176
1199
  continue;
1177
- next = run.step(params, st, input);
1200
+ next = sampled;
1178
1201
  }
1179
1202
  }
1180
1203
  catch {
@@ -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() === '(') {
@@ -263,6 +265,11 @@ const calendarOf = (opts) => {
263
265
  }
264
266
  };
265
267
  export function buildLaw(x, l, opts = {}) {
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';
266
273
  const names = namesWithClock(x), r = x.rule;
267
274
  if (!r)
268
275
  throw new LawError('the extraction has no rule');
@@ -271,15 +278,18 @@ export function buildLaw(x, l, opts = {}) {
271
278
  const e = parse(l.expr);
272
279
  // A first reading finds what the law reads: a request, a result, the failure or the state before make it a step law.
273
280
  const cal = opts.clock === undefined ? undefined : calendarOf(opts);
274
- const probe = { 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 };
275
282
  read(e, probe, names, true);
276
283
  // (a law on a method, the line above it, is a law of its step: the state after it, old(x) before)
277
284
  const step = !!l.method || ['input', 'answer', 'result', 'failed', 'clock', 'method', 'old'].some(k => probe.roles.has(k));
278
- const method = probe.methods.size === 1 ? [...probe.methods][0] : l.method;
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);
279
289
  if (probe.methods.size > 1)
280
290
  throw new LawError(`it reads the arguments of ${[...probe.methods].join(' and ')}: a law of one step is about one method`);
281
291
  const gate = step && method && names.some(n => n.role === 'method') ? method : undefined;
282
- const body0 = (b, a, pins, bits) => read(e, { 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);
283
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)
284
294
  const bitBody = (b, a) => {
285
295
  const count = { ks: [], used: 0, hyps: [] };
@@ -294,10 +304,11 @@ export function buildLaw(x, l, opts = {}) {
294
304
  };
295
305
  // (a law of one step reads no function, so business days there pin each time's week to a key, ∀w. guard → law)
296
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; };
297
308
  if (!step)
298
- 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))) });
299
310
  const mname = names.find(n => n.role === 'method')?.rule;
300
- 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) });
301
312
  }
302
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
303
314
  // a time that may be below 0), under the guards that only each time's own week meets.
@@ -343,7 +354,7 @@ function read(e, c, names, dry) {
343
354
  if (dry) {
344
355
  for (const f of chain)
345
356
  c.keys.set(f.v, new Term({ op: 'const', value: 0 }));
346
- return cond(val(body, c, names, true));
357
+ return cond(val(body, c, names, true), c.strictOptional);
347
358
  }
348
359
  const at = (ks) => {
349
360
  const held = overs.map((o, i) => {
@@ -353,17 +364,17 @@ function read(e, c, names, dry) {
353
364
  c.items.set(chain[i].v, { map: m.at(ks[i]), fields: o.over.n.map.fields });
354
365
  return m.at(ks[i]).has;
355
366
  });
356
- return all(...held).implies(cond(val(body, c, names, false)));
367
+ return all(...held).implies(cond(val(body, c, names, false), c.strictOptional));
357
368
  };
358
369
  return chain.length === 1 ? forall(k => at([k])) : chain.length === 2 ? forall((k, j) => at([k, j])) : forall((k, j, i) => at([k, j, i]));
359
370
  }
360
- return cond(val(e, c, names, dry));
371
+ return cond(val(e, c, names, dry), c.strictOptional);
361
372
  }
362
- const cond = (v) => {
373
+ const cond = (v, strictOptional = false) => {
363
374
  if (v.t === 'cond')
364
375
  return v.v;
365
376
  if (v.t === 'opt' && v.v?.t === 'cond')
366
- return v.v.v;
377
+ return strictOptional ? all(not(v.none), v.v.v) : v.v.v;
367
378
  throw new LawError(`a ${v.t === 'num' ? 'number' : v.t} where a condition is read`);
368
379
  };
369
380
  const num = (v) => {
@@ -392,7 +403,7 @@ function val(e, c, names, dry) {
392
403
  throw new LawError(`${e.text}: not a whole number of the clock's units`);
393
404
  return { t: 'num', v: Int.of(e.v * c.clock) };
394
405
  case 'bool': return { t: 'cond', v: e.v ? yes : no };
395
- case 'null': return { t: 'null' };
406
+ case 'null': return { t: 'null', absence: e.absence };
396
407
  case 'str':
397
408
  if (e.holes)
398
409
  throw new LawError('a string template outside a store\'s key');
@@ -432,6 +443,8 @@ function val(e, c, names, dry) {
432
443
  }
433
444
  }
434
445
  const xs = e.xs.map(go);
446
+ if (c.strictOptional && xs.some(v => v.t === 'opt'))
447
+ throw new LawError('arithmetic on an optional standalone value is not supported');
435
448
  if (dry)
436
449
  return DRY;
437
450
  if (e.f === 'abs')
@@ -440,19 +453,27 @@ function val(e, c, names, dry) {
440
453
  }
441
454
  case 'un': {
442
455
  const v = go(e.x);
456
+ if (c.strictOptional && e.op === '-' && v.t === 'opt')
457
+ throw new LawError('arithmetic on an optional standalone value is not supported');
443
458
  if (dry)
444
459
  return v.t === 'cond' ? v : DRY;
445
- return e.op === '-' ? { t: 'num', v: num(v).negate() } : { t: 'cond', v: not(cond(v)) };
460
+ return e.op === '-' ? { t: 'num', v: num(v).negate() } : { t: 'cond', v: not(cond(v, c.strictOptional)) };
446
461
  }
447
462
  case 'bin': {
448
463
  // (a comparison with x // k on one side, k a positive constant: the same comparison without the division, exact
449
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
450
465
  // of one step can't read)
451
466
  const flip = { '<': '>', '<=': '>=', '>': '<', '>=': '<=', '==': '==', '!=': '!=' };
467
+ // Calendar operands retain strict optional checks throughout nested arithmetic.
452
468
  if (flip[e.op] && (e.a.k === 'bdur' || e.b.k === 'bdur'))
453
- return { t: 'cond', v: businessCompare(e, flip, c, go, dry) };
469
+ return { t: 'cond', v: businessCompare(e, flip, c, operand => val(operand, { ...c, strictOptional: true }, names, dry), dry) };
454
470
  const divk = (x) => (x.k === 'bin' && x.op === '//' && (constOf(x.b) ?? 0) >= 1 ? x : undefined);
455
471
  if (flip[e.op] && (divk(e.b) || divk(e.a))) {
472
+ // Inspect the original numerator before rewriting division into comparisons.
473
+ if (c.strictOptional)
474
+ for (const d of [divk(e.a), divk(e.b)])
475
+ if (d && go(d.a).t === 'opt')
476
+ throw new LawError('arithmetic on an optional standalone value is not supported');
456
477
  const [op, lhs, d] = divk(e.b) ? [e.op, e.a, divk(e.b)] : [flip[e.op], e.b, divk(e.a)];
457
478
  const k = constOf(d.b), ka = { k: 'bin', op: '*', a: { k: 'num', v: k }, b: lhs }, ka1 = { k: 'bin', op: '*', a: { k: 'num', v: k }, b: { k: 'bin', op: '+', a: lhs, b: { k: 'num', v: 1 } } };
458
479
  const le = (a, b) => ({ k: 'bin', op: '<=', a, b }), lt = (a, b) => ({ k: 'bin', op: '<', a, b });
@@ -481,7 +502,9 @@ function val(e, c, names, dry) {
481
502
  if (a.t === 'lit' && a.err && b.t === 'lit' && b.err)
482
503
  throw a.err;
483
504
  if (['&&', '||', '=>'].includes(e.op))
484
- return dry ? { t: 'cond', v: yes } : { t: 'cond', v: e.op === '&&' ? all(cond(a), cond(b)) : e.op === '||' ? any(cond(a), cond(b)) : cond(a).implies(cond(b)) };
505
+ return dry ? { t: 'cond', v: yes } : { t: 'cond', v: e.op === '&&' ? all(cond(a, c.strictOptional), cond(b, c.strictOptional)) : e.op === '||' ? any(cond(a, c.strictOptional), cond(b, c.strictOptional)) : cond(a, c.strictOptional).implies(cond(b, c.strictOptional)) };
506
+ if (c.strictOptional && ['+', '-', '*', '//', '/', '%', '&', '|'].includes(e.op) && [a, b].some(v => v.t === 'opt'))
507
+ throw new LawError('arithmetic on an optional standalone value is not supported');
485
508
  if (dry)
486
509
  return ['+', '-', '*', '//', '/', '%', '&', '|'].includes(e.op) ? DRY : { t: 'cond', v: yes };
487
510
  // x & K and x | K with K a constant (a literal or a constant of the code): K's runs of ones, ((x div 2^lo) mod 2^n)·2^lo
@@ -542,7 +565,7 @@ function val(e, c, names, dry) {
542
565
  throw new LawError(`${e.op} by a positive constant only`);
543
566
  return e.op === '%' ? { t: 'num', v: Int.of(num(a).modBy(k)) } : { t: 'num', v: num(a).divBy(k) };
544
567
  }
545
- return { t: 'cond', v: compare(e.op, a, b, e) };
568
+ return { t: 'cond', v: compare(e.op, a, b, e, c.strictOptional) };
546
569
  }
547
570
  case 'path': return path(e, c, names, dry);
548
571
  case 'forall': return fail('forall ... in ...: at the top of the law only');
@@ -561,6 +584,8 @@ function businessCompare(e, flip, c, go, dry) {
561
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")`);
562
585
  c.roles.add('bdays');
563
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');
564
589
  if (dry)
565
590
  return yes;
566
591
  const cal = c.cal, at = (x, v) => {
@@ -584,13 +609,29 @@ function businessCompare(e, flip, c, go, dry) {
584
609
  // (a path's last name: a choice's value written as one, Outcome.SLOW_ERROR)
585
610
  const lastName = (x) => (x.segs.length ? x.segs.at(-1).f : x.head);
586
611
  const constOf = (x) => (x.k === 'num' ? x.v : x.k === 'un' && x.op === '-' && x.x.k === 'num' ? -x.x.v : undefined);
587
- function compare(op, a, b, e) {
612
+ // Require the caller to choose source semantics, including on recursive unwrapping.
613
+ function compare(op, a, b, e, strictOptional) {
588
614
  if (b.t === 'null' || a.t === 'null') {
615
+ const literal = a.t === 'null' ? a : b;
589
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`);
590
619
  if (!none)
591
620
  throw new LawError(`${show(a.t === 'null' ? e.b : e.a)} is never None here (the rule holds no None for it)`);
592
621
  return op === '==' ? none : op === '!=' ? not(none) : fail(`${op} with None`);
593
622
  }
623
+ // A standalone optional value is absent regardless of its hidden scalar payload.
624
+ // Keep the established law language of other frontends unchanged.
625
+ if (strictOptional && (a.t === 'opt' || b.t === 'opt')) {
626
+ const av = a.t === 'opt' ? a.v : a, bv = b.t === 'opt' ? b.v : b;
627
+ const present = all(a.t === 'opt' ? not(a.none) : yes, b.t === 'opt' ? not(b.none) : yes);
628
+ if (op === '==' || op === '!=') {
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);
631
+ return op === '==' ? equal : not(equal);
632
+ }
633
+ return av && bv ? all(present, compare(op, av, bv, e, strictOptional)) : no;
634
+ }
594
635
  const un = (v) => (v.t === 'opt' && v.v ? v.v : v);
595
636
  a = un(a);
596
637
  b = un(b);
@@ -601,8 +642,12 @@ function compare(op, a, b, e) {
601
642
  const eq = (c) => (op === '==' ? c : op === '!=' ? not(c) : fail(`${op} of values that aren't numbers`));
602
643
  if (a.t === 'choice' || b.t === 'choice') {
603
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.
604
647
  if (o.t === 'choice')
605
- return eq(ch.eq(o.v));
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));
606
651
  const lit = o.t === 'lit' ? o.v : ox.k === 'path' ? lastName(ox) : undefined;
607
652
  if (lit === undefined || !ch.values.includes(lit))
608
653
  throw new LawError(`${show(ox)} isn't one of ${ch.values.join(', ')}`);
@@ -642,6 +687,18 @@ function path(e, c, names, dry) {
642
687
  return DRY;
643
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
644
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
+ }
645
702
  if ((e.head === 'result' || e.head === 'failed') && !names.some(n => n.code === e.head && n.role !== 'failed' && n.role !== 'result')) {
646
703
  const n = e.head === 'failed' ? names.find(x => x.role === 'failed') : results(names, c);
647
704
  if (!n)
@@ -757,7 +814,7 @@ function leaf(n, c, dry) {
757
814
  const get = (r) => { if (!(r in env) && !(r in c.b))
758
815
  throw new LawError(`${n.code}: ${r} isn't in the rule's environment here`); return r in env ? env[r] : c.b[r]; };
759
816
  const v = n.rule ? wrap(get(n.rule)) : undefined;
760
- 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;
761
818
  }
762
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.
763
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 {};