lean4-htt/tests/lean/run/aig_optimizations.lean
Henrik Böving 958ad2b54b
feat: upstream LeanSAT's bitblaster (#5013)
Step 3/~7 in upstreaming LeanSAT.

A few thoughts:
- Why is this not in `Std.Sat`? LeanSAT's bitblaster operates on a
limited internal language. For example it has no idea that signed
comparision operators even exist. This is because it relies on a
normalization pass before being given the goal. For this reason I would
not classify the bitblaster as an API that we should publicly advertise
at this abstraction level
- Sometimes I slightly rebuild parts of the LawfulOperator
infrastructure for operators that work non-tail-recursively. This is
because they do not return an `Entrypoint` but instead an
`ExtendingEntrypoint` in order to even be defined in the first place
(casting Ref's and all that). Given the fact that this barely happens
and I never actually commit to rebuilding the full API I'm hoping that
this is indeed a fine decision?
- The single explicit `decreasing_by` that has a simp only which
*almost* looks like `simp_wf` is missing a singular lemma from `simp_wf`
because it doesn't terminate otherwise.
- I am not using functional induction because it basically always fails
at some generalization step, that is also the reason that there is lots
of explicit `generalize` and manually recursive proofs.

---------

Co-authored-by: Markus Himmel <markus@lean-fro.org>
Co-authored-by: Tobias Grosser <tobias@grosser.es>
2024-08-14 09:54:10 +00:00

53 lines
1.5 KiB
Text

import Lean.Elab.Tactic.BVDecide.Bitblast.BoolExpr
open Std.Sat
open Lean.Elab.Tactic.BVDecide
def mkFalseCollapsible (n : Nat) : BoolExpr Nat :=
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 ofBoolExprCached (mkFalseCollapsible 1) AIG.mkAtomCached |>.aig.decls
/-- info: #[Std.Sat.AIG.Decl.const false] -/
#guard_msgs in
#eval ofBoolExprCached (mkFalseCollapsible 16) AIG.mkAtomCached |>.aig.decls
def mkTrueCollapsible (n : Nat) : BoolExpr Nat :=
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 ofBoolExprCached (mkTrueCollapsible 1) AIG.mkAtomCached |>.aig.decls
/-- info: #[Std.Sat.AIG.Decl.const true] -/
#guard_msgs in
#eval ofBoolExprCached (mkTrueCollapsible 16) AIG.mkAtomCached |>.aig.decls
def mkConstantCollapsible (n : Nat) : BoolExpr Nat :=
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 := ofBoolExprCached (mkConstantCollapsible 1) AIG.mkAtomCached
(entry.aig.decls.size, entry.aig.decls[entry.ref.gate]!)
/-- info: (2, Std.Sat.AIG.Decl.const false) -/
#guard_msgs in
#eval
let entry := ofBoolExprCached (mkConstantCollapsible 16) AIG.mkAtomCached
(entry.aig.decls.size, entry.aig.decls[entry.ref.gate]!)