l3lab/ntp-mathlib huggingface dataset:
nonrec
theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R]
    [GCDMonoid R] [Unique Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R}
    (h : ∀ (i) (_ : i ∈ s) (j) (_ : j ∈ s), i ≠ j → IsCoprime (f i) (f j))
    (hprod : ∏ i in s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by
  classical
    intro i hi
    rw [← insert_erase hi, prod_insert (not_mem_erase i s)] at hprod
    refine'
      exists_eq_pow_of_mul_eq_pow_of_coprime
        (IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => _) hprod
    

Proof state:
M : Type u_1
inst✝⁵ : CancelMonoidWithZero M
inst✝⁴ : Finite M
ι : Type u_2
R : Type u_3
inst✝³ : CommSemiring R
inst✝² : IsDomain R
inst✝¹ : GCDMonoid R
inst✝ : Unique Rˣ
n : ℕ
c : R
s : Finset ι
f : ι → R
h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j)
i : ι
hprod : f i * ∏ x in erase s i, f x = c ^ n
hi : i ∈ s
j : ι
hj : j ∈ erase s i
hij : i = j
⊢ False

Next tactic:
rw [hij] at hj
nonrec
theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R]
    [GCDMonoid R] [Unique Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R}
    (h : ∀ (i) (_ : i ∈ s) (j) (_ : j ∈ s), i ≠ j → IsCoprime (f i) (f j))
    (hprod : ∏ i in s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by
  classical
    intro i hi
    rw [← insert_erase hi, prod_insert (not_mem_erase i s)] at hprod
    refine'
      exists_eq_pow_of_mul_eq_pow_of_coprime
        (IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => _) hprod
    rw [hij] at hj
    

Proof state:
M : Type u_1
inst✝⁵ : CancelMonoidWithZero M
inst✝⁴ : Finite M
ι : Type u_2
R : Type u_3
inst✝³ : CommSemiring R
inst✝² : IsDomain R
inst✝¹ : GCDMonoid R
inst✝ : Unique Rˣ
n : ℕ
c : R
s : Finset ι
f : ι → R
h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j)
i : ι
hprod : f i * ∏ x in erase s i, f x = c ^ n
hi : i ∈ s
j : ι
hj : j ∈ erase s j
hij : i = j
⊢ False

Next tactic:
exact (s.not_mem_erase _) hj
theorem Finite.isField_of_domain (R) [CommRing R] [IsDomain R] [Finite R] : IsField R := by
  

Proof state:
R✝ : Type u_1
G : Type u_2
inst✝⁵ : Ring R✝
inst✝⁴ : IsDomain R✝
inst✝³ : Fintype R✝
R : Type u_3
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : Finite R
⊢ IsField R

Next tactic:
cases nonempty_fintype R
theorem Finite.isField_of_domain (R) [CommRing R] [IsDomain R] [Finite R] : IsField R := by
  cases nonempty_fintype R
  

Proof state:
case intro
R✝ : Type u_1
G : Type u_2
inst✝⁵ : Ring R✝
inst✝⁴ : IsDomain R✝
inst✝³ : Fintype R✝
R : Type u_3
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : Finite R
val✝ : Fintype R
⊢ IsField R

Next tactic:
exact @Field.toIsField R (@Fintype.fieldOfDomain R _ _ (Classical.decEq R) _)
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  

Proof state:
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
⊢ card (filter (fun g => g ^ n = g₀) univ) ≤ Multiset.card (nthRoots n (f g₀))

Next tactic:
haveI : DecidableEq R := Classical.decEq _
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  

Proof state:
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
⊢ card (filter (fun g => g ^ n = g₀) univ) ≤ Multiset.card (nthRoots n (f g₀))

Next tactic:
refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  

Proof state:
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
⊢ card (filter (fun g => g ^ n = g₀) univ) ≤ card (Multiset.toFinset (nthRoots n (f g₀)))

Next tactic:
apply card_le_card_of_inj_on f
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · 

Proof state:
case hf
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
⊢ ∀ a ∈ filter (fun g => g ^ n = g₀) univ, f a ∈ Multiset.toFinset (nthRoots n (f g₀))

Next tactic:
intro g hg
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · intro g hg
    

