Skip to main content

Module prove

Module prove 

Source
Expand description

A native prover (feature prove): expressions are bit-blasted into an and-inverter graph, encoded as clauses, and decided by bitwright’s own CDCL SAT solver. A proof of validity comes with a certificate, the clauses and a DRUP proof of their unsatisfiability, that an independent checker (Certificate::check) verifies, and that any DRAT checker can read (Certificate::dimacs, Certificate::drat). A refutation comes with a counterexample: a value for every symbol, checked by bitwright’s evaluator before it is returned. A question the search does not settle within its budget says why (Unknown), and a Question goes on from where the search stopped, under a larger budget, without starting over. For a small joint output superset above unresolved predicates, domain::analyze preserves shared Boolean structure under explicit premises without solving reachability.

No other solver is involved. Bit-vector operators are blasted with bitwright’s total semantics (SMT-LIB’s); floating-point operators with IEEE 754’s and bitwright’s canonical NaN (crate::fp); extension operations through their expand definition, if they have one (otherwise the question is not decided).

use bitwright::prove::{Config, Outcome, equal};
use bitwright::{Context, ParseOptions, Width};

let mut cx = Context::new();
let o = ParseOptions::width(Width::W32);
let (a, b) = (cx.parse("(x ^ y) + 2 * (x & y)", &o)?, cx.parse("x + y", &o)?);
let Outcome::Proved(Some(cert)) = equal(&mut cx, a, b, &Config::default().with_certificate(true))? else {
    panic!("not proved")
};
assert!(cert.check().is_ok());
let c = cx.parse("x | y", &o)?;
assert!(matches!(equal(&mut cx, a, c, &Config::default())?, Outcome::Refuted(_)));

Re-exports§

pub use sat::Backend;
pub use sat::Limits;

Modules§

aig
An and-inverter graph: every gate a conjunction of two literals, negation free on the edges, with constant folding, trivial simplifications (a ∧ a, a ∧ ¬a) and structural hashing, so equal subcircuits are one gate. Clauses are generated (Tseitin) only for the gates a goal reaches.
blast
Bit-blasting: every bit-vector operator as a circuit over the bits of its operands, with bitwright’s total semantics (SMT-LIB’s): division by zero, shifts past the width, rotations by any count. Bits are little-endian.
domain
Bounded joint output supersets above expensive Boolean predicates.
drup
A forward checker for DRUP proofs: every added clause must follow from the clauses present before it by reverse unit propagation (assigning its literals false and propagating gives a conflict), deleted clauses leave the database, and the proof must add the empty clause. It shares no code with the solver: its own watched-literal propagation over its own database, so a solver bug cannot vouch for itself.
finite
Optional, exhaustively checked finite-domain facts for keyed integer pairs.
lrat
LRAT: a proof of unsatisfiability in which every added clause names the clauses it follows from, in the order unit propagation uses them, so that a checker does no search at all.
sat
A conflict-driven clause-learning SAT solver: two watched literals with blockers, VSIDS decisions with phase saving, first-UIP learning with recursive minimization, Luby restarts, and a learned-clause database reduced by literal block distance. Every learned clause is a reverse-unit-propagation (RUP) consequence of the clauses before it, so the solver can log a DRUP proof (additions and deletions) that super::drup checks independently.

Structs§

Certificate
Clauses and a DRUP proof that they are unsatisfiable, or, for a proof by complete enumeration (Config::exhaustive_inputs), the circuit to enumerate.
Config
How hard to try, and what to keep.
Exhaustion
A circuit and the claim that its goal holds wherever its constraints do, at every assignment of its inputs.
Incremental
A circuit and a SAT search that outlive a question: each predicate asked about is added to the circuit once, its clauses to the search once, and what the search learns stays, so a sequence of related questions (a path condition that grows, a query against one) costs what is new in each.
Question
A question, blasted and encoded once, then decided in as many steps as its caller likes: a search that ends on its limits stops where it is, keeping what it learned, and the next solve goes on from there. Asking under 5,000 conflicts, then 15,000 more, costs what asking under 20,000 once does, and answers the same.
Simplification
What simplifying a question with bitwright’s own engine took (Config::simplify).
Simplifiers
The engines that simplify questions (see Config::simplify), owned by whoever asks: the deobfuscation strategy with the MBA service, built when first needed, and with them the one thing they remember, the MBA solver’s memo. The entry points of this module that take none use one such set for the process; a caller that wants nothing shared with the rest of the process (its statistics, its memory) makes its own and asks through Question::valid_under_with, valid_under_with or a batch::Session, which owns one. Answers are the same either way: the solver’s memo returns what solving again would, at the same cost.
Stats
The work a question took, so far. Every count is of work done, not of time, and the same on every run: a question asked the same way (in a context with the same history) reports the same numbers, and the totals of one resumed in steps are those of one asked at once.
Sweeping
What sweeping a question’s circuit did (Config::sweeping).
WidthReport
A rule at every width up to a bound (see rule_all_widths).

Enums§

IncrementalAnswer
What an Incremental answers. What an Incremental answers.
Outcome
The answer to a question.
RuleOutcome
The answer for a rule at one assignment.
SampleMode
How assignments are selected before SAT search. Sampling can find a concrete counterexample. Complete ordered enumeration on the word path can also prove validity; partial coverage and pseudorandom samples cannot.
Unknown
Why a question is not decided.

Functions§

equal
Whether a and b (of one width) are equal for every value of their symbols agreeing with their declared known bits.
lean_theorem
The claim that the 1-bit predicates do not hold together, as a Lean 4 theorem over BitVec with the proof by bv_decide: a file lean checks on its own, with nothing of bitwright in what it trusts. comment is written above the theorem (how the claim was reached, say).
rule
Proves rule at widths (the width variables’ values, then each mode variable’s index in RoundingMode::ALL). When the solver runs out of conflicts and the rule has const parameters, the proof is split into the values of those the guard admits (found by the solver, each blocked once proved), each proved with the parameters fixed, which folds their circuits (a division by a constant), up to 8,192 of them.
rule_all_widths
Proves rule at every admitted assignment whose widths are at most max_width (every width variable), smallest first, stopping at the first refutation; and, for a rule whose shape makes width irrelevant, at every width at once.
satisfy
A value of the symbols that makes the 1-bit p true, if there is one: Refuted of ¬p read back as a model (Ok(Some)), Ok(None) when p is unsatisfiable, and Err with the reason when not decided.
simplified
p as the prover’s simplifier leaves it within Config::simplify_budget: an expression equal to p at every value of the symbols, which is what the prover builds its circuit of. Asked again of an expression a question was posed about, it costs a lookup.
valid
Whether the 1-bit p is true for every value of its symbols agreeing with their declared known bits.
valid_under
Whether p is true wherever the constraints of assumptions and the symbols’ declared known bits hold.
valid_under_with
valid_under, simplified by the caller’s engines and not the process’s (Simplifiers): the same answer.

Type Aliases§

Model
Values of symbols, as a counterexample or a model gives them.