gdp-wired 0.21.0 → 0.23.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 +16 -1
- package/dist/core/bmc.d.ts +38 -0
- package/dist/core/bmc.js +137 -0
- package/dist/core/check.d.ts +1 -1
- package/dist/core/check.js +19 -6
- package/dist/core/cycles.d.ts +15 -0
- package/dist/core/cycles.js +446 -8
- package/dist/core/cyclic.d.ts +6 -1
- package/dist/core/cyclic.js +13 -1
- package/dist/core/data.d.ts +17 -1
- package/dist/core/data.js +637 -97
- package/dist/core/dsl.d.ts +10 -1
- package/dist/core/dsl.js +47 -12
- package/dist/core/infer.js +518 -5
- package/dist/core/nonterm.d.ts +34 -0
- package/dist/core/nonterm.js +610 -0
- package/dist/core/q.d.ts +17 -0
- package/dist/core/q.js +52 -0
- package/dist/core/rationals.d.ts +112 -0
- package/dist/core/rationals.js +281 -0
- package/dist/core/relation.d.ts +28 -0
- package/dist/core/relation.js +480 -0
- package/dist/core/solver.d.ts +5 -2
- package/dist/core/solver.js +65 -20
- package/dist/core/transfer.d.ts +3 -3
- package/dist/core/transfer.js +77 -42
- package/dist/kernel/cdcl.d.ts +43 -0
- package/dist/kernel/cdcl.js +564 -0
- package/dist/kernel/kernel.d.ts +91 -0
- package/dist/kernel/kernel.js +310 -0
- package/dist/kernel/prove.d.ts +20 -1
- package/dist/kernel/prove.js +119 -44
- package/dist/kernel/qprove.d.ts +18 -0
- package/dist/kernel/qprove.js +157 -0
- package/dist/kernel/reader.d.ts +79 -0
- package/dist/kernel/reader.js +539 -0
- package/dist/kernel/simplex.d.ts +36 -0
- package/dist/kernel/simplex.js +259 -0
- package/dist/lean-kernel/emit.d.ts +19 -1
- package/dist/lean-kernel/emit.js +71 -3
- package/dist/lean-kernel/library.js +2 -0
- package/dist/lean-kernel/qlean.d.ts +26 -0
- package/dist/lean-kernel/qlean.js +105 -0
- package/package.json +6 -2
package/dist/core/dsl.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type C, type E, type Law, type Recurrence, type Machine, type Request, type State } from './machine.js';
|
|
2
|
-
import { type Fold, type Goal, type Liveness, type Loop, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
2
|
+
import { type Fold, type Goal, type Liveness, type Loop, type Recur, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
3
3
|
export type TermLike = Term | number;
|
|
4
4
|
export declare const termOf: (t: TermLike) => E;
|
|
5
5
|
export declare class Term {
|
|
@@ -869,6 +869,15 @@ export declare function crossCheckDecision(d: Decision, opts?: {
|
|
|
869
869
|
export declare const proveLoop: (l: LoopRule<Obj, Obj, Obj>, laws: Law[], opts?: {
|
|
870
870
|
ms?: number;
|
|
871
871
|
}) => Verdict;
|
|
872
|
+
export type NeverEnds = Verdict & {
|
|
873
|
+
recur?: Recur;
|
|
874
|
+
loop?: Loop;
|
|
875
|
+
by?: string;
|
|
876
|
+
};
|
|
877
|
+
export declare function proveNeverEnds<P extends Obj, I extends Obj, S extends Obj>(l: LoopRule<P, I, S>, opts?: {
|
|
878
|
+
ms?: number;
|
|
879
|
+
from?: (p: P) => Cond;
|
|
880
|
+
}): NeverEnds;
|
|
872
881
|
export type TreeValue<I> = {
|
|
873
882
|
leaf: I;
|
|
874
883
|
} | {
|
package/dist/core/dsl.js
CHANGED
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
import { carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, withArithmetic } from "./machine.js";
|
|
19
19
|
import { allowed, keysOf, requestEnv, watch } from "./watch.js";
|
|
20
20
|
import { someHolds, substVars } from "./exists.js";
|
|
21
|
-
import { check, foldObligations, loopObligations } from "../kernel/kernel.js";
|
|
22
|
-
import { factsFor, grow, proveLaws, proveLiveness, proveStepLaws, usualProof, withDeadline } from "../kernel/prove.js";
|
|
21
|
+
import { check, checkRecur, foldObligations, loopObligations } from "../kernel/kernel.js";
|
|
22
|
+
import { certLoop, factsFor, grow, proveLaws, proveLiveness, proveStepLaws, usualProof, withDeadline } from "../kernel/prove.js";
|
|
23
23
|
import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
|
|
24
24
|
import { discover } from "./discover.js";
|
|
25
25
|
import { inferLaws } from "./infer.js";
|
|
26
|
+
import { findBoundedRun } from "./bmc.js";
|
|
26
27
|
import { cycleLemmas, findLeadsTo, findRank } from "./cycles.js";
|
|
28
|
+
import { findNeverEnds } from "./nonterm.js";
|
|
27
29
|
// --- terms and conditions -------------------------------------------------------------------------------------------
|
|
28
30
|
const naturalConst = (v) => {
|
|
29
31
|
if (!Number.isSafeInteger(v) || v < 0)
|
|
@@ -2642,6 +2644,8 @@ const withKinds = (r, laws) => [...r.kindLaws().filter(k => !laws.some(l => l.na
|
|
|
2642
2644
|
// interpreter took. A rule that reads functions is skipped: the kernel knows them only by their facts (a recurrence's
|
|
2643
2645
|
// induction machine reads the function it proves things about), so a run computing them proves nothing about the goal.
|
|
2644
2646
|
const refuteBudget = { trials: 60, depth: 6, bound: 3, ms: 150 };
|
|
2647
|
+
// A request as a run's trace shows it: each map it carries as an object of its cells.
|
|
2648
|
+
const shownRequest = (input) => Object.fromEntries(Object.entries(input).map(([n, x]) => [n, typeof x === 'number' ? x : Object.fromEntries(x)]));
|
|
2645
2649
|
// The search's own runs, before it looks for what the laws need: deeper and wider, from another seed.
|
|
2646
2650
|
const deeperBudget = { trials: 600, depth: 24, bound: 8, ms: 1500, seed: 29 };
|
|
2647
2651
|
function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
@@ -2649,8 +2653,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
2649
2653
|
// Division by a constant is a function too, but its facts fix its value, so a run computing it is a run of the rule.
|
|
2650
2654
|
if (Object.keys(m.fns ?? {}).some(f => !isArithmetic(f)) || m.facts?.some(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':')))))
|
|
2651
2655
|
return undefined;
|
|
2652
|
-
const run = interpret(m), rand = seeded(budget.seed ?? 13), until = performance.now() + budget.ms, bound = budget.bound;
|
|
2653
|
-
const shown = (input) => Object.fromEntries(Object.entries(input).map(([n, x]) => [n, typeof x === 'number' ? x : Object.fromEntries(x)]));
|
|
2656
|
+
const run = interpret(m), rand = seeded(budget.seed ?? 13), until = performance.now() + budget.ms, bound = budget.bound, shown = shownRequest;
|
|
2654
2657
|
try {
|
|
2655
2658
|
for (let trial = 0; trial < budget.trials && performance.now() < until; trial++) {
|
|
2656
2659
|
const params = r.randomParams(rand, bound);
|
|
@@ -2719,8 +2722,11 @@ const noting = (r, ...xs) => { const ks = divisorsIn(xs); if (ks.size)
|
|
|
2719
2722
|
export function proveRule(r, laws, opts = {}) {
|
|
2720
2723
|
noting(r, laws);
|
|
2721
2724
|
const refuted = refuteByRuns(r, laws);
|
|
2725
|
+
// 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
|
|
2726
|
+
// at), is a counterexample to induction: the laws may still hold, so the search goes on from it, as from the kernel's.
|
|
2727
|
+
// (A step law broken so is refused, proveSteps below: it holds from every state the laws allow, reached or not.)
|
|
2722
2728
|
if (refuted)
|
|
2723
|
-
return refutedVerdict(refuted);
|
|
2729
|
+
return refuted.run ? refutedVerdict(refuted) : searched(r, laws, [], refutedVerdict(refuted), opts);
|
|
2724
2730
|
const out = proveLaws(r.machine, withKinds(r, laws));
|
|
2725
2731
|
const v = { 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.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
2726
2732
|
return searched(r, laws, [], v, opts);
|
|
@@ -2744,6 +2750,17 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
2744
2750
|
if (deeper?.run)
|
|
2745
2751
|
return refutedVerdict(deeper);
|
|
2746
2752
|
const until = performance.now() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
|
|
2753
|
+
// Bounded runs (core/bmc.ts): a law broken k steps from the start, a model of the kernel's k-step goal, the run taken
|
|
2754
|
+
// by the interpreter. The shallow depths first, within a fortieth of the search's budget (at most 250 ms, counted and
|
|
2755
|
+
// in wall time); the deeper ones only where the invariant search finds nothing, within the tenth (at most a second)
|
|
2756
|
+
// kept from it, so a law the search proves costs no more than the shallow depths.
|
|
2757
|
+
const total = until - performance.now(), tail = Math.min(1000, total / 10);
|
|
2758
|
+
let reached = 0;
|
|
2759
|
+
const bounded = (ms, from) => findBoundedRun(r.machine, laws, { ms, wall: performance.now() + ms, from, progress: k => { reached = k; } });
|
|
2760
|
+
const refutedBy = (b) => refutedVerdict({ goal: `${b.law} @step (a run of ${b.depth} steps from the start)`, witness: b.witness, run: { params: b.params, trace: b.trace.map(shownRequest) } });
|
|
2761
|
+
const shallow = bounded(Math.min(250, total / 40), 1);
|
|
2762
|
+
if (shallow)
|
|
2763
|
+
return refutedBy(shallow);
|
|
2747
2764
|
let rule = r, lemmas;
|
|
2748
2765
|
const { fns, lists } = r.parts;
|
|
2749
2766
|
if (lists.length || fns.some(([, d]) => recurOf(d))) {
|
|
@@ -2760,12 +2777,16 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
2760
2777
|
if (c.proven && c.checked)
|
|
2761
2778
|
return { proven: true, checked: true, found: { ...(lemmas ? { lemmas } : {}), facts: c.found.map(f => f.text) } };
|
|
2762
2779
|
}
|
|
2763
|
-
const ms = until - performance.now();
|
|
2780
|
+
const ms = until - performance.now() - tail;
|
|
2764
2781
|
if (ms < 500)
|
|
2765
2782
|
return v;
|
|
2766
2783
|
const inf = inferLaws(rule, laws, stepLaws, { ms, ...(rule === r ? { first: v } : {}) });
|
|
2767
|
-
if (!(inf.proven && inf.checked))
|
|
2784
|
+
if (!(inf.proven && inf.checked)) {
|
|
2785
|
+
const deep = bounded(Math.max(0, until - performance.now()), Math.max(1, reached));
|
|
2786
|
+
if (deep)
|
|
2787
|
+
return refutedBy(deep);
|
|
2768
2788
|
return { ...v, why: [v.why, `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms`].filter(Boolean).join('; ') };
|
|
2789
|
+
}
|
|
2769
2790
|
const { found, stats: _stats, ...verdict } = inf;
|
|
2770
2791
|
void _stats;
|
|
2771
2792
|
return { ...verdict, found: { laws: found, ...(lemmas ? { lemmas } : {}) } };
|
|
@@ -2813,15 +2834,29 @@ export function crossCheckDecision(d, opts = {}) {
|
|
|
2813
2834
|
}
|
|
2814
2835
|
// With no rank stated, the rank is searched for from the loop's runs (core/cycles.ts's findRank), with the invariants it
|
|
2815
2836
|
// needs (inferLaws), within `ms` (10 s); the verdict is the kernel's on the rank and the laws found, in `found`.
|
|
2837
|
+
// The certificate, by default, is the cyclic proof of its halting goals (kernel/prove.ts's certLoop, translated from the
|
|
2838
|
+
// usual trees, which are then its input and not checked again); where none is made, the usual trees, checked.
|
|
2816
2839
|
export const proveLoop = (l, laws, opts = {}) => {
|
|
2817
|
-
if (
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2840
|
+
if (l.hasRank) {
|
|
2841
|
+
const t0 = performance.now(), goals = loopObligations(l.loop, laws, l.rankTerms), v = goalsVerdict(goals, !certOn());
|
|
2842
|
+
if (!v.proven)
|
|
2843
|
+
return v;
|
|
2844
|
+
const c = certLoop(l.loop, laws, l.rankTerms, v.trees, performance.now() - t0);
|
|
2845
|
+
return c && !c.checked && certOn() ? { ...v, checked: goals.every(g => check(g, v.trees[g.name])) } : v;
|
|
2846
|
+
}
|
|
2847
|
+
const t0 = performance.now(), out = findRank(l.loop, laws, opts);
|
|
2848
|
+
if (out.proven && out.checked && out.rank && out.trees)
|
|
2849
|
+
certLoop(l.loop, [...laws, ...(out.laws ?? [])], out.rank, out.trees, performance.now() - t0);
|
|
2822
2850
|
return { proven: out.proven, checked: out.checked, ...(out.trees ? { trees: out.trees } : {}), ...(out.goal ? { goal: out.goal, stuck: out.stuck } : {}), ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}),
|
|
2823
2851
|
...(out.found ? { found: { rank: out.found.rank, ...(out.laws?.length ? { laws: out.laws.map((law, i) => ({ law, text: out.found.laws[i] ?? law.name })) } : {}) } } : {}) };
|
|
2824
2852
|
};
|
|
2853
|
+
export function proveNeverEnds(l, opts = {}) {
|
|
2854
|
+
const loop = (opts.from ? l.pre(opts.from) : l).loop;
|
|
2855
|
+
const f = findNeverEnds(loop, { ms: opts.ms ?? 10_000 });
|
|
2856
|
+
if (!f.recur)
|
|
2857
|
+
return { proven: false, checked: false, ...(f.why ? { why: f.why } : {}), loop };
|
|
2858
|
+
return { proven: f.proven, checked: f.checked && checkRecur(loop, f.recur), recur: f.recur, loop, ...(f.by ? { by: f.by } : {}), run: { params: f.recur.start, trace: f.recur.stem } };
|
|
2859
|
+
}
|
|
2825
2860
|
export class FoldRule {
|
|
2826
2861
|
spec;
|
|
2827
2862
|
constructor(spec) {
|