diff --git "a/data/lean/data.json" "b/data/lean/data.json" deleted file mode 100644--- "a/data/lean/data.json" +++ /dev/null @@ -1,100 +0,0 @@ -{"size":22413,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2017 Scott Morrison. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn\n-\/\nimport category_theory.fully_faithful\nimport category_theory.whiskering\nimport category_theory.essential_image\nimport tactic.slice\n\n\/-!\n# Equivalence of categories\n\nAn equivalence of categories `C` and `D` is a pair of functors `F : C \u2964 D` and `G : D \u2964 C` such\nthat `\u03b7 : \ud835\udfed C \u2245 F \u22d9 G` and `\u03b5 : G \u22d9 F \u2245 \ud835\udfed D`. In many situations, equivalences are a better\nnotion of \"sameness\" of categories than the stricter isomorphims of categories.\n\nRecall that one way to express that two functors `F : C \u2964 D` and `G : D \u2964 C` are adjoint is using\ntwo natural transformations `\u03b7 : \ud835\udfed C \u27f6 F \u22d9 G` and `\u03b5 : G \u22d9 F \u27f6 \ud835\udfed D`, called the unit and the\ncounit, such that the compositions `F \u27f6 FGF \u27f6 F` and `G \u27f6 GFG \u27f6 G` are the identity. Unfortunately,\nit is not the case that the natural isomorphisms `\u03b7` and `\u03b5` in the definition of an equivalence\nautomatically give an adjunction. However, it is true that\n* if one of the two compositions is the identity, then so is the other, and\n* given an equivalence of categories, it is always possible to refine `\u03b7` in such a way that the\n identities are satisfied.\n\nFor this reason, in mathlib we define an equivalence to be a \"half-adjoint equivalence\", which is\na tuple `(F, G, \u03b7, \u03b5)` as in the first paragraph such that the composite `F \u27f6 FGF \u27f6 F` is the\nidentity. By the remark above, this already implies that the tuple is an \"adjoint equivalence\",\ni.e., that the composite `G \u27f6 GFG \u27f6 G` is also the identity.\n\nWe also define essentially surjective functors and show that a functor is an equivalence if and only\nif it is full, faithful and essentially surjective.\n\n## Main definitions\n\n* `equivalence`: bundled (half-)adjoint equivalences of categories\n* `is_equivalence`: type class on a functor `F` containing the data of the inverse `G` as well as\n the natural isomorphisms `\u03b7` and `\u03b5`.\n* `ess_surj`: type class on a functor `F` containing the data of the preimages and the isomorphisms\n `F.obj (preimage d) \u2245 d`.\n\n## Main results\n\n* `equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence\n* `equivalence_of_fully_faithfully_ess_surj`: a fully faithful essentially surjective functor is an\n equivalence.\n\n## Notations\n\nWe write `C \u224c D` (`\\backcong`, not to be confused with `\u2245`\/`\\cong`) for a bundled equivalence.\n\n-\/\n\nnamespace category_theory\nopen category_theory.functor nat_iso category\n-- declare the `v`'s first; see `category_theory.category` for an explanation\nuniverses v\u2081 v\u2082 v\u2083 u\u2081 u\u2082 u\u2083\n\n\/-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with\n a unit and counit which are natural isomorphisms and the triangle law `F\u03b7 \u226b \u03b5F = 1`, or in other\n words the composite `F \u27f6 FGF \u27f6 F` is the identity.\n\n In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the\n composite `G \u27f6 GFG \u27f6 G` is also the identity.\n\n The triangle equation is written as a family of equalities between morphisms, it is more\n complicated if we write it as an equality of natural transformations, because then we would have\n to insert natural transformations like `F \u27f6 F1`.\n\nSee https:\/\/stacks.math.columbia.edu\/tag\/001J\n-\/\nstructure equivalence (C : Type u\u2081) [category.{v\u2081} C] (D : Type u\u2082) [category.{v\u2082} D] :=\nmk' ::\n(functor : C \u2964 D)\n(inverse : D \u2964 C)\n(unit_iso : \ud835\udfed C \u2245 functor \u22d9 inverse)\n(counit_iso : inverse \u22d9 functor \u2245 \ud835\udfed D)\n(functor_unit_iso_comp' : \u2200(X : C), functor.map ((unit_iso.hom : \ud835\udfed C \u27f6 functor \u22d9 inverse).app X) \u226b\n counit_iso.hom.app (functor.obj X) = \ud835\udfd9 (functor.obj X) . obviously)\n\nrestate_axiom equivalence.functor_unit_iso_comp'\n\ninfixr ` \u224c `:10 := equivalence\n\nvariables {C : Type u\u2081} [category.{v\u2081} C] {D : Type u\u2082} [category.{v\u2082} D]\n\nnamespace equivalence\n\n\/-- The unit of an equivalence of categories. -\/\nabbreviation unit (e : C \u224c D) : \ud835\udfed C \u27f6 e.functor \u22d9 e.inverse := e.unit_iso.hom\n\/-- The counit of an equivalence of categories. -\/\nabbreviation counit (e : C \u224c D) : e.inverse \u22d9 e.functor \u27f6 \ud835\udfed D := e.counit_iso.hom\n\/-- The inverse of the unit of an equivalence of categories. -\/\nabbreviation unit_inv (e : C \u224c D) : e.functor \u22d9 e.inverse \u27f6 \ud835\udfed C := e.unit_iso.inv\n\/-- The inverse of the counit of an equivalence of categories. -\/\nabbreviation counit_inv (e : C \u224c D) : \ud835\udfed D \u27f6 e.inverse \u22d9 e.functor := e.counit_iso.inv\n\n\/- While these abbreviations are convenient, they also cause some trouble,\npreventing structure projections from unfolding. -\/\n@[simp] lemma equivalence_mk'_unit (functor inverse unit_iso counit_iso f) :\n (\u27e8functor, inverse, unit_iso, counit_iso, f\u27e9 : C \u224c D).unit = unit_iso.hom := rfl\n@[simp] lemma equivalence_mk'_counit (functor inverse unit_iso counit_iso f) :\n (\u27e8functor, inverse, unit_iso, counit_iso, f\u27e9 : C \u224c D).counit = counit_iso.hom := rfl\n@[simp] lemma equivalence_mk'_unit_inv (functor inverse unit_iso counit_iso f) :\n (\u27e8functor, inverse, unit_iso, counit_iso, f\u27e9 : C \u224c D).unit_inv = unit_iso.inv := rfl\n@[simp] lemma equivalence_mk'_counit_inv (functor inverse unit_iso counit_iso f) :\n (\u27e8functor, inverse, unit_iso, counit_iso, f\u27e9 : C \u224c D).counit_inv = counit_iso.inv := rfl\n\n@[simp] lemma functor_unit_comp (e : C \u224c D) (X : C) :\n e.functor.map (e.unit.app X) \u226b e.counit.app (e.functor.obj X) = \ud835\udfd9 (e.functor.obj X) :=\ne.functor_unit_iso_comp X\n\n@[simp] lemma counit_inv_functor_comp (e : C \u224c D) (X : C) :\n e.counit_inv.app (e.functor.obj X) \u226b e.functor.map (e.unit_inv.app X) = \ud835\udfd9 (e.functor.obj X) :=\nbegin\n erw [iso.inv_eq_inv\n (e.functor.map_iso (e.unit_iso.app X) \u226a\u226b e.counit_iso.app (e.functor.obj X)) (iso.refl _)],\n exact e.functor_unit_comp X\nend\n\nlemma counit_inv_app_functor (e : C \u224c D) (X : C) :\n e.counit_inv.app (e.functor.obj X) = e.functor.map (e.unit.app X) :=\nby { symmetry, erw [\u2190iso.comp_hom_eq_id (e.counit_iso.app _), functor_unit_comp], refl }\n\nlemma counit_app_functor (e : C \u224c D) (X : C) :\n e.counit.app (e.functor.obj X) = e.functor.map (e.unit_inv.app X) :=\nby { erw [\u2190iso.hom_comp_eq_id (e.functor.map_iso (e.unit_iso.app X)), functor_unit_comp], refl }\n\n\/-- The other triangle equality. The proof follows the following proof in Globular:\n http:\/\/globular.science\/1905.001 -\/\n@[simp] lemma unit_inverse_comp (e : C \u224c D) (Y : D) :\n e.unit.app (e.inverse.obj Y) \u226b e.inverse.map (e.counit.app Y) = \ud835\udfd9 (e.inverse.obj Y) :=\nbegin\n rw [\u2190id_comp (e.inverse.map _), \u2190map_id e.inverse, \u2190counit_inv_functor_comp, map_comp,\n \u2190iso.hom_inv_id_assoc (e.unit_iso.app _) (e.inverse.map (e.functor.map _)),\n app_hom, app_inv],\n slice_lhs 2 3 { erw [e.unit.naturality] },\n slice_lhs 1 2 { erw [e.unit.naturality] },\n slice_lhs 4 4\n { rw [\u2190iso.hom_inv_id_assoc (e.inverse.map_iso (e.counit_iso.app _)) (e.unit_inv.app _)] },\n slice_lhs 3 4 { erw [\u2190map_comp e.inverse, e.counit.naturality],\n erw [(e.counit_iso.app _).hom_inv_id, map_id] }, erw [id_comp],\n slice_lhs 2 3 { erw [\u2190map_comp e.inverse, e.counit_iso.inv.naturality, map_comp] },\n slice_lhs 3 4 { erw [e.unit_inv.naturality] },\n slice_lhs 4 5 { erw [\u2190map_comp (e.functor \u22d9 e.inverse), (e.unit_iso.app _).hom_inv_id, map_id] },\n erw [id_comp],\n slice_lhs 3 4 { erw [\u2190e.unit_inv.naturality] },\n slice_lhs 2 3 { erw [\u2190map_comp e.inverse, \u2190e.counit_iso.inv.naturality,\n (e.counit_iso.app _).hom_inv_id, map_id] }, erw [id_comp, (e.unit_iso.app _).hom_inv_id], refl\nend\n\n@[simp] lemma inverse_counit_inv_comp (e : C \u224c D) (Y : D) :\n e.inverse.map (e.counit_inv.app Y) \u226b e.unit_inv.app (e.inverse.obj Y) = \ud835\udfd9 (e.inverse.obj Y) :=\nbegin\n erw [iso.inv_eq_inv\n (e.unit_iso.app (e.inverse.obj Y) \u226a\u226b e.inverse.map_iso (e.counit_iso.app Y)) (iso.refl _)],\n exact e.unit_inverse_comp Y\nend\n\nlemma unit_app_inverse (e : C \u224c D) (Y : D) :\n e.unit.app (e.inverse.obj Y) = e.inverse.map (e.counit_inv.app Y) :=\nby { erw [\u2190iso.comp_hom_eq_id (e.inverse.map_iso (e.counit_iso.app Y)), unit_inverse_comp], refl }\n\nlemma unit_inv_app_inverse (e : C \u224c D) (Y : D) :\n e.unit_inv.app (e.inverse.obj Y) = e.inverse.map (e.counit.app Y) :=\nby { symmetry, erw [\u2190iso.hom_comp_eq_id (e.unit_iso.app _), unit_inverse_comp], refl }\n\n@[simp] lemma fun_inv_map (e : C \u224c D) (X Y : D) (f : X \u27f6 Y) :\n e.functor.map (e.inverse.map f) = e.counit.app X \u226b f \u226b e.counit_inv.app Y :=\n(nat_iso.naturality_2 (e.counit_iso) f).symm\n\n@[simp] lemma inv_fun_map (e : C \u224c D) (X Y : C) (f : X \u27f6 Y) :\n e.inverse.map (e.functor.map f) = e.unit_inv.app X \u226b f \u226b e.unit.app Y :=\n(nat_iso.naturality_1 (e.unit_iso) f).symm\n\nsection\n-- In this section we convert an arbitrary equivalence to a half-adjoint equivalence.\nvariables {F : C \u2964 D} {G : D \u2964 C} (\u03b7 : \ud835\udfed C \u2245 F \u22d9 G) (\u03b5 : G \u22d9 F \u2245 \ud835\udfed D)\n\n\/-- If `\u03b7 : \ud835\udfed C \u2245 F \u22d9 G` is part of a (not necessarily half-adjoint) equivalence, we can upgrade it\nto a refined natural isomorphism `adjointify_\u03b7 \u03b7 : \ud835\udfed C \u2245 F \u22d9 G` which exhibits the properties\nrequired for a half-adjoint equivalence. See `equivalence.mk`. -\/\ndef adjointify_\u03b7 : \ud835\udfed C \u2245 F \u22d9 G :=\ncalc\n \ud835\udfed C \u2245 F \u22d9 G : \u03b7\n ... \u2245 F \u22d9 (\ud835\udfed D \u22d9 G) : iso_whisker_left F (left_unitor G).symm\n ... \u2245 F \u22d9 ((G \u22d9 F) \u22d9 G) : iso_whisker_left F (iso_whisker_right \u03b5.symm G)\n ... \u2245 F \u22d9 (G \u22d9 (F \u22d9 G)) : iso_whisker_left F (associator G F G)\n ... \u2245 (F \u22d9 G) \u22d9 (F \u22d9 G) : (associator F G (F \u22d9 G)).symm\n ... \u2245 \ud835\udfed C \u22d9 (F \u22d9 G) : iso_whisker_right \u03b7.symm (F \u22d9 G)\n ... \u2245 F \u22d9 G : left_unitor (F \u22d9 G)\n\nlemma adjointify_\u03b7_\u03b5 (X : C) :\n F.map ((adjointify_\u03b7 \u03b7 \u03b5).hom.app X) \u226b \u03b5.hom.app (F.obj X) = \ud835\udfd9 (F.obj X) :=\nbegin\n dsimp [adjointify_\u03b7], simp,\n have := \u03b5.hom.naturality (F.map (\u03b7.inv.app X)), dsimp at this, rw [this], clear this,\n rw [\u2190assoc _ _ (F.map _)],\n have := \u03b5.hom.naturality (\u03b5.inv.app $ F.obj X), dsimp at this, rw [this], clear this,\n have := (\u03b5.app $ F.obj X).hom_inv_id, dsimp at this, rw [this], clear this,\n rw [id_comp], have := (F.map_iso $ \u03b7.app X).hom_inv_id, dsimp at this, rw [this]\nend\n\nend\n\n\/-- Every equivalence of categories consisting of functors `F` and `G` such that `F \u22d9 G` and\n `G \u22d9 F` are naturally isomorphic to identity functors can be transformed into a half-adjoint\n equivalence without changing `F` or `G`. -\/\nprotected definition mk (F : C \u2964 D) (G : D \u2964 C)\n (\u03b7 : \ud835\udfed C \u2245 F \u22d9 G) (\u03b5 : G \u22d9 F \u2245 \ud835\udfed D) : C \u224c D :=\n\u27e8F, G, adjointify_\u03b7 \u03b7 \u03b5, \u03b5, adjointify_\u03b7_\u03b5 \u03b7 \u03b5\u27e9\n\n\/-- Equivalence of categories is reflexive. -\/\n@[refl, simps] def refl : C \u224c C :=\n\u27e8\ud835\udfed C, \ud835\udfed C, iso.refl _, iso.refl _, \u03bb X, category.id_comp _\u27e9\n\ninstance : inhabited (C \u224c C) :=\n\u27e8refl\u27e9\n\n\/-- Equivalence of categories is symmetric. -\/\n@[symm, simps] def symm (e : C \u224c D) : D \u224c C :=\n\u27e8e.inverse, e.functor, e.counit_iso.symm, e.unit_iso.symm, e.inverse_counit_inv_comp\u27e9\n\nvariables {E : Type u\u2083} [category.{v\u2083} E]\n\n\/-- Equivalence of categories is transitive. -\/\n@[trans, simps] def trans (e : C \u224c D) (f : D \u224c E) : C \u224c E :=\n{ functor := e.functor \u22d9 f.functor,\n inverse := f.inverse \u22d9 e.inverse,\n unit_iso :=\n begin\n refine iso.trans e.unit_iso _,\n exact iso_whisker_left e.functor (iso_whisker_right f.unit_iso e.inverse) ,\n end,\n counit_iso :=\n begin\n refine iso.trans _ f.counit_iso,\n exact iso_whisker_left f.inverse (iso_whisker_right e.counit_iso f.functor)\n end,\n -- We wouldn't have needed to give this proof if we'd used `equivalence.mk`,\n -- but we choose to avoid using that here, for the sake of good structure projection `simp`\n -- lemmas.\n functor_unit_iso_comp' := \u03bb X,\n begin\n dsimp,\n rw [\u2190 f.functor.map_comp_assoc, e.functor.map_comp, \u2190counit_inv_app_functor, fun_inv_map,\n iso.inv_hom_id_app_assoc, assoc, iso.inv_hom_id_app, counit_app_functor,\n \u2190 functor.map_comp],\n erw [comp_id, iso.hom_inv_id_app, functor.map_id],\n end }\n\n\/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic\nfunctor. -\/\ndef fun_inv_id_assoc (e : C \u224c D) (F : C \u2964 E) : e.functor \u22d9 e.inverse \u22d9 F \u2245 F :=\n(functor.associator _ _ _).symm \u226a\u226b iso_whisker_right e.unit_iso.symm F \u226a\u226b F.left_unitor\n\n@[simp] lemma fun_inv_id_assoc_hom_app (e : C \u224c D) (F : C \u2964 E) (X : C) :\n (fun_inv_id_assoc e F).hom.app X = F.map (e.unit_inv.app X) :=\nby { dsimp [fun_inv_id_assoc], tidy }\n\n@[simp] lemma fun_inv_id_assoc_inv_app (e : C \u224c D) (F : C \u2964 E) (X : C) :\n (fun_inv_id_assoc e F).inv.app X = F.map (e.unit.app X) :=\nby { dsimp [fun_inv_id_assoc], tidy }\n\n\/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic\nfunctor. -\/\ndef inv_fun_id_assoc (e : C \u224c D) (F : D \u2964 E) : e.inverse \u22d9 e.functor \u22d9 F \u2245 F :=\n(functor.associator _ _ _).symm \u226a\u226b iso_whisker_right e.counit_iso F \u226a\u226b F.left_unitor\n\n@[simp] lemma inv_fun_id_assoc_hom_app (e : C \u224c D) (F : D \u2964 E) (X : D) :\n (inv_fun_id_assoc e F).hom.app X = F.map (e.counit.app X) :=\nby { dsimp [inv_fun_id_assoc], tidy }\n\n@[simp] lemma inv_fun_id_assoc_inv_app (e : C \u224c D) (F : D \u2964 E) (X : D) :\n (inv_fun_id_assoc e F).inv.app X = F.map (e.counit_inv.app X) :=\nby { dsimp [inv_fun_id_assoc], tidy }\n\n\/-- If `C` is equivalent to `D`, then `C \u2964 E` is equivalent to `D \u2964 E`. -\/\n@[simps functor inverse unit_iso counit_iso]\ndef congr_left (e : C \u224c D) : (C \u2964 E) \u224c (D \u2964 E) :=\nequivalence.mk\n ((whiskering_left _ _ _).obj e.inverse)\n ((whiskering_left _ _ _).obj e.functor)\n (nat_iso.of_components (\u03bb F, (e.fun_inv_id_assoc F).symm) (by tidy))\n (nat_iso.of_components (\u03bb F, e.inv_fun_id_assoc F) (by tidy))\n\n\/-- If `C` is equivalent to `D`, then `E \u2964 C` is equivalent to `E \u2964 D`. -\/\n@[simps functor inverse unit_iso counit_iso]\ndef congr_right (e : C \u224c D) : (E \u2964 C) \u224c (E \u2964 D) :=\nequivalence.mk\n ((whiskering_right _ _ _).obj e.functor)\n ((whiskering_right _ _ _).obj e.inverse)\n (nat_iso.of_components\n (\u03bb F, F.right_unitor.symm \u226a\u226b iso_whisker_left F e.unit_iso \u226a\u226b functor.associator _ _ _)\n (by tidy))\n (nat_iso.of_components\n (\u03bb F, functor.associator _ _ _ \u226a\u226b iso_whisker_left F e.counit_iso \u226a\u226b F.right_unitor)\n (by tidy))\n\nsection cancellation_lemmas\nvariables (e : C \u224c D)\n\n\/- We need special forms of `cancel_nat_iso_hom_right(_assoc)` and\n`cancel_nat_iso_inv_right(_assoc)` for units and counits, because neither `simp` or `rw` will apply\nthose lemmas in this setting without providing `e.unit_iso` (or similar) as an explicit argument.\nWe also provide the lemmas for length four compositions, since they're occasionally useful.\n(e.g. in proving that equivalences take monos to monos) -\/\n\n@[simp] lemma cancel_unit_right {X Y : C}\n (f f' : X \u27f6 Y) :\n f \u226b e.unit.app Y = f' \u226b e.unit.app Y \u2194 f = f' :=\nby simp only [cancel_mono]\n\n@[simp] lemma cancel_unit_inv_right {X Y : C}\n (f f' : X \u27f6 e.inverse.obj (e.functor.obj Y)) :\n f \u226b e.unit_inv.app Y = f' \u226b e.unit_inv.app Y \u2194 f = f' :=\nby simp only [cancel_mono]\n\n@[simp] lemma cancel_counit_right {X Y : D}\n (f f' : X \u27f6 e.functor.obj (e.inverse.obj Y)) :\n f \u226b e.counit.app Y = f' \u226b e.counit.app Y \u2194 f = f' :=\nby simp only [cancel_mono]\n\n@[simp] lemma cancel_counit_inv_right {X Y : D}\n (f f' : X \u27f6 Y) :\n f \u226b e.counit_inv.app Y = f' \u226b e.counit_inv.app Y \u2194 f = f' :=\nby simp only [cancel_mono]\n\n@[simp] lemma cancel_unit_right_assoc {W X X' Y : C}\n (f : W \u27f6 X) (g : X \u27f6 Y) (f' : W \u27f6 X') (g' : X' \u27f6 Y) :\n f \u226b g \u226b e.unit.app Y = f' \u226b g' \u226b e.unit.app Y \u2194 f \u226b g = f' \u226b g' :=\nby simp only [\u2190category.assoc, cancel_mono]\n\n@[simp] lemma cancel_counit_inv_right_assoc {W X X' Y : D}\n (f : W \u27f6 X) (g : X \u27f6 Y) (f' : W \u27f6 X') (g' : X' \u27f6 Y) :\n f \u226b g \u226b e.counit_inv.app Y = f' \u226b g' \u226b e.counit_inv.app Y \u2194 f \u226b g = f' \u226b g' :=\nby simp only [\u2190category.assoc, cancel_mono]\n\n@[simp] lemma cancel_unit_right_assoc' {W X X' Y Y' Z : C}\n (f : W \u27f6 X) (g : X \u27f6 Y) (h : Y \u27f6 Z) (f' : W \u27f6 X') (g' : X' \u27f6 Y') (h' : Y' \u27f6 Z) :\n f \u226b g \u226b h \u226b e.unit.app Z = f' \u226b g' \u226b h' \u226b e.unit.app Z \u2194 f \u226b g \u226b h = f' \u226b g' \u226b h' :=\nby simp only [\u2190category.assoc, cancel_mono]\n\n@[simp] lemma cancel_counit_inv_right_assoc' {W X X' Y Y' Z : D}\n (f : W \u27f6 X) (g : X \u27f6 Y) (h : Y \u27f6 Z) (f' : W \u27f6 X') (g' : X' \u27f6 Y') (h' : Y' \u27f6 Z) :\n f \u226b g \u226b h \u226b e.counit_inv.app Z = f' \u226b g' \u226b h' \u226b e.counit_inv.app Z \u2194 f \u226b g \u226b h = f' \u226b g' \u226b h' :=\nby simp only [\u2190category.assoc, cancel_mono]\n\nend cancellation_lemmas\n\nsection\n\n-- There's of course a monoid structure on `C \u224c C`,\n-- but let's not encourage using it.\n-- The power structure is nevertheless useful.\n\n\/-- Powers of an auto-equivalence. -\/\ndef pow (e : C \u224c C) : \u2124 \u2192 (C \u224c C)\n| (int.of_nat 0) := equivalence.refl\n| (int.of_nat 1) := e\n| (int.of_nat (n+2)) := e.trans (pow (int.of_nat (n+1)))\n| (int.neg_succ_of_nat 0) := e.symm\n| (int.neg_succ_of_nat (n+1)) := e.symm.trans (pow (int.neg_succ_of_nat n))\n\ninstance : has_pow (C \u224c C) \u2124 := \u27e8pow\u27e9\n\n@[simp] lemma pow_zero (e : C \u224c C) : e^(0 : \u2124) = equivalence.refl := rfl\n@[simp] lemma pow_one (e : C \u224c C) : e^(1 : \u2124) = e := rfl\n@[simp] lemma pow_neg_one (e : C \u224c C) : e^(-1 : \u2124) = e.symm := rfl\n\n-- TODO as necessary, add the natural isomorphisms `(e^a).trans e^b \u2245 e^(a+b)`.\n-- At this point, we haven't even defined the category of equivalences.\n\nend\n\nend equivalence\n\n\n\/-- A functor that is part of a (half) adjoint equivalence -\/\nclass is_equivalence (F : C \u2964 D) :=\nmk' ::\n(inverse : D \u2964 C)\n(unit_iso : \ud835\udfed C \u2245 F \u22d9 inverse)\n(counit_iso : inverse \u22d9 F \u2245 \ud835\udfed D)\n(functor_unit_iso_comp' : \u2200 (X : C), F.map ((unit_iso.hom : \ud835\udfed C \u27f6 F \u22d9 inverse).app X) \u226b\n counit_iso.hom.app (F.obj X) = \ud835\udfd9 (F.obj X) . obviously)\n\nrestate_axiom is_equivalence.functor_unit_iso_comp'\n\nnamespace is_equivalence\n\ninstance of_equivalence (F : C \u224c D) : is_equivalence F.functor :=\n{ ..F }\n\ninstance of_equivalence_inverse (F : C \u224c D) : is_equivalence F.inverse :=\nis_equivalence.of_equivalence F.symm\n\nopen equivalence\n\/-- To see that a functor is an equivalence, it suffices to provide an inverse functor `G` such that\n `F \u22d9 G` and `G \u22d9 F` are naturally isomorphic to identity functors. -\/\nprotected definition mk {F : C \u2964 D} (G : D \u2964 C)\n (\u03b7 : \ud835\udfed C \u2245 F \u22d9 G) (\u03b5 : G \u22d9 F \u2245 \ud835\udfed D) : is_equivalence F :=\n\u27e8G, adjointify_\u03b7 \u03b7 \u03b5, \u03b5, adjointify_\u03b7_\u03b5 \u03b7 \u03b5\u27e9\n\nend is_equivalence\n\n\nnamespace functor\n\n\/-- Interpret a functor that is an equivalence as an equivalence. -\/\ndef as_equivalence (F : C \u2964 D) [is_equivalence F] : C \u224c D :=\n\u27e8F, is_equivalence.inverse F, is_equivalence.unit_iso, is_equivalence.counit_iso,\n is_equivalence.functor_unit_iso_comp\u27e9\n\ninstance is_equivalence_refl : is_equivalence (\ud835\udfed C) :=\nis_equivalence.of_equivalence equivalence.refl\n\n\/-- The inverse functor of a functor that is an equivalence. -\/\ndef inv (F : C \u2964 D) [is_equivalence F] : D \u2964 C :=\nis_equivalence.inverse F\n\ninstance is_equivalence_inv (F : C \u2964 D) [is_equivalence F] : is_equivalence F.inv :=\nis_equivalence.of_equivalence F.as_equivalence.symm\n\n@[simp] lemma as_equivalence_functor (F : C \u2964 D) [is_equivalence F] :\n F.as_equivalence.functor = F := rfl\n\n@[simp] lemma as_equivalence_inverse (F : C \u2964 D) [is_equivalence F] :\n F.as_equivalence.inverse = inv F := rfl\n\n@[simp] lemma inv_inv (F : C \u2964 D) [is_equivalence F] :\n inv (inv F) = F := rfl\n\nvariables {E : Type u\u2083} [category.{v\u2083} E]\n\ninstance is_equivalence_trans (F : C \u2964 D) (G : D \u2964 E) [is_equivalence F] [is_equivalence G] :\n is_equivalence (F \u22d9 G) :=\nis_equivalence.of_equivalence (equivalence.trans (as_equivalence F) (as_equivalence G))\n\nend functor\n\nnamespace equivalence\n\n@[simp]\nlemma functor_inv (E : C \u224c D) : E.functor.inv = E.inverse := rfl\n\n@[simp]\nlemma inverse_inv (E : C \u224c D) : E.inverse.inv = E.functor := rfl\n\n@[simp]\nlemma functor_as_equivalence (E : C \u224c D) : E.functor.as_equivalence = E :=\nby { cases E, congr, }\n\n@[simp]\nlemma inverse_as_equivalence (E : C \u224c D) : E.inverse.as_equivalence = E.symm :=\nby { cases E, congr, }\n\nend equivalence\n\nnamespace is_equivalence\n\n@[simp] lemma fun_inv_map (F : C \u2964 D) [is_equivalence F] (X Y : D) (f : X \u27f6 Y) :\n F.map (F.inv.map f) = F.as_equivalence.counit.app X \u226b f \u226b F.as_equivalence.counit_inv.app Y :=\nbegin\n erw [nat_iso.naturality_2],\n refl\nend\n@[simp] lemma inv_fun_map (F : C \u2964 D) [is_equivalence F] (X Y : C) (f : X \u27f6 Y) :\n F.inv.map (F.map f) = F.as_equivalence.unit_inv.app X \u226b f \u226b F.as_equivalence.unit.app Y :=\nbegin\n erw [nat_iso.naturality_1],\n refl\nend\n\nend is_equivalence\n\nnamespace equivalence\n\n\/--\nAn equivalence is essentially surjective.\n\nSee https:\/\/stacks.math.columbia.edu\/tag\/02C3.\n-\/\nlemma ess_surj_of_equivalence (F : C \u2964 D) [is_equivalence F] : ess_surj F :=\n\u27e8\u03bb Y, \u27e8F.inv.obj Y, \u27e8F.as_equivalence.counit_iso.app Y\u27e9\u27e9\u27e9\n\n\/--\nAn equivalence is faithful.\n\nSee https:\/\/stacks.math.columbia.edu\/tag\/02C3.\n-\/\n@[priority 100] -- see Note [lower instance priority]\ninstance faithful_of_equivalence (F : C \u2964 D) [is_equivalence F] : faithful F :=\n{ map_injective' := \u03bb X Y f g w,\n begin\n have p := congr_arg (@category_theory.functor.map _ _ _ _ F.inv _ _) w,\n simpa only [cancel_epi, cancel_mono, is_equivalence.inv_fun_map] using p\n end }.\n\n\/--\nAn equivalence is full.\n\nSee https:\/\/stacks.math.columbia.edu\/tag\/02C3.\n-\/\n@[priority 100] -- see Note [lower instance priority]\ninstance full_of_equivalence (F : C \u2964 D) [is_equivalence F] : full F :=\n{ preimage := \u03bb X Y f, F.as_equivalence.unit.app X \u226b F.inv.map f \u226b F.as_equivalence.unit_inv.app Y,\n witness' := \u03bb X Y f, F.inv.map_injective $\n by simpa only [is_equivalence.inv_fun_map, assoc, iso.inv_hom_id_app_assoc, iso.inv_hom_id_app]\n using comp_id _ }\n\n@[simps] private noncomputable def equivalence_inverse (F : C \u2964 D) [full F] [faithful F]\n [ess_surj F] : D \u2964 C :=\n{ obj := \u03bb X, F.obj_preimage X,\n map := \u03bb X Y f, F.preimage ((F.obj_obj_preimage_iso X).hom \u226b f \u226b (F.obj_obj_preimage_iso Y).inv),\n map_id' := \u03bb X, begin apply F.map_injective, tidy end,\n map_comp' := \u03bb X Y Z f g, by apply F.map_injective; simp }\n\n\/--\nA functor which is full, faithful, and essentially surjective is an equivalence.\n\nSee https:\/\/stacks.math.columbia.edu\/tag\/02C3.\n-\/\nnoncomputable def equivalence_of_fully_faithfully_ess_surj\n (F : C \u2964 D) [full F] [faithful F] [ess_surj F] : is_equivalence F :=\nis_equivalence.mk (equivalence_inverse F)\n (nat_iso.of_components\n (\u03bb X, (preimage_iso $ F.obj_obj_preimage_iso $ F.obj X).symm)\n (\u03bb X Y f, by { apply F.map_injective, obviously }))\n (nat_iso.of_components F.obj_obj_preimage_iso (by tidy))\n\n@[simp] lemma functor_map_inj_iff (e : C \u224c D) {X Y : C} (f g : X \u27f6 Y) :\n e.functor.map f = e.functor.map g \u2194 f = g :=\n\u27e8\u03bb h, e.functor.map_injective h, \u03bb h, h \u25b8 rfl\u27e9\n\n@[simp] lemma inverse_map_inj_iff (e : C \u224c D) {X Y : D} (f g : X \u27f6 Y) :\n e.inverse.map f = e.inverse.map g \u2194 f = g :=\nfunctor_map_inj_iff e.symm f g\n\nend equivalence\n\nend category_theory\n","avg_line_length":41.2003676471,"max_line_length":100,"alphanum_fraction":0.6695667693} -{"size":4392,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"def StateT (m : Type \u2192 Type) (\u03c3 : Type) (\u03b1 : Type) := (Unit \u00d7 \u03c3) \u2192 m (\u03b1 \u00d7 \u03c3)\nnamespace StateT\nvariables {m : Type \u2192 Type} [Monad m] {\u03c3 : Type} {\u03b1 \u03b2 : Type}\n@[inline] protected def pure (a : \u03b1) : StateT m \u03c3 \u03b1 := \u03bb \u27e8_, s\u27e9, pure (a, s)\n@[inline] protected def bind (x : StateT m \u03c3 \u03b1) (f : \u03b1 \u2192 StateT m \u03c3 \u03b2) : StateT m \u03c3 \u03b2 := \u03bb p, do (a, s') \u2190 x p, f a ((), s')\n@[inline] def read : StateT m \u03c3 \u03c3 := \u03bb \u27e8_, s\u27e9, pure (s, s)\n@[inline] def write (s' : \u03c3) : StateT m \u03c3 Unit := \u03bb \u27e8_, s\u27e9, pure ((), s')\n@[inline] def updt (f : \u03c3 \u2192 \u03c3) : StateT m \u03c3 Unit := \u03bb \u27e8_, s\u27e9, pure ((), f s)\ninstance : Monad (StateT m \u03c3) :=\n{pure := @StateT.pure _ _ _, bind := @StateT.bind _ _ _}\nend StateT\n\ndef ExceptT (m : Type \u2192 Type) (\u03b5 : Type) (\u03b1 : Type) := { e : Except \u03b5 Unit \/\/ e = Except.ok () } \u2192 m (Except \u03b5 \u03b1)\nnamespace ExceptT\nvariables {m : Type \u2192 Type} [Monad m] {\u03b5 : Type} {\u03b1 \u03b2 : Type}\n@[inline] protected def pure (a : \u03b1) : ExceptT m \u03b5 \u03b1 :=\n\u03bb e, match e with\n | \u27e8Except.ok _, h\u27e9 := pure (Except.ok a)\n | \u27e8Except.error _, h\u27e9 := Except.noConfusion h\n@[inline] protected def bind (x : ExceptT m \u03b5 \u03b1) (f : \u03b1 \u2192 ExceptT m \u03b5 \u03b2) : ExceptT m \u03b5 \u03b2 :=\n\u03bb e, do v \u2190 x e,\n match v with\n | Except.error e := pure (Except.error e)\n | Except.ok a := f a \u27e8Except.ok (), rfl\u27e9\n@[inline] def error (e : \u03b5) : ExceptT m \u03b5 \u03b1 :=\n\u03bb e', match e' with\n | \u27e8Except.ok _, h\u27e9 := pure (Except.error e)\n | \u27e8Except.error _, h\u27e9 := Except.noConfusion h\n@[inline] def lift (x : m \u03b1) : ExceptT m \u03b5 \u03b1 := \u03bb e, do {a \u2190 x, pure (Except.ok a)}\ninstance : Monad (ExceptT m \u03b5) :=\n{pure := @ExceptT.pure _ _ _, bind := @ExceptT.bind _ _ _}\nend ExceptT\n\nabbreviation Node := Nat\n\nstructure nodeData :=\n(find : Node) (rank : Nat := 0)\n\nabbreviation ufData := Array nodeData\n\nabbreviation M (\u03b1 : Type) := ExceptT (StateT id ufData) String \u03b1\n@[inline] def read : M ufData := ExceptT.lift StateT.read\n@[inline] def write (s : ufData) : M Unit := ExceptT.lift (StateT.write s)\n@[inline] def updt (f : ufData \u2192 ufData) : M Unit := ExceptT.lift (StateT.updt f)\n@[inline] def error {\u03b1 : Type} (e : String) : M \u03b1 := ExceptT.error e\ndef run {\u03b1 : Type} (x : M \u03b1) (s : ufData := Array.nil) : Except String \u03b1 \u00d7 ufData :=\nx \u27e8Except.ok (), rfl\u27e9 ((), s)\n\ndef capacity : M Nat :=\ndo d \u2190 read, pure d.size\n\ndef findEntryAux : Nat \u2192 Node \u2192 M nodeData\n| 0 n := error \"out of fuel\"\n| (i+1) n :=\n do s \u2190 read,\n if h : n < s.size then\n do { let e := s.read \u27e8n, h\u27e9,\n if e.find = n then pure e\n else do e\u2081 \u2190 findEntryAux i e.find,\n updt (\u03bb s, s.write' n e\u2081),\n pure e\u2081 }\n else error \"invalid Node\"\n\ndef findEntry (n : Node) : M nodeData :=\ndo c \u2190 capacity,\n findEntryAux c n\n\ndef find (n : Node) : M Node :=\ndo e \u2190 findEntry n, pure e.find\n\ndef mk : M Node :=\ndo n \u2190 capacity,\n updt $ \u03bb s, s.push {find := n, rank := 1},\n pure n\n\ndef union (n\u2081 n\u2082 : Node) : M Unit :=\ndo r\u2081 \u2190 findEntry n\u2081,\n r\u2082 \u2190 findEntry n\u2082,\n if r\u2081.find = r\u2082.find then pure ()\n else updt $ \u03bb s,\n if r\u2081.rank < r\u2082.rank then s.write' r\u2081.find { find := r\u2082.find }\n else if r\u2081.rank = r\u2082.rank then\n let s\u2081 := s.write' r\u2081.find { find := r\u2082.find } in\n s\u2081.write' r\u2082.find { rank := r\u2082.rank + 1, .. r\u2082}\n else s.write' r\u2082.find { find := r\u2081.find }\n\n\ndef mkNodes : Nat \u2192 M Unit\n| 0 := pure ()\n| (n+1) := mk *> mkNodes n\n\ndef checkEq (n\u2081 n\u2082 : Node) : M Unit :=\ndo r\u2081 \u2190 find n\u2081, r\u2082 \u2190 find n\u2082,\n unless (r\u2081 = r\u2082) $ error \"nodes are not equal\"\n\ndef mergePackAux : Nat \u2192 Nat \u2192 Nat \u2192 M Unit\n| 0 _ _ := pure ()\n| (i+1) n d :=\n do c \u2190 capacity,\n if (n+d) < c\n then union n (n+d) *> mergePackAux i (n+1) d\n else pure ()\n\ndef mergePack (d : Nat) : M Unit :=\ndo c \u2190 capacity, mergePackAux c 0 d\n\ndef numEqsAux : Nat \u2192 Node \u2192 Nat \u2192 M Nat\n| 0 _ r := pure r\n| (i+1) n r :=\n do c \u2190 capacity,\n if n < c\n then do { n\u2081 \u2190 find n, numEqsAux i (n+1) (if n = n\u2081 then r else r+1) }\n else pure r\n\ndef numEqs : M Nat :=\ndo c \u2190 capacity,\n numEqsAux c 0 0\n\ndef test (n : Nat) : M Nat :=\nif n < 2 then error \"input must be greater than 1\"\nelse do\n mkNodes n,\n mergePack 50000,\n mergePack 10000,\n mergePack 5000,\n mergePack 1000,\n numEqs\n\ndef main (xs : List String) : IO UInt32 :=\nlet n := xs.head.toNat in\nmatch run (test n) with\n| (Except.ok v, s) := IO.println (\"ok \" ++ toString v) *> pure 0\n| (Except.error e, s) := IO.println (\"Error : \" ++ e) *> pure 1\n","avg_line_length":32.776119403,"max_line_length":124,"alphanum_fraction":0.5626138434} -{"size":742,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"import Lake\nopen System Lake DSL\n\ndef cDir : FilePath := \"c\"\ndef ffiSrc := cDir \/ \"ffi.cpp\"\ndef buildDir := defaultBuildDir\n\ndef ffiOTarget (pkgDir : FilePath) : FileTarget :=\n let oFile := pkgDir \/ buildDir \/ cDir \/ \"ffi.o\"\n let srcTarget := inputFileTarget <| pkgDir \/ ffiSrc\n fileTargetWithDep oFile srcTarget fun srcFile => do\n compileO oFile srcFile #[\"-I\", (\u2190 getLeanIncludeDir).toString] \"c++\"\n\ndef cLibTarget (pkgDir : FilePath) : FileTarget :=\n let libFile := pkgDir \/ buildDir \/ cDir \/ \"libffi.a\"\n staticLibTarget libFile #[ffiOTarget pkgDir]\n\npackage ffi (pkgDir) (args) {\n -- customize layout\n srcDir := \"lib\"\n libRoots := #[`Ffi]\n -- specify the lib as an additional target\n moreLibTargets := #[cLibTarget pkgDir]\n}\n","avg_line_length":29.68,"max_line_length":72,"alphanum_fraction":0.6900269542} -{"size":1169,"ext":"lean","lang":"Lean","max_stars_count":134.0,"content":"import ddl.basic\n\nnamespace ddl.host\n\n \/- The type syntax of the host language -\/\n inductive type (\u2113 : Type) : Type\n | bool {} : type\n | nat {} : type\n | union_nil {} : type\n | union_cons : \u2113 \u2192 type \u2192 type \u2192 type\n | struct_nil {} : type\n | struct_cons : \u2113 \u2192 type \u2192 type \u2192 type\n | array {} : type \u2192 type\n\n namespace type\n\n variables {\u2113 : Type}\n\n def lookup (l : \u2113) [decidable_eq \u2113] : type \u2113 \u2192 option (type \u2113)\n | (struct_cons l' t tr) := if l = l' then some t else lookup tr\n | _ := none\n\n end type\n\n\n \/- Binary operators -\/\n inductive binop : Type\n | add\n | mul\n\n\n \/- The expression syntax of the host language -\/\n inductive expr (\u2113 : Type) : Type\n | bool {} : bool \u2192 expr\n | nat {} : \u2115 \u2192 expr\n | app_binop {} : binop \u2192 expr \u2192 expr \u2192 expr\n | proj : expr \u2192 \u2113 \u2192 expr\n\n instance has_coe_to_bool {\u2113} : has_coe bool (expr \u2113) := \u27e8expr.bool\u27e9\n instance has_coe_to_nat {\u2113} : has_coe \u2115 (expr \u2113) := \u27e8expr.nat\u27e9\n\n namespace expr\n\n variables {\u2113 : Type}\n\n instance : has_add (expr \u2113) := \u27e8app_binop binop.add\u27e9\n instance : has_mul (expr \u2113) := \u27e8app_binop binop.mul\u27e9\n\n end expr\n\nend ddl.host\n","avg_line_length":22.4807692308,"max_line_length":69,"alphanum_fraction":0.5714285714} -{"size":16206,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2021 Riccardo Brasca. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Riccardo Brasca\n-\/\n\nimport ring_theory.trace\nimport ring_theory.norm\nimport number_theory.number_field\n\n\/-!\n# Discriminant of a family of vectors\n\nGiven an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define the\n*discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of\n`b i * b j`.\n\n## Main definition\n\n* `algebra.discr A b` : the discriminant of `b : \u03b9 \u2192 B`.\n\n## Main results\n\n* `algebra.discr_zero_of_not_linear_independent` : if `b` is not linear independent, then\n `algebra.discr A b = 0`.\n* `algebra.discr_of_matrix_vec_mul` and `discr_of_matrix_mul_vec` : formulas relating\n `algebra.discr A \u03b9 b` with `algebra.discr A ((P.map (algebra_map A B)).vec_mul b)` and\n `algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`.\n* `algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then\n `algebra.discr K b \u2260 0`.\n* `algebra.discr_eq_det_embeddings_matrix_reindex_pow_two` : if `L\/K` is a field extension and\n `b : \u03b9 \u2192 L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)`\n coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the embedding in an algebraically closed\n field `E` corresponding to `j : \u03b9` via a bijection `e : \u03b9 \u2243 (L \u2192\u2090[K] E)`.\n* `algebra.discr_of_power_basis_eq_prod` : the discriminant of a power basis.\n* `discr_is_integral` : if `K` and `L` are fields and `is_scalar_tower R K L`, is `b : \u03b9 \u2192 L`\n satisfies ` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`.\n* `discr_mul_is_integral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain\n `R` and let `L` be a finite separable extension of `K`. Let `B : power_basis K L` be such that\n `is_integral R B.gen`. Then for all, `z : L` we have\n `(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`.\n\n## Implementation details\n\nOur definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module,\nthen `trace A B = 0` by definition, so `discr A b = 0` for any `b`.\n-\/\n\nuniverses u v w z\n\nopen_locale matrix big_operators\n\nopen matrix finite_dimensional fintype polynomial finset intermediate_field\n\nnamespace algebra\n\nvariables (A : Type u) {B : Type v} (C : Type z) {\u03b9 : Type w}\nvariables [comm_ring A] [comm_ring B] [algebra A B] [comm_ring C] [algebra A C]\n\nsection discr\n\n\/-- Given an `A`-algebra `B` and `b`, an `\u03b9`-indexed family of elements of `B`, we define\n`discr A \u03b9 b` as the determinant of `trace_matrix A \u03b9 b`. -\/\nnoncomputable\ndef discr (A : Type u) {B : Type v} [comm_ring A] [comm_ring B] [algebra A B] [fintype \u03b9]\n (b : \u03b9 \u2192 B) := by { classical, exact (trace_matrix A b).det }\n\nlemma discr_def [decidable_eq \u03b9] [fintype \u03b9] (b : \u03b9 \u2192 B) :\n discr A b = (trace_matrix A b).det := by convert rfl\n\nvariables {\u03b9' : Type*} [fintype \u03b9'] [fintype \u03b9]\n\nsection basic\n\n@[simp] lemma discr_reindex (b : basis \u03b9 A B) (f : \u03b9 \u2243 \u03b9') :\n discr A (b \u2218 \u21d1(f.symm)) = discr A b :=\nbegin\n classical,\n rw [\u2190 basis.coe_reindex, discr_def, trace_matrix_reindex, det_reindex_self, \u2190 discr_def]\nend\n\n\/-- If `b` is not linear independent, then `algebra.discr A b = 0`. -\/\nlemma discr_zero_of_not_linear_independent [is_domain A] {b : \u03b9 \u2192 B}\n (hli : \u00aclinear_independent A b) : discr A b = 0 :=\nbegin\n classical,\n obtain \u27e8g, hg, i, hi\u27e9 := fintype.not_linear_independent_iff.1 hli,\n have : (trace_matrix A b).mul_vec g = 0,\n { ext i,\n have : \u2200 j, (trace A B) (b i * b j) * g j = (trace A B) (((g j) \u2022 (b j)) * b i),\n { intro j, simp [mul_comm], },\n simp only [mul_vec, dot_product, trace_matrix, pi.zero_apply, trace_form_apply,\n \u03bb j, this j, \u2190 linear_map.map_sum, \u2190 sum_mul, hg, zero_mul, linear_map.map_zero] },\n by_contra h,\n rw discr_def at h,\n simpa [matrix.eq_zero_of_mul_vec_eq_zero h this] using hi,\nend\n\nvariable {A}\n\n\/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).vec_mul b)`. -\/\nlemma discr_of_matrix_vec_mul [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n discr A ((P.map (algebra_map A B)).vec_mul b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_vec_mul, det_mul, det_mul, det_transpose, mul_comm,\n \u2190 mul_assoc, discr_def, pow_two]\n\n\/-- Relation between `algebra.discr A \u03b9 b` and\n`algebra.discr A ((P.map (algebra_map A B)).mul_vec b)`. -\/\nlemma discr_of_matrix_mul_vec [decidable_eq \u03b9] (b : \u03b9 \u2192 B) (P : matrix \u03b9 \u03b9 A) :\n discr A ((P.map (algebra_map A B)).mul_vec b) = P.det ^ 2 * discr A b :=\nby rw [discr_def, trace_matrix_of_matrix_mul_vec, det_mul, det_mul, det_transpose,\n mul_comm, \u2190 mul_assoc, discr_def, pow_two]\n\nend basic\n\nsection field\n\nvariables (K : Type u) {L : Type v} (E : Type z) [field K] [field L] [field E]\nvariables [algebra K L] [algebra K E]\nvariables [module.finite K L] [is_alg_closed E]\n\n\/-- Over a field, if `b` is a basis, then `algebra.discr K b \u2260 0`. -\/\nlemma discr_not_zero_of_basis [is_separable K L] (b : basis \u03b9 K L) : discr K b \u2260 0 :=\nbegin\n by_cases h : nonempty \u03b9,\n { classical,\n have := span_eq_top_of_linear_independent_of_card_eq_finrank b.linear_independent\n (finrank_eq_card_basis b).symm,\n rw [discr_def, trace_matrix_def],\n simp_rw [\u2190 basis.mk_apply b.linear_independent this],\n rw [\u2190 trace_matrix_def, trace_matrix_of_basis, \u2190 bilin_form.nondegenerate_iff_det_ne_zero],\n exact trace_form_nondegenerate _ _ },\n letI := not_nonempty_iff.1 h,\n simp [discr],\nend\n\n\/-- Over a field, if `b` is a basis, then `algebra.discr K b` is a unit. -\/\nlemma discr_is_unit_of_basis [is_separable K L] (b : basis \u03b9 K L) : is_unit (discr K b) :=\nis_unit.mk0 _ (discr_not_zero_of_basis _ _)\n\nvariables (b : \u03b9 \u2192 L) (pb : power_basis K L)\n\n\/-- If `L\/K` is a field extension and `b : \u03b9 \u2192 L`, then `discr K b` is the square of the\ndeterminant of the matrix whose `(i, j)` coefficient is `\u03c3\u2c7c (b i)`, where `\u03c3\u2c7c : L \u2192\u2090[K] E` is the\nembedding in an algebraically closed field `E` corresponding to `j : \u03b9` via a bijection\n`e : \u03b9 \u2243 (L \u2192\u2090[K] E)`. -\/\nlemma discr_eq_det_embeddings_matrix_reindex_pow_two [decidable_eq \u03b9] [is_separable K L]\n (e : \u03b9 \u2243 (L \u2192\u2090[K] E)) : algebra_map K E (discr K b) =\n (embeddings_matrix_reindex K E b e).det ^ 2 :=\nby rw [discr_def, ring_hom.map_det, ring_hom.map_matrix_apply,\n trace_matrix_eq_embeddings_matrix_reindex_mul_trans, det_mul, det_transpose, pow_two]\n\n\/-- The discriminant of a power basis. -\/\nlemma discr_power_basis_eq_prod (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) [is_separable K L] :\n algebra_map K E (discr K pb.basis) =\n \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j), (e j pb.gen- (e i pb.gen)) ^ 2 :=\nbegin\n rw [discr_eq_det_embeddings_matrix_reindex_pow_two K E pb.basis e,\n embeddings_matrix_reindex_eq_vandermonde, det_transpose, det_vandermonde, \u2190 prod_pow],\n congr, ext i,\n rw [\u2190 prod_pow]\nend\n\n\/-- A variation of `of_power_basis_eq_prod`. -\/\nlemma discr_power_basis_eq_prod' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n algebra_map K E (discr K pb.basis) =\n \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j),\n -((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))) :=\nbegin\n rw [discr_power_basis_eq_prod _ _ _ e],\n congr, ext i, congr, ext j,\n ring\nend\n\nlocal notation `n` := finrank K L\n\n\/-- A variation of `of_power_basis_eq_prod`. -\/\nlemma discr_power_basis_eq_prod'' [is_separable K L] (e : fin pb.dim \u2243 (L \u2192\u2090[K] E)) :\n algebra_map K E (discr K pb.basis) =\n (-1) ^ (n * (n - 1) \/ 2) * \u220f i : fin pb.dim, \u220f j in finset.univ.filter (\u03bb j, i < j),\n ((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))) :=\nbegin\n rw [discr_power_basis_eq_prod' _ _ _ e],\n simp_rw [\u03bb i j, neg_eq_neg_one_mul ((e j pb.gen- (e i pb.gen)) * (e i pb.gen- (e j pb.gen))),\n prod_mul_distrib],\n congr,\n simp only [prod_pow_eq_pow_sum, prod_const],\n congr,\n simp_rw [fin.card_filter_lt],\n apply (@nat.cast_inj \u211a _ _ _ _ _).1,\n rw [nat.cast_sum],\n have : \u2200 (x : fin pb.dim), (\u2191x + 1) \u2264 pb.dim := by simp [nat.succ_le_iff, fin.is_lt],\n simp_rw [nat.sub_sub],\n simp only [nat.cast_sub, this, finset.card_fin, nsmul_eq_mul, sum_const, sum_sub_distrib,\n nat.cast_add, nat.cast_one, sum_add_distrib, mul_one],\n rw [\u2190 nat.cast_sum, \u2190 @finset.sum_range \u2115 _ pb.dim (\u03bb i, i), sum_range_id ],\n have hn : n = pb.dim,\n { rw [\u2190 alg_hom.card K L E, \u2190 fintype.card_fin pb.dim],\n exact card_congr (equiv.symm e) },\n have h\u2082 : 2 \u2223 (pb.dim * (pb.dim - 1)) := even_iff_two_dvd.1 (nat.even_mul_self_pred _),\n have hne : ((2 : \u2115) : \u211a) \u2260 0 := by simp,\n have hle : 1 \u2264 pb.dim,\n { rw [\u2190 hn, nat.one_le_iff_ne_zero, \u2190 zero_lt_iff, finite_dimensional.finrank_pos_iff],\n apply_instance },\n rw [hn, nat.cast_div h\u2082 hne, nat.cast_mul, nat.cast_sub hle],\n field_simp,\n ring,\nend\n\n\/-- Formula for the discriminant of a power basis using the norm of the field extension. -\/\nlemma discr_power_basis_eq_norm [is_separable K L] : discr K pb.basis =\n (-1) ^ (n * (n - 1) \/ 2) * (norm K (aeval pb.gen (minpoly K pb.gen).derivative)) :=\nbegin\n let E := algebraic_closure L,\n letI := \u03bb (a b : E), classical.prop_decidable (eq a b),\n\n have e : fin pb.dim \u2243 (L \u2192\u2090[K] E),\n { refine equiv_of_card_eq _,\n rw [fintype.card_fin, alg_hom.card],\n exact (power_basis.finrank pb).symm },\n have hnodup : (map (algebra_map K E) (minpoly K pb.gen)).roots.nodup :=\n nodup_roots (separable.map (is_separable.separable K pb.gen)),\n have hroots : \u2200 \u03c3 : L \u2192\u2090[K] E, \u03c3 pb.gen \u2208 (map (algebra_map K E) (minpoly K pb.gen)).roots,\n { intro \u03c3,\n rw [mem_roots, is_root.def, eval_map, \u2190 aeval_def, aeval_alg_hom_apply],\n repeat { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n\n apply (algebra_map K E).injective,\n rw [ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_neg, ring_hom.map_one,\n discr_power_basis_eq_prod'' _ _ _ e],\n congr,\n rw [norm_eq_prod_embeddings, fin.prod_filter_lt_mul_neg_eq_prod_off_diag],\n conv_rhs { congr, skip, funext,\n rw [\u2190 aeval_alg_hom_apply, aeval_root_derivative_of_splits (minpoly.monic\n (is_separable.is_integral K pb.gen)) (is_alg_closed.splits_codomain _) (hroots \u03c3),\n \u2190 finset.prod_mk _ (hnodup.erase _)] },\n rw [prod_sigma', prod_sigma'],\n refine prod_bij (\u03bb i hi, \u27e8e i.2, e i.1 pb.gen\u27e9) (\u03bb i hi, _) (\u03bb i hi, by simp at hi)\n (\u03bb i j hi hj hij, _) (\u03bb \u03c3 h\u03c3, _),\n { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma],\n rw [multiset.mem_erase_of_ne (\u03bb h, _)],\n { exact hroots _ },\n { simp only [true_and, mem_filter, mem_univ, ne.def, mem_sigma] at hi,\n refine hi (equiv.injective e (equiv.injective (power_basis.lift_equiv pb) _)),\n rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n exact subtype.eq h } },\n { simp only [equiv.apply_eq_iff_eq, heq_iff_eq] at hij,\n have h := hij.2,\n rw [\u2190 power_basis.lift_equiv_apply_coe, \u2190 power_basis.lift_equiv_apply_coe] at h,\n refine sigma.eq (equiv.injective e (equiv.injective _ (subtype.eq h))) (by simp [hij.1]) },\n { simp only [true_and, finset.mem_mk, mem_univ, mem_sigma] at h\u03c3,\n simp only [sigma.exists, true_and, exists_prop, mem_filter, mem_univ, ne.def, mem_sigma],\n refine \u27e8e.symm (power_basis.lift pb \u03c3.2 _), e.symm \u03c3.1, \u27e8\u03bb h, _, sigma.eq _ _\u27e9\u27e9,\n { rw [aeval_def, eval\u2082_eq_eval_map, \u2190 is_root.def, \u2190 mem_roots],\n { exact multiset.erase_subset _ _ h\u03c3 },\n { simp [minpoly.ne_zero (is_separable.is_integral K pb.gen)] } },\n { replace h := alg_hom.congr_fun (equiv.injective _ h) pb.gen,\n rw [power_basis.lift_gen] at h,\n rw [\u2190 h] at h\u03c3,\n exact hnodup.not_mem_erase h\u03c3 },\n all_goals { simp } }\nend\n\nsection integral\n\nvariables {R : Type z} [comm_ring R] [algebra R K] [algebra R L] [is_scalar_tower R K L]\n\nlocal notation `is_integral` := _root_.is_integral\n\n\/-- If `K` and `L` are fields and `is_scalar_tower R K L`, and `b : \u03b9 \u2192 L` satisfies\n` \u2200 i, is_integral R (b i)`, then `is_integral R (discr K b)`. -\/\nlemma discr_is_integral {b : \u03b9 \u2192 L} (h : \u2200 i, is_integral R (b i)) :\n is_integral R (discr K b) :=\nbegin\n classical,\n rw [discr_def],\n exact is_integral.det (\u03bb i j, is_integral_trace (is_integral_mul (h i) (h j)))\nend\n\n\/-- If `b` and `b'` are `\u211a`-bases of a number field `K` such that\n`\u2200 i j, is_integral \u2124 (b.to_matrix b' i j)` and `\u2200 i j, is_integral \u2124 (b'.to_matrix b i j)` then\n`discr \u211a b = discr \u211a b'`. -\/\nlemma discr_eq_discr_of_to_matrix_coeff_is_integral [number_field K] {b : basis \u03b9 \u211a K}\n {b' : basis \u03b9' \u211a K} (h : \u2200 i j, is_integral \u2124 (b.to_matrix b' i j))\n (h' : \u2200 i j, is_integral \u2124 (b'.to_matrix b i j)) :\n discr \u211a b = discr \u211a b' :=\nbegin\n replace h' : \u2200 i j, is_integral \u2124 (b'.to_matrix ((b.reindex (b.index_equiv b'))) i j),\n { intros i j,\n convert h' i ((b.index_equiv b').symm j),\n simpa },\n classical,\n rw [\u2190 (b.reindex (b.index_equiv b')).to_matrix_map_vec_mul b', discr_of_matrix_vec_mul,\n \u2190 one_mul (discr \u211a b), basis.coe_reindex, discr_reindex],\n congr,\n have hint : is_integral \u2124 (((b.reindex (b.index_equiv b')).to_matrix b').det) :=\n is_integral.det (\u03bb i j, h _ _),\n obtain \u27e8r, hr\u27e9 := is_integrally_closed.is_integral_iff.1 hint,\n have hunit : is_unit r,\n { have : is_integral \u2124 ((b'.to_matrix (b.reindex (b.index_equiv b'))).det) :=\n is_integral.det (\u03bb i j, h' _ _),\n obtain \u27e8r', hr'\u27e9 := is_integrally_closed.is_integral_iff.1 this,\n refine is_unit_iff_exists_inv.2 \u27e8r', _\u27e9,\n suffices : algebra_map \u2124 \u211a (r * r') = 1,\n { rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a)] at this,\n exact (is_fraction_ring.injective \u2124 \u211a) this },\n rw [ring_hom.map_mul, hr, hr', \u2190 det_mul, basis.to_matrix_mul_to_matrix_flip, det_one] },\n rw [\u2190 ring_hom.map_one (algebra_map \u2124 \u211a), \u2190 hr],\n cases int.is_unit_iff.1 hunit with hp hm,\n { simp [hp] },\n { simp [hm] }\nend\n\n\/-- Let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite\nseparable extension of `K`. Let `B : power_basis K L` be such that `is_integral R B.gen`.\nThen for all, `z : L` that are integral over `R`, we have\n`(discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L)`. -\/\nlemma discr_mul_is_integral_mem_adjoin [is_domain R] [is_separable K L] [is_integrally_closed R]\n [is_fraction_ring R K] {B : power_basis K L} (hint : is_integral R B.gen) {z : L}\n (hz : is_integral R z) : (discr K B.basis) \u2022 z \u2208 adjoin R ({B.gen} : set L) :=\nbegin\n have hinv : is_unit (trace_matrix K B.basis).det :=\n by simpa [\u2190 discr_def] using discr_is_unit_of_basis _ B.basis,\n\n have H : (trace_matrix K B.basis).det \u2022 (trace_matrix K B.basis).mul_vec (B.basis.equiv_fun z) =\n (trace_matrix K B.basis).det \u2022 (\u03bb i, trace K L (z * B.basis i)),\n { congr, exact trace_matrix_of_basis_mul_vec _ _ },\n have cramer := mul_vec_cramer (trace_matrix K B.basis) (\u03bb i, trace K L (z * B.basis i)),\n\n suffices : \u2200 i, ((trace_matrix K B.basis).det \u2022 (B.basis.equiv_fun z)) i \u2208 (\u22a5 : subalgebra R K),\n { rw [\u2190 B.basis.sum_repr z, finset.smul_sum],\n refine subalgebra.sum_mem _ (\u03bb i hi, _),\n replace this := this i,\n rw [\u2190 discr_def, pi.smul_apply, mem_bot] at this,\n obtain \u27e8r, hr\u27e9 := this,\n rw [basis.equiv_fun_apply] at hr,\n rw [\u2190 smul_assoc, \u2190 hr, algebra_map_smul],\n refine subalgebra.smul_mem _ _ _,\n rw [B.basis_eq_pow i],\n refine subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton _)) _},\n intro i,\n rw [\u2190 H, \u2190 mul_vec_smul] at cramer,\n replace cramer := congr_arg (mul_vec (trace_matrix K B.basis)\u207b\u00b9) cramer,\n rw [mul_vec_mul_vec, nonsing_inv_mul _ hinv, mul_vec_mul_vec, nonsing_inv_mul _ hinv,\n one_mul_vec, one_mul_vec] at cramer,\n rw [\u2190 congr_fun cramer i, cramer_apply, det_apply],\n refine subalgebra.sum_mem _ (\u03bb \u03c3 _, subalgebra.zsmul_mem _ (subalgebra.prod_mem _ (\u03bb j _, _)) _),\n by_cases hji : j = i,\n { simp only [update_column_apply, hji, eq_self_iff_true, power_basis.coe_basis],\n exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace $\n is_integral_mul hz $ is_integral.pow hint _) },\n { simp only [update_column_apply, hji, power_basis.coe_basis],\n exact mem_bot.2 (is_integrally_closed.is_integral_iff.1 $ is_integral_trace\n $ is_integral_mul (is_integral.pow hint _) (is_integral.pow hint _)) }\nend\n\nend integral\n\nend field\n\nend discr\n\nend algebra\n","avg_line_length":44.4,"max_line_length":99,"alphanum_fraction":0.6743181538} -{"size":37789,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2020 Yury G. Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Yury G. Kudryashov\n-\/\nimport analysis.specific_limits\nimport order.iterate\nimport order.semiconj_Sup\nimport algebra.iterate_hom\n\n\/-!\n# Translation number of a monotone real map that commutes with `x \u21a6 x + 1`\n\nLet `f : \u211d \u2192 \u211d` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit\n$$\n \\tau(f)=\\lim_{n\\to\\infty}{f^n(x)-x}{n}\n$$\nexists and does not depend on `x`. This number is called the *translation number* of `f`.\nDifferent authors use different notation for this number: `\u03c4`, `\u03c1`, `rot`, etc\n\nIn this file we define a structure `circle_deg1_lift` for bundled maps with these properties, define\ntranslation number of `f : circle_deg1_lift`, prove some estimates relating `f^n(x)-x` to `\u03c4(f)`. In\ncase of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and\nonly if `\u03c4(f)=m\/n`.\n\nMaps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More\nprecisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=\u211d\/\u2124$, and\nconsider a real number `a` such that\n`\u27e6a\u27e7 = f 0`, where `\u27e6\u27e7` means the natural projection `\u211d \u2192 \u211d\/\u2124`. Then there exists a unique\ncontinuous function `F : \u211d \u2192 \u211d` such that `F 0 = a` and `\u27e6F x\u27e7 = f \u27e6x\u27e7` for all `x` (this fact is\nnot formalized yet). This function is strictly monotone, continuous, and satisfies\n`F (x + 1) = F x + 1`. The number `\u27e6\u03c4 F\u27e7 : \u211d \/ \u2124` is called the *rotation number* of `f`.\nIt does not depend on the choice of `a`.\n\n## Main definitions\n\n* `circle_deg1_lift`: a monotone map `f : \u211d \u2192 \u211d` such that `f (x + 1) = f x + 1` for all `x`;\n the type `circle_deg1_lift` is equipped with `lattice` and `monoid` structures; the\n multiplication is given by composition: `(f * g) x = f (g x)`.\n* `circle_deg1_lift.translation_number`: translation number of `f : circle_deg1_lift`.\n\n## Main statements\n\nWe prove the following properties of `circle_deg1_lift.translation_number`.\n\n* `circle_deg1_lift.translation_number_eq_of_dist_bounded`: if the distance between `(f^n) 0`\n and `(g^n) 0` is bounded from above uniformly in `n : \u2115`, then `f` and `g` have equal\n translation numbers.\n\n* `circle_deg1_lift.translation_number_eq_of_semiconj_by`: if two `circle_deg1_lift` maps `f`, `g`\n are semiconjugate by a `circle_deg1_lift` map, then `\u03c4 f = \u03c4 g`.\n\n* `circle_deg1_lift.translation_number_units_inv`: if `f` is an invertible `circle_deg1_lift` map\n (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then\n the translation number of `f\u207b\u00b9` is the negative of the translation number of `f`.\n\n* `circle_deg1_lift.translation_number_mul_of_commute`: if `f` and `g` commute, then\n `\u03c4 (f * g) = \u03c4 f + \u03c4 g`.\n\n* `circle_deg1_lift.translation_number_eq_rat_iff`: the translation number of `f` is equal to\n a rational number `m \/ n` if and only if `(f^n) x = x + m` for some `x`.\n\n* `circle_deg1_lift.semiconj_of_bijective_of_translation_number_eq`: if `f` and `g` are two\n bijective `circle_deg1_lift` maps and their translation numbers are equal, then these\n maps are semiconjugate to each other.\n\n* `circle_deg1_lift.semiconj_of_group_action_of_forall_translation_number_eq`: let `f\u2081` and `f\u2082` be\n two actions of a group `G` on the circle by degree 1 maps (formally, `f\u2081` and `f\u2082` are two\n homomorphisms from `G \u2192* circle_deg1_lift`). If the translation numbers of `f\u2081 g` and `f\u2082 g` are\n equal to each other for all `g : G`, then these two actions are semiconjugate by some `F :\n circle_deg1_lift`. This is a version of Proposition 5.4 from [\u00c9tienne Ghys, Groupes\n d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes].\n\n## Notation\n\nWe use a local notation `\u03c4` for the translation number of `f : circle_deg1_lift`.\n\n## Implementation notes\n\nWe define the translation number of `f : circle_deg1_lift` to be the limit of the sequence\n`(f ^ (2 ^ n)) 0 \/ (2 ^ n)`, then prove that `((f ^ n) x - x) \/ n` tends to this number for any `x`.\nThis way it is much easier to prove that the limit exists and basic properties of the limit.\n\nWe define translation number for a wider class of maps `f : \u211d \u2192 \u211d` instead of lifts of orientation\npreserving circle homeomorphisms for two reasons:\n\n* non-strictly monotone circle self-maps with discontinuities naturally appear as Poincar\u00e9 maps\n for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry\n cells);\n* definition and some basic properties still work for this class.\n\n## References\n\n* [\u00c9tienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]\n\n## TODO\n\nHere are some short-term goals.\n\n* Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `units\n circle_deg1_lift` for now, but it's better to have a dedicated type (or a typeclass?).\n\n* Prove that the `semiconj_by` relation on circle homeomorphisms is an equivalence relation.\n\n* Introduce `conditionally_complete_lattice` structure, use it in the proof of\n `circle_deg1_lift.semiconj_of_group_action_of_forall_translation_number_eq`.\n\n* Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a\n homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational\n translation by a continuous `circle_deg1_lift`.\n\n## Tags\n\ncircle homeomorphism, rotation number\n-\/\n\nopen filter set function (hiding commute)\nopen_locale topological_space classical\n\n\/-!\n### Definition and monoid structure\n-\/\n\n\/-- A lift of a monotone degree one map `S\u00b9 \u2192 S\u00b9`. -\/\nstructure circle_deg1_lift : Type :=\n(to_fun : \u211d \u2192 \u211d)\n(monotone' : monotone to_fun)\n(map_add_one' : \u2200 x, to_fun (x + 1) = to_fun x + 1)\n\nnamespace circle_deg1_lift\n\ninstance : has_coe_to_fun circle_deg1_lift := \u27e8\u03bb _, \u211d \u2192 \u211d, circle_deg1_lift.to_fun\u27e9\n\n@[simp] lemma coe_mk (f h\u2081 h\u2082) : \u21d1(mk f h\u2081 h\u2082) = f := rfl\n\nvariables (f g : circle_deg1_lift)\n\nprotected lemma monotone : monotone f := f.monotone'\n\n@[mono] lemma mono {x y} (h : x \u2264 y) : f x \u2264 f y := f.monotone h\n\nlemma strict_mono_iff_injective : strict_mono f \u2194 injective f :=\nf.monotone.strict_mono_iff_injective\n\n@[simp] lemma map_add_one : \u2200 x, f (x + 1) = f x + 1 := f.map_add_one'\n\n@[simp] lemma map_one_add (x : \u211d) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm]\n\ntheorem coe_inj : \u2200 \u2983f g : circle_deg1_lift \u2984, (f : \u211d \u2192 \u211d) = g \u2192 f = g :=\nassume \u27e8f, fm, fd\u27e9 \u27e8g, gm, gd\u27e9 h, by congr; exact h\n\n@[ext] theorem ext \u2983f g : circle_deg1_lift \u2984 (h : \u2200 x, f x = g x) : f = g :=\ncoe_inj $ funext h\n\ntheorem ext_iff {f g : circle_deg1_lift} : f = g \u2194 \u2200 x, f x = g x :=\n\u27e8\u03bb h x, h \u25b8 rfl, \u03bb h, ext h\u27e9\n\ninstance : monoid circle_deg1_lift :=\n{ mul := \u03bb f g,\n { to_fun := f \u2218 g,\n monotone' := f.monotone.comp g.monotone,\n map_add_one' := \u03bb x, by simp [map_add_one] },\n one := \u27e8id, monotone_id, \u03bb _, rfl\u27e9,\n mul_one := \u03bb f, coe_inj $ function.comp.right_id f,\n one_mul := \u03bb f, coe_inj $ function.comp.left_id f,\n mul_assoc := \u03bb f\u2081 f\u2082 f\u2083, coe_inj rfl }\n\ninstance : inhabited circle_deg1_lift := \u27e81\u27e9\n\n@[simp] lemma coe_mul : \u21d1(f * g) = f \u2218 g := rfl\n\nlemma mul_apply (x) : (f * g) x = f (g x) := rfl\n\n@[simp] lemma coe_one : \u21d1(1 : circle_deg1_lift) = id := rfl\n\ninstance units_has_coe_to_fun : has_coe_to_fun (units circle_deg1_lift) :=\n\u27e8\u03bb _, \u211d \u2192 \u211d, \u03bb f, \u21d1(f : circle_deg1_lift)\u27e9\n\n@[simp, norm_cast] lemma units_coe (f : units circle_deg1_lift) : \u21d1(f : circle_deg1_lift) = f := rfl\n\n@[simp] lemma units_inv_apply_apply (f : units circle_deg1_lift) (x : \u211d) :\n (f\u207b\u00b9 : units circle_deg1_lift) (f x) = x :=\nby simp only [\u2190 units_coe, \u2190 mul_apply, f.inv_mul, coe_one, id]\n\n@[simp] lemma units_apply_inv_apply (f : units circle_deg1_lift) (x : \u211d) :\n f ((f\u207b\u00b9 : units circle_deg1_lift) x) = x :=\nby simp only [\u2190 units_coe, \u2190 mul_apply, f.mul_inv, coe_one, id]\n\n\/-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -\/\ndef to_order_iso : units circle_deg1_lift \u2192* \u211d \u2243o \u211d :=\n{ to_fun := \u03bb f,\n { to_fun := f,\n inv_fun := \u21d1(f\u207b\u00b9),\n left_inv := units_inv_apply_apply f,\n right_inv := units_apply_inv_apply f,\n map_rel_iff' := \u03bb x y, \u27e8\u03bb h, by simpa using mono \u2191(f\u207b\u00b9) h, mono f\u27e9 },\n map_one' := rfl,\n map_mul' := \u03bb f g, rfl }\n\n@[simp] lemma coe_to_order_iso (f : units circle_deg1_lift) : \u21d1(to_order_iso f) = f := rfl\n\n@[simp] lemma coe_to_order_iso_symm (f : units circle_deg1_lift) :\n \u21d1(to_order_iso f).symm = (f\u207b\u00b9 : units circle_deg1_lift) := rfl\n\n@[simp] lemma coe_to_order_iso_inv (f : units circle_deg1_lift) :\n \u21d1(to_order_iso f)\u207b\u00b9 = (f\u207b\u00b9 : units circle_deg1_lift) := rfl\n\nlemma is_unit_iff_bijective {f : circle_deg1_lift} : is_unit f \u2194 bijective f :=\n\u27e8\u03bb \u27e8u, h\u27e9, h \u25b8 (to_order_iso u).bijective, \u03bb h, is_unit_unit\n { val := f,\n inv := { to_fun := (equiv.of_bijective f h).symm,\n monotone' := \u03bb x y hxy, (f.strict_mono_iff_injective.2 h.1).le_iff_le.1\n (by simp only [equiv.of_bijective_apply_symm_apply f h, hxy]),\n map_add_one' := \u03bb x, h.1 $\n by simp only [equiv.of_bijective_apply_symm_apply f, f.map_add_one] },\n val_inv := ext $ equiv.of_bijective_apply_symm_apply f h,\n inv_val := ext $ equiv.of_bijective_symm_apply_apply f h }\u27e9\n\nlemma coe_pow : \u2200 n : \u2115, \u21d1(f^n) = (f^[n])\n| 0 := rfl\n| (n+1) := by {ext x, simp [coe_pow n, pow_succ'] }\n\nlemma semiconj_by_iff_semiconj {f g\u2081 g\u2082 : circle_deg1_lift} :\n semiconj_by f g\u2081 g\u2082 \u2194 semiconj f g\u2081 g\u2082 :=\next_iff\n\nlemma commute_iff_commute {f g : circle_deg1_lift} :\n commute f g \u2194 function.commute f g :=\next_iff\n\n\/-!\n### Translate by a constant\n-\/\n\n\/-- The map `y \u21a6 x + y` as a `circle_deg1_lift`. More precisely, we define a homomorphism from\n`multiplicative \u211d` to `units circle_deg1_lift`, so the translation by `x` is\n`translation (multiplicative.of_add x)`. -\/\ndef translate : multiplicative \u211d \u2192* units circle_deg1_lift :=\nby refine (units.map _).comp to_units.to_monoid_hom; exact\n{ to_fun := \u03bb x, \u27e8\u03bb y, x.to_add + y, \u03bb y\u2081 y\u2082 h, add_le_add_left h _, \u03bb y, (add_assoc _ _ _).symm\u27e9,\n map_one' := ext $ zero_add,\n map_mul' := \u03bb x y, ext $ add_assoc _ _ }\n\n@[simp] lemma translate_apply (x y : \u211d) : translate (multiplicative.of_add x) y = x + y := rfl\n\n@[simp]\nlemma translate_inv_apply (x y : \u211d) : (translate $ multiplicative.of_add x)\u207b\u00b9 y = -x + y := rfl\n\n@[simp] lemma translate_gpow (x : \u211d) (n : \u2124) :\n (translate (multiplicative.of_add x))^n = translate (multiplicative.of_add $ \u2191n * x) :=\nby simp only [\u2190 gsmul_eq_mul, of_add_gsmul, monoid_hom.map_gpow]\n\n@[simp] lemma translate_pow (x : \u211d) (n : \u2115) :\n (translate (multiplicative.of_add x))^n = translate (multiplicative.of_add $ \u2191n * x) :=\ntranslate_gpow x n\n\n@[simp] lemma translate_iterate (x : \u211d) (n : \u2115) :\n (translate (multiplicative.of_add x))^[n] = translate (multiplicative.of_add $ \u2191n * x) :=\nby rw [\u2190 units_coe, \u2190 coe_pow, \u2190 units.coe_pow, translate_pow, units_coe]\n\n\/-!\n### Commutativity with integer translations\n\nIn this section we prove that `f` commutes with translations by an integer number.\nFirst we formulate these statements (for a natural or an integer number,\naddition on the left or on the right, addition or subtraction) using `function.commute`,\nthen reformulate as `simp` lemmas `map_int_add` etc.\n-\/\n\nlemma commute_nat_add (n : \u2115) : function.commute f ((+) n) :=\nby simpa only [nsmul_one, add_left_iterate] using function.commute.iterate_right f.map_one_add n\n\nlemma commute_add_nat (n : \u2115) : function.commute f (\u03bb x, x + n) :=\nby simp only [add_comm _ (n:\u211d), f.commute_nat_add n]\n\nlemma commute_sub_nat (n : \u2115) : function.commute f (\u03bb x, x - n) :=\nby simpa only [sub_eq_add_neg] using\n (f.commute_add_nat n).inverses_right (equiv.add_right _).right_inv (equiv.add_right _).left_inv\n\nlemma commute_add_int : \u2200 n : \u2124, function.commute f (\u03bb x, x + n)\n| (n:\u2115) := f.commute_add_nat n\n| -[1+n] := by simpa only [sub_eq_add_neg] using f.commute_sub_nat (n + 1)\n\nlemma commute_int_add (n : \u2124) : function.commute f ((+) n) :=\nby simpa only [add_comm _ (n:\u211d)] using f.commute_add_int n\n\nlemma commute_sub_int (n : \u2124) : function.commute f (\u03bb x, x - n) :=\nby simpa only [sub_eq_add_neg] using\n (f.commute_add_int n).inverses_right (equiv.add_right _).right_inv (equiv.add_right _).left_inv\n\n@[simp] lemma map_int_add (m : \u2124) (x : \u211d) : f (m + x) = m + f x :=\nf.commute_int_add m x\n\n@[simp] lemma map_add_int (x : \u211d) (m : \u2124) : f (x + m) = f x + m :=\nf.commute_add_int m x\n\n@[simp] lemma map_sub_int (x : \u211d) (n : \u2124) : f (x - n) = f x - n :=\nf.commute_sub_int n x\n\n@[simp] lemma map_add_nat (x : \u211d) (n : \u2115) : f (x + n) = f x + n :=\nf.map_add_int x n\n\n@[simp] lemma map_nat_add (n : \u2115) (x : \u211d) : f (n + x) = n + f x :=\nf.map_int_add n x\n\n@[simp] lemma map_sub_nat (x : \u211d) (n : \u2115) : f (x - n) = f x - n :=\nf.map_sub_int x n\n\nlemma map_int_of_map_zero (n : \u2124) : f n = f 0 + n :=\nby rw [\u2190 f.map_add_int, zero_add]\n\n@[simp] lemma map_fract_sub_fract_eq (x : \u211d) :\n f (fract x) - fract x = f x - x :=\nby conv_rhs { rw [\u2190 fract_add_floor x, f.map_add_int, add_sub_comm, sub_self, add_zero] }\n\n\/-!\n### Pointwise order on circle maps\n-\/\n\n\/-- Monotone circle maps form a lattice with respect to the pointwise order -\/\nnoncomputable instance : lattice circle_deg1_lift :=\n{ sup := \u03bb f g,\n { to_fun := \u03bb x, max (f x) (g x),\n monotone' := \u03bb x y h, max_le_max (f.mono h) (g.mono h), -- TODO: generalize to `monotone.max`\n map_add_one' := \u03bb x, by simp [max_add_add_right] },\n le := \u03bb f g, \u2200 x, f x \u2264 g x,\n le_refl := \u03bb f x, le_refl (f x),\n le_trans := \u03bb f\u2081 f\u2082 f\u2083 h\u2081\u2082 h\u2082\u2083 x, le_trans (h\u2081\u2082 x) (h\u2082\u2083 x),\n le_antisymm := \u03bb f\u2081 f\u2082 h\u2081\u2082 h\u2082\u2081, ext $ \u03bb x, le_antisymm (h\u2081\u2082 x) (h\u2082\u2081 x),\n le_sup_left := \u03bb f g x, le_max_left (f x) (g x),\n le_sup_right := \u03bb f g x, le_max_right (f x) (g x),\n sup_le := \u03bb f\u2081 f\u2082 f\u2083 h\u2081 h\u2082 x, max_le (h\u2081 x) (h\u2082 x),\n inf := \u03bb f g,\n { to_fun := \u03bb x, min (f x) (g x),\n monotone' := \u03bb x y h, min_le_min (f.mono h) (g.mono h),\n map_add_one' := \u03bb x, by simp [min_add_add_right] },\n inf_le_left := \u03bb f g x, min_le_left (f x) (g x),\n inf_le_right := \u03bb f g x, min_le_right (f x) (g x),\n le_inf := \u03bb f\u2081 f\u2082 f\u2083 h\u2082 h\u2083 x, le_min (h\u2082 x) (h\u2083 x) }\n\n@[simp] lemma sup_apply (x : \u211d) : (f \u2294 g) x = max (f x) (g x) := rfl\n\n@[simp] lemma inf_apply (x : \u211d) : (f \u2293 g) x = min (f x) (g x) := rfl\n\nlemma iterate_monotone (n : \u2115) : monotone (\u03bb f : circle_deg1_lift, f^[n]) :=\n\u03bb f g h, f.monotone.iterate_le_of_le h _\n\nlemma iterate_mono {f g : circle_deg1_lift} (h : f \u2264 g) (n : \u2115) : f^[n] \u2264 (g^[n]) :=\niterate_monotone n h\n\nlemma pow_mono {f g : circle_deg1_lift} (h : f \u2264 g) (n : \u2115) : f^n \u2264 g^n :=\n\u03bb x, by simp only [coe_pow, iterate_mono h n x]\n\nlemma pow_monotone (n : \u2115) : monotone (\u03bb f : circle_deg1_lift, f^n) :=\n\u03bb f g h, pow_mono h n\n\n\/-!\n### Estimates on `(f * g) 0`\n\nWe prove the estimates `f 0 + \u230ag 0\u230b \u2264 f (g 0) \u2264 f 0 + \u2308g 0\u2309` and some corollaries with added\/removed\nfloors and ceils.\n\nWe also prove that for two semiconjugate maps `g\u2081`, `g\u2082`, the distance between `g\u2081 0` and `g\u2082 0`\nis less than two.\n-\/\n\nlemma map_le_of_map_zero (x : \u211d) : f x \u2264 f 0 + \u2308x\u2309 :=\ncalc f x \u2264 f \u2308x\u2309 : f.monotone $ le_ceil _\n ... = f 0 + \u2308x\u2309 : f.map_int_of_map_zero _\n\nlemma map_map_zero_le : f (g 0) \u2264 f 0 + \u2308g 0\u2309 := f.map_le_of_map_zero (g 0)\n\nlemma floor_map_map_zero_le : \u230af (g 0)\u230b \u2264 \u230af 0\u230b + \u2308g 0\u2309 :=\ncalc \u230af (g 0)\u230b \u2264 \u230af 0 + \u2308g 0\u2309\u230b : floor_mono $ f.map_map_zero_le g\n ... = \u230af 0\u230b + \u2308g 0\u2309 : floor_add_int _ _\n\nlemma ceil_map_map_zero_le : \u2308f (g 0)\u2309 \u2264 \u2308f 0\u2309 + \u2308g 0\u2309 :=\ncalc \u2308f (g 0)\u2309 \u2264 \u2308f 0 + \u2308g 0\u2309\u2309 : ceil_mono $ f.map_map_zero_le g\n ... = \u2308f 0\u2309 + \u2308g 0\u2309 : ceil_add_int _ _\n\nlemma map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 :=\ncalc f (g 0) \u2264 f 0 + \u2308g 0\u2309 : f.map_map_zero_le g\n ... < f 0 + (g 0 + 1) : add_lt_add_left (ceil_lt_add_one _) _\n ... = f 0 + g 0 + 1 : (add_assoc _ _ _).symm\n\nlemma le_map_of_map_zero (x : \u211d) : f 0 + \u230ax\u230b \u2264 f x :=\ncalc f 0 + \u230ax\u230b = f \u230ax\u230b : (f.map_int_of_map_zero _).symm\n ... \u2264 f x : f.monotone $ floor_le _\n\nlemma le_map_map_zero : f 0 + \u230ag 0\u230b \u2264 f (g 0) := f.le_map_of_map_zero (g 0)\n\nlemma le_floor_map_map_zero : \u230af 0\u230b + \u230ag 0\u230b \u2264 \u230af (g 0)\u230b :=\ncalc \u230af 0\u230b + \u230ag 0\u230b = \u230af 0 + \u230ag 0\u230b\u230b : (floor_add_int _ _).symm\n ... \u2264 \u230af (g 0)\u230b : floor_mono $ f.le_map_map_zero g\n\nlemma le_ceil_map_map_zero : \u2308f 0\u2309 + \u230ag 0\u230b \u2264 \u2308(f * g) 0\u2309 :=\ncalc \u2308f 0\u2309 + \u230ag 0\u230b = \u2308f 0 + \u230ag 0\u230b\u2309 : (ceil_add_int _ _).symm\n ... \u2264 \u2308f (g 0)\u2309 : ceil_mono $ f.le_map_map_zero g\n\nlemma lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) :=\ncalc f 0 + g 0 - 1 = f 0 + (g 0 - 1) : add_sub_assoc _ _ _\n ... < f 0 + \u230ag 0\u230b : add_lt_add_left (sub_one_lt_floor _) _\n ... \u2264 f (g 0) : f.le_map_map_zero g\n\nlemma dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 :=\nbegin\n rw [dist_comm, real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', \u2190 sub_eq_add_neg],\n exact \u27e8f.lt_map_map_zero g, f.map_map_zero_lt g\u27e9\nend\n\nlemma dist_map_zero_lt_of_semiconj {f g\u2081 g\u2082 : circle_deg1_lift} (h : function.semiconj f g\u2081 g\u2082) :\n dist (g\u2081 0) (g\u2082 0) < 2 :=\ncalc dist (g\u2081 0) (g\u2082 0) \u2264 dist (g\u2081 0) (f (g\u2081 0) - f 0) + dist _ (g\u2082 0) : dist_triangle _ _ _\n... = dist (f 0 + g\u2081 0) (f (g\u2081 0)) + dist (g\u2082 0 + f 0) (g\u2082 (f 0)) :\n by simp only [h.eq, real.dist_eq, sub_sub, add_comm (f 0), sub_sub_assoc_swap, abs_sub (g\u2082 (f 0))]\n... < 2 : add_lt_add (f.dist_map_map_zero_lt g\u2081) (g\u2082.dist_map_map_zero_lt f)\n\nlemma dist_map_zero_lt_of_semiconj_by {f g\u2081 g\u2082 : circle_deg1_lift} (h : semiconj_by f g\u2081 g\u2082) :\n dist (g\u2081 0) (g\u2082 0) < 2 :=\ndist_map_zero_lt_of_semiconj $ semiconj_by_iff_semiconj.1 h\n\n\/-!\n### Limits at infinities and continuity\n-\/\n\nprotected lemma tendsto_at_bot : tendsto f at_bot at_bot :=\ntendsto_at_bot_mono f.map_le_of_map_zero $ tendsto_at_bot_add_const_left _ _ $\n tendsto_at_bot_mono (\u03bb x, (ceil_lt_add_one x).le) $ tendsto_at_bot_add_const_right _ _ tendsto_id\n\nprotected lemma tendsto_at_top : tendsto f at_top at_top :=\ntendsto_at_top_mono f.le_map_of_map_zero $ tendsto_at_top_add_const_left _ _ $\n tendsto_at_top_mono (\u03bb x, (sub_one_lt_floor x).le) $\n by simpa [sub_eq_add_neg] using tendsto_at_top_add_const_right _ _ tendsto_id\n\nlemma continuous_iff_surjective : continuous f \u2194 function.surjective f :=\n\u27e8\u03bb h, h.surjective f.tendsto_at_top f.tendsto_at_bot, f.monotone.continuous_of_surjective\u27e9\n\n\/-!\n### Estimates on `(f^n) x`\n\nIf we know that `f x` is `\u2264`\/`<`\/`\u2265`\/`>`\/`=` to `x + m`, then we have a similar estimate on\n`f^[n] x` and `x + n * m`.\n\nFor `\u2264`, `\u2265`, and `=` we formulate both `of` (implication) and `iff` versions because implications\nwork for `n = 0`. For `<` and `>` we formulate only `iff` versions.\n-\/\n\nlemma iterate_le_of_map_le_add_int {x : \u211d} {m : \u2124} (h : f x \u2264 x + m) (n : \u2115) :\n f^[n] x \u2264 x + n * m :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const m) h n\n\nlemma le_iterate_of_add_int_le_map {x : \u211d} {m : \u2124} (h : x + m \u2264 f x) (n : \u2115) :\n x + n * m \u2264 (f^[n]) x :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const m) f.monotone h n\n\nlemma iterate_eq_of_map_eq_add_int {x : \u211d} {m : \u2124} (h : f x = x + m) (n : \u2115) :\n f^[n] x = x + n * m :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).iterate_eq_of_map_eq n h\n\nlemma iterate_pos_le_iff {x : \u211d} {m : \u2124} {n : \u2115} (hn : 0 < n) :\n f^[n] x \u2264 x + n * m \u2194 f x \u2264 x + m :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strict_mono_id.add_const m) hn\n\nlemma iterate_pos_lt_iff {x : \u211d} {m : \u2124} {n : \u2115} (hn : 0 < n) :\n f^[n] x < x + n * m \u2194 f x < x + m :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strict_mono_id.add_const m) hn\n\nlemma iterate_pos_eq_iff {x : \u211d} {m : \u2124} {n : \u2115} (hn : 0 < n) :\n f^[n] x = x + n * m \u2194 f x = x + m :=\nby simpa only [nsmul_eq_mul, add_right_iterate]\nusing (f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strict_mono_id.add_const m) hn\n\nlemma le_iterate_pos_iff {x : \u211d} {m : \u2124} {n : \u2115} (hn : 0 < n) :\n x + n * m \u2264 (f^[n]) x \u2194 x + m \u2264 f x :=\nby simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn)\n\nlemma lt_iterate_pos_iff {x : \u211d} {m : \u2124} {n : \u2115} (hn : 0 < n) :\n x + n * m < (f^[n]) x \u2194 x + m < f x :=\nby simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn)\n\nlemma mul_floor_map_zero_le_floor_iterate_zero (n : \u2115) : \u2191n * \u230af 0\u230b \u2264 \u230a(f^[n] 0)\u230b :=\nbegin\n rw [le_floor, int.cast_mul, int.cast_coe_nat, \u2190 zero_add ((n : \u211d) * _)],\n apply le_iterate_of_add_int_le_map,\n simp [floor_le]\nend\n\n\/-!\n### Definition of translation number\n-\/\nnoncomputable theory\n\n\/-- An auxiliary sequence used to define the translation number. -\/\ndef transnum_aux_seq (n : \u2115) : \u211d := (f^(2^n)) 0 \/ 2^n\n\n\/-- The translation number of a `circle_deg1_lift`, $\u03c4(f)=\\lim_{n\u2192\u221e}\\frac{f^n(x)-x}{n}$. We use\nan auxiliary sequence `\\frac{f^{2^n}(0)}{2^n}` to define `\u03c4(f)` because some proofs are simpler\nthis way. -\/\ndef translation_number : \u211d :=\nlim at_top f.transnum_aux_seq\n\n-- TODO: choose two different symbols for `circle_deg1_lift.translation_number` and the future\n-- `circle_mono_homeo.rotation_number`, then make them `localized notation`s\nlocal notation `\u03c4` := translation_number\n\nlemma transnum_aux_seq_def : f.transnum_aux_seq = \u03bb n : \u2115, (f^(2^n)) 0 \/ 2^n := rfl\n\nlemma translation_number_eq_of_tendsto_aux {\u03c4' : \u211d}\n (h : tendsto f.transnum_aux_seq at_top (\ud835\udcdd \u03c4')) :\n \u03c4 f = \u03c4' :=\nh.lim_eq\n\nlemma translation_number_eq_of_tendsto\u2080 {\u03c4' : \u211d}\n (h : tendsto (\u03bb n:\u2115, f^[n] 0 \/ n) at_top (\ud835\udcdd \u03c4')) :\n \u03c4 f = \u03c4' :=\nf.translation_number_eq_of_tendsto_aux $\nby simpa [(\u2218), transnum_aux_seq_def, coe_pow]\nusing h.comp (nat.tendsto_pow_at_top_at_top_of_one_lt one_lt_two)\n\nlemma translation_number_eq_of_tendsto\u2080' {\u03c4' : \u211d}\n (h : tendsto (\u03bb n:\u2115, f^[n + 1] 0 \/ (n + 1)) at_top (\ud835\udcdd \u03c4')) :\n \u03c4 f = \u03c4' :=\nf.translation_number_eq_of_tendsto\u2080 $ (tendsto_add_at_top_iff_nat 1).1 h\n\nlemma transnum_aux_seq_zero : f.transnum_aux_seq 0 = f 0 := by simp [transnum_aux_seq]\n\nlemma transnum_aux_seq_dist_lt (n : \u2115) :\n dist (f.transnum_aux_seq n) (f.transnum_aux_seq (n+1)) < (1 \/ 2) \/ (2^n) :=\nbegin\n have : 0 < (2^(n+1):\u211d) := pow_pos zero_lt_two _,\n rw [div_div_eq_div_mul, \u2190 pow_succ, \u2190 abs_of_pos this],\n replace := abs_pos.2 (ne_of_gt this),\n convert (div_lt_div_right this).2 ((f^(2^n)).dist_map_map_zero_lt (f^(2^n))),\n simp_rw [transnum_aux_seq, real.dist_eq],\n rw [\u2190 abs_div, sub_div, pow_succ', pow_succ, \u2190 two_mul,\n mul_div_mul_left _ _ (@two_ne_zero \u211d _ _),\n pow_mul, pow_two, mul_apply]\nend\n\nlemma tendsto_translation_number_aux : tendsto f.transnum_aux_seq at_top (\ud835\udcdd $ \u03c4 f) :=\n(cauchy_seq_of_le_geometric_two 1 (\u03bb n, le_of_lt $ f.transnum_aux_seq_dist_lt n)).tendsto_lim\n\nlemma dist_map_zero_translation_number_le : dist (f 0) (\u03c4 f) \u2264 1 :=\nf.transnum_aux_seq_zero \u25b8 dist_le_of_le_geometric_two_of_tendsto\u2080 1\n (\u03bb n, le_of_lt $ f.transnum_aux_seq_dist_lt n) f.tendsto_translation_number_aux\n\nlemma tendsto_translation_number_of_dist_bounded_aux (x : \u2115 \u2192 \u211d) (C : \u211d)\n (H : \u2200 n : \u2115, dist ((f^n) 0) (x n) \u2264 C) :\n tendsto (\u03bb n : \u2115, x (2^n) \/ (2^n)) at_top (\ud835\udcdd $ \u03c4 f) :=\nbegin\n refine f.tendsto_translation_number_aux.congr_dist (squeeze_zero (\u03bb _, dist_nonneg) _ _),\n { exact \u03bb n, C \/ 2^n },\n { intro n,\n have : 0 < (2^n:\u211d) := pow_pos zero_lt_two _,\n convert (div_le_div_right this).2 (H (2^n)),\n rw [transnum_aux_seq, real.dist_eq, \u2190 sub_div, abs_div, abs_of_pos this, real.dist_eq] },\n { exact mul_zero C \u25b8 tendsto_const_nhds.mul (tendsto_inv_at_top_zero.comp $\n tendsto_pow_at_top_at_top_of_one_lt one_lt_two) }\nend\n\nlemma translation_number_eq_of_dist_bounded {f g : circle_deg1_lift} (C : \u211d)\n (H : \u2200 n : \u2115, dist ((f^n) 0) ((g^n) 0) \u2264 C) :\n \u03c4 f = \u03c4 g :=\neq.symm $ g.translation_number_eq_of_tendsto_aux $\n f.tendsto_translation_number_of_dist_bounded_aux _ C H\n\n@[simp] lemma translation_number_one : \u03c4 1 = 0 :=\ntranslation_number_eq_of_tendsto\u2080 _ $ by simp [tendsto_const_nhds]\n\nlemma translation_number_eq_of_semiconj_by {f g\u2081 g\u2082 : circle_deg1_lift} (H : semiconj_by f g\u2081 g\u2082) :\n \u03c4 g\u2081 = \u03c4 g\u2082 :=\ntranslation_number_eq_of_dist_bounded 2 $ \u03bb n, le_of_lt $\n dist_map_zero_lt_of_semiconj_by $ H.pow_right n\n\nlemma translation_number_eq_of_semiconj {f g\u2081 g\u2082 : circle_deg1_lift}\n (H : function.semiconj f g\u2081 g\u2082) :\n \u03c4 g\u2081 = \u03c4 g\u2082 :=\ntranslation_number_eq_of_semiconj_by $ semiconj_by_iff_semiconj.2 H\n\nlemma translation_number_mul_of_commute {f g : circle_deg1_lift} (h : commute f g) :\n \u03c4 (f * g) = \u03c4 f + \u03c4 g :=\nbegin\n have : tendsto (\u03bb n : \u2115, ((\u03bb k, (f^k) 0 + (g^k) 0) (2^n)) \/ (2^n)) at_top (\ud835\udcdd $ \u03c4 f + \u03c4 g) :=\n ((f.tendsto_translation_number_aux.add g.tendsto_translation_number_aux).congr $\n \u03bb n, (add_div ((f^(2^n)) 0) ((g^(2^n)) 0) ((2:\u211d)^n)).symm),\n refine tendsto_nhds_unique\n ((f * g).tendsto_translation_number_of_dist_bounded_aux _ 1 (\u03bb n, _))\n this,\n rw [h.mul_pow, dist_comm],\n exact le_of_lt ((f^n).dist_map_map_zero_lt (g^n))\nend\n\n@[simp] lemma translation_number_units_inv (f : units circle_deg1_lift) :\n \u03c4 \u2191(f\u207b\u00b9) = -\u03c4 f :=\neq_neg_iff_add_eq_zero.2 $\n by simp [\u2190 translation_number_mul_of_commute (commute.refl _).units_inv_left]\n\n@[simp] lemma translation_number_pow :\n \u2200 n : \u2115, \u03c4 (f^n) = n * \u03c4 f\n| 0 := by simp\n| (n+1) := by rw [pow_succ', translation_number_mul_of_commute (commute.pow_self f n),\n translation_number_pow n, nat.cast_add_one, add_mul, one_mul]\n\n@[simp] lemma translation_number_gpow (f : units circle_deg1_lift) :\n \u2200 n : \u2124, \u03c4 (f ^ n : units _) = n * \u03c4 f\n| (n : \u2115) := by simp [translation_number_pow f n]\n| -[1+n] := by { simp, ring }\n\n@[simp] lemma translation_number_conj_eq (f : units circle_deg1_lift) (g : circle_deg1_lift) :\n \u03c4 (\u2191f * g * \u2191(f\u207b\u00b9)) = \u03c4 g :=\n(translation_number_eq_of_semiconj_by (f.mk_semiconj_by g)).symm\n\n@[simp] lemma translation_number_conj_eq' (f : units circle_deg1_lift) (g : circle_deg1_lift) :\n \u03c4 (\u2191(f\u207b\u00b9) * g * f) = \u03c4 g :=\ntranslation_number_conj_eq f\u207b\u00b9 g\n\nlemma dist_pow_map_zero_mul_translation_number_le (n:\u2115) :\n dist ((f^n) 0) (n * f.translation_number) \u2264 1 :=\nf.translation_number_pow n \u25b8 (f^n).dist_map_zero_translation_number_le\n\nlemma tendsto_translation_number\u2080' :\n tendsto (\u03bb n:\u2115, (f^(n+1)) 0 \/ (n+1)) at_top (\ud835\udcdd $ \u03c4 f) :=\nbegin\n refine (tendsto_iff_dist_tendsto_zero.2 $ squeeze_zero (\u03bb _, dist_nonneg) (\u03bb n, _)\n ((tendsto_const_div_at_top_nhds_0_nat 1).comp (tendsto_add_at_top_nat 1))),\n dsimp,\n have : (0:\u211d) < n + 1 := n.cast_add_one_pos,\n rw [real.dist_eq, div_sub' _ _ _ (ne_of_gt this), abs_div, \u2190 real.dist_eq, abs_of_pos this,\n div_le_div_right this, \u2190 nat.cast_add_one],\n apply dist_pow_map_zero_mul_translation_number_le\nend\n\nlemma tendsto_translation_number\u2080 :\n tendsto (\u03bb n:\u2115, ((f^n) 0) \/ n) at_top (\ud835\udcdd $ \u03c4 f) :=\n(tendsto_add_at_top_iff_nat 1).1 f.tendsto_translation_number\u2080'\n\n\/-- For any `x : \u211d` the sequence $\\frac{f^n(x)-x}{n}$ tends to the translation number of `f`.\nIn particular, this limit does not depend on `x`. -\/\nlemma tendsto_translation_number (x : \u211d) :\n tendsto (\u03bb n:\u2115, ((f^n) x - x) \/ n) at_top (\ud835\udcdd $ \u03c4 f) :=\nbegin\n rw [\u2190 translation_number_conj_eq' (translate $ multiplicative.of_add x)],\n convert tendsto_translation_number\u2080 _,\n ext n,\n simp [sub_eq_neg_add, units.conj_pow']\nend\n\nlemma tendsto_translation_number' (x : \u211d) :\n tendsto (\u03bb n:\u2115, ((f^(n+1)) x - x) \/ (n+1)) at_top (\ud835\udcdd $ \u03c4 f) :=\n(tendsto_add_at_top_iff_nat 1).2 (f.tendsto_translation_number x)\n\nlemma translation_number_mono : monotone \u03c4 :=\n\u03bb f g h, le_of_tendsto_of_tendsto' f.tendsto_translation_number\u2080\n g.tendsto_translation_number\u2080 $ \u03bb n, div_le_div_of_le_of_nonneg (pow_mono h n 0) n.cast_nonneg\n\nlemma translation_number_translate (x : \u211d) :\n \u03c4 (translate $ multiplicative.of_add x) = x :=\ntranslation_number_eq_of_tendsto\u2080' _ $\n by simp [nat.cast_add_one_ne_zero, mul_div_cancel_left, tendsto_const_nhds]\n\nlemma translation_number_le_of_le_add {z : \u211d} (hz : \u2200 x, f x \u2264 x + z) : \u03c4 f \u2264 z :=\ntranslation_number_translate z \u25b8 translation_number_mono\n (\u03bb x, trans_rel_left _ (hz x) (add_comm _ _))\n\nlemma le_translation_number_of_add_le {z : \u211d} (hz : \u2200 x, x + z \u2264 f x) : z \u2264 \u03c4 f :=\ntranslation_number_translate z \u25b8 translation_number_mono\n (\u03bb x, trans_rel_right _ (add_comm _ _) (hz x))\n\nlemma translation_number_le_of_le_add_int {x : \u211d} {m : \u2124} (h : f x \u2264 x + m) : \u03c4 f \u2264 m :=\nle_of_tendsto' (f.tendsto_translation_number' x) $ \u03bb n,\n(div_le_iff' (n.cast_add_one_pos : (0 : \u211d) < _)).mpr $ sub_le_iff_le_add'.2 $\n(coe_pow f (n + 1)).symm \u25b8 f.iterate_le_of_map_le_add_int h (n + 1)\n\nlemma translation_number_le_of_le_add_nat {x : \u211d} {m : \u2115} (h : f x \u2264 x + m) : \u03c4 f \u2264 m :=\n@translation_number_le_of_le_add_int f x m h\n\nlemma le_translation_number_of_add_int_le {x : \u211d} {m : \u2124} (h : x + m \u2264 f x) : \u2191m \u2264 \u03c4 f :=\nge_of_tendsto' (f.tendsto_translation_number' x) $ \u03bb n,\n(le_div_iff (n.cast_add_one_pos : (0 : \u211d) < _)).mpr $ le_sub_iff_add_le'.2 $\nby simp only [coe_pow, mul_comm (m:\u211d), \u2190 nat.cast_add_one, f.le_iterate_of_add_int_le_map h]\n\nlemma le_translation_number_of_add_nat_le {x : \u211d} {m : \u2115} (h : x + m \u2264 f x) : \u2191m \u2264 \u03c4 f :=\n@le_translation_number_of_add_int_le f x m h\n\n\/-- If `f x - x` is an integer number `m` for some point `x`, then `\u03c4 f = m`.\nOn the circle this means that a map with a fixed point has rotation number zero. -\/\nlemma translation_number_of_eq_add_int {x : \u211d} {m : \u2124} (h : f x = x + m) : \u03c4 f = m :=\nle_antisymm (translation_number_le_of_le_add_int f $ le_of_eq h)\n (le_translation_number_of_add_int_le f $ le_of_eq h.symm)\n\nlemma floor_sub_le_translation_number (x : \u211d) : \u2191\u230af x - x\u230b \u2264 \u03c4 f :=\nle_translation_number_of_add_int_le f $ le_sub_iff_add_le'.1 (floor_le $ f x - x)\n\nlemma translation_number_le_ceil_sub (x : \u211d) : \u03c4 f \u2264 \u2308f x - x\u2309 :=\ntranslation_number_le_of_le_add_int f $ sub_le_iff_le_add'.1 (le_ceil $ f x - x)\n\nlemma map_lt_of_translation_number_lt_int {n : \u2124} (h : \u03c4 f < n) (x : \u211d) : f x < x + n :=\nnot_le.1 $ mt f.le_translation_number_of_add_int_le $ not_le.2 h\n\nlemma map_lt_of_translation_number_lt_nat {n : \u2115} (h : \u03c4 f < n) (x : \u211d) : f x < x + n :=\n@map_lt_of_translation_number_lt_int f n h x\n\nlemma map_lt_add_floor_translation_number_add_one (x : \u211d) : f x < x + \u230a\u03c4 f\u230b + 1 :=\nbegin\n rw [add_assoc],\n norm_cast,\n refine map_lt_of_translation_number_lt_int _ _ _,\n push_cast,\n exact lt_floor_add_one _\nend\n\nlemma map_lt_add_translation_number_add_one (x : \u211d) : f x < x + \u03c4 f + 1 :=\ncalc f x < x + \u230a\u03c4 f\u230b + 1 : f.map_lt_add_floor_translation_number_add_one x\n... \u2264 x + \u03c4 f + 1 : by { mono*, exact floor_le (\u03c4 f) }\n\nlemma lt_map_of_int_lt_translation_number {n : \u2124} (h : \u2191n < \u03c4 f) (x : \u211d) : x + n < f x :=\nnot_le.1 $ mt f.translation_number_le_of_le_add_int $ not_le.2 h\n\nlemma lt_map_of_nat_lt_translation_number {n : \u2115} (h : \u2191n < \u03c4 f) (x : \u211d) : x + n < f x :=\n@lt_map_of_int_lt_translation_number f n h x\n\n\/-- If `f^n x - x`, `n > 0`, is an integer number `m` for some point `x`, then\n`\u03c4 f = m \/ n`. On the circle this means that a map with a periodic orbit has\na rational rotation number. -\/\nlemma translation_number_of_map_pow_eq_add_int {x : \u211d} {n : \u2115} {m : \u2124}\n (h : (f^n) x = x + m) (hn : 0 < n) :\n \u03c4 f = m \/ n :=\nbegin\n have := (f^n).translation_number_of_eq_add_int h,\n rwa [translation_number_pow, mul_comm, \u2190 eq_div_iff] at this,\n exact nat.cast_ne_zero.2 (ne_of_gt hn)\nend\n\n\/-- If a predicate depends only on `f x - x` and holds for all `0 \u2264 x \u2264 1`,\nthen it holds for all `x`. -\/\nlemma forall_map_sub_of_Icc (P : \u211d \u2192 Prop)\n (h : \u2200 x \u2208 Icc (0:\u211d) 1, P (f x - x)) (x : \u211d) : P (f x - x) :=\nf.map_fract_sub_fract_eq x \u25b8 h _ \u27e8fract_nonneg _, le_of_lt (fract_lt_one _)\u27e9\n\nlemma translation_number_lt_of_forall_lt_add (hf : continuous f) {z : \u211d}\n (hz : \u2200 x, f x < x + z) : \u03c4 f < z :=\nbegin\n obtain \u27e8x, xmem, hx\u27e9 : \u2203 x \u2208 Icc (0:\u211d) 1, \u2200 y \u2208 Icc (0:\u211d) 1, f y - y \u2264 f x - x,\n from compact_Icc.exists_forall_ge (nonempty_Icc.2 zero_le_one)\n (hf.sub continuous_id).continuous_on,\n refine lt_of_le_of_lt _ (sub_lt_iff_lt_add'.2 $ hz x),\n apply translation_number_le_of_le_add,\n simp only [\u2190 sub_le_iff_le_add'],\n exact f.forall_map_sub_of_Icc (\u03bb a, a \u2264 f x - x) hx\nend\n\nlemma lt_translation_number_of_forall_add_lt (hf : continuous f) {z : \u211d}\n (hz : \u2200 x, x + z < f x) : z < \u03c4 f :=\nbegin\n obtain \u27e8x, xmem, hx\u27e9 : \u2203 x \u2208 Icc (0:\u211d) 1, \u2200 y \u2208 Icc (0:\u211d) 1, f x - x \u2264 f y - y,\n from compact_Icc.exists_forall_le (nonempty_Icc.2 zero_le_one)\n (hf.sub continuous_id).continuous_on,\n refine lt_of_lt_of_le (lt_sub_iff_add_lt'.2 $ hz x) _,\n apply le_translation_number_of_add_le,\n simp only [\u2190 le_sub_iff_add_le'],\n exact f.forall_map_sub_of_Icc _ hx\nend\n\n\/-- If `f` is a continuous monotone map `\u211d \u2192 \u211d`, `f (x + 1) = f x + 1`, then there exists `x`\nsuch that `f x = x + \u03c4 f`. -\/\nlemma exists_eq_add_translation_number (hf : continuous f) :\n \u2203 x, f x = x + \u03c4 f :=\nbegin\n obtain \u27e8a, ha\u27e9 : \u2203 x, f x \u2264 x + f.translation_number,\n { by_contradiction H,\n push_neg at H,\n exact lt_irrefl _ (f.lt_translation_number_of_forall_add_lt hf H) },\n obtain \u27e8b, hb\u27e9 : \u2203 x, x + \u03c4 f \u2264 f x,\n { by_contradiction H,\n push_neg at H,\n exact lt_irrefl _ (f.translation_number_lt_of_forall_lt_add hf H) },\n exact intermediate_value_univ\u2082 hf (continuous_id.add continuous_const) ha hb\nend\n\nlemma translation_number_eq_int_iff (hf : continuous f) {m : \u2124} :\n \u03c4 f = m \u2194 \u2203 x, f x = x + m :=\nbegin\n refine \u27e8\u03bb h, h \u25b8 f.exists_eq_add_translation_number hf, _\u27e9,\n rintros \u27e8x, hx\u27e9,\n exact f.translation_number_of_eq_add_int hx\nend\n\nlemma continuous_pow (hf : continuous f) (n : \u2115) :\n continuous \u21d1(f^n : circle_deg1_lift) :=\nby { rw coe_pow, exact hf.iterate n }\n\nlemma translation_number_eq_rat_iff (hf : continuous f) {m : \u2124}\n {n : \u2115} (hn : 0 < n) :\n \u03c4 f = m \/ n \u2194 \u2203 x, (f^n) x = x + m :=\nbegin\n rw [eq_div_iff, mul_comm, \u2190 translation_number_pow]; [skip, exact ne_of_gt (nat.cast_pos.2 hn)],\n exact (f^n).translation_number_eq_int_iff (f.continuous_pow hf n)\nend\n\n\/-- Consider two actions `f\u2081 f\u2082 : G \u2192* circle_deg1_lift` of a group on the real line by lifts of\norientation preserving circle homeomorphisms. Suppose that for each `g : G` the homeomorphisms\n`f\u2081 g` and `f\u2082 g` have equal rotation numbers. Then there exists `F : circle_deg1_lift` such that\n`F * f\u2081 g = f\u2082 g * F` for all `g : G`.\n\nThis is a version of Proposition 5.4 from [\u00c9tienne Ghys, Groupes d'homeomorphismes du cercle et\ncohomologie bornee][ghys87:groupes]. -\/\nlemma semiconj_of_group_action_of_forall_translation_number_eq\n {G : Type*} [group G] (f\u2081 f\u2082 : G \u2192* circle_deg1_lift)\n (h : \u2200 g, \u03c4 (f\u2081 g) = \u03c4 (f\u2082 g)) :\n \u2203 F : circle_deg1_lift, \u2200 g, semiconj F (f\u2081 g) (f\u2082 g) :=\nbegin\n -- Equality of translation number guarantees that for each `x`\n -- the set `{f\u2082 g\u207b\u00b9 (f\u2081 g x) | g : G}` is bounded above.\n have : \u2200 x, bdd_above (range $ \u03bb g, f\u2082 g\u207b\u00b9 (f\u2081 g x)),\n { refine \u03bb x, \u27e8x + 2, _\u27e9,\n rintro _ \u27e8g, rfl\u27e9,\n have : \u03c4 (f\u2082 g\u207b\u00b9) = -\u03c4 (f\u2082 g),\n by rw [\u2190 monoid_hom.coe_to_hom_units, monoid_hom.map_inv,\n translation_number_units_inv, monoid_hom.coe_to_hom_units],\n calc f\u2082 g\u207b\u00b9 (f\u2081 g x) \u2264 f\u2082 g\u207b\u00b9 (x + \u03c4 (f\u2081 g) + 1) :\n mono _ (map_lt_add_translation_number_add_one _ _).le\n ... = f\u2082 g\u207b\u00b9 (x + \u03c4 (f\u2082 g)) + 1 :\n by rw [h, map_add_one]\n ... \u2264 x + \u03c4 (f\u2082 g) + \u03c4 (f\u2082 g\u207b\u00b9) + 1 + 1 :\n by { mono, exact (map_lt_add_translation_number_add_one _ _).le }\n ... = x + 2 : by simp [this, bit0, add_assoc] },\n -- We have a theorem about actions by `order_iso`, so we introduce auxiliary maps\n -- to `\u211d \u2243o \u211d`.\n set F\u2081 := to_order_iso.comp f\u2081.to_hom_units,\n set F\u2082 := to_order_iso.comp f\u2082.to_hom_units,\n have hF\u2081 : \u2200 g, \u21d1(F\u2081 g) = f\u2081 g := \u03bb _, rfl,\n have hF\u2082 : \u2200 g, \u21d1(F\u2082 g) = f\u2082 g := \u03bb _, rfl,\n simp only [\u2190 hF\u2081, \u2190 hF\u2082],\n -- Now we apply `cSup_div_semiconj` and go back to `f\u2081` and `f\u2082`.\n refine \u27e8\u27e8_, \u03bb x y hxy, _, \u03bb x, _\u27e9, cSup_div_semiconj F\u2082 F\u2081 (\u03bb x, _)\u27e9;\n simp only [hF\u2081, hF\u2082, \u2190 monoid_hom.map_inv, coe_mk],\n { refine csupr_le_csupr (this y) (\u03bb g, _),\n exact mono _ (mono _ hxy) },\n { simp only [map_add_one],\n exact (map_csupr_of_continuous_at_of_monotone (continuous_at_id.add continuous_at_const)\n (monotone_id.add_const (1 : \u211d)) (this x)).symm },\n { exact this x }\nend\n\n\/-- If two lifts of circle homeomorphisms have the same translation number, then they are\nsemiconjugate by a `circle_deg1_lift`. This version uses arguments `f\u2081 f\u2082 : units circle_deg1_lift`\nto assume that `f\u2081` and `f\u2082` are homeomorphisms. -\/\nlemma units_semiconj_of_translation_number_eq {f\u2081 f\u2082 : units circle_deg1_lift}\n (h : \u03c4 f\u2081 = \u03c4 f\u2082) :\n \u2203 F : circle_deg1_lift, semiconj F f\u2081 f\u2082 :=\nbegin\n have : \u2200 n : multiplicative \u2124, \u03c4 ((units.coe_hom _).comp (gpowers_hom _ f\u2081) n) =\n \u03c4 ((units.coe_hom _).comp (gpowers_hom _ f\u2082) n),\n { intro n, simp [h] },\n exact (semiconj_of_group_action_of_forall_translation_number_eq _ _ this).imp\n (\u03bb F hF, hF (multiplicative.of_add 1))\nend\n\n\/-- If two lifts of circle homeomorphisms have the same translation number, then they are\nsemiconjugate by a `circle_deg1_lift`. This version uses assumptions `is_unit f\u2081` and `is_unit f\u2082`\nto assume that `f\u2081` and `f\u2082` are homeomorphisms. -\/\nlemma semiconj_of_is_unit_of_translation_number_eq {f\u2081 f\u2082 : circle_deg1_lift}\n (h\u2081 : is_unit f\u2081) (h\u2082 : is_unit f\u2082) (h : \u03c4 f\u2081 = \u03c4 f\u2082) :\n \u2203 F : circle_deg1_lift, semiconj F f\u2081 f\u2082 :=\nby { rcases \u27e8h\u2081, h\u2082\u27e9 with \u27e8\u27e8f\u2081, rfl\u27e9, \u27e8f\u2082, rfl\u27e9\u27e9, exact units_semiconj_of_translation_number_eq h }\n\n\/-- If two lifts of circle homeomorphisms have the same translation number, then they are\nsemiconjugate by a `circle_deg1_lift`. This version uses assumptions `bijective f\u2081` and\n`bijective f\u2082` to assume that `f\u2081` and `f\u2082` are homeomorphisms. -\/\nlemma semiconj_of_bijective_of_translation_number_eq {f\u2081 f\u2082 : circle_deg1_lift}\n (h\u2081 : bijective f\u2081) (h\u2082 : bijective f\u2082) (h : \u03c4 f\u2081 = \u03c4 f\u2082) :\n \u2203 F : circle_deg1_lift, semiconj F f\u2081 f\u2082 :=\nsemiconj_of_is_unit_of_translation_number_eq\n (is_unit_iff_bijective.2 h\u2081) (is_unit_iff_bijective.2 h\u2082) h\n\nend circle_deg1_lift\n","avg_line_length":42.8446712018,"max_line_length":100,"alphanum_fraction":0.6749583212} -{"size":9806,"ext":"lean","lang":"Lean","max_stars_count":1538.0,"content":"\/-\nCopyright (c) 2020 Marc Huisinga. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Marc Huisinga, Wojciech Nawrocki\n-\/\nimport Init.Control\nimport Init.System.IO\nimport Std.Data.RBTree\nimport Lean.Data.Json\n\n\/-! Implementation of JSON-RPC 2.0 (https:\/\/www.jsonrpc.org\/specification)\nfor use in the LSP server. -\/\n\nnamespace Lean.JsonRpc\n\nopen Json\nopen Std (RBNode)\n\ninductive RequestID where\n | str (s : String)\n | num (n : JsonNumber)\n | null\n deriving Inhabited, BEq, Ord\n\ninstance : ToString RequestID where\n toString\n | RequestID.str s => s!\"\\\"s\\\"\"\n | RequestID.num n => toString n\n | RequestID.null => \"null\"\n\n\/-- Error codes defined by JSON-RPC and LSP. -\/\ninductive ErrorCode where\n | parseError\n | invalidRequest\n | methodNotFound\n | invalidParams\n | internalError\n | serverNotInitialized\n | unknownErrorCode\n -- LSP-specific codes below.\n | contentModified\n | requestCancelled\n -- Lean-specific codes below.\n | rpcNeedsReconnect\n deriving Inhabited, BEq\n\ninstance : FromJson ErrorCode := \u27e8fun\n | num (-32700 : Int) => ErrorCode.parseError\n | num (-32600 : Int) => ErrorCode.invalidRequest\n | num (-32601 : Int) => ErrorCode.methodNotFound\n | num (-32602 : Int) => ErrorCode.invalidParams\n | num (-32603 : Int) => ErrorCode.internalError\n | num (-32002 : Int) => ErrorCode.serverNotInitialized\n | num (-32001 : Int) => ErrorCode.unknownErrorCode\n | num (-32801 : Int) => ErrorCode.contentModified\n | num (-32800 : Int) => ErrorCode.requestCancelled\n | num (-32900 : Int) => ErrorCode.rpcNeedsReconnect\n | _ => throw \"expected error code\"\u27e9\n\ninstance : ToJson ErrorCode := \u27e8fun\n | ErrorCode.parseError => (-32700 : Int)\n | ErrorCode.invalidRequest => (-32600 : Int)\n | ErrorCode.methodNotFound => (-32601 : Int)\n | ErrorCode.invalidParams => (-32602 : Int)\n | ErrorCode.internalError => (-32603 : Int)\n | ErrorCode.serverNotInitialized => (-32002 : Int)\n | ErrorCode.unknownErrorCode => (-32001 : Int)\n | ErrorCode.contentModified => (-32801 : Int)\n | ErrorCode.requestCancelled => (-32800 : Int)\n | ErrorCode.rpcNeedsReconnect => (-32900 : Int)\u27e9\n\n\/- Uses separate constructors for notifications and errors because client and server\nbehavior is expected to be wildly different for both. -\/\ninductive Message where\n | request (id : RequestID) (method : String) (params? : Option Structured)\n | notification (method : String) (params? : Option Structured)\n | response (id : RequestID) (result : Json)\n | responseError (id : RequestID) (code : ErrorCode) (message : String) (data? : Option Json)\n\ndef Batch := Array Message\n\n-- Compound type with simplified APIs for passing around\n-- jsonrpc data\nstructure Request (\u03b1 : Type u) where\n id : RequestID\n method : String\n param : \u03b1\n deriving Inhabited, BEq\n\ninstance [ToJson \u03b1] : Coe (Request \u03b1) Message :=\n \u27e8fun r => Message.request r.id r.method (toStructured? r.param).toOption\u27e9\n\nstructure Notification (\u03b1 : Type u) where\n method : String\n param : \u03b1\n deriving Inhabited, BEq\n\ninstance [ToJson \u03b1] : Coe (Notification \u03b1) Message :=\n \u27e8fun r => Message.notification r.method (toStructured? r.param).toOption\u27e9\n\nstructure Response (\u03b1 : Type u) where\n id : RequestID\n result : \u03b1\n deriving Inhabited, BEq\n\ninstance [ToJson \u03b1] : Coe (Response \u03b1) Message :=\n \u27e8fun r => Message.response r.id (toJson r.result)\u27e9\n\nstructure ResponseError (\u03b1 : Type u) where\n id : RequestID\n code : ErrorCode\n message : String\n data? : Option \u03b1 := none\n deriving Inhabited, BEq\n\ninstance [ToJson \u03b1] : Coe (ResponseError \u03b1) Message :=\n \u27e8fun r => Message.responseError r.id r.code r.message (r.data?.map toJson)\u27e9\n\ninstance : Coe String RequestID := \u27e8RequestID.str\u27e9\ninstance : Coe JsonNumber RequestID := \u27e8RequestID.num\u27e9\n\nprivate def RequestID.lt : RequestID \u2192 RequestID \u2192 Bool\n | RequestID.str a, RequestID.str b => a < b\n | RequestID.num a, RequestID.num b => a < b\n | RequestID.null, RequestID.num _ => true\n | RequestID.null, RequestID.str _ => true\n | RequestID.num _, RequestID.str _ => true\n | _, _ \/- str < *, num < null, null < null -\/ => false\n\nprivate def RequestID.ltProp : LT RequestID :=\n \u27e8fun a b => RequestID.lt a b = true\u27e9\n\ninstance : LT RequestID :=\n RequestID.ltProp\n\ninstance (a b : RequestID) : Decidable (a < b) :=\n inferInstanceAs (Decidable (RequestID.lt a b = true))\n\ninstance : FromJson RequestID := \u27e8fun j =>\n match j with\n | str s => RequestID.str s\n | num n => RequestID.num n\n | _ => throw \"a request id needs to be a number or a string\"\u27e9\n\ninstance : ToJson RequestID := \u27e8fun rid =>\n match rid with\n | RequestID.str s => s\n | RequestID.num n => num n\n | RequestID.null => null\u27e9\n\ninstance : ToJson Message := \u27e8fun m =>\n mkObj $ \u27e8\"jsonrpc\", \"2.0\"\u27e9 :: match m with\n | Message.request id method params? =>\n [ \u27e8\"id\", toJson id\u27e9,\n \u27e8\"method\", method\u27e9\n ] ++ opt \"params\" params?\n | Message.notification method params? =>\n \u27e8\"method\", method\u27e9 ::\n opt \"params\" params?\n | Message.response id result =>\n [ \u27e8\"id\", toJson id\u27e9,\n \u27e8\"result\", result\u27e9]\n | Message.responseError id code message data? =>\n [ \u27e8\"id\", toJson id\u27e9,\n \u27e8\"error\", mkObj $ [\n \u27e8\"code\", toJson code\u27e9,\n \u27e8\"message\", message\u27e9\n ] ++ opt \"data\" data?\u27e9\n ]\u27e9\n\ninstance : FromJson Message where\n fromJson? j := do\n let \"2.0\" \u2190 j.getObjVal? \"jsonrpc\" | throw \"only version 2.0 of JSON RPC is supported\"\n (do let id \u2190 j.getObjValAs? RequestID \"id\"\n let method \u2190 j.getObjValAs? String \"method\"\n let params? := j.getObjValAs? Structured \"params\"\n pure (Message.request id method params?.toOption)) <|>\n (do let method \u2190 j.getObjValAs? String \"method\"\n let params? := j.getObjValAs? Structured \"params\"\n pure (Message.notification method params?.toOption)) <|>\n (do let id \u2190 j.getObjValAs? RequestID \"id\"\n let result \u2190 j.getObjVal? \"result\"\n pure (Message.response id result)) <|>\n (do let id \u2190 j.getObjValAs? RequestID \"id\"\n let err \u2190 j.getObjVal? \"error\"\n let code \u2190 err.getObjValAs? ErrorCode \"code\"\n let message \u2190 err.getObjValAs? String \"message\"\n let data? := err.getObjVal? \"data\"\n pure (Message.responseError id code message data?.toOption))\n\n-- TODO(WN): temporary until we have deriving FromJson\ninstance [FromJson \u03b1] : FromJson (Notification \u03b1) where\n fromJson? j := do\n let msg : Message \u2190 fromJson? j\n if let Message.notification method params? := msg then\n let params \u2190 params?\n let param : \u03b1 \u2190 fromJson? (toJson params)\n pure $ \u27e8method, param\u27e9\n else throw \"not a notfication\"\n\nend Lean.JsonRpc\n\nnamespace IO.FS.Stream\n\nopen Lean\nopen Lean.JsonRpc\n\nsection\n def readMessage (h : FS.Stream) (nBytes : Nat) : IO Message := do\n let j \u2190 h.readJson nBytes\n match fromJson? j with\n | Except.ok m => pure m\n | Except.error inner => throw $ userError s!\"JSON '{j.compress}' did not have the format of a JSON-RPC message.\\n{inner}\"\n\n def readRequestAs (h : FS.Stream) (nBytes : Nat) (expectedMethod : String) (\u03b1) [FromJson \u03b1] : IO (Request \u03b1) := do\n let m \u2190 h.readMessage nBytes\n match m with\n | Message.request id method params? =>\n if method = expectedMethod then\n let j := toJson params?\n match fromJson? j with\n | Except.ok v => pure \u27e8id, expectedMethod, v\u27e9\n | Except.error inner => throw $ userError s!\"Unexpected param '{j.compress}' for method '{expectedMethod}'\\n{inner}\"\n else\n throw $ userError s!\"Expected method '{expectedMethod}', got method '{method}'\"\n | _ => throw $ userError s!\"Expected JSON-RPC request, got: '{(toJson m).compress}'\"\n\n def readNotificationAs (h : FS.Stream) (nBytes : Nat) (expectedMethod : String) (\u03b1) [FromJson \u03b1] : IO (Notification \u03b1) := do\n let m \u2190 h.readMessage nBytes\n match m with\n | Message.notification method params? =>\n if method = expectedMethod then\n let j := toJson params?\n match fromJson? j with\n | Except.ok v => pure \u27e8expectedMethod, v\u27e9\n | Except.error inner => throw $ userError s!\"Unexpected param '{j.compress}' for method '{expectedMethod}'\\n{inner}\"\n else\n throw $ userError s!\"Expected method '{expectedMethod}', got method '{method}'\"\n | _ => throw $ userError s!\"Expected JSON-RPC notification, got: '{(toJson m).compress}'\"\n\n partial def readResponseAs (h : FS.Stream) (nBytes : Nat) (expectedID : RequestID) (\u03b1) [FromJson \u03b1] : IO (Response \u03b1) := do\n let m \u2190 h.readMessage nBytes\n match m with\n | Message.response id result =>\n if id == expectedID then\n match fromJson? result with\n | Except.ok v => pure \u27e8expectedID, v\u27e9\n | Except.error inner => throw $ userError s!\"Unexpected result '{result.compress}'\\n{inner}\"\n else\n throw $ userError s!\"Expected id {expectedID}, got id {id}\"\n | Message.notification .. => readResponseAs h nBytes expectedID \u03b1\n | _ => throw $ userError s!\"Expected JSON-RPC response, got: '{(toJson m).compress}'\"\nend\n\nsection\n variable [ToJson \u03b1]\n\n def writeMessage (h : FS.Stream) (m : Message) : IO Unit :=\n h.writeJson (toJson m)\n\n def writeRequest (h : FS.Stream) (r : Request \u03b1) : IO Unit :=\n h.writeMessage r\n\n def writeNotification (h : FS.Stream) (n : Notification \u03b1) : IO Unit :=\n h.writeMessage n\n\n def writeResponse (h : FS.Stream) (r : Response \u03b1) : IO Unit :=\n h.writeMessage r\n\n def writeResponseError (h : FS.Stream) (e : ResponseError Unit) : IO Unit :=\n h.writeMessage (Message.responseError e.id e.code e.message none)\n\n def writeResponseErrorWithData (h : FS.Stream) (e : ResponseError \u03b1) : IO Unit :=\n h.writeMessage e\nend\n\nend IO.FS.Stream\n","avg_line_length":35.146953405,"max_line_length":126,"alphanum_fraction":0.6521517438} -{"size":45302,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2016 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes H\u00f6lzl\n-\/\nimport algebra.abs\nimport algebra.order.sub\nimport order.order_dual\n\n\/-!\n# Ordered groups\n\nThis file develops the basics of ordered groups.\n\n## Implementation details\n\nUnfortunately, the number of `'` appended to lemmas in this file\nmay differ between the multiplicative and the additive version of a lemma.\nThe reason is that we did not want to change existing names in the library.\n-\/\n\nset_option old_structure_cmd true\nopen function\n\nuniverse u\nvariable {\u03b1 : Type u}\n\n@[to_additive]\ninstance group.covariant_class_le.to_contravariant_class_le\n [group \u03b1] [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] : contravariant_class \u03b1 \u03b1 (*) (\u2264) :=\ngroup.covconv\n\n@[to_additive]\ninstance group.swap.covariant_class_le.to_contravariant_class_le [group \u03b1] [has_le \u03b1]\n [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] : contravariant_class \u03b1 \u03b1 (swap (*)) (\u2264) :=\n{ elim := \u03bb a b c bc, calc b = b * a * a\u207b\u00b9 : eq_mul_inv_of_mul_eq rfl\n ... \u2264 c * a * a\u207b\u00b9 : mul_le_mul_right' bc a\u207b\u00b9\n ... = c : mul_inv_eq_of_eq_mul rfl }\n\n@[to_additive]\ninstance group.covariant_class_lt.to_contravariant_class_lt\n [group \u03b1] [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] : contravariant_class \u03b1 \u03b1 (*) (<) :=\n{ elim := \u03bb a b c bc, calc b = a\u207b\u00b9 * (a * b) : eq_inv_mul_of_mul_eq rfl\n ... < a\u207b\u00b9 * (a * c) : mul_lt_mul_left' bc a\u207b\u00b9\n ... = c : inv_mul_cancel_left a c }\n\n@[to_additive]\ninstance group.swap.covariant_class_lt.to_contravariant_class_lt [group \u03b1] [has_lt \u03b1]\n [covariant_class \u03b1 \u03b1 (swap (*)) (<)] : contravariant_class \u03b1 \u03b1 (swap (*)) (<) :=\n{ elim := \u03bb a b c bc, calc b = b * a * a\u207b\u00b9 : eq_mul_inv_of_mul_eq rfl\n ... < c * a * a\u207b\u00b9 : mul_lt_mul_right' bc a\u207b\u00b9\n ... = c : mul_inv_eq_of_eq_mul rfl }\n\n\/-- An ordered additive commutative group is an additive commutative group\nwith a partial order in which addition is strictly monotone. -\/\n@[protect_proj, ancestor add_comm_group partial_order]\nclass ordered_add_comm_group (\u03b1 : Type u) extends add_comm_group \u03b1, partial_order \u03b1 :=\n(add_le_add_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c + a \u2264 c + b)\n\n\/-- An ordered commutative group is an commutative group\nwith a partial order in which multiplication is strictly monotone. -\/\n@[protect_proj, ancestor comm_group partial_order]\nclass ordered_comm_group (\u03b1 : Type u) extends comm_group \u03b1, partial_order \u03b1 :=\n(mul_le_mul_left : \u2200 a b : \u03b1, a \u2264 b \u2192 \u2200 c : \u03b1, c * a \u2264 c * b)\nattribute [to_additive] ordered_comm_group\n\n@[to_additive]\ninstance ordered_comm_group.to_covariant_class_left_le (\u03b1 : Type u) [ordered_comm_group \u03b1] :\n covariant_class \u03b1 \u03b1 (*) (\u2264) :=\n{ elim := \u03bb a b c bc, ordered_comm_group.mul_le_mul_left b c bc a }\n\n\/--The units of an ordered commutative monoid form an ordered commutative group. -\/\n@[to_additive]\ninstance units.ordered_comm_group [ordered_comm_monoid \u03b1] : ordered_comm_group \u03b1\u02e3 :=\n{ mul_le_mul_left := \u03bb a b h c, (mul_le_mul_left' (h : (a : \u03b1) \u2264 b) _ : (c : \u03b1) * a \u2264 c * b),\n .. units.partial_order,\n .. units.comm_group }\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance ordered_comm_group.to_ordered_cancel_comm_monoid (\u03b1 : Type u)\n [s : ordered_comm_group \u03b1] :\n ordered_cancel_comm_monoid \u03b1 :=\n{ mul_left_cancel := \u03bb a b c, (mul_right_inj a).mp,\n le_of_mul_le_mul_left := \u03bb a b c, (mul_le_mul_iff_left a).mp,\n ..s }\n\n@[priority 100, to_additive]\ninstance ordered_comm_group.has_exists_mul_of_le (\u03b1 : Type u)\n [ordered_comm_group \u03b1] :\n has_exists_mul_of_le \u03b1 :=\n\u27e8\u03bb a b hab, \u27e8b * a\u207b\u00b9, (mul_inv_cancel_comm_assoc a b).symm\u27e9\u27e9\n\n@[to_additive] instance [h : has_inv \u03b1] : has_inv (order_dual \u03b1) := h\n@[to_additive] instance [h : has_div \u03b1] : has_div (order_dual \u03b1) := h\n@[to_additive] instance [h : div_inv_monoid \u03b1] : div_inv_monoid (order_dual \u03b1) := h\n@[to_additive] instance [h : group \u03b1] : group (order_dual \u03b1) := h\n@[to_additive] instance [h : comm_group \u03b1] : comm_group (order_dual \u03b1) := h\n\n@[to_additive] instance [ordered_comm_group \u03b1] : ordered_comm_group (order_dual \u03b1) :=\n{ .. order_dual.ordered_comm_monoid, .. order_dual.group }\n\nsection group\nvariables [group \u03b1]\n\nsection typeclasses_left_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n\/-- Uses `left` co(ntra)variant. -\/\n@[simp, to_additive left.neg_nonpos_iff]\nlemma left.inv_le_one_iff :\n a\u207b\u00b9 \u2264 1 \u2194 1 \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_left a], simp }\n\n\/-- Uses `left` co(ntra)variant. -\/\n@[simp, to_additive left.nonneg_neg_iff]\nlemma left.one_le_inv_iff :\n 1 \u2264 a\u207b\u00b9 \u2194 a \u2264 1 :=\nby { rw [\u2190 mul_le_mul_iff_left a], simp }\n\n@[simp, to_additive]\nlemma le_inv_mul_iff_mul_le : b \u2264 a\u207b\u00b9 * c \u2194 a * b \u2264 c :=\nby { rw \u2190 mul_le_mul_iff_left a, simp }\n\n@[simp, to_additive]\nlemma inv_mul_le_iff_le_mul : b\u207b\u00b9 * a \u2264 c \u2194 a \u2264 b * c :=\nby rw [\u2190 mul_le_mul_iff_left b, mul_inv_cancel_left]\n\n@[to_additive neg_le_iff_add_nonneg']\nlemma inv_le_iff_one_le_mul' : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 a * b :=\n(mul_le_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one_left : a \u2264 b\u207b\u00b9 \u2194 b * a \u2264 1 :=\n(mul_le_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma le_inv_mul_iff_le : 1 \u2264 b\u207b\u00b9 * a \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_mul_le_one_iff : a\u207b\u00b9 * b \u2264 1 \u2194 b \u2264 a :=\ntrans (inv_mul_le_iff_le_mul) $ by rw mul_one\n\nend typeclasses_left_le\n\nsection typeclasses_left_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c : \u03b1}\n\n\/-- Uses `left` co(ntra)variant. -\/\n@[simp, to_additive left.neg_pos_iff]\nlemma left.one_lt_inv_iff :\n 1 < a\u207b\u00b9 \u2194 a < 1 :=\nby rw [\u2190 mul_lt_mul_iff_left a, mul_inv_self, mul_one]\n\n\/-- Uses `left` co(ntra)variant. -\/\n@[simp, to_additive left.neg_neg_iff]\nlemma left.inv_lt_one_iff :\n a\u207b\u00b9 < 1 \u2194 1 < a :=\nby rw [\u2190 mul_lt_mul_iff_left a, mul_inv_self, mul_one]\n\n@[simp, to_additive]\nlemma lt_inv_mul_iff_mul_lt : b < a\u207b\u00b9 * c \u2194 a * b < c :=\nby { rw [\u2190 mul_lt_mul_iff_left a], simp }\n\n@[simp, to_additive]\nlemma inv_mul_lt_iff_lt_mul : b\u207b\u00b9 * a < c \u2194 a < b * c :=\nby rw [\u2190 mul_lt_mul_iff_left b, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul' : a\u207b\u00b9 < b \u2194 1 < a * b :=\n(mul_lt_mul_iff_left a).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one' : a < b\u207b\u00b9 \u2194 b * a < 1 :=\n(mul_lt_mul_iff_left b).symm.trans $ by rw mul_inv_self\n\n@[to_additive]\nlemma lt_inv_mul_iff_lt : 1 < b\u207b\u00b9 * a \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left]\n\n@[to_additive]\nlemma inv_mul_lt_one_iff : a\u207b\u00b9 * b < 1 \u2194 b < a :=\ntrans (inv_mul_lt_iff_lt_mul) $ by rw mul_one\n\nend typeclasses_left_lt\n\nsection typeclasses_right_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c : \u03b1}\n\n\/-- Uses `right` co(ntra)variant. -\/\n@[simp, to_additive right.neg_nonpos_iff]\nlemma right.inv_le_one_iff :\n a\u207b\u00b9 \u2264 1 \u2194 1 \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_right a], simp }\n\n\/-- Uses `right` co(ntra)variant. -\/\n@[simp, to_additive right.nonneg_neg_iff]\nlemma right.one_le_inv_iff :\n 1 \u2264 a\u207b\u00b9 \u2194 a \u2264 1 :=\nby { rw [\u2190 mul_le_mul_iff_right a], simp }\n\n@[to_additive neg_le_iff_add_nonneg]\nlemma inv_le_iff_one_le_mul : a\u207b\u00b9 \u2264 b \u2194 1 \u2264 b * a :=\n(mul_le_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma le_inv_iff_mul_le_one_right : a \u2264 b\u207b\u00b9 \u2194 a * b \u2264 1 :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[simp, to_additive]\nlemma mul_inv_le_iff_le_mul : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 c * b :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma le_mul_inv_iff_mul_le : c \u2264 a * b\u207b\u00b9 \u2194 c * b \u2264 a :=\n(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma mul_inv_le_one_iff_le : a * b\u207b\u00b9 \u2264 1 \u2194 a \u2264 b :=\nmul_inv_le_iff_le_mul.trans $ by rw one_mul\n\n@[to_additive]\nlemma le_mul_inv_iff_le : 1 \u2264 a * b\u207b\u00b9 \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right]\n\n@[to_additive]\nlemma mul_inv_le_one_iff : b * a\u207b\u00b9 \u2264 1 \u2194 b \u2264 a :=\ntrans (mul_inv_le_iff_le_mul) $ by rw one_mul\n\nend typeclasses_right_le\n\nsection typeclasses_right_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c : \u03b1}\n\n\/-- Uses `right` co(ntra)variant. -\/\n@[simp, to_additive right.neg_neg_iff]\nlemma right.inv_lt_one_iff :\n a\u207b\u00b9 < 1 \u2194 1 < a :=\nby rw [\u2190 mul_lt_mul_iff_right a, inv_mul_self, one_mul]\n\n\/-- Uses `right` co(ntra)variant. -\/\n@[simp, to_additive right.neg_pos_iff]\nlemma right.one_lt_inv_iff :\n 1 < a\u207b\u00b9 \u2194 a < 1 :=\nby rw [\u2190 mul_lt_mul_iff_right a, inv_mul_self, one_mul]\n\n@[to_additive]\nlemma inv_lt_iff_one_lt_mul : a\u207b\u00b9 < b \u2194 1 < b * a :=\n(mul_lt_mul_iff_right a).symm.trans $ by rw inv_mul_self\n\n@[to_additive]\nlemma lt_inv_iff_mul_lt_one : a < b\u207b\u00b9 \u2194 a * b < 1 :=\n(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_self\n\n@[simp, to_additive]\nlemma mul_inv_lt_iff_lt_mul : a * b\u207b\u00b9 < c \u2194 a < c * b :=\nby rw [\u2190 mul_lt_mul_iff_right b, inv_mul_cancel_right]\n\n@[simp, to_additive]\nlemma lt_mul_inv_iff_mul_lt : c < a * b\u207b\u00b9 \u2194 c * b < a :=\n(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right\n\n@[simp, to_additive]\nlemma inv_mul_lt_one_iff_lt : a * b\u207b\u00b9 < 1 \u2194 a < b :=\nby rw [\u2190 mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul]\n\n@[to_additive]\nlemma lt_mul_inv_iff_lt : 1 < a * b\u207b\u00b9 \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right]\n\n@[to_additive]\nlemma mul_inv_lt_one_iff : b * a\u207b\u00b9 < 1 \u2194 b < a :=\ntrans (mul_inv_lt_iff_lt_mul) $ by rw one_mul\n\nend typeclasses_right_lt\n\nsection typeclasses_left_right_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)]\n {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma inv_le_inv_iff : a\u207b\u00b9 \u2264 b\u207b\u00b9 \u2194 b \u2264 a :=\nby { rw [\u2190 mul_le_mul_iff_left a, \u2190 mul_le_mul_iff_right b], simp }\n\nalias neg_le_neg_iff \u2194 le_of_neg_le_neg _\n\nsection\n\nvariable (\u03b1)\n\n\/-- `x \u21a6 x\u207b\u00b9` as an order-reversing equivalence. -\/\n@[to_additive \"`x \u21a6 -x` as an order-reversing equivalence.\", simps]\ndef order_iso.inv : \u03b1 \u2243o order_dual \u03b1 :=\n{ to_equiv := (equiv.inv \u03b1).trans order_dual.to_dual,\n map_rel_iff' := \u03bb a b, @inv_le_inv_iff \u03b1 _ _ _ _ _ _ }\n\nend\n\n@[to_additive neg_le]\nlemma inv_le' : a\u207b\u00b9 \u2264 b \u2194 b\u207b\u00b9 \u2264 a :=\n(order_iso.inv \u03b1).symm_apply_le\n\nalias inv_le' \u2194 inv_le_of_inv_le' _\nattribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le'\n\n@[to_additive le_neg]\nlemma le_inv' : a \u2264 b\u207b\u00b9 \u2194 b \u2264 a\u207b\u00b9 :=\n(order_iso.inv \u03b1).le_symm_apply\n\n@[to_additive]\nlemma mul_inv_le_inv_mul_iff : a * b\u207b\u00b9 \u2264 d\u207b\u00b9 * c \u2194 d * a \u2264 c * b :=\nby rw [\u2190 mul_le_mul_iff_left d, \u2190 mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc,\n inv_mul_cancel_right]\n\n@[simp, to_additive] lemma div_le_self_iff (a : \u03b1) {b : \u03b1} : a \/ b \u2264 a \u2194 1 \u2264 b :=\nby simp [div_eq_mul_inv]\n\n@[simp, to_additive] lemma le_div_self_iff (a : \u03b1) {b : \u03b1} : a \u2264 a \/ b \u2194 b \u2264 1 :=\nby simp [div_eq_mul_inv]\n\nalias sub_le_self_iff \u2194 _ sub_le_self\n\nend typeclasses_left_right_le\n\nsection typeclasses_left_right_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)]\n {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma inv_lt_inv_iff : a\u207b\u00b9 < b\u207b\u00b9 \u2194 b < a :=\nby { rw [\u2190 mul_lt_mul_iff_left a, \u2190 mul_lt_mul_iff_right b], simp }\n\n@[to_additive neg_lt]\nlemma inv_lt' : a\u207b\u00b9 < b \u2194 b\u207b\u00b9 < a :=\nby rw [\u2190 inv_lt_inv_iff, inv_inv]\n\n@[to_additive lt_neg]\nlemma lt_inv' : a < b\u207b\u00b9 \u2194 b < a\u207b\u00b9 :=\nby rw [\u2190 inv_lt_inv_iff, inv_inv]\n\nalias lt_inv' \u2194 lt_inv_of_lt_inv _\nattribute [to_additive] lt_inv_of_lt_inv\n\nalias inv_lt' \u2194 inv_lt_of_inv_lt' _\nattribute [to_additive neg_lt_of_neg_lt] inv_lt_of_inv_lt'\n\n@[to_additive]\nlemma mul_inv_lt_inv_mul_iff : a * b\u207b\u00b9 < d\u207b\u00b9 * c \u2194 d * a < c * b :=\nby rw [\u2190 mul_lt_mul_iff_left d, \u2190 mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc,\n inv_mul_cancel_right]\n\n@[simp, to_additive] lemma div_lt_self_iff (a : \u03b1) {b : \u03b1} : a \/ b < a \u2194 1 < b :=\nby simp [div_eq_mul_inv]\n\nalias sub_lt_self_iff \u2194 _ sub_lt_self\n\nend typeclasses_left_right_lt\n\nsection pre_order\nvariable [preorder \u03b1]\n\nsection left_le\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a : \u03b1}\n\n@[to_additive]\nlemma left.inv_le_self (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 a :=\nle_trans (left.inv_le_one_iff.mpr h) h\n\nalias left.neg_le_self \u2190 neg_le_self\n\n@[to_additive]\nlemma left.self_le_inv (h : a \u2264 1) : a \u2264 a\u207b\u00b9 :=\nle_trans h (left.one_le_inv_iff.mpr h)\n\nend left_le\n\nsection left_lt\nvariables [covariant_class \u03b1 \u03b1 (*) (<)] {a : \u03b1}\n\n@[to_additive]\nlemma left.inv_lt_self (h : 1 < a) : a\u207b\u00b9 < a :=\n(left.inv_lt_one_iff.mpr h).trans h\n\nalias left.neg_lt_self \u2190 neg_lt_self\n\n@[to_additive]\nlemma left.self_lt_inv (h : a < 1) : a < a\u207b\u00b9 :=\nlt_trans h (left.one_lt_inv_iff.mpr h)\n\nend left_lt\n\nsection right_le\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a : \u03b1}\n\n@[to_additive]\nlemma right.inv_le_self (h : 1 \u2264 a) : a\u207b\u00b9 \u2264 a :=\nle_trans (right.inv_le_one_iff.mpr h) h\n\n@[to_additive]\nlemma right.self_le_inv (h : a \u2264 1) : a \u2264 a\u207b\u00b9 :=\nle_trans h (right.one_le_inv_iff.mpr h)\n\nend right_le\n\nsection right_lt\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a : \u03b1}\n\n@[to_additive]\nlemma right.inv_lt_self (h : 1 < a) : a\u207b\u00b9 < a :=\n(right.inv_lt_one_iff.mpr h).trans h\n\n@[to_additive]\nlemma right.self_lt_inv (h : a < 1) : a < a\u207b\u00b9 :=\nlt_trans h (right.one_lt_inv_iff.mpr h)\n\nend right_lt\n\nend pre_order\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive]\nlemma inv_mul_le_iff_le_mul' : c\u207b\u00b9 * a \u2264 b \u2194 a \u2264 b * c :=\nby rw [inv_mul_le_iff_le_mul, mul_comm]\n\n@[simp, to_additive]\nlemma mul_inv_le_iff_le_mul' : a * b\u207b\u00b9 \u2264 c \u2194 a \u2264 b * c :=\nby rw [\u2190 inv_mul_le_iff_le_mul, mul_comm]\n\n@[to_additive add_neg_le_add_neg_iff]\nlemma mul_inv_le_mul_inv_iff' : a * b\u207b\u00b9 \u2264 c * d\u207b\u00b9 \u2194 a * d \u2264 c * b :=\nby rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm]\n\nend has_le\n\nsection has_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive]\nlemma inv_mul_lt_iff_lt_mul' : c\u207b\u00b9 * a < b \u2194 a < b * c :=\nby rw [inv_mul_lt_iff_lt_mul, mul_comm]\n\n@[simp, to_additive]\nlemma mul_inv_lt_iff_le_mul' : a * b\u207b\u00b9 < c \u2194 a < b * c :=\nby rw [\u2190 inv_mul_lt_iff_lt_mul, mul_comm]\n\n@[to_additive add_neg_lt_add_neg_iff]\nlemma mul_inv_lt_mul_inv_iff' : a * b\u207b\u00b9 < c * d\u207b\u00b9 \u2194 a * d < c * b :=\nby rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm]\n\nend has_lt\n\nend comm_group\n\nalias le_inv' \u2194 le_inv_of_le_inv _\nattribute [to_additive] le_inv_of_le_inv\n\nalias left.inv_le_one_iff \u2194 one_le_of_inv_le_one _\nattribute [to_additive] one_le_of_inv_le_one\n\nalias left.one_le_inv_iff \u2194 le_one_of_one_le_inv _\nattribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv\n\nalias inv_lt_inv_iff \u2194 lt_of_inv_lt_inv _\nattribute [to_additive] lt_of_inv_lt_inv\n\nalias left.inv_lt_one_iff \u2194 one_lt_of_inv_lt_one _\nattribute [to_additive] one_lt_of_inv_lt_one\n\nalias left.inv_lt_one_iff \u2190 inv_lt_one_iff_one_lt\nattribute [to_additive] inv_lt_one_iff_one_lt\n\nalias left.inv_lt_one_iff \u2190 inv_lt_one'\nattribute [to_additive neg_lt_zero] inv_lt_one'\n\nalias left.one_lt_inv_iff \u2194 inv_of_one_lt_inv _\nattribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv\n\nalias left.one_lt_inv_iff \u2194 _ one_lt_inv_of_inv\nattribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv\n\nalias le_inv_mul_iff_mul_le \u2194 mul_le_of_le_inv_mul _\nattribute [to_additive] mul_le_of_le_inv_mul\n\nalias le_inv_mul_iff_mul_le \u2194 _ le_inv_mul_of_mul_le\nattribute [to_additive] le_inv_mul_of_mul_le\n\nalias inv_mul_le_iff_le_mul \u2194 _ inv_mul_le_of_le_mul\nattribute [to_additive] inv_mul_le_iff_le_mul\n\nalias lt_inv_mul_iff_mul_lt \u2194 mul_lt_of_lt_inv_mul _\nattribute [to_additive] mul_lt_of_lt_inv_mul\n\nalias lt_inv_mul_iff_mul_lt \u2194 _ lt_inv_mul_of_mul_lt\nattribute [to_additive] lt_inv_mul_of_mul_lt\n\nalias inv_mul_lt_iff_lt_mul \u2194 lt_mul_of_inv_mul_lt inv_mul_lt_of_lt_mul\nattribute [to_additive] lt_mul_of_inv_mul_lt\nattribute [to_additive] inv_mul_lt_of_lt_mul\n\nalias lt_mul_of_inv_mul_lt \u2190 lt_mul_of_inv_mul_lt_left\nattribute [to_additive] lt_mul_of_inv_mul_lt_left\n\nalias left.inv_le_one_iff \u2190 inv_le_one'\nattribute [to_additive neg_nonpos] inv_le_one'\n\nalias left.one_le_inv_iff \u2190 one_le_inv'\nattribute [to_additive neg_nonneg] one_le_inv'\n\nalias left.one_lt_inv_iff \u2190 one_lt_inv'\nattribute [to_additive neg_pos] one_lt_inv'\n\nalias mul_lt_mul_left' \u2190 ordered_comm_group.mul_lt_mul_left'\nattribute [to_additive ordered_add_comm_group.add_lt_add_left] ordered_comm_group.mul_lt_mul_left'\n\nalias le_of_mul_le_mul_left' \u2190 ordered_comm_group.le_of_mul_le_mul_left\nattribute [to_additive ordered_add_comm_group.le_of_add_le_add_left]\n ordered_comm_group.le_of_mul_le_mul_left\n\nalias lt_of_mul_lt_mul_left' \u2190 ordered_comm_group.lt_of_mul_lt_mul_left\nattribute [to_additive ordered_add_comm_group.lt_of_add_lt_add_left]\n ordered_comm_group.lt_of_mul_lt_mul_left\n\n\/-- Pullback an `ordered_comm_group` under an injective map.\nSee note [reducible non-instances]. -\/\n@[reducible, to_additive function.injective.ordered_add_comm_group\n\"Pullback an `ordered_add_comm_group` under an injective map.\"]\ndef function.injective.ordered_comm_group [ordered_comm_group \u03b1] {\u03b2 : Type*}\n [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2]\n (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n (mul : \u2200 x y, f (x * y) = f x * f y)\n (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n (div : \u2200 x y, f (x \/ y) = f x \/ f y) :\n ordered_comm_group \u03b2 :=\n{ ..partial_order.lift f hf,\n ..hf.ordered_comm_monoid f one mul,\n ..hf.comm_group f one mul inv div }\n\n\/- Most of the lemmas that are primed in this section appear in ordered_field. -\/\n\/- I (DT) did not try to minimise the assumptions. -\/\nsection group\nvariables [group \u03b1] [has_le \u03b1]\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma div_le_div_iff_right (c : \u03b1) : a \/ c \u2264 b \/ c \u2194 a \u2264 b :=\nby simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _\n\n@[to_additive sub_le_sub_right]\nlemma div_le_div_right' (h : a \u2264 b) (c : \u03b1) : a \/ c \u2264 b \/ c :=\n(div_le_div_iff_right c).2 h\n\n@[simp, to_additive sub_nonneg]\nlemma one_le_div' : 1 \u2264 a \/ b \u2194 b \u2264 a :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_nonneg \u2194 le_of_sub_nonneg sub_nonneg_of_le\n\n@[simp, to_additive sub_nonpos]\nlemma div_le_one' : a \/ b \u2264 1 \u2194 a \u2264 b :=\nby rw [\u2190 mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_nonpos \u2194 le_of_sub_nonpos sub_nonpos_of_le\n\n@[to_additive]\nlemma le_div_iff_mul_le : a \u2264 c \/ b \u2194 a * b \u2264 c :=\nby rw [\u2190 mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias le_sub_iff_add_le \u2194 add_le_of_le_sub_right le_sub_right_of_add_le\n\n@[to_additive]\nlemma div_le_iff_le_mul : a \/ c \u2264 b \u2194 a \u2264 b * c :=\nby rw [\u2190 mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]\n\n-- TODO: Should we get rid of `sub_le_iff_le_add` in favor of\n-- (a renamed version of) `tsub_le_iff_right`?\n@[priority 100] -- see Note [lower instance priority]\ninstance add_group.to_has_ordered_sub {\u03b1 : Type*} [add_group \u03b1] [has_le \u03b1]\n [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)] : has_ordered_sub \u03b1 :=\n\u27e8\u03bb a b c, sub_le_iff_le_add\u27e9\n\/-- `equiv.mul_right` as an `order_iso`. See also `order_embedding.mul_right`. -\/\n@[to_additive \"`equiv.add_right` as an `order_iso`. See also `order_embedding.add_right`.\",\n simps to_equiv apply {simp_rhs := tt}]\ndef order_iso.mul_right (a : \u03b1) : \u03b1 \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a }\n\n@[simp, to_additive] lemma order_iso.mul_right_symm (a : \u03b1) :\n (order_iso.mul_right a).symm = order_iso.mul_right a\u207b\u00b9 :=\nby { ext x, refl }\n\nend right\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n\n\/-- `equiv.mul_left` as an `order_iso`. See also `order_embedding.mul_left`. -\/\n@[to_additive \"`equiv.add_left` as an `order_iso`. See also `order_embedding.add_left`.\",\n simps to_equiv apply {simp_rhs := tt}]\ndef order_iso.mul_left (a : \u03b1) : \u03b1 \u2243o \u03b1 :=\n{ map_rel_iff' := \u03bb _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a }\n\n@[simp, to_additive] lemma order_iso.mul_left_symm (a : \u03b1) :\n (order_iso.mul_left a).symm = order_iso.mul_left a\u207b\u00b9 :=\nby { ext x, refl }\n\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] {a b c : \u03b1}\n\n@[simp, to_additive]\nlemma div_le_div_iff_left (a : \u03b1) : a \/ b \u2264 a \/ c \u2194 c \u2264 b :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 mul_le_mul_iff_left a\u207b\u00b9, inv_mul_cancel_left,\n inv_mul_cancel_left, inv_le_inv_iff]\n\n@[to_additive sub_le_sub_left]\nlemma div_le_div_left' (h : a \u2264 b) (c : \u03b1) : c \/ b \u2264 c \/ a :=\n(div_le_div_iff_left c).2 h\n\nend left\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_le\nvariables [has_le \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive sub_le_sub_iff]\nlemma div_le_div_iff' : a \/ b \u2264 c \/ d \u2194 a * d \u2264 c * b :=\nby simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff'\n\n@[to_additive]\nlemma le_div_iff_mul_le' : b \u2264 c \/ a \u2194 a * b \u2264 c :=\nby rw [le_div_iff_mul_le, mul_comm]\n\nalias le_sub_iff_add_le' \u2194 add_le_of_le_sub_left le_sub_left_of_add_le\n\n@[to_additive]\nlemma div_le_iff_le_mul' : a \/ b \u2264 c \u2194 a \u2264 b * c :=\nby rw [div_le_iff_le_mul, mul_comm]\n\nalias sub_le_iff_le_add' \u2194 le_add_of_sub_left_le sub_left_le_of_le_add\n\n@[simp, to_additive]\nlemma inv_le_div_iff_le_mul : b\u207b\u00b9 \u2264 a \/ c \u2194 c \u2264 a * b :=\nle_div_iff_mul_le.trans inv_mul_le_iff_le_mul'\n\n@[to_additive]\nlemma inv_le_div_iff_le_mul' : a\u207b\u00b9 \u2264 b \/ c \u2194 c \u2264 a * b :=\nby rw [inv_le_div_iff_le_mul, mul_comm]\n\n@[to_additive sub_le]\nlemma div_le'' : a \/ b \u2264 c \u2194 a \/ c \u2264 b :=\ndiv_le_iff_le_mul'.trans div_le_iff_le_mul.symm\n\n@[to_additive le_sub]\nlemma le_div'' : a \u2264 b \/ c \u2194 c \u2264 b \/ a :=\nle_div_iff_mul_le'.trans le_div_iff_mul_le.symm\n\nend has_le\n\nsection preorder\nvariables [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)] {a b c d : \u03b1}\n\n@[to_additive sub_le_sub]\nlemma div_le_div'' (hab : a \u2264 b) (hcd : c \u2264 d) :\n a \/ d \u2264 b \/ c :=\nbegin\n rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm],\n exact mul_le_mul' hab hcd\nend\n\nend preorder\n\nend comm_group\n\n\/- Most of the lemmas that are primed in this section appear in ordered_field. -\/\n\/- I (DT) did not try to minimise the assumptions. -\/\nsection group\nvariables [group \u03b1] [has_lt \u03b1]\n\nsection right\nvariables [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c d : \u03b1}\n\n@[simp, to_additive]\nlemma div_lt_div_iff_right (c : \u03b1) : a \/ c < b \/ c \u2194 a < b :=\nby simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _\n\n@[to_additive sub_lt_sub_right]\nlemma div_lt_div_right' (h : a < b) (c : \u03b1) : a \/ c < b \/ c :=\n(div_lt_div_iff_right c).2 h\n\n@[simp, to_additive sub_pos]\nlemma one_lt_div' : 1 < a \/ b \u2194 b < a :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_pos \u2194 lt_of_sub_pos sub_pos_of_lt\n\n@[simp, to_additive sub_neg]\nlemma div_lt_one' : a \/ b < 1 \u2194 a < b :=\nby rw [\u2190 mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_neg \u2194 lt_of_sub_neg sub_neg_of_lt\n\nalias sub_neg \u2190 sub_lt_zero\n\n@[to_additive]\nlemma lt_div_iff_mul_lt : a < c \/ b \u2194 a * b < c :=\nby rw [\u2190 mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias lt_sub_iff_add_lt \u2194 add_lt_of_lt_sub_right lt_sub_right_of_add_lt\n\n@[to_additive]\nlemma div_lt_iff_lt_mul : a \/ c < b \u2194 a < b * c :=\nby rw [\u2190 mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]\n\nalias sub_lt_iff_lt_add \u2194 lt_add_of_sub_right_lt sub_right_lt_of_lt_add\n\nend right\n\nsection left\nvariables [covariant_class \u03b1 \u03b1 (*) (<)] [covariant_class \u03b1 \u03b1 (swap (*)) (<)] {a b c : \u03b1}\n\n@[simp, to_additive]\nlemma div_lt_div_iff_left (a : \u03b1) : a \/ b < a \/ c \u2194 c < b :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, \u2190 mul_lt_mul_iff_left a\u207b\u00b9, inv_mul_cancel_left,\n inv_mul_cancel_left, inv_lt_inv_iff]\n\n@[simp, to_additive]\nlemma inv_lt_div_iff_lt_mul : a\u207b\u00b9 < b \/ c \u2194 c < a * b :=\nby rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul]\n\n@[to_additive sub_lt_sub_left]\nlemma div_lt_div_left' (h : a < b) (c : \u03b1) : c \/ b < c \/ a :=\n(div_lt_div_iff_left c).2 h\n\nend left\n\nend group\n\nsection comm_group\nvariables [comm_group \u03b1]\n\nsection has_lt\nvariables [has_lt \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive sub_lt_sub_iff]\nlemma div_lt_div_iff' : a \/ b < c \/ d \u2194 a * d < c * b :=\nby simpa only [div_eq_mul_inv] using mul_inv_lt_mul_inv_iff'\n\n@[to_additive]\nlemma lt_div_iff_mul_lt' : b < c \/ a \u2194 a * b < c :=\nby rw [lt_div_iff_mul_lt, mul_comm]\n\nalias lt_sub_iff_add_lt' \u2194 add_lt_of_lt_sub_left lt_sub_left_of_add_lt\n\n@[to_additive]\nlemma div_lt_iff_lt_mul' : a \/ b < c \u2194 a < b * c :=\nby rw [div_lt_iff_lt_mul, mul_comm]\n\nalias sub_lt_iff_lt_add' \u2194 lt_add_of_sub_left_lt sub_left_lt_of_lt_add\n\n@[to_additive]\nlemma inv_lt_div_iff_lt_mul' : b\u207b\u00b9 < a \/ c \u2194 c < a * b :=\nlt_div_iff_mul_lt.trans inv_mul_lt_iff_lt_mul'\n\n@[to_additive sub_lt]\nlemma div_lt'' : a \/ b < c \u2194 a \/ c < b :=\ndiv_lt_iff_lt_mul'.trans div_lt_iff_lt_mul.symm\n\n@[to_additive lt_sub]\nlemma lt_div'' : a < b \/ c \u2194 c < b \/ a :=\nlt_div_iff_mul_lt'.trans lt_div_iff_mul_lt.symm\n\nend has_lt\n\nsection preorder\nvariables [preorder \u03b1] [covariant_class \u03b1 \u03b1 (*) (<)] {a b c d : \u03b1}\n\n@[to_additive sub_lt_sub]\nlemma div_lt_div'' (hab : a < b) (hcd : c < d) :\n a \/ d < b \/ c :=\nbegin\n rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_lt_inv_mul_iff, mul_comm],\n exact mul_lt_mul_of_lt_of_lt hab hcd\nend\n\nend preorder\n\nend comm_group\n\nsection linear_order\nvariables [group \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n\nsection variable_names\nvariables {a b c : \u03b1}\n\n@[to_additive]\nlemma le_of_forall_one_lt_lt_mul (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a < b * \u03b5) : a \u2264 b :=\nle_of_not_lt (\u03bb h\u2081, lt_irrefl a (by simpa using (h _ (lt_inv_mul_iff_lt.mpr h\u2081))))\n\n@[to_additive]\nlemma le_iff_forall_one_lt_lt_mul : a \u2264 b \u2194 \u2200 \u03b5, 1 < \u03b5 \u2192 a < b * \u03b5 :=\n\u27e8\u03bb h \u03b5, lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul\u27e9\n\n\/- I (DT) introduced this lemma to prove (the additive version `sub_le_sub_flip` of)\n`div_le_div_flip` below. Now I wonder what is the point of either of these lemmas... -\/\n@[to_additive]\nlemma div_le_inv_mul_iff [covariant_class \u03b1 \u03b1 (swap (*)) (\u2264)] :\n a \/ b \u2264 a\u207b\u00b9 * b \u2194 a \u2264 b :=\nbegin\n rw [div_eq_mul_inv, mul_inv_le_inv_mul_iff],\n exact \u27e8\u03bb h, not_lt.mp (\u03bb k, not_lt.mpr h (mul_lt_mul''' k k)), \u03bb h, mul_le_mul' h h\u27e9,\nend\n\n\/- What is the point of this lemma? See comment about `div_le_inv_mul_iff` above. -\/\n@[simp, to_additive]\nlemma div_le_div_flip {\u03b1 : Type*} [comm_group \u03b1] [linear_order \u03b1] [covariant_class \u03b1 \u03b1 (*) (\u2264)]\n {a b : \u03b1}:\n a \/ b \u2264 b \/ a \u2194 a \u2264 b :=\nbegin\n rw [div_eq_mul_inv b, mul_comm],\n exact div_le_inv_mul_iff,\nend\n\n@[simp, to_additive] lemma max_one_div_max_inv_one_eq_self (a : \u03b1) :\n max a 1 \/ max a\u207b\u00b9 1 = a :=\nby { rcases le_total a 1 with h|h; simp [h] }\n\nalias max_zero_sub_max_neg_zero_eq_self \u2190 max_zero_sub_eq_self\n\nend variable_names\n\nsection densely_ordered\nvariables [densely_ordered \u03b1] {a b c : \u03b1}\n\n@[to_additive]\nlemma le_of_forall_one_lt_le_mul (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a \u2264 b * \u03b5) : a \u2264 b :=\nle_of_forall_le_of_dense $ \u03bb c hc,\ncalc a \u2264 b * (b\u207b\u00b9 * c) : h _ (lt_inv_mul_iff_lt.mpr hc)\n ... = c : mul_inv_cancel_left b c\n\n@[to_additive]\nlemma le_of_forall_lt_one_mul_le (h : \u2200 \u03b5 < 1, a * \u03b5 \u2264 b) : a \u2264 b :=\n@le_of_forall_one_lt_le_mul (order_dual \u03b1) _ _ _ _ _ _ h\n\n@[to_additive]\nlemma le_of_forall_one_lt_div_le (h : \u2200 \u03b5 : \u03b1, 1 < \u03b5 \u2192 a \/ \u03b5 \u2264 b) : a \u2264 b :=\nle_of_forall_lt_one_mul_le $ \u03bb \u03b5 \u03b51,\n by simpa only [div_eq_mul_inv, inv_inv] using h \u03b5\u207b\u00b9 (left.one_lt_inv_iff.2 \u03b51)\n\n@[to_additive]\nlemma le_iff_forall_one_lt_le_mul : a \u2264 b \u2194 \u2200 \u03b5, 1 < \u03b5 \u2192 a \u2264 b * \u03b5 :=\n\u27e8\u03bb h \u03b5 \u03b5_pos, le_mul_of_le_of_one_le h \u03b5_pos.le, le_of_forall_one_lt_le_mul\u27e9\n\n@[to_additive]\nlemma le_iff_forall_lt_one_mul_le : a \u2264 b \u2194 \u2200 \u03b5 < 1, a * \u03b5 \u2264 b :=\n@le_iff_forall_one_lt_le_mul (order_dual \u03b1) _ _ _ _ _ _\n\nend densely_ordered\n\nend linear_order\n\n\/-!\n### Linearly ordered commutative groups\n-\/\n\n\/-- A linearly ordered additive commutative group is an\nadditive commutative group with a linear order in which\naddition is monotone. -\/\n@[protect_proj, ancestor ordered_add_comm_group linear_order]\nclass linear_ordered_add_comm_group (\u03b1 : Type u) extends ordered_add_comm_group \u03b1, linear_order \u03b1\n\n\/-- A linearly ordered commutative monoid with an additively absorbing `\u22a4` element.\n Instances should include number systems with an infinite element adjoined.` -\/\n@[protect_proj, ancestor linear_ordered_add_comm_monoid_with_top sub_neg_monoid nontrivial]\nclass linear_ordered_add_comm_group_with_top (\u03b1 : Type*)\n extends linear_ordered_add_comm_monoid_with_top \u03b1, sub_neg_monoid \u03b1, nontrivial \u03b1 :=\n(neg_top : - (\u22a4 : \u03b1) = \u22a4)\n(add_neg_cancel : \u2200 a:\u03b1, a \u2260 \u22a4 \u2192 a + (- a) = 0)\n\n\/-- A linearly ordered commutative group is a\ncommutative group with a linear order in which\nmultiplication is monotone. -\/\n@[protect_proj, ancestor ordered_comm_group linear_order, to_additive]\nclass linear_ordered_comm_group (\u03b1 : Type u) extends ordered_comm_group \u03b1, linear_order \u03b1\n\n@[to_additive] instance [linear_ordered_comm_group \u03b1] :\n linear_ordered_comm_group (order_dual \u03b1) :=\n{ .. order_dual.ordered_comm_group, .. order_dual.linear_order \u03b1 }\n\nsection linear_ordered_comm_group\nvariables [linear_ordered_comm_group \u03b1] {a b c : \u03b1}\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid :\n linear_ordered_cancel_comm_monoid \u03b1 :=\n{ le_of_mul_le_mul_left := \u03bb x y z, le_of_mul_le_mul_left',\n mul_left_cancel := \u03bb x y z, mul_left_cancel,\n ..\u2039linear_ordered_comm_group \u03b1\u203a }\n\n\/-- Pullback a `linear_ordered_comm_group` under an injective map.\nSee note [reducible non-instances]. -\/\n@[reducible, to_additive function.injective.linear_ordered_add_comm_group\n\"Pullback a `linear_ordered_add_comm_group` under an injective map.\"]\ndef function.injective.linear_ordered_comm_group {\u03b2 : Type*}\n [has_one \u03b2] [has_mul \u03b2] [has_inv \u03b2] [has_div \u03b2]\n (f : \u03b2 \u2192 \u03b1) (hf : function.injective f) (one : f 1 = 1)\n (mul : \u2200 x y, f (x * y) = f x * f y)\n (inv : \u2200 x, f (x\u207b\u00b9) = (f x)\u207b\u00b9)\n (div : \u2200 x y, f (x \/ y) = f x \/ f y) :\n linear_ordered_comm_group \u03b2 :=\n{ ..linear_order.lift f hf,\n ..hf.ordered_comm_group f one mul inv div }\n\n@[to_additive linear_ordered_add_comm_group.add_lt_add_left]\nlemma linear_ordered_comm_group.mul_lt_mul_left'\n (a b : \u03b1) (h : a < b) (c : \u03b1) : c * a < c * b :=\nmul_lt_mul_left' h c\n\n@[to_additive min_neg_neg]\nlemma min_inv_inv' (a b : \u03b1) : min (a\u207b\u00b9) (b\u207b\u00b9) = (max a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_max \u03b1 (order_dual \u03b1) _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv_iff.mpr\n\n@[to_additive max_neg_neg]\nlemma max_inv_inv' (a b : \u03b1) : max (a\u207b\u00b9) (b\u207b\u00b9) = (min a b)\u207b\u00b9 :=\neq.symm $ @monotone.map_min \u03b1 (order_dual \u03b1) _ _ has_inv.inv a b $ \u03bb a b, inv_le_inv_iff.mpr\n\n@[to_additive min_sub_sub_right]\nlemma min_div_div_right' (a b c : \u03b1) : min (a \/ c) (b \/ c) = min a b \/ c :=\nby simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive max_sub_sub_right]\nlemma max_div_div_right' (a b c : \u03b1) : max (a \/ c) (b \/ c) = max a b \/ c :=\nby simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c\u207b\u00b9)\n\n@[to_additive min_sub_sub_left]\nlemma min_div_div_left' (a b c : \u03b1) : min (a \/ b) (a \/ c) = a \/ max b c :=\nby simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']\n\n@[to_additive max_sub_sub_left]\nlemma max_div_div_left' (a b c : \u03b1) : max (a \/ b) (a \/ c) = a \/ min b c :=\nby simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']\n\n@[to_additive eq_zero_of_neg_eq]\nlemma eq_one_of_inv_eq' (h : a\u207b\u00b9 = a) : a = 1 :=\nmatch lt_trichotomy a 1 with\n| or.inl h\u2081 :=\n have 1 < a, from h \u25b8 one_lt_inv_of_inv h\u2081,\n absurd h\u2081 this.asymm\n| or.inr (or.inl h\u2081) := h\u2081\n| or.inr (or.inr h\u2081) :=\n have a < 1, from h \u25b8 inv_lt_one'.mpr h\u2081,\n absurd h\u2081 this.asymm\nend\n\n@[to_additive exists_zero_lt]\nlemma exists_one_lt' [nontrivial \u03b1] : \u2203 (a:\u03b1), 1 < a :=\nbegin\n obtain \u27e8y, hy\u27e9 := decidable.exists_ne (1 : \u03b1),\n cases hy.lt_or_lt,\n { exact \u27e8y\u207b\u00b9, one_lt_inv'.mpr h\u27e9 },\n { exact \u27e8y, h\u27e9 }\nend\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_max_order [nontrivial \u03b1] :\n no_max_order \u03b1 :=\n\u27e8 begin\n obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n exact \u03bb a, \u27e8a * y, lt_mul_of_one_lt_right' a hy\u27e9\n end \u27e9\n\n@[priority 100, to_additive] -- see Note [lower instance priority]\ninstance linear_ordered_comm_group.to_no_min_order [nontrivial \u03b1] : no_min_order \u03b1 :=\n\u27e8 begin\n obtain \u27e8y, hy\u27e9 : \u2203 (a:\u03b1), 1 < a := exists_one_lt',\n exact \u03bb a, \u27e8a \/ y, (div_lt_self_iff a).mpr hy\u27e9\n end \u27e9\n\nend linear_ordered_comm_group\n\nsection covariant_add_le\n\nsection has_neg\n\n\/-- `abs a` is the absolute value of `a`. -\/\n@[to_additive, priority 100] -- see Note [lower instance priority]\ninstance has_inv_lattice_has_abs [has_inv \u03b1] [lattice \u03b1] : has_abs (\u03b1) := \u27e8\u03bba, a \u2294 (a\u207b\u00b9)\u27e9\n\n@[to_additive]\nlemma abs_eq_sup_inv [has_inv \u03b1] [lattice \u03b1] (a : \u03b1) : |a| = a \u2294 a\u207b\u00b9 :=\nrfl\n\nvariables [has_neg \u03b1] [linear_order \u03b1] {a b: \u03b1}\n\nlemma abs_eq_max_neg : abs a = max a (-a) :=\nrfl\n\nlemma abs_choice (x : \u03b1) : |x| = x \u2228 |x| = -x := max_choice _ _\n\nlemma abs_le' : |a| \u2264 b \u2194 a \u2264 b \u2227 -a \u2264 b := max_le_iff\n\nlemma le_abs : a \u2264 |b| \u2194 a \u2264 b \u2228 a \u2264 -b := le_max_iff\n\nlemma le_abs_self (a : \u03b1) : a \u2264 |a| := le_max_left _ _\n\nlemma neg_le_abs_self (a : \u03b1) : -a \u2264 |a| := le_max_right _ _\n\nlemma lt_abs : a < |b| \u2194 a < b \u2228 a < -b := lt_max_iff\n\ntheorem abs_le_abs (h\u2080 : a \u2264 b) (h\u2081 : -a \u2264 b) : |a| \u2264 |b| :=\n(abs_le'.2 \u27e8h\u2080, h\u2081\u27e9).trans (le_abs_self b)\n\nlemma abs_by_cases (P : \u03b1 \u2192 Prop) {a : \u03b1} (h1 : P a) (h2 : P (-a)) : P (|a|) :=\nsup_ind _ _ h1 h2\n\nend has_neg\n\nsection add_group\nvariables [add_group \u03b1] [linear_order \u03b1]\n\n@[simp] lemma abs_neg (a : \u03b1) : | -a| = |a| :=\nbegin\n rw [abs_eq_max_neg, max_comm, neg_neg, abs_eq_max_neg]\nend\n\nlemma eq_or_eq_neg_of_abs_eq {a b : \u03b1} (h : |a| = b) : a = b \u2228 a = -b :=\nby simpa only [\u2190 h, eq_comm, eq_neg_iff_eq_neg] using abs_choice a\n\nlemma abs_eq_abs {a b : \u03b1} : |a| = |b| \u2194 a = b \u2228 a = -b :=\nbegin\n refine \u27e8\u03bb h, _, \u03bb h, _\u27e9,\n { obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h;\n simpa only [neg_eq_iff_neg_eq, neg_inj, or.comm, @eq_comm _ (-b)] using abs_choice b },\n { cases h; simp only [h, abs_neg] },\nend\n\nlemma abs_sub_comm (a b : \u03b1) : |a - b| = |b - a| :=\ncalc |a - b| = | - (b - a)| : congr_arg _ (neg_sub b a).symm\n ... = |b - a| : abs_neg (b - a)\n\nvariables [covariant_class \u03b1 \u03b1 (+) (\u2264)] {a b c : \u03b1}\n\nlemma abs_of_nonneg (h : 0 \u2264 a) : |a| = a :=\nmax_eq_left $ (neg_nonpos.2 h).trans h\n\nlemma abs_of_pos (h : 0 < a) : |a| = a :=\nabs_of_nonneg h.le\n\nlemma abs_of_nonpos (h : a \u2264 0) : |a| = -a :=\nmax_eq_right $ h.trans (neg_nonneg.2 h)\n\nlemma abs_of_neg (h : a < 0) : |a| = -a :=\nabs_of_nonpos h.le\n\n@[simp] lemma abs_zero : |0| = (0:\u03b1) :=\nabs_of_nonneg le_rfl\n\n@[simp] lemma abs_pos : 0 < |a| \u2194 a \u2260 0 :=\nbegin\n rcases lt_trichotomy a 0 with (ha|rfl|ha),\n { simp [abs_of_neg ha, neg_pos, ha.ne, ha] },\n { simp },\n { simp [abs_of_pos ha, ha, ha.ne.symm] }\nend\n\nlemma abs_pos_of_pos (h : 0 < a) : 0 < |a| := abs_pos.2 h.ne.symm\n\nlemma abs_pos_of_neg (h : a < 0) : 0 < |a| := abs_pos.2 h.ne\n\nlemma neg_abs_le_self (a : \u03b1) : -|a| \u2264 a :=\nbegin\n cases le_total 0 a with h h,\n { calc -|a| = - a : congr_arg (has_neg.neg) (abs_of_nonneg h)\n ... \u2264 0 : neg_nonpos.mpr h\n ... \u2264 a : h },\n { calc -|a| = - - a : congr_arg (has_neg.neg) (abs_of_nonpos h)\n ... \u2264 a : (neg_neg a).le }\nend\n\nlemma abs_nonneg (a : \u03b1) : 0 \u2264 |a| :=\n(le_total 0 a).elim (\u03bb h, h.trans (le_abs_self a)) (\u03bb h, (neg_nonneg.2 h).trans $ neg_le_abs_self a)\n\n@[simp] lemma abs_abs (a : \u03b1) : | |a| | = |a| :=\nabs_of_nonneg $ abs_nonneg a\n\n@[simp] lemma abs_eq_zero : |a| = 0 \u2194 a = 0 :=\ndecidable.not_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos\n\n@[simp] lemma abs_nonpos_iff {a : \u03b1} : |a| \u2264 0 \u2194 a = 0 :=\n(abs_nonneg a).le_iff_eq.trans abs_eq_zero\n\nvariable [covariant_class \u03b1 \u03b1 (swap (+)) (\u2264)]\n\nlemma abs_lt : |a| < b \u2194 - b < a \u2227 a < b :=\nmax_lt_iff.trans $ and.comm.trans $ by rw [neg_lt]\n\nlemma neg_lt_of_abs_lt (h : |a| < b) : -b < a := (abs_lt.mp h).1\n\nlemma lt_of_abs_lt (h : |a| < b) : a < b := (abs_lt.mp h).2\n\nlemma max_sub_min_eq_abs' (a b : \u03b1) : max a b - min a b = |a - b| :=\nbegin\n cases le_total a b with ab ba,\n { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos },\n { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg }\nend\n\nlemma max_sub_min_eq_abs (a b : \u03b1) : max a b - min a b = |b - a| :=\nby { rw abs_sub_comm, exact max_sub_min_eq_abs' _ _ }\n\nend add_group\n\nend covariant_add_le\n\nsection linear_ordered_add_comm_group\n\nvariables [linear_ordered_add_comm_group \u03b1] {a b c d : \u03b1}\n\nlemma abs_le : |a| \u2264 b \u2194 - b \u2264 a \u2227 a \u2264 b := by rw [abs_le', and.comm, neg_le]\n\nlemma le_abs' : a \u2264 |b| \u2194 b \u2264 -a \u2228 a \u2264 b := by rw [le_abs, or.comm, le_neg]\n\nlemma neg_le_of_abs_le (h : |a| \u2264 b) : -b \u2264 a := (abs_le.mp h).1\n\nlemma le_of_abs_le (h : |a| \u2264 b) : a \u2264 b := (abs_le.mp h).2\n\n\/--\nThe **triangle inequality** in `linear_ordered_add_comm_group`s.\n-\/\nlemma abs_add (a b : \u03b1) : |a + b| \u2264 |a| + |b| :=\nabs_le.2 \u27e8(neg_add (|a|) (|b|)).symm \u25b8\n add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _),\n add_le_add (le_abs_self _) (le_abs_self _)\u27e9\n\ntheorem abs_sub (a b : \u03b1) :\n |a - b| \u2264 |a| + |b| :=\nby { rw [sub_eq_add_neg, \u2190abs_neg b], exact abs_add a _ }\n\nlemma abs_sub_le_iff : |a - b| \u2264 c \u2194 a - b \u2264 c \u2227 b - a \u2264 c :=\nby rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']\n\nlemma abs_sub_lt_iff : |a - b| < c \u2194 a - b < c \u2227 b - a < c :=\nby rw [abs_lt, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']\n\nlemma sub_le_of_abs_sub_le_left (h : |a - b| \u2264 c) : b - c \u2264 a :=\nsub_le.1 $ (abs_sub_le_iff.1 h).2\n\nlemma sub_le_of_abs_sub_le_right (h : |a - b| \u2264 c) : a - c \u2264 b :=\nsub_le_of_abs_sub_le_left (abs_sub_comm a b \u25b8 h)\n\nlemma sub_lt_of_abs_sub_lt_left (h : |a - b| < c) : b - c < a :=\nsub_lt.1 $ (abs_sub_lt_iff.1 h).2\n\nlemma sub_lt_of_abs_sub_lt_right (h : |a - b| < c) : a - c < b :=\nsub_lt_of_abs_sub_lt_left (abs_sub_comm a b \u25b8 h)\n\nlemma abs_sub_abs_le_abs_sub (a b : \u03b1) : |a| - |b| \u2264 |a - b| :=\nsub_le_iff_le_add.2 $\ncalc |a| = |a - b + b| : by rw [sub_add_cancel]\n ... \u2264 |a - b| + |b| : abs_add _ _\n\nlemma abs_abs_sub_abs_le_abs_sub (a b : \u03b1) : | |a| - |b| | \u2264 |a - b| :=\nabs_sub_le_iff.2 \u27e8abs_sub_abs_le_abs_sub _ _, by rw abs_sub_comm; apply abs_sub_abs_le_abs_sub\u27e9\n\nlemma abs_eq (hb : 0 \u2264 b) : |a| = b \u2194 a = b \u2228 a = -b :=\nbegin\n refine \u27e8eq_or_eq_neg_of_abs_eq, _\u27e9,\n rintro (rfl|rfl); simp only [abs_neg, abs_of_nonneg hb]\nend\n\nlemma abs_le_max_abs_abs (hab : a \u2264 b) (hbc : b \u2264 c) : |b| \u2264 max (|a|) (|c|) :=\nabs_le'.2\n \u27e8by simp [hbc.trans (le_abs_self c)],\n by simp [(neg_le_neg_iff.mpr hab).trans (neg_le_abs_self a)]\u27e9\n\nlemma eq_of_abs_sub_eq_zero {a b : \u03b1} (h : |a - b| = 0) : a = b :=\nsub_eq_zero.1 $ abs_eq_zero.1 h\n\nlemma abs_sub_le (a b c : \u03b1) : |a - c| \u2264 |a - b| + |b - c| :=\ncalc\n |a - c| = |a - b + (b - c)| : by rw [sub_add_sub_cancel]\n ... \u2264 |a - b| + |b - c| : abs_add _ _\n\nlemma abs_add_three (a b c : \u03b1) : |a + b + c| \u2264 |a| + |b| + |c| :=\n(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)\n\nlemma dist_bdd_within_interval {a b lb ub : \u03b1} (hal : lb \u2264 a) (hau : a \u2264 ub)\n (hbl : lb \u2264 b) (hbu : b \u2264 ub) : |a - b| \u2264 ub - lb :=\nabs_sub_le_iff.2 \u27e8sub_le_sub hau hbl, sub_le_sub hbu hal\u27e9\n\nlemma eq_of_abs_sub_nonpos (h : |a - b| \u2264 0) : a = b :=\neq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))\n\nlemma max_sub_max_le_max (a b c d : \u03b1) : max a b - max c d \u2264 max (a - c) (b - d) :=\nbegin\n simp only [sub_le_iff_le_add, max_le_iff], split,\n calc a = a - c + c : (sub_add_cancel a c).symm\n ... \u2264 max (a - c) (b - d) + max c d : add_le_add (le_max_left _ _) (le_max_left _ _),\n calc b = b - d + d : (sub_add_cancel b d).symm\n ... \u2264 max (a - c) (b - d) + max c d : add_le_add (le_max_right _ _) (le_max_right _ _)\nend\n\nlemma abs_max_sub_max_le_max (a b c d : \u03b1) : |max a b - max c d| \u2264 max (|a - c|) (|b - d|) :=\nbegin\n refine abs_sub_le_iff.2 \u27e8_, _\u27e9,\n { exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _)) },\n { rw [abs_sub_comm a c, abs_sub_comm b d],\n exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _)) }\nend\n\nlemma abs_min_sub_min_le_max (a b c d : \u03b1) : |min a b - min c d| \u2264 max (|a - c|) (|b - d|) :=\nby simpa only [max_neg_neg, neg_sub_neg, abs_sub_comm]\n using abs_max_sub_max_le_max (-a) (-b) (-c) (-d)\n\nlemma abs_max_sub_max_le_abs (a b c : \u03b1) : |max a c - max b c| \u2264 |a - b| :=\nby simpa only [sub_self, abs_zero, max_eq_left (abs_nonneg _)]\n using abs_max_sub_max_le_max a c b c\n\ninstance with_top.linear_ordered_add_comm_group_with_top :\n linear_ordered_add_comm_group_with_top (with_top \u03b1) :=\n{ neg := option.map (\u03bb a : \u03b1, -a),\n neg_top := @option.map_none _ _ (\u03bb a : \u03b1, -a),\n add_neg_cancel := begin\n rintro (a | a) ha,\n { exact (ha rfl).elim },\n { exact with_top.coe_add.symm.trans (with_top.coe_eq_coe.2 (add_neg_self a)) }\n end,\n .. with_top.linear_ordered_add_comm_monoid_with_top,\n .. option.nontrivial }\n\n@[simp, norm_cast]\nlemma with_top.coe_neg (a : \u03b1) : ((-a : \u03b1) : with_top \u03b1) = -a := rfl\n\nend linear_ordered_add_comm_group\n\nnamespace add_comm_group\n\n\/-- A collection of elements in an `add_comm_group` designated as \"non-negative\".\nThis is useful for constructing an `ordered_add_commm_group`\nby choosing a positive cone in an exisiting `add_comm_group`. -\/\n@[nolint has_inhabited_instance]\nstructure positive_cone (\u03b1 : Type*) [add_comm_group \u03b1] :=\n(nonneg : \u03b1 \u2192 Prop)\n(pos : \u03b1 \u2192 Prop := \u03bb a, nonneg a \u2227 \u00ac nonneg (-a))\n(pos_iff : \u2200 a, pos a \u2194 nonneg a \u2227 \u00ac nonneg (-a) . order_laws_tac)\n(zero_nonneg : nonneg 0)\n(add_nonneg : \u2200 {a b}, nonneg a \u2192 nonneg b \u2192 nonneg (a + b))\n(nonneg_antisymm : \u2200 {a}, nonneg a \u2192 nonneg (-a) \u2192 a = 0)\n\n\/-- A positive cone in an `add_comm_group` induces a linear order if\nfor every `a`, either `a` or `-a` is non-negative. -\/\n@[nolint has_inhabited_instance]\nstructure total_positive_cone (\u03b1 : Type*) [add_comm_group \u03b1] extends positive_cone \u03b1 :=\n(nonneg_decidable : decidable_pred nonneg)\n(nonneg_total : \u2200 a : \u03b1, nonneg a \u2228 nonneg (-a))\n\n\/-- Forget that a `total_positive_cone` is total. -\/\nadd_decl_doc total_positive_cone.to_positive_cone\n\nend add_comm_group\n\nnamespace ordered_add_comm_group\n\nopen add_comm_group\n\n\/-- Construct an `ordered_add_comm_group` by\ndesignating a positive cone in an existing `add_comm_group`. -\/\ndef mk_of_positive_cone {\u03b1 : Type*} [add_comm_group \u03b1] (C : positive_cone \u03b1) :\n ordered_add_comm_group \u03b1 :=\n{ le := \u03bb a b, C.nonneg (b - a),\n lt := \u03bb a b, C.pos (b - a),\n lt_iff_le_not_le := \u03bb a b, by simp; rw [C.pos_iff]; simp,\n le_refl := \u03bb a, by simp [C.zero_nonneg],\n le_trans := \u03bb a b c nab nbc, by simp [-sub_eq_add_neg];\n rw \u2190 sub_add_sub_cancel; exact C.add_nonneg nbc nab,\n le_antisymm := \u03bb a b nab nba, eq_of_sub_eq_zero $\n C.nonneg_antisymm nba (by rw neg_sub; exact nab),\n add_le_add_left := \u03bb a b nab c, by simpa [(\u2264), preorder.le] using nab,\n ..\u2039add_comm_group \u03b1\u203a }\n\nend ordered_add_comm_group\n\nnamespace linear_ordered_add_comm_group\n\nopen add_comm_group\n\n\/-- Construct a `linear_ordered_add_comm_group` by\ndesignating a positive cone in an existing `add_comm_group`\nsuch that for every `a`, either `a` or `-a` is non-negative. -\/\ndef mk_of_positive_cone {\u03b1 : Type*} [add_comm_group \u03b1] (C : total_positive_cone \u03b1) :\n linear_ordered_add_comm_group \u03b1 :=\n{ le_total := \u03bb a b, by { convert C.nonneg_total (b - a), change C.nonneg _ = _, congr, simp, },\n decidable_le := \u03bb a b, C.nonneg_decidable _,\n ..ordered_add_comm_group.mk_of_positive_cone C.to_positive_cone }\n\nend linear_ordered_add_comm_group\n\nnamespace prod\n\nvariables {G H : Type*}\n\n@[to_additive]\ninstance [ordered_comm_group G] [ordered_comm_group H] :\n ordered_comm_group (G \u00d7 H) :=\n{ .. prod.comm_group, .. prod.partial_order G H, .. prod.ordered_cancel_comm_monoid }\n\nend prod\n\nsection type_tags\n\ninstance [ordered_add_comm_group \u03b1] : ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.comm_group,\n ..multiplicative.ordered_comm_monoid }\n\ninstance [ordered_comm_group \u03b1] : ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.add_comm_group,\n ..additive.ordered_add_comm_monoid }\n\ninstance [linear_ordered_add_comm_group \u03b1] : linear_ordered_comm_group (multiplicative \u03b1) :=\n{ ..multiplicative.linear_order,\n ..multiplicative.ordered_comm_group }\n\ninstance [linear_ordered_comm_group \u03b1] : linear_ordered_add_comm_group (additive \u03b1) :=\n{ ..additive.linear_order,\n ..additive.ordered_add_comm_group }\n\nend type_tags\n\nsection norm_num_lemmas\n\/- The following lemmas are stated so that the `norm_num` tactic can use them with the\nexpected signatures. -\/\nvariables [ordered_comm_group \u03b1] {a b : \u03b1}\n\n@[to_additive neg_le_neg]\nlemma inv_le_inv' : a \u2264 b \u2192 b\u207b\u00b9 \u2264 a\u207b\u00b9 :=\ninv_le_inv_iff.mpr\n\n@[to_additive neg_lt_neg]\nlemma inv_lt_inv' : a < b \u2192 b\u207b\u00b9 < a\u207b\u00b9 :=\ninv_lt_inv_iff.mpr\n\n\/- The additive version is also a `linarith` lemma. -\/\n@[to_additive]\ntheorem inv_lt_one_of_one_lt : 1 < a \u2192 a\u207b\u00b9 < 1 :=\ninv_lt_one_iff_one_lt.mpr\n\n\/- The additive version is also a `linarith` lemma. -\/\n@[to_additive]\nlemma inv_le_one_of_one_le : 1 \u2264 a \u2192 a\u207b\u00b9 \u2264 1 :=\ninv_le_one'.mpr\n\n@[to_additive neg_nonneg_of_nonpos]\nlemma one_le_inv_of_le_one : a \u2264 1 \u2192 1 \u2264 a\u207b\u00b9 :=\none_le_inv'.mpr\n\nend norm_num_lemmas\n","avg_line_length":33.1639824305,"max_line_length":100,"alphanum_fraction":0.6895059821} -{"size":10854,"ext":"lean","lang":"Lean","max_stars_count":1131.0,"content":"\/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n\nComputational realization of filters (experimental).\n-\/\nimport order.filter.cofinite\nopen set filter\n\n\/-- A `cfilter \u03b1 \u03c3` is a realization of a filter (base) on `\u03b1`,\n represented by a type `\u03c3` together with operations for the top element and\n the binary inf operation. -\/\nstructure cfilter (\u03b1 \u03c3 : Type*) [partial_order \u03b1] :=\n(f : \u03c3 \u2192 \u03b1)\n(pt : \u03c3)\n(inf : \u03c3 \u2192 \u03c3 \u2192 \u03c3)\n(inf_le_left : \u2200 a b : \u03c3, f (inf a b) \u2264 f a)\n(inf_le_right : \u2200 a b : \u03c3, f (inf a b) \u2264 f b)\n\nvariables {\u03b1 : Type*} {\u03b2 : Type*} {\u03c3 : Type*} {\u03c4 : Type*}\n\nnamespace cfilter\nsection\nvariables [partial_order \u03b1] (F : cfilter \u03b1 \u03c3)\n\ninstance : has_coe_to_fun (cfilter \u03b1 \u03c3) := \u27e8_, cfilter.f\u27e9\n\n@[simp] theorem coe_mk (f pt inf h\u2081 h\u2082 a) : (@cfilter.mk \u03b1 \u03c3 _ f pt inf h\u2081 h\u2082) a = f a := rfl\n\n\/-- Map a cfilter to an equivalent representation type. -\/\ndef of_equiv (E : \u03c3 \u2243 \u03c4) : cfilter \u03b1 \u03c3 \u2192 cfilter \u03b1 \u03c4\n| \u27e8f, p, g, h\u2081, h\u2082\u27e9 :=\n { f := \u03bb a, f (E.symm a),\n pt := E p,\n inf := \u03bb a b, E (g (E.symm a) (E.symm b)),\n inf_le_left := \u03bb a b, by simpa using h\u2081 (E.symm a) (E.symm b),\n inf_le_right := \u03bb a b, by simpa using h\u2082 (E.symm a) (E.symm b) }\n\n@[simp] theorem of_equiv_val (E : \u03c3 \u2243 \u03c4) (F : cfilter \u03b1 \u03c3) (a : \u03c4) :\n F.of_equiv E a = F (E.symm a) := by cases F; refl\n\nend\n\n\/-- The filter represented by a `cfilter` is the collection of supersets of\n elements of the filter base. -\/\ndef to_filter (F : cfilter (set \u03b1) \u03c3) : filter \u03b1 :=\n{ sets := {a | \u2203 b, F b \u2286 a},\n univ_sets := \u27e8F.pt, subset_univ _\u27e9,\n sets_of_superset := \u03bb x y \u27e8b, h\u27e9 s, \u27e8b, subset.trans h s\u27e9,\n inter_sets := \u03bb x y \u27e8a, h\u2081\u27e9 \u27e8b, h\u2082\u27e9, \u27e8F.inf a b,\n subset_inter (subset.trans (F.inf_le_left _ _) h\u2081) (subset.trans (F.inf_le_right _ _) h\u2082)\u27e9 }\n\n@[simp] theorem mem_to_filter_sets (F : cfilter (set \u03b1) \u03c3) {a : set \u03b1} :\n a \u2208 F.to_filter \u2194 \u2203 b, F b \u2286 a := iff.rfl\n\nend cfilter\n\n\/-- A realizer for filter `f` is a cfilter which generates `f`. -\/\nstructure filter.realizer (f : filter \u03b1) :=\n(\u03c3 : Type*)\n(F : cfilter (set \u03b1) \u03c3)\n(eq : F.to_filter = f)\n\nprotected def cfilter.to_realizer (F : cfilter (set \u03b1) \u03c3) : F.to_filter.realizer := \u27e8\u03c3, F, rfl\u27e9\n\nnamespace filter.realizer\n\ntheorem mem_sets {f : filter \u03b1} (F : f.realizer) {a : set \u03b1} : a \u2208 f \u2194 \u2203 b, F.F b \u2286 a :=\nby cases F; subst f; simp\n\n-- Used because it has better definitional equalities than the eq.rec proof\ndef of_eq {f g : filter \u03b1} (e : f = g) (F : f.realizer) : g.realizer :=\n\u27e8F.\u03c3, F.F, F.eq.trans e\u27e9\n\n\/-- A filter realizes itself. -\/\ndef of_filter (f : filter \u03b1) : f.realizer := \u27e8f.sets,\n{ f := subtype.val,\n pt := \u27e8univ, univ_mem\u27e9,\n inf := \u03bb \u27e8x, h\u2081\u27e9 \u27e8y, h\u2082\u27e9, \u27e8_, inter_mem h\u2081 h\u2082\u27e9,\n inf_le_left := \u03bb \u27e8x, h\u2081\u27e9 \u27e8y, h\u2082\u27e9, inter_subset_left x y,\n inf_le_right := \u03bb \u27e8x, h\u2081\u27e9 \u27e8y, h\u2082\u27e9, inter_subset_right x y },\nfilter_eq $ set.ext $ \u03bb x, set_coe.exists.trans exists_mem_subset_iff\u27e9\n\n\/-- Transfer a filter realizer to another realizer on a different base type. -\/\ndef of_equiv {f : filter \u03b1} (F : f.realizer) (E : F.\u03c3 \u2243 \u03c4) : f.realizer :=\n\u27e8\u03c4, F.F.of_equiv E, by refine eq.trans _ F.eq; exact filter_eq (set.ext $ \u03bb x,\n\u27e8\u03bb \u27e8s, h\u27e9, \u27e8E.symm s, by simpa using h\u27e9, \u03bb \u27e8t, h\u27e9, \u27e8E t, by simp [h]\u27e9\u27e9)\u27e9\n\n@[simp] theorem of_equiv_\u03c3 {f : filter \u03b1} (F : f.realizer) (E : F.\u03c3 \u2243 \u03c4) :\n (F.of_equiv E).\u03c3 = \u03c4 := rfl\n@[simp] theorem of_equiv_F {f : filter \u03b1} (F : f.realizer) (E : F.\u03c3 \u2243 \u03c4) (s : \u03c4) :\n (F.of_equiv E).F s = F.F (E.symm s) := by delta of_equiv; simp\n\n\/-- `unit` is a realizer for the principal filter -\/\nprotected def principal (s : set \u03b1) : (principal s).realizer := \u27e8unit,\n{ f := \u03bb _, s,\n pt := (),\n inf := \u03bb _ _, (),\n inf_le_left := \u03bb _ _, le_refl _,\n inf_le_right := \u03bb _ _, le_refl _ },\nfilter_eq $ set.ext $ \u03bb x,\n\u27e8\u03bb \u27e8_, s\u27e9, s, \u03bb h, \u27e8(), h\u27e9\u27e9\u27e9\n\n@[simp] theorem principal_\u03c3 (s : set \u03b1) : (realizer.principal s).\u03c3 = unit := rfl\n@[simp] theorem principal_F (s : set \u03b1) (u : unit) : (realizer.principal s).F u = s := rfl\n\n\/-- `unit` is a realizer for the top filter -\/\nprotected def top : (\u22a4 : filter \u03b1).realizer :=\n(realizer.principal _).of_eq principal_univ\n\n@[simp] theorem top_\u03c3 : (@realizer.top \u03b1).\u03c3 = unit := rfl\n@[simp] theorem top_F (u : unit) : (@realizer.top \u03b1).F u = univ := rfl\n\n\/-- `unit` is a realizer for the bottom filter -\/\nprotected def bot : (\u22a5 : filter \u03b1).realizer :=\n(realizer.principal _).of_eq principal_empty\n\n@[simp] theorem bot_\u03c3 : (@realizer.bot \u03b1).\u03c3 = unit := rfl\n@[simp] theorem bot_F (u : unit) : (@realizer.bot \u03b1).F u = \u2205 := rfl\n\n\/-- Construct a realizer for `map m f` given a realizer for `f` -\/\nprotected def map (m : \u03b1 \u2192 \u03b2) {f : filter \u03b1} (F : f.realizer) : (map m f).realizer := \u27e8F.\u03c3,\n{ f := \u03bb s, image m (F.F s),\n pt := F.F.pt,\n inf := F.F.inf,\n inf_le_left := \u03bb a b, image_subset _ (F.F.inf_le_left _ _),\n inf_le_right := \u03bb a b, image_subset _ (F.F.inf_le_right _ _) },\nfilter_eq $ set.ext $ \u03bb x, by simp [cfilter.to_filter]; rw F.mem_sets; refl \u27e9\n\n@[simp] theorem map_\u03c3 (m : \u03b1 \u2192 \u03b2) {f : filter \u03b1} (F : f.realizer) : (F.map m).\u03c3 = F.\u03c3 := rfl\n@[simp] theorem map_F (m : \u03b1 \u2192 \u03b2) {f : filter \u03b1} (F : f.realizer) (s) :\n (F.map m).F s = image m (F.F s) := rfl\n\n\/-- Construct a realizer for `comap m f` given a realizer for `f` -\/\nprotected def comap (m : \u03b1 \u2192 \u03b2) {f : filter \u03b2} (F : f.realizer) : (comap m f).realizer := \u27e8F.\u03c3,\n{ f := \u03bb s, preimage m (F.F s),\n pt := F.F.pt,\n inf := F.F.inf,\n inf_le_left := \u03bb a b, preimage_mono (F.F.inf_le_left _ _),\n inf_le_right := \u03bb a b, preimage_mono (F.F.inf_le_right _ _) },\nfilter_eq $ set.ext $ \u03bb x, by cases F; subst f; simp [cfilter.to_filter, mem_comap]; exact\n\u27e8\u03bb \u27e8s, h\u27e9, \u27e8_, \u27e8s, subset.refl _\u27e9, h\u27e9,\n \u03bb \u27e8y, \u27e8s, h\u27e9, h\u2082\u27e9, \u27e8s, subset.trans (preimage_mono h) h\u2082\u27e9\u27e9\u27e9\n\n\/-- Construct a realizer for the sup of two filters -\/\nprotected def sup {f g : filter \u03b1} (F : f.realizer) (G : g.realizer) :\n (f \u2294 g).realizer := \u27e8F.\u03c3 \u00d7 G.\u03c3,\n{ f := \u03bb \u27e8s, t\u27e9, F.F s \u222a G.F t,\n pt := (F.F.pt, G.F.pt),\n inf := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, (F.F.inf a b, G.F.inf a' b'),\n inf_le_left := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, union_subset_union (F.F.inf_le_left _ _) (G.F.inf_le_left _ _),\n inf_le_right := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, union_subset_union (F.F.inf_le_right _ _)\n (G.F.inf_le_right _ _) },\nfilter_eq $ set.ext $ \u03bb x, by cases F; cases G; substs f g; simp [cfilter.to_filter]; exact\n\u27e8\u03bb \u27e8s, t, h\u27e9, \u27e8\u27e8s, subset.trans (subset_union_left _ _) h\u27e9,\n \u27e8t, subset.trans (subset_union_right _ _) h\u27e9\u27e9,\n \u03bb \u27e8\u27e8s, h\u2081\u27e9, \u27e8t, h\u2082\u27e9\u27e9, \u27e8s, t, union_subset h\u2081 h\u2082\u27e9\u27e9\u27e9\n\n\/-- Construct a realizer for the inf of two filters -\/\nprotected def inf {f g : filter \u03b1} (F : f.realizer) (G : g.realizer) :\n (f \u2293 g).realizer := \u27e8F.\u03c3 \u00d7 G.\u03c3,\n{ f := \u03bb \u27e8s, t\u27e9, F.F s \u2229 G.F t,\n pt := (F.F.pt, G.F.pt),\n inf := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, (F.F.inf a b, G.F.inf a' b'),\n inf_le_left := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, inter_subset_inter (F.F.inf_le_left _ _) (G.F.inf_le_left _ _),\n inf_le_right := \u03bb \u27e8a, a'\u27e9 \u27e8b, b'\u27e9, inter_subset_inter (F.F.inf_le_right _ _)\n (G.F.inf_le_right _ _) },\n begin\n ext x,\n cases F; cases G; substs f g; simp [cfilter.to_filter],\n split,\n { rintro \u27e8s : F_\u03c3, t : G_\u03c3, h\u27e9,\n apply mem_inf_of_inter _ _ h,\n use s,\n use t, },\n { rintros \u27e8s, \u27e8a, ha\u27e9, t, \u27e8b, hb\u27e9, rfl\u27e9,\n exact \u27e8a, b, inter_subset_inter ha hb\u27e9 }\n end\u27e9\n\n\/-- Construct a realizer for the cofinite filter -\/\nprotected def cofinite [decidable_eq \u03b1] : (@cofinite \u03b1).realizer := \u27e8finset \u03b1,\n{ f := \u03bb s, {a | a \u2209 s},\n pt := \u2205,\n inf := (\u222a),\n inf_le_left := \u03bb s t a, mt (finset.mem_union_left _),\n inf_le_right := \u03bb s t a, mt (finset.mem_union_right _) },\nfilter_eq $ set.ext $ \u03bb x,\n\u27e8\u03bb \u27e8s, h\u27e9, s.finite_to_set.subset (compl_subset_comm.1 h),\n \u03bb \u27e8fs\u27e9, by exactI \u27e8x\u1d9c.to_finset, \u03bb a (h : a \u2209 x\u1d9c.to_finset),\n classical.by_contradiction $ \u03bb h', h (mem_to_finset.2 h')\u27e9\u27e9\u27e9\n\n\/-- Construct a realizer for filter bind -\/\nprotected def bind {f : filter \u03b1} {m : \u03b1 \u2192 filter \u03b2} (F : f.realizer) (G : \u2200 i, (m i).realizer) :\n (f.bind m).realizer :=\n\u27e8\u03a3 s : F.\u03c3, \u03a0 i \u2208 F.F s, (G i).\u03c3,\n{ f := \u03bb \u27e8s, f\u27e9, \u22c3 i \u2208 F.F s, (G i).F (f i H),\n pt := \u27e8F.F.pt, \u03bb i H, (G i).F.pt\u27e9,\n inf := \u03bb \u27e8a, f\u27e9 \u27e8b, f'\u27e9, \u27e8F.F.inf a b, \u03bb i h,\n (G i).F.inf (f i (F.F.inf_le_left _ _ h)) (f' i (F.F.inf_le_right _ _ h))\u27e9,\n inf_le_left := \u03bb \u27e8a, f\u27e9 \u27e8b, f'\u27e9 x,\n show (x \u2208 \u22c3 (i : \u03b1) (H : i \u2208 F.F (F.F.inf a b)), _) \u2192\n x \u2208 \u22c3 i (H : i \u2208 F.F a), ((G i).F) (f i H), by simp; exact\n \u03bb i h\u2081 h\u2082, \u27e8i, F.F.inf_le_left _ _ h\u2081, (G i).F.inf_le_left _ _ h\u2082\u27e9,\n inf_le_right := \u03bb \u27e8a, f\u27e9 \u27e8b, f'\u27e9 x,\n show (x \u2208 \u22c3 (i : \u03b1) (H : i \u2208 F.F (F.F.inf a b)), _) \u2192\n x \u2208 \u22c3 i (H : i \u2208 F.F b), ((G i).F) (f' i H), by simp; exact\n \u03bb i h\u2081 h\u2082, \u27e8i, F.F.inf_le_right _ _ h\u2081, (G i).F.inf_le_right _ _ h\u2082\u27e9 },\nfilter_eq $ set.ext $ \u03bb x,\nby cases F with _ F _; subst f; simp [cfilter.to_filter, mem_bind]; exact\n\u27e8\u03bb \u27e8s, f, h\u27e9, \u27e8F s, \u27e8s, subset.refl _\u27e9, \u03bb i H, (G i).mem_sets.2\n \u27e8f i H, \u03bb a h', h \u27e8_, \u27e8i, rfl\u27e9, _, \u27e8H, rfl\u27e9, h'\u27e9\u27e9\u27e9,\n \u03bb \u27e8y, \u27e8s, h\u27e9, f\u27e9,\n let \u27e8f', h'\u27e9 := classical.axiom_of_choice (\u03bb i:F s, (G i).mem_sets.1 (f i (h i.2))) in\n \u27e8s, \u03bb i h, f' \u27e8i, h\u27e9, \u03bb a \u27e8_, \u27e8i, rfl\u27e9, _, \u27e8H, rfl\u27e9, m\u27e9, h' \u27e8_, H\u27e9 m\u27e9\u27e9\u27e9\n\n\/-- Construct a realizer for indexed supremum -\/\nprotected def Sup {f : \u03b1 \u2192 filter \u03b2} (F : \u2200 i, (f i).realizer) : (\u2a06 i, f i).realizer :=\nlet F' : (\u2a06 i, f i).realizer :=\n ((realizer.bind realizer.top F).of_eq $\n filter_eq $ set.ext $ by simp [filter.bind, eq_univ_iff_forall, supr_sets_eq]) in\nF'.of_equiv $ show (\u03a3 u:unit, \u03a0 (i : \u03b1), true \u2192 (F i).\u03c3) \u2243 \u03a0 i, (F i).\u03c3, from\n\u27e8\u03bb\u27e8_,f\u27e9 i, f i \u27e8\u27e9, \u03bb f, \u27e8(), \u03bb i _, f i\u27e9,\n \u03bb \u27e8\u27e8\u27e9, f\u27e9, by dsimp; congr; simp, \u03bb f, rfl\u27e9\n\n\/-- Construct a realizer for the product of filters -\/\nprotected def prod {f g : filter \u03b1} (F : f.realizer) (G : g.realizer) : (f.prod g).realizer :=\n(F.comap _).inf (G.comap _)\n\ntheorem le_iff {f g : filter \u03b1} (F : f.realizer) (G : g.realizer) :\n f \u2264 g \u2194 \u2200 b : G.\u03c3, \u2203 a : F.\u03c3, F.F a \u2264 G.F b :=\n\u27e8\u03bb H t, F.mem_sets.1 (H (G.mem_sets.2 \u27e8t, subset.refl _\u27e9)),\n \u03bb H x h, F.mem_sets.2 $\n let \u27e8s, h\u2081\u27e9 := G.mem_sets.1 h, \u27e8t, h\u2082\u27e9 := H s in \u27e8t, subset.trans h\u2082 h\u2081\u27e9\u27e9\n\ntheorem tendsto_iff (f : \u03b1 \u2192 \u03b2) {l\u2081 : filter \u03b1} {l\u2082 : filter \u03b2} (L\u2081 : l\u2081.realizer)\n (L\u2082 : l\u2082.realizer) :\n tendsto f l\u2081 l\u2082 \u2194 \u2200 b, \u2203 a, \u2200 x \u2208 L\u2081.F a, f x \u2208 L\u2082.F b :=\n(le_iff (L\u2081.map f) L\u2082).trans $ forall_congr $ \u03bb b, exists_congr $ \u03bb a, image_subset_iff\n\ntheorem ne_bot_iff {f : filter \u03b1} (F : f.realizer) :\n f \u2260 \u22a5 \u2194 \u2200 a : F.\u03c3, (F.F a).nonempty :=\nbegin\n classical,\n rw [not_iff_comm, \u2190 le_bot_iff, F.le_iff realizer.bot, not_forall],\n simp only [set.not_nonempty_iff_eq_empty],\n exact \u27e8\u03bb \u27e8x, e\u27e9 _, \u27e8x, le_of_eq e\u27e9,\n \u03bb h, let \u27e8x, h\u27e9 := h () in \u27e8x, le_bot_iff.1 h\u27e9\u27e9\nend\n\nend filter.realizer\n","avg_line_length":43.0714285714,"max_line_length":100,"alphanum_fraction":0.5665192556} -{"size":5583,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2020 Wojciech Nawrocki. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n\nAuthors: Wojciech Nawrocki\n-\/\nimport Lean.Data.Json\nimport Lean.Data.Lsp.Basic\n\nnamespace Lean\nnamespace Lsp\n\nopen Json\n\nstructure CompletionOptions where\n triggerCharacters? : Option (Array String) := none\n allCommitCharacters?: Option (Array String) := none\n resolveProvider?: Bool := false\n deriving FromJson, ToJson\n\nstructure CompletionItem where\n label : String\n detail? : Option String\n documentation? : Option MarkupContent\n \/-\n kind? : CompletionItemKind\n tags? : CompletionItemTag[]\n deprecated? : boolean\n preselect? : boolean\n sortText? : string\n filterText? : string\n insertText? : string\n insertTextFormat? : InsertTextFormat\n insertTextMode? : InsertTextMode\n textEdit? : TextEdit | InsertReplaceEdit\n additionalTextEdits? : TextEdit[]\n commitCharacters? : string[]\n command? : Command\n data? : any -\/\n deriving FromJson, ToJson, Inhabited\n\nstructure CompletionList where\n isIncomplete : Bool\n items : Array CompletionItem\n deriving FromJson, ToJson\n\nstructure CompletionParams extends TextDocumentPositionParams where\n -- context? : CompletionContext\n deriving FromJson, ToJson\n\nstructure Hover where\n \/- NOTE we should also accept MarkedString\/MarkedString[] here\n but they are deprecated, so maybe can get away without. -\/\n contents : MarkupContent\n range? : Option Range := none\n deriving ToJson, FromJson\n\nstructure HoverParams extends TextDocumentPositionParams\n deriving FromJson, ToJson\n\nstructure DeclarationParams extends TextDocumentPositionParams\n deriving FromJson, ToJson\n\nstructure DefinitionParams extends TextDocumentPositionParams\n deriving FromJson, ToJson\n\nstructure TypeDefinitionParams extends TextDocumentPositionParams\n deriving FromJson, ToJson\n\nstructure DocumentHighlightParams extends TextDocumentPositionParams\n deriving FromJson, ToJson\n\ninductive DocumentHighlightKind where\n | text\n | read\n | write\n\ninstance : ToJson DocumentHighlightKind where\n toJson\n\t| DocumentHighlightKind.text => 1\n\t| DocumentHighlightKind.read => 2\n\t| DocumentHighlightKind.write => 3\n\nstructure DocumentHighlight where\n range : Range\n kind? : Option DocumentHighlightKind := none\n deriving ToJson\n\nabbrev DocumentHighlightResult := Array DocumentHighlight\n\nstructure DocumentSymbolParams where\n textDocument : TextDocumentIdentifier\n deriving FromJson, ToJson\n\ninductive SymbolKind where\n\t| file\n\t| module\n\t| \u00abnamespace\u00bb\n\t| package\n\t| \u00abclass\u00bb\n\t| method\n\t| property\n\t| field\n\t| constructor\n\t| enum\n\t| interface\n\t| function\n\t| \u00abvariable\u00bb\n\t| \u00abconstant\u00bb\n\t| string\n\t| number\n\t| boolean\n\t| array\n\t| object\n\t| key\n\t| null\n\t| enumMember\n\t| struct\n\t| event\n\t| operator\n\t| typeParameter\n\ninstance : ToJson SymbolKind where\n toJson\n\t| SymbolKind.file => 1\n\t| SymbolKind.module => 2\n\t| SymbolKind.namespace => 3\n\t| SymbolKind.package => 4\n\t| SymbolKind.class => 5\n\t| SymbolKind.method => 6\n\t| SymbolKind.property => 7\n\t| SymbolKind.field => 8\n\t| SymbolKind.constructor => 9\n\t| SymbolKind.enum => 10\n\t| SymbolKind.interface => 11\n\t| SymbolKind.function => 12\n\t| SymbolKind.variable => 13\n\t| SymbolKind.constant => 14\n\t| SymbolKind.string => 15\n\t| SymbolKind.number => 16\n\t| SymbolKind.boolean => 17\n\t| SymbolKind.array => 18\n\t| SymbolKind.object => 19\n\t| SymbolKind.key => 20\n\t| SymbolKind.null => 21\n\t| SymbolKind.enumMember => 22\n\t| SymbolKind.struct => 23\n\t| SymbolKind.event => 24\n\t| SymbolKind.operator => 25\n\t| SymbolKind.typeParameter => 26\n\nstructure DocumentSymbolAux (Self : Type) where\n name : String\n detail? : Option String := none\n kind : SymbolKind\n -- tags? : Array SymbolTag\n range : Range\n selectionRange : Range\n children? : Option (Array Self) := none\n deriving ToJson\n\ninductive DocumentSymbol where\n | mk (sym : DocumentSymbolAux DocumentSymbol)\n\npartial instance : ToJson DocumentSymbol where\n toJson :=\n let rec go\n | DocumentSymbol.mk sym =>\n have ToJson DocumentSymbol := \u27e8go\u27e9\n toJson sym\n go\n\nstructure DocumentSymbolResult where\n syms : Array DocumentSymbol\n\ninstance : ToJson DocumentSymbolResult where\n toJson dsr := toJson dsr.syms\n\ninductive SemanticTokenType where\n | keyword\n | \u00abvariable\u00bb\n | property\n \/-\n | \u00abnamespace\u00bb\n | type\n | \u00abclass\u00bb\n | enum\n | interface\n | struct\n | typeParameter\n | parameter\n | enumMember\n | event\n | function\n | method\n | \u00abmacro\u00bb\n | modifier\n | comment\n | string\n | number\n | regexp\n | operator\n -\/\n\ndef SemanticTokenType.names : Array String :=\n #[\"keyword\", \"variable\", \"property\"]\n\n-- must be the correct index in `names`\ndef SemanticTokenType.toNat : SemanticTokenType \u2192 Nat\n | keyword => 0\n | \u00abvariable\u00bb => 1\n | property => 2\n\n\/-\ninductive SemanticTokenModifier where\n | declaration\n | definition\n | readonly\n | static\n | deprecated\n | abstract\n | async\n | modification\n | documentation\n | defaultLibrary\n-\/\n\nstructure SemanticTokensLegend where\n tokenTypes : Array String\n tokenModifiers : Array String\n deriving FromJson, ToJson\n\nstructure SemanticTokensOptions where\n legend : SemanticTokensLegend\n range : Bool\n full : Bool \/- | {\n delta?: boolean;\n } -\/\n deriving FromJson, ToJson\n\nstructure SemanticTokensParams where\n textDocument : TextDocumentIdentifier\n deriving FromJson, ToJson\n\nstructure SemanticTokensRangeParams where\n textDocument : TextDocumentIdentifier\n range : Range\n deriving FromJson, ToJson\n\nstructure SemanticTokens where\n -- resultId?: string;\n data : Array Nat\n deriving FromJson, ToJson\n\nend Lsp\nend Lean\n","avg_line_length":21.7237354086,"max_line_length":68,"alphanum_fraction":0.7345513165} -{"size":49612,"ext":"lean","lang":"Lean","max_stars_count":2.0,"content":"\/-\nCopyright (c) 2020 Anne Baanen. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen\n-\/\nimport algebra.big_operators.finsupp\nimport linear_algebra.finsupp\nimport linear_algebra.prod\nimport linear_algebra.pi\nimport order.zorn\nimport data.finset.order\nimport data.equiv.fin\n\n\/-!\n\n# Linear independence\n\nThis file defines linear independence in a module or vector space.\n\nIt is inspired by Isabelle\/HOL's linear algebra, and hence indirectly by HOL Light.\n\nWe define `linear_independent R v` as `ker (finsupp.total \u03b9 M R v) = \u22a5`. Here `finsupp.total` is the\nlinear map sending a function `f : \u03b9 \u2192\u2080 R` with finite support to the linear combination of vectors\nfrom `v` with these coefficients. Then we prove that several other statements are equivalent to this\none, including injectivity of `finsupp.total \u03b9 M R v` and some versions with explicitly written\nlinear combinations.\n\n## Main definitions\n\nAll definitions are given for families of vectors, i.e. `v : \u03b9 \u2192 M` where `M` is the module or\nvector space and `\u03b9 : Type*` is an arbitrary indexing type.\n\n* `linear_independent R v` states that the elements of the family `v` are linearly independent.\n\n* `linear_independent.repr hv x` returns the linear combination representing `x : span R (range v)`\non the linearly independent vectors `v`, given `hv : linear_independent R v`\n(using classical choice). `linear_independent.repr hv` is provided as a linear map.\n\n## Main statements\n\nWe prove several specialized tests for linear independence of families of vectors and of sets of\nvectors.\n\n* `fintype.linear_independent_iff`: if `\u03b9` is a finite type, then any function `f : \u03b9 \u2192 R` has\n finite support, so we can reformulate the statement using `\u2211 i : \u03b9, f i \u2022 v i` instead of a sum\n over an auxiliary `s : finset \u03b9`;\n* `linear_independent_empty_type`: a family indexed by an empty type is linearly independent;\n* `linear_independent_unique_iff`: if `\u03b9` is a singleton, then `linear_independent K v` is\n equivalent to `v (default \u03b9) \u2260 0`;\n* linear_independent_option`, `linear_independent_sum`, `linear_independent_fin_cons`,\n `linear_independent_fin_succ`: type-specific tests for linear independence of families of vector\n fields;\n* `linear_independent_insert`, `linear_independent_union`, `linear_independent_pair`,\n `linear_independent_singleton`: linear independence tests for set operations.\n\nIn many cases we additionally provide dot-style operations (e.g., `linear_independent.union`) to\nmake the linear independence tests usable as `hv.insert ha` etc.\n\nWe also prove that any family of vectors includes a linear independent subfamily spanning the same\nsubmodule.\n\n## Implementation notes\n\nWe use families instead of sets because it allows us to say that two identical vectors are linearly\ndependent.\n\nIf you want to use sets, use the family `(\u03bb x, x : s \u2192 M)` given a set `s : set M`. The lemmas\n`linear_independent.to_subtype_range` and `linear_independent.of_subtype_range` connect those two\nworlds.\n\n## Tags\n\nlinearly dependent, linear dependence, linearly independent, linear independence\n\n-\/\n\nnoncomputable theory\n\nopen function set submodule\nopen_locale classical big_operators\n\nuniverse u\n\nvariables {\u03b9 : Type*} {\u03b9' : Type*} {R : Type*} {K : Type*}\nvariables {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}\n\n\nsection module\n\nvariables {v : \u03b9 \u2192 M}\nvariables [semiring R] [add_comm_monoid M] [add_comm_monoid M'] [add_comm_monoid M'']\nvariables [module R M] [module R M'] [module R M'']\nvariables {a b : R} {x y : M}\n\nvariables (R) (v)\n\n\/-- `linear_independent R v` states the family of vectors `v` is linearly independent over `R`. -\/\ndef linear_independent : Prop := (finsupp.total \u03b9 M R v).ker = \u22a5\nvariables {R} {v}\n\ntheorem linear_independent_iff : linear_independent R v \u2194\n \u2200l, finsupp.total \u03b9 M R v l = 0 \u2192 l = 0 :=\nby simp [linear_independent, linear_map.ker_eq_bot']\n\ntheorem linear_independent_iff' : linear_independent R v \u2194\n \u2200 s : finset \u03b9, \u2200 g : \u03b9 \u2192 R, \u2211 i in s, g i \u2022 v i = 0 \u2192 \u2200 i \u2208 s, g i = 0 :=\nlinear_independent_iff.trans\n\u27e8\u03bb hf s g hg i his, have h : _ := hf (\u2211 i in s, finsupp.single i (g i)) $\n by simpa only [linear_map.map_sum, finsupp.total_single] using hg, calc\n g i = (finsupp.lapply i : (\u03b9 \u2192\u2080 R) \u2192\u2097[R] R) (finsupp.single i (g i)) :\n by rw [finsupp.lapply_apply, finsupp.single_eq_same]\n ... = \u2211 j in s, (finsupp.lapply i : (\u03b9 \u2192\u2080 R) \u2192\u2097[R] R) (finsupp.single j (g j)) :\n eq.symm $ finset.sum_eq_single i\n (\u03bb j hjs hji, by rw [finsupp.lapply_apply, finsupp.single_eq_of_ne hji])\n (\u03bb hnis, hnis.elim his)\n ... = (\u2211 j in s, finsupp.single j (g j)) i : (finsupp.lapply i : (\u03b9 \u2192\u2080 R) \u2192\u2097[R] R).map_sum.symm\n ... = 0 : finsupp.ext_iff.1 h i,\n\u03bb hf l hl, finsupp.ext $ \u03bb i, classical.by_contradiction $ \u03bb hni, hni $ hf _ _ hl _ $\n finsupp.mem_support_iff.2 hni\u27e9\n\ntheorem linear_independent_iff'' :\n linear_independent R v \u2194 \u2200 (s : finset \u03b9) (g : \u03b9 \u2192 R) (hg : \u2200 i \u2209 s, g i = 0),\n \u2211 i in s, g i \u2022 v i = 0 \u2192 \u2200 i, g i = 0 :=\nlinear_independent_iff'.trans \u27e8\u03bb H s g hg hv i, if his : i \u2208 s then H s g hv i his else hg i his,\n\u03bb H s g hg i hi, by { convert H s (\u03bb j, if j \u2208 s then g j else 0) (\u03bb j hj, if_neg hj)\n (by simp_rw [ite_smul, zero_smul, finset.sum_extend_by_zero, hg]) i,\n exact (if_pos hi).symm }\u27e9\n\ntheorem linear_dependent_iff : \u00ac linear_independent R v \u2194\n \u2203 s : finset \u03b9, \u2203 g : \u03b9 \u2192 R, (\u2211 i in s, g i \u2022 v i) = 0 \u2227 (\u2203 i \u2208 s, g i \u2260 0) :=\nbegin\n rw linear_independent_iff',\n simp only [exists_prop, not_forall],\nend\n\ntheorem fintype.linear_independent_iff [fintype \u03b9] :\n linear_independent R v \u2194 \u2200 g : \u03b9 \u2192 R, \u2211 i, g i \u2022 v i = 0 \u2192 \u2200 i, g i = 0 :=\nbegin\n refine \u27e8\u03bb H g, by simpa using linear_independent_iff'.1 H finset.univ g,\n \u03bb H, linear_independent_iff''.2 $ \u03bb s g hg hs i, H _ _ _\u27e9,\n rw \u2190 hs,\n refine (finset.sum_subset (finset.subset_univ _) (\u03bb i _ hi, _)).symm,\n rw [hg i hi, zero_smul]\nend\n\n\/-- A finite family of vectors `v i` is linear independent iff the linear map that sends\n`c : \u03b9 \u2192 R` to `\u2211 i, c i \u2022 v i` has the trivial kernel. -\/\ntheorem fintype.linear_independent_iff' [fintype \u03b9] :\n linear_independent R v \u2194\n (linear_map.lsum R (\u03bb i : \u03b9, R) \u2115 (\u03bb i, linear_map.id.smul_right (v i))).ker = \u22a5 :=\nby simp [fintype.linear_independent_iff, linear_map.ker_eq_bot', funext_iff]\n\nlemma linear_independent_empty_type (h : \u00ac nonempty \u03b9) : linear_independent R v :=\nbegin\n rw [linear_independent_iff],\n intros,\n ext i,\n exact false.elim (h \u27e8i\u27e9)\nend\n\nlemma linear_independent.ne_zero [nontrivial R]\n (i : \u03b9) (hv : linear_independent R v) : v i \u2260 0 :=\n\u03bb h, @zero_ne_one R _ _ $ eq.symm begin\n suffices : (finsupp.single i 1 : \u03b9 \u2192\u2080 R) i = 0, {simpa},\n rw linear_independent_iff.1 hv (finsupp.single i 1),\n { simp },\n { simp [h] }\nend\n\n\/-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a\nlinearly independent family. -\/\nlemma linear_independent.comp\n (h : linear_independent R v) (f : \u03b9' \u2192 \u03b9) (hf : injective f) : linear_independent R (v \u2218 f) :=\nbegin\n rw [linear_independent_iff, finsupp.total_comp],\n intros l hl,\n have h_map_domain : \u2200 x, (finsupp.map_domain f l) (f x) = 0,\n by rw linear_independent_iff.1 h (finsupp.map_domain f l) hl; simp,\n ext x,\n convert h_map_domain x,\n rw [finsupp.map_domain_apply hf]\nend\n\n\/-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is\ndisjoint with the sumodule spaned by the vectors of `v`, then `f \u2218 v` is a linearly independent\nfamily of vectors. See also `linear_independent.map'` for a special case assuming `ker f = \u22a5`. -\/\nlemma linear_independent.map (hv : linear_independent R v) {f : M \u2192\u2097[R] M'}\n (hf_inj : disjoint (span R (range v)) f.ker) : linear_independent R (f \u2218 v) :=\nbegin\n rw [disjoint, \u2190 set.image_univ, finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap,\n map_le_iff_le_comap, comap_bot, finsupp.supported_univ, top_inf_eq] at hf_inj,\n unfold linear_independent at hv \u22a2,\n rw [hv, le_bot_iff] at hf_inj,\n haveI : inhabited M := \u27e80\u27e9,\n rw [finsupp.total_comp, @finsupp.lmap_domain_total _ _ R _ _ _ _ _ _ _ _ _ _ f,\n linear_map.ker_comp, hf_inj],\n exact \u03bb _, rfl,\nend\n\n\/-- An injective linear map sends linearly independent families of vectors to linearly independent\nfamilies of vectors. See also `linear_independent.map` for a more general statement. -\/\nlemma linear_independent.map' (hv : linear_independent R v) (f : M \u2192\u2097[R] M')\n (hf_inj : f.ker = \u22a5) : linear_independent R (f \u2218 v) :=\nhv.map $ by simp [hf_inj]\n\n\/-- If the image of a family of vectors under a linear map is linearly independent, then so is\nthe original family. -\/\nlemma linear_independent.of_comp (f : M \u2192\u2097[R] M') (hfv : linear_independent R (f \u2218 v)) :\n linear_independent R v :=\nlinear_independent_iff'.2 $ \u03bb s g hg i his,\nhave \u2211 (i : \u03b9) in s, g i \u2022 f (v i) = 0,\n by simp_rw [\u2190 f.map_smul, \u2190 f.map_sum, hg, f.map_zero],\nlinear_independent_iff'.1 hfv s g this i his\n\n\/-- If `f` is an injective linear map, then the family `f \u2218 v` is linearly independent\nif and only if the family `v` is linearly independent. -\/\nprotected lemma linear_map.linear_independent_iff (f : M \u2192\u2097[R] M') (hf_inj : f.ker = \u22a5) :\n linear_independent R (f \u2218 v) \u2194 linear_independent R v :=\n\u27e8\u03bb h, h.of_comp f, \u03bb h, h.map $ by simp only [hf_inj, disjoint_bot_right]\u27e9\n\n@[nontriviality]\nlemma linear_independent_of_subsingleton [subsingleton R] : linear_independent R v :=\nlinear_independent_iff.2 (\u03bb l hl, subsingleton.elim _ _)\n\ntheorem linear_independent_equiv (e : \u03b9 \u2243 \u03b9') {f : \u03b9' \u2192 M} :\n linear_independent R (f \u2218 e) \u2194 linear_independent R f :=\n\u27e8\u03bb h, function.comp.right_id f \u25b8 e.self_comp_symm \u25b8 h.comp _ e.symm.injective,\n\u03bb h, h.comp _ e.injective\u27e9\n\ntheorem linear_independent_equiv' (e : \u03b9 \u2243 \u03b9') {f : \u03b9' \u2192 M} {g : \u03b9 \u2192 M} (h : f \u2218 e = g) :\n linear_independent R g \u2194 linear_independent R f :=\nh \u25b8 linear_independent_equiv e\n\ntheorem linear_independent_subtype_range {\u03b9} {f : \u03b9 \u2192 M} (hf : injective f) :\n linear_independent R (coe : range f \u2192 M) \u2194 linear_independent R f :=\niff.symm $ linear_independent_equiv' (equiv.of_injective f hf) rfl\n\nalias linear_independent_subtype_range \u2194 linear_independent.of_subtype_range _\n\ntheorem linear_independent_image {\u03b9} {s : set \u03b9} {f : \u03b9 \u2192 M} (hf : set.inj_on f s) :\n linear_independent R (\u03bb x : s, f x) \u2194 linear_independent R (\u03bb x : f '' s, (x : M)) :=\nlinear_independent_equiv' (equiv.set.image_of_inj_on _ _ hf) rfl\n\nlemma linear_independent_span (hs : linear_independent R v) :\n @linear_independent \u03b9 R (span R (range v))\n (\u03bb i : \u03b9, \u27e8v i, subset_span (mem_range_self i)\u27e9) _ _ _ :=\nlinear_independent.of_comp (span R (range v)).subtype hs\n\n\/-- See `linear_independent.fin_cons` for a family of elements in a vector space. -\/\nlemma linear_independent.fin_cons' {m : \u2115} (x : M) (v : fin m \u2192 M)\n (hli : linear_independent R v)\n (x_ortho : (\u2200 (c : R) (y : submodule.span R (set.range v)), c \u2022 x + y = (0 : M) \u2192 c = 0)) :\n linear_independent R (fin.cons x v : fin m.succ \u2192 M) :=\nbegin\n rw fintype.linear_independent_iff at hli \u22a2,\n rintros g total_eq j,\n have zero_not_mem : (0 : fin m.succ) \u2209 finset.univ.image (fin.succ : fin m \u2192 fin m.succ),\n { rw finset.mem_image,\n rintro \u27e8x, hx, succ_eq\u27e9,\n exact fin.succ_ne_zero _ succ_eq },\n simp only [submodule.coe_mk, fin.univ_succ, finset.sum_insert zero_not_mem,\n fin.cons_zero, fin.cons_succ,\n forall_true_iff, imp_self, fin.succ_inj, finset.sum_image] at total_eq,\n have : g 0 = 0,\n { refine x_ortho (g 0) \u27e8\u2211 (i : fin m), g i.succ \u2022 v i, _\u27e9 total_eq,\n exact sum_mem _ (\u03bb i _, smul_mem _ _ (subset_span \u27e8i, rfl\u27e9)) },\n refine fin.cases this (\u03bb j, _) j,\n apply hli (\u03bb i, g i.succ),\n simpa only [this, zero_smul, zero_add] using total_eq\nend\n\n\/-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly\nindependent over a subring `R` of `K`.\nThe implementation uses minimal assumptions about the relationship between `R`, `K` and `M`.\nThe version where `K` is an `R`-algebra is `linear_independent.restrict_scalars_algebras`.\n -\/\nlemma linear_independent.restrict_scalars [semiring K] [smul_with_zero R K] [module K M]\n [is_scalar_tower R K M]\n (hinj : function.injective (\u03bb r : R, r \u2022 (1 : K))) (li : linear_independent K v) :\n linear_independent R v :=\nbegin\n refine linear_independent_iff'.mpr (\u03bb s g hg i hi, hinj (eq.trans _ (zero_smul _ _).symm)),\n refine (linear_independent_iff'.mp li : _) _ _ _ i hi,\n simp_rw [smul_assoc, one_smul],\n exact hg,\nend\n\nsection subtype\n\/-! The following lemmas use the subtype defined by a set in `M` as the index set `\u03b9`. -\/\n\ntheorem linear_independent_comp_subtype {s : set \u03b9} :\n linear_independent R (v \u2218 coe : s \u2192 M) \u2194\n \u2200 l \u2208 (finsupp.supported R R s), (finsupp.total \u03b9 M R v) l = 0 \u2192 l = 0 :=\nbegin\n simp only [linear_independent_iff, (\u2218), finsupp.mem_supported, finsupp.total_apply,\n set.subset_def, finset.mem_coe],\n split,\n { intros h l hl\u2081 hl\u2082,\n have := h (l.subtype_domain s) ((finsupp.sum_subtype_domain_index hl\u2081).trans hl\u2082),\n exact (finsupp.subtype_domain_eq_zero_iff hl\u2081).1 this },\n { intros h l hl,\n refine finsupp.emb_domain_eq_zero.1 (h (l.emb_domain $ function.embedding.subtype s) _ _),\n { suffices : \u2200 i hi, \u00acl \u27e8i, hi\u27e9 = 0 \u2192 i \u2208 s, by simpa,\n intros, assumption },\n { rwa [finsupp.emb_domain_eq_map_domain, finsupp.sum_map_domain_index],\n exacts [\u03bb _, zero_smul _ _, \u03bb _ _ _, add_smul _ _ _] } }\nend\n\nlemma linear_dependent_comp_subtype' {s : set \u03b9} :\n \u00ac linear_independent R (v \u2218 coe : s \u2192 M) \u2194\n \u2203 f : \u03b9 \u2192\u2080 R, f \u2208 finsupp.supported R R s \u2227 finsupp.total \u03b9 M R v f = 0 \u2227 f \u2260 0 :=\nby simp [linear_independent_comp_subtype]\n\n\/-- A version of `linear_dependent_comp_subtype'` with `finsupp.total` unfolded. -\/\nlemma linear_dependent_comp_subtype {s : set \u03b9} :\n \u00ac linear_independent R (v \u2218 coe : s \u2192 M) \u2194\n \u2203 f : \u03b9 \u2192\u2080 R, f \u2208 finsupp.supported R R s \u2227 \u2211 i in f.support, f i \u2022 v i = 0 \u2227 f \u2260 0 :=\nlinear_dependent_comp_subtype'\n\ntheorem linear_independent_subtype {s : set M} :\n linear_independent R (\u03bb x, x : s \u2192 M) \u2194\n \u2200 l \u2208 (finsupp.supported R R s), (finsupp.total M M R id) l = 0 \u2192 l = 0 :=\nby apply @linear_independent_comp_subtype _ _ _ id\n\ntheorem linear_independent_comp_subtype_disjoint {s : set \u03b9} :\n linear_independent R (v \u2218 coe : s \u2192 M) \u2194\n disjoint (finsupp.supported R R s) (finsupp.total \u03b9 M R v).ker :=\nby rw [linear_independent_comp_subtype, linear_map.disjoint_ker]\n\ntheorem linear_independent_subtype_disjoint {s : set M} :\n linear_independent R (\u03bb x, x : s \u2192 M) \u2194\n disjoint (finsupp.supported R R s) (finsupp.total M M R id).ker :=\nby apply @linear_independent_comp_subtype_disjoint _ _ _ id\n\ntheorem linear_independent_iff_total_on {s : set M} :\n linear_independent R (\u03bb x, x : s \u2192 M) \u2194 (finsupp.total_on M M R id s).ker = \u22a5 :=\nby rw [finsupp.total_on, linear_map.ker, linear_map.comap_cod_restrict, map_bot, comap_bot,\n linear_map.ker_comp, linear_independent_subtype_disjoint, disjoint, \u2190 map_comap_subtype,\n map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff]\n\nlemma linear_independent.restrict_of_comp_subtype {s : set \u03b9}\n (hs : linear_independent R (v \u2218 coe : s \u2192 M)) :\n linear_independent R (s.restrict v) :=\nhs\n\nvariables (R M)\nlemma linear_independent_empty : linear_independent R (\u03bb x, x : (\u2205 : set M) \u2192 M) :=\nby simp [linear_independent_subtype_disjoint]\nvariables {R M}\n\nlemma linear_independent.mono {t s : set M} (h : t \u2286 s) :\n linear_independent R (\u03bb x, x : s \u2192 M) \u2192 linear_independent R (\u03bb x, x : t \u2192 M) :=\nbegin\n simp only [linear_independent_subtype_disjoint],\n exact (disjoint.mono_left (finsupp.supported_mono h))\nend\n\nlemma linear_independent_of_finite (s : set M)\n (H : \u2200 t \u2286 s, finite t \u2192 linear_independent R (\u03bb x, x : t \u2192 M)) :\n linear_independent R (\u03bb x, x : s \u2192 M) :=\nlinear_independent_subtype.2 $\n \u03bb l hl, linear_independent_subtype.1 (H _ hl (finset.finite_to_set _)) l (subset.refl _)\n\nlemma linear_independent_Union_of_directed {\u03b7 : Type*}\n {s : \u03b7 \u2192 set M} (hs : directed (\u2286) s)\n (h : \u2200 i, linear_independent R (\u03bb x, x : s i \u2192 M)) :\n linear_independent R (\u03bb x, x : (\u22c3 i, s i) \u2192 M) :=\nbegin\n by_cases h\u03b7 : nonempty \u03b7,\n { resetI,\n refine linear_independent_of_finite (\u22c3 i, s i) (\u03bb t ht ft, _),\n rcases finite_subset_Union ft ht with \u27e8I, fi, hI\u27e9,\n rcases hs.finset_le fi.to_finset with \u27e8i, hi\u27e9,\n exact (h i).mono (subset.trans hI $ bUnion_subset $\n \u03bb j hj, hi j (fi.mem_to_finset.2 hj)) },\n { refine (linear_independent_empty _ _).mono _,\n rintro _ \u27e8_, \u27e8i, _\u27e9, _\u27e9, exact h\u03b7 \u27e8i\u27e9 }\nend\n\nlemma linear_independent_sUnion_of_directed {s : set (set M)}\n (hs : directed_on (\u2286) s)\n (h : \u2200 a \u2208 s, linear_independent R (\u03bb x, x : (a : set M) \u2192 M)) :\n linear_independent R (\u03bb x, x : (\u22c3\u2080 s) \u2192 M) :=\nby rw sUnion_eq_Union; exact\nlinear_independent_Union_of_directed hs.directed_coe (by simpa using h)\n\nlemma linear_independent_bUnion_of_directed {\u03b7} {s : set \u03b7} {t : \u03b7 \u2192 set M}\n (hs : directed_on (t \u207b\u00b9'o (\u2286)) s) (h : \u2200a\u2208s, linear_independent R (\u03bb x, x : t a \u2192 M)) :\n linear_independent R (\u03bb x, x : (\u22c3a\u2208s, t a) \u2192 M) :=\nby rw bUnion_eq_Union; exact\nlinear_independent_Union_of_directed (directed_comp.2 $ hs.directed_coe) (by simpa using h)\n\nend subtype\n\nend module\n\n\/-! ### Properties which require `ring R` -\/\n\nsection module\nvariables {v : \u03b9 \u2192 M}\nvariables [ring R] [add_comm_group M] [add_comm_group M'] [add_comm_group M'']\nvariables [module R M] [module R M'] [module R M'']\nvariables {a b : R} {x y : M}\n\ntheorem linear_independent_iff_injective_total : linear_independent R v \u2194\n function.injective (finsupp.total \u03b9 M R v) :=\nlinear_independent_iff.trans (finsupp.total \u03b9 M R v).to_add_monoid_hom.injective_iff.symm\n\nalias linear_independent_iff_injective_total \u2194 linear_independent.injective_total _\n\nlemma linear_independent.injective [nontrivial R] (hv : linear_independent R v) :\n injective v :=\nbegin\n intros i j hij,\n let l : \u03b9 \u2192\u2080 R := finsupp.single i (1 : R) - finsupp.single j 1,\n have h_total : finsupp.total \u03b9 M R v l = 0,\n { simp_rw [linear_map.map_sub, finsupp.total_apply],\n simp [hij] },\n have h_single_eq : finsupp.single i (1 : R) = finsupp.single j 1,\n { rw linear_independent_iff at hv,\n simp [eq_add_of_sub_eq' (hv l h_total)] },\n simpa [finsupp.single_eq_single_iff] using h_single_eq\nend\n\ntheorem linear_independent.to_subtype_range {\u03b9} {f : \u03b9 \u2192 M} (hf : linear_independent R f) :\n linear_independent R (coe : range f \u2192 M) :=\nbegin\n nontriviality R,\n exact (linear_independent_subtype_range hf.injective).2 hf\nend\n\ntheorem linear_independent.to_subtype_range' {\u03b9} {f : \u03b9 \u2192 M} (hf : linear_independent R f)\n {t} (ht : range f = t) :\n linear_independent R (coe : t \u2192 M) :=\nht \u25b8 hf.to_subtype_range\n\ntheorem linear_independent.image_of_comp {\u03b9 \u03b9'} (s : set \u03b9) (f : \u03b9 \u2192 \u03b9') (g : \u03b9' \u2192 M)\n (hs : linear_independent R (\u03bb x : s, g (f x))) :\n linear_independent R (\u03bb x : f '' s, g x) :=\nbegin\n nontriviality R,\n have : inj_on f s, from inj_on_iff_injective.2 hs.injective.of_comp,\n exact (linear_independent_equiv' (equiv.set.image_of_inj_on f s this) rfl).1 hs\nend\n\ntheorem linear_independent.image {\u03b9} {s : set \u03b9} {f : \u03b9 \u2192 M}\n (hs : linear_independent R (\u03bb x : s, f x)) : linear_independent R (\u03bb x : f '' s, (x : M)) :=\nby convert linear_independent.image_of_comp s f id hs\n\nlemma linear_independent.group_smul\n {G : Type*} [hG : group G] [distrib_mul_action G R] [distrib_mul_action G M]\n [is_scalar_tower G R M] [smul_comm_class G R M] {v : \u03b9 \u2192 M} (hv : linear_independent R v)\n (w : \u03b9 \u2192 G) : linear_independent R (w \u2022 v) :=\nbegin\n rw linear_independent_iff'' at hv \u22a2,\n intros s g hgs hsum i,\n refine (smul_eq_zero_iff_eq (w i)).1 _,\n refine hv s (\u03bb i, w i \u2022 g i) (\u03bb i hi, _) _ i,\n { dsimp only,\n exact (hgs i hi).symm \u25b8 smul_zero _ },\n { rw [\u2190 hsum, finset.sum_congr rfl _],\n intros, erw [pi.smul_apply, smul_assoc, smul_comm] },\nend\n\n-- This lemma cannot be proved with `linear_independent.group_smul` since the action of\n-- `units R` on `R` is not commutative.\nlemma linear_independent.units_smul {v : \u03b9 \u2192 M} (hv : linear_independent R v)\n (w : \u03b9 \u2192 units R) : linear_independent R (w \u2022 v) :=\nbegin\n rw linear_independent_iff'' at hv \u22a2,\n intros s g hgs hsum i,\n rw \u2190 (w i).mul_left_eq_zero,\n refine hv s (\u03bb i, g i \u2022 w i) (\u03bb i hi, _) _ i,\n { dsimp only,\n exact (hgs i hi).symm \u25b8 zero_smul _ _ },\n { rw [\u2190 hsum, finset.sum_congr rfl _],\n intros,\n erw [pi.smul_apply, smul_assoc],\n refl }\nend\n\nsection subtype\n\/-! The following lemmas use the subtype defined by a set in `M` as the index set `\u03b9`. -\/\n\nlemma linear_independent.disjoint_span_image (hv : linear_independent R v) {s t : set \u03b9}\n (hs : disjoint s t) :\n disjoint (submodule.span R $ v '' s) (submodule.span R $ v '' t) :=\nbegin\n simp only [disjoint_def, finsupp.mem_span_image_iff_total],\n rintros _ \u27e8l\u2081, hl\u2081, rfl\u27e9 \u27e8l\u2082, hl\u2082, H\u27e9,\n rw [hv.injective_total.eq_iff] at H, subst l\u2082,\n have : l\u2081 = 0 := finsupp.disjoint_supported_supported hs (submodule.mem_inf.2 \u27e8hl\u2081, hl\u2082\u27e9),\n simp [this]\nend\n\nlemma linear_independent_sum {v : \u03b9 \u2295 \u03b9' \u2192 M} :\n linear_independent R v \u2194 linear_independent R (v \u2218 sum.inl) \u2227\n linear_independent R (v \u2218 sum.inr) \u2227\n disjoint (submodule.span R (range (v \u2218 sum.inl))) (submodule.span R (range (v \u2218 sum.inr))) :=\nbegin\n rw [range_comp v, range_comp v],\n refine \u27e8\u03bb h, \u27e8h.comp _ sum.inl_injective, h.comp _ sum.inr_injective,\n h.disjoint_span_image is_compl_range_inl_range_inr.1\u27e9, _\u27e9,\n rintro \u27e8hl, hr, hlr\u27e9,\n rw [linear_independent_iff'] at *,\n intros s g hg i hi,\n have : \u2211 i in s.preimage sum.inl (sum.inl_injective.inj_on _), (\u03bb x, g x \u2022 v x) (sum.inl i) +\n \u2211 i in s.preimage sum.inr (sum.inr_injective.inj_on _), (\u03bb x, g x \u2022 v x) (sum.inr i) = 0,\n { rw [finset.sum_preimage', finset.sum_preimage', \u2190 finset.sum_union, \u2190 finset.filter_or],\n { simpa only [\u2190 mem_union, range_inl_union_range_inr, mem_univ, finset.filter_true] },\n { exact finset.disjoint_filter.2 (\u03bb x hx, disjoint_left.1 is_compl_range_inl_range_inr.1) } },\n { rw \u2190 eq_neg_iff_add_eq_zero at this,\n rw [disjoint_def'] at hlr,\n have A := hlr _ (sum_mem _ $ \u03bb i hi, _) _ (neg_mem _ $ sum_mem _ $ \u03bb i hi, _) this,\n { cases i with i i,\n { exact hl _ _ A i (finset.mem_preimage.2 hi) },\n { rw [this, neg_eq_zero] at A,\n exact hr _ _ A i (finset.mem_preimage.2 hi) } },\n { exact smul_mem _ _ (subset_span \u27e8sum.inl i, mem_range_self _, rfl\u27e9) },\n { exact smul_mem _ _ (subset_span \u27e8sum.inr i, mem_range_self _, rfl\u27e9) } }\nend\n\nlemma linear_independent.sum_type {v' : \u03b9' \u2192 M} (hv : linear_independent R v)\n (hv' : linear_independent R v')\n (h : disjoint (submodule.span R (range v)) (submodule.span R (range v'))) :\n linear_independent R (sum.elim v v') :=\nlinear_independent_sum.2 \u27e8hv, hv', h\u27e9\n\nlemma linear_independent.union {s t : set M}\n (hs : linear_independent R (\u03bb x, x : s \u2192 M)) (ht : linear_independent R (\u03bb x, x : t \u2192 M))\n (hst : disjoint (span R s) (span R t)) :\n linear_independent R (\u03bb x, x : (s \u222a t) \u2192 M) :=\n(hs.sum_type ht $ by simpa).to_subtype_range' $ by simp\n\nlemma linear_independent_Union_finite_subtype {\u03b9 : Type*} {f : \u03b9 \u2192 set M}\n (hl : \u2200i, linear_independent R (\u03bb x, x : f i \u2192 M))\n (hd : \u2200i, \u2200t:set \u03b9, finite t \u2192 i \u2209 t \u2192 disjoint (span R (f i)) (\u2a06i\u2208t, span R (f i))) :\n linear_independent R (\u03bb x, x : (\u22c3i, f i) \u2192 M) :=\nbegin\n rw [Union_eq_Union_finset f],\n apply linear_independent_Union_of_directed,\n apply directed_of_sup,\n exact (assume t\u2081 t\u2082 ht, Union_subset_Union $ assume i, Union_subset_Union_const $ assume h, ht h),\n assume t, rw [set.Union, \u2190 finset.sup_eq_supr],\n refine t.induction_on _ _,\n { rw finset.sup_empty,\n apply linear_independent_empty_type (not_nonempty_iff_imp_false.2 _),\n exact \u03bb x, set.not_mem_empty x (subtype.mem x) },\n { rintros i s his ih,\n rw [finset.sup_insert],\n refine (hl _).union ih _,\n rw [finset.sup_eq_supr],\n refine (hd i _ _ his).mono_right _,\n { simp only [(span_Union _).symm],\n refine span_mono (@supr_le_supr2 (set M) _ _ _ _ _ _),\n rintros i, exact \u27e8i, le_refl _\u27e9 },\n { exact s.finite_to_set } }\nend\n\nlemma linear_independent_Union_finite {\u03b7 : Type*} {\u03b9s : \u03b7 \u2192 Type*}\n {f : \u03a0 j : \u03b7, \u03b9s j \u2192 M}\n (hindep : \u2200j, linear_independent R (f j))\n (hd : \u2200i, \u2200t:set \u03b7, finite t \u2192 i \u2209 t \u2192\n disjoint (span R (range (f i))) (\u2a06i\u2208t, span R (range (f i)))) :\n linear_independent R (\u03bb ji : \u03a3 j, \u03b9s j, f ji.1 ji.2) :=\nbegin\n nontriviality R,\n apply linear_independent.of_subtype_range,\n { rintros \u27e8x\u2081, x\u2082\u27e9 \u27e8y\u2081, y\u2082\u27e9 hxy,\n by_cases h_cases : x\u2081 = y\u2081,\n subst h_cases,\n { apply sigma.eq,\n rw linear_independent.injective (hindep _) hxy,\n refl },\n { have h0 : f x\u2081 x\u2082 = 0,\n { apply disjoint_def.1 (hd x\u2081 {y\u2081} (finite_singleton y\u2081)\n (\u03bb h, h_cases (eq_of_mem_singleton h))) (f x\u2081 x\u2082) (subset_span (mem_range_self _)),\n rw supr_singleton,\n simp only at hxy,\n rw hxy,\n exact (subset_span (mem_range_self y\u2082)) },\n exact false.elim ((hindep x\u2081).ne_zero _ h0) } },\n rw range_sigma_eq_Union_range,\n apply linear_independent_Union_finite_subtype (\u03bb j, (hindep j).to_subtype_range) hd,\nend\n\nend subtype\n\nsection repr\nvariables (hv : linear_independent R v)\n\n\/-- Canonical isomorphism between linear combinations and the span of linearly independent vectors.\n-\/\ndef linear_independent.total_equiv (hv : linear_independent R v) :\n (\u03b9 \u2192\u2080 R) \u2243\u2097[R] span R (range v) :=\nbegin\napply linear_equiv.of_bijective\n (linear_map.cod_restrict (span R (range v)) (finsupp.total \u03b9 M R v) _),\n{ rw linear_map.ker_cod_restrict,\n apply hv },\n{ rw [linear_map.range_eq_map, linear_map.map_cod_restrict, \u2190 linear_map.range_le_iff_comap,\n range_subtype, map_top],\n rw finsupp.range_total,\n apply le_refl (span R (range v)) },\n{ intro l,\n rw \u2190 finsupp.range_total,\n rw linear_map.mem_range,\n apply mem_range_self l }\nend\n\n\/-- Linear combination representing a vector in the span of linearly independent vectors.\n\nGiven a family of linearly independent vectors, we can represent any vector in their span as\na linear combination of these vectors. These are provided by this linear map.\nIt is simply one direction of `linear_independent.total_equiv`. -\/\ndef linear_independent.repr (hv : linear_independent R v) :\n span R (range v) \u2192\u2097[R] \u03b9 \u2192\u2080 R := hv.total_equiv.symm\n\nlemma linear_independent.total_repr (x) : finsupp.total \u03b9 M R v (hv.repr x) = x :=\nsubtype.ext_iff.1 (linear_equiv.apply_symm_apply hv.total_equiv x)\n\nlemma linear_independent.total_comp_repr :\n (finsupp.total \u03b9 M R v).comp hv.repr = submodule.subtype _ :=\nlinear_map.ext $ hv.total_repr\n\nlemma linear_independent.repr_ker : hv.repr.ker = \u22a5 :=\nby rw [linear_independent.repr, linear_equiv.ker]\n\nlemma linear_independent.repr_range : hv.repr.range = \u22a4 :=\nby rw [linear_independent.repr, linear_equiv.range]\n\nlemma linear_independent.repr_eq\n {l : \u03b9 \u2192\u2080 R} {x} (eq : finsupp.total \u03b9 M R v l = \u2191x) :\n hv.repr x = l :=\nbegin\n have : \u2191((linear_independent.total_equiv hv : (\u03b9 \u2192\u2080 R) \u2192\u2097[R] span R (range v)) l)\n = finsupp.total \u03b9 M R v l := rfl,\n have : (linear_independent.total_equiv hv : (\u03b9 \u2192\u2080 R) \u2192\u2097[R] span R (range v)) l = x,\n { rw eq at this,\n exact subtype.ext_iff.2 this },\n rw \u2190linear_equiv.symm_apply_apply hv.total_equiv l,\n rw \u2190this,\n refl,\nend\n\nlemma linear_independent.repr_eq_single (i) (x) (hx : \u2191x = v i) :\n hv.repr x = finsupp.single i 1 :=\nbegin\n apply hv.repr_eq,\n simp [finsupp.total_single, hx]\nend\n\n-- TODO: why is this so slow?\nlemma linear_independent_iff_not_smul_mem_span :\n linear_independent R v \u2194 (\u2200 (i : \u03b9) (a : R), a \u2022 (v i) \u2208 span R (v '' (univ \\ {i})) \u2192 a = 0) :=\n\u27e8 \u03bb hv i a ha, begin\n rw [finsupp.span_image_eq_map_total, mem_map] at ha,\n rcases ha with \u27e8l, hl, e\u27e9,\n rw sub_eq_zero.1 (linear_independent_iff.1 hv (l - finsupp.single i a) (by simp [e])) at hl,\n by_contra hn,\n exact (not_mem_of_mem_diff (hl $ by simp [hn])) (mem_singleton _),\nend, \u03bb H, linear_independent_iff.2 $ \u03bb l hl, begin\n ext i, simp only [finsupp.zero_apply],\n by_contra hn,\n refine hn (H i _ _),\n refine (finsupp.mem_span_image_iff_total _).2 \u27e8finsupp.single i (l i) - l, _, _\u27e9,\n { rw finsupp.mem_supported',\n intros j hj,\n have hij : j = i :=\n not_not.1\n (\u03bb hij : j \u2260 i, hj ((mem_diff _).2 \u27e8mem_univ _, \u03bb h, hij (eq_of_mem_singleton h)\u27e9)),\n simp [hij] },\n { simp [hl] }\nend\u27e9\n\nvariable (R)\n\nlemma exists_maximal_independent' (s : \u03b9 \u2192 M) :\n \u2203 I : set \u03b9, linear_independent R (\u03bb x : I, s x) \u2227\n \u2200 J : set \u03b9, I \u2286 J \u2192 linear_independent R (\u03bb x : J, s x) \u2192 I = J :=\nbegin\n let indep : set \u03b9 \u2192 Prop := \u03bb I, linear_independent R (s \u2218 coe : I \u2192 M),\n let X := { I : set \u03b9 \/\/ indep I },\n let r : X \u2192 X \u2192 Prop := \u03bb I J, I.1 \u2286 J.1,\n have key : \u2200 c : set X, zorn.chain r c \u2192 indep (\u22c3 (I : X) (H : I \u2208 c), I),\n { intros c hc,\n dsimp [indep],\n rw [linear_independent_comp_subtype],\n intros f hsupport hsum,\n rcases eq_empty_or_nonempty c with rfl | \u27e8a, hac\u27e9,\n { simpa using hsupport },\n haveI : is_refl X r := \u27e8\u03bb _, set.subset.refl _\u27e9,\n obtain \u27e8I, I_mem, hI\u27e9 : \u2203 I \u2208 c, (f.support : set \u03b9) \u2286 I :=\n finset.exists_mem_subset_of_subset_bUnion_of_directed_on hac hc.directed_on hsupport,\n exact linear_independent_comp_subtype.mp I.2 f hI hsum },\n have trans : transitive r := \u03bb I J K, set.subset.trans,\n obtain \u27e8\u27e8I, hli : indep I\u27e9, hmax : \u2200 a, r \u27e8I, hli\u27e9 a \u2192 r a \u27e8I, hli\u27e9\u27e9 :=\n @zorn.exists_maximal_of_chains_bounded _ r\n (\u03bb c hc, \u27e8\u27e8\u22c3 I \u2208 c, (I : set \u03b9), key c hc\u27e9, \u03bb I, set.subset_bUnion_of_mem\u27e9) trans,\n exact \u27e8I, hli, \u03bb J hsub hli, set.subset.antisymm hsub (hmax \u27e8J, hli\u27e9 hsub)\u27e9,\nend\n\nlemma exists_maximal_independent (s : \u03b9 \u2192 M) : \u2203 I : set \u03b9, linear_independent R (\u03bb x : I, s x) \u2227\n \u2200 i \u2209 I, \u2203 a : R, a \u2260 0 \u2227 a \u2022 s i \u2208 span R (s '' I) :=\nbegin\n classical,\n rcases exists_maximal_independent' R s with \u27e8I, hIlinind, hImaximal\u27e9,\n use [I, hIlinind],\n intros i hi,\n specialize hImaximal (I \u222a {i}) (by simp),\n set J := I \u222a {i} with hJ,\n have memJ : \u2200 {x}, x \u2208 J \u2194 x = i \u2228 x \u2208 I, by simp [hJ],\n have hiJ : i \u2208 J := by simp,\n have h := mt hImaximal _, swap,\n { intro h2,\n rw h2 at hi,\n exact absurd hiJ hi },\n obtain \u27e8f, supp_f, sum_f, f_ne\u27e9 := linear_dependent_comp_subtype.mp h,\n have hfi : f i \u2260 0,\n { contrapose hIlinind,\n refine linear_dependent_comp_subtype.mpr \u27e8f, _, sum_f, f_ne\u27e9,\n simp only [finsupp.mem_supported, hJ] at \u22a2 supp_f,\n rintro x hx,\n refine (memJ.mp (supp_f hx)).resolve_left _,\n rintro rfl,\n exact hIlinind (finsupp.mem_support_iff.mp hx) },\n use [f i, hfi],\n have hfi' : i \u2208 f.support := finsupp.mem_support_iff.mpr hfi,\n rw [\u2190 finset.insert_erase hfi', finset.sum_insert (finset.not_mem_erase _ _),\n add_eq_zero_iff_eq_neg] at sum_f,\n rw sum_f,\n refine neg_mem _ (sum_mem _ (\u03bb c hc, smul_mem _ _ (subset_span \u27e8c, _, rfl\u27e9))),\n exact (memJ.mp (supp_f (finset.erase_subset _ _ hc))).resolve_left (finset.ne_of_mem_erase hc),\nend\nend repr\n\nlemma surjective_of_linear_independent_of_span [nontrivial R]\n (hv : linear_independent R v) (f : \u03b9' \u21aa \u03b9)\n (hss : range v \u2286 span R (range (v \u2218 f))) :\n surjective f :=\nbegin\n intros i,\n let repr : (span R (range (v \u2218 f)) : Type*) \u2192 \u03b9' \u2192\u2080 R := (hv.comp f f.injective).repr,\n let l := (repr \u27e8v i, hss (mem_range_self i)\u27e9).map_domain f,\n have h_total_l : finsupp.total \u03b9 M R v l = v i,\n { dsimp only [l],\n rw finsupp.total_map_domain,\n rw (hv.comp f f.injective).total_repr,\n { refl },\n { exact f.injective } },\n have h_total_eq : (finsupp.total \u03b9 M R v) l = (finsupp.total \u03b9 M R v) (finsupp.single i 1),\n by rw [h_total_l, finsupp.total_single, one_smul],\n have l_eq : l = _ := linear_map.ker_eq_bot.1 hv h_total_eq,\n dsimp only [l] at l_eq,\n rw \u2190finsupp.emb_domain_eq_map_domain at l_eq,\n rcases finsupp.single_of_emb_domain_single (repr \u27e8v i, _\u27e9) f i (1 : R) zero_ne_one.symm l_eq\n with \u27e8i', hi'\u27e9,\n use i',\n exact hi'.2\nend\n\nlemma eq_of_linear_independent_of_span_subtype [nontrivial R] {s t : set M}\n (hs : linear_independent R (\u03bb x, x : s \u2192 M)) (h : t \u2286 s) (hst : s \u2286 span R t) : s = t :=\nbegin\n let f : t \u21aa s := \u27e8\u03bb x, \u27e8x.1, h x.2\u27e9, \u03bb a b hab, subtype.coe_injective (subtype.mk.inj hab)\u27e9,\n have h_surj : surjective f,\n { apply surjective_of_linear_independent_of_span hs f _,\n convert hst; simp [f, comp], },\n show s = t,\n { apply subset.antisymm _ h,\n intros x hx,\n rcases h_surj \u27e8x, hx\u27e9 with \u27e8y, hy\u27e9,\n convert y.mem,\n rw \u2190 subtype.mk.inj hy,\n refl }\nend\n\nopen linear_map\n\nlemma linear_independent.image_subtype {s : set M} {f : M \u2192\u2097 M'}\n (hs : linear_independent R (\u03bb x, x : s \u2192 M))\n (hf_inj : disjoint (span R s) f.ker) : linear_independent R (\u03bb x, x : f '' s \u2192 M') :=\nbegin\n rw [\u2190 @subtype.range_coe _ s] at hf_inj,\n refine (hs.map hf_inj).to_subtype_range' _,\n simp [set.range_comp f]\nend\n\nlemma linear_independent.inl_union_inr {s : set M} {t : set M'}\n (hs : linear_independent R (\u03bb x, x : s \u2192 M))\n (ht : linear_independent R (\u03bb x, x : t \u2192 M')) :\n linear_independent R (\u03bb x, x : inl R M M' '' s \u222a inr R M M' '' t \u2192 M \u00d7 M') :=\nbegin\n refine (hs.image_subtype _).union (ht.image_subtype _) _; [simp, simp, skip],\n simp only [span_image],\n simp [disjoint_iff, prod_inf_prod]\nend\n\nlemma linear_independent_inl_union_inr' {v : \u03b9 \u2192 M} {v' : \u03b9' \u2192 M'}\n (hv : linear_independent R v) (hv' : linear_independent R v') :\n linear_independent R (sum.elim (inl R M M' \u2218 v) (inr R M M' \u2218 v')) :=\n(hv.map' (inl R M M') ker_inl).sum_type (hv'.map' (inr R M M') ker_inr) $\nbegin\n refine is_compl_range_inl_inr.disjoint.mono _ _;\n simp only [span_le, range_coe, range_comp_subset_range],\nend\n\n\/-- Dedekind's linear independence of characters -\/\n-- See, for example, Keith Conrad's note\n-- \ntheorem linear_independent_monoid_hom (G : Type*) [monoid G] (L : Type*) [comm_ring L]\n [no_zero_divisors L] :\n @linear_independent _ L (G \u2192 L) (\u03bb f, f : (G \u2192* L) \u2192 (G \u2192 L)) _ _ _ :=\nby letI := classical.dec_eq (G \u2192* L);\n letI : mul_action L L := distrib_mul_action.to_mul_action;\n-- We prove linear independence by showing that only the trivial linear combination vanishes.\nexact linear_independent_iff'.2\n-- To do this, we use `finset` induction,\n(\u03bb s, finset.induction_on s (\u03bb g hg i, false.elim) $ \u03bb a s has ih g hg,\n-- Here\n-- * `a` is a new character we will insert into the `finset` of characters `s`,\n-- * `ih` is the fact that only the trivial linear combination of characters in `s` is zero\n-- * `hg` is the fact that `g` are the coefficients of a linear combination summing to zero\n-- and it remains to prove that `g` vanishes on `insert a s`.\n\n-- We now make the key calculation:\n-- For any character `i` in the original `finset`, we have `g i \u2022 i = g i \u2022 a` as functions on the\n-- monoid `G`.\nhave h1 : \u2200 i \u2208 s, (g i \u2022 i : G \u2192 L) = g i \u2022 a, from \u03bb i his, funext $ \u03bb x : G,\n -- We prove these expressions are equal by showing\n -- the differences of their values on each monoid element `x` is zero\n eq_of_sub_eq_zero $ ih (\u03bb j, g j * j x - g j * a x)\n (funext $ \u03bb y : G, calc\n -- After that, it's just a chase scene.\n (\u2211 i in s, ((g i * i x - g i * a x) \u2022 i : G \u2192 L)) y\n = \u2211 i in s, (g i * i x - g i * a x) * i y : finset.sum_apply _ _ _\n ... = \u2211 i in s, (g i * i x * i y - g i * a x * i y) : finset.sum_congr rfl\n (\u03bb _ _, sub_mul _ _ _)\n ... = \u2211 i in s, g i * i x * i y - \u2211 i in s, g i * a x * i y : finset.sum_sub_distrib\n ... = (g a * a x * a y + \u2211 i in s, g i * i x * i y)\n - (g a * a x * a y + \u2211 i in s, g i * a x * i y) : by rw add_sub_add_left_eq_sub\n ... = \u2211 i in insert a s, g i * i x * i y - \u2211 i in insert a s, g i * a x * i y :\n by rw [finset.sum_insert has, finset.sum_insert has]\n ... = \u2211 i in insert a s, g i * i (x * y) - \u2211 i in insert a s, a x * (g i * i y) :\n congr (congr_arg has_sub.sub (finset.sum_congr rfl $ \u03bb i _, by rw [i.map_mul, mul_assoc]))\n (finset.sum_congr rfl $ \u03bb _ _, by rw [mul_assoc, mul_left_comm])\n ... = (\u2211 i in insert a s, (g i \u2022 i : G \u2192 L)) (x * y)\n - a x * (\u2211 i in insert a s, (g i \u2022 i : G \u2192 L)) y :\n by rw [finset.sum_apply, finset.sum_apply, finset.mul_sum]; refl\n ... = 0 - a x * 0 : by rw hg; refl\n ... = 0 : by rw [mul_zero, sub_zero])\n i\n his,\n-- On the other hand, since `a` is not already in `s`, for any character `i \u2208 s`\n-- there is some element of the monoid on which it differs from `a`.\nhave h2 : \u2200 i : G \u2192* L, i \u2208 s \u2192 \u2203 y, i y \u2260 a y, from \u03bb i his,\n classical.by_contradiction $ \u03bb h,\n have hia : i = a, from monoid_hom.ext $ \u03bb y, classical.by_contradiction $ \u03bb hy, h \u27e8y, hy\u27e9,\n has $ hia \u25b8 his,\n-- From these two facts we deduce that `g` actually vanishes on `s`,\nhave h3 : \u2200 i \u2208 s, g i = 0, from \u03bb i his, let \u27e8y, hy\u27e9 := h2 i his in\n have h : g i \u2022 i y = g i \u2022 a y, from congr_fun (h1 i his) y,\n or.resolve_right (mul_eq_zero.1 $ by rw [mul_sub, sub_eq_zero]; exact h) (sub_ne_zero_of_ne hy),\n-- And so, using the fact that the linear combination over `s` and over `insert a s` both vanish,\n-- we deduce that `g a = 0`.\nhave h4 : g a = 0, from calc\n g a = g a * 1 : (mul_one _).symm\n ... = (g a \u2022 a : G \u2192 L) 1 : by rw \u2190 a.map_one; refl\n ... = (\u2211 i in insert a s, (g i \u2022 i : G \u2192 L)) 1 : begin\n rw finset.sum_eq_single a,\n { intros i his hia, rw finset.mem_insert at his,\n rw [h3 i (his.resolve_left hia), zero_smul] },\n { intros haas, exfalso, apply haas, exact finset.mem_insert_self a s }\n end\n ... = 0 : by rw hg; refl,\n-- Now we're done; the last two facts together imply that `g` vanishes on every element\n-- of `insert a s`.\n(finset.forall_mem_insert _ _ _).2 \u27e8h4, h3\u27e9)\n\nlemma le_of_span_le_span [nontrivial R] {s t u: set M}\n (hl : linear_independent R (coe : u \u2192 M )) (hsu : s \u2286 u) (htu : t \u2286 u)\n (hst : span R s \u2264 span R t) : s \u2286 t :=\nbegin\n have := eq_of_linear_independent_of_span_subtype\n (hl.mono (set.union_subset hsu htu))\n (set.subset_union_right _ _)\n (set.union_subset (set.subset.trans subset_span hst) subset_span),\n rw \u2190 this, apply set.subset_union_left\nend\n\nlemma span_le_span_iff [nontrivial R] {s t u: set M}\n (hl : linear_independent R (coe : u \u2192 M)) (hsu : s \u2286 u) (htu : t \u2286 u) :\n span R s \u2264 span R t \u2194 s \u2286 t :=\n\u27e8le_of_span_le_span hl hsu htu, span_mono\u27e9\n\nend module\n\nsection nontrivial\n\nvariables [ring R] [nontrivial R] [add_comm_group M] [add_comm_group M']\nvariables [module R M] [no_zero_smul_divisors R M] [module R M']\nvariables {v : \u03b9 \u2192 M} {s t : set M} {x y z : M}\n\nlemma linear_independent_unique_iff\n (v : \u03b9 \u2192 M) [unique \u03b9] :\n linear_independent R v \u2194 v (default \u03b9) \u2260 0 :=\nbegin\n simp only [linear_independent_iff, finsupp.total_unique, smul_eq_zero],\n refine \u27e8\u03bb h hv, _, \u03bb hv l hl, finsupp.unique_ext $ hl.resolve_right hv\u27e9,\n have := h (finsupp.single (default \u03b9) 1) (or.inr hv),\n exact one_ne_zero (finsupp.single_eq_zero.1 this)\nend\n\nalias linear_independent_unique_iff \u2194 _ linear_independent_unique\n\nlemma linear_independent_singleton {x : M} (hx : x \u2260 0) :\n linear_independent R (\u03bb x, x : ({x} : set M) \u2192 M) :=\nlinear_independent_unique coe hx\n\nend nontrivial\n\n\/-!\n### Properties which require `division_ring K`\n\nThese can be considered generalizations of properties of linear independence in vector spaces.\n-\/\n\nsection module\n\nvariables [division_ring K] [add_comm_group V] [add_comm_group V']\nvariables [module K V] [module K V']\nvariables {v : \u03b9 \u2192 V} {s t : set V} {x y z : V}\n\nopen submodule\n\n\/- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class\n (instead of a data containing type class) -\/\n\nlemma mem_span_insert_exchange : x \u2208 span K (insert y s) \u2192 x \u2209 span K s \u2192 y \u2208 span K (insert x s) :=\nbegin\n simp [mem_span_insert],\n rintro a z hz rfl h,\n refine \u27e8a\u207b\u00b9, -a\u207b\u00b9 \u2022 z, smul_mem _ _ hz, _\u27e9,\n have a0 : a \u2260 0, {rintro rfl, simp * at *},\n simp [a0, smul_add, smul_smul]\nend\n\nlemma linear_independent_iff_not_mem_span :\n linear_independent K v \u2194 (\u2200i, v i \u2209 span K (v '' (univ \\ {i}))) :=\nbegin\n apply linear_independent_iff_not_smul_mem_span.trans,\n split,\n { intros h i h_in_span,\n apply one_ne_zero (h i 1 (by simp [h_in_span])) },\n { intros h i a ha,\n by_contradiction ha',\n exact false.elim (h _ ((smul_mem_iff _ ha').1 ha)) }\nend\n\nlemma linear_independent.insert (hs : linear_independent K (\u03bb b, b : s \u2192 V)) (hx : x \u2209 span K s) :\n linear_independent K (\u03bb b, b : insert x s \u2192 V) :=\nbegin\n rw \u2190 union_singleton,\n have x0 : x \u2260 0 := mt (by rintro rfl; apply zero_mem _) hx,\n apply hs.union (linear_independent_singleton x0),\n rwa [disjoint_span_singleton' x0]\nend\n\nlemma linear_independent_option' :\n linear_independent K (\u03bb o, option.cases_on' o x v : option \u03b9 \u2192 V) \u2194\n linear_independent K v \u2227 (x \u2209 submodule.span K (range v)) :=\nbegin\n rw [\u2190 linear_independent_equiv (equiv.option_equiv_sum_punit \u03b9).symm, linear_independent_sum,\n @range_unique _ punit, @linear_independent_unique_iff punit, disjoint_span_singleton],\n dsimp [(\u2218)],\n refine \u27e8\u03bb h, \u27e8h.1, \u03bb hx, h.2.1 $ h.2.2 hx\u27e9, \u03bb h, \u27e8h.1, _, \u03bb hx, (h.2 hx).elim\u27e9\u27e9,\n rintro rfl,\n exact h.2 (zero_mem _)\nend\n\nlemma linear_independent.option (hv : linear_independent K v)\n (hx : x \u2209 submodule.span K (range v)) :\n linear_independent K (\u03bb o, option.cases_on' o x v : option \u03b9 \u2192 V) :=\nlinear_independent_option'.2 \u27e8hv, hx\u27e9\n\nlemma linear_independent_option {v : option \u03b9 \u2192 V} :\n linear_independent K v \u2194\n linear_independent K (v \u2218 coe : \u03b9 \u2192 V) \u2227 v none \u2209 submodule.span K (range (v \u2218 coe : \u03b9 \u2192 V)) :=\nby simp only [\u2190 linear_independent_option', option.cases_on'_none_coe]\n\ntheorem linear_independent_insert' {\u03b9} {s : set \u03b9} {a : \u03b9} {f : \u03b9 \u2192 V} (has : a \u2209 s) :\n linear_independent K (\u03bb x : insert a s, f x) \u2194\n linear_independent K (\u03bb x : s, f x) \u2227 f a \u2209 submodule.span K (f '' s) :=\nby { rw [\u2190 linear_independent_equiv ((equiv.option_equiv_sum_punit _).trans\n (equiv.set.insert has).symm), linear_independent_option], simp [(\u2218), range_comp f] }\n\ntheorem linear_independent_insert (hxs : x \u2209 s) :\n linear_independent K (\u03bb b : insert x s, (b : V)) \u2194\n linear_independent K (\u03bb b : s, (b : V)) \u2227 x \u2209 submodule.span K s :=\n(@linear_independent_insert' _ _ _ _ _ _ _ _ id hxs).trans $ by simp\n\nlemma linear_independent_pair {x y : V} (hx : x \u2260 0) (hy : \u2200 a : K, a \u2022 x \u2260 y) :\n linear_independent K (coe : ({x, y} : set V) \u2192 V) :=\npair_comm y x \u25b8 (linear_independent_singleton hx).insert $ mt mem_span_singleton.1\n (not_exists.2 hy)\n\nlemma linear_independent_fin_cons {n} {v : fin n \u2192 V} :\n linear_independent K (fin.cons x v : fin (n + 1) \u2192 V) \u2194\n linear_independent K v \u2227 x \u2209 submodule.span K (range v) :=\nbegin\n rw [\u2190 linear_independent_equiv (fin_succ_equiv n).symm, linear_independent_option],\n convert iff.rfl,\n { ext,\n -- TODO: why doesn't simp use `fin_succ_equiv_symm_coe` here?\n rw [comp_app, comp_app, fin_succ_equiv_symm_coe, fin.cons_succ] },\n { rw [comp_app, fin_succ_equiv_symm_none, fin.cons_zero] },\n { ext,\n rw [comp_app, comp_app, fin_succ_equiv_symm_coe, fin.cons_succ] }\nend\n\nlemma linear_independent_fin_snoc {n} {v : fin n \u2192 V} :\n linear_independent K (fin.snoc v x : fin (n + 1) \u2192 V) \u2194\n linear_independent K v \u2227 x \u2209 submodule.span K (range v) :=\nby rw [fin.snoc_eq_cons_rotate, linear_independent_equiv, linear_independent_fin_cons]\n\n\/-- See `linear_independent.fin_cons'` for an uglier version that works if you\nonly have a module over a semiring. -\/\nlemma linear_independent.fin_cons {n} {v : fin n \u2192 V} (hv : linear_independent K v)\n (hx : x \u2209 submodule.span K (range v)) :\n linear_independent K (fin.cons x v : fin (n + 1) \u2192 V) :=\nlinear_independent_fin_cons.2 \u27e8hv, hx\u27e9\n\nlemma linear_independent_fin_succ {n} {v : fin (n + 1) \u2192 V} :\n linear_independent K v \u2194\n linear_independent K (fin.tail v) \u2227 v 0 \u2209 submodule.span K (range $ fin.tail v) :=\nby rw [\u2190 linear_independent_fin_cons, fin.cons_self_tail]\n\nlemma linear_independent_fin_succ' {n} {v : fin (n + 1) \u2192 V} :\n linear_independent K v \u2194\n linear_independent K (fin.init v) \u2227 v (fin.last _) \u2209 submodule.span K (range $ fin.init v) :=\nby rw [\u2190 linear_independent_fin_snoc, fin.snoc_init_self]\n\nlemma linear_independent_fin2 {f : fin 2 \u2192 V} :\n linear_independent K f \u2194 f 1 \u2260 0 \u2227 \u2200 a : K, a \u2022 f 1 \u2260 f 0 :=\nby rw [linear_independent_fin_succ, linear_independent_unique_iff, range_unique,\n mem_span_singleton, not_exists,\n show fin.tail f (default (fin 1)) = f 1, by rw \u2190 fin.succ_zero_eq_one; refl]\n\nlemma exists_linear_independent (hs : linear_independent K (\u03bb x, x : s \u2192 V)) (hst : s \u2286 t) :\n \u2203b\u2286t, s \u2286 b \u2227 t \u2286 span K b \u2227 linear_independent K (\u03bb x, x : b \u2192 V) :=\nbegin\n rcases zorn.zorn_subset_nonempty {b | b \u2286 t \u2227 linear_independent K (\u03bb x, x : b \u2192 V)} _ _\n \u27e8hst, hs\u27e9 with \u27e8b, \u27e8bt, bi\u27e9, sb, h\u27e9,\n { refine \u27e8b, bt, sb, \u03bb x xt, _, bi\u27e9,\n by_contra hn,\n apply hn,\n rw \u2190 h _ \u27e8insert_subset.2 \u27e8xt, bt\u27e9, bi.insert hn\u27e9 (subset_insert _ _),\n exact subset_span (mem_insert _ _) },\n { refine \u03bb c hc cc c0, \u27e8\u22c3\u2080 c, \u27e8_, _\u27e9, \u03bb x, _\u27e9,\n { exact sUnion_subset (\u03bb x xc, (hc xc).1) },\n { exact linear_independent_sUnion_of_directed cc.directed_on (\u03bb x xc, (hc xc).2) },\n { exact subset_sUnion_of_mem } }\nend\n\n\/-- `linear_independent.extend` adds vectors to a linear independent set `s \u2286 t` until it spans\nall elements of `t`. -\/\nnoncomputable def linear_independent.extend (hs : linear_independent K (\u03bb x, x : s \u2192 V))\n (hst : s \u2286 t) : set V :=\nclassical.some (exists_linear_independent hs hst)\n\nlemma linear_independent.extend_subset (hs : linear_independent K (\u03bb x, x : s \u2192 V))\n (hst : s \u2286 t) : hs.extend hst \u2286 t :=\nlet \u27e8hbt, hsb, htb, hli\u27e9 := classical.some_spec (exists_linear_independent hs hst) in hbt\n\nlemma linear_independent.subset_extend (hs : linear_independent K (\u03bb x, x : s \u2192 V))\n (hst : s \u2286 t) : s \u2286 hs.extend hst :=\nlet \u27e8hbt, hsb, htb, hli\u27e9 := classical.some_spec (exists_linear_independent hs hst) in hsb\n\nlemma linear_independent.subset_span_extend (hs : linear_independent K (\u03bb x, x : s \u2192 V))\n (hst : s \u2286 t) : t \u2286 span K (hs.extend hst) :=\nlet \u27e8hbt, hsb, htb, hli\u27e9 := classical.some_spec (exists_linear_independent hs hst) in htb\n\nlemma linear_independent.linear_independent_extend (hs : linear_independent K (\u03bb x, x : s \u2192 V))\n (hst : s \u2286 t) : linear_independent K (coe : hs.extend hst \u2192 V) :=\nlet \u27e8hbt, hsb, htb, hli\u27e9 := classical.some_spec (exists_linear_independent hs hst) in hli\n\nvariables {K V}\n\n-- TODO(Mario): rewrite?\nlemma exists_of_linear_independent_of_finite_span {t : finset V}\n (hs : linear_independent K (\u03bb x, x : s \u2192 V)) (hst : s \u2286 (span K \u2191t : submodule K V)) :\n \u2203t':finset V, \u2191t' \u2286 s \u222a \u2191t \u2227 s \u2286 \u2191t' \u2227 t'.card = t.card :=\nhave \u2200t, \u2200(s' : finset V), \u2191s' \u2286 s \u2192 s \u2229 \u2191t = \u2205 \u2192 s \u2286 (span K \u2191(s' \u222a t) : submodule K V) \u2192\n \u2203t':finset V, \u2191t' \u2286 s \u222a \u2191t \u2227 s \u2286 \u2191t' \u2227 t'.card = (s' \u222a t).card :=\nassume t, finset.induction_on t\n (assume s' hs' _ hss',\n have s = \u2191s',\n from eq_of_linear_independent_of_span_subtype hs hs' $\n by simpa using hss',\n \u27e8s', by simp [this]\u27e9)\n (assume b\u2081 t hb\u2081t ih s' hs' hst hss',\n have hb\u2081s : b\u2081 \u2209 s,\n from assume h,\n have b\u2081 \u2208 s \u2229 \u2191(insert b\u2081 t), from \u27e8h, finset.mem_insert_self _ _\u27e9,\n by rwa [hst] at this,\n have hb\u2081s' : b\u2081 \u2209 s', from assume h, hb\u2081s $ hs' h,\n have hst : s \u2229 \u2191t = \u2205,\n from eq_empty_of_subset_empty $ subset.trans\n (by simp [inter_subset_inter, subset.refl]) (le_of_eq hst),\n classical.by_cases\n (assume : s \u2286 (span K \u2191(s' \u222a t) : submodule K V),\n let \u27e8u, hust, hsu, eq\u27e9 := ih _ hs' hst this in\n have hb\u2081u : b\u2081 \u2209 u, from assume h, (hust h).elim hb\u2081s hb\u2081t,\n \u27e8insert b\u2081 u, by simp [insert_subset_insert hust],\n subset.trans hsu (by simp), by simp [eq, hb\u2081t, hb\u2081s', hb\u2081u]\u27e9)\n (assume : \u00ac s \u2286 (span K \u2191(s' \u222a t) : submodule K V),\n let \u27e8b\u2082, hb\u2082s, hb\u2082t\u27e9 := not_subset.mp this in\n have hb\u2082t' : b\u2082 \u2209 s' \u222a t, from assume h, hb\u2082t $ subset_span h,\n have s \u2286 (span K \u2191(insert b\u2082 s' \u222a t) : submodule K V), from\n assume b\u2083 hb\u2083,\n have \u2191(s' \u222a insert b\u2081 t) \u2286 insert b\u2081 (insert b\u2082 \u2191(s' \u222a t) : set V),\n by simp [insert_eq, -singleton_union, -union_singleton, union_subset_union, subset.refl,\n subset_union_right],\n have hb\u2083 : b\u2083 \u2208 span K (insert b\u2081 (insert b\u2082 \u2191(s' \u222a t) : set V)),\n from span_mono this (hss' hb\u2083),\n have s \u2286 (span K (insert b\u2081 \u2191(s' \u222a t)) : submodule K V),\n by simpa [insert_eq, -singleton_union, -union_singleton] using hss',\n have hb\u2081 : b\u2081 \u2208 span K (insert b\u2082 \u2191(s' \u222a t)),\n from mem_span_insert_exchange (this hb\u2082s) hb\u2082t,\n by rw [span_insert_eq_span hb\u2081] at hb\u2083; simpa using hb\u2083,\n let \u27e8u, hust, hsu, eq\u27e9 := ih _ (by simp [insert_subset, hb\u2082s, hs']) hst this in\n \u27e8u, subset.trans hust $ union_subset_union (subset.refl _) (by simp [subset_insert]),\n hsu, by simp [eq, hb\u2082t', hb\u2081t, hb\u2081s']\u27e9)),\nbegin\n have eq : t.filter (\u03bbx, x \u2208 s) \u222a t.filter (\u03bbx, x \u2209 s) = t,\n { ext1 x,\n by_cases x \u2208 s; simp * },\n apply exists.elim (this (t.filter (\u03bbx, x \u2209 s)) (t.filter (\u03bbx, x \u2208 s))\n (by simp [set.subset_def]) (by simp [set.ext_iff] {contextual := tt}) (by rwa [eq])),\n intros u h,\n exact \u27e8u, subset.trans h.1 (by simp [subset_def, and_imp, or_imp_distrib] {contextual:=tt}),\n h.2.1, by simp only [h.2.2, eq]\u27e9\nend\n\nlemma exists_finite_card_le_of_finite_of_linear_independent_of_span\n (ht : finite t) (hs : linear_independent K (\u03bb x, x : s \u2192 V)) (hst : s \u2286 span K t) :\n \u2203h : finite s, h.to_finset.card \u2264 ht.to_finset.card :=\nhave s \u2286 (span K \u2191(ht.to_finset) : submodule K V), by simp; assumption,\nlet \u27e8u, hust, hsu, eq\u27e9 := exists_of_linear_independent_of_finite_span hs this in\nhave finite s, from u.finite_to_set.subset hsu,\n\u27e8this, by rw [\u2190eq]; exact (finset.card_le_of_subset $ finset.coe_subset.mp $ by simp [hsu])\u27e9\n\nend module\n","avg_line_length":42.9913344887,"max_line_length":100,"alphanum_fraction":0.6652624365} -{"size":457,"ext":"lean","lang":"Lean","max_stars_count":12.0,"content":"\/-\nCopyright (c) 2021 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f\n-\/\nimport mathzoo.imports.miniF2F\n\nopen_locale nat rat real big_operators topological_space\n\ntheorem mathd_algebra_451\n (\u03c3 : equiv \u211d \u211d)\n (h\u2080 : \u03c3.2 (-15) = 0)\n (h\u2081 : \u03c3.2 0 = 3)\n (h\u2082 : \u03c3.2 3 = 9)\n (h\u2083 : \u03c3.2 9 = 20) :\n \u03c3.1 (\u03c3.1 9) = 0 :=\nbegin\n simp [\u2190 h\u2081, \u2190 h\u2082],\nend","avg_line_length":24.0526315789,"max_line_length":67,"alphanum_fraction":0.6630196937} -{"size":852,"ext":"lean","lang":"Lean","max_stars_count":1.0,"content":"\/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-\/\nimport data.nat.sqrt\nimport data.int.basic\n\nnamespace int\n\n\/-- `sqrt n` is the square root of an integer `n`. If `n` is not a\n perfect square, and is positive, it returns the largest `k:\u2124` such\n that `k*k \u2264 n`. If it is negative, it returns 0. For example,\n `sqrt 2 = 1` and `sqrt 1 = 1` and `sqrt (-1) = 0` -\/\ndef sqrt (n : \u2124) : \u2124 :=\nnat.sqrt $ int.to_nat n\n\ntheorem sqrt_eq (n : \u2124) : sqrt (n*n) = n.nat_abs :=\nby rw [sqrt, \u2190 nat_abs_mul_self, to_nat_coe_nat, nat.sqrt_eq]\n\ntheorem exists_mul_self (x : \u2124) :\n (\u2203 n, n * n = x) \u2194 sqrt x * sqrt x = x :=\n\u27e8\u03bb \u27e8n, hn\u27e9, by rw [\u2190 hn, sqrt_eq, \u2190 int.coe_nat_mul, nat_abs_mul_self],\n\u03bb h, \u27e8sqrt x, h\u27e9\u27e9\n\ntheorem sqrt_nonneg (n : \u2124) : 0 \u2264 sqrt n := trivial\n\nend int\n","avg_line_length":29.3793103448,"max_line_length":71,"alphanum_fraction":0.646713615} -{"size":1610,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2018 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jeremy Avigad, Mario Carneiro, Simon Hudon, Alex Keizer\n-\/\n\nimport Qpf.MathlibPort.Fin2\nimport Qpf.Util.HEq\nimport Lean.Elab.Tactic.Conv\n\nuniverse u v w\n\nabbrev DVec {n : Nat} (\u03b1s : Fin2 n \u2192 Type u) : Type _\n := (i : Fin2 n) \u2192 \u03b1s i\n\nabbrev Vec (\u03b1 : Type _) (n : Nat)\n := @DVec n fun _ => \u03b1\n\nnamespace Vec\n def append1 {\u03b1 : Type u} {n} (tl : Vec \u03b1 n) (hd : \u03b1) : Vec \u03b1 (n+1)\n | (Fin2.fs i) => tl i\n | Fin2.fz => hd\n\n -- infixl:67 \" ::: \" => append1\n\n \/-- Drop the last element from a `Vec` -\/\n def drop (v : Vec \u03b1 (n+1)) : Vec \u03b1 n\n := fun i => v (Fin2.fs i)\n\n def constVec {\u03b1 : Type _} (a : \u03b1) (n : Nat) : Vec \u03b1 n\n := fun _ => a\nend Vec\n\nunif_hint (n : Nat) where |- Fin2 n \u2192 Type u =?= Vec (Type u) n\nunif_hint {\u03b1 : Type _} (n : Nat) where |- DVec (Vec.constVec \u03b1 n) =?= Vec \u03b1 n\n\nnamespace DVec\n \/-- Return the last element from a `DVec` -\/\n def last (v : @DVec (n+1) \u03b1s ) : \u03b1s 0\n := v 0\n\n \/-- Drop the last element from a `DVec` -\/\n def drop (v : DVec \u03b1s) : DVec (Vec.drop \u03b1s)\n := fun i => v (Fin2.fs i)\n\n @[reducible]\n def nil : @DVec 0 \u03b1s\n := fun emp => by contradiction\n\n @[reducible]\n def append1 {\u03b1 : Type u} {\u03b1s : Vec (Type u) n} (tl : DVec \u03b1s) (hd : \u03b1) : DVec (Vec.append1 \u03b1s \u03b1)\n | (Fin2.fs i) => tl i\n | Fin2.fz => hd\n \n\n -- infixl:67 \" ::: \" => append1\nend DVec\n\nnamespace Vec\n variable {\u03b1 : Type _} {n : Nat}\n\n abbrev nil : Vec \u03b1 0 := DVec.nil\n abbrev last : Vec \u03b1 n.succ \u2192 \u03b1 := DVec.last\nend Vec\n","avg_line_length":24.7692307692,"max_line_length":98,"alphanum_fraction":0.5664596273} -{"size":3579,"ext":"lean","lang":"Lean","max_stars_count":71.0,"content":"\/-\nCopyright (c) 2016 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-\/\nimport Lean.Parser.Term\nimport Mathlib.Init.SetNotation\n\n\/-!\n\n# Sets\n\nThis file sets up the theory of sets whose elements have a given type.\n\n## Main definitions\n\nGiven a type `X` and a predicate `p : X \u2192 Prop`:\n\n* `Set X` : the type of sets whose elements have type `X`\n* `{a : X | p a} : Set X` : the set of all elements of `X` satisfying `p`\n* `{a | p a} : Set X` : a more concise notation for `{a : X | p a}`\n* `{a \u2208 S | p a} : Set X` : given `S : Set X`, the subset of `S` consisting of\n its elements satisfying `p`.\n\n## Implementation issues\n\nAs in Lean 3, `Set X := X \u2192 Prop`\n\nI didn't call this file Data.Set.Basic because it contains core Lean 3\nstuff which happens before mathlib3's data.set.basic .\nThis file is a port of the core Lean 3 file `lib\/lean\/library\/init\/data\/set.lean`.\n\n-\/\n\ndef Set (\u03b1 : Type u) := \u03b1 \u2192 Prop\n\ndef setOf {\u03b1 : Type u} (p : \u03b1 \u2192 Prop) : Set \u03b1 :=\np\n\nnamespace Set\n\nprotected def mem (a : \u03b1) (s : Set \u03b1) :=\ns a\n\ninstance : Mem \u03b1 (Set \u03b1) :=\n\u27e8Set.mem\u27e9\n\nprotected def subset (s\u2081 s\u2082 : Set \u03b1) :=\n\u2200 {a}, a \u2208 s\u2081 \u2192 a \u2208 s\u2082\n\ninstance : Subset (Set \u03b1) :=\n\u27e8Set.subset\u27e9\n\ninstance : EmptyCollection (Set \u03b1) :=\n\u27e8\u03bb a => false\u27e9\n\nopen Mathlib.ExtendedBinder in\nsyntax \"{ \" extBinder \" | \" term \" }\" : term\n\nmacro_rules\n | `({ $x:ident | $p }) => `(setOf fun $x:ident => $p)\n | `({ $x:ident : $t | $p }) => `(setOf fun $x:ident : $t => $p)\n | `({ $x:ident $b:binderPred | $p }) =>\n `(setOf fun $x:ident => satisfiesBinderPred% $x $b \u2227 $p)\n\n@[appUnexpander setOf]\ndef setOf.unexpander : Lean.PrettyPrinter.Unexpander\n | `(setOf fun $x:ident => $p) => `({ $x:ident | $p })\n | `(setOf fun $x:ident : $ty:term => $p) => `({ $x:ident : $ty:term | $p })\n | _ => throw ()\n\nopen Mathlib.ExtendedBinder in\nmacro (priority := low) \"{ \" t:term \" | \" bs:extBinders \" }\" : term =>\n `({ x | \u2203\u1d49 $bs:extBinders, $t = x })\n\ndef univ : Set \u03b1 := {a | True }\n\nprotected def insert (a : \u03b1) (s : Set \u03b1) : Set \u03b1 :=\n{b | b = a \u2228 b \u2208 s}\n\nprotected def singleton (a : \u03b1) : Set \u03b1 :=\n{b | b = a}\n\nprotected def union (s\u2081 s\u2082 : Set \u03b1) : Set \u03b1 :=\n{a | a \u2208 s\u2081 \u2228 a \u2208 s\u2082}\n\ninstance : Union (Set \u03b1) :=\n\u27e8Set.union\u27e9\n\nprotected def inter (s\u2081 s\u2082 : Set \u03b1) : Set \u03b1 :=\n{a | a \u2208 s\u2081 \u2227 a \u2208 s\u2082}\n\ninstance : Inter (Set \u03b1) :=\n\u27e8Set.inter\u27e9\n\ndef compl (s : Set \u03b1) : Set \u03b1 :=\n{a | a \u2209 s}\n\nprotected def diff (s t : Set \u03b1) : Set \u03b1 :=\n{a \u2208 s | a \u2209 t}\n\ninstance : Sdiff (Set \u03b1) :=\n\u27e8Set.diff\u27e9\n\ndef powerset (s : Set \u03b1) : Set (Set \u03b1) :=\n{t | t \u2286 s}\n\nprefix:100 \"\ud835\udcab\" => powerset\n\n@[reducible]\ndef sUnion (s : Set (Set \u03b1)) : Set \u03b1 := {t | \u2203 a \u2208 s, t \u2208 a}\n\nprefix:110 \"\u22c3\u2080\" => sUnion\n\ndef image (f : \u03b1 \u2192 \u03b2) (s : Set \u03b1) : Set \u03b2 :=\n { f a | a \u2208 s }\n\ninstance : Functor Set :=\n{ map := @Set.image }\n\ninstance : LawfulFunctor Set where\n id_map s := funext $ \u03bb b => propext \u27e8\u03bb \u27e8_, sb, rfl\u27e9 => sb, \u03bb sb => \u27e8_, sb, rfl\u27e9\u27e9\n comp_map g h s := funext $ \u03bb c => propext\n \u27e8\u03bb \u27e8a, \u27e8h\u2081, h\u2082\u27e9\u27e9 => \u27e8g a, \u27e8\u27e8a, \u27e8h\u2081, rfl\u27e9\u27e9, h\u2082\u27e9\u27e9,\n \u03bb \u27e8b, \u27e8\u27e8a, \u27e8h\u2081, h\u2082\u27e9\u27e9, h\u2083\u27e9\u27e9 => \u27e8a, \u27e8h\u2081, show h (g a) = c from h\u2082 \u25b8 h\u2083\u27e9\u27e9\u27e9\n map_const := rfl\n\nsyntax (priority := high) \"{\" term,+ \"}\" : term\n\nmacro_rules\n | `({$x}) => `(Set.singleton $x)\n | `({$x, $xs:term,*}) => `(Set.insert $x {$xs,*})\n\n@[appUnexpander Set.singleton]\ndef singletonUnexpander : Lean.PrettyPrinter.Unexpander\n| `(Set.singleton $a) => `({ $a })\n| _ => throw ()\n\n@[appUnexpander Set.insert]\ndef insertUnexpander : Lean.PrettyPrinter.Unexpander\n| `(Set.insert $a { $ts,* }) => `({$a, $ts,*})\n| _ => throw ()\n\nend Set\n","avg_line_length":24.6827586207,"max_line_length":82,"alphanum_fraction":0.5736239173} -{"size":24132,"ext":"lean","lang":"Lean","max_stars_count":1.0,"content":"\/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Heather Macbeth.\n-\/\nimport analysis.calculus.times_cont_diff\nimport topology.local_homeomorph\nimport topology.metric_space.contracting\n\n\/-!\n# Inverse function theorem\n\nIn this file we prove the inverse function theorem. It says that if a map `f : E \u2192 F`\nhas an invertible strict derivative `f'` at `a`, then it is locally invertible,\nand the inverse function has derivative `f' \u207b\u00b9`.\n\nWe define `has_strict_deriv_at.to_local_homeomorph` that repacks a function `f`\nwith a `hf : has_strict_fderiv_at f f' a`, `f' : E \u2243L[\ud835\udd5c] F`, into a `local_homeomorph`.\nThe `to_fun` of this `local_homeomorph` is `defeq` to `f`, so one can apply theorems\nabout `local_homeomorph` to `hf.to_local_homeomorph f`, and get statements about `f`.\n\nThen we define `has_strict_fderiv_at.local_inverse` to be the `inv_fun` of this `local_homeomorph`,\nand prove two versions of the inverse function theorem:\n\n* `has_strict_fderiv_at.to_local_inverse`: if `f` has an invertible derivative `f'` at `a` in the\n strict sense (`hf`), then `hf.local_inverse f f' a` has derivative `f'.symm` at `f a` in the\n strict sense;\n\n* `has_strict_fderiv_at.to_local_left_inverse`: if `f` has an invertible derivative `f'` at `a` in\n the strict sense and `g` is locally left inverse to `f` near `a`, then `g` has derivative\n `f'.symm` at `f a` in the strict sense.\n\nIn the one-dimensional case we reformulate these theorems in terms of `has_strict_deriv_at` and\n`f'\u207b\u00b9`.\n\nWe also reformulate the theorems in terms of `times_cont_diff`, to give that `C^k` (respectively,\nsmooth) inputs give `C^k` (smooth) inverses. These versions require that continuous\ndifferentiability implies strict differentiability; this is false over a general field, true over\n`\u211d` (the setting in which it is implemented here), and true but (TODO) not yet implemented over `\u2102`.\n\nSome related theorems, providing the derivative and higher regularity assuming that we already know\nthe inverse function, are formulated in `fderiv.lean`, `deriv.lean`, and `times_cont_diff.lean`.\n\n## Notations\n\nIn the section about `approximates_linear_on` we introduce some `local notation` to make formulas\nshorter:\n\n* by `N` we denote `\u2225f'\u207b\u00b9\u2225`;\n* by `g` we denote the auxiliary contracting map `x \u21a6 x + f'.symm (y - f x)` used to prove that\n `{x | f x = y}` is nonempty.\n\n## Tags\n\nderivative, strictly differentiable, continuously differentiable, smooth, inverse function\n-\/\n\nopen function set filter metric\nopen_locale topological_space classical nnreal\n\nnoncomputable theory\n\nvariables {\ud835\udd5c : Type*} [nondiscrete_normed_field \ud835\udd5c]\nvariables {E : Type*} [normed_group E] [normed_space \ud835\udd5c E]\nvariables {F : Type*} [normed_group F] [normed_space \ud835\udd5c F]\nvariables {G : Type*} [normed_group G] [normed_space \ud835\udd5c G]\nvariables {G' : Type*} [normed_group G'] [normed_space \ud835\udd5c G']\n\nopen asymptotics filter metric set\nopen continuous_linear_map (id)\n\n\/-!\n### Non-linear maps approximating close to affine maps\n\nIn this section we study a map `f` such that `\u2225f x - f y - f' (x - y)\u2225 \u2264 c * \u2225x - y\u2225` on an open set\n`s`, where `f' : E \u2243L[\ud835\udd5c] F` is a continuous linear equivalence and `c < \u2225f'\u207b\u00b9\u2225`. Maps of this type\nbehave like `f a + f' (x - a)` near each `a \u2208 s`.\n\nIf `E` is a complete space, we prove that the image `f '' s` is open, and `f` is a homeomorphism\nbetween `s` and `f '' s`. More precisely, we define `approximates_linear_on.to_local_homeomorph` to\nbe a `local_homeomorph` with `to_fun = f`, `source = s`, and `target = f '' s`.\n\nMaps of this type naturally appear in the proof of the inverse function theorem (see next section),\nand `approximates_linear_on.to_local_homeomorph` will imply that the locally inverse function\nexists.\n\nWe define this auxiliary notion to split the proof of the inverse function theorem into small\nlemmas. This approach makes it possible\n\n- to prove a lower estimate on the size of the domain of the inverse function;\n\n- to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a\n function `f : E \u00d7 F \u2192 G` with estimates on `f x y\u2081 - f x y\u2082` but not on `f x\u2081 y - f x\u2082 y`.\n-\/\n\n\/-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`,\nif `\u2225f x - f y - f' (x - y)\u2225 \u2264 c * \u2225x - y\u2225` whenever `x, y \u2208 s`.\n\nThis predicate is defined to facilitate the splitting of the inverse function theorem into small\nlemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined\non a specific set. -\/\ndef approximates_linear_on (f : E \u2192 F) (f' : E \u2192L[\ud835\udd5c] F) (s : set E) (c : \u211d\u22650) : Prop :=\n\u2200 (x \u2208 s) (y \u2208 s), \u2225f x - f y - f' (x - y)\u2225 \u2264 c * \u2225x - y\u2225\n\nnamespace approximates_linear_on\n\nvariables [cs : complete_space E] {f : E \u2192 F}\n\n\/-! First we prove some properties of a function that `approximates_linear_on` a (not necessarily\ninvertible) continuous linear map. -\/\n\nsection\n\nvariables {f' : E \u2192L[\ud835\udd5c] F} {s t : set E} {c c' : \u211d\u22650}\n\ntheorem mono_num (hc : c \u2264 c') (hf : approximates_linear_on f f' s c) :\n approximates_linear_on f f' s c' :=\n\u03bb x hx y hy, le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc $ norm_nonneg _)\n\ntheorem mono_set (hst : s \u2286 t) (hf : approximates_linear_on f f' t c) :\n approximates_linear_on f f' s c :=\n\u03bb x hx y hy, hf x (hst hx) y (hst hy)\n\nlemma lipschitz_sub (hf : approximates_linear_on f f' s c) :\n lipschitz_with c (\u03bb x : s, f x - f' x) :=\nbegin\n refine lipschitz_with.of_dist_le_mul (\u03bb x y, _),\n rw [dist_eq_norm, subtype.dist_eq, dist_eq_norm],\n convert hf x x.2 y y.2 using 2,\n rw [f'.map_sub], abel\nend\n\nprotected lemma lipschitz (hf : approximates_linear_on f f' s c) :\n lipschitz_with (nnnorm f' + c) (s.restrict f) :=\nby simpa only [restrict_apply, add_sub_cancel'_right]\n using (f'.lipschitz.restrict s).add hf.lipschitz_sub\n\nprotected lemma continuous (hf : approximates_linear_on f f' s c) :\n continuous (s.restrict f) :=\nhf.lipschitz.continuous\n\nprotected lemma continuous_on (hf : approximates_linear_on f f' s c) :\n continuous_on f s :=\ncontinuous_on_iff_continuous_restrict.2 hf.continuous\n\nend\n\n\/-!\nFrom now on we assume that `f` approximates an invertible continuous linear map `f : E \u2243L[\ud835\udd5c] F`.\n\nWe also assume that either `E = {0}`, or `c < \u2225f'\u207b\u00b9\u2225\u207b\u00b9`. We use `N` as an abbreviation for `\u2225f'\u207b\u00b9\u2225`.\n-\/\n\nvariables {f' : E \u2243L[\ud835\udd5c] F} {s : set E} {c : \u211d\u22650}\n\nlocal notation `N` := nnnorm (f'.symm : F \u2192L[\ud835\udd5c] E)\n\nprotected lemma antilipschitz (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) :\n antilipschitz_with (N\u207b\u00b9 - c)\u207b\u00b9 (s.restrict f) :=\nbegin\n cases hc with hE hc,\n { haveI : subsingleton s := \u27e8\u03bb x y, subtype.eq $ @subsingleton.elim _ hE _ _\u27e9,\n exact antilipschitz_with.of_subsingleton },\n convert (f'.antilipschitz.restrict s).add_lipschitz_with hf.lipschitz_sub hc,\n simp [restrict]\nend\n\nprotected lemma injective (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) :\n injective (s.restrict f) :=\n(hf.antilipschitz hc).injective\n\nprotected lemma inj_on (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) :\n inj_on f s :=\ninj_on_iff_injective.2 $ hf.injective hc\n\n\/-- A map approximating a linear equivalence on a set defines a local equivalence on this set.\nShould not be used outside of this file, because it is superseded by `to_local_homeomorph` below.\n\nThis is a first step towards the inverse function. -\/\ndef to_local_equiv (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) : local_equiv E F :=\n(hf.inj_on hc).to_local_equiv _ _\n\n\/-- The inverse function is continuous on `f '' s`. Use properties of `local_homeomorph` instead. -\/\nlemma inverse_continuous_on (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) :\n continuous_on (hf.to_local_equiv hc).symm (f '' s) :=\nbegin\n apply continuous_on_iff_continuous_restrict.2,\n refine ((hf.antilipschitz hc).to_right_inv_on' _ (hf.to_local_equiv hc).right_inv').continuous,\n exact (\u03bb x hx, (hf.to_local_equiv hc).map_target hx)\nend\n\n\/-!\nNow we prove that `f '' s` is an open set. This follows from the fact that the restriction of `f`\non `s` is an open map. More precisely, we show that the image of a closed ball $$\\bar B(a, \u03b5) \u2286 s$$\nunder `f` includes the closed ball $$\\bar B\\left(f(a), \\frac{\u03b5}{\u2225{f'}\u207b\u00b9\u2225\u207b\u00b9-c}\\right)$$.\n\nIn order to do this, we introduce an auxiliary map $$g_y(x) = x + {f'}\u207b\u00b9 (y - f x)$$. Provided that\n$$\u2225y - f a\u2225 \u2264 \\frac{\u03b5}{\u2225{f'}\u207b\u00b9\u2225\u207b\u00b9-c}$$, we prove that $$g_y$$ contracts in $$\\bar B(a, \u03b5)$$ and `f`\nsends the fixed point of $$g_y$$ to `y`.\n-\/\n\nsection\n\nvariables (f f')\n\n\/-- Iterations of this map converge to `f\u207b\u00b9 y`. The formula is very similar to the one\nused in Newton's method, but we use the same `f'.symm` for all `y` instead of evaluating\nthe derivative at each point along the orbit. -\/\ndef inverse_approx_map (y : F) (x : E) : E := x + f'.symm (y - f x)\n\nend\n\nsection inverse_approx_map\n\nvariables (y : F) {x x' : E} {\u03b5 : \u211d}\n\nlocal notation `g` := inverse_approx_map f f' y\n\nlemma inverse_approx_map_sub (x x' : E) : g x - g x' = (x - x') - f'.symm (f x - f x') :=\nby { simp only [inverse_approx_map, f'.symm.map_sub], abel }\n\nlemma inverse_approx_map_dist_self (x : E) :\n dist (g x) x = dist (f'.symm $ f x) (f'.symm y) :=\nby simp only [inverse_approx_map, dist_eq_norm, f'.symm.map_sub, add_sub_cancel', norm_sub_rev]\n\nlemma inverse_approx_map_dist_self_le (x : E) :\n dist (g x) x \u2264 N * dist (f x) y :=\nby { rw inverse_approx_map_dist_self, exact f'.symm.lipschitz.dist_le_mul (f x) y }\n\nlemma inverse_approx_map_fixed_iff {x : E} :\n g x = x \u2194 f x = y :=\nby rw [\u2190 dist_eq_zero, inverse_approx_map_dist_self, dist_eq_zero, f'.symm.injective.eq_iff]\n\nlemma inverse_approx_map_contracts_on (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n {x x'} (hx : x \u2208 s) (hx' : x' \u2208 s) :\n dist (g x) (g x') \u2264 N * c * dist x x' :=\nbegin\n rw [dist_eq_norm, dist_eq_norm, inverse_approx_map_sub, norm_sub_rev],\n suffices : \u2225f'.symm (f x - f x' - f' (x - x'))\u2225 \u2264 N * (c * \u2225x - x'\u2225),\n by simpa only [f'.symm.map_sub, f'.symm_apply_apply, mul_assoc] using this,\n exact (f'.symm : F \u2192L[\ud835\udd5c] E).le_op_norm_of_le (hf x hx x' hx')\nend\n\nvariable {y}\n\nlemma inverse_approx_map_maps_to (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) {b : E} (hb : b \u2208 s) (h\u03b5 : closed_ball b \u03b5 \u2286 s)\n (hy : y \u2208 closed_ball (f b) ((N\u207b\u00b9 - c) * \u03b5)) :\n maps_to g (closed_ball b \u03b5) (closed_ball b \u03b5) :=\nbegin\n cases hc with hE hc,\n { exactI \u03bb x hx, subsingleton.elim x (g x) \u25b8 hx },\n assume x hx,\n simp only [mem_closed_ball] at hx hy \u22a2,\n rw [dist_comm] at hy,\n calc dist (inverse_approx_map f f' y x) b \u2264\n dist (inverse_approx_map f f' y x) (inverse_approx_map f f' y b) +\n dist (inverse_approx_map f f' y b) b : dist_triangle _ _ _\n ... \u2264 N * c * dist x b + N * dist (f b) y :\n add_le_add (hf.inverse_approx_map_contracts_on y (h\u03b5 hx) hb)\n (inverse_approx_map_dist_self_le _ _)\n ... \u2264 N * c * \u03b5 + N * ((N\u207b\u00b9 - c) * \u03b5) :\n add_le_add (mul_le_mul_of_nonneg_left hx (mul_nonneg (nnreal.coe_nonneg _) c.coe_nonneg))\n (mul_le_mul_of_nonneg_left hy (nnreal.coe_nonneg _))\n ... = N * (c + (N\u207b\u00b9 - c)) * \u03b5 : by simp only [mul_add, add_mul, mul_assoc]\n ... = \u03b5 : by { rw [add_sub_cancel'_right, mul_inv_cancel, one_mul],\n exact ne_of_gt (inv_pos.1 $ lt_of_le_of_lt c.coe_nonneg hc) }\nend\n\nend inverse_approx_map\n\ninclude cs\n\nvariable {\u03b5 : \u211d}\n\ntheorem surj_on_closed_ball (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) {b : E} (\u03b50 : 0 \u2264 \u03b5) (h\u03b5 : closed_ball b \u03b5 \u2286 s) :\n surj_on f (closed_ball b \u03b5) (closed_ball (f b) ((N\u207b\u00b9 - c) * \u03b5)) :=\nbegin\n cases hc with hE hc,\n { resetI,\n haveI hF : subsingleton F := f'.symm.to_linear_equiv.to_equiv.subsingleton,\n intros y hy,\n exact \u27e8b, mem_closed_ball_self \u03b50, subsingleton.elim _ _\u27e9 },\n intros y hy,\n have : contracting_with (N * c) ((hf.inverse_approx_map_maps_to (or.inr hc)\n (h\u03b5 $ mem_closed_ball_self \u03b50) h\u03b5 hy).restrict _ _ _),\n { split,\n { rwa [mul_comm, \u2190 nnreal.lt_inv_iff_mul_lt],\n exact ne_of_gt (inv_pos.1 $ lt_of_le_of_lt c.coe_nonneg hc) },\n { exact lipschitz_with.of_dist_le_mul (\u03bb x x', hf.inverse_approx_map_contracts_on\n y (h\u03b5 x.mem) (h\u03b5 x'.mem)) } },\n refine \u27e8this.efixed_point' _ _ _ b (mem_closed_ball_self \u03b50) (edist_lt_top _ _), _, _\u27e9,\n { exact is_closed_ball.is_complete },\n { apply contracting_with.efixed_point_mem' },\n { exact (inverse_approx_map_fixed_iff y).1 (this.efixed_point_is_fixed_pt' _ _ _ _) }\nend\n\nsection\n\nvariables (f s)\n\n\/-- Given a function `f` that approximates a linear equivalence on an open set `s`,\nreturns a local homeomorph with `to_fun = f` and `source = s`. -\/\ndef to_local_homeomorph (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) (hs : is_open s) : local_homeomorph E F :=\n{ to_local_equiv := hf.to_local_equiv hc,\n open_source := hs,\n open_target :=\n begin\n cases hc with hE hc,\n { resetI,\n haveI hF : subsingleton F := f'.to_linear_equiv.to_equiv.symm.subsingleton,\n apply is_open_discrete },\n change is_open (f '' s),\n simp only [is_open_iff_mem_nhds, nhds_basis_closed_ball.mem_iff, ball_image_iff] at hs \u22a2,\n intros x hx,\n rcases hs x hx with \u27e8\u03b5, \u03b50, h\u03b5\u27e9,\n refine \u27e8(N\u207b\u00b9 - c) * \u03b5, mul_pos (sub_pos.2 hc) \u03b50, _\u27e9,\n exact (hf.surj_on_closed_ball (or.inr hc) (le_of_lt \u03b50) h\u03b5).mono h\u03b5 (subset.refl _)\n end,\n continuous_to_fun := hf.continuous_on,\n continuous_inv_fun := hf.inverse_continuous_on hc }\n\nend\n\n@[simp] lemma to_local_homeomorph_coe (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) (hs : is_open s) :\n (hf.to_local_homeomorph f s hc hs : E \u2192 F) = f := rfl\n\n@[simp] lemma to_local_homeomorph_source (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) (hs : is_open s) :\n (hf.to_local_homeomorph f s hc hs).source = s := rfl\n\n@[simp] lemma to_local_homeomorph_target (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) (hs : is_open s) :\n (hf.to_local_homeomorph f s hc hs).target = f '' s := rfl\n\nlemma closed_ball_subset_target (hf : approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s c)\n (hc : subsingleton E \u2228 c < N\u207b\u00b9) (hs : is_open s) {b : E} (\u03b50 : 0 \u2264 \u03b5) (h\u03b5 : closed_ball b \u03b5 \u2286 s) :\n closed_ball (f b) ((N\u207b\u00b9 - c) * \u03b5) \u2286 (hf.to_local_homeomorph f s hc hs).target :=\n(hf.surj_on_closed_ball hc \u03b50 h\u03b5).mono h\u03b5 (subset.refl _)\n\nend approximates_linear_on\n\n\/-!\n### Inverse function theorem\n\nNow we prove the inverse function theorem. Let `f : E \u2192 F` be a map defined on a complete vector\nspace `E`. Assume that `f` has an invertible derivative `f' : E \u2243L[\ud835\udd5c] F` at `a : E` in the strict\nsense. Then `f` approximates `f'` in the sense of `approximates_linear_on` on an open neighborhood\nof `a`, and we can apply `approximates_linear_on.to_local_homeomorph` to construct the inverse\nfunction. -\/\n\nnamespace has_strict_fderiv_at\n\n\/-- If `f` has derivative `f'` at `a` in the strict sense and `c > 0`, then `f` approximates `f'`\nwith constant `c` on some neighborhood of `a`. -\/\nlemma approximates_deriv_on_nhds {f : E \u2192 F} {f' : E \u2192L[\ud835\udd5c] F} {a : E}\n (hf : has_strict_fderiv_at f f' a) {c : \u211d\u22650} (hc : subsingleton E \u2228 0 < c) :\n \u2203 s \u2208 \ud835\udcdd a, approximates_linear_on f f' s c :=\nbegin\n cases hc with hE hc,\n { refine \u27e8univ, mem_nhds_sets is_open_univ trivial, \u03bb x hx y hy, _\u27e9,\n simp [@subsingleton.elim E hE x y] },\n have := hf.def hc,\n rw [nhds_prod_eq, filter.eventually, mem_prod_same_iff] at this,\n rcases this with \u27e8s, has, hs\u27e9,\n exact \u27e8s, has, \u03bb x hx y hy, hs (mk_mem_prod hx hy)\u27e9\nend\n\nvariables [cs : complete_space E] {f : E \u2192 F} {f' : E \u2243L[\ud835\udd5c] F} {a : E}\n\nlemma approximates_deriv_on_open_nhds (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n \u2203 (s : set E) (hs : a \u2208 s \u2227 is_open s),\n approximates_linear_on f (f' : E \u2192L[\ud835\udd5c] F) s ((nnnorm (f'.symm : F \u2192L[\ud835\udd5c] E))\u207b\u00b9 \/ 2) :=\nbegin\n refine ((nhds_basis_opens a).exists_iff _).1 _,\n exact (\u03bb s t, approximates_linear_on.mono_set),\n exact (hf.approximates_deriv_on_nhds $ f'.subsingleton_or_nnnorm_symm_pos.imp id $\n \u03bb hf', nnreal.half_pos $ nnreal.inv_pos.2 $ hf')\nend\n\ninclude cs\n\nvariable (f)\n\n\/-- Given a function with an invertible strict derivative at `a`, returns a `local_homeomorph`\nwith `to_fun = f` and `a \u2208 source`. This is a part of the inverse function theorem.\nThe other part `has_strict_fderiv_at.to_local_inverse` states that the inverse function\nof this `local_homeomorph` has derivative `f'.symm`. -\/\ndef to_local_homeomorph (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) : local_homeomorph E F :=\napproximates_linear_on.to_local_homeomorph f\n (classical.some hf.approximates_deriv_on_open_nhds)\n (classical.some_spec hf.approximates_deriv_on_open_nhds).snd\n (f'.subsingleton_or_nnnorm_symm_pos.imp id $ \u03bb hf', nnreal.half_lt_self $ ne_of_gt $\n nnreal.inv_pos.2 $ hf')\n (classical.some_spec hf.approximates_deriv_on_open_nhds).fst.2\n\nvariable {f}\n\n@[simp] lemma to_local_homeomorph_coe (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n (hf.to_local_homeomorph f : E \u2192 F) = f := rfl\n\nlemma mem_to_local_homeomorph_source (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n a \u2208 (hf.to_local_homeomorph f).source :=\n(classical.some_spec hf.approximates_deriv_on_open_nhds).fst.1\n\nlemma image_mem_to_local_homeomorph_target (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n f a \u2208 (hf.to_local_homeomorph f).target :=\n(hf.to_local_homeomorph f).map_source hf.mem_to_local_homeomorph_source\n\nvariables (f f' a)\n\n\/-- Given a function `f` with an invertible derivative, returns a function that is locally inverse\nto `f`. -\/\ndef local_inverse (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) : F \u2192 E :=\n(hf.to_local_homeomorph f).symm\n\nvariables {f f' a}\n\nlemma local_inverse_def (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n hf.local_inverse f _ _ = (hf.to_local_homeomorph f).symm :=\nrfl\n\nlemma eventually_left_inverse (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n \u2200\u1da0 x in \ud835\udcdd a, hf.local_inverse f f' a (f x) = x :=\n(hf.to_local_homeomorph f).eventually_left_inverse hf.mem_to_local_homeomorph_source\n\n@[simp] lemma local_inverse_apply_image (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n hf.local_inverse f f' a (f a) = a :=\nhf.eventually_left_inverse.self_of_nhds\n\nlemma eventually_right_inverse (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n \u2200\u1da0 y in \ud835\udcdd (f a), f (hf.local_inverse f f' a y) = y :=\n(hf.to_local_homeomorph f).eventually_right_inverse' hf.mem_to_local_homeomorph_source\n\nlemma local_inverse_continuous_at (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n continuous_at (hf.local_inverse f f' a) (f a) :=\n(hf.to_local_homeomorph f).continuous_at_symm hf.image_mem_to_local_homeomorph_target\n\nlemma local_inverse_tendsto (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n tendsto (hf.local_inverse f f' a) (\ud835\udcdd $ f a) (\ud835\udcdd a) :=\n(hf.to_local_homeomorph f).tendsto_symm hf.mem_to_local_homeomorph_source\n\nlemma local_inverse_unique (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) {g : F \u2192 E}\n (hg : \u2200\u1da0 x in \ud835\udcdd a, g (f x) = x) :\n \u2200\u1da0 y in \ud835\udcdd (f a), g y = local_inverse f f' a hf y :=\neventually_eq_of_left_inv_of_right_inv hg hf.eventually_right_inverse $\n (hf.to_local_homeomorph f).tendsto_symm hf.mem_to_local_homeomorph_source\n\n\/-- If `f` has an invertible derivative `f'` at `a` in the sense of strict differentiability `(hf)`,\nthen the inverse function `hf.local_inverse f` has derivative `f'.symm` at `f a`. -\/\ntheorem to_local_inverse (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) :\n has_strict_fderiv_at (hf.local_inverse f f' a) (f'.symm : F \u2192L[\ud835\udd5c] E) (f a) :=\n(hf.to_local_homeomorph f).has_strict_fderiv_at_symm hf.image_mem_to_local_homeomorph_target $\n by simpa [\u2190 local_inverse_def] using hf\n\n\/-- If `f : E \u2192 F` has an invertible derivative `f'` at `a` in the sense of strict differentiability\nand `g (f x) = x` in a neighborhood of `a`, then `g` has derivative `f'.symm` at `f a`.\n\nFor a version assuming `f (g y) = y` and continuity of `g` at `f a` but not `[complete_space E]`\nsee `of_local_left_inverse`. -\/\ntheorem to_local_left_inverse (hf : has_strict_fderiv_at f (f' : E \u2192L[\ud835\udd5c] F) a) {g : F \u2192 E}\n (hg : \u2200\u1da0 x in \ud835\udcdd a, g (f x) = x) :\n has_strict_fderiv_at g (f'.symm : F \u2192L[\ud835\udd5c] E) (f a) :=\nhf.to_local_inverse.congr_of_eventually_eq $ (hf.local_inverse_unique hg).mono $ \u03bb _, eq.symm\n\nend has_strict_fderiv_at\n\n\/-!\n### Inverse function theorem, 1D case\n\nIn this case we prove a version of the inverse function theorem for maps `f : \ud835\udd5c \u2192 \ud835\udd5c`.\nWe use `continuous_linear_equiv.units_equiv_aut` to translate `has_strict_deriv_at f f' a` and\n`f' \u2260 0` into `has_strict_fderiv_at f (_ : \ud835\udd5c \u2243L[\ud835\udd5c] \ud835\udd5c) a`.\n-\/\n\nnamespace has_strict_deriv_at\n\nvariables [cs : complete_space \ud835\udd5c] {f : \ud835\udd5c \u2192 \ud835\udd5c} {f' a : \ud835\udd5c} (hf : has_strict_deriv_at f f' a)\n (hf' : f' \u2260 0)\n\ninclude cs\n\nvariables (f f' a)\n\n\/-- A function that is inverse to `f` near `a`. -\/\n@[reducible] def local_inverse : \ud835\udd5c \u2192 \ud835\udd5c :=\n(hf.has_strict_fderiv_at_equiv hf').local_inverse _ _ _\n\nvariables {f f' a}\n\ntheorem to_local_inverse : has_strict_deriv_at (hf.local_inverse f f' a hf') f'\u207b\u00b9 (f a) :=\n(hf.has_strict_fderiv_at_equiv hf').to_local_inverse\n\ntheorem to_local_left_inverse {g : \ud835\udd5c \u2192 \ud835\udd5c} (hg : \u2200\u1da0 x in \ud835\udcdd a, g (f x) = x) :\n has_strict_deriv_at g f'\u207b\u00b9 (f a) :=\n(hf.has_strict_fderiv_at_equiv hf').to_local_left_inverse hg\n\nend has_strict_deriv_at\n\n\/-!\n### Inverse function theorem, smooth case\n\n-\/\n\nnamespace times_cont_diff_at\nvariables {E' : Type*} [normed_group E'] [normed_space \u211d E']\nvariables {F' : Type*} [normed_group F'] [normed_space \u211d F']\nvariables [complete_space E'] (f : E' \u2192 F') {f' : E' \u2243L[\u211d] F'} {a : E'}\n\n\/-- Given a `times_cont_diff` function over `\u211d` with an invertible derivative at `a`, returns a\n`local_homeomorph` with `to_fun = f` and `a \u2208 source`. -\/\ndef to_local_homeomorph\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n local_homeomorph E' F' :=\n(hf.has_strict_fderiv_at' hf' hn).to_local_homeomorph f\n\nvariable {f}\n\n@[simp] lemma to_local_homeomorph_coe\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n (hf.to_local_homeomorph f hf' hn : E' \u2192 F') = f := rfl\n\nlemma mem_to_local_homeomorph_source\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n a \u2208 (hf.to_local_homeomorph f hf' hn).source :=\n(hf.has_strict_fderiv_at' hf' hn).mem_to_local_homeomorph_source\n\nlemma image_mem_to_local_homeomorph_target\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n f a \u2208 (hf.to_local_homeomorph f hf' hn).target :=\n(hf.has_strict_fderiv_at' hf' hn).image_mem_to_local_homeomorph_target\n\n\/-- Given a `times_cont_diff` function over `\u211d` with an invertible derivative at `a`, returns a\nfunction that is locally inverse to `f`. -\/\ndef local_inverse\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n F' \u2192 E' :=\n(hf.has_strict_fderiv_at' hf' hn).local_inverse f f' a\n\nlemma local_inverse_apply_image\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n hf.local_inverse hf' hn (f a) = a :=\n(hf.has_strict_fderiv_at' hf' hn).local_inverse_apply_image\n\n\/-- Given a `times_cont_diff` function over `\u211d` with an invertible derivative at `a`, the inverse\nfunction (produced by `times_cont_diff.to_local_homeomorph`) is also `times_cont_diff`. -\/\nlemma to_local_inverse\n {n : with_top \u2115} (hf : times_cont_diff_at \u211d n f a) (hf' : has_fderiv_at f (f' : E' \u2192L[\u211d] F') a)\n (hn : 1 \u2264 n) :\n times_cont_diff_at \u211d n (hf.local_inverse hf' hn) (f a) :=\nbegin\n have := hf.local_inverse_apply_image hf' hn,\n apply (hf.to_local_homeomorph f hf' hn).times_cont_diff_at_symm\n (image_mem_to_local_homeomorph_target hf hf' hn),\n { convert hf' },\n { convert hf }\nend\n\nend times_cont_diff_at\n","avg_line_length":42.0418118467,"max_line_length":100,"alphanum_fraction":0.6883391348} -{"size":205,"ext":"lean","lang":"Lean","max_stars_count":2232.0,"content":"axiom I : Type\ndefinition F (X : Type) : Type := (X \u2192 Prop) \u2192 Prop\naxiom unfoldd : I \u2192 F I\naxiom foldd : F I \u2192 I\naxiom iso1 : \u2200x, foldd (unfoldd x) = x\n\ntheorem iso2 : \u2200x, foldd (unfoldd x) = x\n:= sorry\n","avg_line_length":22.7777777778,"max_line_length":51,"alphanum_fraction":0.5951219512} -{"size":3175,"ext":"hlean","lang":"Lean","max_stars_count":130.0,"content":"\/-\nCopyright (c) 2015 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris van Doorn\n\nDeclaration of the primitive hits in Lean\n-\/\n\nprelude\n\nimport .trunc .pathover\n\nopen is_trunc eq\n\n\/-\n We take two higher inductive types (hits) as primitive notions in Lean. We define all other hits\n in terms of these two hits. The hits which are primitive are\n - n-truncation\n - quotients (not truncated)\n For each of the hits we add the following constants:\n - the type formation\n - the term and path constructors\n - the dependent recursor\n We add the computation rule for point constructors judgmentally to the kernel of Lean.\n The computation rules for the path constructors are added (propositionally) as axioms\n\n In this file we only define the dependent recursor. For the nondependent recursor and all other\n uses of these hits, see the folder ..\/hit\/\n-\/\n\nconstant trunc.{u} (n : \u2115\u208b\u2082) (A : Type.{u}) : Type.{u}\n\nnamespace trunc\n constant tr {n : \u2115\u208b\u2082} {A : Type} (a : A) : trunc n A\n constant is_trunc_trunc (n : \u2115\u208b\u2082) (A : Type) : is_trunc n (trunc n A)\n\n attribute is_trunc_trunc [instance]\n\n protected constant rec {n : \u2115\u208b\u2082} {A : Type} {P : trunc n A \u2192 Type}\n [Pt : \u03a0aa, is_trunc n (P aa)] (H : \u03a0a, P (tr a)) : \u03a0aa, P aa\n\n protected definition rec_on [reducible] {n : \u2115\u208b\u2082} {A : Type}\n {P : trunc n A \u2192 Type} (aa : trunc n A) [Pt : \u03a0aa, is_trunc n (P aa)] (H : \u03a0a, P (tr a))\n : P aa :=\n trunc.rec H aa\nend trunc\n\nconstant quotient.{u v} {A : Type.{u}} (R : A \u2192 A \u2192 Type.{v}) : Type.{max u v}\n\nnamespace quotient\n\n constant class_of {A : Type} (R : A \u2192 A \u2192 Type) (a : A) : quotient R\n\n constant eq_of_rel {A : Type} (R : A \u2192 A \u2192 Type) \u2983a a' : A\u2984 (H : R a a')\n : class_of R a = class_of R a'\n\n protected constant rec {A : Type} {R : A \u2192 A \u2192 Type} {P : quotient R \u2192 Type}\n (Pc : \u03a0(a : A), P (class_of R a)) (Pp : \u03a0\u2983a a' : A\u2984 (H : R a a'), Pc a =[eq_of_rel R H] Pc a')\n (x : quotient R) : P x\n\n protected definition rec_on [reducible] {A : Type} {R : A \u2192 A \u2192 Type} {P : quotient R \u2192 Type}\n (x : quotient R) (Pc : \u03a0(a : A), P (class_of R a))\n (Pp : \u03a0\u2983a a' : A\u2984 (H : R a a'), Pc a =[eq_of_rel R H] Pc a') : P x :=\n quotient.rec Pc Pp x\n\nend quotient\n\ninit_hits -- Initialize builtin computational rules for trunc and quotient\n\nnamespace trunc\n definition rec_tr [reducible] {n : \u2115\u208b\u2082} {A : Type} {P : trunc n A \u2192 Type}\n [Pt : \u03a0aa, is_trunc n (P aa)] (H : \u03a0a, P (tr a)) (a : A) : trunc.rec H (tr a) = H a :=\n idp\nend trunc\n\nnamespace quotient\n definition rec_class_of {A : Type} {R : A \u2192 A \u2192 Type} {P : quotient R \u2192 Type}\n (Pc : \u03a0(a : A), P (class_of R a)) (Pp : \u03a0\u2983a a' : A\u2984 (H : R a a'), Pc a =[eq_of_rel R H] Pc a')\n (a : A) : quotient.rec Pc Pp (class_of R a) = Pc a :=\n idp\n\n constant rec_eq_of_rel {A : Type} {R : A \u2192 A \u2192 Type} {P : quotient R \u2192 Type}\n (Pc : \u03a0(a : A), P (class_of R a)) (Pp : \u03a0\u2983a a' : A\u2984 (H : R a a'), Pc a =[eq_of_rel R H] Pc a')\n {a a' : A} (H : R a a') : apd (quotient.rec Pc Pp) (eq_of_rel R H) = Pp H\nend quotient\n\nattribute quotient.class_of trunc.tr [constructor]\nattribute quotient.rec_on trunc.rec_on [unfold 4]\n","avg_line_length":35.6741573034,"max_line_length":98,"alphanum_fraction":0.6201574803} -{"size":142,"ext":"lean","lang":"Lean","max_stars_count":19.0,"content":"theorem test (p q : Prop) (hp : p) (hq : q) : p \u2227 q \u2227 p :=\n by apply And.intro\n exact hp\n apply And.intro\n exact hq\n exact hp","avg_line_length":23.6666666667,"max_line_length":58,"alphanum_fraction":0.5281690141} -{"size":11350,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2019 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n-\/\nimport Lean.Compiler.IR.Format\nimport Lean.Compiler.IR.Basic\nimport Lean.Compiler.IR.CompilerM\n\nnamespace Lean.IR.UnreachableBranches\n\n\/-- Value used in the abstract interpreter -\/\ninductive Value where\n | bot -- undefined\n | top -- any value\n | ctor (i : CtorInfo) (vs : Array Value)\n | choice (vs : List Value)\n deriving Inhabited, Repr\n\nprotected partial def Value.toFormat : Value \u2192 Format\n | Value.bot => \"\u22a5\"\n | Value.top => \"\u22a4\"\n | Value.ctor info vs =>\n if vs.isEmpty then\n format info.name\n else\n Format.paren <| format info.name ++ Std.Format.join (vs.toList.map fun v => \" \" ++ Value.toFormat v)\n | Value.choice vs =>\n Format.paren <| Std.Format.joinSep (vs.map Value.toFormat) \" | \"\n\ninstance : ToFormat Value where\n format := Value.toFormat\n\ninstance : ToString Value where\n toString v := toString (format v)\n\nnamespace Value\n\nprotected partial def beq : Value \u2192 Value \u2192 Bool\n | bot, bot => true\n | top, top => true\n | ctor i\u2081 vs\u2081, ctor i\u2082 vs\u2082 => i\u2081 == i\u2082 && Array.isEqv vs\u2081 vs\u2082 Value.beq\n | choice vs\u2081, choice vs\u2082 =>\n vs\u2081.all (fun v\u2081 => vs\u2082.any fun v\u2082 => Value.beq v\u2081 v\u2082)\n &&\n vs\u2082.all (fun v\u2082 => vs\u2081.any fun v\u2081 => Value.beq v\u2081 v\u2082)\n | _, _ => false\n\ninstance : BEq Value := \u27e8Value.beq\u27e9\n\npartial def addChoice (merge : Value \u2192 Value \u2192 Value) : List Value \u2192 Value \u2192 List Value\n | [], v => [v]\n | v\u2081@(ctor i\u2081 _) :: cs, v\u2082@(ctor i\u2082 _) =>\n if i\u2081 == i\u2082 then merge v\u2081 v\u2082 :: cs\n else v\u2081 :: addChoice merge cs v\u2082\n | _, _ => panic! \"invalid addChoice\"\n\npartial def merge (v\u2081 v\u2082 : Value) : Value :=\n match v\u2081, v\u2082 with\n | bot, v => v\n | v, bot => v\n | top, _ => top\n | _, top => top\n | v\u2081@(ctor i\u2081 vs\u2081), v\u2082@(ctor i\u2082 vs\u2082) =>\n if i\u2081 == i\u2082 then ctor i\u2081 <| vs\u2081.size.fold (init := #[]) fun i r => r.push (merge vs\u2081[i] vs\u2082[i])\n else choice [v\u2081, v\u2082]\n | choice vs\u2081, choice vs\u2082 => choice <| vs\u2081.foldl (addChoice merge) vs\u2082\n | choice vs, v => choice <| addChoice merge vs v\n | v, choice vs => choice <| addChoice merge vs v\n\nprotected partial def format : Value \u2192 Format\n | top => \"top\"\n | bot => \"bot\"\n | choice vs => format \"@\" ++ @List.format _ \u27e8Value.format\u27e9 vs\n | ctor i vs => format \"#\" ++ if vs.isEmpty then format i.name else Format.paren (format i.name ++ @formatArray _ \u27e8Value.format\u27e9 vs)\n\ninstance : ToFormat Value := \u27e8Value.format\u27e9\ninstance : ToString Value := \u27e8Format.pretty \u2218 Value.format\u27e9\n\n\/--\n In `truncate`, we approximate a value as `top` if depth > `truncateMaxDepth`.\n TODO: add option to control this parameter.\n-\/\ndef truncateMaxDepth := 8\n\n\/--\n Make sure constructors of recursive inductive datatypes can only occur once in each path.\n Values at depth > truncateMaxDepth are also approximated at `top`.\n We use this function this function to implement a simple widening operation for our abstract\n interpreter.\n Recall the widening functions is used to ensure termination in abstract interpreters.\n-\/\npartial def truncate (env : Environment) (v : Value) (s : NameSet) : Value :=\n go v s truncateMaxDepth\nwhere\n go (v : Value) (s : NameSet) (depth : Nat) : Value :=\n match depth with\n | 0 => top\n | depth+1 =>\n match v, s with\n | ctor i vs, found =>\n let I := i.name.getPrefix\n if found.contains I then\n top\n else\n let cont (found' : NameSet) : Value :=\n ctor i (vs.map fun v => go v found' depth)\n match env.find? I with\n | some (ConstantInfo.inductInfo d) =>\n if d.isRec then cont (found.insert I)\n else cont found\n | _ => cont found\n | choice vs, found =>\n let newVs := vs.map fun v => go v found depth\n if newVs.elem top then top\n else choice newVs\n | v, _ => v\n\n\/-- Widening operator that guarantees termination in our abstract interpreter. -\/\ndef widening (env : Environment) (v\u2081 v\u2082 : Value) : Value :=\n truncate env (merge v\u2081 v\u2082) {}\n\nend Value\n\nabbrev FunctionSummaries := SMap FunId Value\n\nbuiltin_initialize functionSummariesExt : SimplePersistentEnvExtension (FunId \u00d7 Value) FunctionSummaries \u2190\n registerSimplePersistentEnvExtension {\n name := `unreachBranchesFunSummary,\n addImportedFn := fun as =>\n let cache : FunctionSummaries := mkStateFromImportedEntries (fun s (p : FunId \u00d7 Value) => s.insert p.1 p.2) {} as\n cache.switch,\n addEntryFn := fun s \u27e8e, n\u27e9 => s.insert e n\n }\n\ndef addFunctionSummary (env : Environment) (fid : FunId) (v : Value) : Environment :=\n functionSummariesExt.addEntry env (fid, v)\n\ndef getFunctionSummary? (env : Environment) (fid : FunId) : Option Value :=\n (functionSummariesExt.getState env).find? fid\n\nabbrev Assignment := Std.HashMap VarId Value\n\nstructure InterpContext where\n currFnIdx : Nat := 0\n decls : Array Decl\n env : Environment\n lctx : LocalContext := {}\n\nstructure InterpState where\n assignments : Array Assignment\n funVals : Std.PArray Value -- we take snapshots during fixpoint computations\n\nabbrev M := ReaderT InterpContext (StateM InterpState)\n\nopen Value\n\ndef findVarValue (x : VarId) : M Value := do\n let ctx \u2190 read\n let s \u2190 get\n let assignment := s.assignments[ctx.currFnIdx]\n return assignment.findD x bot\n\ndef findArgValue (arg : Arg) : M Value :=\n match arg with\n | Arg.var x => findVarValue x\n | _ => pure top\n\ndef updateVarAssignment (x : VarId) (v : Value) : M Unit := do\n let v' \u2190 findVarValue x\n let ctx \u2190 read\n modify fun s => { s with assignments := s.assignments.modify ctx.currFnIdx fun a => a.insert x (merge v v') }\n\ndef resetVarAssignment (x : VarId) : M Unit := do\n let ctx \u2190 read\n modify fun s => { s with assignments := s.assignments.modify ctx.currFnIdx fun a => a.insert x Value.bot }\n\ndef resetParamAssignment (y : Param) : M Unit :=\n resetVarAssignment y.x\n\npartial def projValue : Value \u2192 Nat \u2192 Value\n | ctor _ vs, i => vs.getD i bot\n | choice vs, i => vs.foldl (fun r v => merge r (projValue v i)) bot\n | v, _ => v\n\ndef interpExpr : Expr \u2192 M Value\n | Expr.ctor i ys => return ctor i (\u2190 ys.mapM fun y => findArgValue y)\n | Expr.proj i x => return projValue (\u2190 findVarValue x) i\n | Expr.fap fid _ => do\n let ctx \u2190 read\n match getFunctionSummary? ctx.env fid with\n | some v => pure v\n | none => do\n let s \u2190 get\n match ctx.decls.findIdx? (fun decl => decl.name == fid) with\n | some idx => pure s.funVals[idx]\n | none => pure top\n | _ => pure top\n\npartial def containsCtor : Value \u2192 CtorInfo \u2192 Bool\n | top, _ => true\n | ctor i _, j => i == j\n | choice vs, j => vs.any fun v => containsCtor v j\n | _, _ => false\n\ndef updateCurrFnSummary (v : Value) : M Unit := do\n let ctx \u2190 read\n let currFnIdx := ctx.currFnIdx\n modify fun s => { s with funVals := s.funVals.modify currFnIdx (fun v' => widening ctx.env v v') }\n\n\/-- Return true if the assignment of at least one parameter has been updated. -\/\ndef updateJPParamsAssignment (ys : Array Param) (xs : Array Arg) : M Bool := do\n let ctx \u2190 read\n let currFnIdx := ctx.currFnIdx\n ys.size.foldM (init := false) fun i r => do\n let y := ys[i]\n let x := xs[i]\n let yVal \u2190 findVarValue y.x\n let xVal \u2190 findArgValue x\n let newVal := merge yVal xVal\n if newVal == yVal then\n pure r\n else\n modify fun s => { s with assignments := s.assignments.modify currFnIdx fun a => a.insert y.x newVal }\n pure true\n\nprivate partial def resetNestedJPParams : FnBody \u2192 M Unit\n | FnBody.jdecl _ ys _ k => do\n ys.forM resetParamAssignment\n \/- Remark we don't need to reset the parameters of joint-points\n nested in `b` since they will be reset if this JP is used. -\/\n resetNestedJPParams k\n | FnBody.case _ _ _ alts =>\n alts.forM fun alt => match alt with\n | Alt.ctor _ b => resetNestedJPParams b\n | Alt.default b => resetNestedJPParams b\n | e => do unless e.isTerminal do resetNestedJPParams e.body\n\npartial def interpFnBody : FnBody \u2192 M Unit\n | FnBody.vdecl x _ e b => do\n let v \u2190 interpExpr e\n updateVarAssignment x v\n interpFnBody b\n | FnBody.jdecl j ys v b =>\n withReader (fun ctx => { ctx with lctx := ctx.lctx.addJP j ys v }) do\n interpFnBody b\n | FnBody.case _ x _ alts => do\n let v \u2190 findVarValue x\n alts.forM fun alt => do\n match alt with\n | Alt.ctor i b => if containsCtor v i then interpFnBody b\n | Alt.default b => interpFnBody b\n | FnBody.ret x => do\n let v \u2190 findArgValue x\n updateCurrFnSummary v\n | FnBody.jmp j xs => do\n let ctx \u2190 read\n let ys := (ctx.lctx.getJPParams j).get!\n let b := (ctx.lctx.getJPBody j).get!\n let updated \u2190 updateJPParamsAssignment ys xs\n if updated then\n -- We must reset the value of nested join-point parameters since they depend on `ys` values\n resetNestedJPParams b\n interpFnBody b\n | e => do\n unless e.isTerminal do\n interpFnBody e.body\n\ndef inferStep : M Bool := do\n let ctx \u2190 read\n modify fun s => { s with assignments := ctx.decls.map fun _ => {} }\n ctx.decls.size.foldM (init := false) fun idx modified => do\n match ctx.decls[idx] with\n | Decl.fdecl (xs := ys) (body := b) .. => do\n let s \u2190 get\n let currVals := s.funVals[idx]\n withReader (fun ctx => { ctx with currFnIdx := idx }) do\n ys.forM fun y => updateVarAssignment y.x top\n interpFnBody b\n let s \u2190 get\n let newVals := s.funVals[idx]\n pure (modified || currVals != newVals)\n | Decl.extern _ _ _ _ => pure modified\n\npartial def inferMain : M Unit := do\n let modified \u2190 inferStep\n if modified then inferMain else pure ()\n\npartial def elimDeadAux (assignment : Assignment) : FnBody \u2192 FnBody\n | FnBody.vdecl x t e b => FnBody.vdecl x t e (elimDeadAux assignment b)\n | FnBody.jdecl j ys v b => FnBody.jdecl j ys (elimDeadAux assignment v) (elimDeadAux assignment b)\n | FnBody.case tid x xType alts =>\n let v := assignment.findD x bot\n let alts := alts.map fun alt =>\n match alt with\n | Alt.ctor i b => Alt.ctor i <| if containsCtor v i then elimDeadAux assignment b else FnBody.unreachable\n | Alt.default b => Alt.default (elimDeadAux assignment b)\n FnBody.case tid x xType alts\n | e =>\n if e.isTerminal then e\n else\n let (instr, b) := e.split\n let b := elimDeadAux assignment b\n instr.setBody b\n\npartial def elimDead (assignment : Assignment) (d : Decl) : Decl :=\n match d with\n | Decl.fdecl (body := b) .. => d.updateBody! <| elimDeadAux assignment b\n | other => other\n\nend UnreachableBranches\n\nopen UnreachableBranches\n\ndef elimDeadBranches (decls : Array Decl) : CompilerM (Array Decl) := do\n let s \u2190 get\n let env := s.env\n let assignments : Array Assignment := decls.map fun _ => {}\n let funVals := Std.mkPArray decls.size Value.bot\n let ctx : InterpContext := { decls := decls, env := env }\n let s : InterpState := { assignments := assignments, funVals := funVals }\n let (_, s) := (inferMain ctx).run s\n let funVals := s.funVals\n let assignments := s.assignments\n modify fun s =>\n let env := decls.size.fold (init := s.env) fun i env =>\n addFunctionSummary env decls[i].name funVals[i]\n { s with env := env }\n return decls.mapIdx fun i decl => elimDead assignments[i] decl\n\nend Lean.IR\n","avg_line_length":34.186746988,"max_line_length":133,"alphanum_fraction":0.6436123348} -{"size":50012,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2018 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau, Yury Kudryashov\n-\/\nimport algebra.iterate_hom\nimport data.equiv.ring_aut\nimport algebra.module.basic\nimport linear_algebra.basic\nimport tactic.abel\n\n\/-!\n# Algebras over commutative semirings\n\nIn this file we define `algebra`s over commutative (semi)rings, algebra homomorphisms `alg_hom`,\nand algebra equivalences `alg_equiv`.\nWe also define the usual operations on `alg_hom`s (`id`, `comp`).\n\n`subalgebra`s are defined in `algebra.algebra.subalgebra`.\n\nIf `S` is an `R`-algebra and `A` is an `S`-algebra then `algebra.comap.algebra R S A` can be used\nto provide `A` with a structure of an `R`-algebra. Other than that, `algebra.comap` is now\ndeprecated and replaced with `is_scalar_tower`.\n\nFor the category of `R`-algebras, denoted `Algebra R`, see the file\n`algebra\/category\/Algebra\/basic.lean`.\n\n## Notations\n\n* `A \u2192\u2090[R] B` : `R`-algebra homomorphism from `A` to `B`.\n* `A \u2243\u2090[R] B` : `R`-algebra equivalence from `A` to `B`.\n-\/\n\nuniverses u v w u\u2081 v\u2081\n\nopen_locale big_operators\n\nsection prio\n-- We set this priority to 0 later in this file\nset_option extends_priority 200 \/- control priority of\n`instance [algebra R A] : has_scalar R A` -\/\n\n\/--\nGiven a commutative (semi)ring `R`, an `R`-algebra is a (possibly noncommutative)\n(semi)ring `A` endowed with a morphism of rings `R \u2192+* A` which lands in the\ncenter of `A`.\n\nFor convenience, this typeclass extends `has_scalar R A` where the scalar action must\nagree with left multiplication by the image of the structure morphism.\n\nGiven an `algebra R A` instance, the structure morphism `R \u2192+* A` is denoted `algebra_map R A`.\n-\/\n@[nolint has_inhabited_instance]\nclass algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A]\n extends has_scalar R A, R \u2192+* A :=\n(commutes' : \u2200 r x, to_fun r * x = x * to_fun r)\n(smul_def' : \u2200 r x, r \u2022 x = to_fun r * x)\nend prio\n\n\/-- Embedding `R \u2192+* A` given by `algebra` structure. -\/\ndef algebra_map (R : Type u) (A : Type v) [comm_semiring R] [semiring A] [algebra R A] : R \u2192+* A :=\nalgebra.to_ring_hom\n\n\/-- Creating an algebra from a morphism to the center of a semiring. -\/\ndef ring_hom.to_algebra' {R S} [comm_semiring R] [semiring S] (i : R \u2192+* S)\n (h : \u2200 c x, i c * x = x * i c) :\n algebra R S :=\n{ smul := \u03bb c x, i c * x,\n commutes' := h,\n smul_def' := \u03bb c x, rfl,\n to_ring_hom := i}\n\n\/-- Creating an algebra from a morphism to a commutative semiring. -\/\ndef ring_hom.to_algebra {R S} [comm_semiring R] [comm_semiring S] (i : R \u2192+* S) :\n algebra R S :=\ni.to_algebra' $ \u03bb _, mul_comm _\n\nlemma ring_hom.algebra_map_to_algebra {R S} [comm_semiring R] [comm_semiring S]\n (i : R \u2192+* S) :\n @algebra_map R S _ _ i.to_algebra = i :=\nrfl\n\nnamespace algebra\n\nvariables {R : Type u} {S : Type v} {A : Type w} {B : Type*}\n\n\/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.\nIf `(r \u2022 1) * x = x * (r \u2022 1) = r \u2022 x` for all `r : R` and `x : A`, then `A` is an `algebra`\nover `R`.\n\nSee note [reducible non-instances]. -\/\n@[reducible]\ndef of_module' [comm_semiring R] [semiring A] [module R A]\n (h\u2081 : \u2200 (r : R) (x : A), (r \u2022 1) * x = r \u2022 x)\n (h\u2082 : \u2200 (r : R) (x : A), x * (r \u2022 1) = r \u2022 x) : algebra R A :=\n{ to_fun := \u03bb r, r \u2022 1,\n map_one' := one_smul _ _,\n map_mul' := \u03bb r\u2081 r\u2082, by rw [h\u2081, mul_smul],\n map_zero' := zero_smul _ _,\n map_add' := \u03bb r\u2081 r\u2082, add_smul r\u2081 r\u2082 1,\n commutes' := \u03bb r x, by simp only [h\u2081, h\u2082],\n smul_def' := \u03bb r x, by simp only [h\u2081] }\n\n\/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.\nIf `(r \u2022 x) * y = x * (r \u2022 y) = r \u2022 (x * y)` for all `r : R` and `x y : A`, then `A`\nis an `algebra` over `R`.\n\nSee note [reducible non-instances]. -\/\n@[reducible]\ndef of_module [comm_semiring R] [semiring A] [module R A]\n (h\u2081 : \u2200 (r : R) (x y : A), (r \u2022 x) * y = r \u2022 (x * y))\n (h\u2082 : \u2200 (r : R) (x y : A), x * (r \u2022 y) = r \u2022 (x * y)) : algebra R A :=\nof_module' (\u03bb r x, by rw [h\u2081, one_mul]) (\u03bb r x, by rw [h\u2082, mul_one])\n\nsection semiring\n\nvariables [comm_semiring R] [comm_semiring S]\nvariables [semiring A] [algebra R A] [semiring B] [algebra R B]\n\n\/-- We keep this lemma private because it picks up the `algebra.to_has_scalar` instance\nwhich we set to priority 0 shortly. See `smul_def` below for the public version. -\/\nprivate lemma smul_def'' (r : R) (x : A) : r \u2022 x = algebra_map R A r * x :=\nalgebra.smul_def' r x\n\n\/--\nTo prove two algebra structures on a fixed `[comm_semiring R] [semiring A]` agree,\nit suffices to check the `algebra_map`s agree.\n-\/\n-- We'll later use this to show `algebra \u2124 M` is a subsingleton.\n@[ext]\nlemma algebra_ext {R : Type*} [comm_semiring R] {A : Type*} [semiring A] (P Q : algebra R A)\n (w : \u2200 (r : R), by { haveI := P, exact algebra_map R A r } =\n by { haveI := Q, exact algebra_map R A r }) :\n P = Q :=\nbegin\n unfreezingI { rcases P with \u27e8\u27e8P\u27e9\u27e9, rcases Q with \u27e8\u27e8Q\u27e9\u27e9 },\n congr,\n { funext r a,\n replace w := congr_arg (\u03bb s, s * a) (w r),\n simp only [\u2190smul_def''] at w,\n apply w, },\n { ext r,\n exact w r, },\n { apply proof_irrel_heq, },\n { apply proof_irrel_heq, },\nend\n\n@[priority 200] -- see Note [lower instance priority]\ninstance to_module : module R A :=\n{ one_smul := by simp [smul_def''],\n mul_smul := by simp [smul_def'', mul_assoc],\n smul_add := by simp [smul_def'', mul_add],\n smul_zero := by simp [smul_def''],\n add_smul := by simp [smul_def'', add_mul],\n zero_smul := by simp [smul_def''] }\n\n-- From now on, we don't want to use the following instance anymore.\n-- Unfortunately, leaving it in place causes deterministic timeouts later in mathlib.\nattribute [instance, priority 0] algebra.to_has_scalar\n\nlemma smul_def (r : R) (x : A) : r \u2022 x = algebra_map R A r * x :=\nalgebra.smul_def' r x\n\nlemma algebra_map_eq_smul_one (r : R) : algebra_map R A r = r \u2022 1 :=\ncalc algebra_map R A r = algebra_map R A r * 1 : (mul_one _).symm\n ... = r \u2022 1 : (algebra.smul_def r 1).symm\n\nlemma algebra_map_eq_smul_one' : \u21d1(algebra_map R A) = \u03bb r, r \u2022 (1 : A) :=\nfunext algebra_map_eq_smul_one\n\n\/-- `mul_comm` for `algebra`s when one element is from the base ring. -\/\ntheorem commutes (r : R) (x : A) : algebra_map R A r * x = x * algebra_map R A r :=\nalgebra.commutes' r x\n\n\/-- `mul_left_comm` for `algebra`s when one element is from the base ring. -\/\ntheorem left_comm (x : A) (r : R) (y : A) :\n x * (algebra_map R A r * y) = algebra_map R A r * (x * y) :=\nby rw [\u2190 mul_assoc, \u2190 commutes, mul_assoc]\n\n\/-- `mul_right_comm` for `algebra`s when one element is from the base ring. -\/\ntheorem right_comm (x : A) (r : R) (y : A) :\n (x * algebra_map R A r) * y = (x * y) * algebra_map R A r :=\nby rw [mul_assoc, commutes, \u2190mul_assoc]\n\ninstance _root_.is_scalar_tower.right : is_scalar_tower R A A :=\n\u27e8\u03bb x y z, by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]\u27e9\n\n\/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass\nsearch (and was here first). -\/\n@[simp] protected lemma mul_smul_comm (s : R) (x y : A) :\n x * (s \u2022 y) = s \u2022 (x * y) :=\n-- TODO: set up `is_scalar_tower.smul_comm_class` earlier so that we can actually prove this using\n-- `mul_smul_comm s x y`.\nby rw [smul_def, smul_def, left_comm]\n\n\/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass\nsearch (and was here first). -\/\n@[simp] protected lemma smul_mul_assoc (r : R) (x y : A) :\n (r \u2022 x) * y = r \u2022 (x * y) :=\nsmul_mul_assoc r x y\n\nsection\nvariables {r : R} {a : A}\n\n@[simp] lemma bit0_smul_one : bit0 r \u2022 (1 : A) = bit0 (r \u2022 (1 : A)) :=\nby simp [bit0, add_smul]\nlemma bit0_smul_one' : bit0 r \u2022 (1 : A) = r \u2022 2 :=\nby simp [bit0, add_smul, smul_add]\n@[simp] lemma bit0_smul_bit0 : bit0 r \u2022 bit0 a = r \u2022 (bit0 (bit0 a)) :=\nby simp [bit0, add_smul, smul_add]\n@[simp] lemma bit0_smul_bit1 : bit0 r \u2022 bit1 a = r \u2022 (bit0 (bit1 a)) :=\nby simp [bit0, add_smul, smul_add]\n@[simp] lemma bit1_smul_one : bit1 r \u2022 (1 : A) = bit1 (r \u2022 (1 : A)) :=\nby simp [bit1, add_smul]\nlemma bit1_smul_one' : bit1 r \u2022 (1 : A) = r \u2022 2 + 1 :=\nby simp [bit1, bit0, add_smul, smul_add]\n@[simp] lemma bit1_smul_bit0 : bit1 r \u2022 bit0 a = r \u2022 (bit0 (bit0 a)) + bit0 a :=\nby simp [bit1, add_smul, smul_add]\n@[simp] lemma bit1_smul_bit1 : bit1 r \u2022 bit1 a = r \u2022 (bit0 (bit1 a)) + bit1 a :=\nby { simp only [bit0, bit1, add_smul, smul_add, one_smul], abel }\n\nend\n\nvariables (R A)\n\n\/--\nThe canonical ring homomorphism `algebra_map R A : R \u2192* A` for any `R`-algebra `A`,\npackaged as an `R`-linear map.\n-\/\nprotected def linear_map : R \u2192\u2097[R] A :=\n{ map_smul' := \u03bb x y, by simp [algebra.smul_def],\n ..algebra_map R A }\n\n@[simp]\nlemma linear_map_apply (r : R) : algebra.linear_map R A r = algebra_map R A r := rfl\n\nlemma coe_linear_map : \u21d1(algebra.linear_map R A) = algebra_map R A := rfl\n\ninstance id : algebra R R := (ring_hom.id R).to_algebra\n\nvariables {R A}\n\nnamespace id\n\n@[simp] lemma map_eq_id : algebra_map R R = ring_hom.id _ := rfl\n\nlemma map_eq_self (x : R) : algebra_map R R x = x := rfl\n\n@[simp] lemma smul_eq_mul (x y : R) : x \u2022 y = x * y := rfl\n\nend id\n\nsection prod\nvariables (R A B)\n\ninstance : algebra R (A \u00d7 B) :=\n{ commutes' := by { rintro r \u27e8a, b\u27e9, dsimp, rw [commutes r a, commutes r b] },\n smul_def' := by { rintro r \u27e8a, b\u27e9, dsimp, rw [smul_def r a, smul_def r b] },\n .. prod.module,\n .. ring_hom.prod (algebra_map R A) (algebra_map R B) }\n\nvariables {R A B}\n\n@[simp] lemma algebra_map_prod_apply (r : R) :\n algebra_map R (A \u00d7 B) r = (algebra_map R A r, algebra_map R B r) := rfl\n\nend prod\n\n\/-- Algebra over a subsemiring. This builds upon `subsemiring.module`. -\/\ninstance of_subsemiring (S : subsemiring R) : algebra S A :=\n{ smul := (\u2022),\n commutes' := \u03bb r x, algebra.commutes r x,\n smul_def' := \u03bb r x, algebra.smul_def r x,\n .. (algebra_map R A).comp S.subtype }\n\n\/-- Algebra over a subring. This builds upon `subring.module`. -\/\ninstance of_subring {R A : Type*} [comm_ring R] [ring A] [algebra R A]\n (S : subring R) : algebra S A :=\n{ smul := (\u2022),\n .. algebra.of_subsemiring S.to_subsemiring,\n .. (algebra_map R A).comp S.subtype }\n\nlemma algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :\n (algebra_map S R : S \u2192+* R) = subring.subtype S := rfl\n\nlemma coe_algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :\n (algebra_map S R : S \u2192 R) = subtype.val := rfl\n\nlemma algebra_map_of_subring_apply {R : Type*} [comm_ring R] (S : subring R) (x : S) :\n algebra_map S R x = x := rfl\n\n\/-- Explicit characterization of the submonoid map in the case of an algebra.\n`S` is made explicit to help with type inference -\/\ndef algebra_map_submonoid (S : Type*) [semiring S] [algebra R S]\n (M : submonoid R) : (submonoid S) :=\nsubmonoid.map (algebra_map R S : R \u2192* S) M\n\nlemma mem_algebra_map_submonoid_of_mem [algebra R S] {M : submonoid R} (x : M) :\n (algebra_map R S x) \u2208 algebra_map_submonoid S M :=\nset.mem_image_of_mem (algebra_map R S) x.2\n\nend semiring\n\nsection ring\nvariables [comm_ring R]\n\nvariables (R)\n\n\/-- A `semiring` that is an `algebra` over a commutative ring carries a natural `ring` structure.\nSee note [reducible non-instances]. -\/\n@[reducible]\ndef semiring_to_ring [semiring A] [algebra R A] : ring A := {\n ..module.add_comm_monoid_to_add_comm_group R,\n ..(infer_instance : semiring A) }\n\nvariables {R}\n\nlemma mul_sub_algebra_map_commutes [ring A] [algebra R A] (x : A) (r : R) :\n x * (x - algebra_map R A r) = (x - algebra_map R A r) * x :=\nby rw [mul_sub, \u2190commutes, sub_mul]\n\nlemma mul_sub_algebra_map_pow_commutes [ring A] [algebra R A] (x : A) (r : R) (n : \u2115) :\n x * (x - algebra_map R A r) ^ n = (x - algebra_map R A r) ^ n * x :=\nbegin\n induction n with n ih,\n { simp },\n { rw [pow_succ, \u2190mul_assoc, mul_sub_algebra_map_commutes,\n mul_assoc, ih, \u2190mul_assoc], }\nend\n\nend ring\n\nend algebra\n\nnamespace no_zero_smul_divisors\n\nvariables {R A : Type*}\n\nopen algebra\n\nsection ring\n\nvariables [comm_ring R]\n\n\/-- If `algebra_map R A` is injective and `A` has no zero divisors,\n`R`-multiples in `A` are zero only if one of the factors is zero.\n\nCannot be an instance because there is no `injective (algebra_map R A)` typeclass.\n-\/\nlemma of_algebra_map_injective\n [semiring A] [algebra R A] [no_zero_divisors A]\n (h : function.injective (algebra_map R A)) : no_zero_smul_divisors R A :=\n\u27e8\u03bb c x hcx, (mul_eq_zero.mp ((smul_def c x).symm.trans hcx)).imp_left\n ((algebra_map R A).injective_iff.mp h _)\u27e9\n\nvariables (R A)\nlemma algebra_map_injective [ring A] [nontrivial A]\n [algebra R A] [no_zero_smul_divisors R A] :\n function.injective (algebra_map R A) :=\nsuffices function.injective (\u03bb (c : R), c \u2022 (1 : A)),\nby { convert this, ext, rw [algebra.smul_def, mul_one] },\nsmul_left_injective R one_ne_zero\n\nvariables {R A}\nlemma iff_algebra_map_injective [ring A] [is_domain A] [algebra R A] :\n no_zero_smul_divisors R A \u2194 function.injective (algebra_map R A) :=\n\u27e8@@no_zero_smul_divisors.algebra_map_injective R A _ _ _ _,\n no_zero_smul_divisors.of_algebra_map_injective\u27e9\n\nend ring\n\nsection field\n\nvariables [field R] [semiring A] [algebra R A]\n\n@[priority 100] -- see note [lower instance priority]\ninstance algebra.no_zero_smul_divisors [nontrivial A] [no_zero_divisors A] :\n no_zero_smul_divisors R A :=\nno_zero_smul_divisors.of_algebra_map_injective (algebra_map R A).injective\n\nend field\n\nend no_zero_smul_divisors\n\nnamespace opposite\n\nvariables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]\n\ninstance : algebra R A\u1d52\u1d56 :=\n{ to_ring_hom := (algebra_map R A).to_opposite $ \u03bb x y, algebra.commutes _ _,\n smul_def' := \u03bb c x, unop_injective $\n by { dsimp, simp only [op_mul, algebra.smul_def, algebra.commutes, op_unop] },\n commutes' := \u03bb r, opposite.rec $ \u03bb x, by dsimp; simp only [\u2190 op_mul, algebra.commutes],\n ..opposite.has_scalar A R }\n\n@[simp] lemma algebra_map_apply (c : R) : algebra_map R A\u1d52\u1d56 c = op (algebra_map R A c) := rfl\n\nend opposite\n\nnamespace module\nvariables (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [module R M]\n\ninstance : algebra R (module.End R M) :=\nalgebra.of_module smul_mul_assoc (\u03bb r f g, (smul_comm r f g).symm)\n\nlemma algebra_map_End_eq_smul_id (a : R) :\n (algebra_map R (End R M)) a = a \u2022 linear_map.id := rfl\n\n@[simp] lemma algebra_map_End_apply (a : R) (m : M) :\n (algebra_map R (End R M)) a m = a \u2022 m := rfl\n\n@[simp] lemma ker_algebra_map_End (K : Type u) (V : Type v)\n [field K] [add_comm_group V] [module K V] (a : K) (ha : a \u2260 0) :\n ((algebra_map K (End K V)) a).ker = \u22a5 :=\nlinear_map.ker_smul _ _ ha\n\nend module\n\nset_option old_structure_cmd true\n\/-- Defining the homomorphism in the category R-Alg. -\/\n@[nolint has_inhabited_instance]\nstructure alg_hom (R : Type u) (A : Type v) (B : Type w)\n [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B :=\n(commutes' : \u2200 r : R, to_fun (algebra_map R A r) = algebra_map R B r)\n\nrun_cmd tactic.add_doc_string `alg_hom.to_ring_hom \"Reinterpret an `alg_hom` as a `ring_hom`\"\n\ninfixr ` \u2192\u2090 `:25 := alg_hom _\nnotation A ` \u2192\u2090[`:25 R `] ` B := alg_hom R A B\n\nnamespace alg_hom\n\nvariables {R : Type u} {A : Type v} {B : Type w} {C : Type u\u2081} {D : Type v\u2081}\n\nsection semiring\n\nvariables [comm_semiring R] [semiring A] [semiring B] [semiring C] [semiring D]\nvariables [algebra R A] [algebra R B] [algebra R C] [algebra R D]\n\ninstance : has_coe_to_fun (A \u2192\u2090[R] B) (\u03bb _, A \u2192 B) := \u27e8alg_hom.to_fun\u27e9\n\ninitialize_simps_projections alg_hom (to_fun \u2192 apply)\n\n@[simp] lemma to_fun_eq_coe (f : A \u2192\u2090[R] B) : f.to_fun = f := rfl\n\ninstance coe_ring_hom : has_coe (A \u2192\u2090[R] B) (A \u2192+* B) := \u27e8alg_hom.to_ring_hom\u27e9\n\ninstance coe_monoid_hom : has_coe (A \u2192\u2090[R] B) (A \u2192* B) := \u27e8\u03bb f, \u2191(f : A \u2192+* B)\u27e9\n\ninstance coe_add_monoid_hom : has_coe (A \u2192\u2090[R] B) (A \u2192+ B) := \u27e8\u03bb f, \u2191(f : A \u2192+* B)\u27e9\n\n@[simp, norm_cast] lemma coe_mk {f : A \u2192 B} (h\u2081 h\u2082 h\u2083 h\u2084 h\u2085) :\n \u21d1(\u27e8f, h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A \u2192\u2090[R] B) = f := rfl\n\n-- make the coercion the simp-normal form\n@[simp] lemma to_ring_hom_eq_coe (f : A \u2192\u2090[R] B) : f.to_ring_hom = f := rfl\n\n@[simp, norm_cast] lemma coe_to_ring_hom (f : A \u2192\u2090[R] B) : \u21d1(f : A \u2192+* B) = f := rfl\n\n-- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute.\n@[norm_cast] lemma coe_to_monoid_hom (f : A \u2192\u2090[R] B) : \u21d1(f : A \u2192* B) = f := rfl\n\n-- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute.\n@[norm_cast] lemma coe_to_add_monoid_hom (f : A \u2192\u2090[R] B) : \u21d1(f : A \u2192+ B) = f := rfl\n\nvariables (\u03c6 : A \u2192\u2090[R] B)\n\ntheorem coe_fn_injective : @function.injective (A \u2192\u2090[R] B) (A \u2192 B) coe_fn :=\nby { intros \u03c6\u2081 \u03c6\u2082 H, cases \u03c6\u2081, cases \u03c6\u2082, congr, exact H }\n\ntheorem coe_fn_inj {\u03c6\u2081 \u03c6\u2082 : A \u2192\u2090[R] B} : (\u03c6\u2081 : A \u2192 B) = \u03c6\u2082 \u2194 \u03c6\u2081 = \u03c6\u2082 := coe_fn_injective.eq_iff\n\ntheorem coe_ring_hom_injective : function.injective (coe : (A \u2192\u2090[R] B) \u2192 (A \u2192+* B)) :=\n\u03bb \u03c6\u2081 \u03c6\u2082 H, coe_fn_injective $ show ((\u03c6\u2081 : (A \u2192+* B)) : A \u2192 B) = ((\u03c6\u2082 : (A \u2192+* B)) : A \u2192 B),\n from congr_arg _ H\n\ntheorem coe_monoid_hom_injective : function.injective (coe : (A \u2192\u2090[R] B) \u2192 (A \u2192* B)) :=\nring_hom.coe_monoid_hom_injective.comp coe_ring_hom_injective\n\ntheorem coe_add_monoid_hom_injective : function.injective (coe : (A \u2192\u2090[R] B) \u2192 (A \u2192+ B)) :=\nring_hom.coe_add_monoid_hom_injective.comp coe_ring_hom_injective\n\nprotected lemma congr_fun {\u03c6\u2081 \u03c6\u2082 : A \u2192\u2090[R] B} (H : \u03c6\u2081 = \u03c6\u2082) (x : A) : \u03c6\u2081 x = \u03c6\u2082 x := H \u25b8 rfl\nprotected lemma congr_arg (\u03c6 : A \u2192\u2090[R] B) {x y : A} (h : x = y) : \u03c6 x = \u03c6 y := h \u25b8 rfl\n\n@[ext]\ntheorem ext {\u03c6\u2081 \u03c6\u2082 : A \u2192\u2090[R] B} (H : \u2200 x, \u03c6\u2081 x = \u03c6\u2082 x) : \u03c6\u2081 = \u03c6\u2082 :=\ncoe_fn_injective $ funext H\n\ntheorem ext_iff {\u03c6\u2081 \u03c6\u2082 : A \u2192\u2090[R] B} : \u03c6\u2081 = \u03c6\u2082 \u2194 \u2200 x, \u03c6\u2081 x = \u03c6\u2082 x :=\n\u27e8alg_hom.congr_fun, ext\u27e9\n\n@[simp] theorem mk_coe {f : A \u2192\u2090[R] B} (h\u2081 h\u2082 h\u2083 h\u2084 h\u2085) :\n (\u27e8f, h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A \u2192\u2090[R] B) = f := ext $ \u03bb _, rfl\n\n@[simp]\ntheorem commutes (r : R) : \u03c6 (algebra_map R A r) = algebra_map R B r := \u03c6.commutes' r\n\ntheorem comp_algebra_map : (\u03c6 : A \u2192+* B).comp (algebra_map R A) = algebra_map R B :=\nring_hom.ext $ \u03c6.commutes\n\n@[simp] lemma map_add (r s : A) : \u03c6 (r + s) = \u03c6 r + \u03c6 s :=\n\u03c6.to_ring_hom.map_add r s\n\n@[simp] lemma map_zero : \u03c6 0 = 0 :=\n\u03c6.to_ring_hom.map_zero\n\n@[simp] lemma map_mul (x y) : \u03c6 (x * y) = \u03c6 x * \u03c6 y :=\n\u03c6.to_ring_hom.map_mul x y\n\n@[simp] lemma map_one : \u03c6 1 = 1 :=\n\u03c6.to_ring_hom.map_one\n\n@[simp] lemma map_smul (r : R) (x : A) : \u03c6 (r \u2022 x) = r \u2022 \u03c6 x :=\nby simp only [algebra.smul_def, map_mul, commutes]\n\n@[simp] lemma map_pow (x : A) (n : \u2115) : \u03c6 (x ^ n) = (\u03c6 x) ^ n :=\n\u03c6.to_ring_hom.map_pow x n\n\nlemma map_sum {\u03b9 : Type*} (f : \u03b9 \u2192 A) (s : finset \u03b9) :\n \u03c6 (\u2211 x in s, f x) = \u2211 x in s, \u03c6 (f x) :=\n\u03c6.to_ring_hom.map_sum f s\n\nlemma map_finsupp_sum {\u03b1 : Type*} [has_zero \u03b1] {\u03b9 : Type*} (f : \u03b9 \u2192\u2080 \u03b1) (g : \u03b9 \u2192 \u03b1 \u2192 A) :\n \u03c6 (f.sum g) = f.sum (\u03bb i a, \u03c6 (g i a)) :=\n\u03c6.map_sum _ _\n\n@[simp] lemma map_nat_cast (n : \u2115) : \u03c6 n = n :=\n\u03c6.to_ring_hom.map_nat_cast n\n\n@[simp] lemma map_bit0 (x) : \u03c6 (bit0 x) = bit0 (\u03c6 x) :=\n\u03c6.to_ring_hom.map_bit0 x\n\n@[simp] lemma map_bit1 (x) : \u03c6 (bit1 x) = bit1 (\u03c6 x) :=\n\u03c6.to_ring_hom.map_bit1 x\n\n\/-- If a `ring_hom` is `R`-linear, then it is an `alg_hom`. -\/\ndef mk' (f : A \u2192+* B) (h : \u2200 (c : R) x, f (c \u2022 x) = c \u2022 f x) : A \u2192\u2090[R] B :=\n{ to_fun := f,\n commutes' := \u03bb c, by simp only [algebra.algebra_map_eq_smul_one, h, f.map_one],\n .. f }\n\n@[simp] lemma coe_mk' (f : A \u2192+* B) (h : \u2200 (c : R) x, f (c \u2022 x) = c \u2022 f x) : \u21d1(mk' f h) = f := rfl\n\nsection\n\nvariables (R A)\n\/-- Identity map as an `alg_hom`. -\/\nprotected def id : A \u2192\u2090[R] A :=\n{ commutes' := \u03bb _, rfl,\n ..ring_hom.id A }\n\n@[simp] lemma coe_id : \u21d1(alg_hom.id R A) = id := rfl\n\n@[simp] lemma id_to_ring_hom : (alg_hom.id R A : A \u2192+* A) = ring_hom.id _ := rfl\n\nend\n\nlemma id_apply (p : A) : alg_hom.id R A p = p := rfl\n\n\/-- Composition of algebra homeomorphisms. -\/\ndef comp (\u03c6\u2081 : B \u2192\u2090[R] C) (\u03c6\u2082 : A \u2192\u2090[R] B) : A \u2192\u2090[R] C :=\n{ commutes' := \u03bb r : R, by rw [\u2190 \u03c6\u2081.commutes, \u2190 \u03c6\u2082.commutes]; refl,\n .. \u03c6\u2081.to_ring_hom.comp \u2191\u03c6\u2082 }\n\n@[simp] lemma coe_comp (\u03c6\u2081 : B \u2192\u2090[R] C) (\u03c6\u2082 : A \u2192\u2090[R] B) : \u21d1(\u03c6\u2081.comp \u03c6\u2082) = \u03c6\u2081 \u2218 \u03c6\u2082 := rfl\n\nlemma comp_apply (\u03c6\u2081 : B \u2192\u2090[R] C) (\u03c6\u2082 : A \u2192\u2090[R] B) (p : A) : \u03c6\u2081.comp \u03c6\u2082 p = \u03c6\u2081 (\u03c6\u2082 p) := rfl\n\nlemma comp_to_ring_hom (\u03c6\u2081 : B \u2192\u2090[R] C) (\u03c6\u2082 : A \u2192\u2090[R] B) :\n \u21d1(\u03c6\u2081.comp \u03c6\u2082 : A \u2192+* C) = (\u03c6\u2081 : B \u2192+* C).comp \u2191\u03c6\u2082 := rfl\n\n@[simp] theorem comp_id : \u03c6.comp (alg_hom.id R A) = \u03c6 :=\next $ \u03bb x, rfl\n\n@[simp] theorem id_comp : (alg_hom.id R B).comp \u03c6 = \u03c6 :=\next $ \u03bb x, rfl\n\ntheorem comp_assoc (\u03c6\u2081 : C \u2192\u2090[R] D) (\u03c6\u2082 : B \u2192\u2090[R] C) (\u03c6\u2083 : A \u2192\u2090[R] B) :\n (\u03c6\u2081.comp \u03c6\u2082).comp \u03c6\u2083 = \u03c6\u2081.comp (\u03c6\u2082.comp \u03c6\u2083) :=\next $ \u03bb x, rfl\n\n\/-- R-Alg \u2964 R-Mod -\/\ndef to_linear_map : A \u2192\u2097[R] B :=\n{ to_fun := \u03c6,\n map_add' := \u03c6.map_add,\n map_smul' := \u03c6.map_smul }\n\n@[simp] lemma to_linear_map_apply (p : A) : \u03c6.to_linear_map p = \u03c6 p := rfl\n\ntheorem to_linear_map_injective : function.injective (to_linear_map : _ \u2192 (A \u2192\u2097[R] B)) :=\n\u03bb \u03c6\u2081 \u03c6\u2082 h, ext $ linear_map.congr_fun h\n\n@[simp] lemma comp_to_linear_map (f : A \u2192\u2090[R] B) (g : B \u2192\u2090[R] C) :\n (g.comp f).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl\n\n@[simp] lemma to_linear_map_id : to_linear_map (alg_hom.id R A) = linear_map.id :=\nlinear_map.ext $ \u03bb _, rfl\n\n\/-- Promote a `linear_map` to an `alg_hom` by supplying proofs about the behavior on `1` and `*`. -\/\n@[simps]\ndef of_linear_map (f : A \u2192\u2097[R] B) (map_one : f 1 = 1) (map_mul : \u2200 x y, f (x * y) = f x * f y) :\n A \u2192\u2090[R] B :=\n{ to_fun := f,\n map_one' := map_one,\n map_mul' := map_mul,\n commutes' := \u03bb c, by simp only [algebra.algebra_map_eq_smul_one, f.map_smul, map_one],\n .. f.to_add_monoid_hom }\n\n@[simp] lemma of_linear_map_to_linear_map (map_one) (map_mul) :\n of_linear_map \u03c6.to_linear_map map_one map_mul = \u03c6 :=\nby { ext, refl }\n\n@[simp] lemma to_linear_map_of_linear_map (f : A \u2192\u2097[R] B) (map_one) (map_mul) :\n to_linear_map (of_linear_map f map_one map_mul) = f :=\nby { ext, refl }\n\n@[simp] lemma of_linear_map_id (map_one) (map_mul) :\n of_linear_map linear_map.id map_one map_mul = alg_hom.id R A :=\next $ \u03bb _, rfl\n\nlemma map_list_prod (s : list A) :\n \u03c6 s.prod = (s.map \u03c6).prod :=\n\u03c6.to_ring_hom.map_list_prod s\n\nsection prod\n\n\/-- First projection as `alg_hom`. -\/\ndef fst : A \u00d7 B \u2192\u2090[R] A :=\n{ commutes' := \u03bb r, rfl, .. ring_hom.fst A B}\n\n\/-- Second projection as `alg_hom`. -\/\ndef snd : A \u00d7 B \u2192\u2090[R] B :=\n{ commutes' := \u03bb r, rfl, .. ring_hom.snd A B}\n\nend prod\n\nlemma algebra_map_eq_apply (f : A \u2192\u2090[R] B) {y : R} {x : A} (h : algebra_map R A y = x) :\n algebra_map R B y = f x :=\nh \u25b8 (f.commutes _).symm\n\nend semiring\n\nsection comm_semiring\n\nvariables [comm_semiring R] [comm_semiring A] [comm_semiring B]\nvariables [algebra R A] [algebra R B] (\u03c6 : A \u2192\u2090[R] B)\n\nlemma map_multiset_prod (s : multiset A) :\n \u03c6 s.prod = (s.map \u03c6).prod :=\n\u03c6.to_ring_hom.map_multiset_prod s\n\nlemma map_prod {\u03b9 : Type*} (f : \u03b9 \u2192 A) (s : finset \u03b9) :\n \u03c6 (\u220f x in s, f x) = \u220f x in s, \u03c6 (f x) :=\n\u03c6.to_ring_hom.map_prod f s\n\nlemma map_finsupp_prod {\u03b1 : Type*} [has_zero \u03b1] {\u03b9 : Type*} (f : \u03b9 \u2192\u2080 \u03b1) (g : \u03b9 \u2192 \u03b1 \u2192 A) :\n \u03c6 (f.prod g) = f.prod (\u03bb i a, \u03c6 (g i a)) :=\n\u03c6.map_prod _ _\n\nend comm_semiring\n\nsection ring\n\nvariables [comm_semiring R] [ring A] [ring B]\nvariables [algebra R A] [algebra R B] (\u03c6 : A \u2192\u2090[R] B)\n\n@[simp] lemma map_neg (x) : \u03c6 (-x) = -\u03c6 x :=\n\u03c6.to_ring_hom.map_neg x\n\n@[simp] lemma map_sub (x y) : \u03c6 (x - y) = \u03c6 x - \u03c6 y :=\n\u03c6.to_ring_hom.map_sub x y\n\n@[simp] lemma map_int_cast (n : \u2124) : \u03c6 n = n :=\n\u03c6.to_ring_hom.map_int_cast n\n\nend ring\n\nsection division_ring\n\nvariables [comm_ring R] [division_ring A] [division_ring B]\nvariables [algebra R A] [algebra R B] (\u03c6 : A \u2192\u2090[R] B)\n\n@[simp] lemma map_inv (x) : \u03c6 (x\u207b\u00b9) = (\u03c6 x)\u207b\u00b9 :=\n\u03c6.to_ring_hom.map_inv x\n\n@[simp] lemma map_div (x y) : \u03c6 (x \/ y) = \u03c6 x \/ \u03c6 y :=\n\u03c6.to_ring_hom.map_div x y\n\nend division_ring\n\ntheorem injective_iff {R A B : Type*} [comm_semiring R] [ring A] [semiring B]\n [algebra R A] [algebra R B] (f : A \u2192\u2090[R] B) :\n function.injective f \u2194 (\u2200 x, f x = 0 \u2192 x = 0) :=\nring_hom.injective_iff (f : A \u2192+* B)\n\nend alg_hom\n\n@[simp] lemma rat.smul_one_eq_coe {A : Type*} [division_ring A] [algebra \u211a A] (m : \u211a) :\n m \u2022 (1 : A) = \u2191m :=\nby rw [algebra.smul_def, mul_one, ring_hom.eq_rat_cast]\n\nset_option old_structure_cmd true\n\/-- An equivalence of algebras is an equivalence of rings commuting with the actions of scalars. -\/\nstructure alg_equiv (R : Type u) (A : Type v) (B : Type w)\n [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]\n extends A \u2243 B, A \u2243* B, A \u2243+ B, A \u2243+* B :=\n(commutes' : \u2200 r : R, to_fun (algebra_map R A r) = algebra_map R B r)\n\nattribute [nolint doc_blame] alg_equiv.to_ring_equiv\nattribute [nolint doc_blame] alg_equiv.to_equiv\nattribute [nolint doc_blame] alg_equiv.to_add_equiv\nattribute [nolint doc_blame] alg_equiv.to_mul_equiv\n\nnotation A ` \u2243\u2090[`:50 R `] ` A' := alg_equiv R A A'\n\nnamespace alg_equiv\n\nvariables {R : Type u} {A\u2081 : Type v} {A\u2082 : Type w} {A\u2083 : Type u\u2081}\n\nsection semiring\n\nvariables [comm_semiring R] [semiring A\u2081] [semiring A\u2082] [semiring A\u2083]\nvariables [algebra R A\u2081] [algebra R A\u2082] [algebra R A\u2083]\nvariables (e : A\u2081 \u2243\u2090[R] A\u2082)\n\ninstance : has_coe_to_fun (A\u2081 \u2243\u2090[R] A\u2082) (\u03bb _, A\u2081 \u2192 A\u2082) := \u27e8alg_equiv.to_fun\u27e9\n\n@[ext]\nlemma ext {f g : A\u2081 \u2243\u2090[R] A\u2082} (h : \u2200 a, f a = g a) : f = g :=\nbegin\n have h\u2081 : f.to_equiv = g.to_equiv := equiv.ext h,\n cases f, cases g, congr,\n { exact (funext h) },\n { exact congr_arg equiv.inv_fun h\u2081 }\nend\n\nprotected lemma congr_arg {f : A\u2081 \u2243\u2090[R] A\u2082} : \u03a0 {x x' : A\u2081}, x = x' \u2192 f x = f x'\n| _ _ rfl := rfl\n\nprotected lemma congr_fun {f g : A\u2081 \u2243\u2090[R] A\u2082} (h : f = g) (x : A\u2081) : f x = g x := h \u25b8 rfl\n\nlemma ext_iff {f g : A\u2081 \u2243\u2090[R] A\u2082} : f = g \u2194 \u2200 x, f x = g x :=\n\u27e8\u03bb h x, h \u25b8 rfl, ext\u27e9\n\nlemma coe_fun_injective : @function.injective (A\u2081 \u2243\u2090[R] A\u2082) (A\u2081 \u2192 A\u2082) (\u03bb e, (e : A\u2081 \u2192 A\u2082)) :=\nbegin\n intros f g w,\n ext,\n exact congr_fun w a,\nend\n\ninstance has_coe_to_ring_equiv : has_coe (A\u2081 \u2243\u2090[R] A\u2082) (A\u2081 \u2243+* A\u2082) := \u27e8alg_equiv.to_ring_equiv\u27e9\n\n@[simp] lemma coe_mk {to_fun inv_fun left_inv right_inv map_mul map_add commutes} :\n \u21d1(\u27e8to_fun, inv_fun, left_inv, right_inv, map_mul, map_add, commutes\u27e9 : A\u2081 \u2243\u2090[R] A\u2082) = to_fun :=\nrfl\n\n@[simp] theorem mk_coe (e : A\u2081 \u2243\u2090[R] A\u2082) (e' h\u2081 h\u2082 h\u2083 h\u2084 h\u2085) :\n (\u27e8e, e', h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A\u2081 \u2243\u2090[R] A\u2082) = e := ext $ \u03bb _, rfl\n\n@[simp] lemma to_fun_eq_coe (e : A\u2081 \u2243\u2090[R] A\u2082) : e.to_fun = e := rfl\n\n@[simp] lemma to_ring_equiv_eq_coe : e.to_ring_equiv = e := rfl\n\n@[simp, norm_cast] lemma coe_ring_equiv : ((e : A\u2081 \u2243+* A\u2082) : A\u2081 \u2192 A\u2082) = e := rfl\nlemma coe_ring_equiv' : (e.to_ring_equiv : A\u2081 \u2192 A\u2082) = e := rfl\n\nlemma coe_ring_equiv_injective : function.injective (coe : (A\u2081 \u2243\u2090[R] A\u2082) \u2192 (A\u2081 \u2243+* A\u2082)) :=\n\u03bb e\u2081 e\u2082 h, ext $ ring_equiv.congr_fun h\n\n@[simp] lemma map_add : \u2200 x y, e (x + y) = e x + e y := e.to_add_equiv.map_add\n\n@[simp] lemma map_zero : e 0 = 0 := e.to_add_equiv.map_zero\n\n@[simp] lemma map_mul : \u2200 x y, e (x * y) = (e x) * (e y) := e.to_mul_equiv.map_mul\n\n@[simp] lemma map_one : e 1 = 1 := e.to_mul_equiv.map_one\n\n@[simp] lemma commutes : \u2200 (r : R), e (algebra_map R A\u2081 r) = algebra_map R A\u2082 r :=\n e.commutes'\n\nlemma map_sum {\u03b9 : Type*} (f : \u03b9 \u2192 A\u2081) (s : finset \u03b9) :\n e (\u2211 x in s, f x) = \u2211 x in s, e (f x) :=\ne.to_add_equiv.map_sum f s\n\nlemma map_finsupp_sum {\u03b1 : Type*} [has_zero \u03b1] {\u03b9 : Type*} (f : \u03b9 \u2192\u2080 \u03b1) (g : \u03b9 \u2192 \u03b1 \u2192 A\u2081) :\n e (f.sum g) = f.sum (\u03bb i b, e (g i b)) :=\ne.map_sum _ _\n\n\/-- Interpret an algebra equivalence as an algebra homomorphism.\n\nThis definition is included for symmetry with the other `to_*_hom` projections.\nThe `simp` normal form is to use the coercion of the `has_coe_to_alg_hom` instance. -\/\ndef to_alg_hom : A\u2081 \u2192\u2090[R] A\u2082 :=\n{ map_one' := e.map_one, map_zero' := e.map_zero, ..e }\n\ninstance has_coe_to_alg_hom : has_coe (A\u2081 \u2243\u2090[R] A\u2082) (A\u2081 \u2192\u2090[R] A\u2082) :=\n\u27e8to_alg_hom\u27e9\n\n@[simp] lemma to_alg_hom_eq_coe : e.to_alg_hom = e := rfl\n\n@[simp, norm_cast] lemma coe_alg_hom : ((e : A\u2081 \u2192\u2090[R] A\u2082) : A\u2081 \u2192 A\u2082) = e :=\nrfl\n\nlemma coe_alg_hom_injective : function.injective (coe : (A\u2081 \u2243\u2090[R] A\u2082) \u2192 (A\u2081 \u2192\u2090[R] A\u2082)) :=\n\u03bb e\u2081 e\u2082 h, ext $ alg_hom.congr_fun h\n\n\/-- The two paths coercion can take to a `ring_hom` are equivalent -\/\nlemma coe_ring_hom_commutes : ((e : A\u2081 \u2192\u2090[R] A\u2082) : A\u2081 \u2192+* A\u2082) = ((e : A\u2081 \u2243+* A\u2082) : A\u2081 \u2192+* A\u2082) :=\nrfl\n\n@[simp] lemma map_pow : \u2200 (x : A\u2081) (n : \u2115), e (x ^ n) = (e x) ^ n := e.to_alg_hom.map_pow\n\nlemma injective : function.injective e := e.to_equiv.injective\n\nlemma surjective : function.surjective e := e.to_equiv.surjective\n\nlemma bijective : function.bijective e := e.to_equiv.bijective\n\ninstance : has_one (A\u2081 \u2243\u2090[R] A\u2081) := \u27e8{commutes' := \u03bb r, rfl, ..(1 : A\u2081 \u2243+* A\u2081)}\u27e9\n\ninstance : inhabited (A\u2081 \u2243\u2090[R] A\u2081) := \u27e81\u27e9\n\n\/-- Algebra equivalences are reflexive. -\/\n@[refl]\ndef refl : A\u2081 \u2243\u2090[R] A\u2081 := 1\n\n@[simp] lemma refl_to_alg_hom : \u2191(refl : A\u2081 \u2243\u2090[R] A\u2081) = alg_hom.id R A\u2081 := rfl\n\n@[simp] lemma coe_refl : \u21d1(refl : A\u2081 \u2243\u2090[R] A\u2081) = id := rfl\n\n\/-- Algebra equivalences are symmetric. -\/\n@[symm]\ndef symm (e : A\u2081 \u2243\u2090[R] A\u2082) : A\u2082 \u2243\u2090[R] A\u2081 :=\n{ commutes' := \u03bb r, by { rw \u2190e.to_ring_equiv.symm_apply_apply (algebra_map R A\u2081 r), congr,\n change _ = e _, rw e.commutes, },\n ..e.to_ring_equiv.symm, }\n\n\/-- See Note [custom simps projection] -\/\ndef simps.symm_apply (e : A\u2081 \u2243\u2090[R] A\u2082) : A\u2082 \u2192 A\u2081 := e.symm\n\ninitialize_simps_projections alg_equiv (to_fun \u2192 apply, inv_fun \u2192 symm_apply)\n\n@[simp] lemma inv_fun_eq_symm {e : A\u2081 \u2243\u2090[R] A\u2082} : e.inv_fun = e.symm := rfl\n\n@[simp] lemma symm_symm (e : A\u2081 \u2243\u2090[R] A\u2082) : e.symm.symm = e :=\nby { ext, refl, }\n\nlemma symm_bijective : function.bijective (symm : (A\u2081 \u2243\u2090[R] A\u2082) \u2192 (A\u2082 \u2243\u2090[R] A\u2081)) :=\nequiv.bijective \u27e8symm, symm, symm_symm, symm_symm\u27e9\n\n@[simp] lemma mk_coe' (e : A\u2081 \u2243\u2090[R] A\u2082) (f h\u2081 h\u2082 h\u2083 h\u2084 h\u2085) :\n (\u27e8f, e, h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A\u2082 \u2243\u2090[R] A\u2081) = e.symm :=\nsymm_bijective.injective $ ext $ \u03bb x, rfl\n\n@[simp] theorem symm_mk (f f') (h\u2081 h\u2082 h\u2083 h\u2084 h\u2085) :\n (\u27e8f, f', h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A\u2081 \u2243\u2090[R] A\u2082).symm =\n { to_fun := f', inv_fun := f,\n ..(\u27e8f, f', h\u2081, h\u2082, h\u2083, h\u2084, h\u2085\u27e9 : A\u2081 \u2243\u2090[R] A\u2082).symm } := rfl\n\n\/-- Algebra equivalences are transitive. -\/\n@[trans]\ndef trans (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) : A\u2081 \u2243\u2090[R] A\u2083 :=\n{ commutes' := \u03bb r, show e\u2082.to_fun (e\u2081.to_fun _) = _, by rw [e\u2081.commutes', e\u2082.commutes'],\n ..(e\u2081.to_ring_equiv.trans e\u2082.to_ring_equiv), }\n\n@[simp] lemma apply_symm_apply (e : A\u2081 \u2243\u2090[R] A\u2082) : \u2200 x, e (e.symm x) = x :=\n e.to_equiv.apply_symm_apply\n\n@[simp] lemma symm_apply_apply (e : A\u2081 \u2243\u2090[R] A\u2082) : \u2200 x, e.symm (e x) = x :=\n e.to_equiv.symm_apply_apply\n\n@[simp] lemma symm_trans_apply (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) (x : A\u2083) :\n (e\u2081.trans e\u2082).symm x = e\u2081.symm (e\u2082.symm x) := rfl\n\n@[simp] lemma coe_trans (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) :\n \u21d1(e\u2081.trans e\u2082) = e\u2082 \u2218 e\u2081 := rfl\n\nlemma trans_apply (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) (x : A\u2081) :\n (e\u2081.trans e\u2082) x = e\u2082 (e\u2081 x) := rfl\n\n@[simp] lemma comp_symm (e : A\u2081 \u2243\u2090[R] A\u2082) :\n alg_hom.comp (e : A\u2081 \u2192\u2090[R] A\u2082) \u2191e.symm = alg_hom.id R A\u2082 :=\nby { ext, simp }\n\n@[simp] lemma symm_comp (e : A\u2081 \u2243\u2090[R] A\u2082) :\n alg_hom.comp \u2191e.symm (e : A\u2081 \u2192\u2090[R] A\u2082) = alg_hom.id R A\u2081 :=\nby { ext, simp }\n\ntheorem left_inverse_symm (e : A\u2081 \u2243\u2090[R] A\u2082) : function.left_inverse e.symm e := e.left_inv\n\ntheorem right_inverse_symm (e : A\u2081 \u2243\u2090[R] A\u2082) : function.right_inverse e.symm e := e.right_inv\n\n\/-- If `A\u2081` is equivalent to `A\u2081'` and `A\u2082` is equivalent to `A\u2082'`, then the type of maps\n`A\u2081 \u2192\u2090[R] A\u2082` is equivalent to the type of maps `A\u2081' \u2192\u2090[R] A\u2082'`. -\/\ndef arrow_congr {A\u2081' A\u2082' : Type*} [semiring A\u2081'] [semiring A\u2082'] [algebra R A\u2081'] [algebra R A\u2082']\n (e\u2081 : A\u2081 \u2243\u2090[R] A\u2081') (e\u2082 : A\u2082 \u2243\u2090[R] A\u2082') : (A\u2081 \u2192\u2090[R] A\u2082) \u2243 (A\u2081' \u2192\u2090[R] A\u2082') :=\n{ to_fun := \u03bb f, (e\u2082.to_alg_hom.comp f).comp e\u2081.symm.to_alg_hom,\n inv_fun := \u03bb f, (e\u2082.symm.to_alg_hom.comp f).comp e\u2081.to_alg_hom,\n left_inv := \u03bb f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, symm_comp],\n simp only [\u2190alg_hom.comp_assoc, symm_comp, alg_hom.id_comp, alg_hom.comp_id] },\n right_inv := \u03bb f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, comp_symm],\n simp only [\u2190alg_hom.comp_assoc, comp_symm, alg_hom.id_comp, alg_hom.comp_id] } }\n\nlemma arrow_congr_comp {A\u2081' A\u2082' A\u2083' : Type*} [semiring A\u2081'] [semiring A\u2082'] [semiring A\u2083']\n [algebra R A\u2081'] [algebra R A\u2082'] [algebra R A\u2083'] (e\u2081 : A\u2081 \u2243\u2090[R] A\u2081') (e\u2082 : A\u2082 \u2243\u2090[R] A\u2082')\n (e\u2083 : A\u2083 \u2243\u2090[R] A\u2083') (f : A\u2081 \u2192\u2090[R] A\u2082) (g : A\u2082 \u2192\u2090[R] A\u2083) :\n arrow_congr e\u2081 e\u2083 (g.comp f) = (arrow_congr e\u2082 e\u2083 g).comp (arrow_congr e\u2081 e\u2082 f) :=\nby { ext, simp only [arrow_congr, equiv.coe_fn_mk, alg_hom.comp_apply],\n congr, exact (e\u2082.symm_apply_apply _).symm }\n\n@[simp] lemma arrow_congr_refl :\n arrow_congr alg_equiv.refl alg_equiv.refl = equiv.refl (A\u2081 \u2192\u2090[R] A\u2082) :=\nby { ext, refl }\n\n@[simp] lemma arrow_congr_trans {A\u2081' A\u2082' A\u2083' : Type*} [semiring A\u2081'] [semiring A\u2082'] [semiring A\u2083']\n [algebra R A\u2081'] [algebra R A\u2082'] [algebra R A\u2083'] (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2081' : A\u2081' \u2243\u2090[R] A\u2082')\n (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) (e\u2082' : A\u2082' \u2243\u2090[R] A\u2083') :\n arrow_congr (e\u2081.trans e\u2082) (e\u2081'.trans e\u2082') = (arrow_congr e\u2081 e\u2081').trans (arrow_congr e\u2082 e\u2082') :=\nby { ext, refl }\n\n@[simp] lemma arrow_congr_symm {A\u2081' A\u2082' : Type*} [semiring A\u2081'] [semiring A\u2082']\n [algebra R A\u2081'] [algebra R A\u2082'] (e\u2081 : A\u2081 \u2243\u2090[R] A\u2081') (e\u2082 : A\u2082 \u2243\u2090[R] A\u2082') :\n (arrow_congr e\u2081 e\u2082).symm = arrow_congr e\u2081.symm e\u2082.symm :=\nby { ext, refl }\n\n\/-- If an algebra morphism has an inverse, it is a algebra isomorphism. -\/\ndef of_alg_hom (f : A\u2081 \u2192\u2090[R] A\u2082) (g : A\u2082 \u2192\u2090[R] A\u2081) (h\u2081 : f.comp g = alg_hom.id R A\u2082)\n (h\u2082 : g.comp f = alg_hom.id R A\u2081) : A\u2081 \u2243\u2090[R] A\u2082 :=\n{ to_fun := f,\n inv_fun := g,\n left_inv := alg_hom.ext_iff.1 h\u2082,\n right_inv := alg_hom.ext_iff.1 h\u2081,\n ..f }\n\nlemma coe_alg_hom_of_alg_hom (f : A\u2081 \u2192\u2090[R] A\u2082) (g : A\u2082 \u2192\u2090[R] A\u2081) (h\u2081 h\u2082) :\n \u2191(of_alg_hom f g h\u2081 h\u2082) = f := alg_hom.ext $ \u03bb _, rfl\n\n@[simp]\nlemma of_alg_hom_coe_alg_hom (f : A\u2081 \u2243\u2090[R] A\u2082) (g : A\u2082 \u2192\u2090[R] A\u2081) (h\u2081 h\u2082) :\n of_alg_hom \u2191f g h\u2081 h\u2082 = f := ext $ \u03bb _, rfl\n\nlemma of_alg_hom_symm (f : A\u2081 \u2192\u2090[R] A\u2082) (g : A\u2082 \u2192\u2090[R] A\u2081) (h\u2081 h\u2082) :\n (of_alg_hom f g h\u2081 h\u2082).symm = of_alg_hom g f h\u2082 h\u2081 := rfl\n\n\/-- Promotes a bijective algebra homomorphism to an algebra equivalence. -\/\nnoncomputable def of_bijective (f : A\u2081 \u2192\u2090[R] A\u2082) (hf : function.bijective f) : A\u2081 \u2243\u2090[R] A\u2082 :=\n{ .. ring_equiv.of_bijective (f : A\u2081 \u2192+* A\u2082) hf, .. f }\n\n\/-- Forgetting the multiplicative structures, an equivalence of algebras is a linear equivalence. -\/\n@[simps apply] def to_linear_equiv (e : A\u2081 \u2243\u2090[R] A\u2082) : A\u2081 \u2243\u2097[R] A\u2082 :=\n{ to_fun := e,\n map_smul' := \u03bb r x, by simp [algebra.smul_def],\n inv_fun := e.symm,\n .. e }\n\n@[simp] lemma to_linear_equiv_refl :\n (alg_equiv.refl : A\u2081 \u2243\u2090[R] A\u2081).to_linear_equiv = linear_equiv.refl R A\u2081 := rfl\n\n@[simp] lemma to_linear_equiv_symm (e : A\u2081 \u2243\u2090[R] A\u2082) :\n e.to_linear_equiv.symm = e.symm.to_linear_equiv := rfl\n\n@[simp] lemma to_linear_equiv_trans (e\u2081 : A\u2081 \u2243\u2090[R] A\u2082) (e\u2082 : A\u2082 \u2243\u2090[R] A\u2083) :\n (e\u2081.trans e\u2082).to_linear_equiv = e\u2081.to_linear_equiv.trans e\u2082.to_linear_equiv := rfl\n\ntheorem to_linear_equiv_injective : function.injective (to_linear_equiv : _ \u2192 (A\u2081 \u2243\u2097[R] A\u2082)) :=\n\u03bb e\u2081 e\u2082 h, ext $ linear_equiv.congr_fun h\n\n\/-- Interpret an algebra equivalence as a linear map. -\/\ndef to_linear_map : A\u2081 \u2192\u2097[R] A\u2082 :=\ne.to_alg_hom.to_linear_map\n\n@[simp] lemma to_alg_hom_to_linear_map :\n (e : A\u2081 \u2192\u2090[R] A\u2082).to_linear_map = e.to_linear_map := rfl\n\n@[simp] lemma to_linear_equiv_to_linear_map :\n e.to_linear_equiv.to_linear_map = e.to_linear_map := rfl\n\n@[simp] lemma to_linear_map_apply (x : A\u2081) : e.to_linear_map x = e x := rfl\n\ntheorem to_linear_map_injective : function.injective (to_linear_map : _ \u2192 (A\u2081 \u2192\u2097[R] A\u2082)) :=\n\u03bb e\u2081 e\u2082 h, ext $ linear_map.congr_fun h\n\n@[simp] lemma trans_to_linear_map (f : A\u2081 \u2243\u2090[R] A\u2082) (g : A\u2082 \u2243\u2090[R] A\u2083) :\n (f.trans g).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl\n\nsection of_linear_equiv\n\nvariables (l : A\u2081 \u2243\u2097[R] A\u2082)\n (map_mul : \u2200 x y : A\u2081, l (x * y) = l x * l y)\n (commutes : \u2200 r : R, l (algebra_map R A\u2081 r) = algebra_map R A\u2082 r)\n\n\/--\nUpgrade a linear equivalence to an algebra equivalence,\ngiven that it distributes over multiplication and action of scalars.\n-\/\n@[simps apply]\ndef of_linear_equiv : A\u2081 \u2243\u2090[R] A\u2082 :=\n{ to_fun := l,\n inv_fun := l.symm,\n map_mul' := map_mul,\n commutes' := commutes,\n ..l }\n\n@[simp]\nlemma of_linear_equiv_symm :\n (of_linear_equiv l map_mul commutes).symm = of_linear_equiv l.symm\n ((of_linear_equiv l map_mul commutes).symm.map_mul)\n ((of_linear_equiv l map_mul commutes).symm.commutes) :=\nrfl\n\n@[simp] lemma of_linear_equiv_to_linear_equiv (map_mul) (commutes) :\n of_linear_equiv e.to_linear_equiv map_mul commutes = e :=\nby { ext, refl }\n\n@[simp] lemma to_linear_equiv_of_linear_equiv :\n to_linear_equiv (of_linear_equiv l map_mul commutes) = l :=\nby { ext, refl }\n\nend of_linear_equiv\n\ninstance aut : group (A\u2081 \u2243\u2090[R] A\u2081) :=\n{ mul := \u03bb \u03d5 \u03c8, \u03c8.trans \u03d5,\n mul_assoc := \u03bb \u03d5 \u03c8 \u03c7, rfl,\n one := 1,\n one_mul := \u03bb \u03d5, by { ext, refl },\n mul_one := \u03bb \u03d5, by { ext, refl },\n inv := symm,\n mul_left_inv := \u03bb \u03d5, by { ext, exact symm_apply_apply \u03d5 a } }\n\n@[simp] lemma mul_apply (e\u2081 e\u2082 : A\u2081 \u2243\u2090[R] A\u2081) (x : A\u2081) : (e\u2081 * e\u2082) x = e\u2081 (e\u2082 x) := rfl\n\n\/-- An algebra isomorphism induces a group isomorphism between automorphism groups -\/\n@[simps apply]\ndef aut_congr (\u03d5 : A\u2081 \u2243\u2090[R] A\u2082) : (A\u2081 \u2243\u2090[R] A\u2081) \u2243* (A\u2082 \u2243\u2090[R] A\u2082) :=\n{ to_fun := \u03bb \u03c8, \u03d5.symm.trans (\u03c8.trans \u03d5),\n inv_fun := \u03bb \u03c8, \u03d5.trans (\u03c8.trans \u03d5.symm),\n left_inv := \u03bb \u03c8, by { ext, simp_rw [trans_apply, symm_apply_apply] },\n right_inv := \u03bb \u03c8, by { ext, simp_rw [trans_apply, apply_symm_apply] },\n map_mul' := \u03bb \u03c8 \u03c7, by { ext, simp only [mul_apply, trans_apply, symm_apply_apply] } }\n\n@[simp] lemma aut_congr_refl : aut_congr (alg_equiv.refl) = mul_equiv.refl (A\u2081 \u2243\u2090[R] A\u2081) :=\nby { ext, refl }\n\n@[simp] lemma aut_congr_symm (\u03d5 : A\u2081 \u2243\u2090[R] A\u2082) : (aut_congr \u03d5).symm = aut_congr \u03d5.symm := rfl\n\n@[simp] lemma aut_congr_trans (\u03d5 : A\u2081 \u2243\u2090[R] A\u2082) (\u03c8 : A\u2082 \u2243\u2090[R] A\u2083) :\n (aut_congr \u03d5).trans (aut_congr \u03c8) = aut_congr (\u03d5.trans \u03c8) := rfl\n\n\/-- The tautological action by `A\u2081 \u2243\u2090[R] A\u2081` on `A\u2081`.\n\nThis generalizes `function.End.apply_mul_action`. -\/\ninstance apply_mul_semiring_action : mul_semiring_action (A\u2081 \u2243\u2090[R] A\u2081) A\u2081 :=\n{ smul := ($),\n smul_zero := alg_equiv.map_zero,\n smul_add := alg_equiv.map_add,\n smul_one := alg_equiv.map_one,\n smul_mul := alg_equiv.map_mul,\n one_smul := \u03bb _, rfl,\n mul_smul := \u03bb _ _ _, rfl }\n\n@[simp] protected lemma smul_def (f : A\u2081 \u2243\u2090[R] A\u2081) (a : A\u2081) : f \u2022 a = f a := rfl\n\ninstance apply_has_faithful_scalar : has_faithful_scalar (A\u2081 \u2243\u2090[R] A\u2081) A\u2081 :=\n\u27e8\u03bb _ _, alg_equiv.ext\u27e9\n\ninstance apply_smul_comm_class : smul_comm_class R (A\u2081 \u2243\u2090[R] A\u2081) A\u2081 :=\n{ smul_comm := \u03bb r e a, (e.to_linear_equiv.map_smul r a).symm }\n\ninstance apply_smul_comm_class' : smul_comm_class (A\u2081 \u2243\u2090[R] A\u2081) R A\u2081 :=\n{ smul_comm := \u03bb e r a, (e.to_linear_equiv.map_smul r a) }\n\n@[simp] lemma algebra_map_eq_apply (e : A\u2081 \u2243\u2090[R] A\u2082) {y : R} {x : A\u2081} :\n (algebra_map R A\u2082 y = e x) \u2194 (algebra_map R A\u2081 y = x) :=\n\u27e8\u03bb h, by simpa using e.symm.to_alg_hom.algebra_map_eq_apply h,\n \u03bb h, e.to_alg_hom.algebra_map_eq_apply h\u27e9\n\nend semiring\n\nsection comm_semiring\n\nvariables [comm_semiring R] [comm_semiring A\u2081] [comm_semiring A\u2082]\nvariables [algebra R A\u2081] [algebra R A\u2082] (e : A\u2081 \u2243\u2090[R] A\u2082)\n\nlemma map_prod {\u03b9 : Type*} (f : \u03b9 \u2192 A\u2081) (s : finset \u03b9) :\n e (\u220f x in s, f x) = \u220f x in s, e (f x) :=\ne.to_alg_hom.map_prod f s\n\nlemma map_finsupp_prod {\u03b1 : Type*} [has_zero \u03b1] {\u03b9 : Type*} (f : \u03b9 \u2192\u2080 \u03b1) (g : \u03b9 \u2192 \u03b1 \u2192 A\u2081) :\n e (f.prod g) = f.prod (\u03bb i a, e (g i a)) :=\ne.to_alg_hom.map_finsupp_prod f g\n\nend comm_semiring\n\nsection ring\n\nvariables [comm_ring R] [ring A\u2081] [ring A\u2082]\nvariables [algebra R A\u2081] [algebra R A\u2082] (e : A\u2081 \u2243\u2090[R] A\u2082)\n\n@[simp] lemma map_neg (x) : e (-x) = -e x :=\ne.to_alg_hom.map_neg x\n\n@[simp] lemma map_sub (x y) : e (x - y) = e x - e y :=\ne.to_alg_hom.map_sub x y\n\nend ring\n\nsection division_ring\n\nvariables [comm_ring R] [division_ring A\u2081] [division_ring A\u2082]\nvariables [algebra R A\u2081] [algebra R A\u2082] (e : A\u2081 \u2243\u2090[R] A\u2082)\n\n@[simp] lemma map_inv (x) : e (x\u207b\u00b9) = (e x)\u207b\u00b9 :=\ne.to_alg_hom.map_inv x\n\n@[simp] lemma map_div (x y) : e (x \/ y) = e x \/ e y :=\ne.to_alg_hom.map_div x y\n\nend division_ring\n\nend alg_equiv\n\nnamespace mul_semiring_action\n\nvariables {M G : Type*} (R A : Type*) [comm_semiring R] [semiring A] [algebra R A]\n\nsection\nvariables [monoid M] [mul_semiring_action M A] [smul_comm_class M R A]\n\n\/-- Each element of the monoid defines a algebra homomorphism.\n\nThis is a stronger version of `mul_semiring_action.to_ring_hom` and\n`distrib_mul_action.to_linear_map`. -\/\n@[simps]\ndef to_alg_hom (m : M) : A \u2192\u2090[R] A :=\nalg_hom.mk' (mul_semiring_action.to_ring_hom _ _ m) (smul_comm _)\n\ntheorem to_alg_hom_injective [has_faithful_scalar M A] :\n function.injective (mul_semiring_action.to_alg_hom R A : M \u2192 A \u2192\u2090[R] A) :=\n\u03bb m\u2081 m\u2082 h, eq_of_smul_eq_smul $ \u03bb r, alg_hom.ext_iff.1 h r\n\nend\n\nsection\nvariables [group G] [mul_semiring_action G A] [smul_comm_class G R A]\n\n\/-- Each element of the group defines a algebra equivalence.\n\nThis is a stronger version of `mul_semiring_action.to_ring_equiv` and\n`distrib_mul_action.to_linear_equiv`. -\/\n@[simps]\ndef to_alg_equiv (g : G) : A \u2243\u2090[R] A :=\n{ .. mul_semiring_action.to_ring_equiv _ _ g,\n .. mul_semiring_action.to_alg_hom R A g }\n\ntheorem to_alg_equiv_injective [has_faithful_scalar G A] :\n function.injective (mul_semiring_action.to_alg_equiv R A : G \u2192 A \u2243\u2090[R] A) :=\n\u03bb m\u2081 m\u2082 h, eq_of_smul_eq_smul $ \u03bb r, alg_equiv.ext_iff.1 h r\n\nend\n\nend mul_semiring_action\n\nsection nat\n\nvariables {R : Type*} [semiring R]\n\n-- Lower the priority so that `algebra.id` is picked most of the time when working with\n-- `\u2115`-algebras. This is only an issue since `algebra.id` and `algebra_nat` are not yet defeq.\n-- TODO: fix this by adding an `of_nat` field to semirings.\n\/-- Semiring \u2964 \u2115-Alg -\/\n@[priority 99] instance algebra_nat : algebra \u2115 R :=\n{ commutes' := nat.cast_commute,\n smul_def' := \u03bb _ _, nsmul_eq_mul _ _,\n to_ring_hom := nat.cast_ring_hom R }\n\ninstance nat_algebra_subsingleton : subsingleton (algebra \u2115 R) :=\n\u27e8\u03bb P Q, by { ext, simp, }\u27e9\n\nend nat\n\nnamespace ring_hom\n\nvariables {R S : Type*}\n\n\/-- Reinterpret a `ring_hom` as an `\u2115`-algebra homomorphism. -\/\ndef to_nat_alg_hom [semiring R] [semiring S] (f : R \u2192+* S) :\n R \u2192\u2090[\u2115] S :=\n{ to_fun := f, commutes' := \u03bb n, by simp, .. f }\n\n\/-- Reinterpret a `ring_hom` as a `\u2124`-algebra homomorphism. -\/\ndef to_int_alg_hom [ring R] [ring S] [algebra \u2124 R] [algebra \u2124 S] (f : R \u2192+* S) :\n R \u2192\u2090[\u2124] S :=\n{ commutes' := \u03bb n, by simp, .. f }\n\n@[simp] lemma map_rat_algebra_map [ring R] [ring S] [algebra \u211a R] [algebra \u211a S] (f : R \u2192+* S)\n (r : \u211a) :\n f (algebra_map \u211a R r) = algebra_map \u211a S r :=\nring_hom.ext_iff.1 (subsingleton.elim (f.comp (algebra_map \u211a R)) (algebra_map \u211a S)) r\n\n\/-- Reinterpret a `ring_hom` as a `\u211a`-algebra homomorphism. -\/\ndef to_rat_alg_hom [ring R] [ring S] [algebra \u211a R] [algebra \u211a S] (f : R \u2192+* S) :\n R \u2192\u2090[\u211a] S :=\n{ commutes' := f.map_rat_algebra_map, .. f }\n\nend ring_hom\n\nnamespace rat\n\ninstance algebra_rat {\u03b1} [division_ring \u03b1] [char_zero \u03b1] : algebra \u211a \u03b1 :=\n(rat.cast_hom \u03b1).to_algebra' $ \u03bb r x, r.cast_commute x\n\n@[simp] theorem algebra_map_rat_rat : algebra_map \u211a \u211a = ring_hom.id \u211a :=\nsubsingleton.elim _ _\n\n-- TODO[gh-6025]: make this an instance once safe to do so\nlemma algebra_rat_subsingleton {\u03b1} [semiring \u03b1] :\n subsingleton (algebra \u211a \u03b1) :=\n\u27e8\u03bb x y, algebra.algebra_ext x y $ ring_hom.congr_fun $ subsingleton.elim _ _\u27e9\n\nend rat\n\nnamespace char_zero\n\nvariables {R : Type*} (S : Type*) [comm_semiring R] [semiring S] [algebra R S]\n\nlemma of_algebra [char_zero S] : char_zero R :=\n\u27e8begin\n suffices : function.injective (algebra_map R S \u2218 coe),\n { exact this.of_comp },\n convert char_zero.cast_injective,\n ext n,\n rw [function.comp_app, \u2190 (algebra_map \u2115 _).eq_nat_cast, \u2190 ring_hom.comp_apply,\n ring_hom.eq_nat_cast],\n all_goals { apply_instance }\nend\u27e9\n\nend char_zero\n\nnamespace algebra\nopen module\n\nvariables (R : Type u) (A : Type v)\n\nvariables [comm_semiring R] [semiring A] [algebra R A]\n\n\/-- `algebra_map` as an `alg_hom`. -\/\ndef of_id : R \u2192\u2090[R] A :=\n{ commutes' := \u03bb _, rfl, .. algebra_map R A }\nvariables {R}\n\ntheorem of_id_apply (r) : of_id R A r = algebra_map R A r := rfl\n\nend algebra\n\nsection int\n\nvariables (R : Type*) [ring R]\n\n-- Lower the priority so that `algebra.id` is picked most of the time when working with\n-- `\u2124`-algebras. This is only an issue since `algebra.id \u2124` and `algebra_int \u2124` are not yet defeq.\n-- TODO: fix this by adding an `of_int` field to rings.\n\/-- Ring \u2964 \u2124-Alg -\/\n@[priority 99] instance algebra_int : algebra \u2124 R :=\n{ commutes' := int.cast_commute,\n smul_def' := \u03bb _ _, zsmul_eq_mul _ _,\n to_ring_hom := int.cast_ring_hom R }\n\nvariables {R}\n\ninstance int_algebra_subsingleton : subsingleton (algebra \u2124 R) :=\n\u27e8\u03bb P Q, by { ext, simp, }\u27e9\n\nend int\n\n\/-!\nThe R-algebra structure on `\u03a0 i : I, A i` when each `A i` is an R-algebra.\n\nWe couldn't set this up back in `algebra.pi_instances` because this file imports it.\n-\/\nnamespace pi\n\nvariable {I : Type u} -- The indexing type\nvariable {R : Type*} -- The scalar type\nvariable {f : I \u2192 Type v} -- The family of types already equipped with instances\nvariables (x y : \u03a0 i, f i) (i : I)\nvariables (I f)\n\ninstance algebra {r : comm_semiring R}\n [s : \u2200 i, semiring (f i)] [\u2200 i, algebra R (f i)] :\n algebra R (\u03a0 i : I, f i) :=\n{ commutes' := \u03bb a f, begin ext, simp [algebra.commutes], end,\n smul_def' := \u03bb a f, begin ext, simp [algebra.smul_def], end,\n ..(pi.ring_hom (\u03bb i, algebra_map R (f i)) : R \u2192+* \u03a0 i : I, f i) }\n\n@[simp] lemma algebra_map_apply {r : comm_semiring R}\n [s : \u2200 i, semiring (f i)] [\u2200 i, algebra R (f i)] (a : R) (i : I) :\n algebra_map R (\u03a0 i, f i) a i = algebra_map R (f i) a := rfl\n\n-- One could also build a `\u03a0 i, R i`-algebra structure on `\u03a0 i, A i`,\n-- when each `A i` is an `R i`-algebra, although I'm not sure that it's useful.\n\nvariables {I} (R) (f)\n\n\/-- `function.eval` as an `alg_hom`. The name matches `pi.eval_ring_hom`, `pi.eval_monoid_hom`,\netc. -\/\n@[simps]\ndef eval_alg_hom {r : comm_semiring R} [\u03a0 i, semiring (f i)] [\u03a0 i, algebra R (f i)] (i : I) :\n (\u03a0 i, f i) \u2192\u2090[R] f i :=\n{ to_fun := \u03bb f, f i, commutes' := \u03bb r, rfl, .. pi.eval_ring_hom f i}\n\nvariables (A B : Type*) [comm_semiring R] [semiring B] [algebra R B]\n\n\/-- `function.const` as an `alg_hom`. The name matches `pi.const_ring_hom`, `pi.const_monoid_hom`,\netc. -\/\n@[simps]\ndef const_alg_hom : B \u2192\u2090[R] (A \u2192 B) :=\n{ to_fun := function.const _,\n commutes' := \u03bb r, rfl,\n .. pi.const_ring_hom A B}\n\n\/-- When `R` is commutative and permits an `algebra_map`, `pi.const_ring_hom` is equal to that\nmap. -\/\n@[simp] lemma const_ring_hom_eq_algebra_map : const_ring_hom A R = algebra_map R (A \u2192 R) :=\nrfl\n\n@[simp] lemma const_alg_hom_eq_algebra_of_id : const_alg_hom R A R = algebra.of_id R (A \u2192 R) :=\nrfl\n\nend pi\n\nsection is_scalar_tower\n\nvariables {R : Type*} [comm_semiring R]\nvariables (A : Type*) [semiring A] [algebra R A]\nvariables {M : Type*} [add_comm_monoid M] [module A M] [module R M] [is_scalar_tower R A M]\nvariables {N : Type*} [add_comm_monoid N] [module A N] [module R N] [is_scalar_tower R A N]\n\nlemma algebra_compatible_smul (r : R) (m : M) : r \u2022 m = ((algebra_map R A) r) \u2022 m :=\nby rw [\u2190(one_smul A m), \u2190smul_assoc, algebra.smul_def, mul_one, one_smul]\n\n@[simp] lemma algebra_map_smul (r : R) (m : M) : ((algebra_map R A) r) \u2022 m = r \u2022 m :=\n(algebra_compatible_smul A r m).symm\n\nvariable {A}\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_scalar_tower.to_smul_comm_class : smul_comm_class R A M :=\n\u27e8\u03bb r a m, by rw [algebra_compatible_smul A r (a \u2022 m), smul_smul, algebra.commutes, mul_smul,\n \u2190algebra_compatible_smul]\u27e9\n\n@[priority 100] -- see Note [lower instance priority]\ninstance is_scalar_tower.to_smul_comm_class' : smul_comm_class A R M :=\nsmul_comm_class.symm _ _ _\n\nlemma smul_algebra_smul_comm (r : R) (a : A) (m : M) : a \u2022 r \u2022 m = r \u2022 a \u2022 m :=\nsmul_comm _ _ _\n\nnamespace linear_map\n\ninstance coe_is_scalar_tower : has_coe (M \u2192\u2097[A] N) (M \u2192\u2097[R] N) :=\n\u27e8restrict_scalars R\u27e9\n\nvariables (R) {A M N}\n\n@[simp, norm_cast squash] lemma coe_restrict_scalars_eq_coe (f : M \u2192\u2097[A] N) :\n (f.restrict_scalars R : M \u2192 N) = f := rfl\n\n@[simp, norm_cast squash] lemma coe_coe_is_scalar_tower (f : M \u2192\u2097[A] N) :\n ((f : M \u2192\u2097[R] N) : M \u2192 N) = f := rfl\n\n\/-- `A`-linearly coerce a `R`-linear map from `M` to `A` to a function, given an algebra `A` over\na commutative semiring `R` and `M` a module over `R`. -\/\ndef lto_fun (R : Type u) (M : Type v) (A : Type w)\n [comm_semiring R] [add_comm_monoid M] [module R M] [comm_ring A] [algebra R A] :\n (M \u2192\u2097[R] A) \u2192\u2097[A] (M \u2192 A) :=\n{ to_fun := linear_map.to_fun,\n map_add' := \u03bb f g, rfl,\n map_smul' := \u03bb c f, rfl }\n\nend linear_map\n\nend is_scalar_tower\n\n\/-! TODO: The following lemmas no longer involve `algebra` at all, and could be moved closer\nto `algebra\/module\/submodule.lean`. Currently this is tricky because `ker`, `range`, `\u22a4`, and `\u22a5`\nare all defined in `linear_algebra\/basic.lean`. -\/\nsection module\nopen module\n\nvariables (R S M N : Type*) [semiring R] [semiring S] [has_scalar R S]\nvariables [add_comm_monoid M] [module R M] [module S M] [is_scalar_tower R S M]\nvariables [add_comm_monoid N] [module R N] [module S N] [is_scalar_tower R S N]\n\nvariables {S M N}\n\n@[simp]\nlemma linear_map.ker_restrict_scalars (f : M \u2192\u2097[S] N) :\n (f.restrict_scalars R).ker = f.ker.restrict_scalars R :=\nrfl\n\nend module\n\nnamespace submodule\n\nvariables (R A M : Type*)\nvariables [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M]\nvariables [module R M] [module A M] [is_scalar_tower R A M]\n\n\/-- If `A` is an `R`-algebra such that the induced morhpsim `R \u2192+* A` is surjective, then the\n`R`-module generated by a set `X` equals the `A`-module generated by `X`. -\/\nlemma span_eq_restrict_scalars (X : set M) (hsur : function.surjective (algebra_map R A)) :\n span R X = restrict_scalars R (span A X) :=\nbegin\n apply (span_le_restrict_scalars R A X).antisymm (\u03bb m hm, _),\n refine span_induction hm subset_span (zero_mem _) (\u03bb _ _, add_mem _) (\u03bb a m hm, _),\n obtain \u27e8r, rfl\u27e9 := hsur a,\n simpa [algebra_map_smul] using smul_mem _ r hm\nend\n\nend submodule\n\nnamespace alg_hom\n\nvariables {R : Type u} {A : Type v} {B : Type w} {I : Type*}\n\nvariables [comm_semiring R] [semiring A] [semiring B]\nvariables [algebra R A] [algebra R B]\n\n\/-- `R`-algebra homomorphism between the function spaces `I \u2192 A` and `I \u2192 B`, induced by an\n`R`-algebra homomorphism `f` between `A` and `B`. -\/\n@[simps] protected def comp_left (f : A \u2192\u2090[R] B) (I : Type*) : (I \u2192 A) \u2192\u2090[R] (I \u2192 B) :=\n{ to_fun := \u03bb h, f \u2218 h,\n commutes' := \u03bb c, by { ext, exact f.commutes' c },\n .. f.to_ring_hom.comp_left I }\n\nend alg_hom\n","avg_line_length":34.7546907575,"max_line_length":100,"alphanum_fraction":0.6446452851} -{"size":28075,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2021 S\u00e9bastien Gou\u00ebzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: S\u00e9bastien Gou\u00ebzel\n-\/\n\nimport measure_theory.measure.regular\nimport topology.semicontinuous\nimport measure_theory.integral.bochner\nimport topology.instances.ereal\n\n\/-!\n# Vitali-Carath\u00e9odory theorem\n\nVitali-Carath\u00e9odory theorem asserts the following. Consider an integrable function `f : \u03b1 \u2192 \u211d` on\na space with a regular measure. Then there exists a function `g : \u03b1 \u2192 ereal` such that `f x < g x`\neverywhere, `g` is lower semicontinuous, and the integral of `g` is arbitrarily close to that of\n`f`. This theorem is proved in this file, as `exists_lt_lower_semicontinuous_integral_lt`.\n\nSymmetrically, there exists `g < f` which is upper semicontinuous, with integral arbitrarily close\nto that of `f`. It follows from the previous statement applied to `-f`. It is formalized under\nthe name `exists_upper_semicontinuous_lt_integral_gt`.\n\nThe most classical version of Vitali-Carath\u00e9odory theorem only ensures a large inequality\n`f x \u2264 g x`. For applications to the fundamental theorem of calculus, though, the strict inequality\n`f x < g x` is important. Therefore, we prove the stronger version with strict inequalities in this\nfile. There is a price to pay: we require that the measure is `\u03c3`-finite, which is not necessary for\nthe classical Vitali-Carath\u00e9odory theorem. Since this is satisfied in all applications, this is\nnot a real problem.\n\n## Sketch of proof\n\nDecomposing `f` as the difference of its positive and negative parts, it suffices to show that a\npositive function can be bounded from above by a lower semicontinuous function, and from below\nby an upper semicontinuous function, with integrals close to that of `f`.\n\nFor the bound from above, write `f` as a series `\u2211' n, c\u2099 * indicator (s\u2099)` of simple functions.\nThen, approximate `s\u2099` by a larger open set `u\u2099` with measure very close to that of `s\u2099` (this is\npossible by regularity of the measure), and set `g = \u2211' n, c\u2099 * indicator (u\u2099)`. It is\nlower semicontinuous as a series of lower semicontinuous functions, and its integral is arbitrarily\nclose to that of `f`.\n\nFor the bound from below, use finitely many terms in the series, and approximate `s\u2099` from inside by\na closed set `F\u2099`. Then `\u2211 n < N, c\u2099 * indicator (F\u2099)` is bounded from above by `f`, it is\nupper semicontinuous as a finite sum of upper semicontinuous functions, and its integral is\narbitrarily close to that of `f`.\n\nThe main pain point in the implementation is that one needs to jump between the spaces `\u211d`, `\u211d\u22650`,\n`\u211d\u22650\u221e` and `ereal` (and be careful that addition is not well behaved on `ereal`), and between\n`lintegral` and `integral`.\n\nWe first show the bound from above for simple functions and the nonnegative integral\n(this is the main nontrivial mathematical point), then deduce it for general nonnegative functions,\nfirst for the nonnegative integral and then for the Bochner integral.\n\nThen we follow the same steps for the lower bound.\n\nFinally, we glue them together to obtain the main statement\n`exists_lt_lower_semicontinuous_integral_lt`.\n\n## Related results\n\nAre you looking for a result on approximation by continuous functions (not just semicontinuous)?\nSee result `measure_theory.Lp.continuous_map_dense`, in the file\n`measure_theory.continuous_map_dense`.\n\n## References\n\n[Rudin, *Real and Complex Analysis* (Theorem 2.24)][rudin2006real]\n\n-\/\n\nopen_locale ennreal nnreal\n\nopen measure_theory measure_theory.measure\n\nvariables {\u03b1 : Type*} [topological_space \u03b1] [measurable_space \u03b1] [borel_space \u03b1] (\u03bc : measure \u03b1)\n [weakly_regular \u03bc]\n\nnamespace measure_theory\n\nlocal infixr ` \u2192\u209b `:25 := simple_func\n\n\/-! ### Lower semicontinuous upper bound for nonnegative functions -\/\n\n\/-- Given a simple function `f` with values in `\u211d\u22650`, there exists a lower semicontinuous\nfunction `g \u2265 f` with integral arbitrarily close to that of `f`. Formulation in terms of\n`lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma simple_func.exists_le_lower_semicontinuous_lintegral_ge :\n \u2200 (f : \u03b1 \u2192\u209b \u211d\u22650) {\u03b5 : \u211d\u22650\u221e} (\u03b5pos : 0 < \u03b5),\n \u2203 g : \u03b1 \u2192 \u211d\u22650, (\u2200 x, f x \u2264 g x) \u2227 lower_semicontinuous g \u2227\n (\u222b\u207b x, g x \u2202\u03bc \u2264 \u222b\u207b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n refine simple_func.induction _ _,\n { assume c s hs \u03b5 \u03b5pos,\n let f := simple_func.piecewise s hs (simple_func.const \u03b1 c) (simple_func.const \u03b1 0),\n by_cases h : \u222b\u207b x, f x \u2202\u03bc = \u22a4,\n { refine \u27e8\u03bb x, c, \u03bb x, _, lower_semicontinuous_const,\n by simp only [ennreal.top_add, le_top, h]\u27e9,\n simp only [simple_func.coe_const, simple_func.const_zero, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise],\n exact set.indicator_le_self _ _ _ },\n by_cases hc : c = 0,\n { refine \u27e8\u03bb x, 0, _, lower_semicontinuous_const, _\u27e9,\n { simp only [hc, set.indicator_zero', pi.zero_apply, simple_func.const_zero, implies_true_iff,\n eq_self_iff_true, simple_func.coe_zero, set.piecewise_eq_indicator,\n simple_func.coe_piecewise, le_zero_iff] },\n { simp only [lintegral_const, zero_mul, zero_le, ennreal.coe_zero] } },\n have : \u03bc s < \u03bc s + \u03b5 \/ c,\n { have : (0 : \u211d\u22650\u221e) < \u03b5 \/ c := ennreal.div_pos_iff.2 \u27e8\u03b5pos.ne', ennreal.coe_ne_top\u27e9,\n simpa using (ennreal.add_lt_add_iff_left _).2 this,\n simpa only [hs, hc, lt_top_iff_ne_top, true_and, simple_func.coe_const, function.const_apply,\n lintegral_const, ennreal.coe_indicator, set.univ_inter, ennreal.coe_ne_top,\n measurable_set.univ, with_top.mul_eq_top_iff, simple_func.const_zero, or_false,\n lintegral_indicator, ennreal.coe_eq_zero, ne.def, not_false_iff, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise, false_and, restrict_apply] using h },\n obtain \u27e8u, u_open, su, \u03bcu\u27e9 : \u2203 u, is_open u \u2227 s \u2286 u \u2227 \u03bc u < \u03bc s + \u03b5 \/ c :=\n hs.exists_is_open_lt_of_lt _ this,\n refine \u27e8set.indicator u (\u03bb x, c), \u03bb x, _, u_open.lower_semicontinuous_indicator (zero_le _), _\u27e9,\n { simp only [simple_func.coe_const, simple_func.const_zero, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise],\n exact set.indicator_le_indicator_of_subset su (\u03bb x, zero_le _) _ },\n { suffices : (c : \u211d\u22650\u221e) * \u03bc u \u2264 c * \u03bc s + \u03b5, by\n simpa only [hs, u_open.measurable_set, simple_func.coe_const, function.const_apply,\n lintegral_const, ennreal.coe_indicator, set.univ_inter, measurable_set.univ,\n simple_func.const_zero, lintegral_indicator, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise, restrict_apply],\n calc (c : \u211d\u22650\u221e) * \u03bc u \u2264 c * (\u03bc s + \u03b5 \/ c) : ennreal.mul_le_mul (le_refl _) \u03bcu.le\n ... = c * \u03bc s + \u03b5 :\n begin\n simp_rw [mul_add],\n rw ennreal.mul_div_cancel' _ ennreal.coe_ne_top,\n simpa using hc,\n end } },\n { assume f\u2081 f\u2082 H h\u2081 h\u2082 \u03b5 \u03b5pos,\n rcases h\u2081 (ennreal.half_pos \u03b5pos) with \u27e8g\u2081, f\u2081_le_g\u2081, g\u2081cont, g\u2081int\u27e9,\n rcases h\u2082 (ennreal.half_pos \u03b5pos) with \u27e8g\u2082, f\u2082_le_g\u2082, g\u2082cont, g\u2082int\u27e9,\n refine \u27e8\u03bb x, g\u2081 x + g\u2082 x, \u03bb x, add_le_add (f\u2081_le_g\u2081 x) (f\u2082_le_g\u2082 x), g\u2081cont.add g\u2082cont, _\u27e9,\n simp only [simple_func.coe_add, ennreal.coe_add, pi.add_apply],\n rw [lintegral_add f\u2081.measurable.coe_nnreal_ennreal f\u2082.measurable.coe_nnreal_ennreal,\n lintegral_add g\u2081cont.measurable.coe_nnreal_ennreal g\u2082cont.measurable.coe_nnreal_ennreal],\n convert add_le_add g\u2081int g\u2082int using 1,\n conv_lhs { rw \u2190 ennreal.add_halves \u03b5 },\n abel }\nend\n\nopen simple_func (eapprox_diff tsum_eapprox_diff)\n\n\/-- Given a measurable function `f` with values in `\u211d\u22650`, there exists a lower semicontinuous\nfunction `g \u2265 f` with integral arbitrarily close to that of `f`. Formulation in terms of\n`lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_le_lower_semicontinuous_lintegral_ge\n (f : \u03b1 \u2192 \u211d\u22650\u221e) (hf : measurable f) {\u03b5 : \u211d\u22650\u221e} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650\u221e, (\u2200 x, f x \u2264 g x) \u2227 lower_semicontinuous g \u2227 (\u222b\u207b x, g x \u2202\u03bc \u2264 \u222b\u207b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n rcases ennreal.exists_pos_sum_of_encodable' \u03b5pos \u2115 with \u27e8\u03b4, \u03b4pos, h\u03b4\u27e9,\n have : \u2200 n, \u2203 g : \u03b1 \u2192 \u211d\u22650, (\u2200 x, simple_func.eapprox_diff f n x \u2264 g x) \u2227 lower_semicontinuous g \u2227\n (\u222b\u207b x, g x \u2202\u03bc \u2264 \u222b\u207b x, simple_func.eapprox_diff f n x \u2202\u03bc + \u03b4 n) :=\n \u03bb n, simple_func.exists_le_lower_semicontinuous_lintegral_ge \u03bc\n (simple_func.eapprox_diff f n) (\u03b4pos n),\n choose g f_le_g gcont hg using this,\n refine \u27e8\u03bb x, (\u2211' n, g n x), \u03bb x, _, _, _\u27e9,\n { rw \u2190 tsum_eapprox_diff f hf,\n exact ennreal.tsum_le_tsum (\u03bb n, ennreal.coe_le_coe.2 (f_le_g n x)) },\n { apply lower_semicontinuous_tsum (\u03bb n, _),\n exact ennreal.continuous_coe.comp_lower_semicontinuous (gcont n)\n (\u03bb x y hxy, ennreal.coe_le_coe.2 hxy) },\n { calc \u222b\u207b x, \u2211' (n : \u2115), g n x \u2202\u03bc\n = \u2211' n, \u222b\u207b x, g n x \u2202\u03bc :\n by rw lintegral_tsum (\u03bb n, (gcont n).measurable.coe_nnreal_ennreal)\n ... \u2264 \u2211' n, (\u222b\u207b x, eapprox_diff f n x \u2202\u03bc + \u03b4 n) : ennreal.tsum_le_tsum hg\n ... = \u2211' n, (\u222b\u207b x, eapprox_diff f n x \u2202\u03bc) + \u2211' n, \u03b4 n : ennreal.tsum_add\n ... \u2264 \u222b\u207b (x : \u03b1), f x \u2202\u03bc + \u03b5 :\n begin\n refine add_le_add _ h\u03b4.le,\n rw [\u2190 lintegral_tsum],\n { simp_rw [tsum_eapprox_diff f hf, le_refl] },\n { assume n, exact (simple_func.measurable _).coe_nnreal_ennreal }\n end }\nend\n\n\/-- Given a measurable function `f` with values in `\u211d\u22650` in a sigma-finite space, there exists a\nlower semicontinuous function `g > f` with integral arbitrarily close to that of `f`.\nFormulation in terms of `lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_lt_lower_semicontinuous_lintegral_ge [sigma_finite \u03bc]\n (f : \u03b1 \u2192 \u211d\u22650) (fmeas : measurable f) {\u03b5 : \u211d\u22650} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650\u221e, (\u2200 x, (f x : \u211d\u22650\u221e) < g x) \u2227 lower_semicontinuous g \u2227\n (\u222b\u207b x, g x \u2202\u03bc \u2264 \u222b\u207b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n rcases exists_integrable_pos_of_sigma_finite \u03bc (nnreal.half_pos \u03b5pos) with \u27e8w, wpos, wmeas, wint\u27e9,\n let f' := \u03bb x, ((f x + w x : \u211d\u22650) : \u211d\u22650\u221e),\n rcases exists_le_lower_semicontinuous_lintegral_ge \u03bc f' (fmeas.add wmeas).coe_nnreal_ennreal\n (ennreal.coe_pos.2 (nnreal.half_pos \u03b5pos)) with \u27e8g, le_g, gcont, gint\u27e9,\n refine \u27e8g, \u03bb x, _, gcont, _\u27e9,\n { calc (f x : \u211d\u22650\u221e) < f' x : by simpa [\u2190 ennreal.coe_lt_coe] using add_lt_add_left (wpos x) (f x)\n ... \u2264 g x : le_g x },\n { calc \u222b\u207b (x : \u03b1), g x \u2202\u03bc\n \u2264 \u222b\u207b (x : \u03b1), f x + w x \u2202\u03bc + (\u03b5 \/ 2 : \u211d\u22650) : gint\n ... = \u222b\u207b (x : \u03b1), f x \u2202 \u03bc + \u222b\u207b (x : \u03b1), w x \u2202 \u03bc + (\u03b5 \/ 2 : \u211d\u22650) :\n by rw lintegral_add fmeas.coe_nnreal_ennreal wmeas.coe_nnreal_ennreal\n ... \u2264 \u222b\u207b (x : \u03b1), f x \u2202 \u03bc + (\u03b5 \/ 2 : \u211d\u22650) + (\u03b5 \/ 2 : \u211d\u22650) :\n add_le_add_right (add_le_add_left wint.le _) _\n ... = \u222b\u207b (x : \u03b1), f x \u2202\u03bc + \u03b5 : by rw [add_assoc, \u2190 ennreal.coe_add, nnreal.add_halves] },\nend\n\n\/-- Given an almost everywhere measurable function `f` with values in `\u211d\u22650` in a sigma-finite space,\nthere exists a lower semicontinuous function `g > f` with integral arbitrarily close to that of `f`.\nFormulation in terms of `lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_lt_lower_semicontinuous_lintegral_ge_of_ae_measurable [sigma_finite \u03bc]\n (f : \u03b1 \u2192 \u211d\u22650) (fmeas : ae_measurable f \u03bc) {\u03b5 : \u211d\u22650} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650\u221e, (\u2200 x, (f x : \u211d\u22650\u221e) < g x) \u2227 lower_semicontinuous g \u2227\n (\u222b\u207b x, g x \u2202\u03bc \u2264 \u222b\u207b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n rcases exists_lt_lower_semicontinuous_lintegral_ge \u03bc (fmeas.mk f) fmeas.measurable_mk\n (nnreal.half_pos \u03b5pos) with \u27e8g0, f_lt_g0, g0_cont, g0_int\u27e9,\n rcases exists_measurable_superset_of_null fmeas.ae_eq_mk with \u27e8s, hs, smeas, \u03bcs\u27e9,\n rcases exists_le_lower_semicontinuous_lintegral_ge \u03bc (s.indicator (\u03bb x, \u221e))\n (measurable_const.indicator smeas) (ennreal.half_pos (ennreal.coe_pos.2 \u03b5pos)) with\n \u27e8g1, le_g1, g1_cont, g1_int\u27e9,\n refine \u27e8\u03bb x, g0 x + g1 x, \u03bb x, _, g0_cont.add g1_cont, _\u27e9,\n { by_cases h : x \u2208 s,\n { have := le_g1 x,\n simp only [h, set.indicator_of_mem, top_le_iff] at this,\n simp [this] },\n { have : f x = fmeas.mk f x,\n by { rw set.compl_subset_comm at hs, exact hs h },\n rw this,\n exact (f_lt_g0 x).trans_le le_self_add } },\n { calc \u222b\u207b x, g0 x + g1 x \u2202\u03bc = \u222b\u207b x, g0 x \u2202\u03bc + \u222b\u207b x, g1 x \u2202\u03bc :\n lintegral_add g0_cont.measurable g1_cont.measurable\n ... \u2264 (\u222b\u207b x, f x \u2202\u03bc + \u03b5 \/ 2) + (0 + \u03b5 \/ 2) :\n begin\n refine add_le_add _ _,\n { convert g0_int using 2,\n { exact lintegral_congr_ae (fmeas.ae_eq_mk.fun_comp _) },\n { simp only [ennreal.coe_div, ennreal.coe_one, ennreal.coe_bit0, ne.def, not_false_iff,\n bit0_eq_zero, one_ne_zero], } },\n { convert g1_int,\n simp only [smeas, \u03bcs, lintegral_const, set.univ_inter, measurable_set.univ,\n lintegral_indicator, mul_zero, restrict_apply] }\n end\n ... = \u222b\u207b x, f x \u2202\u03bc + \u03b5 : by simp only [add_assoc, ennreal.add_halves, zero_add] }\nend\n\nvariable {\u03bc}\n\n\/-- Given an integrable function `f` with values in `\u211d\u22650` in a sigma-finite space, there exists a\nlower semicontinuous function `g > f` with integral arbitrarily close to that of `f`.\nFormulation in terms of `integral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_lt_lower_semicontinuous_integral_gt_nnreal [sigma_finite \u03bc] (f : \u03b1 \u2192 \u211d\u22650)\n (fint : integrable (\u03bb x, (f x : \u211d)) \u03bc) {\u03b5 : \u211d} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650\u221e, (\u2200 x, (f x : \u211d\u22650\u221e) < g x) \u2227 lower_semicontinuous g \u2227 (\u2200\u1d50 x \u2202 \u03bc, g x < \u22a4)\n \u2227 (integrable (\u03bb x, (g x).to_real) \u03bc) \u2227 (\u222b x, (g x).to_real \u2202\u03bc < \u222b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n have fmeas : ae_measurable f \u03bc,\n by { convert fint.ae_measurable.real_to_nnreal, ext1 x, simp only [real.to_nnreal_coe] },\n let \u03b4 : \u211d\u22650 := \u27e8\u03b5\/2, (half_pos \u03b5pos).le\u27e9,\n have \u03b4pos : 0 < \u03b4 := half_pos \u03b5pos,\n have int_f_lt_top : \u222b\u207b (a : \u03b1), (f a) \u2202\u03bc < \u221e :=\n has_finite_integral_iff_of_nnreal.1 fint.has_finite_integral,\n rcases exists_lt_lower_semicontinuous_lintegral_ge_of_ae_measurable \u03bc f fmeas \u03b4pos\n with \u27e8g, f_lt_g, gcont, gint\u27e9,\n have gint_lt : \u222b\u207b (x : \u03b1), g x \u2202\u03bc < \u221e := gint.trans_lt (by simpa using int_f_lt_top),\n have g_lt_top : \u2200\u1d50 (x : \u03b1) \u2202\u03bc, g x < \u221e := ae_lt_top gcont.measurable gint_lt,\n have Ig : \u222b\u207b (a : \u03b1), ennreal.of_real (g a).to_real \u2202\u03bc = \u222b\u207b (a : \u03b1), g a \u2202\u03bc,\n { apply lintegral_congr_ae,\n filter_upwards [g_lt_top],\n assume x hx,\n simp only [hx.ne, ennreal.of_real_to_real, ne.def, not_false_iff] },\n refine \u27e8g, f_lt_g, gcont, g_lt_top, _, _\u27e9,\n { refine \u27e8gcont.measurable.ennreal_to_real.ae_measurable, _\u27e9,\n simp [has_finite_integral_iff_norm, real.norm_eq_abs, abs_of_nonneg],\n convert gint_lt using 1 },\n { rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae],\n { calc\n ennreal.to_real (\u222b\u207b (a : \u03b1), ennreal.of_real (g a).to_real \u2202\u03bc)\n = ennreal.to_real (\u222b\u207b (a : \u03b1), g a \u2202\u03bc) : by congr' 1\n ... \u2264 ennreal.to_real (\u222b\u207b (a : \u03b1), f a \u2202\u03bc + \u03b4) :\n begin\n apply ennreal.to_real_mono _ gint,\n simpa using int_f_lt_top.ne,\n end\n ... = ennreal.to_real (\u222b\u207b (a : \u03b1), f a \u2202\u03bc) + \u03b4 :\n by rw [ennreal.to_real_add int_f_lt_top.ne ennreal.coe_ne_top, ennreal.coe_to_real]\n ... < ennreal.to_real (\u222b\u207b (a : \u03b1), f a \u2202\u03bc) + \u03b5 :\n add_lt_add_left (by simp [\u03b4, half_lt_self \u03b5pos]) _\n ... = (\u222b\u207b (a : \u03b1), ennreal.of_real \u2191(f a) \u2202\u03bc).to_real + \u03b5 :\n by simp },\n { apply filter.eventually_of_forall (\u03bb x, _), simp },\n { exact fmeas.coe_nnreal_real, },\n { apply filter.eventually_of_forall (\u03bb x, _), simp },\n { apply gcont.measurable.ennreal_to_real.ae_measurable } }\nend\n\n\n\/-! ### Upper semicontinuous lower bound for nonnegative functions -\/\n\n\/-- Given a simple function `f` with values in `\u211d\u22650`, there exists an upper semicontinuous\nfunction `g \u2264 f` with integral arbitrarily close to that of `f`. Formulation in terms of\n`lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma simple_func.exists_upper_semicontinuous_le_lintegral_le :\n \u2200 (f : \u03b1 \u2192\u209b \u211d\u22650) (int_f : \u222b\u207b x, f x \u2202\u03bc < \u221e) {\u03b5 : \u211d\u22650\u221e} (\u03b5pos : 0 < \u03b5),\n \u2203 g : \u03b1 \u2192 \u211d\u22650, (\u2200 x, g x \u2264 f x) \u2227 upper_semicontinuous g \u2227 (\u222b\u207b x, f x \u2202\u03bc \u2264 \u222b\u207b x, g x \u2202\u03bc + \u03b5) :=\nbegin\n refine simple_func.induction _ _,\n { assume c s hs int_f \u03b5 \u03b5pos,\n let f := simple_func.piecewise s hs (simple_func.const \u03b1 c) (simple_func.const \u03b1 0),\n by_cases hc : c = 0,\n { refine \u27e8\u03bb x, 0, _, upper_semicontinuous_const, _\u27e9,\n { simp only [hc, set.indicator_zero', pi.zero_apply, simple_func.const_zero, implies_true_iff,\n eq_self_iff_true, simple_func.coe_zero, set.piecewise_eq_indicator,\n simple_func.coe_piecewise, le_zero_iff] },\n { simp only [hc, set.indicator_zero', lintegral_const, zero_mul, pi.zero_apply,\n simple_func.const_zero, zero_add, zero_le', simple_func.coe_zero,\n set.piecewise_eq_indicator, ennreal.coe_zero, simple_func.coe_piecewise, \u03b5pos.le] } },\n have \u03bcs_lt_top : \u03bc s < \u221e,\n by simpa only [hs, hc, lt_top_iff_ne_top, true_and, simple_func.coe_const, or_false,\n lintegral_const, ennreal.coe_indicator, set.univ_inter, ennreal.coe_ne_top, restrict_apply\n measurable_set.univ, with_top.mul_eq_top_iff, simple_func.const_zero, function.const_apply,\n lintegral_indicator, ennreal.coe_eq_zero, ne.def, not_false_iff, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise, false_and] using int_f,\n have : (0 : \u211d\u22650\u221e) < \u03b5 \/ c := ennreal.div_pos_iff.2 \u27e8\u03b5pos.ne', ennreal.coe_ne_top\u27e9,\n obtain \u27e8F, F_closed, Fs, \u03bcF\u27e9 : \u2203 F, is_closed F \u2227 F \u2286 s \u2227 \u03bc s < \u03bc F + \u03b5 \/ c :=\n hs.exists_lt_is_closed_of_lt_top_of_pos \u03bcs_lt_top this,\n refine \u27e8set.indicator F (\u03bb x, c), \u03bb x, _,\n F_closed.upper_semicontinuous_indicator (zero_le _), _\u27e9,\n { simp only [simple_func.coe_const, simple_func.const_zero, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise],\n exact set.indicator_le_indicator_of_subset Fs (\u03bb x, zero_le _) _ },\n { suffices : (c : \u211d\u22650\u221e) * \u03bc s \u2264 c * \u03bc F + \u03b5,\n by simpa only [hs, F_closed.measurable_set, simple_func.coe_const, function.const_apply,\n lintegral_const, ennreal.coe_indicator, set.univ_inter, measurable_set.univ,\n simple_func.const_zero, lintegral_indicator, simple_func.coe_zero,\n set.piecewise_eq_indicator, simple_func.coe_piecewise, restrict_apply],\n calc (c : \u211d\u22650\u221e) * \u03bc s \u2264 c * (\u03bc F + \u03b5 \/ c) : ennreal.mul_le_mul (le_refl _) \u03bcF.le\n ... = c * \u03bc F + \u03b5 :\n begin\n simp_rw [mul_add],\n rw ennreal.mul_div_cancel' _ ennreal.coe_ne_top,\n simpa using hc,\n end } },\n { assume f\u2081 f\u2082 H h\u2081 h\u2082 f_int \u03b5 \u03b5pos,\n have A : \u222b\u207b (x : \u03b1), f\u2081 x \u2202\u03bc + \u222b\u207b (x : \u03b1), f\u2082 x \u2202\u03bc < \u22a4,\n { rw \u2190 lintegral_add f\u2081.measurable.coe_nnreal_ennreal f\u2082.measurable.coe_nnreal_ennreal,\n simpa only [simple_func.coe_add, ennreal.coe_add, pi.add_apply] using f_int },\n rcases h\u2081 (ennreal.add_lt_top.1 A).1 (ennreal.half_pos \u03b5pos) with \u27e8g\u2081, f\u2081_le_g\u2081, g\u2081cont, g\u2081int\u27e9,\n rcases h\u2082 (ennreal.add_lt_top.1 A).2 (ennreal.half_pos \u03b5pos) with \u27e8g\u2082, f\u2082_le_g\u2082, g\u2082cont, g\u2082int\u27e9,\n refine \u27e8\u03bb x, g\u2081 x + g\u2082 x, \u03bb x, add_le_add (f\u2081_le_g\u2081 x) (f\u2082_le_g\u2082 x), g\u2081cont.add g\u2082cont, _\u27e9,\n simp only [simple_func.coe_add, ennreal.coe_add, pi.add_apply],\n rw [lintegral_add f\u2081.measurable.coe_nnreal_ennreal f\u2082.measurable.coe_nnreal_ennreal,\n lintegral_add g\u2081cont.measurable.coe_nnreal_ennreal g\u2082cont.measurable.coe_nnreal_ennreal],\n convert add_le_add g\u2081int g\u2082int using 1,\n conv_lhs { rw \u2190 ennreal.add_halves \u03b5 },\n abel }\nend\n\n\/-- Given an integrable function `f` with values in `\u211d\u22650`, there exists an upper semicontinuous\nfunction `g \u2264 f` with integral arbitrarily close to that of `f`. Formulation in terms of\n`lintegral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_upper_semicontinuous_le_lintegral_le\n (f : \u03b1 \u2192 \u211d\u22650) (int_f : \u222b\u207b x, f x \u2202\u03bc < \u221e) {\u03b5 : \u211d\u22650\u221e} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650, (\u2200 x, g x \u2264 f x) \u2227 upper_semicontinuous g \u2227 (\u222b\u207b x, f x \u2202\u03bc \u2264 \u222b\u207b x, g x \u2202\u03bc + \u03b5) :=\nbegin\n obtain \u27e8fs, fs_le_f, int_fs\u27e9 : \u2203 (fs : \u03b1 \u2192\u209b \u211d\u22650), (\u2200 x, fs x \u2264 f x) \u2227\n (\u222b\u207b x, f x \u2202\u03bc \u2264 \u222b\u207b x, fs x \u2202\u03bc + \u03b5\/2) :=\n begin\n have := ennreal.lt_add_right int_f (ennreal.half_pos \u03b5pos),\n conv_rhs at this { rw lintegral_eq_nnreal (\u03bb x, (f x : \u211d\u22650\u221e)) \u03bc },\n erw ennreal.bsupr_add at this; [skip, exact \u27e80, \u03bb x, by simp\u27e9],\n simp only [lt_supr_iff] at this,\n rcases this with \u27e8fs, fs_le_f, int_fs\u27e9,\n refine \u27e8fs, \u03bb x, by simpa only [ennreal.coe_le_coe] using fs_le_f x, _\u27e9,\n convert int_fs.le,\n rw \u2190 simple_func.lintegral_eq_lintegral,\n refl\n end,\n have int_fs_lt_top : \u222b\u207b x, fs x \u2202\u03bc < \u221e,\n { apply lt_of_le_of_lt (lintegral_mono (\u03bb x, _)) int_f,\n simpa only [ennreal.coe_le_coe] using fs_le_f x },\n obtain \u27e8g, g_le_fs, gcont, gint\u27e9 : \u2203 g : \u03b1 \u2192 \u211d\u22650,\n (\u2200 x, g x \u2264 fs x) \u2227 upper_semicontinuous g \u2227 (\u222b\u207b x, fs x \u2202\u03bc \u2264 \u222b\u207b x, g x \u2202\u03bc + \u03b5\/2) :=\n fs.exists_upper_semicontinuous_le_lintegral_le int_fs_lt_top (ennreal.half_pos \u03b5pos),\n refine \u27e8g, \u03bb x, (g_le_fs x).trans (fs_le_f x), gcont, _\u27e9,\n calc \u222b\u207b x, f x \u2202\u03bc \u2264 \u222b\u207b x, fs x \u2202\u03bc + \u03b5 \/ 2 : int_fs\n ... \u2264 (\u222b\u207b x, g x \u2202\u03bc + \u03b5 \/ 2) + \u03b5 \/ 2 : add_le_add gint (le_refl _)\n ... = \u222b\u207b x, g x \u2202\u03bc + \u03b5 : by rw [add_assoc, ennreal.add_halves]\nend\n\n\/-- Given an integrable function `f` with values in `\u211d\u22650`, there exists an upper semicontinuous\nfunction `g \u2264 f` with integral arbitrarily close to that of `f`. Formulation in terms of\n`integral`.\nAuxiliary lemma for Vitali-Carath\u00e9odory theorem `exists_lt_lower_semicontinuous_integral_lt`. -\/\nlemma exists_upper_semicontinuous_le_integral_le (f : \u03b1 \u2192 \u211d\u22650)\n (fint : integrable (\u03bb x, (f x : \u211d)) \u03bc) {\u03b5 : \u211d} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 \u211d\u22650, (\u2200 x, g x \u2264 f x) \u2227 upper_semicontinuous g \u2227 (integrable (\u03bb x, (g x : \u211d)) \u03bc)\n \u2227 (\u222b x, (f x : \u211d) \u2202\u03bc - \u03b5 \u2264 \u222b x, g x \u2202\u03bc) :=\nbegin\n let \u03b4 : \u211d\u22650 := \u27e8\u03b5, \u03b5pos.le\u27e9,\n have \u03b4pos : (0 : \u211d\u22650\u221e) < \u03b4 := ennreal.coe_lt_coe.2 \u03b5pos,\n have If : \u222b\u207b x, f x \u2202 \u03bc < \u221e := has_finite_integral_iff_of_nnreal.1 fint.has_finite_integral,\n rcases exists_upper_semicontinuous_le_lintegral_le f If \u03b4pos with \u27e8g, gf, gcont, gint\u27e9,\n have Ig : \u222b\u207b x, g x \u2202 \u03bc < \u221e,\n { apply lt_of_le_of_lt (lintegral_mono (\u03bb x, _)) If,\n simpa using gf x },\n refine \u27e8g, gf, gcont, _, _\u27e9,\n { refine integrable.mono fint gcont.measurable.coe_nnreal_real.ae_measurable _,\n exact filter.eventually_of_forall (\u03bb x, by simp [gf x]) },\n { rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae],\n { rw sub_le_iff_le_add,\n convert ennreal.to_real_mono _ gint,\n { simp, },\n { rw ennreal.to_real_add Ig.ne ennreal.coe_ne_top, simp },\n { simpa using Ig.ne } },\n { apply filter.eventually_of_forall, simp },\n { exact gcont.measurable.coe_nnreal_real.ae_measurable },\n { apply filter.eventually_of_forall, simp },\n { exact fint.ae_measurable } }\nend\n\n\/-! ### Vitali-Carath\u00e9odory theorem -\/\n\n\/-- **Vitali-Carath\u00e9odory Theorem**: given an integrable real function `f`, there exists an\nintegrable function `g > f` which is lower semicontinuous, with integral arbitrarily close\nto that of `f`. This function has to be `ereal`-valued in general. -\/\nlemma exists_lt_lower_semicontinuous_integral_lt [sigma_finite \u03bc]\n (f : \u03b1 \u2192 \u211d) (hf : integrable f \u03bc) {\u03b5 : \u211d} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 ereal, (\u2200 x, (f x : ereal) < g x) \u2227 lower_semicontinuous g \u2227\n (integrable (\u03bb x, ereal.to_real (g x)) \u03bc) \u2227 (\u2200\u1d50 x \u2202 \u03bc, g x < \u22a4) \u2227\n (\u222b x, ereal.to_real (g x) \u2202\u03bc < \u222b x, f x \u2202\u03bc + \u03b5) :=\nbegin\n let \u03b4 : \u211d\u22650 := \u27e8\u03b5\/2, (half_pos \u03b5pos).le\u27e9,\n have \u03b4pos : 0 < \u03b4 := half_pos \u03b5pos,\n let fp : \u03b1 \u2192 \u211d\u22650 := \u03bb x, real.to_nnreal (f x),\n have int_fp : integrable (\u03bb x, (fp x : \u211d)) \u03bc := hf.real_to_nnreal,\n rcases exists_lt_lower_semicontinuous_integral_gt_nnreal fp int_fp \u03b4pos\n with \u27e8gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint\u27e9,\n let fm : \u03b1 \u2192 \u211d\u22650 := \u03bb x, real.to_nnreal (-f x),\n have int_fm : integrable (\u03bb x, (fm x : \u211d)) \u03bc := hf.neg.real_to_nnreal,\n rcases exists_upper_semicontinuous_le_integral_le fm int_fm \u03b4pos\n with \u27e8gm, gm_le_fm, gmcont, gm_integrable, gmint\u27e9,\n let g : \u03b1 \u2192 ereal := \u03bb x, (gp x : ereal) - (gm x),\n have ae_g : \u2200\u1d50 x \u2202 \u03bc, (g x).to_real = (gp x : ereal).to_real - (gm x : ereal).to_real,\n { filter_upwards [gp_lt_top],\n assume x hx,\n rw ereal.to_real_sub;\n simp [hx.ne] },\n refine \u27e8g, _, _, _, _, _\u27e9,\n show integrable (\u03bb x, ereal.to_real (g x)) \u03bc,\n { rw integrable_congr ae_g,\n convert gp_integrable.sub gm_integrable,\n ext x,\n simp },\n show \u222b (x : \u03b1), (g x).to_real \u2202\u03bc < \u222b (x : \u03b1), f x \u2202\u03bc + \u03b5, from calc\n \u222b (x : \u03b1), (g x).to_real \u2202\u03bc = \u222b (x : \u03b1), ereal.to_real (gp x) - ereal.to_real (gm x) \u2202\u03bc :\n integral_congr_ae ae_g\n ... = \u222b (x : \u03b1), ereal.to_real (gp x) \u2202 \u03bc - \u222b (x : \u03b1), gm x \u2202\u03bc :\n begin\n simp only [ereal.to_real_coe_ennreal, ennreal.coe_to_real, coe_coe],\n exact integral_sub gp_integrable gm_integrable,\n end\n ... < \u222b (x : \u03b1), \u2191(fp x) \u2202\u03bc + \u2191\u03b4 - \u222b (x : \u03b1), gm x \u2202\u03bc :\n begin\n apply sub_lt_sub_right,\n convert gpint,\n simp only [ereal.to_real_coe_ennreal],\n end\n ... \u2264 \u222b (x : \u03b1), \u2191(fp x) \u2202\u03bc + \u2191\u03b4 - (\u222b (x : \u03b1), fm x \u2202\u03bc - \u03b4) :\n sub_le_sub_left gmint _\n ... = \u222b (x : \u03b1), f x \u2202\u03bc + 2 * \u03b4 :\n by { simp_rw [integral_eq_integral_pos_part_sub_integral_neg_part hf, fp, fm], ring }\n ... = \u222b (x : \u03b1), f x \u2202\u03bc + \u03b5 :\n by { congr' 1, field_simp [\u03b4, mul_comm] },\n show \u2200\u1d50 (x : \u03b1) \u2202\u03bc, g x < \u22a4,\n { filter_upwards [gp_lt_top],\n assume x hx,\n simp [g, ereal.sub_eq_add_neg, lt_top_iff_ne_top, lt_top_iff_ne_top.1 hx] },\n show \u2200 x, (f x : ereal) < g x,\n { assume x,\n rw ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal (f x),\n refine ereal.sub_lt_sub_of_lt_of_le _ _ _ _,\n { simp only [ereal.coe_ennreal_lt_coe_ennreal_iff, coe_coe], exact (fp_lt_gp x) },\n { simp only [ennreal.coe_le_coe, ereal.coe_ennreal_le_coe_ennreal_iff, coe_coe],\n exact (gm_le_fm x) },\n { simp only [ereal.coe_ennreal_ne_bot, ne.def, not_false_iff, coe_coe] },\n { simp only [ereal.coe_nnreal_ne_top, ne.def, not_false_iff, coe_coe] } },\n show lower_semicontinuous g,\n { apply lower_semicontinuous.add',\n { exact continuous_coe_ennreal_ereal.comp_lower_semicontinuous gpcont\n (\u03bb x y hxy, ereal.coe_ennreal_le_coe_ennreal_iff.2 hxy) },\n { apply ereal.continuous_neg.comp_upper_semicontinuous_antimono _\n (\u03bb x y hxy, ereal.neg_le_neg_iff.2 hxy),\n dsimp,\n apply continuous_coe_ennreal_ereal.comp_upper_semicontinuous _\n (\u03bb x y hxy, ereal.coe_ennreal_le_coe_ennreal_iff.2 hxy),\n exact ennreal.continuous_coe.comp_upper_semicontinuous gmcont\n (\u03bb x y hxy, ennreal.coe_le_coe.2 hxy) },\n { assume x,\n exact ereal.continuous_at_add (by simp) (by simp) } }\nend\n\n\/-- **Vitali-Carath\u00e9odory Theorem**: given an integrable real function `f`, there exists an\nintegrable function `g < f` which is upper semicontinuous, with integral arbitrarily close to that\nof `f`. This function has to be `ereal`-valued in general. -\/\nlemma exists_upper_semicontinuous_lt_integral_gt [sigma_finite \u03bc]\n (f : \u03b1 \u2192 \u211d) (hf : integrable f \u03bc) {\u03b5 : \u211d} (\u03b5pos : 0 < \u03b5) :\n \u2203 g : \u03b1 \u2192 ereal, (\u2200 x, (g x : ereal) < f x) \u2227 upper_semicontinuous g \u2227\n (integrable (\u03bb x, ereal.to_real (g x)) \u03bc) \u2227 (\u2200\u1d50 x \u2202\u03bc, \u22a5 < g x) \u2227\n (\u222b x, f x \u2202\u03bc < \u222b x, ereal.to_real (g x) \u2202\u03bc + \u03b5) :=\nbegin\n rcases exists_lt_lower_semicontinuous_integral_lt (\u03bb x, - f x) hf.neg \u03b5pos\n with \u27e8g, g_lt_f, gcont, g_integrable, g_lt_top, gint\u27e9,\n refine \u27e8\u03bb x, - g x, _, _, _, _, _\u27e9,\n { exact \u03bb x, ereal.neg_lt_iff_neg_lt.1 (by simpa only [ereal.coe_neg] using g_lt_f x) },\n { exact ereal.continuous_neg.comp_lower_semicontinuous_antimono gcont\n (\u03bb x y hxy, ereal.neg_le_neg_iff.2 hxy) },\n { convert g_integrable.neg,\n ext x,\n simp },\n { simpa [bot_lt_iff_ne_bot, lt_top_iff_ne_top] using g_lt_top },\n { simp_rw [integral_neg, lt_neg_add_iff_add_lt] at gint,\n rw add_comm at gint,\n simpa [integral_neg] using gint }\nend\n\nend measure_theory\n","avg_line_length":52.6735459662,"max_line_length":100,"alphanum_fraction":0.6700979519} -{"size":17620,"ext":"lean","lang":"Lean","max_stars_count":332.0,"content":"\/-\nCopyright (c) 2014 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Leonardo de Moura\n\nnotation, basic datatypes and type classes\n-\/\nprelude\n\nnotation `Prop` := Sort 0\nnotation f ` $ `:1 a:0 := f a\n\nuniverses u v w\n\n\/--\nThe kernel definitional equality test (t =?= s) has special support for id_delta applications.\nIt implements the following rules\n\n 1) (id_delta t) =?= t\n 2) t =?= (id_delta t)\n 3) (id_delta t) =?= s IF (unfold_of t) =?= s\n 4) t =?= id_delta s IF t =?= (unfold_of s)\n\nThis is mechanism for controlling the delta reduction (aka unfolding) used in the kernel.\n\nWe use id_delta applications to address performance problems when type checking\nlemmas generated by the equation compiler.\n-\/\n@[inline] def id_delta {\u03b1 : Sort u} (a : \u03b1) : \u03b1 :=\na\n\n\/-- Gadget for optional parameter support. -\/\n@[reducible] def opt_param (\u03b1 : Sort u) (default : \u03b1) : Sort u :=\n\u03b1\n\n\/-- Gadget for marking output parameters in type classes. -\/\n@[reducible] def out_param (\u03b1 : Sort u) : Sort u := \u03b1\n\n\/-\n id_rhs is an auxiliary declaration used in the equation compiler to address performance\n issues when proving equational lemmas. The equation compiler uses it as a marker.\n-\/\nabbreviation id_rhs (\u03b1 : Sort u) (a : \u03b1) : \u03b1 := a\n\ninductive punit : Sort u\n| star : punit\n\n\/-- An abbreviation for `punit.{0}`, its most common instantiation.\n This type should be preferred over `punit` where possible to avoid\n unnecessary universe parameters. -\/\nabbreviation unit : Type := punit\n\n@[pattern] abbreviation unit.star : unit := punit.star\n\n\/--\nGadget for defining thunks, thunk parameters have special treatment.\nExample: given\n def f (s : string) (t : thunk nat) : nat\nan application\n f \"hello\" 10\n is converted into\n f \"hello\" (\u03bb _, 10)\n-\/\n@[reducible] def thunk (\u03b1 : Type u) : Type u :=\nunit \u2192 \u03b1\n\ninductive true : Prop\n| intro : true\n\ninductive false : Prop\n\ninductive empty : Type\n\n\/--\nLogical not.\n\n`not P`, with notation `\u00ac P`, is the `Prop` which is true if and only if `P` is false. It is\ninternally represented as `P \u2192 false`, so one way to prove a goal `\u22a2 \u00ac P` is to use `intro h`,\nwhich gives you a new hypothesis `h : P` and the goal `\u22a2 false`.\n\nA hypothesis `h : \u00ac P` can be used in term mode as a function, so if `w : P` then `h w : false`.\n\nRelated mathlib tactic: `contrapose`.\n-\/\ndef not (a : Prop) := a \u2192 false\nprefix `\u00ac`:40 := not\n\ninductive eq {\u03b1 : Sort u} (a : \u03b1) : \u03b1 \u2192 Prop\n| refl [] : eq a\n\n\/-\nInitialize the quotient module, which effectively adds the following definitions:\n\nconstant quot {\u03b1 : Sort u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) : Sort u\n\nconstant quot.mk {\u03b1 : Sort u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) (a : \u03b1) : quot r\n\nconstant quot.lift {\u03b1 : Sort u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b2 : Sort v} (f : \u03b1 \u2192 \u03b2) :\n (\u2200 a b : \u03b1, r a b \u2192 eq (f a) (f b)) \u2192 quot r \u2192 \u03b2\n\nconstant quot.ind {\u03b1 : Sort u} {r : \u03b1 \u2192 \u03b1 \u2192 Prop} {\u03b2 : quot r \u2192 Prop} :\n (\u2200 a : \u03b1, \u03b2 (quot.mk r a)) \u2192 \u2200 q : quot r, \u03b2 q\n\nAlso the reduction rule:\n\nquot.lift f _ (quot.mk a) ~~> f a\n\n-\/\ninit_quotient\n\n\/--\nHeterogeneous equality.\n\nIts purpose is to write down equalities between terms whose types are not definitionally equal.\nFor example, given `x : vector \u03b1 n` and `y : vector \u03b1 (0+n)`, `x = y` doesn't typecheck but `x == y` does.\n\nIf you have a goal `\u22a2 x == y`,\nyour first instinct should be to ask (either yourself, or on [zulip](https:\/\/leanprover.zulipchat.com\/))\nif something has gone wrong already.\nIf you really do need to follow this route,\nyou may find the lemmas `eq_rec_heq` and `eq_mpr_heq` useful.\n-\/\ninductive heq {\u03b1 : Sort u} (a : \u03b1) : \u03a0 {\u03b2 : Sort u}, \u03b2 \u2192 Prop\n| refl [] : heq a\n\nstructure prod (\u03b1 : Type u) (\u03b2 : Type v) :=\n(fst : \u03b1) (snd : \u03b2)\n\n\/-- Similar to `prod`, but \u03b1 and \u03b2 can be propositions.\n We use this type internally to automatically generate the brec_on recursor. -\/\nstructure pprod (\u03b1 : Sort u) (\u03b2 : Sort v) :=\n(fst : \u03b1) (snd : \u03b2)\n\n\/--\nLogical and.\n\n`and P Q`, with notation `P \u2227 Q`, is the `Prop` which is true precisely when `P` and `Q` are\nboth true.\n\nTo prove a goal `\u22a2 P \u2227 Q`, you can use the tactic `split`,\nwhich gives two separate goals `\u22a2 P` and `\u22a2 Q`.\n\nGiven a hypothesis `h : P \u2227 Q`, you can use the tactic `cases h with hP hQ`\nto obtain two new hypotheses `hP : P` and `hQ : Q`. See also the `obtain` or `rcases` tactics in\nmathlib.\n-\/\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\nlemma and.elim_left {a b : Prop} (h : and a b) : a := h.1\n\nlemma and.elim_right {a b : Prop} (h : and a b) : b := h.2\n\n\/- eq basic support -\/\n\ninfix ` = `:50 := eq\n\nattribute [refl] eq.refl\n\n\/- This is a `def`, so that it can be used as pattern in the equation compiler. -\/\n@[pattern] def rfl {\u03b1 : Sort u} {a : \u03b1} : a = a := eq.refl a\n\n@[elab_as_eliminator, subst]\nlemma eq.subst {\u03b1 : Sort u} {P : \u03b1 \u2192 Prop} {a b : \u03b1} (h\u2081 : a = b) (h\u2082 : P a) : P b :=\neq.rec h\u2082 h\u2081\n\ninfixr ` \u25b8 `:75 := eq.subst\n\n@[trans] lemma eq.trans {\u03b1 : Sort u} {a b c : \u03b1} (h\u2081 : a = b) (h\u2082 : b = c) : a = c :=\nh\u2082 \u25b8 h\u2081\n\n@[symm] lemma eq.symm {\u03b1 : Sort u} {a b : \u03b1} (h : a = b) : b = a :=\nh \u25b8 rfl\n\ninfix ` == `:50 := heq\n\n\/- This is a `def`, so that it can be used as pattern in the equation compiler. -\/\n@[pattern] def heq.rfl {\u03b1 : Sort u} {a : \u03b1} : a == a := heq.refl a\n\nlemma eq_of_heq {\u03b1 : Sort u} {a a' : \u03b1} (h : a == a') : a = a' :=\nhave \u2200 (\u03b1' : Sort u) (a' : \u03b1') (h\u2081 : @heq \u03b1 a \u03b1' a') (h\u2082 : \u03b1 = \u03b1'), (eq.rec_on h\u2082 a : \u03b1') = a', from\n \u03bb (\u03b1' : Sort u) (a' : \u03b1') (h\u2081 : @heq \u03b1 a \u03b1' a'), heq.rec_on h\u2081 (\u03bb h\u2082 : \u03b1 = \u03b1, rfl),\nshow (eq.rec_on (eq.refl \u03b1) a : \u03b1) = a', from\n this \u03b1 a' h (eq.refl \u03b1)\n\n\/- The following four lemmas could not be automatically generated when the\n structures were declared, so we prove them manually here. -\/\nlemma prod.mk.inj {\u03b1 : Type u} {\u03b2 : Type v} {x\u2081 : \u03b1} {y\u2081 : \u03b2} {x\u2082 : \u03b1} {y\u2082 : \u03b2}\n : (x\u2081, y\u2081) = (x\u2082, y\u2082) \u2192 and (x\u2081 = x\u2082) (y\u2081 = y\u2082) :=\n\u03bb h, prod.no_confusion h (\u03bb h\u2081 h\u2082, \u27e8h\u2081, h\u2082\u27e9)\n\nlemma prod.mk.inj_arrow {\u03b1 : Type u} {\u03b2 : Type v} {x\u2081 : \u03b1} {y\u2081 : \u03b2} {x\u2082 : \u03b1} {y\u2082 : \u03b2}\n : (x\u2081, y\u2081) = (x\u2082, y\u2082) \u2192 \u03a0 \u2983P : Sort w\u2984, (x\u2081 = x\u2082 \u2192 y\u2081 = y\u2082 \u2192 P) \u2192 P :=\n\u03bb h\u2081 _ h\u2082, prod.no_confusion h\u2081 h\u2082\n\nlemma pprod.mk.inj {\u03b1 : Sort u} {\u03b2 : Sort v} {x\u2081 : \u03b1} {y\u2081 : \u03b2} {x\u2082 : \u03b1} {y\u2082 : \u03b2}\n : pprod.mk x\u2081 y\u2081 = pprod.mk x\u2082 y\u2082 \u2192 and (x\u2081 = x\u2082) (y\u2081 = y\u2082) :=\n\u03bb h, pprod.no_confusion h (\u03bb h\u2081 h\u2082, \u27e8h\u2081, h\u2082\u27e9)\n\nlemma pprod.mk.inj_arrow {\u03b1 : Type u} {\u03b2 : Type v} {x\u2081 : \u03b1} {y\u2081 : \u03b2} {x\u2082 : \u03b1} {y\u2082 : \u03b2}\n : (x\u2081, y\u2081) = (x\u2082, y\u2082) \u2192 \u03a0 \u2983P : Sort w\u2984, (x\u2081 = x\u2082 \u2192 y\u2081 = y\u2082 \u2192 P) \u2192 P :=\n\u03bb h\u2081 _ h\u2082, prod.no_confusion h\u2081 h\u2082\n\ninductive sum (\u03b1 : Type u) (\u03b2 : Type v)\n| inl (val : \u03b1) : sum\n| inr (val : \u03b2) : sum\n\ninductive psum (\u03b1 : Sort u) (\u03b2 : Sort v)\n| inl (val : \u03b1) : psum\n| inr (val : \u03b2) : psum\n\n\/--\nLogical or.\n\n`or P Q`, with notation `P \u2228 Q`, is the proposition which is true if and only if `P` or `Q` is\ntrue.\n\nTo prove a goal `\u22a2 P \u2228 Q`, if you know which alternative you want to prove,\nyou can use the tactics `left` (which gives the goal `\u22a2 P`)\nor `right` (which gives the goal `\u22a2 Q`).\n\nGiven a hypothesis `h : P \u2228 Q` and goal `\u22a2 R`,\nthe tactic `cases h` will give you two copies of the goal `\u22a2 R`,\nwith the hypothesis `h : P` in the first, and the hypothesis `h : Q` in the second.\n-\/\ninductive or (a b : Prop) : Prop\n| inl (h : a) : or\n| inr (h : b) : or\n\nlemma or.intro_left {a : Prop} (b : Prop) (ha : a) : or a b :=\nor.inl ha\n\nlemma or.intro_right (a : Prop) {b : Prop} (hb : b) : or a b :=\nor.inr hb\n\nstructure sigma {\u03b1 : Type u} (\u03b2 : \u03b1 \u2192 Type v) :=\nmk :: (fst : \u03b1) (snd : \u03b2 fst)\n\nstructure psigma {\u03b1 : Sort u} (\u03b2 : \u03b1 \u2192 Sort v) :=\nmk :: (fst : \u03b1) (snd : \u03b2 fst)\n\ninductive bool : Type\n| ff : bool\n| tt : bool\n\n\/- Remark: subtype must take a Sort instead of Type because of the axiom strong_indefinite_description. -\/\nstructure subtype {\u03b1 : Sort u} (p : \u03b1 \u2192 Prop) :=\n(val : \u03b1) (property : p val)\n\nattribute [pp_using_anonymous_constructor] sigma psigma subtype pprod and\n\nclass inductive decidable (p : Prop)\n| is_false (h : \u00acp) : decidable\n| is_true (h : p) : decidable\n\n@[reducible]\ndef decidable_pred {\u03b1 : Sort u} (r : \u03b1 \u2192 Prop) :=\n\u03a0 (a : \u03b1), decidable (r a)\n\n@[reducible]\ndef decidable_rel {\u03b1 : Sort u} (r : \u03b1 \u2192 \u03b1 \u2192 Prop) :=\n\u03a0 (a b : \u03b1), decidable (r a b)\n\n@[reducible]\ndef decidable_eq (\u03b1 : Sort u) :=\ndecidable_rel (@eq \u03b1)\n\ninductive option (\u03b1 : Type u)\n| none : option\n| some (val : \u03b1) : option\n\nexport option (none some)\nexport bool (ff tt)\n\ninductive list (T : Type u)\n| nil : list\n| cons (hd : T) (tl : list) : list\n\ninfixr ` :: `:67 := list.cons\nnotation `[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) := l\n\ninductive nat\n| zero : nat\n| succ (n : nat) : nat\n\nstructure unification_constraint :=\n{\u03b1 : Type u} (lhs : \u03b1) (rhs : \u03b1)\n\ninfix ` \u225f `:50 := unification_constraint.mk\ninfix ` =?= `:50 := unification_constraint.mk\n\nstructure unification_hint :=\n(pattern : unification_constraint)\n(constraints : list unification_constraint)\n\n\/- Declare builtin and reserved notation -\/\n\nclass has_zero (\u03b1 : Type u) := (zero : \u03b1)\nclass has_one (\u03b1 : Type u) := (one : \u03b1)\nclass has_add (\u03b1 : Type u) := (add : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_mul (\u03b1 : Type u) := (mul : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_inv (\u03b1 : Type u) := (inv : \u03b1 \u2192 \u03b1)\nclass has_neg (\u03b1 : Type u) := (neg : \u03b1 \u2192 \u03b1)\nclass has_sub (\u03b1 : Type u) := (sub : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_div (\u03b1 : Type u) := (div : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_dvd (\u03b1 : Type u) := (dvd : \u03b1 \u2192 \u03b1 \u2192 Prop)\nclass has_mod (\u03b1 : Type u) := (mod : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_le (\u03b1 : Type u) := (le : \u03b1 \u2192 \u03b1 \u2192 Prop)\nclass has_lt (\u03b1 : Type u) := (lt : \u03b1 \u2192 \u03b1 \u2192 Prop)\nclass has_append (\u03b1 : Type u) := (append : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_andthen (\u03b1 : Type u) (\u03b2 : Type v) (\u03c3 : out_param $ Type w) := (andthen : \u03b1 \u2192 \u03b2 \u2192 \u03c3)\nclass has_union (\u03b1 : Type u) := (union : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_inter (\u03b1 : Type u) := (inter : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_sdiff (\u03b1 : Type u) := (sdiff : \u03b1 \u2192 \u03b1 \u2192 \u03b1)\nclass has_equiv (\u03b1 : Sort u) := (equiv : \u03b1 \u2192 \u03b1 \u2192 Prop)\nclass has_subset (\u03b1 : Type u) := (subset : \u03b1 \u2192 \u03b1 \u2192 Prop)\nclass has_ssubset (\u03b1 : Type u) := (ssubset : \u03b1 \u2192 \u03b1 \u2192 Prop)\n\/- Type classes has_emptyc and has_insert are\n used to implement polymorphic notation for collections.\n Example: {a, b, c}. -\/\nclass has_emptyc (\u03b1 : Type u) := (emptyc : \u03b1)\nclass has_insert (\u03b1 : out_param $ Type u) (\u03b3 : Type v) := (insert : \u03b1 \u2192 \u03b3 \u2192 \u03b3)\nclass has_singleton (\u03b1 : out_param $ Type u) (\u03b2 : Type v) := (singleton : \u03b1 \u2192 \u03b2)\n\/- Type class used to implement the notation { a \u2208 c | p a } -\/\nclass has_sep (\u03b1 : out_param $ Type u) (\u03b3 : Type v) :=\n(sep : (\u03b1 \u2192 Prop) \u2192 \u03b3 \u2192 \u03b3)\n\/- Type class for set-like membership -\/\nclass has_mem (\u03b1 : out_param $ Type u) (\u03b3 : Type v) := (mem : \u03b1 \u2192 \u03b3 \u2192 Prop)\n\nclass has_pow (\u03b1 : Type u) (\u03b2 : Type v) :=\n(pow : \u03b1 \u2192 \u03b2 \u2192 \u03b1)\n\nexport has_andthen (andthen)\nexport has_pow (pow)\n\ninfix ` \u2208 `:50 := has_mem.mem\nnotation a ` \u2209 `:50 s:50 := \u00ac has_mem.mem a s\ninfixl ` + `:65 := has_add.add\ninfixl ` * `:70 := has_mul.mul\ninfixl ` - `:65 := has_sub.sub\ninfixl ` \/ `:70 := has_div.div\ninfix ` \u2223 `:50 := has_dvd.dvd -- Note this is different to `|`.\ninfixl ` % `:70 := has_mod.mod\nprefix `-`:75 := has_neg.neg\ninfix ` <= `:50 := has_le.le\ninfix ` \u2264 `:50 := has_le.le\ninfix ` < `:50 := has_lt.lt\ninfixl ` ++ `:65 := has_append.append\ninfixl `; `:1 := andthen\nnotation `\u2205` := has_emptyc.emptyc\ninfixl ` \u222a `:65 := has_union.union\ninfixl ` \u2229 `:70 := has_inter.inter\ninfix ` \u2286 `:50 := has_subset.subset\ninfix ` \u2282 `:50 := has_ssubset.ssubset\ninfix ` \\ `:70 := has_sdiff.sdiff\ninfix ` \u2248 `:50 := has_equiv.equiv\ninfixr ` ^ `:80 := has_pow.pow\n\nexport has_append (append)\n\n@[reducible] def ge {\u03b1 : Type u} [has_le \u03b1] (a b : \u03b1) : Prop := has_le.le b a\n@[reducible] def gt {\u03b1 : Type u} [has_lt \u03b1] (a b : \u03b1) : Prop := has_lt.lt b a\n\ninfix ` >= `:50 := ge\ninfix ` \u2265 `:50 := ge\ninfix ` > `:50 := gt\n\n@[reducible] def superset {\u03b1 : Type u} [has_subset \u03b1] (a b : \u03b1) : Prop := has_subset.subset b a\n@[reducible] def ssuperset {\u03b1 : Type u} [has_ssubset \u03b1] (a b : \u03b1) : Prop := has_ssubset.ssubset b a\n\ninfix ` \u2287 `:50 := superset\ninfix ` \u2283 `:50 := ssuperset\n\ndef bit0 {\u03b1 : Type u} [s : has_add \u03b1] (a : \u03b1) : \u03b1 := a + a\ndef bit1 {\u03b1 : Type u} [s\u2081 : has_one \u03b1] [s\u2082 : has_add \u03b1] (a : \u03b1) : \u03b1 := (bit0 a) + 1\n\nattribute [pattern] has_zero.zero has_one.one bit0 bit1 has_add.add has_neg.neg has_mul.mul\n\nexport has_insert (insert)\n\nclass is_lawful_singleton (\u03b1 : Type u) (\u03b2 : Type v) [has_emptyc \u03b2] [has_insert \u03b1 \u03b2]\n [has_singleton \u03b1 \u03b2] : Prop :=\n(insert_emptyc_eq : \u2200 (x : \u03b1), (insert x \u2205 : \u03b2) = {x})\n\nexport has_singleton (singleton)\nexport is_lawful_singleton (insert_emptyc_eq)\n\nattribute [simp] insert_emptyc_eq\n\n\/- nat basic instances -\/\n\nnamespace nat\n protected def add : nat \u2192 nat \u2192 nat\n | a zero := a\n | a (succ b) := succ (add a b)\n\n \/- We mark the following definitions as pattern to make sure they can be used in recursive equations,\n and reduced by the equation compiler. -\/\n attribute [pattern] nat.add nat.add._main\nend nat\n\ninstance : has_zero nat := \u27e8nat.zero\u27e9\n\ninstance : has_one nat := \u27e8nat.succ (nat.zero)\u27e9\n\ninstance : has_add nat := \u27e8nat.add\u27e9\n\ndef std.priority.default : nat := 1000\ndef std.priority.max : nat := 0xFFFFFFFF\n\nnamespace nat\n protected def prio := std.priority.default + 100\nend nat\n\n\/-\n Global declarations of right binding strength\n\n If a module reassigns these, it will be incompatible with other modules that adhere to these\n conventions.\n\n When hovering over a symbol, use \"C-c C-k\" to see how to input it.\n-\/\ndef std.prec.max : nat := 1024 -- the strength of application, identifiers, (, [, etc.\ndef std.prec.arrow : nat := 25\n\n\/-\nThe next def is \"max + 10\". It can be used e.g. for postfix operations that should\nbe stronger than application.\n-\/\n\ndef std.prec.max_plus : nat := std.prec.max + 10\n\npostfix `\u207b\u00b9`:std.prec.max_plus := has_inv.inv -- input with \\sy or \\-1 or \\inv\n\ninfixr ` \u00d7 `:35 := prod\n-- notation for n-ary tuples\n\n\/- sizeof -\/\n\nclass has_sizeof (\u03b1 : Sort u) :=\n(sizeof : \u03b1 \u2192 nat)\n\ndef sizeof {\u03b1 : Sort u} [s : has_sizeof \u03b1] : \u03b1 \u2192 nat :=\nhas_sizeof.sizeof\n\n\/-\nDeclare sizeof instances and lemmas for types declared before has_sizeof.\nFrom now on, the inductive compiler will automatically generate sizeof instances and lemmas.\n-\/\n\n\/- Every type `\u03b1` has a default has_sizeof instance that just returns 0 for every element of `\u03b1` -\/\nprotected def default.sizeof (\u03b1 : Sort u) : \u03b1 \u2192 nat\n| a := 0\n\ninstance default_has_sizeof (\u03b1 : Sort u) : has_sizeof \u03b1 :=\n\u27e8default.sizeof \u03b1\u27e9\n\nprotected def nat.sizeof : nat \u2192 nat\n| n := n\n\ninstance : has_sizeof nat :=\n\u27e8nat.sizeof\u27e9\n\nprotected def prod.sizeof {\u03b1 : Type u} {\u03b2 : Type v} [has_sizeof \u03b1] [has_sizeof \u03b2] : (prod \u03b1 \u03b2) \u2192 nat\n| \u27e8a, b\u27e9 := 1 + sizeof a + sizeof b\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_sizeof \u03b1] [has_sizeof \u03b2] : has_sizeof (prod \u03b1 \u03b2) :=\n\u27e8prod.sizeof\u27e9\n\nprotected def sum.sizeof {\u03b1 : Type u} {\u03b2 : Type v} [has_sizeof \u03b1] [has_sizeof \u03b2] : (sum \u03b1 \u03b2) \u2192 nat\n| (sum.inl a) := 1 + sizeof a\n| (sum.inr b) := 1 + sizeof b\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_sizeof \u03b1] [has_sizeof \u03b2] : has_sizeof (sum \u03b1 \u03b2) :=\n\u27e8sum.sizeof\u27e9\n\nprotected def psum.sizeof {\u03b1 : Type u} {\u03b2 : Type v} [has_sizeof \u03b1] [has_sizeof \u03b2] : (psum \u03b1 \u03b2) \u2192 nat\n| (psum.inl a) := 1 + sizeof a\n| (psum.inr b) := 1 + sizeof b\n\ninstance (\u03b1 : Type u) (\u03b2 : Type v) [has_sizeof \u03b1] [has_sizeof \u03b2] : has_sizeof (psum \u03b1 \u03b2) :=\n\u27e8psum.sizeof\u27e9\n\nprotected def sigma.sizeof {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v} [has_sizeof \u03b1] [\u2200 a, has_sizeof (\u03b2 a)] : sigma \u03b2 \u2192 nat\n| \u27e8a, b\u27e9 := 1 + sizeof a + sizeof b\n\ninstance (\u03b1 : Type u) (\u03b2 : \u03b1 \u2192 Type v) [has_sizeof \u03b1] [\u2200 a, has_sizeof (\u03b2 a)] : has_sizeof (sigma \u03b2) :=\n\u27e8sigma.sizeof\u27e9\n\nprotected def psigma.sizeof {\u03b1 : Type u} {\u03b2 : \u03b1 \u2192 Type v} [has_sizeof \u03b1] [\u2200 a, has_sizeof (\u03b2 a)] : psigma \u03b2 \u2192 nat\n| \u27e8a, b\u27e9 := 1 + sizeof a + sizeof b\n\ninstance (\u03b1 : Type u) (\u03b2 : \u03b1 \u2192 Type v) [has_sizeof \u03b1] [\u2200 a, has_sizeof (\u03b2 a)] : has_sizeof (psigma \u03b2) :=\n\u27e8psigma.sizeof\u27e9\n\nprotected def punit.sizeof : punit \u2192 nat\n| u := 1\n\ninstance : has_sizeof punit := \u27e8punit.sizeof\u27e9\n\nprotected def bool.sizeof : bool \u2192 nat\n| b := 1\n\ninstance : has_sizeof bool := \u27e8bool.sizeof\u27e9\n\nprotected def option.sizeof {\u03b1 : Type u} [has_sizeof \u03b1] : option \u03b1 \u2192 nat\n| none := 1\n| (some a) := 1 + sizeof a\n\ninstance (\u03b1 : Type u) [has_sizeof \u03b1] : has_sizeof (option \u03b1) :=\n\u27e8option.sizeof\u27e9\n\nprotected def list.sizeof {\u03b1 : Type u} [has_sizeof \u03b1] : list \u03b1 \u2192 nat\n| list.nil := 1\n| (list.cons a l) := 1 + sizeof a + list.sizeof l\n\ninstance (\u03b1 : Type u) [has_sizeof \u03b1] : has_sizeof (list \u03b1) :=\n\u27e8list.sizeof\u27e9\n\nprotected def subtype.sizeof {\u03b1 : Type u} [has_sizeof \u03b1] {p : \u03b1 \u2192 Prop} : subtype p \u2192 nat\n| \u27e8a, _\u27e9 := sizeof a\n\ninstance {\u03b1 : Type u} [has_sizeof \u03b1] (p : \u03b1 \u2192 Prop) : has_sizeof (subtype p) :=\n\u27e8subtype.sizeof\u27e9\n\nlemma nat_add_zero (n : nat) : n + 0 = n := rfl\n\n\/- Combinator calculus -\/\nnamespace combinator\nuniverses u\u2081 u\u2082 u\u2083\ndef I {\u03b1 : Type u\u2081} (a : \u03b1) := a\ndef K {\u03b1 : Type u\u2081} {\u03b2 : Type u\u2082} (a : \u03b1) (b : \u03b2) := a\ndef S {\u03b1 : Type u\u2081} {\u03b2 : Type u\u2082} {\u03b3 : Type u\u2083} (x : \u03b1 \u2192 \u03b2 \u2192 \u03b3) (y : \u03b1 \u2192 \u03b2) (z : \u03b1) := x z (y z)\nend combinator\n\n\/-- Auxiliary datatype for #[ ... ] notation.\n #[1, 2, 3, 4] is notation for\n\n bin_tree.node\n (bin_tree.node (bin_tree.leaf 1) (bin_tree.leaf 2))\n (bin_tree.node (bin_tree.leaf 3) (bin_tree.leaf 4))\n\n We use this notation to input long sequences without exhausting the system stack space.\n Later, we define a coercion from `bin_tree` into `list`.\n-\/\ninductive bin_tree (\u03b1 : Type u)\n| empty : bin_tree\n| leaf (val : \u03b1) : bin_tree\n| node (left right : bin_tree) : bin_tree\n\nattribute [elab_simple] bin_tree.node bin_tree.leaf\n\n\/-- Like `by apply_instance`, but not dependent on the tactic framework. -\/\n@[reducible] def infer_instance {\u03b1 : Sort u} [i : \u03b1] : \u03b1 := i\n","avg_line_length":31.7477477477,"max_line_length":113,"alphanum_fraction":0.6150964813} -{"size":3986,"ext":"lean","lang":"Lean","max_stars_count":1131.0,"content":"\/-\nCopyright (c) 2017 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-\/\n\n\/-!\n# Inductive type variant of `fin`\n\n`fin` is defined as a subtype of `\u2115`. This file defines an equivalent type, `fin2`, which is\ndefined inductively. This is useful for its induction principle and different definitional\nequalities.\n\n## Main declarations\n\n* `fin2 n`: Inductive type variant of `fin n`. `fz` corresponds to `0` and `fs n` corresponds to\n `n`.\n* `to_nat`, `opt_of_nat`, `of_nat'`: Conversions to and from `\u2115`. `of_nat' m` takes a proof that\n `m < n` through the class `is_lt`.\n* `add k`: Takes `i : fin2 n` to `i + k : fin2 (n + k)`.\n* `left`: Embeds `fin2 n` into `fin2 (n + k)`.\n* `insert_perm a`: Permutation of `fin2 n` which cycles `0, ..., a - 1` and leaves `a, ..., n - 1`\n unchanged.\n* `remap_left f`: Function `fin2 (m + k) \u2192 fin2 (n + k)` by applying `f : fin m \u2192 fin n` to\n `0, ..., m - 1` and sending `m + i` to `n + i`.\n-\/\n\nopen nat\nuniverses u\n\n\/-- An alternate definition of `fin n` defined as an inductive type instead of a subtype of `\u2115`. -\/\ninductive fin2 : \u2115 \u2192 Type\n\/-- `0` as a member of `fin (succ n)` (`fin 0` is empty) -\/\n| fz {n} : fin2 (succ n)\n\/-- `n` as a member of `fin (succ n)` -\/\n| fs {n} : fin2 n \u2192 fin2 (succ n)\n\nnamespace fin2\n\n\/-- Define a dependent function on `fin2 (succ n)` by giving its value at\nzero (`H1`) and by giving a dependent function on the rest (`H2`). -\/\n@[elab_as_eliminator]\nprotected def cases' {n} {C : fin2 (succ n) \u2192 Sort u} (H1 : C fz) (H2 : \u03a0 n, C (fs n)) :\n \u03a0 (i : fin2 (succ n)), C i\n| fz := H1\n| (fs n) := H2 n\n\n\/-- Ex falso. The dependent eliminator for the empty `fin2 0` type. -\/\ndef elim0 {C : fin2 0 \u2192 Sort u} : \u03a0 (i : fin2 0), C i.\n\n\/-- Converts a `fin2` into a natural. -\/\ndef to_nat : \u03a0 {n}, fin2 n \u2192 \u2115\n| ._ (@fz n) := 0\n| ._ (@fs n i) := succ (to_nat i)\n\n\/-- Converts a natural into a `fin2` if it is in range -\/\ndef opt_of_nat : \u03a0 {n} (k : \u2115), option (fin2 n)\n| 0 _ := none\n| (succ n) 0 := some fz\n| (succ n) (succ k) := fs <$> @opt_of_nat n k\n\n\/-- `i + k : fin2 (n + k)` when `i : fin2 n` and `k : \u2115` -\/\ndef add {n} (i : fin2 n) : \u03a0 k, fin2 (n + k)\n| 0 := i\n| (succ k) := fs (add k)\n\n\/-- `left k` is the embedding `fin2 n \u2192 fin2 (k + n)` -\/\ndef left (k) : \u03a0 {n}, fin2 n \u2192 fin2 (k + n)\n| ._ (@fz n) := fz\n| ._ (@fs n i) := fs (left i)\n\n\/-- `insert_perm a` is a permutation of `fin2 n` with the following properties:\n * `insert_perm a i = i+1` if `i < a`\n * `insert_perm a a = 0`\n * `insert_perm a i = i` if `i > a` -\/\ndef insert_perm : \u03a0 {n}, fin2 n \u2192 fin2 n \u2192 fin2 n\n| ._ (@fz n) (@fz ._) := fz\n| ._ (@fz n) (@fs ._ j) := fs j\n| ._ (@fs (succ n) i) (@fz ._) := fs fz\n| ._ (@fs (succ n) i) (@fs ._ j) := match insert_perm i j with fz := fz | fs k := fs (fs k) end\n\n\/-- `remap_left f k : fin2 (m + k) \u2192 fin2 (n + k)` applies the function\n `f : fin2 m \u2192 fin2 n` to inputs less than `m`, and leaves the right part\n on the right (that is, `remap_left f k (m + i) = n + i`). -\/\ndef remap_left {m n} (f : fin2 m \u2192 fin2 n) : \u03a0 k, fin2 (m + k) \u2192 fin2 (n + k)\n| 0 i := f i\n| (succ k) (@fz ._) := fz\n| (succ k) (@fs ._ i) := fs (remap_left _ i)\n\n\/-- This is a simple type class inference prover for proof obligations\n of the form `m < n` where `m n : \u2115`. -\/\nclass is_lt (m n : \u2115) := (h : m < n)\ninstance is_lt.zero (n) : is_lt 0 (succ n) := \u27e8succ_pos _\u27e9\ninstance is_lt.succ (m n) [l : is_lt m n] : is_lt (succ m) (succ n) := \u27e8succ_lt_succ l.h\u27e9\n\n\/-- Use type class inference to infer the boundedness proof, so that we can directly convert a\n`nat` into a `fin2 n`. This supports notation like `&1 : fin 3`. -\/\ndef of_nat' : \u03a0 {n} m [is_lt m n], fin2 n\n| 0 m \u27e8h\u27e9 := absurd h (nat.not_lt_zero _)\n| (succ n) 0 \u27e8h\u27e9 := fz\n| (succ n) (succ m) \u27e8h\u27e9 := fs (@of_nat' n m \u27e8lt_of_succ_lt_succ h\u27e9)\n\nlocal prefix `&`:max := of_nat'\n\ninstance : inhabited (fin2 1) := \u27e8fz\u27e9\n\nend fin2\n","avg_line_length":36.9074074074,"max_line_length":99,"alphanum_fraction":0.5747616658} -{"size":26579,"ext":"lean","lang":"Lean","max_stars_count":null,"content":"\/-\nCopyright (c) 2018 Johannes H\u00f6lzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes H\u00f6lzl, Callum Sutton, Yury Kudryashov\n-\/\nimport algebra.group.type_tags\nimport algebra.group_with_zero.basic\nimport data.pi\n\n\/-!\n# Multiplicative and additive equivs\n\nIn this file we define two extensions of `equiv` called `add_equiv` and `mul_equiv`, which are\ndatatypes representing isomorphisms of `add_monoid`s\/`add_group`s and `monoid`s\/`group`s.\n\n## Notations\n\n* ``infix ` \u2243* `:25 := mul_equiv``\n* ``infix ` \u2243+ `:25 := add_equiv``\n\nThe extended equivs all have coercions to functions, and the coercions are the canonical\nnotation when treating the isomorphisms as maps.\n\n## Implementation notes\n\nThe fields for `mul_equiv`, `add_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as\nthese are deprecated.\n\n## Tags\n\nequiv, mul_equiv, add_equiv\n-\/\n\nvariables {A : Type*} {B : Type*} {M : Type*} {N : Type*}\n {P : Type*} {Q : Type*} {G : Type*} {H : Type*}\n\n\/-- Makes a multiplicative inverse from a bijection which preserves multiplication. -\/\n@[to_additive \"Makes an additive inverse from a bijection which preserves addition.\"]\ndef mul_hom.inverse [has_mul M] [has_mul N] (f : mul_hom M N) (g : N \u2192 M)\n (h\u2081 : function.left_inverse g f) (h\u2082 : function.right_inverse g f) : mul_hom N M :=\n{ to_fun := g,\n map_mul' := \u03bb x y,\n calc g (x * y) = g (f (g x) * f (g y)) : by rw [h\u2082 x, h\u2082 y]\n ... = g (f (g x * g y)) : by rw f.map_mul\n ... = g x * g y : h\u2081 _, }\n\n\/-- The inverse of a bijective `monoid_hom` is a `monoid_hom`. -\/\n@[to_additive \"The inverse of a bijective `add_monoid_hom` is an `add_monoid_hom`.\", simps]\ndef monoid_hom.inverse {A B : Type*} [monoid A] [monoid B] (f : A \u2192* B) (g : B \u2192 A)\n (h\u2081 : function.left_inverse g f) (h\u2082 : function.right_inverse g f) :\n B \u2192* A :=\n{ to_fun := g,\n map_one' := by rw [\u2190 f.map_one, h\u2081],\n .. (f : mul_hom A B).inverse g h\u2081 h\u2082, }\n\nset_option old_structure_cmd true\n\n\/-- add_equiv \u03b1 \u03b2 is the type of an equiv \u03b1 \u2243 \u03b2 which preserves addition. -\/\n@[ancestor equiv add_hom]\nstructure add_equiv (A B : Type*) [has_add A] [has_add B] extends A \u2243 B, add_hom A B\n\n\/-- `add_equiv_class F A B` states that `F` is a type of addition-preserving morphisms.\nYou should extend this class when you extend `add_equiv`. -\/\nclass add_equiv_class (F A B : Type*) [has_add A] [has_add B]\n extends equiv_like F A B :=\n(map_add : \u2200 (f : F) a b, f (a + b) = f a + f b)\n\n\/-- The `equiv` underlying an `add_equiv`. -\/\nadd_decl_doc add_equiv.to_equiv\n\/-- The `add_hom` underlying a `add_equiv`. -\/\nadd_decl_doc add_equiv.to_add_hom\n\n\/-- `mul_equiv \u03b1 \u03b2` is the type of an equiv `\u03b1 \u2243 \u03b2` which preserves multiplication. -\/\n@[ancestor equiv mul_hom, to_additive]\nstructure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M \u2243 N, mul_hom M N\n\n\/-- The `equiv` underlying a `mul_equiv`. -\/\nadd_decl_doc mul_equiv.to_equiv\n\/-- The `mul_hom` underlying a `mul_equiv`. -\/\nadd_decl_doc mul_equiv.to_mul_hom\n\n\/-- `mul_equiv_class F A B` states that `F` is a type of multiplication-preserving morphisms.\nYou should extend this class when you extend `mul_equiv`. -\/\n@[to_additive]\nclass mul_equiv_class (F A B : Type*) [has_mul A] [has_mul B]\n extends equiv_like F A B :=\n(map_mul : \u2200 (f : F) a b, f (a * b) = f a * f b)\n\ninfix ` \u2243* `:25 := mul_equiv\ninfix ` \u2243+ `:25 := add_equiv\n\nsection mul_equiv_class\n\nvariables (F : Type*)\n\nnamespace mul_equiv_class\n\n@[priority 100, -- See note [lower instance priority]\n to_additive]\ninstance [has_mul M] [has_mul N] [h : mul_equiv_class F M N] : mul_hom_class F M N :=\n{ coe := (coe : F \u2192 M \u2192 N),\n coe_injective' := @fun_like.coe_injective F _ _ _,\n .. h }\n\n@[priority 100, -- See note [lower instance priority]\n to_additive]\ninstance [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N] :\n monoid_hom_class F M N :=\n{ coe := (coe : F \u2192 M \u2192 N),\n map_one := \u03bb e,\n calc e 1 = e 1 * 1 : (mul_one _).symm\n ... = e 1 * e (inv e (1 : N) : M) : congr_arg _ (right_inv e 1).symm\n ... = e (inv e (1 : N)) : by rw [\u2190 map_mul, one_mul]\n ... = 1 : right_inv e 1,\n .. mul_equiv_class.mul_hom_class F }\n\nvariables {F}\n\n@[simp, to_additive]\nlemma map_eq_one_iff {M N} [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N]\n (h : F) {x : M} :\n h x = 1 \u2194 x = 1 :=\nby rw [\u2190 map_one h, equiv_like.apply_eq_iff_eq h]\n\n@[to_additive]\nlemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N]\n (h : F) {x : M} :\n h x \u2260 1 \u2194 x \u2260 1 :=\nnot_congr (map_eq_one_iff h)\n\nend mul_equiv_class\n\nend mul_equiv_class\n\nnamespace mul_equiv\n\n@[to_additive]\ninstance [has_mul M] [has_mul N] : has_coe_to_fun (M \u2243* N) (\u03bb _, M \u2192 N) := \u27e8mul_equiv.to_fun\u27e9\n\n@[to_additive]\ninstance [has_mul M] [has_mul N] : mul_equiv_class (M \u2243* N) M N :=\n{ coe := to_fun, inv := inv_fun, left_inv := left_inv, right_inv := right_inv,\n coe_injective' := \u03bb f g h\u2081 h\u2082, by { cases f, cases g, congr' },\n map_mul := map_mul' }\n\nvariables [has_mul M] [has_mul N] [has_mul P] [has_mul Q]\n\n@[simp, to_additive]\nlemma to_fun_eq_coe {f : M \u2243* N} : f.to_fun = f := rfl\n\n@[simp, to_additive]\nlemma coe_to_equiv {f : M \u2243* N} : \u21d1f.to_equiv = f := rfl\n\n@[simp, to_additive]\nlemma coe_to_mul_hom {f : M \u2243* N} : \u21d1f.to_mul_hom = f := rfl\n\n\/-- A multiplicative isomorphism preserves multiplication (canonical form). -\/\n@[to_additive]\nprotected lemma map_mul (f : M \u2243* N) : \u2200 x y, f (x * y) = f x * f y := map_mul f\n\n\/-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -\/\n@[to_additive \"Makes an additive isomorphism from a bijection which preserves addition.\"]\ndef mk' (f : M \u2243 N) (h : \u2200 x y, f (x * y) = f x * f y) : M \u2243* N :=\n\u27e8f.1, f.2, f.3, f.4, h\u27e9\n\n@[to_additive]\nprotected lemma bijective (e : M \u2243* N) : function.bijective e := equiv_like.bijective e\n\n@[to_additive]\nprotected lemma injective (e : M \u2243* N) : function.injective e := equiv_like.injective e\n\n@[to_additive]\nprotected lemma surjective (e : M \u2243* N) : function.surjective e := equiv_like.surjective e\n\n\/-- The identity map is a multiplicative isomorphism. -\/\n@[refl, to_additive \"The identity map is an additive isomorphism.\"]\ndef refl (M : Type*) [has_mul M] : M \u2243* M :=\n{ map_mul' := \u03bb _ _, rfl,\n..equiv.refl _}\n\n@[to_additive]\ninstance : inhabited (M \u2243* M) := \u27e8refl M\u27e9\n\n\/-- The inverse of an isomorphism is an isomorphism. -\/\n@[symm, to_additive \"The inverse of an isomorphism is an isomorphism.\"]\ndef symm (h : M \u2243* N) : N \u2243* M :=\n{ map_mul' := (h.to_mul_hom.inverse h.to_equiv.symm h.left_inv h.right_inv).map_mul,\n .. h.to_equiv.symm}\n\n@[simp, to_additive]\nlemma inv_fun_eq_symm {f : M \u2243* N} : f.inv_fun = f.symm := rfl\n\n\/-- See Note [custom simps projection] -\/\n-- we don't hyperlink the note in the additive version, since that breaks syntax highlighting\n-- in the whole file.\n@[to_additive \"See Note custom simps projection\"]\ndef simps.symm_apply (e : M \u2243* N) : N \u2192 M := e.symm\n\ninitialize_simps_projections add_equiv (to_fun \u2192 apply, inv_fun \u2192 symm_apply)\ninitialize_simps_projections mul_equiv (to_fun \u2192 apply, inv_fun \u2192 symm_apply)\n\n@[simp, to_additive]\ntheorem to_equiv_symm (f : M \u2243* N) : f.symm.to_equiv = f.to_equiv.symm := rfl\n\n@[simp, to_additive]\ntheorem coe_mk (f : M \u2192 N) (g h\u2081 h\u2082 h\u2083) : \u21d1(mul_equiv.mk f g h\u2081 h\u2082 h\u2083) = f := rfl\n\n@[simp, to_additive]\nlemma to_equiv_mk (f : M \u2192 N) (g : N \u2192 M) (h\u2081 h\u2082 h\u2083) :\n (mk f g h\u2081 h\u2082 h\u2083).to_equiv = \u27e8f, g, h\u2081, h\u2082\u27e9 := rfl\n\n@[simp, to_additive]\nlemma symm_symm : \u2200 (f : M \u2243* N), f.symm.symm = f\n| \u27e8f, g, h\u2081, h\u2082, h\u2083\u27e9 := rfl\n\n@[to_additive]\nlemma symm_bijective : function.bijective (symm : (M \u2243* N) \u2192 (N \u2243* M)) :=\nequiv.bijective \u27e8symm, symm, symm_symm, symm_symm\u27e9\n\n@[simp, to_additive]\ntheorem symm_mk (f : M \u2192 N) (g h\u2081 h\u2082 h\u2083) :\n (mul_equiv.mk f g h\u2081 h\u2082 h\u2083).symm =\n { to_fun := g, inv_fun := f, ..(mul_equiv.mk f g h\u2081 h\u2082 h\u2083).symm} := rfl\n\n\/-- Transitivity of multiplication-preserving isomorphisms -\/\n@[trans, to_additive \"Transitivity of addition-preserving isomorphisms\"]\ndef trans (h1 : M \u2243* N) (h2 : N \u2243* P) : (M \u2243* P) :=\n{ map_mul' := \u03bb x y, show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y),\n by rw [h1.map_mul, h2.map_mul],\n ..h1.to_equiv.trans h2.to_equiv }\n\n\/-- e.right_inv in canonical form -\/\n@[simp, to_additive]\nlemma apply_symm_apply (e : M \u2243* N) : \u2200 y, e (e.symm y) = y :=\ne.to_equiv.apply_symm_apply\n\n\/-- e.left_inv in canonical form -\/\n@[simp, to_additive]\nlemma symm_apply_apply (e : M \u2243* N) : \u2200 x, e.symm (e x) = x :=\ne.to_equiv.symm_apply_apply\n\n@[simp, to_additive]\ntheorem symm_comp_self (e : M \u2243* N) : e.symm \u2218 e = id := funext e.symm_apply_apply\n\n@[simp, to_additive]\ntheorem self_comp_symm (e : M \u2243* N) : e \u2218 e.symm = id := funext e.apply_symm_apply\n\n@[simp, to_additive]\ntheorem coe_refl : \u21d1(refl M) = id := rfl\n\n@[to_additive]\ntheorem refl_apply (m : M) : refl M m = m := rfl\n\n@[simp, to_additive]\ntheorem coe_trans (e\u2081 : M \u2243* N) (e\u2082 : N \u2243* P) : \u21d1(e\u2081.trans e\u2082) = e\u2082 \u2218 e\u2081 := rfl\n\n@[to_additive]\ntheorem trans_apply (e\u2081 : M \u2243* N) (e\u2082 : N \u2243* P) (m : M) : e\u2081.trans e\u2082 m = e\u2082 (e\u2081 m) := rfl\n\n@[simp, to_additive] theorem symm_trans_apply (e\u2081 : M \u2243* N) (e\u2082 : N \u2243* P) (p : P) :\n (e\u2081.trans e\u2082).symm p = e\u2081.symm (e\u2082.symm p) := rfl\n\n@[simp, to_additive] theorem apply_eq_iff_eq (e : M \u2243* N) {x y : M} : e x = e y \u2194 x = y :=\ne.injective.eq_iff\n\n@[to_additive]\nlemma apply_eq_iff_symm_apply (e : M \u2243* N) {x : M} {y : N} : e x = y \u2194 x = e.symm y :=\ne.to_equiv.apply_eq_iff_eq_symm_apply\n\n@[to_additive]\nlemma symm_apply_eq (e : M \u2243* N) {x y} : e.symm x = y \u2194 x = e y :=\ne.to_equiv.symm_apply_eq\n\n@[to_additive]\nlemma eq_symm_apply (e : M \u2243* N) {x y} : y = e.symm x \u2194 e y = x :=\ne.to_equiv.eq_symm_apply\n\n\/-- Two multiplicative isomorphisms agree if they are defined by the\n same underlying function. -\/\n@[ext, to_additive\n \"Two additive isomorphisms agree if they are defined by the same underlying function.\"]\nlemma ext {f g : mul_equiv M N} (h : \u2200 x, f x = g x) : f = g := fun_like.ext f g h\n\n@[to_additive] lemma ext_iff {f g : mul_equiv M N} : f = g \u2194 \u2200 x, f x = g x := fun_like.ext_iff\n\n@[simp, to_additive] lemma mk_coe (e : M \u2243* N) (e' h\u2081 h\u2082 h\u2083) :\n (\u27e8e, e', h\u2081, h\u2082, h\u2083\u27e9 : M \u2243* N) = e := ext $ \u03bb _, rfl\n\n@[simp, to_additive] lemma mk_coe' (e : M \u2243* N) (f h\u2081 h\u2082 h\u2083) :\n (mul_equiv.mk f \u21d1e h\u2081 h\u2082 h\u2083 : N \u2243* M) = e.symm :=\nsymm_bijective.injective $ ext $ \u03bb x, rfl\n\n@[to_additive] protected lemma congr_arg {f : mul_equiv M N} {x x' : M} : x = x' \u2192 f x = f x' :=\nfun_like.congr_arg f\n\n@[to_additive] protected lemma congr_fun {f g : mul_equiv M N} (h : f = g) (x : M) : f x = g x :=\nfun_like.congr_fun h x\n\n\/-- The `mul_equiv` between two monoids with a unique element. -\/\n@[to_additive \"The `add_equiv` between two add_monoids with a unique element.\"]\ndef mul_equiv_of_unique_of_unique {M N}\n [unique M] [unique N] [has_mul M] [has_mul N] : M \u2243* N :=\n{ map_mul' := \u03bb _ _, subsingleton.elim _ _,\n ..equiv_of_unique_of_unique }\n\n\/-- There is a unique monoid homomorphism between two monoids with a unique element. -\/\n@[to_additive] instance {M N} [unique M] [unique N] [has_mul M] [has_mul N] : unique (M \u2243* N) :=\n{ default := mul_equiv_of_unique_of_unique ,\n uniq := \u03bb _, ext $ \u03bb x, subsingleton.elim _ _}\n\n\/-!\n## Monoids\n-\/\n\n\/-- A multiplicative equiv of monoids sends 1 to 1 (and is hence a monoid isomorphism). -\/\n@[to_additive]\nprotected lemma map_one {M N} [mul_one_class M] [mul_one_class N] (h : M \u2243* N) : h 1 = 1 :=\nmap_one h\n\n@[to_additive]\nprotected lemma map_eq_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M \u2243* N) {x : M} :\n h x = 1 \u2194 x = 1 :=\nmul_equiv_class.map_eq_one_iff h\n\n@[to_additive]\nlemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M \u2243* N) {x : M} :\n h x \u2260 1 \u2194 x \u2260 1 :=\nmul_equiv_class.map_ne_one_iff h\n\n\/-- A bijective `monoid` homomorphism is an isomorphism -\/\n@[to_additive \"A bijective `add_monoid` homomorphism is an isomorphism\"]\nnoncomputable def of_bijective {M N} [mul_one_class M] [mul_one_class N] (f : M \u2192* N)\n (hf : function.bijective f) : M \u2243* N :=\n{ map_mul' := f.map_mul',\n ..equiv.of_bijective f hf }\n\n\/--\nExtract the forward direction of a multiplicative equivalence\nas a multiplication-preserving function.\n-\/\n@[to_additive \"Extract the forward direction of an additive equivalence\nas an addition-preserving function.\"]\ndef to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (h : M \u2243* N) : (M \u2192* N) :=\n{ map_one' := h.map_one, .. h }\n\n@[simp, to_additive]\nlemma coe_to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (e : M \u2243* N) :\n \u21d1e.to_monoid_hom = e :=\nrfl\n\n@[to_additive] lemma to_monoid_hom_injective {M N} [mul_one_class M] [mul_one_class N] :\n function.injective (to_monoid_hom : (M \u2243* N) \u2192 M \u2192* N) :=\n\u03bb f g h, mul_equiv.ext (monoid_hom.ext_iff.1 h)\n\n\n\/--\nA multiplicative analogue of `equiv.arrow_congr`,\nwhere the equivalence between the targets is multiplicative.\n-\/\n@[to_additive \"An additive analogue of `equiv.arrow_congr`,\nwhere the equivalence between the targets is additive.\", simps apply]\ndef arrow_congr {M N P Q : Type*} [mul_one_class P] [mul_one_class Q]\n (f : M \u2243 N) (g : P \u2243* Q) : (M \u2192 P) \u2243* (N \u2192 Q) :=\n{ to_fun := \u03bb h n, g (h (f.symm n)),\n inv_fun := \u03bb k m, g.symm (k (f m)),\n left_inv := \u03bb h, by { ext, simp, },\n right_inv := \u03bb k, by { ext, simp, },\n map_mul' := \u03bb h k, by { ext, simp, }, }\n\n\/--\nA multiplicative analogue of `equiv.arrow_congr`,\nfor multiplicative maps from a monoid to a commutative monoid.\n-\/\n@[to_additive \"An additive analogue of `equiv.arrow_congr`,\nfor additive maps from an additive monoid to a commutative additive monoid.\", simps apply]\ndef monoid_hom_congr {M N P Q} [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]\n (f : M \u2243* N) (g : P \u2243* Q) : (M \u2192* P) \u2243* (N \u2192* Q) :=\n{ to_fun := \u03bb h,\n g.to_monoid_hom.comp (h.comp f.symm.to_monoid_hom),\n inv_fun := \u03bb k,\n g.symm.to_monoid_hom.comp (k.comp f.to_monoid_hom),\n left_inv := \u03bb h, by { ext, simp, },\n right_inv := \u03bb k, by { ext, simp, },\n map_mul' := \u03bb h k, by { ext, simp, }, }\n\n\/-- A family of multiplicative equivalences `\u03a0 j, (Ms j \u2243* Ns j)` generates a\nmultiplicative equivalence between `\u03a0 j, Ms j` and `\u03a0 j, Ns j`.\n\nThis is the `mul_equiv` version of `equiv.Pi_congr_right`, and the dependent version of\n`mul_equiv.arrow_congr`.\n-\/\n@[to_additive add_equiv.Pi_congr_right \"A family of additive equivalences `\u03a0 j, (Ms j \u2243+ Ns j)`\ngenerates an additive equivalence between `\u03a0 j, Ms j` and `\u03a0 j, Ns j`.\n\nThis is the `add_equiv` version of `equiv.Pi_congr_right`, and the dependent version of\n`add_equiv.arrow_congr`.\", simps apply]\ndef Pi_congr_right {\u03b7 : Type*}\n {Ms Ns : \u03b7 \u2192 Type*} [\u03a0 j, mul_one_class (Ms j)] [\u03a0 j, mul_one_class (Ns j)]\n (es : \u2200 j, Ms j \u2243* Ns j) : (\u03a0 j, Ms j) \u2243* (\u03a0 j, Ns j) :=\n{ to_fun := \u03bb x j, es j (x j),\n inv_fun := \u03bb x j, (es j).symm (x j),\n map_mul' := \u03bb x y, funext $ \u03bb j, (es j).map_mul (x j) (y j),\n .. equiv.Pi_congr_right (\u03bb j, (es j).to_equiv) }\n\n@[simp]\nlemma Pi_congr_right_refl {\u03b7 : Type*} {Ms : \u03b7 \u2192 Type*} [\u03a0 j, mul_one_class (Ms j)] :\n Pi_congr_right (\u03bb j, mul_equiv.refl (Ms j)) = mul_equiv.refl _ := rfl\n\n@[simp]\nlemma Pi_congr_right_symm {\u03b7 : Type*}\n {Ms Ns : \u03b7 \u2192 Type*} [\u03a0 j, mul_one_class (Ms j)] [\u03a0 j, mul_one_class (Ns j)]\n (es : \u2200 j, Ms j \u2243* Ns j) : (Pi_congr_right es).symm = (Pi_congr_right $ \u03bb i, (es i).symm) := rfl\n\n@[simp]\nlemma Pi_congr_right_trans {\u03b7 : Type*}\n {Ms Ns Ps : \u03b7 \u2192 Type*} [\u03a0 j, mul_one_class (Ms j)] [\u03a0 j, mul_one_class (Ns j)]\n [\u03a0 j, mul_one_class (Ps j)]\n (es : \u2200 j, Ms j \u2243* Ns j) (fs : \u2200 j, Ns j \u2243* Ps j) :\n (Pi_congr_right es).trans (Pi_congr_right fs) = (Pi_congr_right $ \u03bb i, (es i).trans (fs i)) := rfl\n\n\/-- A family indexed by a nonempty subsingleton type is equivalent to the element at the single\nindex. -\/\n@[to_additive add_equiv.Pi_subsingleton \"A family indexed by a nonempty subsingleton type is\nequivalent to the element at the single index.\", simps]\ndef Pi_subsingleton\n {\u03b9 : Type*} (M : \u03b9 \u2192 Type*) [\u03a0 j, has_mul (M j)] [subsingleton \u03b9] (i : \u03b9) :\n (\u03a0 j, M j) \u2243* M i :=\n{ map_mul' := \u03bb f1 f2, pi.mul_apply _ _ _, ..equiv.Pi_subsingleton M i }\n\n\/-!\n# Groups\n-\/\n\n\/-- A multiplicative equivalence of groups preserves inversion. -\/\n@[to_additive]\nprotected lemma map_inv [group G] [group H] (h : G \u2243* H) (x : G) : h x\u207b\u00b9 = (h x)\u207b\u00b9 :=\nmap_inv h x\n\n\/-- A multiplicative equivalence of groups preserves division. -\/\n@[to_additive]\nprotected lemma map_div [group G] [group H] (h : G \u2243* H) (x y : G) : h (x \/ y) = h x \/ h y :=\nmap_div h x y\n\nend mul_equiv\n\n\/-- Given a pair of monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`,\nreturns an multiplicative equivalence with `to_fun = f` and `inv_fun = g`. This constructor is\nuseful if the underlying type(s) have specialized `ext` lemmas for monoid homomorphisms. -\/\n@[to_additive \/-\"Given a pair of additive monoid homomorphisms `f`, `g` such that `g.comp f = id`\nand `f.comp g = id`, returns an additive equivalence with `to_fun = f` and `inv_fun = g`. This\nconstructor is useful if the underlying type(s) have specialized `ext` lemmas for additive\nmonoid homomorphisms.\"-\/, simps {fully_applied := ff}]\ndef monoid_hom.to_mul_equiv [mul_one_class M] [mul_one_class N] (f : M \u2192* N) (g : N \u2192* M)\n (h\u2081 : g.comp f = monoid_hom.id _) (h\u2082 : f.comp g = monoid_hom.id _) :\n M \u2243* N :=\n{ to_fun := f,\n inv_fun := g,\n left_inv := monoid_hom.congr_fun h\u2081,\n right_inv := monoid_hom.congr_fun h\u2082,\n map_mul' := f.map_mul }\n\n\/-- A group is isomorphic to its group of units. -\/\n@[to_additive to_add_units \"An additive group is isomorphic to its group of additive units\"]\ndef to_units [group G] : G \u2243* G\u02e3 :=\n{ to_fun := \u03bb x, \u27e8x, x\u207b\u00b9, mul_inv_self _, inv_mul_self _\u27e9,\n inv_fun := coe,\n left_inv := \u03bb x, rfl,\n right_inv := \u03bb u, units.ext rfl,\n map_mul' := \u03bb x y, units.ext rfl }\n\n@[simp, to_additive coe_to_add_units] lemma coe_to_units [group G] (g : G) :\n (to_units g : G) = g := rfl\n\nprotected lemma group.is_unit {G} [group G] (x : G) : is_unit x := (to_units x).is_unit\n\nnamespace units\n\n@[simp, to_additive] lemma coe_inv [group G] (u : G\u02e3) :\n \u2191u\u207b\u00b9 = (u\u207b\u00b9 : G) :=\nto_units.symm.map_inv u\n\nvariables [monoid M] [monoid N] [monoid P]\n\n\/-- A multiplicative equivalence of monoids defines a multiplicative equivalence\nof their groups of units. -\/\ndef map_equiv (h : M \u2243* N) : M\u02e3 \u2243* N\u02e3 :=\n{ inv_fun := map h.symm.to_monoid_hom,\n left_inv := \u03bb u, ext $ h.left_inv u,\n right_inv := \u03bb u, ext $ h.right_inv u,\n .. map h.to_monoid_hom }\n\n\/-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -\/\n@[to_additive \"Left addition of an additive unit is a permutation of the underlying type.\",\n simps apply {fully_applied := ff}]\ndef mul_left (u : M\u02e3) : equiv.perm M :=\n{ to_fun := \u03bbx, u * x,\n inv_fun := \u03bbx, \u2191u\u207b\u00b9 * x,\n left_inv := u.inv_mul_cancel_left,\n right_inv := u.mul_inv_cancel_left }\n\n@[simp, to_additive]\nlemma mul_left_symm (u : M\u02e3) : u.mul_left.symm = u\u207b\u00b9.mul_left :=\nequiv.ext $ \u03bb x, rfl\n\n@[to_additive]\nlemma mul_left_bijective (a : M\u02e3) : function.bijective ((*) a : M \u2192 M) :=\n(mul_left a).bijective\n\n\/-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -\/\n@[to_additive \"Right addition of an additive unit is a permutation of the underlying type.\",\n simps apply {fully_applied := ff}]\ndef mul_right (u : M\u02e3) : equiv.perm M :=\n{ to_fun := \u03bbx, x * u,\n inv_fun := \u03bbx, x * \u2191u\u207b\u00b9,\n left_inv := \u03bb x, mul_inv_cancel_right x u,\n right_inv := \u03bb x, inv_mul_cancel_right x u }\n\n@[simp, to_additive]\nlemma mul_right_symm (u : M\u02e3) : u.mul_right.symm = u\u207b\u00b9.mul_right :=\nequiv.ext $ \u03bb x, rfl\n\n@[to_additive]\nlemma mul_right_bijective (a : M\u02e3) : function.bijective ((* a) : M \u2192 M) :=\n(mul_right a).bijective\n\nend units\n\nnamespace equiv\n\nsection has_involutive_neg\n\nvariables (G) [has_involutive_inv G]\n\n\/-- Inversion on a `group` or `group_with_zero` is a permutation of the underlying type. -\/\n@[to_additive \"Negation on an `add_group` is a permutation of the underlying type.\",\n simps apply {fully_applied := ff}]\nprotected def inv : perm G := inv_involutive.to_equiv _\n\nvariable {G}\n\n@[simp, to_additive]\nlemma inv_symm : (equiv.inv G).symm = equiv.inv G := rfl\n\nend has_involutive_neg\n\nsection group\nvariables [group G]\n\n\/-- Left multiplication in a `group` is a permutation of the underlying type. -\/\n@[to_additive \"Left addition in an `add_group` is a permutation of the underlying type.\"]\nprotected def mul_left (a : G) : perm G := (to_units a).mul_left\n\n@[simp, to_additive]\nlemma coe_mul_left (a : G) : \u21d1(equiv.mul_left a) = (*) a := rfl\n\n\/-- extra simp lemma that `dsimp` can use. `simp` will never use this. -\/\n@[simp, nolint simp_nf, to_additive]\nlemma mul_left_symm_apply (a : G) : ((equiv.mul_left a).symm : G \u2192 G) = (*) a\u207b\u00b9 := rfl\n\n@[simp, to_additive]\nlemma mul_left_symm (a : G) : (equiv.mul_left a).symm = equiv.mul_left a\u207b\u00b9 :=\next $ \u03bb x, rfl\n\n@[to_additive]\nlemma _root_.group.mul_left_bijective (a : G) : function.bijective ((*) a) :=\n(equiv.mul_left a).bijective\n\n\/-- Right multiplication in a `group` is a permutation of the underlying type. -\/\n@[to_additive \"Right addition in an `add_group` is a permutation of the underlying type.\"]\nprotected def mul_right (a : G) : perm G := (to_units a).mul_right\n\n@[simp, to_additive]\nlemma coe_mul_right (a : G) : \u21d1(equiv.mul_right a) = \u03bb x, x * a := rfl\n\n@[simp, to_additive]\nlemma mul_right_symm (a : G) : (equiv.mul_right a).symm = equiv.mul_right a\u207b\u00b9 :=\next $ \u03bb x, rfl\n\n\/-- extra simp lemma that `dsimp` can use. `simp` will never use this. -\/\n@[simp, nolint simp_nf, to_additive]\nlemma mul_right_symm_apply (a : G) : ((equiv.mul_right a).symm : G \u2192 G) = \u03bb x, x * a\u207b\u00b9 := rfl\n\n@[to_additive]\nlemma _root_.group.mul_right_bijective (a : G) : function.bijective (* a) :=\n(equiv.mul_right a).bijective\n\n\/-- A version of `equiv.mul_left a b\u207b\u00b9` that is defeq to `a \/ b`. -\/\n@[to_additive \/-\" A version of `equiv.add_left a (-b)` that is defeq to `a - b`. \"-\/, simps]\nprotected def div_left (a : G) : G \u2243 G :=\n{ to_fun := \u03bb b, a \/ b,\n inv_fun := \u03bb b, b\u207b\u00b9 * a,\n left_inv := \u03bb b, by simp [div_eq_mul_inv],\n right_inv := \u03bb b, by simp [div_eq_mul_inv] }\n\n@[to_additive]\nlemma div_left_eq_inv_trans_mul_left (a : G) :\n equiv.div_left a = (equiv.inv G).trans (equiv.mul_left a) :=\next $ \u03bb _, div_eq_mul_inv _ _\n\n\/-- A version of `equiv.mul_right a\u207b\u00b9 b` that is defeq to `b \/ a`. -\/\n@[to_additive \/-\" A version of `equiv.add_right (-a) b` that is defeq to `b - a`. \"-\/, simps]\nprotected def div_right (a : G) : G \u2243 G :=\n{ to_fun := \u03bb b, b \/ a,\n inv_fun := \u03bb b, b * a,\n left_inv := \u03bb b, by simp [div_eq_mul_inv],\n right_inv := \u03bb b, by simp [div_eq_mul_inv] }\n\n@[to_additive]\nlemma div_right_eq_mul_right_inv (a : G) : equiv.div_right a = equiv.mul_right a\u207b\u00b9 :=\next $ \u03bb _, div_eq_mul_inv _ _\n\nend group\n\nsection group_with_zero\nvariables [group_with_zero G]\n\n\/-- Left multiplication by a nonzero element in a `group_with_zero` is a permutation of the\nunderlying type. -\/\n@[simps {fully_applied := ff}]\nprotected def mul_left\u2080 (a : G) (ha : a \u2260 0) : perm G :=\n(units.mk0 a ha).mul_left\n\nlemma _root_.mul_left_bijective\u2080 (a : G) (ha : a \u2260 0) :\n function.bijective ((*) a : G \u2192 G) :=\n(equiv.mul_left\u2080 a ha).bijective\n\n\/-- Right multiplication by a nonzero element in a `group_with_zero` is a permutation of the\nunderlying type. -\/\n@[simps {fully_applied := ff}]\nprotected def mul_right\u2080 (a : G) (ha : a \u2260 0) : perm G :=\n(units.mk0 a ha).mul_right\n\nlemma _root_.mul_right_bijective\u2080 (a : G) (ha : a \u2260 0) :\n function.bijective ((* a) : G \u2192 G) :=\n(equiv.mul_right\u2080 a ha).bijective\n\nend group_with_zero\n\nend equiv\n\n\/-- When the group is commutative, `equiv.inv` is a `mul_equiv`. There is a variant of this\n`mul_equiv.inv' G : G \u2243* G\u1d50\u1d52\u1d56` for the non-commutative case. -\/\n@[to_additive \"When the `add_group` is commutative, `equiv.neg` is an `add_equiv`.\"]\ndef mul_equiv.inv (G : Type*) [comm_group G] : G \u2243* G :=\n{ to_fun := has_inv.inv,\n inv_fun := has_inv.inv,\n map_mul' := mul_inv,\n ..equiv.inv G }\n\n\/-- When the group with zero is commutative, `equiv.inv\u2080` is a `mul_equiv`. -\/\n@[simps apply] def mul_equiv.inv\u2080 (G : Type*) [comm_group_with_zero G] : G \u2243* G :=\n{ to_fun := has_inv.inv,\n inv_fun := has_inv.inv,\n map_mul' := \u03bb x y, mul_inv\u2080,\n ..equiv.inv G }\n\n@[simp] lemma mul_equiv.inv\u2080_symm (G : Type*) [comm_group_with_zero G] :\n (mul_equiv.inv\u2080 G).symm = mul_equiv.inv\u2080 G := rfl\n\nsection type_tags\n\n\/-- Reinterpret `G \u2243+ H` as `multiplicative G \u2243* multiplicative H`. -\/\ndef add_equiv.to_multiplicative [add_zero_class G] [add_zero_class H] :\n (G \u2243+ H) \u2243 (multiplicative G \u2243* multiplicative H) :=\n{ to_fun := \u03bb f, \u27e8f.to_add_monoid_hom.to_multiplicative,\n f.symm.to_add_monoid_hom.to_multiplicative, f.3, f.4, f.5\u27e9,\n inv_fun := \u03bb f, \u27e8f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5\u27e9,\n left_inv := \u03bb x, by { ext, refl, },\n right_inv := \u03bb x, by { ext, refl, }, }\n\n\/-- Reinterpret `G \u2243* H` as `additive G \u2243+ additive H`. -\/\ndef mul_equiv.to_additive [mul_one_class G] [mul_one_class H] :\n (G \u2243* H) \u2243 (additive G \u2243+ additive H) :=\n{ to_fun := \u03bb f, \u27e8f.to_monoid_hom.to_additive, f.symm.to_monoid_hom.to_additive, f.3, f.4, f.5\u27e9,\n inv_fun := \u03bb f, \u27e8f.to_add_monoid_hom, f.symm.to_add_monoid_hom, f.3, f.4, f.5\u27e9,\n left_inv := \u03bb x, by { ext, refl, },\n right_inv := \u03bb x, by { ext, refl, }, }\n\n\/-- Reinterpret `additive G \u2243+ H` as `G \u2243* multiplicative H`. -\/\ndef add_equiv.to_multiplicative' [mul_one_class G] [add_zero_class H] :\n (additive G \u2243+ H) \u2243 (G \u2243* multiplicative H) :=\n{ to_fun := \u03bb f, \u27e8f.to_add_monoid_hom.to_multiplicative',\n f.symm.to_add_monoid_hom.to_multiplicative'', f.3, f.4, f.5\u27e9,\n inv_fun := \u03bb f, \u27e8f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5\u27e9,\n left_inv := \u03bb x, by { ext, refl, },\n right_inv := \u03bb x, by { ext, refl, }, }\n\n\/-- Reinterpret `G \u2243* multiplicative H` as `additive G \u2243+ H` as. -\/\ndef mul_equiv.to_additive' [mul_one_class G] [add_zero_class H] :\n (G \u2243* multiplicative H) \u2243 (additive G \u2243+ H) :=\nadd_equiv.to_multiplicative'.symm\n\n\/-- Reinterpret `G \u2243+ additive H` as `multiplicative G \u2243* H`. -\/\ndef add_equiv.to_multiplicative'' [add_zero_class G] [mul_one_class H] :\n (G \u2243+ additive H) \u2243 (multiplicative G \u2243* H) :=\n{ to_fun := \u03bb f, \u27e8f.to_add_monoid_hom.to_multiplicative'',\n f.symm.to_add_monoid_hom.to_multiplicative', f.3, f.4, f.5\u27e9,\n inv_fun := \u03bb f, \u27e8f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5\u27e9,\n left_inv := \u03bb x, by { ext, refl, },\n right_inv := \u03bb x, by { ext, refl, }, }\n\n\/-- Reinterpret `multiplicative G \u2243* H` as `G \u2243+ additive H` as. -\/\ndef mul_equiv.to_additive'' [add_zero_class G] [mul_one_class H] :\n (multiplicative G \u2243* H) \u2243 (G \u2243+ additive H) :=\nadd_equiv.to_multiplicative''.symm\n\nend type_tags\n","avg_line_length":37.540960452,"max_line_length":100,"alphanum_fraction":0.6573234508} -{"size":319,"ext":"lean","lang":"Lean","max_stars_count":4.0,"content":"import Lake\nopen Lake DSL\n\npackage scripts\n\n\/--\nDisplay a greeting\n\nUSAGE:\n lake run greet [name]\n\nGreet the entity with the given name. Otherwise, greet the whole world.\n-\/\nscript greet (args) do\n if h : 0 < args.length then\n IO.println s!\"Hello, {args.get 0 h}!\"\n else\n IO.println \"Hello, world!\"\n return 0\n","avg_line_length":15.95,"max_line_length":71,"alphanum_fraction":0.6833855799} -{"size":594,"ext":"lean","lang":"Lean","max_stars_count":11.0,"content":"import DocGen4.Output.Template\nimport DocGen4.Output.DocString\nimport DocGen4.Process\n\nnamespace DocGen4\nnamespace Output\n\nopen scoped DocGen4.Jsx\n\ndef ctorToHtml (i : Process.NameInfo) : HtmlM Html := do\n let shortName := i.name.components'.head!.toString\n let name := i.name.toString\n pure
  • {shortName} : [\u2190infoFormatToHtml i.type]<\/li>\n\ndef inductiveToHtml (i : Process.InductiveInfo) : HtmlM (Array Html) := do\n let constructorsHtml :=