gdp-wired 0.49.0 → 0.50.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 +4 -0
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/cli.js +3 -0
- package/dist/core/count-support.d.ts +1 -0
- package/dist/core/count-support.js +23 -2
- package/dist/core/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.js +9 -2
- package/dist/core/dsl.d.ts +23 -2
- package/dist/core/dsl.js +49 -16
- package/dist/core/exists.js +2 -1
- package/dist/core/field-laws.js +23 -5
- package/dist/core/infer.js +4 -3
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- package/dist/core/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- package/dist/core/quorum-laws.js +55 -16
- package/dist/kernel/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/prove.d.ts +12 -3
- package/dist/kernel/prove.js +164 -90
- package/dist/lean-kernel/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +25 -2
- package/dist/lean-kernel/emit.js +75 -10
- package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +22 -0
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -578,6 +578,10 @@ const soon = retry.law('the next try is at most 64 after the last request', ({ne
|
|
|
578
578
|
`leanProject(file)` a Lake project with the twin, so `lake build` checks them. Each law comes as the twin's theorem and
|
|
579
579
|
as a plain statement over named variables, e.g. `theorem budget.law0 (h : SReach budget_machine ρ μ) : ρ «s» ≤
|
|
580
580
|
(ρ «b» + ρ «m»)`, for a Lean development to cite.
|
|
581
|
+
- **Retained proof lifting** (`gdp-wired/lift`): `gdp-wired lift capsule source.json --out proof` generates a fresh
|
|
582
|
+
Lean project from a data-only proof capsule and source model, without invariant search. The default command checks
|
|
583
|
+
the source laws in Lean; `--emit-only` does not claim acceptance. See [the lift guide](docs/lift.md) for supported
|
|
584
|
+
transports, hash-bound receipts, and the boundary between an encoded source theorem and an external specification.
|
|
581
585
|
- **Composition** (`gdp-wired/compose`): `product(a, b)`, `interleave(a, b)`, `refinement(impl, spec, {relation, witness, stutter})`,
|
|
582
586
|
`steps(spec, k)` (k spec steps as one, each skippable) and `ghost(m, {name: ever(...) | count(...) | total(m, map, name)})`
|
|
583
587
|
build plain machines from machines (each side's state named `a_x`, `b_x`). A refinement's laws are the relation, proven
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Law, type Machine, type SomeWitness } from './machine.js';
|
|
2
|
+
import { proveSetFast } from '../kernel/prove.js';
|
|
3
|
+
import { type Ghosted } from '../kernel/kernel.js';
|
|
4
|
+
type Closure = ReturnType<typeof proveSetFast>;
|
|
5
|
+
type Drop = {
|
|
6
|
+
name: string;
|
|
7
|
+
goal: string;
|
|
8
|
+
stuck: 'sat';
|
|
9
|
+
};
|
|
10
|
+
export type SeedGhosts = Pick<Ghosted, 'vars' | 'maps'>;
|
|
11
|
+
export type SeedResult = {
|
|
12
|
+
status: 'checked';
|
|
13
|
+
laws: Law[];
|
|
14
|
+
kept: Law[];
|
|
15
|
+
dropped: Drop[];
|
|
16
|
+
closure: Closure;
|
|
17
|
+
projection?: 'skolem';
|
|
18
|
+
} | {
|
|
19
|
+
status: 'inconclusive';
|
|
20
|
+
kept: Law[];
|
|
21
|
+
dropped: Drop[];
|
|
22
|
+
reason: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function proveCandidateSeeds(machine: Machine, publicLaws: Law[], candidates: Law[], witnesses?: Record<string, SomeWitness>, ghosts?: SeedGhosts): SeedResult;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Retained laws, witness terms and ghost definitions are proposals, never facts.
|
|
2
|
+
import { walk } from "./machine.js";
|
|
3
|
+
import { decideLaw, proveLaw, proveSetFast } from "../kernel/prove.js";
|
|
4
|
+
import { checkGhostedLaws, ghostedMachine, ghostedOk, someOfGhostsOk, substC } from "../kernel/kernel.js";
|
|
5
|
+
import { retainFrom } from "./proof-output.js";
|
|
6
|
+
// The caller imposes the deadline. Only the complete checked family is evidence.
|
|
7
|
+
// In particular neither a witness nor a ghost definition is a caller assumption.
|
|
8
|
+
export function proveCandidateSeeds(machine, publicLaws, candidates, witnesses = {}, ghosts = { vars: {}, maps: {} }) {
|
|
9
|
+
const refuse = (reason) => ({ status: 'inconclusive', kept: [], dropped: [], reason });
|
|
10
|
+
if (Object.keys(machine.counts ?? {}).length)
|
|
11
|
+
return refuse('count-bearing machine requires counted candidate admission');
|
|
12
|
+
const names = new Set();
|
|
13
|
+
for (const law of [...publicLaws, ...candidates]) {
|
|
14
|
+
if (!law.name || names.has(law.name))
|
|
15
|
+
throw Error('candidate family requires unique law names');
|
|
16
|
+
names.add(law.name);
|
|
17
|
+
}
|
|
18
|
+
const someKey = (c, positive = true) => c.op === 'all' ? (!positive || someKey(c.c, positive)) : c.op === 'not' ? someKey(c.x, !positive) : c.op === 'and' || c.op === 'or' ? c.xs.some(x => someKey(x, positive)) : false;
|
|
19
|
+
const supported = new Set(['name', 'holds', 'forall', 'keys']);
|
|
20
|
+
const publicSupported = new Set([...supported, 'some', 'witness']);
|
|
21
|
+
if (candidates.some(l => Object.keys(l).some(k => !supported.has(k)) || someKey(l.holds)) ||
|
|
22
|
+
publicLaws.some(l => Object.keys(l).some(k => !publicSupported.has(k)) || someKey(l.holds)))
|
|
23
|
+
return refuse('existential family requires projection');
|
|
24
|
+
if (Object.keys(witnesses).some(name => !publicLaws.some(l => l.name === name && l.some?.length)))
|
|
25
|
+
return refuse('witness provided for unknown existential law');
|
|
26
|
+
const projecting = publicLaws.some(l => l.some?.length) || Object.keys(ghosts.vars).length > 0 || Object.keys(ghosts.maps).length > 0;
|
|
27
|
+
const G = { orig: machine, vars: ghosts.vars, maps: ghosts.maps };
|
|
28
|
+
const gv = new Set(Object.keys(G.vars)), gm = new Set(Object.keys(G.maps));
|
|
29
|
+
const reserved = new Set([...machine.params, ...machine.inputs, ...Object.keys(machine.state), ...Object.keys(machine.maps ?? {}),
|
|
30
|
+
...(machine.inputMaps ?? []), ...Object.keys(machine.fns ?? {}), ...Object.keys(machine.step.flags ?? {})]);
|
|
31
|
+
if ([...gv, ...gm].some(n => reserved.has(n)) || [...gv].some(n => gm.has(n)))
|
|
32
|
+
return refuse('ghost name collision');
|
|
33
|
+
let publicReadsGhost = false;
|
|
34
|
+
for (const law of publicLaws)
|
|
35
|
+
walk(law.holds, o => {
|
|
36
|
+
if (o.op === 'var' && gv.has(o.name) || o.op === 'get' && gm.has(o.map) ||
|
|
37
|
+
o.op === 'flag' && gv.has(`?${o.name}`))
|
|
38
|
+
publicReadsGhost = true;
|
|
39
|
+
});
|
|
40
|
+
if (publicReadsGhost)
|
|
41
|
+
return refuse('public law reads a proposed ghost');
|
|
42
|
+
if (projecting && !ghostedOk(G))
|
|
43
|
+
return refuse('ghost definitions not qualified');
|
|
44
|
+
const plains = Object.create(null);
|
|
45
|
+
const plainPublic = [];
|
|
46
|
+
for (const law of publicLaws) {
|
|
47
|
+
if (!law.some?.length) {
|
|
48
|
+
plainPublic.push(law);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const w = witnesses[law.name];
|
|
52
|
+
const sub = w?.terms;
|
|
53
|
+
if (!sub || w.ghost || Object.keys(sub).length !== law.some.length || !law.some.every(n => Object.hasOwn(sub, n)))
|
|
54
|
+
return refuse(`complete witness terms required for ${law.name}`);
|
|
55
|
+
const plain = { name: law.name, holds: substC(law.holds, { vars: Object.assign(Object.create(null), sub), maps: {}, flags: {} }),
|
|
56
|
+
...(law.forall ? { forall: law.forall } : {}), ...(law.keys ? { keys: law.keys } : {}) };
|
|
57
|
+
if (!someOfGhostsOk(G, law, plain, sub))
|
|
58
|
+
return refuse(`existential projection not qualified: ${law.name}`);
|
|
59
|
+
plains[law.name] = { plain, sub };
|
|
60
|
+
plainPublic.push(plain);
|
|
61
|
+
}
|
|
62
|
+
const working = projecting ? ghostedMachine(G) : machine;
|
|
63
|
+
let kept = [...candidates];
|
|
64
|
+
const dropped = [];
|
|
65
|
+
for (;;) {
|
|
66
|
+
const family = [...plainPublic, ...kept];
|
|
67
|
+
let removed = false;
|
|
68
|
+
for (let i = 0; i < kept.length; i++) {
|
|
69
|
+
const decision = decideLaw(working, family, plainPublic.length + i) ?? proveLaw(working, family, plainPublic.length + i);
|
|
70
|
+
if (!decision.proven) {
|
|
71
|
+
if (decision.stuck !== 'sat')
|
|
72
|
+
return { status: 'inconclusive', kept, dropped, reason: `undecided candidate: ${kept[i].name}: ${decision.stuck}${'why' in decision && decision.why ? `: ${decision.why}` : ''}` };
|
|
73
|
+
dropped.push({ name: kept[i].name, goal: decision.goal, stuck: 'sat' });
|
|
74
|
+
kept = kept.filter((_, j) => j !== i);
|
|
75
|
+
removed = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!removed)
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
const family = [...plainPublic, ...kept];
|
|
83
|
+
const whole = proveSetFast(working, family);
|
|
84
|
+
if (!whole.proven || !whole.checked || !whole.proof)
|
|
85
|
+
return { status: 'inconclusive', kept, dropped, reason: whole.failed?.goal ?? 'whole-family proof not checked' };
|
|
86
|
+
if (projecting && !checkGhostedLaws(G, family, whole.proof))
|
|
87
|
+
return { status: 'inconclusive', kept, dropped, reason: 'ghosted whole-family proof not checked' };
|
|
88
|
+
const closure = projecting ? retainFrom({ ...whole }, [whole], { kind: 'skolem', original: machine, laws: publicLaws, G, plains, family }) : whole;
|
|
89
|
+
return { status: 'checked', laws: [...publicLaws, ...kept], kept, dropped, closure, ...(projecting ? { projection: 'skolem' } : {}) };
|
|
90
|
+
}
|
package/dist/core/cli.js
CHANGED
|
@@ -1102,6 +1102,7 @@ function printRule(r, o) {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
const label = (n) => (n.role === 'answer' ? `${n.code.split('.').pop()}(...)` : n.role === 'input' && n.method ? `${n.method}(${n.code})` : n.role === 'result' && n.method ? `${n.method}() result` : n.code);
|
|
1104
1104
|
const USAGE = `gdp-wired check <file|dir>... [--entry X] [--mode standalone] [--methods a,b] [--failures kept] [--on-error discard] [--json] [--ms 10000] [--no-propose] [--clock s|ms] [--cert <dir>] [--from any] [--require-review] [--security]
|
|
1105
|
+
gdp-wired lift <capsule> <source.json> [--out DIR] [--emit-only] [--sha256 HASH] [--json]
|
|
1105
1106
|
gdp-wired mutate <config.json> [--json]
|
|
1106
1107
|
gdp-wired draft <file> --clause <text> | --clause-file <file> --cite <ref> [--llm <command> | --answer <file>] [--by <who>]
|
|
1107
1108
|
|
|
@@ -1178,6 +1179,8 @@ async function draft(target, o) {
|
|
|
1178
1179
|
// Every target's rules and their laws, and the exit code (1: a stated law broken; 2: one not checked, or with
|
|
1179
1180
|
// --require-review, one cited unreviewed).
|
|
1180
1181
|
export async function main(argv) {
|
|
1182
|
+
if (argv[0] === 'lift')
|
|
1183
|
+
return (await import("./lift-cli.js")).liftMain(argv.slice(1));
|
|
1181
1184
|
const { cmd, targets, o } = args(argv);
|
|
1182
1185
|
if (cmd === 'mutate' && targets.length === 1) {
|
|
1183
1186
|
const { checkMutations } = await import("./mutate.js");
|
|
@@ -822,8 +822,29 @@ export function reservePool(goal, decls, pool, previous, previousDecls, chosen,
|
|
|
822
822
|
const forbidden = sourceNames([{ ...goal, hyps: undefined }, decls, full.reads, [...previous.insts, ...full.insts].map(i => i.below)], reservationOpen);
|
|
823
823
|
for (const n of reservationHypNames(goal.hyps))
|
|
824
824
|
forbidden.add(n);
|
|
825
|
-
if (owner.reserved.has(wit) || forbidden.has(wit))
|
|
826
|
-
|
|
825
|
+
if (owner.reserved.has(wit) || forbidden.has(wit)) {
|
|
826
|
+
// Before acquisition the spelling belongs only to the proposal: a source
|
|
827
|
+
// name is not its binder. Never rewrite the source or a selected pick.
|
|
828
|
+
// Once leased, free HYPS may already mean this witness; those must refuse.
|
|
829
|
+
if ((prior && reservationFree(goal.hyps).has(wit)) || names((previous.picks ?? []).filter((_, i) => chosen.has(oldIds[i])), reservationOpen).has(wit))
|
|
830
|
+
throw new UnsupportedCountProposal('reservation owned witness capture/source');
|
|
831
|
+
const from = wit;
|
|
832
|
+
for (const n of sourceNames([previous, full, goal, decls], reservationOpen))
|
|
833
|
+
fresh.add(n);
|
|
834
|
+
for (const n of owner.reserved)
|
|
835
|
+
fresh.add(n);
|
|
836
|
+
for (const l of [...owner.leases.values(), ...leases.values()])
|
|
837
|
+
fresh.add(l.wit);
|
|
838
|
+
do {
|
|
839
|
+
reservationOpen();
|
|
840
|
+
wit = 'w$' + state.next++;
|
|
841
|
+
} while (fresh.has(wit));
|
|
842
|
+
// Optional picks have no retained meaning: alpha-rename their bound
|
|
843
|
+
// witness occurrences together. A selected pick was refused above.
|
|
844
|
+
full.picks = (full.picks ?? []).map((p, i) => chosen.has(fullIds[i]) ? p : [p[0], p[1].map(t => substE(t, { vars: { [from]: x(wit) }, maps: {}, flags: {} }))]);
|
|
845
|
+
fresh.add(wit);
|
|
846
|
+
renamed.push({ key, from, to: wit, reason: 'source-freshness' });
|
|
847
|
+
}
|
|
827
848
|
if ([...owner.leases, ...leases].some(([id, l]) => id !== key && l.wit === wit) || full.insts.some(i => i.wit === wit && 'i' + instId(i, full.reads) !== key))
|
|
828
849
|
throw new UnsupportedCountProposal('reservation different witness owner');
|
|
829
850
|
if (reservationIdentity(rebound, full.reads, decls) !== identity)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Law, Machine } from './machine.js';
|
|
2
|
+
import { type Counted } from './counts.js';
|
|
3
|
+
export type CountedSeedResult = {
|
|
4
|
+
status: 'checked';
|
|
5
|
+
closure: Counted;
|
|
6
|
+
kept: Law[];
|
|
7
|
+
dropped: Law[];
|
|
8
|
+
} | {
|
|
9
|
+
status: 'inconclusive';
|
|
10
|
+
reason: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function proveCountedCandidateSeeds(machine: Machine, publicLaws: Law[], candidates: Law[], ms: number): CountedSeedResult;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { admitCountedFamily } from "./counts.js";
|
|
2
|
+
import { searchWall } from "./wall.js";
|
|
3
|
+
import { checkCountedLaws } from "../kernel/kernel.js";
|
|
4
|
+
import { clock, counted, fullRate, withDeadline, withWall } from "../kernel/prove.js";
|
|
5
|
+
// The machine is the producer with conservative derived count declarations;
|
|
6
|
+
// the caller retains the unchanged source separately for source projection.
|
|
7
|
+
// Only public laws are admission targets. Every returned law is checked again
|
|
8
|
+
// as one family; no unverified proposal is published as a given.
|
|
9
|
+
export function proveCountedCandidateSeeds(machine, publicLaws, candidates, ms) {
|
|
10
|
+
if (!Number.isFinite(ms) || ms <= 0)
|
|
11
|
+
return { status: 'inconclusive', reason: 'invalid budget' };
|
|
12
|
+
const family = [...publicLaws, ...candidates], names = new Set(family.map(l => l.name));
|
|
13
|
+
if (names.size !== family.length || family.some(l => !l.name))
|
|
14
|
+
return { status: 'inconclusive', reason: 'duplicate or empty law name' };
|
|
15
|
+
try {
|
|
16
|
+
return withWall(searchWall(ms), () => counted(fullRate, () => {
|
|
17
|
+
const until = clock() + ms;
|
|
18
|
+
return withDeadline(until, () => {
|
|
19
|
+
const closure = admitCountedFamily(machine, publicLaws, family, new Set(candidates), until);
|
|
20
|
+
if (!closure.proven || !closure.proof)
|
|
21
|
+
return { status: 'inconclusive', reason: closure.why ?? 'counted family not proven' };
|
|
22
|
+
if (closure.m !== machine || !publicLaws.every(l => closure.laws.includes(l)) || closure.laws.some(l => !family.includes(l)) || !checkCountedLaws(closure.m, closure.laws, closure.proof))
|
|
23
|
+
return { status: 'inconclusive', reason: 'counted family custody or kernel check failed' };
|
|
24
|
+
return { status: 'checked', closure, kept: candidates.filter(l => closure.laws.includes(l)), dropped: candidates.filter(l => !closure.laws.includes(l)) };
|
|
25
|
+
});
|
|
26
|
+
}, true));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { status: 'inconclusive', reason: error instanceof Error ? error.message : String(error) };
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/core/counts.js
CHANGED
|
@@ -1708,6 +1708,7 @@ export function countedAttempts(m, caller, support, until, structured = true, fo
|
|
|
1708
1708
|
// instance by the reads it names, a pick by its read and terms, so the choice outlives the goal's rebuilds)
|
|
1709
1709
|
const chosen = new Set();
|
|
1710
1710
|
const selections = new Map();
|
|
1711
|
+
const reservationRenamings = new Map();
|
|
1711
1712
|
const poolCache = new Map();
|
|
1712
1713
|
const memberSources = new Map();
|
|
1713
1714
|
// Demand-driven ranges (Fable b89dd77a / Lane B): retain a goal's demand
|
|
@@ -1762,7 +1763,13 @@ export function countedAttempts(m, caller, support, until, structured = true, fo
|
|
|
1762
1763
|
selection = { chosen: new Set(ids(pick)), cap: Math.min(10, pick.insts.length + 2), previous: pick, decls, reserve: reservationState(goal, [m, ls, goal], pool), stable: stableState([m, ls, goal]) };
|
|
1763
1764
|
selections.set(goal.name, selection);
|
|
1764
1765
|
}
|
|
1765
|
-
const
|
|
1766
|
+
const reserved = reservePool(goal, decls, pool0, selection.previous, selection.decls, selection.chosen, selection.reserve, pool, reservation);
|
|
1767
|
+
const full = reserved.full;
|
|
1768
|
+
if (reserved.record.renamed.length) {
|
|
1769
|
+
const prior = reservationRenamings.get(goal.name) ?? [];
|
|
1770
|
+
reservationRenamings.set(goal.name, [...prior, ...reserved.record.renamed]);
|
|
1771
|
+
countsDump.on?.({ phase: 'reservation-alpha', law: law.name, goal: goal.name, renamings: reserved.record.renamed });
|
|
1772
|
+
}
|
|
1766
1773
|
const keys = ids(full), lazyRoom = selection.chosen.size < selection.cap;
|
|
1767
1774
|
const view = chosenView(full, selection.chosen, selection.cap);
|
|
1768
1775
|
const c = withRanges(goal, decls, selectedCertificate(goal, decls, view, selection.stable, lazyRoom), full.reads);
|
|
@@ -2054,7 +2061,7 @@ export function countedAttempts(m, caller, support, until, structured = true, fo
|
|
|
2054
2061
|
return refuted(gg, o.witness, at);
|
|
2055
2062
|
if (!o || !('tree' in o))
|
|
2056
2063
|
return { stuck: gg ? o.stuck ?? '' : '' };
|
|
2057
|
-
certs[goal.name] = { reads: c.reads, insts: c.insts, tree: o.tree, ...('picks' in c && c.picks.length ? { picks: c.picks } : {}) };
|
|
2064
|
+
certs[goal.name] = { ...(reservationRenamings.get(goal.name)?.length ? { proposalProvenance: { kind: 'reservation-alpha', renamings: reservationRenamings.get(goal.name) } } : {}), reads: c.reads, insts: c.insts, tree: o.tree, ...('picks' in c && c.picks.length ? { picks: c.picks } : {}) };
|
|
2058
2065
|
}
|
|
2059
2066
|
if (!again)
|
|
2060
2067
|
return { proof: { instances: at, certs } };
|
package/dist/core/dsl.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TranslationFields } from './source-check.js';
|
|
2
2
|
import { type C, type E, type Fn, type Law, type Recurrence, type Machine, type Rand, type Request, type State, type Sum } from './machine.js';
|
|
3
|
-
import { type Fold, type Goal, type Liveness, type Loop, type Recur, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
4
|
-
import { type Report } from '../kernel/prove.js';
|
|
3
|
+
import { type Fold, type Ghosted, type Goal, type Liveness, type Loop, type Recur, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
4
|
+
import { type Report, type ModelRoundPolicy } from '../kernel/prove.js';
|
|
5
5
|
import { type WorkAmount } from './work-amount.js';
|
|
6
6
|
import { findRing } from './live.js';
|
|
7
7
|
export type TermLike = Term | number;
|
|
@@ -952,6 +952,18 @@ export type Found = {
|
|
|
952
952
|
facts?: string[];
|
|
953
953
|
rank?: string;
|
|
954
954
|
};
|
|
955
|
+
export type CandidateSeedAudit = {
|
|
956
|
+
status: 'checked' | 'inconclusive';
|
|
957
|
+
kind?: 'usual' | 'counted';
|
|
958
|
+
kept: string[];
|
|
959
|
+
dropped: {
|
|
960
|
+
name: string;
|
|
961
|
+
goal?: string;
|
|
962
|
+
stuck?: 'sat';
|
|
963
|
+
reason?: string;
|
|
964
|
+
}[];
|
|
965
|
+
reason?: string;
|
|
966
|
+
};
|
|
955
967
|
export type ProveOptions = {
|
|
956
968
|
search?: boolean | {
|
|
957
969
|
ms?: number;
|
|
@@ -960,6 +972,15 @@ export type ProveOptions = {
|
|
|
960
972
|
};
|
|
961
973
|
from?: 'reachable' | 'any';
|
|
962
974
|
fast?: boolean;
|
|
975
|
+
modelRounds?: ModelRoundPolicy;
|
|
976
|
+
candidateSeeds?: {
|
|
977
|
+
kind?: 'usual' | 'counted';
|
|
978
|
+
laws: Law[];
|
|
979
|
+
counts?: NonNullable<Machine['counts']>;
|
|
980
|
+
witnesses?: Record<string, import('./machine.ts').SomeWitness>;
|
|
981
|
+
ghosts?: Pick<Ghosted, 'vars' | 'maps'>;
|
|
982
|
+
report?: (audit: CandidateSeedAudit) => void;
|
|
983
|
+
};
|
|
963
984
|
};
|
|
964
985
|
export declare class Unproven extends Error {
|
|
965
986
|
readonly verdict: Verdict;
|
package/dist/core/dsl.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFrom, retainCounted, publishProof, withPublicRule } from "./proof-output.js";
|
|
1
2
|
import { searchNow as countedSearchNow } from "./wall.js";
|
|
2
3
|
// Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
|
|
3
4
|
// misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
|
|
@@ -17,13 +18,15 @@ import { searchNow as countedSearchNow } from "./wall.js";
|
|
|
17
18
|
// A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
|
|
18
19
|
// both runtimes do.
|
|
19
20
|
import { candidates, cone, searchCounted } from "./counts.js";
|
|
21
|
+
import { proveCandidateSeeds } from "./candidate-seeds.js";
|
|
22
|
+
import { proveCountedCandidateSeeds } from "./counted-candidate-seeds.js";
|
|
20
23
|
import { inheritSource, translationVerdict } from "./source-check.js";
|
|
21
24
|
import { env as knobs } from "./solver.js";
|
|
22
25
|
import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, hasFinite, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
|
|
23
26
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
24
27
|
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
25
28
|
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
26
|
-
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withWall } from "../kernel/prove.js";
|
|
29
|
+
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withModelRounds, withWall } from "../kernel/prove.js";
|
|
27
30
|
import { WallExpired, checkWall, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
28
31
|
import { completeWorkProfile } from "./work-profile.js";
|
|
29
32
|
import { workLedger } from "./work-admission.js";
|
|
@@ -3277,7 +3280,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
3277
3280
|
return undefined;
|
|
3278
3281
|
}
|
|
3279
3282
|
// The kernel's report as a verdict: its first goal left unproven, with its counterexample and why.
|
|
3280
|
-
export const verdictOf = (out) => ({ proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) });
|
|
3283
|
+
export const verdictOf = (out) => retainFrom(({ proven: out.proven, checked: out.checked, ...(out.failed ? { goal: out.failed.goal, stuck: out.failed.stuck, ...(out.failed.witness ? { witness: out.failed.witness } : {}), ...(out.failed.why ? { why: out.failed.why } : {}) } : {}) }), [out]);
|
|
3281
3284
|
const refutedVerdict = (out) => ({ proven: false, checked: false, goal: out.goal, stuck: 'sat', witness: out.witness, ...(out.run ? { run: out.run } : {}) });
|
|
3282
3285
|
// The divisors some laws read (modBy, divBy), noted on the rule so its machine declares them: a law may come from
|
|
3283
3286
|
// another instance of the same rule (a factory called twice).
|
|
@@ -3320,8 +3323,11 @@ function workVerdict(opts, supported, run) {
|
|
|
3320
3323
|
}
|
|
3321
3324
|
}
|
|
3322
3325
|
export function proveRule(r, laws, opts = {}) {
|
|
3323
|
-
|
|
3324
|
-
|
|
3326
|
+
return withModelRounds(opts.modelRounds, () => withPublicRule(outermost => {
|
|
3327
|
+
const captureMachine = r.machine, hasCounts = !!Object.keys(captureMachine.counts ?? {}).length;
|
|
3328
|
+
const result = workVerdict(opts, hasCounts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
|
|
3329
|
+
return outermost ? publishProof(result, captureMachine, laws) : result;
|
|
3330
|
+
}));
|
|
3325
3331
|
}
|
|
3326
3332
|
function proveRuleWall(r, laws, opts) {
|
|
3327
3333
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
@@ -3340,11 +3346,36 @@ function proveRuleWall(r, laws, opts) {
|
|
|
3340
3346
|
};
|
|
3341
3347
|
// One absolute wall for setup, sampling, generation and proof, not a fresh
|
|
3342
3348
|
// allowance for each phase. Nested callers can only shorten it.
|
|
3343
|
-
|
|
3349
|
+
const result = ms === undefined ? run() : withWall(searchWall(ms), run);
|
|
3350
|
+
return retainFrom(translationVerdict(r, laws, result), [result]);
|
|
3344
3351
|
}
|
|
3345
3352
|
function proveRuleIn(r, laws, opts) {
|
|
3346
|
-
r = r.withSumsOf(laws);
|
|
3353
|
+
r = r.withSumsOf(laws, opts.candidateSeeds?.laws ?? []);
|
|
3347
3354
|
noting(r, laws);
|
|
3355
|
+
if (opts.candidateSeeds) {
|
|
3356
|
+
if (opts.search === false || opts.from === 'any')
|
|
3357
|
+
throw Error('candidate seeds require reachable-state search');
|
|
3358
|
+
const machine = r.machine, extraCounts = opts.candidateSeeds.counts ?? {};
|
|
3359
|
+
if (opts.candidateSeeds.kind === 'counted' || Object.keys(machine.counts ?? {}).length || Object.keys(extraCounts).length) {
|
|
3360
|
+
const reserved = new Set([...Object.keys(machine.maps ?? {}), ...Object.keys(machine.counts ?? {}), ...Object.keys(machine.state), ...Object.keys(machine.fns ?? {}), ...(machine.inputMaps ?? []), ...machine.params, ...machine.inputs]);
|
|
3361
|
+
if (Object.keys(extraCounts).some(n => reserved.has(n)))
|
|
3362
|
+
throw Error('candidate count declaration must not override the source');
|
|
3363
|
+
const producer = { ...machine, counts: { ...machine.counts, ...extraCounts } };
|
|
3364
|
+
const seeded = proveCountedCandidateSeeds(producer, withKinds(r, laws), opts.candidateSeeds.laws, typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
3365
|
+
opts.candidateSeeds.report?.({ status: seeded.status, kind: 'counted', kept: seeded.status === 'checked' ? seeded.kept.map(l => l.name) : [],
|
|
3366
|
+
dropped: seeded.status === 'checked' ? seeded.dropped.map(l => ({ name: l.name, reason: 'not retained by counted admission' })) : [],
|
|
3367
|
+
...(seeded.status === 'inconclusive' ? { reason: seeded.reason } : {}) });
|
|
3368
|
+
if (seeded.status === 'checked')
|
|
3369
|
+
return retainCounted({ proven: true, checked: true, found: { laws: seeded.closure.laws.map(l => ({ text: l.name })) } }, seeded.closure);
|
|
3370
|
+
}
|
|
3371
|
+
else {
|
|
3372
|
+
const seeded = proveCandidateSeeds(machine, withKinds(r, laws), opts.candidateSeeds.laws, opts.candidateSeeds.witnesses, opts.candidateSeeds.ghosts);
|
|
3373
|
+
opts.candidateSeeds.report?.({ status: seeded.status, kept: seeded.kept.map(l => l.name), dropped: seeded.dropped,
|
|
3374
|
+
...(seeded.status === 'inconclusive' ? { reason: seeded.reason } : {}) });
|
|
3375
|
+
if (seeded.status === 'checked')
|
|
3376
|
+
return retainFrom(verdictOf(seeded.closure), [seeded.closure], { kind: 'inference', original: machine, laws });
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3348
3379
|
const refuted = refuteByRuns(r, laws);
|
|
3349
3380
|
checkWorkEndpoint('refutation result');
|
|
3350
3381
|
// A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
|
|
@@ -3355,7 +3386,7 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3355
3386
|
// A rule with counts: its goals are the counted ones (core/counts.ts searches them; the kernel checks the set).
|
|
3356
3387
|
if (r.machine.counts && Object.keys(r.machine.counts).length) {
|
|
3357
3388
|
const c = searchCounted(r.machine, withKinds(r, laws), typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
3358
|
-
return { proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } };
|
|
3389
|
+
return retainCounted({ proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } }, c);
|
|
3359
3390
|
}
|
|
3360
3391
|
// (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
|
|
3361
3392
|
// each by its own budget, so the search would never start)
|
|
@@ -3370,6 +3401,8 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3370
3401
|
const out = ms === undefined ? given() : withStageWall(countedSearchNow() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withStageDeadline(clock() + ms / share, given, () => undefined)), () => undefined);
|
|
3371
3402
|
const v = out ? { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
|
|
3372
3403
|
: { proven: false, checked: false, stuck: 'unknown' };
|
|
3404
|
+
if (out)
|
|
3405
|
+
retainFrom(v, [out]);
|
|
3373
3406
|
return searched(r, laws, [], v, opts);
|
|
3374
3407
|
}
|
|
3375
3408
|
export function proveSteps(r, laws, stepLaws, opts = {}) {
|
|
@@ -3500,7 +3533,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3500
3533
|
if (lists.length || fns.some(([, d]) => recurOf(d))) {
|
|
3501
3534
|
const d = withStageDeadline(until, () => discover(r, laws, stepLaws, v), () => undefined);
|
|
3502
3535
|
if (d?.verdict.proven && d.verdict.checked)
|
|
3503
|
-
return { ...d.verdict, found: { lemmas: d.found } };
|
|
3536
|
+
return retainFrom({ ...d.verdict, found: { lemmas: d.found } }, [d.verdict]);
|
|
3504
3537
|
if (d && Object.keys(d.found).length)
|
|
3505
3538
|
(rule = d.rule, lemmas = d.found);
|
|
3506
3539
|
}
|
|
@@ -3524,7 +3557,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3524
3557
|
// (counted, as the laws' own search: the same verdict on any machine)
|
|
3525
3558
|
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withStageDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given)), () => undefined), true);
|
|
3526
3559
|
if (out?.proven && out.checked)
|
|
3527
|
-
return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
|
|
3560
|
+
return retainFrom({ proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) }, [out]);
|
|
3528
3561
|
}
|
|
3529
3562
|
}
|
|
3530
3563
|
let ms = until - clock() - tail;
|
|
@@ -3543,7 +3576,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3543
3576
|
console.error(`exists: cone failed: ${String(e.stack ?? e).slice(0, 600)}`);
|
|
3544
3577
|
}
|
|
3545
3578
|
if (c)
|
|
3546
|
-
return { ...c, found: { ...c.found, ...(lemmas ? { lemmas } : {}) } };
|
|
3579
|
+
return retainFrom({ ...c, found: { ...c.found, ...(lemmas ? { lemmas } : {}) } }, [c]);
|
|
3547
3580
|
if ((ms = until - clock() - tail) < 500)
|
|
3548
3581
|
return v;
|
|
3549
3582
|
}
|
|
@@ -3573,11 +3606,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3573
3606
|
console.error(`exists: back: plain ${plain ? `${plain.proven} ${plain.checked}` : 'none'}, machine ${sameMachine(over.machine, ghostedMachine(G))}`);
|
|
3574
3607
|
if (plain?.proven && plain.checked && sameMachine(over.machine, ghostedMachine(G))
|
|
3575
3608
|
&& 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); }))
|
|
3576
|
-
return { proven: true, checked: true, witnesses: sk.witnesses };
|
|
3609
|
+
return retainFrom({ proven: true, checked: true, witnesses: sk.witnesses }, [plain], { kind: 'skolem', original: G.orig, laws, G, plains: sk.plains, family: ls });
|
|
3577
3610
|
// (proveSome over the original: the found laws that read no ghost map)
|
|
3578
3611
|
const own = found.filter(f => Object.keys(sk.maps).every(mp => !JSON.stringify(f.law.holds).includes(`"map":${JSON.stringify(mp)}`)));
|
|
3579
3612
|
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) });
|
|
3580
|
-
return { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
3613
|
+
return retainFrom({ ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }, [out]);
|
|
3581
3614
|
};
|
|
3582
3615
|
// (the plain law's candidate supports, exists.ts's ghostSupports: Houdini within half of what is left, each with the
|
|
3583
3616
|
// rest assumed, the failing dropped, until none fails; then the set through `back`, the ∃ verdict as the search's)
|
|
@@ -3623,7 +3656,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3623
3656
|
console.error(`exists: ghost supports set: ${b.proven ? 'proven' : `${b.goal} ${b.stuck} ${b.why ?? ''}`}`);
|
|
3624
3657
|
if (b.proven && b.checked) {
|
|
3625
3658
|
const found = keep.map(law => ({ law, text: law.name }));
|
|
3626
|
-
return { ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3659
|
+
return retainFrom({ ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, [b]);
|
|
3627
3660
|
}
|
|
3628
3661
|
break;
|
|
3629
3662
|
}
|
|
@@ -3642,7 +3675,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3642
3675
|
void _s2;
|
|
3643
3676
|
const b = back(summed, found);
|
|
3644
3677
|
if (!sk || (b.proven && b.checked))
|
|
3645
|
-
return { ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3678
|
+
return retainFrom({ ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, sk ? [inf2, b] : [inf2]);
|
|
3646
3679
|
}
|
|
3647
3680
|
}
|
|
3648
3681
|
// (a step law's ghost: at most 10 s of it, as its goals cost more than the laws')
|
|
@@ -3656,7 +3689,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3656
3689
|
const b = back(target, found);
|
|
3657
3690
|
if (sk && !(b.proven && b.checked))
|
|
3658
3691
|
return { ...v, ...b, why: [v.why, 'the set found over the ghost maps is not proven with the laws as stated'].filter(Boolean).join('; ') };
|
|
3659
|
-
return { ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3692
|
+
return retainFrom({ ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) }, sk ? [inf, b] : [inf]);
|
|
3660
3693
|
}
|
|
3661
3694
|
// A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
|
|
3662
3695
|
// then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
|
|
@@ -3695,7 +3728,7 @@ function someCone(r, laws0, ms) {
|
|
|
3695
3728
|
if (clock() > until)
|
|
3696
3729
|
return undefined;
|
|
3697
3730
|
const v = verdictOf(proveSome(m, [...laws, ...kept.filter(c => !laws.some(l => l.name === c.name))]));
|
|
3698
|
-
return v.proven && v.checked ? { ...v, found: { laws: kept.map(l => ({ law: l, text: l.name })) }, ...withAssumes(kept.map(l => ({ text: l.name }))) } : undefined;
|
|
3731
|
+
return v.proven && v.checked ? retainFrom({ ...v, found: { laws: kept.map(l => ({ law: l, text: l.name })) }, ...withAssumes(kept.map(l => ({ text: l.name }))) }, [v]) : undefined;
|
|
3699
3732
|
}
|
|
3700
3733
|
// What a verdict proven with these found laws rests on: the states reachable from init (each found law is proven so).
|
|
3701
3734
|
const reachableBy = (found) => ({ states: 'reachable', laws: found.map(f => f.text) });
|
package/dist/core/exists.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFrom } from "./proof-output.js";
|
|
1
2
|
import { traceNow as countedTraceNow, BudgetExpired } from "./wall.js";
|
|
2
3
|
import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
|
|
3
4
|
import { requestQuotient } from "./request-quotient.js";
|
|
@@ -1364,7 +1365,7 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
1364
1365
|
}
|
|
1365
1366
|
for (let pass = 1;; pass++) {
|
|
1366
1367
|
const { machine, laws: plain, ghosts } = current(), t0 = countedTraceNow();
|
|
1367
|
-
const out = (opts.whole ?? proveLaws)(machine, plain), done = { ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) };
|
|
1368
|
+
const out = (opts.whole ?? proveLaws)(machine, plain), done = retainFrom({ ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) }, [out], { kind: 'witness', original: m, laws, machine, plain, ghosts, plans, cases });
|
|
1368
1369
|
if (log)
|
|
1369
1370
|
console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
|
|
1370
1371
|
const j = out.proven || !out.failed || pass > 8 ? undefined : [...plans.keys()].find(k => out.failed.goal.startsWith(`${laws[k].name} @`));
|
package/dist/core/field-laws.js
CHANGED
|
@@ -104,16 +104,23 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
104
104
|
const old = rows.get(o.map);
|
|
105
105
|
rows.set(o.map, old === undefined || old === key.a.k ? key.a.k : 0);
|
|
106
106
|
});
|
|
107
|
+
// Zero is reserved for ambiguous packed strides; -1 denotes a native tuple.
|
|
108
|
+
for (const [map, sorts] of Object.entries(m.relations ?? {}))
|
|
109
|
+
if (sorts.length === 2 && sorts[0] === sorts[1])
|
|
110
|
+
rows.set(map, -1);
|
|
107
111
|
const agrees = [];
|
|
108
112
|
for (const [map, base] of rows)
|
|
109
113
|
if (base)
|
|
110
114
|
for (let i = 0; i < fs.length; i++)
|
|
111
115
|
for (let j = i + 1; j < fs.length; j++) {
|
|
112
|
-
const f = fs[i], g = fs[j], cell = (row) => get(map, plus(times(base, row), c));
|
|
116
|
+
const f = fs[i], g = fs[j], cell = (row) => get(map, base === -1 ? tuple([row, c]) : plus(times(base, row), c));
|
|
113
117
|
const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)));
|
|
114
118
|
const law = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
// Tuple agreement was already emitted above; use that same stronger law.
|
|
120
|
+
const existing = base === -1 ? out.find(l => l.name === law.name) : undefined;
|
|
121
|
+
if (!existing)
|
|
122
|
+
out.push(law);
|
|
123
|
+
agrees.push({ map, f, g, law: existing ?? law });
|
|
117
124
|
}
|
|
118
125
|
if (!loaded)
|
|
119
126
|
return out;
|
|
@@ -193,7 +200,18 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
193
200
|
}
|
|
194
201
|
const here = t.op === 'and' ? [...positive, ...atoms(t)] : positive;
|
|
195
202
|
const key = t.key, row = key?.b, input = row?.a?.name, src = t.map;
|
|
196
|
-
if (t.op === 'get' && src !== map && src in maps && !rows.has(src)
|
|
203
|
+
if (base === -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src)) {
|
|
204
|
+
const first = { op: 'proj', k: 0, a: x(w.each) }, second = { op: 'proj', k: 1, a: x(w.each) };
|
|
205
|
+
if (sameTerm(t.key, second))
|
|
206
|
+
for (const input of m.inputs)
|
|
207
|
+
if (here.some(q => sameTerm(q, same(first, x(input))) || sameTerm(q, same(x(input), first))))
|
|
208
|
+
for (const q of here)
|
|
209
|
+
if (q.op === 'flag') {
|
|
210
|
+
const flag = q.name;
|
|
211
|
+
loads.set(`${src}:${input}:${flag}`, { src, input, flag });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (base !== -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src) && key?.op === 'sub' && key.a.op === 'var' && key.a.name === w.each
|
|
197
215
|
&& row?.op === 'mul' && row.k === base && row.a.op === 'var' && input !== undefined && m.inputs.includes(input)
|
|
198
216
|
&& here.some(q => sameTerm(q, atMost(times(base, x(input)), x(w.each))))
|
|
199
217
|
&& here.some(q => sameTerm(q, less(x(w.each), plus(times(base, x(input)), n(base))))))
|
|
@@ -206,7 +224,7 @@ export function fieldLaws(m, composed = true, loaded = true) {
|
|
|
206
224
|
visit(u, here);
|
|
207
225
|
};
|
|
208
226
|
visit(w.value, []);
|
|
209
|
-
const cell = (r) => get(map, plus(times(base, r), c));
|
|
227
|
+
const cell = (r) => get(map, base === -1 ? tuple([r, c]) : plus(times(base, r), c));
|
|
210
228
|
for (const { src, input, flag } of loads.values())
|
|
211
229
|
for (const [mk, mw] of Object.entries(m.step.maps ?? {})) {
|
|
212
230
|
if ('each' in mw || mw.key.op !== 'var' || mw.key.name !== input || !(mk in maps) || rows.has(mk) || mk === src)
|
package/dist/core/infer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainFrom } from "./proof-output.js";
|
|
1
2
|
import { searchNow as countedSearchNow, checkWorkEndpoint } from "./wall.js";
|
|
2
3
|
// Invariants nobody wrote: a law that holds but isn't inductive, proven with laws the search finds. Nothing here is
|
|
3
4
|
// trusted; what it finds is proven by the kernel with the rule's own laws, as laws of the same rule.
|
|
@@ -1104,7 +1105,7 @@ function inferLawsSearchIn(target, laws, stepLaws, opts) {
|
|
|
1104
1105
|
const first = opts.first ?? (refuted?.run ? { proven: false, checked: false, stuck: 'sat', ...refuted }
|
|
1105
1106
|
: opts.cubes ? { proven: false, checked: false } : prove(laws));
|
|
1106
1107
|
if ((first.proven && first.checked) || first.run)
|
|
1107
|
-
return { ...first, found: [], stats: stats(0, 0, 0) };
|
|
1108
|
+
return retainFrom({ ...first, found: [], stats: stats(0, 0, 0) }, [first]);
|
|
1108
1109
|
// --- runs ------------------------------------------------------------------------------------------------------------
|
|
1109
1110
|
const run = interpret(m), stepSample = sampleStep(m, run), rand = seeded(17), kinds = rule ? rule.kindsOfState() : [];
|
|
1110
1111
|
const given = rule ? [...rule.kindLaws().filter(k => !laws.some(l => l.name === k.name)), ...laws] : laws;
|
|
@@ -2729,7 +2730,7 @@ function inferLawsSearchIn(target, laws, stepLaws, opts) {
|
|
|
2729
2730
|
return { used, g: g };
|
|
2730
2731
|
};
|
|
2731
2732
|
let at = inst;
|
|
2732
|
-
const { result } = withModels(mm, ls, inst, i2 => (at = i2, goalOf(i2)), gs => ask(gs, at), x => (mapNames.length && x.stuck === 'sat' && x.witness ? { goal: x.g, w: x.witness } : undefined), x => !!x.used || x.stuck === 'sat');
|
|
2733
|
+
const { result } = withModels(mm, ls, inst, i2 => (at = i2, goalOf(i2)), gs => ask(gs, at), x => (mapNames.length && x.stuck === 'sat' && x.witness ? { goal: x.g, w: x.witness } : undefined), x => !!x.used || (x.stuck === 'sat' && !!x.witness), (x, _why) => ({ g: x.g, stuck: 'unknown' }));
|
|
2733
2734
|
return result.used ? { used: result.used } : { stuck: result.stuck, witness: result.witness };
|
|
2734
2735
|
};
|
|
2735
2736
|
const stateOf = (w) => {
|
|
@@ -5337,5 +5338,5 @@ function inferLawsSearchIn(target, laws, stepLaws, opts) {
|
|
|
5337
5338
|
if (kept.length)
|
|
5338
5339
|
rule?.dividesBy(...kept);
|
|
5339
5340
|
trace('end', { proven: true, stopped: stop(), found: chosen.map(f => textOf(f)).join('; ') });
|
|
5340
|
-
return { ...last, found: [...chosen.map(f => { const law = lawFor(f), text = law.name, source = sourceOf(f, text); return { law, text, ...(source ? { source } : {}) }; }), ...(enumProof ? enumSome : []).map(law => ({ law, text: law.name }))], stats: stats(samples.length, forms.length, alive.length) };
|
|
5341
|
+
return retainFrom({ ...last, found: [...chosen.map(f => { const law = lawFor(f), text = law.name, source = sourceOf(f, text); return { law, text, ...(source ? { source } : {}) }; }), ...(enumProof ? enumSome : []).map(law => ({ law, text: law.name }))], stats: stats(samples.length, forms.length, alive.length) }, [last], { kind: 'inference', original: m, laws });
|
|
5341
5342
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface LiftArguments {
|
|
2
|
+
capsule: string;
|
|
3
|
+
source: string;
|
|
4
|
+
out?: string;
|
|
5
|
+
sha256?: string;
|
|
6
|
+
emitOnly: boolean;
|
|
7
|
+
json: boolean;
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseLiftArguments(argv: string[]): LiftArguments;
|
|
11
|
+
export declare function liftMain(argv: string[]): Promise<number>;
|