File size: 11,968 Bytes
1c3ffd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import Mathlib
set_option linter.unusedVariables.analyzeTactics true

open Nat Real


lemma mylemma_xy_le_y
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  -- (g : x ^ y ^ 2 = (x ^ y) ^ y)
  (hxy : x ≀ y)
  (h₁ : (x ^ y) ^ y = y ^ x) :
  x ^ y ≀ y := by
  by_contra hc
  push_neg at hc
  have hβ‚‚: y^x ≀ y^y := by
    { exact Nat.pow_le_pow_of_le_right hβ‚€.2 hxy }
  have h₃: y^y < (x^y)^y := by
    refine Nat.pow_lt_pow_left hc ?_
    refine Nat.pos_iff_ne_zero.mp hβ‚€.2
  rw [h₁] at h₃
  linarith [hβ‚‚, h₃]


lemma four_times_k_less_than_two_pow_k
  (k : β„•)
  (hk : 5 ≀ k) :
  4 * k < 2 ^ k := by
  -- Proceed by induction on k
  induction' k using Nat.case_strong_induction_on with n ih
  -- Base case: k = 0 is not possible since 5 ≀ k
  -- so we start directly with k = 5 as the base case
  . norm_num
  by_cases hβ‚€ : n < 5
  . have hn: n = 4 := by linarith
    rw [hn]
    norm_num
  . push_neg at hβ‚€
    have ih₁ : 4 * n < 2 ^ n := ih n (le_refl n) hβ‚€
    rw [mul_add, pow_add, mul_one, pow_one, mul_two]
    refine Nat.add_lt_add ih₁ ?_
    refine lt_trans ?_ ih₁
    refine (Nat.lt_mul_iff_one_lt_right (by norm_num)).mpr ?_
    refine Nat.lt_of_lt_of_le ?_ hβ‚€
    norm_num


lemma mylemma_case_xley
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x^(y^2) = y^x)
  (g₁ : x^(y^2) = (x^y)^y)
  (hxy : x ≀ y) :
  (x, y) = (1, 1) ∨ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
  rw [g₁] at h₁
  have g2: x^y ≀ y := by
    exact mylemma_xy_le_y x y hβ‚€ hxy h₁
  have g3: x = 1 := by
    by_contra hc
    have g3: 2 ≀ x := by
      by_contra gc
      push_neg at gc
      interval_cases x
      . linarith
      . omega
    have g4: 2^y ≀ x^y := by { exact Nat.pow_le_pow_of_le_left g3 y }
    have g5: y < 2^y := by exact Nat.lt_two_pow_self
    linarith
  rw [g3] at h₁
  simp at h₁
  left
  norm_num
  exact { left := g3, right := id h₁.symm }


lemma mylemma_exp_log
  (x: β„•)
  (hβ‚€: 0 < x):
  (↑x = Real.exp (Real.log ↑x)):= by
  have hx_pos : 0 < (↑x : ℝ) := by exact Nat.cast_pos.mpr hβ‚€
  symm
  exact Real.exp_log hx_pos



lemma mylemma_y2_lt_x
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x ^ y ^ 2 = y ^ x)
  (hxy : y < x) :
  y ^ 2 < x := by
  by_cases hy: 1 < y
  . have hx: 2 ≀ x := by linarith
    have hβ‚‚: y ^ x < x ^ x := by
      refine Nat.pow_lt_pow_left hxy ?_
      exact Nat.ne_of_lt' hβ‚€.1
    rw [← h₁] at hβ‚‚
    exact (Nat.pow_lt_pow_iff_right hx).mp hβ‚‚
  . push_neg at hy
    interval_cases y
    . simp
      exact hβ‚€.1
    . simp at *
      assumption



