[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Limits.Over).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
instance createsColimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) :
    CreatesColimitsOfSize.{w, w'} (map f ⋙ forget Y)
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.CategoryTheory.Limits.Over.hasColimit_of_hasColimit_comp_forget (L39-L42)
instance hasColimit_of_hasColimit_comp_forget (F : J ⥤ Over X) [i : HasColimit (F ⋙ forget X)] :
    HasColimit F :=
CostructuredArrow.hasColimit (i₁ := i)
```

-- snippet 2
```lean
-- Mathlib.CategoryTheory.Limits.Over.createsColimitsOfSize (L54-L57)
instance createsColimitsOfSize : CreatesColimitsOfSize.{w, w'} (forget X) :=
CostructuredArrow.createsColimitsOfSize

-- We can automatically infer that the forgetful functor preserves and reflects colimits.
```

-- snippet 3
```lean
-- Mathlib.CategoryTheory.Limits.Over.epi_left_of_epi (L65-L67)
theorem epi_left_of_epi [HasPushouts C] {f g : Over X} (h : f ⟶ g) [Epi h] : Epi h.left :=
CostructuredArrow.epi_left_of_epi _
```

-- snippet 4
```lean
-- Mathlib.CategoryTheory.Limits.Over.epi_iff_epi_left (L68-L70)
theorem epi_iff_epi_left [HasPushouts C] {f g : Over X} (h : f ⟶ g) : Epi h ↔ Epi h.left :=
CostructuredArrow.epi_iff_epi_left _
```

-- snippet 5
```lean
-- Mathlib.CategoryTheory.Limits.Over.preservesColimitsOfSize_map (L75-L79)
instance preservesColimitsOfSize_map [HasColimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) :
    PreservesColimitsOfSize.{w, w'} (map f) :=
preservesColimits_of_reflects_of_preserves (map f) (forget Y)

/-- If `c` is a colimit cocone, then so is the cocone `c.toOver` with cocone point `𝟙 c.pt`. -/
```

-- snippet 6
```lean
-- Mathlib.CategoryTheory.Limits.Over.isColimitToOver (L80-L84)
def isColimitToOver {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsColimit c.toOver :=
isColimitOfReflects (forget c.pt) <| IsColimit.equivIsoColimit c.mapCoconeToOver.symm hc

/-- If `F` has a colimit, then the cocone `colimit.toOver F` with cocone point `𝟙 (colimit F)` is
    also a colimit cocone. -/
```

-- snippet 7
```lean
-- Mathlib.CategoryTheory.Limits.Over.hasLimit_of_hasLimit_comp_forget (L105-L108)
instance hasLimit_of_hasLimit_comp_forget (F : J ⥤ Under X) [i : HasLimit (F ⋙ forget X)] :
    HasLimit F :=
StructuredArrow.hasLimit (i₁ := i)
```

-- snippet 8
```lean
-- Mathlib.CategoryTheory.Limits.Over.mono_right_of_mono (L115-L117)
theorem mono_right_of_mono [HasPullbacks C] {f g : Under X} (h : f ⟶ g) [Mono h] : Mono h.right :=
StructuredArrow.mono_right_of_mono _
```

-- snippet 9
```lean
-- Mathlib.CategoryTheory.Limits.Over.mono_iff_mono_right (L118-L120)
theorem mono_iff_mono_right [HasPullbacks C] {f g : Under X} (h : f ⟶ g) : Mono h ↔ Mono h.right :=
StructuredArrow.mono_iff_mono_right _
```

-- snippet 10
```lean
-- Mathlib.CategoryTheory.Limits.Over.createsLimitsOfSize (L121-L124)
instance createsLimitsOfSize : CreatesLimitsOfSize.{w, w'} (forget X) :=
StructuredArrow.createsLimitsOfSize

-- We can automatically infer that the forgetful functor preserves and reflects limits.
```

-- snippet 11
```lean
-- Mathlib.CategoryTheory.Limits.Over.createLimitsOfSizeMapCompForget (L131-L134)
instance createLimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) :
    CreatesLimitsOfSize.{w, w'} (map f ⋙ forget X) :=
show CreatesLimitsOfSize.{w, w'} (forget Y) from inferInstance
```

-- snippet 12
```lean
-- Mathlib.CategoryTheory.Limits.Over.preservesLimitsOfSize_map (L135-L139)
instance preservesLimitsOfSize_map [HasLimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) :
    PreservesLimitsOfSize.{w, w'} (map f) :=
preservesLimits_of_reflects_of_preserves (map f) (forget X)

/-- If `c` is a limit cone, then so is the cone `c.toUnder` with cone point `𝟙 c.pt`. -/
```

-- snippet 13
```lean
-- Mathlib.CategoryTheory.Limits.Over.isLimitToUnder (L140-L144)
def isLimitToUnder {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) : IsLimit c.toUnder :=
isLimitOfReflects (forget c.pt) (IsLimit.equivIsoLimit c.mapConeToUnder.symm hc)

/-- If `F` has a limit, then the cone `limit.toUnder F` with cone point `𝟙 (limit F)` is
    also a limit cone. -/
```

-- snippet 14
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_leftFunc (L204-L207)
instance preservesColimitsOfShape_leftFunc [HasColimitsOfShape J T] :
    PreservesColimitsOfShape J (Arrow.leftFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_fst
```

-- snippet 15
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_snd (L169-L180)
instance preservesColimitsOfShape_snd [HasColimitsOfShape J A] [HasColimitsOfShape J B]
    [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.snd L R) where
  preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
      (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
      (colimit.isColimit _)

end Comma

namespace Arrow

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 16
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimits (L189-L192)
instance hasLimits [HasLimits T] : HasLimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 17
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.ι_colimitLimitToLimitColimit_π (L91-L96)
theorem ι_colimitLimitToLimitColimit_π (j) (k) :
    colimit.ι _ k ≫ colimitLimitToLimitColimit F ≫ limit.π _ j =
      limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k := by
dsimp [colimitLimitToLimitColimit]
  simp
```

-- snippet 18
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimit (L151-L154)
instance hasColimit (F : J ⥤ Comma L R) [HasColimit (F ⋙ fst L R)] [HasColimit (F ⋙ snd L R)]
    [PreservesColimit (F ⋙ fst L R) L] : HasColimit F :=
HasColimit.mk ⟨_, coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)⟩
```

-- snippet 19
```lean
-- Mathlib.CategoryTheory.Limits.Comma.colimitAuxiliaryCocone (L94-L101)
def colimitAuxiliaryCocone (c₂ : Cocone (F ⋙ snd L R)) : Cocone ((F ⋙ fst L R) ⋙ L) :=
(Cocone.precompose (whiskerLeft F (Comma.natTrans L R) :)).obj (R.mapCocone c₂)

/--
If `L` preserves the appropriate colimit, then given a colimit cocone for `F ⋙ fst L R : J ⥤ L` and
a cocone for `F ⋙ snd L R : J ⥤ R` we can build a cocone for `F` which will turn out to be a
colimit cocone.
-/
```

-- snippet 20
```lean
-- Mathlib.CategoryTheory.Limits.Comma.mono_right_of_mono (L247-L250)
instance mono_right_of_mono [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
    {Y Z : StructuredArrow X G} (f : Y ⟶ Z) [Mono f] : Mono f.right :=
show Mono ((proj X G).map f) from inferInstance
```

-- snippet 21
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimit (L140-L143)
instance hasLimit (F : J ⥤ Comma L R) [HasLimit (F ⋙ fst L R)] [HasLimit (F ⋙ snd L R)]
    [PreservesLimit (F ⋙ snd L R) R] : HasLimit F :=
HasLimit.mk ⟨_, coneOfPreservesIsLimit _ (limit.isLimit _) (limit.isLimit _)⟩
```

-- snippet 22
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.map_id_right_eq_curry_swap_map (L47-L89)
theorem map_id_right_eq_curry_swap_map {j j' : J} {f : j ⟶ j'} {k : K} :
    F.map (f ×ₘ 𝟙 k) = ((curry.obj (Prod.swap K J ⋙ F)).obj k).map f :=
rfl

variable [HasLimitsOfShape J C]
variable [HasColimitsOfShape K C]

set_option backward.isDefEq.respectTransparency false in
/-- The universal morphism
$\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$.
-/
noncomputable def colimitLimitToLimitColimit :
    colimit (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) ⟶ limit (curry.obj F ⋙ colim) :=
  limit.lift (curry.obj F ⋙ colim)
    { pt := _
      π :=
        { app := fun j =>
            colimit.desc (curry.obj (Prod.swap K J ⋙ F) ⋙ lim)
              { pt := _
                ι :=
                  { app := fun k =>
                      limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫
                        colimit.ι ((curry.obj F).obj j) k
                    naturality := by
                      intro k k' f
                      simp only [Functor.comp_obj, lim_obj, colimit.cocone_x,
                        Functor.const_obj_obj, Functor.comp_map, lim_map,
                        curry_obj_obj_obj, Prod.swap_obj, limMap_π_assoc, curry_obj_map_app,
                        Prod.swap_map, Functor.const_obj_map, Category.comp_id]
                      rw [map_id_left_eq_curry_map, colimit.w] } }
          naturality := by
            intro j j' f
            dsimp
            ext k
            simp only [Functor.comp_obj, lim_obj, Category.id_comp, colimit.ι_desc,
              colimit.ι_desc_assoc, Category.assoc, ι_colimMap,
              curry_obj_obj_obj, curry_obj_map_app]
            rw [map_id_right_eq_curry_swap_map, limit.w_assoc] } }

set_option backward.isDefEq.respectTransparency false in
/-- Since `colimit_limit_to_limit_colimit` is a morphism from a colimit to a limit,
this lemma characterises it.
-/
```

-- snippet 23
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.finBiconeHom (L124-L157)
instance finBiconeHom [FinCategory J] (j k : Bicone J) : Fintype (j ⟶ k) := by
cases j <;> cases k
  · exact
      { elems := {BiconeHom.left_id}
        complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := {BiconeHom.left _}
      complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
      { elems := {BiconeHom.right_id}
        complete := fun f => by cases f; simp }
  · exact
    { elems := {BiconeHom.right _}
      complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := Finset.image BiconeHom.diagram Fintype.elems
      complete := fun f => by
        rcases f with (_ | _ | _ | _ | f)
        simp only [Finset.mem_image]
        use f
        simpa using Fintype.complete _ }
```

-- snippet 24
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.ι_colimitLimitToLimitColimit_π_apply (L98-L106)
theorem ι_colimitLimitToLimitColimit_π_apply [Small.{v} J] [Small.{v} K] (F : J × K ⥤ Type v)
    (j : J) (k : K) (f) : limit.π (curry.obj F ⋙ colim) j
        (colimitLimitToLimitColimit F (colimit.ι (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) k f)) =
      colimit.ι ((curry.obj F).obj j) k (limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j f) := by
dsimp [colimitLimitToLimitColimit]
  simp

set_option backward.isDefEq.respectTransparency false in
/-- The map `colimit_limit_to_limit_colimit` realized as a map of cones. -/
```

-- snippet 25
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimits (L201-L203)
instance hasColimits [HasColimits T] : HasColimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 26
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_fst (L162-L168)
instance preservesColimitsOfShape_fst [HasColimitsOfShape J A] [HasColimitsOfShape J B]
    [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.fst L R) where
  preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
      (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
      (colimit.isColimit _)
```

-- snippet 27
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.map_id_left_eq_curry_map (L43-L46)
theorem map_id_left_eq_curry_map {j : J} {k k' : K} {f : k ⟶ k'} :
    F.map (𝟙 j ×ₘ f) = ((curry.obj F).obj j).map f :=
rfl
```

-- snippet 28
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimitsOfSize (L158-L161)
instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [HasColimitsOfSize.{w, w'} B]
    [PreservesColimitsOfSize.{w, w'} L] : HasColimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 29
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeSmallCategory (L158-L160)
instance biconeSmallCategory : SmallCategory (Bicone J) :=
CategoryTheory.biconeCategory J
```

-- snippet 30
```lean
-- Mathlib.CategoryTheory.Limits.Comma.mono_iff_mono_right (L251-L260)
theorem mono_iff_mono_right [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
    {Y Z : StructuredArrow X G} (f : Y ⟶ Z) : Mono f ↔ Mono f.right :=
⟨fun _ => inferInstance, fun _ => mono_of_mono_right f⟩

end StructuredArrow

namespace CostructuredArrow

variable {G : A ⥤ T} {X : T} (F : J ⥤ CostructuredArrow G X)
```

-- snippet 31
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeCategoryStruct (L74-L87)
instance biconeCategoryStruct : CategoryStruct (Bicone J) where
  Hom := BiconeHom J
id j := Bicone.casesOn j BiconeHom.left_id BiconeHom.right_id fun k => BiconeHom.diagram (𝟙 k)
  comp f g := by
    rcases f with (_ | _ | _ | _ | f)
    · exact g
    · exact g
    · cases g
      apply BiconeHom.left
    · cases g
      apply BiconeHom.right
    · rcases g with (_ | _ | _ | _ | g)
      exact BiconeHom.diagram (f ≫ g)
```

-- snippet 32
```lean
-- Mathlib.CategoryTheory.Limits.Comma.limitAuxiliaryCone (L47-L53)
def limitAuxiliaryCone (c₁ : Cone (F ⋙ fst L R)) : Cone ((F ⋙ snd L R) ⋙ R) :=
(Cone.postcompose (whiskerLeft F (Comma.natTrans L R) :)).obj (L.mapCone c₁)

/-- If `R` preserves the appropriate limit, then given a cone for `F ⋙ fst L R : J ⥤ L` and a
limit cone for `F ⋙ snd L R : J ⥤ R` we can build a cone for `F` which will turn out to be a limit
cone.
-/
```

-- snippet 33
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeCategory (L88-L100)
instance biconeCategory : Category (Bicone J) where
  id_comp f := by cases f <;> simp
comp_id f := by cases f <;> simp
  assoc f g h := by cases f <;> cases g <;> cases h <;> simp

end Bicone

section SmallCategory

variable (J : Type v₁) [SmallCategory J]

/-- Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C`.
-/
```

-- snippet 34
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.BiconeHom (L70-L72)
instance BiconeHom.decidableEq {j k : Bicone J} : DecidableEq (BiconeHom J j k) := fun f g => by
classical cases f <;> cases g <;> simp only [diagram.injEq] <;> infer_instance
```

-- snippet 35
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.finBicone (L52-L66)
instance finBicone [Fintype J] : Fintype (Bicone J) where
  elems := [Bicone.left, Bicone.right].toFinset ∪ Finset.image Bicone.diagram Fintype.elems
complete j := by
    cases j <;> simp [Fintype.complete]

variable [Category.{v₁} J]

/-- The homs for a walking `Bicone J`. -/
inductive BiconeHom : Bicone J → Bicone J → Type max u₁ v₁
  | left_id : BiconeHom Bicone.left Bicone.left
  | right_id : BiconeHom Bicone.right Bicone.right
  | left (j : J) : BiconeHom Bicone.left (Bicone.diagram j)
  | right (j : J) : BiconeHom Bicone.right (Bicone.diagram j)
  | diagram {j k : J} (f : j ⟶ k) : BiconeHom (Bicone.diagram j) (Bicone.diagram k)
```

-- snippet 36
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeMk (L102-L123)
def biconeMk {C : Type u₁} [Category.{v₁} C] {F : J ⥤ C} (c₁ c₂ : Cone F) : Bicone J ⥤ C where
  obj X := Bicone.casesOn X c₁.pt c₂.pt fun j => F.obj j
map f := by
    rcases f with (_ | _ | _ | _ | f)
    · exact 𝟙 _
    · exact 𝟙 _
    · exact c₁.π.app _
    · exact c₂.π.app _
    · exact F.map f
  map_id X := by cases X <;> simp
  map_comp f g := by
    rcases f with (_ | _ | _ | _ | _)
    · exact (Category.id_comp _).symm
    · exact (Category.id_comp _).symm
    · cases g
      exact (Category.id_comp _).symm.trans (c₁.π.naturality _)
    · cases g
      exact (Category.id_comp _).symm.trans (c₂.π.naturality _)
    · cases g
      apply F.map_comp

open scoped Classical in
```

-- snippet 37
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimitsOfSize (L147-L150)
instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [HasLimitsOfSize.{w, w'} B]
    [PreservesLimitsOfSize.{w, w'} R] : HasLimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 38
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_rightFunc (L208-L218)
instance preservesColimitsOfShape_rightFunc [HasColimitsOfShape J T] :
    PreservesColimitsOfShape J (Arrow.rightFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_snd

end Arrow

namespace StructuredArrow

variable {X : T} {G : A ⥤ T} (F : J ⥤ StructuredArrow X G)

set_option backward.isDefEq.respectTransparency false in
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Limits.Over).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
instance createsColimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) :
    CreatesColimitsOfSize.{w, w'} (map f ⋙ forget Y)
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.CategoryTheory.Limits.Over.hasColimit_of_hasColimit_comp_forget (L39-L42)
instance hasColimit_of_hasColimit_comp_forget (F : J ⥤ Over X) [i : HasColimit (F ⋙ forget X)] :
    HasColimit F :=
CostructuredArrow.hasColimit (i₁ := i)
```

-- snippet 2
```lean
-- Mathlib.CategoryTheory.Limits.Over.createsColimitsOfSize (L54-L57)
instance createsColimitsOfSize : CreatesColimitsOfSize.{w, w'} (forget X) :=
CostructuredArrow.createsColimitsOfSize

-- We can automatically infer that the forgetful functor preserves and reflects colimits.
```

-- snippet 3
```lean
-- Mathlib.CategoryTheory.Limits.Over.epi_left_of_epi (L65-L67)
theorem epi_left_of_epi [HasPushouts C] {f g : Over X} (h : f ⟶ g) [Epi h] : Epi h.left :=
CostructuredArrow.epi_left_of_epi _
```

-- snippet 4
```lean
-- Mathlib.CategoryTheory.Limits.Over.epi_iff_epi_left (L68-L70)
theorem epi_iff_epi_left [HasPushouts C] {f g : Over X} (h : f ⟶ g) : Epi h ↔ Epi h.left :=
CostructuredArrow.epi_iff_epi_left _
```

-- snippet 5
```lean
-- Mathlib.CategoryTheory.Limits.Over.preservesColimitsOfSize_map (L75-L79)
instance preservesColimitsOfSize_map [HasColimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) :
    PreservesColimitsOfSize.{w, w'} (map f) :=
preservesColimits_of_reflects_of_preserves (map f) (forget Y)

/-- If `c` is a colimit cocone, then so is the cocone `c.toOver` with cocone point `𝟙 c.pt`. -/
```

-- snippet 6
```lean
-- Mathlib.CategoryTheory.Limits.Over.isColimitToOver (L80-L84)
def isColimitToOver {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsColimit c.toOver :=
isColimitOfReflects (forget c.pt) <| IsColimit.equivIsoColimit c.mapCoconeToOver.symm hc

/-- If `F` has a colimit, then the cocone `colimit.toOver F` with cocone point `𝟙 (colimit F)` is
    also a colimit cocone. -/
```

-- snippet 7
```lean
-- Mathlib.CategoryTheory.Limits.Over.hasLimit_of_hasLimit_comp_forget (L105-L108)
instance hasLimit_of_hasLimit_comp_forget (F : J ⥤ Under X) [i : HasLimit (F ⋙ forget X)] :
    HasLimit F :=
StructuredArrow.hasLimit (i₁ := i)
```

-- snippet 8
```lean
-- Mathlib.CategoryTheory.Limits.Over.mono_right_of_mono (L115-L117)
theorem mono_right_of_mono [HasPullbacks C] {f g : Under X} (h : f ⟶ g) [Mono h] : Mono h.right :=
StructuredArrow.mono_right_of_mono _
```

-- snippet 9
```lean
-- Mathlib.CategoryTheory.Limits.Over.mono_iff_mono_right (L118-L120)
theorem mono_iff_mono_right [HasPullbacks C] {f g : Under X} (h : f ⟶ g) : Mono h ↔ Mono h.right :=
StructuredArrow.mono_iff_mono_right _
```

-- snippet 10
```lean
-- Mathlib.CategoryTheory.Limits.Over.createsLimitsOfSize (L121-L124)
instance createsLimitsOfSize : CreatesLimitsOfSize.{w, w'} (forget X) :=
StructuredArrow.createsLimitsOfSize

-- We can automatically infer that the forgetful functor preserves and reflects limits.
```

-- snippet 11
```lean
-- Mathlib.CategoryTheory.Limits.Over.createLimitsOfSizeMapCompForget (L131-L134)
instance createLimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) :
    CreatesLimitsOfSize.{w, w'} (map f ⋙ forget X) :=
show CreatesLimitsOfSize.{w, w'} (forget Y) from inferInstance
```

-- snippet 12
```lean
-- Mathlib.CategoryTheory.Limits.Over.preservesLimitsOfSize_map (L135-L139)
instance preservesLimitsOfSize_map [HasLimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) :
    PreservesLimitsOfSize.{w, w'} (map f) :=
preservesLimits_of_reflects_of_preserves (map f) (forget X)

/-- If `c` is a limit cone, then so is the cone `c.toUnder` with cone point `𝟙 c.pt`. -/
```

-- snippet 13
```lean
-- Mathlib.CategoryTheory.Limits.Over.isLimitToUnder (L140-L144)
def isLimitToUnder {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) : IsLimit c.toUnder :=
isLimitOfReflects (forget c.pt) (IsLimit.equivIsoLimit c.mapConeToUnder.symm hc)

/-- If `F` has a limit, then the cone `limit.toUnder F` with cone point `𝟙 (limit F)` is
    also a limit cone. -/
```

-- snippet 14
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_leftFunc (L204-L207)
instance preservesColimitsOfShape_leftFunc [HasColimitsOfShape J T] :
    PreservesColimitsOfShape J (Arrow.leftFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_fst
```

-- snippet 15
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_snd (L169-L180)
instance preservesColimitsOfShape_snd [HasColimitsOfShape J A] [HasColimitsOfShape J B]
    [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.snd L R) where
  preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
      (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
      (colimit.isColimit _)

end Comma

namespace Arrow

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 16
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimits (L189-L192)
instance hasLimits [HasLimits T] : HasLimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩

set_option backward.isDefEq.respectTransparency false in
```

-- snippet 17
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.ι_colimitLimitToLimitColimit_π (L91-L96)
theorem ι_colimitLimitToLimitColimit_π (j) (k) :
    colimit.ι _ k ≫ colimitLimitToLimitColimit F ≫ limit.π _ j =
      limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k := by
dsimp [colimitLimitToLimitColimit]
  simp
```

-- snippet 18
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimit (L151-L154)
instance hasColimit (F : J ⥤ Comma L R) [HasColimit (F ⋙ fst L R)] [HasColimit (F ⋙ snd L R)]
    [PreservesColimit (F ⋙ fst L R) L] : HasColimit F :=
HasColimit.mk ⟨_, coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)⟩
```

-- snippet 19
```lean
-- Mathlib.CategoryTheory.Limits.Comma.colimitAuxiliaryCocone (L94-L101)
def colimitAuxiliaryCocone (c₂ : Cocone (F ⋙ snd L R)) : Cocone ((F ⋙ fst L R) ⋙ L) :=
(Cocone.precompose (whiskerLeft F (Comma.natTrans L R) :)).obj (R.mapCocone c₂)

/--
If `L` preserves the appropriate colimit, then given a colimit cocone for `F ⋙ fst L R : J ⥤ L` and
a cocone for `F ⋙ snd L R : J ⥤ R` we can build a cocone for `F` which will turn out to be a
colimit cocone.
-/
```

-- snippet 20
```lean
-- Mathlib.CategoryTheory.Limits.Comma.mono_right_of_mono (L247-L250)
instance mono_right_of_mono [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
    {Y Z : StructuredArrow X G} (f : Y ⟶ Z) [Mono f] : Mono f.right :=
show Mono ((proj X G).map f) from inferInstance
```

-- snippet 21
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimit (L140-L143)
instance hasLimit (F : J ⥤ Comma L R) [HasLimit (F ⋙ fst L R)] [HasLimit (F ⋙ snd L R)]
    [PreservesLimit (F ⋙ snd L R) R] : HasLimit F :=
HasLimit.mk ⟨_, coneOfPreservesIsLimit _ (limit.isLimit _) (limit.isLimit _)⟩
```

-- snippet 22
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.map_id_right_eq_curry_swap_map (L47-L89)
theorem map_id_right_eq_curry_swap_map {j j' : J} {f : j ⟶ j'} {k : K} :
    F.map (f ×ₘ 𝟙 k) = ((curry.obj (Prod.swap K J ⋙ F)).obj k).map f :=
rfl

variable [HasLimitsOfShape J C]
variable [HasColimitsOfShape K C]

set_option backward.isDefEq.respectTransparency false in
/-- The universal morphism
$\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$.
-/
noncomputable def colimitLimitToLimitColimit :
    colimit (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) ⟶ limit (curry.obj F ⋙ colim) :=
  limit.lift (curry.obj F ⋙ colim)
    { pt := _
      π :=
        { app := fun j =>
            colimit.desc (curry.obj (Prod.swap K J ⋙ F) ⋙ lim)
              { pt := _
                ι :=
                  { app := fun k =>
                      limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫
                        colimit.ι ((curry.obj F).obj j) k
                    naturality := by
                      intro k k' f
                      simp only [Functor.comp_obj, lim_obj, colimit.cocone_x,
                        Functor.const_obj_obj, Functor.comp_map, lim_map,
                        curry_obj_obj_obj, Prod.swap_obj, limMap_π_assoc, curry_obj_map_app,
                        Prod.swap_map, Functor.const_obj_map, Category.comp_id]
                      rw [map_id_left_eq_curry_map, colimit.w] } }
          naturality := by
            intro j j' f
            dsimp
            ext k
            simp only [Functor.comp_obj, lim_obj, Category.id_comp, colimit.ι_desc,
              colimit.ι_desc_assoc, Category.assoc, ι_colimMap,
              curry_obj_obj_obj, curry_obj_map_app]
            rw [map_id_right_eq_curry_swap_map, limit.w_assoc] } }

set_option backward.isDefEq.respectTransparency false in
/-- Since `colimit_limit_to_limit_colimit` is a morphism from a colimit to a limit,
this lemma characterises it.
-/
```

-- snippet 23
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.finBiconeHom (L124-L157)
instance finBiconeHom [FinCategory J] (j k : Bicone J) : Fintype (j ⟶ k) := by
cases j <;> cases k
  · exact
      { elems := {BiconeHom.left_id}
        complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := {BiconeHom.left _}
      complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
      { elems := {BiconeHom.right_id}
        complete := fun f => by cases f; simp }
  · exact
    { elems := {BiconeHom.right _}
      complete := fun f => by cases f; simp }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := ∅
      complete := fun f => by cases f }
  · exact
    { elems := Finset.image BiconeHom.diagram Fintype.elems
      complete := fun f => by
        rcases f with (_ | _ | _ | _ | f)
        simp only [Finset.mem_image]
        use f
        simpa using Fintype.complete _ }
```

-- snippet 24
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.ι_colimitLimitToLimitColimit_π_apply (L98-L106)
theorem ι_colimitLimitToLimitColimit_π_apply [Small.{v} J] [Small.{v} K] (F : J × K ⥤ Type v)
    (j : J) (k : K) (f) : limit.π (curry.obj F ⋙ colim) j
        (colimitLimitToLimitColimit F (colimit.ι (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) k f)) =
      colimit.ι ((curry.obj F).obj j) k (limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j f) := by
dsimp [colimitLimitToLimitColimit]
  simp

set_option backward.isDefEq.respectTransparency false in
/-- The map `colimit_limit_to_limit_colimit` realized as a map of cones. -/
```

-- snippet 25
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimits (L201-L203)
instance hasColimits [HasColimits T] : HasColimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 26
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_fst (L162-L168)
instance preservesColimitsOfShape_fst [HasColimitsOfShape J A] [HasColimitsOfShape J B]
    [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.fst L R) where
  preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
      (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
      (colimit.isColimit _)
```

-- snippet 27
```lean
-- Mathlib.CategoryTheory.Limits.ColimitLimit.map_id_left_eq_curry_map (L43-L46)
theorem map_id_left_eq_curry_map {j : J} {k k' : K} {f : k ⟶ k'} :
    F.map (𝟙 j ×ₘ f) = ((curry.obj F).obj j).map f :=
rfl
```

-- snippet 28
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasColimitsOfSize (L158-L161)
instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [HasColimitsOfSize.{w, w'} B]
    [PreservesColimitsOfSize.{w, w'} L] : HasColimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 29
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeSmallCategory (L158-L160)
instance biconeSmallCategory : SmallCategory (Bicone J) :=
CategoryTheory.biconeCategory J
```

-- snippet 30
```lean
-- Mathlib.CategoryTheory.Limits.Comma.mono_iff_mono_right (L251-L260)
theorem mono_iff_mono_right [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
    {Y Z : StructuredArrow X G} (f : Y ⟶ Z) : Mono f ↔ Mono f.right :=
⟨fun _ => inferInstance, fun _ => mono_of_mono_right f⟩

end StructuredArrow

namespace CostructuredArrow

variable {G : A ⥤ T} {X : T} (F : J ⥤ CostructuredArrow G X)
```

-- snippet 31
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeCategoryStruct (L74-L87)
instance biconeCategoryStruct : CategoryStruct (Bicone J) where
  Hom := BiconeHom J
id j := Bicone.casesOn j BiconeHom.left_id BiconeHom.right_id fun k => BiconeHom.diagram (𝟙 k)
  comp f g := by
    rcases f with (_ | _ | _ | _ | f)
    · exact g
    · exact g
    · cases g
      apply BiconeHom.left
    · cases g
      apply BiconeHom.right
    · rcases g with (_ | _ | _ | _ | g)
      exact BiconeHom.diagram (f ≫ g)
```

-- snippet 32
```lean
-- Mathlib.CategoryTheory.Limits.Comma.limitAuxiliaryCone (L47-L53)
def limitAuxiliaryCone (c₁ : Cone (F ⋙ fst L R)) : Cone ((F ⋙ snd L R) ⋙ R) :=
(Cone.postcompose (whiskerLeft F (Comma.natTrans L R) :)).obj (L.mapCone c₁)

/-- If `R` preserves the appropriate limit, then given a cone for `F ⋙ fst L R : J ⥤ L` and a
limit cone for `F ⋙ snd L R : J ⥤ R` we can build a cone for `F` which will turn out to be a limit
cone.
-/
```

-- snippet 33
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeCategory (L88-L100)
instance biconeCategory : Category (Bicone J) where
  id_comp f := by cases f <;> simp
comp_id f := by cases f <;> simp
  assoc f g h := by cases f <;> cases g <;> cases h <;> simp

end Bicone

section SmallCategory

variable (J : Type v₁) [SmallCategory J]

/-- Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C`.
-/
```

-- snippet 34
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.BiconeHom (L70-L72)
instance BiconeHom.decidableEq {j k : Bicone J} : DecidableEq (BiconeHom J j k) := fun f g => by
classical cases f <;> cases g <;> simp only [diagram.injEq] <;> infer_instance
```

-- snippet 35
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.finBicone (L52-L66)
instance finBicone [Fintype J] : Fintype (Bicone J) where
  elems := [Bicone.left, Bicone.right].toFinset ∪ Finset.image Bicone.diagram Fintype.elems
complete j := by
    cases j <;> simp [Fintype.complete]

variable [Category.{v₁} J]

/-- The homs for a walking `Bicone J`. -/
inductive BiconeHom : Bicone J → Bicone J → Type max u₁ v₁
  | left_id : BiconeHom Bicone.left Bicone.left
  | right_id : BiconeHom Bicone.right Bicone.right
  | left (j : J) : BiconeHom Bicone.left (Bicone.diagram j)
  | right (j : J) : BiconeHom Bicone.right (Bicone.diagram j)
  | diagram {j k : J} (f : j ⟶ k) : BiconeHom (Bicone.diagram j) (Bicone.diagram k)
```

-- snippet 36
```lean
-- Mathlib.CategoryTheory.Limits.Bicones.biconeMk (L102-L123)
def biconeMk {C : Type u₁} [Category.{v₁} C] {F : J ⥤ C} (c₁ c₂ : Cone F) : Bicone J ⥤ C where
  obj X := Bicone.casesOn X c₁.pt c₂.pt fun j => F.obj j
map f := by
    rcases f with (_ | _ | _ | _ | f)
    · exact 𝟙 _
    · exact 𝟙 _
    · exact c₁.π.app _
    · exact c₂.π.app _
    · exact F.map f
  map_id X := by cases X <;> simp
  map_comp f g := by
    rcases f with (_ | _ | _ | _ | _)
    · exact (Category.id_comp _).symm
    · exact (Category.id_comp _).symm
    · cases g
      exact (Category.id_comp _).symm.trans (c₁.π.naturality _)
    · cases g
      exact (Category.id_comp _).symm.trans (c₂.π.naturality _)
    · cases g
      apply F.map_comp

open scoped Classical in
```

-- snippet 37
```lean
-- Mathlib.CategoryTheory.Limits.Comma.hasLimitsOfSize (L147-L150)
instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [HasLimitsOfSize.{w, w'} B]
    [PreservesLimitsOfSize.{w, w'} R] : HasLimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
```

-- snippet 38
```lean
-- Mathlib.CategoryTheory.Limits.Comma.preservesColimitsOfShape_rightFunc (L208-L218)
instance preservesColimitsOfShape_rightFunc [HasColimitsOfShape J T] :
    PreservesColimitsOfShape J (Arrow.rightFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_snd

end Arrow

namespace StructuredArrow

variable {X : T} {G : A ⥤ T} (F : J ⥤ StructuredArrow X G)

set_option backward.isDefEq.respectTransparency false in
```
[/INST]


Instruction: Edit `comp_inv_eq` so it still compiles and the proof is simplified where possible. Return the full updated `comp_inv_eq` block.

[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Iso).

[User]
You are editing a file in `Mathlib/CategoryTheory/Iso.lean` (mathlib commit 5e932f97dd25535344f80f9dd8da3aab83df0fe6).

## Current excerpt (around `Mathlib.CategoryTheory.Iso.comp_inv_eq`, L197-L199)
```lean
theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
```

## Edit instruction
Edit `comp_inv_eq` so it still compiles and the proof is simplified where possible. Return the full updated `comp_inv_eq` block.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Iso).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]You are editing a file in `Mathlib/CategoryTheory/Iso.lean` (mathlib commit 5e932f97dd25535344f80f9dd8da3aab83df0fe6).

## Current excerpt (around `Mathlib.CategoryTheory.Iso.comp_inv_eq`, L197-L199)
```lean
theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
```

## Edit instruction
Edit `comp_inv_eq` so it still compiles and the proof is simplified where possible. Return the full updated `comp_inv_eq` block.
[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Analysis.InnerProductSpace.Projection.Basic).

[User]
The following proof-state transcript was extracted from a real mathlib proof. Use it to answer the question below.

```text
Proof-state transcript for `Mathlib.Analysis.InnerProductSpace.Projection.Basic.starProjection_orthogonalComplement_singleton_eq_zero`:
State 0: ⊢ theorem starProjection_orthogonalComplement_singleton_eq_zero (v : E) :
    (𝕜 ∙ v)ᗮ.starProjection v = 0
Tactic: rw [starProjection_apply, coe_eq_zero]
State 1: ⊢ <goal after rw [starProjection_apply, coe_eq_zero]>
Tactic: exact orthogonalProjection_orthogonalComplement_singleton_eq_zero v  /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its  orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/
```

Question: what is the next tactic after the last recorded state, and why?

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Analysis.InnerProductSpace.Projection.Basic).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]The following proof-state transcript was extracted from a real mathlib proof. Use it to answer the question below.

```text
Proof-state transcript for `Mathlib.Analysis.InnerProductSpace.Projection.Basic.starProjection_orthogonalComplement_singleton_eq_zero`:
State 0: ⊢ theorem starProjection_orthogonalComplement_singleton_eq_zero (v : E) :
    (𝕜 ∙ v)ᗮ.starProjection v = 0
Tactic: rw [starProjection_apply, coe_eq_zero]
State 1: ⊢ <goal after rw [starProjection_apply, coe_eq_zero]>
Tactic: exact orthogonalProjection_orthogonalComplement_singleton_eq_zero v  /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its  orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/
```

Question: what is the next tactic after the last recorded state, and why?[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.RingTheory.Ideal.Over).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
def algEquivOfEqComap (h : P = Q.comap σ) : (B ⧸ P) ≃ₐ[A ⧸ p] (C ⧸ Q)
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.RingTheory.Ideal.Over.comap_eq_of_scalar_tower_quotient (L52-L62)
theorem comap_eq_of_scalar_tower_quotient [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)]
    [IsScalarTower R (R ⧸ p) (S ⧸ P)] (h : Function.Injective (algebraMap (R ⧸ p) (S ⧸ P))) :
    comap (algebraMap R S) P = p := by
ext x
  rw [mem_comap, ← Quotient.eq_zero_iff_mem, ← Quotient.eq_zero_iff_mem, Quotient.mk_algebraMap,
    IsScalarTower.algebraMap_apply R (R ⧸ p) (S ⧸ P), Quotient.algebraMap_eq]
  exact map_eq_zero_iff _ h

variable [Algebra R S]

/-- `R / p` has a canonical map to `S / pS`. -/
```

-- snippet 2
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L63-L65)
instance Quotient.algebraQuotientMapQuotient : Algebra (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
Ideal.Quotient.algebraQuotientOfLEComap le_comap_map
```

-- snippet 3
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L67-L72)
theorem Quotient.algebraMap_quotient_map_quotient (x : R) :
    letI f := algebraMap R S
algebraMap (R ⧸ p) (S ⧸ map f p) (Ideal.Quotient.mk p x) =
    Ideal.Quotient.mk (map f p) (f x) :=
  rfl
```

-- snippet 4
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L74-L78)
theorem Quotient.mk_smul_mk_quotient_map_quotient (x : R) (y : S) :
    letI f := algebraMap R S
Quotient.mk p x • Quotient.mk (map f p) y = Quotient.mk (map f p) (f x * y) :=
  Algebra.smul_def _ _
```

-- snippet 5
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L79-L95)
instance Quotient.tower_quotient_map_quotient :
    IsScalarTower R (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
IsScalarTower.of_algebraMap_eq fun x => by
    rw [Quotient.algebraMap_eq, Quotient.algebraMap_quotient_map_quotient,
      Quotient.mk_algebraMap]

end CommRing

section ideal_liesOver

section Semiring

variable (A : Type*) [CommSemiring A] {B C : Type*} [Semiring B] [Semiring C] [Algebra A B]
  [Algebra A C] (P : Ideal B) {Q : Ideal C} (p : Ideal A)
  {G : Type*} [Group G] [MulSemiringAction G B] [SMulCommClass G A B] (g : G)

/-- The ideal obtained by pulling back the ideal `P` from `B` to `A`. -/
```

-- snippet 6
```lean
-- Mathlib.RingTheory.Ideal.Over.under (L96-L97)
abbrev under : Ideal A := Ideal.comap (algebraMap A B) P
```

-- snippet 7
```lean
-- Mathlib.RingTheory.Ideal.Over.under_def (L98-L99)
theorem under_def : P.under A = Ideal.comap (algebraMap A B) P := rfl
```

-- snippet 8
```lean
-- Mathlib.RingTheory.Ideal.Over.IsPrime (L100-L102)
instance IsPrime.under [hP : P.IsPrime] : (P.under A).IsPrime :=
hP.comap (algebraMap A B)
```

-- snippet 9
```lean
-- Mathlib.RingTheory.Ideal.Over.under_smul (L104-L108)
lemma under_smul : (g • P : Ideal B).under A = P.under A := by
ext a
  rw [mem_comap, mem_comap, mem_pointwise_smul_iff_inv_smul_mem, smul_algebraMap]

variable (B) in
```

-- snippet 10
```lean
-- Mathlib.RingTheory.Ideal.Over.under_top (L109-L113)
theorem under_top : under A (⊤ : Ideal B) = ⊤ := comap_top
variable {A}

/-- `P` lies over `p` if `p` is the preimage of `P` by the `algebraMap`. -/
```

-- snippet 11
```lean
-- Mathlib.RingTheory.Ideal.Over.over_under (L117-L118)
instance over_under : P.LiesOver (P.under A) where over := rfl
```

-- snippet 12
```lean
-- Mathlib.RingTheory.Ideal.Over.over_def (L119-L120)
theorem over_def [P.LiesOver p] : p = P.under A := LiesOver.over
```

-- snippet 13
```lean
-- Mathlib.RingTheory.Ideal.Over.mem_of_liesOver (L121-L125)
theorem mem_of_liesOver [P.LiesOver p] (x : A) : x ∈ p ↔ algebraMap A B x ∈ P := by
rw [P.over_def p]
  rfl

variable (A B) in
```

-- snippet 14
```lean
-- Mathlib.RingTheory.Ideal.Over.top_liesOver_top (L126-L128)
instance top_liesOver_top : (⊤ : Ideal B).LiesOver (⊤ : Ideal A) where
  over := (under_top A B).symm
```

-- snippet 15
```lean
-- Mathlib.RingTheory.Ideal.Over.eq_top_iff_of_liesOver (L129-L132)
theorem eq_top_iff_of_liesOver [P.LiesOver p] : P = ⊤ ↔ p = ⊤ := by
rw [P.over_def p]
  exact comap_eq_top_iff.symm
```

-- snippet 16
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.IsNoetherianRing (L92-L117)
theorem IsNoetherianRing.exists_relSeries_isQuotientEquivQuotientPrime :
    ∃ s : RelSeries {(N₁, N₂) | Submodule.IsQuotientEquivQuotientPrime (A := A) (M := M) N₁ N₂},
s.head = ⊥ ∧ s.last = ⊤ := by
  refine WellFoundedGT.induction_top ⟨⊥, .singleton _ ⊥, rfl, rfl⟩ ?_
  rintro N hN ⟨s, hs₁, hs₂⟩
  have := Submodule.Quotient.nontrivial_iff.mpr hN
  obtain ⟨p, hp⟩ := associatedPrimes.nonempty A (M ⧸ N)
  rw [AssociatedPrimes.mem_iff, isAssociatedPrime_iff] at hp
  obtain ⟨hp, x, rfl⟩ := hp
  obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x
  have hxN : x ∉ N := fun h ↦ hp.ne_top (by rw [show N.mkQ x = 0 by simpa]; simp)
  have := Submodule.isQuotientEquivQuotientPrime_iff.mpr ⟨x, hp, rfl⟩
  refine ⟨_, by simpa [hs₂], s.snoc _ (hs₂ ▸ this), by simpa, rfl⟩

/-- If a property on finitely generated modules over a Noetherian ring satisfies that:

- it holds for zero module (it's formalized as it holds for any module which is subsingleton),
- it holds for `A ⧸ p` for every prime ideal `p` of `A` (to avoid universe problem,
  it's formalized as it holds for any module isomorphic to `A ⧸ p`),
- it is stable by short exact sequences,

then the property holds for every finitely generated modules.

NOTE: This should be the induction principle for `M`, but due to the bug
https://github.com/leanprover/lean4/issues/4246
currently it is induction for `Module.Finite A M`. -/
```

-- snippet 17
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.biUnion_associatedPrimes_eq_zero_divisors (L229-L239)
theorem biUnion_associatedPrimes_eq_zero_divisors [IsNoetherianRing R] :
    ⋃ p ∈ associatedPrimes R M, p = { r : R | ∃ x : M, x ≠ 0 ∧ r • x = 0 } := by
simp only [AssociatedPrimes.mem_iff, isAssociatedPrime_iff]
  refine subset_antisymm (Set.iUnion₂_subset ?_) ?_
  · rintro _ ⟨h, x, ⟨⟩⟩ r h'
    exact ⟨x, by simpa using h.ne_top, by simpa using h'⟩
  · intro r ⟨x, h, h'⟩
    obtain ⟨P, hP, hx⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x h
    rw [isAssociatedPrime_iff] at hP
    exact Set.mem_iUnion₂_of_mem hP (hx (by rwa [mem_colon_singleton]))
```

-- snippet 18
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.prod (L206-L211)
theorem prod : associatedPrimes R (M × M') = associatedPrimes R M ∪ associatedPrimes R M' :=
(subset_union_of_exact LinearMap.inl_injective .inl_snd).antisymm (Set.union_subset_iff.2
    ⟨subset_of_injective LinearMap.inl_injective, subset_of_injective LinearMap.inr_injective⟩)

end associatedPrimes
```

-- snippet 19
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.associatedPrimes (L158-L169)
theorem associatedPrimes.finite : (associatedPrimes A M).Finite := by
induction ‹Module.Finite A M› using
    IsNoetherianRing.induction_on_isQuotientEquivQuotientPrime A with
  | subsingleton N => simp [associatedPrimes.eq_empty_of_subsingleton]
  | quotient N p f =>
    have := associatedPrimes.eq_singleton_of_isPrimary p.2.isPrimary
    simp [LinearEquiv.AssociatedPrimes.eq f, this]
  | exact N₁ N₂ N₃ f g hf _ hfg h₁ h₃ =>
    exact (h₁.union h₃).subset (associatedPrimes.subset_union_of_exact hf hfg)

/-- Every maximal ideal of a commutative Noetherian total ring of fractions `A` is
an associated prime of the `A`-module `A`. -/
```

-- snippet 20
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.subset_union_of_exact (L171-L204)
theorem subset_union_of_exact (hf : Function.Injective f) (hfg : Function.Exact f g) :
    associatedPrimes R M' ⊆ associatedPrimes R M ∪ associatedPrimes R M'' := by
rintro p ⟨_, x, hx⟩
  by_cases! h : ∃ a ∈ p.primeCompl, ∃ y : M, ∃ k, f y = a ^ k • x
  · obtain ⟨a, ha, y, k, h⟩ := h
    left
    refine ⟨‹_›, y, le_antisymm (fun b hb ↦ ?_) (fun b ⟨n, hb⟩ ↦ ?_)⟩
    · rw [hx] at hb
      obtain ⟨n, hb⟩ := hb
      use n
      rw [mem_colon_singleton, mem_bot] at hb ⊢
      apply_fun _ using hf
      rw [map_smul, h, smul_comm, hb, smul_zero, map_zero]
    · rw [mem_colon_singleton, mem_bot] at hb
      apply_fun f at hb
      rw [map_smul, map_zero, h, ← mul_smul, ← mem_bot R, ← mem_colon_singleton] at hb
      replace hb := hx.ge (Ideal.le_radical hb)
      contrapose hb
      exact p.primeCompl.mul_mem (p.primeCompl.pow_mem hb n) (p.primeCompl.pow_mem ha k)
  · right
    refine ⟨‹_›, g x, le_antisymm (fun b hb ↦ ?_) (fun b ⟨n, hb⟩ ↦ ?_)⟩
    · rw [hx] at hb
      refine Ideal.radical_mono (fun b hb ↦ ?_) hb
      rw [mem_colon_singleton, mem_bot] at hb ⊢
      rw [← map_smul, hb, map_zero]
    · rw [mem_colon_singleton, mem_bot, ← map_smul, ← LinearMap.mem_ker,
        hfg.linearMap_ker_eq] at hb
      obtain ⟨y, hy⟩ := hb
      by_contra H
      exact h b H y n hy

variable (R M M') in
/-- The set of associated primes of the product of two modules is equal to
the union of those of the two modules. -/
```

-- snippet 21
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.mem_associatedPrimes_atPrime_of_mem_associatedPrimes (L70-L77)
lemma mem_associatedPrimes_atPrime_of_mem_associatedPrimes
    {p : Ideal R} [p.IsPrime] (ass : p ∈ associatedPrimes R M) :
    maximalIdeal (Localization.AtPrime p) ∈
    associatedPrimes (Localization.AtPrime p) (LocalizedModule.AtPrime p M) := by
apply mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule
    p.primeCompl (LocalizedModule.mkLinearMap p.primeCompl M)
  simpa [Localization.AtPrime.comap_maximalIdeal] using ass
```

-- snippet 22
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.Ideal (L170-L179)
theorem Ideal.IsMaximal.mem_associatedPrimes_of_isFractionRing [IsFractionRing A A]
    (I : Ideal A) [hI : I.IsMaximal] : I ∈ associatedPrimes A A :=
have fin := associatedPrimes.finite A A
  have ⟨P, hP⟩ := (I.subset_union_prime_finite fin (f := id) 0 0 fun _ h _ _ ↦ h.isPrime).1 <| by
    simp_rw [id, biUnion_associatedPrimes_eq_compl_nonZeroDivisors]
    exact fun x hx h ↦ hI.ne_top <| I.eq_top_of_isUnit_mem hx
      (IsFractionRing.self_iff_nonZeroDivisors_le_isUnit.mp ‹_› h)
  hI.eq_of_le hP.1.isPrime.ne_top hP.2 ▸ hP.1

/-- A commutative Noetherian total ring of fractions is semilocal. -/
```

-- snippet 23
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.associatedPrimes (L103-L107)
def associatedPrimes : Set (Ideal R) :=
{ I | IsAssociatedPrime I M }

variable {I J M} {M' : Type*} [AddCommMonoid M'] [Module R M'] (f : M →ₗ[R] M')
```

-- snippet 24
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.minimalPrimes_annihilator_subset_associatedPrimes (L131-L150)
lemma minimalPrimes_annihilator_subset_associatedPrimes [IsNoetherianRing R] [Module.Finite R M] :
    (Module.annihilator R M).minimalPrimes ⊆ associatedPrimes R M := by
intro p hp
  have prime := hp.1.1
  let Rₚ := Localization.AtPrime p
  have : Nontrivial (LocalizedModule p.primeCompl M) := by
    simpa [← Module.mem_support_iff (p := ⟨p, prime⟩), Module.support_eq_zeroLocus] using hp.1.2
  rcases associatedPrimes.nonempty Rₚ (LocalizedModule p.primeCompl M) with ⟨q, hq⟩
  have q_prime : q.IsPrime := IsAssociatedPrime.isPrime hq
  simp only [← preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule p.primeCompl
    Rₚ (LocalizedModule.mkLinearMap p.primeCompl M), Set.mem_preimage] at hq
  have ann_le : Module.annihilator R M ≤ Ideal.comap (algebraMap R Rₚ) q :=
    le_of_eq_of_le Submodule.annihilator_top.symm (IsAssociatedPrime.annihilator_le hq)
  have le : Ideal.comap (algebraMap R Rₚ) q ≤ p := by
    have := (IsLocalization.disjoint_comap_iff p.primeCompl Rₚ q).mpr q_prime.ne_top
    simpa only [Ideal.primeCompl, Submonoid.coe_set_mk, Subsemigroup.coe_set_mk,
      Set.disjoint_compl_left_iff_subset] using this
  simpa [Minimal.eq_of_le hp.out ⟨IsAssociatedPrime.isPrime hq, ann_le⟩ le] using hq

end Module.associatedPrimes
```

-- snippet 25
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg (L84-L120)
lemma comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg (p : Ideal R')
    (ass : p ∈ associatedPrimes R' M') (fg : (p.comap (algebraMap R R')).FG) :
    p.comap (algebraMap R R') ∈ associatedPrimes R M := by
rcases ass with ⟨hp, x, hx⟩
  rcases fg with ⟨T, hT⟩
  rcases IsLocalizedModule.mk'_surjective S f x with ⟨⟨m, s⟩, rfl⟩
  simp only [Function.uncurry_apply_pair] at hx
  have mem (a : T) : algebraMap R R' a ∈ p := by
    simpa [← Ideal.mem_comap, ← hT] using Ideal.subset_span a.2
  simp only [hx, Ideal.mem_radical_iff, mem_bot, mem_colon_singleton, ← map_pow, algebraMap_smul,
    ← IsLocalizedModule.mk'_smul, IsLocalizedModule.mk'_eq_zero' f] at mem
  choose e g hg using mem
  refine ⟨.under R p, (∏ a, g a).1 • m, le_antisymm ?_ fun r hr ↦ ?_⟩
  · rw [← hT, Ideal.span_le]
    intro a ha
    simp only [SetLike.mem_coe, Ideal.mem_radical_iff, mem_bot, mem_colon_singleton]
    obtain ⟨u, hu⟩ : g ⟨a, ha⟩ ∣ (∏ a, g a) := by
      apply Finset.dvd_prod_of_mem g (Finset.mem_univ ⟨a, ha⟩)
    use e ⟨a, ha⟩
    rw [hu, Submonoid.coe_mul, smul_smul, ← mul_assoc, mul_comm, ← smul_smul, mul_comm, ← smul_smul]
    exact smul_eq_zero_of_right u.1 (hg ⟨a, ha⟩)
  · simp only [Ideal.mem_radical_iff, mem_bot, mem_colon_singleton, smul_smul] at hr
    obtain ⟨k, hk⟩ := hr
    have mem : r ^ k * (∏ a, g a).1 ∈ Ideal.comap (algebraMap R R') p := by
      rw [hx]
      use 1
      simp_rw [pow_one, mem_colon_singleton, algebraMap_smul, ← IsLocalizedModule.mk'_smul,
        hk, IsLocalizedModule.mk'_zero, mem_bot]
    apply hp.mem_of_pow_mem k
    rw [← map_pow]
    exact ((hp.under R).mul_mem_iff_mem_or_mem.mp mem).resolve_right
      (Set.disjoint_left.mp ((IsLocalization.disjoint_comap_iff S R' p).mpr hp.1) (∏ a, g a).2)

variable (R')

include S f in
open Set in
```

-- snippet 26
```lean
-- Mathlib.RingTheory.Ideal.Basic.pi (L50-L55)
def pi : Ideal (Π i, R i) where
  carrier := { r | ∀ i, r i ∈ I i }
zero_mem' i := (I i).zero_mem
  add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
  smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
```

-- snippet 27
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.subset_of_injective (L165-L169)
theorem subset_of_injective (hf : Function.Injective f) :
    associatedPrimes R M ⊆ associatedPrimes R M' := fun _I h => h.map_of_injective f hf
/-- If `0 → M → M' → M''` is an exact sequence, then the set of associated primes of `M'` is
contained in the union of those of `M` and `M''`. -/
```

-- snippet 28
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.biUnion_associatedPrimes_eq_compl_nonZeroDivisors (L240-L246)
theorem biUnion_associatedPrimes_eq_compl_nonZeroDivisors [IsNoetherianRing R] :
    ⋃ p ∈ associatedPrimes R R, p = (nonZeroDivisors R : Set R)ᶜ :=
(biUnion_associatedPrimes_eq_zero_divisors R R).trans <| by
    ext; simp [← nonZeroDivisorsLeft_eq_nonZeroDivisors, and_comm]

variable {R M}
```

-- snippet 29
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.not_isAssociatedPrime_of_subsingleton (L133-L138)
theorem not_isAssociatedPrime_of_subsingleton [Subsingleton M] : ¬IsAssociatedPrime I M := by
rintro ⟨hI, x, hx⟩
  apply hI.ne_top
  simp [hx, Subsingleton.elim x 0]

variable (R) in
```

-- snippet 30
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.IsAssociatedPrime (L98-L102)
def IsAssociatedPrime : Prop :=
(⊥ : Submodule R M).IsAssociatedPrime I

variable (R) in
/-- The set of associated primes of a module. -/
```

-- snippet 31
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.isAssociatedPrime_iff_exists_injective_linearMap (L257-L267)
theorem isAssociatedPrime_iff_exists_injective_linearMap [IsNoetherianRing R] :
    IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ (f : R ⧸ I →ₗ[R] M), Function.Injective f := by
rw [isAssociatedPrime_iff, and_congr_right_iff]
  refine fun _ ↦ ⟨fun ⟨x, h⟩ ↦ ?_, fun ⟨f, h⟩ ↦ ⟨(f ∘ₗ mkQ I) 1, ?_⟩⟩
  · replace h : I = ker (toSpanSingleton R M x) := by simp [h, SetLike.ext_iff]
    exact ⟨liftQ _ _ h.le, ker_eq_bot.mp (ker_liftQ_eq_bot' _ _ h)⟩
  · conv_lhs => rw [← I.ker_mkQ, ← ker_comp_of_ker_eq_bot (mkQ I) (ker_eq_bot_of_injective h)]
    simp [SetLike.ext_iff, ← Ideal.Quotient.algebraMap_eq, Algebra.algebraMap_eq_smul_one]

variable {I J M}
```

-- snippet 32
```lean
-- Mathlib.RingTheory.Ideal.Basic.mem_pi (L56-L58)
theorem mem_pi (r : Π i, R i) : r ∈ pi I ↔ ∀ i, r i ∈ I i :=
Iff.rfl
```

-- snippet 33
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.exists_le_isAssociatedPrime_of_isNoetherianRing (L139-L163)
theorem exists_le_isAssociatedPrime_of_isNoetherianRing [H : IsNoetherianRing R] (x : M)
    (hx : x ≠ 0) : ∃ P : Ideal R, IsAssociatedPrime P M ∧ (⊥ : Submodule R M).colon {x} ≤ P := by
simp only [isAssociatedPrime_iff]
  obtain ⟨P, ⟨l, h₁, y, rfl⟩, h₃⟩ :=
    set_has_maximal_iff_noetherian.mpr H
      { P | (⊥ : Submodule R M).colon {x} ≤ P ∧ P ≠ ⊤ ∧ ∃ y : M, P = (⊥ : Submodule R M).colon {y} }
      ⟨_, rfl.le, by simpa, x, rfl⟩
  refine ⟨_, ⟨⟨h₁, ?_⟩, y, rfl⟩, l⟩
  intro a b hab
  rw [or_iff_not_imp_left]
  intro ha
  rw [mem_colon_singleton] at ha hab
  have H₁ : (⊥ : Submodule R M).colon {y} ≤ (⊥ : Submodule R M).colon {a • y} := by
    intro c hc
    rw [mem_colon_singleton, mem_bot] at hc ⊢
    rw [smul_comm, hc, smul_zero]
  rwa [H₁.eq_of_not_lt (h₃ _ ⟨l.trans H₁, by simpa, _, rfl⟩),
    mem_colon_singleton, smul_comm, smul_smul]

namespace associatedPrimes

variable {f} {M'' : Type*} [AddCommMonoid M''] [Module R M''] {g : M' →ₗ[R] M''}

/-- If `M → M'` is injective, then the set of associated primes of `M` is
contained in that of `M'`. -/
```

-- snippet 34
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.AssociatedPrimes (L108-L109)
theorem AssociatedPrimes.mem_iff : I ∈ associatedPrimes R M ↔ IsAssociatedPrime I M := Iff.rfl
```

-- snippet 35
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule (L122-L130)
lemma preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule
    [IsNoetherianRing R] :
    (Ideal.comap (algebraMap R R')) ⁻¹' (associatedPrimes R M) = associatedPrimes R' M' := by
ext p
  exact ⟨mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule S f p,
    fun h ↦ comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg S f p h
    ((isNoetherianRing_iff_ideal_fg R).mp ‹_› _)⟩

variable (R M) in
```

-- snippet 36
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule (L40-L69)
lemma mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule
    (p : Ideal R') (ass : p.comap (algebraMap R R') ∈ associatedPrimes R M) :
    p ∈ associatedPrimes R' M' := by
rcases ass with ⟨hp, x, hx⟩
  constructor
  · refine (IsLocalization.isPrime_iff_isPrime_disjoint S _ _).mpr
      ⟨hp, (IsLocalization.disjoint_comap_iff S R' p).mpr ?_⟩
    by_contra eqtop
    simp [eqtop, Ideal.comap_top, Ideal.isPrime_iff] at hp
  · use f x
    ext t
    rcases IsLocalization.exists_mk'_eq S t with ⟨r, s, hrs⟩
    simp_rw [← hrs, Ideal.mem_radical_iff, mem_colon_singleton, ← IsLocalizedModule.mk'_one S f,
      ← IsLocalization.mk'_pow, IsLocalizedModule.mk'_smul_mk', mul_one, mem_bot,
      IsLocalizedModule.mk'_eq_zero']
    refine ⟨fun h ↦ exists_comm.mp ⟨1, ?_⟩, fun ⟨n, t, ht⟩ ↦ ?_⟩
    · simp only [← mem_colon_singleton, one_smul, ← mem_bot R, ← hx, ← Ideal.mem_radical_iff]
      exact hSR'.mk'_mem_iff.mp h
    · have : hSR'.mk' R' r s = hSR'.mk' R' (t.1 * r) 1 * hSR'.mk' R' 1 (t * s) := by
        rw [← hSR'.mk'_mul, mul_one, one_mul, ← sub_eq_zero, ← hSR'.mk'_sub, Submonoid.coe_mul]
        simp [← mul_assoc, mul_comm r t.1, IsLocalization.mk'_zero]
      rw [this]
      apply Ideal.IsTwoSided.mul_mem_of_left
      rw [IsLocalization.mk'_one, ← Ideal.mem_comap, hx]
      rcases eq_zero_or_pos n with rfl | hn
      · exact Ideal.IsTwoSided.mul_mem_of_left _ ⟨1, by simpa using ht⟩
      · use n
        rw [mem_colon_singleton, mul_pow, mul_smul, ← mem_colon_singleton]
        exact Ideal.pow_mem_of_mem _ (by simpa using ht) n hn
```

-- snippet 37
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.Submodule (L51-L55)
def Submodule.IsQuotientEquivQuotientPrime (N₁ N₂ : Submodule A M) :=
N₁ ≤ N₂ ∧ ∃ (p : PrimeSpectrum A), Nonempty ((↥N₂ ⧸ N₁.submoduleOf N₂) ≃ₗ[A] A ⧸ p.1)

set_option backward.isDefEq.respectTransparency false in
open LinearMap in
```

-- snippet 38
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.LinearEquiv (L128-L132)
theorem LinearEquiv.isAssociatedPrime_iff (l : M ≃ₗ[R] M') :
    IsAssociatedPrime I M ↔ IsAssociatedPrime I M' :=
⟨fun h => h.map_of_injective l l.injective,
    fun h => h.map_of_injective l.symm l.symm.injective⟩
```

-- snippet 39
```lean
-- Mathlib.RingTheory.Ideal.Basic.single_mem_pi (L67-L72)
theorem single_mem_pi [DecidableEq ι] {i : ι} {r : R i} (hr : r ∈ I i) : Pi.single i r ∈ pi I := by
intro j
  obtain rfl | ne := eq_or_ne i j
  · simpa
  · simp [ne]
```

-- snippet 40
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.isAssociatedPrime_iff (L117-L120)
theorem isAssociatedPrime_iff [IsNoetherianRing R] :
    IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ x : M, I = colon ⊥ {x} :=
(⊥ : Submodule R M).isAssociatedPrime_iff
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.RingTheory.Ideal.Over).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
def algEquivOfEqComap (h : P = Q.comap σ) : (B ⧸ P) ≃ₐ[A ⧸ p] (C ⧸ Q)
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.RingTheory.Ideal.Over.comap_eq_of_scalar_tower_quotient (L52-L62)
theorem comap_eq_of_scalar_tower_quotient [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)]
    [IsScalarTower R (R ⧸ p) (S ⧸ P)] (h : Function.Injective (algebraMap (R ⧸ p) (S ⧸ P))) :
    comap (algebraMap R S) P = p := by
ext x
  rw [mem_comap, ← Quotient.eq_zero_iff_mem, ← Quotient.eq_zero_iff_mem, Quotient.mk_algebraMap,
    IsScalarTower.algebraMap_apply R (R ⧸ p) (S ⧸ P), Quotient.algebraMap_eq]
  exact map_eq_zero_iff _ h

variable [Algebra R S]

/-- `R / p` has a canonical map to `S / pS`. -/
```

-- snippet 2
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L63-L65)
instance Quotient.algebraQuotientMapQuotient : Algebra (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
Ideal.Quotient.algebraQuotientOfLEComap le_comap_map
```

-- snippet 3
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L67-L72)
theorem Quotient.algebraMap_quotient_map_quotient (x : R) :
    letI f := algebraMap R S
algebraMap (R ⧸ p) (S ⧸ map f p) (Ideal.Quotient.mk p x) =
    Ideal.Quotient.mk (map f p) (f x) :=
  rfl
```

-- snippet 4
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L74-L78)
theorem Quotient.mk_smul_mk_quotient_map_quotient (x : R) (y : S) :
    letI f := algebraMap R S
Quotient.mk p x • Quotient.mk (map f p) y = Quotient.mk (map f p) (f x * y) :=
  Algebra.smul_def _ _
```

-- snippet 5
```lean
-- Mathlib.RingTheory.Ideal.Over.Quotient (L79-L95)
instance Quotient.tower_quotient_map_quotient :
    IsScalarTower R (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
IsScalarTower.of_algebraMap_eq fun x => by
    rw [Quotient.algebraMap_eq, Quotient.algebraMap_quotient_map_quotient,
      Quotient.mk_algebraMap]

end CommRing

section ideal_liesOver

section Semiring

variable (A : Type*) [CommSemiring A] {B C : Type*} [Semiring B] [Semiring C] [Algebra A B]
  [Algebra A C] (P : Ideal B) {Q : Ideal C} (p : Ideal A)
  {G : Type*} [Group G] [MulSemiringAction G B] [SMulCommClass G A B] (g : G)

/-- The ideal obtained by pulling back the ideal `P` from `B` to `A`. -/
```

-- snippet 6
```lean
-- Mathlib.RingTheory.Ideal.Over.under (L96-L97)
abbrev under : Ideal A := Ideal.comap (algebraMap A B) P
```

-- snippet 7
```lean
-- Mathlib.RingTheory.Ideal.Over.under_def (L98-L99)
theorem under_def : P.under A = Ideal.comap (algebraMap A B) P := rfl
```

-- snippet 8
```lean
-- Mathlib.RingTheory.Ideal.Over.IsPrime (L100-L102)
instance IsPrime.under [hP : P.IsPrime] : (P.under A).IsPrime :=
hP.comap (algebraMap A B)
```

-- snippet 9
```lean
-- Mathlib.RingTheory.Ideal.Over.under_smul (L104-L108)
lemma under_smul : (g • P : Ideal B).under A = P.under A := by
ext a
  rw [mem_comap, mem_comap, mem_pointwise_smul_iff_inv_smul_mem, smul_algebraMap]

variable (B) in
```

-- snippet 10
```lean
-- Mathlib.RingTheory.Ideal.Over.under_top (L109-L113)
theorem under_top : under A (⊤ : Ideal B) = ⊤ := comap_top
variable {A}

/-- `P` lies over `p` if `p` is the preimage of `P` by the `algebraMap`. -/
```

-- snippet 11
```lean
-- Mathlib.RingTheory.Ideal.Over.over_under (L117-L118)
instance over_under : P.LiesOver (P.under A) where over := rfl
```

-- snippet 12
```lean
-- Mathlib.RingTheory.Ideal.Over.over_def (L119-L120)
theorem over_def [P.LiesOver p] : p = P.under A := LiesOver.over
```

-- snippet 13
```lean
-- Mathlib.RingTheory.Ideal.Over.mem_of_liesOver (L121-L125)
theorem mem_of_liesOver [P.LiesOver p] (x : A) : x ∈ p ↔ algebraMap A B x ∈ P := by
rw [P.over_def p]
  rfl

variable (A B) in
```

-- snippet 14
```lean
-- Mathlib.RingTheory.Ideal.Over.top_liesOver_top (L126-L128)
instance top_liesOver_top : (⊤ : Ideal B).LiesOver (⊤ : Ideal A) where
  over := (under_top A B).symm
```

-- snippet 15
```lean
-- Mathlib.RingTheory.Ideal.Over.eq_top_iff_of_liesOver (L129-L132)
theorem eq_top_iff_of_liesOver [P.LiesOver p] : P = ⊤ ↔ p = ⊤ := by
rw [P.over_def p]
  exact comap_eq_top_iff.symm
```

-- snippet 16
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.IsNoetherianRing (L92-L117)
theorem IsNoetherianRing.exists_relSeries_isQuotientEquivQuotientPrime :
    ∃ s : RelSeries {(N₁, N₂) | Submodule.IsQuotientEquivQuotientPrime (A := A) (M := M) N₁ N₂},
s.head = ⊥ ∧ s.last = ⊤ := by
  refine WellFoundedGT.induction_top ⟨⊥, .singleton _ ⊥, rfl, rfl⟩ ?_
  rintro N hN ⟨s, hs₁, hs₂⟩
  have := Submodule.Quotient.nontrivial_iff.mpr hN
  obtain ⟨p, hp⟩ := associatedPrimes.nonempty A (M ⧸ N)
  rw [AssociatedPrimes.mem_iff, isAssociatedPrime_iff] at hp
  obtain ⟨hp, x, rfl⟩ := hp
  obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x
  have hxN : x ∉ N := fun h ↦ hp.ne_top (by rw [show N.mkQ x = 0 by simpa]; simp)
  have := Submodule.isQuotientEquivQuotientPrime_iff.mpr ⟨x, hp, rfl⟩
  refine ⟨_, by simpa [hs₂], s.snoc _ (hs₂ ▸ this), by simpa, rfl⟩

/-- If a property on finitely generated modules over a Noetherian ring satisfies that:

- it holds for zero module (it's formalized as it holds for any module which is subsingleton),
- it holds for `A ⧸ p` for every prime ideal `p` of `A` (to avoid universe problem,
  it's formalized as it holds for any module isomorphic to `A ⧸ p`),
- it is stable by short exact sequences,

then the property holds for every finitely generated modules.

NOTE: This should be the induction principle for `M`, but due to the bug
https://github.com/leanprover/lean4/issues/4246
currently it is induction for `Module.Finite A M`. -/
```

-- snippet 17
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.biUnion_associatedPrimes_eq_zero_divisors (L229-L239)
theorem biUnion_associatedPrimes_eq_zero_divisors [IsNoetherianRing R] :
    ⋃ p ∈ associatedPrimes R M, p = { r : R | ∃ x : M, x ≠ 0 ∧ r • x = 0 } := by
simp only [AssociatedPrimes.mem_iff, isAssociatedPrime_iff]
  refine subset_antisymm (Set.iUnion₂_subset ?_) ?_
  · rintro _ ⟨h, x, ⟨⟩⟩ r h'
    exact ⟨x, by simpa using h.ne_top, by simpa using h'⟩
  · intro r ⟨x, h, h'⟩
    obtain ⟨P, hP, hx⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x h
    rw [isAssociatedPrime_iff] at hP
    exact Set.mem_iUnion₂_of_mem hP (hx (by rwa [mem_colon_singleton]))
```

-- snippet 18
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.prod (L206-L211)
theorem prod : associatedPrimes R (M × M') = associatedPrimes R M ∪ associatedPrimes R M' :=
(subset_union_of_exact LinearMap.inl_injective .inl_snd).antisymm (Set.union_subset_iff.2
    ⟨subset_of_injective LinearMap.inl_injective, subset_of_injective LinearMap.inr_injective⟩)

end associatedPrimes
```

-- snippet 19
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.associatedPrimes (L158-L169)
theorem associatedPrimes.finite : (associatedPrimes A M).Finite := by
induction ‹Module.Finite A M› using
    IsNoetherianRing.induction_on_isQuotientEquivQuotientPrime A with
  | subsingleton N => simp [associatedPrimes.eq_empty_of_subsingleton]
  | quotient N p f =>
    have := associatedPrimes.eq_singleton_of_isPrimary p.2.isPrimary
    simp [LinearEquiv.AssociatedPrimes.eq f, this]
  | exact N₁ N₂ N₃ f g hf _ hfg h₁ h₃ =>
    exact (h₁.union h₃).subset (associatedPrimes.subset_union_of_exact hf hfg)

/-- Every maximal ideal of a commutative Noetherian total ring of fractions `A` is
an associated prime of the `A`-module `A`. -/
```

-- snippet 20
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.subset_union_of_exact (L171-L204)
theorem subset_union_of_exact (hf : Function.Injective f) (hfg : Function.Exact f g) :
    associatedPrimes R M' ⊆ associatedPrimes R M ∪ associatedPrimes R M'' := by
rintro p ⟨_, x, hx⟩
  by_cases! h : ∃ a ∈ p.primeCompl, ∃ y : M, ∃ k, f y = a ^ k • x
  · obtain ⟨a, ha, y, k, h⟩ := h
    left
    refine ⟨‹_›, y, le_antisymm (fun b hb ↦ ?_) (fun b ⟨n, hb⟩ ↦ ?_)⟩
    · rw [hx] at hb
      obtain ⟨n, hb⟩ := hb
      use n
      rw [mem_colon_singleton, mem_bot] at hb ⊢
      apply_fun _ using hf
      rw [map_smul, h, smul_comm, hb, smul_zero, map_zero]
    · rw [mem_colon_singleton, mem_bot] at hb
      apply_fun f at hb
      rw [map_smul, map_zero, h, ← mul_smul, ← mem_bot R, ← mem_colon_singleton] at hb
      replace hb := hx.ge (Ideal.le_radical hb)
      contrapose hb
      exact p.primeCompl.mul_mem (p.primeCompl.pow_mem hb n) (p.primeCompl.pow_mem ha k)
  · right
    refine ⟨‹_›, g x, le_antisymm (fun b hb ↦ ?_) (fun b ⟨n, hb⟩ ↦ ?_)⟩
    · rw [hx] at hb
      refine Ideal.radical_mono (fun b hb ↦ ?_) hb
      rw [mem_colon_singleton, mem_bot] at hb ⊢
      rw [← map_smul, hb, map_zero]
    · rw [mem_colon_singleton, mem_bot, ← map_smul, ← LinearMap.mem_ker,
        hfg.linearMap_ker_eq] at hb
      obtain ⟨y, hy⟩ := hb
      by_contra H
      exact h b H y n hy

variable (R M M') in
/-- The set of associated primes of the product of two modules is equal to
the union of those of the two modules. -/
```

-- snippet 21
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.mem_associatedPrimes_atPrime_of_mem_associatedPrimes (L70-L77)
lemma mem_associatedPrimes_atPrime_of_mem_associatedPrimes
    {p : Ideal R} [p.IsPrime] (ass : p ∈ associatedPrimes R M) :
    maximalIdeal (Localization.AtPrime p) ∈
    associatedPrimes (Localization.AtPrime p) (LocalizedModule.AtPrime p M) := by
apply mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule
    p.primeCompl (LocalizedModule.mkLinearMap p.primeCompl M)
  simpa [Localization.AtPrime.comap_maximalIdeal] using ass
```

-- snippet 22
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.Ideal (L170-L179)
theorem Ideal.IsMaximal.mem_associatedPrimes_of_isFractionRing [IsFractionRing A A]
    (I : Ideal A) [hI : I.IsMaximal] : I ∈ associatedPrimes A A :=
have fin := associatedPrimes.finite A A
  have ⟨P, hP⟩ := (I.subset_union_prime_finite fin (f := id) 0 0 fun _ h _ _ ↦ h.isPrime).1 <| by
    simp_rw [id, biUnion_associatedPrimes_eq_compl_nonZeroDivisors]
    exact fun x hx h ↦ hI.ne_top <| I.eq_top_of_isUnit_mem hx
      (IsFractionRing.self_iff_nonZeroDivisors_le_isUnit.mp ‹_› h)
  hI.eq_of_le hP.1.isPrime.ne_top hP.2 ▸ hP.1

/-- A commutative Noetherian total ring of fractions is semilocal. -/
```

-- snippet 23
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.associatedPrimes (L103-L107)
def associatedPrimes : Set (Ideal R) :=
{ I | IsAssociatedPrime I M }

variable {I J M} {M' : Type*} [AddCommMonoid M'] [Module R M'] (f : M →ₗ[R] M')
```

-- snippet 24
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.minimalPrimes_annihilator_subset_associatedPrimes (L131-L150)
lemma minimalPrimes_annihilator_subset_associatedPrimes [IsNoetherianRing R] [Module.Finite R M] :
    (Module.annihilator R M).minimalPrimes ⊆ associatedPrimes R M := by
intro p hp
  have prime := hp.1.1
  let Rₚ := Localization.AtPrime p
  have : Nontrivial (LocalizedModule p.primeCompl M) := by
    simpa [← Module.mem_support_iff (p := ⟨p, prime⟩), Module.support_eq_zeroLocus] using hp.1.2
  rcases associatedPrimes.nonempty Rₚ (LocalizedModule p.primeCompl M) with ⟨q, hq⟩
  have q_prime : q.IsPrime := IsAssociatedPrime.isPrime hq
  simp only [← preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule p.primeCompl
    Rₚ (LocalizedModule.mkLinearMap p.primeCompl M), Set.mem_preimage] at hq
  have ann_le : Module.annihilator R M ≤ Ideal.comap (algebraMap R Rₚ) q :=
    le_of_eq_of_le Submodule.annihilator_top.symm (IsAssociatedPrime.annihilator_le hq)
  have le : Ideal.comap (algebraMap R Rₚ) q ≤ p := by
    have := (IsLocalization.disjoint_comap_iff p.primeCompl Rₚ q).mpr q_prime.ne_top
    simpa only [Ideal.primeCompl, Submonoid.coe_set_mk, Subsemigroup.coe_set_mk,
      Set.disjoint_compl_left_iff_subset] using this
  simpa [Minimal.eq_of_le hp.out ⟨IsAssociatedPrime.isPrime hq, ann_le⟩ le] using hq

end Module.associatedPrimes
```

-- snippet 25
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg (L84-L120)
lemma comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg (p : Ideal R')
    (ass : p ∈ associatedPrimes R' M') (fg : (p.comap (algebraMap R R')).FG) :
    p.comap (algebraMap R R') ∈ associatedPrimes R M := by
rcases ass with ⟨hp, x, hx⟩
  rcases fg with ⟨T, hT⟩
  rcases IsLocalizedModule.mk'_surjective S f x with ⟨⟨m, s⟩, rfl⟩
  simp only [Function.uncurry_apply_pair] at hx
  have mem (a : T) : algebraMap R R' a ∈ p := by
    simpa [← Ideal.mem_comap, ← hT] using Ideal.subset_span a.2
  simp only [hx, Ideal.mem_radical_iff, mem_bot, mem_colon_singleton, ← map_pow, algebraMap_smul,
    ← IsLocalizedModule.mk'_smul, IsLocalizedModule.mk'_eq_zero' f] at mem
  choose e g hg using mem
  refine ⟨.under R p, (∏ a, g a).1 • m, le_antisymm ?_ fun r hr ↦ ?_⟩
  · rw [← hT, Ideal.span_le]
    intro a ha
    simp only [SetLike.mem_coe, Ideal.mem_radical_iff, mem_bot, mem_colon_singleton]
    obtain ⟨u, hu⟩ : g ⟨a, ha⟩ ∣ (∏ a, g a) := by
      apply Finset.dvd_prod_of_mem g (Finset.mem_univ ⟨a, ha⟩)
    use e ⟨a, ha⟩
    rw [hu, Submonoid.coe_mul, smul_smul, ← mul_assoc, mul_comm, ← smul_smul, mul_comm, ← smul_smul]
    exact smul_eq_zero_of_right u.1 (hg ⟨a, ha⟩)
  · simp only [Ideal.mem_radical_iff, mem_bot, mem_colon_singleton, smul_smul] at hr
    obtain ⟨k, hk⟩ := hr
    have mem : r ^ k * (∏ a, g a).1 ∈ Ideal.comap (algebraMap R R') p := by
      rw [hx]
      use 1
      simp_rw [pow_one, mem_colon_singleton, algebraMap_smul, ← IsLocalizedModule.mk'_smul,
        hk, IsLocalizedModule.mk'_zero, mem_bot]
    apply hp.mem_of_pow_mem k
    rw [← map_pow]
    exact ((hp.under R).mul_mem_iff_mem_or_mem.mp mem).resolve_right
      (Set.disjoint_left.mp ((IsLocalization.disjoint_comap_iff S R' p).mpr hp.1) (∏ a, g a).2)

variable (R')

include S f in
open Set in
```

-- snippet 26
```lean
-- Mathlib.RingTheory.Ideal.Basic.pi (L50-L55)
def pi : Ideal (Π i, R i) where
  carrier := { r | ∀ i, r i ∈ I i }
zero_mem' i := (I i).zero_mem
  add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
  smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
```

-- snippet 27
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.subset_of_injective (L165-L169)
theorem subset_of_injective (hf : Function.Injective f) :
    associatedPrimes R M ⊆ associatedPrimes R M' := fun _I h => h.map_of_injective f hf
/-- If `0 → M → M' → M''` is an exact sequence, then the set of associated primes of `M'` is
contained in the union of those of `M` and `M''`. -/
```

-- snippet 28
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.biUnion_associatedPrimes_eq_compl_nonZeroDivisors (L240-L246)
theorem biUnion_associatedPrimes_eq_compl_nonZeroDivisors [IsNoetherianRing R] :
    ⋃ p ∈ associatedPrimes R R, p = (nonZeroDivisors R : Set R)ᶜ :=
(biUnion_associatedPrimes_eq_zero_divisors R R).trans <| by
    ext; simp [← nonZeroDivisorsLeft_eq_nonZeroDivisors, and_comm]

variable {R M}
```

-- snippet 29
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.not_isAssociatedPrime_of_subsingleton (L133-L138)
theorem not_isAssociatedPrime_of_subsingleton [Subsingleton M] : ¬IsAssociatedPrime I M := by
rintro ⟨hI, x, hx⟩
  apply hI.ne_top
  simp [hx, Subsingleton.elim x 0]

variable (R) in
```

-- snippet 30
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.IsAssociatedPrime (L98-L102)
def IsAssociatedPrime : Prop :=
(⊥ : Submodule R M).IsAssociatedPrime I

variable (R) in
/-- The set of associated primes of a module. -/
```

-- snippet 31
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.isAssociatedPrime_iff_exists_injective_linearMap (L257-L267)
theorem isAssociatedPrime_iff_exists_injective_linearMap [IsNoetherianRing R] :
    IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ (f : R ⧸ I →ₗ[R] M), Function.Injective f := by
rw [isAssociatedPrime_iff, and_congr_right_iff]
  refine fun _ ↦ ⟨fun ⟨x, h⟩ ↦ ?_, fun ⟨f, h⟩ ↦ ⟨(f ∘ₗ mkQ I) 1, ?_⟩⟩
  · replace h : I = ker (toSpanSingleton R M x) := by simp [h, SetLike.ext_iff]
    exact ⟨liftQ _ _ h.le, ker_eq_bot.mp (ker_liftQ_eq_bot' _ _ h)⟩
  · conv_lhs => rw [← I.ker_mkQ, ← ker_comp_of_ker_eq_bot (mkQ I) (ker_eq_bot_of_injective h)]
    simp [SetLike.ext_iff, ← Ideal.Quotient.algebraMap_eq, Algebra.algebraMap_eq_smul_one]

variable {I J M}
```

-- snippet 32
```lean
-- Mathlib.RingTheory.Ideal.Basic.mem_pi (L56-L58)
theorem mem_pi (r : Π i, R i) : r ∈ pi I ↔ ∀ i, r i ∈ I i :=
Iff.rfl
```

-- snippet 33
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.exists_le_isAssociatedPrime_of_isNoetherianRing (L139-L163)
theorem exists_le_isAssociatedPrime_of_isNoetherianRing [H : IsNoetherianRing R] (x : M)
    (hx : x ≠ 0) : ∃ P : Ideal R, IsAssociatedPrime P M ∧ (⊥ : Submodule R M).colon {x} ≤ P := by
simp only [isAssociatedPrime_iff]
  obtain ⟨P, ⟨l, h₁, y, rfl⟩, h₃⟩ :=
    set_has_maximal_iff_noetherian.mpr H
      { P | (⊥ : Submodule R M).colon {x} ≤ P ∧ P ≠ ⊤ ∧ ∃ y : M, P = (⊥ : Submodule R M).colon {y} }
      ⟨_, rfl.le, by simpa, x, rfl⟩
  refine ⟨_, ⟨⟨h₁, ?_⟩, y, rfl⟩, l⟩
  intro a b hab
  rw [or_iff_not_imp_left]
  intro ha
  rw [mem_colon_singleton] at ha hab
  have H₁ : (⊥ : Submodule R M).colon {y} ≤ (⊥ : Submodule R M).colon {a • y} := by
    intro c hc
    rw [mem_colon_singleton, mem_bot] at hc ⊢
    rw [smul_comm, hc, smul_zero]
  rwa [H₁.eq_of_not_lt (h₃ _ ⟨l.trans H₁, by simpa, _, rfl⟩),
    mem_colon_singleton, smul_comm, smul_smul]

namespace associatedPrimes

variable {f} {M'' : Type*} [AddCommMonoid M''] [Module R M''] {g : M' →ₗ[R] M''}

/-- If `M → M'` is injective, then the set of associated primes of `M` is
contained in that of `M'`. -/
```

-- snippet 34
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.AssociatedPrimes (L108-L109)
theorem AssociatedPrimes.mem_iff : I ∈ associatedPrimes R M ↔ IsAssociatedPrime I M := Iff.rfl
```

-- snippet 35
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule (L122-L130)
lemma preimage_comap_associatedPrimes_eq_associatedPrimes_of_isLocalizedModule
    [IsNoetherianRing R] :
    (Ideal.comap (algebraMap R R')) ⁻¹' (associatedPrimes R M) = associatedPrimes R' M' := by
ext p
  exact ⟨mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule S f p,
    fun h ↦ comap_mem_associatedPrimes_of_mem_associatedPrimes_of_isLocalizedModule_of_fg S f p h
    ((isNoetherianRing_iff_ideal_fg R).mp ‹_› _)⟩

variable (R M) in
```

-- snippet 36
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Localization.mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule (L40-L69)
lemma mem_associatedPrimes_of_comap_mem_associatedPrimes_of_isLocalizedModule
    (p : Ideal R') (ass : p.comap (algebraMap R R') ∈ associatedPrimes R M) :
    p ∈ associatedPrimes R' M' := by
rcases ass with ⟨hp, x, hx⟩
  constructor
  · refine (IsLocalization.isPrime_iff_isPrime_disjoint S _ _).mpr
      ⟨hp, (IsLocalization.disjoint_comap_iff S R' p).mpr ?_⟩
    by_contra eqtop
    simp [eqtop, Ideal.comap_top, Ideal.isPrime_iff] at hp
  · use f x
    ext t
    rcases IsLocalization.exists_mk'_eq S t with ⟨r, s, hrs⟩
    simp_rw [← hrs, Ideal.mem_radical_iff, mem_colon_singleton, ← IsLocalizedModule.mk'_one S f,
      ← IsLocalization.mk'_pow, IsLocalizedModule.mk'_smul_mk', mul_one, mem_bot,
      IsLocalizedModule.mk'_eq_zero']
    refine ⟨fun h ↦ exists_comm.mp ⟨1, ?_⟩, fun ⟨n, t, ht⟩ ↦ ?_⟩
    · simp only [← mem_colon_singleton, one_smul, ← mem_bot R, ← hx, ← Ideal.mem_radical_iff]
      exact hSR'.mk'_mem_iff.mp h
    · have : hSR'.mk' R' r s = hSR'.mk' R' (t.1 * r) 1 * hSR'.mk' R' 1 (t * s) := by
        rw [← hSR'.mk'_mul, mul_one, one_mul, ← sub_eq_zero, ← hSR'.mk'_sub, Submonoid.coe_mul]
        simp [← mul_assoc, mul_comm r t.1, IsLocalization.mk'_zero]
      rw [this]
      apply Ideal.IsTwoSided.mul_mem_of_left
      rw [IsLocalization.mk'_one, ← Ideal.mem_comap, hx]
      rcases eq_zero_or_pos n with rfl | hn
      · exact Ideal.IsTwoSided.mul_mem_of_left _ ⟨1, by simpa using ht⟩
      · use n
        rw [mem_colon_singleton, mul_pow, mul_smul, ← mem_colon_singleton]
        exact Ideal.pow_mem_of_mem _ (by simpa using ht) n hn
```

-- snippet 37
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness.Submodule (L51-L55)
def Submodule.IsQuotientEquivQuotientPrime (N₁ N₂ : Submodule A M) :=
N₁ ≤ N₂ ∧ ∃ (p : PrimeSpectrum A), Nonempty ((↥N₂ ⧸ N₁.submoduleOf N₂) ≃ₗ[A] A ⧸ p.1)

set_option backward.isDefEq.respectTransparency false in
open LinearMap in
```

-- snippet 38
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.LinearEquiv (L128-L132)
theorem LinearEquiv.isAssociatedPrime_iff (l : M ≃ₗ[R] M') :
    IsAssociatedPrime I M ↔ IsAssociatedPrime I M' :=
⟨fun h => h.map_of_injective l l.injective,
    fun h => h.map_of_injective l.symm l.symm.injective⟩
```

-- snippet 39
```lean
-- Mathlib.RingTheory.Ideal.Basic.single_mem_pi (L67-L72)
theorem single_mem_pi [DecidableEq ι] {i : ι} {r : R i} (hr : r ∈ I i) : Pi.single i r ∈ pi I := by
intro j
  obtain rfl | ne := eq_or_ne i j
  · simpa
  · simp [ne]
```

-- snippet 40
```lean
-- Mathlib.RingTheory.Ideal.AssociatedPrime.Basic.isAssociatedPrime_iff (L117-L120)
theorem isAssociatedPrime_iff [IsNoetherianRing R] :
    IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ x : M, I = colon ⊥ {x} :=
(⊥ : Submodule R M).isAssociatedPrime_iff
```
[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.SetTheory.Cardinal.Order).

[User]
The following Lean code fails to compile. Fix it.

```lean
theorem one_eq_lift_iff {a : Cardinal.{u}} :
    (1 : Cardinal) = lift.{v} a ↔ 1 = a
:= by .someMissingNamespaceXYZ
simpa using nat_eq_lift_iff (n := 1)
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=95, messages=[Message(data='unknown tactic', pos=Position(line=3, column=8), pos_end=None, severity=<Severity.ERROR: 3>, kind=None), Message(data='invalid use of explicit universe parameters, `lift` is a local variable', pos=Position(line=2, column=21), pos_end=Position(line=2, column=25), severity=<Severity.ERROR: 3>, kind=None), Message(data='unsolved goals\nx✝ : Sort u_1\nlift : x✝\na : Cardinal.{u}\n⊢ 1 = sorry ↔ 1 = a', pos=Position(line=3, column=6), pos_end=Position(line=3, column=30), severity=<Severity.ERROR: 3>, kind='Tactic.unsolvedGoals')], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=95, i_end=154, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.SetTheory.Cardinal.Order).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]The following Lean code fails to compile. Fix it.

```lean
theorem one_eq_lift_iff {a : Cardinal.{u}} :
    (1 : Cardinal) = lift.{v} a ↔ 1 = a
:= by .someMissingNamespaceXYZ
simpa using nat_eq_lift_iff (n := 1)
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=95, messages=[Message(data='unknown tactic', pos=Position(line=3, column=8), pos_end=None, severity=<Severity.ERROR: 3>, kind=None), Message(data='invalid use of explicit universe parameters, `lift` is a local variable', pos=Position(line=2, column=21), pos_end=Position(line=2, column=25), severity=<Severity.ERROR: 3>, kind=None), Message(data='unsolved goals\nx✝ : Sort u_1\nlift : x✝\na : Cardinal.{u}\n⊢ 1 = sorry ↔ 1 = a', pos=Position(line=3, column=6), pos_end=Position(line=3, column=30), severity=<Severity.ERROR: 3>, kind='Tactic.unsolvedGoals')], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=95, i_end=154, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.RingTheory.PowerSeries.WeierstrassPreparation).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
theorem IsWeierstrassDivision.unique [IsAdicComplete (IsLocalRing.maximalIdeal A) A]
    {q : A⟦X⟧} {r : A[X]}
    (H : f.IsWeierstrassDivision g q r) : q = f /ʷ g ∧ r = f %ʷ g
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.isWeierstrassDivisionAt_zero (L125-L134)
theorem isWeierstrassDivisionAt_zero : IsWeierstrassDivisionAt 0 g 0 0 I
```

-- snippet 2
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.coeff_f_sub_r_mem (L135-L144)
theorem coeff_f_sub_r_mem (H : f.IsWeierstrassDivisionAt g q r I)
    {i : ℕ} (hi : i < (g.map (Ideal.Quotient.mk I)).order.toNat) :
    coeff i (f - r : A⟦X⟧) ∈ I
```

-- snippet 3
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.add (L145-L150)
theorem add {f' q' r'} (H : f.IsWeierstrassDivisionAt g q r I)
    (H' : f'.IsWeierstrassDivisionAt g q' r' I) :
    (f + f').IsWeierstrassDivisionAt g (q + q') (r + r') I
```

-- snippet 4
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.smul (L151-L170)
theorem smul (H : f.IsWeierstrassDivisionAt g q r I) (a : A) :
    (a • f).IsWeierstrassDivisionAt g (a • q) (a • r) I
```

-- snippet 5
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisorAt (L171-L175)
def IsWeierstrassDivisorAt : Prop
```

-- snippet 6
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisor (L176-L181)
abbrev IsWeierstrassDivisor [IsLocalRing A] : Prop
```

-- snippet 7
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisor (L182-L188)
theorem IsWeierstrassDivisor.of_map_ne_zero [IsLocalRing A]
    (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassDivisor
```

-- snippet 8
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.isUnit_shift (L214-L226)
theorem isUnit_shift : IsUnit <| mk fun i ↦
    coeff (i + (g.map (Ideal.Quotient.mk I)).order.toNat) g
```

-- snippet 9
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.PowerSeries (L58-L77)
abbrev PowerSeries (R : Type*)
```

-- snippet 10
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.forall_coeff_eq_zero (L98-L103)
theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff n φ = 0) ↔ φ = 0
```

-- snippet 11
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.coeff (L78-L81)
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R
```

-- snippet 12
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.monomial (L82-L84)
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧
```

-- snippet 13
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.ext (L91-L96)
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff n φ = coeff n ψ) : φ = ψ
```

-- snippet 14
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.coeff_def (L85-L89)
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) :
    coeff (R
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.RingTheory.PowerSeries.WeierstrassPreparation).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
theorem IsWeierstrassDivision.unique [IsAdicComplete (IsLocalRing.maximalIdeal A) A]
    {q : A⟦X⟧} {r : A[X]}
    (H : f.IsWeierstrassDivision g q r) : q = f /ʷ g ∧ r = f %ʷ g
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.isWeierstrassDivisionAt_zero (L125-L134)
theorem isWeierstrassDivisionAt_zero : IsWeierstrassDivisionAt 0 g 0 0 I
```

-- snippet 2
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.coeff_f_sub_r_mem (L135-L144)
theorem coeff_f_sub_r_mem (H : f.IsWeierstrassDivisionAt g q r I)
    {i : ℕ} (hi : i < (g.map (Ideal.Quotient.mk I)).order.toNat) :
    coeff i (f - r : A⟦X⟧) ∈ I
```

-- snippet 3
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.add (L145-L150)
theorem add {f' q' r'} (H : f.IsWeierstrassDivisionAt g q r I)
    (H' : f'.IsWeierstrassDivisionAt g q' r' I) :
    (f + f').IsWeierstrassDivisionAt g (q + q') (r + r') I
```

-- snippet 4
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.smul (L151-L170)
theorem smul (H : f.IsWeierstrassDivisionAt g q r I) (a : A) :
    (a • f).IsWeierstrassDivisionAt g (a • q) (a • r) I
```

-- snippet 5
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisorAt (L171-L175)
def IsWeierstrassDivisorAt : Prop
```

-- snippet 6
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisor (L176-L181)
abbrev IsWeierstrassDivisor [IsLocalRing A] : Prop
```

-- snippet 7
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.IsWeierstrassDivisor (L182-L188)
theorem IsWeierstrassDivisor.of_map_ne_zero [IsLocalRing A]
    (hg : g.map (IsLocalRing.residue A) ≠ 0) : g.IsWeierstrassDivisor
```

-- snippet 8
```lean
-- Mathlib.RingTheory.PowerSeries.WeierstrassPreparation.isUnit_shift (L214-L226)
theorem isUnit_shift : IsUnit <| mk fun i ↦
    coeff (i + (g.map (Ideal.Quotient.mk I)).order.toNat) g
```

-- snippet 9
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.PowerSeries (L58-L77)
abbrev PowerSeries (R : Type*)
```

-- snippet 10
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.forall_coeff_eq_zero (L98-L103)
theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff n φ = 0) ↔ φ = 0
```

-- snippet 11
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.coeff (L78-L81)
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R
```

-- snippet 12
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.monomial (L82-L84)
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧
```

-- snippet 13
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.ext (L91-L96)
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff n φ = coeff n ψ) : φ = ψ
```

-- snippet 14
```lean
-- Mathlib.RingTheory.PowerSeries.Basic.coeff_def (L85-L89)
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) :
    coeff (R
```
[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.FreeAbelianGroup.Finsupp).

[User]
Complete the following proof.

```lean
def Finsupp.toFreeAbelianGroup : (X →₀ ℤ) →+ FreeAbelianGroup X
```

Provide a complete Lean proof for the statement above. Do not include the statement in your answer.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.FreeAbelianGroup.Finsupp).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Complete the following proof.

```lean
def Finsupp.toFreeAbelianGroup : (X →₀ ℤ) →+ FreeAbelianGroup X
```

Provide a complete Lean proof for the statement above. Do not include the statement in your answer.[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.Module.Submodule.Defs).

[User]
The following Lean code fails to compile. Fix it.

```lean
instance setLike : SetLike (Submodule R M) M where
  coe s
  frobnicateTacticThatDoesNotExist := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=61, messages=[Message(data='unexpected identifier; expected structInstFieldDecl', pos=Position(line=2, column=7), pos_end=Position(line=3, column=34), severity=<Severity.ERROR: 3>, kind=None), Message(data='failed to synthesize instance of type class\n  Semiring R\n\nHint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.', pos=Position(line=1, column=28), pos_end=Position(line=1, column=41), severity=<Severity.ERROR: 3>, kind='lean.synthInstanceFailed._namedError')], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=61, i_end=189, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.Module.Submodule.Defs).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]The following Lean code fails to compile. Fix it.

```lean
instance setLike : SetLike (Submodule R M) M where
  coe s
  frobnicateTacticThatDoesNotExist := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=61, messages=[Message(data='unexpected identifier; expected structInstFieldDecl', pos=Position(line=2, column=7), pos_end=Position(line=3, column=34), severity=<Severity.ERROR: 3>, kind=None), Message(data='failed to synthesize instance of type class\n  Semiring R\n\nHint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.', pos=Position(line=1, column=28), pos_end=Position(line=1, column=41), severity=<Severity.ERROR: 3>, kind='lean.synthInstanceFailed._namedError')], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=61, i_end=189, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Monoidal.Functor).

[User]
The following Lean code fails to compile. Fix it.

```lean
lemma whiskerLeft_μ_δ (X Y : C) (T : D) : T ◁ μ F X Y ≫ T ◁ δ F X Y = 𝟙 _
:= by thisIsWrongLemmaNameXYZ
rw [← MonoidalCategory.whiskerLeft_comp, μ_δ, MonoidalCategory.whiskerLeft_id]
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=46, messages=[Message(data='expected token', pos=Position(line=1, column=44), pos_end=None, severity=<Severity.ERROR: 3>, kind=None)], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=46, i_end=199, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.CategoryTheory.Monoidal.Functor).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]The following Lean code fails to compile. Fix it.

```lean
lemma whiskerLeft_μ_δ (X Y : C) (T : D) : T ◁ μ F X Y ≫ T ◁ δ F X Y = 𝟙 _
:= by thisIsWrongLemmaNameXYZ
rw [← MonoidalCategory.whiskerLeft_comp, μ_δ, MonoidalCategory.whiskerLeft_id]
```

## Compiler diagnostic
```
[CompilationUnit(i_begin=0, i_end=46, messages=[Message(data='expected token', pos=Position(line=1, column=44), pos_end=None, severity=<Severity.ERROR: 3>, kind=None)], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None), CompilationUnit(i_begin=46, i_end=199, messages=[], invocations=None, goal_state=None, goal_src_boundaries=None, new_constants=None)]
```

Return a corrected, compiling version of the code.[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Topology.Algebra.InfiniteSum.UniformOn).

[User]
Complete the following proof.

```lean
theorem HasProdLocallyUniformly.hasProdLocallyUniformlyOn (h : HasProdLocallyUniformly f g) :
    HasProdLocallyUniformlyOn f g s
```

Provide a complete Lean proof for the statement above. Do not include the statement in your answer.

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Topology.Algebra.InfiniteSum.UniformOn).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Complete the following proof.

```lean
theorem HasProdLocallyUniformly.hasProdLocallyUniformlyOn (h : HasProdLocallyUniformly f g) :
    HasProdLocallyUniformlyOn f g s
```

Provide a complete Lean proof for the statement above. Do not include the statement in your answer.[/INST]