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: WF.GuessLex: If there is only one plausible measure, use it (le…
…anprover#2954) If here is only one plausible measure, there is no point having the `GuessLex` code see if it is terminating, running all the tactics, only for the `MkFix` code then run the tactics again. So if there is only one plausible measure (non-mutual recursion with only one varying parameter), just use that measure. Side benefit: If the function isn’t terminating, more detailed error messages are shown (failing proof goals), located at the recursive calls.
- Loading branch information
Showing
5 changed files
with
44 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
/-! | ||
A few cases where guessing the lexicographic order fails, and | ||
where we want to keep tabs on the output. | ||
All functions take more than one changing argument, because the guesslex | ||
code skips non-mutuals unary functions with only one plausible measure. | ||
-/ | ||
|
||
def nonTerminating : Nat → Nat | ||
| 0 => 0 | ||
| n => nonTerminating (.succ n) | ||
def nonTerminating : Nat → Nat → Nat | ||
| 0, _ => 0 | ||
| n, m => nonTerminating (.succ n) (.succ m) | ||
|
||
-- Saying decreasing_by forces Lean to use structural recursion, which gives a different | ||
-- error message | ||
def nonTerminating2 : Nat → Nat | ||
| 0 => 0 | ||
| n => nonTerminating2 (.succ n) | ||
def nonTerminating2 : Nat → Nat → Nat | ||
| 0, _ => 0 | ||
| n, m => nonTerminating2 (.succ n) (.succ m) | ||
decreasing_by decreasing_tactic | ||
|
||
|
||
-- The GuessLex code does not like eta-contracted motives in `casesOn`. | ||
-- At the time of writing, the error message is swallowed | ||
-- When guessing the lexicographic order becomes more verbose this will improve. | ||
def FinPlus1 n := Fin (n + 1) | ||
def badCasesOn (n : Nat) : Fin (n + 1) := | ||
Nat.casesOn (motive := FinPlus1) n (⟨0,Nat.zero_lt_succ _⟩) (fun n => Fin.succ (badCasesOn n)) | ||
def badCasesOn (n m : Nat) : Fin (n + 1) := | ||
Nat.casesOn (motive := FinPlus1) n (⟨0,Nat.zero_lt_succ _⟩) (fun n => Fin.succ (badCasesOn n (.succ m))) | ||
decreasing_by decreasing_tactic | ||
-- termination_by badCasesOn n => n | ||
|
||
|
||
-- Like above, but now with a `casesOn` alternative with insufficient lambdas | ||
def Fin_succ_comp (f : (n : Nat) → Fin (n + 1)) : (n : Nat) → Fin (n + 2) := fun n => Fin.succ (f n) | ||
def badCasesOn2 (n : Nat) : Fin (n + 1) := | ||
def badCasesOn2 (n m : Nat) : Fin (n + 1) := | ||
Nat.casesOn (motive := fun n => Fin (n + 1)) n (⟨0,Nat.zero_lt_succ _⟩) | ||
(Fin_succ_comp (fun n => badCasesOn2 n)) | ||
(Fin_succ_comp (fun n => badCasesOn2 n (.succ m))) | ||
decreasing_by decreasing_tactic | ||
-- termination_by badCasesOn2 n => n |
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,13 +1,17 @@ | ||
guessLexFailures.lean:8:9-8:33: error: fail to show termination for | ||
guessLexFailures.lean:11:12-11:46: error: fail to show termination for | ||
nonTerminating | ||
with errors | ||
argument #1 was not used for structural recursion | ||
failed to eliminate recursive application | ||
nonTerminating (Nat.succ n) | ||
nonTerminating (Nat.succ n) (Nat.succ m) | ||
|
||
argument #2 was not used for structural recursion | ||
failed to eliminate recursive application | ||
nonTerminating (Nat.succ n) (Nat.succ m) | ||
|
||
structural recursion cannot be used | ||
|
||
failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:12:0-15:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:22:0-24:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:30:0-33:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:15:0-18:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:25:0-27:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation | ||
guessLexFailures.lean:33:0-36:31: error: failed to prove termination, use `termination_by` to specify a well-founded relation |
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