l3lab/ntp-mathlib huggingface dataset:
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x y : S
| (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y)

Next tactic:
rw [← h.map_repr x, ← h.map_repr y, ← map_add]
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      rw [← h.map_repr x, ← h.map_repr y, ← map_add]
      

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x y : S
| (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f)
    (h.map (IsAdjoinRoot.repr h.toIsAdjoinRoot x + IsAdjoinRoot.repr h.toIsAdjoinRoot y))

Next tactic:
dsimp only
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      rw [← h.map_repr x, ← h.map_repr y, ← map_add]
      dsimp only -- Porting note: added
      

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x y : S
| IsAdjoinRoot.repr h.toIsAdjoinRoot
      (h.map (IsAdjoinRoot.repr h.toIsAdjoinRoot x + IsAdjoinRoot.repr h.toIsAdjoinRoot y)) %ₘ
    f

Next tactic:
rw [h.modByMonic_repr_map, add_modByMonic]
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      rw [← h.map_repr x, ← h.map_repr y, ← map_add]
      dsimp only -- Porting note: added
      rw [h.modByMonic_repr_map, add_modByMonic]
  map_smul' c x := by
    

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
c : R
x : S
⊢ AddHom.toFun
      { toFun := fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f,
        map_add' :=
          (_ :
            ∀ (x y : S),
              (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y) =
                (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) x +
                  (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) y) }
      (c • x) =
    (RingHom.id R) c •
      AddHom.toFun
        { toFun := fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f,
          map_add' :=
            (_ :
              ∀ (x y : S),
                (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y) =
                  (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) x +
                    (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) y) }
        x

Next tactic:
rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul]
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      rw [← h.map_repr x, ← h.map_repr y, ← map_add]
      dsimp only -- Porting note: added
      rw [h.modByMonic_repr_map, add_modByMonic]
  map_smul' c x := by
    rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul]
    

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
c : R
x : S
⊢ AddHom.toFun
      { toFun := fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f,
        map_add' :=
          (_ :
            ∀ (x y : S),
              (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y) =
                (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) x +
                  (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) y) }
      (h.map (C c * IsAdjoinRoot.repr h.toIsAdjoinRoot x)) =
    c •
      AddHom.toFun
        { toFun := fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f,
          map_add' :=
            (_ :
              ∀ (x y : S),
                (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y) =
                  (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) x +
                    (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) y) }
        (h.map (IsAdjoinRoot.repr h.toIsAdjoinRoot x))

Next tactic:
dsimp only
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
  toFun x := h.repr x %ₘ f
  map_add' x y := by
    conv_lhs =>
      rw [← h.map_repr x, ← h.map_repr y, ← map_add]
      dsimp only -- Porting note: added
      rw [h.modByMonic_repr_map, add_modByMonic]
  map_smul' c x := by
    rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul]
    dsimp only -- Porting note: added
    

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
c : R
x : S
⊢ IsAdjoinRoot.repr h.toIsAdjoinRoot (h.map (C c * IsAdjoinRoot.repr h.toIsAdjoinRoot x)) %ₘ f =
    c • (IsAdjoinRoot.repr h.toIsAdjoinRoot (h.map (IsAdjoinRoot.repr h.toIsAdjoinRoot x)) %ₘ f)

Next tactic:
rw [h.modByMonic_repr_map, ← smul_eq_C_mul, smul_modByMonic, h.map_repr]
@[simp]
theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
⊢ h.map ((modByMonicHom h) x) = x

Next tactic:
rw [modByMonicHom, LinearMap.coe_mk]
@[simp]
theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by
  rw [modByMonicHom, LinearMap.coe_mk]
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
⊢ h.map
      ({ toFun := fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f,
          map_add' :=
            (_ :
              ∀ (x y : S),
                (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) (x + y) =
                  (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) x +
                    (fun x => IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) y) }
        x) =
    x

Next tactic:
dsimp
@[simp]
theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by
  rw [modByMonicHom, LinearMap.coe_mk]
  dsimp -- Porting note: added
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
⊢ h.map (IsAdjoinRoot.repr h.toIsAdjoinRoot x %ₘ f) = x

