Skip to content
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
31 changes: 30 additions & 1 deletion LMLExplore/Algebra/BigOperators/Intervals.lean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🟡 generality — request_changes claude/claude-opus-5-5

The public statements are at the natural level, and the card_eq_two/card_eq_three corollaries are derived from the general theorem; only two_mul_sum_range_sub is under-generalized, being stated for n + 1 where the formula holds for every n.

  • LMLExplore/Algebra/BigOperators/Intervals.lean:102 — two_mul_sum_range_sub is stated only for range (n + 1) with (n + 1 - i) and (n + 1) * (n + 2). That is the successor case of Gauss' formula, which holds for every n. Fix: State it as theorem two_mul_sum_range_sub (n : ℕ) : 2 * ∑ i ∈ range n, (n - i) = n * (n + 1) (the same sum_range_reflect proof works) and call it at n + 1 in LowerBound.lean:601. Update the module docstring entry to match.

Reply in this thread to contest a finding; that re-runs only this rubric and posts an answer here. (To fix it, just push a commit — that re-reviews on its own. To contest again after an answer, post a NEW reply rather than editing an old one.)

claude/claude-opus-5-5 · 26s · 107.5k in (100.7k cache read, 6.8k cache write) / 2.3k out tokens · reviewing this diff · rubric · ⚠️ rubrics checkout differs from published main

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ Authors: LMLExplore contributors
-/
module

public import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Group.Fin.Basic
public import Mathlib.Algebra.BigOperators.Intervals
public import Mathlib.Algebra.Order.Field.Basic
public import Mathlib.Tactic.FieldSimp
public import Mathlib.Tactic.Positivity
public import Mathlib.Tactic.Ring

/-!
# The telescoping series `∑ 1 / ((i + 1) (i + 2))` and sums of clipped indices
# The telescoping series `∑ 1 / ((i + 1) (i + 2))` and sums of clipped and shifted indices

Since `1 / ((i + 1) (i + 2)) = 1 / (i + 1) - 1 / (i + 2)`, the partial sums of the series
`∑ 1 / ((i + 1) (i + 2))` telescope to `1 - 1 / (n + 1)`, so they are at most `1`. A union bound
Expand All @@ -30,6 +32,10 @@ the time-uniform deviation bounds of [LS, Lemma 33.8], thus spends at most `δ`
* `LMLExplore.sum_range_add_ite`:
`∑ k < m + L, (if m ≤ k ∧ k < m + L then F k else 0) = ∑ j < L, F (m + j)`, reindexing a sum
over a final block of indices.
* `LMLExplore.sum_range_add_mod`: `∑ x < K, f ((z + x) % K) = ∑ x < K, f x`, a sum over a full
period of residues does not depend on its starting point.
* `LMLExplore.two_mul_sum_range_sub`: `2 * ∑ i < n + 1, (n + 1 - i) = (n + 1) * (n + 2)`, Gauss'
summation formula for the reflected indices `n + 1 - i`.

## References

