l3lab/ntp-mathlib huggingface dataset:
/-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`,
then it sends this supremum to the supremum of the image of `s`. -/
theorem Monotone.map_csSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
    (Mf : Monotone f) (ne : s.Nonempty) (H : BddAbove s) : f (sSup s) = sSup (f '' s) := by
  

Proof state:
α : Type u
β : Type v
γ : Type w
inst✝⁶ : ConditionallyCompleteLinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : ConditionallyCompleteLinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderClosedTopology β
inst✝ : Nonempty γ
f : α → β
s : Set α
Cf : ContinuousAt f (sSup s)
Mf : Monotone f
ne : Set.Nonempty s
H : BddAbove s
⊢ f (sSup s) = sSup (f '' s)

Next tactic:
refine' ((isLUB_csSup (ne.image f) (Mf.map_bddAbove H)).unique _).symm
/-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`,
then it sends this supremum to the supremum of the image of `s`. -/
theorem Monotone.map_csSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
    (Mf : Monotone f) (ne : s.Nonempty) (H : BddAbove s) : f (sSup s) = sSup (f '' s) := by
  refine' ((isLUB_csSup (ne.image f) (Mf.map_bddAbove H)).unique _).symm
  

Proof state:
α : Type u
β : Type v
γ : Type w
inst✝⁶ : ConditionallyCompleteLinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : ConditionallyCompleteLinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderClosedTopology β
inst✝ : Nonempty γ
f : α → β
s : Set α
Cf : ContinuousAt f (sSup s)
Mf : Monotone f
ne : Set.Nonempty s
H : BddAbove s
⊢ IsLUB (f '' s) (f (sSup s))