Proof state:
case hf
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
g : G
hg : g ∈ filter (fun g => g ^ n = g₀) univ
⊢ f g ∈ Multiset.toFinset (nthRoots n (f g₀))

Next tactic:
rw [mem_filter] at hg
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · intro g hg
    rw [mem_filter] at hg
    

Proof state:
case hf
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
g : G
hg : g ∈ univ ∧ g ^ n = g₀
⊢ f g ∈ Multiset.toFinset (nthRoots n (f g₀))

Next tactic:
rw [Multiset.mem_toFinset, mem_nthRoots hn, ← f.map_pow, hg.2]
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · intro g hg
    rw [mem_filter] at hg
    rw [Multiset.mem_toFinset, mem_nthRoots hn, ← f.map_pow, hg.2]
  · 

Proof state:
case f_inj
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
⊢ ∀ a₁ ∈ filter (fun g => g ^ n = g₀) univ, ∀ a₂ ∈ filter (fun g => g ^ n = g₀) univ, f a₁ = f a₂ → a₁ = a₂

Next tactic:
intros
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · intro g hg
    rw [mem_filter] at hg
    rw [Multiset.mem_toFinset, mem_nthRoots hn, ← f.map_pow, hg.2]
  · intros
    

Proof state:
case f_inj
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
a₁✝ : G
a✝² : a₁✝ ∈ filter (fun g => g ^ n = g₀) univ
a₂✝ : G
a✝¹ : a₂✝ ∈ filter (fun g => g ^ n = g₀) univ
a✝ : f a₁✝ = f a₂✝
⊢ a₁✝ = a₂✝

Next tactic:
apply hf
theorem card_nthRoots_subgroup_units [Fintype G] [DecidableEq G] (f : G →* R) (hf : Injective f)
    {n : ℕ} (hn : 0 < n) (g₀ : G) :
    Finset.card (Finset.univ.filter (fun g ↦ g^n = g₀)) ≤ Multiset.card (nthRoots n (f g₀)) := by
  haveI : DecidableEq R := Classical.decEq _
  refine' le_trans _ (nthRoots n (f g₀)).toFinset_card_le
  apply card_le_card_of_inj_on f
  · intro g hg
    rw [mem_filter] at hg
    rw [Multiset.mem_toFinset, mem_nthRoots hn, ← f.map_pow, hg.2]
  · intros
    apply hf
    

Proof state:
case f_inj.a
R : Type u_1
G : Type u_2
inst✝⁴ : CommRing R
inst✝³ : IsDomain R
inst✝² : Group G
inst✝¹ : Fintype G
inst✝ : DecidableEq G
f : G →* R
hf : Injective ⇑f
n : ℕ
hn : 0 < n
g₀ : G
this : DecidableEq R
a₁✝ : G
a✝² : a₁✝ ∈ filter (fun g => g ^ n = g₀) univ
a₂✝ : G
a✝¹ : a₂✝ ∈ filter (fun g => g ^ n = g₀) univ
a✝ : f a₁✝ = f a₂✝
⊢ f a₁✝ = f a₂✝

Next tactic:
assumption
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by
  

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
inst✝ : Finite G
f : G →* R
hf : Injective ⇑f
⊢ IsCyclic G

Next tactic:
classical
    cases nonempty_fintype G
    apply isCyclic_of_card_pow_eq_one_le
    intro n hn
    exact le_trans (card_nthRoots_subgroup_units f hf hn 1) (card_nthRoots n (f 1))
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by
  classical
    

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
inst✝ : Finite G
f : G →* R
hf : Injective ⇑f
⊢ IsCyclic G

Next tactic:
cases nonempty_fintype G
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by
  classical
    cases nonempty_fintype G
    

Proof state:
case intro
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
inst✝ : Finite G
f : G →* R
hf : Injective ⇑f
val✝ : Fintype G
⊢ IsCyclic G

Next tactic:
apply isCyclic_of_card_pow_eq_one_le
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by
  classical
    cases nonempty_fintype G
    apply isCyclic_of_card_pow_eq_one_le
    

Proof state:
case intro.hn
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
inst✝ : Finite G
f : G →* R
hf : Injective ⇑f
val✝ : Fintype G
⊢ ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n

