forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
decide!
tactic for using kernel reduction
The `decide!` tactic is like `decide`, but when it tries reducing the `Decidable` instance it uses kernel reduction rather than the elaborator's reduction. The kernel ignores transparency, so it can unfold all definitions. Furthermore, by using kernel reduction we can cache the result as an auxiliary lemma — this is more efficient than `decide`, which needs to reduce the instance once in the elaborator to check whether the tactic suceeds, and once again in the kernel during final typechecking. This implements a variant of RFC leanprover#5629, which proposes instead to skip checking altogether during elaboration. With this PR's `decide`, we can use `decide!` as more-or-less a drop-in replacement for `decide`.
- Loading branch information
Showing
5 changed files
with
174 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
theorem foo.bla : 0 < 5 := | ||
of_decide_eq_true (Eq.refl true) | ||
of_decide_eq_true (id (Eq.refl true)) |
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,70 @@ | ||
/-! | ||
# `decide!` tests | ||
-/ | ||
|
||
/-! | ||
Very basic tests | ||
-/ | ||
theorem foo1 : True := by decide | ||
theorem foo2 : True := by decide! | ||
|
||
/-! | ||
Tests of the error message when goal is false. | ||
-/ | ||
|
||
/-- | ||
error: tactic 'decide' proved that the proposition | ||
False | ||
is false | ||
-/ | ||
#guard_msgs in | ||
theorem foo3 : False := by decide | ||
|
||
/-- | ||
error: tactic 'decide!' proved that the proposition | ||
False | ||
is false | ||
-/ | ||
#guard_msgs in | ||
theorem foo4 : False := by decide! | ||
|
||
/-! | ||
The kernel sees through irreducible definitions | ||
-/ | ||
@[irreducible] def irred {α : Type} (x : α) : α := x | ||
|
||
/-- | ||
error: tactic 'decide' failed for proposition | ||
irred 3 = 3 | ||
since its 'Decidable' instance | ||
instDecidableEqNat (irred 3) 3 | ||
did not reduce to 'isTrue' or 'isFalse'. | ||
After unfolding the instances 'instDecidableEqNat' and 'Nat.decEq', reduction got stuck at the 'Decidable' instance | ||
match h : (irred 3).beq 3 with | ||
| true => isTrue ⋯ | ||
| false => isFalse ⋯ | ||
-/ | ||
#guard_msgs in theorem gcd_eq1 : irred 3 = 3 := by decide | ||
|
||
theorem gcd_eq2 : irred 3 = 3 := by decide! | ||
|
||
|
||
/-! | ||
The proofs from `decide!` are cached. | ||
-/ | ||
|
||
theorem thm1 : ∀ x < 100, x * x ≤ 10000 := by decide! | ||
|
||
theorem thm1' : ∀ x < 100, x * x ≤ 10000 := by decide! | ||
|
||
/-- | ||
info: theorem thm1 : ∀ (x : Nat), x < 100 → x * x ≤ 10000 := | ||
lean.run.decideBang._auxLemma.3 | ||
-/ | ||
#guard_msgs in #print thm1 | ||
/-- | ||
info: theorem thm1' : ∀ (x : Nat), x < 100 → x * x ≤ 10000 := | ||
lean.run.decideBang._auxLemma.3 | ||
-/ | ||
#guard_msgs in #print thm1' |