lemma mylemma_5
  (x y: β„•)
  (hβ‚€: 0 < x ∧ 0 < y)
  (h₁: x ^ y ^ 2 = y ^ x) :
  (↑x / ↑y^2) ^ y ^ 2 = (↑y:ℝ)^ ((↑x:ℝ) - 2 * ↑y ^ 2) := by
  have g₁: (↑x:ℝ) ^ (↑y:ℝ) ^ 2 = (↑y:ℝ) ^ (↑x:ℝ) := by
    norm_cast
  have gβ‚‚: 0 < ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
    norm_cast
    exact pow_pos hβ‚€.2 _
  have g₃: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
        = ((↑y:ℝ) ^ (↑x:ℝ)) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2)) := by
    refine (div_left_inj' ?_).mpr g₁
    norm_cast
    refine pow_ne_zero _ ?_
    linarith [hβ‚€.2]
  have gy: 0 < (↑y:ℝ) := by
    norm_cast
    exact hβ‚€.2
  rw [← Real.rpow_sub gy (↑x) (2 * ↑y ^ 2)] at g₃
  have gβ‚„: ((↑x:ℝ) ^ (↑y:ℝ) ^ 2) / ((↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2))
        = (↑x / ↑y^2) ^ y ^ 2 := by
    have gβ‚…: (↑y:ℝ) ^ (2 * (↑y:ℝ) ^ 2) = ((↑y:ℝ) ^ 2) ^ ((↑y:ℝ) ^ 2) := by
      norm_cast
      refine pow_mul y 2 (y^2)
    rw [gβ‚…]
    symm
    norm_cast
    have g₆: ((↑x:ℝ) / ↑y ^ 2) ^ y ^ 2 = ↑x ^ y ^ 2 / (↑y ^ 2) ^ y ^ 2 := by
      refine div_pow (↑x:ℝ) ((↑y:ℝ) ^ 2) (y^2)
    norm_cast at *
  rw [gβ‚„] at g₃
  norm_cast at *




lemma mylemma_2y2_lt_x
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x ^ y ^ 2 = y ^ x)
  (hxy : y < x) :
  2 * y ^ 2 < x := by
  by_cases hy1: y = 1
  . rw [hy1]
    norm_num
    by_contra hc
    push_neg at hc
    interval_cases x
    . linarith
    . linarith
    . rw [hy1] at h₁
      simp at h₁
  . have hy: 1 < y := by
      contrapose! hy1
      linarith
    clear hy1
    have hβ‚‚: (↑y:ℝ) ^ 2 < ↑x := by
      norm_cast
      exact mylemma_y2_lt_x x y hβ‚€ h₁ hxy
    have h₃: 1 < ↑x / (↑y:ℝ) ^ 2 := by
      refine (one_lt_div ?_).mpr hβ‚‚
      norm_cast
      exact pow_pos hβ‚€.2 2  -- rw ← one_mul ((↑y:ℝ)^2) at hβ‚‚, refine lt_div_iff_mul_lt.mpr hβ‚‚, },
    have hβ‚„: 1 < (↑x / (↑y:ℝ)^2)^(y^2) := by
      refine one_lt_powβ‚€ h₃ ?_
      refine Nat.ne_of_gt ?_
      refine sq_pos_of_pos ?_
      exact lt_of_succ_lt hy
    have hβ‚…: (↑x/ (↑y:ℝ)^2)^(y^2) = (↑y:ℝ)^((↑x:ℝ) - 2*(↑y:ℝ)^2) := by
      exact mylemma_5 x y hβ‚€ h₁
    rw [hβ‚…] at hβ‚„
    have h₆: 0 < (↑x:ℝ) - 2 * (↑y:ℝ) ^ 2 := by
      by_contra hc
      push_neg at hc
      cases' lt_or_eq_of_le hc with hlt heq
      . have gy: 1 < (↑y:ℝ) := by
          norm_cast
        have glt: (↑x:ℝ) - 2*(↑y:ℝ)^2 < (↑0:ℝ) := by
          norm_cast at *
        have g₁: (↑y:ℝ) ^ ((↑x:ℝ) - 2*(↑y:ℝ)^2) < (↑y:ℝ) ^ (↑0:ℝ) := by
          exact Real.rpow_lt_rpow_of_exponent_lt gy glt
        simp at g₁
        linarith[ hβ‚„,g₁]
      . rw [heq] at hβ‚„
        simp at hβ‚„
    simp at h₆
    norm_cast at h₆


