roozbeh-yz commited on
Commit
1c3ffd8
·
verified ·
1 Parent(s): b48a5de

Upload 42 files

Browse files
Files changed (42) hide show
  1. Lemmas/ImoSteps.lean +3 -0
  2. Lemmas/imo_1959_p1_lemmas.lean +34 -0
  3. Lemmas/imo_1960_p2_lemmas.lean +135 -0
  4. Lemmas/imo_1962_p2_lemmas.lean +232 -0
  5. Lemmas/imo_1964_p2_lemmas.lean +183 -0
  6. Lemmas/imo_1965_p2_lemmas.lean +0 -0
  7. Lemmas/imo_1983_p6_lemmas.lean +1180 -0
  8. Lemmas/imo_1984_p6_lemmas.lean +1601 -0
  9. Lemmas/imo_1985_p6_lemmas.lean +0 -0
  10. Lemmas/imo_1992_p1_lemmas.lean +2081 -0
  11. Lemmas/imo_1997_p5_lemmas.lean +2926 -0
  12. Lemmas/imo_2022_p2_lemmas.lean +1606 -0
  13. Lemmas/imo_2022_p5_lemmas.lean +0 -0
  14. Lemmas/imo_2023_p4_lemmas.lean +0 -0
  15. Lemmas/lake-manifest.json +95 -0
  16. Lemmas/lakefile.toml +16 -0
  17. Lemmas/lean-toolchain +1 -0
  18. assets/all_llms.png +3 -0
  19. imo_proofs/ImoSteps.lean +3 -0
  20. imo_proofs/imo_1959_p1.lean +20 -0
  21. imo_proofs/imo_1960_p2.lean +40 -0
  22. imo_proofs/imo_1962_p2.lean +64 -0
  23. imo_proofs/imo_1963_p5.lean +53 -0
  24. imo_proofs/imo_1964_p2.lean +55 -0
  25. imo_proofs/imo_1965_p2.lean +198 -0
  26. imo_proofs/imo_1968_p5_1.lean +37 -0
  27. imo_proofs/imo_1969_p2.lean +157 -0
  28. imo_proofs/imo_1974_p3.lean +514 -0
  29. imo_proofs/imo_1981_p6.lean +44 -0
  30. imo_proofs/imo_1982_p1.lean +78 -0
  31. imo_proofs/imo_1983_p6.lean +181 -0
  32. imo_proofs/imo_1984_p6.lean +436 -0
  33. imo_proofs/imo_1985_p6.lean +1318 -0
  34. imo_proofs/imo_1992_p1.lean +484 -0
  35. imo_proofs/imo_1997_p5.lean +402 -0
  36. imo_proofs/imo_2007_p6.lean +571 -0
  37. imo_proofs/imo_2022_p2.lean +256 -0
  38. imo_proofs/imo_2022_p5.lean +587 -0
  39. imo_proofs/imo_2023_p4.lean +453 -0
  40. imo_proofs/lake-manifest.json +95 -0
  41. imo_proofs/lakefile.toml +16 -0
  42. imo_proofs/lean-toolchain +1 -0
Lemmas/ImoSteps.lean ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ -- This module serves as the root of the `ImoSteps` library.
2
+ -- Import modules here that should be built as part of the library.
3
+ import ImoSteps.Basic
Lemmas/imo_1959_p1_lemmas.lean ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat
5
+
6
+ lemma imo_1959_p1_1
7
+ (n : ℕ) :
8
+ Nat.gcd (21 * n + 4) (14 * n + 3) = Nat.gcd (7 * n + 1) (14 * n + 3) := by
9
+ have g₀: (21 * n + 4) = (7*n + 1) + 1 * (14 * n + 3) := by linarith
10
+ rw [g₀]
11
+ exact gcd_add_mul_right_left (7 * n + 1) (14 * n + 3) 1
12
+
13
+
14
+ lemma imo_1959_p1_2
15
+ (n : ℕ) :
16
+ Nat.gcd (7 * n + 1) (14 * n + 3) = Nat.gcd (7 * n + 1) 1 := by
17
+ have g₁: 14 * n + 3 = (7 * n + 1) * 2 + 1 := by linarith
18
+ rw [g₁]
19
+ exact gcd_mul_left_add_right (7 * n + 1) 1 2
20
+
21
+
22
+ lemma imo_1959_p1_3
23
+ (n : ℕ) :
24
+ Nat.gcd (7 * n + 1) 1 = 1 := by
25
+ exact Nat.gcd_one_right (7 * n + 1)
26
+
27
+
28
+ lemma imo_1959_p1_4
29
+ (n : ℕ)
30
+ (h₁ : Nat.gcd (21 * n + 4) (14 * n + 3) = Nat.gcd (7 * n + 1) (14 * n + 3))
31
+ (h₂ : Nat.gcd (7 * n + 1) (14 * n + 3) = Nat.gcd (7 * n + 1) 1)
32
+ (h₃ : Nat.gcd (7 * n + 1) 1 = 1) :
33
+ Nat.gcd (21 * n + 4) (14 * n + 3) = 1 := by
34
+ rw [← h₃, ← h₂, ← h₁]
Lemmas/imo_1960_p2_lemmas.lean ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real
5
+
6
+ theorem imo_1960_p2_1
7
+ (x : ℝ)
8
+ (h₀ : 0 ≤ 1 + 2 * x)
9
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
10
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9)
11
+ (h₃ : 7 * x ≤ -(7/4)) :
12
+ x ^ 3 + x ^ 2 * (2 / 5) ≤ (15/400) ∧ x / 16 + 3 / 160 ≤ (5/100) * x ^ 2 := by
13
+ have h₄: -(1/2) ≤ x := by linarith
14
+ have h₅: x ≤ -(1/4) := by linarith
15
+ have h₆: x ^ 2 ≤ (-(1 / 2)) ^ 2 := by
16
+ refine sq_le_sq.mpr ?_
17
+ norm_num
18
+ have h₆₁: x < 0 := by linarith
19
+ rw [abs_of_neg h₆₁]
20
+ rw [abs_of_pos (by norm_num)]
21
+ exact neg_le.mp h₄
22
+ have h₇: (-(1 / 4)) ^ 2 ≤ x ^ 2 := by
23
+ refine sq_le_sq.mpr ?_
24
+ have h₆₁: x < 0 := by linarith
25
+ rw [abs_of_neg h₆₁]
26
+ rw [abs_of_neg (by norm_num)]
27
+ norm_num
28
+ exact le_neg_of_le_neg h₅
29
+ norm_num at h₆ h₇
30
+ constructor
31
+ . have h₈: x + (4/10) ≤ (15/100) := by linarith
32
+ have h₉: (x + (4/10)) * x ^ 2 ≤ (15/100) * (1 / 4) := by
33
+ refine mul_le_mul h₈ h₆ ?_ ?_
34
+ . exact sq_nonneg x
35
+ . norm_num
36
+ linarith
37
+ . linarith
38
+
39
+
40
+ theorem imo_1960_p2_2
41
+ (x : ℝ)
42
+ -- (h₀ : 0 ≤ 1 + 2 * x)
43
+ (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
44
+ (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9) :
45
+ 4 * x ^ 2 < (2 * x + 9) * (1 - √(1 + 2 * x)) ^ 2 := by
46
+ refine' (div_lt_iff₀ ?_).mp h₂
47
+ refine Ne.lt_of_le (id (Ne.symm h₁)) ?_
48
+ exact sq_nonneg (1 - sqrt (1 + 2 * x))
49
+
50
+ theorem imo_1960_p2_3
51
+ (x : ℝ)
52
+ (h₀ : 0 ≤ 1 + 2 * x) :
53
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
54
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9) :
55
+ (1 - sqrt (1 + 2 * x)) ^ 2 = (2 + 2 * x) - 2 * sqrt (1 + 2 * x) := by
56
+ ring_nf
57
+ ring_nf at h₀
58
+ rw [Real.sq_sqrt h₀]
59
+ ring_nf
60
+
61
+ theorem imo_1960_p2_4
62
+ (x : ℝ)
63
+ (h₀ : 0 ≤ 1 + 2 * x)
64
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
65
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9)
66
+ (h₃: 4 * x ^ 2 < (2 * x + 9) * (1 - sqrt (1 + 2 * x) ) ^ 2)
67
+ (h₄: (1 - sqrt (1 + 2 * x)) ^ 2 = (2 + 2 * x) - 2 * sqrt (1 + 2 * x)) :
68
+ (2 * x + 9) ^ 2 * (sqrt (1 + 2 * x)) ^ 2 < (11 * x + 9) ^ 2 := by
69
+ rw [← mul_pow]
70
+ refine' pow_lt_pow_left₀ ?_ ?_ (by norm_num)
71
+ . rw [h₄] at h₃
72
+ linarith
73
+ . refine' mul_nonneg ?_ ?_
74
+ . linarith
75
+ . exact sqrt_nonneg (1 + 2 * x)
76
+
77
+
78
+ theorem imo_1960_p2_5
79
+ (x : ℝ)
80
+ (h₀ : 0 ≤ 1 + 2 * x)
81
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
82
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9)
83
+ (h₃: (2 * x + 9) ^ 2 * (sqrt (1 + 2 * x)) ^ 2 < (11 * x + 9) ^ 2) :
84
+ 8 * x^3 < 45 * x^2 := by
85
+ rw [Real.sq_sqrt h₀] at h₃
86
+ ring_nf at h₃
87
+ linarith
88
+
89
+
90
+ theorem imo_1960_p2_6
91
+ (x : ℝ)
92
+ -- (h₀ : 0 ≤ 1 + 2 * x)
93
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
94
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9)
95
+ (h₃: x^3 * 8 < x^2 * 45) :
96
+ x < 45/8 := by
97
+ have h₇₁: 0 ≤ x^2 := by exact sq_nonneg x
98
+ refine (lt_div_iff₀ (by norm_num)).mpr ?_
99
+ refine' lt_of_mul_lt_mul_right ?_ h₇₁
100
+ ring_nf
101
+ exact h₃
102
+
103
+
104
+ theorem imo_1960_p2_7
105
+ (x : ℝ)
106
+ (h₀ : 0 ≤ 1 + 2 * x)
107
+ (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
108
+ (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9) :
109
+ 0 < x ^ 2 ∨ x ^ 2 = 0 := by
110
+ have h₄: 0 ≤ x ^ 2 := by
111
+ exact sq_nonneg x
112
+ exact LE.le.gt_or_eq h₄
113
+
114
+
115
+ theorem imo_1960_p2_8
116
+ (x : ℝ)
117
+ -- (h₀ : 0 ≤ 1 + 2 * x)
118
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
119
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9)
120
+ (h₃: 4 * x ^ 2 < (2 * x + 9) * (1 - sqrt (1 + 2 * x) ) ^ 2)
121
+ (h₄: (1 - sqrt (1 + 2 * x)) ^ 2 = (2 + 2 * x) - 2 * sqrt (1 + 2 * x)) :
122
+ (2 * x + 9) * √(1 + 2 * x) < 11 * x + 9 := by
123
+ rw [h₄] at h₃
124
+ linarith
125
+
126
+
127
+ theorem imo_1960_p2_9
128
+ (x : ℝ)
129
+ (h₀ : 0 ≤ 1 + 2 * x) :
130
+ -- (h₁ : (1 - Real.sqrt (1 + 2 * x)) ^ 2 ≠ 0)
131
+ -- (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9) :
132
+ 0 ≤ (2 * x + 9) * √(1 + 2 * x) := by
133
+ refine' mul_nonneg ?_ ?_
134
+ . linarith
135
+ . exact sqrt_nonneg (1 + 2 * x)
Lemmas/imo_1962_p2_lemmas.lean ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+
5
+ open Real
6
+
7
+
8
+
9
+ theorem imo_1962_p2_1
10
+ (x : ℝ)
11
+ -- (h₀ : 0 ≤ 3 - x)
12
+ -- (h₁ : 0 ≤ x + 1)
13
+ (h₂ : 1 / 2 < Real.sqrt (x - 3) - Real.sqrt (x + 1)) :
14
+ -1 ≤ x := by
15
+ refine neg_le_iff_add_nonneg.mpr ?_
16
+ contrapose! h₂
17
+ have h₃: x - 3 < 0 := by linarith [h₂]
18
+ have h₄: Real.sqrt (x + 1) = 0 := by
19
+ refine Real.sqrt_eq_zero'.mpr ?_
20
+ exact le_of_lt h₂
21
+ have h₅: Real.sqrt (x -3) = 0 := by
22
+ refine Real.sqrt_eq_zero'.mpr ?_
23
+ exact le_of_lt h₃
24
+ rw [h₄, h₅, sub_zero]
25
+ refine div_nonneg ?_ ?_
26
+ all_goals try linarith
27
+
28
+
29
+ theorem imo_1962_p2_2
30
+ (x : ℝ)
31
+ (h₀ : 0 ≤ 3 - x)
32
+ (h₁ : 0 ≤ x + 1)
33
+ (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
34
+ (2 * √(3 - x) * √(x + 1)) ^ 2 < (4 - 1 / 4) ^ 2 := by
35
+ refine' pow_lt_pow_left₀ _ _ (by norm_num)
36
+ . refine lt_tsub_iff_left.mpr ?_
37
+ refine lt_tsub_iff_right.mp ?_
38
+ suffices g₀: 4 - 2 * sqrt (3 - x) * sqrt (x + 1) = (sqrt (3 - x) - sqrt (x + 1)) ^ 2
39
+ . rw [g₀]
40
+ have g₁: (1:ℝ) / 4 = (1/2)^2 := by norm_num
41
+ rw [g₁]
42
+ exact pow_lt_pow_left₀ h₂ (by norm_num) (by norm_num)
43
+ rw [sub_sq]
44
+ rw [sq_sqrt h₀, sq_sqrt h₁]
45
+ ring_nf
46
+ . refine' mul_nonneg _ _
47
+ . refine mul_nonneg (by linarith) ?_
48
+ exact sqrt_nonneg (3 - x)
49
+ . exact sqrt_nonneg (x + 1)
50
+
51
+
52
+ theorem imo_1962_p2_3
53
+ (x : ℝ)
54
+ (h₀ : 0 ≤ 3 - x)
55
+ (h₁ : 0 ≤ x + 1)
56
+ (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
57
+ 2 * √(3 - x) * √(x + 1) < 4 - 1 / 4 := by
58
+ refine lt_tsub_iff_left.mpr ?refine'_1.a
59
+ refine lt_tsub_iff_right.mp ?refine'_1.a.a
60
+ suffices g₀: 4 - 2 * sqrt (3 - x) * sqrt (x + 1) = (sqrt (3 - x) - sqrt (x + 1)) ^ 2
61
+ . rw [g₀]
62
+ have g₁: (1:ℝ) / 4 = (1/2)^2 := by norm_num
63
+ rw [g₁]
64
+ exact pow_lt_pow_left₀ h₂ (by norm_num) (by norm_num)
65
+ rw [sub_sq]
66
+ rw [sq_sqrt h₀, sq_sqrt h₁]
67
+ ring_nf
68
+
69
+
70
+ theorem imo_1962_p2_4
71
+ (x : ℝ) :
72
+ -- (h₀ : 0 ≤ 3 - x)
73
+ -- (h₁ : 0 ≤ x + 1)
74
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
75
+ 0 ≤ 2 * √(3 - x) * √(x + 1) := by
76
+ refine' mul_nonneg ?_ ?_
77
+ . refine mul_nonneg (by linarith) ?_
78
+ exact sqrt_nonneg (3 - x)
79
+ . exact sqrt_nonneg (x + 1)
80
+
81
+
82
+
83
+ theorem imo_1962_p2_5
84
+ (x : ℝ)
85
+ (h₀ : 0 ≤ 3 - x)
86
+ (h₁ : 0 ≤ x + 1) :
87
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
88
+ 4 - 2 * √(3 - x) * √(x + 1) = (√(3 - x) - √(x + 1)) ^ 2 := by
89
+ rw [sub_sq]
90
+ rw [sq_sqrt h₀, sq_sqrt h₁]
91
+ ring_nf
92
+
93
+
94
+ theorem imo_1962_p2_6
95
+ (x : ℝ)
96
+ -- (h₀ : 0 ≤ 3 - x)
97
+ -- (h₁ : 0 ≤ x + 1)
98
+ (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
99
+ (h₃: 4 - 2 * √(3 - x) * √(x + 1) = (√(3 - x) - √(x + 1)) ^ 2) :
100
+ 1 / 4 < 4 - 2 * √(3 - x) * √(x + 1) := by
101
+ rw [h₃]
102
+ have g₁: (1:ℝ) / 4 = (1/2) ^ 2 := by norm_num
103
+ rw [g₁]
104
+ exact pow_lt_pow_left₀ h₂ (by norm_num) (by norm_num)
105
+
106
+
107
+ theorem imo_1962_p2_7
108
+ (x : ℝ)
109
+ (h₀ : 0 ≤ 3 - x)
110
+ (h₁ : 0 ≤ x + 1)
111
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
112
+ (h₃: (2 *sqrt (3 - x) * sqrt (x + 1)) ^ 2 < (4 - 1 / 4) ^ 2) :
113
+ 4 * (x + 1) * (3 - x) < 225 / 16 := by
114
+ norm_num at h₃
115
+ suffices g₀: 4 * (x + 1) * (3 - x) = (2 * sqrt (3 - x) * sqrt (x + 1)) ^ 2
116
+ . exact Eq.trans_lt g₀ h₃
117
+ . rw [mul_pow, mul_pow, sq_sqrt h₀, sq_sqrt h₁]
118
+ norm_num
119
+ exact mul_right_comm 4 (x + 1) (3 - x)
120
+
121
+
122
+ theorem imo_1962_p2_8
123
+ (x : ℝ)
124
+ (h₀ : 0 ≤ 3 - x)
125
+ (h₁ : 0 ≤ x + 1)
126
+ (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
127
+ x < 1 := by
128
+ suffices g₀: x + 1 < 3 - x
129
+ . linarith
130
+ . rw [← sq_sqrt h₀, ← sq_sqrt h₁]
131
+ refine' pow_lt_pow_left₀ ?_ ?_ (by norm_num)
132
+ . linarith
133
+ . exact sqrt_nonneg (x + 1)
134
+
135
+
136
+ theorem imo_1962_p2_9
137
+ (x : ℝ)
138
+ -- (h₀ : 0 ≤ 3 - x)
139
+ -- (h₁ : 0 ≤ x + 1)
140
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
141
+ (h₄: 4 * (x + 1) * (3 - x) < 225 / 16) :
142
+ x < 1 - sqrt 31 / 8 ∨ 1 + sqrt 31 / 8 < x := by
143
+ ring_nf at h₄
144
+ have g₀: 0 < x * x + -2 * x + 33 / 64 := by linarith
145
+ let a:ℝ := sqrt 31 / 8
146
+ have g₁: x * x + -2 * x + 33 / 64 = (x - (1 + a)) * (x - (1 - a)) := by
147
+ simp
148
+ ring_nf
149
+ norm_num
150
+ linarith
151
+ rw [g₁] at g₀
152
+ by_cases g₂: (x - (1 - a)) < 0
153
+ . left
154
+ exact sub_neg.mp g₂
155
+ . push_neg at g₂
156
+ right
157
+ have g₃: 0 < (x - (1 + a)) := by exact pos_of_mul_pos_left g₀ g₂
158
+ exact sub_pos.mp g₃
159
+
160
+
161
+ theorem imo_1962_p2_10
162
+ (x : ℝ)
163
+ -- (h₀ : 0 ≤ 3 - x)
164
+ -- (h₁ : 0 ≤ x + 1)
165
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
166
+ (h₄: x < 1)
167
+ (h₅: x < 1 - sqrt 31 / 8 ∨ 1 + sqrt 31 / 8 < x) :
168
+ x < 1 - Real.sqrt 31 / 8 := by
169
+ cases h₅ with
170
+ | inl h₅ => exact h₅
171
+ | inr h₅ => linarith
172
+
173
+
174
+ theorem imo_1962_p2_11
175
+ (x a : ℝ)
176
+ (ha: a = √31 / 8)
177
+ -- (h₀ : 0 ≤ 3 - x)
178
+ -- (h₁ : 0 ≤ x + 1)
179
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
180
+ (h₃: 0 < (x - (1 + a)) * (x - (1 - a))) :
181
+ x < 1 - √31 / 8 ∨ 1 + √31 / 8 < x := by
182
+ by_cases g₂: (x - (1 - a)) < 0
183
+ . left
184
+ rw [ha] at g₂
185
+ exact sub_neg.mp g₂
186
+ . push_neg at g₂
187
+ right
188
+ have g₃: 0 < (x - (1 + a)) := by exact pos_of_mul_pos_left h₃ g₂
189
+ rw [ha] at g₃
190
+ exact sub_pos.mp g₃
191
+
192
+
193
+ theorem imo_1962_p2_12
194
+ (x a : ℝ)
195
+ (ha: a = 0.5)
196
+ -- (h₀ : 0 ≤ 3 - x)
197
+ -- (h₁ : 0 ≤ x + 1)
198
+ -- (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1))
199
+ (h₃: 0 < (x - (1 + a)) * (x - (1 - a))) :
200
+ x < 1 - 0.5 ∨ 1 + 0.5 < x := by
201
+ by_cases g₂: (x - (1 - a)) < 0
202
+ . left
203
+ rw [ha] at g₂
204
+ exact sub_neg.mp g₂
205
+ . push_neg at g₂
206
+ right
207
+ have g₃: 0 < (x - (1 + a)) := by exact pos_of_mul_pos_left h₃ g₂
208
+ rw [ha] at g₃
209
+ exact sub_pos.mp g₃
210
+
211
+
212
+ theorem imo_1962_p2_13
213
+ (x a : ℝ)
214
+ (ha: a = √31 / 8) :
215
+ -- h₀ : 0 ≤ 3 - x
216
+ -- h₁ : 0 ≤ x + 1
217
+ -- h₄ : 12 + (x * 8 - x ^ 2 * 4) < 225 / 16
218
+ -- g₀ : 0 < x * x + -2 * x + 33 / 64
219
+ x ^ 2 - 2 * x + 33 / 64 = (x - (1 + a)) * (x - (1 - a)) := by
220
+ rw [ha]
221
+ ring_nf
222
+ norm_num
223
+ linarith
224
+
225
+ theorem imo_1962_p2_14
226
+ (x : ℝ)
227
+ -- (h₀ : 0 ≤ 3 - x)
228
+ -- (h₁ : 0 ≤ x + 1)
229
+ (h₄ : 12 + (x * 8 - x ^ 2 * 4) < 225 / 16) :
230
+ 0 < x * x + -2 * x + 33 / 64 := by
231
+ ring_nf at h₄
232
+ linarith
Lemmas/imo_1964_p2_lemmas.lean ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real
5
+
6
+ lemma imo_1964_p2_1
7
+ (a b c : ℝ)
8
+ (ha : 0 < -a + b + c)
9
+ (hb : 0 < a - b + c)
10
+ (hc : 0 < a + b - c)
11
+ (g1 : (a + b - c) * (a - b + c) * (-a + b + c) ≤ a * b * c) :
12
+ ((a + b - c) * (a - b + c) * (-a + b + c)) ^ 2 ≤ (a * b * c) ^ 2 := by
13
+ refine pow_le_pow_left₀ (le_of_lt ?_) g1 2
14
+ exact mul_pos (mul_pos hc hb) ha
15
+
16
+ lemma imo_1964_p2_2
17
+ (a b c : ℝ) :
18
+ (a + b - c) * (a + c - b) ≤ a ^ 2 := by
19
+ have h₁: (a + b - c) * (a + c - b) = a ^ 2 - (b - c) ^ 2 := by
20
+ linarith
21
+ rw [h₁]
22
+ refine sub_le_self _ ?_
23
+ exact sq_nonneg (b - c)
24
+
25
+
26
+ lemma imo_1964_p2_3
27
+ (a b c : ℝ) :
28
+ a ^ 2 - (b - c) ^ 2 ≤ a ^ 2 := by
29
+ simp
30
+ exact sq_nonneg (b - c)
31
+
32
+
33
+ lemma imo_1964_p2_4
34
+ (a b c : ℝ)
35
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
36
+ (h₁ : c < a + b)
37
+ (h₂ : b < a + c)
38
+ (h₃ : a < b + c) :
39
+ ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ (a * b * c) ^ 2 := by
40
+ have ha : 0 < b + c - a := by exact sub_pos.mpr h₃
41
+ have hb : 0 < a + c - b := by exact sub_pos.mpr h₂
42
+ have hc : 0 < a + b - c := by exact sub_pos.mpr h₁
43
+ have h₄₁: (a + b - c) * (a + c - b) ≤ a ^ 2 := by
44
+ exact imo_1964_p2_2 a b c
45
+ have h₄₂: (a + b - c) * (b + c - a) ≤ b ^ 2 := by
46
+ rw [add_comm a b]
47
+ exact imo_1964_p2_2 b a c
48
+ have h₄₃: (a + c - b) * (b + c - a) ≤ c ^ 2 := by
49
+ rw [add_comm a c, add_comm b c]
50
+ exact imo_1964_p2_2 c a b
51
+ have h₄₄: ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 = ((a + b - c) * (a + c - b)) *
52
+ ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a)) := by
53
+ linarith
54
+ rw [h₄₄]
55
+ repeat rw [mul_pow]
56
+ refine mul_le_mul ?_ h₄₃ ?_ ?_
57
+ . refine mul_le_mul h₄₁ h₄₂ ?_ ?_
58
+ . refine le_of_lt ?_
59
+ exact mul_pos hc ha
60
+ . exact sq_nonneg a
61
+ . refine le_of_lt ?_
62
+ exact mul_pos hb ha
63
+ . refine le_of_lt ?_
64
+ simp_all only [sub_pos, gt_iff_lt, pow_pos, mul_pos_iff_of_pos_left]
65
+
66
+
67
+ lemma imo_1964_p2_5
68
+ (a b c : ℝ)
69
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
70
+ -- (h₁ : c < a + b)
71
+ -- (h₂ : b < a + c)
72
+ -- (h₃ : a < b + c)
73
+ (ha : 0 < b + c - a)
74
+ (hb : 0 < a + c - b)
75
+ (hc : 0 < a + b - c)
76
+ (h₄₁ : (a + b - c) * (a + c - b) ≤ a ^ 2)
77
+ (h₄₂ : (a + b - c) * (b + c - a) ≤ b ^ 2)
78
+ (h₄₃ : (a + c - b) * (b + c - a) ≤ c ^ 2) :
79
+ ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ (a * b * c) ^ 2 := by
80
+ repeat rw [mul_pow]
81
+ rw [pow_two, pow_two, pow_two]
82
+ have h₅: ((a + b - c) * (a + c - b)) * ((a + b - c) * (b + c - a)) ≤ a ^ 2 * b ^ 2 := by
83
+ refine mul_le_mul h₄₁ h₄₂ ?_ ?_
84
+ . refine le_of_lt ?_
85
+ exact mul_pos hc ha
86
+ . exact sq_nonneg a
87
+ have h₆: ((a + b - c) * (a + c - b)) * ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a))
88
+ ≤ a ^ 2 * b ^ 2 * c ^ 2 := by
89
+ refine mul_le_mul h₅ h₄₃ ?_ ?_
90
+ . refine le_of_lt ?_
91
+ exact mul_pos hb ha
92
+ . refine mul_nonneg ?_ ?_
93
+ . exact sq_nonneg a
94
+ . exact sq_nonneg b
95
+ linarith
96
+
97
+
98
+ lemma imo_1964_p2_6
99
+ (a b c : ℝ)
100
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
101
+ -- h₁ : c < a + b
102
+ -- h₂ : b < a + c
103
+ -- h₃ : a < b + c
104
+ (ha : 0 < b + c - a)
105
+ (hb : 0 < a + c - b)
106
+ (hc : 0 < a + b - c)
107
+ (h₄₁ : (a + b - c) * (a + c - b) ≤ a ^ 2)
108
+ (h₄₂ : (a + b - c) * (b + c - a) ≤ b ^ 2)
109
+ (h₄₃ : (a + c - b) * (b + c - a) ≤ c ^ 2)
110
+ (h₄₄ : ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 =
111
+ (a + b - c) * (a + c - b) * ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a))) :
112
+ ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ a ^ 2 * b ^ 2 * c ^ 2 := by
113
+ rw [h₄₄]
114
+ have h₅: ((a + b - c) * (a + c - b)) * ((a + b - c) * (b + c - a)) ≤ a ^ 2 * b ^ 2 := by
115
+ refine mul_le_mul h₄₁ h₄₂ ?_ ?_
116
+ . refine le_of_lt ?_
117
+ exact mul_pos hc ha
118
+ . exact sq_nonneg a
119
+ have h₆: ((a + b - c) * (a + c - b)) * ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a))
120
+ ≤ a ^ 2 * b ^ 2 * c ^ 2 := by
121
+ refine mul_le_mul h₅ h₄₃ ?_ ?_
122
+ . refine le_of_lt ?_
123
+ exact mul_pos hb ha
124
+ . refine mul_nonneg ?_ ?_
125
+ . exact sq_nonneg a
126
+ . exact sq_nonneg b
127
+ linarith
128
+
129
+
130
+ lemma imo_1964_p2_7
131
+ (a b c : ℝ)
132
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
133
+ -- (h₁ : c < a + b)
134
+ -- (h₂ : b < a + c)
135
+ -- (h₃ : a < b + c)
136
+ (ha : 0 < b + c - a)
137
+ -- (hb : 0 < a + c - b)
138
+ (hc : 0 < a + b - c)
139
+ (h₄₁ : (a + b - c) * (a + c - b) ≤ a ^ 2)
140
+ (h₄₂ : (a + b - c) * (b + c - a) ≤ b ^ 2) :
141
+ -- (h₄₃ : (a + c - b) * (b + c - a) ≤ c ^ 2)
142
+ -- (h₄₄ : ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 =
143
+ -- (a + b - c) * (a + c - b) * ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a))) :
144
+ (a + b - c) * (a + c - b) * ((a + b - c) * (b + c - a)) ≤ a ^ 2 * b ^ 2 := by
145
+ refine mul_le_mul h₄₁ h₄₂ ?_ ?_
146
+ . refine le_of_lt ?_
147
+ exact mul_pos hc ha
148
+ . exact sq_nonneg a
149
+
150
+
151
+ lemma imo_1964_p2_8
152
+ (a b c : ℝ)
153
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
154
+ -- (h₁ : c < a + b)
155
+ -- (h₂ : b < a + c)
156
+ -- (h₃ : a < b + c)
157
+ -- (ha : 0 < b + c - a)
158
+ -- (hb : 0 < a + c - b)
159
+ -- (hc : 0 < a + b - c)
160
+ (h₄ : ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ (a * b * c) ^ 2) :
161
+ (a + b - c) * (a + c - b) * (b + c - a) ≤ a * b * c := by
162
+ refine le_of_pow_le_pow_left₀ ?_ ?_ h₄
163
+ . norm_num
164
+ . refine le_of_lt ?_
165
+ refine mul_pos ?_ h₀.2.2
166
+ exact mul_pos h₀.1 h₀.2.1
167
+
168
+
169
+ lemma imo_1964_p2_9
170
+ (a b c : ℝ)
171
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
172
+ -- (h₁ : c < a + b)
173
+ -- (h₂ : b < a + c)
174
+ -- (h₃ : a < b + c)
175
+ -- (ha : 0 < b + c - a)
176
+ -- (hb : 0 < a + c - b)
177
+ -- (hc : 0 < a + b - c)
178
+ -- (h₄ : ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ (a * b * c) ^ 2)
179
+ (h₅ : (a + b - c) * (a + c - b) * (b + c - a) ≤ a * b * c) :
180
+ a ^ 2 * (b + c - a) + b ^ 2 * (c + a - b) + c ^ 2 * (a + b - c) ≤ 3 * a * b * c := by
181
+ repeat rw [mul_sub]
182
+ repeat rw [mul_add]
183
+ linarith
Lemmas/imo_1965_p2_lemmas.lean ADDED
The diff for this file is too large to render. See raw diff
 
Lemmas/imo_1983_p6_lemmas.lean ADDED
@@ -0,0 +1,1180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ set_option linter.unusedVariables.analyzeTactics true
4
+
5
+
6
+ lemma imo_1983_p6_1
7
+ (a b c : ℝ)
8
+ (x y z : ℝ)
9
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
10
+ (h₂: c ≤ b ∧ b ≤ a)
11
+ (h₃: z ≤ y ∧ y ≤ x) :
12
+ a * z + c * y + b * x ≤ c * z + b * y + a * x := by
13
+ suffices h₄: c * (y - z) + b * (x - y) ≤ a * (x - z)
14
+ . linarith
15
+ . have h₅: c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y) := by
16
+ simp
17
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
18
+ . exact le_rfl
19
+ . exact sub_nonneg_of_le h₃.1
20
+ . exact le_of_lt h₀.2.1
21
+ refine le_trans h₅ ?_
22
+ rw [mul_sub, mul_sub, add_comm]
23
+ rw [← add_sub_assoc, sub_add_cancel]
24
+ rw [← mul_sub]
25
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
26
+ . exact le_rfl
27
+ . refine sub_nonneg_of_le ?_
28
+ exact le_trans h₃.1 h₃.2
29
+ . exact le_of_lt h₀.1
30
+
31
+
32
+
33
+ lemma imo_1983_p6_1_1
34
+ (a b c x y z : ℝ)
35
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
36
+ (h₂ : c ≤ b ∧ b ≤ a)
37
+ (h₃ : z ≤ y ∧ y ≤ x) :
38
+ c * (y - z) + b * (x - y) ≤ a * (x - z) := by
39
+ have h₅: c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y) := by
40
+ simp
41
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
42
+ . exact le_rfl
43
+ . exact sub_nonneg_of_le h₃.1
44
+ . exact le_of_lt h₀.2.1
45
+ refine le_trans h₅ ?_
46
+ rw [mul_sub, mul_sub, add_comm]
47
+ rw [← add_sub_assoc, sub_add_cancel]
48
+ rw [← mul_sub]
49
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
50
+ . exact le_rfl
51
+ . refine sub_nonneg_of_le ?_
52
+ exact le_trans h₃.1 h₃.2
53
+ . exact le_of_lt h₀.1
54
+
55
+
56
+ lemma imo_1983_p6_1_2
57
+ (a b c x y z : ℝ)
58
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
59
+ (h₂ : c ≤ b ∧ b ≤ a)
60
+ (h₃ : z ≤ y ∧ y ≤ x) :
61
+ c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y) := by
62
+ simp
63
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
64
+ . exact le_rfl
65
+ . exact sub_nonneg_of_le h₃.1
66
+ . exact le_of_lt h₀.2.1
67
+
68
+
69
+ lemma imo_1983_p6_1_3
70
+ (a b c x y z : ℝ)
71
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
72
+ (h₂ : c ≤ b ∧ b ≤ a)
73
+ (h₃ : z ≤ y ∧ y ≤ x)
74
+ (h₅ : c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y)) :
75
+ c * (y - z) + b * (x - y) ≤ a * (x - z) := by
76
+ refine le_trans h₅ ?_
77
+ rw [mul_sub, mul_sub, add_comm]
78
+ rw [← add_sub_assoc, sub_add_cancel]
79
+ rw [← mul_sub]
80
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
81
+ . exact le_rfl
82
+ . refine sub_nonneg_of_le ?_
83
+ exact le_trans h₃.1 h₃.2
84
+ . exact le_of_lt h₀.1
85
+
86
+
87
+ lemma imo_1983_p6_1_4
88
+ (a b c x y z : ℝ)
89
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
90
+ (h₂ : c ≤ b ∧ b ≤ a)
91
+ (h₃ : z ≤ y ∧ y ≤ x) :
92
+ -- (h₅ : c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y)) :
93
+ b * (y - z) + b * (x - y) ≤ a * (x - z) := by
94
+ rw [mul_sub, mul_sub, add_comm]
95
+ rw [← add_sub_assoc, sub_add_cancel]
96
+ rw [← mul_sub]
97
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
98
+ . exact le_rfl
99
+ . refine sub_nonneg_of_le ?_
100
+ exact le_trans h₃.1 h₃.2
101
+ . exact le_of_lt h₀.1
102
+
103
+
104
+ lemma imo_1983_p6_1_5
105
+ (a b c x y z : ℝ)
106
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
107
+ (h₂ : c ≤ b ∧ b ≤ a)
108
+ (h₃ : z ≤ y ∧ y ≤ x) :
109
+ -- (h₅ : c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y)) :
110
+ b * (x - z) ≤ a * (x - z) := by
111
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
112
+ . exact le_rfl
113
+ . refine sub_nonneg_of_le ?_
114
+ exact le_trans h₃.1 h₃.2
115
+ . exact le_of_lt h₀.1
116
+
117
+
118
+
119
+
120
+ lemma imo_1983_p6_2
121
+ (a b c : ℝ)
122
+ (x y z : ℝ)
123
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
124
+ (h₂: c ≤ b ∧ b ≤ a)
125
+ (h₃: z ≤ y ∧ y ≤ x) :
126
+ b * z + a * y + c * x ≤ c * z + b * y + a * x := by
127
+ suffices h₄: c * (x - z) + b * (z - y) ≤ a * (x - y)
128
+ . linarith
129
+ . have h₅: c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y) := by
130
+ simp
131
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
132
+ . exact le_rfl
133
+ . refine sub_nonneg_of_le ?_
134
+ exact le_trans h₃.1 h₃.2
135
+ . exact le_of_lt h₀.2.1
136
+ refine le_trans h₅ ?_
137
+ rw [mul_sub, mul_sub]
138
+ rw [← add_sub_assoc, sub_add_cancel]
139
+ rw [← mul_sub]
140
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
141
+ . exact le_rfl
142
+ . exact sub_nonneg_of_le h₃.2
143
+ . exact le_of_lt h₀.1
144
+
145
+
146
+ lemma imo_1983_p6_2_1
147
+ (a b c x y z : ℝ)
148
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
149
+ (h₂ : c ≤ b ∧ b ≤ a)
150
+ (h₃ : z ≤ y ∧ y ≤ x) :
151
+ c * (x - z) + b * (z - y) ≤ a * (x - y) := by
152
+ have h₅: c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y) := by
153
+ simp
154
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
155
+ . exact le_rfl
156
+ . refine sub_nonneg_of_le ?_
157
+ exact le_trans h₃.1 h₃.2
158
+ . exact le_of_lt h₀.2.1
159
+ refine le_trans h₅ ?_
160
+ rw [mul_sub, mul_sub]
161
+ rw [← add_sub_assoc, sub_add_cancel]
162
+ rw [← mul_sub]
163
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
164
+ . exact le_rfl
165
+ . exact sub_nonneg_of_le h₃.2
166
+ . exact le_of_lt h₀.1
167
+
168
+
169
+ lemma imo_1983_p6_2_2
170
+ (a b c x y z : ℝ)
171
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
172
+ (h₂ : c ≤ b ∧ b ≤ a)
173
+ (h₃ : z ≤ y ∧ y ≤ x) :
174
+ c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y) := by
175
+ simp
176
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
177
+ . exact le_rfl
178
+ . refine sub_nonneg_of_le ?_
179
+ exact le_trans h₃.1 h₃.2
180
+ . exact le_of_lt h₀.2.1
181
+
182
+
183
+ lemma imo_1983_p6_2_3
184
+ (a b c x y z : ℝ)
185
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
186
+ (h₂ : c ≤ b ∧ b ≤ a)
187
+ (h₃ : z ≤ y ∧ y ≤ x) :
188
+ c * (x - z) ≤ b * (x - z) := by
189
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
190
+ . exact le_rfl
191
+ . refine sub_nonneg_of_le ?_
192
+ exact le_trans h₃.1 h₃.2
193
+ . exact le_of_lt h₀.2.1
194
+
195
+
196
+ lemma imo_1983_p6_2_4
197
+ -- (a b c : ℝ)
198
+ (x y z : ℝ)
199
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
200
+ -- (h₂ : c ≤ b ∧ b ≤ a)
201
+ (h₃ : z ≤ y ∧ y ≤ x) :
202
+ 0 ≤ x - z := by
203
+ refine sub_nonneg_of_le ?_
204
+ exact le_trans h₃.1 h₃.2
205
+
206
+
207
+ lemma imo_1983_p6_2_5
208
+ (a b c x y z : ℝ)
209
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
210
+ (h₂ : c ≤ b ∧ b ≤ a)
211
+ (h₃ : z ≤ y ∧ y ≤ x) :
212
+ -- (h₅ : c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y)) :
213
+ b * (x - z) + b * (z - y) ≤ a * (x - y) := by
214
+ rw [mul_sub, mul_sub]
215
+ rw [← add_sub_assoc, sub_add_cancel]
216
+ rw [← mul_sub]
217
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
218
+ . exact le_rfl
219
+ . exact sub_nonneg_of_le h₃.2
220
+ . exact le_of_lt h₀.1
221
+
222
+
223
+ lemma imo_1983_p6_2_6
224
+ (a b c x y z : ℝ)
225
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
226
+ (h₂ : c ≤ b ∧ b ≤ a)
227
+ (h₃ : z ≤ y ∧ y ≤ x) :
228
+ -- (h₅ : c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y)) :
229
+ b * (x - y) ≤ a * (x - y) := by
230
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
231
+ . exact le_rfl
232
+ . exact sub_nonneg_of_le h₃.2
233
+ . exact le_of_lt h₀.1
234
+
235
+
236
+
237
+ lemma imo_1983_p6_3
238
+ (a b c : ℝ)
239
+ (hap : 0 < a )
240
+ (hbp : 0 < b )
241
+ (hcp : 0 < c )
242
+ (h₁ : c < a + b)
243
+ -- (h₂ : b < a + c)
244
+ (h₃ : a < b + c)
245
+ (hba: b ≤ a)
246
+ (hcb: c ≤ b) :
247
+ 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a) := by
248
+ have g₀: b * c ≤ a * c := by exact (mul_le_mul_iff_of_pos_right hcp).mpr hba
249
+ have g₁: a * c ≤ a * b := by exact (mul_le_mul_iff_of_pos_left hap).mpr hcb
250
+ have g₂: a * (b + c - a) ≤ b * (a + c - b) := by
251
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
252
+ refine mul_nonneg ?_ ?_
253
+ . exact sub_nonneg_of_le hba
254
+ . refine le_of_lt ?_
255
+ exact sub_pos.mpr h₁
256
+ linarith
257
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
258
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
259
+ refine mul_nonneg ?_ ?_
260
+ . exact sub_nonneg_of_le hcb
261
+ . refine le_of_lt ?_
262
+ exact sub_pos.mpr h₃
263
+ linarith
264
+ have g₄: (a * b) * (a * (b + c - a)) + (b * c) * (b * (a + c - b)) + (a * c) * (c * (a + b - c))
265
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
266
+ refine imo_1983_p6_1 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
267
+ . constructor
268
+ . exact mul_pos hap hbp
269
+ . constructor
270
+ . exact mul_pos hap hcp
271
+ . exact mul_pos hbp hcp
272
+ . exact { left := g₀, right := g₁ }
273
+ . exact { left := g₂, right := g₃ }
274
+ linarith
275
+
276
+
277
+ lemma imo_1983_p6_3_1
278
+ (a b c : ℝ)
279
+ -- (hap : 0 < a)
280
+ -- (hbp : 0 < b)
281
+ -- (hcp : 0 < c)
282
+ (h₁ : c < a + b)
283
+ -- (h₃ : a < b + c)
284
+ (hba : b ≤ a) :
285
+ -- (hcb : c ≤ b)
286
+ -- (g₀ : b * c ≤ a * c)
287
+ -- (g₁ : a * c ≤ a * b) :
288
+ a * (b + c - a) ≤ b * (a + c - b) := by
289
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
290
+ refine mul_nonneg ?_ ?_
291
+ . exact sub_nonneg_of_le hba
292
+ . refine le_of_lt ?_
293
+ exact sub_pos.mpr h₁
294
+ linarith
295
+
296
+
297
+ lemma imo_1983_p6_3_2
298
+ (a b c : ℝ)
299
+ -- (hap : 0 < a)
300
+ -- (hbp : 0 < b)
301
+ -- (hcp : 0 < c)
302
+ -- (h₁ : c < a + b)
303
+ (h₃ : a < b + c)
304
+ -- (hba : b ≤ a)
305
+ (hcb : c ≤ b) :
306
+ -- (g₀ : b * c ≤ a * c)
307
+ -- (g₁ : a * c ≤ a * b)
308
+ -- (g₂ : a * (b + c - a) ≤ b * (a + c - b)) :
309
+ b * (a + c - b) ≤ c * (a + b - c) := by
310
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
311
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
312
+ refine mul_nonneg ?_ ?_
313
+ . exact sub_nonneg_of_le hcb
314
+ . refine le_of_lt ?_
315
+ exact sub_pos.mpr h₃
316
+ linarith
317
+ linarith
318
+
319
+
320
+ lemma imo_1983_p6_3_3
321
+ (a b c : ℝ)
322
+ (hap : 0 < a)
323
+ (hbp : 0 < b)
324
+ (hcp : 0 < c)
325
+ -- (h₁ : c < a + b)
326
+ -- (h₃ : a < b + c)
327
+ -- (hba : b ≤ a)
328
+ -- (hcb : c ≤ b)
329
+ (g₀ : b * c ≤ a * c)
330
+ (g₁ : a * c ≤ a * b)
331
+ (g₂ : a * (b + c - a) ≤ b * (a + c - b))
332
+ (g₃ : b * (a + c - b) ≤ c * (a + b - c)) :
333
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
334
+ have g₄: (a * b) * (a * (b + c - a)) + (b * c) * (b * (a + c - b)) + (a * c) * (c * (a + b - c))
335
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
336
+ refine imo_1983_p6_1 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
337
+ . constructor
338
+ . exact mul_pos hap hbp
339
+ . constructor
340
+ . exact mul_pos hap hcp
341
+ . exact mul_pos hbp hcp
342
+ . exact { left := g₀, right := g₁ }
343
+ . exact { left := g₂, right := g₃ }
344
+ linarith
345
+
346
+
347
+ lemma imo_1983_p6_3_4
348
+ (a b c : ℝ)
349
+ (hap : 0 < a)
350
+ (hbp : 0 < b)
351
+ (hcp : 0 < c)
352
+ -- (h₁ : c < a + b)
353
+ -- (h₃ : a < b + c)
354
+ -- (hba : b ≤ a)
355
+ -- (hcb : c ≤ b)
356
+ (g₀ : b * c ≤ a * c)
357
+ (g₁ : a * c ≤ a * b)
358
+ (g₂ : a * (b + c - a) ≤ b * (a + c - b))
359
+ (g₃ : b * (a + c - b) ≤ c * (a + b - c)) :
360
+ a * b * (a * (b + c - a)) + b * c * (b * (a + c - b)) + a * c * (c * (a + b - c)) ≤
361
+ b * c * (a * (b + c - a)) + a * c * (b * (a + c - b)) + a * b * (c * (a + b - c)) := by
362
+ refine imo_1983_p6_1 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
363
+ . constructor
364
+ . exact mul_pos hap hbp
365
+ . constructor
366
+ . exact mul_pos hap hcp
367
+ . exact mul_pos hbp hcp
368
+ . exact { left := g₀, right := g₁ }
369
+ . exact { left := g₂, right := g₃ }
370
+
371
+
372
+
373
+ lemma imo_1983_p6_4
374
+ (a b c : ℝ)
375
+ (hap : 0 < a )
376
+ (hbp : 0 < b )
377
+ (hcp : 0 < c )
378
+ (h₁ : c < a + b)
379
+ -- (h₂ : b < a + c)
380
+ (h₃ : a < b + c)
381
+ (hba: b ≤ a)
382
+ (hcb: c ≤ b) :
383
+ 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a) := by
384
+ have g₀: b * c ≤ a * c := by exact (mul_le_mul_iff_of_pos_right hcp).mpr hba
385
+ have g₁: a * c ≤ a * b := by exact (mul_le_mul_iff_of_pos_left hap).mpr hcb
386
+ have g₂: a * (b + c - a) ≤ b * (a + c - b) := by
387
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
388
+ refine mul_nonneg ?_ ?_
389
+ . exact sub_nonneg_of_le hba
390
+ . refine le_of_lt ?_
391
+ exact sub_pos.mpr h₁
392
+ linarith
393
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
394
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
395
+ refine mul_nonneg ?_ ?_
396
+ . exact sub_nonneg_of_le hcb
397
+ . refine le_of_lt ?_
398
+ exact sub_pos.mpr h₃
399
+ linarith
400
+ have g₄: (a * c) * (a * (b + c - a)) + (a * b) * (b * (a + c - b)) + (b * c) * (c * (a + b - c))
401
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
402
+ refine imo_1983_p6_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
403
+ . constructor
404
+ . exact mul_pos hap hbp
405
+ . constructor
406
+ . exact mul_pos hap hcp
407
+ . exact mul_pos hbp hcp
408
+ . exact { left := g₀, right := g₁ }
409
+ . exact { left := g₂, right := g₃ }
410
+ linarith
411
+
412
+
413
+ lemma imo_1983_p6_4_1
414
+ (a b c : ℝ)
415
+ (hap : 0 < a)
416
+ (hbp : 0 < b)
417
+ (hcp : 0 < c)
418
+ (h₁ : c < a + b)
419
+ (h₃ : a < b + c)
420
+ (hba : b ≤ a)
421
+ (hcb : c ≤ b)
422
+ (g₀ : b * c ≤ a * c)
423
+ (g₁ : a * c ≤ a * b) :
424
+ 0 ≤ a ^ 2 * c * (a - c) + c ^ 2 * b * (c - b) + b ^ 2 * a * (b - a) := by
425
+ have g₂: a * (b + c - a) ≤ b * (a + c - b) := by
426
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
427
+ refine mul_nonneg ?_ ?_
428
+ . exact sub_nonneg_of_le hba
429
+ . refine le_of_lt ?_
430
+ exact sub_pos.mpr h₁
431
+ linarith
432
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
433
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
434
+ refine mul_nonneg ?_ ?_
435
+ . exact sub_nonneg_of_le hcb
436
+ . refine le_of_lt ?_
437
+ exact sub_pos.mpr h₃
438
+ linarith
439
+ have g₄: (a * c) * (a * (b + c - a)) + (a * b) * (b * (a + c - b)) + (b * c) * (c * (a + b - c))
440
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
441
+ refine imo_1983_p6_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
442
+ . constructor
443
+ . exact mul_pos hap hbp
444
+ . constructor
445
+ . exact mul_pos hap hcp
446
+ . exact mul_pos hbp hcp
447
+ . exact { left := g₀, right := g₁ }
448
+ . exact { left := g₂, right := g₃ }
449
+ linarith
450
+
451
+
452
+ lemma imo_1983_p6_4_2
453
+ (a b c : ℝ)
454
+ (hap : 0 < a)
455
+ (hbp : 0 < b)
456
+ (hcp : 0 < c)
457
+ -- (h₁ : c < a + b)
458
+ (h₃ : a < b + c)
459
+ -- (hba : b ≤ a)
460
+ (hcb : c ≤ b)
461
+ (g₀ : b * c ≤ a * c)
462
+ (g₁ : a * c ≤ a * b)
463
+ (g₂ : a * (b + c - a) ≤ b * (a + c - b)) :
464
+ 0 ≤ a ^ 2 * c * (a - c) + c ^ 2 * b * (c - b) + b ^ 2 * a * (b - a) := by
465
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
466
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
467
+ refine mul_nonneg ?_ ?_
468
+ . exact sub_nonneg_of_le hcb
469
+ . refine le_of_lt ?_
470
+ exact sub_pos.mpr h₃
471
+ linarith
472
+ have g₄: (a * c) * (a * (b + c - a)) + (a * b) * (b * (a + c - b)) + (b * c) * (c * (a + b - c))
473
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
474
+ refine imo_1983_p6_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
475
+ . constructor
476
+ . exact mul_pos hap hbp
477
+ . constructor
478
+ . exact mul_pos hap hcp
479
+ . exact mul_pos hbp hcp
480
+ . exact { left := g₀, right := g₁ }
481
+ . exact { left := g₂, right := g₃ }
482
+ linarith
483
+
484
+
485
+ lemma imo_1983_p6_4_3
486
+ (a b c : ℝ)
487
+ (hap : 0 < a)
488
+ (hbp : 0 < b)
489
+ (hcp : 0 < c)
490
+ -- (h₁ : c < a + b)
491
+ -- (h₃ : a < b + c)
492
+ -- (hba : b ≤ a)
493
+ -- (hcb : c ≤ b)
494
+ (g₀ : b * c ≤ a * c)
495
+ (g₁ : a * c ≤ a * b)
496
+ (g₂ : a * (b + c - a) ≤ b * (a + c - b))
497
+ (g₃ : b * (a + c - b) ≤ c * (a + b - c)) :
498
+ 0 ≤ a ^ 2 * c * (a - c) + c ^ 2 * b * (c - b) + b ^ 2 * a * (b - a) := by
499
+ have g₄: (a * c) * (a * (b + c - a)) + (a * b) * (b * (a + c - b)) + (b * c) * (c * (a + b - c))
500
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
501
+ refine imo_1983_p6_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
502
+ . constructor
503
+ . exact mul_pos hap hbp
504
+ . constructor
505
+ . exact mul_pos hap hcp
506
+ . exact mul_pos hbp hcp
507
+ . exact { left := g₀, right := g₁ }
508
+ . exact { left := g₂, right := g₃ }
509
+ linarith
510
+
511
+
512
+ lemma imo_1983_p6_4_4
513
+ (a b c : ℝ)
514
+ -- (hap : 0 < a)
515
+ -- (hbp : 0 < b)
516
+ -- (hcp : 0 < c)
517
+ (h₁ : c < a + b)
518
+ -- (h₃ : a < b + c)
519
+ (hba : b ≤ a) :
520
+ -- (hcb : c ≤ b)
521
+ -- (g₀ : b * c ≤ a * c)
522
+ -- (g₁ : a * c ≤ a * b) :
523
+ a * (b + c - a) ≤ b * (a + c - b) := by
524
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
525
+ refine mul_nonneg ?_ ?_
526
+ . exact sub_nonneg_of_le hba
527
+ . refine le_of_lt ?_
528
+ exact sub_pos.mpr h₁
529
+ linarith
530
+
531
+
532
+ lemma imo_1983_p6_4_5
533
+ (a b c : ℝ)
534
+ -- (hap : 0 < a)
535
+ -- (hbp : 0 < b)
536
+ -- (hcp : 0 < c)
537
+ (h₁ : c < a + b)
538
+ -- (h₃ : a < b + c)
539
+ (hba : b ≤ a) :
540
+ -- (hcb : c ≤ b)
541
+ -- (g₀ : b * c ≤ a * c)
542
+ -- (g₁ : a * c ≤ a * b) :
543
+ 0 ≤ (a - b) * (a + b - c) := by
544
+ refine mul_nonneg ?_ ?_
545
+ . exact sub_nonneg_of_le hba
546
+ . refine le_of_lt ?_
547
+ exact sub_pos.mpr h₁
548
+
549
+
550
+ lemma imo_1983_p6_4_6
551
+ (a b c : ℝ)
552
+ -- (hap : 0 < a)
553
+ -- (hbp : 0 < b)
554
+ -- (hcp : 0 < c)
555
+ -- (h₁ : c < a + b)
556
+ (h₃ : a < b + c)
557
+ -- (hba : b ≤ a)
558
+ (hcb : c ≤ b) :
559
+ -- (g₀ : b * c ≤ a * c)
560
+ -- (g₁ : a * c ≤ a * b)
561
+ -- (g₂ : a * (b + c - a) ≤ b * (a + c - b)) :
562
+ b * (a + c - b) ≤ c * (a + b - c) := by
563
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
564
+ refine mul_nonneg ?_ ?_
565
+ . exact sub_nonneg_of_le hcb
566
+ . refine le_of_lt ?_
567
+ exact sub_pos.mpr h₃
568
+ linarith
569
+
570
+
571
+ lemma imo_1983_p6_4_7
572
+ (a b c : ℝ)
573
+ -- (hap : 0 < a)
574
+ -- (hbp : 0 < b)
575
+ -- (hcp : 0 < c)
576
+ -- (h₁ : c < a + b)
577
+ (h₃ : a < b + c)
578
+ -- (hba : b ≤ a)
579
+ (hcb : c ≤ b) :
580
+ -- (g₀ : b * c ≤ a * c)
581
+ -- (g₁ : a * c ≤ a * b)
582
+ -- (g₂ : a * (b + c - a) ≤ b * (a + c - b)) :
583
+ 0 ≤ (b - c) * (b + c - a) := by
584
+ refine mul_nonneg ?_ ?_
585
+ . exact sub_nonneg_of_le hcb
586
+ . refine le_of_lt ?_
587
+ exact sub_pos.mpr h₃
588
+
589
+
590
+ lemma imo_1983_p6_4_8
591
+ (a b c : ℝ)
592
+ (hap : 0 < a)
593
+ (hbp : 0 < b)
594
+ (hcp : 0 < c)
595
+ -- (h₁ : c < a + b)
596
+ -- (h₃ : a < b + c)
597
+ -- (hba : b ≤ a)
598
+ -- (hcb : c ≤ b)
599
+ (g₀ : b * c ≤ a * c)
600
+ (g₁ : a * c ≤ a * b)
601
+ (g₂ : a * (b + c - a) ≤ b * (a + c - b))
602
+ (g₃ : b * (a + c - b) ≤ c * (a + b - c)) :
603
+ a * c * (a * (b + c - a)) + a * b * (b * (a + c - b)) + b * c * (c * (a + b - c)) ≤
604
+ b * c * (a * (b + c - a)) + a * c * (b * (a + c - b)) + a * b * (c * (a + b - c)) := by
605
+ refine imo_1983_p6_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
606
+ . constructor
607
+ . exact mul_pos hap hbp
608
+ . constructor
609
+ . exact mul_pos hap hcp
610
+ . exact mul_pos hbp hcp
611
+ . exact { left := g₀, right := g₁ }
612
+ . exact { left := g₂, right := g₃ }
613
+
614
+
615
+ lemma imo_1983_p6_5_1
616
+ (a b c : ℝ)
617
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
618
+ (h₁ : c < a + b)
619
+ (h₂ : b < a + c)
620
+ (h₃ : a < b + c)
621
+ (ho₀ : a < b)
622
+ (ho₁ : b < c) :
623
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
624
+ rw [add_comm] at h₁ h₂ h₃
625
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
626
+ exact imo_1983_p6_4 c b a h₀.2.2 h₀.2.1 h₀.1 h₃ h₁ (le_of_lt ho₁) (le_of_lt ho₀)
627
+ linarith
628
+
629
+
630
+ lemma imo_1983_p6_5_2
631
+ (a b c : ℝ)
632
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
633
+ (h₁ : c < a + b)
634
+ (h₂ : b < a + c)
635
+ (h₃ : a < b + c)
636
+ (ho₀ : a < b)
637
+ (ho₁ : c ≤ b)
638
+ (ho₂ : a < c) :
639
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
640
+ rw [add_comm] at h₁ h₂
641
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
642
+ exact imo_1983_p6_3 b c a h₀.2.1 h₀.2.2 h₀.1 h₃ h₂ ho₁ (le_of_lt ho₂)
643
+ linarith
644
+
645
+
646
+ lemma imo_1983_p6_5_3
647
+ (a b c : ℝ)
648
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
649
+ (h₁ : c < a + b)
650
+ (h₂ : b < a + c)
651
+ (h₃ : a < b + c)
652
+ (ho₀ : a < b)
653
+ (ho₁ : c ≤ b)
654
+ (ho₂ : c ≤ a) :
655
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
656
+ rw [add_comm] at h₁
657
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
658
+ exact imo_1983_p6_4 b a c h₀.2.1 h₀.1 h₀.2.2 h₁ h₂ (le_of_lt ho₀) ho₂
659
+ linarith
660
+
661
+
662
+ lemma imo_1983_p6_5_4
663
+ (a b c : ℝ)
664
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
665
+ (h₁ : c < a + b)
666
+ (h₂ : b < a + c)
667
+ (h₃ : a < b + c)
668
+ (ho₀ : b ≤ a)
669
+ (ho₁ : b < c)
670
+ (ho₂ : a < c) :
671
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
672
+ rw [add_comm] at h₂ h₃
673
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
674
+ exact imo_1983_p6_3 c a b h₀.2.2 h₀.1 h₀.2.1 h₂ h₁ (le_of_lt ho₂) ho₀
675
+ linarith
676
+
677
+
678
+ lemma imo_1983_p6_5_5
679
+ (a b c : ℝ)
680
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
681
+ -- (h₁ : c < a + b)
682
+ (h₂ : b < a + c)
683
+ (h₃ : a < b + c)
684
+ (ho₀ : b ≤ a)
685
+ (ho₁ : b < c)
686
+ (ho₂ : c ≤ a) :
687
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
688
+ rw [add_comm] at h₃
689
+ exact imo_1983_p6_4 a c b h₀.1 h₀.2.2 h₀.2.1 h₂ h₃ ho₂ (le_of_lt ho₁)
690
+
691
+
692
+ lemma imo_1983_p6_5_6
693
+ (a b c : ℝ)
694
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
695
+ (h₁ : c < a + b)
696
+ (h₂ : b < a + c)
697
+ (h₃ : a < b + c)
698
+ (ho₀ : a < b) :
699
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
700
+ wlog ho₁: c ≤ b generalizing a b c
701
+ . clear this
702
+ push_neg at ho₁ -- a < b < c
703
+ rw [add_comm] at h₁ h₂ h₃
704
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
705
+ exact imo_1983_p6_4 c b a h₀.2.2 h₀.2.1 h₀.1 h₃ h₁ (le_of_lt ho₁) (le_of_lt ho₀)
706
+ linarith
707
+ . wlog ho₂: c ≤ a generalizing a b c
708
+ . clear this -- a < c ≤ b
709
+ push_neg at ho₂
710
+ rw [add_comm] at h₁ h₂
711
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
712
+ exact imo_1983_p6_3 b c a h₀.2.1 h₀.2.2 h₀.1 h₃ h₂ ho₁ (le_of_lt ho₂)
713
+ linarith
714
+ . -- c ≤ a < b
715
+ rw [add_comm] at h₁
716
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
717
+ exact imo_1983_p6_4 b a c h₀.2.1 h₀.1 h₀.2.2 h₁ h₂ (le_of_lt ho₀) ho₂
718
+ linarith
719
+
720
+
721
+ lemma imo_1983_p6_5_7
722
+ (a b c : ℝ)
723
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
724
+ (h₁ : c < a + b)
725
+ (h₂ : b < a + c)
726
+ (h₃ : a < b + c)
727
+ (ho₀ : a < b)
728
+ (ho₁ : c ≤ b) :
729
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
730
+ wlog ho₂: c ≤ a generalizing a b c
731
+ . clear this -- a < c ≤ b
732
+ push_neg at ho₂
733
+ rw [add_comm] at h₁ h₂
734
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
735
+ exact imo_1983_p6_3 b c a h₀.2.1 h₀.2.2 h₀.1 h₃ h₂ ho₁ (le_of_lt ho₂)
736
+ linarith
737
+ . -- c ≤ a < b
738
+ rw [add_comm] at h₁
739
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
740
+ exact imo_1983_p6_4 b a c h₀.2.1 h₀.1 h₀.2.2 h₁ h₂ (le_of_lt ho₀) ho₂
741
+ linarith
742
+
743
+
744
+ lemma imo_1983_p6_5_8
745
+ (a b c : ℝ)
746
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
747
+ (h₁ : c < a + b)
748
+ (h₂ : b < a + c)
749
+ (h₃ : a < b + c)
750
+ (ho₀ : b ≤ a) :
751
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
752
+ wlog ho₁: c ≤ b generalizing a b c
753
+ . clear this
754
+ push_neg at ho₁
755
+ wlog ho₂: c ≤ a generalizing a b c
756
+ . clear this
757
+ push_neg at ho₂ -- b < a < c
758
+ rw [add_comm] at h₂ h₃
759
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
760
+ exact imo_1983_p6_3 c a b h₀.2.2 h₀.1 h₀.2.1 h₂ h₁ (le_of_lt ho₂) ho₀
761
+ linarith
762
+ . rw [add_comm] at h₃
763
+ exact imo_1983_p6_4 a c b h₀.1 h₀.2.2 h₀.2.1 h₂ h₃ ho₂ (le_of_lt ho₁)
764
+ . exact imo_1983_p6_3 a b c h₀.1 h₀.2.1 h₀.2.2 h₁ h₃ ho₀ ho₁
765
+
766
+
767
+
768
+ lemma imo_1983_p6_5_9
769
+ (a b c : ℝ)
770
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
771
+ (h₁ : c < a + b)
772
+ (h₂ : b < a + c)
773
+ (h₃ : a < b + c)
774
+ (ho₀ : b ≤ a)
775
+ (ho₁ : b < c) :
776
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
777
+ wlog ho₂: c ≤ a generalizing a b c
778
+ . clear this
779
+ push_neg at ho₂ -- b < a < c
780
+ rw [add_comm] at h₂ h₃
781
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
782
+ exact imo_1983_p6_3 c a b h₀.2.2 h₀.1 h₀.2.1 h₂ h₁ (le_of_lt ho₂) ho₀
783
+ linarith
784
+ . rw [add_comm] at h₃
785
+ exact imo_1983_p6_4 a c b h₀.1 h₀.2.2 h₀.2.1 h₂ h₃ ho₂ (le_of_lt ho₁)
786
+
787
+
788
+ lemma imo_1983_p6_6
789
+ (a b c : ℝ)
790
+ -- (hap : 0 < a )
791
+ -- (hbp : 0 < b )
792
+ (hcp : 0 < c )
793
+ -- (h₁ : c < a + b)
794
+ -- (h₂ : b < a + c)
795
+ -- (h₃ : a < b + c)
796
+ (hba: b ≤ a)
797
+ (hcb: c ≤ b) :
798
+ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a) ≤
799
+ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a) := by
800
+ have h₄ : 0 ≤ (a + b + c) * (a - b) * (a - c) * (b - c) := by
801
+ refine mul_nonneg ?_ (by linarith)
802
+ refine mul_nonneg ?_ (by linarith)
803
+ refine mul_nonneg ?_ (by linarith)
804
+ linarith
805
+ linarith
806
+
807
+
808
+ -- give the tight as a hypothesis, use it to prove each of the 6 cases
809
+ lemma imo_1983_p6_7_1
810
+ (a b c : ℝ)
811
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
812
+ (h₁ : c < a + b)
813
+ -- (h₂ : b < a + c)
814
+ (h₃ : a < b + c)
815
+ (ho₀ : a < b)
816
+ (ho₁ : b < c)
817
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
818
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
819
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
820
+ have h₄: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
821
+ refine ht c b a ?_ ?_ ?_
822
+ . simp_all only [and_self]
823
+ . constructor
824
+ . rw [add_comm]
825
+ exact h₃
826
+ . rw [add_comm]
827
+ exact h₁
828
+ . constructor
829
+ . exact le_of_lt ho₀
830
+ . exact le_of_lt ho₁
831
+ linarith
832
+
833
+
834
+ lemma imo_1983_p6_7_2
835
+ (a b c : ℝ)
836
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
837
+ -- (h₁ : c < a + b)
838
+ (h₂ : b < a + c)
839
+ (h₃ : a < b + c)
840
+ -- (ho₀ : a < b)
841
+ (ho₁ : c ≤ b)
842
+ (ho₂ : a < c)
843
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
844
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
845
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
846
+ have h₄: 0 ≤ b ^ 2 * a * (b - a) + a ^ 2 * c * (a - c) + c ^ 2 * b * (c - b) := by
847
+ refine ht b c a ?_ ?_ ?_
848
+ . simp_all only [and_self]
849
+ . constructor
850
+ . exact h₃
851
+ . rw [add_comm]
852
+ exact h₂
853
+ . constructor
854
+ . exact le_of_lt ho₂
855
+ . exact ho₁
856
+ refine le_trans h₄ ?_
857
+ have h₅: b ^ 2 * a * (b - a) + a ^ 2 * c * (a - c) + c ^ 2 * b * (c - b) ≤
858
+ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
859
+ rw [add_comm] at h₂
860
+ refine imo_1983_p6_6 b c a h₀.1 ho₁ ?_
861
+ exact le_of_lt ho₂
862
+ linarith
863
+
864
+
865
+ lemma imo_1983_p6_7_3
866
+ (a b c : ℝ)
867
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
868
+ (h₁ : c < a + b)
869
+ (h₂ : b < a + c)
870
+ -- (h₃ : a < b + c)
871
+ (ho₀ : a < b)
872
+ -- (ho₁ : c ≤ b)
873
+ (ho₂ : c ≤ a)
874
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
875
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
876
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
877
+ have h₄: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
878
+ refine ht b a c ?_ ?_ ?_
879
+ . simp_all only [and_self]
880
+ . constructor
881
+ . rw [add_comm]
882
+ exact h₁
883
+ . exact h₂
884
+ . constructor
885
+ . exact ho₂
886
+ . exact le_of_lt ho₀
887
+ linarith
888
+
889
+
890
+ lemma imo_1983_p6_7_4
891
+ (a b c : ℝ)
892
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
893
+ (h₁ : c < a + b)
894
+ (h₂ : b < a + c)
895
+ -- (h₃ : a < b + c)
896
+ (ho₀ : b ≤ a)
897
+ -- (ho₁ : b < c)
898
+ (ho₂ : a < c)
899
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
900
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
901
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
902
+ have h₄: 0 ≤ c ^ 2 * b * (c - b) + b ^ 2 * a * (b - a) + a ^ 2 * c * (a - c) := by
903
+ refine ht c a b ?_ ?_ ?_
904
+ . simp_all only [and_self]
905
+ . constructor
906
+ . rw [add_comm]
907
+ exact h₂
908
+ . exact h₁
909
+ . constructor
910
+ . exact ho₀
911
+ . exact le_of_lt ho₂
912
+ refine le_trans h₄ ?_
913
+ have h₅: c ^ 2 * b * (c - b) + b ^ 2 * a * (b - a) + a ^ 2 * c * (a - c) ≤
914
+ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
915
+ rw [add_comm] at h₂
916
+ refine imo_1983_p6_6 c a b h₀.2.1 ?_ ho₀
917
+ exact le_of_lt ho₂
918
+ linarith
919
+
920
+
921
+ lemma imo_1983_p6_7_5
922
+ (a b c : ℝ)
923
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
924
+ -- (h₁ : c < a + b)
925
+ (h₂ : b < a + c)
926
+ (h₃ : a < b + c)
927
+ -- (ho₀ : b ≤ a)
928
+ (ho₁ : b < c)
929
+ (ho₂ : c ≤ a)
930
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
931
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
932
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
933
+ refine ht a c b ?_ ?_ ?_
934
+ . simp_all only [and_self]
935
+ . simp_all only [true_and]
936
+ rw [add_comm]
937
+ exact h₃
938
+ . constructor
939
+ . exact le_of_lt ho₁
940
+ . exact ho₂
941
+
942
+
943
+ lemma imo_1983_p6_7_6
944
+ (a b c : ℝ)
945
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
946
+ (h₁ : c < a + b)
947
+ -- (h₂ : b < a + c)
948
+ (h₃ : a < b + c)
949
+ (ho₀ : b ≤ a)
950
+ (ho₁ : c ≤ b)
951
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
952
+ → 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a)) :
953
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
954
+ have h₄: 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a) := by
955
+ refine ht a b c h₀ ?_ ?_
956
+ . simp_all only [true_and]
957
+ . constructor
958
+ . exact ho₁
959
+ . exact ho₀
960
+ refine le_trans h₄ ?_
961
+ refine imo_1983_p6_6 a b c h₀.2.2 ho₀ ho₁
962
+
963
+
964
+ lemma imo_1983_p6_8_1
965
+ (a b c : ℝ)
966
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
967
+ -- (h₁ : c < a + b)
968
+ (h₂ : b < a + c)
969
+ (h₃ : a < b + c)
970
+ -- (ho₀ : a < b)
971
+ (ho₁ : c ≤ b)
972
+ (ho₂ : a < c)
973
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
974
+ → 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a)) :
975
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
976
+ have h₄: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
977
+ refine ht b c a ?_ ?_ ?_
978
+ . exact and_rotate.mp h₀
979
+ . simp_all only [true_and]
980
+ linarith
981
+ . constructor
982
+ . exact le_of_lt ho₂
983
+ . exact ho₁
984
+ linarith
985
+
986
+
987
+ lemma imo_1983_p6_8_2
988
+ (a b c : ℝ)
989
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
990
+ (h₁ : c < a + b)
991
+ (h₂ : b < a + c)
992
+ -- (h₃ : a < b + c)
993
+ (ho₀ : b ≤ a)
994
+ -- (ho₁ : b < c)
995
+ (ho₂ : a < c)
996
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
997
+ → 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a)) :
998
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
999
+ have h₄: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
1000
+ refine ht c a b ?_ ?_ ?_
1001
+ . exact and_rotate.mp (and_rotate.mp h₀)
1002
+ . constructor
1003
+ . rw [add_comm]
1004
+ exact h₂
1005
+ . exact h₁
1006
+ . constructor
1007
+ . exact ho₀
1008
+ . exact le_of_lt ho₂
1009
+ linarith
1010
+
1011
+
1012
+ lemma imo_1983_p6_8_3
1013
+ (a b c : ℝ)
1014
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1015
+ (h₁ : c < a + b)
1016
+ -- (h₂ : b < a + c)
1017
+ (h₃ : a < b + c)
1018
+ (ho₀ : b ≤ a)
1019
+ (ho₁ : c ≤ b)
1020
+ (ht : ∀ a b c :ℝ, (0 < a ∧ 0 < b ∧ 0 < c) → (c < a + b ∧ a < b + c) → (c ≤ b ∧ b ≤ a)
1021
+ → 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a)) :
1022
+ 0 ≤ a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) := by
1023
+ refine ht a b c h₀ ?_ ?_
1024
+ . simp_all only [true_and]
1025
+ . constructor
1026
+ . exact ho₁
1027
+ . exact ho₀
1028
+
1029
+
1030
+ lemma mylemma_1x
1031
+ (a b c : ℝ)
1032
+ (x y z : ℝ)
1033
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1034
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1035
+ (h₂: c ≤ b ∧ b ≤ a)
1036
+ (h₃: x ≤ y ∧ y ≤ z) :
1037
+ x / c + y / a + z / b ≤ x / a + y / b + z / c := by
1038
+ have g3: (z - x) / b ≤ (z - x) / c := by
1039
+ have g31: 0 ≤ (z-x) := by
1040
+ refine sub_nonneg_of_le ?_
1041
+ exact le_trans h₃.1 h₃.2
1042
+ exact div_le_div_of_nonneg_left g31 (by linarith) h₂.1
1043
+ have g4: (y-x)/a + (z-y)/b ≤ (z-x)/b := by
1044
+ have g41: (y-x)/a + (z-y)/b ≤ (y-x)/b + (z-y)/b := by
1045
+ rw [add_le_add_iff_right ((z-y)/b)]
1046
+ have g411: 0 ≤ (y-x) := by linarith
1047
+ exact div_le_div_of_nonneg_left g411 (by linarith) h₂.2
1048
+ have g42: (y-x)/b + (z-y)/b = (z-x)/b := by ring
1049
+ linarith
1050
+ have g5: (y-x)/a + (z-y)/b ≤ (z-x)/c := by
1051
+ exact le_trans g4 g3
1052
+ ring_nf at g5
1053
+ ring_nf
1054
+ linarith
1055
+
1056
+
1057
+ lemma my_lemma_2x
1058
+ (a b c : ℝ)
1059
+ (x y z : ℝ)
1060
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1061
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1062
+ (h₂: c ≤ b ∧ b ≤ a)
1063
+ (h₃: x ≤ y ∧ y ≤ z) :
1064
+ x/c + y/a + z/b ≤ x/a + y/b + z/c := by
1065
+ have g3: (z-x)/b ≤ (z-x)/c := by
1066
+ have g31: 0 ≤ (z-x) := by linarith
1067
+ exact div_le_div_of_nonneg_left g31 (by linarith) h₂.1
1068
+ have g4: (y-x)/a + (z-y)/b ≤ (z-x)/b := by
1069
+ have g41: (y-x)/a + (z-y)/b ≤ (y-x)/b + (z-y)/b := by
1070
+ rw [add_le_add_iff_right ((z-y)/b)]
1071
+ have g411: 0 ≤ (y-x) := by linarith
1072
+ exact div_le_div_of_nonneg_left g411 (by linarith) h₂.2
1073
+ have g42: (y-x)/b + (z-y)/b = (z-x)/b := by ring_nf
1074
+ linarith
1075
+ have g5: (y-x)/a + (z-y)/b ≤ (z-x)/c := by exact le_trans g4 g3
1076
+ ring_nf at g5
1077
+ ring_nf
1078
+ linarith
1079
+
1080
+
1081
+ lemma my_lemma_3x
1082
+ (a b c : ℝ)
1083
+ (x y z : ℝ)
1084
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1085
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1086
+ (h₂: c ≤ b ∧ b ≤ a)
1087
+ (h₃: x ≤ y ∧ y ≤ z) :
1088
+ x/b + y/c + z/a ≤ x/a + y/b + z/c := by
1089
+ have g3: (z-y)/b ≤ (z-y)/c := by
1090
+ have g31: 0 ≤ (z-y) := by linarith
1091
+ exact div_le_div_of_nonneg_left g31 (by linarith) h₂.1
1092
+ have g4: (x-y)/b + (z-x)/a ≤ (z-y)/b := by
1093
+ have g41: (x-y)/b + (z-x)/a ≤ (x-y)/b + (z-x)/b := by
1094
+ rw [add_le_add_iff_left ((x-y)/b)]
1095
+ have g411: 0 ≤ (z-x) := by linarith
1096
+ exact div_le_div_of_nonneg_left g411 (by linarith) h₂.2
1097
+ have g42: (x-y)/b + (z-x)/b = (z-y)/b := by ring_nf
1098
+ linarith
1099
+ have g5: (x-y)/b + (z-x)/a ≤ (z-y)/c := by
1100
+ exact le_trans g4 g3
1101
+ ring_nf at g5
1102
+ ring_nf
1103
+ linarith
1104
+
1105
+
1106
+ lemma my_lemma_4x
1107
+ (a b c : ℝ)
1108
+ (x y z : ℝ)
1109
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1110
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1111
+ (h₂: c ≤ b ∧ b ≤ a)
1112
+ (h₃: x ≤ y ∧ y ≤ z) :
1113
+ x/b + y/a + z/c ≤ x/a + y/b + z/c := by
1114
+ rw [add_le_add_iff_right (z/c)]
1115
+ have g2: (y-x)/a ≤ (y-x)/b := by
1116
+ exact div_le_div_of_nonneg_left (by linarith) h₀.2.1 h₂.2
1117
+ rw [sub_div] at g2
1118
+ rw [sub_div] at g2
1119
+ linarith
1120
+
1121
+
1122
+ lemma my_lemma_5x
1123
+ (a b c : ℝ)
1124
+ (x y z : ℝ)
1125
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1126
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1127
+ (h₂: c ≤ b ∧ b ≤ a)
1128
+ (h₃: x ≤ y ∧ y ≤ z) :
1129
+ x/a + y/c + z/b ≤ x/a + y/b + z/c := by
1130
+ rw [add_assoc (x/a)]
1131
+ rw [add_assoc (x/a)]
1132
+ rw [add_le_add_iff_left (x/a)]
1133
+ have g1: (z-y)/b ≤ (z-y)/c := by
1134
+ exact div_le_div_of_nonneg_left (by linarith) h₀.2.2 h₂.1
1135
+ rw [sub_div] at g1
1136
+ rw [sub_div] at g1
1137
+ linarith
1138
+
1139
+
1140
+ lemma my_lemma_6x
1141
+ (a b c : ℝ)
1142
+ (x y z : ℝ)
1143
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1144
+ -- (h₁ : 0 < x ∧ 0 < y ∧ 0 < z)
1145
+ (h₂: c ≤ b ∧ b ≤ a)
1146
+ (h₃: x ≤ y ∧ y ≤ z) :
1147
+ x/c + y/b + z/a ≤ x/a + y/b + z/c := by
1148
+ have g1: (z-x)/a ≤ (z-x)/c := by
1149
+ exact div_le_div_of_nonneg_left (by linarith) h₀.2.2 (by linarith)
1150
+ have g2: x/c + z/a ≤ x/a + z/c := by
1151
+ rw [sub_div] at g1
1152
+ rw [sub_div] at g1
1153
+ linarith
1154
+ linarith
1155
+
1156
+
1157
+ lemma mylemma_7x
1158
+ (a b c : ℝ)
1159
+ (x y z : ℝ)
1160
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
1161
+ (h₂: c ≤ b ∧ b ≤ a)
1162
+ (h₃: x ≤ y ∧ y ≤ z) :
1163
+ x / c + y / a + z / b ≤ x / a + y / b + z / c := by
1164
+ have g3: (z - x) / b ≤ (z - x) / c := by
1165
+ have g31: 0 ≤ (z-x) := by
1166
+ refine sub_nonneg_of_le ?_
1167
+ exact le_trans h₃.1 h₃.2
1168
+ exact div_le_div_of_nonneg_left g31 (by linarith) h₂.1
1169
+ have g4: (y-x)/a + (z-y)/b ≤ (z-x)/b := by
1170
+ have g41: (y-x)/a + (z-y)/b ≤ (y-x)/b + (z-y)/b := by
1171
+ rw [add_le_add_iff_right ((z-y)/b)]
1172
+ have g411: 0 ≤ (y-x) := by linarith
1173
+ exact div_le_div_of_nonneg_left g411 (by linarith) h₂.2
1174
+ have g42: (y-x)/b + (z-y)/b = (z-x)/b := by ring
1175
+ linarith
1176
+ have g5: (y-x)/a + (z-y)/b ≤ (z-x)/c := by
1177
+ exact le_trans g4 g3
1178
+ ring_nf at g5
1179
+ ring_nf
1180
+ linarith
Lemmas/imo_1984_p6_lemmas.lean ADDED
@@ -0,0 +1,1601 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat
5
+
6
+ lemma imo_1984_p6_1
7
+ (a b : ℕ)
8
+ -- (hap: 0 < a)
9
+ -- (hbp: 0 < b)
10
+ (h₀: b < a) :
11
+ ((a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b) := by
12
+ have h₁: b^2 ≤ a * b := by
13
+ rw [pow_two]
14
+ refine Nat.mul_le_mul_right ?_ ?_
15
+ exact Nat.le_of_lt h₀
16
+ have h₂: a * b ≤ a ^ 2 := by
17
+ rw [pow_two]
18
+ refine Nat.mul_le_mul_left ?_ ?_
19
+ exact Nat.le_of_lt h₀
20
+ repeat rw [pow_two]
21
+ repeat rw [Nat.mul_sub_left_distrib]
22
+ repeat rw [Nat.mul_sub_right_distrib a b a]
23
+ rw [Nat.sub_right_comm]
24
+ repeat rw [Nat.mul_sub_right_distrib a b b]
25
+ ring_nf
26
+ have h₃: a ^ 2 - (a * b - b ^ 2) = a ^ 2 - a * b + b ^ 2 := by
27
+ refine tsub_tsub_assoc ?h₁ h₁
28
+ exact h₂
29
+ rw [h₃]
30
+ rw [← Nat.sub_add_comm h₂]
31
+ . rw [← Nat.sub_add_eq, ← mul_two]
32
+
33
+
34
+ lemma imo_1984_p6_2
35
+ (a b c d k m : ℕ)
36
+ (h₂ : a < b ∧ b < c ∧ c < d)
37
+ (h₃ : a * d = b * c)
38
+ (h₄ : a + d = 2 ^ k)
39
+ (h₅ : b + c = 2 ^ m) :
40
+ (m < k) := by
41
+ have h₆: (c - b) ^ 2 < (d - a) ^ 2 := by
42
+ refine Nat.pow_lt_pow_left ?_ (by norm_num)
43
+ have h₈₀: c - a < d - a := by
44
+ have g₀: c - a + a < d - a + a := by
45
+ rw [Nat.sub_add_cancel ?_]
46
+ rw [Nat.sub_add_cancel ?_]
47
+ . exact h₂.2.2
48
+ . linarith
49
+ . linarith
50
+ exact Nat.lt_of_add_lt_add_right g₀
51
+ refine lt_trans ?_ h₈₀
52
+ refine Nat.sub_lt_sub_left ?_ h₂.1
53
+ exact lt_trans h₂.1 h₂.2.1
54
+ have h₇: (b + c) ^ 2 < (a + d) ^ 2 := by
55
+ rw [add_sq b c, add_sq a d]
56
+ have hda: a < d := by
57
+ refine lt_trans h₂.1 ?_
58
+ exact lt_trans h₂.2.1 h₂.2.2
59
+ rw [imo_1984_p6_1 d a hda] at h₆
60
+ rw [imo_1984_p6_1 c b h₂.2.1] at h₆
61
+ rw [mul_assoc 2 b c, ← h₃, ← mul_assoc]
62
+ rw [mul_assoc 2 c b, mul_comm c b, ← h₃, ← mul_assoc] at h₆
63
+ rw [add_assoc, add_comm _ (c ^ 2), ← add_assoc]
64
+ rw [add_assoc (a ^ 2), add_comm _ (d ^ 2), ← add_assoc]
65
+ rw [mul_assoc 2 d a, mul_comm d a, ← mul_assoc] at h₆
66
+ rw [add_comm (d ^ 2) (a ^ 2)] at h₆
67
+ rw [add_comm (c ^ 2) (b ^ 2)] at h₆
68
+ have g₀: 2 * a * d ≤ 4 * a * d := by
69
+ ring_nf
70
+ exact Nat.mul_le_mul_left (a * d) (by norm_num)
71
+ have g₁: 2 * a * d = 4 * a * d - 2 * a * d := by
72
+ ring_nf
73
+ rw [← Nat.mul_sub_left_distrib]
74
+ norm_num
75
+ have g₂: 2 * a * d ≤ b ^ 2 + c ^ 2 := by
76
+ rw [mul_assoc, h₃, ← mul_assoc]
77
+ exact two_mul_le_add_sq b c
78
+ have g₃: 2 * a * d ≤ a ^ 2 + d ^ 2 := by
79
+ exact two_mul_le_add_sq a d
80
+ rw [g₁, ← Nat.add_sub_assoc (g₀) (b ^ 2 + c ^ 2)]
81
+ rw [← Nat.add_sub_assoc (g₀) (a ^ 2 + d ^ 2)]
82
+ rw [Nat.sub_add_comm g₂, Nat.sub_add_comm g₃]
83
+ exact (Nat.add_lt_add_iff_right).mpr h₆
84
+ have h2 : 1 < 2 := by norm_num
85
+ refine (Nat.pow_lt_pow_iff_right h2).mp ?_
86
+ rw [← h₄, ← h₅]
87
+ exact (Nat.pow_lt_pow_iff_left (by norm_num) ).mp h₇
88
+
89
+
90
+ lemma imo_1984_p6_3
91
+ (a b c d : ℕ)
92
+ (h₀ : a < b ∧ b < c ∧ c < d) :
93
+ (c - b) ^ 2 < (d - a) ^ 2 := by
94
+ refine Nat.pow_lt_pow_left ?_ (by norm_num)
95
+ have h₁: c - a < d - a := by
96
+ have g₀: c - a + a < d - a + a := by
97
+ rw [Nat.sub_add_cancel ?_]
98
+ rw [Nat.sub_add_cancel ?_]
99
+ . exact h₀.2.2
100
+ . linarith
101
+ . linarith
102
+ exact Nat.lt_of_add_lt_add_right g₀
103
+ refine lt_trans ?_ h₁
104
+ refine Nat.sub_lt_sub_left ?_ h₀.1
105
+ exact lt_trans h₀.1 h₀.2.1
106
+
107
+
108
+ lemma imo_1984_p6_4
109
+ (a b c d : ℕ)
110
+ (h₀ : a < b ∧ b < c ∧ c < d)
111
+ (h₁ : a * d = b * c)
112
+ (h₂ : (c - b) ^ 2 < (d - a) ^ 2) :
113
+ (b + c) ^ 2 < (a + d) ^ 2 := by
114
+ rw [add_sq b c, add_sq a d]
115
+ have hda: a < d := by
116
+ refine lt_trans h₀.1 ?_
117
+ exact lt_trans h₀.2.1 h₀.2.2
118
+ rw [imo_1984_p6_1 d a hda] at h₂
119
+ rw [imo_1984_p6_1 c b h₀.2.1] at h₂
120
+ rw [mul_assoc 2 b c, ← h₁, ← mul_assoc]
121
+ rw [mul_assoc 2 c b, mul_comm c b, ← h₁, ← mul_assoc] at h₂
122
+ rw [add_assoc, add_comm _ (c ^ 2), ← add_assoc]
123
+ rw [add_assoc (a ^ 2), add_comm _ (d ^ 2), ← add_assoc]
124
+ rw [mul_assoc 2 d a, mul_comm d a, ← mul_assoc] at h₂
125
+ rw [add_comm (d ^ 2) (a ^ 2)] at h₂
126
+ rw [add_comm (c ^ 2) (b ^ 2)] at h₂
127
+ have g₀: 2 * a * d ≤ 4 * a * d := by
128
+ ring_nf
129
+ exact Nat.mul_le_mul_left (a * d) (by norm_num)
130
+ have g₁: 2 * a * d = 4 * a * d - 2 * a * d := by
131
+ ring_nf
132
+ rw [← Nat.mul_sub_left_distrib]
133
+ norm_num
134
+ have g₂: 2 * a * d ≤ b ^ 2 + c ^ 2 := by
135
+ rw [mul_assoc, h₁, ← mul_assoc]
136
+ exact two_mul_le_add_sq b c
137
+ have g₃: 2 * a * d ≤ a ^ 2 + d ^ 2 := by
138
+ exact two_mul_le_add_sq a d
139
+ rw [g₁, ← Nat.add_sub_assoc (g₀) (b ^ 2 + c ^ 2)]
140
+ rw [← Nat.add_sub_assoc (g₀) (a ^ 2 + d ^ 2)]
141
+ rw [Nat.sub_add_comm g₂, Nat.sub_add_comm g₃]
142
+ exact (Nat.add_lt_add_iff_right).mpr h₂
143
+
144
+
145
+ lemma imo_1984_p6_5
146
+ (a b c d : ℕ)
147
+ -- (h₀ : a < b ∧ b < c ∧ c < d)
148
+ (h₁ : a * d = b * c)
149
+ (h₂ : b ^ 2 + c ^ 2 - 2 * a * d < a ^ 2 + d ^ 2 - 2 * a * d) :
150
+ b ^ 2 + c ^ 2 + 2 * a * d < a ^ 2 + d ^ 2 + 2 * a * d := by
151
+ have g₀: 2 * a * d ≤ 4 * a * d := by
152
+ ring_nf
153
+ exact Nat.mul_le_mul_left (a * d) (by norm_num)
154
+ have g₁: 2 * a * d = 4 * a * d - 2 * a * d := by
155
+ ring_nf
156
+ rw [← Nat.mul_sub_left_distrib]
157
+ norm_num
158
+ have g₂: 2 * a * d ≤ b ^ 2 + c ^ 2 := by
159
+ rw [mul_assoc, h₁, ← mul_assoc]
160
+ exact two_mul_le_add_sq b c
161
+ have g₃: 2 * a * d ≤ a ^ 2 + d ^ 2 := by
162
+ exact two_mul_le_add_sq a d
163
+ rw [g₁, ← Nat.add_sub_assoc (g₀) (b ^ 2 + c ^ 2)]
164
+ rw [← Nat.add_sub_assoc (g₀) (a ^ 2 + d ^ 2)]
165
+ rw [Nat.sub_add_comm g₂, Nat.sub_add_comm g₃]
166
+ exact (Nat.add_lt_add_iff_right).mpr h₂
167
+
168
+
169
+ lemma imo_1984_p6_6
170
+ (a b c d : ℕ)
171
+ (h₁ : a * d = b * c) :
172
+ -- (h₂ : b ^ 2 + c ^ 2 - 2 * a * d < a ^ 2 + d ^ 2 - 2 * a * d)
173
+ -- (g₀ : 2 * a * d ≤ 4 * a * d)
174
+ -- (g₁ : 2 * a * d = 4 * a * d - 2 * a * d) :
175
+ (2 * a * d ≤ b ^ 2 + c ^ 2) := by
176
+ rw [mul_assoc, h₁, ← mul_assoc]
177
+ exact two_mul_le_add_sq b c
178
+
179
+
180
+ lemma imo_1984_p6_7
181
+ (a b c d k m : ℕ)
182
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
183
+ (h₁ : m < k)
184
+ (h₂ : a < b ∧ b < c ∧ c < d)
185
+ (h₃ : a * d = b * c)
186
+ (h₄ : a + d = 2 ^ k)
187
+ (h₅ : b + c = 2 ^ m)
188
+ (hkm : k ≤ m) :
189
+ a = 99 := by
190
+ linarith [h₁, hkm]
191
+
192
+
193
+
194
+ lemma imo_1984_p6_8
195
+ (a b c d k m : ℕ)
196
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
197
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
198
+ (h₂ : a < b ∧ b < c ∧ c < d)
199
+ (h₃ : a * d = b * c)
200
+ (h₄ : a + d = 2 ^ k)
201
+ (h₅ : b + c = 2 ^ m) :
202
+ -- (hkm : m < k) :
203
+ b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a) := by
204
+ have h₆₀: c = 2 ^ m - b := by exact (tsub_eq_of_eq_add_rev (id h₅.symm)).symm
205
+ have h₆₁: d = 2 ^ k - a := by exact (tsub_eq_of_eq_add_rev (id h₄.symm)).symm
206
+ rw [h₆₀, h₆₁] at h₃
207
+ repeat rw [Nat.mul_sub_left_distrib, ← pow_two] at h₃
208
+ have h₆₂: b * 2 ^ m - a * 2 ^ k = b ^ 2 - a ^ 2 := by
209
+ symm at h₃
210
+ refine Nat.sub_eq_of_eq_add ?_
211
+ rw [add_comm, ← Nat.add_sub_assoc]
212
+ . rw [Nat.sub_add_comm]
213
+ . refine Nat.eq_add_of_sub_eq ?_ h₃
214
+ rw [pow_two]
215
+ refine le_of_lt ?_
216
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.2.1) h₀.2.1
217
+ linarith
218
+ . rw [pow_two]
219
+ refine le_of_lt ?_
220
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.1) h₀.1
221
+ linarith
222
+ . refine le_of_lt ?_
223
+ rw [pow_two, pow_two]
224
+ exact mul_lt_mul h₂.1 (le_of_lt h₂.1) h₀.1 (le_of_lt h₀.2.1)
225
+ rw [Nat.sq_sub_sq b a] at h₆₂
226
+ rw [mul_comm (b - a) _]
227
+ exact h₆₂
228
+
229
+
230
+ lemma imo_1984_p6_8_1
231
+ (a b c d k m : ℕ)
232
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
233
+ -- (h₂ : a < b ∧ b < c ∧ c < d)
234
+ (h₃ : a * d = b * c)
235
+ (h₄ : a + d = 2 ^ k)
236
+ (h₅ : b + c = 2 ^ m) :
237
+ -- (h₆₀ : c = 2 ^ m - b)
238
+ -- (h₆₁ : d = 2 ^ k - a) :
239
+ a * (2 ^ k - a) = b * (2 ^ m - b) := by
240
+ have h₆₀: c = 2 ^ m - b := by exact (tsub_eq_of_eq_add_rev (id h₅.symm)).symm
241
+ have h₆₁: d = 2 ^ k - a := by exact (tsub_eq_of_eq_add_rev (id h₄.symm)).symm
242
+ rw [h₆₀, h₆₁] at h₃
243
+ exact h₃
244
+
245
+
246
+
247
+ lemma imo_1984_p6_8_2
248
+ (a b c d k m : ℕ)
249
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
250
+ (h₂ : a < b)
251
+ (h₃ : a * 2 ^ k - a ^ 2 = b * 2 ^ m - b ^ 2)
252
+ (h₄ : a + d = 2 ^ k)
253
+ (h₅ : b + c = 2 ^ m) :
254
+ -- (h₆₀ : c = 2 ^ m - b)
255
+ -- (h₆₁ : d = 2 ^ k - a) :
256
+ b * 2 ^ m - a * 2 ^ k = b ^ 2 - a ^ 2 := by
257
+ symm at h₃
258
+ refine Nat.sub_eq_of_eq_add ?_
259
+ rw [add_comm, ← Nat.add_sub_assoc]
260
+ . rw [Nat.sub_add_comm]
261
+ . refine Nat.eq_add_of_sub_eq ?_ h₃
262
+ rw [pow_two]
263
+ refine le_of_lt ?_
264
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.2.1) h₀.2.1
265
+ linarith
266
+ . rw [pow_two]
267
+ refine le_of_lt ?_
268
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.1) h₀.1
269
+ linarith
270
+ . refine le_of_lt ?_
271
+ rw [pow_two, pow_two]
272
+ exact mul_lt_mul h₂ (le_of_lt h₂) h₀.1 (le_of_lt h₀.2.1)
273
+
274
+
275
+ lemma imo_1984_p6_8_3
276
+ (a b c d k m : ℕ)
277
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
278
+ -- (h₂ : a < b)
279
+ (h₃ : b * 2 ^ m - b ^ 2 = a * 2 ^ k - a ^ 2)
280
+ -- (h₄ : a + d = 2 ^ k)
281
+ (h₅ : b + c = 2 ^ m) :
282
+ -- (h₆₀ : c = 2 ^ m - b)
283
+ -- (h₆₁ : d = 2 ^ k - a) :
284
+ b * 2 ^ m = a * 2 ^ k - a ^ 2 + b ^ 2 := by
285
+ refine Nat.eq_add_of_sub_eq ?_ h₃
286
+ rw [pow_two]
287
+ refine le_of_lt ?_
288
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.2.1) h₀.2.1
289
+ linarith
290
+
291
+
292
+ lemma imo_1984_p6_8_4
293
+ (a b c d k : ℕ)
294
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
295
+ -- (h₂ : a < b)
296
+ -- (h₃ : b * 2 ^ m - b ^ 2 = a * 2 ^ k - a ^ 2)
297
+ (h₄ : a + d = 2 ^ k) :
298
+ -- (h₅ : b + c = 2 ^ m) :
299
+ a ^ 2 ≤ a * 2 ^ k := by
300
+ rw [pow_two]
301
+ refine le_of_lt ?_
302
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.1) h₀.1
303
+ linarith
304
+
305
+
306
+ lemma imo_1984_p6_8_5
307
+ (a b : ℕ)
308
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
309
+ (h₂ : a < b) :
310
+ -- h₃ : b * 2 ^ m - b ^ 2 = a * 2 ^ k - a ^ 2
311
+ -- h₄ : a + d = 2 ^ k
312
+ -- h₅ : b + c = 2 ^ m
313
+ -- h₆₀ : c = 2 ^ m - b
314
+ -- h₆₁ : d = 2 ^ k - a
315
+ a ^ 2 < b ^ 2 := by
316
+ exact Nat.pow_lt_pow_left h₂ (by norm_num)
317
+
318
+
319
+ lemma imo_1984_p6_8_6
320
+ (a b k m : ℕ)
321
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
322
+ -- (h₂ : a < b ∧ b < c ∧ c < d)
323
+ -- (h₃ : a * 2 ^ k - a ^ 2 = b * 2 ^ m - b ^ 2)
324
+ -- (h₄ : a + d = 2 ^ k)
325
+ -- (h₅ : b + c = 2 ^ m)
326
+ -- (h₆₀ : c = 2 ^ m - b)
327
+ -- (h₆₁ : d = 2 ^ k - a)
328
+ (h₆₂ : b * 2 ^ m - a * 2 ^ k = b ^ 2 - a ^ 2) :
329
+ b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a) := by
330
+ rw [Nat.sq_sub_sq b a] at h₆₂
331
+ rw [mul_comm (b - a) _]
332
+ exact h₆₂
333
+
334
+
335
+
336
+
337
+ lemma imo_1984_p6_9
338
+ (a b k m : ℕ)
339
+ (hkm : m < k)
340
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a)) :
341
+ 2 ^ m ∣ (b - a) * (b + a) := by
342
+ have h₇₀: k = (k - m) + m := by exact (Nat.sub_add_cancel (le_of_lt hkm)).symm
343
+ rw [h₇₀, pow_add] at h₆
344
+ have h₇₁: (b - a * 2 ^ (k - m)) * (2 ^ m) = (b - a) * (b + a) := by
345
+ rw [Nat.mul_sub_right_distrib]
346
+ rw [mul_assoc a _ _]
347
+ exact h₆
348
+ exact Dvd.intro_left (b - a * 2 ^ (k - m)) h₇₁
349
+
350
+
351
+
352
+
353
+ lemma imo_1984_p6_10
354
+ (a b c d k m : ℕ)
355
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
356
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
357
+ (h₂ : a < b ∧ b < c ∧ c < d)
358
+ -- (h₃ : a * d = b * c)
359
+ -- (h₄ : a + d = 2 ^ k)
360
+ (h₅ : b + c = 2 ^ m)
361
+ (hkm : m < k)
362
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
363
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a)) :
364
+ b + a = 2 ^ (m - 1) := by
365
+ have h₇₁: ∃ y z, y ∣ b - a ∧ z ∣ b + a ∧ y * z = 2 ^ m := by
366
+ exact Nat.dvd_mul.mp h₇
367
+ let ⟨p, q, hpd⟩ := h₇₁
368
+ cases' hpd with hpd hqd
369
+ cases' hqd with hqd hpq
370
+ have hm1: 1 ≤ m := by
371
+ by_contra! hc
372
+ interval_cases m
373
+ linarith
374
+ have h₈₀: b - a < 2 ^ (m - 1) := by
375
+ have g₀: b < (b + c) / 2 := by
376
+ refine (Nat.lt_div_iff_mul_lt' ?_ b).mpr ?_
377
+ . refine even_iff_two_dvd.mp ?_
378
+ exact Odd.add_odd h₁.2.1 h₁.2.2.1
379
+ . linarith
380
+ have g₁: (b + c) / 2 = 2 ^ (m-1) := by
381
+ rw [h₅]
382
+ rw [← Nat.pow_sub_mul_pow 2 hm1]
383
+ simp
384
+ rw [← g₁]
385
+ refine lt_trans ?_ g₀
386
+ exact Nat.sub_lt h₀.2.1 h₀.1
387
+ have hp: p = 2 := by
388
+ have hp₀: 2 * b < 2 ^ m := by
389
+ rw [← h₅, two_mul]
390
+ exact Nat.add_lt_add_left h₂.2.1 b
391
+ have hp₁: b + a < 2 ^ (m) := by
392
+ have g₀: b + a < b + b := by
393
+ exact Nat.add_lt_add_left h₂.1 b
394
+ refine Nat.lt_trans g₀ ?_
395
+ rw [← two_mul]
396
+ exact hp₀
397
+ have hp₂: q < 2 ^ m := by
398
+ refine Nat.lt_of_le_of_lt (Nat.le_of_dvd ?_ hqd) hp₁
399
+ exact Nat.add_pos_right b h₀.1
400
+ have hp₃: 1 < p := by
401
+ rw [← hpq] at hp₂
402
+ exact one_lt_of_lt_mul_left hp₂
403
+ have h2prime: Nat.Prime 2 := by exact prime_two
404
+ have hp₅: ∀ i j:ℕ , 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (i < 2 ∨ j < 2) := by
405
+ by_contra! hc
406
+ let ⟨i, j, hi⟩ := hc
407
+ have hti: 2 ^ 2 ∣ 2 ^ i := by exact Nat.pow_dvd_pow 2 hi.2.1
408
+ have htj: 2 ^ 2 ∣ 2 ^ j := by exact Nat.pow_dvd_pow 2 hi.2.2
409
+ norm_num at hti htj
410
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
411
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
412
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
413
+ have hi₇: 2 ∣ b := by
414
+ have g₀: 0 < 2 := by norm_num
415
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
416
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
417
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
418
+ exact hi₆
419
+ have hi₈: Even b := by
420
+ exact even_iff_two_dvd.mpr hi₇
421
+ apply Nat.not_odd_iff_even.mpr hi₈
422
+ exact h₁.2.1
423
+ have hp₆: ∀ i j:ℕ , i + j = m ∧ 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (¬ j < 2) := by
424
+ by_contra! hc
425
+ let ⟨i, j, hi⟩ := hc
426
+ have hi₀: m - 1 ≤ i := by
427
+ rw [← hi.1.1]
428
+ simp
429
+ exact Nat.le_pred_of_lt hi.2
430
+ have hi₁: 2 ^ (m - 1) ≤ 2 ^ i := by exact Nat.pow_le_pow_right (by norm_num) hi₀
431
+ have hi₂: 2 ^ i < 2 ^ (m - 1) := by
432
+ refine lt_of_le_of_lt ?_ h₈₀
433
+ refine Nat.le_of_dvd ?_ hi.1.2.1
434
+ exact Nat.sub_pos_of_lt h₂.1
435
+ -- j must be ≤ 1 which gives i ≥ m - 1
436
+ -- however from h₈₀ we have i < m - 1 leading to a contradiction
437
+ linarith [hi₁, hi₂]
438
+ have hi₀: ∃ i ≤ m, p = 2 ^ i := by
439
+ have g₀: p ∣ 2 ^ m := by
440
+ rw [← hpq]
441
+ exact Nat.dvd_mul_right p q
442
+ exact (Nat.dvd_prime_pow h2prime).mp g₀
443
+ let ⟨i, hp⟩ := hi₀
444
+ cases' hp with him hp
445
+ let j:ℕ := m - i
446
+ have hj₀: j = m - i := by linarith
447
+ have hj₁: i + j = m := by
448
+ rw [add_comm, ← Nat.sub_add_cancel him]
449
+ have hq: q = 2 ^ j := by
450
+ rw [hp] at hpq
451
+ rw [hj₀, ← Nat.pow_div him (by norm_num)]
452
+ refine Nat.eq_div_of_mul_eq_right ?_ hpq
453
+ refine Nat.ne_of_gt ?_
454
+ rw [← hp]
455
+ linarith [hp₃]
456
+ rw [hp] at hpd
457
+ rw [hq] at hqd
458
+ have hj₃: ¬ j < 2 := by
459
+ exact hp₆ i j {left:= hj₁ , right:= { left := hpd , right:= hqd} }
460
+ have hi₂: i < 2 := by
461
+ have g₀: i < 2 ∨ j < 2 := by
462
+ exact hp₅ i j { left := hpd , right:= hqd }
463
+ omega
464
+ have hi₃: 0 < i := by
465
+ rw [hp] at hp₃
466
+ refine Nat.zero_lt_of_ne_zero ?_
467
+ exact (Nat.one_lt_two_pow_iff).mp hp₃
468
+ have hi₄: i = 1 := by
469
+ interval_cases i
470
+ rfl
471
+ rw [hi₄] at hp
472
+ exact hp
473
+ have hq: q = 2 ^ (m - 1) := by
474
+ rw [hp, ← Nat.pow_sub_mul_pow 2 hm1, pow_one, mul_comm] at hpq
475
+ exact Nat.mul_right_cancel (by norm_num) hpq
476
+ rw [hq] at hqd
477
+ have h₈₂: ∃ c, (b + a) = c * 2 ^ (m - 1) := by
478
+ exact exists_eq_mul_left_of_dvd hqd
479
+ let ⟨f, hf⟩ := h₈₂
480
+ have hfeq1: f = 1 := by
481
+ have hf₀: f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1) := by
482
+ rw [← hf, ← Nat.pow_succ', ← Nat.succ_sub hm1]
483
+ rw [Nat.succ_sub_one, ← h₅]
484
+ refine Nat.add_lt_add_left ?_ b
485
+ exact lt_trans h₂.1 h₂.2.1
486
+ have hf₁: f < 2 := by
487
+ exact Nat.lt_of_mul_lt_mul_right hf₀
488
+ interval_cases f
489
+ . simp at hf
490
+ exfalso
491
+ linarith [hf]
492
+ . linarith
493
+ rw [hfeq1, one_mul] at hf
494
+ exact hf
495
+
496
+
497
+ lemma imo_1984_p6_10_1
498
+ (a b c d m : ℕ)
499
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
500
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
501
+ (h₂ : a < b ∧ b < c ∧ c < d)
502
+ (h₅ : b + c = 2 ^ m)
503
+ -- hkm : m < k
504
+ -- h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a)
505
+ -- h₇ : 2 ^ m ∣ (b - a) * (b + a)
506
+ -- h₇₁ : ∃ y z, y ∣ b - a ∧ z ∣ b + a ∧ y * z = 2 ^ m
507
+ -- p q : ℕ
508
+ -- hpd : p ∣ b - a
509
+ -- hqd : q ∣ b + a
510
+ -- hpq : p * q = 2 ^ m
511
+ (hm1 : 1 ≤ m) :
512
+ b - a < 2 ^ (m - 1) := by
513
+ have g₀: b < (b + c) / 2 := by
514
+ refine (Nat.lt_div_iff_mul_lt' ?_ b).mpr ?_
515
+ . refine even_iff_two_dvd.mp ?_
516
+ exact Odd.add_odd h₁.2.1 h₁.2.2.1
517
+ . linarith
518
+ have g₁: (b + c) / 2 = 2 ^ (m-1) := by
519
+ rw [h₅]
520
+ rw [← Nat.pow_sub_mul_pow 2 hm1]
521
+ simp
522
+ rw [← g₁]
523
+ refine lt_trans ?_ g₀
524
+ exact Nat.sub_lt h₀.2.1 h₀.1
525
+
526
+
527
+ lemma imo_1984_p6_10_2
528
+ (b c: ℕ)
529
+ (h₁ : Odd b ∧ Odd c)
530
+ (h₂ : b < c) :
531
+ b < (b + c) / 2 := by
532
+ refine (Nat.lt_div_iff_mul_lt' ?_ b).mpr ?_
533
+ . refine even_iff_two_dvd.mp ?_
534
+ exact Odd.add_odd h₁.1 h₁.2
535
+ . linarith
536
+
537
+ lemma imo_1984_p6_10_3
538
+ (b c m : ℕ)
539
+ (h₅ : b + c = 2 ^ m)
540
+ (hm1 : 1 ≤ m) :
541
+ (b + c) / 2 = 2 ^ (m - 1) := by
542
+ rw [h₅]
543
+ rw [← Nat.pow_sub_mul_pow 2 hm1]
544
+ simp
545
+
546
+
547
+ lemma imo_1984_p6_10_4
548
+ (a b c m : ℕ)
549
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
550
+ (g₀ : b < (b + c) / 2)
551
+ (g₁ : (b + c) / 2 = 2 ^ (m - 1)) :
552
+ b - a < 2 ^ (m - 1) := by
553
+ rw [← g₁]
554
+ refine lt_trans ?_ g₀
555
+ exact Nat.sub_lt h₀.2.1 h₀.1
556
+
557
+ lemma imo_1984_p6_10_5
558
+ (a b c m : ℕ)
559
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
560
+ (h₅ : b + c = 2 ^ m) :
561
+ 1 ≤ m := by
562
+ by_contra! hc
563
+ interval_cases m
564
+ linarith
565
+
566
+
567
+ lemma imo_1984_p6_10_6
568
+ (a b c m : ℕ)
569
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
570
+ (h₁ : Odd a ∧ Odd b ∧ Odd c)
571
+ (h₂ : a < b ∧ b < c)
572
+ (h₅ : b + c = 2 ^ m)
573
+ (p q : ℕ)
574
+ (hpd : p ∣ b - a)
575
+ (hqd : q ∣ b + a)
576
+ (hpq : p * q = 2 ^ m)
577
+ (h₈₀ : b - a < 2 ^ (m - 1)) :
578
+ p = 2 := by
579
+ have hp₀: 2 * b < 2 ^ m := by
580
+ rw [← h₅, two_mul]
581
+ exact Nat.add_lt_add_left h₂.2 b
582
+ have hp₁: b + a < 2 ^ (m) := by
583
+ have g₀: b + a < b + b := by
584
+ exact Nat.add_lt_add_left h₂.1 b
585
+ refine Nat.lt_trans g₀ ?_
586
+ rw [← two_mul]
587
+ exact hp₀
588
+ have hp₂: q < 2 ^ m := by
589
+ refine Nat.lt_of_le_of_lt (Nat.le_of_dvd ?_ hqd) hp₁
590
+ exact Nat.add_pos_right b h₀.1
591
+ have hp₃: 1 < p := by
592
+ rw [← hpq] at hp₂
593
+ exact one_lt_of_lt_mul_left hp₂
594
+ have h2prime: Nat.Prime 2 := by exact prime_two
595
+ have hp₅: ∀ i j:ℕ , 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (i < 2 ∨ j < 2) := by
596
+ by_contra! hc
597
+ let ⟨i, j, hi⟩ := hc
598
+ have hti: 2 ^ 2 ∣ 2 ^ i := by exact Nat.pow_dvd_pow 2 hi.2.1
599
+ have htj: 2 ^ 2 ∣ 2 ^ j := by exact Nat.pow_dvd_pow 2 hi.2.2
600
+ norm_num at hti htj
601
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
602
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
603
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
604
+ have hi₇: 2 ∣ b := by
605
+ have g₀: 0 < 2 := by norm_num
606
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
607
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
608
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
609
+ exact hi₆
610
+ have hi₈: Even b := by
611
+ exact even_iff_two_dvd.mpr hi₇
612
+ apply Nat.not_odd_iff_even.mpr hi₈
613
+ exact h₁.2.1
614
+ have hp₆: ∀ i j:ℕ , i + j = m ∧ 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (¬ j < 2) := by
615
+ by_contra! hc
616
+ let ⟨i, j, hi⟩ := hc
617
+ have hi₀: m - 1 ≤ i := by
618
+ rw [← hi.1.1]
619
+ simp
620
+ exact Nat.le_pred_of_lt hi.2
621
+ have hi₁: 2 ^ (m - 1) ≤ 2 ^ i := by exact Nat.pow_le_pow_right (by norm_num) hi₀
622
+ have hi₂: 2 ^ i < 2 ^ (m - 1) := by
623
+ refine lt_of_le_of_lt ?_ h₈₀
624
+ refine Nat.le_of_dvd ?_ hi.1.2.1
625
+ exact Nat.sub_pos_of_lt h₂.1
626
+ -- j must be ≤ 1 which gives i ≥ m - 1
627
+ -- however from h₈₀ we have i < m - 1 leading to a contradiction
628
+ linarith [hi₁, hi₂]
629
+ have hi₀: ∃ i ≤ m, p = 2 ^ i := by
630
+ have g₀: p ∣ 2 ^ m := by
631
+ rw [← hpq]
632
+ exact Nat.dvd_mul_right p q
633
+ exact (Nat.dvd_prime_pow h2prime).mp g₀
634
+ let ⟨i, hp⟩ := hi₀
635
+ cases' hp with him hp
636
+ let j:ℕ := m - i
637
+ have hj₀: j = m - i := by linarith
638
+ have hj₁: i + j = m := by
639
+ rw [add_comm, ← Nat.sub_add_cancel him]
640
+ have hq: q = 2 ^ j := by
641
+ rw [hp] at hpq
642
+ rw [hj₀, ← Nat.pow_div him (by norm_num)]
643
+ refine Nat.eq_div_of_mul_eq_right ?_ hpq
644
+ refine Nat.ne_of_gt ?_
645
+ rw [← hp]
646
+ linarith [hp₃]
647
+ rw [hp] at hpd
648
+ rw [hq] at hqd
649
+ have hj₃: ¬ j < 2 := by
650
+ exact hp₆ i j {left:= hj₁ , right:= { left := hpd , right:= hqd} }
651
+ have hi₂: i < 2 := by
652
+ have g₀: i < 2 ∨ j < 2 := by
653
+ exact hp₅ i j { left := hpd , right:= hqd }
654
+ omega
655
+ have hi₃: 0 < i := by
656
+ rw [hp] at hp₃
657
+ refine Nat.zero_lt_of_ne_zero ?_
658
+ exact (Nat.one_lt_two_pow_iff).mp hp₃
659
+ have hi₄: i = 1 := by
660
+ interval_cases i
661
+ rfl
662
+ rw [hi₄] at hp
663
+ exact hp
664
+
665
+ lemma imo_1984_p6_10_6_1
666
+ (a b c m : ℕ)
667
+ (h₂ : a < b ∧ b < c)
668
+ (h₅ : b + c = 2 ^ m) :
669
+ 2 * b < 2 ^ m := by
670
+ rw [← h₅, two_mul]
671
+ exact Nat.add_lt_add_left h₂.2 b
672
+
673
+
674
+ lemma imo_1984_p6_10_6_2
675
+ (a b c m : ℕ)
676
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c
677
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c
678
+ (h₂ : a < b ∧ b < c)
679
+ -- h₅ : b + c = 2 ^ m
680
+ -- p q : ℕ
681
+ -- hpd : p ∣ b - a
682
+ -- hqd : q ∣ b + a
683
+ -- hpq : p * q = 2 ^ m
684
+ -- h₈₀ : b - a < 2 ^ (m - 1)
685
+ (hp₀ : 2 * b < 2 ^ m) :
686
+ b + a < 2 ^ m := by
687
+ have g₀: b + a < b + b := by
688
+ exact Nat.add_lt_add_left h₂.1 b
689
+ refine Nat.lt_trans g₀ ?_
690
+ rw [← two_mul]
691
+ exact hp₀
692
+
693
+ lemma imo_1984_p6_10_6_3
694
+ -- (a b c m : ℕ)
695
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c
696
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c
697
+ -- h₂ : a < b ∧ b < c
698
+ -- h₅ : b + c = 2 ^ m
699
+ (m p q : ℕ)
700
+ -- hpd : p ∣ b - a
701
+ -- hqd : q ∣ b + a
702
+ (hpq : p * q = 2 ^ m)
703
+ -- h₈₀ : b - a < 2 ^ (m - 1)
704
+ -- hp₀ : 2 * b < 2 ^ m
705
+ -- hp₁ : b + a < 2 ^ m
706
+ (hp₂ : q < 2 ^ m) :
707
+ 1 < p := by
708
+ rw [← hpq] at hp₂
709
+ exact one_lt_of_lt_mul_left hp₂
710
+
711
+
712
+ lemma imo_1984_p6_10_6_4
713
+ (a b: ℕ)
714
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c
715
+ (h₁ : Odd a ∧ Odd b)
716
+ (h₂ : a < b) :
717
+ -- h₅ : b + c = 2 ^ m
718
+ -- p q : ℕ
719
+ -- hpd : p ∣ b - a
720
+ -- hqd : q ∣ b + a
721
+ -- hpq : p * q = 2 ^ m
722
+ -- h₈₀ : b - a < 2 ^ (m - 1)
723
+ -- hp₀ : 2 * b < 2 ^ m
724
+ -- hp₁ : b + a < 2 ^ m
725
+ -- hp₂ : q < 2 ^ m
726
+ -- hp₃ : 1 < p
727
+ -- h2prime : Nat.Prime 2
728
+ ∀ (i j : ℕ), 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → i < 2 ∨ j < 2 := by
729
+ by_contra! hc
730
+ let ⟨i, j, hi⟩ := hc
731
+ have hti: 2 ^ 2 ∣ 2 ^ i := by exact Nat.pow_dvd_pow 2 hi.2.1
732
+ have htj: 2 ^ 2 ∣ 2 ^ j := by exact Nat.pow_dvd_pow 2 hi.2.2
733
+ norm_num at hti htj
734
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
735
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
736
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
737
+ have hi₇: 2 ∣ b := by
738
+ have g₀: 0 < 2 := by norm_num
739
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
740
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
741
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂)]
742
+ exact hi₆
743
+ have hi₈: Even b := by
744
+ exact even_iff_two_dvd.mpr hi₇
745
+ apply Nat.not_odd_iff_even.mpr hi₈
746
+ exact h₁.2
747
+
748
+ lemma imo_1984_p6_10_6_5
749
+ (a b c : ℕ)
750
+ (h₁ : Odd a ∧ Odd b ∧ Odd c)
751
+ (h₂ : a < b ∧ b < c)
752
+ -- (hc : ∃ i j, (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j)
753
+ (i j : ℕ)
754
+ (hi : (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j)
755
+ (hti : 4 ∣ 2 ^ i)
756
+ (htj : 4 ∣ 2 ^ j) :
757
+ False := by
758
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
759
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
760
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
761
+ have hi₇: 2 ∣ b := by
762
+ have g₀: 0 < 2 := by norm_num
763
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
764
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
765
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
766
+ exact hi₆
767
+ have hi₈: Even b := by
768
+ exact even_iff_two_dvd.mpr hi₇
769
+ apply Nat.not_odd_iff_even.mpr hi₈
770
+ exact h₁.2.1
771
+
772
+ lemma imo_1984_p6_10_6_6
773
+ (a b: ℕ)
774
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c)
775
+ -- (h₂ : a < b ∧ b < c)
776
+ -- hc : ∃ i j, (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
777
+ (i j : ℕ)
778
+ (hi : (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j)
779
+ (hti : 4 ∣ 2 ^ i)
780
+ (htj : 4 ∣ 2 ^ j) :
781
+ 4 ∣ b - a + (b + a) := by
782
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
783
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
784
+ exact Nat.dvd_add hi₄ hi₅
785
+
786
+
787
+ lemma imo_1984_p6_10_6_7
788
+ (a b c : ℕ)
789
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c)
790
+ (h₂ : a < b ∧ b < c)
791
+ -- hc : ∃ i j, (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
792
+ (i j : ℕ)
793
+ (hi : (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j)
794
+ (hti : 4 ∣ 2 ^ i)
795
+ (htj : 4 ∣ 2 ^ j) :
796
+ 2 ∣ b := by
797
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
798
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
799
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
800
+ have g₀: 0 < 2 := by norm_num
801
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
802
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
803
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
804
+ exact hi₆
805
+
806
+
807
+ lemma imo_1984_p6_10_6_8
808
+ (a b c : ℕ)
809
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c)
810
+ (h₂ : a < b ∧ b < c)
811
+ -- hc : ∃ i j, (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
812
+ -- i j : ℕ
813
+ -- hi : (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
814
+ -- hti : 4 ∣ 2 ^ i
815
+ -- htj : 4 ∣ 2 ^ j
816
+ -- (hi₄ : 4 ∣ b - a)
817
+ -- (hi₅ : 4 ∣ b + a)
818
+ (hi₆ : 4 ∣ b - a + (b + a)) :
819
+ 2 ∣ b := by
820
+ have g₀: 0 < 2 := by norm_num
821
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
822
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
823
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
824
+ exact hi₆
825
+
826
+ lemma imo_1984_p6_10_6_9
827
+ (a b c : ℕ)
828
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c)
829
+ (h₂ : a < b ∧ b < c)
830
+ -- hc : ∃ i j, (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
831
+ -- i j : ℕ
832
+ -- hi : (2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ 2 ≤ i ∧ 2 ≤ j
833
+ -- hti : 4 ∣ 2 ^ i
834
+ -- htj : 4 ∣ 2 ^ j
835
+ -- (hi₄ : 4 ∣ b - a)
836
+ -- (hi₅ : 4 ∣ b + a)
837
+ (hi₆ : 4 ∣ b - a + (b + a)) :
838
+ Even b := by
839
+ refine even_iff_two_dvd.mpr ?_
840
+ have g₀: 0 < 2 := by norm_num
841
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
842
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
843
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
844
+ exact hi₆
845
+
846
+ lemma imo_1984_p6_10_6_10
847
+ (a b m : ℕ)
848
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c
849
+ -- (h₁ : Odd a ∧ Odd b)
850
+ (h₂ : a < b)
851
+ -- (a b c m : ℕ)
852
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c
853
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c
854
+ -- h₂ : a < b ∧ b < c
855
+ -- h₅ : b + c = 2 ^ m
856
+ -- p q : ℕ
857
+ -- hpd : p ∣ b - a
858
+ -- hqd : q ∣ b + a
859
+ -- hpq : p * q = 2 ^ m
860
+ (h₈₀ : b - a < 2 ^ (m - 1)) :
861
+ -- hp₀ : 2 * b < 2 ^ m
862
+ -- hp₁ : b + a < 2 ^ m
863
+ -- hp₂ : q < 2 ^ m
864
+ -- hp₃ : 1 < p
865
+ -- h2prime : Nat.Prime 2
866
+ -- hp₅ : ∀ (i j : ℕ), 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → i < 2 ∨ j < 2
867
+ ∀ (i j : ℕ), i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → ¬j < 2 := by
868
+ by_contra! hc
869
+ let ⟨i, j, hi⟩ := hc
870
+ have hi₀: m - 1 ≤ i := by
871
+ rw [← hi.1.1]
872
+ simp
873
+ exact Nat.le_pred_of_lt hi.2
874
+ have hi₁: 2 ^ (m - 1) ≤ 2 ^ i := by exact Nat.pow_le_pow_right (by norm_num) hi₀
875
+ have hi₂: 2 ^ i < 2 ^ (m - 1) := by
876
+ refine lt_of_le_of_lt ?_ h₈₀
877
+ refine Nat.le_of_dvd ?_ hi.1.2.1
878
+ exact Nat.sub_pos_of_lt h₂
879
+ linarith [hi₁, hi₂]
880
+
881
+
882
+ lemma imo_1984_p6_10_6_11
883
+ (m a b : ℕ)
884
+ -- h₁ : Odd a ∧ Odd b
885
+ -- h₂ : a < b
886
+ -- h₈₀ : b - a < 2 ^ (m - 1)
887
+ -- hc : ∃ i j, (i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ j < 2
888
+ (i j : ℕ)
889
+ (hi : (i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ j < 2) :
890
+ 2 ^ (m - 1) ≤ 2 ^ i := by
891
+ refine Nat.pow_le_pow_right (by norm_num) ?_
892
+ rw [← hi.1.1]
893
+ simp
894
+ exact Nat.le_pred_of_lt hi.2
895
+
896
+
897
+ lemma imo_1984_p6_10_6_12
898
+ (m a b : ℕ)
899
+ -- h₁ : Odd a ∧ Odd b
900
+ (h₂ : a < b)
901
+ (h₈₀ : b - a < 2 ^ (m - 1))
902
+ -- hc : ∃ i j, (i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ j < 2
903
+ (i j : ℕ)
904
+ (hi : (i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a) ∧ j < 2) :
905
+ -- hi₀ : m - 1 ≤ i
906
+ -- (hi₁ : 2 ^ (m - 1) ≤ 2 ^ i) :
907
+ 2 ^ i < 2 ^ (m - 1) := by
908
+ refine lt_of_le_of_lt ?_ h₈₀
909
+ refine Nat.le_of_dvd ?_ hi.1.2.1
910
+ exact Nat.sub_pos_of_lt h₂
911
+
912
+
913
+
914
+ lemma imo_1984_p6_10_6_13
915
+ -- (a b c : ℕ)
916
+ (m p q : ℕ)
917
+ (hpq : p * q = 2 ^ m)
918
+ -- h₈₀ : b - a < 2 ^ (m - 1)
919
+ -- hp₀ : 2 * b < 2 ^ m
920
+ -- hp₁ : b + a < 2 ^ m
921
+ -- hp₂ : q < 2 ^ m
922
+ -- hp₃ : 1 < p
923
+ (h2prime : Nat.Prime 2) :
924
+ -- hp₅ : ∀ (i j : ℕ), 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → i < 2 ∨ j < 2
925
+ -- hp₆ : ∀ (i j : ℕ), i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → ¬j < 2
926
+ ∃ i ≤ m, p = 2 ^ i := by
927
+ have g₀: p ∣ 2 ^ m := by
928
+ rw [← hpq]
929
+ exact Nat.dvd_mul_right p q
930
+ exact (Nat.dvd_prime_pow h2prime).mp g₀
931
+
932
+
933
+ lemma imo_1984_p6_10_6_14
934
+ (i m : ℕ)
935
+ (him : i ≤ m)
936
+ (j : ℕ := m - i)
937
+ (hj₀ : j = m - i) :
938
+ i + j = m := by
939
+ rw [add_comm, hj₀]
940
+ exact Nat.sub_add_cancel him
941
+
942
+
943
+ lemma imo_1984_p6_10_6_15
944
+ (p q m j : ℕ)
945
+ (hpq : p * q = 2 ^ m)
946
+ (i : ℕ)
947
+ (him : i ≤ m)
948
+ (hp : p = 2 ^ i)
949
+ (hj₀ : j = m - i) :
950
+ q = 2 ^ j := by
951
+ rw [hp] at hpq
952
+ rw [hj₀, ← Nat.pow_div him (by norm_num)]
953
+ refine Nat.eq_div_of_mul_eq_right ?_ hpq
954
+ refine Nat.ne_of_gt ?_
955
+ exact Nat.two_pow_pos i
956
+
957
+
958
+ lemma imo_1984_p6_10_6_16
959
+ (a b p q m : ℕ)
960
+ (hp₃ : 1 < p)
961
+ (hp₅ : ∀ (i j : ℕ), 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → i < 2 ∨ j < 2)
962
+ (hp₆ : ∀ (i j : ℕ), i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → ¬j < 2)
963
+ (i j : ℕ)
964
+ (hp : p = 2 ^ i)
965
+ (hq : q = 2 ^ j)
966
+ (hpd : 2 ^ i ∣ b - a)
967
+ (hqd : 2 ^ j ∣ b + a)
968
+ (hij : i + j = m) :
969
+ p = 2 := by
970
+ have hj₃: ¬ j < 2 := by
971
+ exact hp₆ i j {left:= hij , right:= { left := hpd , right:= hqd} }
972
+ have hi₂: i < 2 := by
973
+ have g₀: i < 2 ∨ j < 2 := by
974
+ exact hp₅ i j { left := hpd , right:= hqd }
975
+ omega
976
+ have hi₃: 0 < i := by
977
+ rw [hp] at hp₃
978
+ refine Nat.zero_lt_of_ne_zero ?_
979
+ exact (Nat.one_lt_two_pow_iff).mp hp₃
980
+ have hi₄: i = 1 := by
981
+ exact Nat.eq_of_le_of_lt_succ hi₃ hi₂
982
+ rw [hi₄] at hp
983
+ exact hp
984
+
985
+
986
+
987
+ lemma imo_1984_p6_10_6_17
988
+ (a b m : ℕ)
989
+ (hp₆ : ∀ (i j : ℕ), i + j = m ∧ 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → ¬j < 2)
990
+ (i j : ℕ)
991
+ (hpd : 2 ^ i ∣ b - a)
992
+ (hqd : 2 ^ j ∣ b + a)
993
+ (hij : i + j = m) :
994
+ ¬j < 2 := by
995
+ exact hp₆ i j {left:= hij , right:= { left := hpd , right:= hqd} }
996
+
997
+
998
+
999
+ lemma imo_1984_p6_10_6_18
1000
+ (a b : ℕ)
1001
+ (hp₅ : ∀ (i j : ℕ), 2 ^ i ∣ b - a ∧ 2 ^ j ∣ b + a → i < 2 ∨ j < 2)
1002
+ (i j : ℕ)
1003
+ (hpd : 2 ^ i ∣ b - a)
1004
+ (hqd : 2 ^ j ∣ b + a)
1005
+ (hj : ¬j < 2) :
1006
+ i < 2 := by
1007
+ have g₀: i < 2 ∨ j < 2 := by
1008
+ exact hp₅ i j { left := hpd , right:= hqd }
1009
+ omega
1010
+
1011
+ lemma imo_1984_p6_10_6_19
1012
+ (p i : ℕ)
1013
+ (hp₃ : 1 < p)
1014
+ (hp : p = 2 ^ i) :
1015
+ 0 < i := by
1016
+ rw [hp] at hp₃
1017
+ refine Nat.zero_lt_of_ne_zero ?_
1018
+ exact (Nat.one_lt_two_pow_iff).mp hp₃
1019
+
1020
+
1021
+ lemma imo_1984_p6_10_6_20
1022
+ (p q i j m a b : ℕ)
1023
+ (hp : p = 2 ^ i)
1024
+ (hq : q = 2 ^ j)
1025
+ (hpd : 2 ^ i ∣ b - a)
1026
+ (hqd : 2 ^ j ∣ b + a)
1027
+ (hij : i + j = m)
1028
+ (hj₃ : ¬j < 2)
1029
+ (hi₂ : i < 2)
1030
+ (hi₃ : 0 < i) :
1031
+ p = 2 := by
1032
+ suffices hi: i = 1
1033
+ . rw [hi] at hp
1034
+ exact hp
1035
+ . exact Nat.eq_of_le_of_lt_succ hi₃ hi₂
1036
+
1037
+
1038
+ lemma imo_1984_p6_10_7
1039
+ (m p q : ℕ)
1040
+ (hpq : p * q = 2 ^ m)
1041
+ (hm1 : 1 ≤ m)
1042
+ (hp : p = 2) :
1043
+ q = 2 ^ (m - 1) := by
1044
+ rw [hp, ← Nat.pow_sub_mul_pow 2 hm1, pow_one, mul_comm] at hpq
1045
+ exact Nat.mul_right_cancel (by norm_num) hpq
1046
+
1047
+
1048
+ lemma imo_1984_p6_10_8
1049
+ (a b c m : ℕ)
1050
+ -- h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d
1051
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d
1052
+ (h₂ : a < b ∧ b < c)
1053
+ (h₅ : b + c = 2 ^ m)
1054
+ -- hkm : m < k
1055
+ -- h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a)
1056
+ -- h₇ : 2 ^ m ∣ (b - a) * (b + a)
1057
+ -- h₇₁ : ∃ y z, y ∣ b - a ∧ z ∣ b + a ∧ y * z = 2 ^ m
1058
+ (q : ℕ)
1059
+ -- (hpd : p ∣ b - a)
1060
+ (hqd : q ∣ b + a)
1061
+ -- (hpq : p * q = 2 ^ m)
1062
+ (hm1 : 1 ≤ m)
1063
+ (h₈₀ : b - a < 2 ^ (m - 1))
1064
+ -- (hp : p = 2)
1065
+ (hq : q = 2 ^ (m - 1)) :
1066
+ b + a = 2 ^ (m - 1) := by
1067
+ rw [hq] at hqd
1068
+ have h₈₂: ∃ c, (b + a) = c * 2 ^ (m - 1) := by
1069
+ exact exists_eq_mul_left_of_dvd hqd
1070
+ obtain ⟨f, hf⟩ := h₈₂
1071
+ have hfeq1: f = 1 := by
1072
+ have hf₀: f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1) := by
1073
+ rw [← hf, ← Nat.pow_succ', ← Nat.succ_sub hm1]
1074
+ rw [Nat.succ_sub_one, ← h₅]
1075
+ refine Nat.add_lt_add_left ?_ b
1076
+ exact lt_trans h₂.1 h₂.2
1077
+ have hf₁: f < 2 := by
1078
+ exact Nat.lt_of_mul_lt_mul_right hf₀
1079
+ interval_cases f
1080
+ . simp at hf
1081
+ exfalso
1082
+ linarith [hf]
1083
+ . linarith
1084
+ rw [hfeq1, one_mul] at hf
1085
+ exact hf
1086
+
1087
+
1088
+ lemma imo_1984_p6_10_8_1
1089
+ (a b m q: ℕ)
1090
+ (hqd : q ∣ b + a)
1091
+ (hq : q = 2 ^ (m - 1)) :
1092
+ ∃ c, b + a = c * 2 ^ (m - 1) := by
1093
+ refine exists_eq_mul_left_of_dvd ?_
1094
+ rw [hq] at hqd
1095
+ exact hqd
1096
+
1097
+
1098
+ lemma imo_1984_p6_10_8_2
1099
+ (a b c m : ℕ)
1100
+ (h₂ : a < b ∧ b < c)
1101
+ (h₅ : b + c = 2 ^ m)
1102
+ (hm1 : 1 ≤ m)
1103
+ (f : ℕ)
1104
+ (hf : b + a = f * 2 ^ (m - 1)) :
1105
+ f = 1 := by
1106
+ have hf₀: f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1) := by
1107
+ rw [← hf, ← Nat.pow_succ', ← Nat.succ_sub hm1]
1108
+ rw [Nat.succ_sub_one, ← h₅]
1109
+ refine Nat.add_lt_add_left ?_ b
1110
+ exact lt_trans h₂.1 h₂.2
1111
+ have hf₁: f < 2 := by
1112
+ exact Nat.lt_of_mul_lt_mul_right hf₀
1113
+ interval_cases f
1114
+ . simp at hf
1115
+ exfalso
1116
+ linarith [hf]
1117
+ . linarith
1118
+
1119
+
1120
+ lemma imo_1984_p6_10_8_3
1121
+ (a b c m : ℕ)
1122
+ (h₂ : a < b ∧ b < c)
1123
+ (h₅ : b + c = 2 ^ m)
1124
+ (hm1 : 1 ≤ m)
1125
+ (f : ℕ)
1126
+ (hf : b + a = f * 2 ^ (m - 1)) :
1127
+ f < 2 := by
1128
+ have hf₀: f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1) := by
1129
+ rw [← hf, ← Nat.pow_succ', ← Nat.succ_sub hm1]
1130
+ rw [Nat.succ_sub_one, ← h₅]
1131
+ refine Nat.add_lt_add_left ?_ b
1132
+ exact lt_trans h₂.1 h₂.2
1133
+ exact Nat.lt_of_mul_lt_mul_right hf₀
1134
+
1135
+
1136
+ lemma imo_1984_p6_10_8_4
1137
+ (a b c m : ℕ)
1138
+ -- (h₀ : 0 < a ∧ 0 < b)
1139
+ (h₂ : a < b ∧ b < c)
1140
+ (f : ℕ)
1141
+ (hf : b + a = f * 2 ^ (m - 1))
1142
+ -- (hf₀ : f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1))
1143
+ (hf₁ : f < 2) :
1144
+ f = 1 := by
1145
+ interval_cases f
1146
+ . simp at hf
1147
+ exfalso
1148
+ linarith [hf]
1149
+ . linarith
1150
+
1151
+
1152
+ lemma imo_1984_p6_11
1153
+ (a b c d k m : ℕ)
1154
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1155
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1156
+ (h₂ : a < b ∧ b < c ∧ c < d)
1157
+ (h₃ : a * d = b * c)
1158
+ -- (h₄ : a + d = 2 ^ k)
1159
+ (h₅ : b + c = 2 ^ m)
1160
+ -- (hkm : m < k)
1161
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1162
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1163
+ (h₈ : b + a = 2 ^ (m - 1)) :
1164
+ a = 2 ^ (2 * m - 2) / 2 ^ k := by
1165
+ have ga: 1 ≤ a := by exact Nat.succ_le_of_lt h₀.1
1166
+ have gb: 3 ≤ b := by
1167
+ by_contra! hc
1168
+ interval_cases b
1169
+ . linarith
1170
+ . linarith [ga, h₂.1]
1171
+ . have hc₁: Odd 2 := by exact h₁.2.1
1172
+ have hc₂: Even 2 := by exact even_iff.mpr rfl
1173
+ have hc₃: ¬ Even 2 := by exact not_even_iff_odd.mpr hc₁
1174
+ exact hc₃ hc₂
1175
+ have gm: 3 ≤ m := by
1176
+ have gm₀: 2 ^ 2 ≤ 2 ^ (m - 1) := by
1177
+ norm_num
1178
+ rw [← h₈]
1179
+ linarith
1180
+ have gm₁: 2 ≤ m - 1 := by
1181
+ exact (Nat.pow_le_pow_iff_right (by norm_num)).mp gm₀
1182
+ omega
1183
+ have g₀: a < 2 ^ (m - 2) := by
1184
+ have g₀₀: a + a < b + a := by simp [h₂.1]
1185
+ rw [h₈, ← mul_two a] at g₀₀
1186
+ have g₀₁: m - 1 = Nat.succ (m - 2) := by
1187
+ rw [← Nat.succ_sub ?_]
1188
+ . rw [succ_eq_add_one]
1189
+ omega
1190
+ . linarith
1191
+ rw [g₀₁, Nat.pow_succ 2 _] at g₀₀
1192
+ exact Nat.lt_of_mul_lt_mul_right g₀₀
1193
+ have h₉₀: b = 2 ^ (m - 1) - a := by
1194
+ symm
1195
+ exact Nat.sub_eq_of_eq_add h₈.symm
1196
+ rw [h₈, h₉₀] at h₆
1197
+ repeat rw [Nat.mul_sub_right_distrib] at h₆
1198
+ repeat rw [← Nat.pow_add] at h₆
1199
+ have hm1: 1 ≤ m := by
1200
+ linarith
1201
+ repeat rw [← Nat.sub_add_comm hm1] at h₆
1202
+ repeat rw [← Nat.add_sub_assoc hm1] at h₆
1203
+ ring_nf at h₆
1204
+ rw [← Nat.sub_add_eq _ 1 1] at h₆
1205
+ norm_num at h₆
1206
+ rw [← Nat.sub_add_eq _ (a * 2 ^ (m - 1)) (a * 2 ^ (m - 1))] at h₆
1207
+ rw [← two_mul (a * 2 ^ (m - 1))] at h₆
1208
+ rw [mul_comm 2 _] at h₆
1209
+ rw [mul_assoc a (2 ^ (m - 1)) 2] at h₆
1210
+ rw [← Nat.pow_succ, succ_eq_add_one] at h₆
1211
+ rw [Nat.sub_add_cancel hm1] at h₆
1212
+ rw [← Nat.sub_add_eq ] at h₆
1213
+ have h₉₁: 2 ^ (m * 2 - 1) = 2 ^ (m * 2 - 2) - a * 2 ^ m + (a * 2 ^ m + a * 2 ^ k) := by
1214
+ refine Nat.eq_add_of_sub_eq ?_ h₆
1215
+ by_contra! hc
1216
+ have g₁: 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 0 := by
1217
+ exact Nat.sub_eq_zero_of_le (le_of_lt hc)
1218
+ rw [g₁] at h₆
1219
+ have g₂: 2 ^ (m * 2 - 2) ≤ a * 2 ^ m := by exact Nat.le_of_sub_eq_zero h₆.symm
1220
+ have g₃: 2 ^ (m - 2) ≤ a := by
1221
+ rw [mul_two, Nat.add_sub_assoc (by linarith) m] at g₂
1222
+ rw [Nat.pow_add, mul_comm] at g₂
1223
+ refine Nat.le_of_mul_le_mul_right g₂ ?_
1224
+ exact Nat.two_pow_pos m
1225
+ linarith [g₀, g₃]
1226
+ rw [← Nat.add_assoc] at h₉₁
1227
+ have h₉₂: a * 2 ^ k = 2 * 2 ^ (2 * m - 2) - 2 ^ (2 * m - 2) := by
1228
+ rw [Nat.sub_add_cancel ?_] at h₉₁
1229
+ . rw [add_comm] at h₉₁
1230
+ symm
1231
+ rw [← Nat.pow_succ', succ_eq_add_one]
1232
+ rw [← Nat.sub_add_comm ?_]
1233
+ . simp
1234
+ rw [mul_comm 2 m]
1235
+ exact Nat.sub_eq_of_eq_add h₉₁
1236
+ . linarith [hm1]
1237
+ . refine le_of_lt ?_
1238
+ rw [mul_two, Nat.add_sub_assoc, Nat.pow_add, mul_comm (2 ^ m) _]
1239
+ refine (Nat.mul_lt_mul_right (by linarith)).mpr g₀
1240
+ linarith
1241
+ nth_rewrite 2 [← Nat.one_mul (2 ^ (2 * m - 2))] at h₉₂
1242
+ rw [← Nat.mul_sub_right_distrib 2 1 (2 ^ (2 * m - 2))] at h₉₂
1243
+ norm_num at h₉₂
1244
+ refine Nat.eq_div_of_mul_eq_left ?_ h₉₂
1245
+ exact Ne.symm (NeZero.ne' (2 ^ k))
1246
+
1247
+
1248
+ lemma imo_1984_p6_11_1
1249
+ (a b c d: ℕ)
1250
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1251
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1252
+ (h₂ : a < b ∧ b < c ∧ c < d) :
1253
+ -- (h₃ : a * d = b * c)
1254
+ -- (h₅ : b + c = 2 ^ m)
1255
+ -- (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1256
+ -- (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1257
+ -- (h₈ : b + a = 2 ^ (m - 1))
1258
+ 3 ≤ b := by
1259
+ by_contra! hc
1260
+ interval_cases b
1261
+ . linarith
1262
+ . linarith [h₀.1, h₂.1]
1263
+ . have hc₀: Odd 2 := by exact h₁.2.1
1264
+ have hc₁: ¬ Odd 2 := by decide
1265
+ exact hc₁ hc₀
1266
+
1267
+
1268
+ lemma imo_1984_p6_11_2
1269
+ (a b m : ℕ)
1270
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1271
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d
1272
+ -- h₂ : a < b ∧ b < c ∧ c < d
1273
+ -- h₃ : a * d = b * c
1274
+ -- h₅ : b + c = 2 ^ m
1275
+ -- h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a)
1276
+ -- h₇ : 2 ^ m ∣ (b - a) * (b + a)
1277
+ (h₈ : b + a = 2 ^ (m - 1))
1278
+ (ga : 1 ≤ a)
1279
+ (gb : 3 ≤ b) :
1280
+ 3 ≤ m := by
1281
+ have gm₀: 2 ^ 2 ≤ 2 ^ (m - 1) := by
1282
+ norm_num
1283
+ rw [← h₈]
1284
+ linarith
1285
+ have gm₁: 2 ≤ m - 1 := by
1286
+ exact (Nat.pow_le_pow_iff_right (by norm_num)).mp gm₀
1287
+ omega
1288
+
1289
+
1290
+ lemma imo_1984_p6_11_3
1291
+ (a b m : ℕ)
1292
+ (h₂ : a < b)
1293
+ (h₈ : b + a = 2 ^ (m - 1))
1294
+ (gm : 3 ≤ m) :
1295
+ a < 2 ^ (m - 2) := by
1296
+ have g₀₀: a + a < b + a := by simp [h₂]
1297
+ rw [h₈, ← mul_two a] at g₀₀
1298
+ have g₀₁: m - 1 = Nat.succ (m - 2) := by
1299
+ rw [← Nat.succ_sub ?_]
1300
+ . rw [succ_eq_add_one]
1301
+ omega
1302
+ . linarith
1303
+ rw [g₀₁, Nat.pow_succ 2 _] at g₀₀
1304
+ exact Nat.lt_of_mul_lt_mul_right g₀₀
1305
+
1306
+
1307
+ lemma imo_1984_p6_11_4
1308
+ (a b k m : ℕ)
1309
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1310
+ (h₈ : b + a = 2 ^ (m - 1))
1311
+ (h₉ : b = 2 ^ (m - 1) - a)
1312
+ (hm1 : 1 ≤ m) :
1313
+ 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 2 ^ (m * 2 - 2) - a * 2 ^ m := by
1314
+ rw [h₈, h₉] at h₆
1315
+ repeat rw [Nat.mul_sub_right_distrib] at h₆
1316
+ repeat rw [← Nat.pow_add] at h₆
1317
+ repeat rw [← Nat.sub_add_comm hm1] at h₆
1318
+ repeat rw [← Nat.add_sub_assoc hm1] at h₆
1319
+ ring_nf at h₆
1320
+ rw [← Nat.sub_add_eq _ 1 1] at h₆
1321
+ norm_num at h₆
1322
+ rw [← Nat.sub_add_eq _ (a * 2 ^ (m - 1)) (a * 2 ^ (m - 1))] at h₆
1323
+ rw [← two_mul (a * 2 ^ (m - 1))] at h₆
1324
+ rw [mul_comm 2 _] at h₆
1325
+ rw [mul_assoc a (2 ^ (m - 1)) 2] at h₆
1326
+ rw [← Nat.pow_succ, succ_eq_add_one] at h₆
1327
+ rw [Nat.sub_add_cancel hm1] at h₆
1328
+ rw [← Nat.sub_add_eq ] at h₆
1329
+ exact h₆
1330
+
1331
+
1332
+ lemma imo_1984_p6_11_5
1333
+ (a k m : ℕ)
1334
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1335
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1336
+ -- (h₂ : a < b ∧ b < c ∧ c < d)
1337
+ -- (h₃ : a * d = b * c)
1338
+ -- (h₅ : b + c = 2 ^ m)
1339
+ -- (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1340
+ -- (h₈ : b + a = 2 ^ (m - 1))
1341
+ -- (ga : 1 ≤ a)
1342
+ -- (gb : 3 ≤ b)
1343
+ (gm : 3 ≤ m)
1344
+ (g₀ : a < 2 ^ (m - 2))
1345
+ -- (h₉ : b = 2 ^ (m - 1) - a)
1346
+ -- (hm1 : 1 ≤ m)
1347
+ (h₆ : 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 2 ^ (m * 2 - 2) - a * 2 ^ m) :
1348
+ 2 ^ (m * 2 - 1) = 2 ^ (m * 2 - 2) - a * 2 ^ m + (a * 2 ^ m + a * 2 ^ k) := by
1349
+ refine Nat.eq_add_of_sub_eq ?_ h₆
1350
+ by_contra! hc
1351
+ have g₁: 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 0 := by
1352
+ exact Nat.sub_eq_zero_of_le (le_of_lt hc)
1353
+ rw [g₁] at h₆
1354
+ have g₂: 2 ^ (m * 2 - 2) ≤ a * 2 ^ m := by exact Nat.le_of_sub_eq_zero h₆.symm
1355
+ have g₃: 2 ^ (m - 2) ≤ a := by
1356
+ rw [mul_two, Nat.add_sub_assoc (by linarith) m] at g₂
1357
+ rw [Nat.pow_add, mul_comm] at g₂
1358
+ refine Nat.le_of_mul_le_mul_right g₂ ?_
1359
+ exact Nat.two_pow_pos m
1360
+ linarith [g₀, g₃]
1361
+
1362
+
1363
+ lemma imo_1984_p6_11_6
1364
+ (a b c d k m : ℕ)
1365
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1366
+ -- h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d
1367
+ -- h₂ : a < b ∧ b < c ∧ c < d
1368
+ -- h₃ : a * d = b * c
1369
+ (h₅ : b + c = 2 ^ m)
1370
+ -- (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1371
+ -- h₈ : b + a = 2 ^ (m - 1)
1372
+ -- ga : 1 ≤ a
1373
+ -- gb : 3 ≤ b
1374
+ (gm : 3 ≤ m)
1375
+ (g₀ : a < 2 ^ (m - 2))
1376
+ -- h₉₀ : b = 2 ^ (m - 1) - a
1377
+ (hm1 : 1 ≤ m)
1378
+ -- h₆ : 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 2 ^ (m * 2 - 2) - a * 2 ^ m
1379
+ (h₉₁ : 2 ^ (m * 2 - 1) = 2 ^ (m * 2 - 2) - a * 2 ^ m + a * 2 ^ m + a * 2 ^ k) :
1380
+ a * 2 ^ k = 2 * 2 ^ (2 * m - 2) - 2 ^ (2 * m - 2) := by
1381
+ rw [Nat.sub_add_cancel ?_] at h₉₁
1382
+ . rw [add_comm] at h₉₁
1383
+ symm
1384
+ rw [← Nat.pow_succ', succ_eq_add_one]
1385
+ rw [← Nat.sub_add_comm ?_]
1386
+ . simp
1387
+ rw [mul_comm 2 m]
1388
+ exact Nat.sub_eq_of_eq_add h₉₁
1389
+ . linarith [hm1]
1390
+ . refine le_of_lt ?_
1391
+ rw [mul_two, Nat.add_sub_assoc, Nat.pow_add, mul_comm (2 ^ m) _]
1392
+ . refine (Nat.mul_lt_mul_right ?_).mpr g₀
1393
+ linarith
1394
+ . linarith
1395
+
1396
+ lemma imo_1984_p6_11_7
1397
+ (a k m : ℕ)
1398
+ (h₉₂ : a * 2 ^ k = 2 * 2 ^ (2 * m - 2) - 2 ^ (2 * m - 2)) :
1399
+ a = 2 ^ (2 * m - 2) / 2 ^ k := by
1400
+ nth_rewrite 2 [← Nat.one_mul (2 ^ (2 * m - 2))] at h₉₂
1401
+ rw [← Nat.mul_sub_right_distrib 2 1 (2 ^ (2 * m - 2))] at h₉₂
1402
+ norm_num at h₉₂
1403
+ refine Nat.eq_div_of_mul_eq_left ?_ h₉₂
1404
+ exact Ne.symm (NeZero.ne' (2 ^ k))
1405
+
1406
+
1407
+
1408
+ lemma imo_1984_p6_12
1409
+ (a b c d k m : ℕ)
1410
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1411
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1412
+ (h₂ : a < b ∧ b < c ∧ c < d)
1413
+ (h₃ : a * d = b * c)
1414
+ (h₄ : a + d = 2 ^ k)
1415
+ -- (h₅ : b + c = 2 ^ m)
1416
+ -- (hkm : m < k)
1417
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1418
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1419
+ (h₈ : b + a = 2 ^ (m - 1))
1420
+ (h₉ : a = 2 ^ (2 * m - 2) / 2 ^ k) :
1421
+ a = 1 := by
1422
+ by_cases h₁₀: k ≤ 2 * m - 2
1423
+ . rw [Nat.pow_div h₁₀ (by norm_num)] at h₉
1424
+ rw [Nat.sub_right_comm (2*m) 2 k] at h₉
1425
+ by_contra! hc
1426
+ cases' (lt_or_gt_of_ne hc) with hc₀ hc₁
1427
+ . interval_cases a
1428
+ linarith
1429
+ . have hc₂: ¬ Odd a := by
1430
+ refine (not_odd_iff_even).mpr ?_
1431
+ have hc₃: 1 ≤ 2 * m - k - 2 := by
1432
+ by_contra! hc₄
1433
+ interval_cases (2 * m - k - 2)
1434
+ simp at h₉
1435
+ rw [h₉] at hc₁
1436
+ contradiction
1437
+ have hc₄: 2 * m - k - 2 = succ (2 * m - k - 3) := by
1438
+ rw [succ_eq_add_one]
1439
+ exact Nat.eq_add_of_sub_eq hc₃ rfl
1440
+ rw [h₉, hc₄, Nat.pow_succ']
1441
+ exact even_two_mul (2 ^ (2 * m - k - 3))
1442
+ exact hc₂ h₁.1
1443
+ . push_neg at h₁₀
1444
+ exfalso
1445
+ have ha: a = 0 := by
1446
+ rw [h₉]
1447
+ refine (Nat.div_eq_zero_iff).mpr ?_
1448
+ right
1449
+ refine Nat.pow_lt_pow_right ?_ h₁₀
1450
+ exact Nat.one_lt_two
1451
+ linarith [ha, h₀.1]
1452
+
1453
+
1454
+
1455
+ lemma imo_1984_p6_13
1456
+ (a b c d k m : ℕ)
1457
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1458
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1459
+ (h₂ : a < b ∧ b < c ∧ c < d)
1460
+ (h₃ : a * d = b * c)
1461
+ (h₄ : a + d = 2 ^ k)
1462
+ -- (h₅ : b + c = 2 ^ m)
1463
+ -- (hkm : m < k)
1464
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1465
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1466
+ (h₈ : b + a = 2 ^ (m - 1))
1467
+ (h₉ : a = 2 ^ (2 * m - 2) / 2 ^ k)
1468
+ (h₁₀: k ≤ 2 * m - 2) :
1469
+ a = 1 := by
1470
+ rw [Nat.pow_div h₁₀ (by norm_num)] at h₉
1471
+ rw [Nat.sub_right_comm (2*m) 2 k] at h₉
1472
+ by_contra! hc
1473
+ cases' (lt_or_gt_of_ne hc) with hc₀ hc₁
1474
+ . interval_cases a
1475
+ linarith
1476
+ . have hc₂: ¬ Odd a := by
1477
+ refine (not_odd_iff_even).mpr ?_
1478
+ have hc₃: 1 ≤ 2 * m - k - 2 := by
1479
+ by_contra! hc₄
1480
+ interval_cases (2 * m - k - 2)
1481
+ simp at h₉
1482
+ rw [h₉] at hc₁
1483
+ contradiction
1484
+ have hc₄: 2 * m - k - 2 = succ (2 * m - k - 3) := by
1485
+ rw [succ_eq_add_one]
1486
+ exact Nat.eq_add_of_sub_eq hc₃ rfl
1487
+ rw [h₉, hc₄, Nat.pow_succ']
1488
+ exact even_two_mul (2 ^ (2 * m - k - 3))
1489
+ exact hc₂ h₁.1
1490
+
1491
+
1492
+ lemma imo_1984_p6_13_1
1493
+ (a b c d k m : ℕ)
1494
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1495
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1496
+ (h₂ : a < b ∧ b < c ∧ c < d)
1497
+ (h₃ : a * d = b * c)
1498
+ (h₄ : a + d = 2 ^ k)
1499
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1500
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1501
+ (h₈ : b + a = 2 ^ (m - 1))
1502
+ (h₉ : a = 2 ^ (2 * m - k - 2))
1503
+ -- (h₁₀ : k ≤ 2 * m - 2)
1504
+ (hc : a < 1) :
1505
+ False := by
1506
+ interval_cases a
1507
+ linarith
1508
+
1509
+
1510
+ lemma imo_1984_p6_13_2
1511
+ (a b c d k m : ℕ)
1512
+ -- (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
1513
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1514
+ -- (h₂ : a < b ∧ b < c ∧ c < d)
1515
+ -- (h₃ : a * d = b * c)
1516
+ -- (h₄ : a + d = 2 ^ k)
1517
+ -- (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1518
+ -- (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1519
+ -- (h₈ : b + a = 2 ^ (m - 1))
1520
+ (h₉ : a = 2 ^ (2 * m - k - 2))
1521
+ -- (h₁₀ : k ≤ 2 * m - 2)
1522
+ (hc : 1 < a) :
1523
+ False := by
1524
+ have hc₂: ¬ Odd a := by
1525
+ refine (not_odd_iff_even).mpr ?_
1526
+ have hc₃: 1 ≤ 2 * m - k - 2 := by
1527
+ by_contra! hc₄
1528
+ interval_cases (2 * m - k - 2)
1529
+ simp at h₉
1530
+ rw [h₉] at hc
1531
+ contradiction
1532
+ have hc₄: 2 * m - k - 2 = succ (2 * m - k - 3) := by
1533
+ rw [succ_eq_add_one]
1534
+ exact Nat.eq_add_of_sub_eq hc₃ rfl
1535
+ rw [h₉, hc₄, Nat.pow_succ']
1536
+ exact even_two_mul (2 ^ (2 * m - k - 3))
1537
+ exact hc₂ h₁.1
1538
+
1539
+
1540
+ lemma imo_1984_p6_13_3
1541
+ (a k m : ℕ)
1542
+ (h₉ : a = 2 ^ (2 * m - k - 2))
1543
+ (hc : 1 < a) :
1544
+ 1 ≤ 2 * m - k - 2 := by
1545
+ by_contra! hc₄
1546
+ interval_cases (2 * m - k - 2)
1547
+ simp at h₉
1548
+ rw [h₉] at hc
1549
+ contradiction
1550
+
1551
+
1552
+ lemma imo_1984_p6_13_4
1553
+ (a k m : ℕ)
1554
+ (h₉ : a = 2 ^ (2 * m - k - 2))
1555
+ (hc : 1 < a) :
1556
+ Even a := by
1557
+ have hc₃: 1 ≤ 2 * m - k - 2 := by
1558
+ by_contra! hc₄
1559
+ interval_cases (2 * m - k - 2)
1560
+ simp at h₉
1561
+ rw [h₉] at hc
1562
+ contradiction
1563
+ have hc₄: 2 * m - k - 2 = succ (2 * m - k - 3) := by
1564
+ rw [succ_eq_add_one]
1565
+ exact Nat.eq_add_of_sub_eq hc₃ rfl
1566
+ rw [h₉, hc₄, Nat.pow_succ']
1567
+ exact even_two_mul (2 ^ (2 * m - k - 3))
1568
+
1569
+
1570
+ lemma imo_1984_p6_14
1571
+ (a k m : ℕ)
1572
+ (h₀ : 0 < a)
1573
+ -- (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
1574
+ -- (h₂ : a < b ∧ b < c ∧ c < d)
1575
+ -- (h₃ : a * d = b * c)
1576
+ -- (h₄ : a + d = 2 ^ k)
1577
+ -- (h₅ : b + c = 2 ^ m)
1578
+ -- (hkm : m < k)
1579
+ -- (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
1580
+ -- (h₇ : 2 ^ m ∣ (b - a) * (b + a))
1581
+ -- (h₈ : b + a = 2 ^ (m - 1))
1582
+ (h₉ : a = 2 ^ (2 * m - 2) / 2 ^ k)
1583
+ (hk2m : 2 * m - 2 < k) :
1584
+ False := by
1585
+ have ha: a = 0 := by
1586
+ rw [h₉]
1587
+ refine (Nat.div_eq_zero_iff).mpr ?_
1588
+ right
1589
+ exact Nat.pow_lt_pow_right (by norm_num) hk2m
1590
+ linarith [ha, h₀]
1591
+
1592
+
1593
+ lemma imo_1984_p6_15
1594
+ (a k m : ℕ)
1595
+ (h₉ : a = 2 ^ (2 * m - 2) / 2 ^ k)
1596
+ (hk2m : 2 * m - 2 < k) :
1597
+ a = 0 := by
1598
+ rw [h₉]
1599
+ refine (Nat.div_eq_zero_iff).mpr ?_
1600
+ right
1601
+ exact Nat.pow_lt_pow_right (by norm_num) hk2m
Lemmas/imo_1985_p6_lemmas.lean ADDED
The diff for this file is too large to render. See raw diff
 
Lemmas/imo_1992_p1_lemmas.lean ADDED
@@ -0,0 +1,2081 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Int Rat
5
+
6
+
7
+ lemma imo_1992_p1_1
8
+ (p q r: ℤ)
9
+ (hpl: 4 ≤ p)
10
+ (hql: 5 ≤ q)
11
+ (hrl: 6 ≤ r) :
12
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
13
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
14
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) := by
15
+ norm_cast
16
+ simp
17
+ have hp: (↑p/↑(p-1):ℚ) ≤ ((4/3):ℚ) := by
18
+ have g₁: 0 < (↑(p - 1):ℚ) := by
19
+ norm_cast
20
+ linarith [hpl]
21
+ have g₂: ↑p * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(p - 1):ℚ) := by
22
+ norm_cast
23
+ linarith
24
+ refine (div_le_iff₀ g₁).mpr ?_
25
+ rw [div_mul_eq_mul_div]
26
+ refine (le_div_iff₀ ?_).mpr g₂
27
+ norm_num
28
+ have hq: (↑q/↑(q-1)) ≤ ((5/4):ℚ) := by
29
+ have g₁: 0 < (↑(q - 1):ℚ) := by
30
+ norm_cast
31
+ linarith[hql]
32
+ have g₂: ↑q * ↑(4:ℚ) ≤ ↑(5:ℚ) * (↑(q - 1):ℚ) := by
33
+ norm_cast
34
+ linarith
35
+ refine (div_le_iff₀ g₁).mpr ?_
36
+ rw [div_mul_eq_mul_div]
37
+ refine (le_div_iff₀ ?_).mpr g₂
38
+ norm_num
39
+ have hr: (↑r/↑(r-1)) ≤ ((6/5):ℚ) := by
40
+ have g₁: 0 < (↑(r - 1):ℚ) := by
41
+ norm_cast
42
+ linarith[hql]
43
+ have g₂: ↑r * ↑(5:ℚ) ≤ ↑(6:ℚ) * (↑(r - 1):ℚ) := by
44
+ norm_cast
45
+ linarith
46
+ refine (div_le_iff₀ g₁).mpr ?_
47
+ rw [div_mul_eq_mul_div]
48
+ refine (le_div_iff₀ ?_).mpr g₂
49
+ norm_num
50
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ) := by
51
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
52
+ norm_cast
53
+ linarith
54
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
55
+ norm_cast
56
+ linarith
57
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
58
+ exact div_nonneg hq_nonneg hq_1_nonneg
59
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ ((4/3):ℚ) * ((5/4):ℚ) := by
60
+ exact mul_le_mul hp hq h₂ (by norm_num)
61
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
62
+ norm_cast
63
+ linarith
64
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
65
+ norm_cast
66
+ linarith
67
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
68
+ exact div_nonneg hr_nonneg hr_1_nonneg
69
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
70
+ norm_num at hub
71
+ rw [h₁]
72
+ norm_num
73
+ exact hub
74
+
75
+
76
+ lemma imo_1992_p1_1_1
77
+ (p : ℤ)
78
+ (hpl : 4 ≤ p) :
79
+ ↑p / ↑(p - 1) ≤ ((4/3):ℚ) := by
80
+ have g₁: 0 < (↑(p - 1):ℚ) := by
81
+ norm_cast
82
+ linarith [hpl]
83
+ have g₂: ↑p * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(p - 1):ℚ) := by
84
+ norm_cast
85
+ linarith
86
+ refine (div_le_iff₀ g₁).mpr ?_
87
+ rw [div_mul_eq_mul_div]
88
+ refine (le_div_iff₀ ?_).mpr g₂
89
+ norm_num
90
+
91
+
92
+ lemma imo_1992_p1_1_2
93
+ (p : ℤ)
94
+ -- (q r : ℤ)
95
+ -- (hpl : 4 ≤ p)
96
+ -- (hql : 5 ≤ q)
97
+ -- (hrl : 6 ≤ r)
98
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
99
+ (g₁ : 0 < (↑(p - 1):ℚ))
100
+ (g₂ : ↑p * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(p - 1):ℚ)) :
101
+ ↑p / ↑(p - 1) ≤ ((4/3):ℚ) := by
102
+ refine (div_le_iff₀ g₁).mpr ?_
103
+ rw [div_mul_eq_mul_div]
104
+ refine (le_div_iff₀ ?_).mpr g₂
105
+ norm_num
106
+
107
+
108
+ lemma imo_1992_p1_1_3
109
+ -- (p r : ℤ)
110
+ (q: ℤ)
111
+ -- (hpl : 4 ≤ p)
112
+ (hql : 5 ≤ q) :
113
+ -- (hrl : 6 ≤ r)
114
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
115
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3) :
116
+ ↑q / ↑(q - 1) ≤ ((5 / 4):ℚ) := by
117
+ have g₁: 0 < (↑(q - 1):ℚ) := by
118
+ norm_cast
119
+ linarith[hql]
120
+ have g₂: ↑q * ↑(4:ℚ) ≤ ↑(5:ℚ) * (↑(q - 1):ℚ) := by
121
+ norm_cast
122
+ linarith
123
+ refine (div_le_iff₀ g₁).mpr ?_
124
+ rw [div_mul_eq_mul_div]
125
+ refine (le_div_iff₀ ?_).mpr g₂
126
+ norm_num
127
+
128
+
129
+ lemma imo_1992_p1_1_4
130
+ -- (p r : ℤ)
131
+ (q: ℤ)
132
+ -- (hpl : 4 ≤ p)
133
+ -- (hql : 5 ≤ q)
134
+ -- (hrl : 6 ≤ r)
135
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
136
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
137
+ (g₁ : 0 < (↑(q - 1):ℚ))
138
+ (g₂ : ↑q * ↑(4:ℚ) ≤ ↑(5:ℚ) * (↑(q - 1):ℚ)) :
139
+ ↑q / ↑(q - 1) ≤ ((5 / 4):ℚ) := by
140
+ refine (div_le_iff₀ g₁).mpr ?_
141
+ rw [div_mul_eq_mul_div]
142
+ refine (le_div_iff₀ ?_).mpr g₂
143
+ norm_num
144
+
145
+
146
+ lemma imo_1992_p1_1_5
147
+ (p q r : ℤ)
148
+ -- (hpl : 4 ≤ p)
149
+ (hql : 5 ≤ q)
150
+ (hrl : 6 ≤ r)
151
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
152
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)))
153
+ (hp : ↑p / ↑(p - 1) ≤ ((4 / 3):ℚ))
154
+ (hq : ↑q / ↑(q - 1) ≤ ((5 / 4):ℚ)) :
155
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
156
+ have hr: (↑r/↑(r-1)) ≤ ((6/5):ℚ) := by
157
+ have g₁: 0 < (↑(r - 1):ℚ) := by
158
+ norm_cast
159
+ linarith[hql]
160
+ have g₂: ↑r * ↑(5:ℚ) ≤ ↑(6:ℚ) * (↑(r - 1):ℚ) := by
161
+ norm_cast
162
+ linarith
163
+ refine (div_le_iff₀ g₁).mpr ?_
164
+ rw [div_mul_eq_mul_div]
165
+ refine (le_div_iff₀ ?_).mpr g₂
166
+ norm_num
167
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ) := by
168
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
169
+ norm_cast
170
+ linarith
171
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
172
+ norm_cast
173
+ linarith
174
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
175
+ exact div_nonneg hq_nonneg hq_1_nonneg
176
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ ((4/3):ℚ) * ((5/4):ℚ) := by
177
+ exact mul_le_mul hp hq h₂ (by norm_num)
178
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
179
+ norm_cast
180
+ linarith
181
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
182
+ norm_cast
183
+ linarith
184
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
185
+ exact div_nonneg hr_nonneg hr_1_nonneg
186
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
187
+ norm_num at hub
188
+ rw [h₁]
189
+ norm_num
190
+ exact hub
191
+
192
+
193
+ lemma imo_1992_p1_1_6
194
+ -- (p : ℤ)
195
+ (q r : ℤ)
196
+ -- (hpl : 4 ≤ p)
197
+ (hql : 5 ≤ q)
198
+ (hrl : 6 ≤ r) :
199
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
200
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
201
+ -- (hq : ↑q / ↑(q - 1) ≤ 5 / 4) :
202
+ ↑r / ↑(r - 1) ≤ ((6/5):ℚ) := by
203
+ have g₁: 0 < (↑(r - 1):ℚ) := by
204
+ norm_cast
205
+ linarith[hql]
206
+ have g₂: ↑r * ↑(5:ℚ) ≤ ↑(6:ℚ) * (↑(r - 1):ℚ) := by
207
+ norm_cast
208
+ linarith
209
+ refine (div_le_iff₀ g₁).mpr ?_
210
+ rw [div_mul_eq_mul_div]
211
+ refine (le_div_iff₀ ?_).mpr g₂
212
+ norm_num
213
+
214
+
215
+ lemma imo_1992_p1_1_7
216
+ -- (p q : ℤ)
217
+ (r : ℤ)
218
+ -- (hpl : 4 ≤ p)
219
+ -- (hql : 5 ≤ q)
220
+ -- (hrl : 6 ≤ r)
221
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
222
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
223
+ -- (hq : ↑q / ↑(q - 1) ≤ 5 / 4)
224
+ (g₁ : 0 < (↑(r - 1):ℚ))
225
+ (g₂ : ↑r * ↑(5:ℚ) ≤ ↑(6:ℚ) * (↑(r - 1):ℚ)) :
226
+ ↑r / ↑(r - 1) ≤ ((6/5):ℚ) := by
227
+ refine (div_le_iff₀ g₁).mpr ?_
228
+ rw [div_mul_eq_mul_div]
229
+ refine (le_div_iff₀ ?_).mpr g₂
230
+ norm_num
231
+
232
+
233
+ lemma imo_1992_p1_1_8
234
+ (p q r : ℤ)
235
+ -- (hpl : 4 ≤ p)
236
+ (hql : 5 ≤ q)
237
+ (hrl : 6 ≤ r)
238
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
239
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)))
240
+ (hp : ↑p / ↑(p - 1) ≤ ((4/3):ℚ))
241
+ (hq : ↑q / ↑(q - 1) ≤ ((5/4):ℚ))
242
+ (hr : ↑r / ↑(r - 1) ≤ ((6/5):ℚ)) :
243
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
244
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ) := by
245
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
246
+ norm_cast
247
+ linarith
248
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
249
+ norm_cast
250
+ linarith
251
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
252
+ exact div_nonneg hq_nonneg hq_1_nonneg
253
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ ((4/3):ℚ) * ((5/4):ℚ) := by
254
+ exact mul_le_mul hp hq h₂ (by norm_num)
255
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
256
+ norm_cast
257
+ linarith
258
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
259
+ norm_cast
260
+ linarith
261
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
262
+ exact div_nonneg hr_nonneg hr_1_nonneg
263
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
264
+ norm_num at hub
265
+ rw [h₁]
266
+ norm_num
267
+ exact hub
268
+
269
+
270
+ lemma imo_1992_p1_1_9
271
+ (p q r : ℤ)
272
+ -- (hpl : 4 ≤ p)
273
+ (hql : 5 ≤ q)
274
+ (hrl : 6 ≤ r)
275
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
276
+ (hp : ↑p / ↑(p - 1) ≤ ((4 / 3):ℚ))
277
+ (hq : ↑q / ↑(q - 1) ≤ ((5 / 4):ℚ))
278
+ (hr : ↑r / ↑(r - 1) ≤ ((6 / 5):ℚ)) :
279
+ (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ) := by
280
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
281
+ norm_cast
282
+ linarith
283
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
284
+ norm_cast
285
+ linarith
286
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
287
+ exact div_nonneg hq_nonneg hq_1_nonneg
288
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ ((4/3):ℚ) * ((5/4):ℚ) := by
289
+ exact mul_le_mul hp hq h₂ (by norm_num)
290
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
291
+ norm_cast
292
+ linarith
293
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
294
+ norm_cast
295
+ linarith
296
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
297
+ exact div_nonneg hr_nonneg hr_1_nonneg
298
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
299
+
300
+
301
+ lemma imo_1992_p1_1_10
302
+ -- (p r : ℤ)
303
+ (q : ℤ)
304
+ -- (hpl : 4 ≤ p)
305
+ (hql : 5 ≤ q) :
306
+ -- (hrl : 6 ≤ r)
307
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
308
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
309
+ -- (hq : ↑q / ↑(q - 1) ≤ 5 / 4)
310
+ -- (hr : ↑r / ↑(r - 1) ≤ 6 / 5) :
311
+ -- hq_nonneg : 0 ≤ ↑q
312
+ -- hq_1_nonneg : 0 ≤ ↑(q - 1)
313
+ 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
314
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
315
+ norm_cast
316
+ linarith
317
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
318
+ norm_cast
319
+ linarith
320
+ exact div_nonneg hq_nonneg hq_1_nonneg
321
+
322
+
323
+ lemma imo_1992_p1_1_11
324
+ (p q r : ℤ)
325
+ -- (hpl : 4 ≤ p)
326
+ -- (hql : 5 ≤ q)
327
+ -- (hrl : 6 ≤ r)
328
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
329
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)))
330
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
331
+ -- (hq : ↑q / ↑(q - 1) ≤ 5 / 4)
332
+ -- (hr : ↑r / ↑(r - 1) ≤ 6 / 5)
333
+ (hub : (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ)) :
334
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
335
+ rw [h₁]
336
+ norm_num
337
+ norm_num at hub
338
+ exact hub
339
+
340
+
341
+ lemma imo_1992_p1_1_12
342
+ (p q r : ℤ)
343
+ -- (hpl : 4 ≤ p)
344
+ -- (hql : 5 ≤ q)
345
+ -- (hrl : 6 ≤ r)
346
+ -- -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
347
+ -- (hp : ↑p / ↑(p - 1) ≤ 4 / 3)
348
+ -- (hq : ↑q / ↑(q - 1) ≤ 5 / 4)
349
+ -- (hr : ↑r / ↑(r - 1) ≤ 6 / 5)
350
+ (hub : (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ)) :
351
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
352
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
353
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) := by
354
+ norm_cast
355
+ simp
356
+ rw [h₁]
357
+ norm_num
358
+ norm_num at hub
359
+ exact hub
360
+
361
+
362
+ lemma imo_1992_p1_2
363
+ (p q r k: ℤ)
364
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
365
+ (hpl: 4 ≤ p)
366
+ (hql: 5 ≤ q)
367
+ (hrl: 6 ≤ r)
368
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
369
+ (k < 2) := by
370
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
371
+ exact imo_1992_p1_1 p q r hpl hql hrl
372
+ have h₂: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
373
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
374
+ norm_cast
375
+ linarith
376
+ symm
377
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
378
+ norm_cast
379
+ linarith[hden]
380
+ exact (div_eq_iff g₂).mpr g₁
381
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
382
+ rw [h₂]
383
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
384
+ norm_cast
385
+ exact sub_one_lt (p * q * r)
386
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
387
+ norm_cast
388
+ exact div_lt_div_of_pos_right g₁ g₂
389
+ have h₄: (↑k:ℚ) < ↑2 := by
390
+ exact lt_of_lt_of_le h₃ h₁
391
+ norm_cast at h₄
392
+
393
+
394
+ lemma imo_1992_p1_2_1
395
+ (p q r k : ℤ)
396
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
397
+ -- (hpl : 4 ≤ p)
398
+ -- (hql : 5 ≤ q)
399
+ -- (hrl : 6 ≤ r)
400
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1))
401
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ 2) :
402
+ k < 2 := by
403
+ have h₂: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
404
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
405
+ norm_cast
406
+ linarith
407
+ symm
408
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
409
+ norm_cast
410
+ linarith[hden]
411
+ exact (div_eq_iff g₂).mpr g₁
412
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
413
+ rw [h₂]
414
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
415
+ norm_cast
416
+ exact sub_one_lt (p * q * r)
417
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
418
+ norm_cast
419
+ exact div_lt_div_of_pos_right g₁ g₂
420
+ have h₄: (↑k:ℚ) < ↑2 := by
421
+ exact lt_of_lt_of_le h₃ h₁
422
+ norm_cast at h₄
423
+
424
+
425
+ lemma imo_1992_p1_2_2
426
+ (p q r k : ℤ)
427
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
428
+ -- (hpl : 4 ≤ p)
429
+ -- (hql : 5 ≤ q)
430
+ -- (hrl : 6 ≤ r)
431
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1)) :
432
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) ≤ 2) :
433
+ ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
434
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
435
+ norm_cast
436
+ linarith
437
+ symm
438
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
439
+ norm_cast
440
+ linarith[hden]
441
+ exact (div_eq_iff g₂).mpr g₁
442
+
443
+
444
+ lemma imo_1992_p1_2_3
445
+ (p q r k : ℤ)
446
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
447
+ -- (hpl : 4 ≤ p)
448
+ -- (hql : 5 ≤ q)
449
+ -- (hrl : 6 ≤ r)
450
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1))
451
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2)
452
+ (h₂ : ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ)) :
453
+ k < 2 := by
454
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
455
+ rw [h₂]
456
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
457
+ norm_cast
458
+ exact sub_one_lt (p * q * r)
459
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
460
+ norm_cast
461
+ exact div_lt_div_of_pos_right g₁ g₂
462
+ have h₄: (↑k:ℚ) < ↑2 := by
463
+ exact lt_of_lt_of_le h₃ h₁
464
+ norm_cast at h₄
465
+
466
+
467
+ lemma imo_1992_p1_2_4
468
+ (p q r k : ℤ)
469
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
470
+ -- (hpl : 4 ≤ p)
471
+ -- (hql : 5 ≤ q)
472
+ -- (hrl : 6 ≤ r)
473
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1))
474
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) ≤ 2)
475
+ (h₂ : ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ)) :
476
+ ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
477
+ rw [h₂]
478
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
479
+ norm_cast
480
+ exact sub_one_lt (p * q * r)
481
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
482
+ norm_cast
483
+ exact div_lt_div_of_pos_right g₁ g₂
484
+
485
+
486
+ lemma imo_1992_p1_2_5
487
+ (p q r k : ℤ)
488
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
489
+ -- (hpl : 4 ≤ p)
490
+ -- (hql : 5 ≤ q)
491
+ -- (hrl : 6 ≤ r)
492
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
493
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2)
494
+ -- (h₂ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
495
+ (h₃ : ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)) :
496
+ k < 2 := by
497
+ have h₄: (↑k:ℚ) < ↑2 := by
498
+ exact lt_of_lt_of_le h₃ h₁
499
+ norm_cast at h₄
500
+
501
+
502
+ lemma imo_1992_p1_3
503
+ (p q r: ℤ)
504
+ (hpl: 2 ≤ p)
505
+ (hql: 3 ≤ q)
506
+ (hrl: 4 ≤ r) :
507
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑4 := by
508
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
509
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) := by
510
+ norm_cast
511
+ simp
512
+ have hp: (↑p/↑(p-1):ℚ) ≤ ↑(2:ℚ) := by
513
+ have g₁: 0 < (↑(p - 1):ℚ) := by
514
+ norm_cast
515
+ linarith[hpl]
516
+ have g₂: ↑p ≤ ↑(2:ℚ) * (↑(p - 1):ℚ) := by
517
+ norm_cast
518
+ linarith
519
+ exact (div_le_iff₀ g₁).mpr g₂
520
+ have hq: (↑q/↑(q-1)) ≤ ((3/2):ℚ) := by
521
+ have g₁: 0 < (↑(q - 1):ℚ) := by
522
+ norm_cast
523
+ linarith[hql]
524
+ have g₂: ↑q * ↑(2:ℚ) ≤ ↑(3:ℚ) * (↑(q - 1):ℚ) := by
525
+ norm_cast
526
+ linarith
527
+ refine (div_le_iff₀ g₁).mpr ?_
528
+ rw [div_mul_eq_mul_div]
529
+ refine (le_div_iff₀ ?_).mpr g₂
530
+ norm_num
531
+ have hr: (↑r/↑(r-1)) ≤ ((4/3):ℚ) := by
532
+ have g₁: 0 < (↑(r - 1):ℚ) := by
533
+ norm_cast
534
+ linarith[hql]
535
+ have g₂: ↑r * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(r - 1):ℚ) := by
536
+ norm_cast
537
+ linarith
538
+ refine (div_le_iff₀ g₁).mpr ?_
539
+ rw [div_mul_eq_mul_div]
540
+ refine (le_div_iff₀ ?_).mpr g₂
541
+ norm_num
542
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (2:ℚ) * ((3/2):ℚ) * ((4/3):ℚ) := by
543
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
544
+ norm_cast
545
+ linarith
546
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
547
+ norm_cast
548
+ linarith
549
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
550
+ exact div_nonneg hq_nonneg hq_1_nonneg
551
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ (2:ℚ) * ((3/2):ℚ) := by
552
+ exact mul_le_mul hp hq h₂ (by norm_num)
553
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
554
+ norm_cast
555
+ linarith
556
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
557
+ norm_cast
558
+ linarith
559
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
560
+ exact div_nonneg hr_nonneg hr_1_nonneg
561
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
562
+ norm_num at hub
563
+ rw [h₁]
564
+ norm_num
565
+ exact hub
566
+
567
+
568
+ lemma imo_1992_p1_3_1
569
+ (p : ℤ)
570
+ -- (q r : ℤ)
571
+ (hpl : 2 ≤ p) :
572
+ -- (hql : 3 ≤ q)
573
+ -- (hrl : 4 ≤ r)
574
+ -- (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
575
+ -- = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1))) :
576
+ (↑p/↑(p-1):ℚ) ≤ ↑(2:ℚ) := by
577
+ have g₁: 0 < (↑(p - 1):ℚ) := by
578
+ norm_cast
579
+ linarith[hpl]
580
+ have g₂: ↑p ≤ ↑(2:ℚ) * (↑(p - 1):ℚ) := by
581
+ norm_cast
582
+ linarith
583
+ exact (div_le_iff₀ g₁).mpr g₂
584
+
585
+
586
+ lemma imo_1992_p1_3_2
587
+ (p : ℤ)
588
+ -- (q r : ℤ)
589
+ (hpl : 2 ≤ p)
590
+ -- (hql : 3 ≤ q)
591
+ -- (hrl : 4 ≤ r)
592
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
593
+ (g₁ : 0 < (↑(p - 1):ℚ)) :
594
+ (↑p/↑(p-1):ℚ) ≤ ↑(2:ℚ) := by
595
+ have g₂: ↑p ≤ ↑(2:ℚ) * (↑(p - 1):ℚ) := by
596
+ norm_cast
597
+ linarith
598
+ exact (div_le_iff₀ g₁).mpr g₂
599
+
600
+
601
+ lemma imo_1992_p1_3_3
602
+ -- (p r : ℤ)
603
+ (q : ℤ)
604
+ -- (hpl : 2 ≤ p)
605
+ (hql : 3 ≤ q) :
606
+ -- (hrl : 4 ≤ r)
607
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
608
+ -- (hp : ↑p / ↑(p - 1) ≤ 2) :
609
+ (↑q/↑(q-1)) ≤ ((3/2):ℚ) := by
610
+ have g₁: 0 < (↑(q - 1):ℚ) := by
611
+ norm_cast
612
+ linarith[hql]
613
+ have g₂: ↑q * ↑(2:ℚ) ≤ ↑(3:ℚ) * (↑(q - 1):ℚ) := by
614
+ norm_cast
615
+ linarith
616
+ refine (div_le_iff₀ g₁).mpr ?_
617
+ rw [div_mul_eq_mul_div]
618
+ refine (le_div_iff₀ ?_).mpr g₂
619
+ norm_num
620
+
621
+
622
+ lemma imo_1992_p1_3_4
623
+ -- (p r : ℤ)
624
+ (q : ℤ)
625
+ -- (hpl : 2 ≤ p)
626
+ -- (hql : 3 ≤ q)
627
+ -- (hrl : 4 ≤ r)
628
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
629
+ -- (hp : ↑p / ↑(p - 1) ≤ 2)
630
+ (g₁ : 0 < (↑(q - 1):ℚ))
631
+ (g₂ : ↑q * ↑(2:ℚ) ≤ ↑(3:ℚ) * (↑(q - 1):ℚ)) :
632
+ (↑q/↑(q-1)) ≤ ((3/2):ℚ) := by
633
+ refine (div_le_iff₀ g₁).mpr ?_
634
+ rw [div_mul_eq_mul_div]
635
+ refine (le_div_iff₀ ?_).mpr g₂
636
+ norm_num
637
+
638
+
639
+ lemma imo_1992_p1_3_5
640
+ -- (p q : ℤ)
641
+ (r : ℤ)
642
+ -- (hpl : 2 ≤ p)
643
+ -- (hql : 3 ≤ q)
644
+ (hrl : 4 ≤ r) :
645
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
646
+ -- (hp : ↑p / ↑(p - 1) ≤ 2)
647
+ -- (hq : ↑q / ↑(q - 1) ≤ 3 / 2) :
648
+ ↑r / ↑(r - 1) ≤ ((4 / 3):ℚ) := by
649
+ have g₁: 0 < (↑(r - 1):ℚ) := by
650
+ norm_cast
651
+ linarith
652
+ have g₂: ↑r * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(r - 1):ℚ) := by
653
+ norm_cast
654
+ linarith
655
+ refine (div_le_iff₀ g₁).mpr ?_
656
+ rw [div_mul_eq_mul_div]
657
+ refine (le_div_iff₀ ?_).mpr g₂
658
+ norm_num
659
+
660
+
661
+ lemma imo_1992_p1_3_6
662
+ -- (p q : ℤ)
663
+ (r : ℤ)
664
+ -- (hpl : 2 ≤ p)
665
+ -- (hql : 3 ≤ q)
666
+ -- (hrl : 4 ≤ r)
667
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
668
+ -- (hp : ↑p / ↑(p - 1) ≤ 2)
669
+ -- (hq : ↑q / ↑(q - 1) ≤ 3 / 2)
670
+ (g₁ : 0 < (↑(r - 1):ℚ))
671
+ (g₂ : ↑r * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(r - 1):ℚ)) :
672
+ ↑r / ↑(r - 1) ≤ ((4 / 3):ℚ) := by
673
+ refine (div_le_iff₀ g₁).mpr ?_
674
+ rw [div_mul_eq_mul_div]
675
+ refine (le_div_iff₀ ?_).mpr g₂
676
+ norm_num
677
+
678
+
679
+ lemma imo_1992_p1_3_7
680
+ (p q r : ℤ)
681
+ -- (hpl : 2 ≤ p)
682
+ (hql : 3 ≤ q)
683
+ (hrl : 4 ≤ r)
684
+ -- (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
685
+ (hp : (↑p/↑(p-1):ℚ) ≤ ↑(2:ℚ))
686
+ (hq : ↑q / ↑(q - 1) ≤ ((3 / 2):ℚ))
687
+ (hr : ↑r / ↑(r - 1) ≤ ((4 / 3):ℚ)) :
688
+ (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (2:ℚ) * ((3/2):ℚ) * ((4/3):ℚ) := by
689
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
690
+ norm_cast
691
+ linarith
692
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
693
+ norm_cast
694
+ linarith
695
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
696
+ exact div_nonneg hq_nonneg hq_1_nonneg
697
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ (2:ℚ) * ((3/2):ℚ) := by
698
+ exact mul_le_mul hp hq h₂ (by norm_num)
699
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
700
+ norm_cast
701
+ linarith
702
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
703
+ norm_cast
704
+ linarith
705
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
706
+ exact div_nonneg hr_nonneg hr_1_nonneg
707
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
708
+
709
+
710
+ lemma imo_1992_p1_3_8
711
+ (p q r : ℤ)
712
+ -- (hpl : 2 ≤ p)
713
+ -- (hql : 3 ≤ q)
714
+ -- (hrl : 4 ≤ r)
715
+ (h₁ : ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) = ↑p / ↑(p - 1) * (↑q / ↑(q - 1)) * (↑r / ↑(r - 1)))
716
+ -- (hp : ↑p / ↑(p - 1) ≤ 2)
717
+ -- (hq : ↑q / ↑(q - 1) ≤ 3 / 2)
718
+ -- (hr : ↑r / ↑(r - 1) ≤ 4 / 3)
719
+ (hub : ↑p / (↑p - 1) * (↑q / (↑q - 1)) * (↑r / (↑r - 1)) ≤ 4) :
720
+ ↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)) ≤ 4 := by
721
+ rw [h₁]
722
+ exact hub
723
+
724
+
725
+ lemma imo_1992_p1_4
726
+ (p q r k: ℤ)
727
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
728
+ (hpl: 2 ≤ p)
729
+ (hql: 3 ≤ q)
730
+ (hrl: 4 ≤ r)
731
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
732
+ (k < 4) := by
733
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑4 := by
734
+ exact imo_1992_p1_3 p q r hpl hql hrl
735
+ have h₂: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
736
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
737
+ norm_cast
738
+ linarith
739
+ symm
740
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
741
+ norm_cast
742
+ linarith [hden]
743
+ exact (div_eq_iff g₂).mpr g₁
744
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
745
+ rw [h₂]
746
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
747
+ norm_cast
748
+ exact sub_one_lt (p * q * r)
749
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
750
+ norm_cast
751
+ exact div_lt_div_of_pos_right g₁ g₂
752
+ have h₄: (↑k:ℚ) < ↑4 := by
753
+ exact lt_of_lt_of_le h₃ h₁
754
+ norm_cast at h₄
755
+
756
+
757
+ lemma imo_1992_p1_4_1
758
+ (p q r k : ℤ)
759
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
760
+ -- (hpl : 2 ≤ p)
761
+ -- (hql : 3 ≤ q)
762
+ -- (hrl : 4 ≤ r)
763
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
764
+ (h₁ : (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑4)
765
+ -- (h₂ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
766
+ (h₃ : ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)) :
767
+ k < 4 := by
768
+ have h₄: (↑k:ℚ) < ↑4 := by
769
+ exact lt_of_lt_of_le h₃ h₁
770
+ norm_cast at h₄
771
+
772
+
773
+ lemma imo_1992_p1_5
774
+ (p q r k: ℤ)
775
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
776
+ (h₁: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
777
+ (hpl: 2 ≤ p)
778
+ (hql: 3 ≤ q)
779
+ (hrl: 4 ≤ r)
780
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1)) :
781
+ (1 < k) := by
782
+ have hk0: 0 < (↑k:ℚ) := by
783
+ have g₁: 2 * 3 * 4 ≤ p * q * r := by
784
+ have g₂: 2 * 3 ≤ p * q := by
785
+ exact mul_le_mul hpl hql (by norm_num) (by linarith[hpl])
786
+ exact mul_le_mul g₂ hrl (by norm_num) (by linarith[g₂])
787
+ have g₂: 0 < (↑(p * q * r - 1):ℚ) := by
788
+ norm_cast
789
+ linarith[g₁]
790
+ have g₃: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
791
+ norm_cast
792
+ rw [h₁]
793
+ exact div_pos g₂ g₃
794
+ norm_cast at hk0
795
+ by_contra! hc
796
+ interval_cases k
797
+ simp at hk
798
+ have g₁: p*q + q*r + r*p = p+q+r := by linarith
799
+ have g₂: p < p*q := by exact lt_mul_right (by linarith) (by linarith)
800
+ have g₃: q < q*r := by exact lt_mul_right (by linarith) (by linarith)
801
+ have g₄: r < r*p := by exact lt_mul_right (by linarith) (by linarith)
802
+ have g₅: p+q+r < p*q + q*r + r*p := by linarith[g₂,g₃,g₄]
803
+ linarith [g₁,g₅]
804
+
805
+
806
+ lemma imo_1992_p1_5_1
807
+ (p q r k : ℤ)
808
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
809
+ (h₁ : ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
810
+ (hpl : 2 ≤ p)
811
+ (hql : 3 ≤ q)
812
+ (hrl : 4 ≤ r)
813
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1)) :
814
+ 0 < (↑k:ℚ) := by
815
+ have g₁: 2 * 3 * 4 ≤ p * q * r := by
816
+ have g₂: 2 * 3 ≤ p * q := by
817
+ exact mul_le_mul hpl hql (by norm_num) (by linarith[hpl])
818
+ exact mul_le_mul g₂ hrl (by norm_num) (by linarith[g₂])
819
+ have g₂: 0 < (↑(p * q * r - 1):ℚ) := by
820
+ norm_cast
821
+ linarith[g₁]
822
+ have g₃: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
823
+ norm_cast
824
+ rw [h₁]
825
+ exact div_pos g₂ g₃
826
+
827
+
828
+ lemma imo_1992_p1_5_2
829
+ (p q r : ℤ)
830
+ -- (k : ℤ)
831
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
832
+ -- (h₁ : ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
833
+ (hpl : 0 < (p - 1))
834
+ (hql : 0 < (q - 1))
835
+ (hrl : 0 < (r - 1)) :
836
+ -- (hden: 0 < (p - 1) * (q - 1) * (r - 1)) :
837
+ -- (g₁ : 2 * 3 * 4 ≤ p * q * r)
838
+ -- (g₂ : 0 < (↑(p * q * r - 1):ℚ)) :
839
+ 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
840
+ norm_cast
841
+ refine mul_pos ?_ hrl
842
+ exact mul_pos hpl hql
843
+
844
+
845
+ lemma imo_1992_p1_5_3
846
+ (p q r : ℤ)
847
+ -- (k : ℤ)
848
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
849
+ -- (h₁ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
850
+ (hpl : 2 ≤ p)
851
+ (hql : 3 ≤ q)
852
+ (hrl : 4 ≤ r) :
853
+ 0 < ↑(p * q * r - 1) := by
854
+ have g₁: 2 * 3 * 4 ≤ p * q * r := by
855
+ have g₂: 2 * 3 ≤ p * q := by
856
+ exact mul_le_mul hpl hql (by norm_num) (by linarith[hpl])
857
+ exact mul_le_mul g₂ hrl (by norm_num) (by linarith[g₂])
858
+ norm_cast
859
+ linarith[g₁]
860
+
861
+
862
+ lemma imo_1992_p1_5_4
863
+ (p q r k : ℤ)
864
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
865
+ (h₁ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
866
+ (hpl : 2 ≤ p)
867
+ (hql : 3 ≤ q)
868
+ (hrl : 4 ≤ r)
869
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
870
+ (hk0 : 0 < k) :
871
+ 1 < k := by
872
+ by_contra! hc
873
+ interval_cases k
874
+ simp at hk
875
+ have g₁: p*q + q*r + r*p = p+q+r := by linarith
876
+ have g₂: p < p*q := by exact lt_mul_right (by linarith) (by linarith)
877
+ have g₃: q < q*r := by exact lt_mul_right (by linarith) (by linarith)
878
+ have g₄: r < r*p := by exact lt_mul_right (by linarith) (by linarith)
879
+ have g₅: p+q+r < p*q + q*r + r*p := by linarith[g₂,g₃,g₄]
880
+ linarith [g₁,g₅]
881
+
882
+
883
+ lemma imo_1992_p1_5_5
884
+ (p q r : ℤ)
885
+ -- (k : ℤ)
886
+ (hpl : 2 ≤ p)
887
+ (hql : 3 ≤ q)
888
+ (hrl : 4 ≤ r)
889
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
890
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 1) :
891
+ -- (h₁ : ↑1 = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
892
+ -- (hk0 : 0 < 1)
893
+ -- (hc : 1 ≤ 1) :
894
+ False := by
895
+ simp at hk
896
+ have g₁: p * q + q * r + r * p = p + q + r := by linarith
897
+ have g₂: p < p * q := by exact lt_mul_right (by linarith) (by linarith)
898
+ have g₃: q < q * r := by exact lt_mul_right (by linarith) (by linarith)
899
+ have g₄: r < r * p := by exact lt_mul_right (by linarith) (by linarith)
900
+ have g₅: p + q + r < p * q + q * r + r * p := by linarith[g₂,g₃,g₄]
901
+ linarith [g₁,g₅]
902
+
903
+
904
+ lemma imo_1992_p1_5_6
905
+ (p q r : ℤ)
906
+ -- (k : ℤ)
907
+ (hpl : 2 ≤ p)
908
+ (hql : 3 ≤ q)
909
+ (hrl : 4 ≤ r)
910
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
911
+ -- (h₁ : ↑1 = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
912
+ -- (hk0 : 0 < 1)
913
+ -- (hc : 1 ≤ 1)
914
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1))
915
+ (g₁ : p * q + q * r + r * p = p + q + r) :
916
+ False := by
917
+ have g₂: p < p * q := by exact lt_mul_right (by linarith) (by linarith)
918
+ have g₃: q < q * r := by exact lt_mul_right (by linarith) (by linarith)
919
+ have g₄: r < r * p := by exact lt_mul_right (by linarith) (by linarith)
920
+ have g₅: p + q + r < p * q + q * r + r * p := by linarith[g₂,g₃,g₄]
921
+ linarith [g₁,g₅]
922
+
923
+
924
+ lemma imo_1992_p1_5_7
925
+ (p q r : ℤ)
926
+ -- (k : ℤ)
927
+ (hpl : 2 ≤ p)
928
+ -- (hql : 3 ≤ q)
929
+ (hrl : 4 ≤ r)
930
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
931
+ -- (h₁ : ↑1 = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
932
+ -- (hk0 : 0 < 1)
933
+ -- (hc : 1 ≤ 1)
934
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1))
935
+ (g₁ : p * q + q * r + r * p = p + q + r)
936
+ (g₂: p < p * q)
937
+ (g₃: q < q * r) :
938
+ False := by
939
+ have g₄: r < r * p := by exact lt_mul_right (by linarith) (by linarith)
940
+ have g₅: p + q + r < p * q + q * r + r * p := by linarith[g₂,g₃,g₄]
941
+ linarith [g₁,g₅]
942
+
943
+
944
+ lemma imo_1992_p1_6
945
+ (p q r k: ℤ)
946
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
947
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
948
+ (h₁: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
949
+ (hpl: 2 ≤ p)
950
+ (hql: 3 ≤ q)
951
+ (hrl: 4 ≤ r)
952
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
953
+ (p < 4) := by
954
+ by_contra! hcp
955
+ have hcq: 5 ≤ q := by linarith
956
+ have hcr: 6 ≤ r := by linarith
957
+ have h₃: k < 2 := by exact imo_1992_p1_2 p q r k hk hcp hcq hcr hden
958
+ have h₄: 1 < k := by exact imo_1992_p1_5 p q r k hk h₁ hpl hql hrl hden
959
+ linarith
960
+
961
+
962
+ lemma imo_1992_p1_6_1
963
+ (p q r k : ℤ)
964
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
965
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
966
+ (h₁ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
967
+ (hpl : 2 ≤ p)
968
+ (hql : 3 ≤ q)
969
+ (hrl : 4 ≤ r)
970
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1))
971
+ (hcp : 4 ≤ p)
972
+ (hcq : 5 ≤ q)
973
+ (hcr : 6 ≤ r)
974
+ (h₃ : k < 2)
975
+ (h₄ : 1 < k) :
976
+ p < 4 := by
977
+ linarith
978
+
979
+
980
+ lemma imo_1992_p1_7
981
+ (q r : ℤ)
982
+ (p: ℕ)
983
+ (h₀ : q * r = ↑p)
984
+ (h₁: Nat.Prime p) :
985
+ q = -1 ∨ q = 1 ∨ q = -p ∨ q = p := by
986
+ have hq : q ≠ 0 := by
987
+ intro h
988
+ rw [h] at h₀
989
+ simp at h₀
990
+ symm at h₀
991
+ norm_cast at h₀
992
+ rw [h₀] at h₁
993
+ exact Nat.not_prime_zero h₁
994
+ have hr : r ≠ 0 := by
995
+ intro h
996
+ rw [h] at h₀
997
+ simp at h₀
998
+ norm_cast at h₀
999
+ rw [← h₀] at h₁
1000
+ exact Nat.not_prime_zero h₁
1001
+ have hqr : abs q * abs r = p := by
1002
+ have h₃: abs q = q.natAbs := by exact abs_eq_natAbs q
1003
+ have h₄: abs r = r.natAbs := by exact abs_eq_natAbs r
1004
+ rw [h₃,h₄]
1005
+ norm_cast
1006
+ exact Int.natAbs_mul_natAbs_eq h₀
1007
+ have h_abs: abs (↑(q.natAbs):ℤ) = 1 ∨ abs q = p := by
1008
+ cases' Int.natAbs_eq q with h_1 h_2
1009
+ . rw [h_1] at hqr
1010
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1011
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1012
+ norm_cast at *
1013
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1014
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1015
+ cases' h₄ with h₄₀ h₄₁
1016
+ . left
1017
+ norm_cast at *
1018
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1019
+ right
1020
+ rw [h₅]
1021
+ norm_cast at *
1022
+ . rw [h_2] at hqr
1023
+ rw [abs_neg _] at hqr
1024
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1025
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1026
+ norm_cast at *
1027
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1028
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1029
+ cases' h₄ with h₄₀ h₄₁
1030
+ . left
1031
+ norm_cast at *
1032
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1033
+ right
1034
+ rw [h₅]
1035
+ norm_cast
1036
+ cases' h_abs with hq_abs hq_abs
1037
+ . norm_cast at *
1038
+ have h₄: q = ↑(q.natAbs) ∨ q = -↑(q.natAbs) := by
1039
+ exact Int.natAbs_eq q
1040
+ rw [hq_abs] at h₄
1041
+ norm_cast at h₄
1042
+ cases' h₄ with h₄₀ h₄₁
1043
+ . right
1044
+ left
1045
+ exact h₄₀
1046
+ . left
1047
+ exact h₄₁
1048
+ . right
1049
+ right
1050
+ have h₂: abs q = q.natAbs := by exact abs_eq_natAbs q
1051
+ rw [h₂] at hq_abs
1052
+ norm_cast at hq_abs
1053
+ refine or_comm.mp ?_
1054
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
1055
+ norm_cast
1056
+
1057
+
1058
+ lemma imo_1992_p1_7_1
1059
+ (q r : ℤ)
1060
+ (p : ℕ)
1061
+ (h₀ : q * r = ↑p)
1062
+ (h₁ : Nat.Prime p) :
1063
+ q ≠ 0 := by
1064
+ intro h
1065
+ rw [h] at h₀
1066
+ simp at h₀
1067
+ symm at h₀
1068
+ norm_cast at h₀
1069
+ rw [h₀] at h₁
1070
+ exact Nat.not_prime_zero h₁
1071
+
1072
+
1073
+ lemma imo_1992_p1_7_2
1074
+ (q r : ℤ)
1075
+ (p : ℕ)
1076
+ (h₀ : q * r = ↑p)
1077
+ (h₁ : Nat.Prime p)
1078
+ (hq : q ≠ 0) :
1079
+ r ≠ 0 := by
1080
+ intro h
1081
+ rw [h] at h₀
1082
+ simp at h₀
1083
+ norm_cast at h₀
1084
+ rw [← h₀] at h₁
1085
+ exact Nat.not_prime_zero h₁
1086
+
1087
+
1088
+ lemma imo_1992_p1_7_3
1089
+ (q r : ℤ)
1090
+ (p : ���)
1091
+ (h₀ : q * r = ↑p) :
1092
+ -- (h₁ : Nat.Prime p)
1093
+ -- (hq : q ≠ 0)
1094
+ -- (hr : r ≠ 0) :
1095
+ |q| * |r| = ↑p := by
1096
+ have h₃: abs q = q.natAbs := by exact abs_eq_natAbs q
1097
+ have h₄: abs r = r.natAbs := by exact abs_eq_natAbs r
1098
+ rw [h₃,h₄]
1099
+ norm_cast
1100
+ exact Int.natAbs_mul_natAbs_eq h₀
1101
+
1102
+
1103
+ lemma imo_1992_p1_7_4
1104
+ (q r : ℤ)
1105
+ (p : ℕ)
1106
+ (h₀ : q * r = ↑p)
1107
+ -- (h₁ : Nat.Prime p)
1108
+ -- (hq : q ≠ 0)
1109
+ -- (hr : r ≠ 0)
1110
+ (h₃ : |q| = ↑(natAbs q))
1111
+ (h₄ : |r| = ↑(natAbs r)) :
1112
+ |q| * |r| = ↑p := by
1113
+ rw [h₃,h₄]
1114
+ norm_cast
1115
+ exact Int.natAbs_mul_natAbs_eq h₀
1116
+
1117
+
1118
+ lemma imo_1992_p1_7_5
1119
+ (q r : ℤ)
1120
+ (p : ℕ)
1121
+ -- (h₀ : q * r = ↑p)
1122
+ (h₁ : Nat.Prime p)
1123
+ (hq : q ≠ 0)
1124
+ (hr : r ≠ 0)
1125
+ (hqr : |q| * |r| = ↑p) :
1126
+ |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p := by
1127
+ cases' Int.natAbs_eq q with h_1 h_2
1128
+ . rw [h_1] at hqr
1129
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1130
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1131
+ norm_cast at *
1132
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1133
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1134
+ cases' h₄ with h₄₀ h₄₁
1135
+ . left
1136
+ norm_cast at *
1137
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1138
+ right
1139
+ rw [h₅]
1140
+ norm_cast at *
1141
+ . rw [h_2] at hqr
1142
+ rw [abs_neg _] at hqr
1143
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1144
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1145
+ norm_cast at *
1146
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1147
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1148
+ cases' h₄ with h₄₀ h₄₁
1149
+ . left
1150
+ norm_cast at *
1151
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1152
+ right
1153
+ rw [h₅]
1154
+ norm_cast
1155
+
1156
+
1157
+ lemma imo_1992_p1_7_6
1158
+ (q r : ℤ)
1159
+ (p : ℕ)
1160
+ -- (h₀ : q * r = ↑p)
1161
+ (h₁ : Nat.Prime p)
1162
+ (hq : q ≠ 0)
1163
+ (hr : r ≠ 0)
1164
+ (hqr : |q| * |r| = ↑p)
1165
+ (h_1 : q = ↑(natAbs q)) :
1166
+ |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p := by
1167
+ rw [h_1] at hqr
1168
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1169
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1170
+ norm_cast at *
1171
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1172
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1173
+ cases' h₄ with h₄₀ h₄₁
1174
+ . left
1175
+ norm_cast at *
1176
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1177
+ right
1178
+ rw [h₅]
1179
+ norm_cast at *
1180
+
1181
+
1182
+ lemma imo_1992_p1_7_7
1183
+ (q r : ℤ)
1184
+ (p : ℕ)
1185
+ -- (h₀ : q * r = ↑p)
1186
+ -- (h₁ : Nat.Prime p)
1187
+ (hq : q ≠ 0)
1188
+ (hr : r ≠ 0)
1189
+ (hqr : |↑(natAbs q)| * |r| = ↑p)
1190
+ (h_1 : q = ↑(natAbs q))
1191
+ (h₂ : |(↑(natAbs q):ℤ)| ∣ ↑p)
1192
+ -- (h₃ : natAbs q ∣ p)
1193
+ (h₄ : natAbs q = 1 ∨ natAbs q = p) :
1194
+ |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p := by
1195
+ cases' h₄ with h₄₀ h₄₁
1196
+ . left
1197
+ norm_cast at *
1198
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1199
+ right
1200
+ rw [h₅]
1201
+ norm_cast at *
1202
+
1203
+
1204
+ lemma imo_1992_p1_7_8
1205
+ (q r : ℤ)
1206
+ (p : ℕ)
1207
+ -- (h₀ : q * r = ↑p)
1208
+ -- (h₁ : Nat.Prime p)
1209
+ (hq : q ≠ 0)
1210
+ (hr : r ≠ 0)
1211
+ (hqr : |↑(natAbs q)| * |r| = ↑p)
1212
+ (h_1 : q = ↑(natAbs q))
1213
+ (h₂ : |(↑(natAbs q):ℤ)| ∣ ↑p)
1214
+ -- (h₃ : natAbs q ∣ p)
1215
+ (h₄₁ : natAbs q = p) :
1216
+ |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p := by
1217
+ have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1218
+ right
1219
+ rw [h₅]
1220
+ norm_cast at *
1221
+
1222
+
1223
+ lemma imo_1992_p1_7_9
1224
+ (q r : ℤ)
1225
+ (p : ℕ)
1226
+ -- (h₀ : q * r = ↑p)
1227
+ (h₁ : Nat.Prime p)
1228
+ (hq : q ≠ 0)
1229
+ (hr : r ≠ 0)
1230
+ (hqr : |q| * |r| = ↑p)
1231
+ (h_2 : q = -↑(natAbs q)) :
1232
+ |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p := by
1233
+ rw [h_2] at hqr
1234
+ rw [abs_neg _] at hqr
1235
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
1236
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1237
+ norm_cast at *
1238
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
1239
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1240
+ cases' h₄ with h₄₀ h₄₁
1241
+ . left
1242
+ norm_cast at *
1243
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1244
+ right
1245
+ rw [h₅]
1246
+ norm_cast
1247
+
1248
+
1249
+ lemma imo_1992_p1_7_10
1250
+ (q r : ℤ)
1251
+ (p : ℕ)
1252
+ -- (h₀ : q * r = ↑p)
1253
+ -- (h₁ : Nat.Prime p)
1254
+ -- (hq : q ≠ 0)
1255
+ -- (hr : r ≠ 0)
1256
+ (hqr : |(↑(natAbs q):ℤ)| * |r| = ↑p)
1257
+ (h_2 : q = (-↑(q.natAbs):ℤ)) :
1258
+ |(↑(natAbs q):ℤ)| ∣ ↑p := by
1259
+ refine Dvd.intro (abs r) ?_
1260
+ simp at *
1261
+ exact hqr
1262
+
1263
+
1264
+ lemma imo_1992_p1_7_11
1265
+ (q : ℤ)
1266
+ -- (r : ℤ)
1267
+ (p : ℕ)
1268
+ -- (h₀ : q * r = ↑p)
1269
+ (h₁ : Nat.Prime p)
1270
+ -- (hq : q ≠ 0)
1271
+ -- (hr : r ≠ 0)
1272
+ -- (hqr : |↑(natAbs q)| * |r| = ↑p)
1273
+ -- (h_2 : q = -↑(natAbs q))
1274
+ (h₂ : |(↑(natAbs q):ℤ)| ∣ ↑p) :
1275
+ natAbs q = 1 ∨ natAbs q = p := by
1276
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
1277
+ norm_cast at *
1278
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
1279
+
1280
+
1281
+ lemma imo_1992_p1_7_12
1282
+ (q : ℤ)
1283
+ -- (r : ℤ)
1284
+ (p : ℕ)
1285
+ -- (h₀ : q * r = ↑p)
1286
+ -- (h₁ : Nat.Prime p)
1287
+ -- (hq : q ≠ 0)
1288
+ -- (hr : r ≠ 0)
1289
+ -- (hqr : |↑(natAbs q)| * |r| = ↑p)
1290
+ -- (h_2 : q = -↑(natAbs q))
1291
+ -- (h₂ : |(↑(natAbs q):ℤ)| ∣ ↑p)
1292
+ -- (h₃ : natAbs q ∣ p)
1293
+ (h₄₁ : natAbs q = p) :
1294
+ |q| = ↑p := by
1295
+ have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
1296
+ rw [h₅]
1297
+ norm_cast
1298
+
1299
+
1300
+ lemma imo_1992_p1_7_13
1301
+ (q r : ℤ)
1302
+ (p : ℕ)
1303
+ -- (h₀ : q * r = ↑p)
1304
+ -- (h₁ : Nat.Prime p)
1305
+ (hq : q ≠ 0)
1306
+ (hr : r ≠ 0)
1307
+ -- (hqr : |q| * |r| = ↑p)
1308
+ (h_abs : |(↑(natAbs q):ℤ)| = 1 ∨ |q| = ↑p) :
1309
+ q = -1 ∨ q = 1 ∨ q = -↑p ∨ q = ↑p := by
1310
+ cases' h_abs with hq_abs hq_abs
1311
+ . norm_cast at *
1312
+ have h₄: q = ↑(q.natAbs) ∨ q = -↑(q.natAbs) := by
1313
+ exact Int.natAbs_eq q
1314
+ rw [hq_abs] at h₄
1315
+ norm_cast at h₄
1316
+ cases' h₄ with h₄₀ h₄₁
1317
+ . right
1318
+ left
1319
+ exact h₄₀
1320
+ . left
1321
+ exact h₄₁
1322
+ . right
1323
+ right
1324
+ have h₂: abs q = q.natAbs := by exact abs_eq_natAbs q
1325
+ rw [h₂] at hq_abs
1326
+ norm_cast at hq_abs
1327
+ refine or_comm.mp ?_
1328
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
1329
+ norm_cast
1330
+
1331
+
1332
+ lemma imo_1992_p1_7_14
1333
+ (q r : ℤ)
1334
+ (p : ℕ)
1335
+ -- (h₀ : q * r = ↑p)
1336
+ -- (h₁ : Nat.Prime p)
1337
+ (hq : q ≠ 0)
1338
+ (hr : r ≠ 0)
1339
+ -- (hqr : |q| * |r| = ↑p)
1340
+ (hq_abs : |(↑(natAbs q):ℤ)| = 1) :
1341
+ q = -1 ∨ q = 1 ∨ q = -↑p ∨ q = ↑p := by
1342
+ norm_cast at *
1343
+ have h₄: q = ↑(q.natAbs) ∨ q = -↑(q.natAbs) := by
1344
+ exact Int.natAbs_eq q
1345
+ rw [hq_abs] at h₄
1346
+ norm_cast at h₄
1347
+ cases' h₄ with h₄₀ h₄₁
1348
+ . right
1349
+ left
1350
+ exact h₄₀
1351
+ . left
1352
+ exact h₄₁
1353
+
1354
+
1355
+ lemma imo_1992_p1_7_15
1356
+ (q r : ℤ)
1357
+ -- (p : ℕ)
1358
+ (hrq: r = q) :
1359
+ -- (h₀ : q * r = ↑p)
1360
+ -- (h₁ : Nat.Prime p)
1361
+ -- (hqr : |q| * |r| = ↑p)
1362
+ -- (hq : ¬q = 0)
1363
+ -- (hr : ¬r = 0)
1364
+ -- (hq_abs : natAbs q = 1) :
1365
+ r = ↑(natAbs q) ∨ r = -↑(natAbs q) := by
1366
+ rw [← hrq]
1367
+ exact Int.natAbs_eq r
1368
+
1369
+
1370
+ lemma imo_1992_p1_7_16
1371
+ (q : ℤ)
1372
+ -- (r : ℤ)
1373
+ (p : ℕ)
1374
+ -- (h₀ : q * r = ↑p)
1375
+ -- (h₁ : Nat.Prime p)
1376
+ -- (hq : q ≠ 0)
1377
+ -- (hr : r ≠ 0)
1378
+ -- (hqr : |q| * |r| = ↑p)
1379
+ (hq_abs : |q| = ↑p) :
1380
+ q = -1 ∨ q = 1 ∨ q = -↑p ∨ q = ↑p := by
1381
+ right
1382
+ right
1383
+ have h₂: abs q = q.natAbs := by exact abs_eq_natAbs q
1384
+ rw [h₂] at hq_abs
1385
+ norm_cast at hq_abs
1386
+ refine or_comm.mp ?_
1387
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
1388
+ norm_cast
1389
+
1390
+
1391
+ lemma imo_1992_p1_7_17
1392
+ (q : ℤ)
1393
+ -- (r : ℤ)
1394
+ (p : ℕ)
1395
+ -- (h₀ : q * r = ↑p)
1396
+ -- (h₁ : Nat.Prime p)
1397
+ -- (hq : q ≠ 0)
1398
+ -- (hr : r ≠ 0)
1399
+ -- (hqr : |q| * |r| = ↑p)
1400
+ (hq_abs : |q| = ↑p) :
1401
+ q = -↑p ∨ q = ↑p := by
1402
+ have h₂: abs q = q.natAbs := by exact abs_eq_natAbs q
1403
+ rw [h₂] at hq_abs
1404
+ norm_cast at hq_abs
1405
+ refine or_comm.mp ?_
1406
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
1407
+ norm_cast
1408
+
1409
+
1410
+ lemma imo_1992_p1_7_18
1411
+ (q : ℤ)
1412
+ -- (r : ℤ)
1413
+ (p : ℕ)
1414
+ -- (h₀ : q * r = ↑p)
1415
+ -- (h₁ : Nat.Prime p)
1416
+ -- (hq : q ≠ 0)
1417
+ -- (hr : r ≠ 0)
1418
+ -- (hqr : |q| * |r| = ↑p)
1419
+ -- (h₂ : |q| = ↑(natAbs q))
1420
+ (hq_abs : natAbs q = p) :
1421
+ q = -↑p ∨ q = ↑p := by
1422
+ refine or_comm.mp ?_
1423
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
1424
+ norm_cast
1425
+
1426
+
1427
+
1428
+ -- my_case_k_2
1429
+ lemma imo_1992_p1_8
1430
+ (p q r: ℤ)
1431
+ (h₀: 1 < p ∧ p < q ∧ q < r)
1432
+ (hpl: 2 ≤ p)
1433
+ (hql: 3 ≤ q)
1434
+ (hrl: 4 ≤ r)
1435
+ (hpu: p < 4)
1436
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 2) :
1437
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
1438
+ interval_cases p
1439
+ . exfalso
1440
+ norm_num at *
1441
+ have g₁: 2*q + 2*r = 3 := by linarith
1442
+ linarith [g₁,hql,hrl]
1443
+ . right
1444
+ norm_num at *
1445
+ have g₂: (4-q)*(4-r) = 11 := by linarith
1446
+ have g₃: (4-q) = -1 ∨ (4-q) = 1 ∨ (4-q) = -11 ∨ (4-q) = 11 := by
1447
+ refine imo_1992_p1_7 (4-q) (4-r) 11 g₂ ?_
1448
+ decide
1449
+ cases' g₃ with g₃₁ g₃₂
1450
+ . have hq: q = 5 := by linarith
1451
+ constructor
1452
+ . exact hq
1453
+ . rw [hq] at g₂
1454
+ linarith[g₂]
1455
+ . exfalso
1456
+ cases' g₃₂ with g₃₂ g₃₃
1457
+ . have hq: q = 3 := by linarith[g₃₂]
1458
+ rw [hq] at g₂
1459
+ have hr: r = -7 := by linarith[g₂]
1460
+ linarith[hrl,hr]
1461
+ . cases' g₃₃ with g₃₃ g₃₄
1462
+ . have hq: q = 15 := by linarith[g₃₃]
1463
+ rw [hq] at g₂
1464
+ have hr: r = 5 := by linarith[g₂]
1465
+ linarith[hq,hr,h₀.2]
1466
+ . have hq: q = -7 := by linarith[g₃₄]
1467
+ linarith[hq,hql]
1468
+
1469
+
1470
+ lemma imo_1992_p1_8_1
1471
+ (p q r : ℤ)
1472
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
1473
+ (hpl : p = 2)
1474
+ (hql : 3 ≤ q)
1475
+ (hrl : 4 ≤ r)
1476
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 2) :
1477
+ False := by
1478
+ rw [hpl] at *
1479
+ norm_num at *
1480
+ have g₁: 2 * q + 2 * r = 3 := by
1481
+ linarith
1482
+ linarith [g₁,hql,hrl]
1483
+
1484
+
1485
+ lemma imo_1992_p1_8_2
1486
+ -- (p : ℤ)
1487
+ (q r : ℤ)
1488
+ -- (hql : 3 s≤ q)
1489
+ (hrl : 4 ≤ r)
1490
+ (h₀ : 1 < 3 ∧ 3 < q ∧ q < r)
1491
+ -- (hpl : 2 ≤ 3)
1492
+ -- (hpu : 3 < 4)
1493
+ (hk : 3 * q * r - 1 = (3 - 1) * (q - 1) * (r - 1) * 2) :
1494
+ (3, q, r) = (3, 5, 15) := by
1495
+ norm_num at *
1496
+ have g₂: (4-q)*(4-r) = 11 := by linarith
1497
+ have g₃: (4-q) = -1 ∨ (4-q) = 1 ∨ (4-q) = -11 ∨ (4-q) = 11 := by
1498
+ refine imo_1992_p1_7 (4-q) (4-r) 11 g₂ ?_
1499
+ decide
1500
+ cases' g₃ with g₃₁ g₃₂
1501
+ . have hq: q = 5 := by linarith
1502
+ constructor
1503
+ . exact hq
1504
+ . rw [hq] at g₂
1505
+ linarith[g₂]
1506
+ . exfalso
1507
+ cases' g₃₂ with g₃₂ g₃₃
1508
+ . have hq: q = 3 := by linarith[g₃₂]
1509
+ rw [hq] at g₂
1510
+ have hr: r = -7 := by linarith[g₂]
1511
+ linarith[hrl,hr]
1512
+ . cases' g₃₃ with g₃₃ g₃₄
1513
+ . have hq: q = 15 := by linarith[g₃₃]
1514
+ rw [hq] at g₂
1515
+ have hr: r = 5 := by linarith[g₂]
1516
+ linarith[hq,hr,h₀.2]
1517
+ . linarith
1518
+
1519
+
1520
+ lemma imo_1992_p1_8_3
1521
+ -- (p : ℤ)
1522
+ (q r : ℤ)
1523
+ -- (hql : 3 ≤ q)
1524
+ -- (hrl : 4 ≤ r)
1525
+ -- (h₀ : 3 < q ∧ q < r)
1526
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1527
+ -- g₁ : q * r - 4 * q - 4 * r + 5 = 0
1528
+ (g₂ : (4 - q) * (4 - r) = 11) :
1529
+ 4 - q = -1 ∨ 4 - q = 1 ∨ 4 - q = -11 ∨ 4 - q = 11 := by
1530
+ refine imo_1992_p1_7 (4-q) (4-r) 11 g₂ ?_
1531
+ decide
1532
+
1533
+
1534
+ lemma imo_1992_p1_8_4
1535
+ -- (p : ℤ)
1536
+ (q r : ℤ)
1537
+ -- (hql : 3 ≤ q)
1538
+ -- (hrl : 4 ≤ r)
1539
+ -- (h₀ : 3 < q ∧ q < r)
1540
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1541
+ -- (g₁ : q * r - 4 * q - 4 * r + 5 = 0)
1542
+ (g₂ : (4 - q) * (4 - r) = 11)
1543
+ (g₃₁ : 4 - q = -1) :
1544
+ q = 5 ∧ r = 15 := by
1545
+ have hq: q = 5 := by linarith
1546
+ constructor
1547
+ . exact hq
1548
+ . rw [hq] at g₂
1549
+ linarith[g₂]
1550
+
1551
+
1552
+ lemma imo_1992_p1_8_5
1553
+ -- (p : ℤ)
1554
+ (q r : ℤ)
1555
+ -- (hql : 3 ≤ q)
1556
+ (hrl : 4 ≤ r)
1557
+ (h₀ : 3 < q ∧ q < r)
1558
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1559
+ -- (g₁ : q * r - 4 * q - 4 * r + 5 = 0)
1560
+ (g₂ : (4 - q) * (4 - r) = 11)
1561
+ (g₃₂ : 4 - q = 1 ∨ 4 - q = -11 ∨ 4 - q = 11) :
1562
+ False := by
1563
+ cases' g₃₂ with g₃₂ g₃₃
1564
+ . have hq: q = 3 := by linarith[g₃₂]
1565
+ rw [hq] at g₂
1566
+ have hr: r = -7 := by linarith[g₂]
1567
+ linarith[hrl,hr]
1568
+ . cases' g₃₃ with g₃₃ g₃₄
1569
+ . have hq: q = 15 := by linarith[g₃₃]
1570
+ rw [hq] at g₂
1571
+ have hr: r = 5 := by linarith[g₂]
1572
+ linarith[hq,hr,h₀.2]
1573
+ . linarith
1574
+
1575
+
1576
+ lemma imo_1992_p1_8_6
1577
+ -- (p : ℤ)
1578
+ (q r : ℤ)
1579
+ -- (hql : 3 ≤ q)
1580
+ (hrl : 4 ≤ r)
1581
+ (h₀ : 3 < q ∧ q < r)
1582
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1583
+ -- (g₁ : q * r - 4 * q - 4 * r + 5 = 0)
1584
+ (g₂ : (4 - q) * (4 - r) = 11)
1585
+ (g₃₂ : 4 - q = 1) :
1586
+ False := by
1587
+ have hq: q = 3 := by linarith[g₃₂]
1588
+ rw [hq] at g₂
1589
+ have hr: r = -7 := by linarith[g₂]
1590
+ linarith[hrl,hr]
1591
+
1592
+
1593
+ lemma imo_1992_p1_8_7
1594
+ -- (p : ℤ)
1595
+ (q r : ℤ)
1596
+ -- (hql : 3 ≤ q)
1597
+ -- (hrl : 4 ≤ r)
1598
+ (h₀ : 3 < q ∧ q < r)
1599
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1600
+ -- (g₁ : q * r - 4 * q - 4 * r + 5 = 0)
1601
+ (g₂ : (4 - q) * (4 - r) = 11)
1602
+ (g₃₃ : 4 - q = -11) :
1603
+ False := by
1604
+ have hq: q = 15 := by linarith[g₃₃]
1605
+ rw [hq] at g₂
1606
+ have hr: r = 5 := by linarith[g₂]
1607
+ linarith[hq,hr,h₀.2]
1608
+
1609
+
1610
+ lemma imo_1992_p1_8_8
1611
+ -- (p : ℤ)
1612
+ (q r : ℤ)
1613
+ -- (hql : 3 ≤ q)
1614
+ -- (hrl : 4 ≤ r)
1615
+ (h₀ : q < r)
1616
+ (h₁ : 6 < -r)
1617
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 2)
1618
+ -- (g₁ : q * r - 4 * q - 4 * r + 5 = 0)
1619
+ -- (g₂ : (4 - q) * (4 - r) = 11)
1620
+ (g₃₄ : 4 - q = 11) :
1621
+ False := by
1622
+ have h₂: q = -7 := by
1623
+ exact (Int.sub_right_inj 4).mp g₃₄
1624
+ have h₃: -6 ≤ r := by
1625
+ rw [h₂] at h₀
1626
+ exact h₀
1627
+ apply neg_le_neg at h₃
1628
+ exact Lean.Omega.Int.le_lt_asymm h₃ h₁
1629
+
1630
+
1631
+ lemma imo_1992_p1_9
1632
+ (p q r: ℤ)
1633
+ (h₀: 1 < p ∧ p < q ∧ q < r)
1634
+ (hpl: 2 ≤ p)
1635
+ (hql: 3 ≤ q)
1636
+ (hrl: 4 ≤ r)
1637
+ (hpu: p < 4)
1638
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 3) :
1639
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
1640
+ interval_cases p
1641
+ -- p = 2
1642
+ . norm_num at *
1643
+ have g₂: (q - 3) * (r - 3) = 5 := by linarith
1644
+ have g₃: (q - 3) = -1 ∨ (q - 3) = 1 ∨ (q - 3) = -5 ∨ (q - 3) = 5 := by
1645
+ refine imo_1992_p1_7 (q - 3) (r - 3) 5 g₂ ?_
1646
+ decide
1647
+ cases' g₃ with g₃₁ g₃₂
1648
+ . exfalso
1649
+ linarith [hql,g₃₁]
1650
+ . cases' g₃₂ with g₃₂ g₃₃
1651
+ . have hq: q = 4 := by linarith
1652
+ rw [hq] at g₂
1653
+ have hr: r = 8 := by linarith[g₂]
1654
+ exact { left := hq, right := hr }
1655
+ . exfalso
1656
+ cases' g₃₃ with g₃₃ g₃₄
1657
+ . linarith[hql,g₃₃]
1658
+ . have hq: q = 8 := by linarith
1659
+ rw [hq] at g₂
1660
+ norm_num at g₂
1661
+ have hr: r = 4 := by linarith
1662
+ linarith[hrl,hr]
1663
+ . right
1664
+ norm_num at *
1665
+ have g₂: (6 - 3*q) * (2 - r) = 5 := by linarith
1666
+ have g₃: (6 - 3*q) = -1 ∨ (6 - 3*q) = 1 ∨ (6 - 3*q) = -5 ∨ (6 - 3*q) = 5 := by
1667
+ refine imo_1992_p1_7 (6 - 3*q) (2 - r) 5 g₂ ?_
1668
+ decide
1669
+ exfalso
1670
+ cases' g₃ with g₃₁ g₃₂
1671
+ . linarith[g₃₁,q]
1672
+ . cases' g₃₂ with g₃₂ g₃₃
1673
+ . linarith[g₃₂,q]
1674
+ . cases' g₃₃ with g₃₃ g₃₄
1675
+ . linarith[g₃₃,q]
1676
+ . linarith[g₃₄,q]
1677
+
1678
+
1679
+
1680
+ lemma imo_1992_p1_9_1
1681
+ (q r : ℤ)
1682
+ (hql : 3 ≤ q)
1683
+ (hrl : 4 ≤ r)
1684
+ (h₀ : 2 < q ∧ q < r)
1685
+ (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3) :
1686
+ q = 4 ∧ r = 8 := by
1687
+ have g₂: (q - 3) * (r - 3) = 5 := by linarith
1688
+ have g₃: (q - 3) = -1 ∨ (q - 3) = 1 ∨ (q - 3) = -5 ∨ (q - 3) = 5 := by
1689
+ refine imo_1992_p1_7 (q - 3) (r - 3) 5 g₂ ?_
1690
+ decide
1691
+ cases' g₃ with g₃₁ g₃₂
1692
+ . exfalso
1693
+ linarith [hql,g₃₁]
1694
+ . cases' g₃₂ with g₃₂ g₃₃
1695
+ . have hq: q = 4 := by linarith
1696
+ rw [hq] at g₂
1697
+ have hr: r = 8 := by linarith[g₂]
1698
+ exact { left := hq, right := hr }
1699
+ . exfalso
1700
+ cases' g₃₃ with g₃₃ g₃₄
1701
+ . linarith[hql,g₃₃]
1702
+ . have hq: q = 8 := by linarith
1703
+ rw [hq] at g₂
1704
+ norm_num at g₂
1705
+ have hr: r = 4 := by linarith
1706
+ linarith[hrl,hr]
1707
+
1708
+
1709
+
1710
+ lemma imo_1992_p1_9_2
1711
+ (q r : ℤ)
1712
+ (hql : 3 ≤ q)
1713
+ (hrl : 4 ≤ r)
1714
+ (h₀ : 2 < q ∧ q < r)
1715
+ (g₂ : (q - 3) * (r - 3) = 5) :
1716
+ q = 4 ∧ r = 8 := by
1717
+ have g₃: (q - 3) = -1 ∨ (q - 3) = 1 ∨ (q - 3) = -5 ∨ (q - 3) = 5 := by
1718
+ refine imo_1992_p1_7 (q - 3) (r - 3) 5 g₂ ?_
1719
+ decide
1720
+ cases' g₃ with g₃₁ g₃₂
1721
+ . exfalso
1722
+ linarith [hql,g₃₁]
1723
+ . cases' g₃₂ with g₃₂ g₃₃
1724
+ . have hq: q = 4 := by linarith
1725
+ rw [hq] at g₂
1726
+ have hr: r = 8 := by linarith[g₂]
1727
+ exact { left := hq, right := hr }
1728
+ . exfalso
1729
+ cases' g₃₃ with g₃₃ g₃₄
1730
+ . linarith[hql,g₃₃]
1731
+ . have hq: q = 8 := by linarith
1732
+ rw [hq] at g₂
1733
+ norm_num at g₂
1734
+ have hr: r = 4 := by linarith
1735
+ linarith[hrl,hr]
1736
+
1737
+
1738
+ lemma imo_1992_p1_9_3
1739
+ (q r : ℤ)
1740
+ (g₂ : (q - 3) * (r - 3) = 5) :
1741
+ q - 3 = -1 ∨ q - 3 = 1 ∨ q - 3 = -5 ∨ q - 3 = 5 := by
1742
+ refine imo_1992_p1_7 (q - 3) (r - 3) 5 g₂ ?_
1743
+ decide
1744
+
1745
+
1746
+ lemma imo_1992_p1_9_4
1747
+ -- (p : ℤ)
1748
+ (q r : ℤ)
1749
+ (hql : 3 ≤ q)
1750
+ (hrl : 4 ≤ r)
1751
+ (h₀ : 2 < q ∧ q < r)
1752
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1753
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1754
+ (g₂ : (q - 3) * (r - 3) = 5)
1755
+ (g₃ : q - 3 = -1 ∨ q - 3 = 1 ∨ q - 3 = -5 ∨ q - 3 = 5) :
1756
+ q = 4 ∧ r = 8 := by
1757
+ cases' g₃ with g₃₁ g₃₂
1758
+ . exfalso
1759
+ linarith [hql,g₃₁]
1760
+ . cases' g₃₂ with g₃₂ g₃₃
1761
+ . have hq: q = 4 := by linarith
1762
+ rw [hq] at g₂
1763
+ have hr: r = 8 := by linarith[g₂]
1764
+ exact { left := hq, right := hr }
1765
+ . exfalso
1766
+ cases' g₃₃ with g₃₃ g₃₄
1767
+ . linarith[hql,g₃₃]
1768
+ . have hq: q = 8 := by linarith
1769
+ rw [hq] at g₂
1770
+ norm_num at g₂
1771
+ have hr: r = 4 := by linarith
1772
+ linarith[hrl,hr]
1773
+
1774
+
1775
+ lemma imo_1992_p1_9_5
1776
+ -- (p : ℤ)
1777
+ (q r : ℤ)
1778
+ (hql : 3 ≤ q)
1779
+ -- (hrl : 4 ≤ r)
1780
+ -- (h₀ : 2 < q ∧ q < r)
1781
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1782
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1783
+ -- (g₂ : (q - 3) * (r - 3) = 5)
1784
+ (g₃₁ : q - 3 = -1) :
1785
+ q = 4 ∧ r = 8 := by
1786
+ exfalso
1787
+ linarith [hql,g₃₁]
1788
+
1789
+
1790
+ lemma imo_1992_p1_9_6
1791
+ -- (p r : ℤ)
1792
+ (q r : ℤ)
1793
+ (hql : 3 ≤ q)
1794
+ (hrl : 4 ≤ r)
1795
+ -- (h₀ : 2 < q ∧ q < r)
1796
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1797
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1798
+ -- (g₂ : (q - 3) * (r - 3) = 5)
1799
+ (g₃₁ : r * (q - 4) < r * (3 - r)) :
1800
+ False := by
1801
+ have h₀: 3 - r ≤ q - 4 := by
1802
+ exact sub_le_sub hql hrl
1803
+ have h₀: r * (3 - r) ≤ r * (q - 4) := by
1804
+ refine (mul_le_mul_left ?_).mpr h₀
1805
+ linarith
1806
+ linarith
1807
+
1808
+
1809
+ lemma imo_1992_p1_9_7
1810
+ -- (p : ℤ)
1811
+ (q r : ℤ)
1812
+ (hql : 3 ≤ q)
1813
+ (hrl : 4 ≤ r)
1814
+ (h₀ : 2 < q ∧ q < r)
1815
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1816
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1817
+ (g₂ : (q - 3) * (r - 3) = 5)
1818
+ (g₃₂ : q - 3 = 1 ∨ q - 3 = -5 ∨ q - 3 = 5) :
1819
+ q = 4 ∧ r = 8 := by
1820
+ cases' g₃₂ with g₃₂ g₃₃
1821
+ . have hq: q = 4 := by linarith
1822
+ rw [hq] at g₂
1823
+ have hr: r = 8 := by linarith[g₂]
1824
+ exact { left := hq, right := hr }
1825
+ . exfalso
1826
+ cases' g₃₃ with g₃₃ g₃₄
1827
+ . linarith[hql,g₃₃]
1828
+ . have hq: q = 8 := by linarith
1829
+ rw [hq] at g₂
1830
+ norm_num at g₂
1831
+ have hr: r = 4 := by linarith
1832
+ linarith[hrl,hr]
1833
+
1834
+
1835
+ lemma imo_1992_p1_9_8
1836
+ -- (p : ℤ)
1837
+ (q r : ℤ)
1838
+ -- (hql : 3 ≤ q)
1839
+ -- (hrl : 4 ≤ r)
1840
+ -- (h₀ : 2 < q ∧ q < r)
1841
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1842
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1843
+ (g₂ : (q - 3) * (r - 3) = 5)
1844
+ (g₃₂ : q - 3 = 1) :
1845
+ q = 4 ∧ r = 8 := by
1846
+ have hq: q = 4 := by linarith
1847
+ rw [hq] at g₂
1848
+ have hr: r = 8 := by linarith[g₂]
1849
+ exact { left := hq, right := hr }
1850
+
1851
+
1852
+ lemma imo_1992_p1_9_9
1853
+ -- (p : ℤ)
1854
+ (q r : ℤ)
1855
+ -- (hql : 3 ≤ q)
1856
+ -- (hrl : 4 ≤ r)
1857
+ -- (h₀ : 2 < q ∧ q < r)
1858
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1859
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1860
+ (g₂ : (q - 3) * (r - 3) = 5)
1861
+ (g₃₂ : q - 3 = 1)
1862
+ (hq : q = 4) :
1863
+ q = 4 ∧ r = 8 := by
1864
+ rw [hq] at g₂
1865
+ have hr: r = 8 := by linarith[g₂]
1866
+ exact { left := hq, right := hr }
1867
+
1868
+
1869
+ lemma imo_1992_p1_9_10
1870
+ -- (p : ℤ)
1871
+ (q r : ℤ)
1872
+ (hql : 3 ≤ q)
1873
+ (hrl : 4 ≤ r)
1874
+ (h₀ : 2 < q ∧ q < r)
1875
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1876
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1877
+ (g₂ : (q - 3) * (r - 3) = 5)
1878
+ (g₃₃ : q - 3 = -5 ∨ q - 3 = 5) :
1879
+ False := by
1880
+ cases' g₃₃ with g₃₃ g₃₄
1881
+ . linarith[hql,g₃₃]
1882
+ . have hq: q = 8 := by linarith
1883
+ rw [hq] at g₂
1884
+ norm_num at g₂
1885
+ have hr: r = 4 := by linarith
1886
+ linarith[hrl,hr]
1887
+
1888
+
1889
+ lemma imo_1992_p1_9_11
1890
+ -- (p : ℤ)
1891
+ (q r : ℤ)
1892
+ -- (hql : 3 ≤ q)
1893
+ (hrl : 4 ≤ r)
1894
+ (h₀ : 2 < q ∧ q < r)
1895
+ -- (hk : 2 * q * r - 1 = (q - 1) * (r - 1) * 3)
1896
+ -- (g₁ : q * r - 3 * q - 3 * r + 4 = 0)
1897
+ (g₂ : (q - 3) * (r - 3) = 5)
1898
+ (g₃₄ : q - 3 = 5) :
1899
+ False := by
1900
+ have hq: q = 8 := by linarith
1901
+ rw [hq] at g₂
1902
+ norm_num at g₂
1903
+ have hr: r = 4 := by linarith
1904
+ linarith[hrl,hr]
1905
+
1906
+
1907
+ lemma imo_1992_p1_9_12
1908
+ -- (p : ℤ)
1909
+ (q r : ℤ)
1910
+ -- (hql : 3 ≤ q)
1911
+ -- (hrl : 4 ≤ r)
1912
+ (h₀ : 3 < q ∧ q < r)
1913
+ (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 3) :
1914
+ q = 5 ∧ r = 15 := by
1915
+ have g₂: (6 - 3*q) * (2 - r) = 5 := by linarith
1916
+ have g₃: (6 - 3*q) = -1 ∨ (6 - 3*q) = 1 ∨ (6 - 3*q) = -5 ∨ (6 - 3*q) = 5 := by
1917
+ refine imo_1992_p1_7 (6 - 3*q) (2 - r) 5 g₂ ?_
1918
+ decide
1919
+ exfalso
1920
+ cases' g₃ with g₃₁ g₃₂
1921
+ . linarith[g₃₁,q]
1922
+ . cases' g₃₂ with g₃₂ g₃₃
1923
+ . linarith[g₃₂,q]
1924
+ . cases' g₃₃ with g₃₃ g₃₄
1925
+ . linarith[g₃₃,q]
1926
+ . linarith[g₃₄,q]
1927
+
1928
+
1929
+ lemma imo_1992_p1_9_13
1930
+ -- (p : ℤ)
1931
+ (q r : ℤ)
1932
+ -- (hql : 3 ≤ q)
1933
+ -- (hrl : 4 ≤ r)
1934
+ (h₀ : 3 < q ∧ q < r)
1935
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 3)
1936
+ -- (g₁ : 3 * q * r - 6 * q - 6 * r + 7 = 0)
1937
+ (g₂ : (6 - 3 * q) * (2 - r) = 5) :
1938
+ False := by
1939
+ have g₃: (6 - 3*q) = -1 ∨ (6 - 3*q) = 1 ∨ (6 - 3*q) = -5 ∨ (6 - 3*q) = 5 := by
1940
+ refine imo_1992_p1_7 (6 - 3*q) (2 - r) 5 g₂ ?_
1941
+ decide
1942
+ exfalso
1943
+ cases' g₃ with g₃₁ g₃₂
1944
+ . linarith[g₃₁,q]
1945
+ . cases' g₃₂ with g₃₂ g₃₃
1946
+ . linarith[g₃₂,q]
1947
+ . cases' g₃₃ with g₃₃ g₃₄
1948
+ . linarith[g₃₃,q]
1949
+ . linarith[g₃₄,q]
1950
+
1951
+
1952
+ lemma imo_1992_p1_9_14
1953
+ -- (p : ℤ)
1954
+ (q r : ℤ)
1955
+ -- (hql : 3 ≤ q)
1956
+ -- (hrl : 4 ≤ r)
1957
+ -- (h₀ : 3 < q ∧ q < r)
1958
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 3)
1959
+ -- (g₁ : 3 * q * r - 6 * q - 6 * r + 7 = 0)
1960
+ (g₂ : (6 - 3 * q) * (2 - r) = 5) :
1961
+ 6 - 3 * q = -1 ∨ 6 - 3 * q = 1 ∨ 6 - 3 * q = -5 ∨ 6 - 3 * q = 5 := by
1962
+ refine imo_1992_p1_7 (6 - 3*q) (2 - r) 5 g₂ ?_
1963
+ decide
1964
+
1965
+ lemma imo_1992_p1_9_15
1966
+ -- (p : ℤ)
1967
+ (q r : ℤ)
1968
+ -- (hql : 3 ≤ q)
1969
+ -- (hrl : 4 ≤ r)
1970
+ (h₀ : 3 < q ∧ q < r)
1971
+ -- (hk : 3 * q * r - 1 = 2 * (q - 1) * (r - 1) * 3)
1972
+ -- (g₁ : 3 * q * r - 6 * q - 6 * r + 7 = 0)
1973
+ -- (g₂ : (6 - 3 * q) * (2 - r) = 5)
1974
+ (g₃ : 6 - 3 * q = -1 ∨ 6 - 3 * q = 1 ∨ 6 - 3 * q = -5 ∨ 6 - 3 * q = 5) :
1975
+ False := by
1976
+ exfalso
1977
+ cases' g₃ with g₃₁ g₃₂
1978
+ . linarith[g₃₁,q]
1979
+ . cases' g₃₂ with g₃₂ g₃₃
1980
+ . linarith[g₃₂,q]
1981
+ . cases' g₃₃ with g₃₃ g₃₄
1982
+ . linarith[g₃₃,q]
1983
+ . linarith[g₃₄,q]
1984
+
1985
+
1986
+ lemma q_of_qr_eq_11_nat
1987
+ (q r : ℕ)
1988
+ (h₀ : q * r = 11) :
1989
+ q = 1 ∨ q = 11 := by
1990
+ have h₁: Nat.Prime (11:ℕ) := by decide
1991
+ have h₂: ↑q ∣ 11 := by
1992
+ exact Dvd.intro r h₀
1993
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ q h₂
1994
+
1995
+
1996
+ lemma abs_q_r_product
1997
+ (q r : ℤ)
1998
+ (h₀ : q * r = 11) :
1999
+ q.natAbs * r.natAbs = (11:ℕ) := by
2000
+ exact Int.natAbs_mul_natAbs_eq h₀
2001
+ -- Since q * r = 11, taking the absolute value of both sides gives |q * r| = 11.
2002
+ -- By properties of absolute values, |q * r| = |q| * |r|.
2003
+
2004
+
2005
+ lemma myprime5 : Nat.Prime 5 := by
2006
+ rw [Nat.prime_def_lt']
2007
+ constructor
2008
+ . norm_num
2009
+ . intros m hm mu
2010
+ interval_cases m
2011
+ all_goals {try norm_num }
2012
+
2013
+
2014
+
2015
+ lemma abs_q_r_product_2
2016
+ (q r : ℤ)
2017
+ (h₀ : q * r = (11:ℕ)) :
2018
+ abs q * abs r = 11 := by
2019
+ have h₁: q.natAbs * r.natAbs = (11:ℕ) := by
2020
+ exact Int.natAbs_mul_natAbs_eq h₀
2021
+ have h₃: abs q = q.natAbs := by exact abs_eq_natAbs q
2022
+ have h₄: abs r = r.natAbs := by exact abs_eq_natAbs r
2023
+ rw [h₃,h₄]
2024
+ norm_cast
2025
+
2026
+
2027
+ lemma imo_1992_p1_19_1
2028
+ (p q r : ℤ)
2029
+ -- (h₀ : 1 < p ∧ p < q ∧ q < r)
2030
+ (k : ℤ)
2031
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
2032
+ -- (hpl : 2 ≤ p)
2033
+ -- (hql : 3 ≤ q)
2034
+ -- (hrl : 4 ≤ r)
2035
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1)) :
2036
+ ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
2037
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
2038
+ norm_cast
2039
+ linarith
2040
+ symm
2041
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
2042
+ norm_cast
2043
+ linarith[hden]
2044
+ exact (div_eq_iff g₂).mpr g₁
2045
+
2046
+
2047
+ lemma imo_1992_p1_19_2
2048
+ (p q r : ℤ)
2049
+ -- (h₀ : 1 < p ∧ p < q ∧ q < r)
2050
+ (k : ℤ)
2051
+ -- (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
2052
+ -- (hpl : 2 ≤ p)
2053
+ -- (hql : 3 ≤ q)
2054
+ -- (hrl : 4 ≤ r)
2055
+ (hden : 0 < (p - 1) * (q - 1) * (r - 1))
2056
+ (g₁ : ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ)) :
2057
+ ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
2058
+ symm
2059
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
2060
+ norm_cast
2061
+ linarith[hden]
2062
+ exact (div_eq_iff g₂).mpr g₁
2063
+
2064
+
2065
+ lemma imo_1992_p1_19_3
2066
+ (p q r : ℤ)
2067
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
2068
+ (k : ℤ)
2069
+ (hk : p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
2070
+ (hpl : 2 ≤ p)
2071
+ (hql : 3 ≤ q)
2072
+ (hrl : 4 ≤ r)
2073
+ -- (hden : 0 < (p - 1) * (q - 1) * (r - 1))
2074
+ (h₁ : ↑k = ↑(p * q * r - 1) / ↑((p - 1) * (q - 1) * (r - 1)))
2075
+ (hk4 : k < 4)
2076
+ (hk1 : 1 < k)
2077
+ (hpu : p < 4) :
2078
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
2079
+ interval_cases k
2080
+ . exact imo_1992_p1_8 p q r h₀ hpl hql hrl hpu hk
2081
+ . exact imo_1992_p1_9 p q r h₀ hpl hql hrl hpu hk
Lemmas/imo_1997_p5_lemmas.lean ADDED
@@ -0,0 +1,2926 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat Real
5
+
6
+
7
+ lemma imo_1997_p5_1
8
+ (x y : ℕ)
9
+ (h₀ : 0 < x ∧ 0 < y)
10
+ -- (g : x ^ y ^ 2 = (x ^ y) ^ y)
11
+ (hxy : x ≤ y)
12
+ (h₁ : (x ^ y) ^ y = y ^ x) :
13
+ x ^ y ≤ y := by
14
+ by_contra! hc
15
+ have h₂: y^x ≤ y^y := by
16
+ { exact Nat.pow_le_pow_of_le_right h₀.2 hxy }
17
+ have h₃: y^y < (x^y)^y := by
18
+ refine Nat.pow_lt_pow_left hc ?_
19
+ refine Nat.pos_iff_ne_zero.mp h₀.2
20
+ rw [h₁] at h₃
21
+ linarith [h₂, h₃]
22
+
23
+
24
+ lemma imo_1997_p5_1_1
25
+ (x y : ℕ)
26
+ (h₀ : 0 < x ∧ 0 < y)
27
+ (hxy : x ≤ y)
28
+ (h₁ : (x ^ y) ^ y = y ^ x)
29
+ (hc : y < x ^ y) :
30
+ False := by
31
+ have h₂: y^x ≤ y^y := by
32
+ { exact Nat.pow_le_pow_of_le_right h₀.2 hxy }
33
+ have h₃: y^y < (x^y)^y := by
34
+ refine Nat.pow_lt_pow_left hc ?_
35
+ refine Nat.pos_iff_ne_zero.mp h₀.2
36
+ rw [h₁] at h₃
37
+ linarith [h₂, h₃]
38
+
39
+
40
+ lemma imo_1997_p5_1_2
41
+ (x y : ℕ)
42
+ (h₀ : 0 < x ∧ 0 < y)
43
+ -- (hxy : x ≤ y)
44
+ (h₁ : (x ^ y) ^ y = y ^ x)
45
+ (hc : y < x ^ y)
46
+ (h₂ : y ^ x ≤ y ^ y) :
47
+ False := by
48
+ have h₃: y^y < (x^y)^y := by
49
+ refine Nat.pow_lt_pow_left hc ?_
50
+ refine Nat.pos_iff_ne_zero.mp h₀.2
51
+ rw [h₁] at h₃
52
+ linarith [h₂, h₃]
53
+
54
+
55
+ lemma imo_1997_p5_1_3
56
+ (x y : ℕ)
57
+ (h₀ : 0 < x ∧ 0 < y)
58
+ -- (hxy : x ≤ y)
59
+ -- (h₁ : (x ^ y) ^ y = y ^ x)
60
+ (hc : y < x ^ y) :
61
+ -- (h₂ : y ^ x ≤ y ^ y) :
62
+ y ^ y < (x ^ y) ^ y := by
63
+ refine Nat.pow_lt_pow_left hc ?_
64
+ exact Nat.pos_iff_ne_zero.mp h₀.2
65
+
66
+
67
+ lemma imo_1997_p5_2
68
+ (k : ℕ)
69
+ (hk : 5 ≤ k) :
70
+ 4 * k < 2 ^ k := by
71
+ -- Proceed by induction on k
72
+ induction' k using Nat.case_strong_induction_on with n ih
73
+ -- Base case: k = 0 is not possible since 5 ≤ k
74
+ -- so we start directly with k = 5 as the base case
75
+ . norm_num
76
+ by_cases h₀ : n < 5
77
+ . have hn: n = 4 := by linarith
78
+ rw [hn]
79
+ norm_num
80
+ . push_neg at h₀
81
+ have ih₁ : 4 * n < 2 ^ n := ih n (le_refl n) h₀
82
+ rw [mul_add, pow_add, mul_one, pow_one, mul_two]
83
+ refine Nat.add_lt_add ih₁ ?_
84
+ refine lt_trans ?_ ih₁
85
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
86
+ refine Nat.lt_of_lt_of_le ?_ h₀
87
+ norm_num
88
+
89
+
90
+ lemma imo_1997_p5_2_1
91
+ (n : ℕ)
92
+ (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
93
+ (hk : 5 ≤ succ n) :
94
+ 4 * succ n < 2 ^ succ n := by
95
+ by_cases h₀ : n < 5
96
+ . rw [succ_eq_add_one] at hk
97
+ have hn: n = 4 := by linarith
98
+ rw [hn]
99
+ norm_num
100
+ . push_neg at h₀
101
+ have ih₁ : 4 * n < 2 ^ n := ih n (le_refl n) h₀
102
+ rw [succ_eq_add_one, mul_add, pow_add, mul_one, pow_one, mul_two]
103
+ refine Nat.add_lt_add ih₁ ?_
104
+ refine lt_trans ?_ ih₁
105
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
106
+ refine Nat.lt_of_lt_of_le ?_ h₀
107
+ norm_num
108
+
109
+
110
+ lemma imo_1997_p5_2_2
111
+ (n : ℕ)
112
+ -- (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
113
+ (hk : 5 ≤ succ n)
114
+ (h₀ : n < 5) :
115
+ 4 * succ n < 2 ^ succ n := by
116
+ rw [succ_eq_add_one] at hk
117
+ have hn: n = 4 := by linarith
118
+ rw [hn]
119
+ norm_num
120
+
121
+
122
+ lemma imo_1997_p5_2_3
123
+ (n : ℕ)
124
+ (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
125
+ -- (hk : 5 ≤ succ n)
126
+ (h₀ : 5 ≤ n) :
127
+ 4 * succ n < 2 ^ succ n := by
128
+ have ih₁ : 4 * n < 2 ^ n := ih n (le_refl n) h₀
129
+ rw [succ_eq_add_one, mul_add, pow_add, mul_one, pow_one, mul_two]
130
+ refine Nat.add_lt_add ih₁ ?_
131
+ refine lt_trans ?_ ih₁
132
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
133
+ refine Nat.lt_of_lt_of_le ?_ h₀
134
+ norm_num
135
+
136
+
137
+ lemma imo_1997_p5_2_4
138
+ (n : ℕ)
139
+ -- (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
140
+ -- (hk : 5 ≤ succ n)
141
+ (h₀ : 5 ≤ n)
142
+ (ih₁ : 4 * n < 2 ^ n) :
143
+ 4 * succ n < 2 ^ succ n := by
144
+ rw [succ_eq_add_one, mul_add, pow_add, mul_one, pow_one, mul_two]
145
+ refine Nat.add_lt_add ih₁ ?_
146
+ refine lt_trans ?_ ih₁
147
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
148
+ refine Nat.lt_of_lt_of_le ?_ h₀
149
+ norm_num
150
+
151
+
152
+ lemma imo_1997_p5_2_5
153
+ (n : ℕ)
154
+ -- (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
155
+ -- (hk : 5 ≤ succ n)
156
+ (h₀ : 5 ≤ n)
157
+ (ih₁ : 4 * n < 2 ^ n) :
158
+ 4 * n + 4 < 2 ^ n + 2 ^ n := by
159
+ refine Nat.add_lt_add ih₁ ?_
160
+ refine lt_trans ?_ ih₁
161
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
162
+ refine Nat.lt_of_lt_of_le ?_ h₀
163
+ norm_num
164
+
165
+
166
+ lemma imo_1997_p5_2_6
167
+ (n : ℕ)
168
+ -- (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
169
+ -- (hk : 5 ≤ succ n)
170
+ (h₀ : 5 ≤ n)
171
+ (ih₁ : 4 * n < 2 ^ n) :
172
+ 4 < 2 ^ n := by
173
+ refine lt_trans ?_ ih₁
174
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
175
+ refine Nat.lt_of_lt_of_le ?_ h₀
176
+ norm_num
177
+
178
+
179
+ lemma imo_1997_p5_2_7
180
+ (n : ℕ)
181
+ -- (ih : ∀ m ≤ n, 5 ≤ m → 4 * m < 2 ^ m)
182
+ -- (hk : 5 ≤ succ n)
183
+ (h₀ : 5 ≤ n) :
184
+ -- (ih₁ : 4 * n < 2 ^ n) :
185
+ 4 < 4 * n := by
186
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
187
+ refine Nat.lt_of_lt_of_le ?_ h₀
188
+ norm_num
189
+
190
+
191
+ lemma imo_1997_p5_3
192
+ (x y : ℕ)
193
+ (h₀ : 0 < x ∧ 0 < y)
194
+ (h₁ : x^(y^2) = y^x)
195
+ (g₁ : x^(y^2) = (x^y)^y)
196
+ (hxy : x ≤ y) :
197
+ (x, y) = (1, 1) ∨ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
198
+ rw [g₁] at h₁
199
+ have g2: x^y ≤ y := by
200
+ exact imo_1997_p5_1 x y h₀ hxy h₁
201
+ have g3: x = 1 := by
202
+ by_contra! hc
203
+ have g3: 2 ≤ x := by
204
+ by_contra! gc
205
+ interval_cases x
206
+ . linarith
207
+ . omega
208
+ have g4: 2 ^ y ≤ x ^ y := by { exact Nat.pow_le_pow_of_le_left g3 y }
209
+ have g5: y < 2 ^ y := by exact Nat.lt_two_pow_self
210
+ linarith
211
+ rw [g3] at h₁
212
+ simp at h₁
213
+ left
214
+ norm_num
215
+ exact { left := g3, right := id h₁.symm }
216
+
217
+
218
+ lemma imo_1997_p5_3_1
219
+ (x y : ℕ)
220
+ (h₀ : 0 < x ∧ 0 < y)
221
+ (h₁ : (x ^ y) ^ y = y ^ x)
222
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
223
+ (hxy : x ≤ y)
224
+ (g₂ : x ^ y ≤ y) :
225
+ (x, y) = (1, 1) := by
226
+ have g₃: x = 1 := by
227
+ by_contra! hc
228
+ have g3: 2 ≤ x := by
229
+ by_contra! gc
230
+ interval_cases x
231
+ . linarith
232
+ . omega
233
+ have g4: 2^y ≤ x^y := by { exact Nat.pow_le_pow_of_le_left g3 y }
234
+ have g5: y < 2^y := by exact Nat.lt_two_pow_self
235
+ linarith
236
+ rw [g₃] at h₁
237
+ simp at h₁
238
+ norm_num
239
+ exact { left := g₃, right := id h₁.symm }
240
+
241
+
242
+ lemma imo_1997_p5_3_2
243
+ (x y : ℕ)
244
+ (h₀ : 0 < x ∧ 0 < y)
245
+ (h₁ : (x ^ y) ^ y = y ^ x)
246
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
247
+ (hxy : x ≤ y)
248
+ (g2 : x ^ y ≤ y) :
249
+ x = 1 := by
250
+ by_contra! hc
251
+ have g₃: 2 ≤ x := by
252
+ by_contra! gc
253
+ interval_cases x
254
+ . linarith
255
+ . omega
256
+ have g₄: 2^y ≤ x ^ y := by { exact Nat.pow_le_pow_of_le_left g₃ y }
257
+ have g₅: y < 2 ^ y := by exact Nat.lt_two_pow_self
258
+ linarith
259
+
260
+
261
+ lemma imo_1997_p5_3_3
262
+ (x y : ℕ)
263
+ -- (h₀ : 0 < x ∧ 0 < y)
264
+ -- (h₁ : (x ^ y) ^ y = y ^ x)
265
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
266
+ -- (hxy : x ≤ y)
267
+ (g₂ : x ^ y ≤ y)
268
+ -- (hc : ¬x = 1)
269
+ (g₃ : 2 ≤ x) :
270
+ False := by
271
+ have g₄: 2^y ≤ x ^ y := by { exact Nat.pow_le_pow_of_le_left g₃ y }
272
+ have g₅: y < 2 ^ y := by exact Nat.lt_two_pow_self
273
+ linarith
274
+
275
+
276
+ lemma imo_1997_p5_3_4
277
+ (x y : ℕ)
278
+ -- (h₀ : 0 < x ∧ 0 < y)
279
+ -- (h₁ : (x ^ y) ^ y = y ^ x)
280
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
281
+ -- (hxy : x ≤ y)
282
+ (g2 : x ^ y ≤ y)
283
+ -- (hc : ¬x = 1)
284
+ -- (g₃ : 2 ≤ x)
285
+ (g₄ : 2 ^ y ≤ x ^ y) :
286
+ False := by
287
+ have g₅: y < 2 ^ y := by exact Nat.lt_two_pow_self
288
+ linarith
289
+
290
+
291
+ lemma imo_1997_p5_3_5
292
+ (x y : ℕ)
293
+ -- (h₀ : 0 < x ∧ 0 < y)
294
+ -- (h₁ : (x ^ y) ^ y = y ^ x)
295
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
296
+ -- (hxy : x ≤ y)
297
+ -- (g2 : x ^ y ≤ y)
298
+ -- (hc : ¬x = 1)
299
+ (g₃ : 2 ≤ x) :
300
+ -- (g4 : 2 ^ y ≤ x ^ y) :
301
+ y + 2 < 2 ^ y + x := by
302
+ refine lt_add_of_lt_add_left ?_ g₃
303
+ refine add_lt_add_right ?_ 2
304
+ exact Nat.lt_two_pow_self
305
+
306
+
307
+ lemma imo_1997_p5_3_6
308
+ (x y : ℕ)
309
+ -- (h₀ : 0 < x ∧ 0 < y)
310
+ (h₁ : (x ^ y) ^ y = y ^ x)
311
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
312
+ (hxy : x ≤ y)
313
+ (g₂ : x ^ y ≤ y)
314
+ (g₃ : x = 1) :
315
+ y = 1 := by
316
+ rw [g₃] at h₁
317
+ simp at h₁
318
+ exact id h₁.symm
319
+
320
+
321
+ lemma imo_1997_p5_4
322
+ (x: ℕ)
323
+ (h₀: 0 < x):
324
+ (↑x = Real.exp (Real.log ↑x)):= by
325
+ have hx_pos : 0 < (↑x : ℝ) := by exact Nat.cast_pos.mpr h₀
326
+ symm
327
+ exact Real.exp_log hx_pos
328
+
329
+
330
+ lemma imo_1997_p5_5
331
+ (x y : ℕ)
332
+ (h₀ : 0 < x ∧ 0 < y)
333
+ (h₁ : x ^ y ^ 2 = y ^ x)
334
+ (hxy : y < x) :
335
+ y ^ 2 < x := by
336
+ by_cases hy: 1 < y
337
+ . have hx: 2 ≤ x := by linarith
338
+ have h₂: y ^ x < x ^ x := by
339
+ refine Nat.pow_lt_pow_left hxy ?_
340
+ exact Nat.ne_of_lt' h₀.1
341
+ rw [← h₁] at h₂
342
+ exact (Nat.pow_lt_pow_iff_right hx).mp h₂
343
+ . push_neg at hy
344
+ interval_cases y
345
+ . simp
346
+ exact h₀.1
347
+ . simp at *
348
+ assumption
349
+
350
+
351
+ lemma imo_1997_p5_5_1
352
+ (x y : ℕ)
353
+ (h₀ : 0 < x ∧ 0 < y)
354
+ (h₁ : x ^ y ^ 2 = y ^ x)
355
+ (hxy : y < x)
356
+ (hy : 1 < y) :
357
+ y ^ 2 < x := by
358
+ have hx: 2 ≤ x := by linarith
359
+ have h₂: y ^ x < x ^ x := by
360
+ refine Nat.pow_lt_pow_left hxy ?_
361
+ exact Nat.ne_of_lt' h₀.1
362
+ rw [← h₁] at h₂
363
+ exact (Nat.pow_lt_pow_iff_right hx).mp h₂
364
+
365
+
366
+ lemma imo_1997_p5_5_2
367
+ (x y : ℕ)
368
+ (h₀ : 0 < x ∧ 0 < y)
369
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
370
+ (hxy : y < x) :
371
+ -- (hy : 1 < y)
372
+ -- (hx : 2 ≤ x) :
373
+ y ^ x < x ^ x := by
374
+ refine Nat.pow_lt_pow_left hxy ?_
375
+ exact Nat.ne_of_lt' h₀.1
376
+
377
+
378
+ lemma imo_1997_p5_5_3
379
+ (x y : ℕ)
380
+ -- (h₀ : 0 < x ∧ 0 < y)
381
+ (h₁ : x ^ y ^ 2 = y ^ x)
382
+ -- (hxy : y < x)
383
+ -- (hy : 1 < y)
384
+ (hx : 2 ≤ x)
385
+ (h₂ : y ^ x < x ^ x) :
386
+ y ^ 2 < x := by
387
+ rw [← h₁] at h₂
388
+ exact (Nat.pow_lt_pow_iff_right hx).mp h₂
389
+
390
+
391
+ lemma imo_1997_p5_5_4
392
+ (x y : ℕ)
393
+ (h₀ : 0 < x ∧ 0 < y)
394
+ (h₁ : x ^ y ^ 2 = y ^ x)
395
+ (hxy : y < x)
396
+ (hy : ¬1 < y) :
397
+ y ^ 2 < x := by
398
+ push_neg at hy
399
+ interval_cases y
400
+ . simp
401
+ exact h₀.1
402
+ . simp at *
403
+ assumption
404
+
405
+
406
+ lemma imo_1997_p5_6
407
+ (x y: ℕ)
408
+ (h₀: 0 < x ∧ 0 < y)
409
+ (h₁: x ^ y ^ 2 = y ^ x) :
410
+ (↑x / ↑y^2) ^ y ^ 2 = (↑y:ℝ)^ ((↑x:ℝ) - 2 * ↑y ^ 2) := by
411
+ have g₁: (↑x:ℝ) ^ (↑y:ℝ) ^ 2 = (↑y:ℝ) ^ (↑x:ℝ) := by
412
+ norm_cast
413
+ have g₂: 0 < ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
414
+ norm_cast
415
+ exact pow_pos h₀.2 _
416
+ have g₃: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
417
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
418
+ refine (div_left_inj' ?_).mpr g₁
419
+ norm_cast
420
+ refine pow_ne_zero _ ?_
421
+ linarith [h₀.2]
422
+ have gy: 0 < (↑y:ℝ) := by
423
+ norm_cast
424
+ exact h₀.2
425
+ rw [← Real.rpow_sub gy (↑x) (2 * ↑y ^ 2)] at g₃
426
+ have g₄: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
427
+ = (↑x / ↑y^2) ^ y ^ 2 := by
428
+ have g₅: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
429
+ norm_cast
430
+ refine pow_mul y 2 (y^2)
431
+ rw [g₅]
432
+ symm
433
+ norm_cast
434
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
435
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
436
+ norm_cast at *
437
+ rw [g₄] at g₃
438
+ norm_cast at *
439
+
440
+
441
+ lemma imo_1997_p5_6_1
442
+ (x y : ℕ)
443
+ (h₀ : 0 < x ∧ 0 < y) :
444
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
445
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x) :
446
+ 0 < ↑y ^ (2 * ↑y ^ 2) := by
447
+ exact pow_pos h₀.2 _
448
+
449
+
450
+ lemma imo_1997_p5_6_2
451
+ (x y : ℕ)
452
+ (h₀ : 0 < x ∧ 0 < y)
453
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
454
+ (g₁ : (↑x:ℝ) ^ (↑y:ℝ) ^ 2 = (↑y:ℝ) ^ (↑x:ℝ)) :
455
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2)) :
456
+ (↑x / ↑y ^ 2) ^ y ^ 2 = (↑y:ℝ) ^ ((↑x:ℝ) - 2 * ↑y ^ 2) := by
457
+ have g₃: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
458
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
459
+ refine (div_left_inj' ?_).mpr g₁
460
+ norm_cast
461
+ refine pow_ne_zero _ ?_
462
+ linarith [h₀.2]
463
+ have gy: 0 < (↑y:ℝ) := by
464
+ norm_cast
465
+ exact h₀.2
466
+ rw [← Real.rpow_sub gy (↑x) (2 * ↑y ^ 2)] at g₃
467
+ have g₄: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
468
+ = (↑x / ↑y^2) ^ y ^ 2 := by
469
+ have g₅: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
470
+ norm_cast
471
+ refine pow_mul y 2 (y^2)
472
+ rw [g₅]
473
+ symm
474
+ norm_cast
475
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
476
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
477
+ norm_cast at *
478
+ rw [g₄] at g₃
479
+ norm_cast at *
480
+
481
+
482
+ lemma imo_1997_p5_6_3
483
+ (x y : ℕ)
484
+ (h₀ : 0 < x ∧ 0 < y) :
485
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
486
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
487
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2)) :
488
+ ↑y ^ (2 * ↑y ^ 2) ≠ 0 := by
489
+ norm_cast
490
+ refine pow_ne_zero _ ?_
491
+ linarith [h₀.2]
492
+
493
+
494
+ lemma imo_1997_p5_6_4
495
+ (x y : ℕ)
496
+ (h₀ : 0 < x ∧ 0 < y)
497
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
498
+ (g₁ : (↑x:ℝ) ^ (↑y:ℝ) ^ 2 = (↑y:ℝ) ^ (↑x:ℝ)) :
499
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
500
+ -- (g₃ : ↑x ^ ↑y ^ 2 / ↑y ^ (2 * ↑y ^ 2) = ↑y ^ ↑x / ↑y ^ (2 * ↑y ^ 2))
501
+ -- (gy : 0 < ↑y) :
502
+ ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
503
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
504
+ refine (div_left_inj' ?_).mpr g₁
505
+ norm_cast
506
+ refine pow_ne_zero _ ?_
507
+ linarith [h₀.2]
508
+
509
+
510
+ lemma imo_1997_p5_6_5
511
+ (x y : ℕ)
512
+ -- (h₀ : 0 < x ∧ 0 < y)
513
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
514
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
515
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
516
+ (g₃ : ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
517
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)))
518
+ (gy : 0 < (↑y:ℝ)) :
519
+ (↑x / ↑y ^ 2) ^ y ^ 2 = (↑y:ℝ) ^ ((↑x:ℝ) - 2 * ↑y ^ 2) := by
520
+ rw [← Real.rpow_sub gy (↑x) (2 * ↑y ^ 2)] at g₃
521
+ have g₄: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
522
+ = (↑x / ↑y^2) ^ y ^ 2 := by
523
+ have g₅: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
524
+ norm_cast
525
+ refine pow_mul y 2 (y^2)
526
+ rw [g₅]
527
+ symm
528
+ norm_cast
529
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
530
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
531
+ norm_cast at *
532
+ rw [g₄] at g₃
533
+ norm_cast at *
534
+
535
+
536
+ lemma imo_1997_p5_6_6
537
+ (x y : ℕ)
538
+ -- (h₀ : 0 < x ∧ 0 < y)
539
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
540
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
541
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
542
+ (g₃ : ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
543
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)))
544
+ (gy : 0 < (↑y:ℝ)) :
545
+ ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) = (↑x / ↑y^2) ^ y ^ 2 := by
546
+ have g₅: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
547
+ norm_cast
548
+ refine pow_mul y 2 (y^2)
549
+ rw [g₅]
550
+ symm
551
+ norm_cast
552
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
553
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
554
+ norm_cast at *
555
+
556
+
557
+ lemma imo_1997_p5_6_7
558
+ -- (x : ℕ)
559
+ (x y : ℕ)
560
+ -- (h₀ : 0 < x ∧ 0 < y)
561
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
562
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
563
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
564
+ -- (g₃ : ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
565
+ -- = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)))
566
+ (hy : 0 < y)
567
+ (hxy : y < x) :
568
+ (↑y:ℝ) ^ (2 * (y ^ 2)) < ((↑x:ℝ) ^ 2) ^ (y ^ 2) := by
569
+ rw [pow_mul (↑y:ℝ) 2 (y ^ 2)]
570
+ refine pow_lt_pow_left₀ ?_ ?_ ?_
571
+ . norm_cast
572
+ exact Nat.pow_lt_pow_left hxy (by decide)
573
+ . exact sq_nonneg (↑y:ℝ)
574
+ . symm
575
+ refine Nat.ne_of_lt ?_
576
+ exact pos_pow_of_pos 2 hy
577
+
578
+
579
+ lemma imo_1997_p5_6_8
580
+ (x y : ℕ)
581
+ -- (h₀ : 0 < x ∧ 0 < y)
582
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
583
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
584
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
585
+ (g₃ : ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
586
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)))
587
+ (gy : 0 < (↑y:ℝ))
588
+ (g₅ : (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2)) :
589
+ ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) = (↑x / ↑y^2) ^ y ^ 2 := by
590
+ rw [g₅]
591
+ symm
592
+ norm_cast
593
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
594
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
595
+ norm_cast at *
596
+
597
+
598
+ lemma imo_1997_p5_6_9
599
+ (x y : ℕ)
600
+ -- (h₀ : 0 < x ∧ 0 < y)
601
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
602
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
603
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
604
+ (g₃ : ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
605
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)))
606
+ (gy : 0 < (↑y:ℝ))
607
+ (g₅ : (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2)) :
608
+ ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) = (↑x / ↑y^2) ^ y ^ 2 := by
609
+ rw [g₅]
610
+ symm
611
+ norm_cast
612
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
613
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
614
+ norm_cast at *
615
+
616
+
617
+ lemma imo_1997_p5_6_10
618
+ (x y : ℕ)
619
+ -- (h₀ : 0 < x ∧ 0 < y)
620
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
621
+ -- (g₁ : ↑x ^ ↑y ^ 2 = ↑y ^ ↑x)
622
+ -- (g₂ : 0 < ↑y ^ (2 * ↑y ^ 2))
623
+ (g₃ : ↑x ^ ↑y ^ 2 / ↑y ^ (2 * ↑y ^ 2) = ↑y ^ (↑x - 2 * ↑y ^ 2))
624
+ (gy : 0 < ↑y)
625
+ (g₄ : ↑x ^ ↑y ^ 2 / ↑y ^ (2 * ↑y ^ 2) = (↑x / ↑y ^ 2) ^ y ^ 2) :
626
+ (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2) := by
627
+ rw [g₄] at g₃
628
+ norm_cast at *
629
+
630
+
631
+ lemma imo_1997_p5_7
632
+ (x y : ℕ)
633
+ (h₀ : 0 < x ∧ 0 < y)
634
+ (h₁ : x ^ y ^ 2 = y ^ x)
635
+ (hxy : y < x) :
636
+ 2 * y ^ 2 < x := by
637
+ by_cases hy1: y = 1
638
+ . rw [hy1]
639
+ norm_num
640
+ by_contra! hc
641
+ interval_cases x
642
+ . linarith
643
+ . linarith
644
+ . rw [hy1] at h₁
645
+ simp at h₁
646
+ . have hy: 1 < y := by
647
+ contrapose! hy1
648
+ linarith
649
+ clear hy1
650
+ have h₂: (↑y:ℝ) ^ 2 < ↑x := by
651
+ norm_cast
652
+ exact imo_1997_p5_5 x y h₀ h₁ hxy
653
+ have h₃: 1 < ↑x / (↑y:ℝ) ^ 2 := by
654
+ refine (one_lt_div ?_).mpr h₂
655
+ norm_cast
656
+ exact pow_pos h₀.2 2
657
+ have h₄: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
658
+ refine one_lt_pow₀ h₃ ?_
659
+ refine Nat.ne_of_gt ?_
660
+ refine sq_pos_of_pos ?_
661
+ exact lt_of_succ_lt hy
662
+ have h₅: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
663
+ exact imo_1997_p5_6 x y h₀ h₁
664
+ rw [h₅] at h₄
665
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
666
+ by_contra! hc
667
+ cases' lt_or_eq_of_le hc with hlt heq
668
+ . have gy: 1 < (↑y:ℝ) := by
669
+ norm_cast
670
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
671
+ norm_cast at *
672
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
673
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
674
+ simp at g₁
675
+ linarith[ h₄,g₁]
676
+ . rw [heq] at h₄
677
+ simp at h₄
678
+ simp at h₆
679
+ norm_cast at h₆
680
+
681
+
682
+ lemma imo_1997_p5_7_1
683
+ (x y : ℕ)
684
+ (h₀ : 0 < x ∧ 0 < y)
685
+ (h₁ : x ^ y ^ 2 = y ^ x)
686
+ (hxy : y < x)
687
+ (hy1 : y = 1) :
688
+ 2 * y ^ 2 < x := by
689
+ rw [hy1]
690
+ norm_num
691
+ by_contra! hc
692
+ interval_cases x
693
+ . linarith
694
+ . linarith
695
+ . rw [hy1] at h₁
696
+ simp at h₁
697
+
698
+
699
+ lemma imo_1997_p5_7_2
700
+ (x y : ℕ)
701
+ (h₀ : 0 < x ∧ 0 < y)
702
+ (h₁ : x ^ y ^ 2 = y ^ x)
703
+ (hxy : y < x)
704
+ (hy1 : y = 1) :
705
+ 2 < x := by
706
+ by_contra! hc
707
+ interval_cases x
708
+ . linarith
709
+ . linarith
710
+ . rw [hy1] at h₁
711
+ simp at h₁
712
+
713
+
714
+ lemma imo_1997_p5_7_3
715
+ (x y : ℕ)
716
+ (h₀ : 0 < x ∧ 0 < y)
717
+ (h₁ : x ^ y ^ 2 = y ^ x)
718
+ (hxy : y < x)
719
+ (hy1 : y = 1)
720
+ (hc : x ≤ 2) :
721
+ False := by
722
+ interval_cases x
723
+ . linarith
724
+ . linarith
725
+ . rw [hy1] at h₁
726
+ simp at h₁
727
+
728
+
729
+ lemma imo_1997_p5_7_4
730
+ (x y : ℕ)
731
+ (h₀ : 0 < x ∧ 0 < y)
732
+ (h₁ : x ^ y ^ 2 = y ^ x)
733
+ (hxy : y < x)
734
+ (hy : 1 < y) :
735
+ 2 * y ^ 2 < x := by
736
+ have h₂: (↑y:ℝ) ^ 2 < ↑x := by
737
+ norm_cast
738
+ exact imo_1997_p5_5 x y h₀ h₁ hxy
739
+ have h₃: 1 < ↑x / (↑y:ℝ) ^ 2 := by
740
+ refine (one_lt_div ?_).mpr h₂
741
+ norm_cast
742
+ exact pow_pos h₀.2 2
743
+ have h₄: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
744
+ refine one_lt_pow₀ h₃ ?_
745
+ refine Nat.ne_of_gt ?_
746
+ refine sq_pos_of_pos ?_
747
+ exact lt_of_succ_lt hy
748
+ have h₅: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
749
+ exact imo_1997_p5_6 x y h₀ h₁
750
+ rw [h₅] at h₄
751
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
752
+ by_contra! hc
753
+ cases' lt_or_eq_of_le hc with hlt heq
754
+ . have gy: 1 < (↑y:ℝ) := by
755
+ norm_cast
756
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
757
+ norm_cast at *
758
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
759
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
760
+ simp at g₁
761
+ linarith[ h₄,g₁]
762
+ . rw [heq] at h₄
763
+ simp at h₄
764
+ simp at h₆
765
+ norm_cast at h₆
766
+
767
+
768
+ lemma imo_1997_p5_7_5
769
+ (x y : ℕ)
770
+ (h₀ : 0 < x ∧ 0 < y)
771
+ (h₁ : x ^ y ^ 2 = y ^ x)
772
+ -- (hxy : y < x)
773
+ (hy : 1 < y)
774
+ (h₂ : (↑y:ℝ) ^ 2 < ↑x) :
775
+ 2 * y ^ 2 < x := by
776
+ have h₃: 1 < ↑x / (↑y:ℝ) ^ 2 := by
777
+ refine (one_lt_div ?_).mpr h₂
778
+ norm_cast
779
+ exact pow_pos h₀.2 2
780
+ have h₄: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
781
+ refine one_lt_pow₀ h₃ ?_
782
+ refine Nat.ne_of_gt ?_
783
+ refine sq_pos_of_pos ?_
784
+ exact lt_of_succ_lt hy
785
+ have h₅: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
786
+ exact imo_1997_p5_6 x y h₀ h₁
787
+ rw [h₅] at h₄
788
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
789
+ by_contra! hc
790
+ cases' lt_or_eq_of_le hc with hlt heq
791
+ . have gy: 1 < (↑y:ℝ) := by
792
+ norm_cast
793
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
794
+ norm_cast at *
795
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
796
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
797
+ simp at g₁
798
+ linarith[ h₄,g₁]
799
+ . rw [heq] at h₄
800
+ simp at h₄
801
+ simp at h₆
802
+ norm_cast at h₆
803
+
804
+
805
+ lemma imo_1997_p5_7_6
806
+ (x y : ℕ)
807
+ (h₀ : 0 < x ∧ 0 < y)
808
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
809
+ -- (hxy : y < x)
810
+ -- (hy : 1 < y)
811
+ (h₂ : (↑y:ℝ) ^ 2 < ↑x) :
812
+ 1 < ↑x / (↑y:ℝ) ^ 2 := by
813
+ refine (one_lt_div ?_).mpr h₂
814
+ norm_cast
815
+ exact pow_pos h₀.2 2
816
+
817
+
818
+ lemma imo_1997_p5_7_7
819
+ (x y : ℕ)
820
+ (h₀ : 0 < x ∧ 0 < y)
821
+ (h₁ : x ^ y ^ 2 = y ^ x)
822
+ -- (hxy : y < x)
823
+ (hy : 1 < y)
824
+ -- (h₂ : ↑y ^ 2 < ↑x)
825
+ (h₃ : 1 < ↑x / (↑y:ℝ) ^ 2) :
826
+ 2 * y ^ 2 < x := by
827
+ have h₄: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
828
+ refine one_lt_pow₀ h₃ ?_
829
+ refine Nat.ne_of_gt ?_
830
+ refine sq_pos_of_pos ?_
831
+ exact lt_of_succ_lt hy
832
+ have h₅: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
833
+ exact imo_1997_p5_6 x y h₀ h₁
834
+ rw [h₅] at h₄
835
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
836
+ by_contra! hc
837
+ cases' lt_or_eq_of_le hc with hlt heq
838
+ . have gy: 1 < (↑y:ℝ) := by
839
+ norm_cast
840
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
841
+ norm_cast at *
842
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
843
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
844
+ simp at g₁
845
+ linarith[ h₄,g₁]
846
+ . rw [heq] at h₄
847
+ simp at h₄
848
+ simp at h₆
849
+ norm_cast at h₆
850
+
851
+
852
+ lemma imo_1997_p5_7_8
853
+ (x y : ℕ)
854
+ -- (h₀ : 0 < x ∧ 0 < y)
855
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
856
+ -- (hxy : y < x)
857
+ (hy : 1 < y)
858
+ -- (h₂ : ↑y ^ 2 < ↑x)
859
+ (h₃ : 1 < ↑x / ↑y ^ 2) :
860
+ 1 < (↑x / ↑y ^ 2) ^ y ^ 2 := by
861
+ refine one_lt_pow₀ h₃ ?_
862
+ refine Nat.ne_of_gt ?_
863
+ refine sq_pos_of_pos ?_
864
+ exact lt_of_succ_lt hy
865
+
866
+
867
+ lemma imo_1997_p5_7_9
868
+ (x y : ℕ)
869
+ -- (h₀ : 0 < x ∧ 0 < y)
870
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
871
+ -- (hxy : y < x)
872
+ (hy : 1 < y)
873
+ -- (h₂ : ↑y ^ 2 < ↑x)
874
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
875
+ (h₄ : 1 < (↑x / (↑y:ℝ)^2)^(y^2))
876
+ (h₅ : (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2)) :
877
+ 2 * y ^ 2 < x := by
878
+ rw [h₅] at h₄
879
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
880
+ by_contra! hc
881
+ cases' lt_or_eq_of_le hc with hlt heq
882
+ . have gy: 1 < (↑y:ℝ) := by
883
+ norm_cast
884
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
885
+ norm_cast at *
886
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
887
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
888
+ simp at g₁
889
+ linarith[ h₄,g₁]
890
+ . rw [heq] at h₄
891
+ simp at h₄
892
+ simp at h₆
893
+ norm_cast at h₆
894
+
895
+
896
+ lemma imo_1997_p5_7_10
897
+ (x y : ℕ)
898
+ -- (h₀ : 0 < x ∧ 0 < y)
899
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
900
+ -- (hxy : y < x)
901
+ -- (hy : 1 < y)
902
+ -- (h₂ : ↑y ^ 2 < ↑x)
903
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
904
+ (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
905
+ (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2)) :
906
+ 0 < ↑x - 2 * ↑y ^ 2 := by
907
+ by_contra! hc
908
+ cases' lt_or_eq_of_le hc with hlt heq
909
+ . have gy: 1 < (↑y:ℝ) := by
910
+ norm_cast
911
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
912
+ norm_cast at *
913
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
914
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
915
+ simp at g₁
916
+ linarith[ h₄,g₁]
917
+ . rw [heq] at h₄
918
+ simp at h₄
919
+
920
+
921
+ lemma imo_1997_p5_7_11
922
+ (x y : ℕ)
923
+ -- (h₀ : 0 < x ∧ 0 < y)
924
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
925
+ -- (hxy : y < x)
926
+ -- (hy : 1 < y)
927
+ -- (h₂ : ↑y ^ 2 < ↑x)
928
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
929
+ (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
930
+ (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2))
931
+ (hc : ↑x - 2 * ↑y ^ 2 ≤ 0) :
932
+ False := by
933
+ cases' lt_or_eq_of_le hc with hlt heq
934
+ . have gy: 1 < (↑y:ℝ) := by
935
+ norm_cast
936
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
937
+ norm_cast at *
938
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
939
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
940
+ simp at g₁
941
+ linarith[ h₄,g₁]
942
+ . rw [heq] at h₄
943
+ simp at h₄
944
+
945
+
946
+ lemma imo_1997_p5_7_12
947
+ (x y : ℕ)
948
+ -- (h₀ : 0 < x ∧ 0 < y)
949
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
950
+ -- (hxy : y < x)
951
+ -- (hy : 1 < y)
952
+ -- (h₂ : ↑y ^ 2 < ↑x)
953
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
954
+ (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
955
+ -- (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2))
956
+ -- (hc : ↑x - 2 * ↑y ^ 2 ≤ 0)
957
+ (hlt : ↑x - 2 * ↑y ^ 2 < 0) :
958
+ False := by
959
+ have gy: 1 < (↑y:ℝ) := by
960
+ norm_cast
961
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
962
+ norm_cast at *
963
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
964
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
965
+ simp at g₁
966
+ linarith[ h₄,g₁]
967
+
968
+
969
+ lemma imo_1997_p5_7_13
970
+ (x y : ℕ)
971
+ -- (h₀ : 0 < x ∧ 0 < y)
972
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
973
+ -- (hxy : y < x)
974
+ -- (hy : 1 < y)
975
+ -- (h₂ : ↑y ^ 2 < ↑x)
976
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
977
+ (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
978
+ -- (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2))
979
+ -- (hc : ↑x - 2 * ↑y ^ 2 ≤ 0)
980
+ -- (hlt : ↑x - 2 * ↑y ^ 2 < 0)
981
+ (gy : 1 < ↑y)
982
+ -- (glt : ↑x - 2 * ↑y ^ 2 < 0)
983
+ (g₁ : ↑y ^ (↑x - 2 * ↑y ^ 2) < ↑y ^ 0) :
984
+ False := by
985
+ simp at g₁
986
+ linarith[ h₄,g₁]
987
+
988
+
989
+ lemma imo_1997_p5_7_14
990
+ (x y : ℕ)
991
+ -- (h₀ : 0 < x ∧ 0 < y)
992
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
993
+ -- (hxy : y < x)
994
+ -- (hy : 1 < y)
995
+ -- (h₂ : ↑y ^ 2 < ↑x)
996
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
997
+ (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
998
+ (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2))
999
+ (hc : ↑x - 2 * ↑y ^ 2 ≤ 0)
1000
+ (heq : ↑x - 2 * ↑y ^ 2 = 0) :
1001
+ False := by
1002
+ rw [heq] at h₄
1003
+ simp at h₄
1004
+
1005
+
1006
+ lemma imo_1997_p5_7_15
1007
+ (x y : ℕ)
1008
+ -- (h₀ : 0 < x ∧ 0 < y)
1009
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1010
+ -- (hxy : y < x)
1011
+ -- (hy : 1 < y)
1012
+ -- (h₂ : ↑y ^ 2 < ↑x)
1013
+ -- (h₃ : 1 < ↑x / ↑y ^ 2)
1014
+ -- (h₄ : 1 < ↑y ^ (↑x - 2 * ↑y ^ 2))
1015
+ -- (h₅ : (↑x / ↑y ^ 2) ^ y ^ 2 = ↑y ^ (↑x - 2 * ↑y ^ 2))
1016
+ (h₆ : 0 < ↑x - 2 * ↑y ^ 2) :
1017
+ 2 * y ^ 2 < x := by
1018
+ simp at h₆
1019
+ norm_cast at h₆
1020
+
1021
+
1022
+ lemma imo_1997_p5_8
1023
+ (x y: ℕ)
1024
+ (h₀: 0 < x ∧ 0 < y)
1025
+ (h₁ : x ^ y ^ 2 = y ^ x)
1026
+ (hyx: y < x) :
1027
+ (y^2 ∣ x) := by
1028
+ have h₂: (x ^ y ^ 2).factorization = (y^x).factorization := by
1029
+ exact congr_arg Nat.factorization h₁
1030
+ simp at h₂
1031
+ symm at h₂
1032
+ have hxy1: 2 * y^2 ≤ x := by exact le_of_lt (imo_1997_p5_7 x y h₀ h₁ hyx)
1033
+ have hxy: 2 • y^2 ≤ x := by exact hxy1
1034
+ have h₃: 2 • y^2 • x.factorization ≤ x • x.factorization := by
1035
+ rw [← smul_assoc]
1036
+ refine nsmul_le_nsmul_left ?_ hxy
1037
+ norm_num
1038
+ rw [← h₂] at h₃
1039
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1040
+ rw [← smul_assoc, ← smul_assoc]
1041
+ have g₄: 2 • x = x • 2 := by
1042
+ simp
1043
+ exact mul_comm 2 x
1044
+ rw [g₄]
1045
+ rw [h₄] at h₃
1046
+ rw [← Nat.factorization_pow] at h₃
1047
+ rw [← Nat.factorization_pow] at h₃
1048
+ rw [← Nat.factorization_pow] at h₃
1049
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1050
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1051
+ refine pow_ne_zero x ?_
1052
+ refine pow_ne_zero 2 ?_
1053
+ linarith
1054
+ have g₂: x ^ x ≠ 0 := by
1055
+ refine pow_ne_zero x ?_
1056
+ linarith
1057
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1058
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1059
+ exact Nat.ne_of_gt h₀.1
1060
+
1061
+
1062
+ lemma imo_1997_p5_8_1
1063
+ (x y : ℕ)
1064
+ (h₀ : 0 < x ∧ 0 < y)
1065
+ (h₁ : x ^ y ^ 2 = y ^ x)
1066
+ (hyx : y < x)
1067
+ (h₂ : Nat.factorization (x ^ y ^ 2) = Nat.factorization (y ^ x)) :
1068
+ y ^ 2 ∣ x := by
1069
+ simp at h₂
1070
+ symm at h₂
1071
+ have hxy1: 2 * y^2 ≤ x := by exact le_of_lt (imo_1997_p5_7 x y h₀ h₁ hyx)
1072
+ have hxy: 2 • y^2 ≤ x := by exact hxy1
1073
+ have h₃: 2 • y^2 • x.factorization ≤ x • x.factorization := by
1074
+ rw [← smul_assoc]
1075
+ refine nsmul_le_nsmul_left ?_ hxy
1076
+ norm_num
1077
+ rw [← h₂] at h₃
1078
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1079
+ rw [← smul_assoc, ← smul_assoc]
1080
+ have g₄: 2 • x = x • 2 := by
1081
+ simp
1082
+ exact mul_comm 2 x
1083
+ rw [g₄]
1084
+ rw [h₄] at h₃
1085
+ rw [← Nat.factorization_pow] at h₃
1086
+ rw [← Nat.factorization_pow] at h₃
1087
+ rw [← Nat.factorization_pow] at h₃
1088
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1089
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1090
+ refine pow_ne_zero x ?_
1091
+ refine pow_ne_zero 2 ?_
1092
+ linarith
1093
+ have g₂: x ^ x ≠ 0 := by
1094
+ refine pow_ne_zero x ?_
1095
+ linarith
1096
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1097
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1098
+ exact Nat.ne_of_gt h₀.1
1099
+
1100
+
1101
+ lemma imo_1997_p5_8_2
1102
+ (x y : ℕ)
1103
+ (h₀ : 0 < x ∧ 0 < y)
1104
+ (h₁ : x ^ y ^ 2 = y ^ x)
1105
+ (hyx : y < x)
1106
+ (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x) :
1107
+ y ^ 2 ∣ x := by
1108
+ have hxy1: 2 * y^2 ≤ x := by exact le_of_lt (imo_1997_p5_7 x y h₀ h₁ hyx)
1109
+ have hxy: 2 • y^2 ≤ x := by exact hxy1
1110
+ have h₃: 2 • y^2 • x.factorization ≤ x • x.factorization := by
1111
+ rw [← smul_assoc]
1112
+ refine nsmul_le_nsmul_left ?_ hxy
1113
+ norm_num
1114
+ rw [← h₂] at h₃
1115
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1116
+ rw [← smul_assoc, ← smul_assoc]
1117
+ have g₄: 2 • x = x • 2 := by
1118
+ simp
1119
+ exact mul_comm 2 x
1120
+ rw [g₄]
1121
+ rw [h₄] at h₃
1122
+ rw [← Nat.factorization_pow] at h₃
1123
+ rw [← Nat.factorization_pow] at h₃
1124
+ rw [← Nat.factorization_pow] at h₃
1125
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1126
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1127
+ refine pow_ne_zero x ?_
1128
+ refine pow_ne_zero 2 ?_
1129
+ linarith
1130
+ have g₂: x ^ x ≠ 0 := by
1131
+ refine pow_ne_zero x ?_
1132
+ linarith
1133
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1134
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1135
+ exact Nat.ne_of_gt h₀.1
1136
+
1137
+
1138
+ lemma imo_1997_p5_8_3
1139
+ (x y : ℕ)
1140
+ (h₀ : 0 < x ∧ 0 < y)
1141
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1142
+ (hyx : y < x)
1143
+ (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1144
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1145
+ (hxy : 2 • y ^ 2 ≤ x) :
1146
+ y ^ 2 ∣ x := by
1147
+ have h₃: 2 • y^2 • x.factorization ≤ x • x.factorization := by
1148
+ rw [← smul_assoc]
1149
+ refine nsmul_le_nsmul_left ?_ hxy
1150
+ norm_num
1151
+ rw [← h₂] at h₃
1152
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1153
+ rw [← smul_assoc, ← smul_assoc]
1154
+ have g₄: 2 • x = x • 2 := by
1155
+ simp
1156
+ exact mul_comm 2 x
1157
+ rw [g₄]
1158
+ rw [h₄] at h₃
1159
+ rw [← Nat.factorization_pow] at h₃
1160
+ rw [← Nat.factorization_pow] at h₃
1161
+ rw [← Nat.factorization_pow] at h₃
1162
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1163
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1164
+ refine pow_ne_zero x ?_
1165
+ refine pow_ne_zero 2 ?_
1166
+ linarith
1167
+ have g₂: x ^ x ≠ 0 := by
1168
+ refine pow_ne_zero x ?_
1169
+ linarith
1170
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1171
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1172
+ exact Nat.ne_of_gt h₀.1
1173
+
1174
+
1175
+ lemma imo_1997_p5_8_4
1176
+ (x y : ℕ)
1177
+ -- (h₀ : 0 < x ∧ 0 < y)
1178
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1179
+ -- (hyx : y < x)
1180
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1181
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1182
+ (hxy : 2 • y ^ 2 ≤ x) :
1183
+ 2 • y ^ 2 • Nat.factorization x ≤ x • Nat.factorization x := by
1184
+ rw [← smul_assoc]
1185
+ refine nsmul_le_nsmul_left ?_ hxy
1186
+ norm_num
1187
+
1188
+
1189
+ lemma imo_1997_p5_8_5
1190
+ (x y : ℕ)
1191
+ -- (h₀ : 0 < x ∧ 0 < y)
1192
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1193
+ -- (hyx : y < x)
1194
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1195
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1196
+ (hxy : 2 • y ^ 2 ≤ x) :
1197
+ (2 • y ^ 2) • Nat.factorization x ≤ x • Nat.factorization x := by
1198
+ refine nsmul_le_nsmul_left ?_ hxy
1199
+ norm_num
1200
+
1201
+
1202
+ lemma imo_1997_p5_8_6
1203
+ (x y : ℕ)
1204
+ (h₀ : 0 < x ∧ 0 < y)
1205
+ (h₁ : x ^ y ^ 2 = y ^ x)
1206
+ (hyx : y < x)
1207
+ (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1208
+ (hxy1 : 2 * y ^ 2 ≤ x)
1209
+ (hxy : 2 • y ^ 2 ≤ x) :
1210
+ 0 ≤ Nat.factorization x := by
1211
+ exact _root_.zero_le x.factorization
1212
+
1213
+ lemma imo_1997_p5_8_7
1214
+ (x y : ℕ)
1215
+ (h₀ : 0 < x ∧ 0 < y)
1216
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1217
+ (hyx : y < x)
1218
+ (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1219
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1220
+ -- (hxy : 2 • y ^ 2 ≤ x)
1221
+ (h₃ : 2 • y ^ 2 • Nat.factorization x ≤ x • Nat.factorization x) :
1222
+ y ^ 2 ∣ x := by
1223
+ rw [← h₂] at h₃
1224
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1225
+ rw [← smul_assoc, ← smul_assoc]
1226
+ have g₄: 2 • x = x • 2 := by
1227
+ simp
1228
+ exact mul_comm 2 x
1229
+ rw [g₄]
1230
+ rw [h₄] at h₃
1231
+ rw [← Nat.factorization_pow] at h₃
1232
+ rw [← Nat.factorization_pow] at h₃
1233
+ rw [← Nat.factorization_pow] at h₃
1234
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1235
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1236
+ refine pow_ne_zero x ?_
1237
+ refine pow_ne_zero 2 ?_
1238
+ linarith
1239
+ have g₂: x ^ x ≠ 0 := by
1240
+ refine pow_ne_zero x ?_
1241
+ linarith
1242
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1243
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1244
+ exact Nat.ne_of_gt h₀.1
1245
+
1246
+
1247
+ lemma imo_1997_p5_8_8
1248
+ (x y : ℕ)
1249
+ (h₀ : 0 < x ∧ 0 < y)
1250
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1251
+ (hyx : y < x)
1252
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1253
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1254
+ -- (hxy : 2 • y ^ 2 ≤ x)
1255
+ (h₃ : 2 • x • Nat.factorization y ≤ x • Nat.factorization x) :
1256
+ y ^ 2 ∣ x := by
1257
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
1258
+ rw [← smul_assoc, ← smul_assoc]
1259
+ have g₄: 2 • x = x • 2 := by
1260
+ simp
1261
+ exact mul_comm 2 x
1262
+ rw [g₄]
1263
+ rw [h₄] at h₃
1264
+ rw [← Nat.factorization_pow] at h₃
1265
+ rw [← Nat.factorization_pow] at h₃
1266
+ rw [← Nat.factorization_pow] at h₃
1267
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1268
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1269
+ refine pow_ne_zero x ?_
1270
+ refine pow_ne_zero 2 ?_
1271
+ linarith
1272
+ have g₂: x ^ x ≠ 0 := by
1273
+ refine pow_ne_zero x ?_
1274
+ linarith
1275
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1276
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1277
+ exact Nat.ne_of_gt h₀.1
1278
+
1279
+
1280
+
1281
+ lemma imo_1997_p5_8_9
1282
+ (x y : ℕ) :
1283
+ -- (h₀ : 0 < x ∧ 0 < y)
1284
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1285
+ -- (hyx : y < x)
1286
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1287
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1288
+ -- (hxy : 2 • y ^ 2 ≤ x)
1289
+ -- (h₃ : 2 • x • Nat.factorization y ≤ x • Nat.factorization x) :
1290
+ 2 • x • Nat.factorization y = x • 2 • Nat.factorization y := by
1291
+ rw [← smul_assoc, ← smul_assoc]
1292
+ have g₄: 2 • x = x • 2 := by
1293
+ simp
1294
+ exact mul_comm 2 x
1295
+ rw [g₄]
1296
+
1297
+
1298
+ lemma imo_1997_p5_8_10
1299
+ (x y : ℕ) :
1300
+ -- (h₀ : 0 < x ∧ 0 < y)
1301
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1302
+ -- (hyx : y < x)
1303
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1304
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1305
+ -- (hxy : 2 • y ^ 2 ≤ x)
1306
+ -- (h₃ : 2 • x • Nat.factorization y ≤ x • Nat.factorization x) :
1307
+ (2 • x) • Nat.factorization y = (x • 2) • Nat.factorization y := by
1308
+ have g₄: 2 • x = x • 2 := by
1309
+ simp
1310
+ exact mul_comm 2 x
1311
+ rw [g₄]
1312
+
1313
+
1314
+ lemma imo_1997_p5_8_11
1315
+ (x : ℕ) :
1316
+ -- (h₀ : 0 < x ∧ 0 < y)
1317
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1318
+ -- (hyx : y < x)
1319
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1320
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1321
+ -- (hxy : 2 • y ^ 2 ≤ x)
1322
+ -- (h₃ : 2 • x • Nat.factorization y ≤ x • Nat.factorization x) :
1323
+ 2 • x = x • 2 := by
1324
+ rw [smul_eq_mul, smul_eq_mul]
1325
+ exact Nat.mul_comm 2 x
1326
+
1327
+
1328
+ lemma imo_1997_p5_8_12
1329
+ (x y : ℕ)
1330
+ (h₀ : 0 < x ∧ 0 < y)
1331
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1332
+ (hyx : y < x)
1333
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1334
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1335
+ -- (hxy : 2 • y ^ 2 ≤ x)
1336
+ (h₃ : 2 • x • Nat.factorization y ≤ x • Nat.factorization x)
1337
+ (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y) :
1338
+ y ^ 2 ∣ x := by
1339
+ rw [h₄] at h₃
1340
+ rw [← Nat.factorization_pow] at h₃
1341
+ rw [← Nat.factorization_pow] at h₃
1342
+ rw [← Nat.factorization_pow] at h₃
1343
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1344
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1345
+ refine pow_ne_zero x ?_
1346
+ refine pow_ne_zero 2 ?_
1347
+ linarith
1348
+ have g₂: x ^ x ≠ 0 := by
1349
+ refine pow_ne_zero x ?_
1350
+ linarith
1351
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1352
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1353
+ exact Nat.ne_of_gt h₀.1
1354
+
1355
+
1356
+ lemma imo_1997_p5_8_13
1357
+ (x y : ℕ)
1358
+ (h₀ : 0 < x ∧ 0 < y)
1359
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1360
+ (hyx : y < x)
1361
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1362
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1363
+ -- (hxy : 2 • y ^ 2 ≤ x)
1364
+ (h₃ : Nat.factorization ((y ^ 2) ^ x) ≤ Nat.factorization (x ^ x)) :
1365
+ -- (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y) :
1366
+ y ^ 2 ∣ x := by
1367
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
1368
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1369
+ refine pow_ne_zero x ?_
1370
+ refine pow_ne_zero 2 ?_
1371
+ linarith
1372
+ have g₂: x ^ x ≠ 0 := by
1373
+ refine pow_ne_zero x ?_
1374
+ linarith
1375
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1376
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1377
+ exact Nat.ne_of_gt h₀.1
1378
+
1379
+
1380
+ lemma imo_1997_p5_8_14
1381
+ (x y : ℕ)
1382
+ (h₀ : 0 < x ∧ 0 < y)
1383
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1384
+ (hyx : y < x)
1385
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1386
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1387
+ -- (hxy : 2 • y ^ 2 ≤ x)
1388
+ (h₃ : Nat.factorization ((y ^ 2) ^ x) ≤ Nat.factorization (x ^ x)) :
1389
+ -- (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y) :
1390
+ (y ^ 2) ^ x ∣ x ^ x := by
1391
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
1392
+ refine pow_ne_zero x ?_
1393
+ refine pow_ne_zero 2 ?_
1394
+ linarith
1395
+ have g₂: x ^ x ≠ 0 := by
1396
+ refine pow_ne_zero x ?_
1397
+ linarith
1398
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1399
+
1400
+
1401
+ lemma imo_1997_p5_8_15
1402
+ (x y : ℕ)
1403
+ (h₀ : 0 < x ∧ 0 < y)
1404
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1405
+ (hyx : y < x)
1406
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1407
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1408
+ -- (hxy : 2 • y ^ 2 ≤ x)
1409
+ (h₃ : Nat.factorization ((y ^ 2) ^ x) ≤ Nat.factorization (x ^ x))
1410
+ -- (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y)
1411
+ (g₁ : (y ^ 2) ^ x ≠ 0) :
1412
+ (y ^ 2) ^ x ∣ x ^ x := by
1413
+ have g₂: x ^ x ≠ 0 := by
1414
+ refine pow_ne_zero x ?_
1415
+ linarith
1416
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
1417
+
1418
+
1419
+ lemma imo_1997_p5_8_16
1420
+ (x y : ℕ)
1421
+ -- (h₀ : 0 < x ∧ 0 < y)
1422
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1423
+ -- (hyx : y < x)
1424
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1425
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1426
+ -- (hxy : 2 • y ^ 2 ≤ x)
1427
+ (h₃ : Nat.factorization ((y ^ 2) ^ x) ≤ Nat.factorization (x ^ x))
1428
+ -- (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y)
1429
+ (g₁ : y = 0 → x = 0) :
1430
+ (y ^ 2) ^ x ∣ x ^ x := by
1431
+ refine (Nat.factorization_le_iff_dvd ?_ ?_).mp h₃
1432
+ . simp_all only [Nat.factorization_pow, ne_eq, pow_eq_zero_iff', OfNat.ofNat_ne_zero, not_false_eq_true,]
1433
+ omega
1434
+ . simp_all only [ne_eq, pow_eq_zero_iff', and_not_self, not_false_eq_true]
1435
+
1436
+
1437
+
1438
+ lemma imo_1997_p5_8_17
1439
+ (x y : ℕ)
1440
+ (h₀ : 0 < x ∧ 0 < y)
1441
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1442
+ -- (hyx : y < x)
1443
+ -- (h₂ : x • Nat.factorization y = y ^ 2 • Nat.factorization x)
1444
+ -- (hxy1 : 2 * y ^ 2 ≤ x)
1445
+ -- (hxy : 2 • y ^ 2 ≤ x)
1446
+ -- (h₃ : Nat.factorization ((y ^ 2) ^ x) ≤ Nat.factorization (x ^ x))
1447
+ -- (h₄ : 2 • x • Nat.factorization y = x • 2 • Nat.factorization y)
1448
+ (h₅ : (y ^ 2) ^ x ∣ x ^ x) :
1449
+ y ^ 2 ∣ x := by
1450
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
1451
+ exact Nat.ne_of_gt h₀.1
1452
+
1453
+
1454
+
1455
+ lemma imo_1997_p5_9
1456
+ (x y : ℕ)
1457
+ (h₀ : 0 < x ∧ 0 < y)
1458
+ (h₁ : x ^ y ^ 2 = y ^ x)
1459
+ (h₂ : Real.log (↑x:ℝ) = Real.log ↑y * ↑x / (↑(y ^ 2:ℕ ):ℝ) )
1460
+ (hxy : y < x) :
1461
+ x = y ^ (x / y ^ 2) := by
1462
+ have h_exp : Real.exp (Real.log ↑x)
1463
+ = Real.exp (Real.log ↑y * (↑x:ℝ) / ((↑y:ℝ)) ^ 2) := by
1464
+ rw [h₂]
1465
+ norm_cast
1466
+ rw [← imo_1997_p5_4 x h₀.1] at h_exp
1467
+ rw [← mul_div] at h_exp
1468
+ rw [Real.exp_mul] at h_exp
1469
+ rw [← imo_1997_p5_4 y h₀.2] at h_exp
1470
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
1471
+ norm_cast
1472
+ symm
1473
+ have g₂: y^2 ∣ x := by
1474
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1475
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1476
+ norm_cast
1477
+ exact pow_ne_zero 2 ( by linarith)
1478
+ exact Nat.cast_div g₂ h₃
1479
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1480
+ rw [Nat.cast_pow, h₃]
1481
+ norm_cast
1482
+ rw [←h₄] at h_exp
1483
+ exact Nat.cast_inj.mp h_exp
1484
+
1485
+
1486
+ lemma imo_1997_p5_9_1
1487
+ (x y : ℕ)
1488
+ (h₀ : 0 < x ∧ 0 < y)
1489
+ (h₁ : x ^ y ^ 2 = y ^ x)
1490
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1491
+ (hxy : y < x)
1492
+ (h_exp : rexp (Real.log ↑x) = rexp (Real.log ↑y * ↑x / ↑y ^ 2)) :
1493
+ x = y ^ (x / y ^ 2) := by
1494
+ rw [← imo_1997_p5_4 x h₀.1] at h_exp
1495
+ rw [← mul_div] at h_exp
1496
+ rw [Real.exp_mul] at h_exp
1497
+ rw [← imo_1997_p5_4 y h₀.2] at h_exp
1498
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
1499
+ norm_cast
1500
+ symm
1501
+ have g₂: y^2 ∣ x := by
1502
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1503
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1504
+ norm_cast
1505
+ exact pow_ne_zero 2 ( by linarith)
1506
+ exact Nat.cast_div g₂ h₃
1507
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1508
+ rw [Nat.cast_pow, h₃]
1509
+ norm_cast
1510
+ rw [←h₄] at h_exp
1511
+ exact Nat.cast_inj.mp h_exp
1512
+
1513
+
1514
+ lemma imo_1997_p5_9_2
1515
+ (x y : ℕ)
1516
+ (h₀ : 0 < x ∧ 0 < y)
1517
+ (h₁ : x ^ y ^ 2 = y ^ x)
1518
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1519
+ (hxy : y < x)
1520
+ (h_exp : ↑x = rexp (Real.log ↑y * (↑x / ↑y ^ 2))) :
1521
+ x = y ^ (x / y ^ 2) := by
1522
+ rw [Real.exp_mul] at h_exp
1523
+ rw [← imo_1997_p5_4 y h₀.2] at h_exp
1524
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
1525
+ norm_cast
1526
+ symm
1527
+ have g₂: y^2 ∣ x := by
1528
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1529
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1530
+ norm_cast
1531
+ exact pow_ne_zero 2 ( by linarith)
1532
+ exact Nat.cast_div g₂ h₃
1533
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1534
+ rw [Nat.cast_pow, h₃]
1535
+ norm_cast
1536
+ rw [←h₄] at h_exp
1537
+ exact Nat.cast_inj.mp h_exp
1538
+
1539
+
1540
+ lemma imo_1997_p5_9_3
1541
+ (x y : ℕ)
1542
+ (h₀ : 0 < x ∧ 0 < y)
1543
+ (h₁ : x ^ y ^ 2 = y ^ x)
1544
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1545
+ (hxy : y < x)
1546
+ (h_exp : ↑x = rexp (Real.log ↑y) ^ (↑x / (↑y:ℝ) ^ 2)) :
1547
+ x = y ^ (x / y ^ 2) := by
1548
+ rw [← imo_1997_p5_4 y h₀.2] at h_exp
1549
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
1550
+ norm_cast
1551
+ symm
1552
+ have g₂: y^2 ∣ x := by
1553
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1554
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1555
+ norm_cast
1556
+ exact pow_ne_zero 2 ( by linarith)
1557
+ exact Nat.cast_div g₂ h₃
1558
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1559
+ rw [Nat.cast_pow, h₃]
1560
+ norm_cast
1561
+ rw [←h₄] at h_exp
1562
+ exact Nat.cast_inj.mp h_exp
1563
+
1564
+
1565
+ lemma imo_1997_p5_9_4
1566
+ (x y : ℕ)
1567
+ (h₀ : 0 < x ∧ 0 < y)
1568
+ (h₁ : x ^ y ^ 2 = y ^ x)
1569
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1570
+ (hxy : y < x)
1571
+ (h_exp : (↑x:ℝ) = (↑y:ℝ) ^ ((↑x:ℝ) / (↑y:ℝ) ^ 2)) :
1572
+ x = y ^ (x / y ^ 2) := by
1573
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ)) := by
1574
+ norm_cast
1575
+ symm
1576
+ have g₂: y^2 ∣ x := by
1577
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1578
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1579
+ norm_cast
1580
+ exact pow_ne_zero 2 ( by linarith)
1581
+ exact Nat.cast_div g₂ h₃
1582
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1583
+ rw [Nat.cast_pow, h₃]
1584
+ norm_cast
1585
+ rw [←h₄] at h_exp
1586
+ exact Nat.cast_inj.mp h_exp
1587
+
1588
+
1589
+ lemma imo_1997_p5_9_5
1590
+ (x y : ℕ)
1591
+ (h₀ : 0 < x ∧ 0 < y)
1592
+ (h₁ : x ^ y ^ 2 = y ^ x)
1593
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1594
+ (hxy : y < x) :
1595
+ -- (h_exp : ↑x = ↑y ^ (↑x / ↑y ^ 2:ℕ)) :
1596
+ (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
1597
+ norm_cast
1598
+ symm
1599
+ have g₂: y^2 ∣ x := by
1600
+ exact imo_1997_p5_8 x y h₀ h₁ hxy
1601
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1602
+ norm_cast
1603
+ exact pow_ne_zero 2 ( by linarith)
1604
+ exact Nat.cast_div g₂ h₃
1605
+
1606
+
1607
+ lemma imo_1997_p5_9_6
1608
+ (x y : ℕ)
1609
+ (h₀ : 0 < x ∧ 0 < y)
1610
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1611
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1612
+ -- (hxy : y < x)
1613
+ -- (h_exp : ↑x = ↑y ^ (↑x / ↑y ^ 2))
1614
+ (g₂ : y ^ 2 ∣ x) :
1615
+ (↑(x / y^2:ℕ):ℝ) = (↑x:ℝ) / (↑(y^2:ℕ)) := by
1616
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
1617
+ norm_cast
1618
+ exact pow_ne_zero 2 ( by linarith)
1619
+ exact Nat.cast_div g₂ h₃
1620
+
1621
+
1622
+ lemma imo_1997_p5_9_7
1623
+ (x y : ℕ)
1624
+ (h₀ : 0 < x ∧ 0 < y)
1625
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1626
+ -- (hxy : y < x)
1627
+ (h₂ : Real.log (↑x:ℝ) = Real.log ↑y * ↑x / (↑(y ^ 2:ℕ ):ℝ) ) :
1628
+ (↑x:ℝ) = (↑y:ℝ) ^ ((↑x:ℝ) / (↑y:ℝ) ^ 2) := by
1629
+ have h_exp : Real.exp (Real.log ↑x)
1630
+ = Real.exp (Real.log ↑y * (↑x:ℝ) / ((↑y:ℝ)) ^ 2) := by
1631
+ rw [h₂]
1632
+ norm_cast
1633
+ rw [← imo_1997_p5_4 x h₀.1] at h_exp
1634
+ rw [← mul_div] at h_exp
1635
+ rw [Real.exp_mul] at h_exp
1636
+ rw [← imo_1997_p5_4 y h₀.2] at h_exp
1637
+ exact h_exp
1638
+
1639
+
1640
+ lemma imo_1997_p5_9_8
1641
+ (x y : ℕ)
1642
+ (h₀ : 0 < x ∧ 0 < y)
1643
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1644
+ -- (hxy : y < x)
1645
+ (h₂ : Real.log (↑x:ℝ) = Real.log ↑y * ↑x / (↑(y ^ 2:ℕ ):ℝ) ) :
1646
+ ↑x = rexp (Real.log ↑y * (↑x / ↑y ^ 2)) := by
1647
+ have h_exp : Real.exp (Real.log ↑x)
1648
+ = Real.exp (Real.log ↑y * (↑x:ℝ) / ((↑y:ℝ)) ^ 2) := by
1649
+ rw [h₂]
1650
+ norm_cast
1651
+ rw [← imo_1997_p5_4 x h₀.1] at h_exp
1652
+ rw [← mul_div] at h_exp
1653
+ exact h_exp
1654
+
1655
+
1656
+ lemma imo_1997_p5_9_9
1657
+ (x y : ℕ)
1658
+ -- (h₀ : 0 < x ∧ 0 < y)
1659
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1660
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1661
+ -- (hxy : y < x)
1662
+ (h_exp : (↑x:ℝ) = (↑y:ℝ) ^ ((↑x:ℝ) / (↑y:ℝ) ^ 2))
1663
+ (h₃ : (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ))) :
1664
+ x = y ^ (x / y ^ 2) := by
1665
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1666
+ rw [Nat.cast_pow, h₃]
1667
+ norm_cast
1668
+ rw [←h₄] at h_exp
1669
+ exact Nat.cast_inj.mp h_exp
1670
+
1671
+
1672
+ lemma imo_1997_p5_9_10
1673
+ (x y : ℕ)
1674
+ -- (h₀ : 0 < x ∧ 0 < y)
1675
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1676
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1677
+ -- (hxy : y < x)
1678
+ -- (h_exp : ↑x = ↑y ^ (↑x / ↑y ^ 2))
1679
+ (h₃ : (↑x:ℝ) / ((↑y:ℝ)^2) = ↑(x / y^2:ℕ)) :
1680
+ (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ) ^ ((↑x:ℝ) / ((↑y:ℝ)^2)) := by
1681
+ rw [Nat.cast_pow, h₃]
1682
+ norm_cast
1683
+
1684
+
1685
+ lemma imo_1997_p5_9_11
1686
+ (x y : ℕ)
1687
+ -- (h₀ : 0 < x ∧ 0 < y)
1688
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1689
+ -- (h₂ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ))
1690
+ -- (hxy : y < x)
1691
+ (h_exp : ↑x = ↑(y ^ (x / y ^ 2)))
1692
+ (h₃ : ↑x / ↑y ^ 2 = ↑(x / y ^ 2))
1693
+ (h₄ : ↑(y ^ (x / y ^ 2)) = ↑y ^ (↑x / ↑y ^ 2)) :
1694
+ x = y ^ (x / y ^ 2) := by
1695
+ rw [←h₄] at h_exp
1696
+ exact Nat.cast_inj.mp h_exp
1697
+
1698
+
1699
+
1700
+
1701
+ lemma imo_1997_p5_10
1702
+ (x y : ℕ)
1703
+ (h₀ : 0 < x ∧ 0 < y)
1704
+ (h₁ : x ^ y ^ 2 = y ^ x)
1705
+ (hxy : y < x) :
1706
+ x = y ^ (x / y ^ 2) := by
1707
+ -- sketch: y^2 * log x = x * log y
1708
+ have h₃: Real.log (x^(y^2)) = Real.log (y^x) := by
1709
+ norm_cast
1710
+ rw [h₁]
1711
+ have h₄: (↑(y ^ (2:ℕ)):ℝ) * Real.log x = ↑x * Real.log y := by
1712
+ have h41: Real.log (y^x) = (↑x:ℝ) * Real.log (y) := by
1713
+ exact Real.log_pow y x
1714
+ have h42: Real.log (x^(y^2)) = (↑(y ^ (2:ℕ)):ℝ) * Real.log x := by
1715
+ exact Real.log_pow x (y^2)
1716
+ rw [h41,h42] at h₃
1717
+ exact h₃
1718
+ have h₅: Real.log ↑x = Real.log ↑y * ↑x / (↑(y ^ (2:ℕ)):ℝ) := by
1719
+ by_contra! hc
1720
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
1721
+ rw [← h₄, mul_comm, ← mul_div] at hc
1722
+ rw [div_self, mul_one] at hc
1723
+ . apply hc
1724
+ norm_cast
1725
+ . norm_cast
1726
+ push_neg
1727
+ refine pow_ne_zero 2 ?_
1728
+ exact Nat.ne_of_gt h₀.2
1729
+ have h₆: x = y ^ (x / y ^ 2) := by
1730
+ exact imo_1997_p5_9 x y h₀ h₁ h₅ hxy
1731
+ exact h₆
1732
+
1733
+ lemma imo_1997_p5_10_1
1734
+ (x y : ℕ)
1735
+ (h₀ : 0 < x ∧ 0 < y)
1736
+ (h₁ : x ^ y ^ 2 = y ^ x)
1737
+ (hxy : y < x)
1738
+ (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x)) :
1739
+ x = y ^ (x / y ^ 2) := by
1740
+ have h₄: (↑(y ^ (2:ℕ)):ℝ) * Real.log x = ↑x * Real.log y := by
1741
+ have h41: Real.log (y^x) = (↑x:ℝ) * Real.log (y) := by
1742
+ exact Real.log_pow y x
1743
+ have h42: Real.log (x^(y^2)) = (↑(y ^ (2:ℕ)):ℝ) * Real.log x := by
1744
+ exact Real.log_pow x (y^2)
1745
+ rw [h41,h42] at h₃
1746
+ exact h₃
1747
+ have h₅: Real.log ↑x = Real.log ↑y * ↑x / (↑(y ^ (2:ℕ)):ℝ) := by
1748
+ by_contra! hc
1749
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
1750
+ rw [← h₄, mul_comm, ← mul_div] at hc
1751
+ rw [div_self, mul_one] at hc
1752
+ . apply hc
1753
+ norm_cast
1754
+ . norm_cast
1755
+ push_neg
1756
+ refine pow_ne_zero 2 ?_
1757
+ exact Nat.ne_of_gt h₀.2
1758
+ have h₆: x = y ^ (x / y ^ 2) := by
1759
+ exact imo_1997_p5_9 x y h₀ h₁ h₅ hxy
1760
+ exact h₆
1761
+
1762
+
1763
+ lemma imo_1997_p5_10_2
1764
+ (x y : ℕ)
1765
+ -- (h₀ : 0 < x ∧ 0 < y)
1766
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1767
+ -- (hxy : y < x)
1768
+ (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x)) :
1769
+ ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y := by
1770
+ have h41: Real.log (y^x) = (↑x:ℝ) * Real.log (y) := by
1771
+ exact Real.log_pow y x
1772
+ have h42: Real.log (x^(y^2)) = (↑(y ^ (2:ℕ)):ℝ) * Real.log x := by
1773
+ exact Real.log_pow x (y^2)
1774
+ rw [h41,h42] at h₃
1775
+ exact h₃
1776
+
1777
+
1778
+ lemma imo_1997_p5_10_3
1779
+ (x y : ℕ)
1780
+ -- (h₀ : 0 < x ∧ 0 < y)
1781
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1782
+ -- (hxy : y < x)
1783
+ (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1784
+ (h₄₁ : Real.log (↑y ^ x) = ↑x * Real.log ↑y) :
1785
+ ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y := by
1786
+ have h₄₂: Real.log (x^(y^2)) = (↑(y ^ (2:ℕ)):ℝ) * Real.log x := by
1787
+ exact Real.log_pow x (y^2)
1788
+ rw [h₄₁,h₄₂] at h₃
1789
+ exact h₃
1790
+
1791
+
1792
+ lemma imo_1997_p5_10_4
1793
+ (x y : ℕ)
1794
+ -- (h₀ : 0 < x ∧ 0 < y)
1795
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1796
+ -- (hxy : y < x)
1797
+ (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1798
+ (h₄₁ : Real.log (↑y ^ x) = ↑x * Real.log ↑y)
1799
+ (h₄₂ : Real.log (↑x ^ y ^ 2) = ↑(y ^ 2:ℕ) * Real.log ↑x) :
1800
+ ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y := by
1801
+ rw [h₄₁,h₄₂] at h₃
1802
+ exact h₃
1803
+
1804
+ lemma imo_1997_p5_10_5
1805
+ (x y : ℕ)
1806
+ (h₀ : 0 < x ∧ 0 < y)
1807
+ (h₁ : x ^ y ^ 2 = y ^ x)
1808
+ (hxy : y < x)
1809
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1810
+ (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y) :
1811
+ x = y ^ (x / y ^ 2) := by
1812
+ have h₅: Real.log ↑x = Real.log ↑y * ↑x / (↑(y ^ (2:ℕ)):ℝ) := by
1813
+ by_contra! hc
1814
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
1815
+ rw [← h₄, mul_comm, ← mul_div] at hc
1816
+ rw [div_self, mul_one] at hc
1817
+ . apply hc
1818
+ norm_cast
1819
+ . norm_cast
1820
+ push_neg
1821
+ refine pow_ne_zero 2 ?_
1822
+ exact Nat.ne_of_gt h₀.2
1823
+ have h₆: x = y ^ (x / y ^ 2) := by
1824
+ exact imo_1997_p5_9 x y h₀ h₁ h₅ hxy
1825
+ exact h₆
1826
+
1827
+
1828
+ lemma imo_1997_p5_10_6
1829
+ (x y : ℕ)
1830
+ (h₀ : 0 < x ∧ 0 < y)
1831
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1832
+ -- (hxy : y < x)
1833
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1834
+ (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y) :
1835
+ Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ) := by
1836
+ by_contra! hc
1837
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
1838
+ rw [← h₄, mul_comm, ← mul_div] at hc
1839
+ rw [div_self, mul_one] at hc
1840
+ . apply hc
1841
+ norm_cast
1842
+ . norm_cast
1843
+ push_neg
1844
+ refine pow_ne_zero 2 ?_
1845
+ exact Nat.ne_of_gt h₀.2
1846
+
1847
+
1848
+ lemma imo_1997_p5_10_7
1849
+ (x y : ℕ)
1850
+ (h₀ : 0 < x ∧ 0 < y)
1851
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1852
+ -- (hxy : y < x)
1853
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1854
+ (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y)
1855
+ (hc : ¬Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ)) :
1856
+ False := by
1857
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
1858
+ rw [← h₄, mul_comm, ← mul_div] at hc
1859
+ rw [div_self, mul_one] at hc
1860
+ . apply hc
1861
+ norm_cast
1862
+ . norm_cast
1863
+ push_neg
1864
+ refine pow_ne_zero 2 ?_
1865
+ exact Nat.ne_of_gt h₀.2
1866
+
1867
+
1868
+ lemma imo_1997_p5_10_8
1869
+ (x y : ℕ)
1870
+ (h₀ : 0 < x ∧ 0 < y)
1871
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1872
+ -- (hxy : y < x)
1873
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1874
+ (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y)
1875
+ (hc : ¬Real.log ↑x = ↑x * Real.log ↑y / ↑(y ^ 2:ℕ)) :
1876
+ False := by
1877
+ rw [← h₄, mul_comm, ← mul_div] at hc
1878
+ rw [div_self, mul_one] at hc
1879
+ . apply hc
1880
+ norm_cast
1881
+ . norm_cast
1882
+ push_neg
1883
+ refine pow_ne_zero 2 ?_
1884
+ exact Nat.ne_of_gt h₀.2
1885
+
1886
+
1887
+ lemma imo_1997_p5_10_9
1888
+ (x y : ℕ)
1889
+ (h₀ : 0 < x ∧ 0 < y)
1890
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1891
+ -- (hxy : y < x)
1892
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1893
+ -- (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y)
1894
+ (hc : ¬Real.log ↑x = Real.log ↑x * (↑(y ^ 2:ℕ) / ↑(y ^ 2:ℕ))) :
1895
+ False := by
1896
+ rw [div_self, mul_one] at hc
1897
+ . apply hc
1898
+ norm_cast
1899
+ . norm_cast
1900
+ push_neg
1901
+ refine pow_ne_zero 2 ?_
1902
+ exact Nat.ne_of_gt h₀.2
1903
+
1904
+
1905
+ lemma imo_1997_p5_10_10
1906
+ (x y : ℕ)
1907
+ (h₀ : 0 < x ∧ 0 < y)
1908
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
1909
+ -- (hxy : y < x)
1910
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1911
+ -- (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y)
1912
+ (hc : ¬Real.log ↑x = Real.log ↑x * (↑(y ^ 2:ℕ) / ↑(y ^ 2:ℕ))) :
1913
+ ↑((y ^ 2):ℝ) ≠ 0 := by
1914
+ norm_cast
1915
+ push_neg
1916
+ refine pow_ne_zero 2 ?_
1917
+ exact Nat.ne_of_gt h₀.2
1918
+
1919
+
1920
+ lemma imo_1997_p5_10_11
1921
+ (x y : ℕ)
1922
+ (h₀ : 0 < x ∧ 0 < y)
1923
+ (h₁ : x ^ y ^ 2 = y ^ x)
1924
+ (hxy : y < x)
1925
+ -- (h₃ : Real.log (↑x ^ y ^ 2) = Real.log (↑y ^ x))
1926
+ -- (h₄ : ↑(y ^ 2:ℕ) * Real.log ↑x = ↑x * Real.log ↑y)
1927
+ (h₅ : Real.log ↑x = Real.log ↑y * ↑x / ↑(y ^ 2:ℕ)) :
1928
+ x = y ^ (x / y ^ 2) := by
1929
+ exact imo_1997_p5_9 x y h₀ h₁ h₅ hxy
1930
+
1931
+
1932
+ lemma imo_1997_p5_11_1
1933
+ (x y : ℕ) :
1934
+ -- (h₀ : 0 < x ∧ 0 < y)
1935
+ -- (h₁ : x ^ y ^ 2 = y ^ x) :
1936
+ x ^ y ^ 2 = (x ^ y) ^ y := by
1937
+ rw [Nat.pow_two]
1938
+ exact Nat.pow_mul x y y
1939
+
1940
+
1941
+ lemma imo_1997_p5_11_2
1942
+ (x y : ℕ)
1943
+ (h₀ : 0 < x ∧ 0 < y)
1944
+ (h₁ : x ^ y ^ 2 = y ^ x)
1945
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
1946
+ (hxy : y < x) :
1947
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
1948
+ have h₃: x = y ^ (x / y ^ 2) := by
1949
+ exact imo_1997_p5_10 x y h₀ h₁ hxy
1950
+ let k:ℕ := x / y^2
1951
+ have hk_def: k = x / y^2 := by exact rfl
1952
+ by_cases hk: k < 2
1953
+ . rw [← hk_def] at h₃
1954
+ interval_cases k
1955
+ . exfalso
1956
+ simp at h₃
1957
+ linarith
1958
+ . exfalso
1959
+ simp at *
1960
+ linarith [hxy,h₃]
1961
+ . push_neg at hk
1962
+ rw [← hk_def] at h₃
1963
+ have h₅: k = y^(k-2) := by
1964
+ rw [h₃] at hk_def
1965
+ nth_rewrite 1 [hk_def]
1966
+ exact Nat.pow_div hk h₀.2
1967
+ by_cases hk5: k < 5
1968
+ . interval_cases k
1969
+ . exfalso
1970
+ simp at h₅
1971
+ . right
1972
+ norm_num
1973
+ simp at h₅
1974
+ symm at h₅
1975
+ rw [h₅] at h₃
1976
+ norm_num at h₃
1977
+ exact { left := h₃, right := h₅ }
1978
+ . simp at h₅
1979
+ symm at h₅
1980
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
1981
+ rw [g₂, h₅] at h₃
1982
+ norm_num at h₃
1983
+ left
1984
+ norm_num
1985
+ constructor
1986
+ . exact h₃
1987
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
1988
+ norm_num
1989
+ exact h₅
1990
+ have h₇: 0 ≤ y := by
1991
+ linarith
1992
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
1993
+ push_neg at hk5
1994
+ by_cases hy: 2 ≤ y
1995
+ . have h₅₁: k < y^(k-2) := by
1996
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
1997
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
1998
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
1999
+ have h₇: 4*k < 2^k := by
2000
+ exact imo_1997_p5_2 k hk5
2001
+ have h₇: k < 2^(k-2) := by
2002
+ have h₈ : k < 2 ^ k / 4 := by
2003
+ have h81: 4 ∣ 2^k := by
2004
+ have h82: 2^k = 4*2^(k-2) := by
2005
+ have h83: k = 2 + (k -2) := by
2006
+ ring_nf
2007
+ exact (add_sub_of_le hk).symm
2008
+ nth_rewrite 1 [h83]
2009
+ rw [pow_add]
2010
+ norm_num
2011
+ rw [h82]
2012
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2013
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2014
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2015
+ have g2: k = k - 2 + 2 := by
2016
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2017
+ have h1: 2^k = 2^(k - 2 + 2) := by
2018
+ exact congrArg (HPow.hPow 2) g2
2019
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2020
+ rw [h1, h2]
2021
+ ring_nf
2022
+ simp
2023
+ linarith
2024
+ linarith
2025
+ exfalso
2026
+ linarith
2027
+ . push_neg at hy
2028
+ interval_cases y
2029
+ . linarith
2030
+ . simp at h₅
2031
+ simp at h₃
2032
+ linarith
2033
+
2034
+
2035
+ lemma imo_1997_p5_11_3
2036
+ (x y k : ℕ)
2037
+ (h₀ : 0 < x ∧ 0 < y)
2038
+ (h₁ : x ^ y ^ 2 = y ^ x)
2039
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2040
+ (hxy : y < x)
2041
+ (h₃ : x = y ^ (x / y ^ 2))
2042
+ (hk_def : k = x / y ^ 2) :
2043
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2044
+ by_cases hk: k < 2
2045
+ . rw [← hk_def] at h₃
2046
+ interval_cases k
2047
+ . exfalso
2048
+ simp at h₃
2049
+ linarith
2050
+ . exfalso
2051
+ simp at *
2052
+ linarith [hxy,h₃]
2053
+ . push_neg at hk
2054
+ rw [← hk_def] at h₃
2055
+ have h₅: k = y^(k-2) := by
2056
+ rw [h₃] at hk_def
2057
+ nth_rewrite 1 [hk_def]
2058
+ exact Nat.pow_div hk h₀.2
2059
+ by_cases hk5: k < 5
2060
+ . interval_cases k
2061
+ . exfalso
2062
+ simp at h₅
2063
+ . right
2064
+ norm_num
2065
+ simp at h₅
2066
+ symm at h₅
2067
+ rw [h₅] at h₃
2068
+ norm_num at h₃
2069
+ exact { left := h₃, right := h₅ }
2070
+ . simp at h₅
2071
+ symm at h₅
2072
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
2073
+ rw [g₂, h₅] at h₃
2074
+ norm_num at h₃
2075
+ left
2076
+ norm_num
2077
+ constructor
2078
+ . exact h₃
2079
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
2080
+ norm_num
2081
+ exact h₅
2082
+ have h₇: 0 ≤ y := by
2083
+ linarith
2084
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
2085
+ push_neg at hk5
2086
+ by_cases hy: 2 ≤ y
2087
+ . have h₅₁: k < y^(k-2) := by
2088
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2089
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2090
+ refine (Nat.pow_le_pow_iff_left ?_).mpr hy
2091
+ have h₆₀: 2 < k - 2 := by exact hk1
2092
+ exact Nat.not_eq_zero_of_lt h₆₀
2093
+ have h₇: 4*k < 2^k := by
2094
+ exact imo_1997_p5_2 k hk5
2095
+ have h₇: k < 2^(k-2) := by
2096
+ have h₈ : k < 2 ^ k / 4 := by
2097
+ have h81: 4 ∣ 2^k := by
2098
+ have h82: 2^k = 4*2^(k-2) := by
2099
+ have h83: k = 2 + (k -2) := by
2100
+ ring_nf
2101
+ exact (add_sub_of_le hk).symm
2102
+ nth_rewrite 1 [h83]
2103
+ rw [pow_add]
2104
+ norm_num
2105
+ rw [h82]
2106
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2107
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2108
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2109
+ have g2: k = k - 2 + 2 := by
2110
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2111
+ have h1: 2^k = 2^(k - 2 + 2) := by
2112
+ exact congrArg (HPow.hPow 2) g2
2113
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2114
+ rw [h1, h2]
2115
+ ring_nf
2116
+ simp
2117
+ linarith
2118
+ linarith
2119
+ exfalso
2120
+ linarith
2121
+ . push_neg at hy
2122
+ interval_cases y
2123
+ . linarith
2124
+ . simp at h₅
2125
+ simp at h₃
2126
+ linarith
2127
+
2128
+
2129
+ lemma imo_1997_p5_11_4
2130
+ (x y k : ℕ)
2131
+ (h₀ : 0 < x ∧ 0 < y)
2132
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2133
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2134
+ (hxy : y < x)
2135
+ (h₃ : x = y ^ (x / y ^ 2))
2136
+ (hk_def : k = x / y ^ 2)
2137
+ (hk : k < 2) :
2138
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2139
+ rw [← hk_def] at h₃
2140
+ interval_cases k
2141
+ . exfalso
2142
+ simp at h₃
2143
+ linarith
2144
+ . exfalso
2145
+ simp at *
2146
+ linarith [hxy,h₃]
2147
+
2148
+
2149
+ lemma imo_1997_p5_11_5
2150
+ (x y k : ℕ)
2151
+ (h₀ : 0 < x ∧ 0 < y)
2152
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2153
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2154
+ (hxy : y < x)
2155
+ (h₃ : x = y ^ (x / y ^ 2))
2156
+ (hk_def : k = x / y ^ 2)
2157
+ (hk : k < 2) :
2158
+ False := by
2159
+ rw [← hk_def] at h₃
2160
+ interval_cases k
2161
+ . simp at h₃
2162
+ linarith
2163
+ . simp at *
2164
+ linarith [hxy,h₃]
2165
+
2166
+
2167
+ lemma imo_1997_p5_11_6
2168
+ (x y k : ℕ)
2169
+ (h₀ : 0 < x ∧ 0 < y)
2170
+ (h₁ : x ^ y ^ 2 = y ^ x)
2171
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2172
+ (hxy : y < x)
2173
+ (h₃ : x = y ^ (x / y ^ 2))
2174
+ (hk_def : k = x / y ^ 2)
2175
+ (hk : 2 ≤ k) :
2176
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2177
+ rw [← hk_def] at h₃
2178
+ have h₅: k = y^(k-2) := by
2179
+ rw [h₃] at hk_def
2180
+ nth_rewrite 1 [hk_def]
2181
+ exact Nat.pow_div hk h₀.2
2182
+ by_cases hk5: k < 5
2183
+ . interval_cases k
2184
+ . exfalso
2185
+ simp at h₅
2186
+ . right
2187
+ norm_num
2188
+ simp at h₅
2189
+ symm at h₅
2190
+ rw [h₅] at h₃
2191
+ norm_num at h₃
2192
+ exact { left := h₃, right := h₅ }
2193
+ . simp at h₅
2194
+ symm at h₅
2195
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
2196
+ rw [g₂, h₅] at h₃
2197
+ norm_num at h₃
2198
+ left
2199
+ norm_num
2200
+ constructor
2201
+ . exact h₃
2202
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
2203
+ norm_num
2204
+ exact h₅
2205
+ have h₇: 0 ≤ y := by
2206
+ linarith
2207
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
2208
+ push_neg at hk5
2209
+ by_cases hy: 2 ≤ y
2210
+ . have h₅₁: k < y^(k-2) := by
2211
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2212
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2213
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2214
+ have h₇: 4*k < 2^k := by
2215
+ exact imo_1997_p5_2 k hk5
2216
+ have h₇: k < 2^(k-2) := by
2217
+ have h₈ : k < 2 ^ k / 4 := by
2218
+ have h81: 4 ∣ 2^k := by
2219
+ have h82: 2^k = 4*2^(k-2) := by
2220
+ have h83: k = 2 + (k -2) := by
2221
+ ring_nf
2222
+ exact (add_sub_of_le hk).symm
2223
+ nth_rewrite 1 [h83]
2224
+ rw [pow_add]
2225
+ norm_num
2226
+ rw [h82]
2227
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2228
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2229
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2230
+ have g2: k = k - 2 + 2 := by
2231
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2232
+ have h1: 2^k = 2^(k - 2 + 2) := by
2233
+ exact congrArg (HPow.hPow 2) g2
2234
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2235
+ rw [h1, h2]
2236
+ ring_nf
2237
+ simp
2238
+ linarith
2239
+ linarith
2240
+ exfalso
2241
+ linarith
2242
+ . push_neg at hy
2243
+ interval_cases y
2244
+ . linarith
2245
+ . simp at h₅
2246
+ simp at h₃
2247
+ linarith
2248
+
2249
+
2250
+ lemma imo_1997_p5_11_7
2251
+ (x y k : ℕ)
2252
+ (h₀ : 0 < x ∧ 0 < y)
2253
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2254
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2255
+ -- (hxy : y < x)
2256
+ (h₃ : x = y ^ k)
2257
+ (hk_def : k = x / y ^ 2)
2258
+ (hk : 2 ≤ k) :
2259
+ k = y ^ (k - 2) := by
2260
+ rw [h₃] at hk_def
2261
+ nth_rewrite 1 [hk_def]
2262
+ exact Nat.pow_div hk h₀.2
2263
+
2264
+
2265
+ lemma imo_1997_p5_11_8
2266
+ (x y k : ℕ)
2267
+ (h₀ : 0 < x ∧ 0 < y)
2268
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2269
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2270
+ -- (hxy : y < x)
2271
+ (h₃ : x = y ^ k)
2272
+ (hk_def : k = x / y ^ 2)
2273
+ (hk : 2 ≤ k)
2274
+ (h₅ : k = y ^ (k - 2))
2275
+ (hk5 : k < 5) :
2276
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2277
+ interval_cases k
2278
+ . exfalso
2279
+ simp at h₅
2280
+ . right
2281
+ norm_num
2282
+ simp at h₅
2283
+ symm at h₅
2284
+ rw [h₅] at h₃
2285
+ norm_num at h₃
2286
+ exact { left := h₃, right := h₅ }
2287
+ . simp at h₅
2288
+ symm at h₅
2289
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
2290
+ rw [g₂, h₅] at h₃
2291
+ norm_num at h₃
2292
+ left
2293
+ norm_num
2294
+ constructor
2295
+ . exact h₃
2296
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
2297
+ norm_num
2298
+ exact h₅
2299
+ have h₇: 0 ≤ y := by
2300
+ linarith
2301
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
2302
+
2303
+
2304
+ lemma imo_1997_p5_11_9
2305
+ (x y : ℕ)
2306
+ -- (h₀ : 0 < x ∧ 0 < y)
2307
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2308
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2309
+ -- (hxy : y < x)
2310
+ (h₃ : x = y ^ 3)
2311
+ (hk_def : 3 = x / y ^ 2)
2312
+ (hk : 2 ≤ 3)
2313
+ (h₅ : 3 = y ^ (3 - 2))
2314
+ (hk5 : 3 < 5) :
2315
+ (x, y) = (27, 3) := by
2316
+ norm_num
2317
+ simp at h₅
2318
+ symm at h₅
2319
+ rw [h₅] at h₃
2320
+ norm_num at h₃
2321
+ exact { left := h₃, right := h₅ }
2322
+
2323
+
2324
+ lemma imo_1997_p5_11_10
2325
+ (x y : ℕ)
2326
+ (h₀ : 0 < x ∧ 0 < y)
2327
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2328
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2329
+ -- (hxy : y < x)
2330
+ (h₃ : x = y ^ 4)
2331
+ (hk_def : 4 = x / y ^ 2)
2332
+ (hk : 2 ≤ 4)
2333
+ (h₅ : 4 = y ^ (4 - 2))
2334
+ (hk5 : 4 < 5) :
2335
+ (x, y) = (16, 2) := by
2336
+ simp at h₅
2337
+ symm at h₅
2338
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
2339
+ rw [g₂, h₅] at h₃
2340
+ norm_num at h₃
2341
+ norm_num
2342
+ constructor
2343
+ . exact h₃
2344
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
2345
+ norm_num
2346
+ exact h₅
2347
+ have h₇: 0 ≤ y := by
2348
+ linarith
2349
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
2350
+
2351
+
2352
+ lemma imo_1997_p5_11_11
2353
+ (y: ℕ)
2354
+ -- (h₀ : 0 < x ∧ 0 < y)
2355
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2356
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2357
+ -- (hxy : y < x)
2358
+ -- (hk_def : 4 = x / y ^ 2)
2359
+ -- (hk : 2 ≤ 4)
2360
+ -- (hk5 : 4 < 5)
2361
+ (h₅ : y ^ 2 = 4)
2362
+ (g₂ : y ^ 4 = y ^ 2 * y ^ 2) :
2363
+ -- (h₃ : x = 16) :
2364
+ y = 2 := by
2365
+ rw [pow_two] at h₅
2366
+ refine ((fun {m n} => Nat.mul_self_inj.mp) (?_)).symm
2367
+ exact h₅.symm
2368
+
2369
+
2370
+ lemma imo_1997_p5_11_12
2371
+ (x y k : ℕ)
2372
+ (h₀ : 0 < x ∧ 0 < y)
2373
+ (h₁ : x ^ y ^ 2 = y ^ x)
2374
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2375
+ (hxy : y < x)
2376
+ (h₃ : x = y ^ k)
2377
+ (hk_def : k = x / y ^ 2)
2378
+ (hk : 2 ≤ k)
2379
+ (h₅ : k = y ^ (k - 2))
2380
+ (hk5 : 5 ≤ k) :
2381
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2382
+ by_cases hy: 2 ≤ y
2383
+ . have h₅₁: k < y^(k-2) := by
2384
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2385
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2386
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2387
+ have h₇: 4*k < 2^k := by
2388
+ exact imo_1997_p5_2 k hk5
2389
+ have h₇: k < 2^(k-2) := by
2390
+ have h₈ : k < 2 ^ k / 4 := by
2391
+ have h81: 4 ∣ 2^k := by
2392
+ have h82: 2^k = 4*2^(k-2) := by
2393
+ have h83: k = 2 + (k -2) := by
2394
+ ring_nf
2395
+ exact (add_sub_of_le hk).symm
2396
+ nth_rewrite 1 [h83]
2397
+ rw [pow_add]
2398
+ norm_num
2399
+ rw [h82]
2400
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2401
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2402
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2403
+ have g2: k = k - 2 + 2 := by
2404
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2405
+ have h1: 2^k = 2^(k - 2 + 2) := by
2406
+ exact congrArg (HPow.hPow 2) g2
2407
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2408
+ rw [h1, h2]
2409
+ ring_nf
2410
+ simp
2411
+ linarith
2412
+ linarith
2413
+ exfalso
2414
+ linarith
2415
+ . push_neg at hy
2416
+ interval_cases y
2417
+ . linarith
2418
+ . simp at h₅
2419
+ simp at h₃
2420
+ linarith
2421
+
2422
+
2423
+ lemma imo_1997_p5_11_13
2424
+ (x y k : ℕ)
2425
+ -- (h₀ : 0 < x ∧ 0 < y)
2426
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2427
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2428
+ -- (hxy : y < x)
2429
+ -- (h₃ : x = y ^ k)
2430
+ -- (hk_def : k = x / y ^ 2)
2431
+ (hk : 2 ≤ k)
2432
+ (h₅ : k = y ^ (k - 2))
2433
+ (hk5 : 5 ≤ k)
2434
+ (hy : 2 ≤ y) :
2435
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2436
+ have h₅₁: k < y^(k-2) := by
2437
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2438
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2439
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2440
+ have h₇: 4*k < 2^k := by
2441
+ exact imo_1997_p5_2 k hk5
2442
+ have h₇: k < 2^(k-2) := by
2443
+ have h₈ : k < 2 ^ k / 4 := by
2444
+ have h81: 4 ∣ 2^k := by
2445
+ have h82: 2^k = 4*2^(k-2) := by
2446
+ have h83: k = 2 + (k -2) := by
2447
+ ring_nf
2448
+ exact (add_sub_of_le hk).symm
2449
+ nth_rewrite 1 [h83]
2450
+ rw [pow_add]
2451
+ norm_num
2452
+ rw [h82]
2453
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2454
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2455
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2456
+ have g2: k = k - 2 + 2 := by
2457
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2458
+ have h1: 2^k = 2^(k - 2 + 2) := by
2459
+ exact congrArg (HPow.hPow 2) g2
2460
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2461
+ rw [h1, h2]
2462
+ ring_nf
2463
+ simp
2464
+ linarith
2465
+ linarith
2466
+ exfalso
2467
+ linarith
2468
+
2469
+
2470
+ lemma imo_1997_p5_11_14
2471
+ (x y k : ℕ)
2472
+ (h₀ : 0 < x ∧ 0 < y)
2473
+ (h₁ : x ^ y ^ 2 = y ^ x)
2474
+ (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2475
+ (hxy : y < x)
2476
+ (h₃ : x = y ^ k)
2477
+ (hk_def : k = x / y ^ 2)
2478
+ -- (hk : 2 ≤ k)
2479
+ (h₅ : k = y ^ (k - 2))
2480
+ (hk5 : 5 ≤ k)
2481
+ (hy : y < 2) :
2482
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2483
+ interval_cases y
2484
+ . linarith
2485
+ . simp at h₅
2486
+ simp at h₃
2487
+ linarith
2488
+
2489
+
2490
+ lemma imo_1997_p5_11_15
2491
+ (x y k : ℕ)
2492
+ -- (h₀ : 0 < x ∧ 0 < y)
2493
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2494
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2495
+ -- (hxy : y < x)
2496
+ -- (h₃ : x = y ^ k)
2497
+ -- (hk_def : k = x / y ^ 2)
2498
+ (hk : 2 ≤ k)
2499
+ (h₅ : k = y ^ (k - 2))
2500
+ (hk5 : 5 ≤ k)
2501
+ (hy : 2 ≤ y) :
2502
+ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
2503
+ have h₅₁: k < y^(k-2) := by
2504
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2505
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2506
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2507
+ have h₇: 4*k < 2^k := by
2508
+ exact imo_1997_p5_2 k hk5
2509
+ have h₈: k < 2^(k-2) := by
2510
+ have h₈ : k < 2 ^ k / 4 := by
2511
+ have h81: 4 ∣ 2^k := by
2512
+ have h82: 2^k = 4*2^(k-2) := by
2513
+ have h83: k = 2 + (k -2) := by
2514
+ ring_nf
2515
+ exact (add_sub_of_le hk).symm
2516
+ nth_rewrite 1 [h83]
2517
+ rw [pow_add]
2518
+ norm_num
2519
+ rw [h82]
2520
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2521
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2522
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2523
+ have g2: k = k - 2 + 2 := by
2524
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2525
+ have h1: 2^k = 2^(k - 2 + 2) := by
2526
+ exact congrArg (HPow.hPow 2) g2
2527
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2528
+ rw [h1, h2]
2529
+ ring_nf
2530
+ simp
2531
+ linarith
2532
+ linarith
2533
+ exfalso
2534
+ linarith
2535
+
2536
+
2537
+ lemma imo_1997_p5_11_16
2538
+ (y k : ℕ)
2539
+ -- (h₀ : 0 < x ∧ 0 < y)
2540
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2541
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2542
+ -- (hxy : y < x)
2543
+ -- (h₃ : x = y ^ k)
2544
+ -- (hk_def : k = x / y ^ 2)
2545
+ (hk : 2 ≤ k)
2546
+ (h₅ : k = y ^ (k - 2))
2547
+ (hk5 : 5 ≤ k)
2548
+ (hy : 2 ≤ y) :
2549
+ False := by
2550
+ have h₅₁: k < y^(k-2) := by
2551
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2552
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2553
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2554
+ have h₇: 4*k < 2^k := by
2555
+ exact imo_1997_p5_2 k hk5
2556
+ have h₈: k < 2^(k-2) := by
2557
+ have h₈ : k < 2 ^ k / 4 := by
2558
+ have h81: 4 ∣ 2^k := by
2559
+ have h82: 2^k = 4*2^(k-2) := by
2560
+ have h83: k = 2 + (k -2) := by
2561
+ ring_nf
2562
+ exact (add_sub_of_le hk).symm
2563
+ nth_rewrite 1 [h83]
2564
+ rw [pow_add]
2565
+ norm_num
2566
+ rw [h82]
2567
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2568
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2569
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2570
+ have g2: k = k - 2 + 2 := by
2571
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2572
+ have h1: 2^k = 2^(k - 2 + 2) := by
2573
+ exact congrArg (HPow.hPow 2) g2
2574
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2575
+ rw [h1, h2]
2576
+ ring_nf
2577
+ simp
2578
+ linarith
2579
+ linarith
2580
+ nth_rw 1 [← h₅] at h₅₁
2581
+ apply Nat.ne_of_lt at h₅₁
2582
+ refine false_of_ne h₅₁
2583
+
2584
+
2585
+ lemma imo_1997_p5_11_17
2586
+ (y k : ℕ)
2587
+ -- (h₀ : 0 < x ∧ 0 < y)
2588
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2589
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2590
+ -- (hxy : y < x)
2591
+ -- (h₃ : x = y ^ k)
2592
+ -- (hk_def : k = x / y ^ 2)
2593
+ (hk : 2 ≤ k)
2594
+ (h₅ : k = y ^ (k - 2))
2595
+ (hk5 : 5 ≤ k)
2596
+ (hy : 2 ≤ y) :
2597
+ k < y ^ (k - 2) := by
2598
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
2599
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2600
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2601
+ have h₇: 4*k < 2^k := by
2602
+ exact imo_1997_p5_2 k hk5
2603
+ have h₈: k < 2^(k-2) := by
2604
+ have h₈ : k < 2 ^ k / 4 := by
2605
+ have h81: 4 ∣ 2^k := by
2606
+ have h82: 2^k = 4*2^(k-2) := by
2607
+ have h83: k = 2 + (k -2) := by
2608
+ ring_nf
2609
+ exact (add_sub_of_le hk).symm
2610
+ nth_rewrite 1 [h83]
2611
+ rw [pow_add]
2612
+ norm_num
2613
+ rw [h82]
2614
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2615
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2616
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2617
+ have g2: k = k - 2 + 2 := by
2618
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2619
+ have h1: 2^k = 2^(k - 2 + 2) := by
2620
+ exact congrArg (HPow.hPow 2) g2
2621
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2622
+ rw [h1, h2]
2623
+ ring_nf
2624
+ simp
2625
+ linarith
2626
+ linarith
2627
+
2628
+
2629
+ lemma imo_1997_p5_11_18
2630
+ (y k : ℕ)
2631
+ -- (h₀ : 0 < x ∧ 0 < y)
2632
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2633
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2634
+ -- (hxy : y < x)
2635
+ -- (h₃ : x = y ^ k)
2636
+ -- (hk_def : k = x / y ^ 2)
2637
+ -- (hk : 2 ≤ k)
2638
+ -- (h₅ : k = y ^ (k - 2))
2639
+ (hk5 : 5 ≤ k)
2640
+ (hy : 2 ≤ y) :
2641
+ 2 ^ (k - 2) ≤ y ^ (k - 2) := by
2642
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
2643
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
2644
+
2645
+
2646
+ lemma imo_1997_p5_11_19
2647
+ (y k : ℕ)
2648
+ -- (h₀ : 0 < x ∧ 0 < y)
2649
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2650
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2651
+ -- (hxy : y < x)
2652
+ -- (h₃ : x = y ^ k)
2653
+ -- (hk_def : k = x / y ^ 2)
2654
+ (hk : 2 ≤ k)
2655
+ (h₅ : k = y ^ (k - 2))
2656
+ -- (hk5 : 5 ≤ k)
2657
+ -- (hy : 2 ≤ y)
2658
+ (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2659
+ (h₇ : 4 * k < 2 ^ k) :
2660
+ k < y ^ (k - 2) := by
2661
+ have h₈: k < 2^(k-2) := by
2662
+ have h₈ : k < 2 ^ k / 4 := by
2663
+ have h81: 4 ∣ 2^k := by
2664
+ have h82: 2^k = 4*2^(k-2) := by
2665
+ have h83: k = 2 + (k -2) := by
2666
+ ring_nf
2667
+ exact (add_sub_of_le hk).symm
2668
+ nth_rewrite 1 [h83]
2669
+ rw [pow_add]
2670
+ norm_num
2671
+ rw [h82]
2672
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2673
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2674
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2675
+ have g2: k = k - 2 + 2 := by
2676
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2677
+ have h1: 2^k = 2^(k - 2 + 2) := by
2678
+ exact congrArg (HPow.hPow 2) g2
2679
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2680
+ rw [h1, h2]
2681
+ ring_nf
2682
+ simp
2683
+ linarith
2684
+ linarith
2685
+
2686
+
2687
+ lemma imo_1997_p5_11_20
2688
+ (y k : ℕ)
2689
+ -- (h₀ : 0 < x ∧ 0 < y)
2690
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2691
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2692
+ -- (hxy : y < x)
2693
+ -- (h₃ : x = y ^ k)
2694
+ -- (hk_def : k = x / y ^ 2)
2695
+ (hk : 2 ≤ k)
2696
+ (h₅ : k = y ^ (k - 2))
2697
+ -- (hk5 : 5 ≤ k)
2698
+ -- (hy : 2 ≤ y)
2699
+ (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2700
+ (h₇ : 4 * k < 2 ^ k) :
2701
+ k < 2 ^ (k - 2) := by
2702
+ have h₈ : k < 2 ^ k / 4 := by
2703
+ have h81: 4 ∣ 2^k := by
2704
+ have h82: 2^k = 4*2^(k-2) := by
2705
+ have h83: k = 2 + (k -2) := by
2706
+ ring_nf
2707
+ exact (add_sub_of_le hk).symm
2708
+ nth_rewrite 1 [h83]
2709
+ rw [pow_add]
2710
+ norm_num
2711
+ rw [h82]
2712
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2713
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2714
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2715
+ have g2: k = k - 2 + 2 := by
2716
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2717
+ have h1: 2^k = 2^(k - 2 + 2) := by
2718
+ exact congrArg (HPow.hPow 2) g2
2719
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2720
+ rw [h1, h2]
2721
+ ring_nf
2722
+ simp
2723
+ linarith
2724
+
2725
+
2726
+ lemma imo_1997_p5_11_21
2727
+ (k : ℕ)
2728
+ -- (h₀ : 0 < x ∧ 0 < y)
2729
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2730
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2731
+ -- (hxy : y < x)
2732
+ -- (h₃ : x = y ^ k)
2733
+ -- (hk_def : k = x / y ^ 2)
2734
+ (hk : 2 ≤ k)
2735
+ -- (h₅ : k = y ^ (k - 2))
2736
+ -- (hk5 : 5 ≤ k)
2737
+ -- (hy : 2 ≤ y)
2738
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2739
+ (h₇ : 4 * k < 2 ^ k) :
2740
+ k < 2 ^ k / 4 := by
2741
+ have h81: 4 ∣ 2^k := by
2742
+ have h82: 2^k = 4*2^(k-2) := by
2743
+ have h83: k = 2 + (k -2) := by
2744
+ ring_nf
2745
+ exact (add_sub_of_le hk).symm
2746
+ nth_rewrite 1 [h83]
2747
+ rw [pow_add]
2748
+ norm_num
2749
+ rw [h82]
2750
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2751
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
2752
+
2753
+
2754
+ lemma imo_1997_p5_11_22
2755
+ -- (x y : ℕ)
2756
+ (k : ℕ)
2757
+ -- (h₀ : 0 < x ∧ 0 < y)
2758
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2759
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2760
+ -- (hxy : y < x)
2761
+ -- (h₃ : x = y ^ k)
2762
+ -- (hk_def : k = x / y ^ 2)
2763
+ (hk : 2 ≤ k) :
2764
+ -- (h₅ : k = y ^ (k - 2))
2765
+ -- (hk5 : 5 ≤ k)
2766
+ -- (hy : 2 ≤ y)
2767
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2768
+ -- (h₇ : 4 * k < 2 ^ k) :
2769
+ 4 ∣ 2 ^ k := by
2770
+ have h82: 2^k = 4*2^(k-2) := by
2771
+ have h83: k = 2 + (k -2) := by
2772
+ ring_nf
2773
+ exact (add_sub_of_le hk).symm
2774
+ nth_rewrite 1 [h83]
2775
+ rw [pow_add]
2776
+ norm_num
2777
+ rw [h82]
2778
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2779
+
2780
+
2781
+
2782
+ lemma imo_1997_p5_11_23
2783
+ -- (x y : ℕ)
2784
+ (k : ℕ)
2785
+ -- (h₀ : 0 < x ∧ 0 < y)
2786
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2787
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2788
+ -- (hxy : y < x)
2789
+ -- (h₃ : x = y ^ k)
2790
+ -- (hk_def : k = x / y ^ 2)
2791
+ (hk : 2 ≤ k) :
2792
+ -- (h₅ : k = y ^ (k - 2))
2793
+ -- (hk5 : 5 ≤ k)
2794
+ -- (hy : 2 ≤ y)
2795
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2796
+ -- (h₇ : 4 * k < 2 ^ k) :
2797
+ 2 ^ k = 4 * 2 ^ (k - 2) := by
2798
+ have h83: k = 2 + (k -2) := by
2799
+ ring_nf
2800
+ exact (add_sub_of_le hk).symm
2801
+ nth_rewrite 1 [h83]
2802
+ rw [pow_add]
2803
+ norm_num
2804
+
2805
+
2806
+ lemma imo_1997_p5_11_24
2807
+ -- (x y : ℕ)
2808
+ (k : ℕ)
2809
+ -- (h₀ : 0 < x ∧ 0 < y)
2810
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2811
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2812
+ -- (hxy : y < x)
2813
+ -- (h₃ : x = y ^ k)
2814
+ -- (hk_def : k = x / y ^ 2)
2815
+ -- (hk : 2 ≤ k)
2816
+ -- (h₅ : k = y ^ (k - 2))
2817
+ -- (hk5 : 5 ≤ k)
2818
+ -- (hy : 2 ≤ y)
2819
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2820
+ -- (h₇ : 4 * k < 2 ^ k)
2821
+ (h₈₃ : k = 2 + (k - 2)) :
2822
+ 2 ^ k = 4 * 2 ^ (k - 2) := by
2823
+ nth_rewrite 1 [h₈₃]
2824
+ rw [pow_add]
2825
+ norm_num
2826
+
2827
+
2828
+ lemma imo_1997_p5_11_25
2829
+ -- (x y : ℕ)
2830
+ (k : ℕ)
2831
+ -- (h₀ : 0 < x ∧ 0 < y)
2832
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2833
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2834
+ -- (hxy : y < x)
2835
+ -- (h₃ : x = y ^ k)
2836
+ -- (hk_def : k = x / y ^ 2)
2837
+ -- (hk : 2 ≤ k)
2838
+ -- (h₅ : k = y ^ (k - 2))
2839
+ -- (hk5 : 5 ≤ k)
2840
+ -- (hy : 2 ≤ y)
2841
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2842
+ -- (h₇ : 4 * k < 2 ^ k)
2843
+ (h82 : 2 ^ k = 4 * 2 ^ (k - 2)) :
2844
+ 4 ∣ 2 ^ k := by
2845
+ rw [h82]
2846
+ exact Nat.dvd_mul_right 4 (2^(k-2))
2847
+
2848
+
2849
+ lemma imo_1997_p5_11_26
2850
+ -- (x : ℕ)
2851
+ (y k : ℕ)
2852
+ -- (h₀ : 0 < x ∧ 0 < y)
2853
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2854
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2855
+ -- (hxy : y < x)
2856
+ -- (h₃ : x = y ^ k)
2857
+ -- (hk_def : k = x / y ^ 2)
2858
+ (hk : 2 ≤ k)
2859
+ (h₅ : k = y ^ (k - 2))
2860
+ -- (hk5 : 5 ≤ k)
2861
+ -- (hy : 2 ≤ y)
2862
+ (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2863
+ -- (h₇ : 4 * k < 2 ^ k)
2864
+ (h₈ : k < 2 ^ k / 4) :
2865
+ k < 2 ^ (k - 2) := by
2866
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
2867
+ have g2: k = k - 2 + 2 := by
2868
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2869
+ have h1: 2^k = 2^(k - 2 + 2) := by
2870
+ exact congrArg (HPow.hPow 2) g2
2871
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2872
+ rw [h1, h2]
2873
+ ring_nf
2874
+ simp
2875
+ linarith
2876
+
2877
+
2878
+ lemma imo_1997_p5_11_27
2879
+ -- (x y : ℕ)
2880
+ (k : ℕ)
2881
+ -- (h₀ : 0 < x ∧ 0 < y)
2882
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2883
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2884
+ -- (hxy : y < x)
2885
+ -- (h₃ : x = y ^ k)
2886
+ -- (hk_def : k = x / y ^ 2)
2887
+ (hk : 2 ≤ k) :
2888
+ -- (h₅ : k = y ^ (k - 2))
2889
+ -- (hk5 : 5 ≤ k)
2890
+ -- (hy : 2 ≤ y)
2891
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2892
+ -- (h₇ : 4 * k < 2 ^ k)
2893
+ -- (h₈ : k < 2 ^ k / 4) :
2894
+ 2 ^ k / 4 = 2 ^ (k - 2) := by
2895
+ have g2: k = k - 2 + 2 := by
2896
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
2897
+ have h1: 2^k = 2^(k - 2 + 2) := by
2898
+ exact congrArg (HPow.hPow 2) g2
2899
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
2900
+ rw [h1, h2]
2901
+ ring_nf
2902
+ simp
2903
+
2904
+ lemma imo_1997_p5_11_28
2905
+ -- (x y : ℕ)
2906
+ (k : ℕ)
2907
+ -- (h₀ : 0 < x ∧ 0 < y)
2908
+ -- (h₁ : x ^ y ^ 2 = y ^ x)
2909
+ -- (g₁ : x ^ y ^ 2 = (x ^ y) ^ y)
2910
+ -- (hxy : y < x)
2911
+ -- (h₃ : x = y ^ k)
2912
+ -- (hk_def : k = x / y ^ 2)
2913
+ -- (hk : 2 ≤ k)
2914
+ -- (h₅ : k = y ^ (k - 2))
2915
+ -- (hk5 : 5 ≤ k)
2916
+ -- (hy : 2 ≤ y)
2917
+ -- (h₆ : 2 ^ (k - 2) ≤ y ^ (k - 2))
2918
+ -- (h₇ : 4 * k < 2 ^ k)
2919
+ -- (h₈ : k < 2 ^ k / 4)
2920
+ -- (g2 : k = k - 2 + 2)
2921
+ (h1 : 2 ^ k = 2 ^ (k - 2 + 2))
2922
+ (h2 : 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2) :
2923
+ 2 ^ k / 4 = 2 ^ (k - 2) := by
2924
+ rw [h1, h2]
2925
+ ring_nf
2926
+ simp
Lemmas/imo_2022_p2_lemmas.lean ADDED
@@ -0,0 +1,1606 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ set_option linter.unusedVariables.analyzeTactics true
4
+
5
+ open Real
6
+
7
+ lemma imo_2022_p2_simp_1
8
+ (g : ℝ → ℝ)
9
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y,
10
+ 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z) :
11
+ ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y := by
12
+ intros x y hp h₁
13
+ by_contra! hc
14
+ have g₁: 2 * x * x < g x + g x := by
15
+ let ⟨p,h₁₁⟩ := h₀ x hp.1
16
+ cases' h₁₁ with h₁₁ h₁₂
17
+ cases' h₁₂ with h₁₂ h₁₃
18
+ by_cases hxp: x ≠ p
19
+ . have h₁₄: ¬ g x + g x ≤ 2 * x * x := by
20
+ refine h₁₃ x ?_
21
+ constructor
22
+ . exact hp.1
23
+ . exact hxp
24
+ exact not_le.mp h₁₄
25
+ . push_neg at hxp
26
+ exfalso
27
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
28
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
29
+ refine h₁₃ y ?_
30
+ constructor
31
+ . exact hp.2
32
+ . exact hpy
33
+ linarith
34
+ have g₂: 2 * y * y < g y + g y := by
35
+ let ⟨p,h₁₁⟩ := h₀ y hp.2
36
+ cases' h₁₁ with h₁₁ h₁₂
37
+ cases' h₁₂ with h₁₂ h₁₃
38
+ by_cases hyp: y ≠ p
39
+ . have h₁₄: ¬ g y + g y ≤ 2 * y * y := by
40
+ refine h₁₃ y ?_
41
+ constructor
42
+ . exact hp.2
43
+ . exact hyp
44
+ exact not_le.mp h₁₄
45
+ . push_neg at hyp
46
+ exfalso
47
+ have hpx: x ≠ p := by exact Ne.trans_eq hc hyp
48
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
49
+ rw [add_comm, mul_right_comm]
50
+ refine h₁₃ x ?_
51
+ constructor
52
+ . exact hp.1
53
+ . exact hpx
54
+ linarith
55
+ ring_nf at g₁ g₂
56
+ simp at g₁ g₂
57
+ have g₆: (x - y) ≠ 0 := by exact sub_ne_zero.mpr hc
58
+ have g₇: 0 < (x - y) ^ 2 := by exact (sq_pos_iff).mpr g₆
59
+ linarith
60
+
61
+
62
+ lemma imo_2022_p2_simp_1_1
63
+ (g : ℝ → ℝ)
64
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y
65
+ ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
66
+ (x y : ℝ)
67
+ (hp : 0 < x ∧ 0 < y)
68
+ (h₁ : g x + g y ≤ 2 * x * y)
69
+ (hc : x ≠ y) :
70
+ 2 * x * x < g x + g x := by
71
+ let ⟨p,h₁₁⟩ := h₀ x hp.1
72
+ cases' h₁₁ with h₁₁ h₁₂
73
+ cases' h₁₂ with h₁₂ h₁₃
74
+ by_cases hxp: x ≠ p
75
+ . have h₁₄: ¬ g x + g x ≤ 2 * x * x := by
76
+ refine h₁₃ x ?_
77
+ constructor
78
+ . exact hp.1
79
+ . exact hxp
80
+ exact not_le.mp h₁₄
81
+ . push_neg at hxp
82
+ exfalso
83
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
84
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
85
+ refine h₁₃ y ?_
86
+ constructor
87
+ . exact hp.2
88
+ . exact hpy
89
+ linarith
90
+
91
+
92
+
93
+ lemma imo_2022_p2_simp_1_2
94
+ (g : ℝ → ℝ)
95
+ -- h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z
96
+ (x y : ℝ)
97
+ -- (hp : 0 < x ∧ 0 < y)
98
+ (h₁ : g x + g y ≤ 2 * x * y)
99
+ (hc : x ≠ y)
100
+ (g₁ : 2 * x * x < g x + g x)
101
+ (g₂ : 2 * y * y < g y + g y) :
102
+ False := by
103
+ ring_nf at g₁ g₂
104
+ simp at g₁ g₂
105
+ have g₆: (x - y) ≠ 0 := by exact sub_ne_zero.mpr hc
106
+ have g₇: 0 < (x - y) ^ 2 := by exact (sq_pos_iff).mpr g₆
107
+ linarith
108
+
109
+
110
+ lemma imo_2022_p2_simp_1_3
111
+ -- (g : ℝ → ℝ)
112
+ (x y : ℝ)
113
+ -- (h₁ : g x + g y ≤ 2 * x * y)
114
+ (hc : x ≠ y) :
115
+ -- (g₁ : x ^ 2 < g x)
116
+ -- (g₂ : y ^ 2 < g y) :
117
+ 0 < (x - y) ^ 2 := by
118
+ refine (sq_pos_iff).mpr ?_
119
+ exact sub_ne_zero.mpr hc
120
+
121
+
122
+ lemma imo_2022_p2_simp_1_4
123
+ (g : ℝ → ℝ)
124
+ -- h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z
125
+ (x y : ℝ)
126
+ -- (hp : 0 < x ∧ 0 < y)
127
+ (h₁ : g x + g y ≤ 2 * x * y)
128
+ -- (hc : x ≠ y)
129
+ (g₁ : 2 * x * x < g x + g x)
130
+ (g₂ : 2 * y * y < g y + g y) :
131
+ (x - y) ^ 2 < 0 := by
132
+ linarith
133
+
134
+
135
+ lemma imo_2022_p2_simp_1_5
136
+ (g : ℝ → ℝ)
137
+ -- h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z
138
+ (x y : ℝ)
139
+ (hp : 0 < x ∧ 0 < y)
140
+ (h₁ : g x + g y ≤ 2 * x * y)
141
+ (hc : x ≠ y)
142
+ (p : ℝ)
143
+ -- (h₁₁ : 0 < p)
144
+ -- (h₁₂ : g x + g p ≤ 2 * x * p)
145
+ (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ p → ¬g x + g z ≤ 2 * x * z) :
146
+ 2 * x * x < g x + g x := by
147
+ by_cases hxp: x ≠ p
148
+ . have h₁₄: ¬ g x + g x ≤ 2 * x * x := by
149
+ refine h₁₃ x ?_
150
+ constructor
151
+ . exact hp.1
152
+ . exact hxp
153
+ exact not_le.mp h₁₄
154
+ . push_neg at hxp
155
+ exfalso
156
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
157
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
158
+ refine h₁₃ y ?_
159
+ constructor
160
+ . exact hp.2
161
+ . exact hpy
162
+ linarith
163
+
164
+
165
+ lemma imo_2022_p2_simp_1_6
166
+ (g : ℝ → ℝ)
167
+ (x y : ℝ)
168
+ (hxyp : 0 < x ∧ 0 < y)
169
+ -- h₁ : g x + g y ≤ 2 * x * y
170
+ -- hc : x ≠ y
171
+ (p : ℝ)
172
+ (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ p → ¬g x + g z ≤ 2 * x * z)
173
+ (hxp : x ≠ p) :
174
+ 2 * x * x < g x + g x := by
175
+ have h₁₄: ¬ g x + g x ≤ 2 * x * x := by
176
+ refine h₁₃ x ?_
177
+ constructor
178
+ . exact hxyp.1
179
+ . exact hxp
180
+ exact not_le.mp h₁₄
181
+
182
+
183
+ lemma imo_2022_p2_simp_1_7
184
+ (g : ℝ → ℝ)
185
+ (x y : ℝ)
186
+ (hxyp : 0 < x ∧ 0 < y)
187
+ (p : ℝ)
188
+ (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ p → ¬g x + g z ≤ 2 * x * z)
189
+ (hxp : x ≠ p) :
190
+ ¬g x + g x ≤ 2 * x * x := by
191
+ refine h₁₃ x ?_
192
+ constructor
193
+ . exact hxyp.1
194
+ . exact hxp
195
+
196
+
197
+
198
+ lemma imo_2022_p2_simp_1_8
199
+ (g : ℝ → ℝ)
200
+ (x y : ℝ)
201
+ (hp : 0 < x ∧ 0 < y)
202
+ (h₁ : g x + g y ≤ 2 * x * y)
203
+ (hc : x ≠ y)
204
+ (p : ℝ)
205
+ (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ p → ¬g x + g z ≤ 2 * x * z)
206
+ (hxp : ¬x ≠ p) :
207
+ 2 * x * x < g x + g x := by
208
+ push_neg at hxp
209
+ exfalso
210
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
211
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
212
+ refine h₁₃ y ?_
213
+ constructor
214
+ . exact hp.2
215
+ . exact hpy
216
+ linarith
217
+
218
+
219
+
220
+ lemma imo_2022_p2_simp_1_9
221
+ (g : ℝ → ℝ)
222
+ (x y : ℝ)
223
+ (hp : 0 < x ∧ 0 < y)
224
+ (h₁ : g x + g y ≤ 2 * x * y)
225
+ (hc : x ≠ y)
226
+ (p : ℝ)
227
+ (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ p → ¬g x + g z ≤ 2 * x * z)
228
+ (hxp : x = p) :
229
+ False := by
230
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
231
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
232
+ refine h₁₃ y ?_
233
+ constructor
234
+ . exact hp.2
235
+ . exact hpy
236
+ linarith
237
+
238
+
239
+
240
+
241
+ lemma imo_2022_p2_simp_2
242
+ (g : ℝ → ℝ)
243
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧
244
+ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
245
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y) :
246
+ ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2 := by
247
+ intros x hxp
248
+ let ⟨y,h₁₁⟩ := h₀ x hxp
249
+ cases' h₁₁ with h₁₁ h₁₂
250
+ cases' h₁₂ with h₁₂ h₁₃
251
+ have hxy: x = y := by
252
+ apply h₁ x y
253
+ . exact { left := hxp, right := h₁₁ }
254
+ . exact h₁₂
255
+ rw [← hxy] at h₁₂
256
+ linarith
257
+
258
+
259
+ lemma imo_2022_p2_simp_2_1
260
+ (g : ℝ → ℝ)
261
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y
262
+ -- ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
263
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
264
+ (x y: ℝ)
265
+ (hxp : 0 < x)
266
+ (h₁₁ : 0 < y)
267
+ (h₁₂ : g x + g y ≤ 2 * x * y) :
268
+ -- (h₁₃ : ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z) :
269
+ x = y := by
270
+ apply h₁ x y
271
+ . exact { left := hxp, right := h₁₁ }
272
+ . exact h₁₂
273
+
274
+
275
+ lemma imo_2022_p2_simp_2_2
276
+ (g : ℝ → ℝ)
277
+ (x y : ℝ)
278
+ (h₁₂ : g x + g y ≤ 2 * x * y)
279
+ (hxy : x = y) :
280
+ g x ≤ x ^ 2 := by
281
+ rw [← hxy] at h₁₂
282
+ linarith
283
+
284
+
285
+ lemma imo_2022_p2_simp_3
286
+ (g : ℝ → ℝ)
287
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y
288
+ ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
289
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
290
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2) :
291
+ ∀ (x : ℝ), 0 < x → ¬g x < x ^ 2 := by
292
+ simp
293
+ by_contra! hc
294
+ let ⟨x,hxp⟩ := hc
295
+ cases' hxp with hxp h₃
296
+ let d₁:ℝ := x ^ 2 - g x
297
+ have hd₁ : g x = x ^ 2 - d₁ := by exact (sub_sub_self (x ^ 2) (g x)).symm
298
+ let z:ℝ := x + Real.sqrt d₁
299
+ have hz: z = x + Real.sqrt d₁ := by exact rfl
300
+ have hzp: 0 < z := by
301
+ refine add_pos hxp ?_
302
+ refine Real.sqrt_pos_of_pos ?_
303
+ exact sub_pos.mpr h₃
304
+ have hxz: z ≠ x := by
305
+ rw [hz]
306
+ simp
307
+ push_neg
308
+ refine Real.sqrt_ne_zero'.mpr ?_
309
+ exact sub_pos.mpr h₃
310
+ -- have h₄: g z ≤ z ^ 2 := by exact h₂ z hzp
311
+ have h₅: g x + g z ≤ 2 * x * z := by
312
+ rw [hd₁]
313
+ have h₅₁: - d₁ + Real.sqrt (x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0 := by
314
+ simp
315
+ rw [Real.sq_sqrt]
316
+ exact sub_nonneg_of_le (h₂ x hxp)
317
+ have h₅₂: x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
318
+ rw [hz, mul_add, add_sq]
319
+ ring_nf
320
+ repeat rw [add_assoc]
321
+ refine add_le_add_left ?_ (x * Real.sqrt (x ^ 2 - g x) * 2)
322
+ rw [hd₁]
323
+ linarith
324
+ exact add_le_of_add_le_left h₅₂ (h₂ z hzp)
325
+ let ⟨y,hyp⟩ := h₀ x hxp
326
+ cases' hyp with hyp h₆
327
+ cases' h₆ with h₆ h₇
328
+ have hxy: x = y := by
329
+ apply h₁
330
+ . exact { left := hxp, right := hyp }
331
+ . exact h₆
332
+ have h₈: ¬g x + g z ≤ 2 * x * z := by
333
+ refine h₇ z ?_
334
+ constructor
335
+ . exact hzp
336
+ . exact Ne.trans_eq hxz hxy
337
+ linarith[h₅,h₈]
338
+
339
+
340
+ lemma imo_2022_p2_simp_3_1
341
+ (g : ℝ → ℝ)
342
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y
343
+ ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
344
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
345
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
346
+ (hc : ∃ x, 0 < x ∧ g x < x ^ 2) :
347
+ False := by
348
+ let ⟨x,hxp⟩ := hc
349
+ cases' hxp with hxp h₃
350
+ let d₁:ℝ := x ^ 2 - g x
351
+ have hd₁ : g x = x ^ 2 - d₁ := by exact (sub_sub_self (x ^ 2) (g x)).symm
352
+ let z:ℝ := x + Real.sqrt d₁
353
+ have hz: z = x + Real.sqrt d₁ := by exact rfl
354
+ have hzp: 0 < z := by
355
+ refine add_pos hxp ?_
356
+ refine Real.sqrt_pos_of_pos ?_
357
+ exact sub_pos.mpr h₃
358
+ have hxz: z ≠ x := by
359
+ rw [hz]
360
+ simp
361
+ push_neg
362
+ refine Real.sqrt_ne_zero'.mpr ?_
363
+ exact sub_pos.mpr h₃
364
+ have h₅: g x + g z ≤ 2 * x * z := by
365
+ rw [hd₁]
366
+ have h₅₁: - d₁ + Real.sqrt (x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0 := by
367
+ simp
368
+ rw [Real.sq_sqrt]
369
+ exact sub_nonneg_of_le (h₂ x hxp)
370
+ have h₅₂: x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
371
+ rw [hz, mul_add, add_sq]
372
+ ring_nf
373
+ repeat rw [add_assoc]
374
+ refine add_le_add_left ?_ (x * Real.sqrt (x ^ 2 - g x) * 2)
375
+ rw [hd₁]
376
+ linarith
377
+ exact add_le_of_add_le_left h₅₂ (h₂ z hzp)
378
+ let ⟨y,hyp⟩ := h₀ x hxp
379
+ cases' hyp with hyp h₆
380
+ cases' h₆ with h₆ h₇
381
+ have hxy: x = y := by
382
+ apply h₁
383
+ . exact { left := hxp, right := hyp }
384
+ . exact h₆
385
+ have h₈: ¬g x + g z ≤ 2 * x * z := by
386
+ refine h₇ z ?_
387
+ constructor
388
+ . exact hzp
389
+ . exact Ne.trans_eq hxz hxy
390
+ linarith[h₅,h₈]
391
+
392
+
393
+ lemma imo_2022_p2_simp_3_2
394
+ (g : ℝ → ℝ)
395
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
396
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
397
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
398
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
399
+ (x z d₁ : ℝ)
400
+ (hxp : 0 < x)
401
+ (h₃ : g x < x ^ 2)
402
+ (hd₀ : d₁ = x ^ 2 - g x)
403
+ (hd₁ : g x = x ^ 2 - d₁)
404
+ (hz : z = x + √d₁) :
405
+ False := by
406
+ have hzp: 0 < z := by
407
+ rw [hz]
408
+ refine add_pos hxp ?_
409
+ refine Real.sqrt_pos_of_pos ?_
410
+ rw [hd₀]
411
+ exact sub_pos.mpr h₃
412
+ have hxz: z ≠ x := by
413
+ rw [hz]
414
+ simp
415
+ push_neg
416
+ refine Real.sqrt_ne_zero'.mpr ?_
417
+ rw [hd₀]
418
+ exact sub_pos.mpr h₃
419
+ have h₅: g x + g z ≤ 2 * x * z := by
420
+ rw [hd₁]
421
+ have h₅₂: x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
422
+ rw [hz, mul_add, add_sq]
423
+ ring_nf
424
+ repeat rw [add_assoc]
425
+ refine add_le_add_left ?_ (x * √d₁ * 2)
426
+ rw [sq_sqrt]
427
+ simp
428
+ linarith
429
+ exact add_le_of_add_le_left h₅₂ (h₂ z hzp)
430
+ let ⟨y,hyp⟩ := h₀ x hxp
431
+ cases' hyp with hyp h₆
432
+ cases' h₆ with h₆ h₇
433
+ have hxy: x = y := by
434
+ apply h₁
435
+ . exact { left := hxp, right := hyp }
436
+ . exact h₆
437
+ have h₈: ¬g x + g z ≤ 2 * x * z := by
438
+ refine h₇ z ?_
439
+ constructor
440
+ . exact hzp
441
+ . exact Ne.trans_eq hxz hxy
442
+ linarith[h₅,h₈]
443
+
444
+
445
+ lemma imo_2022_p2_simp_3_3
446
+ (g : ℝ → ℝ)
447
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
448
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
449
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
450
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
451
+ (x z d₁ : ℝ)
452
+ (hxp : 0 < x)
453
+ (h₃ : g x < x ^ 2)
454
+ (hd₀ : d₁ = x ^ 2 - g x)
455
+ -- (hd₁ : g x = x ^ 2 - d₁)
456
+ (hz : z = x + √d₁) :
457
+ 0 < z := by
458
+ rw [hz]
459
+ refine add_pos hxp ?_
460
+ refine Real.sqrt_pos_of_pos ?_
461
+ rw [hd₀]
462
+ exact sub_pos.mpr h₃
463
+
464
+
465
+ lemma imo_2022_p2_simp_3_4
466
+ (g : ℝ → ℝ)
467
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
468
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
469
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
470
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
471
+ (x z d₁: ℝ)
472
+ -- (hxp : 0 < x)
473
+ (h₃ : g x < x ^ 2)
474
+ (hd₀ : d₁ = x ^ 2 - g x)
475
+ -- (hd₁ : g x = x ^ 2 - d₁)
476
+ (hz : z = x + √d₁) :
477
+ -- (hzp : 0 < z) :
478
+ z ≠ x := by
479
+ rw [hz]
480
+ simp
481
+ push_neg
482
+ refine Real.sqrt_ne_zero'.mpr ?_
483
+ rw [hd₀]
484
+ exact sub_pos.mpr h₃
485
+
486
+
487
+ lemma imo_2022_p2_simp_3_5
488
+ (g : ℝ → ℝ)
489
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
490
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
491
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
492
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
493
+ (x z d₁: ℝ)
494
+ -- (hxp : 0 < x)
495
+ (h₃ : g x < x ^ 2)
496
+ -- (hd₀ : d₁ = x ^ 2 - g x)
497
+ (hd₁ : g x = x ^ 2 - d₁)
498
+ (hz : z = x + √d₁)
499
+ (hzp : 0 < z) :
500
+ -- (hxz : z ≠ x) :
501
+ g x + g z ≤ 2 * x * z := by
502
+ rw [hd₁]
503
+ have h₅₂: x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
504
+ rw [hz, mul_add, add_sq]
505
+ ring_nf
506
+ repeat rw [add_assoc]
507
+ refine add_le_add_left ?_ (x * √d₁ * 2)
508
+ rw [sq_sqrt]
509
+ simp
510
+ linarith
511
+ exact add_le_of_add_le_left h₅₂ (h₂ z hzp)
512
+
513
+
514
+ lemma imo_2022_p2_simp_3_6
515
+ (g : ℝ → ℝ)
516
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
517
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
518
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
519
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
520
+ (x z : ℝ)
521
+ (hxp : 0 < x)
522
+ -- (h₃ : g x < x ^ 2)
523
+ -- (hd₀ : d₁ = x ^ 2 - g x)
524
+ -- (hd₁ : g x = x ^ 2 - d₁)
525
+ -- (hz : z = x + √d₁)
526
+ (hzp : 0 < z)
527
+ (hxz : z ≠ x)
528
+ (h₅ : g x + g z ≤ 2 * x * z)
529
+ (y : ℝ)
530
+ (hyp : 0 < y)
531
+ (h₆ : g x + g y ≤ 2 * x * y)
532
+ (h₇ : ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z) :
533
+ False := by
534
+ have hxy: x = y := by
535
+ apply h₁
536
+ . exact { left := hxp, right := hyp }
537
+ . exact h₆
538
+ have h₈: ¬g x + g z ≤ 2 * x * z := by
539
+ refine h₇ z ?_
540
+ constructor
541
+ . exact hzp
542
+ . exact Ne.trans_eq hxz hxy
543
+ linarith[h₅,h₈]
544
+
545
+
546
+ lemma imo_2022_p2_simp_3_7
547
+ (g : ℝ → ℝ)
548
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
549
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
550
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
551
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
552
+ (x : ℝ)
553
+ (hxp : 0 < x)
554
+ -- (h₃ : g x < x ^ 2)
555
+ -- (hd₀ : d₁ = x ^ 2 - g x)
556
+ -- (hd₁ : g x = x ^ 2 - d₁)
557
+ -- (hz : z = x + √d₁)
558
+ -- (hzp : 0 < z)
559
+ -- (hxz : z ≠ x)
560
+ -- (h₅ : g x + g z ≤ 2 * x * z)
561
+ (y : ℝ)
562
+ (hyp : 0 < y)
563
+ (h₆ : g x + g y ≤ 2 * x * y) :
564
+ -- (h₇ : ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z) :
565
+ x = y := by
566
+ apply h₁
567
+ . exact { left := hxp, right := hyp }
568
+ . exact h₆
569
+
570
+
571
+ lemma imo_2022_p2_simp_3_8
572
+ (g : ℝ → ℝ)
573
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
574
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
575
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
576
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
577
+ (x z : ℝ)
578
+ -- (hxp : 0 < x)
579
+ -- (h₃ : g x < x ^ 2)
580
+ -- (hd₀ : d₁ = x ^ 2 - g x)
581
+ -- (hd₁ : g x = x ^ 2 - d₁)
582
+ -- (hz : z = x + √d₁)
583
+ (hzp : 0 < z)
584
+ (hxz : z ≠ x)
585
+ -- (h₅ : g x + g z ≤ 2 * x * z)
586
+ (y : ℝ)
587
+ -- (hyp : 0 < y)
588
+ -- (h₆ : g x + g y ≤ 2 * x * y)
589
+ (h₇ : ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
590
+ (hxy : x = y) :
591
+ ¬g x + g z ≤ 2 * x * z := by
592
+ refine h₇ z ?_
593
+ constructor
594
+ . exact hzp
595
+ . exact Ne.trans_eq hxz hxy
596
+
597
+
598
+ lemma imo_2022_p2_simp_3_9
599
+ (g : ℝ → ℝ)
600
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
601
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
602
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
603
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
604
+ (x d₁ : ℝ)
605
+ (hxp : 0 < x)
606
+ -- (h₃ : g x < x ^ 2)
607
+ (hd₀ : d₁ = x ^ 2 - g x) :
608
+ -- (hd₁ : g x = x ^ 2 - d₁)
609
+ -- (hz : z = x + √d₁)
610
+ -- (hzp : 0 < z)
611
+ -- (hxz : z ≠ x) :
612
+ -d₁ + √(x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0 := by
613
+ simp
614
+ rw [Real.sq_sqrt]
615
+ rw [hd₀]
616
+ exact sub_nonneg_of_le (h₂ x hxp)
617
+
618
+
619
+ lemma imo_2022_p2_simp_3_10
620
+ (g : ℝ → ℝ)
621
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
622
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
623
+ -- (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
624
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
625
+ (x z d₁ : ℝ)
626
+ -- (hxp : 0 < x)
627
+ (h₃ : g x < x ^ 2)
628
+ -- (hd₀ : d₁ = x ^ 2 - g x)
629
+ (hd₁ : g x = x ^ 2 - d₁)
630
+ (hz : z = x + √d₁) :
631
+ -- (hzp : 0 < z)
632
+ -- (hxz : z ≠ x)
633
+ -- (h₅₁ : -d₁ + √(x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0) :
634
+ x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
635
+ rw [hz, mul_add, add_sq]
636
+ ring_nf
637
+ repeat rw [add_assoc]
638
+ refine add_le_add_left ?_ (x * √d₁ * 2)
639
+ rw [sq_sqrt]
640
+ simp
641
+ linarith
642
+
643
+
644
+ lemma imo_2022_p2_simp_3_11
645
+ (g : ℝ → ℝ)
646
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
647
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
648
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
649
+ -- (hc : ∃ x, 0 < x ∧ g x < x ^ 2)
650
+ (x z d₁ : ℝ)
651
+ -- (hxp : 0 < x)
652
+ -- (h₃ : g x < x ^ 2)
653
+ -- (hd₀ : d₁ = x ^ 2 - g x)
654
+ -- (hd₁ : g x = x ^ 2 - d₁)
655
+ -- (hz : z = x + √d₁)
656
+ (hzp : 0 < z)
657
+ -- (hxz : z ≠ x)
658
+ -- (h₅₁ : -d₁ + √(x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0)
659
+ (h₅₂ : x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z) :
660
+ x ^ 2 - d₁ + g z ≤ 2 * x * z := by
661
+ refine add_le_of_add_le_left h₅₂ ?_
662
+ exact h₂ z hzp
663
+
664
+
665
+ lemma imo_2022_p2_simp_4
666
+ (g : ℝ → ℝ)
667
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃ y, 0 < y ∧ g x + g y ≤ 2 * x * y
668
+ -- ∧ ∀ (z : ℝ), 0 < z ∧ z ≠ y → ¬g x + g z ≤ 2 * x * z)
669
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y)
670
+ (h₂ : ∀ (x : ℝ), 0 < x → g x ≤ x ^ 2)
671
+ (h₃ : ∀ (x : ℝ), 0 < x → ¬g x < x ^ 2) :
672
+ ∀ (x : ℝ), 0 < x → g x = x ^ 2 := by
673
+ intros x hxp
674
+ have g₂: g x ≤ x ^ 2 := by exact h₂ x hxp
675
+ have g₃: ¬ g x < x ^ 2 := by exact h₃ x hxp
676
+ linarith
677
+
678
+
679
+
680
+ lemma imo_2022_p2_1
681
+ (f : ℝ → ℝ)
682
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
683
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2) :
684
+ ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y := by
685
+ intros x y hp h₁
686
+ by_contra! hc
687
+ have h₁₀: x * f x + x * f x > 2 := by
688
+ let ⟨z,h₁₁⟩ := h₀ x hp.1
689
+ cases' h₁₁ with h₁₁ h₁₂
690
+ have h₁₄: y = z := by
691
+ apply h₁₂ y
692
+ constructor
693
+ . exact hp.2
694
+ . exact h₁
695
+ have hxz: ¬ x = z := by exact Ne.trans_eq hc h₁₄
696
+ have h₁₆: ¬ (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x := by
697
+ exact mt (h₁₂ x) hxz
698
+ have h₁₇: ¬ (0 < x ∧ x * f x + x * f x ≤ 2) := by exact h₁₆
699
+ push_neg at h₁₇
700
+ exact h₁₇ hp.1
701
+ have h₁₁: y * f y + y * f y > 2 := by
702
+ let ⟨z,h₁₁⟩ := h₀ y hp.2
703
+ cases' h₁₁ with h₁₁ h₁₂
704
+ have h₁₄: x = z := by
705
+ apply h₁₂ x
706
+ constructor
707
+ . exact hp.1
708
+ . rw [add_comm]
709
+ exact h₁
710
+ have hxz: ¬ y = z := by exact Ne.trans_eq (id (Ne.symm hc)) h₁₄
711
+ have h₁₆: ¬ (fun y_2 => 0 < y_2 ∧ y * f y_2 + y_2 * f y ≤ 2) y := by
712
+ exact mt (h₁₂ y) hxz
713
+ have h₁₇: ¬ (0 < y ∧ y * f y + y * f y ≤ 2) := by exact h₁₆
714
+ push_neg at h₁₇
715
+ exact h₁₇ hp.2
716
+ ring_nf at h₁₀ h₁₁
717
+ simp at h₁₀ h₁₁
718
+ have h₁₅: 1 / x < f x := by exact (div_lt_iff₀' hp.1).mpr (h₁₀)
719
+ have h₁₆: 1 / y < f y := by exact (div_lt_iff₀' hp.2).mpr (h₁₁)
720
+ have h₁₂: x / y + y / x < 2 := by
721
+ refine lt_of_le_of_lt' h₁ ?_
722
+ refine add_lt_add ?_ ?_
723
+ . rw [← mul_one_div]
724
+ exact (mul_lt_mul_left hp.1).mpr h₁₆
725
+ . rw [← mul_one_div]
726
+ exact (mul_lt_mul_left hp.2).mpr h₁₅
727
+ have h₁₃: 2 < x / y + y / x := by
728
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.1)
729
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.2)
730
+ repeat rw [add_mul, mul_assoc]
731
+ rw [mul_comm x y, ← mul_assoc (x/y)]
732
+ rw [div_mul_comm x y y, div_mul_comm y x x, div_self, div_self]
733
+ . ring_nf
734
+ refine lt_of_sub_pos ?_
735
+ rw [mul_comm _ 2, ← mul_assoc]
736
+ rw [← sub_sq']
737
+ refine sq_pos_of_ne_zero ?_
738
+ exact sub_ne_zero.mpr hc.symm
739
+ . exact ne_of_gt hp.1
740
+ . exact ne_of_gt hp.2
741
+ linarith
742
+
743
+
744
+ lemma imo_2022_p2_1_1
745
+ (f : ℝ → ℝ)
746
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
747
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
748
+ (x y : ℝ)
749
+ (hp : 0 < x ∧ 0 < y)
750
+ (h₁ : x * f y + y * f x ≤ 2)
751
+ (hc : x ≠ y) :
752
+ x * f x + x * f x > 2 := by
753
+ let ⟨z,h₁₁⟩ := h₀ x hp.1
754
+ cases' h₁₁ with h₁₁ h₁₂
755
+ have h₁₄: y = z := by
756
+ apply h₁₂ y
757
+ constructor
758
+ . exact hp.2
759
+ . exact h₁
760
+ have hxz: ¬ x = z := by exact Ne.trans_eq hc h₁₄
761
+ have h₁₆: ¬ (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x := by
762
+ exact mt (h₁₂ x) hxz
763
+ have h₁₇: ¬ (0 < x ∧ x * f x + x * f x ≤ 2) := by exact h₁₆
764
+ push_neg at h₁₇
765
+ exact h₁₇ hp.1
766
+
767
+
768
+ lemma imo_2022_p2_1_2
769
+ (f : ℝ → ℝ)
770
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
771
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
772
+ (x y : ℝ)
773
+ (hp : 0 < x ∧ 0 < y)
774
+ (h₁ : x * f y + y * f x ≤ 2)
775
+ (hc : x ≠ y)
776
+ (z : ℝ)
777
+ -- (h₁₁ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) z)
778
+ (h₁₂ : ∀ (y : ℝ), (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y → y = z) :
779
+ x * f x + x * f x > 2 := by
780
+ have h₁₄: y = z := by
781
+ apply h₁₂ y
782
+ constructor
783
+ . exact hp.2
784
+ . exact h₁
785
+ have hxz: ¬ x = z := by exact Ne.trans_eq hc h₁₄
786
+ have h₁₆: ¬ (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x := by
787
+ exact mt (h₁₂ x) hxz
788
+ have h₁₇: ¬ (0 < x ∧ x * f x + x * f x ≤ 2) := by exact h₁₆
789
+ push_neg at h₁₇
790
+ exact h₁₇ hp.1
791
+
792
+
793
+ lemma imo_2022_p2_1_3
794
+ (f : ℝ → ℝ)
795
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
796
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
797
+ (x y : ℝ)
798
+ (hp : 0 < x ∧ 0 < y)
799
+ (h₁ : x * f y + y * f x ≤ 2)
800
+ -- (hc : x ≠ y)
801
+ (z : ℝ)
802
+ -- (h₁₁ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) z)
803
+ (h₁₂ : ∀ (y : ℝ), (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y → y = z) :
804
+ y = z := by
805
+ apply h₁₂ y
806
+ constructor
807
+ . exact hp.2
808
+ . exact h₁
809
+
810
+
811
+ lemma imo_2022_p2_1_4
812
+ (f : ℝ → ℝ)
813
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
814
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
815
+ (x z : ℝ)
816
+ -- (y : ℝ)
817
+ -- (hp : 0 < x ∧ 0 < y)
818
+ -- (h₁ : x * f y + y * f x ≤ 2)
819
+ -- (hc : x ≠ y)
820
+ -- (h₁₁ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) z)
821
+ (h₁₂ : ∀ (y : ℝ), (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y → y = z)
822
+ -- (h₁₄ : y = z)
823
+ (hxz : ¬x = z) :
824
+ ¬(fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x := by
825
+ exact mt (h₁₂ x) hxz
826
+
827
+
828
+ lemma imo_2022_p2_1_5
829
+ (f : ℝ → ℝ)
830
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
831
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
832
+ (x y : ℝ)
833
+ (hp : 0 < x ∧ 0 < y)
834
+ -- (h₁ : x * f y + y * f x ≤ 2)
835
+ -- (hc : x ≠ y)
836
+ -- (z : ℝ)
837
+ -- (h₁₁ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) z)
838
+ -- (h₁₂ : ∀ (y : ℝ), (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y → y = z)
839
+ -- (h₁₄ : y = z)
840
+ -- (hxz : ¬x = z)
841
+ -- (h₁₆ : ¬(fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x)
842
+ (h₁₇ : ¬(0 < x ∧ x * f x + x * f x ≤ 2)) :
843
+ x * f x + x * f x > 2 := by
844
+ push_neg at h₁₇
845
+ refine h₁₇ ?_
846
+ exact hp.1
847
+
848
+
849
+ lemma imo_2022_p2_1_6
850
+ (f : ℝ → ℝ)
851
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
852
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
853
+ (x y : ℝ)
854
+ (hp : 0 < x ∧ 0 < y)
855
+ -- (h₁ : x * f y + y * f x ≤ 2)
856
+ -- (hc : x ≠ y)
857
+ -- (z : ℝ)
858
+ -- (h₁₁ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) z)
859
+ -- (h₁₂ : ∀ (y : ℝ), (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y → y = z)
860
+ -- (h₁₄ : y = z)
861
+ -- (hxz : ¬x = z)
862
+ -- (h₁₆ : ¬(fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x)
863
+ (h₁₇ : 0 < x → 2 < x * f x + x * f x) :
864
+ x * f x + x * f x > 2 := by
865
+ refine h₁₇ ?_
866
+ exact hp.1
867
+
868
+
869
+ lemma imo_2022_p2_1_7
870
+ (f : ℝ → ℝ)
871
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
872
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
873
+ (x y : ℝ)
874
+ (hp : 0 < x ∧ 0 < y)
875
+ (h₁ : x * f y + y * f x ≤ 2)
876
+ (hc : x ≠ y)
877
+ (h₁₀ : 1 < x * f x)
878
+ (h₁₁ : 1 < y * f y) :
879
+ False := by
880
+ have h₁₅: 1 / x < f x := by exact (div_lt_iff₀' hp.1).mpr (h₁₀)
881
+ have h₁₆: 1 / y < f y := by exact (div_lt_iff₀' hp.2).mpr (h₁₁)
882
+ have h₁₂: x / y + y / x < 2 := by
883
+ refine lt_of_le_of_lt' h₁ ?_
884
+ refine add_lt_add ?_ ?_
885
+ . rw [← mul_one_div]
886
+ exact (mul_lt_mul_left hp.1).mpr h₁₆
887
+ . rw [← mul_one_div]
888
+ exact (mul_lt_mul_left hp.2).mpr h₁₅
889
+ have h₁₃: 2 < x / y + y / x := by
890
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.1)
891
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.2)
892
+ repeat rw [add_mul, mul_assoc]
893
+ -- rw [div_mul_mul_cancel x x y]
894
+ rw [mul_comm x y, ← mul_assoc (x/y)]
895
+ -- rw [mul_comm (x / y * y) x]
896
+ rw [div_mul_comm x y y, div_mul_comm y x x, div_self, div_self]
897
+ . ring_nf
898
+ refine lt_of_sub_pos ?_
899
+ rw [mul_comm _ 2, ← mul_assoc]
900
+ rw [← sub_sq']
901
+ refine sq_pos_of_ne_zero ?_
902
+ exact sub_ne_zero.mpr hc.symm
903
+ . exact ne_of_gt hp.1
904
+ . exact ne_of_gt hp.2
905
+ linarith
906
+
907
+
908
+ lemma imo_2022_p2_1_8
909
+ (f : ℝ → ℝ)
910
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
911
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
912
+ (x y : ℝ)
913
+ (hp : 0 < x ∧ 0 < y)
914
+ (h₁ : x * f y + y * f x ≤ 2)
915
+ -- (hc : x ≠ y)
916
+ -- (h₁₀ : 1 < x * f x)
917
+ -- (h₁₁ : 1 < y * f y)
918
+ (h₁₅ : 1 / x < f x)
919
+ (h₁₆ : 1 / y < f y) :
920
+ x / y + y / x < 2 := by
921
+ refine lt_of_le_of_lt' h₁ ?_
922
+ refine add_lt_add ?_ ?_
923
+ . rw [← mul_one_div]
924
+ exact (mul_lt_mul_left hp.1).mpr h₁₆
925
+ . rw [← mul_one_div]
926
+ exact (mul_lt_mul_left hp.2).mpr h₁₅
927
+
928
+
929
+ lemma imo_2022_p2_1_9
930
+ (f : ℝ → ℝ)
931
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
932
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
933
+ (x y : ℝ)
934
+ (hp : 0 < x ∧ 0 < y)
935
+ -- (h₁ : x * f y + y * f x ≤ 2)
936
+ -- (hc : x ≠ y)
937
+ -- (h₁₀ : 1 < x * f x)
938
+ -- (h₁₁ : 1 < y * f y)
939
+ -- (h₁₅ : 1 / x < f x)
940
+ (h₁₆ : 1 / y < f y) :
941
+ x / y < x * f y := by
942
+ rw [← mul_one_div]
943
+ exact (mul_lt_mul_left hp.1).mpr h₁₆
944
+
945
+
946
+ lemma imo_2022_p2_1_10
947
+ -- (f : ℝ → ℝ)
948
+ -- hfp : ∀ (x : ℝ), 0 < x → 0 < f x
949
+ -- h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2
950
+ (x y : ℝ)
951
+ (hp : 0 < x ∧ 0 < y)
952
+ -- h₁ : x * f y + y * f x ≤ 2
953
+ (hc : x ≠ y) :
954
+ -- h₁₀ : 1 < x * f x
955
+ -- h₁₁ : 1 < y * f y
956
+ -- h₁₅ : 1 / x < f x
957
+ -- h₁₆ : 1 / y < f y
958
+ -- (h₁₂ : x / y + y / x < 2) :
959
+ 2 < x / y + y / x := by
960
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.1)
961
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.2)
962
+ repeat rw [add_mul, mul_assoc]
963
+ -- rw [div_mul_mul_cancel x x y]
964
+ rw [mul_comm x y, ← mul_assoc (x/y)]
965
+ -- rw [mul_comm (x / y * y) x]
966
+ rw [div_mul_comm x y y, div_mul_comm y x x, div_self, div_self]
967
+ . ring_nf
968
+ refine lt_of_sub_pos ?_
969
+ rw [mul_comm _ 2, ← mul_assoc]
970
+ rw [← sub_sq']
971
+ refine sq_pos_of_ne_zero ?_
972
+ exact sub_ne_zero.mpr hc.symm
973
+ . exact ne_of_gt hp.1
974
+ . exact ne_of_gt hp.2
975
+
976
+
977
+ lemma imo_2022_p2_1_11
978
+ -- (f : ℝ → ℝ)
979
+ (x y : ℝ)
980
+ (hp : 0 < x ∧ 0 < y)
981
+ (hc : x ≠ y) :
982
+ 2 * x * y < (x / y + y / x) * x * y := by
983
+ repeat rw [add_mul, mul_assoc]
984
+ -- rw [div_mul_mul_cancel x x y]
985
+ rw [mul_comm x y, ← mul_assoc (x/y)]
986
+ -- rw [mul_comm (x / y * y) x]
987
+ rw [div_mul_comm x y y, div_mul_comm y x x, div_self, div_self]
988
+ . ring_nf
989
+ refine lt_of_sub_pos ?_
990
+ rw [mul_comm _ 2, ← mul_assoc]
991
+ rw [← sub_sq']
992
+ refine sq_pos_of_ne_zero ?_
993
+ exact sub_ne_zero.mpr hc.symm
994
+ . exact ne_of_gt hp.1
995
+ . exact ne_of_gt hp.2
996
+
997
+
998
+ lemma imo_2022_p2_1_12
999
+ -- (f : ℝ → ℝ)
1000
+ (x y : ℝ)
1001
+ -- (hp : 0 < x ∧ 0 < y)
1002
+ (hc : x ≠ y) :
1003
+ y * x * 2 < y ^ 2 + x ^ 2 := by
1004
+ refine lt_of_sub_pos ?_
1005
+ rw [mul_comm _ 2, ← mul_assoc]
1006
+ rw [← sub_sq']
1007
+ refine sq_pos_of_ne_zero ?_
1008
+ exact sub_ne_zero.mpr hc.symm
1009
+
1010
+
1011
+
1012
+ lemma imo_2022_p2_2
1013
+ (f : ℝ → ℝ)
1014
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1015
+ (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1016
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y) :
1017
+ ∀ (x : ℝ), 0 < x → x * f x ≤ 1 := by
1018
+ intros x hxp
1019
+ obtain ⟨y,h₂₁⟩ := h₀ x hxp
1020
+ cases' h₂₁ with h₂₁ h₂₂
1021
+ have hxy: x = y := by
1022
+ have h₂₃: 0 < y ∧ x * f y + y * f x ≤ 2 := by exact h₂₁
1023
+ apply h₁ x y
1024
+ . constructor
1025
+ . exact hxp
1026
+ . exact h₂₃.1
1027
+ . exact h₂₃.2
1028
+ rw [← hxy] at h₂₁
1029
+ linarith
1030
+
1031
+
1032
+ lemma imo_2022_p2_2_1
1033
+ (f : ℝ → ℝ)
1034
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1035
+ (x : ℝ)
1036
+ (hxp : 0 < x)
1037
+ (y : ℝ)
1038
+ (h₂ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y) :
1039
+ x * f x ≤ 1 := by
1040
+ have hxy: x = y := by
1041
+ apply h₁ x y
1042
+ . constructor
1043
+ . exact hxp
1044
+ . exact h₂.1
1045
+ . exact h₂.2
1046
+ rw [← hxy] at h₂
1047
+ linarith
1048
+
1049
+
1050
+ lemma imo_2022_p2_2_2
1051
+ (f : ℝ → ℝ)
1052
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1053
+ (x : ℝ)
1054
+ (hxp : 0 < x)
1055
+ (y : ℝ)
1056
+ (h₂ : (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) y) :
1057
+ x = y := by
1058
+ apply h₁ x y
1059
+ . constructor
1060
+ . exact hxp
1061
+ . exact h₂.1
1062
+ . exact h₂.2
1063
+
1064
+
1065
+ lemma imo_2022_p2_2_3
1066
+ (f : ℝ → ℝ)
1067
+ -- h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y
1068
+ (x y : ℝ)
1069
+ -- (hxp : 0 < x)
1070
+ (h₂ : 0 < y ∧ x * f y + y * f x ≤ 2)
1071
+ (hxy : x = y) :
1072
+ x * f x ≤ 1 := by
1073
+ rw [← hxy] at h₂
1074
+ linarith
1075
+
1076
+
1077
+
1078
+ lemma imo_2022_p2_3
1079
+ (f : ℝ → ℝ)
1080
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1081
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1082
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1083
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1) :
1084
+ ∀ (x : ℝ), 0 < x → ¬x * f x < 1 := by
1085
+ by_contra! hc
1086
+ let ⟨x,hxp⟩ := hc
1087
+ cases' hxp with hxp h₃
1088
+ let d₁:ℝ := 1 - x * f x
1089
+ have hd₁ : x * f x = 1 - d₁ := by exact (sub_sub_self 1 (x * f x)).symm
1090
+ let z:ℝ := x + d₁ / f x
1091
+ have hz: z = x + d₁ / f x := by exact rfl
1092
+ have hzp: 0 < z := by
1093
+ refine add_pos hxp ?_
1094
+ refine div_pos ?_ ?_
1095
+ . exact sub_pos.mpr h₃
1096
+ . exact hfp x hxp
1097
+ have hxz: ¬ x = z := by
1098
+ by_contra! hcz₀
1099
+ rw [← hcz₀] at hz
1100
+ have hcz₁: 0 < d₁ / f x := by
1101
+ refine div_pos ?_ (hfp x hxp)
1102
+ exact sub_pos.mpr h₃
1103
+ linarith
1104
+ have h₄: ¬ (x * f z + z * f x ≤ 2) := by
1105
+ have h₄₁: x * f z + z * f x ≤ 2 → x = z := by
1106
+ exact h₁ x z { left := hxp, right := hzp }
1107
+ exact mt h₄₁ hxz
1108
+ have h₅: x * f z < 1 := by
1109
+ suffices h₅₁: z * f z ≤ 1 by
1110
+ refine lt_of_lt_of_le ?_ h₅₁
1111
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1112
+ rw [hz]
1113
+ refine lt_add_of_pos_right x ?_
1114
+ refine div_pos ?_ (hfp x hxp)
1115
+ exact sub_pos.mpr h₃
1116
+ exact h₂ z hzp
1117
+ have h₆: x * f z + z * f x < 2 := by
1118
+ suffices h₇: z * f x ≤ 1 by
1119
+ linarith
1120
+ rw [hz, add_mul, hd₁]
1121
+ rw [div_mul_comm d₁ (f x) (f x)]
1122
+ rw [div_self]
1123
+ . rw [one_mul, sub_add_cancel]
1124
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1125
+ linarith
1126
+
1127
+
1128
+ lemma imo_2022_p2_3_1
1129
+ (f : ℝ → ℝ)
1130
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1131
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1132
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1133
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1134
+ (hc : ∃ x, 0 < x ∧ x * f x < 1) :
1135
+ -- (x : ℝ)
1136
+ -- (hxp : 0 < x)
1137
+ -- (h₃ : x * f x < 1) :
1138
+ False := by
1139
+ let ⟨x,hxp⟩ := hc
1140
+ cases' hxp with hxp h₃
1141
+ let d₁:ℝ := 1 - x * f x
1142
+ have hd₁ : x * f x = 1 - d₁ := by exact (sub_sub_self 1 (x * f x)).symm
1143
+ let z:ℝ := x + d₁ / f x
1144
+ have hz: z = x + d₁ / f x := by exact rfl
1145
+ have hzp: 0 < z := by
1146
+ refine add_pos hxp ?_
1147
+ refine div_pos ?_ ?_
1148
+ . exact sub_pos.mpr h₃
1149
+ . exact hfp x hxp
1150
+ have hxz: ¬ x = z := by
1151
+ by_contra! hcz₀
1152
+ rw [← hcz₀] at hz
1153
+ have hcz₁: 0 < d₁ / f x := by
1154
+ refine div_pos ?_ (hfp x hxp)
1155
+ exact sub_pos.mpr h₃
1156
+ linarith
1157
+ have h₄: ¬ (x * f z + z * f x ≤ 2) := by
1158
+ have h₄₁: x * f z + z * f x ≤ 2 → x = z := by
1159
+ exact h₁ x z { left := hxp, right := hzp }
1160
+ exact mt h₄₁ hxz
1161
+ have h₅: x * f z < 1 := by
1162
+ suffices h₅₁: z * f z ≤ 1 by
1163
+ refine lt_of_lt_of_le ?_ h₅₁
1164
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1165
+ rw [hz]
1166
+ refine lt_add_of_pos_right x ?_
1167
+ refine div_pos ?_ (hfp x hxp)
1168
+ exact sub_pos.mpr h₃
1169
+ exact h₂ z hzp
1170
+ have h₆: x * f z + z * f x < 2 := by
1171
+ suffices h₇: z * f x ≤ 1 by
1172
+ linarith
1173
+ rw [hz, add_mul, hd₁]
1174
+ rw [div_mul_comm d₁ (f x) (f x)]
1175
+ rw [div_self]
1176
+ . rw [one_mul, sub_add_cancel]
1177
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1178
+ linarith
1179
+
1180
+
1181
+ lemma imo_2022_p2_3_2
1182
+ (f : ℝ → ℝ)
1183
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1184
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1185
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1186
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1187
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1188
+ (x z d₁: ℝ)
1189
+ (hxp : 0 < x)
1190
+ (h₃ : x * f x < 1)
1191
+ (hd₀ : d₁ = 1 - x * f x)
1192
+ (hd₁ : x * f x = 1 - d₁)
1193
+ (hz : z = x + d₁ / f x) :
1194
+ False := by
1195
+ have hzp: 0 < z := by
1196
+ rw [hz]
1197
+ refine add_pos hxp ?_
1198
+ refine div_pos ?_ ?_
1199
+ . rw [hd₀]
1200
+ exact sub_pos.mpr h₃
1201
+ . exact hfp x hxp
1202
+ have hxz: ¬ x = z := by
1203
+ by_contra! hcz₀
1204
+ rw [← hcz₀] at hz
1205
+ have hcz₁: 0 < d₁ / f x := by
1206
+ refine div_pos ?_ (hfp x hxp)
1207
+ rw [hd₀]
1208
+ exact sub_pos.mpr h₃
1209
+ linarith
1210
+ have h₄: ¬ (x * f z + z * f x ≤ 2) := by
1211
+ have h₄₁: x * f z + z * f x ≤ 2 → x = z := by
1212
+ exact h₁ x z { left := hxp, right := hzp }
1213
+ exact mt h₄₁ hxz
1214
+ have h₅: x * f z < 1 := by
1215
+ suffices h₅₁: z * f z ≤ 1 by
1216
+ refine lt_of_lt_of_le ?_ h₅₁
1217
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1218
+ rw [hz]
1219
+ refine lt_add_of_pos_right x ?_
1220
+ refine div_pos ?_ (hfp x hxp)
1221
+ rw [hd₀]
1222
+ exact sub_pos.mpr h₃
1223
+ exact h₂ z hzp
1224
+ have h₆: x * f z + z * f x < 2 := by
1225
+ suffices h₇: z * f x ≤ 1 by
1226
+ linarith
1227
+ rw [hz, add_mul, hd₁]
1228
+ rw [div_mul_comm d₁ (f x) (f x)]
1229
+ rw [div_self]
1230
+ . rw [one_mul, sub_add_cancel]
1231
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1232
+ linarith
1233
+
1234
+
1235
+ lemma imo_2022_p2_3_3
1236
+ (f : ℝ → ℝ)
1237
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1238
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1239
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1240
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1241
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1242
+ (x d₁ z : ℝ)
1243
+ (hxp : 0 < x)
1244
+ (h₃ : x * f x < 1)
1245
+ (hd₀ : d₁ = 1 - x * f x)
1246
+ -- (hd₁ : x * f x = 1 - d₁)
1247
+ (hz : z = x + d₁ / f x) :
1248
+ 0 < z := by
1249
+ rw [hz]
1250
+ refine add_pos hxp ?_
1251
+ refine div_pos ?_ ?_
1252
+ . rw [hd₀]
1253
+ exact sub_pos.mpr h₃
1254
+ . exact hfp x hxp
1255
+
1256
+
1257
+ lemma imo_2022_p2_3_4
1258
+ (f : ℝ → ℝ)
1259
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1260
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1261
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1262
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1263
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1264
+ (x d₁ : ℝ)
1265
+ (hxp : 0 < x)
1266
+ (h₃ : x * f x < 1)
1267
+ (hd₀ : d₁ = 1 - x * f x) :
1268
+ -- (hd₁ : x * f x = 1 - d₁)
1269
+ -- (hz : z = x + d₁ / f x) :
1270
+ 0 < d₁ / f x := by
1271
+ refine div_pos ?_ ?_
1272
+ . rw [hd₀]
1273
+ exact sub_pos.mpr h₃
1274
+ . exact hfp x hxp
1275
+
1276
+
1277
+ lemma imo_2022_p2_3_5
1278
+ (f : ℝ → ℝ)
1279
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1280
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1281
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1282
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1283
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1284
+ (x d₁ z: ℝ)
1285
+ (hxp : 0 < x)
1286
+ (h₃ : x * f x < 1)
1287
+ (hd₀ : d₁ = 1 - x * f x)
1288
+ -- (hd₁ : x * f x = 1 - d₁)
1289
+ (hz : z = x + d₁ / f x)
1290
+ (hzp : 0 < z) :
1291
+ ¬x = z := by
1292
+ by_contra! hcz₀
1293
+ rw [← hcz₀] at hz
1294
+ have hcz₁: 0 < d₁ / f x := by
1295
+ refine div_pos ?_ (hfp x hxp)
1296
+ rw [hd₀]
1297
+ exact sub_pos.mpr h₃
1298
+ linarith
1299
+
1300
+
1301
+ lemma imo_2022_p2_3_6
1302
+ (f : ℝ → ℝ)
1303
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1304
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1305
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1306
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1307
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1308
+ (x d₁ : ℝ)
1309
+ (hxp : 0 < x)
1310
+ (h₃ : x * f x < 1)
1311
+ (hd₀ : d₁ = 1 - x * f x)
1312
+ -- (hd₁ : x * f x = 1 - d₁)
1313
+ (hz : x = x + d₁ / f x) :
1314
+ -- (hzp : 0 < z)
1315
+ -- (hcz₀ : x = z) :
1316
+ False := by
1317
+ have hcz₁: 0 < d₁ / f x := by
1318
+ refine div_pos ?_ (hfp x hxp)
1319
+ rw [hd₀]
1320
+ exact sub_pos.mpr h₃
1321
+ linarith
1322
+
1323
+
1324
+ lemma imo_2022_p2_3_7
1325
+ (f : ℝ → ℝ)
1326
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1327
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1328
+ (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1329
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1330
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1331
+ (x z d₁ : ℝ)
1332
+ (hxp : 0 < x)
1333
+ (h₃ : x * f x < 1)
1334
+ (hd₀ : d₁ = 1 - x * f x)
1335
+ (hd₁ : x * f x = 1 - d₁)
1336
+ (hz : z = x + d₁ / f x)
1337
+ (hzp : 0 < z)
1338
+ (hxz : ¬x = z) :
1339
+ ¬x * f z + z * f x ≤ 2 := by
1340
+ have h₄: ¬ (x * f z + z * f x ≤ 2) := by
1341
+ have h₄₁: x * f z + z * f x ≤ 2 → x = z := by
1342
+ exact h₁ x z { left := hxp, right := hzp }
1343
+ exact mt h₄₁ hxz
1344
+ have h₅: x * f z < 1 := by
1345
+ suffices h₅₁: z * f z ≤ 1 by
1346
+ refine lt_of_lt_of_le ?_ h₅₁
1347
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1348
+ rw [hz]
1349
+ refine lt_add_of_pos_right x ?_
1350
+ refine div_pos ?_ (hfp x hxp)
1351
+ rw [hd₀]
1352
+ exact sub_pos.mpr h₃
1353
+ exact h₂ z hzp
1354
+ have h₆: x * f z + z * f x < 2 := by
1355
+ suffices h₇: z * f x ≤ 1 by
1356
+ linarith
1357
+ rw [hz, add_mul, hd₁]
1358
+ rw [div_mul_comm d₁ (f x) (f x)]
1359
+ rw [div_self]
1360
+ . rw [one_mul, sub_add_cancel]
1361
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1362
+ linarith
1363
+
1364
+
1365
+ lemma imo_2022_p2_3_8
1366
+ (f : ℝ → ℝ)
1367
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1368
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1369
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1370
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1371
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1372
+ (x z d₁ : ℝ)
1373
+ (hxp : 0 < x)
1374
+ (h₃ : x * f x < 1)
1375
+ (hd₀ : d₁ = 1 - x * f x)
1376
+ (hd₁ : x * f x = 1 - d₁)
1377
+ (hz : z = x + d₁ / f x)
1378
+ (hzp : 0 < z)
1379
+ -- (hxz : ¬x = z)
1380
+ (h₄ : ¬x * f z + z * f x ≤ 2) :
1381
+ x * f z < 1 := by
1382
+ have h₅: x * f z < 1 := by
1383
+ suffices h₅₁: z * f z ≤ 1 by
1384
+ refine lt_of_lt_of_le ?_ h₅₁
1385
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1386
+ rw [hz]
1387
+ refine lt_add_of_pos_right x ?_
1388
+ refine div_pos ?_ (hfp x hxp)
1389
+ rw [hd₀]
1390
+ exact sub_pos.mpr h₃
1391
+ exact h₂ z hzp
1392
+ have h₆: x * f z + z * f x < 2 := by
1393
+ suffices h₇: z * f x ≤ 1 by
1394
+ linarith
1395
+ rw [hz, add_mul, hd₁]
1396
+ rw [div_mul_comm d₁ (f x) (f x)]
1397
+ rw [div_self]
1398
+ . rw [one_mul, sub_add_cancel]
1399
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1400
+ linarith
1401
+
1402
+
1403
+ lemma imo_2022_p2_3_9
1404
+ (f : ℝ → ℝ)
1405
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1406
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1407
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1408
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1409
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1410
+ (x z d₁ : ℝ)
1411
+ (hxp : 0 < x)
1412
+ (h₃ : x * f x < 1)
1413
+ (hd₀ : d₁ = 1 - x * f x)
1414
+ -- (hd₁ : x * f x = 1 - d₁)
1415
+ (hz : z = x + d₁ / f x)
1416
+ (hzp : 0 < z)
1417
+ -- (hxz : ¬x = z)
1418
+ -- (h₄ : ¬x * f z + z * f x ≤ 2)
1419
+ (h₅₁ : z * f z ≤ 1) :
1420
+ x * f z < 1 := by
1421
+ refine lt_of_lt_of_le ?_ h₅₁
1422
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
1423
+ rw [hz]
1424
+ refine lt_add_of_pos_right x ?_
1425
+ refine div_pos ?_ (hfp x hxp)
1426
+ rw [hd₀]
1427
+ exact sub_pos.mpr h₃
1428
+
1429
+
1430
+ lemma imo_2022_p2_3_10
1431
+ (f : ℝ → ℝ)
1432
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1433
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1434
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1435
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1436
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1437
+ (x z d₁ : ℝ)
1438
+ (hxp : 0 < x)
1439
+ -- (h₃ : x * f x < 1)
1440
+ -- (hd₀ : d₁ = 1 - x * f x)
1441
+ (hd₁ : x * f x = 1 - d₁)
1442
+ (hz : z = x + d₁ / f x)
1443
+ -- (hzp : 0 < z)
1444
+ -- (hxz : ¬x = z)
1445
+ (h₄ : ¬x * f z + z * f x ≤ 2)
1446
+ (h₅ : x * f z < 1) :
1447
+ x * f z + z * f x < 2 := by
1448
+ have h₆: x * f z + z * f x < 2 := by
1449
+ suffices h₇: z * f x ≤ 1 by
1450
+ linarith
1451
+ rw [hz, add_mul, hd₁]
1452
+ rw [div_mul_comm d₁ (f x) (f x)]
1453
+ rw [div_self]
1454
+ . rw [one_mul, sub_add_cancel]
1455
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1456
+ linarith
1457
+
1458
+
1459
+ lemma imo_2022_p2_3_11
1460
+ (f : ℝ → ℝ)
1461
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1462
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1463
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1464
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1465
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1466
+ (x z d₁ : ℝ)
1467
+ (hxp : 0 < x)
1468
+ -- (h₃ : x * f x < 1)
1469
+ -- (hd₀ : d₁ = 1 - x * f x)
1470
+ (hd₁ : x * f x = 1 - d₁)
1471
+ (hz : z = x + d₁ / f x)
1472
+ -- (hzp : 0 < z)
1473
+ -- (hxz : ¬x = z)
1474
+ (h₄ : ¬x * f z + z * f x ≤ 2)
1475
+ (h₅ : x * f z < 1) :
1476
+ z * f x ≤ 1 := by
1477
+ suffices h₇: z * f x ≤ 1 by
1478
+ linarith
1479
+ rw [hz, add_mul, hd₁]
1480
+ rw [div_mul_comm d₁ (f x) (f x)]
1481
+ rw [div_self]
1482
+ . rw [one_mul, sub_add_cancel]
1483
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1484
+
1485
+
1486
+ lemma imo_2022_p2_3_12
1487
+ (f : ℝ → ℝ)
1488
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1489
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1490
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1491
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1492
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1493
+ (x d₁ : ℝ)
1494
+ (hxp : 0 < x) :
1495
+ -- (h₃ : x * f x < 1)
1496
+ -- (hd₀ : d₁ = 1 - x * f x)
1497
+ -- (hd₁ : x * f x = 1 - d₁)
1498
+ -- (hz : z = x + d₁ / f x)
1499
+ -- (hzp : 0 < z)
1500
+ -- (hxz : ¬x = z)
1501
+ -- (h₄ : ¬x * f z + z * f x ≤ 2)
1502
+ -- (h₅ : x * f z < 1) :
1503
+ 1 - d₁ + d₁ / f x * f x ≤ 1 := by
1504
+ rw [div_mul_comm d₁ (f x) (f x)]
1505
+ rw [div_self]
1506
+ . rw [one_mul, sub_add_cancel]
1507
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1508
+
1509
+
1510
+ lemma imo_2022_p2_3_13
1511
+ (f : ℝ → ℝ)
1512
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1513
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1514
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1515
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1516
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1517
+ (x d₁ : ℝ)
1518
+ (hxp : 0 < x) :
1519
+ -- (h₃ : x * f x < 1) :
1520
+ -- (hd₀ : d₁ = 1 - x * f x)
1521
+ -- (hd₁ : x * f x = 1 - d₁)
1522
+ -- (hz : z = x + d₁ / f x)
1523
+ -- (hzp : 0 < z)
1524
+ -- (hxz : ¬x = z)
1525
+ -- (h₄ : ¬x * f z + z * f x ≤ 2)
1526
+ -- (h₅ : x * f z < 1) :
1527
+ 1 - d₁ + f x / f x * d₁ ≤ 1 := by
1528
+ rw [div_self]
1529
+ . rw [one_mul, sub_add_cancel]
1530
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
1531
+
1532
+
1533
+ lemma imo_2022_p2_3_14
1534
+ -- (f : ℝ → ℝ)
1535
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1536
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1537
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1538
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1539
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1540
+ (d₁ : ℝ) :
1541
+ -- (hxp : 0 < x)
1542
+ -- (h₃ : x * f x < 1)
1543
+ -- (hd₀ : d₁ = 1 - x * f x)
1544
+ -- (hd₁ : x * f x = 1 - d₁)
1545
+ -- (hz : z = x + d₁ / f x)
1546
+ -- (hzp : 0 < z)
1547
+ -- (hxz : ¬x = z)
1548
+ -- (h₄ : ¬x * f z + z * f x ≤ 2)
1549
+ -- (h₅ : x * f z < 1) :
1550
+ 1 - d₁ + 1 * d₁ ≤ 1 := by
1551
+ rw [one_mul]
1552
+ refine le_of_eq ?_
1553
+ exact sub_add_cancel 1 d₁
1554
+
1555
+
1556
+ lemma imo_2022_p2_3_15
1557
+ (f : ℝ → ℝ)
1558
+ (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1559
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1560
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1561
+ -- (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1562
+ -- (hc : ∃ x, 0 < x ∧ x * f x < 1)
1563
+ (x : ℝ)
1564
+ (hxp : 0 < x) :
1565
+ -- (h₃ : x * f x < 1)
1566
+ -- (hd₀ : d₁ = 1 - x * f x)
1567
+ -- (hd₁ : x * f x = 1 - d₁)
1568
+ -- (hz : z = x + d₁ / f x)
1569
+ -- (hzp : 0 < z)
1570
+ -- (hxz : ¬x = z)
1571
+ -- (h₄ : ¬x * f z + z * f x ≤ 2)
1572
+ -- (h₅ : x * f z < 1) :
1573
+ f x ≠ 0 := by
1574
+ refine PartialHomeomorph.unitBallBall.proof_2 (f x) ?_
1575
+ exact (hfp x hxp)
1576
+
1577
+
1578
+ lemma imo_2022_p2_4
1579
+ (f : ℝ → ℝ)
1580
+ -- (hfp : ∀ (x : ℝ), 0 < x → 0 < f x)
1581
+ -- (h₀ : ∀ (x : ℝ), 0 < x → ∃! y, 0 < y ∧ x * f y + y * f x ≤ 2)
1582
+ -- (h₁ : ∀ (x y : ℝ), 0 < x ∧ 0 < y → x * f y + y * f x ≤ 2 → x = y)
1583
+ (h₂ : ∀ (x : ℝ), 0 < x → x * f x ≤ 1)
1584
+ (h₃ : ∀ (x : ℝ), 0 < x → ¬x * f x < 1) :
1585
+ ∀ (x : ℝ), 0 < x → f x = 1 / x := by
1586
+ intros x hxp
1587
+ have h₄: x * f x ≤ 1 := by exact h₂ x hxp
1588
+ have h₅: ¬ x * f x < 1 := by exact h₃ x hxp
1589
+ refine eq_div_of_mul_eq ?_ ?_
1590
+ . exact ne_of_gt hxp
1591
+ . push_neg at h₅
1592
+ linarith
1593
+
1594
+
1595
+ lemma imo_2022_p2_4_1
1596
+ (f : ℝ → ℝ)
1597
+ (x : ℝ)
1598
+ (hxp : 0 < x)
1599
+ (h₄ : x * f x ≤ 1)
1600
+ (h₅ : ¬x * f x < 1) :
1601
+ f x = 1 / x := by
1602
+ refine eq_div_of_mul_eq ?_ ?_
1603
+ . exact ne_of_gt hxp
1604
+ . push_neg at h₅
1605
+ rw [mul_comm]
1606
+ exact le_antisymm h₄ h₅
Lemmas/imo_2022_p5_lemmas.lean ADDED
The diff for this file is too large to render. See raw diff
 
Lemmas/imo_2023_p4_lemmas.lean ADDED
The diff for this file is too large to render. See raw diff
 
Lemmas/lake-manifest.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"version": "1.1.0",
2
+ "packagesDir": ".lake/packages",
3
+ "packages":
4
+ [{"url": "https://github.com/leanprover-community/mathlib4",
5
+ "type": "git",
6
+ "subDir": null,
7
+ "scope": "leanprover-community",
8
+ "rev": "d066138f11f7fdf68dcda20d1ed2d296e9d992d7",
9
+ "name": "mathlib",
10
+ "manifestFile": "lake-manifest.json",
11
+ "inputRev": "master",
12
+ "inherited": false,
13
+ "configFile": "lakefile.lean"},
14
+ {"url": "https://github.com/leanprover-community/plausible",
15
+ "type": "git",
16
+ "subDir": null,
17
+ "scope": "leanprover-community",
18
+ "rev": "59a8514bb0ee5bae2689d8be717b5272c9b3dc1c",
19
+ "name": "plausible",
20
+ "manifestFile": "lake-manifest.json",
21
+ "inputRev": "main",
22
+ "inherited": true,
23
+ "configFile": "lakefile.toml"},
24
+ {"url": "https://github.com/leanprover-community/LeanSearchClient",
25
+ "type": "git",
26
+ "subDir": null,
27
+ "scope": "leanprover-community",
28
+ "rev": "0c169a0d55fef3763cfb3099eafd7b884ec7e41d",
29
+ "name": "LeanSearchClient",
30
+ "manifestFile": "lake-manifest.json",
31
+ "inputRev": "main",
32
+ "inherited": true,
33
+ "configFile": "lakefile.toml"},
34
+ {"url": "https://github.com/leanprover-community/import-graph",
35
+ "type": "git",
36
+ "subDir": null,
37
+ "scope": "leanprover-community",
38
+ "rev": "461b96f5527089718cb23d3f1fd2960a5d0ff516",
39
+ "name": "importGraph",
40
+ "manifestFile": "lake-manifest.json",
41
+ "inputRev": "main",
42
+ "inherited": true,
43
+ "configFile": "lakefile.toml"},
44
+ {"url": "https://github.com/leanprover-community/ProofWidgets4",
45
+ "type": "git",
46
+ "subDir": null,
47
+ "scope": "leanprover-community",
48
+ "rev": "8fff3f074da9237cd4e179fd6dd89be6c4022d41",
49
+ "name": "proofwidgets",
50
+ "manifestFile": "lake-manifest.json",
51
+ "inputRev": "v0.0.52-pre",
52
+ "inherited": true,
53
+ "configFile": "lakefile.lean"},
54
+ {"url": "https://github.com/leanprover-community/aesop",
55
+ "type": "git",
56
+ "subDir": null,
57
+ "scope": "leanprover-community",
58
+ "rev": "ba9a63be53f16b3b6e4043641c6bad4883e650b4",
59
+ "name": "aesop",
60
+ "manifestFile": "lake-manifest.json",
61
+ "inputRev": "master",
62
+ "inherited": true,
63
+ "configFile": "lakefile.toml"},
64
+ {"url": "https://github.com/leanprover-community/quote4",
65
+ "type": "git",
66
+ "subDir": null,
67
+ "scope": "leanprover-community",
68
+ "rev": "7b3b0c8327b3c0214ac49ca6d6922edbb81ab8c9",
69
+ "name": "Qq",
70
+ "manifestFile": "lake-manifest.json",
71
+ "inputRev": "master",
72
+ "inherited": true,
73
+ "configFile": "lakefile.toml"},
74
+ {"url": "https://github.com/leanprover-community/batteries",
75
+ "type": "git",
76
+ "subDir": null,
77
+ "scope": "leanprover-community",
78
+ "rev": "b18855cb0f9a19bd4d7e21f3e5525272e377f431",
79
+ "name": "batteries",
80
+ "manifestFile": "lake-manifest.json",
81
+ "inputRev": "main",
82
+ "inherited": true,
83
+ "configFile": "lakefile.toml"},
84
+ {"url": "https://github.com/leanprover/lean4-cli",
85
+ "type": "git",
86
+ "subDir": null,
87
+ "scope": "leanprover",
88
+ "rev": "a2eb24a3dbf681f2b655f82ba5ee5b139d4a5abc",
89
+ "name": "Cli",
90
+ "manifestFile": "lake-manifest.json",
91
+ "inputRev": "main",
92
+ "inherited": true,
93
+ "configFile": "lakefile.toml"}],
94
+ "name": "imo_steps",
95
+ "lakeDir": ".lake"}
Lemmas/lakefile.toml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name = "imo_steps"
2
+ version = "0.1.0"
3
+ keywords = ["math"]
4
+ defaultTargets = ["ImoSteps"]
5
+
6
+ [leanOptions]
7
+ pp.unicode.fun = true # pretty-prints `fun a ↦ b`
8
+ autoImplicit = false
9
+
10
+ [[require]]
11
+ name = "mathlib"
12
+ scope = "leanprover-community"
13
+ rev = "v4.17.0"
14
+
15
+ [[lean_lib]]
16
+ name = "ImoSteps"
Lemmas/lean-toolchain ADDED
@@ -0,0 +1 @@
 
 
1
+ leanprover/lean4:v4.17.0
assets/all_llms.png ADDED

Git LFS Details

  • SHA256: db8d9ae4a0e45cfa72625d8c682853315aaac19912627d9b6fa0a26c8c43e92c
  • Pointer size: 131 Bytes
  • Size of remote file: 158 kB
imo_proofs/ImoSteps.lean ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ -- This module serves as the root of the `ImoSteps` library.
2
+ -- Import modules here that should be built as part of the library.
3
+ import ImoSteps.Basic
imo_proofs/imo_1959_p1.lean ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+
4
+ open Nat
5
+
6
+ theorem imo_1959_p1
7
+ (n : ℕ)
8
+ (h₀ : 0 < n) :
9
+ Nat.gcd (21*n + 4) (14*n + 3) = 1 := by
10
+ have h₁: Nat.gcd (21*n + 4) (14*n + 3) = Nat.gcd (7*n + 1) (14*n + 3) := by
11
+ have g₀: (21 * n + 4) = (7*n + 1) + 1 * (14 * n + 3) := by linarith
12
+ rw [g₀]
13
+ exact gcd_add_mul_right_left (7 * n + 1) (14 * n + 3) 1
14
+ have h₂: Nat.gcd (7*n + 1) (14*n + 3) = Nat.gcd (7*n + 1) (1) := by
15
+ have g₁: 14 * n + 3 = (7 * n + 1) * 2 + 1 := by linarith
16
+ rw [g₁]
17
+ exact gcd_mul_left_add_right (7 * n + 1) 1 2
18
+ have h₃: Nat.gcd (7*n + 1) (1) = 1 := by
19
+ exact Nat.gcd_one_right (7 * n + 1)
20
+ linarith
imo_proofs/imo_1960_p2.lean ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ open Real
4
+
5
+
6
+ theorem imo_1960_p2
7
+ (x : ℝ)
8
+ (h₀ : 0 ≤ 1 + 2 * x)
9
+ (h₁ : (1 - Real.sqrt (1 + 2 * x))^2 ≠ 0)
10
+ (h₂ : (4 * x^2) / (1 - Real.sqrt (1 + 2*x))^2 < 2*x + 9) :
11
+ -(1 / 2) ≤ x ∧ x < 45 / 8 := by
12
+ apply And.intro
13
+ . linarith
14
+ . have h₃: 4 * x ^ 2 < (2 * x + 9) * (1 - sqrt (1 + 2 * x) ) ^ 2 := by
15
+ refine' (div_lt_iff₀ _).mp h₂
16
+ refine Ne.lt_of_le (id (Ne.symm h₁)) ?_
17
+ exact sq_nonneg (1 - sqrt (1 + 2 * x))
18
+ have h₄: (1 - sqrt (1 + 2 * x)) ^ 2 = (2 + 2 * x) - 2 * sqrt (1 + 2 * x) := by
19
+ ring_nf at *
20
+ rw [Real.sq_sqrt h₀]
21
+ ring_nf
22
+ have h₅: (2 * x + 9) ^ 2 * (sqrt (1 + 2 * x)) ^ 2 < (11 * x + 9) ^ 2 := by
23
+ rw [← mul_pow]
24
+ refine' pow_lt_pow_left₀ _ _ (by norm_num)
25
+ rw [h₄] at h₃
26
+ simp_all only [ne_eq, zero_lt_two]
27
+ . linarith
28
+ . refine' mul_nonneg _ _
29
+ linarith
30
+ exact sqrt_nonneg (1 + 2 * x)
31
+ have h₆: 8 * x^3 < 45 * x^2 := by
32
+ rw [Real.sq_sqrt h₀] at h₅
33
+ ring_nf at h₅
34
+ linarith
35
+ have h₇₁: 0 ≤ x^2 := by exact sq_nonneg x
36
+ have h₇: 8 * x < 45 := by
37
+ refine' lt_of_mul_lt_mul_right ?_ h₇₁
38
+ ring_nf at *
39
+ exact h₆
40
+ linarith
imo_proofs/imo_1962_p2.lean ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ open Real
4
+ set_option linter.unusedVariables.analyzeTactics true
5
+
6
+
7
+ theorem imo_1962_p2
8
+ (x : ℝ)
9
+ (h₀ : 0 ≤ 3 - x)
10
+ (h₁ : 0 ≤ x + 1)
11
+ (h₂ : 1 / 2 < Real.sqrt (3 - x) - Real.sqrt (x + 1)) :
12
+ -1 ≤ x ∧ x < 1 - Real.sqrt 31 / 8 := by
13
+ constructor
14
+ . exact neg_le_iff_add_nonneg.mpr h₁
15
+ have h₃: (2 *sqrt (3 - x) * sqrt (x + 1)) ^ 2 < (4 - 1 / 4) ^ 2 := by
16
+ refine' pow_lt_pow_left₀ _ _ (by norm_num)
17
+ . refine lt_tsub_iff_left.mpr ?_
18
+ refine lt_tsub_iff_right.mp ?_
19
+ suffices g₀: 4 - 2 * sqrt (3 - x) * sqrt (x + 1) = (sqrt (3 - x) - sqrt (x + 1)) ^ 2
20
+ . rw [g₀]
21
+ have g₁: (1:ℝ) / 4 = (1/2)^2 := by norm_num
22
+ rw [g₁]
23
+ exact pow_lt_pow_left₀ h₂ (by norm_num) (by norm_num)
24
+ rw [sub_sq]
25
+ rw [sq_sqrt h₀, sq_sqrt h₁]
26
+ ring_nf
27
+ . refine' mul_nonneg _ _
28
+ . refine mul_nonneg (by norm_num) ?_
29
+ exact sqrt_nonneg (3 - x)
30
+ . exact sqrt_nonneg (x + 1)
31
+ have h₄: 4 * (x + 1) * (3 - x) < 225 / 16 := by
32
+ norm_num at h₃
33
+ suffices g₀: 4 * (x + 1) * (3 - x) = (2 * sqrt (3 - x) * sqrt (x + 1)) ^ 2
34
+ . exact Eq.trans_lt g₀ h₃
35
+ . rw [mul_pow, mul_pow, sq_sqrt h₀, sq_sqrt h₁]
36
+ norm_num
37
+ exact mul_right_comm 4 (x + 1) (3 - x)
38
+ have hx1: x < 1 := by
39
+ suffices g₀: x + 1 < 3 - x
40
+ . linarith
41
+ . rw [← sq_sqrt h₀, ← sq_sqrt h₁]
42
+ refine' pow_lt_pow_left₀ _ _ (by norm_num)
43
+ . linarith
44
+ exact sqrt_nonneg (x + 1)
45
+ have h₅: x < 1 - sqrt 31 / 8 ∨ 1 + sqrt 31 / 8 < x := by
46
+ ring_nf at h₄
47
+ have g₀: 0 < x * x + -2 * x + 33 / 64 := by linarith
48
+ let a:ℝ := sqrt 31 / 8
49
+ have g₁: x * x + -2 * x + 33 / 64 = (x - (1 + a)) * (x - (1 - a)) := by
50
+ simp
51
+ ring_nf
52
+ norm_num
53
+ linarith
54
+ rw [g₁] at g₀
55
+ by_cases g₂: (x - (1 - a)) < 0
56
+ . left
57
+ exact sub_neg.mp g₂
58
+ push_neg at g₂
59
+ right
60
+ have g₃: 0 < (x - (1 + a)) := by exact pos_of_mul_pos_left g₀ g₂
61
+ exact sub_pos.mp g₃
62
+ cases h₅ with
63
+ | inl h₅ => exact h₅
64
+ | inr h₅ => linarith
imo_proofs/imo_1963_p5.lean ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ open Real
4
+ set_option linter.unusedVariables.analyzeTactics true
5
+
6
+
7
+ lemma sin_mul_cos
8
+ (x y : ℝ) :
9
+ Real.sin x * Real.cos y = (sin (x + y) + sin (x - y)) / 2 := by
10
+ rw [sin_add, sin_sub]
11
+ simp
12
+
13
+ theorem imo_1963_p5 :
14
+ Real.cos (π / 7) - Real.cos (2 * π / 7) + Real.cos (3 * π / 7) = 1 / 2 := by
15
+ let S:ℝ := Real.cos (π / 7) - Real.cos (2 * π / 7) + Real.cos (3 * π / 7)
16
+ have h₀: Real.sin (π / 7) * (S * 2) = Real.sin (π / 7) := by
17
+ ring_nf
18
+ have h₀₀: sin (π * (1 / 7)) * cos (π * (1 / 7)) * 2 = sin (2 * (π * (1 / 7))) := by
19
+ rw [Real.sin_two_mul]
20
+ exact (mul_rotate 2 (sin (π * (1 / 7))) (cos (π * (1 / 7)))).symm
21
+ rw [h₀₀, sin_mul_cos, sin_mul_cos]
22
+ rw [← mul_add, ← mul_sub, ← mul_add, ← mul_sub]
23
+ norm_num
24
+ ring_nf
25
+ have h₀₁: -sin (π * (3 / 7)) + sin (π * (4 / 7)) = 0 := by
26
+ rw [add_comm]
27
+ refine add_neg_eq_of_eq_add ?_
28
+ simp
29
+ refine sin_eq_sin_iff.mpr ?_
30
+ use 0
31
+ right
32
+ ring
33
+ linarith
34
+ have h₁: S = 1 / 2 := by
35
+ refine eq_div_of_mul_eq (by norm_num) ?_
36
+ nth_rewrite 2 [← mul_one (sin (π / 7))] at h₀
37
+ refine (mul_right_inj' ?_).mp h₀
38
+ refine sin_ne_zero_iff.mpr ?_
39
+ intro n
40
+ ring_nf
41
+ rw [mul_comm]
42
+ simp
43
+ push_neg
44
+ constructor
45
+ . by_contra! hc₀
46
+ have hc₁: 7 * (↑n:ℝ) = 1 := by
47
+ rw [mul_comm]
48
+ exact (mul_eq_one_iff_eq_inv₀ (by norm_num)).mpr hc₀
49
+ norm_cast at hc₁
50
+ have g₀: 0 < n := by linarith
51
+ linarith
52
+ . exact pi_ne_zero
53
+ exact h₁
imo_proofs/imo_1964_p2.lean ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real
5
+
6
+
7
+ lemma le_a_sq
8
+ (a b c : ℝ) :
9
+ (a + b - c) * (a + c - b) ≤ a ^ 2 := by
10
+ have h1: (a + b - c) * (a + c - b) = a ^ 2 - (b - c) ^ 2 := by
11
+ linarith
12
+ have h2: 0 ≤ (b - c) ^ 2 := by exact pow_two_nonneg (b - c)
13
+ rw [h1]
14
+ exact sub_le_self _ h2
15
+
16
+
17
+ theorem imo_1964_p2
18
+ (a b c : ℝ)
19
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
20
+ (h₁ : c < a + b)
21
+ (h₂ : b < a + c)
22
+ (h₃ : a < b + c) :
23
+ a ^ 2 * (b + c - a) + b ^ 2 * (c + a - b) + c ^ 2 * (a + b - c) ≤ 3 * a * b * c := by
24
+ have ha : 0 < b + c - a := by exact sub_pos.mpr h₃
25
+ have hb : 0 < a + c - b := by exact sub_pos.mpr h₂
26
+ have hc : 0 < a + b - c := by exact sub_pos.mpr h₁
27
+ have h₄: ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 ≤ (a * b * c) ^ 2 := by
28
+ have h₄₁: (a + b - c) * (a + c - b) ≤ a ^ 2 := by
29
+ exact le_a_sq a b c
30
+ have h₄₂: (a + b - c) * (b + c - a) ≤ b ^ 2 := by
31
+ rw [add_comm a b]
32
+ exact le_a_sq b a c
33
+ have h₄₃: (a + c - b) * (b + c - a) ≤ c ^ 2 := by
34
+ rw [add_comm a c, add_comm b c]
35
+ exact le_a_sq c a b
36
+ have h₄₄: ((a + b - c) * (a + c - b) * (b + c - a)) ^ 2 = ((a + b - c) * (a + c - b)) *
37
+ ((a + b - c) * (b + c - a)) * ((a + c - b) * (b + c - a)) := by
38
+ linarith
39
+ rw [h₄₄]
40
+ repeat rw [mul_pow]
41
+ refine mul_le_mul ?_ h₄₃ ?_ ?_
42
+ . refine mul_le_mul h₄₁ h₄₂ ?_ ?_
43
+ . refine le_of_lt ?_
44
+ exact mul_pos hc ha
45
+ . exact sq_nonneg a
46
+ . refine le_of_lt ?_
47
+ exact mul_pos hb ha
48
+ . refine le_of_lt ?_
49
+ simp_all only [sub_pos, gt_iff_lt, pow_pos, mul_pos_iff_of_pos_left]
50
+ have h₅: (a + b - c) * (a + c - b) * (b + c - a) ≤ a * b * c := by
51
+ refine le_of_pow_le_pow_left₀ (by norm_num) ?_ h₄
52
+ refine le_of_lt ?_
53
+ refine mul_pos ?_ h₀.2.2
54
+ exact mul_pos h₀.1 h₀.2.1
55
+ linarith
imo_proofs/imo_1965_p2.lean ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+
5
+ theorem imo_1965_p2
6
+ (x y z : ℝ)
7
+ (a : ℕ → ℝ)
8
+ (h₀ : 0 < a 0 ∧ 0 < a 4 ∧ 0 < a 8)
9
+ (h₁ : a 1 < 0 ∧ a 2 < 0)
10
+ (h₂ : a 3 < 0 ∧ a 5 < 0)
11
+ (h₃ : a 6 < 0 ∧ a 7 < 0)
12
+ (h₄ : 0 < a 0 + a 1 + a 2)
13
+ (h₅ : 0 < a 3 + a 4 + a 5)
14
+ (h₆ : 0 < a 6 + a 7 + a 8)
15
+ (h₇ : a 0 * x + a 1 * y + a 2 * z = 0)
16
+ (h₈ : a 3 * x + a 4 * y + a 5 * z = 0)
17
+ (h₉ : a 6 * x + a 7 * y + a 8 * z = 0) :
18
+ x = 0 ∧ y = 0 ∧ z = 0 := by
19
+ by_cases hx0: x = 0
20
+ . rw [hx0] at h₇
21
+ constructor
22
+ . exact hx0
23
+ . rw [hx0] at h₈ h₉
24
+ simp at h₇ h₈ h₉
25
+ by_cases hy0: y = 0
26
+ . constructor
27
+ . exact hy0
28
+ . rw [hy0] at h₇
29
+ simp at h₇
30
+ . cases' h₇ with h₇₀ h₇₁
31
+ . exfalso
32
+ linarith
33
+ . exact h₇₁
34
+ . by_cases hyn: y < 0
35
+ . have g1: 0 < a 1 * y := by exact mul_pos_of_neg_of_neg h₁.1 hyn
36
+ have g2: a 1 * y = -a 2 * z := by linarith
37
+ rw [g2] at g1
38
+ have g3: a 2 *z < 0 := by linarith
39
+ have hzp: 0 < z := by exact pos_of_mul_neg_right g3 (le_of_lt h₁.2)
40
+ exfalso
41
+ have g4: a 4 * y < 0 := by exact mul_neg_of_pos_of_neg h₀.2.1 hyn
42
+ have g5: a 5 * z < 0 := by exact mul_neg_of_neg_of_pos h₂.2 hzp
43
+ linarith
44
+ . push_neg at hy0 hyn
45
+ have hyp: 0 < y := by exact lt_of_le_of_ne hyn hy0.symm
46
+ exfalso
47
+ have g1: a 1 * y < 0 := by exact mul_neg_of_neg_of_pos h₁.1 hyp
48
+ have g2: 0 < z * a 2 := by linarith
49
+ have hzp: z < 0 := by exact neg_of_mul_pos_left g2 (le_of_lt h₁.2)
50
+ have g3: 0 < a 4 * y := by exact mul_pos h₀.2.1 hyp
51
+ have g4: 0 < a 5 * z := by exact mul_pos_of_neg_of_neg h₂.2 hzp
52
+ linarith
53
+ . exfalso
54
+ push_neg at hx0
55
+ by_cases hxp: 0 < x
56
+ . by_cases hy0: y = 0
57
+ . rw [hy0] at h₇ h₈ h₉
58
+ simp at h₇ h₈ h₉
59
+ have g1: 0 < a 0 * x := by exact mul_pos h₀.1 hxp
60
+ have g2: a 2 * z < 0 := by linarith
61
+ have hzn: 0 < z := by exact pos_of_mul_neg_right g2 (le_of_lt h₁.2)
62
+ have g3: a 3 * x < 0 := by exact mul_neg_of_neg_of_pos h₂.1 hxp
63
+ have g4: a 5 * z < 0 := by exact mul_neg_of_neg_of_pos h₂.2 hzn
64
+ linarith
65
+ . push_neg at hy0
66
+ by_cases hyp: 0 < y
67
+ . have g1: a 6 * x < 0 := by exact mul_neg_of_neg_of_pos h₃.1 hxp
68
+ have g2: a 7 * y < 0 := by exact mul_neg_of_neg_of_pos h₃.2 hyp
69
+ have g3: 0 < z * a 8 := by linarith
70
+ have hzp: 0 < z := by exact pos_of_mul_pos_left g3 (le_of_lt h₀.2.2)
71
+ ------ here we consider all the possible relationships between x, y, z
72
+ by_cases rxy: x ≤ y
73
+ . by_cases ryz: y ≤ z
74
+ -- x <= y <= z
75
+ . have g2: 0 < (a 6 + a 7 + a 8) * y := by exact mul_pos h₆ hyp
76
+ have g3: 0 ≤ a 6 * (x-y) := by
77
+ exact mul_nonneg_of_nonpos_of_nonpos (le_of_lt h₃.1) (by linarith)-- exact mul_nonneg (le_of_lt h₃.1) (by linarith),},
78
+ have g4: 0 ≤ a 8 * (z-y) := by exact mul_nonneg (le_of_lt h₀.2.2) (by linarith)
79
+ linarith
80
+ push_neg at ryz
81
+ by_cases rxz: x ≤ z
82
+ -- x <= z < y
83
+ . have g2: 0 < (a 3 + a 4 + a 5) * y := by exact mul_pos h₅ hyp
84
+ have g3: 0 ≤ a 3 * (x-y) := by
85
+ exact mul_nonneg_of_nonpos_of_nonpos (le_of_lt h₂.1) (by linarith)
86
+ have g4: 0 < a 5 * (z-y) := by
87
+ exact mul_pos_of_neg_of_neg h₂.2 (by linarith)
88
+ linarith
89
+ push_neg at rxz -- z < x <= y
90
+ have g2: 0 < (a 3 + a 4 + a 5) * y := by exact mul_pos h₅ hyp
91
+ have g3: 0 ≤ a 3 * (x-y) := by
92
+ exact mul_nonneg_of_nonpos_of_nonpos (le_of_lt h₂.1) (by linarith)
93
+ have g4: 0 < a 5 * (z-y) := by
94
+ exact mul_pos_of_neg_of_neg h₂.2 (by linarith)
95
+ linarith
96
+ push_neg at rxy
97
+ by_cases rzy: z ≤ y
98
+ -- z <= y < x
99
+ . have g2: 0 < (a 0 + a 1 + a 2) * y := by exact mul_pos h₄ hyp
100
+ have g3: 0 < a 0 * (x-y) := by exact mul_pos h₀.1 (by linarith)
101
+ have g4: 0 ≤ a 2 * (z-y) := by
102
+ exact mul_nonneg_of_nonpos_of_nonpos (le_of_lt h₁.2) (by linarith)
103
+ linarith
104
+ . push_neg at rzy
105
+ by_cases rzx: z ≤ x
106
+ -- y < z <= x
107
+ . have g2: 0 < (a 0 + a 1 + a 2) * z := by exact mul_pos h₄ hzp
108
+ have g3: 0 ≤ a 0 * (x-z) := by exact mul_nonneg (le_of_lt h₀.1) (by linarith)
109
+ have g4: 0 < a 1 * (y-z) := by exact mul_pos_of_neg_of_neg h₁.1 (by linarith)
110
+ linarith
111
+ . push_neg at rzx
112
+ -- y < x < z
113
+ have g2: 0 < (a 6 + a 7 + a 8) * z := by exact mul_pos h₆ hzp
114
+ have g3: 0 < a 6 * (x-z) := by exact mul_pos_of_neg_of_neg h₃.1 (by linarith)
115
+ have g4: 0 < a 7 * (y-z) := by exact mul_pos_of_neg_of_neg h₃.2 (by linarith)
116
+ linarith
117
+ -------- new world where y < 0 and 0 < x
118
+ . push_neg at hyp
119
+ have hyn: y < 0 := by exact lt_of_le_of_ne hyp hy0
120
+ -- show from a 0 that 0 < z
121
+ have g1: 0 < a 0 * x := by exact mul_pos h₀.1 hxp
122
+ have g2: 0 < a 1 * y := by exact mul_pos_of_neg_of_neg h₁.1 hyn
123
+ have g3: a 2 * z < 0 := by linarith
124
+ have hzp: 0 < z := by exact pos_of_mul_neg_right g3 (le_of_lt h₁.2)
125
+ -- then show from a 3 that's not possible
126
+ have g4: a 3 * x < 0 := by exact mul_neg_of_neg_of_pos h₂.1 hxp
127
+ have g5: a 4 * y < 0 := by exact mul_neg_of_pos_of_neg h₀.2.1 hyn
128
+ have g6: a 5 * z < 0 := by exact mul_neg_of_neg_of_pos h₂.2 hzp
129
+ linarith
130
+ . push_neg at hxp
131
+ have hxn: x < 0 := by exact lt_of_le_of_ne hxp hx0
132
+ by_cases hyp: 0 ≤ y
133
+ . have g1: a 0 * x < 0 := by exact mul_neg_of_pos_of_neg h₀.1 hxn
134
+ have g2: a 1 * y ≤ 0 := by
135
+ refine mul_nonpos_iff.mpr ?_
136
+ right
137
+ constructor
138
+ . exact le_of_lt h₁.1
139
+ . exact hyp
140
+ have g3: 0 < z * a 2 := by linarith
141
+ have hzn: z < 0 := by exact neg_of_mul_pos_left g3 (le_of_lt h₁.2)
142
+ -- demonstrate the contradiction
143
+ have g4: 0 < a 3 * x := by exact mul_pos_of_neg_of_neg h₂.1 hxn
144
+ have g5: 0 ≤ a 4 * y := by exact mul_nonneg (le_of_lt h₀.2.1) hyp
145
+ have g6: 0 < a 5 * z := by exact mul_pos_of_neg_of_neg h₂.2 hzn
146
+ linarith
147
+ . push_neg at hyp
148
+ -- have hyn: y < 0, {exact lt_of_le_of_ne hyp hy0,},
149
+ have g1: 0 < a 6 * x := by exact mul_pos_of_neg_of_neg h₃.1 hxn
150
+ have g2: 0 < a 7 * y := by exact mul_pos_of_neg_of_neg h₃.2 hyp
151
+ have g3: z * a 8 < 0 := by linarith
152
+ have hzp: z < 0 := by exact neg_of_mul_neg_left g3 (le_of_lt h₀.2.2)
153
+ -- we have x,y,z < 0 -- we will examine all the orders they can have
154
+ by_cases rxy: x ≤ y
155
+ . by_cases ryz: y ≤ z
156
+ -- x <= y <= z
157
+ . have g2: (a 0 + a 1 + a 2) * y < 0 := by exact mul_neg_of_pos_of_neg h₄ hyp
158
+ have g3: a 0 * (x-y) ≤ 0 := by
159
+ exact mul_nonpos_of_nonneg_of_nonpos (le_of_lt h₀.1) (by linarith)
160
+ have g4: a 2 * (z-y) ≤ 0 := by
161
+ exact mul_nonpos_of_nonpos_of_nonneg (le_of_lt h₁.2) (by linarith)
162
+ linarith
163
+ . push_neg at ryz
164
+ by_cases rxz: x ≤ z
165
+ -- x <= z < y
166
+ . have g2: (a 0 + a 1 + a 2) * z < 0 := by exact mul_neg_of_pos_of_neg h₄ hzp
167
+ have g3: a 0 * (x-z) ≤ 0 := by
168
+ exact mul_nonpos_of_nonneg_of_nonpos (le_of_lt h₀.1) (by linarith)
169
+ have g4: a 1 * (y-z) < 0 := by
170
+ exact mul_neg_of_neg_of_pos h₁.1 (by linarith)
171
+ linarith
172
+ . push_neg at rxz -- z < x <= y
173
+ have g2: (a 6 + a 7 + a 8) * z < 0 := by exact mul_neg_of_pos_of_neg h₆ hzp
174
+ have g3: a 6 * (x-z) < 0 := by exact mul_neg_of_neg_of_pos h₃.1 (by linarith)
175
+ have g4: a 7 * (y-z) < 0 := by exact mul_neg_of_neg_of_pos h₃.2 (by linarith)
176
+ linarith
177
+ . push_neg at rxy
178
+ by_cases rzy: z ≤ y
179
+ -- z <= y < x
180
+ . have g2: (a 6 + a 7 + a 8) * y < 0 := by exact mul_neg_of_pos_of_neg h₆ hyp
181
+ have g3: a 6 * (x-y) < 0 := by exact mul_neg_of_neg_of_pos h₃.1 (by linarith)
182
+ have g4: a 8 * (z-y) ≤ 0 := by
183
+ exact mul_nonpos_of_nonneg_of_nonpos (le_of_lt h₀.2.2) (by linarith)
184
+ linarith
185
+ . push_neg at rzy
186
+ by_cases rzx: z ≤ x
187
+ -- y < z <= x
188
+ . have g2: (a 3 + a 4 + a 5) * z < 0 := by exact mul_neg_of_pos_of_neg h₅ hzp
189
+ have g3: a 3 * (x-z) ≤ 0 := by
190
+ exact mul_nonpos_of_nonpos_of_nonneg (le_of_lt h₂.1) (by linarith)
191
+ have g4: a 4 * (y-z) < 0 := by exact mul_neg_of_pos_of_neg h₀.2.1 (by linarith)
192
+ linarith
193
+ . push_neg at rzx
194
+ -- y < x < z
195
+ have g2: (a 3 + a 4 + a 5) * y < 0 := by exact mul_neg_of_pos_of_neg h₅ hyp
196
+ have g3: a 3 * (x-y) < 0 := by exact mul_neg_of_neg_of_pos h₂.1 (by linarith)
197
+ have g4: a 5 * (z-y) < 0 := by exact mul_neg_of_neg_of_pos h₂.2 (by linarith)
198
+ linarith
imo_proofs/imo_1968_p5_1.lean ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real
5
+
6
+
7
+ theorem imo_1968_p5_1
8
+ (a : ℝ)
9
+ (f : ℝ → ℝ)
10
+ (h₀ : 0 < a)
11
+ (h₁ : ∀ x, f (x + a) = 1 / 2 + Real.sqrt (f x - (f x)^2))
12
+ (h₂ : ∀ x, 1 / 2 ≤ f x ∧ f x ≤ 1) :
13
+ ∃ b > 0, ∀ x, f (x + b) = f x := by
14
+ use (2 * a)
15
+ constructor
16
+ . refine mul_pos (by norm_num) h₀
17
+ . intro x
18
+ have h₃: f (x + a) = 1 / 2 + Real.sqrt (f x - (f x)^2) := by
19
+ exact h₁ x
20
+ have h₄: f (x + 2 * a) = 1 / 2 + Real.sqrt (f (x + a) - (f (x + a)^2)) := by
21
+ rw [two_mul, ← add_assoc]
22
+ exact h₁ (x + a)
23
+ have h₅: f (x + a) - (f (x + a) ^ 2) = (f x - 1 / 2) ^ 2 := by
24
+ have h₅₁: 0 ≤ f x - (f x)^2 := by
25
+ refine sub_nonneg_of_le ?_
26
+ rw [pow_two]
27
+ nth_rw 3 [← mul_one (f x)]
28
+ refine (mul_le_mul_left ?_).mpr ?_
29
+ . linarith [h₂ x]
30
+ . exact (h₂ x).2
31
+ rw [h₃, add_sq, sub_sq, sq_sqrt h₅₁]
32
+ ring_nf
33
+ rw [h₅, sqrt_sq ?_] at h₄
34
+ . linarith
35
+ . have h₆: 1 / 2 ≤ f x := by
36
+ exact (h₂ x).1
37
+ linarith [h₆]
imo_proofs/imo_1969_p2.lean ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real BigOperators
5
+
6
+ theorem imo_1969_p2
7
+ (m n : ℝ)
8
+ (k : ℕ)
9
+ (a : ℕ → ℝ)
10
+ (f : ℝ → ℝ)
11
+ -- (h₀ : 0 < k)
12
+ -- (h₁ : ∀ x, f x = ∑ i in Finset.range k, ((Real.cos (a i + x)) / (2^i)))
13
+ (h₁ : ∀ x, f x = Finset.sum (Finset.range k) fun i => ((Real.cos (a i + x)) / (2^i)))
14
+ (h₂ : f m = 0)
15
+ (h₃ : f n = 0)
16
+ (h₄: Finset.sum (Finset.range k) (fun i => (((cos (a i)) / (2 ^ i)))) ≠ 0) :
17
+ ∃ t : ℤ, m - n = t * π := by
18
+ let Ccos := Finset.sum (Finset.range k) (fun i => (((cos (a i)) / (2 ^ i))))
19
+ let Csin := Finset.sum (Finset.range k) (fun i => (((sin (a i)) / (2 ^ i))))
20
+ have hCcos: Ccos = Finset.sum (Finset.range k) (fun i => (((cos (a i)) / (2 ^ i)))) := by
21
+ exact rfl
22
+ have hCsin: Csin = Finset.sum (Finset.range k) (fun i => (((sin (a i)) / (2 ^ i)))) := by
23
+ exact rfl
24
+ have h₅: ∀ x, f x = Ccos * cos x - Csin * sin x := by
25
+ intro x
26
+ rw [h₁ x]
27
+ have h₅₀: ∑ i ∈ Finset.range k, (cos (a i + x) / 2 ^ i)
28
+ = ∑ i ∈ Finset.range k, (((cos (a i) * cos (x) - sin (a i) * sin (x)) / (2^i))) := by
29
+ refine Finset.sum_congr (by rfl) ?_
30
+ simp
31
+ intros i _
32
+ refine (div_eq_div_iff ?_ ?_).mpr ?_
33
+ . exact Ne.symm (NeZero.ne' (2 ^ i))
34
+ . exact Ne.symm (NeZero.ne' (2 ^ i))
35
+ . refine mul_eq_mul_right_iff.mpr ?_
36
+ simp
37
+ exact cos_add (a i) x
38
+ rw [h₅₀]
39
+ ring_nf
40
+ rw [Finset.sum_sub_distrib]
41
+ have h₅₂: ∑ i ∈ Finset.range k, cos (a i) * cos x * (1 / 2) ^ i
42
+ = ∑ i ∈ Finset.range k, (cos (a i) * (1 / 2) ^ i) * cos x := by
43
+ refine Finset.sum_congr (by rfl) ?_
44
+ simp
45
+ intro i _
46
+ linarith
47
+ have h₅₃: ∑ x_1 ∈ Finset.range k, sin (a x_1) * sin x * (1 / 2) ^ x_1
48
+ = ∑ x_1 ∈ Finset.range k, ((sin (a x_1) * (1 / 2) ^ x_1) * sin x) := by
49
+ refine Finset.sum_congr (by rfl) ?_
50
+ simp
51
+ intro i _
52
+ linarith
53
+ rw [h₅₂, ← Finset.sum_mul _ _ (cos x)]
54
+ rw [h₅₃, ← Finset.sum_mul _ _ (sin x)]
55
+ ring_nf at hCcos
56
+ ring_nf at hCsin
57
+ rw [hCcos, hCsin]
58
+ have h₆: (∃ x, (f x = 0 ∧ cos x = 0)) → ∀ y, f y = Ccos * cos y := by
59
+ intro g₀
60
+ obtain ⟨x, hx₀, hx₁⟩ := g₀
61
+ have g₁: Finset.sum (Finset.range k) (fun i => (((sin (a i)) / (2 ^ i)))) = 0 := by
62
+ rw [h₅ x, hx₁] at hx₀
63
+ simp at hx₀
64
+ cases' hx₀ with hx₂ hx₃
65
+ . exact hx₂
66
+ . exfalso
67
+ apply sin_eq_zero_iff_cos_eq.mp at hx₃
68
+ cases' hx₃ with hx₃ hx₄
69
+ . linarith
70
+ . linarith
71
+ intro y
72
+ rw [h₅ y]
73
+ have g₂: Csin = 0 := by
74
+ linarith
75
+ rw [g₂, zero_mul]
76
+ exact sub_zero (Ccos * cos y)
77
+ by_cases hmn: (cos m = 0) ∨ (cos n = 0)
78
+ . have h₇: ∀ (x : ℝ), f x = Ccos * cos x := by
79
+ refine h₆ ?_
80
+ cases' hmn with hm hn
81
+ . use m
82
+ . use n
83
+ have h₈: ∀ x, f x = 0 → cos x = 0 := by
84
+ intros x hx₀
85
+ rw [h₇ x] at hx₀
86
+ refine eq_zero_of_ne_zero_of_mul_left_eq_zero ?_ hx₀
87
+ exact h₄
88
+ have hm₀: ∃ t:ℤ , m = (2 * ↑ t + 1) * π / 2 := by
89
+ refine cos_eq_zero_iff.mp ?_
90
+ exact h₈ m h₂
91
+ have hn₀: ∃ t:ℤ , n = (2 * ↑ t + 1) * π / 2 := by
92
+ refine cos_eq_zero_iff.mp ?_
93
+ exact h₈ n h₃
94
+ obtain ⟨tm, hm₁⟩ := hm₀
95
+ obtain ⟨tn, hn₁⟩ := hn₀
96
+ rw [hm₁, hn₁]
97
+ use (tm - tn)
98
+ rw [Int.cast_sub]
99
+ ring_nf
100
+ . push_neg at hmn
101
+ have h₇: tan m = tan n := by
102
+ have h₇₀: ∀ (x:ℝ), (f x = 0 ∧ cos x ≠ 0) → tan x = Ccos / Csin := by
103
+ intro x hx₀
104
+ rw [tan_eq_sin_div_cos]
105
+ symm
106
+ refine (div_eq_div_iff ?_ ?_).mp ?_
107
+ . simp
108
+ exact hx₀.2
109
+ . simp
110
+ have hx₁: Ccos * cos x ≠ 0 := by
111
+ refine mul_ne_zero ?_ hx₀.2
112
+ exact h₄
113
+ have hx₂: Ccos * cos x = Csin * sin x := by
114
+ rw [h₅ x] at hx₀
115
+ refine eq_of_sub_eq_zero ?_
116
+ exact hx₀.1
117
+ have hx₃: Csin * sin x ≠ 0 := by
118
+ rw [← hx₂]
119
+ exact hx₁
120
+ exact left_ne_zero_of_mul hx₃
121
+ . simp
122
+ symm
123
+ refine eq_of_sub_eq_zero ?_
124
+ rw [h₅ x] at hx₀
125
+ linarith
126
+ have h₇₁: tan m = Ccos / Csin := by
127
+ refine h₇₀ m ?_
128
+ constructor
129
+ . exact h₂
130
+ . exact hmn.1
131
+ have h₇₂: tan n = Ccos / Csin := by
132
+ refine h₇₀ n ?_
133
+ constructor
134
+ . exact h₃
135
+ . exact hmn.2
136
+ rw [h₇₁, h₇₂]
137
+ have h₈: sin (m - n) = 0 := by
138
+ have h₈₀: tan m - tan n = 0 := by exact sub_eq_zero_of_eq h₇
139
+ have h₈₁: (sin m * cos n - cos m * sin n) / (cos m * cos n) = 0 := by
140
+ rw [← div_sub_div (sin m) (sin n) hmn.1 hmn.2]
141
+ repeat rw [← tan_eq_sin_div_cos]
142
+ exact h₈₀
143
+ have h₈₂: sin (m - n) / (cos m * cos n) = 0 := by
144
+ rw [sin_sub]
145
+ exact h₈₁
146
+ apply div_eq_zero_iff.mp at h₈₂
147
+ cases' h₈₂ with h₈₂ h₈₃
148
+ . exact h₈₂
149
+ . exfalso
150
+ simp at h₈₃
151
+ cases' h₈₃ with h₈₄ h₈₅
152
+ . exact hmn.1 h₈₄
153
+ . exact hmn.2 h₈₅
154
+ apply sin_eq_zero_iff.mp at h₈
155
+ let ⟨t, ht⟩ := h₈
156
+ use t
157
+ exact ht.symm
imo_proofs/imo_1974_p3.lean ADDED
@@ -0,0 +1,514 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat BigOperators Finset
5
+
6
+
7
+ lemma aux_1
8
+ (a : ℕ) :
9
+ ¬ a ^ 2 ≡ 2 [MOD 5] := by
10
+ intro ha₀
11
+ induction' a with n hn
12
+ . simp at ha₀
13
+ have ha₁: ¬ 0 ≡ 2 [MOD 5] := by decide
14
+ exact ha₁ ha₀
15
+ . let b:ℕ := n % 5
16
+ have hb₀: b < 5 := by omega
17
+ have hb₁: n ≡ b [MOD 5] := by exact Nat.ModEq.symm (Nat.mod_modEq n 5)
18
+ have hb₂: (n + 1) ≡ (b + 1) [MOD 5] := by
19
+ exact Nat.ModEq.add_right 1 hb₁
20
+ have hb₃: (n + 1) ^ 2 ≡ (b + 1) ^ 2 [MOD 5] := by
21
+ exact Nat.ModEq.pow 2 hb₂
22
+ interval_cases b
23
+ . simp at *
24
+ have g₀: 1 ≡ 2 [MOD 5] := by
25
+ refine Nat.ModEq.trans hb₃.symm ha₀
26
+ have g₁: ¬ 1 ≡ 2 [MOD 5] := by decide
27
+ exact g₁ g₀
28
+ . simp at hb₃
29
+ have g₀: 4 ≡ 2 [MOD 5] := by
30
+ refine Nat.ModEq.trans hb₃.symm ha₀
31
+ have g₁: ¬ 4 ≡ 2 [MOD 5] := by decide
32
+ exact g₁ g₀
33
+ . simp at hb₃
34
+ have g₀: 9 ≡ 2 [MOD 5] := by
35
+ refine Nat.ModEq.trans hb₃.symm ha₀
36
+ have g₁: ¬ 9 ≡ 2 [MOD 5] := by decide
37
+ exact g₁ g₀
38
+ . simp at hb₃
39
+ have g₀: 16 ≡ 2 [MOD 5] := by
40
+ refine Nat.ModEq.trans hb₃.symm ha₀
41
+ have g₁: ¬ 16 ≡ 2 [MOD 5] := by decide
42
+ exact g₁ g₀
43
+ . simp at hb₃
44
+ have g₀: 25 ≡ 2 [MOD 5] := by
45
+ refine Nat.ModEq.trans hb₃.symm ha₀
46
+ have g₁: ¬ 25 ≡ 2 [MOD 5] := by decide
47
+ exact g₁ g₀
48
+
49
+
50
+ lemma aux_2
51
+ (a : ℕ) :
52
+ ¬ a ^ 2 ≡ 3 [MOD 5] := by
53
+ intro ha₀
54
+ induction' a with n hn
55
+ . simp at ha₀
56
+ have ha₁: ¬ 0 ≡ 3 [MOD 5] := by decide
57
+ exact ha₁ ha₀
58
+ . let b:ℕ := n % 5
59
+ have hb₀: b < 5 := by omega
60
+ have hb₁: n ≡ b [MOD 5] := by exact Nat.ModEq.symm (Nat.mod_modEq n 5)
61
+ have hb₂: (n + 1) ≡ (b + 1) [MOD 5] := by
62
+ exact Nat.ModEq.add_right 1 hb₁
63
+ have hb₃: (n + 1) ^ 2 ≡ (b + 1) ^ 2 [MOD 5] := by
64
+ exact Nat.ModEq.pow 2 hb₂
65
+ interval_cases b
66
+ . simp at *
67
+ have g₀: 1 ≡ 3 [MOD 5] := by
68
+ refine Nat.ModEq.trans hb₃.symm ha₀
69
+ have g₁: ¬ 1 ≡ 3 [MOD 5] := by decide
70
+ exact g₁ g₀
71
+ . simp at hb₃
72
+ have g₀: 4 ≡ 3 [MOD 5] := by
73
+ refine Nat.ModEq.trans hb₃.symm ha₀
74
+ have g₁: ¬ 4 ≡ 3 [MOD 5] := by decide
75
+ exact g₁ g₀
76
+ . simp at hb₃
77
+ have g₀: 9 ≡ 3 [MOD 5] := by
78
+ refine Nat.ModEq.trans hb₃.symm ha₀
79
+ have g₁: ¬ 9 ≡ 3 [MOD 5] := by decide
80
+ exact g₁ g₀
81
+ . simp at hb₃
82
+ have g₀: 16 ≡ 3 [MOD 5] := by
83
+ refine Nat.ModEq.trans hb₃.symm ha₀
84
+ have g₁: ¬ 16 ≡ 3 [MOD 5] := by decide
85
+ exact g₁ g₀
86
+ . simp at hb₃
87
+ have g₀: 25 ≡ 3 [MOD 5] := by
88
+ refine Nat.ModEq.trans hb₃.symm ha₀
89
+ have g₁: ¬ 25 ≡ 3 [MOD 5] := by decide
90
+ exact g₁ g₀
91
+
92
+
93
+ lemma aux_3
94
+ (n : ℕ) :
95
+ 7 ^ (2 * n + 1) ≡ 2 [MOD 5] ∨ 7 ^ (2 * n + 1) ≡ 3 [MOD 5] := by
96
+ induction' n with d hd
97
+ . simp
98
+ left
99
+ decide
100
+ . let b:ℕ := (7 ^ (2 * d + 1)) % 5
101
+ have hb: b = (7 ^ (2 * d + 1)) % 5 := by rfl
102
+ have hb₀: b < 5 := by
103
+ rw [hb]
104
+ omega
105
+ have hb₁: (7 ^ (2 * d + 1)) ≡ b [MOD 5] := by
106
+ exact ModEq.symm (mod_modEq (7 ^ (2 * d + 1)) 5)
107
+ ring_nf at *
108
+ have hb₂: 7 ^ (d * 2) * 7 * 49 ≡ b * 49 [MOD 5] := by
109
+ exact ModEq.mul hb₁ rfl
110
+ have hb₃: 7 ^ (d * 2) * 7 * 49 ≡ 2 * 49 [MOD 5] ∨ 7 ^ (d * 2) * 7 * 49 ≡ 3 * 49 [MOD 5] := by
111
+ cases' hd with hd₀ hd₁
112
+ . left
113
+ exact ModEq.mul hd₀ rfl
114
+ . right
115
+ exact ModEq.mul hd₁ rfl
116
+ ring_nf at hb₂
117
+ ring_nf at *
118
+ cases' hb₃ with hb₄ hb₅
119
+ . interval_cases b
120
+ . ring_nf at hb₂
121
+ have g₀: 0 ≡ 98 [MOD 5] := by
122
+ refine Nat.ModEq.trans hb₂.symm hb₄
123
+ have g₁: ¬ 0 ≡ 98 [MOD 5] := by decide
124
+ exact (g₁ g₀).elim
125
+ . ring_nf at hb₂
126
+ have g₀: 49 ≡ 98 [MOD 5] := by
127
+ refine Nat.ModEq.trans hb₂.symm hb₄
128
+ have g₁: ¬ 49 ≡ 98 [MOD 5] := by decide
129
+ exact (g₁ g₀).elim
130
+ . ring_nf at hb₂
131
+ have g₀: 98 ≡ 3 [MOD 5] := by decide
132
+ right
133
+ refine Nat.ModEq.trans hb₂ g₀
134
+ . ring_nf at hb₂
135
+ have g₀: 147 ≡ 98 [MOD 5] := by
136
+ refine Nat.ModEq.trans hb₂.symm hb₄
137
+ have g₁: ¬ 147 ≡ 98 [MOD 5] := by decide
138
+ exact (g₁ g₀).elim
139
+ . ring_nf at hb₂
140
+ have g₀: 196 ≡ 98 [MOD 5] := by
141
+ refine Nat.ModEq.trans hb₂.symm hb₄
142
+ have g₁: ¬ 196 ≡ 98 [MOD 5] := by decide
143
+ exact (g₁ g₀).elim
144
+ . interval_cases b
145
+ . ring_nf at hb₂
146
+ have g₀: 0 ≡ 147 [MOD 5] := by
147
+ refine Nat.ModEq.trans hb₂.symm hb₅
148
+ have g₁: ¬ 0 ≡ 147 [MOD 5] := by decide
149
+ exact (g₁ g₀).elim
150
+ . ring_nf at hb₂
151
+ have g₀: 49 ≡ 147 [MOD 5] := by
152
+ refine Nat.ModEq.trans hb₂.symm hb₅
153
+ have g₁: ¬ 49 ≡ 147 [MOD 5] := by decide
154
+ exact (g₁ g₀).elim
155
+ . ring_nf at hb₂
156
+ have g₀: 98 ≡ 147 [MOD 5] := by
157
+ refine Nat.ModEq.trans hb₂.symm hb₅
158
+ have g₁: ¬ 98 ≡ 147 [MOD 5] := by decide
159
+ exact (g₁ g₀).elim
160
+ . ring_nf at hb₂
161
+ exact Or.intro_left (7 ^ (d * 2) * 343 ≡ 3 [MOD 5]) hb₅
162
+ . ring_nf at hb₂
163
+ have g₀: 196 ≡ 147 [MOD 5] := by
164
+ refine Nat.ModEq.trans hb₂.symm hb₅
165
+ have g₁: ¬ 196 ≡ 147 [MOD 5] := by decide
166
+ exact (g₁ g₀).elim
167
+
168
+
169
+ lemma aux_4
170
+ (n b a : ℕ)
171
+ (k : ℝ)
172
+ -- (hk : k = √8)
173
+ -- (hb : b = ∑ k ∈ range (n + 1), (2 * n + 1).choose (2 * k + 1) * 2 ^ (3 * k))
174
+ -- (ha : a = ∑ k ∈ range (n + 1), (2 * n + 1).choose (2 * k) * 2 ^ (3 * k))
175
+ (hb₁ : ↑b = 1 / k * ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x + 1)) * k ^ (2 * x + 1))
176
+ (ha₁ : ↑a = ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x)) * k ^ (2 * x))
177
+ (hk₀ : k * k⁻¹ = 1) :
178
+ (1 + k) ^ (2 * n + 1) = ↑a + ↑b * k := by
179
+ rw [mul_comm _ k, hb₁, ← mul_assoc]
180
+ rw [← inv_eq_one_div, hk₀, one_mul, ha₁]
181
+ rw [add_comm, add_pow k 1 (2 * n + 1)]
182
+ simp
183
+ clear hb₁ ha₁ b a hk₀
184
+ let f : ℕ → ℝ := fun i => ↑((2 * n + 1).choose (i)) * k ^ i
185
+ let fs₂ := Finset.range (2 * n + 2)
186
+ -- let fs₀ : Finset ℕ := Finset.filter (fun x => Odd x) (Finset.range (2 * n + 2))
187
+ let fs₀ : Finset ℕ := fs₂.filter (fun x => Odd x)
188
+ let fs₁ : Finset ℕ := fs₂.filter (fun x => Even x)
189
+ let fs₃ : Finset ℕ := Finset.range (n + 1)
190
+ have h₀: ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x + 1)) * k ^ (2 * x + 1) =
191
+ ∑ x ∈ fs₀, ↑((2 * n + 1).choose (x)) * k ^ (x) := by
192
+ have h₀₁: ∑ x ∈ fs₃, f (2 * x + 1) = ∑ x ∈ (fs₀), f x := by
193
+ refine sum_bij ?i ?_ ?i_inj ?i_surj ?h
194
+ . intros a _
195
+ exact (2 * a + 1)
196
+ . intros a ha₀
197
+ have ha₁: a ≤ n := by exact mem_range_succ_iff.mp ha₀
198
+ have ha₂: 2 * a + 1 ≤ 2 * n + 1 := by linarith
199
+ have ha₃: (2 * a + 1) ∈ fs₂ := by exact mem_range_succ_iff.mpr ha₂
200
+ have ha₄: Odd (2 * a + 1) := by exact odd_two_mul_add_one a
201
+ refine mem_filter.mpr ?_
202
+ exact And.symm ⟨ha₄, ha₃⟩
203
+ . intros a _ b _ h₃
204
+ linarith
205
+ . intros b hb₀
206
+ use ((b - 1) / 2)
207
+ refine exists_prop.mpr ?_
208
+ have hb₁: b ∈ fs₂ ∧ Odd b := by exact mem_filter.mp hb₀
209
+ have hb₂: 1 ≤ b := by
210
+ by_contra! hc₀
211
+ interval_cases b
212
+ have hc₁: ¬ Odd 0 := by decide
213
+ apply hc₁ hb₁.2
214
+ have hb₃: Even (b - 1) := by
215
+ refine (Nat.even_sub hb₂).mpr ?_
216
+ simp only [not_even_one, iff_false, not_even_iff_odd]
217
+ exact hb₁.2
218
+ constructor
219
+ . have hb₄: b < 2 * n + 2 := by exact List.mem_range.mp hb₁.1
220
+ have hb₅: (b - 1) / 2 < n + 1 := by omega
221
+ exact mem_range.mpr hb₅
222
+ . have hb₆: 2 * ((b - 1) / 2) = b - 1 := by exact two_mul_div_two_of_even hb₃
223
+ rw [hb₆]
224
+ exact Nat.sub_add_cancel hb₂
225
+ . exact fun a _ => rfl
226
+ exact h₀₁
227
+ have h₁: ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x)) * k ^ (2 * x) =
228
+ ∑ x ∈ fs₁, ↑((2 * n + 1).choose (x)) * k ^ (x) := by
229
+ have h₁₁: ∑ x ∈ fs₃, f (2 * x) = ∑ x ∈ (fs₁), f x := by
230
+ refine sum_bij ?_ ?_ ?_ ?_ ?_
231
+ . intros a _
232
+ exact (2 * a)
233
+ . intros a ha₀
234
+ have ha₁: a < n + 1 := by exact List.mem_range.mp ha₀
235
+ have ha₂: 2 * a < 2 * n + 2 := by linarith
236
+ refine mem_filter.mpr ?_
237
+ constructor
238
+ . exact mem_range.mpr ha₂
239
+ . exact even_two_mul a
240
+ . intros a _ b _ h₃
241
+ exact Nat.eq_of_mul_eq_mul_left (by norm_num) h₃
242
+ . intros b hb₀
243
+ use (b/2)
244
+ refine exists_prop.mpr ?_
245
+ have hb₁: b ∈ fs₂ ∧ Even b := by exact mem_filter.mp hb₀
246
+ constructor
247
+ . have hb₂: b < 2 * n + 2 := by exact List.mem_range.mp hb₁.1
248
+ have hb₃: (b / 2) < n + 1 := by exact Nat.div_lt_of_lt_mul hb₂
249
+ exact mem_range.mpr hb₃
250
+ . exact two_mul_div_two_of_even hb₁.2
251
+ . exact fun a _ => rfl
252
+ exact h₁₁
253
+ have h₂: ∑ x ∈ range (2 * n + 1 + 1), k ^ x * ↑((2 * n + 1).choose x) =
254
+ ∑ x ∈ fs₂, ↑((2 * n + 1).choose x) * k ^ x := by
255
+ refine Finset.sum_congr (rfl) ?_
256
+ intros x _
257
+ rw [mul_comm]
258
+ rw [h₀, h₁, h₂]
259
+ have h₃: fs₂ = fs₀ ∪ fs₁ := by
260
+ refine Finset.ext_iff.mpr ?_
261
+ intro a
262
+ constructor
263
+ . intro ha₀
264
+ refine mem_union.mpr ?mp.a
265
+ have ha₁: Odd a ∨ Even a := by exact Or.symm (even_or_odd a)
266
+ cases' ha₁ with ha₂ ha₃
267
+ . left
268
+ refine mem_filter.mpr ?mp.a.inl.h.a
269
+ exact And.symm ⟨ha₂, ha₀⟩
270
+ . right
271
+ refine mem_filter.mpr ?mp.a.inl.h.b
272
+ exact And.symm ⟨ha₃, ha₀⟩
273
+ . intro ha₀
274
+ apply mem_union.mp at ha₀
275
+ cases' ha₀ with ha₁ ha₂
276
+ . exact mem_of_mem_filter a ha₁
277
+ . exact mem_of_mem_filter a ha₂
278
+ have h₄: Disjoint fs₀ fs₁ := by
279
+ refine disjoint_filter.mpr ?_
280
+ intros x _ hx₁
281
+ exact not_even_iff_odd.mpr hx₁
282
+ nth_rw 2 [add_comm]
283
+ rw [h₃, Finset.sum_union h₄]
284
+
285
+
286
+ lemma aux_5
287
+ (n b a : ℕ)
288
+ (k : ℝ)
289
+ -- (hk : k = √8)
290
+ -- (hb : b = ∑ k ∈ range (n + 1), (2 * n + 1).choose (2 * k + 1) * 2 ^ (3 * k))
291
+ -- (ha : a = ∑ k ∈ range (n + 1), (2 * n + 1).choose (2 * k) * 2 ^ (3 * k))
292
+ (hb₁ : ↑b = 1 / k * ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x + 1)) * k ^ (2 * x + 1))
293
+ (ha₁ : ↑a = ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x)) * k ^ (2 * x))
294
+ (hk₀ : k * k⁻¹ = 1) :
295
+ (1 - k) ^ (2 * n + 1) = ↑a - ↑b * k := by
296
+ rw [mul_comm _ k, hb₁, ← mul_assoc]
297
+ rw [← inv_eq_one_div, hk₀, one_mul, ha₁, sub_eq_add_neg]
298
+ rw [add_comm 1 _, add_pow (-k) 1 (2 * n + 1)]
299
+ simp
300
+ clear hb₁ ha₁ b a hk₀
301
+ let f₀ : ℕ → ℝ := fun i => ↑((2 * n + 1).choose (i)) * k ^ i
302
+ let f₁ : ℕ → ℝ := fun i => ↑((2 * n + 1).choose (i)) * (-k) ^ i
303
+ let fs₂ := Finset.range (2 * n + 2)
304
+ let fs₀ : Finset ℕ := fs₂.filter (fun x => Odd x)
305
+ let fs₁ : Finset ℕ := fs₂.filter (fun x => Even x)
306
+ let fs₃ : Finset ℕ := Finset.range (n + 1)
307
+ have h₀: ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x + 1)) * k ^ (2 * x + 1) =
308
+ - ∑ x ∈ fs₀, ↑((2 * n + 1).choose (x)) * (-k) ^ (x) := by
309
+ rw [neg_eq_neg_one_mul, Finset.mul_sum]
310
+ have h₀₁: ∑ x ∈ fs₃, f₀ (2 * x + 1) = ∑ x ∈ (fs₀), -1 * f₁ x := by
311
+ refine sum_bij ?i ?_ ?i_inj ?i_surj ?h
312
+ . intros a _
313
+ exact (2 * a + 1)
314
+ . intros a ha₀
315
+ have ha₁: a ≤ n := by exact mem_range_succ_iff.mp ha₀
316
+ have ha₂: 2 * a + 1 ≤ 2 * n + 1 := by linarith
317
+ have ha₃: (2 * a + 1) ∈ fs₂ := by exact mem_range_succ_iff.mpr ha₂
318
+ have ha₄: Odd (2 * a + 1) := by exact odd_two_mul_add_one a
319
+ refine mem_filter.mpr ?_
320
+ exact And.symm ⟨ha₄, ha₃⟩
321
+ . intros a _ b _ h₃
322
+ linarith
323
+ . intros b hb₀
324
+ use ((b - 1) / 2)
325
+ refine exists_prop.mpr ?_
326
+ have hb₁: b ∈ fs₂ ∧ Odd b := by exact mem_filter.mp hb₀
327
+ have hb₂: 1 ≤ b := by
328
+ by_contra! hc₀
329
+ interval_cases b
330
+ have hc₁: ¬ Odd 0 := by decide
331
+ apply hc₁ hb₁.2
332
+ have hb₃: Even (b - 1) := by
333
+ refine (Nat.even_sub hb₂).mpr ?_
334
+ simp only [not_even_one, iff_false, not_even_iff_odd]
335
+ exact hb₁.2
336
+ constructor
337
+ . have hb₄: b < 2 * n + 2 := by exact List.mem_range.mp hb₁.1
338
+ have hb₅: (b - 1) / 2 < n + 1 := by omega
339
+ exact mem_range.mpr hb₅
340
+ . have hb₆: 2 * ((b - 1) / 2) = b - 1 := by exact two_mul_div_two_of_even hb₃
341
+ rw [hb₆]
342
+ exact Nat.sub_add_cancel hb₂
343
+ . intros b hb₀
344
+ ring_nf
345
+ have hb₁: (-1:ℝ) ^ (b * 2) = 1 := by
346
+ refine (neg_one_pow_eq_one_iff_even (by norm_num)).mpr ?_
347
+ rw [mul_comm]
348
+ exact even_two_mul b
349
+ rw [hb₁, mul_one]
350
+ exact h₀₁
351
+ have h₁: ∑ x ∈ range (n + 1), ↑((2 * n + 1).choose (2 * x)) * k ^ (2 * x) =
352
+ ∑ x ∈ fs₁, ↑((2 * n + 1).choose (x)) * (-k) ^ (x) := by
353
+ have h₁₁: ∑ x ∈ fs₃, f₀ (2 * x) = ∑ x ∈ (fs₁), f₁ x := by
354
+ refine sum_bij ?_ ?_ ?_ ?_ ?_
355
+ . intros a _
356
+ exact (2 * a)
357
+ . intros a ha₀
358
+ have ha₁: a < n + 1 := by exact List.mem_range.mp ha₀
359
+ have ha₂: 2 * a < 2 * n + 2 := by linarith
360
+ refine mem_filter.mpr ?_
361
+ constructor
362
+ . exact mem_range.mpr ha₂
363
+ . exact even_two_mul a
364
+ . intros a _ b _ h₃
365
+ exact Nat.eq_of_mul_eq_mul_left (by norm_num) h₃
366
+ . intros b hb₀
367
+ use (b/2)
368
+ refine exists_prop.mpr ?_
369
+ have hb₁: b ∈ fs₂ ∧ Even b := by exact mem_filter.mp hb₀
370
+ constructor
371
+ . have hb₂: b < 2 * n + 2 := by exact List.mem_range.mp hb₁.1
372
+ have hb₃: (b / 2) < n + 1 := by exact Nat.div_lt_of_lt_mul hb₂
373
+ exact mem_range.mpr hb₃
374
+ . exact two_mul_div_two_of_even hb₁.2
375
+ . intros b hb₀
376
+ ring_nf
377
+ have hb₁: (-1:ℝ) ^ (b * 2) = 1 := by
378
+ refine (neg_one_pow_eq_one_iff_even (by norm_num)).mpr ?_
379
+ rw [mul_comm]
380
+ exact even_two_mul b
381
+ rw [hb₁, mul_one]
382
+ exact h₁₁
383
+ have h₂: ∑ x ∈ range (2 * n + 1 + 1), (-k) ^ x * ↑((2 * n + 1).choose x) =
384
+ ∑ x ∈ fs₂, ↑((2 * n + 1).choose x) * (-k) ^ x := by
385
+ refine Finset.sum_congr (rfl) ?_
386
+ intros x _
387
+ rw [mul_comm]
388
+ rw [h₀, h₁, h₂, sub_neg_eq_add]
389
+ have h₃: fs₂ = fs₀ ∪ fs₁ := by
390
+ refine Finset.ext_iff.mpr ?_
391
+ intro a
392
+ constructor
393
+ . intro ha₀
394
+ refine mem_union.mpr ?mp.a
395
+ have ha₁: Odd a ∨ Even a := by exact Or.symm (even_or_odd a)
396
+ cases' ha₁ with ha₂ ha₃
397
+ . left
398
+ refine mem_filter.mpr ?mp.a.inl.h.a
399
+ exact And.symm ⟨ha₂, ha₀⟩
400
+ . right
401
+ refine mem_filter.mpr ?mp.a.inl.h.b
402
+ exact And.symm ⟨ha₃, ha₀⟩
403
+ . intro ha₀
404
+ apply mem_union.mp at ha₀
405
+ cases' ha₀ with ha₁ ha₂
406
+ . exact mem_of_mem_filter a ha₁
407
+ . exact mem_of_mem_filter a ha₂
408
+ have h₄: Disjoint fs₀ fs₁ := by
409
+ refine disjoint_filter.mpr ?_
410
+ intros x _ hx₁
411
+ exact not_even_iff_odd.mpr hx₁
412
+ nth_rw 2 [add_comm]
413
+ rw [h₃, Finset.sum_union h₄]
414
+
415
+
416
+
417
+
418
+ theorem imo_1974_p3
419
+ (n : ℕ) :
420
+ ¬ 5 ∣ ∑ k ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k)) := by
421
+ let k:ℝ := Real.sqrt (8:ℝ)
422
+ have hk: k = Real.sqrt (8:ℝ) := by rfl
423
+ let b:ℕ := ∑ k ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k))
424
+ have hb: b = ∑ k ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k)) := by rfl
425
+ rw [← hb]
426
+ let a:ℕ := ∑ k ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * k) * (2 ^ (3 * k)))
427
+ have ha: a = ∑ k ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * k) * (2 ^ (3 * k))) := by rfl
428
+ have hb₁: b = (1 / k) *
429
+ ∑ x ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * x + 1)) * (k ^ (2 * x + 1)) := by
430
+ rw [hb, hk]
431
+ simp
432
+ rw [Finset.mul_sum]
433
+ refine Finset.sum_congr (rfl) ?_
434
+ intros x _
435
+ rw [mul_comm ((√8)⁻¹), mul_assoc]
436
+ refine mul_eq_mul_left_iff.mpr ?_
437
+ left
438
+ rw [pow_succ, pow_mul, pow_mul, Real.sq_sqrt (by norm_num)]
439
+ norm_num
440
+ have ha₁: a = ∑ x ∈ Finset.range (n + 1), (Nat.choose (2 * n + 1) (2 * x) * (k ^ (2 * x))) := by
441
+ rw [ha, hk]
442
+ simp
443
+ refine Finset.sum_congr (rfl) ?_
444
+ intros x _
445
+ refine mul_eq_mul_left_iff.mpr ?_
446
+ left
447
+ rw [pow_mul, pow_mul, Real.sq_sqrt (by norm_num)]
448
+ norm_num
449
+ have hk₀: k * k⁻¹ = 1 := by
450
+ refine (mul_inv_eq_one₀ ?_).mpr (rfl)
451
+ rw [hk]
452
+ norm_num
453
+ have h₀: (1 + k) ^ (2 * n + 1) = a + b * k := by
454
+ exact aux_4 n b a k hb₁ ha₁ hk₀
455
+ have h₁: (1 - k) ^ (2 * n + 1) = a - b * k := by
456
+ exact aux_5 n b a k hb₁ ha₁ hk₀
457
+ have h₂: ((1 + k) * (1 - k)) ^ (2 * n + 1) = (a + b * k) * (a - b * k) := by
458
+ rw [mul_pow, h₀, h₁]
459
+ rw [← sq_sub_sq 1 k] at h₂
460
+ rw [← sq_sub_sq (↑a) ((↑b:ℝ) * k)] at h₂
461
+ rw [mul_pow, hk] at h₂
462
+ norm_num at h₂
463
+ have h₃: (7:ℕ) ^ (2 * n + 1) = b ^ 2 * 8 - a ^ 2 := by
464
+ have h₃₀: Odd (2 * n + 1) := by exact odd_two_mul_add_one n
465
+ have h₃₁: (-7:ℝ) = (-1:ℝ) * (7:ℕ) := by norm_num
466
+ have h₃₂: (-1:ℝ) ^ (2 * n + 1) = -1 := by exact Odd.neg_one_pow h₃₀
467
+ have h₃₃: ↑a ^ 2 - ↑b ^ 2 * 8 = (-1:ℝ) * (↑b ^ 2 * 8 - ↑a ^ 2) := by
468
+ linarith
469
+ rw [h₃₁, mul_pow, h₃₂, h₃₃] at h₂
470
+ simp at h₂
471
+ have h₃₄: (7:ℝ) ^ (2 * n + 1) = ↑b ^ 2 * 8 - ↑a ^ 2 := by
472
+ linarith
473
+ norm_cast at h₃₄
474
+ rw [Int.subNatNat_eq_coe] at h₃₄
475
+ rw [← Int.toNat_sub, ← h₃₄]
476
+ exact rfl
477
+ have h₄: 7 ^ (2 * n + 1) ≡ 2 [MOD 5] ∨ 7 ^ (2 * n + 1) ≡ 3 [MOD 5] := by
478
+ refine aux_3 n
479
+ by_contra! hc₀
480
+ have hc₁: b^2 * 8 ≡ 0^2 * 8 [MOD 5] := by
481
+ refine ModEq.mul ?_ rfl
482
+ refine ModEq.pow 2 ?_
483
+ exact modEq_zero_iff_dvd.mpr hc₀
484
+ simp at hc₁
485
+ have h₅: a ^ 2 < b ^ 2 * 8 := by
486
+ have h₅₀: 0 < 7 ^ (2 * n + 1) := by
487
+ exact Nat.pow_pos (by norm_num)
488
+ rw [h₃] at h₅₀
489
+ exact Nat.lt_of_sub_pos h₅₀
490
+ cases' h₄ with h₄₀ h₄₁
491
+ . rw [h₃] at h₄₀
492
+ have hc₂: b ^ 2 * 8 - a ^ 2 + a ^ 2 ≡ 2 + a ^ 2 [MOD 5] := by
493
+ exact ModEq.add_right (a ^ 2) h₄₀
494
+ rw [Nat.sub_add_cancel (le_of_lt h₅)] at hc₂
495
+ have hc₃: 3 + (2 + a ^ 2) ≡ 3 [MOD 5] := by
496
+ apply Nat.ModEq.trans hc₂.symm at hc₁
497
+ exact ModEq.add_left 3 hc₁
498
+ have hc₄: a ^ 2 ≡ 3 [MOD 5] := by
499
+ rw [← add_assoc, ← zero_add 3] at hc₃
500
+ norm_num at hc₃
501
+ have hc₄: 5 ≡ 0 [MOD 5] := by decide
502
+ exact Nat.ModEq.add_left_cancel hc₄ hc₃
503
+ have hc₅: ¬ a ^ 2 ≡ 3 [MOD 5] := by exact aux_2 a
504
+ exact hc₅ hc₄
505
+ . rw [h₃] at h₄₁
506
+ have hc₂: b ^ 2 * 8 - a ^ 2 + a ^ 2 ≡ 3 + a ^ 2 [MOD 5] := by
507
+ exact ModEq.add_right (a ^ 2) h₄₁
508
+ rw [Nat.sub_add_cancel (le_of_lt h₅)] at hc₂
509
+ apply Nat.ModEq.trans hc₂.symm at hc₁
510
+ have hc₃: a ^ 2 ≡ 2 [MOD 5] := by
511
+ refine Nat.ModEq.add_left_cancel' 3 ?_
512
+ exact hc₁
513
+ have hc₄: ¬ a ^ 2 ≡ 2 [MOD 5] := by exact aux_1 a
514
+ exact hc₄ hc₃
imo_proofs/imo_1981_p6.lean ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+
5
+ open Nat
6
+
7
+ theorem imo_1981_p6
8
+ (f : ℕ → ℕ → ℕ)
9
+ (h₀ : ∀ y, f 0 y = y + 1)
10
+ (h₁ : ∀ x, f (x + 1) 0 = f x 1)
11
+ (h₂ : ∀ x y, f (x + 1) (y + 1) = f x (f (x + 1) y)) :
12
+ ∀ y, f 4 (y + 1) = 2 ^ (f 4 y + 3) - 3 := by
13
+ have h₃: ∀ y, f 1 y = y + 2 := by
14
+ intro y
15
+ induction' y with n hn
16
+ . simp_all only [zero_eq, zero_add]
17
+ . nth_rw 1 [← zero_add 1]
18
+ rw [h₂ 0 n, h₀ (f (0 + 1) n), hn]
19
+ have h₄: ∀ y, f 2 y = 2 * y + 3 := by
20
+ intro y
21
+ induction' y with n hn
22
+ . simp_all only [zero_eq, zero_add, mul_zero]
23
+ . rw [h₂, h₃, hn, mul_add]
24
+ have h₅: ∀ y, f 3 y = 2 ^ (y + 3) - 3 := by
25
+ intro y
26
+ induction' y with n hn
27
+ . simp_all only [zero_eq, zero_add, mul_zero]
28
+ omega
29
+ . rw [h₂, h₄, hn]
30
+ rw [Nat.mul_sub_left_distrib]
31
+ ring_nf
32
+ by_cases hn₀: 0 < n
33
+ . rw [← Nat.add_sub_assoc, add_comm]
34
+ . omega
35
+ . have hn₂: 2 ^ 1 ≤ 2 ^ n := by exact Nat.pow_le_pow_of_le (by norm_num) hn₀
36
+ linarith
37
+ . have hn₁: n = 0 := by linarith
38
+ rw [hn₁]
39
+ omega
40
+ intro y
41
+ induction' y with n hn
42
+ . simp
43
+ rw [h₂, h₁, h₅]
44
+ . rw [hn, h₂, h₅, h₂, h₅]
imo_proofs/imo_1982_p1.lean ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+
5
+ open Nat
6
+
7
+ theorem imo_1982_p1
8
+ (f : ℕ → ℤ)
9
+ (h₀ : ∀ m n, (0 < m ∧ 0 < n) → f (m + n) - f m - f n = 0 ∨ f (m + n) - f m - f n = 1)
10
+ (h₁ : f 2 = 0)
11
+ (h₂ : 0 < f 3)
12
+ (h₃ : f 9999 = 3333) :
13
+ f 1982 = 660 := by
14
+ have h₀₀: ∀ m n, (0 < m ∧ 0 < n) → f m + f n ≤ f (m + n) := by
15
+ intros m n hmn
16
+ have g₀: f (m + n) - f m - f n = 0 ∨ f (m + n) - f m - f n = 1 := by
17
+ exact h₀ m n hmn
18
+ omega
19
+ have h₀₁: ∀ m k, (0 < m ∧ 0 < k) → k * f m ≤ f (k * m) := by
20
+ intros m k hmk
21
+ have g₁: 1 ≤ k := by linarith
22
+ refine Nat.le_induction ?_ ?_ k g₁
23
+ . simp
24
+ . intros n hmn g₂
25
+ rw [cast_add]
26
+ rw [add_mul, add_mul, one_mul]
27
+ simp
28
+ have g₃: f (n * m) + f (m) ≤ f (n * m + m) := by
29
+ refine h₀₀ (n * m) m ?_
30
+ constructor
31
+ . refine mul_pos ?_ hmk.1
32
+ exact hmn
33
+ . exact hmk.1
34
+ refine le_trans ?_ g₃
35
+ exact (Int.add_le_add_iff_right (f m)).mpr g₂
36
+ have h₄: f 3 = 1 := by
37
+ have g₀ : 3333 * f 3 ≤ f (9999) := by
38
+ refine h₀₁ 3 3333 ?_
39
+ omega
40
+ linarith
41
+ have h₅: f 1980 = 660 := by
42
+ have h₅₀: f 1980 ≤ 660 := by
43
+ have g₀ : f (5 * 1980) + f 99 ≤ f (9999) := by
44
+ refine h₀₀ (5 * 1980) 99 (by omega)
45
+ have g₁: 5 * f (1980) ≤ f (5 * 1980) := by
46
+ exact h₀₁ 1980 5 (by omega)
47
+ have g₂: 33 * f 3 ≤ f 99 := by
48
+ exact h₀₁ 3 33 (by omega)
49
+ rw [h₃] at g₀
50
+ linarith
51
+ have h₅₁: 660 ≤ f 1980 := by
52
+ have g₀ : 660 * f 3 ≤ f (1980) := by
53
+ refine h₀₁ 3 660 ?_
54
+ omega
55
+ rw [h₄] at g₀
56
+ exact g₀
57
+ exact le_antisymm h₅₀ h₅₁
58
+ have h₆: f 1982 - f 1980 - f 2 = 0 ∨ f 1982 - f 1980 - f 2 = 1 := by
59
+ refine h₀ 1980 2 ?_
60
+ omega
61
+ cases' h₆ with h₆₀ h₆₁
62
+ . linarith
63
+ . exfalso
64
+ rw [h₅, h₁] at h₆₁
65
+ have h₆₂: f 1982 = 661 := by
66
+ linarith
67
+ have h₆₃: 5 * f 1982 + 29 ≤ 3333 := by
68
+ have g₀ : f (5 * 1982) + f 89 ≤ f 9999 := by
69
+ refine h₀₀ (5 * 1982) 89 (by omega)
70
+ have g₁: f (29 * 3) + f 2 ≤ f 89 := by
71
+ refine h₀₀ (29 * 3) 2 (by omega)
72
+ have g₂: 5 * f (1982) ≤ f (5 * 1982) := by
73
+ exact h₀₁ 1982 5 (by omega)
74
+ have g₃: 29 * f 3 ≤ f (87) := by
75
+ exact h₀₁ 3 29 (by omega)
76
+ linarith
77
+ rw [h₆₂] at h₆₃
78
+ linarith
imo_proofs/imo_1983_p6.lean ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Real
5
+
6
+ lemma mylemma_1
7
+ (a b c : ℝ)
8
+ (x y z : ℝ)
9
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
10
+ (h₂: c ≤ b ∧ b ≤ a)
11
+ (h₃: z ≤ y ∧ y ≤ x) :
12
+ a * z + c * y + b * x ≤ c * z + b * y + a * x := by
13
+ suffices h₄: c * (y - z) + b * (x - y) ≤ a * (x - z)
14
+ . linarith
15
+ . have h₅: c * (y - z) + b * (x - y) ≤ b * (y - z) + b * (x - y) := by
16
+ simp
17
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
18
+ . exact le_rfl
19
+ . exact sub_nonneg_of_le h₃.1
20
+ . exact le_of_lt h₀.2.1
21
+ refine le_trans h₅ ?_
22
+ rw [mul_sub, mul_sub, add_comm]
23
+ rw [← add_sub_assoc, sub_add_cancel]
24
+ rw [← mul_sub]
25
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
26
+ . exact le_rfl
27
+ . refine sub_nonneg_of_le ?_
28
+ exact le_trans h₃.1 h₃.2
29
+ . exact le_of_lt h₀.1
30
+
31
+
32
+ lemma mylemma_2
33
+ (a b c : ℝ)
34
+ (x y z : ℝ)
35
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
36
+ (h₂: c ≤ b ∧ b ≤ a)
37
+ (h₃: z ≤ y ∧ y ≤ x) :
38
+ b * z + a * y + c * x ≤ c * z + b * y + a * x := by
39
+ suffices h₄: c * (x - z) + b * (z - y) ≤ a * (x - y)
40
+ . linarith
41
+ . have h₅: c * (x - z) + b * (z - y) ≤ b * (x - z) + b * (z - y) := by
42
+ simp
43
+ refine mul_le_mul h₂.1 ?_ ?_ ?_
44
+ . exact le_rfl
45
+ . refine sub_nonneg_of_le ?_
46
+ exact le_trans h₃.1 h₃.2
47
+ . exact le_of_lt h₀.2.1
48
+ refine le_trans h₅ ?_
49
+ rw [mul_sub, mul_sub]
50
+ rw [← add_sub_assoc, sub_add_cancel]
51
+ rw [← mul_sub]
52
+ refine mul_le_mul h₂.2 ?_ ?_ ?_
53
+ . exact le_rfl
54
+ . exact sub_nonneg_of_le h₃.2
55
+ . exact le_of_lt h₀.1
56
+
57
+
58
+ -- case #1
59
+ lemma mylemma_cba
60
+ (a b c : ℝ)
61
+ (hap : 0 < a )
62
+ (hbp : 0 < b )
63
+ (hcp : 0 < c )
64
+ (h₁ : c < a + b)
65
+ -- (h₂ : b < a + c)
66
+ (h₃ : a < b + c)
67
+ (hba: b ≤ a)
68
+ (hcb: c ≤ b) :
69
+ 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a) := by
70
+ have g₀: b * c ≤ a * c := by exact (mul_le_mul_iff_of_pos_right hcp).mpr hba
71
+ have g₁: a * c ≤ a * b := by exact (mul_le_mul_iff_of_pos_left hap).mpr hcb
72
+ have g₂: a * (b + c - a) ≤ b * (a + c - b) := by
73
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
74
+ refine mul_nonneg ?_ ?_
75
+ . exact sub_nonneg_of_le hba
76
+ . refine le_of_lt ?_
77
+ exact sub_pos.mpr h₁
78
+ linarith
79
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
80
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
81
+ refine mul_nonneg ?_ ?_
82
+ . exact sub_nonneg_of_le hcb
83
+ . refine le_of_lt ?_
84
+ exact sub_pos.mpr h₃
85
+ linarith
86
+ have g₄: (a * b) * (a * (b + c - a)) + (b * c) * (b * (a + c - b)) + (a * c) * (c * (a + b - c))
87
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
88
+ refine mylemma_1 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
89
+ . constructor
90
+ . exact mul_pos hap hbp
91
+ . constructor
92
+ . exact mul_pos hap hcp
93
+ . exact mul_pos hbp hcp
94
+ . exact { left := g₀, right := g₁ }
95
+ . exact { left := g₂, right := g₃ }
96
+ linarith
97
+
98
+
99
+ -- tight version
100
+ lemma mylemma_cba_tight
101
+ (a b c : ℝ)
102
+ (hap : 0 < a )
103
+ (hbp : 0 < b )
104
+ (hcp : 0 < c )
105
+ (h₁ : c < a + b)
106
+ -- (h₂ : b < a + c)
107
+ (h₃ : a < b + c)
108
+ (hba: b ≤ a)
109
+ (hcb: c ≤ b) :
110
+ 0 ≤ a^2 * c * (a - c) + c^2 * b * (c - b) + b^2 * a * (b - a) := by
111
+ have g₀: b * c ≤ a * c := by exact (mul_le_mul_iff_of_pos_right hcp).mpr hba
112
+ have g₁: a * c ≤ a * b := by exact (mul_le_mul_iff_of_pos_left hap).mpr hcb
113
+ have g₂: a * (b + c - a) ≤ b * (a + c - b) := by
114
+ have g₂₁: 0 ≤ (a-b) * (a+b-c) := by
115
+ refine mul_nonneg ?_ ?_
116
+ . exact sub_nonneg_of_le hba
117
+ . refine le_of_lt ?_
118
+ exact sub_pos.mpr h₁
119
+ linarith
120
+ have g₃: b * (a + c - b) ≤ c * (a + b - c) := by
121
+ have g₃₁: 0 ≤ (b - c) * (b + c - a) := by
122
+ refine mul_nonneg ?_ ?_
123
+ . exact sub_nonneg_of_le hcb
124
+ . refine le_of_lt ?_
125
+ exact sub_pos.mpr h₃
126
+ linarith
127
+ have g₄: (a * c) * (a * (b + c - a)) + (a * b) * (b * (a + c - b)) + (b * c) * (c * (a + b - c))
128
+ ≤ (b * c) * (a * (b + c - a)) + (a * c) * (b * (a + c - b)) + (a * b) * (c * (a + b - c)) := by
129
+ refine mylemma_2 (a * b) (a * c) (b * c) (c * (a + b - c)) (b * (a + c - b)) (a * (b + c - a)) ?_ ?_ ?_
130
+ . constructor
131
+ . exact mul_pos hap hbp
132
+ . constructor
133
+ . exact mul_pos hap hcp
134
+ . exact mul_pos hbp hcp
135
+ . exact { left := g₀, right := g₁ }
136
+ . exact { left := g₂, right := g₃ }
137
+ linarith
138
+
139
+
140
+ theorem imo_1983_p6
141
+ (a b c : ℝ)
142
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c)
143
+ (h₁ : c < a + b)
144
+ (h₂ : b < a + c)
145
+ (h₃ : a < b + c) :
146
+ 0 ≤ a^2 * b * (a - b) + b^2 * c * (b - c) + c^2 * a * (c - a) := by
147
+ wlog ho₀: b ≤ a generalizing a b c
148
+ . clear this
149
+ push_neg at ho₀
150
+ wlog ho₁: c ≤ b generalizing a b c
151
+ . clear this
152
+ push_neg at ho₁ -- a < b < c
153
+ rw [add_comm] at h₁ h₂ h₃
154
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
155
+ exact mylemma_cba_tight c b a h₀.2.2 h₀.2.1 h₀.1 h₃ h₁ (le_of_lt ho₁) (le_of_lt ho₀)
156
+ linarith
157
+ . wlog ho₂: c ≤ a generalizing a b c
158
+ . clear this -- a < c ≤ b
159
+ push_neg at ho₂
160
+ rw [add_comm] at h₁ h₂
161
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
162
+ exact mylemma_cba b c a h₀.2.1 h₀.2.2 h₀.1 h₃ h₂ ho₁ (le_of_lt ho₂)
163
+ linarith
164
+ . -- c ≤ a < b
165
+ rw [add_comm] at h₁
166
+ have g₀: 0 ≤ b ^ 2 * c * (b - c) + c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) := by
167
+ exact mylemma_cba_tight b a c h₀.2.1 h₀.1 h₀.2.2 h₁ h₂ (le_of_lt ho₀) ho₂
168
+ linarith
169
+ . wlog ho₁: c ≤ b generalizing a b c
170
+ . clear this
171
+ push_neg at ho₁
172
+ wlog ho₂: c ≤ a generalizing a b c
173
+ . clear this
174
+ push_neg at ho₂ -- b < a < c
175
+ rw [add_comm] at h₂ h₃
176
+ have g₀: 0 ≤ c ^ 2 * a * (c - a) + a ^ 2 * b * (a - b) + b ^ 2 * c * (b - c) := by
177
+ exact mylemma_cba c a b h₀.2.2 h₀.1 h₀.2.1 h₂ h₁ (le_of_lt ho₂) ho₀
178
+ linarith
179
+ . rw [add_comm] at h₃
180
+ exact mylemma_cba_tight a c b h₀.1 h₀.2.2 h₀.2.1 h₂ h₃ ho₂ (le_of_lt ho₁)
181
+ . exact mylemma_cba a b c h₀.1 h₀.2.1 h₀.2.2 h₁ h₃ ho₀ ho₁
imo_proofs/imo_1984_p6.lean ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat
5
+
6
+
7
+ lemma mylemma_sub_sq
8
+ (a b : ℕ)
9
+ (h₀: b < a) :
10
+ ((a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b) := by
11
+ have h₁: b^2 ≤ a * b := by
12
+ rw [pow_two]
13
+ refine Nat.mul_le_mul_right ?_ ?_
14
+ exact Nat.le_of_lt h₀
15
+ have h₂: a * b ≤ a ^ 2 := by
16
+ rw [pow_two]
17
+ refine Nat.mul_le_mul_left ?_ ?_
18
+ exact Nat.le_of_lt h₀
19
+ repeat rw [pow_two]
20
+ repeat rw [Nat.mul_sub_left_distrib]
21
+ repeat rw [Nat.mul_sub_right_distrib a b a]
22
+ rw [Nat.sub_right_comm]
23
+ repeat rw [Nat.mul_sub_right_distrib a b b]
24
+ ring_nf
25
+ have h₃: a ^ 2 - (a * b - b ^ 2) = a ^ 2 - a * b + b ^ 2 := by
26
+ refine tsub_tsub_assoc ?h₁ h₁
27
+ exact h₂
28
+ rw [h₃]
29
+ rw [← Nat.sub_add_comm h₂]
30
+ . rw [← Nat.sub_add_eq, ← mul_two]
31
+
32
+
33
+ lemma mylemma_k_le_m_alt
34
+ (a b c d k m : ℕ)
35
+ (h₂ : a < b ∧ b < c ∧ c < d)
36
+ (h₃ : a * d = b * c)
37
+ (h₄ : a + d = 2 ^ k)
38
+ (h₅ : b + c = 2 ^ m)
39
+ (hkm : k ≤ m) :
40
+ False := by
41
+ have h₆: (a + d) ^ 2 ≤ (b + c) ^ 2 := by
42
+ refine Nat.pow_le_pow_of_le_left ?_ 2
43
+ rw [h₄,h₅]
44
+ exact pow_le_pow_right₀ (by norm_num) hkm
45
+ rw [add_sq, add_sq, mul_assoc, h₃, mul_assoc] at h₆
46
+ have h₇: (d - a) ^ 2 ≤ (c - b) ^ 2 := by
47
+ have hda: a < d := by
48
+ refine lt_trans h₂.1 ?_
49
+ exact lt_trans h₂.2.1 h₂.2.2
50
+ rw [mylemma_sub_sq d a hda]
51
+ rw [mylemma_sub_sq c b h₂.2.1]
52
+ rw [mul_assoc, mul_assoc]
53
+ rw [mul_comm d a, mul_comm c b]
54
+ rw [h₃]
55
+ refine Nat.sub_le_sub_right ?_ (2 * (b * c))
56
+ linarith
57
+ have h₈: (c - b) ^ 2 < (d - a) ^ 2 := by
58
+ refine Nat.pow_lt_pow_left ?_ (by norm_num)
59
+ have h₈₀: c - a < d - a := by
60
+ have g₀: c - a + a < d - a + a := by
61
+ rw [Nat.sub_add_cancel ?_]
62
+ rw [Nat.sub_add_cancel ?_]
63
+ . exact h₂.2.2
64
+ . linarith
65
+ . linarith
66
+ exact Nat.lt_of_add_lt_add_right g₀
67
+ refine lt_trans ?_ h₈₀
68
+ refine Nat.sub_lt_sub_left ?_ h₂.1
69
+ exact lt_trans h₂.1 h₂.2.1
70
+ have h₉: (d - a) ^ 2 ≠ (d - a) ^ 2 := by
71
+ refine Nat.ne_of_lt ?_
72
+ exact lt_of_le_of_lt h₇ h₈
73
+ refine false_of_ne h₉
74
+
75
+
76
+
77
+
78
+ lemma mylemma_k_le_m
79
+ (a b c d k m : ℕ)
80
+ (h₂ : a < b ∧ b < c ∧ c < d)
81
+ (h₃ : a * d = b * c)
82
+ (h₄ : a + d = 2 ^ k)
83
+ (h₅ : b + c = 2 ^ m) :
84
+ (m < k) := by
85
+ have h₆: (c - b) ^ 2 < (d - a) ^ 2 := by
86
+ refine Nat.pow_lt_pow_left ?_ (by norm_num)
87
+ have h₈₀: c - a < d - a := by
88
+ have g₀: c - a + a < d - a + a := by
89
+ rw [Nat.sub_add_cancel ?_]
90
+ rw [Nat.sub_add_cancel ?_]
91
+ . exact h₂.2.2
92
+ . linarith
93
+ . linarith
94
+ exact Nat.lt_of_add_lt_add_right g₀
95
+ refine lt_trans ?_ h₈₀
96
+ refine Nat.sub_lt_sub_left ?_ h₂.1
97
+ exact lt_trans h₂.1 h₂.2.1
98
+ have h₇: (b + c) ^ 2 < (a + d) ^ 2 := by
99
+ rw [add_sq b c, add_sq a d]
100
+ have hda: a < d := by
101
+ refine lt_trans h₂.1 ?_
102
+ exact lt_trans h₂.2.1 h₂.2.2
103
+ rw [mylemma_sub_sq d a hda] at h₆
104
+ rw [mylemma_sub_sq c b h₂.2.1] at h₆
105
+ rw [mul_assoc 2 b c, ← h₃, ← mul_assoc]
106
+ rw [mul_assoc 2 c b, mul_comm c b, ← h₃, ← mul_assoc] at h₆
107
+ rw [add_assoc, add_comm _ (c ^ 2), ← add_assoc]
108
+ rw [add_assoc (a ^ 2), add_comm _ (d ^ 2), ← add_assoc]
109
+ rw [mul_assoc 2 d a, mul_comm d a, ← mul_assoc] at h₆
110
+ rw [add_comm (d ^ 2) (a ^ 2)] at h₆
111
+ rw [add_comm (c ^ 2) (b ^ 2)] at h₆
112
+ have g₀: 2 * a * d ≤ 4 * a * d := by
113
+ ring_nf
114
+ exact Nat.mul_le_mul_left (a * d) (by norm_num)
115
+ have g₁: 2 * a * d = 4 * a * d - 2 * a * d := by
116
+ ring_nf
117
+ rw [← Nat.mul_sub_left_distrib]
118
+ norm_num
119
+ have g₂: 2 * a * d ≤ b ^ 2 + c ^ 2 := by
120
+ rw [mul_assoc, h₃, ← mul_assoc]
121
+ exact two_mul_le_add_sq b c
122
+ have g₃: 2 * a * d ≤ a ^ 2 + d ^ 2 := by
123
+ exact two_mul_le_add_sq a d
124
+ rw [g₁, ← Nat.add_sub_assoc (g₀) (b ^ 2 + c ^ 2)]
125
+ rw [← Nat.add_sub_assoc (g₀) (a ^ 2 + d ^ 2)]
126
+ rw [Nat.sub_add_comm g₂, Nat.sub_add_comm g₃]
127
+ exact (Nat.add_lt_add_iff_right).mpr h₆
128
+ have h2 : 1 < 2 := by norm_num
129
+ refine (Nat.pow_lt_pow_iff_right h2).mp ?_
130
+ rw [← h₄, ← h₅]
131
+ exact (Nat.pow_lt_pow_iff_left (by norm_num) ).mp h₇
132
+
133
+
134
+
135
+ lemma mylemma_h8
136
+ (a b c d k m : ℕ)
137
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
138
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
139
+ (h₂ : a < b ∧ b < c ∧ c < d)
140
+ (h₅ : b + c = 2 ^ m)
141
+ (hkm : m < k)
142
+ (h₆ : b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a))
143
+ (h₇ : 2 ^ m ∣ (b - a) * (b + a)) :
144
+ (b + a = 2 ^ (m - 1)) := by
145
+ have h₇₁: ∃ y z, y ∣ b - a ∧ z ∣ b + a ∧ y * z = 2 ^ m := by
146
+ exact Nat.dvd_mul.mp h₇
147
+ let ⟨p, q, hpd⟩ := h₇₁
148
+ cases' hpd with hpd hqd
149
+ cases' hqd with hqd hpq
150
+ have hm1: 1 ≤ m := by
151
+ by_contra! hc
152
+ interval_cases m
153
+ linarith
154
+ have h₈₀: b - a < 2 ^ (m - 1) := by
155
+ have g₀: b < (b + c) / 2 := by
156
+ refine (Nat.lt_div_iff_mul_lt' ?_ b).mpr ?_
157
+ . refine even_iff_two_dvd.mp ?_
158
+ exact Odd.add_odd h₁.2.1 h₁.2.2.1
159
+ . linarith
160
+ have g₁: (b + c) / 2 = 2 ^ (m-1) := by
161
+ rw [h₅]
162
+ rw [← Nat.pow_sub_mul_pow 2 hm1]
163
+ simp
164
+ rw [← g₁]
165
+ refine lt_trans ?_ g₀
166
+ exact Nat.sub_lt h₀.2.1 h₀.1
167
+ have hp: p = 2 := by
168
+ have hp₀: 2 * b < 2 ^ m := by
169
+ rw [← h₅, two_mul]
170
+ exact Nat.add_lt_add_left h₂.2.1 b
171
+ have hp₁: b + a < 2 ^ (m) := by
172
+ have g₀: b + a < b + b := by
173
+ exact Nat.add_lt_add_left h₂.1 b
174
+ refine Nat.lt_trans g₀ ?_
175
+ rw [← two_mul]
176
+ exact hp₀
177
+ have hp₂: q < 2 ^ m := by
178
+ refine Nat.lt_of_le_of_lt (Nat.le_of_dvd ?_ hqd) hp₁
179
+ exact Nat.add_pos_right b h₀.1
180
+ have hp₃: 1 < p := by
181
+ rw [← hpq] at hp₂
182
+ exact one_lt_of_lt_mul_left hp₂
183
+ have h2prime: Nat.Prime 2 := by exact prime_two
184
+ have hp₅: ∀ i j:ℕ , 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (i < 2 ∨ j < 2) := by
185
+ by_contra! hc
186
+ let ⟨i, j, hi⟩ := hc
187
+ have hti: 2 ^ 2 ∣ 2 ^ i := by exact Nat.pow_dvd_pow 2 hi.2.1
188
+ have htj: 2 ^ 2 ∣ 2 ^ j := by exact Nat.pow_dvd_pow 2 hi.2.2
189
+ norm_num at hti htj
190
+ have hi₄: 4 ∣ b - a := by exact Nat.dvd_trans hti hi.1.1
191
+ have hi₅: 4 ∣ b + a := by exact Nat.dvd_trans htj hi.1.2
192
+ have hi₆: 4 ∣ (b - a) + (b + a) := by exact Nat.dvd_add hi₄ hi₅
193
+ have hi₇: 2 ∣ b := by
194
+ have g₀: 0 < 2 := by norm_num
195
+ refine Nat.dvd_of_mul_dvd_mul_left g₀ ?_
196
+ rw [← Nat.add_sub_cancel (2 * b) a, Nat.two_mul b]
197
+ rw [add_assoc, Nat.sub_add_comm (le_of_lt h₂.1)]
198
+ exact hi₆
199
+ have hi₈: Even b := by
200
+ exact even_iff_two_dvd.mpr hi₇
201
+ apply Nat.not_odd_iff_even.mpr hi₈
202
+ exact h₁.2.1
203
+ have hp₆: ∀ i j:ℕ , i + j = m ∧ 2 ^ i ∣ (b - a) ∧ 2 ^ j ∣ (b + a) → (¬ j < 2) := by
204
+ by_contra! hc
205
+ let ⟨i, j, hi⟩ := hc
206
+ have hi₀: m - 1 ≤ i := by
207
+ rw [← hi.1.1]
208
+ simp
209
+ exact Nat.le_pred_of_lt hi.2
210
+ have hi₁: 2 ^ (m - 1) ≤ 2 ^ i := by exact Nat.pow_le_pow_right (by norm_num) hi₀
211
+ have hi₂: 2 ^ i < 2 ^ (m - 1) := by
212
+ refine lt_of_le_of_lt ?_ h₈₀
213
+ refine Nat.le_of_dvd ?_ hi.1.2.1
214
+ exact Nat.sub_pos_of_lt h₂.1
215
+ linarith [hi₁, hi₂]
216
+ have hi₀: ∃ i ≤ m, p = 2 ^ i := by
217
+ have g₀: p ∣ 2 ^ m := by
218
+ rw [← hpq]
219
+ exact Nat.dvd_mul_right p q
220
+ exact (Nat.dvd_prime_pow h2prime).mp g₀
221
+ let ⟨i, hp⟩ := hi₀
222
+ cases' hp with him hp
223
+ let j:ℕ := m - i
224
+ have hj₀: j = m - i := by linarith
225
+ have hj₁: i + j = m := by
226
+ rw [add_comm, ← Nat.sub_add_cancel him]
227
+ have hq: q = 2 ^ j := by
228
+ rw [hp] at hpq
229
+ rw [hj₀, ← Nat.pow_div him (by norm_num)]
230
+ refine Nat.eq_div_of_mul_eq_right ?_ hpq
231
+ refine Nat.ne_of_gt ?_
232
+ rw [← hp]
233
+ linarith [hp₃]
234
+ rw [hp] at hpd
235
+ rw [hq] at hqd
236
+ have hj₃: ¬ j < 2 := by
237
+ exact hp₆ i j {left:= hj₁ , right:= { left := hpd , right:= hqd} }
238
+ have hi₂: i < 2 := by
239
+ have g₀: i < 2 ∨ j < 2 := by
240
+ exact hp₅ i j { left := hpd , right:= hqd }
241
+ omega
242
+ have hi₃: 0 < i := by
243
+ rw [hp] at hp₃
244
+ refine Nat.zero_lt_of_ne_zero ?_
245
+ exact (Nat.one_lt_two_pow_iff).mp hp₃
246
+ have hi₄: i = 1 := by
247
+ interval_cases i
248
+ rfl
249
+ rw [hi₄] at hp
250
+ exact hp
251
+ have hq: q = 2 ^ (m - 1) := by
252
+ rw [hp, ← Nat.pow_sub_mul_pow 2 hm1, pow_one, mul_comm] at hpq
253
+ exact Nat.mul_right_cancel (by norm_num) hpq
254
+ rw [hq] at hqd
255
+ have h₈₂: ∃ c, (b + a) = c * 2 ^ (m - 1) := by
256
+ exact exists_eq_mul_left_of_dvd hqd
257
+ let ⟨f, hf⟩ := h₈₂
258
+ have hfeq1: f = 1 := by
259
+ have hf₀: f * 2 ^ (m - 1) < 2 * 2 ^ (m - 1) := by
260
+ rw [← hf, ← Nat.pow_succ', ← Nat.succ_sub hm1]
261
+ rw [Nat.succ_sub_one, ← h₅]
262
+ refine Nat.add_lt_add_left ?_ b
263
+ exact lt_trans h₂.1 h₂.2.1
264
+ have hf₁: f < 2 := by
265
+ exact Nat.lt_of_mul_lt_mul_right hf₀
266
+ interval_cases f
267
+ . simp at hf
268
+ exfalso
269
+ linarith [hf]
270
+ . linarith
271
+ rw [hfeq1, one_mul] at hf
272
+ exact hf
273
+
274
+
275
+
276
+
277
+ theorem imo_1984_p6
278
+ (a b c d k m : ℕ)
279
+ (h₀ : 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d)
280
+ (h₁ : Odd a ∧ Odd b ∧ Odd c ∧ Odd d)
281
+ (h₂ : a < b ∧ b < c ∧ c < d)
282
+ (h₃ : a * d = b * c)
283
+ (h₄ : a + d = (2:ℕ)^k)
284
+ (h₅ : b + c = 2^m) :
285
+ a = 1 := by
286
+ by_cases hkm: k ≤ m
287
+ . exfalso
288
+ apply Nat.not_lt_of_le at hkm
289
+ rw [← not_true_eq_false]
290
+ refine (not_congr ?_).mp hkm
291
+ refine iff_true_intro ?_
292
+ exact mylemma_k_le_m a b c d k m h₂ h₃ h₄ h₅
293
+ . push_neg at hkm
294
+ have h₆: b * 2 ^ m - a * 2 ^ k = (b - a) * (b + a) := by
295
+ have h₆₀: c = 2 ^ m - b := by exact (tsub_eq_of_eq_add_rev (id h₅.symm)).symm
296
+ have h₆₁: d = 2 ^ k - a := by exact (tsub_eq_of_eq_add_rev (id h₄.symm)).symm
297
+ rw [h₆₀, h₆₁] at h₃
298
+ repeat rw [Nat.mul_sub_left_distrib, ← pow_two] at h₃
299
+ have h₆₂: b * 2 ^ m - a * 2 ^ k = b ^ 2 - a ^ 2 := by
300
+ symm at h₃
301
+ refine Nat.sub_eq_of_eq_add ?_
302
+ rw [add_comm, ← Nat.add_sub_assoc]
303
+ . rw [Nat.sub_add_comm]
304
+ . refine Nat.eq_add_of_sub_eq ?_ h₃
305
+ rw [pow_two]
306
+ refine le_of_lt ?_
307
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.2.1) h₀.2.1
308
+ linarith
309
+ . rw [pow_two]
310
+ refine le_of_lt ?_
311
+ refine mul_lt_mul' (by linarith) ?_ (le_of_lt h₀.1) h₀.1
312
+ linarith
313
+ . refine le_of_lt ?_
314
+ rw [pow_two, pow_two]
315
+ exact mul_lt_mul h₂.1 (le_of_lt h₂.1) h₀.1 (le_of_lt h₀.2.1)
316
+ rw [Nat.sq_sub_sq b a] at h₆₂
317
+ linarith
318
+ have h₇: 2 ^ m ∣ (b - a) * (b + a) := by
319
+ have h₇₀: k = (k - m) + m := by exact (Nat.sub_add_cancel (le_of_lt hkm)).symm
320
+ rw [h₇₀, pow_add] at h₆
321
+ have h₇₁: (b - a * 2 ^ (k - m)) * (2 ^ m) = (b - a) * (b + a) := by
322
+ rw [Nat.mul_sub_right_distrib]
323
+ rw [mul_assoc a _ _]
324
+ exact h₆
325
+ exact Dvd.intro_left (b - a * 2 ^ (k - m)) h₇₁
326
+ have h₈: b + a = 2 ^ (m - 1) := by
327
+ exact mylemma_h8 a b c d k m h₀ h₁ h₂ h₅ hkm h₆ h₇
328
+ have h₉: a = 2 ^ (2 * m - 2) / 2 ^ k := by
329
+ have ga: 1 ≤ a := by exact Nat.succ_le_of_lt h₀.1
330
+ have gb: 3 ≤ b := by
331
+ by_contra! hc
332
+ interval_cases b
333
+ . linarith
334
+ . linarith [ga, h₂.1]
335
+ . have g₀: ¬ Odd 2 := by decide
336
+ exact g₀ h₁.2.1
337
+ have gm: 3 ≤ m := by
338
+ have gm₀: 2 ^ 2 ≤ 2 ^ (m - 1) := by
339
+ norm_num
340
+ rw [← h₈]
341
+ linarith
342
+ have gm₁: 2 ≤ m - 1 := by
343
+ exact (Nat.pow_le_pow_iff_right (by norm_num)).mp gm₀
344
+ omega
345
+ have g₀: a < 2 ^ (m - 2) := by
346
+ have g₀₀: a + a < b + a := by simp [h₂.1]
347
+ rw [h₈, ← mul_two a] at g₀₀
348
+ have g₀₁: m - 1 = Nat.succ (m - 2) := by
349
+ rw [← Nat.succ_sub ?_]
350
+ . rw [succ_eq_add_one]
351
+ omega
352
+ . linarith
353
+ rw [g₀₁, Nat.pow_succ 2 _] at g₀₀
354
+ exact Nat.lt_of_mul_lt_mul_right g₀₀
355
+ have h₉₀: b = 2 ^ (m - 1) - a := by
356
+ symm
357
+ exact Nat.sub_eq_of_eq_add h₈.symm
358
+ rw [h₈, h₉₀] at h₆
359
+ repeat rw [Nat.mul_sub_right_distrib] at h₆
360
+ repeat rw [← Nat.pow_add] at h₆
361
+ have hm1: 1 ≤ m := by
362
+ linarith
363
+ repeat rw [← Nat.sub_add_comm hm1] at h₆
364
+ repeat rw [← Nat.add_sub_assoc hm1] at h₆
365
+ ring_nf at h₆
366
+ rw [← Nat.sub_add_eq _ 1 1] at h₆
367
+ norm_num at h₆
368
+ rw [← Nat.sub_add_eq _ (a * 2 ^ (m - 1)) (a * 2 ^ (m - 1))] at h₆
369
+ rw [← two_mul (a * 2 ^ (m - 1))] at h₆
370
+ rw [mul_comm 2 _] at h₆
371
+ rw [mul_assoc a (2 ^ (m - 1)) 2] at h₆
372
+ rw [← Nat.pow_succ, succ_eq_add_one] at h₆
373
+ rw [Nat.sub_add_cancel hm1] at h₆
374
+ rw [← Nat.sub_add_eq ] at h₆
375
+ have h₉₁: 2 ^ (m * 2 - 1) = 2 ^ (m * 2 - 2) - a * 2 ^ m + (a * 2 ^ m + a * 2 ^ k) := by
376
+ refine Nat.eq_add_of_sub_eq ?_ h₆
377
+ by_contra! hc
378
+ have g₁: 2 ^ (m * 2 - 1) - (a * 2 ^ m + a * 2 ^ k) = 0 := by
379
+ exact Nat.sub_eq_zero_of_le (le_of_lt hc)
380
+ rw [g₁] at h₆
381
+ have g₂: 2 ^ (m * 2 - 2) ≤ a * 2 ^ m := by exact Nat.le_of_sub_eq_zero h₆.symm
382
+ have g₃: 2 ^ (m - 2) ≤ a := by
383
+ rw [mul_two, Nat.add_sub_assoc (by linarith) m] at g₂
384
+ rw [Nat.pow_add, mul_comm] at g₂
385
+ refine Nat.le_of_mul_le_mul_right g₂ ?_
386
+ exact Nat.two_pow_pos m
387
+ linarith [g₀, g₃]
388
+ rw [← Nat.add_assoc] at h₉₁
389
+ have h₉₂: a * 2 ^ k = 2 * 2 ^ (2 * m - 2) - 2 ^ (2 * m - 2) := by
390
+ rw [Nat.sub_add_cancel ?_] at h₉₁
391
+ . rw [add_comm] at h₉₁
392
+ symm
393
+ rw [← Nat.pow_succ', succ_eq_add_one]
394
+ rw [← Nat.sub_add_comm ?_]
395
+ . refine Nat.sub_eq_of_eq_add ?_
396
+ rw [mul_comm 2 m, ← h₉₁]
397
+ exact rfl
398
+ . linarith [hm1]
399
+ . refine le_of_lt ?_
400
+ rw [mul_two, Nat.add_sub_assoc, Nat.pow_add, mul_comm (2 ^ m) _]
401
+ refine (Nat.mul_lt_mul_right (by linarith)).mpr g₀
402
+ linarith
403
+ nth_rewrite 2 [← Nat.one_mul (2 ^ (2 * m - 2))] at h₉₂
404
+ rw [← Nat.mul_sub_right_distrib 2 1 (2 ^ (2 * m - 2))] at h₉₂
405
+ norm_num at h₉₂
406
+ refine Nat.eq_div_of_mul_eq_left ?_ h₉₂
407
+ exact Ne.symm (NeZero.ne' (2 ^ k))
408
+ by_cases hk2m: k ≤ 2 * m - 2
409
+ . rw [Nat.pow_div hk2m (by norm_num)] at h₉
410
+ rw [Nat.sub_right_comm (2*m) 2 k] at h₉
411
+ by_contra! hc
412
+ cases' (lt_or_gt_of_ne hc) with hc₀ hc₁
413
+ . interval_cases a
414
+ linarith
415
+ . have hc₂: ¬ Odd a := by
416
+ refine (not_odd_iff_even).mpr ?_
417
+ have hc₃: 1 ≤ 2 * m - k - 2 := by
418
+ by_contra! hc₄
419
+ interval_cases (2 * m - k - 2)
420
+ simp at h₉
421
+ rw [h₉] at hc₁
422
+ contradiction
423
+ have hc₄: 2 * m - k - 2 = succ (2 * m - k - 3) := by
424
+ rw [succ_eq_add_one]
425
+ exact Nat.eq_add_of_sub_eq hc₃ rfl
426
+ rw [h₉, hc₄, Nat.pow_succ']
427
+ exact even_two_mul (2 ^ (2 * m - k - 3))
428
+ exact hc₂ h₁.1
429
+ . push_neg at hk2m
430
+ exfalso
431
+ have ha: a = 0 := by
432
+ rw [h₉]
433
+ refine (Nat.div_eq_zero_iff).mpr ?_
434
+ right
435
+ exact Nat.pow_lt_pow_right (by norm_num) hk2m
436
+ linarith [ha, h₀.1]
imo_proofs/imo_1985_p6.lean ADDED
@@ -0,0 +1,1318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+
3
+ set_option linter.unusedVariables.analyzeTactics true
4
+
5
+ lemma aux_1
6
+ (f : ℕ → NNReal → ℝ)
7
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
8
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n)) :
9
+ ∀ (n : ℕ) (x : NNReal), 0 < n ∧ 0 < x → 0 < f n x := by
10
+ intros n x hp
11
+ have hz₇: n ≤ 7 ∨ 7 < n := by
12
+ exact le_or_lt n 7
13
+ cases' hp with hn₀ hx₀
14
+ by_cases hn₁: 1 < n
15
+ . refine Nat.le_induction ?_ ?_ n hn₁
16
+ . rw [h₁ 1 x (by norm_num)]
17
+ rw [h₀ x]
18
+ refine mul_pos hx₀ ?_
19
+ refine add_pos hx₀ (by norm_num)
20
+ . intros m hm₀ hm₁
21
+ rw [h₁ m x (by linarith)]
22
+ refine mul_pos hm₁ ?_
23
+ refine add_pos hm₁ ?_
24
+ refine one_div_pos.mpr ?_
25
+ norm_cast
26
+ exact Nat.zero_lt_of_lt hm₀
27
+ . interval_cases n
28
+ rw [h₀ x]
29
+ exact hx₀
30
+
31
+
32
+ lemma aux_2
33
+ (f : ℕ → NNReal → ℝ)
34
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
35
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
36
+ (h₂ : ∀ (n : ℕ) (x : NNReal), 0 < n ∧ 0 < x → 0 < f n x)
37
+ (h₃ : ∀ (n : ℕ) (x : NNReal), 0 < n → 0 ≤ f n x) :
38
+ ∀ (n : ℕ) (x y : NNReal), 0 < n → x < y → f n x < f n y := by
39
+ intros n x y hn hxy
40
+ by_cases hn₁: 1 < n
41
+ . refine Nat.le_induction ?_ ?_ n hn₁
42
+ . rw [h₁ 1 x (by norm_num)]
43
+ rw [h₁ 1 y (by norm_num)]
44
+ norm_num
45
+ refine mul_lt_mul ?_ ?_ ?_ ?_
46
+ . rw [h₀ x, h₀ y]
47
+ exact hxy
48
+ . refine _root_.add_le_add ?_ (by norm_num)
49
+ rw [h₀ x, h₀ y]
50
+ exact le_of_lt hxy
51
+ . refine add_pos_of_nonneg_of_pos ?_ (by linarith)
52
+ rw [h₀ x]
53
+ exact NNReal.zero_le_coe
54
+ . refine le_of_lt ?_
55
+ refine h₂ 1 y ?_
56
+ norm_num
57
+ exact pos_of_gt hxy
58
+ . intros m hm₀ hm₁
59
+ rw [h₁ m x (by linarith)]
60
+ rw [h₁ m y (by linarith)]
61
+ refine mul_lt_mul hm₁ ?_ ?_ ?_
62
+ . refine _root_.add_le_add ?_ (by norm_num)
63
+ exact le_of_lt hm₁
64
+ . refine add_pos_of_nonneg_of_pos ?_ ?_
65
+ . exact h₃ m x (by linarith)
66
+ . refine one_div_pos.mpr ?_
67
+ norm_cast
68
+ exact Nat.zero_lt_of_lt hm₀
69
+ . refine le_of_lt ?_
70
+ refine h₂ m y ?_
71
+ constructor
72
+ . exact Nat.zero_lt_of_lt hm₀
73
+ . exact pos_of_gt hxy
74
+ . interval_cases n
75
+ rw [h₀ x, h₀ y]
76
+ exact hxy
77
+
78
+
79
+ lemma aux_3
80
+ (f : ℕ → NNReal → ℝ)
81
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
82
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
83
+ (h₄ : ∀ (n : ℕ) (x y : NNReal), 0 < n → x < y → f n x < f n y) :
84
+ ∀ (n : ℕ) (x : NNReal), 1 < n ∧ 1 ≤ x → 1 < f n x := by
85
+ intros n x hx₀
86
+ cases' hx₀ with hn₀ hx₁
87
+ have g₂₀: f n 1 ≤ f n x := by
88
+ by_cases hx₂: 1 < x
89
+ . refine le_of_lt ?_
90
+ refine h₄ n 1 x ?_ hx₂
91
+ exact Nat.zero_lt_of_lt hn₀
92
+ . push_neg at hx₂
93
+ have hx₃: x = 1 := by exact le_antisymm hx₂ hx₁
94
+ rw [hx₃]
95
+ have g₂₁: f 1 1 < f n 1 := by
96
+ rw [h₀]
97
+ refine Nat.le_induction ?_ ?_ n hn₀
98
+ . rw [h₁ 1 1 (by norm_num), h₀]
99
+ norm_num
100
+ . intros m hm₀ hm₁
101
+ rw [h₁ m 1 (by linarith)]
102
+ refine one_lt_mul_of_lt_of_le hm₁ ?_
103
+ nth_rw 1 [← add_zero 1]
104
+ refine add_le_add ?_ ?_
105
+ . exact le_of_lt hm₁
106
+ . refine one_div_nonneg.mpr ?_
107
+ exact Nat.cast_nonneg' m
108
+ refine lt_of_lt_of_le ?_ g₂₀
109
+ exact (lt_iff_lt_of_cmp_eq_cmp (congrFun (congrArg cmp (h₀ 1)) (f n 1))).mp g₂₁
110
+
111
+
112
+ lemma aux_4
113
+ (f : ℕ → NNReal → ℝ)
114
+ (h₃ : ∀ (n : ℕ) (x : NNReal), 0 < n → 0 ≤ f n x)
115
+ (h₄ : ∀ (n : ℕ) (x y : NNReal), 0 < n → x < y → f n x < f n y)
116
+ (f₀ : ℕ → NNReal → NNReal)
117
+ (hf₀ : f₀ = fun n x => (f n x).toNNReal) :
118
+ ∀ (n : ℕ), 0 < n → StrictMono (f₀ n) := by
119
+ intros n hn₀
120
+ refine Monotone.strictMono_of_injective ?_ ?_
121
+ . refine monotone_iff_forall_lt.mpr ?_
122
+ intros a b hab
123
+ refine le_of_lt ?_
124
+ rw [hf₀]
125
+ exact (Real.toNNReal_lt_toNNReal_iff_of_nonneg (h₃ n a hn₀)).mpr (h₄ n a b hn₀ hab)
126
+ . intros p q hpq
127
+ contrapose! hpq
128
+ apply lt_or_gt_of_ne at hpq
129
+ cases' hpq with hpq hpq
130
+ . refine ne_of_lt ?_
131
+ rw [hf₀]
132
+ exact (Real.toNNReal_lt_toNNReal_iff_of_nonneg (h₃ n p hn₀)).mpr (h₄ n p q hn₀ hpq)
133
+ . symm
134
+ refine ne_of_lt ?_
135
+ rw [hf₀]
136
+ exact (Real.toNNReal_lt_toNNReal_iff_of_nonneg (h₃ n q hn₀)).mpr (h₄ n q p hn₀ hpq)
137
+
138
+
139
+ lemma aux_5
140
+ (f : ℕ → NNReal → ℝ)
141
+ (hmo₁ : ∀ (n : ℕ), 0 < n → Function.Injective (f n))
142
+ (f₀ : ℕ → NNReal → NNReal)
143
+ (hmo₂ : ∀ (n : ℕ), 0 < n → StrictMono (f₀ n))
144
+ (fi : ℕ → NNReal → NNReal)
145
+ (hfi : fi = fun n => Function.invFun (f₀ n)):
146
+ ∀ (n : ℕ) (x y : NNReal), 0 < n → f₀ n x = y → fi n y = x := by
147
+ intros n x y hn₀ hn₁
148
+ have hf₃: ∀ n y, fi n y = Function.invFun (f₀ n) y := by
149
+ exact fun n y => congrFun (congrFun hfi n) y
150
+ rw [← hn₁, hf₃]
151
+ have hmo₃: ∀ n, 0 < n → Function.Injective (f₀ n) := by
152
+ exact fun n a => StrictMono.injective (hmo₂ n a)
153
+ have hn₂: (Function.invFun (f₀ n)) ∘ (f₀ n) = id := by exact Function.invFun_comp (hmo₃ n hn₀)
154
+ rw [Function.comp_def (Function.invFun (f₀ n)) (f₀ n)] at hn₂
155
+ have hn₃: (fun x => Function.invFun (f₀ n) (f₀ n x)) x = id x := by exact Eq.symm (NNReal.eq (congrArg NNReal.toReal (congrFun (id (Eq.symm hn₂)) x)))
156
+ exact hmo₁ n hn₀ (congrArg (f n) hn₃)
157
+
158
+
159
+ lemma aux_6
160
+ (f : ℕ → NNReal → ℝ)
161
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
162
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
163
+ (f₀ : ℕ → NNReal → NNReal)
164
+ (hf₀ : f₀ = fun n x => (f n x).toNNReal) :
165
+ ∀ (n : ℕ), 0 < n → Continuous (f₀ n) := by
166
+ intros n hn₀
167
+ rw [hf₀]
168
+ refine Continuous.comp' ?_ ?_
169
+ . exact continuous_real_toNNReal
170
+ . refine Nat.le_induction ?_ ?_ n hn₀
171
+ . have hn₁: f 1 = fun (x:NNReal) => (x:ℝ) := by exact (Set.eqOn_univ (f 1) fun x => ↑x).mp fun ⦃x⦄ _ => h₀ x
172
+ rw [hn₁]
173
+ exact NNReal.continuous_coe
174
+ . intros d hd₀ hd₁
175
+ have hd₂: f (d + 1) = fun x => f d x * (f d x + 1 / ↑d) := by
176
+ exact (Set.eqOn_univ (f (d + 1)) fun x => f d x * (f d x + 1 / ↑d)).mp fun ⦃x⦄ _ => h₁ d x hd₀
177
+ rw [hd₂]
178
+ refine Continuous.mul hd₁ ?_
179
+ refine Continuous.add hd₁ ?_
180
+ exact continuous_const
181
+
182
+
183
+ lemma aux_7
184
+ (f : ℕ → NNReal → ℝ)
185
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
186
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
187
+ (h₃ : ∀ (n : ℕ) (x : NNReal), 0 < n → 0 ≤ f n x)
188
+ (h₅ : ∀ (n : ℕ) (x : NNReal), 1 < n ∧ 1 ≤ x → 1 < f n x)
189
+ (f₀ : ℕ → NNReal → NNReal)
190
+ (hf₂ : ∀ (n : ℕ) (x : NNReal), 0 < n → f₀ n x = (f n x).toNNReal)
191
+ (hmo₂ : ∀ (n : ℕ), 0 < n → StrictMono (f₀ n))
192
+ (hmo₄ : ∀ (n : ℕ), 0 < n → Continuous (f₀ n)) :
193
+ ∀ (n : ℕ), 0 < n → Function.Surjective (f₀ n) := by
194
+ intros n hn₀
195
+ refine Continuous.surjective (hmo₄ n hn₀) ?_ ?_
196
+ . refine Monotone.tendsto_atTop_atTop ?_ ?_
197
+ . exact StrictMono.monotone (hmo₂ n hn₀)
198
+ . intro b
199
+ use (b + 1)
200
+ refine Nat.le_induction ?_ ?_ n hn₀
201
+ . rw [hf₂ 1 (b + 1) (by linarith), h₀]
202
+ simp
203
+ . intros d hd₀ hd₁
204
+ rw [hf₂ (d + 1) (b + 1) (by linarith), h₁ d (b + 1) (by linarith)]
205
+ have hd₂: b ≤ f d (b + 1) := by
206
+ rw [hf₂ d (b + 1) (by linarith)] at hd₁
207
+ exact (Real.le_toNNReal_iff_coe_le (h₃ d (b + 1) hd₀)).mp hd₁
208
+ have hd₃: 1 < (f d (b + 1) + 1 / ↑d) := by
209
+ by_cases hd₄: 1 < d
210
+ . refine lt_add_of_lt_of_pos ?_ ?_
211
+ . refine h₅ d (b + 1) ?_
212
+ constructor
213
+ . exact hd₄
214
+ . exact le_add_self
215
+ . refine div_pos (by linarith) ?_
216
+ exact Nat.cast_pos'.mpr hd₀
217
+ . have hd₅: d = 1 := by linarith
218
+ rw [hd₅, h₀]
219
+ simp
220
+ norm_cast
221
+ refine add_pos_of_nonneg_of_pos ?_ ?_
222
+ . exact _root_.zero_le b
223
+ . exact zero_lt_one' NNReal
224
+ refine NNReal.le_toNNReal_of_coe_le ?_
225
+ nth_rw 1 [← mul_one (↑b:ℝ)]
226
+ refine mul_le_mul hd₂ (le_of_lt hd₃) (by linarith) ?_
227
+ exact h₃ d (b + 1) hd₀
228
+ . refine Filter.tendsto_atBot_atBot.mpr ?_
229
+ intro b
230
+ use 0
231
+ intro a ha₀
232
+ have ha₁: a = 0 := by exact nonpos_iff_eq_zero.mp ha₀
233
+ have ha₂: f₀ n 0 = 0 := by
234
+ refine Nat.le_induction ?_ ?_ n hn₀
235
+ . rw [hf₂ 1 0 (by linarith), h₀]
236
+ exact Real.toNNReal_coe
237
+ . intros d hd₀ hd₁
238
+ rw [hf₂ (d + 1) 0 (by linarith), h₁ d 0 (by linarith)]
239
+ have hd₂: 0 ≤ f d 0 := by exact h₃ d 0 hd₀
240
+ have hd₃: f d 0 = 0 := by
241
+ rw [hf₂ d 0 (by linarith)] at hd₁
242
+ apply Real.toNNReal_eq_zero.mp at hd₁
243
+ exact eq_of_le_of_le hd₁ hd₂
244
+ rw [hd₃, zero_mul]
245
+ exact Real.toNNReal_zero
246
+ rw [ha₁, ha₂]
247
+ exact _root_.zero_le b
248
+
249
+
250
+ lemma aux_8
251
+ (f : ℕ → NNReal → ℝ)
252
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
253
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
254
+ (hmo₀ : ∀ (n : ℕ), 0 < n → StrictMono (f n))
255
+ (hmo₁ : ∀ (n : ℕ), 0 < n → Function.Injective (f n))
256
+ (f₀ : ℕ → NNReal → NNReal)
257
+ (hf₂ : ∀ (n : ℕ) (x : NNReal), 0 < n → f₀ n x = (f n x).toNNReal)
258
+ (sn : Set ℕ)
259
+ (fb : ↑sn → NNReal)
260
+ (hsn₁ : ∀ (n : ↑sn), ↑n ∈ sn ∧ 0 < n.1)
261
+ (hfb₁ : ∀ (n : ↑sn), f₀ (↑n) (fb n) = 1 - 1 / ↑↑n) :
262
+ ∀ (n : ↑sn), fb n < 1 := by
263
+ intros n
264
+ have hn₀: 0 < (n:ℕ) := by exact (hsn₁ n).2
265
+ let z := fb n
266
+ have hz₀: z = fb n := by rfl
267
+ rw [← hz₀]
268
+ by_contra! hc₀
269
+ have hc₁: 1 ≤ f n z := by
270
+ by_cases hn₁: 1 < (n:ℕ)
271
+ . refine le_of_lt ?_
272
+ refine aux_3 f h₀ h₁ ?_ (↑n) z ?_
273
+ . exact fun n x y a a_1 => hmo₀ n a a_1
274
+ . exact ⟨hn₁, hc₀⟩
275
+ . have hn₂: (n:ℕ) = 1 := by linarith
276
+ rw [hn₂, h₀]
277
+ exact hc₀
278
+ have hz₁: f₀ n z = 1 - 1 / n := by
279
+ exact hfb₁ n
280
+ have hz₃: f n z = 1 - 1 / n := by
281
+ rw [hf₂ n z hn₀] at hz₁
282
+ by_cases hn₁: 1 < (n:ℕ)
283
+ . have hz₂: 1 - 1 / (n:NNReal) ≠ 0 := by
284
+ have g₀: (n:NNReal) ≠ 0 := by
285
+ norm_cast
286
+ linarith
287
+ nth_rw 1 [← div_self g₀, ← NNReal.sub_div]
288
+ refine div_ne_zero ?_ g₀
289
+ norm_cast
290
+ exact Nat.sub_ne_zero_iff_lt.mpr hn₁
291
+ apply (Real.toNNReal_eq_iff_eq_coe hz₂).mp at hz₁
292
+ rw [hz₁]
293
+ exact Eq.symm ((fun {r} {p:NNReal} hp => (Real.toNNReal_eq_iff_eq_coe hp).mp) hz₂ (hmo₁ n hn₀ rfl))
294
+ . have hn₂: (n:ℕ) = 1 := by linarith
295
+ rw [hn₂, h₀] at hz₁
296
+ simp at hz₁
297
+ rw [hn₂, h₀, hz₁]
298
+ simp
299
+ rw [hz₃] at hc₁
300
+ have hz₄: 0 < 1 / (n:ℝ) := by
301
+ refine div_pos (by linarith) ?_
302
+ exact Nat.cast_pos'.mpr hn₀
303
+ linarith
304
+
305
+
306
+ lemma aux_9
307
+ (f : ℕ → NNReal → ℝ)
308
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
309
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
310
+ (f₀ : ℕ → NNReal → NNReal)
311
+ (hf₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f n x = ↑(f₀ n x))
312
+ (hf₂ : ∀ (n : ℕ) (x : NNReal), 0 < n → f₀ n x = (f n x).toNNReal)
313
+ (hmo₂ : ∀ (n : ℕ), 0 < n → StrictMono (f₀ n))
314
+ (fi : ℕ → NNReal → NNReal)
315
+ (hf₅ : ∀ (x : NNReal), fi 1 x = x)
316
+ (hmo₇ : ∀ (n : ℕ), 0 < n → Function.RightInverse (fi n) (f₀ n))
317
+ (hf₇ : ∀ (n : ℕ) (x y : NNReal), 0 < n → (f₀ n x = y ↔ fi n y = x))
318
+ (fb : ℕ → NNReal)
319
+ (hfb₀ : fb = fun n => fi n (1 - 1 / ↑n))
320
+ (sn : Set ℕ)
321
+ (hsn : sn = Set.Ici 1) :
322
+ StrictMonoOn fb sn := by
323
+ rw [hsn]
324
+ refine strictMonoOn_Ici_of_pred_lt ?hψ
325
+ intros m hm₀
326
+ rw [hfb₀]
327
+ refine Nat.le_induction ?_ ?_ m hm₀
328
+ . have g₁: fi 1 0 = 0 := by exact hf₅ 0
329
+ have g₂: (2:NNReal).IsConjExponent (2:NNReal) := by
330
+ refine (NNReal.isConjExponent_iff_eq_conjExponent ?_).mpr ?_
331
+ . exact one_lt_two
332
+ . norm_cast
333
+ simp
334
+ simp
335
+ norm_cast
336
+ rw [g₁, NNReal.IsConjExponent.one_sub_inv g₂]
337
+ let x := fi 2 2⁻¹
338
+ have hx₀: x = fi 2 2⁻¹ := by rfl
339
+ have hx₁: f₀ 2 x = 2⁻¹ := by
340
+ rw [hx₀]
341
+ have g₃: Function.RightInverse (fi 2) (f₀ 2) := by exact hmo₇ 2 (by linarith)
342
+ exact g₃ 2⁻¹
343
+ rw [← hx₀]
344
+ contrapose! hx₁
345
+ have hc₁: x = 0 := by exact nonpos_iff_eq_zero.mp hx₁
346
+ have hc₃: f₀ 2 x = 0 := by
347
+ rw [hc₁, hf₂ 2 0 (by linarith), h₁ 1 0 (by linarith), h₀ 0]
348
+ norm_cast
349
+ rw [zero_mul]
350
+ exact Real.toNNReal_zero
351
+ rw [hc₃]
352
+ exact Ne.symm (NNReal.IsConjExponent.inv_ne_zero g₂)
353
+ . simp
354
+ intros n hn₀ _
355
+ let i := fi n (1 - (↑n)⁻¹)
356
+ let j := fi (n + 1) (1 - ((↑n:NNReal) + 1)⁻¹)
357
+ have hi₀: i = fi n (1 - (↑n)⁻¹) := by rfl
358
+ have hj₀: j = fi (n + 1) (1 - ((↑n:NNReal) + 1)⁻¹) := by rfl
359
+ have hi₁: f₀ n i = (1 - (↑n)⁻¹) := by exact (hf₇ n i (1 - (↑n:NNReal)⁻¹) (by linarith)).mpr hi₀.symm
360
+ have hj₁: f₀ (n + 1) j = (1 - ((↑n:NNReal) + 1)⁻¹) := by
361
+ exact (hf₇ (n + 1) j _ (by linarith)).mpr hj₀.symm
362
+ have hj₂: (1 - ((↑n:NNReal) + 1)⁻¹) = (1 - ((n:ℝ) + 1)⁻¹).toNNReal := by
363
+ exact rfl
364
+ have hn₂: f₀ (n + 1) i < f₀ (n + 1) j := by
365
+ rw [hj₁, hj₂, hf₂ (n + 1) _ (by linarith), h₁ n i (by linarith)]
366
+ rw [hf₁ n i (by linarith), hi₁]
367
+ refine (Real.toNNReal_lt_toNNReal_iff ?_).mpr ?_
368
+ . refine sub_pos.mpr ?_
369
+ refine inv_lt_one_of_one_lt₀ ?_
370
+ norm_cast
371
+ exact Nat.lt_add_right 1 hn₀
372
+ . have g₀: (↑n:NNReal)⁻¹ ≤ 1 := by exact Nat.cast_inv_le_one n
373
+ rw [NNReal.coe_sub g₀, NNReal.coe_inv]
374
+ simp
375
+ refine inv_strictAnti₀ ?_ ?_
376
+ . norm_cast
377
+ exact Nat.zero_lt_of_lt hn₀
378
+ . norm_cast
379
+ exact lt_add_one n
380
+ refine (StrictMono.lt_iff_lt ?_).mp hn₂
381
+ exact hmo₂ (n + 1) (by linarith)
382
+
383
+
384
+ lemma aux_10
385
+ (f : ℕ → NNReal → ℝ)
386
+ (h₀ : ∀ (x : NNReal), f 1 x = ↑x)
387
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
388
+ (f₀ : ℕ → NNReal → NNReal)
389
+ (hf₂ : ∀ (n : ℕ) (x : NNReal), 0 < n → f₀ n x = (f n x).toNNReal)
390
+ (fi : ℕ → NNReal → NNReal)
391
+ (hmo₇ : ∀ (n : ℕ), 0 < n → Function.RightInverse (fi n) (f₀ n))
392
+ (sn : Set ℕ)
393
+ (sb : Set NNReal)
394
+ (fb : ↑sn → NNReal)
395
+ (hsn₀ : sn = Set.Ici 1)
396
+ (hfb₀ : fb = fun n:↑sn => fi (↑n) (1 - 1 / ↑��n))
397
+ (hsb₀ : sb = Set.range fb)
398
+ (fr : NNReal → ℝ)
399
+ (hfr: fr = fun x => ↑x)
400
+ (sbr : Set ℝ)
401
+ (hsbr: sbr = fr '' sb)
402
+ (br: ℝ)
403
+ (hbr₀ : IsLUB sbr br) :
404
+ 0 < br := by
405
+ have hnb₀: 2 ∈ sn := by
406
+ rw [hsn₀]
407
+ decide
408
+ let nb : ↑sn := ⟨2, hnb₀⟩
409
+ have g₀: 0 < fb nb := by
410
+ have g₁: (2:NNReal).IsConjExponent (2:NNReal) := by
411
+ refine (NNReal.isConjExponent_iff_eq_conjExponent ?_).mpr ?_
412
+ . exact one_lt_two
413
+ . norm_cast
414
+ simp
415
+ rw [hfb₀]
416
+ simp
417
+ have hnb₁: nb.val = 2 := by exact rfl
418
+ rw [hnb₁]
419
+ norm_cast
420
+ rw [NNReal.IsConjExponent.one_sub_inv g₁]
421
+ let x := fi 2 2⁻¹
422
+ have hx₀: x = fi 2 2⁻¹ := by rfl
423
+ have hx₁: f₀ 2 x = 2⁻¹ := by
424
+ rw [hx₀]
425
+ have g₃: Function.RightInverse (fi 2) (f₀ 2) := by exact hmo₇ 2 (by linarith)
426
+ exact g₃ 2⁻¹
427
+ rw [← hx₀]
428
+ contrapose! hx₁
429
+ have hc₁: x = 0 := by exact nonpos_iff_eq_zero.mp hx₁
430
+ have hc₃: f₀ 2 x = 0 := by
431
+ rw [hc₁, hf₂ 2 0 (by linarith), h₁ 1 0 (by linarith), h₀ 0]
432
+ norm_cast
433
+ rw [zero_mul]
434
+ exact Real.toNNReal_zero
435
+ rw [hc₃]
436
+ exact Ne.symm (NNReal.IsConjExponent.inv_ne_zero g₁)
437
+ have g₁: ∃ x, 0 < x ∧ x ∈ sbr := by
438
+ use (fb nb).toReal
439
+ constructor
440
+ . exact g₀
441
+ . rw [hsbr]
442
+ simp
443
+ use fb ↑nb
444
+ constructor
445
+ . rw [hsb₀]
446
+ exact Set.mem_range_self nb
447
+ . exact congrFun hfr (fb ↑nb)
448
+ obtain ⟨x, hx₀, hx₁⟩ := g₁
449
+ have hx₂: br ∈ upperBounds sbr := by
450
+ refine (isLUB_le_iff hbr₀).mp ?_
451
+ exact Preorder.le_refl br
452
+ exact gt_of_ge_of_gt (hx₂ hx₁) hx₀
453
+
454
+
455
+ lemma aux_11
456
+ (sn : Set ℕ)
457
+ (fb fc : ↑sn → NNReal)
458
+ (hfc₂ : ∀ (n : ↑sn), fb n < fc n)
459
+ (hfb₃ : StrictMono fb)
460
+ (hfc₃ : StrictAnti fc)
461
+ (sb sc : Set NNReal)
462
+ (hsb₀ : sb = Set.range fb)
463
+ (hsc₀ : sc = Set.range fc)
464
+ (fr : NNReal → ℝ)
465
+ (hfr : fr = fun x ↦ ↑x)
466
+ (sbr scr : Set ℝ)
467
+ (hsbr : sbr = fr '' sb)
468
+ (hscr : scr = fr '' sc)
469
+ (br cr : ℝ)
470
+ (hbr₀ : IsLUB sbr br)
471
+ (hcr₀ : IsGLB scr cr)
472
+ (hfb₄ : ∀ (n : ↑sn), 0 ≤ fb n) :
473
+ br ≤ cr := by
474
+ have hfc₄: ∀ nb nc, fb nb < fc nc := by
475
+ intros nb nc
476
+ cases' (lt_or_le nb nc) with hn₀ hn₀
477
+ . refine lt_trans ?_ (hfc₂ nc)
478
+ exact hfb₃ hn₀
479
+ cases' lt_or_eq_of_le hn₀ with hn₁ hn₁
480
+ . refine lt_trans (hfc₂ nb) ?_
481
+ exact hfc₃ hn₁
482
+ . rw [hn₁]
483
+ exact hfc₂ nb
484
+ by_contra! hc₀
485
+ have hc₁: ∃ x ∈ sbr, cr < x ∧ x ≤ br := by exact IsLUB.exists_between hbr₀ hc₀
486
+ let ⟨x, hx₀, hx₁, _⟩ := hc₁
487
+ have hc₂: ∃ y ∈ scr, cr ≤ y ∧ y < x := by exact IsGLB.exists_between hcr₀ hx₁
488
+ let ⟨y, hy₀, _, hy₂⟩ := hc₂
489
+ have hc₃: x < y := by
490
+ have hx₃: x.toNNReal ∈ sb := by
491
+ rw [hsbr] at hx₀
492
+ apply (Set.mem_image fr sb x).mp at hx₀
493
+ obtain ⟨z, hz₀, hz₁⟩ := hx₀
494
+ rw [← hz₁, hfr, Real.toNNReal_coe]
495
+ exact hz₀
496
+ have hy₃: y.toNNReal ∈ sc := by
497
+ rw [hscr] at hy₀
498
+ apply (Set.mem_image fr sc y).mp at hy₀
499
+ obtain ⟨z, hz₀, hz₁⟩ := hy₀
500
+ rw [← hz₁, hfr, Real.toNNReal_coe]
501
+ exact hz₀
502
+ rw [hsb₀] at hx₃
503
+ rw [hsc₀] at hy₃
504
+ apply Set.mem_range.mp at hx₃
505
+ apply Set.mem_range.mp at hy₃
506
+ let ⟨nx, hnx₀⟩ := hx₃
507
+ let ⟨ny, hny₀⟩ := hy₃
508
+ have hy₄: 0 < y := by
509
+ contrapose! hy₃
510
+ have hy₅: y.toNNReal = 0 := by exact Real.toNNReal_of_nonpos hy₃
511
+ intro z
512
+ rw [hy₅]
513
+ refine ne_of_gt ?_
514
+ refine lt_of_le_of_lt ?_ (hfc₂ z)
515
+ exact hfb₄ z
516
+ refine (Real.toNNReal_lt_toNNReal_iff hy₄).mp ?_
517
+ rw [← hnx₀, ← hny₀]
518
+ exact hfc₄ nx ny
519
+ refine (lt_self_iff_false x).mp ?_
520
+ exact lt_trans hc₃ hy₂
521
+
522
+
523
+ lemma aux_exists
524
+ (f : ℕ → NNReal → ℝ)
525
+ (h₂ : ∀ (n : ℕ) (x : NNReal), 0 < n ∧ 0 < x → 0 < f n x)
526
+ (hmo₀ : ∀ (n : ℕ), 0 < n → StrictMono (f n))
527
+ (f₀ : ℕ → NNReal → NNReal)
528
+ (hf₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f n x = ↑(f₀ n x))
529
+ (sn : Set ℕ)
530
+ (hsn₀ : sn = Set.Ici 1)
531
+ (fb fc : ↑sn → NNReal)
532
+ (hfb₁ : ∀ (n : ↑sn), f₀ (↑n) (fb n) = 1 - 1 / ↑↑n)
533
+ (hfc₁ : ∀ (n : ↑sn), f₀ (↑n) (fc n) = 1)
534
+ (hfb₃ : StrictMono fb)
535
+ (hfc₃ : StrictAnti fc)
536
+ (sb sc : Set NNReal)
537
+ (hsb₀ : sb = Set.range fb)
538
+ (hsc₀ : sc = Set.range fc)
539
+ (fr : NNReal → ℝ)
540
+ (hfr : fr = fun x => ↑x)
541
+ (sbr scr : Set ℝ)
542
+ (hsbr : sbr = fr '' sb)
543
+ (hscr : scr = fr '' sc)
544
+ (br cr : ℝ)
545
+ (h₈ : ∀ (n : ℕ) (x : NNReal), 0 < n → 0 < x → 1 - 1 / ↑n < f n x → f n x < f (n + 1) x)
546
+ (hbr₁ : 0 < br)
547
+ (hu₅ : br ≤ cr)
548
+ (hbr₃ : ∀ x ∈ sbr, x ≤ br)
549
+ (hcr₃ : ∀ x ∈ scr, cr ≤ x) :
550
+ ∃ x, ∀ (n : ℕ), 0 < n → 0 < f n x ∧ f n x < f (n + 1) x ∧ f (n + 1) x < 1 := by
551
+ cases' lt_or_eq_of_le hu₅ with hu₆ hu₆
552
+ . apply exists_between at hu₆
553
+ let ⟨a, ha₀, ha₁⟩ := hu₆
554
+ have ha₂: 0 < a := by exact gt_trans ha₀ hbr₁
555
+ have ha₃: 0 < a.toNNReal := by exact Real.toNNReal_pos.mpr ha₂
556
+ use a.toNNReal
557
+ intros n hn₀
558
+ have hn₁: n ∈ sn := by
559
+ rw [hsn₀]
560
+ exact hn₀
561
+ constructor
562
+ . exact h₂ n a.toNNReal ⟨hn₀, ha₃⟩
563
+ constructor
564
+ . refine h₈ n a.toNNReal hn₀ ?_ ?_
565
+ . exact Real.toNNReal_pos.mpr ha₂
566
+ . let nn : ↑sn := ⟨n, hn₁⟩
567
+ have hn₂: f n (fb nn) = 1 - 1 / n := by
568
+ rw [hf₁ n _ hn₀, hfb₁ nn]
569
+ refine NNReal.coe_sub ?_
570
+ refine div_le_self ?_ ?_
571
+ . exact zero_le_one' NNReal
572
+ . exact Nat.one_le_cast.mpr hn₀
573
+ rw [← hn₂]
574
+ refine hmo₀ n hn₀ ?_
575
+ refine Real.lt_toNNReal_iff_coe_lt.mpr ?_
576
+ refine lt_of_le_of_lt ?_ ha₀
577
+ refine hbr₃ _ ?_
578
+ rw [hsbr]
579
+ refine (Set.mem_image fr sb _).mpr ?_
580
+ use (fb nn)
581
+ rw [hfr, hsb₀]
582
+ refine ⟨?_, rfl⟩
583
+ exact Set.mem_range_self nn
584
+ . have hn₂: n + 1 ∈ sn := by
585
+ rw [hsn₀]
586
+ exact Set.mem_Ici.mpr (by linarith)
587
+ let nn : ↑sn := ⟨n + 1, hn₂⟩
588
+ have hn₃: f (n + 1) (fc (nn)) = 1 := by
589
+ rw [hf₁ (n + 1) _ (by linarith), hfc₁ nn]
590
+ exact rfl
591
+ rw [← hn₃]
592
+ refine hmo₀ (n + 1) (by linarith) ?_
593
+ refine (Real.toNNReal_lt_iff_lt_coe (le_of_lt ha₂)).mpr ?_
594
+ refine lt_of_lt_of_le ha₁ ?_
595
+ refine hcr₃ _ ?_
596
+ rw [hscr]
597
+ refine (Set.mem_image fr sc _).mpr ?_
598
+ use (fc nn)
599
+ rw [hfr, hsc₀]
600
+ refine ⟨?_, rfl⟩
601
+ exact Set.mem_range_self nn
602
+ . use br.toNNReal
603
+ intros n hn₀
604
+ have hn₁: n ∈ sn := by
605
+ rw [hsn₀]
606
+ exact hn₀
607
+ constructor
608
+ . refine h₂ n br.toNNReal ⟨hn₀, ?_⟩
609
+ exact Real.toNNReal_pos.mpr hbr₁
610
+ constructor
611
+ . refine h₈ n br.toNNReal hn₀ ?_ ?_
612
+ . exact Real.toNNReal_pos.mpr hbr₁
613
+ . let nn : ↑sn := ⟨n, hn₁⟩
614
+ have hn₂: fb nn < br := by
615
+ by_contra! hc₀
616
+ have hbr₅: (fb nn) = br := by
617
+ refine eq_of_le_of_le ?_ hc₀
618
+ refine hbr₃ _ ?_
619
+ rw [hsbr]
620
+ refine (Set.mem_image fr sb _).mpr ?_
621
+ use (fb nn)
622
+ rw [hfr, hsb₀]
623
+ constructor
624
+ . exact Set.mem_range_self nn
625
+ . exact rfl
626
+ have hn₂: n + 1 ∈ sn := by
627
+ rw [hsn₀]
628
+ refine Set.mem_Ici.mpr ?_
629
+ exact Nat.le_add_right_of_le hn₀
630
+ let ns : ↑sn := ⟨n + 1, hn₂⟩
631
+ have hc₁: fb nn < fb ns := by
632
+ refine hfb₃ ?_
633
+ refine Subtype.mk_lt_mk.mpr ?_
634
+ exact lt_add_one n
635
+ have hbr₆: fb ns ≤ fb nn := by
636
+ refine NNReal.coe_le_coe.mp ?_
637
+ rw [hbr₅]
638
+ refine hbr₃ _ ?_
639
+ rw [hsbr]
640
+ refine (Set.mem_image fr sb _).mpr ?_
641
+ use (fb ns)
642
+ rw [hfr, hsb₀]
643
+ refine ⟨?_, rfl⟩
644
+ exact Set.mem_range_self ns
645
+ refine (lt_self_iff_false (fb nn)).mp ?_
646
+ exact lt_of_lt_of_le hc₁ hbr₆
647
+ have hn₃: f n (fb nn) = 1 - 1 / n := by
648
+ rw [hf₁ n _ hn₀, hfb₁ nn]
649
+ refine NNReal.coe_sub ?_
650
+ refine div_le_self ?_ ?_
651
+ . exact zero_le_one' NNReal
652
+ . exact Nat.one_le_cast.mpr hn₀
653
+ rw [← hn₃]
654
+ refine hmo₀ n hn₀ ?_
655
+ exact Real.lt_toNNReal_iff_coe_lt.mpr hn₂
656
+ . have hn₂: n + 1 ∈ sn := by
657
+ rw [hsn₀]
658
+ exact Set.mem_Ici.mpr (by linarith)
659
+ let nn : ↑sn := ⟨n + 1, hn₂⟩
660
+ have hcr₁: 0 < cr := by exact gt_of_ge_of_gt hu₅ hbr₁
661
+ have hn₃: f (n + 1) (fc (nn)) = 1 := by
662
+ rw [hf₁ (n + 1) _ (by linarith), hfc₁ nn]
663
+ exact rfl
664
+ rw [← hn₃, hu₆]
665
+ refine hmo₀ (n + 1) (by linarith) ?_
666
+ refine (Real.toNNReal_lt_iff_lt_coe (le_of_lt hcr₁)).mpr ?_
667
+ by_contra! hc₀
668
+ have hc₁: fc nn = cr := by
669
+ refine eq_of_le_of_le hc₀ ?_
670
+ refine hcr₃ _ ?_
671
+ rw [hscr]
672
+ refine (Set.mem_image fr sc _).mpr ?_
673
+ use (fc nn)
674
+ rw [hfr, hsc₀]
675
+ refine ⟨?_, rfl⟩
676
+ exact Set.mem_range_self nn
677
+ have hn₄: n + 2 ∈ sn := by
678
+ rw [hsn₀]
679
+ refine Set.mem_Ici.mpr ?_
680
+ exact Nat.le_add_right_of_le hn₀
681
+ let ns : ↑sn := ⟨n + 2, hn₄⟩
682
+ have hn₅: fc ns < fc nn := by
683
+ refine hfc₃ ?_
684
+ refine Subtype.mk_lt_mk.mpr ?_
685
+ exact Nat.lt_add_one (n + 1)
686
+ have hc₂: fc nn ≤ fc ns := by
687
+ refine NNReal.coe_le_coe.mp ?_
688
+ rw [hc₁]
689
+ refine hcr₃ _ ?_
690
+ rw [hscr]
691
+ refine (Set.mem_image fr sc _).mpr ?_
692
+ use (fc ns)
693
+ rw [hfr, hsc₀]
694
+ refine ⟨?_, rfl⟩
695
+ exact Set.mem_range_self ns
696
+ refine (lt_self_iff_false (fc ns)).mp ?_
697
+ exact lt_of_lt_of_le hn₅ hc₂
698
+
699
+
700
+
701
+
702
+ lemma aux_unique_top_ind
703
+ (f : ℕ → NNReal → ℝ)
704
+ (sd : Set ℕ)
705
+ (hsd : sd = Set.Ici 2)
706
+ (fd : NNReal → NNReal → ↑sd → ℝ)
707
+ (hfd₁ : ∀ (y₁ y₂ : NNReal) (n : ↑sd), fd y₁ y₂ n = f (↑n) y₂ - f (↑n) y₁)
708
+ (hd₁ : ∀ (n : ↑sd) (a b : NNReal), a < b → 0 < fd a b n)
709
+ (a b : NNReal)
710
+ (ha₀ : a < b)
711
+ (hd₃: ∀ (nd : ↑sd), nd.1 + (1:ℕ) ∈ sd)
712
+ (hd₂ : ∀ (nd : ↑sd), fd a b nd * (2 - 1 / ↑↑nd) ≤ fd a b ⟨nd.1 + 1, hd₃ nd⟩)
713
+ (hi₀ : 2 ∈ sd)
714
+ (i : ↑sd)
715
+ (hi₁ : i = ⟨2, hi₀⟩) :
716
+ ∀ (nd : ↑sd), fd a b i * (3 / 2) ^ (nd.1 - 2) ≤ fd a b nd := by
717
+ intro nd
718
+ rw [hfd₁ a b nd]
719
+ have hnd₀: 2 ≤ nd.1 := by
720
+ refine Set.mem_Ici.mp ?_
721
+ rw [← hsd]
722
+ exact nd.2
723
+ refine Nat.le_induction ?_ ?_ nd.1 hnd₀
724
+ . have hi₂: i.val = (2:ℕ) := by
725
+ simp_all only [Subtype.forall]
726
+ rw [hfd₁ a b i, hi₂]
727
+ simp
728
+ . simp
729
+ intros n hn₀ hn₁
730
+ have hn₂: n - 1 = n - 2 + 1 := by
731
+ simp
732
+ exact (Nat.sub_eq_iff_eq_add hn₀).mp rfl
733
+ have hn₃: n ∈ sd := by
734
+ rw [hsd]
735
+ exact hn₀
736
+ let nn : ↑sd := ⟨n, hn₃⟩
737
+ have hnn: nn.1 = n := by exact rfl
738
+ have hn₄: nn.1 + 1 ∈ sd := by
739
+ rw [hnn, hsd]
740
+ refine Set.mem_Ici.mpr ?_
741
+ exact Nat.le_add_right_of_le hn₀
742
+ have hn₅: fd a b nn * (2 - 1 / ↑n) ≤ fd a b ⟨nn.1 + 1, hn₄⟩ := by exact hd₂ nn
743
+ rw [hfd₁ a b ⟨nn.1 + 1, hn₄⟩] at hn₅
744
+ have hn₆: f (↑nn + 1) b - f (↑nn + 1) a = f (n + 1) b - f (n + 1) a := by exact rfl
745
+ rw [hn₆] at hn₅
746
+ refine le_trans ?_ hn₅
747
+ rw [hn₂, pow_succ (3/2) (n - 2), ← mul_assoc (fd a b i)]
748
+ refine mul_le_mul ?_ ?_ (by linarith) ?_
749
+ . refine le_of_le_of_eq hn₁ ?_
750
+ rw [hfd₁]
751
+ . refine (div_le_iff₀ (two_pos)).mpr ?_
752
+ rw [sub_mul, one_div_mul_eq_div _ 2]
753
+ refine le_sub_iff_add_le.mpr ?_
754
+ refine le_sub_iff_add_le'.mp ?_
755
+ refine (div_le_iff₀ ?_).mpr ?_
756
+ . refine Nat.cast_pos.mpr ?_
757
+ exact lt_of_lt_of_le (two_pos) hn₀
758
+ . ring_nf
759
+ exact Nat.ofNat_le_cast.mpr hn₀
760
+ . exact le_of_lt (hd₁ nn a b ha₀)
761
+
762
+
763
+
764
+ lemma aux_unique_top
765
+ (f : ℕ → NNReal → ℝ)
766
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
767
+ (h₇ : ∀ (n : ℕ) (x : NNReal), 0 < n → f n x < f (n + 1) x → 1 - 1 / ↑n < f n x)
768
+ (sd : Set ℕ)
769
+ (hsd : sd = Set.Ici 2)
770
+ (fd : NNReal → NNReal → ↑sd → ℝ)
771
+ (hfd₁ : ∀ (y₁ y₂ : NNReal) (n : ↑sd), fd y₁ y₂ n = f (↑n) y₂ - f (↑n) y₁)
772
+ (hd₁ : ∀ (n : ↑sd) (a b : NNReal), a < b → 0 < fd a b n) :
773
+ ∀ (a b : NNReal),
774
+ a < b →
775
+ (∀ (n : ↑sd), f (↑n) a < f (↑n + 1) a ∧ f (↑n) b < f (↑n + 1) b)
776
+ → Filter.Tendsto (fd a b) Filter.atTop Filter.atTop := by
777
+ intros a b ha₀ ha₁
778
+ have hd₀: ∀ (nd:↑sd), (nd.1 + 1) ∈ sd := by
779
+ intro nd
780
+ let t : ℕ := nd.1
781
+ have ht: t = nd.1 := by rfl
782
+ rw [← ht, hsd]
783
+ refine Set.mem_Ici.mpr ?_
784
+ refine Nat.le_add_right_of_le ?_
785
+ refine Set.mem_Ici.mp ?_
786
+ rw [ht, ← hsd]
787
+ exact nd.2
788
+ have hd₂: ∀ nd, fd a b nd * (2 - 1 / nd.1) ≤ fd a b ⟨nd.1 + 1, hd₀ nd⟩ := by
789
+ intro nd
790
+ have hnd₀: 0 < nd.1 := by
791
+ have g₀: 2 ≤ nd.1 := by
792
+ refine Set.mem_Ici.mp ?_
793
+ rw [← hsd]
794
+ exact nd.2
795
+ exact Nat.zero_lt_of_lt g₀
796
+ rw [hfd₁, hfd₁, h₁ nd.1 _ hnd₀, h₁ nd.1 _ hnd₀]
797
+ have hnd₁: f (↑nd) b * (f (↑nd) b + 1 / ↑↑nd) - f (↑nd) a * (f (↑nd) a + 1 / ↑↑nd) =
798
+ (f (↑nd) b - f (↑nd) a) * (f (↑nd) b + f (↑nd) a + 1 / nd.1) := by
799
+ ring_nf
800
+ rw [hnd₁]
801
+ refine (mul_le_mul_left ?_).mpr ?_
802
+ . rw [← hfd₁]
803
+ exact hd₁ nd a b ha₀
804
+ . refine le_sub_iff_add_le.mp ?_
805
+ rw [sub_neg_eq_add]
806
+ have hnd₂: 1 - 1 / nd.1 < f (↑nd) b := by
807
+ exact h₇ nd.1 b hnd₀ (ha₁ nd).2
808
+ have hnd₃: 1 - 1 / nd.1 < f (↑nd) a := by
809
+ exact h₇ nd.1 a hnd₀ (ha₁ nd).1
810
+ linarith
811
+ have hi: 2 ∈ sd := by
812
+ rw [hsd]
813
+ decide
814
+ let i : ↑sd := ⟨(2:ℕ), hi⟩
815
+ have hd₃: ∀ nd, fd a b i * (3 / 2) ^ (nd.1 - 2) ≤ fd a b nd := by
816
+ intro nd
817
+ exact aux_unique_top_ind f sd hsd fd hfd₁ hd₁ a b ha₀ hd₀ hd₂ hi i rfl nd
818
+ have hsd₁: Nonempty ↑sd := by
819
+ refine Set.Nonempty.to_subtype ?_
820
+ exact Set.nonempty_of_mem (hd₀ i)
821
+ refine Filter.tendsto_atTop_atTop.mpr ?_
822
+ intro z
823
+ by_cases hz₀: z ≤ fd a b i
824
+ . use i
825
+ intros j _
826
+ refine le_trans hz₀ ?_
827
+ refine le_trans ?_ (hd₃ j)
828
+ refine le_mul_of_one_le_right ?_ ?_
829
+ . refine le_of_lt ?_
830
+ exact hd₁ i a b ha₀
831
+ . refine one_le_pow₀ ?_
832
+ linarith
833
+ . push_neg at hz₀
834
+ have hz₁: 0 < fd a b i := by exact hd₁ i a b ha₀
835
+ have hz₂: 0 < Real.log (z / fd a b i) := by
836
+ refine Real.log_pos ?_
837
+ exact (one_lt_div hz₁).mpr hz₀
838
+ let j : ℕ := Nat.ceil (2 + Real.log (z / fd a b i) / Real.log (3 / 2))
839
+ have hj₀: 2 < j := by
840
+ refine Nat.lt_ceil.mpr ?_
841
+ norm_cast
842
+ refine lt_add_of_pos_right 2 ?_
843
+ refine div_pos ?_ ?_
844
+ . exact hz₂
845
+ . refine Real.log_pos ?_
846
+ linarith
847
+ have hj₁: j ∈ sd := by
848
+ rw [hsd]
849
+ exact Set.mem_Ici_of_Ioi hj₀
850
+ use ⟨j, hj₁⟩
851
+ intro k hk₀
852
+ have hk₁: fd a b i * (3 / 2) ^ (k.1 - 2) ≤ fd a b k := by
853
+ exact hd₃ k
854
+ have hk₂: i < k := by
855
+ refine lt_of_lt_of_le ?_ hk₀
856
+ refine Subtype.mk_lt_mk.mpr ?_
857
+ refine Nat.lt_ceil.mpr ?_
858
+ norm_cast
859
+ refine lt_add_of_pos_right 2 ?_
860
+ refine div_pos ?_ ?_
861
+ . exact hz₂
862
+ . refine Real.log_pos ?_
863
+ linarith
864
+ refine le_trans ?_ hk₁
865
+ refine (div_le_iff₀' ?_).mp ?_
866
+ . exact hz₁
867
+ . refine Real.le_pow_of_log_le (by linarith) ?_
868
+ refine (div_le_iff₀ ?_).mp ?_
869
+ . refine Real.log_pos ?_
870
+ linarith
871
+ . rw [Nat.cast_sub ?_]
872
+ . rw [Nat.cast_two]
873
+ refine le_sub_iff_add_le'.mpr ?_
874
+ exact Nat.le_of_ceil_le hk₀
875
+ . exact Nat.le_of_succ_le hk₂
876
+
877
+
878
+
879
+ lemma aux_unique_nhds
880
+ (f : ℕ → NNReal → ℝ)
881
+ (sd : Set ℕ)
882
+ (hsd : sd = Set.Ici 2)
883
+ (fd : NNReal → NNReal → ↑sd → ℝ)
884
+ (hfd₁ : ∀ (y₁ y₂ : NNReal) (n : ↑sd), fd y₁ y₂ n = f (↑n) y₂ - f (↑n) y₁)
885
+ (hd₁ : ∀ (n : ↑sd) (a b : NNReal), a < b → 0 < fd a b n) :
886
+ ∀ (a b : NNReal),
887
+ a < b →
888
+ (∀ (n : ↑sd), (1 - 1 / ↑↑n < f (↑n) a ∧ 1 - 1 / ↑↑n < f (↑n) b) ∧ f (↑n) a < 1 ∧ f (↑n) b < 1) →
889
+ Filter.Tendsto (fd a b) Filter.atTop (nhds 0) := by
890
+ intros a b ha₀ ha₁
891
+ have hsd₁: Nonempty ↑sd := by
892
+ rw [hsd]
893
+ refine Set.Nonempty.to_subtype ?_
894
+ exact Set.nonempty_Ici
895
+ refine tendsto_atTop_nhds.mpr ?_
896
+ intros U hU₀ hU₁
897
+ have hU₂: U ∈ nhds 0 := by exact IsOpen.mem_nhds hU₁ hU₀
898
+ apply mem_nhds_iff_exists_Ioo_subset.mp at hU₂
899
+ obtain ⟨l, u, hl₀, hl₁⟩ := hU₂
900
+ have hl₂: 0 < u := by exact (Set.mem_Ioo.mpr hl₀).2
901
+ let nd := 2 + Nat.ceil (1/u)
902
+ have hnd₀: nd ∈ sd := by
903
+ rw [hsd]
904
+ refine Set.mem_Ici.mpr ?_
905
+ exact Nat.le_add_right 2 ⌈1 / u⌉₊
906
+ use ⟨nd, hnd₀⟩
907
+ intros n hn₀
908
+ refine (IsOpen.mem_nhds_iff hU₁).mp ?_
909
+ refine mem_nhds_iff.mpr ?_
910
+ use Set.Ioo l u
911
+ constructor
912
+ . exact hl₁
913
+ constructor
914
+ . exact isOpen_Ioo
915
+ . refine Set.mem_Ioo.mpr ?_
916
+ constructor
917
+ . refine lt_trans ?_ (hd₁ n a b ha₀)
918
+ exact (Set.mem_Ioo.mp hl₀).1
919
+ . have hn₁: fd a b n < 1 / n := by
920
+ rw [hfd₁]
921
+ have ha₂: 1 - 1 / n < f n a := by exact (ha₁ n).1.1
922
+ have hb₁: f n b < 1 := by exact (ha₁ n).2.2
923
+ refine sub_lt_iff_lt_add.mpr ?_
924
+ refine lt_trans hb₁ ?_
925
+ exact sub_lt_iff_lt_add'.mp ha₂
926
+ have hn₂: (1:ℝ) / n ≤ 1 / nd := by
927
+ refine one_div_le_one_div_of_le ?_ ?_
928
+ . refine Nat.cast_pos.mpr ?_
929
+ rw [hsd] at hnd₀
930
+ exact lt_of_lt_of_le (Nat.zero_lt_two) hnd₀
931
+ . exact Nat.cast_le.mpr hn₀
932
+ refine lt_of_lt_of_le hn₁ ?_
933
+ refine le_trans hn₂ ?_
934
+ refine div_le_of_le_mul₀ ?_ ?_ ?_
935
+ . exact Nat.cast_nonneg' nd
936
+ . exact le_of_lt hl₂
937
+ . have hl₃: u * (2 + 1 / u) ≤ u * ↑((2:ℕ) + ⌈(1:ℝ) / u⌉₊) := by
938
+ refine (mul_le_mul_left hl₂).mpr ?_
939
+ rw [Nat.cast_add 2 _, Nat.cast_two]
940
+ refine add_le_add_left ?_ 2
941
+ exact Nat.le_ceil (1 / u)
942
+ refine le_trans ?_ hl₃
943
+ rw [mul_add, mul_one_div u u, div_self (ne_of_gt hl₂)]
944
+ refine le_of_lt ?_
945
+ refine sub_lt_iff_lt_add.mp ?_
946
+ rw [sub_self 1]
947
+ exact mul_pos hl₂ (two_pos)
948
+
949
+
950
+
951
+
952
+ lemma aux_unique
953
+ (f : ℕ → NNReal → ℝ)
954
+ (h₁ : ∀ (n : ℕ) (x : NNReal), 0 < n → f (n + 1) x = f n x * (f n x + 1 / ↑n))
955
+ (hmo₀ : ∀ (n : ℕ), 0 < n → StrictMono (f n))
956
+ (h₇ : ∀ (n : ℕ) (x : NNReal), 0 < n → f n x < f (n + 1) x → 1 - 1 / ↑n < f n x) :
957
+ ∀ (y₁ y₂ : NNReal),
958
+ (∀ (n : ℕ), 0 < n → 0 < f n y₁ ∧ f n y₁ < f (n + 1) y₁ ∧ f (n + 1) y₁ < 1) →
959
+ (∀ (n : ℕ), 0 < n → 0 < f n y₂ ∧ f n y₂ < f (n + 1) y₂ ∧ f (n + 1) y₂ < 1) → y₁ = y₂ := by
960
+ intros x y hx₀ hy₀
961
+ let sd : Set ℕ := Set.Ici 2
962
+ let fd : NNReal → NNReal → ↑sd → ℝ := fun y₁ y₂ n => (f n.1 y₂ - f n.1 y₁)
963
+ have hfd₁: ∀ y₁ y₂ n, fd y₁ y₂ n = f n.1 y₂ - f n.1 y₁ := by exact fun y₁ y₂ n => rfl
964
+ have hd₁: ∀ n a b, a < b → 0 < fd a b n := by
965
+ intros nd a b hnd₀
966
+ rw [hfd₁]
967
+ refine sub_pos.mpr ?_
968
+ refine hmo₀ nd.1 ?_ hnd₀
969
+ exact lt_of_lt_of_le (Nat.zero_lt_two) nd.2
970
+ have hfd₂: ∀ a b, a < b → (∀ n:↑sd, f n.1 a < f (n.1 + 1) a ∧ f n.1 b < f (n.1 + 1) b)
971
+ → Filter.Tendsto (fd a b) Filter.atTop Filter.atTop := by
972
+ intros a b ha₀ ha₁
973
+ exact aux_unique_top f h₁ h₇ sd rfl fd hfd₁ hd₁ a b ha₀ ha₁
974
+ have hfd₃: ∀ a b, a < b → (∀ (n:↑sd), (1 - 1 / n.1 < f n.1 a ∧ 1 - 1 / n.1 < f n.1 b) ∧ (f n.1 a < 1 ∧ f n.1 b < 1))
975
+ → Filter.Tendsto (fd a b) Filter.atTop (nhds 0) := by
976
+ intros a b ha₀ ha₁
977
+ exact aux_unique_nhds f sd rfl fd hfd₁ hd₁ a b ha₀ ha₁
978
+ by_contra! hc₀
979
+ by_cases hy₁: x < y
980
+ . have hy₂: Filter.Tendsto (fd x y) Filter.atTop Filter.atTop := by
981
+ refine hfd₂ x y hy₁ ?_
982
+ intro nd
983
+ have hnd₀: 0 < nd.1 := by exact lt_of_lt_of_le (two_pos) nd.2
984
+ constructor
985
+ . exact (hx₀ nd.1 hnd₀).2.1
986
+ . exact (hy₀ nd.1 hnd₀).2.1
987
+ have hy₃: Filter.Tendsto (fd x y) Filter.atTop (nhds 0) := by
988
+ refine hfd₃ x y hy₁ ?_
989
+ intro nd
990
+ have hnd₀: 0 < nd.1 := by
991
+ refine lt_of_lt_of_le ?_ nd.2
992
+ exact Nat.zero_lt_two
993
+ have hnd₁: nd.1 - 1 + 1 = nd.1 := by exact Nat.sub_add_cancel hnd₀
994
+ have hnd₂: 0 < nd.1 - 1 := by
995
+ refine Nat.sub_pos_of_lt ?_
996
+ refine lt_of_lt_of_le ?_ nd.2
997
+ exact Nat.one_lt_two
998
+ constructor
999
+ . constructor
1000
+ . refine h₇ nd.1 x hnd₀ ?_
1001
+ exact (hx₀ (nd.1) hnd₀).2.1
1002
+ . refine h₇ nd.1 y hnd₀ ?_
1003
+ exact (hy₀ (nd.1) hnd₀).2.1
1004
+ . constructor
1005
+ . rw [← hnd₁]
1006
+ exact (hx₀ (nd.1 - 1) hnd₂).2.2
1007
+ . rw [← hnd₁]
1008
+ exact (hy₀ (nd.1 - 1) hnd₂).2.2
1009
+ apply Filter.tendsto_atTop_atTop.mp at hy₂
1010
+ apply tendsto_atTop_nhds.mp at hy₃
1011
+ contrapose! hy₃
1012
+ clear hy₃
1013
+ let sx : Set ℝ := Set.Ioo (-1) 1
1014
+ use sx
1015
+ constructor
1016
+ . refine Set.mem_Ioo.mpr ?_
1017
+ simp
1018
+ constructor
1019
+ . exact isOpen_Ioo
1020
+ . intro N
1021
+ have hy₅: ∃ i, ∀ (a : ↑sd), i ≤ a → N + 3 ≤ fd x y a := by exact hy₂ (N + 3)
1022
+ obtain ⟨i, hi₀⟩ := hy₅
1023
+ have hi₁: (N.1 + i.1) ∈ sd := by
1024
+ refine Set.mem_Ici.mpr ?_
1025
+ rw [← add_zero 2]
1026
+ refine Nat.add_le_add ?_ ?_
1027
+ . exact N.2
1028
+ . refine le_trans ?_ i.2
1029
+ exact Nat.zero_le 2
1030
+ let a : ↑sd := ⟨N + i, hi₁⟩
1031
+ use a
1032
+ constructor
1033
+ . refine Subtype.mk_le_mk.mpr ?_
1034
+ exact Nat.le_add_right ↑N ↑i
1035
+ . refine Set.not_mem_Ioo_of_ge ?_
1036
+ have hi₂: ↑↑N + 3 ≤ fd x y a := by
1037
+ refine hi₀ a ?_
1038
+ refine Subtype.mk_le_mk.mpr ?_
1039
+ exact Nat.le_add_left ↑i ↑N
1040
+ refine le_trans ?_ hi₂
1041
+ norm_cast
1042
+ exact Nat.le_add_left 1 (↑N + 2)
1043
+ . have hy₂: y < x := by
1044
+ push_neg at hy₁
1045
+ exact lt_of_le_of_ne hy₁ hc₀.symm
1046
+ have hy₃: Filter.Tendsto (fd y x) Filter.atTop Filter.atTop := by
1047
+ refine hfd₂ y x hy₂ ?_
1048
+ intro nd
1049
+ have hnd₀: 0 < nd.1 := by exact lt_of_lt_of_le (two_pos) nd.2
1050
+ constructor
1051
+ . exact (hy₀ nd.1 hnd₀).2.1
1052
+ . exact (hx₀ nd.1 hnd₀).2.1
1053
+ have hy₄: Filter.Tendsto (fd y x) Filter.atTop (nhds 0) := by
1054
+ refine hfd₃ y x hy₂ ?_
1055
+ intro nd
1056
+ have hnd₀: 0 < nd.1 := by exact lt_of_lt_of_le (Nat.zero_lt_two) nd.2
1057
+ have hnd₁: nd.1 - 1 + 1 = nd.1 := by exact Nat.sub_add_cancel hnd₀
1058
+ have hnd₂: 0 < nd.1 - 1 := by
1059
+ refine Nat.sub_pos_of_lt ?_
1060
+ exact lt_of_lt_of_le (Nat.one_lt_two) nd.2
1061
+ constructor
1062
+ . constructor
1063
+ . refine h₇ nd.1 y hnd₀ ?_
1064
+ exact (hy₀ (nd.1) hnd₀).2.1
1065
+ . refine h₇ nd.1 x hnd₀ ?_
1066
+ exact (hx₀ (nd.1) hnd₀).2.1
1067
+ . constructor
1068
+ . rw [← hnd₁]
1069
+ exact (hy₀ (nd.1 - 1) hnd₂).2.2
1070
+ . rw [← hnd₁]
1071
+ exact (hx₀ (nd.1 - 1) hnd₂).2.2
1072
+ apply Filter.tendsto_atTop_atTop.mp at hy₃
1073
+ apply tendsto_atTop_nhds.mp at hy₄
1074
+ contrapose! hy₄
1075
+ clear hy₄
1076
+ let sx : Set ℝ := Set.Ioo (-1) 1
1077
+ use sx
1078
+ constructor
1079
+ . refine Set.mem_Ioo.mpr ?_
1080
+ simp
1081
+ constructor
1082
+ . exact isOpen_Ioo
1083
+ . intro N
1084
+ have hy₅: ∃ i, ∀ (a : ↑sd), i ≤ a → N + 3 ≤ fd y x a := by exact hy₃ (N + 3)
1085
+ obtain ⟨i, hi₀⟩ := hy₅
1086
+ have hi₁: (N.1 + i.1) ∈ sd := by
1087
+ refine Set.mem_Ici.mpr ?_
1088
+ rw [← add_zero 2]
1089
+ refine Nat.add_le_add ?_ ?_
1090
+ . exact N.2
1091
+ . refine le_trans ?_ i.2
1092
+ exact Nat.zero_le 2
1093
+ let a : ↑sd := ⟨N + i, hi₁⟩
1094
+ use a
1095
+ constructor
1096
+ . refine Subtype.mk_le_mk.mpr ?_
1097
+ exact Nat.le_add_right ↑N ↑i
1098
+ . refine Set.not_mem_Ioo_of_ge ?_
1099
+ have hi₂: ↑↑N + 3 ≤ fd y x a := by
1100
+ refine hi₀ a ?_
1101
+ refine Subtype.mk_le_mk.mpr ?_
1102
+ exact Nat.le_add_left ↑i ↑N
1103
+ refine le_trans ?_ hi₂
1104
+ norm_cast
1105
+ exact Nat.le_add_left 1 (↑N + 2)
1106
+
1107
+
1108
+
1109
+
1110
+ theorem imo_1985_p6
1111
+ (f : ℕ → NNReal → ℝ)
1112
+ (h₀ : ∀ x, f 1 x = x)
1113
+ (h₁ : ∀ n x, 0 < n → f (n + 1) x = f n x * (f n x + 1 / n)) :
1114
+ ∃! a, ∀ n, 0 < n → 0 < f n a ∧ f n a < f (n + 1) a ∧ f (n + 1) a < 1 := by
1115
+ have h₂: ∀ n x, 0 < n ∧ 0 < x → 0 < f n x := by
1116
+ exact fun n x a => aux_1 f h₀ h₁ n x a
1117
+ have h₃: ∀ n x, 0 < n → 0 ≤ f n x := by
1118
+ intros n x hn
1119
+ refine Nat.le_induction ?_ ?_ n hn
1120
+ . rw [h₀ x]
1121
+ exact NNReal.zero_le_coe
1122
+ . intros d hd₀ hd₁
1123
+ rw [h₁ d x hd₀]
1124
+ refine mul_nonneg hd₁ ?_
1125
+ refine add_nonneg hd₁ ?_
1126
+ refine div_nonneg (by linarith) ?_
1127
+ exact Nat.cast_nonneg' d
1128
+ have hmo₀: ∀ n, 0 < n → StrictMono (f n) := by
1129
+ intros n hn₀
1130
+ refine Monotone.strictMono_of_injective ?h₁ ?h₂
1131
+ . refine monotone_iff_forall_lt.mpr ?h₁.a
1132
+ intros a b hab
1133
+ refine le_of_lt ?_
1134
+ exact aux_2 f h₀ h₁ h₂ h₃ n a b hn₀ hab
1135
+ . intros p q hpq
1136
+ contrapose! hpq
1137
+ apply lt_or_gt_of_ne at hpq
1138
+ cases' hpq with hpq hpq
1139
+ . refine ne_of_lt ?_
1140
+ exact aux_2 f h₀ h₁ h₂ h₃ n p q hn₀ hpq
1141
+ . symm
1142
+ refine ne_of_lt ?_
1143
+ exact aux_2 f h₀ h₁ h₂ h₃ n q p hn₀ hpq
1144
+ have hmo₁: ∀ n, 0 < n → Function.Injective (f n) := by exact fun n a => StrictMono.injective (hmo₀ n a)
1145
+ let f₀: ℕ → NNReal → NNReal := fun n x => (f n x).toNNReal
1146
+ have hf₀: f₀ = fun n x => (f n x).toNNReal := by rfl
1147
+ have hf₁: ∀ n x, 0 < n → f n x = f₀ n x := by
1148
+ intros n x hn₀
1149
+ rw [hf₀]
1150
+ simp
1151
+ exact h₃ n x hn₀
1152
+ have hf₂: ∀ n x, 0 < n → f₀ n x = (f n x).toNNReal := by
1153
+ intros n x _
1154
+ rw [hf₀]
1155
+ have hmo₂: ∀ n, 0 < n → StrictMono (f₀ n) := by
1156
+ intros n hn₀
1157
+ refine aux_4 f h₃ ?_ f₀ hf₀ n hn₀
1158
+ exact fun n x y a a_1 => hmo₀ n a a_1
1159
+ let fi : ℕ → NNReal → NNReal := fun n => Function.invFun (f₀ n)
1160
+ have hmo₇: ∀ n, 0 < n → Function.RightInverse (fi n) (f₀ n) := by
1161
+ intros n hn₀
1162
+ refine Function.rightInverse_invFun ?_
1163
+ have h₄: ∀ n x y, 0 < n → x < y → f n x < f n y := by
1164
+ exact fun n x y a a_1 => aux_2 f h₀ h₁ h₂ h₃ n x y a a_1
1165
+ refine aux_7 f h₀ h₁ h₃ ?_ f₀ hf₂ hmo₂ ?_ n hn₀
1166
+ . exact fun n x a => aux_3 f h₀ h₁ h₄ n x a
1167
+ . intros m hm₀
1168
+ exact aux_6 f h₀ h₁ f₀ hf₀ m hm₀
1169
+ have hf₇: ∀ n x y, 0 < n → (f₀ n x = y ↔ fi n y = x) := by
1170
+ intros n x y hn₀
1171
+ constructor
1172
+ . intro hn₁
1173
+ rw [← hn₁, hf₀]
1174
+ have hn₂: (Function.invFun (f n)) ∘ (f n) = id := by exact Function.invFun_comp (hmo₁ n hn₀)
1175
+ rw [Function.comp_def (Function.invFun (f n)) (f n)] at hn₂
1176
+ exact aux_5 f hmo₁ f₀ hmo₂ fi rfl n x ((fun n x => (f n x).toNNReal) n x) hn₀ (hf₂ n x hn₀)
1177
+ . intro hn₁
1178
+ rw [← hn₁]
1179
+ exact hmo₁ n hn₀ (congrArg (f n) (hmo₇ n hn₀ y))
1180
+ let sn : Set ℕ := Set.Ici 1
1181
+ let fb : ↑sn → NNReal := sn.restrict (fun (n:ℕ) => fi n (1 - 1 / (n:NNReal)))
1182
+ let fc : ↑sn → NNReal := sn.restrict (fun (n:ℕ) => fi n 1)
1183
+ have hsn₁: ∀ n:↑sn, ↑n ∈ sn ∧ 0 < (↑n:ℕ) := by
1184
+ intro n
1185
+ have hn₀: ↑n ∈ sn := by exact Subtype.coe_prop n
1186
+ constructor
1187
+ . exact Subtype.coe_prop n
1188
+ . exact hn₀
1189
+ have hfb₀: fb = fun (n:↑sn) => fi n (1 - 1 / (n:NNReal)) := by rfl
1190
+ have hfc₀: fc = fun (n:↑sn) => fi n 1 := by rfl
1191
+ have hfb₁: ∀ n:↑sn, f₀ n (fb n) = 1 - 1 / (n:NNReal) := by
1192
+ intros n
1193
+ have hn₀: 0 < (n:ℕ) := by exact (hsn₁ n).2
1194
+ rw [hfb₀]
1195
+ exact hmo₁ n hn₀ (congrArg (f n) (hmo₇ n hn₀ (1 - 1 / (n:NNReal))))
1196
+ have hfc₁: ∀ n:↑sn, f₀ n (fc n) = 1 := by
1197
+ intros n
1198
+ have hn₀: 0 < (n:ℕ) := by exact (hsn₁ n).2
1199
+ rw [hfc₀]
1200
+ exact hmo₁ n hn₀ (congrArg (f n) (hmo₇ n hn₀ 1))
1201
+ have hu₁: ∀ n:↑sn, fb n < 1 := by
1202
+ exact aux_8 f h₀ h₁ hmo₀ hmo₁ f₀ hf₂ sn fb hsn₁ hfb₁
1203
+ have hfc₂: ∀ n:↑sn, fb n < fc n := by
1204
+ intros n
1205
+ have hn₀: 0 < (n:ℕ) := by exact (hsn₁ n).2
1206
+ have g₀: f₀ n (fb n) < f₀ n (fc n) := by
1207
+ rw [hfb₁ n, hfc₁ n]
1208
+ simp
1209
+ exact (hsn₁ n).2
1210
+ exact (StrictMono.lt_iff_lt (hmo₂ n hn₀)).mp g₀
1211
+ have hfb₃: StrictMono fb := by
1212
+ refine StrictMonoOn.restrict ?_
1213
+ refine aux_9 f h₀ h₁ f₀ hf₁ hf₂ hmo₂ fi ?_ hmo₇ hf₇ _ (by rfl) sn (by rfl)
1214
+ intro x
1215
+ refine (hf₇ 1 x x (by linarith)).mp ?_
1216
+ rw [hf₂ 1 x (by linarith), h₀]
1217
+ exact Real.toNNReal_coe
1218
+ have hfc₃: StrictAnti fc := by
1219
+ have g₀: StrictAntiOn (fun n => fi n 1) sn := by
1220
+ refine strictAntiOn_Ici_of_lt_pred ?_
1221
+ intros m hm₀
1222
+ have hm₁: 0 < m - 1 := by exact Nat.zero_lt_sub_of_lt hm₀
1223
+ have hm₂: m = m - 1 + 1 := by rw [Nat.sub_add_cancel (le_of_lt hm₀)]
1224
+ have hm₃: 0 < m := by exact Nat.zero_lt_of_lt hm₀
1225
+ simp
1226
+ let x := fi m 1
1227
+ let y := fi (m - 1) 1
1228
+ have hx₀: x = fi m 1 := by rfl
1229
+ have hy₀: y = fi (m - 1) 1 := by rfl
1230
+ have hx₁: f₀ m x = 1 := by exact (hf₇ m x 1 (by linarith)).mpr hx₀.symm
1231
+ have hy₁: f₀ (m - 1) y = 1 := by
1232
+ exact (hf₇ (m - 1) y 1 hm₁).mpr hy₀.symm
1233
+ have hy₂: f (m - 1) y = 1 := by
1234
+ rw [hf₁ (m - 1) y hm₁, hy₁]
1235
+ exact rfl
1236
+ have hf: StrictMono (f m) := by exact hmo₀ m hm₃
1237
+ refine (StrictMono.lt_iff_lt hf).mp ?_
1238
+ rw [← hx₀, ← hy₀]
1239
+ rw [hf₁ m x hm₃, hf₁ m y hm₃]
1240
+ refine NNReal.coe_lt_coe.mpr ?_
1241
+ rw [hx₁, hf₂ m y hm₃, hm₂, h₁ (m - 1) y hm₁, hy₂]
1242
+ simp
1243
+ exact hm₀
1244
+ intros m n hmn
1245
+ rw [hfc₀]
1246
+ simp
1247
+ let mn : ℕ := ↑m
1248
+ let nn : ℕ := ↑n
1249
+ have hm₀: mn ∈ sn := by exact Subtype.coe_prop m
1250
+ have hn₀: nn ∈ sn := by exact Subtype.coe_prop n
1251
+ exact g₀ hm₀ hn₀ hmn
1252
+ let sb := Set.range fb
1253
+ let sc := Set.range fc
1254
+ have hsb₀: sb = Set.range fb := by rfl
1255
+ have hsc₀: sc = Set.range fc := by rfl
1256
+ let fr : NNReal → ℝ := fun x => x.toReal
1257
+ let sbr := Set.image fr sb
1258
+ let scr := Set.image fr sc
1259
+ have hu₃: ∃ br, IsLUB sbr br := by
1260
+ refine Real.exists_isLUB ?_ ?_
1261
+ . exact Set.Nonempty.of_subtype
1262
+ . refine NNReal.bddAbove_coe.mpr ?_
1263
+ refine (bddAbove_iff_exists_ge 1).mpr ?_
1264
+ use 1
1265
+ constructor
1266
+ . exact Preorder.le_refl 1
1267
+ . intros y hy₀
1268
+ apply Set.mem_range.mp at hy₀
1269
+ obtain ⟨na, hna₀⟩ := hy₀
1270
+ refine le_of_lt ?_
1271
+ rw [← hna₀]
1272
+ exact hu₁ na
1273
+ have hu₄: ∃ cr, IsGLB scr cr := by
1274
+ refine Real.exists_isGLB ?_ ?_
1275
+ . refine Set.Nonempty.image fr ?_
1276
+ exact Set.range_nonempty fc
1277
+ . exact NNReal.bddBelow_coe sc
1278
+ obtain ⟨br, hbr₀⟩ := hu₃
1279
+ obtain ⟨cr, hcr₀⟩ := hu₄
1280
+ have h₇: ∀ n x, 0 < n → (f n x < f (n + 1) x → 1 - 1 / n < f n x) := by
1281
+ intros n x hn₀ hn₁
1282
+ rw [h₁ n x hn₀] at hn₁
1283
+ nth_rw 1 [← mul_one (f n x)] at hn₁
1284
+ suffices g₀: 1 < f n x + 1 / ↑n
1285
+ . exact sub_right_lt_of_lt_add g₀
1286
+ . refine lt_of_mul_lt_mul_left hn₁ ?_
1287
+ exact h₃ n x hn₀
1288
+ have h₈: ∀ n x, 0 < n → 0 < x → 1 - 1 / n < f n x → f n x < f (n + 1) x := by
1289
+ intros n x hn₀ hx₀ hn₁
1290
+ rw [h₁ n x hn₀]
1291
+ suffices g₀: 1 < f n x + 1 / ↑n
1292
+ . nth_rw 1 [← mul_one (f n x)]
1293
+ refine mul_lt_mul' ?_ g₀ ?_ ?_
1294
+ . exact Preorder.le_refl (f n x)
1295
+ . exact zero_le_one' ℝ
1296
+ . exact gt_of_gt_of_ge (hmo₀ n hn₀ hx₀) (h₃ n 0 hn₀)
1297
+ . exact lt_add_of_tsub_lt_right hn₁
1298
+ have hbr₁: 0 < br := by
1299
+ exact aux_10 f h₀ h₁ f₀ hf₂ fi hmo₇ sn sb fb (by rfl) hfb₀ hsb₀ fr (by rfl) sbr (by rfl) br hbr₀
1300
+ have hfb₄: ∀ n, 0 ≤ fb n := by
1301
+ intro n
1302
+ have hfb₂: fb = fun (n:↑sn) => Function.invFun (f₀ n) (1 - 1 / ↑n) := by exact hfb₀
1303
+ rw [hfb₂]
1304
+ simp
1305
+ have hu₅: br ≤ cr := by
1306
+ exact aux_11 sn fb fc hfc₂ hfb₃ hfc₃ sb sc hsb₀ hsc₀ fr (by rfl) sbr scr (by rfl) (by rfl) br cr hbr₀ hcr₀ hfb₄
1307
+ have hbr₃: ∀ x ∈ sbr, x ≤ br := by
1308
+ refine mem_upperBounds.mp ?_
1309
+ refine (isLUB_le_iff hbr₀).mp ?_
1310
+ exact Preorder.le_refl br
1311
+ have hcr₃: ∀ x ∈ scr, cr ≤ x := by
1312
+ refine mem_lowerBounds.mp ?_
1313
+ refine (le_isGLB_iff hcr₀).mp ?_
1314
+ exact Preorder.le_refl cr
1315
+ refine existsUnique_of_exists_of_unique ?_ ?_
1316
+ . exact aux_exists f h₂ hmo₀ f₀ hf₁ sn (by rfl) fb fc hfb₁ hfc₁ hfb₃ hfc₃ sb sc hsb₀ hsc₀ fr (by rfl) sbr scr (by rfl) (by rfl) br cr h₈ hbr₁ hu₅ hbr₃ hcr₃
1317
+ . intros x y hx₀ hy₀
1318
+ exact aux_unique f h₁ hmo₀ h₇ x y hx₀ hy₀
imo_proofs/imo_1992_p1.lean ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Int Rat
5
+
6
+
7
+ lemma mylemma_main_lt2
8
+ (p q r: ℤ)
9
+ (hpl: 4 ≤ p)
10
+ (hql: 5 ≤ q)
11
+ (hrl: 6 ≤ r) :
12
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
13
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
14
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) := by
15
+ norm_cast
16
+ simp
17
+ have hp: (↑p/↑(p-1):ℚ) ≤ ((4/3):ℚ) := by
18
+ have g₁: 0 < (↑(p - 1):ℚ) := by
19
+ norm_cast
20
+ linarith [hpl]
21
+ have g₂: ↑p * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(p - 1):ℚ) := by
22
+ norm_cast
23
+ linarith
24
+ refine (div_le_iff₀ g₁).mpr ?_
25
+ rw [div_mul_eq_mul_div]
26
+ refine (le_div_iff₀ ?_).mpr g₂
27
+ norm_num
28
+ have hq: (↑q/↑(q-1)) ≤ ((5/4):ℚ) := by
29
+ have g₁: 0 < (↑(q - 1):ℚ) := by
30
+ norm_cast
31
+ linarith[hql]
32
+ have g₂: ↑q * ↑(4:ℚ) ≤ ↑(5:ℚ) * (↑(q - 1):ℚ) := by
33
+ norm_cast
34
+ linarith
35
+ refine (div_le_iff₀ g₁).mpr ?_
36
+ rw [div_mul_eq_mul_div]
37
+ refine (le_div_iff₀ ?_).mpr g₂
38
+ norm_num
39
+ have hr: (↑r/↑(r-1)) ≤ ((6/5):ℚ) := by
40
+ have g₁: 0 < (↑(r - 1):ℚ) := by
41
+ norm_cast
42
+ linarith[hql]
43
+ have g₂: ↑r * ↑(5:ℚ) ≤ ↑(6:ℚ) * (↑(r - 1):ℚ) := by
44
+ norm_cast
45
+ linarith
46
+ refine (div_le_iff₀ g₁).mpr ?_
47
+ rw [div_mul_eq_mul_div]
48
+ refine (le_div_iff₀ ?_).mpr g₂
49
+ norm_num
50
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (4/3:ℚ) * ((5/4):ℚ) * ((6/5):ℚ) := by
51
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
52
+ norm_cast
53
+ linarith
54
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
55
+ norm_cast
56
+ linarith
57
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
58
+ exact div_nonneg hq_nonneg hq_1_nonneg
59
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ ((4/3):ℚ) * ((5/4):ℚ) := by
60
+ exact mul_le_mul hp hq h₂ (by norm_num)
61
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
62
+ norm_cast
63
+ linarith
64
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
65
+ norm_cast
66
+ linarith
67
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
68
+ exact div_nonneg hr_nonneg hr_1_nonneg
69
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
70
+ norm_num at hub
71
+ rw [h₁]
72
+ norm_num
73
+ exact hub
74
+
75
+
76
+ lemma mylemma_k_lt_2
77
+ (p q r k: ℤ)
78
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
79
+ (hpl: 4 ≤ p)
80
+ (hql: 5 ≤ q)
81
+ (hrl: 6 ≤ r)
82
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
83
+ (k < 2) := by
84
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑2 := by
85
+ exact mylemma_main_lt2 p q r hpl hql hrl
86
+ have h₂: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
87
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
88
+ norm_cast
89
+ linarith
90
+ symm
91
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
92
+ norm_cast
93
+ linarith[hden]
94
+ exact (div_eq_iff g₂).mpr g₁
95
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
96
+ rw [h₂]
97
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
98
+ norm_cast
99
+ exact sub_one_lt (p * q * r)
100
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
101
+ norm_cast
102
+ exact div_lt_div_of_pos_right g₁ g₂
103
+ have h₄: (↑k:ℚ) < ↑2 := by
104
+ exact lt_of_lt_of_le h₃ h₁
105
+ norm_cast at h₄
106
+
107
+
108
+ lemma mylemma_main_lt4
109
+ (p q r: ℤ)
110
+ (hpl: 2 ≤ p)
111
+ (hql: 3 ≤ q)
112
+ (hrl: 4 ≤ r) :
113
+ (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑4 := by
114
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ)
115
+ = (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) := by
116
+ norm_cast
117
+ simp
118
+ have hp: (↑p/↑(p-1):ℚ) ≤ ↑(2:ℚ) := by
119
+ have g₁: 0 < (↑(p - 1):ℚ) := by
120
+ norm_cast
121
+ linarith[hpl]
122
+ have g₂: ↑p ≤ ↑(2:ℚ) * (↑(p - 1):ℚ) := by
123
+ norm_cast
124
+ linarith
125
+ exact (div_le_iff₀ g₁).mpr g₂
126
+ have hq: (↑q/↑(q-1)) ≤ ((3/2):ℚ) := by
127
+ have g₁: 0 < (↑(q - 1):ℚ) := by
128
+ norm_cast
129
+ linarith[hql]
130
+ have g₂: ↑q * ↑(2:ℚ) ≤ ↑(3:ℚ) * (↑(q - 1):ℚ) := by
131
+ norm_cast
132
+ linarith
133
+ refine (div_le_iff₀ g₁).mpr ?_
134
+ rw [div_mul_eq_mul_div]
135
+ refine (le_div_iff₀ ?_).mpr g₂
136
+ norm_num
137
+ have hr: (↑r/↑(r-1)) ≤ ((4/3):ℚ) := by
138
+ have g₁: 0 < (↑(r - 1):ℚ) := by
139
+ norm_cast
140
+ linarith[hql]
141
+ have g₂: ↑r * ↑(3:ℚ) ≤ ↑(4:ℚ) * (↑(r - 1):ℚ) := by
142
+ norm_cast
143
+ linarith
144
+ refine (div_le_iff₀ g₁).mpr ?_
145
+ rw [div_mul_eq_mul_div]
146
+ refine (le_div_iff₀ ?_).mpr g₂
147
+ norm_num
148
+ have hub: (↑p/↑(p-1)) * (↑q/↑(q-1)) * (↑r/↑(r-1)) ≤ (2:ℚ) * ((3/2):ℚ) * ((4/3):ℚ) := by
149
+ have hq_nonneg: 0 ≤ (↑q:ℚ) := by
150
+ norm_cast
151
+ linarith
152
+ have hq_1_nonneg: 0 ≤ (↑(q - 1):ℚ) := by
153
+ norm_cast
154
+ linarith
155
+ have h₂: 0 ≤ (((q:ℚ) / ↑(q - 1)):ℚ) := by
156
+ exact div_nonneg hq_nonneg hq_1_nonneg
157
+ have hub1: (↑p/↑(p-1)) * (↑q/↑(q-1)) ≤ (2:ℚ) * ((3/2):ℚ) := by
158
+ exact mul_le_mul hp hq h₂ (by norm_num)
159
+ have hr_nonneg: 0 ≤ (↑r:ℚ) := by
160
+ norm_cast
161
+ linarith
162
+ have hr_1_nonneg: 0 ≤ (↑(r - 1):ℚ) := by
163
+ norm_cast
164
+ linarith
165
+ have h₃: 0 ≤ (((r:ℚ) / ↑(r - 1)):ℚ) := by
166
+ exact div_nonneg hr_nonneg hr_1_nonneg
167
+ exact mul_le_mul hub1 hr h₃ (by norm_num)
168
+ norm_num at hub
169
+ rw [h₁]
170
+ norm_num
171
+ exact hub
172
+
173
+
174
+
175
+ lemma mylemma_k_lt_4
176
+ (p q r k: ℤ)
177
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
178
+ (hpl: 2 ≤ p)
179
+ (hql: 3 ≤ q)
180
+ (hrl: 4 ≤ r)
181
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
182
+ (k < 4) := by
183
+ have h₁: (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≤ ↑4 := by
184
+ exact mylemma_main_lt4 p q r hpl hql hrl
185
+ have h₂: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
186
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
187
+ norm_cast
188
+ linarith
189
+ symm
190
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
191
+ norm_cast
192
+ linarith [hden]
193
+ exact (div_eq_iff g₂).mpr g₁
194
+ have h₃: ↑k < (↑(p * q * r) / ↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
195
+ rw [h₂]
196
+ have g₁: (↑(p * q * r - 1):ℚ) < (↑(p * q * r):ℚ) := by
197
+ norm_cast
198
+ exact sub_one_lt (p * q * r)
199
+ have g₂: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
200
+ norm_cast
201
+ exact div_lt_div_of_pos_right g₁ g₂
202
+ have h₄: (↑k:ℚ) < ↑4 := by
203
+ exact lt_of_lt_of_le h₃ h₁
204
+ norm_cast at h₄
205
+
206
+
207
+
208
+ lemma mylemma_k_gt_1
209
+ (p q r k: ℤ)
210
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
211
+ (h₁: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
212
+ (hpl: 2 ≤ p)
213
+ (hql: 3 ≤ q)
214
+ (hrl: 4 ≤ r)
215
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
216
+ (1 < k) := by
217
+ have hk0: 0 < (↑k:ℚ) := by
218
+ have g₁: 2*3*4 ≤ p * q * r := by
219
+ have g₂: 2*3 ≤ p * q := by
220
+ exact mul_le_mul hpl hql (by norm_num) (by linarith[hpl])
221
+ exact mul_le_mul g₂ hrl (by norm_num) (by linarith[g₂])
222
+ have g₂: 0 < (↑(p * q * r - 1):ℚ) := by
223
+ norm_cast
224
+ linarith[g₁]
225
+ have g₃: 0 < (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
226
+ norm_cast
227
+ rw [h₁]
228
+ exact div_pos g₂ g₃
229
+ norm_cast at hk0
230
+ by_contra hc
231
+ push_neg at hc
232
+ interval_cases k
233
+ simp at hk
234
+ exfalso
235
+ have g₁: p*q + q*r + r*p = p+q+r := by linarith
236
+ have g₂: p < p*q := by exact lt_mul_right (by linarith) (by linarith)
237
+ have g₃: q < q*r := by exact lt_mul_right (by linarith) (by linarith)
238
+ have g₄: r < r*p := by exact lt_mul_right (by linarith) (by linarith)
239
+ have g₅: p+q+r < p*q + q*r + r*p := by linarith[g₂,g₃,g₄]
240
+ linarith [g₁,g₅]
241
+
242
+
243
+
244
+ lemma mylemma_p_lt_4
245
+ (p q r k: ℤ)
246
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
247
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * k)
248
+ (h₁: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ))
249
+ (hpl: 2 ≤ p)
250
+ (hql: 3 ≤ q)
251
+ (hrl: 4 ≤ r)
252
+ (hden: 0 < (p - 1) * (q - 1) * (r - 1) ) :
253
+ (p < 4) := by
254
+ by_contra hcp
255
+ push_neg at hcp
256
+ have hcq: 5 ≤ q := by linarith
257
+ have hcr: 6 ≤ r := by linarith
258
+ have h₃: k < 2 := by exact mylemma_k_lt_2 p q r k hk hcp hcq hcr hden
259
+ have h₄: 1 < k := by exact mylemma_k_gt_1 p q r k hk h₁ hpl hql hrl hden
260
+ linarith
261
+
262
+
263
+ lemma q_r_divisor_of_prime
264
+ (q r : ℤ)
265
+ (p: ℕ)
266
+ (h₀ : q * r = ↑p)
267
+ (h₁: Nat.Prime p) :
268
+ q = -1 ∨ q = 1 ∨ q = -p ∨ q = p := by
269
+ have hq : q ≠ 0 := by
270
+ intro h
271
+ rw [h] at h₀
272
+ simp at h₀
273
+ symm at h₀
274
+ norm_cast at h₀
275
+ rw [h₀] at h₁
276
+ exact Nat.not_prime_zero h₁
277
+ have hr : r ≠ 0 := by
278
+ intro h
279
+ rw [h] at h₀
280
+ simp at h₀
281
+ norm_cast at h₀
282
+ rw [← h₀] at h₁
283
+ exact Nat.not_prime_zero h₁
284
+ have hqr : abs q * abs r = p := by
285
+ have h₃: abs q = q.natAbs := by exact abs_eq_natAbs q
286
+ have h₄: abs r = r.natAbs := by exact abs_eq_natAbs r
287
+ rw [h₃,h₄]
288
+ norm_cast
289
+ exact Int.natAbs_mul_natAbs_eq h₀
290
+ have h_abs: abs (↑(q.natAbs):ℤ) = 1 ∨ abs q = p := by
291
+ cases' Int.natAbs_eq q with h_1 h_2
292
+ . rw [h_1] at hqr
293
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
294
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
295
+ norm_cast at *
296
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
297
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
298
+ cases' h₄ with h₄₀ h₄₁
299
+ . left
300
+ norm_cast at *
301
+ have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
302
+ right
303
+ rw [h₅]
304
+ norm_cast at *
305
+ . rw [h_2] at hqr
306
+ rw [abs_neg _] at hqr
307
+ have h₂: abs (↑(q.natAbs):ℤ) ∣ p := by exact Dvd.intro (abs r) hqr
308
+ have h₃: (↑(q.natAbs):ℕ) ∣ p := by
309
+ norm_cast at *
310
+ have h₄: (↑(q.natAbs):ℕ) = 1 ∨ (↑(q.natAbs):ℕ) = p := by
311
+ exact Nat.Prime.eq_one_or_self_of_dvd h₁ (↑(q.natAbs):ℕ) h₃
312
+ cases' h₄ with h₄₀ h₄₁
313
+ . left
314
+ norm_cast at *
315
+ . have h₅: abs q = q.natAbs := by exact abs_eq_natAbs q
316
+ right
317
+ rw [h₅]
318
+ norm_cast
319
+ cases' h_abs with hq_abs hq_abs
320
+ . norm_cast at *
321
+ have h₄: q = ↑(q.natAbs) ∨ q = -↑(q.natAbs) := by
322
+ exact Int.natAbs_eq q
323
+ rw [hq_abs] at h₄
324
+ norm_cast at h₄
325
+ cases' h₄ with h₄₀ h₄₁
326
+ . right
327
+ left
328
+ exact h₄₀
329
+ . left
330
+ exact h₄₁
331
+ . right
332
+ right
333
+ have h₂: abs q = q.natAbs := by exact abs_eq_natAbs q
334
+ rw [h₂] at hq_abs
335
+ norm_cast at hq_abs
336
+ refine or_comm.mp ?_
337
+ refine (Int.natAbs_eq_natAbs_iff).mp ?_
338
+ norm_cast
339
+
340
+
341
+ lemma mylemma_qr_11
342
+ (q r: ℤ)
343
+ (h₀: (4 - q) * (4 - r) = 11) :
344
+ (4 - q = -1 ∨ 4 - q = 1 ∨ 4 - q = -11 ∨ 4 - q = 11) := by
345
+ have h₁: Nat.Prime (11) := by decide
346
+ exact q_r_divisor_of_prime (4-q) (4-r) 11 h₀ h₁
347
+
348
+
349
+ lemma mylemma_qr_5
350
+ (q r: ℤ)
351
+ (h₀: (q - 3) * (r - 3) = 5) :
352
+ (q - 3 = -1 ∨ q - 3 = 1 ∨ q - 3 = -5 ∨ q - 3 = 5) := by
353
+ have h₁: Nat.Prime (5) := by decide
354
+ exact q_r_divisor_of_prime (q - 3) (r - 3) 5 h₀ h₁
355
+
356
+
357
+ lemma mylemma_63qr_5
358
+ (q r: ℤ)
359
+ (h₀: (6 - 3*q) * (2 - r) = 5) :
360
+ (6 - 3*q = -1 ∨ 6 - 3*q = 1 ∨ 6 - 3*q = -5 ∨ 6 - 3*q = 5) := by
361
+ have h₁: Nat.Prime (5) := by decide
362
+ exact q_r_divisor_of_prime (6 - 3*q) (2 - r) 5 h₀ h₁
363
+
364
+
365
+ lemma mylemma_case_k_2
366
+ (p q r: ℤ)
367
+ (h₀: 1 < p ∧ p < q ∧ q < r)
368
+ (hpl: 2 ≤ p)
369
+ (hql: 3 ≤ q)
370
+ (hrl: 4 ≤ r)
371
+ (hpu: p < 4)
372
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 2) :
373
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
374
+ interval_cases p
375
+ . exfalso
376
+ norm_num at *
377
+ have g₁: 2*q + 2*r = 3 := by linarith
378
+ linarith [g₁,hql,hrl]
379
+ . right
380
+ norm_num at *
381
+ -- have g₁: q*r - 4*q - 4*r + 5 = 0 := by linarith
382
+ have g₂: (4-q)*(4-r) = 11 := by linarith
383
+ have g₃: (4-q) = -1 ∨ (4-q) = 1 ∨ (4-q) = -11 ∨ (4-q) = 11 := by
384
+ exact mylemma_qr_11 q r g₂
385
+ cases' g₃ with g₃₁ g₃₂
386
+ . have hq: q = 5 := by linarith
387
+ constructor
388
+ . exact hq
389
+ . rw [hq] at g₂
390
+ linarith[g₂]
391
+ . exfalso
392
+ cases' g₃₂ with g₃₂ g₃₃
393
+ . have hq: q = 3 := by linarith[g₃₂]
394
+ rw [hq] at g₂
395
+ have hr: r = -7 := by linarith[g₂]
396
+ linarith[hrl,hr]
397
+ . cases' g₃₃ with g₃₃ g₃₄
398
+ . have hq: q = 15 := by linarith[g₃₃]
399
+ rw [hq] at g₂
400
+ have hr: r = 5 := by linarith[g₂]
401
+ linarith[hq,hr,h₀.2]
402
+ . have hq: q = -7 := by linarith[g₃₄]
403
+ linarith[hq,hql]
404
+
405
+
406
+ lemma mylemma_case_k_3
407
+ (p q r: ℤ)
408
+ (h₀: 1 < p ∧ p < q ∧ q < r)
409
+ (hpl: 2 ≤ p)
410
+ (hql: 3 ≤ q)
411
+ (hrl: 4 ≤ r)
412
+ (hpu: p < 4)
413
+ (hk: p * q * r - 1 = (p - 1) * (q - 1) * (r - 1) * 3) :
414
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
415
+ interval_cases p
416
+ -- p = 2
417
+ . norm_num at *
418
+ -- have g₁: q*r - 3*q - 3*r + 4 = 0 := by linarith
419
+ have g₂: (q-3)*(r-3) = 5 := by linarith
420
+ have g₃: (q-3) = -1 ∨ (q-3) = 1 ∨ (q-3) = -5 ∨ (q-3) = 5 := by
421
+ exact mylemma_qr_5 q r g₂
422
+ cases' g₃ with g₃₁ g₃₂
423
+ . exfalso
424
+ linarith [hql,g₃₁]
425
+ . cases' g₃₂ with g₃₂ g₃₃
426
+ . have hq: q = 4 := by linarith
427
+ rw [hq] at g₂
428
+ have hr: r = 8 := by linarith[g₂]
429
+ exact { left := hq, right := hr }
430
+ . exfalso
431
+ cases' g₃₃ with g₃₃ g₃₄
432
+ . linarith[hql,g₃₃]
433
+ . have hq: q = 8 := by linarith
434
+ rw [hq] at g₂
435
+ norm_num at g₂
436
+ have hr: r = 4 := by linarith
437
+ linarith[hrl,hr]
438
+ -- p = 3
439
+ . right
440
+ norm_num at *
441
+ -- have g₁: 3 * q * r - 6 * q - 6 * r + 7 = 0 := by linarith
442
+ have g₂: (6 - 3*q) * (2 - r) = 5 := by linarith
443
+ have g₃: (6 - 3*q) = -1 ∨ (6 - 3*q) = 1 ∨ (6 - 3*q) = -5 ∨ (6 - 3*q) = 5 := by
444
+ exact mylemma_63qr_5 q r g₂
445
+ exfalso
446
+ cases' g₃ with g₃₁ g₃₂
447
+ . linarith[g₃₁,q]
448
+ . cases' g₃₂ with g₃₂ g₃₃
449
+ . linarith[g₃₂,q]
450
+ . cases' g₃₃ with g₃₃ g₃₄
451
+ . linarith[g₃₃,q]
452
+ . linarith[g₃₄,q]
453
+
454
+
455
+
456
+ theorem imo_1992_p1
457
+ (p q r : ℤ)
458
+ (h₀ : 1 < p ∧ p < q ∧ q < r)
459
+ (h₁ : (p - 1) * (q - 1) * (r - 1)∣(p * q * r - 1)) :
460
+ (p, q, r) = (2, 4, 8) ∨ (p, q, r) = (3, 5, 15) := by
461
+ cases' h₁ with k hk
462
+ have hpl: 2 ≤ p := by linarith
463
+ have hql: 3 ≤ q := by linarith
464
+ have hrl: 4 ≤ r := by linarith
465
+ have hden: 0 < (((p - 1) * (q - 1)) * (r - 1)) := by
466
+ have gp: 0 < (p - 1) := by linarith
467
+ have gq: 0 < (q - 1) := by linarith
468
+ have gr: 0 < (r - 1) := by linarith
469
+ exact mul_pos (mul_pos gp gq) gr
470
+ have h₁: ↑k = (↑(p * q * r - 1):ℚ) / (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
471
+ have g₁: ↑(p * q * r - 1) = ↑k * (↑((p - 1) * (q - 1) * (r - 1)):ℚ) := by
472
+ norm_cast
473
+ linarith
474
+ symm
475
+ have g₂: (↑((p - 1) * (q - 1) * (r - 1)):ℚ) ≠ 0 := by
476
+ norm_cast
477
+ linarith[hden]
478
+ exact (div_eq_iff g₂).mpr g₁
479
+ have hk4: k < 4 := by exact mylemma_k_lt_4 p q r k hk hpl hql hrl hden
480
+ have hk1: 1 < k := by exact mylemma_k_gt_1 p q r k hk h₁ hpl hql hrl hden
481
+ have hpu: p < 4 := by exact mylemma_p_lt_4 p q r k h₀ hk h₁ hpl hql hrl hden
482
+ interval_cases k
483
+ . exact mylemma_case_k_2 p q r h₀ hpl hql hrl hpu hk
484
+ . exact mylemma_case_k_3 p q r h₀ hpl hql hrl hpu hk
imo_proofs/imo_1997_p5.lean ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat Real
5
+
6
+
7
+ lemma mylemma_xy_le_y
8
+ (x y : ℕ)
9
+ (h₀ : 0 < x ∧ 0 < y)
10
+ -- (g : x ^ y ^ 2 = (x ^ y) ^ y)
11
+ (hxy : x ≤ y)
12
+ (h₁ : (x ^ y) ^ y = y ^ x) :
13
+ x ^ y ≤ y := by
14
+ by_contra hc
15
+ push_neg at hc
16
+ have h₂: y^x ≤ y^y := by
17
+ { exact Nat.pow_le_pow_of_le_right h₀.2 hxy }
18
+ have h₃: y^y < (x^y)^y := by
19
+ refine Nat.pow_lt_pow_left hc ?_
20
+ refine Nat.pos_iff_ne_zero.mp h₀.2
21
+ rw [h₁] at h₃
22
+ linarith [h₂, h₃]
23
+
24
+
25
+ lemma four_times_k_less_than_two_pow_k
26
+ (k : ℕ)
27
+ (hk : 5 ≤ k) :
28
+ 4 * k < 2 ^ k := by
29
+ -- Proceed by induction on k
30
+ induction' k using Nat.case_strong_induction_on with n ih
31
+ -- Base case: k = 0 is not possible since 5 ≤ k
32
+ -- so we start directly with k = 5 as the base case
33
+ . norm_num
34
+ by_cases h₀ : n < 5
35
+ . have hn: n = 4 := by linarith
36
+ rw [hn]
37
+ norm_num
38
+ . push_neg at h₀
39
+ have ih₁ : 4 * n < 2 ^ n := ih n (le_refl n) h₀
40
+ rw [mul_add, pow_add, mul_one, pow_one, mul_two]
41
+ refine Nat.add_lt_add ih₁ ?_
42
+ refine lt_trans ?_ ih₁
43
+ refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
44
+ refine Nat.lt_of_lt_of_le ?_ h₀
45
+ norm_num
46
+
47
+
48
+ lemma mylemma_case_xley
49
+ (x y : ℕ)
50
+ (h₀ : 0 < x ∧ 0 < y)
51
+ (h₁ : x^(y^2) = y^x)
52
+ (g₁ : x^(y^2) = (x^y)^y)
53
+ (hxy : x ≤ y) :
54
+ (x, y) = (1, 1) ∨ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
55
+ rw [g₁] at h₁
56
+ have g2: x^y ≤ y := by
57
+ exact mylemma_xy_le_y x y h₀ hxy h₁
58
+ have g3: x = 1 := by
59
+ by_contra hc
60
+ have g3: 2 ≤ x := by
61
+ by_contra gc
62
+ push_neg at gc
63
+ interval_cases x
64
+ . linarith
65
+ . omega
66
+ have g4: 2^y ≤ x^y := by { exact Nat.pow_le_pow_of_le_left g3 y }
67
+ have g5: y < 2^y := by exact Nat.lt_two_pow_self
68
+ linarith
69
+ rw [g3] at h₁
70
+ simp at h₁
71
+ left
72
+ norm_num
73
+ exact { left := g3, right := id h₁.symm }
74
+
75
+
76
+ lemma mylemma_exp_log
77
+ (x: ℕ)
78
+ (h₀: 0 < x):
79
+ (↑x = Real.exp (Real.log ↑x)):= by
80
+ have hx_pos : 0 < (↑x : ℝ) := by exact Nat.cast_pos.mpr h₀
81
+ symm
82
+ exact Real.exp_log hx_pos
83
+
84
+
85
+
86
+ lemma mylemma_y2_lt_x
87
+ (x y : ℕ)
88
+ (h₀ : 0 < x ∧ 0 < y)
89
+ (h₁ : x ^ y ^ 2 = y ^ x)
90
+ (hxy : y < x) :
91
+ y ^ 2 < x := by
92
+ by_cases hy: 1 < y
93
+ . have hx: 2 ≤ x := by linarith
94
+ have h₂: y ^ x < x ^ x := by
95
+ refine Nat.pow_lt_pow_left hxy ?_
96
+ exact Nat.ne_of_lt' h₀.1
97
+ rw [← h₁] at h₂
98
+ exact (Nat.pow_lt_pow_iff_right hx).mp h₂
99
+ . push_neg at hy
100
+ interval_cases y
101
+ . simp
102
+ exact h₀.1
103
+ . simp at *
104
+ assumption
105
+
106
+
107
+
108
+ lemma mylemma_5
109
+ (x y: ℕ)
110
+ (h₀: 0 < x ∧ 0 < y)
111
+ (h₁: x ^ y ^ 2 = y ^ x) :
112
+ (↑x / ↑y^2) ^ y ^ 2 = (↑y:ℝ)^ ((↑x:ℝ) - 2 * ↑y ^ 2) := by
113
+ have g₁: (↑x:ℝ) ^ (↑y:ℝ) ^ 2 = (↑y:ℝ) ^ (↑x:ℝ) := by
114
+ norm_cast
115
+ have g₂: 0 < ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
116
+ norm_cast
117
+ exact pow_pos h₀.2 _
118
+ have g₃: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
119
+ = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
120
+ refine (div_left_inj' ?_).mpr g₁
121
+ norm_cast
122
+ refine pow_ne_zero _ ?_
123
+ linarith [h₀.2]
124
+ have gy: 0 < (↑y:ℝ) := by
125
+ norm_cast
126
+ exact h₀.2
127
+ rw [← Real.rpow_sub gy (↑x) (2 * ↑y ^ 2)] at g₃
128
+ have g₄: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
129
+ = (↑x / ↑y^2) ^ y ^ 2 := by
130
+ have g₅: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
131
+ norm_cast
132
+ refine pow_mul y 2 (y^2)
133
+ rw [g₅]
134
+ symm
135
+ norm_cast
136
+ have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
137
+ refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
138
+ norm_cast at *
139
+ rw [g₄] at g₃
140
+ norm_cast at *
141
+
142
+
143
+
144
+
145
+ lemma mylemma_2y2_lt_x
146
+ (x y : ℕ)
147
+ (h₀ : 0 < x ∧ 0 < y)
148
+ (h₁ : x ^ y ^ 2 = y ^ x)
149
+ (hxy : y < x) :
150
+ 2 * y ^ 2 < x := by
151
+ by_cases hy1: y = 1
152
+ . rw [hy1]
153
+ norm_num
154
+ by_contra hc
155
+ push_neg at hc
156
+ interval_cases x
157
+ . linarith
158
+ . linarith
159
+ . rw [hy1] at h₁
160
+ simp at h₁
161
+ . have hy: 1 < y := by
162
+ contrapose! hy1
163
+ linarith
164
+ clear hy1
165
+ have h₂: (↑y:ℝ) ^ 2 < ↑x := by
166
+ norm_cast
167
+ exact mylemma_y2_lt_x x y h₀ h₁ hxy
168
+ have h₃: 1 < ↑x / (↑y:ℝ) ^ 2 := by
169
+ refine (one_lt_div ?_).mpr h₂
170
+ norm_cast
171
+ exact pow_pos h₀.2 2 -- rw ← one_mul ((↑y:ℝ)^2) at h₂, refine lt_div_iff_mul_lt.mpr h₂, },
172
+ have h₄: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
173
+ refine one_lt_pow₀ h₃ ?_
174
+ refine Nat.ne_of_gt ?_
175
+ refine sq_pos_of_pos ?_
176
+ exact lt_of_succ_lt hy
177
+ have h₅: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
178
+ exact mylemma_5 x y h₀ h₁
179
+ rw [h₅] at h₄
180
+ have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
181
+ by_contra hc
182
+ push_neg at hc
183
+ cases' lt_or_eq_of_le hc with hlt heq
184
+ . have gy: 1 < (↑y:ℝ) := by
185
+ norm_cast
186
+ have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
187
+ norm_cast at *
188
+ have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
189
+ exact Real.rpow_lt_rpow_of_exponent_lt gy glt
190
+ simp at g₁
191
+ linarith[ h₄,g₁]
192
+ . rw [heq] at h₄
193
+ simp at h₄
194
+ simp at h₆
195
+ norm_cast at h₆
196
+
197
+
198
+ lemma mylemma_castdvd
199
+ (x y: ℕ)
200
+ (h₀: 0 < x ∧ 0 < y)
201
+ (h₁ : x ^ y ^ 2 = y ^ x)
202
+ (hyx: y < x) :
203
+ (y^2 ∣ x) := by
204
+ have h₂: (x ^ y ^ 2).factorization = (y^x).factorization := by
205
+ exact congr_arg Nat.factorization h₁
206
+ simp at h₂
207
+ symm at h₂
208
+ have hxy1: 2 * y^2 ≤ x := by exact le_of_lt (mylemma_2y2_lt_x x y h₀ h₁ hyx)
209
+ have hxy: 2 • y^2 ≤ x := by exact hxy1
210
+ have h₃: 2 • y^2 • x.factorization ≤ x • x.factorization := by
211
+ rw [← smul_assoc]
212
+ refine nsmul_le_nsmul_left ?_ hxy
213
+ norm_num
214
+ rw [← h₂] at h₃
215
+ have h₄: 2 • x • y.factorization = x • (2 • y.factorization) := by
216
+ rw [← smul_assoc, ← smul_assoc]
217
+ have g₄: 2 • x = x • 2 := by
218
+ simp
219
+ exact mul_comm 2 x
220
+ rw [g₄]
221
+ rw [h₄] at h₃
222
+ rw [← Nat.factorization_pow] at h₃
223
+ rw [← Nat.factorization_pow] at h₃
224
+ rw [← Nat.factorization_pow] at h₃
225
+ have h₅: (y ^ 2) ^ x ∣ x^x := by
226
+ have g₁: (y ^ 2) ^ x ≠ 0 := by
227
+ refine pow_ne_zero x ?_
228
+ refine pow_ne_zero 2 ?_
229
+ linarith
230
+ have g₂: x ^ x ≠ 0 := by
231
+ refine pow_ne_zero x ?_
232
+ linarith
233
+ exact (Nat.factorization_le_iff_dvd g₁ g₂).mp h₃
234
+ refine (Nat.pow_dvd_pow_iff ?_).mp h₅
235
+ exact Nat.ne_of_gt h₀.1
236
+
237
+
238
+
239
+
240
+ lemma mylemma_xsuby_eq_2xy2_help
241
+ (x y : ℕ)
242
+ (h₀ : 0 < x ∧ 0 < y)
243
+ (h₁ : x ^ y ^ 2 = y ^ x)
244
+ (h₂ : Real.log (↑x:ℝ) = Real.log ↑y * ↑x / (↑(y ^ 2:ℕ ):ℝ) )
245
+ (hxy : y < x) :
246
+ x = y ^ (x / y ^ 2) := by
247
+ have h_exp : Real.exp (Real.log ↑x)
248
+ = Real.exp (Real.log ↑y * (↑x:ℝ) / ((↑y:ℝ)) ^ 2) := by
249
+ rw [h₂]
250
+ norm_cast
251
+ rw [← mylemma_exp_log x h₀.1] at h_exp
252
+ rw [← mul_div] at h_exp
253
+ rw [Real.exp_mul] at h_exp
254
+ rw [← mylemma_exp_log y h₀.2] at h_exp
255
+ have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:ℕ):ℝ) := by
256
+ norm_cast
257
+ symm
258
+ have g₂: y^2 ∣ x := by
259
+ exact mylemma_castdvd x y h₀ h₁ hxy
260
+ have h₃: (↑(y^(2:ℕ)):ℝ) ≠ 0 := by
261
+ norm_cast
262
+ exact pow_ne_zero 2 ( by linarith)
263
+ exact Nat.cast_div g₂ h₃
264
+ have h₄ : (↑(y ^ (x / y ^ (2:ℕ))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
265
+ rw [Nat.cast_pow, h₃]
266
+ norm_cast
267
+ rw [←h₄] at h_exp
268
+ exact Nat.cast_inj.mp h_exp
269
+
270
+
271
+ theorem mylemma_xsuby_eq_2xy2
272
+ (x y : ℕ)
273
+ (h₀ : 0 < x ∧ 0 < y)
274
+ (h₁ : x ^ y ^ 2 = y ^ x)
275
+ (hxy : y < x) :
276
+ x = y ^ (x / y ^ 2) := by
277
+ -- sketch: y^2 * log x = x * log y
278
+ have h₃: Real.log (x^(y^2)) = Real.log (y^x) := by
279
+ norm_cast
280
+ rw [h₁]
281
+ have h₄: (↑(y ^ (2:ℕ)):ℝ) * Real.log x = ↑x * Real.log y := by
282
+ have h41: Real.log (y^x) = (↑x:ℝ) * Real.log (y) := by
283
+ exact Real.log_pow y x
284
+ have h42: Real.log (x^(y^2)) = (↑(y ^ (2:ℕ)):ℝ) * Real.log x := by
285
+ exact Real.log_pow x (y^2)
286
+ rw [h41,h42] at h₃
287
+ exact h₃
288
+ ring_nf at h₄
289
+ have h₅: Real.log ↑x = Real.log ↑y * ↑x / (↑(y ^ (2:ℕ)):ℝ) := by
290
+ by_contra hc
291
+ rw [mul_comm (Real.log ↑y) (↑x)] at hc
292
+ rw [← h₄, mul_comm, ← mul_div] at hc
293
+ rw [div_self, mul_one] at hc
294
+ . apply hc
295
+ norm_cast
296
+ . norm_cast
297
+ push_neg
298
+ refine pow_ne_zero 2 ?_
299
+ exact Nat.ne_of_gt h₀.2
300
+ have h₆: x = y ^ (x / y ^ 2) := by
301
+ exact mylemma_xsuby_eq_2xy2_help x y h₀ h₁ h₅ hxy
302
+ exact h₆
303
+
304
+
305
+
306
+ theorem imo_1997_p5
307
+ (x y : ℕ)
308
+ (h₀ : 0 < x ∧ 0 < y)
309
+ (h₁ : x^(y^2) = y^x) :
310
+ (x, y) = (1, 1) ∨ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
311
+ have g₁: x^(y^2) = (x^y)^y := by
312
+ rw [Nat.pow_two]
313
+ exact Nat.pow_mul x y y
314
+ by_cases hxy: x ≤ y
315
+ . exact mylemma_case_xley x y h₀ h₁ g₁ hxy
316
+ . push_neg at hxy
317
+ right
318
+ have h₃: x = y ^ (x / y ^ 2) := by
319
+ exact mylemma_xsuby_eq_2xy2 x y h₀ h₁ hxy
320
+ let k:ℕ := x / y^2 -- { admit },
321
+ have hk_def: k = x / y^2 := by exact rfl
322
+ by_cases hk: k < 2
323
+ . rw [← hk_def] at h₃
324
+ interval_cases k
325
+ . exfalso
326
+ simp at h₃
327
+ linarith
328
+ . exfalso
329
+ simp at *
330
+ linarith [hxy,h₃] --simp at h₃, rw h₃ at hxy, linarith[hxy], },
331
+ . push_neg at hk
332
+ rw [← hk_def] at h₃
333
+ have h₅: k = y^(k-2) := by
334
+ rw [h₃] at hk_def
335
+ nth_rewrite 1 [hk_def]
336
+ exact Nat.pow_div hk h₀.2
337
+ by_cases hk5: k < 5
338
+ . interval_cases k
339
+ . exfalso
340
+ simp at h₅
341
+ . right
342
+ norm_num
343
+ simp at h₅
344
+ symm at h₅
345
+ rw [h₅] at h₃
346
+ norm_num at h₃
347
+ exact { left := h₃, right := h₅ }
348
+ . simp at h₅
349
+ symm at h₅
350
+ have g₂: y^4 = y^2 * y^2 := by ring_nf
351
+ rw [g₂, h₅] at h₃
352
+ norm_num at h₃
353
+ left
354
+ norm_num
355
+ constructor
356
+ . exact h₃
357
+ . have h₆ : y ^ 2 = 2 ^ 2 := by
358
+ norm_num
359
+ exact h₅
360
+ have h₇: 0 ≤ y := by
361
+ linarith
362
+ exact (sq_eq_sq₀ h₇ (by linarith)).mp (h₆)
363
+ push_neg at hk5
364
+ by_cases hy: 2 ≤ y
365
+ . have h₅₁: k < y^(k-2) := by
366
+ have h₆: 2^(k-2) ≤ y^(k-2) := by
367
+ have hk1: 3 ≤ k - 2 := by exact Nat.sub_le_sub_right hk5 2
368
+ exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
369
+ have h₇: 4*k < 2^k := by
370
+ exact four_times_k_less_than_two_pow_k k hk5
371
+ have h₇: k < 2^(k-2) := by
372
+ have h₈ : k < 2 ^ k / 4 := by
373
+ have h81: 4 ∣ 2^k := by
374
+ have h82: 2^k = 4*2^(k-2) := by
375
+ have h83: k = 2 + (k -2) := by
376
+ ring_nf
377
+ exact (add_sub_of_le hk).symm
378
+ nth_rewrite 1 [h83]
379
+ rw [pow_add]
380
+ norm_num
381
+ rw [h82]
382
+ exact Nat.dvd_mul_right 4 (2^(k-2))
383
+ exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
384
+ have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
385
+ have g2: k = k - 2 + 2 := by
386
+ exact (Nat.sub_eq_iff_eq_add hk).mp rfl
387
+ have h1: 2^k = 2^(k - 2 + 2) := by
388
+ exact congrArg (HPow.hPow 2) g2
389
+ have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
390
+ rw [h1, h2]
391
+ ring_nf
392
+ simp
393
+ linarith
394
+ linarith
395
+ exfalso
396
+ linarith
397
+ . push_neg at hy
398
+ interval_cases y
399
+ . linarith
400
+ . simp at h₅
401
+ simp at h₃
402
+ linarith
imo_proofs/imo_2007_p6.lean ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open NNReal Nat BigOperators Finset
5
+
6
+ -- imo-official.org/problems/IMO2007SL.pdf
7
+
8
+
9
+ lemma aux1
10
+ (a : ℕ → NNReal)
11
+ (m : ℕ)
12
+ (hm₀ : Nat.succ 4 ≤ m) :
13
+ a (m - 1) ^ 2 + a m ^ 2 + a 1 ^ 2 + a 2 ^ 2 ≤ ∑ x ∈ Finset.range m, a (x + 1) ^ 2 := by
14
+ let fs: Finset ℕ := {0, 1, m-2, m-1}
15
+ have h₀: fs = {0, 1, m-2, m-1} := by rfl
16
+ have h₁: fs ⊆ Finset.range m := by
17
+ refine insert_subset ?_ ?_
18
+ . refine mem_range.mpr ?_
19
+ exact zero_lt_of_lt hm₀
20
+ . refine insert_subset ?_ ?_
21
+ . refine mem_range.mpr ?_
22
+ linarith
23
+ . refine insert_subset ?_ ?_
24
+ . refine mem_range.mpr ?_
25
+ refine sub_lt ?_ (by norm_num)
26
+ exact zero_lt_of_lt hm₀
27
+ . refine singleton_subset_iff.mpr ?_
28
+ refine mem_range.mpr ?_
29
+ exact sub_one_lt_of_lt hm₀
30
+ rw [← Finset.sum_sdiff h₁]
31
+ have h₂: ∑ x ∈ fs, a (x + 1) ^ 2 = a (m - 1) ^ 2 + a m ^ 2 + a 1 ^ 2 + a 2 ^ 2 := by
32
+ rw [h₀]
33
+ have g₀: 0 ∈ fs := by exact mem_insert_self 0 {1, m - 2, m - 1}
34
+ rw [← Finset.add_sum_erase fs _ g₀]
35
+ simp
36
+ have g₁: 4 ≤ m - 1 := by exact Nat.le_sub_one_of_lt hm₀
37
+ have g₂: 3 ≤ m - 2 := by exact le_sub_of_add_le hm₀
38
+ have g₃: fs.erase 0 = ({1, m - 2, m - 1}:(Finset ℕ)) := by
39
+ rw [h₀]
40
+ refine erase_insert ?h
41
+ refine forall_mem_not_eq'.mp ?_
42
+ intros b hb₀ hb₁
43
+ rw [hb₁] at hb₀
44
+ norm_num at hb₀
45
+ cases' hb₀ with hb₀ hb₀
46
+ . rw [← hb₀] at g₂
47
+ linarith
48
+ . rw [← hb₀] at g₁
49
+ linarith
50
+ rw [g₃]
51
+ have g₄: (1:ℕ) ∈ ({1, m - 2, m - 1}:(Finset ℕ)) := by
52
+ exact mem_insert_self 1 {m - 2, m - 1}
53
+ rw [← Finset.add_sum_erase _ _ g₄]
54
+ simp
55
+ rw [Finset.erase_eq_self.mpr ?_]
56
+ . have g₅: (m - 2) ∈ ({m - 2, m - 1}:(Finset ℕ)) := by
57
+ exact mem_insert_self (m - 2) {m - 1}
58
+ rw [← Finset.add_sum_erase _ _ g₅]
59
+ simp
60
+ rw [Finset.erase_eq_self.mpr ?_]
61
+ . rw [Finset.sum_singleton, Nat.sub_add_cancel (by linarith)]
62
+ rw [← Nat.sub_add_comm (by linarith)]
63
+ simp
64
+ ring_nf
65
+ . refine Finset.not_mem_singleton.mpr ?_
66
+ omega
67
+ . refine forall_mem_not_eq'.mp ?_
68
+ intros b hb₀ hb₁
69
+ rw [hb₁] at hb₀
70
+ simp at hb₀
71
+ cases' hb₀ with hb₀ hb₀
72
+ . rw [← hb₀] at g₂
73
+ linarith
74
+ . rw [← hb₀] at g₁
75
+ linarith
76
+ rw [add_comm _ (∑ x ∈ fs, a (x + 1) ^ 2), h₂]
77
+ exact le_self_add
78
+
79
+
80
+
81
+ lemma aux2
82
+ (a : ℕ → NNReal) :
83
+ ∀ (n : ℕ),
84
+ 4 < n ∧ n < 101 →
85
+ (∀ (x y : ℕ), x % n = y % n → a (x + 1) = a (y + 1)) →
86
+ ∑ x ∈ range n, (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) ≤
87
+ (∑ x ∈ range n, a (x + 1) ^ 2) ^ 2 := by
88
+ intro n hn₀ hn₂
89
+ cases' hn₀ with hn₀ hn₁
90
+ have hn₃: n = (n - 2) + 1 + 1 := by omega
91
+ nth_rw 1 [hn₃,]
92
+ rw [Finset.sum_range_succ, sum_range_succ]
93
+ have hn₄: a (n - 2 + 1) = a (n - 1) := by
94
+ refine congrArg a (by omega)
95
+ have hn₅: a (n - 2 + 3) = a 1 := by
96
+ refine hn₂ (n - 2 + 2) 0 ?_
97
+ rw [Nat.zero_mod, Nat.sub_add_cancel ?_]
98
+ . rw [Nat.mod_self n]
99
+ . linarith
100
+ have hn₆: a (n - 2 + 1 + 3) = a 2 := by
101
+ refine hn₂ (n - 2 + 3) 1 ?_
102
+ symm
103
+ rw [Nat.mod_eq_of_lt (by linarith)]
104
+ have g₀: n - 2 + 3 = n + 1 := by linarith
105
+ rw [g₀]
106
+ refine Eq.symm (mod_eq_of_modEq ?_ (by linarith))
107
+ exact Nat.add_modEq_left
108
+ rw [← hn₃, hn₄, hn₅, hn₆]
109
+ refine le_induction ?_ ?_ n hn₀
110
+ . repeat rw [Finset.sum_range_succ]
111
+ simp
112
+ ring_nf
113
+ repeat refine add_le_add_right ?_ _
114
+ refine le_of_eq ?_
115
+ rfl
116
+ . intros m hm₀ hm₁
117
+ have hm₂: m + 1 - 2 = m - 2 + 1 := by
118
+ rw [add_comm, add_comm _ 1, Nat.add_sub_assoc ?_ 1]
119
+ omega
120
+ rw [hm₂, Finset.sum_range_succ, sum_range_succ]
121
+ have hm₃: m - 2 + 1 = m - 1 := by exact id (Eq.symm hm₂)
122
+ have hm₄: m - 2 + 2 = m := by exact Eq.symm ((fun {m n} => pred_eq_succ_iff.mp) hm₂)
123
+ have hm₅: m - 2 + 3 = m + 1 := by omega
124
+ have hm₆: m + 1 - 1 = m := by exact rfl
125
+ rw [hm₃, hm₄, hm₅, hm₆]
126
+ clear hm₃ hm₄ hm₅ hm₆
127
+ rw [add_sq, add_assoc ((∑ x ∈ Finset.range m, a (x + 1) ^ 2) ^ 2)]
128
+ have h₅₀: 2 * a (m - 1) ^ 2 * a (m + 1) ^ 2 + 2 * a m ^ 2 * a (m + 1) ^ 2
129
+ + 2 * a (m + 1) ^ 2 * a 1 ^ 2 + 2 * a (m + 1) ^ 2 * a 2 ^ 2 + a (m + 1) ^ 4 ≤
130
+ (2 * ∑ x ∈ Finset.range m, a (x + 1) ^ 2) * a (m + 1) ^ 2 + (a (m + 1) ^ 2) ^ 2 := by
131
+ rw [← pow_mul]
132
+ simp
133
+ have h₅₁: 2 * a (m - 1) ^ 2 * a (m + 1) ^ 2 + 2 * a m ^ 2 * a (m + 1) ^ 2 + 2 * a (m + 1) ^ 2 * a 1 ^ 2 +
134
+ 2 * a (m + 1) ^ 2 * a 2 ^ 2 =
135
+ 2 * a (m + 1) ^ 2 * (a (m - 1) ^ 2 + a m ^ 2 + a 1 ^ 2 + a 2 ^ 2) := by
136
+ ring_nf
137
+ rw [h₅₁, mul_assoc 2 _ (a (m + 1) ^ 2), mul_comm (∑ x ∈ Finset.range m, a (x + 1) ^ 2), ← mul_assoc 2]
138
+ have h₅₂: a (m - 1) ^ 2 + a m ^ 2 + a 1 ^ 2 + a 2 ^ 2 ≤ ∑ x ∈ Finset.range m, a (x + 1) ^ 2 := by
139
+ exact aux1 a m hm₀
140
+ refine mul_le_mul ?_ ?_ ?_ ?_
141
+ . exact le_of_eq (by rfl)
142
+ . exact h₅₂
143
+ . exact _root_.zero_le (a (m - 1) ^ 2 + a m ^ 2 + a 1 ^ 2 + a 2 ^ 2)
144
+ . exact _root_.zero_le (2 * a (m + 1) ^ 2)
145
+ have h₅₃: ∑ x ∈ Finset.range (m - 2), (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) +
146
+ a (m - 1) ^ 4 + 2 * a (m - 1) ^ 2 * a m ^ 2 + a m ^ 4 + 2 * a m ^ 2 * a 1 ^ 2
147
+ ≤ (∑ x ∈ Finset.range m, a (x + 1) ^ 2) ^ 2 := by
148
+ have h₅₄: ∑ x ∈ Finset.range (m - 2), (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) +
149
+ a (m - 1) ^ 4 + 2 * a (m - 1) ^ 2 * a m ^ 2 + a m ^ 4 + 2 * a m ^ 2 * a 1 ^ 2
150
+ ≤ ∑ x ∈ Finset.range (m - 2), (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) +
151
+ (a (m - 1) ^ 4 + 2 * a (m - 1) ^ 2 * a m ^ 2 + 2 * a (m - 1) ^ 2 * a 1 ^ 2) +
152
+ (a m ^ 4 + 2 * a m ^ 2 * a 1 ^ 2 + 2 * a m ^ 2 * a 2 ^ 2) := by
153
+ repeat rw [add_assoc]
154
+ repeat refine add_le_add_left ?_ _
155
+ have h₅₅: 2 * a (m - 1) ^ 2 * a 1 ^ 2 + (a m ^ 4 + (2 * a m ^ 2 * a 1 ^ 2 + 2 * a m ^ 2 * a 2 ^ 2)) =
156
+ (a m ^ 4 + 2 * a m ^ 2 * a 1 ^ 2) + (2 * a (m - 1) ^ 2 * a 1 ^ 2 + 2 * a m ^ 2 * a 2 ^ 2) := by
157
+ ring_nf
158
+ rw [h₅₅]
159
+ exact le_self_add
160
+ exact le_trans h₅₄ hm₁
161
+ apply add_le_add h₅₃ at h₅₀
162
+ have h₅₆: ∑ x ∈ Finset.range (m - 2), (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2)
163
+ + a (m - 1) ^ 4 + 2 * a (m - 1) ^ 2 * a m ^ 2 + a m ^ 4 + 2 * a m ^ 2 * a 1 ^ 2
164
+ + (2 * a (m - 1) ^ 2 * a (m + 1) ^ 2 + 2 * a m ^ 2 * a (m + 1) ^ 2 + 2 * a (m + 1) ^ 2 * a 1 ^ 2
165
+ + 2 * a (m + 1) ^ 2 * a 2 ^ 2 + a (m + 1) ^ 4)
166
+ = ∑ x ∈ Finset.range (m - 2), (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) +
167
+ (a (m - 1) ^ 4 + 2 * a (m - 1) ^ 2 * a m ^ 2 + 2 * a (m - 1) ^ 2 * a (m + 1) ^ 2) +
168
+ (a m ^ 4 + 2 * a m ^ 2 * a (m + 1) ^ 2 + 2 * a m ^ 2 * a 1 ^ 2) +
169
+ (a (m + 1) ^ 4 + 2 * a (m + 1) ^ 2 * a 1 ^ 2 + 2 * a (m + 1) ^ 2 * a 2 ^ 2) := by
170
+ repeat rw [add_assoc]
171
+ simp
172
+ ring_nf
173
+ rw [← h₅₆]
174
+ exact h₅₀
175
+
176
+
177
+ theorem imo_2007_p6
178
+ (a : ℕ → NNReal)
179
+ (h₀ : ∑ x ∈ Finset.range 100, ((a (x + 1)) ^ 2) = 1)
180
+ (h₁ : ∀ x y, x % 100 = y % 100 → a (x + 1) = a (y + 1)) :
181
+ ∑ x ∈ Finset.range (99), ((a (x + 1)) ^ 2 * a (x + 2)) + (a 100) ^ 2 * a 1 < (12:NNReal) / (25:NNReal) := by
182
+ have h₂: ∀ x, 2 * a x ^ 2 * a (x + 1) * a (x + 2) ≤
183
+ (a x * a (x + 1)) ^ 2 + (a x * a (x + 2)) ^ 2 := by
184
+ intro x
185
+ have h₂₀: 2 * (a x * a (x + 1)) * (a x * a (x + 2)) ≤
186
+ (a x * a (x + 1)) ^ 2 + (a x * a (x + 2)) ^ 2 := by
187
+ exact two_mul_le_add_sq (a x * a (x + 1)) (a x * a (x + 2))
188
+ have h₂₁: 2 * (a x * a (x + 1)) * (a x * a (x + 2)) = 2 * a x ^ 2 * a (x + 1) * a (x + 2) := by
189
+ rw [pow_two]
190
+ ring_nf
191
+ exact le_of_eq_of_le (id (Eq.symm h₂₁)) h₂₀
192
+ have h₃: ∀ x ∈ Finset.range 100, a (x + 1) ≤ 1 := by
193
+ intros x hx₀
194
+ by_contra hx₁
195
+ push_neg at hx₁
196
+ let fsx : Finset ℕ := {x}
197
+ have hx₂: 1 < ∑ x ∈ range 100, a (x + 1) ^ 2 := by
198
+ have hx₃: 0 ≤ ∑ x ∈ (range 100 \ fsx), a (x + 1) ^ 2 := by
199
+ exact _root_.zero_le (∑ x ∈ range 100 \ fsx, a (x + 1) ^ 2)
200
+ have hx₄: 1 < ∑ x ∈ (fsx), a (x + 1) ^ 2 := by
201
+ rw [Finset.sum_singleton]
202
+ refine one_lt_pow₀ hx₁ ?_
203
+ norm_num
204
+ have hx₅: ∑ x ∈ (range 100 \ fsx), a (x + 1) ^ 2 + ∑ x ∈ (fsx), a (x + 1) ^ 2 =
205
+ ∑ x ∈ range 100, a (x + 1) ^ 2 := by
206
+ rw [← Finset.sum_union ?_]
207
+ . rw [Finset.sdiff_union_self_eq_union]
208
+ have hx₆: range 100 ∪ fsx = range 100 := by
209
+ refine Finset.union_eq_left.mpr ?_
210
+ exact singleton_subset_iff.mpr hx₀
211
+ rw [hx₆]
212
+ . exact sdiff_disjoint
213
+ rw [← hx₅]
214
+ exact lt_add_of_nonneg_of_lt hx₃ hx₄
215
+ simp_all only [mem_range, lt_self_iff_false]
216
+ have h₄: (∑ x ∈ Finset.range 100, (a (x + 2) * (a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3)))) ^ 2 ≤
217
+ ∑ x ∈ Finset.range 100, (a (x + 1) ^ 4 + 6 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) := by
218
+ have h₄₀: (∑ x ∈ Finset.range 100, (a (x + 2) * (a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3)))) ^ 2 ≤
219
+ (∑ x ∈ Finset.range 100, (a (x + 2) ^ 2)) *
220
+ (∑ x ∈ Finset.range 100, ((a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3))) ^ 2) := by
221
+ refine sum_mul_sq_le_sq_mul_sq (range 100) (fun i => a (i + 2)) _
222
+ have h₄₁: ∑ x ∈ Finset.range 100, (a (x + 2) ^ 2) = 1 := by
223
+ rw [Finset.sum_range_succ'] at h₀
224
+ simp at h₀
225
+ rw [Finset.sum_range_succ]
226
+ have h₄₁₁: a 1 = a 101 := by exact h₁ 0 100 rfl
227
+ rw [← h₄₁₁]
228
+ exact h₀
229
+ have h₄₂: ∑ x ∈ Finset.range 100, ((a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3))) ^ 2 =
230
+ ∑ x ∈ Finset.range 100, ((a (x + 1) ^ 4 + 4 * a (x + 1) ^ 2 * a (x + 2) * a (x + 3)
231
+ + 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2)) := by
232
+ refine Finset.sum_congr (rfl) ?_
233
+ intros x _
234
+ rw [add_sq]
235
+ ring_nf
236
+ rw [h₄₁, one_mul, h₄₂] at h₄₀
237
+ have h₄₃: ∑ x ∈ Finset.range 100, ((a (x + 1) ^ 4 + 4 * a (x + 1) ^ 2 * a (x + 2) * a (x + 3)
238
+ + 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2)) ≤
239
+ ∑ x ∈ Finset.range 100, ((a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * (a (x + 2) ^ 2 + a (x + 3) ^ 2)
240
+ + 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2)) := by
241
+ refine Finset.sum_le_sum ?_
242
+ intros x _
243
+ rw [add_comm (a (x + 1) ^ 4) _, add_comm (a (x + 1) ^ 4) _]
244
+ rw [add_assoc, add_assoc]
245
+ refine add_le_add ?_ ?_
246
+ . have hx₁: 2 * a (x + 1) ^ 2 * a (x + 1 + 1) * a (x + 1 + 2) ≤
247
+ (a (x + 1) * a (x + 1 + 1)) ^ 2 + (a (x + 1) * a (x + 1 + 2)) ^ 2 := by
248
+ exact h₂ (x + 1)
249
+ have hx₂: 2 * a (x + 1) ^ 2 * a (x + 2) * a (x + 3) ≤
250
+ a (x + 1) ^ 2 * (a (x + 2) ^ 2 + a (x + 3) ^ 2) := by
251
+ rw [mul_add]
252
+ refine le_of_le_of_eq hx₁ ?_
253
+ ring_nf
254
+ have hx₃: (4:NNReal) = 2 * 2 := by norm_num
255
+ rw [hx₃]
256
+ repeat rw [mul_assoc]
257
+ have hx₄: 0 < (2:NNReal) := by norm_num
258
+ refine (mul_le_mul_left hx₄).mpr ?_
259
+ ring_nf
260
+ ring_nf at hx₂
261
+ exact hx₂
262
+ . exact Preorder.le_refl (a (x + 1) ^ 4 + 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2)
263
+ have h₄₄: ∑ x ∈ Finset.range 100, ((a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * (a (x + 2) ^ 2 + a (x + 3) ^ 2)
264
+ + 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2)) =
265
+ ∑ x ∈ Finset.range 100, (a (x + 1) ^ 4 + 6 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2
266
+ * a (x + 1) ^ 2 * a (x + 3) ^ 2) := by
267
+ rw [Finset.sum_add_distrib]
268
+ have h₄₄₁: ∑ x ∈ range 100, 4 * a (x + 2) ^ 2 * a (x + 3) ^ 2 =
269
+ ∑ x ∈ range 100, 4 * a (x + 1) ^ 2 * a (x + 2) ^ 2 := by
270
+ rw [Finset.sum_range_succ _ 99, sum_range_succ' _ 99]
271
+ have g₀: a 101 = a 1 := by exact h₁ 100 0 rfl
272
+ have g₁: a 102 = a 2 := by exact h₁ 101 1 rfl
273
+ rw [g₀, g₁]
274
+ rw [h₄₄₁, ← Finset.sum_add_distrib]
275
+ refine Finset.sum_congr (rfl) ?_
276
+ intros x _
277
+ rw [mul_add]
278
+ ring_nf
279
+ rw [h₄₄] at h₄₃
280
+ exact le_trans h₄₀ h₄₃
281
+ have h₆: ∑ x ∈ range 100, 4 * a (x + 1) ^ 2 * a (x + 2) ^ 2 ≤ 1 := by
282
+ have h₆₀: ∑ x ∈ range 100, 4 * a (x + 1) ^ 2 * a (x + 2) ^ 2 =
283
+ ∑ x ∈ range 100, 4 * (a (x + 1) ^ 2 * a (x + 2) ^ 2) := by
284
+ refine Finset.sum_congr rfl ?_
285
+ intros x _
286
+ ring_nf
287
+ rw [h₆₀, ← Finset.mul_sum]
288
+ let fs₂ := Finset.range (100)
289
+ let fs₀ : Finset ℕ := fs₂.filter (fun x => Odd x)
290
+ let fs₁ : Finset ℕ := fs₂.filter (fun x => Even x)
291
+ have h₆₁ : Disjoint fs₀ fs₁ := by
292
+ refine Finset.sdiff_eq_self_iff_disjoint.mp (by rfl)
293
+ have h₆₂ : fs₀ ∪ fs₁ = fs₂ := by
294
+ symm
295
+ refine Finset.ext_iff.mpr ?_
296
+ intro a
297
+ constructor
298
+ . intro ha₀
299
+ refine mem_union.mpr ?mp.a
300
+ have ha₁: Odd a ∨ Even a := by exact Or.symm (even_or_odd a)
301
+ cases' ha₁ with ha₂ ha₃
302
+ . left
303
+ refine mem_filter.mpr ?mp.a.inl.h.a
304
+ exact And.symm ⟨ha₂, ha₀⟩
305
+ . right
306
+ refine mem_filter.mpr ?mp.a.inl.h.b
307
+ exact And.symm ⟨ha₃, ha₀⟩
308
+ . intro ha₀
309
+ apply mem_union.mp at ha₀
310
+ cases' ha₀ with ha₁ ha₂
311
+ . exact mem_of_mem_filter a ha₁
312
+ . exact mem_of_mem_filter a ha₂
313
+ have h₆₃: 4 * ∑ i ∈ fs₂, a (i + 1) ^ 2 * a (i + 2) ^ 2 ≤
314
+ 4 * ((∑ i ∈ fs₀, (a (i + 1) ^ 2)) * (∑ i ∈ fs₁, (a (i + 1) ^ 2))) := by
315
+ refine mul_le_mul (by norm_num) ?_ ?_ (by norm_num)
316
+ . rw [← h₆₂, Finset.sum_union h₆₁]
317
+ have g₀: ∑ i ∈ fs₁, a (i + 1) ^ 2 = ∑ i ∈ fs₀, (a i) ^ 2 := by
318
+ refine sum_bij ?_ ?h.b2 ?h.b3 ?h.b4 ?h.b5
319
+ . intros b _
320
+ exact (b + 1)
321
+ . intros b hb₀
322
+ apply mem_filter.mp at hb₀
323
+ cases' hb₀ with hb₀ hb₁
324
+ have hb₂: Odd (b + 1) := by exact Even.add_one hb₁
325
+ have hb₃: b ≤ 98 := by
326
+ by_contra hc₀
327
+ apply mem_range.mp at hb₀
328
+ interval_cases b
329
+ have hc₁: ¬ Even 99 := by decide
330
+ exact hc₁ hb₁
331
+ have hb₄: b + 1 < 100 := by linarith
332
+ have hb₅: (b + 1) ∈ fs₂ := by exact mem_range.mpr hb₄
333
+ refine mem_filter.mpr ?_
334
+ exact And.symm ⟨hb₂, hb₅⟩
335
+ . intros b _ c _ hb₂
336
+ linarith
337
+ . intros b hb₀
338
+ use (b - 1)
339
+ refine exists_prop.mpr ?h.a
340
+ have hb₁: b ∈ fs₂ ∧ Odd b := by exact mem_filter.mp hb₀
341
+ have hb₂: 1 ≤ b := by
342
+ by_contra hc
343
+ interval_cases b
344
+ have hb₃: ¬ Odd 0 := by decide
345
+ exact hb₃ hb₁.2
346
+ constructor
347
+ . cases' hb₁ with hb₁ hb₃
348
+ have hb₄: Even (b - 1) := by exact Nat.Odd.sub_odd hb₃ (by decide)
349
+ have hb₅: (b - 1) ∈ fs₂ := by
350
+ refine mem_range.mpr ?_
351
+ have hb₆: b < 100 := by exact List.mem_range.mp hb₁
352
+ omega
353
+ refine mem_filter.mpr ?_
354
+ exact And.symm ⟨hb₄, hb₅⟩
355
+ . exact Nat.sub_add_cancel hb₂
356
+ . exact fun a_1 _ => rfl
357
+ have g₁: ∑ x ∈ fs₁, a (x + 1) ^ 2 * a (x + 2) ^ 2 =
358
+ ∑ x ∈ fs₀, a (x) ^ 2 * a (x + 1) ^ 2 := by
359
+ refine sum_bij ?_ ?_ ?_ ?_ ?_
360
+ . intros b _
361
+ exact (b + 1)
362
+ . intros b hb₀
363
+ apply mem_filter.mp at hb₀
364
+ cases' hb₀ with hb₀ hb₁
365
+ have hb₂: Odd (b + 1) := by exact Even.add_one hb₁
366
+ have hb₃: b ≤ 98 := by
367
+ by_contra hc₀
368
+ apply mem_range.mp at hb₀
369
+ interval_cases b
370
+ have hc₁: ¬ Even 99 := by decide
371
+ exact hc₁ hb₁
372
+ have hb₄: b + 1 < 100 := by linarith
373
+ have hb₅: (b + 1) ∈ fs₂ := by exact mem_range.mpr hb₄
374
+ refine mem_filter.mpr ?_
375
+ exact And.symm ⟨hb₂, hb₅⟩
376
+ . intros b _ c _ hb₂
377
+ linarith
378
+ . intros b hb₀
379
+ use (b - 1)
380
+ refine exists_prop.mpr ?h.b
381
+ have hb₁: b ∈ fs₂ ∧ Odd b := by exact mem_filter.mp hb₀
382
+ have hb₂: 1 ≤ b := by
383
+ by_contra hc
384
+ interval_cases b
385
+ have hb₃: ¬ Odd 0 := by decide
386
+ exact hb₃ hb₁.2
387
+ constructor
388
+ . cases' hb₁ with hb₁ hb₃
389
+ have hb₄: Even (b - 1) := by exact Nat.Odd.sub_odd hb₃ (by decide)
390
+ have hb₅: (b - 1) ∈ fs₂ := by
391
+ refine mem_range.mpr ?_
392
+ have hb₆: b < 100 := by exact List.mem_range.mp hb₁
393
+ omega
394
+ refine mem_filter.mpr ?_
395
+ exact And.symm ⟨hb₄, hb₅⟩
396
+ . exact Nat.sub_add_cancel hb₂
397
+ . exact fun a_1 _ => rfl
398
+ rw [g₀, g₁, Finset.sum_mul_sum, add_comm, ← sum_add_distrib]
399
+ refine sum_le_sum ?_
400
+ intros x hx₀
401
+ apply mem_filter.mp at hx₀
402
+ cases' hx₀ with hx₀ hx₁
403
+ apply mem_range.mp at hx₀
404
+ by_cases hx₃: x < 99
405
+ . clear h₀ h₁ h₂ h₃ h₄ h₆₀ g₀ g₁
406
+ let fs₃ : Finset ℕ := {x, (x + 2)}
407
+ have hx₄: fs₃ ⊆ fs₀ := by
408
+ intros b hb₀
409
+ have hb₁: b = x ∨ b = x + 2 := by
410
+ have g₀: fs₃ = {x, x + 2} := by rfl
411
+ simp_all only [mem_insert, mem_singleton]
412
+ cases' hb₁ with hb₁ hb₁
413
+ . rw [hb₁]
414
+ refine mem_filter.mpr ?_
415
+ apply mem_range.mpr at hx₀
416
+ exact And.symm ⟨hx₁, hx₀⟩
417
+ . rw [hb₁]
418
+ refine mem_filter.mpr ?_
419
+ constructor
420
+ . have hx₄: x < 98 := by
421
+ by_contra hc
422
+ interval_cases x
423
+ have hx₅: ¬ Odd 98 := by decide
424
+ apply hx₅ hx₁
425
+ refine mem_range.mpr ?_
426
+ linarith
427
+ . refine Odd.add_even hx₁ ?_
428
+ decide
429
+ have hx₅: ∑ j ∈ fs₃, a (x + 1) ^ 2 * a j ^ 2 = a (x + 1) ^ 2 * a x ^ 2 + a (x + 1) ^ 2 * a (x + 2) ^ 2 := by
430
+ have hx₆: fs₃ = {x, x + 2} := by rfl
431
+ refine Finset.sum_eq_add_of_mem (x) (x + 2) ?_ ?_ (by norm_num) ?_
432
+ . rw [hx₆]
433
+ exact mem_insert_self x {x + 2}
434
+ . rw [hx₆]
435
+ simp
436
+ . intros c hc₀ hc₁
437
+ exfalso
438
+ rw [hx₆] at hc₀
439
+ simp only [mem_insert, mem_singleton] at hc₀
440
+ have hc₃: ¬ (c ≠ x ∧ c ≠ x + 2) := by
441
+ omega
442
+ exact hc₃ hc₁
443
+ rw [← Finset.sum_sdiff hx₄, hx₅]
444
+ refine le_add_left ?_
445
+ refine le_of_eq ?_
446
+ rw [mul_comm (a x ^ 2) (a (x + 1) ^ 2)]
447
+ . interval_cases x
448
+ norm_num
449
+ have hx₄: a 101 = a 1 := by exact h₁ 100 0 rfl
450
+ let fs₃: Finset ℕ := {1, 99}
451
+ have hx₅: fs₃ ⊆ fs₀ := by
452
+ refine Finset.subset_iff.mpr ?_
453
+ intros b hb₀
454
+ have hb₁: b = 1 ∨ b = 99 := by exact List.mem_pair.mp hb₀
455
+ cases' hb₁ with hb₂ hb₂
456
+ . refine mem_filter.mpr ?_
457
+ rw [hb₂]
458
+ constructor
459
+ . refine mem_range.mpr (by decide)
460
+ . decide
461
+ . rw [hb₂]
462
+ refine mem_filter.mpr ?_
463
+ constructor
464
+ . exact self_mem_range_succ 99
465
+ . decide
466
+ have hx₆: ∑ x ∈ fs₃, a 100 ^ 2 * a x ^ 2 = a 100 ^ 2 * a 99 ^ 2 + a 100 ^ 2 * a 1 ^ 2 := by
467
+ clear h₀ h₁ h₂ h₃ h₄ h₆₀
468
+ have hx₇: fs₃ = {1, 99} := by rfl
469
+ refine Finset.sum_eq_add_of_mem (99:ℕ) (1:ℕ) ?_ ?_ (by norm_num) ?_
470
+ . rw [hx₇]
471
+ decide
472
+ . rw [hx₇]
473
+ decide
474
+ . intros c hc₀ hc₁
475
+ exfalso
476
+ have hc₂: c = 99 ∨ c = 1 := by
477
+ refine Or.symm ?_
478
+ exact List.mem_pair.mp hc₀
479
+ have hc₃: ¬ (c ≠ 99 ∧ c ≠ 1) := by omega
480
+ exact hc₃ hc₁
481
+ rw [← Finset.sum_sdiff hx₅, hx₄, hx₆]
482
+ refine le_add_left ?_
483
+ refine le_of_eq ?_
484
+ rw [mul_comm (a 99 ^ 2) (a 100 ^ 2)]
485
+ . exact _root_.zero_le (∑ i ∈ range 100, a (i + 1) ^ 2 * a (i + 2) ^ 2)
486
+ have h₆₄: 4 * ((∑ i ∈ fs₀, (a (i + 1) ^ 2)) * (∑ i ∈ fs₁, (a (i + 1) ^ 2))) ≤
487
+ (∑ i ∈ fs₀, (a (i + 1) ^ 2) + ∑ i ∈ fs₁, (a (i + 1) ^ 2)) ^ 2 := by
488
+ have g₀: ∀ x y : ℝ, 4 * x * y ≤ (x + y) ^ 2 := by
489
+ intros x y
490
+ rw [add_sq]
491
+ have g₁: 2 * x * y ≤ x ^ 2 + y ^ 2 := by exact two_mul_le_add_sq x y
492
+ linarith
493
+ rw [← mul_assoc]
494
+ let x := (∑ i ∈ fs₀, a (i + 1) ^ 2)
495
+ let y := (∑ i ∈ fs₁, a (i + 1) ^ 2)
496
+ refine g₀ x y
497
+ have h₆₅: (∑ i ∈ fs₀, (a (i + 1) ^ 2) + ∑ i ∈ fs₁, (a (i + 1) ^ 2)) ^ 2 = 1 := by
498
+ rw [← Finset.sum_union h₆₁, h₆₂, h₀]
499
+ exact one_pow 2
500
+ refine le_trans h₆₃ ?_
501
+ refine le_trans h₆₄ ?_
502
+ rw [h₆₅]
503
+ let S : NNReal := ∑ x ∈ Finset.range 99, ((a (x + 1)) ^ 2 * a (x + 2)) + (a 100) ^ 2 * a 1
504
+ have hS : S = ∑ x ∈ Finset.range 99, ((a (x + 1)) ^ 2 * a (x + 2)) + (a 100) ^ 2 * a 1 := by rfl
505
+ rw [← hS]
506
+ have hS₁ : S = ∑ x ∈ Finset.range 100, ((a (x + 1)) ^ 2 * a (x + 2)) := by
507
+ rw [Finset.sum_range_succ]
508
+ norm_num
509
+ have g₀: a 101 = a 1 := by exact h₁ 100 0 rfl
510
+ rw [g₀]
511
+ have h₇: (3 * S) ^ 2 ≤ 2 := by
512
+ have h₇₀: 3 * S = ∑ x ∈ Finset.range 100, (a (x + 2) * (a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3))) := by
513
+ have g₀: ∑ x ∈ Finset.range 100, (a (x + 2) * (a (x + 1) ^ 2 + 2 * a (x + 2) * a (x + 3))) =
514
+ ∑ x ∈ Finset.range 100, (a (x + 1) ^ 2 * a (x + 2) + 2 * a (x + 2) ^ 2 * a (x + 3)) := by
515
+ refine Finset.sum_congr rfl ?_
516
+ intros x _
517
+ ring_nf
518
+ have g₁: (3:NNReal) = 1 + 2 := by norm_num
519
+ rw [g₀, Finset.sum_add_distrib]
520
+ rw [g₁, hS₁, add_mul, one_mul, Finset.mul_sum]
521
+ simp
522
+ rw [Finset.sum_range_succ' _ 99, sum_range_succ _ 99]
523
+ norm_num
524
+ have g₂: a 101 = a 1 := by exact h₁ 100 0 rfl
525
+ have g₃: a 102 = a 2 := by exact h₁ 101 1 rfl
526
+ rw [g₂, g₃, ← mul_assoc 2]
527
+ simp
528
+ refine Finset.sum_congr rfl ?_
529
+ intros x _
530
+ ring_nf
531
+ rw [← h₇₀] at h₄
532
+ refine le_trans h₄ ?_
533
+ have h₇₁: ∑ x ∈ range 100, (a (x + 1) ^ 4 + 6 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) =
534
+ ∑ x ∈ range 100, (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) +
535
+ ∑ x ∈ range 100, 4 * a (x + 1) ^ 2 * a (x + 2) ^ 2 := by
536
+ rw [← Finset.sum_add_distrib]
537
+ refine Finset.sum_congr rfl ?_
538
+ intros x _
539
+ ring_nf
540
+ have h₇₂: ∑ x ∈ range 100, (a (x + 1) ^ 4 + 2 * a (x + 1) ^ 2 * a (x + 2) ^ 2 + 2 * a (x + 1) ^ 2 * a (x + 3) ^ 2) ≤ 1 := by
541
+ refine le_trans (aux2 a 100 ?_ h₁) ?_
542
+ . omega
543
+ . refine (sq_le_one_iff₀ ?_).mpr ?_
544
+ . exact _root_.zero_le (∑ x ∈ range 100, a (x + 1) ^ 2)
545
+ . rw [← h₀]
546
+ rw [h₇₁, ← one_add_one_eq_two]
547
+ refine add_le_add ?_ h₆
548
+ norm_num
549
+ exact h₇₂
550
+ have h₈ : S ≤ (NNReal.sqrt 2) / (3:NNReal) := by
551
+ have h₆₀: NNReal.sqrt (((3:NNReal) * S) ^ 2) ≤ NNReal.sqrt 2 := by
552
+ exact NNReal.sqrt_le_sqrt.mpr h₇
553
+ rw [sqrt_sq, mul_comm] at h₆₀
554
+ refine (le_div_iff₀ (by norm_num)).mpr h₆₀
555
+ have h₉: (NNReal.sqrt 2) / (3:NNReal) < (12:NNReal) / (25:NNReal) := by
556
+ have h₇₁: 2 < 144 / (625:NNReal) * 9 := by
557
+ refine (one_lt_div (by norm_num)).mp ?_
558
+ rw [mul_comm_div, ← mul_div_assoc, div_div]
559
+ norm_num
560
+ refine (one_lt_div (by norm_num)).mpr ?_
561
+ norm_num
562
+ have h₇₂: (NNReal.sqrt 2 / 3:NNReal) ^ 2 < (12 / 25:NNReal) ^ 2 := by
563
+ rw [div_pow, div_pow]
564
+ norm_num
565
+ refine (div_lt_iff₀ ?_).mpr h₇₁
566
+ exact ofNat_pos'
567
+ have h₇₃: NNReal.sqrt ((NNReal.sqrt 2 / 3) ^ 2) < NNReal.sqrt ((12 / 25) ^ 2) := by
568
+ exact sqrt_lt_sqrt.mpr h₇₂
569
+ rw [sqrt_sq, sqrt_sq] at h₇₃
570
+ exact h₇₃
571
+ exact lt_of_le_of_lt h₈ h₉
imo_proofs/imo_2022_p2.lean ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+
5
+ theorem imo_2022_p2_simple
6
+ (g: ℝ → ℝ)
7
+ (h₀: ∀ x, 0 < x → ∃ y:ℝ , (0 < y ∧ g (x) + g (y) ≤ 2 * x * y
8
+ ∧ (∀ z:ℝ, (0 < z ∧ z ≠ y) → ¬ g (x) + g (z) ≤ 2 * x * z) )) :
9
+ (∀ x:ℝ , 0 < x → g x = x^2) := by
10
+ have h₁: ∀ x y:ℝ , 0 < x ∧ 0 < y → g x + g y ≤ 2 * x * y → x = y := by
11
+ intros x y hp h₁
12
+ by_contra! hc
13
+ have g₁: 2 * x * x < g x + g x := by
14
+ let ⟨p,h₁₁⟩ := h₀ x hp.1
15
+ cases' h₁₁ with h₁₁ h₁₂
16
+ cases' h₁₂ with h₁₂ h₁₃
17
+ by_cases hxp: x ≠ p
18
+ . have h₁₄: ¬ g x + g x ≤ 2 * x * x := by
19
+ refine h₁₃ x ?_
20
+ constructor
21
+ . exact hp.1
22
+ . exact hxp
23
+ exact not_le.mp h₁₄
24
+ . push_neg at hxp
25
+ exfalso
26
+ have hpy: y ≠ p := by exact Ne.trans_eq (id (Ne.symm hc)) hxp
27
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
28
+ refine h₁₃ y ?_
29
+ constructor
30
+ . exact hp.2
31
+ . exact hpy
32
+ linarith
33
+ have g₂: 2 * y * y < g y + g y := by
34
+ let ⟨p,h₁₁⟩ := h₀ y hp.2
35
+ cases' h₁₁ with h₁₁ h₁₂
36
+ cases' h₁₂ with h₁₂ h₁₃
37
+ by_cases hyp: y ≠ p
38
+ . have h₁₄: ¬ g y + g y ≤ 2 * y * y := by
39
+ refine h₁₃ y ?_
40
+ constructor
41
+ . exact hp.2
42
+ . exact hyp
43
+ exact not_le.mp h₁₄
44
+ . push_neg at hyp
45
+ exfalso
46
+ have hpx: x ≠ p := by exact Ne.trans_eq hc hyp
47
+ have hcy: ¬g x + g y ≤ 2 * x * y := by
48
+ rw [add_comm, mul_right_comm]
49
+ refine h₁₃ x ?_
50
+ constructor
51
+ . exact hp.1
52
+ . exact hpx
53
+ linarith
54
+ ring_nf at g₁ g₂
55
+ simp at g₁ g₂
56
+ have g₃: x ^ 2 + y ^ 2 < g x + g y := by exact add_lt_add g₁ g₂
57
+ have g₄: x ^ 2 + y ^ 2 < 2 * x * y := by exact LT.lt.trans_le g₃ h₁
58
+ have g₅: (x - y) ^ 2 < 0 := by
59
+ rw [sub_sq, sub_add_eq_add_sub]
60
+ exact sub_neg.mpr g₄
61
+ have g₆: (x - y) ≠ 0 := by exact sub_ne_zero.mpr hc
62
+ have g₇: 0 < (x - y) ^ 2 := by exact (sq_pos_iff).mpr g₆
63
+ have g₈: (0:ℝ) ≠ 0 := by
64
+ refine ne_of_lt ?_
65
+ exact lt_trans g₇ g₅
66
+ refine false_of_ne g₈
67
+ have h₂: ∀ x:ℝ , 0 < x → g x ≤ x ^ 2 := by
68
+ intros x hxp
69
+ let ⟨y,h₁₁⟩ := h₀ x hxp
70
+ cases' h₁₁ with h₁₁ h₁₂
71
+ cases' h₁₂ with h₁₂ h₁₃
72
+ have hxy: x = y := by
73
+ apply h₁ x y
74
+ . exact { left := hxp, right := h₁₁ }
75
+ . exact h₁₂
76
+ rw [← hxy] at h₁₂
77
+ linarith
78
+ have h₃: ∀ x:ℝ , 0 < x → ¬ g x < x ^ 2 := by
79
+ simp
80
+ by_contra! hc
81
+ let ⟨x,hxp⟩ := hc
82
+ cases' hxp with hxp h₃
83
+ let d₁:ℝ := x ^ 2 - g x
84
+ have hd₁ : g x = x ^ 2 - d₁ := by exact (sub_sub_self (x ^ 2) (g x)).symm
85
+ let z:ℝ := x + Real.sqrt d₁
86
+ have hz: z = x + Real.sqrt d₁ := by exact rfl
87
+ have hzp: 0 < z := by
88
+ refine add_pos hxp ?_
89
+ refine Real.sqrt_pos_of_pos ?_
90
+ exact sub_pos.mpr h₃
91
+ have hxz: z ≠ x := by
92
+ rw [hz]
93
+ simp
94
+ push_neg
95
+ refine Real.sqrt_ne_zero'.mpr ?_
96
+ exact sub_pos.mpr h₃
97
+ have h₅: g x + g z ≤ 2 * x * z := by
98
+ rw [hd₁]
99
+ have h₅₁: - d₁ + Real.sqrt (x ^ 2 - (x ^ 2 - d₁)) ^ 2 ≤ 0 := by
100
+ simp
101
+ rw [Real.sq_sqrt]
102
+ exact sub_nonneg_of_le (h₂ x hxp)
103
+ have h₅₂: x ^ 2 - d₁ + z ^ 2 ≤ 2 * x * z := by
104
+ rw [hz, mul_add, add_sq]
105
+ ring_nf
106
+ repeat rw [add_assoc]
107
+ refine add_le_add_left ?_ (x * Real.sqrt (x ^ 2 - g x) * 2)
108
+ rw [hd₁]
109
+ linarith
110
+ exact add_le_of_add_le_left h₅₂ (h₂ z hzp)
111
+ let ⟨y,hyp⟩ := h₀ x hxp
112
+ cases' hyp with hyp h₆
113
+ cases' h₆ with h₆ h₇
114
+ have hxy: x = y := by
115
+ apply h₁
116
+ . exact { left := hxp, right := hyp }
117
+ . exact h₆
118
+ have h₈: ¬g x + g z ≤ 2 * x * z := by
119
+ refine h₇ z ?_
120
+ constructor
121
+ . exact hzp
122
+ . exact Ne.trans_eq hxz hxy
123
+ linarith[h₅,h₈]
124
+ intros x hxp
125
+ have g₂: g x ≤ x ^ 2 := by exact h₂ x hxp
126
+ have g₃: ¬ g x < x ^ 2 := by exact h₃ x hxp
127
+ linarith
128
+
129
+
130
+
131
+
132
+
133
+ theorem imo_2022_p2
134
+ (f: ℝ → ℝ)
135
+ (hfp: ∀ x:ℝ, 0 < x → 0 < f x)
136
+ (h₀: ∀ x:ℝ , 0 < x → ∃! y:ℝ , 0 < y ∧ (x * f (y) + y * f (x) ≤ 2) ):
137
+ ∀ x:ℝ , 0 < x → f (x) = 1 / x := by
138
+ have h₁: ∀ x y:ℝ , (0 < x ∧ 0 < y) → (x * f (y) + y * f (x) ≤ 2) → x = y := by
139
+ intros x y hp h₁
140
+ by_contra! hc
141
+ have h₁₀: x * f x + x * f x > 2 := by
142
+ let ⟨z,h₁₁⟩ := h₀ x hp.1
143
+ cases' h₁₁ with h₁₁ h₁₂
144
+ have h₁₄: y = z := by
145
+ apply h₁₂ y
146
+ constructor
147
+ . exact hp.2
148
+ . exact h₁
149
+ have hxz: ¬ x = z := by exact Ne.trans_eq hc h₁₄
150
+ have h₁₆: ¬ (fun y => 0 < y ∧ x * f y + y * f x ≤ 2) x := by
151
+ exact mt (h₁₂ x) hxz
152
+ have h₁₇: ¬ (0 < x ∧ x * f x + x * f x ≤ 2) := by exact h₁₆
153
+ push_neg at h₁₇
154
+ exact h₁₇ hp.1
155
+ have h₁₁: y * f y + y * f y > 2 := by
156
+ let ⟨z,h₁₁⟩ := h₀ y hp.2
157
+ cases' h₁₁ with h₁₁ h₁₂
158
+ have h₁₄: x = z := by
159
+ apply h₁₂ x
160
+ constructor
161
+ . exact hp.1
162
+ . rw [add_comm]
163
+ exact h₁
164
+ have hxz: ¬ y = z := by exact Ne.trans_eq (id (Ne.symm hc)) h₁₄
165
+ have h₁₆: ¬ (fun y_2 => 0 < y_2 ∧ y * f y_2 + y_2 * f y ≤ 2) y := by
166
+ exact mt (h₁₂ y) hxz
167
+ have h₁₇: ¬ (0 < y ∧ y * f y + y * f y ≤ 2) := by exact h₁₆
168
+ push_neg at h₁₇
169
+ exact h₁₇ hp.2
170
+ ring_nf at h₁₀ h₁₁
171
+ simp at h₁₀ h₁₁
172
+ have h₁₅: 1 / x < f x := by exact (div_lt_iff₀' hp.1).mpr (h₁₀)
173
+ have h₁₆: 1 / y < f y := by exact (div_lt_iff₀' hp.2).mpr (h₁₁)
174
+ have h₁₂: x / y + y / x < 2 := by
175
+ refine lt_of_le_of_lt' h₁ ?_
176
+ refine add_lt_add ?_ ?_
177
+ . rw [← mul_one_div]
178
+ exact (mul_lt_mul_left hp.1).mpr h₁₆
179
+ . rw [← mul_one_div]
180
+ exact (mul_lt_mul_left hp.2).mpr h₁₅
181
+ have h₁₃: 2 < x / y + y / x := by
182
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.1)
183
+ refine lt_of_mul_lt_mul_right ?_ (le_of_lt hp.2)
184
+ repeat rw [add_mul, mul_assoc]
185
+ rw [mul_comm x y, ← mul_assoc (x/y)]
186
+ rw [div_mul_comm x y y, div_mul_comm y x x, div_self, div_self]
187
+ . ring_nf
188
+ refine lt_of_sub_pos ?_
189
+ rw [mul_comm _ 2, ← mul_assoc]
190
+ rw [← sub_sq']
191
+ refine sq_pos_of_ne_zero ?_
192
+ exact sub_ne_zero.mpr hc.symm
193
+ . exact ne_of_gt hp.1
194
+ . exact ne_of_gt hp.2
195
+ linarith
196
+ have h₂: ∀ x:ℝ , 0 < x → x * f x ≤ 1 := by
197
+ intros x hxp
198
+ let ⟨y,h₂₁⟩ := h₀ x hxp
199
+ cases' h₂₁ with h₂₁ h₂₂
200
+ have hxy: x = y := by
201
+ apply h₁ x y
202
+ . constructor
203
+ . exact hxp
204
+ . exact h₂₁.1
205
+ . exact h₂₁.2
206
+ rw [← hxy] at h₂₁
207
+ linarith
208
+ have h₃: ∀ x:ℝ , 0 < x → ¬ x * f x < 1 := by
209
+ by_contra! hc
210
+ let ⟨x,hxp⟩ := hc
211
+ cases' hxp with hxp h₃
212
+ let d₁:ℝ := 1 - x * f x
213
+ have hd₁ : x * f x = 1 - d₁ := by exact (sub_sub_self 1 (x * f x)).symm
214
+ let z:ℝ := x + d₁ / f x
215
+ have hz: z = x + d₁ / f x := by exact rfl
216
+ have hzp: 0 < z := by
217
+ refine add_pos hxp ?_
218
+ refine div_pos ?_ ?_
219
+ . exact sub_pos.mpr h₃
220
+ . exact hfp x hxp
221
+ have hxz: ¬ x = z := by
222
+ by_contra! hcz₀
223
+ rw [← hcz₀] at hz
224
+ have hcz₁: 0 < d₁ / f x := by
225
+ refine div_pos ?_ (hfp x hxp)
226
+ exact sub_pos.mpr h₃
227
+ linarith
228
+ have h₄: ¬ (x * f z + z * f x ≤ 2) := by
229
+ have h₄₁: x * f z + z * f x ≤ 2 → x = z := by
230
+ exact h₁ x z { left := hxp, right := hzp }
231
+ exact mt h₄₁ hxz
232
+ have h₅: x * f z < 1 := by
233
+ suffices h₅₁: z * f z ≤ 1 by
234
+ refine lt_of_lt_of_le ?_ h₅₁
235
+ refine (mul_lt_mul_right (hfp z hzp)).mpr ?_
236
+ rw [hz]
237
+ refine lt_add_of_pos_right x ?_
238
+ refine div_pos ?_ (hfp x hxp)
239
+ exact sub_pos.mpr h₃
240
+ exact h₂ z hzp
241
+ have h₆: x * f z + z * f x < 2 := by
242
+ suffices h₇: z * f x ≤ 1 by
243
+ linarith
244
+ rw [hz, add_mul, hd₁]
245
+ rw [div_mul_comm d₁ (f x) (f x)]
246
+ rw [div_self]
247
+ . rw [one_mul, sub_add_cancel]
248
+ . exact Ne.symm (ne_of_lt (hfp x hxp))
249
+ linarith
250
+ intros x hxp
251
+ have h₄: x * f x ≤ 1 := by exact h₂ x hxp
252
+ have h₅: ¬ x * f x < 1 := by exact h₃ x hxp
253
+ refine eq_div_of_mul_eq ?_ ?_
254
+ . exact ne_of_gt hxp
255
+ . push_neg at h₅
256
+ linarith
imo_proofs/imo_2022_p5.lean ADDED
@@ -0,0 +1,587 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ set_option linter.unusedVariables.analyzeTactics true
3
+
4
+ open Nat
5
+
6
+
7
+ lemma mylemma_1
8
+ (b p: ℕ)
9
+ (h₀: 0 < b)
10
+ (hbp: b < p) :
11
+ (1 + (b * p + b ^ p) ≤ (1 + b) ^ p) := by
12
+ refine Nat.le_induction ?_ ?_ p hbp
13
+ . rw [add_pow 1 b b.succ]
14
+ rw [Finset.sum_range_succ _ b.succ]
15
+ simp
16
+ rw [Finset.sum_range_succ _ b]
17
+ simp
18
+ rw [add_comm _ (b * (b + 1))]
19
+ have gb: b = b - 1 + 1 := by exact (Nat.sub_eq_iff_eq_add h₀).mp rfl
20
+ nth_rewrite 7 [gb]
21
+ rw [Finset.sum_range_succ' _ (b-1)]
22
+ simp
23
+ omega
24
+ . intros n _ h₂
25
+ nth_rewrite 2 [pow_add]
26
+ rw [pow_one]
27
+ have h₃: (1 + (b * n + b ^ n)) * (1 + b) ≤ ((1 + b) ^ n) * (1 + b) := by
28
+ exact mul_le_mul_right' h₂ (1 + b)
29
+ have h₄: 1 + (b * (n + 1) + b ^ (n + 1)) ≤ (1 + (b * n + b ^ n)) * (1 + b) := by
30
+ ring_nf
31
+ rw [Nat.add_assoc _ (b ^ 2 * n) (b ^ n)]
32
+ exact Nat.le_add_right (1 + b + b * b ^ n + b * n) (b ^ 2 * n + b ^ n)
33
+ exact le_trans h₄ h₃
34
+
35
+
36
+ lemma mylemma_2
37
+ (b: ℕ) :
38
+ (b.factorial ≤ b ^ b) := by
39
+ -- exact factorial_le_pow b
40
+ -- lean 4 has the lemma factorial_le_pow
41
+ induction' b with n hi
42
+ . norm_num
43
+ . by_cases hnp: 0 < n
44
+ . rw [ factorial_succ, pow_add, pow_one, mul_comm ]
45
+ refine mul_le_mul_right (n + 1) ?_
46
+ have h₂: n^ n ≤ (n + 1)^n := by
47
+ refine (Nat.pow_le_pow_iff_left ?_).mpr ?_
48
+ . linarith
49
+ . linarith
50
+ exact le_trans hi h₂
51
+ . push_neg at hnp
52
+ interval_cases n
53
+ simp
54
+
55
+
56
+ lemma mylemma_3
57
+ (a b p: ℕ)
58
+ (hp: Nat.Prime p)
59
+ (h₁: a ^ p = b.factorial + p)
60
+ (hbp: p ≤ b) :
61
+ (p ∣ a) := by
62
+ have h₂: p ∣ b.factorial := by exact Nat.dvd_factorial (Nat.Prime.pos hp) hbp
63
+ have h₃: p ∣ b.factorial + p := by exact Nat.dvd_add_self_right.mpr h₂
64
+ have h₄: p ∣ a^p := by
65
+ rw [h₁]
66
+ exact h₃
67
+ exact Nat.Prime.dvd_of_dvd_pow hp h₄
68
+
69
+
70
+ lemma mylemma_42
71
+ (a b : ℕ)
72
+ (h₀: 2 ≤ a)
73
+ (h₁: a < b) :
74
+ (a + b < a * b ) := by
75
+ have h₂: a + b < b + b := by exact add_lt_add_right h₁ b
76
+ have h₃: b + b ≤ a * b := by
77
+ rw [← two_mul]
78
+ exact mul_le_mul_right' h₀ b
79
+ exact gt_of_ge_of_gt h₃ h₂
80
+
81
+
82
+ lemma mylemma_43
83
+ (p: ℕ) :
84
+ (Finset.Ico p (2 * p - 1)).prod (fun x => x + 1)
85
+ = (Finset.range (p - 1)).prod (fun x => p + (x + 1)) := by
86
+ rw [Finset.prod_Ico_eq_prod_range _ (p) (2 * p - 1)]
87
+ have h₀: 2 * p - 1 - p = p - 1 := by omega
88
+ rw [h₀]
89
+ exact rfl
90
+
91
+
92
+ lemma mylemma_44
93
+ (p: ℕ)
94
+ (hp: 2 ≤ p) :
95
+ (Finset.range (p - 1)).prod (fun (x : ℕ) => x + 1)
96
+ = (Finset.range (p - 1)).prod (fun (x : ℕ) => p - (x + 1)) := by
97
+ refine Nat.le_induction ?_ ?_ p hp
98
+ . norm_num
99
+ . intros n hn2 h₀
100
+ simp at *
101
+ have hn: 0 < n := by exact lt_of_succ_lt hn2
102
+ rw [← Nat.mul_factorial_pred hn, h₀]
103
+ let f: (ℕ → ℕ) := fun (x : ℕ) => n - x
104
+ have h₁: (Finset.range n).prod f =
105
+ (Finset.range 1).prod f * (Finset.Ico 1 n).prod f := by
106
+ exact (Finset.prod_range_mul_prod_Ico (fun k => n - k) hn).symm
107
+ rw [h₁]
108
+ have h₂: (Finset.range 1).prod f = n := by
109
+ exact Finset.prod_range_one fun k => n - k
110
+ rw [h₂]
111
+ simp
112
+ left
113
+ rw [Finset.prod_Ico_eq_prod_range f 1 n]
114
+ ring_nf
115
+ exact rfl
116
+
117
+
118
+ lemma mylemma_41
119
+ (b p: ℕ)
120
+ -- (h₀: 0 < b)
121
+ (hp: Nat.Prime p)
122
+ (hb2p: b < 2 * p) :
123
+ b.factorial + p < p ^ (2 * p) := by
124
+ have h₁: b.factorial ≤ (2*p - 1).factorial := by
125
+ refine factorial_le ?_
126
+ exact le_pred_of_lt hb2p
127
+ have gp: 2 ≤ p := by exact Prime.two_le hp
128
+ have gp1: (p - 1) + 1 = p := by
129
+ refine Nat.sub_add_cancel ?_
130
+ exact one_le_of_lt gp
131
+ let f: (ℕ → ℕ) := (fun (x : ℕ) => x + 1)
132
+ have h₂: (Finset.range (2 * p - 1)).prod f =
133
+ (Finset.range (p - 1)).prod (fun (x : ℕ) => p^2 - (x+1)^2) * p := by
134
+ -- break the prod into three segments rang(p-1) + p + (p+1) until 2p-1
135
+ have g₀: (Finset.range (2 * p - 1)).prod f = (Finset.range ((p - 1) + 1)).prod f
136
+ * (Finset.Ico ((p - 1) + 1) (2 * p - 1)).prod f := by
137
+ symm
138
+ refine Finset.prod_range_mul_prod_Ico f ?_
139
+ rw [gp1]
140
+ have gg₀: p + 2 - 1 ≤ 2 * p - 1 := by
141
+ refine Nat.sub_le_sub_right ?_ 1
142
+ rw [add_comm]
143
+ exact add_le_mul (by norm_num) gp
144
+ exact le_of_lt gg₀
145
+ have g₁: (Finset.range ((p - 1) + 1)).prod (fun (x : ℕ) => x + 1) =
146
+ (Finset.range (p - 1)).prod (fun (x : ℕ) => x + 1) * ((p - 1) + 1) := by
147
+ exact Finset.prod_range_succ _ (p - 1)
148
+ rw [g₁] at g₀
149
+ nth_rewrite 2 [mul_comm] at g₀
150
+ rw [← mul_assoc] at g₀
151
+ rw [gp1] at g₀ g₁
152
+ have g₂: (Finset.Ico ((p - 1) + 1) (2 * p - 1)).prod (fun (x : ℕ) => x + 1)
153
+ = (Finset.range (p - 1)).prod (fun (x : ℕ) => p + (x+1)) := by
154
+ rw [gp1]
155
+ exact mylemma_43 p
156
+ have g₃: (Finset.range (p - 1)).prod (fun (x : ℕ) => x + 1)
157
+ = (Finset.range (p - 1)).prod (fun (x : ℕ) => p - (x+1)) := by
158
+ exact mylemma_44 p gp
159
+ rw [gp1] at g₂
160
+ rw [g₂,g₃] at g₀
161
+ have g₄: (Finset.range (p - 1)).prod (fun (x : ℕ) => p + (x+1))
162
+ * (Finset.range (p - 1)).prod (fun (x : ℕ) => p - (x+1))
163
+ = (Finset.range (p - 1)).prod (fun (x : ℕ) => (p + (x+1)) * (p - (x+1))) := by
164
+ symm
165
+ exact Finset.prod_mul_distrib
166
+ have g₅: (fun (x : ℕ) => p ^ 2 - (x+1) ^ 2) = (fun (x : ℕ) => (p + (x+1)) * (p - (x+1))) := by
167
+ ext1 x
168
+ exact Nat.sq_sub_sq p (x + 1)
169
+ rw [g₄,← g₅] at g₀
170
+ exact g₀
171
+ have h₃: (Finset.range (p - 1)).prod (fun (x : ℕ) => p^2 - (x+1)^2) * p
172
+ ≤ (p^2)^(Finset.range (p - 1)).card * p := by
173
+ refine Nat.mul_le_mul_right ?_ ?_
174
+ refine Finset.prod_le_pow_card (Finset.range (p - 1)) ?_ (p^2) ?_
175
+ intros x _
176
+ exact (p ^ 2).sub_le ((x + 1) ^ 2)
177
+ simp at *
178
+ have h₄: b.factorial + p ≤ (p ^ 2) ^ (p - 1) * p + p := by
179
+ refine add_le_add_right ?_ p
180
+ refine le_trans ?_ h₃
181
+ rw [← h₂]
182
+ rw [Finset.prod_range_add_one_eq_factorial]
183
+ exact h₁
184
+ have h₅: b.factorial + p < (p ^ 2) ^ (p - 1) * p * p := by
185
+ refine lt_of_le_of_lt h₄ ?_
186
+ rw [add_comm]
187
+ nth_rewrite 2 [mul_comm]
188
+ refine mylemma_42 p ((p ^ 2) ^ (p - 1) * p) gp ?_
189
+ refine lt_mul_left (by linarith) ?_
190
+ rw [← pow_mul]
191
+ refine Nat.one_lt_pow ?_ (Nat.lt_of_succ_le gp)
192
+ refine Nat.mul_ne_zero (by norm_num) ?_
193
+ exact Nat.sub_ne_zero_iff_lt.mpr gp
194
+ rw [mul_assoc _ p p, ← pow_two p] at h₅
195
+ rw [← Nat.pow_succ, succ_eq_add_one, gp1] at h₅
196
+ rw [Nat.pow_mul]
197
+ exact h₅
198
+
199
+
200
+ lemma mylemma_4
201
+ (a b p: ℕ)
202
+ (h₀: 0 < a ∧ 0 < b)
203
+ (hp: Nat.Prime p)
204
+ (h₁: a ^ p = b.factorial + p)
205
+ (hbp: p ≤ b)
206
+ (h₂: p ∣ a)
207
+ (hb2p: b < 2 * p) :
208
+ (a = p) := by
209
+ have gp: p ≤ a := by exact Nat.le_of_dvd h₀.1 h₂
210
+ cases' lt_or_eq_of_le gp with h₃ h₃
211
+ . exfalso
212
+ cases' h₂ with c h₂
213
+ have gc: 0 < c := by
214
+ by_contra! hc0
215
+ interval_cases c
216
+ simp at *
217
+ linarith
218
+ by_cases hc: c < p
219
+ . have g₁: c ∣ c^p := by exact dvd_pow_self c (by linarith)
220
+ have h₄: c ∣ a^p := by
221
+ rw [h₂, mul_pow]
222
+ exact dvd_mul_of_dvd_right g₁ (p ^ p)
223
+ have h₅: c ∣ b.factorial := by exact Nat.dvd_factorial gc (by linarith)
224
+ have g₂: p = a ^ p - b.factorial := by
225
+ symm
226
+ rw [add_comm] at h₁
227
+ refine (Nat.sub_eq_iff_eq_add ?_).mpr h₁
228
+ rw [add_comm] at h₁
229
+ exact le.intro (h₁.symm)
230
+ have h₆: c ∣ p := by
231
+ rw [g₂]
232
+ exact dvd_sub' h₄ h₅
233
+ have h₇: c = 1 ∨ c = p := by exact (dvd_prime hp).mp h₆
234
+ cases' h₇ with h₇₀ h₇₁
235
+ . rw [h₇₀, mul_one] at h₂
236
+ rw [h₂] at h₃
237
+ linarith [h₃]
238
+ . rw [h₇₁] at hc
239
+ simp at hc
240
+ . push_neg at hc
241
+ have g₃: p^2 ≤ a := by
242
+ rw [h₂, pow_two]
243
+ exact mul_le_mul_left' hc p
244
+ have h₃: p^(2*p) ≤ a^p := by
245
+ rw [pow_mul]
246
+ exact pow_left_mono p g₃
247
+ have h₇: b.factorial + p < p^(2*p) := by exact mylemma_41 b p hp hb2p
248
+ rw [←h₁] at h₇
249
+ linarith
250
+ exact h₃.symm
251
+
252
+
253
+ lemma mylemma_53
254
+ (p: ℕ)
255
+ (hp5: 5 ≤ p) :
256
+ ((↑p:ℤ) ^ p ≡ ↑p * (↑p + 1) * (-1) ^ (p - 1) + (-1) ^ p [ZMOD (↑p + 1) ^ 2]) := by
257
+ -- have h₁: ↑p ^ p = Finset.range -- binomial expansion
258
+ -- take the first two elements out
259
+ -- show that all the other elements are individually divisible by (p+1)^2
260
+ -- conclude that their sum is divisible by (p+1)^2
261
+ -- summation ≡ 0 [ZMOD (↑p + 1) ^ 2]
262
+ -- now show that Nat.modeq.add
263
+ have h₀: (↑p:ℤ) = (↑p + 1) - 1 := by simp
264
+ have h₁: ↑p ^ p ≡ ((↑p + 1) - 1) ^ p [ZMOD (↑p + 1) ^ 2] := by rw [← h₀]
265
+ have h₂: (((↑p:ℤ) + 1) - 1) ^ p = (↑p * (↑p + 1) * (-1:ℤ) ^ (p - 1) + (-1) ^ p)
266
+ + (Finset.Ico 2 (p + 1)).sum (fun (k : ℕ) =>
267
+ (↑p + 1) ^ k * (-1:ℤ) ^ (p - k) * ↑(p.choose k)) := by
268
+ rw [sub_eq_add_neg]
269
+ rw [add_pow ((↑p:ℤ) + 1) (-1:ℤ)]
270
+ have g₀: 2 ≤ p + 1 := by
271
+ have gg₀: 5 + 1 ≤ p + 1 := by exact add_le_add_right hp5 1
272
+ refine le_trans ?_ gg₀
273
+ norm_num
274
+ have g₁: 1 ≤ 2 := by norm_num
275
+ rw [← Finset.sum_range_add_sum_Ico _ g₀]
276
+ rw [← Finset.sum_range_add_sum_Ico _ g₁]
277
+ simp
278
+ rw [add_comm]
279
+ simp
280
+ rw [mul_comm]
281
+ rw [mul_assoc]
282
+ have h₃: 0 ≡ (Finset.Ico 2 (p + 1)).sum (fun (k : ℕ) => (↑p + 1) ^ k * (-1) ^ (p - k) * ↑(p.choose k))
283
+ [ZMOD (↑p + 1) ^ 2] := by
284
+ refine Int.modEq_of_dvd ?_
285
+ simp
286
+ refine Finset.dvd_sum ?_
287
+ intros x g₀
288
+ have gx: 2 ≤ x := by exact (Finset.mem_Ico.mp g₀).left
289
+ rw [mul_assoc]
290
+ refine dvd_mul_of_dvd_left ?_ ((-1:ℤ) ^ (p - x) * ↑(p.choose x))
291
+ refine pow_dvd_pow ((↑p:ℤ) + 1) gx
292
+ rw [h₂] at h₁
293
+ rw [← add_zero ((↑p:ℤ) ^ p)] at h₁
294
+ exact Int.ModEq.add_right_cancel h₃ h₁
295
+
296
+
297
+ lemma mylemma_52
298
+ (p: ℕ)
299
+ (hp: Nat.Prime p)
300
+ (hp5: 5 ≤ p)
301
+ (h₀: (p + 1) ^ 2 ∣ p ^ p - p) :
302
+ False := by
303
+ have h₁: ((↑p^p - ↑p):ℤ) ≡ (↑(p.choose 1) * ↑(p + 1) * (-1:ℤ)^(p-1) + (-1:ℤ)^p) - ↑p
304
+ [ZMOD ↑(p+1)^2] := by
305
+ refine Int.ModEq.sub_right (↑p) ?_
306
+ simp
307
+ exact mylemma_53 p hp5
308
+ have gpo: Odd p := by
309
+ refine Nat.Prime.odd_of_ne_two hp ?_
310
+ linarith [hp5]
311
+ have gpe: Even (p - 1) := by
312
+ refine hp.even_sub_one ?_
313
+ linarith [hp5]
314
+ have g₁: (-1:ℤ) ^ (p - 1) = 1 := by exact Even.neg_one_pow gpe
315
+ have g₂: (-1:ℤ) ^ (p) = -1 := by exact Odd.neg_one_pow gpo
316
+ rw [g₁,g₂] at h₁
317
+ simp at h₁
318
+ have h₂: (p ^ p - p) ≡ (p * (p + 1)) - 1 - p [MOD ((p + 1) ^ 2)] := by
319
+ refine Int.natCast_modEq_iff.mp ?_
320
+ have g₃: p ≤ p^p := by
321
+ refine Nat.le_self_pow (by linarith) _
322
+ rw [Nat.cast_sub g₃]
323
+ have g₄: p ≤ p * (p + 1) - 1 := by
324
+ rw [mul_add]
325
+ simp
326
+ rw [add_comm, Nat.add_sub_assoc]
327
+ . simp
328
+ . rw [← pow_two]
329
+ refine Nat.one_le_pow 2 p (by linarith)
330
+ rw [Nat.cast_sub g₄]
331
+ have g₅: 1 ≤ p * (p + 1) := by
332
+ rw [← mul_one (p * (p + 1))]
333
+ refine Nat.le_mul_of_pos_left ?_ ?_
334
+ refine Nat.mul_pos (by linarith) (by linarith)
335
+ rw [Nat.cast_sub g₅]
336
+ rw [← sub_eq_add_neg] at h₁
337
+ norm_cast
338
+ norm_cast at h₁
339
+ have h₃: p * (p + 1) - 1 - p = p^2 - 1 := by
340
+ rw [Nat.sub_sub, mul_add]
341
+ simp
342
+ rw [← pow_two]
343
+ exact Nat.add_sub_add_right (p^2) p 1
344
+ rw [h₃] at h₂
345
+ clear h₃ gpo gpe g₁ g₂
346
+ -- now derive a line of contradictions from h₀
347
+ have hc₁: (p ^ p - p) ≡ 0 [MOD (p+1)^2] := by exact modEq_zero_iff_dvd.mpr h₀
348
+ -- mix the contradiction with what we had in h₂
349
+ have h₄: p ^ 2 - 1 ≡ 0 [MOD (p+1)^2] := by
350
+ apply Nat.ModEq.symm at h₂
351
+ exact Nat.ModEq.trans h₂ hc₁
352
+ have h₅: p - 1 ≡ 0 [MOD (p+1)] := by
353
+ rw [pow_two] at h₄
354
+ have g₀: p^2 - 1^2 = (p-1) * (p+1) := by
355
+ rw [mul_comm]
356
+ exact Nat.sq_sub_sq p 1
357
+ simp at g₀
358
+ rw [g₀] at h₄
359
+ have g₁: p + 1 ≠ 0 := by linarith
360
+ refine Nat.ModEq.mul_right_cancel' g₁ ?_
361
+ rw [zero_mul]
362
+ exact h₄
363
+ have h₆: p - 1 ≤ 0 := by
364
+ refine Nat.ModEq.le_of_lt_add h₅ ?_
365
+ simp
366
+ rw [← succ_eq_add_one]
367
+ refine Nat.sub_lt_succ p 1
368
+ have h₇: 0 < p - 1 := by
369
+ simp
370
+ linarith
371
+ linarith [h₆,h₇]
372
+
373
+
374
+ lemma mylemma_51
375
+ (p: ℕ)
376
+ (hpl: 5 ≤ p) :
377
+ (p + p.factorial < p ^ p) := by
378
+ -- we use induction
379
+ refine Nat.le_induction ?_ ?_ p (hpl)
380
+ . exact Nat.lt_of_sub_eq_succ rfl
381
+ . intros n hn h₁
382
+ have h₂: n + 1 + (n + 1).factorial = (n.factorial + 1) * (n + 1) := by
383
+ rw[add_mul, one_mul, Nat.factorial_succ]
384
+ rw [add_comm (n + 1)]
385
+ rw [mul_comm (n + 1)]
386
+ rw [h₂, pow_add, pow_one ]
387
+ refine Nat.mul_lt_mul_of_pos_right ?_ (by linarith)
388
+ have h₅: n ^ n < (n + 1) ^ n := by
389
+ refine Nat.pow_lt_pow_left ?_ ?_
390
+ . exact lt_add_one n
391
+ . refine Nat.ne_of_gt ?_
392
+ linarith
393
+ linarith
394
+
395
+
396
+ lemma mylemma_5
397
+ (b p: ℕ)
398
+ (hp: Nat.Prime p)
399
+ (hbp: p ≤ b)
400
+ (h₁: p ^ p = b.factorial + p)
401
+ (hp5: 5 ≤ p) :
402
+ (False) := by
403
+ -- first prove that b = p cannot be
404
+ by_cases h₄: b = p
405
+ . have h₅: p + p.factorial < p^p := by exact mylemma_51 p hp5
406
+ rw [h₄] at h₁
407
+ linarith
408
+ . have hpb: p < b := by exact lt_of_le_of_ne' hbp h₄
409
+ clear hbp h₄
410
+ have h₂: (p + 1) ^ 2 ∣ b.factorial := by
411
+ have g₁: p + 1 ≤ b := by exact succ_le_iff.mpr hpb
412
+ have g₂: 2 ∣ (p + 1) := by
413
+ have gg₁: Odd p := by
414
+ refine hp.odd_of_ne_two ?_
415
+ linarith
416
+ have gg₂: Even (p + 1) := by
417
+ refine gg₁.add_odd ?_
418
+ norm_num
419
+ exact even_iff_two_dvd.mp gg₂
420
+ have g₃: 2 * ((p+1)/2) * (p + 1) ∣ b.factorial := by
421
+ have gg₁: (p + 1).factorial ∣ b.factorial := by exact Nat.factorial_dvd_factorial g₁
422
+ have gg₂: (p + 1).factorial = (p + 1) * p.factorial := by exact factorial_succ p
423
+ rw [mul_comm] at gg₂
424
+ have gg₃: 6/2 ≤ (p + 1)/2 := by
425
+ refine Nat.div_le_div_right ?_
426
+ linarith
427
+ norm_num at gg₃
428
+ have gg₄: 2 + (p+1)/2 ≤ p := by -- strong induction
429
+ refine Nat.le_induction ?_ ?_ p (hp5)
430
+ . norm_num
431
+ . intros n _ h₂
432
+ ring_nf
433
+ have ggg₁: (n / 2).succ ≤ (n + 1) / 2 + 1 := by
434
+ rw [← succ_eq_add_one]
435
+ refine Nat.succ_le_succ ?_
436
+ refine Nat.div_le_div_right ?_
437
+ linarith
438
+ simp
439
+ nth_rewrite 1 [← mul_one 2]
440
+ rw [Nat.two_mul 1, add_assoc]
441
+ refine Nat.add_le_add_left ?_ 1
442
+ refine le_trans ?_ h₂
443
+ rw [add_comm 2 _]
444
+ nth_rewrite 3 [← mul_one 2]
445
+ rw [Nat.two_mul 1, ← add_assoc, add_comm 1]
446
+ exact Nat.add_le_add_right ggg₁ 1
447
+ have gg₅: (2+(p+1)/2).factorial ∣ p.factorial := by
448
+ exact factorial_dvd_factorial gg₄
449
+ have gg₆: (2:ℕ).factorial * ((p+1)/2).factorial ∣ p.factorial := by
450
+ refine dvd_trans ?_ gg₅
451
+ exact (2:ℕ).factorial_mul_factorial_dvd_factorial_add ((p + 1) / 2)
452
+ have gg₇: 2 * ((p+1)/2) ∣ p.factorial := by
453
+ refine dvd_trans ?_ gg₆
454
+ simp
455
+ refine mul_dvd_mul_left 2 ?_
456
+ refine Nat.dvd_factorial (by linarith[gg₃]) (by linarith)
457
+ have gg₈: 2 * ((p+1)/2) * (p + 1) ∣ p.factorial * (p + 1) := by
458
+ refine mul_dvd_mul_right ?_ (p + 1)
459
+ exact gg₇
460
+ rw [gg₂] at gg₁
461
+ exact dvd_trans gg₈ gg₁
462
+ have g₄: 2 * ((p+1)/2) = (p + 1) := by
463
+ exact Nat.mul_div_cancel' g₂
464
+ rw [g₄] at g₃
465
+ ring_nf at *
466
+ exact g₃
467
+ have h₃: b.factorial = p ^ p - p := by exact eq_tsub_of_add_eq (h₁.symm)
468
+ rw [h₃] at h₂
469
+ exact mylemma_52 p hp hp5 h₂
470
+
471
+
472
+ lemma mylemma_6
473
+ (a b p: ℕ)
474
+ (hp: Nat.Prime p)
475
+ (h₂: p ∣ a)
476
+ (hb2p: 2 * p ≤ b) :
477
+ (p ^ 2 ∣ a ^ p - b.factorial) := by
478
+ have g₁: p^p ∣ a^p := by exact pow_dvd_pow_of_dvd h₂ p
479
+ have g₂: 2 ≤ p := by exact Prime.two_le hp
480
+ have h₃: p^2 ∣ a^p := by exact pow_dvd_of_le_of_pow_dvd g₂ g₁
481
+ have g₃: (2*p).factorial ∣ b.factorial := by exact factorial_dvd_factorial hb2p
482
+ have g₄: p.factorial * p.factorial ∣ (p+p).factorial := by
483
+ exact factorial_mul_factorial_dvd_factorial_add p p
484
+ rw [← pow_two, ← two_mul] at g₄
485
+ have g₅: p ∣ p.factorial := by exact Nat.dvd_factorial (by linarith) (by linarith)
486
+ have h₄: p ^ 2 ∣ p.factorial ^ 2 := by exact pow_dvd_pow_of_dvd g₅ 2
487
+ have g₆: p ^ 2 ∣ (2 * p).factorial := by exact dvd_trans h₄ g₄
488
+ have h₅: p^2 ∣ b.factorial := by exact dvd_trans g₆ g₃
489
+ exact dvd_sub' h₃ h₅
490
+
491
+
492
+ theorem imo_2022_p5
493
+ (a b p : ℕ)
494
+ (h₀: 0 < a ∧ 0 < b)
495
+ (hp: Nat.Prime p)
496
+ (h₁: a^p = Nat.factorial b + p) :
497
+ (a, b, p) = (2, 2, 2) ∨ (a, b, p) = (3, 4, 3) := by
498
+ by_cases hbp: b < p -- no solution
499
+ . exfalso
500
+ by_cases hab: a ≤ b
501
+ . have h₂: a ∣ b.factorial := by exact Nat.dvd_factorial h₀.1 hab
502
+ have g₃: a ∣ b.factorial + p := by
503
+ rw [← h₁]
504
+ refine dvd_pow_self a ?_
505
+ exact Nat.Prime.ne_zero hp
506
+ have h₃: a ∣ p := by exact (Nat.dvd_add_right h₂).mp g₃
507
+ have h₄: a = 1 := by
508
+ have g₄: a = 1 ∨ a = p := by
509
+ exact (Nat.dvd_prime hp).mp h₃
510
+ cases' g₄ with g₄₀ g₄₁
511
+ . exact g₄₀
512
+ . exfalso
513
+ rw [← g₄₁] at hbp
514
+ linarith[hbp,hab]
515
+ rw [h₄] at h₁
516
+ simp at h₁
517
+ have h₅: 2 ≤ p := by exact Nat.Prime.two_le hp
518
+ have g₆: 0 < b.factorial := by exact Nat.factorial_pos b
519
+ have h₇: 1+2 ≤ b.factorial + p := by exact Nat.add_le_add g₆ h₅
520
+ rw [← h₁] at h₇
521
+ linarith
522
+ . push_neg at hab
523
+ have h₂: (b+1)^p ≤ a^p := by
524
+ refine (Nat.pow_le_pow_iff_left ?_).mpr hab
525
+ exact Nat.Prime.ne_zero hp
526
+ have h₃: b^p + p*b + 1 ≤ (b+1)^p := by
527
+ ring_nf
528
+ rw [add_assoc]
529
+ exact mylemma_1 b p h₀.2 hbp
530
+ have g₄: p * 1 ≤ p * b := by
531
+ refine mul_le_mul ?_ ?_ ?_ ?_
532
+ . exact rfl.ge
533
+ . exact h₀.2
534
+ . norm_num
535
+ . exact Nat.zero_le p
536
+ have g₄: b.factorial ≤ b^b := by exact Nat.factorial_le_pow b
537
+ have g₅: b^b ≤ b^p := by
538
+ refine Nat.pow_le_pow_of_le_right h₀.2 ?_
539
+ exact le_of_lt hbp
540
+ linarith
541
+ . push_neg at hbp
542
+ have h₂: p ∣ a := by exact mylemma_3 a b p hp h₁ hbp
543
+ by_cases hb2p: b < 2*p
544
+ . have h₃: a = p := by exact mylemma_4 a b p h₀ hp h₁ hbp h₂ hb2p
545
+ rw [h₃] at h₁
546
+ by_cases hp5: p < 5
547
+ . have h₄: 2 ≤ p := by exact Prime.two_le hp
548
+ interval_cases p
549
+ . left
550
+ norm_num at h₁
551
+ have h₄: b.factorial = 2 := by linarith
552
+ have g₅: (2:ℕ).factorial = 2 := by norm_num
553
+ rw [← g₅] at h₄
554
+ have h₅: b = 2 := by
555
+ refine (Nat.factorial_inj ?_).mp h₄
556
+ linarith
557
+ rw [h₃,h₅]
558
+ . right
559
+ norm_num at h₁
560
+ rw [h₃]
561
+ have h₄: b.factorial = 24 := by linarith
562
+ have g₅: (4:ℕ).factorial = 24 := by exact rfl
563
+ rw [← g₅] at h₄
564
+ have h₅: b = 4 := by
565
+ refine (Nat.factorial_inj ?_).mp h₄
566
+ linarith
567
+ rw [h₅]
568
+ . exfalso
569
+ contradiction
570
+ . push_neg at hp5
571
+ exfalso -- lifting the exponent
572
+ exact mylemma_5 b p hp hbp h₁ hp5
573
+ . push_neg at hb2p
574
+ exfalso
575
+ have h₃: p^2 ∣ a^p - b.factorial := by exact mylemma_6 a b p hp h₂ hb2p
576
+ have g₃: b.factorial ≤ a^p := by exact le.intro (h₁.symm)
577
+ have g₄: a^p - b.factorial = p := by
578
+ rw [add_comm] at h₁
579
+ exact (Nat.sub_eq_iff_eq_add g₃).mpr h₁
580
+ have h₄: p^2 ∣ p := by
581
+ rw [g₄] at h₃
582
+ exact h₃
583
+ have gp: 0 < p := by exact Prime.pos hp
584
+ have h₅: p^2 ≤ p := by exact Nat.le_of_dvd gp h₄
585
+ have g₆: 1 < p := by exact Prime.one_lt hp
586
+ have h₆: p^1 < p^2 := by exact Nat.pow_lt_pow_succ g₆
587
+ linarith
imo_proofs/imo_2023_p4.lean ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Mathlib
2
+ import Mathlib.Analysis.SpecialFunctions.Pow.Real
3
+
4
+
5
+ set_option linter.unusedVariables.analyzeTactics true
6
+
7
+ open Real Set
8
+
9
+ lemma mylemma_1
10
+ (x a: ℕ → ℝ)
11
+ (hxp: ∀ (i : ℕ), 0 < x i)
12
+ (h₀: ∀ (n : ℕ),
13
+ 1 ≤ n ∧ n ≤ 2023 →
14
+ a n = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
15
+ * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)) :
16
+ ∀ (n : ℕ), (1 ≤ n ∧ n ≤ 2022) → a (n) < a (n + 1) := by
17
+ intros n hn
18
+ have h₂: a n = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
19
+ * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
20
+ refine h₀ n ?_
21
+ constructor
22
+ . exact hn.1
23
+ linarith
24
+ have h₃: a (n + 1) = sqrt ((Finset.sum (Finset.Ico 1 (n + 2)) fun k => x k)
25
+ * Finset.sum (Finset.Ico 1 (n + 2)) fun k => 1 / x k) := by
26
+ refine h₀ (n + 1) ?_
27
+ constructor
28
+ . linarith
29
+ linarith
30
+ rw [h₂,h₃]
31
+ refine sqrt_lt_sqrt ?_ ?_
32
+ . refine le_of_lt ?_
33
+ refine mul_pos ?_ ?_
34
+ . refine Finset.sum_pos ?_ ?_
35
+ . exact fun i _ => hxp i
36
+ . simp
37
+ linarith
38
+ . refine Finset.sum_pos ?_ ?_
39
+ intros i _
40
+ exact one_div_pos.mpr (hxp i)
41
+ . simp
42
+ linarith
43
+ have g₀: 1 ≤ n + 1 := by linarith
44
+ rw [Finset.sum_Ico_succ_top g₀ _, Finset.sum_Ico_succ_top g₀ _]
45
+ repeat rw [add_mul, mul_add]
46
+ have h₄: 0 < (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1)) +
47
+ x (n + 1) * ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) + 1 / x (n + 1)) := by
48
+ refine add_pos ?_ ?_
49
+ . refine mul_pos ?_ ?_
50
+ . refine Finset.sum_pos ?_ ?_
51
+ . exact fun i _ => hxp i
52
+ . simp
53
+ linarith
54
+ . exact one_div_pos.mpr (hxp (n + 1))
55
+ . refine mul_pos ?_ ?_
56
+ . exact hxp (n + 1)
57
+ . refine add_pos ?_ ?_
58
+ . refine Finset.sum_pos ?_ ?_
59
+ . intros i _
60
+ exact one_div_pos.mpr (hxp i)
61
+ . simp
62
+ linarith
63
+ exact one_div_pos.mpr (hxp (n + 1))
64
+ linarith
65
+
66
+
67
+ lemma mylemma_amgm
68
+ (b1 b2 b3 b4 :ℝ)
69
+ (hb1: 0 ≤ b1)
70
+ (hb2: 0 ≤ b2)
71
+ (hb3: 0 ≤ b3)
72
+ (hb4: 0 ≤ b4) :
73
+ (4 * (b1 * b2 * b3 * b4) ^ (4:ℝ)⁻¹ ≤ b1 + b2 + b3 + b4) := by
74
+ let w1 : ℝ := (4:ℝ)⁻¹
75
+ let w2 : ℝ := w1
76
+ let w3 : ℝ := w2
77
+ let w4 : ℝ := w3
78
+ rw [mul_comm]
79
+ refine mul_le_of_le_div₀ ?_ (by norm_num) ?_
80
+ . refine add_nonneg ?_ hb4
81
+ refine add_nonneg ?_ hb3
82
+ exact add_nonneg hb1 hb2
83
+ have h₀: (b1^w1 * b2^w2 * b3^w3 * b4^w4) ≤ w1 * b1 + w2 * b2 + w3 * b3 + w4 * b4 := by
84
+ refine geom_mean_le_arith_mean4_weighted (by norm_num) ?_ ?_ ?_ hb1 hb2 hb3 hb4 ?_
85
+ . norm_num
86
+ . norm_num
87
+ . norm_num
88
+ . norm_num
89
+ repeat rw [mul_rpow _]
90
+ ring_nf at *
91
+ linarith
92
+ repeat { assumption }
93
+ . exact mul_nonneg hb1 hb2
94
+ . exact hb4
95
+ . refine mul_nonneg ?_ hb3
96
+ exact mul_nonneg hb1 hb2
97
+
98
+
99
+
100
+ lemma mylemma_2
101
+ (x a: ℕ → ℝ)
102
+ (hxp: ∀ (i : ℕ), 0 < x i)
103
+ (h₀: ∀ (n : ℕ),
104
+ 1 ≤ n ∧ n ≤ 2023 →
105
+ a n = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
106
+ * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)))
107
+ (n: ℕ)
108
+ (hn: 1 ≤ n ∧ n ≤ 2021) :
109
+ (4 * a n ≤
110
+ (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1) + 1 / x (n + 2)) +
111
+ (x (n + 1) + x (n + 2)) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
112
+ repeat rw [mul_add, add_mul]
113
+ have g₁₁: 0 ≤ Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1 := by
114
+ refine le_of_lt ?_
115
+ refine Finset.sum_pos ?_ ?_
116
+ . exact fun i _ => hxp i
117
+ . simp
118
+ linarith
119
+ have g₁₂: 0 ≤ Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹ := by
120
+ refine le_of_lt ?_
121
+ refine Finset.sum_pos ?_ ?_
122
+ . intros i _
123
+ exact inv_pos.mpr (hxp i)
124
+ . simp
125
+ linarith
126
+ have h₃₂: 4 * ( ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1))) *
127
+ ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 2))) *
128
+ ((x (n + 1) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)) *
129
+ (x (n + 2) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) ) ^ (4:ℝ)⁻¹
130
+ ≤ (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1)) +
131
+ (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 2)) +
132
+ ((x (n + 1) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) +
133
+ x (n + 2) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
134
+ let b1:ℝ := (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1))
135
+ let b2:ℝ := (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 2))
136
+ let b3:ℝ := (x (n + 1) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)
137
+ let b4:ℝ := x (n + 2) * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)
138
+ have hb1: b1 = (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1)) := by
139
+ exact rfl
140
+ have hb2: b2 = (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 2)) := by
141
+ exact rfl
142
+ have hb3: b3 = (x (n + 1) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
143
+ exact rfl
144
+ have hb4: b4 = x (n + 2) * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
145
+ exact rfl
146
+ rw [← hb1, ← hb2, ← hb3, ← hb4]
147
+ have g₀: 4 * (b1 * b2 * b3 * b4) ^ (4:ℝ)⁻¹ ≤ b1 + b2 + b3 + b4 := by
148
+ have b1p: 0 ≤ b1 := by
149
+ rw [hb1]
150
+ refine mul_nonneg ?_ ?_
151
+ . ring_nf
152
+ exact g₁₁
153
+ . refine le_of_lt ?_
154
+ exact one_div_pos.mpr (hxp (n + 1))
155
+ have b2p: 0 ≤ b2 := by
156
+ rw [hb2]
157
+ refine mul_nonneg ?_ ?_
158
+ . ring_nf
159
+ exact g₁₁
160
+ . refine le_of_lt ?_
161
+ exact one_div_pos.mpr (hxp (n + 2))
162
+ have b3p: 0 ≤ b3 := by
163
+ rw [hb3]
164
+ refine mul_nonneg ?_ ?_
165
+ . exact LT.lt.le (hxp (n + 1))
166
+ . ring_nf
167
+ exact g₁₂
168
+ have b4p: 0 ≤ b4 := by
169
+ rw [hb4]
170
+ refine mul_nonneg ?_ ?_
171
+ . exact LT.lt.le (hxp (n + 2))
172
+ . ring_nf
173
+ exact g₁₂
174
+ exact mylemma_amgm b1 b2 b3 b4 b1p b2p b3p b4p
175
+ linarith
176
+ have h₃₃: 4 * a (n) = 4 * (((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 1))) *
177
+ ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) * (1 / x (n + 2))) *
178
+ ((x (n + 1) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)) *
179
+ (x (n + 2) * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) ) ^ (4:ℝ)⁻¹ := by
180
+ simp
181
+ ring_nf
182
+ have g₀: (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1) ^ 2
183
+ * x (1 + n) * (x (1 + n))⁻¹ * x (2 + n) * (x (2 + n))⁻¹ *
184
+ (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹) ^ 2
185
+ = x (1 + n) * (x (1 + n))⁻¹ * x (2 + n) * (x (2 + n))⁻¹ *
186
+ (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1) ^ 2 *
187
+ (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹) ^ 2 := by
188
+ linarith
189
+ have g₁: x (1 + n) * (x (1 + n))⁻¹ * x (2 + n) * (x (2 + n))⁻¹ = 1 := by
190
+ rw [mul_assoc]
191
+ have gg₁: x (1 + n) * (x (1 + n))⁻¹ = 1 := by
192
+ refine div_self ?_
193
+ exact ne_of_gt (hxp (1 + n))
194
+ have gg₂: x (2 + n) * (x (2 + n))⁻¹ = 1 := by
195
+ refine div_self ?_
196
+ exact ne_of_gt (hxp (2 + n))
197
+ rw [gg₁, gg₂]
198
+ norm_num
199
+ rw [g₁] at g₀
200
+ rw [g₀]
201
+ simp
202
+ repeat rw [mul_rpow]
203
+ have g₂: ((Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1) ^ (2:ℝ)) ^ (4:ℝ)⁻¹
204
+ = (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1) ^ (1/(2:ℝ)) := by
205
+ rw [← rpow_mul g₁₁ (2:ℝ) (4:ℝ)⁻¹]
206
+ norm_num
207
+ have g₃: ((Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹) ^ (2:ℝ)) ^ (4:ℝ)⁻¹
208
+ = (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹) ^ (1/(2:ℝ)) := by
209
+ rw [← rpow_mul g₁₂ (2:ℝ) (4:ℝ)⁻¹]
210
+ norm_num
211
+ -- rw [g₂, ← sqrt_eq_rpow (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1)]
212
+ -- rw [g₃, ← sqrt_eq_rpow (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹)]
213
+ have g₄: a (n) = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
214
+ * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
215
+ refine h₀ n ?_
216
+ constructor
217
+ . exact hn.1
218
+ . linarith
219
+ norm_cast at *
220
+ rw [g₂, g₃, ← mul_rpow]
221
+ rw [← sqrt_eq_rpow]
222
+ ring_nf at g₄
223
+ exact g₄
224
+ . exact g₁₁
225
+ . exact g₁₂
226
+ . exact sq_nonneg (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => x x_1)
227
+ . exact sq_nonneg (Finset.sum (Finset.Ico 1 (1 + n)) fun x_1 => (x x_1)⁻¹)
228
+ exact Eq.trans_le h₃₃ h₃₂
229
+
230
+
231
+ lemma mylemma_3
232
+ (x a: ℕ → ℝ)
233
+ (hxp: ∀ (i : ℕ), 0 < x i)
234
+ (hx: ∀ (i j : ℕ), i ≠ j → x i ≠ x j)
235
+ (h₀: ∀ (n : ℕ),
236
+ 1 ≤ n ∧ n ≤ 2023 →
237
+ a n = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
238
+ * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)))
239
+ (h₀₁: ∀ (n : ℕ), 1 ≤ n ∧ n ≤ 2023 → 0 < a n) :
240
+ (∀ (n : ℕ), 1 ≤ n ∧ n ≤ 2021 → a n + 2 < a (n + 2)) := by
241
+ intros n hn
242
+ have g₀: 0 ≤ a n + 2 := by
243
+ refine le_of_lt ?_
244
+ refine add_pos ?_ (by norm_num)
245
+ refine h₀₁ n ?_
246
+ constructor
247
+ . exact hn.1
248
+ . linarith
249
+ have g₁: 0 ≤ a (n + 2) := by
250
+ refine le_of_lt ?_
251
+ refine h₀₁ (n + 2) ?_
252
+ constructor
253
+ . linarith
254
+ . linarith
255
+ rw [← sqrt_sq g₀, ← sqrt_sq g₁]
256
+ have g₂: 0 ≤ (a n + 2) ^ 2 := by exact sq_nonneg (a n + 2)
257
+ -- simp
258
+ refine Real.sqrt_lt_sqrt g₂ ?_
259
+ have g₃: 0 ≤ ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
260
+ * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)) := by
261
+ refine le_of_lt ?_
262
+ refine mul_pos ?_ ?_
263
+ . refine Finset.sum_pos ?_ ?_
264
+ . exact fun i _ => hxp i
265
+ . simp
266
+ linarith
267
+ . refine Finset.sum_pos ?_ ?_
268
+ . intros i _
269
+ exact one_div_pos.mpr (hxp i)
270
+ . simp
271
+ linarith
272
+ have gn₀: a (n) ^ 2 = ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
273
+ * (Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)) := by
274
+ rw [← sq_sqrt g₃]
275
+ have g₄: 0 ≤ a n := by
276
+ refine le_of_lt ?_
277
+ refine h₀₁ n ?_
278
+ constructor
279
+ . exact hn.1
280
+ . linarith
281
+ refine (sq_eq_sq₀ g₄ ?_).mpr ?_
282
+ . exact
283
+ sqrt_nonneg
284
+ ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k) *
285
+ Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k)
286
+ . refine h₀ (n) ?_
287
+ constructor
288
+ . exact hn.1
289
+ . linarith
290
+ have gn₁: a (n + 2) = sqrt ((Finset.sum (Finset.Ico 1 (n + 2 + 1)) fun k => x k)
291
+ * Finset.sum (Finset.Ico 1 (n + 2 + 1)) fun k => 1 / x k) := by
292
+ refine h₀ (n + 2) ?_
293
+ constructor
294
+ . linarith
295
+ . linarith
296
+ rw [add_sq, gn₁, sq_sqrt]
297
+ . have ga₀: 1 ≤ n + 2 := by linarith
298
+ rw [Finset.sum_Ico_succ_top ga₀ _, Finset.sum_Ico_succ_top ga₀ _]
299
+ have ga₁: 1 ≤ n + 1 := by linarith
300
+ rw [Finset.sum_Ico_succ_top ga₁ _, Finset.sum_Ico_succ_top ga₁ _]
301
+ rw [add_assoc, add_assoc, add_assoc]
302
+ rw [add_mul, mul_add]
303
+ rw [← gn₀]
304
+ repeat rw [add_assoc]
305
+ refine add_lt_add_left ?_ (a (n) ^ 2)
306
+ rw [mul_add (x (n + 1) + x (n + 2))]
307
+ have h₂: 4 < (x (n + 1) + x (n + 2)) * (1 / x (n + 1) + 1 / x (n + 2)) := by
308
+ repeat rw [add_mul, mul_add, mul_add]
309
+ repeat rw [mul_div_left_comm _ 1 _, one_mul]
310
+ repeat rw [div_self ?_]
311
+ . have hc₂: x (n + 1) * x (n + 2) * (x (n + 1) / x (n + 2))
312
+ = x (n + 1) * x (n + 1) := by
313
+ rw [mul_assoc, ← mul_div_assoc, mul_div_right_comm, div_self ?_]
314
+ simp
315
+ exact ne_of_gt (hxp (n + 2))
316
+ have hc₃: x (n + 1) * x (n + 2) * (x (n + 2) / x (n + 1))
317
+ = x (n + 2) * x (n + 2) := by
318
+ rw [mul_comm (x (n + 1)) (x (n + 2)), mul_assoc, ← mul_div_assoc, mul_div_right_comm, div_self ?_]
319
+ simp
320
+ exact ne_of_gt (hxp (n + 1))
321
+ have h₂₀: 0 < x (n + 1) * x (n + 2) := by
322
+ refine mul_pos ?_ ?_
323
+ . exact hxp (n + 1)
324
+ . exact hxp (n + 2)
325
+ have h₂₁: 2 < x (n + 1) / x (n + 2) + x (n + 2) / x (n + 1) := by
326
+ refine lt_of_mul_lt_mul_left ?_ (le_of_lt h₂₀)
327
+ rw [mul_add, hc₂, hc₃, ← sq, ← sq]
328
+ refine lt_of_sub_pos ?_
329
+ have gh₂₁: x (n + 1) ^ 2 + x (n + 2) ^ 2 - x (n + 1) * x (n + 2) * 2
330
+ = (x (n + 1) - x (n + 2)) ^ 2 := by
331
+ rw [sub_sq]
332
+ linarith
333
+ rw [gh₂₁]
334
+ refine (sq_pos_iff).mpr ?_
335
+ refine sub_ne_zero.mpr ?_
336
+ exact hx (n+1) (n+2) (by linarith)
337
+ linarith
338
+ . exact ne_of_gt (hxp (n + 2))
339
+ . exact ne_of_gt (hxp (n + 1))
340
+ clear gn₀ gn₁ g₀ g₁ g₂ g₃ ga₀ ga₁
341
+ have h₃: 4 * a (n) ≤ (Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
342
+ * (1 / x (n + 1) + 1 / x (n + 2)) +
343
+ ((x (n + 1) + x (n + 2))
344
+ * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
345
+ exact mylemma_2 (fun k => x k) a hxp h₀ n hn
346
+ linarith
347
+ . refine mul_nonneg ?_ ?_
348
+ . refine Finset.sum_nonneg ?_
349
+ intros i _
350
+ exact LT.lt.le (hxp i)
351
+ . refine Finset.sum_nonneg ?_
352
+ intros i _
353
+ simp
354
+ exact LT.lt.le (hxp i)
355
+
356
+
357
+ theorem imo_2023_p4
358
+ (x : ℕ → ℝ)
359
+ (a : ℕ → ℝ)
360
+ (hxp: ∀ (i: ℕ), (0 < x i) )
361
+ (hx: ∀ (i j: ℕ), (i ≠ j) → (x i ≠ x j) )
362
+ (h₀: ∀ (n:ℕ), (1 ≤ n ∧ n ≤ 2023) →
363
+ a n = Real.sqrt ( (Finset.sum (Finset.Ico 1 (n + 1)) fun (k : ℕ) => (x k))
364
+ * (Finset.sum (Finset.Ico 1 (n + 1)) fun (k : ℕ) => 1 / (x k)) ) )
365
+ (h₁: ∀ (n:ℕ), (1 ≤ n ∧ n ≤ 2023) → ∃ (kz:ℤ), (a n = ↑kz )) :
366
+ (3034 ≤ a 2023) := by
367
+ have ha1: a 1 = 1 := by
368
+ have g₀: sqrt ((Finset.sum (Finset.Ico 1 (1 + 1)) fun k => x k)
369
+ * Finset.sum (Finset.Ico 1 (1 + 1)) fun k => 1 / x k) = 1 := by
370
+ norm_num
371
+ refine div_self ?_
372
+ exact ne_of_gt (hxp 1)
373
+ rw [← g₀]
374
+ exact h₀ (1) (by norm_num)
375
+ have h₀₁: ∀ (n : ℕ), (1 ≤ n ∧ n ≤ 2023) → 0 < a n := by
376
+ intros n hn
377
+ have ha: a n = sqrt ((Finset.sum (Finset.Ico 1 (n + 1)) fun k => x k)
378
+ * Finset.sum (Finset.Ico 1 (n + 1)) fun k => 1 / x k) := by
379
+ exact h₀ (n) (hn)
380
+ rw [ha]
381
+ refine Real.sqrt_pos.mpr ?_
382
+ refine mul_pos ?_ ?_
383
+ . refine Finset.sum_pos ?_ ?_
384
+ . intros i _
385
+ exact hxp i
386
+ simp
387
+ linarith
388
+ . refine Finset.sum_pos ?_ ?_
389
+ . intros i _
390
+ exact one_div_pos.mpr (hxp i)
391
+ simp
392
+ linarith
393
+ have h₁₁: ∀ (n : ℕ), (1 ≤ n ∧ n ≤ 2023) → ∃ (kn:ℕ), a n = ↑kn := by
394
+ intros n hn
395
+ have g₁₁: 0 < a n := by
396
+ exact h₀₁ n hn
397
+ let ⟨p, gp⟩ := h₁ n hn
398
+ let q:ℕ := Int.toNat p
399
+ have g₁₂: ↑q = p := by
400
+ refine Int.toNat_of_nonneg ?_
401
+ rw [gp] at g₁₁
402
+ norm_cast at g₁₁
403
+ exact Int.le_of_lt g₁₁
404
+ use q
405
+ rw [gp]
406
+ norm_cast
407
+ exact id g₁₂.symm
408
+ have h₂₁: ∀ (n:ℕ), (1 ≤ n ∧ n ≤ 2021) → a n + 2 < a (n+2) := by
409
+ exact fun n a_1 => mylemma_3 (fun i => x i) a hxp hx h₀ h₀₁ n a_1
410
+ have h₂: ∀ (n:ℕ), (1 ≤ n ∧ n ≤ 2021) → a n + 3 ≤ a (n+2) := by
411
+ intros n hn
412
+ have g₀: a n + 2 < a (n + 2) := by exact h₂₁ n hn
413
+ have g₀₁: ∃ (p:ℕ), a n = ↑p := by
414
+ apply h₁₁
415
+ constructor
416
+ . linarith
417
+ . linarith
418
+ have g₀₂: ∃ (q:ℕ), a (n + 2) = ↑q := by
419
+ apply h₁₁
420
+ constructor
421
+ . linarith
422
+ . linarith
423
+ let ⟨p, _⟩ := g₀₁
424
+ let ⟨q, _⟩ := g₀₂
425
+ have g₁: p + 2 < q := by
426
+ suffices g₁₁: ↑p + (2:ℝ) < ↑q
427
+ . norm_cast at g₁₁
428
+ . linarith
429
+ have g₂: ↑p + (3:ℝ) ≤ ↑q := by norm_cast
430
+ linarith
431
+ have h₃: ∀ (n:ℕ), (0 ≤ n ∧ n ≤ 1010) → a 1 + 3 * (↑(n) + 1) ≤ a (3 + 2 * n) := by
432
+ intros n hn
433
+ induction' n with d hd
434
+ · simp
435
+ exact h₂ (1) (by norm_num)
436
+ · rw [mul_add]
437
+ simp
438
+ have g₀: a (3 + 2 * d) + 3 ≤ a (3 + 2 * (d + 1)) := by
439
+ refine h₂ (3 + 2 * d) ?_
440
+ constructor
441
+ . linarith
442
+ . linarith
443
+ have g₁: a 1 + 3 * (↑d + 1) + 3 ≤ a (3 + 2 * d) + 3 := by
444
+ refine add_le_add_right ?_ (3)
445
+ apply hd
446
+ constructor
447
+ . linarith
448
+ . linarith
449
+ refine le_trans (by linarith[g₁]) g₀
450
+ rw [ha1] at h₃
451
+ have h₄: (3034:ℝ) = 1 + 3 * (↑1010 + 1) := by norm_num
452
+ rw [h₄]
453
+ exact h₃ (1010) (by norm_num)
imo_proofs/lake-manifest.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"version": "1.1.0",
2
+ "packagesDir": ".lake/packages",
3
+ "packages":
4
+ [{"url": "https://github.com/leanprover-community/mathlib4",
5
+ "type": "git",
6
+ "subDir": null,
7
+ "scope": "leanprover-community",
8
+ "rev": "d066138f11f7fdf68dcda20d1ed2d296e9d992d7",
9
+ "name": "mathlib",
10
+ "manifestFile": "lake-manifest.json",
11
+ "inputRev": "master",
12
+ "inherited": false,
13
+ "configFile": "lakefile.lean"},
14
+ {"url": "https://github.com/leanprover-community/plausible",
15
+ "type": "git",
16
+ "subDir": null,
17
+ "scope": "leanprover-community",
18
+ "rev": "59a8514bb0ee5bae2689d8be717b5272c9b3dc1c",
19
+ "name": "plausible",
20
+ "manifestFile": "lake-manifest.json",
21
+ "inputRev": "main",
22
+ "inherited": true,
23
+ "configFile": "lakefile.toml"},
24
+ {"url": "https://github.com/leanprover-community/LeanSearchClient",
25
+ "type": "git",
26
+ "subDir": null,
27
+ "scope": "leanprover-community",
28
+ "rev": "0c169a0d55fef3763cfb3099eafd7b884ec7e41d",
29
+ "name": "LeanSearchClient",
30
+ "manifestFile": "lake-manifest.json",
31
+ "inputRev": "main",
32
+ "inherited": true,
33
+ "configFile": "lakefile.toml"},
34
+ {"url": "https://github.com/leanprover-community/import-graph",
35
+ "type": "git",
36
+ "subDir": null,
37
+ "scope": "leanprover-community",
38
+ "rev": "461b96f5527089718cb23d3f1fd2960a5d0ff516",
39
+ "name": "importGraph",
40
+ "manifestFile": "lake-manifest.json",
41
+ "inputRev": "main",
42
+ "inherited": true,
43
+ "configFile": "lakefile.toml"},
44
+ {"url": "https://github.com/leanprover-community/ProofWidgets4",
45
+ "type": "git",
46
+ "subDir": null,
47
+ "scope": "leanprover-community",
48
+ "rev": "8fff3f074da9237cd4e179fd6dd89be6c4022d41",
49
+ "name": "proofwidgets",
50
+ "manifestFile": "lake-manifest.json",
51
+ "inputRev": "v0.0.52-pre",
52
+ "inherited": true,
53
+ "configFile": "lakefile.lean"},
54
+ {"url": "https://github.com/leanprover-community/aesop",
55
+ "type": "git",
56
+ "subDir": null,
57
+ "scope": "leanprover-community",
58
+ "rev": "ba9a63be53f16b3b6e4043641c6bad4883e650b4",
59
+ "name": "aesop",
60
+ "manifestFile": "lake-manifest.json",
61
+ "inputRev": "master",
62
+ "inherited": true,
63
+ "configFile": "lakefile.toml"},
64
+ {"url": "https://github.com/leanprover-community/quote4",
65
+ "type": "git",
66
+ "subDir": null,
67
+ "scope": "leanprover-community",
68
+ "rev": "7b3b0c8327b3c0214ac49ca6d6922edbb81ab8c9",
69
+ "name": "Qq",
70
+ "manifestFile": "lake-manifest.json",
71
+ "inputRev": "master",
72
+ "inherited": true,
73
+ "configFile": "lakefile.toml"},
74
+ {"url": "https://github.com/leanprover-community/batteries",
75
+ "type": "git",
76
+ "subDir": null,
77
+ "scope": "leanprover-community",
78
+ "rev": "b18855cb0f9a19bd4d7e21f3e5525272e377f431",
79
+ "name": "batteries",
80
+ "manifestFile": "lake-manifest.json",
81
+ "inputRev": "main",
82
+ "inherited": true,
83
+ "configFile": "lakefile.toml"},
84
+ {"url": "https://github.com/leanprover/lean4-cli",
85
+ "type": "git",
86
+ "subDir": null,
87
+ "scope": "leanprover",
88
+ "rev": "a2eb24a3dbf681f2b655f82ba5ee5b139d4a5abc",
89
+ "name": "Cli",
90
+ "manifestFile": "lake-manifest.json",
91
+ "inputRev": "main",
92
+ "inherited": true,
93
+ "configFile": "lakefile.toml"}],
94
+ "name": "imo_steps",
95
+ "lakeDir": ".lake"}
imo_proofs/lakefile.toml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name = "imo_steps"
2
+ version = "0.1.0"
3
+ keywords = ["math"]
4
+ defaultTargets = ["ImoSteps"]
5
+
6
+ [leanOptions]
7
+ pp.unicode.fun = true # pretty-prints `fun a ↦ b`
8
+ autoImplicit = false
9
+
10
+ [[require]]
11
+ name = "mathlib"
12
+ scope = "leanprover-community"
13
+ rev = "v4.17.0"
14
+
15
+ [[lean_lib]]
16
+ name = "ImoSteps"
imo_proofs/lean-toolchain ADDED
@@ -0,0 +1 @@
 
 
1
+ leanprover/lean4:v4.17.0