consecutive_sum_ap_distinct_sums
For integers a and K with 1 ≤ a, 1 ≤ K, and K ≤ a, and natural numbers u, r, v, s such that u + r ≤ consecutive_sum_bound_k a K, 0 < r, v + s ≤ consecutive_sum_bound_k a K, and 0 < s, if ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = ∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j, then u = v and r = s.
Statement
theorem consecutive_sum_ap_distinct_sums (a K : ℤ) (ha : 1 ≤ a) (hK : 1 ≤ K) (haK : K ≤ a)
(u r v s : ℕ)
(hur : u + r ≤ consecutive_sum_bound_k a K) (hr : 0 < r)
(hvs : v + s ≤ consecutive_sum_bound_k a K) (hs : 0 < s)
(hsum : ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i =
∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j) :
u = v ∧ r = s- Source
- arXiv:2611.30462 Theorem 3.2
- Verified
- 25 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 4
- consecutive_sum_bound_kFor integers a and K, the index k = ⌊2√(a/K - 1)⌋ as a natural number.
- consecutive_sum_apFor integers a and K and a natural number i, the integer a + ((i : ℤ) - 1) * K, representing the i-th term of an arithmetic progression…
- LinearOrder.toTotalPreorderEvery
LinearOrderis aTotalPreorder. - TotalPreorderA total preorder: a preorder where
≤is total (complete). This is weaker thanLinearOrder— it does NOT require antisymmetry or…
Read back from the Lean
For all integers $a$ and $K$ satisfying $1 ≤ a$, $1 ≤ K$, and $K ≤ a$, and for all natural numbers $u, r, v, s$: if $u + r ≤ \text{consecutive\_sum\_bound\_k}(a, K)$, $0 < r$, $v + s ≤ \text{consecutive\_sum\_bound\_k}(a, K)$, $0 < s$, and $\sum_{i \in (u, u + r]} \text{consecutive\_sum\_ap}(a, K, i) = \sum_{j \in (v, v + s]} \text{consecutive\_sum\_ap}(a, K, j)$, then $u = v$ and $r = s$.
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
The proof, explained
To prove that two subsegment sums of an arithmetic progression are distinct unless the intervals are identical, we first express the sum of the progression over (u, u + r] in closed form. We then show that the two intervals must have the same length (r = s): if one were strictly shorter, comparing the doubled sums would force k² < k², contradicting the definition of the length bound k = ⌊2√(a/K - 1)⌋. Finally, knowing r = s, the equation between the two sums simplifies to 2Kr(u - v) = 0, which immediately implies u = v because K and r are positive.
Twice the sum of the integers in the interval (u, u + r] is r(2u + r + 1).
We argue by induction on r. The base case r = 0 is trivial because the interval is empty. For the inductive step r = r' + 1, we split off the top element u + r' + 1 using sum_Ioc_succ_top and simplify using the induction hypothesis and linear arithmetic.
uses
Nat.le_add_right,add_assoc,sum_Ioc_succ_topinduction r with | zero => simp | succ r' ih => have hle : u ≤ u + r' := Nat.le_add_right u r' rw [← add_assoc, sum_Ioc_succ_top hle] push_cast linarith
The sum of the arithmetic progression over (u, u + r] equals r(a - K) + K ∑ i.
Each term of the progression is consecutive_sum_ap a K i = (a - K) + i * K. Distributing the sum over addition, the constant term (a - K) is summed over r elements, giving r * (a - K), and factoring K out of the remaining sum yields the formula.
uses
sum_congr,sum_add_distrib,sum_const,nsmul_eq_mul,Nat.card_Ioc,Nat.add_sub_cancel_left,mul_sumhave : ∀ i ∈ Ioc u (u + r), consecutive_sum_ap a K i = (a - K) + (i : ℤ) * K := by intro i _ dsimp [consecutive_sum_ap] ring rw [sum_congr rfl this] rw [sum_add_distrib, sum_const, nsmul_eq_mul, Nat.card_Ioc, Nat.add_sub_cancel_left] have h_comm : ∑ x ∈ Ioc u (u + r), (x : ℤ) * K = K * ∑ i ∈ Ioc u (u + r), (i : ℤ) := by rw [mul_sum] apply sum_congr rfl intro x _ ring rw [h_comm]
Twice the sum of the arithmetic progression over (u, u + r] equals 2r(a - K) + Kr(2u + r + 1).
We multiply the formula for the sum of the progression by 2 and substitute the closed form for twice the sum of indices from consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_id.
uses
consecutive_sum_ap_distinct_sums_sum_ap,consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_idhave h1 := consecutive_sum_ap_distinct_sums_sum_ap a K u r have h2 := consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_id u r calc 2 * ∑ i ∈ Ioc u (u + r), consecutive_sum_ap a K i _ = 2 * ((r : ℤ) * (a - K) + K * ∑ i ∈ Ioc u (u + r), (i : ℤ)) := by rw [h1] _ = 2 * (r : ℤ) * (a - K) + K * (2 * ∑ i ∈ Ioc u (u + r), (i : ℤ)) := by ring _ = 2 * (r : ℤ) * (a - K) + K * (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) := by rw [h2]; ring
The length bound k satisfies K * k² ≤ 4(a - K).
Since 1 ≤ K ≤ a, the ratio a / K is at least 1, so (a / K) - 1 ≥ 0. The definition of k as the floor of 2√(a/K - 1) gives k ≤ 2√(a/K - 1). Squaring both sides yields k² ≤ 4(a/K - 1), and multiplying by K > 0 gives K * k² ≤ 4(a - K) in ℝ, which casts down to ℤ.
uses
sub_nonneg,le_div_iff₀,Nat.floor_le,Real.sq_sqrt,div_mul_cancel₀,ne_of_gthave hKa_real : (K : ℝ) ≤ a := by exact_mod_cast haK have hKpos : (0 : ℝ) < (K : ℝ) := by positivity have h_nonneg : 0 ≤ (a : ℝ) / (K : ℝ) - 1 := by rw [sub_nonneg] rw [le_div_iff₀ hKpos] linarith have h_sqrt_nonneg : 0 ≤ 2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1) := by positivity have h_floor := Nat.floor_le h_sqrt_nonneg have h1 : (consecutive_sum_bound_k a K : ℝ) ^ 2 ≤ (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 := by dsimp [consecutive_sum_bound_k] nlinarith have h2 : (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 = 4 * ((a : ℝ) / (K : ℝ) - 1) := by calc (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 _ = 4 * (Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 := by ring _ = 4 * ((a : ℝ) / (K : ℝ) - 1) := by rw [Real.sq_sqrt h_nonneg] have h_real : (K : ℝ) * (consecutive_sum_bound_k a K : ℝ)^2 ≤ 4 * ((a : ℝ) - (K : ℝ)) := by have h_div : 4 * ((a : ℝ) / (K : ℝ) - 1) * (K : ℝ) = 4 * ((a : ℝ) - (K : ℝ)) := by calc 4 * ((a : ℝ) / (K : ℝ) - 1) * (K : ℝ) _ = 4 * (((a : ℝ) / (K : ℝ)) * (K : ℝ) - (K : ℝ)) := by ring _ = 4 * ((a : ℝ) - (K : ℝ)) := by rw [div_mul_cancel₀ _ (ne_of_gt hKpos)] nlinarith exact_mod_cast h_real
If r < s and the two sums are equal, then 2(s - r)(a - K) = K [r(2u + r + 1) - s(2v + s + 1)].
Assuming r < s and equating the two sums, we multiply both sides by 2 and expand them using consecutive_sum_ap_distinct_sums_two_mul_sum_ap. Rearranging terms isolates 2(s - r)(a - K) on the left-hand side.
uses
Nat.zero_le,consecutive_sum_ap_distinct_sums_two_mul_sum_aplet k : ℤ := (consecutive_sum_bound_k a K : ℤ) have hrs_int : (r : ℤ) + 1 ≤ (s : ℤ) := by exact_mod_cast hrs have hr_ge : 1 ≤ (r : ℤ) := by exact_mod_cast hr have hu_le : (u : ℤ) + (r : ℤ) ≤ k := by show (u : ℤ) + (r : ℤ) ≤ (consecutive_sum_bound_k a K : ℤ) exact_mod_cast hur have hv_ge : 0 ≤ (v : ℤ) := by exact_mod_cast (Nat.zero_le v) have hsum2 : 2 * ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = 2 * ∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j := by rw [hsum] rw [consecutive_sum_ap_distinct_sums_two_mul_sum_ap, consecutive_sum_ap_distinct_sums_two_mul_sum_ap] at hsum2 have hsum_eq : 2 * ((s : ℤ) - (r : ℤ)) * (a - K) = K * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) := by linarith [hsum2]
k² is bounded above by 2 [r(2u + r + 1) - s(2v + s + 1)].
Because s - r ≥ 1 and a - K ≥ 0, we have 4(a - K) ≤ 4(s - r)(a - K) = 2 * [2(s - r)(a - K)]. Combining this with K * k² ≤ 4(a - K) from consecutive_sum_ap_distinct_sums_k_sq_mul_le and the algebraic relation above gives K * k² ≤ K * 2 [r(2u + r + 1) - s(2v + s + 1)]. Dividing by K > 0 proves the inequality.
uses
consecutive_sum_ap_distinct_sums_k_sq_mul_le,le_of_mul_le_mul_lefthave hk_bound : K * k^2 ≤ 4 * (a - K) := consecutive_sum_ap_distinct_sums_k_sq_mul_le a K hK haK have hk_le : k^2 ≤ 2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) := by have h1 : 4 * (a - K) ≤ 4 * ((s : ℤ) - (r : ℤ)) * (a - K) := by have : 1 ≤ (s : ℤ) - (r : ℤ) := by linarith have : 0 ≤ a - K := by linarith nlinarith have h2 : K * k^2 ≤ K * (2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1))) := by linarith [hk_bound, h1, hsum_eq] have hK_pos : 0 < K := by linarith exact le_of_mul_le_mul_left h2 hK_pos
2 [r(2u + r + 1) - s(2v + s + 1)] is bounded above by 4r(k - r - 1) - 4.
Using u + r ≤ k, the first term r(2u + r + 1) is at most r(2k - r + 1). Using s ≥ r + 1 and v ≥ 0, the subtracted term s(2v + s + 1) is at least (r + 1)(r + 2). Combining these gives an upper bound of 4r(k - r - 1) - 4 on the doubled difference.
have h_ub : 2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) ≤ 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 := by have h_r_term : (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) ≤ (r : ℤ) * (2 * k - (r : ℤ) + 1) := by have : 2 * (u : ℤ) + (r : ℤ) + 1 ≤ 2 * k - (r : ℤ) + 1 := by linarith nlinarith have h_s_term : ((r : ℤ) + 1) * ((r : ℤ) + 2) ≤ (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1) := by have : (r : ℤ) + 2 ≤ 2 * (v : ℤ) + (s : ℤ) + 1 := by linarith nlinarith linarith
4r(k - r - 1) - 4 is strictly less than k², giving a contradiction.
Completing the square shows 4r(k - r - 1) - 4 - k² = -((k - 2r)² + 4r + 4). Because squares are non-negative and r ≥ 1, this difference is strictly negative, so 4r(k - r - 1) - 4 < k². Chaining with the previous inequalities implies k² < k², which is impossible.
uses
sq_nonneghave h_quad : 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 < k^2 := by have hsq : 0 ≤ (k - 2 * (r : ℤ))^2 := sq_nonneg _ have h_id : 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 - k^2 = -((k - 2 * (r : ℤ))^2 + 4 * (r : ℤ) + 4) := by ring linarith linarith
The lengths of the two subsegments must be equal: r = s.
By consecutive_sum_ap_distinct_sums_not_lt, r < s is impossible. By symmetry, swapping the roles of the two intervals shows s < r is also impossible. Therefore, r = s.
uses
consecutive_sum_ap_distinct_sums_not_lthave h_not_lt : ¬ (r < s) := fun hlt => consecutive_sum_ap_distinct_sums_not_lt a K hK haK u r v s hur hr hlt hsum have h_not_gt : ¬ (s < r) := fun hgt => consecutive_sum_ap_distinct_sums_not_lt a K hK haK v s u r hvs hs hgt hsum.symm have hrs : r = s := by omega subst hrs
The starting indices must be equal: u = v, so u = v and r = s.
With r = s, equating twice the two sums and applying consecutive_sum_ap_distinct_sums_two_mul_sum_ap leaves 2 * K * r * (u - v) = 0. Since K ≥ 1 and r > 0, the factor 2Kr is strictly positive, forcing u - v = 0 and hence u = v.
uses
consecutive_sum_ap_distinct_sums_two_mul_sum_ap,Nat.cast_inj.mp,sub_eq_zero.mphave hsum2 : 2 * ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = 2 * ∑ j ∈ Finset.Ioc v (v + r), consecutive_sum_ap a K j := by rw [hsum] rw [consecutive_sum_ap_distinct_sums_two_mul_sum_ap, consecutive_sum_ap_distinct_sums_two_mul_sum_ap] at hsum2 have huv_diff : 2 * K * (r : ℤ) * ((u : ℤ) - (v : ℤ)) = 0 := by linarith [hsum2] have hKr_pos : 0 < 2 * K * (r : ℤ) := by have : (0 : ℤ) < (r : ℤ) := by exact_mod_cast hr nlinarith have h_sub : (u : ℤ) - (v : ℤ) = 0 := by nlinarith [huv_diff, hKr_pos] have huv : u = v := Nat.cast_inj.mp (sub_eq_zero.mp h_sub) exact ⟨huv, rfl⟩
Nat.le_add_right- For natural numbers n and k, n ≤ n + k.
add_assoc- Addition is associative: (a + b) + c = a + (b + c).
sum_Ioc_succ_top- For a ≤ b, the sum over (a, b + 1] equals the sum over (a, b] plus the term at b + 1.
sum_congr- If two index sets are equal and two functions agree on the set, their sums are equal.
sum_add_distrib- The sum of a sum is the sum of the sums: ∑ (f x + g x) = ∑ f x + ∑ g x.
sum_const- The sum of a constant over a finite set equals the cardinality of the set multiplied by the constant.
nsmul_eq_mul- Scalar multiplication by a natural number n • a is equal to the product n * a.
Nat.card_Ioc- The cardinality of the half-open interval of natural numbers (a, b] is b - a.
Nat.add_sub_cancel_left- For natural numbers n and m, (n + m) - n = m.
mul_sum- Multiplication distributes over finite sums: a * ∑ f i = ∑ (a * f i).
consecutive_sum_ap_distinct_sums_sum_ap- The sum of consecutive_sum_ap a K i over (u, u + r] equals r(a - K) + K ∑ i.
consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_id- Twice the sum of integers over (u, u + r] equals r(2u + r + 1).
sub_nonneg- In an ordered additive group, 0 ≤ a - b if and only if b ≤ a.
le_div_iff₀- For c > 0, a ≤ b / c if and only if a * c ≤ b.
Nat.floor_le- For a non-negative real number, its floor as a natural number is less than or equal to itself.
Real.sq_sqrt- For a non-negative real number x, (√x)² = x.
div_mul_cancel₀- For a non-zero element b, (a / b) * b = a.
ne_of_gt- If b < a, then a ≠ b.
Nat.zero_le- Every natural number is non-negative: 0 ≤ n.
consecutive_sum_ap_distinct_sums_two_mul_sum_ap- Twice the sum of the arithmetic progression over (u, u + r] equals 2r(a - K) + Kr(2u + r + 1).
consecutive_sum_ap_distinct_sums_k_sq_mul_le- For 1 ≤ K ≤ a, K * k² ≤ 4(a - K) where k = consecutive_sum_bound_k a K.
le_of_mul_le_mul_left- If a * b ≤ a * c and a > 0, then b ≤ c.
sq_nonneg- The square of any element in a linear ordered semiring is non-negative.
consecutive_sum_ap_distinct_sums_not_lt- Under the bound on total length, two subsegment sums of the arithmetic progression cannot have strictly different lengths r < s.
Nat.cast_inj.mp- If the integer casts of two natural numbers are equal, the natural numbers are equal.
sub_eq_zero.mp- If x - y = 0, then x = y.
- The bound k = ⌊2√(a/K - 1)⌋ is chosen so that K k² ≤ 4(a - K); the impossibility of different lengths r < s in consecutive_sum_ap_distinct_sums_not_lt relies on completing the square (k - 2r)² ≥ 0 to show that the difference of the sums cannot be reconciled with this bound.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
open Finsetlemma consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_id (u r : ℕ) : 2 * ∑ i ∈ Ioc u (u + r), (i : ℤ) = (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) := by induction r with | zero => simp | succ r' ih => have hle : u ≤ u + r' := Nat.le_add_right u r' rw [← add_assoc, sum_Ioc_succ_top hle] push_cast linarithlemma consecutive_sum_ap_distinct_sums_sum_ap (a K : ℤ) (u r : ℕ) : ∑ i ∈ Ioc u (u + r), consecutive_sum_ap a K i = (r : ℤ) * (a - K) + K * ∑ i ∈ Ioc u (u + r), (i : ℤ) := by have : ∀ i ∈ Ioc u (u + r), consecutive_sum_ap a K i = (a - K) + (i : ℤ) * K := by intro i _ dsimp [consecutive_sum_ap] ring rw [sum_congr rfl this] rw [sum_add_distrib, sum_const, nsmul_eq_mul, Nat.card_Ioc, Nat.add_sub_cancel_left] have h_comm : ∑ x ∈ Ioc u (u + r), (x : ℤ) * K = K * ∑ i ∈ Ioc u (u + r), (i : ℤ) := by rw [mul_sum] apply sum_congr rfl intro x _ ring rw [h_comm]lemma consecutive_sum_ap_distinct_sums_two_mul_sum_ap (a K : ℤ) (u r : ℕ) : 2 * ∑ i ∈ Ioc u (u + r), consecutive_sum_ap a K i = 2 * (r : ℤ) * (a - K) + K * (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) := by have h1 := consecutive_sum_ap_distinct_sums_sum_ap a K u r have h2 := consecutive_sum_ap_distinct_sums_two_mul_sum_Ioc_id u r calc 2 * ∑ i ∈ Ioc u (u + r), consecutive_sum_ap a K i _ = 2 * ((r : ℤ) * (a - K) + K * ∑ i ∈ Ioc u (u + r), (i : ℤ)) := by rw [h1] _ = 2 * (r : ℤ) * (a - K) + K * (2 * ∑ i ∈ Ioc u (u + r), (i : ℤ)) := by ring _ = 2 * (r : ℤ) * (a - K) + K * (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) := by rw [h2]; ringlemma consecutive_sum_ap_distinct_sums_k_sq_mul_le (a K : ℤ) (hK : 1 ≤ K) (haK : K ≤ a) : K * ((consecutive_sum_bound_k a K : ℤ))^2 ≤ 4 * (a - K) := by have hKa_real : (K : ℝ) ≤ a := by exact_mod_cast haK have hKpos : (0 : ℝ) < (K : ℝ) := by positivity have h_nonneg : 0 ≤ (a : ℝ) / (K : ℝ) - 1 := by rw [sub_nonneg] rw [le_div_iff₀ hKpos] linarith have h_sqrt_nonneg : 0 ≤ 2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1) := by positivity have h_floor := Nat.floor_le h_sqrt_nonneg have h1 : (consecutive_sum_bound_k a K : ℝ) ^ 2 ≤ (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 := by dsimp [consecutive_sum_bound_k] nlinarith have h2 : (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 = 4 * ((a : ℝ) / (K : ℝ) - 1) := by calc (2 * Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 _ = 4 * (Real.sqrt ((a : ℝ) / (K : ℝ) - 1)) ^ 2 := by ring _ = 4 * ((a : ℝ) / (K : ℝ) - 1) := by rw [Real.sq_sqrt h_nonneg] have h_real : (K : ℝ) * (consecutive_sum_bound_k a K : ℝ)^2 ≤ 4 * ((a : ℝ) - (K : ℝ)) := by have h_div : 4 * ((a : ℝ) / (K : ℝ) - 1) * (K : ℝ) = 4 * ((a : ℝ) - (K : ℝ)) := by calc 4 * ((a : ℝ) / (K : ℝ) - 1) * (K : ℝ) _ = 4 * (((a : ℝ) / (K : ℝ)) * (K : ℝ) - (K : ℝ)) := by ring _ = 4 * ((a : ℝ) - (K : ℝ)) := by rw [div_mul_cancel₀ _ (ne_of_gt hKpos)] nlinarith exact_mod_cast h_reallemma consecutive_sum_ap_distinct_sums_not_lt (a K : ℤ) (hK : 1 ≤ K) (haK : K ≤ a) (u r v s : ℕ) (hur : u + r ≤ consecutive_sum_bound_k a K) (hr : 0 < r) (hrs : r < s) (hsum : ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = ∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j) : False := by let k : ℤ := (consecutive_sum_bound_k a K : ℤ) have hrs_int : (r : ℤ) + 1 ≤ (s : ℤ) := by exact_mod_cast hrs have hr_ge : 1 ≤ (r : ℤ) := by exact_mod_cast hr have hu_le : (u : ℤ) + (r : ℤ) ≤ k := by show (u : ℤ) + (r : ℤ) ≤ (consecutive_sum_bound_k a K : ℤ) exact_mod_cast hur have hv_ge : 0 ≤ (v : ℤ) := by exact_mod_cast (Nat.zero_le v) have hsum2 : 2 * ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = 2 * ∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j := by rw [hsum] rw [consecutive_sum_ap_distinct_sums_two_mul_sum_ap, consecutive_sum_ap_distinct_sums_two_mul_sum_ap] at hsum2 have hsum_eq : 2 * ((s : ℤ) - (r : ℤ)) * (a - K) = K * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) := by linarith [hsum2] have hk_bound : K * k^2 ≤ 4 * (a - K) := consecutive_sum_ap_distinct_sums_k_sq_mul_le a K hK haK have hk_le : k^2 ≤ 2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) := by have h1 : 4 * (a - K) ≤ 4 * ((s : ℤ) - (r : ℤ)) * (a - K) := by have : 1 ≤ (s : ℤ) - (r : ℤ) := by linarith have : 0 ≤ a - K := by linarith nlinarith have h2 : K * k^2 ≤ K * (2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1))) := by linarith [hk_bound, h1, hsum_eq] have hK_pos : 0 < K := by linarith exact le_of_mul_le_mul_left h2 hK_pos have h_ub : 2 * ((r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) - (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1)) ≤ 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 := by have h_r_term : (r : ℤ) * (2 * (u : ℤ) + (r : ℤ) + 1) ≤ (r : ℤ) * (2 * k - (r : ℤ) + 1) := by have : 2 * (u : ℤ) + (r : ℤ) + 1 ≤ 2 * k - (r : ℤ) + 1 := by linarith nlinarith have h_s_term : ((r : ℤ) + 1) * ((r : ℤ) + 2) ≤ (s : ℤ) * (2 * (v : ℤ) + (s : ℤ) + 1) := by have : (r : ℤ) + 2 ≤ 2 * (v : ℤ) + (s : ℤ) + 1 := by linarith nlinarith linarith have h_quad : 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 < k^2 := by have hsq : 0 ≤ (k - 2 * (r : ℤ))^2 := sq_nonneg _ have h_id : 4 * (r : ℤ) * (k - (r : ℤ) - 1) - 4 - k^2 = -((k - 2 * (r : ℤ))^2 + 4 * (r : ℤ) + 4) := by ring linarith linarith/-- Consecutive sums in the arithmetic progression of length k = ⌊2√(a/K - 1)⌋ are distinct. -/theorem consecutive_sum_ap_distinct_sums (a K : ℤ) (ha : 1 ≤ a) (hK : 1 ≤ K) (haK : K ≤ a) (u r v s : ℕ) (hur : u + r ≤ consecutive_sum_bound_k a K) (hr : 0 < r) (hvs : v + s ≤ consecutive_sum_bound_k a K) (hs : 0 < s) (hsum : ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = ∑ j ∈ Finset.Ioc v (v + s), consecutive_sum_ap a K j) : u = v ∧ r = s := by have h_not_lt : ¬ (r < s) := fun hlt => consecutive_sum_ap_distinct_sums_not_lt a K hK haK u r v s hur hr hlt hsum have h_not_gt : ¬ (s < r) := fun hgt => consecutive_sum_ap_distinct_sums_not_lt a K hK haK v s u r hvs hs hgt hsum.symm have hrs : r = s := by omega subst hrs have hsum2 : 2 * ∑ i ∈ Finset.Ioc u (u + r), consecutive_sum_ap a K i = 2 * ∑ j ∈ Finset.Ioc v (v + r), consecutive_sum_ap a K j := by rw [hsum] rw [consecutive_sum_ap_distinct_sums_two_mul_sum_ap, consecutive_sum_ap_distinct_sums_two_mul_sum_ap] at hsum2 have huv_diff : 2 * K * (r : ℤ) * ((u : ℤ) - (v : ℤ)) = 0 := by linarith [hsum2] have hKr_pos : 0 < 2 * K * (r : ℤ) := by have : (0 : ℤ) < (r : ℤ) := by exact_mod_cast hr nlinarith have h_sub : (u : ℤ) - (v : ℤ) = 0 := by nlinarith [huv_diff, hKr_pos] have huv : u = v := Nat.cast_inj.mp (sub_eq_zero.mp h_sub) exact ⟨huv, rfl⟩