l3lab/ntp-mathlib huggingface dataset:
theorem le_nth_of_lt_nth_succ {k a : ℕ} (h : a < nth p (k + 1)) (ha : p a) : a ≤ nth p k := by
  cases' (setOf p).finite_or_infinite with hf hf
  · rcases exists_lt_card_finite_nth_eq hf ha with ⟨n, hn, rfl⟩
    cases' lt_or_le (k + 1) hf.toFinset.card with hk hk
    · rwa [(nth_strictMonoOn hf).lt_iff_lt hn hk, lt_succ_iff,
        ← (nth_strictMonoOn hf).le_iff_le hn (k.lt_succ_self.trans hk)] at h
    · rw [nth_of_card_le _ hk] at h
      exact absurd h (zero_le _).not_lt
  · 

Proof state:
case inr
p : ℕ → Prop
k a : ℕ
h : a < nth p (k + 1)
ha : p a
hf : Set.Infinite (setOf p)
⊢ a ≤ nth p k

Next tactic:
rcases subset_range_nth ha with ⟨n, rfl⟩
theorem le_nth_of_lt_nth_succ {k a : ℕ} (h : a < nth p (k + 1)) (ha : p a) : a ≤ nth p k := by
  cases' (setOf p).finite_or_infinite with hf hf
  · rcases exists_lt_card_finite_nth_eq hf ha with ⟨n, hn, rfl⟩
    cases' lt_or_le (k + 1) hf.toFinset.card with hk hk
    · rwa [(nth_strictMonoOn hf).lt_iff_lt hn hk, lt_succ_iff,
        ← (nth_strictMonoOn hf).le_iff_le hn (k.lt_succ_self.trans hk)] at h
    · rw [nth_of_card_le _ hk] at h
      exact absurd h (zero_le _).not_lt
  · rcases subset_range_nth ha with ⟨n, rfl⟩
    

Proof state:
case inr.intro
p : ℕ → Prop
k : ℕ
hf : Set.Infinite (setOf p)
n : ℕ
h : nth p n < nth p (k + 1)
ha : p (nth p n)
⊢ nth p n ≤ nth p k

Next tactic:
rwa [nth_lt_nth hf, lt_succ_iff, ← nth_le_nth hf] at h
@[simp]
theorem count_nth_zero : count p (nth p 0) = 0 := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
⊢ count p (nth p 0) = 0

Next tactic:
rw [count_eq_card_filter_range, card_eq_zero, filter_eq_empty_iff, nth_zero]
@[simp]
theorem count_nth_zero : count p (nth p 0) = 0 := by
  rw [count_eq_card_filter_range, card_eq_zero, filter_eq_empty_iff, nth_zero]
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
⊢ ∀ ⦃x : ℕ⦄, x ∈ range (sInf (setOf p)) → ¬p x

Next tactic:
exact fun n h₁ h₂ => (mem_range.1 h₁).not_le (Nat.sInf_le h₂)
theorem filter_range_nth_subset_insert (k : ℕ) :
    (range (nth p (k + 1))).filter p ⊆ insert (nth p k) ((range (nth p k)).filter p) := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
⊢ filter p (range (nth p (k + 1))) ⊆ insert (nth p k) (filter p (range (nth p k)))

Next tactic:
intro a ha
theorem filter_range_nth_subset_insert (k : ℕ) :
    (range (nth p (k + 1))).filter p ⊆ insert (nth p k) ((range (nth p k)).filter p) := by
  intro a ha
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k a : ℕ
ha : a ∈ filter p (range (nth p (k + 1)))
⊢ a ∈ insert (nth p k) (filter p (range (nth p k)))

Next tactic:
simp only [mem_insert, mem_filter, mem_range] at ha ⊢
theorem filter_range_nth_subset_insert (k : ℕ) :
    (range (nth p (k + 1))).filter p ⊆ insert (nth p k) ((range (nth p k)).filter p) := by
  intro a ha
  simp only [mem_insert, mem_filter, mem_range] at ha ⊢
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k a : ℕ
ha : a < nth p (k + 1) ∧ p a
⊢ a = nth p k ∨ a < nth p k ∧ p a

