instance algebra {S : Type*} [CommSemiring S] [Algebra S R] : Algebra S (Localization M) where
  toRingHom :=
    RingHom.comp
      { Localization.monoidOf M with
        toFun := (monoidOf M).toMap
        map_zero' := by rw [← mk_zero (1 : M), mk_one_eq_monoidOf_mk]
        map_add' := fun x y => by
          simp only [← mk_one_eq_monoidOf_mk, add_mk, Submonoid.coe_one, one_mul, add_comm] }
      (algebraMap S R)
  smul_def' s :=
    Localization.ind <|
      Prod.rec <| by
        intro r x
        dsimp
        simp only [← mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul,
          Algebra.smul_def]
  commutes' s :=
    Localization.ind <|
      Prod.rec <| by
        

Proof state:
R : Type u_1
inst✝⁵ : CommSemiring R
M : Submonoid R
S✝ : Type u_2
inst✝⁴ : CommSemiring S✝
inst✝³ : Algebra R S✝
P : Type u_3
inst✝² : CommSemiring P
S : Type u_4
inst✝¹ : CommSemiring S
inst✝ : Algebra S R
s : S
⊢ ∀ (fst : R) (snd : ↥M),
    (RingHom.comp
            (let src := monoidOf M;
            {
              toMonoidHom :=
                {
                  toOneHom :=
                    { toFun := ⇑(Submonoid.LocalizationMap.toMap (monoidOf M)),
                      map_one' := (_ : OneHom.toFun (↑src.toMonoidHom) 1 = 1) },
                  map_mul' :=
                    (_ :
                      ∀ (x y : R),
                        OneHom.toFun (↑src.toMonoidHom) (x * y) =
                          OneHom.toFun (↑src.toMonoidHom) x * OneHom.toFun (↑src.toMonoidHom) y) },
              map_zero' :=
                (_ :
                  OneHom.toFun
                      (↑{
                          toOneHom :=
                            { toFun := ⇑(Submonoid.LocalizationMap.toMap (monoidOf M)),
                              map_one' := (_ : OneHom.toFun (↑src.toMonoidHom) 1 = 1) },
                          map_mul' :=
                            (_ :
                              ∀ (x y : R),
                                OneHom.toFun (↑src.toMonoidHom) (x * y) =
                                  OneHom.toFun (↑src.toMonoidHom) x * OneHom.toFun (↑src.toMonoidHom) y) })
                      0 =
                    0),
              map_add' := (_ : ∀ (x y : R), mk (x + y) 1 = mk x 1 + mk y 1) })
            (algebraMap S R))
          s *
        mk (fst, snd).1 (fst, snd).2 =
      mk (fst, snd).1 (fst, snd).2 *
        (RingHom.comp
            (let src := monoidOf M;
            {
              toMonoidHom :=
                {
                  toOneHom :=
                    { toFun := ⇑(Submonoid.LocalizationMap.toMap (monoidOf M)),
                      map_one' := (_ : OneHom.toFun (↑src.toMonoidHom) 1 = 1) },
                  map_mul' :=
                    (_ :
                      ∀ (x y : R),
                        OneHom.toFun (↑src.toMonoidHom) (x * y) =
                          OneHom.toFun (↑src.toMonoidHom) x * OneHom.toFun (↑src.toMonoidHom) y) },
              map_zero' :=
                (_ :
                  OneHom.toFun
                      (↑{
                          toOneHom :=
                            { toFun := ⇑(Submonoid.LocalizationMap.toMap (monoidOf M)),
                              map_one' := (_ : OneHom.toFun (↑src.toMonoidHom) 1 = 1) },
                          map_mul' :=
                            (_ :
                              ∀ (x y : R),
                                OneHom.toFun (↑src.toMonoidHom) (x * y) =
                                  OneHom.toFun (↑src.toMonoidHom) x * OneHom.toFun (↑src.toMonoidHom) y) })
                      0 =
                    0),
              map_add' := (_ : ∀ (x y : R), mk (x + y) 1 = mk x 1 + mk y 1) })
            (algebraMap S R))
          s

Next tactic:
intro r x