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

feat: migrate List lemmas from mathlib #233

Closed

Conversation

AdrienChampion
Copy link
Contributor

Integrates a few of Mathlib's lemmas over Lists. Some proofs have been slightly simplified

@AdrienChampion
Copy link
Contributor Author

AdrienChampion commented Aug 25, 2023

Solved simp-normal form issues, but I'm not sure what to do with

@[simp 1100] theorem modifyHead_modifyHead (l : List α) (f g : α → α) :
    (l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by
  -- ...

I commented the simp 1100 as the linter complains with

List.modifyHead_modifyHead.{u_1} Left-hand side simplifies from
  List.modifyHead g (List.modifyHead f l)
to
  match
  match l with
  | [] => []
  | a :: l => f a :: l with
| [] => []
| a :: l => g a :: l
using
  simp only [@List.modifyHead]
Try to change the left-hand side to the simplified term!

since List.modifyHead is @[simp], but I don't want to use the simplified term :/

@digama0
Copy link
Member

digama0 commented Aug 25, 2023

List.modifyHead should not be simp. I think most of those are mistakes, that kind of thing used to work in lean 3 but in lean 4 it unfolds directly to the match statement which is almost never what you want.

@AdrienChampion
Copy link
Contributor Author

List.modifyHead should not be simp. I think most of those are mistakes, that kind of thing used to work in lean 3 but in lean 4 it unfolds directly to the match statement which is almost never what you want.

So should I remove the simp on List.modifyHead then? Or just leave it like this?

@digama0
Copy link
Member

digama0 commented Aug 25, 2023

So should I remove the simp on List.modifyHead then?

👍

@AdrienChampion
Copy link
Contributor Author

Done, I made modifyHead_modifyHead just be simp instead of simp 1100 since the linter authorized me

@semorrison semorrison added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Aug 26, 2023
@fgdorais
Copy link
Collaborator

fgdorais commented Sep 1, 2023

Would it make sense to split this PR into sections? Everything looks good and many parts deserve an immediate all clear review (e.g. the concat lemmas) but they are bogged down by tiny issues (e.g. is there a common use case for length_eq_three?)

@AdrienChampion
Copy link
Contributor Author

I'm fine with splitting this PR if you let me know what does (not) deserve to be merged immediately.

Regarding length_eq_three I don't have an argument for it, it's only here because it can be migrated from mathlib. From what I can see it's used in only one place there:

❯ rg length_eq_three
Mathlib/Data/Multiset/Basic.lean
801:      (List.length_eq_three.mp h).imp fun _a =>

Mathlib/Data/List/Basic.lean
223:theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
225:#align list.length_eq_three List.length_eq_three

@fgdorais
Copy link
Collaborator

fgdorais commented Sep 1, 2023

I was thinking about splitting per section header but that's perhaps too much detail. Here is what I'm thinking:

  • The head and tail stuff can go together, perhaps combined with concat, these parts are really straightforward. Length and get stuff can go in there too but it might be easier to split them since the use cases are rare.
  • The pure, map, bind stuff should be separate since there is a need to discuss (not necessarily in this PR) whether to make the List functor an applicative, an alternative, and/or a monad. It's lawful for all but there are other issues. The outcome of this decision will cause the syntax of the lemmas to change.

It's a matter of taste whether to split into smaller parts than these two.

Copy link
Collaborator

@fgdorais fgdorais left a comment

Choose a reason for hiding this comment

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

Got part way...

Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
@semorrison semorrison added awaiting-author Waiting for PR author to address issues and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Sep 4, 2023
@fgdorais fgdorais added awaiting-review This PR is ready for review; the author thinks it is ready to be merged. and removed awaiting-author Waiting for PR author to address issues labels Sep 5, 2023
@semorrison
Copy link
Collaborator

Is there a matching Mathlib PR? It would be nice to be able to verify that Mathlib can be updated cleanly.

(Maybe you know this already, but you can just make a Mathlib branch in which the lakefile points to this branch.)

@semorrison semorrison added awaiting-author Waiting for PR author to address issues and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Sep 7, 2023
@AdrienChampion
Copy link
Contributor Author

Is there a matching Mathlib PR? It would be nice to be able to verify that Mathlib can be updated cleanly.

(Maybe you know this already, but you can just make a Mathlib branch in which the lakefile points to this branch.)

I can do that, I did not know about the lakefile-pointer bit but I can probably figure it out.

But I'd rather wait for the review process to be completed on this PR first, so that I know what will actually end up being merged.

@AdrienChampion
Copy link
Contributor Author

AdrienChampion commented Sep 9, 2023

On that note, this PR is awaiting reviews, not author, could you change the label back @semorrison please?

@fgdorais fgdorais added awaiting-review This PR is ready for review; the author thinks it is ready to be merged. and removed awaiting-author Waiting for PR author to address issues labels Sep 9, 2023
@semorrison
Copy link
Collaborator

@AdrienChampion, in fact anyone can change labels, by writing a message solely containing one of awaiting-author, awaiting-review, or WIP!

@AdrienChampion
Copy link
Contributor Author

Is there something blocking this PR on my end?

Is it maybe the mathlib PR, should I open one to move on on this one?

Copy link
Collaborator

@fgdorais fgdorais left a comment

Choose a reason for hiding this comment

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

Golfing.

Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
Std/Data/List/Lemmas.lean Outdated Show resolved Hide resolved
@fgdorais fgdorais added awaiting-author Waiting for PR author to address issues and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Nov 5, 2023
All suggestions from @fgdorais

Co-authored-by: François G. Dorais <fgdorais@gmail.com>
@github-actions github-actions bot added awaiting-review This PR is ready for review; the author thinks it is ready to be merged. and removed awaiting-author Waiting for PR author to address issues labels Nov 6, 2023
@fgdorais
Copy link
Collaborator

There was a recent discussion on Zulip that is relevant to this PR: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/List.2Econcat.20and.20List.2Eappend

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 9, 2024
@fgdorais
Copy link
Collaborator

From a quick experiment, this seems to be mostly absorbed by core and other PRs. Should we close?

@AdrienChampion
Copy link
Contributor Author

AdrienChampion commented Jul 20, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review This PR is ready for review; the author thinks it is ready to be merged. merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants