Skip to main content

lean_theorem

Function lean_theorem 

Source
pub fn lean_theorem(
    cx: &mut Context,
    name: &str,
    predicates: &[Expr],
    comment: &str,
) -> Result<String, Error>
Expand description

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).

The statement is the predicates as given, each a bit-vector term equal to 1#1, so it can be read against what was asked; whether Lean’s proof by bit-blasting succeeds is for Lean to say, and for arithmetic at 64 bits it often does not: a word-level proof is not something bv_decide finds again. An error names what Lean’s BitVec has no counterpart for (bit counts, byte swaps, the high half of a product, rotations by a variable, floating point, extension operations) or says the statement is too large. Rotations by a constant are written with BitVec.rotateLeft and rotateRight.

use bitwright::{Context, ParseOptions, Width};

let mut cx = Context::new();
let o = ParseOptions::width(Width::W8);
let (a, b) = (cx.parse("x * 3 == 9", &o)?, cx.parse("x >u 3", &o)?);
let lean = bitwright::prove::lean_theorem(&mut cx, "no_other_root", &[a, b], "")?;
assert_eq!(
    lean,
    "import Std.Tactic.BVDecide\n\n\
     theorem no_other_root (x : BitVec 8) :\n    \
     ¬ ((BitVec.ofBool ((x * 3#8) == 9#8)) = 1#1 ∧\n      \
     (BitVec.ofBool (BitVec.ult 3#8 x)) = 1#1) := by\n  bv_decide\n"
);