lemma mylemma_castdvd
  (x y: β„•)
  (hβ‚€: 0 < x ∧ 0 < y)
  (h₁ : x ^ y ^ 2 = y ^ x)
  (hyx: y < x) :
  (y^2 ∣ x) := by
  have hβ‚‚: (x ^ y ^ 2).factorization = (y^x).factorization := by
    exact congr_arg Nat.factorization h₁
  simp at hβ‚‚
  symm at hβ‚‚
  have hxy1: 2 * y^2 ≀ x := by exact le_of_lt (mylemma_2y2_lt_x x y hβ‚€ h₁ hyx)
  have hxy: 2 β€’ y^2 ≀ x := by exact hxy1
  have h₃: 2 β€’ y^2 β€’ x.factorization ≀ x β€’ x.factorization := by
    rw [← smul_assoc]
    refine nsmul_le_nsmul_left ?_ hxy
    norm_num
  rw [← hβ‚‚] at h₃
  have hβ‚„: 2 β€’ x β€’ y.factorization = x β€’ (2 β€’ y.factorization) := by
    rw [← smul_assoc, ← smul_assoc]
    have gβ‚„: 2 β€’ x = x β€’ 2 := by
      simp
      exact mul_comm 2 x
    rw [gβ‚„]
  rw [hβ‚„] at h₃
  rw [← Nat.factorization_pow] at h₃
  rw [← Nat.factorization_pow] at h₃
  rw [← Nat.factorization_pow] at h₃
  have hβ‚…: (y ^ 2) ^ x ∣ x^x := by
    have g₁: (y ^ 2) ^ x β‰  0 := by
      refine pow_ne_zero x ?_
      refine pow_ne_zero 2 ?_
      linarith
    have gβ‚‚: x ^ x β‰  0 := by
      refine pow_ne_zero x ?_
      linarith
    exact (Nat.factorization_le_iff_dvd g₁ gβ‚‚).mp h₃
  refine (Nat.pow_dvd_pow_iff ?_).mp hβ‚…
  exact Nat.ne_of_gt hβ‚€.1




lemma mylemma_xsuby_eq_2xy2_help
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x ^ y ^ 2 = y ^ x)
  (hβ‚‚ : Real.log (↑x:ℝ)  = Real.log ↑y * ↑x / (↑(y ^ 2:β„• ):ℝ) )
  (hxy : y < x) :
  x = y ^ (x / y ^ 2) := by
  have h_exp : Real.exp (Real.log ↑x)
            = Real.exp (Real.log ↑y * (↑x:ℝ)  / ((↑y:ℝ)) ^ 2) := by
    rw [hβ‚‚]
    norm_cast
  rw [← mylemma_exp_log x hβ‚€.1] at h_exp
  rw [← mul_div] at h_exp
  rw [Real.exp_mul] at h_exp
  rw [← mylemma_exp_log y hβ‚€.2] at h_exp
  have h₃: (↑x:ℝ) / ((↑y:ℝ)^2) = (↑(x / y^2:β„•):ℝ) := by
    norm_cast
    symm
    have gβ‚‚: y^2 ∣ x := by
      exact mylemma_castdvd x y hβ‚€ h₁ hxy
    have h₃: (↑(y^(2:β„•)):ℝ) β‰  0 := by
      norm_cast
      exact pow_ne_zero 2 ( by linarith)
    exact Nat.cast_div gβ‚‚ h₃
  have hβ‚„ : (↑(y ^ (x / y ^ (2:β„•))):ℝ) = (↑y:ℝ)^((↑x:ℝ) / ((↑y:ℝ)^2)) := by
    rw [Nat.cast_pow, h₃]
    norm_cast
  rw [←hβ‚„] at h_exp
  exact Nat.cast_inj.mp h_exp


theorem mylemma_xsuby_eq_2xy2
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x ^ y ^ 2 = y ^ x)
  (hxy : y < x) :
  x = y ^ (x / y ^ 2) := by
  -- sketch: y^2 * log x = x * log y
  have h₃: Real.log (x^(y^2)) = Real.log (y^x) := by
    norm_cast
    rw [h₁]
  have hβ‚„: (↑(y ^ (2:β„•)):ℝ)  * Real.log x = ↑x * Real.log y := by
    have h41: Real.log (y^x) = (↑x:ℝ) * Real.log (y) := by
      exact Real.log_pow y x
    have h42: Real.log (x^(y^2)) = (↑(y ^ (2:β„•)):ℝ) * Real.log x := by
      exact Real.log_pow x (y^2)
    rw [h41,h42] at h₃
    exact h₃
  ring_nf at hβ‚„
  have hβ‚…: Real.log ↑x = Real.log ↑y * ↑x / (↑(y ^ (2:β„•)):ℝ) := by
    by_contra hc
    rw [mul_comm (Real.log ↑y) (↑x)] at hc
    rw [← hβ‚„, mul_comm, ← mul_div] at hc
    rw [div_self, mul_one] at hc
    . apply hc
      norm_cast
    . norm_cast
      push_neg
      refine pow_ne_zero 2 ?_
      exact Nat.ne_of_gt hβ‚€.2
  have h₆: x = y ^ (x / y ^ 2) := by
    exact mylemma_xsuby_eq_2xy2_help x y hβ‚€ h₁ hβ‚… hxy
  exact h₆



