set_option maxHeartbeats 500000 in
/-- Given `R`-module X and `S`-module Y, any `g : (restrictScalars f).obj Y ⟶ X`
corresponds to `Y ⟶ (coextendScalars f).obj X` by sending `y ↦ (s ↦ g (s • y))`
-/
@[simps apply_apply]
def HomEquiv.fromRestriction {X : ModuleCat R} {Y : ModuleCat S}
    (g : (restrictScalars f).obj Y ⟶ X) : Y ⟶ (coextendScalars f).obj X where
  toFun := fun y : Y =>
    { toFun := fun s : S => g <| (s • y : Y)
      map_add' := fun s1 s2 : S => by simp only [add_smul]; rw [LinearMap.map_add]
      map_smul' := fun r (s : S) => by
        -- Porting note: dsimp clears out some rw's but less eager to apply others with Lean 4
        dsimp
        rw [← g.map_smul]
        erw [smul_eq_mul, mul_smul]
        rfl}
  map_add' := fun y1 y2 : Y =>
    LinearMap.ext fun s : S => by
      -- Porting note: double dsimp seems odd
      dsimp
      rw [LinearMap.add_apply, LinearMap.coe_mk, LinearMap.coe_mk]
      dsimp
      rw [smul_add, map_add]
  map_smul' := fun (s : S) (y : Y) => LinearMap.ext fun t : S => by
      -- Porting note: used to be simp [mul_smul]
      

