test: add further ac_refl tests.

This commit is contained in:
Daniel Fabian 2022-03-04 15:18:36 +00:00 committed by Leonardo de Moura
parent a60220b036
commit 84f72b9389
2 changed files with 28 additions and 19 deletions

View file

@ -272,18 +272,24 @@ where
| maybeNormalized _ l r => do mkAppM' op #[←convertType op l, ←convertType op r]
inductive ProofStrategy
| rfl (lhs rhs : NormalizedExpr)
| ac_rfl (lhs rhs : NormalizedExpr)
| rfl (tgt : Expr)
| norm (e : NormalizedExpr)
def pickStrategy (e : Expr) : M ProofStrategy := do
match e with
| eq lhs rhs =>
match ←findUnnormalizedOperator lhs with
| eq l r =>
match ←findUnnormalizedOperator l with
| lhs@(unnormalized _ _) => return ProofStrategy.norm lhs
| lhs =>
match ←findUnnormalizedOperator rhs with
| lhs@(maybeNormalized _ _ _) =>
match ←findUnnormalizedOperator r with
| rhs@(unnormalized _ _) => return ProofStrategy.norm rhs
| rhs => return ProofStrategy.rfl lhs rhs
| rhs => return ProofStrategy.ac_rfl lhs rhs
| lhs@(definitelyNormalized _) =>
match ←findUnnormalizedOperator r with
| rhs@(unnormalized _ _) => return ProofStrategy.norm rhs
| rhs@(maybeNormalized _ _ _) => return ProofStrategy.ac_rfl lhs rhs
| rhs@(definitelyNormalized _) => return ProofStrategy.rfl l
| e => return ProofStrategy.norm $ ←findUnnormalizedOperator e
def addAcEq (mvarId : MVarId) (e : NormalizedExpr) (target : Expr) : M MVarId := do
@ -298,14 +304,17 @@ partial def rewriteUnnormalized (mvarId : MVarId) : M Unit :=
withMVarContext mvarId do
let target ← getMVarType mvarId
match ←pickStrategy target with
| ProofStrategy.rfl lhs rhs =>
trace[Meta.AC] "picking rfl strategy {MessageData.ofGoal mvarId}"
| ProofStrategy.ac_rfl lhs rhs =>
trace[Meta.AC] "picking ac_rfl strategy {MessageData.ofGoal mvarId}"
try
let (proof, ty) ← buildProof lhs rhs
if ←isDefEq target ty then
assignExprMVar mvarId proof
else throwError ""
catch _ => throwError "cannot synthesize proof:\n{MessageData.ofGoal mvarId}"
| ProofStrategy.rfl tgt =>
trace[Meta.AC] "picking rfl strategy {MessageData.ofGoal mvarId}"
assignExprMVar mvarId (←mkAppM ``Eq.refl #[tgt])
| ProofStrategy.norm (definitelyNormalized _) => throwError "no unnormalized operators found"
| ProofStrategy.norm e =>
trace[Meta.AC] "picking norm strategy {MessageData.ofGoal mvarId}"

View file

@ -21,7 +21,7 @@ theorem max_comm (n m : Nat) : max n m = max m n := by
case inr h₁ h₂ => simp [Nat.not_lt_eq] at *; apply Nat.le_antisymm <;> assumption
theorem max_idem (n : Nat) : max n n = n := by
simp [max]; split <;> rfl
simp [max]
theorem Nat.zero_max (n : Nat) : max 0 n = n := by
simp [max]; rfl
@ -34,17 +34,17 @@ instance : IsCommutative (α := Nat) max := ⟨max_comm⟩
instance : IsIdempotent (α := Nat) max := ⟨max_idem⟩
instance : IsNeutral max 0 := ⟨Nat.zero_max, Nat.max_zero⟩
example (x y z : Nat) : x + y + 0 + z = z + (x + y) := by
ac_refl
example (x y z : Nat) : x + y + 0 + z = z + (x + y) := by ac_refl
example (x y z : Nat) : (x + y) * (0 + z) = (x + y) * z:= by
ac_refl
example (x y z : Nat) : (x + y) * (0 + z) = (x + y) * z:= by ac_refl
example (x y z : Nat) : (x + y) * (0 + z) = 1 * z * (y + 0 + x) := by
ac_refl
example (x y z : Nat) : (x + y) * (0 + z) = 1 * z * (y + 0 + x) := by ac_refl
example (x y z : Nat) : max (0 + (max x (max z (max (0 + 0) ((max 1 0) + 0 + 0) * y)))) y = max (max x y) z := by
ac_refl
example (x y z : Nat) : max (0 + (max x (max z (max (0 + 0) ((max 1 0) + 0 + 0) * y)))) y = max (max x y) z := by ac_refl
example (x y : Nat) : 1 + 0 + 0 = 0 + 1 := by ac_refl
example (x y : Nat) : (x + y = 42) = (y + x = 42) := by ac_refl
example (x y : Nat) (P : Prop) : (x + y = 42 → P) = (y + x = 42 → P) := by ac_refl
example (x y : Nat) : 1 + 0 + 0 = 0 + 1 := by
ac_refl