Skip to content

Commit a3a2bc4

Browse files
mo271Parcly-Taxeljcommelin
committed
feat: port Archive.OxfordInvariants.2021summer.Week3P1 (leanprover-community#5705)
Co-authored-by: Moritz Firsching <firsching@google.com> Co-authored-by: Jeremy Tan Jie Rui <reddeloostw@gmail.com> Co-authored-by: Johan Commelin <johan@commelin.net>
1 parent 6fae06c commit a3a2bc4

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

Archive.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Archive.Imo.Imo2021Q1
3434
import Archive.MiuLanguage.Basic
3535
import Archive.MiuLanguage.DecisionNec
3636
import Archive.MiuLanguage.DecisionSuf
37+
import Archive.OxfordInvariants.Summer2021.Week3P1
3738
import Archive.Sensitivity
3839
import Archive.Wiedijk100Theorems.AbelRuffini
3940
import Archive.Wiedijk100Theorems.AreaOfACircle
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/-
2+
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yaël Dillies, Bhavik Mehta
5+
6+
! This file was ported from Lean 3 source module oxford_invariants.2021summer.week3_p1
7+
! leanprover-community/mathlib commit 328375597f2c0dd00522d9c2e5a33b6a6128feeb
8+
! Please do not edit these lines, except to modify the commit id
9+
! if you have ported upstream changes.
10+
-/
11+
import Mathlib.Algebra.BigOperators.Order
12+
import Mathlib.Algebra.BigOperators.Ring
13+
import Mathlib.Algebra.CharZero.Lemmas
14+
import Mathlib.Data.Rat.Cast
15+
16+
/-!
17+
# The Oxford Invariants Puzzle Challenges - Summer 2021, Week 3, Problem 1
18+
19+
## Original statement
20+
21+
Let `n ≥ 3`, `a₁, ..., aₙ` be strictly positive integers such that `aᵢ ∣ aᵢ₋₁ + aᵢ₊₁` for
22+
`i = 2, ..., n - 1`. Show that $\sum_{i=1}^{n-1}\dfrac{a_0a_n}{a_ia_{i+1}} ∈ \mathbb N$.
23+
24+
## Comments
25+
26+
Mathlib is based on type theory, so saying that a rational is a natural doesn't make sense. Instead,
27+
we ask that there exists `b : ℕ` whose cast to `α` is the sum we want.
28+
29+
In mathlib, `ℕ` starts at `0`. To make the indexing cleaner, we use `a₀, ..., aₙ₋₁` instead of
30+
`a₁, ..., aₙ`. Similarly, it's nicer to not use subtraction of naturals, so we replace
31+
`aᵢ ∣ aᵢ₋₁ + aᵢ₊₁` by `aᵢ₊₁ ∣ aᵢ + aᵢ₊₂`.
32+
33+
We don't actually have to work in `ℚ` or `ℝ`. We can be even more general by stating the result for
34+
any linearly ordered field.
35+
36+
Instead of having `n` naturals, we use a function `a : ℕ → ℕ`.
37+
38+
In the proof itself, we replace `n : ℕ, 1 ≤ n` by `n + 1`.
39+
40+
The statement is actually true for `n = 0, 1` (`n = 1, 2` before the reindexing) as the sum is
41+
simply `0` and `1` respectively. So the version we prove is slightly more general.
42+
43+
Overall, the indexing is a bit of a mess to understand. But, trust Lean, it works.
44+
45+
## Formalised statement
46+
47+
Let `n : ℕ`, `a : ℕ → ℕ`, `∀ i ≤ n, 0 < a i`, `∀ i, i + 2 ≤ n → aᵢ₊₁ ∣ aᵢ + aᵢ₊₂` (read `→` as
48+
"implies"). Then there exists `b : ℕ` such that `b` as an element of any linearly ordered field
49+
equals $\sum_{i=0}^{n-1} (a_0 a_n) / (a_i a_{i+1})$.
50+
51+
## Proof outline
52+
53+
The case `n = 0` is trivial.
54+
55+
For `n + 1`, we prove the result by induction but by adding `aₙ₊₁ ∣ aₙ * b - a₀` to the induction
56+
hypothesis, where `b` is the previous sum, $\sum_{i=0}^{n-1} (a_0 a_n) / (a_i a_{i+1})$, as a
57+
natural.
58+
* Base case:
59+
* $\sum_{i=0}^0 (a_0 a_{0+1}) / (a_0 a_{0+1})$ is a natural:
60+
$\sum_{i=0}^0 (a_0 a_{0+1}) / (a_0 a_{0+1}) = (a_0 a_1) / (a_0 a_1) = 1$.
61+
* Divisibility condition:
62+
`a₀ * 1 - a₀ = 0` is clearly divisible by `a₁`.
63+
* Induction step:
64+
* $\sum_{i=0}^n (a_0 a_{n+1}) / (a_i a_{i+1})$ is a natural:
65+
$$\sum_{i=0}^{n+1} (a_0 a_{n+2}) / (a_i a_{i+1})
66+
= \sum_{i=0}^n\ (a_0 a_{n+2}) / (a_i a_{i+1}) + (a_0 a_{n+2}) / (a_{n+1} a_{n+2})
67+
= a_{n+2} / a_{n+1} × \sum_{i=0}^n (a_0 a_{n+1}) / (a_i a_{i+1}) + a_0 / a_{n+1}
68+
= a_{n+2} / a_{n+1} × b + a_0 / a_{n+1}
69+
= (a_n + a_{n+2}) / a_{n+1} × b - (a_n b - a_0)(a_{n+1})$$
70+
which is a natural because `(aₙ + aₙ₊₂)/aₙ₊₁`, `b` and `(aₙ * b - a₀)/aₙ₊₁` are (plus an
71+
annoying inequality, or the fact that the original sum is positive because its terms are).
72+
* Divisibility condition:
73+
`aₙ₊₁ * ((aₙ + aₙ₊₂)/aₙ₊₁ * b - (aₙ * b - a₀)/aₙ₊₁) - a₀ = aₙ₊₁aₙ₊₂b` is divisible by `aₙ₊₂`.
74+
-/
75+
76+
open scoped BigOperators
77+
78+
variable {α : Type _} [LinearOrderedField α]
79+
80+
theorem OxfordInvariants.Week3P1 (n : ℕ) (a : ℕ → ℕ) (a_pos : ∀ i ≤ n, 0 < a i)
81+
(ha : ∀ i, i + 2 ≤ n → a (i + 1) ∣ a i + a (i + 2)) :
82+
∃ b : ℕ, (b : α) = ∑ i in Finset.range n, (a 0 : α) * a n / (a i * a (i + 1)) := by
83+
-- Treat separately `n = 0` and `n ≥ 1`
84+
cases' n with n
85+
/- Case `n = 0`
86+
The sum is trivially equal to `0` -/
87+
· exact ⟨0, by rw [Nat.cast_zero, Finset.sum_range_zero]⟩
88+
-- `⟨Claim it, Prove it⟩`
89+
/- Case `n ≥ 1`. We replace `n` by `n + 1` everywhere to make this inequality explicit
90+
Set up the stronger induction hypothesis -/
91+
rsuffices ⟨b, hb, -⟩ :
92+
∃ b : ℕ,
93+
(b : α) = ∑ i in Finset.range (n + 1), (a 0 : α) * a (n + 1) / (a i * a (i + 1)) ∧
94+
a (n + 1) ∣ a n * b - a 0
95+
· exact ⟨b, hb⟩
96+
simp_rw [← @Nat.cast_pos α] at a_pos
97+
/- Declare the induction
98+
`ih` will be the induction hypothesis -/
99+
induction' n with n ih
100+
/- Base case
101+
Claim that the sum equals `1`-/
102+
· refine' ⟨1, _, _⟩
103+
-- Check that this indeed equals the sum
104+
· rw [Nat.cast_one, Finset.sum_range_one]
105+
norm_num
106+
rw [div_self]
107+
exact (mul_pos (a_pos 0 (Nat.zero_le _)) (a_pos 1 (Nat.zero_lt_succ _))).ne'
108+
-- Check the divisibility condition
109+
· rw [mul_one, tsub_self]
110+
exact dvd_zero _
111+
/- Induction step
112+
`b` is the value of the previous sum as a natural, `hb` is the proof that it is indeed the
113+
value, and `han` is the divisibility condition -/
114+
obtain ⟨b, hb, han⟩ :=
115+
ih (fun i hi => ha i <| Nat.le_succ_of_le hi) fun i hi => a_pos i <| Nat.le_succ_of_le hi
116+
specialize ha n le_rfl
117+
have ha₀ : a 0 ≤ a n * b := by
118+
-- Needing this is an artifact of `ℕ`-subtraction.
119+
rw [← @Nat.cast_le α, Nat.cast_mul, hb, ←
120+
div_le_iff' (a_pos _ <| n.le_succ.trans <| Nat.le_succ _), ←
121+
mul_div_mul_right _ _ (a_pos _ <| Nat.le_succ _).ne']
122+
suffices h : ∀ i, i ∈ Finset.range (n + 1) → 0 ≤ (a 0 : α) * a (n + 1) / (a i * a (i + 1))
123+
· exact Finset.single_le_sum h (Finset.self_mem_range_succ n)
124+
refine' fun i _ => div_nonneg _ _ <;> refine' mul_nonneg _ _ <;> exact Nat.cast_nonneg _
125+
-- Claim that the sum equals `(aₙ + aₙ₊₂)/aₙ₊₁ * b - (aₙ * b - a₀)/aₙ₊₁`
126+
refine' ⟨(a n + a (n + 2)) / a (n + 1) * b - (a n * b - a 0) / a (n + 1), _, _⟩
127+
-- Check that this indeed equals the sum
128+
· calc
129+
(((a n + a (n + 2)) / a (n + 1) * b - (a n * b - a 0) / a (n + 1) : ℕ) : α) =
130+
((a n + a (n + 2)) / a (n + 1) * b - (a n * b - a 0) / a (n + 1) ) := by
131+
have :((a (n + 1)) : α) ≠ 0 := ne_of_gt <| a_pos (n + 1) <| Nat.le_succ (n + 1)
132+
simp only [← Nat.cast_add, ← Nat.cast_div ha this, ← Nat.cast_mul, ← Nat.cast_sub ha₀,
133+
← Nat.cast_div han this]
134+
rw [Nat.cast_sub (Nat.div_le_of_le_mul _)]
135+
rw [← mul_assoc, Nat.mul_div_cancel' ha, add_mul]
136+
exact tsub_le_self.trans (Nat.le_add_right _ _)
137+
_ = a (n + 2) / a (n + 1) * b + a 0 * a (n + 2) / (a (n + 1) * a (n + 2)) := by
138+
rw [add_div, add_mul, sub_div, mul_div_right_comm, add_sub_sub_cancel,
139+
mul_div_mul_right _ _ (a_pos _ le_rfl).ne']
140+
_ = ∑ i : ℕ in Finset.range (n + 2), (a 0 : α) * a (n + 2) / (a i * a (i + 1)) := by
141+
rw [Finset.sum_range_succ, hb, Finset.mul_sum]
142+
congr; ext i
143+
rw [← mul_div_assoc, ← mul_div_right_comm, mul_div_assoc,
144+
mul_div_cancel _ (a_pos _ <| Nat.le_succ _).ne', mul_comm]
145+
-- Check the divisibility condition
146+
· rw [mul_tsub, ← mul_assoc, Nat.mul_div_cancel' ha, add_mul, Nat.mul_div_cancel' han,
147+
add_tsub_tsub_cancel ha₀, add_tsub_cancel_right]
148+
exact dvd_mul_right _ _
149+
#align oxford_invariants.week3_p1 OxfordInvariants.Week3P1

0 commit comments

Comments
 (0)