Skip to content

Some lemmata for lists and non-empty lists #2730

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

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

pmbittner
Copy link

These are some lemmata we needed in our project Vatras for reasoning on non-empty lists. It seemed these lemmata could be generally useful to other people as well.

-- PR is part of Zurihac 2025

@Taneb
Copy link
Member

Taneb commented Jun 8, 2025

These look like good additions! Can you update Changelog.md with these?

@pmbittner pmbittner force-pushed the non-empty-list branch 2 times, most recently from ad38846 to f4737f0 Compare June 8, 2025 13:37
@pmbittner
Copy link
Author

Ok, I updated the changelog as well. :)

@pmbittner
Copy link
Author

I also migrated some additional lemmas from Data.List.Properties.

Copy link
Contributor

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

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

A few nits, but otherwise this is looking nice.

[Not a big fan of rewrite, but it's not a showstopper.]

@pmbittner
Copy link
Author

Thank you for the review. :) I integrated the requested changes. I also got rid of the rewrite by introducing an analogous lemma to Data.List.Properties and then reusing that.

@pmbittner pmbittner force-pushed the non-empty-list branch 2 times, most recently from f387ebc to 658a9b0 Compare June 10, 2025 09:59
Copy link
Member

@gallais gallais left a comment

Choose a reason for hiding this comment

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

Happy with this; apart from two small naming issues (and related completeness question).

@MatthewDaggitt MatthewDaggitt added this to the v2.3 milestone Jun 15, 2025
@pmbittner
Copy link
Author

Hi everyone,

I implemented the requested changes. Implementing the length-++-≤ʳ theorem required some additional lemmata, which unfortunately required another theorem (++-identityʳ) which was located below in that file. So I had to reorder some theorems, including module definitions. Please check whether my changes remain idiomatic to the standard library.

(Maybe there is a simpler proof for length-++-≤ʳ but I did not find it yet.)

length-++-sucʳ [] _ _ = refl
length-++-sucʳ (_ ∷ xs) y ys = cong suc (length-++-sucʳ xs y ys)

length-++-comm : ∀ (xs ys : List A) →
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this would be easier to prove as a corollary of length being preserved by permutations?

Copy link
Author

Choose a reason for hiding this comment

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

If I understand correctly, this means to

  1. Establish a theorem that says that length is preserved under permutation.
  2. Prove that xs ++ ys is a permutation of ys ++ xs.
  3. Prove length-++-comm as a corollary.

This should be possible and the theorems 1 and 2 should be useful as well. I am not sure this would be a simpler as a sole means to prove length-++-comm though.

Given that there are multiple definitions of permutations, which one should be used here? Data.List.Relation.Binary.Permutation.Setoid or Data.List.Relation.Binary.Permutation.Propositional?

Copy link
Contributor

Choose a reason for hiding this comment

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

I know step 1 already exists, I've used it recently. I'm almost sure step 2 does as well.

I'd use Propositional as it is more precise in what it asserts.

Copy link
Member

Choose a reason for hiding this comment

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

I'd caution against doing this for dependency tree reasons...

Copy link
Author

Choose a reason for hiding this comment

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

So how should we proceed with this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

(Note that I approved the changes, my suggestion above was for a potential future, not this. Now it's up to someone else to also approve the latest changes. Maybe @MatthewDaggitt can re-review?)

@pmbittner pmbittner changed the title Some lemmata for non-empty lists Some lemmata for lists and non-empty lists Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants