/-- 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
        

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
g : Fin (natDegree f) →₀ R
⊢ AddHom.toFun
      {
          toAddHom :=
            {
              toFun := fun x =>
                Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
                  (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)),
              map_add' :=
                (_ :
                  ∀ (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) },
          map_smul' :=
            (_ :
              ∀ (c : R) (x : S),
                AddHom.toFun
                    {
                      toFun := fun x =>
                        Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
                          (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)),
                      map_add' :=
                        (_ :
                          ∀ (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) }
                    (c • x) =
                  (RingHom.id R) c •
                    AddHom.toFun
                      {
                        toFun := fun x =>
                          Finsupp.comapDomain Fin.val ((modByMonicHom h) x).toFinsupp
                            (_ : Set.InjOn Fin.val (Fin.val ⁻¹' ↑((modByMonicHom h) x).toFinsupp.support)),
                        map_add' :=
                          (_ :
                            ∀ (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) }
                      x) }.toAddHom
      ((fun g => h.map { toFinsupp := Finsupp.mapDomain Fin.val g }) g) =
    g

Next tactic:
nontriviality R