-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add term offset support to the
grind
E-matching modulo (#6533)
This PR adds support to E-matching offset patterns. For example, we want to be able to E-match the pattern `f (#0 + 1)` with term `f (a + 2)`.
- Loading branch information
1 parent
9dcbc33
commit dc5c809
Showing
7 changed files
with
206 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
opaque g : Nat → Nat | ||
|
||
@[simp] def f (a : Nat) := | ||
match a with | ||
| 0 => 10 | ||
| x+1 => g (f x) | ||
|
||
set_option trace.grind.ematch.pattern true | ||
set_option trace.grind.ematch.instance true | ||
set_option trace.grind.assert true | ||
|
||
/-- | ||
info: [grind.ematch.pattern] f.eq_2: [f (Lean.Grind.offset #0 (1))] | ||
-/ | ||
#guard_msgs in | ||
grind_pattern f.eq_2 => f (x + 1) | ||
|
||
|
||
/-- | ||
info: [grind.assert] f (y + 1) = a | ||
[grind.assert] ¬a = g (f y) | ||
[grind.ematch.instance] f.eq_2: f y.succ = g (f y) | ||
[grind.assert] f (y + 1) = g (f y) | ||
-/ | ||
#guard_msgs (info) in | ||
example : f (y + 1) = a → a = g (f y):= by | ||
grind | ||
|
||
/-- | ||
info: [grind.assert] f 1 = a | ||
[grind.assert] ¬a = g (f 0) | ||
[grind.ematch.instance] f.eq_2: f (Nat.succ 0) = g (f 0) | ||
[grind.assert] f 1 = g (f 0) | ||
-/ | ||
#guard_msgs (info) in | ||
example : f 1 = a → a = g (f 0) := by | ||
grind | ||
|
||
/-- | ||
info: [grind.assert] f 10 = a | ||
[grind.assert] ¬a = g (f 9) | ||
[grind.ematch.instance] f.eq_2: f (Nat.succ 8) = g (f 8) | ||
[grind.ematch.instance] f.eq_2: f (Nat.succ 9) = g (f 9) | ||
[grind.assert] f 9 = g (f 8) | ||
[grind.assert] f 10 = g (f 9) | ||
-/ | ||
#guard_msgs (info) in | ||
example : f 10 = a → a = g (f 9) := by | ||
grind | ||
|
||
/-- | ||
info: [grind.assert] f (c + 2) = a | ||
[grind.assert] ¬a = g (g (f c)) | ||
[grind.ematch.instance] f.eq_2: f (c + 1).succ = g (f (c + 1)) | ||
[grind.assert] f (c + 2) = g (f (c + 1)) | ||
[grind.ematch.instance] f.eq_2: f c.succ = g (f c) | ||
[grind.assert] f (c + 1) = g (f c) | ||
-/ | ||
#guard_msgs (info) in | ||
example : f (c + 2) = a → a = g (g (f c)) := by | ||
grind | ||
|
||
@[simp] def foo (a : Nat) := | ||
match a with | ||
| 0 => 10 | ||
| 1 => 10 | ||
| a+2 => g (foo a) | ||
|
||
/-- | ||
info: [grind.ematch.pattern] foo.eq_3: [foo (Lean.Grind.offset #0 (2))] | ||
-/ | ||
#guard_msgs in | ||
grind_pattern foo.eq_3 => foo (a_2 + 2) | ||
|
||
-- The instance is correctly found in the following example. | ||
-- TODO: to complete the proof, we need linear arithmetic support to prove that `b + 2 = c + 1`. | ||
/-- | ||
info: [grind.assert] foo (c + 1) = a | ||
[grind.assert] c = b + 1 | ||
[grind.assert] ¬a = g (foo b) | ||
[grind.ematch.instance] foo.eq_3: foo b.succ.succ = g (foo b) | ||
[grind.assert] foo (b + 2) = g (foo b) | ||
-/ | ||
#guard_msgs (info) in | ||
example : foo (c + 1) = a → c = b + 1 → a = g (foo b) := by | ||
fail_if_success grind | ||
sorry |