Skip to content
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

chore: changes required for leanprover/lean4#2783 #331

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Std/Classes/LawfulMonad.lean
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ namespace SatisfiesM
/-- If `p` is always true, then every `x` satisfies it. -/
theorem of_true [Applicative m] [LawfulApplicative m] {x : m α}
(h : ∀ a, p a) : SatisfiesM p x :=
⟨(fun a => ⟨a, h a⟩) <$> x, by simp [← comp_map, Function.comp]⟩
⟨(fun a => ⟨a, h a⟩) <$> x,
by simp (config := { unfoldPartialApp := true }) [← comp_map, Function.comp]⟩
Comment on lines +77 to +78
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@digama0, in Mathlib we have the lemma Function.comp_def, and there I have used that to avoid needing unfoldPartialApp := true every time we want to unfold Function.comp.

Do you think I should move that up to Std?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've done this in #367 now.


/--
If `p` is always true, then every `x` satisfies it.
Expand All @@ -93,7 +94,8 @@ protected theorem map [Functor m] [LawfulFunctor m] {x : m α}
(hx : SatisfiesM p x) (hf : ∀ {a}, p a → q (f a)) : SatisfiesM q (f <$> x) := by
let ⟨x', hx⟩ := hx
refine ⟨(fun ⟨a, h⟩ => ⟨f a, hf h⟩) <$> x', ?_⟩
rw [← hx]; simp [← comp_map, Function.comp]
rw [← hx]
simp (config := { unfoldPartialApp := true }) [← comp_map, Function.comp]

/--
`SatisfiesM` distributes over `<$>`, strongest postcondition version.
Expand Down Expand Up @@ -126,8 +128,10 @@ protected theorem seq [Applicative m] [LawfulApplicative m] {x : m α}
(H : ∀ {f a}, p₁ f → p₂ a → q (f a)) : SatisfiesM q (f <*> x) := by
match f, x, hf, hx with | _, _, ⟨f, rfl⟩, ⟨x, rfl⟩ => ?_
refine ⟨(fun ⟨a, h₁⟩ ⟨b, h₂⟩ => ⟨a b, H h₁ h₂⟩) <$> f <*> x, ?_⟩
simp only [← pure_seq]; simp [SatisfiesM, seq_assoc]
simp only [← pure_seq]; simp [seq_assoc, Function.comp]
simp only [← pure_seq]
simp only [seq_assoc, map_pure, seq_pure]
simp only [← pure_seq]
simp (config := { unfoldPartialApp := true }) only [Function.comp, seq_assoc, map_pure, seq_pure]

/-- `SatisfiesM` distributes over `<*>`, strongest postcondition version. -/
protected theorem seq_post [Applicative m] [LawfulApplicative m] {x : m α}
Expand Down
4 changes: 2 additions & 2 deletions Std/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ theorem scanlTR_go_eq : ∀ l, scanlTR.go f l a acc = acc.data ++ scanl f a l
| a :: l => by simp [scanlTR.go, scanl, scanlTR_go_eq l]

@[csimp] theorem scanl_eq_scanlTR : @scanl = @scanlTR := by
funext α f n l; simp [scanlTR, scanlTR_go_eq]
funext α f n l; simp (config := { unfoldPartialApp := true }) [scanlTR, scanlTR_go_eq]

/--
Fold a function `f` over the list from the right, returning the list of partial results.
Expand Down Expand Up @@ -866,7 +866,7 @@ def tailsTR (l : List α) : List (List α) := go l #[] where
funext α
have H (l : List α) : ∀ acc, tailsTR.go l acc = acc.toList ++ tails l := by
induction l <;> simp [*, tailsTR.go]
simp [tailsTR, H]
simp (config := { unfoldPartialApp := true }) [tailsTR, H]

/--
`sublists' l` is the list of all (non-contiguous) sublists of `l`.
Expand Down
2 changes: 1 addition & 1 deletion Std/Data/List/Pairwise.lean
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ theorem sublist_eq_map_get (h : l' <+ l) : ∃ is : List (Fin l.length),
| cons₂ _ _ IH =>
rcases IH with ⟨is,IH⟩
refine ⟨⟨0, by simp [Nat.zero_lt_succ]⟩ :: is.map (·.succ), ?_⟩
simp [comp, pairwise_map, IH]
simp (config := { unfoldPartialApp := true }) [comp, pairwise_map, IH]

theorem pairwise_iff_get : Pairwise R l ↔ ∀ (i j) (_hij : i < j), R (get l i) (get l j) := by
rw [pairwise_iff_forall_sublist]
Expand Down
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:nightly-2023-11-06
leanprover/lean4-pr-releases:pr-release-2783
Loading