Next tactic:
intro n hn
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem isCyclic_of_subgroup_isDomain [Finite G] (f : G →* R) (hf : Injective f) : IsCyclic G := by
  classical
    cases nonempty_fintype G
    apply isCyclic_of_card_pow_eq_one_le
    intro n hn
    

Proof state:
case intro.hn
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
inst✝ : Finite G
f : G →* R
hf : Injective ⇑f
val✝ : Fintype G
n : ℕ
hn : 0 < n
⊢ card (filter (fun a => a ^ n = 1) univ) ≤ n

Next tactic:
exact le_trans (card_nthRoots_subgroup_units f hf hn 1) (card_nthRoots n (f 1))
/-- A finite subgroup of the units of an integral domain is cyclic. -/
instance subgroup_units_cyclic : IsCyclic S := by
  -- porting note: the original proof used a `coe`, but I was not able to get it to work.
  

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
S : Subgroup Rˣ
inst✝ : Finite ↥S
⊢ IsCyclic ↥S

Next tactic:
apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _
/-- A finite subgroup of the units of an integral domain is cyclic. -/
instance subgroup_units_cyclic : IsCyclic S := by
  -- porting note: the original proof used a `coe`, but I was not able to get it to work.
  apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _
  · 

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
S : Subgroup Rˣ
inst✝ : Finite ↥S
⊢ ↥S →* R

