Skip to content

Commit 6108f5f

Browse files
committed
fix: equality propagation in grind order
This PR fixes a bug in the equality propagation procedure in `grind.order`. Specifically, it affects the procedure that asserts equalities in the `grind` core state that are implied by (ring) inequalities in the `grind.order` module. closes #10622
1 parent cd60d9c commit 6108f5f

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/Init/Grind/Order.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ Helper theorem for equality propagation
107107
theorem eq_of_le_of_le {α} [LE α] [Std.IsPartialOrder α] {a b : α} : a ≤ b → b ≤ a → a = b :=
108108
Std.IsPartialOrder.le_antisymm _ _
109109

110+
theorem eq_of_le_of_le_0 {α} [LE α] [Std.IsPartialOrder α] [Ring α]
111+
{a b : α} : a ≤ b + Int.cast (R := α) 0 → b ≤ a + Int.cast (R := α) 0 → a = b := by
112+
simp [Ring.intCast_zero, Semiring.add_zero]
113+
apply Std.IsPartialOrder.le_antisymm
114+
110115
/-!
111116
Transitivity
112117
-/

src/Lean/Meta/Tactic/Grind/Order/Proof.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,19 @@ public def mkUnsatProof (u v : Expr) (k₁ : Weight) (h₁ : Expr) (k₂ : Weigh
210210
else
211211
mkUnsatProofCore u v k₁ h₁ k₂ h₂
212212

213-
public def mkEqProofOfLeOfLe (u v : Expr) (h₁ : Expr) (h₂ : Expr) : OrderM Expr := do
213+
public def mkEqProofOfLeOfLeCore (u v : Expr) (h₁ : Expr) (h₂ : Expr) : OrderM Expr := do
214214
let h ← mkLePartialPrefix ``Grind.Order.eq_of_le_of_le
215215
return mkApp4 h u v h₁ h₂
216216

217+
public def mkEqProofOfLeOfLeOffset (u v : Expr) (h₁ : Expr) (h₂ : Expr) : OrderM Expr := do
218+
let h ← mkLePartialPrefix ``Grind.Order.eq_of_le_of_le_0
219+
let h := mkApp h (← getStruct).ringInst?.get!
220+
return mkApp4 h u v h₁ h₂
221+
222+
public def mkEqProofOfLeOfLe (u v : Expr) (h₁ : Expr) (h₂ : Expr) : OrderM Expr := do
223+
if (← isRing) then
224+
mkEqProofOfLeOfLeOffset u v h₁ h₂
225+
else
226+
mkEqProofOfLeOfLeCore u v h₁ h₂
227+
217228
end Lean.Meta.Grind.Order

src/Lean/Meta/Tactic/Grind/Order/Types.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ structure Cnstr (α : Type) where
3333
k : Int := 0
3434
/-- Denotation of this constraint as an expression. -/
3535
e : Expr
36+
/--
37+
If `h? := some h`, then `h` is proof for that the expression associated with this constraint
38+
is equal to `e`. Recall that the input constraints are normalized. For example, given `x y : Int`,
39+
`x ≤ y` is internally represented as `x ≤ y + 0`
40+
-/
3641
h? : Option Expr := none
3742
deriving Inhabited
3843

tests/lean/run/grind_10622.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def Int.leastOfBdd {P : Int → Prop} [DecidablePred P] (b : Int) (Hb : ∀ z : Int, P z → b ≤ z)
2+
(Hinh : ∃ z : Int, P z) : { lb : Int // P lb ∧ ∀ z : Int, P z → lb ≤ z } :=
3+
sorry
4+
5+
theorem Int.coe_leastOfBdd_eq {P : Int → Prop} [DecidablePred P] {b b' : Int} (Hb : ∀ z : Int, P z → b ≤ z)
6+
(Hb' : ∀ z : Int, P z → b' ≤ z) (Hinh : ∃ z : Int, P z) :
7+
(leastOfBdd b Hb Hinh : Int) = leastOfBdd b' Hb' Hinh := by
8+
grind
9+
10+
example (f : Int → Int) (x y : Int) : x ≤ y → y ≤ x → f x = f y := by
11+
grind -cutsat -linarith

0 commit comments

Comments
 (0)