Open Proof Network

Problems / erdos-402 / erdos-402--h3-v2--h1--h1

Pair or a prime factor p with |B| ≤ 2p

erdos-402--h3-v2--h1--h1

open

Hole hsmooth of erdos-402--h3-v2--h1 (split by 20261001T115500Z-t1001-402a-partial.lean).

$\displaystyle \begin{aligned}&0 \notin B,\ B \ne \emptyset,\ \gcd(B) = 1,\ |B|\ \text{not prime},\ |B| \ne q + 1\ \text{for every prime } q,\\&\forall a, b \in B:\ a \le |B| \cdot \gcd(a,b),\qquad \forall a \in B,\ \forall p\ \text{prime},\ \forall k \in \mathbb{N}:\ p^k \mid a \Rightarrow p^k < |B|\\&\Longrightarrow\ \bigl(\exists\, a, b \in B:\ \gcd(a,b) \le \frac{a}{|B|}\bigr) \vee \bigl(\exists\, p\ \text{prime}:\ |B| \le 2p,\ \exists\, a \in B,\ p \mid a\bigr)\end{aligned}$

For every finite set B of positive integers (0 ∉ B, B nonempty) whose elements have greatest common divisor 1, whose size |B| is neither a prime nor one more than a prime, in which a ≤ |B|·gcd(a, b) for all a, b ∈ B, and in which every prime power dividing an element is below |B|, either some a, b ∈ B (possibly equal) have gcd(a, b) ≤ a/|B|, or some element of B has a prime factor p with |B| ≤ 2p. gcd(B) is the greatest common divisor of all elements of B; the division is in ℚ, the rest is over ℕ.

unverified · history

Lean
theorem erdos_402__h3_v2__h1__h1 : ∀ (B : Finset ℕ),
  (0 : ℕ) ∉ B →
    B.Nonempty →
      B.gcd id = (1 : ℕ) →
        ¬Nat.Prime B.card →
          (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) →
            (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
              (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) →
                (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨
                  ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a := by
  sorry
Why does it end in sorry?

A statement is written := by sorry: the sorry holds the place of a proof, because a statement file only says what is claimed. A proof the gate checked is its own file, Proof.lean. How to read a proof page →

How it is being proved

Open. A direct proof, or proofs of its holes, close it.

Split into

Proved from this hole by 20261001T143056Z-t1001-402a-partial.lean (merged in f2aff77837fd, attestation 000344).

  • hmid → erdos-402--h3-v2--h1--h1--h1 (open)

    $\displaystyle \begin{aligned}&0 \notin B,\ B \ne \emptyset,\ \gcd(B) = 1,\ |B|\ \text{not prime},\ |B| \ne q + 1\ \text{for every prime } q,\\&\forall a, b \in B:\ a \le |B| \cdot \gcd(a,b),\qquad \forall a \in B,\ \forall p\ \text{prime},\ \forall k \in \mathbb{N}:\ p^k \mid a \Rightarrow p^k < |B|\\&\Longrightarrow\ \bigl(\exists\, a, b \in B:\ \gcd(a,b) \le \frac{a}{|B|}\bigr) \vee \bigl(\exists\, p\ \text{prime}:\ |B| \le 3p,\ \exists\, a \in B,\ p \mid a\bigr)\end{aligned}$

Read the partial proof (Lean)
theorem erdos_402__h3_v2__h1__h1 : ∀ (B : Finset ℕ),
  (0 : ℕ) ∉ B →
    B.Nonempty →
      B.gcd id = (1 : ℕ) →
        ¬Nat.Prime B.card →
          (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) →
            (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
              (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) →
                (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨
                  ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a := by
  -- Informal argument and the Lean of each lemma: annex eb2314a2c5e64fe114b9093565a401979c6ef009436d2f021627b4d3d63663fd on erdos-402--h3-v2 (graph PR #340, agent 402-R2-b); dual set from agents 402-R1-b and 402-R2-c.
  -- Hole `hmid`: B has a pair with gcd(a, b) ≤ a / n, or an element with a prime factor p ≥ n / 3.
  -- The assembly proves: in a strict counterexample no prime p with 2p < n ≤ 3p divides an element
  -- (block lemma for k = 2, matching lemma for B = {2p} ∪ T, and the dual set for the other side).
  have hmid : ∀ B : Finset ℕ, 0 ∉ B → B.Nonempty → B.gcd id = 1 → ¬ B.card.Prime →
      (∀ q : ℕ, q.Prime → B.card ≠ q + 1) →
      (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
      (∀ a ∈ B, ∀ p k : ℕ, p.Prime → p ^ k ∣ a → p ^ k < B.card) →
      (∃ a ∈ B, ∃ b ∈ B, (a.gcd b : ℚ) ≤ (a : ℚ) / (B.card : ℚ)) ∨
        ∃ p : ℕ, p.Prime ∧ B.card ≤ 3 * p ∧ ∃ a ∈ B, p ∣ a := sorry
  have R2b_lemI : ∀ (n p : ℕ) (T : Finset ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (h0 : ∀ b ∈ T, 0 < b) (hpT : ∀ b ∈ T, ¬ p ∣ b) (ho : ∀ b ∈ T, ¬ 2 ∣ b → b < n) (he : ∀ b ∈ T, 2 ∣ b → b < 2 * n) (hx : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → b < n * b.gcd t),
      T.card + 2 ≤ n := by
    intro n p T hp hp3 h2p hn3 h0 hpT ho he hx
    -- φ t = the unique t·2^j in [n/2, n-1]
    have hφ : ∀ b : ℕ, 0 < b → b < n →
        b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ n - 1 ∧ n - 1 < 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by
      intro b hb hbn
      have hne : (n - 1) / b ≠ 0 := by
        have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb
        omega
      have h1 := Nat.pow_log_le_self 2 hne
      have h2 := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) ((n - 1) / b)
      have h3 : b * ((n - 1) / b) ≤ n - 1 := Nat.mul_div_le _ _
      have h4 : b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ b * ((n - 1) / b) := Nat.mul_le_mul_left b h1
      have h5 : n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := (Nat.div_lt_iff_lt_mul hb).mp h2
      refine ⟨h4.trans h3, ?_⟩
      calc n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := h5
        _ = 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by rw [pow_succ]; ring
    have hinj0 : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → j ≤ j' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
      intro b b' j j' hb hjj h
      obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le hjj
      have h1 : b * 2 ^ j = (b' * 2 ^ d) * 2 ^ j := by rw [h, pow_add]; ring
      have h2 : b = b' * 2 ^ d := Nat.eq_of_mul_eq_mul_right (by positivity) h1
      rcases Nat.eq_zero_or_pos d with hd | hd
      · rw [hd] at h2; simpa using h2
      · exfalso; apply hb; rw [h2]
        exact Dvd.dvd.mul_left (dvd_pow_self 2 (by omega)) _
    have hinj : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → ¬ 2 ∣ b' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
      intro b b' j j' hb hb' h
      rcases le_total j j' with hjj | hjj
      · exact hinj0 b b' j j' hb hjj h
      · exact (hinj0 b' b j' j hb' hjj h.symm).symm
    -- coprimality of t with (t·m − 1)
    have hcop : ∀ t m w : ℕ, w + 1 = t * m → Nat.Coprime w t := by
      intro t m w h
      have h1 : Nat.Coprime w (w + 1) := by simp
      rw [h] at h1
      exact Nat.Coprime.coprime_mul_right_right h1
    set φ : ℕ → ℕ := fun b => b * 2 ^ Nat.log 2 ((n - 1) / b) with hφdef
    set g : ℕ → ℕ := fun b =>
      if 2 ∣ b then b / 2 else if b = 2 * p + 1 then 2 * p - 1
      else if 2 * (φ b - 1) < n then 0 else φ b - 1 with hgdef
    have hmaps : ∀ b ∈ T, g b ∈ insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p)) := by
      intro b hb
      have hb0 := h0 b hb
      have hpb := hpT b hb
      rw [Finset.mem_insert, Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
      simp only [hgdef]
      by_cases h2 : 2 ∣ b
      · rw [if_pos h2]
        right
        obtain ⟨c, rfl⟩ := h2
        have := he _ hb ⟨c, rfl⟩
        rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2)]
        refine ⟨?_, ?_, ?_, ?_⟩
        · rintro rfl; exact hpb ⟨4, by ring⟩
        · rintro rfl; exact hpb ⟨2, by ring⟩
        · omega
        · omega
      · rw [if_neg h2]
        by_cases h3 : b = 2 * p + 1
        · rw [if_pos h3]; right; omega
        · rw [if_neg h3]
          by_cases h4 : 2 * (φ b - 1) < n
          · rw [if_pos h4]; left; rfl
          · rw [if_neg h4]
            right
            have hb1 := hφ b hb0 (ho b hb h2)
            have hne : φ b ≠ 2 * p + 1 := by
              intro h
              have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
              exact h3 (hinj _ _ _ _ h2 (by omega) h5)
            change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
            omega
    have hginj : Set.InjOn g (T : Set ℕ) := by
      -- even / odd collision is impossible
      have hEO : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → g b = g t → False := by
        intro b hb t ht h2b h2t h
        have hb0 := h0 b hb
        have ht0 := h0 t ht
        have hx' := hx b hb t ht h2b h2t
        obtain ⟨c, rfl⟩ := h2b
        simp only [hgdef] at h
        rw [if_pos ⟨c, rfl⟩, if_neg h2t, Nat.mul_div_cancel_left c (by norm_num : 0 < 2)] at h
        by_cases h3 : t = 2 * p + 1
        · rw [if_pos h3] at h
          have hc : Nat.Coprime c t := by
            have h1 : Nat.Coprime c (2 + c) := by
              rw [Nat.coprime_add_self_right]
              rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
              intro hd; omega
            have : 2 + c = t := by omega
            rwa [this] at h1
          have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
          have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
          rw [hg] at hx'
          omega
        · rw [if_neg h3] at h
          by_cases h4 : 2 * (φ t - 1) < n
          · rw [if_pos h4] at h; omega
          · rw [if_neg h4] at h
            have ht1 := hφ t ht0 (ho t ht h2t)
            change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
            have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
              change c + 1 = φ t
              omega)
            have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
            have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
            rw [hg] at hx'
            omega
      intro b hb b' hb' h
      have hb0 := h0 b hb
      have hb0' := h0 b' hb'
      by_cases h2 : 2 ∣ b
      · by_cases h2' : 2 ∣ b'
        · simp only [hgdef] at h
          rw [if_pos h2, if_pos h2'] at h
          obtain ⟨c, rfl⟩ := h2
          obtain ⟨c', rfl⟩ := h2'
          rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
            Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
          rw [h]
        · exact (hEO b hb b' hb' h2 h2' h).elim
      · by_cases h2' : 2 ∣ b'
        · exact (hEO b' hb' b hb h2' h2 h.symm).elim
        · -- both odd
          have hb1 := hφ b hb0 (ho b hb h2)
          have hb1' := hφ b' hb0' (ho b' hb' h2')
          change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
          change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
          have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
          have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
            intro t ht h2t e
            have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
            rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
            · exact hpT t ht h5
            · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
              have h7 := Nat.le_of_dvd (by norm_num) h6
              omega
          have e1 := h2p' b hb h2
          have e2 := h2p' b' hb' h2'
          simp only [hgdef] at h
          rw [if_neg h2, if_neg h2'] at h
          by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
          · rw [h3, h3']
          · rw [if_pos h3, if_neg h3'] at h
            by_cases h4 : 2 * (φ b' - 1) < n
            · rw [if_pos h4] at h; omega
            · rw [if_neg h4] at h; omega
          · rw [if_neg h3, if_pos h3'] at h
            by_cases h4 : 2 * (φ b - 1) < n
            · rw [if_pos h4] at h; omega
            · rw [if_neg h4] at h; omega
          · rw [if_neg h3, if_neg h3'] at h
            by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
            · exact hφinj (by omega)
            · rw [if_pos h4, if_neg h4'] at h; omega
            · rw [if_neg h4, if_pos h4'] at h; omega
            · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)
    have hcard : (insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p))).card = n - 2 := by
      rw [Finset.card_insert_of_notMem (by simp), Finset.card_erase_of_mem, Finset.card_erase_of_mem,
        Nat.card_Ioo]
      · omega
      · rw [Finset.mem_Ioo]; omega
      · rw [Finset.mem_erase, Finset.mem_Ioo]; omega
    have hle := Finset.card_le_card_of_injOn g hmaps hginj
    rw [hcard] at hle
    omega
  have R2b_K2half : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card) (hle : X.card ≤ S.card),
      ∀ x ∈ X, x = 1 := by
    intro n p X S hp0 h2p h9 hxs hX hS hcard hle
    have big : ∀ Y : Finset ℕ, (∀ x ∈ Y, 0 < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x := by
      intro Y hpos hY
      by_contra h
      push Not at h
      have hsub : Y ⊆ Finset.Ioo 0 Y.card := by
        intro x hx
        exact Finset.mem_Ioo.mpr ⟨hpos x hx, h x hx⟩
      have h1 := Finset.card_le_card hsub
      rw [Nat.card_Ioo] at h1
      have h2 := hY.card_pos
      omega
    have hXpos : ∀ x ∈ X, 0 < x := by
      intro x hx
      obtain ⟨s, hs⟩ := hS
      obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
      apply Nat.pos_of_ne_zero
      rintro rfl
      rw [Nat.zero_mul] at h
      omega
    have hSpos : ∀ s ∈ S, 0 < s := by
      intro s hs
      obtain ⟨x, hx⟩ := hX
      obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
      apply Nat.pos_of_ne_zero
      rintro rfl
      rw [Nat.mul_zero] at h
      omega
    have hmul : ∀ u v : ℕ, 4 ≤ u → 5 ≤ v → 2 * u + 2 * v ≤ u * v := by
      intro u v hu hv
      obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hu
      obtain ⟨b, rfl⟩ := Nat.exists_eq_add_of_le hv
      nlinarith [Nat.zero_le (a * b)]
    obtain ⟨x0, hx0, hx0c⟩ := big X hXpos hX
    obtain ⟨s0, hs0, hs0c⟩ := big S hSpos hS
    have huv : X.card * S.card < 2 * n := by
      obtain ⟨y, -, hyn, -, h⟩ := hxs x0 hx0 s0 hs0
      have h2 : X.card * S.card ≤ x0 * s0 := Nat.mul_le_mul hx0c hs0c
      omega
    have hu2 : X.card ≤ 2 := by
      by_contra h
      push Not at h
      rcases Nat.lt_or_ge X.card 4 with h4 | h4
      · have h3 : X.card = 3 := by omega
        rw [h3] at huv hcard
        omega
      · have := hmul X.card S.card h4 (by omega)
        omega
    intro x hx
    by_contra hx1
    have hxpos := hXpos x hx
    rcases Nat.lt_or_ge x 3 with h3 | h3
    · have hx2 : x = 2 := by omega
      subst hx2
      have hsub : S ⊆ ((Finset.Ioo 0 n).erase p).erase (2 * p) := by
        intro s hs
        obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs
        have hsy : s = y := by omega
        subst hsy
        rw [Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
        refine ⟨?_, ?_, hy0, hyn⟩
        · rintro rfl; exact hpy ⟨2, by ring⟩
        · rintro rfl; exact hpy ⟨1, by ring⟩
      have h1 := Finset.card_le_card hsub
      rw [Finset.card_erase_of_mem (by
          rw [Finset.mem_erase, Finset.mem_Ioo]; omega),
        Finset.card_erase_of_mem (by rw [Finset.mem_Ioo]; omega), Nat.card_Ioo] at h1
      omega
    · have hsub : S ⊆ Finset.Icc 1 (2 * (n - 1) / 3) := by
        intro s hs
        obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs
        have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3
        rw [Finset.mem_Icc]
        exact ⟨hSpos s hs, by omega⟩
      have h1 := Finset.card_le_card hsub
      rw [Nat.card_Icc] at h1
      omega
  have R2b_K2 : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card),
      (∀ x ∈ X, x = 1) ∨ (∀ s ∈ S, s = 1) := by
    intro n p X S hp0 h2p h9 hxs hX hS hcard
    rcases le_total X.card S.card with h | h
    · exact Or.inl (R2b_K2half n p X S hp0 h2p h9 hxs hX hS hcard h)
    · refine Or.inr (R2b_K2half n p S X hp0 h2p h9 ?_ hS hX (by omega) h)
      intro s hs x hx
      rw [Nat.mul_comm]
      exact hxs x hx s hs
  have R2b_block : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card) (hex : ∃ a ∈ B, p ∣ a),
      ∃ g ∈ B, ¬ p ∣ g ∧ (∀ b ∈ B, ¬ p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ 2 * p * g := by
    intro B h0 hgcd hlt p hp hp3 h2p hn3 h9 hex
    obtain ⟨a0, ha0, hpa0⟩ := hex
    have hexb : ∃ b ∈ B, ¬ p ∣ b := by
      by_contra h
      push Not at h
      have h1 : p ∣ B.gcd id := Finset.dvd_gcd (fun b hb => h b hb)
      rw [hgcd] at h1
      exact hp.one_lt.ne' (Nat.dvd_one.mp h1)
    obtain ⟨b0, hb0, hpb0⟩ := hexb
    have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
    -- the pair analysis: a = g·x, b = g·y, x ∈ {p, 2p}
    have hA : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b → ∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
        b = a.gcd b * y ∧ (a = p * a.gcd b ∨ (a = 2 * p * a.gcd b ∧ ¬ 2 ∣ y)) := by
      intro a ha hpa b hb hpb
      have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (hpos a ha)
      obtain ⟨x, hx⟩ := Nat.gcd_dvd_left a b
      obtain ⟨y, hy⟩ := Nat.gcd_dvd_right a b
      have hpg : ¬ p ∣ a.gcd b := fun h => hpb (h.trans (Nat.gcd_dvd_right a b))
      have hpx : p ∣ x := by
        have h1 : p ∣ a.gcd b * x := hx ▸ hpa
        exact (hp.dvd_mul.mp h1).resolve_left hpg
      obtain ⟨t, ht⟩ := hpx
      have hxn : x < B.card := by
        have h3 : a.gcd b * x < a.gcd b * B.card := by
          rw [← hx, Nat.mul_comm]; exact hlt a ha b hb
        exact Nat.lt_of_mul_lt_mul_left h3
      have hyn : y < B.card := by
        have h3 : a.gcd b * y < a.gcd b * B.card := by
          rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha
        exact Nat.lt_of_mul_lt_mul_left h3
      have hx0 : x ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at hx
        exact (hpos a ha).ne' hx
      have hy0 : y ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at hy
        exact (hpos b hb).ne' hy
      have hpy : ¬ p ∣ y := fun h => hpb (hy ▸ Dvd.dvd.mul_left h _)
      have hcop : Nat.Coprime x y := by
        have h1 := Nat.coprime_div_gcd_div_gcd hg0
        have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx
        have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy
        rwa [e1, e2] at h1
      have ht0 : t ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at ht
        exact hx0 ht
      have ht3 : t < 3 := by
        by_contra h
        push Not at h
        have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h
        omega
      refine ⟨y, Nat.pos_of_ne_zero hy0, hyn, hpy, hy, ?_⟩
      rcases (by omega : t = 1 ∨ t = 2) with rfl | rfl
      · left
        calc a = a.gcd b * x := hx
          _ = p * a.gcd b := by rw [ht]; ring
      · right
        refine ⟨(calc a = a.gcd b * x := hx
          _ = 2 * p * a.gcd b := by rw [ht]; ring), ?_⟩
        intro h2y
        have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩
        have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y
        omega
    have hG0 : (B.filter (fun b => ¬ p ∣ b)).gcd id ≠ 0 := by
      intro h
      have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ id b0 :=
        Finset.gcd_dvd (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)
      rw [h] at h1
      exact hpb0 (by rw [show b0 = 0 from Nat.eq_zero_of_zero_dvd h1]; exact dvd_zero p)
    have hGb : ∀ b ∈ B, ¬ p ∣ b → (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ b := by
      intro b hb hpb
      exact Finset.gcd_dvd (f := id) (Finset.mem_filter.mpr ⟨hb, hpb⟩)
    have hdiv : ∀ a ∈ B, p ∣ a → a ∣ 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
      intro a ha hpa
      have h1 : a ∣ (B.filter (fun b => ¬ p ∣ b)).gcd (fun b => (2 * p) * id b) := by
        apply Finset.dvd_gcd
        intro b hb
        obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
        obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb
        have h2 : a ∣ 2 * p * a.gcd b := by
          rcases h with h | ⟨h, -⟩
          · exact ⟨2, by linarith⟩
          · exact ⟨1, by linarith⟩
        exact h2.trans (Nat.mul_dvd_mul_left _ (Nat.gcd_dvd_right a b))
      rw [Finset.gcd_mul_left] at h1
      simpa using h1
    have hprod : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b →
        (∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
          ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = 2 * y ∨
           ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = y ∧ ¬ 2 ∣ y))) ∧
        a * (2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
      intro a ha hpa b hb hpb
      have hd := hdiv a ha hpa
      have hGb' := hGb b hb hpb
      generalize (B.filter (fun b => ¬ p ∣ b)).gcd id = G at *
      obtain ⟨e, he⟩ := hd
      obtain ⟨s, hs⟩ := hGb'
      obtain ⟨y, hy0, hyn, hpy, hy, h⟩ := hA a ha hpa b hb hpb
      have ha0' := hpos a ha
      have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b ha0'
      have hx : 2 * p * G / a = e := by rw [he]; exact Nat.mul_div_cancel_left e ha0'
      have ht : b / G = s := by
        rw [hs]; exact Nat.mul_div_cancel_left s (Nat.pos_of_ne_zero hG0)
      rw [hx, ht]
      have hmain : a * (e * s) = 2 * p * (a.gcd b * y) := by
        calc a * (e * s) = (a * e) * s := by ring
          _ = 2 * p * (G * s) := by rw [← he]; ring
          _ = 2 * p * (a.gcd b * y) := by rw [← hs, ← hy]
      refine ⟨⟨y, hy0, hyn, hpy, ?_⟩, he.symm⟩
      rcases h with h | ⟨h, h2y⟩
      · left
        have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
          calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
            _ = 2 * p * (a.gcd b * y) := hmain
            _ = p * a.gcd b * (2 * y) := by ring
        exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos hp.pos hg0) h5
      · right
        refine ⟨?_, h2y⟩
        have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
          calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
            _ = 2 * p * (a.gcd b * y) := hmain
            _ = 2 * p * a.gcd b * y := by ring
        exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) hg0) h5
    have hcardsum : (B.filter (fun a => p ∣ a)).card + (B.filter (fun b => ¬ p ∣ b)).card = B.card := by
      rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter_filter_not B B (fun a => p ∣ a)),
        Finset.filter_union_filter_not_eq]
    have hinjX : Set.InjOn (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a)
        (B.filter (fun a => p ∣ a) : Finset ℕ) := by
      intro a ha a' ha' h
      obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
      obtain ⟨haB', hpa'⟩ := Finset.mem_filter.mp ha'
      have h1 := (hprod a haB hpa b0 hb0 hpb0).2
      have h2 := (hprod a' haB' hpa' b0 hb0 hpb0).2
      simp only at h
      rw [← h] at h2
      have hq : 0 < 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a := by
        apply Nat.pos_of_ne_zero
        intro hz
        rw [hz, Nat.mul_zero] at h1
        have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)
        omega
      exact Nat.eq_of_mul_eq_mul_right hq (h1.trans h2.symm)
    have hinjT : Set.InjOn (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id)
        (B.filter (fun b => ¬ p ∣ b) : Finset ℕ) := by
      intro b hb b' hb' h
      obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
      obtain ⟨hbB', hpb'⟩ := Finset.mem_filter.mp hb'
      simp only at h
      rw [← Nat.div_mul_cancel (hGb b hbB hpb), ← Nat.div_mul_cancel (hGb b' hbB' hpb'), h]
    have hK := R2b_K2 B.card p
      ((B.filter (fun a => p ∣ a)).image (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a))
      ((B.filter (fun b => ¬ p ∣ b)).image (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id))
      hp.pos h2p h9
      (by
        intro x hx t ht
        obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hx
        obtain ⟨b, hb, rfl⟩ := Finset.mem_image.mp ht
        obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
        obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
        exact (hprod a haB hpa b hbB hpb).1)
      ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha0, hpa0⟩)⟩
      ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)⟩
      (by rw [Finset.card_image_of_injOn hinjX, Finset.card_image_of_injOn hinjT, hcardsum])
    rcases hK with hX1 | hS1
    · -- every multiple of p equals 2pG, G = 1: B = {2p} ∪ T, impossible by Lemma I
      exfalso
      have hall : ∀ a ∈ B, p ∣ a → a = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
        intro a ha hpa
        have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))
        have h2 := (hprod a ha hpa b0 hb0 hpb0).2
        rw [h1, Nat.mul_one] at h2
        exact h2
      have hG1 : (B.filter (fun b => ¬ p ∣ b)).gcd id = 1 := by
        have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
          apply Finset.dvd_gcd
          intro b hb
          by_cases hpb : p ∣ b
          · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
          · exact hGb b hb hpb
        rw [hgcd] at h1
        exact Nat.dvd_one.mp h1
      rw [hG1, Nat.mul_one] at hall
      have h2pB : 2 * p ∈ B := by rw [← hall a0 ha0 hpa0]; exact ha0
      have hT : ∀ b ∈ B.erase (2 * p), b ∈ B ∧ ¬ p ∣ b := by
        intro b hb
        obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb
        exact ⟨hbB, fun h => hne (hall b hbB h)⟩
      have hbound : ∀ b ∈ B.erase (2 * p), b < B.card * b.gcd 2 := by
        intro b hb
        obtain ⟨hbB, hpb⟩ := hT b hb
        have h1 := hlt b hbB (2 * p) h2pB
        have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb
        rwa [Nat.Coprime.gcd_mul_right_cancel_right 2 hc] at h1
      have hI := R2b_lemI B.card p (B.erase (2 * p)) hp hp3 h2p hn3
        (fun b hb => hpos b (hT b hb).1) (fun b hb => (hT b hb).2)
        (by
          intro b hb h2
          have h1 := hbound b hb
          have hc : Nat.Coprime b 2 :=
            Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)
          rw [Nat.Coprime.gcd_eq_one hc] at h1
          omega)
        (by
          intro b hb _
          have h1 := hbound b hb
          have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)
          have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3
          omega)
        (fun b hb t ht _ _ => hlt b (hT b hb).1 t (hT t ht).1)
      rw [Finset.card_erase_of_mem h2pB] at hI
      omega
    · -- every non-multiple equals G
      have hall : ∀ b ∈ B, ¬ p ∣ b → b = (B.filter (fun b => ¬ p ∣ b)).gcd id := by
        intro b hb hpb
        have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))
        have h2 := Nat.div_mul_cancel (hGb b hb hpb)
        rw [h1, Nat.one_mul] at h2
        exact h2.symm
      have hb0G := hall b0 hb0 hpb0
      refine ⟨b0, hb0, hpb0, ?_, ?_⟩
      · intro b hb hpb
        rw [hall b hb hpb, ← hb0G]
      · intro a ha
        by_cases hpa : p ∣ a
        · rw [hb0G]; exact hdiv a ha hpa
        · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl
  have R1b_dual_quot : ∀ (L a a' b b' : ℕ) (ha : a * a' = L) (hb : b * b' = L) (h0 : 0 < a),
      a' * Nat.gcd a b = b * Nat.gcd a' b' := by
    intro L a a' b b' ha hb h0
    have h1 : Nat.gcd a' b' * (a * b) = L * Nat.gcd a b := by
      rw [← Nat.gcd_mul_right]
      have e1 : a' * (a * b) = L * b := by rw [← ha]; ring
      have e2 : b' * (a * b) = L * a := by rw [← hb]; ring
      rw [e1, e2, Nat.gcd_mul_left, Nat.gcd_comm b a]
    have h2 : a * (a' * Nat.gcd a b) = a * (b * Nat.gcd a' b') := by
      rw [← mul_assoc, ha, ← h1]; ring
    exact Nat.eq_of_mul_eq_mul_left h0 h2
  have R1b_dual_strict : ∀ (L a a' b b' n : ℕ) (ha : a * a' = L) (hb : b * b' = L) (hL : 0 < L) (h : a < n * Nat.gcd a b),
      b' < n * Nat.gcd b' a' := by
    intro L a a' b b' n ha hb hL h
    have hb0 : 0 < b := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
    have hb'0 : 0 < b' := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
    have ha0 : 0 < a := Nat.pos_of_ne_zero (by rintro rfl; simp at ha; omega)
    have e := R1b_dual_quot L b b' a a' hb ha hb0
    have hg : 0 < Nat.gcd b a := Nat.gcd_pos_of_pos_left _ hb0
    have hg' : 0 < Nat.gcd b' a' := Nat.gcd_pos_of_pos_left _ hb'0
    rw [Nat.gcd_comm a b] at h
    by_contra hcon
    push Not at hcon
    have h3 : n * Nat.gcd b' a' * Nat.gcd b a ≤ b' * Nat.gcd b a := Nat.mul_le_mul_right _ hcon
    have h4 : a * Nat.gcd b' a' < n * Nat.gcd b a * Nat.gcd b' a' := Nat.mul_lt_mul_of_pos_right h hg'
    rw [e] at h3
    nlinarith
  have R1b_dual_set : ∀ (B : Finset ℕ) (n : ℕ) (hne : B.Nonempty) (h0 : 0 ∉ B) (hs : ∀ a ∈ B, ∀ b ∈ B, a < n * Nat.gcd a b),
      (B.image (fun a => B.lcm id / a)).card = B.card ∧ 0 ∉ B.image (fun a => B.lcm id / a) ∧ (B.image (fun a => B.lcm id / a)).gcd id = 1 ∧ ∀ a ∈ B.image (fun a => B.lcm id / a), ∀ b ∈ B.image (fun a => B.lcm id / a), a < n * Nat.gcd a b := by
    intro B n hne h0 hs
    set L := B.lcm id with hLdef
    have hdvd : ∀ a ∈ B, a ∣ L := fun a ha => Finset.dvd_lcm (f := id) ha
    have hL0 : L ≠ 0 := by
      intro h
      rw [hLdef, Finset.lcm_eq_zero_iff] at h
      simp at h
      exact h0 h
    have hLpos : 0 < L := Nat.pos_of_ne_zero hL0
    have hmul : ∀ a ∈ B, a * (L / a) = L := fun a ha => Nat.mul_div_cancel' (hdvd a ha)
    have hqpos : ∀ a ∈ B, 0 < L / a := by
      intro a ha
      rcases Nat.eq_zero_or_pos (L / a) with h | h
      · have := hmul a ha
        rw [h] at this
        simp at this
        exact absurd this.symm hL0
      · exact h
    have hapos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun e => h0 (e ▸ ha))
    refine ⟨?_, ?_, ?_, ?_⟩
    · apply Finset.card_image_of_injOn
      intro a ha b hb hab
      simp only at hab
      have e1 := hmul a ha
      have e2 := hmul b hb
      rw [hab] at e1
      have : a * (L / b) = b * (L / b) := by rw [e1, e2]
      exact Nat.eq_of_mul_eq_mul_right (hqpos b hb) this
    · intro h
      rw [Finset.mem_image] at h
      obtain ⟨a, ha, e⟩ := h
      have := hqpos a ha
      omega
    · set d := (B.image (fun a => L / a)).gcd id with hd
      have hdd : ∀ a ∈ B, d ∣ L / a := by
        intro a ha
        exact Finset.gcd_dvd (f := id) (Finset.mem_image_of_mem _ ha)
      obtain ⟨a0, ha0⟩ := hne
      have hdL : d ∣ L := (hdd a0 ha0).trans (Nat.div_dvd_of_dvd (hdvd a0 ha0))
      have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hdL hLpos
      have hall : ∀ a ∈ B, id a ∣ L / d := by
        intro a ha
        obtain ⟨k, hk⟩ := hdd a ha
        have e : L = d * (a * k) := by
          have := hmul a ha
          rw [hk] at this
          rw [← this]; ring
        have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos
        rw [this]; exact Dvd.intro _ rfl
      have hLdvd : L ∣ L / d := Finset.lcm_dvd hall
      have hpos' : 0 < L / d := Nat.div_pos (Nat.le_of_dvd hLpos hdL) hdpos
      have hle : L ≤ L / d := Nat.le_of_dvd hpos' hLdvd
      by_contra hne1
      have h2 : 2 ≤ d := by omega
      have := Nat.div_lt_self hLpos h2
      omega
    · intro x hx y hy
      rw [Finset.mem_image] at hx hy
      obtain ⟨a, ha, rfl⟩ := hx
      obtain ⟨b, hb, rfl⟩ := hy
      exact R1b_dual_strict L b (L / b) a (L / a) n (hmul b hb) (hmul a ha) hLpos (hs b hb a ha)
  have R2b_small : ∀ (n p : ℕ) (hp : p.Prime) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (hnp : ¬ n.Prime) (hnp1 : ∀ q : ℕ, q.Prime → n ≠ q + 1),
      3 ≤ p ∧ 9 ≤ n := by
    intro n p hp h2p hn3 hnp hnp1
    have h2 := hp.two_le
    rcases Nat.lt_or_ge p 5 with h5 | h5
    · interval_cases p
      · exfalso
        interval_cases n
        · exact hnp (by norm_num)
        · exact hnp1 5 (by norm_num) rfl
      · refine ⟨le_refl _, ?_⟩
        interval_cases n
        · exact (hnp (by norm_num)).elim
        · exact (hnp1 7 (by norm_num) rfl).elim
        · exact le_refl _
      · exact absurd hp (by norm_num)
    · omega
  have R2b_no_mid_prime : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card),
      ∀ a ∈ B, ¬ p ∣ a := by
    intro B h0 hgcd hlt p hp hp3 h2p hn3 h9
    intro a0 ha0 hpa0
    obtain ⟨g, hg, hpg, huniq, hdvd⟩ := R2b_block B h0 hgcd hlt p hp hp3 h2p hn3 h9 ⟨a0, ha0, hpa0⟩
    obtain ⟨hcard, h0', hgcd', hlt'⟩ := R1b_dual_set B B.card ⟨a0, ha0⟩ h0 hlt
    have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
    have hL : B.lcm id ∣ 2 * p * g := Finset.lcm_dvd (fun a ha => hdvd a ha)
    have hLpos : 0 < B.lcm id :=
      Nat.pos_of_dvd_of_pos hL (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) (hpos g hg))
    have hmul : ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id :=
      fun a ha => Nat.mul_div_cancel' (Finset.dvd_lcm (f := id) ha)
    have hpLg : p ∣ B.lcm id / g := by
      have h1 : p ∣ g * (B.lcm id / g) := by
        rw [hmul g hg]; exact hpa0.trans (Finset.dvd_lcm (f := id) ha0)
      exact (hp.dvd_mul.mp h1).resolve_left hpg
    rw [← hcard] at hlt' h2p hn3 h9
    obtain ⟨g', hg', hpg', huniq', -⟩ := R2b_block _ h0' hgcd' hlt' p hp hp3 h2p hn3 h9
      ⟨_, Finset.mem_image_of_mem _ hg, hpLg⟩
    have h2 : 1 < (B.erase g).card := by
      rw [Finset.card_erase_of_mem hg, ← hcard]; omega
    obtain ⟨a1, ha1, a2, ha2, hne⟩ := Finset.one_lt_card.mp h2
    obtain ⟨hne1, ha1B⟩ := Finset.mem_erase.mp ha1
    obtain ⟨hne2, ha2B⟩ := Finset.mem_erase.mp ha2
    have hfin : ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False := by
      intro a ha hag hpLa
      have hpa : p ∣ a := by
        by_contra h
        exact hag (huniq a ha h)
      obtain ⟨c, hc⟩ := hpa
      obtain ⟨d, hd⟩ := hpLa
      have h3 : p * (p * (c * d)) ∣ p * (2 * g) := by
        have h4 : p * (p * (c * d)) = B.lcm id := by
          rw [← hmul a ha, hd]; rw [hc]; ring
        rw [h4]
        exact hL.trans (dvd_of_eq (by ring))
      have h5 : p ∣ 2 * g := (Dvd.intro _ rfl).trans (Nat.dvd_of_mul_dvd_mul_left hp.pos h3)
      rcases hp.dvd_mul.mp h5 with h6 | h6
      · have := Nat.le_of_dvd (by norm_num) h6
        omega
      · exact hpg h6
    by_cases hp1 : p ∣ B.lcm id / a1
    · exact hfin a1 ha1B hne1 hp1
    · by_cases hp2 : p ∣ B.lcm id / a2
      · exact hfin a2 ha2B hne2 hp2
      · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1
        have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2
        have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm
        have m1 := hmul a1 ha1B
        have m2 := hmul a2 ha2B
        rw [e3] at m1
        have hq : 0 < B.lcm id / a2 := by
          apply Nat.pos_of_ne_zero
          intro hz
          rw [hz, Nat.mul_zero] at m2
          omega
        exact hne (Nat.eq_of_mul_eq_mul_right hq (m1.trans m2.symm))
  intro B h0 hne hgcd hnp hnp1 hle hpp
  rcases hmid B h0 hne hgcd hnp hnp1 hle hpp with h | ⟨p, hp, hn3, a, ha, hpa⟩
  · exact Or.inl h
  · by_cases h2 : B.card ≤ 2 * p
    · exact Or.inr ⟨p, hp, h2, a, ha, hpa⟩
    · left
      by_contra hcon
      have hn : 0 < B.card := hne.card_pos
      have hnq : (0 : ℚ) < B.card := by exact_mod_cast hn
      have hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b := by
        intro a ha b hb
        rcases (hle a ha b hb).lt_or_eq with h | h
        · exact h
        · exfalso
          apply hcon
          refine ⟨a, ha, b, hb, ?_⟩
          rw [le_div_iff₀ hnq]
          have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
          exact_mod_cast h2
      obtain ⟨hp3, h9⟩ := R2b_small B.card p hp (by omega) hn3 hnp hnp1
      exact R2b_no_mid_prime B h0 hgcd hlt p hp hp3 (by omega) hn3 h9 a ha hpa
