|
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 |
|
|