Next tactic:
exact (le_nth_of_lt_nth_succ ha.1 ha.2).eq_or_lt.imp_right fun h => ⟨h, ha.2⟩
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
⊢ filter p (range (nth p (k + 1))) = insert (nth p k) (filter p (range (nth p k)))

Next tactic:
refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
a : ℕ
ha : a ∈ insert (nth p k) (filter p (range (nth p k)))
⊢ a ∈ filter p (range (nth p (k + 1)))

Next tactic:
simp only [mem_insert, mem_filter, mem_range] at ha ⊢
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
  simp only [mem_insert, mem_filter, mem_range] at ha ⊢
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
a : ℕ
ha : a = nth p k ∨ a < nth p k ∧ p a
⊢ a < nth p (k + 1) ∧ p a

Next tactic:
have : nth p k < nth p (k + 1) := nth_lt_nth' k.lt_succ_self hlt
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
  simp only [mem_insert, mem_filter, mem_range] at ha ⊢
  have : nth p k < nth p (k + 1) := nth_lt_nth' k.lt_succ_self hlt
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
a : ℕ
ha : a = nth p k ∨ a < nth p k ∧ p a
this : nth p k < nth p (k + 1)
⊢ a < nth p (k + 1) ∧ p a

Next tactic:
rcases ha with (rfl | ⟨hlt, hpa⟩)
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
  simp only [mem_insert, mem_filter, mem_range] at ha ⊢
  have : nth p k < nth p (k + 1) := nth_lt_nth' k.lt_succ_self hlt
  rcases ha with (rfl | ⟨hlt, hpa⟩)
  · 

Proof state:
case inl
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
this : nth p k < nth p (k + 1)
⊢ nth p k < nth p (k + 1) ∧ p (nth p k)

Next tactic:
exact ⟨this, nth_mem _ fun hf => k.lt_succ_self.trans (hlt hf)⟩
theorem filter_range_nth_eq_insert {k : ℕ}
    (hlt : ∀ hf : (setOf p).Finite, k + 1 < hf.toFinset.card) :
    (range (nth p (k + 1))).filter p = insert (nth p k) ((range (nth p k)).filter p) := by
  refine' (filter_range_nth_subset_insert p k).antisymm fun a ha => _
  simp only [mem_insert, mem_filter, mem_range] at ha ⊢
  have : nth p k < nth p (k + 1) := nth_lt_nth' k.lt_succ_self hlt
  rcases ha with (rfl | ⟨hlt, hpa⟩)
  · exact ⟨this, nth_mem _ fun hf => k.lt_succ_self.trans (hlt hf)⟩
  · 

Proof state:
case inr.intro
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
hlt✝ : ∀ (hf : Set.Finite (setOf p)), k + 1 < card (Set.Finite.toFinset hf)
a : ℕ
this : nth p k < nth p (k + 1)
hlt : a < nth p k
hpa : p a
⊢ a < nth p (k + 1) ∧ p a

Next tactic:
exact ⟨hlt.trans this, hpa⟩
theorem count_nth {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n) = n := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n : ℕ
hn : ∀ (hf : Set.Finite (setOf p)), n < card (Set.Finite.toFinset hf)
⊢ count p (nth p n) = n

Next tactic:
induction' n with k ihk
theorem count_nth {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n) = n := by
  induction' n with k ihk
  · 

Proof state:
case zero
p : ℕ → Prop
inst✝ : DecidablePred p
hn : ∀ (hf : Set.Finite (setOf p)), zero < card (Set.Finite.toFinset hf)
⊢ count p (nth p zero) = zero

Next tactic:
exact count_nth_zero _
theorem count_nth {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n) = n := by
  induction' n with k ihk
  · exact count_nth_zero _
  · 

Proof state:
case succ
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
ihk : (∀ (hf : Set.Finite (setOf p)), k < card (Set.Finite.toFinset hf)) → count p (nth p k) = k
hn : ∀ (hf : Set.Finite (setOf p)), succ k < card (Set.Finite.toFinset hf)
⊢ count p (nth p (succ k)) = succ k

Next tactic:
rw [count_eq_card_filter_range, filter_range_nth_eq_insert hn, card_insert_of_not_mem, ←
      count_eq_card_filter_range, ihk fun hf => lt_of_succ_lt (hn hf)]
theorem count_nth {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n) = n := by
  induction' n with k ihk
  · exact count_nth_zero _
  · rw [count_eq_card_filter_range, filter_range_nth_eq_insert hn, card_insert_of_not_mem, ←
      count_eq_card_filter_range, ihk fun hf => lt_of_succ_lt (hn hf)]
    

Proof state:
case succ
p : ℕ → Prop
inst✝ : DecidablePred p
k : ℕ
ihk : (∀ (hf : Set.Finite (setOf p)), k < card (Set.Finite.toFinset hf)) → count p (nth p k) = k
hn : ∀ (hf : Set.Finite (setOf p)), succ k < card (Set.Finite.toFinset hf)
⊢ nth p k ∉ filter p (range (nth p k))

Next tactic:
simp
theorem count_nth_succ {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
    count p (nth p n + 1) = n + 1 := by 

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n : ℕ
hn : ∀ (hf : Set.Finite (setOf p)), n < card (Set.Finite.toFinset hf)
⊢ count p (nth p n + 1) = n + 1

Next tactic:
rw [count_succ, count_nth hn, if_pos (nth_mem _ hn)]
theorem nth_lt_of_lt_count {n k : ℕ} (h : k < count p n) : nth p k < n := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n k : ℕ
h : k < count p n
⊢ nth p k < n

Next tactic:
refine' (count_monotone p).reflect_lt _
theorem nth_lt_of_lt_count {n k : ℕ} (h : k < count p n) : nth p k < n := by
  refine' (count_monotone p).reflect_lt _
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n k : ℕ
h : k < count p n
⊢ count p (nth p k) < count p n

Next tactic:
rwa [count_nth]
theorem nth_lt_of_lt_count {n k : ℕ} (h : k < count p n) : nth p k < n := by
  refine' (count_monotone p).reflect_lt _
  rwa [count_nth]
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n k : ℕ
h : k < count p n
⊢ ∀ (hf : Set.Finite (setOf p)), k < card (Set.Finite.toFinset hf)

Next tactic:
exact fun hf => h.trans_le (count_le_card hf n)
theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} := by
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n : ℕ
⊢ nth p (count p n) = sInf {i | p i ∧ n ≤ i}

Next tactic:
refine' (nth_eq_sInf _ _).trans (congr_arg sInf _)
theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} := by
  refine' (nth_eq_sInf _ _).trans (congr_arg sInf _)
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n : ℕ
⊢ {x | p x ∧ ∀ k < count p n, nth p k < x} = {i | p i ∧ n ≤ i}

Next tactic:
refine' Set.ext fun a => and_congr_right fun hpa => _
theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} := by
  refine' (nth_eq_sInf _ _).trans (congr_arg sInf _)
  refine' Set.ext fun a => and_congr_right fun hpa => _
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n a : ℕ
hpa : p a
⊢ (∀ k < count p n, nth p k < a) ↔ n ≤ a

Next tactic:
refine' ⟨fun h => not_lt.1 fun ha => _, fun hn k hk => lt_of_lt_of_le (nth_lt_of_lt_count hk) hn⟩
theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} := by
  refine' (nth_eq_sInf _ _).trans (congr_arg sInf _)
  refine' Set.ext fun a => and_congr_right fun hpa => _
  refine' ⟨fun h => not_lt.1 fun ha => _, fun hn k hk => lt_of_lt_of_le (nth_lt_of_lt_count hk) hn⟩
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n a : ℕ
hpa : p a
h : ∀ k < count p n, nth p k < a
ha : a < n
⊢ False

Next tactic:
have hn : nth p (count p a) < a := h _ (count_strict_mono hpa ha)
theorem nth_count_eq_sInf (n : ℕ) : nth p (count p n) = sInf {i : ℕ | p i ∧ n ≤ i} := by
  refine' (nth_eq_sInf _ _).trans (congr_arg sInf _)
  refine' Set.ext fun a => and_congr_right fun hpa => _
  refine' ⟨fun h => not_lt.1 fun ha => _, fun hn k hk => lt_of_lt_of_le (nth_lt_of_lt_count hk) hn⟩
  have hn : nth p (count p a) < a := h _ (count_strict_mono hpa ha)
  

