/-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a`
and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/
theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M]
    [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG)
    (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by
  let A' : Subalgebra R A :=
    { carrier := { x | ∀ n ∈ N, x • n ∈ N }
      mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn)
      one_mem' := fun n hn => (one_smul A n).symm ▸ hn
      add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn)
      zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem
      algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn }
  let f : A' →ₐ[R] Module.End R N :=
    AlgHom.ofLinearMap
      { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop
        -- porting note: was
                -- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n`
        map_add' := by intros x y; ext; exact add_smul _ _ _
        -- porting note: was
                --  `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n`
        map_smul' := by intros r s; ext; apply smul_assoc }
      -- porting note: the next two lines were
      --`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>`
      --`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n`
      (by ext; apply one_smul)
      (by intros x y; ext; apply mul_smul)
  obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by
    by_contra! h'
    apply hN
    rwa [eq_bot_iff]
  have : Function.Injective f := by
    show Function.Injective f.toLinearMap
    rw [← LinearMap.ker_eq_bot, eq_bot_iff]
    intro s hs
    have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩)
    exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂)
  show IsIntegral R (A'.val ⟨x, hx⟩)
  

Proof state:
case intro.intro
R : Type u_1
A : Type u_2
B : Type u_3
S : Type u_4
inst✝¹⁰ : CommRing R
inst✝⁹ : CommRing A
inst✝⁸ : Ring B
inst✝⁷ : CommRing S
inst✝⁶ : Algebra R A
inst✝⁵ : Algebra R B
f✝ : R →+* S
M : Type u_5
inst✝⁴ : AddCommGroup M
inst✝³ : Module R M
inst✝² : Module A M
inst✝¹ : IsScalarTower R A M
inst✝ : NoZeroSMulDivisors A M
N : Submodule R M
hN : N ≠ ⊥
hN' : FG N
x : A
hx : ∀ n ∈ N, x • n ∈ N
A' : Subalgebra R A :=
  {
    toSubsemiring :=
      {
        toSubmonoid :=
          {
            toSubsemigroup :=
              { carrier := {x | ∀ n ∈ N, x • n ∈ N},
                mul_mem' :=
                  (_ :
                    ∀ {a b : A},
                      a ∈ {x | ∀ n ∈ N, x • n ∈ N} → b ∈ {x | ∀ n ∈ N, x • n ∈ N} → ∀ n ∈ N, (a * b) • n ∈ N) },
            one_mem' := (_ : ∀ n ∈ N, 1 • n ∈ N) },
        add_mem' :=
          (_ :
            ∀ {a b : A},
              a ∈
                  {
                        toSubsemigroup :=
                          { carrier := {x | ∀ n ∈ N, x • n ∈ N},
                            mul_mem' :=
                              (_ :
                                ∀ {a b : A},
                                  a ∈ {x | ∀ n ∈ N, x • n ∈ N} →
                                    b ∈ {x | ∀ n ∈ N, x • n ∈ N} → ∀ n ∈ N, (a * b) • n ∈ N) },
                        one_mem' := (_ : ∀ n ∈ N, 1 • n ∈ N) }.toSubsemigroup.carrier →
                b ∈
                    {
                          toSubsemigroup :=
                            { carrier := {x | ∀ n ∈ N, x • n ∈ N},
                              mul_mem' :=
                                (_ :
                                  ∀ {a b : A},
                                    a ∈ {x | ∀ n ∈ N, x • n ∈ N} →
                                      b ∈ {x | ∀ n ∈ N, x • n ∈ N} → ∀ n ∈ N, (a * b) • n ∈ N) },
                          one_mem' := (_ : ∀ n ∈ N, 1 • n ∈ N) }.toSubsemigroup.carrier →
                  ∀ n ∈ N, (a + b) • n ∈ N),
        zero_mem' := (_ : ∀ n ∈ N, 0 • n ∈ N) },
    algebraMap_mem' := (_ : ∀ (r : R), ∀ n ∈ N, (algebraMap R A) r • n ∈ N) }
f : ↥A' →ₐ[R] Module.End R ↥N :=
  AlgHom.ofLinearMap
    {
      toAddHom :=
        { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
          map_add' :=
            (_ :
              ∀ (x y : ↥A'),
                (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) },
      map_smul' :=
        (_ :
          ∀ (r : R) (s : ↥A'),
            AddHom.toFun
                { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                  map_add' :=
                    (_ :
                      ∀ (x y : ↥A'),
                        (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                            (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) }
                (r • s) =
              (RingHom.id R) r •
                AddHom.toFun
                  { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                    map_add' :=
                      (_ :
                        ∀ (x y : ↥A'),
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                            (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                              (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) }
                  s) }
    (_ :
      {
            toAddHom :=
              { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                map_add' :=
                  (_ :
                    ∀ (x y : ↥A'),
                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                        (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) },
            map_smul' :=
              (_ :
                ∀ (r : R) (s : ↥A'),
                  AddHom.toFun
                      { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                        map_add' :=
                          (_ :
                            ∀ (x y : ↥A'),
                              (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                                (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) }
                      (r • s) =
                    (RingHom.id R) r •
                      AddHom.toFun
                        { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                          map_add' :=
                            (_ :
                              ∀ (x y : ↥A'),
                                (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                    (x + y) =
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                      y) }
                        s) }
          1 =
        1)
    (_ :
      ∀ (x y : ↥A'),
        {
              toAddHom :=
                { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                  map_add' :=
                    (_ :
                      ∀ (x y : ↥A'),
                        (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                            (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) },
              map_smul' :=
                (_ :
                  ∀ (r : R) (s : ↥A'),
                    AddHom.toFun
                        { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                          map_add' :=
                            (_ :
                              ∀ (x y : ↥A'),
                                (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                    (x + y) =
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                      y) }
                        (r • s) =
                      (RingHom.id R) r •
                        AddHom.toFun
                          { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                            map_add' :=
                              (_ :
                                ∀ (x y : ↥A'),
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                      (x + y) =
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                        y) }
                          s) }
            (x * y) =
          {
                toAddHom :=
                  { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                    map_add' :=
                      (_ :
                        ∀ (x y : ↥A'),
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                            (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                              (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) },
                map_smul' :=
                  (_ :
                    ∀ (r : R) (s : ↥A'),
                      AddHom.toFun
                          { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                            map_add' :=
                              (_ :
                                ∀ (x y : ↥A'),
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                      (x + y) =
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                        y) }
                          (r • s) =
                        (RingHom.id R) r •
                          AddHom.toFun
                            { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                              map_add' :=
                                (_ :
                                  ∀ (x y : ↥A'),
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                        (x + y) =
                                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                          x +
                                        (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                          y) }
                            s) }
              x *
            {
                toAddHom :=
                  { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                    map_add' :=
                      (_ :
                        ∀ (x y : ↥A'),
                          (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) (x + y) =
                            (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                              (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) y) },
                map_smul' :=
                  (_ :
                    ∀ (r : R) (s : ↥A'),
                      AddHom.toFun
                          { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                            map_add' :=
                              (_ :
                                ∀ (x y : ↥A'),
                                  (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                      (x + y) =
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A')) x +
                                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                        y) }
                          (r • s) =
                        (RingHom.id R) r •
                          AddHom.toFun
                            { toFun := fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'),
                              map_add' :=
                                (_ :
                                  ∀ (x y : ↥A'),
                                    (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                        (x + y) =
                                      (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                          x +
                                        (fun x => LinearMap.restrict (DistribMulAction.toLinearMap R M x) (_ : ↑x ∈ A'))
                                          y) }
                            s) }
              y)
a : M
ha₁ : a ∈ N
ha₂ : a ≠ 0
this : Function.Injective ⇑f
⊢ IsIntegral R ((Subalgebra.val A') { val := x, property := hx })

Next tactic:
rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this]