lean4-htt/tests/lean/run/aig_optimizations.lean
Henrik Böving f241cc832b
perf: bv_decide don't drop the expression level cache (#7636)
This PR makes sure that the expression level cache in bv_decide is
maintained across the entire bitblaster instead of just locally per
BitVec expression.

The PR was split off from the first one (#7606) as this mostly entails
pulling the invariant through and is thus much more mechanical.
2025-03-23 13:05:01 +00:00

53 lines
1.4 KiB
Text

import Std.Tactic.BVDecide.Bitblast
open Std.Sat
open Std.Tactic.BVDecide
def mkFalseCollapsible (n : Nat) : BVLogicalExpr :=
match n with
| 0 => .const false
| n + 1 =>
let tree := mkFalseCollapsible n
.gate .and tree tree
/-- info: #[Std.Sat.AIG.Decl.const false] -/
#guard_msgs in
#eval BVLogicalExpr.bitblast (mkFalseCollapsible 1) |>.aig.decls
/-- info: #[Std.Sat.AIG.Decl.const false] -/
#guard_msgs in
#eval BVLogicalExpr.bitblast (mkFalseCollapsible 16) |>.aig.decls
def mkTrueCollapsible (n : Nat) : BVLogicalExpr :=
match n with
| 0 => .const true
| n + 1 =>
let tree := mkTrueCollapsible n
.gate .and tree tree
/-- info: #[Std.Sat.AIG.Decl.const true] -/
#guard_msgs in
#eval BVLogicalExpr.bitblast (mkTrueCollapsible 1) |>.aig.decls
/-- info: #[Std.Sat.AIG.Decl.const true] -/
#guard_msgs in
#eval BVLogicalExpr.bitblast (mkTrueCollapsible 16) |>.aig.decls
def mkConstantCollapsible (n : Nat) : BVLogicalExpr :=
match n with
| 0 => .const false
| n + 1 =>
let tree := mkTrueCollapsible n
.gate .and (.gate .and tree tree) (.const false)
/-- info: (2, Std.Sat.AIG.Decl.const false) -/
#guard_msgs in
#eval
let entry := BVLogicalExpr.bitblast (mkConstantCollapsible 1)
(entry.aig.decls.size, entry.aig.decls[entry.ref.gate]!)
/-- info: (2, Std.Sat.AIG.Decl.const false) -/
#guard_msgs in
#eval
let entry := BVLogicalExpr.bitblast (mkConstantCollapsible 16)
(entry.aig.decls.size, entry.aig.decls[entry.ref.gate]!)