gdp-wired 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +423 -31
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/cli.d.ts +3 -0
- package/dist/core/cli.js +204 -38
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +4 -1
- package/dist/core/counts.js +314 -85
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +2 -1
- package/dist/core/data.js +223 -24
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +37 -3
- package/dist/core/dsl.js +167 -26
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +191 -16
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +169 -22
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +66 -0
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +2 -1
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +38 -4
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +2 -0
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +20 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +1 -1
- package/dist/core/extract-read.d.ts +17 -0
- package/dist/core/extract-read.js +5 -5
- package/dist/core/extract-rs.js +5 -1
- package/dist/core/extract-shapes.js +2 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-step.d.ts +151 -1
- package/dist/core/extract-step.js +1232 -60
- package/dist/core/extract-swift.js +6 -2
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +61 -5
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +918 -217
- package/dist/core/jvm/JavaReader.java +23 -6
- package/dist/core/jvm/Jvm.java +3 -0
- package/dist/core/jvm/KtReader.java +6 -5
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +15 -1
- package/dist/core/machine.js +187 -15
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +183 -10
- package/dist/core/py/reader.py +234 -40
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +8 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +57 -4
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +3 -1
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.js +1 -1
- package/dist/core/transfer.js +22 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +50 -5
- package/dist/interchange/format.js +11 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +56 -9
- package/dist/kernel/epr.js +108 -26
- package/dist/kernel/kernel.d.ts +29 -1
- package/dist/kernel/kernel.js +325 -62
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +10 -3
- package/dist/kernel/prove.js +332 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.js +30 -37
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +6 -1
|
@@ -201,6 +201,19 @@ final class Reader {
|
|
|
201
201
|
func load(_ paths: [String]) {
|
|
202
202
|
for p in paths {
|
|
203
203
|
guard let src = try? String(contentsOfFile: p, encoding: .utf8) else { continue }
|
|
204
|
+
// A linear, conservative resource preflight before SwiftParser's error recovery. Deep
|
|
205
|
+
// unclosed delimiters can make that recovery exponential, even in a tiny source file.
|
|
206
|
+
// Count text (including strings/comments), not syntax: this is a reader limit, not a
|
|
207
|
+
// claim that the source is invalid. The compiler still checks every accepted source.
|
|
208
|
+
var depth = 0
|
|
209
|
+
for c in src.utf8 {
|
|
210
|
+
if c == 40 || c == 91 || c == 123 { depth += 1 }
|
|
211
|
+
else if c == 41 || c == 93 || c == 125 { depth = max(0, depth - 1) }
|
|
212
|
+
if depth > 32 {
|
|
213
|
+
FileHandle.standardError.write(Data("gdp: refused: \(p): the source nests delimiter characters past reader limit 32 (including strings and comments)\n".utf8))
|
|
214
|
+
exit(1)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
204
217
|
let parsed = Parser.parse(source: src)
|
|
205
218
|
let folded = OperatorTable.standardOperators.foldAll(parsed) { _ in }.as(SourceFileSyntax.self) ?? parsed
|
|
206
219
|
let rel = p.hasPrefix(root + "/") ? String(p.dropFirst(root.count + 1)) : p
|
|
@@ -460,7 +473,7 @@ final class Reader {
|
|
|
460
473
|
// The initializer: the one there is, or the one of the arity asked for (ctor); none: the memberwise one (a struct's)
|
|
461
474
|
// or the default one (a class's whose properties all have initial values).
|
|
462
475
|
var inits: [(InitializerDeclSyntax, String)] = []
|
|
463
|
-
for (mf, d) in t.members { if let i = d.as(InitializerDeclSyntax.self)
|
|
476
|
+
for (mf, d) in t.members { if let i = d.as(InitializerDeclSyntax.self) { inits.append((i, mf)) } }
|
|
464
477
|
let initId = "\(t.qual).__init__"
|
|
465
478
|
var ctorJ: J = .null
|
|
466
479
|
let bare = { (s: String) in s.filter { !$0.isWhitespace } }
|
|
@@ -474,15 +487,19 @@ final class Reader {
|
|
|
474
487
|
} else if pick.count != 1 {
|
|
475
488
|
funcs.append((initId, stub(initId, "__init__", t, pick.isEmpty ? "no init of the arity or parameters asked for (ctor)" : "a type with \(pick.count) inits (name one by its arity or its parameters: ctor, e.g. \"(limit: Int)\")")))
|
|
476
489
|
methodsJ.append(("__init__", .s(initId)))
|
|
490
|
+
} else if pick[0].0.optionalMark != nil {
|
|
491
|
+
funcs.append((initId, stub(initId, "__init__", t, "a failable initializer (init? or init!)")))
|
|
492
|
+
methodsJ.append(("__init__", .s(initId)))
|
|
477
493
|
} else {
|
|
478
494
|
let (i, mf) = pick[0]
|
|
479
495
|
funcs.append((initId, with(file: mf) { initFunc(i, t, ps, initId) }))
|
|
480
496
|
methodsJ.append(("__init__", .s(initId)))
|
|
481
|
-
for (o, of) in inits
|
|
482
|
-
let
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
497
|
+
for (o, of) in inits {
|
|
498
|
+
let key = "__init__/" + bare(o.signature.parameterClause.trimmedDescription)
|
|
499
|
+
if o == i { methodsJ.append((key, .s(initId))); continue }
|
|
500
|
+
let oid = "\(t.qual).\(key)"
|
|
501
|
+
funcs.append((oid, o.optionalMark != nil ? stub(oid, key, t, "a failable initializer (init? or init!)") : with(file: of) { initFunc(o, t, ps, oid) }))
|
|
502
|
+
methodsJ.append((key, .s(oid)))
|
|
486
503
|
}
|
|
487
504
|
ctorJ = ["labels": .a(i.signature.parameterClause.parameters.map { .s($0.firstName.text) }), "throws": .b(i.signature.effectSpecifiers?.trimmedDescription.contains("throws") ?? false),
|
|
488
505
|
"types": .a(i.signature.parameterClause.parameters.map { .s($0.type.trimmedDescription) })]
|
|
@@ -508,6 +525,7 @@ final class Reader {
|
|
|
508
525
|
var inits0: J = .null
|
|
509
526
|
if !own.isEmpty { inits0 = .s("a subclass of \(own[0].qual) (the subset reads a class with no superclass of the code's own)") }
|
|
510
527
|
recs.append((t.qual, ["name": .s(t.qual), "short": .s(t.name), "fields": .a(fields), "methods": .o(methodsJ), "kinds": .a(kinds), "own": true, "module": "", "p": .s("\(t.file):\(t.line):1"),
|
|
528
|
+
"initializers": ctorArity == nil && ctorSig == nil && inits.count > 1 ? .a(inits.map { .s($0.0.signature.parameterClause.trimmedDescription) }) : .null,
|
|
511
529
|
"swift": ["kind": .s(t.kind), "qual": .s(t.qual), "file": .s(t.file), "priv": .b(t.priv), "ctor": ctorJ, "sigs": .o(sigs), "refused": inits0,
|
|
512
530
|
"props": .a(ps.map { ["name": .s($0.name), "t": .s($0.ttext), "let": .b($0.isLet), "kw": .s($0.kw), "init": .b($0.hasInit)] })]]))
|
|
513
531
|
if !inits0.isNull { funcs.removeAll { $0.0 == initId }; funcs.append((initId, stub(initId, "__init__", t, inits0.str!))) }
|
|
@@ -1114,7 +1132,32 @@ final class Reader {
|
|
|
1114
1132
|
return ([], no(p, "\(t): a case with associated values, or a static member the context doesn't state"))
|
|
1115
1133
|
}
|
|
1116
1134
|
let bt = base.trimmedDescription
|
|
1117
|
-
if bt == "self", n == "init" {
|
|
1135
|
+
if bt == "self", n == "init" {
|
|
1136
|
+
var candidates = selfTy?.members.compactMap { $0.1.as(InitializerDeclSyntax.self) }.filter { $0.signature.parameterClause.parameters.map { $0.firstName.text } == labels } ?? []
|
|
1137
|
+
if candidates.count > 1 {
|
|
1138
|
+
// No contextual guess for literals, operators, generic conversions or overload results.
|
|
1139
|
+
// A declared scalar value or explicit integer conversion has an exact argument type.
|
|
1140
|
+
func exactScalar(_ e: ExprSyntax) -> TT? {
|
|
1141
|
+
if let parens = e.as(TupleExprSyntax.self), parens.elements.count == 1 { return exactScalar(parens.elements.first!.expression) }
|
|
1142
|
+
let integerCast: Bool = { guard let call = e.as(FunctionCallExprSyntax.self), let name = call.calledExpression.as(DeclReferenceExprSyntax.self)?.baseName.text else { return false }; return INTS[name] != nil && local(name) == nil }()
|
|
1143
|
+
guard e.is(DeclReferenceExprSyntax.self) || e.is(MemberAccessExprSyntax.self) || integerCast,
|
|
1144
|
+
let known = typeOf(e).map(resolve), case .n(let name, let parameters) = known,
|
|
1145
|
+
parameters.isEmpty, INTS[name] != nil || name == "Bool" || name == "String" else { return nil }
|
|
1146
|
+
return known
|
|
1147
|
+
}
|
|
1148
|
+
let known = c.arguments.map { exactScalar($0.expression) }
|
|
1149
|
+
candidates = candidates.filter { candidate in
|
|
1150
|
+
let declared = candidate.signature.parameterClause.parameters.map { resolve(parseType($0.type.trimmedDescription)) }
|
|
1151
|
+
return zip(known, declared).allSatisfy { actual, expected in actual == expected }
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
guard candidates.count == 1 else { return ([], no(p, "\(t): initializer delegation has ambiguous parameter labels (an exact scalar overload is required)")) }
|
|
1155
|
+
let selected = candidates[0]
|
|
1156
|
+
let key = "__init__/" + selected.signature.parameterClause.trimmedDescription.filter { !$0.isWhitespace }
|
|
1157
|
+
let expected = selected.signature.parameterClause.parameters.map { parseType($0.type.trimmedDescription) }
|
|
1158
|
+
let (pre, xs) = args(c.arguments, expected)
|
|
1159
|
+
return (pre, X("call", p, [("f", X("get", p, [("x", v("self", p)), ("f", .s(key)), ("text", "self.init")])), ("args", .a(xs)), ("kw", []), ("text", .s(t))]))
|
|
1160
|
+
}
|
|
1118
1161
|
if bt.first?.isUppercase == true, local(bt) == nil, base.is(DeclReferenceExprSyntax.self) || base.is(MemberAccessExprSyntax.self) {
|
|
1119
1162
|
let tn = bt == "Self" ? selfTy?.name ?? bt : bt
|
|
1120
1163
|
if let x = ty(named: tn, from: selfTy) {
|
package/dist/core/system.js
CHANGED
|
@@ -280,7 +280,7 @@ export function isolation(m, level) {
|
|
|
280
280
|
return ite(sigmaC(e.c), sigma(e.then), sigma(e.else));
|
|
281
281
|
if (e.op === 'const')
|
|
282
282
|
return e;
|
|
283
|
-
if (e.op === 'mul')
|
|
283
|
+
if (e.op === 'mul' || e.op === 'proj')
|
|
284
284
|
return { ...e, a: sigma(e.a) };
|
|
285
285
|
return { ...e, a: sigma(e.a), b: sigma(e.b) };
|
|
286
286
|
};
|
package/dist/core/transfer.js
CHANGED
|
@@ -123,7 +123,7 @@ function isBridge(y, f, op) {
|
|
|
123
123
|
const callsOf = (t) => { const out = []; walk(t, o => { if (o.op === 'call')
|
|
124
124
|
out.push(o.fn); }); return out; };
|
|
125
125
|
export function transferPlan(l) {
|
|
126
|
-
const p = programOf([l]), bridges = new Map();
|
|
126
|
+
const p = programOf([l], [], false), bridges = new Map();
|
|
127
127
|
for (const f of p.fns) {
|
|
128
128
|
const op = builtinOf(f);
|
|
129
129
|
if (op && !isBridge(l.holds, f, op))
|
|
@@ -233,7 +233,7 @@ const freshName = (base) => { let n = base; for (let i = 2; fnNamed(n); i++)
|
|
|
233
233
|
function build(l, bridged, unfold) {
|
|
234
234
|
// Copied: a function that calls a bridged one, or (unfolding) one that isn't recursive, or a copied one; a function
|
|
235
235
|
// that isn't recursive is unfolded where it is called instead.
|
|
236
|
-
const p0 = programOf([l]), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
|
|
236
|
+
const p0 = programOf([l], [], false), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
|
|
237
237
|
for (let changed = true; changed;) {
|
|
238
238
|
changed = false;
|
|
239
239
|
for (const f of p0.fns)
|
|
@@ -307,7 +307,7 @@ function build(l, bridged, unfold) {
|
|
|
307
307
|
return undefined;
|
|
308
308
|
const v = (name) => ({ op: 'var', name });
|
|
309
309
|
// Only the copies the law said through them reaches (each with those its copy calls).
|
|
310
|
-
const p1 = programOf([lstar]), back = new Map([...copies].map(([a, b]) => [b, a]));
|
|
310
|
+
const p1 = programOf([lstar], [], false), back = new Map([...copies].map(([a, b]) => [b, a]));
|
|
311
311
|
const bridges = [...bridged].map(([f, op]) => {
|
|
312
312
|
const fn = fnOf(f), vs = fn.params.map(q => q.name);
|
|
313
313
|
return { fn, op, law: { name: `${f} is ${op.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: f, args: vs.map(v) }, b: op.x(vs.map(v)) }, params: [] } };
|
|
@@ -316,7 +316,7 @@ function build(l, bridged, unfold) {
|
|
|
316
316
|
const fn = fnOf(back.get(c.name)), vs = fn.params.map(q => q.name), params = [...new Set(fn.paramFns)];
|
|
317
317
|
return { fn, law: { name: `${fn.name} is ${c.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: fn.name, args: vs.map(v) }, b: { op: 'call', fn: c.name, args: vs.map(v) } }, params } };
|
|
318
318
|
});
|
|
319
|
-
const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)]);
|
|
319
|
+
const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)], [], false);
|
|
320
320
|
return { p, lstar, bridges, equivs, copies, unfolded: unfold };
|
|
321
321
|
}
|
|
322
322
|
// --- the proof ---------------------------------------------------------------------------------------------------------
|
|
@@ -345,15 +345,24 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
345
345
|
if (!b)
|
|
346
346
|
return undefined;
|
|
347
347
|
// One chain of nodes: each bridge (by the search), each copy's law (its node made, or by the search), in order.
|
|
348
|
-
|
|
348
|
+
let fs = factsOf(b.p);
|
|
349
|
+
const chain = [], nodes = [], nodeOf = new Map();
|
|
350
|
+
// Search may invent ordinary observer definitions. Its facts append to the context's,
|
|
351
|
+
// preserving the indices of the chain; carry that vocabulary into the final verification.
|
|
352
|
+
const extend = (r) => { if (r.out && r.facts && r.verdict.program) {
|
|
353
|
+
fs = r.facts;
|
|
354
|
+
b.p = r.verdict.program;
|
|
355
|
+
} };
|
|
349
356
|
const add = (pr) => { chain.push(pr); nodes.splice(0, nodes.length, ...pr.nodes); nodeOf.set(pr.law.name, nodes.findIndex(n => n.name === pr.spec.name)); };
|
|
350
357
|
const ctx = () => ({ p: b.p, fs, base: [...chain], level: chain.length ? top(chain.at(-1)) : 0 });
|
|
351
358
|
const lost = [];
|
|
352
359
|
for (const x of b.bridges) {
|
|
353
360
|
const r = searchIn(x.law, opts, Math.min(until, clock() + 6000 * (opts.patience ?? 1)), ctx());
|
|
354
361
|
tried += r.verdict.tried;
|
|
355
|
-
if (r.out)
|
|
362
|
+
if (r.out) {
|
|
363
|
+
extend(r);
|
|
356
364
|
add(r.out);
|
|
365
|
+
}
|
|
357
366
|
else
|
|
358
367
|
lost.push(x.fn.name);
|
|
359
368
|
}
|
|
@@ -375,6 +384,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
375
384
|
tried += r.verdict.tried;
|
|
376
385
|
if (!r.out)
|
|
377
386
|
return undefined;
|
|
387
|
+
extend(r);
|
|
378
388
|
add(r.out);
|
|
379
389
|
}
|
|
380
390
|
// (through the bridges and unfolded: half the time left, the other half through the unfolding alone, the functions
|
|
@@ -388,6 +398,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
388
398
|
}
|
|
389
399
|
if (!r.out)
|
|
390
400
|
return { ...r.verdict, proven: false, checked: false, law: l.name, counterexample: undefined, tried };
|
|
401
|
+
extend(r);
|
|
391
402
|
// The nodes: the chain's, then the law's said through them, then the law's own.
|
|
392
403
|
const specs = [...nodes], names = new Set(specs.map(n => n.name)), off = specs.length;
|
|
393
404
|
for (const n of r.out.nodes) {
|
|
@@ -405,7 +416,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
405
416
|
const v = verify(fs, specs, Math.max(until, clock() + 3000));
|
|
406
417
|
if (!v.proven || !v.checked)
|
|
407
418
|
return undefined;
|
|
408
|
-
const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l]).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
|
|
419
|
+
const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l], [], false).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
|
|
409
420
|
return { law: l.name, proven: true, checked: true, proof: v, lemmas: [...b.bridges.map(x => x.law.name), ...b.equivs.map(x => x.law.name), ...r.verdict.lemmas], scheme: `${r.verdict.scheme ?? 'no induction'}, through the law ${b.lstar.name}`, tried, program: b.p, node: specs.length - 1, ms: Math.round(performance.now() - t0), through };
|
|
410
421
|
}
|
|
411
422
|
}
|
|
@@ -472,11 +483,13 @@ function walker(b, fs, nodeOf, own) {
|
|
|
472
483
|
case 'sub':
|
|
473
484
|
case 'min':
|
|
474
485
|
case 'max':
|
|
475
|
-
case 'prod':
|
|
486
|
+
case 'prod':
|
|
487
|
+
case 'tup': {
|
|
476
488
|
const o = c;
|
|
477
489
|
return walkE(a.a, o.a) && walkE(a.b, o.b);
|
|
478
490
|
}
|
|
479
|
-
case 'mul':
|
|
491
|
+
case 'mul':
|
|
492
|
+
case 'proj': {
|
|
480
493
|
const o = c;
|
|
481
494
|
return a.k === o.k && walkE(a.a, o.a);
|
|
482
495
|
}
|
package/dist/core/translate.js
CHANGED
|
@@ -13,12 +13,20 @@ import { walk } from "./machine.js";
|
|
|
13
13
|
import { add, costs, env, refuteFast, scale, solve } from "./solver.js";
|
|
14
14
|
import { checkRefutation } from "./check.js";
|
|
15
15
|
import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraints, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
|
|
16
|
-
import { cellProducts,
|
|
16
|
+
import { cellProducts, grow, late, leafRowsOf, parseKey, withinDeadline } from "../kernel/prove.js";
|
|
17
17
|
import { Reader, times } from "../kernel/reader.js";
|
|
18
18
|
const omega = 'O$';
|
|
19
19
|
const debugOn = () => !!env.GDP_CYCLIC_DEBUG;
|
|
20
20
|
// A cell's key, from its name (`M[key]`, the key's canonical text, whose names may be cells themselves).
|
|
21
|
-
const keyOf = (cell) =>
|
|
21
|
+
const keyOf = (cell) => {
|
|
22
|
+
const text = cell.slice(cell.indexOf('[') + 1, -1);
|
|
23
|
+
// The time encoding below is scalar. A tuple cell is not a linear key: parsing its
|
|
24
|
+
// separators as coefficients made NaN rows, on which elimination's gcd never ends.
|
|
25
|
+
if (text.startsWith('⟨'))
|
|
26
|
+
return undefined;
|
|
27
|
+
const key = parseKey(text);
|
|
28
|
+
return Object.values(key).every(Number.isFinite) ? key : undefined;
|
|
29
|
+
};
|
|
22
30
|
export function renamer(r) {
|
|
23
31
|
const terms = new Map(), memo = new WeakMap(), cells = r.cells ?? {};
|
|
24
32
|
const col = (name, wp) => {
|
|
@@ -51,7 +59,7 @@ export function renamer(r) {
|
|
|
51
59
|
return out;
|
|
52
60
|
}
|
|
53
61
|
if (isCell(name)) {
|
|
54
|
-
const map = name.slice(0, name.indexOf('[')),
|
|
62
|
+
const map = name.slice(0, name.indexOf('[')), original = keyOf(name), key = original && lin(original, wp);
|
|
55
63
|
if (!key)
|
|
56
64
|
return undefined;
|
|
57
65
|
const to = cells[map];
|
|
@@ -148,12 +156,14 @@ function regrow(whole, wp, until) {
|
|
|
148
156
|
export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), wp = new Map(), swaps = []) {
|
|
149
157
|
// (within the deadline it runs in too: a certificate's translation, core/cyclic.ts's translateMs)
|
|
150
158
|
const until = withinDeadline(until0);
|
|
159
|
+
if (late(until))
|
|
160
|
+
return undefined;
|
|
151
161
|
const ren = swaps.length ? (lin, p) => {
|
|
152
162
|
const out = {};
|
|
153
163
|
for (const key in lin) {
|
|
154
164
|
let to = key;
|
|
155
165
|
if (isCell(key)) {
|
|
156
|
-
const
|
|
166
|
+
const k = keyOf(key), sw = k && swaps.find(x => x[0] === canon(k));
|
|
157
167
|
if (sw)
|
|
158
168
|
to = `${key.slice(0, key.indexOf('['))}[${sw[1]}]`;
|
|
159
169
|
}
|
|
@@ -174,7 +184,7 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
174
184
|
return yes && no ? { split: wl, yes, no } : undefined;
|
|
175
185
|
}
|
|
176
186
|
// (past its budget, no translation: each leaf reads the two goals' rows whole, counted, so a large tree's stops there)
|
|
177
|
-
if (
|
|
187
|
+
if (late(until))
|
|
178
188
|
return undefined;
|
|
179
189
|
// (the usual leaf's rows as its search kept them, where it did: kernel/prove.ts's leafRowsOf; else read again)
|
|
180
190
|
const kept = !tree.products && !tree.squares ? leafRowsOf.get(tree) : undefined;
|
|
@@ -198,7 +208,10 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
198
208
|
const a = ren({ [pair[0]]: 1 }, wp), b = ren({ [pair[1]]: 1 }, wp), [ca] = Object.keys(a ?? {}), [cb] = Object.keys(b ?? {});
|
|
199
209
|
if (!ca || !cb || !isCell(ca) || !isCell(cb))
|
|
200
210
|
continue;
|
|
201
|
-
const
|
|
211
|
+
const ak = keyOf(ca), bk = keyOf(cb);
|
|
212
|
+
if (!ak || !bk)
|
|
213
|
+
continue;
|
|
214
|
+
const d = add(ak, scale(bk, -1)), q0 = {};
|
|
202
215
|
if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
|
|
203
216
|
continue;
|
|
204
217
|
for (const key of Object.keys(d)) {
|
|
@@ -252,6 +265,8 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
252
265
|
return close(whole, wp, st, until);
|
|
253
266
|
}
|
|
254
267
|
export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(), swaps = []) {
|
|
268
|
+
if (late(withinDeadline(until)))
|
|
269
|
+
return undefined;
|
|
255
270
|
if (!reads.length)
|
|
256
271
|
return inner(wp, swaps);
|
|
257
272
|
const [r, ...rest] = reads, ku = linear(r.k, new Map()), wu = linear(r.w, new Map()), kl = ku && ren(ku, wp), wl = wu && ren(wu, wp);
|
|
@@ -281,6 +296,8 @@ export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(),
|
|
|
281
296
|
// A path where l >= 1 (two cells' keys apart by l = q·Ω) while q <= 0 is a row: refuted by q·Ω <= 0, the product of
|
|
282
297
|
// that row and Ω >= 0.
|
|
283
298
|
function apart(whole, wp, l, q, st, until) {
|
|
299
|
+
if (late(withinDeadline(until)))
|
|
300
|
+
return undefined;
|
|
284
301
|
const rows = rowsAt(whole, wp), find = (x) => { const c = canon(x); return rows.findIndex(r => canon(r.lin) === c); };
|
|
285
302
|
const iq = find(q), io = find({ [omega]: -1 }), ia = find(add({ 1: 1 }, scale(l, -1)));
|
|
286
303
|
if (iq >= 0 && io >= 0 && ia >= 0) {
|
|
@@ -317,6 +334,8 @@ function atomsOf(c, wp) {
|
|
|
317
334
|
// A tree for `whole` that first decides each condition true (a guard, the antecedent of a use's implication), each
|
|
318
335
|
// other side grown on the goal (the node's hypotheses refute it), then `inner` at the path where all hold.
|
|
319
336
|
export function decide(whole, conds, inner, st, until, wp = new Map()) {
|
|
337
|
+
if (late(withinDeadline(until)))
|
|
338
|
+
return undefined;
|
|
320
339
|
for (const [i, c] of conds.entries()) {
|
|
321
340
|
if (truth(c, wp) === true)
|
|
322
341
|
continue;
|
|
@@ -376,7 +395,10 @@ function cellAtom(g, wp) {
|
|
|
376
395
|
for (const q of names.slice(i + 1)) {
|
|
377
396
|
if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
|
|
378
397
|
continue;
|
|
379
|
-
const
|
|
398
|
+
const pk = keyOf(p), qk = keyOf(q);
|
|
399
|
+
if (!pk || !qk)
|
|
400
|
+
continue;
|
|
401
|
+
const d = add(pk, scale(qk, -1));
|
|
380
402
|
if (Object.keys(d).some(key => key !== '1' && isMonomial(key)))
|
|
381
403
|
continue;
|
|
382
404
|
const column = Object.keys(d).some(key => key.includes('⟦'));
|
|
@@ -444,7 +466,10 @@ function omegaPair(g, wp) {
|
|
|
444
466
|
for (const q of names.slice(i + 1)) {
|
|
445
467
|
if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
|
|
446
468
|
continue;
|
|
447
|
-
const
|
|
469
|
+
const pk = keyOf(p), qk = keyOf(q);
|
|
470
|
+
if (!pk || !qk)
|
|
471
|
+
continue;
|
|
472
|
+
const d = add(pk, scale(qk, -1)), q0 = {};
|
|
448
473
|
if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
|
|
449
474
|
continue;
|
|
450
475
|
for (const key of Object.keys(d)) {
|
|
@@ -471,11 +496,13 @@ function omegaPair(g, wp) {
|
|
|
471
496
|
// A case of `g` closed: refuted by its rows, else an open choice, two reads of a function or two cells over time split
|
|
472
497
|
// (each then equal), else the goal grown at the path.
|
|
473
498
|
export function close(g, wp, st, until) {
|
|
499
|
+
if (late(withinDeadline(until)))
|
|
500
|
+
return undefined;
|
|
474
501
|
const l = leafAt(g, wp, true, st);
|
|
475
502
|
if (l)
|
|
476
503
|
return l;
|
|
477
504
|
const pick = choiceAtom(g, wp) ?? cellAtom(g, wp), om = pick ? undefined : omegaPair(g, wp), next = pick ?? om?.l;
|
|
478
|
-
if (next &&
|
|
505
|
+
if (next && !late(withinDeadline(until))) {
|
|
479
506
|
st.splits++;
|
|
480
507
|
const id = canon(next), y = close(g, new Map(wp).set(id, { lin: next, holds: true }), st, until);
|
|
481
508
|
const no = new Map(wp).set(id, { lin: next, holds: false }), n = y && (om?.q ? apart(g, no, next, om.q, st, until) : close(g, no, st, until));
|
|
@@ -496,6 +523,8 @@ export function close(g, wp, st, until) {
|
|
|
496
523
|
// `nUses`: the uses' hypotheses, just before the conclusion refuted (mainGoal's order).
|
|
497
524
|
export function carry(g, nFacts, nUses, st, until0) {
|
|
498
525
|
const until = withinDeadline(until0);
|
|
526
|
+
if (late(until))
|
|
527
|
+
return undefined;
|
|
499
528
|
const last = g.hyps.length - 1, uses = g.hyps.slice(last - nUses, last), facts = g.hyps.slice(last - nUses - nFacts, last - nUses);
|
|
500
529
|
const law = g.hyps[last].x;
|
|
501
530
|
const parts = uses.map(u => (u.op === 'or' && u.xs.length === 2 && u.xs[0].op === 'not' ? { guard: u.xs[0].x, concl: u.xs[1] } : { guard: undefined, concl: u }));
|
|
@@ -541,7 +570,7 @@ export function carry(g, nFacts, nUses, st, until0) {
|
|
|
541
570
|
};
|
|
542
571
|
const leafOf = (wp, solveIt) => leafAt(g, wp, solveIt, st), final = (wp) => close(g, wp, st, until);
|
|
543
572
|
const node = (wp, guardsDone) => {
|
|
544
|
-
if (
|
|
573
|
+
if (late(until))
|
|
545
574
|
return undefined;
|
|
546
575
|
// A hypothesis false at the path: the law at t holds there, or a law it is carried from (its guard true) fails.
|
|
547
576
|
if (truth(law, wp) === true || parts.some(p => (p.guard === undefined || truth(p.guard, wp) === true) && truth(p.concl, wp) === false))
|
package/dist/core/watch.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// at every k steps in a row the run takes: each step's `when` read with the state it starts from, its request, queries
|
|
8
8
|
// and flags; `then` with the state before the first step (plain names), the first request and its flags, the j-th
|
|
9
9
|
// request as input@j, and the state and maps after the last step (primed names).
|
|
10
|
-
import { carriedView, evalC, numbersOf, walk } from "./machine.js";
|
|
10
|
+
import { carriedView, evalC, evalE, numbersOf, walk } from "./machine.js";
|
|
11
11
|
import { someHolds } from "./exists.js";
|
|
12
12
|
export const isStepLaw = (w) => 'then' in w;
|
|
13
13
|
// A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
|
|
@@ -77,6 +77,43 @@ function keysPer(c, names) {
|
|
|
77
77
|
return [...vals];
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
+
// A key no map reads, scaled and compared linearly with what the run holds (c·k ⋈ t, c >= 16: a time's week,
|
|
81
|
+
// core/calendar.ts), is read
|
|
82
|
+
// where that comparison turns too: ⌊t/c⌋ and the keys beside it, each later key 0 while it is solved. Untrusted: more
|
|
83
|
+
// keys read is only more of the law checked.
|
|
84
|
+
function turns(c, names) {
|
|
85
|
+
const atoms = [];
|
|
86
|
+
walk(c, o => {
|
|
87
|
+
if (o.op !== '<' && o.op !== '<=' && o.op !== '=')
|
|
88
|
+
return;
|
|
89
|
+
// (a key scaled past the small keys a run reads, k·x with k at least 16: its turn is far from 0 to bound + 1)
|
|
90
|
+
const t = JSON.stringify(o), reads = new Set(names.filter(x => [...t.matchAll(new RegExp(`"op":"mul","k":(\\d+),"a":\\{"op":"var","name":${JSON.stringify(x).replace(/[$]/g, '\\$&')}\\}`, 'g'))].some(m => Number(m[1]) >= 16)));
|
|
91
|
+
if (reads.size)
|
|
92
|
+
atoms.push({ a: o.a, b: o.b, reads });
|
|
93
|
+
});
|
|
94
|
+
return (i, env, st, m) => {
|
|
95
|
+
const x = names[i], out = new Set(), saved = names.slice(i).map(y => env[y]);
|
|
96
|
+
for (let j = i + 1; j < names.length; j++)
|
|
97
|
+
env[names[j]] = 0;
|
|
98
|
+
for (const at of atoms) {
|
|
99
|
+
if (!at.reads.has(x))
|
|
100
|
+
continue;
|
|
101
|
+
try {
|
|
102
|
+
const f = (v) => { env[x] = v; return evalE(at.a, env, st, m) - evalE(at.b, env, st, m); };
|
|
103
|
+
const f0 = f(0), slope = f(1) - f0;
|
|
104
|
+
if (slope) {
|
|
105
|
+
const k = Math.floor(-f0 / slope);
|
|
106
|
+
for (const v of [k - 1, k, k + 1])
|
|
107
|
+
if (v >= 0 && Number.isSafeInteger(v))
|
|
108
|
+
out.add(v);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch { /* (a value the run doesn't hold: no turn) */ }
|
|
112
|
+
}
|
|
113
|
+
names.slice(i).forEach((y, j) => { env[y] = saved[j]; });
|
|
114
|
+
return [...out];
|
|
115
|
+
};
|
|
116
|
+
}
|
|
80
117
|
// The tuples every watch has read a law at (core/dsl.ts's refuteByRuns counts its budget in them).
|
|
81
118
|
export const watchWork = { n: 0 };
|
|
82
119
|
// Watches one law or step law along one run: `start` with the state at the start, `step` after each step the run takes
|
|
@@ -84,13 +121,21 @@ export const watchWork = { n: 0 };
|
|
|
84
121
|
export function watch(m, run, w, params, bound) {
|
|
85
122
|
// At every tuple of the keys (each name's own: keysPer), one key per name, in one environment set in place.
|
|
86
123
|
const names = w.forall ? [w.forall, ...(w.keys ?? [])] : [], per = keysPer(isStepLaw(w) ? w.then : w.holds, names);
|
|
87
|
-
|
|
124
|
+
// (the keys no map reads, also where a comparison of theirs turns)
|
|
125
|
+
const mapRead = new Set();
|
|
126
|
+
walk(isStepLaw(w) ? w.then : w.holds, o => { if (o.op === 'get')
|
|
127
|
+
for (const x of names)
|
|
128
|
+
if (JSON.stringify(o.key).includes(`"name":${JSON.stringify(x)}`))
|
|
129
|
+
mapRead.add(x); });
|
|
130
|
+
const turn = names.some(x => !mapRead.has(x)) ? turns(isStepLaw(w) ? w.then : w.holds, names) : undefined;
|
|
131
|
+
const atKeys = (keys, env, f, st, mm) => {
|
|
88
132
|
const go = (i) => {
|
|
89
133
|
if (i === names.length) {
|
|
90
134
|
watchWork.n++;
|
|
91
135
|
return f(env);
|
|
92
136
|
}
|
|
93
|
-
|
|
137
|
+
const more = turn && st && mm && !mapRead.has(names[i]) ? turn(i, env, st, mm).filter(k => !keys[i].includes(k)) : [];
|
|
138
|
+
for (const key of more.length ? [...keys[i], ...more] : keys[i]) {
|
|
94
139
|
env[names[i]] = key;
|
|
95
140
|
if (!go(i + 1))
|
|
96
141
|
return false;
|
|
@@ -103,7 +148,7 @@ export function watch(m, run, w, params, bound) {
|
|
|
103
148
|
// A law with "there exists" (core/exists.ts): broken only where no value can be a witness, as far as that is decided
|
|
104
149
|
// (one natural or integer read linearly); undecided, it is kept.
|
|
105
150
|
const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m, true)?.holds ?? true : evalC(w.holds, env, st, m));
|
|
106
|
-
const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st));
|
|
151
|
+
const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st), st, m);
|
|
107
152
|
return { start: holds, step: (_before, _input, after) => holds(after) };
|
|
108
153
|
}
|
|
109
154
|
const k = w.steps ?? 1, whens = w.when === undefined ? [] : Array.isArray(w.when) ? w.when : [w.when];
|
|
@@ -132,7 +177,7 @@ export function watch(m, run, w, params, bound) {
|
|
|
132
177
|
maps: { ...first.maps, ...Object.fromEntries(Object.entries(after.maps).map(([n, cells]) => [`${n}'`, cells])) },
|
|
133
178
|
defaults: { ...first.defaults, ...Object.fromEntries(Object.entries(after.defaults ?? {}).map(([n, d]) => [`${n}'`, d])) },
|
|
134
179
|
};
|
|
135
|
-
return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps));
|
|
180
|
+
return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps), both, primedMaps);
|
|
136
181
|
},
|
|
137
182
|
};
|
|
138
183
|
}
|
|
@@ -70,6 +70,8 @@ export function encE(e, at = 'term') {
|
|
|
70
70
|
case 'mul': return { op: e.op, k: nat(e.k, `${at}.k`), a: encE(e.a, `${at}.a`) };
|
|
71
71
|
case 'if': return { op: e.op, c: encC(e.c, `${at}.c`), then: encE(e.then, `${at}.then`), else: encE(e.else, `${at}.else`) };
|
|
72
72
|
case 'get': return { op: e.op, map: name(e.map, `${at}.map`), key: encE(e.key, `${at}.key`) };
|
|
73
|
+
case 'tup':
|
|
74
|
+
case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
|
|
73
75
|
default: return fail(at, `no term op ${JSON.stringify(e.op)}`);
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -100,6 +102,8 @@ export function decE(x, at = 'term') {
|
|
|
100
102
|
case 'get':
|
|
101
103
|
obj(o, at, ['op', 'map', 'key']);
|
|
102
104
|
return { op: 'get', map: name(o.map, `${at}.map`), key: decE(o.key, `${at}.key`) };
|
|
105
|
+
case 'tup':
|
|
106
|
+
case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
|
|
103
107
|
default: return fail(at, `no term op ${JSON.stringify(o.op ?? null)}`);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
@@ -267,6 +271,9 @@ function encAtom(key, cols, at) {
|
|
|
267
271
|
return { mono: factorsOf(key).map((f, i) => encAtom(f, cols, `${at}.mono[${i}]`)) };
|
|
268
272
|
if (isCell(key)) {
|
|
269
273
|
const map = key.slice(0, key.indexOf('[')), inner = key.slice(key.indexOf('[') + 1, -1);
|
|
274
|
+
// Version 1.1 has one linear key, not the native tuple's list of linear parts.
|
|
275
|
+
if (inner.startsWith('⟨'))
|
|
276
|
+
fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
|
|
270
277
|
// (a cell's name is the kernel's canon of its key: written back from the key read, it must be the same text)
|
|
271
278
|
const lin = parseKey(inner);
|
|
272
279
|
if (canon(lin) !== inner)
|
|
@@ -297,7 +304,10 @@ function decAtom(x, cols, at) {
|
|
|
297
304
|
return [...fs].sort().join('*');
|
|
298
305
|
}
|
|
299
306
|
obj(o, at, ['cell', 'key']);
|
|
300
|
-
|
|
307
|
+
const key = canon(decLin(o.key, cols, `${at}.key`));
|
|
308
|
+
if (key.startsWith('⟨'))
|
|
309
|
+
fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
|
|
310
|
+
return `${name(o.cell, `${at}.cell`)}[${key}]`;
|
|
301
311
|
}
|
|
302
312
|
export function encLin(lin, cols, at = 'row') {
|
|
303
313
|
if (!isObj(lin))
|
package/dist/kernel/cdcl.d.ts
CHANGED
|
@@ -49,6 +49,10 @@ export declare const cdclStats: {
|
|
|
49
49
|
lpLoad: number;
|
|
50
50
|
nodes: number;
|
|
51
51
|
boundRounds: number;
|
|
52
|
+
fmLeafMs: number;
|
|
53
|
+
fmOpenMs: number;
|
|
54
|
+
fastMs: number;
|
|
55
|
+
missMs: number;
|
|
52
56
|
};
|
|
53
57
|
export declare const REFUTED = "refuted, not unfolded";
|
|
54
58
|
export type Refuted = Outcome & {
|
|
@@ -64,6 +68,7 @@ export type CdclOptions = {
|
|
|
64
68
|
clausal?: boolean;
|
|
65
69
|
sideOf?: (hyp: number) => number;
|
|
66
70
|
quiet?: (name: string) => boolean;
|
|
71
|
+
point?: boolean;
|
|
67
72
|
};
|
|
68
73
|
export declare function growCdcl(goal: Goal, root: Path, budget: {
|
|
69
74
|
nodes: number;
|