Skip to content

Conversation

@datokrat
Copy link
Contributor

@datokrat datokrat commented Jan 13, 2026

This PR provides more lemmas about sums of lists/arrays/vectors, especially sums of Nat or Int lists/arrays/vectors.

This change has been motivated by my experience solving human-eval-lean problems. Sums, minima and maxima are frequently required and the improvements provided in this PR make it easier to verify such programming tasks.

Changes:

  • Added lemmas that sum equals foldl/foldr.
  • Generalized sum_append_nat and sum_reverse_nat lemmas so that they are polymorphic, requiring only some type class instances about the list elements' type. The polymorphic lemmas aren't simp- or grind-annotated because I fear the instance synthesis overhead. However, the Nat and Int specializations are annotated (see below). Note that as {Array,Vector}.min do not exist, some lemmas can't be stated and were omitted.
  • Added List.min_singleton and List.max_singleton lemmas as they were needed for some proofs.
  • Nat-related:
    • Moved all {List,Array,Vector}.sum lemmas that are specific for Nat into their own module: Init.Data.List.Nat.Sum, Init.Data.Array.Nat and Int.Data.Vector.Nat.
    • Notably, moved Nat.sum_pos_iff_exists_pos and renamed it to List.sum_pos_iff_exists_pos_nat. This is more consistent and made it possible to add Array and Vector variants of this lemma.
    • Added lemmas proving that l.sum / l.length lies between the minimum and the maximum of a list.
  • Added analogous lemmas for Int lists/arrays/vectors to parallel modules: Init.Data.List.Int.Sum, Init.Data.Array.Int and Int.Data.Vector.Int.
  • Renamed sum_eq_sum_toList to sum_toList, which better represents the theorem's content.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 13, 2026
@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-01-12 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-01-13 19:07:37)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 13, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jan 13, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 13, 2026
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 13, 2026
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Jan 13, 2026

Mathlib CI status (docs):

@datokrat
Copy link
Contributor Author

!radar

@leanprover-radar
Copy link

leanprover-radar commented Jan 14, 2026

Benchmark results for 75e46e1 against e56351d are in! @datokrat

Warnings (2)

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Runner for run build has different system configurations between commits.
  • Runner for run other has different system configurations between commits.
Small changes (2✅, 10🟥)
  • 🟥 build/module/Init.Data.Array.Lemmas//instructions: +239.0M (+0.3%)
  • 🟥 build/module/Init.Data.Array.OfFn//instructions: +119.5M (+5.0%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.List.Count//instructions: +68.7M (+1.8%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.List.Lemmas//instructions: +657.7M (+1.3%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.List.MinMax//instructions: +61.8M (+1.5%)
  • 🟥 build/module/Init.Data.List.Nat.Find//instructions: +123.3M (+7.4%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.Nat.Div.Lemmas//instructions: +420.3M (+8.1%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.Vector.Lemmas//instructions: +405.1M (+0.7%) (reduced significance based on *//lines)
  • 🟥 build/module/Init.Data.Vector.OfFn//instructions: +93.3M (+1.4%) (reduced significance based on *//lines)
  • build/module/Lake.CLI//instructions: -16.4M (-2.1%)
  • build/module/Lean.Elab.Tactic.Congr//instructions: -21.1M (-2.0%)
  • 🟥 bv_decide_large_aig.lean//instructions: +194.4M (+0.4%)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 15, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 15, 2026
@datokrat datokrat added the changelog-library Library label Jan 15, 2026
@leanprover-community-bot leanprover-community-bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan and removed builds-mathlib CI has verified that Mathlib builds against this PR labels Jan 15, 2026
@datokrat datokrat changed the title wip: human-eval-lean upstreaming feat: lemmas about sums of lists/arrays/vectors Jan 15, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 15, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 15, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 15, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 15, 2026
@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Jan 16, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 16, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 16, 2026
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 changelog-library Library mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants