Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smt rw tac: Added the import to Smt.Reconstruction.Certifying #65

Merged
merged 8 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Smt/Reconstruction/Certifying.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ import Smt.Reconstruction.Certifying.Arith
import Smt.Reconstruction.Rewrites.Arith
import Smt.Reconstruction.Rewrites.Builtin
import Smt.Reconstruction.Rewrites.Prop
import Smt.Reconstruction.Rewrites.Tactic
32 changes: 19 additions & 13 deletions Smt/Reconstruction/Rewrites/Tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ theorem bool_and_dup : (xs ∧ b ∧ ys ∧ b ∧ zs) = (xs ∧ b ∧ ys ∧ zs)

theorem bool_or_dup : (xs ∨ b ∨ ys ∨ b ∨ zs) = (xs ∨ b ∨ ys ∨ zs) := by aesop

def smtRw (mv : MVarId) (assoc : Expr) (null : Expr) (rule : Expr) (arr : Array (Array Expr)) : MetaM Unit := do
def opsAssocNull : Name → Array Expr
| ``or => #[Expr.const ``or_assoc_eq [], Expr.const ``or_false []]
| ``and => #[Expr.const ``and_assoc_eq [], Expr.const ``and_true []]
| _ => #[]

def smtRw (mv : MVarId) (op : Name) (rule : Expr) (arr : Array (Array Expr)) : MetaM Unit := do
let n := arr.size
let mut mv' := mv
let assoc := (opsAssocNull op)[0]!
let null := (opsAssocNull op)[1]!
Copy link
Collaborator

@tomaz1502 tomaz1502 Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no big deal, but I believe it would be better if opsAssocNull returned
a pair with the two Expr instead of an Array, unless you're planning to extend
this function to return more constants in the future. Then you can do
let (assoc, null) := opsAssocNull op at smtRw.
(sorry I forgot to publish the comment before)

Copy link
Collaborator Author

@mhk119 mhk119 Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I plan to add more operators.

for i in [: n] do
let mut m := arr[i]!.size
if m > 1 then
Expand All @@ -54,7 +61,7 @@ def smtRw (mv : MVarId) (assoc : Expr) (null : Expr) (rule : Expr) (arr : Array
syntax inner := "[" term,* "]"
syntax outer := "[" inner,* "]"

syntax (name := smt_rw) "smt_rw" ident ident ident outer : tactic
syntax (name := smt_rw) "smt_rw" ident ident outer : tactic

def parseInner : TSyntax ``inner → TacticM (Array Expr)
| `(inner| [$ts,*]) => ts.getElems.mapM (elabTerm · none)
Expand All @@ -66,24 +73,23 @@ def parseOuter : TSyntax ``outer → TacticM (Array (Array Expr))

@[tactic smt_rw] def evalSMTRw : Tactic := fun stx => do
let mv : MVarId ← getMainGoal
let rr ← elabTerm stx[3] none
let xs ← parseOuter ⟨stx[4]⟩
let op ← elabTermForApply stx[1]
let nu ← elabTermForApply stx[2]
smtRw mv op nu rr xs
let rr ← elabTerm stx[2] none
let xs ← parseOuter ⟨stx[3]⟩
let op := stx[1].getId
smtRw mv op rr xs
replaceMainGoal [mv]

example : (x1 ∧ x2 ∧ x3 ∧ (b ∧ y1 ∧ y2 ∧ True) ∧ z1 ∧ z2 ∧ True) = (x1 ∧ x2 ∧ x3 ∧ b ∧ y1 ∧ y2 ∧ z1 ∧ z2 ∧ True) := by
smt_rw and_assoc_eq and_true bool_and_flatten [[x1, x2], [b], [y1, y2], [z1, z2]]
smt_rw and bool_and_flatten [[x1, x2], [b], [y1, y2], [z1, z2]]

example : (x1 ∧ x2 ∧ x3 ∧ b ∧ y1 ∧ y2 ∧ b ∧ z1 ∧ z2 ∧ True) = (x1 ∧ x2 ∧ x3 ∧ b ∧ y1 ∧ y2 ∧ z1 ∧ z2 ∧ True) := by
smt_rw and_assoc_eq and_true bool_and_dup [[x1, x2, x3], [y1, y2], [z1, z2]]
smt_rw and bool_and_dup[[x1, x2, x3], [y1, y2], [z1, z2]]

example : (x1 ∨ x2 ∨ x3 ∨ b ∨ y1 ∨ y2 ∨ b ∨ z1 ∨ z2 ∨ False) = (x1 ∨ x2 ∨ x3 ∨ b ∨ y1 ∨ y2 ∨ z1 ∨ z2 ∨ False) := by
smt_rw or_assoc_eq or_false bool_or_dup [[x1, x2, x3], [y1, y2], [z1, z2]]
smt_rw or bool_or_dup [[x1, x2, x3], [y1, y2], [z1, z2]]

example : (x1 ∧ x2 ∧ x3 ∧ b ∧ y1 ∧ y2 ∧ b ∧ z1 ∧ z2 ∧ True) = (x1 ∧ x2 ∧ x3 ∧ b ∧ y1 ∧ y2 ∧ z1 ∧ z2 ∧ True) := by
smt_rw and_assoc_eq and_true bool_and_dup [[x1, x2, x3], [y1, y2], [z1, z2]]
smt_rw and bool_and_dup [[x1, x2, x3], [y1, y2], [z1, z2]]

example : (x1 ∨ x2 ∨ x3 ∨ (b ∨ y1 ∨ False) ∨ z1 ∨ False) = (x1 ∨ x2 ∨ x3 ∨ b ∨ y1 ∨ z1 ∨ False) := by
smt_rw or_assoc_eq or_false bool_or_flatten [[x1, x2, x3], [b], [y1], [z1]]
example : (x1 ∨ x2 ∨ x3 ∨ (b ∨ y1 ∨ False) ∨ z1 ∨ False)= (x1 ∨ x2 ∨ x3 ∨ b ∨ y1 ∨ z1 ∨ False) := by
smt_rw or bool_or_flatten [[x1, x2, x3], [b], [y1], [z1]]
Loading