Proof state:
p : ℕ → Prop
inst✝ : DecidablePred p
n a : ℕ
hpa : p a
h : ∀ k < count p n, nth p k < a
ha : a < n
hn : nth p (count p a) < a
⊢ False

Next tactic:
rwa [nth_count hpa, lt_self_iff_false] at hn
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
⊢ ∃ a b, (∀ {d : A}, d ∣ a → d ∣ ↑b → IsUnit d) ∧ mk' K a b = x

Next tactic:
obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  

Proof state:
case intro.mk.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
b : A
b_nonzero : b ∈ nonZeroDivisors A
a : A
hab : (algebraMap A K) a = ↑{ val := b, property := b_nonzero } • x
⊢ ∃ a b, (∀ {d : A}, d ∣ a → d ∣ ↑b → IsUnit d) ∧ mk' K a b = x

Next tactic:
obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
  

Proof state:
case intro.mk.intro.intro.intro.intro.intro.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
a' b' c' : A
no_factor : ∀ {d : A}, d ∣ a' → d ∣ b' → IsUnit d
b_nonzero : c' * b' ∈ nonZeroDivisors A
hab : (algebraMap A K) (c' * a') = ↑{ val := c' * b', property := b_nonzero } • x
⊢ ∃ a b, (∀ {d : A}, d ∣ a → d ∣ ↑b → IsUnit d) ∧ mk' K a b = x

Next tactic:
obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
  obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
  

Proof state:
case intro.mk.intro.intro.intro.intro.intro.intro.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
a' b' c' : A
no_factor : ∀ {d : A}, d ∣ a' → d ∣ b' → IsUnit d
b_nonzero : c' * b' ∈ nonZeroDivisors A
hab : (algebraMap A K) (c' * a') = ↑{ val := c' * b', property := b_nonzero } • x
left✝ : c' ∈ nonZeroDivisors A
b'_nonzero : b' ∈ nonZeroDivisors A
⊢ ∃ a b, (∀ {d : A}, d ∣ a → d ∣ ↑b → IsUnit d) ∧ mk' K a b = x

Next tactic:
refine' ⟨a', ⟨b', b'_nonzero⟩, no_factor, _⟩
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
  obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
  refine' ⟨a', ⟨b', b'_nonzero⟩, no_factor, _⟩
  

Proof state:
case intro.mk.intro.intro.intro.intro.intro.intro.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
a' b' c' : A
no_factor : ∀ {d : A}, d ∣ a' → d ∣ b' → IsUnit d
b_nonzero : c' * b' ∈ nonZeroDivisors A
hab : (algebraMap A K) (c' * a') = ↑{ val := c' * b', property := b_nonzero } • x
left✝ : c' ∈ nonZeroDivisors A
b'_nonzero : b' ∈ nonZeroDivisors A
⊢ mk' K a' { val := b', property := b'_nonzero } = x

Next tactic:
refine' mul_left_cancel₀ (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors b_nonzero) _
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
  obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
  refine' ⟨a', ⟨b', b'_nonzero⟩, no_factor, _⟩
  refine' mul_left_cancel₀ (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors b_nonzero) _
  

Proof state:
case intro.mk.intro.intro.intro.intro.intro.intro.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
a' b' c' : A
no_factor : ∀ {d : A}, d ∣ a' → d ∣ b' → IsUnit d
b_nonzero : c' * b' ∈ nonZeroDivisors A
hab : (algebraMap A K) (c' * a') = ↑{ val := c' * b', property := b_nonzero } • x
left✝ : c' ∈ nonZeroDivisors A
b'_nonzero : b' ∈ nonZeroDivisors A
⊢ (algebraMap A K) (c' * b') * mk' K a' { val := b', property := b'_nonzero } = (algebraMap A K) (c' * b') * x

