tla-ts 0.0.4-dev.c4929d7 → 0.0.4-dev.ca40dfe
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 +31 -6
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +27 -27
- package/dist/deciders.js +34 -34
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -14
- package/dist/index.d.ts +12 -14
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +37 -27
- package/dist/prove.js +39 -29
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +76 -86
- package/dist/transfer.js +73 -83
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1154
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/cli/tlc.ts +941 -0
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +12 -36
- package/src/evaluate.ts +81 -101
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/obligations/action.ts +9 -45
- package/src/obligations/{anon.ts → anonymize.ts} +13 -25
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +42 -517
- package/src/obligations/generate.ts +88 -778
- package/src/obligations/index.ts +20 -22
- package/src/obligations/levels.ts +36 -41
- package/src/obligations/module.ts +88 -708
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +21 -15
- package/src/obligations/printer.ts +81 -188
- package/src/obligations/proof.ts +0 -1
- package/src/obligations/regroup.ts +100 -0
- package/src/obligations/simplify.ts +668 -0
- package/src/obligations/source.ts +25 -131
- package/src/obligations/{deref.ts → subexpression.ts} +48 -56
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +28 -26
- package/src/obligations/tuples.ts +37 -53
- package/src/parallel-worker.ts +37 -33
- package/src/parallel.ts +30 -24
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prove/decide-pool.ts +7 -12
- package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
- package/src/prove/isabelle/decide.ts +3 -6
- package/src/prove/isabelle/encode.ts +35 -93
- package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
- package/src/prove/isabelle/isar/method.ts +3 -3
- package/src/prove/isabelle/isar/type-check.ts +1 -1
- package/src/prove/isabelle/provers/blast/blast.ts +1 -1
- package/src/prove/isabelle/provers/blast/branch.ts +1 -1
- package/src/prove/isabelle/provers/blast/term.ts +3 -4
- package/src/prove/isabelle/provers/clasimp.ts +1 -1
- package/src/prove/isabelle/provers/classical.ts +3 -3
- package/src/prove/isabelle/provers/hypsubst.ts +1 -9
- package/src/prove/isabelle/pure/conv.ts +1 -1
- package/src/prove/isabelle/pure/drule.ts +2 -2
- package/src/prove/isabelle/pure/envir.ts +3 -35
- package/src/prove/isabelle/pure/logic.ts +4 -76
- package/src/prove/isabelle/pure/name.ts +1 -13
- package/src/prove/isabelle/pure/net.ts +2 -49
- package/src/prove/isabelle/pure/pattern.ts +3 -22
- package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
- package/src/prove/isabelle/pure/seq.ts +0 -23
- package/src/prove/isabelle/pure/simplifier.ts +2 -8
- package/src/prove/isabelle/pure/table.ts +1 -8
- package/src/prove/isabelle/pure/tactic.ts +5 -113
- package/src/prove/isabelle/pure/tactical.ts +1 -84
- package/src/prove/isabelle/pure/term-ord.ts +1 -55
- package/src/prove/isabelle/pure/term.ts +8 -128
- package/src/prove/isabelle/pure/thm.ts +4 -27
- package/src/prove/isabelle/pure/type.ts +0 -12
- package/src/prove/isabelle/pure/unify.ts +1 -1
- package/src/prove/isabelle/tla/classical-setup.ts +1 -1
- package/src/prove/ocaml.ts +1 -1
- package/src/prove/prep/action.ts +23 -36
- package/src/prove/prep/enabled-axioms.ts +2 -2
- package/src/prove/prep/fingerprint.ts +3 -3
- package/src/prove/prep/level-comparison.ts +9 -37
- package/src/prove/prep/md5.ts +2 -9
- package/src/prove/prep/normalize.ts +309 -0
- package/src/prove/prove-worker.ts +2 -5
- package/src/prove/prove.ts +98 -111
- package/src/prove/ptl/encode.ts +19 -31
- package/src/prove/smt/axioms.ts +45 -58
- package/src/prove/smt/encode.ts +124 -15
- package/src/prove/smt/instances.ts +2 -3
- package/src/prove/smt/rewrite.ts +24 -31
- package/src/prove/smt/solver/ast-util.ts +0 -56
- package/src/prove/smt/solver/case-split-queue.ts +1 -1
- package/src/prove/smt/solver/enode.ts +1 -1
- package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
- package/src/prove/smt/solver/model-macro-solver.ts +1 -1
- package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
- package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
- package/src/prove/smt/solver/nlsat/explain.ts +1 -1
- package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
- package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
- package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
- package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
- package/src/prove/smt/solver/pattern-inference.ts +1 -1
- package/src/prove/smt/solver/relevancy.ts +2 -2
- package/src/prove/smt/solver/rewriter.ts +1 -1
- package/src/prove/smt/solver/solver.ts +2 -2
- package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
- package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
- package/src/prove/verdict.ts +0 -5
- package/src/prove/zenon/decide.ts +5 -11
- package/src/prove/zenon/encode.ts +21 -80
- package/src/prove/zenon/eqrel.ts +1 -1
- package/src/prove/zenon/equality-rules.ts +1 -1
- package/src/prove/zenon/expr.ts +2 -2
- package/src/prove/zenon/index-table.ts +1 -1
- package/src/prove/zenon/isar.ts +1 -1
- package/src/prove/zenon/llproof.ts +1 -1
- package/src/prove/zenon/mltoll.ts +1 -1
- package/src/prove/zenon/node.ts +1 -1
- package/src/prove/zenon/search.ts +1 -1
- package/src/prove/zenon/tla/terms.ts +1 -20
- package/src/prove/zenon/tla/tla.ts +1 -1
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +16 -19
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -213
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/transfer.ts +32 -32
- package/src/values.ts +72 -67
- package/src/worker.ts +1 -4
- package/dist/run-cli.cjs +0 -45
- package/dist/run-cli.js +0 -45
- package/src/canonical.ts +0 -40
- package/src/obligations/ctx.ts +0 -64
- package/src/prove/prep/defs.ts +0 -33
- package/src/prove/prep/elab.ts +0 -156
- package/src/prove/prep/enabled.ts +0 -43
- package/src/prove/prep/flatten.ts +0 -70
- package/src/prove/prep/trivial.ts +0 -22
- package/src/prove/smt/axiomatize.ts +0 -69
- package/src/prove/smt/simplify.ts +0 -57
- package/src/run-cli.ts +0 -1806
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
- /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
package/src/prove/smt/encode.ts
CHANGED
|
@@ -3,20 +3,130 @@
|
|
|
3
3
|
// and each symbol the obligation uses brings the symbols and axioms encode/n_data.ml lists for it.
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
applyBuiltin,
|
|
7
|
+
at,
|
|
8
|
+
mapChildren,
|
|
7
9
|
type Expr,
|
|
8
10
|
type Hyp,
|
|
9
|
-
type Scope,
|
|
10
11
|
type Sequent,
|
|
11
12
|
} from "../../obligations/expression";
|
|
12
13
|
import { compareStrings } from "../ocaml";
|
|
13
|
-
import { collectSymbols } from "./axiomatize";
|
|
14
14
|
import { createPrinter } from "./context";
|
|
15
|
+
import { getSymbolSpec, type CollectState, type SymbolSpec } from "./data";
|
|
15
16
|
import type { Entry } from "./flatten";
|
|
16
|
-
import { declare, MEM } from "./format";
|
|
17
|
-
import { simplifyRecordEqualities, sortRecordFields } from "./simplify";
|
|
17
|
+
import { declare, getTlaName, MEM } from "./format";
|
|
18
18
|
import { createEncoder, type Binding, type EncodingSession, type Env, type Mode } from "./rewrite";
|
|
19
|
-
import { compareAxioms } from "./table";
|
|
19
|
+
import { compareAxioms, getAxiomKey, type Axiom } from "./table";
|
|
20
|
+
|
|
21
|
+
type RecordExpr = Extract<Expr, { kind: "Record" }>;
|
|
22
|
+
|
|
23
|
+
const isSameFieldSet = (left: RecordExpr, right: RecordExpr) =>
|
|
24
|
+
left.fields.length === right.fields.length &&
|
|
25
|
+
left.fields.every((field) => right.fields.some((other) => other.name === field.name)) &&
|
|
26
|
+
right.fields.every((field) => left.fields.some((other) => other.name === field.name));
|
|
27
|
+
|
|
28
|
+
// mk_conj: e1 /\ (e2 /\ ...).
|
|
29
|
+
const conjoinRight = (items: Expr[]): Expr =>
|
|
30
|
+
items.length === 1
|
|
31
|
+
? items[0]
|
|
32
|
+
: applyBuiltin("Conj", [items[0], conjoinRight(items.slice(1))], items[0]);
|
|
33
|
+
|
|
34
|
+
const decompose = (left: Expr, right: Expr, from: Expr): Expr => {
|
|
35
|
+
if (left.kind !== "Record" || right.kind !== "Record" || !isSameFieldSet(left, right))
|
|
36
|
+
return applyBuiltin("Eq", [left, right], from);
|
|
37
|
+
return conjoinRight(
|
|
38
|
+
left.fields.map((field) =>
|
|
39
|
+
decompose(
|
|
40
|
+
field.value,
|
|
41
|
+
right.fields.find((other) => other.name === field.name)?.value ?? field.value,
|
|
42
|
+
from,
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// N_rewrite.simpl_receq, before Type.Synthesize: an equality of two record constructors with the same fields is the conjunction of
|
|
49
|
+
// the equalities of their fields, paired by name.
|
|
50
|
+
const simplifyRecordEqualities = (expression: Expr): Expr => {
|
|
51
|
+
const inner = mapChildren(expression, simplifyRecordEqualities);
|
|
52
|
+
if (
|
|
53
|
+
inner.kind !== "Apply" ||
|
|
54
|
+
inner.operator.kind !== "Internal" ||
|
|
55
|
+
inner.operator.builtin !== "Eq" ||
|
|
56
|
+
inner.args.length !== 2 ||
|
|
57
|
+
inner.args[0].kind !== "Record" ||
|
|
58
|
+
inner.args[1].kind !== "Record"
|
|
59
|
+
)
|
|
60
|
+
return inner;
|
|
61
|
+
return at(decompose(inner.args[0], inner.args[1], inner), inner);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// N_rewrite.sort_recfields: a record's or a record set's fields in order. Like tlapm, it doesn't visit the
|
|
65
|
+
// field values, so a record inside a record keeps the order it's written in.
|
|
66
|
+
const sortRecordFields = (expression: Expr): Expr =>
|
|
67
|
+
expression.kind === "Record" || expression.kind === "Rect"
|
|
68
|
+
? {
|
|
69
|
+
...expression,
|
|
70
|
+
fields: expression.fields.toSorted((left, right) => compareStrings(left.name, right.name)),
|
|
71
|
+
}
|
|
72
|
+
: mapChildren(expression, sortRecordFields);
|
|
73
|
+
|
|
74
|
+
// N_axiomatize.collect: each symbol the obligation uses, in the order tlapm visits them, brings
|
|
75
|
+
// the symbols and axioms it depends on, smallest name first.
|
|
76
|
+
const collectSymbols = (entries: Entry[], encoder: Encoder) => {
|
|
77
|
+
const state: CollectState = {
|
|
78
|
+
recordFields: encoder.recordFields,
|
|
79
|
+
strings: [],
|
|
80
|
+
isFunConstr: false,
|
|
81
|
+
isFunSet: false,
|
|
82
|
+
isExcept: false,
|
|
83
|
+
tuples: [],
|
|
84
|
+
records: [],
|
|
85
|
+
anonymous: encoder.anonymous,
|
|
86
|
+
};
|
|
87
|
+
const symbols = new Map<string, SymbolSpec>();
|
|
88
|
+
const axioms = new Map<string, Axiom>();
|
|
89
|
+
const add = (name: string) => {
|
|
90
|
+
const work = new Set([name]);
|
|
91
|
+
while (work.size > 0) {
|
|
92
|
+
const next = [...work].toSorted(compareStrings)[0];
|
|
93
|
+
work.delete(next);
|
|
94
|
+
if (symbols.has(next)) continue;
|
|
95
|
+
const spec = getSymbolSpec(next, state);
|
|
96
|
+
symbols.set(next, spec);
|
|
97
|
+
spec.deps.forEach((dep) => work.add(dep));
|
|
98
|
+
spec.axioms.forEach((entry) => axioms.set(getAxiomKey(entry), entry));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// A flattened symbol stands for a builtin applied to its first-order arguments and then its
|
|
102
|
+
// higher-order ones, so its higher-order text is visited after its arguments.
|
|
103
|
+
const visit = (text: string) => {
|
|
104
|
+
const tokens = text.match(/[()]|[^\s()]+/g) ?? [];
|
|
105
|
+
const pending: { depth: number; text: string }[] = [];
|
|
106
|
+
tokens.reduce((depth, token, index) => {
|
|
107
|
+
if (token === "(") return depth + 1;
|
|
108
|
+
if (token === ")") {
|
|
109
|
+
if (pending.at(-1)?.depth === depth) visit(pending.pop()?.text ?? "");
|
|
110
|
+
return depth - 1;
|
|
111
|
+
}
|
|
112
|
+
const flat = encoder.flattened.get(token);
|
|
113
|
+
if (!flat) {
|
|
114
|
+
const builtin = getTlaName(token);
|
|
115
|
+
if (builtin !== undefined) add(builtin);
|
|
116
|
+
return depth;
|
|
117
|
+
}
|
|
118
|
+
if (flat.kind !== "") add(flat.kind);
|
|
119
|
+
if (tokens[index - 1] === "(") pending.push({ depth, text: flat.visit });
|
|
120
|
+
else visit(flat.visit);
|
|
121
|
+
return depth;
|
|
122
|
+
}, 0);
|
|
123
|
+
};
|
|
124
|
+
entries.forEach((entry) => {
|
|
125
|
+
if (typeof entry === "string") visit(entry);
|
|
126
|
+
else if ("omitted" in entry) visit(entry.omitted);
|
|
127
|
+
});
|
|
128
|
+
return { symbols, axioms };
|
|
129
|
+
};
|
|
20
130
|
|
|
21
131
|
type Encoder = ReturnType<typeof createEncoder>;
|
|
22
132
|
|
|
@@ -32,13 +142,17 @@ const isSecondOrder = (expression: Expr) =>
|
|
|
32
142
|
expression.kind === "Sequent" &&
|
|
33
143
|
expression.sequent.context.some((hyp) => hyp.kind === "Fresh" && hyp.shape > 0);
|
|
34
144
|
|
|
145
|
+
interface EncodedContext {
|
|
146
|
+
env: Env | undefined;
|
|
147
|
+
entries: Entry[];
|
|
148
|
+
}
|
|
149
|
+
|
|
35
150
|
// Declares each hypothesis's names and asserts its facts, in order, as Smtlib.pp_print_obligation.
|
|
36
151
|
const encodeContext = (context: Hyp[], encoder: Encoder) =>
|
|
37
|
-
context.reduce<
|
|
152
|
+
context.reduce<EncodedContext>(
|
|
38
153
|
(state, hyp) => {
|
|
39
154
|
const next = (binding: Binding, entries: Entry[] = []) => ({
|
|
40
155
|
env: encoder.push(state.env, binding),
|
|
41
|
-
scope: adjoin(state.scope, hyp),
|
|
42
156
|
entries: [...state.entries, ...entries],
|
|
43
157
|
});
|
|
44
158
|
switch (hyp.kind) {
|
|
@@ -106,7 +220,7 @@ const encodeContext = (context: Hyp[], encoder: Encoder) =>
|
|
|
106
220
|
}
|
|
107
221
|
}
|
|
108
222
|
},
|
|
109
|
-
{ env: undefined,
|
|
223
|
+
{ env: undefined, entries: [] },
|
|
110
224
|
);
|
|
111
225
|
|
|
112
226
|
// Smtlib.pp_print_obligation: the logic, the sort, the builtin symbols by name, their axioms,
|
|
@@ -126,12 +240,7 @@ export const encodeSmt = (prepared: Sequent, session: EncodingSession) => {
|
|
|
126
240
|
);
|
|
127
241
|
const entries = [...context.entries, ...goal];
|
|
128
242
|
const printer = createPrinter(encoder.declared);
|
|
129
|
-
const collected = collectSymbols(
|
|
130
|
-
entries,
|
|
131
|
-
encoder.flattened,
|
|
132
|
-
encoder.anonymous,
|
|
133
|
-
encoder.recordFields,
|
|
134
|
-
);
|
|
243
|
+
const collected = collectSymbols(entries, encoder);
|
|
135
244
|
const declarations = [...collected.symbols]
|
|
136
245
|
.toSorted((left, right) => compareStrings(left[0], right[0]))
|
|
137
246
|
.flatMap((symbol) => (symbol[1].declaration === undefined ? [] : [symbol[1].declaration]));
|
|
@@ -53,6 +53,7 @@ export const getSetOfAxioms = (name: string, free: string[], element: string, bo
|
|
|
53
53
|
const guards = variables.map((variable, index) => `(${MEM} ${variable} ${sets[index]})`);
|
|
54
54
|
// N_axioms.assert_issetof names its one set a.
|
|
55
55
|
const single = count === 1 ? ["a"] : sets;
|
|
56
|
+
const asserted = call(name, [...single, ...free]);
|
|
56
57
|
return [
|
|
57
58
|
axiom(
|
|
58
59
|
"SetOfIntro",
|
|
@@ -74,9 +75,7 @@ export const getSetOfAxioms = (name: string, free: string[], element: string, bo
|
|
|
74
75
|
axiom(
|
|
75
76
|
"AssertIsSetOf",
|
|
76
77
|
[count],
|
|
77
|
-
forall([...free, ...single], `(${IS_SET_OF} ${
|
|
78
|
-
[call(name, [...single, ...free])],
|
|
79
|
-
]),
|
|
78
|
+
forall([...free, ...single], `(${IS_SET_OF} ${asserted})`, [[asserted]]),
|
|
80
79
|
),
|
|
81
80
|
];
|
|
82
81
|
};
|
package/src/prove/smt/rewrite.ts
CHANGED
|
@@ -3,14 +3,8 @@
|
|
|
3
3
|
// flattened symbol brings are in instances.ts.
|
|
4
4
|
|
|
5
5
|
import { TlaUnsupportedError } from "../../errors";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
shiftExpr,
|
|
9
|
-
type Bound,
|
|
10
|
-
type Builtin,
|
|
11
|
-
type Expr,
|
|
12
|
-
type Sequent,
|
|
13
|
-
} from "../../obligations/expression";
|
|
6
|
+
import { normalizeApply, shiftExpr } from "../../obligations/substitution";
|
|
7
|
+
import { type Bound, type Builtin, type Expr, type Sequent } from "../../obligations/expression";
|
|
14
8
|
import { createContext, type Identifier } from "./context";
|
|
15
9
|
import {
|
|
16
10
|
createFlattener,
|
|
@@ -51,7 +45,7 @@ import {
|
|
|
51
45
|
getSetStAxioms,
|
|
52
46
|
} from "./instances";
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
interface Term {
|
|
55
49
|
isBool: boolean;
|
|
56
50
|
text: string;
|
|
57
51
|
// Type.Synthesize: the Int-sorted form of a term that is an integer before it's cast to Idv.
|
|
@@ -83,6 +77,14 @@ export interface Env {
|
|
|
83
77
|
rest: Env | undefined;
|
|
84
78
|
}
|
|
85
79
|
|
|
80
|
+
// A nested ASSUME's declarations and facts so far: each wraps the goal in a quantifier or an
|
|
81
|
+
// implication.
|
|
82
|
+
interface NestedContext {
|
|
83
|
+
env: Env | undefined;
|
|
84
|
+
mode: Mode;
|
|
85
|
+
wrappers: ((body: string) => string)[];
|
|
86
|
+
}
|
|
87
|
+
|
|
86
88
|
export const createEncoder = (session: EncodingSession) => {
|
|
87
89
|
const flattener = createFlattener();
|
|
88
90
|
const flatten = flattener.flatten;
|
|
@@ -548,11 +550,7 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
548
550
|
};
|
|
549
551
|
|
|
550
552
|
const encodeSequent = (sequent: Sequent, env: Env | undefined, mode: Mode): string => {
|
|
551
|
-
const steps = sequent.context.reduce<
|
|
552
|
-
env: Env | undefined;
|
|
553
|
-
mode: Mode;
|
|
554
|
-
wrappers: ((body: string) => string)[];
|
|
555
|
-
}>(
|
|
553
|
+
const steps = sequent.context.reduce<NestedContext>(
|
|
556
554
|
(state, hyp) => {
|
|
557
555
|
switch (hyp.kind) {
|
|
558
556
|
case "Fresh": {
|
|
@@ -562,10 +560,7 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
562
560
|
return {
|
|
563
561
|
env: push(state.env, { kind: "operator", symbol: variable, arity: hyp.shape }),
|
|
564
562
|
mode: { ...state.mode, depth: state.mode.depth + 1 },
|
|
565
|
-
wrappers: [
|
|
566
|
-
...state.wrappers,
|
|
567
|
-
(body: string) => `(forall ((${variable} Idv)) ${body})`,
|
|
568
|
-
],
|
|
563
|
+
wrappers: [...state.wrappers, (body) => `(forall ((${variable} Idv)) ${body})`],
|
|
569
564
|
};
|
|
570
565
|
}
|
|
571
566
|
if (hyp.level !== "Constant")
|
|
@@ -579,8 +574,7 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
579
574
|
mode: bound.mode,
|
|
580
575
|
wrappers: [
|
|
581
576
|
...state.wrappers,
|
|
582
|
-
(body
|
|
583
|
-
`(forall ((${variable} Idv)) ${guard ? `(=> ${guard} ${body})` : body})`,
|
|
577
|
+
(body) => `(forall ((${variable} Idv)) ${guard ? `(=> ${guard} ${body})` : body})`,
|
|
584
578
|
],
|
|
585
579
|
};
|
|
586
580
|
}
|
|
@@ -593,7 +587,7 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
593
587
|
env: push(state.env, { kind: "unsupported", reason: "a reference to a fact" }),
|
|
594
588
|
mode: state.mode,
|
|
595
589
|
wrappers: fact
|
|
596
|
-
? [...state.wrappers, (body
|
|
590
|
+
? [...state.wrappers, (body) => `(=> ${fact} ${body})`]
|
|
597
591
|
: state.wrappers,
|
|
598
592
|
};
|
|
599
593
|
}
|
|
@@ -639,7 +633,7 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
639
633
|
if (operator.kind === "Opaque")
|
|
640
634
|
return encodeOpaque(operator.name, expression.args, env, mode);
|
|
641
635
|
if (operator.kind === "Lambda")
|
|
642
|
-
return encode(
|
|
636
|
+
return encode(normalizeApply(operator, expression.args), env, mode);
|
|
643
637
|
throw new TlaUnsupportedError(`an application of ${operator.kind}`);
|
|
644
638
|
}
|
|
645
639
|
case "Sequent":
|
|
@@ -698,10 +692,10 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
698
692
|
return encodeFunction(expression, env, mode);
|
|
699
693
|
// Rewrite.elim_multiarg: f[a, b] applies f to the tuple <<a, b>>.
|
|
700
694
|
case "FcnApp": {
|
|
701
|
-
const
|
|
695
|
+
const encodedFunction = encodeIdv(expression.function, env, mode);
|
|
702
696
|
const args = expression.args.map((arg) => encodeIdv(arg, env, mode));
|
|
703
697
|
const argument = args.length === 1 ? args[0] : call(tla(`Tuple_${args.length}`), args);
|
|
704
|
-
return idv(`(${FUN_APP} ${
|
|
698
|
+
return idv(`(${FUN_APP} ${encodedFunction} ${argument})`);
|
|
705
699
|
}
|
|
706
700
|
case "Arrow":
|
|
707
701
|
return idv(
|
|
@@ -712,15 +706,14 @@ export const createEncoder = (session: EncodingSession) => {
|
|
|
712
706
|
);
|
|
713
707
|
case "Record":
|
|
714
708
|
case "Rect": {
|
|
715
|
-
const
|
|
716
|
-
const
|
|
717
|
-
recordFields.set(`Record_${
|
|
718
|
-
recordFields.set(`RecordSet_${
|
|
719
|
-
const name = `${expression.kind === "Record" ? "Record" : "RecordSet"}_${names.join("_")}`;
|
|
709
|
+
const names = expression.fields.map((field) => field.name);
|
|
710
|
+
const suffix = names.join("_");
|
|
711
|
+
recordFields.set(`Record_${suffix}`, names);
|
|
712
|
+
recordFields.set(`RecordSet_${suffix}`, names);
|
|
720
713
|
return idv(
|
|
721
714
|
call(
|
|
722
|
-
tla(
|
|
723
|
-
fields.map((field) => encodeIdv(field.value, env, mode)),
|
|
715
|
+
tla(`${expression.kind === "Record" ? "Record" : "RecordSet"}_${suffix}`),
|
|
716
|
+
expression.fields.map((field) => encodeIdv(field.value, env, mode)),
|
|
724
717
|
),
|
|
725
718
|
);
|
|
726
719
|
}
|
|
@@ -13,62 +13,6 @@ export const mkNot = (manager: AstManager, expr: number) =>
|
|
|
13
13
|
? manager.trueExpr
|
|
14
14
|
: manager.mkNot(expr);
|
|
15
15
|
|
|
16
|
-
// push_not: moves the negation through conjunctions and disjunctions.
|
|
17
|
-
export const pushNot = (manager: AstManager, expr: number): number => {
|
|
18
|
-
const op = manager.getOp(expr);
|
|
19
|
-
if (op === OP_AND) return manager.mkOr(manager.mapArgs(expr, (arg) => pushNot(manager, arg)));
|
|
20
|
-
if (op === OP_OR) return manager.mkAnd(manager.mapArgs(expr, (arg) => pushNot(manager, arg)));
|
|
21
|
-
return mkNot(manager, expr);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// flatten_and and flatten_or: a flattened list replaces an element by the last one, so the order
|
|
25
|
-
// follows Z3's.
|
|
26
|
-
const flatten = (manager: AstManager, input: number[], isAnd: boolean) => {
|
|
27
|
-
const result = [...input];
|
|
28
|
-
const seen = new Set<number>();
|
|
29
|
-
const junction = isAnd ? OP_AND : OP_OR;
|
|
30
|
-
const dual = isAnd ? OP_OR : OP_AND;
|
|
31
|
-
const unit = isAnd ? manager.trueExpr : manager.falseExpr;
|
|
32
|
-
const zero = isAnd ? manager.falseExpr : manager.trueExpr;
|
|
33
|
-
const replaceByLast = (index: number) => {
|
|
34
|
-
result[index] = result[result.length - 1];
|
|
35
|
-
result.pop();
|
|
36
|
-
};
|
|
37
|
-
for (let index = 0; index < result.length; index++) {
|
|
38
|
-
const expr = result[index];
|
|
39
|
-
if (seen.has(expr)) {
|
|
40
|
-
replaceByLast(index--);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
seen.add(expr);
|
|
44
|
-
const inner = manager.isNot(expr) ? manager.getArg(expr, 0) : -1;
|
|
45
|
-
const innerOp = inner === -1 ? -1 : manager.getOp(inner);
|
|
46
|
-
if (manager.getOp(expr) === junction) {
|
|
47
|
-
manager.pushArgs(expr, result);
|
|
48
|
-
replaceByLast(index--);
|
|
49
|
-
} else if (innerOp === OP_NOT) result[index--] = manager.getArg(inner, 0);
|
|
50
|
-
else if (innerOp === dual) {
|
|
51
|
-
for (let argIndex = 0; argIndex < manager.getNumArgs(inner); argIndex++) {
|
|
52
|
-
const arg = manager.getArg(inner, argIndex);
|
|
53
|
-
result.push(mkNot(manager, arg));
|
|
54
|
-
}
|
|
55
|
-
replaceByLast(index--);
|
|
56
|
-
} else if (isAnd && innerOp === OP_IMPLIES) {
|
|
57
|
-
result.push(manager.getArg(inner, 0));
|
|
58
|
-
result[index--] = mkNot(manager, manager.getArg(inner, 1));
|
|
59
|
-
} else if (!isAnd && manager.getOp(expr) === OP_IMPLIES) {
|
|
60
|
-
result.push(manager.getArg(expr, 1));
|
|
61
|
-
result[index--] = mkNot(manager, manager.getArg(expr, 0));
|
|
62
|
-
} else if (expr === unit || inner === zero) replaceByLast(index--);
|
|
63
|
-
else if (expr === zero || inner === unit) return [zero];
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const flattenAnd = (manager: AstManager, input: number[]) => flatten(manager, input, true);
|
|
69
|
-
|
|
70
|
-
export const flattenOr = (manager: AstManager, input: number[]) => flatten(manager, input, false);
|
|
71
|
-
|
|
72
16
|
// flatten_and and flatten_or on an expr_ref_vector, with Z3's references: the vector holds its
|
|
73
17
|
// expressions, and pin holds each visited one until the end.
|
|
74
18
|
const flattenVector = (manager: AstManager, result: RefVector, isAnd: boolean) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// MIT license, see z3-license.txt. E-graph nodes and the justifications for their equalities.
|
|
3
3
|
import type { Literal } from "./literal";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface Antecedents {
|
|
6
6
|
markLiteral(literal: Literal): void;
|
|
7
7
|
markEq(first: Enode, second: Enode): void;
|
|
8
8
|
markJustification(justification: Justification): void;
|
|
@@ -587,25 +587,11 @@ export const intersect = (
|
|
|
587
587
|
export const setValue = (interval: DepInterval, value: Rational) =>
|
|
588
588
|
setBounds(interval, mkNumeral(value), false, mkNumeral(value), false);
|
|
589
589
|
|
|
590
|
-
// reset: both bounds infinite, keeping the values, openness, and dependencies.
|
|
591
|
-
export const reset = (interval: DepInterval) => {
|
|
592
|
-
interval.isLowerInf = true;
|
|
593
|
-
interval.isUpperInf = true;
|
|
594
|
-
};
|
|
595
|
-
|
|
596
590
|
export const setZeroIntervalDepsForMult = (interval: DepInterval) => {
|
|
597
591
|
interval.lowerDep = mkJoin(interval.lowerDep, interval.upperDep);
|
|
598
592
|
interval.upperDep = interval.lowerDep;
|
|
599
593
|
};
|
|
600
594
|
|
|
601
|
-
export const isZero = (interval: DepInterval) =>
|
|
602
|
-
!interval.isLowerInf &&
|
|
603
|
-
!interval.isUpperInf &&
|
|
604
|
-
!interval.isLowerOpen &&
|
|
605
|
-
!interval.isUpperOpen &&
|
|
606
|
-
interval.lower.isZero() &&
|
|
607
|
-
interval.upper.isZero();
|
|
608
|
-
|
|
609
595
|
export const isEmpty = (interval: DepInterval) => {
|
|
610
596
|
if (interval.isLowerInf || interval.isUpperInf) return false;
|
|
611
597
|
const comparison = interval.lower.compare(interval.upper);
|
|
@@ -20,7 +20,7 @@ const SIGN_PRECISION = 2;
|
|
|
20
20
|
const X = 0;
|
|
21
21
|
const Y = 1;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
class AlgebraicCell {
|
|
24
24
|
constructor(
|
|
25
25
|
public p: Upolynomial,
|
|
26
26
|
public lower: Mpbq,
|
|
@@ -81,12 +81,12 @@ interface IsolatingFactor {
|
|
|
81
81
|
lowerVariations: number;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
interface ClosestAnums {
|
|
85
85
|
roots: Anum[];
|
|
86
86
|
indices: number[];
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
interface SignedRoots {
|
|
90
90
|
roots: Anum[];
|
|
91
91
|
signs: number[];
|
|
92
92
|
}
|
|
@@ -19,7 +19,7 @@ const FLIPPED_KIND: Record<IneqKind, IneqKind> = { EQ: "EQ", LT: "GT", GT: "LT"
|
|
|
19
19
|
export const flipKind = (kind: IneqKind) => FLIPPED_KIND[kind];
|
|
20
20
|
|
|
21
21
|
// What the solver keeps per Boolean variable, reset when a variable is made or deleted.
|
|
22
|
-
|
|
22
|
+
interface BoolVarHooks {
|
|
23
23
|
onMk: (boolVar: number) => void;
|
|
24
24
|
onDelete: (boolVar: number) => void;
|
|
25
25
|
}
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { type IneqAtom, type IneqKind, type RootKind, isIneqAtom } from "./types";
|
|
25
25
|
|
|
26
26
|
// The solver state an explanation reads.
|
|
27
|
-
|
|
27
|
+
interface ExplainContext {
|
|
28
28
|
atoms: AtomTable;
|
|
29
29
|
// sample(): the solver's assignment, refined in place.
|
|
30
30
|
sample: (Anum | undefined)[];
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
|
|
21
21
|
// A section is the index-th root of lower. A sector lies between the lowerIndex-th root of lower
|
|
22
22
|
// and the upperIndex-th root of upper, and a null bound is infinite.
|
|
23
|
-
|
|
23
|
+
interface CellInterval {
|
|
24
24
|
isSection: boolean;
|
|
25
25
|
lower: Polynomial | null;
|
|
26
26
|
lowerIndex: number;
|
|
@@ -29,13 +29,13 @@ export interface CellInterval {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// lws_spt_threshold, lws_witness_subs_lc and lws_witness_subs_disc.
|
|
32
|
-
|
|
32
|
+
interface LevelwiseParams {
|
|
33
33
|
spanningTreeThreshold: number;
|
|
34
34
|
isWitnessSubsLc: boolean;
|
|
35
35
|
isWitnessSubsDisc: boolean;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const DEFAULT_LEVELWISE_PARAMS: LevelwiseParams = {
|
|
39
39
|
spanningTreeThreshold: 4,
|
|
40
40
|
isWitnessSubsLc: true,
|
|
41
41
|
isWitnessSubsDisc: true,
|
|
@@ -56,10 +56,7 @@ const BOTH_SIDES = 3;
|
|
|
56
56
|
|
|
57
57
|
// stable_index_merge_sort: bottom-up, so each pair is compared once even though comparing refines
|
|
58
58
|
// the numbers.
|
|
59
|
-
|
|
60
|
-
count: number,
|
|
61
|
-
isLess: (first: number, second: number) => boolean,
|
|
62
|
-
) => {
|
|
59
|
+
const sortIndicesStably = (count: number, isLess: (first: number, second: number) => boolean) => {
|
|
63
60
|
let source = Array.from({ length: count }, (_, index) => index);
|
|
64
61
|
for (let width = 1; width < count; width *= 2) {
|
|
65
62
|
const target: number[] = [];
|
|
@@ -62,7 +62,7 @@ const RATIONAL_OPS: ValueOps<Rational> = {
|
|
|
62
62
|
const getMonomialKey = (vars: readonly number[], degrees: readonly number[]) =>
|
|
63
63
|
vars.map((variable, index) => `${variable}^${degrees[index]}`).join(",");
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
class Monomial {
|
|
66
66
|
readonly totalDegree: number;
|
|
67
67
|
|
|
68
68
|
// vars and degrees change only when the manager renames the variables.
|
|
@@ -102,7 +102,7 @@ export class Monomial {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// lex_compare: the biggest variable dominates, then its degree.
|
|
105
|
-
|
|
105
|
+
const lexCompare = (first: Monomial, second: Monomial) => {
|
|
106
106
|
if (first === second) return 0;
|
|
107
107
|
let firstIndex = first.size - 1;
|
|
108
108
|
let secondIndex = second.size - 1;
|
|
@@ -124,7 +124,7 @@ export const lexCompare = (first: Monomial, second: Monomial) => {
|
|
|
124
124
|
return firstIndex < 0 ? -1 : 1;
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
const gradedLexCompare = (first: Monomial, second: Monomial) =>
|
|
128
128
|
first.totalDegree === second.totalDegree
|
|
129
129
|
? lexCompare(first, second)
|
|
130
130
|
: first.totalDegree < second.totalDegree
|
|
@@ -335,7 +335,7 @@ class CheapSomBuffer {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
|
|
338
|
+
interface Factors {
|
|
339
339
|
constant: bigint;
|
|
340
340
|
factors: Polynomial[];
|
|
341
341
|
degrees: number[];
|
|
@@ -59,14 +59,14 @@ const trim = (coeffs: bigint[]) => {
|
|
|
59
59
|
return coeffs;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
interface IsolatedRoots {
|
|
63
63
|
roots: Mpbq[];
|
|
64
64
|
lowers: Mpbq[];
|
|
65
65
|
uppers: Mpbq[];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// An interval (a, b) refined around the root of a square-free polynomial, or the root itself.
|
|
69
|
-
|
|
69
|
+
interface Refinement {
|
|
70
70
|
isInterval: boolean;
|
|
71
71
|
lower: Mpbq;
|
|
72
72
|
upper: Mpbq;
|
|
@@ -5,9 +5,9 @@ import { AstManager, KIND_APP, OP_AND, OP_IMPLIES, OP_ITE, OP_OR } from "./ast";
|
|
|
5
5
|
import type { Enode } from "./enode";
|
|
6
6
|
import { shrink } from "./array";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type RelevancyHandler = () => void;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface RelevancyContext {
|
|
11
11
|
manager: AstManager;
|
|
12
12
|
// lbool as 1, -1 or 0.
|
|
13
13
|
findAssignment(expr: number): number;
|
|
@@ -42,7 +42,7 @@ import { getRewriteDepth, type Rewrite, RewriterTpl } from "./rewriter-tpl";
|
|
|
42
42
|
import { sortByKey } from "./sort";
|
|
43
43
|
import { UnusedVarsEliminator } from "./var-subst";
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
interface RewriterOptions {
|
|
46
46
|
// Replaces (and a b) with (not (or (not a) (not b))), as Z3's asserted_formulas does after NNF.
|
|
47
47
|
readonly isEliminatingAnd: boolean;
|
|
48
48
|
readonly arith: ArithRewriterOptions;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Ported from Z3 (src/smt/smt_solver.cpp, src/smt/smt_kernel.cpp, src/smt/smt_setup.cpp), MIT
|
|
2
2
|
// license, see z3-license.txt. Decides an SMT-LIB problem the way `z3 -smt2 AUTO_CONFIG=false
|
|
3
3
|
// smt.MBQI=true` does for tlapm's UFNIA obligations.
|
|
4
|
-
import { SmtCanceledError, SmtUnsupportedError } from "../../../errors";
|
|
5
|
-
import {
|
|
4
|
+
import { isStackOverflow, SmtCanceledError, SmtUnsupportedError } from "../../../errors";
|
|
5
|
+
import type { DecideOptions, Verdict } from "../../verdict";
|
|
6
6
|
import { AssertedFormulas } from "./asserted-formulas";
|
|
7
7
|
import { AstManager } from "./ast";
|
|
8
8
|
import { Context } from "./context";
|