-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: IndPred: track function's motive in a let binding, use withoutProofIrrelevance, no chaining #4839
Merged
Conversation
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
…oofIrrelevance this improves support for structural recursion over inductive *predicates* when there are reflexive arguments. Consider ```lean inductive F: Prop where | base | step (fn: Nat → F) -- set_option trace.Meta.IndPredBelow.search true set_option pp.proofs true def F.asdf1 : (f : F) → True | base => trivial | step f => F.asdf1 (f 0) termination_by structural f => f` ``` Previously the search for the right induction hypothesis would fail with ``` could not solve using backwards chaining x✝¹ : F x✝ : x✝¹.below f : Nat → F a✝¹ : ∀ (a : Nat), (f a).below a✝ : Nat → True ⊢ True ``` The backchaining process will try to use `a✝ : Nat → True`, but then has no idea what to use for `Nat`. There are three steps to fix this. 1. We let-bind the function's type before the whole process. Now the goal is ``` motive : F → Prop := fun x => True x✝ : x✝¹.below f : Nat → F a✝¹ : ∀ (a : Nat), (f a).below a✝ : ∀ (a : Nat), motive (f a) ⊢ motive (f 0) ``` 2. Next we do more aggressive unification when seeing if an assumption matches: Given ``` g a b =?= h c d ``` it continues with `a =?= c` and `b =?= d`, even if `g` is a let-bound variable. 3. This gives us `f 0 =?= f ?a`. In order to make progress here, we use `withoutProofIrrelevance`, because else `isDefEq` is happy to say “they are equal” without actually looking at the terms and thus assigning `?a := 0`. This idea of let-binding the function's motive may also be useful for the other recursion compilers, as it may simplify the FunInd construction. This is to be investigated. fixes #4751
github-actions
bot
added
the
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
label
Jul 26, 2024
Mathlib CI status (docs):
|
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 27, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jul 27, 2024
leanprover-community-mathlib4-bot
added
the
builds-mathlib
CI has verified that Mathlib builds against this PR
label
Jul 27, 2024
@DanielFabian , this does successfully build mathlib, and I have a sense that this is a step in the right direction. Do you want to have a final look before I merge this, or should I just go ahead? |
go ahead, imo. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
builds-mathlib
CI has verified that Mathlib builds against this PR
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this improves support for structural recursion over inductive
predicates when there are reflexive arguments.
Consider
Previously the search for the right induction hypothesis would fail with
The backchaining process will try to use
a✝ : Nat → True
, but then hasno idea what to use for
Nat
.There are three steps here to fix this.
We let-bind the function's type before the whole process. Now the
goal is
Instead of using the general purpose backchaining proof search, which is more
powerful than we need here (we need on recursive search and no backtracking),
we have a custom search that looks for local assumptions that
provide evidence of
funType
, and extracts the arguments from that“type” application to construct the recursive call.
Above, it will thus unify
f a =?= f 0
.In order to make progress here, we also turn on use
withoutProofIrrelevance
,because else
isDefEq
is happy to say “they are equal” without actually lookingat the terms and thus assigning
?a := 0
.This idea of let-binding the function's motive may also be useful for
the other recursion compilers, as it may simplify the FunInd
construction. This is to be investigated.
fixes #4751