-
Notifications
You must be signed in to change notification settings - Fork 248
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
feat(Mathlib/Tactic/finCases): Port fin_cases
#346
Conversation
Mathlib/Tactic/finCases.lean
Outdated
liftMetaTacticAux fun mvarId => do | ||
let rec loop (goal : MVarId) (hyp : FVarId) (cont : Array MVarId) := do | ||
try | ||
let #[g₁, g₂] ← cases goal hyp | | ||
throwError "'cases' tactic failed, unexpected number of subgoals" | ||
loop g₂.mvarId g₂.fields[3]!.fvarId! (cont.push g₁.mvarId) | ||
catch _ => | ||
return cont | ||
return ((), Array.toList <|← loop mvarId hyp #[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a gigantic hack. Is there a way recursively apply cases
and capture the subgoals in a list nicely?
Mathlib/Tactic/finCases.lean
Outdated
-- Deal with `x : A`, where `[Fintype A]` is available: | ||
let inst ← synthInstance (← mkAppM ``Fintype #[lDecl.type]) | ||
let elems ← mkAppOptM ``Fintype.elems #[lDecl.type, inst] | ||
let t ← mkAppM ``Membership.mem #[lDecl.toExpr, elems] | ||
let v ← mkAppOptM ``Fintype.complete #[lDecl.type, inst, lDecl.toExpr] | ||
|
||
let hyp ← liftMetaTacticAux fun mvarId => do | ||
let (fvar, mvarId) ← intro1P (← assert mvarId `this t v) | ||
pure (fvar, [mvarId]) | ||
|
||
withMainContext do | ||
finCasesAt hyp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it works, but are there any footguns I should be careful about?
Please separate out the porting parts of this PR into its own PR. |
@@ -882,7 +883,7 @@ theorem erasep_append_right : | |||
| (x::xs), l₂, h => by | |||
simp [(forall_mem_cons.1 h).1, erasep_append_right _ (forall_mem_cons.1 h).2] | |||
|
|||
-- theorem erasep_sublist (l : List α) : l.erasep p <+ l := | |||
-- theorem erasep_subList (l : List α) : l.erasep p <+ l := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/subList/sublist/, this is an actual word
@@ -1168,7 +1169,7 @@ end union | |||
cases l₁ <;> simp [List.inter, mem_filter] | |||
|
|||
/-- | |||
List.prod satisfies a specification of cartesian product on lists. | |||
List.prod satisfies a specification of cartesian product on Lists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List.prod satisfies a specification of cartesian product on Lists. | |
List.prod satisfies a specification of cartesian product on lists. |
For porting, you should be using https://github.com/leanprover-community/mathlib3port, not https://github.com/leanprover-community/mathlib directly. This will save you a lot of trouble fixing lean 3 syntax stuff, and will save us trouble when we later have to diff these files against the automatically ported files when new theorems are added to mathlib and/or we get around to porting these files for real. |
· sorry | ||
· sorry | ||
-- hb.Pairwise.cons begin | ||
-- simp only [mem_cons_iff, forall_eq_or_imp, h, true_and] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #350 to add these missing lemmas.
Ports [`mem_cons_iff`](https://github.com/leanprover-community/lean/blob/3526539070ea6268df5dd373deeb3ac8b9621952/library/init/data/list/lemmas.lean#L100-L101) and [`forall_eq_or_imp`](https://github.com/leanprover-community/mathlib/blob/8edffc250c25db5a7bada5472dd02a166f7f8bfc/src/logic/basic.lean#L1135-L1137), to be used in the proof of `Chain.Pairwise` in #346.
Ports [`mem_cons_iff`](https://github.com/leanprover-community/lean/blob/3526539070ea6268df5dd373deeb3ac8b9621952/library/init/data/list/lemmas.lean#L100-L101) and [`forall_eq_or_imp`](https://github.com/leanprover-community/mathlib/blob/8edffc250c25db5a7bada5472dd02a166f7f8bfc/src/logic/basic.lean#L1135-L1137), to be used in the proof of `Chain.Pairwise` in #346.
@winston-h-zhang, would it be okay if I started some work on this port? My plan would be
I would probably just start a new branch, but make use of some of your code from here (appropriately credited, of course :-). |
This is a bare minimum port of the definitions of `Finset` / `Multiset` / `Fintype`. I am hoping that these are enough to port the `fin_cases` tactic. (i.e. replacing the unfinished work in #346, which still had sorries in the corresponding material) Where possible I have started by copying and pasting the output from `mathlib3port`. Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Made redundant by #437. |
This PR implements
fin_cases
from mathlib3. It largely follows the original idea behind Scott's code. There are a few notable details for this PRfin_cases
s full functionality, we must portFintype/Finset/Multiset
. I've tried my best to only use the minimal number of dependencies, but right now it feels very messy. Is there a standard way of organizing this?cases_core
doesn't exist and I don't know how to recreate the API. There's an extremely hacky section that needs to be fixed.