-- Lean 4 proof step from Mathlib.Algebra.Module.PID (goal)
Goal:
R : Type u
inst : CommRing R
inst_1 : IsPrincipalIdealRing R
inst_2 : IsDomain R
p : R
hp : Irreducible p
d : ℕ
M : Type v
inst_3 : AddCommGroup M
inst_4 : Module R M
hM : IsTorsion'.{v, u} M ↥(Submonoid.powers p)
s : Fin (d + 1) → M
hs : Eq (α := Submodule R M) (Submodule.span R (Set.range s)) ⊤
this_1 : (x : M) → Decidable (x = 0)
j : Fin d.succ
hj : IsTorsionBy R M (p ^ pOrder hM (s j))
s' : Fin d → HasQuotient.Quotient M (B := Submodule R M) (R ∙ s j) := Submodule.Quotient.mk ∘ s ∘ j.succAbove
k : Fin d → ℕ
f :
  LinearEquiv.{u, u, v, u} (RingHom.id R) (HasQuotient.Quotient M (B := Submodule R M) (R ∙ s j))
    (⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
this :
  ∀ (i : Fin d),
    ∃ (x : M),
      p ^ k i • x = 0 ∧
        Eq.{u + 1} (α := ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
          ((f : (a : M ⧸ R ∙ s j) → ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i) (Submodule.Quotient.mk x) :
            ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
          (((DirectSum.lof R (Fin d) (fun (i : Fin d) ↦ HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i)) i :
                  HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i) →ₗ[R]
                    ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i)) :
                (a : R ⧸ R ∙ p ^ k i) → ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i)
              1 :
            ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
h :
  LinearMap.range (M := ↥(R ∙ s j)) (Submodule.subtype (R ∙ s j)) =
    ((↑f : M ⧸ R ∙ s j →ₗ[R] ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i) ∘ₗ mkQ (R ∙ s j)).ker
⊢ M ≃ₗ[R]
    ⨁ (i : Fin (d + 1)),
      HasQuotient.Quotient R (B := Submodule R R)
        (R ∙
          HPow.hPow (β := ℕ) p
            ((fun (i : Option (Fin d)) ↦
                (Option.rec (motive := fun (x : Option (Fin d)) ↦ ℕ) (pOrder hM (s j)) k i : ℕ))
              ((finSuccEquiv d : (a : Fin (d + 1)) → Option (Fin d)) i)))
have h₁ : (((↑f : M ⧸ R ∙ s j →ₗ[R] ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i) ∘ₗ mkQ (R ∙ s j)) ∘ₗ
    DirectSum.toModule R (Fin d) (M := fun (i : Fin d) ↦ HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i)) M
      fun (i : Fin d) ↦
      liftQSpanSingleton (p ^ k i)
        (LinearMap.toSpanSingleton R M
          (sorry.choose (p := fun (x : M) ↦
            p ^ k i • x = 0 ∧
              Eq.{u + 1} (α := ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
                ((f : (a : M ⧸ R ∙ s j) → ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i) (Submodule.Quotient.mk x) :
                  ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
                (((DirectSum.lof R (Fin d) (fun (i : Fin d) ↦ HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i))
                          i :
                        HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i) →ₗ[R]
                          ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i)) :
                      (a : R ⧸ R ∙ p ^ k i) → ⨁ (i : Fin d), R ⧸ R ∙ p ^ k i)
                    1 :
                  ⨁ (i : Fin d), HasQuotient.Quotient R (B := Submodule R R) (R ∙ p ^ k i)))))
        sorry) =
  LinearMap.id
Tactic: refine
          (lequivProdOfRightSplitExact
            (g := f.toLinearMap.comp <| mkQ _)
            (f := (DirectSum.toModule _ _ _ fun i => (liftQSpanSingleton (p ^ k i)
                (LinearMap.toSpanSingleton _ _ _) (this i).choose_spec.left : R ⧸ _ →ₗ[R] _)))
              (R ∙ s j).injective_subtype ?_ ?_).symm ≪≫ₗ
          (((quotTorsionOfEquivSpanSingleton R M (s j)).symm ≪≫ₗ
            (quotEquivOfEq (torsionOf R M (s j)) _
              (Ideal.torsionOf_eq_span_pow_pOrder hp hM (s j)))).prodCongr (.refl _ _)) ≪≫ₗ
          (@DirectSum.lequivProdDirectSum R _ _
            (fun i => R ⧸ R ∙ p ^ @Option.rec _ (fun _ => ℕ) (pOrder hM <| s j) k i) _ _).symm ≪≫ₗ
          (DirectSum.lequivCongrLeft R (finSuccEquiv d).symm)