theorem generator_maximal_submoduleImage_dvd {N O : Submodule R M} (hNO : N ≤ O) {ϕ : O →ₗ[R] R}
    (hϕ : ∀ ψ : O →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N)
    [(ϕ.submoduleImage N).IsPrincipal] (y : M) (yN : y ∈ N)
    (ϕy_eq : ϕ ⟨y, hNO yN⟩ = generator (ϕ.submoduleImage N)) (ψ : O →ₗ[R] R) :
    generator (ϕ.submoduleImage N) ∣ ψ ⟨y, hNO yN⟩ := by
  let a : R := generator (ϕ.submoduleImage N)
  let d : R := IsPrincipal.generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩})
  have d_dvd_left : d ∣ a := (mem_iff_generator_dvd _).mp (subset_span (mem_insert _ _))
  have d_dvd_right : d ∣ ψ ⟨y, hNO yN⟩ :=
    (mem_iff_generator_dvd _).mp (subset_span (mem_insert_of_mem _ (mem_singleton _)))
  refine' dvd_trans _ d_dvd_right
  rw [dvd_generator_iff, Ideal.span, ←
    span_singleton_generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩})]
  obtain ⟨r₁, r₂, d_eq⟩ : ∃ r₁ r₂ : R, d = r₁ * a + r₂ * ψ ⟨y, hNO yN⟩ := by
    obtain ⟨r₁, r₂', hr₂', hr₁⟩ :=
      mem_span_insert.mp (IsPrincipal.generator_mem (Submodule.span R {a, ψ ⟨y, hNO yN⟩}))
    obtain ⟨r₂, rfl⟩ := mem_span_singleton.mp hr₂'
    exact ⟨r₁, r₂, hr₁⟩
  let ψ' : O →ₗ[R] R := r₁ • ϕ + r₂ • ψ
  have : span R {d} ≤ ψ'.submoduleImage N := by
    rw [span_le, singleton_subset_iff, SetLike.mem_coe, LinearMap.mem_submoduleImage_of_le hNO]
    refine' ⟨y, yN, _⟩
    change r₁ * ϕ ⟨y, hNO yN⟩ + r₂ * ψ ⟨y, hNO yN⟩ = d
    rw [d_eq, ϕy_eq]
  refine'
    le_antisymm (this.trans (le_of_eq _)) (Ideal.span_singleton_le_span_singleton.mpr d_dvd_left)
  

Proof state:
case intro.intro
ι : Type u_1
R : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : IsPrincipalIdealRing R
M : Type u_3
inst✝² : AddCommGroup M
inst✝¹ : Module R M
b : ι → M
N O : Submodule R M
hNO : N ≤ O
ϕ : ↥O →ₗ[R] R
hϕ : ∀ (ψ : ↥O →ₗ[R] R), ¬LinearMap.submoduleImage ϕ N < LinearMap.submoduleImage ψ N
inst✝ : IsPrincipal (LinearMap.submoduleImage ϕ N)
y : M
yN : y ∈ N
ϕy_eq : ϕ { val := y, property := (_ : y ∈ O) } = generator (LinearMap.submoduleImage ϕ N)
ψ : ↥O →ₗ[R] R
a : R := generator (LinearMap.submoduleImage ϕ N)
d : R := generator (span R {a, ψ { val := y, property := (_ : y ∈ O) }})
d_dvd_left : d ∣ a
d_dvd_right : d ∣ ψ { val := y, property := (_ : y ∈ O) }
r₁ r₂ : R
d_eq : d = r₁ * a + r₂ * ψ { val := y, property := (_ : y ∈ O) }
ψ' : ↥O →ₗ[R] R := r₁ • ϕ + r₂ • ψ
this : span R {d} ≤ LinearMap.submoduleImage ψ' N
⊢ LinearMap.submoduleImage ψ' N = span R {generator (LinearMap.submoduleImage ϕ N)}
ι : Type u_1
R : Type u_2
inst✝⁵ : CommRing R
inst✝⁴ : IsDomain R
inst✝³ : IsPrincipalIdealRing R
M : Type u_3
inst✝² : AddCommGroup M
inst✝¹ : Module R M
b : ι → M
N O : Submodule R M
hNO : N ≤ O
ϕ : ↥O →ₗ[R] R
hϕ : ∀ (ψ : ↥O →ₗ[R] R), ¬LinearMap.submoduleImage ϕ N < LinearMap.submoduleImage ψ N
inst✝ : IsPrincipal (LinearMap.submoduleImage ϕ N)
y : M
yN : y ∈ N
ϕy_eq : ϕ { val := y, property := (_ : y ∈ O) } = generator (LinearMap.submoduleImage ϕ N)
ψ : ↥O →ₗ[R] R
a : R := generator (LinearMap.submoduleImage ϕ N)
d : R := generator (span R {a, ψ { val := y, property := (_ : y ∈ O) }})
d_dvd_left : d ∣ a
d_dvd_right : d ∣ ψ { val := y, property := (_ : y ∈ O) }
⊢ generator (LinearMap.submoduleImage ϕ N) ∈ span R {a, ψ { val := y, property := (_ : y ∈ O) }}

Next tactic:
rw [span_singleton_generator]