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

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

Next tactic:
dsimp only