import Mathlib.Tactic import Mathlib.Data.Nat.Prime.Basic /-! # Bonza functions: small restrictions on `f(2)` and `f(3)` We use the bonza condition stated in `ℤ`: `(f a : ℤ) ∣ (b : ℤ)^a - (f b : ℤ)^(f a)` for all `a,b>0`. This file proves: * `f(2) ∣ 4`. * `f(3) ∈ {1,3,9,27}`. * In fact `f(3) ≠ 27`. These are intended as auxiliary lemmas toward a full classification / bound. -/ /-- Bonza property, stated in `ℤ` to avoid subtraction issues in `ℕ`. -/ def Bonza (f : ℕ → ℕ) : Prop := (∀ a b : ℕ, 0 < a → 0 < b → (f a : ℤ) ∣ (b : ℤ)^a - (f b : ℤ)^(f a)) ∧ (∀ n : ℕ, 0 < n → 0 < f n) namespace Bonza variable {f : ℕ → ℕ} lemma pos (hf : Bonza f) {n : ℕ} (hn : 0 < n) : 0 < f n := hf.2 n hn /-- From bonza: `(f a : ℤ) ∣ (a : ℤ)^a`. -/ lemma int_dvd_self_pow (hf : Bonza f) {a : ℕ} (ha : 0 < a) : (f a : ℤ) ∣ (a : ℤ)^a := by have hdiv := hf.1 a a ha ha have hpow : (f a : ℤ) ∣ (f a : ℤ)^(f a) := by have hfa0 : f a ≠ 0 := Nat.ne_of_gt (hf.2 a ha) -- `dvd_pow_self` needs a proof that the exponent is nonzero. exact dvd_pow_self (f a : ℤ) (hn := by intro hn exact hfa0 (by simpa using hn)) have := dvd_add hdiv hpow simpa [sub_eq_add_neg, add_assoc, add_left_comm, add_comm] using this /-- From bonza: `f a ∣ a^a` in `ℕ`. -/ lemma dvd_self_pow (hf : Bonza f) {a : ℕ} (ha : 0 < a) : f a ∣ a^a := by have hz : (f a : ℤ) ∣ (a : ℤ)^a := int_dvd_self_pow (f := f) hf ha have : (f a : ℤ) ∣ (a^a : ℤ) := by simpa using hz exact Int.ofNat_dvd.mp this /-- Any bonza function has `f(2) ∣ 4`. -/ lemma f2_dvd_four (hf : Bonza f) : f 2 ∣ 4 := by simpa using (dvd_self_pow (f := f) hf (a := 2) (by decide)) /-- Any bonza function has `f(3) ∈ {1,3,9,27}`. -/ lemma f3_mem (hf : Bonza f) : f 3 = 1 ∨ f 3 = 3 ∨ f 3 = 9 ∨ f 3 = 27 := by have hdiv : f 3 ∣ 3^3 := by simpa using (dvd_self_pow (f := f) hf (a := 3) (by decide)) have hp : Nat.Prime 3 := by decide rcases (Nat.dvd_prime_pow hp (i := f 3) (m := 3)).1 (by simpa using hdiv) with ⟨k, hk, hkEq⟩ -- `k ≤ 3`, hence `k = 0,1,2,3` have hkCases : k = 0 ∨ k = 1 ∨ k = 2 ∨ k = 3 := by omega rcases hkCases with rfl | rfl | rfl | rfl <;> simp [hkEq] /-- `f(3) ≠ 27` for bonza functions. Proof: assume `f(3)=27`. From `f(2) ∣ 4 = 2^2` we have `f(2) ∈ {1,2,4}`. Plugging `(a,b)=(3,2)` forces `27 ∣ 8 - f(2)^27`, which fails in all cases. -/ lemma f3_ne_twentySeven (hf : Bonza f) : f 3 ≠ 27 := by intro h27 have h2div : f 2 ∣ 4 := f2_dvd_four (f := f) hf -- classify `f 2` using `Nat.dvd_prime_pow` on `4 = 2^2`. have hp2 : Nat.Prime 2 := by decide rcases (Nat.dvd_prime_pow hp2 (i := f 2) (m := 2)).1 (by simpa using h2div) with ⟨k, hk, hkEq⟩ have hkCases : k = 0 ∨ k = 1 ∨ k = 2 := by omega have hbonza := hf.1 3 2 (by decide) (by decide) have htmp : (f 3 : ℤ) ∣ (2 : ℤ)^3 - (f 2 : ℤ)^(f 3) := hbonza have htmp27 := htmp -- rewrite both the divisor and the exponent rw [h27] at htmp27 have hdiv27 : (27 : ℤ) ∣ (2 : ℤ)^3 - (f 2 : ℤ)^(27) := by simpa using htmp27 -- now check the three possibilities for `f 2`. rcases hkCases with rfl | rfl | rfl · -- k=0, so f2=1 have h1 : f 2 = 1 := by simpa [hkEq] have hdiv1 : (27 : ℤ) ∣ (2 : ℤ)^3 - (1 : ℤ)^(27) := by simpa [h1] using hdiv27 have : ¬ (27 : ℤ) ∣ (2 : ℤ)^3 - (1 : ℤ)^(27) := by decide exact (this hdiv1).elim · -- k=1, so f2=2 have h2 : f 2 = 2 := by simpa [hkEq] have hdiv2 : (27 : ℤ) ∣ (2 : ℤ)^3 - (2 : ℤ)^(27) := by simpa [h2] using hdiv27 have : ¬ (27 : ℤ) ∣ (2 : ℤ)^3 - (2 : ℤ)^(27) := by decide exact (this hdiv2).elim · -- k=2, so f2=4 have h4 : f 2 = 4 := by simpa [hkEq] have hdiv4 : (27 : ℤ) ∣ (2 : ℤ)^3 - (4 : ℤ)^(27) := by simpa [h4] using hdiv27 have : ¬ (27 : ℤ) ∣ (2 : ℤ)^3 - (4 : ℤ)^(27) := by decide exact (this hdiv4).elim end Bonza