klause

SMT-LIB

Klause reads first-order quantifier-free SMT-LIB 2.7 scripts through its CLI. This guide describes the current main branch; an older published release may have a smaller language surface. The examples below use a CLI built from that source.

Build the CLI

The JVM build and launcher require JDK 25 or newer. From a Klause checkout:

./gradlew :klause-cli:installJvmDist
klause-cli/build/install/klause-cli-jvm/bin/klause-cli --help

Pass a .smt2 or .smt file to the launcher. Other filenames can use --format smtlib. Standard responses go to regular output; solver observations use SMT-LIB comments beginning with ;.

Supported language

Family Supported forms
Core Booleans, connectives, equality, distinct, ite, lexical let and definitions
Integers and reals Exact numerals, decimals and arithmetic; comparisons; integer div, mod, abs and **; real /; to_real, to_int, is_int and indexed divisibility
Bitvectors Positive widths beyond machine-word size; bitwise and modular arithmetic, shifts, comparisons, concatenation, extraction, extensions, rotations, conversions and overflow predicates
Free sorts and functions Sort constructors and aliases, typed functions, predicates and first-order polymorphic declarations
Arrays select, store and extensional equality; nested arrays and arrays in index, argument and result positions
Algebraic datatypes Constructors, selectors, testers, exhaustive match, parametric and mutually recursive declarations
Command sessions Repeated checks, assumptions, assertion stacks, resets, named terms, model and value queries, and recursive definitions

The families compose in one formula. Integer and real declarations keep their source domains; a bitvector conversion does not silently bound an integer. Array equality compares contents, and recursive datatype values must be finite constructor trees.

Floating-point and String/RegLan theories, term quantifiers (forall and exists), and higher-order maps/application are excluded. Strings in commands and attributes, such as echo, remain valid. The nonstandard constant-array input extension (as const (Array ...)) is unsupported; a model may still render total arrays using constant-array and store terms.

Language support does not promise a conclusive result for every formula. Nonlinear integer satisfaction is undecidable, and nonlinear and transcendental search can return unknown. The conformance inventory pins the reference revisions and maps supported forms to local regression tests.

Run a script and query a model

Save this as session.smt2. Enable model production before set-logic, declarations or assertions, and request values explicitly after a successful check.

(set-option :produce-models true)
(set-logic QF_LIA)
(declare-const x Int)
(assert (= x 7))
(check-sat)
(get-value (x (+ x 1)))

Run it from the checkout:

klause-cli/build/install/klause-cli-jvm/bin/klause-cli session.smt2

The standard responses are:

sat
((x 7) ((+ x 1) 8))

get-model requests the full retained interpretation. get-value evaluates terms in that same interpretation, including composite values and new function arguments; it does not solve another model. Integers and rationals retain exact values. Source names are preserved, and private encoding variables are omitted.

Check a temporary assertion

Append these commands to session.smt2:

(push 1)
(assert (< x 5))
(check-sat)
(pop 1)
(check-sat)
(get-value (x))
(check-sat-assuming ((> x 10)))
(check-sat)
(get-value (x))

The additional standard responses are:

unsat
sat
((x 7))
unsat
sat
((x 7))

Assumptions apply only to their check. Declarations are local by default; push and pop scope them together with assertions. Set :global-declarations to true before set-logic to make declarations survive stack operations. reset-assertions removes all assertions and nonglobal declarations, including those at the base level, while preserving global declarations and options. reset restores the initial state, including options.

A context change invalidates the previous model. Query it only after a new sat response with model production enabled. Malformed commands produce protocol errors; they do not become unsat. Optional proof, unsat-core and unsat-assumption production respond unsupported when enabled, and querying disabled production is an error.

Combine arrays with datatypes and bitvectors

Save this as packet.smt2 and run it with the same launcher:

(set-option :produce-models true)
(set-logic ALL)
(declare-datatype Packet ((packet (payload (_ BitVec 8)))))
(declare-const memory (Array Int Packet))
(assert (= (select memory 3) (packet #x2a)))
(check-sat)
(get-value ((payload (select memory 3))))

The standard responses are:

sat
(((payload (select memory 3)) #b00101010))

The read returns a datatype value whose field is an eight-bit word. Both the source assertion and later query use its constructor and bitvector meanings. set-logic identifies the input logic; it does not select an external backend.

Check function congruence

Free functions are total and must return equal results for equal arguments. Save this as functions.smt2:

(set-logic QF_UFLIA)
(declare-sort Key 0)
(declare-fun value (Key) Int)
(declare-const a Key)
(declare-const b Key)
(assert (= a b))
(assert (distinct (value a) (value b)))
(check-sat)

Running it returns unsat: the two asserted function values cannot differ.

Interpret an inconclusive result

sat requires a checked source witness. unsat requires a refutation; failure to find a witness is insufficient. unknown means the solve was inconclusive, for example because search or representation work exhausted its allowance. After unknown, (get-info :reason-unknown) asks for the reason. An unavailable exact comparison during a later model query produces a query error without replacing the retained interpretation.

Use the launcher’s --help for resource controls. Increasing a budget can help an inconclusive solve, but cannot turn an unsupported language feature into a supported one or guarantee completion of nonlinear search.