import Mathlib /-! # Erdős Problem 1094: the kill rule of the logic net, proved The logic net learned, from pairs with `n ≤ 120`, that clock `p` lets `(n, k)` through exactly when every base-`p` digit of `k` is at most the corresponding digit of `n`. Here this rule is proved for all `n, k` (it is Lucas's theorem in digit form), and the exceptional set of the problem is rewritten with it. -/ namespace Erdos1094Rule /-- The learned gate, applied to all base-`p` digit pairs: every digit of `k` is `≤` that of `n`. -/ def passes (p : ℕ) : ℕ → ℕ → Prop | n, k => if _h : k = 0 ∨ p < 2 then True else k % p ≤ n % p ∧ passes p (n / p) (k / p) decreasing_by have hk : k ≠ 0 := fun h0 ↦ _h (Or.inl h0) have hp : 2 ≤ p := by omega exact Nat.div_lt_self (Nat.pos_of_ne_zero hk) hp theorem passes_zero (p n : ℕ) : passes p n 0 := by unfold passes; simp theorem passes_step {p : ℕ} (hp : 2 ≤ p) (n : ℕ) {k : ℕ} (hk : k ≠ 0) : passes p n k ↔ k % p ≤ n % p ∧ passes p (n / p) (k / p) := by rw [passes] have h1 : 1 < p := by omega simp [hk, h1] /-- **Kill rule.** For a prime `p`: `p ∤ C(n, k)` iff every base-`p` digit of `k` is at most that of `n`. -/ theorem not_dvd_choose_iff_passes {p : ℕ} (hp : p.Prime) : ∀ k n : ℕ, ¬ p ∣ n.choose k ↔ passes p n k := by have : Fact p.Prime := ⟨hp⟩ intro k induction k using Nat.strong_induction_on with | _ k ih => intro n by_cases hk : k = 0 · subst hk simp [passes_zero, hp.one_lt.ne', Nat.dvd_one] · rw [passes_step hp.two_le n hk] have hlt : k / p < k := Nat.div_lt_self (Nat.pos_of_ne_zero hk) hp.two_le rw [← ih (k / p) hlt (n / p)] have hl := Choose.choose_modEq_choose_mod_mul_choose_div_nat (n := n) (k := k) (p := p) have hdvd : p ∣ n.choose k ↔ p ∣ (n % p).choose (k % p) * (n / p).choose (k / p) := by rw [Nat.dvd_iff_mod_eq_zero, Nat.dvd_iff_mod_eq_zero] unfold Nat.ModEq at hl rw [hl] rw [hdvd, hp.dvd_mul, not_or] have hdig : ¬ p ∣ (n % p).choose (k % p) ↔ k % p ≤ n % p := by constructor · intro h by_contra hlt' exact h (by rw [Nat.choose_eq_zero_of_lt (by omega)]; exact dvd_zero p) · intro hle hd have hnp : n % p < p := Nat.mod_lt _ hp.pos have hpos : 0 < (n % p).choose (k % p) := Nat.choose_pos hle have : p ∣ (n % p).factorial := by rw [← Nat.choose_mul_factorial_mul_factorial hle] exact Dvd.dvd.mul_right (Dvd.dvd.mul_right hd _) _ exact absurd ((hp.dvd_factorial).1 this) (by omega) rw [hdig] /-- The exceptional set of Erdős Problem 1094 (verbatim from Formal Conjectures). -/ def Exc : Set (ℕ × ℕ) := {(n, k) : ℕ × ℕ | 0 < k ∧ 2 * k ≤ n ∧ (n.choose k).minFac > max (n / k) k} /-- A pair is exceptional iff it passes every prime clock `p ≤ max (n / k) k`. -/ theorem mem_Exc_iff {n k : ℕ} (hk : 0 < k) (hn : 2 * k ≤ n) : (n, k) ∈ Exc ↔ ∀ p : ℕ, p.Prime → p ≤ max (n / k) k → passes p n k := by have hc1 : n.choose k ≠ 1 := by intro h have := Nat.choose_eq_one_iff.1 h omega constructor · rintro ⟨-, -, h⟩ p hp hple rw [← not_dvd_choose_iff_passes hp] intro hd have := Nat.minFac_le_of_dvd hp.two_le hd omega · intro h refine ⟨hk, hn, ?_⟩ by_contra hle push Not at hle have hp := Nat.minFac_prime hc1 exact (not_dvd_choose_iff_passes hp k n).2 (h _ hp hle) (Nat.minFac_dvd _) end Erdos1094Rule #print axioms Erdos1094Rule.not_dvd_choose_iff_passes #print axioms Erdos1094Rule.mem_Exc_iff