Dataset Viewer
Auto-converted to Parquet Duplicate
id
string
source
string
formal_statement
string
header
string
lean4_code
string
has_proof
bool
proof_body
string
natural_language
null
lean_version
string
split
string
tags
list
category
null
metadata
string
verification
string
v4210_is_valid
bool
v4210_compiles
bool
v4210_has_sorry
bool
v4210_latency_s
float64
compfiles_Bulgaria1998P1
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 1 We will be considering colorings in 2 colors of n (distinct) points A₁, A₂, ..., Aₙ. Call such a coloring "good" if there exist three points Aᵢ, Aⱼ, A₂ⱼ₋ᵢ, 1 ≤ i < 2j - i ≤ n, which are colored the same color. Find the least natural number n (n ≥ 3) such that all colorings of n points are good. -/ namespace Bulgaria1998P1 abbrev coloring_is_good {m : ℕ} (color : Set.Icc 1 m → Fin 2) : Prop := ∃ i j : Set.Icc 1 m, i < j ∧ ∃ h3 : 2 * j.val - i ∈ Set.Icc 1 m, color i = color j ∧ color i = color ⟨2 * j - i, h3⟩ abbrev all_colorings_are_good (m : ℕ) : Prop := 3 ≤ m ∧ ∀ color : Set.Icc 1 m → Fin 2, coloring_is_good color lemma lemma1 {m n : ℕ} (hmn : m ≤ n) (hm : all_colorings_are_good m) : all_colorings_are_good n := by constructor · exact hm.1.trans hmn · intro c let c' : Set.Icc 1 m → Fin 2 := fun x ↦ c ⟨x.val, by rw [Set.mem_Icc]; exact ⟨x.prop.1, x.prop.2.trans hmn⟩⟩ obtain ⟨⟨i, hi1, hi2⟩, ⟨j, hj1, hj2⟩, hij1, hij2, hc1, hc2⟩ := hm.2 c' use ⟨i, hi1, hi2.trans hmn⟩ use ⟨j, hj1, hj2.trans hmn⟩ simp only [Subtype.mk_lt_mk, Set.mem_Icc, tsub_le_iff_right, exists_and_left] simp only [Subtype.mk_lt_mk] at hij1 refine ⟨hij1, ?_⟩ simp only [Set.mem_Icc, tsub_le_iff_right] at hij2 simp only [c'] at hc1 refine ⟨hc1, ?_⟩ have hij2' : 1 ≤ 2 * j - i ∧ 2 * j ≤ n + i := ⟨hij2.1, le_add_of_le_add_right hij2.2 hmn⟩ use hij2' def coloring_of_eight {n : ℕ} : Set.Icc 1 n → Fin 2 | ⟨1, _⟩ => 0 | ⟨2, _⟩ => 1 | ⟨3, _⟩ => 0 | ⟨4, _⟩ => 1 | ⟨5, _⟩ => 1 | ⟨6, _⟩ => 0 | ⟨7, _⟩ => 1 | ⟨8, _⟩ => 0 | _ => 0 -- unreachable lemma lemma2 : ∃ f : Set.Icc 1 8 → Fin 2, ¬coloring_is_good f := by use coloring_of_eight intro h obtain ⟨⟨i, hi1, hi2⟩, ⟨j, hj1, hj2⟩, hij1, hij2, hc1, hc2⟩ := h dsimp [coloring_of_eight] at * interval_cases i <;> interval_cases j <;> sorry --aesop (simp_config := {decide := true}) abbrev solution_value : ℕ := 9 theorem bulgaria1998_p1 : IsLeast { m | all_colorings_are_good m } solution_value := by constructor · rw [Set.mem_setOf_eq] refine ⟨by norm_num, ?_⟩ intro color sorry · rw [mem_lowerBounds] intro n hn rw [Set.mem_setOf_eq] at hn by_contra! H have h1 : n ≤ solution_value - 1 := Nat.le_pred_of_lt H have ⟨h2, h3⟩ := lemma1 h1 hn obtain ⟨f, hf⟩ := lemma2 exact (hf (h3 f)).elim end Bulgaria1998P1
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 1 We will be considering colorings in 2 colors of n (distinct) points A₁, A₂, ..., Aₙ. Call such a coloring "good" if there exist three points Aᵢ, Aⱼ, A₂ⱼ₋ᵢ, 1 ≤ i < 2j - i ≤ n, which are colored the same color. Find the least natural number n (n ≥ 3) such that all colorings of n points are good. -/ namespace Bulgaria1998P1 abbrev coloring_is_good {m : ℕ} (color : Set.Icc 1 m → Fin 2) : Prop := ∃ i j : Set.Icc 1 m, i < j ∧ ∃ h3 : 2 * j.val - i ∈ Set.Icc 1 m, color i = color j ∧ color i = color ⟨2 * j - i, h3⟩ abbrev all_colorings_are_good (m : ℕ) : Prop := 3 ≤ m ∧ ∀ color : Set.Icc 1 m → Fin 2, coloring_is_good color lemma lemma1 {m n : ℕ} (hmn : m ≤ n) (hm : all_colorings_are_good m) : all_colorings_are_good n := by constructor · exact hm.1.trans hmn · intro c let c' : Set.Icc 1 m → Fin 2 := fun x ↦ c ⟨x.val, by rw [Set.mem_Icc]; exact ⟨x.prop.1, x.prop.2.trans hmn⟩⟩ obtain ⟨⟨i, hi1, hi2⟩, ⟨j, hj1, hj2⟩, hij1, hij2, hc1, hc2⟩ := hm.2 c' use ⟨i, hi1, hi2.trans hmn⟩ use ⟨j, hj1, hj2.trans hmn⟩ simp only [Subtype.mk_lt_mk, Set.mem_Icc, tsub_le_iff_right, exists_and_left] simp only [Subtype.mk_lt_mk] at hij1 refine ⟨hij1, ?_⟩ simp only [Set.mem_Icc, tsub_le_iff_right] at hij2 simp only [c'] at hc1 refine ⟨hc1, ?_⟩ have hij2' : 1 ≤ 2 * j - i ∧ 2 * j ≤ n + i := ⟨hij2.1, le_add_of_le_add_right hij2.2 hmn⟩ use hij2' def coloring_of_eight {n : ℕ} : Set.Icc 1 n → Fin 2 | ⟨1, _⟩ => 0 | ⟨2, _⟩ => 1 | ⟨3, _⟩ => 0 | ⟨4, _⟩ => 1 | ⟨5, _⟩ => 1 | ⟨6, _⟩ => 0 | ⟨7, _⟩ => 1 | ⟨8, _⟩ => 0 | _ => 0 -- unreachable lemma lemma2 : ∃ f : Set.Icc 1 8 → Fin 2, ¬coloring_is_good f := by use coloring_of_eight intro h obtain ⟨⟨i, hi1, hi2⟩, ⟨j, hj1, hj2⟩, hij1, hij2, hc1, hc2⟩ := h dsimp [coloring_of_eight] at * interval_cases i <;> interval_cases j <;> sorry --aesop (simp_config := {decide := true}) abbrev solution_value : ℕ := 9 theorem bulgaria1998_p1 : IsLeast { m | all_colorings_are_good m } solution_value := by constructor · rw [Set.mem_setOf_eq] refine ⟨by norm_num, ?_⟩ intro color sorry · rw [mem_lowerBounds] intro n hn rw [Set.mem_setOf_eq] at hn by_contra! H have h1 : n ≤ solution_value - 1 := Nat.le_pred_of_lt H have ⟨h2, h3⟩ := lemma1 h1 hn obtain ⟨f, hf⟩ := lemma2 exact (hf (h3 f)).elim end Bulgaria1998P1
false
null
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P1.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": true, "errors": [], "timeout_s": 600.0, "latency_s": 34.5438, "verified_at": "2026-03-26T18:15:55.711664+00:00"}}
false
true
true
34.5438
compfiles_Bulgaria1998P11
compfiles
Copyright (c) 2023 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw, Adam Kurkiewicz -/ import Mathlib /-! Bulgarian Mathematical Olympiad 1998, Problem 11 Let m,n be natural numbers such that A = ((m + 3)ⁿ + 1) / (3m) is an integer. Prove that A is odd. -/ namespace Bulgaria1998P11 lemma mod_3_add_3_under_exponent (m n : ℕ) : ((m + 3) ^ n) ≡ (m ^ n) [MOD 3] := by change (m + 3)^n % 3 = m ^ n % 3 simp [Nat.pow_mod] lemma zero_pow_mod_3 {m n : ℕ} (h1 : n > 0) (h2 : m ≡ 0 [MOD 3]) : m ^ n ≡ 0 [MOD 3]:= by change _ % 3 = 0 at h2 ⊢ rw [←Nat.dvd_iff_mod_eq_zero] at h2 ⊢ exact Dvd.dvd.pow h2 (Nat.ne_zero_of_lt h1) lemma one_pow_mod_3 {m n : ℕ} (h2 : m ≡ 1 [MOD 3]) : m ^ n ≡ 1 [MOD 3]:= by change _ % _ = 1 at h2 ⊢ simp [Nat.pow_mod, h2] lemma two_even_pow_mod_3 {m n : ℕ} (h1 : Even n) (h2 : m ≡ 2 [MOD 3]) : m ^ n ≡ 1 [MOD 3] := by change _ % _ = _ at h2 ⊢ obtain ⟨k, hk⟩ := h1 simp (config := { arith := true, decide := true }) [Nat.pow_mod, h2, hk, pow_mul] theorem n_odd_and_m_eq_2_mod_3 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd n ∧ m ≡ 2 [MOD 3] := by by_cases n_gt_zero : n > 0 · have h_mod_3 : 0 ≡ (m ^ n + 1) [MOD 3] := by calc 0 ≡ 3 * (m * A) [MOD 3] := (Nat.mul_mod_right 3 (m * A)).symm _ ≡ (3 * m * A) [MOD 3] := by rw[show 3 * (m * A) = (3 * m * A) by ring] _ ≡ ((m + 3) ^ n + 1) [MOD 3] := by rw[h] _ ≡ (m ^ n + 1) [MOD 3] := Nat.ModEq.add (mod_3_add_3_under_exponent m n) rfl mod_cases mod_case : m % 3 · have towards_contradiction : 0 ≡ 1 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 0 + 1 [MOD 3] := Nat.ModEq.add (zero_pow_mod_3 n_gt_zero mod_case) rfl _ ≡ 1 [MOD 3] := by rfl contradiction · have towards_contradiction : 0 ≡ 2 [MOD 3] := by rw[show 2 = 1 + 1 by ring] calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (one_pow_mod_3 mod_case) rfl contradiction · by_cases n_even : Even n · have towards_contradiction : 0 ≡ 2 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (two_even_pow_mod_3 n_even mod_case) rfl _ ≡ 2 [MOD 3] := by rfl contradiction · rw [Nat.not_even_iff_odd] at n_even exact ⟨n_even, mod_case⟩ · rw [Nat.eq_zero_of_not_pos n_gt_zero] at h omega lemma not_one_le_k {k : ℕ} (h : ¬1 ≤ k) : k = 0 := by simp_all only [not_le, Nat.lt_one_iff] lemma two_le_pow_two (l : ℕ) : 2 ≤ 2 ^ (l + 1) := by rw [pow_succ] suffices 1 ≤ 2 ^ l from Nat.le_mul_of_pos_left 2 this exact Nat.one_le_two_pow lemma two_n_and_rest_factorisation (m : ℕ) (even_m : Even m) (h: 0 < m) : ∃ (l : ℕ) (m₁ : ℕ), 1 ≤ l ∧ Odd m₁ ∧ m = 2 ^ l * m₁ := by have ⟨a, ha⟩ := (pow_padicValNat_dvd : 2 ^ padicValNat 2 m ∣ m) refine ⟨padicValNat 2 m, a, ?_⟩ obtain ⟨k, hk⟩ := even_iff_two_dvd.mp even_m have hk0 : 0 < k := by omega refine ⟨?_, ?_, ha⟩ · rw [hk] rw [show 2 * k = 2^1 * k from rfl] rw [padicValNat_base_pow_mul one_lt_two hk0.ne'] exact Nat.le_add_left 1 (padicValNat 2 k) · by_contra! Ha rw [Nat.not_odd_iff_even] at Ha obtain ⟨b, hb⟩ := Ha have h3 : 2 ^ (padicValNat 2 m + 1) ∣ m := by use b rw [hb] at ha rw [pow_succ] linarith only [ha] have h4 := (Nat.pow_dvd_iff_le_padicValNat (by omega) (Nat.ne_zero_of_lt h)).mp h3 exact (lt_self_iff_false _).mp (Nat.succ_le_iff.mp h4) lemma m_mod_2_contradiction (m n A : ℕ) (even_A : Even A) (m_eq_2_mod_4 : m ≡ 2 [MOD 4]) (h : 3 * m * A = (m + 3)^n + 1) : False := by rw [← ZMod.natCast_eq_natCast_iff] at m_eq_2_mod_4 apply_fun (fun x ↦ (x : ZMod 4)) at h push_cast at h rw [m_eq_2_mod_4] at h obtain ⟨a, rfl⟩ := even_A push_cast at h rw [←two_mul] at h ring_nf at h; reduce_mod_char at h rw [one_pow n] at h simp (config := { arith := true, decide := true })at h lemma m_add_3_pow_n_mod_m (n m : ℕ) : (m + 3)^n ≡ 3^n [MOD m] := by simp [Nat.ModEq, Nat.pow_mod] lemma too_good_to_be_true (n l : ℕ) (three_le_l : 3 ≤ l) (two_pow_l_divides_expresion : 2^l ∣ (3^n + 1)) (expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8]) : False := by have : 8 ∣ 3 ^ n + 1 := by obtain ⟨a, Ha⟩ := two_pow_l_divides_expresion obtain ⟨b, Hb⟩ := Nat.exists_eq_add_of_le' three_le_l rw[Hb] at Ha dsimp [Dvd.dvd] use 2 ^ b * a rw[Ha] ring obtain ⟨a, Ha⟩ := this rw [Ha] at expression_eq_4_mod_8 dsimp[Nat.ModEq] at expression_eq_4_mod_8 simp at expression_eq_4_mod_8 lemma thue (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), (a : ZMod n) * x + y = 0 ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by -- https://services.artofproblemsolving.com/download.php?id=YXR0YWNobWVudHMvMy8yL2QzYjEzOGM0ODE3YzYwZGU4NGFmOTEwZDc0ZGNhODRjOGMyMzZlLnBkZg==&rn=dGh1ZS12NC5wZGY= -- let r = ⌊√n⌋, i.e. r is the unique integer for which -- r² ≤ n < (r + 1)². let r := Nat.sqrt n -- The number of pairs (x,y) so that 0 ≤ x,y ≤ r is (r + 1)² which -- is greater than n. -- -- Therefore there must be two different pairs (x₁, y₁) and (x₂, y₂) -- such that -- ax₁ + y₁ = ax₂ + ay₂ (mod n) -- i.e. -- a(x₁ - x₂) = y₂ - y₁ (mod n) -- let D := Fin (r + 1) × Fin (r + 1) let f : D → ZMod n := fun ⟨x,y⟩ ↦ a * (x.val : ZMod n) + (y.val : ZMod n) have cardD : Fintype.card D = (r + 1)^2 := by unfold D rw [sq, Fintype.card_prod, Fintype.card_fin] have : NeZero n := NeZero.of_gt hn have cardZ : Fintype.card (ZMod n) = n := ZMod.card n have hDZ : Fintype.card (ZMod n) < Fintype.card D := by rw [cardD, cardZ] exact Nat.lt_succ_sqrt' n obtain ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩, hxyn, hxy⟩ := Fintype.exists_ne_map_eq_of_card_lt f hDZ dsimp [f] at hxy replace hxy : (a : ZMod n) * (↑↑x₁ - ↑↑x₂) + (↑↑y₁ - ↑↑y₂) = 0 := by linear_combination hxy use (x₁ : ℤ) - (x₂ : ℤ) use (y₁ : ℤ) - (y₂ : ℤ) have hx1 : ((x₁ : ℕ): ZMod n) = (((x₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hx2 : ((x₂ : ℕ): ZMod n) = (((x₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hx3 : (((x₁ : ℕ): ℤ) : ZMod n) - (((x₂ : ℕ): ℤ) : ZMod n) = (((((x₁ : ℕ): ℤ) -((x₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast have hy1 : ((y₁ : ℕ): ZMod n) = (((y₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hy2 : ((y₂ : ℕ): ZMod n) = (((y₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hy3 : (((y₁ : ℕ): ℤ) : ZMod n) - (((y₂ : ℕ): ℤ) : ZMod n) = (((((y₁ : ℕ): ℤ) -((y₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast refine ⟨?_, ?_, ?_, ?_⟩ · rw [hx1, hx2, hx3, hy1, hy2, hy3] at hxy rw [hxy] · by_contra! H replace H : |((x₁:ℕ):ℤ) - ↑↑x₂| = 0 := by have : (0 : ℤ) ≤ |((x₁:ℕ):ℤ) - ↑↑x₂| := abs_nonneg _ exact (Int.le_antisymm this H).symm rw [abs_eq_zero] at H replace H : ((x₁:ℕ):ℤ) = ↑↑x₂ := Int.eq_of_sub_eq_zero H replace H : x₁.val = x₂.val := Int.ofNat_inj.mp H replace H : x₁ = x₂ := Fin.eq_of_val_eq H rw [H, sub_self, mul_zero, zero_add] at hxy have h4 : ((y₁:ℕ): ZMod n) = ↑↑y₂ := by linear_combination hxy rw [ZMod.natCast_eq_natCast_iff'] at h4 have p1 := y₁.prop have p2 := y₂.prop have : r + 1 ≤ n := by have h31 := Nat.sqrt_lt_self hn omega have h10 : y₁.val < n := by omega have h11 : y₂.val < n := by omega rw [Nat.mod_eq_of_lt h10, Nat.mod_eq_of_lt h11] at h4 have h12 : y₁ = y₂ := Fin.eq_of_val_eq h4 rw [H,h12] at hxyn simp at hxyn · have hx₁ : x₁.val < r + 1 := x₁.prop have hx₂ : x₂.val < r + 1 := x₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hx₁, hx₂, hr1] · have hy₁ : y₁.val < r + 1 := y₁.prop have hy₂ : y₂.val < r + 1 := y₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hy₁, hy₂, hr1] /-- In this version of Thue's lemma, we get an `x` that is nonzero and a `y` that might be zero. If we wanted to guarantee that `y` is nonzero, we would need an extra hypothesis `Nat.Coprime a n`. -/ lemma Thue's_lemma (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), a * x + y ≡ 0 [ZMOD n] ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by obtain ⟨x, y, hxay, hx, hx1, hy1⟩ := thue a n hn refine ⟨x, y, ?_, hx, hx1, hy1⟩ have h1 : (a : ZMod n) * (x : ZMod n) + (y : ZMod n) = ((((a : ℤ) * x + y):ℤ) : ZMod n) := by norm_cast have h2 : ((0:ℤ):ZMod n) = 0 := by norm_cast rw [h1, ←h2] at hxay exact (ZMod.intCast_eq_intCast_iff (a * x + y) 0 n).mp hxay example (a b n : ℕ) (ha : a < n + 1) (hb : b < n + 1) : ((a : ℤ) - (b : ℤ))^2 ≤ n^2 := by nlinarith lemma square_mod_4_zmod (x : ZMod 4) : x ^ 2 = 1 ∨ x ^ 2 = 0 := by fin_cases x <;> simp (config := { arith := true, decide := true })lemma square_mod_3_zmod_0 : ∀ {x : ZMod 3} (_ : x ^ 2 = 0), x = 0 := by decide lemma leaf_contradiction {x y m₁ : ℤ} (h: 3 * x ^ 2 + y ^ 2 = m₁) (h2 : m₁ - 5 ≡ 0 [ZMOD 6]) : False := by replace h2 : m₁ - 5 ≡ 0 [ZMOD 3] := Int.ModEq.of_mul_left 2 h2 rw [show 3 = ((3:ℕ):ℤ) by rfl] at h2 rw [← ZMod.intCast_eq_intCast_iff] at h2 apply_fun (fun x ↦ (x : ZMod 3)) at h push_cast at h h2 replace h2 : (m₁:ZMod 3) = 5 := by linear_combination h2 rw [h2] at h reduce_mod_char at h generalize hz : (y : ZMod 3) = z fin_cases z <;> rw [hz] at h <;> grind theorem bulgaria1998_p11 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd A := by -- Follows the second solution in _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have ⟨⟨k, Hk⟩, m_eq_2_mod_3⟩ : Odd n ∧ m ≡ 2 [MOD 3] := n_odd_and_m_eq_2_mod_3 m n A h by_contra even_A rw [Nat.not_odd_iff_even] at even_A have zero_lt_m : 0 < m := by by_contra m_eq_0 replace m_eq_0 := not_one_le_k m_eq_0 rw [m_eq_0] at h ring_nf at h have : 1 + 3 ^ n > 0 := by positivity rw [← h] at this contradiction have even_m : Even m := by have n_ne_zero : n ≠ 0 := by omega replace evenA : (A : ZMod 2) = (0:ℕ) := by rw [Nat.even_iff] at even_A exact (ZMod.natCast_eq_natCast_iff' A 0 2).mpr even_A suffices H : (m : ZMod 2) = (0:ℕ) · rw [ZMod.natCast_eq_natCast_iff] at H exact Nat.even_iff.mpr H apply_fun (fun x ↦ (x : ZMod 2)) at h push_cast at h rw [evenA] at h simp only [Nat.cast_zero, mul_zero] at h generalize hm' : (m : ZMod 2) = m' rw [hm'] at h fin_cases m' · rfl · dsimp only [Nat.reduceAdd, Fin.mk_one, Fin.isValue] at h reduce_mod_char at h rw [zero_pow n_ne_zero, zero_add] at h exact (zero_ne_one h).elim obtain ⟨l, m₁, ⟨one_le_l, odd_m₁, m_factorisation⟩⟩ := two_n_and_rest_factorisation m even_m zero_lt_m by_cases l_eq_one : (l = 1) · rw [l_eq_one] at m_factorisation ring_nf at m_factorisation have : m₁ ≡ 1 [MOD 4] ∨ m₁ ≡ 3 [MOD 4] := by obtain ⟨a, rfl⟩ := odd_m₁ obtain ⟨b, rfl⟩ | ⟨b, rfl⟩ := Nat.even_or_odd a · left dsimp [Nat.ModEq] ring_nf simp · right dsimp [Nat.ModEq] ring_nf simp have m_eq_2_mod_4 : m ≡ 2 [MOD 4] := by rw [m_factorisation] obtain left | right := this · nth_rw 2 [show 2 = 1 * 2 by rfl] exact Nat.ModEq.mul_right _ left · calc m₁ * 2 ≡ 3 * 2 [MOD 4] := Nat.ModEq.mul right rfl _ ≡ 2 [MOD 4] := rfl exact m_mod_2_contradiction m n A even_A m_eq_2_mod_4 h · have eq_2 : 0 ≡ 3^n + 1 [MOD m] := by calc 0 ≡ m * (3 * A) [MOD m] := by rw[show 0 = 0 * (3 * A) by ring] refine Nat.ModEq.mul_right _ ?_ simp [Nat.ModEq] _ ≡ 3 * m * A [MOD m] := by rw[show m * (3 * A) = 3 * m * A by ring] _ ≡ (m + 3)^n + 1 [MOD m] := by rw[h] _ ≡ 3^n + 1 [MOD m] := by refine Nat.ModEq.add_right _ ?_ exact m_add_3_pow_n_mod_m n m have l_eq_2 : l = 2 := by have two_le_l : 2 ≤ l := by omega obtain left | right := lt_or_eq_of_le two_le_l · have two_pow_l_divides_expresion : 2 ^ l ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use m₁ * a rw[show 2 ^ l * (m₁ * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8] := by rw [←ZMod.natCast_eq_natCast_iff, Hk] rw [pow_succ, pow_mul] rw[show (3 ^ 2) = 9 by rfl] push_cast reduce_mod_char rw [one_pow (M := ZMod 8) k] simp (config := { arith := true, decide := true })exfalso exact too_good_to_be_true n l (show 3 ≤ l by exact left) two_pow_l_divides_expresion expression_eq_4_mod_8 · exact right.symm have m_eq_4_m₁ : m = 4 * m₁ := by rw[l_eq_2] at m_factorisation exact m_factorisation have m₁_divides_expresion : m₁ ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use 2 ^ l * a rw[show m₁ * (2 ^ l * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have m₁_eq_2_mod_3 : m₁ ≡ 2 [MOD 3] := by have step_1 : 4 * m₁ ≡ 2 [MOD 3] := by rw[m_eq_4_m₁] at m_eq_2_mod_3 exact m_eq_2_mod_3 have step_2 : 4 * m₁ ≡ m₁ [MOD 3] := by nth_rw 2 [show m₁ = 1 * m₁ by ring] exact Nat.ModEq.mul rfl rfl calc m₁ ≡ 4 * m₁ [MOD 3] := step_2.symm _ ≡ 2 [MOD 3] := step_1 have m₁_eq_5_mod_6 : m₁ ≡ 5 [MOD 6] := by mod_cases m_mod_six : m₁ % 6 · have step_1: m₁ * 2 ≡ 0 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 1 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have : m₁ ≡ 1 [MOD 2] := by obtain ⟨a, Ha⟩ := odd_m₁ rw[show 1 = 0 + 1 by norm_num] rw[Ha] refine Nat.ModEq.add_right _ ?_ simp[Nat.ModEq] have step_1: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 have step_2: m₁ * 3 ≡ 1 * 3 [MOD 2 * 3] := Nat.ModEq.mul_right' 3 this change m₁ * 2 + m₁ ≡ 2 * 2 + 5 [MOD 2 * 3] at step_2 exact Nat.ModEq.add_left_cancel step_1 step_2 · have step_1: m₁ * 2 ≡ 3 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 4 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · exact m_mod_six have exists_a : ∃ a : ℕ, a = 3 ^ (k + 1) := by use 3 ^ (k + 1) obtain ⟨a, Ha⟩ := exists_a have m₁_divides_for_thues_lemma : m₁ ∣ a^2 + 3 := by apply Nat.modEq_zero_iff_dvd.mp have step_1:= Nat.modEq_zero_iff_dvd.mpr m₁_divides_expresion rw[Hk] at step_1 have step_2: 3 * (3 ^ (2 * k + 1) + 1) ≡ 3 * 0 [MOD m₁] := Nat.ModEq.mul_left 3 step_1 ring_nf at step_2 rw[show 3 ^ (k * 2) * 9 = 3 ^ ((k + 1) * 2 ) by ring] at step_2 have step_3 : 3 ^ ((k + 1) * 2) = (3 ^ (k + 1)) ^ (2) := pow_mul 3 (k + 1) 2 rw[step_3] at step_2 rw[← Ha] at step_2 ring_nf exact step_2 have hn1 : 1 < m₁ := by change _ % _ = _ % _ at m₁_eq_2_mod_3 omega obtain ⟨x, y, x_y_props⟩ := Thue's_lemma a m₁ hn1 clear hn1 obtain ⟨mod_expression, x_lower, x_higher, y_higher⟩ := x_y_props have lifted_m₁_result := Int.natCast_modEq_iff.mpr (Nat.modEq_zero_iff_dvd.mpr m₁_divides_for_thues_lemma) norm_num at lifted_m₁_result have expression : 3 * x ^ 2 + y ^ 2 ≡ 0 [ZMOD m₁] := by have step_2 : a * x ≡ -y [ZMOD m₁] := by rw [show -y = 0 - y by ring] rw [show a * x = a * x + y - y by ring] exact Int.ModEq.sub_right _ mod_expression have step_3 : a ^ 2 * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by rw [show a ^ 2 * x ^ 2 = (a * x) * (a * x) by ring] rw [show y ^ 2 = (-y) * (-y) by ring] exact Int.ModEq.mul step_2 step_2 have step_4: (-3) * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by have step_1 : a ^ 2 ≡ -3 [ZMOD m₁] := Int.ModEq.add_right_cancel' 3 lifted_m₁_result trans a ^ 2 * x ^ 2 · exact Int.ModEq.mul (step_1.symm) rfl · exact step_3 have : ((-3) * x ^ 2) + (3 * x ^ 2) ≡ (y ^ 2) + (3 * x ^ 2) [ZMOD m₁] := Int.ModEq.add_right _ step_4 rw [show (-3) * x ^ 2 + (3 * x ^ 2) = 0 by ring] at this rw [show y ^ 2 + 3 * x ^ 2 = 3 * x ^ 2 + y ^ 2 by ring] at this exact this.symm obtain ⟨s, Hs⟩ := Int.modEq_zero_iff_dvd.mp expression rw [m_eq_4_m₁] at zero_lt_m have zero_lt_m₁ : 0 < @Nat.cast ℤ _ m₁ := by omega have upper_bound_s : s ≤ 4 := by have upper_bound_expression: 3 * x ^ 2 + y ^ 2 ≤ 4 * m₁ := by omega rw [Hs] at upper_bound_expression rw [show m₁ * s = s * m₁ by ring] at upper_bound_expression exact le_of_mul_le_mul_right upper_bound_expression zero_lt_m₁ have lower_bound_s : 0 < s := by have lower_bound_expression : 0 < 3 * x ^ 2 + y ^ 2 := by have h1 : 0 < 3 * x ^ 2 := by rw [←sq_abs]; positivity exact Int.add_pos_of_pos_of_nonneg h1 (sq_nonneg y) rw [Hs] at lower_bound_expression exact Int.pos_of_mul_pos_right lower_bound_expression zero_lt_m₁ have m₁_sub_5_mod_6 : ↑m₁ - 5 ≡ 0 [ZMOD 6] := by exact Int.ModEq.sub (Int.natCast_modEq_iff.mpr m₁_eq_5_mod_6) rfl interval_cases s · -- s = 1 rw [mul_one] at Hs exact leaf_contradiction Hs m₁_sub_5_mod_6 · -- s = 2 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := sub_eq_iff_eq_add.mp this rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_4 : ((x : (ZMod 4)) ^ 2 * 3 + y ^ 2) = ((10 + c * 12) : (ZMod 4)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_4 obtain left_x | right_x := square_mod_4_zmod x · rw[left_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · -- s = 3 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := by omega rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_3 : ((x : (ZMod 3)) ^ 2 * 3 + y ^ 2) = ((15 + c * 18) : (ZMod 3)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_3 have : (y : ZMod 3) = 0 := square_mod_3_zmod_0 expression_mod_3 have := (ZMod.intCast_zmod_eq_zero_iff_dvd y 3).mp this dsimp[Dvd.dvd] at this obtain⟨y', Hy'⟩ := this rw[Hy'] at Hs ring_nf at Hs rw[show x ^ 2 * 3 + y' ^ 2 * 9 = 3 * (x ^ 2 + 3 * y' ^ 2) by ring] at Hs rw[show 15 + c * 18 = 3 * (5 + 6 * c) by ring] at Hs have reduced_expression : (x ^ 2 + 3 * y' ^ 2) = (5 + 6 * c) := by omega rw[show 5 + 6 * c = 6 * c + 5 by ring] at reduced_expression rw[← expr_m₁_mod_6] at reduced_expression rw[show x ^ 2 + 3 * y' ^ 2 = 3 * y' ^ 2 + x ^ 2 by ring] at reduced_expression exact leaf_contradiction reduced_expression m₁_sub_5_mod_6 · -- s = 4 have : y^2 < m₁ := by by_contra! H have h1 : y^2 = m₁ := (Int.le_antisymm H y_higher).symm rw [←sq_abs, Int.abs_eq_natAbs] at h1 norm_cast at h1 generalize hyy : y.natAbs = yy rw [hyy] at h1 rw [←h1] at m₁_eq_2_mod_3 mod_cases Hyy : yy % 3 <;> change _ % _ = _ % _ at Hyy m₁_eq_2_mod_3 <;> simp [Nat.pow_mod, Hyy] at m₁_eq_2_mod_3 omega end Bulgaria1998P11
/-
/- Copyright (c) 2023 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw, Adam Kurkiewicz -/ import Mathlib /-! Bulgarian Mathematical Olympiad 1998, Problem 11 Let m,n be natural numbers such that A = ((m + 3)ⁿ + 1) / (3m) is an integer. Prove that A is odd. -/ namespace Bulgaria1998P11 lemma mod_3_add_3_under_exponent (m n : ℕ) : ((m + 3) ^ n) ≡ (m ^ n) [MOD 3] := by change (m + 3)^n % 3 = m ^ n % 3 simp [Nat.pow_mod] lemma zero_pow_mod_3 {m n : ℕ} (h1 : n > 0) (h2 : m ≡ 0 [MOD 3]) : m ^ n ≡ 0 [MOD 3]:= by change _ % 3 = 0 at h2 ⊢ rw [←Nat.dvd_iff_mod_eq_zero] at h2 ⊢ exact Dvd.dvd.pow h2 (Nat.ne_zero_of_lt h1) lemma one_pow_mod_3 {m n : ℕ} (h2 : m ≡ 1 [MOD 3]) : m ^ n ≡ 1 [MOD 3]:= by change _ % _ = 1 at h2 ⊢ simp [Nat.pow_mod, h2] lemma two_even_pow_mod_3 {m n : ℕ} (h1 : Even n) (h2 : m ≡ 2 [MOD 3]) : m ^ n ≡ 1 [MOD 3] := by change _ % _ = _ at h2 ⊢ obtain ⟨k, hk⟩ := h1 simp (config := { arith := true, decide := true }) [Nat.pow_mod, h2, hk, pow_mul] theorem n_odd_and_m_eq_2_mod_3 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd n ∧ m ≡ 2 [MOD 3] := by by_cases n_gt_zero : n > 0 · have h_mod_3 : 0 ≡ (m ^ n + 1) [MOD 3] := by calc 0 ≡ 3 * (m * A) [MOD 3] := (Nat.mul_mod_right 3 (m * A)).symm _ ≡ (3 * m * A) [MOD 3] := by rw[show 3 * (m * A) = (3 * m * A) by ring] _ ≡ ((m + 3) ^ n + 1) [MOD 3] := by rw[h] _ ≡ (m ^ n + 1) [MOD 3] := Nat.ModEq.add (mod_3_add_3_under_exponent m n) rfl mod_cases mod_case : m % 3 · have towards_contradiction : 0 ≡ 1 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 0 + 1 [MOD 3] := Nat.ModEq.add (zero_pow_mod_3 n_gt_zero mod_case) rfl _ ≡ 1 [MOD 3] := by rfl contradiction · have towards_contradiction : 0 ≡ 2 [MOD 3] := by rw[show 2 = 1 + 1 by ring] calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (one_pow_mod_3 mod_case) rfl contradiction · by_cases n_even : Even n · have towards_contradiction : 0 ≡ 2 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (two_even_pow_mod_3 n_even mod_case) rfl _ ≡ 2 [MOD 3] := by rfl contradiction · rw [Nat.not_even_iff_odd] at n_even exact ⟨n_even, mod_case⟩ · rw [Nat.eq_zero_of_not_pos n_gt_zero] at h omega lemma not_one_le_k {k : ℕ} (h : ¬1 ≤ k) : k = 0 := by simp_all only [not_le, Nat.lt_one_iff] lemma two_le_pow_two (l : ℕ) : 2 ≤ 2 ^ (l + 1) := by rw [pow_succ] suffices 1 ≤ 2 ^ l from Nat.le_mul_of_pos_left 2 this exact Nat.one_le_two_pow lemma two_n_and_rest_factorisation (m : ℕ) (even_m : Even m) (h: 0 < m) : ∃ (l : ℕ) (m₁ : ℕ), 1 ≤ l ∧ Odd m₁ ∧ m = 2 ^ l * m₁ := by have ⟨a, ha⟩ := (pow_padicValNat_dvd : 2 ^ padicValNat 2 m ∣ m) refine ⟨padicValNat 2 m, a, ?_⟩ obtain ⟨k, hk⟩ := even_iff_two_dvd.mp even_m have hk0 : 0 < k := by omega refine ⟨?_, ?_, ha⟩ · rw [hk] rw [show 2 * k = 2^1 * k from rfl] rw [padicValNat_base_pow_mul one_lt_two hk0.ne'] exact Nat.le_add_left 1 (padicValNat 2 k) · by_contra! Ha rw [Nat.not_odd_iff_even] at Ha obtain ⟨b, hb⟩ := Ha have h3 : 2 ^ (padicValNat 2 m + 1) ∣ m := by use b rw [hb] at ha rw [pow_succ] linarith only [ha] have h4 := (Nat.pow_dvd_iff_le_padicValNat (by omega) (Nat.ne_zero_of_lt h)).mp h3 exact (lt_self_iff_false _).mp (Nat.succ_le_iff.mp h4) lemma m_mod_2_contradiction (m n A : ℕ) (even_A : Even A) (m_eq_2_mod_4 : m ≡ 2 [MOD 4]) (h : 3 * m * A = (m + 3)^n + 1) : False := by rw [← ZMod.natCast_eq_natCast_iff] at m_eq_2_mod_4 apply_fun (fun x ↦ (x : ZMod 4)) at h push_cast at h rw [m_eq_2_mod_4] at h obtain ⟨a, rfl⟩ := even_A push_cast at h rw [←two_mul] at h ring_nf at h; reduce_mod_char at h rw [one_pow n] at h simp (config := { arith := true, decide := true })at h lemma m_add_3_pow_n_mod_m (n m : ℕ) : (m + 3)^n ≡ 3^n [MOD m] := by simp [Nat.ModEq, Nat.pow_mod] lemma too_good_to_be_true (n l : ℕ) (three_le_l : 3 ≤ l) (two_pow_l_divides_expresion : 2^l ∣ (3^n + 1)) (expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8]) : False := by have : 8 ∣ 3 ^ n + 1 := by obtain ⟨a, Ha⟩ := two_pow_l_divides_expresion obtain ⟨b, Hb⟩ := Nat.exists_eq_add_of_le' three_le_l rw[Hb] at Ha dsimp [Dvd.dvd] use 2 ^ b * a rw[Ha] ring obtain ⟨a, Ha⟩ := this rw [Ha] at expression_eq_4_mod_8 dsimp[Nat.ModEq] at expression_eq_4_mod_8 simp at expression_eq_4_mod_8 lemma thue (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), (a : ZMod n) * x + y = 0 ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by -- https://services.artofproblemsolving.com/download.php?id=YXR0YWNobWVudHMvMy8yL2QzYjEzOGM0ODE3YzYwZGU4NGFmOTEwZDc0ZGNhODRjOGMyMzZlLnBkZg==&rn=dGh1ZS12NC5wZGY= -- let r = ⌊√n⌋, i.e. r is the unique integer for which -- r² ≤ n < (r + 1)². let r := Nat.sqrt n -- The number of pairs (x,y) so that 0 ≤ x,y ≤ r is (r + 1)² which -- is greater than n. -- -- Therefore there must be two different pairs (x₁, y₁) and (x₂, y₂) -- such that -- ax₁ + y₁ = ax₂ + ay₂ (mod n) -- i.e. -- a(x₁ - x₂) = y₂ - y₁ (mod n) -- let D := Fin (r + 1) × Fin (r + 1) let f : D → ZMod n := fun ⟨x,y⟩ ↦ a * (x.val : ZMod n) + (y.val : ZMod n) have cardD : Fintype.card D = (r + 1)^2 := by unfold D rw [sq, Fintype.card_prod, Fintype.card_fin] have : NeZero n := NeZero.of_gt hn have cardZ : Fintype.card (ZMod n) = n := ZMod.card n have hDZ : Fintype.card (ZMod n) < Fintype.card D := by rw [cardD, cardZ] exact Nat.lt_succ_sqrt' n obtain ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩, hxyn, hxy⟩ := Fintype.exists_ne_map_eq_of_card_lt f hDZ dsimp [f] at hxy replace hxy : (a : ZMod n) * (↑↑x₁ - ↑↑x₂) + (↑↑y₁ - ↑↑y₂) = 0 := by linear_combination hxy use (x₁ : ℤ) - (x₂ : ℤ) use (y₁ : ℤ) - (y₂ : ℤ) have hx1 : ((x₁ : ℕ): ZMod n) = (((x₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hx2 : ((x₂ : ℕ): ZMod n) = (((x₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hx3 : (((x₁ : ℕ): ℤ) : ZMod n) - (((x₂ : ℕ): ℤ) : ZMod n) = (((((x₁ : ℕ): ℤ) -((x₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast have hy1 : ((y₁ : ℕ): ZMod n) = (((y₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hy2 : ((y₂ : ℕ): ZMod n) = (((y₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hy3 : (((y₁ : ℕ): ℤ) : ZMod n) - (((y₂ : ℕ): ℤ) : ZMod n) = (((((y₁ : ℕ): ℤ) -((y₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast refine ⟨?_, ?_, ?_, ?_⟩ · rw [hx1, hx2, hx3, hy1, hy2, hy3] at hxy rw [hxy] · by_contra! H replace H : |((x₁:ℕ):ℤ) - ↑↑x₂| = 0 := by have : (0 : ℤ) ≤ |((x₁:ℕ):ℤ) - ↑↑x₂| := abs_nonneg _ exact (Int.le_antisymm this H).symm rw [abs_eq_zero] at H replace H : ((x₁:ℕ):ℤ) = ↑↑x₂ := Int.eq_of_sub_eq_zero H replace H : x₁.val = x₂.val := Int.ofNat_inj.mp H replace H : x₁ = x₂ := Fin.eq_of_val_eq H rw [H, sub_self, mul_zero, zero_add] at hxy have h4 : ((y₁:ℕ): ZMod n) = ↑↑y₂ := by linear_combination hxy rw [ZMod.natCast_eq_natCast_iff'] at h4 have p1 := y₁.prop have p2 := y₂.prop have : r + 1 ≤ n := by have h31 := Nat.sqrt_lt_self hn omega have h10 : y₁.val < n := by omega have h11 : y₂.val < n := by omega rw [Nat.mod_eq_of_lt h10, Nat.mod_eq_of_lt h11] at h4 have h12 : y₁ = y₂ := Fin.eq_of_val_eq h4 rw [H,h12] at hxyn simp at hxyn · have hx₁ : x₁.val < r + 1 := x₁.prop have hx₂ : x₂.val < r + 1 := x₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hx₁, hx₂, hr1] · have hy₁ : y₁.val < r + 1 := y₁.prop have hy₂ : y₂.val < r + 1 := y₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hy₁, hy₂, hr1] /-- In this version of Thue's lemma, we get an `x` that is nonzero and a `y` that might be zero. If we wanted to guarantee that `y` is nonzero, we would need an extra hypothesis `Nat.Coprime a n`. -/ lemma Thue's_lemma (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), a * x + y ≡ 0 [ZMOD n] ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by obtain ⟨x, y, hxay, hx, hx1, hy1⟩ := thue a n hn refine ⟨x, y, ?_, hx, hx1, hy1⟩ have h1 : (a : ZMod n) * (x : ZMod n) + (y : ZMod n) = ((((a : ℤ) * x + y):ℤ) : ZMod n) := by norm_cast have h2 : ((0:ℤ):ZMod n) = 0 := by norm_cast rw [h1, ←h2] at hxay exact (ZMod.intCast_eq_intCast_iff (a * x + y) 0 n).mp hxay example (a b n : ℕ) (ha : a < n + 1) (hb : b < n + 1) : ((a : ℤ) - (b : ℤ))^2 ≤ n^2 := by nlinarith lemma square_mod_4_zmod (x : ZMod 4) : x ^ 2 = 1 ∨ x ^ 2 = 0 := by fin_cases x <;> simp (config := { arith := true, decide := true })lemma square_mod_3_zmod_0 : ∀ {x : ZMod 3} (_ : x ^ 2 = 0), x = 0 := by decide lemma leaf_contradiction {x y m₁ : ℤ} (h: 3 * x ^ 2 + y ^ 2 = m₁) (h2 : m₁ - 5 ≡ 0 [ZMOD 6]) : False := by replace h2 : m₁ - 5 ≡ 0 [ZMOD 3] := Int.ModEq.of_mul_left 2 h2 rw [show 3 = ((3:ℕ):ℤ) by rfl] at h2 rw [← ZMod.intCast_eq_intCast_iff] at h2 apply_fun (fun x ↦ (x : ZMod 3)) at h push_cast at h h2 replace h2 : (m₁:ZMod 3) = 5 := by linear_combination h2 rw [h2] at h reduce_mod_char at h generalize hz : (y : ZMod 3) = z fin_cases z <;> rw [hz] at h <;> grind theorem bulgaria1998_p11 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd A := by -- Follows the second solution in _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have ⟨⟨k, Hk⟩, m_eq_2_mod_3⟩ : Odd n ∧ m ≡ 2 [MOD 3] := n_odd_and_m_eq_2_mod_3 m n A h by_contra even_A rw [Nat.not_odd_iff_even] at even_A have zero_lt_m : 0 < m := by by_contra m_eq_0 replace m_eq_0 := not_one_le_k m_eq_0 rw [m_eq_0] at h ring_nf at h have : 1 + 3 ^ n > 0 := by positivity rw [← h] at this contradiction have even_m : Even m := by have n_ne_zero : n ≠ 0 := by omega replace evenA : (A : ZMod 2) = (0:ℕ) := by rw [Nat.even_iff] at even_A exact (ZMod.natCast_eq_natCast_iff' A 0 2).mpr even_A suffices H : (m : ZMod 2) = (0:ℕ) · rw [ZMod.natCast_eq_natCast_iff] at H exact Nat.even_iff.mpr H apply_fun (fun x ↦ (x : ZMod 2)) at h push_cast at h rw [evenA] at h simp only [Nat.cast_zero, mul_zero] at h generalize hm' : (m : ZMod 2) = m' rw [hm'] at h fin_cases m' · rfl · dsimp only [Nat.reduceAdd, Fin.mk_one, Fin.isValue] at h reduce_mod_char at h rw [zero_pow n_ne_zero, zero_add] at h exact (zero_ne_one h).elim obtain ⟨l, m₁, ⟨one_le_l, odd_m₁, m_factorisation⟩⟩ := two_n_and_rest_factorisation m even_m zero_lt_m by_cases l_eq_one : (l = 1) · rw [l_eq_one] at m_factorisation ring_nf at m_factorisation have : m₁ ≡ 1 [MOD 4] ∨ m₁ ≡ 3 [MOD 4] := by obtain ⟨a, rfl⟩ := odd_m₁ obtain ⟨b, rfl⟩ | ⟨b, rfl⟩ := Nat.even_or_odd a · left dsimp [Nat.ModEq] ring_nf simp · right dsimp [Nat.ModEq] ring_nf simp have m_eq_2_mod_4 : m ≡ 2 [MOD 4] := by rw [m_factorisation] obtain left | right := this · nth_rw 2 [show 2 = 1 * 2 by rfl] exact Nat.ModEq.mul_right _ left · calc m₁ * 2 ≡ 3 * 2 [MOD 4] := Nat.ModEq.mul right rfl _ ≡ 2 [MOD 4] := rfl exact m_mod_2_contradiction m n A even_A m_eq_2_mod_4 h · have eq_2 : 0 ≡ 3^n + 1 [MOD m] := by calc 0 ≡ m * (3 * A) [MOD m] := by rw[show 0 = 0 * (3 * A) by ring] refine Nat.ModEq.mul_right _ ?_ simp [Nat.ModEq] _ ≡ 3 * m * A [MOD m] := by rw[show m * (3 * A) = 3 * m * A by ring] _ ≡ (m + 3)^n + 1 [MOD m] := by rw[h] _ ≡ 3^n + 1 [MOD m] := by refine Nat.ModEq.add_right _ ?_ exact m_add_3_pow_n_mod_m n m have l_eq_2 : l = 2 := by have two_le_l : 2 ≤ l := by omega obtain left | right := lt_or_eq_of_le two_le_l · have two_pow_l_divides_expresion : 2 ^ l ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use m₁ * a rw[show 2 ^ l * (m₁ * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8] := by rw [←ZMod.natCast_eq_natCast_iff, Hk] rw [pow_succ, pow_mul] rw[show (3 ^ 2) = 9 by rfl] push_cast reduce_mod_char rw [one_pow (M := ZMod 8) k] simp (config := { arith := true, decide := true })exfalso exact too_good_to_be_true n l (show 3 ≤ l by exact left) two_pow_l_divides_expresion expression_eq_4_mod_8 · exact right.symm have m_eq_4_m₁ : m = 4 * m₁ := by rw[l_eq_2] at m_factorisation exact m_factorisation have m₁_divides_expresion : m₁ ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use 2 ^ l * a rw[show m₁ * (2 ^ l * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have m₁_eq_2_mod_3 : m₁ ≡ 2 [MOD 3] := by have step_1 : 4 * m₁ ≡ 2 [MOD 3] := by rw[m_eq_4_m₁] at m_eq_2_mod_3 exact m_eq_2_mod_3 have step_2 : 4 * m₁ ≡ m₁ [MOD 3] := by nth_rw 2 [show m₁ = 1 * m₁ by ring] exact Nat.ModEq.mul rfl rfl calc m₁ ≡ 4 * m₁ [MOD 3] := step_2.symm _ ≡ 2 [MOD 3] := step_1 have m₁_eq_5_mod_6 : m₁ ≡ 5 [MOD 6] := by mod_cases m_mod_six : m₁ % 6 · have step_1: m₁ * 2 ≡ 0 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 1 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have : m₁ ≡ 1 [MOD 2] := by obtain ⟨a, Ha⟩ := odd_m₁ rw[show 1 = 0 + 1 by norm_num] rw[Ha] refine Nat.ModEq.add_right _ ?_ simp[Nat.ModEq] have step_1: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 have step_2: m₁ * 3 ≡ 1 * 3 [MOD 2 * 3] := Nat.ModEq.mul_right' 3 this change m₁ * 2 + m₁ ≡ 2 * 2 + 5 [MOD 2 * 3] at step_2 exact Nat.ModEq.add_left_cancel step_1 step_2 · have step_1: m₁ * 2 ≡ 3 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 4 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · exact m_mod_six have exists_a : ∃ a : ℕ, a = 3 ^ (k + 1) := by use 3 ^ (k + 1) obtain ⟨a, Ha⟩ := exists_a have m₁_divides_for_thues_lemma : m₁ ∣ a^2 + 3 := by apply Nat.modEq_zero_iff_dvd.mp have step_1:= Nat.modEq_zero_iff_dvd.mpr m₁_divides_expresion rw[Hk] at step_1 have step_2: 3 * (3 ^ (2 * k + 1) + 1) ≡ 3 * 0 [MOD m₁] := Nat.ModEq.mul_left 3 step_1 ring_nf at step_2 rw[show 3 ^ (k * 2) * 9 = 3 ^ ((k + 1) * 2 ) by ring] at step_2 have step_3 : 3 ^ ((k + 1) * 2) = (3 ^ (k + 1)) ^ (2) := pow_mul 3 (k + 1) 2 rw[step_3] at step_2 rw[← Ha] at step_2 ring_nf exact step_2 have hn1 : 1 < m₁ := by change _ % _ = _ % _ at m₁_eq_2_mod_3 omega obtain ⟨x, y, x_y_props⟩ := Thue's_lemma a m₁ hn1 clear hn1 obtain ⟨mod_expression, x_lower, x_higher, y_higher⟩ := x_y_props have lifted_m₁_result := Int.natCast_modEq_iff.mpr (Nat.modEq_zero_iff_dvd.mpr m₁_divides_for_thues_lemma) norm_num at lifted_m₁_result have expression : 3 * x ^ 2 + y ^ 2 ≡ 0 [ZMOD m₁] := by have step_2 : a * x ≡ -y [ZMOD m₁] := by rw [show -y = 0 - y by ring] rw [show a * x = a * x + y - y by ring] exact Int.ModEq.sub_right _ mod_expression have step_3 : a ^ 2 * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by rw [show a ^ 2 * x ^ 2 = (a * x) * (a * x) by ring] rw [show y ^ 2 = (-y) * (-y) by ring] exact Int.ModEq.mul step_2 step_2 have step_4: (-3) * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by have step_1 : a ^ 2 ≡ -3 [ZMOD m₁] := Int.ModEq.add_right_cancel' 3 lifted_m₁_result trans a ^ 2 * x ^ 2 · exact Int.ModEq.mul (step_1.symm) rfl · exact step_3 have : ((-3) * x ^ 2) + (3 * x ^ 2) ≡ (y ^ 2) + (3 * x ^ 2) [ZMOD m₁] := Int.ModEq.add_right _ step_4 rw [show (-3) * x ^ 2 + (3 * x ^ 2) = 0 by ring] at this rw [show y ^ 2 + 3 * x ^ 2 = 3 * x ^ 2 + y ^ 2 by ring] at this exact this.symm obtain ⟨s, Hs⟩ := Int.modEq_zero_iff_dvd.mp expression rw [m_eq_4_m₁] at zero_lt_m have zero_lt_m₁ : 0 < @Nat.cast ℤ _ m₁ := by omega have upper_bound_s : s ≤ 4 := by have upper_bound_expression: 3 * x ^ 2 + y ^ 2 ≤ 4 * m₁ := by omega rw [Hs] at upper_bound_expression rw [show m₁ * s = s * m₁ by ring] at upper_bound_expression exact le_of_mul_le_mul_right upper_bound_expression zero_lt_m₁ have lower_bound_s : 0 < s := by have lower_bound_expression : 0 < 3 * x ^ 2 + y ^ 2 := by have h1 : 0 < 3 * x ^ 2 := by rw [←sq_abs]; positivity exact Int.add_pos_of_pos_of_nonneg h1 (sq_nonneg y) rw [Hs] at lower_bound_expression exact Int.pos_of_mul_pos_right lower_bound_expression zero_lt_m₁ have m₁_sub_5_mod_6 : ↑m₁ - 5 ≡ 0 [ZMOD 6] := by exact Int.ModEq.sub (Int.natCast_modEq_iff.mpr m₁_eq_5_mod_6) rfl interval_cases s · -- s = 1 rw [mul_one] at Hs exact leaf_contradiction Hs m₁_sub_5_mod_6 · -- s = 2 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := sub_eq_iff_eq_add.mp this rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_4 : ((x : (ZMod 4)) ^ 2 * 3 + y ^ 2) = ((10 + c * 12) : (ZMod 4)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_4 obtain left_x | right_x := square_mod_4_zmod x · rw[left_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · -- s = 3 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := by omega rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_3 : ((x : (ZMod 3)) ^ 2 * 3 + y ^ 2) = ((15 + c * 18) : (ZMod 3)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_3 have : (y : ZMod 3) = 0 := square_mod_3_zmod_0 expression_mod_3 have := (ZMod.intCast_zmod_eq_zero_iff_dvd y 3).mp this dsimp[Dvd.dvd] at this obtain⟨y', Hy'⟩ := this rw[Hy'] at Hs ring_nf at Hs rw[show x ^ 2 * 3 + y' ^ 2 * 9 = 3 * (x ^ 2 + 3 * y' ^ 2) by ring] at Hs rw[show 15 + c * 18 = 3 * (5 + 6 * c) by ring] at Hs have reduced_expression : (x ^ 2 + 3 * y' ^ 2) = (5 + 6 * c) := by omega rw[show 5 + 6 * c = 6 * c + 5 by ring] at reduced_expression rw[← expr_m₁_mod_6] at reduced_expression rw[show x ^ 2 + 3 * y' ^ 2 = 3 * y' ^ 2 + x ^ 2 by ring] at reduced_expression exact leaf_contradiction reduced_expression m₁_sub_5_mod_6 · -- s = 4 have : y^2 < m₁ := by by_contra! H have h1 : y^2 = m₁ := (Int.le_antisymm H y_higher).symm rw [←sq_abs, Int.abs_eq_natAbs] at h1 norm_cast at h1 generalize hyy : y.natAbs = yy rw [hyy] at h1 rw [←h1] at m₁_eq_2_mod_3 mod_cases Hyy : yy % 3 <;> change _ % _ = _ % _ at Hyy m₁_eq_2_mod_3 <;> simp [Nat.pow_mod, Hyy] at m₁_eq_2_mod_3 omega end Bulgaria1998P11
true
Copyright (c) 2023 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw, Adam Kurkiewicz -/ import Mathlib /-! Bulgarian Mathematical Olympiad 1998, Problem 11 Let m,n be natural numbers such that A = ((m + 3)ⁿ + 1) / (3m) is an integer. Prove that A is odd. -/ namespace Bulgaria1998P11 lemma mod_3_add_3_under_exponent (m n : ℕ) : ((m + 3) ^ n) ≡ (m ^ n) [MOD 3] := by change (m + 3)^n % 3 = m ^ n % 3 simp [Nat.pow_mod] lemma zero_pow_mod_3 {m n : ℕ} (h1 : n > 0) (h2 : m ≡ 0 [MOD 3]) : m ^ n ≡ 0 [MOD 3]:= by change _ % 3 = 0 at h2 ⊢ rw [←Nat.dvd_iff_mod_eq_zero] at h2 ⊢ exact Dvd.dvd.pow h2 (Nat.ne_zero_of_lt h1) lemma one_pow_mod_3 {m n : ℕ} (h2 : m ≡ 1 [MOD 3]) : m ^ n ≡ 1 [MOD 3]:= by change _ % _ = 1 at h2 ⊢ simp [Nat.pow_mod, h2] lemma two_even_pow_mod_3 {m n : ℕ} (h1 : Even n) (h2 : m ≡ 2 [MOD 3]) : m ^ n ≡ 1 [MOD 3] := by change _ % _ = _ at h2 ⊢ obtain ⟨k, hk⟩ := h1 simp (config := { arith := true, decide := true }) [Nat.pow_mod, h2, hk, pow_mul] theorem n_odd_and_m_eq_2_mod_3 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd n ∧ m ≡ 2 [MOD 3] := by by_cases n_gt_zero : n > 0 · have h_mod_3 : 0 ≡ (m ^ n + 1) [MOD 3] := by calc 0 ≡ 3 * (m * A) [MOD 3] := (Nat.mul_mod_right 3 (m * A)).symm _ ≡ (3 * m * A) [MOD 3] := by rw[show 3 * (m * A) = (3 * m * A) by ring] _ ≡ ((m + 3) ^ n + 1) [MOD 3] := by rw[h] _ ≡ (m ^ n + 1) [MOD 3] := Nat.ModEq.add (mod_3_add_3_under_exponent m n) rfl mod_cases mod_case : m % 3 · have towards_contradiction : 0 ≡ 1 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 0 + 1 [MOD 3] := Nat.ModEq.add (zero_pow_mod_3 n_gt_zero mod_case) rfl _ ≡ 1 [MOD 3] := by rfl contradiction · have towards_contradiction : 0 ≡ 2 [MOD 3] := by rw[show 2 = 1 + 1 by ring] calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (one_pow_mod_3 mod_case) rfl contradiction · by_cases n_even : Even n · have towards_contradiction : 0 ≡ 2 [MOD 3] := by calc 0 ≡ m ^ n + 1 [MOD 3] := h_mod_3 _ ≡ 1 + 1 [MOD 3] := Nat.ModEq.add (two_even_pow_mod_3 n_even mod_case) rfl _ ≡ 2 [MOD 3] := by rfl contradiction · rw [Nat.not_even_iff_odd] at n_even exact ⟨n_even, mod_case⟩ · rw [Nat.eq_zero_of_not_pos n_gt_zero] at h omega lemma not_one_le_k {k : ℕ} (h : ¬1 ≤ k) : k = 0 := by simp_all only [not_le, Nat.lt_one_iff] lemma two_le_pow_two (l : ℕ) : 2 ≤ 2 ^ (l + 1) := by rw [pow_succ] suffices 1 ≤ 2 ^ l from Nat.le_mul_of_pos_left 2 this exact Nat.one_le_two_pow lemma two_n_and_rest_factorisation (m : ℕ) (even_m : Even m) (h: 0 < m) : ∃ (l : ℕ) (m₁ : ℕ), 1 ≤ l ∧ Odd m₁ ∧ m = 2 ^ l * m₁ := by have ⟨a, ha⟩ := (pow_padicValNat_dvd : 2 ^ padicValNat 2 m ∣ m) refine ⟨padicValNat 2 m, a, ?_⟩ obtain ⟨k, hk⟩ := even_iff_two_dvd.mp even_m have hk0 : 0 < k := by omega refine ⟨?_, ?_, ha⟩ · rw [hk] rw [show 2 * k = 2^1 * k from rfl] rw [padicValNat_base_pow_mul one_lt_two hk0.ne'] exact Nat.le_add_left 1 (padicValNat 2 k) · by_contra! Ha rw [Nat.not_odd_iff_even] at Ha obtain ⟨b, hb⟩ := Ha have h3 : 2 ^ (padicValNat 2 m + 1) ∣ m := by use b rw [hb] at ha rw [pow_succ] linarith only [ha] have h4 := (Nat.pow_dvd_iff_le_padicValNat (by omega) (Nat.ne_zero_of_lt h)).mp h3 exact (lt_self_iff_false _).mp (Nat.succ_le_iff.mp h4) lemma m_mod_2_contradiction (m n A : ℕ) (even_A : Even A) (m_eq_2_mod_4 : m ≡ 2 [MOD 4]) (h : 3 * m * A = (m + 3)^n + 1) : False := by rw [← ZMod.natCast_eq_natCast_iff] at m_eq_2_mod_4 apply_fun (fun x ↦ (x : ZMod 4)) at h push_cast at h rw [m_eq_2_mod_4] at h obtain ⟨a, rfl⟩ := even_A push_cast at h rw [←two_mul] at h ring_nf at h; reduce_mod_char at h rw [one_pow n] at h simp (config := { arith := true, decide := true })at h lemma m_add_3_pow_n_mod_m (n m : ℕ) : (m + 3)^n ≡ 3^n [MOD m] := by simp [Nat.ModEq, Nat.pow_mod] lemma too_good_to_be_true (n l : ℕ) (three_le_l : 3 ≤ l) (two_pow_l_divides_expresion : 2^l ∣ (3^n + 1)) (expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8]) : False := by have : 8 ∣ 3 ^ n + 1 := by obtain ⟨a, Ha⟩ := two_pow_l_divides_expresion obtain ⟨b, Hb⟩ := Nat.exists_eq_add_of_le' three_le_l rw[Hb] at Ha dsimp [Dvd.dvd] use 2 ^ b * a rw[Ha] ring obtain ⟨a, Ha⟩ := this rw [Ha] at expression_eq_4_mod_8 dsimp[Nat.ModEq] at expression_eq_4_mod_8 simp at expression_eq_4_mod_8 lemma thue (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), (a : ZMod n) * x + y = 0 ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by -- https://services.artofproblemsolving.com/download.php?id=YXR0YWNobWVudHMvMy8yL2QzYjEzOGM0ODE3YzYwZGU4NGFmOTEwZDc0ZGNhODRjOGMyMzZlLnBkZg==&rn=dGh1ZS12NC5wZGY= -- let r = ⌊√n⌋, i.e. r is the unique integer for which -- r² ≤ n < (r + 1)². let r := Nat.sqrt n -- The number of pairs (x,y) so that 0 ≤ x,y ≤ r is (r + 1)² which -- is greater than n. -- -- Therefore there must be two different pairs (x₁, y₁) and (x₂, y₂) -- such that -- ax₁ + y₁ = ax₂ + ay₂ (mod n) -- i.e. -- a(x₁ - x₂) = y₂ - y₁ (mod n) -- let D := Fin (r + 1) × Fin (r + 1) let f : D → ZMod n := fun ⟨x,y⟩ ↦ a * (x.val : ZMod n) + (y.val : ZMod n) have cardD : Fintype.card D = (r + 1)^2 := by unfold D rw [sq, Fintype.card_prod, Fintype.card_fin] have : NeZero n := NeZero.of_gt hn have cardZ : Fintype.card (ZMod n) = n := ZMod.card n have hDZ : Fintype.card (ZMod n) < Fintype.card D := by rw [cardD, cardZ] exact Nat.lt_succ_sqrt' n obtain ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩, hxyn, hxy⟩ := Fintype.exists_ne_map_eq_of_card_lt f hDZ dsimp [f] at hxy replace hxy : (a : ZMod n) * (↑↑x₁ - ↑↑x₂) + (↑↑y₁ - ↑↑y₂) = 0 := by linear_combination hxy use (x₁ : ℤ) - (x₂ : ℤ) use (y₁ : ℤ) - (y₂ : ℤ) have hx1 : ((x₁ : ℕ): ZMod n) = (((x₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hx2 : ((x₂ : ℕ): ZMod n) = (((x₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hx3 : (((x₁ : ℕ): ℤ) : ZMod n) - (((x₂ : ℕ): ℤ) : ZMod n) = (((((x₁ : ℕ): ℤ) -((x₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast have hy1 : ((y₁ : ℕ): ZMod n) = (((y₁ : ℕ): ℤ) : ZMod n) := by norm_cast have hy2 : ((y₂ : ℕ): ZMod n) = (((y₂ : ℕ): ℤ) : ZMod n) := by norm_cast have hy3 : (((y₁ : ℕ): ℤ) : ZMod n) - (((y₂ : ℕ): ℤ) : ZMod n) = (((((y₁ : ℕ): ℤ) -((y₂ : ℕ): ℤ)) : ℤ) : ZMod n) := by norm_cast refine ⟨?_, ?_, ?_, ?_⟩ · rw [hx1, hx2, hx3, hy1, hy2, hy3] at hxy rw [hxy] · by_contra! H replace H : |((x₁:ℕ):ℤ) - ↑↑x₂| = 0 := by have : (0 : ℤ) ≤ |((x₁:ℕ):ℤ) - ↑↑x₂| := abs_nonneg _ exact (Int.le_antisymm this H).symm rw [abs_eq_zero] at H replace H : ((x₁:ℕ):ℤ) = ↑↑x₂ := Int.eq_of_sub_eq_zero H replace H : x₁.val = x₂.val := Int.ofNat_inj.mp H replace H : x₁ = x₂ := Fin.eq_of_val_eq H rw [H, sub_self, mul_zero, zero_add] at hxy have h4 : ((y₁:ℕ): ZMod n) = ↑↑y₂ := by linear_combination hxy rw [ZMod.natCast_eq_natCast_iff'] at h4 have p1 := y₁.prop have p2 := y₂.prop have : r + 1 ≤ n := by have h31 := Nat.sqrt_lt_self hn omega have h10 : y₁.val < n := by omega have h11 : y₂.val < n := by omega rw [Nat.mod_eq_of_lt h10, Nat.mod_eq_of_lt h11] at h4 have h12 : y₁ = y₂ := Fin.eq_of_val_eq h4 rw [H,h12] at hxyn simp at hxyn · have hx₁ : x₁.val < r + 1 := x₁.prop have hx₂ : x₂.val < r + 1 := x₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hx₁, hx₂, hr1] · have hy₁ : y₁.val < r + 1 := y₁.prop have hy₂ : y₂.val < r + 1 := y₂.prop have hr1 : r^2 ≤ n := Nat.sqrt_le' n nlinarith only [hy₁, hy₂, hr1] /-- In this version of Thue's lemma, we get an `x` that is nonzero and a `y` that might be zero. If we wanted to guarantee that `y` is nonzero, we would need an extra hypothesis `Nat.Coprime a n`. -/ lemma Thue's_lemma (a n : ℕ) (hn : 1 < n) : ∃ (x y : ℤ), a * x + y ≡ 0 [ZMOD n] ∧ 0 < |x| ∧ x ^ 2 ≤ n ∧ y ^ 2 ≤ n := by obtain ⟨x, y, hxay, hx, hx1, hy1⟩ := thue a n hn refine ⟨x, y, ?_, hx, hx1, hy1⟩ have h1 : (a : ZMod n) * (x : ZMod n) + (y : ZMod n) = ((((a : ℤ) * x + y):ℤ) : ZMod n) := by norm_cast have h2 : ((0:ℤ):ZMod n) = 0 := by norm_cast rw [h1, ←h2] at hxay exact (ZMod.intCast_eq_intCast_iff (a * x + y) 0 n).mp hxay example (a b n : ℕ) (ha : a < n + 1) (hb : b < n + 1) : ((a : ℤ) - (b : ℤ))^2 ≤ n^2 := by nlinarith lemma square_mod_4_zmod (x : ZMod 4) : x ^ 2 = 1 ∨ x ^ 2 = 0 := by fin_cases x <;> simp (config := { arith := true, decide := true })lemma square_mod_3_zmod_0 : ∀ {x : ZMod 3} (_ : x ^ 2 = 0), x = 0 := by decide lemma leaf_contradiction {x y m₁ : ℤ} (h: 3 * x ^ 2 + y ^ 2 = m₁) (h2 : m₁ - 5 ≡ 0 [ZMOD 6]) : False := by replace h2 : m₁ - 5 ≡ 0 [ZMOD 3] := Int.ModEq.of_mul_left 2 h2 rw [show 3 = ((3:ℕ):ℤ) by rfl] at h2 rw [← ZMod.intCast_eq_intCast_iff] at h2 apply_fun (fun x ↦ (x : ZMod 3)) at h push_cast at h h2 replace h2 : (m₁:ZMod 3) = 5 := by linear_combination h2 rw [h2] at h reduce_mod_char at h generalize hz : (y : ZMod 3) = z fin_cases z <;> rw [hz] at h <;> grind theorem bulgaria1998_p11 (m n A : ℕ) (h : 3 * m * A = (m + 3)^n + 1) : Odd A := by -- Follows the second solution in _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have ⟨⟨k, Hk⟩, m_eq_2_mod_3⟩ : Odd n ∧ m ≡ 2 [MOD 3] := n_odd_and_m_eq_2_mod_3 m n A h by_contra even_A rw [Nat.not_odd_iff_even] at even_A have zero_lt_m : 0 < m := by by_contra m_eq_0 replace m_eq_0 := not_one_le_k m_eq_0 rw [m_eq_0] at h ring_nf at h have : 1 + 3 ^ n > 0 := by positivity rw [← h] at this contradiction have even_m : Even m := by have n_ne_zero : n ≠ 0 := by omega replace evenA : (A : ZMod 2) = (0:ℕ) := by rw [Nat.even_iff] at even_A exact (ZMod.natCast_eq_natCast_iff' A 0 2).mpr even_A suffices H : (m : ZMod 2) = (0:ℕ) · rw [ZMod.natCast_eq_natCast_iff] at H exact Nat.even_iff.mpr H apply_fun (fun x ↦ (x : ZMod 2)) at h push_cast at h rw [evenA] at h simp only [Nat.cast_zero, mul_zero] at h generalize hm' : (m : ZMod 2) = m' rw [hm'] at h fin_cases m' · rfl · dsimp only [Nat.reduceAdd, Fin.mk_one, Fin.isValue] at h reduce_mod_char at h rw [zero_pow n_ne_zero, zero_add] at h exact (zero_ne_one h).elim obtain ⟨l, m₁, ⟨one_le_l, odd_m₁, m_factorisation⟩⟩ := two_n_and_rest_factorisation m even_m zero_lt_m by_cases l_eq_one : (l = 1) · rw [l_eq_one] at m_factorisation ring_nf at m_factorisation have : m₁ ≡ 1 [MOD 4] ∨ m₁ ≡ 3 [MOD 4] := by obtain ⟨a, rfl⟩ := odd_m₁ obtain ⟨b, rfl⟩ | ⟨b, rfl⟩ := Nat.even_or_odd a · left dsimp [Nat.ModEq] ring_nf simp · right dsimp [Nat.ModEq] ring_nf simp have m_eq_2_mod_4 : m ≡ 2 [MOD 4] := by rw [m_factorisation] obtain left | right := this · nth_rw 2 [show 2 = 1 * 2 by rfl] exact Nat.ModEq.mul_right _ left · calc m₁ * 2 ≡ 3 * 2 [MOD 4] := Nat.ModEq.mul right rfl _ ≡ 2 [MOD 4] := rfl exact m_mod_2_contradiction m n A even_A m_eq_2_mod_4 h · have eq_2 : 0 ≡ 3^n + 1 [MOD m] := by calc 0 ≡ m * (3 * A) [MOD m] := by rw[show 0 = 0 * (3 * A) by ring] refine Nat.ModEq.mul_right _ ?_ simp [Nat.ModEq] _ ≡ 3 * m * A [MOD m] := by rw[show m * (3 * A) = 3 * m * A by ring] _ ≡ (m + 3)^n + 1 [MOD m] := by rw[h] _ ≡ 3^n + 1 [MOD m] := by refine Nat.ModEq.add_right _ ?_ exact m_add_3_pow_n_mod_m n m have l_eq_2 : l = 2 := by have two_le_l : 2 ≤ l := by omega obtain left | right := lt_or_eq_of_le two_le_l · have two_pow_l_divides_expresion : 2 ^ l ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use m₁ * a rw[show 2 ^ l * (m₁ * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have expression_eq_4_mod_8 : 3^n + 1 ≡ 4 [MOD 8] := by rw [←ZMod.natCast_eq_natCast_iff, Hk] rw [pow_succ, pow_mul] rw[show (3 ^ 2) = 9 by rfl] push_cast reduce_mod_char rw [one_pow (M := ZMod 8) k] simp (config := { arith := true, decide := true })exfalso exact too_good_to_be_true n l (show 3 ≤ l by exact left) two_pow_l_divides_expresion expression_eq_4_mod_8 · exact right.symm have m_eq_4_m₁ : m = 4 * m₁ := by rw[l_eq_2] at m_factorisation exact m_factorisation have m₁_divides_expresion : m₁ ∣ (3^n + 1) := by have m_divides_expression : m ∣ (3 ^ n) + 1 := by exact (@Nat.modEq_zero_iff_dvd m (3^n + 1)).mp eq_2.symm dsimp[Dvd.dvd] obtain ⟨a, Ha⟩ := m_divides_expression use 2 ^ l * a rw[show m₁ * (2 ^ l * a) = (2 ^ l * m₁) * a by ring] rw[← m_factorisation] exact Ha have m₁_eq_2_mod_3 : m₁ ≡ 2 [MOD 3] := by have step_1 : 4 * m₁ ≡ 2 [MOD 3] := by rw[m_eq_4_m₁] at m_eq_2_mod_3 exact m_eq_2_mod_3 have step_2 : 4 * m₁ ≡ m₁ [MOD 3] := by nth_rw 2 [show m₁ = 1 * m₁ by ring] exact Nat.ModEq.mul rfl rfl calc m₁ ≡ 4 * m₁ [MOD 3] := step_2.symm _ ≡ 2 [MOD 3] := step_1 have m₁_eq_5_mod_6 : m₁ ≡ 5 [MOD 6] := by mod_cases m_mod_six : m₁ % 6 · have step_1: m₁ * 2 ≡ 0 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 1 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have : m₁ ≡ 1 [MOD 2] := by obtain ⟨a, Ha⟩ := odd_m₁ rw[show 1 = 0 + 1 by norm_num] rw[Ha] refine Nat.ModEq.add_right _ ?_ simp[Nat.ModEq] have step_1: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 have step_2: m₁ * 3 ≡ 1 * 3 [MOD 2 * 3] := Nat.ModEq.mul_right' 3 this change m₁ * 2 + m₁ ≡ 2 * 2 + 5 [MOD 2 * 3] at step_2 exact Nat.ModEq.add_left_cancel step_1 step_2 · have step_1: m₁ * 2 ≡ 3 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · have step_1: m₁ * 2 ≡ 4 * 2 [MOD 6]:= Nat.ModEq.mul_right 2 m_mod_six have step_2: m₁ * 2 ≡ 2 * 2 [MOD 3 * 2] := Nat.ModEq.mul_right' 2 m₁_eq_2_mod_3 simp at step_1 simp at step_2 exfalso have := Nat.ModEq.trans step_2.symm step_1 contradiction · exact m_mod_six have exists_a : ∃ a : ℕ, a = 3 ^ (k + 1) := by use 3 ^ (k + 1) obtain ⟨a, Ha⟩ := exists_a have m₁_divides_for_thues_lemma : m₁ ∣ a^2 + 3 := by apply Nat.modEq_zero_iff_dvd.mp have step_1:= Nat.modEq_zero_iff_dvd.mpr m₁_divides_expresion rw[Hk] at step_1 have step_2: 3 * (3 ^ (2 * k + 1) + 1) ≡ 3 * 0 [MOD m₁] := Nat.ModEq.mul_left 3 step_1 ring_nf at step_2 rw[show 3 ^ (k * 2) * 9 = 3 ^ ((k + 1) * 2 ) by ring] at step_2 have step_3 : 3 ^ ((k + 1) * 2) = (3 ^ (k + 1)) ^ (2) := pow_mul 3 (k + 1) 2 rw[step_3] at step_2 rw[← Ha] at step_2 ring_nf exact step_2 have hn1 : 1 < m₁ := by change _ % _ = _ % _ at m₁_eq_2_mod_3 omega obtain ⟨x, y, x_y_props⟩ := Thue's_lemma a m₁ hn1 clear hn1 obtain ⟨mod_expression, x_lower, x_higher, y_higher⟩ := x_y_props have lifted_m₁_result := Int.natCast_modEq_iff.mpr (Nat.modEq_zero_iff_dvd.mpr m₁_divides_for_thues_lemma) norm_num at lifted_m₁_result have expression : 3 * x ^ 2 + y ^ 2 ≡ 0 [ZMOD m₁] := by have step_2 : a * x ≡ -y [ZMOD m₁] := by rw [show -y = 0 - y by ring] rw [show a * x = a * x + y - y by ring] exact Int.ModEq.sub_right _ mod_expression have step_3 : a ^ 2 * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by rw [show a ^ 2 * x ^ 2 = (a * x) * (a * x) by ring] rw [show y ^ 2 = (-y) * (-y) by ring] exact Int.ModEq.mul step_2 step_2 have step_4: (-3) * x ^ 2 ≡ y ^ 2 [ZMOD m₁] := by have step_1 : a ^ 2 ≡ -3 [ZMOD m₁] := Int.ModEq.add_right_cancel' 3 lifted_m₁_result trans a ^ 2 * x ^ 2 · exact Int.ModEq.mul (step_1.symm) rfl · exact step_3 have : ((-3) * x ^ 2) + (3 * x ^ 2) ≡ (y ^ 2) + (3 * x ^ 2) [ZMOD m₁] := Int.ModEq.add_right _ step_4 rw [show (-3) * x ^ 2 + (3 * x ^ 2) = 0 by ring] at this rw [show y ^ 2 + 3 * x ^ 2 = 3 * x ^ 2 + y ^ 2 by ring] at this exact this.symm obtain ⟨s, Hs⟩ := Int.modEq_zero_iff_dvd.mp expression rw [m_eq_4_m₁] at zero_lt_m have zero_lt_m₁ : 0 < @Nat.cast ℤ _ m₁ := by omega have upper_bound_s : s ≤ 4 := by have upper_bound_expression: 3 * x ^ 2 + y ^ 2 ≤ 4 * m₁ := by omega rw [Hs] at upper_bound_expression rw [show m₁ * s = s * m₁ by ring] at upper_bound_expression exact le_of_mul_le_mul_right upper_bound_expression zero_lt_m₁ have lower_bound_s : 0 < s := by have lower_bound_expression : 0 < 3 * x ^ 2 + y ^ 2 := by have h1 : 0 < 3 * x ^ 2 := by rw [←sq_abs]; positivity exact Int.add_pos_of_pos_of_nonneg h1 (sq_nonneg y) rw [Hs] at lower_bound_expression exact Int.pos_of_mul_pos_right lower_bound_expression zero_lt_m₁ have m₁_sub_5_mod_6 : ↑m₁ - 5 ≡ 0 [ZMOD 6] := by exact Int.ModEq.sub (Int.natCast_modEq_iff.mpr m₁_eq_5_mod_6) rfl interval_cases s · -- s = 1 rw [mul_one] at Hs exact leaf_contradiction Hs m₁_sub_5_mod_6 · -- s = 2 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := sub_eq_iff_eq_add.mp this rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_4 : ((x : (ZMod 4)) ^ 2 * 3 + y ^ 2) = ((10 + c * 12) : (ZMod 4)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_4 obtain left_x | right_x := square_mod_4_zmod x · rw[left_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_x] at expression_mod_4 obtain left_y | right_y := square_mod_4_zmod y · rw[left_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · rw[right_y] at expression_mod_4 simp (config := { arith := true, decide := true })at expression_mod_4 · -- s = 3 have := Int.modEq_zero_iff_dvd.mp m₁_sub_5_mod_6 dsimp[Dvd.dvd] at this obtain ⟨c, this⟩ := this have expr_m₁_mod_6 : ↑m₁ = 6 * c + 5 := by omega rw[expr_m₁_mod_6] at Hs ring_nf at Hs have expression_mod_3 : ((x : (ZMod 3)) ^ 2 * 3 + y ^ 2) = ((15 + c * 18) : (ZMod 3)) := by norm_cast rw[Hs] reduce_mod_char at expression_mod_3 have : (y : ZMod 3) = 0 := square_mod_3_zmod_0 expression_mod_3 have := (ZMod.intCast_zmod_eq_zero_iff_dvd y 3).mp this dsimp[Dvd.dvd] at this obtain⟨y', Hy'⟩ := this rw[Hy'] at Hs ring_nf at Hs rw[show x ^ 2 * 3 + y' ^ 2 * 9 = 3 * (x ^ 2 + 3 * y' ^ 2) by ring] at Hs rw[show 15 + c * 18 = 3 * (5 + 6 * c) by ring] at Hs have reduced_expression : (x ^ 2 + 3 * y' ^ 2) = (5 + 6 * c) := by omega rw[show 5 + 6 * c = 6 * c + 5 by ring] at reduced_expression rw[← expr_m₁_mod_6] at reduced_expression rw[show x ^ 2 + 3 * y' ^ 2 = 3 * y' ^ 2 + x ^ 2 by ring] at reduced_expression exact leaf_contradiction reduced_expression m₁_sub_5_mod_6 · -- s = 4 have : y^2 < m₁ := by by_contra! H have h1 : y^2 = m₁ := (Int.le_antisymm H y_higher).symm rw [←sq_abs, Int.abs_eq_natAbs] at h1 norm_cast at h1 generalize hyy : y.natAbs = yy rw [hyy] at h1 rw [←h1] at m₁_eq_2_mod_3 mod_cases Hyy : yy % 3 <;> change _ % _ = _ % _ at Hyy m₁_eq_2_mod_3 <;> simp [Nat.pow_mod, Hyy] at m₁_eq_2_mod_3 omega end Bulgaria1998P11
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P11.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["unknown tactic", "unsolved goals\ncase neg\nm n A : \u2115\nh : 3 * m * A = (m + 3) ^ 0 + 1\nn_gt_zero : \u00acn > 0\n\u22a2 Odd n \u2227 m \u2261 2 [MOD 3]", "unknown tactic", "unsolved goals\nm : \u2115\neven_m : Even m\nh : 0 < m\na : \u2115\nha : m = 2 ^ padicValNat 2 m * a\nk : \u2115\nhk : m = 2 * k\n\u22a2 0 < k", "unsolved goals\ncase intro\nm : \u2115\neven_m : Even m\nh : 0 < m\na : \u2115\nha : m = 2 ^ padicValNat 2 m * a\nk : \u2115\nhk : m = 2 * k\nhk0 : 0 < k\n\u22a2 1 \u2264 padicValNat 2 m \u2227 Odd a \u2227 m = 2 ^ padicValNat 2 m * a", "unknown tactic", "unsolved goals\na n : \u2115\nhn : 1 < n\nr : \u2115 := n.sqrt\nD : Type := Fin (r + 1) \u00d7 Fin (r + 1)\nf : D \u2192 ZMod n :=\n fun x =>\n match x with\n | (x, y) => \u2191a * \u2191\u2191x + \u2191\u2191y\ncardD : Fintype.card D = (r + 1) ^ 2\nthis : NeZero n\ncardZ : Fintype.card (ZMod n) = n\nhDZ : Fintype.card (ZMod n) < Fintype.card D\nx\u2081 y\u2081 x\u2082 y\u2082 : Fin (r + 1)\nhxyn : (x\u2081, y\u2081) \u2260 (x\u2082, y\u2082)\nhxy : \u2191\u2191y\u2081 - \u2191\u2191y\u2082 = 0\nhx1 : \u2191\u2191x\u2081 = \u2191\u2191\u2191x\u2081\nhx2 : \u2191\u2191x\u2082 = \u2191\u2191\u2191x\u2082\nhx3 : \u2191\u2191\u2191x\u2081 - \u2191\u2191\u2191x\u2082 = \u2191(\u2191\u2191x\u2081 - \u2191\u2191x\u2082)\nhy1 : \u2191\u2191y\u2081 = \u2191\u2191\u2191y\u2081\nhy2 : \u2191\u2191y\u2082 = \u2191\u2191\u2191y\u2082\nhy3 : \u2191\u2191\u2191y\u2081 - \u2191\u2191\u2191y\u2082 = \u2191(\u2191\u2191y\u2081 - \u2191\u2191y\u2082)\nH : x\u2081 = x\u2082\nh4 : \u2191y\u2081 % n = \u2191y\u2082 % n\np1 : \u2191y\u2081 < r + 1\np2 : \u2191y\u2082 < r + 1\nh31 : n.sqrt < n\n\u22a2 r + 1 \u2264 n", "unsolved goals\ncase h.refine_2\na n : \u2115\nhn : 1 < n\nr : \u2115 := n.sqrt\nD : Type := Fin (r + 1) \u00d7 Fin (r + 1)\nf : D \u2192 ZMod n :=\n fun x =>\n match x with\n | (x, y) => \u2191a * \u2191\u2191x + \u2191\u2191y\ncardD : Fintype.card D = (r + 1) ^ 2\nthis\u271d : NeZero n\ncardZ : Fintype.card (ZMod n) = n\nhDZ : Fintype.card (ZMod n) < Fintype.card D\nx\u2081 y\u2081 x\u2082 y\u2082 : Fin (r + 1)\nhxyn : (x\u2081, y\u2081) \u2260 (x\u2082, y\u2082)\nhxy : \u2191\u2191y\u2081 - \u2191\u2191y\u2082 = 0\nhx1 : \u2191\u2191x\u2081 = \u2191\u2191\u2191x\u2081\nhx2 : \u2191\u2191x\u2082 = \u2191\u2191\u2191x\u2082\nhx3 : \u2191\u2191\u2191x\u2081 - \u2191\u2191\u2191x\u2082 = \u2191(\u2191\u2191x\u2081 - \u2191\u2191x\u2082)\nhy1 : \u2191\u2191y\u2081 = \u2191\u2191\u2191y\u2081\nhy2 : \u2191\u2191y\u2082 = \u2191\u2191\u2191y\u2082\nhy3 : \u2191\u2191\u2191y\u2081 - \u2191\u2191\u2191y\u2082 = \u2191(\u2191\u2191y\u2081 - \u2191\u2191y\u2082)\nH : x\u2081 = x\u2082\nh4 : \u2191y\u2081 % n = \u2191y\u2082 % n\np1 : \u2191y\u2081 < r + 1\np2 : \u2191y\u2082 < r + 1\nthis : r + 1 \u2264 n\n\u22a2 False", "unsolved goals\ncase h.refine_3\na n : \u2115\nhn : 1 < n\nr : \u2115 := n.sqrt\nD : Type := Fin (r + 1) \u00d7 Fin (r + 1)\nf : D \u2192 ZMod n :=\n fun x =>\n match x with\n | (x, y) => \u2191a * \u2191\u2191x + \u2191\u2191y\ncardD : Fintype.card D = (r + 1) ^ 2\nthis : NeZero n\ncardZ : Fintype.card (ZMod n) = n\nhDZ : Fintype.card (ZMod n) < Fintype.card D\nx\u2081 y\u2081 x\u2082 y\u2082 : Fin (r + 1)\nhxyn : (x\u2081, y\u2081) \u2260 (x\u2082, y\u2082)\nhxy : \u2191a * (\u2191\u2191x\u2081 - \u2191\u2191x\u2082) + (\u2191\u2191y\u2081 - \u2191\u2191y\u2082) = 0\nhx1 : \u2191\u2191x\u2081 = \u2191\u2191\u2191x\u2081\nhx2 : \u2191\u2191x\u2082 = \u2191\u2191\u2191x\u2082\nhx3 : \u2191\u2191\u2191x\u2081 - \u2191\u2191\u2191x\u2082 = \u2191(\u2191\u2191x\u2081 - \u2191\u2191x\u2082)\nhy1 : \u2191\u2191y\u2081 = \u2191\u2191\u2191y\u2081\nhy2 : \u2191\u2191y\u2082 = \u2191\u2191\u2191y\u2082\nhy3 : \u2191\u2191\u2191y\u2081 - \u2191\u2191\u2191y\u2082 = \u2191(\u2191\u2191y\u2081 - \u2191\u2191y\u2082)\n\u22a2 (\u2191\u2191x\u2081 - \u2191\u2191x\u2082) ^ 2 \u2264 \u2191n\n\ncase h.refine_4\na n : \u2115\nhn : 1 < n\nr : \u2115 := n.sqrt\nD : Type := Fin (r + 1) \u00d7 Fin (r + 1)\nf : D \u2192 ZMod n :=\n fun x =>\n match x with\n | (x, y) => \u2191a * \u2191\u2191x + \u2191\u2191y\ncardD : Fintype.card D = (r + 1) ^ 2\nthis : NeZero n\ncardZ : Fintype.card (ZMod n) = n\nhDZ : Fintype.card (ZMod n) < Fintype.card D\nx\u2081 y\u2081 x\u2082 y\u2082 : Fin (r + 1)\nhxyn : (x\u2081, y\u2081) \u2260 (x\u2082, y\u2082)\nhxy : \u2191a * (\u2191\u2191x\u2081 - \u2191\u2191x\u2082) + (\u2191\u2191y\u2081 - \u2191\u2191y\u2082) = 0\nhx1 : \u2191\u2191x\u2081 = \u2191\u2191\u2191x\u2081\nhx2 : \u2191\u2191x\u2082 = \u2191\u2191\u2191x\u2082\nhx3 : \u2191\u2191\u2191x\u2081 - \u2191\u2191\u2191x\u2082 = \u2191(\u2191\u2191x\u2081 - \u2191\u2191x\u2082)\nhy1 : \u2191\u2191y\u2081 = \u2191\u2191\u2191y\u2081\nhy2 : \u2191\u2191y\u2082 = \u2191\u2191\u2191y\u2082\nhy3 : \u2191\u2191\u2191y\u2081 - \u2191\u2191\u2191y\u2082 = \u2191(\u2191\u2191y\u2081 - \u2191\u2191y\u2082)\n\u22a2 (\u2191\u2191y\u2081 - \u2191\u2191y\u2082) ^ 2 \u2264 \u2191n", "unknown tactic", "unsolved goals\nm n A : \u2115\nh : 3 * m * A = (m + 3) ^ n + 1\nk : \u2115\nHk : n = 2 * k + 1\nm_eq_2_mod_3 : m \u2261 2 [MOD 3]\neven_A : Even A\nzero_lt_m : 0 < m\n\u22a2 n \u2260 0", "unsolved goals\nm n A : \u2115\nh : 3 * m * A = (m + 3) ^ n + 1\nk : \u2115\nHk : n = 2 * k + 1\nm_eq_2_mod_3 : m \u2261 2 [MOD 3]\neven_A : Even A\nzero_lt_m : 0 < m\nn_ne_zero : n \u2260 0\n\u22a2 Even m", "unsolved goals\nm n A : \u2115\nh : 3 * m * A = (m + 3) ^ n + 1\nk : \u2115\nHk : n = 2 * k + 1\nm_eq_2_mod_3 : m \u2261 2 [MOD 3]\neven_A : Even A\nzero_lt_m : 0 < m\neven_m : Even m\n\u22a2 False", "unexpected identifier; expected command"], "timeout_s": 600.0, "latency_s": 40.3366, "verified_at": "2026-03-26T18:16:01.505278+00:00"}}
false
true
false
40.3366
compfiles_Bulgaria1998P2
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 2 A convex quadrilateral ABCD has AD = CD and ∠DAB = ∠ABC < 90°. The line through D and the midpoint of BC intersects line AB in point E. Prove that ∠BEC = ∠DAC. (Note: The problem is valid without the assumption ∠ABC < 90°.) -/ namespace Bulgaria1998P2 open EuclideanGeometry theorem bulgaria1998_p2 (A B C D E M : EuclideanSpace ℝ (Fin 2)) (H1 : dist D A = dist D C) (H2 : ∠ D A B = ∠ A B C) (H3 : M = midpoint ℝ B C) : ∠ B E C = ∠ D A C := by let x := ∠ D A C have : ∠ D A C = ∠ D C A := EuclideanGeometry.angle_eq_angle_of_dist_eq H1 let y := ∠ C A B have : ∠ A B C = x + y := by rw [←H2]; sorry -- need to switch to oangles? sorry end Bulgaria1998P2
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 2 A convex quadrilateral ABCD has AD = CD and ∠DAB = ∠ABC < 90°. The line through D and the midpoint of BC intersects line AB in point E. Prove that ∠BEC = ∠DAC. (Note: The problem is valid without the assumption ∠ABC < 90°.) -/ namespace Bulgaria1998P2 open EuclideanGeometry theorem bulgaria1998_p2 (A B C D E M : EuclideanSpace ℝ (Fin 2)) (H1 : dist D A = dist D C) (H2 : ∠ D A B = ∠ A B C) (H3 : M = midpoint ℝ B C) : ∠ B E C = ∠ D A C := by let x := ∠ D A C have : ∠ D A C = ∠ D C A := EuclideanGeometry.angle_eq_angle_of_dist_eq H1 let y := ∠ C A B have : ∠ A B C = x + y := by rw [←H2]; sorry -- need to switch to oangles? sorry end Bulgaria1998P2
false
null
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P2.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": true, "errors": [], "timeout_s": 600.0, "latency_s": 33.2751, "verified_at": "2026-03-26T18:15:54.443933+00:00"}}
false
true
true
33.2751
compfiles_Bulgaria1998P3
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 3 Let ℝ⁺ be the set of positive real numbers. Prove that there does not exist a function f: ℝ⁺ → ℝ⁺ such that (f(x))² ≥ f(x + y) * (f(x) + y) for every x,y ∈ ℝ⁺. -/ namespace Bulgaria1998P3 lemma geom_sum_bound (n : ℕ) : ∑ i ∈ Finset.range n, (1:ℝ) / (2^i) < 3 := calc ∑ i ∈ Finset.range n, (1:ℝ) / ((2:ℝ)^i) = ∑ i ∈ Finset.range n, ((1:ℝ) / 2)^i := by {congr; simp [div_eq_mul_inv]} _ ≤ 2 := sum_geometric_two_le n _ < 3 := by norm_num theorem bulgaria1998_p3 (f : ℝ → ℝ) (hpos : ∀ x : ℝ, 0 < x → 0 < f x) (hf : (∀ x y : ℝ, 0 < x → 0 < y → (f (x + y)) * (f x + y) ≤ (f x)^2)) : False := by -- Follows the "second solution" of _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have f_decr : ∀ x y : ℝ, 0 < x → 0 < y → f (x + y) < f x := by intro x y hx hy have h1 := hf x y hx hy have h2 : 0 < f x + y := add_pos (hpos x hx) hy have h4 : f x < f x + y := lt_add_of_pos_right (f x) hy have h5 : f x / (f x + y) < 1 := (div_lt_one h2).mpr h4 calc f (x + y) = f (x + y) * 1 := (mul_one (f (x + y))).symm _ = f (x + y) * ((f x + y) / (f x + y)) := by rw [div_self (Ne.symm (ne_of_lt h2))] _ = (f (x + y) * (f x + y)) / (f x + y) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + y) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + y)) := by field_simp [pow_two] _ < f x := (mul_lt_iff_lt_one_right (hpos x hx)).mpr h5 have f_half : ∀ x : ℝ, 0 < x → f (x + f x) ≤ f x / 2 := by intro x hx have h0 := hpos x hx have h1 := hf x (f x) hx h0 have h2 : 0 < f x + f x := add_pos h0 h0 have h3 : 0 ≠ f x + f x := ne_of_lt h2 have h6: 2 * f x ≠ 0 := by positivity have h7 : (f x / (2 * f x)) = 1 / 2 := by { rw [div_eq_iff h6]; ring } calc f (x + f x) = f (x + f x) * 1 := (mul_one _).symm _ = f (x + f x) * ((f x + f x) / (f x + f x)) := by rw [div_self (Ne.symm h3)] _ = (f (x + f x) * (f x + f x)) / (f x + f x) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + f x) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + f x)) := by field_simp [pow_two] _ = (f x) * (f x / (2 * f x)) := by rw [two_mul] _ = f x / 2 := by field_simp [h7] let x_seq : ℕ → ℝ := λ n : ℕ ↦ 1 + ∑ i ∈ Finset.range n, (f 1) / (2^i) have hz : x_seq 0 = 1 := by simp only [x_seq, add_eq_left, Finset.sum_empty, Finset.range_zero] have hf1 := hpos 1 zero_lt_one have x_seq_pos : ∀ n: ℕ, 0 < x_seq n := by intro n positivity have f_x_seq: ∀ n : ℕ, f (x_seq n) ≤ f 1 / 2^n := by intro n induction n with | zero => rw [hz]; simp only [pow_zero, div_one, le_refl] | succ pn hpn => have hpp : x_seq pn.succ = x_seq pn + f 1 / 2^pn := by rw [show x_seq _ = 1 + ∑ i ∈ Finset.range _, (f 1) / (2^i) by rfl] have : ∑ i ∈ Finset.range pn.succ, f 1 / 2 ^ i = f 1 / 2 ^ pn + ∑ i ∈ Finset.range pn, f 1 / 2 ^ i := Finset.sum_range_succ_comm (λ (x : ℕ) ↦ f 1 / 2 ^ x) pn rw [this] ring have h1 : f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := by rw [hpp] obtain heq | hlt := eq_or_lt_of_le hpn · rw [heq] · have := le_of_lt (f_decr (x_seq pn + f (x_seq pn)) (f 1 / 2 ^ pn - f (x_seq pn)) (add_pos (x_seq_pos pn) (hpos (x_seq pn) (x_seq_pos pn))) (sub_pos.mpr hlt)) rw [add_add_sub_cancel] at this exact this calc f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := h1 _ ≤ f (x_seq pn) / 2 := f_half (x_seq pn) (x_seq_pos pn) _ ≤ (f 1 / 2 ^ pn) / 2 := (div_le_div_iff_of_pos_right two_pos).mpr hpn _ = f 1 / 2 ^ pn.succ := by field_simp [ne_of_gt hf1]; exact pow_succ 2 pn have h1: ∀ n: ℕ, x_seq n < 1 + 3 * f 1 := by intro n norm_num [x_seq] have : MulPosStrictMono ℝ := MulPosReflectLT.toMulPosStrictMono ℝ calc ∑ i ∈ Finset.range n, f 1 / (2:ℝ) ^ i = (∑ i ∈ Finset.range n, 1 / (2:ℝ) ^ i) * f 1 := by rw [Finset.sum_mul]; field_simp _ < 3 * f 1 := (mul_lt_mul_iff_left₀ hf1).mpr (geom_sum_bound n) have h2 : ∀ n : ℕ, 0 < 1 + 3 * f 1 - x_seq n := by intro n; linarith [h1 n] have h3 : ∀ n : ℕ, f (1 + 3 * f 1) < f 1 / 2 ^ n := by intro n calc f (1 + 3 * f 1) = f (x_seq n + (1 + 3 * f 1 - x_seq n)) := by simp only [x_seq, add_sub_add_left_eq_sub, add_add_sub_cancel] _ < f (x_seq n) := f_decr (x_seq n) _ (x_seq_pos n) (h2 n) _ ≤ f 1 / 2^n := f_x_seq n have he : ∃n : ℕ, f 1 / 2^n < f (1 + 3 * f 1) := by obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt (f 1 / f (1 + 3 * f 1)) one_lt_two use N have hp : 0 < f (1 + 3 * f 1) := hpos (1 + 3 * f 1) (lt_trans (x_seq_pos 0) (h1 0)) have h2N : (0:ℝ) < 2^N := pow_pos two_pos N exact (div_lt_iff₀ h2N).mpr ((div_lt_iff₀' hp).mp hN) obtain ⟨N, hN⟩ := he exact lt_irrefl _ (lt_trans (h3 N) hN) end Bulgaria1998P3
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 3 Let ℝ⁺ be the set of positive real numbers. Prove that there does not exist a function f: ℝ⁺ → ℝ⁺ such that (f(x))² ≥ f(x + y) * (f(x) + y) for every x,y ∈ ℝ⁺. -/ namespace Bulgaria1998P3 lemma geom_sum_bound (n : ℕ) : ∑ i ∈ Finset.range n, (1:ℝ) / (2^i) < 3 := calc ∑ i ∈ Finset.range n, (1:ℝ) / ((2:ℝ)^i) = ∑ i ∈ Finset.range n, ((1:ℝ) / 2)^i := by {congr; simp [div_eq_mul_inv]} _ ≤ 2 := sum_geometric_two_le n _ < 3 := by norm_num theorem bulgaria1998_p3 (f : ℝ → ℝ) (hpos : ∀ x : ℝ, 0 < x → 0 < f x) (hf : (∀ x y : ℝ, 0 < x → 0 < y → (f (x + y)) * (f x + y) ≤ (f x)^2)) : False := by -- Follows the "second solution" of _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have f_decr : ∀ x y : ℝ, 0 < x → 0 < y → f (x + y) < f x := by intro x y hx hy have h1 := hf x y hx hy have h2 : 0 < f x + y := add_pos (hpos x hx) hy have h4 : f x < f x + y := lt_add_of_pos_right (f x) hy have h5 : f x / (f x + y) < 1 := (div_lt_one h2).mpr h4 calc f (x + y) = f (x + y) * 1 := (mul_one (f (x + y))).symm _ = f (x + y) * ((f x + y) / (f x + y)) := by rw [div_self (Ne.symm (ne_of_lt h2))] _ = (f (x + y) * (f x + y)) / (f x + y) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + y) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + y)) := by field_simp [pow_two] _ < f x := (mul_lt_iff_lt_one_right (hpos x hx)).mpr h5 have f_half : ∀ x : ℝ, 0 < x → f (x + f x) ≤ f x / 2 := by intro x hx have h0 := hpos x hx have h1 := hf x (f x) hx h0 have h2 : 0 < f x + f x := add_pos h0 h0 have h3 : 0 ≠ f x + f x := ne_of_lt h2 have h6: 2 * f x ≠ 0 := by positivity have h7 : (f x / (2 * f x)) = 1 / 2 := by { rw [div_eq_iff h6]; ring } calc f (x + f x) = f (x + f x) * 1 := (mul_one _).symm _ = f (x + f x) * ((f x + f x) / (f x + f x)) := by rw [div_self (Ne.symm h3)] _ = (f (x + f x) * (f x + f x)) / (f x + f x) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + f x) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + f x)) := by field_simp [pow_two] _ = (f x) * (f x / (2 * f x)) := by rw [two_mul] _ = f x / 2 := by field_simp [h7] let x_seq : ℕ → ℝ := λ n : ℕ ↦ 1 + ∑ i ∈ Finset.range n, (f 1) / (2^i) have hz : x_seq 0 = 1 := by simp only [x_seq, add_eq_left, Finset.sum_empty, Finset.range_zero] have hf1 := hpos 1 zero_lt_one have x_seq_pos : ∀ n: ℕ, 0 < x_seq n := by intro n positivity have f_x_seq: ∀ n : ℕ, f (x_seq n) ≤ f 1 / 2^n := by intro n induction n with | zero => rw [hz]; simp only [pow_zero, div_one, le_refl] | succ pn hpn => have hpp : x_seq pn.succ = x_seq pn + f 1 / 2^pn := by rw [show x_seq _ = 1 + ∑ i ∈ Finset.range _, (f 1) / (2^i) by rfl] have : ∑ i ∈ Finset.range pn.succ, f 1 / 2 ^ i = f 1 / 2 ^ pn + ∑ i ∈ Finset.range pn, f 1 / 2 ^ i := Finset.sum_range_succ_comm (λ (x : ℕ) ↦ f 1 / 2 ^ x) pn rw [this] ring have h1 : f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := by rw [hpp] obtain heq | hlt := eq_or_lt_of_le hpn · rw [heq] · have := le_of_lt (f_decr (x_seq pn + f (x_seq pn)) (f 1 / 2 ^ pn - f (x_seq pn)) (add_pos (x_seq_pos pn) (hpos (x_seq pn) (x_seq_pos pn))) (sub_pos.mpr hlt)) rw [add_add_sub_cancel] at this exact this calc f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := h1 _ ≤ f (x_seq pn) / 2 := f_half (x_seq pn) (x_seq_pos pn) _ ≤ (f 1 / 2 ^ pn) / 2 := (div_le_div_iff_of_pos_right two_pos).mpr hpn _ = f 1 / 2 ^ pn.succ := by field_simp [ne_of_gt hf1]; exact pow_succ 2 pn have h1: ∀ n: ℕ, x_seq n < 1 + 3 * f 1 := by intro n norm_num [x_seq] have : MulPosStrictMono ℝ := MulPosReflectLT.toMulPosStrictMono ℝ calc ∑ i ∈ Finset.range n, f 1 / (2:ℝ) ^ i = (∑ i ∈ Finset.range n, 1 / (2:ℝ) ^ i) * f 1 := by rw [Finset.sum_mul]; field_simp _ < 3 * f 1 := (mul_lt_mul_iff_left₀ hf1).mpr (geom_sum_bound n) have h2 : ∀ n : ℕ, 0 < 1 + 3 * f 1 - x_seq n := by intro n; linarith [h1 n] have h3 : ∀ n : ℕ, f (1 + 3 * f 1) < f 1 / 2 ^ n := by intro n calc f (1 + 3 * f 1) = f (x_seq n + (1 + 3 * f 1 - x_seq n)) := by simp only [x_seq, add_sub_add_left_eq_sub, add_add_sub_cancel] _ < f (x_seq n) := f_decr (x_seq n) _ (x_seq_pos n) (h2 n) _ ≤ f 1 / 2^n := f_x_seq n have he : ∃n : ℕ, f 1 / 2^n < f (1 + 3 * f 1) := by obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt (f 1 / f (1 + 3 * f 1)) one_lt_two use N have hp : 0 < f (1 + 3 * f 1) := hpos (1 + 3 * f 1) (lt_trans (x_seq_pos 0) (h1 0)) have h2N : (0:ℝ) < 2^N := pow_pos two_pos N exact (div_lt_iff₀ h2N).mpr ((div_lt_iff₀' hp).mp hN) obtain ⟨N, hN⟩ := he exact lt_irrefl _ (lt_trans (h3 N) hN) end Bulgaria1998P3
true
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 3 Let ℝ⁺ be the set of positive real numbers. Prove that there does not exist a function f: ℝ⁺ → ℝ⁺ such that (f(x))² ≥ f(x + y) * (f(x) + y) for every x,y ∈ ℝ⁺. -/ namespace Bulgaria1998P3 lemma geom_sum_bound (n : ℕ) : ∑ i ∈ Finset.range n, (1:ℝ) / (2^i) < 3 := calc ∑ i ∈ Finset.range n, (1:ℝ) / ((2:ℝ)^i) = ∑ i ∈ Finset.range n, ((1:ℝ) / 2)^i := by {congr; simp [div_eq_mul_inv]} _ ≤ 2 := sum_geometric_two_le n _ < 3 := by norm_num theorem bulgaria1998_p3 (f : ℝ → ℝ) (hpos : ∀ x : ℝ, 0 < x → 0 < f x) (hf : (∀ x y : ℝ, 0 < x → 0 < y → (f (x + y)) * (f x + y) ≤ (f x)^2)) : False := by -- Follows the "second solution" of _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have f_decr : ∀ x y : ℝ, 0 < x → 0 < y → f (x + y) < f x := by intro x y hx hy have h1 := hf x y hx hy have h2 : 0 < f x + y := add_pos (hpos x hx) hy have h4 : f x < f x + y := lt_add_of_pos_right (f x) hy have h5 : f x / (f x + y) < 1 := (div_lt_one h2).mpr h4 calc f (x + y) = f (x + y) * 1 := (mul_one (f (x + y))).symm _ = f (x + y) * ((f x + y) / (f x + y)) := by rw [div_self (Ne.symm (ne_of_lt h2))] _ = (f (x + y) * (f x + y)) / (f x + y) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + y) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + y)) := by field_simp [pow_two] _ < f x := (mul_lt_iff_lt_one_right (hpos x hx)).mpr h5 have f_half : ∀ x : ℝ, 0 < x → f (x + f x) ≤ f x / 2 := by intro x hx have h0 := hpos x hx have h1 := hf x (f x) hx h0 have h2 : 0 < f x + f x := add_pos h0 h0 have h3 : 0 ≠ f x + f x := ne_of_lt h2 have h6: 2 * f x ≠ 0 := by positivity have h7 : (f x / (2 * f x)) = 1 / 2 := by { rw [div_eq_iff h6]; ring } calc f (x + f x) = f (x + f x) * 1 := (mul_one _).symm _ = f (x + f x) * ((f x + f x) / (f x + f x)) := by rw [div_self (Ne.symm h3)] _ = (f (x + f x) * (f x + f x)) / (f x + f x) := mul_div_assoc' _ _ _ _ ≤ (f x)^2 / (f x + f x) := (div_le_div_iff_of_pos_right h2).mpr h1 _ = (f x) * (f x / (f x + f x)) := by field_simp [pow_two] _ = (f x) * (f x / (2 * f x)) := by rw [two_mul] _ = f x / 2 := by field_simp [h7] let x_seq : ℕ → ℝ := λ n : ℕ ↦ 1 + ∑ i ∈ Finset.range n, (f 1) / (2^i) have hz : x_seq 0 = 1 := by simp only [x_seq, add_eq_left, Finset.sum_empty, Finset.range_zero] have hf1 := hpos 1 zero_lt_one have x_seq_pos : ∀ n: ℕ, 0 < x_seq n := by intro n positivity have f_x_seq: ∀ n : ℕ, f (x_seq n) ≤ f 1 / 2^n := by intro n induction n with | zero => rw [hz]; simp only [pow_zero, div_one, le_refl] | succ pn hpn => have hpp : x_seq pn.succ = x_seq pn + f 1 / 2^pn := by rw [show x_seq _ = 1 + ∑ i ∈ Finset.range _, (f 1) / (2^i) by rfl] have : ∑ i ∈ Finset.range pn.succ, f 1 / 2 ^ i = f 1 / 2 ^ pn + ∑ i ∈ Finset.range pn, f 1 / 2 ^ i := Finset.sum_range_succ_comm (λ (x : ℕ) ↦ f 1 / 2 ^ x) pn rw [this] ring have h1 : f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := by rw [hpp] obtain heq | hlt := eq_or_lt_of_le hpn · rw [heq] · have := le_of_lt (f_decr (x_seq pn + f (x_seq pn)) (f 1 / 2 ^ pn - f (x_seq pn)) (add_pos (x_seq_pos pn) (hpos (x_seq pn) (x_seq_pos pn))) (sub_pos.mpr hlt)) rw [add_add_sub_cancel] at this exact this calc f (x_seq pn.succ) ≤ f (x_seq pn + f (x_seq pn)) := h1 _ ≤ f (x_seq pn) / 2 := f_half (x_seq pn) (x_seq_pos pn) _ ≤ (f 1 / 2 ^ pn) / 2 := (div_le_div_iff_of_pos_right two_pos).mpr hpn _ = f 1 / 2 ^ pn.succ := by field_simp [ne_of_gt hf1]; exact pow_succ 2 pn have h1: ∀ n: ℕ, x_seq n < 1 + 3 * f 1 := by intro n norm_num [x_seq] have : MulPosStrictMono ℝ := MulPosReflectLT.toMulPosStrictMono ℝ calc ∑ i ∈ Finset.range n, f 1 / (2:ℝ) ^ i = (∑ i ∈ Finset.range n, 1 / (2:ℝ) ^ i) * f 1 := by rw [Finset.sum_mul]; field_simp _ < 3 * f 1 := (mul_lt_mul_iff_left₀ hf1).mpr (geom_sum_bound n) have h2 : ∀ n : ℕ, 0 < 1 + 3 * f 1 - x_seq n := by intro n; linarith [h1 n] have h3 : ∀ n : ℕ, f (1 + 3 * f 1) < f 1 / 2 ^ n := by intro n calc f (1 + 3 * f 1) = f (x_seq n + (1 + 3 * f 1 - x_seq n)) := by simp only [x_seq, add_sub_add_left_eq_sub, add_add_sub_cancel] _ < f (x_seq n) := f_decr (x_seq n) _ (x_seq_pos n) (h2 n) _ ≤ f 1 / 2^n := f_x_seq n have he : ∃n : ℕ, f 1 / 2^n < f (1 + 3 * f 1) := by obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt (f 1 / f (1 + 3 * f 1)) one_lt_two use N have hp : 0 < f (1 + 3 * f 1) := hpos (1 + 3 * f 1) (lt_trans (x_seq_pos 0) (h1 0)) have h2N : (0:ℝ) < 2^N := pow_pos two_pos N exact (div_lt_iff₀ h2N).mpr ((div_lt_iff₀' hp).mp hN) obtain ⟨N, hN⟩ := he exact lt_irrefl _ (lt_trans (h3 N) hN) end Bulgaria1998P3
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P3.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["unknown identifier 'mul_lt_mul_iff_left\u2080'"], "timeout_s": 600.0, "latency_s": 35.1685, "verified_at": "2026-03-26T18:15:56.337288+00:00"}}
false
true
false
35.1685
compfiles_Bulgaria1998P6
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 6 Prove that the equation x²y² = z²(z² - x² - y²) has no solutions in positive integers. -/ namespace Bulgaria1998P6 lemma lemma_1' (a b c : ℕ) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (h : a^4 = b^4 + c^2) : False := by induction' a using Nat.strongRecOn with a ih have hab : Nat.gcd a b = 1 := sorry obtain c_even | c_odd := Nat.even_or_odd c · have a_odd : Odd a := sorry have b_odd : Odd b := sorry sorry · sorry lemma lemma_1 {s t u : ℤ} (hs : 0 < s) (ht : 0 < t) (hu : 0 < u) (h : s^4 - t^4 = u^2) : False := by replace h : s^4 = t^4 + u^2 := eq_add_of_sub_eq' h lift s to ℕ using Int.le_of_lt hs lift t to ℕ using Int.le_of_lt ht lift u to ℕ using Int.le_of_lt hu replace hs : 0 < s := Int.natCast_pos.mp hs replace ht : 0 < t := Int.natCast_pos.mp ht replace hy : 0 < u := Int.natCast_pos.mp hu have h' : s ^ 4 = t ^ 4 + u ^ 2 := by exact Int.ofNat_inj.mp h exact lemma_1' s t u hs ht hy h' theorem bulgaria1998_p6 (x y z : ℤ) (hx : 0 < x) (hy : 0 < y) (_hz : 0 < z) (h : x^2 * y^2 = z^2 * (z^2 - x^2 - y^2)) : False := by -- Follows the informal solution in _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have h1 : 1 * (z^2 * z^2) + (- (x^2 + y^2)) * z^2 + -(x^2 * y^2) = 0 := by rw[h]; ring have : NeZero (2 : ℤ) := CharZero.NeZero.two have h2 := (quadratic_eq_zero_iff_discrim_eq_sq one_ne_zero (z^2)).mp h1 dsimp [discrim] at h2 let a := x^2 + y^2 let b := 2 * x * y have h3 : a^2 + b^2 = (2 * z ^ 2 - (x ^ 2 + y ^ 2)) ^ 2 := by linear_combination h2 have h4 : IsSquare (a^2 + b^2) := by use 2 * z ^ 2 - (x ^ 2 + y ^ 2); rwa [←sq] have h5 : IsSquare (a^2 - b^2) := by use (x^2 - y^2); ring have h6 : IsSquare ((a^2 + b^2) * (a^2 - b^2)) := IsSquare.mul h4 h5 rw [show (a^2 + b^2) * (a^2 - b^2) = a^4 - b^4 by ring] at h6 obtain ⟨c, hc⟩ := h6 rw [←sq, ←sq_abs] at hc have ha' : 0 < a := by positivity have hb' : 0 < b := by positivity have hc' : 0 < |c| := by obtain hc1 | hc2 | hc3 := lt_trichotomy 0 |c| · exact hc1 · have hab : a^2 = b^2 := by rw [← hc2, zero_pow (by norm_num)] at hc have hc3 : (a^2)^2 = (b^2)^2 := by linear_combination hc have hap : 0 ≤ a^2 := by positivity have hbp : 0 ≤ b^2 := by positivity exact (pow_left_inj₀ hap hbp two_ne_zero).mp hc3 rw [hab] at h4 obtain ⟨r, hr⟩ := h4 rw [←two_mul, ←sq] at hr have h10 : b^2 ∣ r^2 := Dvd.intro_left _ hr rw [Int.pow_dvd_pow_iff two_ne_zero] at h10 obtain ⟨e, rfl⟩ := h10 rw [show (b * e)^2 = e^2 * b^2 by ring] at hr have h11 : b^2 ≠ 0 := by positivity have h12 : 2 = e^2 := (Int.mul_eq_mul_right_iff h11).mp hr clear h h1 h3 h5 hab have h13 : e < 2 := by by_contra! H have h20 : 2^2 ≤ e^2 := by gcongr rw [←h12] at h20 norm_num at h20 have h14 : -2 < e := by by_contra! H replace H : 2 ≤ -e := Int.le_neg_of_le_neg H have h20 : 2^2 ≤ (-e)^2 := by gcongr rw [neg_sq, ←h12] at h20 norm_num at h20 interval_cases e <;> linarith · exact (Int.not_lt.mpr (abs_nonneg c) hc3).elim exact lemma_1 ha' hb' hc' hc end Bulgaria1998P6
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 6 Prove that the equation x²y² = z²(z² - x² - y²) has no solutions in positive integers. -/ namespace Bulgaria1998P6 lemma lemma_1' (a b c : ℕ) (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (h : a^4 = b^4 + c^2) : False := by induction' a using Nat.strongRecOn with a ih have hab : Nat.gcd a b = 1 := sorry obtain c_even | c_odd := Nat.even_or_odd c · have a_odd : Odd a := sorry have b_odd : Odd b := sorry sorry · sorry lemma lemma_1 {s t u : ℤ} (hs : 0 < s) (ht : 0 < t) (hu : 0 < u) (h : s^4 - t^4 = u^2) : False := by replace h : s^4 = t^4 + u^2 := eq_add_of_sub_eq' h lift s to ℕ using Int.le_of_lt hs lift t to ℕ using Int.le_of_lt ht lift u to ℕ using Int.le_of_lt hu replace hs : 0 < s := Int.natCast_pos.mp hs replace ht : 0 < t := Int.natCast_pos.mp ht replace hy : 0 < u := Int.natCast_pos.mp hu have h' : s ^ 4 = t ^ 4 + u ^ 2 := by exact Int.ofNat_inj.mp h exact lemma_1' s t u hs ht hy h' theorem bulgaria1998_p6 (x y z : ℤ) (hx : 0 < x) (hy : 0 < y) (_hz : 0 < z) (h : x^2 * y^2 = z^2 * (z^2 - x^2 - y^2)) : False := by -- Follows the informal solution in _Mathematical Olympiads 1998-1999_ -- (edited by Titu Andreescu and Zuming Feng) have h1 : 1 * (z^2 * z^2) + (- (x^2 + y^2)) * z^2 + -(x^2 * y^2) = 0 := by rw[h]; ring have : NeZero (2 : ℤ) := CharZero.NeZero.two have h2 := (quadratic_eq_zero_iff_discrim_eq_sq one_ne_zero (z^2)).mp h1 dsimp [discrim] at h2 let a := x^2 + y^2 let b := 2 * x * y have h3 : a^2 + b^2 = (2 * z ^ 2 - (x ^ 2 + y ^ 2)) ^ 2 := by linear_combination h2 have h4 : IsSquare (a^2 + b^2) := by use 2 * z ^ 2 - (x ^ 2 + y ^ 2); rwa [←sq] have h5 : IsSquare (a^2 - b^2) := by use (x^2 - y^2); ring have h6 : IsSquare ((a^2 + b^2) * (a^2 - b^2)) := IsSquare.mul h4 h5 rw [show (a^2 + b^2) * (a^2 - b^2) = a^4 - b^4 by ring] at h6 obtain ⟨c, hc⟩ := h6 rw [←sq, ←sq_abs] at hc have ha' : 0 < a := by positivity have hb' : 0 < b := by positivity have hc' : 0 < |c| := by obtain hc1 | hc2 | hc3 := lt_trichotomy 0 |c| · exact hc1 · have hab : a^2 = b^2 := by rw [← hc2, zero_pow (by norm_num)] at hc have hc3 : (a^2)^2 = (b^2)^2 := by linear_combination hc have hap : 0 ≤ a^2 := by positivity have hbp : 0 ≤ b^2 := by positivity exact (pow_left_inj₀ hap hbp two_ne_zero).mp hc3 rw [hab] at h4 obtain ⟨r, hr⟩ := h4 rw [←two_mul, ←sq] at hr have h10 : b^2 ∣ r^2 := Dvd.intro_left _ hr rw [Int.pow_dvd_pow_iff two_ne_zero] at h10 obtain ⟨e, rfl⟩ := h10 rw [show (b * e)^2 = e^2 * b^2 by ring] at hr have h11 : b^2 ≠ 0 := by positivity have h12 : 2 = e^2 := (Int.mul_eq_mul_right_iff h11).mp hr clear h h1 h3 h5 hab have h13 : e < 2 := by by_contra! H have h20 : 2^2 ≤ e^2 := by gcongr rw [←h12] at h20 norm_num at h20 have h14 : -2 < e := by by_contra! H replace H : 2 ≤ -e := Int.le_neg_of_le_neg H have h20 : 2^2 ≤ (-e)^2 := by gcongr rw [neg_sq, ←h12] at h20 norm_num at h20 interval_cases e <;> linarith · exact (Int.not_lt.mpr (abs_nonneg c) hc3).elim exact lemma_1 ha' hb' hc' hc end Bulgaria1998P6
false
null
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P6.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": true, "errors": [], "timeout_s": 600.0, "latency_s": 1.6128, "verified_at": "2026-03-26T18:15:56.056907+00:00"}}
false
true
true
1.6128
compfiles_Bulgaria1998P8
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 8 The polynomials Pₙ(x,y) for n = 1, 2, ... are defined by P₁(x,y) = 1 and Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) Prove that Pₙ(x,y) = Pₙ(y,x) for all x,y,n. -/ namespace Bulgaria1998P8 variable {R : Type} [CommRing R] def P : ℕ → R → R → R | 0, _, _ => 1 | n+1, x, y => (x + y - 1) * (y + 1) * P n x (y + 2) + (y - y^2) * P n x y /- helper function Sₙ₋₁(x,y) = [(x + y)² - 1](y + 1)(x + 1)Pₙ₋₁(y+2, x+2). -/ def S : ℕ → R → R → R | n, x, y => ((x + y)^2 - 1) * (y + 1) * (x + 1) * P n (y + 2) (x + 2) /- helper function Tₙ₋₁(x,y) = (y - y²)(x - x²)Pₙ₋₁(y, x). -/ def T : ℕ → R → R → R | n, x, y => (y - y^2) * (x - x^2) * P n y x /- helper function Uₙ₋₁(x,y) = (x + y - 1) [(y + 1)(x - x²)Pₙ₋₁(y + 2, x) + (x + 1)(y - y²) Pₙ₋₁(y, x + 2)] -/ def U : ℕ → R → R → R | n, x, y => (x + y - 1) *((y + 1)*(x - x^2) * P n (y + 2) x + (x + 1) * (y - y^2) * P n y (x + 2)) theorem bulgaria1998_p8 (n : ℕ) (x y : R) : P n x y = P n y x := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng -- We induct on n. For n = 1,2 the result is evident. -- So we take n > 1 and suppose that the result is true for -- Pₙ₋₁(x,y) and Pₙ₋₂(x,y). revert x y induction n using Nat.strong_induction_on with | h n ih => cases n with | zero => intros; rfl | succ n => cases n with | zero => intros; dsimp only [P]; ring | succ n => -- in the informal proof at this point, we're trying to -- prove the end result at n+1. -- In our formal version, that corresponds to proving the result for -- n.succ.succ /- We have Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) = (x + y - 1)(y + 1)Pₙ(y+2,x) + (y - y²)Pₙ(y,x) -/ have ih1 := ih n.succ (lt_add_one n.succ) have h1 : ∀ x y : R, P n.succ.succ x y = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by intro x y calc P (n.succ.succ) x y = (x + y - 1) * (y + 1) * (P n.succ x (y + 2)) + (y - y^2) * (P n.succ x y) := rfl _ = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by rw [ih1 x y, ih1 x (y+2)] have h2 : ∀ x y : R, (x + y - 1) * (y + 1) * P n.succ (y + 2) x = S n x y + (x + y - 1)* (y + 1) * (x - x^2)* P n (y+2) x := by intro x y; dsimp only [S, P]; ring have h_s_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, S m x y = S m y x := by intro m hm x y; dsimp only [S]; rw [ih m hm (x + 2) (y + 2)]; ring have h4 : ∀ x y : R, (y - y^2) * P n.succ y x = (y - y^2) * (x + y -1) * (x + 1) * P n y (x + 2) + T n x y := by intro x y; dsimp only [T, P]; ring have h_t_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, T m x y = T m y x := by intro m hm x y; dsimp only[T]; rw [ih m hm x y]; ring have h_u_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, U m x y = U m y x := by intro m hm x y; dsimp only [U]; rw [ih m hm (y+2) x, ih m hm (x+2) y]; ring have h7 : ∀ x y : R, P n.succ.succ x y = S n x y + T n x y + U n x y := by intro x y; rw [h1 x y, h2 x y, h4 x y]; dsimp only [U]; ring have h8 : n < n.succ := lt_add_one n have h9 : n < n.succ.succ := Nat.lt_succ_of_lt h8 intro x y calc P n.succ.succ x y = S n x y + T n x y + U n x y := h7 x y _ = S n y x + T n x y + U n x y := by rw [h_s_symm n h9 x y] _ = S n y x + T n y x + U n x y := by rw [h_t_symm n h9 x y] _ = S n y x + T n y x + U n y x := by rw [h_u_symm n h9 x y] _ = P n.succ.succ y x := (h7 y x).symm end Bulgaria1998P8
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 8 The polynomials Pₙ(x,y) for n = 1, 2, ... are defined by P₁(x,y) = 1 and Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) Prove that Pₙ(x,y) = Pₙ(y,x) for all x,y,n. -/ namespace Bulgaria1998P8 variable {R : Type} [CommRing R] def P : ℕ → R → R → R | 0, _, _ => 1 | n+1, x, y => (x + y - 1) * (y + 1) * P n x (y + 2) + (y - y^2) * P n x y /- helper function Sₙ₋₁(x,y) = [(x + y)² - 1](y + 1)(x + 1)Pₙ₋₁(y+2, x+2). -/ def S : ℕ → R → R → R | n, x, y => ((x + y)^2 - 1) * (y + 1) * (x + 1) * P n (y + 2) (x + 2) /- helper function Tₙ₋₁(x,y) = (y - y²)(x - x²)Pₙ₋₁(y, x). -/ def T : ℕ → R → R → R | n, x, y => (y - y^2) * (x - x^2) * P n y x /- helper function Uₙ₋₁(x,y) = (x + y - 1) [(y + 1)(x - x²)Pₙ₋₁(y + 2, x) + (x + 1)(y - y²) Pₙ₋₁(y, x + 2)] -/ def U : ℕ → R → R → R | n, x, y => (x + y - 1) *((y + 1)*(x - x^2) * P n (y + 2) x + (x + 1) * (y - y^2) * P n y (x + 2)) theorem bulgaria1998_p8 (n : ℕ) (x y : R) : P n x y = P n y x := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng -- We induct on n. For n = 1,2 the result is evident. -- So we take n > 1 and suppose that the result is true for -- Pₙ₋₁(x,y) and Pₙ₋₂(x,y). revert x y induction n using Nat.strong_induction_on with | h n ih => cases n with | zero => intros; rfl | succ n => cases n with | zero => intros; dsimp only [P]; ring | succ n => -- in the informal proof at this point, we're trying to -- prove the end result at n+1. -- In our formal version, that corresponds to proving the result for -- n.succ.succ /- We have Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) = (x + y - 1)(y + 1)Pₙ(y+2,x) + (y - y²)Pₙ(y,x) -/ have ih1 := ih n.succ (lt_add_one n.succ) have h1 : ∀ x y : R, P n.succ.succ x y = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by intro x y calc P (n.succ.succ) x y = (x + y - 1) * (y + 1) * (P n.succ x (y + 2)) + (y - y^2) * (P n.succ x y) := rfl _ = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by rw [ih1 x y, ih1 x (y+2)] have h2 : ∀ x y : R, (x + y - 1) * (y + 1) * P n.succ (y + 2) x = S n x y + (x + y - 1)* (y + 1) * (x - x^2)* P n (y+2) x := by intro x y; dsimp only [S, P]; ring have h_s_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, S m x y = S m y x := by intro m hm x y; dsimp only [S]; rw [ih m hm (x + 2) (y + 2)]; ring have h4 : ∀ x y : R, (y - y^2) * P n.succ y x = (y - y^2) * (x + y -1) * (x + 1) * P n y (x + 2) + T n x y := by intro x y; dsimp only [T, P]; ring have h_t_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, T m x y = T m y x := by intro m hm x y; dsimp only[T]; rw [ih m hm x y]; ring have h_u_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, U m x y = U m y x := by intro m hm x y; dsimp only [U]; rw [ih m hm (y+2) x, ih m hm (x+2) y]; ring have h7 : ∀ x y : R, P n.succ.succ x y = S n x y + T n x y + U n x y := by intro x y; rw [h1 x y, h2 x y, h4 x y]; dsimp only [U]; ring have h8 : n < n.succ := lt_add_one n have h9 : n < n.succ.succ := Nat.lt_succ_of_lt h8 intro x y calc P n.succ.succ x y = S n x y + T n x y + U n x y := h7 x y _ = S n y x + T n x y + U n x y := by rw [h_s_symm n h9 x y] _ = S n y x + T n y x + U n x y := by rw [h_t_symm n h9 x y] _ = S n y x + T n y x + U n y x := by rw [h_u_symm n h9 x y] _ = P n.succ.succ y x := (h7 y x).symm end Bulgaria1998P8
true
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Bulgarian Mathematical Olympiad 1998, Problem 8 The polynomials Pₙ(x,y) for n = 1, 2, ... are defined by P₁(x,y) = 1 and Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) Prove that Pₙ(x,y) = Pₙ(y,x) for all x,y,n. -/ namespace Bulgaria1998P8 variable {R : Type} [CommRing R] def P : ℕ → R → R → R | 0, _, _ => 1 | n+1, x, y => (x + y - 1) * (y + 1) * P n x (y + 2) + (y - y^2) * P n x y /- helper function Sₙ₋₁(x,y) = [(x + y)² - 1](y + 1)(x + 1)Pₙ₋₁(y+2, x+2). -/ def S : ℕ → R → R → R | n, x, y => ((x + y)^2 - 1) * (y + 1) * (x + 1) * P n (y + 2) (x + 2) /- helper function Tₙ₋₁(x,y) = (y - y²)(x - x²)Pₙ₋₁(y, x). -/ def T : ℕ → R → R → R | n, x, y => (y - y^2) * (x - x^2) * P n y x /- helper function Uₙ₋₁(x,y) = (x + y - 1) [(y + 1)(x - x²)Pₙ₋₁(y + 2, x) + (x + 1)(y - y²) Pₙ₋₁(y, x + 2)] -/ def U : ℕ → R → R → R | n, x, y => (x + y - 1) *((y + 1)*(x - x^2) * P n (y + 2) x + (x + 1) * (y - y^2) * P n y (x + 2)) theorem bulgaria1998_p8 (n : ℕ) (x y : R) : P n x y = P n y x := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng -- We induct on n. For n = 1,2 the result is evident. -- So we take n > 1 and suppose that the result is true for -- Pₙ₋₁(x,y) and Pₙ₋₂(x,y). revert x y induction n using Nat.strong_induction_on with | h n ih => cases n with | zero => intros; rfl | succ n => cases n with | zero => intros; dsimp only [P]; ring | succ n => -- in the informal proof at this point, we're trying to -- prove the end result at n+1. -- In our formal version, that corresponds to proving the result for -- n.succ.succ /- We have Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y) = (x + y - 1)(y + 1)Pₙ(y+2,x) + (y - y²)Pₙ(y,x) -/ have ih1 := ih n.succ (lt_add_one n.succ) have h1 : ∀ x y : R, P n.succ.succ x y = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by intro x y calc P (n.succ.succ) x y = (x + y - 1) * (y + 1) * (P n.succ x (y + 2)) + (y - y^2) * (P n.succ x y) := rfl _ = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) + (y - y^2) * (P n.succ y x) := by rw [ih1 x y, ih1 x (y+2)] have h2 : ∀ x y : R, (x + y - 1) * (y + 1) * P n.succ (y + 2) x = S n x y + (x + y - 1)* (y + 1) * (x - x^2)* P n (y+2) x := by intro x y; dsimp only [S, P]; ring have h_s_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, S m x y = S m y x := by intro m hm x y; dsimp only [S]; rw [ih m hm (x + 2) (y + 2)]; ring have h4 : ∀ x y : R, (y - y^2) * P n.succ y x = (y - y^2) * (x + y -1) * (x + 1) * P n y (x + 2) + T n x y := by intro x y; dsimp only [T, P]; ring have h_t_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, T m x y = T m y x := by intro m hm x y; dsimp only[T]; rw [ih m hm x y]; ring have h_u_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, U m x y = U m y x := by intro m hm x y; dsimp only [U]; rw [ih m hm (y+2) x, ih m hm (x+2) y]; ring have h7 : ∀ x y : R, P n.succ.succ x y = S n x y + T n x y + U n x y := by intro x y; rw [h1 x y, h2 x y, h4 x y]; dsimp only [U]; ring have h8 : n < n.succ := lt_add_one n have h9 : n < n.succ.succ := Nat.lt_succ_of_lt h8 intro x y calc P n.succ.succ x y = S n x y + T n x y + U n x y := h7 x y _ = S n y x + T n x y + U n x y := by rw [h_s_symm n h9 x y] _ = S n y x + T n y x + U n x y := by rw [h_t_symm n h9 x y] _ = S n y x + T n y x + U n y x := by rw [h_u_symm n h9 x y] _ = P n.succ.succ y x := (h7 y x).symm end Bulgaria1998P8
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Bulgaria1998P8.lean"}
{"v4.21.0": {"is_valid": true, "has_sorry": false, "errors": [], "timeout_s": 600.0, "latency_s": 1.7539, "verified_at": "2026-03-26T18:15:57.465676+00:00"}}
true
true
false
1.7539
compfiles_CIIM2022P6
compfiles
Copyright (c) 2024 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Iberoamerican Interuniversity Mathematics Competition 2022, Problem 6 Given a positive integer m, let d(m) be the number of postive divisors of m. Show that for every positive integer n, one has d((n + 1)!) ≤ 2d(n!). -/ namespace CIIM2022P6 def d : ℕ → ℕ | m => (Nat.divisors m).card theorem ciim2022_p6 (n : ℕ) (hn : 0 < n) : d (Nat.factorial (n + 1)) ≤ 2 * d (Nat.factorial n) := by sorry end CIIM2022P6
/-
/- Copyright (c) 2024 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Iberoamerican Interuniversity Mathematics Competition 2022, Problem 6 Given a positive integer m, let d(m) be the number of postive divisors of m. Show that for every positive integer n, one has d((n + 1)!) ≤ 2d(n!). -/ namespace CIIM2022P6 def d : ℕ → ℕ | m => (Nat.divisors m).card theorem ciim2022_p6 (n : ℕ) (hn : 0 < n) : d (Nat.factorial (n + 1)) ≤ 2 * d (Nat.factorial n) := by sorry end CIIM2022P6
false
null
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "CIIM2022P6.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": true, "errors": [], "timeout_s": 600.0, "latency_s": 0.0288, "verified_at": "2026-03-26T18:15:56.085817+00:00"}}
false
true
true
0.0288
compfiles_Canada1998P3
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! Canadian Mathematical Olympiad 1998, Problem 3 Let n be a natural number such that n ≥ 2. Show that (1/(n + 1))(1 + 1/3 + ... + 1/(2n - 1)) > (1/n)(1/2 + 1/4 + ... + 1/2n). -/ namespace Canada1998P3 theorem canada1998_p3 (n : ℕ) (hn : 2 ≤ n) : (1/(n:ℝ)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 2)) < (1/((n:ℝ) + 1)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 1)) := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng cases n with | zero => norm_num at hn | succ n => cases n with | zero => norm_num at hn | succ n => revert hn intro h2; clear h2 -- We prove -- (n + 1)(1/2 + 1/4 + ... + 1/2n) < n(1 + 1/3 + ... + 1/(2n - 1)) -- by induction. suffices ((n.succ.succ:ℝ) + 1) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 2)) < (n.succ.succ:ℝ) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 1)) by rw [div_mul_eq_mul_div₀, one_mul, div_mul_eq_mul_div₀, one_mul] apply (div_lt_div_iff₀ (by positivity) (by positivity)).mpr linarith induction n with | zero => -- Base case: when n = 2, we have 8/3 > 9/4. norm_num | succ m ih => let k := m.succ.succ -- Inductive case: suppose claim is true for k ≥ 2. Then we have -- k (1 + 1/3 + ... 1/(2k - 1)) > (k + 1)(1/2 + 1/4 + ... + 1/2k). -- Note that -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) -- = (1/2 + 1/3 + ... + 1/(2k-1)) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). have h1 : (1:ℝ) / (2 * ↑(0:ℕ) + 1) = 1 := by norm_num have h2 : ∀ k' ∈ Finset.range (m + 1), (1:ℝ) / (2 * ↑(k' + 1) + 1 + 1) < (1:ℝ) / (2 * ↑(k' + 1) + 1) := by intro k' _ apply div_lt_div_of_pos_left zero_lt_one · positivity · exact lt_add_one _ have h3 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h3 rw [h1, add_assoc] at h3 have h4 : Finset.Nonempty (Finset.range (m + 1)) := Finset.nonempty_range_add_one have h5 := Finset.sum_lt_sum_of_nonempty h4 h2 norm_cast at h5 have h6 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h6 have h7' : (2:ℝ) * (k:ℝ) ≥ 4 := by have hh2' : k ≥ 2 := Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le m)) have hh2 : (k:ℝ) ≥ 2 := by exact_mod_cast hh2' calc (2:ℝ) * (k:ℝ) ≥ (2:ℝ) * 2 := mul_le_mul_of_nonneg_left hh2 zero_le_two _ = 4 := by norm_num have h7 : 1 / (2 * (k:ℝ) + 2) < 1 / 2 := by apply div_lt_div₀' <;> linarith have h8 : ((k:ℝ)+1)/(2 * (k:ℝ) + 2) < ((k:ℝ)+1)/(2 * (k:ℝ) + 1) := by apply div_lt_div₀' <;> linarith have h9 := -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) calc (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) -- = (1/3 + ... + 1/(2k-1)) + (1 + (k+1)/(2k+1)) = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1)) + (1 + (k+1)/(2 * k + 1)) := by rw [←h3]; norm_cast -- TODO shouldn't need casting? -- > (1/4 + ... + 1/2k) + (1 + (k+1)/(2k+1)) _ > (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1 + (k+1)/(2 * k + 1)) := by norm_cast; linarith _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1/2 + 1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/2 + (1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/(2 *(((0:ℕ)):ℝ) + 1 + 1) + (1/2 + (k+1)/(2 * k + 1)) := by norm_num _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (1/2 + (k+1)/(2 * k + 1)) := by rw [←h6]; norm_cast -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) _ > (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + ((k+1)/(2 * k + 2) + 1/(2 * k + 2)) := by linarith -- = (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k+2)/(2 * k + 2) := by field -- -- Then we are done because -- (k + 1)(1 + 1/3 + ... + 1/(2k - 1) + 1/(2k + 1)) -- = k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1 + 1/3 + ... + 1/(2k - 1)) + (k + 1)/(2k + 1) -- > k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1/2 + 1/4 + ... + 1/2k)) + (k + 2)/(2k + 2) -- (by h9, proved above) -- > (k + 2)(1/2 + 1/4 + ... + 1/(2k + 2)). have := calc (k + 1) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 1)) = k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k + 1) / (2 * k + 1)) := by rw [Finset.sum_range_succ]; ring _ > k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_right h9 _ _ > (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_left ih _ _ = (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + (k + 2) / (2 * k + 2)) := by congr; funext x; rw [add_assoc, show (1:ℝ) + 1 = 2 by norm_num] _ = (k + 2) * ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + 1 / (2 * k + 2)) := by ring _ = (k + 2) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 2)) := by rw [←Finset.sum_range_succ] norm_cast at this norm_cast end Canada1998P3
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! Canadian Mathematical Olympiad 1998, Problem 3 Let n be a natural number such that n ≥ 2. Show that (1/(n + 1))(1 + 1/3 + ... + 1/(2n - 1)) > (1/n)(1/2 + 1/4 + ... + 1/2n). -/ namespace Canada1998P3 theorem canada1998_p3 (n : ℕ) (hn : 2 ≤ n) : (1/(n:ℝ)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 2)) < (1/((n:ℝ) + 1)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 1)) := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng cases n with | zero => norm_num at hn | succ n => cases n with | zero => norm_num at hn | succ n => revert hn intro h2; clear h2 -- We prove -- (n + 1)(1/2 + 1/4 + ... + 1/2n) < n(1 + 1/3 + ... + 1/(2n - 1)) -- by induction. suffices ((n.succ.succ:ℝ) + 1) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 2)) < (n.succ.succ:ℝ) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 1)) by rw [div_mul_eq_mul_div₀, one_mul, div_mul_eq_mul_div₀, one_mul] apply (div_lt_div_iff₀ (by positivity) (by positivity)).mpr linarith induction n with | zero => -- Base case: when n = 2, we have 8/3 > 9/4. norm_num | succ m ih => let k := m.succ.succ -- Inductive case: suppose claim is true for k ≥ 2. Then we have -- k (1 + 1/3 + ... 1/(2k - 1)) > (k + 1)(1/2 + 1/4 + ... + 1/2k). -- Note that -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) -- = (1/2 + 1/3 + ... + 1/(2k-1)) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). have h1 : (1:ℝ) / (2 * ↑(0:ℕ) + 1) = 1 := by norm_num have h2 : ∀ k' ∈ Finset.range (m + 1), (1:ℝ) / (2 * ↑(k' + 1) + 1 + 1) < (1:ℝ) / (2 * ↑(k' + 1) + 1) := by intro k' _ apply div_lt_div_of_pos_left zero_lt_one · positivity · exact lt_add_one _ have h3 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h3 rw [h1, add_assoc] at h3 have h4 : Finset.Nonempty (Finset.range (m + 1)) := Finset.nonempty_range_add_one have h5 := Finset.sum_lt_sum_of_nonempty h4 h2 norm_cast at h5 have h6 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h6 have h7' : (2:ℝ) * (k:ℝ) ≥ 4 := by have hh2' : k ≥ 2 := Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le m)) have hh2 : (k:ℝ) ≥ 2 := by exact_mod_cast hh2' calc (2:ℝ) * (k:ℝ) ≥ (2:ℝ) * 2 := mul_le_mul_of_nonneg_left hh2 zero_le_two _ = 4 := by norm_num have h7 : 1 / (2 * (k:ℝ) + 2) < 1 / 2 := by apply div_lt_div₀' <;> linarith have h8 : ((k:ℝ)+1)/(2 * (k:ℝ) + 2) < ((k:ℝ)+1)/(2 * (k:ℝ) + 1) := by apply div_lt_div₀' <;> linarith have h9 := -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) calc (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) -- = (1/3 + ... + 1/(2k-1)) + (1 + (k+1)/(2k+1)) = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1)) + (1 + (k+1)/(2 * k + 1)) := by rw [←h3]; norm_cast -- TODO shouldn't need casting? -- > (1/4 + ... + 1/2k) + (1 + (k+1)/(2k+1)) _ > (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1 + (k+1)/(2 * k + 1)) := by norm_cast; linarith _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1/2 + 1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/2 + (1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/(2 *(((0:ℕ)):ℝ) + 1 + 1) + (1/2 + (k+1)/(2 * k + 1)) := by norm_num _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (1/2 + (k+1)/(2 * k + 1)) := by rw [←h6]; norm_cast -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) _ > (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + ((k+1)/(2 * k + 2) + 1/(2 * k + 2)) := by linarith -- = (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k+2)/(2 * k + 2) := by field -- -- Then we are done because -- (k + 1)(1 + 1/3 + ... + 1/(2k - 1) + 1/(2k + 1)) -- = k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1 + 1/3 + ... + 1/(2k - 1)) + (k + 1)/(2k + 1) -- > k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1/2 + 1/4 + ... + 1/2k)) + (k + 2)/(2k + 2) -- (by h9, proved above) -- > (k + 2)(1/2 + 1/4 + ... + 1/(2k + 2)). have := calc (k + 1) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 1)) = k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k + 1) / (2 * k + 1)) := by rw [Finset.sum_range_succ]; ring _ > k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_right h9 _ _ > (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_left ih _ _ = (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + (k + 2) / (2 * k + 2)) := by congr; funext x; rw [add_assoc, show (1:ℝ) + 1 = 2 by norm_num] _ = (k + 2) * ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + 1 / (2 * k + 2)) := by ring _ = (k + 2) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 2)) := by rw [←Finset.sum_range_succ] norm_cast at this norm_cast end Canada1998P3
true
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! Canadian Mathematical Olympiad 1998, Problem 3 Let n be a natural number such that n ≥ 2. Show that (1/(n + 1))(1 + 1/3 + ... + 1/(2n - 1)) > (1/n)(1/2 + 1/4 + ... + 1/2n). -/ namespace Canada1998P3 theorem canada1998_p3 (n : ℕ) (hn : 2 ≤ n) : (1/(n:ℝ)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 2)) < (1/((n:ℝ) + 1)) * ∑ i ∈ Finset.range n, (1/(2 * (i:ℝ) + 1)) := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng cases n with | zero => norm_num at hn | succ n => cases n with | zero => norm_num at hn | succ n => revert hn intro h2; clear h2 -- We prove -- (n + 1)(1/2 + 1/4 + ... + 1/2n) < n(1 + 1/3 + ... + 1/(2n - 1)) -- by induction. suffices ((n.succ.succ:ℝ) + 1) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 2)) < (n.succ.succ:ℝ) * ∑ i ∈ Finset.range n.succ.succ, (1/(2 * (i:ℝ) + 1)) by rw [div_mul_eq_mul_div₀, one_mul, div_mul_eq_mul_div₀, one_mul] apply (div_lt_div_iff₀ (by positivity) (by positivity)).mpr linarith induction n with | zero => -- Base case: when n = 2, we have 8/3 > 9/4. norm_num | succ m ih => let k := m.succ.succ -- Inductive case: suppose claim is true for k ≥ 2. Then we have -- k (1 + 1/3 + ... 1/(2k - 1)) > (k + 1)(1/2 + 1/4 + ... + 1/2k). -- Note that -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) -- = (1/2 + 1/3 + ... + 1/(2k-1)) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + 1/2 + (k+1)/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) -- > (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). have h1 : (1:ℝ) / (2 * ↑(0:ℕ) + 1) = 1 := by norm_num have h2 : ∀ k' ∈ Finset.range (m + 1), (1:ℝ) / (2 * ↑(k' + 1) + 1 + 1) < (1:ℝ) / (2 * ↑(k' + 1) + 1) := by intro k' _ apply div_lt_div_of_pos_left zero_lt_one · positivity · exact lt_add_one _ have h3 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h3 rw [h1, add_assoc] at h3 have h4 : Finset.Nonempty (Finset.range (m + 1)) := Finset.nonempty_range_add_one have h5 := Finset.sum_lt_sum_of_nonempty h4 h2 norm_cast at h5 have h6 : (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) = _ := rfl nth_rewrite 1 [Finset.sum_range_succ'] at h6 have h7' : (2:ℝ) * (k:ℝ) ≥ 4 := by have hh2' : k ≥ 2 := Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le m)) have hh2 : (k:ℝ) ≥ 2 := by exact_mod_cast hh2' calc (2:ℝ) * (k:ℝ) ≥ (2:ℝ) * 2 := mul_le_mul_of_nonneg_left hh2 zero_le_two _ = 4 := by norm_num have h7 : 1 / (2 * (k:ℝ) + 2) < 1 / 2 := by apply div_lt_div₀' <;> linarith have h8 : ((k:ℝ)+1)/(2 * (k:ℝ) + 2) < ((k:ℝ)+1)/(2 * (k:ℝ) + 1) := by apply div_lt_div₀' <;> linarith have h9 := -- (1 + 1/3 + ... + 1/(2k-1)) + (k+1)/(2k+1) calc (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k+1)/(2 * k + 1) -- = (1/3 + ... + 1/(2k-1)) + (1 + (k+1)/(2k+1)) = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1)) + (1 + (k+1)/(2 * k + 1)) := by rw [←h3]; norm_cast -- TODO shouldn't need casting? -- > (1/4 + ... + 1/2k) + (1 + (k+1)/(2k+1)) _ > (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1 + (k+1)/(2 * k + 1)) := by norm_cast; linarith _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + (1/2 + 1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/2 + (1/2 + (k+1)/(2 * k + 1)) := by ring _ = (∑i ∈ Finset.range (m+1), 1 / (2 * ((i + 1):ℝ) + 1 + 1)) + 1/(2 *(((0:ℕ)):ℝ) + 1 + 1) + (1/2 + (k+1)/(2 * k + 1)) := by norm_num _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (1/2 + (k+1)/(2 * k + 1)) := by rw [←h6]; norm_cast -- > (1/2 + 1/4 + ... + 1/2k) + (k + 1)/(2k + 2) + 1/(2k+1) _ > (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + ((k+1)/(2 * k + 2) + 1/(2 * k + 2)) := by linarith -- = (1/2 + 1/4 + ... + 1/2k) + (k + 2)/(2k + 2). _ = (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k+2)/(2 * k + 2) := by field -- -- Then we are done because -- (k + 1)(1 + 1/3 + ... + 1/(2k - 1) + 1/(2k + 1)) -- = k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1 + 1/3 + ... + 1/(2k - 1)) + (k + 1)/(2k + 1) -- > k (1 + 1/3 + ... + 1/(2k - 1)) -- + (1/2 + 1/4 + ... + 1/2k)) + (k + 2)/(2k + 2) -- (by h9, proved above) -- > (k + 2)(1/2 + 1/4 + ... + 1/(2k + 2)). have := calc (k + 1) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 1)) = k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + (k + 1) / (2 * k + 1)) := by rw [Finset.sum_range_succ]; ring _ > k * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_right h9 _ _ > (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 1 + 1)) + (k + 2) / (2 * k + 2)) := add_lt_add_left ih _ _ = (k + 1) * (∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + (k + 2) / (2 * k + 2)) := by congr; funext x; rw [add_assoc, show (1:ℝ) + 1 = 2 by norm_num] _ = (k + 2) * ((∑i ∈ Finset.range k, 1 / (2 * (i:ℝ) + 2)) + 1 / (2 * k + 2)) := by ring _ = (k + 2) * (∑i ∈ Finset.range k.succ, 1 / (2 * (i:ℝ) + 2)) := by rw [←Finset.sum_range_succ] norm_cast at this norm_cast end Canada1998P3
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Canada1998P3.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["unknown tactic", "unknown constant 'Finset.nonempty_range_add_one'", "unsolved goals\nm : \u2115\nih :\n (\u2191m.succ.succ + 1) * \u2211 i \u2208 Finset.range m.succ.succ, 1 / (2 * \u2191i + 2) <\n \u2191m.succ.succ * \u2211 i \u2208 Finset.range m.succ.succ, 1 / (2 * \u2191i + 1)\nk : \u2115 := m.succ.succ\nh1 : 1 / (2 * \u21910 + 1) = 1\nh2 : \u2200 k' \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k' + 1) + 1 + 1) < 1 / (2 * \u2191(k' + 1) + 1)\nh3 :\n \u2211 k \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k + 1) + 1) + (1 + (\u2191k + 1) / (2 * \u2191k + 1)) =\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1) + (\u2191k + 1) / (2 * \u2191k + 1)\nh4 : (Finset.range (m + 1)).Nonempty\nh5 : \u2211 x \u2208 Finset.range (m + 1), 1 / \u2191(2 * (x + 1) + 1 + 1) < \u2211 x \u2208 Finset.range (m + 1), 1 / \u2191(2 * (x + 1) + 1)\nh6 :\n \u2211 k \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k + 1) + 1 + 1) + 1 / (2 * \u21910 + 1 + 1) =\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1 + 1)\nh7' : 2 * \u2191k \u2265 4\nh7 : 1 / (2 * \u2191k + 2) < 1 / 2\nh8 : (\u2191k + 1) / (2 * \u2191k + 2) < (\u2191k + 1) / (2 * \u2191k + 1)\n\u22a2 \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1 + 1) + ((\u2191k + 1) / (2 * \u2191k + 2) + 1 / (2 * \u2191k + 2)) =\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1 + 1) + (\u2191k + 2) / (2 * \u2191k + 2)", "unsolved goals\ncase succ.succ.succ\nm : \u2115\nih :\n (\u2191m.succ.succ + 1) * \u2211 i \u2208 Finset.range m.succ.succ, 1 / (2 * \u2191i + 2) <\n \u2191m.succ.succ * \u2211 i \u2208 Finset.range m.succ.succ, 1 / (2 * \u2191i + 1)\nk : \u2115 := m.succ.succ\nh1 : 1 / (2 * \u21910 + 1) = 1\nh2 : \u2200 k' \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k' + 1) + 1 + 1) < 1 / (2 * \u2191(k' + 1) + 1)\nh3 :\n \u2211 k \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k + 1) + 1) + (1 + (\u2191k + 1) / (2 * \u2191k + 1)) =\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1) + (\u2191k + 1) / (2 * \u2191k + 1)\nh4 : (Finset.range (m + 1)).Nonempty\nh5 : \u2211 x \u2208 Finset.range (m + 1), 1 / \u2191(2 * (x + 1) + 1 + 1) < \u2211 x \u2208 Finset.range (m + 1), 1 / \u2191(2 * (x + 1) + 1)\nh6 :\n \u2211 k \u2208 Finset.range (m + 1), 1 / (2 * \u2191(k + 1) + 1 + 1) + 1 / (2 * \u21910 + 1 + 1) =\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1 + 1)\nh7' : 2 * \u2191k \u2265 4\nh7 : 1 / (2 * \u2191k + 2) < 1 / 2\nh8 : (\u2191k + 1) / (2 * \u2191k + 2) < (\u2191k + 1) / (2 * \u2191k + 1)\nh9 :\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1) + (\u2191k + 1) / (2 * \u2191k + 1) >\n \u2211 i \u2208 Finset.range k, 1 / (2 * \u2191i + 1 + 1) + (\u2191k + 2) / (2 * \u2191k + 2)\n\u22a2 (\u2191(m + 1).succ.succ + 1) * \u2211 i \u2208 Finset.range (m + 1).succ.succ, 1 / (2 * \u2191i + 2) <\n \u2191(m + 1).succ.succ * \u2211 i \u2208 Finset.range (m + 1).succ.succ, 1 / (2 * \u2191i + 1)"], "timeout_s": 600.0, "latency_s": 5.2525, "verified_at": "2026-03-26T18:16:01.338447+00:00"}}
false
true
false
5.2525
compfiles_Canada1998P5
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! Canadian Mathematical Olympiad 1998, Problem 5 Let m be a positive integer. Define the sequence {aₙ} by a₀ = 0, a₁ = m, and aₙ₊₁ = m²aₙ - aₙ₋₁ for n ≥ 1. Prove that an ordered pair (a,b) of nonegative integers, with a ≤ b, is a solution of the equation (a² + b²) / (ab + 1) = m² if an only if (a,b) = (aₙ,aₙ₊₁) for some n ≥ 0. -/ namespace Canada1998P5 def A (m : ℕ) (hm : 0 < m) : ℕ → ℤ | 0 => 0 | 1 => (↑m) | n + 2 => (m : ℤ)^2 * A m hm (n + 1) - A m hm n theorem canada1998_p5 (m : ℕ) (hm : 0 < m) (a b : ℕ) (hab : a ≤ b) : a^2 + b^2 = m^2 * (a * b + 1) ↔ ∃ n : ℕ, (a:ℤ) = A m hm n ∧ (b:ℤ) = A m hm (n + 1) := by sorry end Canada1998P5
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! Canadian Mathematical Olympiad 1998, Problem 5 Let m be a positive integer. Define the sequence {aₙ} by a₀ = 0, a₁ = m, and aₙ₊₁ = m²aₙ - aₙ₋₁ for n ≥ 1. Prove that an ordered pair (a,b) of nonegative integers, with a ≤ b, is a solution of the equation (a² + b²) / (ab + 1) = m² if an only if (a,b) = (aₙ,aₙ₊₁) for some n ≥ 0. -/ namespace Canada1998P5 def A (m : ℕ) (hm : 0 < m) : ℕ → ℤ | 0 => 0 | 1 => (↑m) | n + 2 => (m : ℤ)^2 * A m hm (n + 1) - A m hm n theorem canada1998_p5 (m : ℕ) (hm : 0 < m) (a b : ℕ) (hab : a ≤ b) : a^2 + b^2 = m^2 * (a * b + 1) ↔ ∃ n : ℕ, (a:ℤ) = A m hm n ∧ (b:ℤ) = A m hm (n + 1) := by sorry end Canada1998P5
false
null
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Canada1998P5.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": true, "errors": [], "timeout_s": 600.0, "latency_s": 0.0672, "verified_at": "2026-03-26T18:15:56.404638+00:00"}}
false
true
true
0.0672
compfiles_Egmo2023P1
compfiles
Copyright (c) 2025 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ansar Azharov -/ import Mathlib /-! # European Girls' Mathematical Olympiad 2023, Problem 1 There are n ≥ 3 positive real numbers a_1, a_2, . . . , a_n. For each 1 ≤ i ≤ n we let b_i = (a_(i-1) + a_(i+1)) / a_i (here we define a_0 to be a_n and a_(n+1) to be a_1). Assume that for all i and j in the range 1 to n, we have a_i ≤ a_j if and only if b_i ≤ b_j. Prove that a_1 = a_2 = ... = a_n. -/ namespace Egmo2023P1 theorem egmo2023_p1 (n : ℕ) [NeZero n] (_ : n ≥ 3) (a : Fin n → ℝ) (ha : ∀ i, a i > 0) (b : Fin n → ℝ) (hb : ∀ i, b i = (a (i - 1) + a (i + 1)) / (a i)) (h : ∀ i j, a i ≤ a j ↔ b i ≤ b j) : ∀ i j, a i = a j := by -- The solution was adapted from here: https://www.youtube.com/watch?v=PNFh789P31E. -- Note that indexing starts from 0 in the formalized statement. obtain ⟨m, hm⟩ := Finite.exists_min a obtain ⟨M, hM⟩ := Finite.exists_max a have h1 : b m ≥ 2 := calc b m _ ≥ (a m + a m) / (a m) := by rw [hb m] gcongr · exact le_of_lt (ha m) · exact hm (m - 1) · exact hm (m + 1) _ ≥ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha m] have h2 : b M ≤ 2 := calc b M _ ≤ (a M + a M) / (a M) := by rw [hb M] gcongr · exact le_of_lt (ha M) · exact hM (M - 1) · exact hM (M + 1) _ ≤ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha M] have h3 : ∀ i, b i = 2 := by intro i apply eq_of_le_of_ge · exact le_trans ((h i M).mp (hM i)) h2 · exact le_trans h1 ((h m i).mp (hm i)) intro i j apply eq_of_le_of_ge · rw [h i j, h3 i, h3 j] · rw [h j i, h3 j, h3 i] end Egmo2023P1
/-
/- Copyright (c) 2025 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ansar Azharov -/ import Mathlib /-! # European Girls' Mathematical Olympiad 2023, Problem 1 There are n ≥ 3 positive real numbers a_1, a_2, . . . , a_n. For each 1 ≤ i ≤ n we let b_i = (a_(i-1) + a_(i+1)) / a_i (here we define a_0 to be a_n and a_(n+1) to be a_1). Assume that for all i and j in the range 1 to n, we have a_i ≤ a_j if and only if b_i ≤ b_j. Prove that a_1 = a_2 = ... = a_n. -/ namespace Egmo2023P1 theorem egmo2023_p1 (n : ℕ) [NeZero n] (_ : n ≥ 3) (a : Fin n → ℝ) (ha : ∀ i, a i > 0) (b : Fin n → ℝ) (hb : ∀ i, b i = (a (i - 1) + a (i + 1)) / (a i)) (h : ∀ i j, a i ≤ a j ↔ b i ≤ b j) : ∀ i j, a i = a j := by -- The solution was adapted from here: https://www.youtube.com/watch?v=PNFh789P31E. -- Note that indexing starts from 0 in the formalized statement. obtain ⟨m, hm⟩ := Finite.exists_min a obtain ⟨M, hM⟩ := Finite.exists_max a have h1 : b m ≥ 2 := calc b m _ ≥ (a m + a m) / (a m) := by rw [hb m] gcongr · exact le_of_lt (ha m) · exact hm (m - 1) · exact hm (m + 1) _ ≥ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha m] have h2 : b M ≤ 2 := calc b M _ ≤ (a M + a M) / (a M) := by rw [hb M] gcongr · exact le_of_lt (ha M) · exact hM (M - 1) · exact hM (M + 1) _ ≤ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha M] have h3 : ∀ i, b i = 2 := by intro i apply eq_of_le_of_ge · exact le_trans ((h i M).mp (hM i)) h2 · exact le_trans h1 ((h m i).mp (hm i)) intro i j apply eq_of_le_of_ge · rw [h i j, h3 i, h3 j] · rw [h j i, h3 j, h3 i] end Egmo2023P1
true
Copyright (c) 2025 The Compfiles Contributors. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ansar Azharov -/ import Mathlib /-! # European Girls' Mathematical Olympiad 2023, Problem 1 There are n ≥ 3 positive real numbers a_1, a_2, . . . , a_n. For each 1 ≤ i ≤ n we let b_i = (a_(i-1) + a_(i+1)) / a_i (here we define a_0 to be a_n and a_(n+1) to be a_1). Assume that for all i and j in the range 1 to n, we have a_i ≤ a_j if and only if b_i ≤ b_j. Prove that a_1 = a_2 = ... = a_n. -/ namespace Egmo2023P1 theorem egmo2023_p1 (n : ℕ) [NeZero n] (_ : n ≥ 3) (a : Fin n → ℝ) (ha : ∀ i, a i > 0) (b : Fin n → ℝ) (hb : ∀ i, b i = (a (i - 1) + a (i + 1)) / (a i)) (h : ∀ i j, a i ≤ a j ↔ b i ≤ b j) : ∀ i j, a i = a j := by -- The solution was adapted from here: https://www.youtube.com/watch?v=PNFh789P31E. -- Note that indexing starts from 0 in the formalized statement. obtain ⟨m, hm⟩ := Finite.exists_min a obtain ⟨M, hM⟩ := Finite.exists_max a have h1 : b m ≥ 2 := calc b m _ ≥ (a m + a m) / (a m) := by rw [hb m] gcongr · exact le_of_lt (ha m) · exact hm (m - 1) · exact hm (m + 1) _ ≥ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha m] have h2 : b M ≤ 2 := calc b M _ ≤ (a M + a M) / (a M) := by rw [hb M] gcongr · exact le_of_lt (ha M) · exact hM (M - 1) · exact hM (M + 1) _ ≤ 2 := by rw [← two_mul, mul_div_cancel_right₀] positivity [ha M] have h3 : ∀ i, b i = 2 := by intro i apply eq_of_le_of_ge · exact le_trans ((h i M).mp (hM i)) h2 · exact le_trans h1 ((h m i).mp (hm i)) intro i j apply eq_of_le_of_ge · rw [h i j, h3 i, h3 j] · rw [h j i, h3 j, h3 i] end Egmo2023P1
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Egmo2023P1.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["failed to prove positivity/nonnegativity/nonzeroness", "unsolved goals\ncase intro.intro\nn : \u2115\ninst\u271d : NeZero n\nx\u271d : n \u2265 3\na : Fin n \u2192 \u211d\nha : \u2200 (i : Fin n), a i > 0\nb : Fin n \u2192 \u211d\nhb : \u2200 (i : Fin n), b i = (a (i - 1) + a (i + 1)) / a i\nh : \u2200 (i j : Fin n), a i \u2264 a j \u2194 b i \u2264 b j\nm : Fin n\nhm : \u2200 (x : Fin n), a m \u2264 a x\nM : Fin n\nhM : \u2200 (x : Fin n), a x \u2264 a M\nh1 : b m \u2265 2\n\u22a2 \u2200 (i j : Fin n), a i = a j", "unexpected token '['; expected command"], "timeout_s": 600.0, "latency_s": 0.2509, "verified_at": "2026-03-26T18:15:56.655693+00:00"}}
false
true
false
0.2509
compfiles_Hungary1998P6
compfiles
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Hungarian Mathematical Olympiad 1998, Problem 6 Let x, y, z be integers with z > 1. Show that (x + 1)² + (x + 2)² + ... + (x + 99)² ≠ yᶻ. -/ namespace Hungary1998P6 lemma sum_range_square_mul_six (n : ℕ) : (∑i ∈ Finset.range n, (i + 1)^2) * 6 = n * (n + 1) * (2 * n + 1) := by induction n with | zero => rfl | succ n ih => rw [Finset.sum_range_succ, add_mul, ih] ring lemma sum_range_square (n : ℕ) : ∑i ∈ Finset.range n, (i + 1)^2 = n * (n + 1) * (2 * n + 1)/6 := by rw [← sum_range_square_mul_six n, Nat.mul_div_cancel] norm_num lemma cast_sum_square (n : ℕ) : ∑i ∈ Finset.range n, ((i:ℤ)+1)^2 = (((∑i ∈ Finset.range n, (i+1)^2) : ℕ) : ℤ) := by norm_cast theorem hungary1998_p6 (x y : ℤ) (z : ℕ) (hz : 1 < z) : ∑ i ∈ Finset.range 99, (x + i + 1)^2 ≠ y^z := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng. -- Suppose (x + 1)² + (x + 2)² + ... + (x + 99)² = yᶻ. intro he -- We notice that -- y^z = (x + 1)² + (x + 2)² + ... + (x + 99)² -- = 99x² + 2(1 + 2 + ... + 99)x + (1² + 2² + ... + 99²) -- = 99x² + 2[(99 ⬝ 100)/2]x + (99 ⬝ 100 ⬝ 199)/6 -- = 33(3x² + 300x + 50 ⬝ 199). have h2 : ∑ i ∈ Finset.range 99, x^2 = 99 * x^2 := by norm_num have h4 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1) = ∑ i ∈ Finset.range 100, (i:ℤ) := by rw [Finset.sum_range_succ'] simp [Finset.sum_range_succ] have h5 : ∑ i ∈ Finset.range 100, (i:ℤ) = 99 * 100 / 2 := by rw [←Nat.cast_sum, Finset.sum_range_id]; decide have h6 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 = (99 * 100 * 199)/6 := by rw [cast_sum_square, sum_range_square]; decide have hnn1 : (99:ℤ) * 100 / 2 = 99 * 50 := by decide have hnn2 : ((99:ℤ) * 100 * 199)/6 = 33 * 50 * 199 := by decide have h7 := calc y^z = ∑ i ∈ Finset.range 99, ((x + i) + 1)^2 := he.symm _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1) + ((i:ℤ) + 1)^2) := by with_reducible congr; funext; ring _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 := Finset.sum_add_distrib _ = ∑ i ∈ Finset.range 99, x^2 + ∑ i ∈ Finset.range 99, (2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, (((i:ℤ) + 1)^2) := by rw [Finset.sum_add_distrib] _ = 99 * x^2 + 2 * x * (99 * 100 / 2) + (99 * 100 * 199)/6 := by rw [h2, ←Finset.mul_sum, h4, h5, h6] _ = 3 * (11 * (3 * x^2 + 300 * x + 50 * 199)) := by rw [hnn1, hnn2]; ring -- which implies that 3∣y. have h8 : 3 ∣ y^z := Dvd.intro _ (Eq.symm h7) have h9 : 3 ∣ y := Prime.dvd_of_dvd_pow Int.prime_three h8 obtain ⟨k, hk⟩ := h9 rw [hk] at h7 cases z with | zero => exact Nat.not_lt_zero 1 hz | succ z => cases z with | zero => exact Nat.lt_asymm hz hz | succ z => rw [pow_succ, pow_succ] at h7 -- Since z ≥ 2, 3²∣yᶻ, but 3² does not divide -- 33(3x² + 300x + 50 ⬝ 199), contradiction. omega end Hungary1998P6
/-
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Hungarian Mathematical Olympiad 1998, Problem 6 Let x, y, z be integers with z > 1. Show that (x + 1)² + (x + 2)² + ... + (x + 99)² ≠ yᶻ. -/ namespace Hungary1998P6 lemma sum_range_square_mul_six (n : ℕ) : (∑i ∈ Finset.range n, (i + 1)^2) * 6 = n * (n + 1) * (2 * n + 1) := by induction n with | zero => rfl | succ n ih => rw [Finset.sum_range_succ, add_mul, ih] ring lemma sum_range_square (n : ℕ) : ∑i ∈ Finset.range n, (i + 1)^2 = n * (n + 1) * (2 * n + 1)/6 := by rw [← sum_range_square_mul_six n, Nat.mul_div_cancel] norm_num lemma cast_sum_square (n : ℕ) : ∑i ∈ Finset.range n, ((i:ℤ)+1)^2 = (((∑i ∈ Finset.range n, (i+1)^2) : ℕ) : ℤ) := by norm_cast theorem hungary1998_p6 (x y : ℤ) (z : ℕ) (hz : 1 < z) : ∑ i ∈ Finset.range 99, (x + i + 1)^2 ≠ y^z := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng. -- Suppose (x + 1)² + (x + 2)² + ... + (x + 99)² = yᶻ. intro he -- We notice that -- y^z = (x + 1)² + (x + 2)² + ... + (x + 99)² -- = 99x² + 2(1 + 2 + ... + 99)x + (1² + 2² + ... + 99²) -- = 99x² + 2[(99 ⬝ 100)/2]x + (99 ⬝ 100 ⬝ 199)/6 -- = 33(3x² + 300x + 50 ⬝ 199). have h2 : ∑ i ∈ Finset.range 99, x^2 = 99 * x^2 := by norm_num have h4 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1) = ∑ i ∈ Finset.range 100, (i:ℤ) := by rw [Finset.sum_range_succ'] simp [Finset.sum_range_succ] have h5 : ∑ i ∈ Finset.range 100, (i:ℤ) = 99 * 100 / 2 := by rw [←Nat.cast_sum, Finset.sum_range_id]; decide have h6 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 = (99 * 100 * 199)/6 := by rw [cast_sum_square, sum_range_square]; decide have hnn1 : (99:ℤ) * 100 / 2 = 99 * 50 := by decide have hnn2 : ((99:ℤ) * 100 * 199)/6 = 33 * 50 * 199 := by decide have h7 := calc y^z = ∑ i ∈ Finset.range 99, ((x + i) + 1)^2 := he.symm _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1) + ((i:ℤ) + 1)^2) := by with_reducible congr; funext; ring _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 := Finset.sum_add_distrib _ = ∑ i ∈ Finset.range 99, x^2 + ∑ i ∈ Finset.range 99, (2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, (((i:ℤ) + 1)^2) := by rw [Finset.sum_add_distrib] _ = 99 * x^2 + 2 * x * (99 * 100 / 2) + (99 * 100 * 199)/6 := by rw [h2, ←Finset.mul_sum, h4, h5, h6] _ = 3 * (11 * (3 * x^2 + 300 * x + 50 * 199)) := by rw [hnn1, hnn2]; ring -- which implies that 3∣y. have h8 : 3 ∣ y^z := Dvd.intro _ (Eq.symm h7) have h9 : 3 ∣ y := Prime.dvd_of_dvd_pow Int.prime_three h8 obtain ⟨k, hk⟩ := h9 rw [hk] at h7 cases z with | zero => exact Nat.not_lt_zero 1 hz | succ z => cases z with | zero => exact Nat.lt_asymm hz hz | succ z => rw [pow_succ, pow_succ] at h7 -- Since z ≥ 2, 3²∣yᶻ, but 3² does not divide -- 33(3x² + 300x + 50 ⬝ 199), contradiction. omega end Hungary1998P6
true
Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Mathlib /-! # Hungarian Mathematical Olympiad 1998, Problem 6 Let x, y, z be integers with z > 1. Show that (x + 1)² + (x + 2)² + ... + (x + 99)² ≠ yᶻ. -/ namespace Hungary1998P6 lemma sum_range_square_mul_six (n : ℕ) : (∑i ∈ Finset.range n, (i + 1)^2) * 6 = n * (n + 1) * (2 * n + 1) := by induction n with | zero => rfl | succ n ih => rw [Finset.sum_range_succ, add_mul, ih] ring lemma sum_range_square (n : ℕ) : ∑i ∈ Finset.range n, (i + 1)^2 = n * (n + 1) * (2 * n + 1)/6 := by rw [← sum_range_square_mul_six n, Nat.mul_div_cancel] norm_num lemma cast_sum_square (n : ℕ) : ∑i ∈ Finset.range n, ((i:ℤ)+1)^2 = (((∑i ∈ Finset.range n, (i+1)^2) : ℕ) : ℤ) := by norm_cast theorem hungary1998_p6 (x y : ℤ) (z : ℕ) (hz : 1 < z) : ∑ i ∈ Finset.range 99, (x + i + 1)^2 ≠ y^z := by -- Follows the proof in _Mathematical Olympiads 1998-1999_ -- by Titu Andreescu and Zuming Feng. -- Suppose (x + 1)² + (x + 2)² + ... + (x + 99)² = yᶻ. intro he -- We notice that -- y^z = (x + 1)² + (x + 2)² + ... + (x + 99)² -- = 99x² + 2(1 + 2 + ... + 99)x + (1² + 2² + ... + 99²) -- = 99x² + 2[(99 ⬝ 100)/2]x + (99 ⬝ 100 ⬝ 199)/6 -- = 33(3x² + 300x + 50 ⬝ 199). have h2 : ∑ i ∈ Finset.range 99, x^2 = 99 * x^2 := by norm_num have h4 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1) = ∑ i ∈ Finset.range 100, (i:ℤ) := by rw [Finset.sum_range_succ'] simp [Finset.sum_range_succ] have h5 : ∑ i ∈ Finset.range 100, (i:ℤ) = 99 * 100 / 2 := by rw [←Nat.cast_sum, Finset.sum_range_id]; decide have h6 : ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 = (99 * 100 * 199)/6 := by rw [cast_sum_square, sum_range_square]; decide have hnn1 : (99:ℤ) * 100 / 2 = 99 * 50 := by decide have hnn2 : ((99:ℤ) * 100 * 199)/6 = 33 * 50 * 199 := by decide have h7 := calc y^z = ∑ i ∈ Finset.range 99, ((x + i) + 1)^2 := he.symm _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1) + ((i:ℤ) + 1)^2) := by with_reducible congr; funext; ring _ = ∑ i ∈ Finset.range 99, (x^2 + 2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, ((i:ℤ) + 1)^2 := Finset.sum_add_distrib _ = ∑ i ∈ Finset.range 99, x^2 + ∑ i ∈ Finset.range 99, (2 * x * ((i:ℤ) + 1)) + ∑ i ∈ Finset.range 99, (((i:ℤ) + 1)^2) := by rw [Finset.sum_add_distrib] _ = 99 * x^2 + 2 * x * (99 * 100 / 2) + (99 * 100 * 199)/6 := by rw [h2, ←Finset.mul_sum, h4, h5, h6] _ = 3 * (11 * (3 * x^2 + 300 * x + 50 * 199)) := by rw [hnn1, hnn2]; ring -- which implies that 3∣y. have h8 : 3 ∣ y^z := Dvd.intro _ (Eq.symm h7) have h9 : 3 ∣ y := Prime.dvd_of_dvd_pow Int.prime_three h8 obtain ⟨k, hk⟩ := h9 rw [hk] at h7 cases z with | zero => exact Nat.not_lt_zero 1 hz | succ z => cases z with | zero => exact Nat.lt_asymm hz hz | succ z => rw [pow_succ, pow_succ] at h7 -- Since z ≥ 2, 3²∣yᶻ, but 3² does not divide -- 33(3x² + 300x + 50 ⬝ 199), contradiction. omega end Hungary1998P6
null
v4.29.0-rc6
test
[ "competition" ]
null
{"filename": "Hungary1998P6.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["unknown tactic", "unsolved goals\ncase intro.succ.succ\nx y : \u2124\nh2 : \u2211 i \u2208 Finset.range 99, x ^ 2 = 99 * x ^ 2\nh4 : \u2211 i \u2208 Finset.range 99, (\u2191i + 1) = \u2211 i \u2208 Finset.range 100, \u2191i\nh5 : \u2211 i \u2208 Finset.range 100, \u2191i = 99 * 100 / 2\nh6 : \u2211 i \u2208 Finset.range 99, (\u2191i + 1) ^ 2 = 99 * 100 * 199 / 6\nhnn1 : 99 * 100 / 2 = 99 * 50\nhnn2 : 99 * 100 * 199 / 6 = 33 * 50 * 199\nk : \u2124\nhk : y = 3 * k\nz : \u2115\nhz : 1 < z + 1 + 1\nhe : \u2211 i \u2208 Finset.range 99, (x + \u2191i + 1) ^ 2 = y ^ (z + 1 + 1)\nh8 : 3 \u2223 y ^ (z + 1 + 1)\nh7 : (3 * k) ^ z * (3 * k) * (3 * k) = 3 * (11 * (3 * x ^ 2 + 300 * x + 50 * 199))\n\u22a2 False"], "timeout_s": 600.0, "latency_s": 1.7075, "verified_at": "2026-03-26T18:15:58.363303+00:00"}}
false
true
false
1.7075
compfiles_Imo1959P1
compfiles
Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 1. Prove that the fraction `(21n+4)/(14n+3)` is irreducible for every natural number `n`. -/ namespace Imo1959P1 lemma calculation (n k : ℕ) (h1 : k ∣ 21 * n + 4) (h2 : k ∣ 14 * n + 3) : k ∣ 1 := by have h3 : k ∣ 2 * (21 * n + 4) := h1.mul_left 2 have h4 : k ∣ 3 * (14 * n + 3) := h2.mul_left 3 have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1 := by ring exact (Nat.dvd_add_right h3).mp (h5 ▸ h4) /- Since Lean doesn't have a concept of "irreducible fractions" per se, we just formalize this as saying the numerator and denominator are relatively prime. -/ theorem imo1959_p1 : ∀ n : ℕ, Nat.Coprime (21 * n + 4) (14 * n + 3) := fun n => Nat.coprime_of_dvd' <| λ k _ h1 h2 => calculation n k h1 h2 end Imo1959P1
/-
/- Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 1. Prove that the fraction `(21n+4)/(14n+3)` is irreducible for every natural number `n`. -/ namespace Imo1959P1 lemma calculation (n k : ℕ) (h1 : k ∣ 21 * n + 4) (h2 : k ∣ 14 * n + 3) : k ∣ 1 := by have h3 : k ∣ 2 * (21 * n + 4) := h1.mul_left 2 have h4 : k ∣ 3 * (14 * n + 3) := h2.mul_left 3 have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1 := by ring exact (Nat.dvd_add_right h3).mp (h5 ▸ h4) /- Since Lean doesn't have a concept of "irreducible fractions" per se, we just formalize this as saying the numerator and denominator are relatively prime. -/ theorem imo1959_p1 : ∀ n : ℕ, Nat.Coprime (21 * n + 4) (14 * n + 3) := fun n => Nat.coprime_of_dvd' <| λ k _ h1 h2 => calculation n k h1 h2 end Imo1959P1
true
Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 1. Prove that the fraction `(21n+4)/(14n+3)` is irreducible for every natural number `n`. -/ namespace Imo1959P1 lemma calculation (n k : ℕ) (h1 : k ∣ 21 * n + 4) (h2 : k ∣ 14 * n + 3) : k ∣ 1 := by have h3 : k ∣ 2 * (21 * n + 4) := h1.mul_left 2 have h4 : k ∣ 3 * (14 * n + 3) := h2.mul_left 3 have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1 := by ring exact (Nat.dvd_add_right h3).mp (h5 ▸ h4) /- Since Lean doesn't have a concept of "irreducible fractions" per se, we just formalize this as saying the numerator and denominator are relatively prime. -/ theorem imo1959_p1 : ∀ n : ℕ, Nat.Coprime (21 * n + 4) (14 * n + 3) := fun n => Nat.coprime_of_dvd' <| λ k _ h1 h2 => calculation n k h1 h2 end Imo1959P1
null
v4.29.0-rc6
test
[ "competition", "imo" ]
null
{"filename": "Imo1959P1.lean"}
{"v4.21.0": {"is_valid": true, "has_sorry": false, "errors": [], "timeout_s": 600.0, "latency_s": 0.0842, "verified_at": "2026-03-26T18:15:57.549955+00:00"}}
true
true
false
0.0842
compfiles_Imo1959P2
compfiles
Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 2 For what real values of x is √(x+√(2x-1)) + √(x-√(2x-1)) = A, given: (a) A = √2 (b) A = 1 (c) A = 2, where only non-negative real numbers are admitted for square roots? -/ open Set Real namespace Imo1959P2 def IsGood (x A : ℝ) : Prop := sqrt (x + sqrt (2 * x - 1)) + sqrt (x - sqrt (2 * x - 1)) = A ∧ 0 ≤ 2 * x - 1 ∧ 0 ≤ x + sqrt (2 * x - 1) ∧ 0 ≤ x - sqrt (2 * x - 1) variable {x A : ℝ} /- We follow second solution from the [Art of Problem Solving](https://artofproblemsolving.com/wiki/index.php/1959_IMO_Problems/Problem_2) website. Namely, we rewrite the equation as $\sqrt{2x-1}+1+|\sqrt{2x-1}-1|=A\sqrt{2}$, then consider the cases $\sqrt{2x-1}\le 1$ and $1 < \sqrt{2x-1}$ separately. -/ theorem isGood_iff : IsGood x A ↔ sqrt (2 * x - 1) + 1 + |sqrt (2 * x - 1) - 1| = A * sqrt 2 ∧ 1 / 2 ≤ x := by cases le_or_gt (1 / 2) x with | inl hx => have hx' : 0 ≤ 2 * x - 1 := by linarith have h₁ : x + sqrt (2 * x - 1) = (sqrt (2 * x - 1) + 1) ^ 2 / 2 := by rw [add_sq, sq_sqrt hx']; field_simp; ring have h₂ : x - sqrt (2 * x - 1) = (sqrt (2 * x - 1) - 1) ^ 2 / 2 := by rw [sub_sq, sq_sqrt hx']; field_simp; ring simp only [IsGood, *, div_nonneg (sq_nonneg _) (zero_le_two (α := ℝ)), sqrt_div (sq_nonneg _), and_true] rw [sqrt_sq, sqrt_sq_eq_abs] <;> [skip; positivity] field_simp | inr hx => have : 2 * x - 1 < 0 := by linarith simp only [IsGood, this.not_ge, hx.not_ge]; simp theorem IsGood.one_half_le (h : IsGood x A) : 1 / 2 ≤ x := (isGood_iff.1 h).2 theorem sqrt_two_mul_sub_one_le_one : sqrt (2 * x - 1) ≤ 1 ↔ x ≤ 1 := by simp [sqrt_le_iff, ← two_mul] theorem isGood_iff_eq_sqrt_two (hx : x ∈ Icc (1 / 2) 1) : IsGood x A ↔ A = sqrt 2 := by have : sqrt (2 * x - 1) ≤ 1 := sqrt_two_mul_sub_one_le_one.2 hx.2 simp only [isGood_iff, hx.1, abs_sub_comm _ (1 : ℝ), abs_of_nonneg (sub_nonneg.2 this), and_true] suffices 2 = A * sqrt 2 ↔ A = sqrt 2 by convert this using 2; ring rw [← div_eq_iff, div_sqrt, eq_comm] positivity theorem isGood_iff_eq_sqrt (hx : 1 < x) : IsGood x A ↔ A = sqrt (4 * x - 2) := by have h₁ : 1 < sqrt (2 * x - 1) := by simpa only [← not_le, sqrt_two_mul_sub_one_le_one] using hx have h₂ : 1 / 2 ≤ x := by linarith simp only [isGood_iff, h₂, abs_of_pos (sub_pos.2 h₁), add_add_sub_cancel, and_true] rw [← mul_two, ← div_eq_iff (by positivity), mul_div_assoc, div_sqrt, ← sqrt_mul' _ zero_le_two, eq_comm] ring_nf theorem IsGood.sqrt_two_lt_of_one_lt (h : IsGood x A) (hx : 1 < x) : sqrt 2 < A := by rw [(isGood_iff_eq_sqrt hx).1 h] refine sqrt_lt_sqrt zero_le_two ?_ linarith theorem IsGood.eq_sqrt_two_iff_le_one (h : IsGood x A) : A = sqrt 2 ↔ x ≤ 1 := ⟨fun hA ↦ not_lt.1 fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).ne' hA, fun hx ↦ (isGood_iff_eq_sqrt_two ⟨h.one_half_le, hx⟩).1 h⟩ theorem IsGood.sqrt_two_lt_iff_one_lt (h : IsGood x A) : sqrt 2 < A ↔ 1 < x := ⟨fun hA ↦ not_le.1 fun hx ↦ hA.ne' <| h.eq_sqrt_two_iff_le_one.2 hx, h.sqrt_two_lt_of_one_lt⟩ theorem IsGood.sqrt_two_le (h : IsGood x A) : sqrt 2 ≤ A := (le_or_gt x 1).elim (fun hx ↦ (h.eq_sqrt_two_iff_le_one.2 hx).ge) fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).le theorem isGood_iff_of_sqrt_two_lt (hA : sqrt 2 < A) : IsGood x A ↔ x = (A / 2) ^ 2 + 1 / 2 := by have : 0 < A := lt_trans (by simp) hA constructor · intro h have hx : 1 < x := by rwa [h.sqrt_two_lt_iff_one_lt] at hA rw [isGood_iff_eq_sqrt hx, eq_comm, sqrt_eq_iff_eq_sq] at h <;> linarith · rintro rfl rw [isGood_iff_eq_sqrt] · conv_lhs => rw [← sqrt_sq this.le] ring_nf · rw [sqrt_lt' this] at hA linarith abbrev solution_set_sqrt2 : Set ℝ := Icc (1 / 2) 1 theorem imo1959_p2a : IsGood x (sqrt 2) ↔ x ∈ solution_set_sqrt2 := by refine ⟨fun h ↦ ?_, fun h ↦ (isGood_iff_eq_sqrt_two h).2 rfl⟩ exact ⟨h.one_half_le, not_lt.1 fun h₁ ↦ (h.sqrt_two_lt_of_one_lt h₁).false⟩ abbrev solution_set_one : Set ℝ := ∅ theorem imo1959_p2b : IsGood x 1 ↔ x ∈ solution_set_one := by have not_isGood_one : ¬IsGood x 1 := fun h ↦ h.sqrt_two_le.not_gt <| (lt_sqrt zero_le_one).2 (by norm_num) exact iff_of_false not_isGood_one fun a ↦ a abbrev solution_set_two : Set ℝ := { 3 / 2 } theorem imo1959_p2c : IsGood x 2 ↔ x ∈ solution_set_two := by rw [mem_singleton_iff] exact (isGood_iff_of_sqrt_two_lt <| (sqrt_lt' two_pos).2 (by norm_num)).trans <| by norm_num end Imo1959P2
/-
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 2 For what real values of x is √(x+√(2x-1)) + √(x-√(2x-1)) = A, given: (a) A = √2 (b) A = 1 (c) A = 2, where only non-negative real numbers are admitted for square roots? -/ open Set Real namespace Imo1959P2 def IsGood (x A : ℝ) : Prop := sqrt (x + sqrt (2 * x - 1)) + sqrt (x - sqrt (2 * x - 1)) = A ∧ 0 ≤ 2 * x - 1 ∧ 0 ≤ x + sqrt (2 * x - 1) ∧ 0 ≤ x - sqrt (2 * x - 1) variable {x A : ℝ} /- We follow second solution from the [Art of Problem Solving](https://artofproblemsolving.com/wiki/index.php/1959_IMO_Problems/Problem_2) website. Namely, we rewrite the equation as $\sqrt{2x-1}+1+|\sqrt{2x-1}-1|=A\sqrt{2}$, then consider the cases $\sqrt{2x-1}\le 1$ and $1 < \sqrt{2x-1}$ separately. -/ theorem isGood_iff : IsGood x A ↔ sqrt (2 * x - 1) + 1 + |sqrt (2 * x - 1) - 1| = A * sqrt 2 ∧ 1 / 2 ≤ x := by cases le_or_gt (1 / 2) x with | inl hx => have hx' : 0 ≤ 2 * x - 1 := by linarith have h₁ : x + sqrt (2 * x - 1) = (sqrt (2 * x - 1) + 1) ^ 2 / 2 := by rw [add_sq, sq_sqrt hx']; field_simp; ring have h₂ : x - sqrt (2 * x - 1) = (sqrt (2 * x - 1) - 1) ^ 2 / 2 := by rw [sub_sq, sq_sqrt hx']; field_simp; ring simp only [IsGood, *, div_nonneg (sq_nonneg _) (zero_le_two (α := ℝ)), sqrt_div (sq_nonneg _), and_true] rw [sqrt_sq, sqrt_sq_eq_abs] <;> [skip; positivity] field_simp | inr hx => have : 2 * x - 1 < 0 := by linarith simp only [IsGood, this.not_ge, hx.not_ge]; simp theorem IsGood.one_half_le (h : IsGood x A) : 1 / 2 ≤ x := (isGood_iff.1 h).2 theorem sqrt_two_mul_sub_one_le_one : sqrt (2 * x - 1) ≤ 1 ↔ x ≤ 1 := by simp [sqrt_le_iff, ← two_mul] theorem isGood_iff_eq_sqrt_two (hx : x ∈ Icc (1 / 2) 1) : IsGood x A ↔ A = sqrt 2 := by have : sqrt (2 * x - 1) ≤ 1 := sqrt_two_mul_sub_one_le_one.2 hx.2 simp only [isGood_iff, hx.1, abs_sub_comm _ (1 : ℝ), abs_of_nonneg (sub_nonneg.2 this), and_true] suffices 2 = A * sqrt 2 ↔ A = sqrt 2 by convert this using 2; ring rw [← div_eq_iff, div_sqrt, eq_comm] positivity theorem isGood_iff_eq_sqrt (hx : 1 < x) : IsGood x A ↔ A = sqrt (4 * x - 2) := by have h₁ : 1 < sqrt (2 * x - 1) := by simpa only [← not_le, sqrt_two_mul_sub_one_le_one] using hx have h₂ : 1 / 2 ≤ x := by linarith simp only [isGood_iff, h₂, abs_of_pos (sub_pos.2 h₁), add_add_sub_cancel, and_true] rw [← mul_two, ← div_eq_iff (by positivity), mul_div_assoc, div_sqrt, ← sqrt_mul' _ zero_le_two, eq_comm] ring_nf theorem IsGood.sqrt_two_lt_of_one_lt (h : IsGood x A) (hx : 1 < x) : sqrt 2 < A := by rw [(isGood_iff_eq_sqrt hx).1 h] refine sqrt_lt_sqrt zero_le_two ?_ linarith theorem IsGood.eq_sqrt_two_iff_le_one (h : IsGood x A) : A = sqrt 2 ↔ x ≤ 1 := ⟨fun hA ↦ not_lt.1 fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).ne' hA, fun hx ↦ (isGood_iff_eq_sqrt_two ⟨h.one_half_le, hx⟩).1 h⟩ theorem IsGood.sqrt_two_lt_iff_one_lt (h : IsGood x A) : sqrt 2 < A ↔ 1 < x := ⟨fun hA ↦ not_le.1 fun hx ↦ hA.ne' <| h.eq_sqrt_two_iff_le_one.2 hx, h.sqrt_two_lt_of_one_lt⟩ theorem IsGood.sqrt_two_le (h : IsGood x A) : sqrt 2 ≤ A := (le_or_gt x 1).elim (fun hx ↦ (h.eq_sqrt_two_iff_le_one.2 hx).ge) fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).le theorem isGood_iff_of_sqrt_two_lt (hA : sqrt 2 < A) : IsGood x A ↔ x = (A / 2) ^ 2 + 1 / 2 := by have : 0 < A := lt_trans (by simp) hA constructor · intro h have hx : 1 < x := by rwa [h.sqrt_two_lt_iff_one_lt] at hA rw [isGood_iff_eq_sqrt hx, eq_comm, sqrt_eq_iff_eq_sq] at h <;> linarith · rintro rfl rw [isGood_iff_eq_sqrt] · conv_lhs => rw [← sqrt_sq this.le] ring_nf · rw [sqrt_lt' this] at hA linarith abbrev solution_set_sqrt2 : Set ℝ := Icc (1 / 2) 1 theorem imo1959_p2a : IsGood x (sqrt 2) ↔ x ∈ solution_set_sqrt2 := by refine ⟨fun h ↦ ?_, fun h ↦ (isGood_iff_eq_sqrt_two h).2 rfl⟩ exact ⟨h.one_half_le, not_lt.1 fun h₁ ↦ (h.sqrt_two_lt_of_one_lt h₁).false⟩ abbrev solution_set_one : Set ℝ := ∅ theorem imo1959_p2b : IsGood x 1 ↔ x ∈ solution_set_one := by have not_isGood_one : ¬IsGood x 1 := fun h ↦ h.sqrt_two_le.not_gt <| (lt_sqrt zero_le_one).2 (by norm_num) exact iff_of_false not_isGood_one fun a ↦ a abbrev solution_set_two : Set ℝ := { 3 / 2 } theorem imo1959_p2c : IsGood x 2 ↔ x ∈ solution_set_two := by rw [mem_singleton_iff] exact (isGood_iff_of_sqrt_two_lt <| (sqrt_lt' two_pos).2 (by norm_num)).trans <| by norm_num end Imo1959P2
true
Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib /-! # International Mathematical Olympiad 1959, Problem 2 For what real values of x is √(x+√(2x-1)) + √(x-√(2x-1)) = A, given: (a) A = √2 (b) A = 1 (c) A = 2, where only non-negative real numbers are admitted for square roots? -/ open Set Real namespace Imo1959P2 def IsGood (x A : ℝ) : Prop := sqrt (x + sqrt (2 * x - 1)) + sqrt (x - sqrt (2 * x - 1)) = A ∧ 0 ≤ 2 * x - 1 ∧ 0 ≤ x + sqrt (2 * x - 1) ∧ 0 ≤ x - sqrt (2 * x - 1) variable {x A : ℝ} /- We follow second solution from the [Art of Problem Solving](https://artofproblemsolving.com/wiki/index.php/1959_IMO_Problems/Problem_2) website. Namely, we rewrite the equation as $\sqrt{2x-1}+1+|\sqrt{2x-1}-1|=A\sqrt{2}$, then consider the cases $\sqrt{2x-1}\le 1$ and $1 < \sqrt{2x-1}$ separately. -/ theorem isGood_iff : IsGood x A ↔ sqrt (2 * x - 1) + 1 + |sqrt (2 * x - 1) - 1| = A * sqrt 2 ∧ 1 / 2 ≤ x := by cases le_or_gt (1 / 2) x with | inl hx => have hx' : 0 ≤ 2 * x - 1 := by linarith have h₁ : x + sqrt (2 * x - 1) = (sqrt (2 * x - 1) + 1) ^ 2 / 2 := by rw [add_sq, sq_sqrt hx']; field_simp; ring have h₂ : x - sqrt (2 * x - 1) = (sqrt (2 * x - 1) - 1) ^ 2 / 2 := by rw [sub_sq, sq_sqrt hx']; field_simp; ring simp only [IsGood, *, div_nonneg (sq_nonneg _) (zero_le_two (α := ℝ)), sqrt_div (sq_nonneg _), and_true] rw [sqrt_sq, sqrt_sq_eq_abs] <;> [skip; positivity] field_simp | inr hx => have : 2 * x - 1 < 0 := by linarith simp only [IsGood, this.not_ge, hx.not_ge]; simp theorem IsGood.one_half_le (h : IsGood x A) : 1 / 2 ≤ x := (isGood_iff.1 h).2 theorem sqrt_two_mul_sub_one_le_one : sqrt (2 * x - 1) ≤ 1 ↔ x ≤ 1 := by simp [sqrt_le_iff, ← two_mul] theorem isGood_iff_eq_sqrt_two (hx : x ∈ Icc (1 / 2) 1) : IsGood x A ↔ A = sqrt 2 := by have : sqrt (2 * x - 1) ≤ 1 := sqrt_two_mul_sub_one_le_one.2 hx.2 simp only [isGood_iff, hx.1, abs_sub_comm _ (1 : ℝ), abs_of_nonneg (sub_nonneg.2 this), and_true] suffices 2 = A * sqrt 2 ↔ A = sqrt 2 by convert this using 2; ring rw [← div_eq_iff, div_sqrt, eq_comm] positivity theorem isGood_iff_eq_sqrt (hx : 1 < x) : IsGood x A ↔ A = sqrt (4 * x - 2) := by have h₁ : 1 < sqrt (2 * x - 1) := by simpa only [← not_le, sqrt_two_mul_sub_one_le_one] using hx have h₂ : 1 / 2 ≤ x := by linarith simp only [isGood_iff, h₂, abs_of_pos (sub_pos.2 h₁), add_add_sub_cancel, and_true] rw [← mul_two, ← div_eq_iff (by positivity), mul_div_assoc, div_sqrt, ← sqrt_mul' _ zero_le_two, eq_comm] ring_nf theorem IsGood.sqrt_two_lt_of_one_lt (h : IsGood x A) (hx : 1 < x) : sqrt 2 < A := by rw [(isGood_iff_eq_sqrt hx).1 h] refine sqrt_lt_sqrt zero_le_two ?_ linarith theorem IsGood.eq_sqrt_two_iff_le_one (h : IsGood x A) : A = sqrt 2 ↔ x ≤ 1 := ⟨fun hA ↦ not_lt.1 fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).ne' hA, fun hx ↦ (isGood_iff_eq_sqrt_two ⟨h.one_half_le, hx⟩).1 h⟩ theorem IsGood.sqrt_two_lt_iff_one_lt (h : IsGood x A) : sqrt 2 < A ↔ 1 < x := ⟨fun hA ↦ not_le.1 fun hx ↦ hA.ne' <| h.eq_sqrt_two_iff_le_one.2 hx, h.sqrt_two_lt_of_one_lt⟩ theorem IsGood.sqrt_two_le (h : IsGood x A) : sqrt 2 ≤ A := (le_or_gt x 1).elim (fun hx ↦ (h.eq_sqrt_two_iff_le_one.2 hx).ge) fun hx ↦ (h.sqrt_two_lt_of_one_lt hx).le theorem isGood_iff_of_sqrt_two_lt (hA : sqrt 2 < A) : IsGood x A ↔ x = (A / 2) ^ 2 + 1 / 2 := by have : 0 < A := lt_trans (by simp) hA constructor · intro h have hx : 1 < x := by rwa [h.sqrt_two_lt_iff_one_lt] at hA rw [isGood_iff_eq_sqrt hx, eq_comm, sqrt_eq_iff_eq_sq] at h <;> linarith · rintro rfl rw [isGood_iff_eq_sqrt] · conv_lhs => rw [← sqrt_sq this.le] ring_nf · rw [sqrt_lt' this] at hA linarith abbrev solution_set_sqrt2 : Set ℝ := Icc (1 / 2) 1 theorem imo1959_p2a : IsGood x (sqrt 2) ↔ x ∈ solution_set_sqrt2 := by refine ⟨fun h ↦ ?_, fun h ↦ (isGood_iff_eq_sqrt_two h).2 rfl⟩ exact ⟨h.one_half_le, not_lt.1 fun h₁ ↦ (h.sqrt_two_lt_of_one_lt h₁).false⟩ abbrev solution_set_one : Set ℝ := ∅ theorem imo1959_p2b : IsGood x 1 ↔ x ∈ solution_set_one := by have not_isGood_one : ¬IsGood x 1 := fun h ↦ h.sqrt_two_le.not_gt <| (lt_sqrt zero_le_one).2 (by norm_num) exact iff_of_false not_isGood_one fun a ↦ a abbrev solution_set_two : Set ℝ := { 3 / 2 } theorem imo1959_p2c : IsGood x 2 ↔ x ∈ solution_set_two := by rw [mem_singleton_iff] exact (isGood_iff_of_sqrt_two_lt <| (sqrt_lt' two_pos).2 (by norm_num)).trans <| by norm_num end Imo1959P2
null
v4.29.0-rc6
test
[ "competition", "imo" ]
null
{"filename": "Imo1959P2.lean"}
{"v4.21.0": {"is_valid": false, "has_sorry": false, "errors": ["unknown identifier 'sqrt'", "unknown identifier 'sqrt'", "unknown identifier 'sqrt'", "unknown identifier 'sqrt'", "function expected at\n sqrt\nterm has type\n ?m.449", "function expected at\n sqrt\nterm has type\n ?m.449", "function expected at\n sqrt\nterm has type\n ?m.449", "function expected at\n sqrt\nterm has type\n x\u271d", "function expected at\n sqrt\nterm has type\n x\u271d", "unknown identifier 'sq_sqrt'", "function expected at\n sqrt\nterm has type\n x\u271d", "function expected at\n sqrt\nterm has type\n x\u271d", "unknown identifier 'sq_sqrt'", "unknown identifier 'sqrt_div'", "unknown identifier 'sqrt_sq'", "don't know how to synthesize placeholder\ncontext:\nx A : \u211d\nh : IsGood x A\n\u22a2 ?m.27224 one_half_le h", "don't know how to synthesize placeholder\ncontext:\nx A : \u211d\nh : IsGood x A\n\u22a2 Sort ?u.27207", "function expected at\n sqrt\nterm has type\n ?m.27237", "unknown identifier 'sqrt_le_iff'", "unsolved goals\nx : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\n\u22a2 sorry () \u2264 1 \u2194 x \u2264 1", "function expected at\n Icc\nterm has type\n ?m.31210", "function expected at\n sqrt\nterm has type\n ?m.31497", "function expected at\n sqrt\nterm has type\n x\u271d", "unsolved goals\nx A : \u211d\nx\u271d\u00b9 : Sort u_1\nIcc : x\u271d\u00b9\nx\u271d : Sort u_2\nsqrt : x\u271d\nhx : x \u2208 sorry\n\u22a2 IsGood x A \u2194 A = sorry", "function expected at\n sqrt\nterm has type\n ?m.33921", "function expected at\n sqrt\nterm has type\n x\u271d", "failed to synthesize\n AddGroup \u2115\n\nAdditional diagnostic information may be available using the `set_option diagnostics true` command.", "failed to synthesize\n AddGroup \u2115\n\nAdditional diagnostic information may be available using the `set_option diagnostics true` command.", "simp made no progress", "function expected at\n sqrt\nterm has type\n ?m.38109", "unsolved goals\nx A : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nh : IsGood x A\nhx : 1 < x\n\u22a2 sorry < A", "function expected at\n sqrt\nterm has type\n ?m.38605", "unknown identifier 'isGood_iff_eq_sqrt_two'", "function expected at\n sqrt\nterm has type\n ?m.39281", "function expected at\n sqrt\nterm has type\n ?m.39960", "function expected at\n sqrt\nterm has type\n ?m.40540", "unsolved goals\nx A : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\n\u22a2 0 < sorry ()", "unsolved goals\nx A : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\nthis : 0 < A\nh : IsGood x A\n\u22a2 Sort ?u.44022\n\nx A : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\nthis : 0 < A\nh : IsGood x A\n\u22a2 ?m.44030", "unknown identifier 'sqrt_eq_iff_eq_sq'", "unknown identifier 'sqrt_sq'", "tactic 'rewrite' failed, equality or iff proof expected\n ?m.44184\nA : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\nthis : 0 < A\n| A", "unknown identifier 'sqrt_lt''", "unsolved goals\nA : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\nthis : 0 < A\n\u22a2 Sort ?u.44149\n\nA : \u211d\nx\u271d : Sort u_1\nsqrt : x\u271d\nhA : sorry < A\nthis : 0 < A\n\u22a2 ?m.44152", "unknown identifier 'Icc'", "function expected at\n sqrt\nterm has type\n ?m.44210", "unknown identifier 'isGood_iff_eq_sqrt_two'", "unknown identifier 'lt_sqrt'", "unsolved goals\nx : \u211d\n\u22a2 IsGood x 1 \u2194 x \u2208 solution_set_one", "unknown identifier 'mem_singleton_iff'", "unsolved goals\nx : \u211d\n\u22a2 IsGood x 2 \u2194 x \u2208 solution_set_two"], "timeout_s": 600.0, "latency_s": 0.8435, "verified_at": "2026-03-26T18:15:58.393786+00:00"}}
false
true
false
0.8435
End of preview. Expand in Data Studio

ai4math-lean

21 Lean 4 formal mathematics datasets with machine-verified labels.

Every problem has been verified against lean-server v4.21.0 on UVA's HPC cluster. Results are embedded in each row as both structured verification JSON and flattened convenience columns.

Quick Start

from datasets import load_dataset

# Load a single dataset
ds = load_dataset("charliemeyer2000/ai4math-lean", "deepseek_prover")

# Load a large dataset with streaming
ds = load_dataset("charliemeyer2000/ai4math-lean", "goedel_pset", streaming=True)

# Filter to valid proofs
valid = ds.filter(lambda x: x["v4210_is_valid"] == True)

# Filter to RL targets (compiles but no proof)
rl = ds.filter(lambda x: x["v4210_compiles"] and not x["has_proof"])

Totals

Metric Count
Total problems 3,394,310
With proofs (SFT) 1,273,472
Valid on v4.21.0 352,065

Datasets

Dataset Problems Proofs Valid v4.21.0
compfiles 297 259 67
deepseek_prover 27,503 27,503 27,126
deepseek_proverbench 325 0 0
formal_conjectures 618 13 13
formalmath 5,560 5,556 2
goedel_minif2f 244 0 0
goedel_mobench 360 0 0
goedel_pset 1,732,594 263,589 9,755
goedel_test 8 0 0
hf_lean_workbook 29,750 29,750 29,208
hf_minif2f_lean4 231 0 0
hf_minif2f_v2 488 0 0
hf_tonic_minif2f 488 0 0
lean_proofs 98 97 15
lean_workbook_full 140,214 0 0
matholympiadbench 360 0 0
nemotron_proofs 1,349,950 915,078 285,867
numinamath_lean 104,155 31,615 0
proofnet 371 0 0
putnam2025 24 12 12
putnam_bench 672 0 0

Schema

Each row contains:

Field Type Description
id string Unique problem identifier
source string Dataset source name
formal_statement string Lean 4 theorem statement (no proof body)
header string Import/setup code
lean4_code string Full runnable Lean 4 code
has_proof bool True if contains a real proof (not sorry)
proof_body string? Proof tactic block (if has_proof)
natural_language string? NL problem statement (if available)
lean_version string? Original Lean toolchain version
split string? train/test/val split
tags list[string] Tags (topic, difficulty, etc.)
category string? Math category
verification string (JSON) Full verification results per Lean version
v4210_is_valid bool? True=valid, False=errors/sorry, None=timeout
v4210_compiles bool Whether the code compiled (is_valid is not None)
v4210_has_sorry bool? Whether sorry was detected
v4210_latency_s float? Verification wall time in seconds

Verification Details

The verification column contains a JSON string mapping Lean versions to results:

{
  "v4.21.0": {
    "is_valid": false,
    "has_sorry": true,
    "errors": [],
    "timeout_s": 600.0,
    "latency_s": 34.59,
    "verified_at": "2026-03-26T21:57:47Z"
  }
}

License

Apache 2.0

Downloads last month
94