theorem imo_1997_p5
  (x y : β„•)
  (hβ‚€ : 0 < x ∧ 0 < y)
  (h₁ : x^(y^2) = y^x) :
  (x, y) = (1, 1) ∨ (x, y) = (16, 2) ∨ (x, y) = (27, 3) := by
  have g₁: x^(y^2) = (x^y)^y := by
    rw [Nat.pow_two]
    exact Nat.pow_mul x y y
  by_cases hxy: x ≀ y
  . exact mylemma_case_xley x y hβ‚€ h₁ g₁ hxy
  . push_neg at hxy
    right
    have h₃: x = y ^ (x / y ^ 2) := by
      exact mylemma_xsuby_eq_2xy2 x y hβ‚€ h₁ hxy
    let k:β„•  := x / y^2 -- { admit },
    have hk_def: k = x / y^2 := by exact rfl
    by_cases hk: k < 2
    . rw [← hk_def] at h₃
      interval_cases k
      . exfalso
        simp at h₃
        linarith
      . exfalso
        simp at *
        linarith [hxy,h₃] --simp at h₃, rw h₃ at hxy, linarith[hxy], },
    . push_neg at hk
      rw [← hk_def] at h₃
      have hβ‚…: k = y^(k-2) := by
        rw [h₃] at hk_def
        nth_rewrite 1 [hk_def]
        exact Nat.pow_div hk hβ‚€.2
      by_cases hk5: k < 5
      . interval_cases k
        . exfalso
          simp at hβ‚…
        . right
          norm_num
          simp at hβ‚…
          symm at hβ‚…
          rw [hβ‚…] at h₃
          norm_num at h₃
          exact { left := h₃, right := hβ‚… }
        . simp at hβ‚…
          symm at hβ‚…
          have gβ‚‚: y^4 = y^2 * y^2 := by ring_nf
          rw [gβ‚‚, hβ‚…] at h₃
          norm_num at h₃
          left
          norm_num
          constructor
          . exact h₃
          . have h₆ : y ^ 2 = 2 ^ 2 := by
              norm_num
              exact hβ‚…
            have h₇: 0 ≀ y := by
              linarith
            exact (sq_eq_sqβ‚€ h₇ (by linarith)).mp (h₆)
      push_neg at hk5
      by_cases hy: 2 ≀ y
      . have h₅₁: k < y^(k-2) := by
          have h₆: 2^(k-2) ≀ y^(k-2) := by
            have hk1: 3 ≀ k - 2 := by exact Nat.sub_le_sub_right hk5 2
            exact (Nat.pow_le_pow_iff_left (by linarith)).mpr hy
          have h₇: 4*k < 2^k := by
            exact four_times_k_less_than_two_pow_k k hk5
          have h₇: k < 2^(k-2) := by
            have hβ‚ˆ : k < 2 ^ k / 4 := by
              have h81: 4 ∣ 2^k := by
                have h82: 2^k = 4*2^(k-2) := by
                  have h83: k = 2 + (k -2) := by
                    ring_nf
                    exact (add_sub_of_le hk).symm
                  nth_rewrite 1 [h83]
                  rw [pow_add]
                  norm_num
                rw [h82]
                exact Nat.dvd_mul_right 4 (2^(k-2))
              exact (Nat.lt_div_iff_mul_lt' h81 k).mpr h₇
            have h₉: 2 ^ k / 4 = 2 ^ (k-2) := by
              have g2: k = k - 2 + 2 := by
                exact (Nat.sub_eq_iff_eq_add hk).mp rfl
              have h1: 2^k = 2^(k - 2 + 2) := by
                exact congrArg (HPow.hPow 2) g2
              have h2: 2 ^ (k - 2 + 2) = 2 ^ (k - 2) * 2 ^ 2 := by rw [pow_add]
              rw [h1, h2]
              ring_nf
              simp
            linarith
          linarith
        exfalso
        linarith
      . push_neg at hy
        interval_cases y
        . linarith
        . simp at hβ‚…
          simp at h₃
          linarith