Proof state:
R✝ : Type u₁
S✝ : Type u₂
inst✝³ : CommRing R✝
inst✝² : CommRing S✝
f✝ : R✝ →+* S✝
R : Type u₁
S : Type u₂
inst✝¹ : Ring R
inst✝ : Ring S
f : R →+* S
X : ModuleCat R
Y : ModuleCat S
g : (restrictScalars f).obj Y ⟶ X
s : S
y : ↑Y
t : S
⊢ (AddHom.toFun
        {
          toFun := fun y =>
            {
              toAddHom :=
                { toFun := fun s => g (s • y),
                  map_add' :=
                    (_ :
                      ∀ (s1 s2 : S),
                        (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
              map_smul' :=
                (_ :
                  ∀ (r : R) (s : S),
                    AddHom.toFun
                        { toFun := fun s => g (s • y),
                          map_add' :=
                            (_ :
                              ∀ (s1 s2 : S),
                                (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                        (r • s) =
                      (RingHom.id R) r •
                        AddHom.toFun
                          { toFun := fun s => g (s • y),
                            map_add' :=
                              (_ :
                                ∀ (s1 s2 : S),
                                  (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                          s) },
          map_add' :=
            (_ :
              ∀ (y1 y2 : ↑Y),
                (fun y =>
                      {
                        toAddHom :=
                          { toFun := fun s => g (s • y),
                            map_add' :=
                              (_ :
                                ∀ (s1 s2 : S),
                                  (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                        map_smul' :=
                          (_ :
                            ∀ (r : R) (s : S),
                              AddHom.toFun
                                  { toFun := fun s => g (s • y),
                                    map_add' :=
                                      (_ :
                                        ∀ (s1 s2 : S),
                                          (fun s => g (s • y)) (s1 + s2) =
                                            (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                  (r • s) =
                                (RingHom.id R) r •
                                  AddHom.toFun
                                    { toFun := fun s => g (s • y),
                                      map_add' :=
                                        (_ :
                                          ∀ (s1 s2 : S),
                                            (fun s => g (s • y)) (s1 + s2) =
                                              (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                    s) })
                    (y1 + y2) =
                  (fun y =>
                        {
                          toAddHom :=
                            { toFun := fun s => g (s • y),
                              map_add' :=
                                (_ :
                                  ∀ (s1 s2 : S),
                                    (fun s => g (s • y)) (s1 + s2) =
                                      (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                          map_smul' :=
                            (_ :
                              ∀ (r : R) (s : S),
                                AddHom.toFun
                                    { toFun := fun s => g (s • y),
                                      map_add' :=
                                        (_ :
                                          ∀ (s1 s2 : S),
                                            (fun s => g (s • y)) (s1 + s2) =
                                              (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                    (r • s) =
                                  (RingHom.id R) r •
                                    AddHom.toFun
                                      { toFun := fun s => g (s • y),
                                        map_add' :=
                                          (_ :
                                            ∀ (s1 s2 : S),
                                              (fun s => g (s • y)) (s1 + s2) =
                                                (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                      s) })
                      y1 +
                    (fun y =>
                        {
                          toAddHom :=
                            { toFun := fun s => g (s • y),
                              map_add' :=
                                (_ :
                                  ∀ (s1 s2 : S),
                                    (fun s => g (s • y)) (s1 + s2) =
                                      (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                          map_smul' :=
                            (_ :
                              ∀ (r : R) (s : S),
                                AddHom.toFun
                                    { toFun := fun s => g (s • y),
                                      map_add' :=
                                        (_ :
                                          ∀ (s1 s2 : S),
                                            (fun s => g (s • y)) (s1 + s2) =
                                              (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                    (r • s) =
                                  (RingHom.id R) r •
                                    AddHom.toFun
                                      { toFun := fun s => g (s • y),
                                        map_add' :=
                                          (_ :
                                            ∀ (s1 s2 : S),
                                              (fun s => g (s • y)) (s1 + s2) =
                                                (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                      s) })
                      y2) }
        (s • y))
      t =
    ((RingHom.id S) s •
        AddHom.toFun
          {
            toFun := fun y =>
              {
                toAddHom :=
                  { toFun := fun s => g (s • y),
                    map_add' :=
                      (_ :
                        ∀ (s1 s2 : S),
                          (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                map_smul' :=
                  (_ :
                    ∀ (r : R) (s : S),
                      AddHom.toFun
                          { toFun := fun s => g (s • y),
                            map_add' :=
                              (_ :
                                ∀ (s1 s2 : S),
                                  (fun s => g (s • y)) (s1 + s2) = (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                          (r • s) =
                        (RingHom.id R) r •
                          AddHom.toFun
                            { toFun := fun s => g (s • y),
                              map_add' :=
                                (_ :
                                  ∀ (s1 s2 : S),
                                    (fun s => g (s • y)) (s1 + s2) =
                                      (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                            s) },
            map_add' :=
              (_ :
                ∀ (y1 y2 : ↑Y),
                  (fun y =>
                        {
                          toAddHom :=
                            { toFun := fun s => g (s • y),
                              map_add' :=
                                (_ :
                                  ∀ (s1 s2 : S),
                                    (fun s => g (s • y)) (s1 + s2) =
                                      (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                          map_smul' :=
                            (_ :
                              ∀ (r : R) (s : S),
                                AddHom.toFun
                                    { toFun := fun s => g (s • y),
                                      map_add' :=
                                        (_ :
                                          ∀ (s1 s2 : S),
                                            (fun s => g (s • y)) (s1 + s2) =
                                              (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                    (r • s) =
                                  (RingHom.id R) r •
                                    AddHom.toFun
                                      { toFun := fun s => g (s • y),
                                        map_add' :=
                                          (_ :
                                            ∀ (s1 s2 : S),
                                              (fun s => g (s • y)) (s1 + s2) =
                                                (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                      s) })
                      (y1 + y2) =
                    (fun y =>
                          {
                            toAddHom :=
                              { toFun := fun s => g (s • y),
                                map_add' :=
                                  (_ :
                                    ∀ (s1 s2 : S),
                                      (fun s => g (s • y)) (s1 + s2) =
                                        (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                            map_smul' :=
                              (_ :
                                ∀ (r : R) (s : S),
                                  AddHom.toFun
                                      { toFun := fun s => g (s • y),
                                        map_add' :=
                                          (_ :
                                            ∀ (s1 s2 : S),
                                              (fun s => g (s • y)) (s1 + s2) =
                                                (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                      (r • s) =
                                    (RingHom.id R) r •
                                      AddHom.toFun
                                        { toFun := fun s => g (s • y),
                                          map_add' :=
                                            (_ :
                                              ∀ (s1 s2 : S),
                                                (fun s => g (s • y)) (s1 + s2) =
                                                  (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                        s) })
                        y1 +
                      (fun y =>
                          {
                            toAddHom :=
                              { toFun := fun s => g (s • y),
                                map_add' :=
                                  (_ :
                                    ∀ (s1 s2 : S),
                                      (fun s => g (s • y)) (s1 + s2) =
                                        (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) },
                            map_smul' :=
                              (_ :
                                ∀ (r : R) (s : S),
                                  AddHom.toFun
                                      { toFun := fun s => g (s • y),
                                        map_add' :=
                                          (_ :
                                            ∀ (s1 s2 : S),
                                              (fun s => g (s • y)) (s1 + s2) =
                                                (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                      (r • s) =
                                    (RingHom.id R) r •
                                      AddHom.toFun
                                        { toFun := fun s => g (s • y),
                                          map_add' :=
                                            (_ :
                                              ∀ (s1 s2 : S),
                                                (fun s => g (s • y)) (s1 + s2) =
                                                  (fun s => g (s • y)) s1 + (fun s => g (s • y)) s2) }
                                        s) })
                        y2) }
          y)
      t

Next tactic:
rw [RingHom.id_apply, LinearMap.coe_mk, ModuleCat.CoextendScalars.smul_apply',
        LinearMap.coe_mk]