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

leanprover-bot commented Jan 13, 2026

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)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-01-28 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-29 14:35:34)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-01-30 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-30 12:13:56)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c7a9a4e18c2c1defa4261b852f38f6d67f18eb1c --onto 42a0e9245300da6b3d971fa0033d726bb8e11cc3. You can force reference manual CI using the force-manual-ci label. (2026-02-01 20:44:11)

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
@datokrat datokrat marked this pull request as ready for review January 16, 2026 22:58
@[deprecated sum_toList (since := "2026-01-14")]
def sum_eq_sum_toList := @sum_toList

theorem sum_append [Zero α] [Add α] [Std.Associative (α := α) (· + ·)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be worthwhile to leave a comment here explaining why you haven't labelled these as simp, grind =, but only done this on the specializations.

In fact, even better would be to benchmark this against Mathlib, with and without annotations on the generic version. I suspect it is actually fine. (Perhaps not even that much work given our new infrastructure?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've annotated sum_append and sum_reverse instead now, I think the benchmark turned out neutral (as long as 0.5% on build//instructions and no other significant changes is natural variability...)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 29, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 29, 2026
@datokrat
Copy link
Contributor Author

!bench mathlib

@leanprover-radar
Copy link

leanprover-radar commented Jan 29, 2026

Benchmark results for leanprover-community/mathlib4-nightly-testing@2975ae5 against leanprover-community/mathlib4-nightly-testing@e0bf30b are in! @datokrat

  • 🟥 main exited with code 1

No significant changes detected.

@datokrat
Copy link
Contributor Author

!bench mathlib

@leanprover-radar
Copy link

leanprover-radar commented Jan 30, 2026

Benchmark results for leanprover-community/mathlib4-nightly-testing@074ad7a against leanprover-community/mathlib4-nightly-testing@e0bf30b are in! @datokrat

  • build//instructions: +93.3G (+0.05%)

No significant changes detected.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 30, 2026
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 30, 2026
add lemmas used by HumanEval43 and HumanEval110

add required lemmas

fix test

cleanups

improvements

extract some changes into separate PR

remove exists_mem_iff_...

remove LeftIdentity instance parameter

try marking sum_append and sum_reverse as simp/grind lemmas

remove leftover annotations

remove grind annotations on inequalities

revert unrelated file

revert more unrelated stuff
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.

6 participants