Next tactic:
exact MonoidHom.mk (OneHom.mk (fun s => ↑s.val) rfl) (by simp)
/-- A finite subgroup of the units of an integral domain is cyclic. -/
instance subgroup_units_cyclic : IsCyclic S := by
  -- porting note: the original proof used a `coe`, but I was not able to get it to work.
  apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _
  · exact MonoidHom.mk (OneHom.mk (fun s => ↑s.val) rfl) (by 

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
S : Subgroup Rˣ
inst✝ : Finite ↥S
⊢ ∀ (x y : ↥S),
    OneHom.toFun { toFun := fun s => ↑↑s, map_one' := (_ : (fun s => ↑↑s) 1 = (fun s => ↑↑s) 1) } (x * y) =
      OneHom.toFun { toFun := fun s => ↑↑s, map_one' := (_ : (fun s => ↑↑s) 1 = (fun s => ↑↑s) 1) } x *
        OneHom.toFun { toFun := fun s => ↑↑s, map_one' := (_ : (fun s => ↑↑s) 1 = (fun s => ↑↑s) 1) } y

Next tactic:
simp
/-- A finite subgroup of the units of an integral domain is cyclic. -/
instance subgroup_units_cyclic : IsCyclic S := by
  -- porting note: the original proof used a `coe`, but I was not able to get it to work.
  apply isCyclic_of_subgroup_isDomain (R := R) (G := S) _ _
  · exact MonoidHom.mk (OneHom.mk (fun s => ↑s.val) rfl) (by simp)
  · 

Proof state:
R : Type u_1
G : Type u_2
inst✝³ : CommRing R
inst✝² : IsDomain R
inst✝¹ : Group G
S : Subgroup Rˣ
inst✝ : Finite ↥S
⊢ Injective
    ⇑{ toOneHom := { toFun := fun s => ↑↑s, map_one' := (_ : (fun s => ↑↑s) 1 = (fun s => ↑↑s) 1) },
        map_mul' := (_ : ∀ (a a_1 : ↥S), ↑↑a * ↑↑a_1 = ↑↑a * ↑↑a_1) }

Next tactic:
exact Units.ext.comp Subtype.val_injective
theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) :
    ∃ q r : R[X], r.degree < g.degree ∧
      (algebraMap R[X] K f) / (algebraMap R[X] K g) =
        algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by
  

Proof state:
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
K : Type
inst✝² : Field K
inst✝¹ : Algebra R[X] K
inst✝ : IsFractionRing R[X] K
f g : R[X]
hg : Monic g
⊢ ∃ q r,
    degree r < degree g ∧
      (algebraMap R[X] K) f / (algebraMap R[X] K) g =
        (algebraMap R[X] K) q + (algebraMap R[X] K) r / (algebraMap R[X] K) g

Next tactic:
refine' ⟨f /ₘ g, f %ₘ g, _, _⟩
theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) :
    ∃ q r : R[X], r.degree < g.degree ∧
      (algebraMap R[X] K f) / (algebraMap R[X] K g) =
        algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by
  refine' ⟨f /ₘ g, f %ₘ g, _, _⟩
  · 

Proof state:
case refine'_1
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
K : Type
inst✝² : Field K
inst✝¹ : Algebra R[X] K
inst✝ : IsFractionRing R[X] K
f g : R[X]
hg : Monic g
⊢ degree (f %ₘ g) < degree g

Next tactic:
exact degree_modByMonic_lt _ hg
theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) :
    ∃ q r : R[X], r.degree < g.degree ∧
      (algebraMap R[X] K f) / (algebraMap R[X] K g) =
        algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by
  refine' ⟨f /ₘ g, f %ₘ g, _, _⟩
  · exact degree_modByMonic_lt _ hg
  · 

Proof state:
case refine'_2
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
K : Type
inst✝² : Field K
inst✝¹ : Algebra R[X] K
inst✝ : IsFractionRing R[X] K
f g : R[X]
hg : Monic g
⊢ (algebraMap R[X] K) f / (algebraMap R[X] K) g =
    (algebraMap R[X] K) (f /ₘ g) + (algebraMap R[X] K) (f %ₘ g) / (algebraMap R[X] K) g

Next tactic:
have hg' : algebraMap R[X] K g ≠ 0 :=
      -- porting note: the proof was `by exact_mod_cast Monic.ne_zero hg`
      (map_ne_zero_iff _ (IsFractionRing.injective R[X] K)).mpr (Monic.ne_zero hg)
theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) :
    ∃ q r : R[X], r.degree < g.degree ∧
      (algebraMap R[X] K f) / (algebraMap R[X] K g) =
        algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by
  refine' ⟨f /ₘ g, f %ₘ g, _, _⟩
  · exact degree_modByMonic_lt _ hg
  · have hg' : algebraMap R[X] K g ≠ 0 :=
      -- porting note: the proof was `by exact_mod_cast Monic.ne_zero hg`
      (map_ne_zero_iff _ (IsFractionRing.injective R[X] K)).mpr (Monic.ne_zero hg)
    

Proof state:
case refine'_2
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
K : Type
inst✝² : Field K
inst✝¹ : Algebra R[X] K
inst✝ : IsFractionRing R[X] K
f g : R[X]
hg : Monic g
hg' : (algebraMap R[X] K) g ≠ 0
⊢ (algebraMap R[X] K) f / (algebraMap R[X] K) g =
    (algebraMap R[X] K) (f /ₘ g) + (algebraMap R[X] K) (f %ₘ g) / (algebraMap R[X] K) g

Next tactic:
field_simp [hg']
theorem div_eq_quo_add_rem_div (f : R[X]) {g : R[X]} (hg : g.Monic) :
    ∃ q r : R[X], r.degree < g.degree ∧
      (algebraMap R[X] K f) / (algebraMap R[X] K g) =
        algebraMap R[X] K q + (algebraMap R[X] K r) / (algebraMap R[X] K g) := by
  refine' ⟨f /ₘ g, f %ₘ g, _, _⟩
  · exact degree_modByMonic_lt _ hg
  · have hg' : algebraMap R[X] K g ≠ 0 :=
      -- porting note: the proof was `by exact_mod_cast Monic.ne_zero hg`
      (map_ne_zero_iff _ (IsFractionRing.injective R[X] K)).mpr (Monic.ne_zero hg)
    field_simp [hg']
    -- porting note: `norm_cast` was here, but does nothing.
    

Proof state:
case refine'_2
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
K : Type
inst✝² : Field K
inst✝¹ : Algebra R[X] K
inst✝ : IsFractionRing R[X] K
f g : R[X]
hg : Monic g
hg' : (algebraMap R[X] K) g ≠ 0
⊢ (algebraMap R[X] K) f = (algebraMap R[X] K) (f /ₘ g) * (algebraMap R[X] K) g + (algebraMap R[X] K) (f %ₘ g)

Next tactic:
rw [add_comm, mul_comm, ← map_mul, ← map_add, modByMonic_add_div f hg]
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  

Proof state:
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
x y : H
hx : x ∈ Set.range ⇑f
hy : y ∈ Set.range ⇑f
⊢ card (filter (fun g => f g = x) univ) = card (filter (fun g => f g = y) univ)

Next tactic:
rcases hx with ⟨x, rfl⟩
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  rcases hx with ⟨x, rfl⟩
  

Proof state:
case intro
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
y : H
hy : y ∈ Set.range ⇑f
x : G
⊢ card (filter (fun g => f g = f x) univ) = card (filter (fun g => f g = y) univ)

Next tactic:
rcases hy with ⟨y, rfl⟩
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  rcases hx with ⟨x, rfl⟩
  rcases hy with ⟨y, rfl⟩
  

Proof state:
case intro.intro
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
x y : G
⊢ card (filter (fun g => f g = f x) univ) = card (filter (fun g => f g = f y) univ)

Next tactic:
refine' card_congr (fun g _ => g * x⁻¹ * y) _ _ fun g hg => ⟨g * y⁻¹ * x, _⟩
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  rcases hx with ⟨x, rfl⟩
  rcases hy with ⟨y, rfl⟩
  refine' card_congr (fun g _ => g * x⁻¹ * y) _ _ fun g hg => ⟨g * y⁻¹ * x, _⟩
  · 

Proof state:
case intro.intro.refine'_1
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
x y : G
⊢ ∀ (a : G) (ha : a ∈ filter (fun g => f g = f x) univ),
    (fun g x_1 => g * x⁻¹ * y) a ha ∈ filter (fun g => f g = f y) univ

Next tactic:
simp (config := { contextual := true }) only [*, mem_filter, one_mul, MonoidHom.map_mul,
      mem_univ, mul_right_inv, eq_self_iff_true, MonoidHom.map_mul_inv, and_self_iff,
      forall_true_iff]
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  rcases hx with ⟨x, rfl⟩
  rcases hy with ⟨y, rfl⟩
  refine' card_congr (fun g _ => g * x⁻¹ * y) _ _ fun g hg => ⟨g * y⁻¹ * x, _⟩
  · simp (config := { contextual := true }) only [*, mem_filter, one_mul, MonoidHom.map_mul,
      mem_univ, mul_right_inv, eq_self_iff_true, MonoidHom.map_mul_inv, and_self_iff,
      forall_true_iff]
    -- porting note: added the following `simp`
    

Proof state:
case intro.intro.refine'_1
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
x y : G
⊢ ∀ (a : G), True ∧ f a = f x → True ∧ f x * f x⁻¹ * f y = f y

Next tactic:
simp only [true_and, map_inv, mul_right_inv, one_mul, and_self, implies_true, forall_const]
theorem card_fiber_eq_of_mem_range {H : Type*} [Group H] [DecidableEq H] (f : G →* H) {x y : H}
    (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
    -- porting note: the `filter` had an index `ₓ` that I removed.
    (univ.filter fun g => f g = x).card = (univ.filter fun g => f g = y).card := by
  rcases hx with ⟨x, rfl⟩
  rcases hy with ⟨y, rfl⟩
  refine' card_congr (fun g _ => g * x⁻¹ * y) _ _ fun g hg => ⟨g * y⁻¹ * x, _⟩
  · simp (config := { contextual := true }) only [*, mem_filter, one_mul, MonoidHom.map_mul,
      mem_univ, mul_right_inv, eq_self_iff_true, MonoidHom.map_mul_inv, and_self_iff,
      forall_true_iff]
    -- porting note: added the following `simp`
    simp only [true_and, map_inv, mul_right_inv, one_mul, and_self, implies_true, forall_const]
  · 

Proof state:
case intro.intro.refine'_2
R : Type u_1
G : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : Group G
inst✝² : Fintype G
H : Type u_3
inst✝¹ : Group H
inst✝ : DecidableEq H
f : G →* H
x y : G
⊢ ∀ (a b : G) (ha : a ∈ filter (fun g => f g = f x) univ) (hb : b ∈ filter (fun g => f g = f x) univ),
    (fun g x_1 => g * x⁻¹ * y) a ha = (fun g x_1 => g * x⁻¹ * y) b hb → a = b

Next tactic:
simp only [mul_left_inj, imp_self, forall₂_true_iff]