Theorem: Nat.minSqFacAux_has_prop
File: Mathlib/Data/Nat/Squarefree.lean

tactic: rw [minSqFacAux]
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
⊢ MinSqFacProp n (minSqFacAux n k)

tactic: by_cases h : n < k * k <;> simp [h]
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
⊢ MinSqFacProp n
    (if h : n < k * k then none
    else
      let_fun this := (_ : sqrt n - k < sqrt n + 2 - k);
      if k ∣ n then
        let n' := n / k;
        let_fun this := (_ : sqrt n' - k < sqrt n + 2 - k);
        if k ∣ n' then some k else minSqFacAux n' (k + 2)
      else minSqFacAux n (k + 2))

tactic: have k2 : 2 ≤ k := by
  subst e
  linarith
state_before: case neg
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
⊢ MinSqFacProp n (if k ∣ n then if k ∣ n / k then some k else minSqFacAux (n / k) (k + 2) else minSqFacAux n (k + 2))

tactic: have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
state_before: case neg
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
⊢ MinSqFacProp n (if k ∣ n then if k ∣ n / k then some k else minSqFacAux (n / k) (k + 2) else minSqFacAux n (k + 2))

tactic: have pk : k ∣ n → Prime k := by
  refine' fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) _⟩
  exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
state_before: case neg
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
⊢ MinSqFacProp n (if k ∣ n then if k ∣ n / k then some k else minSqFacAux (n / k) (k + 2) else minSqFacAux n (k + 2))

tactic: split_ifs with dk dkk
state_before: case neg
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
pk : k ∣ n → Prime k
⊢ MinSqFacProp n (if k ∣ n then if k ∣ n / k then some k else minSqFacAux (n / k) (k + 2) else minSqFacAux n (k + 2))

tactic: refine' squarefree_iff_prime_squarefree.2 fun p pp d => _
state_before: case pos
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : n < k * k
⊢ MinSqFacProp n none

tactic: have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
state_before: case pos
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : n < k * k
p : ℕ
pp : Prime p
d : p * p ∣ n
⊢ False

tactic: have := Nat.mul_le_mul this this
state_before: case pos
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : n < k * k
p : ℕ
pp : Prime p
d : p * p ∣ n
this : k ≤ p
⊢ False

tactic: exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
state_before: case pos
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : n < k * k
p : ℕ
pp : Prime p
d : p * p ∣ n
this✝ : k ≤ p
this : k * k ≤ p * p
⊢ False

tactic: subst e
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
⊢ 2 ≤ k

tactic: linarith
state_before: n : ℕ
n0 : 0 < n
i : ℕ
ih : ∀ (m : ℕ), Prime m → m ∣ n → 2 * i + 3 ≤ m
h : ¬n < (2 * i + 3) * (2 * i + 3)
⊢ 2 ≤ 2 * i + 3

tactic: decide
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
⊢ 0 < 2

tactic: intro n' nd' nk
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
⊢ ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))

tactic: have hn' := le_of_dvd n0 nd'
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
⊢ MinSqFacProp n' (minSqFacAux n' (k + 2))

tactic: refine'
  have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=
    lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)
  @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
    (by simp [e, left_distrib]) fun m m2 d => _
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
⊢ MinSqFacProp n' (minSqFacAux n' (k + 2))

tactic: cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : m ∣ n'
⊢ k + 2 ≤ m

tactic: apply (Nat.eq_or_lt_of_le ml).resolve_left
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : m ∣ n'
ml : k < m
⊢ k + 2 ≤ m

tactic: intro me
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : m ∣ n'
ml : k < m
⊢ ¬succ k = m

tactic: rw [← me, e] at d
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : m ∣ n'
ml : k < m
me : succ k = m
⊢ False

tactic: change 2 * (i + 2) ∣ n' at d
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : succ (2 * i + 3) ∣ n'
ml : k < m
me : succ k = m
⊢ False

tactic: have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
ml : k < m
me : succ k = m
d : 2 * (i + 2) ∣ n'
⊢ False

tactic: rw [e] at this
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this✝ : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
ml : k < m
me : succ k = m
d : 2 * (i + 2) ∣ n'
this : k ≤ 2
⊢ False

tactic: exact absurd this (by linarith)
state_before: case inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this✝ : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
ml : k < m
me : succ k = m
d : 2 * (i + 2) ∣ n'
this : 2 * i + 3 ≤ 2
⊢ False

tactic: simp [e, left_distrib]
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
⊢ k + 2 = 2 * (i + 1) + 3

tactic: subst me
state_before: case inl
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
d : m ∣ n'
me : k = m
⊢ k + 2 ≤ m

tactic: contradiction
state_before: case inl
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this : sqrt n' - k < sqrt n + 2 - k
m2 : Prime k
d : k ∣ n'
⊢ k + 2 ≤ k

tactic: linarith
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
n' : ℕ
nd' : n' ∣ n
nk : ¬k ∣ n'
hn' : n' ≤ n
this✝ : sqrt n' - k < sqrt n + 2 - k
m : ℕ
m2 : Prime m
ml : k < m
me : succ k = m
d : 2 * (i + 2) ∣ n'
this : 2 * i + 3 ≤ 2
⊢ ¬2 * i + 3 ≤ 2

tactic: refine' fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) _⟩
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
⊢ k ∣ n → Prime k

tactic: exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
state_before: n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
dk : k ∣ n
⊢ k ≤ minFac k

tactic: exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩
state_before: case neg.inl.inl
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
pk : k ∣ n → Prime k
dk : k ∣ n
dkk : k ∣ n / k
⊢ MinSqFacProp n (some k)

tactic: specialize IH (n / k) (div_dvd_of_dvd dk) dkk
state_before: case neg.inl.inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
pk : k ∣ n → Prime k
dk : k ∣ n
dkk : ¬k ∣ n / k
⊢ MinSqFacProp n (minSqFacAux (n / k) (k + 2))

tactic: exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
state_before: case neg.inl.inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
pk : k ∣ n → Prime k
dk : k ∣ n
dkk : ¬k ∣ n / k
IH : MinSqFacProp (n / k) (minSqFacAux (n / k) (k + 2))
⊢ MinSqFacProp n (minSqFacAux (n / k) (k + 2))

tactic: exact IH n (dvd_refl _) dk
state_before: case neg.inr
n k : ℕ
n0 : 0 < n
i : ℕ
e : k = 2 * i + 3
ih : ∀ (m : ℕ), Prime m → m ∣ n → k ≤ m
h : ¬n < k * k
k2 : 2 ≤ k
k0 : 0 < k
IH : ∀ (n' : ℕ), n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (minSqFacAux n' (k + 2))
pk : k ∣ n → Prime k
dk : ¬k ∣ n
⊢ MinSqFacProp n (minSqFacAux n (k + 2))