{"name": "putnam_1964_a4", "proof_length": 1769, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Set Function\n\n\n", "signature": "theorem putnam_1964_a4\n(u : ℕ → ℤ)\n(boundedu : ∃ B T : ℤ, ∀ n : ℕ, B ≤ u n ∧ u n ≤ T)\n(hu : ∀ n ≥ 4, u n = ((u (n - 1) + u (n - 2) + u (n - 3) * u (n - 4)) : ℝ) / (u (n - 1) * u (n - 2) + u (n - 3) + u (n - 4)) ∧ (u (n - 1) * u (n - 2) + u (n - 3) + u (n - 4)) ≠ 0)\n: (∃ N c : ℕ, c > 0 ∧ ∀ n ≥ N, u (n + c) = u n)", "src": "theorem putnam_1964_a4\n(u : ℕ → ℤ)\n(boundedu : ∃ B T : ℤ, ∀ n : ℕ, B ≤ u n ∧ u n ≤ T)\n(hu : ∀ n ≥ 4, u n = ((u (n - 1) + u (n - 2) + u (n - 3) * u (n - 4)) : ℝ) / (u (n - 1) * u (n - 2) + u (n - 3) + u (n - 4)) ∧ (u (n - 1) * u (n - 2) + u (n - 3) + u (n - 4)) ≠ 0)\n: (∃ N c : ℕ, c > 0 ∧ ∀ n ≥ N, u (n + c) = u n) := by \n have h_main : ∃ (i j : ℕ), i < j ∧ (u i = u j ∧ u (i + 1) = u (j + 1) ∧ u (i + 2) = u (j + 2) ∧ u (i + 3) = u (j + 3)) := by\n obtain ⟨B, T, hB⟩ := boundedu\n have h₁ : ∃ (i j : ℕ), i < j ∧ (u i = u j ∧ u (i + 1) = u (j + 1) ∧ u (i + 2) = u (j + 2) ∧ u (i + 3) = u (j + 3)) := by\n \n classical\n \n let f : ℕ → (ℤ × ℤ × ℤ × ℤ) := fun n => (u n, u (n + 1), u (n + 2), u (n + 3))\n have h₂ : Set.Finite (Set.range f) := by\n have h₃ : Set.range f ⊆ Set.Icc (B, B, B, B) (T, T, T, T) := by\n intro x hx\n rcases hx with ⟨n, rfl⟩\n have h₄ := hB n\n have h₅ := hB (n + 1)\n have h₆ := hB (n + 2)\n have h₇ := hB (n + 3)\n simp only [Set.mem_Icc, Prod.le_def] at h₄ h₅ h₆ h₇ ⊢\n constructor <;>\n (try constructor) <;>\n (try constructor) <;>\n (try constructor) <;>\n (try simp_all [f]) <;>\n (try nlinarith)\n \n have h₄ : Set.Finite (Set.Icc (B, B, B, B) (T, T, T, T)) := by\n apply Set.Finite.subset (Set.finite_mem_finset (Finset.Icc (B, B, B, B) (T, T, T, T)))\n intro x hx\n simp_all [Set.mem_Icc]\n <;>\n (try aesop)\n exact Set.Finite.subset h₄ h₃\n \n have h₃ : ∃ (i j : ℕ), i < j ∧ f i = f j := by\n by_contra! h₄\n have h₅ : Function.Injective f := by\n intro i j h₆\n by_cases h₇ : i = j\n · exact h₇\n · have h₈ : i < j ∨ j < i := by omega\n cases h₈ with\n | inl h₈ =>\n have h₉ := h₄ i j h₈\n simp_all\n | inr h₈ =>\n have h₉ := h₄ j i h₈\n simp_all\n have h₆ : Set.Infinite (Set.range f) := Set.infinite_range_of_injective h₅\n exact Set.not_infinite.mpr h₂ h₆\n \n obtain ⟨i, j, h₄, h₅⟩ := h₃\n refine' ⟨i, j, h₄, _⟩\n simp [f] at h₅ ⊢\n <;>\n (try simp_all [Prod.ext_iff]) <;>\n (try omega) <;>\n (try aesop)\n exact h₁\n \n have h_periodic : ∃ N c : ℕ, c > 0 ∧ ∀ n ≥ N, u (n + c) = u n := by\n obtain ⟨i, j, hij, h_eq⟩ := h_main\n have h₁ : ∀ m : ℕ, u (i + m) = u (j + m) := by\n intro m\n have h₂ : ∀ m : ℕ, u (i + m) = u (j + m) := by\n intro m\n induction m using Nat.strong_induction_on with\n | h m ih =>\n match m with\n | 0 =>\n have h₃ := h_eq.1\n simp at h₃ ⊢\n <;> simp_all [add_assoc]\n | 1 =>\n have h₃ := h_eq.2.1\n simp at h₃ ⊢\n <;> simp_all [add_assoc]\n <;> ring_nf at *\n <;> omega\n | 2 =>\n have h₃ := h_eq.2.2.1\n simp at h₃ ⊢\n <;> simp_all [add_assoc]\n <;> ring_nf at *\n <;> omega\n | 3 =>\n have h₃ := h_eq.2.2.2\n simp at h₃ ⊢\n <;> simp_all [add_assoc]\n <;> ring_nf at *\n <;> omega\n | m + 4 =>\n have h₃ : i + (m + 4) ≥ 4 := by\n have h₄ : i ≥ 0 := by linarith\n omega\n have h₄ : u (i + (m + 4)) = ((u (i + (m + 4) - 1) + u (i + (m + 4) - 2) + u (i + (m + 4) - 3) * u (i + (m + 4) - 4)) : ℝ) / (u (i + (m + 4) - 1) * u (i + (m + 4) - 2) + u (i + (m + 4) - 3) + u (i + (m + 4) - 4)) := by\n have h₅ := hu (i + (m + 4)) (by omega)\n have h₆ := h₅.1\n norm_cast at h₆ ⊢\n <;> simp_all [add_assoc]\n <;> ring_nf at *\n <;> norm_num at *\n <;> linarith\n have h₅ : u (j + (m + 4)) = ((u (j + (m + 4) - 1) + u (j + (m + 4) - 2) + u (j + (m + 4) - 3) * u (j + (m + 4) - 4)) : ℝ) / (u (j + (m + 4) - 1) * u (j + (m + 4) - 2) + u (j + (m + 4) - 3) + u (j + (m + 4) - 4)) := by\n have h₆ := hu (j + (m + 4)) (by\n have h₇ : j ≥ i + 1 := by omega\n omega\n )\n have h₇ := h₆.1\n norm_cast at h₇ ⊢\n <;> simp_all [add_assoc]\n <;> ring_nf at *\n <;> norm_num at *\n <;> linarith\n have h₆ : (i + (m + 4) - 1 : ℕ) = i + (m + 3) := by\n omega\n have h₇ : (i + (m + 4) - 2 : ℕ) = i + (m + 2) := by\n omega\n have h₈ : (i + (m + 4) - 3 : ℕ) = i + (m + 1) := by\n omega\n have h₉ : (i + (m + 4) - 4 : ℕ) = i + m := by\n omega\n have h₁₀ : (j + (m + 4) - 1 : ℕ) = j + (m + 3) := by\n omega\n have h₁₁ : (j + (m + 4) - 2 : ℕ) = j + (m + 2) := by\n omega\n have h₁₂ : (j + (m + 4) - 3 : ℕ) = j + (m + 1) := by\n omega\n have h₁₃ : (j + (m + 4) - 4 : ℕ) = j + m := by\n omega\n have h₁₄ : u (i + (m + 3)) = u (j + (m + 3)) := by\n have h₁₅ := ih (m + 3) (by omega)\n simp [add_assoc] at h₁₅ ⊢\n <;> omega\n have h₁₅ : u (i + (m + 2)) = u (j + (m + 2)) := by\n have h₁₆ := ih (m + 2) (by omega)\n simp [add_assoc] at h₁₆ ⊢\n <;> omega\n have h₁₆ : u (i + (m + 1)) = u (j + (m + 1)) := by\n have h₁₇ := ih (m + 1) (by omega)\n simp [add_assoc] at h₁₇ ⊢\n <;> omega\n have h₁₇ : u (i + m) = u (j + m) := by\n have h₁₈ := ih m (by omega)\n simp [add_assoc] at h₁₈ ⊢\n <;> omega\n have h₁₈ : (u (i + (m + 4)) : ℝ) = (u (j + (m + 4)) : ℝ) := by\n rw [h₄, h₅]\n simp [h₆, h₇, h₈, h₉, h₁₀, h₁₁, h₁₂, h₁₃] at *\n norm_cast at *\n <;>\n (try simp_all [h₁₄, h₁₅, h₁₆, h₁₇]) <;>\n (try ring_nf at *) <;>\n (try field_simp at *) <;>\n (try norm_cast at *) <;>\n (try linarith)\n norm_cast at h₁₈ ⊢\n <;>\n (try simp_all) <;>\n (try linarith)\n exact h₂ m\n have h₂ : ∃ N c : ℕ, c > 0 ∧ ∀ n ≥ N, u (n + c) = u n := by\n use i, (j - i)\n have h₃ : j - i > 0 := by\n omega\n constructor\n · exact h₃\n · intro n hn\n have h₄ : u (n + (j - i)) = u n := by\n have h₅ : u (i + (n - i)) = u (j + (n - i)) := by\n have h₆ := h₁ (n - i)\n simp [add_assoc] at h₆ ⊢\n <;> omega\n have h₆ : i + (n - i) = n := by\n omega\n have h₇ : j + (n - i) = n + (j - i) := by\n omega\n rw [h₆] at h₅\n rw [h₇] at h₅\n linarith\n exact h₄\n exact h₂\n \n exact h_periodic"} {"name": "putnam_1995_a3", "proof_length": 4085, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Filter Topology Real\n\n\n", "signature": "theorem putnam_1995_a3\n(relation : (Fin 9 → ℤ) → (Fin 9 → ℤ) → Prop)\n(digits_to_num : (Fin 9 → ℤ) → ℤ)\n(hdigits_to_num : digits_to_num = fun dig => ∑ i : Fin 9, (dig i) * 10^i.1)\n(hrelation : ∀ d e : (Fin 9 → ℤ), relation d e ↔ (∀ i : Fin 9, d i < 10 ∧ d i ≥ 0 ∧ e i < 10 ∧ e i ≥ 0) ∧ (∀ i : Fin 9, 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then e j else d j))))\n: ∀ d e f : (Fin 9 → ℤ), ((relation d e) ∧ (relation e f)) → (∀ i : Fin 9, 7 ∣ d i - f i)", "src": "theorem putnam_1995_a3\n(relation : (Fin 9 → ℤ) → (Fin 9 → ℤ) → Prop)\n(digits_to_num : (Fin 9 → ℤ) → ℤ)\n(hdigits_to_num : digits_to_num = fun dig => ∑ i : Fin 9, (dig i) * 10^i.1)\n(hrelation : ∀ d e : (Fin 9 → ℤ), relation d e ↔ (∀ i : Fin 9, d i < 10 ∧ d i ≥ 0 ∧ e i < 10 ∧ e i ≥ 0) ∧ (∀ i : Fin 9, 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then e j else d j))))\n: ∀ d e f : (Fin 9 → ℤ), ((relation d e) ∧ (relation e f)) → (∀ i : Fin 9, 7 ∣ d i - f i) := by \n have h_main : ∀ (d e f : (Fin 9 → ℤ)), ((relation d e) ∧ (relation e f)) → (∀ i : Fin 9, 7 ∣ d i - f i) := by\n intro d e f h\n have h₁ : relation d e := h.1\n have h₂ : relation e f := h.2\n have h₃ : ∀ (i : Fin 9), 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then e j else d j)) := by\n have h₄ : (∀ i : Fin 9, 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then e j else d j))) := (hrelation d e).mp h₁ |>.2\n exact h₄\n have h₄ : ∀ (i : Fin 9), 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then f j else e j)) := by\n have h₅ : (∀ i : Fin 9, 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then f j else e j))) := (hrelation e f).mp h₂ |>.2\n exact h₅\n \n have h₅ : ∀ (i : Fin 9), 7 ∣ (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d := by\n intro i\n have h₆ : 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then e j else d j)) := h₃ i\n have h₇ : (digits_to_num (fun j : Fin 9 => if j = i then e j else d j)) = digits_to_num d + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n (digits_to_num (fun j : Fin 9 => if j = i then e j else d j)) = ∑ j : Fin 9, (if j = i then e j else d j) * (10 : ℤ) ^ (j : ℕ) := by\n simp [hdigits_to_num]\n <;>\n rfl\n _ = ∑ j : Fin 9, (if j = i then e j else d j) * (10 : ℤ) ^ (j : ℕ) := rfl\n _ = (∑ j : Fin 9, d j * (10 : ℤ) ^ (j : ℕ)) + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n (∑ j : Fin 9, (if j = i then e j else d j) * (10 : ℤ) ^ (j : ℕ)) = ∑ j : Fin 9, (d j * (10 : ℤ) ^ (j : ℕ) + (if j = i then (e j - d j) else 0) * (10 : ℤ) ^ (j : ℕ)) := by\n apply Finset.sum_congr rfl\n intro j _\n by_cases h : j = i\n · simp [h]\n <;> ring\n · simp [h]\n <;> ring\n _ = (∑ j : Fin 9, d j * (10 : ℤ) ^ (j : ℕ)) + ∑ j : Fin 9, (if j = i then (e j - d j) else 0) * (10 : ℤ) ^ (j : ℕ) := by\n rw [Finset.sum_add_distrib]\n _ = (∑ j : Fin 9, d j * (10 : ℤ) ^ (j : ℕ)) + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n have h₈ : ∑ j : Fin 9, (if j = i then (e j - d j) else 0) * (10 : ℤ) ^ (j : ℕ) = (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n _ = ∑ j : Fin 9, (if j = i then (e j - d j) else 0) * (10 : ℤ) ^ (j : ℕ) := rfl\n _ = (if i = i then (e i - d i) else 0) * (10 : ℤ) ^ (i : ℕ) := by\n \n simp [Finset.sum_ite_eq', Finset.mem_univ, i.is_lt]\n _ = (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by simp\n rw [h₈]\n <;> simp [hdigits_to_num]\n <;>\n rfl\n _ = digits_to_num d + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n simp [hdigits_to_num]\n <;>\n rfl\n have h₈ : 7 ∣ digits_to_num d + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n rw [h₇] at h₆\n exact h₆\n \n have h₉ : 7 ∣ (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d := by\n \n have h₁₀ : (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d = digits_to_num d + (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by ring\n rw [h₁₀]\n exact h₈\n exact h₉\n \n have h₆ : ∀ (i : Fin 9), 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e := by\n intro i\n have h₇ : 7 ∣ (digits_to_num (fun j : Fin 9 => if j = i then f j else e j)) := h₄ i\n have h₈ : (digits_to_num (fun j : Fin 9 => if j = i then f j else e j)) = digits_to_num e + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n (digits_to_num (fun j : Fin 9 => if j = i then f j else e j)) = ∑ j : Fin 9, (if j = i then f j else e j) * (10 : ℤ) ^ (j : ℕ) := by\n simp [hdigits_to_num]\n <;>\n rfl\n _ = ∑ j : Fin 9, (if j = i then f j else e j) * (10 : ℤ) ^ (j : ℕ) := rfl\n _ = (∑ j : Fin 9, e j * (10 : ℤ) ^ (j : ℕ)) + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n (∑ j : Fin 9, (if j = i then f j else e j) * (10 : ℤ) ^ (j : ℕ)) = ∑ j : Fin 9, (e j * (10 : ℤ) ^ (j : ℕ) + (if j = i then (f j - e j) else 0) * (10 : ℤ) ^ (j : ℕ)) := by\n apply Finset.sum_congr rfl\n intro j _\n by_cases h : j = i\n · simp [h]\n <;> ring\n · simp [h]\n <;> ring\n _ = (∑ j : Fin 9, e j * (10 : ℤ) ^ (j : ℕ)) + ∑ j : Fin 9, (if j = i then (f j - e j) else 0) * (10 : ℤ) ^ (j : ℕ) := by\n rw [Finset.sum_add_distrib]\n _ = (∑ j : Fin 9, e j * (10 : ℤ) ^ (j : ℕ)) + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n have h₉ : ∑ j : Fin 9, (if j = i then (f j - e j) else 0) * (10 : ℤ) ^ (j : ℕ) = (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n _ = ∑ j : Fin 9, (if j = i then (f j - e j) else 0) * (10 : ℤ) ^ (j : ℕ) := rfl\n _ = (if i = i then (f i - e i) else 0) * (10 : ℤ) ^ (i : ℕ) := by\n \n simp [Finset.sum_ite_eq', Finset.mem_univ, i.is_lt]\n _ = (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by simp\n rw [h₉]\n <;> simp [hdigits_to_num]\n <;>\n rfl\n _ = digits_to_num e + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n simp [hdigits_to_num]\n <;>\n rfl\n have h₉ : 7 ∣ digits_to_num e + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by\n rw [h₈] at h₇\n exact h₇\n \n have h₁₀ : 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e := by\n \n have h₁₁ : (f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e = digits_to_num e + (f i - e i) * (10 : ℤ) ^ (i : ℕ) := by ring\n rw [h₁₁]\n exact h₉\n exact h₁₀\n \n have h₇ : 7 ∣ digits_to_num e + digits_to_num d := by\n have h₈ : digits_to_num e = digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n calc\n digits_to_num e = ∑ i : Fin 9, e i * (10 : ℤ) ^ (i : ℕ) := by simp [hdigits_to_num]\n _ = ∑ i : Fin 9, (d i + (e i - d i)) * (10 : ℤ) ^ (i : ℕ) := by\n apply Finset.sum_congr rfl\n intro i _\n ring\n _ = ∑ i : Fin 9, (d i * (10 : ℤ) ^ (i : ℕ) + (e i - d i) * (10 : ℤ) ^ (i : ℕ)) := by\n apply Finset.sum_congr rfl\n intro i _\n ring\n _ = (∑ i : Fin 9, d i * (10 : ℤ) ^ (i : ℕ)) + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n rw [Finset.sum_add_distrib]\n _ = digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n simp [hdigits_to_num]\n <;>\n rfl\n have h₉ : ∀ i : Fin 9, 7 ∣ (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d := h₅\n have h₁₀ : 7 ∣ ∑ i : Fin 9, ((e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d) := by\n apply Finset.dvd_sum\n intro i _\n exact h₉ i\n have h₁₁ : ∑ i : Fin 9, ((e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d) = ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + 9 * digits_to_num d := by\n calc\n ∑ i : Fin 9, ((e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d) = ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + ∑ i : Fin 9, digits_to_num d := by\n rw [Finset.sum_add_distrib]\n _ = ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + 9 * digits_to_num d := by\n simp [Finset.sum_const, Finset.card_fin]\n <;> ring\n <;> norm_num\n have h₁₂ : 7 ∣ ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + 9 * digits_to_num d := by\n rw [h₁₁] at h₁₀\n exact h₁₀\n have h₁₃ : 7 ∣ digits_to_num e + digits_to_num d := by\n have h₁₄ : digits_to_num e + digits_to_num d = 2 * digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n linarith\n rw [h₁₄]\n have h₁₅ : 7 ∣ 2 * digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n have h₁₆ : 7 ∣ ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + 9 * digits_to_num d := h₁₂\n have h₁₇ : 7 ∣ 2 * digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n \n have h₁₈ : (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) + 9 * digits_to_num d) = (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 9 * digits_to_num d := by ring\n rw [h₁₈] at h₁₆\n \n \n \n \n \n \n have h₁₉ : 7 ∣ (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 2 * digits_to_num d := by\n \n \n \n have h₂₀ : 7 ∣ (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 9 * digits_to_num d := h₁₆\n have h₂₁ : 7 ∣ 7 * digits_to_num d := by\n use digits_to_num d\n <;> ring\n have h₂₂ : 7 ∣ (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 2 * digits_to_num d := by\n \n have h₂₃ : (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 2 * digits_to_num d = ((∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 9 * digits_to_num d) - 7 * digits_to_num d := by ring\n rw [h₂₃]\n exact dvd_sub h₂₀ h₂₁\n exact h₂₂\n \n have h₂₀ : 7 ∣ 2 * digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n \n have h₂₁ : 2 * digits_to_num d + ∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ) = (∑ i : Fin 9, (e i - d i) * (10 : ℤ) ^ (i : ℕ)) + 2 * digits_to_num d := by ring\n rw [h₂₁]\n exact h₁₉\n exact h₂₀\n exact h₁₇\n exact h₁₅\n exact h₁₃\n \n have h₈ : ∀ (i : Fin 9), 7 ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n intro i\n have h₉ : 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e := h₆ i\n have h₁₀ : 7 ∣ (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d := h₅ i\n have h₁₁ : 7 ∣ digits_to_num e + digits_to_num d := h₇\n \n have h₁₂ : 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) - digits_to_num d := by\n \n \n have h₁₃ : 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e := h₆ i\n have h₁₄ : 7 ∣ digits_to_num e + digits_to_num d := h₇\n \n have h₁₅ : 7 ∣ ((f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e) - (digits_to_num e + digits_to_num d) := by\n exact dvd_sub h₁₃ h₁₄\n \n have h₁₆ : ((f i - e i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num e) - (digits_to_num e + digits_to_num d) = (f i - e i) * (10 : ℤ) ^ (i : ℕ) - digits_to_num d := by\n ring\n rw [h₁₆] at h₁₅\n exact h₁₅\n \n have h₁₃ : 7 ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n have h₁₄ : 7 ∣ (f i - e i) * (10 : ℤ) ^ (i : ℕ) - digits_to_num d := h₁₂\n have h₁₅ : 7 ∣ (e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d := h₅ i\n \n have h₁₆ : 7 ∣ ((f i - e i) * (10 : ℤ) ^ (i : ℕ) - digits_to_num d) + ((e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d) := by\n exact dvd_add h₁₄ h₁₅\n \n have h₁₇ : ((f i - e i) * (10 : ℤ) ^ (i : ℕ) - digits_to_num d) + ((e i - d i) * (10 : ℤ) ^ (i : ℕ) + digits_to_num d) = (f i - d i) * (10 : ℤ) ^ (i : ℕ) := by\n ring\n rw [h₁₇] at h₁₆\n exact h₁₆\n exact h₁₃\n \n have h₉ : ∀ (i : Fin 9), 7 ∣ d i - f i := by\n intro i\n have h₁₀ : 7 ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := h₈ i\n have h₁₁ : 7 ∣ (f i - d i) := by\n \n have h₁₂ : (7 : ℤ) ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := h₁₀\n \n have h₁₃ : (7 : ℕ).Prime := by decide\n have h₁₄ : ¬(7 : ℤ) ∣ (10 : ℤ) ^ (i : ℕ) := by\n \n intro h\n have h₁₅ : (7 : ℕ) ∣ (10 : ℕ) ^ (i : ℕ) := by\n norm_cast at h ⊢\n <;> simpa [Int.coe_nat_dvd_left] using h\n have h₁₆ : (7 : ℕ) ∣ 10 := by\n \n exact Nat.Prime.dvd_of_dvd_pow h₁₃ h₁₅\n norm_num at h₁₆\n <;> contradiction\n \n have h₁₅ : (7 : ℤ) ∣ (f i - d i) := by\n \n have h₁₆ : (7 : ℤ) ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := h₁₂\n have h₁₇ : ¬(7 : ℤ) ∣ (10 : ℤ) ^ (i : ℕ) := h₁₄\n \n have h₁₈ : (7 : ℤ) ∣ (f i - d i) := by\n \n have h₁₉ : (7 : ℤ) ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := h₁₂\n have h₂₀ : (7 : ℕ).Prime := by decide\n have h₂₁ : (7 : ℤ) ∣ (f i - d i) ∨ (7 : ℤ) ∣ (10 : ℤ) ^ (i : ℕ) := by\n \n have h₂₂ : (7 : ℤ) ∣ (f i - d i) * (10 : ℤ) ^ (i : ℕ) := h₁₂\n have h₂₃ : (7 : ℤ) ∣ (f i - d i) ∨ (7 : ℤ) ∣ (10 : ℤ) ^ (i : ℕ) := by\n \n apply (Int.prime_iff_natAbs_prime.mpr (by decide)).dvd_mul.mp\n exact h₂₂\n exact h₂₃\n cases h₂₁ with\n | inl h₂₁ =>\n exact h₂₁\n | inr h₂₁ =>\n exfalso\n exact h₁₄ h₂₁\n exact h₁₈\n exact h₁₅\n \n have h₁₂ : 7 ∣ d i - f i := by\n have h₁₃ : 7 ∣ (f i - d i) := h₁₁\n have h₁₄ : 7 ∣ -(f i - d i) := by\n exact dvd_neg.mpr h₁₃\n have h₁₅ : -(f i - d i) = d i - f i := by ring\n rw [h₁₅] at h₁₄\n exact h₁₄\n exact h₁₂\n \n intro i\n have h₁₀ : 7 ∣ d i - f i := h₉ i\n exact h₁₀\n exact h_main"} {"name": "putnam_1988_a2", "proof_length": 2161, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Set\n\n\n\n", "signature": "theorem putnam_1988_a2\n (f : ℝ → ℝ)\n (hf : f = fun x ↦ Real.exp (x ^ 2)) :\n ((True) : Prop ) ↔\n (∃ a b : ℝ,\n a < b ∧\n ∃ g : ℝ → ℝ,\n (∃ x ∈ Ioo a b, g x ≠ 0) ∧\n DifferentiableOn ℝ g (Ioo a b) ∧\n ∀ x ∈ Ioo a b, deriv (fun y ↦ f y * g y) x = (deriv f x) * (deriv g x))", "src": "theorem putnam_1988_a2\n (f : ℝ → ℝ)\n (hf : f = fun x ↦ Real.exp (x ^ 2)) :\n ((True) : Prop ) ↔\n (∃ a b : ℝ,\n a < b ∧\n ∃ g : ℝ → ℝ,\n (∃ x ∈ Ioo a b, g x ≠ 0) ∧\n DifferentiableOn ℝ g (Ioo a b) ∧\n ∀ x ∈ Ioo a b, deriv (fun y ↦ f y * g y) x = (deriv f x) * (deriv g x)) :=\n by \n have h_main : (∃ (a b : ℝ), a < b ∧ ∃ (g : ℝ → ℝ), (∃ x ∈ Set.Ioo a b, g x ≠ 0) ∧ DifferentiableOn ℝ g (Set.Ioo a b) ∧ ∀ x ∈ Set.Ioo a b, deriv (fun y ↦ f y * g y) x = (deriv f x) * (deriv g x)) := by\n use 1, 2\n constructor\n · norm_num\n · \n use fun x => Real.exp x * Real.sqrt (2 * x - 1)\n constructor\n · \n use 3 / 2\n constructor\n · \n norm_num [Set.mem_Ioo]\n · \n have h₁ : Real.exp (3 / 2 : ℝ) > 0 := Real.exp_pos _\n have h₂ : Real.sqrt (2 * (3 / 2 : ℝ) - 1) > 0 := by\n apply Real.sqrt_pos_of_pos\n norm_num\n have h₃ : Real.exp (3 / 2 : ℝ) * Real.sqrt (2 * (3 / 2 : ℝ) - 1) > 0 := by positivity\n intro h₄\n linarith\n · constructor\n · \n have h₁ : DifferentiableOn ℝ (fun x : ℝ => Real.exp x * Real.sqrt (2 * x - 1)) (Set.Ioo 1 2) := by\n apply DifferentiableOn.mul\n · exact DifferentiableOn.exp (differentiableOn_id)\n · apply DifferentiableOn.sqrt\n · \n have h₂ : DifferentiableOn ℝ (fun x : ℝ => (2 : ℝ) * x - 1) (Set.Ioo 1 2) := by\n apply DifferentiableOn.sub\n · apply DifferentiableOn.const_mul\n exact differentiableOn_id\n · exact differentiableOn_const _\n exact h₂\n · \n intro x hx\n have h₃ : 1 < x := hx.1\n have h₄ : x < 2 := hx.2\n have h₅ : (2 : ℝ) * x - 1 > 0 := by linarith\n linarith\n exact h₁\n · \n intro x hx\n have h₁ : x ∈ Set.Ioo 1 2 := hx\n have h₂ : 1 < x := h₁.1\n have h₃ : x < 2 := h₁.2\n have h₄ : (2 : ℝ) * x - 1 > 0 := by linarith\n have h₅ : Real.sqrt (2 * x - 1) > 0 := Real.sqrt_pos.mpr h₄\n have h₆ : HasDerivAt (fun x : ℝ => Real.exp x * Real.sqrt (2 * x - 1)) (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) x := by\n \n have h₇ : HasDerivAt (fun x : ℝ => Real.exp x) (Real.exp x) x := Real.hasDerivAt_exp x\n have h₈ : HasDerivAt (fun x : ℝ => Real.sqrt (2 * x - 1)) (1 / Real.sqrt (2 * x - 1)) x := by\n have h₉ : HasDerivAt (fun x : ℝ => (2 : ℝ) * x - 1) 2 x := by\n simpa using (hasDerivAt_id x).const_mul 2 |>.sub_const 1\n have h₁₀ : HasDerivAt (fun x : ℝ => Real.sqrt (2 * x - 1)) (1 / Real.sqrt (2 * x - 1)) x := by\n convert HasDerivAt.sqrt h₉ (by positivity) using 1 <;>\n field_simp [h₄.ne'] <;>\n ring_nf <;>\n field_simp [h₄.ne'] <;>\n ring\n exact h₁₀\n have h₁₁ : HasDerivAt (fun x : ℝ => Real.exp x * Real.sqrt (2 * x - 1)) (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) x := by\n convert h₇.mul h₈ using 1 <;>\n field_simp [h₄.ne'] <;>\n ring_nf <;>\n field_simp [h₄.ne'] <;>\n ring\n exact h₁₁\n have h₇ : deriv (fun x : ℝ => Real.exp x * Real.sqrt (2 * x - 1)) x = Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1) := by\n apply HasDerivAt.deriv\n exact h₆\n \n have h₈ : f = fun x => Real.exp (x ^ 2) := hf\n have h₉ : deriv f x = 2 * x * Real.exp (x ^ 2) := by\n rw [h₈]\n \n have h₁₀ : HasDerivAt (fun x : ℝ => Real.exp (x ^ 2)) (2 * x * Real.exp (x ^ 2)) x := by\n have h₁₁ : HasDerivAt (fun x : ℝ => x ^ 2) (2 * x) x := by\n simpa using (hasDerivAt_pow 2 x)\n have h₁₂ : HasDerivAt (fun x : ℝ => Real.exp (x ^ 2)) (Real.exp (x ^ 2) * (2 * x)) x := by\n apply HasDerivAt.exp\n exact h₁₁\n convert h₁₂ using 1 <;> ring\n have h₁₃ : deriv (fun x : ℝ => Real.exp (x ^ 2)) x = 2 * x * Real.exp (x ^ 2) := by\n apply HasDerivAt.deriv\n exact h₁₀\n exact h₁₃\n have h₁₀ : deriv (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) x = (deriv f x) * (deriv (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) x) := by\n \n have h₁₁ : deriv (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) x = deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) := by\n \n have h₁₂ : HasDerivAt (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) (deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1))) x := by\n have h₁₃ : HasDerivAt f (deriv f x) x := by\n have h₁₄ : DifferentiableAt ℝ f x := by\n rw [h₈]\n apply DifferentiableAt.exp\n apply DifferentiableAt.pow\n exact differentiableAt_id\n exact h₁₄.hasDerivAt\n have h₁₄ : HasDerivAt (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) x := by\n convert h₆ using 1\n have h₁₅ : HasDerivAt (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) (deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1))) x := by\n convert h₁₃.mul h₁₄ using 1 <;>\n simp [h₉, h₈, mul_assoc]\n <;>\n ring_nf\n <;>\n field_simp [h₄.ne']\n <;>\n ring\n exact h₁₅\n have h₁₆ : deriv (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) x = deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) := by\n apply HasDerivAt.deriv\n exact h₁₂\n exact h₁₆\n have h₁₇ : deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) = (deriv f x) * (deriv (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) x) := by\n \n have h₁₈ : deriv f x = 2 * x * Real.exp (x ^ 2) := h₉\n have h₁₉ : f x = Real.exp (x ^ 2) := by\n rw [h₈]\n <;> simp\n have h₂₀ : deriv (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) x = Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1) := h₇\n have h₂₁ : 2 * x * (Real.exp x * Real.sqrt (2 * x - 1)) + (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) = 2 * x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) := by\n \n have h₂₂ : Real.exp x > 0 := Real.exp_pos x\n have h₂₃ : Real.sqrt (2 * x - 1) > 0 := Real.sqrt_pos.mpr (by linarith)\n field_simp [h₂₃.ne', h₂₂.ne']\n <;>\n nlinarith [Real.sq_sqrt (show 0 ≤ 2 * x - 1 by linarith)]\n calc\n deriv f x * (Real.exp x * Real.sqrt (2 * x - 1)) + f x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) = (2 * x * Real.exp (x ^ 2)) * (Real.exp x * Real.sqrt (2 * x - 1)) + Real.exp (x ^ 2) * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) := by\n rw [h₁₈, h₁₉]\n _ = Real.exp (x ^ 2) * (2 * x * (Real.exp x * Real.sqrt (2 * x - 1)) + (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1))) := by\n ring_nf\n <;>\n field_simp [Real.exp_ne_zero]\n <;>\n ring_nf\n _ = Real.exp (x ^ 2) * (2 * x * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1))) := by\n rw [h₂₁]\n <;>\n ring_nf\n _ = (2 * x * Real.exp (x ^ 2)) * (Real.exp x * Real.sqrt (2 * x - 1) + Real.exp x / Real.sqrt (2 * x - 1)) := by\n ring_nf\n _ = (deriv f x) * (deriv (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) x) := by\n rw [h₁₈, h₂₀]\n <;>\n ring_nf\n <;>\n field_simp [Real.exp_ne_zero]\n <;>\n ring_nf\n rw [h₁₁]\n rw [h₁₇]\n \n have h₁₁ : deriv (fun y : ℝ => f y * (Real.exp y * Real.sqrt (2 * y - 1))) x = (deriv f x) * (deriv (fun y : ℝ => Real.exp y * Real.sqrt (2 * y - 1)) x) := h₁₀\n simpa [h₈] using h₁₁\n \n have h_final : ((True) : Prop ) ↔ (∃ a b : ℝ, a < b ∧ ∃ g : ℝ → ℝ, (∃ x ∈ Set.Ioo a b, g x ≠ 0) ∧ DifferentiableOn ℝ g (Set.Ioo a b) ∧ ∀ x ∈ Set.Ioo a b, deriv (fun y ↦ f y * g y) x = (deriv f x) * (deriv g x)) := by\n constructor\n · intro _\n exact h_main\n · intro h\n trivial\n \n exact h_final"} {"name": "putnam_2001_b1", "proof_length": 3178, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Topology Filter Polynomial Set\n\n\n", "signature": "theorem putnam_2001_b1\n (n : ℕ)\n (hn : n > 0) (hn' : Even n)\n (nums : Fin n → Fin n → ℤ)\n (colors : Fin n → Fin n → Fin 2)\n (hnums : ∀ k l, nums k l = k * n + l + 1)\n (hcolorsrows : ∀ k, (∑ l, (if (colors k l = 0) then 1 else 0)) = n / 2)\n (hcolorscols : ∀ l, (∑ k, (if (colors k l = 0) then 1 else 0)) = n / 2) :\n (∑ k, ∑ l, (if (colors k l = 0) then (nums k l) else 0)) = (∑ k, ∑ l, (if (colors k l = 1) then (nums k l) else 0))", "src": "theorem putnam_2001_b1\n (n : ℕ)\n (hn : n > 0) (hn' : Even n)\n (nums : Fin n → Fin n → ℤ)\n (colors : Fin n → Fin n → Fin 2)\n (hnums : ∀ k l, nums k l = k * n + l + 1)\n (hcolorsrows : ∀ k, (∑ l, (if (colors k l = 0) then 1 else 0)) = n / 2)\n (hcolorscols : ∀ l, (∑ k, (if (colors k l = 0) then 1 else 0)) = n / 2) :\n (∑ k, ∑ l, (if (colors k l = 0) then (nums k l) else 0)) = (∑ k, ∑ l, (if (colors k l = 1) then (nums k l) else 0)) := by \n have hrow_sum_zero : ∀ (k : Fin n), (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := by\n intro k\n have h1 : (∑ l : Fin n, (if colors k l = 0 then (1 : ℤ) else 0)) = n / 2 := by\n norm_cast at hcolorsrows ⊢\n simpa using hcolorsrows k\n have h2 : (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := by\n calc\n (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0))) - ∑ l : Fin n, (1 : ℤ) := by\n rw [Finset.sum_sub_distrib]\n _ = 2 * (∑ l : Fin n, (if colors k l = 0 then (1 : ℤ) else 0)) - ∑ l : Fin n, (1 : ℤ) := by\n rw [Finset.mul_sum]\n _ = 2 * (n / 2 : ℤ) - n := by\n rw [h1]\n simp [Finset.sum_const, Finset.card_fin]\n <;> norm_cast\n <;> simp [nsmul_eq_mul]\n <;> ring_nf\n <;> simp_all [Nat.cast_inj]\n <;> omega\n _ = 0 := by\n have h3 : (n : ℤ) % 2 = 0 := by\n have h4 : Even n := hn'\n rw [even_iff_two_dvd] at h4\n obtain ⟨m, hm⟩ := h4\n norm_cast at hm ⊢\n omega\n have h4 : (n : ℤ) / 2 * 2 = n := by\n have h5 : (n : ℤ) % 2 = 0 := h3\n have h6 : (n : ℤ) = 2 * ((n : ℤ) / 2) := by\n omega\n linarith\n ring_nf at *\n <;> omega\n exact h2\n \n have hcol_sum_zero : ∀ (l : Fin n), (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := by\n intro l\n have h1 : (∑ k : Fin n, (if colors k l = 0 then (1 : ℤ) else 0)) = n / 2 := by\n norm_cast at hcolorscols ⊢\n simpa using hcolorscols l\n have h2 : (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := by\n calc\n (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0))) - ∑ k : Fin n, (1 : ℤ) := by\n rw [Finset.sum_sub_distrib]\n _ = 2 * (∑ k : Fin n, (if colors k l = 0 then (1 : ℤ) else 0)) - ∑ k : Fin n, (1 : ℤ) := by\n rw [Finset.mul_sum]\n _ = 2 * (n / 2 : ℤ) - n := by\n rw [h1]\n simp [Finset.sum_const, Finset.card_fin]\n <;> norm_cast\n <;> simp [nsmul_eq_mul]\n <;> ring_nf\n <;> simp_all [Nat.cast_inj]\n <;> omega\n _ = 0 := by\n have h3 : (n : ℤ) % 2 = 0 := by\n have h4 : Even n := hn'\n rw [even_iff_two_dvd] at h4\n obtain ⟨m, hm⟩ := h4\n norm_cast at hm ⊢\n omega\n have h4 : (n : ℤ) / 2 * 2 = n := by\n have h5 : (n : ℤ) % 2 = 0 := h3\n have h6 : (n : ℤ) = 2 * ((n : ℤ) / 2) := by\n omega\n linarith\n ring_nf at *\n <;> omega\n exact h2\n \n have hsum_diff : (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 0 then (nums k l : ℤ) else 0)) - (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 1 then (nums k l : ℤ) else 0)) = ∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * (nums k l : ℤ) := by\n have h₁ : (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 0 then (nums k l : ℤ) else 0)) - (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 1 then (nums k l : ℤ) else 0)) = ∑ k : Fin n, ∑ l : Fin n, ((if colors k l = 0 then (nums k l : ℤ) else 0) - (if colors k l = 1 then (nums k l : ℤ) else 0)) := by\n simp [Finset.sum_sub_distrib, Finset.sum_add_distrib]\n <;>\n simp_all [Finset.sum_sub_distrib]\n <;>\n rfl\n have h₂ : ∀ (k : Fin n) (l : Fin n), ((if colors k l = 0 then (nums k l : ℤ) else 0) - (if colors k l = 1 then (nums k l : ℤ) else 0)) = (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * (nums k l : ℤ) := by\n intro k l\n have h₃ : colors k l = 0 ∨ colors k l = 1 := by\n have h₄ : colors k l = 0 ∨ colors k l = 1 := by\n have h₅ : colors k l = 0 ∨ colors k l = 1 := by\n have : colors k l = 0 ∨ colors k l = 1 := by\n have h₆ : (colors k l : ℕ) < 2 := by\n have : (colors k l : ℕ) < 2 := by\n simp [Fin.is_lt]\n exact this\n omega\n exact this\n exact h₅\n exact h₄\n rcases h₃ with (h₃ | h₃)\n · \n simp [h₃]\n <;>\n (try norm_num) <;>\n (try ring_nf) <;>\n (try simp_all)\n <;>\n (try omega)\n · \n simp [h₃]\n <;>\n (try norm_num) <;>\n (try ring_nf) <;>\n (try simp_all)\n <;>\n (try omega)\n calc\n (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 0 then (nums k l : ℤ) else 0)) - (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 1 then (nums k l : ℤ) else 0)) = ∑ k : Fin n, ∑ l : Fin n, ((if colors k l = 0 then (nums k l : ℤ) else 0) - (if colors k l = 1 then (nums k l : ℤ) else 0)) := by rw [h₁]\n _ = ∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * (nums k l : ℤ) := by\n apply Finset.sum_congr rfl\n intro k _\n apply Finset.sum_congr rfl\n intro l _\n rw [h₂ k l]\n \n have hsum_split_zero : (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * (nums k l : ℤ)) = 0 := by\n have h₁ : (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * (nums k l : ℤ)) = ∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n + (l : ℤ) + 1) := by\n apply Finset.sum_congr rfl\n intro k _\n apply Finset.sum_congr rfl\n intro l _\n rw [hnums]\n <;> simp [Fin.val_mk]\n <;> norm_cast\n <;> ring_nf\n rw [h₁]\n have h₂ : (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n + (l : ℤ) + 1)) = (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) + (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) := by\n calc\n (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n + (l : ℤ) + 1)) = ∑ k : Fin n, ∑ l : Fin n, ((2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n) + (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) := by\n apply Finset.sum_congr rfl\n intro k _\n apply Finset.sum_congr rfl\n intro l _\n ring_nf\n _ = (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) + (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) := by\n simp [Finset.sum_add_distrib]\n rw [h₂]\n have h₃ : (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) = 0 := by\n have h₄ : ∀ (k : Fin n), (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) = 0 := by\n intro k\n have h₅ : (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := hrow_sum_zero k\n calc\n (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) = ∑ l : Fin n, ((k : ℤ) * n) * (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) := by\n apply Finset.sum_congr rfl\n intro l _\n ring_nf\n _ = ((k : ℤ) * n) * ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) := by\n rw [Finset.mul_sum]\n _ = ((k : ℤ) * n) * 0 := by rw [h₅]\n _ = 0 := by ring\n calc\n (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) = ∑ k : Fin n, (∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((k : ℤ) * n)) := by simp [Finset.sum_sigma']\n _ = ∑ k : Fin n, 0 := by\n apply Finset.sum_congr rfl\n intro k _\n rw [h₄ k]\n _ = 0 := by simp\n have h₄ : (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) = 0 := by\n have h₅ : ∀ (l : Fin n), (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) = 0 := by\n intro l\n exact hcol_sum_zero l\n calc\n (∑ k : Fin n, ∑ l : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) = ∑ l : Fin n, ∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1) := by\n rw [Finset.sum_comm]\n _ = ∑ l : Fin n, ((l : ℤ) + 1) * (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1)) := by\n apply Finset.sum_congr rfl\n intro l _\n calc\n (∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) * ((l : ℤ) + 1)) = ∑ k : Fin n, ((l : ℤ) + 1) * (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) := by\n apply Finset.sum_congr rfl\n intro k _\n ring_nf\n _ = ((l : ℤ) + 1) * ∑ k : Fin n, (2 * (if colors k l = 0 then (1 : ℤ) else 0) - 1) := by\n rw [Finset.mul_sum]\n _ = ∑ l : Fin n, ((l : ℤ) + 1) * 0 := by\n apply Finset.sum_congr rfl\n intro l _\n rw [h₅ l]\n _ = ∑ l : Fin n, 0 := by\n apply Finset.sum_congr rfl\n intro l _\n ring_nf\n _ = 0 := by simp\n rw [h₃, h₄]\n <;> simp\n \n have hfinal : (∑ k, ∑ l, (if (colors k l = 0) then (nums k l) else 0)) = (∑ k, ∑ l, (if (colors k l = 1) then (nums k l) else 0)) := by\n have h₁ : (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 0 then (nums k l : ℤ) else 0)) - (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 1 then (nums k l : ℤ) else 0)) = 0 := by\n rw [hsum_diff]\n rw [hsum_split_zero]\n have h₂ : (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 0 then (nums k l : ℤ) else 0)) = (∑ k : Fin n, ∑ l : Fin n, (if colors k l = 1 then (nums k l : ℤ) else 0)) := by\n linarith\n simpa using h₂\n \n exact hfinal"} {"name": "putnam_1964_b2", "proof_length": 1754, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Set Function Filter Topology\n\n\n", "signature": "theorem putnam_1964_b2\n(S : Type*) [Fintype S] [Nonempty S]\n(P : Finset (Set S))\n(hPP : ∀ T ∈ P, ∀ U ∈ P, T ∩ U ≠ ∅)\n(hPS : ¬∃ T : Set S, T ∉ P ∧ (∀ U ∈ P, T ∩ U ≠ ∅))\n: (P.card = 2 ^ (Fintype.card S - 1))", "src": "theorem putnam_1964_b2\n(S : Type*) [Fintype S] [Nonempty S]\n(P : Finset (Set S))\n(hPP : ∀ T ∈ P, ∀ U ∈ P, T ∩ U ≠ ∅)\n(hPS : ¬∃ T : Set S, T ∉ P ∧ (∀ U ∈ P, T ∩ U ≠ ∅))\n: (P.card = 2 ^ (Fintype.card S - 1)) := by \n have h_no_empty : ∀ (T : Set S), T ∈ P → T.Nonempty := by\n intro T hT\n have h₁ : T ∩ T ≠ ∅ := hPP T hT T hT\n have h₂ : T ∩ T = T := by simp [Set.ext_iff]\n rw [h₂] at h₁\n exact Set.nonempty_iff_ne_empty.mpr h₁\n \n have h_subset_or_compl : ∀ (A : Set S), A ∈ P ∨ Aᶜ ∈ P := by\n intro A\n by_contra! h\n have h₁ : A ∉ P := h.1\n have h₂ : Aᶜ ∉ P := h.2\n \n have h₃ : ∃ (U : Set S), U ∈ P ∧ A ∩ U = ∅ := by\n have h₄ : ¬(A ∉ P ∧ ∀ (U : Set S), U ∈ P → A ∩ U ≠ ∅) := by\n intro h₅\n have h₆ : ∃ (T : Set S), T ∉ P ∧ (∀ U ∈ P, T ∩ U ≠ ∅) := by\n refine' ⟨A, _⟩\n constructor\n · exact h₅.1\n · intro U hU\n have h₇ := h₅.2 U hU\n have h₈ : A ∩ U ≠ ∅ := h₇\n have h₉ : A ∩ U = U ∩ A := by\n ext x\n simp [Set.mem_inter_iff]\n <;> tauto\n have h₁₀ : U ∩ A ≠ ∅ := by\n intro h₁₁\n apply h₈\n simp_all [Set.ext_iff]\n <;> aesop\n simpa [Set.inter_comm] using h₁₀\n exact hPS h₆\n by_cases h₅ : A ∉ P\n · have h₆ : ¬(∀ (U : Set S), U ∈ P → A ∩ U ≠ ∅) := by\n intro h₇\n exact h₄ ⟨h₅, h₇⟩\n push_neg at h₆\n obtain ⟨U, hU, h₈⟩ := h₆\n refine' ⟨U, hU, _⟩\n have h₉ : A ∩ U = ∅ := by\n by_contra h₁₀\n have h₁₁ : A ∩ U ≠ ∅ := h₁₀\n simp_all [Set.ext_iff]\n <;> aesop\n exact h₉\n · exfalso\n simp_all\n \n have h₄ : ∃ (V : Set S), V ∈ P ∧ Aᶜ ∩ V = ∅ := by\n have h₅ : ¬(Aᶜ ∉ P ∧ ∀ (U : Set S), U ∈ P → Aᶜ ∩ U ≠ ∅) := by\n intro h₆\n have h₇ : ∃ (T : Set S), T ∉ P ∧ (∀ U ∈ P, T ∩ U ≠ ∅) := by\n refine' ⟨Aᶜ, _⟩\n constructor\n · exact h₆.1\n · intro U hU\n have h₈ := h₆.2 U hU\n have h₉ : Aᶜ ∩ U ≠ ∅ := h₈\n have h₁₀ : Aᶜ ∩ U = U ∩ Aᶜ := by\n ext x\n simp [Set.mem_inter_iff]\n <;> tauto\n have h₁₁ : U ∩ Aᶜ ≠ ∅ := by\n intro h₁₂\n apply h₉\n simp_all [Set.ext_iff]\n <;> aesop\n simpa [Set.inter_comm] using h₁₁\n exact hPS h₇\n by_cases h₆ : Aᶜ ∉ P\n · have h₇ : ¬(∀ (U : Set S), U ∈ P → Aᶜ ∩ U ≠ ∅) := by\n intro h₈\n exact h₅ ⟨h₆, h₈⟩\n push_neg at h₇\n obtain ⟨V, hV, h₈⟩ := h₇\n refine' ⟨V, hV, _⟩\n have h₉ : Aᶜ ∩ V = ∅ := by\n by_contra h₁₀\n have h₁₁ : Aᶜ ∩ V ≠ ∅ := h₁₀\n simp_all [Set.ext_iff]\n <;> aesop\n exact h₉\n · exfalso\n simp_all\n \n obtain ⟨U, hU, hU'⟩ := h₃\n obtain ⟨V, hV, hV'⟩ := h₄\n \n have h₅ : U ⊆ Aᶜ := by\n intro x hx\n by_contra h₆\n have h₇ : x ∈ A := by simp_all [Set.mem_compl_iff]\n have h₈ : x ∈ A ∩ U := Set.mem_inter h₇ hx\n rw [hU'] at h₈\n simp at h₈\n <;> aesop\n have h₆ : V ⊆ A := by\n intro x hx\n by_contra h₇\n have h₈ : x ∈ Aᶜ := by simp_all [Set.mem_compl_iff]\n have h₉ : x ∈ Aᶜ ∩ V := Set.mem_inter h₈ hx\n rw [hV'] at h₉\n simp at h₉\n <;> aesop\n \n have h₇ : U ∩ V = ∅ := by\n apply Set.eq_empty_of_forall_not_mem\n intro x hx\n have h₈ : x ∈ U := Set.mem_of_mem_inter_left hx\n have h₉ : x ∈ V := Set.mem_of_mem_inter_right hx\n have h₁₀ : x ∈ Aᶜ := h₅ h₈\n have h₁₁ : x ∈ A := h₆ h₉\n simp_all [Set.mem_compl_iff]\n <;> aesop\n \n have h₈ : U ∩ V ≠ ∅ := hPP U hU V hV\n simp_all [Set.ext_iff]\n <;> aesop\n \n have h_not_both : ∀ (A : Set S), A ∈ P → Aᶜ ∉ P := by\n intro A hA\n by_contra h\n have h₁ : Aᶜ ∈ P := h\n have h₂ : A ∩ Aᶜ = ∅ := by\n ext x\n simp [Set.mem_inter_iff]\n <;> tauto\n have h₃ : A ∩ Aᶜ ≠ ∅ := hPP A hA Aᶜ h₁\n rw [h₂] at h₃\n contradiction\n \n have h_card : P.card = 2 ^ (Fintype.card S - 1) := by\n classical\n \n let Q : Finset (Set S) := (Finset.univ : Finset (Set S)) \\ P\n \n have h₁ : P.card = Q.card := by\n \n have h₂ : ∀ (A : Set S), A ∈ P → Aᶜ ∈ Q := by\n intro A hA\n have h₃ : Aᶜ ∈ (Finset.univ : Finset (Set S)) := Finset.mem_univ _\n have h₄ : Aᶜ ∉ P := h_not_both A hA\n simp only [Q, Finset.mem_sdiff] at *\n tauto\n have h₃ : ∀ (A : Set S), A ∈ Q → Aᶜ ∈ P := by\n intro A hA\n have h₄ : A ∈ (Finset.univ : Finset (Set S)) := by\n simp only [Q, Finset.mem_sdiff] at hA\n tauto\n have h₅ : A ∉ P := by\n simp only [Q, Finset.mem_sdiff] at hA\n tauto\n have h₆ : A ∈ (Finset.univ : Finset (Set S)) := by tauto\n have h₇ : A ∈ P ∨ Aᶜ ∈ P := h_subset_or_compl A\n cases h₇ with\n | inl h₈ =>\n exfalso\n tauto\n | inr h₈ =>\n exact h₈\n \n have h₄ : P.card = Q.card := by\n \n have h₅ : P.card = Q.card := by\n \n have h₆ : ∀ (A : Set S), A ∈ P → Aᶜ ∈ Q := h₂\n have h₇ : ∀ (A : Set S), A ∈ Q → Aᶜ ∈ P := h₃\n \n have h₈ : P.card = Q.card := by\n \n apply Finset.card_bij' (fun A _ => Aᶜ) (fun A _ => Aᶜ)\n <;> simp_all [Set.ext_iff]\n <;>\n (try\n {\n aesop\n })\n <;>\n (try\n {\n tauto\n })\n <;>\n (try\n {\n intros\n <;>\n simp_all [Set.ext_iff]\n <;>\n tauto\n })\n <;>\n (try\n {\n intros\n <;>\n simp_all [Set.ext_iff]\n <;>\n tauto\n })\n exact h₈\n exact h₅\n exact h₄\n \n have h₂ : P.card + Q.card = 2 ^ Fintype.card S := by\n have h₃ : P.card + Q.card = (Finset.univ : Finset (Set S)).card := by\n have h₄ : Disjoint P Q := by\n rw [Finset.disjoint_left]\n intro A hA hA'\n simp only [Q, Finset.mem_sdiff] at hA'\n tauto\n have h₅ : P ∪ Q = (Finset.univ : Finset (Set S)) := by\n apply Finset.ext\n intro A\n simp only [Q, Finset.mem_union, Finset.mem_sdiff, Finset.mem_univ, true_and]\n <;>\n by_cases h₆ : A ∈ P <;> simp_all [h_subset_or_compl]\n <;>\n (try tauto)\n <;>\n (try\n {\n have h₇ := h_subset_or_compl A\n cases h₇ with\n | inl h₈ => tauto\n | inr h₈ =>\n have h₉ : Aᶜ ∈ P := h₈\n have h₁₀ : A ∈ P ∨ Aᶜ ∈ P := by tauto\n tauto\n })\n have h₆ : P.card + Q.card = (P ∪ Q).card := by\n rw [← Finset.card_union_add_card_inter P Q]\n have h₇ : P ∩ Q = ∅ := Finset.disjoint_iff_inter_eq_empty.mp h₄\n rw [h₇]\n simp\n rw [h₅] at h₆\n exact h₆\n have h₄ : (Finset.univ : Finset (Set S)).card = 2 ^ Fintype.card S := by\n simp [Fintype.card_fun]\n <;>\n simp_all [Fintype.card_fun]\n <;>\n ring_nf\n <;>\n simp_all [Fintype.card_fun]\n <;>\n norm_num\n <;>\n aesop\n linarith\n \n have h₃ : P.card * 2 = 2 ^ Fintype.card S := by\n have h₄ : P.card + Q.card = 2 ^ Fintype.card S := h₂\n have h₅ : P.card = Q.card := h₁\n linarith\n \n have h₄ : Fintype.card S ≥ 1 := by\n have h₅ : Nonempty S := inferInstance\n have h₆ : 0 < Fintype.card S := by\n apply Fintype.card_pos_iff.mpr\n exact ⟨Classical.choice h₅⟩\n omega\n have h₅ : P.card = 2 ^ (Fintype.card S - 1) := by\n have h₆ : P.card * 2 = 2 ^ Fintype.card S := h₃\n have h₇ : Fintype.card S ≥ 1 := h₄\n have h₈ : 2 ^ (Fintype.card S - 1) * 2 = 2 ^ Fintype.card S := by\n have h₉ : Fintype.card S - 1 + 1 = Fintype.card S := by\n have h₁₀ : Fintype.card S ≥ 1 := h₄\n omega\n calc\n 2 ^ (Fintype.card S - 1) * 2 = 2 ^ (Fintype.card S - 1) * 2 ^ 1 := by norm_num\n _ = 2 ^ ((Fintype.card S - 1) + 1) := by\n rw [← pow_add]\n _ = 2 ^ Fintype.card S := by\n rw [h₉]\n <;> simp [add_comm]\n have h₉ : P.card = 2 ^ (Fintype.card S - 1) := by\n have h₁₀ : P.card * 2 = 2 ^ Fintype.card S := h₃\n have h₁₁ : 2 ^ (Fintype.card S - 1) * 2 = 2 ^ Fintype.card S := h₈\n have h₁₂ : P.card = 2 ^ (Fintype.card S - 1) := by\n nlinarith\n exact h₁₂\n exact h₉\n exact h₅\n \n exact h_card"} {"name": "putnam_2007_a1", "proof_length": 5463, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\n\n\n\n", "signature": "theorem putnam_2007_a1\n (P : (ℝ → ℝ) → Prop)\n (P_def : ∀ f, P f ↔ ∃ x y, f x = y ∧ f y = x ∧ deriv f x * deriv f y = 1)\n (α : ℝ) :\n P (fun t ↦ α * t ^ 2 + α * t + 1 / 24) ↔ α ∈ (({2 / 3, 3 / 2, (13 + √601) / 12, (13 - √601) / 12}) : Set ℝ )", "src": "theorem putnam_2007_a1\n (P : (ℝ → ℝ) → Prop)\n (P_def : ∀ f, P f ↔ ∃ x y, f x = y ∧ f y = x ∧ deriv f x * deriv f y = 1)\n (α : ℝ) :\n P (fun t ↦ α * t ^ 2 + α * t + 1 / 24) ↔ α ∈ (({2 / 3, 3 / 2, (13 + √601) / 12, (13 - √601) / 12}) : Set ℝ ) :=\n by \n have h_main : P (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) ↔ α = 2 / 3 ∨ α = 3 / 2 ∨ α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12 := by\n have h₁ : P (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) ↔ ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := by\n have h₂ : P (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) ↔ ∃ x y, (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x = y ∧ (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) y = x ∧ deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x * deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) y = 1 := by\n rw [P_def]\n <;> simp\n rw [h₂]\n have h₃ : ∀ (x : ℝ), deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x = 2 * α * x + α := by\n intro x\n \n have h₄ : deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x = deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x := rfl\n rw [h₄]\n \n have h₅ : HasDerivAt (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) (2 * α * x + α) x := by\n \n have h₆ : HasDerivAt (fun t : ℝ => α * t ^ 2) (2 * α * x) x := by\n \n have h₇ : HasDerivAt (fun t : ℝ => t ^ 2) (2 * x) x := by\n simpa using (hasDerivAt_pow 2 x)\n have h₈ : HasDerivAt (fun t : ℝ => α * t ^ 2) (α * (2 * x)) x := by\n convert HasDerivAt.const_mul α h₇ using 1 <;> ring\n convert h₈ using 1 <;> ring\n have h₉ : HasDerivAt (fun t : ℝ => α * t) α x := by\n \n have h₁₀ : HasDerivAt (fun t : ℝ => t) 1 x := by\n simpa using hasDerivAt_id x\n have h₁₁ : HasDerivAt (fun t : ℝ => α * t) (α * 1) x := by\n convert HasDerivAt.const_mul α h₁₀ using 1 <;> ring\n convert h₁₁ using 1 <;> ring\n have h₁₂ : HasDerivAt (fun t : ℝ => (1 : ℝ) / 24) 0 x := by\n \n simpa using hasDerivAt_const x (1 / 24 : ℝ)\n \n have h₁₃ : HasDerivAt (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) (2 * α * x + α) x := by\n convert h₆.add h₉ |>.add h₁₂ using 1 <;> ring\n exact h₁₃\n \n have h₁₄ : deriv (fun t : ℝ => α * t ^ 2 + α * t + 1 / 24) x = 2 * α * x + α := by\n apply HasDerivAt.deriv\n exact h₅\n rw [h₁₄]\n \n constructor\n · intro h\n obtain ⟨x, y, h₁₅, h₁₆, h₁₇⟩ := h\n refine' ⟨x, y, _, _, _⟩ <;>\n (try simp_all [h₃]) <;>\n (try ring_nf at * <;> simp_all) <;>\n (try nlinarith)\n · intro h\n obtain ⟨x, y, h₁₅, h₁₆, h₁₇⟩ := h\n refine' ⟨x, y, _, _, _⟩ <;>\n (try simp_all [h₃]) <;>\n (try ring_nf at * <;> simp_all) <;>\n (try nlinarith)\n rw [h₁]\n constructor\n · \n intro h\n have h₂ : ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := h\n obtain ⟨x, y, h₃, h₄, h₅⟩ := h₂\n have h₆ : (x - y) * (α * (x + y + 1) + 1) = 0 := by\n have h₇ : α * x ^ 2 + α * x + 1 / 24 = y := h₃\n have h₈ : α * y ^ 2 + α * y + 1 / 24 = x := h₄\n have h₉ : α * (x ^ 2 - y ^ 2) + α * (x - y) = (y - x) := by\n linarith\n have h₁₀ : α * (x - y) * (x + y) + α * (x - y) = -(x - y) := by\n linarith\n have h₁₁ : (x - y) * (α * (x + y) + α + 1) = 0 := by\n linarith\n have h₁₂ : (x - y) * (α * (x + y + 1) + 1) = 0 := by\n linarith\n exact h₁₂\n by_cases h₇ : x = y\n · \n have h₈ : α * x ^ 2 + α * x + 1 / 24 = x := by\n linarith\n have h₉ : (2 * α * x + α) * (2 * α * x + α) = 1 := by\n have h₁₀ : (2 * α * x + α) * (2 * α * y + α) = 1 := h₅\n have h₁₁ : (2 * α * x + α) * (2 * α * x + α) = 1 := by\n simpa [h₇] using h₁₀\n exact h₁₁\n have h₁₀ : (2 * α * x + α) = 1 ∨ (2 * α * x + α) = -1 := by\n have h₁₁ : (2 * α * x + α) ^ 2 = 1 := by\n nlinarith\n have h₁₂ : (2 * α * x + α) = 1 ∨ (2 * α * x + α) = -1 := by\n apply or_iff_not_imp_left.mpr\n intro h₁₃\n apply eq_of_sub_eq_zero\n apply mul_left_cancel₀ (sub_ne_zero.mpr h₁₃)\n nlinarith\n exact h₁₂\n cases h₁₀ with\n | inl h₁₀ =>\n \n have h₁₁ : 2 * α * x + α = 1 := h₁₀\n have h₁₂ : α ≠ 0 := by\n by_contra h₁₃\n rw [h₁₃] at h₁₁\n norm_num at h₁₁\n <;> linarith\n have h₁₃ : x = (1 - α) / (2 * α) := by\n have h₁₄ : 2 * α * x + α = 1 := h₁₁\n field_simp at h₁₄ ⊢\n nlinarith\n have h₁₄ : α * x ^ 2 + (α - 1) * x + 1 / 24 = 0 := by\n have h₁₅ : α * x ^ 2 + α * x + 1 / 24 = x := h₈\n linarith\n rw [h₁₃] at h₁₄\n have h₁₅ : α * ((1 - α) / (2 * α)) ^ 2 + (α - 1) * ((1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₄\n have h₁₆ : 6 * α ^ 2 - 13 * α + 6 = 0 := by\n field_simp at h₁₅\n ring_nf at h₁₅ ⊢\n nlinarith [sq_pos_of_ne_zero h₁₂]\n have h₁₇ : α = 2 / 3 ∨ α = 3 / 2 := by\n have h₁₈ : (α - 2 / 3) * (α - 3 / 2) = 0 := by\n nlinarith\n have h₁₉ : α - 2 / 3 = 0 ∨ α - 3 / 2 = 0 := by\n apply eq_zero_or_eq_zero_of_mul_eq_zero h₁₈\n cases h₁₉ with\n | inl h₁₉ =>\n have h₂₀ : α = 2 / 3 := by linarith\n exact Or.inl h₂₀\n | inr h₁₉ =>\n have h₂₀ : α = 3 / 2 := by linarith\n exact Or.inr h₂₀\n cases h₁₇ with\n | inl h₁₇ =>\n exact Or.inl h₁₇\n | inr h₁₇ =>\n exact Or.inr (Or.inl h₁₇)\n | inr h₁₀ =>\n \n have h₁₁ : 2 * α * x + α = -1 := h₁₀\n have h₁₂ : α ≠ 0 := by\n by_contra h₁₃\n rw [h₁₃] at h₁₁\n norm_num at h₁₁\n <;> linarith\n have h₁₃ : x = (-1 - α) / (2 * α) := by\n have h₁₄ : 2 * α * x + α = -1 := h₁₁\n field_simp at h₁₄ ⊢\n nlinarith\n have h₁₄ : α * x ^ 2 + (α - 1) * x + 1 / 24 = 0 := by\n have h₁₅ : α * x ^ 2 + α * x + 1 / 24 = x := h₈\n linarith\n rw [h₁₃] at h₁₄\n have h₁₅ : α * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₄\n have h₁₆ : 6 * α ^ 2 - 13 * α - 18 = 0 := by\n field_simp at h₁₅\n ring_nf at h₁₅ ⊢\n nlinarith [sq_pos_of_ne_zero h₁₂]\n have h₁₇ : α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12 := by\n have h₁₈ : α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12 := by\n have h₁₉ : α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12 := by\n have h₂₀ : (α - (13 + Real.sqrt 601) / 12) * (α - (13 - Real.sqrt 601) / 12) = 0 := by\n have h₂₁ : Real.sqrt 601 ≥ 0 := Real.sqrt_nonneg _\n nlinarith [Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n have h₂₂ : α - (13 + Real.sqrt 601) / 12 = 0 ∨ α - (13 - Real.sqrt 601) / 12 = 0 := by\n apply eq_zero_or_eq_zero_of_mul_eq_zero h₂₀\n cases h₂₂ with\n | inl h₂₂ =>\n have h₂₃ : α = (13 + Real.sqrt 601) / 12 := by linarith\n exact Or.inl h₂₃\n | inr h₂₂ =>\n have h₂₃ : α = (13 - Real.sqrt 601) / 12 := by linarith\n exact Or.inr h₂₃\n exact h₁₉\n exact h₁₈\n cases h₁₇ with\n | inl h₁₇ =>\n exact Or.inr (Or.inr (Or.inl h₁₇))\n | inr h₁₇ =>\n exact Or.inr (Or.inr (Or.inr h₁₇))\n · \n have h₈ : α * (x + y + 1) + 1 = 0 := by\n apply mul_left_cancel₀ (sub_ne_zero.mpr h₇)\n nlinarith\n have h₉ : (2 * α * x + α) + (2 * α * y + α) = -2 := by\n have h₁₀ : α * (x + y + 1) + 1 = 0 := h₈\n have h₁₁ : α * (x + y + 1) = -1 := by linarith\n have h₁₂ : 2 * α * (x + y + 1) = -2 := by linarith\n have h₁₃ : 2 * α * x + 2 * α * y + 2 * α = -2 := by linarith\n linarith\n have h₁₀ : (2 * α * x + α) * (2 * α * y + α) = 1 := h₅\n have h₁₁ : (2 * α * x + α) = -1 := by\n have h₁₂ : (2 * α * x + α) + (2 * α * y + α) = -2 := h₉\n have h₁₃ : (2 * α * x + α) * (2 * α * y + α) = 1 := h₁₀\n have h₁₄ : (2 * α * x + α) = -1 := by\n nlinarith [sq_nonneg ((2 * α * x + α) - (2 * α * y + α))]\n exact h₁₄\n have h₁₂ : (2 * α * y + α) = -1 := by\n have h₁₃ : (2 * α * x + α) + (2 * α * y + α) = -2 := h₉\n have h₁₄ : (2 * α * x + α) = -1 := h₁₁\n linarith\n have h₁₃ : 2 * α * x + α = -1 := h₁₁\n have h₁₄ : 2 * α * y + α = -1 := h₁₂\n have h₁₅ : x = y := by\n have h₁₆ : 2 * α * x + α = 2 * α * y + α := by linarith\n have h₁₇ : 2 * α * x = 2 * α * y := by linarith\n by_cases h₁₈ : α = 0\n · have h₁₉ : α = 0 := h₁₈\n rw [h₁₉] at h₁₃\n norm_num at h₁₃\n <;> linarith\n · have h₁₉ : α ≠ 0 := h₁₈\n have h₂₀ : x = y := by\n apply mul_left_cancel₀ (show (2 : ℝ) * α ≠ 0 by\n intro h₂₁\n apply h₁₉\n linarith)\n linarith\n exact h₂₀\n contradiction\n · \n intro h\n have h₂ : α = 2 / 3 ∨ α = 3 / 2 ∨ α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12 := h\n cases h₂ with\n | inl h₂ =>\n \n have h₃ : α = 2 / 3 := h₂\n have h₄ : ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := by\n use 1 / 4, 1 / 4\n rw [h₃]\n norm_num\n <;>\n (try ring_nf) <;>\n (try norm_num) <;>\n (try linarith)\n exact h₄\n | inr h₂ =>\n cases h₂ with\n | inl h₂ =>\n \n have h₃ : α = 3 / 2 := h₂\n have h₄ : ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := by\n use -1 / 6, -1 / 6\n rw [h₃]\n norm_num\n <;>\n (try ring_nf) <;>\n (try norm_num) <;>\n (try linarith)\n exact h₄\n | inr h₂ =>\n cases h₂ with\n | inl h₂ =>\n \n have h₃ : α = (13 + Real.sqrt 601) / 12 := h₂\n have h₄ : ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := by\n have h₅ : α ≠ 0 := by\n rw [h₃]\n nlinarith [Real.sqrt_nonneg 601, Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n use (-1 - α) / (2 * α), (-1 - α) / (2 * α)\n constructor\n · \n have h₆ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₇ : α ≠ 0 := h₅\n have h₈ : 6 * α ^ 2 - 13 * α - 18 = 0 := by\n rw [h₃]\n nlinarith [Real.sq_sqrt (show (0 : ℝ) ≤ 601 by norm_num)]\n have h₉ : (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 = 0 := by\n have h₁₀ : 6 * α ^ 2 = 13 * α + 18 := by linarith\n field_simp [h₇]\n nlinarith\n have h₁₀ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := by\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 := by\n field_simp [h₇]\n <;> ring_nf\n <;> field_simp [h₇]\n <;> ring_nf\n rw [h₁₁]\n linarith\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₁₂ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₀\n have h₁₃ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n linarith\n exact h₁₃\n exact h₁₁\n exact h₆\n · constructor\n · \n have h₆ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₇ : α ≠ 0 := h₅\n have h₈ : 6 * α ^ 2 - 13 * α - 18 = 0 := by\n rw [h₃]\n nlinarith [Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n have h₉ : (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 = 0 := by\n have h₁₀ : 6 * α ^ 2 = 13 * α + 18 := by linarith\n field_simp [h₇]\n nlinarith\n have h₁₀ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := by\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 := by\n field_simp [h₇]\n <;> ring_nf\n <;> field_simp [h₇]\n <;> ring_nf\n rw [h₁₁]\n linarith\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₁₂ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₀\n have h₁₃ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n linarith\n exact h₁₃\n exact h₁₁\n linarith\n · \n have h₆ : (2 * α * ((-1 - α) / (2 * α)) + α) * (2 * α * ((-1 - α) / (2 * α)) + α) = 1 := by\n have h₇ : α ≠ 0 := h₅\n field_simp [h₇]\n <;> ring_nf\n <;> nlinarith [Real.sqrt_nonneg 601, Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n exact h₆\n exact h₄\n | inr h₂ =>\n \n have h₃ : α = (13 - Real.sqrt 601) / 12 := h₂\n have h₄ : ∃ (x y : ℝ), (α * x ^ 2 + α * x + 1 / 24 : ℝ) = y ∧ (α * y ^ 2 + α * y + 1 / 24 : ℝ) = x ∧ (2 * α * x + α) * (2 * α * y + α) = 1 := by\n have h₅ : α ≠ 0 := by\n rw [h₃]\n nlinarith [Real.sqrt_nonneg 601, Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n use (-1 - α) / (2 * α), (-1 - α) / (2 * α)\n constructor\n · \n have h₆ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₇ : α ≠ 0 := h₅\n have h₈ : 6 * α ^ 2 - 13 * α - 18 = 0 := by\n rw [h₃]\n nlinarith [Real.sq_sqrt (show (0 : ℝ) ≤ 601 by norm_num)]\n have h₉ : (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 = 0 := by\n have h₁₀ : 6 * α ^ 2 = 13 * α + 18 := by linarith\n field_simp [h₇]\n nlinarith\n have h₁₀ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := by\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 := by\n field_simp [h₇]\n <;> ring_nf\n <;> field_simp [h₇]\n <;> ring_nf\n rw [h₁₁]\n linarith\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₁₂ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₀\n have h₁₃ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n linarith\n exact h₁₃\n exact h₁₁\n exact h₆\n · constructor\n · \n have h₆ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₇ : α ≠ 0 := h₅\n have h₈ : 6 * α ^ 2 - 13 * α - 18 = 0 := by\n rw [h₃]\n nlinarith [Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n have h₉ : (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 = 0 := by\n have h₁₀ : 6 * α ^ 2 = 13 * α + 18 := by linarith\n field_simp [h₇]\n nlinarith\n have h₁₀ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := by\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = (3 + 2 * α - α ^ 2) / (4 * α) + 1 / 24 := by\n field_simp [h₇]\n <;> ring_nf\n <;> field_simp [h₇]\n <;> ring_nf\n rw [h₁₁]\n linarith\n have h₁₁ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n have h₁₂ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + (α - 1) * ((-1 - α) / (2 * α)) + 1 / 24 = 0 := h₁₀\n have h₁₃ : (α : ℝ) * ((-1 - α) / (2 * α)) ^ 2 + α * ((-1 - α) / (2 * α)) + 1 / 24 = (-1 - α) / (2 * α) := by\n linarith\n exact h₁₃\n exact h₁₁\n linarith\n · \n have h₆ : (2 * α * ((-1 - α) / (2 * α)) + α) * (2 * α * ((-1 - α) / (2 * α)) + α) = 1 := by\n have h₇ : α ≠ 0 := h₅\n field_simp [h₇]\n <;> ring_nf\n <;> nlinarith [Real.sqrt_nonneg 601, Real.sq_sqrt (show 0 ≤ 601 by norm_num)]\n exact h₆\n exact h₄\n \n have h_final : (α = 2 / 3 ∨ α = 3 / 2 ∨ α = (13 + Real.sqrt 601) / 12 ∨ α = (13 - Real.sqrt 601) / 12) ↔ α ∈ (({2 / 3, 3 / 2, (13 + √601) / 12, (13 - √601) / 12}) : Set ℝ) := by\n constructor\n · \n intro h\n simp only [Set.mem_insert_iff, Set.mem_singleton_iff]\n tauto\n · \n intro h\n simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at h\n tauto\n \n have h_result : P (fun t ↦ α * t ^ 2 + α * t + 1 / 24) ↔ α ∈ (({2 / 3, 3 / 2, (13 + √601) / 12, (13 - √601) / 12}) : Set ℝ) := by\n rw [h_main]\n rw [h_final]\n <;>\n simp_all\n <;>\n tauto\n \n exact h_result"} {"name": "putnam_1970_b5", "proof_length": 2134, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Metric Set EuclideanGeometry Filter Topology\n\n\n", "signature": "theorem putnam_1970_b5\n(ramp : ℤ → (ℝ → ℝ))\n(ramp_def : ramp = fun (n : ℤ) => (fun (x : ℝ) => if x ≤ -n then (-n : ℝ) else (if -n < x ∧ x ≤ n then x else (n : ℝ))))\n(F : ℝ → ℝ)\n: Continuous F ↔ (∀ n : ℕ, Continuous ((ramp n) ∘ F))", "src": "theorem putnam_1970_b5\n(ramp : ℤ → (ℝ → ℝ))\n(ramp_def : ramp = fun (n : ℤ) => (fun (x : ℝ) => if x ≤ -n then (-n : ℝ) else (if -n < x ∧ x ≤ n then x else (n : ℝ))))\n(F : ℝ → ℝ)\n: Continuous F ↔ (∀ n : ℕ, Continuous ((ramp n) ∘ F)) := by \n have h_ramp_def : ∀ (n : ℤ) (x : ℝ), ramp n x = if x ≤ -n then (-n : ℝ) else (if -n < x ∧ x ≤ n then x else (n : ℝ)) := by\n intro n x\n rw [ramp_def]\n <;> simp [n]\n <;> aesop\n \n have h_imp : Continuous F → (∀ n : ℕ, Continuous ((ramp n) ∘ F)) := by\n intro hF\n intro n\n have h₁ : Continuous (ramp n) := by\n have h₂ : Continuous (fun x : ℝ => min (max x (-(n : ℝ))) (n : ℝ)) := by\n continuity\n have h₃ : (ramp n) = (fun x : ℝ => min (max x (-(n : ℝ))) (n : ℝ)) := by\n funext x\n have h₄ : ramp n x = if x ≤ (-(n : ℝ)) then (-(n : ℝ)) else (if (-(n : ℝ) : ℝ) < x ∧ x ≤ (n : ℝ) then x else (n : ℝ)) := by\n have h₅ := h_ramp_def (n : ℤ) x\n simp [Int.cast_neg, Int.cast_ofNat] at h₅ ⊢\n <;>\n (try norm_num at h₅ ⊢) <;>\n (try ring_nf at h₅ ⊢) <;>\n (try simp_all) <;>\n (try linarith)\n <;>\n (try\n {\n split_ifs at h₅ ⊢ <;>\n simp_all [Int.cast_neg, Int.cast_ofNat] <;>\n norm_num at * <;>\n (try linarith)\n })\n rw [h₄]\n split_ifs <;>\n (try {\n simp_all [max_eq_left, max_eq_right, min_eq_left, min_eq_right, le_of_lt]\n <;>\n (try { nlinarith }) <;>\n (try { linarith })\n }) <;>\n (try {\n cases' le_total x (n : ℝ) with h₆ h₆ <;>\n simp_all [max_eq_left, max_eq_right, min_eq_left, min_eq_right, le_of_lt] <;>\n (try { nlinarith }) <;>\n (try { linarith })\n })\n rw [h₃]\n exact h₂\n \n exact h₁.comp hF\n \n have h_conv : (∀ n : ℕ, Continuous ((ramp n) ∘ F)) → Continuous F := by\n intro h\n have h₁ : Continuous F := by\n have h₂ : ∀ (x₀ : ℝ), ContinuousAt F x₀ := by\n intro x₀\n \n have h₃ : ∀ (ε : ℝ), ε > 0 → (∃ (δ : ℝ), δ > 0 ∧ ∀ (x : ℝ), |x - x₀| < δ → |F x - F x₀| < ε) := by\n intro ε εpos\n \n have h₄ : ∃ (n : ℕ), (n : ℝ) > |F x₀| + ε := by\n obtain ⟨n, hn⟩ := exists_nat_gt (|F x₀| + ε)\n refine' ⟨n, _⟩\n exact_mod_cast hn\n obtain ⟨n, hn⟩ := h₄\n have h₅ : (n : ℝ) > |F x₀| + ε := hn\n have h₆ : Continuous ((ramp n) ∘ F) := h n\n have h₇ : ContinuousAt ((ramp n) ∘ F) x₀ := h₆.continuousAt\n \n have h₈ : ∀ (ε : ℝ), ε > 0 → (∃ (δ : ℝ), δ > 0 ∧ ∀ (x : ℝ), |x - x₀| < δ → |(ramp n ∘ F) x - (ramp n ∘ F) x₀| < ε) := by\n intro ε εpos\n have h₉ : ContinuousAt ((ramp n) ∘ F) x₀ := h₇\n exact Metric.continuousAt_iff.mp h₉ ε εpos\n have h₉ : ∃ (δ : ℝ), δ > 0 ∧ ∀ (x : ℝ), |x - x₀| < δ → |(ramp n ∘ F) x - (ramp n ∘ F) x₀| < ε := h₈ ε εpos\n obtain ⟨δ, δpos, hδ⟩ := h₉\n use δ\n constructor\n · exact δpos\n · intro x hx\n have h₁₀ : |(ramp n ∘ F) x - (ramp n ∘ F) x₀| < ε := hδ x hx\n have h₁₁ : (ramp n ∘ F) x = ramp n (F x) := rfl\n have h₁₂ : (ramp n ∘ F) x₀ = ramp n (F x₀) := rfl\n rw [h₁₁, h₁₂] at h₁₀\n \n have h₁₃ : ramp n (F x₀) = F x₀ := by\n have h₁₄ : (F x₀ : ℝ) ≤ (n : ℝ) := by\n have h₁₅ : |F x₀| + ε < (n : ℝ) := by linarith\n have h₁₆ : |F x₀| < (n : ℝ) := by linarith\n have h₁₇ : F x₀ ≤ |F x₀| := by\n cases' abs_cases (F x₀) with h₁₈ h₁₈ <;> linarith\n linarith\n have h₁₅ : (F x₀ : ℝ) > (-(n : ℝ)) := by\n have h₁₆ : |F x₀| + ε < (n : ℝ) := by linarith\n have h₁₇ : |F x₀| < (n : ℝ) := by linarith\n have h₁₈ : - (n : ℝ) < F x₀ := by\n cases' abs_cases (F x₀) with h₁₉ h₁₉ <;> linarith\n linarith\n have h₁₆ : (F x₀ : ℝ) > (-(n : ℝ)) ∧ (F x₀ : ℝ) ≤ (n : ℝ) := ⟨h₁₅, h₁₄⟩\n have h₁₇ : ramp n (F x₀) = (F x₀ : ℝ) := by\n have h₁₈ : ramp n (F x₀) = if (F x₀ : ℝ) ≤ (-(n : ℝ)) then (-(n : ℝ)) else (if (-(n : ℝ)) < (F x₀ : ℝ) ∧ (F x₀ : ℝ) ≤ (n : ℝ) then (F x₀ : ℝ) else (n : ℝ)) := by\n rw [h_ramp_def]\n <;> simp [Int.cast_neg, Int.cast_ofNat]\n <;> norm_num\n <;>\n (try\n {\n ring_nf\n <;>\n norm_cast\n })\n <;>\n (try\n {\n simp_all [Int.cast_neg, Int.cast_ofNat]\n <;>\n norm_num\n <;>\n linarith\n })\n rw [h₁₈]\n have h₁₉ : ¬((F x₀ : ℝ) ≤ (-(n : ℝ))) := by\n intro h₂₀\n have h₂₁ : (F x₀ : ℝ) ≤ (-(n : ℝ)) := h₂₀\n have h₂₂ : (-(n : ℝ)) < (F x₀ : ℝ) := by\n have h₂₃ : |F x₀| + ε < (n : ℝ) := by linarith\n have h₂₄ : |F x₀| < (n : ℝ) := by linarith\n cases' abs_cases (F x₀) with h₂₅ h₂₅ <;> linarith\n linarith\n have h₂₀ : (-(n : ℝ)) < (F x₀ : ℝ) ∧ (F x₀ : ℝ) ≤ (n : ℝ) := h₁₆\n split_ifs at * <;> simp_all [h₁₉] <;>\n (try { contradiction }) <;>\n (try { linarith })\n rw [h₁₇]\n have h₁₄ : ramp n (F x) = F x := by\n by_contra h₁₅\n have h₁₆ : ramp n (F x) ≠ F x := h₁₅\n have h₁₇ : ramp n (F x) = (-(n : ℝ)) ∨ ramp n (F x) = (n : ℝ) := by\n have h₁₈ : ramp n (F x) = if (F x : ℝ) ≤ (-(n : ℝ)) then (-(n : ℝ)) else (if (-(n : ℝ)) < (F x : ℝ) ∧ (F x : ℝ) ≤ (n : ℝ) then (F x : ℝ) else (n : ℝ)) := by\n rw [h_ramp_def]\n <;> simp [Int.cast_neg, Int.cast_ofNat]\n <;> norm_num\n <;>\n (try\n {\n ring_nf\n <;>\n norm_cast\n })\n <;>\n (try\n {\n simp_all [Int.cast_neg, Int.cast_ofNat]\n <;>\n norm_num\n <;>\n linarith\n })\n rw [h₁₈] at *\n split_ifs at * <;>\n (try { simp_all }) <;>\n (try {\n left\n <;>\n linarith\n }) <;>\n (try {\n right\n <;>\n linarith\n }) <;>\n (try {\n exfalso\n apply h₁₆\n <;>\n simp_all\n })\n cases h₁₇ with\n | inl h₁₇ =>\n have h₁₈ : ramp n (F x) = (-(n : ℝ)) := h₁₇\n have h₁₉ : |(ramp n (F x) : ℝ) - (ramp n (F x₀) : ℝ)| < ε := by simpa [h₁₃] using h₁₀\n have h₂₀ : |(-(n : ℝ) : ℝ) - (F x₀ : ℝ)| < ε := by simpa [h₁₈, h₁₃] using h₁₉\n have h₂₁ : (n : ℝ) > |F x₀| + ε := by exact_mod_cast hn\n have h₂₂ : |(-(n : ℝ) : ℝ) - (F x₀ : ℝ)| ≥ (n : ℝ) - |F x₀| := by\n cases' abs_cases (F x₀) with h₂₃ h₂₃ <;>\n cases' abs_cases (-(n : ℝ) - F x₀) with h₂₄ h₂₄ <;>\n linarith\n have h₂₃ : (n : ℝ) - |F x₀| > ε := by linarith\n linarith\n | inr h₁₇ =>\n have h₁₈ : ramp n (F x) = (n : ℝ) := h₁₇\n have h₁₉ : |(ramp n (F x) : ℝ) - (ramp n (F x₀) : ℝ)| < ε := by simpa [h₁₃] using h₁₀\n have h₂₀ : |(n : ℝ) - (F x₀ : ℝ)| < ε := by simpa [h₁₈, h₁₃] using h₁₉\n have h₂₁ : (n : ℝ) > |F x₀| + ε := by exact_mod_cast hn\n have h₂₂ : |(n : ℝ) - (F x₀ : ℝ)| ≥ (n : ℝ) - |F x₀| := by\n cases' abs_cases (F x₀) with h₂₃ h₂₃ <;>\n cases' abs_cases ((n : ℝ) - F x₀) with h₂₄ h₂₄ <;>\n linarith\n have h₂₃ : (n : ℝ) - |F x₀| > ε := by linarith\n linarith\n have h₁₅ : |F x - F x₀| < ε := by\n have h₁₆ : ramp n (F x) = F x := h₁₄\n have h₁₇ : ramp n (F x₀) = F x₀ := h₁₃\n have h₁₈ : |(ramp n (F x) : ℝ) - (ramp n (F x₀) : ℝ)| < ε := by simpa [h₁₆, h₁₇] using h₁₀\n simpa [h₁₆, h₁₇] using h₁₈\n exact h₁₅\n <;>\n simp_all [abs_lt]\n <;>\n linarith\n \n have h₄ : ContinuousAt F x₀ := by\n rw [Metric.continuousAt_iff]\n intro ε εpos\n obtain ⟨δ, δpos, hδ⟩ := h₃ ε εpos\n refine' ⟨δ, δpos, _⟩\n intro x hx\n have h₅ : |F x - F x₀| < ε := hδ x hx\n exact h₅\n exact h₄\n \n exact continuous_iff_continuousAt.mpr h₂\n exact h₁\n \n constructor\n · intro h\n exact h_imp h\n · intro h\n exact h_conv h"} {"name": "putnam_1968_a1", "proof_length": 1084, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\n\n", "signature": "theorem putnam_1968_a1\n: 22/7 - Real.pi = ∫ x in (0)..1, x^4 * (1 - x)^4 / (1 + x^2)", "src": "theorem putnam_1968_a1\n: 22/7 - Real.pi = ∫ x in (0)..1, x^4 * (1 - x)^4 / (1 + x^2) := by \n have h_main : (∫ x in (0)..1, x^4 * (1 - x)^4 / (1 + x^2)) = 22/7 - Real.pi := by\n have h₁ : (∫ x in (0)..1, x^4 * (1 - x)^4 / (1 + x^2)) = (∫ x in (0)..1, (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ) - 4 / (1 + x^2)) := by\n have h₁₁ : ∀ (x : ℝ), x^4 * (1 - x)^4 / (1 + x^2) = (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ) - 4 / (1 + x^2) := by\n intro x\n have h₁₂ : (1 + x^2 : ℝ) ≠ 0 := by nlinarith\n have h₁₃ : x^4 * (1 - x)^4 = (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ) * (1 + x^2) - 4 := by\n ring_nf\n <;>\n nlinarith [sq_nonneg (x ^ 2), sq_nonneg (x ^ 3), sq_nonneg (x - 1), sq_nonneg (x + 1)]\n have h₁₄ : x^4 * (1 - x)^4 / (1 + x^2) = ((x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ) * (1 + x^2) - 4) / (1 + x^2) := by\n rw [h₁₃]\n rw [h₁₄]\n field_simp [h₁₂]\n <;> ring_nf\n <;> field_simp [h₁₂]\n <;> ring_nf\n \n congr\n ext x\n rw [h₁₁ x]\n rw [h₁]\n \n have h₂ : (∫ x in (0)..1, (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ) - 4 / (1 + x^2)) = (∫ x in (0)..1, (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ)) - (∫ x in (0)..1, (4 : ℝ) / (1 + x^2)) := by\n apply intervalIntegral.integral_sub\n · \n apply Continuous.intervalIntegrable\n continuity\n · \n apply Continuous.intervalIntegrable\n \n have h₃ : Continuous (fun x : ℝ => (4 : ℝ) / (1 + x ^ 2)) := by\n apply Continuous.div\n · exact continuous_const\n · exact Continuous.add continuous_const (continuous_pow 2)\n · intro x\n have h₄ : (1 + x ^ 2 : ℝ) ≠ 0 := by nlinarith\n exact h₄\n exact h₃\n rw [h₂]\n \n have h₃ : (∫ x in (0)..1, (x^6 - 4*x^5 + 5*x^4 - 4*x^2 + 4 : ℝ)) = (22 / 7 : ℝ) := by\n norm_num [integral_id, mul_comm]\n <;>\n ring_nf\n <;>\n norm_num\n <;>\n linarith [Real.pi_pos]\n \n have h₄ : (∫ x in (0)..1, (4 : ℝ) / (1 + x^2)) = Real.pi := by\n have h₄₁ : (∫ x in (0)..1, (4 : ℝ) / (1 + x ^ 2)) = 4 * (∫ x in (0)..1, (1 : ℝ) / (1 + x ^ 2)) := by\n \n have h₄₂ : (∫ x in (0)..1, (4 : ℝ) / (1 + x ^ 2)) = (∫ x in (0)..1, 4 * (1 : ℝ) / (1 + x ^ 2)) := by\n congr\n ext x\n <;> ring_nf\n rw [h₄₂]\n have h₄₃ : (∫ x in (0)..1, 4 * (1 : ℝ) / (1 + x ^ 2)) = 4 * (∫ x in (0)..1, (1 : ℝ) / (1 + x ^ 2)) := by\n \n simp [intervalIntegral.integral_comp_mul_left (fun x => (1 : ℝ) / (1 + x ^ 2))]\n <;>\n norm_num\n <;>\n field_simp\n <;>\n ring_nf\n <;>\n norm_num\n <;>\n linarith [Real.pi_pos]\n rw [h₄₃]\n rw [h₄₁]\n have h₄₄ : (∫ x in (0)..1, (1 : ℝ) / (1 + x ^ 2)) = Real.pi / 4 := by\n \n have h₄₅ : (∫ x in (0)..1, (1 : ℝ) / (1 + x ^ 2)) = Real.arctan 1 - Real.arctan 0 := by\n \n rw [integral_one_div_one_add_sq]\n <;>\n norm_num\n rw [h₄₅]\n have h₄₆ : Real.arctan 1 = Real.pi / 4 := by\n \n norm_num [Real.arctan_one]\n have h₄₇ : Real.arctan 0 = 0 := by\n \n norm_num [Real.arctan_zero]\n rw [h₄₆, h₄₇]\n <;>\n ring_nf\n <;>\n norm_num\n rw [h₄₄]\n <;>\n ring_nf\n <;>\n norm_num\n \n rw [h₃, h₄]\n <;>\n ring_nf\n <;>\n norm_num\n \n have h_final : 22/7 - Real.pi = ∫ x in (0)..1, x^4 * (1 - x)^4 / (1 + x^2) := by\n rw [h_main]\n <;>\n linarith [Real.pi_pos]\n \n exact h_final"} {"name": "putnam_1991_b1", "proof_length": 3313, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Filter Topology\n\n\n\n", "signature": "theorem putnam_1991_b1\n (m S : ℤ → ℤ)\n (A : ℤ)\n (a : ℕ → ℤ)\n (hm : ∀ n, 0 ≤ n → (m n) ^ 2 ≤ n ∧ (∀ m' : ℤ, m' ^ 2 ≤ n → m' ≤ m n))\n (hS : ∀ n, 0 ≤ n → S n = n - (m n) ^ 2)\n (ha : a 0 = A ∧ (∀ k, a (k + 1) = a k + S (a k)))\n (hA : A > 0) :\n (∃ (K : ℕ) (c : ℕ), ∀ k ≥ K, a k = c) ↔ A ∈ (({A : ℤ | ∃ x > 0, A = x ^ 2}) : Set ℤ )", "src": "theorem putnam_1991_b1\n (m S : ℤ → ℤ)\n (A : ℤ)\n (a : ℕ → ℤ)\n (hm : ∀ n, 0 ≤ n → (m n) ^ 2 ≤ n ∧ (∀ m' : ℤ, m' ^ 2 ≤ n → m' ≤ m n))\n (hS : ∀ n, 0 ≤ n → S n = n - (m n) ^ 2)\n (ha : a 0 = A ∧ (∀ k, a (k + 1) = a k + S (a k)))\n (hA : A > 0) :\n (∃ (K : ℕ) (c : ℕ), ∀ k ≥ K, a k = c) ↔ A ∈ (({A : ℤ | ∃ x > 0, A = x ^ 2}) : Set ℤ ) := by \n have h_nonneg : ∀ (k : ℕ), a k ≥ 0 := by\n intro k\n induction k with\n | zero =>\n have h₁ : a 0 = A := ha.1\n linarith\n | succ k ih =>\n have h₁ : a (k + 1) = a k + S (a k) := ha.2 k\n rw [h₁]\n have h₂ : 0 ≤ a k := ih\n have h₃ : S (a k) = a k - (m (a k)) ^ 2 := hS (a k) h₂\n have h₄ : (m (a k)) ^ 2 ≤ a k := (hm (a k) h₂).1\n have h₅ : S (a k) ≥ 0 := by\n rw [h₃]\n linarith\n linarith\n \n have h_nondec : ∀ k, a (k + 1) ≥ a k := by\n intro k\n have h₁ : a (k + 1) = a k + S (a k) := (ha.2) k\n rw [h₁]\n have h₂ : 0 ≤ a k := h_nonneg k\n have h₃ : S (a k) = a k - (m (a k)) ^ 2 := hS (a k) h₂\n have h₄ : (m (a k)) ^ 2 ≤ a k := (hm (a k) h₂).1\n have h₅ : S (a k) ≥ 0 := by\n rw [h₃]\n linarith\n linarith\n \n have h_S_pos : ∀ (n : ℤ), 0 ≤ n → (∀ (t : ℤ), n ≠ t ^ 2) → S n ≥ 1 := by\n intro n hn hnotsquare\n have h₁ : S n = n - (m n) ^ 2 := hS n hn\n rw [h₁]\n have h₂ : (m n) ^ 2 ≤ n := (hm n hn).1\n have h₃ : ∀ (m' : ℤ), m' ^ 2 ≤ n → m' ≤ m n := (hm n hn).2\n \n have h₄ : n - (m n) ^ 2 ≥ 1 := by\n by_contra h\n \n have h₅ : n - (m n) ^ 2 ≤ 0 := by\n linarith\n \n have h₆ : (m n + 1 : ℤ) ^ 2 > n := by\n by_contra h₆\n have h₇ : (m n + 1 : ℤ) ^ 2 ≤ n := by linarith\n have h₈ : m n + 1 ≤ m n := h₃ (m n + 1) h₇\n linarith\n \n have h₇ : (m n : ℤ) ^ 2 ≤ n := h₂\n have h₈ : (m n + 1 : ℤ) ^ 2 > n := h₆\n have h₉ : (m n + 1 : ℤ) ^ 2 > n := h₈\n \n \n \n \n \n \n \n have h₁₀ : (m n : ℤ) ^ 2 = n := by\n nlinarith\n \n have h₁₁ : ∃ (t : ℤ), n = t ^ 2 := by\n refine' ⟨m n, _⟩\n linarith\n \n obtain ⟨t, ht⟩ := h₁₁\n have h₁₂ : n = t ^ 2 := ht\n have h₁₃ : n ≠ t ^ 2 := hnotsquare t\n contradiction\n \n linarith\n \n have h_no_new_squares : ∀ (k : ℕ), (∀ (t : ℤ), a k ≠ t ^ 2) → (∀ (t : ℤ), a (k + 1) ≠ t ^ 2) := by\n intro k hk\n intro t ht\n have h₁ : a (k + 1) = a k + S (a k) := ha.2 k\n have h₂ : 0 ≤ a k := h_nonneg k\n have h₃ : S (a k) = a k - (m (a k)) ^ 2 := hS (a k) h₂\n have h₄ : a (k + 1) = a k + (a k - (m (a k)) ^ 2) := by\n rw [h₁, h₃]\n <;> ring\n have h₅ : a (k + 1) = 2 * a k - (m (a k)) ^ 2 := by\n linarith\n have h₆ : a (k + 1) = t ^ 2 := ht\n have h₇ : 2 * a k - (m (a k)) ^ 2 = t ^ 2 := by linarith\n have h₈ : (m (a k)) ^ 2 ≤ a k := (hm (a k) h₂).1\n have h₉ : ∀ (m' : ℤ), m' ^ 2 ≤ a k → m' ≤ m (a k) := (hm (a k) h₂).2\n have h₁₀ : a k < (m (a k) + 1) ^ 2 := by\n by_contra h\n have h₁₁ : (m (a k) + 1 : ℤ) ^ 2 ≤ a k := by linarith\n have h₁₂ : m (a k) + 1 ≤ m (a k) := h₉ (m (a k) + 1) h₁₁\n linarith\n \n \n \n have h₁₁ : m (a k) ≥ 0 := by\n by_contra h\n have h₁₂ : m (a k) < 0 := by linarith\n have h₁₃ : (m (a k)) ^ 2 > 0 := by nlinarith\n have h₁₄ : (m (a k) + 1 : ℤ) ^ 2 ≤ a k := by\n nlinarith [h₈]\n have h₁₅ : m (a k) + 1 ≤ m (a k) := h₉ (m (a k) + 1) h₁₄\n linarith\n \n \n have h₁₂ : t ^ 2 = 2 * a k - (m (a k)) ^ 2 := by linarith\n have h₁₃ : (m (a k)) ^ 2 < t ^ 2 := by\n have h₁₄ : (m (a k)) ^ 2 < a k := by\n by_contra h₁₄\n have h₁₅ : (m (a k)) ^ 2 ≥ a k := by linarith\n have h₁₆ : (m (a k)) ^ 2 ≤ a k := h₈\n have h₁₇ : (m (a k)) ^ 2 = a k := by linarith\n have h₁₈ : ∃ (t : ℤ), a k = t ^ 2 := by\n refine' ⟨m (a k), _⟩\n linarith\n obtain ⟨t', ht'⟩ := h₁₈\n have h₁₉ : a k = t' ^ 2 := ht'\n have h₂₀ : a k ≠ t' ^ 2 := hk t'\n contradiction\n nlinarith\n have h₁₄ : t ^ 2 < (m (a k) + 2) ^ 2 := by\n nlinarith [h₁₀]\n \n \n have h₁₅ : t = m (a k) + 1 ∨ t = -(m (a k) + 1) := by\n have h₁₆ : m (a k) ≥ 0 := h₁₁\n have h₁₇ : t ^ 2 < (m (a k) + 2) ^ 2 := h₁₄\n have h₁₈ : (m (a k)) ^ 2 < t ^ 2 := h₁₃\n have h₁₉ : t ≤ m (a k) + 1 := by\n nlinarith\n have h₂₀ : t ≥ -(m (a k) + 1) := by\n nlinarith\n have h₂₁ : t ≥ m (a k) + 1 ∨ t ≤ -(m (a k) + 1) := by\n by_contra! h₂₂\n have h₂₃ : -(m (a k) + 1) < t := by linarith\n have h₂₄ : t < m (a k) + 1 := by linarith\n have h₂₅ : t ^ 2 < (m (a k) + 1) ^ 2 := by\n nlinarith\n nlinarith\n cases h₂₁ with\n | inl h₂₁ =>\n have h₂₂ : t = m (a k) + 1 := by\n nlinarith\n exact Or.inl h₂₂\n | inr h₂₁ =>\n have h₂₂ : t = -(m (a k) + 1) := by\n nlinarith\n exact Or.inr h₂₂\n \n cases h₁₅ with\n | inl h₁₅ =>\n have h₁₆ : t = m (a k) + 1 := h₁₅\n have h₁₇ : t ^ 2 = (m (a k) + 1) ^ 2 := by\n rw [h₁₆]\n <;> ring_nf\n have h₁₈ : 2 * a k - (m (a k)) ^ 2 = (m (a k) + 1) ^ 2 := by\n linarith\n have h₁₉ : 2 * a k = 2 * (m (a k)) ^ 2 + 2 * m (a k) + 1 := by\n nlinarith\n have h₂₀ : (2 : ℤ) * a k % 2 = 1 := by\n have h₂₁ : (2 : ℤ) * a k = 2 * (m (a k)) ^ 2 + 2 * m (a k) + 1 := h₁₉\n omega\n have h₂₁ : (2 : ℤ) * a k % 2 = 0 := by\n have h₂₂ : (2 : ℤ) * a k % 2 = 0 := by\n have h₂₃ : (2 : ℤ) * a k % 2 = 0 := by\n omega\n exact h₂₃\n exact h₂₂\n omega\n | inr h₁₅ =>\n have h₁₆ : t = -(m (a k) + 1) := h₁₅\n have h₁₇ : t ^ 2 = (m (a k) + 1) ^ 2 := by\n rw [h₁₆]\n <;> ring_nf\n <;> simp [sq]\n <;> linarith\n have h₁₈ : 2 * a k - (m (a k)) ^ 2 = (m (a k) + 1) ^ 2 := by\n linarith\n have h₁₉ : 2 * a k = 2 * (m (a k)) ^ 2 + 2 * m (a k) + 1 := by\n nlinarith\n have h₂₀ : (2 : ℤ) * a k % 2 = 1 := by\n have h₂₁ : (2 : ℤ) * a k = 2 * (m (a k)) ^ 2 + 2 * m (a k) + 1 := h₁₉\n omega\n have h₂₁ : (2 : ℤ) * a k % 2 = 0 := by\n have h₂₂ : (2 : ℤ) * a k % 2 = 0 := by\n have h₂₃ : (2 : ℤ) * a k % 2 = 0 := by\n omega\n exact h₂₃\n exact h₂₂\n omega\n \n have h_strict_increasing : (∀ (t : ℤ), A ≠ t ^ 2) → ∀ (k : ℕ), a (k + 1) > a k := by\n intro hA_not_square k\n have h₁ : ∀ (k : ℕ), (∀ (t : ℤ), a k ≠ t ^ 2) := by\n intro k\n induction k with\n | zero =>\n intro t ht\n have h₂ : a 0 = A := ha.1\n rw [h₂] at ht\n exact hA_not_square t ht\n | succ k ih =>\n intro t ht\n have h₂ : (∀ (t : ℤ), a k ≠ t ^ 2) := ih\n have h₃ : (∀ (t : ℤ), a (k + 1) ≠ t ^ 2) := h_no_new_squares k h₂\n exact h₃ t ht\n have h₂ : (∀ (t : ℤ), a k ≠ t ^ 2) := h₁ k\n have h₃ : 0 ≤ a k := h_nonneg k\n have h₄ : S (a k) ≥ 1 := h_S_pos (a k) h₃ h₂\n have h₅ : a (k + 1) = a k + S (a k) := ha.2 k\n have h₆ : a (k + 1) > a k := by\n linarith\n exact h₆\n \n have h_imp : (∃ (K : ℕ) (c : ℕ), ∀ k ≥ K, a k = c) → A ∈ (({A : ℤ | ∃ x > 0, A = x ^ 2}) : Set ℤ) := by\n intro h\n by_contra h₁\n \n have h₂ : ∀ (t : ℤ), A ≠ t ^ 2 := by\n intro t ht\n have h₃ : A ∈ ({A : ℤ | ∃ x > 0, A = x ^ 2} : Set ℤ) := by\n refine' ⟨t.natAbs, _⟩\n have h₄ : A = t ^ 2 := ht\n have h₅ : (t.natAbs : ℤ) > 0 := by\n have h₆ : t ≠ 0 := by\n by_contra h₆\n rw [h₆] at h₄\n have h₇ : A = 0 := by\n norm_num at h₄ ⊢\n <;> linarith\n linarith\n have h₈ : t.natAbs > 0 := by\n exact Nat.pos_of_ne_zero (by\n intro h₉\n have h₁₀ : t.natAbs = 0 := h₉\n have h₁₁ : t = 0 := by\n simp [Int.natAbs_eq_zero] at h₁₀ ⊢\n <;> omega\n contradiction\n )\n exact_mod_cast h₈\n have h₉ : A = (t.natAbs : ℤ) ^ 2 := by\n have h₁₀ : A = t ^ 2 := ht\n have h₁₁ : (t.natAbs : ℤ) ^ 2 = t ^ 2 := by\n simp [sq, Int.natAbs_mul]\n <;> cases' le_or_lt 0 t with h₁₂ h₁₂ <;> simp_all [Int.natAbs_of_nonneg, Int.natAbs_of_nonpos, pow_two] <;>\n ring_nf <;> nlinarith\n linarith\n exact ⟨by exact_mod_cast h₅, by linarith⟩\n contradiction\n \n have h₃ : ∀ (k : ℕ), a (k + 1) > a k := h_strict_increasing h₂\n \n obtain ⟨K, c, h₄⟩ := h\n have h₅ : a (K + 1) > a K := h₃ K\n have h₆ : a (K + 1) = c := by\n have h₇ : K + 1 ≥ K := by linarith\n have h₈ : a (K + 1) = c := h₄ (K + 1) h₇\n exact h₈\n have h₇ : a K = c := by\n have h₈ : K ≥ K := by linarith\n have h₉ : a K = c := h₄ K h₈\n exact h₉\n linarith\n \n have h_conv : A ∈ (({A : ℤ | ∃ x > 0, A = x ^ 2}) : Set ℤ) → (∃ (K : ℕ) (c : ℕ), ∀ k ≥ K, a k = c) := by\n intro h\n obtain ⟨x, hx, hx'⟩ := h\n have h₁ : a 0 = A := ha.1\n have h₂ : ∀ k, a (k + 1) = a k + S (a k) := ha.2\n have h₃ : ∀ k, a k = A := by\n intro k\n induction k with\n | zero => simp [h₁]\n | succ k ih =>\n have h₄ : a (k + 1) = a k + S (a k) := h₂ k\n rw [h₄]\n have h₅ : a k = A := ih\n rw [h₅]\n have h₆ : S A = 0 := by\n have h₇ : 0 ≤ A := by linarith\n have h₈ : S A = A - (m A) ^ 2 := hS A h₇\n rw [h₈]\n have h₉ : (m A) ^ 2 ≤ A := (hm A h₇).1\n have h₁₀ : ∀ (m' : ℤ), m' ^ 2 ≤ A → m' ≤ m A := (hm A h₇).2\n have h₁₁ : A = x ^ 2 := by\n norm_cast at hx' ⊢\n <;> simp_all [pow_two]\n <;> nlinarith\n have h₁₂ : (m A : ℤ) = x := by\n have h₁₃ : (m A : ℤ) ≥ 0 := by\n by_contra h₁₄\n have h₁₅ : (m A : ℤ) < 0 := by linarith\n have h₁₆ : (m A : ℤ) ^ 2 > 0 := by nlinarith\n have h₁₇ : (m A + 1 : ℤ) ^ 2 ≤ A := by\n nlinarith [h₉]\n have h₁₈ : m A + 1 ≤ m A := h₁₀ (m A + 1) h₁₇\n linarith\n have h₁₉ : (m A : ℤ) ≤ x := by\n have h₂₀ : (m A : ℤ) ^ 2 ≤ A := h₉\n have h₂₁ : A = x ^ 2 := by\n norm_cast at hx' ⊢\n <;> simp_all [pow_two]\n <;> nlinarith\n have h₂₂ : (m A : ℤ) ^ 2 ≤ x ^ 2 := by\n linarith\n nlinarith\n have h₂₀ : (m A : ℤ) ≥ x := by\n by_contra h₂₁\n have h₂₂ : (m A : ℤ) < x := by linarith\n have h₂₃ : (m A + 1 : ℤ) ≤ x := by\n linarith\n have h₂₄ : (m A + 1 : ℤ) ^ 2 ≤ x ^ 2 := by\n have h₂₅ : (m A + 1 : ℤ) ≤ x := by linarith\n have h₂₆ : 0 ≤ (m A + 1 : ℤ) := by\n nlinarith [h₁₃]\n nlinarith\n have h₂₅ : (m A + 1 : ℤ) ^ 2 ≤ A := by\n have h₂₆ : A = x ^ 2 := by\n norm_cast at hx' ⊢\n <;> simp_all [pow_two]\n <;> nlinarith\n linarith\n have h₂₆ : m A + 1 ≤ m A := h₁₀ (m A + 1) h₂₅\n linarith\n linarith\n have h₂₁ : (m A : ℤ) = x := h₁₂\n have h₂₂ : (m A : ℤ) ^ 2 = x ^ 2 := by\n rw [h₂₁]\n have h₂₃ : A = x ^ 2 := by\n norm_cast at hx' ⊢\n <;> simp_all [pow_two]\n <;> nlinarith\n linarith\n linarith\n refine' ⟨0, Int.toNat A, _⟩\n intro k hk\n have h₄ : a k = A := h₃ k\n have h₅ : 0 ≤ A := by linarith\n have h₆ : (A : ℤ) = Int.toNat A := by\n rw [Int.toNat_of_nonneg h₅]\n <;> simp\n rw [h₄]\n <;> norm_cast at h₆ ⊢ <;> simp_all\n <;>\n (try omega)\n \n constructor\n · \n intro h\n exact h_imp h\n · \n intro h\n exact h_conv h"} {"name": "putnam_2019_a1", "proof_length": 2381, "header": "import Mathlib\nimport Aesop\n\nset_option maxHeartbeats 0\n\nopen Topology Filter\n\n\n\n", "signature": "theorem putnam_2019_a1\n: {n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} = (({n : ℤ | n ≥ 0 ∧ ¬Int.ModEq 9 n 3 ∧ ¬Int.ModEq 9 n 6}) : Set ℤ )", "src": "theorem putnam_2019_a1\n: {n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} = (({n : ℤ | n ≥ 0 ∧ ¬Int.ModEq 9 n 3 ∧ ¬Int.ModEq 9 n 6}) : Set ℤ ) := by \n have h_subset₁ : {n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} ⊆ ({n : ℤ | n ≥ 0 ∧ ¬Int.ModEq 9 n 3 ∧ ¬Int.ModEq 9 n 6} : Set ℤ) := by\n intro n hn\n rcases hn with ⟨A, B, C, hA, hB, hC, hn⟩\n have h₁ : n ≥ 0 := by\n have h₁ : (A : ℤ) ≥ 0 := by exact_mod_cast hA\n have h₂ : (B : ℤ) ≥ 0 := by exact_mod_cast hB\n have h₃ : (C : ℤ) ≥ 0 := by exact_mod_cast hC\n have h₄ : (A : ℤ)^3 + (B : ℤ)^3 + (C : ℤ)^3 - 3 * (A : ℤ) * (B : ℤ) * (C : ℤ) ≥ 0 := by\n nlinarith [sq_nonneg (A - B), sq_nonneg (B - C), sq_nonneg (C - A),\n mul_nonneg h₁ h₂, mul_nonneg h₂ h₃, mul_nonneg h₃ h₁,\n sq_nonneg (A + B + C), sq_nonneg (A + B - C), sq_nonneg (A + C - B),\n sq_nonneg (B + C - A)]\n linarith\n have h₂ : ¬Int.ModEq 9 n 3 := by\n have h₂ : ∀ (A B C : ℤ), A ≥ 0 → B ≥ 0 → C ≥ 0 → (A^3 + B^3 + C^3 - 3*A*B*C) % 9 ≠ 3 := by\n intro A B C hA hB hC\n have h₃ : A % 9 = 0 ∨ A % 9 = 1 ∨ A % 9 = 2 ∨ A % 9 = 3 ∨ A % 9 = 4 ∨ A % 9 = 5 ∨ A % 9 = 6 ∨ A % 9 = 7 ∨ A % 9 = 8 := by\n omega\n have h₄ : B % 9 = 0 ∨ B % 9 = 1 ∨ B % 9 = 2 ∨ B % 9 = 3 ∨ B % 9 = 4 ∨ B % 9 = 5 ∨ B % 9 = 6 ∨ B % 9 = 7 ∨ B % 9 = 8 := by\n omega\n have h₅ : C % 9 = 0 ∨ C % 9 = 1 ∨ C % 9 = 2 ∨ C % 9 = 3 ∨ C % 9 = 4 ∨ C % 9 = 5 ∨ C % 9 = 6 ∨ C % 9 = 7 ∨ C % 9 = 8 := by\n omega\n rcases h₃ with (h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃) <;>\n rcases h₄ with (h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄) <;>\n rcases h₅ with (h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅) <;>\n (try omega) <;>\n (try {\n simp [h₃, h₄, h₅, pow_three, Int.mul_emod, Int.add_emod, Int.sub_emod]\n <;> norm_num <;> omega\n })\n have h₃ := h₂ A B C hA hB hC\n intro h₄\n have h₅ : (n : ℤ) % 9 = 3 := by\n rw [Int.ModEq] at h₄\n omega\n have h₆ : (A^3 + B^3 + C^3 - 3*A*B*C) % 9 = 3 := by\n omega\n contradiction\n have h₃ : ¬Int.ModEq 9 n 6 := by\n have h₂ : ∀ (A B C : ℤ), A ≥ 0 → B ≥ 0 → C ≥ 0 → (A^3 + B^3 + C^3 - 3*A*B*C) % 9 ≠ 6 := by\n intro A B C hA hB hC\n have h₃ : A % 9 = 0 ∨ A % 9 = 1 ∨ A % 9 = 2 ∨ A % 9 = 3 ∨ A % 9 = 4 ∨ A % 9 = 5 ∨ A % 9 = 6 ∨ A % 9 = 7 ∨ A % 9 = 8 := by\n omega\n have h₄ : B % 9 = 0 ∨ B % 9 = 1 ∨ B % 9 = 2 ∨ B % 9 = 3 ∨ B % 9 = 4 ∨ B % 9 = 5 ∨ B % 9 = 6 ∨ B % 9 = 7 ∨ B % 9 = 8 := by\n omega\n have h₅ : C % 9 = 0 ∨ C % 9 = 1 ∨ C % 9 = 2 ∨ C % 9 = 3 ∨ C % 9 = 4 ∨ C % 9 = 5 ∨ C % 9 = 6 ∨ C % 9 = 7 ∨ C % 9 = 8 := by\n omega\n rcases h₃ with (h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃ | h₃) <;>\n rcases h₄ with (h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄ | h₄) <;>\n rcases h₅ with (h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅ | h₅) <;>\n (try omega) <;>\n (try {\n simp [h₃, h₄, h₅, pow_three, Int.mul_emod, Int.add_emod, Int.sub_emod]\n <;> norm_num <;> omega\n })\n have h₃ := h₂ A B C hA hB hC\n intro h₄\n have h₅ : (n : ℤ) % 9 = 6 := by\n rw [Int.ModEq] at h₄\n omega\n have h₆ : (A^3 + B^3 + C^3 - 3*A*B*C) % 9 = 6 := by\n omega\n contradiction\n exact ⟨h₁, h₂, h₃⟩\n \n have h_subset₂ : ({n : ℤ | n ≥ 0 ∧ ¬Int.ModEq 9 n 3 ∧ ¬Int.ModEq 9 n 6} : Set ℤ) ⊆ {n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} := by\n intro n hn\n have h₁ : n ≥ 0 := hn.1\n have h₂ : ¬Int.ModEq 9 n 3 := hn.2.1\n have h₃ : ¬Int.ModEq 9 n 6 := hn.2.2\n \n have h₄ : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by\n have h₄ : n % 3 = 0 ∨ n % 3 = 1 ∨ n % 3 = 2 := by omega\n exact h₄\n rcases h₄ with (h₄ | h₄ | h₄)\n · \n have h₅ : n % 9 ≠ 3 := by\n intro h₅\n have h₆ : Int.ModEq 9 n 3 := by\n rw [Int.ModEq]\n omega\n contradiction\n have h₆ : n % 9 ≠ 6 := by\n intro h₆\n have h₇ : Int.ModEq 9 n 6 := by\n rw [Int.ModEq]\n omega\n contradiction\n \n have h₇ : n % 9 = 0 := by\n have h₇ : n % 9 = 0 ∨ n % 9 = 3 ∨ n % 9 = 6 := by\n omega\n rcases h₇ with (h₇ | h₇ | h₇)\n · exact h₇\n · exfalso\n exact h₅ h₇\n · exfalso\n exact h₆ h₇\n \n have h₈ : ∃ (k : ℤ), n = 9 * k := by\n use n / 9\n have h₈ : n % 9 = 0 := h₇\n have h₉ : n = 9 * (n / 9) := by\n omega\n exact h₉\n rcases h₈ with ⟨k, hk⟩\n by_cases h₉ : k = 0\n · \n use 0, 0, 0\n simp [h₉, hk]\n <;> norm_num\n · \n have h₁₀ : k > 0 := by\n by_contra h₁₀\n have h₁₁ : k ≤ 0 := by linarith\n have h₁₂ : n ≤ 0 := by\n have h₁₃ : (9 : ℤ) * k ≤ 0 := by nlinarith\n linarith\n have h₁₃ : n ≥ 0 := h₁\n have h₁₄ : n = 0 := by linarith\n have h₁₅ : k = 0 := by\n omega\n contradiction\n \n use (k + 1 : ℤ), (k : ℤ), (k - 1 : ℤ)\n have h₁₁ : (k + 1 : ℤ) ≥ 0 := by linarith\n have h₁₂ : (k : ℤ) ≥ 0 := by linarith\n have h₁₃ : (k - 1 : ℤ) ≥ 0 := by\n have h₁₄ : k ≥ 1 := by\n by_contra h₁₄\n have h₁₅ : k ≤ 0 := by linarith\n have h₁₆ : n ≤ 0 := by\n have h₁₇ : (9 : ℤ) * k ≤ 0 := by nlinarith\n linarith\n have h₁₇ : n ≥ 0 := h₁\n have h₁₈ : n = 0 := by linarith\n have h₁₉ : k = 0 := by\n omega\n contradiction\n linarith\n constructor\n · exact_mod_cast h₁₁\n constructor\n · exact_mod_cast h₁₂\n constructor\n · exact_mod_cast h₁₃\n \n have h₁₄ : (k + 1 : ℤ)^3 + (k : ℤ)^3 + (k - 1 : ℤ)^3 - 3 * (k + 1 : ℤ) * (k : ℤ) * (k - 1 : ℤ) = 9 * k := by\n ring_nf\n <;> nlinarith\n rw [hk]\n linarith\n · \n \n have h₅ : (n - 1) % 3 = 0 := by\n omega\n have h₆ : ∃ (m : ℤ), n = 3 * m + 1 := by\n use (n - 1) / 3\n have h₆ : (n - 1) % 3 = 0 := h₅\n have h₇ : n - 1 = 3 * ((n - 1) / 3) := by\n omega\n linarith\n rcases h₆ with ⟨m, hm⟩\n have h₇ : m ≥ 0 := by\n by_contra h₇\n have h₈ : m < 0 := by linarith\n have h₉ : n < 1 := by\n nlinarith\n have h₁₀ : n ≥ 0 := h₁\n omega\n use (m + 1 : ℤ), (m : ℤ), (m : ℤ)\n have h₈ : (m + 1 : ℤ) ≥ 0 := by linarith\n have h₉ : (m : ℤ) ≥ 0 := by linarith\n have h₁₀ : (m : ℤ) ≥ 0 := by linarith\n constructor\n · exact_mod_cast h₈\n constructor\n · exact_mod_cast h₉\n constructor\n · exact_mod_cast h₁₀\n \n have h₁₁ : (m + 1 : ℤ)^3 + (m : ℤ)^3 + (m : ℤ)^3 - 3 * (m + 1 : ℤ) * (m : ℤ) * (m : ℤ) = 3 * m + 1 := by\n ring_nf\n <;> nlinarith\n rw [hm]\n linarith\n · \n \n have h₅ : (n - 2) % 3 = 0 := by\n omega\n have h₆ : ∃ (m : ℤ), n = 3 * m + 2 := by\n use (n - 2) / 3\n have h₆ : (n - 2) % 3 = 0 := h₅\n have h₇ : n - 2 = 3 * ((n - 2) / 3) := by\n omega\n linarith\n rcases h₆ with ⟨m, hm⟩\n have h₇ : m ≥ 0 := by\n by_contra h₇\n have h₈ : m < 0 := by linarith\n have h₉ : n < 2 := by\n nlinarith\n have h₁₀ : n ≥ 0 := h₁\n have h₁₁ : m ≤ -1 := by\n omega\n have h₁₂ : n < 0 := by\n nlinarith\n linarith\n use (m + 1 : ℤ), (m + 1 : ℤ), (m : ℤ)\n have h₈ : (m + 1 : ℤ) ≥ 0 := by linarith\n have h₉ : (m + 1 : ℤ) ≥ 0 := by linarith\n have h₁₀ : (m : ℤ) ≥ 0 := by linarith\n constructor\n · exact_mod_cast h₈\n constructor\n · exact_mod_cast h₉\n constructor\n · exact_mod_cast h₁₀\n \n have h₁₁ : (m + 1 : ℤ)^3 + (m + 1 : ℤ)^3 + (m : ℤ)^3 - 3 * (m + 1 : ℤ) * (m + 1 : ℤ) * (m : ℤ) = 3 * m + 2 := by\n ring_nf\n <;> nlinarith\n rw [hm]\n linarith\n \n have h_main : {n : ℤ | ∃ A B C : ℤ, A ≥ 0 ∧ B ≥ 0 ∧ C ≥ 0 ∧ A^3 + B^3 + C^3 - 3*A*B*C = n} = (({n : ℤ | n ≥ 0 ∧ ¬Int.ModEq 9 n 3 ∧ ¬Int.ModEq 9 n 6}) : Set ℤ ) := by\n apply Set.Subset.antisymm\n · exact h_subset₁\n · exact h_subset₂\n \n exact h_main"}