Next tactic:
refine' (isLUB_csSup ne H).isLUB_of_tendsto (fun x _ y _ xy => Mf xy) ne _
/-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`,
then it sends this supremum to the supremum of the image of `s`. -/
theorem Monotone.map_csSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
    (Mf : Monotone f) (ne : s.Nonempty) (H : BddAbove s) : f (sSup s) = sSup (f '' s) := by
  refine' ((isLUB_csSup (ne.image f) (Mf.map_bddAbove H)).unique _).symm
  refine' (isLUB_csSup ne H).isLUB_of_tendsto (fun x _ y _ xy => Mf xy) ne _
  

Proof state:
α : Type u
β : Type v
γ : Type w
inst✝⁶ : ConditionallyCompleteLinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : ConditionallyCompleteLinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderClosedTopology β
inst✝ : Nonempty γ
f : α → β
s : Set α
Cf : ContinuousAt f (sSup s)
Mf : Monotone f
ne : Set.Nonempty s
H : BddAbove s
⊢ Tendsto f (𝓝[s] sSup s) (𝓝 (f (sSup s)))

Next tactic:
exact Cf.mono_left inf_le_left
/-- If a monotone function is continuous at the indexed supremum of a bounded function on
a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/
theorem Monotone.map_ciSup_of_continuousAt {f : α → β} {g : γ → α} (Cf : ContinuousAt f (⨆ i, g i))
    (Mf : Monotone f) (H : BddAbove (range g)) : f (⨆ i, g i) = ⨆ i, f (g i) := by
  

Proof state:
α : Type u
β : Type v
γ : Type w
inst✝⁶ : ConditionallyCompleteLinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : ConditionallyCompleteLinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderClosedTopology β
inst✝ : Nonempty γ
f : α → β
g : γ → α
Cf : ContinuousAt f (⨆ i, g i)
Mf : Monotone f
H : BddAbove (range g)
⊢ f (⨆ i, g i) = ⨆ i, f (g i)

Next tactic:
rw [iSup, Mf.map_csSup_of_continuousAt Cf (range_nonempty _) H, ← range_comp, iSup]
/-- If a monotone function is continuous at the indexed supremum of a bounded function on
a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/
theorem Monotone.map_ciSup_of_continuousAt {f : α → β} {g : γ → α} (Cf : ContinuousAt f (⨆ i, g i))
    (Mf : Monotone f) (H : BddAbove (range g)) : f (⨆ i, g i) = ⨆ i, f (g i) := by
  rw [iSup, Mf.map_csSup_of_continuousAt Cf (range_nonempty _) H, ← range_comp, iSup]; 

Proof state:
α : Type u
β : Type v
γ : Type w
inst✝⁶ : ConditionallyCompleteLinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : ConditionallyCompleteLinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderClosedTopology β
inst✝ : Nonempty γ
f : α → β
g : γ → α
Cf : ContinuousAt f (⨆ i, g i)
Mf : Monotone f
H : BddAbove (range g)
⊢ sSup (range (f ∘ fun i => g i)) = sSup (range fun i => f (g i))

Next tactic:
rfl
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  

Proof state:
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
⊢ Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x)))

Next tactic:
rcases eq_empty_or_nonempty (Iio x) with (h | h)
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · 

Proof state:
case inl
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Iio x = ∅
⊢ Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x)))

Next tactic:
simp [h]
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  

Proof state:
case inr
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
⊢ Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x)))

Next tactic:
refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
  · 

Proof state:
case inr.refine'_1
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
l : β
hl : l < sSup (f '' Iio x)
⊢ ∀ᶠ (b : α) in 𝓝[<] x, l < f b

Next tactic:
obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
      simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
        exists_lt_of_lt_csSup (nonempty_image_iff.2 h) hl
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
  · obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
      

Proof state:
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
l : β
hl : l < sSup (f '' Iio x)
⊢ ∃ a < x, l < f a

Next tactic:
simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
        exists_lt_of_lt_csSup (nonempty_image_iff.2 h) hl
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
  · obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
      simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
        exists_lt_of_lt_csSup (nonempty_image_iff.2 h) hl
    

Proof state:
case inr.refine'_1.intro.intro
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
l : β
hl : l < sSup (f '' Iio x)
z : α
zx : z < x
lz : l < f z
⊢ ∀ᶠ (b : α) in 𝓝[<] x, l < f b

Next tactic:
exact mem_of_superset (Ioo_mem_nhdsWithin_Iio' zx) fun y hy => lz.trans_le (Mf hy.1.le)
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
  · obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
      simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
        exists_lt_of_lt_csSup (nonempty_image_iff.2 h) hl
    exact mem_of_superset (Ioo_mem_nhdsWithin_Iio' zx) fun y hy => lz.trans_le (Mf hy.1.le)
  · 

Proof state:
case inr.refine'_2
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
m : β
hm : m > sSup (f '' Iio x)
⊢ ∀ᶠ (b : α) in 𝓝[<] x, f b < m

Next tactic:
refine mem_of_superset self_mem_nhdsWithin fun _ hy => lt_of_le_of_lt ?_ hm
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsWithin_Iio {α β : Type*} [LinearOrder α] [TopologicalSpace α]
    [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
    {f : α → β} (Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
  rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
  refine' tendsto_order.2 ⟨fun l hl => _, fun m hm => _⟩
  · obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
      simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
        exists_lt_of_lt_csSup (nonempty_image_iff.2 h) hl
    exact mem_of_superset (Ioo_mem_nhdsWithin_Iio' zx) fun y hy => lz.trans_le (Mf hy.1.le)
  · refine mem_of_superset self_mem_nhdsWithin fun _ hy => lt_of_le_of_lt ?_ hm
    

Proof state:
case inr.refine'_2
α✝ : Type u
β✝ : Type v
γ : Type w
inst✝¹² : ConditionallyCompleteLinearOrder α✝
inst✝¹¹ : TopologicalSpace α✝
inst✝¹⁰ : OrderTopology α✝
inst✝⁹ : ConditionallyCompleteLinearOrder β✝
inst✝⁸ : TopologicalSpace β✝
inst✝⁷ : OrderClosedTopology β✝
inst✝⁶ : Nonempty γ
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : ConditionallyCompleteLinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
Mf : Monotone f
x : α
h : Set.Nonempty (Iio x)
m : β
hm : m > sSup (f '' Iio x)
x✝ : α
hy : x✝ ∈ Iio x
⊢ f x✝ ≤ sSup (f '' Iio x)

Next tactic:
exact le_csSup (Mf.map_bddAbove bddAbove_Iio) (mem_image_of_mem _ hy)
/--
Tail recursive function which returns the largest `k : ℕ` such that `p ^ k ∣ n` for any `p : ℕ`.
`padicValNat_eq_maxPowDiv` allows the code generator to use this definition for `padicValNat`
-/
def maxPowDiv (p n : ℕ) : ℕ :=
  go 0 p n
where go (k p n : ℕ) : ℕ :=
  if h : 1 < p ∧ 0 < n ∧ n % p = 0 then
    have : n / p < n := by 

Proof state:
p✝ n✝ k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ n / p < n

Next tactic:
apply Nat.div_lt_self
/--
Tail recursive function which returns the largest `k : ℕ` such that `p ^ k ∣ n` for any `p : ℕ`.
`padicValNat_eq_maxPowDiv` allows the code generator to use this definition for `padicValNat`
-/
def maxPowDiv (p n : ℕ) : ℕ :=
  go 0 p n
where go (k p n : ℕ) : ℕ :=
  if h : 1 < p ∧ 0 < n ∧ n % p = 0 then
    have : n / p < n := by apply Nat.div_lt_self <;> 

Proof state:
case hLtN
p✝ n✝ k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ 0 < n

Next tactic:
aesop
/--
Tail recursive function which returns the largest `k : ℕ` such that `p ^ k ∣ n` for any `p : ℕ`.
`padicValNat_eq_maxPowDiv` allows the code generator to use this definition for `padicValNat`
-/
def maxPowDiv (p n : ℕ) : ℕ :=
  go 0 p n
where go (k p n : ℕ) : ℕ :=
  if h : 1 < p ∧ 0 < n ∧ n % p = 0 then
    have : n / p < n := by apply Nat.div_lt_self <;> 

Proof state:
case hLtK
p✝ n✝ k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ 1 < p

Next tactic:
aesop
theorem go_eq {k p n : ℕ} :
    go k p n = if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k+1) p (n / p) else k := by
  

Proof state:
k p n : ℕ
⊢ go k p n = if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k

Next tactic:
dsimp [go, go._unary]
theorem go_eq {k p n : ℕ} :
    go k p n = if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k+1) p (n / p) else k := by
  dsimp [go, go._unary]
  

Proof state:
k p n : ℕ
⊢ WellFounded.fix go._unary.proof_1
      (fun _x a =>
        if h : 1 < _x.snd.fst ∧ 0 < _x.snd.snd ∧ _x.snd.snd % _x.snd.fst = 0 then
          a { fst := _x.fst + 1, snd := { fst := _x.snd.fst, snd := _x.snd.snd / _x.snd.fst } }
            (_ : _x.snd.snd / _x.snd.fst < _x.snd.snd)
        else _x.fst)
      { fst := k, snd := { fst := p, snd := n } } =
    if 1 < p ∧ 0 < n ∧ n % p = 0 then
      WellFounded.fix go._unary.proof_1
        (fun _x a =>
          if h : 1 < _x.snd.fst ∧ 0 < _x.snd.snd ∧ _x.snd.snd % _x.snd.fst = 0 then
            a { fst := _x.fst + 1, snd := { fst := _x.snd.fst, snd := _x.snd.snd / _x.snd.fst } }
              (_ : _x.snd.snd / _x.snd.fst < _x.snd.snd)
          else _x.fst)
        { fst := k + 1, snd := { fst := p, snd := n / p } }
    else k

Next tactic:
rw [WellFounded.fix_eq]
theorem go_eq {k p n : ℕ} :
    go k p n = if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k+1) p (n / p) else k := by
  dsimp [go, go._unary]
  rw [WellFounded.fix_eq]
  

Proof state:
k p n : ℕ
⊢ (if h :
        1 < { fst := k, snd := { fst := p, snd := n } }.snd.fst ∧
          0 < { fst := k, snd := { fst := p, snd := n } }.snd.snd ∧
            { fst := k, snd := { fst := p, snd := n } }.snd.snd % { fst := k, snd := { fst := p, snd := n } }.snd.fst =
              0 then
      (fun y x =>
          WellFounded.fix go._unary.proof_1
            (fun _x a =>
              if h : 1 < _x.snd.fst ∧ 0 < _x.snd.snd ∧ _x.snd.snd % _x.snd.fst = 0 then
                a { fst := _x.fst + 1, snd := { fst := _x.snd.fst, snd := _x.snd.snd / _x.snd.fst } }
                  (_ : _x.snd.snd / _x.snd.fst < _x.snd.snd)
              else _x.fst)
            y)
        { fst := { fst := k, snd := { fst := p, snd := n } }.fst + 1,
          snd :=
            { fst := { fst := k, snd := { fst := p, snd := n } }.snd.fst,
              snd :=
                { fst := k, snd := { fst := p, snd := n } }.snd.snd /
                  { fst := k, snd := { fst := p, snd := n } }.snd.fst } }
        (_ :
          { fst := k, snd := { fst := p, snd := n } }.snd.snd / { fst := k, snd := { fst := p, snd := n } }.snd.fst <
            { fst := k, snd := { fst := p, snd := n } }.snd.snd)
    else { fst := k, snd := { fst := p, snd := n } }.fst) =
    if 1 < p ∧ 0 < n ∧ n % p = 0 then
      WellFounded.fix go._unary.proof_1
        (fun _x a =>
          if h : 1 < _x.snd.fst ∧ 0 < _x.snd.snd ∧ _x.snd.snd % _x.snd.fst = 0 then
            a { fst := _x.fst + 1, snd := { fst := _x.snd.fst, snd := _x.snd.snd / _x.snd.fst } }
              (_ : _x.snd.snd / _x.snd.fst < _x.snd.snd)
          else _x.fst)
        { fst := k + 1, snd := { fst := p, snd := n / p } }
    else k

Next tactic:
simp
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  

Proof state:
k p n : ℕ
⊢ go (k + 1) p n = go k p n + 1

Next tactic:
rw [go_eq]
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  

Proof state:
k p n : ℕ
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) = go k p n + 1

Next tactic:
conv_rhs => rw [go_eq]
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => 

Proof state:
k p n : ℕ
| go k p n + 1

Next tactic:
rw [go_eq]
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  

Proof state:
k p n : ℕ
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1

Next tactic:
by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0)
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); 

Proof state:
case pos
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1
case neg
k p n : ℕ
h : ¬(1 < p ∧ 0 < n ∧ n % p = 0)
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1

Next tactic:
swap
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · 

Proof state:
case neg
k p n : ℕ
h : ¬(1 < p ∧ 0 < n ∧ n % p = 0)
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1

Next tactic:
simp only [if_neg h]
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · 

Proof state:
case pos
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1

Next tactic:
have : n / p < n := by apply Nat.div_lt_self <;> aesop
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · have : n / p < n := by 

Proof state:
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ n / p < n

Next tactic:
apply Nat.div_lt_self
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · have : n / p < n := by apply Nat.div_lt_self <;> 

Proof state:
case hLtN
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ 0 < n

Next tactic:
aesop
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · have : n / p < n := by apply Nat.div_lt_self <;> 

Proof state:
case hLtK
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
⊢ 1 < p

Next tactic:
aesop
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · have : n / p < n := by apply Nat.div_lt_self <;> aesop
    

Proof state:
case pos
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
this : n / p < n
⊢ (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1 + 1) p (n / p) else k + 1) =
    (if 1 < p ∧ 0 < n ∧ n % p = 0 then go (k + 1) p (n / p) else k) + 1

Next tactic:
simp only [if_pos h]
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
  rw [go_eq]
  conv_rhs => rw [go_eq]
  by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0); swap
  · simp only [if_neg h]
  · have : n / p < n := by apply Nat.div_lt_self <;> aesop
    simp only [if_pos h]
    

Proof state:
case pos
k p n : ℕ
h : 1 < p ∧ 0 < n ∧ n % p = 0
this : n / p < n
⊢ go (k + 1 + 1) p (n / p) = go (k + 1) p (n / p) + 1

Next tactic:
apply go_succ
@[simp]
theorem zero_base {n : ℕ} : maxPowDiv 0 n = 0 := by
  

Proof state:
n : ℕ
⊢ maxPowDiv 0 n = 0

Next tactic:
dsimp [maxPowDiv]
@[simp]
theorem zero_base {n : ℕ} : maxPowDiv 0 n = 0 := by
  dsimp [maxPowDiv]
  

Proof state:
n : ℕ
⊢ go 0 0 n = 0

Next tactic:
rw [maxPowDiv.go_eq]
@[simp]
theorem zero_base {n : ℕ} : maxPowDiv 0 n = 0 := by
  dsimp [maxPowDiv]
  rw [maxPowDiv.go_eq]
  

Proof state:
n : ℕ
⊢ (if 1 < 0 ∧ 0 < n ∧ n % 0 = 0 then go (0 + 1) 0 (n / 0) else 0) = 0

Next tactic:
simp
@[simp]
theorem zero {p : ℕ} : maxPowDiv p 0 = 0 := by
  

Proof state:
p : ℕ
⊢ maxPowDiv p 0 = 0

Next tactic:
dsimp [maxPowDiv]
@[simp]
theorem zero {p : ℕ} : maxPowDiv p 0 = 0 := by
  dsimp [maxPowDiv]
  

Proof state:
p : ℕ
⊢ go 0 p 0 = 0

Next tactic:
rw [maxPowDiv.go_eq]
@[simp]
theorem zero {p : ℕ} : maxPowDiv p 0 = 0 := by
  dsimp [maxPowDiv]
  rw [maxPowDiv.go_eq]
  

Proof state:
p : ℕ
⊢ (if 1 < p ∧ 0 < 0 ∧ 0 % p = 0 then go (0 + 1) p (0 / p) else 0) = 0

Next tactic:
simp