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
      

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
y1 y2 : ↑Y
s : S
⊢ ((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))
      s =
    ((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

Next tactic:
dsimp