Next tactic:
rw [map_modByMonic, map_repr]
@[simp]
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) :
    h.modByMonicHom (h.root ^ n) = X ^ n := by
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
n : ℕ
hdeg : n < natDegree f
⊢ (modByMonicHom h) (root h.toIsAdjoinRoot ^ n) = X ^ n

Next tactic:
nontriviality R
@[simp]
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) :
    h.modByMonicHom (h.root ^ n) = X ^ n := by
  nontriviality R
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
n : ℕ
hdeg : n < natDegree f
✝ : Nontrivial R
⊢ (modByMonicHom h) (root h.toIsAdjoinRoot ^ n) = X ^ n

Next tactic:
rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow]
@[simp]
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) :
    h.modByMonicHom (h.root ^ n) = X ^ n := by
  nontriviality R
  rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow]
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
n : ℕ
hdeg : n < natDegree f
✝ : Nontrivial R
⊢ ↑n < degree f

Next tactic:
contrapose! hdeg
@[simp]
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) :
    h.modByMonicHom (h.root ^ n) = X ^ n := by
  nontriviality R
  rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow]
  contrapose! hdeg
  

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
n : ℕ
✝ : Nontrivial R
hdeg : degree f ≤ ↑n
⊢ natDegree f ≤ n

Next tactic:
simpa [natDegree_le_iff_degree_le] using hdeg
@[simp]
theorem modByMonicHom_root (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) :
    h.modByMonicHom h.root = X := by 

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
hdeg : 1 < natDegree f
⊢ (modByMonicHom h) (root h.toIsAdjoinRoot) = X

Next tactic:
simpa using modByMonicHom_root_pow h hdeg
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
        contrapose! hi
        simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne.def,
          modByMonicHom, LinearMap.coe_mk, Finset.mem_coe]
        by_cases hx : h.toIsAdjoinRoot.repr x %ₘ f = 0
        · simp [hx]
        refine coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le ?_ hi)
        dsimp -- Porting note: added
        rw [natDegree_lt_natDegree_iff hx]
        · exact degree_modByMonic_lt _ h.Monic
      right_inv := fun g => by
        nontriviality R
        ext i
        simp only [h.modByMonicHom_map, Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply]
        rw [(Polynomial.modByMonic_eq_self_iff h.Monic).mpr, Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_apply Fin.val_injective]
        rw [degree_eq_natDegree h.Monic.ne_zero, degree_lt_iff_coeff_zero]
        intro m hm
        rw [Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_notin_range]
        rw [Set.mem_range, not_exists]
        rintro i rfl
        exact i.prop.not_le hm
      map_add' := fun x y => by
        

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x y : S
⊢ (fun x =>
        Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
          (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)))
      (x + y) =
    (fun x =>
          Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
            (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)))
        x +
      (fun x =>
          Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
            (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)))
        y

Next tactic:
dsimp only
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
        contrapose! hi
        simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne.def,
          modByMonicHom, LinearMap.coe_mk, Finset.mem_coe]
        by_cases hx : h.toIsAdjoinRoot.repr x %ₘ f = 0
        · simp [hx]
        refine coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le ?_ hi)
        dsimp -- Porting note: added
        rw [natDegree_lt_natDegree_iff hx]
        · exact degree_modByMonic_lt _ h.Monic
      right_inv := fun g => by
        nontriviality R
        ext i
        simp only [h.modByMonicHom_map, Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply]
        rw [(Polynomial.modByMonic_eq_self_iff h.Monic).mpr, Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_apply Fin.val_injective]
        rw [degree_eq_natDegree h.Monic.ne_zero, degree_lt_iff_coeff_zero]
        intro m hm
        rw [Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_notin_range]
        rw [Set.mem_range, not_exists]
        rintro i rfl
        exact i.prop.not_le hm
      map_add' := fun x y => by
        dsimp only -- Porting note: added
        

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x y : S
⊢ Finsupp.comapDomain Fin.val ((modByMonicHom h) (x + y)).toFinsupp
      (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) (x + y)).toFinsupp.support)) =
    Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
        (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)) +
      Finsupp.comapDomain Fin.val ((modByMonicHom h) y).toFinsupp
        (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) y).toFinsupp.support))