Next tactic:
simp only [Subtype.coe_mk, RingHom.map_mul, Algebra.smul_def] at *
theorem exists_reduced_fraction (x : K) :
    ∃ (a : A) (b : nonZeroDivisors A), (∀ {d}, d ∣ a → d ∣ b → IsUnit d) ∧ mk' K a b = x := by
  obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
  obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
    UniqueFactorizationMonoid.exists_reduced_factors' a b
      (mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
  obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
  refine' ⟨a', ⟨b', b'_nonzero⟩, no_factor, _⟩
  refine' mul_left_cancel₀ (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors b_nonzero) _
  simp only [Subtype.coe_mk, RingHom.map_mul, Algebra.smul_def] at *
  

Proof state:
case intro.mk.intro.intro.intro.intro.intro.intro.intro
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
a' b' c' : A
no_factor : ∀ {d : A}, d ∣ a' → d ∣ b' → IsUnit d
b_nonzero : c' * b' ∈ nonZeroDivisors A
left✝ : c' ∈ nonZeroDivisors A
b'_nonzero : b' ∈ nonZeroDivisors A
hab : (algebraMap A K) c' * (algebraMap A K) a' = (algebraMap A K) c' * (algebraMap A K) b' * x
⊢ (algebraMap A K) c' * (algebraMap A K) b' * mk' K a' { val := b', property := b'_nonzero } =
    (algebraMap A K) c' * (algebraMap A K) b' * x

Next tactic:
erw [← hab, mul_assoc, mk'_spec' _ a' ⟨b', b'_nonzero⟩]
@[simp]
theorem mk'_num_den' (x : K) : algebraMap A K (num A x) / algebraMap A K (den A x) = x := by
  

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
⊢ (algebraMap A K) (num A x) / (algebraMap A K) ↑(den A x) = x

Next tactic:
rw [← mk'_eq_div]
@[simp]
theorem mk'_num_den' (x : K) : algebraMap A K (num A x) / algebraMap A K (den A x) = x := by
  rw [← mk'_eq_div]
  

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x : K
⊢ mk' K (num A x) (den A x) = x

Next tactic:
apply mk'_num_den
theorem num_mul_den_eq_num_iff_eq {x y : K} :
    x * algebraMap A K (den A y) = algebraMap A K (num A y) ↔ x = y :=
  ⟨fun h => by 

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x y : K
h : x * (algebraMap A K) ↑(den A y) = (algebraMap A K) (num A y)
⊢ x = y

Next tactic:
simpa only [mk'_num_den] using eq_mk'_iff_mul_eq.mpr h
theorem num_mul_den_eq_num_iff_eq {x y : K} :
    x * algebraMap A K (den A y) = algebraMap A K (num A y) ↔ x = y :=
  ⟨fun h => by simpa only [mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦
    eq_mk'_iff_mul_eq.mp (by 

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x y : K
h : x = y
⊢ x = mk' K (num A y) (den A y)

Next tactic:
rw [h, mk'_num_den]
theorem num_mul_den_eq_num_iff_eq' {x y : K} :
    y * algebraMap A K (den A x) = algebraMap A K (num A x) ↔ x = y :=
  ⟨fun h ↦ by 

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x y : K
h : y * (algebraMap A K) ↑(den A x) = (algebraMap A K) (num A x)
⊢ x = y

Next tactic:
simpa only [eq_comm, mk'_num_den] using eq_mk'_iff_mul_eq.mpr h
theorem num_mul_den_eq_num_iff_eq' {x y : K} :
    y * algebraMap A K (den A x) = algebraMap A K (num A x) ↔ x = y :=
  ⟨fun h ↦ by simpa only [eq_comm, mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦
    eq_mk'_iff_mul_eq.mp (by 

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x y : K
h : x = y
⊢ y = mk' K (num A x) (den A x)

Next tactic:
rw [h, mk'_num_den]
theorem num_mul_den_eq_num_mul_den_iff_eq {x y : K} :
    num A y * den A x = num A x * den A y ↔ x = y :=
  ⟨fun h ↦ by 

Proof state:
R : Type u_1
inst✝⁹ : CommRing R
M : Submonoid R
S : Type u_2
inst✝⁸ : CommRing S
inst✝⁷ : Algebra R S
P : Type u_3
inst✝⁶ : CommRing P
A : Type u_4
inst✝⁵ : CommRing A
inst✝⁴ : IsDomain A
inst✝³ : UniqueFactorizationMonoid A
K : Type u_5
inst✝² : Field K
inst✝¹ : Algebra A K
inst✝ : IsFractionRing A K
x y : K
h : num A y * ↑(den A x) = num A x * ↑(den A y)
⊢ x = y

Next tactic:
simpa only [mk'_num_den] using mk'_eq_of_eq' (S := K) h