diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Category_GroupCat_EpiMono.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Category_GroupCat_EpiMono.jsonl" deleted file mode 100644--- "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_Category_GroupCat_EpiMono.jsonl" +++ /dev/null @@ -1,123 +0,0 @@ -{"state":"A : Type u\nB : Type v\ninst✝¹ : Group A\ninst✝ : Group B\nf : A →* B\nh : ∀ (u v : ↥(ker f) →* A), comp f u = comp f v → u = v\n⊢ ker f = ⊥","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by ","nextTactic":"simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))","declUpToTactic":"@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.34_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : Group A\ninst✝ : Group B\nf : A →* B\nh : ∀ (u v : ↥(ker f) →* A), comp f u = comp f v → u = v\n⊢ comp f (Subgroup.subtype (ker f)) = comp f 1","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by ","nextTactic":"aesop_cat","declUpToTactic":"@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.34_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ∀ (u v : B →* B ⧸ range f), comp u f = comp v f → u = v\n⊢ range f = ⊤","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n ","nextTactic":"specialize h 1 (QuotientGroup.mk' _) _","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ∀ (u v : B →* B ⧸ range f), comp u f = comp v f → u = v\n⊢ comp 1 f = comp (QuotientGroup.mk' (range f)) f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ","nextTactic":"ext1 x","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"case h\nA : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ∀ (u v : B →* B ⧸ range f), comp u f = comp v f → u = v\nx : A\n⊢ (comp 1 f) x = (comp (QuotientGroup.mk' (range f)) f) x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n ","nextTactic":"simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"case h\nA : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ∀ (u v : B →* B ⧸ range f), comp u f = comp v f → u = v\nx : A\n⊢ 1 = ↑(f x)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n ","nextTactic":"rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"case h\nA : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ∀ (u v : B →* B ⧸ range f), comp u f = comp v f → u = v\nx : A\n⊢ f x ∈ range f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n ","nextTactic":"exact ⟨x, rfl⟩","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : 1 = QuotientGroup.mk' (range f)\n⊢ range f = ⊤","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n ","nextTactic":"replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : 1 = QuotientGroup.mk' (range f)\n⊢ ker (QuotientGroup.mk' ?m.29435) = ker 1","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by ","nextTactic":"rw [h]","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"A : Type u\nB : Type v\ninst✝¹ : CommGroup A\ninst✝ : CommGroup B\nf : A →* B\nh : ker (QuotientGroup.mk' (range f)) = ker 1\n⊢ range f = ⊤","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n ","nextTactic":"rwa [ker_one, QuotientGroup.ker_mk'] at h","declUpToTactic":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.46_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ b • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n ","nextTactic":"rw [← y.2.choose_spec]","declUpToTactic":"instance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.119_0.wDYTn9LgMD7bTAL","decl":"instance : SMul B X' where\n smul b x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ b • (fun x => x • ↑(MonoidHom.range f)) (Exists.choose (_ : ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f))) ∈\n Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n ","nextTactic":"rw [leftCoset_assoc]","declUpToTactic":"instance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.119_0.wDYTn9LgMD7bTAL","decl":"instance : SMul B X' where\n smul b x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ (b * Exists.choose (_ : ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f))) • ↑(MonoidHom.range f) ∈\n Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n ","nextTactic":"let b' : B := y.2.choose","declUpToTactic":"instance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.119_0.wDYTn9LgMD7bTAL","decl":"instance : SMul B X' where\n smul b x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\nb' : ↑B := Exists.choose (_ : ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ (b * Exists.choose (_ : ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f))) • ↑(MonoidHom.range f) ∈\n Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n ","nextTactic":"use b * b'","declUpToTactic":"instance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.119_0.wDYTn9LgMD7bTAL","decl":"instance : SMul B X' where\n smul b x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb b' : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ (b * b') • fromCoset y = b • b' • fromCoset y","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n ","nextTactic":"change fromCoset _ = fromCoset _","declUpToTactic":"theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.130_0.wDYTn9LgMD7bTAL","decl":"theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb b' : ↑B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ fromCoset { val := (b * b') • ↑y, property := (_ : (b * b') • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)) } =\n fromCoset\n { val := b • ↑{ val := b' • ↑y, property := (_ : b' • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)) },\n property :=\n (_ :\n b • ↑{ val := b' • ↑y, property := (_ : b' • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n ","nextTactic":"simp only [leftCoset_assoc]","declUpToTactic":"theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.130_0.wDYTn9LgMD7bTAL","decl":"theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ 1 • fromCoset y = fromCoset y","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n ","nextTactic":"change fromCoset _ = fromCoset _","declUpToTactic":"theorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.138_0.wDYTn9LgMD7bTAL","decl":"theorem one_smul (x : X') : (1 : B) • x = x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : X'\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ fromCoset { val := 1 • ↑y, property := (_ : 1 • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)) } = fromCoset y","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n ","nextTactic":"simp only [one_leftCoset, Subtype.ext_iff_val]","declUpToTactic":"theorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.138_0.wDYTn9LgMD7bTAL","decl":"theorem one_smul (x : X') : (1 : B) • x = x "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∈ MonoidHom.range f\n⊢ fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) } =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","nextTactic":"congr","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∈ MonoidHom.range f\n⊢ b • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n ","nextTactic":"let b : B.α := b","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb✝ : ↑B\nhb : b✝ ∈ MonoidHom.range f\nb : ↑B := b✝\n⊢ b✝ • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n ","nextTactic":"change b • (f.range : Set B) = f.range","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb✝ : ↑B\nhb : b✝ ∈ MonoidHom.range f\nb : ↑B := b✝\n⊢ b • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n ","nextTactic":"nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb✝ : ↑B\nhb : b✝ ∈ MonoidHom.range f\nb : ↑B := b✝\n⊢ b • ↑(MonoidHom.range f) = 1 • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n ","nextTactic":"rw [leftCoset_eq_iff]","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb✝ : ↑B\nhb : b✝ ∈ MonoidHom.range f\nb : ↑B := b✝\n⊢ b⁻¹ * 1 ∈ MonoidHom.range f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B �� f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n ","nextTactic":"rw [mul_one]","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"case e_a.e_val\nA B : GroupCat\nf : A ⟶ B\nb✝ : ↑B\nhb : b✝ ∈ MonoidHom.range f\nb : ↑B := b✝\n⊢ b⁻¹ ∈ MonoidHom.range f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n ","nextTactic":"exact Subgroup.inv_mem _ hb","declUpToTactic":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.146_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) } ≠\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","nextTactic":"intro r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr :\n fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) } =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n ","nextTactic":"simp only [fromCoset.injEq, Subtype.mk.injEq] at r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : b • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n ","nextTactic":"let b' : B.α := b","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : b • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)\nb' : ↑B := b\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n ","nextTactic":"change b' • (f.range : Set B) = f.range at r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nb' : ↑B := b\nr : b' • ↑(MonoidHom.range f) = ↑(MonoidHom.range f)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n ","nextTactic":"nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nb' : ↑B := b\nr : b' • ↑(MonoidHom.range f) = 1 • ↑(MonoidHom.range f)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n ","nextTactic":"rw [leftCoset_eq_iff] at r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nb' : ↑B := b\nr : b'⁻¹ * 1 ∈ MonoidHom.range f\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n ","nextTactic":"rw [mul_one] at r","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : b ∉ MonoidHom.range f\nb' : ↑B := b\nr : b'⁻¹ ∈ MonoidHom.range f\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n ","nextTactic":"exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)","declUpToTactic":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.159_0.wDYTn9LgMD7bTAL","decl":"theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ τ.symm\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n ","nextTactic":"rw [tau]","declUpToTactic":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.196_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞).symm\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n ","nextTactic":"rw [Equiv.symm_swap]","declUpToTactic":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.196_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n ","nextTactic":"rw [Equiv.swap_apply_left]","declUpToTactic":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.196_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ τ.symm ∞ =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) �� f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","nextTactic":"rw [tau]","declUpToTactic":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.202_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞).symm\n ∞ =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n ","nextTactic":"rw [Equiv.symm_swap]","declUpToTactic":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.202_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n ∞ =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n ","nextTactic":"rw [Equiv.swap_apply_right]","declUpToTactic":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.202_0.wDYTn9LgMD7bTAL","decl":"theorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ (fun x => β⁻¹ • x) ((fun x => β • x) x) = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n ","nextTactic":"dsimp only","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ β⁻¹ • β • x = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n ","nextTactic":"rw [← mul_smul]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ (β⁻¹ * β) • x = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n ","nextTactic":"rw [mul_left_inv]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ 1 • x = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n ","nextTactic":"rw [one_smul]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ (fun x => β • x) ((fun x => β⁻¹ • x) x) = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n ","nextTactic":"dsimp only","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nβ : ↑B\nx : X'\n⊢ β • β⁻¹ • x = x","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.��_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n ","nextTactic":"rw [← mul_smul, mul_right_inv, one_smul]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ","nextTactic":"ext","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"case H\nA B : GroupCat\nf : A ⟶ B\nx✝ : X'\n⊢ ((fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1)\n x✝ =\n 1 x✝","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n ","nextTactic":"simp [one_smul]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb1 b2 : ↑B\n⊢ OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n (b1 * b2) =\n OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n b1 *\n OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n b2","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ","nextTactic":"ext","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"case H\nA B : GroupCat\nf : A ⟶ B\nb1 b2 : ↑B\nx✝ : X'\n⊢ (OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n (b1 * b2))\n x✝ =\n (OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n b1 *\n OneHom.toFun\n {\n toFun := fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) },\n map_one' :=\n (_ :\n (fun β =>\n { toFun := fun x => β • x, invFun := fun x => β⁻¹ • x,\n left_inv := (_ : ∀ (x : X'), (fun x => β⁻¹ • x) ((fun x => β • x) x) = x),\n right_inv := (_ : ∀ (x : X'), (fun x => β • x) ((fun x => β⁻¹ • x) x) = x) })\n 1 =\n 1) }\n b2)\n x✝","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n ","nextTactic":"simp [mul_smul]","declUpToTactic":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.209_0.wDYTn9LgMD7bTAL","decl":"/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ","nextTactic":"ext","declUpToTactic":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.234_0.wDYTn9LgMD7bTAL","decl":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β "} -{"state":"case H\nA B : GroupCat\nf : A ⟶ B\nx✝ : X'\n⊢ ((fun β => (τ.symm.trans (g β)).trans τ) 1) x✝ = 1 x✝","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n ","nextTactic":"simp","declUpToTactic":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.234_0.wDYTn9LgMD7bTAL","decl":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb1 b2 : ↑B\n⊢ OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n (b1 * b2) =\n OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n b1 *\n OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n b2","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ","nextTactic":"ext","declUpToTactic":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.234_0.wDYTn9LgMD7bTAL","decl":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β "} -{"state":"case H\nA B : GroupCat\nf : A ⟶ B\nb1 b2 : ↑B\nx✝ : X'\n⊢ (OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n (b1 * b2))\n x✝ =\n (OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n b1 *\n OneHom.toFun\n { toFun := fun β => (τ.symm.trans (g β)).trans τ,\n map_one' := (_ : (fun β => (τ.symm.trans (g β)).trans τ) 1 = 1) }\n b2)\n x✝","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n ","nextTactic":"simp","declUpToTactic":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.234_0.wDYTn9LgMD7bTAL","decl":"/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\n⊢ x • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by ","nextTactic":"obtain ⟨z, hz⟩ := y.2","declUpToTactic":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.257_0.wDYTn9LgMD7bTAL","decl":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ "} -{"state":"case intro\nA B : GroupCat\nf : A ⟶ B\nx : ↑B\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\nz : ↑B\nhz : (fun x => x • ↑(MonoidHom.range f)) z = ↑y\n⊢ x • ↑y ∈ Set.range fun x => x • ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; ","nextTactic":"exact ⟨x * z, by simp [← hz, smul_smul]⟩","declUpToTactic":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.257_0.wDYTn9LgMD7bTAL","decl":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\ny : ↑(Set.range fun x => x • ↑(MonoidHom.range f))\nz : ↑B\nhz : (fun x => x • ↑(MonoidHom.range f)) z = ↑y\n⊢ (fun x => x • ↑(MonoidHom.range f)) (x * z) = x • ↑y","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by ","nextTactic":"simp [← hz, smul_smul]","declUpToTactic":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.257_0.wDYTn9LgMD7bTAL","decl":"theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\n⊢ (h x) ∞ = ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n ","nextTactic":"change ((τ).symm.trans (g x)).trans τ _ = _","declUpToTactic":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.265_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\n⊢ ((τ.symm.trans (g x)).trans τ) ∞ = ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","nextTactic":"simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]","declUpToTactic":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.265_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\n⊢ τ ((g x) (τ.symm ∞)) = ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n ","nextTactic":"rw [τ_symm_apply_infinity]","declUpToTactic":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.265_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\n⊢ τ\n ((g x)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })) =\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n ","nextTactic":"rw [g_apply_fromCoset]","declUpToTactic":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.265_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\n⊢ τ\n (fromCoset\n {\n val :=\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) },\n property :=\n (_ :\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }) =\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n ","nextTactic":"simpa only using τ_apply_fromCoset' f x hx","declUpToTactic":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.265_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\n⊢ (h x)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","nextTactic":"change ((τ).symm.trans (g x)).trans τ _ = _","declUpToTactic":"theorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.273_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\n⊢ ((τ.symm.trans (g x)).trans τ)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","nextTactic":"simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]","declUpToTactic":"theorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.273_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ (h x)\n (fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = (x * b) • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n ","nextTactic":"change ((τ).symm.trans (g x)).trans τ _ = _","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ ((τ.symm.trans (g x)).trans τ)\n (fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = (x * b) • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm �� h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","nextTactic":"simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n ((g x)\n ((Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞).symm\n (fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }))) =\n fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = (x * b) • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n ","nextTactic":"rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) } ≠\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by ","nextTactic":"simp","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n ((g x)\n (fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) })) =\n fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = (x * b) • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n ","nextTactic":"simp only [g_apply_fromCoset, leftCoset_assoc]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ (Equiv.swap\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n (fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property :=\n (_ : (fun x => x ∈ Set.range fun x => x • ↑(MonoidHom.range f)) ((x * b) • ↑(MonoidHom.range f))) }) =\n fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = (x * b) • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n ","nextTactic":"refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\n⊢ fromCoset\n { val := (x * b) • ↑(MonoidHom.range f),\n property :=\n (_ : (fun x => x ∈ Set.range fun x => x • ↑(MonoidHom.range f)) ((x * b) • ↑(MonoidHom.range f))) } ≠\n ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by ","nextTactic":"simp","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : x * b ∈ MonoidHom.range f\n⊢ b ∈ MonoidHom.range f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n ","nextTactic":"convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"case h.e'_4\nA B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : x * b ∈ MonoidHom.range f\n⊢ b = x⁻¹ * (x * b)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ��� h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n ","nextTactic":"rw [← mul_assoc]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"case h.e'_4\nA B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : x * b ∈ MonoidHom.range f\n⊢ b = x⁻¹ * x * b","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n ","nextTactic":"rw [mul_left_inv]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"case h.e'_4\nA B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∈ MonoidHom.range f\nb : ↑B\nhb : b ∉ MonoidHom.range f\nr : x * b ∈ MonoidHom.range f\n⊢ b = 1 * b","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n ","nextTactic":"rw [one_mul]","declUpToTactic":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.285_0.wDYTn9LgMD7bTAL","decl":"theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ ↑(MonoidHom.range f) = {x | h x = g x}","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ �� = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n ","nextTactic":"refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1\nA B : GroupCat\nf : A ⟶ B\nb : ↑B\n⊢ b ∈ ↑(MonoidHom.range f) → b ∈ {x | h x = g x}","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) ��� x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x �� f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · ","nextTactic":"rintro ⟨a, rfl⟩","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1.intro\nA B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ f a ∈ {x | h x = g x}","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n ","nextTactic":"change h (f a) = g (f a)","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1.intro\nA B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ h (f a) = g (f a)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ","nextTactic":"ext ⟨⟨_, ⟨y, rfl⟩⟩⟩","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1.intro.H.fromCoset.mk.intro\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\n⊢ (h (f a))\n (fromCoset\n { val := (fun x => x • ↑(MonoidHom.range f)) y,\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) }) =\n (g (f a))\n (fromCoset\n { val := (fun x => x • ↑(MonoidHom.range f)) y,\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) })","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · ","nextTactic":"rw [g_apply_fromCoset]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1.intro.H.fromCoset.mk.intro\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\n⊢ (h (f a))\n (fromCoset\n { val := (fun x => x • ↑(MonoidHom.range f)) y,\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) }) =\n fromCoset\n {\n val :=\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) },\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n ","nextTactic":"by_cases m : y ∈ f.range","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case pos\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\nm : y ∈ MonoidHom.range f\n⊢ (h (f a))\n (fromCoset\n { val := (fun x => x • ↑(MonoidHom.range f)) y,\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) }) =\n fromCoset\n {\n val :=\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) },\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · ","nextTactic":"rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case pos\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\nm : y ∈ MonoidHom.range f\n⊢ fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } =\n fromCoset\n {\n val :=\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) },\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n ","nextTactic":"change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case pos\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\nm : y ∈ MonoidHom.range f\n⊢ fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } =\n fromCoset\n { val := f a • y • ↑(MonoidHom.range f),\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n ","nextTactic":"simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case neg\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\nm : y ∉ MonoidHom.range f\n⊢ (h (f a))\n (fromCoset\n { val := (fun x => x • ↑(MonoidHom.range f)) y,\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) }) =\n fromCoset\n {\n val :=\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) },\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · ","nextTactic":"rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case neg\nA B : GroupCat\nf : A ⟶ B\na : ↑A\ny : ↑B\nm : y ∉ MonoidHom.range f\n⊢ fromCoset\n { val := (f a * y) • ↑(MonoidHom.range f),\n property := (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (f a * y) • ↑(MonoidHom.range f)) } =\n fromCoset\n {\n val :=\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) },\n property :=\n (_ :\n f a •\n ↑{ val := (fun x => x • ↑(MonoidHom.range f)) y,\n property :=\n (_ : ∃ y_1, (fun x => x • ↑(MonoidHom.range f)) y_1 = (fun x => x • ↑(MonoidHom.range f)) y) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n ","nextTactic":"simp only [leftCoset_assoc]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_1.intro.H.infinity\nA B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ (h (f a)) ∞ = (g (f a)) ∞","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · ","nextTactic":"rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_2\nA B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · ","nextTactic":"have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\n⊢ (h b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","nextTactic":"change ((τ).symm.trans (g b)).trans τ _ = _","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\n⊢ ((τ.symm.trans (g b)).trans τ)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n ","nextTactic":"dsimp [tau]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\n⊢ (Equiv.swap\n (fromCoset\n { val := Set.range ⇑f, property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n ((g b)\n ((Equiv.swap\n (fromCoset\n { val := Set.range ⇑f,\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n ∞)\n (fromCoset { val := Set.range ⇑f, property := (_ : ∃ y, y • Set.range ⇑f = Set.range ⇑f) }))) =\n fromCoset { val := Set.range ⇑f, property := (_ : ∃ y, y • Set.range ⇑f = Set.range ⇑f) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n ","nextTactic":"simp [g_apply_infinity f]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_2\nA B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\neq1 :\n (h b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n ","nextTactic":"have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"case refine'_2\nA B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\neq1 :\n (h b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }\neq2 :\n (g b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n ","nextTactic":"exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"A B : GroupCat\nf : A ⟶ B\nb : ↑B\nhb : h b = g b\nr : b ∉ ↑(MonoidHom.range f)\neq1 :\n (h b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }\neq2 :\n (g b)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }\n⊢ fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } =\n fromCoset\n { val := b • ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = b • ↑(MonoidHom.range f)) }","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by ","nextTactic":"rw [← eq1, ← eq2, FunLike.congr_fun hb]","declUpToTactic":"theorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.300_0.wDYTn9LgMD7bTAL","decl":"theorem agree : f.range = { x | h x = g x } "} -{"state":"A B : GroupCat\nf : A ⟶ B\n⊢ (f ≫\n let_fun this := g;\n this) =\n f ≫\n let_fun this := h;\n this","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ","nextTactic":"ext a","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"case w\nA B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ (f ≫\n let_fun this := g;\n this)\n a =\n (f ≫\n let_fun this := h;\n this)\n a","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n ","nextTactic":"change g (f a) = h (f a)","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"case w\nA B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ g (f a) = h (f a)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n ","nextTactic":"have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"A B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ f a ∈ {b | h b = g b}","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n ","nextTactic":"rw [← agree]","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"A B : GroupCat\nf : A ⟶ B\na : ↑A\n⊢ f a ∈ ↑(MonoidHom.range f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n ","nextTactic":"use a","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"case w\nA B : GroupCat\nf : A ⟶ B\na : ↑A\nthis : f a ∈ {b | h b = g b}\n⊢ g (f a) = h (f a)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n ","nextTactic":"rw [this]","declUpToTactic":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.323_0.wDYTn9LgMD7bTAL","decl":"theorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\n⊢ g ≠ h","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n ","nextTactic":"intro r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr : g = h\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n ","nextTactic":"replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n (g x)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n (h x)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n ","nextTactic":"change _ = ((τ).symm.trans (g x)).trans τ _ at r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n (g x)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }) =\n ((τ.symm.trans (g x)).trans τ)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n ","nextTactic":"rw [g_apply_fromCoset] at r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n fromCoset\n {\n val :=\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) },\n property :=\n (_ :\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) } =\n ((τ.symm.trans (g x)).trans τ)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n ","nextTactic":"rw [MonoidHom.coe_mk] at r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n fromCoset\n {\n val :=\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) },\n property :=\n (_ :\n x •\n ↑{ val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) } ∈\n Set.range fun x => x • ↑(MonoidHom.range f)) } =\n ((τ.symm.trans (↑g x)).trans τ)\n (fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) })\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n ","nextTactic":"simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n fromCoset\n { val := x • Set.range ⇑f,\n property := (_ : (fun x => x ∈ Set.range fun x => x • ↑(MonoidHom.range f)) (x • Set.range ⇑f)) } =\n τ\n ((↑g x)\n (τ.symm\n (fromCoset\n { val := Set.range ⇑f,\n property := (_ : (fun x => x ∈ Set.range fun x => x • ↑(MonoidHom.range f)) (Set.range ⇑f)) })))\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n ","nextTactic":"erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\nx : ↑B\nhx : x ∉ MonoidHom.range f\nr :\n fromCoset\n { val := x • Set.range ⇑f,\n property := (_ : (fun x => x ∈ Set.range fun x => x • ↑(MonoidHom.range f)) (x • Set.range ⇑f)) } =\n fromCoset\n { val := ↑(MonoidHom.range f),\n property := (_ : ∃ y, (fun x => x • ↑(MonoidHom.range f)) y = ↑(MonoidHom.range f)) }\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n ","nextTactic":"exact fromCoset_ne_of_nin_range _ hx r","declUpToTactic":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.332_0.wDYTn9LgMD7bTAL","decl":"theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h "} -{"state":"A B : GroupCat\nf : A ⟶ B\ninst✝ : Epi f\n⊢ Function.Surjective ⇑f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n ","nextTactic":"by_contra r","declUpToTactic":"theorem surjective_of_epi [Epi f] : Function.Surjective f := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.347_0.wDYTn9LgMD7bTAL","decl":"theorem surjective_of_epi [Epi f] : Function.Surjective f "} -{"state":"A B : GroupCat\nf : A ⟶ B\ninst✝ : Epi f\nr : ¬Function.Surjective ⇑f\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n ","nextTactic":"dsimp [Function.Surjective] at r","declUpToTactic":"theorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.347_0.wDYTn9LgMD7bTAL","decl":"theorem surjective_of_epi [Epi f] : Function.Surjective f "} -{"state":"A B : GroupCat\nf : A ⟶ B\ninst✝ : Epi f\nr : ¬∀ (b : ↑B), ∃ a, f a = b\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n ","nextTactic":"push_neg at r","declUpToTactic":"theorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.347_0.wDYTn9LgMD7bTAL","decl":"theorem surjective_of_epi [Epi f] : Function.Surjective f "} -{"state":"A B : GroupCat\nf : A ⟶ B\ninst✝ : Epi f\nr : ∃ b, ∀ (a : ↑A), f a ≠ b\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n ","nextTactic":"rcases r with ⟨b, hb⟩","declUpToTactic":"theorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.347_0.wDYTn9LgMD7bTAL","decl":"theorem surjective_of_epi [Epi f] : Function.Surjective f "} -{"state":"case intro\nA B : GroupCat\nf : A ⟶ B\ninst✝ : Epi f\nb : ↑B\nhb : ∀ (a : ↑A), f a ≠ b\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n ","nextTactic":"exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))","declUpToTactic":"theorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.347_0.wDYTn9LgMD7bTAL","decl":"theorem surjective_of_epi [Epi f] : Function.Surjective f "} -{"state":"A B : AddGroupCat\nf : A ⟶ B\n⊢ Epi f ↔ Function.Surjective ⇑f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n ","nextTactic":"have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi","declUpToTactic":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.373_0.wDYTn9LgMD7bTAL","decl":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : AddGroupCat\nf : A ⟶ B\n⊢ Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n ","nextTactic":"refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩","declUpToTactic":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.373_0.wDYTn9LgMD7bTAL","decl":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : AddGroupCat\nf : A ⟶ B\n⊢ Epi f → Epi (groupAddGroupEquivalence.inverse.map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨��f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n ","nextTactic":"intro e'","declUpToTactic":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.373_0.wDYTn9LgMD7bTAL","decl":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : AddGroupCat\nf : A ⟶ B\ne' : Epi f\n⊢ Epi (groupAddGroupEquivalence.inverse.map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n ","nextTactic":"apply groupAddGroupEquivalence.inverse.map_epi","declUpToTactic":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.373_0.wDYTn9LgMD7bTAL","decl":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : AddGroupCat\nf : A ⟶ B\ni1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f)\n⊢ Epi f ↔ Function.Surjective ⇑f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n ","nextTactic":"rwa [GroupCat.epi_iff_surjective] at i1","declUpToTactic":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.373_0.wDYTn9LgMD7bTAL","decl":"theorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : GroupCat\nf✝ : A ⟶ B\nX✝ Y✝ : GroupCat\nf : X✝ ⟶ Y✝\ne : Mono f\n⊢ Mono ((forget GroupCat).map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by ","nextTactic":"rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e","declUpToTactic":"@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.393_0.wDYTn9LgMD7bTAL","decl":"@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e "} -{"state":"A B : GroupCat\nf✝ : A ⟶ B\nX✝ Y✝ : GroupCat\nf : X✝ ⟶ Y✝\ne : Epi f\n⊢ Epi ((forget GroupCat).map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align Group.forget_Group_preserves_mono GroupCat.forget_groupCat_preserves_mono\n#align AddGroup.forget_Group_preserves_mono AddGroupCat.forget_groupCat_preserves_mono\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by ","nextTactic":"rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e","declUpToTactic":"@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.399_0.wDYTn9LgMD7bTAL","decl":"@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e "} -{"state":"A B : CommGroupCat\nf : A ⟶ B\n⊢ Epi f ↔ Function.Surjective ⇑f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align Group.forget_Group_preserves_mono GroupCat.forget_groupCat_preserves_mono\n#align AddGroup.forget_Group_preserves_mono AddGroupCat.forget_groupCat_preserves_mono\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e\n#align Group.forget_Group_preserves_epi GroupCat.forget_groupCat_preserves_epi\n#align AddGroup.forget_Group_preserves_epi AddGroupCat.forget_groupCat_preserves_epi\n\nend GroupCat\n\nnamespace CommGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : CommGroupCat.{u}} (f : A ⟶ B)\n\n-- Porting note: again to help with non-transparency\nprivate instance (A : CommGroupCat) : CommGroup A.α := A.str\nprivate instance (A : CommGroupCat) : Group A.α := A.str.toGroup\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show CommGroupCat.of f.ker ⟶ A from u) _).1\n#align CommGroup.ker_eq_bot_of_mono CommGroupCat.ker_eq_bot_of_mono\n#align AddCommGroup.ker_eq_bot_of_mono AddCommGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align CommGroup.mono_iff_ker_eq_bot CommGroupCat.mono_iff_ker_eq_bot\n#align AddCommGroup.mono_iff_ker_eq_bot AddCommGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align CommGroup.mono_iff_injective CommGroupCat.mono_iff_injective\n#align AddCommGroup.mono_iff_injective AddCommGroupCat.mono_iff_injective\n\n@[to_additive]\ntheorem range_eq_top_of_epi [Epi f] : f.range = ⊤ :=\n MonoidHom.range_eq_top_of_cancel fun u v h =>\n (@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ MonoidHom.range f, inferInstance⟩ from u) v).1 h\n#align CommGroup.range_eq_top_of_epi CommGroupCat.range_eq_top_of_epi\n#align AddCommGroup.range_eq_top_of_epi AddCommGroupCat.range_eq_top_of_epi\n\n-- Porting note: again lack of transparency\n@[to_additive]\ninstance (G : CommGroupCat) : CommGroup <| (forget CommGroupCat).obj G :=\n G.str\n\n@[to_additive]\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n ⟨fun _ => range_eq_top_of_epi _, fun hf =>\n ConcreteCategory.epi_of_surjective _ <| MonoidHom.range_top_iff_surjective.mp hf⟩\n#align CommGroup.epi_iff_range_eq_top CommGroupCat.epi_iff_range_eq_top\n#align AddCommGroup.epi_iff_range_eq_top AddCommGroupCat.epi_iff_range_eq_top\n\n@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n ","nextTactic":"rw [epi_iff_range_eq_top]","declUpToTactic":"@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.456_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : CommGroupCat\nf : A ⟶ B\n⊢ MonoidHom.range f = ⊤ ↔ Function.Surjective ⇑f","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align Group.forget_Group_preserves_mono GroupCat.forget_groupCat_preserves_mono\n#align AddGroup.forget_Group_preserves_mono AddGroupCat.forget_groupCat_preserves_mono\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e\n#align Group.forget_Group_preserves_epi GroupCat.forget_groupCat_preserves_epi\n#align AddGroup.forget_Group_preserves_epi AddGroupCat.forget_groupCat_preserves_epi\n\nend GroupCat\n\nnamespace CommGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : CommGroupCat.{u}} (f : A ⟶ B)\n\n-- Porting note: again to help with non-transparency\nprivate instance (A : CommGroupCat) : CommGroup A.α := A.str\nprivate instance (A : CommGroupCat) : Group A.α := A.str.toGroup\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show CommGroupCat.of f.ker ⟶ A from u) _).1\n#align CommGroup.ker_eq_bot_of_mono CommGroupCat.ker_eq_bot_of_mono\n#align AddCommGroup.ker_eq_bot_of_mono AddCommGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align CommGroup.mono_iff_ker_eq_bot CommGroupCat.mono_iff_ker_eq_bot\n#align AddCommGroup.mono_iff_ker_eq_bot AddCommGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align CommGroup.mono_iff_injective CommGroupCat.mono_iff_injective\n#align AddCommGroup.mono_iff_injective AddCommGroupCat.mono_iff_injective\n\n@[to_additive]\ntheorem range_eq_top_of_epi [Epi f] : f.range = ⊤ :=\n MonoidHom.range_eq_top_of_cancel fun u v h =>\n (@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ MonoidHom.range f, inferInstance⟩ from u) v).1 h\n#align CommGroup.range_eq_top_of_epi CommGroupCat.range_eq_top_of_epi\n#align AddCommGroup.range_eq_top_of_epi AddCommGroupCat.range_eq_top_of_epi\n\n-- Porting note: again lack of transparency\n@[to_additive]\ninstance (G : CommGroupCat) : CommGroup <| (forget CommGroupCat).obj G :=\n G.str\n\n@[to_additive]\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n ⟨fun _ => range_eq_top_of_epi _, fun hf =>\n ConcreteCategory.epi_of_surjective _ <| MonoidHom.range_top_iff_surjective.mp hf⟩\n#align CommGroup.epi_iff_range_eq_top CommGroupCat.epi_iff_range_eq_top\n#align AddCommGroup.epi_iff_range_eq_top AddCommGroupCat.epi_iff_range_eq_top\n\n@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n rw [epi_iff_range_eq_top]\n ","nextTactic":"rw [MonoidHom.range_top_iff_surjective]","declUpToTactic":"@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n rw [epi_iff_range_eq_top]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.456_0.wDYTn9LgMD7bTAL","decl":"@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f "} -{"state":"A B : CommGroupCat\nf✝ : A ⟶ B\nX✝ Y✝ : CommGroupCat\nf : X✝ ⟶ Y✝\ne : Mono f\n⊢ Mono ((forget CommGroupCat).map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align Group.forget_Group_preserves_mono GroupCat.forget_groupCat_preserves_mono\n#align AddGroup.forget_Group_preserves_mono AddGroupCat.forget_groupCat_preserves_mono\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e\n#align Group.forget_Group_preserves_epi GroupCat.forget_groupCat_preserves_epi\n#align AddGroup.forget_Group_preserves_epi AddGroupCat.forget_groupCat_preserves_epi\n\nend GroupCat\n\nnamespace CommGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : CommGroupCat.{u}} (f : A ⟶ B)\n\n-- Porting note: again to help with non-transparency\nprivate instance (A : CommGroupCat) : CommGroup A.α := A.str\nprivate instance (A : CommGroupCat) : Group A.α := A.str.toGroup\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show CommGroupCat.of f.ker ⟶ A from u) _).1\n#align CommGroup.ker_eq_bot_of_mono CommGroupCat.ker_eq_bot_of_mono\n#align AddCommGroup.ker_eq_bot_of_mono AddCommGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align CommGroup.mono_iff_ker_eq_bot CommGroupCat.mono_iff_ker_eq_bot\n#align AddCommGroup.mono_iff_ker_eq_bot AddCommGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align CommGroup.mono_iff_injective CommGroupCat.mono_iff_injective\n#align AddCommGroup.mono_iff_injective AddCommGroupCat.mono_iff_injective\n\n@[to_additive]\ntheorem range_eq_top_of_epi [Epi f] : f.range = ⊤ :=\n MonoidHom.range_eq_top_of_cancel fun u v h =>\n (@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ MonoidHom.range f, inferInstance⟩ from u) v).1 h\n#align CommGroup.range_eq_top_of_epi CommGroupCat.range_eq_top_of_epi\n#align AddCommGroup.range_eq_top_of_epi AddCommGroupCat.range_eq_top_of_epi\n\n-- Porting note: again lack of transparency\n@[to_additive]\ninstance (G : CommGroupCat) : CommGroup <| (forget CommGroupCat).obj G :=\n G.str\n\n@[to_additive]\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n ⟨fun _ => range_eq_top_of_epi _, fun hf =>\n ConcreteCategory.epi_of_surjective _ <| MonoidHom.range_top_iff_surjective.mp hf⟩\n#align CommGroup.epi_iff_range_eq_top CommGroupCat.epi_iff_range_eq_top\n#align AddCommGroup.epi_iff_range_eq_top AddCommGroupCat.epi_iff_range_eq_top\n\n@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n rw [epi_iff_range_eq_top]\n rw [MonoidHom.range_top_iff_surjective]\n#align CommGroup.epi_iff_surjective CommGroupCat.epi_iff_surjective\n#align AddCommGroup.epi_iff_surjective AddCommGroupCat.epi_iff_surjective\n\n@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_mono]\ninstance forget_commGroupCat_preserves_mono : (forget CommGroupCat).PreservesMonomorphisms where\n preserves f e := by ","nextTactic":"rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e","declUpToTactic":"@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_mono]\ninstance forget_commGroupCat_preserves_mono : (forget CommGroupCat).PreservesMonomorphisms where\n preserves f e := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.463_0.wDYTn9LgMD7bTAL","decl":"@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_mono]\ninstance forget_commGroupCat_preserves_mono : (forget CommGroupCat).PreservesMonomorphisms where\n preserves f e "} -{"state":"A B : CommGroupCat\nf✝ : A ⟶ B\nX✝ Y✝ : CommGroupCat\nf : X✝ ⟶ Y✝\ne : Epi f\n⊢ Epi ((forget CommGroupCat).map f)","srcUpToTactic":"/-\nCopyright (c) 2022 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jujian Zhang\n-/\nimport Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup\nimport Mathlib.GroupTheory.QuotientGroup\n\n#align_import algebra.category.Group.epi_mono from \"leanprover-community/mathlib\"@\"70fd9563a21e7b963887c9360bd29b2393e6225a\"\n\n/-!\n# Monomorphisms and epimorphisms in `Group`\nIn this file, we prove monomorphisms in the category of groups are injective homomorphisms and\nepimorphisms are surjective homomorphisms.\n-/\n\n\nnoncomputable section\n\nopen scoped Pointwise\n\nuniverse u v\n\nnamespace MonoidHom\n\nopen QuotientGroup\n\nvariable {A : Type u} {B : Type v}\n\nsection\n\nvariable [Group A] [Group B]\n\n@[to_additive]\ntheorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :\n f.ker = ⊥ := by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))\n#align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel\n#align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel\n\nend\n\nsection\n\nvariable [CommGroup A] [CommGroup B]\n\n@[to_additive]\ntheorem range_eq_top_of_cancel {f : A →* B}\n (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by\n specialize h 1 (QuotientGroup.mk' _) _\n · ext1 x\n simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]\n rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,\n one_mul]\n exact ⟨x, rfl⟩\n replace h : (QuotientGroup.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]\n rwa [ker_one, QuotientGroup.ker_mk'] at h\n#align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel\n#align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel\n\nend\n\nend MonoidHom\n\nsection\n\nopen CategoryTheory\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\n-- Porting note: already have Group G but Lean can't use that\n@[to_additive]\ninstance (G : GroupCat) : Group G.α :=\n G.str\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1\n#align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono\n#align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot\n#align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align Group.mono_iff_injective GroupCat.mono_iff_injective\n#align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective\n\nnamespace SurjectiveOfEpiAuxs\n\nset_option quotPrecheck false in\nlocal notation \"X\" => Set.range (· • (f.range : Set B) : B → Set B)\n\n/-- Define `X'` to be the set of all left cosets with an extra point at \"infinity\".\n-/\ninductive XWithInfinity\n | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity\n | infinity : XWithInfinity\n#align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity\n\nopen XWithInfinity Equiv.Perm\n\nlocal notation \"X'\" => XWithInfinity f\n\nlocal notation \"∞\" => XWithInfinity.infinity\n\nlocal notation \"SX'\" => Equiv.Perm X'\n\ninstance : SMul B X' where\n smul b x :=\n match x with\n | fromCoset y => fromCoset ⟨b • y, by\n rw [← y.2.choose_spec]\n rw [leftCoset_assoc]\n -- Porting note: should we make `Bundled.α` reducible?\n let b' : B := y.2.choose\n use b * b'⟩\n | ∞ => ∞\n\ntheorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [leftCoset_assoc]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul\n\ntheorem one_smul (x : X') : (1 : B) • x = x :=\n match x with\n | fromCoset y => by\n change fromCoset _ = fromCoset _\n simp only [one_leftCoset, Subtype.ext_iff_val]\n | ∞ => rfl\n#align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul\n\ntheorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n congr\n let b : B.α := b\n change b • (f.range : Set B) = f.range\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]\n rw [leftCoset_eq_iff]\n rw [mul_one]\n exact Subgroup.inv_mem _ hb\n#align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range\n\nexample (G : Type) [Group G] (S : Subgroup G) : Set G := S\n\ntheorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :\n fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n intro r\n simp only [fromCoset.injEq, Subtype.mk.injEq] at r\n -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B\n let b' : B.α := b\n change b' • (f.range : Set B) = f.range at r\n nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r\n rw [leftCoset_eq_iff] at r\n rw [mul_one] at r\n exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)\n#align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range\n\ninstance : DecidableEq X' :=\n Classical.decEq _\n\n/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.\n-/\nnoncomputable def tau : SX' :=\n Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞\n#align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau\n\nlocal notation \"τ\" => tau f\n\ntheorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=\n Equiv.swap_apply_right _ _\n#align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity\n\ntheorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=\n Equiv.swap_apply_left _ _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset\n\ntheorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :\n τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=\n (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _\n#align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset'\n\ntheorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_left]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset\n\ntheorem τ_symm_apply_infinity :\n Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n rw [tau]\n rw [Equiv.symm_swap]\n rw [Equiv.swap_apply_right]\n#align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity\n\n/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending\npoint at infinity to point at infinity and sending coset `y` to `β • y`.\n-/\ndef g : B →* SX' where\n toFun β :=\n { toFun := fun x => β • x\n invFun := fun x => β⁻¹ • x\n left_inv := fun x => by\n dsimp only\n rw [← mul_smul]\n rw [mul_left_inv]\n rw [one_smul]\n right_inv := fun x => by\n dsimp only\n rw [← mul_smul, mul_right_inv, one_smul] }\n map_one' := by\n ext\n simp [one_smul]\n map_mul' b1 b2 := by\n ext\n simp [mul_smul]\n#align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g\n\nlocal notation \"g\" => g f\n\n/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`\n-/\ndef h : B →* SX' where\n -- Porting note: mathport removed () from (τ) which are needed\n toFun β := ((τ).symm.trans (g β)).trans τ\n map_one' := by\n ext\n simp\n map_mul' b1 b2 := by\n ext\n simp\n#align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h\n\nlocal notation \"h\" => h f\n\n/-!\nThe strategy is the following: assuming `epi f`\n* prove that `f.range = {x | h x = g x}`;\n* thus `f ≫ h = f ≫ g` so that `h = g`;\n* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.\n-/\n\n\ntheorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :\n g x (fromCoset y) = fromCoset ⟨x • ↑y,\n by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset\n\ntheorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl\n#align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity\n\ntheorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [τ_symm_apply_infinity]\n rw [g_apply_fromCoset]\n simpa only using τ_apply_fromCoset' f x hx\n#align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity\n\ntheorem h_apply_fromCoset (x : B) :\n (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset\n\ntheorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=\n (fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset'\n\ntheorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :\n h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by\n change ((τ).symm.trans (g x)).trans τ _ = _\n simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]\n rw [Equiv.symm_swap,\n @Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞\n (fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]\n simp only [g_apply_fromCoset, leftCoset_assoc]\n refine' Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb _) (by simp)\n convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r\n rw [← mul_assoc]\n rw [mul_left_inv]\n rw [one_mul]\n#align Group.surjective_of_epi_auxs.h_apply_fromCoset_nin_range GroupCat.SurjectiveOfEpiAuxs.h_apply_fromCoset_nin_range\n\ntheorem agree : f.range = { x | h x = g x } := by\n refine' Set.ext fun b => ⟨_, fun hb : h b = g b => by_contradiction fun r => _⟩\n · rintro ⟨a, rfl⟩\n change h (f a) = g (f a)\n ext ⟨⟨_, ⟨y, rfl⟩⟩⟩\n · rw [g_apply_fromCoset]\n by_cases m : y ∈ f.range\n · rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]\n change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩\n simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]\n · rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]\n simp only [leftCoset_assoc]\n · rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]\n · have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =\n fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by\n change ((τ).symm.trans (g b)).trans τ _ = _\n dsimp [tau]\n simp [g_apply_infinity f]\n have eq2 :\n g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl\n exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, FunLike.congr_fun hb])\n#align Group.surjective_of_epi_auxs.agree GroupCat.SurjectiveOfEpiAuxs.agree\n\ntheorem comp_eq : (f ≫ show B ⟶ GroupCat.of SX' from g) = f ≫ show B ⟶ GroupCat.of SX' from h := by\n ext a\n change g (f a) = h (f a)\n have : f a ∈ { b | h b = g b } := by\n rw [← agree]\n use a\n rw [this]\n#align Group.surjective_of_epi_auxs.comp_eq GroupCat.SurjectiveOfEpiAuxs.comp_eq\n\ntheorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by\n intro r\n replace r :=\n FunLike.congr_fun (FunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)\n change _ = ((τ).symm.trans (g x)).trans τ _ at r\n rw [g_apply_fromCoset] at r\n rw [MonoidHom.coe_mk] at r\n simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,\n Equiv.coe_trans, Function.comp_apply] at r\n erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r\n exact fromCoset_ne_of_nin_range _ hx r\n#align Group.surjective_of_epi_auxs.g_ne_h GroupCat.SurjectiveOfEpiAuxs.g_ne_h\n\nend SurjectiveOfEpiAuxs\n\ntheorem surjective_of_epi [Epi f] : Function.Surjective f := by\n by_contra r\n dsimp [Function.Surjective] at r\n push_neg at r\n rcases r with ⟨b, hb⟩\n exact\n SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)\n ((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))\n#align Group.surjective_of_epi GroupCat.surjective_of_epi\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=\n ⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩\n#align Group.epi_iff_surjective GroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm\n#align Group.epi_iff_range_eq_top GroupCat.epi_iff_range_eq_top\n\nend GroupCat\n\nnamespace AddGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : AddGroupCat.{u}} (f : A ⟶ B)\n\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by\n refine' ⟨_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩\n intro e'\n apply groupAddGroupEquivalence.inverse.map_epi\n rwa [GroupCat.epi_iff_surjective] at i1\n#align AddGroup.epi_iff_surjective AddGroupCat.epi_iff_surjective\n\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm\n#align AddGroup.epi_iff_range_eq_top AddGroupCat.epi_iff_range_eq_top\n\nend AddGroupCat\n\nnamespace GroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : GroupCat.{u}} (f : A ⟶ B)\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_mono]\ninstance forget_groupCat_preserves_mono : (forget GroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align Group.forget_Group_preserves_mono GroupCat.forget_groupCat_preserves_mono\n#align AddGroup.forget_Group_preserves_mono AddGroupCat.forget_groupCat_preserves_mono\n\n@[to_additive AddGroupCat.forget_groupCat_preserves_epi]\ninstance forget_groupCat_preserves_epi : (forget GroupCat).PreservesEpimorphisms where\n preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e\n#align Group.forget_Group_preserves_epi GroupCat.forget_groupCat_preserves_epi\n#align AddGroup.forget_Group_preserves_epi AddGroupCat.forget_groupCat_preserves_epi\n\nend GroupCat\n\nnamespace CommGroupCat\n\nset_option linter.uppercaseLean3 false\n\nvariable {A B : CommGroupCat.{u}} (f : A ⟶ B)\n\n-- Porting note: again to help with non-transparency\nprivate instance (A : CommGroupCat) : CommGroup A.α := A.str\nprivate instance (A : CommGroupCat) : Group A.α := A.str.toGroup\n\n@[to_additive]\ntheorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=\n MonoidHom.ker_eq_bot_of_cancel fun u _ =>\n (@cancel_mono _ _ _ _ _ f _ (show CommGroupCat.of f.ker ⟶ A from u) _).1\n#align CommGroup.ker_eq_bot_of_mono CommGroupCat.ker_eq_bot_of_mono\n#align AddCommGroup.ker_eq_bot_of_mono AddCommGroupCat.ker_eq_bot_of_mono\n\n@[to_additive]\ntheorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=\n ⟨fun _ => ker_eq_bot_of_mono f, fun h =>\n ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩\n#align CommGroup.mono_iff_ker_eq_bot CommGroupCat.mono_iff_ker_eq_bot\n#align AddCommGroup.mono_iff_ker_eq_bot AddCommGroupCat.mono_iff_ker_eq_bot\n\n@[to_additive]\ntheorem mono_iff_injective : Mono f ↔ Function.Injective f :=\n Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f\n#align CommGroup.mono_iff_injective CommGroupCat.mono_iff_injective\n#align AddCommGroup.mono_iff_injective AddCommGroupCat.mono_iff_injective\n\n@[to_additive]\ntheorem range_eq_top_of_epi [Epi f] : f.range = ⊤ :=\n MonoidHom.range_eq_top_of_cancel fun u v h =>\n (@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ MonoidHom.range f, inferInstance⟩ from u) v).1 h\n#align CommGroup.range_eq_top_of_epi CommGroupCat.range_eq_top_of_epi\n#align AddCommGroup.range_eq_top_of_epi AddCommGroupCat.range_eq_top_of_epi\n\n-- Porting note: again lack of transparency\n@[to_additive]\ninstance (G : CommGroupCat) : CommGroup <| (forget CommGroupCat).obj G :=\n G.str\n\n@[to_additive]\ntheorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=\n ⟨fun _ => range_eq_top_of_epi _, fun hf =>\n ConcreteCategory.epi_of_surjective _ <| MonoidHom.range_top_iff_surjective.mp hf⟩\n#align CommGroup.epi_iff_range_eq_top CommGroupCat.epi_iff_range_eq_top\n#align AddCommGroup.epi_iff_range_eq_top AddCommGroupCat.epi_iff_range_eq_top\n\n@[to_additive]\ntheorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by\n rw [epi_iff_range_eq_top]\n rw [MonoidHom.range_top_iff_surjective]\n#align CommGroup.epi_iff_surjective CommGroupCat.epi_iff_surjective\n#align AddCommGroup.epi_iff_surjective AddCommGroupCat.epi_iff_surjective\n\n@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_mono]\ninstance forget_commGroupCat_preserves_mono : (forget CommGroupCat).PreservesMonomorphisms where\n preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e\n#align CommGroup.forget_CommGroup_preserves_mono CommGroupCat.forget_commGroupCat_preserves_mono\n#align AddCommGroup.forget_CommGroup_preserves_mono AddCommGroupCat.forget_commGroupCat_preserves_mono\n\n@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_epi]\ninstance forget_commGroupCat_preserves_epi : (forget CommGroupCat).PreservesEpimorphisms where\n preserves f e := by ","nextTactic":"rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e","declUpToTactic":"@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_epi]\ninstance forget_commGroupCat_preserves_epi : (forget CommGroupCat).PreservesEpimorphisms where\n preserves f e := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_Category_GroupCat_EpiMono.469_0.wDYTn9LgMD7bTAL","decl":"@[to_additive AddCommGroupCat.forget_commGroupCat_preserves_epi]\ninstance forget_commGroupCat_preserves_epi : (forget CommGroupCat).PreservesEpimorphisms where\n preserves f e "}