Skip to content

Commit 9d4ad12

Browse files
leodemourakim-em
authored andcommitted
fix: bug ite/dite propagator used in grind (#11295)
This PR fixes a bug in the propagation rules for `ite` and `dite` used in `grind`. The bug prevented equalities from being propagated to the satellite solvers. Here is an example affected by this issue. ```lean example [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α] [Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α] (a b c : α) : (if a - b ≤ -(a - b) then -(a - b) else a - b) ≤ ((if a - c ≤ -(a - c) then -(a - c) else a - c) + if c - d ≤ -(c - d) then -(c - d) else c - d) + if b - d ≤ -(b - d) then -(b - d) else b - d := by grind ```
1 parent 5812e43 commit 9d4ad12

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

src/Lean/Meta/Tactic/Grind/Propagate.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,13 @@ Helper function for propagating over-applied `ite` and `dite`-applications.
300300
`prefixSize <= args.size`
301301
-/
302302
private def applyCongrFun (e rhs : Expr) (h : Expr) (prefixSize : Nat) (args : Array Expr) : GoalM Unit := do
303+
/-
304+
**Note**: We did not use to set `e` as the parent for `rhs`. This was incorrect because some
305+
solvers will inspect the parent to decide whether the term should be internalized or not in the
306+
solver.
307+
-/
303308
if prefixSize == args.size then
304-
internalize rhs (← getGeneration e)
309+
internalize rhs (← getGeneration e) e
305310
pushEq e rhs h
306311
else
307312
go rhs h prefixSize
@@ -314,7 +319,7 @@ where
314319
go rhs' h' (i+1)
315320
else
316321
let rhs ← preprocessLight rhs
317-
internalize rhs (← getGeneration e)
322+
internalize rhs (← getGeneration e) e
318323
pushEq e rhs h
319324

320325
/-- Propagates `ite` upwards -/
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/-
2+
The `ite` and `dite` propagators in `grind` were not internalizing
3+
their children using the correct parent information. Several examples
4+
in this file were failing because of this bug.
5+
-/
6+
7+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
8+
[Lean.Grind.IntModule α] [DecidableLE α] [Lean.Grind.OrderedAdd α]
9+
(a b c d : α)
10+
(h : ¬(-(a - b)) ≤ ((-(a - c)) + -(c - d)) + -(b - d))
11+
(h_1 : b - d ≤ -(b - d)) : False := by
12+
grind
13+
14+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
15+
[Lean.Grind.IntModule α] [DecidableLE α] [Lean.Grind.OrderedAdd α]
16+
(a b c d : α)
17+
(h : ¬(-(a - b)) ≤ ((-(a - c)) + -(c - d)) + if b - d ≤ -(b - d) then -(b - d) else b - d)
18+
(h_1 : b - d ≤ -(b - d)) : False := by
19+
grind
20+
21+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
22+
[Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α]
23+
(a b c : α)
24+
(h : a ≤ a + if b ≤ c then (-1 : α) else (-2))
25+
(h_1 : b ≤ c)
26+
: False := by
27+
grind
28+
29+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
30+
[Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α]
31+
(a b c : α)
32+
(h : a ≤ a + if b ≤ c then (-1 : α) else (-2))
33+
: False := by
34+
grind
35+
36+
example [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α] [Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α] (a b c : α) :
37+
(if a - b ≤ -(a - b) then -(a - b) else a - b) ≤
38+
((if a - c ≤ -(a - c) then -(a - c) else a - c) + if c - d ≤ -(c - d) then -(c - d) else c - d) +
39+
if b - d ≤ -(b - d) then -(b - d) else b - d := by
40+
grind
41+
42+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
43+
[Lean.Grind.IntModule α] [DecidableLE α] [Lean.Grind.OrderedAdd α]
44+
(a b c d : α)
45+
(h : ¬(-(a - b)) ≤ ((-(a - c)) + -(c - d)) + -(b - d))
46+
(h_1 : b - d ≤ -(b - d)) : False := by
47+
grind -order
48+
49+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
50+
[Lean.Grind.IntModule α] [DecidableLE α] [Lean.Grind.OrderedAdd α]
51+
(a b c d : α)
52+
(h : ¬(-(a - b)) ≤ ((-(a - c)) + -(c - d)) + if b - d ≤ -(b - d) then -(b - d) else b - d)
53+
(h_1 : b - d ≤ -(b - d)) : False := by
54+
grind -order
55+
56+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
57+
[Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α]
58+
(a b c : α)
59+
(h : a ≤ a + if b ≤ c then (-1 : α) else (-2))
60+
(h_1 : b ≤ c)
61+
: False := by
62+
grind -order
63+
64+
example {α : Type _} [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α]
65+
[Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α]
66+
(a b c : α)
67+
(h : a ≤ a + if b ≤ c then (-1 : α) else (-2))
68+
: False := by
69+
grind -order
70+
71+
example [LE α] [LT α] [Std.IsLinearOrder α] [Std.LawfulOrderLT α] [Lean.Grind.CommRing α] [DecidableLE α] [Lean.Grind.OrderedRing α] (a b c : α) :
72+
(if a - b ≤ -(a - b) then -(a - b) else a - b) ≤
73+
((if a - c ≤ -(a - c) then -(a - c) else a - c) + if c - d ≤ -(c - d) then -(c - d) else c - d) +
74+
if b - d ≤ -(b - d) then -(b - d) else b - d := by
75+
grind -order

0 commit comments

Comments
 (0)