Next tactic:
rw [map_add, toFinsupp_add, Finsupp.comapDomain_add_of_injective Fin.val_injective]
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
        contrapose! hi
        simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne.def,
          modByMonicHom, LinearMap.coe_mk, Finset.mem_coe]
        by_cases hx : h.toIsAdjoinRoot.repr x %ₘ f = 0
        · simp [hx]
        refine coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le ?_ hi)
        dsimp -- Porting note: added
        rw [natDegree_lt_natDegree_iff hx]
        · exact degree_modByMonic_lt _ h.Monic
      right_inv := fun g => by
        nontriviality R
        ext i
        simp only [h.modByMonicHom_map, Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply]
        rw [(Polynomial.modByMonic_eq_self_iff h.Monic).mpr, Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_apply Fin.val_injective]
        rw [degree_eq_natDegree h.Monic.ne_zero, degree_lt_iff_coeff_zero]
        intro m hm
        rw [Polynomial.coeff]
        dsimp only -- Porting note: added
        rw [Finsupp.mapDomain_notin_range]
        rw [Set.mem_range, not_exists]
        rintro i rfl
        exact i.prop.not_le hm
      map_add' := fun x y => by
        dsimp only -- Porting note: added
        rw [map_add, toFinsupp_add, Finsupp.comapDomain_add_of_injective Fin.val_injective]
      -- Porting note: the original simp proof with the same lemmas does not work
      -- See https://github.com/leanprover-community/mathlib4/issues/5026
      -- simp only [map_add, Finsupp.comapDomain_add_of_injective Fin.val_injective, toFinsupp_add]
      map_smul' := fun c x => by
        dsimp only -- Porting note: added
        

Proof state:
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
c : R
x : S
⊢ Finsupp.comapDomain Fin.val ((modByMonicHom h) (c • x)).toFinsupp
      (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) (c • x)).toFinsupp.support)) =
    (RingHom.id R) c •
      Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
        (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support))

Next tactic:
rw [map_smul, toFinsupp_smul, Finsupp.comapDomain_smul_of_injective Fin.val_injective,
          RingHom.id_apply]
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        

Proof state:
case inr
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
⊢ h.map
      {
        toFinsupp :=
          Finsupp.mapDomain
            (?m.1402729 h
              (Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
                (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support))))
            (Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
              (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support))) } =
    x

Next tactic:
rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · 

Proof state:
case inr.hf
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
⊢ Function.Injective Fin.val

Next tactic:
exact Fin.val_injective
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        

Proof state:
case inr.hl
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
⊢ ↑((modByMonicHom h) x).toFinsupp.support ⊆ Set.range Fin.val

Next tactic:
intro i hi
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        

Proof state:
case inr.hl
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
i : ℕ
hi : i ∈ ↑((modByMonicHom h) x).toFinsupp.support
⊢ i ∈ Set.range Fin.val

Next tactic:
refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
        

Proof state:
case inr.hl
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
i : ℕ
hi : i ∈ ↑((modByMonicHom h) x).toFinsupp.support
⊢ i < natDegree f

Next tactic:
contrapose! hi
/-- The basis on `S` generated by powers of `h.root`.

Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
  Basis.ofRepr
    { toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ (Fin.val_injective.injOn _)
      invFun := fun g => h.map (ofFinsupp (g.mapDomain _))
      left_inv := fun x => by
        cases subsingleton_or_nontrivial R
        · haveI := h.subsingleton
          exact Subsingleton.elim _ _
        simp only
        rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
        · exact Fin.val_injective
        intro i hi
        refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
        contrapose! hi
        

Proof state:
case inr.hl
R : Type u
S : Type v
inst✝² : CommRing R
inst✝¹ : Ring S
f : R[X]
inst✝ : Algebra R S
h : IsAdjoinRootMonic S f
x : S
h✝ : Nontrivial R
i : ℕ
hi : natDegree f ≤ i
⊢ i ∉ ↑((modByMonicHom h) x).toFinsupp.support

Next tactic:
simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne.def,
          modByMonicHom, LinearMap.coe_mk, Finset.mem_coe]