Skip to content

SMT-LIB export

To ask a solver your own questions about an operator, the solver needs the operator in its own language, with Opulse's truncating division and bound.

opulse analyze writes each operator as SMT-LIB functions (the z3 field), so z3 or any other SMT solver can reason about it directly.

opulse operators --out outputs/operators.jsonl --layers 2 1 --seed 1
opulse analyze --operators outputs/operators.jsonl --out outputs/operators.analyzed.jsonl

An operator f becomes two functions over (definedness, value) pairs: f_d says whether the result is defined, f_v gives the value where it is. Operands carry definedness because a definition may ignore an undefined operand. The recursive operator from the quickstart:

; ♣₂₅: a ♣₂₅ = { - 2, if a % 9 == 0; & (((a % 9) - 1) ♣₂₅), if a % 9 > 0; & (((a % 9) + 1) ♣₂₅), if a % 9 < 0 }
(define-funs-rec ((op_vSGEK9n4ny_d ((a_d Bool) (a Int)) Bool) (op_vSGEK9n4ny_v ((a_d Bool) (a Int)) Int))
  ((ite (not (and a_d (base_mod_d a 9))) false (ite (= (base_mod_v a 9) 0) (base_neg_d 2) (ite (not (and a_d (base_mod_d a 9))) false (ite (> (base_mod_v a 9) 0) (and (op_vSGEK9n4ny_d (and (and a_d (base_mod_d a 9)) (base_sub_d (base_mod_v a 9) 1)) (base_sub_v (base_mod_v a 9) 1)) (base_digitsum_d (op_vSGEK9n4ny_v (and (and a_d (base_mod_d a 9)) (base_sub_d (base_mod_v a 9) 1)) (base_sub_v (base_mod_v a 9) 1)))) (ite (not (and a_d (base_mod_d a 9))) false (ite (< (base_mod_v a 9) 0) (and (op_vSGEK9n4ny_d (and (and a_d (base_mod_d a 9)) (base_add_d (base_mod_v a 9) 1)) (base_add_v (base_mod_v a 9) 1)) (base_digitsum_d (op_vSGEK9n4ny_v (and (and a_d (base_mod_d a 9)) (base_add_d (base_mod_v a 9) 1)) (base_add_v (base_mod_v a 9) 1)))) false))))))
   (ite (= (base_mod_v a 9) 0) (base_neg_v 2) (ite (> (base_mod_v a 9) 0) (base_digitsum_v (op_vSGEK9n4ny_v (and (and a_d (base_mod_d a 9)) (base_sub_d (base_mod_v a 9) 1)) (base_sub_v (base_mod_v a 9) 1))) (ite (< (base_mod_v a 9) 0) (base_digitsum_v (op_vSGEK9n4ny_v (and (and a_d (base_mod_d a 9)) (base_add_d (base_mod_v a 9) 1)) (base_add_v (base_mod_v a 9) 1))) 0)))))
  • Calls to other operators are by name, so each export is about as long as its definition.
  • Base operations come from a shared prelude (<out>.prelude.smt2) in which truncating division and the bound are written out. SMT-LIB div and mod are Euclidean; using them directly would be wrong for negative operands.
  • Every operator is declared with define-funs-rec, recursive or not, because z3 expands define-fun as a macro and would inline whole dependency chains.

Checked before it is written

opulse.solver.smt.module assembles a self-contained script (prelude, dependencies, the operator). Before an export is written, z3 parses it and an independent SMT-LIB evaluator compares it with the reference interpreter on boundary inputs and NaN inputs.

Solving with the export

; <module text>
(declare-const x Int)
(assert (op_<id>_d true x))
(assert (= (op_<id>_v true x) 42))
(check-sat)
(get-model)