Closing it through its holes

Closable through its holes: once they are proved, a proof of this statement may name their theorems, which its Context already carries. A direct proof is accepted at any time.

What is known

Work on it

Work on this statement →

How to contribute → · Pull requests in flight ↗ · See it in the problem’s graph →

Record

Statement: the Lean file and its words (1 version)

Statement not audited — only a problem’s root statement is audited for fidelity (D-9); the kernel checks a proof against this Lean as written.

import Mathlib
import Nodes.«erdos-402--h3-v2--h1--h1».Context

open Filter

/-! Hole `hsmooth` of a merged partial proof, as a node (D-12 #5, D-29).
Statement generated by the gate from the assembly; immutable (D-3). -/

theorem erdos_402__h3_v2__h1__h1 : ∀ (B : Finset ℕ),
  (0 : ℕ) ∉ B →
    B.Nonempty →
      B.gcd id = (1 : ℕ) →
        ¬Nat.Prime B.card →
          (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) →
            (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
              (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) →
                (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨
                  ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a := by
  sorry

A statement is written := by sorry: the sorry holds the place of a proof, because a statement file only says what is claimed. A proof the gate checked is its own file, Proof.lean. How to read a proof page →

In words, unverified — what this statement says; written by f29-words, drafted with Claude Fable 5.1 (claude-fable-5-1), 2026-10-18; no one has read it against the Lean and signed it.

Draft · drafted, by the model named above

$\displaystyle \begin{aligned}&0 \notin B,\ B \ne \emptyset,\ \gcd(B) = 1,\ |B|\ \text{not prime},\ |B| \ne q + 1\ \text{for every prime } q,\\&\forall a, b \in B:\ a \le |B| \cdot \gcd(a,b),\qquad \forall a \in B,\ \forall p\ \text{prime},\ \forall k \in \mathbb{N}:\ p^k \mid a \Rightarrow p^k < |B|\\&\Longrightarrow\ \bigl(\exists\, a, b \in B:\ \gcd(a,b) \le \frac{a}{|B|}\bigr) \vee \bigl(\exists\, p\ \text{prime}:\ |B| \le 2p,\ \exists\, a \in B,\ p \mid a\bigr)\end{aligned}$

For every finite set B of positive integers (0 ∉ B, B nonempty) whose elements have greatest common divisor 1, whose size |B| is neither a prime nor one more than a prime, in which a ≤ |B|·gcd(a, b) for all a, b ∈ B, and in which every prime power dividing an element is below |B|, either some a, b ∈ B (possibly equal) have gcd(a, b) ≤ a/|B|, or some element of B has a prime factor p with |B| ≤ 2p. gcd(B) is the greatest common divisor of all elements of B; the division is in ℚ, the rest is over ℕ.

Rendered from gloss/67a1a678dfc5….md · Improve these words →

Rendered from targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/Statement.lean. Origin: compiler-derived.

Depends on (1), each in words

Depends on, each in words where someone has written them:

  • erdos-402--h3-v2--h1--h1--h1: $\begin{aligned}&0 \notin B,\ B \ne \emptyset,\ \gcd(B) = 1,\ |B|\ \text{not prime},\ |B| \ne q + 1\ \text{for every prime } q,\\&\forall a, b \in B:\ a \le |B| \cdot \gcd(a,b),\qquad \forall a \in B,\ \forall p\ \text{prime},\ \forall k \in \mathbb{N}:\ p^k \mid a \Rightarrow p^k < |B|\\&\Longrightarrow\ \bigl(\exists\, a, b \in B:\ \gcd(a,b) \le \frac{a}{|B|}\bigr) \vee \bigl(\exists\, p\ \text{prime}:\ |B| \le 3p,\ \exists\, a \in B,\ p \mid a\bigr)\end{aligned}$
Attestation: none of a proof

No proof of this statement has been merged. A partial assembly merged under attestations/000344.json: it records an attempt, not a proof (see Attempts below).

Witness

Not checked — no run on this page records step 7 passing for it.

Witness.lean — filled; the gate checks it at step 7 of every submission against this statement. Rendered from targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/Witness.lean, sha256 853b068efe9d.
import Mathlib
import Nodes.«erdos-402--h3-v2--h1--h1».Context

open Filter

theorem witness : ∃ B : Finset ℕ, 0 ∉ B ∧ B.Nonempty ∧ B.gcd id = 1 ∧ ¬ B.card.Prime ∧
    (∀ q : ℕ, q.Prime → B.card ≠ q + 1) ∧
    (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) ∧
    (∀ a ∈ B, ∀ p k : ℕ, p.Prime → p ^ k ∣ a → p ^ k < B.card) := by
  have hc : ({1, 2, 3, 4, 5, 6, 7, 8, 9, 10} : Finset ℕ).card = 10 := by decide
  refine ⟨{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, by decide, ⟨1, by decide⟩, by decide, ?_, ?_, ?_, ?_⟩
  · rw [hc]
    norm_num
  · intro q hq h
    rw [hc] at h
    have hq9 : q = 9 := by omega
    rw [hq9] at hq
    norm_num at hq
  · intro a ha b hb
    rw [hc]
    simp only [Finset.mem_insert, Finset.mem_singleton] at ha
    have ha10 : a ≤ 10 := by omega
    have hg : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (by omega)
    calc a ≤ 10 := ha10
      _ ≤ 10 * a.gcd b := Nat.le_mul_of_pos_right 10 hg
  · intro a ha p k hp hdvd
    rw [hc]
    simp only [Finset.mem_insert, Finset.mem_singleton] at ha
    have ha0 : 0 < a := by omega
    have hle : p ^ k ≤ a := Nat.le_of_dvd ha0 hdvd
    have hne : p ^ k ≠ 10 := by
      intro h10
      have hk : k ≠ 0 := by
        rintro rfl
        simp at h10
      have hp10 : p ∣ 10 := by
        rw [← h10]
        exact dvd_pow_self p hk
      have hp10' : p ≤ 10 := Nat.le_of_dvd (by norm_num) hp10
      have hk4 : k < 4 := by
        have h2 : 2 ^ k ≤ p ^ k := Nat.pow_le_pow_left hp.two_le k
        by_contra hk4
        push Not at hk4
        have h16 : 2 ^ 4 ≤ 2 ^ k := Nat.pow_le_pow_right (by norm_num) hk4
        omega
      have hp2 := hp.two_le
      interval_cases p <;> interval_cases k <;> simp_all (config := { decide := true })
    omega

No gloss yet: no one has written in words what this witness says (D-3 v3.30); the Lean above is the witness. How to write one →

Attempts (1)

1 recorded. Routes refuted: none. Failure classes: none.

Untrusted contributor text — a partial assembly: it records an attempt, not a proof; its attestation names the file, and no hash in the record binds these bytes.

Untrusted: partial assembly (D-12 #5), by t1001-402a; merged in f2aff77837fd under attestations/000344.json, whose step 2 took this file as a partial. A partial records an attempt, not a proof: the gate replayed it with its holes left as sorry. Rendered from targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean.

Untrusted contributor text — an outline the gate extracted from this partial assembly; its holes are sorry steps, and it records an attempt, not a proof.

Outline of 20261001T143056Z-t1001-402a-partial.lean, extracted by the gate at 82834c4684b8 from the proof’s elaboration: each step is a claim the proof establishes and the goal it leaves. Open a step for what it uses and its Lean lines.

  1. hmid hole ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (3 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a hole

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with hmid : ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (3 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a.

    Uses library Finset Finset α is the type of finite sets of elements of α. , id The identity function. .

    Left open as a hole; its statement is erdos-402--h3-v2--h1--h1--h1 (open).

    Lean, lines 23–28
      have hmid : ∀ B : Finset ℕ, 0 ∉ B → B.Nonempty → B.gcd id = 1 → ¬ B.card.Prime →
          (∀ q : ℕ, q.Prime → B.card ≠ q + 1) →
          (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
          (∀ a ∈ B, ∀ p k : ℕ, p.Prime → p ^ k ∣ a → p ^ k < B.card) →
          (∃ a ∈ B, ∃ b ∈ B, (a.gcd b : ℚ) ≤ (a : ℚ) / (B.card : ℚ)) ∨
            ∃ p : ℕ, p.Prime ∧ B.card ≤ 3 * p ∧ ∃ a ∈ B, p ∣ a := sorry

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 23–28 at 841d05f96fd2 ↗

  2. R2b_lemI have ∀ (n p : ℕ) (T : Finset ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < n → n ≤ (3 : ℕ) * p → (∀ b ∈ T, (0 : ℕ) < b) → (∀ b ∈ T, ¬p ∣ b) → (∀ b ∈ T, ¬(2 : ℕ) ∣ b → b < n) → (∀ b ∈ T, (2 : ℕ) ∣ b → b < (2 : ℕ) * n) → (∀ b ∈ T, ∀ t ∈ T, (2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ t → b < n * b.gcd t) → T.card + (2 : ℕ) ≤ n

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_lemI : ∀ (n p : ℕ) (T : Finset ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < n → n ≤ (3 : ℕ) * p → (∀ b ∈ T, (0 : ℕ) < b) → (∀ b ∈ T, ¬p ∣ b) → (∀ b ∈ T, ¬(2 : ℕ) ∣ b → b < n) → (∀ b ∈ T, (2 : ℕ) ∣ b → b < (2 : ℕ) * n) → (∀ b ∈ T, ∀ t ∈ T, (2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ t → b < n * b.gcd t) → T.card + (2 : ℕ) ≤ n.

    Uses library Finset Finset α is the type of finite sets of elements of α. , Nat.log log b n, is the logarithm of natural number n in base b. .

    Lean, lines 29–196
      have R2b_lemI : ∀ (n p : ℕ) (T : Finset ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (h0 : ∀ b ∈ T, 0 < b) (hpT : ∀ b ∈ T, ¬ p ∣ b) (ho : ∀ b ∈ T, ¬ 2 ∣ b → b < n) (he : ∀ b ∈ T, 2 ∣ b → b < 2 * n) (hx : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → b < n * b.gcd t),
          T.card + 2 ≤ n := by
        intro n p T hp hp3 h2p hn3 h0 hpT ho he hx
        -- φ t = the unique t·2^j in [n/2, n-1]
        have hφ : ∀ b : ℕ, 0 < b → b < n →
            b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ n - 1 ∧ n - 1 < 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by
          intro b hb hbn
          have hne : (n - 1) / b ≠ 0 := by
            have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb
            omega
          have h1 := Nat.pow_log_le_self 2 hne
          have h2 := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) ((n - 1) / b)
          have h3 : b * ((n - 1) / b) ≤ n - 1 := Nat.mul_div_le _ _
          have h4 : b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ b * ((n - 1) / b) := Nat.mul_le_mul_left b h1
          have h5 : n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := (Nat.div_lt_iff_lt_mul hb).mp h2
          refine ⟨h4.trans h3, ?_⟩
          calc n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := h5
            _ = 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by rw [pow_succ]; ring
        have hinj0 : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → j ≤ j' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
          intro b b' j j' hb hjj h
          obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le hjj
          have h1 : b * 2 ^ j = (b' * 2 ^ d) * 2 ^ j := by rw [h, pow_add]; ring
          have h2 : b = b' * 2 ^ d := Nat.eq_of_mul_eq_mul_right (by positivity) h1
          rcases Nat.eq_zero_or_pos d with hd | hd
          · rw [hd] at h2; simpa using h2
          · exfalso; apply hb; rw [h2]
            exact Dvd.dvd.mul_left (dvd_pow_self 2 (by omega)) _
        have hinj : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → ¬ 2 ∣ b' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
          intro b b' j j' hb hb' h
          rcases le_total j j' with hjj | hjj
          · exact hinj0 b b' j j' hb hjj h
          · exact (hinj0 b' b j' j hb' hjj h.symm).symm
        -- coprimality of t with (t·m − 1)
        have hcop : ∀ t m w : ℕ, w + 1 = t * m → Nat.Coprime w t := by
          intro t m w h
          have h1 : Nat.Coprime w (w + 1) := by simp
          rw [h] at h1
          exact Nat.Coprime.coprime_mul_right_right h1
        set φ : ℕ → ℕ := fun b => b * 2 ^ Nat.log 2 ((n - 1) / b) with hφdef
        set g : ℕ → ℕ := fun b =>
          if 2 ∣ b then b / 2 else if b = 2 * p + 1 then 2 * p - 1
          else if 2 * (φ b - 1) < n then 0 else φ b - 1 with hgdef
        have hmaps : ∀ b ∈ T, g b ∈ insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p)) := by
          intro b hb
          have hb0 := h0 b hb
          have hpb := hpT b hb
          rw [Finset.mem_insert, Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
          simp only [hgdef]
          by_cases h2 : 2 ∣ b
          · rw [if_pos h2]
            right
            obtain ⟨c, rfl⟩ := h2
            have := he _ hb ⟨c, rfl⟩
            rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2)]
            refine ⟨?_, ?_, ?_, ?_⟩
            · rintro rfl; exact hpb ⟨4, by ring⟩
            · rintro rfl; exact hpb ⟨2, by ring⟩
            · omega
            · omega
          · rw [if_neg h2]
            by_cases h3 : b = 2 * p + 1
            · rw [if_pos h3]; right; omega
            · rw [if_neg h3]
              by_cases h4 : 2 * (φ b - 1) < n
              · rw [if_pos h4]; left; rfl
              · rw [if_neg h4]
                right
                have hb1 := hφ b hb0 (ho b hb h2)
                have hne : φ b ≠ 2 * p + 1 := by
                  intro h
                  have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                  exact h3 (hinj _ _ _ _ h2 (by omega) h5)
                change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                omega
        have hginj : Set.InjOn g (T : Set ℕ) := by
          -- even / odd collision is impossible
          have hEO : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → g b = g t → False := by
            intro b hb t ht h2b h2t h
            have hb0 := h0 b hb
            have ht0 := h0 t ht
            have hx' := hx b hb t ht h2b h2t
            obtain ⟨c, rfl⟩ := h2b
            simp only [hgdef] at h
            rw [if_pos ⟨c, rfl⟩, if_neg h2t, Nat.mul_div_cancel_left c (by norm_num : 0 < 2)] at h
            by_cases h3 : t = 2 * p + 1
            · rw [if_pos h3] at h
              have hc : Nat.Coprime c t := by
                have h1 : Nat.Coprime c (2 + c) := by
                  rw [Nat.coprime_add_self_right]
                  rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                  intro hd; omega
                have : 2 + c = t := by omega
                rwa [this] at h1
              have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
              have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
              rw [hg] at hx'
              omega
            · rw [if_neg h3] at h
              by_cases h4 : 2 * (φ t - 1) < n
              · rw [if_pos h4] at h; omega
              · rw [if_neg h4] at h
                have ht1 := hφ t ht0 (ho t ht h2t)
                change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
                have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                  change c + 1 = φ t
                  omega)
                have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                rw [hg] at hx'
                omega
          intro b hb b' hb' h
          have hb0 := h0 b hb
          have hb0' := h0 b' hb'
          by_cases h2 : 2 ∣ b
          · by_cases h2' : 2 ∣ b'
            · simp only [hgdef] at h
              rw [if_pos h2, if_pos h2'] at h
              obtain ⟨c, rfl⟩ := h2
              obtain ⟨c', rfl⟩ := h2'
              rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
                Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
              rw [h]
            · exact (hEO b hb b' hb' h2 h2' h).elim
          · by_cases h2' : 2 ∣ b'
            · exact (hEO b' hb' b hb h2' h2 h.symm).elim
            · -- both odd
              have hb1 := hφ b hb0 (ho b hb h2)
              have hb1' := hφ b' hb0' (ho b' hb' h2')
              change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
              change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
              have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
              have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
                intro t ht h2t e
                have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
                rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
                · exact hpT t ht h5
                · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                  have h7 := Nat.le_of_dvd (by norm_num) h6
                  omega
              have e1 := h2p' b hb h2
              have e2 := h2p' b' hb' h2'
              simp only [hgdef] at h
              rw [if_neg h2, if_neg h2'] at h
              by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
              · rw [h3, h3']
              · rw [if_pos h3, if_neg h3'] at h
                by_cases h4 : 2 * (φ b' - 1) < n
                · rw [if_pos h4] at h; omega
                · rw [if_neg h4] at h; omega
              · rw [if_neg h3, if_pos h3'] at h
                by_cases h4 : 2 * (φ b - 1) < n
                · rw [if_pos h4] at h; omega
                · rw [if_neg h4] at h; omega
              · rw [if_neg h3, if_neg h3'] at h
                by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
                · exact hφinj (by omega)
                · rw [if_pos h4, if_neg h4'] at h; omega
                · rw [if_neg h4, if_pos h4'] at h; omega
                · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)
        have hcard : (insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p))).card = n - 2 := by
          rw [Finset.card_insert_of_notMem (by simp), Finset.card_erase_of_mem, Finset.card_erase_of_mem,
            Nat.card_Ioo]
          · omega
          · rw [Finset.mem_Ioo]; omega
          · rw [Finset.mem_erase, Finset.mem_Ioo]; omega
        have hle := Finset.card_le_card_of_injOn g hmaps hginj
        rw [hcard] at hle
        omega

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 29–196 at 841d05f96fd2 ↗

    1. R2b_lemI.h_x3c6 (hφ) have ∀ (b : ℕ), (0 : ℕ) < b → b < n → b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b))

      Leaves T.card + (2 : ℕ) ≤ n, with hφ : ∀ (b : ℕ), (0 : ℕ) < b → b < n → b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).

      Uses library Nat.log log b n, is the logarithm of natural number n in base b. , And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

      Lean, lines 33–46
          have hφ : ∀ b : ℕ, 0 < b → b < n →
              b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ n - 1 ∧ n - 1 < 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by
            intro b hb hbn
            have hne : (n - 1) / b ≠ 0 := by
              have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb
              omega
            have h1 := Nat.pow_log_le_self 2 hne
            have h2 := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) ((n - 1) / b)
            have h3 : b * ((n - 1) / b) ≤ n - 1 := Nat.mul_div_le _ _
            have h4 : b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ b * ((n - 1) / b) := Nat.mul_le_mul_left b h1
            have h5 : n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := (Nat.div_lt_iff_lt_mul hb).mp h2
            refine ⟨h4.trans h3, ?_⟩
            calc n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := h5
              _ = 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by rw [pow_succ]; ring

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 33–46 at 841d05f96fd2 ↗

      1. R2b_lemI.h_x3c6.hne have (n - (1 : ℕ)) / b ≠ (0 : ℕ)

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with hne : (n - (1 : ℕ)) / b ≠ (0 : ℕ).

        Lean, lines 36–38
              have hne : (n - 1) / b ≠ 0 := by
                have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 36–38 at 841d05f96fd2 ↗

        1. R2b_lemI.h_x3c6.hne.this have (0 : ℕ) < (n - (1 : ℕ)) / b

          Leaves (n - (1 : ℕ)) / b ≠ (0 : ℕ), with this : (0 : ℕ) < (n - (1 : ℕ)) / b.

          Uses library Nat.div_pos.

          Lean, line 37
                  have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 37 at 841d05f96fd2 ↗

      2. R2b_lemI.h_x3c6.h1 have (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ (n - (1 : ℕ)) / b

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with h1 : (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ (n - (1 : ℕ)) / b.

        Uses library Nat.pow_log_le_self.

        Lean, line 39
              have h1 := Nat.pow_log_le_self 2 hne

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 39 at 841d05f96fd2 ↗

      3. R2b_lemI.h_x3c6.h2 have (n - (1 : ℕ)) / b < (2 : ℕ) ^ (Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).succ

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with h2 : (n - (1 : ℕ)) / b < (2 : ℕ) ^ (Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).succ.

        Uses library Nat.lt_pow_succ_log_self.

        Lean, line 40
              have h2 := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) ((n - 1) / b)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 40 at 841d05f96fd2 ↗

      4. R2b_lemI.h_x3c6.h3 have b * ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ)

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with h3 : b * ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ).

        Uses library Nat.mul_div_le.

        Lean, line 41
              have h3 : b * ((n - 1) / b) ≤ n - 1 := Nat.mul_div_le _ _

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 41 at 841d05f96fd2 ↗

      5. R2b_lemI.h_x3c6.h4 have b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ b * ((n - (1 : ℕ)) / b)

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with h4 : b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ b * ((n - (1 : ℕ)) / b).

        Uses library Nat.log log b n, is the logarithm of natural number n in base b. , Nat.mul_le_mul_left.

        Lean, line 42
              have h4 : b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ b * ((n - 1) / b) := Nat.mul_le_mul_left b h1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 42 at 841d05f96fd2 ↗

      6. R2b_lemI.h_x3c6.h5 have n - (1 : ℕ) < (2 : ℕ) ^ (Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).succ * b

        Leaves b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)), with h5 : n - (1 : ℕ) < (2 : ℕ) ^ (Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).succ * b.

        Uses library Nat.log log b n, is the logarithm of natural number n in base b. , Nat.div_lt_iff_lt_mul.

        Lean, line 43
              have h5 : n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := (Nat.div_lt_iff_lt_mul hb).mp h2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 43 at 841d05f96fd2 ↗

      7. R2b_lemI.h_x3c6.s7 calc n - (1 : ℕ) < (2 : ℕ) ^ (Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).succ * b

        Closes the goal.

        Uses library Nat.log log b n, is the logarithm of natural number n in base b. .

        Lean, line 45
              calc n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := h5

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 45 at 841d05f96fd2 ↗

      8. R2b_lemI.h_x3c6.s8 calc

        Closes the goal.

        Uses library Nat.log log b n, is the logarithm of natural number n in base b. , pow_succ.

        Lean, line 46
                _ = 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by rw [pow_succ]; ring

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 46 at 841d05f96fd2 ↗

    2. R2b_lemI.hinj0 have ∀ (b b' j j' : ℕ), ¬(2 : ℕ) ∣ b → j ≤ j' → b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ j' → b = b'

      Leaves T.card + (2 : ℕ) ≤ n, with hinj0 : ∀ (b b' j j' : ℕ), ¬(2 : ℕ) ∣ b → j ≤ j' → b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ j' → b = b'.

      Uses library Nat.eq_zero_or_pos.

      Lean, lines 47–55
          have hinj0 : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → j ≤ j' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
            intro b b' j j' hb hjj h
            obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le hjj
            have h1 : b * 2 ^ j = (b' * 2 ^ d) * 2 ^ j := by rw [h, pow_add]; ring
            have h2 : b = b' * 2 ^ d := Nat.eq_of_mul_eq_mul_right (by positivity) h1
            rcases Nat.eq_zero_or_pos d with hd | hd
            · rw [hd] at h2; simpa using h2
            · exfalso; apply hb; rw [h2]
              exact Dvd.dvd.mul_left (dvd_pow_self 2 (by omega)) _

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 47–55 at 841d05f96fd2 ↗

      1. R2b_lemI.hinj0.s1 obtain ∃ (k : ℕ), j' = j + k

        Leaves b = b', with d : ℕ, hjj : j ≤ j + d, h : b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ (j + d).

        Uses library Nat.exists_eq_add_of_le.

        Lean, line 49
              obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le hjj

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 49 at 841d05f96fd2 ↗

      2. R2b_lemI.hinj0.h1 have b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ d * (2 : ℕ) ^ j

        Leaves b = b', with h1 : b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ d * (2 : ℕ) ^ j.

        Uses library pow_add.

        Lean, line 50
              have h1 : b * 2 ^ j = (b' * 2 ^ d) * 2 ^ j := by rw [h, pow_add]; ring

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 50 at 841d05f96fd2 ↗

      3. R2b_lemI.hinj0.h2 have b = b' * (2 : ℕ) ^ d

        Leaves b = b', with h2 : b = b' * (2 : ℕ) ^ d.

        Uses library Nat.eq_of_mul_eq_mul_right.

        Lean, line 51
              have h2 : b = b' * 2 ^ d := Nat.eq_of_mul_eq_mul_right (by positivity) h1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 51 at 841d05f96fd2 ↗

      4. R2b_lemI.hinj0.s4 case
      5. R2b_lemI.hinj0.s5 case

        Leaves b = b'.

        Uses library Dvd.dvd.mul_left Alias of dvd_mul_of_dvd_right. , dvd_pow_self.

        Lean, lines 54–55
              · exfalso; apply hb; rw [h2]
                exact Dvd.dvd.mul_left (dvd_pow_self 2 (by omega)) _

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 54–55 at 841d05f96fd2 ↗

    3. R2b_lemI.hinj have ∀ (b b' j j' : ℕ), ¬(2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ b' → b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ j' → b = b'

      Leaves T.card + (2 : ℕ) ≤ n, with hinj : ∀ (b b' j j' : ℕ), ¬(2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ b' → b * (2 : ℕ) ^ j = b' * (2 : ℕ) ^ j' → b = b'.

      Uses library le_total.

      Lean, lines 56–60
          have hinj : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → ¬ 2 ∣ b' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
            intro b b' j j' hb hb' h
            rcases le_total j j' with hjj | hjj
            · exact hinj0 b b' j j' hb hjj h
            · exact (hinj0 b' b j' j hb' hjj h.symm).symm

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 56–60 at 841d05f96fd2 ↗

      1. R2b_lemI.hinj.s1 case
      2. R2b_lemI.hinj.s2 case
    4. R2b_lemI.hcop have ∀ (t m w : ℕ), w + (1 : ℕ) = t * m → w.Coprime t

      Leaves T.card + (2 : ℕ) ≤ n, with hcop : ∀ (t m w : ℕ), w + (1 : ℕ) = t * m → w.Coprime t.

      Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.Coprime.coprime_mul_right_right.

      Lean, lines 62–66
          have hcop : ∀ t m w : ℕ, w + 1 = t * m → Nat.Coprime w t := by
            intro t m w h
            have h1 : Nat.Coprime w (w + 1) := by simp
            rw [h] at h1
            exact Nat.Coprime.coprime_mul_right_right h1

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 62–66 at 841d05f96fd2 ↗

      1. R2b_lemI.hcop.h1 have w.Coprime (w + (1 : ℕ)) routine: simp

        Leaves w.Coprime t, with h1 : w.Coprime (w + (1 : ℕ)).

        Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. .

        Lean, line 64
              have h1 : Nat.Coprime w (w + 1) := by simp

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 64 at 841d05f96fd2 ↗

    5. R2b_lemI.hmaps have ∀ b ∈ T, g b ∈ insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p))

      Leaves T.card + (2 : ℕ) ≤ n, with hmaps : ∀ b ∈ T, g b ∈ insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)).

      Uses library Insert.insert insert x xs inserts the element x into the collection xs. , Finset.Ioo The finset $(a, b)$ of elements x such that a < x and x < b. , Finset.mem_insert, Finset.mem_erase, Finset.mem_Ioo.

      Lean, lines 71–102
          have hmaps : ∀ b ∈ T, g b ∈ insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p)) := by
            intro b hb
            have hb0 := h0 b hb
            have hpb := hpT b hb
            rw [Finset.mem_insert, Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
            simp only [hgdef]
            by_cases h2 : 2 ∣ b
            · rw [if_pos h2]
              right
              obtain ⟨c, rfl⟩ := h2
              have := he _ hb ⟨c, rfl⟩
              rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2)]
              refine ⟨?_, ?_, ?_, ?_⟩
              · rintro rfl; exact hpb ⟨4, by ring⟩
              · rintro rfl; exact hpb ⟨2, by ring⟩
              · omega
              · omega
            · rw [if_neg h2]
              by_cases h3 : b = 2 * p + 1
              · rw [if_pos h3]; right; omega
              · rw [if_neg h3]
                by_cases h4 : 2 * (φ b - 1) < n
                · rw [if_pos h4]; left; rfl
                · rw [if_neg h4]
                  right
                  have hb1 := hφ b hb0 (ho b hb h2)
                  have hne : φ b ≠ 2 * p + 1 := by
                    intro h
                    have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                    exact h3 (hinj _ _ _ _ h2 (by omega) h5)
                  change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                  omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 71–102 at 841d05f96fd2 ↗

      1. R2b_lemI.hmaps.hb0 have (0 : ℕ) < b

        Leaves g b ∈ insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)), with hb0 : (0 : ℕ) < b.

        Lean, line 73
              have hb0 := h0 b hb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 73 at 841d05f96fd2 ↗

      2. R2b_lemI.hmaps.hpb have ¬p ∣ b

        Leaves g b ∈ insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)), with hpb : ¬p ∣ b.

        Lean, line 74
              have hpb := hpT b hb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 74 at 841d05f96fd2 ↗

      3. R2b_lemI.hmaps.s3 case

        Leaves (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

        Uses library if_pos, Nat.mul_div_cancel_left, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 78–87
              · rw [if_pos h2]
                right
                obtain ⟨c, rfl⟩ := h2
                have := he _ hb ⟨c, rfl⟩
                rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2)]
                refine ⟨?_, ?_, ?_, ?_⟩
                · rintro rfl; exact hpb ⟨4, by ring⟩
                · rintro rfl; exact hpb ⟨2, by ring⟩
                · omega
                · omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 78–87 at 841d05f96fd2 ↗

        1. R2b_lemI.hmaps.s3.s1 obtain (2 : ℕ) ∣ b

          Leaves (2 : ℕ) * c / (2 : ℕ) ≠ (2 : ℕ) * p ∧ (2 : ℕ) * c / (2 : ℕ) ≠ p ∧ (0 : ℕ) < (2 : ℕ) * c / (2 : ℕ) ∧ (2 : ℕ) * c / (2 : ℕ) < n, with c : ℕ, hb : (2 : ℕ) * c ∈ T, hb0 : (0 : ℕ) < (2 : ℕ) * c, hpb : ¬p ∣ (2 : ℕ) * c.

          Lean, line 80
                  obtain ⟨c, rfl⟩ := h2

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 80 at 841d05f96fd2 ↗

        2. R2b_lemI.hmaps.s3.this have (2 : ℕ) * c < (2 : ℕ) * n

          Leaves (2 : ℕ) * c / (2 : ℕ) ≠ (2 : ℕ) * p ∧ (2 : ℕ) * c / (2 : ℕ) ≠ p ∧ (0 : ℕ) < (2 : ℕ) * c / (2 : ℕ) ∧ (2 : ℕ) * c / (2 : ℕ) < n, with this : (2 : ℕ) * c < (2 : ℕ) * n.

          Uses library Exists.intro Existential introduction. , rfl rfl : a = a is the unique constructor of the equality type. .

          Lean, line 81
                  have := he _ hb ⟨c, rfl⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 81 at 841d05f96fd2 ↗

        3. R2b_lemI.hmaps.s3.s3 case

          Leaves c ≠ (2 : ℕ) * p.

          Uses library Exists.intro Existential introduction. .

          Lean, line 84
                  · rintro rfl; exact hpb ⟨4, by ring⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 84 at 841d05f96fd2 ↗

        4. R2b_lemI.hmaps.s3.s4 case

          Leaves c ≠ p.

          Uses library Exists.intro Existential introduction. .

          Lean, line 85
                  · rintro rfl; exact hpb ⟨2, by ring⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 85 at 841d05f96fd2 ↗

        5. R2b_lemI.hmaps.s3.s5 case routine: omega
        6. R2b_lemI.hmaps.s3.s6 case routine: omega
      4. R2b_lemI.hmaps.s4 case

        Leaves (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if (2 : ℕ) ∣ b then b / (2 : ℕ) else if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

        Uses library if_neg.

        Lean, lines 88–102
              · rw [if_neg h2]
                by_cases h3 : b = 2 * p + 1
                · rw [if_pos h3]; right; omega
                · rw [if_neg h3]
                  by_cases h4 : 2 * (φ b - 1) < n
                  · rw [if_pos h4]; left; rfl
                  · rw [if_neg h4]
                    right
                    have hb1 := hφ b hb0 (ho b hb h2)
                    have hne : φ b ≠ 2 * p + 1 := by
                      intro h
                      have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                      exact h3 (hinj _ _ _ _ h2 (by omega) h5)
                    change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                    omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 88–102 at 841d05f96fd2 ↗

        1. R2b_lemI.hmaps.s4.s1 case

          Leaves (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

          Uses library if_pos.

          Lean, line 90
                  · rw [if_pos h3]; right; omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 90 at 841d05f96fd2 ↗

        2. R2b_lemI.hmaps.s4.s2 case

          Leaves (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if b = (2 : ℕ) * p + (1 : ℕ) then (2 : ℕ) * p - (1 : ℕ) else if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

          Uses library if_neg.

          Lean, lines 91–102
                  · rw [if_neg h3]
                    by_cases h4 : 2 * (φ b - 1) < n
                    · rw [if_pos h4]; left; rfl
                    · rw [if_neg h4]
                      right
                      have hb1 := hφ b hb0 (ho b hb h2)
                      have hne : φ b ≠ 2 * p + 1 := by
                        intro h
                        have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                        exact h3 (hinj _ _ _ _ h2 (by omega) h5)
                      change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                      omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 91–102 at 841d05f96fd2 ↗

          1. R2b_lemI.hmaps.s4.s2.s1 case

            Leaves (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

            Uses library if_pos.

            Lean, line 93
                      · rw [if_pos h4]; left; rfl

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 93 at 841d05f96fd2 ↗

          2. R2b_lemI.hmaps.s4.s2.s2 case

            Leaves (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) = (0 : ℕ) ∨ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ (2 : ℕ) * p ∧ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ≠ p ∧ ((0 : ℕ) < if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) ∧ (if (2 : ℕ) * (φ b - (1 : ℕ)) < n then (0 : ℕ) else φ b - (1 : ℕ)) < n.

            Uses library if_neg.

            Lean, lines 94–102
                      · rw [if_neg h4]
                        right
                        have hb1 := hφ b hb0 (ho b hb h2)
                        have hne : φ b ≠ 2 * p + 1 := by
                          intro h
                          have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                          exact h3 (hinj _ _ _ _ h2 (by omega) h5)
                        change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                        omega

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 94–102 at 841d05f96fd2 ↗

            1. R2b_lemI.hmaps.s4.s2.s2.hb1 have b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b))

              Leaves φ b - (1 : ℕ) ≠ (2 : ℕ) * p ∧ φ b - (1 : ℕ) ≠ p ∧ (0 : ℕ) < φ b - (1 : ℕ) ∧ φ b - (1 : ℕ) < n, with hb1 : b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).

              Lean, line 96
                          have hb1 := hφ b hb0 (ho b hb h2)

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 96 at 841d05f96fd2 ↗

            2. R2b_lemI.hmaps.s4.s2.s2.hne have φ b ≠ (2 : ℕ) * p + (1 : ℕ)

              Leaves φ b - (1 : ℕ) ≠ (2 : ℕ) * p ∧ φ b - (1 : ℕ) ≠ p ∧ (0 : ℕ) < φ b - (1 : ℕ) ∧ φ b - (1 : ℕ) < n, with hne : φ b ≠ (2 : ℕ) * p + (1 : ℕ).

              Lean, lines 97–100
                          have hne : φ b ≠ 2 * p + 1 := by
                            intro h
                            have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
                            exact h3 (hinj _ _ _ _ h2 (by omega) h5)

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 97–100 at 841d05f96fd2 ↗

              1. R2b_lemI.hmaps.s4.s2.s2.hne.h5 have b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) = ((2 : ℕ) * p + (1 : ℕ)) * (2 : ℕ) ^ (0 : ℕ)

                Leaves False, with h5 : b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) = ((2 : ℕ) * p + (1 : ℕ)) * (2 : ℕ) ^ (0 : ℕ).

                Uses library Nat.log log b n, is the logarithm of natural number n in base b. .

                Lean, line 99
                              have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h

                targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 99 at 841d05f96fd2 ↗

    6. R2b_lemI.hginj have Set.InjOn g (↑T : Set ℕ)

      Leaves T.card + (2 : ℕ) ≤ n, with hginj : Set.InjOn g (↑T : Set ℕ).

      Uses library Set.InjOn f is injective on s if the restriction of f to s is injective. , Set A set is a collection of elements of some type α. .

      Lean, lines 103–187
          have hginj : Set.InjOn g (T : Set ℕ) := by
            -- even / odd collision is impossible
            have hEO : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → g b = g t → False := by
              intro b hb t ht h2b h2t h
              have hb0 := h0 b hb
              have ht0 := h0 t ht
              have hx' := hx b hb t ht h2b h2t
              obtain ⟨c, rfl⟩ := h2b
              simp only [hgdef] at h
              rw [if_pos ⟨c, rfl⟩, if_neg h2t, Nat.mul_div_cancel_left c (by norm_num : 0 < 2)] at h
              by_cases h3 : t = 2 * p + 1
              · rw [if_pos h3] at h
                have hc : Nat.Coprime c t := by
                  have h1 : Nat.Coprime c (2 + c) := by
                    rw [Nat.coprime_add_self_right]
                    rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                    intro hd; omega
                  have : 2 + c = t := by omega
                  rwa [this] at h1
                have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                rw [hg] at hx'
                omega
              · rw [if_neg h3] at h
                by_cases h4 : 2 * (φ t - 1) < n
                · rw [if_pos h4] at h; omega
                · rw [if_neg h4] at h
                  have ht1 := hφ t ht0 (ho t ht h2t)
                  change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
                  have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                    change c + 1 = φ t
                    omega)
                  have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                  have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                  rw [hg] at hx'
                  omega
            intro b hb b' hb' h
            have hb0 := h0 b hb
            have hb0' := h0 b' hb'
            by_cases h2 : 2 ∣ b
            · by_cases h2' : 2 ∣ b'
              · simp only [hgdef] at h
                rw [if_pos h2, if_pos h2'] at h
                obtain ⟨c, rfl⟩ := h2
                obtain ⟨c', rfl⟩ := h2'
                rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
                  Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
                rw [h]
              · exact (hEO b hb b' hb' h2 h2' h).elim
            · by_cases h2' : 2 ∣ b'
              · exact (hEO b' hb' b hb h2' h2 h.symm).elim
              · -- both odd
                have hb1 := hφ b hb0 (ho b hb h2)
                have hb1' := hφ b' hb0' (ho b' hb' h2')
                change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
                have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
                have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
                  intro t ht h2t e
                  have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
                  rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
                  · exact hpT t ht h5
                  · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                    have h7 := Nat.le_of_dvd (by norm_num) h6
                    omega
                have e1 := h2p' b hb h2
                have e2 := h2p' b' hb' h2'
                simp only [hgdef] at h
                rw [if_neg h2, if_neg h2'] at h
                by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
                · rw [h3, h3']
                · rw [if_pos h3, if_neg h3'] at h
                  by_cases h4 : 2 * (φ b' - 1) < n
                  · rw [if_pos h4] at h; omega
                  · rw [if_neg h4] at h; omega
                · rw [if_neg h3, if_pos h3'] at h
                  by_cases h4 : 2 * (φ b - 1) < n
                  · rw [if_pos h4] at h; omega
                  · rw [if_neg h4] at h; omega
                · rw [if_neg h3, if_neg h3'] at h
                  by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
                  · exact hφinj (by omega)
                  · rw [if_pos h4, if_neg h4'] at h; omega
                  · rw [if_neg h4, if_pos h4'] at h; omega
                  · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 103–187 at 841d05f96fd2 ↗

      1. R2b_lemI.hginj.hEO have ∀ b ∈ T, ∀ t ∈ T, (2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ t → g b = g t → False

        Leaves Set.InjOn g (↑T : Set ℕ), with hEO : ∀ b ∈ T, ∀ t ∈ T, (2 : ℕ) ∣ b → ¬(2 : ℕ) ∣ t → g b = g t → False.

        Uses library False False is the empty proposition. , if_pos, Exists.intro Existential introduction. , rfl rfl : a = a is the unique constructor of the equality type. , if_neg, Nat.mul_div_cancel_left.

        Lean, lines 105–138
              have hEO : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → g b = g t → False := by
                intro b hb t ht h2b h2t h
                have hb0 := h0 b hb
                have ht0 := h0 t ht
                have hx' := hx b hb t ht h2b h2t
                obtain ⟨c, rfl⟩ := h2b
                simp only [hgdef] at h
                rw [if_pos ⟨c, rfl⟩, if_neg h2t, Nat.mul_div_cancel_left c (by norm_num : 0 < 2)] at h
                by_cases h3 : t = 2 * p + 1
                · rw [if_pos h3] at h
                  have hc : Nat.Coprime c t := by
                    have h1 : Nat.Coprime c (2 + c) := by
                      rw [Nat.coprime_add_self_right]
                      rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                      intro hd; omega
                    have : 2 + c = t := by omega
                    rwa [this] at h1
                  have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                  have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                  rw [hg] at hx'
                  omega
                · rw [if_neg h3] at h
                  by_cases h4 : 2 * (φ t - 1) < n
                  · rw [if_pos h4] at h; omega
                  · rw [if_neg h4] at h
                    have ht1 := hφ t ht0 (ho t ht h2t)
                    change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
                    have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                      change c + 1 = φ t
                      omega)
                    have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                    have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                    rw [hg] at hx'
                    omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 105–138 at 841d05f96fd2 ↗

        1. R2b_lemI.hginj.hEO.hb0 have (0 : ℕ) < b
        2. R2b_lemI.hginj.hEO.ht0 have (0 : ℕ) < t
        3. R2b_lemI.hginj.hEO.hx' have b < n * b.gcd t

          Leaves False, with hx' : b < n * b.gcd t.

          Lean, line 109
                  have hx' := hx b hb t ht h2b h2t

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 109 at 841d05f96fd2 ↗

        4. R2b_lemI.hginj.hEO.s4 obtain (2 : ℕ) ∣ b

          Leaves False, with c : ℕ, hb : (2 : ℕ) * c ∈ T, h : g ((2 : ℕ) * c) = g t, hb0 : (0 : ℕ) < (2 : ℕ) * c, hx' : (2 : ℕ) * c < n * ((2 : ℕ) * c).gcd t.

          Lean, line 110
                  obtain ⟨c, rfl⟩ := h2b

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 110 at 841d05f96fd2 ↗

        5. R2b_lemI.hginj.hEO.s5 case

          Leaves False.

          Uses library if_pos.

          Lean, lines 114–125
                  · rw [if_pos h3] at h
                    have hc : Nat.Coprime c t := by
                      have h1 : Nat.Coprime c (2 + c) := by
                        rw [Nat.coprime_add_self_right]
                        rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                        intro hd; omega
                      have : 2 + c = t := by omega
                      rwa [this] at h1
                    have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                    have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                    rw [hg] at hx'
                    omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 114–125 at 841d05f96fd2 ↗

          1. R2b_lemI.hginj.hEO.s5.hc have c.Coprime t

            Leaves False, with hc : c.Coprime t.

            Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. .

            Lean, lines 115–121
                      have hc : Nat.Coprime c t := by
                        have h1 : Nat.Coprime c (2 + c) := by
                          rw [Nat.coprime_add_self_right]
                          rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                          intro hd; omega
                        have : 2 + c = t := by omega
                        rwa [this] at h1

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 115–121 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.hEO.s5.hc.h1 have c.Coprime ((2 : ℕ) + c)

              Leaves c.Coprime t, with h1 : c.Coprime ((2 : ℕ) + c).

              Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.coprime_add_self_right, Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd, Nat.prime_two.

              Lean, lines 116–119
                          have h1 : Nat.Coprime c (2 + c) := by
                            rw [Nat.coprime_add_self_right]
                            rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
                            intro hd; omega

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 116–119 at 841d05f96fd2 ↗

            2. R2b_lemI.hginj.hEO.s5.hc.this have (2 : ℕ) + c = t routine: omega

              Leaves c.Coprime t, with this : (2 : ℕ) + c = t.

              Lean, line 120
                          have : 2 + c = t := by omega

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 120 at 841d05f96fd2 ↗

          2. R2b_lemI.hginj.hEO.s5.h2t' have Nat.Coprime (2 : ℕ) t

            Leaves False, with h2t' : Nat.Coprime (2 : ℕ) t.

            Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.Prime.coprime_iff_not_dvd, Nat.prime_two.

            Lean, line 122
                      have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 122 at 841d05f96fd2 ↗

          3. R2b_lemI.hginj.hEO.s5.hg have ((2 : ℕ) * c).gcd t = (1 : ℕ)

            Leaves False, with hg : ((2 : ℕ) * c).gcd t = (1 : ℕ).

            Uses library Nat.Coprime.mul_left.

            Lean, line 123
                      have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 123 at 841d05f96fd2 ↗

        6. R2b_lemI.hginj.hEO.s6 case

          Leaves False.

          Uses library if_neg.

          Lean, lines 126–138
                  · rw [if_neg h3] at h
                    by_cases h4 : 2 * (φ t - 1) < n
                    · rw [if_pos h4] at h; omega
                    · rw [if_neg h4] at h
                      have ht1 := hφ t ht0 (ho t ht h2t)
                      change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
                      have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                        change c + 1 = φ t
                        omega)
                      have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                      have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                      rw [hg] at hx'
                      omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 126–138 at 841d05f96fd2 ↗

          1. R2b_lemI.hginj.hEO.s6.s1 case
          2. R2b_lemI.hginj.hEO.s6.s2 case

            Leaves False.

            Uses library if_neg.

            Lean, lines 129–138
                      · rw [if_neg h4] at h
                        have ht1 := hφ t ht0 (ho t ht h2t)
                        change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
                        have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                          change c + 1 = φ t
                          omega)
                        have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
                        have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
                        rw [hg] at hx'
                        omega

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 129–138 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.hEO.s6.s2.ht1 have t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t))

              Leaves False, with ht1 : t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t)).

              Lean, line 130
                          have ht1 := hφ t ht0 (ho t ht h2t)

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 130 at 841d05f96fd2 ↗

            2. R2b_lemI.hginj.hEO.s6.s2.hc have c.Coprime t

              Leaves False, with hc : c.Coprime t.

              Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.log log b n, is the logarithm of natural number n in base b. .

              Lean, lines 132–134
                          have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
                            change c + 1 = φ t
                            omega)

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 132–134 at 841d05f96fd2 ↗

            3. R2b_lemI.hginj.hEO.s6.s2.h2t' have Nat.Coprime (2 : ℕ) t

              Leaves False, with h2t' : Nat.Coprime (2 : ℕ) t.

              Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.Prime.coprime_iff_not_dvd, Nat.prime_two.

              Lean, line 135
                          have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 135 at 841d05f96fd2 ↗

            4. R2b_lemI.hginj.hEO.s6.s2.hg have ((2 : ℕ) * c).gcd t = (1 : ℕ)

              Leaves False, with hg : ((2 : ℕ) * c).gcd t = (1 : ℕ).

              Uses library Nat.Coprime.mul_left.

              Lean, line 136
                          have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 136 at 841d05f96fd2 ↗

      2. R2b_lemI.hginj.hb0 have (0 : ℕ) < b
      3. R2b_lemI.hginj.hb0' have (0 : ℕ) < b'
      4. R2b_lemI.hginj.s4 case

        Leaves b = b'.

        Lean, lines 143–151
              · by_cases h2' : 2 ∣ b'
                · simp only [hgdef] at h
                  rw [if_pos h2, if_pos h2'] at h
                  obtain ⟨c, rfl⟩ := h2
                  obtain ⟨c', rfl⟩ := h2'
                  rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
                    Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
                  rw [h]
                · exact (hEO b hb b' hb' h2 h2' h).elim

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 143–151 at 841d05f96fd2 ↗

        1. R2b_lemI.hginj.s4.s1 case

          Leaves b = b'.

          Uses library if_pos, Nat.mul_div_cancel_left.

          Lean, lines 144–150
                  · simp only [hgdef] at h
                    rw [if_pos h2, if_pos h2'] at h
                    obtain ⟨c, rfl⟩ := h2
                    obtain ⟨c', rfl⟩ := h2'
                    rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
                      Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
                    rw [h]

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 144–150 at 841d05f96fd2 ↗

          1. R2b_lemI.hginj.s4.s1.s1 obtain (2 : ℕ) ∣ b

            Leaves (2 : ℕ) * c = b', with c : ℕ, hb : (2 : ℕ) * c ∈ (↑T : Set ℕ), hb0 : (0 : ℕ) < (2 : ℕ) * c, h : (2 : ℕ) * c / (2 : ℕ) = b' / (2 : ℕ).

            Lean, line 146
                      obtain ⟨c, rfl⟩ := h2

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 146 at 841d05f96fd2 ↗

          2. R2b_lemI.hginj.s4.s1.s2 obtain (2 : ℕ) ∣ b'

            Leaves (2 : ℕ) * c = (2 : ℕ) * c', with c' : ℕ, hb' : (2 : ℕ) * c' ∈ (↑T : Set ℕ), hb0' : (0 : ℕ) < (2 : ℕ) * c', h : (2 : ℕ) * c / (2 : ℕ) = (2 : ℕ) * c' / (2 : ℕ).

            Lean, line 147
                      obtain ⟨c', rfl⟩ := h2'

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 147 at 841d05f96fd2 ↗

        2. R2b_lemI.hginj.s4.s2 case
      5. R2b_lemI.hginj.s5 case

        Leaves b = b'.

        Lean, lines 152–187
              · by_cases h2' : 2 ∣ b'
                · exact (hEO b' hb' b hb h2' h2 h.symm).elim
                · -- both odd
                  have hb1 := hφ b hb0 (ho b hb h2)
                  have hb1' := hφ b' hb0' (ho b' hb' h2')
                  change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                  change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
                  have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
                  have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
                    intro t ht h2t e
                    have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
                    rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
                    · exact hpT t ht h5
                    · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                      have h7 := Nat.le_of_dvd (by norm_num) h6
                      omega
                  have e1 := h2p' b hb h2
                  have e2 := h2p' b' hb' h2'
                  simp only [hgdef] at h
                  rw [if_neg h2, if_neg h2'] at h
                  by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
                  · rw [h3, h3']
                  · rw [if_pos h3, if_neg h3'] at h
                    by_cases h4 : 2 * (φ b' - 1) < n
                    · rw [if_pos h4] at h; omega
                    · rw [if_neg h4] at h; omega
                  · rw [if_neg h3, if_pos h3'] at h
                    by_cases h4 : 2 * (φ b - 1) < n
                    · rw [if_pos h4] at h; omega
                    · rw [if_neg h4] at h; omega
                  · rw [if_neg h3, if_neg h3'] at h
                    by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
                    · exact hφinj (by omega)
                    · rw [if_pos h4, if_neg h4'] at h; omega
                    · rw [if_neg h4, if_pos h4'] at h; omega
                    · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 152–187 at 841d05f96fd2 ↗

        1. R2b_lemI.hginj.s5.s1 case
        2. R2b_lemI.hginj.s5.s2 case

          Leaves b = b'.

          Uses library if_neg.

          Lean, lines 154–187
                  · -- both odd
                    have hb1 := hφ b hb0 (ho b hb h2)
                    have hb1' := hφ b' hb0' (ho b' hb' h2')
                    change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
                    change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
                    have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
                    have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
                      intro t ht h2t e
                      have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
                      rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
                      · exact hpT t ht h5
                      · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                        have h7 := Nat.le_of_dvd (by norm_num) h6
                        omega
                    have e1 := h2p' b hb h2
                    have e2 := h2p' b' hb' h2'
                    simp only [hgdef] at h
                    rw [if_neg h2, if_neg h2'] at h
                    by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
                    · rw [h3, h3']
                    · rw [if_pos h3, if_neg h3'] at h
                      by_cases h4 : 2 * (φ b' - 1) < n
                      · rw [if_pos h4] at h; omega
                      · rw [if_neg h4] at h; omega
                    · rw [if_neg h3, if_pos h3'] at h
                      by_cases h4 : 2 * (φ b - 1) < n
                      · rw [if_pos h4] at h; omega
                      · rw [if_neg h4] at h; omega
                    · rw [if_neg h3, if_neg h3'] at h
                      by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
                      · exact hφinj (by omega)
                      · rw [if_pos h4, if_neg h4'] at h; omega
                      · rw [if_neg h4, if_pos h4'] at h; omega
                      · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 154–187 at 841d05f96fd2 ↗

          1. R2b_lemI.hginj.s5.s2.hb1 have b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b))

            Leaves b = b', with hb1 : b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b) ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b)).

            Lean, line 155
                      have hb1 := hφ b hb0 (ho b hb h2)

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 155 at 841d05f96fd2 ↗

          2. R2b_lemI.hginj.s5.s2.hb1' have b' * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b') ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b' * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b'))

            Leaves b = b', with hb1' : b' * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b') ≤ n - (1 : ℕ) ∧ n - (1 : ℕ) < (2 : ℕ) * (b' * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / b')).

            Lean, line 156
                      have hb1' := hφ b' hb0' (ho b' hb' h2')

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 156 at 841d05f96fd2 ↗

          3. R2b_lemI.hginj.s5.s2.h_x3c6inj (hφinj) have φ b = φ b' → b = b'

            Leaves b = b', with hφinj : φ b = φ b' → b = b'.

            Lean, line 159
                      have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 159 at 841d05f96fd2 ↗

          4. R2b_lemI.hginj.s5.s2.h2p' have ∀ t ∈ T, ¬(2 : ℕ) ∣ t → φ t ≠ (2 : ℕ) * p

            Leaves b = b', with h2p' : ∀ t ∈ T, ¬(2 : ℕ) ∣ t → φ t ≠ (2 : ℕ) * p.

            Uses library Nat.Prime.dvd_mul.

            Lean, lines 160–167
                      have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
                        intro t ht h2t e
                        have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
                        rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
                        · exact hpT t ht h5
                        · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                          have h7 := Nat.le_of_dvd (by norm_num) h6
                          omega

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 160–167 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.s5.s2.h2p'.hd have p ∣ t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t)

              Leaves False, with hd : p ∣ t * (2 : ℕ) ^ Nat.log (2 : ℕ) ((n - (1 : ℕ)) / t).

              Uses library Nat.log log b n, is the logarithm of natural number n in base b. , Exists.intro Existential introduction. .

              Lean, line 162
                          have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 162 at 841d05f96fd2 ↗

            2. R2b_lemI.hginj.s5.s2.h2p'.s2 case
            3. R2b_lemI.hginj.s5.s2.h2p'.s3 case

              Leaves False.

              Lean, lines 165–167
                          · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
                            have h7 := Nat.le_of_dvd (by norm_num) h6
                            omega

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 165–167 at 841d05f96fd2 ↗

              1. R2b_lemI.hginj.s5.s2.h2p'.s3.h6 have p ∣ (2 : ℕ)

                Leaves False, with h6 : p ∣ (2 : ℕ).

                Uses library Nat.Prime.dvd_of_dvd_pow.

                Lean, line 165
                            · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5

                targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 165 at 841d05f96fd2 ↗

              2. R2b_lemI.hginj.s5.s2.h2p'.s3.h7 have p ≤ (2 : ℕ)

                Leaves False, with h7 : p ≤ (2 : ℕ).

                Uses library Nat.le_of_dvd.

                Lean, line 166
                              have h7 := Nat.le_of_dvd (by norm_num) h6

                targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 166 at 841d05f96fd2 ↗

          5. R2b_lemI.hginj.s5.s2.e1 have φ b ≠ (2 : ℕ) * p

            Leaves b = b', with e1 : φ b ≠ (2 : ℕ) * p.

            Lean, line 168
                      have e1 := h2p' b hb h2

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 168 at 841d05f96fd2 ↗

          6. R2b_lemI.hginj.s5.s2.e2 have φ b' ≠ (2 : ℕ) * p

            Leaves b = b', with e2 : φ b' ≠ (2 : ℕ) * p.

            Lean, line 169
                      have e2 := h2p' b' hb' h2'

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 169 at 841d05f96fd2 ↗

          7. R2b_lemI.hginj.s5.s2.s7 case
          8. R2b_lemI.hginj.s5.s2.s8 case

            Leaves b = b'.

            Uses library if_pos, if_neg.

            Lean, lines 174–177
                      · rw [if_pos h3, if_neg h3'] at h
                        by_cases h4 : 2 * (φ b' - 1) < n
                        · rw [if_pos h4] at h; omega
                        · rw [if_neg h4] at h; omega

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 174–177 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.s5.s2.s8.s1 case
            2. R2b_lemI.hginj.s5.s2.s8.s2 case
          9. R2b_lemI.hginj.s5.s2.s9 case

            Leaves b = b'.

            Uses library if_neg, if_pos.

            Lean, lines 178–181
                      · rw [if_neg h3, if_pos h3'] at h
                        by_cases h4 : 2 * (φ b - 1) < n
                        · rw [if_pos h4] at h; omega
                        · rw [if_neg h4] at h; omega

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 178–181 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.s5.s2.s9.s1 case
            2. R2b_lemI.hginj.s5.s2.s9.s2 case
          10. R2b_lemI.hginj.s5.s2.s10 case

            Leaves b = b'.

            Uses library if_neg.

            Lean, lines 182–187
                      · rw [if_neg h3, if_neg h3'] at h
                        by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
                        · exact hφinj (by omega)
                        · rw [if_pos h4, if_neg h4'] at h; omega
                        · rw [if_neg h4, if_pos h4'] at h; omega
                        · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 182–187 at 841d05f96fd2 ↗

            1. R2b_lemI.hginj.s5.s2.s10.s1 case
            2. R2b_lemI.hginj.s5.s2.s10.s2 case

              Leaves b = b'.

              Uses library if_pos, if_neg.

              Lean, line 185
                          · rw [if_pos h4, if_neg h4'] at h; omega

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 185 at 841d05f96fd2 ↗

            3. R2b_lemI.hginj.s5.s2.s10.s3 case

              Leaves b = b'.

              Uses library if_neg, if_pos.

              Lean, line 186
                          · rw [if_neg h4, if_pos h4'] at h; omega

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 186 at 841d05f96fd2 ↗

            4. R2b_lemI.hginj.s5.s2.s10.s4 case

              Leaves b = b'.

              Uses library if_neg.

              Lean, line 187
                          · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)

              targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 187 at 841d05f96fd2 ↗

    7. R2b_lemI.hcard have (insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p))).card = n - (2 : ℕ)

      Leaves T.card + (2 : ℕ) ≤ n, with hcard : (insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p))).card = n - (2 : ℕ).

      Uses library Insert.insert insert x xs inserts the element x into the collection xs. , Finset.Ioo The finset $(a, b)$ of elements x such that a < x and x < b. , Finset.card_insert_of_notMem, Finset.card_erase_of_mem $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. , Nat.card_Ioo.

      Lean, lines 188–193
          have hcard : (insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p))).card = n - 2 := by
            rw [Finset.card_insert_of_notMem (by simp), Finset.card_erase_of_mem, Finset.card_erase_of_mem,
              Nat.card_Ioo]
            · omega
            · rw [Finset.mem_Ioo]; omega
            · rw [Finset.mem_erase, Finset.mem_Ioo]; omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 188–193 at 841d05f96fd2 ↗

      1. R2b_lemI.hcard.s1 case routine: omega

        Leaves n - (0 : ℕ) - (1 : ℕ) - (1 : ℕ) - (1 : ℕ) + (1 : ℕ) = n - (2 : ℕ).

        Lean, line 191
              · omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 191 at 841d05f96fd2 ↗

      2. R2b_lemI.hcard.s2 case

        Leaves p ∈ Finset.Ioo (0 : ℕ) n.

        Uses library Finset.mem_Ioo.

        Lean, line 192
              · rw [Finset.mem_Ioo]; omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 192 at 841d05f96fd2 ↗

      3. R2b_lemI.hcard.s3 case

        Leaves (2 : ℕ) * p ∈ (Finset.Ioo (0 : ℕ) n).erase p.

        Uses library Finset.mem_erase, Finset.mem_Ioo.

        Lean, line 193
              · rw [Finset.mem_erase, Finset.mem_Ioo]; omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 193 at 841d05f96fd2 ↗

    8. R2b_lemI.hle have T.card ≤ (insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p))).card

      Leaves T.card + (2 : ℕ) ≤ n, with hle : T.card ≤ (insert (0 : ℕ) (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p))).card.

      Uses library Finset.card_le_card_of_injOn.

      Lean, line 194
          have hle := Finset.card_le_card_of_injOn g hmaps hginj

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 194 at 841d05f96fd2 ↗

  3. R2b_K2half have ∀ (n p : ℕ) (X S : Finset ℕ), (0 : ℕ) < p → (2 : ℕ) * p < n → (9 : ℕ) ≤ n → (∀ x ∈ X, ∀ s ∈ S, ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)) → X.Nonempty → S.Nonempty → n ≤ X.card + S.card → X.card ≤ S.card → ∀ x ∈ X, x = (1 : ℕ)

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_K2half : ∀ (n p : ℕ) (X S : Finset ℕ), (0 : ℕ) < p → (2 : ℕ) * p < n → (9 : ℕ) ≤ n → (∀ x ∈ X, ∀ s ∈ S, ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)) → X.Nonempty → S.Nonempty → n ≤ X.card + S.card → X.card ≤ S.card → ∀ x ∈ X, x = (1 : ℕ).

    Uses library Finset Finset α is the type of finite sets of elements of α. , Nat.lt_or_ge.

    Lean, lines 197–275
      have R2b_K2half : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card) (hle : X.card ≤ S.card),
          ∀ x ∈ X, x = 1 := by
        intro n p X S hp0 h2p h9 hxs hX hS hcard hle
        have big : ∀ Y : Finset ℕ, (∀ x ∈ Y, 0 < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x := by
          intro Y hpos hY
          by_contra h
          push Not at h
          have hsub : Y ⊆ Finset.Ioo 0 Y.card := by
            intro x hx
            exact Finset.mem_Ioo.mpr ⟨hpos x hx, h x hx⟩
          have h1 := Finset.card_le_card hsub
          rw [Nat.card_Ioo] at h1
          have h2 := hY.card_pos
          omega
        have hXpos : ∀ x ∈ X, 0 < x := by
          intro x hx
          obtain ⟨s, hs⟩ := hS
          obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
          apply Nat.pos_of_ne_zero
          rintro rfl
          rw [Nat.zero_mul] at h
          omega
        have hSpos : ∀ s ∈ S, 0 < s := by
          intro s hs
          obtain ⟨x, hx⟩ := hX
          obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
          apply Nat.pos_of_ne_zero
          rintro rfl
          rw [Nat.mul_zero] at h
          omega
        have hmul : ∀ u v : ℕ, 4 ≤ u → 5 ≤ v → 2 * u + 2 * v ≤ u * v := by
          intro u v hu hv
          obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hu
          obtain ⟨b, rfl⟩ := Nat.exists_eq_add_of_le hv
          nlinarith [Nat.zero_le (a * b)]
        obtain ⟨x0, hx0, hx0c⟩ := big X hXpos hX
        obtain ⟨s0, hs0, hs0c⟩ := big S hSpos hS
        have huv : X.card * S.card < 2 * n := by
          obtain ⟨y, -, hyn, -, h⟩ := hxs x0 hx0 s0 hs0
          have h2 : X.card * S.card ≤ x0 * s0 := Nat.mul_le_mul hx0c hs0c
          omega
        have hu2 : X.card ≤ 2 := by
          by_contra h
          push Not at h
          rcases Nat.lt_or_ge X.card 4 with h4 | h4
          · have h3 : X.card = 3 := by omega
            rw [h3] at huv hcard
            omega
          · have := hmul X.card S.card h4 (by omega)
            omega
        intro x hx
        by_contra hx1
        have hxpos := hXpos x hx
        rcases Nat.lt_or_ge x 3 with h3 | h3
        · have hx2 : x = 2 := by omega
          subst hx2
          have hsub : S ⊆ ((Finset.Ioo 0 n).erase p).erase (2 * p) := by
            intro s hs
            obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs
            have hsy : s = y := by omega
            subst hsy
            rw [Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
            refine ⟨?_, ?_, hy0, hyn⟩
            · rintro rfl; exact hpy ⟨2, by ring⟩
            · rintro rfl; exact hpy ⟨1, by ring⟩
          have h1 := Finset.card_le_card hsub
          rw [Finset.card_erase_of_mem (by
              rw [Finset.mem_erase, Finset.mem_Ioo]; omega),
            Finset.card_erase_of_mem (by rw [Finset.mem_Ioo]; omega), Nat.card_Ioo] at h1
          omega
        · have hsub : S ⊆ Finset.Icc 1 (2 * (n - 1) / 3) := by
            intro s hs
            obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs
            have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3
            rw [Finset.mem_Icc]
            exact ⟨hSpos s hs, by omega⟩
          have h1 := Finset.card_le_card hsub
          rw [Nat.card_Icc] at h1
          omega

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 197–275 at 841d05f96fd2 ↗

    1. R2b_K2half.big have ∀ (Y : Finset ℕ), (∀ x ∈ Y, (0 : ℕ) < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x

      Leaves ∀ x ∈ X, x = (1 : ℕ), with big : ∀ (Y : Finset ℕ), (∀ x ∈ Y, (0 : ℕ) < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x.

      Uses library Finset Finset α is the type of finite sets of elements of α. , Not Not p, or ¬p, is the negation of p. , Nat.card_Ioo.

      Lean, lines 200–210
          have big : ∀ Y : Finset ℕ, (∀ x ∈ Y, 0 < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x := by
            intro Y hpos hY
            by_contra h
            push Not at h
            have hsub : Y ⊆ Finset.Ioo 0 Y.card := by
              intro x hx
              exact Finset.mem_Ioo.mpr ⟨hpos x hx, h x hx⟩
            have h1 := Finset.card_le_card hsub
            rw [Nat.card_Ioo] at h1
            have h2 := hY.card_pos
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 200–210 at 841d05f96fd2 ↗

      1. R2b_K2half.big.hsub have Y ⊆ Finset.Ioo (0 : ℕ) Y.card

        Leaves False, with hsub : Y ⊆ Finset.Ioo (0 : ℕ) Y.card.

        Uses library Finset.Ioo The finset $(a, b)$ of elements x such that a < x and x < b. , Finset.mem_Ioo, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 204–206
              have hsub : Y ⊆ Finset.Ioo 0 Y.card := by
                intro x hx
                exact Finset.mem_Ioo.mpr ⟨hpos x hx, h x hx⟩

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 204–206 at 841d05f96fd2 ↗

      2. R2b_K2half.big.h1 have Y.card ≤ (Finset.Ioo (0 : ℕ) Y.card).card

        Leaves False, with h1 : Y.card ≤ (Finset.Ioo (0 : ℕ) Y.card).card.

        Uses library Finset.card_le_card.

        Lean, line 207
              have h1 := Finset.card_le_card hsub

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 207 at 841d05f96fd2 ↗

      3. R2b_K2half.big.h2 have (0 : ℕ) < Y.card
    2. R2b_K2half.hXpos have ∀ x ∈ X, (0 : ℕ) < x

      Leaves ∀ x ∈ X, x = (1 : ℕ), with hXpos : ∀ x ∈ X, (0 : ℕ) < x.

      Uses library Nat.pos_of_ne_zero, Nat.zero_mul.

      Lean, lines 211–218
          have hXpos : ∀ x ∈ X, 0 < x := by
            intro x hx
            obtain ⟨s, hs⟩ := hS
            obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
            apply Nat.pos_of_ne_zero
            rintro rfl
            rw [Nat.zero_mul] at h
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 211–218 at 841d05f96fd2 ↗

      1. R2b_K2half.hXpos.s1 obtain S.Nonempty

        Leaves (0 : ℕ) < x, with s : ℕ, hs : s ∈ S.

        Lean, line 213
              obtain ⟨s, hs⟩ := hS

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 213 at 841d05f96fd2 ↗

      2. R2b_K2half.hXpos.s2 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)

        Leaves (0 : ℕ) < x, with y : ℕ, hy0 : (0 : ℕ) < y, h : x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y.

        Lean, line 214
              obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 214 at 841d05f96fd2 ↗

    3. R2b_K2half.hSpos have ∀ s ∈ S, (0 : ℕ) < s

      Leaves ∀ x ∈ X, x = (1 : ℕ), with hSpos : ∀ s ∈ S, (0 : ℕ) < s.

      Uses library Nat.pos_of_ne_zero, Nat.mul_zero.

      Lean, lines 219–226
          have hSpos : ∀ s ∈ S, 0 < s := by
            intro s hs
            obtain ⟨x, hx⟩ := hX
            obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
            apply Nat.pos_of_ne_zero
            rintro rfl
            rw [Nat.mul_zero] at h
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 219–226 at 841d05f96fd2 ↗

      1. R2b_K2half.hSpos.s1 obtain X.Nonempty

        Leaves (0 : ℕ) < s, with x : ℕ, hx : x ∈ X.

        Lean, line 221
              obtain ⟨x, hx⟩ := hX

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 221 at 841d05f96fd2 ↗

      2. R2b_K2half.hSpos.s2 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)

        Leaves (0 : ℕ) < s, with y : ℕ, hy0 : (0 : ℕ) < y, h : x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y.

        Lean, line 222
              obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 222 at 841d05f96fd2 ↗

    4. R2b_K2half.hmul have ∀ (u v : ℕ), (4 : ℕ) ≤ u → (5 : ℕ) ≤ v → (2 : ℕ) * u + (2 : ℕ) * v ≤ u * v

      Leaves ∀ x ∈ X, x = (1 : ℕ), with hmul : ∀ (u v : ℕ), (4 : ℕ) ≤ u → (5 : ℕ) ≤ v → (2 : ℕ) * u + (2 : ℕ) * v ≤ u * v.

      Uses library Nat.zero_le.

      Lean, lines 227–231
          have hmul : ∀ u v : ℕ, 4 ≤ u → 5 ≤ v → 2 * u + 2 * v ≤ u * v := by
            intro u v hu hv
            obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hu
            obtain ⟨b, rfl⟩ := Nat.exists_eq_add_of_le hv
            nlinarith [Nat.zero_le (a * b)]

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 227–231 at 841d05f96fd2 ↗

      1. R2b_K2half.hmul.s1 obtain ∃ (k : ℕ), u = (4 : ℕ) + k

        Leaves (2 : ℕ) * ((4 : ℕ) + a) + (2 : ℕ) * v ≤ ((4 : ℕ) + a) * v, with a : ℕ, hu : (4 : ℕ) ≤ (4 : ℕ) + a.

        Uses library Nat.exists_eq_add_of_le.

        Lean, line 229
              obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hu

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 229 at 841d05f96fd2 ↗

      2. R2b_K2half.hmul.s2 obtain ∃ (k : ℕ), v = (5 : ℕ) + k

        Leaves (2 : ℕ) * ((4 : ℕ) + a) + (2 : ℕ) * ((5 : ℕ) + b) ≤ ((4 : ℕ) + a) * ((5 : ℕ) + b), with b : ℕ, hv : (5 : ℕ) ≤ (5 : ℕ) + b.

        Uses library Nat.exists_eq_add_of_le.

        Lean, line 230
              obtain ⟨b, rfl⟩ := Nat.exists_eq_add_of_le hv

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 230 at 841d05f96fd2 ↗

    5. R2b_K2half.s5 obtain ∃ x ∈ X, X.card ≤ x

      Leaves ∀ x ∈ X, x = (1 : ℕ), with x0 : ℕ, hx0 : x0 ∈ X, hx0c : X.card ≤ x0.

      Lean, line 232
          obtain ⟨x0, hx0, hx0c⟩ := big X hXpos hX

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 232 at 841d05f96fd2 ↗

    6. R2b_K2half.s6 obtain ∃ x ∈ S, S.card ≤ x

      Leaves ∀ x ∈ X, x = (1 : ℕ), with s0 : ℕ, hs0 : s0 ∈ S, hs0c : S.card ≤ s0.

      Lean, line 233
          obtain ⟨s0, hs0, hs0c⟩ := big S hSpos hS

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 233 at 841d05f96fd2 ↗

    7. R2b_K2half.huv have X.card * S.card < (2 : ℕ) * n

      Leaves ∀ x ∈ X, x = (1 : ℕ), with huv : X.card * S.card < (2 : ℕ) * n.

      Lean, lines 234–237
          have huv : X.card * S.card < 2 * n := by
            obtain ⟨y, -, hyn, -, h⟩ := hxs x0 hx0 s0 hs0
            have h2 : X.card * S.card ≤ x0 * s0 := Nat.mul_le_mul hx0c hs0c
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 234–237 at 841d05f96fd2 ↗

      1. R2b_K2half.huv.s1 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x0 * s0 = (2 : ℕ) * y ∨ x0 * s0 = y ∧ ¬(2 : ℕ) ∣ y)

        Leaves X.card * S.card < (2 : ℕ) * n, with y : ℕ, hyn : y < n, h : x0 * s0 = (2 : ℕ) * y ∨ x0 * s0 = y ∧ ¬(2 : ℕ) ∣ y.

        Lean, line 235
              obtain ⟨y, -, hyn, -, h⟩ := hxs x0 hx0 s0 hs0

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 235 at 841d05f96fd2 ↗

      2. R2b_K2half.huv.h2 have X.card * S.card ≤ x0 * s0

        Leaves X.card * S.card < (2 : ℕ) * n, with h2 : X.card * S.card ≤ x0 * s0.

        Uses library Nat.mul_le_mul.

        Lean, line 236
              have h2 : X.card * S.card ≤ x0 * s0 := Nat.mul_le_mul hx0c hs0c

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 236 at 841d05f96fd2 ↗

    8. R2b_K2half.hu2 have X.card ≤ (2 : ℕ)

      Leaves ∀ x ∈ X, x = (1 : ℕ), with hu2 : X.card ≤ (2 : ℕ).

      Uses library Not Not p, or ¬p, is the negation of p. , Nat.lt_or_ge.

      Lean, lines 238–246
          have hu2 : X.card ≤ 2 := by
            by_contra h
            push Not at h
            rcases Nat.lt_or_ge X.card 4 with h4 | h4
            · have h3 : X.card = 3 := by omega
              rw [h3] at huv hcard
              omega
            · have := hmul X.card S.card h4 (by omega)
              omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 238–246 at 841d05f96fd2 ↗

      1. R2b_K2half.hu2.s1 case

        Leaves False.

        Lean, lines 242–244
              · have h3 : X.card = 3 := by omega
                rw [h3] at huv hcard
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 242–244 at 841d05f96fd2 ↗

        1. R2b_K2half.hu2.s1.h3 have X.card = (3 : ℕ) routine: omega

          Leaves False, with h3 : X.card = (3 : ℕ).

          Lean, line 242
                · have h3 : X.card = 3 := by omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 242 at 841d05f96fd2 ↗

      2. R2b_K2half.hu2.s2 case

        Leaves False.

        Lean, lines 245–246
              · have := hmul X.card S.card h4 (by omega)
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 245–246 at 841d05f96fd2 ↗

        1. R2b_K2half.hu2.s2.this have (2 : ℕ) * X.card + (2 : ℕ) * S.card ≤ X.card * S.card

          Leaves False, with this : (2 : ℕ) * X.card + (2 : ℕ) * S.card ≤ X.card * S.card.

          Lean, line 245
                · have := hmul X.card S.card h4 (by omega)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 245 at 841d05f96fd2 ↗

    9. R2b_K2half.hxpos have (0 : ℕ) < x
    10. R2b_K2half.s10 case

      Leaves False.

      Uses library Finset.card_erase_of_mem $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. , Finset.mem_erase, Finset.mem_Ioo, Nat.card_Ioo.

      Lean, lines 251–266
          · have hx2 : x = 2 := by omega
            subst hx2
            have hsub : S ⊆ ((Finset.Ioo 0 n).erase p).erase (2 * p) := by
              intro s hs
              obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs
              have hsy : s = y := by omega
              subst hsy
              rw [Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
              refine ⟨?_, ?_, hy0, hyn⟩
              · rintro rfl; exact hpy ⟨2, by ring⟩
              · rintro rfl; exact hpy ⟨1, by ring⟩
            have h1 := Finset.card_le_card hsub
            rw [Finset.card_erase_of_mem (by
                rw [Finset.mem_erase, Finset.mem_Ioo]; omega),
              Finset.card_erase_of_mem (by rw [Finset.mem_Ioo]; omega), Nat.card_Ioo] at h1
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 251–266 at 841d05f96fd2 ↗

      1. R2b_K2half.s10.hx2 have x = (2 : ℕ) routine: omega
      2. R2b_K2half.s10.hsub have S ⊆ ((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)

        Leaves False, with hsub : S ⊆ ((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p).

        Uses library Finset.Ioo The finset $(a, b)$ of elements x such that a < x and x < b. , Finset.mem_erase, Finset.mem_Ioo, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 253–261
              have hsub : S ⊆ ((Finset.Ioo 0 n).erase p).erase (2 * p) := by
                intro s hs
                obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs
                have hsy : s = y := by omega
                subst hsy
                rw [Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
                refine ⟨?_, ?_, hy0, hyn⟩
                · rintro rfl; exact hpy ⟨2, by ring⟩
                · rintro rfl; exact hpy ⟨1, by ring⟩

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 253–261 at 841d05f96fd2 ↗

        1. R2b_K2half.s10.hsub.s1 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ ((2 : ℕ) * s = (2 : ℕ) * y ∨ (2 : ℕ) * s = y ∧ ¬(2 : ℕ) ∣ y)

          Leaves s ∈ ((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p), with y : ℕ, hy0 : (0 : ℕ) < y, hyn : y < n, hpy : ¬p ∣ y, h : (2 : ℕ) * s = (2 : ℕ) * y ∨ (2 : ℕ) * s = y ∧ ¬(2 : ℕ) ∣ y.

          Lean, line 255
                  obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 255 at 841d05f96fd2 ↗

        2. R2b_K2half.s10.hsub.hsy have s = y routine: omega

          Leaves s ∈ ((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p), with hsy : s = y.

          Lean, line 256
                  have hsy : s = y := by omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 256 at 841d05f96fd2 ↗

        3. R2b_K2half.s10.hsub.s3 case

          Leaves s ≠ (2 : ℕ) * p.

          Uses library Exists.intro Existential introduction. .

          Lean, line 260
                  · rintro rfl; exact hpy ⟨2, by ring⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 260 at 841d05f96fd2 ↗

        4. R2b_K2half.s10.hsub.s4 case

          Leaves s ≠ p.

          Uses library Exists.intro Existential introduction. .

          Lean, line 261
                  · rintro rfl; exact hpy ⟨1, by ring⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 261 at 841d05f96fd2 ↗

      3. R2b_K2half.s10.h1 have S.card ≤ (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)).card

        Leaves False, with h1 : S.card ≤ (((Finset.Ioo (0 : ℕ) n).erase p).erase ((2 : ℕ) * p)).card.

        Uses library Finset.card_le_card.

        Lean, line 262
              have h1 := Finset.card_le_card hsub

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 262 at 841d05f96fd2 ↗

    11. R2b_K2half.s11 case

      Leaves False.

      Uses library Nat.card_Icc.

      Lean, lines 267–275
          · have hsub : S ⊆ Finset.Icc 1 (2 * (n - 1) / 3) := by
              intro s hs
              obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs
              have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3
              rw [Finset.mem_Icc]
              exact ⟨hSpos s hs, by omega⟩
            have h1 := Finset.card_le_card hsub
            rw [Nat.card_Icc] at h1
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 267–275 at 841d05f96fd2 ↗

      1. R2b_K2half.s11.hsub have S ⊆ Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ))

        Leaves False, with hsub : S ⊆ Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ)).

        Uses library Finset.Icc The finset $[a, b]$ of elements x such that a ≤ x and x ≤ b. , Finset.mem_Icc, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 267–272
            · have hsub : S ⊆ Finset.Icc 1 (2 * (n - 1) / 3) := by
                intro s hs
                obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs
                have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3
                rw [Finset.mem_Icc]
                exact ⟨hSpos s hs, by omega⟩

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 267–272 at 841d05f96fd2 ↗

        1. R2b_K2half.s11.hsub.s1 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)

          Leaves s ∈ Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ)), with y : ℕ, hy0 : (0 : ℕ) < y, hyn : y < n, hpy : ¬p ∣ y, h : x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y.

          Lean, line 269
                  obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 269 at 841d05f96fd2 ↗

        2. R2b_K2half.s11.hsub.h4 have (3 : ℕ) * s ≤ x * s

          Leaves s ∈ Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ)), with h4 : (3 : ℕ) * s ≤ x * s.

          Uses library Nat.mul_le_mul_right.

          Lean, line 270
                  have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 270 at 841d05f96fd2 ↗

      2. R2b_K2half.s11.h1 have S.card ≤ (Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ))).card

        Leaves False, with h1 : S.card ≤ (Finset.Icc (1 : ℕ) ((2 : ℕ) * (n - (1 : ℕ)) / (3 : ℕ))).card.

        Uses library Finset.card_le_card.

        Lean, line 273
              have h1 := Finset.card_le_card hsub

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 273 at 841d05f96fd2 ↗

  4. R2b_K2 have ∀ (n p : ℕ) (X S : Finset ℕ), (0 : ℕ) < p → (2 : ℕ) * p < n → (9 : ℕ) ≤ n → (∀ x ∈ X, ∀ s ∈ S, ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)) → X.Nonempty → S.Nonempty → n ≤ X.card + S.card → (∀ x ∈ X, x = (1 : ℕ)) ∨ ∀ s ∈ S, s = (1 : ℕ)

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_K2 : ∀ (n p : ℕ) (X S : Finset ℕ), (0 : ℕ) < p → (2 : ℕ) * p < n → (9 : ℕ) ≤ n → (∀ x ∈ X, ∀ s ∈ S, ∃ (y : ℕ), (0 : ℕ) < y ∧ y < n ∧ ¬p ∣ y ∧ (x * s = (2 : ℕ) * y ∨ x * s = y ∧ ¬(2 : ℕ) ∣ y)) → X.Nonempty → S.Nonempty → n ≤ X.card + S.card → (∀ x ∈ X, x = (1 : ℕ)) ∨ ∀ s ∈ S, s = (1 : ℕ).

    Uses library Finset Finset α is the type of finite sets of elements of α. , le_total.

    Lean, lines 276–284
      have R2b_K2 : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card),
          (∀ x ∈ X, x = 1) ∨ (∀ s ∈ S, s = 1) := by
        intro n p X S hp0 h2p h9 hxs hX hS hcard
        rcases le_total X.card S.card with h | h
        · exact Or.inl (R2b_K2half n p X S hp0 h2p h9 hxs hX hS hcard h)
        · refine Or.inr (R2b_K2half n p S X hp0 h2p h9 ?_ hS hX (by omega) h)
          intro s hs x hx
          rw [Nat.mul_comm]
          exact hxs x hx s hs

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 276–284 at 841d05f96fd2 ↗

    1. R2b_K2.s1 case

      Leaves (∀ x ∈ X, x = (1 : ℕ)) ∨ ∀ s ∈ S, s = (1 : ℕ).

      Uses library Or.inl Or.inl is "left injection" into an Or. .

      Lean, line 280
          · exact Or.inl (R2b_K2half n p X S hp0 h2p h9 hxs hX hS hcard h)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 280 at 841d05f96fd2 ↗

    2. R2b_K2.s2 case

      Leaves (∀ x ∈ X, x = (1 : ℕ)) ∨ ∀ s ∈ S, s = (1 : ℕ).

      Uses library Or.inr Or.inr is "right injection" into an Or. , Nat.mul_comm.

      Lean, lines 281–284
          · refine Or.inr (R2b_K2half n p S X hp0 h2p h9 ?_ hS hX (by omega) h)
            intro s hs x hx
            rw [Nat.mul_comm]
            exact hxs x hx s hs

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 281–284 at 841d05f96fd2 ↗

  5. R2b_block have ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.gcd id = (1 : ℕ) → (∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) → ∀ (p : ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < B.card → B.card ≤ (3 : ℕ) * p → (9 : ℕ) ≤ B.card → (∃ a ∈ B, p ∣ a) → ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_block : ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.gcd id = (1 : ℕ) → (∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) → ∀ (p : ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < B.card → B.card ≤ (3 : ℕ) * p → (9 : ℕ) ≤ B.card → (∃ a ∈ B, p ∣ a) → ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g.

    Uses library Finset Finset α is the type of finite sets of elements of α. , id The identity function. .

    Lean, lines 285–514
      have R2b_block : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card) (hex : ∃ a ∈ B, p ∣ a),
          ∃ g ∈ B, ¬ p ∣ g ∧ (∀ b ∈ B, ¬ p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ 2 * p * g := by
        intro B h0 hgcd hlt p hp hp3 h2p hn3 h9 hex
        obtain ⟨a0, ha0, hpa0⟩ := hex
        have hexb : ∃ b ∈ B, ¬ p ∣ b := by
          by_contra h
          push Not at h
          have h1 : p ∣ B.gcd id := Finset.dvd_gcd (fun b hb => h b hb)
          rw [hgcd] at h1
          exact hp.one_lt.ne' (Nat.dvd_one.mp h1)
        obtain ⟨b0, hb0, hpb0⟩ := hexb
        have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
        -- the pair analysis: a = g·x, b = g·y, x ∈ {p, 2p}
        have hA : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b → ∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
            b = a.gcd b * y ∧ (a = p * a.gcd b ∨ (a = 2 * p * a.gcd b ∧ ¬ 2 ∣ y)) := by
          intro a ha hpa b hb hpb
          have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (hpos a ha)
          obtain ⟨x, hx⟩ := Nat.gcd_dvd_left a b
          obtain ⟨y, hy⟩ := Nat.gcd_dvd_right a b
          have hpg : ¬ p ∣ a.gcd b := fun h => hpb (h.trans (Nat.gcd_dvd_right a b))
          have hpx : p ∣ x := by
            have h1 : p ∣ a.gcd b * x := hx ▸ hpa
            exact (hp.dvd_mul.mp h1).resolve_left hpg
          obtain ⟨t, ht⟩ := hpx
          have hxn : x < B.card := by
            have h3 : a.gcd b * x < a.gcd b * B.card := by
              rw [← hx, Nat.mul_comm]; exact hlt a ha b hb
            exact Nat.lt_of_mul_lt_mul_left h3
          have hyn : y < B.card := by
            have h3 : a.gcd b * y < a.gcd b * B.card := by
              rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha
            exact Nat.lt_of_mul_lt_mul_left h3
          have hx0 : x ≠ 0 := by
            rintro rfl
            rw [Nat.mul_zero] at hx
            exact (hpos a ha).ne' hx
          have hy0 : y ≠ 0 := by
            rintro rfl
            rw [Nat.mul_zero] at hy
            exact (hpos b hb).ne' hy
          have hpy : ¬ p ∣ y := fun h => hpb (hy ▸ Dvd.dvd.mul_left h _)
          have hcop : Nat.Coprime x y := by
            have h1 := Nat.coprime_div_gcd_div_gcd hg0
            have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx
            have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy
            rwa [e1, e2] at h1
          have ht0 : t ≠ 0 := by
            rintro rfl
            rw [Nat.mul_zero] at ht
            exact hx0 ht
          have ht3 : t < 3 := by
            by_contra h
            push Not at h
            have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h
            omega
          refine ⟨y, Nat.pos_of_ne_zero hy0, hyn, hpy, hy, ?_⟩
          rcases (by omega : t = 1 ∨ t = 2) with rfl | rfl
          · left
            calc a = a.gcd b * x := hx
              _ = p * a.gcd b := by rw [ht]; ring
          · right
            refine ⟨(calc a = a.gcd b * x := hx
              _ = 2 * p * a.gcd b := by rw [ht]; ring), ?_⟩
            intro h2y
            have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩
            have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y
            omega
        have hG0 : (B.filter (fun b => ¬ p ∣ b)).gcd id ≠ 0 := by
          intro h
          have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ id b0 :=
            Finset.gcd_dvd (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)
          rw [h] at h1
          exact hpb0 (by rw [show b0 = 0 from Nat.eq_zero_of_zero_dvd h1]; exact dvd_zero p)
        have hGb : ∀ b ∈ B, ¬ p ∣ b → (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ b := by
          intro b hb hpb
          exact Finset.gcd_dvd (f := id) (Finset.mem_filter.mpr ⟨hb, hpb⟩)
        have hdiv : ∀ a ∈ B, p ∣ a → a ∣ 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
          intro a ha hpa
          have h1 : a ∣ (B.filter (fun b => ¬ p ∣ b)).gcd (fun b => (2 * p) * id b) := by
            apply Finset.dvd_gcd
            intro b hb
            obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
            obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb
            have h2 : a ∣ 2 * p * a.gcd b := by
              rcases h with h | ⟨h, -⟩
              · exact ⟨2, by linarith⟩
              · exact ⟨1, by linarith⟩
            exact h2.trans (Nat.mul_dvd_mul_left _ (Nat.gcd_dvd_right a b))
          rw [Finset.gcd_mul_left] at h1
          simpa using h1
        have hprod : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b →
            (∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
              ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = 2 * y ∨
               ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = y ∧ ¬ 2 ∣ y))) ∧
            a * (2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
          intro a ha hpa b hb hpb
          have hd := hdiv a ha hpa
          have hGb' := hGb b hb hpb
          generalize (B.filter (fun b => ¬ p ∣ b)).gcd id = G at *
          obtain ⟨e, he⟩ := hd
          obtain ⟨s, hs⟩ := hGb'
          obtain ⟨y, hy0, hyn, hpy, hy, h⟩ := hA a ha hpa b hb hpb
          have ha0' := hpos a ha
          have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b ha0'
          have hx : 2 * p * G / a = e := by rw [he]; exact Nat.mul_div_cancel_left e ha0'
          have ht : b / G = s := by
            rw [hs]; exact Nat.mul_div_cancel_left s (Nat.pos_of_ne_zero hG0)
          rw [hx, ht]
          have hmain : a * (e * s) = 2 * p * (a.gcd b * y) := by
            calc a * (e * s) = (a * e) * s := by ring
              _ = 2 * p * (G * s) := by rw [← he]; ring
              _ = 2 * p * (a.gcd b * y) := by rw [← hs, ← hy]
          refine ⟨⟨y, hy0, hyn, hpy, ?_⟩, he.symm⟩
          rcases h with h | ⟨h, h2y⟩
          · left
            have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
              calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                _ = 2 * p * (a.gcd b * y) := hmain
                _ = p * a.gcd b * (2 * y) := by ring
            exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos hp.pos hg0) h5
          · right
            refine ⟨?_, h2y⟩
            have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
              calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                _ = 2 * p * (a.gcd b * y) := hmain
                _ = 2 * p * a.gcd b * y := by ring
            exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) hg0) h5
        have hcardsum : (B.filter (fun a => p ∣ a)).card + (B.filter (fun b => ¬ p ∣ b)).card = B.card := by
          rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter_filter_not B B (fun a => p ∣ a)),
            Finset.filter_union_filter_not_eq]
        have hinjX : Set.InjOn (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a)
            (B.filter (fun a => p ∣ a) : Finset ℕ) := by
          intro a ha a' ha' h
          obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
          obtain ⟨haB', hpa'⟩ := Finset.mem_filter.mp ha'
          have h1 := (hprod a haB hpa b0 hb0 hpb0).2
          have h2 := (hprod a' haB' hpa' b0 hb0 hpb0).2
          simp only at h
          rw [← h] at h2
          have hq : 0 < 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a := by
            apply Nat.pos_of_ne_zero
            intro hz
            rw [hz, Nat.mul_zero] at h1
            have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)
            omega
          exact Nat.eq_of_mul_eq_mul_right hq (h1.trans h2.symm)
        have hinjT : Set.InjOn (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id)
            (B.filter (fun b => ¬ p ∣ b) : Finset ℕ) := by
          intro b hb b' hb' h
          obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
          obtain ⟨hbB', hpb'⟩ := Finset.mem_filter.mp hb'
          simp only at h
          rw [← Nat.div_mul_cancel (hGb b hbB hpb), ← Nat.div_mul_cancel (hGb b' hbB' hpb'), h]
        have hK := R2b_K2 B.card p
          ((B.filter (fun a => p ∣ a)).image (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a))
          ((B.filter (fun b => ¬ p ∣ b)).image (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id))
          hp.pos h2p h9
          (by
            intro x hx t ht
            obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hx
            obtain ⟨b, hb, rfl⟩ := Finset.mem_image.mp ht
            obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
            obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
            exact (hprod a haB hpa b hbB hpb).1)
          ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha0, hpa0⟩)⟩
          ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)⟩
          (by rw [Finset.card_image_of_injOn hinjX, Finset.card_image_of_injOn hinjT, hcardsum])
        rcases hK with hX1 | hS1
        · -- every multiple of p equals 2pG, G = 1: B = {2p} ∪ T, impossible by Lemma I
          exfalso
          have hall : ∀ a ∈ B, p ∣ a → a = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
            intro a ha hpa
            have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))
            have h2 := (hprod a ha hpa b0 hb0 hpb0).2
            rw [h1, Nat.mul_one] at h2
            exact h2
          have hG1 : (B.filter (fun b => ¬ p ∣ b)).gcd id = 1 := by
            have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
              apply Finset.dvd_gcd
              intro b hb
              by_cases hpb : p ∣ b
              · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
              · exact hGb b hb hpb
            rw [hgcd] at h1
            exact Nat.dvd_one.mp h1
          rw [hG1, Nat.mul_one] at hall
          have h2pB : 2 * p ∈ B := by rw [← hall a0 ha0 hpa0]; exact ha0
          have hT : ∀ b ∈ B.erase (2 * p), b ∈ B ∧ ¬ p ∣ b := by
            intro b hb
            obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb
            exact ⟨hbB, fun h => hne (hall b hbB h)⟩
          have hbound : ∀ b ∈ B.erase (2 * p), b < B.card * b.gcd 2 := by
            intro b hb
            obtain ⟨hbB, hpb⟩ := hT b hb
            have h1 := hlt b hbB (2 * p) h2pB
            have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb
            rwa [Nat.Coprime.gcd_mul_right_cancel_right 2 hc] at h1
          have hI := R2b_lemI B.card p (B.erase (2 * p)) hp hp3 h2p hn3
            (fun b hb => hpos b (hT b hb).1) (fun b hb => (hT b hb).2)
            (by
              intro b hb h2
              have h1 := hbound b hb
              have hc : Nat.Coprime b 2 :=
                Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)
              rw [Nat.Coprime.gcd_eq_one hc] at h1
              omega)
            (by
              intro b hb _
              have h1 := hbound b hb
              have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)
              have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3
              omega)
            (fun b hb t ht _ _ => hlt b (hT b hb).1 t (hT t ht).1)
          rw [Finset.card_erase_of_mem h2pB] at hI
          omega
        · -- every non-multiple equals G
          have hall : ∀ b ∈ B, ¬ p ∣ b → b = (B.filter (fun b => ¬ p ∣ b)).gcd id := by
            intro b hb hpb
            have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))
            have h2 := Nat.div_mul_cancel (hGb b hb hpb)
            rw [h1, Nat.one_mul] at h2
            exact h2.symm
          have hb0G := hall b0 hb0 hpb0
          refine ⟨b0, hb0, hpb0, ?_, ?_⟩
          · intro b hb hpb
            rw [hall b hb hpb, ← hb0G]
          · intro a ha
            by_cases hpa : p ∣ a
            · rw [hb0G]; exact hdiv a ha hpa
            · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 285–514 at 841d05f96fd2 ↗

    1. R2b_block.s1 obtain ∃ a ∈ B, p ∣ a

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with a0 : ℕ, ha0 : a0 ∈ B, hpa0 : p ∣ a0.

      Lean, line 288
          obtain ⟨a0, ha0, hpa0⟩ := hex

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 288 at 841d05f96fd2 ↗

    2. R2b_block.hexb have ∃ b ∈ B, ¬p ∣ b

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hexb : ∃ b ∈ B, ¬p ∣ b.

      Uses library Not Not p, or ¬p, is the negation of p. , Nat.dvd_one.

      Lean, lines 289–294
          have hexb : ∃ b ∈ B, ¬ p ∣ b := by
            by_contra h
            push Not at h
            have h1 : p ∣ B.gcd id := Finset.dvd_gcd (fun b hb => h b hb)
            rw [hgcd] at h1
            exact hp.one_lt.ne' (Nat.dvd_one.mp h1)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 289–294 at 841d05f96fd2 ↗

      1. R2b_block.hexb.h1 have p ∣ B.gcd id

        Leaves False, with h1 : p ∣ B.gcd id.

        Uses library id The identity function. , Finset.dvd_gcd.

        Lean, line 292
              have h1 : p ∣ B.gcd id := Finset.dvd_gcd (fun b hb => h b hb)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 292 at 841d05f96fd2 ↗

    3. R2b_block.s3 obtain ∃ b ∈ B, ¬p ∣ b

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with b0 : ℕ, hb0 : b0 ∈ B, hpb0 : ¬p ∣ b0.

      Lean, line 295
          obtain ⟨b0, hb0, hpb0⟩ := hexb

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 295 at 841d05f96fd2 ↗

    4. R2b_block.hpos have ∀ a ∈ B, (0 : ℕ) < a

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hpos : ∀ a ∈ B, (0 : ℕ) < a.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 296
          have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 296 at 841d05f96fd2 ↗

    5. R2b_block.hA have ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬p ∣ b → ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y)

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hA : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬p ∣ b → ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y).

      Uses library Exists.intro Existential introduction. , Nat.pos_of_ne_zero.

      Lean, lines 298–351
          have hA : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b → ∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
              b = a.gcd b * y ∧ (a = p * a.gcd b ∨ (a = 2 * p * a.gcd b ∧ ¬ 2 ∣ y)) := by
            intro a ha hpa b hb hpb
            have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (hpos a ha)
            obtain ⟨x, hx⟩ := Nat.gcd_dvd_left a b
            obtain ⟨y, hy⟩ := Nat.gcd_dvd_right a b
            have hpg : ¬ p ∣ a.gcd b := fun h => hpb (h.trans (Nat.gcd_dvd_right a b))
            have hpx : p ∣ x := by
              have h1 : p ∣ a.gcd b * x := hx ▸ hpa
              exact (hp.dvd_mul.mp h1).resolve_left hpg
            obtain ⟨t, ht⟩ := hpx
            have hxn : x < B.card := by
              have h3 : a.gcd b * x < a.gcd b * B.card := by
                rw [← hx, Nat.mul_comm]; exact hlt a ha b hb
              exact Nat.lt_of_mul_lt_mul_left h3
            have hyn : y < B.card := by
              have h3 : a.gcd b * y < a.gcd b * B.card := by
                rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha
              exact Nat.lt_of_mul_lt_mul_left h3
            have hx0 : x ≠ 0 := by
              rintro rfl
              rw [Nat.mul_zero] at hx
              exact (hpos a ha).ne' hx
            have hy0 : y ≠ 0 := by
              rintro rfl
              rw [Nat.mul_zero] at hy
              exact (hpos b hb).ne' hy
            have hpy : ¬ p ∣ y := fun h => hpb (hy ▸ Dvd.dvd.mul_left h _)
            have hcop : Nat.Coprime x y := by
              have h1 := Nat.coprime_div_gcd_div_gcd hg0
              have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx
              have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy
              rwa [e1, e2] at h1
            have ht0 : t ≠ 0 := by
              rintro rfl
              rw [Nat.mul_zero] at ht
              exact hx0 ht
            have ht3 : t < 3 := by
              by_contra h
              push Not at h
              have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h
              omega
            refine ⟨y, Nat.pos_of_ne_zero hy0, hyn, hpy, hy, ?_⟩
            rcases (by omega : t = 1 ∨ t = 2) with rfl | rfl
            · left
              calc a = a.gcd b * x := hx
                _ = p * a.gcd b := by rw [ht]; ring
            · right
              refine ⟨(calc a = a.gcd b * x := hx
                _ = 2 * p * a.gcd b := by rw [ht]; ring), ?_⟩
              intro h2y
              have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩
              have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y
              omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 298–351 at 841d05f96fd2 ↗

      1. R2b_block.hA.hg0 have (0 : ℕ) < a.gcd b

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hg0 : (0 : ℕ) < a.gcd b.

        Uses library Nat.gcd_pos_of_pos_left.

        Lean, line 301
              have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (hpos a ha)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 301 at 841d05f96fd2 ↗

      2. R2b_block.hA.s2 obtain a.gcd b ∣ a

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with x : ℕ, hx : a = a.gcd b * x.

        Uses library Nat.gcd_dvd_left.

        Lean, line 302
              obtain ⟨x, hx⟩ := Nat.gcd_dvd_left a b

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 302 at 841d05f96fd2 ↗

      3. R2b_block.hA.s3 obtain a.gcd b ∣ b

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with y : ℕ, hy : b = a.gcd b * y.

        Uses library Nat.gcd_dvd_right.

        Lean, line 303
              obtain ⟨y, hy⟩ := Nat.gcd_dvd_right a b

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 303 at 841d05f96fd2 ↗

      4. R2b_block.hA.hpg have ¬p ∣ a.gcd b

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hpg : ¬p ∣ a.gcd b.

        Uses library Nat.gcd_dvd_right.

        Lean, line 304
              have hpg : ¬ p ∣ a.gcd b := fun h => hpb (h.trans (Nat.gcd_dvd_right a b))

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 304 at 841d05f96fd2 ↗

      5. R2b_block.hA.hpx have p ∣ x

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hpx : p ∣ x.

        Lean, lines 305–307
              have hpx : p ∣ x := by
                have h1 : p ∣ a.gcd b * x := hx ▸ hpa
                exact (hp.dvd_mul.mp h1).resolve_left hpg

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 305–307 at 841d05f96fd2 ↗

        1. R2b_block.hA.hpx.h1 have p ∣ a.gcd b * x

          Leaves p ∣ x, with h1 : p ∣ a.gcd b * x.

          Lean, line 306
                  have h1 : p ∣ a.gcd b * x := hx ▸ hpa

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 306 at 841d05f96fd2 ↗

      6. R2b_block.hA.s6 obtain p ∣ x

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with t : ℕ, ht : x = p * t.

        Lean, line 308
              obtain ⟨t, ht⟩ := hpx

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 308 at 841d05f96fd2 ↗

      7. R2b_block.hA.hxn have x < B.card

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hxn : x < B.card.

        Uses library Nat.lt_of_mul_lt_mul_left.

        Lean, lines 309–312
              have hxn : x < B.card := by
                have h3 : a.gcd b * x < a.gcd b * B.card := by
                  rw [← hx, Nat.mul_comm]; exact hlt a ha b hb
                exact Nat.lt_of_mul_lt_mul_left h3

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 309–312 at 841d05f96fd2 ↗

        1. R2b_block.hA.hxn.h3 have a.gcd b * x < a.gcd b * B.card

          Leaves x < B.card, with h3 : a.gcd b * x < a.gcd b * B.card.

          Uses library Nat.mul_comm.

          Lean, lines 310–311
                  have h3 : a.gcd b * x < a.gcd b * B.card := by
                    rw [← hx, Nat.mul_comm]; exact hlt a ha b hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 310–311 at 841d05f96fd2 ↗

      8. R2b_block.hA.hyn have y < B.card

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hyn : y < B.card.

        Uses library Nat.lt_of_mul_lt_mul_left.

        Lean, lines 313–316
              have hyn : y < B.card := by
                have h3 : a.gcd b * y < a.gcd b * B.card := by
                  rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha
                exact Nat.lt_of_mul_lt_mul_left h3

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 313–316 at 841d05f96fd2 ↗

        1. R2b_block.hA.hyn.h3 have a.gcd b * y < a.gcd b * B.card

          Leaves y < B.card, with h3 : a.gcd b * y < a.gcd b * B.card.

          Uses library Nat.mul_comm, Nat.gcd_comm.

          Lean, lines 314–315
                  have h3 : a.gcd b * y < a.gcd b * B.card := by
                    rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 314–315 at 841d05f96fd2 ↗

      9. R2b_block.hA.hx0 have x ≠ (0 : ℕ)

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hx0 : x ≠ (0 : ℕ).

        Uses library Nat.mul_zero.

        Lean, lines 317–320
              have hx0 : x ≠ 0 := by
                rintro rfl
                rw [Nat.mul_zero] at hx
                exact (hpos a ha).ne' hx

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 317–320 at 841d05f96fd2 ↗

      10. R2b_block.hA.hy0 have y ≠ (0 : ℕ)

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hy0 : y ≠ (0 : ℕ).

        Uses library Nat.mul_zero.

        Lean, lines 321–324
              have hy0 : y ≠ 0 := by
                rintro rfl
                rw [Nat.mul_zero] at hy
                exact (hpos b hb).ne' hy

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 321–324 at 841d05f96fd2 ↗

      11. R2b_block.hA.hpy have ¬p ∣ y

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hpy : ¬p ∣ y.

        Uses library Dvd.dvd.mul_left Alias of dvd_mul_of_dvd_right. .

        Lean, line 325
              have hpy : ¬ p ∣ y := fun h => hpb (hy ▸ Dvd.dvd.mul_left h _)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 325 at 841d05f96fd2 ↗

      12. R2b_block.hA.hcop have x.Coprime y

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with hcop : x.Coprime y.

        Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. .

        Lean, lines 326–330
              have hcop : Nat.Coprime x y := by
                have h1 := Nat.coprime_div_gcd_div_gcd hg0
                have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx
                have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy
                rwa [e1, e2] at h1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 326–330 at 841d05f96fd2 ↗

        1. R2b_block.hA.hcop.h1 have (a / a.gcd b).Coprime (b / a.gcd b)

          Leaves x.Coprime y, with h1 : (a / a.gcd b).Coprime (b / a.gcd b).

          Uses library Nat.coprime_div_gcd_div_gcd.

          Lean, line 327
                  have h1 := Nat.coprime_div_gcd_div_gcd hg0

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 327 at 841d05f96fd2 ↗

        2. R2b_block.hA.hcop.e1 have a / a.gcd b = x

          Leaves x.Coprime y, with e1 : a / a.gcd b = x.

          Uses library Nat.div_eq_of_eq_mul_right.

          Lean, line 328
                  have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 328 at 841d05f96fd2 ↗

        3. R2b_block.hA.hcop.e2 have b / a.gcd b = y

          Leaves x.Coprime y, with e2 : b / a.gcd b = y.

          Uses library Nat.div_eq_of_eq_mul_right.

          Lean, line 329
                  have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 329 at 841d05f96fd2 ↗

      13. R2b_block.hA.ht0 have t ≠ (0 : ℕ)

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with ht0 : t ≠ (0 : ℕ).

        Uses library Nat.mul_zero.

        Lean, lines 331–334
              have ht0 : t ≠ 0 := by
                rintro rfl
                rw [Nat.mul_zero] at ht
                exact hx0 ht

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 331–334 at 841d05f96fd2 ↗

      14. R2b_block.hA.ht3 have t < (3 : ℕ)

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y), with ht3 : t < (3 : ℕ).

        Uses library Not Not p, or ¬p, is the negation of p. .

        Lean, lines 335–339
              have ht3 : t < 3 := by
                by_contra h
                push Not at h
                have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 335–339 at 841d05f96fd2 ↗

        1. R2b_block.hA.ht3.h4 have p * (3 : ℕ) ≤ p * t

          Leaves False, with h4 : p * (3 : ℕ) ≤ p * t.

          Uses library Nat.mul_le_mul_left.

          Lean, line 338
                  have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 338 at 841d05f96fd2 ↗

      15. R2b_block.hA.s15 case

        Leaves a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y.

        Lean, lines 342–344
              · left
                calc a = a.gcd b * x := hx
                  _ = p * a.gcd b := by rw [ht]; ring

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 342–344 at 841d05f96fd2 ↗

        1. R2b_block.hA.s15.s1 calc a = a.gcd b * x
        2. R2b_block.hA.s15.s2 calc
      16. R2b_block.hA.s16 case

        Leaves a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y.

        Uses library And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 345–351
              · right
                refine ⟨(calc a = a.gcd b * x := hx
                  _ = 2 * p * a.gcd b := by rw [ht]; ring), ?_⟩
                intro h2y
                have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩
                have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 345–351 at 841d05f96fd2 ↗

        1. R2b_block.hA.s16.s1 calc a = a.gcd b * x
        2. R2b_block.hA.s16.s2 calc
        3. R2b_block.hA.s16.h2x have (2 : ℕ) ∣ x

          Leaves False, with h2x : (2 : ℕ) ∣ x.

          Uses library Exists.intro Existential introduction. .

          Lean, line 349
                  have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 349 at 841d05f96fd2 ↗

        4. R2b_block.hA.s16.this have (2 : ℕ) = (1 : ℕ)

          Leaves False, with this : (2 : ℕ) = (1 : ℕ).

          Uses library Nat.Coprime.eq_one_of_dvd, Nat.Coprime.coprime_dvd_left.

          Lean, line 350
                  have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 350 at 841d05f96fd2 ↗

    6. R2b_block.hG0 have {b ∈ B | ¬p ∣ b}.gcd id ≠ (0 : ℕ)

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hG0 : {b ∈ B | ¬p ∣ b}.gcd id ≠ (0 : ℕ).

      Uses library id The identity function. , Nat.eq_zero_of_zero_dvd, dvd_zero.

      Lean, lines 352–357
          have hG0 : (B.filter (fun b => ¬ p ∣ b)).gcd id ≠ 0 := by
            intro h
            have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ id b0 :=
              Finset.gcd_dvd (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)
            rw [h] at h1
            exact hpb0 (by rw [show b0 = 0 from Nat.eq_zero_of_zero_dvd h1]; exact dvd_zero p)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 352–357 at 841d05f96fd2 ↗

      1. R2b_block.hG0.h1 have {b ∈ B | ¬p ∣ b}.gcd id ∣ id b0

        Leaves False, with h1 : {b ∈ B | ¬p ∣ b}.gcd id ∣ id b0.

        Uses library id The identity function. , Finset.gcd_dvd, Finset.mem_filter, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 354–355
              have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ id b0 :=
                Finset.gcd_dvd (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 354–355 at 841d05f96fd2 ↗

    7. R2b_block.hGb have ∀ b ∈ B, ¬p ∣ b → {b ∈ B | ¬p ∣ b}.gcd id ∣ b

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hGb : ∀ b ∈ B, ¬p ∣ b → {b ∈ B | ¬p ∣ b}.gcd id ∣ b.

      Uses library id The identity function. , Finset.gcd_dvd, Finset.mem_filter, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

      Lean, lines 358–360
          have hGb : ∀ b ∈ B, ¬ p ∣ b → (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ b := by
            intro b hb hpb
            exact Finset.gcd_dvd (f := id) (Finset.mem_filter.mpr ⟨hb, hpb⟩)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 358–360 at 841d05f96fd2 ↗

    8. R2b_block.hdiv have ∀ a ∈ B, p ∣ a → a ∣ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hdiv : ∀ a ∈ B, p ∣ a → a ∣ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

      Uses library id The identity function. , Finset.gcd_mul_left.

      Lean, lines 361–374
          have hdiv : ∀ a ∈ B, p ∣ a → a ∣ 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
            intro a ha hpa
            have h1 : a ∣ (B.filter (fun b => ¬ p ∣ b)).gcd (fun b => (2 * p) * id b) := by
              apply Finset.dvd_gcd
              intro b hb
              obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
              obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb
              have h2 : a ∣ 2 * p * a.gcd b := by
                rcases h with h | ⟨h, -⟩
                · exact ⟨2, by linarith⟩
                · exact ⟨1, by linarith⟩
              exact h2.trans (Nat.mul_dvd_mul_left _ (Nat.gcd_dvd_right a b))
            rw [Finset.gcd_mul_left] at h1
            simpa using h1

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 361–374 at 841d05f96fd2 ↗

      1. R2b_block.hdiv.h1 have a ∣ {b ∈ B | ¬p ∣ b}.gcd fun (b : ℕ) => (2 : ℕ) * p * id b

        Leaves a ∣ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id, with h1 : a ∣ {b ∈ B | ¬p ∣ b}.gcd fun (b : ℕ) => (2 : ℕ) * p * id b.

        Uses library id The identity function. , Finset.dvd_gcd, Nat.mul_dvd_mul_left, Nat.gcd_dvd_right.

        Lean, lines 363–372
              have h1 : a ∣ (B.filter (fun b => ¬ p ∣ b)).gcd (fun b => (2 * p) * id b) := by
                apply Finset.dvd_gcd
                intro b hb
                obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
                obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb
                have h2 : a ∣ 2 * p * a.gcd b := by
                  rcases h with h | ⟨h, -⟩
                  · exact ⟨2, by linarith⟩
                  · exact ⟨1, by linarith⟩
                exact h2.trans (Nat.mul_dvd_mul_left _ (Nat.gcd_dvd_right a b))

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 363–372 at 841d05f96fd2 ↗

        1. R2b_block.hdiv.h1.s1 obtain b ∈ B ∧ ¬p ∣ b

          Leaves a ∣ (2 : ℕ) * p * id b, with hbB : b ∈ B, hpb : ¬p ∣ b.

          Uses library Finset.mem_filter.

          Lean, line 366
                  obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 366 at 841d05f96fd2 ↗

        2. R2b_block.hdiv.h1.s2 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y)

          Leaves a ∣ (2 : ℕ) * p * id b, with y : ℕ, hy : b = a.gcd b * y, h : a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y.

          Lean, line 367
                  obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 367 at 841d05f96fd2 ↗

        3. R2b_block.hdiv.h1.h2 have a ∣ (2 : ℕ) * p * a.gcd b

          Leaves a ∣ (2 : ℕ) * p * id b, with h2 : a ∣ (2 : ℕ) * p * a.gcd b.

          Lean, lines 368–371
                  have h2 : a ∣ 2 * p * a.gcd b := by
                    rcases h with h | ⟨h, -⟩
                    · exact ⟨2, by linarith⟩
                    · exact ⟨1, by linarith⟩

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 368–371 at 841d05f96fd2 ↗

          1. R2b_block.hdiv.h1.h2.s1 case

            Leaves a ∣ (2 : ℕ) * p * a.gcd b.

            Uses library Exists.intro Existential introduction. .

            Lean, line 370
                      · exact ⟨2, by linarith⟩

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 370 at 841d05f96fd2 ↗

          2. R2b_block.hdiv.h1.h2.s2 case

            Leaves a ∣ (2 : ℕ) * p * a.gcd b.

            Uses library Exists.intro Existential introduction. .

            Lean, line 371
                      · exact ⟨1, by linarith⟩

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 371 at 841d05f96fd2 ↗

    9. R2b_block.hprod have ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬p ∣ b → (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hprod : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬p ∣ b → (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

      Uses library id The identity function. , And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. , Exists.intro Existential introduction. .

      Lean, lines 375–411
          have hprod : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b →
              (∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
                ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = 2 * y ∨
                 ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = y ∧ ¬ 2 ∣ y))) ∧
              a * (2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
            intro a ha hpa b hb hpb
            have hd := hdiv a ha hpa
            have hGb' := hGb b hb hpb
            generalize (B.filter (fun b => ¬ p ∣ b)).gcd id = G at *
            obtain ⟨e, he⟩ := hd
            obtain ⟨s, hs⟩ := hGb'
            obtain ⟨y, hy0, hyn, hpy, hy, h⟩ := hA a ha hpa b hb hpb
            have ha0' := hpos a ha
            have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b ha0'
            have hx : 2 * p * G / a = e := by rw [he]; exact Nat.mul_div_cancel_left e ha0'
            have ht : b / G = s := by
              rw [hs]; exact Nat.mul_div_cancel_left s (Nat.pos_of_ne_zero hG0)
            rw [hx, ht]
            have hmain : a * (e * s) = 2 * p * (a.gcd b * y) := by
              calc a * (e * s) = (a * e) * s := by ring
                _ = 2 * p * (G * s) := by rw [← he]; ring
                _ = 2 * p * (a.gcd b * y) := by rw [← hs, ← hy]
            refine ⟨⟨y, hy0, hyn, hpy, ?_⟩, he.symm⟩
            rcases h with h | ⟨h, h2y⟩
            · left
              have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
                calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                  _ = 2 * p * (a.gcd b * y) := hmain
                  _ = p * a.gcd b * (2 * y) := by ring
              exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos hp.pos hg0) h5
            · right
              refine ⟨?_, h2y⟩
              have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
                calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                  _ = 2 * p * (a.gcd b * y) := hmain
                  _ = 2 * p * a.gcd b * y := by ring
              exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) hg0) h5

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 375–411 at 841d05f96fd2 ↗

      1. R2b_block.hprod.hd have a ∣ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id, with hd : a ∣ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

        Lean, line 381
              have hd := hdiv a ha hpa

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 381 at 841d05f96fd2 ↗

      2. R2b_block.hprod.hGb' have {b ∈ B | ¬p ∣ b}.gcd id ∣ b

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id, with hGb' : {b ∈ B | ¬p ∣ b}.gcd id ∣ b.

        Lean, line 382
              have hGb' := hGb b hb hpb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 382 at 841d05f96fd2 ↗

      3. R2b_block.hprod.s3 obtain a ∣ (2 : ℕ) * p * G

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with e : ℕ, he : (2 : ℕ) * p * G = a * e.

        Lean, line 384
              obtain ⟨e, he⟩ := hd

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 384 at 841d05f96fd2 ↗

      4. R2b_block.hprod.s4 obtain G ∣ b

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with s : ℕ, hs : b = G * s.

        Lean, line 385
              obtain ⟨s, hs⟩ := hGb'

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 385 at 841d05f96fd2 ↗

      5. R2b_block.hprod.s5 obtain ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ b = a.gcd b * y ∧ (a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y)

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with y : ℕ, hy0 : (0 : ℕ) < y, hyn : y < B.card, hpy : ¬p ∣ y, hy : b = a.gcd b * y, h : a = p * a.gcd b ∨ a = (2 : ℕ) * p * a.gcd b ∧ ¬(2 : ℕ) ∣ y.

        Lean, line 386
              obtain ⟨y, hy0, hyn, hpy, hy, h⟩ := hA a ha hpa b hb hpb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 386 at 841d05f96fd2 ↗

      6. R2b_block.hprod.ha0' have (0 : ℕ) < a

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with ha0' : (0 : ℕ) < a.

        Lean, line 387
              have ha0' := hpos a ha

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 387 at 841d05f96fd2 ↗

      7. R2b_block.hprod.hg0 have (0 : ℕ) < a.gcd b

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with hg0 : (0 : ℕ) < a.gcd b.

        Uses library Nat.gcd_pos_of_pos_left.

        Lean, line 388
              have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b ha0'

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 388 at 841d05f96fd2 ↗

      8. R2b_block.hprod.hx have (2 : ℕ) * p * G / a = e

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with hx : (2 : ℕ) * p * G / a = e.

        Uses library Nat.mul_div_cancel_left.

        Lean, line 389
              have hx : 2 * p * G / a = e := by rw [he]; exact Nat.mul_div_cancel_left e ha0'

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 389 at 841d05f96fd2 ↗

      9. R2b_block.hprod.ht have b / G = s

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * G / a * (b / G) = (2 : ℕ) * y ∨ (2 : ℕ) * p * G / a * (b / G) = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * ((2 : ℕ) * p * G / a) = (2 : ℕ) * p * G, with ht : b / G = s.

        Uses library Nat.mul_div_cancel_left, Nat.pos_of_ne_zero.

        Lean, lines 390–391
              have ht : b / G = s := by
                rw [hs]; exact Nat.mul_div_cancel_left s (Nat.pos_of_ne_zero hG0)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 390–391 at 841d05f96fd2 ↗

      10. R2b_block.hprod.hmain have a * (e * s) = (2 : ℕ) * p * (a.gcd b * y)

        Leaves (∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ (e * s = (2 : ℕ) * y ∨ e * s = y ∧ ¬(2 : ℕ) ∣ y)) ∧ a * e = (2 : ℕ) * p * G, with hmain : a * (e * s) = (2 : ℕ) * p * (a.gcd b * y).

        Lean, lines 393–396
              have hmain : a * (e * s) = 2 * p * (a.gcd b * y) := by
                calc a * (e * s) = (a * e) * s := by ring
                  _ = 2 * p * (G * s) := by rw [← he]; ring
                  _ = 2 * p * (a.gcd b * y) := by rw [← hs, ← hy]

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 393–396 at 841d05f96fd2 ↗

        1. R2b_block.hprod.hmain.s1 calc a * (e * s) = a * e * s routine: ring
        2. R2b_block.hprod.hmain.s2 calc
        3. R2b_block.hprod.hmain.s3 calc
      11. R2b_block.hprod.s11 case

        Leaves e * s = (2 : ℕ) * y ∨ e * s = y ∧ ¬(2 : ℕ) ∣ y.

        Uses library Nat.eq_of_mul_eq_mul_left, Nat.mul_pos.

        Lean, lines 399–404
              · left
                have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
                  calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                    _ = 2 * p * (a.gcd b * y) := hmain
                    _ = p * a.gcd b * (2 * y) := by ring
                exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos hp.pos hg0) h5

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 399–404 at 841d05f96fd2 ↗

        1. R2b_block.hprod.s11.h5 have p * a.gcd b * (e * s) = p * a.gcd b * ((2 : ℕ) * y)

          Leaves e * s = (2 : ℕ) * y, with h5 : p * a.gcd b * (e * s) = p * a.gcd b * ((2 : ℕ) * y).

          Lean, lines 400–403
                  have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
                    calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                      _ = 2 * p * (a.gcd b * y) := hmain
                      _ = p * a.gcd b * (2 * y) := by ring

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 400–403 at 841d05f96fd2 ↗

          1. R2b_block.hprod.s11.h5.s1 calc p * a.gcd b * (e * s) = a * (e * s)

            Closes the goal.

            Lean, line 401
                      calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 401 at 841d05f96fd2 ↗

          2. R2b_block.hprod.s11.h5.s2 calc a * (e * s) = (2 : ℕ) * p * (a.gcd b * y)
          3. R2b_block.hprod.s11.h5.s3 calc routine: ring
      12. R2b_block.hprod.s12 case

        Leaves e * s = (2 : ℕ) * y ∨ e * s = y ∧ ¬(2 : ℕ) ∣ y.

        Uses library And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. , Nat.eq_of_mul_eq_mul_left, Nat.mul_pos.

        Lean, lines 405–411
              · right
                refine ⟨?_, h2y⟩
                have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
                  calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                    _ = 2 * p * (a.gcd b * y) := hmain
                    _ = 2 * p * a.gcd b * y := by ring
                exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) hg0) h5

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 405–411 at 841d05f96fd2 ↗

        1. R2b_block.hprod.s12.h5 have (2 : ℕ) * p * a.gcd b * (e * s) = (2 : ℕ) * p * a.gcd b * y

          Leaves e * s = y, with h5 : (2 : ℕ) * p * a.gcd b * (e * s) = (2 : ℕ) * p * a.gcd b * y.

          Lean, lines 407–410
                  have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
                    calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
                      _ = 2 * p * (a.gcd b * y) := hmain
                      _ = 2 * p * a.gcd b * y := by ring

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 407–410 at 841d05f96fd2 ↗

          1. R2b_block.hprod.s12.h5.s1 calc (2 : ℕ) * p * a.gcd b * (e * s) = a * (e * s)

            Closes the goal.

            Lean, line 408
                      calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 408 at 841d05f96fd2 ↗

          2. R2b_block.hprod.s12.h5.s2 calc a * (e * s) = (2 : ℕ) * p * (a.gcd b * y)
          3. R2b_block.hprod.s12.h5.s3 calc routine: ring
    10. R2b_block.hcardsum have {a ∈ B | p ∣ a}.card + {b ∈ B | ¬p ∣ b}.card = B.card

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hcardsum : {a ∈ B | p ∣ a}.card + {b ∈ B | ¬p ∣ b}.card = B.card.

      Uses library Finset.card_union_of_disjoint Alias of the reverse direction of Finset.card_union_eq_card_add_card. , Finset.disjoint_filter_filter_not, Finset.filter_union_filter_not_eq.

      Lean, lines 412–414
          have hcardsum : (B.filter (fun a => p ∣ a)).card + (B.filter (fun b => ¬ p ∣ b)).card = B.card := by
            rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter_filter_not B B (fun a => p ∣ a)),
              Finset.filter_union_filter_not_eq]

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 412–414 at 841d05f96fd2 ↗

    11. R2b_block.hinjX have Set.InjOn (fun (a : ℕ) => (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) (↑({a ∈ B | p ∣ a}) : Set ℕ)

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hinjX : Set.InjOn (fun (a : ℕ) => (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) (↑({a ∈ B | p ∣ a}) : Set ℕ).

      Uses library Set.InjOn f is injective on s if the restriction of f to s is injective. , id The identity function. , Finset Finset α is the type of finite sets of elements of α. , Nat.eq_of_mul_eq_mul_right.

      Lean, lines 415–430
          have hinjX : Set.InjOn (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a)
              (B.filter (fun a => p ∣ a) : Finset ℕ) := by
            intro a ha a' ha' h
            obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
            obtain ⟨haB', hpa'⟩ := Finset.mem_filter.mp ha'
            have h1 := (hprod a haB hpa b0 hb0 hpb0).2
            have h2 := (hprod a' haB' hpa' b0 hb0 hpb0).2
            simp only at h
            rw [← h] at h2
            have hq : 0 < 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a := by
              apply Nat.pos_of_ne_zero
              intro hz
              rw [hz, Nat.mul_zero] at h1
              have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)
              omega
            exact Nat.eq_of_mul_eq_mul_right hq (h1.trans h2.symm)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 415–430 at 841d05f96fd2 ↗

      1. R2b_block.hinjX.s1 obtain a ∈ B ∧ p ∣ a

        Leaves a = a', with haB : a ∈ B, hpa : p ∣ a.

        Uses library Finset.mem_filter.

        Lean, line 418
              obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 418 at 841d05f96fd2 ↗

      2. R2b_block.hinjX.s2 obtain a' ∈ B ∧ p ∣ a'

        Leaves a = a', with haB' : a' ∈ B, hpa' : p ∣ a'.

        Uses library Finset.mem_filter.

        Lean, line 419
              obtain ⟨haB', hpa'⟩ := Finset.mem_filter.mp ha'

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 419 at 841d05f96fd2 ↗

      3. R2b_block.hinjX.h1 have a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

        Leaves a = a', with h1 : a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

        Lean, line 420
              have h1 := (hprod a haB hpa b0 hb0 hpb0).2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 420 at 841d05f96fd2 ↗

      4. R2b_block.hinjX.h2 have a' * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a') = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

        Leaves a = a', with h2 : a' * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a') = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

        Lean, line 421
              have h2 := (hprod a' haB' hpa' b0 hb0 hpb0).2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 421 at 841d05f96fd2 ↗

      5. R2b_block.hinjX.hq have (0 : ℕ) < (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a

        Leaves a = a', with hq : (0 : ℕ) < (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a.

        Uses library id The identity function. , Nat.pos_of_ne_zero, Nat.mul_zero.

        Lean, lines 424–429
              have hq : 0 < 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a := by
                apply Nat.pos_of_ne_zero
                intro hz
                rw [hz, Nat.mul_zero] at h1
                have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 424–429 at 841d05f96fd2 ↗

        1. R2b_block.hinjX.hq.this have (0 : ℕ) < (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

          Leaves False, with this : (0 : ℕ) < (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

          Uses library Nat.mul_pos, Nat.pos_of_ne_zero.

          Lean, line 428
                  have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 428 at 841d05f96fd2 ↗

    12. R2b_block.hinjT have Set.InjOn (fun (b : ℕ) => b / {b ∈ B | ¬p ∣ b}.gcd id) (↑({b ∈ B | ¬p ∣ b}) : Set ℕ)

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hinjT : Set.InjOn (fun (b : ℕ) => b / {b ∈ B | ¬p ∣ b}.gcd id) (↑({b ∈ B | ¬p ∣ b}) : Set ℕ).

      Uses library Set.InjOn f is injective on s if the restriction of f to s is injective. , id The identity function. , Finset Finset α is the type of finite sets of elements of α. , Nat.div_mul_cancel.

      Lean, lines 431–437
          have hinjT : Set.InjOn (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id)
              (B.filter (fun b => ¬ p ∣ b) : Finset ℕ) := by
            intro b hb b' hb' h
            obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
            obtain ⟨hbB', hpb'⟩ := Finset.mem_filter.mp hb'
            simp only at h
            rw [← Nat.div_mul_cancel (hGb b hbB hpb), ← Nat.div_mul_cancel (hGb b' hbB' hpb'), h]

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 431–437 at 841d05f96fd2 ↗

      1. R2b_block.hinjT.s1 obtain b ∈ B ∧ ¬p ∣ b

        Leaves b = b', with hbB : b ∈ B, hpb : ¬p ∣ b.

        Uses library Finset.mem_filter.

        Lean, line 434
              obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 434 at 841d05f96fd2 ↗

      2. R2b_block.hinjT.s2 obtain b' ∈ B ∧ ¬p ∣ b'

        Leaves b = b', with hbB' : b' ∈ B, hpb' : ¬p ∣ b'.

        Uses library Finset.mem_filter.

        Lean, line 435
              obtain ⟨hbB', hpb'⟩ := Finset.mem_filter.mp hb'

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 435 at 841d05f96fd2 ↗

    13. R2b_block.hK have (∀ x ∈ Finset.image (fun (a : ℕ) => (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) ({a ∈ B | p ∣ a}), x = (1 : ℕ)) ∨ ∀ s ∈ Finset.image (fun (b : ℕ) => b / {b ∈ B | ¬p ∣ b}.gcd id) ({b ∈ B | ¬p ∣ b}), s = (1 : ℕ)

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hK : (∀ x ∈ Finset.image (fun (a : ℕ) => (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) ({a ∈ B | p ∣ a}), x = (1 : ℕ)) ∨ ∀ s ∈ Finset.image (fun (b : ℕ) => b / {b ∈ B | ¬p ∣ b}.gcd id) ({b ∈ B | ¬p ∣ b}), s = (1 : ℕ).

      Uses library id The identity function. , Exists.intro Existential introduction. , Finset.mem_image_of_mem, Finset.mem_filter, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. , Finset.card_image_of_injOn.

      Lean, lines 438–451
          have hK := R2b_K2 B.card p
            ((B.filter (fun a => p ∣ a)).image (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a))
            ((B.filter (fun b => ¬ p ∣ b)).image (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id))
            hp.pos h2p h9
            (by
              intro x hx t ht
              obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hx
              obtain ⟨b, hb, rfl⟩ := Finset.mem_image.mp ht
              obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
              obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
              exact (hprod a haB hpa b hbB hpb).1)
            ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha0, hpa0⟩)⟩
            ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)⟩
            (by rw [Finset.card_image_of_injOn hinjX, Finset.card_image_of_injOn hinjT, hcardsum])

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 438–451 at 841d05f96fd2 ↗

      1. R2b_block.hK.s1 obtain ∃ a ∈ {a ∈ B | p ∣ a}, (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a = x

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * t = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * t = y ∧ ¬(2 : ℕ) ∣ y), with a : ℕ, ha : a ∈ {a ∈ B | p ∣ a}, hx : (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a ∈ Finset.image (fun (a : ℕ) => (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) ({a ∈ B | p ∣ a}).

        Uses library Finset.mem_image.

        Lean, line 444
                obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hx

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 444 at 841d05f96fd2 ↗

      2. R2b_block.hK.s2 obtain ∃ a ∈ {b ∈ B | ¬p ∣ b}, a / {b ∈ B | ¬p ∣ b}.gcd id = t

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y), with b : ℕ, hb : b ∈ {b ∈ B | ¬p ∣ b}, ht : b / {b ∈ B | ¬p ∣ b}.gcd id ∈ Finset.image (fun (b : ℕ) => b / {b ∈ B | ¬p ∣ b}.gcd id) ({b ∈ B | ¬p ∣ b}).

        Uses library Finset.mem_image.

        Lean, line 445
                obtain ⟨b, hb, rfl⟩ := Finset.mem_image.mp ht

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 445 at 841d05f96fd2 ↗

      3. R2b_block.hK.s3 obtain a ∈ B ∧ p ∣ a

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y), with haB : a ∈ B, hpa : p ∣ a.

        Uses library Finset.mem_filter.

        Lean, line 446
                obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 446 at 841d05f96fd2 ↗

      4. R2b_block.hK.s4 obtain b ∈ B ∧ ¬p ∣ b

        Leaves ∃ (y : ℕ), (0 : ℕ) < y ∧ y < B.card ∧ ¬p ∣ y ∧ ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = (2 : ℕ) * y ∨ (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a * (b / {b ∈ B | ¬p ∣ b}.gcd id) = y ∧ ¬(2 : ℕ) ∣ y), with hbB : b ∈ B, hpb : ¬p ∣ b.

        Uses library Finset.mem_filter.

        Lean, line 447
                obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 447 at 841d05f96fd2 ↗

    14. R2b_block.s14 case

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g.

      Uses library Nat.mul_one, Finset.card_erase_of_mem $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. .

      Lean, lines 453–499
          · -- every multiple of p equals 2pG, G = 1: B = {2p} ∪ T, impossible by Lemma I
            exfalso
            have hall : ∀ a ∈ B, p ∣ a → a = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
              intro a ha hpa
              have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))
              have h2 := (hprod a ha hpa b0 hb0 hpb0).2
              rw [h1, Nat.mul_one] at h2
              exact h2
            have hG1 : (B.filter (fun b => ¬ p ∣ b)).gcd id = 1 := by
              have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
                apply Finset.dvd_gcd
                intro b hb
                by_cases hpb : p ∣ b
                · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
                · exact hGb b hb hpb
              rw [hgcd] at h1
              exact Nat.dvd_one.mp h1
            rw [hG1, Nat.mul_one] at hall
            have h2pB : 2 * p ∈ B := by rw [← hall a0 ha0 hpa0]; exact ha0
            have hT : ∀ b ∈ B.erase (2 * p), b ∈ B ∧ ¬ p ∣ b := by
              intro b hb
              obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb
              exact ⟨hbB, fun h => hne (hall b hbB h)⟩
            have hbound : ∀ b ∈ B.erase (2 * p), b < B.card * b.gcd 2 := by
              intro b hb
              obtain ⟨hbB, hpb⟩ := hT b hb
              have h1 := hlt b hbB (2 * p) h2pB
              have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb
              rwa [Nat.Coprime.gcd_mul_right_cancel_right 2 hc] at h1
            have hI := R2b_lemI B.card p (B.erase (2 * p)) hp hp3 h2p hn3
              (fun b hb => hpos b (hT b hb).1) (fun b hb => (hT b hb).2)
              (by
                intro b hb h2
                have h1 := hbound b hb
                have hc : Nat.Coprime b 2 :=
                  Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)
                rw [Nat.Coprime.gcd_eq_one hc] at h1
                omega)
              (by
                intro b hb _
                have h1 := hbound b hb
                have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)
                have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3
                omega)
              (fun b hb t ht _ _ => hlt b (hT b hb).1 t (hT t ht).1)
            rw [Finset.card_erase_of_mem h2pB] at hI
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 453–499 at 841d05f96fd2 ↗

      1. R2b_block.s14.hall have ∀ a ∈ B, p ∣ a → a = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

        Leaves False, with hall : ∀ a ∈ B, p ∣ a → a = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

        Uses library id The identity function. , Nat.mul_one.

        Lean, lines 455–460
              have hall : ∀ a ∈ B, p ∣ a → a = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
                intro a ha hpa
                have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))
                have h2 := (hprod a ha hpa b0 hb0 hpb0).2
                rw [h1, Nat.mul_one] at h2
                exact h2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 455–460 at 841d05f96fd2 ↗

        1. R2b_block.s14.hall.h1 have (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a = (1 : ℕ)

          Leaves a = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id, with h1 : (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a = (1 : ℕ).

          Uses library Finset.mem_image_of_mem, Finset.mem_filter, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

          Lean, line 457
                  have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 457 at 841d05f96fd2 ↗

        2. R2b_block.s14.hall.h2 have a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id

          Leaves a = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id, with h2 : a * ((2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id / a) = (2 : ℕ) * p * {b ∈ B | ¬p ∣ b}.gcd id.

          Lean, line 458
                  have h2 := (hprod a ha hpa b0 hb0 hpb0).2

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 458 at 841d05f96fd2 ↗

      2. R2b_block.s14.hG1 have {b ∈ B | ¬p ∣ b}.gcd id = (1 : ℕ)

        Leaves False, with hG1 : {b ∈ B | ¬p ∣ b}.gcd id = (1 : ℕ).

        Uses library id The identity function. , Nat.dvd_one.

        Lean, lines 461–469
              have hG1 : (B.filter (fun b => ¬ p ∣ b)).gcd id = 1 := by
                have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
                  apply Finset.dvd_gcd
                  intro b hb
                  by_cases hpb : p ∣ b
                  · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
                  · exact hGb b hb hpb
                rw [hgcd] at h1
                exact Nat.dvd_one.mp h1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 461–469 at 841d05f96fd2 ↗

        1. R2b_block.s14.hG1.h1 have {b ∈ B | ¬p ∣ b}.gcd id ∣ B.gcd id

          Leaves {b ∈ B | ¬p ∣ b}.gcd id = (1 : ℕ), with h1 : {b ∈ B | ¬p ∣ b}.gcd id ∣ B.gcd id.

          Uses library id The identity function. , Finset.dvd_gcd.

          Lean, lines 462–467
                  have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
                    apply Finset.dvd_gcd
                    intro b hb
                    by_cases hpb : p ∣ b
                    · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
                    · exact hGb b hb hpb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 462–467 at 841d05f96fd2 ↗

          1. R2b_block.s14.hG1.h1.s1 case

            Leaves {b ∈ B | ¬p ∣ b}.gcd id ∣ id b.

            Uses library Exists.intro Existential introduction. , id The identity function. .

            Lean, line 466
                      · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 466 at 841d05f96fd2 ↗

          2. R2b_block.s14.hG1.h1.s2 case
      3. R2b_block.s14.h2pB have (2 : ℕ) * p ∈ B

        Leaves False, with h2pB : (2 : ℕ) * p ∈ B.

        Lean, line 471
              have h2pB : 2 * p ∈ B := by rw [← hall a0 ha0 hpa0]; exact ha0

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 471 at 841d05f96fd2 ↗

      4. R2b_block.s14.hT have ∀ b ∈ B.erase ((2 : ℕ) * p), b ∈ B ∧ ¬p ∣ b

        Leaves False, with hT : ∀ b ∈ B.erase ((2 : ℕ) * p), b ∈ B ∧ ¬p ∣ b.

        Uses library And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

        Lean, lines 472–475
              have hT : ∀ b ∈ B.erase (2 * p), b ∈ B ∧ ¬ p ∣ b := by
                intro b hb
                obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb
                exact ⟨hbB, fun h => hne (hall b hbB h)⟩

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 472–475 at 841d05f96fd2 ↗

        1. R2b_block.s14.hT.s1 obtain b ≠ (2 : ℕ) * p ∧ b ∈ B

          Leaves b ∈ B ∧ ¬p ∣ b, with hne : b ≠ (2 : ℕ) * p, hbB : b ∈ B.

          Uses library Finset.mem_erase.

          Lean, line 474
                  obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 474 at 841d05f96fd2 ↗

      5. R2b_block.s14.hbound have ∀ b ∈ B.erase ((2 : ℕ) * p), b < B.card * b.gcd (2 : ℕ)

        Leaves False, with hbound : ∀ b ∈ B.erase ((2 : ℕ) * p), b < B.card * b.gcd (2 : ℕ).

        Uses library Nat.Coprime.gcd_mul_right_cancel_right.

        Lean, lines 476–481
              have hbound : ∀ b ∈ B.erase (2 * p), b < B.card * b.gcd 2 := by
                intro b hb
                obtain ⟨hbB, hpb⟩ := hT b hb
                have h1 := hlt b hbB (2 * p) h2pB
                have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb
                rwa [Nat.Coprime.gcd_mul_right_cancel_right 2 hc] at h1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 476–481 at 841d05f96fd2 ↗

        1. R2b_block.s14.hbound.s1 obtain b ∈ B ∧ ¬p ∣ b

          Leaves b < B.card * b.gcd (2 : ℕ), with hbB : b ∈ B, hpb : ¬p ∣ b.

          Lean, line 478
                  obtain ⟨hbB, hpb⟩ := hT b hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 478 at 841d05f96fd2 ↗

        2. R2b_block.s14.hbound.h1 have b < B.card * b.gcd ((2 : ℕ) * p)

          Leaves b < B.card * b.gcd (2 : ℕ), with h1 : b < B.card * b.gcd ((2 : ℕ) * p).

          Lean, line 479
                  have h1 := hlt b hbB (2 * p) h2pB

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 479 at 841d05f96fd2 ↗

        3. R2b_block.s14.hbound.hc have p.Coprime b

          Leaves b < B.card * b.gcd (2 : ℕ), with hc : p.Coprime b.

          Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.Prime.coprime_iff_not_dvd.

          Lean, line 480
                  have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 480 at 841d05f96fd2 ↗

      6. R2b_block.s14.hI have (B.erase ((2 : ℕ) * p)).card + (2 : ℕ) ≤ B.card

        Leaves False, with hI : (B.erase ((2 : ℕ) * p)).card + (2 : ℕ) ≤ B.card.

        Uses library Nat.Coprime.gcd_eq_one.

        Lean, lines 482–497
              have hI := R2b_lemI B.card p (B.erase (2 * p)) hp hp3 h2p hn3
                (fun b hb => hpos b (hT b hb).1) (fun b hb => (hT b hb).2)
                (by
                  intro b hb h2
                  have h1 := hbound b hb
                  have hc : Nat.Coprime b 2 :=
                    Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)
                  rw [Nat.Coprime.gcd_eq_one hc] at h1
                  omega)
                (by
                  intro b hb _
                  have h1 := hbound b hb
                  have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)
                  have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3
                  omega)
                (fun b hb t ht _ _ => hlt b (hT b hb).1 t (hT t ht).1)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 482–497 at 841d05f96fd2 ↗

        1. R2b_block.s14.hI.s1 have b < B.card * b.gcd (2 : ℕ)

          Leaves b < B.card, with h1 : b < B.card * b.gcd (2 : ℕ).

          Lean, line 486
                    have h1 := hbound b hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 486 at 841d05f96fd2 ↗

        2. R2b_block.s14.hI.hc have b.Coprime (2 : ℕ)

          Leaves b < B.card, with hc : b.Coprime (2 : ℕ).

          Uses library Nat.Coprime m and n are coprime, or relatively prime, if their gcd is 1. , Nat.Coprime.symm, Nat.Prime.coprime_iff_not_dvd, Nat.prime_two.

          Lean, lines 487–488
                    have hc : Nat.Coprime b 2 :=
                      Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 487–488 at 841d05f96fd2 ↗

        3. R2b_block.s14.hI.s3 have b < B.card * b.gcd (2 : ℕ)

          Leaves b < (2 : ℕ) * B.card, with h1 : b < B.card * b.gcd (2 : ℕ).

          Lean, line 493
                    have h1 := hbound b hb

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 493 at 841d05f96fd2 ↗

        4. R2b_block.s14.hI.h3 have b.gcd (2 : ℕ) ≤ (2 : ℕ)

          Leaves b < (2 : ℕ) * B.card, with h3 : b.gcd (2 : ℕ) ≤ (2 : ℕ).

          Uses library Nat.gcd_le_right.

          Lean, line 494
                    have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 494 at 841d05f96fd2 ↗

        5. R2b_block.s14.hI.h4 have B.card * b.gcd (2 : ℕ) ≤ B.card * (2 : ℕ)

          Leaves b < (2 : ℕ) * B.card, with h4 : B.card * b.gcd (2 : ℕ) ≤ B.card * (2 : ℕ).

          Uses library Nat.mul_le_mul_left.

          Lean, line 495
                    have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 495 at 841d05f96fd2 ↗

    15. R2b_block.s15 case

      Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g.

      Uses library Exists.intro Existential introduction. .

      Lean, lines 500–514
          · -- every non-multiple equals G
            have hall : ∀ b ∈ B, ¬ p ∣ b → b = (B.filter (fun b => ¬ p ∣ b)).gcd id := by
              intro b hb hpb
              have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))
              have h2 := Nat.div_mul_cancel (hGb b hb hpb)
              rw [h1, Nat.one_mul] at h2
              exact h2.symm
            have hb0G := hall b0 hb0 hpb0
            refine ⟨b0, hb0, hpb0, ?_, ?_⟩
            · intro b hb hpb
              rw [hall b hb hpb, ← hb0G]
            · intro a ha
              by_cases hpa : p ∣ a
              · rw [hb0G]; exact hdiv a ha hpa
              · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 500–514 at 841d05f96fd2 ↗

      1. R2b_block.s15.hall have ∀ b ∈ B, ¬p ∣ b → b = {b ∈ B | ¬p ∣ b}.gcd id

        Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hall : ∀ b ∈ B, ¬p ∣ b → b = {b ∈ B | ¬p ∣ b}.gcd id.

        Uses library id The identity function. , Nat.one_mul.

        Lean, lines 501–506
              have hall : ∀ b ∈ B, ¬ p ∣ b → b = (B.filter (fun b => ¬ p ∣ b)).gcd id := by
                intro b hb hpb
                have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))
                have h2 := Nat.div_mul_cancel (hGb b hb hpb)
                rw [h1, Nat.one_mul] at h2
                exact h2.symm

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 501–506 at 841d05f96fd2 ↗

        1. R2b_block.s15.hall.h1 have b / {b ∈ B | ¬p ∣ b}.gcd id = (1 : ℕ)

          Leaves b = {b ∈ B | ¬p ∣ b}.gcd id, with h1 : b / {b ∈ B | ¬p ∣ b}.gcd id = (1 : ℕ).

          Uses library Finset.mem_image_of_mem, Finset.mem_filter, And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

          Lean, line 503
                  have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 503 at 841d05f96fd2 ↗

        2. R2b_block.s15.hall.h2 have b / {b ∈ B | ¬p ∣ b}.gcd id * {b ∈ B | ¬p ∣ b}.gcd id = b

          Leaves b = {b ∈ B | ¬p ∣ b}.gcd id, with h2 : b / {b ∈ B | ¬p ∣ b}.gcd id * {b ∈ B | ¬p ∣ b}.gcd id = b.

          Uses library Nat.div_mul_cancel.

          Lean, line 504
                  have h2 := Nat.div_mul_cancel (hGb b hb hpb)

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 504 at 841d05f96fd2 ↗

      2. R2b_block.s15.hb0G have b0 = {b ∈ B | ¬p ∣ b}.gcd id

        Leaves ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g, with hb0G : b0 = {b ∈ B | ¬p ∣ b}.gcd id.

        Lean, line 507
              have hb0G := hall b0 hb0 hpb0

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 507 at 841d05f96fd2 ↗

      3. R2b_block.s15.s3 case

        Leaves ∀ b ∈ B, ¬p ∣ b → b = b0.

        Lean, lines 509–510
              · intro b hb hpb
                rw [hall b hb hpb, ← hb0G]

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 509–510 at 841d05f96fd2 ↗

      4. R2b_block.s15.s4 case

        Leaves ∀ a ∈ B, a ∣ (2 : ℕ) * p * b0.

        Lean, lines 511–514
              · intro a ha
                by_cases hpa : p ∣ a
                · rw [hb0G]; exact hdiv a ha hpa
                · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 511–514 at 841d05f96fd2 ↗

        1. R2b_block.s15.s4.s1 case
        2. R2b_block.s15.s4.s2 case

          Leaves a ∣ (2 : ℕ) * p * b0.

          Uses library Dvd.intro_left, rfl rfl : a = a is the unique constructor of the equality type. .

          Lean, line 514
                  · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 514 at 841d05f96fd2 ↗

  6. R1b_dual_quot have ∀ (L a a' b b' : ℕ), a * a' = L → b * b' = L → (0 : ℕ) < a → a' * a.gcd b = b * a'.gcd b'

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R1b_dual_quot : ∀ (L a a' b b' : ℕ), a * a' = L → b * b' = L → (0 : ℕ) < a → a' * a.gcd b = b * a'.gcd b'.

    Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.eq_of_mul_eq_mul_left.

    Lean, lines 515–525
      have R1b_dual_quot : ∀ (L a a' b b' : ℕ) (ha : a * a' = L) (hb : b * b' = L) (h0 : 0 < a),
          a' * Nat.gcd a b = b * Nat.gcd a' b' := by
        intro L a a' b b' ha hb h0
        have h1 : Nat.gcd a' b' * (a * b) = L * Nat.gcd a b := by
          rw [← Nat.gcd_mul_right]
          have e1 : a' * (a * b) = L * b := by rw [← ha]; ring
          have e2 : b' * (a * b) = L * a := by rw [← hb]; ring
          rw [e1, e2, Nat.gcd_mul_left, Nat.gcd_comm b a]
        have h2 : a * (a' * Nat.gcd a b) = a * (b * Nat.gcd a' b') := by
          rw [← mul_assoc, ha, ← h1]; ring
        exact Nat.eq_of_mul_eq_mul_left h0 h2

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 515–525 at 841d05f96fd2 ↗

    1. R1b_dual_quot.h1 have a'.gcd b' * (a * b) = L * a.gcd b

      Leaves a' * a.gcd b = b * a'.gcd b', with h1 : a'.gcd b' * (a * b) = L * a.gcd b.

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.gcd_mul_right, Nat.gcd_mul_left, Nat.gcd_comm.

      Lean, lines 518–522
          have h1 : Nat.gcd a' b' * (a * b) = L * Nat.gcd a b := by
            rw [← Nat.gcd_mul_right]
            have e1 : a' * (a * b) = L * b := by rw [← ha]; ring
            have e2 : b' * (a * b) = L * a := by rw [← hb]; ring
            rw [e1, e2, Nat.gcd_mul_left, Nat.gcd_comm b a]

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 518–522 at 841d05f96fd2 ↗

      1. R1b_dual_quot.h1.e1 have a' * (a * b) = L * b

        Leaves (a' * (a * b)).gcd (b' * (a * b)) = L * a.gcd b, with e1 : a' * (a * b) = L * b.

        Lean, line 520
              have e1 : a' * (a * b) = L * b := by rw [← ha]; ring

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 520 at 841d05f96fd2 ↗

      2. R1b_dual_quot.h1.e2 have b' * (a * b) = L * a

        Leaves (a' * (a * b)).gcd (b' * (a * b)) = L * a.gcd b, with e2 : b' * (a * b) = L * a.

        Lean, line 521
              have e2 : b' * (a * b) = L * a := by rw [← hb]; ring

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 521 at 841d05f96fd2 ↗

    2. R1b_dual_quot.h2 have a * (a' * a.gcd b) = a * (b * a'.gcd b')

      Leaves a' * a.gcd b = b * a'.gcd b', with h2 : a * (a' * a.gcd b) = a * (b * a'.gcd b').

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , mul_assoc.

      Lean, lines 523–524
          have h2 : a * (a' * Nat.gcd a b) = a * (b * Nat.gcd a' b') := by
            rw [← mul_assoc, ha, ← h1]; ring

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 523–524 at 841d05f96fd2 ↗

  7. R1b_dual_strict have ∀ (L a a' b b' n : ℕ), a * a' = L → b * b' = L → (0 : ℕ) < L → a < n * a.gcd b → b' < n * b'.gcd a'

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R1b_dual_strict : ∀ (L a a' b b' n : ℕ), a * a' = L → b * b' = L → (0 : ℕ) < L → a < n * a.gcd b → b' < n * b'.gcd a'.

    Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.gcd_comm, Not Not p, or ¬p, is the negation of p. .

    Lean, lines 526–541
      have R1b_dual_strict : ∀ (L a a' b b' n : ℕ) (ha : a * a' = L) (hb : b * b' = L) (hL : 0 < L) (h : a < n * Nat.gcd a b),
          b' < n * Nat.gcd b' a' := by
        intro L a a' b b' n ha hb hL h
        have hb0 : 0 < b := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
        have hb'0 : 0 < b' := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
        have ha0 : 0 < a := Nat.pos_of_ne_zero (by rintro rfl; simp at ha; omega)
        have e := R1b_dual_quot L b b' a a' hb ha hb0
        have hg : 0 < Nat.gcd b a := Nat.gcd_pos_of_pos_left _ hb0
        have hg' : 0 < Nat.gcd b' a' := Nat.gcd_pos_of_pos_left _ hb'0
        rw [Nat.gcd_comm a b] at h
        by_contra hcon
        push Not at hcon
        have h3 : n * Nat.gcd b' a' * Nat.gcd b a ≤ b' * Nat.gcd b a := Nat.mul_le_mul_right _ hcon
        have h4 : a * Nat.gcd b' a' < n * Nat.gcd b a * Nat.gcd b' a' := Nat.mul_lt_mul_of_pos_right h hg'
        rw [e] at h3
        nlinarith

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 526–541 at 841d05f96fd2 ↗

    1. R1b_dual_strict.hb0 have (0 : ℕ) < b

      Leaves b' < n * b'.gcd a', with hb0 : (0 : ℕ) < b.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 529
          have hb0 : 0 < b := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 529 at 841d05f96fd2 ↗

    2. R1b_dual_strict.hb'0 have (0 : ℕ) < b'

      Leaves b' < n * b'.gcd a', with hb'0 : (0 : ℕ) < b'.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 530
          have hb'0 : 0 < b' := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 530 at 841d05f96fd2 ↗

    3. R1b_dual_strict.ha0 have (0 : ℕ) < a

      Leaves b' < n * b'.gcd a', with ha0 : (0 : ℕ) < a.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 531
          have ha0 : 0 < a := Nat.pos_of_ne_zero (by rintro rfl; simp at ha; omega)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 531 at 841d05f96fd2 ↗

    4. R1b_dual_strict.e have b' * b.gcd a = a * b'.gcd a'

      Leaves b' < n * b'.gcd a', with e : b' * b.gcd a = a * b'.gcd a'.

      Lean, line 532
          have e := R1b_dual_quot L b b' a a' hb ha hb0

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 532 at 841d05f96fd2 ↗

    5. R1b_dual_strict.hg have (0 : ℕ) < b.gcd a

      Leaves b' < n * b'.gcd a', with hg : (0 : ℕ) < b.gcd a.

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.gcd_pos_of_pos_left.

      Lean, line 533
          have hg : 0 < Nat.gcd b a := Nat.gcd_pos_of_pos_left _ hb0

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 533 at 841d05f96fd2 ↗

    6. R1b_dual_strict.hg' have (0 : ℕ) < b'.gcd a'

      Leaves b' < n * b'.gcd a', with hg' : (0 : ℕ) < b'.gcd a'.

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.gcd_pos_of_pos_left.

      Lean, line 534
          have hg' : 0 < Nat.gcd b' a' := Nat.gcd_pos_of_pos_left _ hb'0

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 534 at 841d05f96fd2 ↗

    7. R1b_dual_strict.h3 have n * b'.gcd a' * b.gcd a ≤ b' * b.gcd a

      Leaves False, with h3 : n * b'.gcd a' * b.gcd a ≤ b' * b.gcd a.

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.mul_le_mul_right.

      Lean, line 538
          have h3 : n * Nat.gcd b' a' * Nat.gcd b a ≤ b' * Nat.gcd b a := Nat.mul_le_mul_right _ hcon

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 538 at 841d05f96fd2 ↗

    8. R1b_dual_strict.h4 have a * b'.gcd a' < n * b.gcd a * b'.gcd a'

      Leaves False, with h4 : a * b'.gcd a' < n * b.gcd a * b'.gcd a'.

      Uses library Nat.gcd Computes the greatest common divisor of two natural numbers. , Nat.mul_lt_mul_of_pos_right.

      Lean, line 539
          have h4 : a * Nat.gcd b' a' < n * Nat.gcd b a * Nat.gcd b' a' := Nat.mul_lt_mul_of_pos_right h hg'

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 539 at 841d05f96fd2 ↗

  8. R1b_dual_set have ∀ (B : Finset ℕ) (n : ℕ), B.Nonempty → (0 : ℕ) ∉ B → (∀ a ∈ B, ∀ b ∈ B, a < n * a.gcd b) → (Finset.image (fun (a : ℕ) => B.lcm id / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => B.lcm id / a) B ∧ (Finset.image (fun (a : ℕ) => B.lcm id / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, a < n * a.gcd b

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R1b_dual_set : ∀ (B : Finset ℕ) (n : ℕ), B.Nonempty → (0 : ℕ) ∉ B → (∀ a ∈ B, ∀ b ∈ B, a < n * a.gcd b) → (Finset.image (fun (a : ℕ) => B.lcm id / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => B.lcm id / a) B ∧ (Finset.image (fun (a : ℕ) => B.lcm id / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, a < n * a.gcd b.

    Uses library Finset Finset α is the type of finite sets of elements of α. , Nat.gcd Computes the greatest common divisor of two natural numbers. , id The identity function. , And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. .

    Lean, lines 542–604
      have R1b_dual_set : ∀ (B : Finset ℕ) (n : ℕ) (hne : B.Nonempty) (h0 : 0 ∉ B) (hs : ∀ a ∈ B, ∀ b ∈ B, a < n * Nat.gcd a b),
          (B.image (fun a => B.lcm id / a)).card = B.card ∧ 0 ∉ B.image (fun a => B.lcm id / a) ∧ (B.image (fun a => B.lcm id / a)).gcd id = 1 ∧ ∀ a ∈ B.image (fun a => B.lcm id / a), ∀ b ∈ B.image (fun a => B.lcm id / a), a < n * Nat.gcd a b := by
        intro B n hne h0 hs
        set L := B.lcm id with hLdef
        have hdvd : ∀ a ∈ B, a ∣ L := fun a ha => Finset.dvd_lcm (f := id) ha
        have hL0 : L ≠ 0 := by
          intro h
          rw [hLdef, Finset.lcm_eq_zero_iff] at h
          simp at h
          exact h0 h
        have hLpos : 0 < L := Nat.pos_of_ne_zero hL0
        have hmul : ∀ a ∈ B, a * (L / a) = L := fun a ha => Nat.mul_div_cancel' (hdvd a ha)
        have hqpos : ∀ a ∈ B, 0 < L / a := by
          intro a ha
          rcases Nat.eq_zero_or_pos (L / a) with h | h
          · have := hmul a ha
            rw [h] at this
            simp at this
            exact absurd this.symm hL0
          · exact h
        have hapos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun e => h0 (e ▸ ha))
        refine ⟨?_, ?_, ?_, ?_⟩
        · apply Finset.card_image_of_injOn
          intro a ha b hb hab
          simp only at hab
          have e1 := hmul a ha
          have e2 := hmul b hb
          rw [hab] at e1
          have : a * (L / b) = b * (L / b) := by rw [e1, e2]
          exact Nat.eq_of_mul_eq_mul_right (hqpos b hb) this
        · intro h
          rw [Finset.mem_image] at h
          obtain ⟨a, ha, e⟩ := h
          have := hqpos a ha
          omega
        · set d := (B.image (fun a => L / a)).gcd id with hd
          have hdd : ∀ a ∈ B, d ∣ L / a := by
            intro a ha
            exact Finset.gcd_dvd (f := id) (Finset.mem_image_of_mem _ ha)
          obtain ⟨a0, ha0⟩ := hne
          have hdL : d ∣ L := (hdd a0 ha0).trans (Nat.div_dvd_of_dvd (hdvd a0 ha0))
          have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hdL hLpos
          have hall : ∀ a ∈ B, id a ∣ L / d := by
            intro a ha
            obtain ⟨k, hk⟩ := hdd a ha
            have e : L = d * (a * k) := by
              have := hmul a ha
              rw [hk] at this
              rw [← this]; ring
            have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos
            rw [this]; exact Dvd.intro _ rfl
          have hLdvd : L ∣ L / d := Finset.lcm_dvd hall
          have hpos' : 0 < L / d := Nat.div_pos (Nat.le_of_dvd hLpos hdL) hdpos
          have hle : L ≤ L / d := Nat.le_of_dvd hpos' hLdvd
          by_contra hne1
          have h2 : 2 ≤ d := by omega
          have := Nat.div_lt_self hLpos h2
          omega
        · intro x hx y hy
          rw [Finset.mem_image] at hx hy
          obtain ⟨a, ha, rfl⟩ := hx
          obtain ⟨b, hb, rfl⟩ := hy
          exact R1b_dual_strict L b (L / b) a (L / a) n (hmul b hb) (hmul a ha) hLpos (hs b hb a ha)

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 542–604 at 841d05f96fd2 ↗

    1. R1b_dual_set.hdvd have ∀ a ∈ B, a ∣ L

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hdvd : ∀ a ∈ B, a ∣ L.

      Uses library Finset.dvd_lcm, id The identity function. .

      Lean, line 546
          have hdvd : ∀ a ∈ B, a ∣ L := fun a ha => Finset.dvd_lcm (f := id) ha

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 546 at 841d05f96fd2 ↗

    2. R1b_dual_set.hL0 have L ≠ (0 : ℕ)

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hL0 : L ≠ (0 : ℕ).

      Uses library Finset.lcm_eq_zero_iff.

      Lean, lines 547–551
          have hL0 : L ≠ 0 := by
            intro h
            rw [hLdef, Finset.lcm_eq_zero_iff] at h
            simp at h
            exact h0 h

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 547–551 at 841d05f96fd2 ↗

    3. R1b_dual_set.hLpos have (0 : ℕ) < L

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hLpos : (0 : ℕ) < L.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 552
          have hLpos : 0 < L := Nat.pos_of_ne_zero hL0

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 552 at 841d05f96fd2 ↗

    4. R1b_dual_set.hmul have ∀ a ∈ B, a * (L / a) = L

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hmul : ∀ a ∈ B, a * (L / a) = L.

      Uses library Nat.mul_div_cancel'.

      Lean, line 553
          have hmul : ∀ a ∈ B, a * (L / a) = L := fun a ha => Nat.mul_div_cancel' (hdvd a ha)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 553 at 841d05f96fd2 ↗

    5. R1b_dual_set.hqpos have ∀ a ∈ B, (0 : ℕ) < L / a

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hqpos : ∀ a ∈ B, (0 : ℕ) < L / a.

      Uses library Nat.eq_zero_or_pos.

      Lean, lines 554–561
          have hqpos : ∀ a ∈ B, 0 < L / a := by
            intro a ha
            rcases Nat.eq_zero_or_pos (L / a) with h | h
            · have := hmul a ha
              rw [h] at this
              simp at this
              exact absurd this.symm hL0
            · exact h

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 554–561 at 841d05f96fd2 ↗

      1. R1b_dual_set.hqpos.s1 case

        Leaves (0 : ℕ) < L / a.

        Uses library absurd Anything follows from two contradictory hypotheses. .

        Lean, lines 557–560
              · have := hmul a ha
                rw [h] at this
                simp at this
                exact absurd this.symm hL0

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 557–560 at 841d05f96fd2 ↗

        1. R1b_dual_set.hqpos.s1.this have a * (L / a) = L

          Leaves (0 : ℕ) < L / a, with this : a * (L / a) = L.

          Lean, line 557
                · have := hmul a ha

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 557 at 841d05f96fd2 ↗

      2. R1b_dual_set.hqpos.s2 case
    6. R1b_dual_set.hapos have ∀ a ∈ B, (0 : ℕ) < a

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B ∧ (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b, with hapos : ∀ a ∈ B, (0 : ℕ) < a.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 562
          have hapos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun e => h0 (e ▸ ha))

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 562 at 841d05f96fd2 ↗

    7. R1b_dual_set.s7 case

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).card = B.card.

      Uses library Finset.card_image_of_injOn, Nat.eq_of_mul_eq_mul_right.

      Lean, lines 564–571
          · apply Finset.card_image_of_injOn
            intro a ha b hb hab
            simp only at hab
            have e1 := hmul a ha
            have e2 := hmul b hb
            rw [hab] at e1
            have : a * (L / b) = b * (L / b) := by rw [e1, e2]
            exact Nat.eq_of_mul_eq_mul_right (hqpos b hb) this

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 564–571 at 841d05f96fd2 ↗

      1. R1b_dual_set.s7.e1 have a * (L / a) = L
      2. R1b_dual_set.s7.e2 have b * (L / b) = L
      3. R1b_dual_set.s7.this have a * (L / b) = b * (L / b)

        Leaves a = b, with this : a * (L / b) = b * (L / b).

        Lean, line 570
              have : a * (L / b) = b * (L / b) := by rw [e1, e2]

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 570 at 841d05f96fd2 ↗

    8. R1b_dual_set.s8 case

      Leaves (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => L / a) B.

      Uses library Finset.mem_image.

      Lean, lines 572–576
          · intro h
            rw [Finset.mem_image] at h
            obtain ⟨a, ha, e⟩ := h
            have := hqpos a ha
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 572–576 at 841d05f96fd2 ↗

      1. R1b_dual_set.s8.s1 obtain ∃ a ∈ B, L / a = (0 : ℕ)

        Leaves False, with a : ℕ, ha : a ∈ B, e : L / a = (0 : ℕ).

        Lean, line 574
              obtain ⟨a, ha, e⟩ := h

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 574 at 841d05f96fd2 ↗

      2. R1b_dual_set.s8.this have (0 : ℕ) < L / a
    9. R1b_dual_set.s9 case

      Leaves (Finset.image (fun (a : ℕ) => L / a) B).gcd id = (1 : ℕ).

      Uses library id The identity function. .

      Lean, lines 577–599
          · set d := (B.image (fun a => L / a)).gcd id with hd
            have hdd : ∀ a ∈ B, d ∣ L / a := by
              intro a ha
              exact Finset.gcd_dvd (f := id) (Finset.mem_image_of_mem _ ha)
            obtain ⟨a0, ha0⟩ := hne
            have hdL : d ∣ L := (hdd a0 ha0).trans (Nat.div_dvd_of_dvd (hdvd a0 ha0))
            have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hdL hLpos
            have hall : ∀ a ∈ B, id a ∣ L / d := by
              intro a ha
              obtain ⟨k, hk⟩ := hdd a ha
              have e : L = d * (a * k) := by
                have := hmul a ha
                rw [hk] at this
                rw [← this]; ring
              have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos
              rw [this]; exact Dvd.intro _ rfl
            have hLdvd : L ∣ L / d := Finset.lcm_dvd hall
            have hpos' : 0 < L / d := Nat.div_pos (Nat.le_of_dvd hLpos hdL) hdpos
            have hle : L ≤ L / d := Nat.le_of_dvd hpos' hLdvd
            by_contra hne1
            have h2 : 2 ≤ d := by omega
            have := Nat.div_lt_self hLpos h2
            omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 577–599 at 841d05f96fd2 ↗

      1. R1b_dual_set.s9.hdd have ∀ a ∈ B, d ∣ L / a

        Leaves d = (1 : ℕ), with hdd : ∀ a ∈ B, d ∣ L / a.

        Uses library Finset.gcd_dvd, id The identity function. , Finset.mem_image_of_mem.

        Lean, lines 578–580
              have hdd : ∀ a ∈ B, d ∣ L / a := by
                intro a ha
                exact Finset.gcd_dvd (f := id) (Finset.mem_image_of_mem _ ha)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 578–580 at 841d05f96fd2 ↗

      2. R1b_dual_set.s9.s2 obtain B.Nonempty

        Leaves d = (1 : ℕ), with a0 : ℕ, ha0 : a0 ∈ B.

        Lean, line 581
              obtain ⟨a0, ha0⟩ := hne

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 581 at 841d05f96fd2 ↗

      3. R1b_dual_set.s9.hdL have d ∣ L

        Leaves d = (1 : ℕ), with hdL : d ∣ L.

        Uses library Nat.div_dvd_of_dvd.

        Lean, line 582
              have hdL : d ∣ L := (hdd a0 ha0).trans (Nat.div_dvd_of_dvd (hdvd a0 ha0))

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 582 at 841d05f96fd2 ↗

      4. R1b_dual_set.s9.hdpos have (0 : ℕ) < d

        Leaves d = (1 : ℕ), with hdpos : (0 : ℕ) < d.

        Uses library Nat.pos_of_dvd_of_pos.

        Lean, line 583
              have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hdL hLpos

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 583 at 841d05f96fd2 ↗

      5. R1b_dual_set.s9.hall have ∀ a ∈ B, id a ∣ L / d

        Leaves d = (1 : ℕ), with hall : ∀ a ∈ B, id a ∣ L / d.

        Uses library id The identity function. , Dvd.intro, rfl rfl : a = a is the unique constructor of the equality type. .

        Lean, lines 584–592
              have hall : ∀ a ∈ B, id a ∣ L / d := by
                intro a ha
                obtain ⟨k, hk⟩ := hdd a ha
                have e : L = d * (a * k) := by
                  have := hmul a ha
                  rw [hk] at this
                  rw [← this]; ring
                have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos
                rw [this]; exact Dvd.intro _ rfl

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 584–592 at 841d05f96fd2 ↗

        1. R1b_dual_set.s9.hall.s1 obtain d ∣ L / a

          Leaves id a ∣ L / d, with k : ℕ, hk : L / a = d * k.

          Lean, line 586
                  obtain ⟨k, hk⟩ := hdd a ha

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 586 at 841d05f96fd2 ↗

        2. R1b_dual_set.s9.hall.e have L = d * (a * k)

          Leaves id a ∣ L / d, with e : L = d * (a * k).

          Lean, lines 587–590
                  have e : L = d * (a * k) := by
                    have := hmul a ha
                    rw [hk] at this
                    rw [← this]; ring

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 587–590 at 841d05f96fd2 ↗

          1. R1b_dual_set.s9.hall.e.this have a * (L / a) = L
        3. R1b_dual_set.s9.hall.this have L / d = a * k

          Leaves id a ∣ L / d, with this : L / d = a * k.

          Uses library Nat.mul_div_cancel_left.

          Lean, line 591
                  have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 591 at 841d05f96fd2 ↗

      6. R1b_dual_set.s9.hLdvd have L ∣ L / d

        Leaves d = (1 : ℕ), with hLdvd : L ∣ L / d.

        Uses library Finset.lcm_dvd.

        Lean, line 593
              have hLdvd : L ∣ L / d := Finset.lcm_dvd hall

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 593 at 841d05f96fd2 ↗

      7. R1b_dual_set.s9.hpos' have (0 : ℕ) < L / d

        Leaves d = (1 : ℕ), with hpos' : (0 : ℕ) < L / d.

        Uses library Nat.div_pos, Nat.le_of_dvd.

        Lean, line 594
              have hpos' : 0 < L / d := Nat.div_pos (Nat.le_of_dvd hLpos hdL) hdpos

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 594 at 841d05f96fd2 ↗

      8. R1b_dual_set.s9.hle have L ≤ L / d

        Leaves d = (1 : ℕ), with hle : L ≤ L / d.

        Uses library Nat.le_of_dvd.

        Lean, line 595
              have hle : L ≤ L / d := Nat.le_of_dvd hpos' hLdvd

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 595 at 841d05f96fd2 ↗

      9. R1b_dual_set.s9.h2 have (2 : ℕ) ≤ d routine: omega
      10. R1b_dual_set.s9.this have L / d < L

        Leaves False, with this : L / d < L.

        Uses library Nat.div_lt_self.

        Lean, line 598
              have := Nat.div_lt_self hLpos h2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 598 at 841d05f96fd2 ↗

    10. R1b_dual_set.s10 case

      Leaves ∀ a ∈ Finset.image (fun (a : ℕ) => L / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => L / a) B, a < n * a.gcd b.

      Uses library Finset.mem_image.

      Lean, lines 600–604
          · intro x hx y hy
            rw [Finset.mem_image] at hx hy
            obtain ⟨a, ha, rfl⟩ := hx
            obtain ⟨b, hb, rfl⟩ := hy
            exact R1b_dual_strict L b (L / b) a (L / a) n (hmul b hb) (hmul a ha) hLpos (hs b hb a ha)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 600–604 at 841d05f96fd2 ↗

      1. R1b_dual_set.s10.s1 obtain ∃ a ∈ B, L / a = x

        Leaves L / a < n * (L / a).gcd y, with a : ℕ, ha : a ∈ B.

        Lean, line 602
              obtain ⟨a, ha, rfl⟩ := hx

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 602 at 841d05f96fd2 ↗

      2. R1b_dual_set.s10.s2 obtain ∃ a ∈ B, L / a = y

        Leaves L / a < n * (L / a).gcd (L / b), with b : ℕ, hb : b ∈ B.

        Lean, line 603
              obtain ⟨b, hb, rfl⟩ := hy

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 603 at 841d05f96fd2 ↗

  9. R2b_small have ∀ (n p : ℕ), Nat.Prime p → (2 : ℕ) * p < n → n ≤ (3 : ℕ) * p → ¬Nat.Prime n → (∀ (q : ℕ), Nat.Prime q → n ≠ q + (1 : ℕ)) → (3 : ℕ) ≤ p ∧ (9 : ℕ) ≤ n

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_small : ∀ (n p : ℕ), Nat.Prime p → (2 : ℕ) * p < n → n ≤ (3 : ℕ) * p → ¬Nat.Prime n → (∀ (q : ℕ), Nat.Prime q → n ≠ q + (1 : ℕ)) → (3 : ℕ) ≤ p ∧ (9 : ℕ) ≤ n.

    Uses library Nat.lt_or_ge.

    Lean, lines 605–621
      have R2b_small : ∀ (n p : ℕ) (hp : p.Prime) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (hnp : ¬ n.Prime) (hnp1 : ∀ q : ℕ, q.Prime → n ≠ q + 1),
          3 ≤ p ∧ 9 ≤ n := by
        intro n p hp h2p hn3 hnp hnp1
        have h2 := hp.two_le
        rcases Nat.lt_or_ge p 5 with h5 | h5
        · interval_cases p
          · exfalso
            interval_cases n
            · exact hnp (by norm_num)
            · exact hnp1 5 (by norm_num) rfl
          · refine ⟨le_refl _, ?_⟩
            interval_cases n
            · exact (hnp (by norm_num)).elim
            · exact (hnp1 7 (by norm_num) rfl).elim
            · exact le_refl _
          · exact absurd hp (by norm_num)
        · omega

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 605–621 at 841d05f96fd2 ↗

    1. R2b_small.h2 have (2 : ℕ) ≤ p

      Leaves (3 : ℕ) ≤ p ∧ (9 : ℕ) ≤ n, with h2 : (2 : ℕ) ≤ p.

      Lean, line 608
          have h2 := hp.two_le

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 608 at 841d05f96fd2 ↗

    2. R2b_small.s2 case

      Leaves (3 : ℕ) ≤ p ∧ (9 : ℕ) ≤ n.

      Lean, lines 610–620
          · interval_cases p
            · exfalso
              interval_cases n
              · exact hnp (by norm_num)
              · exact hnp1 5 (by norm_num) rfl
            · refine ⟨le_refl _, ?_⟩
              interval_cases n
              · exact (hnp (by norm_num)).elim
              · exact (hnp1 7 (by norm_num) rfl).elim
              · exact le_refl _
            · exact absurd hp (by norm_num)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 610–620 at 841d05f96fd2 ↗

      1. R2b_small.s2.s1 case

        Leaves (3 : ℕ) ≤ (2 : ℕ) ∧ (9 : ℕ) ≤ n.

        Lean, lines 611–614
              · exfalso
                interval_cases n
                · exact hnp (by norm_num)
                · exact hnp1 5 (by norm_num) rfl

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 611–614 at 841d05f96fd2 ↗

        1. R2b_small.s2.s1.s1 case
        2. R2b_small.s2.s1.s2 case

          Leaves False.

          Uses library rfl rfl : a = a is the unique constructor of the equality type. .

          Lean, line 614
                  · exact hnp1 5 (by norm_num) rfl

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 614 at 841d05f96fd2 ↗

      2. R2b_small.s2.s2 case

        Leaves (3 : ℕ) ≤ (3 : ℕ) ∧ (9 : ℕ) ≤ n.

        Uses library And.intro And.intro : a → b → a ∧ b is the constructor for the And operation. , le_refl The relation ≤ on a preorder is reflexive. .

        Lean, lines 615–619
              · refine ⟨le_refl _, ?_⟩
                interval_cases n
                · exact (hnp (by norm_num)).elim
                · exact (hnp1 7 (by norm_num) rfl).elim
                · exact le_refl _

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 615–619 at 841d05f96fd2 ↗

        1. R2b_small.s2.s2.s1 case
        2. R2b_small.s2.s2.s2 case

          Leaves (9 : ℕ) ≤ (8 : ℕ).

          Uses library rfl rfl : a = a is the unique constructor of the equality type. .

          Lean, line 618
                  · exact (hnp1 7 (by norm_num) rfl).elim

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 618 at 841d05f96fd2 ↗

        3. R2b_small.s2.s2.s3 case

          Leaves (9 : ℕ) ≤ (9 : ℕ).

          Uses library le_refl The relation ≤ on a preorder is reflexive. .

          Lean, line 619
                  · exact le_refl _

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 619 at 841d05f96fd2 ↗

      3. R2b_small.s2.s3 case

        Leaves (3 : ℕ) ≤ (4 : ℕ) ∧ (9 : ℕ) ≤ n.

        Uses library absurd Anything follows from two contradictory hypotheses. .

        Lean, line 620
              · exact absurd hp (by norm_num)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 620 at 841d05f96fd2 ↗

    3. R2b_small.s3 case routine: omega
  10. R2b_no_mid_prime have ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.gcd id = (1 : ℕ) → (∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) → ∀ (p : ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < B.card → B.card ≤ (3 : ℕ) * p → (9 : ℕ) ≤ B.card → ∀ a ∈ B, ¬p ∣ a

    Leaves ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.Nonempty → B.gcd id = (1 : ℕ) → ¬Nat.Prime B.card → (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) → (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) → (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) → (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a, with R2b_no_mid_prime : ∀ (B : Finset ℕ), (0 : ℕ) ∉ B → B.gcd id = (1 : ℕ) → (∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) → ∀ (p : ℕ), Nat.Prime p → (3 : ℕ) ≤ p → (2 : ℕ) * p < B.card → B.card ≤ (3 : ℕ) * p → (9 : ℕ) ≤ B.card → ∀ a ∈ B, ¬p ∣ a.

    Uses library Finset Finset α is the type of finite sets of elements of α. , id The identity function. .

    Lean, lines 622–678
      have R2b_no_mid_prime : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card),
          ∀ a ∈ B, ¬ p ∣ a := by
        intro B h0 hgcd hlt p hp hp3 h2p hn3 h9
        intro a0 ha0 hpa0
        obtain ⟨g, hg, hpg, huniq, hdvd⟩ := R2b_block B h0 hgcd hlt p hp hp3 h2p hn3 h9 ⟨a0, ha0, hpa0⟩
        obtain ⟨hcard, h0', hgcd', hlt'⟩ := R1b_dual_set B B.card ⟨a0, ha0⟩ h0 hlt
        have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
        have hL : B.lcm id ∣ 2 * p * g := Finset.lcm_dvd (fun a ha => hdvd a ha)
        have hLpos : 0 < B.lcm id :=
          Nat.pos_of_dvd_of_pos hL (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) (hpos g hg))
        have hmul : ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id :=
          fun a ha => Nat.mul_div_cancel' (Finset.dvd_lcm (f := id) ha)
        have hpLg : p ∣ B.lcm id / g := by
          have h1 : p ∣ g * (B.lcm id / g) := by
            rw [hmul g hg]; exact hpa0.trans (Finset.dvd_lcm (f := id) ha0)
          exact (hp.dvd_mul.mp h1).resolve_left hpg
        rw [← hcard] at hlt' h2p hn3 h9
        obtain ⟨g', hg', hpg', huniq', -⟩ := R2b_block _ h0' hgcd' hlt' p hp hp3 h2p hn3 h9
          ⟨_, Finset.mem_image_of_mem _ hg, hpLg⟩
        have h2 : 1 < (B.erase g).card := by
          rw [Finset.card_erase_of_mem hg, ← hcard]; omega
        obtain ⟨a1, ha1, a2, ha2, hne⟩ := Finset.one_lt_card.mp h2
        obtain ⟨hne1, ha1B⟩ := Finset.mem_erase.mp ha1
        obtain ⟨hne2, ha2B⟩ := Finset.mem_erase.mp ha2
        have hfin : ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False := by
          intro a ha hag hpLa
          have hpa : p ∣ a := by
            by_contra h
            exact hag (huniq a ha h)
          obtain ⟨c, hc⟩ := hpa
          obtain ⟨d, hd⟩ := hpLa
          have h3 : p * (p * (c * d)) ∣ p * (2 * g) := by
            have h4 : p * (p * (c * d)) = B.lcm id := by
              rw [← hmul a ha, hd]; rw [hc]; ring
            rw [h4]
            exact hL.trans (dvd_of_eq (by ring))
          have h5 : p ∣ 2 * g := (Dvd.intro _ rfl).trans (Nat.dvd_of_mul_dvd_mul_left hp.pos h3)
          rcases hp.dvd_mul.mp h5 with h6 | h6
          · have := Nat.le_of_dvd (by norm_num) h6
            omega
          · exact hpg h6
        by_cases hp1 : p ∣ B.lcm id / a1
        · exact hfin a1 ha1B hne1 hp1
        · by_cases hp2 : p ∣ B.lcm id / a2
          · exact hfin a2 ha2B hne2 hp2
          · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1
            have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2
            have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm
            have m1 := hmul a1 ha1B
            have m2 := hmul a2 ha2B
            rw [e3] at m1
            have hq : 0 < B.lcm id / a2 := by
              apply Nat.pos_of_ne_zero
              intro hz
              rw [hz, Nat.mul_zero] at m2
              omega
            exact hne (Nat.eq_of_mul_eq_mul_right hq (m1.trans m2.symm))

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 622–678 at 841d05f96fd2 ↗

    1. R2b_no_mid_prime.s1 obtain ∃ g ∈ B, ¬p ∣ g ∧ (∀ b ∈ B, ¬p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ (2 : ℕ) * p * g

      Leaves False, with g : ℕ, hg : g ∈ B, hpg : ¬p ∣ g, huniq : ∀ b ∈ B, ¬p ∣ b → b = g, hdvd : ∀ a ∈ B, a ∣ (2 : ℕ) * p * g.

      Uses library Exists.intro Existential introduction. .

      Lean, line 626
          obtain ⟨g, hg, hpg, huniq, hdvd⟩ := R2b_block B h0 hgcd hlt p hp hp3 h2p hn3 h9 ⟨a0, ha0, hpa0⟩

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 626 at 841d05f96fd2 ↗

    2. R2b_no_mid_prime.s2 obtain (Finset.image (fun (a : ℕ) => B.lcm id / a) B).card = B.card ∧ (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => B.lcm id / a) B ∧ (Finset.image (fun (a : ℕ) => B.lcm id / a) B).gcd id = (1 : ℕ) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, a < B.card * a.gcd b

      Leaves False, with hcard : (Finset.image (fun (a : ℕ) => B.lcm id / a) B).card = B.card, h0' : (0 : ℕ) ∉ Finset.image (fun (a : ℕ) => B.lcm id / a) B, hgcd' : (Finset.image (fun (a : ℕ) => B.lcm id / a) B).gcd id = (1 : ℕ), hlt' : ∀ a ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, a < B.card * a.gcd b.

      Uses library Exists.intro Existential introduction. .

      Lean, line 627
          obtain ⟨hcard, h0', hgcd', hlt'⟩ := R1b_dual_set B B.card ⟨a0, ha0⟩ h0 hlt

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 627 at 841d05f96fd2 ↗

    3. R2b_no_mid_prime.hpos have ∀ a ∈ B, (0 : ℕ) < a

      Leaves False, with hpos : ∀ a ∈ B, (0 : ℕ) < a.

      Uses library Nat.pos_of_ne_zero.

      Lean, line 628
          have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 628 at 841d05f96fd2 ↗

    4. R2b_no_mid_prime.hL have B.lcm id ∣ (2 : ℕ) * p * g

      Leaves False, with hL : B.lcm id ∣ (2 : ℕ) * p * g.

      Uses library id The identity function. , Finset.lcm_dvd.

      Lean, line 629
          have hL : B.lcm id ∣ 2 * p * g := Finset.lcm_dvd (fun a ha => hdvd a ha)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 629 at 841d05f96fd2 ↗

    5. R2b_no_mid_prime.hLpos have (0 : ℕ) < B.lcm id

      Leaves False, with hLpos : (0 : ℕ) < B.lcm id.

      Uses library id The identity function. , Nat.pos_of_dvd_of_pos, Nat.mul_pos.

      Lean, lines 630–631
          have hLpos : 0 < B.lcm id :=
            Nat.pos_of_dvd_of_pos hL (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) (hpos g hg))

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 630–631 at 841d05f96fd2 ↗

    6. R2b_no_mid_prime.hmul have ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id

      Leaves False, with hmul : ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id.

      Uses library id The identity function. , Nat.mul_div_cancel', Finset.dvd_lcm.

      Lean, lines 632–633
          have hmul : ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id :=
            fun a ha => Nat.mul_div_cancel' (Finset.dvd_lcm (f := id) ha)

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 632–633 at 841d05f96fd2 ↗

    7. R2b_no_mid_prime.hpLg have p ∣ B.lcm id / g

      Leaves False, with hpLg : p ∣ B.lcm id / g.

      Uses library id The identity function. .

      Lean, lines 634–637
          have hpLg : p ∣ B.lcm id / g := by
            have h1 : p ∣ g * (B.lcm id / g) := by
              rw [hmul g hg]; exact hpa0.trans (Finset.dvd_lcm (f := id) ha0)
            exact (hp.dvd_mul.mp h1).resolve_left hpg

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 634–637 at 841d05f96fd2 ↗

      1. R2b_no_mid_prime.hpLg.h1 have p ∣ g * (B.lcm id / g)

        Leaves p ∣ B.lcm id / g, with h1 : p ∣ g * (B.lcm id / g).

        Uses library id The identity function. , Finset.dvd_lcm.

        Lean, lines 635–636
              have h1 : p ∣ g * (B.lcm id / g) := by
                rw [hmul g hg]; exact hpa0.trans (Finset.dvd_lcm (f := id) ha0)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 635–636 at 841d05f96fd2 ↗

    8. R2b_no_mid_prime.s8 obtain ∃ g ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ¬p ∣ g ∧ (∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ¬p ∣ b → b = g) ∧ ∀ a ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, a ∣ (2 : ℕ) * p * g

      Leaves False, with g' : ℕ, hg' : g' ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, hpg' : ¬p ∣ g', huniq' : ∀ b ∈ Finset.image (fun (a : ℕ) => B.lcm id / a) B, ¬p ∣ b → b = g'.

      Uses library Exists.intro Existential introduction. , Finset.mem_image_of_mem.

      Lean, lines 639–640
          obtain ⟨g', hg', hpg', huniq', -⟩ := R2b_block _ h0' hgcd' hlt' p hp hp3 h2p hn3 h9
            ⟨_, Finset.mem_image_of_mem _ hg, hpLg⟩

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 639–640 at 841d05f96fd2 ↗

    9. R2b_no_mid_prime.h2 have (1 : ℕ) < (B.erase g).card

      Leaves False, with h2 : (1 : ℕ) < (B.erase g).card.

      Uses library Finset.card_erase_of_mem $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. .

      Lean, lines 641–642
          have h2 : 1 < (B.erase g).card := by
            rw [Finset.card_erase_of_mem hg, ← hcard]; omega

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 641–642 at 841d05f96fd2 ↗

    10. R2b_no_mid_prime.s10 obtain ∃ a ∈ B.erase g, ∃ b ∈ B.erase g, a ≠ b

      Leaves False, with a1 : ℕ, ha1 : a1 ∈ B.erase g, a2 : ℕ, ha2 : a2 ∈ B.erase g, hne : a1 ≠ a2.

      Uses library Finset.one_lt_card.

      Lean, line 643
          obtain ⟨a1, ha1, a2, ha2, hne⟩ := Finset.one_lt_card.mp h2

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 643 at 841d05f96fd2 ↗

    11. R2b_no_mid_prime.s11 obtain a1 ≠ g ∧ a1 ∈ B

      Leaves False, with hne1 : a1 ≠ g, ha1B : a1 ∈ B.

      Uses library Finset.mem_erase.

      Lean, line 644
          obtain ⟨hne1, ha1B⟩ := Finset.mem_erase.mp ha1

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 644 at 841d05f96fd2 ↗

    12. R2b_no_mid_prime.s12 obtain a2 ≠ g ∧ a2 ∈ B

      Leaves False, with hne2 : a2 ≠ g, ha2B : a2 ∈ B.

      Uses library Finset.mem_erase.

      Lean, line 645
          obtain ⟨hne2, ha2B⟩ := Finset.mem_erase.mp ha2

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 645 at 841d05f96fd2 ↗

    13. R2b_no_mid_prime.hfin have ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False

      Leaves False, with hfin : ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False.

      Uses library id The identity function. , False False is the empty proposition. .

      Lean, lines 646–662
          have hfin : ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False := by
            intro a ha hag hpLa
            have hpa : p ∣ a := by
              by_contra h
              exact hag (huniq a ha h)
            obtain ⟨c, hc⟩ := hpa
            obtain ⟨d, hd⟩ := hpLa
            have h3 : p * (p * (c * d)) ∣ p * (2 * g) := by
              have h4 : p * (p * (c * d)) = B.lcm id := by
                rw [← hmul a ha, hd]; rw [hc]; ring
              rw [h4]
              exact hL.trans (dvd_of_eq (by ring))
            have h5 : p ∣ 2 * g := (Dvd.intro _ rfl).trans (Nat.dvd_of_mul_dvd_mul_left hp.pos h3)
            rcases hp.dvd_mul.mp h5 with h6 | h6
            · have := Nat.le_of_dvd (by norm_num) h6
              omega
            · exact hpg h6

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 646–662 at 841d05f96fd2 ↗

      1. R2b_no_mid_prime.hfin.hpa have p ∣ a

        Leaves False, with hpa : p ∣ a.

        Lean, lines 648–650
              have hpa : p ∣ a := by
                by_contra h
                exact hag (huniq a ha h)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 648–650 at 841d05f96fd2 ↗

      2. R2b_no_mid_prime.hfin.s2 obtain p ∣ a
      3. R2b_no_mid_prime.hfin.s3 obtain p ∣ B.lcm id / a

        Leaves False, with d : ℕ, hd : B.lcm id / a = p * d.

        Lean, line 652
              obtain ⟨d, hd⟩ := hpLa

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 652 at 841d05f96fd2 ↗

      4. R2b_no_mid_prime.hfin.h3 have p * (p * (c * d)) ∣ p * ((2 : ℕ) * g)

        Leaves False, with h3 : p * (p * (c * d)) ∣ p * ((2 : ℕ) * g).

        Uses library dvd_of_eq.

        Lean, lines 653–657
              have h3 : p * (p * (c * d)) ∣ p * (2 * g) := by
                have h4 : p * (p * (c * d)) = B.lcm id := by
                  rw [← hmul a ha, hd]; rw [hc]; ring
                rw [h4]
                exact hL.trans (dvd_of_eq (by ring))

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 653–657 at 841d05f96fd2 ↗

        1. R2b_no_mid_prime.hfin.h3.h4 have p * (p * (c * d)) = B.lcm id

          Leaves p * (p * (c * d)) ∣ p * ((2 : ℕ) * g), with h4 : p * (p * (c * d)) = B.lcm id.

          Uses library id The identity function. .

          Lean, lines 654–655
                  have h4 : p * (p * (c * d)) = B.lcm id := by
                    rw [← hmul a ha, hd]; rw [hc]; ring

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 654–655 at 841d05f96fd2 ↗

      5. R2b_no_mid_prime.hfin.h5 have p ∣ (2 : ℕ) * g

        Leaves False, with h5 : p ∣ (2 : ℕ) * g.

        Uses library Dvd.intro, rfl rfl : a = a is the unique constructor of the equality type. , Nat.dvd_of_mul_dvd_mul_left.

        Lean, line 658
              have h5 : p ∣ 2 * g := (Dvd.intro _ rfl).trans (Nat.dvd_of_mul_dvd_mul_left hp.pos h3)

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 658 at 841d05f96fd2 ↗

      6. R2b_no_mid_prime.hfin.s6 case

        Leaves False.

        Lean, lines 660–661
              · have := Nat.le_of_dvd (by norm_num) h6
                omega

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 660–661 at 841d05f96fd2 ↗

        1. R2b_no_mid_prime.hfin.s6.this have p ≤ (2 : ℕ)

          Leaves False, with this : p ≤ (2 : ℕ).

          Uses library Nat.le_of_dvd.

          Lean, line 660
                · have := Nat.le_of_dvd (by norm_num) h6

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 660 at 841d05f96fd2 ↗

      7. R2b_no_mid_prime.hfin.s7 case
    14. R2b_no_mid_prime.s14 case
    15. R2b_no_mid_prime.s15 case

      Leaves False.

      Uses library id The identity function. .

      Lean, lines 665–678
          · by_cases hp2 : p ∣ B.lcm id / a2
            · exact hfin a2 ha2B hne2 hp2
            · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1
              have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2
              have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm
              have m1 := hmul a1 ha1B
              have m2 := hmul a2 ha2B
              rw [e3] at m1
              have hq : 0 < B.lcm id / a2 := by
                apply Nat.pos_of_ne_zero
                intro hz
                rw [hz, Nat.mul_zero] at m2
                omega
              exact hne (Nat.eq_of_mul_eq_mul_right hq (m1.trans m2.symm))

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 665–678 at 841d05f96fd2 ↗

      1. R2b_no_mid_prime.s15.s1 case
      2. R2b_no_mid_prime.s15.s2 case

        Leaves False.

        Uses library Nat.eq_of_mul_eq_mul_right.

        Lean, lines 667–678
              · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1
                have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2
                have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm
                have m1 := hmul a1 ha1B
                have m2 := hmul a2 ha2B
                rw [e3] at m1
                have hq : 0 < B.lcm id / a2 := by
                  apply Nat.pos_of_ne_zero
                  intro hz
                  rw [hz, Nat.mul_zero] at m2
                  omega
                exact hne (Nat.eq_of_mul_eq_mul_right hq (m1.trans m2.symm))

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 667–678 at 841d05f96fd2 ↗

        1. R2b_no_mid_prime.s15.s2.e1 have B.lcm id / a1 = g'

          Leaves False, with e1 : B.lcm id / a1 = g'.

          Uses library Finset.mem_image_of_mem.

          Lean, line 667
                · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 667 at 841d05f96fd2 ↗

        2. R2b_no_mid_prime.s15.s2.e2 have B.lcm id / a2 = g'

          Leaves False, with e2 : B.lcm id / a2 = g'.

          Uses library Finset.mem_image_of_mem.

          Lean, line 668
                  have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 668 at 841d05f96fd2 ↗

        3. R2b_no_mid_prime.s15.s2.e3 have B.lcm id / a1 = B.lcm id / a2

          Leaves False, with e3 : B.lcm id / a1 = B.lcm id / a2.

          Uses library id The identity function. .

          Lean, line 669
                  have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 669 at 841d05f96fd2 ↗

        4. R2b_no_mid_prime.s15.s2.m1 have a1 * (B.lcm id / a1) = B.lcm id

          Leaves False, with m1 : a1 * (B.lcm id / a1) = B.lcm id.

          Lean, line 670
                  have m1 := hmul a1 ha1B

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 670 at 841d05f96fd2 ↗

        5. R2b_no_mid_prime.s15.s2.m2 have a2 * (B.lcm id / a2) = B.lcm id

          Leaves False, with m2 : a2 * (B.lcm id / a2) = B.lcm id.

          Lean, line 671
                  have m2 := hmul a2 ha2B

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 671 at 841d05f96fd2 ↗

        6. R2b_no_mid_prime.s15.s2.hq have (0 : ℕ) < B.lcm id / a2

          Leaves False, with hq : (0 : ℕ) < B.lcm id / a2.

          Uses library id The identity function. , Nat.pos_of_ne_zero, Nat.mul_zero.

          Lean, lines 673–677
                  have hq : 0 < B.lcm id / a2 := by
                    apply Nat.pos_of_ne_zero
                    intro hz
                    rw [hz, Nat.mul_zero] at m2
                    omega

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 673–677 at 841d05f96fd2 ↗

  11. s11 case

    Leaves (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a.

    Uses library Or.inl Or.inl is "left injection" into an Or. .

    Lean, line 681
      · exact Or.inl h

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 681 at 841d05f96fd2 ↗

  12. s12 case

    Leaves (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a.

    Lean, lines 682–699
      · by_cases h2 : B.card ≤ 2 * p
        · exact Or.inr ⟨p, hp, h2, a, ha, hpa⟩
        · left
          by_contra hcon
          have hn : 0 < B.card := hne.card_pos
          have hnq : (0 : ℚ) < B.card := by exact_mod_cast hn
          have hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b := by
            intro a ha b hb
            rcases (hle a ha b hb).lt_or_eq with h | h
            · exact h
            · exfalso
              apply hcon
              refine ⟨a, ha, b, hb, ?_⟩
              rw [le_div_iff₀ hnq]
              have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
              exact_mod_cast h2
          obtain ⟨hp3, h9⟩ := R2b_small B.card p hp (by omega) hn3 hnp hnp1
          exact R2b_no_mid_prime B h0 hgcd hlt p hp hp3 (by omega) hn3 h9 a ha hpa

    targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 682–699 at 841d05f96fd2 ↗

    1. s12.s1 case

      Leaves (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a.

      Uses library Or.inr Or.inr is "right injection" into an Or. , Exists.intro Existential introduction. .

      Lean, line 683
          · exact Or.inr ⟨p, hp, h2, a, ha, hpa⟩

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 683 at 841d05f96fd2 ↗

    2. s12.s2 case

      Leaves (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨ ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a.

      Lean, lines 684–699
          · left
            by_contra hcon
            have hn : 0 < B.card := hne.card_pos
            have hnq : (0 : ℚ) < B.card := by exact_mod_cast hn
            have hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b := by
              intro a ha b hb
              rcases (hle a ha b hb).lt_or_eq with h | h
              · exact h
              · exfalso
                apply hcon
                refine ⟨a, ha, b, hb, ?_⟩
                rw [le_div_iff₀ hnq]
                have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
                exact_mod_cast h2
            obtain ⟨hp3, h9⟩ := R2b_small B.card p hp (by omega) hn3 hnp hnp1
            exact R2b_no_mid_prime B h0 hgcd hlt p hp hp3 (by omega) hn3 h9 a ha hpa

      targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 684–699 at 841d05f96fd2 ↗

      1. s12.s2.hn have (0 : ℕ) < B.card

        Leaves False, with hn : (0 : ℕ) < B.card.

        Lean, line 686
              have hn : 0 < B.card := hne.card_pos

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 686 at 841d05f96fd2 ↗

      2. s12.s2.hnq have (0 : ℚ) < (↑B.card : ℚ)

        Leaves False, with hnq : (0 : ℚ) < (↑B.card : ℚ).

        Lean, line 687
              have hnq : (0 : ℚ) < B.card := by exact_mod_cast hn

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 687 at 841d05f96fd2 ↗

      3. s12.s2.hlt have ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b

        Leaves False, with hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b.

        Lean, lines 688–697
              have hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b := by
                intro a ha b hb
                rcases (hle a ha b hb).lt_or_eq with h | h
                · exact h
                · exfalso
                  apply hcon
                  refine ⟨a, ha, b, hb, ?_⟩
                  rw [le_div_iff₀ hnq]
                  have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
                  exact_mod_cast h2

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 688–697 at 841d05f96fd2 ↗

        1. s12.s2.hlt.s1 case
        2. s12.s2.hlt.s2 case

          Leaves a < B.card * a.gcd b.

          Uses library Exists.intro Existential introduction. , le_div_iff₀ See le_div_iff₀' for a version with multiplication on the other side. .

          Lean, lines 692–697
                  · exfalso
                    apply hcon
                    refine ⟨a, ha, b, hb, ?_⟩
                    rw [le_div_iff₀ hnq]
                    have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
                    exact_mod_cast h2

          targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, lines 692–697 at 841d05f96fd2 ↗

          1. s12.s2.hlt.s2.h2 have a.gcd b * B.card ≤ a

            Leaves (↑(a.gcd b) : ℚ) * (↑B.card : ℚ) ≤ (↑a : ℚ), with h2 : a.gcd b * B.card ≤ a.

            Uses library Nat.mul_comm.

            Lean, line 696
                      have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge

            targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 696 at 841d05f96fd2 ↗

      4. s12.s2.s4 obtain (3 : ℕ) ≤ p ∧ (9 : ℕ) ≤ B.card

        Leaves False, with hp3 : (3 : ℕ) ≤ p, h9 : (9 : ℕ) ≤ B.card.

        Lean, line 698
              obtain ⟨hp3, h9⟩ := R2b_small B.card p hp (by omega) hn3 hnp hnp1

        targets/erdos-402/nodes/erdos-402--h3-v2--h1--h1/attempts/20261001T143056Z-t1001-402a-partial.lean, line 698 at 841d05f96fd2 ↗

import Mathlib
import Nodes.«erdos-402--h3-v2--h1--h1».Context

open Filter

/-! Hole `hsmooth` of a merged partial proof, as a node (D-12 #5, D-29).
Statement generated by the gate from the assembly; immutable (D-3). -/

theorem erdos_402__h3_v2__h1__h1 : ∀ (B : Finset ℕ),
  (0 : ℕ) ∉ B →
    B.Nonempty →
      B.gcd id = (1 : ℕ) →
        ¬Nat.Prime B.card →
          (∀ (q : ℕ), Nat.Prime q → B.card ≠ q + (1 : ℕ)) →
            (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
              (∀ a ∈ B, ∀ (p k : ℕ), Nat.Prime p → p ^ k ∣ a → p ^ k < B.card) →
                (∃ a ∈ B, ∃ b ∈ B, (↑(a.gcd b) : ℚ) ≤ (↑a : ℚ) / (↑B.card : ℚ)) ∨
                  ∃ (p : ℕ), Nat.Prime p ∧ B.card ≤ (2 : ℕ) * p ∧ ∃ a ∈ B, p ∣ a := by
  -- Informal argument and the Lean of each lemma: annex eb2314a2c5e64fe114b9093565a401979c6ef009436d2f021627b4d3d63663fd on erdos-402--h3-v2 (graph PR #340, agent 402-R2-b); dual set from agents 402-R1-b and 402-R2-c.
  -- Hole `hmid`: B has a pair with gcd(a, b) ≤ a / n, or an element with a prime factor p ≥ n / 3.
  -- The assembly proves: in a strict counterexample no prime p with 2p < n ≤ 3p divides an element
  -- (block lemma for k = 2, matching lemma for B = {2p} ∪ T, and the dual set for the other side).
  have hmid : ∀ B : Finset ℕ, 0 ∉ B → B.Nonempty → B.gcd id = 1 → ¬ B.card.Prime →
      (∀ q : ℕ, q.Prime → B.card ≠ q + 1) →
      (∀ a ∈ B, ∀ b ∈ B, a ≤ B.card * a.gcd b) →
      (∀ a ∈ B, ∀ p k : ℕ, p.Prime → p ^ k ∣ a → p ^ k < B.card) →
      (∃ a ∈ B, ∃ b ∈ B, (a.gcd b : ℚ) ≤ (a : ℚ) / (B.card : ℚ)) ∨
        ∃ p : ℕ, p.Prime ∧ B.card ≤ 3 * p ∧ ∃ a ∈ B, p ∣ a := sorry
  have R2b_lemI : ∀ (n p : ℕ) (T : Finset ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (h0 : ∀ b ∈ T, 0 < b) (hpT : ∀ b ∈ T, ¬ p ∣ b) (ho : ∀ b ∈ T, ¬ 2 ∣ b → b < n) (he : ∀ b ∈ T, 2 ∣ b → b < 2 * n) (hx : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → b < n * b.gcd t),
      T.card + 2 ≤ n := by
    intro n p T hp hp3 h2p hn3 h0 hpT ho he hx
    -- φ t = the unique t·2^j in [n/2, n-1]
    have hφ : ∀ b : ℕ, 0 < b → b < n →
        b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ n - 1 ∧ n - 1 < 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by
      intro b hb hbn
      have hne : (n - 1) / b ≠ 0 := by
        have : 0 < (n - 1) / b := Nat.div_pos (by omega) hb
        omega
      have h1 := Nat.pow_log_le_self 2 hne
      have h2 := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) ((n - 1) / b)
      have h3 : b * ((n - 1) / b) ≤ n - 1 := Nat.mul_div_le _ _
      have h4 : b * 2 ^ Nat.log 2 ((n - 1) / b) ≤ b * ((n - 1) / b) := Nat.mul_le_mul_left b h1
      have h5 : n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := (Nat.div_lt_iff_lt_mul hb).mp h2
      refine ⟨h4.trans h3, ?_⟩
      calc n - 1 < 2 ^ (Nat.log 2 ((n - 1) / b)).succ * b := h5
        _ = 2 * (b * 2 ^ Nat.log 2 ((n - 1) / b)) := by rw [pow_succ]; ring
    have hinj0 : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → j ≤ j' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
      intro b b' j j' hb hjj h
      obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le hjj
      have h1 : b * 2 ^ j = (b' * 2 ^ d) * 2 ^ j := by rw [h, pow_add]; ring
      have h2 : b = b' * 2 ^ d := Nat.eq_of_mul_eq_mul_right (by positivity) h1
      rcases Nat.eq_zero_or_pos d with hd | hd
      · rw [hd] at h2; simpa using h2
      · exfalso; apply hb; rw [h2]
        exact Dvd.dvd.mul_left (dvd_pow_self 2 (by omega)) _
    have hinj : ∀ b b' j j' : ℕ, ¬ 2 ∣ b → ¬ 2 ∣ b' → b * 2 ^ j = b' * 2 ^ j' → b = b' := by
      intro b b' j j' hb hb' h
      rcases le_total j j' with hjj | hjj
      · exact hinj0 b b' j j' hb hjj h
      · exact (hinj0 b' b j' j hb' hjj h.symm).symm
    -- coprimality of t with (t·m − 1)
    have hcop : ∀ t m w : ℕ, w + 1 = t * m → Nat.Coprime w t := by
      intro t m w h
      have h1 : Nat.Coprime w (w + 1) := by simp
      rw [h] at h1
      exact Nat.Coprime.coprime_mul_right_right h1
    set φ : ℕ → ℕ := fun b => b * 2 ^ Nat.log 2 ((n - 1) / b) with hφdef
    set g : ℕ → ℕ := fun b =>
      if 2 ∣ b then b / 2 else if b = 2 * p + 1 then 2 * p - 1
      else if 2 * (φ b - 1) < n then 0 else φ b - 1 with hgdef
    have hmaps : ∀ b ∈ T, g b ∈ insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p)) := by
      intro b hb
      have hb0 := h0 b hb
      have hpb := hpT b hb
      rw [Finset.mem_insert, Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
      simp only [hgdef]
      by_cases h2 : 2 ∣ b
      · rw [if_pos h2]
        right
        obtain ⟨c, rfl⟩ := h2
        have := he _ hb ⟨c, rfl⟩
        rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2)]
        refine ⟨?_, ?_, ?_, ?_⟩
        · rintro rfl; exact hpb ⟨4, by ring⟩
        · rintro rfl; exact hpb ⟨2, by ring⟩
        · omega
        · omega
      · rw [if_neg h2]
        by_cases h3 : b = 2 * p + 1
        · rw [if_pos h3]; right; omega
        · rw [if_neg h3]
          by_cases h4 : 2 * (φ b - 1) < n
          · rw [if_pos h4]; left; rfl
          · rw [if_neg h4]
            right
            have hb1 := hφ b hb0 (ho b hb h2)
            have hne : φ b ≠ 2 * p + 1 := by
              intro h
              have h5 : b * 2 ^ Nat.log 2 ((n - 1) / b) = (2 * p + 1) * 2 ^ 0 := by simpa using h
              exact h3 (hinj _ _ _ _ h2 (by omega) h5)
            change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
            omega
    have hginj : Set.InjOn g (T : Set ℕ) := by
      -- even / odd collision is impossible
      have hEO : ∀ b ∈ T, ∀ t ∈ T, 2 ∣ b → ¬ 2 ∣ t → g b = g t → False := by
        intro b hb t ht h2b h2t h
        have hb0 := h0 b hb
        have ht0 := h0 t ht
        have hx' := hx b hb t ht h2b h2t
        obtain ⟨c, rfl⟩ := h2b
        simp only [hgdef] at h
        rw [if_pos ⟨c, rfl⟩, if_neg h2t, Nat.mul_div_cancel_left c (by norm_num : 0 < 2)] at h
        by_cases h3 : t = 2 * p + 1
        · rw [if_pos h3] at h
          have hc : Nat.Coprime c t := by
            have h1 : Nat.Coprime c (2 + c) := by
              rw [Nat.coprime_add_self_right]
              rw [Nat.coprime_comm, Nat.Prime.coprime_iff_not_dvd Nat.prime_two]
              intro hd; omega
            have : 2 + c = t := by omega
            rwa [this] at h1
          have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
          have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
          rw [hg] at hx'
          omega
        · rw [if_neg h3] at h
          by_cases h4 : 2 * (φ t - 1) < n
          · rw [if_pos h4] at h; omega
          · rw [if_neg h4] at h
            have ht1 := hφ t ht0 (ho t ht h2t)
            change φ t ≤ n - 1 ∧ n - 1 < 2 * φ t at ht1
            have hc : Nat.Coprime c t := hcop t (2 ^ Nat.log 2 ((n - 1) / t)) c (by
              change c + 1 = φ t
              omega)
            have h2t' : Nat.Coprime 2 t := (Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2t
            have hg : (2 * c).gcd t = 1 := Nat.Coprime.mul_left h2t' hc
            rw [hg] at hx'
            omega
      intro b hb b' hb' h
      have hb0 := h0 b hb
      have hb0' := h0 b' hb'
      by_cases h2 : 2 ∣ b
      · by_cases h2' : 2 ∣ b'
        · simp only [hgdef] at h
          rw [if_pos h2, if_pos h2'] at h
          obtain ⟨c, rfl⟩ := h2
          obtain ⟨c', rfl⟩ := h2'
          rw [Nat.mul_div_cancel_left c (by norm_num : 0 < 2),
            Nat.mul_div_cancel_left c' (by norm_num : 0 < 2)] at h
          rw [h]
        · exact (hEO b hb b' hb' h2 h2' h).elim
      · by_cases h2' : 2 ∣ b'
        · exact (hEO b' hb' b hb h2' h2 h.symm).elim
        · -- both odd
          have hb1 := hφ b hb0 (ho b hb h2)
          have hb1' := hφ b' hb0' (ho b' hb' h2')
          change φ b ≤ n - 1 ∧ n - 1 < 2 * φ b at hb1
          change φ b' ≤ n - 1 ∧ n - 1 < 2 * φ b' at hb1'
          have hφinj : φ b = φ b' → b = b' := fun e => hinj _ _ _ _ h2 h2' e
          have h2p' : ∀ t ∈ T, ¬ 2 ∣ t → φ t ≠ 2 * p := by
            intro t ht h2t e
            have hd : p ∣ t * 2 ^ Nat.log 2 ((n - 1) / t) := ⟨2, by change φ t = p * 2; omega⟩
            rcases (Nat.Prime.dvd_mul hp).mp hd with h5 | h5
            · exact hpT t ht h5
            · have h6 := Nat.Prime.dvd_of_dvd_pow hp h5
              have h7 := Nat.le_of_dvd (by norm_num) h6
              omega
          have e1 := h2p' b hb h2
          have e2 := h2p' b' hb' h2'
          simp only [hgdef] at h
          rw [if_neg h2, if_neg h2'] at h
          by_cases h3 : b = 2 * p + 1 <;> by_cases h3' : b' = 2 * p + 1
          · rw [h3, h3']
          · rw [if_pos h3, if_neg h3'] at h
            by_cases h4 : 2 * (φ b' - 1) < n
            · rw [if_pos h4] at h; omega
            · rw [if_neg h4] at h; omega
          · rw [if_neg h3, if_pos h3'] at h
            by_cases h4 : 2 * (φ b - 1) < n
            · rw [if_pos h4] at h; omega
            · rw [if_neg h4] at h; omega
          · rw [if_neg h3, if_neg h3'] at h
            by_cases h4 : 2 * (φ b - 1) < n <;> by_cases h4' : 2 * (φ b' - 1) < n
            · exact hφinj (by omega)
            · rw [if_pos h4, if_neg h4'] at h; omega
            · rw [if_neg h4, if_pos h4'] at h; omega
            · rw [if_neg h4, if_neg h4'] at h; exact hφinj (by omega)
    have hcard : (insert 0 (((Finset.Ioo 0 n).erase p).erase (2 * p))).card = n - 2 := by
      rw [Finset.card_insert_of_notMem (by simp), Finset.card_erase_of_mem, Finset.card_erase_of_mem,
        Nat.card_Ioo]
      · omega
      · rw [Finset.mem_Ioo]; omega
      · rw [Finset.mem_erase, Finset.mem_Ioo]; omega
    have hle := Finset.card_le_card_of_injOn g hmaps hginj
    rw [hcard] at hle
    omega
  have R2b_K2half : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card) (hle : X.card ≤ S.card),
      ∀ x ∈ X, x = 1 := by
    intro n p X S hp0 h2p h9 hxs hX hS hcard hle
    have big : ∀ Y : Finset ℕ, (∀ x ∈ Y, 0 < x) → Y.Nonempty → ∃ x ∈ Y, Y.card ≤ x := by
      intro Y hpos hY
      by_contra h
      push Not at h
      have hsub : Y ⊆ Finset.Ioo 0 Y.card := by
        intro x hx
        exact Finset.mem_Ioo.mpr ⟨hpos x hx, h x hx⟩
      have h1 := Finset.card_le_card hsub
      rw [Nat.card_Ioo] at h1
      have h2 := hY.card_pos
      omega
    have hXpos : ∀ x ∈ X, 0 < x := by
      intro x hx
      obtain ⟨s, hs⟩ := hS
      obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
      apply Nat.pos_of_ne_zero
      rintro rfl
      rw [Nat.zero_mul] at h
      omega
    have hSpos : ∀ s ∈ S, 0 < s := by
      intro s hs
      obtain ⟨x, hx⟩ := hX
      obtain ⟨y, hy0, -, -, h⟩ := hxs x hx s hs
      apply Nat.pos_of_ne_zero
      rintro rfl
      rw [Nat.mul_zero] at h
      omega
    have hmul : ∀ u v : ℕ, 4 ≤ u → 5 ≤ v → 2 * u + 2 * v ≤ u * v := by
      intro u v hu hv
      obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hu
      obtain ⟨b, rfl⟩ := Nat.exists_eq_add_of_le hv
      nlinarith [Nat.zero_le (a * b)]
    obtain ⟨x0, hx0, hx0c⟩ := big X hXpos hX
    obtain ⟨s0, hs0, hs0c⟩ := big S hSpos hS
    have huv : X.card * S.card < 2 * n := by
      obtain ⟨y, -, hyn, -, h⟩ := hxs x0 hx0 s0 hs0
      have h2 : X.card * S.card ≤ x0 * s0 := Nat.mul_le_mul hx0c hs0c
      omega
    have hu2 : X.card ≤ 2 := by
      by_contra h
      push Not at h
      rcases Nat.lt_or_ge X.card 4 with h4 | h4
      · have h3 : X.card = 3 := by omega
        rw [h3] at huv hcard
        omega
      · have := hmul X.card S.card h4 (by omega)
        omega
    intro x hx
    by_contra hx1
    have hxpos := hXpos x hx
    rcases Nat.lt_or_ge x 3 with h3 | h3
    · have hx2 : x = 2 := by omega
      subst hx2
      have hsub : S ⊆ ((Finset.Ioo 0 n).erase p).erase (2 * p) := by
        intro s hs
        obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs 2 hx s hs
        have hsy : s = y := by omega
        subst hsy
        rw [Finset.mem_erase, Finset.mem_erase, Finset.mem_Ioo]
        refine ⟨?_, ?_, hy0, hyn⟩
        · rintro rfl; exact hpy ⟨2, by ring⟩
        · rintro rfl; exact hpy ⟨1, by ring⟩
      have h1 := Finset.card_le_card hsub
      rw [Finset.card_erase_of_mem (by
          rw [Finset.mem_erase, Finset.mem_Ioo]; omega),
        Finset.card_erase_of_mem (by rw [Finset.mem_Ioo]; omega), Nat.card_Ioo] at h1
      omega
    · have hsub : S ⊆ Finset.Icc 1 (2 * (n - 1) / 3) := by
        intro s hs
        obtain ⟨y, hy0, hyn, hpy, h⟩ := hxs x hx s hs
        have h4 : 3 * s ≤ x * s := Nat.mul_le_mul_right s h3
        rw [Finset.mem_Icc]
        exact ⟨hSpos s hs, by omega⟩
      have h1 := Finset.card_le_card hsub
      rw [Nat.card_Icc] at h1
      omega
  have R2b_K2 : ∀ (n p : ℕ) (X S : Finset ℕ) (hp0 : 0 < p) (h2p : 2 * p < n) (h9 : 9 ≤ n) (hxs : ∀ x ∈ X, ∀ s ∈ S, ∃ y, 0 < y ∧ y < n ∧ ¬ p ∣ y ∧ (x * s = 2 * y ∨ (x * s = y ∧ ¬ 2 ∣ y))) (hX : X.Nonempty) (hS : S.Nonempty) (hcard : n ≤ X.card + S.card),
      (∀ x ∈ X, x = 1) ∨ (∀ s ∈ S, s = 1) := by
    intro n p X S hp0 h2p h9 hxs hX hS hcard
    rcases le_total X.card S.card with h | h
    · exact Or.inl (R2b_K2half n p X S hp0 h2p h9 hxs hX hS hcard h)
    · refine Or.inr (R2b_K2half n p S X hp0 h2p h9 ?_ hS hX (by omega) h)
      intro s hs x hx
      rw [Nat.mul_comm]
      exact hxs x hx s hs
  have R2b_block : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card) (hex : ∃ a ∈ B, p ∣ a),
      ∃ g ∈ B, ¬ p ∣ g ∧ (∀ b ∈ B, ¬ p ∣ b → b = g) ∧ ∀ a ∈ B, a ∣ 2 * p * g := by
    intro B h0 hgcd hlt p hp hp3 h2p hn3 h9 hex
    obtain ⟨a0, ha0, hpa0⟩ := hex
    have hexb : ∃ b ∈ B, ¬ p ∣ b := by
      by_contra h
      push Not at h
      have h1 : p ∣ B.gcd id := Finset.dvd_gcd (fun b hb => h b hb)
      rw [hgcd] at h1
      exact hp.one_lt.ne' (Nat.dvd_one.mp h1)
    obtain ⟨b0, hb0, hpb0⟩ := hexb
    have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
    -- the pair analysis: a = g·x, b = g·y, x ∈ {p, 2p}
    have hA : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b → ∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
        b = a.gcd b * y ∧ (a = p * a.gcd b ∨ (a = 2 * p * a.gcd b ∧ ¬ 2 ∣ y)) := by
      intro a ha hpa b hb hpb
      have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b (hpos a ha)
      obtain ⟨x, hx⟩ := Nat.gcd_dvd_left a b
      obtain ⟨y, hy⟩ := Nat.gcd_dvd_right a b
      have hpg : ¬ p ∣ a.gcd b := fun h => hpb (h.trans (Nat.gcd_dvd_right a b))
      have hpx : p ∣ x := by
        have h1 : p ∣ a.gcd b * x := hx ▸ hpa
        exact (hp.dvd_mul.mp h1).resolve_left hpg
      obtain ⟨t, ht⟩ := hpx
      have hxn : x < B.card := by
        have h3 : a.gcd b * x < a.gcd b * B.card := by
          rw [← hx, Nat.mul_comm]; exact hlt a ha b hb
        exact Nat.lt_of_mul_lt_mul_left h3
      have hyn : y < B.card := by
        have h3 : a.gcd b * y < a.gcd b * B.card := by
          rw [← hy, Nat.mul_comm, Nat.gcd_comm]; exact hlt b hb a ha
        exact Nat.lt_of_mul_lt_mul_left h3
      have hx0 : x ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at hx
        exact (hpos a ha).ne' hx
      have hy0 : y ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at hy
        exact (hpos b hb).ne' hy
      have hpy : ¬ p ∣ y := fun h => hpb (hy ▸ Dvd.dvd.mul_left h _)
      have hcop : Nat.Coprime x y := by
        have h1 := Nat.coprime_div_gcd_div_gcd hg0
        have e1 : a / a.gcd b = x := Nat.div_eq_of_eq_mul_right hg0 hx
        have e2 : b / a.gcd b = y := Nat.div_eq_of_eq_mul_right hg0 hy
        rwa [e1, e2] at h1
      have ht0 : t ≠ 0 := by
        rintro rfl
        rw [Nat.mul_zero] at ht
        exact hx0 ht
      have ht3 : t < 3 := by
        by_contra h
        push Not at h
        have h4 : p * 3 ≤ p * t := Nat.mul_le_mul_left p h
        omega
      refine ⟨y, Nat.pos_of_ne_zero hy0, hyn, hpy, hy, ?_⟩
      rcases (by omega : t = 1 ∨ t = 2) with rfl | rfl
      · left
        calc a = a.gcd b * x := hx
          _ = p * a.gcd b := by rw [ht]; ring
      · right
        refine ⟨(calc a = a.gcd b * x := hx
          _ = 2 * p * a.gcd b := by rw [ht]; ring), ?_⟩
        intro h2y
        have h2x : 2 ∣ x := ⟨p, by rw [ht]; ring⟩
        have := Nat.Coprime.eq_one_of_dvd (Nat.Coprime.coprime_dvd_left h2x hcop) h2y
        omega
    have hG0 : (B.filter (fun b => ¬ p ∣ b)).gcd id ≠ 0 := by
      intro h
      have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ id b0 :=
        Finset.gcd_dvd (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)
      rw [h] at h1
      exact hpb0 (by rw [show b0 = 0 from Nat.eq_zero_of_zero_dvd h1]; exact dvd_zero p)
    have hGb : ∀ b ∈ B, ¬ p ∣ b → (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ b := by
      intro b hb hpb
      exact Finset.gcd_dvd (f := id) (Finset.mem_filter.mpr ⟨hb, hpb⟩)
    have hdiv : ∀ a ∈ B, p ∣ a → a ∣ 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
      intro a ha hpa
      have h1 : a ∣ (B.filter (fun b => ¬ p ∣ b)).gcd (fun b => (2 * p) * id b) := by
        apply Finset.dvd_gcd
        intro b hb
        obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
        obtain ⟨y, -, -, -, hy, h⟩ := hA a ha hpa b hbB hpb
        have h2 : a ∣ 2 * p * a.gcd b := by
          rcases h with h | ⟨h, -⟩
          · exact ⟨2, by linarith⟩
          · exact ⟨1, by linarith⟩
        exact h2.trans (Nat.mul_dvd_mul_left _ (Nat.gcd_dvd_right a b))
      rw [Finset.gcd_mul_left] at h1
      simpa using h1
    have hprod : ∀ a ∈ B, p ∣ a → ∀ b ∈ B, ¬ p ∣ b →
        (∃ y, 0 < y ∧ y < B.card ∧ ¬ p ∣ y ∧
          ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = 2 * y ∨
           ((2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) * (b / (B.filter (fun b => ¬ p ∣ b)).gcd id) = y ∧ ¬ 2 ∣ y))) ∧
        a * (2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a) = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
      intro a ha hpa b hb hpb
      have hd := hdiv a ha hpa
      have hGb' := hGb b hb hpb
      generalize (B.filter (fun b => ¬ p ∣ b)).gcd id = G at *
      obtain ⟨e, he⟩ := hd
      obtain ⟨s, hs⟩ := hGb'
      obtain ⟨y, hy0, hyn, hpy, hy, h⟩ := hA a ha hpa b hb hpb
      have ha0' := hpos a ha
      have hg0 : 0 < a.gcd b := Nat.gcd_pos_of_pos_left b ha0'
      have hx : 2 * p * G / a = e := by rw [he]; exact Nat.mul_div_cancel_left e ha0'
      have ht : b / G = s := by
        rw [hs]; exact Nat.mul_div_cancel_left s (Nat.pos_of_ne_zero hG0)
      rw [hx, ht]
      have hmain : a * (e * s) = 2 * p * (a.gcd b * y) := by
        calc a * (e * s) = (a * e) * s := by ring
          _ = 2 * p * (G * s) := by rw [← he]; ring
          _ = 2 * p * (a.gcd b * y) := by rw [← hs, ← hy]
      refine ⟨⟨y, hy0, hyn, hpy, ?_⟩, he.symm⟩
      rcases h with h | ⟨h, h2y⟩
      · left
        have h5 : p * a.gcd b * (e * s) = p * a.gcd b * (2 * y) := by
          calc p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
            _ = 2 * p * (a.gcd b * y) := hmain
            _ = p * a.gcd b * (2 * y) := by ring
        exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos hp.pos hg0) h5
      · right
        refine ⟨?_, h2y⟩
        have h5 : 2 * p * a.gcd b * (e * s) = 2 * p * a.gcd b * y := by
          calc 2 * p * a.gcd b * (e * s) = a * (e * s) := by rw [← h]
            _ = 2 * p * (a.gcd b * y) := hmain
            _ = 2 * p * a.gcd b * y := by ring
        exact Nat.eq_of_mul_eq_mul_left (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) hg0) h5
    have hcardsum : (B.filter (fun a => p ∣ a)).card + (B.filter (fun b => ¬ p ∣ b)).card = B.card := by
      rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter_filter_not B B (fun a => p ∣ a)),
        Finset.filter_union_filter_not_eq]
    have hinjX : Set.InjOn (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a)
        (B.filter (fun a => p ∣ a) : Finset ℕ) := by
      intro a ha a' ha' h
      obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
      obtain ⟨haB', hpa'⟩ := Finset.mem_filter.mp ha'
      have h1 := (hprod a haB hpa b0 hb0 hpb0).2
      have h2 := (hprod a' haB' hpa' b0 hb0 hpb0).2
      simp only at h
      rw [← h] at h2
      have hq : 0 < 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a := by
        apply Nat.pos_of_ne_zero
        intro hz
        rw [hz, Nat.mul_zero] at h1
        have := Nat.mul_pos (Nat.mul_pos (by norm_num : 0 < 2) hp.pos) (Nat.pos_of_ne_zero hG0)
        omega
      exact Nat.eq_of_mul_eq_mul_right hq (h1.trans h2.symm)
    have hinjT : Set.InjOn (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id)
        (B.filter (fun b => ¬ p ∣ b) : Finset ℕ) := by
      intro b hb b' hb' h
      obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
      obtain ⟨hbB', hpb'⟩ := Finset.mem_filter.mp hb'
      simp only at h
      rw [← Nat.div_mul_cancel (hGb b hbB hpb), ← Nat.div_mul_cancel (hGb b' hbB' hpb'), h]
    have hK := R2b_K2 B.card p
      ((B.filter (fun a => p ∣ a)).image (fun a => 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id / a))
      ((B.filter (fun b => ¬ p ∣ b)).image (fun b => b / (B.filter (fun b => ¬ p ∣ b)).gcd id))
      hp.pos h2p h9
      (by
        intro x hx t ht
        obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hx
        obtain ⟨b, hb, rfl⟩ := Finset.mem_image.mp ht
        obtain ⟨haB, hpa⟩ := Finset.mem_filter.mp ha
        obtain ⟨hbB, hpb⟩ := Finset.mem_filter.mp hb
        exact (hprod a haB hpa b hbB hpb).1)
      ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha0, hpa0⟩)⟩
      ⟨_, Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb0, hpb0⟩)⟩
      (by rw [Finset.card_image_of_injOn hinjX, Finset.card_image_of_injOn hinjT, hcardsum])
    rcases hK with hX1 | hS1
    · -- every multiple of p equals 2pG, G = 1: B = {2p} ∪ T, impossible by Lemma I
      exfalso
      have hall : ∀ a ∈ B, p ∣ a → a = 2 * p * (B.filter (fun b => ¬ p ∣ b)).gcd id := by
        intro a ha hpa
        have h1 := hX1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨ha, hpa⟩))
        have h2 := (hprod a ha hpa b0 hb0 hpb0).2
        rw [h1, Nat.mul_one] at h2
        exact h2
      have hG1 : (B.filter (fun b => ¬ p ∣ b)).gcd id = 1 := by
        have h1 : (B.filter (fun b => ¬ p ∣ b)).gcd id ∣ B.gcd id := by
          apply Finset.dvd_gcd
          intro b hb
          by_cases hpb : p ∣ b
          · exact ⟨2 * p, by rw [id, hall b hb hpb]; ring⟩
          · exact hGb b hb hpb
        rw [hgcd] at h1
        exact Nat.dvd_one.mp h1
      rw [hG1, Nat.mul_one] at hall
      have h2pB : 2 * p ∈ B := by rw [← hall a0 ha0 hpa0]; exact ha0
      have hT : ∀ b ∈ B.erase (2 * p), b ∈ B ∧ ¬ p ∣ b := by
        intro b hb
        obtain ⟨hne, hbB⟩ := Finset.mem_erase.mp hb
        exact ⟨hbB, fun h => hne (hall b hbB h)⟩
      have hbound : ∀ b ∈ B.erase (2 * p), b < B.card * b.gcd 2 := by
        intro b hb
        obtain ⟨hbB, hpb⟩ := hT b hb
        have h1 := hlt b hbB (2 * p) h2pB
        have hc : Nat.Coprime p b := (Nat.Prime.coprime_iff_not_dvd hp).mpr hpb
        rwa [Nat.Coprime.gcd_mul_right_cancel_right 2 hc] at h1
      have hI := R2b_lemI B.card p (B.erase (2 * p)) hp hp3 h2p hn3
        (fun b hb => hpos b (hT b hb).1) (fun b hb => (hT b hb).2)
        (by
          intro b hb h2
          have h1 := hbound b hb
          have hc : Nat.Coprime b 2 :=
            Nat.Coprime.symm ((Nat.Prime.coprime_iff_not_dvd Nat.prime_two).mpr h2)
          rw [Nat.Coprime.gcd_eq_one hc] at h1
          omega)
        (by
          intro b hb _
          have h1 := hbound b hb
          have h3 : b.gcd 2 ≤ 2 := Nat.gcd_le_right b (by norm_num)
          have h4 : B.card * b.gcd 2 ≤ B.card * 2 := Nat.mul_le_mul_left _ h3
          omega)
        (fun b hb t ht _ _ => hlt b (hT b hb).1 t (hT t ht).1)
      rw [Finset.card_erase_of_mem h2pB] at hI
      omega
    · -- every non-multiple equals G
      have hall : ∀ b ∈ B, ¬ p ∣ b → b = (B.filter (fun b => ¬ p ∣ b)).gcd id := by
        intro b hb hpb
        have h1 := hS1 _ (Finset.mem_image_of_mem _ (Finset.mem_filter.mpr ⟨hb, hpb⟩))
        have h2 := Nat.div_mul_cancel (hGb b hb hpb)
        rw [h1, Nat.one_mul] at h2
        exact h2.symm
      have hb0G := hall b0 hb0 hpb0
      refine ⟨b0, hb0, hpb0, ?_, ?_⟩
      · intro b hb hpb
        rw [hall b hb hpb, ← hb0G]
      · intro a ha
        by_cases hpa : p ∣ a
        · rw [hb0G]; exact hdiv a ha hpa
        · rw [hall a ha hpa, ← hb0G]; exact Dvd.intro_left _ rfl
  have R1b_dual_quot : ∀ (L a a' b b' : ℕ) (ha : a * a' = L) (hb : b * b' = L) (h0 : 0 < a),
      a' * Nat.gcd a b = b * Nat.gcd a' b' := by
    intro L a a' b b' ha hb h0
    have h1 : Nat.gcd a' b' * (a * b) = L * Nat.gcd a b := by
      rw [← Nat.gcd_mul_right]
      have e1 : a' * (a * b) = L * b := by rw [← ha]; ring
      have e2 : b' * (a * b) = L * a := by rw [← hb]; ring
      rw [e1, e2, Nat.gcd_mul_left, Nat.gcd_comm b a]
    have h2 : a * (a' * Nat.gcd a b) = a * (b * Nat.gcd a' b') := by
      rw [← mul_assoc, ha, ← h1]; ring
    exact Nat.eq_of_mul_eq_mul_left h0 h2
  have R1b_dual_strict : ∀ (L a a' b b' n : ℕ) (ha : a * a' = L) (hb : b * b' = L) (hL : 0 < L) (h : a < n * Nat.gcd a b),
      b' < n * Nat.gcd b' a' := by
    intro L a a' b b' n ha hb hL h
    have hb0 : 0 < b := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
    have hb'0 : 0 < b' := Nat.pos_of_ne_zero (by rintro rfl; simp at hb; omega)
    have ha0 : 0 < a := Nat.pos_of_ne_zero (by rintro rfl; simp at ha; omega)
    have e := R1b_dual_quot L b b' a a' hb ha hb0
    have hg : 0 < Nat.gcd b a := Nat.gcd_pos_of_pos_left _ hb0
    have hg' : 0 < Nat.gcd b' a' := Nat.gcd_pos_of_pos_left _ hb'0
    rw [Nat.gcd_comm a b] at h
    by_contra hcon
    push Not at hcon
    have h3 : n * Nat.gcd b' a' * Nat.gcd b a ≤ b' * Nat.gcd b a := Nat.mul_le_mul_right _ hcon
    have h4 : a * Nat.gcd b' a' < n * Nat.gcd b a * Nat.gcd b' a' := Nat.mul_lt_mul_of_pos_right h hg'
    rw [e] at h3
    nlinarith
  have R1b_dual_set : ∀ (B : Finset ℕ) (n : ℕ) (hne : B.Nonempty) (h0 : 0 ∉ B) (hs : ∀ a ∈ B, ∀ b ∈ B, a < n * Nat.gcd a b),
      (B.image (fun a => B.lcm id / a)).card = B.card ∧ 0 ∉ B.image (fun a => B.lcm id / a) ∧ (B.image (fun a => B.lcm id / a)).gcd id = 1 ∧ ∀ a ∈ B.image (fun a => B.lcm id / a), ∀ b ∈ B.image (fun a => B.lcm id / a), a < n * Nat.gcd a b := by
    intro B n hne h0 hs
    set L := B.lcm id with hLdef
    have hdvd : ∀ a ∈ B, a ∣ L := fun a ha => Finset.dvd_lcm (f := id) ha
    have hL0 : L ≠ 0 := by
      intro h
      rw [hLdef, Finset.lcm_eq_zero_iff] at h
      simp at h
      exact h0 h
    have hLpos : 0 < L := Nat.pos_of_ne_zero hL0
    have hmul : ∀ a ∈ B, a * (L / a) = L := fun a ha => Nat.mul_div_cancel' (hdvd a ha)
    have hqpos : ∀ a ∈ B, 0 < L / a := by
      intro a ha
      rcases Nat.eq_zero_or_pos (L / a) with h | h
      · have := hmul a ha
        rw [h] at this
        simp at this
        exact absurd this.symm hL0
      · exact h
    have hapos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun e => h0 (e ▸ ha))
    refine ⟨?_, ?_, ?_, ?_⟩
    · apply Finset.card_image_of_injOn
      intro a ha b hb hab
      simp only at hab
      have e1 := hmul a ha
      have e2 := hmul b hb
      rw [hab] at e1
      have : a * (L / b) = b * (L / b) := by rw [e1, e2]
      exact Nat.eq_of_mul_eq_mul_right (hqpos b hb) this
    · intro h
      rw [Finset.mem_image] at h
      obtain ⟨a, ha, e⟩ := h
      have := hqpos a ha
      omega
    · set d := (B.image (fun a => L / a)).gcd id with hd
      have hdd : ∀ a ∈ B, d ∣ L / a := by
        intro a ha
        exact Finset.gcd_dvd (f := id) (Finset.mem_image_of_mem _ ha)
      obtain ⟨a0, ha0⟩ := hne
      have hdL : d ∣ L := (hdd a0 ha0).trans (Nat.div_dvd_of_dvd (hdvd a0 ha0))
      have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hdL hLpos
      have hall : ∀ a ∈ B, id a ∣ L / d := by
        intro a ha
        obtain ⟨k, hk⟩ := hdd a ha
        have e : L = d * (a * k) := by
          have := hmul a ha
          rw [hk] at this
          rw [← this]; ring
        have : L / d = a * k := by rw [e]; exact Nat.mul_div_cancel_left _ hdpos
        rw [this]; exact Dvd.intro _ rfl
      have hLdvd : L ∣ L / d := Finset.lcm_dvd hall
      have hpos' : 0 < L / d := Nat.div_pos (Nat.le_of_dvd hLpos hdL) hdpos
      have hle : L ≤ L / d := Nat.le_of_dvd hpos' hLdvd
      by_contra hne1
      have h2 : 2 ≤ d := by omega
      have := Nat.div_lt_self hLpos h2
      omega
    · intro x hx y hy
      rw [Finset.mem_image] at hx hy
      obtain ⟨a, ha, rfl⟩ := hx
      obtain ⟨b, hb, rfl⟩ := hy
      exact R1b_dual_strict L b (L / b) a (L / a) n (hmul b hb) (hmul a ha) hLpos (hs b hb a ha)
  have R2b_small : ∀ (n p : ℕ) (hp : p.Prime) (h2p : 2 * p < n) (hn3 : n ≤ 3 * p) (hnp : ¬ n.Prime) (hnp1 : ∀ q : ℕ, q.Prime → n ≠ q + 1),
      3 ≤ p ∧ 9 ≤ n := by
    intro n p hp h2p hn3 hnp hnp1
    have h2 := hp.two_le
    rcases Nat.lt_or_ge p 5 with h5 | h5
    · interval_cases p
      · exfalso
        interval_cases n
        · exact hnp (by norm_num)
        · exact hnp1 5 (by norm_num) rfl
      · refine ⟨le_refl _, ?_⟩
        interval_cases n
        · exact (hnp (by norm_num)).elim
        · exact (hnp1 7 (by norm_num) rfl).elim
        · exact le_refl _
      · exact absurd hp (by norm_num)
    · omega
  have R2b_no_mid_prime : ∀ (B : Finset ℕ) (h0 : 0 ∉ B) (hgcd : B.gcd id = 1) (hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b) (p : ℕ) (hp : p.Prime) (hp3 : 3 ≤ p) (h2p : 2 * p < B.card) (hn3 : B.card ≤ 3 * p) (h9 : 9 ≤ B.card),
      ∀ a ∈ B, ¬ p ∣ a := by
    intro B h0 hgcd hlt p hp hp3 h2p hn3 h9
    intro a0 ha0 hpa0
    obtain ⟨g, hg, hpg, huniq, hdvd⟩ := R2b_block B h0 hgcd hlt p hp hp3 h2p hn3 h9 ⟨a0, ha0, hpa0⟩
    obtain ⟨hcard, h0', hgcd', hlt'⟩ := R1b_dual_set B B.card ⟨a0, ha0⟩ h0 hlt
    have hpos : ∀ a ∈ B, 0 < a := fun a ha => Nat.pos_of_ne_zero (fun h => h0 (h ▸ ha))
    have hL : B.lcm id ∣ 2 * p * g := Finset.lcm_dvd (fun a ha => hdvd a ha)
    have hLpos : 0 < B.lcm id :=
      Nat.pos_of_dvd_of_pos hL (Nat.mul_pos (Nat.mul_pos (by norm_num) hp.pos) (hpos g hg))
    have hmul : ∀ a ∈ B, a * (B.lcm id / a) = B.lcm id :=
      fun a ha => Nat.mul_div_cancel' (Finset.dvd_lcm (f := id) ha)
    have hpLg : p ∣ B.lcm id / g := by
      have h1 : p ∣ g * (B.lcm id / g) := by
        rw [hmul g hg]; exact hpa0.trans (Finset.dvd_lcm (f := id) ha0)
      exact (hp.dvd_mul.mp h1).resolve_left hpg
    rw [← hcard] at hlt' h2p hn3 h9
    obtain ⟨g', hg', hpg', huniq', -⟩ := R2b_block _ h0' hgcd' hlt' p hp hp3 h2p hn3 h9
      ⟨_, Finset.mem_image_of_mem _ hg, hpLg⟩
    have h2 : 1 < (B.erase g).card := by
      rw [Finset.card_erase_of_mem hg, ← hcard]; omega
    obtain ⟨a1, ha1, a2, ha2, hne⟩ := Finset.one_lt_card.mp h2
    obtain ⟨hne1, ha1B⟩ := Finset.mem_erase.mp ha1
    obtain ⟨hne2, ha2B⟩ := Finset.mem_erase.mp ha2
    have hfin : ∀ a ∈ B, a ≠ g → p ∣ B.lcm id / a → False := by
      intro a ha hag hpLa
      have hpa : p ∣ a := by
        by_contra h
        exact hag (huniq a ha h)
      obtain ⟨c, hc⟩ := hpa
      obtain ⟨d, hd⟩ := hpLa
      have h3 : p * (p * (c * d)) ∣ p * (2 * g) := by
        have h4 : p * (p * (c * d)) = B.lcm id := by
          rw [← hmul a ha, hd]; rw [hc]; ring
        rw [h4]
        exact hL.trans (dvd_of_eq (by ring))
      have h5 : p ∣ 2 * g := (Dvd.intro _ rfl).trans (Nat.dvd_of_mul_dvd_mul_left hp.pos h3)
      rcases hp.dvd_mul.mp h5 with h6 | h6
      · have := Nat.le_of_dvd (by norm_num) h6
        omega
      · exact hpg h6
    by_cases hp1 : p ∣ B.lcm id / a1
    · exact hfin a1 ha1B hne1 hp1
    · by_cases hp2 : p ∣ B.lcm id / a2
      · exact hfin a2 ha2B hne2 hp2
      · have e1 := huniq' _ (Finset.mem_image_of_mem _ ha1B) hp1
        have e2 := huniq' _ (Finset.mem_image_of_mem _ ha2B) hp2
        have e3 : B.lcm id / a1 = B.lcm id / a2 := e1.trans e2.symm
        have m1 := hmul a1 ha1B
        have m2 := hmul a2 ha2B
        rw [e3] at m1
        have hq : 0 < B.lcm id / a2 := by
          apply Nat.pos_of_ne_zero
          intro hz
          rw [hz, Nat.mul_zero] at m2
          omega
        exact hne (Nat.eq_of_mul_eq_mul_right hq (m1.trans m2.symm))
  intro B h0 hne hgcd hnp hnp1 hle hpp
  rcases hmid B h0 hne hgcd hnp hnp1 hle hpp with h | ⟨p, hp, hn3, a, ha, hpa⟩
  · exact Or.inl h
  · by_cases h2 : B.card ≤ 2 * p
    · exact Or.inr ⟨p, hp, h2, a, ha, hpa⟩
    · left
      by_contra hcon
      have hn : 0 < B.card := hne.card_pos
      have hnq : (0 : ℚ) < B.card := by exact_mod_cast hn
      have hlt : ∀ a ∈ B, ∀ b ∈ B, a < B.card * a.gcd b := by
        intro a ha b hb
        rcases (hle a ha b hb).lt_or_eq with h | h
        · exact h
        · exfalso
          apply hcon
          refine ⟨a, ha, b, hb, ?_⟩
          rw [le_div_iff₀ hnq]
          have h2 : a.gcd b * B.card ≤ a := by rw [Nat.mul_comm]; exact h.ge
          exact_mod_cast h2
      obtain ⟨hp3, h9⟩ := R2b_small B.card p hp (by omega) hn3 hnp hnp1
      exact R2b_no_mid_prime B h0 hgcd hlt p hp hp3 (by omega) hn3 h9 a ha hpa
How to read this page

No explainer yet. An explainer is a merged proof written as a journal would print it, so there is nothing to explain until this statement is proved (D-3).

How to read a statement’s page →