tla-ts 0.0.10-dev.8aec06f77 → 0.0.10-dev.94c3dd828
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/dist/deciders.cjs +37 -36
- package/dist/deciders.js +55 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +146 -58
- package/dist/prove.js +142 -54
- package/dist/run.cjs +45 -43
- package/dist/run.js +47 -45
- package/dist/transfer.cjs +39 -36
- package/dist/transfer.js +23 -20
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/ast.ts +3 -3
- package/src/check.ts +203 -33
- package/src/cli/tlapm.ts +261 -68
- package/src/dependencies.ts +23 -2
- package/src/errors.ts +1 -1
- package/src/exit-codes.ts +1 -0
- package/src/liveness-checker.ts +530 -201
- package/src/liveness.ts +47 -32
- package/src/obligations/anonymize.ts +2 -4
- package/src/obligations/index.ts +5 -3
- package/src/obligations/pragma.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +151 -42
- package/src/prover/deciders.ts +1 -8
- package/src/prover/isabelle/isar/attrib.ts +86 -45
- package/src/prover/isabelle/isar/context.ts +25 -22
- package/src/prover/isabelle/isar/induct.ts +2 -5
- package/src/prover/isabelle/isar/method.ts +5 -7
- package/src/prover/isabelle/isar/proof.ts +33 -16
- package/src/prover/isabelle/isar/rule-cases.ts +6 -14
- package/src/prover/isabelle/isar/theory.ts +16 -17
- package/src/prover/isabelle/isar/toplevel.ts +46 -52
- package/src/prover/isabelle/provers/classical.ts +1 -1
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +1 -0
- package/src/prover/prep/methods.ts +50 -3
- package/src/prover/prep/normalize.ts +4 -1
- package/src/prover/prove.ts +58 -32
- package/src/prover/ptl/decide.ts +43 -63
- package/src/prover/smt/data.ts +51 -45
- package/src/prover/smt/encode.ts +1 -2
- package/src/prover/smt/rewrite.ts +1 -0
- package/src/prover/smt/solver/aig-tactic.ts +25 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -5
- package/src/prover/smt/solver/asserted-formulas.ts +1 -1
- package/src/prover/smt/solver/ast-util.ts +3 -1
- package/src/prover/smt/solver/ast.ts +110 -152
- package/src/prover/smt/solver/bound-manager.ts +39 -28
- package/src/prover/smt/solver/bv-bound-chk.ts +2 -8
- package/src/prover/smt/solver/bv-rewriter.ts +14 -16
- package/src/prover/smt/solver/bv1-blast.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +19 -14
- package/src/prover/smt/solver/check-logic.ts +6 -1
- package/src/prover/smt/solver/context.ts +20 -10
- package/src/prover/smt/solver/demodulator.ts +2 -2
- package/src/prover/smt/solver/dependent-expr-state.ts +16 -0
- package/src/prover/smt/solver/distribute-forall.ts +1 -10
- package/src/prover/smt/solver/dom-simplify.ts +1 -1
- package/src/prover/smt/solver/dt2bv-tactic.ts +2 -7
- package/src/prover/smt/solver/e-matching.ts +6 -6
- package/src/prover/smt/solver/elim-uncnstr.ts +3 -14
- package/src/prover/smt/solver/enode.ts +15 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +19 -8
- package/src/prover/smt/solver/euf/dt-solver.ts +19 -19
- package/src/prover/smt/solver/euf/egraph.ts +65 -32
- package/src/prover/smt/solver/euf/euf-solver.ts +35 -18
- package/src/prover/smt/solver/euf/fpa-solver.ts +37 -51
- package/src/prover/smt/solver/euf/mam.ts +6 -48
- package/src/prover/smt/solver/euf/q-ematch.ts +21 -94
- package/src/prover/smt/solver/euf/q-mbi.ts +4 -2
- package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -1
- package/src/prover/smt/solver/euf/q-solver.ts +2 -0
- package/src/prover/smt/solver/euf/th-solver.ts +1 -1
- package/src/prover/smt/solver/factor.ts +1 -11
- package/src/prover/smt/solver/fd-solver.ts +1 -2
- package/src/prover/smt/solver/fm-tactic.ts +19 -13
- package/src/prover/smt/solver/fpa-rewriter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-converter.ts +10 -6
- package/src/prover/smt/solver/internalizer.ts +41 -2
- package/src/prover/smt/solver/lia2pb.ts +18 -4
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +144 -107
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -17
- package/src/prover/smt/solver/macro-finder.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +13 -13
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -11
- package/src/prover/smt/solver/maxcore.ts +4 -12
- package/src/prover/smt/solver/maxlex.ts +0 -7
- package/src/prover/smt/solver/maxsmt-base.ts +7 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -11
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +9 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -9
- package/src/prover/smt/solver/model-evaluator.ts +9 -5
- package/src/prover/smt/solver/model-macro-solver.ts +3 -3
- package/src/prover/smt/solver/muz/dl-context.ts +57 -3
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -20
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -1
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -10
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +76 -13
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -2
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
- package/src/prover/smt/solver/muz/dl-rule.ts +93 -29
- package/src/prover/smt/solver/muz/hnf.ts +6 -5
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +178 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -3
- package/src/prover/smt/solver/muz/rule-properties.ts +194 -36
- package/src/prover/smt/solver/muz/spacer-context.ts +102 -84
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -2
- package/src/prover/smt/solver/muz/spacer-pdr.ts +3 -3
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -7
- package/src/prover/smt/solver/muz/spacer-util.ts +2 -2
- package/src/prover/smt/solver/muz/substitution.ts +88 -37
- package/src/prover/smt/solver/nlqsat.ts +2 -2
- package/src/prover/smt/solver/nlsat/algebraic.ts +1 -2
- package/src/prover/smt/solver/nlsat/explain.ts +5 -0
- package/src/prover/smt/solver/nlsat/solver.ts +36 -25
- package/src/prover/smt/solver/opt-context.ts +9 -8
- package/src/prover/smt/solver/opt-nlsat.ts +68 -58
- package/src/prover/smt/solver/opt-solver.ts +16 -7
- package/src/prover/smt/solver/optsmt.ts +12 -9
- package/src/prover/smt/solver/pattern-inference.ts +2 -2
- package/src/prover/smt/solver/pb-rewriter.ts +13 -13
- package/src/prover/smt/solver/poly-rewriter.ts +2 -2
- package/src/prover/smt/solver/probes.ts +1 -1
- package/src/prover/smt/solver/propagate-values.ts +4 -0
- package/src/prover/smt/solver/proto-model.ts +5 -5
- package/src/prover/smt/solver/purify-arith.ts +50 -15
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -1
- package/src/prover/smt/solver/qe-mbp.ts +13 -23
- package/src/prover/smt/solver/qe.ts +45 -53
- package/src/prover/smt/solver/qsat.ts +70 -90
- package/src/prover/smt/solver/quantifier-analyzer.ts +9 -9
- package/src/prover/smt/solver/quasi-macros.ts +9 -18
- package/src/prover/smt/solver/rational.ts +17 -0
- package/src/prover/smt/solver/recfun-decl-plugin.ts +33 -19
- package/src/prover/smt/solver/recfun-rewriter.ts +1 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +6 -2
- package/src/prover/smt/solver/rewriter.ts +1 -1
- package/src/prover/smt/solver/sat/asymm-branch.ts +59 -46
- package/src/prover/smt/solver/sat/clause-use-list.ts +0 -6
- package/src/prover/smt/solver/sat/clause.ts +1 -3
- package/src/prover/smt/solver/sat/config.ts +3 -3
- package/src/prover/smt/solver/sat/consequences.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +1 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +4 -12
- package/src/prover/smt/solver/sat/model-converter.ts +1 -15
- package/src/prover/smt/solver/sat/pb-solver.ts +49 -23
- package/src/prover/smt/solver/sat/probing.ts +22 -19
- package/src/prover/smt/solver/sat/sat2goal.ts +9 -10
- package/src/prover/smt/solver/sat/simplifier.ts +15 -56
- package/src/prover/smt/solver/sat/solver.ts +20 -19
- package/src/prover/smt/solver/sat/watch-list.ts +7 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +7 -7
- package/src/prover/smt/solver/seq-derive.ts +6 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +7 -7
- package/src/prover/smt/solver/seq-range-predicate.ts +14 -1
- package/src/prover/smt/solver/seq-re-rewriter.ts +1 -10
- package/src/prover/smt/solver/seq-re-util.ts +1 -2
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +4 -4
- package/src/prover/smt/solver/seq-rewriter.ts +1 -4
- package/src/prover/smt/solver/smt-setup.ts +15 -9
- package/src/prover/smt/solver/smtlib-parser.ts +1174 -579
- package/src/prover/smt/solver/smtlib-script.ts +866 -728
- package/src/prover/smt/solver/tactic.ts +66 -14
- package/src/prover/smt/solver/theory-array.ts +25 -58
- package/src/prover/smt/solver/theory-bv.ts +13 -50
- package/src/prover/smt/solver/theory-fpa.ts +46 -78
- package/src/prover/smt/solver/theory-pb.ts +10 -6
- package/src/prover/smt/solver/theory-recfun.ts +2 -2
- package/src/prover/smt/solver/theory-seq-regex.ts +3 -6
- package/src/prover/smt/solver/theory-seq-solve.ts +5 -5
- package/src/prover/smt/solver/theory-seq-state.ts +6 -3
- package/src/prover/smt/solver/theory-seq.ts +32 -54
- package/src/prover/smt/solver/theory.ts +16 -1
- package/src/prover/smt/solver/tseitin-cnf.ts +3 -3
- package/src/prover/smt/solver/var-subst.ts +2 -2
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/zenon/decide.ts +9 -11
- package/src/prover/zenon/node.ts +12 -11
- package/src/prover/zenon/tla/sets.ts +1 -1
- package/src/search.ts +131 -16
- package/src/successors.ts +1 -1
- package/src/symmetry.ts +2 -2
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/summary.ts +29 -14
- package/src/typed-tier.ts +6535 -0
- package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
|
@@ -276,6 +276,8 @@ interface CheckResult {
|
|
|
276
276
|
isOptimizing: boolean;
|
|
277
277
|
model: ProtoModel | undefined;
|
|
278
278
|
core: number[] | undefined;
|
|
279
|
+
// check_sat_result::reason_unknown, where the port tracks it.
|
|
280
|
+
reasonUnknown?: string;
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
interface ScriptState {
|
|
@@ -317,9 +319,15 @@ const MANAGERLESS_COMMANDS = new Set([
|
|
|
317
319
|
export const runSmtlibScript = (
|
|
318
320
|
text: string,
|
|
319
321
|
options: DecideOptions,
|
|
320
|
-
|
|
322
|
+
printLine: (line: string, isDiagnostic?: boolean) => void,
|
|
321
323
|
) => {
|
|
322
324
|
const commands = createCommandReader(text);
|
|
325
|
+
// Z3 writes to a stream: text left without a newline starts the next line.
|
|
326
|
+
let pendingText = "";
|
|
327
|
+
const print = (line: string, isDiagnostic?: boolean) => {
|
|
328
|
+
printLine(pendingText + line, isDiagnostic);
|
|
329
|
+
pendingText = "";
|
|
330
|
+
};
|
|
323
331
|
const settings = {
|
|
324
332
|
isPrintingSuccess: false,
|
|
325
333
|
isProducingModels: true,
|
|
@@ -365,18 +373,17 @@ export const runSmtlibScript = (
|
|
|
365
373
|
eufSolver: undefined,
|
|
366
374
|
};
|
|
367
375
|
};
|
|
368
|
-
|
|
376
|
+
let state = createState();
|
|
369
377
|
const getPrintEnvironment = () => ({
|
|
370
378
|
options: settings.printOptions,
|
|
371
|
-
isUsed:
|
|
372
|
-
isClashing:
|
|
379
|
+
isUsed: state.reader.isUsed,
|
|
380
|
+
isClashing: state.reader.isClashing,
|
|
373
381
|
});
|
|
374
|
-
const format = (expr: number) => printExpr(
|
|
382
|
+
const format = (expr: number) => printExpr(state.manager, getPrintEnvironment(), expr);
|
|
375
383
|
const display = (expr: number) => print(format(expr));
|
|
376
384
|
const report = (error: SmtParseError) =>
|
|
377
385
|
print(`(error "line ${error.line} column ${error.column}: ${error.message}")`);
|
|
378
386
|
const getNamedAssertions = () => {
|
|
379
|
-
const state = script.state;
|
|
380
387
|
const manager = state.manager;
|
|
381
388
|
const isNamed = hasNames();
|
|
382
389
|
return state.assertions.map((assertion, index) =>
|
|
@@ -405,7 +412,6 @@ export const runSmtlibScript = (
|
|
|
405
412
|
};
|
|
406
413
|
};
|
|
407
414
|
const optimize = (extra: number[]) => {
|
|
408
|
-
const state = script.state;
|
|
409
415
|
const manager = state.manager;
|
|
410
416
|
const objectives = state.objectives;
|
|
411
417
|
const hard = [...getNamedAssertions(), ...state.names.filter((name) => name !== -1), ...extra];
|
|
@@ -423,7 +429,7 @@ export const runSmtlibScript = (
|
|
|
423
429
|
setup: getSetup(),
|
|
424
430
|
write: () => {},
|
|
425
431
|
parameters: settings.parameters,
|
|
426
|
-
hasDefinitions: () =>
|
|
432
|
+
hasDefinitions: () => state.reader.hasDefinitions(),
|
|
427
433
|
},
|
|
428
434
|
objectives,
|
|
429
435
|
);
|
|
@@ -448,14 +454,7 @@ export const runSmtlibScript = (
|
|
|
448
454
|
!hasAssumptions &&
|
|
449
455
|
settings.parameters.get("opt.incremental") !== "true",
|
|
450
456
|
});
|
|
451
|
-
optimizer.model
|
|
452
|
-
state.check = {
|
|
453
|
-
status,
|
|
454
|
-
context: undefined,
|
|
455
|
-
isOptimizing: true,
|
|
456
|
-
model: optimizer.model ?? undefined,
|
|
457
|
-
core: undefined,
|
|
458
|
-
};
|
|
457
|
+
setCheck(status, { isOptimizing: true, model: optimizer.model ?? undefined });
|
|
459
458
|
print(getVerdict(status));
|
|
460
459
|
return true;
|
|
461
460
|
} catch (error) {
|
|
@@ -466,13 +465,7 @@ export const runSmtlibScript = (
|
|
|
466
465
|
}
|
|
467
466
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
468
467
|
optimizer.release();
|
|
469
|
-
|
|
470
|
-
status: L_UNDEF,
|
|
471
|
-
context: undefined,
|
|
472
|
-
isOptimizing: true,
|
|
473
|
-
model: undefined,
|
|
474
|
-
core: undefined,
|
|
475
|
-
};
|
|
468
|
+
setCheck(L_UNDEF, { isOptimizing: true });
|
|
476
469
|
print("unknown");
|
|
477
470
|
return true;
|
|
478
471
|
} finally {
|
|
@@ -481,12 +474,11 @@ export const runSmtlibScript = (
|
|
|
481
474
|
}
|
|
482
475
|
};
|
|
483
476
|
const resetOptimizer = () => {
|
|
484
|
-
|
|
485
|
-
|
|
477
|
+
state.optimizer?.release();
|
|
478
|
+
state.optimizer = undefined;
|
|
486
479
|
};
|
|
487
480
|
// The port keeps answering with the smt kernel where it lacks a piece of the logic's strategy.
|
|
488
481
|
const solveWithStrategy = () => {
|
|
489
|
-
const state = script.state;
|
|
490
482
|
const goal = getGoal();
|
|
491
483
|
const strategy =
|
|
492
484
|
settings.parameters.get("tactic.default_tactic") ??
|
|
@@ -516,8 +508,12 @@ export const runSmtlibScript = (
|
|
|
516
508
|
isFindingMacros: settings.isFindingMacros,
|
|
517
509
|
setup: getSetup(),
|
|
518
510
|
});
|
|
511
|
+
// mk_special_solver_for_logic gives these logics the finite-domain solver, incremental or not.
|
|
512
|
+
const isUsingFdSolver = () =>
|
|
513
|
+
(state.logic === "QF_FD" || state.logic === "SAT") &&
|
|
514
|
+
!settings.isProducingProofs &&
|
|
515
|
+
!settings.parameters.has("tactic.default_tactic");
|
|
519
516
|
const checkSat = (extra: number[]) => {
|
|
520
|
-
const state = script.state;
|
|
521
517
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
522
518
|
// opt::context::optimize answers as the search of the hard constraints does: once they are
|
|
523
519
|
// satisfiable, optsmt and maxsmt only improve the model. The unported parts of optimization
|
|
@@ -532,14 +528,9 @@ export const runSmtlibScript = (
|
|
|
532
528
|
const isAssuming = isNamed || extra.length > 0;
|
|
533
529
|
if (isAssuming) state.isIncremental = true;
|
|
534
530
|
if (!isOptimizing) state.hasChecked = true;
|
|
535
|
-
// mk_special_solver_for_logic gives these logics the finite-domain solver, incremental or not.
|
|
536
|
-
const isFd =
|
|
537
|
-
(state.logic === "QF_FD" || state.logic === "SAT") &&
|
|
538
|
-
!settings.isProducingProofs &&
|
|
539
|
-
!settings.parameters.has("tactic.default_tactic");
|
|
540
531
|
const assumptions = isNamed ? [...names, ...extra] : extra;
|
|
541
532
|
const kernel =
|
|
542
|
-
isAssuming || (state.isIncremental && !isOptimizing && !
|
|
533
|
+
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver())
|
|
543
534
|
? checkKernel(assumptions)
|
|
544
535
|
: undefined;
|
|
545
536
|
// Z3 retries a quantifier-free problem with its tactic when the incremental kernel gives up.
|
|
@@ -551,24 +542,16 @@ export const runSmtlibScript = (
|
|
|
551
542
|
manager.limit.inc())
|
|
552
543
|
? { ...solveWithStrategy(), core: undefined }
|
|
553
544
|
: kernel;
|
|
554
|
-
solved.
|
|
555
|
-
state.check = {
|
|
556
|
-
status: solved.result,
|
|
545
|
+
setCheck(solved.result, {
|
|
557
546
|
context: solved.context,
|
|
558
547
|
isOptimizing,
|
|
559
548
|
model: solved.model,
|
|
560
549
|
core: solved.core ?? solved.context?.unsatCore ?? [],
|
|
561
|
-
};
|
|
550
|
+
});
|
|
562
551
|
print(getVerdict(solved.result));
|
|
563
552
|
} catch (error) {
|
|
564
553
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
565
|
-
|
|
566
|
-
status: L_UNDEF,
|
|
567
|
-
context: undefined,
|
|
568
|
-
isOptimizing,
|
|
569
|
-
model: undefined,
|
|
570
|
-
core: undefined,
|
|
571
|
-
};
|
|
554
|
+
setCheck(L_UNDEF, { isOptimizing });
|
|
572
555
|
print("unknown");
|
|
573
556
|
} finally {
|
|
574
557
|
state.manager.limit.release();
|
|
@@ -576,27 +559,38 @@ export const runSmtlibScript = (
|
|
|
576
559
|
}
|
|
577
560
|
};
|
|
578
561
|
const getModel = (list: SmtList) => {
|
|
579
|
-
const check =
|
|
562
|
+
const check = state.check;
|
|
580
563
|
if (!settings.isProducingModels || check === undefined || check.status === L_FALSE)
|
|
581
564
|
throw new SmtParseError("model is not available", list.end);
|
|
582
565
|
if (check.model !== undefined) return check.model;
|
|
583
566
|
if (check.isOptimizing) throw new SmtUnsupportedError("the models of optimization");
|
|
584
567
|
if (check.context === undefined && check.status !== L_TRUE)
|
|
585
568
|
throw new SmtUnsupportedError("the model of a canceled search");
|
|
586
|
-
const model = check.context?.getModel() ?? new ProtoModel(
|
|
569
|
+
const model = check.context?.getModel() ?? new ProtoModel(state.manager);
|
|
587
570
|
model.incRef();
|
|
588
571
|
check.model = model;
|
|
589
572
|
return model;
|
|
590
573
|
};
|
|
591
574
|
const clearCheck = () => {
|
|
592
|
-
|
|
593
|
-
|
|
575
|
+
state.check?.model?.decRef();
|
|
576
|
+
state.check = undefined;
|
|
577
|
+
};
|
|
578
|
+
// The check holds a reference to its model until clearCheck.
|
|
579
|
+
const setCheck = (status: number, result: Partial<Omit<CheckResult, "status">> = {}) => {
|
|
580
|
+
result.model?.incRef();
|
|
581
|
+
state.check = {
|
|
582
|
+
status,
|
|
583
|
+
context: undefined,
|
|
584
|
+
isOptimizing: false,
|
|
585
|
+
model: undefined,
|
|
586
|
+
core: undefined,
|
|
587
|
+
...result,
|
|
588
|
+
};
|
|
594
589
|
};
|
|
595
590
|
// cmd_context::mk_solver: mk_solver_for_logic makes the incremental solver the smt kernel unless
|
|
596
591
|
// the logic, the default tactic or the sat parameters pick a sat solver. Under sat.euf that
|
|
597
592
|
// solver is inc_sat_solver in euf mode; the other sat solvers only store their assertions.
|
|
598
593
|
const resetKernel = () => {
|
|
599
|
-
const state = script.state;
|
|
600
594
|
const logic = state.logic;
|
|
601
595
|
const parameters = settings.parameters;
|
|
602
596
|
const isProofsEnabled = settings.isProducingProofs || state.isProofsEnabled === true;
|
|
@@ -615,10 +609,13 @@ export const runSmtlibScript = (
|
|
|
615
609
|
isEuf && !isFdSolver && parameters.get("sat.smt") !== "true"
|
|
616
610
|
? new IncSatSolver(state.manager, getSatParams(parameters), true, mkThSolver)
|
|
617
611
|
: undefined;
|
|
612
|
+
for (let index = 0; index < state.scopes.length; index++) {
|
|
613
|
+
state.kernel?.push();
|
|
614
|
+
useEufSolver((solver) => solver.push());
|
|
615
|
+
}
|
|
618
616
|
};
|
|
619
617
|
// The parts of sat.euf that are not ported leave its answers to the smt kernel.
|
|
620
618
|
const useEufSolver = <Result>(action: (solver: IncSatSolver) => Result) => {
|
|
621
|
-
const state = script.state;
|
|
622
619
|
const solver = state.eufSolver;
|
|
623
620
|
if (solver === undefined) return undefined;
|
|
624
621
|
try {
|
|
@@ -632,7 +629,6 @@ export const runSmtlibScript = (
|
|
|
632
629
|
};
|
|
633
630
|
// solver_na2as asserts a named assertion as an implication from its name.
|
|
634
631
|
const assertInKernel = (formula: number, name: number) => {
|
|
635
|
-
const state = script.state;
|
|
636
632
|
const manager = state.manager;
|
|
637
633
|
const asserted = name === -1 ? formula : manager.mkApp(OP_IMPLIES, [name, formula], SORT_BOOL);
|
|
638
634
|
manager.incRef(asserted);
|
|
@@ -641,7 +637,6 @@ export const runSmtlibScript = (
|
|
|
641
637
|
manager.decRef(asserted);
|
|
642
638
|
};
|
|
643
639
|
const checkKernel = (assumptions: number[]) => {
|
|
644
|
-
const state = script.state;
|
|
645
640
|
const kernel = state.kernel;
|
|
646
641
|
const found = useEufSolver((solver) => {
|
|
647
642
|
const result = solver.check(assumptions);
|
|
@@ -666,31 +661,30 @@ export const runSmtlibScript = (
|
|
|
666
661
|
core: undefined,
|
|
667
662
|
};
|
|
668
663
|
};
|
|
669
|
-
let pendingText = "";
|
|
670
664
|
const printDiagnostic = (line: string) => print(line, !settings.isDiagnosticOnStdout);
|
|
671
665
|
const write = (text: string, isDiagnostic: boolean) => {
|
|
672
|
-
const lines =
|
|
673
|
-
|
|
666
|
+
const lines = text.split("\n");
|
|
667
|
+
const rest = lines.pop() ?? "";
|
|
674
668
|
for (const line of lines) (isDiagnostic ? printDiagnostic : print)(line);
|
|
669
|
+
pendingText += rest;
|
|
675
670
|
};
|
|
676
671
|
const getSetup = () => ({
|
|
677
|
-
logic:
|
|
672
|
+
logic: state.logic,
|
|
678
673
|
isAutoConfig:
|
|
679
674
|
settings.parameters.get("auto_config") !== "false" &&
|
|
680
675
|
settings.parameters.get("smt.auto_config") !== "false",
|
|
681
676
|
});
|
|
682
677
|
const getTacticEnvironment = () => ({
|
|
683
|
-
manager:
|
|
678
|
+
manager: state.manager,
|
|
684
679
|
isMbqi: settings.isMbqi,
|
|
685
680
|
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
686
681
|
isFindingMacros: settings.isFindingMacros,
|
|
687
682
|
setup: getSetup(),
|
|
688
683
|
write,
|
|
689
684
|
parameters: settings.parameters,
|
|
690
|
-
hasDefinitions: () =>
|
|
685
|
+
hasDefinitions: () => state.reader.hasDefinitions(),
|
|
691
686
|
});
|
|
692
687
|
const getDatalog = () => {
|
|
693
|
-
const state = script.state;
|
|
694
688
|
state.datalog ??= createDatalogContext(
|
|
695
689
|
state.manager,
|
|
696
690
|
settings.parameters,
|
|
@@ -701,7 +695,6 @@ export const runSmtlibScript = (
|
|
|
701
695
|
const getTactic = (sexpr: SExpr, end: SmtList["end"]) =>
|
|
702
696
|
compileTactic(getTacticEnvironment(), sexpr, end);
|
|
703
697
|
const getGoal = (isTrackingDependencies = false) => {
|
|
704
|
-
const state = script.state;
|
|
705
698
|
const goal = new Goal(state.manager);
|
|
706
699
|
goal.isProofsEnabled = settings.isProducingProofs || state.isProofsEnabled === true;
|
|
707
700
|
goal.isCoresEnabled = settings.isProducingUnsatCores;
|
|
@@ -714,11 +707,18 @@ export const runSmtlibScript = (
|
|
|
714
707
|
);
|
|
715
708
|
return goal;
|
|
716
709
|
};
|
|
717
|
-
const hasNames = () =>
|
|
718
|
-
|
|
719
|
-
|
|
710
|
+
const hasNames = () => state.names.some((name) => name !== -1);
|
|
711
|
+
// parse_check_sat shrinks the expression stack once the check has run.
|
|
712
|
+
const checkSatAssuming = (items: SmtList["items"]) => {
|
|
713
|
+
const literals: number[] = [];
|
|
714
|
+
try {
|
|
715
|
+
for (const item of items) literals.push(state.reader.parseFormula(item));
|
|
716
|
+
checkSat(literals);
|
|
717
|
+
} finally {
|
|
718
|
+
for (const literal of literals) state.manager.decRef(literal);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
720
721
|
const addObjective = (list: SmtList, isMax: boolean) => {
|
|
721
|
-
const state = script.state;
|
|
722
722
|
const term = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
723
723
|
const sort = state.manager.sorts[term];
|
|
724
724
|
if (sort !== SORT_INT && sort !== SORT_REAL && !state.manager.isBvSort(sort))
|
|
@@ -734,7 +734,6 @@ export const runSmtlibScript = (
|
|
|
734
734
|
});
|
|
735
735
|
};
|
|
736
736
|
const releaseObjectives = (size: number, softSize: number) => {
|
|
737
|
-
const state = script.state;
|
|
738
737
|
for (const index of state.softTrail.splice(softSize).reverse()) {
|
|
739
738
|
const objective = state.objectives[index];
|
|
740
739
|
state.manager.decRef(objective.terms.pop() as number);
|
|
@@ -744,13 +743,11 @@ export const runSmtlibScript = (
|
|
|
744
743
|
if (objective.type !== O_MAXSMT) state.manager.decRef(objective.term);
|
|
745
744
|
};
|
|
746
745
|
const restoreAssertions = (size: number) => {
|
|
747
|
-
const state = script.state;
|
|
748
746
|
for (const assertion of state.assertions.splice(size)) state.manager.decRef(assertion);
|
|
749
747
|
for (const name of state.names.splice(size)) if (name !== -1) state.manager.decRef(name);
|
|
750
748
|
state.assertionTexts.length = size;
|
|
751
749
|
};
|
|
752
750
|
const instantiate = (list: SmtList, isNested: boolean) => {
|
|
753
|
-
const state = script.state;
|
|
754
751
|
const manager = state.manager;
|
|
755
752
|
const outer = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
756
753
|
if (manager.kinds[outer] !== KIND_QUANTIFIER)
|
|
@@ -781,700 +778,839 @@ export const runSmtlibScript = (
|
|
|
781
778
|
manager.decRef(result);
|
|
782
779
|
manager.decRef(substituted);
|
|
783
780
|
};
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
if (logicError !== undefined) {
|
|
791
|
-
state.manager.decRef(assertion.formula);
|
|
792
|
-
throw new SmtParseError(logicError, list.end);
|
|
793
|
-
}
|
|
794
|
-
state.assertions.push(assertion.formula);
|
|
795
|
-
state.assertionTexts.push(
|
|
796
|
-
text.slice(term.offset, (term.kind === "list" ? term.end : term).endOffset).trim(),
|
|
797
|
-
);
|
|
798
|
-
if (state.hasChecked) state.isIncremental = true;
|
|
799
|
-
resetOptimizer();
|
|
800
|
-
if (!settings.isProducingUnsatCores || assertion.name === undefined) state.names.push(-1);
|
|
801
|
-
else {
|
|
802
|
-
const manager = state.manager;
|
|
803
|
-
const answer = manager.mkApp(
|
|
804
|
-
manager.mkFuncDecl(assertion.name, [], SORT_BOOL, true),
|
|
805
|
-
[],
|
|
806
|
-
SORT_BOOL,
|
|
807
|
-
);
|
|
808
|
-
manager.incRef(answer);
|
|
809
|
-
state.names.push(answer);
|
|
810
|
-
}
|
|
811
|
-
assertInKernel(assertion.formula, state.names[state.names.length - 1]);
|
|
812
|
-
clearCheck();
|
|
813
|
-
},
|
|
814
|
-
"check-sat": (list) => checkSat(parseFormulas(list.items.slice(1))),
|
|
815
|
-
"declare-rel": (list) => {
|
|
816
|
-
const state = script.state;
|
|
817
|
-
const name = list.items[1];
|
|
818
|
-
const domain = list.items[2];
|
|
819
|
-
if (!isSymbol(name) || domain?.kind !== "list")
|
|
820
|
-
throw new SmtParseError("at least 2 arguments expected", list.end);
|
|
821
|
-
const decl = state.manager.mkFuncDecl(
|
|
822
|
-
name.text,
|
|
823
|
-
domain.items.map((sort) => state.reader.parseSort(sort)),
|
|
824
|
-
SORT_BOOL,
|
|
825
|
-
);
|
|
826
|
-
state.reader.insertFunc(decl, list.end);
|
|
827
|
-
getDatalog().registerPredicate(decl);
|
|
828
|
-
},
|
|
829
|
-
"declare-var": (list) => {
|
|
830
|
-
const state = script.state;
|
|
831
|
-
const name = list.items[1];
|
|
832
|
-
const sort = list.items[2];
|
|
833
|
-
if (!isSymbol(name) || sort === undefined)
|
|
834
|
-
throw new SmtParseError("invalid declare-var command, symbol and sort expected", list.end);
|
|
835
|
-
const manager = state.manager;
|
|
836
|
-
const range = state.reader.parseSort(sort);
|
|
837
|
-
const decl = manager.mkFuncDecl(name.text, [], range);
|
|
838
|
-
state.reader.insertFunc(decl, list.end);
|
|
839
|
-
getDatalog().registerVariable(manager.mkApp(decl, [], range));
|
|
840
|
-
},
|
|
841
|
-
rule: (list) => {
|
|
842
|
-
const rule = list.items[1];
|
|
843
|
-
if (rule === undefined) throw new SmtParseError("invalid rule, expected formula", list.end);
|
|
844
|
-
const name = list.items[2];
|
|
845
|
-
getDatalog().addRule(script.state.reader.parseFormula(rule), isSymbol(name) ? name.text : "");
|
|
846
|
-
},
|
|
847
|
-
query: (list) => {
|
|
848
|
-
const state = script.state;
|
|
849
|
-
const target = list.items[1];
|
|
850
|
-
if (!isSymbol(target))
|
|
851
|
-
throw new SmtParseError("invalid query command, argument expected", list.end);
|
|
852
|
-
const decls = state.reader.getFuncs(target.text);
|
|
853
|
-
if (decls.length !== 1)
|
|
781
|
+
// parser::parse_func_decl_ref: a name, or a name with its signature. Z3 ends the message of an
|
|
782
|
+
// unexpected token with the last identifier it read.
|
|
783
|
+
const getFuncDeclRef = (reference: SExpr) => {
|
|
784
|
+
if (isSymbol(reference)) {
|
|
785
|
+
const decls = state.reader.getFuncs(reference.text);
|
|
786
|
+
if (decls.length > 1)
|
|
854
787
|
throw new SmtParseError(
|
|
855
|
-
`
|
|
856
|
-
|
|
788
|
+
`ambiguous function declaration reference, provide full signature to disambiguate (<symbol> (<sort>*) <sort>) ${reference.text}`,
|
|
789
|
+
reference,
|
|
857
790
|
);
|
|
858
|
-
|
|
859
|
-
const relation = decls[0];
|
|
860
|
-
if (!datalog.isPredicateDecl(relation))
|
|
791
|
+
if (decls.length === 0)
|
|
861
792
|
throw new SmtParseError(
|
|
862
|
-
|
|
863
|
-
|
|
793
|
+
`invalid function declaration reference, unknown function ${reference.text}`,
|
|
794
|
+
reference,
|
|
864
795
|
);
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
796
|
+
return decls[0];
|
|
797
|
+
}
|
|
798
|
+
const name = reference.kind === "list" ? (reference.items[0] ?? reference.end) : reference;
|
|
799
|
+
if (reference.kind !== "list" || name.kind !== "symbol") {
|
|
800
|
+
if (name.kind === "list")
|
|
801
|
+
throw new SmtUnsupportedError("an indexed function declaration reference");
|
|
802
|
+
throw new SmtParseError(
|
|
803
|
+
"invalid function declaration reference, symbol or '(' expected got query",
|
|
804
|
+
name,
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
const domain = reference.items[1] ?? reference.end;
|
|
808
|
+
if (domain.kind !== "list")
|
|
809
|
+
throw new SmtParseError(
|
|
810
|
+
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.kind === "symbol" || domain.kind === "keyword" ? domain.text : name.text}`,
|
|
811
|
+
domain,
|
|
812
|
+
);
|
|
813
|
+
const sorts = domain.items.map((sort) => state.reader.parseSort(sort));
|
|
814
|
+
if (reference.items[2] === undefined)
|
|
815
|
+
throw new SmtParseError("Invalid function name invalid sort, unexpected ')'", reference.end);
|
|
816
|
+
const range = state.reader.parseSort(reference.items[2]);
|
|
817
|
+
const follower = reference.items[3] ?? reference.end;
|
|
818
|
+
const found = state.reader.getFuncs(name.text).find((decl) => {
|
|
819
|
+
const funcDecl = state.manager.funcDecls[decl];
|
|
820
|
+
return (
|
|
821
|
+
funcDecl.range === range &&
|
|
822
|
+
funcDecl.domain.length === sorts.length &&
|
|
823
|
+
funcDecl.domain.every((sort, index) => sort === sorts[index])
|
|
824
|
+
);
|
|
825
|
+
});
|
|
826
|
+
if (found === undefined)
|
|
827
|
+
throw new SmtParseError(
|
|
828
|
+
`invalid function declaration reference, unknown indexed function ${name.text}`,
|
|
829
|
+
follower,
|
|
830
|
+
);
|
|
831
|
+
if (follower !== reference.end)
|
|
832
|
+
throw new SmtUnsupportedError("a function declaration reference with trailing terms");
|
|
833
|
+
return found;
|
|
834
|
+
};
|
|
835
|
+
const runCommand = new Map<string, (list: SmtList) => void>([
|
|
836
|
+
[
|
|
837
|
+
"assert",
|
|
838
|
+
(list) => {
|
|
839
|
+
const term = list.items[1] ?? list.end;
|
|
840
|
+
const assertion = state.reader.parseAssertion(term);
|
|
841
|
+
const logicError = state.reader.getLogicError(assertion.formula);
|
|
842
|
+
if (logicError !== undefined) {
|
|
843
|
+
state.manager.decRef(assertion.formula);
|
|
844
|
+
throw new SmtParseError(logicError, list.end);
|
|
845
|
+
}
|
|
846
|
+
state.assertions.push(assertion.formula);
|
|
847
|
+
state.assertionTexts.push(
|
|
848
|
+
text.slice(term.offset, (term.kind === "list" ? term.end : term).endOffset).trim(),
|
|
908
849
|
);
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
if (
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
850
|
+
if (state.hasChecked) state.isIncremental = true;
|
|
851
|
+
resetOptimizer();
|
|
852
|
+
if (!settings.isProducingUnsatCores || assertion.name === undefined) state.names.push(-1);
|
|
853
|
+
else {
|
|
854
|
+
const manager = state.manager;
|
|
855
|
+
const answer = manager.mkApp(
|
|
856
|
+
manager.mkFuncDecl(assertion.name, [], SORT_BOOL, true),
|
|
857
|
+
[],
|
|
858
|
+
SORT_BOOL,
|
|
859
|
+
);
|
|
860
|
+
manager.incRef(answer);
|
|
861
|
+
state.names.push(answer);
|
|
862
|
+
}
|
|
863
|
+
assertInKernel(assertion.formula, state.names[state.names.length - 1]);
|
|
864
|
+
clearCheck();
|
|
865
|
+
},
|
|
866
|
+
],
|
|
867
|
+
["check-sat", (list) => checkSatAssuming(list.items.slice(1))],
|
|
868
|
+
[
|
|
869
|
+
"declare-rel",
|
|
870
|
+
(list) => {
|
|
871
|
+
const name = list.items[1];
|
|
872
|
+
const domain = list.items[2];
|
|
873
|
+
if (!isSymbol(name) || domain?.kind !== "list")
|
|
874
|
+
throw new SmtParseError("at least 2 arguments expected", list.end);
|
|
875
|
+
const decl = state.manager.mkFuncDecl(
|
|
876
|
+
name.text,
|
|
877
|
+
domain.items.map((sort) => state.reader.parseSort(sort)),
|
|
878
|
+
SORT_BOOL,
|
|
879
|
+
);
|
|
880
|
+
state.reader.insertFunc(decl, list.end);
|
|
881
|
+
getDatalog().registerPredicate(decl);
|
|
882
|
+
},
|
|
883
|
+
],
|
|
884
|
+
[
|
|
885
|
+
"declare-var",
|
|
886
|
+
(list) => {
|
|
887
|
+
const name = list.items[1];
|
|
888
|
+
const sort = list.items[2];
|
|
889
|
+
if (!isSymbol(name) || sort === undefined)
|
|
890
|
+
throw new SmtParseError(
|
|
891
|
+
"invalid declare-var command, symbol and sort expected",
|
|
892
|
+
list.end,
|
|
893
|
+
);
|
|
894
|
+
const manager = state.manager;
|
|
895
|
+
const range = state.reader.parseSort(sort);
|
|
896
|
+
const decl = manager.mkFuncDecl(name.text, [], range);
|
|
897
|
+
state.reader.insertFunc(decl, list.end);
|
|
898
|
+
getDatalog().registerVariable(manager.mkApp(decl, [], range));
|
|
899
|
+
},
|
|
900
|
+
],
|
|
901
|
+
[
|
|
902
|
+
"rule",
|
|
903
|
+
(list) => {
|
|
904
|
+
const rule = list.items[1];
|
|
905
|
+
if (rule === undefined) throw new SmtParseError("invalid rule, expected formula", list.end);
|
|
906
|
+
const name = list.items[2];
|
|
907
|
+
getDatalog().addRule(state.reader.parseFormula(rule), isSymbol(name) ? name.text : "");
|
|
908
|
+
},
|
|
909
|
+
],
|
|
910
|
+
[
|
|
911
|
+
"query",
|
|
912
|
+
(list) => {
|
|
913
|
+
if (list.items[1] === undefined)
|
|
914
|
+
throw new SmtParseError("invalid query command, argument expected", list.end);
|
|
915
|
+
const relation = getFuncDeclRef(list.items[1]);
|
|
916
|
+
const datalog = getDatalog();
|
|
917
|
+
// dl_query_cmd::set_next_arg runs once the parser is past the reference.
|
|
918
|
+
const follower = list.items[2] ?? list.end;
|
|
919
|
+
if (!datalog.isPredicateDecl(relation))
|
|
920
|
+
throw new SmtParseError(
|
|
921
|
+
"Invalid query argument, expected a predicate registered as a relation",
|
|
922
|
+
follower,
|
|
923
|
+
);
|
|
924
|
+
if (follower.kind !== "keyword" && follower !== list.end)
|
|
925
|
+
throw new SmtParseError("invalid command argument, keyword expected", follower);
|
|
926
|
+
for (const assertion of state.assertions) datalog.assertExpr(assertion);
|
|
927
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
928
|
+
state.manager.limit.push(settings.rlimit);
|
|
929
|
+
try {
|
|
930
|
+
print(getVerdict(datalog.relQuery(relation)));
|
|
931
|
+
} catch (error) {
|
|
932
|
+
if (!(error instanceof SmtTacticError)) throw error;
|
|
933
|
+
print(`(error "query failed: ${error.message}")`);
|
|
934
|
+
print("unknown");
|
|
935
|
+
} finally {
|
|
936
|
+
state.manager.limit.pop();
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
],
|
|
940
|
+
[
|
|
941
|
+
"check-sat-using",
|
|
942
|
+
(list) => {
|
|
943
|
+
const params = getCommandParams(list.items, CHECK_SAT_USING_PARAMETERS);
|
|
944
|
+
if (list.items[1] === undefined)
|
|
945
|
+
throw new SmtParseError("check-sat-using needs a tactic argument", list.end);
|
|
946
|
+
const builder = getTactic(list.items[1], list.end);
|
|
947
|
+
const tactic = builder.build(params);
|
|
948
|
+
clearCheck();
|
|
949
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
950
|
+
state.manager.limit.push(settings.rlimit);
|
|
951
|
+
try {
|
|
952
|
+
const checked = checkSatUsing(tactic, getGoal(builder.isTrackingDependencies));
|
|
953
|
+
setCheck(checked.status, {
|
|
954
|
+
model: checked.model,
|
|
955
|
+
core:
|
|
956
|
+
builder.isTrackingDependencies || !hasNames()
|
|
957
|
+
? getDependencyValues(checked.core)
|
|
958
|
+
: undefined,
|
|
959
|
+
reasonUnknown: checked.reasonUnknown,
|
|
960
|
+
});
|
|
961
|
+
print(getVerdict(checked.status));
|
|
962
|
+
} finally {
|
|
963
|
+
state.manager.limit.pop();
|
|
964
|
+
}
|
|
965
|
+
},
|
|
966
|
+
],
|
|
967
|
+
[
|
|
968
|
+
"check-sat-assuming",
|
|
969
|
+
(list) => {
|
|
970
|
+
const literals = list.items[1];
|
|
971
|
+
if (literals?.kind !== "list")
|
|
972
|
+
throw new SmtParseError(
|
|
973
|
+
"invalid check-sat-assuming command, '(' expected",
|
|
974
|
+
literals ?? list.end,
|
|
975
|
+
);
|
|
976
|
+
checkSatAssuming(literals.items);
|
|
977
|
+
},
|
|
978
|
+
],
|
|
979
|
+
[
|
|
980
|
+
"get-consequences",
|
|
981
|
+
(list) => {
|
|
982
|
+
const manager = state.manager;
|
|
983
|
+
const [assumptions, vars] = [list.items[1], list.items[2]].map((terms) => {
|
|
984
|
+
if (terms === undefined)
|
|
985
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
986
|
+
if (terms.kind !== "list")
|
|
987
|
+
throw new SmtParseError("invalid list of terms, '(' expected", terms);
|
|
988
|
+
return terms.items.map((item) => state.reader.parseTerm(item));
|
|
989
|
+
});
|
|
990
|
+
if (list.items.length > 3)
|
|
991
|
+
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
992
|
+
clearCheck();
|
|
993
|
+
manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
994
|
+
manager.limit.push(settings.rlimit);
|
|
995
|
+
const names = state.names.filter((name) => name !== -1);
|
|
996
|
+
try {
|
|
997
|
+
if (isUsingFdSolver()) {
|
|
998
|
+
if (names.length > 0)
|
|
999
|
+
throw new SmtUnsupportedError("the named assertions of the finite-domain solver");
|
|
1000
|
+
const found = getFdConsequences(
|
|
1001
|
+
manager,
|
|
1002
|
+
new Map(),
|
|
1003
|
+
state.assertions,
|
|
1004
|
+
assumptions,
|
|
1005
|
+
vars,
|
|
1006
|
+
);
|
|
1007
|
+
setCheck(found.result, { model: found.model });
|
|
1008
|
+
print(getVerdict(found.result));
|
|
1009
|
+
print("");
|
|
1010
|
+
for (const consequence of found.consequences.items) display(consequence);
|
|
1011
|
+
found.consequences.reset();
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
const kernel = state.kernel ?? new SmtKernel(manager, getKernelParams());
|
|
1015
|
+
if (state.kernel === undefined)
|
|
1016
|
+
for (const assertion of getNamedAssertions()) kernel.assertExpr(assertion);
|
|
1017
|
+
const found = getConsequences(kernel, [...names, ...assumptions], vars);
|
|
1018
|
+
setCheck(found.result, { context: kernel.context, core: kernel.context.unsatCore });
|
|
944
1019
|
print(getVerdict(found.result));
|
|
945
1020
|
print("");
|
|
946
1021
|
for (const consequence of found.consequences.items) display(consequence);
|
|
947
1022
|
found.consequences.reset();
|
|
948
|
-
|
|
1023
|
+
} finally {
|
|
1024
|
+
manager.limit.pop();
|
|
949
1025
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
found.consequences.reset();
|
|
965
|
-
} finally {
|
|
966
|
-
manager.limit.pop();
|
|
967
|
-
}
|
|
968
|
-
},
|
|
969
|
-
minimize: (list) => addObjective(list, false),
|
|
970
|
-
maximize: (list) => addObjective(list, true),
|
|
971
|
-
"assert-soft": (list) => {
|
|
972
|
-
const state = script.state;
|
|
973
|
-
const formula = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
974
|
-
if (state.manager.sorts[formula] !== SORT_BOOL)
|
|
975
|
-
throw new SmtParseError("Invalid type for expression. Expected Boolean type.", list.end);
|
|
976
|
-
const parameters = getSoftParameters(list.items.slice(2));
|
|
977
|
-
resetOptimizer();
|
|
978
|
-
const existing = state.objectives.findIndex(
|
|
979
|
-
(objective) => objective.type === O_MAXSMT && objective.id === parameters.id,
|
|
980
|
-
);
|
|
981
|
-
const index = existing === -1 ? state.objectives.length : existing;
|
|
982
|
-
if (existing === -1)
|
|
983
|
-
state.objectives.push({
|
|
984
|
-
type: O_MAXSMT,
|
|
985
|
-
term: -1,
|
|
986
|
-
terms: [],
|
|
987
|
-
weights: [],
|
|
988
|
-
id: parameters.id,
|
|
989
|
-
});
|
|
990
|
-
if (parameters.weight.isZero()) return;
|
|
991
|
-
state.manager.incRef(formula);
|
|
992
|
-
state.objectives[index].terms.push(formula);
|
|
993
|
-
state.objectives[index].weights.push(parameters.weight);
|
|
994
|
-
state.softTrail.push(index);
|
|
995
|
-
},
|
|
996
|
-
push: (list) => {
|
|
997
|
-
const state = script.state;
|
|
998
|
-
clearCheck();
|
|
999
|
-
for (let index = getScopeCount(list); index > 0; index--) {
|
|
1000
|
-
state.scopes.push({
|
|
1001
|
-
assertions: state.assertions.length,
|
|
1002
|
-
objectives: state.objectives.length,
|
|
1003
|
-
softTrail: state.softTrail.length,
|
|
1004
|
-
});
|
|
1005
|
-
state.reader.push();
|
|
1006
|
-
state.isIncremental = true;
|
|
1007
|
-
state.kernel?.push();
|
|
1008
|
-
useEufSolver((solver) => solver.push());
|
|
1009
|
-
}
|
|
1010
|
-
},
|
|
1011
|
-
pop: (list) => {
|
|
1012
|
-
const state = script.state;
|
|
1013
|
-
const count = getScopeCount(list);
|
|
1014
|
-
if (count > state.scopes.length)
|
|
1015
|
-
throw new SmtParseError(
|
|
1016
|
-
"invalid pop command, argument is greater than the current stack depth",
|
|
1017
|
-
list.end,
|
|
1026
|
+
},
|
|
1027
|
+
],
|
|
1028
|
+
["minimize", (list) => addObjective(list, false)],
|
|
1029
|
+
["maximize", (list) => addObjective(list, true)],
|
|
1030
|
+
[
|
|
1031
|
+
"assert-soft",
|
|
1032
|
+
(list) => {
|
|
1033
|
+
const formula = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
1034
|
+
if (state.manager.sorts[formula] !== SORT_BOOL)
|
|
1035
|
+
throw new SmtParseError("Invalid type for expression. Expected Boolean type.", list.end);
|
|
1036
|
+
const parameters = getSoftParameters(list.items.slice(2));
|
|
1037
|
+
resetOptimizer();
|
|
1038
|
+
const existing = state.objectives.findIndex(
|
|
1039
|
+
(objective) => objective.type === O_MAXSMT && objective.id === parameters.id,
|
|
1018
1040
|
);
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1041
|
+
const index = existing === -1 ? state.objectives.length : existing;
|
|
1042
|
+
if (existing === -1)
|
|
1043
|
+
state.objectives.push({
|
|
1044
|
+
type: O_MAXSMT,
|
|
1045
|
+
term: -1,
|
|
1046
|
+
terms: [],
|
|
1047
|
+
weights: [],
|
|
1048
|
+
id: parameters.id,
|
|
1049
|
+
});
|
|
1050
|
+
if (parameters.weight.isZero()) return;
|
|
1051
|
+
state.manager.incRef(formula);
|
|
1052
|
+
state.objectives[index].terms.push(formula);
|
|
1053
|
+
state.objectives[index].weights.push(parameters.weight);
|
|
1054
|
+
state.softTrail.push(index);
|
|
1055
|
+
},
|
|
1056
|
+
],
|
|
1057
|
+
[
|
|
1058
|
+
"push",
|
|
1059
|
+
(list) => {
|
|
1060
|
+
clearCheck();
|
|
1061
|
+
for (let index = getScopeCount(list); index > 0; index--) {
|
|
1062
|
+
state.scopes.push({
|
|
1063
|
+
assertions: state.assertions.length,
|
|
1064
|
+
objectives: state.objectives.length,
|
|
1065
|
+
softTrail: state.softTrail.length,
|
|
1066
|
+
});
|
|
1067
|
+
state.reader.push();
|
|
1068
|
+
state.isIncremental = true;
|
|
1046
1069
|
state.kernel?.push();
|
|
1047
1070
|
useEufSolver((solver) => solver.push());
|
|
1048
1071
|
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1072
|
+
},
|
|
1073
|
+
],
|
|
1074
|
+
[
|
|
1075
|
+
"pop",
|
|
1076
|
+
(list) => {
|
|
1077
|
+
const count = getScopeCount(list);
|
|
1078
|
+
if (count > state.scopes.length)
|
|
1079
|
+
throw new SmtParseError(
|
|
1080
|
+
"invalid pop command, argument is greater than the current stack depth",
|
|
1081
|
+
list.end,
|
|
1082
|
+
);
|
|
1083
|
+
clearCheck();
|
|
1084
|
+
if (count === 0) return;
|
|
1085
|
+
state.isIncremental = true;
|
|
1086
|
+
const scope = state.scopes[state.scopes.length - count];
|
|
1087
|
+
state.kernel?.pop(count);
|
|
1088
|
+
useEufSolver((solver) => solver.pop(count));
|
|
1089
|
+
for (let index = 0; index < count; index++) state.reader.pop();
|
|
1090
|
+
restoreAssertions(scope.assertions);
|
|
1091
|
+
resetOptimizer();
|
|
1092
|
+
releaseObjectives(scope.objectives, scope.softTrail);
|
|
1093
|
+
state.scopes.length -= count;
|
|
1094
|
+
},
|
|
1095
|
+
],
|
|
1096
|
+
[
|
|
1097
|
+
"reset",
|
|
1098
|
+
() => {
|
|
1099
|
+
clearCheck();
|
|
1100
|
+
resetOptimizer();
|
|
1101
|
+
state = createState();
|
|
1102
|
+
},
|
|
1103
|
+
],
|
|
1104
|
+
[
|
|
1105
|
+
"reset-assertions",
|
|
1106
|
+
() => {
|
|
1107
|
+
clearCheck();
|
|
1108
|
+
restoreAssertions(0);
|
|
1109
|
+
resetOptimizer();
|
|
1110
|
+
releaseObjectives(0, 0);
|
|
1111
|
+
state.scopes = state.scopes.map(() => ({ assertions: 0, objectives: 0, softTrail: 0 }));
|
|
1112
|
+
if (state.isProofsEnabled !== undefined) resetKernel();
|
|
1113
|
+
state.isIncremental = state.scopes.length > 0;
|
|
1114
|
+
state.hasChecked = false;
|
|
1115
|
+
},
|
|
1116
|
+
],
|
|
1117
|
+
[
|
|
1118
|
+
"simplify",
|
|
1119
|
+
(list) => {
|
|
1120
|
+
const manager = state.manager;
|
|
1121
|
+
if (list.items.length < 2)
|
|
1122
|
+
throw new SmtParseError("invalid simplify command, argument expected", list.end);
|
|
1123
|
+
const term = state.reader.parseTerm(list.items[1]);
|
|
1124
|
+
manager.incRef(term);
|
|
1125
|
+
const rewriter = new Rewriter(
|
|
1126
|
+
manager,
|
|
1127
|
+
getRewriterOptions(manager, getSimplifyParams(list.items.slice(2))),
|
|
1128
|
+
);
|
|
1129
|
+
const simplified = rewriter.rewrite(term);
|
|
1130
|
+
rewriter.cleanup();
|
|
1131
|
+
display(simplified);
|
|
1132
|
+
rewriter.release();
|
|
1133
|
+
manager.decRef(simplified);
|
|
1134
|
+
manager.decRef(term);
|
|
1135
|
+
},
|
|
1136
|
+
],
|
|
1070
1137
|
// The Boolean rewriter alone matches the simplifier only on Boolean structure over constants.
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
throw new SmtParseError("invalid command, one argument expected", list.end);
|
|
1075
|
-
const term = script.state.reader.parseTerm(list.items[1]);
|
|
1076
|
-
manager.incRef(term);
|
|
1077
|
-
const visited = new Set<number>();
|
|
1078
|
-
const todo = [term];
|
|
1079
|
-
while (todo.length > 0) {
|
|
1080
|
-
const expr = todo.pop() as number;
|
|
1081
|
-
if (visited.has(expr)) continue;
|
|
1082
|
-
visited.add(expr);
|
|
1083
|
-
const family = manager.kinds[expr] === KIND_APP ? manager.getFamily(expr) : -1;
|
|
1084
|
-
if (family !== FAMILY_BASIC && family !== FAMILY_USER && !manager.isNumeral(expr))
|
|
1085
|
-
throw new SmtUnsupportedError("the command dbg-bool-flat-rewriter beyond Boolean terms");
|
|
1086
|
-
manager.pushArgs(expr, todo);
|
|
1087
|
-
}
|
|
1088
|
-
const rewriter = new Rewriter(manager, getRewriterOptions(manager, new Map()));
|
|
1089
|
-
const rewritten = rewriter.rewrite(term);
|
|
1090
|
-
display(rewritten);
|
|
1091
|
-
rewriter.release();
|
|
1092
|
-
manager.decRef(rewritten);
|
|
1093
|
-
manager.decRef(term);
|
|
1094
|
-
},
|
|
1095
|
-
apply: (list) => {
|
|
1096
|
-
const state = script.state;
|
|
1097
|
-
const params = getCommandParams(list.items, APPLY_PARAMETERS);
|
|
1098
|
-
if (list.items[1] === undefined)
|
|
1099
|
-
throw new SmtParseError("apply needs a tactic argument", list.end);
|
|
1100
|
-
const builder = getTactic(list.items[1], list.end);
|
|
1101
|
-
const tactic = builder.build(params);
|
|
1102
|
-
const isPrintingDependencies = params.get("print_dependencies") === true;
|
|
1103
|
-
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1104
|
-
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1105
|
-
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1106
|
-
const input = getGoal(builder.isTrackingDependencies);
|
|
1107
|
-
const goals = (() => {
|
|
1108
|
-
try {
|
|
1109
|
-
return applyTactic(tactic, input);
|
|
1110
|
-
} catch (error) {
|
|
1111
|
-
if (!(error instanceof SmtTacticError)) throw error;
|
|
1112
|
-
print(`(error "tactic failed: ${error.message}")`);
|
|
1113
|
-
return undefined;
|
|
1114
|
-
}
|
|
1115
|
-
})();
|
|
1116
|
-
// apply_tactic_cmd releases the result goals and then the input goal.
|
|
1117
|
-
if (goals === undefined) {
|
|
1118
|
-
input.reset();
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
try {
|
|
1138
|
+
[
|
|
1139
|
+
"dbg-bool-flat-rewriter",
|
|
1140
|
+
(list) => {
|
|
1122
1141
|
const manager = state.manager;
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1142
|
+
if (list.items.length !== 2)
|
|
1143
|
+
throw new SmtParseError("invalid command, one argument expected", list.end);
|
|
1144
|
+
const term = state.reader.parseTerm(list.items[1]);
|
|
1145
|
+
manager.incRef(term);
|
|
1146
|
+
const visited = new Set<number>();
|
|
1147
|
+
const todo = [term];
|
|
1148
|
+
while (todo.length > 0) {
|
|
1149
|
+
const expr = todo.pop() as number;
|
|
1150
|
+
if (visited.has(expr)) continue;
|
|
1151
|
+
visited.add(expr);
|
|
1152
|
+
const family = manager.kinds[expr] === KIND_APP ? manager.getFamily(expr) : -1;
|
|
1153
|
+
if (family !== FAMILY_BASIC && family !== FAMILY_USER && !manager.isNumeral(expr))
|
|
1154
|
+
throw new SmtUnsupportedError(
|
|
1155
|
+
"the command dbg-bool-flat-rewriter beyond Boolean terms",
|
|
1156
|
+
);
|
|
1157
|
+
manager.pushArgs(expr, todo);
|
|
1158
|
+
}
|
|
1159
|
+
const rewriter = new Rewriter(manager, getRewriterOptions(manager, new Map()));
|
|
1160
|
+
const rewritten = rewriter.rewrite(term);
|
|
1161
|
+
display(rewritten);
|
|
1162
|
+
rewriter.release();
|
|
1163
|
+
manager.decRef(rewritten);
|
|
1164
|
+
manager.decRef(term);
|
|
1165
|
+
},
|
|
1166
|
+
],
|
|
1167
|
+
[
|
|
1168
|
+
"apply",
|
|
1169
|
+
(list) => {
|
|
1170
|
+
const params = getCommandParams(list.items, APPLY_PARAMETERS);
|
|
1171
|
+
if (list.items[1] === undefined)
|
|
1172
|
+
throw new SmtParseError("apply needs a tactic argument", list.end);
|
|
1173
|
+
const builder = getTactic(list.items[1], list.end);
|
|
1174
|
+
const tactic = builder.build(params);
|
|
1175
|
+
const isPrintingDependencies = params.get("print_dependencies") === true;
|
|
1176
|
+
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1177
|
+
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1178
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1179
|
+
const input = getGoal(builder.isTrackingDependencies);
|
|
1180
|
+
const goals = (() => {
|
|
1181
|
+
try {
|
|
1182
|
+
return applyTactic(tactic, input);
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
if (!(error instanceof SmtTacticError)) throw error;
|
|
1185
|
+
print(`(error "tactic failed: ${error.message}")`);
|
|
1186
|
+
return undefined;
|
|
1187
|
+
}
|
|
1188
|
+
})();
|
|
1189
|
+
// apply_tactic_cmd releases the result goals and then the input goal.
|
|
1190
|
+
if (goals === undefined) {
|
|
1191
|
+
input.reset();
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
try {
|
|
1195
|
+
const manager = state.manager;
|
|
1196
|
+
const environment = getPrintEnvironment();
|
|
1197
|
+
if (params.get("print") !== false)
|
|
1198
|
+
print(
|
|
1199
|
+
[
|
|
1200
|
+
"(goals",
|
|
1201
|
+
...goals.map((goal) =>
|
|
1202
|
+
[
|
|
1203
|
+
"(goal",
|
|
1204
|
+
...goal.forms.items.flatMap((form, index) => [
|
|
1205
|
+
...(isPrintingDependencies
|
|
1206
|
+
? [
|
|
1207
|
+
[
|
|
1208
|
+
" |-",
|
|
1209
|
+
...getDependencyValues(goal.getDependency(index)).map(format),
|
|
1210
|
+
].join(" "),
|
|
1211
|
+
]
|
|
1212
|
+
: []),
|
|
1213
|
+
` ${printExpr(state.manager, environment, form, 2)}`,
|
|
1214
|
+
]),
|
|
1215
|
+
` :precision ${PRECISION_NAMES[goal.precision]} :depth ${goal.depth})`,
|
|
1216
|
+
].join("\n"),
|
|
1217
|
+
),
|
|
1218
|
+
")",
|
|
1219
|
+
].join("\n"),
|
|
1220
|
+
);
|
|
1221
|
+
if (
|
|
1222
|
+
params.get("print_model_converter") === true &&
|
|
1223
|
+
input.converters.some(
|
|
1224
|
+
(entry) => !("definitions" in entry) || entry.definitions.length > 0,
|
|
1225
|
+
)
|
|
1152
1226
|
)
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1227
|
+
throw new SmtUnsupportedError("printing a model converter");
|
|
1228
|
+
if (params.get("print_benchmark") !== true) return;
|
|
1229
|
+
const assertions =
|
|
1230
|
+
goals.length === 1
|
|
1231
|
+
? goals[0].forms.items
|
|
1232
|
+
: [
|
|
1233
|
+
manager.mkOr(
|
|
1234
|
+
goals.map((goal) =>
|
|
1235
|
+
goal.forms.size === 1 ? goal.forms.items[0] : manager.mkAnd(goal.forms.items),
|
|
1236
|
+
),
|
|
1163
1237
|
),
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1238
|
+
];
|
|
1239
|
+
for (const assertion of assertions) manager.incRef(assertion);
|
|
1240
|
+
const visited = new Set<number>();
|
|
1241
|
+
const decls = new Set<number>();
|
|
1242
|
+
for (const assertion of assertions) {
|
|
1243
|
+
const todo = [assertion];
|
|
1244
|
+
while (todo.length > 0) {
|
|
1245
|
+
const expr = todo.pop() as number;
|
|
1246
|
+
if (visited.has(expr)) continue;
|
|
1247
|
+
visited.add(expr);
|
|
1248
|
+
if (manager.kinds[expr] === KIND_QUANTIFIER) {
|
|
1249
|
+
const data = manager.getQuantifier(expr);
|
|
1250
|
+
todo.push(data.body, ...data.patterns, ...data.noPatterns);
|
|
1251
|
+
} else if (manager.kinds[expr] === KIND_APP) {
|
|
1252
|
+
manager.pushArgs(expr, todo);
|
|
1253
|
+
const decl = manager.decls[expr];
|
|
1254
|
+
const family = manager.funcDecls[decl].family;
|
|
1255
|
+
if (family === FAMILY_USER || family === FAMILY_MODEL_VALUE) decls.add(decl);
|
|
1256
|
+
}
|
|
1183
1257
|
}
|
|
1184
1258
|
}
|
|
1259
|
+
const lines = [...decls].map((decl) => {
|
|
1260
|
+
const funcDecl = manager.funcDecls[decl];
|
|
1261
|
+
return renderFormat(
|
|
1262
|
+
mkSeq1(
|
|
1263
|
+
[
|
|
1264
|
+
mkText(getQuotedName(funcDecl.name)),
|
|
1265
|
+
mkSeq5(funcDecl.domain.map((sort) => formatSort(manager, sort))),
|
|
1266
|
+
formatSort(manager, funcDecl.range),
|
|
1267
|
+
],
|
|
1268
|
+
"declare-fun",
|
|
1269
|
+
),
|
|
1270
|
+
environment.options,
|
|
1271
|
+
);
|
|
1272
|
+
});
|
|
1273
|
+
for (const assertion of assertions)
|
|
1274
|
+
lines.push(`(assert ${printExpr(manager, environment, assertion, 8)})`);
|
|
1275
|
+
print([...lines, "(check-sat)"].join("\n"));
|
|
1276
|
+
for (const assertion of assertions) manager.decRef(assertion);
|
|
1277
|
+
} finally {
|
|
1278
|
+
for (const goal of goals) if (goal !== input) goal.reset();
|
|
1279
|
+
input.reset();
|
|
1185
1280
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1281
|
+
},
|
|
1282
|
+
],
|
|
1283
|
+
[
|
|
1284
|
+
"get-assertions",
|
|
1285
|
+
(list) => {
|
|
1286
|
+
if (!settings.isInteractive)
|
|
1287
|
+
throw new SmtParseError(
|
|
1288
|
+
"command is only available in interactive mode, use command (set-option :interactive-mode true)",
|
|
1289
|
+
list.end,
|
|
1290
|
+
);
|
|
1291
|
+
print(`(${state.assertionTexts.join("\n ")})`);
|
|
1292
|
+
},
|
|
1293
|
+
],
|
|
1294
|
+
[
|
|
1295
|
+
"get-unsat-core",
|
|
1296
|
+
(list) => {
|
|
1297
|
+
if (!settings.isProducingUnsatCores)
|
|
1298
|
+
throw new SmtParseError(
|
|
1299
|
+
"unsat core construction is not enabled, use command (set-option :produce-unsat-cores true)",
|
|
1300
|
+
list.end,
|
|
1198
1301
|
);
|
|
1302
|
+
const check = state.check;
|
|
1303
|
+
if (check === undefined || check.status !== L_FALSE)
|
|
1304
|
+
throw new SmtParseError("unsat core is not available", list.end);
|
|
1305
|
+
if (check.core === undefined)
|
|
1306
|
+
throw new SmtUnsupportedError("the unsat core of a tactic that drops dependencies");
|
|
1307
|
+
print(`(${check.core.map(format).join(" ")})`);
|
|
1308
|
+
},
|
|
1309
|
+
],
|
|
1310
|
+
[
|
|
1311
|
+
"eval",
|
|
1312
|
+
(list) => {
|
|
1313
|
+
const target = list.items[1];
|
|
1314
|
+
const term = target === undefined ? -1 : state.reader.parseTerm(target);
|
|
1315
|
+
if (list.items.length > 2) throw new SmtUnsupportedError("the parameters of eval");
|
|
1316
|
+
const model = getModel(list);
|
|
1317
|
+
if (term === -1) throw new SmtParseError("no arguments passed to eval", list.end);
|
|
1318
|
+
const manager = state.manager;
|
|
1319
|
+
manager.incRef(term);
|
|
1320
|
+
const value = model.eval(term, false);
|
|
1321
|
+
display(value);
|
|
1322
|
+
manager.decRef(value);
|
|
1323
|
+
manager.decRef(term);
|
|
1324
|
+
},
|
|
1325
|
+
],
|
|
1326
|
+
[
|
|
1327
|
+
"get-value",
|
|
1328
|
+
(list) => {
|
|
1329
|
+
const terms = list.items[1];
|
|
1330
|
+
if (terms?.kind !== "list")
|
|
1331
|
+
throw new SmtParseError("invalid get-value command, '(' expected", terms ?? list.end);
|
|
1332
|
+
const manager = state.manager;
|
|
1333
|
+
const exprs = terms.items.map((item) => state.reader.parseTerm(item));
|
|
1334
|
+
if (exprs.length === 0)
|
|
1335
|
+
throw new SmtParseError("invalid get-value command, empty list of terms", terms.end);
|
|
1336
|
+
if (list.items.length > 2) throw new SmtUnsupportedError("the parameters of get-value");
|
|
1337
|
+
const model = getModel(list);
|
|
1338
|
+
model.compact();
|
|
1339
|
+
// Z3 prints each term as the script spells it, from the end of the term before.
|
|
1340
|
+
const offsets = [
|
|
1341
|
+
terms.offset + 1,
|
|
1342
|
+
...terms.items.map((item) => (item.kind === "list" ? item.end : item).endOffset),
|
|
1343
|
+
];
|
|
1344
|
+
const lines = exprs.map((expr, index) => {
|
|
1345
|
+
manager.incRef(expr);
|
|
1346
|
+
const value = model.eval(expr, true);
|
|
1347
|
+
const line = `(${text.slice(offsets[index], offsets[index + 1]).trim()} ${format(value)})`;
|
|
1348
|
+
manager.decRef(value);
|
|
1349
|
+
manager.decRef(expr);
|
|
1350
|
+
return line;
|
|
1199
1351
|
});
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1352
|
+
print(`(${lines.join("\n ")})`);
|
|
1353
|
+
},
|
|
1354
|
+
],
|
|
1355
|
+
[
|
|
1356
|
+
"get-objectives",
|
|
1357
|
+
() => {
|
|
1358
|
+
const optimizer = state.optimizer;
|
|
1359
|
+
if (optimizer === undefined || state.check === undefined)
|
|
1360
|
+
throw new SmtUnsupportedError("the command get-objectives");
|
|
1361
|
+
print(optimizer.getObjectives(format));
|
|
1362
|
+
},
|
|
1363
|
+
],
|
|
1364
|
+
[
|
|
1365
|
+
"get-model",
|
|
1366
|
+
(list) => {
|
|
1367
|
+
if (list.items.length > 1) throw new SmtUnsupportedError("the index of get-model");
|
|
1368
|
+
const manager = state.manager;
|
|
1369
|
+
const model = getModel(list);
|
|
1370
|
+
model.compact();
|
|
1371
|
+
for (const decl of state.reader.getDeclaredFuncs()) {
|
|
1372
|
+
const funcDecl = manager.funcDecls[decl];
|
|
1373
|
+
if (
|
|
1374
|
+
funcDecl.family !== FAMILY_USER ||
|
|
1375
|
+
model.constInterps.has(decl) ||
|
|
1376
|
+
model.funcInterps.has(decl)
|
|
1377
|
+
)
|
|
1378
|
+
continue;
|
|
1379
|
+
const value = model.getSomeValue(funcDecl.range);
|
|
1380
|
+
if (funcDecl.domain.length === 0) {
|
|
1381
|
+
model.registerConst(decl, value);
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
const interp = new FuncInterp(manager, funcDecl.domain.length);
|
|
1385
|
+
interp.setElse(value);
|
|
1386
|
+
model.registerFunc(decl, interp);
|
|
1387
|
+
}
|
|
1388
|
+
model.addRecFuns();
|
|
1389
|
+
print(`(\n${printModel(manager, getPrintEnvironment(), model, 2)})`);
|
|
1390
|
+
},
|
|
1391
|
+
],
|
|
1392
|
+
["display", (list) => display(state.reader.parseTerm(list.items[1] ?? list.end))],
|
|
1393
|
+
[
|
|
1394
|
+
"dbg-lt",
|
|
1395
|
+
(list) => {
|
|
1396
|
+
const first = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
1397
|
+
const second = state.reader.parseTerm(list.items[2] ?? list.end);
|
|
1398
|
+
print(String(isAstLess(state.manager, first, second)));
|
|
1399
|
+
},
|
|
1400
|
+
],
|
|
1401
|
+
[
|
|
1402
|
+
"dbg-some-value",
|
|
1403
|
+
(list) => {
|
|
1404
|
+
display(
|
|
1405
|
+
getManagerSomeValue(state.manager, state.reader.parseSort(list.items[1] ?? list.end)),
|
|
1214
1406
|
);
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1407
|
+
},
|
|
1408
|
+
],
|
|
1409
|
+
[
|
|
1410
|
+
"dbg-used-vars",
|
|
1411
|
+
(list) => {
|
|
1412
|
+
const manager = state.manager;
|
|
1413
|
+
const term = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
1414
|
+
const body =
|
|
1415
|
+
manager.kinds[term] === KIND_QUANTIFIER ? manager.getQuantifier(term).body : term;
|
|
1416
|
+
const sorts = getFreeVarSorts(manager, body, manager.freeVarBounds[body]);
|
|
1417
|
+
const lines = sorts.map(
|
|
1418
|
+
(sort, index) =>
|
|
1419
|
+
`\n (${String(index).padEnd(6)} ${sort === undefined ? "<not-used>" : renderFormat(formatSort(manager, sort), settings.printOptions)})`,
|
|
1222
1420
|
);
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
print(optimizer.getObjectives(format));
|
|
1274
|
-
},
|
|
1275
|
-
"get-model": (list) => {
|
|
1276
|
-
if (list.items.length > 1) throw new SmtUnsupportedError("the index of get-model");
|
|
1277
|
-
const manager = script.state.manager;
|
|
1278
|
-
const model = getModel(list);
|
|
1279
|
-
model.compact();
|
|
1280
|
-
for (const decl of script.state.reader.getDeclaredFuncs()) {
|
|
1281
|
-
const funcDecl = manager.funcDecls[decl];
|
|
1421
|
+
print(`(vars${lines.join("")})`);
|
|
1422
|
+
},
|
|
1423
|
+
],
|
|
1424
|
+
[
|
|
1425
|
+
"dbg-elim-unused-vars",
|
|
1426
|
+
(list) => {
|
|
1427
|
+
const manager = state.manager;
|
|
1428
|
+
const term = state.reader.parseTerm(list.items[1] ?? list.end);
|
|
1429
|
+
if (manager.kinds[term] !== KIND_QUANTIFIER) {
|
|
1430
|
+
write(format(term), false);
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
display(elimUnusedVars(manager, term));
|
|
1434
|
+
},
|
|
1435
|
+
],
|
|
1436
|
+
["dbg-instantiate", (list) => instantiate(list, false)],
|
|
1437
|
+
["dbg-instantiate-nested", (list) => instantiate(list, true)],
|
|
1438
|
+
[
|
|
1439
|
+
"echo",
|
|
1440
|
+
(list) => {
|
|
1441
|
+
const message = list.items[1];
|
|
1442
|
+
if (message?.kind !== "string")
|
|
1443
|
+
throw new SmtParseError("invalid echo command, string expected", message ?? list.end);
|
|
1444
|
+
print(message.text);
|
|
1445
|
+
},
|
|
1446
|
+
],
|
|
1447
|
+
[
|
|
1448
|
+
"set-option",
|
|
1449
|
+
(list) => {
|
|
1450
|
+
const option = list.items[1];
|
|
1451
|
+
const keyword = option?.kind === "keyword" ? option.text : "";
|
|
1452
|
+
const optionName = `:${getParameterName(keyword)}`;
|
|
1453
|
+
const value = list.items[2];
|
|
1454
|
+
const isTrue = isSymbol(value, "true");
|
|
1455
|
+
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1456
|
+
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1457
|
+
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1458
|
+
if (keyword === ":interactive-mode") settings.isInteractive = isTrue;
|
|
1459
|
+
if (keyword === ":diagnostic-output-channel")
|
|
1460
|
+
settings.isDiagnosticOnStdout = value?.kind === "string" && value.text === "stdout";
|
|
1461
|
+
if (keyword === ":int-real-coercions" && !isTrue)
|
|
1462
|
+
throw new SmtUnsupportedError("the option :int-real-coercions false");
|
|
1463
|
+
if (keyword === ":error-behavior") {
|
|
1464
|
+
if (!isSymbol(value, "immediate-exit") && !isSymbol(value, "continued-execution"))
|
|
1465
|
+
throw new SmtParseError(
|
|
1466
|
+
"error setting :error-behavior, 'immediate-execution' or 'continued-execution' expected",
|
|
1467
|
+
list.end,
|
|
1468
|
+
);
|
|
1469
|
+
settings.isExitingOnError = isSymbol(value, "immediate-exit");
|
|
1470
|
+
}
|
|
1282
1471
|
if (
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1472
|
+
keyword !== "" &&
|
|
1473
|
+
!BUILTIN_OPTIONS.has(keyword) &&
|
|
1474
|
+
value !== undefined &&
|
|
1475
|
+
value.kind !== "list"
|
|
1286
1476
|
)
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
if (
|
|
1290
|
-
|
|
1291
|
-
|
|
1477
|
+
settings.parameters.set(getParameterName(keyword), value.text);
|
|
1478
|
+
if (optionName === ":print_success") settings.isPrintingSuccess = isTrue;
|
|
1479
|
+
if (
|
|
1480
|
+
!BUILTIN_OPTIONS.has(keyword) &&
|
|
1481
|
+
settings.parameters.get("smtlib2_compliant") === "true"
|
|
1482
|
+
)
|
|
1483
|
+
settings.isPrintingSuccess = true;
|
|
1484
|
+
if (optionName === ":smt.mbqi") settings.isMbqi = isTrue;
|
|
1485
|
+
if (optionName === ":smt.macro_finder") settings.isFindingMacros = isTrue;
|
|
1486
|
+
if (optionName === ":smt.mbqi.max_iterations" && value?.kind === "numeral")
|
|
1487
|
+
settings.mbqiMaxIterations = Number(value.text);
|
|
1488
|
+
if (optionName === ":rlimit" && value?.kind === "numeral")
|
|
1489
|
+
settings.rlimit = Number(value.text);
|
|
1490
|
+
if (optionName === ":rewriter.hi_div0") {
|
|
1491
|
+
settings.isHiDiv0 = isTrue;
|
|
1492
|
+
state.manager.isHiDiv0 = isTrue;
|
|
1292
1493
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
if (
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
)
|
|
1370
|
-
settings.parameters.set(getParameterName(keyword), value.text);
|
|
1371
|
-
if (optionName === ":print_success") settings.isPrintingSuccess = isTrue;
|
|
1372
|
-
if (!BUILTIN_OPTIONS.has(keyword) && settings.parameters.get("smtlib2_compliant") === "true")
|
|
1373
|
-
settings.isPrintingSuccess = true;
|
|
1374
|
-
if (optionName === ":smt.mbqi") settings.isMbqi = isTrue;
|
|
1375
|
-
if (optionName === ":smt.macro_finder") settings.isFindingMacros = isTrue;
|
|
1376
|
-
if (optionName === ":smt.mbqi.max_iterations" && value?.kind === "numeral")
|
|
1377
|
-
settings.mbqiMaxIterations = Number(value.text);
|
|
1378
|
-
if (optionName === ":rlimit" && value?.kind === "numeral")
|
|
1379
|
-
settings.rlimit = Number(value.text);
|
|
1380
|
-
if (optionName === ":rewriter.hi_div0") {
|
|
1381
|
-
settings.isHiDiv0 = isTrue;
|
|
1382
|
-
script.state.manager.isHiDiv0 = isTrue;
|
|
1383
|
-
}
|
|
1384
|
-
if (optionName === ":encoding" && value !== undefined && value.kind !== "list") {
|
|
1385
|
-
settings.encoding = ENCODINGS.get(value.text) ?? UNICODE_ENCODING;
|
|
1386
|
-
script.state.manager.maxChar = settings.encoding.maxChar;
|
|
1387
|
-
script.state.manager.charBits = settings.encoding.charBits;
|
|
1388
|
-
}
|
|
1389
|
-
if (optionName === ":parser.ignore_bad_patterns")
|
|
1390
|
-
settings.parserOptions.isIgnoringBadPatterns = isTrue;
|
|
1391
|
-
const numericOption = NUMERIC_PRINT_OPTIONS.get(optionName);
|
|
1392
|
-
if (numericOption !== undefined && value?.kind === "numeral")
|
|
1393
|
-
settings.printOptions[numericOption] = Number(value.text);
|
|
1394
|
-
const booleanOption = BOOLEAN_PRINT_OPTIONS.get(optionName);
|
|
1395
|
-
if (booleanOption !== undefined) settings.printOptions[booleanOption] = isTrue;
|
|
1396
|
-
if (
|
|
1397
|
-
optionName.startsWith(":pp.") &&
|
|
1398
|
-
numericOption === undefined &&
|
|
1399
|
-
booleanOption === undefined
|
|
1400
|
-
)
|
|
1401
|
-
throw new SmtUnsupportedError(`the option ${optionName}`);
|
|
1402
|
-
},
|
|
1403
|
-
"get-option": (list) => {
|
|
1404
|
-
const option = list.items[1];
|
|
1405
|
-
if (option?.kind !== "keyword")
|
|
1406
|
-
throw new SmtParseError("invalid command argument, keyword expected", option ?? list.end);
|
|
1407
|
-
const builtinValues = new Map<string, boolean | string>([
|
|
1408
|
-
[":print-success", settings.isPrintingSuccess],
|
|
1409
|
-
[":produce-models", settings.isProducingModels],
|
|
1410
|
-
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
1411
|
-
[":int-real-coercions", true],
|
|
1412
|
-
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1413
|
-
]);
|
|
1414
|
-
const name = getParameterName(option.text);
|
|
1415
|
-
const value =
|
|
1416
|
-
builtinValues.get(option.text) ??
|
|
1417
|
-
(BUILTIN_OPTIONS.has(option.text)
|
|
1418
|
-
? undefined
|
|
1419
|
-
: (settings.parameters.get(name) ?? PARAMETER_DEFAULTS.get(name)));
|
|
1420
|
-
if (value === undefined) throw new SmtUnsupportedError(`the option ${option.text}`);
|
|
1421
|
-
print(String(value));
|
|
1422
|
-
},
|
|
1423
|
-
"get-info": (list) => {
|
|
1424
|
-
const info = list.items[1];
|
|
1425
|
-
if (info?.kind !== "keyword")
|
|
1426
|
-
throw new SmtParseError("invalid command argument, keyword expected", info ?? list.end);
|
|
1427
|
-
const optimizer = script.state.optimizer;
|
|
1428
|
-
if (
|
|
1429
|
-
info.text === ":reason-unknown" &&
|
|
1430
|
-
script.state.check?.status === L_UNDEF &&
|
|
1431
|
-
optimizer !== undefined &&
|
|
1432
|
-
optimizer.reasonUnknown !== ""
|
|
1433
|
-
) {
|
|
1434
|
-
print(`(:reason-unknown "${optimizer.reasonUnknown}")`);
|
|
1435
|
-
return;
|
|
1436
|
-
}
|
|
1437
|
-
if (info.text !== ":error-behavior")
|
|
1438
|
-
throw new SmtUnsupportedError(`the information ${info.text}`);
|
|
1439
|
-
print(
|
|
1440
|
-
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1441
|
-
);
|
|
1442
|
-
},
|
|
1443
|
-
"set-logic": (list) => {
|
|
1444
|
-
const state = script.state;
|
|
1445
|
-
const logic = list.items[1];
|
|
1446
|
-
if (!isSymbol(logic))
|
|
1447
|
-
throw new SmtParseError("invalid logic name, symbol expected", logic ?? list.end);
|
|
1448
|
-
if (state.logic !== undefined)
|
|
1449
|
-
throw new SmtParseError("the logic has already been set", list.end);
|
|
1450
|
-
if (state.assertions.length > 0)
|
|
1451
|
-
throw new SmtParseError("logic must be set before initialization", list.end);
|
|
1452
|
-
if (!isSupportedLogic(logic.text)) {
|
|
1453
|
-
print("unsupported");
|
|
1454
|
-
printDiagnostic(
|
|
1455
|
-
`; ignoring unsupported logic ${logic.text} line: ${list.line} position: ${list.column}`,
|
|
1494
|
+
if (optionName === ":encoding" && value !== undefined && value.kind !== "list") {
|
|
1495
|
+
settings.encoding = ENCODINGS.get(value.text) ?? UNICODE_ENCODING;
|
|
1496
|
+
state.manager.maxChar = settings.encoding.maxChar;
|
|
1497
|
+
state.manager.charBits = settings.encoding.charBits;
|
|
1498
|
+
}
|
|
1499
|
+
if (optionName === ":parser.ignore_bad_patterns")
|
|
1500
|
+
settings.parserOptions.isIgnoringBadPatterns = isTrue;
|
|
1501
|
+
const numericOption = NUMERIC_PRINT_OPTIONS.get(optionName);
|
|
1502
|
+
if (numericOption !== undefined && value?.kind === "numeral")
|
|
1503
|
+
settings.printOptions[numericOption] = Number(value.text);
|
|
1504
|
+
const booleanOption = BOOLEAN_PRINT_OPTIONS.get(optionName);
|
|
1505
|
+
if (booleanOption !== undefined) settings.printOptions[booleanOption] = isTrue;
|
|
1506
|
+
if (
|
|
1507
|
+
optionName.startsWith(":pp.") &&
|
|
1508
|
+
numericOption === undefined &&
|
|
1509
|
+
booleanOption === undefined
|
|
1510
|
+
)
|
|
1511
|
+
throw new SmtUnsupportedError(`the option ${optionName}`);
|
|
1512
|
+
},
|
|
1513
|
+
],
|
|
1514
|
+
[
|
|
1515
|
+
"get-option",
|
|
1516
|
+
(list) => {
|
|
1517
|
+
const option = list.items[1];
|
|
1518
|
+
if (option?.kind !== "keyword")
|
|
1519
|
+
throw new SmtParseError("invalid command argument, keyword expected", option ?? list.end);
|
|
1520
|
+
const builtinValues = new Map<string, boolean | string>([
|
|
1521
|
+
[":print-success", settings.isPrintingSuccess],
|
|
1522
|
+
[":produce-models", settings.isProducingModels],
|
|
1523
|
+
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
1524
|
+
[":int-real-coercions", true],
|
|
1525
|
+
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1526
|
+
]);
|
|
1527
|
+
const name = getParameterName(option.text);
|
|
1528
|
+
const value =
|
|
1529
|
+
builtinValues.get(option.text) ??
|
|
1530
|
+
(BUILTIN_OPTIONS.has(option.text)
|
|
1531
|
+
? undefined
|
|
1532
|
+
: (settings.parameters.get(name) ?? PARAMETER_DEFAULTS.get(name)));
|
|
1533
|
+
if (value === undefined) throw new SmtUnsupportedError(`the option ${option.text}`);
|
|
1534
|
+
print(String(value));
|
|
1535
|
+
},
|
|
1536
|
+
],
|
|
1537
|
+
[
|
|
1538
|
+
"get-info",
|
|
1539
|
+
(list) => {
|
|
1540
|
+
const info = list.items[1];
|
|
1541
|
+
if (info?.kind !== "keyword")
|
|
1542
|
+
throw new SmtParseError("invalid command argument, keyword expected", info ?? list.end);
|
|
1543
|
+
const optimizer = state.optimizer;
|
|
1544
|
+
const check = state.check;
|
|
1545
|
+
if (
|
|
1546
|
+
info.text === ":reason-unknown" &&
|
|
1547
|
+
check?.status === L_UNDEF &&
|
|
1548
|
+
optimizer !== undefined &&
|
|
1549
|
+
optimizer.reasonUnknown !== ""
|
|
1550
|
+
) {
|
|
1551
|
+
print(`(:reason-unknown "${optimizer.reasonUnknown}")`);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
const reasonUnknown =
|
|
1555
|
+
check === undefined
|
|
1556
|
+
? "state of the most recent check-sat command is not known"
|
|
1557
|
+
: check.reasonUnknown;
|
|
1558
|
+
if (info.text === ":reason-unknown" && reasonUnknown !== undefined) {
|
|
1559
|
+
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (info.text === ":rlimit") {
|
|
1563
|
+
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (info.text !== ":error-behavior")
|
|
1567
|
+
throw new SmtUnsupportedError(`the information ${info.text}`);
|
|
1568
|
+
print(
|
|
1569
|
+
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1456
1570
|
);
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1571
|
+
},
|
|
1572
|
+
],
|
|
1573
|
+
[
|
|
1574
|
+
"set-logic",
|
|
1575
|
+
(list) => {
|
|
1576
|
+
const logic = list.items[1];
|
|
1577
|
+
if (!isSymbol(logic))
|
|
1578
|
+
throw new SmtParseError("invalid logic name, symbol expected", logic ?? list.end);
|
|
1579
|
+
if (state.logic !== undefined)
|
|
1580
|
+
throw new SmtParseError("the logic has already been set", logic);
|
|
1581
|
+
if (state.assertions.length > 0)
|
|
1582
|
+
throw new SmtParseError("logic must be set before initialization", logic);
|
|
1583
|
+
if (!isSupportedLogic(logic.text)) {
|
|
1584
|
+
print("unsupported");
|
|
1585
|
+
printDiagnostic(
|
|
1586
|
+
`; ignoring unsupported logic ${logic.text} line: ${list.line} position: ${list.column}`,
|
|
1587
|
+
);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
state.logic = logic.text;
|
|
1591
|
+
if (state.isProofsEnabled === undefined)
|
|
1592
|
+
state.reader = createSmtlibReader(state.manager, logic.text, settings.parserOptions);
|
|
1593
|
+
else {
|
|
1594
|
+
state.reader.restrictSorts(logic.text);
|
|
1595
|
+
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop
|
|
1596
|
+
// and keeps what they asserted.
|
|
1597
|
+
resetKernel();
|
|
1598
|
+
}
|
|
1599
|
+
if (settings.isPrintingSuccess) print("success");
|
|
1600
|
+
},
|
|
1601
|
+
],
|
|
1602
|
+
["set-info", () => {}],
|
|
1603
|
+
]);
|
|
1466
1604
|
const run = (list: SmtList) => {
|
|
1467
1605
|
const head = list.items[0];
|
|
1468
1606
|
if (!isSymbol(head))
|
|
1469
1607
|
throw new SmtParseError("invalid command, symbol expected", head ?? list.end);
|
|
1470
1608
|
const command = DECLARATIONS.has(head.text)
|
|
1471
|
-
? (declaration: SmtList) =>
|
|
1472
|
-
:
|
|
1473
|
-
? runCommand[head.text]
|
|
1474
|
-
: undefined;
|
|
1609
|
+
? (declaration: SmtList) => state.reader.declareCommand(declaration)
|
|
1610
|
+
: runCommand.get(head.text);
|
|
1475
1611
|
if (command === undefined) throw new SmtUnsupportedError(`the command ${head.text}`);
|
|
1476
|
-
if (!MANAGERLESS_COMMANDS.has(head.text) &&
|
|
1477
|
-
|
|
1612
|
+
if (!MANAGERLESS_COMMANDS.has(head.text) && state.isProofsEnabled === undefined) {
|
|
1613
|
+
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
1478
1614
|
resetKernel();
|
|
1479
1615
|
}
|
|
1480
1616
|
command(list);
|
|
@@ -1483,13 +1619,15 @@ export const runSmtlibScript = (
|
|
|
1483
1619
|
for (;;) {
|
|
1484
1620
|
try {
|
|
1485
1621
|
const list = commands.read();
|
|
1486
|
-
if (list === undefined || isSymbol(list.items[0], "exit"))
|
|
1622
|
+
if (list === undefined || isSymbol(list.items[0], "exit")) break;
|
|
1487
1623
|
run(list);
|
|
1488
1624
|
} catch (error) {
|
|
1489
1625
|
if (!(error instanceof SmtParseError)) throw error;
|
|
1490
1626
|
report(error);
|
|
1491
|
-
if (settings.isExitingOnError)
|
|
1627
|
+
if (settings.isExitingOnError) break;
|
|
1628
|
+
state.reader.reset();
|
|
1492
1629
|
commands.skip(report);
|
|
1493
1630
|
}
|
|
1494
1631
|
}
|
|
1632
|
+
if (pendingText !== "") printLine(pendingText);
|
|
1495
1633
|
};
|