Expand Down Expand Up @@ -79,4 +85,27 @@ theorem sum_range_add_ite {M : Type*} [AddCommMonoid M] (m L : ℕ) (F : ℕ →
rw [sum_range_add, sum_eq_zero fun k hk ↦ ite_eq_right fun h ↦ by simp at hk; lia, zero_add]
exact sum_congr rfl fun j hj ↦ ite_eq_left ⟨by lia, by simp at hj; lia⟩

/-- A product over a full period of residues modulo `K` does not depend on its starting point `z`:
`∏_{x < K} f ((z + x) % K) = ∏_{x < K} f x`. -/
@[to_additive /-- A sum over a full period of residues modulo `K` does not depend on its starting
point `z`: `∑_{x < K} f ((z + x) % K) = ∑_{x < K} f x`. -/]
theorem prod_range_add_mod {M : Type*} [CommMonoid M] (f : ℕ → M) (K z : ℕ) :
∏ x ∈ range K, f ((z + x) % K) = ∏ x ∈ range K, f x := by
rcases K with _ | K
· simp
rw [← Fin.prod_univ_eq_prod_range (fun x ↦ f ((z + x) % (K + 1))),
← Fin.prod_univ_eq_prod_range f]
exact Fintype.prod_equiv (Equiv.addLeft (Fin.ofNat (K + 1) z)) _ _ fun x ↦ by simp [Fin.val_add]

/-- Gauss' summation formula for the reflected indices `n + 1 - i`:
`2 * ∑_{i < n + 1} (n + 1 - i) = (n + 1) * (n + 2)`. -/
theorem two_mul_sum_range_sub (n : ℕ) :
2 * ∑ i ∈ range (n + 1), (n + 1 - i) = (n + 1) * (n + 2) := by
have h : ∑ i ∈ range (n + 1), (n + 1 - i) = ∑ i ∈ range (n + 1), (i + 1) := by
rw [← sum_range_reflect (fun i ↦ i + 1)]
exact sum_congr rfl fun i hi ↦ by have := mem_range.1 hi; omega
rw [h, sum_add_distrib, mul_add, mul_comm 2, sum_range_id_mul_two]
simp only [sum_const, card_range, smul_eq_mul, mul_one, Nat.add_sub_cancel]
ring

end LMLExplore
41 changes: 41 additions & 0 deletions LMLExplore/Data/Fintype/BigOperators.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/-
Copyright (c) 2026 LMLExplore contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: LMLExplore contributors
-/
module

public import Mathlib.Data.Fintype.BigOperators

/-!
# Counting functions with a coordinatewise condition

The functions `f : ∀ i, α i` with `Q i (f i)` for every `i` form the box
`Fintype.piFinset fun i ↦ {a | Q i a}`, so there are `∏ i, #{a | Q i a}` of them. The lower
bound for e-BH on running maxima (`LMLExplore.EValues.MultipleTesting.RunningMaxima.LowerBound`)
counts the height vectors in a fiber of its information this way.

## Main statements

* `Fintype.card_filter_forall`: the number of functions satisfying a coordinatewise condition is
the product of the numbers of values satisfying it at each coordinate.
-/

public section

namespace Fintype

variable {ι : Type*} [Fintype ι] [DecidableEq ι] {α : ι → Type*} [∀ i, Fintype (α i)]

/-- The number of functions `f : ∀ i, α i` with `Q i (f i)` for every `i` is the product over `i`
of the number of values `a : α i` with `Q i a`. -/
theorem card_filter_forall (Q : ∀ i, α i → Prop)
[∀ i, DecidablePred (Q i)] [DecidablePred fun f : ∀ i, α i ↦ ∀ i, Q i (f i)] :
(Finset.univ.filter fun f : ∀ i, α i ↦ ∀ i, Q i (f i)).card =
∏ i, (Finset.univ.filter (Q i)).card := by
rw [← card_piFinset]
congr 1
ext f
simp [mem_piFinset]

end Fintype
40 changes: 40 additions & 0 deletions LMLExplore/Data/Int/Interval.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/-
Copyright (c) 2026 LMLExplore contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: LMLExplore contributors
-/
module

public import Mathlib.Data.Finset.Max
public import Mathlib.Data.Int.Interval

/-!
# Finite sets of integers of small diameter

A finite set of integers whose elements are pairwise less than `d` apart lies in an interval
`[a, a + d)`, so it has at most `d` elements. The cycle lemma in
`LMLExplore.EValues.MultipleTesting.RunningMaxima.LowerBound` uses it to count the shifts of a
walk whose values are pairwise close.

## Main statements

* `Int.card_le_toNat_of_forall_lt_add`: a finite set of integers whose elements are less than `d`
apart has at most `d.toNat` elements.
-/

public section

namespace Int

/-- A finite set of integers whose elements are less than `d` apart has at most `d` elements. -/
theorem card_le_toNat_of_forall_lt_add {S : Finset ℤ} {d : ℤ}
(h : ∀ x ∈ S, ∀ y ∈ S, x ≤ y → y < x + d) :
S.card ≤ d.toNat := by
rcases S.eq_empty_or_nonempty with rfl | hS
· simp
have hsub : S ⊆ Finset.Ico (S.min' hS) (S.min' hS + d) := fun x hx ↦
Finset.mem_Ico.2 ⟨S.min'_le x hx, h _ (S.min'_mem hS) x hx (S.min'_le x hx)⟩
calc S.card ≤ (Finset.Ico (S.min' hS) (S.min' hS + d)).card := Finset.card_le_card hsub
_ = d.toNat := by simp

end Int
44 changes: 44 additions & 0 deletions LMLExplore/Data/Nat/Mod.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/-
Copyright (c) 2026 LMLExplore contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: LMLExplore contributors
-/
module

public import Mathlib.Data.Nat.Init
import Mathlib.Tactic.SplitIfs

/-!
# Shifting residues modulo `K`

For residues `h`, `u` and `x` modulo `K`, the shift `(h + u) % K` is `x` exactly when `h` is the
shift `(x + K - u) % K` of `x` by `-u`. The cycle lemma of the lower bound for e-BH on running
maxima (`LMLExplore.EValues.MultipleTesting.RunningMaxima.LowerBound`) uses it to count shifted
heights.

## Main statements

* `Nat.add_mod_eq_iff`: `(h + u) % K = x ↔ h = (x + K - u) % K` for `h, u, x < K`.
-/

public section

namespace Nat

/-- Shifting residues modulo `K`: for `h, u, x < K`, `(h + u) % K = x` exactly when
`h = (x + K - u) % K`. -/
theorem add_mod_eq_iff {K h u x : ℕ} (hh : h < K) (hu : u < K) (hx : x < K) :
(h + u) % K = x ↔ h = (x + K - u) % K := by
have e1 : (h + u) % K = if h + u < K then h + u else h + u - K := by
split_ifs with h'
· exact Nat.mod_eq_of_lt h'
· rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)]
have e2 : (x + K - u) % K = if x < u then x + K - u else x - u := by
split_ifs with h'
· exact Nat.mod_eq_of_lt (by omega)
· rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)]
omega
rw [e1, e2]
split_ifs <;> omega

end Nat
Loading
Loading