blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
7
139
content_id
stringlengths
40
40
detected_licenses
listlengths
0
16
license_type
stringclasses
2 values
repo_name
stringlengths
7
55
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
6 values
visit_date
int64
1,471B
1,694B
revision_date
int64
1,378B
1,694B
committer_date
int64
1,378B
1,694B
github_id
float64
1.33M
604M
βŒ€
star_events_count
int64
0
43.5k
fork_events_count
int64
0
1.5k
gha_license_id
stringclasses
6 values
gha_event_created_at
int64
1,402B
1,695B
βŒ€
gha_created_at
int64
1,359B
1,637B
βŒ€
gha_language
stringclasses
19 values
src_encoding
stringclasses
2 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
1 class
length_bytes
int64
3
6.4M
extension
stringclasses
4 values
content
stringlengths
3
6.12M
702f42fe8a2a856d4ee56524f390ed4a5fc54d78
76df16d6c3760cb415f1294caee997cc4736e09b
/lean/src/op/simp.lean
cb690f2e99bce0b5fd14696d57c2e7f21a49e040
[ "MIT" ]
permissive
uw-unsat/leanette-popl22-artifact
70409d9cbd8921d794d27b7992bf1d9a4087e9fe
80fea2519e61b45a283fbf7903acdf6d5528dbe7
refs/heads/master
1,681,592,449,670
1,637,037,431,000
1,637,037,431,000
414,331,908
6
1
null
null
null
null
UTF-8
Lean
false
false
163
lean
import .sym import data.subtype namespace op.sym run_cmd mk_simp_attr `term_is_true attribute [term_is_true] term.is_true term.eval lit.to_bool end op.sym
2eec6df9e31a921abbd4819b21170265708d3a35
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/t1.lean
3b8b79674f3d83351fcc2f37e0aa8a7c296da905
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
334
lean
prelude definition Prop : Type.{1} := Type.{0} print raw ((Prop)) print raw Prop print raw fun (x y : Prop), x x print raw fun (x y : Prop) {z : Prop}, x y print raw Ξ» [x : Prop] [y : Prop] {z : Prop}, x z print raw Pi (x y : Prop) {z : Prop}, x print raw βˆ€ (x y : Prop) {z : Prop}, x print raw forall {x y : Prop} w {z : Prop}, x
d729b3fc0b65a8af7e5c5c78530927046085afe3
e63bde1648bdfa54c017c4a787f5a73637f26459
/src/mockup.lean
02398ff1d7d2acf8142eb17e63461d0fbf18fade
[]
no_license
jcommelin/zkprfcrt
c03b9027937198c75a189322d1cef9356ecaa791
e1047719eeee24c0a3a2b07a498015e7a7fba96c
refs/heads/master
1,585,751,982,815
1,539,670,378,000
1,539,670,378,000
153,302,877
0
0
null
null
null
null
UTF-8
Lean
false
false
496
lean
def certificate : Type := sorry def gen_prf_crt (P : Prop) (p : P) : certificate := sorry def ver_prf_crt (P : Prop) (c : certificate) : bool := sorry lemma correctness (P : Prop) (p : P) : ver_prf_crt P (gen_prf_crt P p) = true := sorry -- "lemma" integrity (P : Prop) : -- it_is_hard_to_find (c : certificate) -- such_that (ver_prf_crt P c = true) := sorry -- "lemma" zero_knowledge (P : Prop) (c : certificate) -- (h : ver_prf_crt P c = true) : -- gives_no_knowledge_about_a_proof_of P
750c002b96a9e6b4d14a25dce006e1440b1da2f4
94e33a31faa76775069b071adea97e86e218a8ee
/src/algebraic_geometry/open_immersion.lean
c8f5a8b7251dd547f0234c1f75765b989a095176
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
72,503
lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import algebraic_geometry.presheafed_space.has_colimits import category_theory.limits.shapes.binary_products import category_theory.limits.preserves.shapes.pullbacks import topology.sheaves.functors import algebraic_geometry.Scheme import category_theory.limits.shapes.strict_initial import algebra.category.Ring.instances /-! # Open immersions of structured spaces We say that a morphism of presheafed spaces `f : X ⟢ Y` is an open immersions if the underlying map of spaces is an open embedding `f : X ⟢ U βŠ† Y`, and the sheaf map `Y(V) ⟢ f _* X(V)` is an iso for each `V βŠ† U`. Abbreviations are also provided for `SheafedSpace`, `LocallyRingedSpace` and `Scheme`. ## Main definitions * `algebraic_geometry.PresheafedSpace.is_open_immersion`: the `Prop`-valued typeclass asserting that a PresheafedSpace hom `f` is an open_immersion. * `algebraic_geometry.is_open_immersion`: the `Prop`-valued typeclass asserting that a Scheme morphism `f` is an open_immersion. * `algebraic_geometry.PresheafedSpace.is_open_immersion.iso_restrict`: The source of an open immersion is isomorphic to the restriction of the target onto the image. * `algebraic_geometry.PresheafedSpace.is_open_immersion.lift`: Any morphism whose range is contained in an open immersion factors though the open immersion. * `algebraic_geometry.PresheafedSpace.is_open_immersion.to_SheafedSpace`: If `f : X ⟢ Y` is an open immersion of presheafed spaces, and `Y` is a sheafed space, then `X` is also a sheafed space. The morphism as morphisms of sheafed spaces is given by `to_SheafedSpace_hom`. * `algebraic_geometry.PresheafedSpace.is_open_immersion.to_LocallyRingedSpace`: If `f : X ⟢ Y` is an open immersion of presheafed spaces, and `Y` is a locally ringed space, then `X` is also a locally ringed space. The morphism as morphisms of locally ringed spaces is given by `to_LocallyRingedSpace_hom`. ## Main results * `algebraic_geometry.PresheafedSpace.is_open_immersion.comp`: The composition of two open immersions is an open immersion. * `algebraic_geometry.PresheafedSpace.is_open_immersion.of_iso`: An iso is an open immersion. * `algebraic_geometry.PresheafedSpace.is_open_immersion.to_iso`: A surjective open immersion is an isomorphism. * `algebraic_geometry.PresheafedSpace.is_open_immersion.stalk_iso`: An open immersion induces an isomorphism on stalks. * `algebraic_geometry.PresheafedSpace.is_open_immersion.has_pullback_of_left`: If `f` is an open immersion, then the pullback `(f, g)` exists (and the forgetful functor to `Top` preserves it). * `algebraic_geometry.PresheafedSpace.is_open_immersion.pullback_snd_of_left`: Open immersions are stable under pullbacks. * `algebraic_geometry.SheafedSpace.is_open_immersion.of_stalk_iso` An (topological) open embedding between two sheafed spaces is an open immersion if all the stalk maps are isomorphisms. -/ open topological_space category_theory opposite open category_theory.limits namespace algebraic_geometry universes v v₁ vβ‚‚ u variables {C : Type u} [category.{v} C] /-- An open immersion of PresheafedSpaces is an open embedding `f : X ⟢ U βŠ† Y` of the underlying spaces, such that the sheaf map `Y(V) ⟢ f _* X(V)` is an iso for each `V βŠ† U`. -/ class PresheafedSpace.is_open_immersion {X Y : PresheafedSpace.{v} C} (f : X ⟢ Y) : Prop := (base_open : open_embedding f.base) (c_iso : βˆ€ U : opens X, is_iso (f.c.app (op (base_open.is_open_map.functor.obj U)))) /-- A morphism of SheafedSpaces is an open immersion if it is an open immersion as a morphism of PresheafedSpaces -/ abbreviation SheafedSpace.is_open_immersion [has_products.{v} C] {X Y : SheafedSpace.{v} C} (f : X ⟢ Y) : Prop := PresheafedSpace.is_open_immersion f /-- A morphism of LocallyRingedSpaces is an open immersion if it is an open immersion as a morphism of SheafedSpaces -/ abbreviation LocallyRingedSpace.is_open_immersion {X Y : LocallyRingedSpace} (f : X ⟢ Y) : Prop := SheafedSpace.is_open_immersion f.1 /-- A morphism of Schemes is an open immersion if it is an open immersion as a morphism of LocallyRingedSpaces -/ abbreviation is_open_immersion {X Y : Scheme} (f : X ⟢ Y) : Prop := LocallyRingedSpace.is_open_immersion f namespace PresheafedSpace.is_open_immersion open PresheafedSpace local notation `is_open_immersion` := PresheafedSpace.is_open_immersion attribute [instance] is_open_immersion.c_iso section variables {X Y : PresheafedSpace.{v} C} {f : X ⟢ Y} (H : is_open_immersion f) /-- The functor `opens X β₯€ opens Y` associated with an open immersion `f : X ⟢ Y`. -/ abbreviation open_functor := H.base_open.is_open_map.functor /-- An open immersion `f : X ⟢ Y` induces an isomorphism `X β‰… Y|_{f(X)}`. -/ @[simps] noncomputable def iso_restrict : X β‰… Y.restrict H.base_open := PresheafedSpace.iso_of_components (iso.refl _) begin symmetry, fapply nat_iso.of_components, intro U, refine as_iso (f.c.app (op (H.open_functor.obj (unop U)))) β‰ͺ≫ X.presheaf.map_iso (eq_to_iso _), { induction U using opposite.rec, cases U, dsimp only [is_open_map.functor, functor.op, opens.map], congr' 2, erw set.preimage_image_eq _ H.base_open.inj, refl }, { intros U V i, simp only [category_theory.eq_to_iso.hom, Top.presheaf.pushforward_obj_map, category.assoc, functor.op_map, iso.trans_hom, as_iso_hom, functor.map_iso_hom, ←X.presheaf.map_comp], erw [f.c.naturality_assoc, ←X.presheaf.map_comp], congr } end @[simp] lemma iso_restrict_hom_of_restrict : H.iso_restrict.hom ≫ Y.of_restrict _ = f := begin ext, { simp only [comp_c_app, iso_restrict_hom_c_app, nat_trans.comp_app, eq_to_hom_refl, of_restrict_c_app, category.assoc, whisker_right_id'], erw [category.comp_id, f.c.naturality_assoc, ←X.presheaf.map_comp], transitivity f.c.app x ≫ X.presheaf.map (πŸ™ _), { congr }, { erw [X.presheaf.map_id, category.comp_id] } }, { simp } end @[simp] lemma iso_restrict_inv_of_restrict : H.iso_restrict.inv ≫ f = Y.of_restrict _ := by { rw iso.inv_comp_eq, simp } instance mono [H : is_open_immersion f] : mono f := by { rw ← H.iso_restrict_hom_of_restrict, apply mono_comp } /-- The composition of two open immersions is an open immersion. -/ instance comp {Z : PresheafedSpace C} (f : X ⟢ Y) [hf : is_open_immersion f] (g : Y ⟢ Z) [hg : is_open_immersion g] : is_open_immersion (f ≫ g) := { base_open := hg.base_open.comp hf.base_open, c_iso := Ξ» U, begin generalize_proofs h, dsimp only [algebraic_geometry.PresheafedSpace.comp_c_app, unop_op, functor.op, comp_base, Top.presheaf.pushforward_obj_obj, opens.map_comp_obj], apply_with is_iso.comp_is_iso { instances := ff }, swap, { have : (opens.map g.base).obj (h.functor.obj U) = hf.open_functor.obj U, { dsimp only [opens.map, is_open_map.functor, PresheafedSpace.comp_base], congr' 1, rw [coe_comp, ←set.image_image, set.preimage_image_eq _ hg.base_open.inj] }, rw this, apply_instance }, { have : h.functor.obj U = hg.open_functor.obj (hf.open_functor.obj U), { dsimp only [is_open_map.functor], congr' 1, rw [comp_base, coe_comp, ←set.image_image], congr }, rw this, apply_instance } end } /-- For an open immersion `f : X ⟢ Y` and an open set `U βŠ† X`, we have the map `X(U) ⟢ Y(U)`. -/ noncomputable def inv_app (U : opens X) : X.presheaf.obj (op U) ⟢ Y.presheaf.obj (op (H.open_functor.obj U)) := X.presheaf.map (eq_to_hom (by simp [opens.map, set.preimage_image_eq _ H.base_open.inj])) ≫ inv (f.c.app (op (H.open_functor.obj U))) @[simp, reassoc] lemma inv_naturality {U V : (opens X)α΅’α΅–} (i : U ⟢ V) : X.presheaf.map i ≫ H.inv_app (unop V) = H.inv_app (unop U) ≫ Y.presheaf.map (H.open_functor.op.map i) := begin simp only [inv_app, ←category.assoc], rw [is_iso.comp_inv_eq], simp only [category.assoc, f.c.naturality, is_iso.inv_hom_id_assoc, ← X.presheaf.map_comp], erw ← X.presheaf.map_comp, congr end instance (U : opens X) : is_iso (H.inv_app U) := by { delta inv_app, apply_instance } lemma inv_inv_app (U : opens X) : inv (H.inv_app U) = f.c.app (op (H.open_functor.obj U)) ≫ X.presheaf.map (eq_to_hom (by simp [opens.map, set.preimage_image_eq _ H.base_open.inj])) := begin rw ← cancel_epi (H.inv_app U), rw is_iso.hom_inv_id, delta inv_app, simp [← functor.map_comp] end @[simp, reassoc, elementwise] lemma inv_app_app (U : opens X) : H.inv_app U ≫ f.c.app (op (H.open_functor.obj U)) = X.presheaf.map (eq_to_hom (by simp [opens.map, set.preimage_image_eq _ H.base_open.inj])) := by rw [inv_app, category.assoc, is_iso.inv_hom_id, category.comp_id] @[simp, reassoc] lemma app_inv_app (U : opens Y) : f.c.app (op U) ≫ H.inv_app ((opens.map f.base).obj U) = Y.presheaf.map ((hom_of_le (by exact set.image_preimage_subset f.base U)).op : op U ⟢ op (H.open_functor.obj ((opens.map f.base).obj U))) := by { erw ← category.assoc, rw [is_iso.comp_inv_eq, f.c.naturality], congr } /-- A variant of `app_inv_app` that gives an `eq_to_hom` instead of `hom_of_le`. -/ @[reassoc] lemma app_inv_app' (U : opens Y) (hU : (U : set Y) βŠ† set.range f.base) : f.c.app (op U) ≫ H.inv_app ((opens.map f.base).obj U) = Y.presheaf.map (eq_to_hom (by { apply has_le.le.antisymm, { exact set.image_preimage_subset f.base U.1 }, { change U βŠ† _, refine has_le.le.trans_eq _ (@set.image_preimage_eq_inter_range _ _ f.base U.1).symm, exact set.subset_inter_iff.mpr ⟨λ _ h, h, hU⟩ } })).op := by { erw ← category.assoc, rw [is_iso.comp_inv_eq, f.c.naturality], congr } /-- An isomorphism is an open immersion. -/ instance of_iso {X Y : PresheafedSpace.{v} C} (H : X β‰… Y) : is_open_immersion H.hom := { base_open := (Top.homeo_of_iso ((forget C).map_iso H)).open_embedding, c_iso := Ξ» _, infer_instance } @[priority 100] instance of_is_iso {X Y : PresheafedSpace.{v} C} (f : X ⟢ Y) [is_iso f] : is_open_immersion f := algebraic_geometry.PresheafedSpace.is_open_immersion.of_iso (as_iso f) instance of_restrict {X : Top} (Y : PresheafedSpace C) {f : X ⟢ Y.carrier} (hf : open_embedding f) : is_open_immersion (Y.of_restrict hf) := { base_open := hf, c_iso := Ξ» U, begin dsimp, have : (opens.map f).obj (hf.is_open_map.functor.obj U) = U, { cases U, dsimp only [opens.map, is_open_map.functor], congr' 1, rw set.preimage_image_eq _ hf.inj, refl }, convert (show is_iso (Y.presheaf.map (πŸ™ _)), from infer_instance), { apply subsingleton.helim, rw this }, { rw Y.presheaf.map_id, apply_instance } end } @[elementwise, simp] lemma of_restrict_inv_app {C : Type*} [category C] (X : PresheafedSpace C) {Y : Top} {f : Y ⟢ Top.of X.carrier} (h : open_embedding f) (U : opens (X.restrict h).carrier) : (PresheafedSpace.is_open_immersion.of_restrict X h).inv_app U = πŸ™ _ := begin delta PresheafedSpace.is_open_immersion.inv_app, rw [is_iso.comp_inv_eq, category.id_comp], change X.presheaf.map _ = X.presheaf.map _, congr end /-- An open immersion is an iso if the underlying continuous map is epi. -/ lemma to_iso (f : X ⟢ Y) [h : is_open_immersion f] [h' : epi f.base] : is_iso f := begin apply_with is_iso_of_components { instances := ff }, { let : X β‰ƒβ‚œ Y := (homeomorph.of_embedding _ h.base_open.to_embedding).trans { to_fun := subtype.val, inv_fun := Ξ» x, ⟨x, by { rw set.range_iff_surjective.mpr ((Top.epi_iff_surjective _).mp h'), trivial }⟩, left_inv := Ξ» ⟨_,_⟩, rfl, right_inv := Ξ» _, rfl }, convert is_iso.of_iso (Top.iso_of_homeo this), { ext, refl } }, { apply_with nat_iso.is_iso_of_is_iso_app { instances := ff }, intro U, have : U = op (h.open_functor.obj ((opens.map f.base).obj (unop U))), { induction U using opposite.rec, cases U, dsimp only [functor.op, opens.map], congr, exact (set.image_preimage_eq _ ((Top.epi_iff_surjective _).mp h')).symm }, convert @@is_open_immersion.c_iso _ h ((opens.map f.base).obj (unop U)) } end instance stalk_iso [has_colimits C] [H : is_open_immersion f] (x : X) : is_iso (stalk_map f x) := begin rw ← H.iso_restrict_hom_of_restrict, rw PresheafedSpace.stalk_map.comp, apply_instance end end section pullback noncomputable theory variables {X Y Z : PresheafedSpace.{v} C} (f : X ⟢ Z) [hf : is_open_immersion f] (g : Y ⟢ Z) include hf /-- (Implementation.) The projection map when constructing the pullback along an open immersion. -/ def pullback_cone_of_left_fst : Y.restrict (Top.snd_open_embedding_of_left_open_embedding hf.base_open g.base) ⟢ X := { base := pullback.fst, c := { app := Ξ» U, hf.inv_app (unop U) ≫ g.c.app (op (hf.base_open.is_open_map.functor.obj (unop U))) ≫ Y.presheaf.map (eq_to_hom (begin simp only [is_open_map.functor, subtype.mk_eq_mk, unop_op, op_inj_iff, opens.map, subtype.coe_mk, functor.op_obj, subtype.val_eq_coe], apply has_le.le.antisymm, { rintros _ ⟨_, h₁, hβ‚‚βŸ©, use (Top.pullback_iso_prod_subtype _ _).inv ⟨⟨_, _⟩, hβ‚‚βŸ©, simpa using h₁ }, { rintros _ ⟨x, h₁, rfl⟩, exact ⟨_, h₁, concrete_category.congr_hom pullback.condition x⟩ } end)), naturality' := begin intros U V i, induction U using opposite.rec, induction V using opposite.rec, simp only [quiver.hom.unop_op, Top.presheaf.pushforward_obj_map, category.assoc, nat_trans.naturality_assoc, functor.op_map, inv_naturality_assoc, ← Y.presheaf.map_comp], erw ← Y.presheaf.map_comp, congr end } } lemma pullback_cone_of_left_condition : pullback_cone_of_left_fst f g ≫ f = Y.of_restrict _ ≫ g := begin ext U, { induction U using opposite.rec, dsimp only [comp_c_app, nat_trans.comp_app, unop_op, whisker_right_app, pullback_cone_of_left_fst], simp only [quiver.hom.unop_op, Top.presheaf.pushforward_obj_map, app_inv_app_assoc, eq_to_hom_app, eq_to_hom_unop, category.assoc, nat_trans.naturality_assoc, functor.op_map], erw [← Y.presheaf.map_comp, ← Y.presheaf.map_comp], congr }, { simpa using pullback.condition } end /-- We construct the pullback along an open immersion via restricting along the pullback of the maps of underlying spaces (which is also an open embedding). -/ def pullback_cone_of_left : pullback_cone f g := pullback_cone.mk (pullback_cone_of_left_fst f g) (Y.of_restrict _) (pullback_cone_of_left_condition f g) variable (s : pullback_cone f g) /-- (Implementation.) Any cone over `cospan f g` indeed factors through the constructed cone. -/ def pullback_cone_of_left_lift : s.X ⟢ (pullback_cone_of_left f g).X := { base := pullback.lift s.fst.base s.snd.base (congr_arg (Ξ» x, PresheafedSpace.hom.base x) s.condition), c := { app := Ξ» U, s.snd.c.app _ ≫ s.X.presheaf.map (eq_to_hom (begin dsimp only [opens.map, is_open_map.functor, functor.op], congr' 2, let s' : pullback_cone f.base g.base := pullback_cone.mk s.fst.base s.snd.base _, have : _ = s.snd.base := limit.lift_Ο€ s' walking_cospan.right, conv_lhs { erw ← this, rw coe_comp, erw ← set.preimage_preimage }, erw set.preimage_image_eq _ (Top.snd_open_embedding_of_left_open_embedding hf.base_open g.base).inj, simp, end)), naturality' := Ξ» U V i, begin erw s.snd.c.naturality_assoc, rw category.assoc, erw [← s.X.presheaf.map_comp, ← s.X.presheaf.map_comp], congr end } } -- this lemma is not a `simp` lemma, because it is an implementation detail lemma pullback_cone_of_left_lift_fst : pullback_cone_of_left_lift f g s ≫ (pullback_cone_of_left f g).fst = s.fst := begin ext x, { induction x using opposite.rec, change ((_ ≫ _) ≫ _ ≫ _) ≫ _ = _, simp_rw [category.assoc], erw ← s.X.presheaf.map_comp, erw s.snd.c.naturality_assoc, have := congr_app s.condition (op (hf.open_functor.obj x)), dsimp only [comp_c_app, unop_op] at this, rw ← is_iso.comp_inv_eq at this, reassoc! this, erw [← this, hf.inv_app_app_assoc, s.fst.c.naturality_assoc], simpa [eq_to_hom_map], }, { change pullback.lift _ _ _ ≫ pullback.fst = _, simp } end -- this lemma is not a `simp` lemma, because it is an implementation detail lemma pullback_cone_of_left_lift_snd : pullback_cone_of_left_lift f g s ≫ (pullback_cone_of_left f g).snd = s.snd := begin ext x, { change (_ ≫ _ ≫ _) ≫ _ = _, simp_rw category.assoc, erw s.snd.c.naturality_assoc, erw [← s.X.presheaf.map_comp, ← s.X.presheaf.map_comp], transitivity s.snd.c.app x ≫ s.X.presheaf.map (πŸ™ _), { congr }, { rw s.X.presheaf.map_id, erw category.comp_id } }, { change pullback.lift _ _ _ ≫ pullback.snd = _, simp } end instance pullback_cone_snd_is_open_immersion : is_open_immersion (pullback_cone_of_left f g).snd := begin erw category_theory.limits.pullback_cone.mk_snd, apply_instance end /-- The constructed pullback cone is indeed the pullback. -/ def pullback_cone_of_left_is_limit : is_limit (pullback_cone_of_left f g) := begin apply pullback_cone.is_limit_aux', intro s, use pullback_cone_of_left_lift f g s, use pullback_cone_of_left_lift_fst f g s, use pullback_cone_of_left_lift_snd f g s, intros m h₁ hβ‚‚, rw ← cancel_mono (pullback_cone_of_left f g).snd, exact (hβ‚‚.trans (pullback_cone_of_left_lift_snd f g s).symm) end instance has_pullback_of_left : has_pullback f g := ⟨⟨⟨_, pullback_cone_of_left_is_limit f g⟩⟩⟩ instance has_pullback_of_right : has_pullback g f := has_pullback_symmetry f g /-- Open immersions are stable under base-change. -/ instance pullback_snd_of_left : is_open_immersion (pullback.snd : pullback f g ⟢ _) := begin delta pullback.snd, rw ← limit.iso_limit_cone_hom_Ο€ ⟨_, pullback_cone_of_left_is_limit f g⟩ walking_cospan.right, apply_instance end /-- Open immersions are stable under base-change. -/ instance pullback_fst_of_right : is_open_immersion (pullback.fst : pullback g f ⟢ _) := begin rw ← pullback_symmetry_hom_comp_snd, apply_instance end instance pullback_to_base_is_open_immersion [is_open_immersion g] : is_open_immersion (limit.Ο€ (cospan f g) walking_cospan.one) := begin rw [←limit.w (cospan f g) walking_cospan.hom.inl, cospan_map_inl], apply_instance end instance forget_preserves_limits_of_left : preserves_limit (cospan f g) (forget C) := preserves_limit_of_preserves_limit_cone (pullback_cone_of_left_is_limit f g) begin apply (is_limit.postcompose_hom_equiv (diagram_iso_cospan.{v} _) _).to_fun, refine (is_limit.equiv_iso_limit _).to_fun (limit.is_limit (cospan f.base g.base)), fapply cones.ext, exact (iso.refl _), change βˆ€ j, _ = πŸ™ _ ≫ _ ≫ _, simp_rw category.id_comp, rintros (_|_|_); symmetry, { erw category.comp_id, exact limit.w (cospan f.base g.base) walking_cospan.hom.inl }, { exact category.comp_id _ }, { exact category.comp_id _ }, end instance forget_preserves_limits_of_right : preserves_limit (cospan g f) (forget C) := preserves_pullback_symmetry (forget C) f g lemma pullback_snd_is_iso_of_range_subset (H : set.range g.base βŠ† set.range f.base) : is_iso (pullback.snd : pullback f g ⟢ _) := begin haveI := Top.snd_iso_of_left_embedding_range_subset hf.base_open.to_embedding g.base H, haveI : is_iso (pullback.snd : pullback f g ⟢ _).base, { delta pullback.snd, rw ← limit.iso_limit_cone_hom_Ο€ ⟨_, pullback_cone_of_left_is_limit f g⟩ walking_cospan.right, change is_iso (_ ≫ pullback.snd), apply_instance }, apply to_iso end /-- The universal property of open immersions: For an open immersion `f : X ⟢ Z`, given any morphism of schemes `g : Y ⟢ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟢ X` that commutes with these maps. -/ def lift (H : set.range g.base βŠ† set.range f.base) : Y ⟢ X := begin haveI := pullback_snd_is_iso_of_range_subset f g H, exact inv (pullback.snd : pullback f g ⟢ _) ≫ pullback.fst, end @[simp, reassoc] lemma lift_fac (H : set.range g.base βŠ† set.range f.base) : lift f g H ≫ f = g := by { erw category.assoc, rw is_iso.inv_comp_eq, exact pullback.condition } lemma lift_uniq (H : set.range g.base βŠ† set.range f.base) (l : Y ⟢ X) (hl : l ≫ f = g) : l = lift f g H := by rw [← cancel_mono f, hl, lift_fac] /-- Two open immersions with equal range is isomorphic. -/ @[simps] def iso_of_range_eq [is_open_immersion g] (e : set.range f.base = set.range g.base) : X β‰… Y := { hom := lift g f (le_of_eq e), inv := lift f g (le_of_eq e.symm), hom_inv_id' := by { rw ← cancel_mono f, simp }, inv_hom_id' := by { rw ← cancel_mono g, simp } } end pullback open category_theory.limits.walking_cospan section to_SheafedSpace variables [has_products.{v} C] {X : PresheafedSpace.{v} C} (Y : SheafedSpace C) variables (f : X ⟢ Y.to_PresheafedSpace) [H : is_open_immersion f] include H /-- If `X ⟢ Y` is an open immersion, and `Y` is a SheafedSpace, then so is `X`. -/ def to_SheafedSpace : SheafedSpace C := { is_sheaf := begin apply Top.presheaf.is_sheaf_of_iso (sheaf_iso_of_iso H.iso_restrict.symm).symm, apply Top.sheaf.pushforward_sheaf_of_sheaf, exact (Y.restrict H.base_open).is_sheaf end, to_PresheafedSpace := X } @[simp] lemma to_SheafedSpace_to_PresheafedSpace : (to_SheafedSpace Y f).to_PresheafedSpace = X := rfl /-- If `X ⟢ Y` is an open immersion of PresheafedSpaces, and `Y` is a SheafedSpace, we can upgrade it into a morphism of SheafedSpaces. -/ def to_SheafedSpace_hom : to_SheafedSpace Y f ⟢ Y := f @[simp] lemma to_SheafedSpace_hom_base : (to_SheafedSpace_hom Y f).base = f.base := rfl @[simp] lemma to_SheafedSpace_hom_c : (to_SheafedSpace_hom Y f).c = f.c := rfl instance to_SheafedSpace_is_open_immersion : SheafedSpace.is_open_immersion (to_SheafedSpace_hom Y f) := H omit H @[simp] lemma SheafedSpace_to_SheafedSpace {X Y : SheafedSpace.{v} C} (f : X ⟢ Y) [is_open_immersion f] : to_SheafedSpace Y f = X := by unfreezingI { cases X, refl } end to_SheafedSpace section to_LocallyRingedSpace variables {X : PresheafedSpace.{u} CommRing.{u}} (Y : LocallyRingedSpace.{u}) variables (f : X ⟢ Y.to_PresheafedSpace) [H : is_open_immersion f] include H /-- If `X ⟢ Y` is an open immersion, and `Y` is a LocallyRingedSpace, then so is `X`. -/ def to_LocallyRingedSpace : LocallyRingedSpace := { to_SheafedSpace := to_SheafedSpace Y.to_SheafedSpace f, local_ring := Ξ» x, begin haveI : local_ring (Y.to_SheafedSpace.to_PresheafedSpace.stalk (f.base x)) := Y.local_ring _, exact (as_iso (stalk_map f x)).CommRing_iso_to_ring_equiv.local_ring end } @[simp] lemma to_LocallyRingedSpace_to_SheafedSpace : (to_LocallyRingedSpace Y f).to_SheafedSpace = (to_SheafedSpace Y.1 f) := rfl /-- If `X ⟢ Y` is an open immersion of PresheafedSpaces, and `Y` is a LocallyRingedSpace, we can upgrade it into a morphism of LocallyRingedSpace. -/ def to_LocallyRingedSpace_hom : to_LocallyRingedSpace Y f ⟢ Y := ⟨f, Ξ» x, infer_instance⟩ @[simp] lemma to_LocallyRingedSpace_hom_val : (to_LocallyRingedSpace_hom Y f).val = f := rfl instance to_LocallyRingedSpace_is_open_immersion : LocallyRingedSpace.is_open_immersion (to_LocallyRingedSpace_hom Y f) := H omit H @[simp] lemma LocallyRingedSpace_to_LocallyRingedSpace {X Y : LocallyRingedSpace} (f : X ⟢ Y) [LocallyRingedSpace.is_open_immersion f] : @to_LocallyRingedSpace X.to_PresheafedSpace Y (@@coe (@@coe_to_lift (@@coe_base coe_subtype)) f) (show is_open_immersion f.val, by apply_instance) = X := by unfreezingI { cases X, delta to_LocallyRingedSpace, simp } end to_LocallyRingedSpace lemma is_iso_of_subset {X Y : PresheafedSpace.{v} C} (f : X ⟢ Y) [H : PresheafedSpace.is_open_immersion f] (U : opens Y.carrier) (hU : (U : set Y.carrier) βŠ† set.range f.base) : is_iso (f.c.app $ op U) := begin have : U = H.base_open.is_open_map.functor.obj ((opens.map f.base).obj U), { ext1, exact (set.inter_eq_left_iff_subset.mpr hU).symm.trans set.image_preimage_eq_inter_range.symm }, convert PresheafedSpace.is_open_immersion.c_iso ((opens.map f.base).obj U), end end PresheafedSpace.is_open_immersion namespace SheafedSpace.is_open_immersion variables [has_products.{v} C] @[priority 100] instance of_is_iso {X Y : SheafedSpace.{v} C} (f : X ⟢ Y) [is_iso f] : SheafedSpace.is_open_immersion f := @@PresheafedSpace.is_open_immersion.of_is_iso _ f (SheafedSpace.forget_to_PresheafedSpace.map_is_iso _) instance comp {X Y Z : SheafedSpace C} (f : X ⟢ Y) (g : Y ⟢ Z) [SheafedSpace.is_open_immersion f] [SheafedSpace.is_open_immersion g] : SheafedSpace.is_open_immersion (f ≫ g) := PresheafedSpace.is_open_immersion.comp f g section pullback variables {X Y Z : SheafedSpace C} (f : X ⟢ Z) (g : Y ⟢ Z) variable [H : SheafedSpace.is_open_immersion f] include H local notation `forget` := SheafedSpace.forget_to_PresheafedSpace open category_theory.limits.walking_cospan instance : mono f := forget .mono_of_mono_map (show @mono (PresheafedSpace C) _ _ _ f, by apply_instance) instance forget_map_is_open_immersion : PresheafedSpace.is_open_immersion (forget .map f) := ⟨H.base_open, H.c_iso⟩ instance has_limit_cospan_forget_of_left : has_limit (cospan f g β‹™ forget) := begin apply has_limit_of_iso (diagram_iso_cospan.{v} _).symm, change has_limit (cospan (forget .map f) (forget .map g)), apply_instance end instance has_limit_cospan_forget_of_left' : has_limit (cospan ((cospan f g β‹™ forget).map hom.inl) ((cospan f g β‹™ forget).map hom.inr)) := show has_limit (cospan (forget .map f) (forget .map g)), from infer_instance instance has_limit_cospan_forget_of_right : has_limit (cospan g f β‹™ forget) := begin apply has_limit_of_iso (diagram_iso_cospan.{v} _).symm, change has_limit (cospan (forget .map g) (forget .map f)), apply_instance end instance has_limit_cospan_forget_of_right' : has_limit (cospan ((cospan g f β‹™ forget).map hom.inl) ((cospan g f β‹™ forget).map hom.inr)) := show has_limit (cospan (forget .map g) (forget .map f)), from infer_instance instance forget_creates_pullback_of_left : creates_limit (cospan f g) forget := creates_limit_of_fully_faithful_of_iso (PresheafedSpace.is_open_immersion.to_SheafedSpace Y (@pullback.snd (PresheafedSpace C) _ _ _ _ f g _)) (eq_to_iso (show pullback _ _ = pullback _ _, by congr) β‰ͺ≫ has_limit.iso_of_nat_iso (diagram_iso_cospan _).symm) instance forget_creates_pullback_of_right : creates_limit (cospan g f) forget := creates_limit_of_fully_faithful_of_iso (PresheafedSpace.is_open_immersion.to_SheafedSpace Y (@pullback.fst (PresheafedSpace C) _ _ _ _ g f _)) (eq_to_iso (show pullback _ _ = pullback _ _, by congr) β‰ͺ≫ has_limit.iso_of_nat_iso (diagram_iso_cospan _).symm) instance SheafedSpace_forget_preserves_of_left : preserves_limit (cospan f g) (SheafedSpace.forget C) := @@limits.comp_preserves_limit _ _ _ _ forget (PresheafedSpace.forget C) _ begin apply_with (preserves_limit_of_iso_diagram _ (diagram_iso_cospan.{v} _).symm) { instances := tt }, dsimp, apply_instance end instance SheafedSpace_forget_preserves_of_right : preserves_limit (cospan g f) (SheafedSpace.forget C) := preserves_pullback_symmetry _ _ _ instance SheafedSpace_has_pullback_of_left : has_pullback f g := has_limit_of_created (cospan f g) forget instance SheafedSpace_has_pullback_of_right : has_pullback g f := has_limit_of_created (cospan g f) forget /-- Open immersions are stable under base-change. -/ instance SheafedSpace_pullback_snd_of_left : SheafedSpace.is_open_immersion (pullback.snd : pullback f g ⟢ _) := begin delta pullback.snd, have : _ = limit.Ο€ (cospan f g) right := preserves_limits_iso_hom_Ο€ forget (cospan f g) right, rw ← this, have := has_limit.iso_of_nat_iso_hom_Ο€ (diagram_iso_cospan.{v} (cospan f g β‹™ forget)) right, erw category.comp_id at this, rw ← this, dsimp, apply_instance end instance SheafedSpace_pullback_fst_of_right : SheafedSpace.is_open_immersion (pullback.fst : pullback g f ⟢ _) := begin delta pullback.fst, have : _ = limit.Ο€ (cospan g f) left := preserves_limits_iso_hom_Ο€ forget (cospan g f) left, rw ← this, have := has_limit.iso_of_nat_iso_hom_Ο€ (diagram_iso_cospan.{v} (cospan g f β‹™ forget)) left, erw category.comp_id at this, rw ← this, dsimp, apply_instance end instance SheafedSpace_pullback_to_base_is_open_immersion [SheafedSpace.is_open_immersion g] : SheafedSpace.is_open_immersion (limit.Ο€ (cospan f g) one : pullback f g ⟢ Z) := begin rw [←limit.w (cospan f g) hom.inl, cospan_map_inl], apply_instance end end pullback section of_stalk_iso variables [has_limits C] [has_colimits C] [concrete_category.{v} C] variables [reflects_isomorphisms (forget C)] [preserves_limits (forget C)] variables [preserves_filtered_colimits (forget C)] /-- Suppose `X Y : SheafedSpace C`, where `C` is a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then a morphism `X ⟢ Y` that is a topological open embedding is an open immersion iff every stalk map is an iso. -/ lemma of_stalk_iso {X Y : SheafedSpace C} (f : X ⟢ Y) (hf : open_embedding f.base) [H : βˆ€ x : X, is_iso (PresheafedSpace.stalk_map f x)] : SheafedSpace.is_open_immersion f := { base_open := hf, c_iso := Ξ» U, begin apply_with (Top.presheaf.app_is_iso_of_stalk_functor_map_iso (show Y.sheaf ⟢ (Top.sheaf.pushforward f.base).obj X.sheaf, from f.c)) { instances := ff }, rintros ⟨_, y, hy, rfl⟩, specialize H y, delta PresheafedSpace.stalk_map at H, haveI H' := Top.presheaf.stalk_pushforward.stalk_pushforward_iso_of_open_embedding C hf X.presheaf y, have := @@is_iso.comp_is_iso _ H (@@is_iso.inv_is_iso _ H'), rw [category.assoc, is_iso.hom_inv_id, category.comp_id] at this, exact this end } end of_stalk_iso section prod variables [has_limits C] {ΞΉ : Type v} (F : discrete ΞΉ β₯€ SheafedSpace C) [has_colimit F] (i : discrete ΞΉ) lemma sigma_ΞΉ_open_embedding : open_embedding (colimit.ΞΉ F i).base := begin rw ← (show _ = (colimit.ΞΉ F i).base, from ΞΉ_preserves_colimits_iso_inv (SheafedSpace.forget C) F i), have : _ = _ ≫ colimit.ΞΉ (discrete.functor ((F β‹™ SheafedSpace.forget C).obj ∘ discrete.mk)) i := has_colimit.iso_of_nat_iso_ΞΉ_hom discrete.nat_iso_functor i, rw ← iso.eq_comp_inv at this, rw this, have : colimit.ΞΉ _ _ ≫ _ = _ := Top.sigma_iso_sigma_hom_ΞΉ.{v v} ((F β‹™ SheafedSpace.forget C).obj ∘ discrete.mk) i.as, rw ← iso.eq_comp_inv at this, cases i, rw this, simp_rw [← category.assoc, Top.open_embedding_iff_comp_is_iso, Top.open_embedding_iff_is_iso_comp], dsimp, exact open_embedding_sigma_mk end lemma image_preimage_is_empty (j : discrete ΞΉ) (h : i β‰  j) (U : opens (F.obj i)) : (opens.map (colimit.ΞΉ (F β‹™ SheafedSpace.forget_to_PresheafedSpace) j).base).obj ((opens.map (preserves_colimit_iso SheafedSpace.forget_to_PresheafedSpace F).inv.base).obj ((sigma_ΞΉ_open_embedding F i).is_open_map.functor.obj U)) = βˆ… := begin ext, apply iff_false_intro, rintro ⟨y, hy, eq⟩, replace eq := concrete_category.congr_arg (preserves_colimit_iso (SheafedSpace.forget C) F β‰ͺ≫ has_colimit.iso_of_nat_iso discrete.nat_iso_functor β‰ͺ≫ Top.sigma_iso_sigma.{v} _).hom eq, simp_rw [category_theory.iso.trans_hom, ← Top.comp_app, ← PresheafedSpace.comp_base] at eq, rw ΞΉ_preserves_colimits_iso_inv at eq, change ((SheafedSpace.forget C).map (colimit.ΞΉ F i) ≫ _) y = ((SheafedSpace.forget C).map (colimit.ΞΉ F j) ≫ _) x at eq, cases i, cases j, rw [ΞΉ_preserves_colimits_iso_hom_assoc, ΞΉ_preserves_colimits_iso_hom_assoc, has_colimit.iso_of_nat_iso_ΞΉ_hom_assoc, has_colimit.iso_of_nat_iso_ΞΉ_hom_assoc, Top.sigma_iso_sigma_hom_ΞΉ.{v}, Top.sigma_iso_sigma_hom_ΞΉ.{v}] at eq, exact h (congr_arg discrete.mk (congr_arg sigma.fst eq)), end instance sigma_ΞΉ_is_open_immersion [has_strict_terminal_objects C] : SheafedSpace.is_open_immersion (colimit.ΞΉ F i) := { base_open := sigma_ΞΉ_open_embedding F i, c_iso := Ξ» U, begin have e : colimit.ΞΉ F i = _ := (ΞΉ_preserves_colimits_iso_inv SheafedSpace.forget_to_PresheafedSpace F i).symm, have H : open_embedding (colimit.ΞΉ (F β‹™ SheafedSpace.forget_to_PresheafedSpace) i ≫ (preserves_colimit_iso SheafedSpace.forget_to_PresheafedSpace F).inv).base := e β–Έ sigma_ΞΉ_open_embedding F i, suffices : is_iso ((colimit.ΞΉ (F β‹™ SheafedSpace.forget_to_PresheafedSpace) i ≫ (preserves_colimit_iso SheafedSpace.forget_to_PresheafedSpace F).inv).c.app (op (H.is_open_map.functor.obj U))), { convert this }, rw [PresheafedSpace.comp_c_app, ← PresheafedSpace.colimit_presheaf_obj_iso_componentwise_limit_hom_Ο€], suffices : is_iso (limit.Ο€ (PresheafedSpace.componentwise_diagram (F β‹™ SheafedSpace.forget_to_PresheafedSpace) ((opens.map (preserves_colimit_iso SheafedSpace.forget_to_PresheafedSpace F).inv.base).obj (unop $ op $ H.is_open_map.functor.obj U))) (op i)), { resetI, apply_instance }, apply limit_Ο€_is_iso_of_is_strict_terminal, intros j hj, induction j using opposite.rec, dsimp, convert (F.obj j).sheaf.is_terminal_of_empty, convert image_preimage_is_empty F i j (Ξ» h, hj (congr_arg op h.symm)) U, exact (congr_arg PresheafedSpace.hom.base e).symm end } end prod end SheafedSpace.is_open_immersion namespace LocallyRingedSpace.is_open_immersion section pullback variables {X Y Z : LocallyRingedSpace.{u}} (f : X ⟢ Z) (g : Y ⟢ Z) variable [H : LocallyRingedSpace.is_open_immersion f] @[priority 100] instance of_is_iso [is_iso g] : LocallyRingedSpace.is_open_immersion g := @@PresheafedSpace.is_open_immersion.of_is_iso _ g.1 ⟨⟨(inv g).1, by { erw ← LocallyRingedSpace.comp_val, rw is_iso.hom_inv_id, erw ← LocallyRingedSpace.comp_val, rw is_iso.inv_hom_id, split; simpa }⟩⟩ include H instance comp (g : Z ⟢ Y) [LocallyRingedSpace.is_open_immersion g] : LocallyRingedSpace.is_open_immersion (f ≫ g) := PresheafedSpace.is_open_immersion.comp f.1 g.1 instance mono : mono f := LocallyRingedSpace.forget_to_SheafedSpace.mono_of_mono_map (show mono f.1, by apply_instance) instance : SheafedSpace.is_open_immersion (LocallyRingedSpace.forget_to_SheafedSpace.map f) := H /-- An explicit pullback cone over `cospan f g` if `f` is an open immersion. -/ def pullback_cone_of_left : pullback_cone f g := begin refine pullback_cone.mk _ (Y.of_restrict (Top.snd_open_embedding_of_left_open_embedding H.base_open g.1.base)) _, { use PresheafedSpace.is_open_immersion.pullback_cone_of_left_fst f.1 g.1, intro x, have := PresheafedSpace.stalk_map.congr_hom _ _ (PresheafedSpace.is_open_immersion.pullback_cone_of_left_condition f.1 g.1) x, rw [PresheafedSpace.stalk_map.comp, PresheafedSpace.stalk_map.comp] at this, rw ← is_iso.eq_inv_comp at this, rw this, apply_instance }, { exact subtype.eq (PresheafedSpace.is_open_immersion.pullback_cone_of_left_condition _ _) }, end instance : LocallyRingedSpace.is_open_immersion (pullback_cone_of_left f g).snd := show PresheafedSpace.is_open_immersion (Y.to_PresheafedSpace.of_restrict _), by apply_instance /-- The constructed `pullback_cone_of_left` is indeed limiting. -/ def pullback_cone_of_left_is_limit : is_limit (pullback_cone_of_left f g) := pullback_cone.is_limit_aux' _ $ Ξ» s, begin use PresheafedSpace.is_open_immersion.pullback_cone_of_left_lift f.1 g.1 (pullback_cone.mk s.fst.1 s.snd.1 (congr_arg subtype.val s.condition)), { intro x, have := PresheafedSpace.stalk_map.congr_hom _ _ (PresheafedSpace.is_open_immersion.pullback_cone_of_left_lift_snd f.1 g.1 (pullback_cone.mk s.fst.1 s.snd.1 (congr_arg subtype.val s.condition))) x, change _ = _ ≫ PresheafedSpace.stalk_map s.snd.1 x at this, rw [PresheafedSpace.stalk_map.comp, ← is_iso.eq_inv_comp] at this, rw this, apply_instance }, split, exact subtype.eq (PresheafedSpace.is_open_immersion.pullback_cone_of_left_lift_fst f.1 g.1 _), split, exact subtype.eq (PresheafedSpace.is_open_immersion.pullback_cone_of_left_lift_snd f.1 g.1 _), intros m h₁ hβ‚‚, rw ← cancel_mono (pullback_cone_of_left f g).snd, exact (hβ‚‚.trans (subtype.eq (PresheafedSpace.is_open_immersion.pullback_cone_of_left_lift_snd f.1 g.1 (pullback_cone.mk s.fst.1 s.snd.1 (congr_arg subtype.val s.condition))).symm)) end instance has_pullback_of_left : has_pullback f g := ⟨⟨⟨_, pullback_cone_of_left_is_limit f g⟩⟩⟩ instance has_pullback_of_right : has_pullback g f := has_pullback_symmetry f g /-- Open immersions are stable under base-change. -/ instance pullback_snd_of_left : LocallyRingedSpace.is_open_immersion (pullback.snd : pullback f g ⟢ _) := begin delta pullback.snd, rw ← limit.iso_limit_cone_hom_Ο€ ⟨_, pullback_cone_of_left_is_limit f g⟩ walking_cospan.right, apply_instance end /-- Open immersions are stable under base-change. -/ instance pullback_fst_of_right : LocallyRingedSpace.is_open_immersion (pullback.fst : pullback g f ⟢ _) := begin rw ← pullback_symmetry_hom_comp_snd, apply_instance end instance pullback_to_base_is_open_immersion [LocallyRingedSpace.is_open_immersion g] : LocallyRingedSpace.is_open_immersion (limit.Ο€ (cospan f g) walking_cospan.one) := begin rw [←limit.w (cospan f g) walking_cospan.hom.inl, cospan_map_inl], apply_instance end instance forget_preserves_pullback_of_left : preserves_limit (cospan f g) LocallyRingedSpace.forget_to_SheafedSpace := preserves_limit_of_preserves_limit_cone (pullback_cone_of_left_is_limit f g) begin apply (is_limit_map_cone_pullback_cone_equiv _ _).symm.to_fun, apply is_limit_of_is_limit_pullback_cone_map SheafedSpace.forget_to_PresheafedSpace, exact PresheafedSpace.is_open_immersion.pullback_cone_of_left_is_limit f.1 g.1 end instance forget_to_PresheafedSpace_preserves_pullback_of_left : preserves_limit (cospan f g) (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) := preserves_limit_of_preserves_limit_cone (pullback_cone_of_left_is_limit f g) begin apply (is_limit_map_cone_pullback_cone_equiv _ _).symm.to_fun, exact PresheafedSpace.is_open_immersion.pullback_cone_of_left_is_limit f.1 g.1 end instance forget_to_PresheafedSpace_preserves_open_immersion : PresheafedSpace.is_open_immersion ((LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace).map f) := H instance forget_to_Top_preserves_pullback_of_left : preserves_limit (cospan f g) (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget _) := begin change preserves_limit _ ((LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) β‹™ PresheafedSpace.forget _), apply_with limits.comp_preserves_limit { instances := ff }, apply_instance, apply preserves_limit_of_iso_diagram _ (diagram_iso_cospan.{u} _).symm, dsimp [SheafedSpace.forget_to_PresheafedSpace, -subtype.val_eq_coe], apply_instance, end instance forget_reflects_pullback_of_left : reflects_limit (cospan f g) LocallyRingedSpace.forget_to_SheafedSpace := reflects_limit_of_reflects_isomorphisms _ _ instance forget_preserves_pullback_of_right : preserves_limit (cospan g f) LocallyRingedSpace.forget_to_SheafedSpace := preserves_pullback_symmetry _ _ _ instance forget_to_PresheafedSpace_preserves_pullback_of_right : preserves_limit (cospan g f) (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) := preserves_pullback_symmetry _ _ _ instance forget_reflects_pullback_of_right : reflects_limit (cospan g f) LocallyRingedSpace.forget_to_SheafedSpace := reflects_limit_of_reflects_isomorphisms _ _ instance forget_to_PresheafedSpace_reflects_pullback_of_left : reflects_limit (cospan f g) (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) := reflects_limit_of_reflects_isomorphisms _ _ instance forget_to_PresheafedSpace_reflects_pullback_of_right : reflects_limit (cospan g f) (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) := reflects_limit_of_reflects_isomorphisms _ _ lemma pullback_snd_is_iso_of_range_subset (H' : set.range g.1.base βŠ† set.range f.1.base) : is_iso (pullback.snd : pullback f g ⟢ _) := begin apply_with (reflects_isomorphisms.reflects LocallyRingedSpace.forget_to_SheafedSpace) { instances := ff }, apply_with (reflects_isomorphisms.reflects SheafedSpace.forget_to_PresheafedSpace) { instances := ff }, erw ← preserves_pullback.iso_hom_snd (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget_to_PresheafedSpace) f g, haveI := PresheafedSpace.is_open_immersion.pullback_snd_is_iso_of_range_subset _ _ H', apply_instance, apply_instance end /-- The universal property of open immersions: For an open immersion `f : X ⟢ Z`, given any morphism of schemes `g : Y ⟢ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟢ X` that commutes with these maps. -/ def lift (H' : set.range g.1.base βŠ† set.range f.1.base) : Y ⟢ X := begin haveI := pullback_snd_is_iso_of_range_subset f g H', exact inv (pullback.snd : pullback f g ⟢ _) ≫ pullback.fst, end @[simp, reassoc] lemma lift_fac (H' : set.range g.1.base βŠ† set.range f.1.base) : lift f g H' ≫ f = g := by { erw category.assoc, rw is_iso.inv_comp_eq, exact pullback.condition } lemma lift_uniq (H' : set.range g.1.base βŠ† set.range f.1.base) (l : Y ⟢ X) (hl : l ≫ f = g) : l = lift f g H' := by rw [← cancel_mono f, hl, lift_fac] lemma lift_range (H' : set.range g.1.base βŠ† set.range f.1.base) : set.range (lift f g H').1.base = f.1.base ⁻¹' (set.range g.1.base) := begin haveI := pullback_snd_is_iso_of_range_subset f g H', dsimp only [lift], have : _ = (pullback.fst : pullback f g ⟢ _).val.base := preserves_pullback.iso_hom_fst (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget _) f g, rw [LocallyRingedSpace.comp_val, SheafedSpace.comp_base, ← this, ← category.assoc, coe_comp], rw [set.range_comp, set.range_iff_surjective.mpr, set.image_univ, Top.pullback_fst_range], ext, split, { rintros ⟨y, eq⟩, exact ⟨y, eq.symm⟩ }, { rintros ⟨y, eq⟩, exact ⟨y, eq.symm⟩ }, { rw ← Top.epi_iff_surjective, rw (show (inv (pullback.snd : pullback f g ⟢ _)).val.base = _, from (LocallyRingedSpace.forget_to_SheafedSpace β‹™ SheafedSpace.forget _).map_inv _), apply_instance } end end pullback /-- An open immersion is isomorphic to the induced open subscheme on its image. -/ def iso_restrict {X Y : LocallyRingedSpace} {f : X ⟢ Y} (H : LocallyRingedSpace.is_open_immersion f) : X β‰… Y.restrict H.base_open := begin apply LocallyRingedSpace.iso_of_SheafedSpace_iso, refine SheafedSpace.forget_to_PresheafedSpace.preimage_iso _, exact H.iso_restrict end /-- To show that a locally ringed space is a scheme, it suffices to show that it has a jointly surjective family of open immersions from affine schemes. -/ protected def Scheme (X : LocallyRingedSpace) (h : βˆ€ (x : X), βˆƒ (R : CommRing) (f : Spec.to_LocallyRingedSpace.obj (op R) ⟢ X), (x ∈ set.range f.1.base : _) ∧ LocallyRingedSpace.is_open_immersion f) : Scheme := { to_LocallyRingedSpace := X, local_affine := begin intro x, obtain ⟨R, f, h₁, hβ‚‚βŸ© := h x, refine ⟨⟨⟨_, hβ‚‚.base_open.open_range⟩, hβ‚βŸ©, R, ⟨_⟩⟩, apply LocallyRingedSpace.iso_of_SheafedSpace_iso, refine SheafedSpace.forget_to_PresheafedSpace.preimage_iso _, resetI, apply PresheafedSpace.is_open_immersion.iso_of_range_eq (PresheafedSpace.of_restrict _ _) f.1, { exact subtype.range_coe_subtype }, { apply_instance } end } end LocallyRingedSpace.is_open_immersion lemma is_open_immersion.open_range {X Y : Scheme} (f : X ⟢ Y) [H : is_open_immersion f] : is_open (set.range f.1.base) := H.base_open.open_range section open_cover namespace Scheme /-- An open cover of `X` consists of a family of open immersions into `X`, and for each `x : X` an open immersion (indexed by `f x`) that covers `x`. This is merely a coverage in the Zariski pretopology, and it would be optimal if we could reuse the existing API about pretopologies, However, the definitions of sieves and grothendieck topologies uses `Prop`s, so that the actual open sets and immersions are hard to obtain. Also, since such a coverage in the pretopology usually contains a proper class of immersions, it is quite hard to glue them, reason about finite covers, etc. -/ -- TODO: provide API to and from a presieve. structure open_cover (X : Scheme.{u}) := (J : Type v) (obj : Ξ  (j : J), Scheme) (map : Ξ  (j : J), obj j ⟢ X) (f : X.carrier β†’ J) (covers : βˆ€ x, x ∈ set.range ((map (f x)).1.base)) (is_open : βˆ€ x, is_open_immersion (map x) . tactic.apply_instance) attribute [instance] open_cover.is_open variables {X Y Z : Scheme.{u}} (𝒰 : open_cover X) (f : X ⟢ Z) (g : Y ⟢ Z) variables [βˆ€ x, has_pullback (𝒰.map x ≫ f) g] /-- The affine cover of a scheme. -/ def affine_cover (X : Scheme) : open_cover X := { J := X.carrier, obj := Ξ» x, Spec.obj $ opposite.op (X.local_affine x).some_spec.some, map := Ξ» x, ((X.local_affine x).some_spec.some_spec.some.inv ≫ X.to_LocallyRingedSpace.of_restrict _ : _), f := Ξ» x, x, is_open := Ξ» x, begin apply_with PresheafedSpace.is_open_immersion.comp { instances := ff }, apply_instance, apply PresheafedSpace.is_open_immersion.of_restrict, end, covers := begin intro x, erw coe_comp, rw [set.range_comp, set.range_iff_surjective.mpr, set.image_univ], erw subtype.range_coe_subtype, exact (X.local_affine x).some.2, rw ← Top.epi_iff_surjective, change epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forget_to_SheafedSpace.map _)), apply_instance end } instance : inhabited X.open_cover := ⟨X.affine_cover⟩ /-- Given an open cover `{ Uα΅’ }` of `X`, and for each `Uα΅’` an open cover, we may combine these open covers to form an open cover of `X`. -/ @[simps J obj map] def open_cover.bind (f : Ξ  (x : 𝒰.J), open_cover (𝒰.obj x)) : open_cover X := { J := Ξ£ (i : 𝒰.J), (f i).J, obj := Ξ» x, (f x.1).obj x.2, map := Ξ» x, (f x.1).map x.2 ≫ 𝒰.map x.1, f := Ξ» x, ⟨_, (f _).f (𝒰.covers x).some⟩, covers := Ξ» x, begin let y := (𝒰.covers x).some, have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.covers x).some_spec, rcases (f (𝒰.f x)).covers y with ⟨z, hz⟩, change x ∈ set.range (((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base), use z, erw comp_apply, rw [hz, hy], end } /-- An isomorphism `X ⟢ Y` is an open cover of `Y`. -/ @[simps J obj map] def open_cover_of_is_iso {X Y : Scheme.{u}} (f : X ⟢ Y) [is_iso f] : open_cover Y := { J := punit.{v+1}, obj := Ξ» _, X, map := Ξ» _, f, f := Ξ» _, punit.star, covers := Ξ» x, by { rw set.range_iff_surjective.mpr, { trivial }, rw ← Top.epi_iff_surjective, apply_instance } } /-- We construct an open cover from another, by providing the needed fields and showing that the provided fields are isomorphic with the original open cover. -/ @[simps J obj map] def open_cover.copy {X : Scheme} (𝒰 : open_cover X) (J : Type*) (obj : J β†’ Scheme) (map : βˆ€ i, obj i ⟢ X) (e₁ : J ≃ 𝒰.J) (eβ‚‚ : βˆ€ i, obj i β‰… 𝒰.obj (e₁ i)) (eβ‚‚ : βˆ€ i, map i = (eβ‚‚ i).hom ≫ 𝒰.map (e₁ i)) : open_cover X := { J := J, obj := obj, map := map, f := Ξ» x, e₁.symm (𝒰.f x), covers := Ξ» x, begin rw [eβ‚‚, Scheme.comp_val_base, coe_comp, set.range_comp, set.range_iff_surjective.mpr, set.image_univ, e₁.right_inverse_symm], { exact 𝒰.covers x }, { rw ← Top.epi_iff_surjective, apply_instance } end, is_open := Ξ» i, by { rw eβ‚‚, apply_instance } } /-- The pushforward of an open cover along an isomorphism. -/ @[simps J obj map] def open_cover.pushforward_iso {X Y : Scheme} (𝒰 : open_cover X) (f : X ⟢ Y) [is_iso f] : open_cover Y := ((open_cover_of_is_iso f).bind (Ξ» _, 𝒰)).copy 𝒰.J _ _ ((equiv.punit_prod _).symm.trans (equiv.sigma_equiv_prod punit 𝒰.J).symm) (Ξ» _, iso.refl _) (Ξ» _, (category.id_comp _).symm) /-- Adding an open immersion into an open cover gives another open cover. -/ @[simps] def open_cover.add {X : Scheme} (𝒰 : X.open_cover) {Y : Scheme} (f : Y ⟢ X) [is_open_immersion f] : X.open_cover := { J := option 𝒰.J, obj := Ξ» i, option.rec Y 𝒰.obj i, map := Ξ» i, option.rec f 𝒰.map i, f := Ξ» x, some (𝒰.f x), covers := 𝒰.covers, is_open := by rintro (_|_); dsimp; apply_instance } -- Related result : `open_cover.pullback_cover`, where we pullback an open cover on `X` along a -- morphism `W ⟢ X`. This is provided at the end of the file since it needs some more results -- about open immersion (which in turn needs the open cover API). local attribute [reducible] CommRing.of CommRing.of_hom instance val_base_is_iso {X Y : Scheme} (f : X ⟢ Y) [is_iso f] : is_iso f.1.base := Scheme.forget_to_Top.map_is_iso f instance basic_open_is_open_immersion {R : CommRing} (f : R) : algebraic_geometry.is_open_immersion (Scheme.Spec.map (CommRing.of_hom (algebra_map R (localization.away f))).op) := begin apply_with SheafedSpace.is_open_immersion.of_stalk_iso { instances := ff }, any_goals { apply_instance }, any_goals { apply_instance }, exact (prime_spectrum.localization_away_open_embedding (localization.away f) f : _), intro x, exact Spec_map_localization_is_iso R (submonoid.powers f) x, end /-- The basic open sets form an affine open cover of `Spec R`. -/ def affine_basis_cover_of_affine (R : CommRing) : open_cover (Spec.obj (opposite.op R)) := { J := R, obj := Ξ» r, Spec.obj (opposite.op $ CommRing.of $ localization.away r), map := Ξ» r, Spec.map (quiver.hom.op (algebra_map R (localization.away r) : _)), f := Ξ» x, 1, covers := Ξ» r, begin rw set.range_iff_surjective.mpr ((Top.epi_iff_surjective _).mp _), { exact trivial }, { apply_instance } end, is_open := Ξ» x, algebraic_geometry.Scheme.basic_open_is_open_immersion x } /-- We may bind the basic open sets of an open affine cover to form a affine cover that is also a basis. -/ def affine_basis_cover (X : Scheme) : open_cover X := X.affine_cover.bind (Ξ» x, affine_basis_cover_of_affine _) /-- The coordinate ring of a component in the `affine_basis_cover`. -/ def affine_basis_cover_ring (X : Scheme) (i : X.affine_basis_cover.J) : CommRing := CommRing.of $ @localization.away (X.local_affine i.1).some_spec.some _ i.2 lemma affine_basis_cover_obj (X : Scheme) (i : X.affine_basis_cover.J) : X.affine_basis_cover.obj i = Spec.obj (op $ X.affine_basis_cover_ring i) := rfl lemma affine_basis_cover_map_range (X : Scheme) (x : X.carrier) (r : (X.local_affine x).some_spec.some) : set.range (X.affine_basis_cover.map ⟨x, r⟩).1.base = (X.affine_cover.map x).1.base '' (prime_spectrum.basic_open r).1 := begin erw [coe_comp, set.range_comp], congr, exact (prime_spectrum.localization_away_comap_range (localization.away r) r : _) end lemma affine_basis_cover_is_basis (X : Scheme) : topological_space.is_topological_basis { x : set X.carrier | βˆƒ a : X.affine_basis_cover.J, x = set.range ((X.affine_basis_cover.map a).1.base) } := begin apply topological_space.is_topological_basis_of_open_of_nhds, { rintros _ ⟨a, rfl⟩, exact is_open_immersion.open_range (X.affine_basis_cover.map a) }, { rintros a U haU hU, rcases X.affine_cover.covers a with ⟨x, e⟩, let U' := (X.affine_cover.map (X.affine_cover.f a)).1.base ⁻¹' U, have hxU' : x ∈ U' := by { rw ← e at haU, exact haU }, rcases prime_spectrum.is_basis_basic_opens.exists_subset_of_mem_open hxU' ((X.affine_cover.map (X.affine_cover.f a)).1.base.continuous_to_fun.is_open_preimage _ hU) with ⟨_,⟨_,⟨s,rfl⟩,rfl⟩,hxV,hVU⟩, refine ⟨_,⟨⟨_,s⟩,rfl⟩,_,_⟩; erw affine_basis_cover_map_range, { exact ⟨x,hxV,e⟩ }, { rw set.image_subset_iff, exact hVU } } end /-- Every open cover of a quasi-compact scheme can be refined into a finite subcover. -/ @[simps obj map] def open_cover.finite_subcover {X : Scheme} (𝒰 : open_cover X) [H : compact_space X.carrier] : open_cover X := begin have := @@compact_space.elim_nhds_subcover _ H (Ξ» (x : X.carrier), set.range ((𝒰.map (𝒰.f x)).1.base)) (Ξ» x, (is_open_immersion.open_range (𝒰.map (𝒰.f x))).mem_nhds (𝒰.covers x)), let t := this.some, have h : βˆ€ (x : X.carrier), βˆƒ (y : t), x ∈ set.range ((𝒰.map (𝒰.f y)).1.base), { intro x, have h' : x ∈ (⊀ : set X.carrier) := trivial, rw [← classical.some_spec this, set.mem_Union] at h', rcases h' with ⟨y,_,⟨hy,rfl⟩,hy'⟩, exact ⟨⟨y,hy⟩,hy'⟩ }, exact { J := t, obj := Ξ» x, 𝒰.obj (𝒰.f x.1), map := Ξ» x, 𝒰.map (𝒰.f x.1), f := Ξ» x, (h x).some, covers := Ξ» x, (h x).some_spec } end instance [H : compact_space X.carrier] : fintype 𝒰.finite_subcover.J := by { delta open_cover.finite_subcover, apply_instance } end Scheme end open_cover namespace PresheafedSpace.is_open_immersion section to_Scheme variables {X : PresheafedSpace.{u} CommRing.{u}} (Y : Scheme.{u}) variables (f : X ⟢ Y.to_PresheafedSpace) [H : PresheafedSpace.is_open_immersion f] include H /-- If `X ⟢ Y` is an open immersion, and `Y` is a scheme, then so is `X`. -/ def to_Scheme : Scheme := begin apply LocallyRingedSpace.is_open_immersion.Scheme (to_LocallyRingedSpace _ f), intro x, obtain ⟨_,⟨i,rfl⟩,hx,hi⟩ := Y.affine_basis_cover_is_basis.exists_subset_of_mem_open (set.mem_range_self x) H.base_open.open_range, use Y.affine_basis_cover_ring i, use LocallyRingedSpace.is_open_immersion.lift (to_LocallyRingedSpace_hom _ f) _ hi, split, { rw LocallyRingedSpace.is_open_immersion.lift_range, exact hx }, { delta LocallyRingedSpace.is_open_immersion.lift, apply_instance } end @[simp] lemma to_Scheme_to_LocallyRingedSpace : (to_Scheme Y f).to_LocallyRingedSpace = (to_LocallyRingedSpace Y.1 f) := rfl /-- If `X ⟢ Y` is an open immersion of PresheafedSpaces, and `Y` is a Scheme, we can upgrade it into a morphism of Schemes. -/ def to_Scheme_hom : to_Scheme Y f ⟢ Y := to_LocallyRingedSpace_hom _ f @[simp] lemma to_Scheme_hom_val : (to_Scheme_hom Y f).val = f := rfl instance to_Scheme_hom_is_open_immersion : is_open_immersion (to_Scheme_hom Y f) := H omit H lemma Scheme_eq_of_LocallyRingedSpace_eq {X Y : Scheme} (H : X.to_LocallyRingedSpace = Y.to_LocallyRingedSpace) : X = Y := by { cases X, cases Y, congr, exact H } lemma Scheme_to_Scheme {X Y : Scheme} (f : X ⟢ Y) [is_open_immersion f] : to_Scheme Y f.1 = X := begin apply Scheme_eq_of_LocallyRingedSpace_eq, exact LocallyRingedSpace_to_LocallyRingedSpace f end end to_Scheme end PresheafedSpace.is_open_immersion /-- The restriction of a Scheme along an open embedding. -/ @[simps] def Scheme.restrict {U : Top} (X : Scheme) {f : U ⟢ Top.of X.carrier} (h : open_embedding f) : Scheme := { to_PresheafedSpace := X.to_PresheafedSpace.restrict h, ..(PresheafedSpace.is_open_immersion.to_Scheme X (X.to_PresheafedSpace.of_restrict h)) } /-- The canonical map from the restriction to the supspace. -/ @[simps] def Scheme.of_restrict {U : Top} (X : Scheme) {f : U ⟢ Top.of X.carrier} (h : open_embedding f) : X.restrict h ⟢ X := X.to_LocallyRingedSpace.of_restrict h instance is_open_immersion.of_restrict {U : Top} (X : Scheme) {f : U ⟢ Top.of X.carrier} (h : open_embedding f) : is_open_immersion (X.of_restrict h) := show PresheafedSpace.is_open_immersion (X.to_PresheafedSpace.of_restrict h), by apply_instance namespace is_open_immersion variables {X Y Z : Scheme.{u}} (f : X ⟢ Z) (g : Y ⟢ Z) variable [H : is_open_immersion f] @[priority 100] instance of_is_iso [is_iso g] : is_open_immersion g := @@LocallyRingedSpace.is_open_immersion.of_is_iso _ (show is_iso ((induced_functor _).map g), by apply_instance) /-- A open immersion induces an isomorphism from the domain onto the image -/ def iso_restrict : X β‰… (Z.restrict H.base_open : _) := ⟨H.iso_restrict.hom, H.iso_restrict.inv, H.iso_restrict.hom_inv_id, H.iso_restrict.inv_hom_id⟩ include H local notation `forget` := Scheme.forget_to_LocallyRingedSpace instance mono : mono f := (induced_functor _).mono_of_mono_map (show @mono LocallyRingedSpace _ _ _ f, by apply_instance) instance forget_map_is_open_immersion : LocallyRingedSpace.is_open_immersion (forget .map f) := ⟨H.base_open, H.c_iso⟩ instance has_limit_cospan_forget_of_left : has_limit (cospan f g β‹™ Scheme.forget_to_LocallyRingedSpace) := begin apply has_limit_of_iso (diagram_iso_cospan.{u} _).symm, change has_limit (cospan (forget .map f) (forget .map g)), apply_instance end open category_theory.limits.walking_cospan instance has_limit_cospan_forget_of_left' : has_limit (cospan ((cospan f g β‹™ forget).map hom.inl) ((cospan f g β‹™ forget).map hom.inr)) := show has_limit (cospan (forget .map f) (forget .map g)), from infer_instance instance has_limit_cospan_forget_of_right : has_limit (cospan g f β‹™ forget) := begin apply has_limit_of_iso (diagram_iso_cospan.{u} _).symm, change has_limit (cospan (forget .map g) (forget .map f)), apply_instance end instance has_limit_cospan_forget_of_right' : has_limit (cospan ((cospan g f β‹™ forget).map hom.inl) ((cospan g f β‹™ forget).map hom.inr)) := show has_limit (cospan (forget .map g) (forget .map f)), from infer_instance instance forget_creates_pullback_of_left : creates_limit (cospan f g) forget := creates_limit_of_fully_faithful_of_iso (PresheafedSpace.is_open_immersion.to_Scheme Y (@pullback.snd LocallyRingedSpace _ _ _ _ f g _).1) (eq_to_iso (by simp) β‰ͺ≫ has_limit.iso_of_nat_iso (diagram_iso_cospan _).symm) instance forget_creates_pullback_of_right : creates_limit (cospan g f) forget := creates_limit_of_fully_faithful_of_iso (PresheafedSpace.is_open_immersion.to_Scheme Y (@pullback.fst LocallyRingedSpace _ _ _ _ g f _).1) (eq_to_iso (by simp) β‰ͺ≫ has_limit.iso_of_nat_iso (diagram_iso_cospan _).symm) instance forget_preserves_of_left : preserves_limit (cospan f g) forget := category_theory.preserves_limit_of_creates_limit_and_has_limit _ _ instance forget_preserves_of_right : preserves_limit (cospan g f) forget := preserves_pullback_symmetry _ _ _ instance has_pullback_of_left : has_pullback f g := has_limit_of_created (cospan f g) forget instance has_pullback_of_right : has_pullback g f := has_limit_of_created (cospan g f) forget instance pullback_snd_of_left : is_open_immersion (pullback.snd : pullback f g ⟢ _) := begin have := preserves_pullback.iso_hom_snd forget f g, dsimp only [Scheme.forget_to_LocallyRingedSpace, induced_functor_map] at this, rw ← this, change LocallyRingedSpace.is_open_immersion _, apply_instance end instance pullback_fst_of_right : is_open_immersion (pullback.fst : pullback g f ⟢ _) := begin rw ← pullback_symmetry_hom_comp_snd, apply_instance end instance pullback_to_base [is_open_immersion g] : is_open_immersion (limit.Ο€ (cospan f g) walking_cospan.one) := begin rw ← limit.w (cospan f g) walking_cospan.hom.inl, change is_open_immersion (_ ≫ f), apply_instance end instance forget_to_Top_preserves_of_left : preserves_limit (cospan f g) Scheme.forget_to_Top := begin apply_with limits.comp_preserves_limit { instances := ff }, apply_instance, apply preserves_limit_of_iso_diagram _ (diagram_iso_cospan.{u} _).symm, dsimp [LocallyRingedSpace.forget_to_Top], apply_instance end instance forget_to_Top_preserves_of_right : preserves_limit (cospan g f) Scheme.forget_to_Top := preserves_pullback_symmetry _ _ _ lemma range_pullback_snd_of_left : set.range (pullback.snd : pullback f g ⟢ Y).1.base = (opens.map g.1.base).obj ⟨set.range f.1.base, H.base_open.open_range⟩ := begin rw [← (show _ = (pullback.snd : pullback f g ⟢ _).1.base, from preserves_pullback.iso_hom_snd Scheme.forget_to_Top f g), coe_comp, set.range_comp, set.range_iff_surjective.mpr, ← @set.preimage_univ _ _ (pullback.fst : pullback f.1.base g.1.base ⟢ _), Top.pullback_snd_image_fst_preimage, set.image_univ], refl, rw ← Top.epi_iff_surjective, apply_instance end lemma range_pullback_fst_of_right : set.range (pullback.fst : pullback g f ⟢ Y).1.base = (opens.map g.1.base).obj ⟨set.range f.1.base, H.base_open.open_range⟩ := begin rw [← (show _ = (pullback.fst : pullback g f ⟢ _).1.base, from preserves_pullback.iso_hom_fst Scheme.forget_to_Top g f), coe_comp, set.range_comp, set.range_iff_surjective.mpr, ← @set.preimage_univ _ _ (pullback.snd : pullback g.1.base f.1.base ⟢ _), Top.pullback_fst_image_snd_preimage, set.image_univ], refl, rw ← Top.epi_iff_surjective, apply_instance end lemma range_pullback_to_base_of_left : set.range (pullback.fst ≫ f : pullback f g ⟢ Z).1.base = set.range f.1.base ∩ set.range g.1.base := begin rw [pullback.condition, Scheme.comp_val_base, coe_comp, set.range_comp, range_pullback_snd_of_left, opens.map_obj, subtype.coe_mk, set.image_preimage_eq_inter_range, set.inter_comm], end lemma range_pullback_to_base_of_right : set.range (pullback.fst ≫ g : pullback g f ⟢ Z).1.base = set.range g.1.base ∩ set.range f.1.base := begin rw [Scheme.comp_val_base, coe_comp, set.range_comp, range_pullback_fst_of_right, opens.map_obj, subtype.coe_mk, set.image_preimage_eq_inter_range, set.inter_comm], end /-- The universal property of open immersions: For an open immersion `f : X ⟢ Z`, given any morphism of schemes `g : Y ⟢ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟢ X` that commutes with these maps. -/ def lift (H' : set.range g.1.base βŠ† set.range f.1.base) : Y ⟢ X := LocallyRingedSpace.is_open_immersion.lift f g H' @[simp, reassoc] lemma lift_fac (H' : set.range g.1.base βŠ† set.range f.1.base) : lift f g H' ≫ f = g := LocallyRingedSpace.is_open_immersion.lift_fac f g H' lemma lift_uniq (H' : set.range g.1.base βŠ† set.range f.1.base) (l : Y ⟢ X) (hl : l ≫ f = g) : l = lift f g H' := LocallyRingedSpace.is_open_immersion.lift_uniq f g H' l hl /-- Two open immersions with equal range are isomorphic. -/ @[simps] def iso_of_range_eq [is_open_immersion g] (e : set.range f.1.base = set.range g.1.base) : X β‰… Y := { hom := lift g f (le_of_eq e), inv := lift f g (le_of_eq e.symm), hom_inv_id' := by { rw ← cancel_mono f, simp }, inv_hom_id' := by { rw ← cancel_mono g, simp } } lemma image_basic_open {X Y : Scheme} (f : X ⟢ Y) [H : is_open_immersion f] {U : opens X.carrier} (r : X.presheaf.obj (op U)) : H.base_open.is_open_map.functor.obj (X.basic_open r) = Y.basic_open (H.inv_app U r) := begin have e := Scheme.preimage_basic_open f (H.inv_app U r), rw [PresheafedSpace.is_open_immersion.inv_app_app_apply, Scheme.basic_open_res, opens.inter_eq, inf_eq_right.mpr _] at e, rw ← e, ext1, refine set.image_preimage_eq_inter_range.trans _, erw set.inter_eq_left_iff_subset, refine set.subset.trans (Scheme.basic_open_subset _ _) (set.image_subset_range _ _), refine le_trans (Scheme.basic_open_subset _ _) (le_of_eq _), ext1, exact (set.preimage_image_eq _ H.base_open.inj).symm end end is_open_immersion /-- The functor taking open subsets of `X` to open subschemes of `X`. -/ @[simps obj_left obj_hom map_left] def Scheme.restrict_functor (X : Scheme) : opens X.carrier β₯€ over X := { obj := Ξ» U, over.mk (X.of_restrict U.open_embedding), map := Ξ» U V i, over.hom_mk (is_open_immersion.lift (X.of_restrict _) (X.of_restrict _) (by { change set.range coe βŠ† set.range coe, simp_rw [subtype.range_coe], exact i.le })) (is_open_immersion.lift_fac _ _ _), map_id' := Ξ» U, by begin ext1, dsimp only [over.hom_mk_left, over.id_left], rw [← cancel_mono (X.of_restrict U.open_embedding), category.id_comp, is_open_immersion.lift_fac], end, map_comp' := Ξ» U V W i j, begin ext1, dsimp only [over.hom_mk_left, over.comp_left], rw [← cancel_mono (X.of_restrict W.open_embedding), category.assoc], iterate 3 { rw [is_open_immersion.lift_fac] } end } /-- The restriction of an isomorphism onto an open set. -/ noncomputable abbreviation Scheme.restrict_map_iso {X Y : Scheme} (f : X ⟢ Y) [is_iso f] (U : opens Y.carrier) : X.restrict ((opens.map f.1.base).obj U).open_embedding β‰… Y.restrict U.open_embedding := begin refine is_open_immersion.iso_of_range_eq (X.of_restrict _ ≫ f) (Y.of_restrict _) _, dsimp [opens.inclusion], rw [coe_comp, set.range_comp], dsimp, rw [subtype.range_coe, subtype.range_coe], refine @set.image_preimage_eq _ _ f.1.base U.1 _, rw ← Top.epi_iff_surjective, apply_instance end /-- Given an open cover on `X`, we may pull them back along a morphism `W ⟢ X` to obtain an open cover of `W`. -/ @[simps] def Scheme.open_cover.pullback_cover {X : Scheme} (𝒰 : X.open_cover) {W : Scheme} (f : W ⟢ X) : W.open_cover := { J := 𝒰.J, obj := Ξ» x, pullback f (𝒰.map x), map := Ξ» x, pullback.fst, f := Ξ» x, 𝒰.f (f.1.base x), covers := Ξ» x, begin rw ← (show _ = (pullback.fst : pullback f (𝒰.map (𝒰.f (f.1.base x))) ⟢ _).1.base, from preserves_pullback.iso_hom_fst Scheme.forget_to_Top f (𝒰.map (𝒰.f (f.1.base x)))), rw [coe_comp, set.range_comp, set.range_iff_surjective.mpr, set.image_univ, Top.pullback_fst_range], obtain ⟨y, h⟩ := 𝒰.covers (f.1.base x), exact ⟨y, h.symm⟩, { rw ← Top.epi_iff_surjective, apply_instance } end } /-- Given open covers `{ Uα΅’ }` and `{ Uβ±Ό }`, we may form the open cover `{ Uα΅’ ∩ Uβ±Ό }`. -/ def Scheme.open_cover.inter {X : Scheme.{u}} (𝒰₁ : Scheme.open_cover.{v₁} X) (𝒰₂ : Scheme.open_cover.{vβ‚‚} X) : X.open_cover := { J := 𝒰₁.J Γ— 𝒰₂.J, obj := Ξ» ij, pullback (𝒰₁.map ij.1) (𝒰₂.map ij.2), map := Ξ» ij, pullback.fst ≫ 𝒰₁.map ij.1, f := Ξ» x, βŸ¨π’°β‚.f x, 𝒰₂.f x⟩, covers := Ξ» x, by { rw is_open_immersion.range_pullback_to_base_of_left, exact βŸ¨π’°β‚.covers x, 𝒰₂.covers x⟩ } } section morphism_restrict /-- Given a morphism `f : X ⟢ Y` and an open set `U βŠ† Y`, we have `X Γ—[Y] U β‰… X |_{f ⁻¹ U}` -/ def pullback_restrict_iso_restrict {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : pullback f (Y.of_restrict U.open_embedding) β‰… X.restrict ((opens.map f.1.base).obj U).open_embedding := begin refine is_open_immersion.iso_of_range_eq pullback.fst (X.of_restrict _) _, rw is_open_immersion.range_pullback_fst_of_right, dsimp [opens.inclusion], rw [subtype.range_coe, subtype.range_coe], refl, end @[simp, reassoc] lemma pullback_restrict_iso_restrict_inv_fst {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : (pullback_restrict_iso_restrict f U).inv ≫ pullback.fst = X.of_restrict _ := by { delta pullback_restrict_iso_restrict, simp } @[simp, reassoc] lemma pullback_restrict_iso_restrict_hom_restrict {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : (pullback_restrict_iso_restrict f U).hom ≫ X.of_restrict _ = pullback.fst := by { delta pullback_restrict_iso_restrict, simp } /-- The restriction of a morphism `X ⟢ Y` onto `X |_{f ⁻¹ U} ⟢ Y |_ U`. -/ def morphism_restrict {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : X.restrict ((opens.map f.1.base).obj U).open_embedding ⟢ Y.restrict U.open_embedding := (pullback_restrict_iso_restrict f U).inv ≫ pullback.snd infix ` ∣_ `: 80 := morphism_restrict @[simp, reassoc] lemma pullback_restrict_iso_restrict_hom_morphism_restrict {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : (pullback_restrict_iso_restrict f U).hom ≫ f ∣_ U = pullback.snd := iso.hom_inv_id_assoc _ _ @[simp, reassoc] lemma morphism_restrict_ΞΉ {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : f ∣_ U ≫ Y.of_restrict U.open_embedding = X.of_restrict _ ≫ f := by { delta morphism_restrict, rw [category.assoc, pullback.condition.symm, pullback_restrict_iso_restrict_inv_fst_assoc] } lemma morphism_restrict_comp {X Y Z : Scheme} (f : X ⟢ Y) (g : Y ⟢ Z) (U : opens Z.carrier) : (f ≫ g) ∣_ U = (f ∣_ ((opens.map g.val.base).obj U) ≫ g ∣_ U : _) := begin delta morphism_restrict, rw ← pullback_right_pullback_fst_iso_inv_snd_snd, simp_rw ← category.assoc, congr' 1, rw ← cancel_mono pullback.fst, simp_rw category.assoc, rw [pullback_restrict_iso_restrict_inv_fst, pullback_right_pullback_fst_iso_inv_snd_fst, ← pullback.condition, pullback_restrict_iso_restrict_inv_fst_assoc, pullback_restrict_iso_restrict_inv_fst_assoc], refl, apply_instance end instance {X Y : Scheme} (f : X ⟢ Y) [is_iso f] (U : opens Y.carrier) : is_iso (f ∣_ U) := by { delta morphism_restrict, apply_instance } lemma morphism_restrict_base_coe {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) (x) : @coe U Y.carrier _ ((f ∣_ U).1.base x) = f.1.base x.1 := congr_arg (Ξ» f, PresheafedSpace.hom.base (subtype.val f) x) (morphism_restrict_ΞΉ f U) lemma image_morphism_restrict_preimage {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) (V : opens U) : ((opens.map f.val.base).obj U).open_embedding.is_open_map.functor.obj ((opens.map (f ∣_ U).val.base).obj V) = (opens.map f.val.base).obj (U.open_embedding.is_open_map.functor.obj V) := begin ext1, ext x, split, { rintro ⟨⟨x, hx⟩, (hx' : (f ∣_ U).1.base _ ∈ _), rfl⟩, refine ⟨⟨_, hx⟩, _, rfl⟩, convert hx', ext1, exact (morphism_restrict_base_coe f U ⟨x, hx⟩).symm }, { rintro ⟨⟨x, hx⟩, hx', (rfl : x = _)⟩, refine ⟨⟨_, hx⟩, (_: ((f ∣_ U).1.base ⟨x, hx⟩) ∈ V.1), rfl⟩, convert hx', ext1, exact morphism_restrict_base_coe f U ⟨x, hx⟩ } end lemma morphism_restrict_c_app {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) (V : opens U) : (f ∣_ U).1.c.app (op V) = f.1.c.app (op (U.open_embedding.is_open_map.functor.obj V)) ≫ X.presheaf.map (eq_to_hom (image_morphism_restrict_preimage f U V)).op := begin have := Scheme.congr_app (morphism_restrict_ΞΉ f U) (op (U.open_embedding.is_open_map.functor.obj V)), rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app_assoc] at this, have e : (opens.map U.inclusion).obj (U.open_embedding.is_open_map.functor.obj V) = V, { ext1, exact set.preimage_image_eq _ subtype.coe_injective }, have : _ ≫ X.presheaf.map _ = _ := (((f ∣_ U).1.c.naturality (eq_to_hom e).op).symm.trans _).trans this, swap, { change Y.presheaf.map _ ≫ _ = Y.presheaf.map _ ≫ _, congr, }, rw [← is_iso.eq_comp_inv, ← functor.map_inv, category.assoc] at this, rw this, congr' 1, erw [← X.presheaf.map_comp, ← X.presheaf.map_comp], congr' 1, end lemma Ξ“_map_morphism_restrict {X Y : Scheme} (f : X ⟢ Y) (U : opens Y.carrier) : Scheme.Ξ“.map (f ∣_ U).op = Y.presheaf.map (eq_to_hom $ U.open_embedding_obj_top.symm).op ≫ f.1.c.app (op U) ≫ X.presheaf.map (eq_to_hom $ ((opens.map f.val.base).obj U).open_embedding_obj_top).op := begin rw [Scheme.Ξ“_map_op, morphism_restrict_c_app f U ⊀, f.val.c.naturality_assoc], erw ← X.presheaf.map_comp, congr, end end morphism_restrict end algebraic_geometry
0bd9b8aa2b5930ab34a77aad1cd331e6d98437e0
5c4b17dae42fab1d4f493f3b52977bffa54fefea
/4.6.7.lean
ce0b7c5ea14f7d91be3be9587da4f170da6064b5
[]
no_license
hyponymous/theorem-proving-in-lean-solutions
9214cb45cc87347862fd17dfdea79fdf24b9df92
a95320ae81c90c1b15da04574602cd378794400d
refs/heads/master
1,585,777,733,214
1,541,039,359,000
1,541,039,359,000
153,676,525
2
0
null
null
null
null
UTF-8
Lean
false
false
184
lean
#check sub_self example (x : β„€) : x * 0 = 0 := calc x * 0 = x * (x - x) : by rw sub_self ... = x * x - x * x : by rw mul_sub ... = 0 : by rw sub_self
2567524baa70f1d4a63f0219aa4c202b0b0701bb
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/univ.lean
95d41ac9b20c25d7ca7335e43fa43230ec2e087f
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
234
lean
-- definition id2 (A : Type*) (a : A) := a check id2 Type* num check id2 Type* num check id2 Type num check id2 _ num check id2 (Type (_+1)) num check id2 (Type (0+1)) num check id2 Type* (Type 1) check id2 (Type*) (Type 1)
5db8271d59e8429177ffa696fa54f2c57361c00e
e61a235b8468b03aee0120bf26ec615c045005d2
/src/Init/Lean/Modifiers.lean
c370b0154a71b8b1479611b7333a54d5f4ab2cde
[ "Apache-2.0" ]
permissive
SCKelemen/lean4
140dc63a80539f7c61c8e43e1c174d8500ec3230
e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc
refs/heads/master
1,660,973,595,917
1,590,278,033,000
1,590,278,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,630
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Environment namespace Lean def mkProtectedExtension : IO TagDeclarationExtension := mkTagDeclarationExtension `protected @[init mkProtectedExtension] constant protectedExt : TagDeclarationExtension := arbitrary _ @[export lean_add_protected] def addProtected (env : Environment) (n : Name) : Environment := protectedExt.tag env n @[export lean_is_protected] def isProtected (env : Environment) (n : Name) : Bool := protectedExt.isTagged env n def mkPrivateExtension : IO (EnvExtension Nat) := registerEnvExtension (pure 1) @[init mkPrivateExtension] constant privateExt : EnvExtension Nat := arbitrary _ /- Private name support. Suppose the user marks as declaration `n` as private. Then, we create the name: `_private.<module_name>.<index> ++ n`. We say `_private.<module_name>.<index>` is the "private prefix" where `<index>` comes from the environment extension `privateExt`. We assume that `n` is a valid user name and does not contain `Name.num` constructors. Thus, we can easily convert from private internal name to user given name. -/ def privateHeader : Name := `_private @[export lean_mk_private_prefix] def mkUniquePrivatePrefix (env : Environment) : Environment Γ— Name := let idx := privateExt.getState env; let p := mkNameNum (privateHeader ++ env.mainModule) idx; let env := privateExt.setState env (idx+1); (env, p) @[export lean_mk_private_name] def mkUniquePrivateName (env : Environment) (n : Name) : Environment Γ— Name := let (env, p) := mkUniquePrivatePrefix env; (env, p ++ n) def mkPrivateName (env : Environment) (n : Name) : Name := mkNameNum (privateHeader ++ env.mainModule) 0 ++ n def isPrivateName : Name β†’ Bool | n@(Name.str p _ _) => n == privateHeader || isPrivateName p | Name.num p _ _ => isPrivateName p | _ => false @[export lean_is_private_name] def isPrivateNameExport (n : Name) : Bool := isPrivateName n private def privateToUserNameAux : Name β†’ Name | Name.str p s _ => mkNameStr (privateToUserNameAux p) s | _ => Name.anonymous @[export lean_private_to_user_name] def privateToUserName? (n : Name) : Option Name := if isPrivateName n then privateToUserNameAux n else none private def privatePrefixAux : Name β†’ Name | Name.str p _ _ => privatePrefixAux p | n => n @[export lean_private_prefix] def privatePrefix (n : Name) : Option Name := if isPrivateName n then privatePrefixAux n else none end Lean
b3111df1f1bb1c27ebfd4fba7a40fcd2c5405ef3
6f1049e897f569e5c47237de40321e62f0181948
/src/solutions/08_limits_negation.lean
5b485314afc63e9db9f5ff06473ac4387ceb922a
[ "Apache-2.0" ]
permissive
anrddh/tutorials
f654a0807b9523608544836d9a81939f8e1dceb8
3ba43804e7b632201c494cdaa8da5406f1a255f9
refs/heads/master
1,655,542,921,827
1,588,846,595,000
1,588,846,595,000
262,330,134
0
0
null
1,588,944,346,000
1,588,944,345,000
null
UTF-8
Lean
false
false
5,044
lean
import tuto_lib section /- The first part of this file makes sure you can negate quantified statements in your head without the help of push_neg. You need to complete the statement and then use the `check_me` tactic to check your answer. This tactic exists only for those exercises, it mostly calls push_neg and clean up a bit. def seq_limit (u : β„• β†’ ℝ) (l : ℝ) : Prop := βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n β‰₯ N, |u n - l| ≀ Ξ΅ -/ -- Dans cette section, u dΓ©signe une suite de rΓ©els, f une fonction -- de ℝ dans ℝ, et xβ‚€ et l des rΓ©els. variables (u : β„• β†’ ℝ) (f : ℝ β†’ ℝ) (xβ‚€ l : ℝ) /- Negation of "u tends to l" -/ -- 0062 example : Β¬ (βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n β‰₯ N, |u n - l| ≀ Ξ΅) ↔ -- sorry βˆƒ Ξ΅ > 0, βˆ€ N, βˆƒ n β‰₯ N, |u n - l| > Ξ΅ -- sorry := begin -- sorry check_me, -- sorry end /- Negation of "f is continuous at xβ‚€" -/ -- 0063 example : Β¬ (βˆ€ Ξ΅ > 0, βˆƒ Ξ΄ > 0, βˆ€ x, |x - xβ‚€| ≀ Ξ΄ β†’ |f x - f xβ‚€| ≀ Ξ΅) ↔ -- sorry βˆƒ Ξ΅ > 0, βˆ€ Ξ΄ > 0, βˆƒ x, |x - xβ‚€| ≀ Ξ΄ ∧ |f x - f xβ‚€| > Ξ΅ -- sorry := begin -- sorry check_me, -- sorry end /- In the next exercise, we need to keep in mind that `βˆ€ x x', ...` is the abbreviation of `βˆ€ x, βˆ€ x', ... `. Also, `βˆƒ x x', ...` is the abbreviation of `βˆƒ x, βˆƒ x', ...`. -/ /- Negation of "f is uniformly continuous on ℝ" -/ -- 0064 example : Β¬ (βˆ€ Ξ΅ > 0, βˆƒ Ξ΄ > 0, βˆ€ x x', |x' - x| ≀ Ξ΄ β†’ |f x' - f x| ≀ Ξ΅) ↔ -- sorry βˆƒ Ξ΅ > 0, βˆ€ Ξ΄ > 0, βˆƒ x x', |x' - x| ≀ Ξ΄ ∧ |f x' - f x| > Ξ΅ -- sorry := begin -- sorry check_me, -- sorry end /- Negation of "f is sequentially continuous at xβ‚€" -/ -- 0065 example : Β¬ (βˆ€ u : β„• β†’ ℝ, (βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n β‰₯ N, |u n - xβ‚€| ≀ Ξ΅) β†’ (βˆ€ Ξ΅ > 0, βˆƒ N, βˆ€ n β‰₯ N, |(f ∘ u) n - f xβ‚€| ≀ Ξ΅)) ↔ -- sorry βˆƒ u : β„• β†’ ℝ, (βˆ€ Ξ΄ > 0, βˆƒ N, βˆ€ n β‰₯ N, |u n - xβ‚€| ≀ Ξ΄) ∧ (βˆƒ Ξ΅ > 0, βˆ€ N, βˆƒ n β‰₯ N, |f (u n) - f xβ‚€| > Ξ΅) -- sorry := begin -- sorry check_me, -- sorry end end /- We now turn to elementary applications of negations to limits of sequences. Remember linarith can find easy numerical contradictions. Remember also the lemmas: abs_le (x y : ℝ) : |x| ≀ y ↔ -y ≀ x ∧ x ≀ y ge_max_iff (p q r) : r β‰₯ max p q ↔ r β‰₯ p ∧ r β‰₯ q le_max_left p q : p ≀ max p q le_max_right p q : q ≀ max p q /-- The sequence `u` tends to `+∞`. -/ def tendsto_infinity (u : β„• β†’ ℝ) := βˆ€ A, βˆƒ N, βˆ€ n β‰₯ N, u n β‰₯ A -/ -- 0066 example {u : β„• β†’ ℝ} : tendsto_infinity u β†’ βˆ€ l, Β¬ seq_limit u l := begin -- sorry intros lim_infinie l lim_l, cases lim_l 1 (by linarith) with N hN, cases lim_infinie (l+2) with N' hN', let Nβ‚€ := max N N', specialize hN Nβ‚€ (le_max_left _ _), specialize hN' Nβ‚€ (le_max_right _ _), rw abs_le at hN, linarith, -- sorry end def nondecreasing_seq (u : β„• β†’ ℝ) := βˆ€ n m, n ≀ m β†’ u n ≀ u m -- 0067 example (u : β„• β†’ ℝ) (l : ℝ) (h : seq_limit u l) (h' : nondecreasing_seq u) : βˆ€ n, u n ≀ l := begin -- sorry intro n, by_contradiction H, push_neg at H, cases h ((u n - l)/2) (by linarith) with N hN, specialize hN (max n N) (le_max_right _ _), specialize h' n (max n N) (le_max_left _ _), rw abs_le at hN, linarith, -- sorry end /- In the following exercises, `A : set ℝ` means that A is a set of real numbers. We can use the usual notation x ∈ A. The notation `βˆ€ x ∈ A, ...` is the abbreviation of `βˆ€ x, x ∈ A β†’ ... ` The notation `βˆƒ x ∈ A, ...` is the abbreviation of `βˆƒ x, x ∈ A ∧ ... `. More precisely it is the abbreviation of `βˆƒ x (H : x ∈ A), ...` which is Lean's strange way of saying `βˆƒ x, x ∈ A ∧ ... `. You can convert between both form using the lemma exists_prop {p q : Prop} : (βˆƒ (h : p), q) ↔ p ∧ q We'll work with upper bounds and supremums. Again we'll introduce specialized definitions for the sake of exercises, but mathlib has more general versions. def upper_bound (A : set ℝ) (x : ℝ) := βˆ€ a ∈ A, a ≀ x def is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ βˆ€ y, upper_bound A y β†’ x ≀ y Remark: one can easily show that a set of real numbers has at most one sup, but we won't need this. -/ -- 0068 example {A : set ℝ} {x : ℝ} (hx : is_sup A x) : βˆ€ y, y < x β†’ βˆƒ a ∈ A, y < a := begin -- sorry intro y, contrapose!, exact hx.right y, -- sorry end /- Let's do a variation on an example from file 07 that will be useful in the last exercise below. -/ -- 0069 lemma le_of_le_add_all' {x y : ℝ} : (βˆ€ Ξ΅ > 0, y ≀ x + Ξ΅) β†’ y ≀ x := begin -- sorry contrapose!, intro h, use (y-x)/2, split ; linarith, -- sorry end -- 0070 example {x y : ℝ} {u : β„• β†’ ℝ} (hu : seq_limit u x) (ineg : βˆ€ n, u n ≀ y) : x ≀ y := begin -- sorry apply le_of_le_add_all', intros Ξ΅ Ξ΅_pos, cases hu Ξ΅ Ξ΅_pos with N hN, specialize hN N (by linarith), rw abs_le at hN, linarith [ineg N], -- sorry end
9f2e3239193d2f268fcc8ca36c9ea195045619ac
f57749ca63d6416f807b770f67559503fdb21001
/library/data/nat/order.lean
e0ea1115470fa2a67ec0cf38f28608a0deb00351
[ "Apache-2.0" ]
permissive
aliassaf/lean
bd54e85bed07b1ff6f01396551867b2677cbc6ac
f9b069b6a50756588b309b3d716c447004203152
refs/heads/master
1,610,982,152,948
1,438,916,029,000
1,438,916,029,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
21,519
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad The order relation on the natural numbers. -/ import data.nat.basic algebra.ordered_ring open eq.ops namespace nat /- lt and le -/ theorem le_of_lt_or_eq {m n : β„•} (H : m < n ∨ m = n) : m ≀ n := le_of_eq_or_lt (or.swap H) theorem lt_or_eq_of_le {m n : β„•} (H : m ≀ n) : m < n ∨ m = n := or.swap (eq_or_lt_of_le H) theorem le_iff_lt_or_eq (m n : β„•) : m ≀ n ↔ m < n ∨ m = n := iff.intro lt_or_eq_of_le le_of_lt_or_eq theorem lt_of_le_and_ne {m n : β„•} (H1 : m ≀ n) : m β‰  n β†’ m < n := or_resolve_right (eq_or_lt_of_le H1) theorem lt_iff_le_and_ne (m n : β„•) : m < n ↔ m ≀ n ∧ m β‰  n := iff.intro (take H, and.intro (le_of_lt H) (take H1, !lt.irrefl (H1 β–Έ H))) (and.rec lt_of_le_and_ne) theorem le_add_right (n k : β„•) : n ≀ n + k := nat.rec !le.refl (Ξ» k, le_succ_of_le) k theorem le_add_left (n m : β„•): n ≀ m + n := !add.comm β–Έ !le_add_right theorem le.intro {n m k : β„•} (h : n + k = m) : n ≀ m := h β–Έ !le_add_right theorem le.elim {n m : β„•} : n ≀ m β†’ βˆƒk, n + k = m := le.rec (exists.intro 0 rfl) (Ξ»m h, Exists.rec (Ξ» k H, exists.intro (succ k) (H β–Έ rfl))) theorem le.total {m n : β„•} : m ≀ n ∨ n ≀ m := or.imp_left le_of_lt !lt_or_ge /- addition -/ theorem add_le_add_left {n m : β„•} (H : n ≀ m) (k : β„•) : k + n ≀ k + m := obtain l Hl, from le.elim H, le.intro (Hl β–Έ !add.assoc) theorem add_le_add_right {n m : β„•} (H : n ≀ m) (k : β„•) : n + k ≀ m + k := !add.comm β–Έ !add.comm β–Έ add_le_add_left H k theorem le_of_add_le_add_left {k n m : β„•} (H : k + n ≀ k + m) : n ≀ m := obtain l Hl, from le.elim H, le.intro (add.cancel_left (!add.assoc⁻¹ ⬝ Hl)) theorem lt_of_add_lt_add_left {k n m : β„•} (H : k + n < k + m) : n < m := let H' := le_of_lt H in lt_of_le_and_ne (le_of_add_le_add_left H') (assume Heq, !lt.irrefl (Heq β–Έ H)) theorem add_lt_add_left {n m : β„•} (H : n < m) (k : β„•) : k + n < k + m := lt_of_succ_le (!add_succ β–Έ add_le_add_left (succ_le_of_lt H) k) theorem add_lt_add_right {n m : β„•} (H : n < m) (k : β„•) : n + k < m + k := !add.comm β–Έ !add.comm β–Έ add_lt_add_left H k theorem lt_add_of_pos_right {n k : β„•} (H : k > 0) : n < n + k := !add_zero β–Έ add_lt_add_left H n /- multiplication -/ theorem mul_le_mul_left {n m : β„•} (k : β„•) (H : n ≀ m) : k * n ≀ k * m := obtain (l : β„•) (Hl : n + l = m), from le.elim H, have k * n + k * l = k * m, by rewrite [-mul.left_distrib, Hl], le.intro this theorem mul_le_mul_right {n m : β„•} (k : β„•) (H : n ≀ m) : n * k ≀ m * k := !mul.comm β–Έ !mul.comm β–Έ !mul_le_mul_left H theorem mul_le_mul {n m k l : β„•} (H1 : n ≀ k) (H2 : m ≀ l) : n * m ≀ k * l := le.trans (!mul_le_mul_right H1) (!mul_le_mul_left H2) theorem mul_lt_mul_of_pos_left {n m k : β„•} (H : n < m) (Hk : k > 0) : k * n < k * m := calc k * n < k * n + k : lt_add_of_pos_right Hk ... ≀ k * m : !mul_succ β–Έ mul_le_mul_left k (succ_le_of_lt H) theorem mul_lt_mul_of_pos_right {n m k : β„•} (H : n < m) (Hk : k > 0) : n * k < m * k := !mul.comm β–Έ !mul.comm β–Έ mul_lt_mul_of_pos_left H Hk /- min and max -/ /- definition max (a b : β„•) : β„• := if a < b then b else a definition min (a b : β„•) : β„• := if a < b then a else b theorem max_self [simp] (a : β„•) : max a a = a := eq.rec_on !if_t_t rfl theorem max_le {n m k : β„•} (H₁ : n ≀ k) (Hβ‚‚ : m ≀ k) : max n m ≀ k := if H : n < m then by rewrite [↑max, if_pos H]; apply Hβ‚‚ else by rewrite [↑max, if_neg H]; apply H₁ theorem min_le_left (n m : β„•) : min n m ≀ n := if H : n < m then by rewrite [↑min, if_pos H] else assert H' : m ≀ n, from or_resolve_right !lt_or_ge H, by rewrite [↑min, if_neg H]; apply H' theorem min_le_right (n m : β„•) : min n m ≀ m := if H : n < m then by rewrite [↑min, if_pos H]; apply le_of_lt H else assert H' : m ≀ n, from or_resolve_right !lt_or_ge H, by rewrite [↑min, if_neg H] theorem le_min {n m k : β„•} (H₁ : k ≀ n) (Hβ‚‚ : k ≀ m) : k ≀ min n m := if H : n < m then by rewrite [↑min, if_pos H]; apply H₁ else by rewrite [↑min, if_neg H]; apply Hβ‚‚ theorem eq_max_right {a b : β„•} (H : a < b) : b = max a b := (if_pos H)⁻¹ theorem eq_max_left {a b : β„•} (H : Β¬ a < b) : a = max a b := (if_neg H)⁻¹ open decidable theorem le_max_right (a b : β„•) : b ≀ max a b := lt.by_cases (suppose a < b, (eq_max_right this) β–Έ !le.refl) (suppose a = b, this β–Έ !max_self⁻¹ β–Έ !le.refl) (suppose b < a, (eq_max_left (lt.asymm this)) β–Έ (le_of_lt this)) theorem le_max_left (a b : β„•) : a ≀ max a b := if h : a < b then le_of_lt (eq.rec_on (eq_max_right h) h) else (eq_max_left h) β–Έ !le.refl -/ /- nat is an instance of a linearly ordered semiring and a lattice -/ section migrate_algebra open [classes] algebra local attribute nat.comm_semiring [instance] protected definition decidable_linear_ordered_semiring [reducible] : algebra.decidable_linear_ordered_semiring nat := ⦃ algebra.decidable_linear_ordered_semiring, nat.comm_semiring, add_left_cancel := @add.cancel_left, add_right_cancel := @add.cancel_right, lt := lt, le := le, le_refl := le.refl, le_trans := @le.trans, le_antisymm := @le.antisymm, le_total := @le.total, le_iff_lt_or_eq := @le_iff_lt_or_eq, le_of_lt := @le_of_lt, lt_irrefl := @lt.irrefl, lt_of_lt_of_le := @lt_of_lt_of_le, lt_of_le_of_lt := @lt_of_le_of_lt, lt_of_add_lt_add_left := @lt_of_add_lt_add_left, add_lt_add_left := @add_lt_add_left, add_le_add_left := @add_le_add_left, le_of_add_le_add_left := @le_of_add_le_add_left, zero_lt_one := zero_lt_succ 0, mul_le_mul_of_nonneg_left := (take a b c H1 H2, mul_le_mul_left c H1), mul_le_mul_of_nonneg_right := (take a b c H1 H2, mul_le_mul_right c H1), mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left, mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right, decidable_lt := nat.decidable_lt ⦄ /- protected definition lattice [reducible] : algebra.lattice nat := ⦃ algebra.lattice, nat.linear_ordered_semiring, min := min, max := max, min_le_left := min_le_left, min_le_right := min_le_right, le_min := @le_min, le_max_left := le_max_left, le_max_right := le_max_right, max_le := @max_le ⦄ local attribute nat.linear_ordered_semiring [instance] local attribute nat.lattice [instance] -/ local attribute nat.decidable_linear_ordered_semiring [instance] definition min : β„• β†’ β„• β†’ β„• := algebra.min definition max : β„• β†’ β„• β†’ β„• := algebra.max migrate from algebra with nat replacing dvd β†’ dvd, has_le.ge β†’ ge, has_lt.gt β†’ gt, min β†’ min, max β†’ max hiding add_pos_of_pos_of_nonneg, add_pos_of_nonneg_of_pos, add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg, le_add_of_nonneg_of_le, le_add_of_le_of_nonneg, lt_add_of_nonneg_of_lt, lt_add_of_lt_of_nonneg, lt_of_mul_lt_mul_left, lt_of_mul_lt_mul_right, pos_of_mul_pos_left, pos_of_mul_pos_right, mul_lt_mul attribute le.trans ge.trans lt.trans gt.trans [trans] attribute lt_of_lt_of_le lt_of_le_of_lt gt_of_gt_of_ge gt_of_ge_of_gt [trans] theorem add_pos_left {a : β„•} (H : 0 < a) (b : β„•) : 0 < a + b := @algebra.add_pos_of_pos_of_nonneg _ _ a b H !zero_le theorem add_pos_right {a : β„•} (H : 0 < a) (b : β„•) : 0 < b + a := !add.comm β–Έ add_pos_left H b theorem add_eq_zero_iff_eq_zero_and_eq_zero {a b : β„•} : a + b = 0 ↔ a = 0 ∧ b = 0 := @algebra.add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg _ _ a b !zero_le !zero_le theorem le_add_of_le_left {a b c : β„•} (H : b ≀ c) : b ≀ a + c := @algebra.le_add_of_nonneg_of_le _ _ a b c !zero_le H theorem le_add_of_le_right {a b c : β„•} (H : b ≀ c) : b ≀ c + a := @algebra.le_add_of_le_of_nonneg _ _ a b c H !zero_le theorem lt_add_of_lt_left {b c : β„•} (H : b < c) (a : β„•) : b < a + c := @algebra.lt_add_of_nonneg_of_lt _ _ a b c !zero_le H theorem lt_add_of_lt_right {b c : β„•} (H : b < c) (a : β„•) : b < c + a := @algebra.lt_add_of_lt_of_nonneg _ _ a b c H !zero_le theorem lt_of_mul_lt_mul_left {a b c : β„•} (H : c * a < c * b) : a < b := @algebra.lt_of_mul_lt_mul_left _ _ a b c H !zero_le theorem lt_of_mul_lt_mul_right {a b c : β„•} (H : a * c < b * c) : a < b := @algebra.lt_of_mul_lt_mul_right _ _ a b c H !zero_le theorem pos_of_mul_pos_left {a b : β„•} (H : 0 < a * b) : 0 < b := @algebra.pos_of_mul_pos_left _ _ a b H !zero_le theorem pos_of_mul_pos_right {a b : β„•} (H : 0 < a * b) : 0 < a := @algebra.pos_of_mul_pos_right _ _ a b H !zero_le end migrate_algebra theorem zero_le_one : 0 ≀ 1 := dec_trivial /- properties specific to nat -/ theorem lt_intro {n m k : β„•} (H : succ n + k = m) : n < m := lt_of_succ_le (le.intro H) theorem lt_elim {n m : β„•} (H : n < m) : βˆƒk, succ n + k = m := le.elim (succ_le_of_lt H) theorem lt_add_succ (n m : β„•) : n < n + succ m := lt_intro !succ_add_eq_succ_add theorem eq_zero_of_le_zero {n : β„•} (H : n ≀ 0) : n = 0 := obtain (k : β„•) (Hk : n + k = 0), from le.elim H, eq_zero_of_add_eq_zero_right Hk /- succ and pred -/ theorem le_of_lt_succ {m n : nat} : m < succ n β†’ m ≀ n := le_of_succ_le_succ theorem lt_iff_succ_le (m n : nat) : m < n ↔ succ m ≀ n := iff.rfl theorem lt_succ_iff_le (m n : nat) : m < succ n ↔ m ≀ n := iff.intro le_of_lt_succ lt_succ_of_le theorem self_le_succ (n : β„•) : n ≀ succ n := le.intro !add_one theorem succ_le_or_eq_of_le {n m : β„•} : n ≀ m β†’ succ n ≀ m ∨ n = m := lt_or_eq_of_le theorem pred_le_of_le_succ {n m : β„•} : n ≀ succ m β†’ pred n ≀ m := pred_le_pred theorem succ_le_of_le_pred {n m : β„•} : succ n ≀ m β†’ n ≀ pred m := pred_le_pred theorem pred_le_pred_of_le {n m : β„•} : n ≀ m β†’ pred n ≀ pred m := pred_le_pred theorem pre_lt_of_lt {n m : β„•} : n < m β†’ pred n < m := lt_of_le_of_lt !pred_le theorem lt_of_pred_lt_pred {n m : β„•} (H : pred n < pred m) : n < m := lt_of_not_ge (suppose m ≀ n, not_lt_of_ge (pred_le_pred_of_le this) H) theorem le_or_eq_succ_of_le_succ {n m : β„•} (H : n ≀ succ m) : n ≀ m ∨ n = succ m := or.imp_left le_of_succ_le_succ (succ_le_or_eq_of_le H) theorem le_pred_self (n : β„•) : pred n ≀ n := !pred_le theorem succ_pos (n : β„•) : 0 < succ n := !zero_lt_succ theorem succ_pred_of_pos {n : β„•} (H : n > 0) : succ (pred n) = n := (or_resolve_right (eq_zero_or_eq_succ_pred n) (ne.symm (ne_of_lt H)))⁻¹ theorem exists_eq_succ_of_lt {n : β„•} : Ξ  {m : β„•}, n < m β†’ βˆƒk, m = succ k | 0 H := absurd H !not_lt_zero | (succ k) H := exists.intro k rfl theorem lt_succ_self (n : β„•) : n < succ n := lt.base n lemma lt_succ_of_lt {i j : nat} : i < j β†’ i < succ j := assume Plt, lt.trans Plt (self_lt_succ j) /- other forms of induction -/ protected definition strong_rec_on {P : nat β†’ Type} (n : β„•) (H : βˆ€n, (βˆ€m, m < n β†’ P m) β†’ P n) : P n := nat.rec (Ξ»m, not.elim !not_lt_zero) (Ξ»n' (IH : βˆ€ {m : β„•}, m < n' β†’ P m) m l, or.by_cases (lt_or_eq_of_le (le_of_lt_succ l)) IH (Ξ» e, eq.rec (H n' @IH) e⁻¹)) (succ n) n !lt_succ_self protected theorem strong_induction_on {P : nat β†’ Prop} (n : β„•) (H : βˆ€n, (βˆ€m, m < n β†’ P m) β†’ P n) : P n := nat.strong_rec_on n H protected theorem case_strong_induction_on {P : nat β†’ Prop} (a : nat) (H0 : P 0) (Hind : βˆ€(n : nat), (βˆ€m, m ≀ n β†’ P m) β†’ P (succ n)) : P a := nat.strong_induction_on a (take n, show (βˆ€ m, m < n β†’ P m) β†’ P n, from nat.cases_on n (suppose (βˆ€ m, m < 0 β†’ P m), show P 0, from H0) (take n, suppose (βˆ€ m, m < succ n β†’ P m), show P (succ n), from Hind n (take m, assume H1 : m ≀ n, this _ (lt_succ_of_le H1)))) /- pos -/ theorem by_cases_zero_pos {P : β„• β†’ Prop} (y : β„•) (H0 : P 0) (H1 : βˆ€ {y : nat}, y > 0 β†’ P y) : P y := nat.cases_on y H0 (take y, H1 !succ_pos) theorem eq_zero_or_pos (n : β„•) : n = 0 ∨ n > 0 := or_of_or_of_imp_left (or.swap (lt_or_eq_of_le !zero_le)) (suppose 0 = n, by subst n) theorem pos_of_ne_zero {n : β„•} (H : n β‰  0) : n > 0 := or.elim !eq_zero_or_pos (take H2 : n = 0, by contradiction) (take H2 : n > 0, H2) theorem ne_zero_of_pos {n : β„•} (H : n > 0) : n β‰  0 := ne.symm (ne_of_lt H) theorem exists_eq_succ_of_pos {n : β„•} (H : n > 0) : exists l, n = succ l := exists_eq_succ_of_lt H theorem pos_of_dvd_of_pos {m n : β„•} (H1 : m ∣ n) (H2 : n > 0) : m > 0 := pos_of_ne_zero (suppose m = 0, assert n = 0, from eq_zero_of_zero_dvd (this β–Έ H1), ne_of_lt H2 (by subst n)) /- multiplication -/ theorem mul_lt_mul_of_le_of_lt {n m k l : β„•} (Hk : k > 0) (H1 : n ≀ k) (H2 : m < l) : n * m < k * l := lt_of_le_of_lt (mul_le_mul_right m H1) (mul_lt_mul_of_pos_left H2 Hk) theorem mul_lt_mul_of_lt_of_le {n m k l : β„•} (Hl : l > 0) (H1 : n < k) (H2 : m ≀ l) : n * m < k * l := lt_of_le_of_lt (mul_le_mul_left n H2) (mul_lt_mul_of_pos_right H1 Hl) theorem mul_lt_mul_of_le_of_le {n m k l : β„•} (H1 : n < k) (H2 : m < l) : n * m < k * l := have H3 : n * m ≀ k * m, from mul_le_mul_right m (le_of_lt H1), have H4 : k * m < k * l, from mul_lt_mul_of_pos_left H2 (lt_of_le_of_lt !zero_le H1), lt_of_le_of_lt H3 H4 theorem eq_of_mul_eq_mul_left {m k n : β„•} (Hn : n > 0) (H : n * m = n * k) : m = k := have n * m ≀ n * k, by rewrite H, have m ≀ k, from le_of_mul_le_mul_left this Hn, have n * k ≀ n * m, by rewrite H, have k ≀ m, from le_of_mul_le_mul_left this Hn, le.antisymm `m ≀ k` this theorem eq_of_mul_eq_mul_right {n m k : β„•} (Hm : m > 0) (H : n * m = k * m) : n = k := eq_of_mul_eq_mul_left Hm (!mul.comm β–Έ !mul.comm β–Έ H) theorem eq_zero_or_eq_of_mul_eq_mul_left {n m k : β„•} (H : n * m = n * k) : n = 0 ∨ m = k := or_of_or_of_imp_right !eq_zero_or_pos (assume Hn : n > 0, eq_of_mul_eq_mul_left Hn H) theorem eq_zero_or_eq_of_mul_eq_mul_right {n m k : β„•} (H : n * m = k * m) : m = 0 ∨ n = k := eq_zero_or_eq_of_mul_eq_mul_left (!mul.comm β–Έ !mul.comm β–Έ H) theorem eq_one_of_mul_eq_one_right {n m : β„•} (H : n * m = 1) : n = 1 := have H2 : n * m > 0, by rewrite H; apply succ_pos, or.elim (le_or_gt n 1) (suppose n ≀ 1, have n > 0, from pos_of_mul_pos_right H2, show n = 1, from le.antisymm `n ≀ 1` (succ_le_of_lt this)) (suppose n > 1, have m > 0, from pos_of_mul_pos_left H2, have n * m β‰₯ 2 * 1, from mul_le_mul (succ_le_of_lt `n > 1`) (succ_le_of_lt this), have 1 β‰₯ 2, from !mul_one β–Έ H β–Έ this, absurd !lt_succ_self (not_lt_of_ge this)) theorem eq_one_of_mul_eq_one_left {n m : β„•} (H : n * m = 1) : m = 1 := eq_one_of_mul_eq_one_right (!mul.comm β–Έ H) theorem eq_one_of_mul_eq_self_left {n m : β„•} (Hpos : n > 0) (H : m * n = n) : m = 1 := eq_of_mul_eq_mul_right Hpos (H ⬝ !one_mul⁻¹) theorem eq_one_of_mul_eq_self_right {n m : β„•} (Hpos : m > 0) (H : m * n = m) : n = 1 := eq_one_of_mul_eq_self_left Hpos (!mul.comm β–Έ H) theorem eq_one_of_dvd_one {n : β„•} (H : n ∣ 1) : n = 1 := dvd.elim H (take m, suppose 1 = n * m, eq_one_of_mul_eq_one_right this⁻¹) /- min and max -/ open decidable theorem le_max_left_iff_true [simp] (a b : β„•) : a ≀ max a b ↔ true := iff_true_intro (le_max_left a b) theorem le_max_right_iff_true [simp] (a b : β„•) : b ≀ max a b ↔ true := iff_true_intro (le_max_right a b) theorem min_zero [simp] (a : β„•) : min a 0 = 0 := by rewrite [min_eq_right !zero_le] theorem zero_min [simp] (a : β„•) : min 0 a = 0 := by rewrite [min_eq_left !zero_le] theorem max_zero [simp] (a : β„•) : max a 0 = a := by rewrite [max_eq_left !zero_le] theorem zero_max [simp] (a : β„•) : max 0 a = a := by rewrite [max_eq_right !zero_le] theorem min_succ_succ [simp] (a b : β„•) : min (succ a) (succ b) = succ (min a b) := or.elim !lt_or_ge (suppose a < b, by rewrite [min_eq_left_of_lt this, min_eq_left_of_lt (succ_lt_succ this)]) (suppose a β‰₯ b, by rewrite [min_eq_right this, min_eq_right (succ_le_succ this)]) theorem max_succ_succ [simp] (a b : β„•) : max (succ a) (succ b) = succ (max a b) := or.elim !lt_or_ge (suppose a < b, by rewrite [max_eq_right_of_lt this, max_eq_right_of_lt (succ_lt_succ this)]) (suppose a β‰₯ b, by rewrite [max_eq_left this, max_eq_left (succ_le_succ this)]) /- In algebra.ordered_group, these next four are only proved for additive groups, not additive semigroups. -/ theorem min_add_add_left (a b c : β„•) : min (a + b) (a + c) = a + min b c := decidable.by_cases (suppose b ≀ c, assert a + b ≀ a + c, from add_le_add_left this _, by rewrite [min_eq_left `b ≀ c`, min_eq_left this]) (suppose Β¬ b ≀ c, assert c ≀ b, from le_of_lt (lt_of_not_ge this), assert a + c ≀ a + b, from add_le_add_left this _, by rewrite [min_eq_right `c ≀ b`, min_eq_right this]) theorem min_add_add_right (a b c : β„•) : min (a + c) (b + c) = min a b + c := by rewrite [add.comm a c, add.comm b c, add.comm _ c]; apply min_add_add_left theorem max_add_add_left (a b c : β„•) : max (a + b) (a + c) = a + max b c := decidable.by_cases (suppose b ≀ c, assert a + b ≀ a + c, from add_le_add_left this _, by rewrite [max_eq_right `b ≀ c`, max_eq_right this]) (suppose Β¬ b ≀ c, assert c ≀ b, from le_of_lt (lt_of_not_ge this), assert a + c ≀ a + b, from add_le_add_left this _, by rewrite [max_eq_left `c ≀ b`, max_eq_left this]) theorem max_add_add_right (a b c : β„•) : max (a + c) (b + c) = max a b + c := by rewrite [add.comm a c, add.comm b c, add.comm _ c]; apply max_add_add_left /- least and greatest -/ section least_and_greatest variable (P : β„• β†’ Prop) variable [decP : βˆ€ n, decidable (P n)] include decP -- returns the least i < n satisfying P, or n if there is none definition least : β„• β†’ β„• | 0 := 0 | (succ n) := if P (least n) then least n else succ n theorem least_of_bound {n : β„•} (H : P n) : P (least P n) := begin induction n with [m, ih], rewrite ↑least, apply H, rewrite ↑least, cases decidable.em (P (least P m)) with [Hlp, Hlp], rewrite [if_pos Hlp], apply Hlp, rewrite [if_neg Hlp], apply H end theorem least_le (n : β„•) : least P n ≀ n:= begin induction n with [m, ih], {rewrite ↑least}, rewrite ↑least, cases decidable.em (P (least P m)) with [Psm, Pnsm], rewrite [if_pos Psm], apply le.trans ih !le_succ, rewrite [if_neg Pnsm] end theorem least_of_lt {i n : β„•} (ltin : i < n) (H : P i) : P (least P n) := begin induction n with [m, ih], exact absurd ltin !not_lt_zero, rewrite ↑least, cases decidable.em (P (least P m)) with [Psm, Pnsm], rewrite [if_pos Psm], apply Psm, rewrite [if_neg Pnsm], cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq], exact absurd (ih Hlt) Pnsm, rewrite Heq at H, exact absurd (least_of_bound P H) Pnsm end theorem ge_least_of_lt {i n : β„•} (ltin : i < n) (Hi : P i) : i β‰₯ least P n := begin induction n with [m, ih], exact absurd ltin !not_lt_zero, rewrite ↑least, cases decidable.em (P (least P m)) with [Psm, Pnsm], rewrite [if_pos Psm], cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq], apply ih Hlt, rewrite Heq, apply least_le, rewrite [if_neg Pnsm], cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq], apply absurd (least_of_lt P Hlt Hi) Pnsm, rewrite Heq at Hi, apply absurd (least_of_bound P Hi) Pnsm end theorem least_lt {n i : β„•} (ltin : i < n) (Hi : P i) : least P n < n := lt_of_le_of_lt (ge_least_of_lt P ltin Hi) ltin -- returns the largest i < n satisfying P, or n if there is none. definition greatest : β„• β†’ β„• | 0 := 0 | (succ n) := if P n then n else greatest n theorem greatest_of_lt {i n : β„•} (ltin : i < n) (Hi : P i) : P (greatest P n) := begin induction n with [m, ih], {exact absurd ltin !not_lt_zero}, {cases (decidable.em (P m)) with [Psm, Pnsm], {rewrite [↑greatest, if_pos Psm]; exact Psm}, {rewrite [↑greatest, if_neg Pnsm], have neim : i β‰  m, from assume H : i = m, absurd (H β–Έ Hi) Pnsm, have ltim : i < m, from lt_of_le_of_ne (le_of_lt_succ ltin) neim, apply ih ltim}} end theorem le_greatest_of_lt {i n : β„•} (ltin : i < n) (Hi : P i) : i ≀ greatest P n := begin induction n with [m, ih], {exact absurd ltin !not_lt_zero}, {cases (decidable.em (P m)) with [Psm, Pnsm], {rewrite [↑greatest, if_pos Psm], apply le_of_lt_succ ltin}, {rewrite [↑greatest, if_neg Pnsm], have neim : i β‰  m, from assume H : i = m, absurd (H β–Έ Hi) Pnsm, have ltim : i < m, from lt_of_le_of_ne (le_of_lt_succ ltin) neim, apply ih ltim}} end end least_and_greatest end nat
a76eff320b684e4c80e561ba291f257ce5e2772f
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/topology/sheaves/presheaf.lean
2972579fbd3a285d29d510bc9be25362c810f68e
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
2,221
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Mario Carneiro, Reid Barton -/ import topology.category.Top.opens import category_theory.whiskering universes v u open category_theory open topological_space open opposite variables (C : Type u) [π’ž : category.{v} C] include π’ž namespace Top def presheaf (X : Top.{v}) := (opens X)α΅’α΅– β₯€ C instance category_presheaf (X : Top.{v}) : category (X.presheaf C) := by dsimp [presheaf]; apply_instance namespace presheaf variables {C} def pushforward {X Y : Top.{v}} (f : X ⟢ Y) (β„± : X.presheaf C) : Y.presheaf C := (opens.map f).op β‹™ β„± infix ` _* `: 80 := pushforward def pushforward_eq {X Y : Top.{v}} {f g : X ⟢ Y} (h : f = g) (β„± : X.presheaf C) : f _* β„± β‰… g _* β„± := iso_whisker_right (nat_iso.op (opens.map_iso f g h).symm) β„± lemma pushforward_eq_eq {X Y : Top.{v}} {f g : X ⟢ Y} (h₁ hβ‚‚ : f = g) (β„± : X.presheaf C) : β„±.pushforward_eq h₁ = β„±.pushforward_eq hβ‚‚ := rfl namespace pushforward variables {X : Top.{v}} (β„± : X.presheaf C) def id : (πŸ™ X) _* β„± β‰… β„± := (iso_whisker_right (nat_iso.op (opens.map_id X).symm) β„±) β‰ͺ≫ functor.left_unitor _ @[simp] lemma id_hom_app' (U) (p) : (id β„±).hom.app (op ⟨U, p⟩) = β„±.map (πŸ™ (op ⟨U, p⟩)) := by { dsimp [id], simp, } local attribute [tidy] tactic.op_induction' @[simp, priority 990] lemma id_hom_app (U) : (id β„±).hom.app U = β„±.map (eq_to_hom (opens.op_map_id_obj U)) := by tidy @[simp] lemma id_inv_app' (U) (p) : (id β„±).inv.app (op ⟨U, p⟩) = β„±.map (πŸ™ (op ⟨U, p⟩)) := by { dsimp [id], simp, } def comp {Y Z : Top.{v}} (f : X ⟢ Y) (g : Y ⟢ Z) : (f ≫ g) _* β„± β‰… g _* (f _* β„±) := iso_whisker_right (nat_iso.op (opens.map_comp f g).symm) β„± @[simp] lemma comp_hom_app {Y Z : Top.{v}} (f : X ⟢ Y) (g : Y ⟢ Z) (U) : (comp β„± f g).hom.app U = πŸ™ _ := begin dsimp [pushforward, comp], tidy, end @[simp] lemma comp_inv_app {Y Z : Top.{v}} (f : X ⟢ Y) (g : Y ⟢ Z) (U) : (comp β„± f g).inv.app U = πŸ™ _ := begin dsimp [pushforward, comp], tidy, end end pushforward end presheaf end Top
0aa748970db4fad8807df7a762c423b64f642829
4fa161becb8ce7378a709f5992a594764699e268
/src/group_theory/submonoid.lean
3792cdc2a325db46e5d20ecc98b95496b3f6480c
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
32,109
lean
/- Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import algebra.big_operators import algebra.free_monoid import algebra.group.prod import data.equiv.mul_add /-! # Submonoids This file defines bundled multiplicative and additive submonoids. We prove submonoids of a monoid form a complete lattice, and results about images and preimages of submonoids under monoid homomorphisms. There are also theorems about the submonoids generated by an element or a subset of a monoid, defined as the infimum of the set of submonoids containing a given element/subset. ## Implementation notes Submonoid inclusion is denoted `≀` rather than `βŠ†`, although `∈` is defined as membership of a submonoid's underlying set. ## Tags submonoid, submonoids -/ open_locale big_operators variables {M : Type*} [monoid M] {s : set M} variables {A : Type*} [add_monoid A] {t : set A} /-- A submonoid of a monoid `M` is a subset containing 1 and closed under multiplication. -/ structure submonoid (M : Type*) [monoid M] := (carrier : set M) (one_mem' : (1 : M) ∈ carrier) (mul_mem' {a b} : a ∈ carrier β†’ b ∈ carrier β†’ a * b ∈ carrier) /-- An additive submonoid of an additive monoid `M` is a subset containing 0 and closed under addition. -/ structure add_submonoid (M : Type*) [add_monoid M] := (carrier : set M) (zero_mem' : (0 : M) ∈ carrier) (add_mem' {a b} : a ∈ carrier β†’ b ∈ carrier β†’ a + b ∈ carrier) attribute [to_additive add_submonoid] submonoid /-- Map from submonoids of monoid `M` to `add_submonoid`s of `additive M`. -/ def submonoid.to_add_submonoid {M : Type*} [monoid M] (S : submonoid M) : add_submonoid (additive M) := { carrier := S.carrier, zero_mem' := S.one_mem', add_mem' := S.mul_mem' } /-- Map from `add_submonoid`s of `additive M` to submonoids of `M`. -/ def submonoid.of_add_submonoid {M : Type*} [monoid M] (S : add_submonoid (additive M)) : submonoid M := { carrier := S.carrier, one_mem' := S.zero_mem', mul_mem' := S.add_mem' } /-- Map from `add_submonoid`s of `add_monoid M` to submonoids of `multiplicative M`. -/ def add_submonoid.to_submonoid {M : Type*} [add_monoid M] (S : add_submonoid M) : submonoid (multiplicative M) := { carrier := S.carrier, one_mem' := S.zero_mem', mul_mem' := S.add_mem' } /-- Map from submonoids of `multiplicative M` to `add_submonoid`s of `add_monoid M`. -/ def add_submonoid.of_submonoid {M : Type*} [add_monoid M] (S : submonoid (multiplicative M)) : add_submonoid M := { carrier := S.carrier, zero_mem' := S.one_mem', add_mem' := S.mul_mem' } /-- Submonoids of monoid `M` are isomorphic to additive submonoids of `additive M`. -/ def submonoid.add_submonoid_equiv (M : Type*) [monoid M] : submonoid M ≃ add_submonoid (additive M) := { to_fun := submonoid.to_add_submonoid, inv_fun := submonoid.of_add_submonoid, left_inv := Ξ» x, by cases x; refl, right_inv := Ξ» x, by cases x; refl } namespace submonoid @[to_additive] instance : has_coe (submonoid M) (set M) := ⟨submonoid.carrier⟩ @[to_additive] instance : has_coe_to_sort (submonoid M) := ⟨Type*, Ξ» S, S.carrier⟩ @[to_additive] instance : has_mem M (submonoid M) := ⟨λ m S, m ∈ (S:set M)⟩ @[simp, to_additive] lemma mem_carrier {s : submonoid M} {x : M} : x ∈ s.carrier ↔ x ∈ s := iff.rfl @[simp, norm_cast, to_additive] lemma mem_coe {S : submonoid M} {m : M} : m ∈ (S : set M) ↔ m ∈ S := iff.rfl @[simp, norm_cast, to_additive] lemma coe_coe (s : submonoid M) : β†₯(s : set M) = s := rfl attribute [norm_cast] add_submonoid.mem_coe add_submonoid.coe_coe end submonoid @[to_additive] protected lemma submonoid.exists {s : submonoid M} {p : s β†’ Prop} : (βˆƒ x : s, p x) ↔ βˆƒ x ∈ s, p ⟨x, β€Ήx ∈ sβ€ΊβŸ© := set_coe.exists @[to_additive] protected lemma submonoid.forall {s : submonoid M} {p : s β†’ Prop} : (βˆ€ x : s, p x) ↔ βˆ€ x ∈ s, p ⟨x, β€Ήx ∈ sβ€ΊβŸ© := set_coe.forall namespace submonoid variables (S : submonoid M) /-- Two submonoids are equal if the underlying subsets are equal. -/ @[to_additive "Two `add_submonoid`s are equal if the underlying subsets are equal."] theorem ext' ⦃S T : submonoid M⦄ (h : (S : set M) = T) : S = T := by cases S; cases T; congr' /-- Two submonoids are equal if and only if the underlying subsets are equal. -/ @[to_additive "Two `add_submonoid`s are equal if and only if the underlying subsets are equal."] protected theorem ext'_iff {S T : submonoid M} : S = T ↔ (S : set M) = T := ⟨λ h, h β–Έ rfl, Ξ» h, ext' h⟩ /-- Two submonoids are equal if they have the same elements. -/ @[ext, to_additive "Two `add_submonoid`s are equal if they have the same elements."] theorem ext {S T : submonoid M} (h : βˆ€ x, x ∈ S ↔ x ∈ T) : S = T := ext' $ set.ext h attribute [ext] add_submonoid.ext /-- Copy a submonoid replacing `carrier` with a set that is equal to it. -/ @[to_additive "Copy an additive submonoid replacing `carrier` with a set that is equal to it."] def copy (S : submonoid M) (s : set M) (hs : s = S) : submonoid M := { carrier := s, one_mem' := hs.symm β–Έ S.one_mem', mul_mem' := hs.symm β–Έ S.mul_mem' } @[simp, to_additive] lemma coe_copy {S : submonoid M} {s : set M} (hs : s = S) : (S.copy s hs : set M) = s := rfl @[to_additive] lemma copy_eq {S : submonoid M} {s : set M} (hs : s = S) : S.copy s hs = S := ext' hs /-- A submonoid contains the monoid's 1. -/ @[to_additive "An `add_submonoid` contains the monoid's 0."] theorem one_mem : (1 : M) ∈ S := S.one_mem' /-- A submonoid is closed under multiplication. -/ @[to_additive "An `add_submonoid` is closed under addition."] theorem mul_mem {x y : M} : x ∈ S β†’ y ∈ S β†’ x * y ∈ S := submonoid.mul_mem' S /-- Product of a list of elements in a submonoid is in the submonoid. -/ @[to_additive "Sum of a list of elements in an `add_submonoid` is in the `add_submonoid`."] lemma list_prod_mem : βˆ€ {l : list M}, (βˆ€x ∈ l, x ∈ S) β†’ l.prod ∈ S | [] h := S.one_mem | (a::l) h := suffices a * l.prod ∈ S, by rwa [list.prod_cons], have a ∈ S ∧ (βˆ€ x ∈ l, x ∈ S), from list.forall_mem_cons.1 h, S.mul_mem this.1 (list_prod_mem this.2) /-- Product of a multiset of elements in a submonoid of a `comm_monoid` is in the submonoid. -/ @[to_additive "Sum of a multiset of elements in an `add_submonoid` of an `add_comm_monoid` is in the `add_submonoid`."] lemma multiset_prod_mem {M} [comm_monoid M] (S : submonoid M) (m : multiset M) : (βˆ€a ∈ m, a ∈ S) β†’ m.prod ∈ S := begin refine quotient.induction_on m (assume l hl, _), rw [multiset.quot_mk_to_coe, multiset.coe_prod], exact S.list_prod_mem hl end /-- Product of elements of a submonoid of a `comm_monoid` indexed by a `finset` is in the submonoid. -/ @[to_additive "Sum of elements in an `add_submonoid` of an `add_comm_monoid` indexed by a `finset` is in the `add_submonoid`."] lemma prod_mem {M : Type*} [comm_monoid M] (S : submonoid M) {ΞΉ : Type*} {t : finset ΞΉ} {f : ΞΉ β†’ M} (h : βˆ€c ∈ t, f c ∈ S) : ∏ c in t, f c ∈ S := S.multiset_prod_mem (t.1.map f) $ Ξ» x hx, let ⟨i, hi, hix⟩ := multiset.mem_map.1 hx in hix β–Έ h i hi lemma pow_mem {x : M} (hx : x ∈ S) : βˆ€ n:β„•, x^n ∈ S | 0 := S.one_mem | (n+1) := S.mul_mem hx (pow_mem n) /-- A submonoid of a monoid inherits a multiplication. -/ @[to_additive "An `add_submonoid` of an `add_monoid` inherits an addition."] instance has_mul : has_mul S := ⟨λ a b, ⟨a.1 * b.1, S.mul_mem a.2 b.2⟩⟩ /-- A submonoid of a monoid inherits a 1. -/ @[to_additive "An `add_submonoid` of an `add_monoid` inherits a zero."] instance has_one : has_one S := ⟨⟨_, S.one_mem⟩⟩ @[simp, to_additive] lemma coe_mul (x y : S) : (↑(x * y) : M) = ↑x * ↑y := rfl @[simp, to_additive] lemma coe_one : ((1 : S) : M) = 1 := rfl @[simp, to_additive] lemma coe_eq_coe (x y : S) : (x : M) = y ↔ x = y := set_coe.ext_iff attribute [norm_cast] coe_eq_coe coe_mul coe_one attribute [norm_cast] add_submonoid.coe_eq_coe add_submonoid.coe_add add_submonoid.coe_zero /-- A submonoid of a monoid inherits a monoid structure. -/ @[to_additive to_add_monoid "An `add_submonoid` of an `add_monoid` inherits an `add_monoid` structure."] instance to_monoid {M : Type*} [monoid M] (S : submonoid M) : monoid S := by refine { mul := (*), one := 1, .. }; simp [mul_assoc, ← submonoid.coe_eq_coe] /-- A submonoid of a `comm_monoid` is a `comm_monoid`. -/ @[to_additive to_add_comm_monoid "An `add_submonoid` of an `add_comm_monoid` is an `add_comm_monoid`."] instance to_comm_monoid {M} [comm_monoid M] (S : submonoid M) : comm_monoid S := { mul_comm := Ξ» _ _, subtype.eq $ mul_comm _ _, ..S.to_monoid} /-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/ @[to_additive "The natural monoid hom from an `add_submonoid` of `add_monoid` `M` to `M`."] def subtype : S β†’* M := ⟨coe, rfl, Ξ» _ _, rfl⟩ @[simp, to_additive] theorem coe_subtype : ⇑S.subtype = coe := rfl @[to_additive] instance : has_le (submonoid M) := ⟨λ S T, βˆ€ ⦃x⦄, x ∈ S β†’ x ∈ T⟩ @[to_additive] lemma le_def {S T : submonoid M} : S ≀ T ↔ βˆ€ ⦃x : M⦄, x ∈ S β†’ x ∈ T := iff.rfl @[simp, norm_cast, to_additive] lemma coe_subset_coe {S T : submonoid M} : (S : set M) βŠ† T ↔ S ≀ T := iff.rfl @[to_additive] instance : partial_order (submonoid M) := { le := Ξ» S T, βˆ€ ⦃x⦄, x ∈ S β†’ x ∈ T, .. partial_order.lift (coe : submonoid M β†’ set M) ext' } @[simp, norm_cast, to_additive] lemma coe_ssubset_coe {S T : submonoid M} : (S : set M) βŠ‚ T ↔ S < T := iff.rfl attribute [norm_cast] add_submonoid.coe_subset_coe add_submonoid.coe_ssubset_coe /-- The submonoid `M` of the monoid `M`. -/ @[to_additive "The `add_submonoid M` of the `add_monoid M`."] instance : has_top (submonoid M) := ⟨{ carrier := set.univ, one_mem' := set.mem_univ 1, mul_mem' := Ξ» _ _ _ _, set.mem_univ _ }⟩ /-- The trivial submonoid `{1}` of an monoid `M`. -/ @[to_additive "The trivial `add_submonoid` `{0}` of an `add_monoid` `M`."] instance : has_bot (submonoid M) := ⟨{ carrier := {1}, one_mem' := set.mem_singleton 1, mul_mem' := Ξ» a b ha hb, by { simp only [set.mem_singleton_iff] at *, rw [ha, hb, mul_one] }}⟩ @[to_additive] instance : inhabited (submonoid M) := ⟨βŠ₯⟩ @[simp, to_additive] lemma mem_bot {x : M} : x ∈ (βŠ₯ : submonoid M) ↔ x = 1 := set.mem_singleton_iff @[simp, to_additive] lemma mem_top (x : M) : x ∈ (⊀ : submonoid M) := set.mem_univ x @[simp, to_additive] lemma coe_top : ((⊀ : submonoid M) : set M) = set.univ := rfl @[simp, to_additive] lemma coe_bot : ((βŠ₯ : submonoid M) : set M) = {1} := rfl /-- The inf of two submonoids is their intersection. -/ @[to_additive "The inf of two `add_submonoid`s is their intersection."] instance : has_inf (submonoid M) := ⟨λ S₁ Sβ‚‚, { carrier := S₁ ∩ Sβ‚‚, one_mem' := ⟨S₁.one_mem, Sβ‚‚.one_mem⟩, mul_mem' := Ξ» _ _ ⟨hx, hx'⟩ ⟨hy, hy'⟩, ⟨S₁.mul_mem hx hy, Sβ‚‚.mul_mem hx' hy'⟩ }⟩ @[simp, to_additive] lemma coe_inf (p p' : submonoid M) : ((p βŠ“ p' : submonoid M) : set M) = p ∩ p' := rfl @[simp, to_additive] lemma mem_inf {p p' : submonoid M} {x : M} : x ∈ p βŠ“ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl @[to_additive] instance : has_Inf (submonoid M) := ⟨λ s, { carrier := β‹‚ t ∈ s, ↑t, one_mem' := set.mem_bInter $ Ξ» i h, i.one_mem, mul_mem' := Ξ» x y hx hy, set.mem_bInter $ Ξ» i h, i.mul_mem (by apply set.mem_bInter_iff.1 hx i h) (by apply set.mem_bInter_iff.1 hy i h) }⟩ @[simp, to_additive] lemma coe_Inf (S : set (submonoid M)) : ((Inf S : submonoid M) : set M) = β‹‚ s ∈ S, ↑s := rfl @[to_additive] lemma mem_Inf {S : set (submonoid M)} {x : M} : x ∈ Inf S ↔ βˆ€ p ∈ S, x ∈ p := set.mem_bInter_iff @[to_additive] lemma mem_infi {ΞΉ : Sort*} {S : ΞΉ β†’ submonoid M} {x : M} : (x ∈ β¨… i, S i) ↔ βˆ€ i, x ∈ S i := by simp only [infi, mem_Inf, set.forall_range_iff] @[simp, to_additive] lemma coe_infi {ΞΉ : Sort*} {S : ΞΉ β†’ submonoid M} : (↑(β¨… i, S i) : set M) = β‹‚ i, S i := by simp only [infi, coe_Inf, set.bInter_range] attribute [norm_cast] coe_Inf coe_infi /-- Submonoids of a monoid form a complete lattice. -/ @[to_additive "The `add_submonoid`s of an `add_monoid` form a complete lattice."] instance : complete_lattice (submonoid M) := { le := (≀), lt := (<), bot := (βŠ₯), bot_le := Ξ» S x hx, (mem_bot.1 hx).symm β–Έ S.one_mem, top := (⊀), le_top := Ξ» S x hx, mem_top x, inf := (βŠ“), Inf := has_Inf.Inf, le_inf := Ξ» a b c ha hb x hx, ⟨ha hx, hb hx⟩, inf_le_left := Ξ» a b x, and.left, inf_le_right := Ξ» a b x, and.right, .. complete_lattice_of_Inf (submonoid M) $ Ξ» s, is_glb.of_image (Ξ» S T, show (S : set M) ≀ T ↔ S ≀ T, from coe_subset_coe) is_glb_binfi } /-- The `submonoid` generated by a set. -/ @[to_additive "The `add_submonoid` generated by a set"] def closure (s : set M) : submonoid M := Inf {S | s βŠ† S} @[to_additive] lemma mem_closure {x : M} : x ∈ closure s ↔ βˆ€ S : submonoid M, s βŠ† S β†’ x ∈ S := mem_Inf /-- The submonoid generated by a set includes the set. -/ @[simp, to_additive "The `add_submonoid` generated by a set includes the set."] lemma subset_closure : s βŠ† closure s := Ξ» x hx, mem_closure.2 $ Ξ» S hS, hS hx variable {S} open set /-- A submonoid `S` includes `closure s` if and only if it includes `s`. -/ @[simp, to_additive "An additive submonoid `S` includes `closure s` if and only if it includes `s`"] lemma closure_le : closure s ≀ S ↔ s βŠ† S := ⟨subset.trans subset_closure, Ξ» h, Inf_le h⟩ /-- Submonoid closure of a set is monotone in its argument: if `s βŠ† t`, then `closure s ≀ closure t`. -/ @[to_additive "Additive submonoid closure of a set is monotone in its argument: if `s βŠ† t`, then `closure s ≀ closure t`"] lemma closure_mono ⦃s t : set M⦄ (h : s βŠ† t) : closure s ≀ closure t := closure_le.2 $ subset.trans h subset_closure @[to_additive] lemma closure_eq_of_le (h₁ : s βŠ† S) (hβ‚‚ : S ≀ closure s) : closure s = S := le_antisymm (closure_le.2 h₁) hβ‚‚ variable (S) /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `s`, and is preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/ @[to_additive "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `s`, and is preserved under addition, then `p` holds for all elements of the additive closure of `s`."] lemma closure_induction {p : M β†’ Prop} {x} (h : x ∈ closure s) (Hs : βˆ€ x ∈ s, p x) (H1 : p 1) (Hmul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) : p x := (@closure_le _ _ _ ⟨p, H1, Hmul⟩).2 Hs h attribute [elab_as_eliminator] submonoid.closure_induction add_submonoid.closure_induction variable (M) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : galois_insertion (@closure M _) coe := { choice := Ξ» s _, closure s, gc := Ξ» s t, closure_le, le_l_u := Ξ» s, subset_closure, choice_eq := Ξ» s h, rfl } variable {M} /-- Closure of a submonoid `S` equals `S`. -/ @[simp, to_additive "Additive closure of an additive submonoid `S` equals `S`"] lemma closure_eq : closure (S : set M) = S := (submonoid.gi M).l_u_eq S @[simp, to_additive] lemma closure_empty : closure (βˆ… : set M) = βŠ₯ := (submonoid.gi M).gc.l_bot @[simp, to_additive] lemma closure_univ : closure (univ : set M) = ⊀ := @coe_top M _ β–Έ closure_eq ⊀ @[to_additive] lemma closure_union (s t : set M) : closure (s βˆͺ t) = closure s βŠ” closure t := (submonoid.gi M).gc.l_sup @[to_additive] lemma closure_Union {ΞΉ} (s : ΞΉ β†’ set M) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (submonoid.gi M).gc.l_supr @[to_additive] lemma mem_supr_of_directed {ΞΉ} [hΞΉ : nonempty ΞΉ] {S : ΞΉ β†’ submonoid M} (hS : directed (≀) S) {x : M} : x ∈ (⨆ i, S i) ↔ βˆƒ i, x ∈ S i := begin refine ⟨_, Ξ» ⟨i, hi⟩, (le_def.1 $ le_supr S i) hi⟩, suffices : x ∈ closure (⋃ i, (S i : set M)) β†’ βˆƒ i, x ∈ S i, by simpa only [closure_Union, closure_eq (S _)] using this, refine (Ξ» hx, closure_induction hx (Ξ» _, mem_Union.1) _ _), { exact hΞΉ.elim (Ξ» i, ⟨i, (S i).one_mem⟩) }, { rintros x y ⟨i, hi⟩ ⟨j, hj⟩, rcases hS i j with ⟨k, hki, hkj⟩, exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ } end @[to_additive] lemma coe_supr_of_directed {ΞΉ} [nonempty ΞΉ] {S : ΞΉ β†’ submonoid M} (hS : directed (≀) S) : ((⨆ i, S i : submonoid M) : set M) = ⋃ i, ↑(S i) := set.ext $ Ξ» x, by simp [mem_supr_of_directed hS] @[to_additive] lemma mem_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty) (hS : directed_on (≀) S) {x : M} : x ∈ Sup S ↔ βˆƒ s ∈ S, x ∈ s := begin haveI : nonempty S := Sne.to_subtype, rw [Sup_eq_supr, supr_subtype', mem_supr_of_directed, subtype.exists], exact (directed_on_iff_directed _).1 hS end @[to_additive] lemma coe_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty) (hS : directed_on (≀) S) : (↑(Sup S) : set M) = ⋃ s ∈ S, ↑s := set.ext $ Ξ» x, by simp [mem_Sup_of_directed_on Sne hS] variables {N : Type*} [monoid N] {P : Type*} [monoid P] /-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The preimage of an `add_submonoid` along an `add_monoid` homomorphism is an `add_submonoid`."] def comap (f : M β†’* N) (S : submonoid N) : submonoid M := { carrier := (f ⁻¹' S), one_mem' := show f 1 ∈ S, by rw f.map_one; exact S.one_mem, mul_mem' := Ξ» a b ha hb, show f (a * b) ∈ S, by rw f.map_mul; exact S.mul_mem ha hb } @[simp, to_additive] lemma coe_comap (S : submonoid N) (f : M β†’* N) : (S.comap f : set M) = f ⁻¹' S := rfl @[simp, to_additive] lemma mem_comap {S : submonoid N} {f : M β†’* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl @[to_additive] lemma comap_comap (S : submonoid P) (g : N β†’* P) (f : M β†’* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl /-- The image of a submonoid along a monoid homomorphism is a submonoid. -/ @[to_additive "The image of an `add_submonoid` along an `add_monoid` homomorphism is an `add_submonoid`."] def map (f : M β†’* N) (S : submonoid M) : submonoid N := { carrier := (f '' S), one_mem' := ⟨1, S.one_mem, f.map_one⟩, mul_mem' := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩, exact ⟨x * y, S.mul_mem hx hy, by rw f.map_mul; refl⟩ end } @[simp, to_additive] lemma coe_map (f : M β†’* N) (S : submonoid M) : (S.map f : set N) = f '' S := rfl @[simp, to_additive] lemma mem_map {f : M β†’* N} {S : submonoid M} {y : N} : y ∈ S.map f ↔ βˆƒ x ∈ S, f x = y := mem_image_iff_bex @[to_additive] lemma map_map (g : N β†’* P) (f : M β†’* N) : (S.map f).map g = S.map (g.comp f) := ext' $ image_image _ _ _ @[to_additive] lemma map_le_iff_le_comap {f : M β†’* N} {S : submonoid M} {T : submonoid N} : S.map f ≀ T ↔ S ≀ T.comap f := image_subset_iff @[to_additive] lemma gc_map_comap (f : M β†’* N) : galois_connection (map f) (comap f) := Ξ» S T, map_le_iff_le_comap @[to_additive] lemma map_sup (S T : submonoid M) (f : M β†’* N) : (S βŠ” T).map f = S.map f βŠ” T.map f := (gc_map_comap f).l_sup @[to_additive] lemma map_supr {ΞΉ : Sort*} (f : M β†’* N) (s : ΞΉ β†’ submonoid M) : (supr s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_supr @[to_additive] lemma comap_inf (S T : submonoid N) (f : M β†’* N) : (S βŠ“ T).comap f = S.comap f βŠ“ T.comap f := (gc_map_comap f).u_inf @[to_additive] lemma comap_infi {ΞΉ : Sort*} (f : M β†’* N) (s : ΞΉ β†’ submonoid N) : (infi s).comap f = β¨… i, (s i).comap f := (gc_map_comap f).u_infi @[simp, to_additive] lemma map_bot (f : M β†’* N) : (βŠ₯ : submonoid M).map f = βŠ₯ := (gc_map_comap f).l_bot @[simp, to_additive] lemma comap_top (f : M β†’* N) : (⊀ : submonoid N).comap f = ⊀ := (gc_map_comap f).u_top @[simp, to_additive] lemma map_id (S : submonoid M) : S.map (monoid_hom.id M) = S := ext (Ξ» x, ⟨λ ⟨_, h, rfl⟩, h, Ξ» h, ⟨_, h, rfl⟩⟩) /-- Given `submonoid`s `s`, `t` of monoids `M`, `N` respectively, `s Γ— t` as a submonoid of `M Γ— N`. -/ @[to_additive prod "Given `add_submonoid`s `s`, `t` of `add_monoid`s `A`, `B` respectively, `s Γ— t` as an `add_submonoid` of `A Γ— B`."] def prod (s : submonoid M) (t : submonoid N) : submonoid (M Γ— N) := { carrier := (s : set M).prod t, one_mem' := ⟨s.one_mem, t.one_mem⟩, mul_mem' := Ξ» p q hp hq, ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ } @[to_additive coe_prod] lemma coe_prod (s : submonoid M) (t : submonoid N) : (s.prod t : set (M Γ— N)) = (s : set M).prod (t : set N) := rfl @[to_additive mem_prod] lemma mem_prod {s : submonoid M} {t : submonoid N} {p : M Γ— N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl @[to_additive prod_mono] lemma prod_mono : ((≀) β‡’ (≀) β‡’ (≀)) (@prod M _ N _) (@prod M _ N _) := Ξ» s s' hs t t' ht, set.prod_mono hs ht @[to_additive prod_mono_right] lemma prod_mono_right (s : submonoid M) : monotone (Ξ» t : submonoid N, s.prod t) := prod_mono (le_refl s) @[to_additive prod_mono_left] lemma prod_mono_left (t : submonoid N) : monotone (Ξ» s : submonoid M, s.prod t) := Ξ» s₁ sβ‚‚ hs, prod_mono hs (le_refl t) @[to_additive prod_top] lemma prod_top (s : submonoid M) : s.prod (⊀ : submonoid N) = s.comap (monoid_hom.fst M N) := ext $ Ξ» x, by simp [mem_prod, monoid_hom.coe_fst] @[to_additive top_prod] lemma top_prod (s : submonoid N) : (⊀ : submonoid M).prod s = s.comap (monoid_hom.snd M N) := ext $ Ξ» x, by simp [mem_prod, monoid_hom.coe_snd] @[simp, to_additive top_prod_top] lemma top_prod_top : (⊀ : submonoid M).prod (⊀ : submonoid N) = ⊀ := (top_prod _).trans $ comap_top _ @[to_additive] lemma bot_prod_bot : (βŠ₯ : submonoid M).prod (βŠ₯ : submonoid N) = βŠ₯ := ext' $ by simp [coe_prod, prod.one_eq_mk] /-- Product of submonoids is isomorphic to their product as monoids. -/ @[to_additive prod_equiv "Product of additive submonoids is isomorphic to their product as additive monoids"] def prod_equiv (s : submonoid M) (t : submonoid N) : s.prod t ≃* s Γ— t := { map_mul' := Ξ» x y, rfl, .. equiv.set.prod ↑s ↑t } end submonoid namespace monoid_hom variables {N : Type*} {P : Type*} [monoid N] [monoid P] (S : submonoid M) open submonoid /-- The range of a monoid homomorphism is a submonoid. -/ @[to_additive "The range of an `add_monoid_hom` is an `add_submonoid`."] def mrange (f : M β†’* N) : submonoid N := (⊀ : submonoid M).map f @[simp, to_additive] lemma coe_mrange (f : M β†’* N) : (f.mrange : set N) = set.range f := set.image_univ @[simp, to_additive] lemma mem_mrange {f : M β†’* N} {y : N} : y ∈ f.mrange ↔ βˆƒ x, f x = y := by simp [mrange] @[to_additive] lemma map_mrange (g : N β†’* P) (f : M β†’* N) : f.mrange.map g = (g.comp f).mrange := (⊀ : submonoid M).map_map g f /-- Restriction of a monoid hom to a submonoid of the domain. -/ @[to_additive "Restriction of an add_monoid hom to an `add_submonoid` of the domain."] def mrestrict {N : Type*} [monoid N] (f : M β†’* N) (S : submonoid M) : S β†’* N := f.comp S.subtype @[simp, to_additive] lemma mrestrict_apply {N : Type*} [monoid N] (f : M β†’* N) (x : S) : f.mrestrict S x = f x := rfl /-- Restriction of a monoid hom to a submonoid of the codomain. -/ @[to_additive "Restriction of an `add_monoid` hom to an `add_submonoid` of the codomain."] def cod_mrestrict (f : M β†’* N) (S : submonoid N) (h : βˆ€ x, f x ∈ S) : M β†’* S := { to_fun := Ξ» n, ⟨f n, h n⟩, map_one' := subtype.eq f.map_one, map_mul' := Ξ» x y, subtype.eq (f.map_mul x y) } /-- Restriction of a monoid hom to its range iterpreted as a submonoid. -/ @[to_additive "Restriction of an `add_monoid` hom to its range interpreted as a submonoid."] def mrange_restrict {N} [monoid N] (f : M β†’* N) : M β†’* f.mrange := f.cod_mrestrict f.mrange $ Ξ» x, ⟨x, submonoid.mem_top x, rfl⟩ @[simp, to_additive] lemma coe_mrange_restrict {N} [monoid N] (f : M β†’* N) (x : M) : (f.mrange_restrict x : N) = f x := rfl @[to_additive] lemma mrange_top_iff_surjective {N} [monoid N] {f : M β†’* N} : f.mrange = (⊀ : submonoid N) ↔ function.surjective f := submonoid.ext'_iff.trans $ iff.trans (by rw [coe_mrange, coe_top]) set.range_iff_surjective /-- The range of a surjective monoid hom is the whole of the codomain. -/ @[to_additive "The range of a surjective `add_monoid` hom is the whole of the codomain."] lemma mrange_top_of_surjective {N} [monoid N] (f : M β†’* N) (hf : function.surjective f) : f.mrange = (⊀ : submonoid N) := mrange_top_iff_surjective.2 hf /-- The submonoid of elements `x : M` such that `f x = g x` -/ @[to_additive "The additive submonoid of elements `x : M` such that `f x = g x`"] def eq_mlocus (f g : M β†’* N) : submonoid M := { carrier := {x | f x = g x}, one_mem' := by rw [set.mem_set_of_eq, f.map_one, g.map_one], mul_mem' := Ξ» x y (hx : _ = _) (hy : _ = _), by simp [*] } /-- If two monoid homomorphisms are equal on a set, then they are equal on its submonoid closure. -/ @[to_additive] lemma eq_on_mclosure {f g : M β†’* N} {s : set M} (h : set.eq_on f g s) : set.eq_on f g (closure s) := show closure s ≀ f.eq_mlocus g, from closure_le.2 h @[to_additive] lemma eq_of_eq_on_mtop {f g : M β†’* N} (h : set.eq_on f g (⊀ : submonoid M)) : f = g := ext $ Ξ» x, h trivial @[to_additive] lemma eq_of_eq_on_mdense {s : set M} (hs : closure s = ⊀) {f g : M β†’* N} (h : s.eq_on f g) : f = g := eq_of_eq_on_mtop $ hs β–Έ eq_on_mclosure h @[to_additive] lemma mclosure_preimage_le (f : M β†’* N) (s : set N) : closure (f ⁻¹' s) ≀ (closure s).comap f := closure_le.2 $ Ξ» x hx, mem_coe.2 $ mem_comap.2 $ subset_closure hx /-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated by the image of the set. -/ @[to_additive "The image under an `add_monoid` hom of the `add_submonoid` generated by a set equals the `add_submonoid` generated by the image of the set."] lemma map_mclosure (f : M β†’* N) (s : set M) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _) (mclosure_preimage_le _ _)) (closure_le.2 $ set.image_subset _ subset_closure) end monoid_hom namespace free_monoid variables {Ξ± : Type*} open submonoid @[to_additive] theorem closure_range_of : closure (set.range $ @of Ξ±) = ⊀ := eq_top_iff.2 $ Ξ» x hx, free_monoid.rec_on x (one_mem _) $ Ξ» x xs hxs, mul_mem _ (subset_closure $ set.mem_range_self _) hxs end free_monoid namespace submonoid variables {N : Type*} [monoid N] open monoid_hom /-- The monoid hom associated to an inclusion of submonoids. -/ @[to_additive "The `add_monoid` hom associated to an inclusion of submonoids."] def inclusion {S T : submonoid M} (h : S ≀ T) : S β†’* T := S.subtype.cod_mrestrict _ (Ξ» x, h x.2) @[simp, to_additive] lemma range_subtype (s : submonoid M) : s.subtype.mrange = s := ext' $ (coe_mrange _).trans $ set.range_coe_subtype s lemma closure_singleton_eq (x : M) : closure ({x} : set M) = (powers_hom M x).mrange := closure_eq_of_le (set.singleton_subset_iff.2 ⟨multiplicative.of_add 1, trivial, pow_one x⟩) $ Ξ» x ⟨n, _, hn⟩, hn β–Έ pow_mem _ (subset_closure $ set.mem_singleton _) _ /-- The submonoid generated by an element of a monoid equals the set of natural number powers of the element. -/ lemma mem_closure_singleton {x y : M} : y ∈ closure ({x} : set M) ↔ βˆƒ n:β„•, x^n=y := by rw [closure_singleton_eq, mem_mrange]; refl @[to_additive] lemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s β†’ M)).mrange := by rw [mrange, ← free_monoid.closure_range_of, map_mclosure, ← set.range_comp, free_monoid.lift_comp_of, set.range_coe_subtype] @[to_additive] lemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x ∈ closure s) : βˆƒ (l : list M) (hl : βˆ€ y ∈ l, y ∈ s), l.prod = x := begin rw [closure_eq_mrange, mem_mrange] at hx, rcases hx with ⟨l, hx⟩, exact ⟨list.map coe l, Ξ» y hy, let ⟨z, hz, hy⟩ := list.mem_map.1 hy in hy β–Έ z.2, hx⟩ end @[to_additive] lemma map_inl (s : submonoid M) : s.map (inl M N) = s.prod βŠ₯ := ext $ Ξ» p, ⟨λ ⟨x, hx, hp⟩, hp β–Έ ⟨hx, set.mem_singleton 1⟩, Ξ» ⟨hps, hp1⟩, ⟨p.1, hps, prod.ext rfl $ (set.eq_of_mem_singleton hp1).symm⟩⟩ @[to_additive] lemma map_inr (s : submonoid N) : s.map (inr M N) = prod βŠ₯ s := ext $ Ξ» p, ⟨λ ⟨x, hx, hp⟩, hp β–Έ ⟨set.mem_singleton 1, hx⟩, Ξ» ⟨hp1, hps⟩, ⟨p.2, hps, prod.ext (set.eq_of_mem_singleton hp1).symm rfl⟩⟩ @[to_additive] lemma range_inl : (inl M N).mrange = prod ⊀ βŠ₯ := map_inl ⊀ @[to_additive] lemma range_inr : (inr M N).mrange = prod βŠ₯ ⊀ := map_inr ⊀ @[to_additive] lemma range_inl' : (inl M N).mrange = comap (snd M N) βŠ₯ := range_inl.trans (top_prod _) @[to_additive] lemma range_inr' : (inr M N).mrange = comap (fst M N) βŠ₯ := range_inr.trans (prod_top _) @[simp, to_additive] lemma range_fst : (fst M N).mrange = ⊀ := (fst M N).mrange_top_of_surjective $ @prod.fst_surjective _ _ ⟨1⟩ @[simp, to_additive] lemma range_snd : (snd M N).mrange = ⊀ := (snd M N).mrange_top_of_surjective $ @prod.snd_surjective _ _ ⟨1⟩ @[simp, to_additive prod_bot_sup_bot_prod] lemma prod_bot_sup_bot_prod (s : submonoid M) (t : submonoid N) : (s.prod βŠ₯) βŠ” (prod βŠ₯ t) = s.prod t := le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) $ assume p hp, prod.fst_mul_snd p β–Έ mul_mem _ ((le_sup_left : s.prod βŠ₯ ≀ s.prod βŠ₯ βŠ” prod βŠ₯ t) ⟨hp.1, set.mem_singleton 1⟩) ((le_sup_right : prod βŠ₯ t ≀ s.prod βŠ₯ βŠ” prod βŠ₯ t) ⟨set.mem_singleton 1, hp.2⟩) @[simp, to_additive] lemma range_inl_sup_range_inr : (inl M N).mrange βŠ” (inr M N).mrange = ⊀ := by simp only [range_inl, range_inr, prod_bot_sup_bot_prod, top_prod_top] end submonoid namespace submonoid variables {N : Type*} [comm_monoid N] open monoid_hom @[to_additive] lemma sup_eq_range (s t : submonoid N) : s βŠ” t = (s.subtype.coprod t.subtype).mrange := by rw [mrange, ← range_inl_sup_range_inr, map_sup, map_mrange, coprod_comp_inl, map_mrange, coprod_comp_inr, range_subtype, range_subtype] @[to_additive] lemma mem_sup {s t : submonoid N} {x : N} : x ∈ s βŠ” t ↔ βˆƒ (y ∈ s) (z ∈ t), y * z = x := by simp only [sup_eq_range, mem_mrange, coprod_apply, prod.exists, submonoid.exists, coe_subtype, subtype.coe_mk] end submonoid namespace add_submonoid open set lemma smul_mem (S : add_submonoid A) {x : A} (hx : x ∈ S) : βˆ€ n : β„•, n β€’β„• x ∈ S | 0 := S.zero_mem | (n+1) := S.add_mem hx (smul_mem n) lemma closure_singleton_eq (x : A) : closure ({x} : set A) = (multiples_hom A x).mrange := closure_eq_of_le (set.singleton_subset_iff.2 ⟨1, trivial, one_nsmul x⟩) $ Ξ» x ⟨n, _, hn⟩, hn β–Έ smul_mem _ (subset_closure $ set.mem_singleton _) _ /-- The `add_submonoid` generated by an element of an `add_monoid` equals the set of natural number multiples of the element. -/ lemma mem_closure_singleton {x y : A} : y ∈ closure ({x} : set A) ↔ βˆƒ n:β„•, n β€’β„• x = y := by rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl end add_submonoid namespace mul_equiv variables {S T : submonoid M} /-- Makes the identity isomorphism from a proof two submonoids of a multiplicative monoid are equal. -/ @[to_additive add_submonoid_congr "Makes the identity additive isomorphism from a proof two submonoids of an additive monoid are equal."] def submonoid_congr (h : S = T) : S ≃* T := { map_mul' := Ξ» _ _, rfl, ..equiv.set_congr $ submonoid.ext'_iff.1 h } end mul_equiv
4488bb721b0537f0deee5220346cc722a56d71e1
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/measure_theory/measure/haar.lean
210ddac7862ffa755e38da3cc447d8a9470876dd
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
32,390
lean
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import measure_theory.measure.content import measure_theory.group.prod /-! # Haar measure In this file we prove the existence of Haar measure for a locally compact Hausdorff topological group. For the construction, we follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*. This is essentially the same argument as in https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets. We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest) number of left-translates of `U` that are needed to cover `K` (`index` in the formalization). Then we define a function `h` on compact sets as `lim_U (K : U) / (Kβ‚€ : U)`, where `U` becomes a smaller and smaller open neighborhood of `1`, and `Kβ‚€` is a fixed compact set with nonempty interior. This function is `chaar` in the formalization, and we define the limit formally using Tychonoff's theorem. This function `h` forms a content, which we can extend to an outer measure and then a measure (`haar_measure`). We normalize the Haar measure so that the measure of `Kβ‚€` is `1`. We show that for second countable spaces any left invariant Borel measure is a scalar multiple of the Haar measure. Note that `ΞΌ` need not coincide with `h` on compact sets, according to [halmos1950measure, ch. X, Β§53 p.233]. However, we know that `h(K)` lies between `ΞΌ(Kα΅’)` and `ΞΌ(K)`, where `α΅’` denotes the interior. ## Main Declarations * `haar_measure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant regular measure. It takes as argument a compact set of the group (with non-empty interior), and is normalized so that the measure of the given set is 1. * `haar_measure_self`: the Haar measure is normalized. * `is_left_invariant_haar_measure`: the Haar measure is left invariant. * `regular_haar_measure`: the Haar measure is a regular measure. * `is_haar_measure_haar_measure`: the Haar measure satisfies the `is_haar_measure` typeclass, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. * `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as `haar_measure K` where `K` is some arbitrary choice of a compact set with nonempty interior. ## References * Paul Halmos (1950), Measure Theory, Β§53 * Jonathan Gleason, Existence and Uniqueness of Haar Measure - Note: step 9, page 8 contains a mistake: the last defined `ΞΌ` does not extend the `ΞΌ` on compact sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11) invalid. * https://en.wikipedia.org/wiki/Haar_measure -/ noncomputable theory open set has_inv function topological_space measurable_space open_locale nnreal classical ennreal pointwise topological_space variables {G : Type*} [group G] namespace measure_theory namespace measure /-! We put the internal functions in the construction of the Haar measure in a namespace, so that the chosen names don't clash with other declarations. We first define a couple of the functions before proving the properties (that require that `G` is a topological group). -/ namespace haar /-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`: it is the smallest number of (left) translates of `V` that is necessary to cover `K`. It is defined to be 0 if no finite number of translates cover `K`. -/ @[to_additive add_index "additive version of `measure_theory.measure.haar.index`"] def index (K V : set G) : β„• := Inf $ finset.card '' {t : finset G | K βŠ† ⋃ g ∈ t, (Ξ» h, g * h) ⁻¹' V } @[to_additive add_index_empty] lemma index_empty {V : set G} : index βˆ… V = 0 := begin simp only [index, nat.Inf_eq_zero], left, use βˆ…, simp only [finset.card_empty, empty_subset, mem_set_of_eq, eq_self_iff_true, and_self], end variables [topological_space G] /-- `prehaar Kβ‚€ U K` is a weighted version of the index, defined as `(K : U)/(Kβ‚€ : U)`. In the applications `Kβ‚€` is compact with non-empty interior, `U` is open containing `1`, and `K` is any compact set. The argument `K` is a (bundled) compact set, so that we can consider `prehaar Kβ‚€ U` as an element of `haar_product` (below). -/ @[to_additive "additive version of `measure_theory.measure.haar.prehaar`"] def prehaar (Kβ‚€ U : set G) (K : compacts G) : ℝ := (index K.1 U : ℝ) / index Kβ‚€ U @[to_additive] lemma prehaar_empty (Kβ‚€ : positive_compacts G) {U : set G} : prehaar Kβ‚€.1 U βŠ₯ = 0 := by { simp only [prehaar, compacts.bot_val, index_empty, nat.cast_zero, zero_div] } @[to_additive] lemma prehaar_nonneg (Kβ‚€ : positive_compacts G) {U : set G} (K : compacts G) : 0 ≀ prehaar Kβ‚€.1 U K := by apply div_nonneg; norm_cast; apply zero_le /-- `haar_product Kβ‚€` is the product of intervals `[0, (K : Kβ‚€)]`, for all compact sets `K`. For all `U`, we can show that `prehaar Kβ‚€ U ∈ haar_product Kβ‚€`. -/ @[to_additive "additive version of `measure_theory.measure.haar.haar_product`"] def haar_product (Kβ‚€ : set G) : set (compacts G β†’ ℝ) := pi univ (Ξ» K, Icc 0 $ index K.1 Kβ‚€) @[simp, to_additive] lemma mem_prehaar_empty {Kβ‚€ : set G} {f : compacts G β†’ ℝ} : f ∈ haar_product Kβ‚€ ↔ βˆ€ K : compacts G, f K ∈ Icc (0 : ℝ) (index K.1 Kβ‚€) := by simp only [haar_product, pi, forall_prop_of_true, mem_univ, mem_set_of_eq] /-- The closure of the collection of elements of the form `prehaar Kβ‚€ U`, for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space `compacts G β†’ ℝ`, with the topology of pointwise convergence. We show that the intersection of all these sets is nonempty, and the Haar measure on compact sets is defined to be an element in the closure of this intersection. -/ @[to_additive "additive version of `measure_theory.measure.haar.cl_prehaar`"] def cl_prehaar (Kβ‚€ : set G) (V : open_nhds_of (1 : G)) : set (compacts G β†’ ℝ) := closure $ prehaar Kβ‚€ '' { U : set G | U βŠ† V.1 ∧ is_open U ∧ (1 : G) ∈ U } variables [topological_group G] /-! ### Lemmas about `index` -/ /-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties. -/ @[to_additive add_index_defined] lemma index_defined {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) : βˆƒ n : β„•, n ∈ finset.card '' {t : finset G | K βŠ† ⋃ g ∈ t, (Ξ» h, g * h) ⁻¹' V } := by { rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩, exact ⟨t.card, t, ht, rfl⟩ } @[to_additive add_index_elim] lemma index_elim {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) : βˆƒ (t : finset G), K βŠ† (⋃ g ∈ t, (Ξ» h, g * h) ⁻¹' V) ∧ finset.card t = index K V := by { have := nat.Inf_mem (index_defined hK hV), rwa [mem_image] at this } @[to_additive le_add_index_mul] lemma le_index_mul (Kβ‚€ : positive_compacts G) (K : compacts G) {V : set G} (hV : (interior V).nonempty) : index K.1 V ≀ index K.1 Kβ‚€.1 * index Kβ‚€.1 V := begin rcases index_elim K.2 Kβ‚€.2.2 with ⟨s, h1s, h2s⟩, rcases index_elim Kβ‚€.2.1 hV with ⟨t, h1t, h2t⟩, rw [← h2s, ← h2t, mul_comm], refine le_trans _ finset.mul_card_le, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], refine subset.trans h1s _, apply bUnion_subset, intros g₁ hg₁, rw preimage_subset_iff, intros gβ‚‚ hgβ‚‚, have := h1t hgβ‚‚, rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩, rw [mem_preimage, ← mul_assoc] at h2V, exact mem_bUnion (finset.mul_mem_mul hg₃ hg₁) h2V end @[to_additive add_index_pos] lemma index_pos (K : positive_compacts G) {V : set G} (hV : (interior V).nonempty) : 0 < index K.1 V := begin unfold index, rw [nat.Inf_def, nat.find_pos, mem_image], { rintro ⟨t, h1t, h2t⟩, rw [finset.card_eq_zero] at h2t, subst h2t, cases K.2.2 with g hg, show g ∈ (βˆ… : set G), convert h1t (interior_subset hg), symmetry, apply bUnion_empty }, { exact index_defined K.2.1 hV } end @[to_additive add_index_mono] lemma index_mono {K K' V : set G} (hK' : is_compact K') (h : K βŠ† K') (hV : (interior V).nonempty) : index K V ≀ index K' V := begin rcases index_elim hK' hV with ⟨s, h1s, h2s⟩, apply nat.Inf_le, rw [mem_image], refine ⟨s, subset.trans h h1s, h2s⟩ end @[to_additive add_index_union_le] lemma index_union_le (K₁ Kβ‚‚ : compacts G) {V : set G} (hV : (interior V).nonempty) : index (K₁.1 βˆͺ Kβ‚‚.1) V ≀ index K₁.1 V + index Kβ‚‚.1 V := begin rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩, rcases index_elim Kβ‚‚.2 hV with ⟨t, h1t, h2t⟩, rw [← h2s, ← h2t], refine le_trans _ (finset.card_union_le _ _), apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], apply union_subset; refine subset.trans (by assumption) _; apply bUnion_subset_bUnion_left; intros g hg; simp only [mem_def] at hg; simp only [mem_def, multiset.mem_union, finset.union_val, hg, or_true, true_or] end @[to_additive add_index_union_eq] lemma index_union_eq (K₁ Kβ‚‚ : compacts G) {V : set G} (hV : (interior V).nonempty) (h : disjoint (K₁.1 * V⁻¹) (Kβ‚‚.1 * V⁻¹)) : index (K₁.1 βˆͺ Kβ‚‚.1) V = index K₁.1 V + index Kβ‚‚.1 V := begin apply le_antisymm (index_union_le K₁ Kβ‚‚ hV), rcases index_elim (K₁.2.union Kβ‚‚.2) hV with ⟨s, h1s, h2s⟩, rw [← h2s], have : βˆ€ (K : set G) , K βŠ† (⋃ g ∈ s, (Ξ» h, g * h) ⁻¹' V) β†’ index K V ≀ (s.filter (Ξ» g, ((Ξ» (h : G), g * h) ⁻¹' V ∩ K).nonempty)).card, { intros K hK, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], intros g hg, rcases hK hg with ⟨_, ⟨gβ‚€, rfl⟩, _, ⟨h1gβ‚€, rfl⟩, h2gβ‚€βŸ©, simp only [mem_preimage] at h2gβ‚€, simp only [mem_Union], use gβ‚€, split, { simp only [finset.mem_filter, h1gβ‚€, true_and], use g, simp only [hg, h2gβ‚€, mem_inter_eq, mem_preimage, and_self] }, exact h2gβ‚€ }, refine le_trans (add_le_add (this K₁.1 $ subset.trans (subset_union_left _ _) h1s) (this Kβ‚‚.1 $ subset.trans (subset_union_right _ _) h1s)) _, rw [← finset.card_union_eq, finset.filter_union_right], exact s.card_filter_le _, apply finset.disjoint_filter.mpr, rintro g₁ h1g₁ ⟨gβ‚‚, h1gβ‚‚, h2gβ‚‚βŸ© ⟨g₃, h1g₃, h2gβ‚ƒβŸ©, simp only [mem_preimage] at h1g₃ h1gβ‚‚, apply @h g₁⁻¹, split; simp only [set.mem_inv, set.mem_mul, exists_exists_and_eq_and, exists_and_distrib_left], { refine ⟨_, h2gβ‚‚, (g₁ * gβ‚‚)⁻¹, _, _⟩, simp only [inv_inv, h1gβ‚‚], simp only [mul_inv_rev, mul_inv_cancel_left] }, { refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, _, _⟩, simp only [inv_inv, h1g₃], simp only [mul_inv_rev, mul_inv_cancel_left] } end @[to_additive add_left_add_index_le] lemma mul_left_index_le {K : set G} (hK : is_compact K) {V : set G} (hV : (interior V).nonempty) (g : G) : index ((Ξ» h, g * h) '' K) V ≀ index K V := begin rcases index_elim hK hV with ⟨s, h1s, h2s⟩, rw [← h2s], apply nat.Inf_le, rw [mem_image], refine ⟨s.map (equiv.mul_right g⁻¹).to_embedding, _, finset.card_map _⟩, { simp only [mem_set_of_eq], refine subset.trans (image_subset _ h1s) _, rintro _ ⟨g₁, ⟨_, ⟨gβ‚‚, rfl⟩, ⟨_, ⟨hgβ‚‚, rfl⟩, hgβ‚βŸ©βŸ©, rfl⟩, simp only [mem_preimage] at hg₁, simp only [exists_prop, mem_Union, finset.mem_map, equiv.coe_mul_right, exists_exists_and_eq_and, mem_preimage, equiv.to_embedding_apply], refine ⟨_, hgβ‚‚, _⟩, simp only [mul_assoc, hg₁, inv_mul_cancel_left] } end @[to_additive is_left_invariant_add_index] lemma is_left_invariant_index {K : set G} (hK : is_compact K) (g : G) {V : set G} (hV : (interior V).nonempty) : index ((Ξ» h, g * h) '' K) V = index K V := begin refine le_antisymm (mul_left_index_le hK hV g) _, convert mul_left_index_le (hK.image $ continuous_mul_left g) hV g⁻¹, rw [image_image], symmetry, convert image_id' _, ext h, apply inv_mul_cancel_left end /-! ### Lemmas about `prehaar` -/ @[to_additive add_prehaar_le_add_index] lemma prehaar_le_index (Kβ‚€ : positive_compacts G) {U : set G} (K : compacts G) (hU : (interior U).nonempty) : prehaar Kβ‚€.1 U K ≀ index K.1 Kβ‚€.1 := begin unfold prehaar, rw [div_le_iff]; norm_cast, { apply le_index_mul Kβ‚€ K hU }, { exact index_pos Kβ‚€ hU } end @[to_additive] lemma prehaar_pos (Kβ‚€ : positive_compacts G) {U : set G} (hU : (interior U).nonempty) {K : set G} (h1K : is_compact K) (h2K : (interior K).nonempty) : 0 < prehaar Kβ‚€.1 U ⟨K, h1K⟩ := by { apply div_pos; norm_cast, apply index_pos ⟨K, h1K, h2K⟩ hU, exact index_pos Kβ‚€ hU } @[to_additive] lemma prehaar_mono {Kβ‚€ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) {K₁ Kβ‚‚ : compacts G} (h : K₁.1 βŠ† Kβ‚‚.1) : prehaar Kβ‚€.1 U K₁ ≀ prehaar Kβ‚€.1 U Kβ‚‚ := begin simp only [prehaar], rw [div_le_div_right], exact_mod_cast index_mono Kβ‚‚.2 h hU, exact_mod_cast index_pos Kβ‚€ hU end @[to_additive] lemma prehaar_self {Kβ‚€ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) : prehaar Kβ‚€.1 U ⟨Kβ‚€.1, Kβ‚€.2.1⟩ = 1 := by { simp only [prehaar], rw [div_self], apply ne_of_gt, exact_mod_cast index_pos Kβ‚€ hU } @[to_additive] lemma prehaar_sup_le {Kβ‚€ : positive_compacts G} {U : set G} (K₁ Kβ‚‚ : compacts G) (hU : (interior U).nonempty) : prehaar Kβ‚€.1 U (K₁ βŠ” Kβ‚‚) ≀ prehaar Kβ‚€.1 U K₁ + prehaar Kβ‚€.1 U Kβ‚‚ := begin simp only [prehaar], rw [div_add_div_same, div_le_div_right], exact_mod_cast index_union_le K₁ Kβ‚‚ hU, exact_mod_cast index_pos Kβ‚€ hU end @[to_additive] lemma prehaar_sup_eq {Kβ‚€ : positive_compacts G} {U : set G} {K₁ Kβ‚‚ : compacts G} (hU : (interior U).nonempty) (h : disjoint (K₁.1 * U⁻¹) (Kβ‚‚.1 * U⁻¹)) : prehaar Kβ‚€.1 U (K₁ βŠ” Kβ‚‚) = prehaar Kβ‚€.1 U K₁ + prehaar Kβ‚€.1 U Kβ‚‚ := by { simp only [prehaar], rw [div_add_div_same], congr', exact_mod_cast index_union_eq K₁ Kβ‚‚ hU h } @[to_additive] lemma is_left_invariant_prehaar {Kβ‚€ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) (g : G) (K : compacts G) : prehaar Kβ‚€.1 U (K.map _ $ continuous_mul_left g) = prehaar Kβ‚€.1 U K := by simp only [prehaar, compacts.map_val, is_left_invariant_index K.2 _ hU] /-! ### Lemmas about `haar_product` -/ @[to_additive] lemma prehaar_mem_haar_product (Kβ‚€ : positive_compacts G) {U : set G} (hU : (interior U).nonempty) : prehaar Kβ‚€.1 U ∈ haar_product Kβ‚€.1 := by { rintro ⟨K, hK⟩ h2K, rw [mem_Icc], exact ⟨prehaar_nonneg Kβ‚€ _, prehaar_le_index Kβ‚€ _ hU⟩ } @[to_additive] lemma nonempty_Inter_cl_prehaar (Kβ‚€ : positive_compacts G) : (haar_product Kβ‚€.1 ∩ β‹‚ (V : open_nhds_of (1 : G)), cl_prehaar Kβ‚€.1 V).nonempty := begin have : is_compact (haar_product Kβ‚€.1), { apply is_compact_univ_pi, intro K, apply is_compact_Icc }, refine this.inter_Inter_nonempty (cl_prehaar Kβ‚€.1) (Ξ» s, is_closed_closure) (Ξ» t, _), let Vβ‚€ := β‹‚ (V ∈ t), (V : open_nhds_of 1).1, have h1Vβ‚€ : is_open Vβ‚€, { apply is_open_bInter, apply finite_mem_finset, rintro ⟨V, hV⟩ h2V, exact hV.1 }, have h2Vβ‚€ : (1 : G) ∈ Vβ‚€, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, exact hV.2 }, refine ⟨prehaar Kβ‚€.1 Vβ‚€, _⟩, split, { apply prehaar_mem_haar_product Kβ‚€, use 1, rwa h1Vβ‚€.interior_eq }, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, apply subset_closure, apply mem_image_of_mem, rw [mem_set_of_eq], exact ⟨subset.trans (Inter_subset _ ⟨V, hV⟩) (Inter_subset _ h2V), h1Vβ‚€, h2Vβ‚€βŸ© }, end /-! ### Lemmas about `chaar` -/ /-- This is the "limit" of `prehaar Kβ‚€.1 U K` as `U` becomes a smaller and smaller open neighborhood of `(1 : G)`. More precisely, it is defined to be an arbitrary element in the intersection of all the sets `cl_prehaar Kβ‚€ V` in `haar_product Kβ‚€`. This is roughly equal to the Haar measure on compact sets, but it can differ slightly. We do know that `haar_measure Kβ‚€ (interior K.1) ≀ chaar Kβ‚€ K ≀ haar_measure Kβ‚€ K.1`. -/ @[to_additive add_chaar "additive version of `measure_theory.measure.haar.chaar`"] def chaar (Kβ‚€ : positive_compacts G) (K : compacts G) : ℝ := classical.some (nonempty_Inter_cl_prehaar Kβ‚€) K @[to_additive add_chaar_mem_add_haar_product] lemma chaar_mem_haar_product (Kβ‚€ : positive_compacts G) : chaar Kβ‚€ ∈ haar_product Kβ‚€.1 := (classical.some_spec (nonempty_Inter_cl_prehaar Kβ‚€)).1 @[to_additive add_chaar_mem_cl_add_prehaar] lemma chaar_mem_cl_prehaar (Kβ‚€ : positive_compacts G) (V : open_nhds_of (1 : G)) : chaar Kβ‚€ ∈ cl_prehaar Kβ‚€.1 V := by { have := (classical.some_spec (nonempty_Inter_cl_prehaar Kβ‚€)).2, rw [mem_Inter] at this, exact this V } @[to_additive add_chaar_nonneg] lemma chaar_nonneg (Kβ‚€ : positive_compacts G) (K : compacts G) : 0 ≀ chaar Kβ‚€ K := by { have := chaar_mem_haar_product Kβ‚€ K (mem_univ _), rw mem_Icc at this, exact this.1 } @[to_additive add_chaar_empty] lemma chaar_empty (Kβ‚€ : positive_compacts G) : chaar Kβ‚€ βŠ₯ = 0 := begin let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f βŠ₯, have : continuous eval := continuous_apply βŠ₯, show chaar Kβ‚€ ∈ eval ⁻¹' {(0 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_empty }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton }, end @[to_additive add_chaar_self] lemma chaar_self (Kβ‚€ : positive_compacts G) : chaar Kβ‚€ ⟨Kβ‚€.1, Kβ‚€.2.1⟩ = 1 := begin let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f ⟨Kβ‚€.1, Kβ‚€.2.1⟩, have : continuous eval := continuous_apply _, show chaar Kβ‚€ ∈ eval ⁻¹' {(1 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_self, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton } end @[to_additive add_chaar_mono] lemma chaar_mono {Kβ‚€ : positive_compacts G} {K₁ Kβ‚‚ : compacts G} (h : K₁.1 βŠ† Kβ‚‚.1) : chaar Kβ‚€ K₁ ≀ chaar Kβ‚€ Kβ‚‚ := begin let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f Kβ‚‚ - f K₁, have : continuous eval := (continuous_apply Kβ‚‚).sub (continuous_apply K₁), rw [← sub_nonneg], show chaar Kβ‚€ ∈ eval ⁻¹' (Ici (0 : ℝ)), apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg], apply prehaar_mono _ h, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_Ici }, end @[to_additive add_chaar_sup_le] lemma chaar_sup_le {Kβ‚€ : positive_compacts G} (K₁ Kβ‚‚ : compacts G) : chaar Kβ‚€ (K₁ βŠ” Kβ‚‚) ≀ chaar Kβ‚€ K₁ + chaar Kβ‚€ Kβ‚‚ := begin let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f K₁ + f Kβ‚‚ - f (K₁ βŠ” Kβ‚‚), have : continuous eval := ((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply Kβ‚‚))).sub (continuous_apply (K₁ βŠ” Kβ‚‚)), rw [← sub_nonneg], show chaar Kβ‚€ ∈ eval ⁻¹' (Ici (0 : ℝ)), apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg], apply prehaar_sup_le, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_Ici }, end @[to_additive add_chaar_sup_eq] lemma chaar_sup_eq [t2_space G] {Kβ‚€ : positive_compacts G} {K₁ Kβ‚‚ : compacts G} (h : disjoint K₁.1 Kβ‚‚.1) : chaar Kβ‚€ (K₁ βŠ” Kβ‚‚) = chaar Kβ‚€ K₁ + chaar Kβ‚€ Kβ‚‚ := begin rcases compact_compact_separated K₁.2 Kβ‚‚.2 (disjoint_iff.mp h) with ⟨U₁, Uβ‚‚, h1U₁, h1Uβ‚‚, h2U₁, h2Uβ‚‚, hU⟩, rw [← disjoint_iff_inter_eq_empty] at hU, rcases compact_open_separated_mul K₁.2 h1U₁ h2U₁ with ⟨V₁, h1V₁, h2V₁, h3Vβ‚βŸ©, rcases compact_open_separated_mul Kβ‚‚.2 h1Uβ‚‚ h2Uβ‚‚ with ⟨Vβ‚‚, h1Vβ‚‚, h2Vβ‚‚, h3Vβ‚‚βŸ©, let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f K₁ + f Kβ‚‚ - f (K₁ βŠ” Kβ‚‚), have : continuous eval := ((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply Kβ‚‚))).sub (continuous_apply (K₁ βŠ” Kβ‚‚)), rw [eq_comm, ← sub_eq_zero], show chaar Kβ‚€ ∈ eval ⁻¹' {(0 : ℝ)}, let V := V₁ ∩ Vβ‚‚, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨V⁻¹, (is_open.inter h1V₁ h1Vβ‚‚).preimage continuous_inv, by simp only [mem_inv, one_inv, h2V₁, h2Vβ‚‚, V, mem_inter_eq, true_and]⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, eval, sub_eq_zero, mem_singleton_iff], rw [eq_comm], apply prehaar_sup_eq, { rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { refine disjoint_of_subset _ _ hU, { refine subset.trans (mul_subset_mul subset.rfl _) h3V₁, exact subset.trans (inv_subset.mpr h1U) (inter_subset_left _ _) }, { refine subset.trans (mul_subset_mul subset.rfl _) h3Vβ‚‚, exact subset.trans (inv_subset.mpr h1U) (inter_subset_right _ _) }}}, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton }, end @[to_additive is_left_invariant_add_chaar] lemma is_left_invariant_chaar {Kβ‚€ : positive_compacts G} (g : G) (K : compacts G) : chaar Kβ‚€ (K.map _ $ continuous_mul_left g) = chaar Kβ‚€ K := begin let eval : (compacts G β†’ ℝ) β†’ ℝ := Ξ» f, f (K.map _ $ continuous_mul_left g) - f K, have : continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K), rw [← sub_eq_zero], show chaar Kβ‚€ ∈ eval ⁻¹' {(0 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar Kβ‚€ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_singleton_iff, mem_preimage, eval, sub_eq_zero], apply is_left_invariant_prehaar, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton }, end variable [t2_space G] /-- The function `chaar` interpreted in `ℝβ‰₯0`, as a content -/ @[to_additive "additive version of `measure_theory.measure.haar.haar_content`"] def haar_content (Kβ‚€ : positive_compacts G) : content G := { to_fun := Ξ» K, ⟨chaar Kβ‚€ K, chaar_nonneg _ _⟩, mono' := Ξ» K₁ Kβ‚‚ h, by simp only [←nnreal.coe_le_coe, subtype.coe_mk, chaar_mono, h], sup_disjoint' := Ξ» K₁ Kβ‚‚ h, by { simp only [chaar_sup_eq h], refl }, sup_le' := Ξ» K₁ Kβ‚‚, by simp only [←nnreal.coe_le_coe, nnreal.coe_add, subtype.coe_mk, chaar_sup_le] } /-! We only prove the properties for `haar_content` that we use at least twice below. -/ @[to_additive] lemma haar_content_apply (Kβ‚€ : positive_compacts G) (K : compacts G) : haar_content Kβ‚€ K = show nnreal, from ⟨chaar Kβ‚€ K, chaar_nonneg _ _⟩ := rfl /-- The variant of `chaar_self` for `haar_content` -/ @[to_additive] lemma haar_content_self {Kβ‚€ : positive_compacts G} : haar_content Kβ‚€ ⟨Kβ‚€.1, Kβ‚€.2.1⟩ = 1 := by { simp_rw [← ennreal.coe_one, haar_content_apply, ennreal.coe_eq_coe, chaar_self], refl } /-- The variant of `is_left_invariant_chaar` for `haar_content` -/ @[to_additive] lemma is_left_invariant_haar_content {Kβ‚€ : positive_compacts G} (g : G) (K : compacts G) : haar_content Kβ‚€ (K.map _ $ continuous_mul_left g) = haar_content Kβ‚€ K := by simpa only [ennreal.coe_eq_coe, ←nnreal.coe_eq, haar_content_apply] using is_left_invariant_chaar g K @[to_additive] lemma haar_content_outer_measure_self_pos {Kβ‚€ : positive_compacts G} : 0 < (haar_content Kβ‚€).outer_measure Kβ‚€.1 := begin apply ennreal.zero_lt_one.trans_le, rw [content.outer_measure_eq_infi], refine le_binfi _, intros U hU, refine le_infi _, intros h2U, refine le_trans (le_of_eq _) (le_bsupr ⟨Kβ‚€.1, Kβ‚€.2.1⟩ h2U), exact haar_content_self.symm end end haar open haar /-! ### The Haar measure -/ variables [topological_space G] [t2_space G] [topological_group G] [measurable_space G] [borel_space G] /-- The Haar measure on the locally compact group `G`, scaled so that `haar_measure Kβ‚€ Kβ‚€ = 1`. -/ @[to_additive "The Haar measure on the locally compact additive group `G`, scaled so that `add_haar_measure Kβ‚€ Kβ‚€ = 1`."] def haar_measure (Kβ‚€ : positive_compacts G) : measure G := ((haar_content Kβ‚€).outer_measure Kβ‚€.1)⁻¹ β€’ (haar_content Kβ‚€).measure @[to_additive] lemma haar_measure_apply {Kβ‚€ : positive_compacts G} {s : set G} (hs : measurable_set s) : haar_measure Kβ‚€ s = (haar_content Kβ‚€).outer_measure s / (haar_content Kβ‚€).outer_measure Kβ‚€.1 := begin change (((haar_content Kβ‚€).outer_measure) Kβ‚€.val)⁻¹ * (haar_content Kβ‚€).measure s = _, simp only [hs, div_eq_mul_inv, mul_comm, content.measure_apply], end @[to_additive] lemma is_mul_left_invariant_haar_measure (Kβ‚€ : positive_compacts G) : is_mul_left_invariant (haar_measure Kβ‚€) := begin intros g A hA, rw [haar_measure_apply hA, haar_measure_apply (measurable_const_mul g hA)], congr' 1, apply content.is_mul_left_invariant_outer_measure, apply is_left_invariant_haar_content, end @[to_additive] lemma haar_measure_self {Kβ‚€ : positive_compacts G} : haar_measure Kβ‚€ Kβ‚€.1 = 1 := begin haveI : locally_compact_space G := Kβ‚€.locally_compact_space_of_group, rw [haar_measure_apply Kβ‚€.2.1.measurable_set, ennreal.div_self], { rw [← pos_iff_ne_zero], exact haar_content_outer_measure_self_pos }, { exact ne_of_lt (content.outer_measure_lt_top_of_is_compact _ Kβ‚€.2.1) } end /-- The Haar measure is regular. -/ @[to_additive] instance regular_haar_measure {Kβ‚€ : positive_compacts G} : (haar_measure Kβ‚€).regular := begin haveI : locally_compact_space G := Kβ‚€.locally_compact_space_of_group, apply regular.smul, rw ennreal.inv_ne_top, exact haar_content_outer_measure_self_pos.ne', end /-- The Haar measure is sigma-finite in a second countable group. -/ @[to_additive] instance sigma_finite_haar_measure [second_countable_topology G] {Kβ‚€ : positive_compacts G} : sigma_finite (haar_measure Kβ‚€) := by { haveI : locally_compact_space G := Kβ‚€.locally_compact_space_of_group, apply_instance, } /-- The Haar measure is a Haar measure, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. -/ @[to_additive] instance is_haar_measure_haar_measure (Kβ‚€ : positive_compacts G) : is_haar_measure (haar_measure Kβ‚€) := begin apply is_haar_measure_of_is_compact_nonempty_interior _ (is_mul_left_invariant_haar_measure Kβ‚€) Kβ‚€.1 Kβ‚€.2.1 Kβ‚€.2.2, { simp only [haar_measure_self], exact one_ne_zero }, { simp only [haar_measure_self], exact ennreal.coe_ne_top }, end /-- `haar` is some choice of a Haar measure, on a locally compact group. -/ @[reducible, to_additive "`add_haar` is some choice of a Haar measure, on a locally compact additive group."] def haar [locally_compact_space G] : measure G := haar_measure $ classical.choice (topological_space.nonempty_positive_compacts G) section unique variables [second_countable_topology G] {ΞΌ : measure G} [sigma_finite ΞΌ] /-- The Haar measure is unique up to scaling. More precisely: every Οƒ-finite left invariant measure is a scalar multiple of the Haar measure. -/ @[to_additive] theorem haar_measure_unique (hΞΌ : is_mul_left_invariant ΞΌ) (Kβ‚€ : positive_compacts G) : ΞΌ = ΞΌ Kβ‚€.1 β€’ haar_measure Kβ‚€ := begin ext1 s hs, have := measure_mul_measure_eq hΞΌ (is_mul_left_invariant_haar_measure Kβ‚€) Kβ‚€.2.1 hs, rw [haar_measure_self, one_mul] at this, rw [← this (by norm_num), smul_apply], end @[to_additive] theorem regular_of_is_mul_left_invariant (hΞΌ : is_mul_left_invariant ΞΌ) {K} (hK : is_compact K) (h2K : (interior K).nonempty) (hΞΌK : ΞΌ K β‰  ∞) : regular ΞΌ := begin rw [haar_measure_unique hΞΌ ⟨K, hK, h2K⟩], exact regular.smul hΞΌK end end unique @[to_additive is_add_haar_measure_eq_smul_is_add_haar_measure] theorem is_haar_measure_eq_smul_is_haar_measure [locally_compact_space G] [second_countable_topology G] (ΞΌ Ξ½ : measure G) [is_haar_measure ΞΌ] [is_haar_measure Ξ½] : βˆƒ (c : ℝβ‰₯0∞), (c β‰  0) ∧ (c β‰  ∞) ∧ (ΞΌ = c β€’ Ξ½) := begin have K : positive_compacts G := classical.choice (topological_space.nonempty_positive_compacts G), have Ξ½pos : 0 < Ξ½ K.1 := haar_pos_of_nonempty_interior _ K.2.2, have Ξ½lt : Ξ½ K.1 < ∞ := is_compact.haar_lt_top _ K.2.1, refine ⟨μ K.1 / Ξ½ K.1, _, _, _⟩, { simp only [Ξ½lt.ne, (ΞΌ.haar_pos_of_nonempty_interior K.property.right).ne', ne.def, ennreal.div_zero_iff, not_false_iff, or_self] }, { simp only [div_eq_mul_inv, Ξ½pos.ne', (is_compact.haar_lt_top ΞΌ K.property.left).ne, or_self, ennreal.inv_eq_top, with_top.mul_eq_top_iff, ne.def, not_false_iff, and_false, false_and] }, { calc ΞΌ = ΞΌ K.1 β€’ haar_measure K : haar_measure_unique (is_mul_left_invariant_haar ΞΌ) K ... = (ΞΌ K.1 / Ξ½ K.1) β€’ (Ξ½ K.1 β€’ haar_measure K) : by rw [smul_smul, div_eq_mul_inv, mul_assoc, ennreal.inv_mul_cancel Ξ½pos.ne' Ξ½lt.ne, mul_one] ... = (ΞΌ K.1 / Ξ½ K.1) β€’ Ξ½ : by rw ← haar_measure_unique (is_mul_left_invariant_haar Ξ½) K } end /-- Any Haar measure is invariant under inversion in a commutative group. -/ @[to_additive] lemma map_haar_inv {G : Type*} [comm_group G] [topological_space G] [topological_group G] [t2_space G] [measurable_space G] [borel_space G] [locally_compact_space G] [second_countable_topology G] (ΞΌ : measure G) [is_haar_measure ΞΌ] : measure.map has_inv.inv ΞΌ = ΞΌ := begin -- the image measure is a Haar measure. By uniqueness up to multiplication, it is of the form -- `c ΞΌ`. Applying again inversion, one gets the measure `c^2 ΞΌ`. But since inversion is an -- involution, this is also `ΞΌ`. Hence, `c^2 = 1`, which implies `c = 1`. haveI : is_haar_measure (measure.map has_inv.inv ΞΌ) := is_haar_measure_map ΞΌ (mul_equiv.inv G) continuous_inv continuous_inv, obtain ⟨c, cpos, clt, hc⟩ : βˆƒ (c : ℝβ‰₯0∞), (c β‰  0) ∧ (c β‰  ∞) ∧ (measure.map has_inv.inv ΞΌ = c β€’ ΞΌ) := is_haar_measure_eq_smul_is_haar_measure _ _, have : map has_inv.inv (map has_inv.inv ΞΌ) = c^2 β€’ ΞΌ, by simp only [hc, smul_smul, pow_two, linear_map.map_smul], have ΞΌeq : ΞΌ = c^2 β€’ ΞΌ, { rw [map_map continuous_inv.measurable continuous_inv.measurable] at this, { simpa only [inv_involutive, involutive.comp_self, map_id] }, all_goals { apply_instance } }, have K : positive_compacts G := classical.choice (topological_space.nonempty_positive_compacts G), have : c^2 * ΞΌ K.1 = 1^2 * ΞΌ K.1, by { conv_rhs { rw ΞΌeq }, -- use `change` instead of `simp` to avoid `to_additive` issues change c ^ 2 * ΞΌ K.1 = 1 ^ 2 * (c ^ 2 * ΞΌ K.1), rw [one_pow, one_mul] }, have : c^2 = 1^2 := (ennreal.mul_eq_mul_right (haar_pos_of_nonempty_interior _ K.2.2).ne' (is_compact.haar_lt_top _ K.2.1).ne).1 this, have : c = 1 := (ennreal.pow_strict_mono two_ne_zero).injective this, rw [hc, this, one_smul] end @[simp, to_additive] lemma haar_preimage_inv {G : Type*} [comm_group G] [topological_space G] [topological_group G] [t2_space G] [measurable_space G] [borel_space G] [locally_compact_space G] [second_countable_topology G] (ΞΌ : measure G) [is_haar_measure ΞΌ] (s : set G) : ΞΌ (s⁻¹) = ΞΌ s := calc ΞΌ (s⁻¹) = measure.map (has_inv.inv) ΞΌ s : ((homeomorph.inv G).to_measurable_equiv.map_apply s).symm ... = ΞΌ s : by rw map_haar_inv end measure end measure_theory
b45dbcd6f0e1ad34d465f0ed834aa8aeaa23f9e8
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/buffer/parser/numeral.lean
4f604062d992624931b0ada718d9fbbaebd5874d
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
4,486
lean
/- Copyright (c) 2020 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import data.fintype.card import data.buffer.parser.basic /-! # Numeral parsers This file expands on the existing `nat : parser β„•` to provide parsers into any type `Ξ±` that can be represented by a numeral, which relies on `Ξ±` having a 0, 1, and addition operation. There are also convenience parsers that ensure that the numeral parsed in is not larger than the cardinality of the type `Ξ±` , if it is known that `fintype Ξ±`. Additionally, there are convenience parsers that parse in starting from "1", which can be useful for positive ordinals; or parser from a given character or character range. ## Main definitions * 'numeral` : The parser which uses `nat.cast` to map the result of `parser.nat` to the desired `Ξ±` * `numeral.of_fintype` : The parser which `guard`s to make sure the parsed numeral is within the cardinality of the target `fintype` type `Ξ±`. ## Implementation details When the `numeral` or related parsers are invoked, the desired type is provided explicitly. In many cases, it can be inferred, so one can write, for example ```lean def get_fin : string β†’ fin 5 := sum.elim (Ξ» _, 0) id ∘ parser.run_string (parser.numeral.of_fintype _) ``` In the definitions of the parsers (except for `numeral`), there is an explicit `nat.bin_cast` instead an explicit or implicit `nat.cast` -/ open parser parse_result namespace parser variables (Ξ± : Type) [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] /-- Parse a string of digits as a numeral while casting it to target type `Ξ±`. -/ @[derive [mono, bounded, prog]] def numeral : parser Ξ± := nat.bin_cast <$> nat /-- Parse a string of digits as a numeral while casting it to target type `Ξ±`, which has a `[fintype Ξ±]` constraint. The parser ensures that the numeral parsed in is within the cardinality of the type `Ξ±`. -/ @[derive [mono, bounded, prog]] def numeral.of_fintype [fintype Ξ±] : parser Ξ± := do c ← nat, decorate_error (sformat!"<numeral less than {to_string (fintype.card Ξ±)}>") (guard (c < fintype.card Ξ±)), pure $ nat.bin_cast c /-- Parse a string of digits as a numeral while casting it to target type `Ξ±`. The parsing starts at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure. -/ @[derive [mono, bounded, prog]] def numeral.from_one : parser Ξ± := do c ← nat, decorate_error ("<positive numeral>") (guard (0 < c)), pure $ nat.bin_cast (c - 1) /-- Parse a string of digits as a numeral while casting it to target type `Ξ±`, which has a `[fintype Ξ±]` constraint. The parser ensures that the numeral parsed in is within the cardinality of the type `Ξ±`. The parsing starts at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure. -/ @[derive [mono, bounded, prog]] def numeral.from_one.of_fintype [fintype Ξ±] : parser Ξ± := do c ← nat, decorate_error (sformat!"<positive numeral less than or equal to {to_string (fintype.card Ξ±)}>") (guard (0 < c ∧ c ≀ fintype.card Ξ±)), pure $ nat.bin_cast (c - 1) /-- Parse a character as a numeral while casting it to target type `Ξ±`, The parser ensures that the character parsed in is within the bounds set by `fromc` and `toc`, and subtracts the value of `fromc` from the parsed in character. -/ @[derive [mono, bounded, err_static, step]] def numeral.char (fromc toc : char) : parser Ξ± := do c ← decorate_error (sformat!"<char between '{fromc.to_string}' to '{toc.to_string}' inclusively>") (sat (Ξ» c, fromc ≀ c ∧ c ≀ toc)), pure $ nat.bin_cast (c.to_nat - fromc.to_nat) /-- Parse a character as a numeral while casting it to target type `Ξ±`, which has a `[fintype Ξ±]` constraint. The parser ensures that the character parsed in is greater or equal to `fromc` and and subtracts the value of `fromc` from the parsed in character. There is also a check that the resulting value is within the cardinality of the type `Ξ±`. -/ @[derive [mono, bounded, err_static, step]] def numeral.char.of_fintype [fintype Ξ±] (fromc : char) : parser Ξ± := do c ← decorate_error (sformat!"<char from '{fromc.to_string}' to '{ (char.of_nat (fromc.to_nat + fintype.card Ξ± - 1)).to_string}' inclusively>") (sat (Ξ» c, fromc ≀ c ∧ c.to_nat - fintype.card Ξ± < fromc.to_nat)), pure $ nat.bin_cast (c.to_nat - fromc.to_nat) end parser
c283f8242cdad38b9ff2f35b0217266bffb2be46
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
/src/Lean/Elab/Tactic/Induction.lean
46c7a99954a7732f2abe4c5bec5e1067245e4aa4
[ "Apache-2.0" ]
permissive
williamdemeo/lean4
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
refs/heads/master
1,678,305,356,877
1,614,708,995,000
1,614,708,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
24,877
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Parser.Term import Lean.Meta.RecursorInfo import Lean.Meta.CollectMVars import Lean.Meta.Tactic.ElimInfo import Lean.Meta.Tactic.Induction import Lean.Meta.Tactic.Cases import Lean.Elab.App import Lean.Elab.Tactic.ElabTerm import Lean.Elab.Tactic.Generalize namespace Lean.Elab.Tactic open Meta /- Given an `inductionAlt` of the form ``` nodeWithAntiquot "inductionAlt" `Lean.Parser.Tactic.inductionAlt $ ident' >> many ident' >> darrow >> termParser ``` -/ private def getAltName (alt : Syntax) : Name := -- alt[1] is of the form (("@"? ident) <|> "_") if alt[1].hasArgs then alt[1][1].getId.eraseMacroScopes else `_ private def altHasExplicitModifier (alt : Syntax) : Bool := alt[1].hasArgs && !alt[1][0].isNone private def getAltVarNames (alt : Syntax) : Array Name := alt[2].getArgs.map getNameOfIdent' private def getAltRHS (alt : Syntax) : Syntax := alt[4] private def getAltDArrow (alt : Syntax) : Syntax := alt[3] -- Return true if `stx` is a term occurring in the RHS of the induction/cases tactic def isHoleRHS (rhs : Syntax) : Bool := rhs.isOfKind ``Parser.Term.syntheticHole || rhs.isOfKind ``Parser.Term.hole def evalAlt (mvarId : MVarId) (alt : Syntax) (remainingGoals : Array MVarId) : TacticM (Array MVarId) := withRef (getAltDArrow alt) do -- using `=>`'s position for error messages let rhs := getAltRHS alt if isHoleRHS rhs then let gs' ← withMVarContext mvarId $ withRef rhs do let mvarDecl ← getMVarDecl mvarId let val ← elabTermEnsuringType rhs mvarDecl.type assignExprMVar mvarId val let gs' ← getMVarsNoDelayed val tagUntaggedGoals mvarDecl.userName `induction gs'.toList pure gs' pure (remainingGoals ++ gs') else setGoals [mvarId] closeUsingOrAdmit rhs pure remainingGoals /- Helper method for creating an user-defined eliminator/recursor application. -/ namespace ElimApp structure Context where elimInfo : ElimInfo targets : Array Expr -- targets provided by the user structure State where argPos : Nat := 0 -- current argument position targetPos : Nat := 0 -- current target at targetsStx f : Expr fType : Expr alts : Array (Name Γ— MVarId) := #[] instMVars : Array MVarId := #[] abbrev M := ReaderT Context $ StateRefT State TermElabM private def addInstMVar (mvarId : MVarId) : M Unit := modify fun s => { s with instMVars := s.instMVars.push mvarId } private def addNewArg (arg : Expr) : M Unit := modify fun s => { s with argPos := s.argPos+1, f := mkApp s.f arg, fType := s.fType.bindingBody!.instantiate1 arg } /- Return the binder name at `fType`. This method assumes `fType` is a function type. -/ private def getBindingName : M Name := return (← get).fType.bindingName! /- Return the next argument expected type. This method assumes `fType` is a function type. -/ private def getArgExpectedType : M Expr := return (← get).fType.bindingDomain! private def getFType : M Expr := do let fType ← whnfForall (← get).fType modify fun s => { s with fType := fType } pure fType structure Result where elimApp : Expr alts : Array (Name Γ— MVarId) := #[] partial def mkElimApp (elimName : Name) (elimInfo : ElimInfo) (targets : Array Expr) (tag : Name) : TermElabM Result := do let rec loop : M Unit := do match (← getFType) with | Expr.forallE binderName _ _ c => let ctx ← read let argPos := (← get).argPos if ctx.elimInfo.motivePos == argPos then let motive ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.syntheticOpaque addNewArg motive else if ctx.elimInfo.targetsPos.contains argPos then if c.binderInfo.isExplicit then let s ← get let ctx ← read unless s.targetPos < ctx.targets.size do throwError! "insufficient number of targets for '{elimName}'" let target := ctx.targets[s.targetPos] let expectedType ← getArgExpectedType let target ← Term.ensureHasType expectedType target modify fun s => { s with targetPos := s.targetPos + 1 } addNewArg target else let target ← mkFreshExprMVar (← getArgExpectedType) addNewArg target else match c.binderInfo with | BinderInfo.implicit => let arg ← mkFreshExprMVar (← getArgExpectedType) addNewArg arg | BinderInfo.instImplicit => let arg ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.synthetic addInstMVar arg.mvarId! addNewArg arg | _ => let alt ← mkFreshExprSyntheticOpaqueMVar (← getArgExpectedType) (tag := appendTag tag binderName) modify fun s => { s with alts := s.alts.push (← getBindingName, alt.mvarId!) } addNewArg alt loop | _ => pure () let f ← Term.mkConst elimName let fType ← inferType f let (_, s) ← loop.run { elimInfo := elimInfo, targets := targets } |>.run { f := f, fType := fType } Lean.Elab.Term.synthesizeAppInstMVars s.instMVars pure { elimApp := (← instantiateMVars s.f), alts := s.alts } /- Given a goal `... targets ... |- C[targets]` associated with `mvarId`, assign `motiveArg := fun targets => C[targets]` -/ def setMotiveArg (mvarId : MVarId) (motiveArg : MVarId) (targets : Array FVarId) : MetaM Unit := do let type ← inferType (mkMVar mvarId) let motive ← mkLambdaFVars (targets.map mkFVar) type let motiverInferredType ← inferType motive let motiveType ← inferType (mkMVar motiveArg) unless (← isDefEqGuarded motiverInferredType motiveType) do throwError! "type mismatch when assigning motive{indentExpr motive}\n{← mkHasTypeButIsExpectedMsg motiverInferredType motiveType}" assignExprMVar motiveArg motive private def getAltNumFields (elimInfo : ElimInfo) (altName : Name) : TermElabM Nat := do for altInfo in elimInfo.altsInfo do if altInfo.name == altName then return altInfo.numFields throwError! "unknown alternative name '{altName}'" private def checkAltNames (alts : Array (Name Γ— MVarId)) (altsSyntax : Array Syntax) : TacticM Unit := for altStx in altsSyntax do let altName := getAltName altStx if altName != `_ then unless alts.any fun (n, _) => n == altName do throwErrorAt! altStx "invalid alternative name '{altName}'" def evalAlts (elimInfo : ElimInfo) (alts : Array (Name Γ— MVarId)) (altsSyntax : Array Syntax) (numEqs : Nat := 0) (numGeneralized : Nat := 0) (toClear : Array FVarId := #[]) : TacticM Unit := do checkAltNames alts altsSyntax let mut usedWildcard := false let hasAlts := altsSyntax.size > 0 let mut subgoals := #[] -- when alternatives are not provided, we accumulate subgoals here let mut altsSyntax := altsSyntax for (altName, altMVarId) in alts do let numFields ← getAltNumFields elimInfo altName let altStx? ← match altsSyntax.findIdx? (fun alt => getAltName alt == altName) with | some idx => let altStx := altsSyntax[idx] altsSyntax := altsSyntax.eraseIdx idx pure (some altStx) | none => match altsSyntax.findIdx? (fun alt => getAltName alt == `_) with | some idx => usedWildcard := true pure (some altsSyntax[idx]) | none => pure none match altStx? with | none => let mut (_, altMVarId) ← introN altMVarId numFields match (← Cases.unifyEqs numEqs altMVarId {}) with | none => pure () -- alternative is not reachable | some (altMVarId, _) => if !hasAlts then -- User did not provide alternatives using `|` let (_, altMVarId) ← introNP altMVarId numGeneralized for fvarId in toClear do altMVarId ← tryClear altMVarId fvarId trace[Meta.debug]! "new subgoal {MessageData.ofGoal altMVarId}" subgoals := subgoals.push altMVarId else throwError! "alternative '{altName}' has not been provided" | some altStx => subgoals ← withRef altStx do let altVarNames := getAltVarNames altStx let mut (_, altMVarId) ← introN altMVarId numFields altVarNames.toList (useNamesForExplicitOnly := !altHasExplicitModifier altStx) match (← Cases.unifyEqs numEqs altMVarId {}) with | none => throwError! "alternative '{altName}' is not needed" | some (altMVarId, _) => let (_, altMVarId) ← introNP altMVarId numGeneralized for fvarId in toClear do altMVarId ← tryClear altMVarId fvarId evalAlt altMVarId altStx subgoals if usedWildcard then altsSyntax := altsSyntax.filter fun alt => getAltName alt != `_ unless altsSyntax.isEmpty do throwErrorAt altsSyntax[0] "unused alternative" setGoals subgoals.toList end ElimApp /- Recall that ``` generalizingVars := optional (" generalizing " >> many1 ident) Β«inductionΒ» := parser! nonReservedSymbol "induction " >> majorPremise >> usingRec >> generalizingVars >> optional inductionAlts ``` `stx` is syntax for `induction`. -/ private def getGeneralizingFVarIds (stx : Syntax) : TacticM (Array FVarId) := withRef stx do let generalizingStx := stx[3] if generalizingStx.isNone then pure #[] else withMainMVarContext do trace `Elab.induction fun _ => generalizingStx let vars := generalizingStx[1].getArgs getFVarIds vars -- process `generalizingVars` subterm of induction Syntax `stx`. private def generalizeVars (stx : Syntax) (targets : Array Expr) : TacticM Nat := do let fvarIds ← getGeneralizingFVarIds stx liftMetaTacticAux fun mvarId => do let (fvarIds, mvarId') ← Meta.revert mvarId fvarIds if targets.any fun target => fvarIds.contains target.fvarId! then Meta.throwTacticEx `induction mvarId "major premise depends on variable being generalized" pure (fvarIds.size, [mvarId']) private def getAltsOfInductionAlts (inductionAlts : Syntax) : Array Syntax := inductionAlts[1].getArgs private def getAltsOfOptInductionAlts (optInductionAlts : Syntax) : Array Syntax := if optInductionAlts.isNone then #[] else getAltsOfInductionAlts optInductionAlts[0] /- We may have at most one `| _ => ...` (wildcard alternative), and it must not set variable names. The idea is to make sure users do not write unstructured tactics. -/ private def checkAltsOfOptInductionAlts (optInductionAlts : Syntax) : TacticM Unit := unless optInductionAlts.isNone do let mut found := false for alt in getAltsOfInductionAlts optInductionAlts[0] do let n := getAltName alt if n == `_ then unless (getAltVarNames alt).isEmpty do throwErrorAt! alt "wildcard alternative must not specify variable names" if found then throwErrorAt! alt "more than one wildcard alternative '| _ => ...' used" found := true /- Given alts of the form ``` nodeWithAntiquot "inductionAlt" `Lean.Parser.Tactic.inductionAlt $ ident' >> many ident' >> darrow >> termParser ``` esnure the first `ident'` is `_` or a constructor name. -/ private def checkAltCtorNames (alts : Array Syntax) (ctorNames : List Name) : TacticM Unit := for alt in alts do let n := getAltName alt withRef alt $ trace[Elab.checkAlt]! "{n} , {alt}" unless n == `_ || ctorNames.any (fun ctorName => n.isSuffixOf ctorName) do throwErrorAt! alt[0] "invalid constructor name '{n}'" structure RecInfo where recName : Name alts : Array Syntax := #[] -- alternatives def getInductiveValFromMajor (major : Expr) : TacticM InductiveVal := liftMetaMAtMain fun mvarId => do let majorType ← inferType major let majorType ← whnf majorType matchConstInduct majorType.getAppFn (fun _ => Meta.throwTacticEx `induction mvarId m!"major premise type is not an inductive type {indentExpr majorType}") (fun val _ => pure val) private partial def getRecFromUsingLoop (baseRecName : Name) (majorType : Expr) : TacticM (Option Meta.RecursorInfo) := do let finalize (majorType : Expr) : TacticM (Option Meta.RecursorInfo) := do let majorType? ← unfoldDefinition? majorType match majorType? with | some majorType => withIncRecDepth $ getRecFromUsingLoop baseRecName majorType | none => pure none let majorType ← whnfCore majorType match majorType.getAppFn with | Expr.const name _ _ => let candidate := name ++ baseRecName match (← getEnv).find? candidate with | some _ => try liftMetaMAtMain fun _ => do let info ← Meta.mkRecursorInfo candidate pure (some info) catch _ => finalize majorType | none => finalize majorType | _ => finalize majorType def getRecFromUsing (major : Expr) (baseRecName : Name) : TacticM Meta.RecursorInfo := do match ← getRecFromUsingLoop baseRecName (← inferType major) with | some recInfo => pure recInfo | none => let recName ← resolveGlobalConstNoOverload baseRecName try liftMetaMAtMain fun _ => Meta.mkRecursorInfo recName catch _ => throwError! "invalid recursor name '{baseRecName}'" /- Create `RecInfo` assuming builtin recursor -/ private def getRecInfoDefault (major : Expr) (optInductionAlts : Syntax) (allowMissingAlts : Bool) : TacticM (RecInfo Γ— Array Name) := do let indVal ← getInductiveValFromMajor major let recName := mkRecName indVal.name if optInductionAlts.isNone then pure ({ recName := recName }, #[]) else let ctorNames := indVal.ctors let alts := getAltsOfInductionAlts optInductionAlts[0] checkAltCtorNames alts ctorNames let mut altsNew := #[] -- This code can be simplified if we decide to keep `checkAltsOfOptInductionAlts` let mut remainingAlts := alts let mut prevAnonymousAlt? := none for ctorName in ctorNames do match remainingAlts.findIdx? (fun alt => (getAltName alt).isSuffixOf ctorName) with | some idx => let newAlt := remainingAlts[idx] altsNew := altsNew.push newAlt remainingAlts := remainingAlts.eraseIdx idx | none => match remainingAlts.findIdx? (fun alt => getAltName alt == `_) with | some idx => let newAlt := remainingAlts[idx] altsNew := altsNew.push newAlt remainingAlts := remainingAlts.eraseIdx idx prevAnonymousAlt? := some newAlt | none => match prevAnonymousAlt? with | some alt => altsNew := altsNew.push alt | none => if allowMissingAlts then altsNew := altsNew.push Syntax.missing else throwError! "alternative for constructor '{ctorName}' is missing" unless remainingAlts.isEmpty do throwErrorAt remainingAlts[0] "unused alternative" pure ({ recName := recName, alts := altsNew }, ctorNames.toArray) /- Recall that ``` altRHS := Term.hole <|> Term.syntheticHole <|> tacticSeq inductionAlt : Parser := parser! ident' >> many ident' >> darrow >> altRHS inductionAlts : Parser := parser! withPosition ("| " >> sepBy1 inductionAlt (checkColGe "alternatives must be indented" >> "|")) usingRec : Parser := optional (" using " >> ident) generalizingVars := optional (" generalizing " >> many1 ident) induction := parser! nonReservedSymbol "induction " >> sepBy1 termParser ", " >> usingRec >> generalizingVars >> optional inductionAlts ``` -/ private def getRecInfo (stx : Syntax) (major : Expr) : TacticM RecInfo := withRef stx $ withMainMVarContext do let usingRecStx := stx[2] let optInductionAlts := stx[4] checkAltsOfOptInductionAlts optInductionAlts if usingRecStx.isNone then let (rinfo, _) ← getRecInfoDefault major optInductionAlts false pure rinfo else let baseRecName := usingRecStx.getIdAt 1 |>.eraseMacroScopes let recInfo ← getRecFromUsing major baseRecName let recName := recInfo.recursorName if optInductionAlts.isNone then pure { recName := recName } else let alts := getAltsOfInductionAlts optInductionAlts[0] let paramNames ← liftMetaMAtMain fun _ => getParamNames recInfo.recursorName let mut remainingAlts := alts let mut prevAnonymousAlt? := none let mut altsNew := #[] for i in [:paramNames.size] do if recInfo.isMinor i then let paramName := paramNames[i] match remainingAlts.findIdx? (fun alt => getAltName alt == paramName) with | some idx => let newAlt := remainingAlts[idx] altsNew := altsNew.push newAlt remainingAlts := remainingAlts.eraseIdx idx | none => match remainingAlts.findIdx? (fun alt => getAltName alt == `_) with | some idx => let newAlt := remainingAlts[idx] altsNew := altsNew.push newAlt remainingAlts := remainingAlts.eraseIdx idx prevAnonymousAlt? := some newAlt | none => match prevAnonymousAlt? with | some alt => altsNew := altsNew.push alt | none => throwError! "alternative for minor premise '{paramName}' is missing" unless remainingAlts.isEmpty do throwErrorAt remainingAlts[0] "unused alternative" pure { recName := recName, alts := altsNew } private def processResult (alts : Array Syntax) (result : Array Meta.InductionSubgoal) (numToIntro : Nat := 0) : TacticM Unit := do if alts.isEmpty then setGoals <| result.toList.map fun s => s.mvarId else unless alts.size == result.size do throwError! "mistmatch on the number of subgoals produced ({result.size}) and alternatives provided ({alts.size})" let mut gs := #[] for i in [:result.size] do let subgoal := result[i] let mut mvarId := subgoal.mvarId if numToIntro > 0 then (_, mvarId) ← introNP mvarId numToIntro gs ← evalAlt mvarId alts[i] gs setGoals gs.toList private def generalizeTerm (term : Expr) : TacticM Expr := do match term with | Expr.fvar .. => pure term | _ => liftMetaTacticAux fun mvarId => do let mvarId ← Meta.generalize mvarId term `x false let (fvarId, mvarId) ← Meta.intro1 mvarId pure (mkFVar fvarId, [mvarId]) @[builtinTactic Lean.Parser.Tactic.induction] def evalInduction : Tactic := fun stx => focus do let targets ← stx[1].getSepArgs.mapM fun target => do let target ← withMainMVarContext <| elabTerm target none generalizeTerm target let n ← generalizeVars stx targets if targets.size == 1 then let recInfo ← getRecInfo stx targets[0] let (mvarId, _) ← getMainGoal let altVars := recInfo.alts.map fun alt => { explicit := altHasExplicitModifier alt, varNames := (getAltVarNames alt).toList : AltVarNames } let result ← Meta.induction mvarId targets[0].fvarId! recInfo.recName altVars processResult recInfo.alts result (numToIntro := n) else if stx[2].isNone then throwError! "eliminator must be provided when multiple targets are used (use 'using <eliminator-name>')" let elimId := stx[2][1] let elimName ← withRef elimId do resolveGlobalConstNoOverload elimId.getId.eraseMacroScopes let elimInfo ← withRef elimId do getElimInfo elimName let (mvarId, _) ← getMainGoal let tag ← getMVarTag mvarId withMVarContext mvarId do let result ← withRef stx[1] do -- use target position as reference ElimApp.mkElimApp elimName elimInfo targets tag assignExprMVar mvarId result.elimApp let elimArgs := result.elimApp.getAppArgs let targets ← elimInfo.targetsPos.mapM fun i => instantiateMVars elimArgs[i] let targetFVarIds := targets.map (Β·.fvarId!) ElimApp.setMotiveArg mvarId elimArgs[elimInfo.motivePos].mvarId! targetFVarIds let optInductionAlts := stx[4] ElimApp.evalAlts elimInfo result.alts (getAltsOfOptInductionAlts optInductionAlts) (numGeneralized := n) (toClear := targetFVarIds) private partial def checkCasesResult (casesResult : Array Meta.CasesSubgoal) (ctorNames : Array Name) (alts : Array Syntax) : TacticM Unit := do let rec loop (i j : Nat) : TacticM Unit := if h : j < alts.size then do let alt := alts.get ⟨j, h⟩ if alt.isMissing then loop i (j+1) else let ctorName := ctorNames.get! j if h : i < casesResult.size then let subgoal := casesResult.get ⟨i, h⟩ if ctorName == subgoal.ctorName then loop (i+1) (j+1) else throwError! "alternative for '{subgoal.ctorName}' has not been provided" else throwError! "alternative for '{ctorName}' is not needed" else if h : i < casesResult.size then let subgoal := casesResult.get ⟨i, h⟩ throwError! "alternative for '{subgoal.ctorName}' has not been provided" else pure () unless alts.isEmpty do loop 0 0 -- Recall that -- majorPremise := parser! optional (try (ident >> " : ")) >> termParser private def getTargetHypothesisName? (target : Syntax) : Option Name := if target[0].isNone then none else some target[0][0].getId private def getTargetTerm (target : Syntax) : Syntax := target[1] private def elabTaggedTerm (h? : Option Name) (termStx : Syntax) : TacticM Expr := withMainMVarContext $ withRef termStx do let term ← elabTerm termStx none match h? with | none => pure term | some h => let lctx ← getLCtx let x ← mkFreshUserName `x evalGeneralizeAux h? term x withMainMVarContext do let lctx ← getLCtx match lctx.findFromUserName? x with | some decl => pure decl.toExpr | none => throwError "failed to generalize" def elabTargets (targets : Array Syntax) : TacticM (Array Expr) := targets.mapM fun target => do let h? := getTargetHypothesisName? target let term ← elabTaggedTerm h? (getTargetTerm target) generalizeTerm term builtin_initialize registerTraceClass `Elab.cases /- Default `cases` tactic that uses `casesOn` eliminator -/ def evalCasesOn (target : Expr) (optInductionAlts : Syntax) : TacticM Unit := do let (mvarId, _) ← getMainGoal let (recInfo, ctorNames) ← getRecInfoDefault target optInductionAlts (allowMissingAlts := true) let altVars := recInfo.alts.map fun alt => { explicit := altHasExplicitModifier alt, varNames := (getAltVarNames alt).toList : AltVarNames } let result ← Meta.cases mvarId target.fvarId! altVars trace[Elab.cases]! "recInfo.alts.size: #{recInfo.alts.size} {recInfo.alts.map getAltVarNames}" trace[Elab.cases]! "recInfo.alts: #{recInfo.alts.map toString}" checkCasesResult result ctorNames recInfo.alts let result := result.map (fun s => s.toInductionSubgoal) let alts := recInfo.alts.filter fun stx => !stx.isMissing processResult alts result def evalCasesUsing (elimId : Syntax) (targetRef : Syntax) (targets : Array Expr) (optInductionAlts : Syntax) : TacticM Unit := do let elimName ← withRef elimId do resolveGlobalConstNoOverload elimId.getId.eraseMacroScopes let elimInfo ← withRef elimId do getElimInfo elimName let (mvarId, _) ← getMainGoal let tag ← getMVarTag mvarId withMVarContext mvarId do let result ← withRef targetRef <| ElimApp.mkElimApp elimName elimInfo targets tag let elimArgs := result.elimApp.getAppArgs let targets ← elimInfo.targetsPos.mapM fun i => instantiateMVars elimArgs[i] let motiveType ← inferType elimArgs[elimInfo.motivePos] let mvarId ← generalizeTargets mvarId motiveType targets let (targetsNew, mvarId) ← introN mvarId targets.size withMVarContext mvarId do ElimApp.setMotiveArg mvarId elimArgs[elimInfo.motivePos].mvarId! targetsNew assignExprMVar mvarId result.elimApp ElimApp.evalAlts elimInfo result.alts (getAltsOfOptInductionAlts optInductionAlts) (numEqs := targets.size) (toClear := targetsNew) @[builtinTactic Lean.Parser.Tactic.cases] def evalCases : Tactic := fun stx => focus do -- parser! nonReservedSymbol "cases " >> sepBy1 (group majorPremise) ", " >> usingRec >> optInductionAlts let targets ← elabTargets stx[1].getSepArgs let optInductionAlts := stx[3] checkAltsOfOptInductionAlts optInductionAlts if stx[2].isNone then unless targets.size == 1 do throwErrorAt stx[1] "multiple targets are only supported when a user-defined eliminator is provided with 'using'" evalCasesOn targets[0] optInductionAlts else evalCasesUsing stx[2][1] (targetRef := stx[1]) targets optInductionAlts end Lean.Elab.Tactic
ae60ef963b5682913f37bab4cb76271237a5e0c4
934eae675a9d997202bb021816325184e7d694aa
/_notes/Languages/lean/myproject/IMP.lean
f93b708a85d07d0b1371ec71e17ec23de557ffb7
[]
no_license
philzook58/philzook58.github.io
da78841df4ffd9a19c81e0eab833983d95a64b70
76000a5847bd6ee41dff25937ae916835bbcf03f
refs/heads/master
1,692,951,958,916
1,692,631,945,000
1,692,631,945,000
91,513,884
9
4
null
1,677,330,791,000
1,494,977,989,000
Jupyter Notebook
UTF-8
Lean
false
false
24,106
lean
-- From Coq Require Import Arith ZArith Psatz Bool String List Program.Equality. -- Require Import Sequences. /- -/ -- Local Open Scope string_scope. -- Local Open Scope Z_scope. -- Local Open Scope list_scope. -- import home.philip.Documents.lean.std4.Std.Data.Int.Basics -- import Std.Data.List.Basic import Std.Data.Int.Basic import Std.Data.Int.Lemmas import Std.Data.List.Basic import Mathlib.Tactic.LibrarySearch import Mathlib.Tactic.Linarith #eval Lean.versionString #eval 1 + 1 #check (1 : Int) #check "string" /- -- /-* * 1. The source language: IMP -/ -/ -- /-* ** 1.1 Arithmetic expressions -/ abbrev ident : Type := String #check String -- def mythree : Nat := 3 -- type ident = string -- /-* The abstract syntax: an arithmetic expression is either... -/ def myid : forall {a :Type}, a -> a := fun x => x def myid2 : {a :Type} -> a -> a := fun x => x #check myid inductive aexp where | CONST (n : Int) : aexp -- /-*r a constant, or -/ | VAR (x : ident) : aexp -- /-*r a variable, or -/ | PLUS (a1 : aexp) (a2 : aexp) : aexp -- /-*r a sum of two expressions, or -/ | MINUS (a1 : aexp) (a2 : aexp) : aexp -- /-*r a difference of two expressions -/ /- /- * The denotational semantics: an evaluation function that computes the integer value denoted by an expression. It is parameterized by a store [s] that associates values to variables. -/ -/ def store : Type := ident -> Int def aeval (s: store) (a: aexp) : Int := match a with | aexp.CONST n => n | aexp.VAR x => s x | aexp.PLUS a1 a2 => aeval s a1 + aeval s a2 | aexp.MINUS a1 a2 => aeval s a1 - aeval s a2 --/-* Such evaluation functions / denotational semantics have many uses. -- First, we can use [aeval] to evaluate a given expression in a given store. -/ #eval (aeval (fun _x => 2) (aexp.PLUS (aexp.VAR "x") (aexp.MINUS (aexp.VAR "x") (aexp.CONST 1)))) -- /-* Result is: [ = 3 : Z ]. -/ -- /-* We can also do partial evaluation with respect to an unknown store -/ open aexp -- hmm #eval doesn't work. #reduce is a little too aggressive #reduce (fun s => aeval s (PLUS (VAR "x") (MINUS (CONST 10) (CONST 1)))) -- example : forall s, 42 = aeval s (PLUS (VAR "x") (MINUS (CONST 10) (CONST 1))) := by -- intros -- simp [aeval] --/-* Result is: [ = fun s : store => s "x" + 9 ]. -/ -- /-* We can prove properties of a given expression. -/ #print Int.lt_succ --set_option trace.Compiler. --set_option t.Compiler.simp true --set_option trace.Debug.Meta.Tactic.simp true set_option trace.Meta.Tactic.simp true --set_option pp.all true theorem aeval_xplus1 : forall (s :store) (x :ident), aeval s (PLUS (VAR x) (CONST 1)) > aeval s (VAR x) := by intros s x --simp? [aeval] simp only [aeval, gt_iff_lt, lt_add_iff_pos_right] --simp [aeval] --linarith -- huh merely importing Linarith makes simpe discharge this -- library_search -- apply Int.lt_succ -- delta aeval #check "hi" #check 10 #check aeval_xplus1 /- Proof. intros. cbn. lia. Qed. -/ /- /-* Finally, we can prove "meta-properties" that hold for all expressions. For example: the value of an expression depends only on the values of its free variables. Free variables are defined by this recursive predicate: -/ -/ def free_in_aexp (x: ident) (a: aexp) : Prop := match a with | CONST n => False | VAR y => y = x | PLUS a1 a2 | MINUS a1 a2 => free_in_aexp x a1 \/ free_in_aexp x a2 theorem aeval_free: forall s1 s2 a, (forall x, free_in_aexp x a -> s1 x = s2 x) -> aeval s1 a = aeval s2 a := by intros s1 s2 a induction a <;> simp [aeval] <;> intros hyp -- case CONST n => simp [aeval] case VAR x => apply hyp; simp [free_in_aexp] -- what a mess case PLUS a1 a2 => rw [a1, a2] <;> intros x f <;> apply hyp <;> simp [free_in_aexp]; apply Or.inr; assumption; apply Or.inl; assumption case MINUS a1 a2 => rw [a1, a2] <;> intros x f <;> apply hyp <;> simp [free_in_aexp]; apply Or.inr; assumption; apply Or.inl; assumption #check "hello" /- Proof. induction a; cbn; intros SAMEFREE. - /- Case a = CONST n -/ auto. - /- Case a = VAR x -/ apply SAMEFREE. auto. - /- Case a = PLUS a1 a2 -/ rewrite IHa1, IHa2. auto. auto. auto. - /- Case a = MINUS a1 a2 -/ rewrite IHa1, IHa2; auto. Qed. /-* *** Exercise (1 star, recommended). -/ /-* Add support for multiplication in arithmetic expressions. Modify the [aexp] type and the [aeval] function accordingly. -/ /-* *** Exercise (2 stars, recommended). -/ /-* Add support for division and for detecting arithmetic overflow. With this extension, the evaluation of an expression can produce an error: integer division by zero or result that exceeds the range [[min_int, max_int]]. You can either change the type of the function [aeval] to << aeval: store -> aexp -> option Z >> with [None] meaning "error" and [Some n] meaning "success with result n". Alternatively, you can define the semantics as a relation instead of a function: << Inductive aeval_rel: store -> aexp -> Z -> Prop := ... >> Some definitions you can use: -/ -/ #check Int.pow def min_int := - ((2 : Int) ^ 63) def max_int := (2 : Int) ^ 63 - 1 def check_for_overflow (n: Int): Option Int := if n < min_int then none else if n > max_int then none else some n #eval (check_for_overflow 2222222222222222222) /- /-* ** 1.3 Boolean expressions -/ /-* The IMP language has conditional statements (if/then/else) and loops. They are controlled by expressions that evaluate to Boolean values. Here is the abstract syntax of Boolean expressions. -/ -/ inductive bexp : Type := | TRUE -- /-*r always true -/ | FALSE -- /-*r always false -/ | EQUAL (a1: aexp) (a2: aexp) -- /-*r whether [a1 = a2] -/ | LESSEQUAL (a1: aexp) (a2: aexp) -- /-*r whether [a1 <= a2] -/ | NOT (b1: bexp) -- /-*r Boolean negation -/ | AND (b1: bexp) (b2: bexp) -- /-*r Boolean conjunction -/ /- /-* Just like arithmetic expressions evaluate to integers, Boolean expressions evaluate to Boolean values [true] or [false]. -/ -/ open bexp def beval (s: store) (b: bexp) : Bool := match b with | TRUE => true | FALSE => false | EQUAL a1 a2 => aeval s a1 == aeval s a2 | LESSEQUAL a1 a2 => aeval s a1 <= aeval s a2 | NOT b1 => not (beval s b1) | AND b1 b2 => beval s b1 && beval s b2 -- /-* There are many useful derived forms. -/ def NOTEQUAL (a1 a2: aexp) : bexp := NOT (EQUAL a1 a2) def GREATEREQUAL (a1 a2: aexp) : bexp := LESSEQUAL a2 a1 def GREATER (a1 a2: aexp) : bexp := NOT (LESSEQUAL a1 a2) def LESS (a1 a2: aexp) : bexp := GREATER a2 a1 def OR (b1 b2: bexp) : bexp := NOT (AND (NOT b1) (NOT b2)) -- /- * *** Exercise (1 star, recommended) -/ -- /- * Show the expected semantics for the [OR] derived form: -/ lemma beval_OR : forall s b1 b2, beval s (OR b1 b2) = (beval s b1 || beval s b2) := by intros s b1 b2 simp [beval] --rw [Bool.not_and] --library_search cases (beval s b1) <;> cases (beval s b2) <;> simp /- Proof. intros; cbn. /- Hint: do "SearchAbout negb" to see the available lemmas about Boolean negation. -/ /- Hint: or just do a case analysis on [beval s b1] and [beval s b2], there are only 4 cases to consider. -/ /- FILL IN HERE -/ Abort. -/ /-* ** 1.4 Commands -/ /-* To complete the definition of the IMP language, here is the abstract syntax of commands, also known as statements. -/ inductive com: Type := | SKIP /-*r do nothing -/ | ASSIGN (x: ident) (a: aexp) /-*r assignment: [v := a] -/ | SEQ (c1: com) (c2: com) /-*r sequence: [c1; c2] -/ | IFTHENELSE (b: bexp) (c1: com) (c2: com) /-*r conditional: [if b then c1 else c2] -/ | WHILE (b: bexp) (c1: com) /-*r loop: [while b do c1 done] -/ /-* We can write [c1 ;; c2] instead of [SEQ c1 c2], it is easier on the eyes. -/ infixr:80 ";;" => com.SEQ -- (at level 80, right associativity). /-* Here is an IMP program that performs Euclidean division by repeated subtraction. At the end of the program, "q" contains the quotient of "a" by "b", and "r" contains the remainder. In pseudocode: << r := a; q := 0; while b <= r do r := r - b; q := q + 1 done >> In abstract syntax: -/ open com def Euclidean_division := ASSIGN "r" (VAR "a") ;; ASSIGN "q" (CONST 0) ;; WHILE (LESSEQUAL (VAR "b") (VAR "r")) (ASSIGN "r" (MINUS (VAR "r") (VAR "b")) ;; ASSIGN "q" (PLUS (VAR "q") (CONST 1))) /-* A useful operation over stores: [update x v s] is the store that maps [x] to [v] and is equal to [s] for all variables other than [x]. -/ #print ident #print store def update (x: ident) (v: Int) (s: store) : store := fun y => if x == y then v else s y /-* A naive approach to giving semantics to commands is to write an evaluation function [cexec s c] that runs the command [c] in initial store [s] and returns the final store when [c] terminates. -/ -- Lean accepts this deftion with the unsafe keyword unsafe def cexec' (s: store) (c: com) : store := match c with | SKIP => s | ASSIGN x a => update x (aeval s a) s | SEQ c1 c2 => let s' := cexec' s c1 cexec' s' c2 | IFTHENELSE b c1 c2 => if beval s b then cexec' s c1 else cexec' s c2 | WHILE b c1 => if beval s b then (let s' := cexec' s c1 cexec' s' (WHILE b c1)) else s /-* The definition above is rejected by Coq, and rightly so, because all Coq functions must terminate, yet the [WHILE] case may not terminate. Consider for example the infinite loop [WHILE TRUE SKIP]. Worse, IMP is Turing-complete, since it has unbounded iteration ([WHILE]) plus arbitrary-precision integers. Hence, there is no computable function [cexec s c] that would return [Some s'] if [c] terminates with store [s'], and [None] if [c] does not terminate. However, instead of computable functions, we can use a relation [cexec s c s'] that holds iff command [c], started in state [s], terminates with state [s']. This relation can easily be defined as a Coq inductive predicate: -/ inductive cexec: store -> com -> store -> Prop where | cexec_skip: forall s, cexec s SKIP s | cexec_assign: forall s x a, cexec s (ASSIGN x a) (update x (aeval s a) s) | cexec_seq: forall c1 c2 s s' s'', cexec s c1 s' -> cexec s' c2 s'' -> cexec s (SEQ c1 c2) s'' | cexec_ifthenelse: forall b c1 c2 s s', cexec s (if beval s b then c1 else c2) s' -> cexec s (IFTHENELSE b c1 c2) s' | cexec_while_done: forall b c s, beval s b = false -> cexec s (WHILE b c) s | cexec_while_loop: forall b c s s' s'', beval s b = true -> cexec s c s' -> cexec s' (WHILE b c) s'' -> cexec s (WHILE b c) s'' /-* This style of semantics is known as natural semantics or big-step operational semantics. The predicate [cexec s c s'] holds iff there exists a finite derivation of this conclusion, using the axioms and inference rules above. The structure of the derivation represents the computations performed by [c] in a tree-like manner. The finiteness of the derivation guarantees that only terminating executions satisfy [cexec]. Indeed, [WHILE TRUE SKIP] does not satisfy [cexec]: -/ lemma cexec_infinite_loop: forall s, Β¬ exists s', cexec s (WHILE TRUE SKIP) s':= by sorry /- assert (A: forall s c s', cexec s c s' -> c = WHILE TRUE SKIP -> False). { induction 1; intros EQ; inversion EQ. - subst b c. cbn in H. discriminate. - subst b c. apply IHcexec2. auto. } intros s (s' & EXEC). apply A with (s := s) (c := WHILE TRUE SKIP) (s' := s'); auto. Qed. -/ /-* Our naive idea of an execution function for commands was not completely off. We can define an approximation of such a function by bounding a priori the recursion depth, using a [fuel] parameter of type [nat]. When the fuel drops to 0, [None] is returned, meaning that the final store could not be computed. -/ #check Option def cexec_bounded (fuel: Nat) (s: store) (c: com) : Option store := match fuel with | .zero => none | .succ fuel' => match c with | SKIP => some s | ASSIGN x a => some (update x (aeval s a) s) | SEQ c1 c2 => match cexec_bounded fuel' s c1 with | none => none | some s' => cexec_bounded fuel' s' c2 | IFTHENELSE b c1 c2 => if beval s b then cexec_bounded fuel' s c1 else cexec_bounded fuel' s c2 | WHILE b c1 => if beval s b then match cexec_bounded fuel' s c1 with | none => none | some s' => cexec_bounded fuel' s' (WHILE b c1) else some s /-* This bounded execution function is great for testing programs. For example, let's compute the quotient and the remainder of 14 by 3 using the Euclidean division program above. -/ #eval (let s := update "a" 14 (update "b" 3 (fun _ => 0)) match cexec_bounded 100 s Euclidean_division with | none => none | some s' => some (s' "q", s' "r") ) /-* *** Exercise (3 stars, optional) -/ /-* Relate the [cexec] relation with the [cexec_bounded] function by proving the following two lemmas. -/ lemma cexec_bounded_sound: forall fuel s c s', cexec_bounded fuel s c = some s' -> cexec s c s' := by induction fuel as [ | fuel ]; cbn; intros. - discriminate. - destruct c. /- FILL IN HERE -/ Abort. lemma cexec_bounded_complete: forall s c s', cexec s c s' -> exists fuel1, forall fuel, (fuel >= fuel1)%nat -> cexec_bounded fuel s c = Some s'. Proof. induction 1. /- FILL IN HERE -/ Abort. /-* * 6. Small-step semantics for IMP -/ /-* * 6.1 Reduction semantics -/ /-* In small-step style, the semantics is presented as a one-step reduction relation [ red (c, s) (c', s') ], meaning that the command [c], executed in initial state [s], performs one elementary step of computation. [s'] is the updated state after this step. [c'] is the residual command, capturing all the computations that remain to be done. -/ inductive red: com * store -> com * store -> Prop where | red_assign: forall x a s, red (ASSIGN x a, s) (SKIP, update x (aeval s a) s) | red_seq_done: forall c s, red (SEQ SKIP c, s) (c, s) | red_seq_step: forall c1 c s1 c2 s2, red (c1, s1) (c2, s2) -> red (SEQ c1 c, s1) (SEQ c2 c, s2) | red_ifthenelse: forall b c1 c2 s, red (IFTHENELSE b c1 c2, s) ((if beval s b then c1 else c2), s) | red_while_done: forall b c s, beval s b = false -> red (WHILE b c, s) (SKIP, s) | red_while_loop: forall b c s, beval s b = true -> red (WHILE b c, s) (SEQ c (WHILE b c), s). /-* *** Exercise (2 stars, recommended) -/ /-* Show that Imp programs cannot go wrong. Hint: first prove the following "progress" result for non-[SKIP] commands. -/ lemma red_progress: forall c s, c = SKIP \/ exists c', exists s', red (c, s) (c', s'). Proof. induction c; intros. /- FILL IN HERE -/ Abort. def goes_wrong (c: com) (s: store) : Prop := exists c', exists s', star red (c, s) (c', s') /\ irred red (c', s') /\ c' <> SKIP. lemma not_goes_wrong: forall c s, ~(goes_wrong c s). Proof. intros c s (c' & s' & STAR & IRRED & NOTSKIP). /- FILL IN HERE -/ Abort. /-* Sequences of reductions can go under a sequence context, generalizing rule [red_seq_step]. -/ lemma red_seq_steps: forall c2 s c s' c', star red (c, s) (c', s') -> star red ((c;;c2), s) ((c';;c2), s'). Proof. intros. dependent induction H. - apply star_refl. - destruct b as [c1 st1]. apply star_step with (c1;;c2, st1). apply red_seq_step. auto. auto. Qed. /-* We now recall the equivalence result between - termination according to the big-step semantics - existence of a finite sequence of reductions to [SKIP] according to the small-step semantics. We start with the implication big-step ==> small-step, which is a straightforward induction on the big-step evaluation derivation. -/ Theorem cexec_to_reds: forall s c s', cexec s c s' -> star red (c, s) (SKIP, s'). Proof. induction 1. - /- SKIP -/ apply star_refl. - /- ASSIGN -/ apply star_one. apply red_assign. - /- SEQ -/ eapply star_trans. apply red_seq_steps. apply IHcexec1. eapply star_step. apply red_seq_done. apply IHcexec2. - /- IFTHENELSE -/ eapply star_step. apply red_ifthenelse. auto. - /- WHILE stop -/ apply star_one. apply red_while_done. auto. - /- WHILE loop -/ eapply star_step. apply red_while_loop. auto. eapply star_trans. apply red_seq_steps. apply IHcexec1. eapply star_step. apply red_seq_done. apply IHcexec2. Qed. /-* The reverse implication, from small-step to big-step, is more subtle. The key lemma is the following, showing that one step of reduction followed by a big-step evaluation to a final state can be collapsed into a single big-step evaluation to that final state. -/ lemma red_append_cexec: forall c1 s1 c2 s2, red (c1, s1) (c2, s2) -> forall s', cexec s2 c2 s' -> cexec s1 c1 s'. Proof. intros until s2; intros STEP. dependent induction STEP; intros. - /- red_assign -/ inversion H; subst. apply cexec_assign. - /- red_seq_done -/ apply cexec_seq with s2. apply cexec_skip. auto. - /- red seq step -/ inversion H; subst. apply cexec_seq with s'0. eapply IHSTEP; eauto. auto. - /- red_ifthenelse -/ apply cexec_ifthenelse. auto. - /- red_while_done -/ inversion H0; subst. apply cexec_while_done. auto. - /- red while loop -/ inversion H0; subst. apply cexec_while_loop with s'0; auto. Qed. /-* As a consequence, a term that reduces to [SKIP] evaluates in big-step with the same final state. -/ Theorem reds_to_cexec: forall s c s', star red (c, s) (SKIP, s') -> cexec s c s'. Proof. intros. dependent induction H. - apply cexec_skip. - destruct b as [c1 s1]. apply red_append_cexec with c1 s1; auto. Qed. /-* ** 6.2 Transition semantics with continuations -/ /-* We now introduce an alternate form of small-step semantics where the command to be executed is explicitly decomposed into: - a sub-command under focus, where computation takes place; - a continuation (or context) describing the position of this sub-command in the whole command, or, equivalently, describing the parts of the whole command that remain to be reduced once the sub-command is done. As a consequence, the small-step semantics is presented as a transition relation between triples (subcommand-under-focus, continuation, state). Previously, we had transitions between pairs (whole-command, state). The syntax of continuations is as follows: -/ inductive cont : Type := | Kstop | Kseq (c: com) (k: cont) | Kwhile (b: bexp) (c: com) (k: cont). /-* Intuitive meaning of these constructors: - [Kstop] means that, after the sub-command under focus terminates, nothing remains to be done, and execution can stop. In other words, the sub-command under focus is the whole command. - [Kseq c k] means that, after the sub-command terminates, we still need to execute command [c] in sequence, then continue as described by [k]. - [Kwhile b c k] means that, after the sub-command terminates, we still need to execute a loop [WHILE b DO c END], then continue as described by [k]. -/ /-* Another way to forge intuitions about continuations is to ponder the following [apply_cont k c] function, which takes a sub-command [c] under focus and a continuation [k], and rebuilds the whole command. It simply puts [c] in lefmost position in a nest of sequences as described by [k]. -/ def apply_cont (k: cont) (c: com) : com := match k with | Kstop => c | Kseq c1 k1 => apply_cont k1 (SEQ c c1) | Kwhile b1 c1 k1 => apply_cont k1 (SEQ c (WHILE b1 c1)) /-* Transitions between (subcommand-under-focus, continuation, state) triples perform conceptually different kinds of actions: - Computation: evaluate an arithmetic expression or boolean expression and modify the triple according to the result of the evaluation. - Focusing: replace the sub-command by a sub-sub-command that is to be evaluated next, possibly enriching the continuation as a consequence. - Resumption: when the sub-command is [SKIP] and therefore fully executed, look at the head of the continuation to see what to do next. Here are the transition rules, classified by the kinds of actions they implement. -/ inductive step: com * cont * store -> com * cont * store -> Prop := | step_assign: forall x a k s, /-*r computation for assignments -/ step (ASSIGN x a, k, s) (SKIP, k, update x (aeval s a) s) | step_seq: forall c1 c2 s k, /-*r focusing for sequence -/ step (SEQ c1 c2, k, s) (c1, Kseq c2 k, s) | step_ifthenelse: forall b c1 c2 k s, /-*r computation for conditionals -/ step (IFTHENELSE b c1 c2, k, s) ((if beval s b then c1 else c2), k, s) | step_while_done: forall b c k s, /-*r computation for loops -/ beval s b = false -> step (WHILE b c, k, s) (SKIP, k, s) | step_while_true: forall b c k s, /-*r computation and focusSKIing for loops -/ beval s b = true -> step (WHILE b c, k, s) (c, Kwhile b c k, s) | step_skip_seq: forall c k s, /-*r resumption -/ step (SKIP, Kseq c k, s) (c, k, s) | step_skip_while: forall b c k s, /-*r resumption -/ step (SKIP, Kwhile b c k, s) (WHILE b c, k, s). /-* *** Extensions to other control structures -/ /-* A remarkable feature of continuation semantics is that they extend very easily to other control structures besides "if-then-else" and "while" loops. Consider for instance the "break" construct of C, C++ and Java, which immediately terminates the nearest enclosing "while" loop. Assume we extend the type of commands with a [BREAK] constructor. Then, all we need to give "break" a semantics is to add two resumption rules: << | step_break_seq: forall c k s, step (BREAK, Kseq c k, s) (BREAK, k, s) | step_break_while: forall b c k s, step (BREAK, Kwhile b c k, s) (SKIP, k, s) >> The first rule says that a [BREAK] statement "floats up" pending sequences, skipping over the computations they contain. Eventually, a [Kwhile] continuation is encountered, meaning that the [BREAK] found its enclosing loop. Then, the second rule discards the [Kwhile] continuation and turns the [BREAK] into a [SKIP], effectively terminating the loop. That's all there is to it! *-/ /-* *** Exercise (2 stars, recommended) -/ /-* Besides "break", C, C++ and Java also have a "continue" statement that terminates the current iteration of the enclosing loop, then resumes the loop at its next iteration (instead of stopping the loop like "break" does). Give the transition rules for the "continue" statement. -/ /-* *** Exercise (3 stars, optional) -/ /-* In Java, loops as well as "break" and "continue" statements carry an optional label. "break" without a label exits out of the immediately enclosing loop, but "break lbl" exits out of the first enclosing loop that carries the label "lbl". Similarly for "continue". Give the transition rules for "break lbl" and "continue lbl". -/ /-* *** Relating the continuation semantics and the big-step semantics -/ /-* *** Exercise (2 stars, optional) -/ /-* Show that a big-step execution give rise to a sequence of steps to [SKIP]. You can adapt the proof of theorem [cexec_to_reds] with minor changes. -/ Theorem cexec_to_steps: forall s c s', cexec s c s' -> forall k, star step (c, k, s) (SKIP, k, s'). Proof. induction 1; intros k. /- FILL IN HERE -/ Abort. /-* *** Exercise (3 stars, optional) -/ /-* Show the converse result: a sequence of steps to [(SKIP, Kstop)] corresponds to a big-step execution. You need a lemma similar to [red_append_cexec], but also a notion of big-step execution of a continuation. -/ Theorem steps_to_cexec: forall c s s', star step (c, Kstop, s) (SKIP, Kstop, s') -> cexec s c s'. Proof. /- FILL IN HERE -/ Abort.
d6b3d95b461283e9a219f6a8063e049c29f9d73b
94e33a31faa76775069b071adea97e86e218a8ee
/src/category_theory/functor/fully_faithful.lean
30b08d29c6ada9766582d6b5c898ecce40e25844
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
10,875
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.natural_isomorphism import logic.equiv.basic /-! # Full and faithful functors We define typeclasses `full` and `faithful`, decorating functors. Use `F.map_injective` to retrieve the fact that `F.map` is injective when `[faithful F]`, and `F.preimage` to obtain preimages of morphisms when `[full F]`. We prove some basic "cancellation" lemmas for full and/or faithful functors. See `category_theory.equivalence` for the fact that a functor is an equivalence if and only if it is fully faithful and essentially surjective. -/ -- declare the `v`'s first; see `category_theory.category` for an explanation universes v₁ vβ‚‚ v₃ u₁ uβ‚‚ u₃ namespace category_theory variables {C : Type u₁} [category.{v₁} C] {D : Type uβ‚‚} [category.{vβ‚‚} D] /-- A functor `F : C β₯€ D` is full if for each `X Y : C`, `F.map` is surjective. In fact, we use a constructive definition, so the `full F` typeclass contains data, specifying a particular preimage of each `f : F.obj X ⟢ F.obj Y`. See <https://stacks.math.columbia.edu/tag/001C>. -/ class full (F : C β₯€ D) := (preimage : βˆ€ {X Y : C} (f : (F.obj X) ⟢ (F.obj Y)), X ⟢ Y) (witness' : βˆ€ {X Y : C} (f : (F.obj X) ⟢ (F.obj Y)), F.map (preimage f) = f . obviously) restate_axiom full.witness' attribute [simp] full.witness /-- A functor `F : C β₯€ D` is faithful if for each `X Y : C`, `F.map` is injective. See <https://stacks.math.columbia.edu/tag/001C>. -/ class faithful (F : C β₯€ D) : Prop := (map_injective' [] : βˆ€ {X Y : C}, function.injective (@functor.map _ _ _ _ F X Y) . obviously) restate_axiom faithful.map_injective' namespace functor variables {X Y : C} lemma map_injective (F : C β₯€ D) [faithful F] : function.injective $ @functor.map _ _ _ _ F X Y := faithful.map_injective F lemma map_iso_injective (F : C β₯€ D) [faithful F] : function.injective $ @functor.map_iso _ _ _ _ F X Y := Ξ» i j h, iso.ext (map_injective F (congr_arg iso.hom h : _)) /-- The specified preimage of a morphism under a full functor. -/ def preimage (F : C β₯€ D) [full F] (f : F.obj X ⟢ F.obj Y) : X ⟢ Y := full.preimage.{v₁ vβ‚‚} f @[simp] lemma image_preimage (F : C β₯€ D) [full F] {X Y : C} (f : F.obj X ⟢ F.obj Y) : F.map (preimage F f) = f := by unfold preimage; obviously end functor section variables {F : C β₯€ D} [full F] [faithful F] {X Y Z : C} @[simp] lemma preimage_id : F.preimage (πŸ™ (F.obj X)) = πŸ™ X := F.map_injective (by simp) @[simp] lemma preimage_comp (f : F.obj X ⟢ F.obj Y) (g : F.obj Y ⟢ F.obj Z) : F.preimage (f ≫ g) = F.preimage f ≫ F.preimage g := F.map_injective (by simp) @[simp] lemma preimage_map (f : X ⟢ Y) : F.preimage (F.map f) = f := F.map_injective (by simp) variables (F) namespace functor /-- If `F : C β₯€ D` is fully faithful, every isomorphism `F.obj X β‰… F.obj Y` has a preimage. -/ @[simps] def preimage_iso (f : (F.obj X) β‰… (F.obj Y)) : X β‰… Y := { hom := F.preimage f.hom, inv := F.preimage f.inv, hom_inv_id' := F.map_injective (by simp), inv_hom_id' := F.map_injective (by simp), } @[simp] lemma preimage_iso_map_iso (f : X β‰… Y) : F.preimage_iso (F.map_iso f) = f := by { ext, simp, } end functor /-- If the image of a morphism under a fully faithful functor in an isomorphism, then the original morphisms is also an isomorphism. -/ lemma is_iso_of_fully_faithful (f : X ⟢ Y) [is_iso (F.map f)] : is_iso f := ⟨⟨F.preimage (inv (F.map f)), ⟨F.map_injective (by simp), F.map_injective (by simp)⟩⟩⟩ /-- If `F` is fully faithful, we have an equivalence of hom-sets `X ⟢ Y` and `F X ⟢ F Y`. -/ @[simps] def equiv_of_fully_faithful {X Y} : (X ⟢ Y) ≃ (F.obj X ⟢ F.obj Y) := { to_fun := Ξ» f, F.map f, inv_fun := Ξ» f, F.preimage f, left_inv := Ξ» f, by simp, right_inv := Ξ» f, by simp } /-- If `F` is fully faithful, we have an equivalence of iso-sets `X β‰… Y` and `F X β‰… F Y`. -/ @[simps] def iso_equiv_of_fully_faithful {X Y} : (X β‰… Y) ≃ (F.obj X β‰… F.obj Y) := { to_fun := Ξ» f, F.map_iso f, inv_fun := Ξ» f, F.preimage_iso f, left_inv := Ξ» f, by simp, right_inv := Ξ» f, by { ext, simp, } } end section variables {E : Type*} [category E] {F G : C β₯€ D} (H : D β₯€ E) [full H] [faithful H] /-- We can construct a natural transformation between functors by constructing a natural transformation between those functors composed with a fully faithful functor. -/ @[simps] def nat_trans_of_comp_fully_faithful (Ξ± : F β‹™ H ⟢ G β‹™ H) : F ⟢ G := { app := Ξ» X, (equiv_of_fully_faithful H).symm (Ξ±.app X), naturality' := Ξ» X Y f, by { dsimp, apply H.map_injective, simpa using Ξ±.naturality f, } } /-- We can construct a natural isomorphism between functors by constructing a natural isomorphism between those functors composed with a fully faithful functor. -/ @[simps] def nat_iso_of_comp_fully_faithful (i : F β‹™ H β‰… G β‹™ H) : F β‰… G := nat_iso.of_components (Ξ» X, (iso_equiv_of_fully_faithful H).symm (i.app X)) (Ξ» X Y f, by { dsimp, apply H.map_injective, simpa using i.hom.naturality f, }) lemma nat_iso_of_comp_fully_faithful_hom (i : F β‹™ H β‰… G β‹™ H) : (nat_iso_of_comp_fully_faithful H i).hom = nat_trans_of_comp_fully_faithful H i.hom := by { ext, simp [nat_iso_of_comp_fully_faithful], } lemma nat_iso_of_comp_fully_faithful_inv (i : F β‹™ H β‰… G β‹™ H) : (nat_iso_of_comp_fully_faithful H i).inv = nat_trans_of_comp_fully_faithful H i.inv := by { ext, simp [←preimage_comp], dsimp, simp, } end end category_theory namespace category_theory variables {C : Type u₁} [category.{v₁} C] instance full.id : full (𝟭 C) := { preimage := Ξ» _ _ f, f } instance faithful.id : faithful (𝟭 C) := by obviously variables {D : Type uβ‚‚} [category.{vβ‚‚} D] {E : Type u₃} [category.{v₃} E] variables (F F' : C β₯€ D) (G : D β₯€ E) instance faithful.comp [faithful F] [faithful G] : faithful (F β‹™ G) := { map_injective' := Ξ» _ _ _ _ p, F.map_injective (G.map_injective p) } lemma faithful.of_comp [faithful $ F β‹™ G] : faithful F := { map_injective' := Ξ» X Y, (F β‹™ G).map_injective.of_comp } section variables {F F'} /-- If `F` is full, and naturally isomorphic to some `F'`, then `F'` is also full. -/ def full.of_iso [full F] (Ξ± : F β‰… F') : full F' := { preimage := Ξ» X Y f, F.preimage ((Ξ±.app X).hom ≫ f ≫ (Ξ±.app Y).inv), witness' := Ξ» X Y f, by simp [←nat_iso.naturality_1 Ξ±], } lemma faithful.of_iso [faithful F] (Ξ± : F β‰… F') : faithful F' := { map_injective' := Ξ» X Y f f' h, F.map_injective (by rw [←nat_iso.naturality_1 Ξ±.symm, h, nat_iso.naturality_1 Ξ±.symm]) } end variables {F G} lemma faithful.of_comp_iso {H : C β₯€ E} [β„‹ : faithful H] (h : F β‹™ G β‰… H) : faithful F := @faithful.of_comp _ _ _ _ _ _ F G (faithful.of_iso h.symm) alias faithful.of_comp_iso ← _root_.category_theory.iso.faithful_of_comp -- We could prove this from `faithful.of_comp_iso` using `eq_to_iso`, -- but that would introduce a cyclic import. lemma faithful.of_comp_eq {H : C β₯€ E} [β„‹ : faithful H] (h : F β‹™ G = H) : faithful F := @faithful.of_comp _ _ _ _ _ _ F G (h.symm β–Έ β„‹) alias faithful.of_comp_eq ← _root_.eq.faithful_of_comp variables (F G) /-- β€œDivide” a functor by a faithful functor. -/ protected def faithful.div (F : C β₯€ E) (G : D β₯€ E) [faithful G] (obj : C β†’ D) (h_obj : βˆ€ X, G.obj (obj X) = F.obj X) (map : Ξ  {X Y}, (X ⟢ Y) β†’ (obj X ⟢ obj Y)) (h_map : βˆ€ {X Y} {f : X ⟢ Y}, G.map (map f) == F.map f) : C β₯€ D := { obj := obj, map := @map, map_id' := begin assume X, apply G.map_injective, apply eq_of_heq, transitivity F.map (πŸ™ X), from h_map, rw [F.map_id, G.map_id, h_obj X] end, map_comp' := begin assume X Y Z f g, apply G.map_injective, apply eq_of_heq, transitivity F.map (f ≫ g), from h_map, rw [F.map_comp, G.map_comp], congr' 1; try { exact (h_obj _).symm }; exact h_map.symm end } -- This follows immediately from `functor.hext` (`functor.hext h_obj @h_map`), -- but importing `category_theory.eq_to_hom` causes an import loop: -- category_theory.eq_to_hom β†’ category_theory.opposites β†’ -- category_theory.equivalence β†’ category_theory.fully_faithful lemma faithful.div_comp (F : C β₯€ E) [faithful F] (G : D β₯€ E) [faithful G] (obj : C β†’ D) (h_obj : βˆ€ X, G.obj (obj X) = F.obj X) (map : Ξ  {X Y}, (X ⟢ Y) β†’ (obj X ⟢ obj Y)) (h_map : βˆ€ {X Y} {f : X ⟢ Y}, G.map (map f) == F.map f) : (faithful.div F G obj @h_obj @map @h_map) β‹™ G = F := begin casesI F with F_obj _ _ _, casesI G with G_obj _ _ _, unfold faithful.div functor.comp, unfold_projs at h_obj, have: F_obj = G_obj ∘ obj := (funext h_obj).symm, substI this, congr, funext, exact eq_of_heq h_map end lemma faithful.div_faithful (F : C β₯€ E) [faithful F] (G : D β₯€ E) [faithful G] (obj : C β†’ D) (h_obj : βˆ€ X, G.obj (obj X) = F.obj X) (map : Ξ  {X Y}, (X ⟢ Y) β†’ (obj X ⟢ obj Y)) (h_map : βˆ€ {X Y} {f : X ⟢ Y}, G.map (map f) == F.map f) : faithful (faithful.div F G obj @h_obj @map @h_map) := (faithful.div_comp F G _ h_obj _ @h_map).faithful_of_comp instance full.comp [full F] [full G] : full (F β‹™ G) := { preimage := Ξ» _ _ f, F.preimage (G.preimage f) } /-- If `F β‹™ G` is full and `G` is faithful, then `F` is full. -/ def full.of_comp_faithful [full $ F β‹™ G] [faithful G] : full F := { preimage := Ξ» X Y f, (F β‹™ G).preimage (G.map f), witness' := Ξ» X Y f, G.map_injective ((F β‹™ G).image_preimage _) } /-- If `F β‹™ G` is full and `G` is faithful, then `F` is full. -/ def full.of_comp_faithful_iso {F : C β₯€ D} {G : D β₯€ E} {H : C β₯€ E} [full H] [faithful G] (h : F β‹™ G β‰… H) : full F := @full.of_comp_faithful _ _ _ _ _ _ F G (full.of_iso h.symm) _ /-- Given a natural isomorphism between `F β‹™ H` and `G β‹™ H` for a fully faithful functor `H`, we can 'cancel' it to give a natural iso between `F` and `G`. -/ def fully_faithful_cancel_right {F G : C β₯€ D} (H : D β₯€ E) [full H] [faithful H] (comp_iso: F β‹™ H β‰… G β‹™ H) : F β‰… G := nat_iso.of_components (Ξ» X, H.preimage_iso (comp_iso.app X)) (Ξ» X Y f, H.map_injective (by simpa using comp_iso.hom.naturality f)) @[simp] lemma fully_faithful_cancel_right_hom_app {F G : C β₯€ D} {H : D β₯€ E} [full H] [faithful H] (comp_iso: F β‹™ H β‰… G β‹™ H) (X : C) : (fully_faithful_cancel_right H comp_iso).hom.app X = H.preimage (comp_iso.hom.app X) := rfl @[simp] lemma fully_faithful_cancel_right_inv_app {F G : C β₯€ D} {H : D β₯€ E} [full H] [faithful H] (comp_iso: F β‹™ H β‰… G β‹™ H) (X : C) : (fully_faithful_cancel_right H comp_iso).inv.app X = H.preimage (comp_iso.inv.app X) := rfl end category_theory
1b3a4f700467aa1e2980e06a82789358d48d1527
19cc34575500ee2e3d4586c15544632aa07a8e66
/src/data/polynomial/basic.lean
dc8ceeb3a9f549c4b6bf15639941296ead35df9b
[ "Apache-2.0" ]
permissive
LibertasSpZ/mathlib
b9fcd46625eb940611adb5e719a4b554138dade6
33f7870a49d7cc06d2f3036e22543e6ec5046e68
refs/heads/master
1,672,066,539,347
1,602,429,158,000
1,602,429,158,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,939
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes HΓΆlzl, Scott Morrison, Jens Wagemaker -/ import tactic.ring_exp import tactic.chain import algebra.monoid_algebra import data.finset.sort /-! # Theory of univariate polynomials Polynomials are represented as `add_monoid_algebra R β„•`, where `R` is a commutative semiring. In this file, we define `polynomial`, provide basic instances, and prove an `ext` lemma. -/ noncomputable theory /-- `polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ def polynomial (R : Type*) [semiring R] := add_monoid_algebra R β„• open finsupp add_monoid_algebra open_locale big_operators namespace polynomial universes u variables {R : Type u} {a : R} {m n : β„•} section semiring variables [semiring R] {p q : polynomial R} instance : inhabited (polynomial R) := finsupp.inhabited instance : semiring (polynomial R) := add_monoid_algebra.semiring instance : has_scalar R (polynomial R) := add_monoid_algebra.has_scalar instance : semimodule R (polynomial R) := add_monoid_algebra.semimodule instance subsingleton [subsingleton R] : subsingleton (polynomial R) := ⟨λ _ _, ext (Ξ» _, subsingleton.elim _ _)⟩ @[simp] lemma support_zero : (0 : polynomial R).support = βˆ… := rfl /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : β„•) (a : R) : polynomial R := finsupp.single n a @[simp] lemma monomial_zero_right (n : β„•) : monomial n (0 : R) = 0 := by simp [monomial] lemma monomial_add (n : β„•) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := by simp [monomial] lemma monomial_mul_monomial (n m : β„•) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := by simp only [monomial, single_mul_single] /-- `X` is the polynomial variable (aka indeterminant). -/ def X : polynomial R := monomial 1 1 /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ lemma X_mul : X * p = p * X := by { ext, simp [X, monomial, add_monoid_algebra.mul_apply, sum_single_index, add_comm] } lemma X_pow_mul {n : β„•} : X^n * p = p * X^n := begin induction n with n ih, { simp, }, { conv_lhs { rw pow_succ', }, rw [mul_assoc, X_mul, ←mul_assoc, ih, mul_assoc, ←pow_succ'], } end lemma X_pow_mul_assoc {n : β„•} : (p * X^n) * q = (p * q) * X^n := by rw [mul_assoc, X_pow_mul, ←mul_assoc] lemma commute_X (p : polynomial R) : commute X p := X_mul /-- coeff p n is the coefficient of X^n in p -/ def coeff (p : polynomial R) := p.to_fun @[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial R) = f := rfl lemma coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by { dsimp [monomial, single, finsupp.single], congr, } /-- This lemma is needed for occasions when we break through the abstraction from `polynomial` to `finsupp`; ideally it wouldn't be necessary at all. -/ lemma coeff_single : coeff (single n a) m = if n = m then a else 0 := coeff_monomial @[simp] lemma coeff_zero (n : β„•) : coeff (0 : polynomial R) n = 0 := rfl @[simp] lemma coeff_one_zero : coeff (1 : polynomial R) 0 = 1 := coeff_monomial @[simp] lemma coeff_X_one : coeff (X : polynomial R) 1 = 1 := coeff_monomial @[simp] lemma coeff_X_zero : coeff (X : polynomial R) 0 = 0 := coeff_monomial lemma coeff_X : coeff (X : polynomial R) n = if 1 = n then 1 else 0 := coeff_monomial theorem ext_iff {p q : polynomial R} : p = q ↔ βˆ€ n, coeff p n = coeff q n := ⟨λ h n, h β–Έ rfl, finsupp.ext⟩ @[ext] lemma ext {p q : polynomial R} : (βˆ€ n, coeff p n = coeff q n) β†’ p = q := (@ext_iff _ _ p q).2 -- this has the same content as the subsingleton lemma eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : polynomial R) : p = 0 := by rw [←one_smul R p, ←h, zero_smul] lemma support_monomial (n) (a : R) (H : a β‰  0) : (monomial n a).support = singleton n := begin ext, have m3 : a_1 ∈ (monomial n a).support ↔ coeff (monomial n a) a_1 β‰  0 := (monomial n a).mem_support_to_fun a_1, rw [finset.mem_singleton, m3, coeff_monomial], split_ifs, { rwa [h, eq_self_iff_true, iff_true], }, { rw [← @not_not (a_1=n)], apply not_congr, rw [eq_self_iff_true, true_iff, ← ne.def], symmetry, assumption, }, end lemma support_monomial' (n) (a : R) : (monomial n a).support βŠ† singleton n := begin by_cases h : a = 0, { rw [h, monomial_zero_right, support_zero], exact finset.empty_subset {n}, }, { rw support_monomial n a h, exact finset.subset.refl {n}, }, end lemma monomial_eq_X_pow (n) : X^n = monomial n (1:R) := begin induction n with n hn, { refl, }, { conv_rhs {rw nat.succ_eq_add_one, congr, skip, rw ← mul_one (1:R)}, rw [← monomial_mul_monomial, ← hn, pow_succ, X_mul, X], }, end lemma support_X_pow (H : Β¬ (1:R) = 0) (n : β„•) : (X^n : polynomial R).support = singleton n := begin convert support_monomial n 1 H, exact monomial_eq_X_pow n, end lemma support_X_empty (H : (1:R)=0) : (X : polynomial R).support = βˆ… := begin rw [X, H, monomial_zero_right, support_zero], end lemma support_X (H : Β¬ (1 : R) = 0) : (X : polynomial R).support = singleton 1 := begin rw [← pow_one X, support_X_pow H 1], end end semiring section comm_semiring variables [comm_semiring R] instance : comm_semiring (polynomial R) := add_monoid_algebra.comm_semiring instance : comm_monoid (polynomial R) := comm_semiring.to_comm_monoid (polynomial R) end comm_semiring section ring variables [ring R] instance : ring (polynomial R) := add_monoid_algebra.ring @[simp] lemma coeff_neg (p : polynomial R) (n : β„•) : coeff (-p) n = -coeff p n := rfl @[simp] lemma coeff_sub (p q : polynomial R) (n : β„•) : coeff (p - q) n = coeff p n - coeff q n := rfl end ring instance [comm_ring R] : comm_ring (polynomial R) := add_monoid_algebra.comm_ring section nonzero_semiring variables [semiring R] [nontrivial R] instance : nontrivial (polynomial R) := begin refine nontrivial_of_ne 0 1 _, intro h, have := coeff_zero 0, revert this, rw h, simp, end lemma X_ne_zero : (X : polynomial R) β‰  0 := mt (congr_arg (Ξ» p, coeff p 1)) (by simp) end nonzero_semiring section repr variables [semiring R] local attribute [instance, priority 100] classical.prop_decidable instance [has_repr R] : has_repr (polynomial R) := ⟨λ p, if p = 0 then "0" else (p.support.sort (≀)).foldr (Ξ» n a, a ++ (if a = "" then "" else " + ") ++ if n = 0 then "C (" ++ repr (coeff p n) ++ ")" else if n = 1 then if (coeff p n) = 1 then "X" else "C (" ++ repr (coeff p n) ++ ") * X" else if (coeff p n) = 1 then "X ^ " ++ repr n else "C (" ++ repr (coeff p n) ++ ") * X ^ " ++ repr n) ""⟩ end repr end polynomial
29156d5404d328c7efb7588df71f82d2161c2028
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/dsimp_whnf_post.lean
8c944e6d88cee4ad38dfc0a3d0f21466f46f1445
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
157
lean
structure Foo := (foo : unit) def my_foo : Foo := Foo.mk () @[simp] lemma my_foo.def : my_foo = Foo.mk () := rfl example : Foo.foo my_foo = () := by dsimp
08b72124fcbcda291a33f0f2ba9cfe9359ab6465
618003631150032a5676f229d13a079ac875ff77
/src/category_theory/monad/adjunction.lean
5ad5cc193509e631d7222960d1b6b948909afc25
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
5,781
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.monad.algebra import category_theory.adjunction.fully_faithful namespace category_theory open category universes v₁ vβ‚‚ u₁ uβ‚‚ -- declare the `v`'s first; see `category_theory.category` for an explanation variables {C : Type u₁} [category.{v₁} C] {D : Type uβ‚‚} [category.{vβ‚‚} D] variables (R : D β₯€ C) namespace adjunction instance monad (R : D β₯€ C) [is_right_adjoint R] : monad.{v₁} ((left_adjoint R) β‹™ R) := let L := left_adjoint R in let h : L ⊣ R := is_right_adjoint.adj in { Ξ· := h.unit, ΞΌ := whisker_right (whisker_left L h.counit) R, assoc' := Ξ» X, by { dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp], refl }, right_unit' := Ξ» X, by { dsimp, rw [←R.map_comp], simp }, } @[simp] lemma monad_Ξ·_app [is_right_adjoint R] (X) : (Ξ·_ ((left_adjoint R) β‹™ R)).app X = is_right_adjoint.adj.unit.app X := rfl @[simp] lemma monad_ΞΌ_app [is_right_adjoint R] (X) : (ΞΌ_ ((left_adjoint R) β‹™ R)).app X = R.map (is_right_adjoint.adj.counit.app ((left_adjoint R).obj X)) := rfl end adjunction namespace monad -- We can't use `@[simps]` here because it can't cope with `let` statements. def comparison [is_right_adjoint R] : D β₯€ algebra ((left_adjoint R) β‹™ R) := let h : _ ⊣ R := is_right_adjoint.adj in { obj := Ξ» X, { A := R.obj X, a := R.map (h.counit.app X), assoc' := by { dsimp, conv { to_rhs, erw [←R.map_comp, h.counit.naturality, R.map_comp], }, refl } }, map := Ξ» X Y f, { f := R.map f, h' := begin dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp, functor.id_map], refl, end } }. @[simp] lemma comparison_map_f [is_right_adjoint R] {X Y} (f : X ⟢ Y) : ((comparison R).map f).f = R.map f := rfl @[simp] lemma comparison_obj_a [is_right_adjoint R] (X) : ((comparison R).obj X).a = R.map (is_right_adjoint.adj.counit.app X) := rfl def comparison_forget [is_right_adjoint R] : comparison R β‹™ forget ((left_adjoint R) β‹™ R) β‰… R := { hom := { app := Ξ» X, πŸ™ _, }, inv := { app := Ξ» X, πŸ™ _, } } end monad section prio set_option default_priority 100 -- see Note [default priority] /-- A functor is *reflective*, or *a reflective inclusion*, if it is fully faithful and right adjoint. -/ class reflective (R : D β₯€ C) extends is_right_adjoint R, full R, faithful R. /-- A right adjoint functor `R : D β₯€ C` is *monadic* if the comparison function `monad.comparison R` from `D` to the category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/ class monadic_right_adjoint (R : D β₯€ C) extends is_right_adjoint R := (eqv : is_equivalence (monad.comparison R)) end prio instance ΞΌ_iso_of_reflective [reflective R] : is_iso (ΞΌ_ ((left_adjoint R) β‹™ R)) := by { dsimp [adjunction.monad], apply_instance } attribute [instance] monadic_right_adjoint.eqv -- PROJECT prove Beck's monadicity theorem, e.g. from Section 5.5 of [Riehl][riehl2017] namespace reflective lemma comparison_ess_surj_aux [reflective R] (X : monad.algebra ((left_adjoint R) β‹™ R)) : ((is_right_adjoint.adj).unit).app (R.obj ((left_adjoint R).obj (X.A))) = R.map ((left_adjoint R).map ((is_right_adjoint.adj).unit.app X.A)) := begin -- both are left inverses to ΞΌ_X. apply (cancel_mono ((ΞΌ_ ((left_adjoint R) β‹™ R)).app _)).1, { dsimp, erw [adjunction.right_triangle_components, ←R.map_comp], simp, }, { apply is_iso.mono_of_iso _, apply nat_iso.is_iso_app_of_is_iso } end instance [reflective R] (X : monad.algebra ((left_adjoint R) β‹™ R)) : is_iso ((is_right_adjoint.adj : _ ⊣ R).unit.app X.A) := let L := left_adjoint R in let h : L ⊣ R := (is_right_adjoint.adj) in { inv := X.a, hom_inv_id' := X.unit, inv_hom_id' := begin dsimp, erw [h.unit.naturality, comparison_ess_surj_aux, ←R.map_comp, ←L.map_comp, X.unit, L.map_id, R.map_id], refl end } instance comparison_ess_surj [reflective R]: ess_surj (monad.comparison R) := let L := left_adjoint R in let h : L ⊣ R := is_right_adjoint.adj in { obj_preimage := Ξ» X, L.obj X.A, iso' := Ξ» X, { hom := { f := (as_iso (h.unit.app X.A)).inv, h' := begin dsimp, apply (cancel_epi (R.map (L.map ((h.unit).app (X.A))))).1, rw [is_iso.hom_inv_id_assoc, ←category.assoc, ←R.map_comp,adjunction.left_triangle_components], erw [functor.map_id, category.id_comp], apply (cancel_epi ((h.unit).app (X.A))).1, rw is_iso.hom_inv_id, exact X.unit, end }, inv := { f := (as_iso (h.unit.app X.A)).hom, h' := begin dsimp, erw [←R.map_comp, adjunction.left_triangle_components, R.map_id], apply (cancel_epi ((h.unit).app (X.A))).1, conv { to_rhs, erw [←category.assoc, X.unit] }, erw [comp_id, id_comp], end }, hom_inv_id' := by { ext, exact (as_iso (h.unit.app X.A)).inv_hom_id, }, inv_hom_id' := by { ext, exact (as_iso (h.unit.app X.A)).hom_inv_id, }, } } instance comparison_full [full R] [is_right_adjoint R] : full (monad.comparison R) := { preimage := Ξ» X Y f, R.preimage f.f } instance comparison_faithful [faithful R] [is_right_adjoint R] : faithful (monad.comparison R) := { injectivity' := Ξ» X Y f g w, by { have w' := (congr_arg monad.algebra.hom.f w), exact R.injectivity w' } } end reflective /-- Any reflective inclusion has a monadic right adjoint. cf Prop 5.3.3 of [Riehl][riehl2017] -/ @[priority 100] -- see Note [lower instance priority] instance monadic_of_reflective [reflective R] : monadic_right_adjoint R := { eqv := equivalence.equivalence_of_fully_faithfully_ess_surj _ } end category_theory
cfd3f0a865d932f38c62092187a7648f7201aa12
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/int/parity.lean
589922fd863accb7d2bf8a951a6971991ad0b1e8
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
3,809
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Benjamin Davidson The `even` and `odd` predicates on the integers. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.int.modeq import Mathlib.data.nat.parity import Mathlib.PostPort namespace Mathlib namespace int @[simp] theorem mod_two_ne_one {n : β„€} : Β¬n % bit0 1 = 1 ↔ n % bit0 1 = 0 := sorry theorem mod_two_ne_zero {n : β„€} : Β¬n % bit0 1 = 0 ↔ n % bit0 1 = 1 := sorry @[simp] theorem even_coe_nat (n : β„•) : even ↑n ↔ even n := sorry theorem even_iff {n : β„€} : even n ↔ n % bit0 1 = 0 := sorry theorem odd_iff {n : β„€} : odd n ↔ n % bit0 1 = 1 := sorry theorem not_even_iff {n : β„€} : Β¬even n ↔ n % bit0 1 = 1 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬even n ↔ n % bit0 1 = 1)) (propext even_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (Β¬n % bit0 1 = 0 ↔ n % bit0 1 = 1)) (propext mod_two_ne_zero))) (iff.refl (n % bit0 1 = 1))) theorem not_odd_iff {n : β„€} : Β¬odd n ↔ n % bit0 1 = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬odd n ↔ n % bit0 1 = 0)) (propext odd_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (Β¬n % bit0 1 = 1 ↔ n % bit0 1 = 0)) (propext mod_two_ne_one))) (iff.refl (n % bit0 1 = 0))) theorem even_iff_not_odd {n : β„€} : even n ↔ Β¬odd n := eq.mpr (id (Eq._oldrec (Eq.refl (even n ↔ Β¬odd n)) (propext not_odd_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (even n ↔ n % bit0 1 = 0)) (propext even_iff))) (iff.refl (n % bit0 1 = 0))) @[simp] theorem odd_iff_not_even {n : β„€} : odd n ↔ Β¬even n := eq.mpr (id (Eq._oldrec (Eq.refl (odd n ↔ Β¬even n)) (propext not_even_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (odd n ↔ n % bit0 1 = 1)) (propext odd_iff))) (iff.refl (n % bit0 1 = 1))) theorem even_or_odd (n : β„€) : even n ∨ odd n := or.imp_right (iff.mpr odd_iff_not_even) (em (even n)) theorem even_or_odd' (n : β„€) : βˆƒ (k : β„€), n = bit0 1 * k ∨ n = bit0 1 * k + 1 := sorry theorem even_xor_odd (n : β„€) : xor (even n) (odd n) := or.dcases_on (even_or_odd n) (fun (h : even n) => Or.inl { left := h, right := iff.mp even_iff_not_odd h }) fun (h : odd n) => Or.inr { left := h, right := iff.mp odd_iff_not_even h } theorem even_xor_odd' (n : β„€) : βˆƒ (k : β„€), xor (n = bit0 1 * k) (n = bit0 1 * k + 1) := sorry theorem ne_of_odd_sum {x : β„€} {y : β„€} (h : odd (x + y)) : x β‰  y := sorry @[simp] theorem two_dvd_ne_zero {n : β„€} : Β¬bit0 1 ∣ n ↔ n % bit0 1 = 1 := not_even_iff protected instance even.decidable_pred : decidable_pred even := fun (n : β„€) => decidable_of_decidable_of_iff (int.decidable_eq (n % bit0 1) 0) sorry protected instance decidable_pred_odd : decidable_pred odd := fun (n : β„€) => decidable_of_decidable_of_iff not.decidable sorry @[simp] theorem even_zero : even 0 := Exists.intro 0 (of_as_true trivial) @[simp] theorem not_even_one : Β¬even 1 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬even 1)) (propext even_iff))) one_ne_zero @[simp] theorem even_bit0 (n : β„€) : even (bit0 n) := Exists.intro n (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 n = bit0 1 * n)) (bit0.equations._eqn_1 n))) (eq.mpr (id (Eq._oldrec (Eq.refl (n + n = bit0 1 * n)) (two_mul n))) (Eq.refl (n + n)))) theorem even_add {m : β„€} {n : β„€} : even (m + n) ↔ (even m ↔ even n) := sorry theorem even_neg {n : β„€} : even (-n) ↔ even n := sorry @[simp] theorem not_even_bit1 (n : β„€) : Β¬even (bit1 n) := sorry theorem even_sub {m : β„€} {n : β„€} : even (m - n) ↔ (even m ↔ even n) := sorry theorem even_mul {m : β„€} {n : β„€} : even (m * n) ↔ even m ∨ even n := sorry theorem even_pow {m : β„€} {n : β„•} : even (m ^ n) ↔ even m ∧ n β‰  0 := sorry
42589e1fc28d7a41dc4251135a1254de378733ec
7490bf5d40d31857a58062614642bb5a41c36154
/final_exam.lean
311d0f703a129b605ac652f933a51a58f3a43852
[]
no_license
reesegrayallen/Lean-Discrete-Mathematics
9f1d6fe1c814cc9264ce868a67adcf5a82566e22
00c875284613ea12e0a729f519738aab8599456b
refs/heads/main
1,674,181,372,629
1,606,801,004,000
1,606,801,004,000
317,387,970
0
0
null
null
null
null
UTF-8
Lean
false
false
15,205
lean
/- | REESE ALLEN (rga2uz) | CS2102 S20 Sullivan | Final Exam -/ /- 1. You know from our study of the Boolean satisfiability problem that there are 2^n possible combinations of Boolean values for n Boolean variables. Let's make the property of natural numbers that is at issue clear by defining "P n" to be proposition that "the number of possible combinations of values for *n* Boolean variables is *2^n*." What your are to prove is the proposition that this is true for any value of n. That is, you are to prove βˆ€ n, P n. Mext, recall that a proof of a universal generalization (such as βˆ€ n, P n) *by induction* is based on the application of the *induction principle* for for the given data type. Here the data type is β„•, and the induction rule for β„• is as follows: βˆ€ {P : Prop}, P 0 β†’ (βˆ€ n', P n' β†’ P (n' + 1)) β†’ βˆ€ n, P n. Reading backwards, this says that if you want to prove βˆ€ n, P n, it will *suffice* to prove P 0 and βˆ€ n', P n' β†’ P (n' + 1)). The reason is that you can then apply the rule to deduce that βˆ€ n, P n must be true. In other words, you can reduce the task of proving βˆ€ n, P n to the tasks of proving the two antecedents of this conclusion in the induction rule. -/ /- *ANSWER* Theorem: For any natural number, n, the number of combinations of values for n Boolean variables is 2^n. Proof: By induction. To prove βˆ€ n, P n, where P is defined to be the proposition, "the number of possible combinations of values for n Boolean variables is 2^n," it will suffice to prove P 0 and βˆ€ n', P n' β†’ (n' + 1) Here is a more complete quasi-formal version of the proof with algebra: Our aim is to prove the predicate [P(n)], which says that for any β„• n, the number of possible combinations of values, i.e. interpretations, for n Boolean variables is 2^n. We do so inductively and must first prove / show two things: [1] The proposition P is true for n = 0, our base case. [2] If we assume the number of combinations for n' Boolean variables is 2^n' for some arbitrary but specific β„• n', our induction hypothesis, then the number of combinations of (n' + 1) Boolean variables is 2^(n' + 1). By the principle of induction, through assuming P(n') is true and using it to prove that P(n' + 1) is true, we can conclude that P(n) is true for all β„•s n. [1] This is easy. Our base case says that for zero Boolean variables, there is one combination. We treat P(0) = 1 almost like an axiom. We have defined the number of combinations of values for 0 Boolean variables to be 1. This is certainly true. [2] We can prove this second step algebraically. I'm going to use k here to represent n' because it is a bit cleaner to read. Assuming P(k) = 2^k is true, we want to show P(k + 1) = 2^(k + 1) is true. 2^(k + 1) is equivalent to (2^k) + (2^1) by our rules of exponents, which is equivalent to (2^k) * 2; it follows that P(k + 1) = P(k) * 2. Because P(k) is true for any k, it must be that P(n) is true for any n. -/ /- 2 -/ def aProp := βˆ€ (Ξ± : Type), βˆ€ (Heavy Charmed: Ξ± β†’ Prop), (βˆƒ (a : Ξ±), Heavy a ∧ Charmed a) β†’ (βˆƒ (a : Ξ±), Charmed a) /- 2a. English language rendition of this proposition: The proposition aProp says suppose that you have ojects of some type Ξ± and that Heavy and Charmed are properties of type Ξ±. If there exists an object a of type Ξ± that is both Heavy and Charmed, then there exists some object that is only Charmed. -/ /- 2b. Give a formal proof of it. -/ example : aProp := Ξ» Ξ± : Type, Ξ» H C : Ξ± β†’ Prop, Ξ» hac : βˆƒ (a : Ξ±), H a ∧ C a, match hac with | exists.intro obj pf := let Cobj := pf.right in exists.intro obj Cobj end /- 2c. Quasi-formal, English-language proof: To prove the proposition aProp, we suppose that objects of type Ξ± exist and that Heavy and Charmed are predicates that take an object of type Ξ± as an argument and return a proposition, which could be true or false. We will just say that heavy and charmed are properties of these objects. Denoting an object of type Ξ± as a and the predicates Heavy and Charmed as H and C, respectively, when we say that there is a proof of heavy and charmed, for example, what we mean is that there is a proof that the conjunction of H(a) and C(a) is true. In this context, we want to prove an implication by showing that if there is an object that is both heavy and charmed, then there is an object that is charmed. Given a proof that objects of type Ξ± exist that are both heavy and charmed, which we call hac, we can deduce that there is an object that has the properties of heavy and charmed. We assume this by reasoning through case analysis and with existential instantiation, i.e. the exists introduction rule. We call our single arbitrary but specific object of type Ξ± obj. The only case in which our proof hac could have been constructed is by applying the exists introduction rule to obj and a proof that heavy and charmed is true, i.e. that obj has the properties of heavy and charmed, which we call pf. The proof pf is constructed through conjunction introduction, another rule of inference. We can destructure pf with the right elimination rule; given a proof of heavy and charmed, we can derive a proof of just charmed, which we call Cobj. We can then use instantiation again by applying the exists introduction rule to our object obj and our proof of charmed Cobj. By showing that a proof that an object of type Ξ± can be constructed from a proof that objects of type Ξ± exist with the properties of heavy and charmed, we have proved aProp. -/ /- 3 -/ def aProp2 := βˆ€ (Ξ± : Type), βˆ€ (Heavy Charmed: Ξ± β†’ Prop), (βˆƒ (a : Ξ±), Heavy a ∨ Charmed a) β†’ (βˆƒ (a : Ξ±), Heavy a) ∨ (βˆƒ (a : Ξ±), Charmed a) /- 3a. English language rendition of this proposition: The proposition aProp2 says suppose that you have objects of some type Ξ± and that Heavy and Charmed are properties of type Ξ±. If there exists an object a of type Ξ± that is Heavy or Charmed, then there exists an object that is just Heavy or there exists an object that is just Charmed. -/ /- 3b. Give a formal proof of it. -/ example : aProp2 := Ξ» Ξ± : Type, Ξ» H C : Ξ± β†’ Prop, Ξ» hoc : βˆƒ (a : Ξ±), H a ∨ C a, match hoc with | exists.intro obj pf := match pf with | or.inl h := or.inl (exists.intro obj h) | or.inr c := or.inr (exists.intro obj c) end end /- 3c. Quasi-formal, English-language proof: To prove the proposition aProp2, we suppose that objects of type Ξ± exist and that Heavy and Charmed are predicates that take an object of type Ξ± as an argument and return a proposition, which could be true or false. We will just say that heavy and charmed are properties of these objects. When we say that there is a proof of heavy or charmed, for example, what we mean is that there is a proof that the disjunction of the predicates Heavy and Charmed, when each is given an object of type Ξ±, is true. This is analogous to saying that the object has the property of heavy, the property of charmed, or both. In this context, we want to prove an implication by showing that if there is an object that is heavy or charmed, then there is an object that is heavy or there is an object that is charmed. Given a proof that objects of type Ξ± exist that are heavy or charmed, which we call hoc, we can deduce that there is an object that has the properties of heavy or charmed. We assume this by reasoning through case analysis and with existential instantiation, i.e. the exists introduction rule. We call our single arbitrary but specific object of type Ξ± obj. The only case in which our proof hoc could have been constructed is by applying the exists introduction rule of inference to obj and a proof that obj is heavy or charmed, which we call pf. The proof pf is constructed through disjunction introduction. Using case analysis again, we can destructure pf to show the two ways in which it could have been formed. A proof of a disjunction is constructed either from a proof of the left disjunct or a proof of the right disjunct. We assume that our object obj has the property of heavy in the first case, the proof of which we denote as h, and that obj has the property of charmed in the second case, which we denote as c. To prove the first case, we use the left elimination rule applied to a proof that there exists an object that is heavy, which is given through instantiation by applying the exists introduction rule to our object obj and our proof h. Similarly, to prove the second case, we use the right elimination rule applied to a proof that there exists an object that is charmed, which is given through instantiation by applying the exists introduction rule to our object obj and our proof c. By showing that a proof that an object of type Ξ± has the property of heavy and a proof that an object of type Ξ± has the property of charmed can be constructed from a proof that objects of type Ξ± exists that are heavy or charmed, we have proved aProp2. -/ /- 4. Formally specify the syntax and semantics of a language of *arithmetic* expressions that can include variables, where the meaning of an expression is (reduces to) a natural number. Hint: model your answer on our specification of the syntax and semantics of *propositional logic* expressions. -/ /- In this language, an interpretation will map variables to natural numbers rather than to Boolean values. We'll give you a start on a solution by defining (1) a type of variables that are distinguished from one another by a β„•-valued index, (2) specifying the type of an interpretation, and (3) giving an example of an interpretation in which all variables have the value zero. -/ -- our variable type structure a_var : Type := mk :: (index : β„•) -- friendly names for a few variables def X_var := a_var.mk 0 def Y_var := a_var.mk 1 def Z_var := a_var.mk 2 -- the type of an interpretation def interp := a_var β†’ β„• -- one possible interpretation, "all zero" def all_zero_interp : interp := Ξ» v, 0 /- 4a. Define an interpretation in which X has value 3, Y has value 7, and Z has value 1, and all other variables have value 0. -/ def an_interp : interp := Ξ» v, match v with | a_var.mk 0 := 3 | a_var.mk 1:= 7 | a_var.mk 2 := 1 | _ := 0 end /- 4b. Define the syntax of your language to have the following kinds of expressions. - β„• literal expression - β„• variable expression - expression + expression - expression * expression Do this by defining an inductive type, aexp, the values of which are arithmetic expressions in our language. Call your constructors lit, var, add, and mul. When you succeed, the test expressions we give you should type check. -/ inductive aexp : Type | lit : β„• β†’ aexp | var : a_var β†’ aexp | add : aexp β†’ aexp β†’ aexp | mul : aexp β†’ aexp β†’ aexp open aexp -- These expressions should type-check def X := aexp.var X_var def Y := aexp.var Y_var def Z := aexp.var Z_var def l6 := aexp.lit 6 def e1 := aexp.add X Y def e2 := aexp.mul X Z def e3 := aexp.mul e1 l6 /- 4c. Define a semantics for your language so that expressions evaluate to natural numbers as they would using the standard notions of addition and multiplication. Furthermore, literal expressions should evaluate to their natural numbers arguments, and variable expressions should evaluate the natural numbers according to an interpretation given to the evaluation function (call it aEval). Remember to put constructor expressions in parentheses when using pattern matching / destructuring. When you've succeeded, the test cases we've provided should all pass. -/ -- Your answer here def aEval : aexp β†’ interp β†’ β„• | (lit n) _ := n | (var av) i := i av | (add ae1 ae2) i := (aEval ae1 i) + (aEval ae2 i) | (mul ae1 ae2) i := (aEval ae1 i) * (aEval ae2 i ) -- Test cases that should pass when you've succeeded example : aEval X an_interp = 3 := rfl example : aEval Y an_interp = 7 := rfl example : aEval Z an_interp = 1 := rfl example : aEval l6 all_zero_interp = 6 := rfl example : aEval e1 all_zero_interp = 0 := rfl example : aEval e2 an_interp = 3 := rfl example : aEval e3 an_interp = 60 := rfl /- 5. Explain concisely but also precisely how a proof of a proposition, P, "by contradiction" would be carried out. Be sure to point out exactly where negation elimination is involved. Then explain concisely and precisely how a proof of a proposition, Β¬ P, would be carried out. To carry out a proof of a proposition P by contradiction, we assume Β¬P and show that this leads to a contradiction. Negation elimination essentially allows us to delete double-negatives and is given by the law of the excluded middle, which we treat as an axiom in Lean. Specifically, classical.em : βˆ€ (P : Prop), P ∨ Β¬ P. It allows us to assume that for any proposition, either that proposition is true or its negation is true In order to carry out a proof of a proposition Β¬ P, we use proof by negation. We start by assuming that there is a proof that the proposition is true and show that this enables us to construct a proof of false. A proof of false does not exist, so if assuming P allows us to construct one, then the assumption that P is true must be wrong, i.e. Β¬ P is true. Β¬ P is equivalent to P β†’ false. To prove Β¬P, we just show that if P is true then false is true. An example would be to use case analysis to prove the implication P β†’ false. Assuming P, we match the proof of P with a constructor, which is an empty match statement (there are no cases). This shows that P implies false, so we have proved that Β¬ P, the negation of P, must be true. -/ /- 6. A simplish proof. Give a formal proof of the following proposition. Then explain briefly in English why the proposition must be true no matter what propositions P and Q are. -/ example : βˆ€ (P Q R : Prop), Β¬ ((P ∧ Β¬ Q) ∧ (Q ∧ Β¬ R)) := Ξ» P Q R, Ξ» h, match h with | and.intro panq qanr := let nq := panq.right in let q := qanr.left in nq q end /- Our goal is to prove that for any propositions P, Q, and R, it is not the case that the conjunction of P and not Q, the left conjunct, and Q and not R, the right conjunct, is true. This is to show that (P ∧ Β¬ Q) ∧ (Q ∧ Β¬ R) implies false. We start by assuming that we have propositions P, Q, and R and a proof, which we call h, that (P ∧ Β¬ Q) ∧ (Q ∧ Β¬ R) is true. We reason by case analysis and show that to construct h, the and introduction rule is applied to the left and right conjuncts. Using the left and right elimination rules applied to the left and right conjuncts of h respectively, we arrive at a proof, or a construction, of Β¬ Q ∧ Q, which is false. By showing that (P ∧ Β¬ Q) ∧ (Q ∧ Β¬ R) leads to a contradiction, we have proved that h implies false, i.e. Β¬ ((P ∧ Β¬ Q) ∧ (Q ∧ Β¬ R)) is true. -/
7fa9a123a71fa01b19292c1490ced1aebd8534ae
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/equiv/list.lean
3326dacf7ffc241ea57bc096d8c1e12922dfe7b9
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
12,893
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.equiv.denumerable import data.finset.sort /-! # Equivalences involving `list`-like types This file defines some additional constructive equivalences using `encodable` and the pairing function on `β„•`. -/ open nat list namespace encodable variables {Ξ± : Type*} section list variable [encodable Ξ±] /-- Explicit encoding function for `list Ξ±` -/ def encode_list : list Ξ± β†’ β„• | [] := 0 | (a::l) := succ (mkpair (encode a) (encode_list l)) /-- Explicit decoding function for `list Ξ±` -/ def decode_list : β„• β†’ option (list Ξ±) | 0 := some [] | (succ v) := match unpair v, unpair_right_le v with | (v₁, vβ‚‚), h := have vβ‚‚ < succ v, from lt_succ_of_le h, (::) <$> decode Ξ± v₁ <*> decode_list vβ‚‚ end /-- If `Ξ±` is encodable, then so is `list Ξ±`. This uses the `mkpair` and `unpair` functions from `data.nat.pairing`. -/ instance list : encodable (list Ξ±) := ⟨encode_list, decode_list, Ξ» l, by induction l with a l IH; simp [encode_list, decode_list, unpair_mkpair, encodek, *]⟩ @[simp] theorem encode_list_nil : encode (@nil Ξ±) = 0 := rfl @[simp] theorem encode_list_cons (a : Ξ±) (l : list Ξ±) : encode (a :: l) = succ (mkpair (encode a) (encode l)) := rfl @[simp] theorem decode_list_zero : decode (list Ξ±) 0 = some [] := show decode_list 0 = some [], by rw decode_list @[simp] theorem decode_list_succ (v : β„•) : decode (list Ξ±) (succ v) = (::) <$> decode Ξ± v.unpair.1 <*> decode (list Ξ±) v.unpair.2 := show decode_list (succ v) = _, begin cases e : unpair v with v₁ vβ‚‚, simp [decode_list, e], refl end theorem length_le_encode : βˆ€ (l : list Ξ±), length l ≀ encode l | [] := _root_.zero_le _ | (a :: l) := succ_le_succ $ (length_le_encode l).trans (right_le_mkpair _ _) end list section finset variables [encodable Ξ±] private def enle : Ξ± β†’ Ξ± β†’ Prop := encode ⁻¹'o (≀) private lemma enle.is_linear_order : is_linear_order Ξ± enle := (rel_embedding.preimage ⟨encode, encode_injective⟩ (≀)).is_linear_order private def decidable_enle (a b : Ξ±) : decidable (enle a b) := by unfold enle order.preimage; apply_instance local attribute [instance] enle.is_linear_order decidable_enle /-- Explicit encoding function for `multiset Ξ±` -/ def encode_multiset (s : multiset Ξ±) : β„• := encode (s.sort enle) /-- Explicit decoding function for `multiset Ξ±` -/ def decode_multiset (n : β„•) : option (multiset Ξ±) := coe <$> decode (list Ξ±) n /-- If `Ξ±` is encodable, then so is `multiset Ξ±`. -/ instance multiset : encodable (multiset Ξ±) := ⟨encode_multiset, decode_multiset, Ξ» s, by simp [encode_multiset, decode_multiset, encodek]⟩ end finset /-- A listable type with decidable equality is encodable. -/ def encodable_of_list [decidable_eq Ξ±] (l : list Ξ±) (H : βˆ€ x, x ∈ l) : encodable Ξ± := ⟨λ a, index_of a l, l.nth, Ξ» a, index_of_nth (H _)⟩ def trunc_encodable_of_fintype (Ξ± : Type*) [decidable_eq Ξ±] [fintype Ξ±] : trunc (encodable Ξ±) := @@quot.rec_on_subsingleton _ (Ξ» s : multiset Ξ±, (βˆ€ x:Ξ±, x ∈ s) β†’ trunc (encodable Ξ±)) _ finset.univ.1 (Ξ» l H, trunc.mk $ encodable_of_list l H) finset.mem_univ /-- A noncomputable way to arbitrarily choose an ordering on a finite type. It is not made into a global instance, since it involves an arbitrary choice. This can be locally made into an instance with `local attribute [instance] fintype.encodable`. -/ noncomputable def fintype.encodable (Ξ± : Type*) [fintype Ξ±] : encodable Ξ± := by { classical, exact (encodable.trunc_encodable_of_fintype Ξ±).out } /-- If `Ξ±` is encodable, then so is `vector Ξ± n`. -/ instance vector [encodable Ξ±] {n} : encodable (vector Ξ± n) := encodable.subtype /-- If `Ξ±` is encodable, then so is `fin n β†’ Ξ±`. -/ instance fin_arrow [encodable Ξ±] {n} : encodable (fin n β†’ Ξ±) := of_equiv _ (equiv.vector_equiv_fin _ _).symm instance fin_pi (n) (Ο€ : fin n β†’ Type*) [βˆ€ i, encodable (Ο€ i)] : encodable (Ξ  i, Ο€ i) := of_equiv _ (equiv.pi_equiv_subtype_sigma (fin n) Ο€) /-- If `Ξ±` is encodable, then so is `array n Ξ±`. -/ instance array [encodable Ξ±] {n} : encodable (array n Ξ±) := of_equiv _ (equiv.array_equiv_fin _ _) /-- If `Ξ±` is encodable, then so is `finset Ξ±`. -/ instance finset [encodable Ξ±] : encodable (finset Ξ±) := by haveI := decidable_eq_of_encodable Ξ±; exact of_equiv {s : multiset Ξ± // s.nodup} ⟨λ ⟨a, b⟩, ⟨a, b⟩, Ξ» ⟨a, b⟩, ⟨a, b⟩, Ξ» ⟨a, b⟩, rfl, Ξ» ⟨a, b⟩, rfl⟩ def fintype_arrow (Ξ± : Type*) (Ξ² : Type*) [decidable_eq Ξ±] [fintype Ξ±] [encodable Ξ²] : trunc (encodable (Ξ± β†’ Ξ²)) := (fintype.trunc_equiv_fin Ξ±).map $ Ξ» f, encodable.of_equiv (fin (fintype.card Ξ±) β†’ Ξ²) $ equiv.arrow_congr f (equiv.refl _) def fintype_pi (Ξ± : Type*) (Ο€ : Ξ± β†’ Type*) [decidable_eq Ξ±] [fintype Ξ±] [βˆ€ a, encodable (Ο€ a)] : trunc (encodable (Ξ  a, Ο€ a)) := (encodable.trunc_encodable_of_fintype Ξ±).bind $ Ξ» a, (@fintype_arrow Ξ± (Ξ£a, Ο€ a) _ _ (@encodable.sigma _ _ a _)).bind $ Ξ» f, trunc.mk $ @encodable.of_equiv _ _ (@encodable.subtype _ _ f _) (equiv.pi_equiv_subtype_sigma Ξ± Ο€) /-- The elements of a `fintype` as a sorted list. -/ def sorted_univ (Ξ±) [fintype Ξ±] [encodable Ξ±] : list Ξ± := finset.univ.sort (encodable.encode' Ξ± ⁻¹'o (≀)) theorem mem_sorted_univ {Ξ±} [fintype Ξ±] [encodable Ξ±] (x : Ξ±) : x ∈ sorted_univ Ξ± := (finset.mem_sort _).2 (finset.mem_univ _) theorem length_sorted_univ {Ξ±} [fintype Ξ±] [encodable Ξ±] : (sorted_univ Ξ±).length = fintype.card Ξ± := finset.length_sort _ theorem sorted_univ_nodup {Ξ±} [fintype Ξ±] [encodable Ξ±] : (sorted_univ Ξ±).nodup := finset.sort_nodup _ _ /-- An encodable `fintype` is equivalent to the same size `fin`. -/ def fintype_equiv_fin {Ξ±} [fintype Ξ±] [encodable Ξ±] : Ξ± ≃ fin (fintype.card Ξ±) := begin haveI : decidable_eq Ξ± := encodable.decidable_eq_of_encodable _, transitivity, { exact fintype.equiv_fin_of_forall_mem_list mem_sorted_univ (@sorted_univ_nodup Ξ± _ _) }, exact equiv.cast (congr_arg _ (@length_sorted_univ Ξ± _ _)) end /-- If `Ξ±` and `Ξ²` are encodable and `Ξ±` is a fintype, then `Ξ± β†’ Ξ²` is encodable as well. -/ instance fintype_arrow_of_encodable {Ξ± Ξ² : Type*} [encodable Ξ±] [fintype Ξ±] [encodable Ξ²] : encodable (Ξ± β†’ Ξ²) := of_equiv (fin (fintype.card Ξ±) β†’ Ξ²) $ equiv.arrow_congr fintype_equiv_fin (equiv.refl _) end encodable namespace denumerable variables {Ξ± : Type*} {Ξ² : Type*} [denumerable Ξ±] [denumerable Ξ²] open encodable section list theorem denumerable_list_aux : βˆ€ n : β„•, βˆƒ a ∈ @decode_list Ξ± _ n, encode_list a = n | 0 := by rw decode_list; exact ⟨_, rfl, rfl⟩ | (succ v) := begin cases e : unpair v with v₁ vβ‚‚, have h := unpair_right_le v, rw e at h, rcases have vβ‚‚ < succ v, from lt_succ_of_le h, denumerable_list_aux vβ‚‚ with ⟨a, h₁, hβ‚‚βŸ©, rw option.mem_def at h₁, use of_nat Ξ± v₁ :: a, simp [decode_list, e, hβ‚‚, h₁, encode_list, mkpair_unpair' e], end /-- If `Ξ±` is denumerable, then so is `list Ξ±`. -/ instance denumerable_list : denumerable (list Ξ±) := ⟨denumerable_list_aux⟩ @[simp] theorem list_of_nat_zero : of_nat (list Ξ±) 0 = [] := by rw [← @encode_list_nil Ξ±, of_nat_encode] @[simp] theorem list_of_nat_succ (v : β„•) : of_nat (list Ξ±) (succ v) = of_nat Ξ± v.unpair.1 :: of_nat (list Ξ±) v.unpair.2 := of_nat_of_decode $ show decode_list (succ v) = _, begin cases e : unpair v with v₁ vβ‚‚, simp [decode_list, e], rw [show decode_list vβ‚‚ = decode (list Ξ±) vβ‚‚, from rfl, decode_eq_of_nat]; refl end end list section multiset /-- Outputs the list of differences of the input list, that is `lower [a₁, aβ‚‚, ...] n = [a₁ - n, aβ‚‚ - a₁, ...]` -/ def lower : list β„• β†’ β„• β†’ list β„• | [] n := [] | (m :: l) n := (m - n) :: lower l m /-- Outputs the list of partial sums of the input list, that is `raise [a₁, aβ‚‚, ...] n = [n + a₁, n + a₁ + aβ‚‚, ...]` -/ def raise : list β„• β†’ β„• β†’ list β„• | [] n := [] | (m :: l) n := (m + n) :: raise l (m + n) lemma lower_raise : βˆ€ l n, lower (raise l n) n = l | [] n := rfl | (m :: l) n := by rw [raise, lower, nat.add_sub_cancel, lower_raise] lemma raise_lower : βˆ€ {l n}, list.sorted (≀) (n :: l) β†’ raise (lower l n) n = l | [] n h := rfl | (m :: l) n h := have n ≀ m, from list.rel_of_sorted_cons h _ (l.mem_cons_self _), by simp [raise, lower, nat.sub_add_cancel this, raise_lower (list.sorted_of_sorted_cons h)] lemma raise_chain : βˆ€ l n, list.chain (≀) n (raise l n) | [] n := list.chain.nil | (m :: l) n := list.chain.cons (nat.le_add_left _ _) (raise_chain _ _) /-- `raise l n` is an non-decreasing sequence. -/ lemma raise_sorted : βˆ€ l n, list.sorted (≀) (raise l n) | [] n := list.sorted_nil | (m :: l) n := (list.chain_iff_pairwise (@le_trans _ _)).1 (raise_chain _ _) /-- If `Ξ±` is denumerable, then so is `multiset Ξ±`. Warning: this is *not* the same encoding as used in `encodable.multiset`. -/ instance multiset : denumerable (multiset Ξ±) := mk' ⟨ Ξ» s : multiset Ξ±, encode $ lower ((s.map encode).sort (≀)) 0, Ξ» n, multiset.map (of_nat Ξ±) (raise (of_nat (list β„•) n) 0), Ξ» s, by have := raise_lower (list.sorted_cons.2 ⟨λ n _, zero_le n, (s.map encode).sort_sorted _⟩); simp [-multiset.coe_map, this], Ξ» n, by simp [-multiset.coe_map, list.merge_sort_eq_self _ (raise_sorted _ _), lower_raise]⟩ end multiset section finset /-- Outputs the list of differences minus one of the input list, that is `lower' [a₁, aβ‚‚, a₃, ...] n = [a₁ - n, aβ‚‚ - a₁ - 1, a₃ - aβ‚‚ - 1, ...]`. -/ def lower' : list β„• β†’ β„• β†’ list β„• | [] n := [] | (m :: l) n := (m - n) :: lower' l (m + 1) /-- Outputs the list of partial sums plus one of the input list, that is `raise [a₁, aβ‚‚, a₃, ...] n = [n + a₁, n + a₁ + aβ‚‚ + 1, n + a₁ + aβ‚‚ + a₃ + 2, ...]`. Adding one each time ensures the elements are distinct. -/ def raise' : list β„• β†’ β„• β†’ list β„• | [] n := [] | (m :: l) n := (m + n) :: raise' l (m + n + 1) lemma lower_raise' : βˆ€ l n, lower' (raise' l n) n = l | [] n := rfl | (m :: l) n := by simp [raise', lower', nat.add_sub_cancel, lower_raise'] lemma raise_lower' : βˆ€ {l n}, (βˆ€ m ∈ l, n ≀ m) β†’ list.sorted (<) l β†’ raise' (lower' l n) n = l | [] n h₁ hβ‚‚ := rfl | (m :: l) n h₁ hβ‚‚ := have n ≀ m, from h₁ _ (l.mem_cons_self _), by simp [raise', lower', nat.sub_add_cancel this, raise_lower' (list.rel_of_sorted_cons hβ‚‚ : βˆ€ a ∈ l, m < a) (list.sorted_of_sorted_cons hβ‚‚)] lemma raise'_chain : βˆ€ l {m n}, m < n β†’ list.chain (<) m (raise' l n) | [] m n h := list.chain.nil | (a :: l) m n h := list.chain.cons (lt_of_lt_of_le h (nat.le_add_left _ _)) (raise'_chain _ (lt_succ_self _)) /-- `raise' l n` is a strictly increasing sequence. -/ lemma raise'_sorted : βˆ€ l n, list.sorted (<) (raise' l n) | [] n := list.sorted_nil | (m :: l) n := (list.chain_iff_pairwise (@lt_trans _ _)).1 (raise'_chain _ (lt_succ_self _)) /-- Makes `raise' l n` into a finset. Elements are distinct thanks to `raise'_sorted`. -/ def raise'_finset (l : list β„•) (n : β„•) : finset β„• := ⟨raise' l n, (raise'_sorted _ _).imp (@ne_of_lt _ _)⟩ /-- If `Ξ±` is denumerable, then so is `finset Ξ±`. Warning: this is *not* the same encoding as used in `encodable.finset`. -/ instance finset : denumerable (finset Ξ±) := mk' ⟨ Ξ» s : finset Ξ±, encode $ lower' ((s.map (eqv Ξ±).to_embedding).sort (≀)) 0, Ξ» n, finset.map (eqv Ξ±).symm.to_embedding (raise'_finset (of_nat (list β„•) n) 0), Ξ» s, finset.eq_of_veq $ by simp [-multiset.coe_map, raise'_finset, raise_lower' (Ξ» n _, zero_le n) (finset.sort_sorted_lt _)], Ξ» n, by simp [-multiset.coe_map, finset.map, raise'_finset, finset.sort, list.merge_sort_eq_self (≀) ((raise'_sorted _ _).imp (@le_of_lt _ _)), lower_raise']⟩ end finset end denumerable namespace equiv /-- The type lists on unit is canonically equivalent to the natural numbers. -/ def list_unit_equiv : list unit ≃ β„• := { to_fun := list.length, inv_fun := list.repeat (), left_inv := Ξ» u, list.length_injective (by simp), right_inv := Ξ» n, list.length_repeat () n } /-- `list β„•` is equivalent to `β„•`. -/ def list_nat_equiv_nat : list β„• ≃ β„• := denumerable.eqv _ /-- If `Ξ±` is equivalent to `β„•`, then `list Ξ±` is equivalent to `Ξ±`. -/ def list_equiv_self_of_equiv_nat {Ξ± : Type} (e : Ξ± ≃ β„•) : list Ξ± ≃ Ξ± := calc list Ξ± ≃ list β„• : list_equiv_of_equiv e ... ≃ β„• : list_nat_equiv_nat ... ≃ Ξ± : e.symm end equiv
8d1a767029182218bdbf0ccc2eca84e4eea9c406
40ad357bbd0d327dd1e3e7f7beb868bd4e5b0a9d
/src/temporal_logic/persistent.lean
49c7ff3b707907880f5f1831ef59c28ecc92fc50
[]
no_license
unitb/temporal-logic
9966424f015976d5997a9ffa30cbd77cc3a9cb1c
accec04d1b09ca841be065511c9e206b725b16e9
refs/heads/master
1,633,868,382,769
1,541,072,223,000
1,541,072,223,000
114,790,987
5
3
null
null
null
null
UTF-8
Lean
false
false
5,774
lean
import temporal_logic.basic import tactic.squeeze universe variables u uβ‚€ u₁ uβ‚‚ variables {Ξ± : Sort uβ‚€} {Ξ² : Sort u₁} {Ξ³ : Sort uβ‚‚} namespace temporal open predicate class postponable (p : cpred) : Prop := (postpone : β—‡p = p) export postponable (postpone) instance henceforth_persistent {p : cpred} : persistent (β—»p) := by { constructor, simp only [temporal.henceforth_henceforth, eq_self_iff_true] with tl_simp } instance persistent_not {p : cpred} [postponable p] : persistent (-p) := by { constructor, rw [← not_eventually, postpone p] } instance leads_to_persistent {p q : cpred} : persistent (p ~> q) := by { constructor, simp only [tl_leads_to, is_persistent, eq_self_iff_true] } instance and_persistent {p q : cpred} [persistent p] [persistent q] : persistent (p β‹€ q) := by { constructor, simp only [henceforth_and, is_persistent, eq_self_iff_true], } instance coe_persistent (p : Prop) : persistent (p : cpred) := by { constructor, cases classical.prop_complete p ; subst p ; simp only [eq_self_iff_true, temporal.hence_false, predicate.coe_false,predicate.coe_true, eq_self_iff_true, temporal.hence_true] with tl_simp, } instance false_persistent : persistent (False : cpred) := by { constructor, simp only [eq_self_iff_true, temporal.hence_false] with tl_simp, } instance forall_persistent {p : Ξ± β†’ cpred} [βˆ€ i, persistent (p i)] : persistent (p_forall p) := by { constructor, simp only [henceforth_forall, is_persistent, eq_self_iff_true], } instance exists_persistent {p : Ξ± β†’ cpred} [βˆ€ i, persistent (p i)] : persistent (p_exists p) := by { constructor, apply mutual_entails, apply henceforth_str, apply p_exists_elim, intro, rw ← is_persistent (p x), mono, apply p_exists_intro, } instance (p : cpred) : postponable (β—‡p) := by { constructor, simp only [eventually_eventually, temporal.eventually_eventually, eq_self_iff_true] } instance postponable_not {p : cpred} [persistent p] : postponable (-p) := by { constructor, rw [← not_henceforth, is_persistent p] } instance or_postponable {p q : cpred} [postponable p] [postponable q] : postponable (p ⋁ q) := by { constructor, simp only [eventually_or, postpone, eq_self_iff_true], } instance imp_postponable {p q : cpred} [persistent p] [postponable q] : postponable (p ⟢ q) := by { simp only [p_imp_iff_p_not_p_or], apply_instance } instance coe_postponable (p : Prop) : postponable (p : cpred) := by { constructor, cases classical.prop_complete p ; subst p ; simp only [temporal.event_false, eq_self_iff_true, predicate.coe_false, predicate.coe_true, temporal.eventually_true, eq_self_iff_true] with tl_simp, } instance forall_postponable (p : Ξ± β†’ cpred) [βˆ€ i, postponable (p i)] : postponable (p_forall p) := ⟨ begin apply mutual_entails, { rw [p_entails_of_fun], introv h, rw p_forall_to_fun, intro i, rw ← postpone (p i), revert h, apply p_impl_revert, revert Ξ“, change (_ ⟹ _), mono, rw [p_entails_of_fun], introv h, apply p_forall_revert h }, apply eventually_weaken end ⟩ instance exists_postponable (p : Ξ± β†’ cpred) [βˆ€ i, postponable (p i)] : postponable (p_exists p) := by constructor ; simp only [eventually_exists, postpone, eq_self_iff_true] instance liftedβ‚€_postponable (c : Prop) : postponable (liftedβ‚€ c) := by { constructor, ext, simp only [liftedβ‚€, eventually, iff_self, predicate.liftedβ‚€, exists_const] } instance liftedβ‚€_persistent (c : Prop) : persistent (liftedβ‚€ c) := by { constructor, ext, simp only [liftedβ‚€, henceforth, forall_const, iff_self, predicate.liftedβ‚€] } instance True_postponable : postponable True := by { dunfold True, apply_instance } instance True_persistent : persistent True := by { dunfold True, apply_instance } instance False_postponable : postponable False := by { dunfold False, apply_instance } instance False_persistent : persistent False := by { dunfold False, apply_instance } -- instance not_forall_persistent {p : Ξ± β†’ cpred} [βˆ€ i, persistent (- p i)] -- : persistent (- p_forall p) := -- by { constructor, squeeze_simp [p_not_p_forall], apply is_persistent } inductive list_persistent : list cpred β†’ Prop | nil_persistent : list_persistent [] | cons_persistent (x : cpred) (xs : list $ cpred) [persistent x] (h : list_persistent xs) : list_persistent (x :: xs) export list_persistent (nil_persistent) def with_h_asms (Ξ“ : cpred) : Ξ  (xs : list (cpred)) (x : cpred), Prop | [] x := Ξ“ ⊒ x | (x :: xs) y := Ξ“ ⊒ x β†’ with_h_asms xs y lemma indirect_judgement (h p : pred' Ξ²) (H : βˆ€ Ξ“, Ξ“ ⊒ h β†’ Ξ“ ⊒ p) : h ⊒ p := by { apply H, lifted_pred keep, assumption } lemma judgement_trans (p q r : pred' Ξ²) (hβ‚€ : p ⊒ q) (h₁ : q ⊒ r) : p ⊒ r := by { lifted_pred keep, apply h₁.apply, apply hβ‚€.apply _ a } @[trans] lemma judgement_trans' {p q r : pred' Ξ²} (hβ‚€ : p ⊒ q) (h₁ : q ⊒ r) : p ⊒ r := judgement_trans _ _ _ hβ‚€ h₁ lemma p_imp_postpone (Ξ“ p q : cpred) [persistent Ξ“] [postponable q] (h : ctx_impl Ξ“ p q) : ctx_impl Ξ“ (β—‡p) q := begin rw ← postpone q, mono, end lemma persistent_to_henceforth {p q : cpred} [persistent p] (h : p ⊒ q) : p ⊒ β—» q := by { rw ← is_persistent p, lifted_pred keep, intro i, apply h.apply _ (a i), } lemma henceforth_deduction {Ξ“ p q : cpred} (h : Ξ“ ⊒ β—»(p ⟢ q)) : Ξ“ ⊒ p β†’ Ξ“ ⊒ q := henceforth_str (p ⟢ q) Ξ“ h instance has_coe_to_fun_henceforth (Ξ“ p q : cpred) : has_coe_to_fun (Ξ“ ⊒ β—»(p ⟢ q)) := { F := Ξ» _, Ξ“ ⊒ p β†’ Ξ“ ⊒ q , coe := henceforth_deduction } instance has_coe_to_fun_leads_to (Ξ“ p q : cpred) : has_coe_to_fun (Ξ“ ⊒ p ~> q) := temporal.has_coe_to_fun_henceforth _ _ _ end temporal
00f1de42b4b6083038aa23c70b24d487db06d45a
1446f520c1db37e157b631385707cc28a17a595e
/stage0/src/Init/Lean/ToExpr.lean
77c9fcc662aff82c95bc280db1b92bddcc680998
[ "Apache-2.0" ]
permissive
bdbabiak/lean4
cab06b8a2606d99a168dd279efdd404edb4e825a
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
refs/heads/master
1,615,045,275,530
1,583,793,696,000
1,583,793,696,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
770
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Expr universe u namespace Lean class ToExpr (Ξ± : Type u) := (toExpr : Ξ± β†’ Expr) export ToExpr (toExpr) instance exprToExpr : ToExpr Expr := ⟨id⟩ instance natToExpr : ToExpr Nat := ⟨mkNatLit⟩ instance strToExpr : ToExpr String := ⟨mkStrLit⟩ def nameToExprAux : Name β†’ Expr | Name.anonymous => mkConst `Lean.Name.anonymous | Name.str p s _ => mkAppB (mkConst `Lean.mkNameStr) (nameToExprAux p) (toExpr s) | Name.num p n _ => mkAppB (mkConst `Lean.mkNameNum) (nameToExprAux p) (toExpr n) instance nameToExpr : ToExpr Name := ⟨nameToExprAux⟩ end Lean
371cbc0ad49d59de09d3c0f237e40f1d720106c1
63abd62053d479eae5abf4951554e1064a4c45b4
/src/group_theory/free_group.lean
92d61998c9ffaa5de86a6543410b3fc21560f9d1
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
32,275
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau Free groups as a quotient over the reduction relation `a * x * x⁻¹ * b = a * b`. First we introduce the one step reduction relation `free_group.red.step`: w * x * x⁻¹ * v ~> w * v its reflexive transitive closure: `free_group.red.trans` and proof that its join is an equivalence relation. Then we introduce `free_group Ξ±` as a quotient over `free_group.red.step`. -/ import data.fintype.basic import group_theory.subgroup open relation universes u v w variables {Ξ± : Type u} local attribute [simp] list.append_eq_has_append namespace free_group variables {L L₁ Lβ‚‚ L₃ Lβ‚„ : list (Ξ± Γ— bool)} /-- Reduction step: `w * x * x⁻¹ * v ~> w * v` -/ inductive red.step : list (Ξ± Γ— bool) β†’ list (Ξ± Γ— bool) β†’ Prop | bnot {L₁ Lβ‚‚ x b} : red.step (L₁ ++ (x, b) :: (x, bnot b) :: Lβ‚‚) (L₁ ++ Lβ‚‚) attribute [simp] red.step.bnot /-- Reflexive-transitive closure of red.step -/ def red : list (Ξ± Γ— bool) β†’ list (Ξ± Γ— bool) β†’ Prop := refl_trans_gen red.step @[refl] lemma red.refl : red L L := refl_trans_gen.refl @[trans] lemma red.trans : red L₁ Lβ‚‚ β†’ red Lβ‚‚ L₃ β†’ red L₁ L₃ := refl_trans_gen.trans namespace red /-- Predicate asserting that word `w₁` can be reduced to `wβ‚‚` in one step, i.e. there are words `w₃ wβ‚„` and letter `x` such that `w₁ = w₃xx⁻¹wβ‚„` and `wβ‚‚ = w₃wβ‚„` -/ theorem step.length : βˆ€ {L₁ Lβ‚‚ : list (Ξ± Γ— bool)}, step L₁ Lβ‚‚ β†’ Lβ‚‚.length + 2 = L₁.length | _ _ (@red.step.bnot _ L1 L2 x b) := by rw [list.length_append, list.length_append]; refl @[simp] lemma step.bnot_rev {x b} : step (L₁ ++ (x, bnot b) :: (x, b) :: Lβ‚‚) (L₁ ++ Lβ‚‚) := by cases b; from step.bnot @[simp] lemma step.cons_bnot {x b} : red.step ((x, b) :: (x, bnot b) :: L) L := @step.bnot _ [] _ _ _ @[simp] lemma step.cons_bnot_rev {x b} : red.step ((x, bnot b) :: (x, b) :: L) L := @red.step.bnot_rev _ [] _ _ _ theorem step.append_left : βˆ€ {L₁ Lβ‚‚ L₃ : list (Ξ± Γ— bool)}, step Lβ‚‚ L₃ β†’ step (L₁ ++ Lβ‚‚) (L₁ ++ L₃) | _ _ _ red.step.bnot := by rw [← list.append_assoc, ← list.append_assoc]; constructor theorem step.cons {x} (H : red.step L₁ Lβ‚‚) : red.step (x :: L₁) (x :: Lβ‚‚) := @step.append_left _ [x] _ _ H theorem step.append_right : βˆ€ {L₁ Lβ‚‚ L₃ : list (Ξ± Γ— bool)}, step L₁ Lβ‚‚ β†’ step (L₁ ++ L₃) (Lβ‚‚ ++ L₃) | _ _ _ red.step.bnot := by simp lemma not_step_nil : Β¬ step [] L := begin generalize h' : [] = L', assume h, cases h with L₁ Lβ‚‚, simp [list.nil_eq_append_iff] at h', contradiction end lemma step.cons_left_iff {a : Ξ±} {b : bool} : step ((a, b) :: L₁) Lβ‚‚ ↔ (βˆƒL, step L₁ L ∧ Lβ‚‚ = (a, b) :: L) ∨ (L₁ = (a, bnot b)::Lβ‚‚) := begin split, { generalize hL : ((a, b) :: L₁ : list _) = L, assume h, rcases h with ⟨_ | ⟨p, s'⟩, e, a', b'⟩, { simp at hL, simp [*] }, { simp at hL, rcases hL with ⟨rfl, rfl⟩, refine or.inl ⟨s' ++ e, step.bnot, _⟩, simp } }, { assume h, rcases h with ⟨L, h, rfl⟩ | rfl, { exact step.cons h }, { exact step.cons_bnot } } end lemma not_step_singleton : βˆ€ {p : Ξ± Γ— bool}, Β¬ step [p] L | (a, b) := by simp [step.cons_left_iff, not_step_nil] lemma step.cons_cons_iff : βˆ€{p : Ξ± Γ— bool}, step (p :: L₁) (p :: Lβ‚‚) ↔ step L₁ Lβ‚‚ := by simp [step.cons_left_iff, iff_def, or_imp_distrib] {contextual := tt} lemma step.append_left_iff : βˆ€L, step (L ++ L₁) (L ++ Lβ‚‚) ↔ step L₁ Lβ‚‚ | [] := by simp | (p :: l) := by simp [step.append_left_iff l, step.cons_cons_iff] private theorem step.diamond_aux : βˆ€ {L₁ Lβ‚‚ L₃ Lβ‚„ : list (Ξ± Γ— bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, bnot b1) :: Lβ‚‚ = L₃ ++ (x2, b2) :: (x2, bnot b2) :: Lβ‚„ β†’ L₁ ++ Lβ‚‚ = L₃ ++ Lβ‚„ ∨ βˆƒ Lβ‚…, red.step (L₁ ++ Lβ‚‚) Lβ‚… ∧ red.step (L₃ ++ Lβ‚„) Lβ‚… | [] _ [] _ _ _ _ _ H := by injections; subst_vars; simp | [] _ [(x3,b3)] _ _ _ _ _ H := by injections; subst_vars; simp | [(x3,b3)] _ [] _ _ _ _ _ H := by injections; subst_vars; simp | [] _ ((x3,b3)::(x4,b4)::tl) _ _ _ _ _ H := by injections; subst_vars; simp; right; exact ⟨_, red.step.bnot, red.step.cons_bnot⟩ | ((x3,b3)::(x4,b4)::tl) _ [] _ _ _ _ _ H := by injections; subst_vars; simp; right; exact ⟨_, red.step.cons_bnot, red.step.bnot⟩ | ((x3,b3)::tl) _ ((x4,b4)::tl2) _ _ _ _ _ H := let ⟨H1, H2⟩ := list.cons.inj H in match step.diamond_aux H2 with | or.inl H3 := or.inl $ by simp [H1, H3] | or.inr ⟨Lβ‚…, H3, H4⟩ := or.inr ⟨_, step.cons H3, by simpa [H1] using step.cons H4⟩ end theorem step.diamond : βˆ€ {L₁ Lβ‚‚ L₃ Lβ‚„ : list (Ξ± Γ— bool)}, red.step L₁ L₃ β†’ red.step Lβ‚‚ Lβ‚„ β†’ L₁ = Lβ‚‚ β†’ L₃ = Lβ‚„ ∨ βˆƒ Lβ‚…, red.step L₃ Lβ‚… ∧ red.step Lβ‚„ Lβ‚… | _ _ _ _ red.step.bnot red.step.bnot H := step.diamond_aux H lemma step.to_red : step L₁ Lβ‚‚ β†’ red L₁ Lβ‚‚ := refl_trans_gen.single /-- Church-Rosser theorem for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. -/ theorem church_rosser : red L₁ Lβ‚‚ β†’ red L₁ L₃ β†’ join red Lβ‚‚ L₃ := relation.church_rosser (assume a b c hab hac, match b, c, red.step.diamond hab hac rfl with | b, _, or.inl rfl := ⟨b, by refl, by refl⟩ | b, c, or.inr ⟨d, hbd, hcd⟩ := ⟨d, refl_gen.single hbd, hcd.to_red⟩ end) lemma cons_cons {p} : red L₁ Lβ‚‚ β†’ red (p :: L₁) (p :: Lβ‚‚) := refl_trans_gen_lift (list.cons p) (assume a b, step.cons) lemma cons_cons_iff (p) : red (p :: L₁) (p :: Lβ‚‚) ↔ red L₁ Lβ‚‚ := iff.intro begin generalize eq₁ : (p :: L₁ : list _) = LL₁, generalize eqβ‚‚ : (p :: Lβ‚‚ : list _) = LLβ‚‚, assume h, induction h using relation.refl_trans_gen.head_induction_on with L₁ Lβ‚‚ h₁₂ h ih generalizing L₁ Lβ‚‚, { subst_vars, cases eqβ‚‚, constructor }, { subst_vars, cases p with a b, rw [step.cons_left_iff] at h₁₂, rcases h₁₂ with ⟨L, h₁₂, rfl⟩ | rfl, { exact (ih rfl rfl).head h₁₂ }, { exact (cons_cons h).tail step.cons_bnot_rev } } end cons_cons lemma append_append_left_iff : βˆ€L, red (L ++ L₁) (L ++ Lβ‚‚) ↔ red L₁ Lβ‚‚ | [] := iff.rfl | (p :: L) := by simp [append_append_left_iff L, cons_cons_iff] lemma append_append (h₁ : red L₁ L₃) (hβ‚‚ : red Lβ‚‚ Lβ‚„) : red (L₁ ++ Lβ‚‚) (L₃ ++ Lβ‚„) := (refl_trans_gen_lift (Ξ»L, L ++ Lβ‚‚) (assume a b, step.append_right) h₁).trans ((append_append_left_iff _).2 hβ‚‚) lemma to_append_iff : red L (L₁ ++ Lβ‚‚) ↔ (βˆƒL₃ Lβ‚„, L = L₃ ++ Lβ‚„ ∧ red L₃ L₁ ∧ red Lβ‚„ Lβ‚‚) := iff.intro begin generalize eq : L₁ ++ Lβ‚‚ = L₁₂, assume h, induction h with L' L₁₂ hLL' h ih generalizing L₁ Lβ‚‚, { exact ⟨_, _, eq.symm, by refl, by refl⟩ }, { cases h with s e a b, rcases list.append_eq_append_iff.1 eq with ⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩, { have : L₁ ++ (s' ++ ((a, b) :: (a, bnot b) :: e)) = (L₁ ++ s') ++ ((a, b) :: (a, bnot b) :: e), { simp }, rcases ih this with ⟨w₁, wβ‚‚, rfl, h₁, hβ‚‚βŸ©, exact ⟨w₁, wβ‚‚, rfl, h₁, hβ‚‚.tail step.bnot⟩ }, { have : (s ++ ((a, b) :: (a, bnot b) :: e')) ++ Lβ‚‚ = s ++ ((a, b) :: (a, bnot b) :: (e' ++ Lβ‚‚)), { simp }, rcases ih this with ⟨w₁, wβ‚‚, rfl, h₁, hβ‚‚βŸ©, exact ⟨w₁, wβ‚‚, rfl, h₁.tail step.bnot, hβ‚‚βŸ© }, } end (assume ⟨L₃, Lβ‚„, eq, h₃, hβ‚„βŸ©, eq.symm β–Έ append_append h₃ hβ‚„) /-- The empty word `[]` only reduces to itself. -/ theorem nil_iff : red [] L ↔ L = [] := refl_trans_gen_iff_eq (assume l, red.not_step_nil) /-- A letter only reduces to itself. -/ theorem singleton_iff {x} : red [x] L₁ ↔ L₁ = [x] := refl_trans_gen_iff_eq (assume l, not_step_singleton) /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ theorem cons_nil_iff_singleton {x b} : red ((x, b) :: L) [] ↔ red L [(x, bnot b)] := iff.intro (assume h, have h₁ : red ((x, bnot b) :: (x, b) :: L) [(x, bnot b)], from cons_cons h, have hβ‚‚ : red ((x, bnot b) :: (x, b) :: L) L, from refl_trans_gen.single step.cons_bnot_rev, let ⟨L', h₁, hβ‚‚βŸ© := church_rosser h₁ hβ‚‚ in by rw [singleton_iff] at h₁; subst L'; assumption) (assume h, (cons_cons h).tail step.cons_bnot) theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) β‰  (x2, b2)) : red [(x1, bnot b1), (x2, b2)] L ↔ L = [(x1, bnot b1), (x2, b2)] := begin apply refl_trans_gen_iff_eq, generalize eq : [(x1, bnot b1), (x2, b2)] = L', assume L h', cases h', simp [list.cons_eq_append_iff, list.nil_eq_append_iff] at eq, rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩, subst_vars, simp at h, contradiction end /-- If `x` and `y` are distinct letters and `w₁ wβ‚‚` are words such that `xw₁` reduces to `ywβ‚‚`, then `w₁` reduces to `x⁻¹ywβ‚‚`. -/ theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) β‰  (x2, b2)) (H2 : red ((x1, b1) :: L₁) ((x2, b2) :: Lβ‚‚)) : red L₁ ((x1, bnot b1) :: (x2, b2) :: Lβ‚‚) := begin have : red ((x1, b1) :: L₁) ([(x2, b2)] ++ Lβ‚‚), from H2, rcases to_append_iff.1 this with ⟨_ | ⟨p, Lβ‚ƒβŸ©, Lβ‚„, eq, h₁, hβ‚‚βŸ©, { simp [nil_iff] at h₁, contradiction }, { cases eq, show red (L₃ ++ Lβ‚„) ([(x1, bnot b1), (x2, b2)] ++ Lβ‚‚), apply append_append _ hβ‚‚, have h₁ : red ((x1, bnot b1) :: (x1, b1) :: L₃) [(x1, bnot b1), (x2, b2)], { exact cons_cons h₁ }, have hβ‚‚ : red ((x1, bnot b1) :: (x1, b1) :: L₃) L₃, { exact step.cons_bnot_rev.to_red }, rcases church_rosser h₁ hβ‚‚ with ⟨L', h₁, hβ‚‚βŸ©, rw [red_iff_irreducible H1] at h₁, rwa [h₁] at hβ‚‚ } end theorem step.sublist (H : red.step L₁ Lβ‚‚) : Lβ‚‚ <+ L₁ := by cases H; simp; constructor; constructor; refl /-- If `w₁ wβ‚‚` are words such that `w₁` reduces to `wβ‚‚`, then `wβ‚‚` is a sublist of `w₁`. -/ theorem sublist : red L₁ Lβ‚‚ β†’ Lβ‚‚ <+ L₁ := refl_trans_gen_of_transitive_reflexive (Ξ»l, list.sublist.refl l) (Ξ»a b c hab hbc, list.sublist.trans hbc hab) (Ξ»a b, red.step.sublist) theorem sizeof_of_step : βˆ€ {L₁ Lβ‚‚ : list (Ξ± Γ— bool)}, step L₁ Lβ‚‚ β†’ Lβ‚‚.sizeof < L₁.sizeof | _ _ (@step.bnot _ L1 L2 x b) := begin induction L1 with hd tl ih, case list.nil { dsimp [list.sizeof], have H : 1 + sizeof (x, b) + (1 + sizeof (x, bnot b) + list.sizeof L2) = (list.sizeof L2 + 1) + (sizeof (x, b) + sizeof (x, bnot b) + 1), { ac_refl }, rw H, exact nat.le_add_right _ _ }, case list.cons { dsimp [list.sizeof], exact nat.add_lt_add_left ih _ } end theorem length (h : red L₁ Lβ‚‚) : βˆƒ n, L₁.length = Lβ‚‚.length + 2 * n := begin induction h with Lβ‚‚ L₃ h₁₂ h₂₃ ih, { exact ⟨0, rfl⟩ }, { rcases ih with ⟨n, eq⟩, existsi (1 + n), simp [mul_add, eq, (step.length h₂₃).symm, add_assoc] } end theorem antisymm (h₁₂ : red L₁ Lβ‚‚) : red Lβ‚‚ L₁ β†’ L₁ = Lβ‚‚ := match L₁, h₁₂.cases_head with | _, or.inl rfl := assume h, rfl | L₁, or.inr ⟨L₃, h₁₃, hβ‚ƒβ‚‚βŸ© := assume h₂₁, let ⟨n, eq⟩ := length (h₃₂.trans h₂₁) in have list.length L₃ + 0 = list.length L₃ + (2 * n + 2), by simpa [(step.length h₁₃).symm, add_comm, add_assoc] using eq, (nat.no_confusion $ nat.add_left_cancel this) end end red theorem equivalence_join_red : equivalence (join (@red Ξ±)) := equivalence_join_refl_trans_gen $ assume a b c hab hac, (match b, c, red.step.diamond hab hac rfl with | b, _, or.inl rfl := ⟨b, by refl, by refl⟩ | b, c, or.inr ⟨d, hbd, hcd⟩ := ⟨d, refl_gen.single hbd, refl_trans_gen.single hcd⟩ end) theorem join_red_of_step (h : red.step L₁ Lβ‚‚) : join red L₁ Lβ‚‚ := join_of_single reflexive_refl_trans_gen h.to_red theorem eqv_gen_step_iff_join_red : eqv_gen red.step L₁ Lβ‚‚ ↔ join red L₁ Lβ‚‚ := iff.intro (assume h, have eqv_gen (join red) L₁ Lβ‚‚ := eqv_gen_mono (assume a b, join_red_of_step) h, (eqv_gen_iff_of_equivalence $ equivalence_join_red).1 this) (join_of_equivalence (eqv_gen.is_equivalence _) $ assume a b, refl_trans_gen_of_equivalence (eqv_gen.is_equivalence _) eqv_gen.rel) end free_group /-- The free group over a type, i.e. the words formed by the elements of the type and their formal inverses, quotient by one step reduction. -/ def free_group (Ξ± : Type u) : Type u := quot $ @free_group.red.step Ξ± namespace free_group variables {Ξ±} {L L₁ Lβ‚‚ L₃ Lβ‚„ : list (Ξ± Γ— bool)} /-- The canonical map from `list (Ξ± Γ— bool)` to the free group on `Ξ±`. -/ def mk (L) : free_group Ξ± := quot.mk red.step L @[simp] lemma quot_mk_eq_mk : quot.mk red.step L = mk L := rfl @[simp] lemma quot_lift_mk (Ξ² : Type v) (f : list (Ξ± Γ— bool) β†’ Ξ²) (H : βˆ€ L₁ Lβ‚‚, red.step L₁ Lβ‚‚ β†’ f L₁ = f Lβ‚‚) : quot.lift f H (mk L) = f L := rfl @[simp] lemma quot_lift_on_mk (Ξ² : Type v) (f : list (Ξ± Γ— bool) β†’ Ξ²) (H : βˆ€ L₁ Lβ‚‚, red.step L₁ Lβ‚‚ β†’ f L₁ = f Lβ‚‚) : quot.lift_on (mk L) f H = f L := rfl instance : has_one (free_group Ξ±) := ⟨mk []⟩ lemma one_eq_mk : (1 : free_group Ξ±) = mk [] := rfl instance : inhabited (free_group Ξ±) := ⟨1⟩ instance : has_mul (free_group Ξ±) := ⟨λ x y, quot.lift_on x (Ξ» L₁, quot.lift_on y (Ξ» Lβ‚‚, mk $ L₁ ++ Lβ‚‚) (Ξ» Lβ‚‚ L₃ H, quot.sound $ red.step.append_left H)) (Ξ» L₁ Lβ‚‚ H, quot.induction_on y $ Ξ» L₃, quot.sound $ red.step.append_right H)⟩ @[simp] lemma mul_mk : mk L₁ * mk Lβ‚‚ = mk (L₁ ++ Lβ‚‚) := rfl instance : has_inv (free_group Ξ±) := ⟨λx, quot.lift_on x (Ξ» L, mk (L.map $ Ξ» x : Ξ± Γ— bool, (x.1, bnot x.2)).reverse) (assume a b h, quot.sound $ by cases h; simp)⟩ @[simp] lemma inv_mk : (mk L)⁻¹ = mk (L.map $ Ξ» x : Ξ± Γ— bool, (x.1, bnot x.2)).reverse := rfl instance : group (free_group Ξ±) := { mul := (*), one := 1, inv := has_inv.inv, mul_assoc := by rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ© ⟨Lβ‚ƒβŸ©; simp, one_mul := by rintros ⟨L⟩; refl, mul_one := by rintros ⟨L⟩; simp [one_eq_mk], mul_left_inv := by rintros ⟨L⟩; exact (list.rec_on L rfl $ Ξ» ⟨x, b⟩ tl ih, eq.trans (quot.sound $ by simp [one_eq_mk]) ih) } /-- `of x` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ def of (x : Ξ±) : free_group Ξ± := mk [(x, tt)] theorem red.exact : mk L₁ = mk Lβ‚‚ ↔ join red L₁ Lβ‚‚ := calc (mk L₁ = mk Lβ‚‚) ↔ eqv_gen red.step L₁ Lβ‚‚ : iff.intro (quot.exact _) quot.eqv_gen_sound ... ↔ join red L₁ Lβ‚‚ : eqv_gen_step_iff_join_red /-- The canonical injection from the type to the free group is an injection. -/ theorem of.inj {x y : Ξ±} (H : of x = of y) : x = y := let ⟨L₁, hx, hy⟩ := red.exact.1 H in by simp [red.singleton_iff] at hx hy; cc section to_group variables {Ξ² : Type v} [group Ξ²] (f : Ξ± β†’ Ξ²) {x y : free_group Ξ±} /-- Given `f : Ξ± β†’ Ξ²` with `Ξ²` a group, the canonical map `list (Ξ± Γ— bool) β†’ Ξ²` -/ def to_group.aux : list (Ξ± Γ— bool) β†’ Ξ² := Ξ» L, list.prod $ L.map $ Ξ» x, cond x.2 (f x.1) (f x.1)⁻¹ theorem red.step.to_group {f : Ξ± β†’ Ξ²} (H : red.step L₁ Lβ‚‚) : to_group.aux f L₁ = to_group.aux f Lβ‚‚ := by cases H with _ _ _ b; cases b; simp [to_group.aux] /-- If `Ξ²` is a group, then any function from `Ξ±` to `Ξ²` extends uniquely to a group homomorphism from the free group over `Ξ±` to `Ξ²`. Note that this is the bare function; the group homomorphism is `to_group`. -/ def to_group.to_fun : free_group Ξ± β†’ Ξ² := quot.lift (to_group.aux f) $ Ξ» L₁ Lβ‚‚ H, red.step.to_group H /-- If `Ξ²` is a group, then any function from `Ξ±` to `Ξ²` extends uniquely to a group homomorphism from the free group over `Ξ±` to `Ξ²` -/ def to_group : free_group Ξ± β†’* Ξ² := monoid_hom.mk' (to_group.to_fun f) $ begin rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ©; simp [to_group.to_fun, to_group.aux], end variable {f} @[simp] lemma to_group.mk : to_group f (mk L) = list.prod (L.map $ Ξ» x, cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[simp] lemma to_group.of {x} : to_group f (of x) = f x := one_mul _ instance to_group.is_group_hom : is_group_hom (to_group f) := { map_mul := by rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ©; simp } @[simp] lemma to_group.mul : to_group f (x * y) = to_group f x * to_group f y := is_mul_hom.map_mul _ _ _ @[simp] lemma to_group.one : to_group f 1 = 1 := is_group_hom.map_one _ @[simp] lemma to_group.inv : to_group f x⁻¹ = (to_group f x)⁻¹ := is_group_hom.map_inv _ _ theorem to_group.unique (g : free_group Ξ± β†’* Ξ²) (hg : βˆ€ x, g (of x) = f x) : βˆ€{x}, g x = to_group f x := by rintros ⟨L⟩; exact list.rec_on L (is_group_hom.map_one g) (Ξ» ⟨x, b⟩ t (ih : g (mk t) = _), bool.rec_on b (show g ((of x)⁻¹ * mk t) = to_group f (mk ((x, ff) :: t)), by simp [monoid_hom.map_mul g, monoid_hom.map_inv g, hg, ih, to_group.to_fun, to_group.aux]) (show g (of x * mk t) = to_group f (mk ((x, tt) :: t)), by simp [monoid_hom.map_mul g, monoid_hom.map_inv g, hg, ih, to_group.to_fun, to_group.aux])) theorem to_group.of_eq (x : free_group Ξ±) : to_group of x = x := eq.symm $ to_group.unique (monoid_hom.id _) (Ξ» x, rfl) theorem to_group.range_subset {s : subgroup Ξ²} (H : set.range f βŠ† s) : set.range (to_group f) βŠ† s := by rintros _ ⟨⟨L⟩, rfl⟩; exact list.rec_on L s.one_mem (Ξ» ⟨x, b⟩ tl ih, bool.rec_on b (by simp at ih ⊒; from s.mul_mem (s.inv_mem $ H ⟨x, rfl⟩) ih) (by simp at ih ⊒; from s.mul_mem (H ⟨x, rfl⟩) ih)) theorem closure_subset {G : Type*} [group G] {s : set G} {t : subgroup G} (h : s βŠ† t) : subgroup.closure s ≀ t := begin simp only [h, subgroup.closure_le], end theorem to_group.range_eq_closure : set.range (to_group f) = subgroup.closure (set.range f) := set.subset.antisymm (to_group.range_subset subgroup.subset_closure) begin suffices : (subgroup.closure (set.range f)) ≀ monoid_hom.range (to_group f), simpa, rw subgroup.closure_le, rintros y ⟨x, hx⟩, exact ⟨of x, by simpa⟩ end end to_group section map variables {Ξ² : Type v} (f : Ξ± β†’ Ξ²) {x y : free_group Ξ±} /-- Given `f : Ξ± β†’ Ξ²`, the canonical map `list (Ξ± Γ— bool) β†’ list (Ξ² Γ— bool)`. -/ def map.aux (L : list (Ξ± Γ— bool)) : list (Ξ² Γ— bool) := L.map $ Ξ» x, (f x.1, x.2) /-- Any function from `Ξ±` to `Ξ²` extends uniquely to a group homomorphism from the free group over `Ξ±` to the free group over `Ξ²`. Note that this is the bare function; for the group homomorphism use `map`. -/ def map.to_fun (x : free_group Ξ±) : free_group Ξ² := x.lift_on (Ξ» L, mk $ map.aux f L) $ Ξ» L₁ Lβ‚‚ H, quot.sound $ by cases H; simp [map.aux] /-- Any function from `Ξ±` to `Ξ²` extends uniquely to a group homomorphism from the free group ver `Ξ±` to the free group over `Ξ²`. -/ def map : free_group Ξ± β†’* free_group Ξ² := monoid_hom.mk' (map.to_fun f) begin rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ©, simp [map.to_fun, map.aux] end --by rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ©; simp [map, map.aux] variable {f} @[simp] lemma map.mk : map f (mk L) = mk (L.map (Ξ» x, (f x.1, x.2))) := rfl @[simp] lemma map.id : map id x = x := have H1 : (Ξ» (x : Ξ± Γ— bool), x) = id := rfl, by rcases x with ⟨L⟩; simp [H1] @[simp] lemma map.id' : map (Ξ» z, z) x = x := map.id theorem map.comp {Ξ³ : Type w} {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} {x} : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp @[simp] lemma map.of {x} : map f (of x) = of (f x) := rfl @[simp] lemma map.mul : map f (x * y) = map f x * map f y := is_mul_hom.map_mul _ x y @[simp] lemma map.one : map f 1 = 1 := is_group_hom.map_one _ @[simp] lemma map.inv : map f x⁻¹ = (map f x)⁻¹ := is_group_hom.map_inv _ x theorem map.unique (g : free_group Ξ± β†’ free_group Ξ²) [is_group_hom g] (hg : βˆ€ x, g (of x) = of (f x)) : βˆ€{x}, g x = map f x := by rintros ⟨L⟩; exact list.rec_on L (is_group_hom.map_one g) (Ξ» ⟨x, b⟩ t (ih : g (mk t) = map f (mk t)), bool.rec_on b (show g ((of x)⁻¹ * mk t) = map f ((of x)⁻¹ * mk t), by simp [is_mul_hom.map_mul g, is_group_hom.map_inv g, hg, ih]) (show g (of x * mk t) = map f (of x * mk t), by simp [is_mul_hom.map_mul g, hg, ih])) /-- Equivalent types give rise to equivalent free groups. -/ def free_group_congr {Ξ± Ξ²} (e : Ξ± ≃ Ξ²) : free_group Ξ± ≃ free_group Ξ² := ⟨map e, map e.symm, Ξ» x, by simp [function.comp, map.comp], Ξ» x, by simp [function.comp, map.comp]⟩ theorem map_eq_to_group : map f x = to_group (of ∘ f) x := eq.symm $ map.unique _ $ Ξ» x, by simp end map section prod variables [group Ξ±] (x y : free_group Ξ±) /-- If `Ξ±` is a group, then any function from `Ξ±` to `Ξ±` extends uniquely to a homomorphism from the free group over `Ξ±` to `Ξ±`. This is the multiplicative version of `sum`. -/ def prod : free_group Ξ± β†’* Ξ± := to_group id variables {x y} @[simp] lemma prod_mk : prod (mk L) = list.prod (L.map $ Ξ» x, cond x.2 x.1 x.1⁻¹) := rfl @[simp] lemma prod.of {x : Ξ±} : prod (of x) = x := to_group.of @[simp] lemma prod.mul : prod (x * y) = prod x * prod y := to_group.mul @[simp] lemma prod.one : prod (1:free_group Ξ±) = 1 := to_group.one @[simp] lemma prod.inv : prod x⁻¹ = (prod x)⁻¹ := to_group.inv lemma prod.unique (g : free_group Ξ± β†’* Ξ±) (hg : βˆ€ x, g (of x) = x) {x} : g x = prod x := to_group.unique g hg end prod theorem to_group_eq_prod_map {Ξ² : Type v} [group Ξ²] {f : Ξ± β†’ Ξ²} {x} : to_group f x = prod (map f x) := begin rw ←to_group.unique (prod.comp (map f)), { refl }, { simp } end section sum variables [add_group Ξ±] (x y : free_group Ξ±) /-- If `Ξ±` is a group, then any function from `Ξ±` to `Ξ±` extends uniquely to a homomorphism from the free group over `Ξ±` to `Ξ±`. This is the additive version of `prod`. -/ def sum : Ξ± := @prod (multiplicative _) _ x variables {x y} @[simp] lemma sum_mk : sum (mk L) = list.sum (L.map $ Ξ» x, cond x.2 x.1 (-x.1)) := rfl @[simp] lemma sum.of {x : Ξ±} : sum (of x) = x := prod.of instance sum.is_group_hom : is_group_hom (@sum Ξ± _) := prod.is_group_hom @[simp] lemma sum.mul : sum (x * y) = sum x + sum y := prod.mul @[simp] lemma sum.one : sum (1:free_group Ξ±) = 0 := prod.one @[simp] lemma sum.inv : sum x⁻¹ = -sum x := prod.inv end sum /-- The bijection between the free group on the empty type, and a type with one element. -/ def free_group_empty_equiv_unit : free_group empty ≃ unit := { to_fun := Ξ» _, (), inv_fun := Ξ» _, 1, left_inv := by rintros ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; refl, right_inv := Ξ» ⟨⟩, rfl } /-- The bijection between the free group on a singleton, and the integers. -/ def free_group_unit_equiv_int : free_group unit ≃ int := { to_fun := Ξ» x, sum begin revert x, apply monoid_hom.to_fun, apply map (Ξ» _, (1 : β„€)), end, inv_fun := Ξ» x, of () ^ x, left_inv := begin rintros ⟨L⟩, refine list.rec_on L rfl _, exact (Ξ» ⟨⟨⟩, b⟩ tl ih, by cases b; simp [gpow_add] at ih ⊒; rw ih; refl), end, right_inv := Ξ» x, int.induction_on x (by simp) (Ξ» i ih, by simp at ih; simp [gpow_add, ih]) (Ξ» i ih, by simp at ih; simp [gpow_add, ih, sub_eq_add_neg]) } section category variables {Ξ² : Type u} instance : monad free_group.{u} := { pure := Ξ» Ξ±, of, map := Ξ» Ξ± Ξ² f, (map f), bind := Ξ» Ξ± Ξ² x f, to_group f x } @[elab_as_eliminator] protected theorem induction_on {C : free_group Ξ± β†’ Prop} (z : free_group Ξ±) (C1 : C 1) (Cp : βˆ€ x, C $ pure x) (Ci : βˆ€ x, C (pure x) β†’ C (pure x)⁻¹) (Cm : βˆ€ x y, C x β†’ C y β†’ C (x * y)) : C z := quot.induction_on z $ Ξ» L, list.rec_on L C1 $ Ξ» ⟨x, b⟩ tl ih, bool.rec_on b (Cm _ _ (Ci _ $ Cp x) ih) (Cm _ _ (Cp x) ih) @[simp] lemma map_pure (f : Ξ± β†’ Ξ²) (x : Ξ±) : f <$> (pure x : free_group Ξ±) = pure (f x) := map.of @[simp] lemma map_one (f : Ξ± β†’ Ξ²) : f <$> (1 : free_group Ξ±) = 1 := map.one @[simp] lemma map_mul (f : Ξ± β†’ Ξ²) (x y : free_group Ξ±) : f <$> (x * y) = f <$> x * f <$> y := map.mul @[simp] lemma map_inv (f : Ξ± β†’ Ξ²) (x : free_group Ξ±) : f <$> (x⁻¹) = (f <$> x)⁻¹ := map.inv @[simp] lemma pure_bind (f : Ξ± β†’ free_group Ξ²) (x) : pure x >>= f = f x := to_group.of @[simp] lemma one_bind (f : Ξ± β†’ free_group Ξ²) : 1 >>= f = 1 := @@to_group.one _ f @[simp] lemma mul_bind (f : Ξ± β†’ free_group Ξ²) (x y : free_group Ξ±) : x * y >>= f = (x >>= f) * (y >>= f) := to_group.mul @[simp] lemma inv_bind (f : Ξ± β†’ free_group Ξ²) (x : free_group Ξ±) : x⁻¹ >>= f = (x >>= f)⁻¹ := to_group.inv instance : is_lawful_monad free_group.{u} := { id_map := Ξ» Ξ± x, free_group.induction_on x (map_one id) (Ξ» x, map_pure id x) (Ξ» x ih, by rw [map_inv, ih]) (Ξ» x y ihx ihy, by rw [map_mul, ihx, ihy]), pure_bind := Ξ» Ξ± Ξ² x f, pure_bind f x, bind_assoc := Ξ» Ξ± Ξ² Ξ³ x f g, free_group.induction_on x (by iterate 3 { rw one_bind }) (Ξ» x, by iterate 2 { rw pure_bind }) (Ξ» x ih, by iterate 3 { rw inv_bind }; rw ih) (Ξ» x y ihx ihy, by iterate 3 { rw mul_bind }; rw [ihx, ihy]), bind_pure_comp_eq_map := Ξ» Ξ± Ξ² f x, free_group.induction_on x (by rw [one_bind, map_one]) (Ξ» x, by rw [pure_bind, map_pure]) (Ξ» x ih, by rw [inv_bind, map_inv, ih]) (Ξ» x y ihx ihy, by rw [mul_bind, map_mul, ihx, ihy]) } end category section reduce variable [decidable_eq Ξ±] /-- The maximal reduction of a word. It is computable iff `Ξ±` has decidable equality. -/ def reduce (L : list (Ξ± Γ— bool)) : list (Ξ± Γ— bool) := list.rec_on L [] $ Ξ» hd1 tl1 ih, list.cases_on ih [hd1] $ Ξ» hd2 tl2, if hd1.1 = hd2.1 ∧ hd1.2 = bnot hd2.2 then tl2 else hd1 :: hd2 :: tl2 @[simp] lemma reduce.cons (x) : reduce (x :: L) = list.cases_on (reduce L) [x] (Ξ» hd tl, if x.1 = hd.1 ∧ x.2 = bnot hd.2 then tl else x :: hd :: tl) := rfl /-- The first theorem that characterises the function `reduce`: a word reduces to its maximal reduction. -/ theorem reduce.red : red L (reduce L) := begin induction L with hd1 tl1 ih, case list.nil { constructor }, case list.cons { dsimp, revert ih, generalize htl : reduce tl1 = TL, intro ih, cases TL with hd2 tl2, case list.nil { exact red.cons_cons ih }, case list.cons { dsimp, by_cases h : hd1.fst = hd2.fst ∧ hd1.snd = bnot (hd2.snd), { rw [if_pos h], transitivity, { exact red.cons_cons ih }, { cases hd1, cases hd2, cases h, dsimp at *, subst_vars, exact red.step.cons_bnot_rev.to_red } }, { rw [if_neg h], exact red.cons_cons ih } } } end theorem reduce.not {p : Prop} : βˆ€ {L₁ Lβ‚‚ L₃ : list (Ξ± Γ— bool)} {x b}, reduce L₁ = Lβ‚‚ ++ (x, b) :: (x, bnot b) :: L₃ β†’ p | [] L2 L3 _ _ := Ξ» h, by cases L2; injections | ((x,b)::L1) L2 L3 x' b' := begin dsimp, cases r : reduce L1, { dsimp, intro h, have := congr_arg list.length h, simp [-add_comm] at this, exact absurd this dec_trivial }, cases hd with y c, by_cases x = y ∧ b = bnot c; simp [h]; intro H, { rw H at r, exact @reduce.not L1 ((y,c)::L2) L3 x' b' r }, rcases L2 with _|⟨a, L2⟩, { injections, subst_vars, simp at h, cc }, { refine @reduce.not L1 L2 L3 x' b' _, injection H with _ H, rw [r, H], refl } end /-- The second theorem that characterises the function `reduce`: the maximal reduction of a word only reduces to itself. -/ theorem reduce.min (H : red (reduce L₁) Lβ‚‚) : reduce L₁ = Lβ‚‚ := begin induction H with L1 L' L2 H1 H2 ih, { refl }, { cases H1 with L4 L5 x b, exact reduce.not H2 } end /-- `reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the maximal reduction of the word. -/ theorem reduce.idem : reduce (reduce L) = reduce L := eq.symm $ reduce.min reduce.red theorem reduce.step.eq (H : red.step L₁ Lβ‚‚) : reduce L₁ = reduce Lβ‚‚ := let ⟨L₃, HR13, HR23⟩ := red.church_rosser reduce.red (reduce.red.head H) in (reduce.min HR13).trans (reduce.min HR23).symm /-- If a word reduces to another word, then they have a common maximal reduction. -/ theorem reduce.eq_of_red (H : red L₁ Lβ‚‚) : reduce L₁ = reduce Lβ‚‚ := let ⟨L₃, HR13, HR23⟩ := red.church_rosser reduce.red (red.trans H reduce.red) in (reduce.min HR13).trans (reduce.min HR23).symm /-- If two words correspond to the same element in the free group, then they have a common maximal reduction. This is the proof that the function that sends an element of the free group to its maximal reduction is well-defined. -/ theorem reduce.sound (H : mk L₁ = mk Lβ‚‚) : reduce L₁ = reduce Lβ‚‚ := let ⟨L₃, H13, H23⟩ := red.exact.1 H in (reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm /-- If two words have a common maximal reduction, then they correspond to the same element in the free group. -/ theorem reduce.exact (H : reduce L₁ = reduce Lβ‚‚) : mk L₁ = mk Lβ‚‚ := red.exact.2 ⟨reduce Lβ‚‚, H β–Έ reduce.red, reduce.red⟩ /-- A word and its maximal reduction correspond to the same element of the free group. -/ theorem reduce.self : mk (reduce L) = mk L := reduce.exact reduce.idem /-- If words `w₁ wβ‚‚` are such that `w₁` reduces to `wβ‚‚`, then `wβ‚‚` reduces to the maximal reduction of `w₁`. -/ theorem reduce.rev (H : red L₁ Lβ‚‚) : red Lβ‚‚ (reduce L₁) := (reduce.eq_of_red H).symm β–Έ reduce.red /-- The function that sends an element of the free group to its maximal reduction. -/ def to_word : free_group Ξ± β†’ list (Ξ± Γ— bool) := quot.lift reduce $ Ξ» L₁ Lβ‚‚ H, reduce.step.eq H lemma to_word.mk : βˆ€{x : free_group Ξ±}, mk (to_word x) = x := by rintros ⟨L⟩; exact reduce.self lemma to_word.inj : βˆ€(x y : free_group Ξ±), to_word x = to_word y β†’ x = y := by rintros ⟨Lβ‚βŸ© ⟨Lβ‚‚βŸ©; exact reduce.exact /-- Constructive Church-Rosser theorem (compare `church_rosser`). -/ def reduce.church_rosser (H12 : red L₁ Lβ‚‚) (H13 : red L₁ L₃) : { Lβ‚„ // red Lβ‚‚ Lβ‚„ ∧ red L₃ Lβ‚„ } := ⟨reduce L₁, reduce.rev H12, reduce.rev H13⟩ instance : decidable_eq (free_group Ξ±) := function.injective.decidable_eq to_word.inj instance red.decidable_rel : decidable_rel (@red Ξ±) | [] [] := is_true red.refl | [] (hd2::tl2) := is_false $ Ξ» H, list.no_confusion (red.nil_iff.1 H) | ((x,b)::tl) [] := match red.decidable_rel tl [(x, bnot b)] with | is_true H := is_true $ red.trans (red.cons_cons H) $ (@red.step.bnot _ [] [] _ _).to_red | is_false H := is_false $ Ξ» H2, H $ red.cons_nil_iff_singleton.1 H2 end | ((x1,b1)::tl1) ((x2,b2)::tl2) := if h : (x1, b1) = (x2, b2) then match red.decidable_rel tl1 tl2 with | is_true H := is_true $ h β–Έ red.cons_cons H | is_false H := is_false $ Ξ» H2, H $ h β–Έ (red.cons_cons_iff _).1 $ H2 end else match red.decidable_rel tl1 ((x1,bnot b1)::(x2,b2)::tl2) with | is_true H := is_true $ (red.cons_cons H).tail red.step.cons_bnot | is_false H := is_false $ Ξ» H2, H $ red.inv_of_red_of_ne h H2 end /-- A list containing every word that `w₁` reduces to. -/ def red.enum (L₁ : list (Ξ± Γ— bool)) : list (list (Ξ± Γ— bool)) := list.filter (Ξ» Lβ‚‚, red L₁ Lβ‚‚) (list.sublists L₁) theorem red.enum.sound (H : Lβ‚‚ ∈ red.enum L₁) : red L₁ Lβ‚‚ := list.of_mem_filter H theorem red.enum.complete (H : red L₁ Lβ‚‚) : Lβ‚‚ ∈ red.enum L₁ := list.mem_filter_of_mem (list.mem_sublists.2 $ red.sublist H) H instance : fintype { Lβ‚‚ // red L₁ Lβ‚‚ } := fintype.subtype (list.to_finset $ red.enum L₁) $ Ξ» Lβ‚‚, ⟨λ H, red.enum.sound $ list.mem_to_finset.1 H, Ξ» H, list.mem_to_finset.2 $ red.enum.complete H⟩ end reduce end free_group
4ae91fc2d4b834f889bd965bfeb62cd8e124302b
4727251e0cd73359b15b664c3170e5d754078599
/src/field_theory/is_alg_closed/algebraic_closure.lean
94f4671ff1e03c2975bc288eac8da70e3998eeaa
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
10,831
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.direct_limit import field_theory.is_alg_closed.basic /-! # Algebraic Closure In this file we construct the algebraic closure of a field ## Main Definitions - `algebraic_closure k` is an algebraic closure of `k` (in the same universe). It is constructed by taking the polynomial ring generated by indeterminates `x_f` corresponding to monic irreducible polynomials `f` with coefficients in `k`, and quotienting out by a maximal ideal containing every `f(x_f)`, and then repeating this step countably many times. See Exercise 1.13 in Atiyah--Macdonald. ## Tags algebraic closure, algebraically closed -/ universes u v w noncomputable theory open_locale classical big_operators polynomial open polynomial variables (k : Type u) [field k] namespace algebraic_closure open mv_polynomial /-- The subtype of monic irreducible polynomials -/ @[reducible] def monic_irreducible : Type u := { f : k[X] // monic f ∧ irreducible f } /-- Sends a monic irreducible polynomial `f` to `f(x_f)` where `x_f` is a formal indeterminate. -/ def eval_X_self (f : monic_irreducible k) : mv_polynomial (monic_irreducible k) k := polynomial.evalβ‚‚ mv_polynomial.C (X f) f /-- The span of `f(x_f)` across monic irreducible polynomials `f` where `x_f` is an indeterminate. -/ def span_eval : ideal (mv_polynomial (monic_irreducible k) k) := ideal.span $ set.range $ eval_X_self k /-- Given a finset of monic irreducible polynomials, construct an algebra homomorphism to the splitting field of the product of the polynomials sending each indeterminate `x_f` represented by the polynomial `f` in the finset to a root of `f`. -/ def to_splitting_field (s : finset (monic_irreducible k)) : mv_polynomial (monic_irreducible k) k →ₐ[k] splitting_field (∏ x in s, x : k[X]) := mv_polynomial.aeval $ Ξ» f, if hf : f ∈ s then root_of_splits _ ((splits_prod_iff _ $ Ξ» (j : monic_irreducible k) _, j.2.2.ne_zero).1 (splitting_field.splits _) f hf) (mt is_unit_iff_degree_eq_zero.2 f.2.2.not_unit) else 37 theorem to_splitting_field_eval_X_self {s : finset (monic_irreducible k)} {f} (hf : f ∈ s) : to_splitting_field k s (eval_X_self k f) = 0 := by { rw [to_splitting_field, eval_X_self, ← alg_hom.coe_to_ring_hom, hom_evalβ‚‚, alg_hom.coe_to_ring_hom, mv_polynomial.aeval_X, dif_pos hf, ← algebra_map_eq, alg_hom.comp_algebra_map], exact map_root_of_splits _ _ _ } theorem span_eval_ne_top : span_eval k β‰  ⊀ := begin rw [ideal.ne_top_iff_one, span_eval, ideal.span, ← set.image_univ, finsupp.mem_span_image_iff_total], rintros ⟨v, _, hv⟩, replace hv := congr_arg (to_splitting_field k v.support) hv, rw [alg_hom.map_one, finsupp.total_apply, finsupp.sum, alg_hom.map_sum, finset.sum_eq_zero] at hv, { exact zero_ne_one hv }, intros j hj, rw [smul_eq_mul, alg_hom.map_mul, to_splitting_field_eval_X_self k hj, mul_zero] end /-- A random maximal ideal that contains `span_eval k` -/ def max_ideal : ideal (mv_polynomial (monic_irreducible k) k) := classical.some $ ideal.exists_le_maximal _ $ span_eval_ne_top k instance max_ideal.is_maximal : (max_ideal k).is_maximal := (classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).1 theorem le_max_ideal : span_eval k ≀ max_ideal k := (classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).2 /-- The first step of constructing `algebraic_closure`: adjoin a root of all monic polynomials -/ def adjoin_monic : Type u := mv_polynomial (monic_irreducible k) k β§Έ max_ideal k instance adjoin_monic.field : field (adjoin_monic k) := ideal.quotient.field _ instance adjoin_monic.inhabited : inhabited (adjoin_monic k) := ⟨37⟩ /-- The canonical ring homomorphism to `adjoin_monic k`. -/ def to_adjoin_monic : k β†’+* adjoin_monic k := (ideal.quotient.mk _).comp C instance adjoin_monic.algebra : algebra k (adjoin_monic k) := (to_adjoin_monic k).to_algebra theorem adjoin_monic.algebra_map : algebra_map k (adjoin_monic k) = (ideal.quotient.mk _).comp C := rfl theorem adjoin_monic.is_integral (z : adjoin_monic k) : is_integral k z := let ⟨p, hp⟩ := ideal.quotient.mk_surjective z in hp β–Έ mv_polynomial.induction_on p (Ξ» x, is_integral_algebra_map) (Ξ» p q, is_integral_add) (Ξ» p f ih, @is_integral_mul _ _ _ _ _ _ (ideal.quotient.mk _ _) ih ⟨f, f.2.1, by { erw [adjoin_monic.algebra_map, ← hom_evalβ‚‚, ideal.quotient.eq_zero_iff_mem], exact le_max_ideal k (ideal.subset_span ⟨f, rfl⟩) }⟩) theorem adjoin_monic.exists_root {f : k[X]} (hfm : f.monic) (hfi : irreducible f) : βˆƒ x : adjoin_monic k, f.evalβ‚‚ (to_adjoin_monic k) x = 0 := ⟨ideal.quotient.mk _ $ X (⟨f, hfm, hfi⟩ : monic_irreducible k), by { rw [to_adjoin_monic, ← hom_evalβ‚‚, ideal.quotient.eq_zero_iff_mem], exact le_max_ideal k (ideal.subset_span $ ⟨_, rfl⟩) }⟩ /-- The `n`th step of constructing `algebraic_closure`, together with its `field` instance. -/ def step_aux (n : β„•) : Ξ£ Ξ± : Type u, field Ξ± := nat.rec_on n ⟨k, infer_instance⟩ $ Ξ» n ih, ⟨@adjoin_monic ih.1 ih.2, @adjoin_monic.field ih.1 ih.2⟩ /-- The `n`th step of constructing `algebraic_closure`. -/ def step (n : β„•) : Type u := (step_aux k n).1 instance step.field (n : β„•) : field (step k n) := (step_aux k n).2 instance step.inhabited (n) : inhabited (step k n) := ⟨37⟩ /-- The canonical inclusion to the `0`th step. -/ def to_step_zero : k β†’+* step k 0 := ring_hom.id k /-- The canonical ring homomorphism to the next step. -/ def to_step_succ (n : β„•) : step k n β†’+* step k (n + 1) := @to_adjoin_monic (step k n) (step.field k n) instance step.algebra_succ (n) : algebra (step k n) (step k (n + 1)) := (to_step_succ k n).to_algebra theorem to_step_succ.exists_root {n} {f : polynomial (step k n)} (hfm : f.monic) (hfi : irreducible f) : βˆƒ x : step k (n + 1), f.evalβ‚‚ (to_step_succ k n) x = 0 := @adjoin_monic.exists_root _ (step.field k n) _ hfm hfi /-- The canonical ring homomorphism to a step with a greater index. -/ def to_step_of_le (m n : β„•) (h : m ≀ n) : step k m β†’+* step k n := { to_fun := nat.le_rec_on h (Ξ» n, to_step_succ k n), map_one' := begin induction h with n h ih, { exact nat.le_rec_on_self 1 }, rw [nat.le_rec_on_succ h, ih, ring_hom.map_one] end, map_mul' := Ξ» x y, begin induction h with n h ih, { simp_rw nat.le_rec_on_self }, simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_mul] end, map_zero' := begin induction h with n h ih, { exact nat.le_rec_on_self 0 }, rw [nat.le_rec_on_succ h, ih, ring_hom.map_zero] end, map_add' := Ξ» x y, begin induction h with n h ih, { simp_rw nat.le_rec_on_self }, simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_add] end } @[simp] lemma coe_to_step_of_le (m n : β„•) (h : m ≀ n) : (to_step_of_le k m n h : step k m β†’ step k n) = nat.le_rec_on h (Ξ» n, to_step_succ k n) := rfl instance step.algebra (n) : algebra k (step k n) := (to_step_of_le k 0 n n.zero_le).to_algebra instance step.scalar_tower (n) : is_scalar_tower k (step k n) (step k (n + 1)) := is_scalar_tower.of_algebra_map_eq $ Ξ» z, @nat.le_rec_on_succ (step k) 0 n n.zero_le (n + 1).zero_le (Ξ» n, to_step_succ k n) z theorem step.is_integral (n) : βˆ€ z : step k n, is_integral k z := nat.rec_on n (Ξ» z, is_integral_algebra_map) $ Ξ» n ih z, is_integral_trans ih _ (adjoin_monic.is_integral (step k n) z : _) instance to_step_of_le.directed_system : directed_system (step k) (Ξ» i j h, to_step_of_le k i j h) := ⟨λ i x h, nat.le_rec_on_self x, Ξ» i₁ iβ‚‚ i₃ h₁₂ h₂₃ x, (nat.le_rec_on_trans h₁₂ h₂₃ x).symm⟩ end algebraic_closure /-- The canonical algebraic closure of a field, the direct limit of adding roots to the field for each polynomial over the field. -/ def algebraic_closure : Type u := ring.direct_limit (algebraic_closure.step k) (Ξ» i j h, algebraic_closure.to_step_of_le k i j h) namespace algebraic_closure instance : field (algebraic_closure k) := field.direct_limit.field _ _ instance : inhabited (algebraic_closure k) := ⟨37⟩ /-- The canonical ring embedding from the `n`th step to the algebraic closure. -/ def of_step (n : β„•) : step k n β†’+* algebraic_closure k := ring.direct_limit.of _ _ _ instance algebra_of_step (n) : algebra (step k n) (algebraic_closure k) := (of_step k n).to_algebra theorem of_step_succ (n : β„•) : (of_step k (n + 1)).comp (to_step_succ k n) = of_step k n := ring_hom.ext $ Ξ» x, show ring.direct_limit.of (step k) (Ξ» i j h, to_step_of_le k i j h) _ _ = _, by { convert ring.direct_limit.of_f n.le_succ x, ext x, exact (nat.le_rec_on_succ' x).symm } theorem exists_of_step (z : algebraic_closure k) : βˆƒ n x, of_step k n x = z := ring.direct_limit.exists_of z -- slow theorem exists_root {f : polynomial (algebraic_closure k)} (hfm : f.monic) (hfi : irreducible f) : βˆƒ x : algebraic_closure k, f.eval x = 0 := begin have : βˆƒ n p, polynomial.map (of_step k n) p = f, { convert ring.direct_limit.polynomial.exists_of f }, unfreezingI { obtain ⟨n, p, rfl⟩ := this }, rw monic_map_iff at hfm, have := hfm.irreducible_of_irreducible_map (of_step k n) p hfi, obtain ⟨x, hx⟩ := to_step_succ.exists_root k hfm this, refine ⟨of_step k (n + 1) x, _⟩, rw [← of_step_succ k n, eval_map, ← hom_evalβ‚‚, hx, ring_hom.map_zero] end instance : is_alg_closed (algebraic_closure k) := is_alg_closed.of_exists_root _ $ Ξ» f, exists_root k instance {R : Type*} [comm_semiring R] [alg : algebra R k] : algebra R (algebraic_closure k) := ((of_step k 0).comp (@algebra_map _ _ _ _ alg)).to_algebra lemma algebra_map_def {R : Type*} [comm_semiring R] [alg : algebra R k] : algebra_map R (algebraic_closure k) = ((of_step k 0 : k β†’+* _).comp (@algebra_map _ _ _ _ alg)) := rfl instance {R S : Type*} [comm_semiring R] [comm_semiring S] [algebra R S] [algebra S k] [algebra R k] [is_scalar_tower R S k] : is_scalar_tower R S (algebraic_closure k) := is_scalar_tower.of_algebra_map_eq (Ξ» x, ring_hom.congr_arg _ (is_scalar_tower.algebra_map_apply R S k x : _)) /-- Canonical algebra embedding from the `n`th step to the algebraic closure. -/ def of_step_hom (n) : step k n →ₐ[k] algebraic_closure k := { commutes' := Ξ» x, ring.direct_limit.of_f n.zero_le x, .. of_step k n } theorem is_algebraic : algebra.is_algebraic k (algebraic_closure k) := Ξ» z, is_algebraic_iff_is_integral.2 $ let ⟨n, x, hx⟩ := exists_of_step k z in hx β–Έ is_integral_alg_hom (of_step_hom k n) (step.is_integral k n x) instance : is_alg_closure k (algebraic_closure k) := ⟨algebraic_closure.is_alg_closed k, is_algebraic k⟩ end algebraic_closure
27c99454cecb4a88d81f6d01d5c1d9a6652859d9
58840d1f4c8fba0ed6eb3a08b3c7491e28e2a4a2
/SGDT/later.lean
a49964c6d36241a5eff9e9693919f9a8183d16c7
[]
no_license
jonsterling/lean4-sgdt
7ba9f2ff2a21981f1d6517b86be1bee76e8d426e
5858bfe96f2c5de8343c0f7befddd946ef6ce3e6
refs/heads/master
1,685,409,923,012
1,623,505,684,000
1,623,505,684,000
371,836,555
10
0
null
null
null
null
UTF-8
Lean
false
false
1,967
lean
import sgdt.prelude universes u v axiom ltr : Sort u -> Sort u prefix:100 "β–·" => ltr axiom next : {A : Sort u} β†’ A β†’ β–· A noncomputable instance : Pure ltr where pure := next section variable {A : Sort u} {B : Sort v} axiom ltr.seq : β–· (A β†’ B) β†’ β–· A β†’ β–· B infixl:60 "βŠ›" => ltr.seq noncomputable instance : Seq ltr where seq := ltr.seq noncomputable instance : Functor ltr where map f x := next f βŠ› x end namespace ltr variable {A B : Sort u} axiom fix : (β–· A β†’ A) β†’ A axiom lex : βˆ€ x y : A, β–· (x = y) = (next x = next y) namespace fix axiom red : {f : β–· A β†’ A} β†’ fix f = f (next (fix f)) variable {F : β–· Sort u β†’ Sort u} def intro : F (next (fix F)) β†’ fix F := by intro x rw [← @red _ F] at x exact x def elim : fix F β†’ F (next (fix F)) := by intro x rw [← @red _ F] exact x @[simp] def beta (x : F (next (fix F))) : elim (intro x) = x := by simp [intro,elim] @[simp] def eta (x : fix F) : intro (elim x) = x := by simp [intro,elim] end fix @[simp] axiom seq.red : βˆ€ {f : (A β†’ B)} {x : A}, next f βŠ› next x = next (f x) end ltr class flasque (A : Type u) : Prop where next_surj : βˆ€ x : β–· A, βˆƒ y : A, x = pure y axiom exists_ltr {A : Type u} [flasque A] [Nonempty A] {P : A β†’ Prop} : (β–· βˆƒ x : A, P x) β†’ βˆƒ x : A, β–· P x axiom Nat_next_surj : βˆ€ x : β–· Nat, βˆƒ y : Nat, x = pure y instance : flasque Nat where next_surj := Nat_next_surj axiom dltr : β–· Sort u -> Sort u prefix:100 "[β–·]" => dltr @[simp] axiom dltr.red : {A : Sort u} β†’ [β–·] next A = β–· A macro "fix " p:term " => " d:term : term => `(ltr.fix fun $p:term => $d:term) axiom forall_ltr {A : Type u} {P : A β†’ Prop} : (β–· βˆ€ x : A, P x) β†’ βˆ€ x : β–· A, [β–·] (next P βŠ› x) axiom forall_ltr2 {A : Type u} {P : A β†’ A β†’ Prop} : (β–· βˆ€ x y : A, P x y) β†’ βˆ€ x y : β–· A, [β–·] (next P βŠ› x βŠ› y)
3a8d66aa00bd62c9ec5d0171baaade6bfe0280e3
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/traceElabIssue.lean
2ddc8a5cadd8a6f8bcf743bdf7629b7df139cadf
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
178
lean
set_option trace.Elab true inductive Vec (Ξ± : Type u) : Nat β†’ Type u | nil : Vec Ξ± Nat.zero | cons {n : Nat} : (head : Ξ±) β†’ (tail : Vec Ξ± n) β†’ Vec Ξ± (Nat.succ n)
04571ae644b0058c0f338e0d2407430e89b842ad
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/matrix/pequiv.lean
5aa86acc0a02bd7f689b6a1965045cd92b0b44c5
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
6,479
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.matrix.basic import data.pequiv /-! # partial equivalences for matrices > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Using partial equivalences to represent matrices. This file introduces the function `pequiv.to_matrix`, which returns a matrix containing ones and zeros. For any partial equivalence `f`, `f.to_matrix i j = 1 ↔ f i = some j`. The following important properties of this function are proved `to_matrix_trans : (f.trans g).to_matrix = f.to_matrix ⬝ g.to_matrix` `to_matrix_symm : f.symm.to_matrix = f.to_matrixα΅€` `to_matrix_refl : (pequiv.refl n).to_matrix = 1` `to_matrix_bot : βŠ₯.to_matrix = 0` This theory gives the matrix representation of projection linear maps, and their right inverses. For example, the matrix `(single (0 : fin 1) (i : fin n)).to_matrix` corresponds to the ith projection map from R^n to R. Any injective function `fin m β†’ fin n` gives rise to a `pequiv`, whose matrix is the projection map from R^m β†’ R^n represented by the same function. The transpose of this matrix is the right inverse of this map, sending anything not in the image to zero. ## notations This file uses the notation ` ⬝ ` for `matrix.mul` and `α΅€` for `matrix.transpose`. -/ namespace pequiv open matrix universes u v variables {k l m n : Type*} variables {Ξ± : Type v} open_locale matrix /-- `to_matrix` returns a matrix containing ones and zeros. `f.to_matrix i j` is `1` if `f i = some j` and `0` otherwise -/ def to_matrix [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (f : m ≃. n) : matrix m n Ξ± := of $ Ξ» i j, if j ∈ f i then (1 : Ξ±) else 0 -- TODO: set as an equation lemma for `to_matrix`, see mathlib4#3024 @[simp] lemma to_matrix_apply [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (f : m ≃. n) (i j) : to_matrix f i j = if j ∈ f i then (1 : Ξ±) else 0 := rfl lemma mul_matrix_apply [fintype m] [decidable_eq m] [semiring Ξ±] (f : l ≃. m) (M : matrix m n Ξ±) (i j) : (f.to_matrix ⬝ M) i j = option.cases_on (f i) 0 (Ξ» fi, M fi j) := begin dsimp [to_matrix, matrix.mul_apply], cases h : f i with fi, { simp [h] }, { rw finset.sum_eq_single fi; simp [h, eq_comm] {contextual := tt} } end lemma to_matrix_symm [decidable_eq m] [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (f : m ≃. n) : (f.symm.to_matrix : matrix n m Ξ±) = f.to_matrixα΅€ := by ext; simp only [transpose, mem_iff_mem f, to_matrix_apply]; congr @[simp] lemma to_matrix_refl [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] : ((pequiv.refl n).to_matrix : matrix n n Ξ±) = 1 := by ext; simp [to_matrix_apply, one_apply]; congr lemma matrix_mul_apply [fintype m] [semiring Ξ±] [decidable_eq n] (M : matrix l m Ξ±) (f : m ≃. n) (i j) : (M ⬝ f.to_matrix) i j = option.cases_on (f.symm j) 0 (Ξ» fj, M i fj) := begin dsimp [to_matrix, matrix.mul_apply], cases h : f.symm j with fj, { simp [h, ← f.eq_some_iff] }, { rw finset.sum_eq_single fj, { simp [h, ← f.eq_some_iff], }, { intros b H n, simp [h, ← f.eq_some_iff, n.symm], }, { simp, } } end lemma to_pequiv_mul_matrix [fintype m] [decidable_eq m] [semiring Ξ±] (f : m ≃ m) (M : matrix m n Ξ±) : (f.to_pequiv.to_matrix ⬝ M) = Ξ» i, M (f i) := by { ext i j, rw [mul_matrix_apply, equiv.to_pequiv_apply] } lemma mul_to_pequiv_to_matrix {m n Ξ± : Type*} [fintype n] [decidable_eq n] [semiring Ξ±] (f : n ≃ n) (M : matrix m n Ξ±) : (M ⬝ f.to_pequiv.to_matrix) = M.submatrix id (f.symm) := matrix.ext $ Ξ» i j, by rw [pequiv.matrix_mul_apply, ←equiv.to_pequiv_symm, equiv.to_pequiv_apply, matrix.submatrix_apply, id.def] lemma to_matrix_trans [fintype m] [decidable_eq m] [decidable_eq n] [semiring Ξ±] (f : l ≃. m) (g : m ≃. n) : ((f.trans g).to_matrix : matrix l n Ξ±) = f.to_matrix ⬝ g.to_matrix := begin ext i j, rw [mul_matrix_apply], dsimp [to_matrix, pequiv.trans], cases f i; simp end @[simp] lemma to_matrix_bot [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] : ((βŠ₯ : pequiv m n).to_matrix : matrix m n Ξ±) = 0 := rfl lemma to_matrix_injective [decidable_eq n] [monoid_with_zero Ξ±] [nontrivial Ξ±] : function.injective (@to_matrix m n Ξ± _ _ _) := begin classical, assume f g, refine not_imp_not.1 _, simp only [matrix.ext_iff.symm, to_matrix_apply, pequiv.ext_iff, not_forall, exists_imp_distrib], assume i hi, use i, cases hf : f i with fi, { cases hg : g i with gi, { cc }, { use gi, simp, } }, { use fi, simp [hf.symm, ne.symm hi] } end lemma to_matrix_swap [decidable_eq n] [ring Ξ±] (i j : n) : (equiv.swap i j).to_pequiv.to_matrix = (1 : matrix n n Ξ±) - (single i i).to_matrix - (single j j).to_matrix + (single i j).to_matrix + (single j i).to_matrix := begin ext, dsimp [to_matrix, single, equiv.swap_apply_def, equiv.to_pequiv, one_apply], split_ifs; {simp * at *} <|> { exfalso, assumption }, end @[simp] lemma single_mul_single [fintype n] [decidable_eq k] [decidable_eq m] [decidable_eq n] [semiring Ξ±] (a : m) (b : n) (c : k) : ((single a b).to_matrix : matrix _ _ Ξ±) ⬝ (single b c).to_matrix = (single a c).to_matrix := by rw [← to_matrix_trans, single_trans_single] lemma single_mul_single_of_ne [fintype n] [decidable_eq n] [decidable_eq k] [decidable_eq m] [semiring Ξ±] {b₁ bβ‚‚ : n} (hb : b₁ β‰  bβ‚‚) (a : m) (c : k) : ((single a b₁).to_matrix : matrix _ _ Ξ±) ⬝ (single bβ‚‚ c).to_matrix = 0 := by rw [← to_matrix_trans, single_trans_single_of_ne hb, to_matrix_bot] /-- Restatement of `single_mul_single`, which will simplify expressions in `simp` normal form, when associativity may otherwise need to be carefully applied. -/ @[simp] lemma single_mul_single_right [fintype n] [fintype k] [decidable_eq n] [decidable_eq k] [decidable_eq m] [semiring Ξ±] (a : m) (b : n) (c : k) (M : matrix k l Ξ±) : (single a b).to_matrix ⬝ ((single b c).to_matrix ⬝ M) = (single a c).to_matrix ⬝ M := by rw [← matrix.mul_assoc, single_mul_single] /-- We can also define permutation matrices by permuting the rows of the identity matrix. -/ lemma equiv_to_pequiv_to_matrix [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (Οƒ : equiv n n) (i j : n) : Οƒ.to_pequiv.to_matrix i j = (1 : matrix n n Ξ±) (Οƒ i) j := if_congr option.some_inj rfl rfl end pequiv
abd88962efed590d940093b8571d5454c13336bd
4e0d7c3132ce31edc5829849735dd25db406b144
/lean/love09_hoare_logic_exercise_sheet.lean
a2671415e8da1f11f20360ea1c4b2445b0a185c5
[]
no_license
gonzalgu/logical_verification_2020
a0013a6c22ea254e9f4d245f2948f0f4d44df4bb
724d0457dff2c3ff10f9ab2170388f4c5e958b75
refs/heads/master
1,660,886,374,533
1,589,859,641,000
1,589,859,641,000
256,069,971
0
0
null
1,586,997,430,000
1,586,997,429,000
null
UTF-8
Lean
false
false
6,164
lean
import .love09_hoare_logic_demo /-! # LoVe Exercise 9: Hoare Logic -/ set_option pp.beta true namespace LoVe /-! ## Question 1: Program Verification The following WHILE program is intended to compute the Gaussian sum up to `n`, leaving the result in `r`. -/ def GAUSS : stmt := stmt.assign "r" (Ξ»s, 0) ;; stmt.while (Ξ»s, s "n" β‰  0) (stmt.assign "r" (Ξ»s, s "r" + s "n") ;; stmt.assign "n" (Ξ»s, s "n" - 1)) /-! The summation function: -/ def sum_upto : β„• β†’ β„• | 0 := 0 | (n + 1) := n + 1 + sum_upto n #eval list.map sum_upto [5,4,3,2,1,0] /- r = 0, n = 5, i=0, sum_upto 0 = 0 r = 5, n = 4, i=1, sum_upto 1 = 1 r = 9, n = 3, i=2, sum_upto 2 = 3 r = 12, n = 2,i=3, sum_upto 3 = 6 r = 14, n = 1,i=4, sum_upto 4 = 10 r = 15, n = 0.i=5, sum_upto 5 = 15 -/ /-! 1.1. Prove the correctness of `GAUSS` using `vcg`. The main challenge is to figure out which invariant to use for the while loop. The invariant should capture both the work that has been done already (the intermediate result) and the work that remains to be done. -/ lemma GAUSS_correct (nβ‚€ : β„•) : {* Ξ»s, s "n" = nβ‚€ *} GAUSS {* Ξ»s, s "r" = sum_upto nβ‚€ *} := begin sorry, end /-! 1.2. The following WHILE program is intended to compute the product of `n` and `m`, leaving the result in `r`. Prove its correctness using `vcg`. Hint: If a variable `x` does not change in a program, it might be useful to record this in the invariant, by adding a conjunct `s "x" = xβ‚€`. -/ def MUL : stmt := stmt.assign "r" (Ξ»s, 0) ;; stmt.while (Ξ»s, s "n" β‰  0) (stmt.assign "r" (Ξ»s, s "r" + s "m") ;; stmt.assign "n" (Ξ»s, s "n" - 1)) lemma MUL_correct (nβ‚€ mβ‚€ : β„•) : {* Ξ»s, s "n" = nβ‚€ ∧ s "m" = mβ‚€ *} MUL {* Ξ»s, s "r" = nβ‚€ * mβ‚€ *} := sorry /-! ## Question 2: Hoare Triples for Total Correctness -/ def total_hoare (P : state β†’ Prop) (S : stmt) (Q : state β†’ Prop) : Prop := βˆ€s, P s β†’ βˆƒt, (S, s) ⟹ t ∧ Q t notation `[* ` P : 1 ` *] ` S : 1 ` [* ` Q : 1 ` *]` := total_hoare P S Q namespace total_hoare /-! 2.1. Prove the consequence rule. -/ /- hEt : βˆƒ (t : state), (S, s) ⟹ t ∧ Q t, t0 : state, hSand : (S, s) ⟹ t0 ∧ Q t0, (hEt t0).right -/ lemma consequence {P P' Q Q' : state β†’ Prop} {S} (hS : [* P *] S [* Q *]) (hP : βˆ€s, P' s β†’ P s) (hQ : βˆ€s, Q s β†’ Q' s) : [* P' *] S [* Q' *] := fix s, assume hP's : P' s, have hEt : βˆƒt, (S, s) ⟹ t ∧ Q t, from hS s (hP s hP's), match hEt with | ⟨t0,hSand⟩ := have hQ't0 : Q' t0, from hQ t0 (hSand.right), exists.intro t0 ⟨hSand.left, hQ't0⟩ end lemma tac_consequence {P P' Q Q' : state β†’ Prop} {S} (hS : [* P *] S [* Q *]) (hP : βˆ€s, P' s β†’ P s) (hQ : βˆ€s, Q s β†’ Q' s) : [* P' *] S [* Q' *] := begin intros s hP's, have hPs : P s := hP s hP's, have hex : βˆƒ (t : state), (S, s) ⟹ t ∧ Q t := hS s hPs, cases hex with t0 hand, have hQ' : Q' t0 := hQ t0 (hand.right), existsi t0, split, { exact hand.left, }, { exact hQ', } end /-! 2.2. Prove the rule for `skip`. -/ lemma skip_intro {P} : [* P *] stmt.skip [* P *] := begin intros s hPs, existsi s, split, { apply big_step.skip, }, { assumption, } end lemma fwd_skip_intro {P} : [* P *] stmt.skip [* P *] := fix s, assume hPs : P s , ⟨ s, ⟨ big_step.skip, hPs⟩ ⟩ /-! 2.3. Prove the rule for `assign`. -/ lemma assign_intro {P : state β†’ Prop} {x} {a : state β†’ β„•} : [* Ξ»s, P (s{x ↦ a s}) *] stmt.assign x a [* P *] := begin intros s hPs, existsi s{x ↦ a s}, split, { simp, }, { assumption, } end lemma fwd_assign_intro {P : state β†’ Prop} {x} {a : state β†’ β„•} : [* Ξ»s, P (s{x ↦ a s}) *] stmt.assign x a [* P *] := fix s, assume hPs : _, ⟨ s{x ↦ a s}, ⟨ big_step.assign, hPs ⟩ ⟩ /-! 2.4. Prove the rule for `seq`. -/ lemma seq_intro {P Q R S T} (hS : [* P *] S [* Q *]) (hT : [* Q *] T [* R *]) : [* P *] S ;; T [* R *] := begin intros s hPs, have hSQ : _ := hS s hPs, cases hSQ with r hSQr, have hTR : _ := hT r hSQr.right, cases hTR with t hTRt, existsi t, split, { apply big_step.seq hSQr.left hTRt.left, }, { exact hTRt.right, } end /-! 2.5. Complete the proof of the rule for `ite`. Hint: This requires a case distinction on the truth value of `b s`. -/ lemma ite_intro {b P Q : state β†’ Prop} {S T} (hS : [* Ξ»s, P s ∧ b s *] S [* Q *]) (hT : [* Ξ»s, P s ∧ Β¬ b s *] T [* Q *]) : [* P *] stmt.ite b S T [* Q *] := begin intros s hPs, cases classical.em (b s), { have hSQ : _ := hS s ⟨hPs, h⟩, cases hSQ with t hand, existsi t, split, { apply big_step.ite_true h hand.left, }, { exact hand.right, } }, { have hTQ : _ := hT s ⟨hPs, h⟩, cases hTQ with t hand, existsi t, split, { apply big_step.ite_false h hand.left, }, { exact hand.right, } } end /-! 2.6 (**optional**). Try to prove the rule for `while`. The rule is parameterized by a loop invariant `I` and by a variant `V` that decreases with each iteration of the loop body. Before we prove the desired lemma, we introduce an auxiliary lemma. Its proof requires well-founded induction. When using `while_intro.aux` as induction hypothesis we recommend to do it directly after proving that the argument is less than `vβ‚€`: have ih : βˆƒu, (stmt.while b S, t) ⟹ u ∧ I u ∧ Β¬ b u := have V t < vβ‚€ := …, while_intro.aux (V t) …, Similarly to `ite`, the proof requires a case distinction on `b s ∨ Β¬ b s`. -/ lemma while_intro.aux {b : state β†’ Prop} (I : state β†’ Prop) (V : state β†’ β„•) {S} (h_inv : βˆ€vβ‚€, [* Ξ»s, I s ∧ b s ∧ V s = vβ‚€ *] S [* Ξ»s, I s ∧ V s < vβ‚€ *]) : βˆ€vβ‚€ s, V s = vβ‚€ β†’ I s β†’ βˆƒt, (stmt.while b S, s) ⟹ t ∧ I t ∧ Β¬ b t | vβ‚€ s V_eq hs := sorry lemma while_intro {b : state β†’ Prop} (I : state β†’ Prop) (V : state β†’ β„•) {S} (hinv : βˆ€vβ‚€, [* Ξ»s, I s ∧ b s ∧ V s = vβ‚€ *] S [* Ξ»s, I s ∧ V s < vβ‚€ *]) : [* I *] stmt.while b S [* Ξ»s, I s ∧ Β¬ b s *] := sorry end total_hoare end LoVe
9186f88757a8d9389928e47a22e8d5a5ce9ed46c
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/set/finite.lean
e74c0f821af56f035d28488e31014101af538b2d
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
33,552
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import data.fintype.basic /-! # Finite sets This file defines predicates `finite : set Ξ± β†’ Prop` and `infinite : set Ξ± β†’ Prop` and proves some basic facts about finite sets. -/ open set function universes u v w x variables {Ξ± : Type u} {Ξ² : Type v} {ΞΉ : Sort w} {Ξ³ : Type x} namespace set /-- A set is finite if the subtype is a fintype, i.e. there is a list that enumerates its members. -/ def finite (s : set Ξ±) : Prop := nonempty (fintype s) /-- A set is infinite if it is not finite. -/ def infinite (s : set Ξ±) : Prop := Β¬ finite s /-- The subtype corresponding to a finite set is a finite type. Note that because `finite` isn't a typeclass, this will not fire if it is made into an instance -/ noncomputable def finite.fintype {s : set Ξ±} (h : finite s) : fintype s := classical.choice h /-- Get a finset from a finite set -/ noncomputable def finite.to_finset {s : set Ξ±} (h : finite s) : finset Ξ± := @set.to_finset _ _ h.fintype @[simp] theorem finite.mem_to_finset {s : set Ξ±} (h : finite s) {a : Ξ±} : a ∈ h.to_finset ↔ a ∈ s := @mem_to_finset _ _ h.fintype _ @[simp] theorem finite.to_finset.nonempty {s : set Ξ±} (h : finite s) : h.to_finset.nonempty ↔ s.nonempty := show (βˆƒ x, x ∈ h.to_finset) ↔ (βˆƒ x, x ∈ s), from exists_congr (Ξ» _, h.mem_to_finset) @[simp] lemma finite.coe_to_finset {s : set Ξ±} (h : finite s) : ↑h.to_finset = s := @set.coe_to_finset _ s h.fintype @[simp] lemma finite.coe_sort_to_finset {s : set Ξ±} (h : finite s) : (h.to_finset : Type*) = s := by rw [← finset.coe_sort_coe _, h.coe_to_finset] @[simp] lemma finite_empty_to_finset (h : finite (βˆ… : set Ξ±)) : h.to_finset = βˆ… := by rw [← finset.coe_inj, h.coe_to_finset, finset.coe_empty] @[simp] lemma finite.to_finset_inj {s t : set Ξ±} {hs : finite s} {ht : finite t} : hs.to_finset = ht.to_finset ↔ s = t := by simp [←finset.coe_inj] @[simp] lemma finite_to_finset_eq_empty_iff {s : set Ξ±} {h : finite s} : h.to_finset = βˆ… ↔ s = βˆ… := by simp [←finset.coe_inj] theorem finite.exists_finset {s : set Ξ±} : finite s β†’ βˆƒ s' : finset Ξ±, βˆ€ a : Ξ±, a ∈ s' ↔ a ∈ s | ⟨h⟩ := by exactI ⟨to_finset s, Ξ» _, mem_to_finset⟩ theorem finite.exists_finset_coe {s : set Ξ±} (hs : finite s) : βˆƒ s' : finset Ξ±, ↑s' = s := ⟨hs.to_finset, hs.coe_to_finset⟩ /-- Finite sets can be lifted to finsets. -/ instance : can_lift (set Ξ±) (finset Ξ±) := { coe := coe, cond := finite, prf := Ξ» s hs, hs.exists_finset_coe } theorem finite_mem_finset (s : finset Ξ±) : finite {a | a ∈ s} := ⟨fintype.of_finset s (Ξ» _, iff.rfl)⟩ theorem finite.of_fintype [fintype Ξ±] (s : set Ξ±) : finite s := by classical; exact ⟨set_fintype s⟩ theorem exists_finite_iff_finset {p : set Ξ± β†’ Prop} : (βˆƒ s, finite s ∧ p s) ↔ βˆƒ s : finset Ξ±, p ↑s := ⟨λ ⟨s, hs, hps⟩, ⟨hs.to_finset, hs.coe_to_finset.symm β–Έ hps⟩, Ξ» ⟨s, hs⟩, βŸ¨β†‘s, finite_mem_finset s, hs⟩⟩ lemma finite.fin_embedding {s : set Ξ±} (h : finite s) : βˆƒ (n : β„•) (f : fin n β†ͺ Ξ±), range f = s := ⟨_, (fintype.equiv_fin (h.to_finset : set Ξ±)).symm.as_embedding, by simp⟩ lemma finite.fin_param {s : set Ξ±} (h : finite s) : βˆƒ (n : β„•) (f : fin n β†’ Ξ±), injective f ∧ range f = s := let ⟨n, f, hf⟩ := h.fin_embedding in ⟨n, f, f.injective, hf⟩ /-- Membership of a subset of a finite type is decidable. Using this as an instance leads to potential loops with `subtype.fintype` under certain decidability assumptions, so it should only be declared a local instance. -/ def decidable_mem_of_fintype [decidable_eq Ξ±] (s : set Ξ±) [fintype s] (a) : decidable (a ∈ s) := decidable_of_iff _ mem_to_finset instance fintype_empty : fintype (βˆ… : set Ξ±) := fintype.of_finset βˆ… $ by simp theorem empty_card : fintype.card (βˆ… : set Ξ±) = 0 := rfl @[simp] theorem empty_card' {h : fintype.{u} (βˆ… : set Ξ±)} : @fintype.card (βˆ… : set Ξ±) h = 0 := eq.trans (by congr) empty_card @[simp] theorem finite_empty : @finite Ξ± βˆ… := ⟨set.fintype_empty⟩ instance finite.inhabited : inhabited {s : set Ξ± // finite s} := βŸ¨βŸ¨βˆ…, finite_empty⟩⟩ /-- A `fintype` structure on `insert a s`. -/ def fintype_insert' {a : Ξ±} (s : set Ξ±) [fintype s] (h : a βˆ‰ s) : fintype (insert a s : set Ξ±) := fintype.of_finset ⟨a ::β‚˜ s.to_finset.1, multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2⟩ $ by simp theorem card_fintype_insert' {a : Ξ±} (s : set Ξ±) [fintype s] (h : a βˆ‰ s) : @fintype.card _ (fintype_insert' s h) = fintype.card s + 1 := by rw [fintype_insert', fintype.card_of_finset]; simp [finset.card, to_finset]; refl @[simp] theorem card_insert {a : Ξ±} (s : set Ξ±) [fintype s] (h : a βˆ‰ s) {d : fintype.{u} (insert a s : set Ξ±)} : @fintype.card _ d = fintype.card s + 1 := by rw ← card_fintype_insert' s h; congr lemma card_image_of_inj_on {s : set Ξ±} [fintype s] {f : Ξ± β†’ Ξ²} [fintype (f '' s)] (H : βˆ€x∈s, βˆ€y∈s, f x = f y β†’ x = y) : fintype.card (f '' s) = fintype.card s := by haveI := classical.prop_decidable; exact calc fintype.card (f '' s) = (s.to_finset.image f).card : fintype.card_of_finset' _ (by simp) ... = s.to_finset.card : finset.card_image_of_inj_on (Ξ» x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy) ... = fintype.card s : (fintype.card_of_finset' _ (Ξ» a, mem_to_finset)).symm lemma card_image_of_injective (s : set Ξ±) [fintype s] {f : Ξ± β†’ Ξ²} [fintype (f '' s)] (H : function.injective f) : fintype.card (f '' s) = fintype.card s := card_image_of_inj_on $ Ξ» _ _ _ _ h, H h section local attribute [instance] decidable_mem_of_fintype instance fintype_insert [decidable_eq Ξ±] (a : Ξ±) (s : set Ξ±) [fintype s] : fintype (insert a s : set Ξ±) := if h : a ∈ s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)] else fintype_insert' _ h end @[simp] theorem finite.insert (a : Ξ±) {s : set Ξ±} : finite s β†’ finite (insert a s) | ⟨h⟩ := ⟨@set.fintype_insert _ (classical.dec_eq Ξ±) _ _ h⟩ lemma to_finset_insert [decidable_eq Ξ±] {a : Ξ±} {s : set Ξ±} (hs : finite s) : (hs.insert a).to_finset = insert a hs.to_finset := finset.ext $ by simp @[simp] lemma insert_to_finset [decidable_eq Ξ±] {a : Ξ±} {s : set Ξ±} [fintype s] : (insert a s).to_finset = insert a s.to_finset := by simp [finset.ext_iff, mem_insert_iff] @[elab_as_eliminator] theorem finite.induction_on {C : set Ξ± β†’ Prop} {s : set Ξ±} (h : finite s) (H0 : C βˆ…) (H1 : βˆ€ {a s}, a βˆ‰ s β†’ finite s β†’ C s β†’ C (insert a s)) : C s := let ⟨t⟩ := h in by exactI match s.to_finset, @mem_to_finset _ s _ with | ⟨l, nd⟩, al := begin change βˆ€ a, a ∈ l ↔ a ∈ s at al, clear _let_match _match t h, revert s nd al, refine multiset.induction_on l _ (Ξ» a l IH, _); intros s nd al, { rw show s = βˆ…, from eq_empty_iff_forall_not_mem.2 (by simpa using al), exact H0 }, { rw ← show insert a {x | x ∈ l} = s, from set.ext (by simpa using al), cases multiset.nodup_cons.1 nd with m nd', refine H1 _ ⟨finset.subtype.fintype ⟨l, nd'⟩⟩ (IH nd' (Ξ» _, iff.rfl)), exact m } end end @[elab_as_eliminator] theorem finite.dinduction_on {C : βˆ€s:set Ξ±, finite s β†’ Prop} {s : set Ξ±} (h : finite s) (H0 : C βˆ… finite_empty) (H1 : βˆ€ {a s}, a βˆ‰ s β†’ βˆ€h:finite s, C s h β†’ C (insert a s) (h.insert a)) : C s h := have βˆ€h:finite s, C s h, from finite.induction_on h (assume h, H0) (assume a s has hs ih h, H1 has hs (ih _)), this h instance fintype_singleton (a : Ξ±) : fintype ({a} : set Ξ±) := unique.fintype @[simp] theorem card_singleton (a : Ξ±) : fintype.card ({a} : set Ξ±) = 1 := fintype.card_of_subsingleton _ @[simp] theorem finite_singleton (a : Ξ±) : finite ({a} : set Ξ±) := ⟨set.fintype_singleton _⟩ lemma subsingleton.finite {s : set Ξ±} (h : s.subsingleton) : finite s := h.induction_on finite_empty finite_singleton instance fintype_pure : βˆ€ a : Ξ±, fintype (pure a : set Ξ±) := set.fintype_singleton theorem finite_pure (a : Ξ±) : finite (pure a : set Ξ±) := ⟨set.fintype_pure a⟩ instance fintype_univ [fintype Ξ±] : fintype (@univ Ξ±) := fintype.of_equiv Ξ± $ (equiv.set.univ Ξ±).symm theorem finite_univ [fintype Ξ±] : finite (@univ Ξ±) := ⟨set.fintype_univ⟩ /-- If `(set.univ : set Ξ±)` is finite then `Ξ±` is a finite type. -/ noncomputable def fintype_of_univ_finite (H : (univ : set Ξ±).finite ) : fintype Ξ± := @fintype.of_equiv _ (univ : set Ξ±) H.fintype (equiv.set.univ _) lemma univ_finite_iff_nonempty_fintype : (univ : set Ξ±).finite ↔ nonempty (fintype Ξ±) := begin split, { intro h, exact ⟨fintype_of_univ_finite h⟩ }, { rintro ⟨_i⟩, exactI finite_univ } end theorem infinite_univ_iff : (@univ Ξ±).infinite ↔ _root_.infinite Ξ± := ⟨λ h₁, ⟨λ hβ‚‚, h₁ $ @finite_univ Ξ± hβ‚‚βŸ©, Ξ» ⟨hβ‚βŸ© hβ‚‚, h₁ (fintype_of_univ_finite hβ‚‚)⟩ theorem infinite_univ [h : _root_.infinite Ξ±] : infinite (@univ Ξ±) := infinite_univ_iff.2 h theorem infinite_coe_iff {s : set Ξ±} : _root_.infinite s ↔ infinite s := ⟨λ ⟨hβ‚βŸ© hβ‚‚, h₁ hβ‚‚.some, Ξ» h₁, ⟨λ hβ‚‚, h₁ ⟨hβ‚‚βŸ©βŸ©βŸ© theorem infinite.to_subtype {s : set Ξ±} (h : infinite s) : _root_.infinite s := infinite_coe_iff.2 h /-- Embedding of `β„•` into an infinite set. -/ noncomputable def infinite.nat_embedding (s : set Ξ±) (h : infinite s) : β„• β†ͺ s := by { haveI := h.to_subtype, exact infinite.nat_embedding s } lemma infinite.exists_subset_card_eq {s : set Ξ±} (hs : infinite s) (n : β„•) : βˆƒ t : finset Ξ±, ↑t βŠ† s ∧ t.card = n := ⟨((finset.range n).map (hs.nat_embedding _)).map (embedding.subtype _), by simp⟩ lemma infinite.nonempty {s : set Ξ±} (h : s.infinite) : s.nonempty := let a := infinite.nat_embedding s h 37 in ⟨a.1, a.2⟩ instance fintype_union [decidable_eq Ξ±] (s t : set Ξ±) [fintype s] [fintype t] : fintype (s βˆͺ t : set Ξ±) := fintype.of_finset (s.to_finset βˆͺ t.to_finset) $ by simp theorem finite.union {s t : set Ξ±} : finite s β†’ finite t β†’ finite (s βˆͺ t) | ⟨hs⟩ ⟨ht⟩ := ⟨@set.fintype_union _ (classical.dec_eq Ξ±) _ _ hs ht⟩ lemma finite.sup {s t : set Ξ±} : finite s β†’ finite t β†’ finite (s βŠ” t) := finite.union lemma infinite_of_finite_compl {Ξ± : Type} [_root_.infinite Ξ±] {s : set Ξ±} (hs : sᢜ.finite) : s.infinite := Ξ» h, set.infinite_univ (by simpa using hs.union h) lemma finite.infinite_compl {Ξ± : Type} [_root_.infinite Ξ±] {s : set Ξ±} (hs : s.finite) : sᢜ.infinite := Ξ» h, set.infinite_univ (by simpa using hs.union h) instance fintype_sep (s : set Ξ±) (p : Ξ± β†’ Prop) [fintype s] [decidable_pred p] : fintype ({a ∈ s | p a} : set Ξ±) := fintype.of_finset (s.to_finset.filter p) $ by simp instance fintype_inter (s t : set Ξ±) [fintype s] [decidable_pred t] : fintype (s ∩ t : set Ξ±) := set.fintype_sep s t /-- A `fintype` structure on a set defines a `fintype` structure on its subset. -/ def fintype_subset (s : set Ξ±) {t : set Ξ±} [fintype s] [decidable_pred t] (h : t βŠ† s) : fintype t := by rw ← inter_eq_self_of_subset_right h; apply_instance theorem finite.subset {s : set Ξ±} : finite s β†’ βˆ€ {t : set Ξ±}, t βŠ† s β†’ finite t | ⟨hs⟩ t h := ⟨@set.fintype_subset _ _ _ hs (classical.dec_pred t) h⟩ lemma finite.union_iff {s t : set Ξ±} : finite (s βˆͺ t) ↔ finite s ∧ finite t := ⟨λ h, ⟨h.subset (subset_union_left _ _), h.subset (subset_union_right _ _)⟩, Ξ» ⟨hs, ht⟩, hs.union ht⟩ lemma finite.diff {s t u : set Ξ±} (hs : s.finite) (ht : t.finite) (h : u \ t ≀ s) : u.finite := begin refine finite.subset (ht.union hs) _, exact diff_subset_iff.mp h end theorem finite.inter_of_left {s : set Ξ±} (h : finite s) (t : set Ξ±) : finite (s ∩ t) := h.subset (inter_subset_left _ _) theorem finite.inter_of_right {s : set Ξ±} (h : finite s) (t : set Ξ±) : finite (t ∩ s) := h.subset (inter_subset_right _ _) theorem finite.inf_of_left {s : set Ξ±} (h : finite s) (t : set Ξ±) : finite (s βŠ“ t) := h.inter_of_left t theorem finite.inf_of_right {s : set Ξ±} (h : finite s) (t : set Ξ±) : finite (t βŠ“ s) := h.inter_of_right t theorem infinite_mono {s t : set Ξ±} (h : s βŠ† t) : infinite s β†’ infinite t := mt (Ξ» ht, ht.subset h) instance fintype_image [decidable_eq Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) [fintype s] : fintype (f '' s) := fintype.of_finset (s.to_finset.image f) $ by simp instance fintype_range [decidable_eq Ξ²] (f : Ξ± β†’ Ξ²) [fintype Ξ±] : fintype (range f) := fintype.of_finset (finset.univ.image f) $ by simp [range] theorem finite_range (f : Ξ± β†’ Ξ²) [fintype Ξ±] : finite (range f) := by haveI := classical.dec_eq Ξ²; exact ⟨by apply_instance⟩ theorem finite.image {s : set Ξ±} (f : Ξ± β†’ Ξ²) : finite s β†’ finite (f '' s) | ⟨h⟩ := ⟨@set.fintype_image _ _ (classical.dec_eq Ξ²) _ _ h⟩ theorem infinite_of_infinite_image (f : Ξ± β†’ Ξ²) {s : set Ξ±} (hs : (f '' s).infinite) : s.infinite := mt (finite.image f) hs lemma finite.dependent_image {s : set Ξ±} (hs : finite s) (F : Ξ  i ∈ s, Ξ²) : finite {y : Ξ² | βˆƒ x (hx : x ∈ s), y = F x hx} := begin letI : fintype s := hs.fintype, convert finite_range (Ξ» x : s, F x x.2), simp only [set_coe.exists, subtype.coe_mk, eq_comm], end theorem finite.of_preimage {f : Ξ± β†’ Ξ²} {s : set Ξ²} (h : finite (f ⁻¹' s)) (hf : surjective f) : finite s := hf.image_preimage s β–Έ h.image _ instance fintype_map {Ξ± Ξ²} [decidable_eq Ξ²] : βˆ€ (s : set Ξ±) (f : Ξ± β†’ Ξ²) [fintype s], fintype (f <$> s) := set.fintype_image theorem finite.map {Ξ± Ξ²} {s : set Ξ±} : βˆ€ (f : Ξ± β†’ Ξ²), finite s β†’ finite (f <$> s) := finite.image /-- If a function `f` has a partial inverse and sends a set `s` to a set with `[fintype]` instance, then `s` has a `fintype` structure as well. -/ def fintype_of_fintype_image (s : set Ξ±) {f : Ξ± β†’ Ξ²} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s := fintype.of_finset ⟨_, @multiset.nodup_filter_map Ξ² Ξ± g _ (@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2⟩ $ Ξ» a, begin suffices : (βˆƒ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s, by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc], rw exists_swap, suffices : (βˆƒ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s, {simpa [and.comm, and.left_comm, and.assoc]}, simp [I _, (injective_of_partial_inv I).eq_iff] end theorem finite_of_finite_image {s : set Ξ±} {f : Ξ± β†’ Ξ²} (hi : set.inj_on f s) : finite (f '' s) β†’ finite s | ⟨h⟩ := ⟨@fintype.of_injective _ _ h (Ξ»a:s, ⟨f a.1, mem_image_of_mem f a.2⟩) $ assume a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext_iff_val.1 eq⟩ theorem finite_image_iff {s : set Ξ±} {f : Ξ± β†’ Ξ²} (hi : inj_on f s) : finite (f '' s) ↔ finite s := ⟨finite_of_finite_image hi, finite.image _⟩ theorem infinite_image_iff {s : set Ξ±} {f : Ξ± β†’ Ξ²} (hi : inj_on f s) : infinite (f '' s) ↔ infinite s := not_congr $ finite_image_iff hi theorem infinite_of_inj_on_maps_to {s : set Ξ±} {t : set Ξ²} {f : Ξ± β†’ Ξ²} (hi : inj_on f s) (hm : maps_to f s t) (hs : infinite s) : infinite t := infinite_mono (maps_to'.mp hm) $ (infinite_image_iff hi).2 hs theorem infinite.exists_ne_map_eq_of_maps_to {s : set Ξ±} {t : set Ξ²} {f : Ξ± β†’ Ξ²} (hs : infinite s) (hf : maps_to f s t) (ht : finite t) : βˆƒ (x ∈ s) (y ∈ s), x β‰  y ∧ f x = f y := begin unfreezingI { contrapose! ht }, exact infinite_of_inj_on_maps_to (Ξ» x hx y hy, not_imp_not.1 (ht x hx y hy)) hf hs end theorem infinite.exists_lt_map_eq_of_maps_to [linear_order Ξ±] {s : set Ξ±} {t : set Ξ²} {f : Ξ± β†’ Ξ²} (hs : infinite s) (hf : maps_to f s t) (ht : finite t) : βˆƒ (x ∈ s) (y ∈ s), x < y ∧ f x = f y := let ⟨x, hx, y, hy, hxy, hf⟩ := hs.exists_ne_map_eq_of_maps_to hf ht in hxy.lt_or_lt.elim (Ξ» hxy, ⟨x, hx, y, hy, hxy, hf⟩) (Ξ» hyx, ⟨y, hy, x, hx, hyx, hf.symm⟩) theorem infinite_range_of_injective [_root_.infinite Ξ±] {f : Ξ± β†’ Ξ²} (hi : injective f) : infinite (range f) := by { rw [←image_univ, infinite_image_iff (inj_on_of_injective hi _)], exact infinite_univ } theorem infinite_of_injective_forall_mem [_root_.infinite Ξ±] {s : set Ξ²} {f : Ξ± β†’ Ξ²} (hi : injective f) (hf : βˆ€ x : Ξ±, f x ∈ s) : infinite s := by { rw ←range_subset_iff at hf, exact infinite_mono hf (infinite_range_of_injective hi) } theorem finite.preimage {s : set Ξ²} {f : Ξ± β†’ Ξ²} (I : set.inj_on f (f⁻¹' s)) (h : finite s) : finite (f ⁻¹' s) := finite_of_finite_image I (h.subset (image_preimage_subset f s)) theorem finite.preimage_embedding {s : set Ξ²} (f : Ξ± β†ͺ Ξ²) (h : s.finite) : (f ⁻¹' s).finite := finite.preimage (Ξ» _ _ _ _ h', f.injective h') h lemma finite_option {s : set (option Ξ±)} : finite s ↔ finite {x : Ξ± | some x ∈ s} := ⟨λ h, h.preimage_embedding embedding.some, Ξ» h, ((h.image some).insert none).subset $ Ξ» x, option.cases_on x (Ξ» _, or.inl rfl) (Ξ» x hx, or.inr $ mem_image_of_mem _ hx)⟩ instance fintype_Union [decidable_eq Ξ±] {ΞΉ : Type*} [fintype ΞΉ] (f : ΞΉ β†’ set Ξ±) [βˆ€ i, fintype (f i)] : fintype (⋃ i, f i) := fintype.of_finset (finset.univ.bUnion (Ξ» i, (f i).to_finset)) $ by simp theorem finite_Union {ΞΉ : Type*} [fintype ΞΉ] {f : ΞΉ β†’ set Ξ±} (H : βˆ€i, finite (f i)) : finite (⋃ i, f i) := ⟨@set.fintype_Union _ (classical.dec_eq Ξ±) _ _ _ (Ξ» i, finite.fintype (H i))⟩ /-- A union of sets with `fintype` structure over a set with `fintype` structure has a `fintype` structure. -/ def fintype_bUnion [decidable_eq Ξ±] {ΞΉ : Type*} {s : set ΞΉ} [fintype s] (f : ΞΉ β†’ set Ξ±) (H : βˆ€ i ∈ s, fintype (f i)) : fintype (⋃ i ∈ s, f i) := by rw bUnion_eq_Union; exact @set.fintype_Union _ _ _ _ _ (by rintro ⟨i, hi⟩; exact H i hi) instance fintype_bUnion' [decidable_eq Ξ±] {ΞΉ : Type*} {s : set ΞΉ} [fintype s] (f : ΞΉ β†’ set Ξ±) [H : βˆ€ i, fintype (f i)] : fintype (⋃ i ∈ s, f i) := fintype_bUnion _ (Ξ» i _, H i) theorem finite.sUnion {s : set (set Ξ±)} (h : finite s) (H : βˆ€t∈s, finite t) : finite (⋃₀ s) := by rw sUnion_eq_Union; haveI := finite.fintype h; apply finite_Union; simpa using H theorem finite.bUnion {Ξ±} {ΞΉ : Type*} {s : set ΞΉ} {f : Ξ  i ∈ s, set Ξ±} : finite s β†’ (βˆ€ i ∈ s, finite (f i β€Ή_β€Ί)) β†’ finite (⋃ i∈s, f i β€Ή_β€Ί) | ⟨hs⟩ h := by rw [bUnion_eq_Union]; exactI finite_Union (Ξ» i, h _ _) theorem finite_Union_Prop {p : Prop} {f : p β†’ set Ξ±} (hf : βˆ€ h, finite (f h)) : finite (⋃ h : p, f h) := by by_cases p; simp * instance fintype_lt_nat (n : β„•) : fintype {i | i < n} := fintype.of_finset (finset.range n) $ by simp instance fintype_le_nat (n : β„•) : fintype {i | i ≀ n} := by simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1) lemma finite_le_nat (n : β„•) : finite {i | i ≀ n} := ⟨set.fintype_le_nat _⟩ lemma finite_lt_nat (n : β„•) : finite {i | i < n} := ⟨set.fintype_lt_nat _⟩ instance fintype_prod (s : set Ξ±) (t : set Ξ²) [fintype s] [fintype t] : fintype (set.prod s t) := fintype.of_finset (s.to_finset.product t.to_finset) $ by simp lemma finite.prod {s : set Ξ±} {t : set Ξ²} : finite s β†’ finite t β†’ finite (set.prod s t) | ⟨hs⟩ ⟨ht⟩ := by exactI ⟨set.fintype_prod s t⟩ /-- `image2 f s t` is finitype if `s` and `t` are. -/ instance fintype_image2 [decidable_eq Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (s : set Ξ±) (t : set Ξ²) [hs : fintype s] [ht : fintype t] : fintype (image2 f s t : set Ξ³) := by { rw ← image_prod, apply set.fintype_image } lemma finite.image2 (f : Ξ± β†’ Ξ² β†’ Ξ³) {s : set Ξ±} {t : set Ξ²} (hs : finite s) (ht : finite t) : finite (image2 f s t) := by { rw ← image_prod, exact (hs.prod ht).image _ } /-- If `s : set Ξ±` is a set with `fintype` instance and `f : Ξ± β†’ set Ξ²` is a function such that each `f a`, `a ∈ s`, has a `fintype` structure, then `s >>= f` has a `fintype` structure. -/ def fintype_bind {Ξ± Ξ²} [decidable_eq Ξ²] (s : set Ξ±) [fintype s] (f : Ξ± β†’ set Ξ²) (H : βˆ€ a ∈ s, fintype (f a)) : fintype (s >>= f) := set.fintype_bUnion _ H instance fintype_bind' {Ξ± Ξ²} [decidable_eq Ξ²] (s : set Ξ±) [fintype s] (f : Ξ± β†’ set Ξ²) [H : βˆ€ a, fintype (f a)] : fintype (s >>= f) := fintype_bind _ _ (Ξ» i _, H i) theorem finite.bind {Ξ± Ξ²} {s : set Ξ±} {f : Ξ± β†’ set Ξ²} (h : finite s) (hf : βˆ€ a ∈ s, finite (f a)) : finite (s >>= f) := h.bUnion hf instance fintype_seq [decidable_eq Ξ²] (f : set (Ξ± β†’ Ξ²)) (s : set Ξ±) [fintype f] [fintype s] : fintype (f.seq s) := by { rw seq_def, apply set.fintype_bUnion' } instance fintype_seq' {Ξ± Ξ² : Type u} [decidable_eq Ξ²] (f : set (Ξ± β†’ Ξ²)) (s : set Ξ±) [fintype f] [fintype s] : fintype (f <*> s) := set.fintype_seq f s theorem finite.seq {f : set (Ξ± β†’ Ξ²)} {s : set Ξ±} (hf : finite f) (hs : finite s) : finite (f.seq s) := by { rw seq_def, exact hf.bUnion (Ξ» f _, hs.image _) } theorem finite.seq' {Ξ± Ξ² : Type u} {f : set (Ξ± β†’ Ξ²)} {s : set Ξ±} (hf : finite f) (hs : finite s) : finite (f <*> s) := hf.seq hs /-- There are finitely many subsets of a given finite set -/ lemma finite.finite_subsets {Ξ± : Type u} {a : set Ξ±} (h : finite a) : finite {b | b βŠ† a} := begin -- we just need to translate the result, already known for finsets, -- to the language of finite sets let s : set (set Ξ±) := coe '' (↑(finset.powerset (finite.to_finset h)) : set (finset Ξ±)), have : finite s := (finite_mem_finset _).image _, apply this.subset, refine Ξ» b hb, ⟨(h.subset hb).to_finset, _, finite.coe_to_finset _⟩, simpa [finset.subset_iff] end lemma exists_min_image [linear_order Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) (h1 : finite s) : s.nonempty β†’ βˆƒ a ∈ s, βˆ€ b ∈ s, f a ≀ f b | ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset] using h1.to_finset.exists_min_image f ⟨x, h1.mem_to_finset.2 hx⟩ lemma exists_max_image [linear_order Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) (h1 : finite s) : s.nonempty β†’ βˆƒ a ∈ s, βˆ€ b ∈ s, f b ≀ f a | ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset] using h1.to_finset.exists_max_image f ⟨x, h1.mem_to_finset.2 hx⟩ theorem exists_lower_bound_image [hΞ± : nonempty Ξ±] [linear_order Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) (h : s.finite) : βˆƒ (a : Ξ±), βˆ€ b ∈ s, f a ≀ f b := begin by_cases hs : set.nonempty s, { exact let ⟨xβ‚€, H, hxβ‚€βŸ© := set.exists_min_image s f h hs in ⟨xβ‚€, Ξ» x hx, hxβ‚€ x hx⟩ }, { exact nonempty.elim hΞ± (Ξ» a, ⟨a, Ξ» x hx, absurd (set.nonempty_of_mem hx) hs⟩) } end theorem exists_upper_bound_image [hΞ± : nonempty Ξ±] [linear_order Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) (h : s.finite) : βˆƒ (a : Ξ±), βˆ€ b ∈ s, f b ≀ f a := begin by_cases hs : set.nonempty s, { exact let ⟨xβ‚€, H, hxβ‚€βŸ© := set.exists_max_image s f h hs in ⟨xβ‚€, Ξ» x hx, hxβ‚€ x hx⟩ }, { exact nonempty.elim hΞ± (Ξ» a, ⟨a, Ξ» x hx, absurd (set.nonempty_of_mem hx) hs⟩) } end end set namespace finset variables [decidable_eq Ξ²] variables {s : finset Ξ±} lemma finite_to_set (s : finset Ξ±) : set.finite (↑s : set Ξ±) := set.finite_mem_finset s @[simp] lemma coe_bUnion {f : Ξ± β†’ finset Ξ²} : ↑(s.bUnion f) = (⋃x ∈ (↑s : set Ξ±), ↑(f x) : set Ξ²) := by simp [set.ext_iff] @[simp] lemma finite_to_set_to_finset {Ξ± : Type*} (s : finset Ξ±) : (finite_to_set s).to_finset = s := by { ext, rw [set.finite.mem_to_finset, mem_coe] } end finset namespace set /-- Finite product of finite sets is finite -/ lemma finite.pi {Ξ΄ : Type*} [fintype Ξ΄] {ΞΊ : Ξ΄ β†’ Type*} {t : Ξ  d, set (ΞΊ d)} (ht : βˆ€ d, (t d).finite) : (pi univ t).finite := begin classical, convert (fintype.pi_finset (Ξ» d, (ht d).to_finset)).finite_to_set, ext, simp, end lemma finite_subset_Union {s : set Ξ±} (hs : finite s) {ΞΉ} {t : ΞΉ β†’ set Ξ±} (h : s βŠ† ⋃ i, t i) : βˆƒ I : set ΞΉ, finite I ∧ s βŠ† ⋃ i ∈ I, t i := begin casesI hs, choose f hf using show βˆ€ x : s, βˆƒ i, x.1 ∈ t i, {simpa [subset_def] using h}, refine ⟨range f, finite_range f, _⟩, rintro x hx, simp, exact ⟨x, ⟨hx, hf _⟩⟩, end lemma eq_finite_Union_of_finite_subset_Union {ΞΉ} {s : ΞΉ β†’ set Ξ±} {t : set Ξ±} (tfin : finite t) (h : t βŠ† ⋃ i, s i) : βˆƒ I : set ΞΉ, (finite I) ∧ βˆƒ Οƒ : {i | i ∈ I} β†’ set Ξ±, (βˆ€ i, finite (Οƒ i)) ∧ (βˆ€ i, Οƒ i βŠ† s i) ∧ t = ⋃ i, Οƒ i := let ⟨I, Ifin, hI⟩ := finite_subset_Union tfin h in ⟨I, Ifin, Ξ» x, s x ∩ t, Ξ» i, tfin.subset (inter_subset_right _ _), Ξ» i, inter_subset_left _ _, begin ext x, rw mem_Union, split, { intro x_in, rcases mem_Union.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩, use [i, hi, H, x_in] }, { rintros ⟨i, hi, H⟩, exact H } end⟩ /-- An increasing union distributes over finite intersection. -/ lemma Union_Inter_of_monotone {ΞΉ ΞΉ' Ξ± : Type*} [fintype ΞΉ] [linear_order ΞΉ'] [nonempty ΞΉ'] {s : ΞΉ β†’ ΞΉ' β†’ set Ξ±} (hs : βˆ€ i, monotone (s i)) : (⋃ j : ΞΉ', β‹‚ i : ΞΉ, s i j) = β‹‚ i : ΞΉ, ⋃ j : ΞΉ', s i j := begin ext x, refine ⟨λ hx, Union_Inter_subset hx, Ξ» hx, _⟩, simp only [mem_Inter, mem_Union, mem_Inter] at hx ⊒, choose j hj using hx, obtain ⟨jβ‚€βŸ© := show nonempty ΞΉ', by apply_instance, refine ⟨finset.univ.fold max jβ‚€ j, Ξ» i, hs i _ (hj i)⟩, rw [finset.fold_op_rel_iff_or (@le_max_iff _ _)], exact or.inr ⟨i, finset.mem_univ i, le_rfl⟩ end instance nat.fintype_Iio (n : β„•) : fintype (Iio n) := fintype.of_finset (finset.range n) $ by simp /-- If `P` is some relation between terms of `Ξ³` and sets in `Ξ³`, such that every finite set `t : set Ξ³` has some `c : Ξ³` related to it, then there is a recursively defined sequence `u` in `Ξ³` so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`. (We use this later to show sequentially compact sets are totally bounded.) -/ lemma seq_of_forall_finite_exists {Ξ³ : Type*} {P : Ξ³ β†’ set Ξ³ β†’ Prop} (h : βˆ€ t, finite t β†’ βˆƒ c, P c t) : βˆƒ u : β„• β†’ Ξ³, βˆ€ n, P (u n) (u '' Iio n) := ⟨λ n, @nat.strong_rec_on' (Ξ» _, Ξ³) n $ Ξ» n ih, classical.some $ h (range $ Ξ» m : Iio n, ih m.1 m.2) (finite_range _), Ξ» n, begin classical, refine nat.strong_rec_on' n (Ξ» n ih, _), rw nat.strong_rec_on_beta', convert classical.some_spec (h _ _), ext x, split, { rintros ⟨m, hmn, rfl⟩, exact ⟨⟨m, hmn⟩, rfl⟩ }, { rintros ⟨⟨m, hmn⟩, rfl⟩, exact ⟨m, hmn, rfl⟩ } end⟩ lemma finite_range_ite {p : Ξ± β†’ Prop} [decidable_pred p] {f g : Ξ± β†’ Ξ²} (hf : finite (range f)) (hg : finite (range g)) : finite (range (Ξ» x, if p x then f x else g x)) := (hf.union hg).subset range_ite_subset lemma finite_range_const {c : Ξ²} : finite (range (Ξ» x : Ξ±, c)) := (finite_singleton c).subset range_const_subset lemma range_find_greatest_subset {P : Ξ± β†’ β„• β†’ Prop} [βˆ€ x, decidable_pred (P x)] {b : β„•}: range (Ξ» x, nat.find_greatest (P x) b) βŠ† ↑(finset.range (b + 1)) := by { rw range_subset_iff, assume x, simp [nat.lt_succ_iff, nat.find_greatest_le] } lemma finite_range_find_greatest {P : Ξ± β†’ β„• β†’ Prop} [βˆ€ x, decidable_pred (P x)] {b : β„•} : finite (range (Ξ» x, nat.find_greatest (P x) b)) := (finset.range (b + 1)).finite_to_set.subset range_find_greatest_subset lemma card_lt_card {s t : set Ξ±} [fintype s] [fintype t] (h : s βŠ‚ t) : fintype.card s < fintype.card t := fintype.card_lt_of_injective_not_surjective (set.inclusion h.1) (set.inclusion_injective h.1) $ Ξ» hst, (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst) lemma card_le_of_subset {s t : set Ξ±} [fintype s] [fintype t] (hsub : s βŠ† t) : fintype.card s ≀ fintype.card t := fintype.card_le_of_injective (set.inclusion hsub) (set.inclusion_injective hsub) lemma eq_of_subset_of_card_le {s t : set Ξ±} [fintype s] [fintype t] (hsub : s βŠ† t) (hcard : fintype.card t ≀ fintype.card s) : s = t := (eq_or_ssubset_of_subset hsub).elim id (Ξ» h, absurd hcard $ not_le_of_lt $ card_lt_card h) lemma subset_iff_to_finset_subset (s t : set Ξ±) [fintype s] [fintype t] : s βŠ† t ↔ s.to_finset βŠ† t.to_finset := by simp @[simp, mono] lemma finite.to_finset_mono {s t : set Ξ±} {hs : finite s} {ht : finite t} : hs.to_finset βŠ† ht.to_finset ↔ s βŠ† t := begin split, { intros h x, rw [←finite.mem_to_finset hs, ←finite.mem_to_finset ht], exact Ξ» hx, h hx }, { intros h x, rw [finite.mem_to_finset hs, finite.mem_to_finset ht], exact Ξ» hx, h hx } end @[simp, mono] lemma finite.to_finset_strict_mono {s t : set Ξ±} {hs : finite s} {ht : finite t} : hs.to_finset βŠ‚ ht.to_finset ↔ s βŠ‚ t := begin rw [←lt_eq_ssubset, ←finset.lt_iff_ssubset, lt_iff_le_and_ne, lt_iff_le_and_ne], simp end lemma card_range_of_injective [fintype Ξ±] {f : Ξ± β†’ Ξ²} (hf : injective f) [fintype (range f)] : fintype.card (range f) = fintype.card Ξ± := eq.symm $ fintype.card_congr $ equiv.of_injective f hf lemma finite.exists_maximal_wrt [partial_order Ξ²] (f : Ξ± β†’ Ξ²) (s : set Ξ±) (h : set.finite s) : s.nonempty β†’ βˆƒa∈s, βˆ€a'∈s, f a ≀ f a' β†’ f a = f a' := begin classical, refine h.induction_on _ _, { assume h, exact absurd h empty_not_nonempty }, assume a s his _ ih _, cases s.eq_empty_or_nonempty with h h, { use a, simp [h] }, rcases ih h with ⟨b, hb, ih⟩, by_cases f b ≀ f a, { refine ⟨a, set.mem_insert _ _, assume c hc hac, le_antisymm hac _⟩, rcases set.mem_insert_iff.1 hc with rfl | hcs, { refl }, { rwa [← ih c hcs (le_trans h hac)] } }, { refine ⟨b, set.mem_insert_of_mem _ hb, assume c hc hbc, _⟩, rcases set.mem_insert_iff.1 hc with rfl | hcs, { exact (h hbc).elim }, { exact ih c hcs hbc } } end lemma finite.card_to_finset {s : set Ξ±} [fintype s] (h : s.finite) : h.to_finset.card = fintype.card s := by { rw [← finset.card_attach, finset.attach_eq_univ, ← fintype.card], congr' 2, funext, rw set.finite.mem_to_finset } section decidable_eq lemma to_finset_compl {Ξ± : Type*} [fintype Ξ±] [decidable_eq Ξ±] (s : set Ξ±) [fintype (sᢜ : set Ξ±)] [fintype s] : sᢜ.to_finset = (s.to_finset)ᢜ := by ext; simp lemma to_finset_inter {Ξ± : Type*} [decidable_eq Ξ±] (s t : set Ξ±) [fintype (s ∩ t : set Ξ±)] [fintype s] [fintype t] : (s ∩ t).to_finset = s.to_finset ∩ t.to_finset := by ext; simp lemma to_finset_union {Ξ± : Type*} [decidable_eq Ξ±] (s t : set Ξ±) [fintype (s βˆͺ t : set Ξ±)] [fintype s] [fintype t] : (s βˆͺ t).to_finset = s.to_finset βˆͺ t.to_finset := by ext; simp lemma to_finset_ne_eq_erase {Ξ± : Type*} [decidable_eq Ξ±] [fintype Ξ±] (a : Ξ±) [fintype {x : Ξ± | x β‰  a}] : {x : Ξ± | x β‰  a}.to_finset = finset.univ.erase a := by ext; simp lemma card_ne_eq [fintype Ξ±] (a : Ξ±) [fintype {x : Ξ± | x β‰  a}] : fintype.card {x : Ξ± | x β‰  a} = fintype.card Ξ± - 1 := begin haveI := classical.dec_eq Ξ±, rw [←to_finset_card, to_finset_ne_eq_erase, finset.card_erase_of_mem (finset.mem_univ _), finset.card_univ, nat.pred_eq_sub_one], end end decidable_eq section variables [semilattice_sup Ξ±] [nonempty Ξ±] {s : set Ξ±} /--A finite set is bounded above.-/ protected lemma finite.bdd_above (hs : finite s) : bdd_above s := finite.induction_on hs bdd_above_empty $ Ξ» a s _ _ h, h.insert a /--A finite union of sets which are all bounded above is still bounded above.-/ lemma finite.bdd_above_bUnion {I : set Ξ²} {S : Ξ² β†’ set Ξ±} (H : finite I) : (bdd_above (⋃i∈I, S i)) ↔ (βˆ€i ∈ I, bdd_above (S i)) := finite.induction_on H (by simp only [bUnion_empty, bdd_above_empty, ball_empty_iff]) (Ξ» a s ha _ hs, by simp only [bUnion_insert, ball_insert_iff, bdd_above_union, hs]) end section variables [semilattice_inf Ξ±] [nonempty Ξ±] {s : set Ξ±} /--A finite set is bounded below.-/ protected lemma finite.bdd_below (hs : finite s) : bdd_below s := @finite.bdd_above (order_dual Ξ±) _ _ _ hs /--A finite union of sets which are all bounded below is still bounded below.-/ lemma finite.bdd_below_bUnion {I : set Ξ²} {S : Ξ² β†’ set Ξ±} (H : finite I) : (bdd_below (⋃i∈I, S i)) ↔ (βˆ€i ∈ I, bdd_below (S i)) := @finite.bdd_above_bUnion (order_dual Ξ±) _ _ _ _ _ H end end set namespace finset /-- A finset is bounded above. -/ protected lemma bdd_above [semilattice_sup Ξ±] [nonempty Ξ±] (s : finset Ξ±) : bdd_above (↑s : set Ξ±) := s.finite_to_set.bdd_above /-- A finset is bounded below. -/ protected lemma bdd_below [semilattice_inf Ξ±] [nonempty Ξ±] (s : finset Ξ±) : bdd_below (↑s : set Ξ±) := s.finite_to_set.bdd_below end finset namespace fintype variables [fintype Ξ±] {p q : Ξ± β†’ Prop} [decidable_pred p] [decidable_pred q] @[simp] lemma card_subtype_compl : fintype.card {x // Β¬ p x} = fintype.card Ξ± - fintype.card {x // p x} := begin classical, rw [fintype.card_of_subtype (set.to_finset pᢜ), set.to_finset_compl p, finset.card_compl, fintype.card_of_subtype (set.to_finset p)]; intros; simp; refl end /-- If two subtypes of a fintype have equal cardinality, so do their complements. -/ lemma card_compl_eq_card_compl (h : fintype.card {x // p x} = fintype.card {x // q x}) : fintype.card {x // Β¬ p x} = fintype.card {x // Β¬ q x} := by simp only [card_subtype_compl, h] end fintype
7b155db9674c9121adfdd0a10aa7293593e6ff23
968e2f50b755d3048175f176376eff7139e9df70
/examples/prop_logic_lean_summary/unnamed_22.lean
7962f34aa6fa777b416008393482973e6d0e619c
[]
no_license
gihanmarasingha/mth1001_sphinx
190a003269ba5e54717b448302a27ca26e31d491
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
refs/heads/master
1,672,913,933,677
1,604,516,583,000
1,604,516,583,000
309,245,750
1
0
null
null
null
null
UTF-8
Lean
false
false
79
lean
variables p q r : Prop -- This is a one-line comment. In has no effect in Lean.
f29d1f97480226fbfc0f2465a6e6f4665f9948a2
b794ca1df49bc5a3bd3fd5552eed3bc4f63b8b93
/src/mywork/review.lean
793647092f904536bec24ed67b5951aa928c3ac0
[]
no_license
akraisinger/cs2120f21
8235ac98375e04ffcec504cff5cab7833ee69e54
4ef83d7151bb6a284028092aa4f1d509c0eb8237
refs/heads/main
1,691,714,771,612
1,632,889,465,000
1,632,889,465,000
399,946,508
0
0
null
null
null
null
UTF-8
Lean
false
false
2,694
lean
/-axiom is a way of saying to assume a truth. A type judgement? can do more than one via axioms-/ namespace implies axioms (P Q : Prop) def if_P_is_true_then_so_is_Q : Prop := P β†’ Q /-binding if_P_is to be a proposition arrow shows conditional in logic. "if P then Q" to show p implies q, show in context of p, q must be true. -/ axiom p : P -- assume P is true -- assume we have a prrof of P (p) axiom pq : P β†’ Q -- assume that we have a proof of pq, that if p then q -- P β†’ Q is a proposition -- intro rule for implies: assume premise, show conclusion -- elimination rule for implies: apply proof of p β†’ q to proof of p #check pq #check p #check (pq p) /- suppose P and Q are propostions and you know that P β†’ Q and that P are both true. Show that Q is true. Proof: Apply the truth of P β†’ Q to the truth of P to derrive the truth of Q. Also, Proof: By the elimination rule for β†’ with pq applied to p.add_key_equivalence Also, Proof: By "modus ponens". QED -/ -- think of proof Pβ†’Q as a function! -- takes in a proof of P -- returns a proof of Q end implies /- FOR ALL (βˆ€) -/ namespace all axioms (T : Type) (P: T β†’ Prop) --predicate (P) of a type that assumes a proposition (t : T) (a : βˆ€ (x : T), P x) -- for any object of type T that object has property of P -- does t have property P? -- yes! bc t is of type T where any object of that type it has that property example : P t := a t -- applying axiom a to t proves that t has property P #check a t end all /- AND & β†’ -/ /- P ∧ Q if have proof of p and proof of q then can proof of p ∧ q two smaller proofs into one bigger proof -/ /- given proposition of P, can also make proposition Β¬P way to prove Β¬P is to show P has no proof. if Β¬P is true, then assuming P is true will able to deduce proof of false. say Β¬P by saying P is true is impossible, and because impossible, no proof of P. if Pβ†’false is true, then there is not proof of P, so Β¬P. (remember, no proofs of false) -/ /- -- INTRO AND ELIM RULES!! -- EQUALS (=) intro: (1 rule) elim: (1 rule) AND (∧) intro: (and.intro) elim: (and.elim_left, and.elim_right) OR (∨) intro: (or.intro_left, or.intro_right) elim: (or.elim) FOR ALL (βˆ€) intro: if you can assume an arbitrary version and prove it, then you can for all elim: apply the for all func IMPLIES (β†’) intro: assume the antecedent, if you can prove the consequent, then you can prove implies. elim: apply the implies func NOT (Β¬) intro (none??) elim?? IF AND ONLY IFF (↔) intro: (iff.intro) elim? TRUE intro: (true.intro) elim: no real elimination rule for true FALSE intro: no real intro rule for false elim: (false.elim) -/
e2a3dfe0c5eab7d9f2a2d70e3355444289620c34
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/lean/run/108.lean
828b12a8efd68d41f8429ce288d85d527e227904
[ "Apache-2.0" ]
permissive
mhuisi/lean4
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
refs/heads/master
1,621,225,489,283
1,585,142,689,000
1,585,142,689,000
250,590,438
0
2
Apache-2.0
1,602,443,220,000
1,585,327,814,000
C
UTF-8
Lean
false
false
77
lean
new_frontend macro m n:ident : command => `(def $n := 1) m foo #check foo
09a5da48b4fee6b963b6bc2b57bc3dfde65ee96c
4727251e0cd73359b15b664c3170e5d754078599
/src/category_theory/limits/over.lean
19ca81696d51da8612e2167a0240f012e382371e
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
4,986
lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import category_theory.over import category_theory.adjunction.opposites import category_theory.limits.preserves.basic import category_theory.limits.shapes.pullbacks import category_theory.limits.creates import category_theory.limits.comma /-! # Limits and colimits in the over and under categories Show that the forgetful functor `forget X : over X β₯€ C` creates colimits, and hence `over X` has any colimits that `C` has (as well as the dual that `forget X : under X ⟢ C` creates limits). Note that the folder `category_theory.limits.shapes.constructions.over` further shows that `forget X : over X β₯€ C` creates connected limits (so `over X` has connected limits), and that `over X` has `J`-indexed products if `C` has `J`-indexed wide pullbacks. TODO: If `C` has binary products, then `forget X : over X β₯€ C` has a right adjoint. -/ noncomputable theory universes v u -- morphism levels before object levels. See note [category_theory universes]. open category_theory category_theory.limits variables {J : Type v} [small_category J] variables {C : Type u} [category.{v} C] variable {X : C} namespace category_theory.over instance has_colimit_of_has_colimit_comp_forget (F : J β₯€ over X) [i : has_colimit (F β‹™ forget X)] : has_colimit F := @@costructured_arrow.has_colimit _ _ _ _ i _ instance [has_colimits_of_shape J C] : has_colimits_of_shape J (over X) := {} instance [has_colimits C] : has_colimits (over X) := ⟨infer_instance⟩ instance creates_colimits : creates_colimits (forget X) := costructured_arrow.creates_colimits -- We can automatically infer that the forgetful functor preserves and reflects colimits. example [has_colimits C] : preserves_colimits (forget X) := infer_instance example : reflects_colimits (forget X) := infer_instance section variables [has_pullbacks C] open tactic /-- When `C` has pullbacks, a morphism `f : X ⟢ Y` induces a functor `over Y β₯€ over X`, by pulling back a morphism along `f`. -/ @[simps] def pullback {X Y : C} (f : X ⟢ Y) : over Y β₯€ over X := { obj := Ξ» g, over.mk (pullback.snd : pullback g.hom f ⟢ X), map := Ξ» g h k, over.hom_mk (pullback.lift (pullback.fst ≫ k.left) pullback.snd (by simp [pullback.condition])) (by tidy) } /-- `over.map f` is left adjoint to `over.pullback f`. -/ def map_pullback_adj {A B : C} (f : A ⟢ B) : over.map f ⊣ pullback f := adjunction.mk_of_hom_equiv { hom_equiv := Ξ» g h, { to_fun := Ξ» X, over.hom_mk (pullback.lift X.left g.hom (over.w X)) (pullback.lift_snd _ _ _), inv_fun := Ξ» Y, begin refine over.hom_mk _ _, refine Y.left ≫ pullback.fst, dsimp, rw [← over.w Y, category.assoc, pullback.condition, category.assoc], refl, end, left_inv := Ξ» X, by { ext, dsimp, simp, }, right_inv := Ξ» Y, begin ext, dsimp, simp only [pullback.lift_fst], dsimp, rw [pullback.lift_snd, ← over.w Y], refl, end } } /-- pullback (πŸ™ A) : over A β₯€ over A is the identity functor. -/ def pullback_id {A : C} : pullback (πŸ™ A) β‰… 𝟭 _ := adjunction.right_adjoint_uniq (map_pullback_adj _) (adjunction.id.of_nat_iso_left over.map_id.symm) /-- pullback commutes with composition (up to natural isomorphism). -/ def pullback_comp {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) : pullback (f ≫ g) β‰… pullback g β‹™ pullback f := adjunction.right_adjoint_uniq (map_pullback_adj _) (((map_pullback_adj _).comp _ _ (map_pullback_adj _)).of_nat_iso_left (over.map_comp _ _).symm) instance pullback_is_right_adjoint {A B : C} (f : A ⟢ B) : is_right_adjoint (pullback f) := ⟨_, map_pullback_adj f⟩ end end category_theory.over namespace category_theory.under instance has_limit_of_has_limit_comp_forget (F : J β₯€ under X) [i : has_limit (F β‹™ forget X)] : has_limit F := @@structured_arrow.has_limit _ _ _ _ i _ instance [has_limits_of_shape J C] : has_limits_of_shape J (under X) := {} instance [has_limits C] : has_limits (under X) := ⟨infer_instance⟩ instance creates_limits : creates_limits (forget X) := structured_arrow.creates_limits -- We can automatically infer that the forgetful functor preserves and reflects limits. example [has_limits C] : preserves_limits (forget X) := infer_instance example : reflects_limits (forget X) := infer_instance section variables [has_pushouts C] /-- When `C` has pushouts, a morphism `f : X ⟢ Y` induces a functor `under X β₯€ under Y`, by pushing a morphism forward along `f`. -/ @[simps] def pushout {X Y : C} (f : X ⟢ Y) : under X β₯€ under Y := { obj := Ξ» g, under.mk (pushout.inr : Y ⟢ pushout g.hom f), map := Ξ» g h k, under.hom_mk (pushout.desc (k.right ≫ pushout.inl) pushout.inr (by { simp [←pushout.condition], })) (by tidy) } end end category_theory.under
b2702eda217f3f53e5e0ca3e551e756a7b0c8772
ea5678cc400c34ff95b661fa26d15024e27ea8cd
/islanders_neat.lean
c793c1196a22038199cef88083cb6acf212ef77b
[]
no_license
ChrisHughes24/leanstuff
dca0b5349c3ed893e8792ffbd98cbcadaff20411
9efa85f72efaccd1d540385952a6acc18fce8687
refs/heads/master
1,654,883,241,759
1,652,873,885,000
1,652,873,885,000
134,599,537
1
0
null
null
null
null
UTF-8
Lean
false
false
5,420
lean
import data.nat.basic open nat /-- Statement of "what the islanders know". Given a day number `d`, and the actual number of blue eyed islanders `b`, and a hypothesized number of blue eyed islanders `B`, it returns whether or not `B` is a possible number of blue eyed islanders from the blue eyed islanders perspective. -/ def island_rules : β„• β†’ β„• β†’ β„• β†’ Prop /- on day 0 there are two possibilities for the number of blue eyed islanders `b` and `b - 1` unless `b = 1`, in which case there is only one possibility, since it is also known that the actual number is greater than zero -/ | 0 b B := (B = b ∨ B = b - 1) ∧ 0 < B /- On subsequent days, a hypothesized value `B` is possible if and only if it was possible the previous day and it is consistent with whether or not islanders left the previous day -/ | (d+1) b B := island_rules d b B ∧ ((βˆ€ C, island_rules d b C β†’ C = b) ↔ βˆ€ C, island_rules d B C β†’ C = B) lemma island_rules_zero_of_island_rules : βˆ€ {d b B : β„•}, island_rules d b B β†’ (B = b ∨ B = b - 1) ∧ 0 < B | 0 b B h := h | (d+1) b B h := island_rules_zero_of_island_rules h.left theorem blue_eyed_islander_mp : βˆ€ {d b}, 0 < b β†’ b ≀ d + 1 β†’ βˆ€ B, island_rules d b B β†’ B = b | 0 b hb0 hdb B hir := begin have : b = 1, from le_antisymm hdb (succ_le_of_lt hb0), unfold island_rules at hir, cases hir.left with h h, { exact h }, { simp [this, *, lt_irrefl] at * } end | (d+1) b hb hdbB B hir := have (B = b ∨ B = b - 1) ∧ 0 < B, from island_rules_zero_of_island_rules hir, begin unfold island_rules at hir, cases this.left with h h, { exact h }, { /- the case B = b - 1 -/ have hb0 : 0 < b - 1, from h β–Έ this.right, have hb1 : 1 ≀ b, from le_trans (succ_le_of_lt hb0) (nat.sub_le_self _ _), have hdbB' : b - 1 ≀ d + 1, from nat.sub_le_right_iff_le_add.2 hdbB, /- by our induction hypothesis, they would have left on day d if the actual number was b - 1 -/ have ih : βˆ€ C : β„•, island_rules d B C β†’ C = B, from h.symm β–Έ blue_eyed_islander_mp hb0 hdbB', /- From the definition of island_rules, this means they left yesterday -/ rw ← hir.right at ih, /- Slightly strange proof, even though we know B = b - 1 and we're trying to prove B = b, we don't find a contradiction, we just prove B = b directly -/ exact ih B hir.left } end /-- This seems to come up over and over again, so I proved it seperately -/ theorem nat.sub_one_ne_self_of_pos {a : β„•} (ha : 0 < a) : a - 1 β‰  a := ne_of_lt (nat.sub_lt_self ha dec_trivial) /-- The other direction of the iff, stated in an easier to prove but equivalent way. If `d + 1` < b, then there are two possible values. -/ lemma blue_eyed_islander_mpr : βˆ€ {d b}, 0 < b β†’ d + 1 < b β†’ βˆ€ B, island_rules d b B ↔ (B = b ∨ B = b - 1) | 0 b hb0 hdb B := begin unfold island_rules, split, { exact Ξ» h, h.left }, { assume hbB, split, { exact hbB }, { cases hbB with hbB hbB, { exact hbB.symm β–Έ hb0 }, { exact hbB.symm β–Έ nat.sub_pos_of_lt hdb } } } end | (succ d) b hb0 hdb B := begin split, { exact Ξ» h, (island_rules_zero_of_island_rules h).left }, { assume hbB, have hb10 : 0 < b - 1, from nat.sub_pos_of_lt (lt_trans dec_trivial hdb), have hdb1 : d + 1 < b - 1, from nat.lt_sub_right_of_add_lt hdb, /- Use our induction hypothesis twice. For both possible values of B, the islanders did not leave the previous day. This means we have no new information -/ have ihb : βˆ€ B : β„•, island_rules d b B ↔ B = b ∨ B = b - 1, from blue_eyed_islander_mpr hb0 (lt_trans (lt_succ_self _) hdb), have ihb1 : βˆ€ B : β„•, island_rules d (b - 1) B ↔ B = b - 1 ∨ B = b - 1 - 1, from blue_eyed_islander_mpr hb10 hdb1, unfold island_rules, split, { rw ihb, exact hbB }, /- the interesting part of the proof starts here, we have to prove that either value of B is possible -/ { cases hbB with hbB hbB, { /- case B = b is easy -/ rw hbB }, { /- case B = b - 1 is harder -/ /- By our induction hypotheses it was impossible to deduce the value of `b` yesterday in both the real world, and for our hypothesized value of `B`, which is `b - 1`. This means both sides of the iff statement are false -/ simp only [ihb, ihb1, hbB], /- After applying the induction hypothesis, it is now obvious that both sides are false, and the proof is easy from now on -/ apply iff_of_false, { assume h, have : b - 1 = b, from h (b - 1) (or.inr rfl), exact nat.sub_one_ne_self_of_pos hb0 this }, { assume h, have : b - 1 - 1 = b - 1, from h (b - 1 - 1) (or.inr rfl), exact nat.sub_one_ne_self_of_pos hb10 this } } } } end lemma blue_eyed_islander {d b} (hb0 : 0 < b) : (βˆ€ B, island_rules d b B β†’ B = b) ↔ b ≀ d + 1 := begin split, { assume h, refine le_of_not_gt (Ξ» hbd : d + 1 < b, _), have := blue_eyed_islander_mpr hb0 hbd, have : b - 1 = b, from h (b - 1) ((this (b - 1)).mpr (or.inr rfl)), exact nat.sub_one_ne_self_of_pos hb0 this }, { exact blue_eyed_islander_mp hb0 } end lemma blue_eyed_islander_100 {d : β„•} : (βˆ€ B, island_rules d 100 B β†’ B = 100) ↔ 100 ≀ d + 1 := blue_eyed_islander dec_trivial
f1012edd3e36a4e27e0249e17be5d11e47bc2478
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/category/bitraversable/basic.lean
45b0b28c580f84aacd1ceb1c83cc0855cab839c8
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
2,110
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon Functors with two arguments -/ import category.functor category.bifunctor category.traversable.basic tactic.basic universes u class bitraversable (t : Type u β†’ Type u β†’ Type u) extends bifunctor t := (bitraverse : Ξ  {m : Type u β†’ Type u} [applicative m] {Ξ± Ξ±' Ξ² Ξ²'}, (Ξ± β†’ m Ξ±') β†’ (Ξ² β†’ m Ξ²') β†’ t Ξ± Ξ² β†’ m (t Ξ±' Ξ²')) export bitraversable ( bitraverse ) def bisequence {t m} [bitraversable t] [applicative m] {Ξ± Ξ²} : t (m Ξ±) (m Ξ²) β†’ m (t Ξ± Ξ²) := bitraverse id id open functor class is_lawful_bitraversable (t : Type u β†’ Type u β†’ Type u) [bitraversable t] extends is_lawful_bifunctor t := (id_bitraverse : βˆ€ {Ξ± Ξ²} (x : t Ξ± Ξ²), bitraverse id.mk id.mk x = id.mk x ) (comp_bitraverse : βˆ€ {F G} [applicative F] [applicative G] [is_lawful_applicative F] [is_lawful_applicative G] {Ξ± Ξ±' Ξ² Ξ²' Ξ³ Ξ³'} (f : Ξ² β†’ F Ξ³) (f' : Ξ²' β†’ F Ξ³') (g : Ξ± β†’ G Ξ²) (g' : Ξ±' β†’ G Ξ²') (x : t Ξ± Ξ±'), bitraverse (comp.mk ∘ map f ∘ g) (comp.mk ∘ map f' ∘ g') x = comp.mk (bitraverse f f' <$> bitraverse g g' x) ) (bitraverse_eq_bimap_id : βˆ€ {Ξ± Ξ±' Ξ² Ξ²'} (f : Ξ± β†’ Ξ²) (f' : Ξ±' β†’ Ξ²') (x : t Ξ± Ξ±'), bitraverse (id.mk ∘ f) (id.mk ∘ f') x = id.mk (bimap f f' x)) (binaturality : βˆ€ {F G} [applicative F] [applicative G] [is_lawful_applicative F] [is_lawful_applicative G] (Ξ· : applicative_transformation F G) {Ξ± Ξ±' Ξ² Ξ²'} (f : Ξ± β†’ F Ξ²) (f' : Ξ±' β†’ F Ξ²') (x : t Ξ± Ξ±'), Ξ· (bitraverse f f' x) = bitraverse (@Ξ· _ ∘ f) (@Ξ· _ ∘ f') x) export is_lawful_bitraversable ( id_bitraverse comp_bitraverse bitraverse_eq_bimap_id ) open is_lawful_bitraversable attribute [higher_order bitraverse_id_id] id_bitraverse attribute [higher_order bitraverse_comp] comp_bitraverse attribute [higher_order] binaturality bitraverse_eq_bimap_id export is_lawful_bitraversable (bitraverse_id_id bitraverse_comp)
f4587bd64ae912c563928837b7e8bde53122f429
e514e8b939af519a1d5e9b30a850769d058df4e9
/test/rewrite_search_discovery_2.lean
84e34b898244dd822ef8216e01263d8427536752
[]
no_license
semorrison/lean-rewrite-search
dca317c5a52e170fb6ffc87c5ab767afb5e3e51a
e804b8f2753366b8957be839908230ee73f9e89f
refs/heads/master
1,624,051,754,485
1,614,160,817,000
1,614,160,817,000
162,660,605
0
1
null
null
null
null
UTF-8
Lean
false
false
988
lean
import tactic.rewrite_search open tactic.rewrite_search.discovery namespace tactic.rewrite_search.testing local attribute [instance] classical.prop_decidable example {A B C : Prop} : ((B β†’ C) β†’ (Β¬(A β†’ C) ∧ Β¬(A ∨ B))) = (B ∧ Β¬C) := by rewrite_search_using! [] {} end tactic.rewrite_search.testing namespace tactic.rewrite_search.testing axiom foo' : [6] = [7] axiom bar' : [[5],[5]] = [[6],[6]] example : [[7],[6]] = [[5],[5]] := begin rewrite_search_with [←foo', bar'] {}, end axiom foo'' : [7] = [8] axiom foo''' : [8] = [7] run_cmd (rewrite_list_from_lemma `(foo'')).mmap (Ξ» rw, is_promising_rewrite rw [`([[8],[6]])]) >>= tactic.trace run_cmd (rewrite_list_from_lemma `(foo''')).mmap (Ξ» rw, is_promising_rewrite rw [`([[8],[6]])]) >>= tactic.trace def my_test : [[7],[6]] = [[5],[5]] := begin success_if_fail { rewrite_search_with [ bar'] {help_me := ff} }, rewrite_search_with! [ bar'] {help_me := tt} end end tactic.rewrite_search.testing
2d6d7c3b1954d7a69cf8028ab0d75d0c8601e357
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/order/bounds/basic.lean
6add0bb14d55516aa3031623c8bbc822f72bd75c
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
51,825
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Yury Kudryashov -/ import data.set.intervals.basic import data.set.n_ary import order.directed /-! # Upper / lower bounds > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define: * `upper_bounds`, `lower_bounds` : the set of upper bounds (resp., lower bounds) of a set; * `bdd_above s`, `bdd_below s` : the set `s` is bounded above (resp., below), i.e., the set of upper (resp., lower) bounds of `s` is nonempty; * `is_least s a`, `is_greatest s a` : `a` is a least (resp., greatest) element of `s`; for a partial order, it is unique if exists; * `is_lub s a`, `is_glb s a` : `a` is a least upper bound (resp., a greatest lower bound) of `s`; for a partial order, it is unique if exists. We also prove various lemmas about monotonicity, behaviour under `βˆͺ`, `∩`, `insert`, and provide formulas for `βˆ…`, `univ`, and intervals. -/ open function set order_dual (to_dual of_dual) universes u v w x variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {ΞΉ : Sort x} section variables [preorder Ξ±] [preorder Ξ²] {s t : set Ξ±} {a b : Ξ±} /-! ### Definitions -/ /-- The set of upper bounds of a set. -/ def upper_bounds (s : set Ξ±) : set Ξ± := { x | βˆ€ ⦃a⦄, a ∈ s β†’ a ≀ x } /-- The set of lower bounds of a set. -/ def lower_bounds (s : set Ξ±) : set Ξ± := { x | βˆ€ ⦃a⦄, a ∈ s β†’ x ≀ a } /-- A set is bounded above if there exists an upper bound. -/ def bdd_above (s : set Ξ±) := (upper_bounds s).nonempty /-- A set is bounded below if there exists a lower bound. -/ def bdd_below (s : set Ξ±) := (lower_bounds s).nonempty /-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/ def is_least (s : set Ξ±) (a : Ξ±) : Prop := a ∈ s ∧ a ∈ lower_bounds s /-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists -/ def is_greatest (s : set Ξ±) (a : Ξ±) : Prop := a ∈ s ∧ a ∈ upper_bounds s /-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/ def is_lub (s : set Ξ±) : Ξ± β†’ Prop := is_least (upper_bounds s) /-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/ def is_glb (s : set Ξ±) : Ξ± β†’ Prop := is_greatest (lower_bounds s) lemma mem_upper_bounds : a ∈ upper_bounds s ↔ βˆ€ x ∈ s, x ≀ a := iff.rfl lemma mem_lower_bounds : a ∈ lower_bounds s ↔ βˆ€ x ∈ s, a ≀ x := iff.rfl lemma bdd_above_def : bdd_above s ↔ βˆƒ x, βˆ€ y ∈ s, y ≀ x := iff.rfl lemma bdd_below_def : bdd_below s ↔ βˆƒ x, βˆ€ y ∈ s, x ≀ y := iff.rfl lemma bot_mem_lower_bounds [order_bot Ξ±] (s : set Ξ±) : βŠ₯ ∈ lower_bounds s := Ξ» _ _, bot_le lemma top_mem_upper_bounds [order_top Ξ±] (s : set Ξ±) : ⊀ ∈ upper_bounds s := Ξ» _ _, le_top @[simp] lemma is_least_bot_iff [order_bot Ξ±] : is_least s βŠ₯ ↔ βŠ₯ ∈ s := and_iff_left $ bot_mem_lower_bounds _ @[simp] lemma is_greatest_top_iff [order_top Ξ±] : is_greatest s ⊀ ↔ ⊀ ∈ s := and_iff_left $ top_mem_upper_bounds _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x` is not greater than or equal to `y`. This version only assumes `preorder` structure and uses `Β¬(y ≀ x)`. A version for linear orders is called `not_bdd_above_iff`. -/ lemma not_bdd_above_iff' : Β¬bdd_above s ↔ βˆ€ x, βˆƒ y ∈ s, Β¬(y ≀ x) := by simp [bdd_above, upper_bounds, set.nonempty] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x` is not less than or equal to `y`. This version only assumes `preorder` structure and uses `Β¬(x ≀ y)`. A version for linear orders is called `not_bdd_below_iff`. -/ lemma not_bdd_below_iff' : Β¬bdd_below s ↔ βˆ€ x, βˆƒ y ∈ s, Β¬ x ≀ y := @not_bdd_above_iff' Ξ±α΅’α΅ˆ _ _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater than `x`. A version for preorders is called `not_bdd_above_iff'`. -/ lemma not_bdd_above_iff {Ξ± : Type*} [linear_order Ξ±] {s : set Ξ±} : Β¬bdd_above s ↔ βˆ€ x, βˆƒ y ∈ s, x < y := by simp only [not_bdd_above_iff', not_le] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less than `x`. A version for preorders is called `not_bdd_below_iff'`. -/ lemma not_bdd_below_iff {Ξ± : Type*} [linear_order Ξ±] {s : set Ξ±} : Β¬bdd_below s ↔ βˆ€ x, βˆƒ y ∈ s, y < x := @not_bdd_above_iff Ξ±α΅’α΅ˆ _ _ lemma bdd_above.dual (h : bdd_above s) : bdd_below (of_dual ⁻¹' s) := h lemma bdd_below.dual (h : bdd_below s) : bdd_above (of_dual ⁻¹' s) := h lemma is_least.dual (h : is_least s a) : is_greatest (of_dual ⁻¹' s) (to_dual a) := h lemma is_greatest.dual (h : is_greatest s a) : is_least (of_dual ⁻¹' s) (to_dual a) := h lemma is_lub.dual (h : is_lub s a) : is_glb (of_dual ⁻¹' s) (to_dual a) := h lemma is_glb.dual (h : is_glb s a) : is_lub (of_dual ⁻¹' s) (to_dual a) := h /-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/ @[reducible] def is_least.order_bot (h : is_least s a) : order_bot s := { bot := ⟨a, h.1⟩, bot_le := subtype.forall.2 h.2 } /-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/ @[reducible] def is_greatest.order_top (h : is_greatest s a) : order_top s := { top := ⟨a, h.1⟩, le_top := subtype.forall.2 h.2 } /-! ### Monotonicity -/ lemma upper_bounds_mono_set ⦃s t : set α⦄ (hst : s βŠ† t) : upper_bounds t βŠ† upper_bounds s := Ξ» b hb x h, hb $ hst h lemma lower_bounds_mono_set ⦃s t : set α⦄ (hst : s βŠ† t) : lower_bounds t βŠ† lower_bounds s := Ξ» b hb x h, hb $ hst h lemma upper_bounds_mono_mem ⦃a b⦄ (hab : a ≀ b) : a ∈ upper_bounds s β†’ b ∈ upper_bounds s := Ξ» ha x h, le_trans (ha h) hab lemma lower_bounds_mono_mem ⦃a b⦄ (hab : a ≀ b) : b ∈ lower_bounds s β†’ a ∈ lower_bounds s := Ξ» hb x h, le_trans hab (hb h) lemma upper_bounds_mono ⦃s t : set α⦄ (hst : s βŠ† t) ⦃a b⦄ (hab : a ≀ b) : a ∈ upper_bounds t β†’ b ∈ upper_bounds s := Ξ» ha, upper_bounds_mono_set hst $ upper_bounds_mono_mem hab ha lemma lower_bounds_mono ⦃s t : set α⦄ (hst : s βŠ† t) ⦃a b⦄ (hab : a ≀ b) : b ∈ lower_bounds t β†’ a ∈ lower_bounds s := Ξ» hb, lower_bounds_mono_set hst $ lower_bounds_mono_mem hab hb /-- If `s βŠ† t` and `t` is bounded above, then so is `s`. -/ lemma bdd_above.mono ⦃s t : set α⦄ (h : s βŠ† t) : bdd_above t β†’ bdd_above s := nonempty.mono $ upper_bounds_mono_set h /-- If `s βŠ† t` and `t` is bounded below, then so is `s`. -/ lemma bdd_below.mono ⦃s t : set α⦄ (h : s βŠ† t) : bdd_below t β†’ bdd_below s := nonempty.mono $ lower_bounds_mono_set h /-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any set `t`, `s βŠ† t βŠ† p`. -/ lemma is_lub.of_subset_of_superset {s t p : set Ξ±} (hs : is_lub s a) (hp : is_lub p a) (hst : s βŠ† t) (htp : t βŠ† p) : is_lub t a := ⟨upper_bounds_mono_set htp hp.1, lower_bounds_mono_set (upper_bounds_mono_set hst) hs.2⟩ /-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any set `t`, `s βŠ† t βŠ† p`. -/ lemma is_glb.of_subset_of_superset {s t p : set Ξ±} (hs : is_glb s a) (hp : is_glb p a) (hst : s βŠ† t) (htp : t βŠ† p) : is_glb t a := hs.dual.of_subset_of_superset hp hst htp lemma is_least.mono (ha : is_least s a) (hb : is_least t b) (hst : s βŠ† t) : b ≀ a := hb.2 (hst ha.1) lemma is_greatest.mono (ha : is_greatest s a) (hb : is_greatest t b) (hst : s βŠ† t) : a ≀ b := hb.2 (hst ha.1) lemma is_lub.mono (ha : is_lub s a) (hb : is_lub t b) (hst : s βŠ† t) : a ≀ b := hb.mono ha $ upper_bounds_mono_set hst lemma is_glb.mono (ha : is_glb s a) (hb : is_glb t b) (hst : s βŠ† t) : b ≀ a := hb.mono ha $ lower_bounds_mono_set hst lemma subset_lower_bounds_upper_bounds (s : set Ξ±) : s βŠ† lower_bounds (upper_bounds s) := Ξ» x hx y hy, hy hx lemma subset_upper_bounds_lower_bounds (s : set Ξ±) : s βŠ† upper_bounds (lower_bounds s) := Ξ» x hx y hy, hy hx lemma set.nonempty.bdd_above_lower_bounds (hs : s.nonempty) : bdd_above (lower_bounds s) := hs.mono (subset_upper_bounds_lower_bounds s) lemma set.nonempty.bdd_below_upper_bounds (hs : s.nonempty) : bdd_below (upper_bounds s) := hs.mono (subset_lower_bounds_upper_bounds s) /-! ### Conversions -/ lemma is_least.is_glb (h : is_least s a) : is_glb s a := ⟨h.2, Ξ» b hb, hb h.1⟩ lemma is_greatest.is_lub (h : is_greatest s a) : is_lub s a := ⟨h.2, Ξ» b hb, hb h.1⟩ lemma is_lub.upper_bounds_eq (h : is_lub s a) : upper_bounds s = Ici a := set.ext $ Ξ» b, ⟨λ hb, h.2 hb, Ξ» hb, upper_bounds_mono_mem hb h.1⟩ lemma is_glb.lower_bounds_eq (h : is_glb s a) : lower_bounds s = Iic a := h.dual.upper_bounds_eq lemma is_least.lower_bounds_eq (h : is_least s a) : lower_bounds s = Iic a := h.is_glb.lower_bounds_eq lemma is_greatest.upper_bounds_eq (h : is_greatest s a) : upper_bounds s = Ici a := h.is_lub.upper_bounds_eq lemma is_lub_le_iff (h : is_lub s a) : a ≀ b ↔ b ∈ upper_bounds s := by { rw h.upper_bounds_eq, refl } lemma le_is_glb_iff (h : is_glb s a) : b ≀ a ↔ b ∈ lower_bounds s := by { rw h.lower_bounds_eq, refl } lemma is_lub_iff_le_iff : is_lub s a ↔ βˆ€ b, a ≀ b ↔ b ∈ upper_bounds s := ⟨λ h b, is_lub_le_iff h, Ξ» H, ⟨(H _).1 le_rfl, Ξ» b hb, (H b).2 hb⟩⟩ lemma is_glb_iff_le_iff : is_glb s a ↔ βˆ€ b, b ≀ a ↔ b ∈ lower_bounds s := @is_lub_iff_le_iff Ξ±α΅’α΅ˆ _ _ _ /-- If `s` has a least upper bound, then it is bounded above. -/ lemma is_lub.bdd_above (h : is_lub s a) : bdd_above s := ⟨a, h.1⟩ /-- If `s` has a greatest lower bound, then it is bounded below. -/ lemma is_glb.bdd_below (h : is_glb s a) : bdd_below s := ⟨a, h.1⟩ /-- If `s` has a greatest element, then it is bounded above. -/ lemma is_greatest.bdd_above (h : is_greatest s a) : bdd_above s := ⟨a, h.2⟩ /-- If `s` has a least element, then it is bounded below. -/ lemma is_least.bdd_below (h : is_least s a) : bdd_below s := ⟨a, h.2⟩ lemma is_least.nonempty (h : is_least s a) : s.nonempty := ⟨a, h.1⟩ lemma is_greatest.nonempty (h : is_greatest s a) : s.nonempty := ⟨a, h.1⟩ /-! ### Union and intersection -/ @[simp] lemma upper_bounds_union : upper_bounds (s βˆͺ t) = upper_bounds s ∩ upper_bounds t := subset.antisymm (Ξ» b hb, ⟨λ x hx, hb (or.inl hx), Ξ» x hx, hb (or.inr hx)⟩) (Ξ» b hb x hx, hx.elim (Ξ» hs, hb.1 hs) (Ξ» ht, hb.2 ht)) @[simp] lemma lower_bounds_union : lower_bounds (s βˆͺ t) = lower_bounds s ∩ lower_bounds t := @upper_bounds_union Ξ±α΅’α΅ˆ _ s t lemma union_upper_bounds_subset_upper_bounds_inter : upper_bounds s βˆͺ upper_bounds t βŠ† upper_bounds (s ∩ t) := union_subset (upper_bounds_mono_set $ inter_subset_left _ _) (upper_bounds_mono_set $ inter_subset_right _ _) lemma union_lower_bounds_subset_lower_bounds_inter : lower_bounds s βˆͺ lower_bounds t βŠ† lower_bounds (s ∩ t) := @union_upper_bounds_subset_upper_bounds_inter Ξ±α΅’α΅ˆ _ s t lemma is_least_union_iff {a : Ξ±} {s t : set Ξ±} : is_least (s βˆͺ t) a ↔ (is_least s a ∧ a ∈ lower_bounds t ∨ a ∈ lower_bounds s ∧ is_least t a) := by simp [is_least, lower_bounds_union, or_and_distrib_right, and_comm (a ∈ t), and_assoc] lemma is_greatest_union_iff : is_greatest (s βˆͺ t) a ↔ (is_greatest s a ∧ a ∈ upper_bounds t ∨ a ∈ upper_bounds s ∧ is_greatest t a) := @is_least_union_iff Ξ±α΅’α΅ˆ _ a s t /-- If `s` is bounded, then so is `s ∩ t` -/ lemma bdd_above.inter_of_left (h : bdd_above s) : bdd_above (s ∩ t) := h.mono $ inter_subset_left s t /-- If `t` is bounded, then so is `s ∩ t` -/ lemma bdd_above.inter_of_right (h : bdd_above t) : bdd_above (s ∩ t) := h.mono $ inter_subset_right s t /-- If `s` is bounded, then so is `s ∩ t` -/ lemma bdd_below.inter_of_left (h : bdd_below s) : bdd_below (s ∩ t) := h.mono $ inter_subset_left s t /-- If `t` is bounded, then so is `s ∩ t` -/ lemma bdd_below.inter_of_right (h : bdd_below t) : bdd_below (s ∩ t) := h.mono $ inter_subset_right s t /-- In a directed order, the union of bounded above sets is bounded above. -/ lemma bdd_above.union [is_directed Ξ± (≀)] {s t : set Ξ±} : bdd_above s β†’ bdd_above t β†’ bdd_above (s βˆͺ t) := begin rintro ⟨a, ha⟩ ⟨b, hb⟩, obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b, rw [bdd_above, upper_bounds_union], exact ⟨c, upper_bounds_mono_mem hca ha, upper_bounds_mono_mem hcb hb⟩, end /-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/ lemma bdd_above_union [is_directed Ξ± (≀)] {s t : set Ξ±} : bdd_above (s βˆͺ t) ↔ bdd_above s ∧ bdd_above t := ⟨λ h, ⟨h.mono $ subset_union_left _ _, h.mono $ subset_union_right _ _⟩, Ξ» h, h.1.union h.2⟩ /-- In a codirected order, the union of bounded below sets is bounded below. -/ lemma bdd_below.union [is_directed Ξ± (β‰₯)] {s t : set Ξ±} : bdd_below s β†’ bdd_below t β†’ bdd_below (s βˆͺ t) := @bdd_above.union Ξ±α΅’α΅ˆ _ _ _ _ /-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/ lemma bdd_below_union [is_directed Ξ± (β‰₯)] {s t : set Ξ±} : bdd_below (s βˆͺ t) ↔ bdd_below s ∧ bdd_below t := @bdd_above_union Ξ±α΅’α΅ˆ _ _ _ _ /-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`, then `a βŠ” b` is the least upper bound of `s βˆͺ t`. -/ lemma is_lub.union [semilattice_sup Ξ³] {a b : Ξ³} {s t : set Ξ³} (hs : is_lub s a) (ht : is_lub t b) : is_lub (s βˆͺ t) (a βŠ” b) := ⟨λ c h, h.cases_on (Ξ» h, le_sup_of_le_left $ hs.left h) (Ξ» h, le_sup_of_le_right $ ht.left h), Ξ» c hc, sup_le (hs.right $ Ξ» d hd, hc $ or.inl hd) (ht.right $ Ξ» d hd, hc $ or.inr hd)⟩ /-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`, then `a βŠ“ b` is the greatest lower bound of `s βˆͺ t`. -/ lemma is_glb.union [semilattice_inf Ξ³] {a₁ aβ‚‚ : Ξ³} {s t : set Ξ³} (hs : is_glb s a₁) (ht : is_glb t aβ‚‚) : is_glb (s βˆͺ t) (a₁ βŠ“ aβ‚‚) := hs.dual.union ht /-- If `a` is the least element of `s` and `b` is the least element of `t`, then `min a b` is the least element of `s βˆͺ t`. -/ lemma is_least.union [linear_order Ξ³] {a b : Ξ³} {s t : set Ξ³} (ha : is_least s a) (hb : is_least t b) : is_least (s βˆͺ t) (min a b) := ⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1], (ha.is_glb.union hb.is_glb).1⟩ /-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`, then `max a b` is the greatest element of `s βˆͺ t`. -/ lemma is_greatest.union [linear_order Ξ³] {a b : Ξ³} {s t : set Ξ³} (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s βˆͺ t) (max a b) := ⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1], (ha.is_lub.union hb.is_lub).1⟩ lemma is_lub.inter_Ici_of_mem [linear_order Ξ³] {s : set Ξ³} {a b : Ξ³} (ha : is_lub s a) (hb : b ∈ s) : is_lub (s ∩ Ici b) a := ⟨λ x hx, ha.1 hx.1, Ξ» c hc, have hbc : b ≀ c, from hc ⟨hb, le_rfl⟩, ha.2 $ Ξ» x hx, (le_total x b).elim (Ξ» hxb, hxb.trans hbc) $ Ξ» hbx, hc ⟨hx, hbx⟩⟩ lemma is_glb.inter_Iic_of_mem [linear_order Ξ³] {s : set Ξ³} {a b : Ξ³} (ha : is_glb s a) (hb : b ∈ s) : is_glb (s ∩ Iic b) a := ha.dual.inter_Ici_of_mem hb lemma bdd_above_iff_exists_ge [semilattice_sup Ξ³] {s : set Ξ³} (xβ‚€ : Ξ³) : bdd_above s ↔ βˆƒ x, xβ‚€ ≀ x ∧ βˆ€ y ∈ s, y ≀ x := by { rw [bdd_above_def, exists_ge_and_iff_exists], exact monotone.ball (Ξ» x hx, monotone_le) } lemma bdd_below_iff_exists_le [semilattice_inf Ξ³] {s : set Ξ³} (xβ‚€ : Ξ³) : bdd_below s ↔ βˆƒ x, x ≀ xβ‚€ ∧ βˆ€ y ∈ s, x ≀ y := bdd_above_iff_exists_ge (to_dual xβ‚€) lemma bdd_above.exists_ge [semilattice_sup Ξ³] {s : set Ξ³} (hs : bdd_above s) (xβ‚€ : Ξ³) : βˆƒ x, xβ‚€ ≀ x ∧ βˆ€ y ∈ s, y ≀ x := (bdd_above_iff_exists_ge xβ‚€).mp hs lemma bdd_below.exists_le [semilattice_inf Ξ³] {s : set Ξ³} (hs : bdd_below s) (xβ‚€ : Ξ³) : βˆƒ x, x ≀ xβ‚€ ∧ βˆ€ y ∈ s, x ≀ y := (bdd_below_iff_exists_le xβ‚€).mp hs /-! ### Specific sets #### Unbounded intervals -/ lemma is_least_Ici : is_least (Ici a) a := ⟨left_mem_Ici, Ξ» x, id⟩ lemma is_greatest_Iic : is_greatest (Iic a) a := ⟨right_mem_Iic, Ξ» x, id⟩ lemma is_lub_Iic : is_lub (Iic a) a := is_greatest_Iic.is_lub lemma is_glb_Ici : is_glb (Ici a) a := is_least_Ici.is_glb lemma upper_bounds_Iic : upper_bounds (Iic a) = Ici a := is_lub_Iic.upper_bounds_eq lemma lower_bounds_Ici : lower_bounds (Ici a) = Iic a := is_glb_Ici.lower_bounds_eq lemma bdd_above_Iic : bdd_above (Iic a) := is_lub_Iic.bdd_above lemma bdd_below_Ici : bdd_below (Ici a) := is_glb_Ici.bdd_below lemma bdd_above_Iio : bdd_above (Iio a) := ⟨a, Ξ» x hx, le_of_lt hx⟩ lemma bdd_below_Ioi : bdd_below (Ioi a) := ⟨a, Ξ» x hx, le_of_lt hx⟩ lemma lub_Iio_le (a : Ξ±) (hb : is_lub (set.Iio a) b) : b ≀ a := (is_lub_le_iff hb).mpr $ Ξ» k hk, le_of_lt hk lemma le_glb_Ioi (a : Ξ±) (hb : is_glb (set.Ioi a) b) : a ≀ b := @lub_Iio_le Ξ±α΅’α΅ˆ _ _ a hb lemma lub_Iio_eq_self_or_Iio_eq_Iic [partial_order Ξ³] {j : Ξ³} (i : Ξ³) (hj : is_lub (set.Iio i) j) : j = i ∨ set.Iio i = set.Iic j := begin cases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i, { exact or.inl hj_eq_i, }, { right, exact set.ext (Ξ» k, ⟨λ hk_lt, hj.1 hk_lt, Ξ» hk_le_j, lt_of_le_of_lt hk_le_j hj_lt_i⟩), }, end lemma glb_Ioi_eq_self_or_Ioi_eq_Ici [partial_order Ξ³] {j : Ξ³} (i : Ξ³) (hj : is_glb (set.Ioi i) j) : j = i ∨ set.Ioi i = set.Ici j := @lub_Iio_eq_self_or_Iio_eq_Iic Ξ³α΅’α΅ˆ _ j i hj section variables [linear_order Ξ³] lemma exists_lub_Iio (i : Ξ³) : βˆƒ j, is_lub (set.Iio i) j := begin by_cases h_exists_lt : βˆƒ j, j ∈ upper_bounds (set.Iio i) ∧ j < i, { obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt, exact ⟨j, hj_ub, Ξ» k hk_ub, hk_ub hj_lt_i⟩, }, { refine ⟨i, Ξ» j hj, le_of_lt hj, _⟩, rw mem_lower_bounds, by_contra, refine h_exists_lt _, push_neg at h, exact h, }, end lemma exists_glb_Ioi (i : Ξ³) : βˆƒ j, is_glb (set.Ioi i) j := @exists_lub_Iio Ξ³α΅’α΅ˆ _ i variables [densely_ordered Ξ³] lemma is_lub_Iio {a : Ξ³} : is_lub (Iio a) a := ⟨λ x hx, le_of_lt hx, Ξ» y hy, le_of_forall_ge_of_dense hy⟩ lemma is_glb_Ioi {a : Ξ³} : is_glb (Ioi a) a := @is_lub_Iio Ξ³α΅’α΅ˆ _ _ a lemma upper_bounds_Iio {a : Ξ³} : upper_bounds (Iio a) = Ici a := is_lub_Iio.upper_bounds_eq lemma lower_bounds_Ioi {a : Ξ³} : lower_bounds (Ioi a) = Iic a := is_glb_Ioi.lower_bounds_eq end /-! #### Singleton -/ lemma is_greatest_singleton : is_greatest {a} a := ⟨mem_singleton a, Ξ» x hx, le_of_eq $ eq_of_mem_singleton hx⟩ lemma is_least_singleton : is_least {a} a := @is_greatest_singleton Ξ±α΅’α΅ˆ _ a lemma is_lub_singleton : is_lub {a} a := is_greatest_singleton.is_lub lemma is_glb_singleton : is_glb {a} a := is_least_singleton.is_glb lemma bdd_above_singleton : bdd_above ({a} : set Ξ±) := is_lub_singleton.bdd_above lemma bdd_below_singleton : bdd_below ({a} : set Ξ±) := is_glb_singleton.bdd_below @[simp] lemma upper_bounds_singleton : upper_bounds {a} = Ici a := is_lub_singleton.upper_bounds_eq @[simp] lemma lower_bounds_singleton : lower_bounds {a} = Iic a := is_glb_singleton.lower_bounds_eq /-! #### Bounded intervals -/ lemma bdd_above_Icc : bdd_above (Icc a b) := ⟨b, Ξ» _, and.right⟩ lemma bdd_below_Icc : bdd_below (Icc a b) := ⟨a, Ξ» _, and.left⟩ lemma bdd_above_Ico : bdd_above (Ico a b) := bdd_above_Icc.mono Ico_subset_Icc_self lemma bdd_below_Ico : bdd_below (Ico a b) := bdd_below_Icc.mono Ico_subset_Icc_self lemma bdd_above_Ioc : bdd_above (Ioc a b) := bdd_above_Icc.mono Ioc_subset_Icc_self lemma bdd_below_Ioc : bdd_below (Ioc a b) := bdd_below_Icc.mono Ioc_subset_Icc_self lemma bdd_above_Ioo : bdd_above (Ioo a b) := bdd_above_Icc.mono Ioo_subset_Icc_self lemma bdd_below_Ioo : bdd_below (Ioo a b) := bdd_below_Icc.mono Ioo_subset_Icc_self lemma is_greatest_Icc (h : a ≀ b) : is_greatest (Icc a b) b := ⟨right_mem_Icc.2 h, Ξ» x, and.right⟩ lemma is_lub_Icc (h : a ≀ b) : is_lub (Icc a b) b := (is_greatest_Icc h).is_lub lemma upper_bounds_Icc (h : a ≀ b) : upper_bounds (Icc a b) = Ici b := (is_lub_Icc h).upper_bounds_eq lemma is_least_Icc (h : a ≀ b) : is_least (Icc a b) a := ⟨left_mem_Icc.2 h, Ξ» x, and.left⟩ lemma is_glb_Icc (h : a ≀ b) : is_glb (Icc a b) a := (is_least_Icc h).is_glb lemma lower_bounds_Icc (h : a ≀ b) : lower_bounds (Icc a b) = Iic a := (is_glb_Icc h).lower_bounds_eq lemma is_greatest_Ioc (h : a < b) : is_greatest (Ioc a b) b := ⟨right_mem_Ioc.2 h, Ξ» x, and.right⟩ lemma is_lub_Ioc (h : a < b) : is_lub (Ioc a b) b := (is_greatest_Ioc h).is_lub lemma upper_bounds_Ioc (h : a < b) : upper_bounds (Ioc a b) = Ici b := (is_lub_Ioc h).upper_bounds_eq lemma is_least_Ico (h : a < b) : is_least (Ico a b) a := ⟨left_mem_Ico.2 h, Ξ» x, and.left⟩ lemma is_glb_Ico (h : a < b) : is_glb (Ico a b) a := (is_least_Ico h).is_glb lemma lower_bounds_Ico (h : a < b) : lower_bounds (Ico a b) = Iic a := (is_glb_Ico h).lower_bounds_eq section variables [semilattice_sup Ξ³] [densely_ordered Ξ³] lemma is_glb_Ioo {a b : Ξ³} (h : a < b) : is_glb (Ioo a b) a := ⟨λ x hx, hx.1.le, Ξ» x hx, begin cases eq_or_lt_of_le (le_sup_right : a ≀ x βŠ” a) with h₁ hβ‚‚, { exact h₁.symm β–Έ le_sup_left }, obtain ⟨y, lty, ylt⟩ := exists_between hβ‚‚, apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim, obtain ⟨u, au, ub⟩ := exists_between h, apply (hx ⟨au, ub⟩).trans ub.le, end⟩ lemma lower_bounds_Ioo {a b : Ξ³} (hab : a < b) : lower_bounds (Ioo a b) = Iic a := (is_glb_Ioo hab).lower_bounds_eq lemma is_glb_Ioc {a b : Ξ³} (hab : a < b) : is_glb (Ioc a b) a := (is_glb_Ioo hab).of_subset_of_superset (is_glb_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self lemma lower_bound_Ioc {a b : Ξ³} (hab : a < b) : lower_bounds (Ioc a b) = Iic a := (is_glb_Ioc hab).lower_bounds_eq end section variables [semilattice_inf Ξ³] [densely_ordered Ξ³] lemma is_lub_Ioo {a b : Ξ³} (hab : a < b) : is_lub (Ioo a b) b := by simpa only [dual_Ioo] using is_glb_Ioo hab.dual lemma upper_bounds_Ioo {a b : Ξ³} (hab : a < b) : upper_bounds (Ioo a b) = Ici b := (is_lub_Ioo hab).upper_bounds_eq lemma is_lub_Ico {a b : Ξ³} (hab : a < b) : is_lub (Ico a b) b := by simpa only [dual_Ioc] using is_glb_Ioc hab.dual lemma upper_bounds_Ico {a b : Ξ³} (hab : a < b) : upper_bounds (Ico a b) = Ici b := (is_lub_Ico hab).upper_bounds_eq end lemma bdd_below_iff_subset_Ici : bdd_below s ↔ βˆƒ a, s βŠ† Ici a := iff.rfl lemma bdd_above_iff_subset_Iic : bdd_above s ↔ βˆƒ a, s βŠ† Iic a := iff.rfl lemma bdd_below_bdd_above_iff_subset_Icc : bdd_below s ∧ bdd_above s ↔ βˆƒ a b, s βŠ† Icc a b := by simp only [Ici_inter_Iic.symm, subset_inter_iff, bdd_below_iff_subset_Ici, bdd_above_iff_subset_Iic, exists_and_distrib_left, exists_and_distrib_right] /-! #### Univ -/ @[simp] lemma is_greatest_univ_iff : is_greatest univ a ↔ is_top a := by simp [is_greatest, mem_upper_bounds, is_top] lemma is_greatest_univ [order_top Ξ±] : is_greatest (univ : set Ξ±) ⊀ := is_greatest_univ_iff.2 is_top_top @[simp] lemma order_top.upper_bounds_univ [partial_order Ξ³] [order_top Ξ³] : upper_bounds (univ : set Ξ³) = {⊀} := by rw [is_greatest_univ.upper_bounds_eq, Ici_top] lemma is_lub_univ [order_top Ξ±] : is_lub (univ : set Ξ±) ⊀ := is_greatest_univ.is_lub @[simp] lemma order_bot.lower_bounds_univ [partial_order Ξ³] [order_bot Ξ³] : lower_bounds (univ : set Ξ³) = {βŠ₯} := @order_top.upper_bounds_univ Ξ³α΅’α΅ˆ _ _ @[simp] lemma is_least_univ_iff : is_least univ a ↔ is_bot a := @is_greatest_univ_iff Ξ±α΅’α΅ˆ _ _ lemma is_least_univ [order_bot Ξ±] : is_least (univ : set Ξ±) βŠ₯ := @is_greatest_univ Ξ±α΅’α΅ˆ _ _ lemma is_glb_univ [order_bot Ξ±] : is_glb (univ : set Ξ±) βŠ₯ := is_least_univ.is_glb @[simp] lemma no_max_order.upper_bounds_univ [no_max_order Ξ±] : upper_bounds (univ : set Ξ±) = βˆ… := eq_empty_of_subset_empty $ Ξ» b hb, let ⟨x, hx⟩ := exists_gt b in not_le_of_lt hx (hb trivial) @[simp] lemma no_min_order.lower_bounds_univ [no_min_order Ξ±] : lower_bounds (univ : set Ξ±) = βˆ… := @no_max_order.upper_bounds_univ Ξ±α΅’α΅ˆ _ _ @[simp] lemma not_bdd_above_univ [no_max_order Ξ±] : Β¬bdd_above (univ : set Ξ±) := by simp [bdd_above] @[simp] lemma not_bdd_below_univ [no_min_order Ξ±] : Β¬bdd_below (univ : set Ξ±) := @not_bdd_above_univ Ξ±α΅’α΅ˆ _ _ /-! #### Empty set -/ @[simp] lemma upper_bounds_empty : upper_bounds (βˆ… : set Ξ±) = univ := by simp only [upper_bounds, eq_univ_iff_forall, mem_set_of_eq, ball_empty_iff, forall_true_iff] @[simp] lemma lower_bounds_empty : lower_bounds (βˆ… : set Ξ±) = univ := @upper_bounds_empty Ξ±α΅’α΅ˆ _ @[simp] lemma bdd_above_empty [nonempty Ξ±] : bdd_above (βˆ… : set Ξ±) := by simp only [bdd_above, upper_bounds_empty, univ_nonempty] @[simp] lemma bdd_below_empty [nonempty Ξ±] : bdd_below (βˆ… : set Ξ±) := by simp only [bdd_below, lower_bounds_empty, univ_nonempty] @[simp] lemma is_glb_empty_iff : is_glb βˆ… a ↔ is_top a := by simp [is_glb] @[simp] lemma is_lub_empty_iff : is_lub βˆ… a ↔ is_bot a := @is_glb_empty_iff Ξ±α΅’α΅ˆ _ _ lemma is_glb_empty [order_top Ξ±] : is_glb βˆ… (⊀:Ξ±) := is_glb_empty_iff.2 is_top_top lemma is_lub_empty [order_bot Ξ±] : is_lub βˆ… (βŠ₯:Ξ±) := @is_glb_empty Ξ±α΅’α΅ˆ _ _ lemma is_lub.nonempty [no_min_order Ξ±] (hs : is_lub s a) : s.nonempty := let ⟨a', ha'⟩ := exists_lt a in nonempty_iff_ne_empty.2 $ Ξ» h, not_le_of_lt ha' $ hs.right $ by simp only [h, upper_bounds_empty] lemma is_glb.nonempty [no_max_order Ξ±] (hs : is_glb s a) : s.nonempty := hs.dual.nonempty lemma nonempty_of_not_bdd_above [ha : nonempty Ξ±] (h : Β¬bdd_above s) : s.nonempty := nonempty.elim ha $ Ξ» x, (not_bdd_above_iff'.1 h x).imp $ Ξ» a ha, ha.fst lemma nonempty_of_not_bdd_below [ha : nonempty Ξ±] (h : Β¬bdd_below s) : s.nonempty := @nonempty_of_not_bdd_above Ξ±α΅’α΅ˆ _ _ _ h /-! #### insert -/ /-- Adding a point to a set preserves its boundedness above. -/ @[simp] lemma bdd_above_insert [is_directed Ξ± (≀)] {s : set Ξ±} {a : Ξ±} : bdd_above (insert a s) ↔ bdd_above s := by simp only [insert_eq, bdd_above_union, bdd_above_singleton, true_and] protected lemma bdd_above.insert [is_directed Ξ± (≀)] {s : set Ξ±} (a : Ξ±) : bdd_above s β†’ bdd_above (insert a s) := bdd_above_insert.2 /--Adding a point to a set preserves its boundedness below.-/ @[simp] lemma bdd_below_insert [is_directed Ξ± (β‰₯)] {s : set Ξ±} {a : Ξ±} : bdd_below (insert a s) ↔ bdd_below s := by simp only [insert_eq, bdd_below_union, bdd_below_singleton, true_and] lemma bdd_below.insert [is_directed Ξ± (β‰₯)] {s : set Ξ±} (a : Ξ±) : bdd_below s β†’ bdd_below (insert a s) := bdd_below_insert.2 lemma is_lub.insert [semilattice_sup Ξ³] (a) {b} {s : set Ξ³} (hs : is_lub s b) : is_lub (insert a s) (a βŠ” b) := by { rw insert_eq, exact is_lub_singleton.union hs } lemma is_glb.insert [semilattice_inf Ξ³] (a) {b} {s : set Ξ³} (hs : is_glb s b) : is_glb (insert a s) (a βŠ“ b) := by { rw insert_eq, exact is_glb_singleton.union hs } lemma is_greatest.insert [linear_order Ξ³] (a) {b} {s : set Ξ³} (hs : is_greatest s b) : is_greatest (insert a s) (max a b) := by { rw insert_eq, exact is_greatest_singleton.union hs } lemma is_least.insert [linear_order Ξ³] (a) {b} {s : set Ξ³} (hs : is_least s b) : is_least (insert a s) (min a b) := by { rw insert_eq, exact is_least_singleton.union hs } @[simp] lemma upper_bounds_insert (a : Ξ±) (s : set Ξ±) : upper_bounds (insert a s) = Ici a ∩ upper_bounds s := by rw [insert_eq, upper_bounds_union, upper_bounds_singleton] @[simp] lemma lower_bounds_insert (a : Ξ±) (s : set Ξ±) : lower_bounds (insert a s) = Iic a ∩ lower_bounds s := by rw [insert_eq, lower_bounds_union, lower_bounds_singleton] /-- When there is a global maximum, every set is bounded above. -/ @[simp] protected lemma order_top.bdd_above [order_top Ξ±] (s : set Ξ±) : bdd_above s := ⟨⊀, Ξ» a ha, order_top.le_top a⟩ /-- When there is a global minimum, every set is bounded below. -/ @[simp] protected lemma order_bot.bdd_below [order_bot Ξ±] (s : set Ξ±) : bdd_below s := ⟨βŠ₯, Ξ» a ha, order_bot.bot_le a⟩ /-! #### Pair -/ lemma is_lub_pair [semilattice_sup Ξ³] {a b : Ξ³} : is_lub {a, b} (a βŠ” b) := is_lub_singleton.insert _ lemma is_glb_pair [semilattice_inf Ξ³] {a b : Ξ³} : is_glb {a, b} (a βŠ“ b) := is_glb_singleton.insert _ lemma is_least_pair [linear_order Ξ³] {a b : Ξ³} : is_least {a, b} (min a b) := is_least_singleton.insert _ lemma is_greatest_pair [linear_order Ξ³] {a b : Ξ³} : is_greatest {a, b} (max a b) := is_greatest_singleton.insert _ /-! #### Lower/upper bounds -/ @[simp] lemma is_lub_lower_bounds : is_lub (lower_bounds s) a ↔ is_glb s a := ⟨λ H, ⟨λ x hx, H.2 $ subset_upper_bounds_lower_bounds s hx, H.1⟩, is_greatest.is_lub⟩ @[simp] lemma is_glb_upper_bounds : is_glb (upper_bounds s) a ↔ is_lub s a := @is_lub_lower_bounds Ξ±α΅’α΅ˆ _ _ _ end /-! ### (In)equalities with the least upper bound and the greatest lower bound -/ section preorder variables [preorder Ξ±] {s : set Ξ±} {a b : Ξ±} lemma lower_bounds_le_upper_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds s) : s.nonempty β†’ a ≀ b | ⟨c, hc⟩ := le_trans (ha hc) (hb hc) lemma is_glb_le_is_lub (ha : is_glb s a) (hb : is_lub s b) (hs : s.nonempty) : a ≀ b := lower_bounds_le_upper_bounds ha.1 hb.1 hs lemma is_lub_lt_iff (ha : is_lub s a) : a < b ↔ βˆƒ c ∈ upper_bounds s, c < b := ⟨λ hb, ⟨a, ha.1, hb⟩, Ξ» ⟨c, hcs, hcb⟩, lt_of_le_of_lt (ha.2 hcs) hcb⟩ lemma lt_is_glb_iff (ha : is_glb s a) : b < a ↔ βˆƒ c ∈ lower_bounds s, b < c := is_lub_lt_iff ha.dual lemma le_of_is_lub_le_is_glb {x y} (ha : is_glb s a) (hb : is_lub s b) (hab : b ≀ a) (hx : x ∈ s) (hy : y ∈ s) : x ≀ y := calc x ≀ b : hb.1 hx ... ≀ a : hab ... ≀ y : ha.1 hy end preorder section partial_order variables [partial_order Ξ±] {s : set Ξ±} {a b : Ξ±} lemma is_least.unique (Ha : is_least s a) (Hb : is_least s b) : a = b := le_antisymm (Ha.right Hb.left) (Hb.right Ha.left) lemma is_least.is_least_iff_eq (Ha : is_least s a) : is_least s b ↔ a = b := iff.intro Ha.unique (Ξ» h, h β–Έ Ha) lemma is_greatest.unique (Ha : is_greatest s a) (Hb : is_greatest s b) : a = b := le_antisymm (Hb.right Ha.left) (Ha.right Hb.left) lemma is_greatest.is_greatest_iff_eq (Ha : is_greatest s a) : is_greatest s b ↔ a = b := iff.intro Ha.unique (Ξ» h, h β–Έ Ha) lemma is_lub.unique (Ha : is_lub s a) (Hb : is_lub s b) : a = b := Ha.unique Hb lemma is_glb.unique (Ha : is_glb s a) (Hb : is_glb s b) : a = b := Ha.unique Hb lemma set.subsingleton_of_is_lub_le_is_glb (Ha : is_glb s a) (Hb : is_lub s b) (hab : b ≀ a) : s.subsingleton := Ξ» x hx y hy, le_antisymm (le_of_is_lub_le_is_glb Ha Hb hab hx hy) (le_of_is_lub_le_is_glb Ha Hb hab hy hx) lemma is_glb_lt_is_lub_of_ne (Ha : is_glb s a) (Hb : is_lub s b) {x y} (Hx : x ∈ s) (Hy : y ∈ s) (Hxy : x β‰  y) : a < b := lt_iff_le_not_le.2 ⟨lower_bounds_le_upper_bounds Ha.1 Hb.1 ⟨x, Hx⟩, Ξ» hab, Hxy $ set.subsingleton_of_is_lub_le_is_glb Ha Hb hab Hx Hy⟩ end partial_order section linear_order variables [linear_order Ξ±] {s : set Ξ±} {a b : Ξ±} lemma lt_is_lub_iff (h : is_lub s a) : b < a ↔ βˆƒ c ∈ s, b < c := by simp only [← not_le, is_lub_le_iff h, mem_upper_bounds, not_forall] lemma is_glb_lt_iff (h : is_glb s a) : a < b ↔ βˆƒ c ∈ s, c < b := lt_is_lub_iff h.dual lemma is_lub.exists_between (h : is_lub s a) (hb : b < a) : βˆƒ c ∈ s, b < c ∧ c ≀ a := let ⟨c, hcs, hbc⟩ := (lt_is_lub_iff h).1 hb in ⟨c, hcs, hbc, h.1 hcs⟩ lemma is_lub.exists_between' (h : is_lub s a) (h' : a βˆ‰ s) (hb : b < a) : βˆƒ c ∈ s, b < c ∧ c < a := let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb in ⟨c, hcs, hbc, hca.lt_of_ne $ Ξ» hac, h' $ hac β–Έ hcs⟩ lemma is_glb.exists_between (h : is_glb s a) (hb : a < b) : βˆƒ c ∈ s, a ≀ c ∧ c < b := let ⟨c, hcs, hbc⟩ := (is_glb_lt_iff h).1 hb in ⟨c, hcs, h.1 hcs, hbc⟩ lemma is_glb.exists_between' (h : is_glb s a) (h' : a βˆ‰ s) (hb : a < b) : βˆƒ c ∈ s, a < c ∧ c < b := let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb in ⟨c, hcs, hac.lt_of_ne $ Ξ» hac, h' $ hac.symm β–Έ hcs, hcb⟩ end linear_order /-! ### Images of upper/lower bounds under monotone functions -/ namespace monotone_on variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} {s t : set Ξ±} (Hf : monotone_on f t) {a : Ξ±} (Hst : s βŠ† t) include Hf lemma mem_upper_bounds_image (Has : a ∈ upper_bounds s) (Hat : a ∈ t) : f a ∈ upper_bounds (f '' s) := ball_image_of_ball (Ξ» x H, Hf (Hst H) Hat (Has H)) lemma mem_upper_bounds_image_self : a ∈ upper_bounds t β†’ a ∈ t β†’ f a ∈ upper_bounds (f '' t) := Hf.mem_upper_bounds_image subset_rfl lemma mem_lower_bounds_image (Has : a ∈ lower_bounds s) (Hat : a ∈ t) : f a ∈ lower_bounds (f '' s) := ball_image_of_ball (Ξ» x H, Hf Hat (Hst H) (Has H)) lemma mem_lower_bounds_image_self : a ∈ lower_bounds t β†’ a ∈ t β†’ f a ∈ lower_bounds (f '' t) := Hf.mem_lower_bounds_image subset_rfl lemma image_upper_bounds_subset_upper_bounds_image (Hst : s βŠ† t) : f '' (upper_bounds s ∩ t) βŠ† upper_bounds (f '' s) := by { rintro _ ⟨a, ha, rfl⟩, exact Hf.mem_upper_bounds_image Hst ha.1 ha.2 } lemma image_lower_bounds_subset_lower_bounds_image : f '' (lower_bounds s ∩ t) βŠ† lower_bounds (f '' s) := Hf.dual.image_upper_bounds_subset_upper_bounds_image Hst /-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t` is bounded above. -/ lemma map_bdd_above : (upper_bounds s ∩ t).nonempty β†’ bdd_above (f '' s) := Ξ» ⟨C, hs, ht⟩, ⟨f C, Hf.mem_upper_bounds_image Hst hs ht⟩ /-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t` is bounded below. -/ lemma map_bdd_below : (lower_bounds s ∩ t).nonempty β†’ bdd_below (f '' s) := Ξ» ⟨C, hs, ht⟩, ⟨f C, Hf.mem_lower_bounds_image Hst hs ht⟩ /-- A monotone map sends a least element of a set to a least element of its image. -/ lemma map_is_least (Ha : is_least t a) : is_least (f '' t) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image_self Ha.2 Ha.1⟩ /-- A monotone map sends a greatest element of a set to a greatest element of its image. -/ lemma map_is_greatest (Ha : is_greatest t a) : is_greatest (f '' t) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image_self Ha.2 Ha.1⟩ end monotone_on namespace antitone_on variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} {s t : set Ξ±} (Hf : antitone_on f t) {a : Ξ±} (Hst : s βŠ† t) include Hf lemma mem_upper_bounds_image (Has : a ∈ lower_bounds s) : a ∈ t β†’ f a ∈ upper_bounds (f '' s) := Hf.dual_right.mem_lower_bounds_image Hst Has lemma mem_upper_bounds_image_self : a ∈ lower_bounds t β†’ a ∈ t β†’ f a ∈ upper_bounds (f '' t) := Hf.dual_right.mem_lower_bounds_image_self lemma mem_lower_bounds_image : a ∈ upper_bounds s β†’ a ∈ t β†’ f a ∈ lower_bounds (f '' s) := Hf.dual_right.mem_upper_bounds_image Hst lemma mem_lower_bounds_image_self : a ∈ upper_bounds t β†’ a ∈ t β†’ f a ∈ lower_bounds (f '' t) := Hf.dual_right.mem_upper_bounds_image_self lemma image_lower_bounds_subset_upper_bounds_image : f '' (lower_bounds s ∩ t) βŠ† upper_bounds (f '' s) := Hf.dual_right.image_lower_bounds_subset_lower_bounds_image Hst lemma image_upper_bounds_subset_lower_bounds_image : f '' (upper_bounds s ∩ t) βŠ† lower_bounds (f '' s) := Hf.dual_right.image_upper_bounds_subset_upper_bounds_image Hst /-- The image under an antitone function of a set which is bounded above is bounded below. -/ lemma map_bdd_above : (upper_bounds s ∩ t).nonempty β†’ bdd_below (f '' s) := Hf.dual_right.map_bdd_above Hst /-- The image under an antitone function of a set which is bounded below is bounded above. -/ lemma map_bdd_below : (lower_bounds s ∩ t).nonempty β†’ bdd_above (f '' s) := Hf.dual_right.map_bdd_below Hst /-- An antitone map sends a greatest element of a set to a least element of its image. -/ lemma map_is_greatest : is_greatest t a β†’ is_least (f '' t) (f a) := Hf.dual_right.map_is_greatest /-- An antitone map sends a least element of a set to a greatest element of its image. -/ lemma map_is_least : is_least t a β†’ is_greatest (f '' t) (f a) := Hf.dual_right.map_is_least end antitone_on namespace monotone variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} (Hf : monotone f) {a : Ξ±} {s : set Ξ±} include Hf lemma mem_upper_bounds_image (Ha : a ∈ upper_bounds s) : f a ∈ upper_bounds (f '' s) := ball_image_of_ball (Ξ» x H, Hf (Ha H)) lemma mem_lower_bounds_image (Ha : a ∈ lower_bounds s) : f a ∈ lower_bounds (f '' s) := ball_image_of_ball (Ξ» x H, Hf (Ha H)) lemma image_upper_bounds_subset_upper_bounds_image : f '' upper_bounds s βŠ† upper_bounds (f '' s) := by { rintro _ ⟨a, ha, rfl⟩, exact Hf.mem_upper_bounds_image ha } lemma image_lower_bounds_subset_lower_bounds_image : f '' lower_bounds s βŠ† lower_bounds (f '' s) := Hf.dual.image_upper_bounds_subset_upper_bounds_image /-- The image under a monotone function of a set which is bounded above is bounded above. See also `bdd_above.image2`. -/ lemma map_bdd_above : bdd_above s β†’ bdd_above (f '' s) | ⟨C, hC⟩ := ⟨f C, Hf.mem_upper_bounds_image hC⟩ /-- The image under a monotone function of a set which is bounded below is bounded below. See also `bdd_below.image2`. -/ lemma map_bdd_below : bdd_below s β†’ bdd_below (f '' s) | ⟨C, hC⟩ := ⟨f C, Hf.mem_lower_bounds_image hC⟩ /-- A monotone map sends a least element of a set to a least element of its image. -/ lemma map_is_least (Ha : is_least s a) : is_least (f '' s) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image Ha.2⟩ /-- A monotone map sends a greatest element of a set to a greatest element of its image. -/ lemma map_is_greatest (Ha : is_greatest s a) : is_greatest (f '' s) (f a) := ⟨mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image Ha.2⟩ end monotone namespace antitone variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} (hf : antitone f) {a : Ξ±} {s : set Ξ±} lemma mem_upper_bounds_image : a ∈ lower_bounds s β†’ f a ∈ upper_bounds (f '' s) := hf.dual_right.mem_lower_bounds_image lemma mem_lower_bounds_image : a ∈ upper_bounds s β†’ f a ∈ lower_bounds (f '' s) := hf.dual_right.mem_upper_bounds_image lemma image_lower_bounds_subset_upper_bounds_image : f '' lower_bounds s βŠ† upper_bounds (f '' s) := hf.dual_right.image_lower_bounds_subset_lower_bounds_image lemma image_upper_bounds_subset_lower_bounds_image : f '' upper_bounds s βŠ† lower_bounds (f '' s) := hf.dual_right.image_upper_bounds_subset_upper_bounds_image /-- The image under an antitone function of a set which is bounded above is bounded below. -/ lemma map_bdd_above : bdd_above s β†’ bdd_below (f '' s) := hf.dual_right.map_bdd_above /-- The image under an antitone function of a set which is bounded below is bounded above. -/ lemma map_bdd_below : bdd_below s β†’ bdd_above (f '' s) := hf.dual_right.map_bdd_below /-- An antitone map sends a greatest element of a set to a least element of its image. -/ lemma map_is_greatest : is_greatest s a β†’ is_least (f '' s) (f a) := hf.dual_right.map_is_greatest /-- An antitone map sends a least element of a set to a greatest element of its image. -/ lemma map_is_least : is_least s a β†’ is_greatest (f '' s) (f a) := hf.dual_right.map_is_least end antitone section image2 variables [preorder Ξ±] [preorder Ξ²] [preorder Ξ³] {f : Ξ± β†’ Ξ² β†’ Ξ³} {s : set Ξ±} {t : set Ξ²} {a : Ξ±} {b : Ξ²} section monotone_monotone variables (hβ‚€ : βˆ€ b, monotone (swap f b)) (h₁ : βˆ€ a, monotone (f a)) include hβ‚€ h₁ lemma mem_upper_bounds_image2 (ha : a ∈ upper_bounds s) (hb : b ∈ upper_bounds t) : f a b ∈ upper_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma mem_lower_bounds_image2 (ha : a ∈ lower_bounds s) (hb : b ∈ lower_bounds t) : f a b ∈ lower_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma image2_upper_bounds_upper_bounds_subset : image2 f (upper_bounds s) (upper_bounds t) βŠ† upper_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_upper_bounds_image2 hβ‚€ h₁ ha hb } lemma image2_lower_bounds_lower_bounds_subset : image2 f (lower_bounds s) (lower_bounds t) βŠ† lower_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_lower_bounds_image2 hβ‚€ h₁ ha hb } /-- See also `monotone.map_bdd_above`. -/ lemma bdd_above.image2 : bdd_above s β†’ bdd_above t β†’ bdd_above (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_upper_bounds_image2 hβ‚€ h₁ ha hb⟩ } /-- See also `monotone.map_bdd_below`. -/ lemma bdd_below.image2 : bdd_below s β†’ bdd_below t β†’ bdd_below (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_lower_bounds_image2 hβ‚€ h₁ ha hb⟩ } lemma is_greatest.image2 (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2 hβ‚€ h₁ ha.2 hb.2⟩ lemma is_least.image2 (ha : is_least s a) (hb : is_least t b) : is_least (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2 hβ‚€ h₁ ha.2 hb.2⟩ end monotone_monotone section monotone_antitone variables (hβ‚€ : βˆ€ b, monotone (swap f b)) (h₁ : βˆ€ a, antitone (f a)) include hβ‚€ h₁ lemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds (ha : a ∈ upper_bounds s) (hb : b ∈ lower_bounds t) : f a b ∈ upper_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds t) : f a b ∈ lower_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma image2_upper_bounds_lower_bounds_subset_upper_bounds_image2 : image2 f (upper_bounds s) (lower_bounds t) βŠ† upper_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds hβ‚€ h₁ ha hb } lemma image2_lower_bounds_upper_bounds_subset_lower_bounds_image2 : image2 f (lower_bounds s) (upper_bounds t) βŠ† lower_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds hβ‚€ h₁ ha hb } lemma bdd_above.bdd_above_image2_of_bdd_below : bdd_above s β†’ bdd_below t β†’ bdd_above (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds hβ‚€ h₁ ha hb⟩ } lemma bdd_below.bdd_below_image2_of_bdd_above : bdd_below s β†’ bdd_above t β†’ bdd_below (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds hβ‚€ h₁ ha hb⟩ } lemma is_greatest.is_greatest_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) : is_greatest (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_lower_bounds hβ‚€ h₁ ha.2 hb.2⟩ lemma is_least.is_least_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) : is_least (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_upper_bounds hβ‚€ h₁ ha.2 hb.2⟩ end monotone_antitone section antitone_antitone variables (hβ‚€ : βˆ€ b, antitone (swap f b)) (h₁ : βˆ€ a, antitone (f a)) include hβ‚€ h₁ lemma mem_upper_bounds_image2_of_mem_lower_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ lower_bounds t) : f a b ∈ upper_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma mem_lower_bounds_image2_of_mem_upper_bounds (ha : a ∈ upper_bounds s) (hb : b ∈ upper_bounds t) : f a b ∈ lower_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma image2_upper_bounds_upper_bounds_subset_upper_bounds_image2 : image2 f (lower_bounds s) (lower_bounds t) βŠ† upper_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_upper_bounds_image2_of_mem_lower_bounds hβ‚€ h₁ ha hb } lemma image2_lower_bounds_lower_bounds_subset_lower_bounds_image2 : image2 f (upper_bounds s) (upper_bounds t) βŠ† lower_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_lower_bounds_image2_of_mem_upper_bounds hβ‚€ h₁ ha hb } lemma bdd_below.image2_bdd_above : bdd_below s β†’ bdd_below t β†’ bdd_above (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_upper_bounds_image2_of_mem_lower_bounds hβ‚€ h₁ ha hb⟩ } lemma bdd_above.image2_bdd_below : bdd_above s β†’ bdd_above t β†’ bdd_below (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_lower_bounds_image2_of_mem_upper_bounds hβ‚€ h₁ ha hb⟩ } lemma is_least.is_greatest_image2 (ha : is_least s a) (hb : is_least t b) : is_greatest (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2_of_mem_lower_bounds hβ‚€ h₁ ha.2 hb.2⟩ lemma is_greatest.is_least_image2 (ha : is_greatest s a) (hb : is_greatest t b) : is_least (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2_of_mem_upper_bounds hβ‚€ h₁ ha.2 hb.2⟩ end antitone_antitone section antitone_monotone variables (hβ‚€ : βˆ€ b, antitone (swap f b)) (h₁ : βˆ€ a, monotone (f a)) include hβ‚€ h₁ lemma mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds t) : f a b ∈ upper_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds (ha : a ∈ upper_bounds s) (hb : b ∈ lower_bounds t) : f a b ∈ lower_bounds (image2 f s t) := forall_image2_iff.2 $ Ξ» x hx y hy, (hβ‚€ _ $ ha hx).trans $ h₁ _ $ hb hy lemma image2_lower_bounds_upper_bounds_subset_upper_bounds_image2 : image2 f (lower_bounds s) (upper_bounds t) βŠ† upper_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds hβ‚€ h₁ ha hb } lemma image2_upper_bounds_lower_bounds_subset_lower_bounds_image2 : image2 f (upper_bounds s) (lower_bounds t) βŠ† lower_bounds (image2 f s t) := by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds hβ‚€ h₁ ha hb } lemma bdd_below.bdd_above_image2_of_bdd_above : bdd_below s β†’ bdd_above t β†’ bdd_above (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds hβ‚€ h₁ ha hb⟩ } lemma bdd_above.bdd_below_image2_of_bdd_above : bdd_above s β†’ bdd_below t β†’ bdd_below (image2 f s t) := by { rintro ⟨a, ha⟩ ⟨b, hb⟩, exact ⟨f a b, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds hβ‚€ h₁ ha hb⟩ } lemma is_least.is_greatest_image2_of_is_greatest (ha : is_least s a) (hb : is_greatest t b) : is_greatest (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_upper_bounds_image2_of_mem_upper_bounds_of_mem_upper_bounds hβ‚€ h₁ ha.2 hb.2⟩ lemma is_greatest.is_least_image2_of_is_least (ha : is_greatest s a) (hb : is_least t b) : is_least (image2 f s t) (f a b) := ⟨mem_image2_of_mem ha.1 hb.1, mem_lower_bounds_image2_of_mem_lower_bounds_of_mem_lower_bounds hβ‚€ h₁ ha.2 hb.2⟩ end antitone_monotone end image2 lemma is_glb.of_image [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} (hf : βˆ€ {x y}, f x ≀ f y ↔ x ≀ y) {s : set Ξ±} {x : Ξ±} (hx : is_glb (f '' s) (f x)) : is_glb s x := ⟨λ y hy, hf.1 $ hx.1 $ mem_image_of_mem _ hy, Ξ» y hy, hf.1 $ hx.2 $ monotone.mem_lower_bounds_image (Ξ» x y, hf.2) hy⟩ lemma is_lub.of_image [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} (hf : βˆ€ {x y}, f x ≀ f y ↔ x ≀ y) {s : set Ξ±} {x : Ξ±} (hx : is_lub (f '' s) (f x)) : is_lub s x := @is_glb.of_image Ξ±α΅’α΅ˆ Ξ²α΅’α΅ˆ _ _ f (Ξ» x y, hf) _ _ hx lemma is_lub_pi {Ο€ : Ξ± β†’ Type*} [Ξ  a, preorder (Ο€ a)] {s : set (Ξ  a, Ο€ a)} {f : Ξ  a, Ο€ a} : is_lub s f ↔ βˆ€ a, is_lub (function.eval a '' s) (f a) := begin classical, refine ⟨λ H a, ⟨(function.monotone_eval a).mem_upper_bounds_image H.1, Ξ» b hb, _⟩, Ξ» H, ⟨_, _⟩⟩, { suffices : function.update f a b ∈ upper_bounds s, from function.update_same a b f β–Έ H.2 this a, refine Ξ» g hg, le_update_iff.2 ⟨hb $ mem_image_of_mem _ hg, Ξ» i hi, H.1 hg i⟩ }, { exact Ξ» g hg a, (H a).1 (mem_image_of_mem _ hg) }, { exact Ξ» g hg a, (H a).2 ((function.monotone_eval a).mem_upper_bounds_image hg) } end lemma is_glb_pi {Ο€ : Ξ± β†’ Type*} [Ξ  a, preorder (Ο€ a)] {s : set (Ξ  a, Ο€ a)} {f : Ξ  a, Ο€ a} : is_glb s f ↔ βˆ€ a, is_glb (function.eval a '' s) (f a) := @is_lub_pi Ξ± (Ξ» a, (Ο€ a)α΅’α΅ˆ) _ s f lemma is_lub_prod [preorder Ξ±] [preorder Ξ²] {s : set (Ξ± Γ— Ξ²)} (p : Ξ± Γ— Ξ²) : is_lub s p ↔ is_lub (prod.fst '' s) p.1 ∧ is_lub (prod.snd '' s) p.2 := begin refine ⟨λ H, ⟨⟨monotone_fst.mem_upper_bounds_image H.1, Ξ» a ha, _⟩, ⟨monotone_snd.mem_upper_bounds_image H.1, Ξ» a ha, _⟩⟩, Ξ» H, ⟨_, _⟩⟩, { suffices : (a, p.2) ∈ upper_bounds s, from (H.2 this).1, exact Ξ» q hq, ⟨ha $ mem_image_of_mem _ hq, (H.1 hq).2⟩ }, { suffices : (p.1, a) ∈ upper_bounds s, from (H.2 this).2, exact Ξ» q hq, ⟨(H.1 hq).1, ha $ mem_image_of_mem _ hq⟩ }, { exact Ξ» q hq, ⟨H.1.1 $ mem_image_of_mem _ hq, H.2.1 $ mem_image_of_mem _ hq⟩ }, { exact Ξ» q hq, ⟨H.1.2 $ monotone_fst.mem_upper_bounds_image hq, H.2.2 $ monotone_snd.mem_upper_bounds_image hq⟩ } end lemma is_glb_prod [preorder Ξ±] [preorder Ξ²] {s : set (Ξ± Γ— Ξ²)} (p : Ξ± Γ— Ξ²) : is_glb s p ↔ is_glb (prod.fst '' s) p.1 ∧ is_glb (prod.snd '' s) p.2 := @is_lub_prod Ξ±α΅’α΅ˆ Ξ²α΅’α΅ˆ _ _ _ _ section scott_continuous variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β†’ Ξ²} {a : Ξ±} /-- A function between preorders is said to be Scott continuous if it preserves `is_lub` on directed sets. It can be shown that a function is Scott continuous if and only if it is continuous wrt the Scott topology. The dual notion ```lean βˆ€ ⦃d : set α⦄, d.nonempty β†’ directed_on (β‰₯) d β†’ βˆ€ ⦃a⦄, is_glb d a β†’ is_glb (f '' d) (f a) ``` does not appear to play a significant role in the literature, so is omitted here. -/ def scott_continuous (f : Ξ± β†’ Ξ²) : Prop := βˆ€ ⦃d : set α⦄, d.nonempty β†’ directed_on (≀) d β†’ βˆ€ ⦃a⦄, is_lub d a β†’ is_lub (f '' d) (f a) protected lemma scott_continuous.monotone (h : scott_continuous f) : monotone f := begin refine Ξ» a b hab, (h (insert_nonempty _ _) (directed_on_pair le_refl hab) _).1 (mem_image_of_mem _ $ mem_insert _ _), rw [is_lub, upper_bounds_insert, upper_bounds_singleton, inter_eq_self_of_subset_right (Ici_subset_Ici.2 hab)], exact is_least_Ici, end end scott_continuous
d3ecf1f899304a7dcd04c7cc7403836eddeeddaa
54d7e71c3616d331b2ec3845d31deb08f3ff1dea
/tests/lean/run/auto_param_in_structures.lean
18ad7c664cd83bebfe535c53cca5bec0a623cba9
[ "Apache-2.0" ]
permissive
pachugupta/lean
6f3305c4292288311cc4ab4550060b17d49ffb1d
0d02136a09ac4cf27b5c88361750e38e1f485a1a
refs/heads/master
1,611,110,653,606
1,493,130,117,000
1,493,167,649,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
406
lean
namespace test open tactic meta def my_tac : tactic unit := abstract (intros >> simp) structure monoid (Ξ± : Type) := (op : Ξ± β†’ Ξ± β†’ Ξ±) (assoc : βˆ€ a b c, op (op a b) c = op a (op b c) . my_tac) def m1 : monoid nat := monoid.mk add def m2 : monoid nat := monoid.mk mul #print m1 #print m2 def m3 : monoid nat := {op := add} def m4 : monoid nat := {op := mul} #print m3 #print m4 end test
7de977a8aa33f6c52a86b0344955d1b2cdab81ed
1546f9083f4babf70df0329497d1ee05adc8c665
/src/monoidal_categories_reboot/examples/products.lean
877f382fbbefd9bc53ab5c4a5da6e0c12d0dc0fb
[ "Apache-2.0" ]
permissive
khoek/monoidal-categories-reboot
0899b0d4552ff039388042059c91f7207c6c34e5
ed3df8ecce5d4e3d95cb858911bad12bb632cf8a
refs/heads/master
1,588,877,903,131
1,554,987,273,000
1,554,987,273,000
180,791,863
0
0
null
1,554,987,295,000
1,554,987,295,000
null
UTF-8
Lean
false
false
3,507
lean
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison import category_theory.limits.binary_products import category_theory.limits.terminal import category_theory.limits.types import ..braided_monoidal_category open category_theory open category_theory.monoidal universes u v @[obviously] meta def obviously_products := tactic.tidy { tactics := extended_tidy_tactics } namespace category_theory.limits attribute [search] prod.lift_fst prod.lift_snd prod.map_fst prod.map_snd variables {C : Type u} [π’ž : category.{v} C] [has_binary_products.{u v} C] [has_terminal.{u v} C] include π’ž @[simp] def binary_product.braiding (P Q : C) : limits.prod P Q β‰… limits.prod Q P := { hom := prod.lift (prod.snd P Q) (prod.fst P Q), inv := prod.lift (prod.snd Q P) (prod.fst Q P) } def binary_product.symmetry (P Q : C) : (binary_product.braiding P Q).hom ≫ (binary_product.braiding Q P).hom = πŸ™ _ := by tidy @[simp] def binary_product.associativity (P Q R : C) : (limits.prod (limits.prod P Q) R) β‰… (limits.prod P (limits.prod Q R)) := { hom := prod.lift (prod.fst _ _ ≫ prod.fst _ _) (prod.lift (prod.fst _ _ ≫ prod.snd _ _) (prod.snd _ _)), inv := prod.lift (prod.lift (prod.fst _ _) (prod.snd _ _ ≫ prod.fst _ _)) (prod.snd _ _ ≫ prod.snd _ _) } @[simp] def binary_product.left_unitor (P : C) : (limits.prod (terminal.{u v} C) P) β‰… P := { hom := prod.snd _ _, inv := prod.lift (terminal.from P) (πŸ™ _) } @[simp] def binary_product.right_unitor (P : C) : (limits.prod P (terminal.{u v} C)) β‰… P := { hom := prod.fst _ _, inv := prod.lift (πŸ™ _) (terminal.from P) } end category_theory.limits open category_theory.limits namespace category_theory.monoidal variables (C : Type u) [π’ž : category.{v} C] [has_products.{u v} C] include π’ž instance : has_binary_products.{u v} C := has_binary_products_of_has_products instance : has_terminal.{u v} C := has_terminal_of_has_products C -- TODO extract the rewrite proofs obviously produces below. def monoidal_of_has_products : monoidal_category.{v} C := { tensor_obj := Ξ» X Y, limits.prod X Y, tensor_hom := Ξ» _ _ _ _ f g, limits.prod.map f g, tensor_unit := terminal C, associator := binary_product.associativity, left_unitor := binary_product.left_unitor, right_unitor := binary_product.right_unitor, tensor_map_id' := sorry, -- works `by obviously` tensor_map_comp' := sorry, -- works `by obviously` associator_naturality' := sorry, -- works `by obviously` left_unitor_naturality' := sorry, -- works `by obviously right_unitor_naturality' := sorry, -- works `by obviously pentagon' := sorry, -- works `by obviously`, but slow, triangle' := sorry, -- works `by obviously` } def braided_monoidal_of_has_products : braided_monoidal_category.{v} C := { braiding := binary_product.braiding, braiding_naturality' := sorry, -- works `by obviously` hexagon_forward' := sorry, -- works `by obviously`, but slow, hexagon_reverse' := sorry, -- works `by obviously`, but slow .. monoidal_of_has_products C } def symmetric_monoidal_of_has_products : symmetric_monoidal_category.{v} C := { symmetry' := binary_product.symmetry, .. braided_monoidal_of_has_products C } end category_theory.monoidal open category_theory.monoidal instance Type_symmetric : symmetric_monoidal_category.{u+1 u} (Type u) := symmetric_monoidal_of_has_products (Type u)
7784f74cc21c97efa2320daf68c052f32df58517
3af272061d36e7f3f0521cceaa3a847ed4e03af9
/src/monoid_stuff.lean
44df173d03abff398bc0098e1d5800c15fc03a52
[]
no_license
semorrison/kbb
fdab0929d21dca880d835081814225a95f946187
229bd06e840bc7a7438b8fee6802a4f8024419e3
refs/heads/master
1,585,351,834,355
1,539,848,241,000
1,539,848,241,000
147,323,315
2
1
null
null
null
null
UTF-8
Lean
false
false
502
lean
import algebra.group import group_theory.subgroup universes u v namespace units variables {Ξ± : Type u} {Ξ² : Type v} [monoid Ξ±] [monoid Ξ²] (f : Ξ± β†’ Ξ²) [is_monoid_hom f] definition map : units Ξ± β†’ units Ξ² := Ξ» u, ⟨f u.val, f u.inv, by rw [← is_monoid_hom.map_mul f, u.val_inv, is_monoid_hom.map_one f], by rw [← is_monoid_hom.map_mul f, u.inv_val, is_monoid_hom.map_one f] ⟩ instance : is_group_hom (units.map f) := ⟨λ a b, by ext; exact is_monoid_hom.map_mul f ⟩ end units
79e6f1bcad756e3c55f84de72d9d962225a962b4
892c0ca8b8ddfe17a2c64fb7b721f9e2d9287539
/checking.lean
82f5c43446bbe379ff84712e324711ab439e5fe2
[]
no_license
ssomayyajula/stlc
f7ef96de541f9519b00912337332366317282dce
cf92bf387b4418f9a6261c7ea4876db4e4280dd2
refs/heads/master
1,630,729,373,254
1,516,045,347,000
1,516,045,347,000
115,835,353
5
0
null
null
null
null
UTF-8
Lean
false
false
2,448
lean
import .syntax .typing .partial_fun -- Encodes an typechecking algorithm /-instance {Ξ“ : ctx} {e : term} {Ο„ : type} : decidable (has_type_under Ξ“ e Ο„) := begin induction e generalizing Ξ“ Ο„, case term.unit { cases Ο„, { right, apply has_type_under.unit }, { left, intro t, cases t } }, case term.var x { by_cases (Ξ“ x = some Ο„), { right, apply has_type_under.var, assumption }, { left, intro t, cases t, contradiction } }, case term.abs x Ο„' e ih { cases Ο„, case type.unit { left, intro t, cases t }, case type.func Ο„'' Ο„ { cases @ih (extend Ξ“ x Ο„') Ο„, { left, intro t, cases t, contradiction }, { by_cases (Ο„'' = Ο„') with h, { rw h, right, apply has_type_under.abs, assumption }, { left, intro t, cases t, contradiction } } } }, case term.app e₁ eβ‚‚ ih₁ ihβ‚‚ { } end -/ instance {Ξ±} {a : option Ξ±} : decidable (βˆƒ b, a = some b) := begin cases a, left, intro h, cases h, contradiction, right, existsi a, refl end class inductive tdecidable (t : Prop) : Prop | is_false : (t β†’ false) β†’ tdecidable | is_true : t β†’ tdecidable instance infer {e : term} : βˆ€ {Ξ“ : ctx}, tdecidable (βˆƒ Ο„, has_type_under Ξ“ e Ο„) := begin intro Ξ“, induction e generalizing Ξ“, case term.var x { by_cases (βˆƒ Ο„, Ξ“ x = some Ο„), right, cases h with Ο„ h, existsi Ο„, apply has_type_under.var, assumption, left, intro t, cases t with Ο„ t, cases t, let := forall_not_of_not_exists h Ο„, contradiction }, case term.abs x Ο„ e ih { cases @ih (extend Ξ“ x Ο„) with h h, left, intro t, cases t with Ο„' t, cases t, let := forall_not_of_not_exists h Ο„'_1, contradiction, right, cases h with Ο„' t, existsi type.func Ο„ Ο„', apply has_type_under.abs, assumption, }, case term.app e₁ eβ‚‚ ih₁ ihβ‚‚ { cases @ih₁ Ξ“ with ih₁ ih₁', left, intro t, cases t with Ο„' t, cases t, let := forall_not_of_not_exists ih₁ (type.func Ο„ Ο„'), contradiction, cases @ihβ‚‚ Ξ“ with ihβ‚‚ ihβ‚‚', left, intro t, cases t with Ο„' t, cases t, let := forall_not_of_not_exists ihβ‚‚ Ο„, contradiction, --left, cases ih₁' with Ο„, cases Ο„, left, intro t, cases t with _ t, cases t with _ t, cases a, cases a_2, }, case term.unit { right, existsi type.unit, apply has_type_under.unit } end
e6c21ee01a6e568278b9a93004ca048240435ecb
a5e2e6395319779f21675263bc0e486be5bc03bd
/bench/stlc_small5k.lean
614b572c4ce0c1516dad6b8a7ae228f9192dd09d
[ "MIT" ]
permissive
AndrasKovacs/smalltt
10f0ec55fb3f487e9dd21a740fe1a899e0cdb790
c306f727ba3c92abe6ef75013da5a5dade6b15c8
refs/heads/master
1,689,497,785,394
1,680,893,106,000
1,680,893,106,000
112,098,494
483
26
MIT
1,640,720,815,000
1,511,713,805,000
Lean
UTF-8
Lean
false
false
222,111
lean
def Ty : Type 1 := βˆ€ (Ty : Type) (ΞΉ : Ty) (arr : Ty β†’ Ty β†’ Ty) , Ty def ΞΉ : Ty := Ξ» _ ΞΉ _ => ΞΉ def arr : Ty β†’ Ty β†’ Ty := Ξ» A B Ty ΞΉ arr => arr (A Ty ΞΉ arr) (B Ty ΞΉ arr) def Con : Type 1 := βˆ€ (Con : Type) (nil : Con) (snoc : Con β†’ Ty β†’ Con) , Con def nil : Con := Ξ» Con nil snoc => nil def snoc : Con β†’ Ty β†’ Con := Ξ» Ξ“ A Con nil snoc => snoc (Ξ“ Con nil snoc) A def Var : Con β†’ Ty β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var : Con β†’ Ty β†’ Type) (vz : βˆ€ Ξ“ A, Var (snoc Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var Ξ“ A β†’ Var (snoc Ξ“ B) A) , Var Ξ“ A def vz {Ξ“ A} : Var (snoc Ξ“ A) A := Ξ» Var vz vs => vz _ _ def vs {Ξ“ B A} : Var Ξ“ A β†’ Var (snoc Ξ“ B) A := Ξ» x Var vz vs => vs _ _ _ (x Var vz vs) def Tm : Con β†’ Ty β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm : Con β†’ Ty β†’ Type) (var : βˆ€ Ξ“ A , Var Ξ“ A β†’ Tm Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm (snoc Ξ“ A) B β†’ Tm Ξ“ (arr A B)) (app : βˆ€ Ξ“ A B , Tm Ξ“ (arr A B) β†’ Tm Ξ“ A β†’ Tm Ξ“ B) , Tm Ξ“ A def var {Ξ“ A} : Var Ξ“ A β†’ Tm Ξ“ A := Ξ» x Tm var lam app => var _ _ x def lam {Ξ“ A B} : Tm (snoc Ξ“ A) B β†’ Tm Ξ“ (arr A B) := Ξ» t Tm var lam app => lam _ _ _ (t Tm var lam app) def app {Ξ“ A B} : Tm Ξ“ (arr A B) β†’ Tm Ξ“ A β†’ Tm Ξ“ B := Ξ» t u Tm var lam app => app _ _ _ (t Tm var lam app) (u Tm var lam app) def v0 {Ξ“ A} : Tm (snoc Ξ“ A) A := var vz def v1 {Ξ“ A B} : Tm (snoc (snoc Ξ“ A) B) A := var (vs vz) def v2 {Ξ“ A B C} : Tm (snoc (snoc (snoc Ξ“ A) B) C) A := var (vs (vs vz)) def v3 {Ξ“ A B C D} : Tm (snoc (snoc (snoc (snoc Ξ“ A) B) C) D) A := var (vs (vs (vs vz))) def v4 {Ξ“ A B C D E} : Tm (snoc (snoc (snoc (snoc (snoc Ξ“ A) B) C) D) E) A := var (vs (vs (vs (vs vz)))) def test {Ξ“ A} : Tm Ξ“ (arr (arr A A) (arr A A)) := lam (lam (app v1 (app v1 (app v1 (app v1 (app v1 (app v1 v0))))))) def Ty1 : Type 1 := βˆ€ (Ty1 : Type) (ΞΉ : Ty1) (arr : Ty1 β†’ Ty1 β†’ Ty1) , Ty1 def ΞΉ1 : Ty1 := Ξ» _ ΞΉ1 _ => ΞΉ1 def arr1 : Ty1 β†’ Ty1 β†’ Ty1 := Ξ» A B Ty1 ΞΉ1 arr1 => arr1 (A Ty1 ΞΉ1 arr1) (B Ty1 ΞΉ1 arr1) def Con1 : Type 1 := βˆ€ (Con1 : Type) (nil : Con1) (snoc : Con1 β†’ Ty1 β†’ Con1) , Con1 def nil1 : Con1 := Ξ» Con1 nil1 snoc => nil1 def snoc1 : Con1 β†’ Ty1 β†’ Con1 := Ξ» Ξ“ A Con1 nil1 snoc1 => snoc1 (Ξ“ Con1 nil1 snoc1) A def Var1 : Con1 β†’ Ty1 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var1 : Con1 β†’ Ty1 β†’ Type) (vz : βˆ€ Ξ“ A, Var1 (snoc1 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var1 Ξ“ A β†’ Var1 (snoc1 Ξ“ B) A) , Var1 Ξ“ A def vz1 {Ξ“ A} : Var1 (snoc1 Ξ“ A) A := Ξ» Var1 vz1 vs => vz1 _ _ def vs1 {Ξ“ B A} : Var1 Ξ“ A β†’ Var1 (snoc1 Ξ“ B) A := Ξ» x Var1 vz1 vs1 => vs1 _ _ _ (x Var1 vz1 vs1) def Tm1 : Con1 β†’ Ty1 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm1 : Con1 β†’ Ty1 β†’ Type) (var : βˆ€ Ξ“ A , Var1 Ξ“ A β†’ Tm1 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm1 (snoc1 Ξ“ A) B β†’ Tm1 Ξ“ (arr1 A B)) (app : βˆ€ Ξ“ A B , Tm1 Ξ“ (arr1 A B) β†’ Tm1 Ξ“ A β†’ Tm1 Ξ“ B) , Tm1 Ξ“ A def var1 {Ξ“ A} : Var1 Ξ“ A β†’ Tm1 Ξ“ A := Ξ» x Tm1 var1 lam app => var1 _ _ x def lam1 {Ξ“ A B} : Tm1 (snoc1 Ξ“ A) B β†’ Tm1 Ξ“ (arr1 A B) := Ξ» t Tm1 var1 lam1 app => lam1 _ _ _ (t Tm1 var1 lam1 app) def app1 {Ξ“ A B} : Tm1 Ξ“ (arr1 A B) β†’ Tm1 Ξ“ A β†’ Tm1 Ξ“ B := Ξ» t u Tm1 var1 lam1 app1 => app1 _ _ _ (t Tm1 var1 lam1 app1) (u Tm1 var1 lam1 app1) def v01 {Ξ“ A} : Tm1 (snoc1 Ξ“ A) A := var1 vz1 def v11 {Ξ“ A B} : Tm1 (snoc1 (snoc1 Ξ“ A) B) A := var1 (vs1 vz1) def v21 {Ξ“ A B C} : Tm1 (snoc1 (snoc1 (snoc1 Ξ“ A) B) C) A := var1 (vs1 (vs1 vz1)) def v31 {Ξ“ A B C D} : Tm1 (snoc1 (snoc1 (snoc1 (snoc1 Ξ“ A) B) C) D) A := var1 (vs1 (vs1 (vs1 vz1))) def v41 {Ξ“ A B C D E} : Tm1 (snoc1 (snoc1 (snoc1 (snoc1 (snoc1 Ξ“ A) B) C) D) E) A := var1 (vs1 (vs1 (vs1 (vs1 vz1)))) def test1 {Ξ“ A} : Tm1 Ξ“ (arr1 (arr1 A A) (arr1 A A)) := lam1 (lam1 (app1 v11 (app1 v11 (app1 v11 (app1 v11 (app1 v11 (app1 v11 v01))))))) def Ty2 : Type 1 := βˆ€ (Ty2 : Type) (ΞΉ : Ty2) (arr : Ty2 β†’ Ty2 β†’ Ty2) , Ty2 def ΞΉ2 : Ty2 := Ξ» _ ΞΉ2 _ => ΞΉ2 def arr2 : Ty2 β†’ Ty2 β†’ Ty2 := Ξ» A B Ty2 ΞΉ2 arr2 => arr2 (A Ty2 ΞΉ2 arr2) (B Ty2 ΞΉ2 arr2) def Con2 : Type 1 := βˆ€ (Con2 : Type) (nil : Con2) (snoc : Con2 β†’ Ty2 β†’ Con2) , Con2 def nil2 : Con2 := Ξ» Con2 nil2 snoc => nil2 def snoc2 : Con2 β†’ Ty2 β†’ Con2 := Ξ» Ξ“ A Con2 nil2 snoc2 => snoc2 (Ξ“ Con2 nil2 snoc2) A def Var2 : Con2 β†’ Ty2 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var2 : Con2 β†’ Ty2 β†’ Type) (vz : βˆ€ Ξ“ A, Var2 (snoc2 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var2 Ξ“ A β†’ Var2 (snoc2 Ξ“ B) A) , Var2 Ξ“ A def vz2 {Ξ“ A} : Var2 (snoc2 Ξ“ A) A := Ξ» Var2 vz2 vs => vz2 _ _ def vs2 {Ξ“ B A} : Var2 Ξ“ A β†’ Var2 (snoc2 Ξ“ B) A := Ξ» x Var2 vz2 vs2 => vs2 _ _ _ (x Var2 vz2 vs2) def Tm2 : Con2 β†’ Ty2 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm2 : Con2 β†’ Ty2 β†’ Type) (var : βˆ€ Ξ“ A , Var2 Ξ“ A β†’ Tm2 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm2 (snoc2 Ξ“ A) B β†’ Tm2 Ξ“ (arr2 A B)) (app : βˆ€ Ξ“ A B , Tm2 Ξ“ (arr2 A B) β†’ Tm2 Ξ“ A β†’ Tm2 Ξ“ B) , Tm2 Ξ“ A def var2 {Ξ“ A} : Var2 Ξ“ A β†’ Tm2 Ξ“ A := Ξ» x Tm2 var2 lam app => var2 _ _ x def lam2 {Ξ“ A B} : Tm2 (snoc2 Ξ“ A) B β†’ Tm2 Ξ“ (arr2 A B) := Ξ» t Tm2 var2 lam2 app => lam2 _ _ _ (t Tm2 var2 lam2 app) def app2 {Ξ“ A B} : Tm2 Ξ“ (arr2 A B) β†’ Tm2 Ξ“ A β†’ Tm2 Ξ“ B := Ξ» t u Tm2 var2 lam2 app2 => app2 _ _ _ (t Tm2 var2 lam2 app2) (u Tm2 var2 lam2 app2) def v02 {Ξ“ A} : Tm2 (snoc2 Ξ“ A) A := var2 vz2 def v12 {Ξ“ A B} : Tm2 (snoc2 (snoc2 Ξ“ A) B) A := var2 (vs2 vz2) def v22 {Ξ“ A B C} : Tm2 (snoc2 (snoc2 (snoc2 Ξ“ A) B) C) A := var2 (vs2 (vs2 vz2)) def v32 {Ξ“ A B C D} : Tm2 (snoc2 (snoc2 (snoc2 (snoc2 Ξ“ A) B) C) D) A := var2 (vs2 (vs2 (vs2 vz2))) def v42 {Ξ“ A B C D E} : Tm2 (snoc2 (snoc2 (snoc2 (snoc2 (snoc2 Ξ“ A) B) C) D) E) A := var2 (vs2 (vs2 (vs2 (vs2 vz2)))) def test2 {Ξ“ A} : Tm2 Ξ“ (arr2 (arr2 A A) (arr2 A A)) := lam2 (lam2 (app2 v12 (app2 v12 (app2 v12 (app2 v12 (app2 v12 (app2 v12 v02))))))) def Ty3 : Type 1 := βˆ€ (Ty3 : Type) (ΞΉ : Ty3) (arr : Ty3 β†’ Ty3 β†’ Ty3) , Ty3 def ΞΉ3 : Ty3 := Ξ» _ ΞΉ3 _ => ΞΉ3 def arr3 : Ty3 β†’ Ty3 β†’ Ty3 := Ξ» A B Ty3 ΞΉ3 arr3 => arr3 (A Ty3 ΞΉ3 arr3) (B Ty3 ΞΉ3 arr3) def Con3 : Type 1 := βˆ€ (Con3 : Type) (nil : Con3) (snoc : Con3 β†’ Ty3 β†’ Con3) , Con3 def nil3 : Con3 := Ξ» Con3 nil3 snoc => nil3 def snoc3 : Con3 β†’ Ty3 β†’ Con3 := Ξ» Ξ“ A Con3 nil3 snoc3 => snoc3 (Ξ“ Con3 nil3 snoc3) A def Var3 : Con3 β†’ Ty3 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var3 : Con3 β†’ Ty3 β†’ Type) (vz : βˆ€ Ξ“ A, Var3 (snoc3 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var3 Ξ“ A β†’ Var3 (snoc3 Ξ“ B) A) , Var3 Ξ“ A def vz3 {Ξ“ A} : Var3 (snoc3 Ξ“ A) A := Ξ» Var3 vz3 vs => vz3 _ _ def vs3 {Ξ“ B A} : Var3 Ξ“ A β†’ Var3 (snoc3 Ξ“ B) A := Ξ» x Var3 vz3 vs3 => vs3 _ _ _ (x Var3 vz3 vs3) def Tm3 : Con3 β†’ Ty3 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm3 : Con3 β†’ Ty3 β†’ Type) (var : βˆ€ Ξ“ A , Var3 Ξ“ A β†’ Tm3 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm3 (snoc3 Ξ“ A) B β†’ Tm3 Ξ“ (arr3 A B)) (app : βˆ€ Ξ“ A B , Tm3 Ξ“ (arr3 A B) β†’ Tm3 Ξ“ A β†’ Tm3 Ξ“ B) , Tm3 Ξ“ A def var3 {Ξ“ A} : Var3 Ξ“ A β†’ Tm3 Ξ“ A := Ξ» x Tm3 var3 lam app => var3 _ _ x def lam3 {Ξ“ A B} : Tm3 (snoc3 Ξ“ A) B β†’ Tm3 Ξ“ (arr3 A B) := Ξ» t Tm3 var3 lam3 app => lam3 _ _ _ (t Tm3 var3 lam3 app) def app3 {Ξ“ A B} : Tm3 Ξ“ (arr3 A B) β†’ Tm3 Ξ“ A β†’ Tm3 Ξ“ B := Ξ» t u Tm3 var3 lam3 app3 => app3 _ _ _ (t Tm3 var3 lam3 app3) (u Tm3 var3 lam3 app3) def v03 {Ξ“ A} : Tm3 (snoc3 Ξ“ A) A := var3 vz3 def v13 {Ξ“ A B} : Tm3 (snoc3 (snoc3 Ξ“ A) B) A := var3 (vs3 vz3) def v23 {Ξ“ A B C} : Tm3 (snoc3 (snoc3 (snoc3 Ξ“ A) B) C) A := var3 (vs3 (vs3 vz3)) def v33 {Ξ“ A B C D} : Tm3 (snoc3 (snoc3 (snoc3 (snoc3 Ξ“ A) B) C) D) A := var3 (vs3 (vs3 (vs3 vz3))) def v43 {Ξ“ A B C D E} : Tm3 (snoc3 (snoc3 (snoc3 (snoc3 (snoc3 Ξ“ A) B) C) D) E) A := var3 (vs3 (vs3 (vs3 (vs3 vz3)))) def test3 {Ξ“ A} : Tm3 Ξ“ (arr3 (arr3 A A) (arr3 A A)) := lam3 (lam3 (app3 v13 (app3 v13 (app3 v13 (app3 v13 (app3 v13 (app3 v13 v03))))))) def Ty4 : Type 1 := βˆ€ (Ty4 : Type) (ΞΉ : Ty4) (arr : Ty4 β†’ Ty4 β†’ Ty4) , Ty4 def ΞΉ4 : Ty4 := Ξ» _ ΞΉ4 _ => ΞΉ4 def arr4 : Ty4 β†’ Ty4 β†’ Ty4 := Ξ» A B Ty4 ΞΉ4 arr4 => arr4 (A Ty4 ΞΉ4 arr4) (B Ty4 ΞΉ4 arr4) def Con4 : Type 1 := βˆ€ (Con4 : Type) (nil : Con4) (snoc : Con4 β†’ Ty4 β†’ Con4) , Con4 def nil4 : Con4 := Ξ» Con4 nil4 snoc => nil4 def snoc4 : Con4 β†’ Ty4 β†’ Con4 := Ξ» Ξ“ A Con4 nil4 snoc4 => snoc4 (Ξ“ Con4 nil4 snoc4) A def Var4 : Con4 β†’ Ty4 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var4 : Con4 β†’ Ty4 β†’ Type) (vz : βˆ€ Ξ“ A, Var4 (snoc4 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var4 Ξ“ A β†’ Var4 (snoc4 Ξ“ B) A) , Var4 Ξ“ A def vz4 {Ξ“ A} : Var4 (snoc4 Ξ“ A) A := Ξ» Var4 vz4 vs => vz4 _ _ def vs4 {Ξ“ B A} : Var4 Ξ“ A β†’ Var4 (snoc4 Ξ“ B) A := Ξ» x Var4 vz4 vs4 => vs4 _ _ _ (x Var4 vz4 vs4) def Tm4 : Con4 β†’ Ty4 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm4 : Con4 β†’ Ty4 β†’ Type) (var : βˆ€ Ξ“ A , Var4 Ξ“ A β†’ Tm4 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm4 (snoc4 Ξ“ A) B β†’ Tm4 Ξ“ (arr4 A B)) (app : βˆ€ Ξ“ A B , Tm4 Ξ“ (arr4 A B) β†’ Tm4 Ξ“ A β†’ Tm4 Ξ“ B) , Tm4 Ξ“ A def var4 {Ξ“ A} : Var4 Ξ“ A β†’ Tm4 Ξ“ A := Ξ» x Tm4 var4 lam app => var4 _ _ x def lam4 {Ξ“ A B} : Tm4 (snoc4 Ξ“ A) B β†’ Tm4 Ξ“ (arr4 A B) := Ξ» t Tm4 var4 lam4 app => lam4 _ _ _ (t Tm4 var4 lam4 app) def app4 {Ξ“ A B} : Tm4 Ξ“ (arr4 A B) β†’ Tm4 Ξ“ A β†’ Tm4 Ξ“ B := Ξ» t u Tm4 var4 lam4 app4 => app4 _ _ _ (t Tm4 var4 lam4 app4) (u Tm4 var4 lam4 app4) def v04 {Ξ“ A} : Tm4 (snoc4 Ξ“ A) A := var4 vz4 def v14 {Ξ“ A B} : Tm4 (snoc4 (snoc4 Ξ“ A) B) A := var4 (vs4 vz4) def v24 {Ξ“ A B C} : Tm4 (snoc4 (snoc4 (snoc4 Ξ“ A) B) C) A := var4 (vs4 (vs4 vz4)) def v34 {Ξ“ A B C D} : Tm4 (snoc4 (snoc4 (snoc4 (snoc4 Ξ“ A) B) C) D) A := var4 (vs4 (vs4 (vs4 vz4))) def v44 {Ξ“ A B C D E} : Tm4 (snoc4 (snoc4 (snoc4 (snoc4 (snoc4 Ξ“ A) B) C) D) E) A := var4 (vs4 (vs4 (vs4 (vs4 vz4)))) def test4 {Ξ“ A} : Tm4 Ξ“ (arr4 (arr4 A A) (arr4 A A)) := lam4 (lam4 (app4 v14 (app4 v14 (app4 v14 (app4 v14 (app4 v14 (app4 v14 v04))))))) def Ty5 : Type 1 := βˆ€ (Ty5 : Type) (ΞΉ : Ty5) (arr : Ty5 β†’ Ty5 β†’ Ty5) , Ty5 def ΞΉ5 : Ty5 := Ξ» _ ΞΉ5 _ => ΞΉ5 def arr5 : Ty5 β†’ Ty5 β†’ Ty5 := Ξ» A B Ty5 ΞΉ5 arr5 => arr5 (A Ty5 ΞΉ5 arr5) (B Ty5 ΞΉ5 arr5) def Con5 : Type 1 := βˆ€ (Con5 : Type) (nil : Con5) (snoc : Con5 β†’ Ty5 β†’ Con5) , Con5 def nil5 : Con5 := Ξ» Con5 nil5 snoc => nil5 def snoc5 : Con5 β†’ Ty5 β†’ Con5 := Ξ» Ξ“ A Con5 nil5 snoc5 => snoc5 (Ξ“ Con5 nil5 snoc5) A def Var5 : Con5 β†’ Ty5 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var5 : Con5 β†’ Ty5 β†’ Type) (vz : βˆ€ Ξ“ A, Var5 (snoc5 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var5 Ξ“ A β†’ Var5 (snoc5 Ξ“ B) A) , Var5 Ξ“ A def vz5 {Ξ“ A} : Var5 (snoc5 Ξ“ A) A := Ξ» Var5 vz5 vs => vz5 _ _ def vs5 {Ξ“ B A} : Var5 Ξ“ A β†’ Var5 (snoc5 Ξ“ B) A := Ξ» x Var5 vz5 vs5 => vs5 _ _ _ (x Var5 vz5 vs5) def Tm5 : Con5 β†’ Ty5 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm5 : Con5 β†’ Ty5 β†’ Type) (var : βˆ€ Ξ“ A , Var5 Ξ“ A β†’ Tm5 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm5 (snoc5 Ξ“ A) B β†’ Tm5 Ξ“ (arr5 A B)) (app : βˆ€ Ξ“ A B , Tm5 Ξ“ (arr5 A B) β†’ Tm5 Ξ“ A β†’ Tm5 Ξ“ B) , Tm5 Ξ“ A def var5 {Ξ“ A} : Var5 Ξ“ A β†’ Tm5 Ξ“ A := Ξ» x Tm5 var5 lam app => var5 _ _ x def lam5 {Ξ“ A B} : Tm5 (snoc5 Ξ“ A) B β†’ Tm5 Ξ“ (arr5 A B) := Ξ» t Tm5 var5 lam5 app => lam5 _ _ _ (t Tm5 var5 lam5 app) def app5 {Ξ“ A B} : Tm5 Ξ“ (arr5 A B) β†’ Tm5 Ξ“ A β†’ Tm5 Ξ“ B := Ξ» t u Tm5 var5 lam5 app5 => app5 _ _ _ (t Tm5 var5 lam5 app5) (u Tm5 var5 lam5 app5) def v05 {Ξ“ A} : Tm5 (snoc5 Ξ“ A) A := var5 vz5 def v15 {Ξ“ A B} : Tm5 (snoc5 (snoc5 Ξ“ A) B) A := var5 (vs5 vz5) def v25 {Ξ“ A B C} : Tm5 (snoc5 (snoc5 (snoc5 Ξ“ A) B) C) A := var5 (vs5 (vs5 vz5)) def v35 {Ξ“ A B C D} : Tm5 (snoc5 (snoc5 (snoc5 (snoc5 Ξ“ A) B) C) D) A := var5 (vs5 (vs5 (vs5 vz5))) def v45 {Ξ“ A B C D E} : Tm5 (snoc5 (snoc5 (snoc5 (snoc5 (snoc5 Ξ“ A) B) C) D) E) A := var5 (vs5 (vs5 (vs5 (vs5 vz5)))) def test5 {Ξ“ A} : Tm5 Ξ“ (arr5 (arr5 A A) (arr5 A A)) := lam5 (lam5 (app5 v15 (app5 v15 (app5 v15 (app5 v15 (app5 v15 (app5 v15 v05))))))) def Ty6 : Type 1 := βˆ€ (Ty6 : Type) (ΞΉ : Ty6) (arr : Ty6 β†’ Ty6 β†’ Ty6) , Ty6 def ΞΉ6 : Ty6 := Ξ» _ ΞΉ6 _ => ΞΉ6 def arr6 : Ty6 β†’ Ty6 β†’ Ty6 := Ξ» A B Ty6 ΞΉ6 arr6 => arr6 (A Ty6 ΞΉ6 arr6) (B Ty6 ΞΉ6 arr6) def Con6 : Type 1 := βˆ€ (Con6 : Type) (nil : Con6) (snoc : Con6 β†’ Ty6 β†’ Con6) , Con6 def nil6 : Con6 := Ξ» Con6 nil6 snoc => nil6 def snoc6 : Con6 β†’ Ty6 β†’ Con6 := Ξ» Ξ“ A Con6 nil6 snoc6 => snoc6 (Ξ“ Con6 nil6 snoc6) A def Var6 : Con6 β†’ Ty6 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var6 : Con6 β†’ Ty6 β†’ Type) (vz : βˆ€ Ξ“ A, Var6 (snoc6 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var6 Ξ“ A β†’ Var6 (snoc6 Ξ“ B) A) , Var6 Ξ“ A def vz6 {Ξ“ A} : Var6 (snoc6 Ξ“ A) A := Ξ» Var6 vz6 vs => vz6 _ _ def vs6 {Ξ“ B A} : Var6 Ξ“ A β†’ Var6 (snoc6 Ξ“ B) A := Ξ» x Var6 vz6 vs6 => vs6 _ _ _ (x Var6 vz6 vs6) def Tm6 : Con6 β†’ Ty6 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm6 : Con6 β†’ Ty6 β†’ Type) (var : βˆ€ Ξ“ A , Var6 Ξ“ A β†’ Tm6 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm6 (snoc6 Ξ“ A) B β†’ Tm6 Ξ“ (arr6 A B)) (app : βˆ€ Ξ“ A B , Tm6 Ξ“ (arr6 A B) β†’ Tm6 Ξ“ A β†’ Tm6 Ξ“ B) , Tm6 Ξ“ A def var6 {Ξ“ A} : Var6 Ξ“ A β†’ Tm6 Ξ“ A := Ξ» x Tm6 var6 lam app => var6 _ _ x def lam6 {Ξ“ A B} : Tm6 (snoc6 Ξ“ A) B β†’ Tm6 Ξ“ (arr6 A B) := Ξ» t Tm6 var6 lam6 app => lam6 _ _ _ (t Tm6 var6 lam6 app) def app6 {Ξ“ A B} : Tm6 Ξ“ (arr6 A B) β†’ Tm6 Ξ“ A β†’ Tm6 Ξ“ B := Ξ» t u Tm6 var6 lam6 app6 => app6 _ _ _ (t Tm6 var6 lam6 app6) (u Tm6 var6 lam6 app6) def v06 {Ξ“ A} : Tm6 (snoc6 Ξ“ A) A := var6 vz6 def v16 {Ξ“ A B} : Tm6 (snoc6 (snoc6 Ξ“ A) B) A := var6 (vs6 vz6) def v26 {Ξ“ A B C} : Tm6 (snoc6 (snoc6 (snoc6 Ξ“ A) B) C) A := var6 (vs6 (vs6 vz6)) def v36 {Ξ“ A B C D} : Tm6 (snoc6 (snoc6 (snoc6 (snoc6 Ξ“ A) B) C) D) A := var6 (vs6 (vs6 (vs6 vz6))) def v46 {Ξ“ A B C D E} : Tm6 (snoc6 (snoc6 (snoc6 (snoc6 (snoc6 Ξ“ A) B) C) D) E) A := var6 (vs6 (vs6 (vs6 (vs6 vz6)))) def test6 {Ξ“ A} : Tm6 Ξ“ (arr6 (arr6 A A) (arr6 A A)) := lam6 (lam6 (app6 v16 (app6 v16 (app6 v16 (app6 v16 (app6 v16 (app6 v16 v06))))))) def Ty7 : Type 1 := βˆ€ (Ty7 : Type) (ΞΉ : Ty7) (arr : Ty7 β†’ Ty7 β†’ Ty7) , Ty7 def ΞΉ7 : Ty7 := Ξ» _ ΞΉ7 _ => ΞΉ7 def arr7 : Ty7 β†’ Ty7 β†’ Ty7 := Ξ» A B Ty7 ΞΉ7 arr7 => arr7 (A Ty7 ΞΉ7 arr7) (B Ty7 ΞΉ7 arr7) def Con7 : Type 1 := βˆ€ (Con7 : Type) (nil : Con7) (snoc : Con7 β†’ Ty7 β†’ Con7) , Con7 def nil7 : Con7 := Ξ» Con7 nil7 snoc => nil7 def snoc7 : Con7 β†’ Ty7 β†’ Con7 := Ξ» Ξ“ A Con7 nil7 snoc7 => snoc7 (Ξ“ Con7 nil7 snoc7) A def Var7 : Con7 β†’ Ty7 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var7 : Con7 β†’ Ty7 β†’ Type) (vz : βˆ€ Ξ“ A, Var7 (snoc7 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var7 Ξ“ A β†’ Var7 (snoc7 Ξ“ B) A) , Var7 Ξ“ A def vz7 {Ξ“ A} : Var7 (snoc7 Ξ“ A) A := Ξ» Var7 vz7 vs => vz7 _ _ def vs7 {Ξ“ B A} : Var7 Ξ“ A β†’ Var7 (snoc7 Ξ“ B) A := Ξ» x Var7 vz7 vs7 => vs7 _ _ _ (x Var7 vz7 vs7) def Tm7 : Con7 β†’ Ty7 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm7 : Con7 β†’ Ty7 β†’ Type) (var : βˆ€ Ξ“ A , Var7 Ξ“ A β†’ Tm7 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm7 (snoc7 Ξ“ A) B β†’ Tm7 Ξ“ (arr7 A B)) (app : βˆ€ Ξ“ A B , Tm7 Ξ“ (arr7 A B) β†’ Tm7 Ξ“ A β†’ Tm7 Ξ“ B) , Tm7 Ξ“ A def var7 {Ξ“ A} : Var7 Ξ“ A β†’ Tm7 Ξ“ A := Ξ» x Tm7 var7 lam app => var7 _ _ x def lam7 {Ξ“ A B} : Tm7 (snoc7 Ξ“ A) B β†’ Tm7 Ξ“ (arr7 A B) := Ξ» t Tm7 var7 lam7 app => lam7 _ _ _ (t Tm7 var7 lam7 app) def app7 {Ξ“ A B} : Tm7 Ξ“ (arr7 A B) β†’ Tm7 Ξ“ A β†’ Tm7 Ξ“ B := Ξ» t u Tm7 var7 lam7 app7 => app7 _ _ _ (t Tm7 var7 lam7 app7) (u Tm7 var7 lam7 app7) def v07 {Ξ“ A} : Tm7 (snoc7 Ξ“ A) A := var7 vz7 def v17 {Ξ“ A B} : Tm7 (snoc7 (snoc7 Ξ“ A) B) A := var7 (vs7 vz7) def v27 {Ξ“ A B C} : Tm7 (snoc7 (snoc7 (snoc7 Ξ“ A) B) C) A := var7 (vs7 (vs7 vz7)) def v37 {Ξ“ A B C D} : Tm7 (snoc7 (snoc7 (snoc7 (snoc7 Ξ“ A) B) C) D) A := var7 (vs7 (vs7 (vs7 vz7))) def v47 {Ξ“ A B C D E} : Tm7 (snoc7 (snoc7 (snoc7 (snoc7 (snoc7 Ξ“ A) B) C) D) E) A := var7 (vs7 (vs7 (vs7 (vs7 vz7)))) def test7 {Ξ“ A} : Tm7 Ξ“ (arr7 (arr7 A A) (arr7 A A)) := lam7 (lam7 (app7 v17 (app7 v17 (app7 v17 (app7 v17 (app7 v17 (app7 v17 v07))))))) def Ty8 : Type 1 := βˆ€ (Ty8 : Type) (ΞΉ : Ty8) (arr : Ty8 β†’ Ty8 β†’ Ty8) , Ty8 def ΞΉ8 : Ty8 := Ξ» _ ΞΉ8 _ => ΞΉ8 def arr8 : Ty8 β†’ Ty8 β†’ Ty8 := Ξ» A B Ty8 ΞΉ8 arr8 => arr8 (A Ty8 ΞΉ8 arr8) (B Ty8 ΞΉ8 arr8) def Con8 : Type 1 := βˆ€ (Con8 : Type) (nil : Con8) (snoc : Con8 β†’ Ty8 β†’ Con8) , Con8 def nil8 : Con8 := Ξ» Con8 nil8 snoc => nil8 def snoc8 : Con8 β†’ Ty8 β†’ Con8 := Ξ» Ξ“ A Con8 nil8 snoc8 => snoc8 (Ξ“ Con8 nil8 snoc8) A def Var8 : Con8 β†’ Ty8 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var8 : Con8 β†’ Ty8 β†’ Type) (vz : βˆ€ Ξ“ A, Var8 (snoc8 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var8 Ξ“ A β†’ Var8 (snoc8 Ξ“ B) A) , Var8 Ξ“ A def vz8 {Ξ“ A} : Var8 (snoc8 Ξ“ A) A := Ξ» Var8 vz8 vs => vz8 _ _ def vs8 {Ξ“ B A} : Var8 Ξ“ A β†’ Var8 (snoc8 Ξ“ B) A := Ξ» x Var8 vz8 vs8 => vs8 _ _ _ (x Var8 vz8 vs8) def Tm8 : Con8 β†’ Ty8 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm8 : Con8 β†’ Ty8 β†’ Type) (var : βˆ€ Ξ“ A , Var8 Ξ“ A β†’ Tm8 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm8 (snoc8 Ξ“ A) B β†’ Tm8 Ξ“ (arr8 A B)) (app : βˆ€ Ξ“ A B , Tm8 Ξ“ (arr8 A B) β†’ Tm8 Ξ“ A β†’ Tm8 Ξ“ B) , Tm8 Ξ“ A def var8 {Ξ“ A} : Var8 Ξ“ A β†’ Tm8 Ξ“ A := Ξ» x Tm8 var8 lam app => var8 _ _ x def lam8 {Ξ“ A B} : Tm8 (snoc8 Ξ“ A) B β†’ Tm8 Ξ“ (arr8 A B) := Ξ» t Tm8 var8 lam8 app => lam8 _ _ _ (t Tm8 var8 lam8 app) def app8 {Ξ“ A B} : Tm8 Ξ“ (arr8 A B) β†’ Tm8 Ξ“ A β†’ Tm8 Ξ“ B := Ξ» t u Tm8 var8 lam8 app8 => app8 _ _ _ (t Tm8 var8 lam8 app8) (u Tm8 var8 lam8 app8) def v08 {Ξ“ A} : Tm8 (snoc8 Ξ“ A) A := var8 vz8 def v18 {Ξ“ A B} : Tm8 (snoc8 (snoc8 Ξ“ A) B) A := var8 (vs8 vz8) def v28 {Ξ“ A B C} : Tm8 (snoc8 (snoc8 (snoc8 Ξ“ A) B) C) A := var8 (vs8 (vs8 vz8)) def v38 {Ξ“ A B C D} : Tm8 (snoc8 (snoc8 (snoc8 (snoc8 Ξ“ A) B) C) D) A := var8 (vs8 (vs8 (vs8 vz8))) def v48 {Ξ“ A B C D E} : Tm8 (snoc8 (snoc8 (snoc8 (snoc8 (snoc8 Ξ“ A) B) C) D) E) A := var8 (vs8 (vs8 (vs8 (vs8 vz8)))) def test8 {Ξ“ A} : Tm8 Ξ“ (arr8 (arr8 A A) (arr8 A A)) := lam8 (lam8 (app8 v18 (app8 v18 (app8 v18 (app8 v18 (app8 v18 (app8 v18 v08))))))) def Ty9 : Type 1 := βˆ€ (Ty9 : Type) (ΞΉ : Ty9) (arr : Ty9 β†’ Ty9 β†’ Ty9) , Ty9 def ΞΉ9 : Ty9 := Ξ» _ ΞΉ9 _ => ΞΉ9 def arr9 : Ty9 β†’ Ty9 β†’ Ty9 := Ξ» A B Ty9 ΞΉ9 arr9 => arr9 (A Ty9 ΞΉ9 arr9) (B Ty9 ΞΉ9 arr9) def Con9 : Type 1 := βˆ€ (Con9 : Type) (nil : Con9) (snoc : Con9 β†’ Ty9 β†’ Con9) , Con9 def nil9 : Con9 := Ξ» Con9 nil9 snoc => nil9 def snoc9 : Con9 β†’ Ty9 β†’ Con9 := Ξ» Ξ“ A Con9 nil9 snoc9 => snoc9 (Ξ“ Con9 nil9 snoc9) A def Var9 : Con9 β†’ Ty9 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var9 : Con9 β†’ Ty9 β†’ Type) (vz : βˆ€ Ξ“ A, Var9 (snoc9 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var9 Ξ“ A β†’ Var9 (snoc9 Ξ“ B) A) , Var9 Ξ“ A def vz9 {Ξ“ A} : Var9 (snoc9 Ξ“ A) A := Ξ» Var9 vz9 vs => vz9 _ _ def vs9 {Ξ“ B A} : Var9 Ξ“ A β†’ Var9 (snoc9 Ξ“ B) A := Ξ» x Var9 vz9 vs9 => vs9 _ _ _ (x Var9 vz9 vs9) def Tm9 : Con9 β†’ Ty9 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm9 : Con9 β†’ Ty9 β†’ Type) (var : βˆ€ Ξ“ A , Var9 Ξ“ A β†’ Tm9 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm9 (snoc9 Ξ“ A) B β†’ Tm9 Ξ“ (arr9 A B)) (app : βˆ€ Ξ“ A B , Tm9 Ξ“ (arr9 A B) β†’ Tm9 Ξ“ A β†’ Tm9 Ξ“ B) , Tm9 Ξ“ A def var9 {Ξ“ A} : Var9 Ξ“ A β†’ Tm9 Ξ“ A := Ξ» x Tm9 var9 lam app => var9 _ _ x def lam9 {Ξ“ A B} : Tm9 (snoc9 Ξ“ A) B β†’ Tm9 Ξ“ (arr9 A B) := Ξ» t Tm9 var9 lam9 app => lam9 _ _ _ (t Tm9 var9 lam9 app) def app9 {Ξ“ A B} : Tm9 Ξ“ (arr9 A B) β†’ Tm9 Ξ“ A β†’ Tm9 Ξ“ B := Ξ» t u Tm9 var9 lam9 app9 => app9 _ _ _ (t Tm9 var9 lam9 app9) (u Tm9 var9 lam9 app9) def v09 {Ξ“ A} : Tm9 (snoc9 Ξ“ A) A := var9 vz9 def v19 {Ξ“ A B} : Tm9 (snoc9 (snoc9 Ξ“ A) B) A := var9 (vs9 vz9) def v29 {Ξ“ A B C} : Tm9 (snoc9 (snoc9 (snoc9 Ξ“ A) B) C) A := var9 (vs9 (vs9 vz9)) def v39 {Ξ“ A B C D} : Tm9 (snoc9 (snoc9 (snoc9 (snoc9 Ξ“ A) B) C) D) A := var9 (vs9 (vs9 (vs9 vz9))) def v49 {Ξ“ A B C D E} : Tm9 (snoc9 (snoc9 (snoc9 (snoc9 (snoc9 Ξ“ A) B) C) D) E) A := var9 (vs9 (vs9 (vs9 (vs9 vz9)))) def test9 {Ξ“ A} : Tm9 Ξ“ (arr9 (arr9 A A) (arr9 A A)) := lam9 (lam9 (app9 v19 (app9 v19 (app9 v19 (app9 v19 (app9 v19 (app9 v19 v09))))))) def Ty10 : Type 1 := βˆ€ (Ty10 : Type) (ΞΉ : Ty10) (arr : Ty10 β†’ Ty10 β†’ Ty10) , Ty10 def ΞΉ10 : Ty10 := Ξ» _ ΞΉ10 _ => ΞΉ10 def arr10 : Ty10 β†’ Ty10 β†’ Ty10 := Ξ» A B Ty10 ΞΉ10 arr10 => arr10 (A Ty10 ΞΉ10 arr10) (B Ty10 ΞΉ10 arr10) def Con10 : Type 1 := βˆ€ (Con10 : Type) (nil : Con10) (snoc : Con10 β†’ Ty10 β†’ Con10) , Con10 def nil10 : Con10 := Ξ» Con10 nil10 snoc => nil10 def snoc10 : Con10 β†’ Ty10 β†’ Con10 := Ξ» Ξ“ A Con10 nil10 snoc10 => snoc10 (Ξ“ Con10 nil10 snoc10) A def Var10 : Con10 β†’ Ty10 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var10 : Con10 β†’ Ty10 β†’ Type) (vz : βˆ€ Ξ“ A, Var10 (snoc10 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var10 Ξ“ A β†’ Var10 (snoc10 Ξ“ B) A) , Var10 Ξ“ A def vz10 {Ξ“ A} : Var10 (snoc10 Ξ“ A) A := Ξ» Var10 vz10 vs => vz10 _ _ def vs10 {Ξ“ B A} : Var10 Ξ“ A β†’ Var10 (snoc10 Ξ“ B) A := Ξ» x Var10 vz10 vs10 => vs10 _ _ _ (x Var10 vz10 vs10) def Tm10 : Con10 β†’ Ty10 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm10 : Con10 β†’ Ty10 β†’ Type) (var : βˆ€ Ξ“ A , Var10 Ξ“ A β†’ Tm10 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm10 (snoc10 Ξ“ A) B β†’ Tm10 Ξ“ (arr10 A B)) (app : βˆ€ Ξ“ A B , Tm10 Ξ“ (arr10 A B) β†’ Tm10 Ξ“ A β†’ Tm10 Ξ“ B) , Tm10 Ξ“ A def var10 {Ξ“ A} : Var10 Ξ“ A β†’ Tm10 Ξ“ A := Ξ» x Tm10 var10 lam app => var10 _ _ x def lam10 {Ξ“ A B} : Tm10 (snoc10 Ξ“ A) B β†’ Tm10 Ξ“ (arr10 A B) := Ξ» t Tm10 var10 lam10 app => lam10 _ _ _ (t Tm10 var10 lam10 app) def app10 {Ξ“ A B} : Tm10 Ξ“ (arr10 A B) β†’ Tm10 Ξ“ A β†’ Tm10 Ξ“ B := Ξ» t u Tm10 var10 lam10 app10 => app10 _ _ _ (t Tm10 var10 lam10 app10) (u Tm10 var10 lam10 app10) def v010 {Ξ“ A} : Tm10 (snoc10 Ξ“ A) A := var10 vz10 def v110 {Ξ“ A B} : Tm10 (snoc10 (snoc10 Ξ“ A) B) A := var10 (vs10 vz10) def v210 {Ξ“ A B C} : Tm10 (snoc10 (snoc10 (snoc10 Ξ“ A) B) C) A := var10 (vs10 (vs10 vz10)) def v310 {Ξ“ A B C D} : Tm10 (snoc10 (snoc10 (snoc10 (snoc10 Ξ“ A) B) C) D) A := var10 (vs10 (vs10 (vs10 vz10))) def v410 {Ξ“ A B C D E} : Tm10 (snoc10 (snoc10 (snoc10 (snoc10 (snoc10 Ξ“ A) B) C) D) E) A := var10 (vs10 (vs10 (vs10 (vs10 vz10)))) def test10 {Ξ“ A} : Tm10 Ξ“ (arr10 (arr10 A A) (arr10 A A)) := lam10 (lam10 (app10 v110 (app10 v110 (app10 v110 (app10 v110 (app10 v110 (app10 v110 v010))))))) def Ty11 : Type 1 := βˆ€ (Ty11 : Type) (ΞΉ : Ty11) (arr : Ty11 β†’ Ty11 β†’ Ty11) , Ty11 def ΞΉ11 : Ty11 := Ξ» _ ΞΉ11 _ => ΞΉ11 def arr11 : Ty11 β†’ Ty11 β†’ Ty11 := Ξ» A B Ty11 ΞΉ11 arr11 => arr11 (A Ty11 ΞΉ11 arr11) (B Ty11 ΞΉ11 arr11) def Con11 : Type 1 := βˆ€ (Con11 : Type) (nil : Con11) (snoc : Con11 β†’ Ty11 β†’ Con11) , Con11 def nil11 : Con11 := Ξ» Con11 nil11 snoc => nil11 def snoc11 : Con11 β†’ Ty11 β†’ Con11 := Ξ» Ξ“ A Con11 nil11 snoc11 => snoc11 (Ξ“ Con11 nil11 snoc11) A def Var11 : Con11 β†’ Ty11 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var11 : Con11 β†’ Ty11 β†’ Type) (vz : βˆ€ Ξ“ A, Var11 (snoc11 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var11 Ξ“ A β†’ Var11 (snoc11 Ξ“ B) A) , Var11 Ξ“ A def vz11 {Ξ“ A} : Var11 (snoc11 Ξ“ A) A := Ξ» Var11 vz11 vs => vz11 _ _ def vs11 {Ξ“ B A} : Var11 Ξ“ A β†’ Var11 (snoc11 Ξ“ B) A := Ξ» x Var11 vz11 vs11 => vs11 _ _ _ (x Var11 vz11 vs11) def Tm11 : Con11 β†’ Ty11 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm11 : Con11 β†’ Ty11 β†’ Type) (var : βˆ€ Ξ“ A , Var11 Ξ“ A β†’ Tm11 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm11 (snoc11 Ξ“ A) B β†’ Tm11 Ξ“ (arr11 A B)) (app : βˆ€ Ξ“ A B , Tm11 Ξ“ (arr11 A B) β†’ Tm11 Ξ“ A β†’ Tm11 Ξ“ B) , Tm11 Ξ“ A def var11 {Ξ“ A} : Var11 Ξ“ A β†’ Tm11 Ξ“ A := Ξ» x Tm11 var11 lam app => var11 _ _ x def lam11 {Ξ“ A B} : Tm11 (snoc11 Ξ“ A) B β†’ Tm11 Ξ“ (arr11 A B) := Ξ» t Tm11 var11 lam11 app => lam11 _ _ _ (t Tm11 var11 lam11 app) def app11 {Ξ“ A B} : Tm11 Ξ“ (arr11 A B) β†’ Tm11 Ξ“ A β†’ Tm11 Ξ“ B := Ξ» t u Tm11 var11 lam11 app11 => app11 _ _ _ (t Tm11 var11 lam11 app11) (u Tm11 var11 lam11 app11) def v011 {Ξ“ A} : Tm11 (snoc11 Ξ“ A) A := var11 vz11 def v111 {Ξ“ A B} : Tm11 (snoc11 (snoc11 Ξ“ A) B) A := var11 (vs11 vz11) def v211 {Ξ“ A B C} : Tm11 (snoc11 (snoc11 (snoc11 Ξ“ A) B) C) A := var11 (vs11 (vs11 vz11)) def v311 {Ξ“ A B C D} : Tm11 (snoc11 (snoc11 (snoc11 (snoc11 Ξ“ A) B) C) D) A := var11 (vs11 (vs11 (vs11 vz11))) def v411 {Ξ“ A B C D E} : Tm11 (snoc11 (snoc11 (snoc11 (snoc11 (snoc11 Ξ“ A) B) C) D) E) A := var11 (vs11 (vs11 (vs11 (vs11 vz11)))) def test11 {Ξ“ A} : Tm11 Ξ“ (arr11 (arr11 A A) (arr11 A A)) := lam11 (lam11 (app11 v111 (app11 v111 (app11 v111 (app11 v111 (app11 v111 (app11 v111 v011))))))) def Ty12 : Type 1 := βˆ€ (Ty12 : Type) (ΞΉ : Ty12) (arr : Ty12 β†’ Ty12 β†’ Ty12) , Ty12 def ΞΉ12 : Ty12 := Ξ» _ ΞΉ12 _ => ΞΉ12 def arr12 : Ty12 β†’ Ty12 β†’ Ty12 := Ξ» A B Ty12 ΞΉ12 arr12 => arr12 (A Ty12 ΞΉ12 arr12) (B Ty12 ΞΉ12 arr12) def Con12 : Type 1 := βˆ€ (Con12 : Type) (nil : Con12) (snoc : Con12 β†’ Ty12 β†’ Con12) , Con12 def nil12 : Con12 := Ξ» Con12 nil12 snoc => nil12 def snoc12 : Con12 β†’ Ty12 β†’ Con12 := Ξ» Ξ“ A Con12 nil12 snoc12 => snoc12 (Ξ“ Con12 nil12 snoc12) A def Var12 : Con12 β†’ Ty12 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var12 : Con12 β†’ Ty12 β†’ Type) (vz : βˆ€ Ξ“ A, Var12 (snoc12 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var12 Ξ“ A β†’ Var12 (snoc12 Ξ“ B) A) , Var12 Ξ“ A def vz12 {Ξ“ A} : Var12 (snoc12 Ξ“ A) A := Ξ» Var12 vz12 vs => vz12 _ _ def vs12 {Ξ“ B A} : Var12 Ξ“ A β†’ Var12 (snoc12 Ξ“ B) A := Ξ» x Var12 vz12 vs12 => vs12 _ _ _ (x Var12 vz12 vs12) def Tm12 : Con12 β†’ Ty12 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm12 : Con12 β†’ Ty12 β†’ Type) (var : βˆ€ Ξ“ A , Var12 Ξ“ A β†’ Tm12 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm12 (snoc12 Ξ“ A) B β†’ Tm12 Ξ“ (arr12 A B)) (app : βˆ€ Ξ“ A B , Tm12 Ξ“ (arr12 A B) β†’ Tm12 Ξ“ A β†’ Tm12 Ξ“ B) , Tm12 Ξ“ A def var12 {Ξ“ A} : Var12 Ξ“ A β†’ Tm12 Ξ“ A := Ξ» x Tm12 var12 lam app => var12 _ _ x def lam12 {Ξ“ A B} : Tm12 (snoc12 Ξ“ A) B β†’ Tm12 Ξ“ (arr12 A B) := Ξ» t Tm12 var12 lam12 app => lam12 _ _ _ (t Tm12 var12 lam12 app) def app12 {Ξ“ A B} : Tm12 Ξ“ (arr12 A B) β†’ Tm12 Ξ“ A β†’ Tm12 Ξ“ B := Ξ» t u Tm12 var12 lam12 app12 => app12 _ _ _ (t Tm12 var12 lam12 app12) (u Tm12 var12 lam12 app12) def v012 {Ξ“ A} : Tm12 (snoc12 Ξ“ A) A := var12 vz12 def v112 {Ξ“ A B} : Tm12 (snoc12 (snoc12 Ξ“ A) B) A := var12 (vs12 vz12) def v212 {Ξ“ A B C} : Tm12 (snoc12 (snoc12 (snoc12 Ξ“ A) B) C) A := var12 (vs12 (vs12 vz12)) def v312 {Ξ“ A B C D} : Tm12 (snoc12 (snoc12 (snoc12 (snoc12 Ξ“ A) B) C) D) A := var12 (vs12 (vs12 (vs12 vz12))) def v412 {Ξ“ A B C D E} : Tm12 (snoc12 (snoc12 (snoc12 (snoc12 (snoc12 Ξ“ A) B) C) D) E) A := var12 (vs12 (vs12 (vs12 (vs12 vz12)))) def test12 {Ξ“ A} : Tm12 Ξ“ (arr12 (arr12 A A) (arr12 A A)) := lam12 (lam12 (app12 v112 (app12 v112 (app12 v112 (app12 v112 (app12 v112 (app12 v112 v012))))))) def Ty13 : Type 1 := βˆ€ (Ty13 : Type) (ΞΉ : Ty13) (arr : Ty13 β†’ Ty13 β†’ Ty13) , Ty13 def ΞΉ13 : Ty13 := Ξ» _ ΞΉ13 _ => ΞΉ13 def arr13 : Ty13 β†’ Ty13 β†’ Ty13 := Ξ» A B Ty13 ΞΉ13 arr13 => arr13 (A Ty13 ΞΉ13 arr13) (B Ty13 ΞΉ13 arr13) def Con13 : Type 1 := βˆ€ (Con13 : Type) (nil : Con13) (snoc : Con13 β†’ Ty13 β†’ Con13) , Con13 def nil13 : Con13 := Ξ» Con13 nil13 snoc => nil13 def snoc13 : Con13 β†’ Ty13 β†’ Con13 := Ξ» Ξ“ A Con13 nil13 snoc13 => snoc13 (Ξ“ Con13 nil13 snoc13) A def Var13 : Con13 β†’ Ty13 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var13 : Con13 β†’ Ty13 β†’ Type) (vz : βˆ€ Ξ“ A, Var13 (snoc13 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var13 Ξ“ A β†’ Var13 (snoc13 Ξ“ B) A) , Var13 Ξ“ A def vz13 {Ξ“ A} : Var13 (snoc13 Ξ“ A) A := Ξ» Var13 vz13 vs => vz13 _ _ def vs13 {Ξ“ B A} : Var13 Ξ“ A β†’ Var13 (snoc13 Ξ“ B) A := Ξ» x Var13 vz13 vs13 => vs13 _ _ _ (x Var13 vz13 vs13) def Tm13 : Con13 β†’ Ty13 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm13 : Con13 β†’ Ty13 β†’ Type) (var : βˆ€ Ξ“ A , Var13 Ξ“ A β†’ Tm13 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm13 (snoc13 Ξ“ A) B β†’ Tm13 Ξ“ (arr13 A B)) (app : βˆ€ Ξ“ A B , Tm13 Ξ“ (arr13 A B) β†’ Tm13 Ξ“ A β†’ Tm13 Ξ“ B) , Tm13 Ξ“ A def var13 {Ξ“ A} : Var13 Ξ“ A β†’ Tm13 Ξ“ A := Ξ» x Tm13 var13 lam app => var13 _ _ x def lam13 {Ξ“ A B} : Tm13 (snoc13 Ξ“ A) B β†’ Tm13 Ξ“ (arr13 A B) := Ξ» t Tm13 var13 lam13 app => lam13 _ _ _ (t Tm13 var13 lam13 app) def app13 {Ξ“ A B} : Tm13 Ξ“ (arr13 A B) β†’ Tm13 Ξ“ A β†’ Tm13 Ξ“ B := Ξ» t u Tm13 var13 lam13 app13 => app13 _ _ _ (t Tm13 var13 lam13 app13) (u Tm13 var13 lam13 app13) def v013 {Ξ“ A} : Tm13 (snoc13 Ξ“ A) A := var13 vz13 def v113 {Ξ“ A B} : Tm13 (snoc13 (snoc13 Ξ“ A) B) A := var13 (vs13 vz13) def v213 {Ξ“ A B C} : Tm13 (snoc13 (snoc13 (snoc13 Ξ“ A) B) C) A := var13 (vs13 (vs13 vz13)) def v313 {Ξ“ A B C D} : Tm13 (snoc13 (snoc13 (snoc13 (snoc13 Ξ“ A) B) C) D) A := var13 (vs13 (vs13 (vs13 vz13))) def v413 {Ξ“ A B C D E} : Tm13 (snoc13 (snoc13 (snoc13 (snoc13 (snoc13 Ξ“ A) B) C) D) E) A := var13 (vs13 (vs13 (vs13 (vs13 vz13)))) def test13 {Ξ“ A} : Tm13 Ξ“ (arr13 (arr13 A A) (arr13 A A)) := lam13 (lam13 (app13 v113 (app13 v113 (app13 v113 (app13 v113 (app13 v113 (app13 v113 v013))))))) def Ty14 : Type 1 := βˆ€ (Ty14 : Type) (ΞΉ : Ty14) (arr : Ty14 β†’ Ty14 β†’ Ty14) , Ty14 def ΞΉ14 : Ty14 := Ξ» _ ΞΉ14 _ => ΞΉ14 def arr14 : Ty14 β†’ Ty14 β†’ Ty14 := Ξ» A B Ty14 ΞΉ14 arr14 => arr14 (A Ty14 ΞΉ14 arr14) (B Ty14 ΞΉ14 arr14) def Con14 : Type 1 := βˆ€ (Con14 : Type) (nil : Con14) (snoc : Con14 β†’ Ty14 β†’ Con14) , Con14 def nil14 : Con14 := Ξ» Con14 nil14 snoc => nil14 def snoc14 : Con14 β†’ Ty14 β†’ Con14 := Ξ» Ξ“ A Con14 nil14 snoc14 => snoc14 (Ξ“ Con14 nil14 snoc14) A def Var14 : Con14 β†’ Ty14 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var14 : Con14 β†’ Ty14 β†’ Type) (vz : βˆ€ Ξ“ A, Var14 (snoc14 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var14 Ξ“ A β†’ Var14 (snoc14 Ξ“ B) A) , Var14 Ξ“ A def vz14 {Ξ“ A} : Var14 (snoc14 Ξ“ A) A := Ξ» Var14 vz14 vs => vz14 _ _ def vs14 {Ξ“ B A} : Var14 Ξ“ A β†’ Var14 (snoc14 Ξ“ B) A := Ξ» x Var14 vz14 vs14 => vs14 _ _ _ (x Var14 vz14 vs14) def Tm14 : Con14 β†’ Ty14 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm14 : Con14 β†’ Ty14 β†’ Type) (var : βˆ€ Ξ“ A , Var14 Ξ“ A β†’ Tm14 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm14 (snoc14 Ξ“ A) B β†’ Tm14 Ξ“ (arr14 A B)) (app : βˆ€ Ξ“ A B , Tm14 Ξ“ (arr14 A B) β†’ Tm14 Ξ“ A β†’ Tm14 Ξ“ B) , Tm14 Ξ“ A def var14 {Ξ“ A} : Var14 Ξ“ A β†’ Tm14 Ξ“ A := Ξ» x Tm14 var14 lam app => var14 _ _ x def lam14 {Ξ“ A B} : Tm14 (snoc14 Ξ“ A) B β†’ Tm14 Ξ“ (arr14 A B) := Ξ» t Tm14 var14 lam14 app => lam14 _ _ _ (t Tm14 var14 lam14 app) def app14 {Ξ“ A B} : Tm14 Ξ“ (arr14 A B) β†’ Tm14 Ξ“ A β†’ Tm14 Ξ“ B := Ξ» t u Tm14 var14 lam14 app14 => app14 _ _ _ (t Tm14 var14 lam14 app14) (u Tm14 var14 lam14 app14) def v014 {Ξ“ A} : Tm14 (snoc14 Ξ“ A) A := var14 vz14 def v114 {Ξ“ A B} : Tm14 (snoc14 (snoc14 Ξ“ A) B) A := var14 (vs14 vz14) def v214 {Ξ“ A B C} : Tm14 (snoc14 (snoc14 (snoc14 Ξ“ A) B) C) A := var14 (vs14 (vs14 vz14)) def v314 {Ξ“ A B C D} : Tm14 (snoc14 (snoc14 (snoc14 (snoc14 Ξ“ A) B) C) D) A := var14 (vs14 (vs14 (vs14 vz14))) def v414 {Ξ“ A B C D E} : Tm14 (snoc14 (snoc14 (snoc14 (snoc14 (snoc14 Ξ“ A) B) C) D) E) A := var14 (vs14 (vs14 (vs14 (vs14 vz14)))) def test14 {Ξ“ A} : Tm14 Ξ“ (arr14 (arr14 A A) (arr14 A A)) := lam14 (lam14 (app14 v114 (app14 v114 (app14 v114 (app14 v114 (app14 v114 (app14 v114 v014))))))) def Ty15 : Type 1 := βˆ€ (Ty15 : Type) (ΞΉ : Ty15) (arr : Ty15 β†’ Ty15 β†’ Ty15) , Ty15 def ΞΉ15 : Ty15 := Ξ» _ ΞΉ15 _ => ΞΉ15 def arr15 : Ty15 β†’ Ty15 β†’ Ty15 := Ξ» A B Ty15 ΞΉ15 arr15 => arr15 (A Ty15 ΞΉ15 arr15) (B Ty15 ΞΉ15 arr15) def Con15 : Type 1 := βˆ€ (Con15 : Type) (nil : Con15) (snoc : Con15 β†’ Ty15 β†’ Con15) , Con15 def nil15 : Con15 := Ξ» Con15 nil15 snoc => nil15 def snoc15 : Con15 β†’ Ty15 β†’ Con15 := Ξ» Ξ“ A Con15 nil15 snoc15 => snoc15 (Ξ“ Con15 nil15 snoc15) A def Var15 : Con15 β†’ Ty15 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var15 : Con15 β†’ Ty15 β†’ Type) (vz : βˆ€ Ξ“ A, Var15 (snoc15 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var15 Ξ“ A β†’ Var15 (snoc15 Ξ“ B) A) , Var15 Ξ“ A def vz15 {Ξ“ A} : Var15 (snoc15 Ξ“ A) A := Ξ» Var15 vz15 vs => vz15 _ _ def vs15 {Ξ“ B A} : Var15 Ξ“ A β†’ Var15 (snoc15 Ξ“ B) A := Ξ» x Var15 vz15 vs15 => vs15 _ _ _ (x Var15 vz15 vs15) def Tm15 : Con15 β†’ Ty15 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm15 : Con15 β†’ Ty15 β†’ Type) (var : βˆ€ Ξ“ A , Var15 Ξ“ A β†’ Tm15 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm15 (snoc15 Ξ“ A) B β†’ Tm15 Ξ“ (arr15 A B)) (app : βˆ€ Ξ“ A B , Tm15 Ξ“ (arr15 A B) β†’ Tm15 Ξ“ A β†’ Tm15 Ξ“ B) , Tm15 Ξ“ A def var15 {Ξ“ A} : Var15 Ξ“ A β†’ Tm15 Ξ“ A := Ξ» x Tm15 var15 lam app => var15 _ _ x def lam15 {Ξ“ A B} : Tm15 (snoc15 Ξ“ A) B β†’ Tm15 Ξ“ (arr15 A B) := Ξ» t Tm15 var15 lam15 app => lam15 _ _ _ (t Tm15 var15 lam15 app) def app15 {Ξ“ A B} : Tm15 Ξ“ (arr15 A B) β†’ Tm15 Ξ“ A β†’ Tm15 Ξ“ B := Ξ» t u Tm15 var15 lam15 app15 => app15 _ _ _ (t Tm15 var15 lam15 app15) (u Tm15 var15 lam15 app15) def v015 {Ξ“ A} : Tm15 (snoc15 Ξ“ A) A := var15 vz15 def v115 {Ξ“ A B} : Tm15 (snoc15 (snoc15 Ξ“ A) B) A := var15 (vs15 vz15) def v215 {Ξ“ A B C} : Tm15 (snoc15 (snoc15 (snoc15 Ξ“ A) B) C) A := var15 (vs15 (vs15 vz15)) def v315 {Ξ“ A B C D} : Tm15 (snoc15 (snoc15 (snoc15 (snoc15 Ξ“ A) B) C) D) A := var15 (vs15 (vs15 (vs15 vz15))) def v415 {Ξ“ A B C D E} : Tm15 (snoc15 (snoc15 (snoc15 (snoc15 (snoc15 Ξ“ A) B) C) D) E) A := var15 (vs15 (vs15 (vs15 (vs15 vz15)))) def test15 {Ξ“ A} : Tm15 Ξ“ (arr15 (arr15 A A) (arr15 A A)) := lam15 (lam15 (app15 v115 (app15 v115 (app15 v115 (app15 v115 (app15 v115 (app15 v115 v015))))))) def Ty16 : Type 1 := βˆ€ (Ty16 : Type) (ΞΉ : Ty16) (arr : Ty16 β†’ Ty16 β†’ Ty16) , Ty16 def ΞΉ16 : Ty16 := Ξ» _ ΞΉ16 _ => ΞΉ16 def arr16 : Ty16 β†’ Ty16 β†’ Ty16 := Ξ» A B Ty16 ΞΉ16 arr16 => arr16 (A Ty16 ΞΉ16 arr16) (B Ty16 ΞΉ16 arr16) def Con16 : Type 1 := βˆ€ (Con16 : Type) (nil : Con16) (snoc : Con16 β†’ Ty16 β†’ Con16) , Con16 def nil16 : Con16 := Ξ» Con16 nil16 snoc => nil16 def snoc16 : Con16 β†’ Ty16 β†’ Con16 := Ξ» Ξ“ A Con16 nil16 snoc16 => snoc16 (Ξ“ Con16 nil16 snoc16) A def Var16 : Con16 β†’ Ty16 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var16 : Con16 β†’ Ty16 β†’ Type) (vz : βˆ€ Ξ“ A, Var16 (snoc16 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var16 Ξ“ A β†’ Var16 (snoc16 Ξ“ B) A) , Var16 Ξ“ A def vz16 {Ξ“ A} : Var16 (snoc16 Ξ“ A) A := Ξ» Var16 vz16 vs => vz16 _ _ def vs16 {Ξ“ B A} : Var16 Ξ“ A β†’ Var16 (snoc16 Ξ“ B) A := Ξ» x Var16 vz16 vs16 => vs16 _ _ _ (x Var16 vz16 vs16) def Tm16 : Con16 β†’ Ty16 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm16 : Con16 β†’ Ty16 β†’ Type) (var : βˆ€ Ξ“ A , Var16 Ξ“ A β†’ Tm16 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm16 (snoc16 Ξ“ A) B β†’ Tm16 Ξ“ (arr16 A B)) (app : βˆ€ Ξ“ A B , Tm16 Ξ“ (arr16 A B) β†’ Tm16 Ξ“ A β†’ Tm16 Ξ“ B) , Tm16 Ξ“ A def var16 {Ξ“ A} : Var16 Ξ“ A β†’ Tm16 Ξ“ A := Ξ» x Tm16 var16 lam app => var16 _ _ x def lam16 {Ξ“ A B} : Tm16 (snoc16 Ξ“ A) B β†’ Tm16 Ξ“ (arr16 A B) := Ξ» t Tm16 var16 lam16 app => lam16 _ _ _ (t Tm16 var16 lam16 app) def app16 {Ξ“ A B} : Tm16 Ξ“ (arr16 A B) β†’ Tm16 Ξ“ A β†’ Tm16 Ξ“ B := Ξ» t u Tm16 var16 lam16 app16 => app16 _ _ _ (t Tm16 var16 lam16 app16) (u Tm16 var16 lam16 app16) def v016 {Ξ“ A} : Tm16 (snoc16 Ξ“ A) A := var16 vz16 def v116 {Ξ“ A B} : Tm16 (snoc16 (snoc16 Ξ“ A) B) A := var16 (vs16 vz16) def v216 {Ξ“ A B C} : Tm16 (snoc16 (snoc16 (snoc16 Ξ“ A) B) C) A := var16 (vs16 (vs16 vz16)) def v316 {Ξ“ A B C D} : Tm16 (snoc16 (snoc16 (snoc16 (snoc16 Ξ“ A) B) C) D) A := var16 (vs16 (vs16 (vs16 vz16))) def v416 {Ξ“ A B C D E} : Tm16 (snoc16 (snoc16 (snoc16 (snoc16 (snoc16 Ξ“ A) B) C) D) E) A := var16 (vs16 (vs16 (vs16 (vs16 vz16)))) def test16 {Ξ“ A} : Tm16 Ξ“ (arr16 (arr16 A A) (arr16 A A)) := lam16 (lam16 (app16 v116 (app16 v116 (app16 v116 (app16 v116 (app16 v116 (app16 v116 v016))))))) def Ty17 : Type 1 := βˆ€ (Ty17 : Type) (ΞΉ : Ty17) (arr : Ty17 β†’ Ty17 β†’ Ty17) , Ty17 def ΞΉ17 : Ty17 := Ξ» _ ΞΉ17 _ => ΞΉ17 def arr17 : Ty17 β†’ Ty17 β†’ Ty17 := Ξ» A B Ty17 ΞΉ17 arr17 => arr17 (A Ty17 ΞΉ17 arr17) (B Ty17 ΞΉ17 arr17) def Con17 : Type 1 := βˆ€ (Con17 : Type) (nil : Con17) (snoc : Con17 β†’ Ty17 β†’ Con17) , Con17 def nil17 : Con17 := Ξ» Con17 nil17 snoc => nil17 def snoc17 : Con17 β†’ Ty17 β†’ Con17 := Ξ» Ξ“ A Con17 nil17 snoc17 => snoc17 (Ξ“ Con17 nil17 snoc17) A def Var17 : Con17 β†’ Ty17 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var17 : Con17 β†’ Ty17 β†’ Type) (vz : βˆ€ Ξ“ A, Var17 (snoc17 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var17 Ξ“ A β†’ Var17 (snoc17 Ξ“ B) A) , Var17 Ξ“ A def vz17 {Ξ“ A} : Var17 (snoc17 Ξ“ A) A := Ξ» Var17 vz17 vs => vz17 _ _ def vs17 {Ξ“ B A} : Var17 Ξ“ A β†’ Var17 (snoc17 Ξ“ B) A := Ξ» x Var17 vz17 vs17 => vs17 _ _ _ (x Var17 vz17 vs17) def Tm17 : Con17 β†’ Ty17 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm17 : Con17 β†’ Ty17 β†’ Type) (var : βˆ€ Ξ“ A , Var17 Ξ“ A β†’ Tm17 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm17 (snoc17 Ξ“ A) B β†’ Tm17 Ξ“ (arr17 A B)) (app : βˆ€ Ξ“ A B , Tm17 Ξ“ (arr17 A B) β†’ Tm17 Ξ“ A β†’ Tm17 Ξ“ B) , Tm17 Ξ“ A def var17 {Ξ“ A} : Var17 Ξ“ A β†’ Tm17 Ξ“ A := Ξ» x Tm17 var17 lam app => var17 _ _ x def lam17 {Ξ“ A B} : Tm17 (snoc17 Ξ“ A) B β†’ Tm17 Ξ“ (arr17 A B) := Ξ» t Tm17 var17 lam17 app => lam17 _ _ _ (t Tm17 var17 lam17 app) def app17 {Ξ“ A B} : Tm17 Ξ“ (arr17 A B) β†’ Tm17 Ξ“ A β†’ Tm17 Ξ“ B := Ξ» t u Tm17 var17 lam17 app17 => app17 _ _ _ (t Tm17 var17 lam17 app17) (u Tm17 var17 lam17 app17) def v017 {Ξ“ A} : Tm17 (snoc17 Ξ“ A) A := var17 vz17 def v117 {Ξ“ A B} : Tm17 (snoc17 (snoc17 Ξ“ A) B) A := var17 (vs17 vz17) def v217 {Ξ“ A B C} : Tm17 (snoc17 (snoc17 (snoc17 Ξ“ A) B) C) A := var17 (vs17 (vs17 vz17)) def v317 {Ξ“ A B C D} : Tm17 (snoc17 (snoc17 (snoc17 (snoc17 Ξ“ A) B) C) D) A := var17 (vs17 (vs17 (vs17 vz17))) def v417 {Ξ“ A B C D E} : Tm17 (snoc17 (snoc17 (snoc17 (snoc17 (snoc17 Ξ“ A) B) C) D) E) A := var17 (vs17 (vs17 (vs17 (vs17 vz17)))) def test17 {Ξ“ A} : Tm17 Ξ“ (arr17 (arr17 A A) (arr17 A A)) := lam17 (lam17 (app17 v117 (app17 v117 (app17 v117 (app17 v117 (app17 v117 (app17 v117 v017))))))) def Ty18 : Type 1 := βˆ€ (Ty18 : Type) (ΞΉ : Ty18) (arr : Ty18 β†’ Ty18 β†’ Ty18) , Ty18 def ΞΉ18 : Ty18 := Ξ» _ ΞΉ18 _ => ΞΉ18 def arr18 : Ty18 β†’ Ty18 β†’ Ty18 := Ξ» A B Ty18 ΞΉ18 arr18 => arr18 (A Ty18 ΞΉ18 arr18) (B Ty18 ΞΉ18 arr18) def Con18 : Type 1 := βˆ€ (Con18 : Type) (nil : Con18) (snoc : Con18 β†’ Ty18 β†’ Con18) , Con18 def nil18 : Con18 := Ξ» Con18 nil18 snoc => nil18 def snoc18 : Con18 β†’ Ty18 β†’ Con18 := Ξ» Ξ“ A Con18 nil18 snoc18 => snoc18 (Ξ“ Con18 nil18 snoc18) A def Var18 : Con18 β†’ Ty18 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var18 : Con18 β†’ Ty18 β†’ Type) (vz : βˆ€ Ξ“ A, Var18 (snoc18 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var18 Ξ“ A β†’ Var18 (snoc18 Ξ“ B) A) , Var18 Ξ“ A def vz18 {Ξ“ A} : Var18 (snoc18 Ξ“ A) A := Ξ» Var18 vz18 vs => vz18 _ _ def vs18 {Ξ“ B A} : Var18 Ξ“ A β†’ Var18 (snoc18 Ξ“ B) A := Ξ» x Var18 vz18 vs18 => vs18 _ _ _ (x Var18 vz18 vs18) def Tm18 : Con18 β†’ Ty18 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm18 : Con18 β†’ Ty18 β†’ Type) (var : βˆ€ Ξ“ A , Var18 Ξ“ A β†’ Tm18 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm18 (snoc18 Ξ“ A) B β†’ Tm18 Ξ“ (arr18 A B)) (app : βˆ€ Ξ“ A B , Tm18 Ξ“ (arr18 A B) β†’ Tm18 Ξ“ A β†’ Tm18 Ξ“ B) , Tm18 Ξ“ A def var18 {Ξ“ A} : Var18 Ξ“ A β†’ Tm18 Ξ“ A := Ξ» x Tm18 var18 lam app => var18 _ _ x def lam18 {Ξ“ A B} : Tm18 (snoc18 Ξ“ A) B β†’ Tm18 Ξ“ (arr18 A B) := Ξ» t Tm18 var18 lam18 app => lam18 _ _ _ (t Tm18 var18 lam18 app) def app18 {Ξ“ A B} : Tm18 Ξ“ (arr18 A B) β†’ Tm18 Ξ“ A β†’ Tm18 Ξ“ B := Ξ» t u Tm18 var18 lam18 app18 => app18 _ _ _ (t Tm18 var18 lam18 app18) (u Tm18 var18 lam18 app18) def v018 {Ξ“ A} : Tm18 (snoc18 Ξ“ A) A := var18 vz18 def v118 {Ξ“ A B} : Tm18 (snoc18 (snoc18 Ξ“ A) B) A := var18 (vs18 vz18) def v218 {Ξ“ A B C} : Tm18 (snoc18 (snoc18 (snoc18 Ξ“ A) B) C) A := var18 (vs18 (vs18 vz18)) def v318 {Ξ“ A B C D} : Tm18 (snoc18 (snoc18 (snoc18 (snoc18 Ξ“ A) B) C) D) A := var18 (vs18 (vs18 (vs18 vz18))) def v418 {Ξ“ A B C D E} : Tm18 (snoc18 (snoc18 (snoc18 (snoc18 (snoc18 Ξ“ A) B) C) D) E) A := var18 (vs18 (vs18 (vs18 (vs18 vz18)))) def test18 {Ξ“ A} : Tm18 Ξ“ (arr18 (arr18 A A) (arr18 A A)) := lam18 (lam18 (app18 v118 (app18 v118 (app18 v118 (app18 v118 (app18 v118 (app18 v118 v018))))))) def Ty19 : Type 1 := βˆ€ (Ty19 : Type) (ΞΉ : Ty19) (arr : Ty19 β†’ Ty19 β†’ Ty19) , Ty19 def ΞΉ19 : Ty19 := Ξ» _ ΞΉ19 _ => ΞΉ19 def arr19 : Ty19 β†’ Ty19 β†’ Ty19 := Ξ» A B Ty19 ΞΉ19 arr19 => arr19 (A Ty19 ΞΉ19 arr19) (B Ty19 ΞΉ19 arr19) def Con19 : Type 1 := βˆ€ (Con19 : Type) (nil : Con19) (snoc : Con19 β†’ Ty19 β†’ Con19) , Con19 def nil19 : Con19 := Ξ» Con19 nil19 snoc => nil19 def snoc19 : Con19 β†’ Ty19 β†’ Con19 := Ξ» Ξ“ A Con19 nil19 snoc19 => snoc19 (Ξ“ Con19 nil19 snoc19) A def Var19 : Con19 β†’ Ty19 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var19 : Con19 β†’ Ty19 β†’ Type) (vz : βˆ€ Ξ“ A, Var19 (snoc19 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var19 Ξ“ A β†’ Var19 (snoc19 Ξ“ B) A) , Var19 Ξ“ A def vz19 {Ξ“ A} : Var19 (snoc19 Ξ“ A) A := Ξ» Var19 vz19 vs => vz19 _ _ def vs19 {Ξ“ B A} : Var19 Ξ“ A β†’ Var19 (snoc19 Ξ“ B) A := Ξ» x Var19 vz19 vs19 => vs19 _ _ _ (x Var19 vz19 vs19) def Tm19 : Con19 β†’ Ty19 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm19 : Con19 β†’ Ty19 β†’ Type) (var : βˆ€ Ξ“ A , Var19 Ξ“ A β†’ Tm19 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm19 (snoc19 Ξ“ A) B β†’ Tm19 Ξ“ (arr19 A B)) (app : βˆ€ Ξ“ A B , Tm19 Ξ“ (arr19 A B) β†’ Tm19 Ξ“ A β†’ Tm19 Ξ“ B) , Tm19 Ξ“ A def var19 {Ξ“ A} : Var19 Ξ“ A β†’ Tm19 Ξ“ A := Ξ» x Tm19 var19 lam app => var19 _ _ x def lam19 {Ξ“ A B} : Tm19 (snoc19 Ξ“ A) B β†’ Tm19 Ξ“ (arr19 A B) := Ξ» t Tm19 var19 lam19 app => lam19 _ _ _ (t Tm19 var19 lam19 app) def app19 {Ξ“ A B} : Tm19 Ξ“ (arr19 A B) β†’ Tm19 Ξ“ A β†’ Tm19 Ξ“ B := Ξ» t u Tm19 var19 lam19 app19 => app19 _ _ _ (t Tm19 var19 lam19 app19) (u Tm19 var19 lam19 app19) def v019 {Ξ“ A} : Tm19 (snoc19 Ξ“ A) A := var19 vz19 def v119 {Ξ“ A B} : Tm19 (snoc19 (snoc19 Ξ“ A) B) A := var19 (vs19 vz19) def v219 {Ξ“ A B C} : Tm19 (snoc19 (snoc19 (snoc19 Ξ“ A) B) C) A := var19 (vs19 (vs19 vz19)) def v319 {Ξ“ A B C D} : Tm19 (snoc19 (snoc19 (snoc19 (snoc19 Ξ“ A) B) C) D) A := var19 (vs19 (vs19 (vs19 vz19))) def v419 {Ξ“ A B C D E} : Tm19 (snoc19 (snoc19 (snoc19 (snoc19 (snoc19 Ξ“ A) B) C) D) E) A := var19 (vs19 (vs19 (vs19 (vs19 vz19)))) def test19 {Ξ“ A} : Tm19 Ξ“ (arr19 (arr19 A A) (arr19 A A)) := lam19 (lam19 (app19 v119 (app19 v119 (app19 v119 (app19 v119 (app19 v119 (app19 v119 v019))))))) def Ty20 : Type 1 := βˆ€ (Ty20 : Type) (ΞΉ : Ty20) (arr : Ty20 β†’ Ty20 β†’ Ty20) , Ty20 def ΞΉ20 : Ty20 := Ξ» _ ΞΉ20 _ => ΞΉ20 def arr20 : Ty20 β†’ Ty20 β†’ Ty20 := Ξ» A B Ty20 ΞΉ20 arr20 => arr20 (A Ty20 ΞΉ20 arr20) (B Ty20 ΞΉ20 arr20) def Con20 : Type 1 := βˆ€ (Con20 : Type) (nil : Con20) (snoc : Con20 β†’ Ty20 β†’ Con20) , Con20 def nil20 : Con20 := Ξ» Con20 nil20 snoc => nil20 def snoc20 : Con20 β†’ Ty20 β†’ Con20 := Ξ» Ξ“ A Con20 nil20 snoc20 => snoc20 (Ξ“ Con20 nil20 snoc20) A def Var20 : Con20 β†’ Ty20 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var20 : Con20 β†’ Ty20 β†’ Type) (vz : βˆ€ Ξ“ A, Var20 (snoc20 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var20 Ξ“ A β†’ Var20 (snoc20 Ξ“ B) A) , Var20 Ξ“ A def vz20 {Ξ“ A} : Var20 (snoc20 Ξ“ A) A := Ξ» Var20 vz20 vs => vz20 _ _ def vs20 {Ξ“ B A} : Var20 Ξ“ A β†’ Var20 (snoc20 Ξ“ B) A := Ξ» x Var20 vz20 vs20 => vs20 _ _ _ (x Var20 vz20 vs20) def Tm20 : Con20 β†’ Ty20 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm20 : Con20 β†’ Ty20 β†’ Type) (var : βˆ€ Ξ“ A , Var20 Ξ“ A β†’ Tm20 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm20 (snoc20 Ξ“ A) B β†’ Tm20 Ξ“ (arr20 A B)) (app : βˆ€ Ξ“ A B , Tm20 Ξ“ (arr20 A B) β†’ Tm20 Ξ“ A β†’ Tm20 Ξ“ B) , Tm20 Ξ“ A def var20 {Ξ“ A} : Var20 Ξ“ A β†’ Tm20 Ξ“ A := Ξ» x Tm20 var20 lam app => var20 _ _ x def lam20 {Ξ“ A B} : Tm20 (snoc20 Ξ“ A) B β†’ Tm20 Ξ“ (arr20 A B) := Ξ» t Tm20 var20 lam20 app => lam20 _ _ _ (t Tm20 var20 lam20 app) def app20 {Ξ“ A B} : Tm20 Ξ“ (arr20 A B) β†’ Tm20 Ξ“ A β†’ Tm20 Ξ“ B := Ξ» t u Tm20 var20 lam20 app20 => app20 _ _ _ (t Tm20 var20 lam20 app20) (u Tm20 var20 lam20 app20) def v020 {Ξ“ A} : Tm20 (snoc20 Ξ“ A) A := var20 vz20 def v120 {Ξ“ A B} : Tm20 (snoc20 (snoc20 Ξ“ A) B) A := var20 (vs20 vz20) def v220 {Ξ“ A B C} : Tm20 (snoc20 (snoc20 (snoc20 Ξ“ A) B) C) A := var20 (vs20 (vs20 vz20)) def v320 {Ξ“ A B C D} : Tm20 (snoc20 (snoc20 (snoc20 (snoc20 Ξ“ A) B) C) D) A := var20 (vs20 (vs20 (vs20 vz20))) def v420 {Ξ“ A B C D E} : Tm20 (snoc20 (snoc20 (snoc20 (snoc20 (snoc20 Ξ“ A) B) C) D) E) A := var20 (vs20 (vs20 (vs20 (vs20 vz20)))) def test20 {Ξ“ A} : Tm20 Ξ“ (arr20 (arr20 A A) (arr20 A A)) := lam20 (lam20 (app20 v120 (app20 v120 (app20 v120 (app20 v120 (app20 v120 (app20 v120 v020))))))) def Ty21 : Type 1 := βˆ€ (Ty21 : Type) (ΞΉ : Ty21) (arr : Ty21 β†’ Ty21 β†’ Ty21) , Ty21 def ΞΉ21 : Ty21 := Ξ» _ ΞΉ21 _ => ΞΉ21 def arr21 : Ty21 β†’ Ty21 β†’ Ty21 := Ξ» A B Ty21 ΞΉ21 arr21 => arr21 (A Ty21 ΞΉ21 arr21) (B Ty21 ΞΉ21 arr21) def Con21 : Type 1 := βˆ€ (Con21 : Type) (nil : Con21) (snoc : Con21 β†’ Ty21 β†’ Con21) , Con21 def nil21 : Con21 := Ξ» Con21 nil21 snoc => nil21 def snoc21 : Con21 β†’ Ty21 β†’ Con21 := Ξ» Ξ“ A Con21 nil21 snoc21 => snoc21 (Ξ“ Con21 nil21 snoc21) A def Var21 : Con21 β†’ Ty21 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var21 : Con21 β†’ Ty21 β†’ Type) (vz : βˆ€ Ξ“ A, Var21 (snoc21 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var21 Ξ“ A β†’ Var21 (snoc21 Ξ“ B) A) , Var21 Ξ“ A def vz21 {Ξ“ A} : Var21 (snoc21 Ξ“ A) A := Ξ» Var21 vz21 vs => vz21 _ _ def vs21 {Ξ“ B A} : Var21 Ξ“ A β†’ Var21 (snoc21 Ξ“ B) A := Ξ» x Var21 vz21 vs21 => vs21 _ _ _ (x Var21 vz21 vs21) def Tm21 : Con21 β†’ Ty21 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm21 : Con21 β†’ Ty21 β†’ Type) (var : βˆ€ Ξ“ A , Var21 Ξ“ A β†’ Tm21 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm21 (snoc21 Ξ“ A) B β†’ Tm21 Ξ“ (arr21 A B)) (app : βˆ€ Ξ“ A B , Tm21 Ξ“ (arr21 A B) β†’ Tm21 Ξ“ A β†’ Tm21 Ξ“ B) , Tm21 Ξ“ A def var21 {Ξ“ A} : Var21 Ξ“ A β†’ Tm21 Ξ“ A := Ξ» x Tm21 var21 lam app => var21 _ _ x def lam21 {Ξ“ A B} : Tm21 (snoc21 Ξ“ A) B β†’ Tm21 Ξ“ (arr21 A B) := Ξ» t Tm21 var21 lam21 app => lam21 _ _ _ (t Tm21 var21 lam21 app) def app21 {Ξ“ A B} : Tm21 Ξ“ (arr21 A B) β†’ Tm21 Ξ“ A β†’ Tm21 Ξ“ B := Ξ» t u Tm21 var21 lam21 app21 => app21 _ _ _ (t Tm21 var21 lam21 app21) (u Tm21 var21 lam21 app21) def v021 {Ξ“ A} : Tm21 (snoc21 Ξ“ A) A := var21 vz21 def v121 {Ξ“ A B} : Tm21 (snoc21 (snoc21 Ξ“ A) B) A := var21 (vs21 vz21) def v221 {Ξ“ A B C} : Tm21 (snoc21 (snoc21 (snoc21 Ξ“ A) B) C) A := var21 (vs21 (vs21 vz21)) def v321 {Ξ“ A B C D} : Tm21 (snoc21 (snoc21 (snoc21 (snoc21 Ξ“ A) B) C) D) A := var21 (vs21 (vs21 (vs21 vz21))) def v421 {Ξ“ A B C D E} : Tm21 (snoc21 (snoc21 (snoc21 (snoc21 (snoc21 Ξ“ A) B) C) D) E) A := var21 (vs21 (vs21 (vs21 (vs21 vz21)))) def test21 {Ξ“ A} : Tm21 Ξ“ (arr21 (arr21 A A) (arr21 A A)) := lam21 (lam21 (app21 v121 (app21 v121 (app21 v121 (app21 v121 (app21 v121 (app21 v121 v021))))))) def Ty22 : Type 1 := βˆ€ (Ty22 : Type) (ΞΉ : Ty22) (arr : Ty22 β†’ Ty22 β†’ Ty22) , Ty22 def ΞΉ22 : Ty22 := Ξ» _ ΞΉ22 _ => ΞΉ22 def arr22 : Ty22 β†’ Ty22 β†’ Ty22 := Ξ» A B Ty22 ΞΉ22 arr22 => arr22 (A Ty22 ΞΉ22 arr22) (B Ty22 ΞΉ22 arr22) def Con22 : Type 1 := βˆ€ (Con22 : Type) (nil : Con22) (snoc : Con22 β†’ Ty22 β†’ Con22) , Con22 def nil22 : Con22 := Ξ» Con22 nil22 snoc => nil22 def snoc22 : Con22 β†’ Ty22 β†’ Con22 := Ξ» Ξ“ A Con22 nil22 snoc22 => snoc22 (Ξ“ Con22 nil22 snoc22) A def Var22 : Con22 β†’ Ty22 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var22 : Con22 β†’ Ty22 β†’ Type) (vz : βˆ€ Ξ“ A, Var22 (snoc22 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var22 Ξ“ A β†’ Var22 (snoc22 Ξ“ B) A) , Var22 Ξ“ A def vz22 {Ξ“ A} : Var22 (snoc22 Ξ“ A) A := Ξ» Var22 vz22 vs => vz22 _ _ def vs22 {Ξ“ B A} : Var22 Ξ“ A β†’ Var22 (snoc22 Ξ“ B) A := Ξ» x Var22 vz22 vs22 => vs22 _ _ _ (x Var22 vz22 vs22) def Tm22 : Con22 β†’ Ty22 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm22 : Con22 β†’ Ty22 β†’ Type) (var : βˆ€ Ξ“ A , Var22 Ξ“ A β†’ Tm22 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm22 (snoc22 Ξ“ A) B β†’ Tm22 Ξ“ (arr22 A B)) (app : βˆ€ Ξ“ A B , Tm22 Ξ“ (arr22 A B) β†’ Tm22 Ξ“ A β†’ Tm22 Ξ“ B) , Tm22 Ξ“ A def var22 {Ξ“ A} : Var22 Ξ“ A β†’ Tm22 Ξ“ A := Ξ» x Tm22 var22 lam app => var22 _ _ x def lam22 {Ξ“ A B} : Tm22 (snoc22 Ξ“ A) B β†’ Tm22 Ξ“ (arr22 A B) := Ξ» t Tm22 var22 lam22 app => lam22 _ _ _ (t Tm22 var22 lam22 app) def app22 {Ξ“ A B} : Tm22 Ξ“ (arr22 A B) β†’ Tm22 Ξ“ A β†’ Tm22 Ξ“ B := Ξ» t u Tm22 var22 lam22 app22 => app22 _ _ _ (t Tm22 var22 lam22 app22) (u Tm22 var22 lam22 app22) def v022 {Ξ“ A} : Tm22 (snoc22 Ξ“ A) A := var22 vz22 def v122 {Ξ“ A B} : Tm22 (snoc22 (snoc22 Ξ“ A) B) A := var22 (vs22 vz22) def v222 {Ξ“ A B C} : Tm22 (snoc22 (snoc22 (snoc22 Ξ“ A) B) C) A := var22 (vs22 (vs22 vz22)) def v322 {Ξ“ A B C D} : Tm22 (snoc22 (snoc22 (snoc22 (snoc22 Ξ“ A) B) C) D) A := var22 (vs22 (vs22 (vs22 vz22))) def v422 {Ξ“ A B C D E} : Tm22 (snoc22 (snoc22 (snoc22 (snoc22 (snoc22 Ξ“ A) B) C) D) E) A := var22 (vs22 (vs22 (vs22 (vs22 vz22)))) def test22 {Ξ“ A} : Tm22 Ξ“ (arr22 (arr22 A A) (arr22 A A)) := lam22 (lam22 (app22 v122 (app22 v122 (app22 v122 (app22 v122 (app22 v122 (app22 v122 v022))))))) def Ty23 : Type 1 := βˆ€ (Ty23 : Type) (ΞΉ : Ty23) (arr : Ty23 β†’ Ty23 β†’ Ty23) , Ty23 def ΞΉ23 : Ty23 := Ξ» _ ΞΉ23 _ => ΞΉ23 def arr23 : Ty23 β†’ Ty23 β†’ Ty23 := Ξ» A B Ty23 ΞΉ23 arr23 => arr23 (A Ty23 ΞΉ23 arr23) (B Ty23 ΞΉ23 arr23) def Con23 : Type 1 := βˆ€ (Con23 : Type) (nil : Con23) (snoc : Con23 β†’ Ty23 β†’ Con23) , Con23 def nil23 : Con23 := Ξ» Con23 nil23 snoc => nil23 def snoc23 : Con23 β†’ Ty23 β†’ Con23 := Ξ» Ξ“ A Con23 nil23 snoc23 => snoc23 (Ξ“ Con23 nil23 snoc23) A def Var23 : Con23 β†’ Ty23 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var23 : Con23 β†’ Ty23 β†’ Type) (vz : βˆ€ Ξ“ A, Var23 (snoc23 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var23 Ξ“ A β†’ Var23 (snoc23 Ξ“ B) A) , Var23 Ξ“ A def vz23 {Ξ“ A} : Var23 (snoc23 Ξ“ A) A := Ξ» Var23 vz23 vs => vz23 _ _ def vs23 {Ξ“ B A} : Var23 Ξ“ A β†’ Var23 (snoc23 Ξ“ B) A := Ξ» x Var23 vz23 vs23 => vs23 _ _ _ (x Var23 vz23 vs23) def Tm23 : Con23 β†’ Ty23 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm23 : Con23 β†’ Ty23 β†’ Type) (var : βˆ€ Ξ“ A , Var23 Ξ“ A β†’ Tm23 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm23 (snoc23 Ξ“ A) B β†’ Tm23 Ξ“ (arr23 A B)) (app : βˆ€ Ξ“ A B , Tm23 Ξ“ (arr23 A B) β†’ Tm23 Ξ“ A β†’ Tm23 Ξ“ B) , Tm23 Ξ“ A def var23 {Ξ“ A} : Var23 Ξ“ A β†’ Tm23 Ξ“ A := Ξ» x Tm23 var23 lam app => var23 _ _ x def lam23 {Ξ“ A B} : Tm23 (snoc23 Ξ“ A) B β†’ Tm23 Ξ“ (arr23 A B) := Ξ» t Tm23 var23 lam23 app => lam23 _ _ _ (t Tm23 var23 lam23 app) def app23 {Ξ“ A B} : Tm23 Ξ“ (arr23 A B) β†’ Tm23 Ξ“ A β†’ Tm23 Ξ“ B := Ξ» t u Tm23 var23 lam23 app23 => app23 _ _ _ (t Tm23 var23 lam23 app23) (u Tm23 var23 lam23 app23) def v023 {Ξ“ A} : Tm23 (snoc23 Ξ“ A) A := var23 vz23 def v123 {Ξ“ A B} : Tm23 (snoc23 (snoc23 Ξ“ A) B) A := var23 (vs23 vz23) def v223 {Ξ“ A B C} : Tm23 (snoc23 (snoc23 (snoc23 Ξ“ A) B) C) A := var23 (vs23 (vs23 vz23)) def v323 {Ξ“ A B C D} : Tm23 (snoc23 (snoc23 (snoc23 (snoc23 Ξ“ A) B) C) D) A := var23 (vs23 (vs23 (vs23 vz23))) def v423 {Ξ“ A B C D E} : Tm23 (snoc23 (snoc23 (snoc23 (snoc23 (snoc23 Ξ“ A) B) C) D) E) A := var23 (vs23 (vs23 (vs23 (vs23 vz23)))) def test23 {Ξ“ A} : Tm23 Ξ“ (arr23 (arr23 A A) (arr23 A A)) := lam23 (lam23 (app23 v123 (app23 v123 (app23 v123 (app23 v123 (app23 v123 (app23 v123 v023))))))) def Ty24 : Type 1 := βˆ€ (Ty24 : Type) (ΞΉ : Ty24) (arr : Ty24 β†’ Ty24 β†’ Ty24) , Ty24 def ΞΉ24 : Ty24 := Ξ» _ ΞΉ24 _ => ΞΉ24 def arr24 : Ty24 β†’ Ty24 β†’ Ty24 := Ξ» A B Ty24 ΞΉ24 arr24 => arr24 (A Ty24 ΞΉ24 arr24) (B Ty24 ΞΉ24 arr24) def Con24 : Type 1 := βˆ€ (Con24 : Type) (nil : Con24) (snoc : Con24 β†’ Ty24 β†’ Con24) , Con24 def nil24 : Con24 := Ξ» Con24 nil24 snoc => nil24 def snoc24 : Con24 β†’ Ty24 β†’ Con24 := Ξ» Ξ“ A Con24 nil24 snoc24 => snoc24 (Ξ“ Con24 nil24 snoc24) A def Var24 : Con24 β†’ Ty24 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var24 : Con24 β†’ Ty24 β†’ Type) (vz : βˆ€ Ξ“ A, Var24 (snoc24 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var24 Ξ“ A β†’ Var24 (snoc24 Ξ“ B) A) , Var24 Ξ“ A def vz24 {Ξ“ A} : Var24 (snoc24 Ξ“ A) A := Ξ» Var24 vz24 vs => vz24 _ _ def vs24 {Ξ“ B A} : Var24 Ξ“ A β†’ Var24 (snoc24 Ξ“ B) A := Ξ» x Var24 vz24 vs24 => vs24 _ _ _ (x Var24 vz24 vs24) def Tm24 : Con24 β†’ Ty24 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm24 : Con24 β†’ Ty24 β†’ Type) (var : βˆ€ Ξ“ A , Var24 Ξ“ A β†’ Tm24 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm24 (snoc24 Ξ“ A) B β†’ Tm24 Ξ“ (arr24 A B)) (app : βˆ€ Ξ“ A B , Tm24 Ξ“ (arr24 A B) β†’ Tm24 Ξ“ A β†’ Tm24 Ξ“ B) , Tm24 Ξ“ A def var24 {Ξ“ A} : Var24 Ξ“ A β†’ Tm24 Ξ“ A := Ξ» x Tm24 var24 lam app => var24 _ _ x def lam24 {Ξ“ A B} : Tm24 (snoc24 Ξ“ A) B β†’ Tm24 Ξ“ (arr24 A B) := Ξ» t Tm24 var24 lam24 app => lam24 _ _ _ (t Tm24 var24 lam24 app) def app24 {Ξ“ A B} : Tm24 Ξ“ (arr24 A B) β†’ Tm24 Ξ“ A β†’ Tm24 Ξ“ B := Ξ» t u Tm24 var24 lam24 app24 => app24 _ _ _ (t Tm24 var24 lam24 app24) (u Tm24 var24 lam24 app24) def v024 {Ξ“ A} : Tm24 (snoc24 Ξ“ A) A := var24 vz24 def v124 {Ξ“ A B} : Tm24 (snoc24 (snoc24 Ξ“ A) B) A := var24 (vs24 vz24) def v224 {Ξ“ A B C} : Tm24 (snoc24 (snoc24 (snoc24 Ξ“ A) B) C) A := var24 (vs24 (vs24 vz24)) def v324 {Ξ“ A B C D} : Tm24 (snoc24 (snoc24 (snoc24 (snoc24 Ξ“ A) B) C) D) A := var24 (vs24 (vs24 (vs24 vz24))) def v424 {Ξ“ A B C D E} : Tm24 (snoc24 (snoc24 (snoc24 (snoc24 (snoc24 Ξ“ A) B) C) D) E) A := var24 (vs24 (vs24 (vs24 (vs24 vz24)))) def test24 {Ξ“ A} : Tm24 Ξ“ (arr24 (arr24 A A) (arr24 A A)) := lam24 (lam24 (app24 v124 (app24 v124 (app24 v124 (app24 v124 (app24 v124 (app24 v124 v024))))))) def Ty25 : Type 1 := βˆ€ (Ty25 : Type) (ΞΉ : Ty25) (arr : Ty25 β†’ Ty25 β†’ Ty25) , Ty25 def ΞΉ25 : Ty25 := Ξ» _ ΞΉ25 _ => ΞΉ25 def arr25 : Ty25 β†’ Ty25 β†’ Ty25 := Ξ» A B Ty25 ΞΉ25 arr25 => arr25 (A Ty25 ΞΉ25 arr25) (B Ty25 ΞΉ25 arr25) def Con25 : Type 1 := βˆ€ (Con25 : Type) (nil : Con25) (snoc : Con25 β†’ Ty25 β†’ Con25) , Con25 def nil25 : Con25 := Ξ» Con25 nil25 snoc => nil25 def snoc25 : Con25 β†’ Ty25 β†’ Con25 := Ξ» Ξ“ A Con25 nil25 snoc25 => snoc25 (Ξ“ Con25 nil25 snoc25) A def Var25 : Con25 β†’ Ty25 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var25 : Con25 β†’ Ty25 β†’ Type) (vz : βˆ€ Ξ“ A, Var25 (snoc25 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var25 Ξ“ A β†’ Var25 (snoc25 Ξ“ B) A) , Var25 Ξ“ A def vz25 {Ξ“ A} : Var25 (snoc25 Ξ“ A) A := Ξ» Var25 vz25 vs => vz25 _ _ def vs25 {Ξ“ B A} : Var25 Ξ“ A β†’ Var25 (snoc25 Ξ“ B) A := Ξ» x Var25 vz25 vs25 => vs25 _ _ _ (x Var25 vz25 vs25) def Tm25 : Con25 β†’ Ty25 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm25 : Con25 β†’ Ty25 β†’ Type) (var : βˆ€ Ξ“ A , Var25 Ξ“ A β†’ Tm25 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm25 (snoc25 Ξ“ A) B β†’ Tm25 Ξ“ (arr25 A B)) (app : βˆ€ Ξ“ A B , Tm25 Ξ“ (arr25 A B) β†’ Tm25 Ξ“ A β†’ Tm25 Ξ“ B) , Tm25 Ξ“ A def var25 {Ξ“ A} : Var25 Ξ“ A β†’ Tm25 Ξ“ A := Ξ» x Tm25 var25 lam app => var25 _ _ x def lam25 {Ξ“ A B} : Tm25 (snoc25 Ξ“ A) B β†’ Tm25 Ξ“ (arr25 A B) := Ξ» t Tm25 var25 lam25 app => lam25 _ _ _ (t Tm25 var25 lam25 app) def app25 {Ξ“ A B} : Tm25 Ξ“ (arr25 A B) β†’ Tm25 Ξ“ A β†’ Tm25 Ξ“ B := Ξ» t u Tm25 var25 lam25 app25 => app25 _ _ _ (t Tm25 var25 lam25 app25) (u Tm25 var25 lam25 app25) def v025 {Ξ“ A} : Tm25 (snoc25 Ξ“ A) A := var25 vz25 def v125 {Ξ“ A B} : Tm25 (snoc25 (snoc25 Ξ“ A) B) A := var25 (vs25 vz25) def v225 {Ξ“ A B C} : Tm25 (snoc25 (snoc25 (snoc25 Ξ“ A) B) C) A := var25 (vs25 (vs25 vz25)) def v325 {Ξ“ A B C D} : Tm25 (snoc25 (snoc25 (snoc25 (snoc25 Ξ“ A) B) C) D) A := var25 (vs25 (vs25 (vs25 vz25))) def v425 {Ξ“ A B C D E} : Tm25 (snoc25 (snoc25 (snoc25 (snoc25 (snoc25 Ξ“ A) B) C) D) E) A := var25 (vs25 (vs25 (vs25 (vs25 vz25)))) def test25 {Ξ“ A} : Tm25 Ξ“ (arr25 (arr25 A A) (arr25 A A)) := lam25 (lam25 (app25 v125 (app25 v125 (app25 v125 (app25 v125 (app25 v125 (app25 v125 v025))))))) def Ty26 : Type 1 := βˆ€ (Ty26 : Type) (ΞΉ : Ty26) (arr : Ty26 β†’ Ty26 β†’ Ty26) , Ty26 def ΞΉ26 : Ty26 := Ξ» _ ΞΉ26 _ => ΞΉ26 def arr26 : Ty26 β†’ Ty26 β†’ Ty26 := Ξ» A B Ty26 ΞΉ26 arr26 => arr26 (A Ty26 ΞΉ26 arr26) (B Ty26 ΞΉ26 arr26) def Con26 : Type 1 := βˆ€ (Con26 : Type) (nil : Con26) (snoc : Con26 β†’ Ty26 β†’ Con26) , Con26 def nil26 : Con26 := Ξ» Con26 nil26 snoc => nil26 def snoc26 : Con26 β†’ Ty26 β†’ Con26 := Ξ» Ξ“ A Con26 nil26 snoc26 => snoc26 (Ξ“ Con26 nil26 snoc26) A def Var26 : Con26 β†’ Ty26 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var26 : Con26 β†’ Ty26 β†’ Type) (vz : βˆ€ Ξ“ A, Var26 (snoc26 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var26 Ξ“ A β†’ Var26 (snoc26 Ξ“ B) A) , Var26 Ξ“ A def vz26 {Ξ“ A} : Var26 (snoc26 Ξ“ A) A := Ξ» Var26 vz26 vs => vz26 _ _ def vs26 {Ξ“ B A} : Var26 Ξ“ A β†’ Var26 (snoc26 Ξ“ B) A := Ξ» x Var26 vz26 vs26 => vs26 _ _ _ (x Var26 vz26 vs26) def Tm26 : Con26 β†’ Ty26 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm26 : Con26 β†’ Ty26 β†’ Type) (var : βˆ€ Ξ“ A , Var26 Ξ“ A β†’ Tm26 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm26 (snoc26 Ξ“ A) B β†’ Tm26 Ξ“ (arr26 A B)) (app : βˆ€ Ξ“ A B , Tm26 Ξ“ (arr26 A B) β†’ Tm26 Ξ“ A β†’ Tm26 Ξ“ B) , Tm26 Ξ“ A def var26 {Ξ“ A} : Var26 Ξ“ A β†’ Tm26 Ξ“ A := Ξ» x Tm26 var26 lam app => var26 _ _ x def lam26 {Ξ“ A B} : Tm26 (snoc26 Ξ“ A) B β†’ Tm26 Ξ“ (arr26 A B) := Ξ» t Tm26 var26 lam26 app => lam26 _ _ _ (t Tm26 var26 lam26 app) def app26 {Ξ“ A B} : Tm26 Ξ“ (arr26 A B) β†’ Tm26 Ξ“ A β†’ Tm26 Ξ“ B := Ξ» t u Tm26 var26 lam26 app26 => app26 _ _ _ (t Tm26 var26 lam26 app26) (u Tm26 var26 lam26 app26) def v026 {Ξ“ A} : Tm26 (snoc26 Ξ“ A) A := var26 vz26 def v126 {Ξ“ A B} : Tm26 (snoc26 (snoc26 Ξ“ A) B) A := var26 (vs26 vz26) def v226 {Ξ“ A B C} : Tm26 (snoc26 (snoc26 (snoc26 Ξ“ A) B) C) A := var26 (vs26 (vs26 vz26)) def v326 {Ξ“ A B C D} : Tm26 (snoc26 (snoc26 (snoc26 (snoc26 Ξ“ A) B) C) D) A := var26 (vs26 (vs26 (vs26 vz26))) def v426 {Ξ“ A B C D E} : Tm26 (snoc26 (snoc26 (snoc26 (snoc26 (snoc26 Ξ“ A) B) C) D) E) A := var26 (vs26 (vs26 (vs26 (vs26 vz26)))) def test26 {Ξ“ A} : Tm26 Ξ“ (arr26 (arr26 A A) (arr26 A A)) := lam26 (lam26 (app26 v126 (app26 v126 (app26 v126 (app26 v126 (app26 v126 (app26 v126 v026))))))) def Ty27 : Type 1 := βˆ€ (Ty27 : Type) (ΞΉ : Ty27) (arr : Ty27 β†’ Ty27 β†’ Ty27) , Ty27 def ΞΉ27 : Ty27 := Ξ» _ ΞΉ27 _ => ΞΉ27 def arr27 : Ty27 β†’ Ty27 β†’ Ty27 := Ξ» A B Ty27 ΞΉ27 arr27 => arr27 (A Ty27 ΞΉ27 arr27) (B Ty27 ΞΉ27 arr27) def Con27 : Type 1 := βˆ€ (Con27 : Type) (nil : Con27) (snoc : Con27 β†’ Ty27 β†’ Con27) , Con27 def nil27 : Con27 := Ξ» Con27 nil27 snoc => nil27 def snoc27 : Con27 β†’ Ty27 β†’ Con27 := Ξ» Ξ“ A Con27 nil27 snoc27 => snoc27 (Ξ“ Con27 nil27 snoc27) A def Var27 : Con27 β†’ Ty27 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var27 : Con27 β†’ Ty27 β†’ Type) (vz : βˆ€ Ξ“ A, Var27 (snoc27 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var27 Ξ“ A β†’ Var27 (snoc27 Ξ“ B) A) , Var27 Ξ“ A def vz27 {Ξ“ A} : Var27 (snoc27 Ξ“ A) A := Ξ» Var27 vz27 vs => vz27 _ _ def vs27 {Ξ“ B A} : Var27 Ξ“ A β†’ Var27 (snoc27 Ξ“ B) A := Ξ» x Var27 vz27 vs27 => vs27 _ _ _ (x Var27 vz27 vs27) def Tm27 : Con27 β†’ Ty27 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm27 : Con27 β†’ Ty27 β†’ Type) (var : βˆ€ Ξ“ A , Var27 Ξ“ A β†’ Tm27 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm27 (snoc27 Ξ“ A) B β†’ Tm27 Ξ“ (arr27 A B)) (app : βˆ€ Ξ“ A B , Tm27 Ξ“ (arr27 A B) β†’ Tm27 Ξ“ A β†’ Tm27 Ξ“ B) , Tm27 Ξ“ A def var27 {Ξ“ A} : Var27 Ξ“ A β†’ Tm27 Ξ“ A := Ξ» x Tm27 var27 lam app => var27 _ _ x def lam27 {Ξ“ A B} : Tm27 (snoc27 Ξ“ A) B β†’ Tm27 Ξ“ (arr27 A B) := Ξ» t Tm27 var27 lam27 app => lam27 _ _ _ (t Tm27 var27 lam27 app) def app27 {Ξ“ A B} : Tm27 Ξ“ (arr27 A B) β†’ Tm27 Ξ“ A β†’ Tm27 Ξ“ B := Ξ» t u Tm27 var27 lam27 app27 => app27 _ _ _ (t Tm27 var27 lam27 app27) (u Tm27 var27 lam27 app27) def v027 {Ξ“ A} : Tm27 (snoc27 Ξ“ A) A := var27 vz27 def v127 {Ξ“ A B} : Tm27 (snoc27 (snoc27 Ξ“ A) B) A := var27 (vs27 vz27) def v227 {Ξ“ A B C} : Tm27 (snoc27 (snoc27 (snoc27 Ξ“ A) B) C) A := var27 (vs27 (vs27 vz27)) def v327 {Ξ“ A B C D} : Tm27 (snoc27 (snoc27 (snoc27 (snoc27 Ξ“ A) B) C) D) A := var27 (vs27 (vs27 (vs27 vz27))) def v427 {Ξ“ A B C D E} : Tm27 (snoc27 (snoc27 (snoc27 (snoc27 (snoc27 Ξ“ A) B) C) D) E) A := var27 (vs27 (vs27 (vs27 (vs27 vz27)))) def test27 {Ξ“ A} : Tm27 Ξ“ (arr27 (arr27 A A) (arr27 A A)) := lam27 (lam27 (app27 v127 (app27 v127 (app27 v127 (app27 v127 (app27 v127 (app27 v127 v027))))))) def Ty28 : Type 1 := βˆ€ (Ty28 : Type) (ΞΉ : Ty28) (arr : Ty28 β†’ Ty28 β†’ Ty28) , Ty28 def ΞΉ28 : Ty28 := Ξ» _ ΞΉ28 _ => ΞΉ28 def arr28 : Ty28 β†’ Ty28 β†’ Ty28 := Ξ» A B Ty28 ΞΉ28 arr28 => arr28 (A Ty28 ΞΉ28 arr28) (B Ty28 ΞΉ28 arr28) def Con28 : Type 1 := βˆ€ (Con28 : Type) (nil : Con28) (snoc : Con28 β†’ Ty28 β†’ Con28) , Con28 def nil28 : Con28 := Ξ» Con28 nil28 snoc => nil28 def snoc28 : Con28 β†’ Ty28 β†’ Con28 := Ξ» Ξ“ A Con28 nil28 snoc28 => snoc28 (Ξ“ Con28 nil28 snoc28) A def Var28 : Con28 β†’ Ty28 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var28 : Con28 β†’ Ty28 β†’ Type) (vz : βˆ€ Ξ“ A, Var28 (snoc28 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var28 Ξ“ A β†’ Var28 (snoc28 Ξ“ B) A) , Var28 Ξ“ A def vz28 {Ξ“ A} : Var28 (snoc28 Ξ“ A) A := Ξ» Var28 vz28 vs => vz28 _ _ def vs28 {Ξ“ B A} : Var28 Ξ“ A β†’ Var28 (snoc28 Ξ“ B) A := Ξ» x Var28 vz28 vs28 => vs28 _ _ _ (x Var28 vz28 vs28) def Tm28 : Con28 β†’ Ty28 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm28 : Con28 β†’ Ty28 β†’ Type) (var : βˆ€ Ξ“ A , Var28 Ξ“ A β†’ Tm28 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm28 (snoc28 Ξ“ A) B β†’ Tm28 Ξ“ (arr28 A B)) (app : βˆ€ Ξ“ A B , Tm28 Ξ“ (arr28 A B) β†’ Tm28 Ξ“ A β†’ Tm28 Ξ“ B) , Tm28 Ξ“ A def var28 {Ξ“ A} : Var28 Ξ“ A β†’ Tm28 Ξ“ A := Ξ» x Tm28 var28 lam app => var28 _ _ x def lam28 {Ξ“ A B} : Tm28 (snoc28 Ξ“ A) B β†’ Tm28 Ξ“ (arr28 A B) := Ξ» t Tm28 var28 lam28 app => lam28 _ _ _ (t Tm28 var28 lam28 app) def app28 {Ξ“ A B} : Tm28 Ξ“ (arr28 A B) β†’ Tm28 Ξ“ A β†’ Tm28 Ξ“ B := Ξ» t u Tm28 var28 lam28 app28 => app28 _ _ _ (t Tm28 var28 lam28 app28) (u Tm28 var28 lam28 app28) def v028 {Ξ“ A} : Tm28 (snoc28 Ξ“ A) A := var28 vz28 def v128 {Ξ“ A B} : Tm28 (snoc28 (snoc28 Ξ“ A) B) A := var28 (vs28 vz28) def v228 {Ξ“ A B C} : Tm28 (snoc28 (snoc28 (snoc28 Ξ“ A) B) C) A := var28 (vs28 (vs28 vz28)) def v328 {Ξ“ A B C D} : Tm28 (snoc28 (snoc28 (snoc28 (snoc28 Ξ“ A) B) C) D) A := var28 (vs28 (vs28 (vs28 vz28))) def v428 {Ξ“ A B C D E} : Tm28 (snoc28 (snoc28 (snoc28 (snoc28 (snoc28 Ξ“ A) B) C) D) E) A := var28 (vs28 (vs28 (vs28 (vs28 vz28)))) def test28 {Ξ“ A} : Tm28 Ξ“ (arr28 (arr28 A A) (arr28 A A)) := lam28 (lam28 (app28 v128 (app28 v128 (app28 v128 (app28 v128 (app28 v128 (app28 v128 v028))))))) def Ty29 : Type 1 := βˆ€ (Ty29 : Type) (ΞΉ : Ty29) (arr : Ty29 β†’ Ty29 β†’ Ty29) , Ty29 def ΞΉ29 : Ty29 := Ξ» _ ΞΉ29 _ => ΞΉ29 def arr29 : Ty29 β†’ Ty29 β†’ Ty29 := Ξ» A B Ty29 ΞΉ29 arr29 => arr29 (A Ty29 ΞΉ29 arr29) (B Ty29 ΞΉ29 arr29) def Con29 : Type 1 := βˆ€ (Con29 : Type) (nil : Con29) (snoc : Con29 β†’ Ty29 β†’ Con29) , Con29 def nil29 : Con29 := Ξ» Con29 nil29 snoc => nil29 def snoc29 : Con29 β†’ Ty29 β†’ Con29 := Ξ» Ξ“ A Con29 nil29 snoc29 => snoc29 (Ξ“ Con29 nil29 snoc29) A def Var29 : Con29 β†’ Ty29 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var29 : Con29 β†’ Ty29 β†’ Type) (vz : βˆ€ Ξ“ A, Var29 (snoc29 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var29 Ξ“ A β†’ Var29 (snoc29 Ξ“ B) A) , Var29 Ξ“ A def vz29 {Ξ“ A} : Var29 (snoc29 Ξ“ A) A := Ξ» Var29 vz29 vs => vz29 _ _ def vs29 {Ξ“ B A} : Var29 Ξ“ A β†’ Var29 (snoc29 Ξ“ B) A := Ξ» x Var29 vz29 vs29 => vs29 _ _ _ (x Var29 vz29 vs29) def Tm29 : Con29 β†’ Ty29 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm29 : Con29 β†’ Ty29 β†’ Type) (var : βˆ€ Ξ“ A , Var29 Ξ“ A β†’ Tm29 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm29 (snoc29 Ξ“ A) B β†’ Tm29 Ξ“ (arr29 A B)) (app : βˆ€ Ξ“ A B , Tm29 Ξ“ (arr29 A B) β†’ Tm29 Ξ“ A β†’ Tm29 Ξ“ B) , Tm29 Ξ“ A def var29 {Ξ“ A} : Var29 Ξ“ A β†’ Tm29 Ξ“ A := Ξ» x Tm29 var29 lam app => var29 _ _ x def lam29 {Ξ“ A B} : Tm29 (snoc29 Ξ“ A) B β†’ Tm29 Ξ“ (arr29 A B) := Ξ» t Tm29 var29 lam29 app => lam29 _ _ _ (t Tm29 var29 lam29 app) def app29 {Ξ“ A B} : Tm29 Ξ“ (arr29 A B) β†’ Tm29 Ξ“ A β†’ Tm29 Ξ“ B := Ξ» t u Tm29 var29 lam29 app29 => app29 _ _ _ (t Tm29 var29 lam29 app29) (u Tm29 var29 lam29 app29) def v029 {Ξ“ A} : Tm29 (snoc29 Ξ“ A) A := var29 vz29 def v129 {Ξ“ A B} : Tm29 (snoc29 (snoc29 Ξ“ A) B) A := var29 (vs29 vz29) def v229 {Ξ“ A B C} : Tm29 (snoc29 (snoc29 (snoc29 Ξ“ A) B) C) A := var29 (vs29 (vs29 vz29)) def v329 {Ξ“ A B C D} : Tm29 (snoc29 (snoc29 (snoc29 (snoc29 Ξ“ A) B) C) D) A := var29 (vs29 (vs29 (vs29 vz29))) def v429 {Ξ“ A B C D E} : Tm29 (snoc29 (snoc29 (snoc29 (snoc29 (snoc29 Ξ“ A) B) C) D) E) A := var29 (vs29 (vs29 (vs29 (vs29 vz29)))) def test29 {Ξ“ A} : Tm29 Ξ“ (arr29 (arr29 A A) (arr29 A A)) := lam29 (lam29 (app29 v129 (app29 v129 (app29 v129 (app29 v129 (app29 v129 (app29 v129 v029))))))) def Ty30 : Type 1 := βˆ€ (Ty30 : Type) (ΞΉ : Ty30) (arr : Ty30 β†’ Ty30 β†’ Ty30) , Ty30 def ΞΉ30 : Ty30 := Ξ» _ ΞΉ30 _ => ΞΉ30 def arr30 : Ty30 β†’ Ty30 β†’ Ty30 := Ξ» A B Ty30 ΞΉ30 arr30 => arr30 (A Ty30 ΞΉ30 arr30) (B Ty30 ΞΉ30 arr30) def Con30 : Type 1 := βˆ€ (Con30 : Type) (nil : Con30) (snoc : Con30 β†’ Ty30 β†’ Con30) , Con30 def nil30 : Con30 := Ξ» Con30 nil30 snoc => nil30 def snoc30 : Con30 β†’ Ty30 β†’ Con30 := Ξ» Ξ“ A Con30 nil30 snoc30 => snoc30 (Ξ“ Con30 nil30 snoc30) A def Var30 : Con30 β†’ Ty30 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var30 : Con30 β†’ Ty30 β†’ Type) (vz : βˆ€ Ξ“ A, Var30 (snoc30 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var30 Ξ“ A β†’ Var30 (snoc30 Ξ“ B) A) , Var30 Ξ“ A def vz30 {Ξ“ A} : Var30 (snoc30 Ξ“ A) A := Ξ» Var30 vz30 vs => vz30 _ _ def vs30 {Ξ“ B A} : Var30 Ξ“ A β†’ Var30 (snoc30 Ξ“ B) A := Ξ» x Var30 vz30 vs30 => vs30 _ _ _ (x Var30 vz30 vs30) def Tm30 : Con30 β†’ Ty30 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm30 : Con30 β†’ Ty30 β†’ Type) (var : βˆ€ Ξ“ A , Var30 Ξ“ A β†’ Tm30 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm30 (snoc30 Ξ“ A) B β†’ Tm30 Ξ“ (arr30 A B)) (app : βˆ€ Ξ“ A B , Tm30 Ξ“ (arr30 A B) β†’ Tm30 Ξ“ A β†’ Tm30 Ξ“ B) , Tm30 Ξ“ A def var30 {Ξ“ A} : Var30 Ξ“ A β†’ Tm30 Ξ“ A := Ξ» x Tm30 var30 lam app => var30 _ _ x def lam30 {Ξ“ A B} : Tm30 (snoc30 Ξ“ A) B β†’ Tm30 Ξ“ (arr30 A B) := Ξ» t Tm30 var30 lam30 app => lam30 _ _ _ (t Tm30 var30 lam30 app) def app30 {Ξ“ A B} : Tm30 Ξ“ (arr30 A B) β†’ Tm30 Ξ“ A β†’ Tm30 Ξ“ B := Ξ» t u Tm30 var30 lam30 app30 => app30 _ _ _ (t Tm30 var30 lam30 app30) (u Tm30 var30 lam30 app30) def v030 {Ξ“ A} : Tm30 (snoc30 Ξ“ A) A := var30 vz30 def v130 {Ξ“ A B} : Tm30 (snoc30 (snoc30 Ξ“ A) B) A := var30 (vs30 vz30) def v230 {Ξ“ A B C} : Tm30 (snoc30 (snoc30 (snoc30 Ξ“ A) B) C) A := var30 (vs30 (vs30 vz30)) def v330 {Ξ“ A B C D} : Tm30 (snoc30 (snoc30 (snoc30 (snoc30 Ξ“ A) B) C) D) A := var30 (vs30 (vs30 (vs30 vz30))) def v430 {Ξ“ A B C D E} : Tm30 (snoc30 (snoc30 (snoc30 (snoc30 (snoc30 Ξ“ A) B) C) D) E) A := var30 (vs30 (vs30 (vs30 (vs30 vz30)))) def test30 {Ξ“ A} : Tm30 Ξ“ (arr30 (arr30 A A) (arr30 A A)) := lam30 (lam30 (app30 v130 (app30 v130 (app30 v130 (app30 v130 (app30 v130 (app30 v130 v030))))))) def Ty31 : Type 1 := βˆ€ (Ty31 : Type) (ΞΉ : Ty31) (arr : Ty31 β†’ Ty31 β†’ Ty31) , Ty31 def ΞΉ31 : Ty31 := Ξ» _ ΞΉ31 _ => ΞΉ31 def arr31 : Ty31 β†’ Ty31 β†’ Ty31 := Ξ» A B Ty31 ΞΉ31 arr31 => arr31 (A Ty31 ΞΉ31 arr31) (B Ty31 ΞΉ31 arr31) def Con31 : Type 1 := βˆ€ (Con31 : Type) (nil : Con31) (snoc : Con31 β†’ Ty31 β†’ Con31) , Con31 def nil31 : Con31 := Ξ» Con31 nil31 snoc => nil31 def snoc31 : Con31 β†’ Ty31 β†’ Con31 := Ξ» Ξ“ A Con31 nil31 snoc31 => snoc31 (Ξ“ Con31 nil31 snoc31) A def Var31 : Con31 β†’ Ty31 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var31 : Con31 β†’ Ty31 β†’ Type) (vz : βˆ€ Ξ“ A, Var31 (snoc31 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var31 Ξ“ A β†’ Var31 (snoc31 Ξ“ B) A) , Var31 Ξ“ A def vz31 {Ξ“ A} : Var31 (snoc31 Ξ“ A) A := Ξ» Var31 vz31 vs => vz31 _ _ def vs31 {Ξ“ B A} : Var31 Ξ“ A β†’ Var31 (snoc31 Ξ“ B) A := Ξ» x Var31 vz31 vs31 => vs31 _ _ _ (x Var31 vz31 vs31) def Tm31 : Con31 β†’ Ty31 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm31 : Con31 β†’ Ty31 β†’ Type) (var : βˆ€ Ξ“ A , Var31 Ξ“ A β†’ Tm31 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm31 (snoc31 Ξ“ A) B β†’ Tm31 Ξ“ (arr31 A B)) (app : βˆ€ Ξ“ A B , Tm31 Ξ“ (arr31 A B) β†’ Tm31 Ξ“ A β†’ Tm31 Ξ“ B) , Tm31 Ξ“ A def var31 {Ξ“ A} : Var31 Ξ“ A β†’ Tm31 Ξ“ A := Ξ» x Tm31 var31 lam app => var31 _ _ x def lam31 {Ξ“ A B} : Tm31 (snoc31 Ξ“ A) B β†’ Tm31 Ξ“ (arr31 A B) := Ξ» t Tm31 var31 lam31 app => lam31 _ _ _ (t Tm31 var31 lam31 app) def app31 {Ξ“ A B} : Tm31 Ξ“ (arr31 A B) β†’ Tm31 Ξ“ A β†’ Tm31 Ξ“ B := Ξ» t u Tm31 var31 lam31 app31 => app31 _ _ _ (t Tm31 var31 lam31 app31) (u Tm31 var31 lam31 app31) def v031 {Ξ“ A} : Tm31 (snoc31 Ξ“ A) A := var31 vz31 def v131 {Ξ“ A B} : Tm31 (snoc31 (snoc31 Ξ“ A) B) A := var31 (vs31 vz31) def v231 {Ξ“ A B C} : Tm31 (snoc31 (snoc31 (snoc31 Ξ“ A) B) C) A := var31 (vs31 (vs31 vz31)) def v331 {Ξ“ A B C D} : Tm31 (snoc31 (snoc31 (snoc31 (snoc31 Ξ“ A) B) C) D) A := var31 (vs31 (vs31 (vs31 vz31))) def v431 {Ξ“ A B C D E} : Tm31 (snoc31 (snoc31 (snoc31 (snoc31 (snoc31 Ξ“ A) B) C) D) E) A := var31 (vs31 (vs31 (vs31 (vs31 vz31)))) def test31 {Ξ“ A} : Tm31 Ξ“ (arr31 (arr31 A A) (arr31 A A)) := lam31 (lam31 (app31 v131 (app31 v131 (app31 v131 (app31 v131 (app31 v131 (app31 v131 v031))))))) def Ty32 : Type 1 := βˆ€ (Ty32 : Type) (ΞΉ : Ty32) (arr : Ty32 β†’ Ty32 β†’ Ty32) , Ty32 def ΞΉ32 : Ty32 := Ξ» _ ΞΉ32 _ => ΞΉ32 def arr32 : Ty32 β†’ Ty32 β†’ Ty32 := Ξ» A B Ty32 ΞΉ32 arr32 => arr32 (A Ty32 ΞΉ32 arr32) (B Ty32 ΞΉ32 arr32) def Con32 : Type 1 := βˆ€ (Con32 : Type) (nil : Con32) (snoc : Con32 β†’ Ty32 β†’ Con32) , Con32 def nil32 : Con32 := Ξ» Con32 nil32 snoc => nil32 def snoc32 : Con32 β†’ Ty32 β†’ Con32 := Ξ» Ξ“ A Con32 nil32 snoc32 => snoc32 (Ξ“ Con32 nil32 snoc32) A def Var32 : Con32 β†’ Ty32 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var32 : Con32 β†’ Ty32 β†’ Type) (vz : βˆ€ Ξ“ A, Var32 (snoc32 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var32 Ξ“ A β†’ Var32 (snoc32 Ξ“ B) A) , Var32 Ξ“ A def vz32 {Ξ“ A} : Var32 (snoc32 Ξ“ A) A := Ξ» Var32 vz32 vs => vz32 _ _ def vs32 {Ξ“ B A} : Var32 Ξ“ A β†’ Var32 (snoc32 Ξ“ B) A := Ξ» x Var32 vz32 vs32 => vs32 _ _ _ (x Var32 vz32 vs32) def Tm32 : Con32 β†’ Ty32 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm32 : Con32 β†’ Ty32 β†’ Type) (var : βˆ€ Ξ“ A , Var32 Ξ“ A β†’ Tm32 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm32 (snoc32 Ξ“ A) B β†’ Tm32 Ξ“ (arr32 A B)) (app : βˆ€ Ξ“ A B , Tm32 Ξ“ (arr32 A B) β†’ Tm32 Ξ“ A β†’ Tm32 Ξ“ B) , Tm32 Ξ“ A def var32 {Ξ“ A} : Var32 Ξ“ A β†’ Tm32 Ξ“ A := Ξ» x Tm32 var32 lam app => var32 _ _ x def lam32 {Ξ“ A B} : Tm32 (snoc32 Ξ“ A) B β†’ Tm32 Ξ“ (arr32 A B) := Ξ» t Tm32 var32 lam32 app => lam32 _ _ _ (t Tm32 var32 lam32 app) def app32 {Ξ“ A B} : Tm32 Ξ“ (arr32 A B) β†’ Tm32 Ξ“ A β†’ Tm32 Ξ“ B := Ξ» t u Tm32 var32 lam32 app32 => app32 _ _ _ (t Tm32 var32 lam32 app32) (u Tm32 var32 lam32 app32) def v032 {Ξ“ A} : Tm32 (snoc32 Ξ“ A) A := var32 vz32 def v132 {Ξ“ A B} : Tm32 (snoc32 (snoc32 Ξ“ A) B) A := var32 (vs32 vz32) def v232 {Ξ“ A B C} : Tm32 (snoc32 (snoc32 (snoc32 Ξ“ A) B) C) A := var32 (vs32 (vs32 vz32)) def v332 {Ξ“ A B C D} : Tm32 (snoc32 (snoc32 (snoc32 (snoc32 Ξ“ A) B) C) D) A := var32 (vs32 (vs32 (vs32 vz32))) def v432 {Ξ“ A B C D E} : Tm32 (snoc32 (snoc32 (snoc32 (snoc32 (snoc32 Ξ“ A) B) C) D) E) A := var32 (vs32 (vs32 (vs32 (vs32 vz32)))) def test32 {Ξ“ A} : Tm32 Ξ“ (arr32 (arr32 A A) (arr32 A A)) := lam32 (lam32 (app32 v132 (app32 v132 (app32 v132 (app32 v132 (app32 v132 (app32 v132 v032))))))) def Ty33 : Type 1 := βˆ€ (Ty33 : Type) (ΞΉ : Ty33) (arr : Ty33 β†’ Ty33 β†’ Ty33) , Ty33 def ΞΉ33 : Ty33 := Ξ» _ ΞΉ33 _ => ΞΉ33 def arr33 : Ty33 β†’ Ty33 β†’ Ty33 := Ξ» A B Ty33 ΞΉ33 arr33 => arr33 (A Ty33 ΞΉ33 arr33) (B Ty33 ΞΉ33 arr33) def Con33 : Type 1 := βˆ€ (Con33 : Type) (nil : Con33) (snoc : Con33 β†’ Ty33 β†’ Con33) , Con33 def nil33 : Con33 := Ξ» Con33 nil33 snoc => nil33 def snoc33 : Con33 β†’ Ty33 β†’ Con33 := Ξ» Ξ“ A Con33 nil33 snoc33 => snoc33 (Ξ“ Con33 nil33 snoc33) A def Var33 : Con33 β†’ Ty33 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var33 : Con33 β†’ Ty33 β†’ Type) (vz : βˆ€ Ξ“ A, Var33 (snoc33 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var33 Ξ“ A β†’ Var33 (snoc33 Ξ“ B) A) , Var33 Ξ“ A def vz33 {Ξ“ A} : Var33 (snoc33 Ξ“ A) A := Ξ» Var33 vz33 vs => vz33 _ _ def vs33 {Ξ“ B A} : Var33 Ξ“ A β†’ Var33 (snoc33 Ξ“ B) A := Ξ» x Var33 vz33 vs33 => vs33 _ _ _ (x Var33 vz33 vs33) def Tm33 : Con33 β†’ Ty33 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm33 : Con33 β†’ Ty33 β†’ Type) (var : βˆ€ Ξ“ A , Var33 Ξ“ A β†’ Tm33 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm33 (snoc33 Ξ“ A) B β†’ Tm33 Ξ“ (arr33 A B)) (app : βˆ€ Ξ“ A B , Tm33 Ξ“ (arr33 A B) β†’ Tm33 Ξ“ A β†’ Tm33 Ξ“ B) , Tm33 Ξ“ A def var33 {Ξ“ A} : Var33 Ξ“ A β†’ Tm33 Ξ“ A := Ξ» x Tm33 var33 lam app => var33 _ _ x def lam33 {Ξ“ A B} : Tm33 (snoc33 Ξ“ A) B β†’ Tm33 Ξ“ (arr33 A B) := Ξ» t Tm33 var33 lam33 app => lam33 _ _ _ (t Tm33 var33 lam33 app) def app33 {Ξ“ A B} : Tm33 Ξ“ (arr33 A B) β†’ Tm33 Ξ“ A β†’ Tm33 Ξ“ B := Ξ» t u Tm33 var33 lam33 app33 => app33 _ _ _ (t Tm33 var33 lam33 app33) (u Tm33 var33 lam33 app33) def v033 {Ξ“ A} : Tm33 (snoc33 Ξ“ A) A := var33 vz33 def v133 {Ξ“ A B} : Tm33 (snoc33 (snoc33 Ξ“ A) B) A := var33 (vs33 vz33) def v233 {Ξ“ A B C} : Tm33 (snoc33 (snoc33 (snoc33 Ξ“ A) B) C) A := var33 (vs33 (vs33 vz33)) def v333 {Ξ“ A B C D} : Tm33 (snoc33 (snoc33 (snoc33 (snoc33 Ξ“ A) B) C) D) A := var33 (vs33 (vs33 (vs33 vz33))) def v433 {Ξ“ A B C D E} : Tm33 (snoc33 (snoc33 (snoc33 (snoc33 (snoc33 Ξ“ A) B) C) D) E) A := var33 (vs33 (vs33 (vs33 (vs33 vz33)))) def test33 {Ξ“ A} : Tm33 Ξ“ (arr33 (arr33 A A) (arr33 A A)) := lam33 (lam33 (app33 v133 (app33 v133 (app33 v133 (app33 v133 (app33 v133 (app33 v133 v033))))))) def Ty34 : Type 1 := βˆ€ (Ty34 : Type) (ΞΉ : Ty34) (arr : Ty34 β†’ Ty34 β†’ Ty34) , Ty34 def ΞΉ34 : Ty34 := Ξ» _ ΞΉ34 _ => ΞΉ34 def arr34 : Ty34 β†’ Ty34 β†’ Ty34 := Ξ» A B Ty34 ΞΉ34 arr34 => arr34 (A Ty34 ΞΉ34 arr34) (B Ty34 ΞΉ34 arr34) def Con34 : Type 1 := βˆ€ (Con34 : Type) (nil : Con34) (snoc : Con34 β†’ Ty34 β†’ Con34) , Con34 def nil34 : Con34 := Ξ» Con34 nil34 snoc => nil34 def snoc34 : Con34 β†’ Ty34 β†’ Con34 := Ξ» Ξ“ A Con34 nil34 snoc34 => snoc34 (Ξ“ Con34 nil34 snoc34) A def Var34 : Con34 β†’ Ty34 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var34 : Con34 β†’ Ty34 β†’ Type) (vz : βˆ€ Ξ“ A, Var34 (snoc34 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var34 Ξ“ A β†’ Var34 (snoc34 Ξ“ B) A) , Var34 Ξ“ A def vz34 {Ξ“ A} : Var34 (snoc34 Ξ“ A) A := Ξ» Var34 vz34 vs => vz34 _ _ def vs34 {Ξ“ B A} : Var34 Ξ“ A β†’ Var34 (snoc34 Ξ“ B) A := Ξ» x Var34 vz34 vs34 => vs34 _ _ _ (x Var34 vz34 vs34) def Tm34 : Con34 β†’ Ty34 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm34 : Con34 β†’ Ty34 β†’ Type) (var : βˆ€ Ξ“ A , Var34 Ξ“ A β†’ Tm34 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm34 (snoc34 Ξ“ A) B β†’ Tm34 Ξ“ (arr34 A B)) (app : βˆ€ Ξ“ A B , Tm34 Ξ“ (arr34 A B) β†’ Tm34 Ξ“ A β†’ Tm34 Ξ“ B) , Tm34 Ξ“ A def var34 {Ξ“ A} : Var34 Ξ“ A β†’ Tm34 Ξ“ A := Ξ» x Tm34 var34 lam app => var34 _ _ x def lam34 {Ξ“ A B} : Tm34 (snoc34 Ξ“ A) B β†’ Tm34 Ξ“ (arr34 A B) := Ξ» t Tm34 var34 lam34 app => lam34 _ _ _ (t Tm34 var34 lam34 app) def app34 {Ξ“ A B} : Tm34 Ξ“ (arr34 A B) β†’ Tm34 Ξ“ A β†’ Tm34 Ξ“ B := Ξ» t u Tm34 var34 lam34 app34 => app34 _ _ _ (t Tm34 var34 lam34 app34) (u Tm34 var34 lam34 app34) def v034 {Ξ“ A} : Tm34 (snoc34 Ξ“ A) A := var34 vz34 def v134 {Ξ“ A B} : Tm34 (snoc34 (snoc34 Ξ“ A) B) A := var34 (vs34 vz34) def v234 {Ξ“ A B C} : Tm34 (snoc34 (snoc34 (snoc34 Ξ“ A) B) C) A := var34 (vs34 (vs34 vz34)) def v334 {Ξ“ A B C D} : Tm34 (snoc34 (snoc34 (snoc34 (snoc34 Ξ“ A) B) C) D) A := var34 (vs34 (vs34 (vs34 vz34))) def v434 {Ξ“ A B C D E} : Tm34 (snoc34 (snoc34 (snoc34 (snoc34 (snoc34 Ξ“ A) B) C) D) E) A := var34 (vs34 (vs34 (vs34 (vs34 vz34)))) def test34 {Ξ“ A} : Tm34 Ξ“ (arr34 (arr34 A A) (arr34 A A)) := lam34 (lam34 (app34 v134 (app34 v134 (app34 v134 (app34 v134 (app34 v134 (app34 v134 v034))))))) def Ty35 : Type 1 := βˆ€ (Ty35 : Type) (ΞΉ : Ty35) (arr : Ty35 β†’ Ty35 β†’ Ty35) , Ty35 def ΞΉ35 : Ty35 := Ξ» _ ΞΉ35 _ => ΞΉ35 def arr35 : Ty35 β†’ Ty35 β†’ Ty35 := Ξ» A B Ty35 ΞΉ35 arr35 => arr35 (A Ty35 ΞΉ35 arr35) (B Ty35 ΞΉ35 arr35) def Con35 : Type 1 := βˆ€ (Con35 : Type) (nil : Con35) (snoc : Con35 β†’ Ty35 β†’ Con35) , Con35 def nil35 : Con35 := Ξ» Con35 nil35 snoc => nil35 def snoc35 : Con35 β†’ Ty35 β†’ Con35 := Ξ» Ξ“ A Con35 nil35 snoc35 => snoc35 (Ξ“ Con35 nil35 snoc35) A def Var35 : Con35 β†’ Ty35 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var35 : Con35 β†’ Ty35 β†’ Type) (vz : βˆ€ Ξ“ A, Var35 (snoc35 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var35 Ξ“ A β†’ Var35 (snoc35 Ξ“ B) A) , Var35 Ξ“ A def vz35 {Ξ“ A} : Var35 (snoc35 Ξ“ A) A := Ξ» Var35 vz35 vs => vz35 _ _ def vs35 {Ξ“ B A} : Var35 Ξ“ A β†’ Var35 (snoc35 Ξ“ B) A := Ξ» x Var35 vz35 vs35 => vs35 _ _ _ (x Var35 vz35 vs35) def Tm35 : Con35 β†’ Ty35 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm35 : Con35 β†’ Ty35 β†’ Type) (var : βˆ€ Ξ“ A , Var35 Ξ“ A β†’ Tm35 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm35 (snoc35 Ξ“ A) B β†’ Tm35 Ξ“ (arr35 A B)) (app : βˆ€ Ξ“ A B , Tm35 Ξ“ (arr35 A B) β†’ Tm35 Ξ“ A β†’ Tm35 Ξ“ B) , Tm35 Ξ“ A def var35 {Ξ“ A} : Var35 Ξ“ A β†’ Tm35 Ξ“ A := Ξ» x Tm35 var35 lam app => var35 _ _ x def lam35 {Ξ“ A B} : Tm35 (snoc35 Ξ“ A) B β†’ Tm35 Ξ“ (arr35 A B) := Ξ» t Tm35 var35 lam35 app => lam35 _ _ _ (t Tm35 var35 lam35 app) def app35 {Ξ“ A B} : Tm35 Ξ“ (arr35 A B) β†’ Tm35 Ξ“ A β†’ Tm35 Ξ“ B := Ξ» t u Tm35 var35 lam35 app35 => app35 _ _ _ (t Tm35 var35 lam35 app35) (u Tm35 var35 lam35 app35) def v035 {Ξ“ A} : Tm35 (snoc35 Ξ“ A) A := var35 vz35 def v135 {Ξ“ A B} : Tm35 (snoc35 (snoc35 Ξ“ A) B) A := var35 (vs35 vz35) def v235 {Ξ“ A B C} : Tm35 (snoc35 (snoc35 (snoc35 Ξ“ A) B) C) A := var35 (vs35 (vs35 vz35)) def v335 {Ξ“ A B C D} : Tm35 (snoc35 (snoc35 (snoc35 (snoc35 Ξ“ A) B) C) D) A := var35 (vs35 (vs35 (vs35 vz35))) def v435 {Ξ“ A B C D E} : Tm35 (snoc35 (snoc35 (snoc35 (snoc35 (snoc35 Ξ“ A) B) C) D) E) A := var35 (vs35 (vs35 (vs35 (vs35 vz35)))) def test35 {Ξ“ A} : Tm35 Ξ“ (arr35 (arr35 A A) (arr35 A A)) := lam35 (lam35 (app35 v135 (app35 v135 (app35 v135 (app35 v135 (app35 v135 (app35 v135 v035))))))) def Ty36 : Type 1 := βˆ€ (Ty36 : Type) (ΞΉ : Ty36) (arr : Ty36 β†’ Ty36 β†’ Ty36) , Ty36 def ΞΉ36 : Ty36 := Ξ» _ ΞΉ36 _ => ΞΉ36 def arr36 : Ty36 β†’ Ty36 β†’ Ty36 := Ξ» A B Ty36 ΞΉ36 arr36 => arr36 (A Ty36 ΞΉ36 arr36) (B Ty36 ΞΉ36 arr36) def Con36 : Type 1 := βˆ€ (Con36 : Type) (nil : Con36) (snoc : Con36 β†’ Ty36 β†’ Con36) , Con36 def nil36 : Con36 := Ξ» Con36 nil36 snoc => nil36 def snoc36 : Con36 β†’ Ty36 β†’ Con36 := Ξ» Ξ“ A Con36 nil36 snoc36 => snoc36 (Ξ“ Con36 nil36 snoc36) A def Var36 : Con36 β†’ Ty36 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var36 : Con36 β†’ Ty36 β†’ Type) (vz : βˆ€ Ξ“ A, Var36 (snoc36 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var36 Ξ“ A β†’ Var36 (snoc36 Ξ“ B) A) , Var36 Ξ“ A def vz36 {Ξ“ A} : Var36 (snoc36 Ξ“ A) A := Ξ» Var36 vz36 vs => vz36 _ _ def vs36 {Ξ“ B A} : Var36 Ξ“ A β†’ Var36 (snoc36 Ξ“ B) A := Ξ» x Var36 vz36 vs36 => vs36 _ _ _ (x Var36 vz36 vs36) def Tm36 : Con36 β†’ Ty36 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm36 : Con36 β†’ Ty36 β†’ Type) (var : βˆ€ Ξ“ A , Var36 Ξ“ A β†’ Tm36 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm36 (snoc36 Ξ“ A) B β†’ Tm36 Ξ“ (arr36 A B)) (app : βˆ€ Ξ“ A B , Tm36 Ξ“ (arr36 A B) β†’ Tm36 Ξ“ A β†’ Tm36 Ξ“ B) , Tm36 Ξ“ A def var36 {Ξ“ A} : Var36 Ξ“ A β†’ Tm36 Ξ“ A := Ξ» x Tm36 var36 lam app => var36 _ _ x def lam36 {Ξ“ A B} : Tm36 (snoc36 Ξ“ A) B β†’ Tm36 Ξ“ (arr36 A B) := Ξ» t Tm36 var36 lam36 app => lam36 _ _ _ (t Tm36 var36 lam36 app) def app36 {Ξ“ A B} : Tm36 Ξ“ (arr36 A B) β†’ Tm36 Ξ“ A β†’ Tm36 Ξ“ B := Ξ» t u Tm36 var36 lam36 app36 => app36 _ _ _ (t Tm36 var36 lam36 app36) (u Tm36 var36 lam36 app36) def v036 {Ξ“ A} : Tm36 (snoc36 Ξ“ A) A := var36 vz36 def v136 {Ξ“ A B} : Tm36 (snoc36 (snoc36 Ξ“ A) B) A := var36 (vs36 vz36) def v236 {Ξ“ A B C} : Tm36 (snoc36 (snoc36 (snoc36 Ξ“ A) B) C) A := var36 (vs36 (vs36 vz36)) def v336 {Ξ“ A B C D} : Tm36 (snoc36 (snoc36 (snoc36 (snoc36 Ξ“ A) B) C) D) A := var36 (vs36 (vs36 (vs36 vz36))) def v436 {Ξ“ A B C D E} : Tm36 (snoc36 (snoc36 (snoc36 (snoc36 (snoc36 Ξ“ A) B) C) D) E) A := var36 (vs36 (vs36 (vs36 (vs36 vz36)))) def test36 {Ξ“ A} : Tm36 Ξ“ (arr36 (arr36 A A) (arr36 A A)) := lam36 (lam36 (app36 v136 (app36 v136 (app36 v136 (app36 v136 (app36 v136 (app36 v136 v036))))))) def Ty37 : Type 1 := βˆ€ (Ty37 : Type) (ΞΉ : Ty37) (arr : Ty37 β†’ Ty37 β†’ Ty37) , Ty37 def ΞΉ37 : Ty37 := Ξ» _ ΞΉ37 _ => ΞΉ37 def arr37 : Ty37 β†’ Ty37 β†’ Ty37 := Ξ» A B Ty37 ΞΉ37 arr37 => arr37 (A Ty37 ΞΉ37 arr37) (B Ty37 ΞΉ37 arr37) def Con37 : Type 1 := βˆ€ (Con37 : Type) (nil : Con37) (snoc : Con37 β†’ Ty37 β†’ Con37) , Con37 def nil37 : Con37 := Ξ» Con37 nil37 snoc => nil37 def snoc37 : Con37 β†’ Ty37 β†’ Con37 := Ξ» Ξ“ A Con37 nil37 snoc37 => snoc37 (Ξ“ Con37 nil37 snoc37) A def Var37 : Con37 β†’ Ty37 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var37 : Con37 β†’ Ty37 β†’ Type) (vz : βˆ€ Ξ“ A, Var37 (snoc37 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var37 Ξ“ A β†’ Var37 (snoc37 Ξ“ B) A) , Var37 Ξ“ A def vz37 {Ξ“ A} : Var37 (snoc37 Ξ“ A) A := Ξ» Var37 vz37 vs => vz37 _ _ def vs37 {Ξ“ B A} : Var37 Ξ“ A β†’ Var37 (snoc37 Ξ“ B) A := Ξ» x Var37 vz37 vs37 => vs37 _ _ _ (x Var37 vz37 vs37) def Tm37 : Con37 β†’ Ty37 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm37 : Con37 β†’ Ty37 β†’ Type) (var : βˆ€ Ξ“ A , Var37 Ξ“ A β†’ Tm37 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm37 (snoc37 Ξ“ A) B β†’ Tm37 Ξ“ (arr37 A B)) (app : βˆ€ Ξ“ A B , Tm37 Ξ“ (arr37 A B) β†’ Tm37 Ξ“ A β†’ Tm37 Ξ“ B) , Tm37 Ξ“ A def var37 {Ξ“ A} : Var37 Ξ“ A β†’ Tm37 Ξ“ A := Ξ» x Tm37 var37 lam app => var37 _ _ x def lam37 {Ξ“ A B} : Tm37 (snoc37 Ξ“ A) B β†’ Tm37 Ξ“ (arr37 A B) := Ξ» t Tm37 var37 lam37 app => lam37 _ _ _ (t Tm37 var37 lam37 app) def app37 {Ξ“ A B} : Tm37 Ξ“ (arr37 A B) β†’ Tm37 Ξ“ A β†’ Tm37 Ξ“ B := Ξ» t u Tm37 var37 lam37 app37 => app37 _ _ _ (t Tm37 var37 lam37 app37) (u Tm37 var37 lam37 app37) def v037 {Ξ“ A} : Tm37 (snoc37 Ξ“ A) A := var37 vz37 def v137 {Ξ“ A B} : Tm37 (snoc37 (snoc37 Ξ“ A) B) A := var37 (vs37 vz37) def v237 {Ξ“ A B C} : Tm37 (snoc37 (snoc37 (snoc37 Ξ“ A) B) C) A := var37 (vs37 (vs37 vz37)) def v337 {Ξ“ A B C D} : Tm37 (snoc37 (snoc37 (snoc37 (snoc37 Ξ“ A) B) C) D) A := var37 (vs37 (vs37 (vs37 vz37))) def v437 {Ξ“ A B C D E} : Tm37 (snoc37 (snoc37 (snoc37 (snoc37 (snoc37 Ξ“ A) B) C) D) E) A := var37 (vs37 (vs37 (vs37 (vs37 vz37)))) def test37 {Ξ“ A} : Tm37 Ξ“ (arr37 (arr37 A A) (arr37 A A)) := lam37 (lam37 (app37 v137 (app37 v137 (app37 v137 (app37 v137 (app37 v137 (app37 v137 v037))))))) def Ty38 : Type 1 := βˆ€ (Ty38 : Type) (ΞΉ : Ty38) (arr : Ty38 β†’ Ty38 β†’ Ty38) , Ty38 def ΞΉ38 : Ty38 := Ξ» _ ΞΉ38 _ => ΞΉ38 def arr38 : Ty38 β†’ Ty38 β†’ Ty38 := Ξ» A B Ty38 ΞΉ38 arr38 => arr38 (A Ty38 ΞΉ38 arr38) (B Ty38 ΞΉ38 arr38) def Con38 : Type 1 := βˆ€ (Con38 : Type) (nil : Con38) (snoc : Con38 β†’ Ty38 β†’ Con38) , Con38 def nil38 : Con38 := Ξ» Con38 nil38 snoc => nil38 def snoc38 : Con38 β†’ Ty38 β†’ Con38 := Ξ» Ξ“ A Con38 nil38 snoc38 => snoc38 (Ξ“ Con38 nil38 snoc38) A def Var38 : Con38 β†’ Ty38 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var38 : Con38 β†’ Ty38 β†’ Type) (vz : βˆ€ Ξ“ A, Var38 (snoc38 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var38 Ξ“ A β†’ Var38 (snoc38 Ξ“ B) A) , Var38 Ξ“ A def vz38 {Ξ“ A} : Var38 (snoc38 Ξ“ A) A := Ξ» Var38 vz38 vs => vz38 _ _ def vs38 {Ξ“ B A} : Var38 Ξ“ A β†’ Var38 (snoc38 Ξ“ B) A := Ξ» x Var38 vz38 vs38 => vs38 _ _ _ (x Var38 vz38 vs38) def Tm38 : Con38 β†’ Ty38 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm38 : Con38 β†’ Ty38 β†’ Type) (var : βˆ€ Ξ“ A , Var38 Ξ“ A β†’ Tm38 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm38 (snoc38 Ξ“ A) B β†’ Tm38 Ξ“ (arr38 A B)) (app : βˆ€ Ξ“ A B , Tm38 Ξ“ (arr38 A B) β†’ Tm38 Ξ“ A β†’ Tm38 Ξ“ B) , Tm38 Ξ“ A def var38 {Ξ“ A} : Var38 Ξ“ A β†’ Tm38 Ξ“ A := Ξ» x Tm38 var38 lam app => var38 _ _ x def lam38 {Ξ“ A B} : Tm38 (snoc38 Ξ“ A) B β†’ Tm38 Ξ“ (arr38 A B) := Ξ» t Tm38 var38 lam38 app => lam38 _ _ _ (t Tm38 var38 lam38 app) def app38 {Ξ“ A B} : Tm38 Ξ“ (arr38 A B) β†’ Tm38 Ξ“ A β†’ Tm38 Ξ“ B := Ξ» t u Tm38 var38 lam38 app38 => app38 _ _ _ (t Tm38 var38 lam38 app38) (u Tm38 var38 lam38 app38) def v038 {Ξ“ A} : Tm38 (snoc38 Ξ“ A) A := var38 vz38 def v138 {Ξ“ A B} : Tm38 (snoc38 (snoc38 Ξ“ A) B) A := var38 (vs38 vz38) def v238 {Ξ“ A B C} : Tm38 (snoc38 (snoc38 (snoc38 Ξ“ A) B) C) A := var38 (vs38 (vs38 vz38)) def v338 {Ξ“ A B C D} : Tm38 (snoc38 (snoc38 (snoc38 (snoc38 Ξ“ A) B) C) D) A := var38 (vs38 (vs38 (vs38 vz38))) def v438 {Ξ“ A B C D E} : Tm38 (snoc38 (snoc38 (snoc38 (snoc38 (snoc38 Ξ“ A) B) C) D) E) A := var38 (vs38 (vs38 (vs38 (vs38 vz38)))) def test38 {Ξ“ A} : Tm38 Ξ“ (arr38 (arr38 A A) (arr38 A A)) := lam38 (lam38 (app38 v138 (app38 v138 (app38 v138 (app38 v138 (app38 v138 (app38 v138 v038))))))) def Ty39 : Type 1 := βˆ€ (Ty39 : Type) (ΞΉ : Ty39) (arr : Ty39 β†’ Ty39 β†’ Ty39) , Ty39 def ΞΉ39 : Ty39 := Ξ» _ ΞΉ39 _ => ΞΉ39 def arr39 : Ty39 β†’ Ty39 β†’ Ty39 := Ξ» A B Ty39 ΞΉ39 arr39 => arr39 (A Ty39 ΞΉ39 arr39) (B Ty39 ΞΉ39 arr39) def Con39 : Type 1 := βˆ€ (Con39 : Type) (nil : Con39) (snoc : Con39 β†’ Ty39 β†’ Con39) , Con39 def nil39 : Con39 := Ξ» Con39 nil39 snoc => nil39 def snoc39 : Con39 β†’ Ty39 β†’ Con39 := Ξ» Ξ“ A Con39 nil39 snoc39 => snoc39 (Ξ“ Con39 nil39 snoc39) A def Var39 : Con39 β†’ Ty39 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var39 : Con39 β†’ Ty39 β†’ Type) (vz : βˆ€ Ξ“ A, Var39 (snoc39 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var39 Ξ“ A β†’ Var39 (snoc39 Ξ“ B) A) , Var39 Ξ“ A def vz39 {Ξ“ A} : Var39 (snoc39 Ξ“ A) A := Ξ» Var39 vz39 vs => vz39 _ _ def vs39 {Ξ“ B A} : Var39 Ξ“ A β†’ Var39 (snoc39 Ξ“ B) A := Ξ» x Var39 vz39 vs39 => vs39 _ _ _ (x Var39 vz39 vs39) def Tm39 : Con39 β†’ Ty39 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm39 : Con39 β†’ Ty39 β†’ Type) (var : βˆ€ Ξ“ A , Var39 Ξ“ A β†’ Tm39 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm39 (snoc39 Ξ“ A) B β†’ Tm39 Ξ“ (arr39 A B)) (app : βˆ€ Ξ“ A B , Tm39 Ξ“ (arr39 A B) β†’ Tm39 Ξ“ A β†’ Tm39 Ξ“ B) , Tm39 Ξ“ A def var39 {Ξ“ A} : Var39 Ξ“ A β†’ Tm39 Ξ“ A := Ξ» x Tm39 var39 lam app => var39 _ _ x def lam39 {Ξ“ A B} : Tm39 (snoc39 Ξ“ A) B β†’ Tm39 Ξ“ (arr39 A B) := Ξ» t Tm39 var39 lam39 app => lam39 _ _ _ (t Tm39 var39 lam39 app) def app39 {Ξ“ A B} : Tm39 Ξ“ (arr39 A B) β†’ Tm39 Ξ“ A β†’ Tm39 Ξ“ B := Ξ» t u Tm39 var39 lam39 app39 => app39 _ _ _ (t Tm39 var39 lam39 app39) (u Tm39 var39 lam39 app39) def v039 {Ξ“ A} : Tm39 (snoc39 Ξ“ A) A := var39 vz39 def v139 {Ξ“ A B} : Tm39 (snoc39 (snoc39 Ξ“ A) B) A := var39 (vs39 vz39) def v239 {Ξ“ A B C} : Tm39 (snoc39 (snoc39 (snoc39 Ξ“ A) B) C) A := var39 (vs39 (vs39 vz39)) def v339 {Ξ“ A B C D} : Tm39 (snoc39 (snoc39 (snoc39 (snoc39 Ξ“ A) B) C) D) A := var39 (vs39 (vs39 (vs39 vz39))) def v439 {Ξ“ A B C D E} : Tm39 (snoc39 (snoc39 (snoc39 (snoc39 (snoc39 Ξ“ A) B) C) D) E) A := var39 (vs39 (vs39 (vs39 (vs39 vz39)))) def test39 {Ξ“ A} : Tm39 Ξ“ (arr39 (arr39 A A) (arr39 A A)) := lam39 (lam39 (app39 v139 (app39 v139 (app39 v139 (app39 v139 (app39 v139 (app39 v139 v039))))))) def Ty40 : Type 1 := βˆ€ (Ty40 : Type) (ΞΉ : Ty40) (arr : Ty40 β†’ Ty40 β†’ Ty40) , Ty40 def ΞΉ40 : Ty40 := Ξ» _ ΞΉ40 _ => ΞΉ40 def arr40 : Ty40 β†’ Ty40 β†’ Ty40 := Ξ» A B Ty40 ΞΉ40 arr40 => arr40 (A Ty40 ΞΉ40 arr40) (B Ty40 ΞΉ40 arr40) def Con40 : Type 1 := βˆ€ (Con40 : Type) (nil : Con40) (snoc : Con40 β†’ Ty40 β†’ Con40) , Con40 def nil40 : Con40 := Ξ» Con40 nil40 snoc => nil40 def snoc40 : Con40 β†’ Ty40 β†’ Con40 := Ξ» Ξ“ A Con40 nil40 snoc40 => snoc40 (Ξ“ Con40 nil40 snoc40) A def Var40 : Con40 β†’ Ty40 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var40 : Con40 β†’ Ty40 β†’ Type) (vz : βˆ€ Ξ“ A, Var40 (snoc40 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var40 Ξ“ A β†’ Var40 (snoc40 Ξ“ B) A) , Var40 Ξ“ A def vz40 {Ξ“ A} : Var40 (snoc40 Ξ“ A) A := Ξ» Var40 vz40 vs => vz40 _ _ def vs40 {Ξ“ B A} : Var40 Ξ“ A β†’ Var40 (snoc40 Ξ“ B) A := Ξ» x Var40 vz40 vs40 => vs40 _ _ _ (x Var40 vz40 vs40) def Tm40 : Con40 β†’ Ty40 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm40 : Con40 β†’ Ty40 β†’ Type) (var : βˆ€ Ξ“ A , Var40 Ξ“ A β†’ Tm40 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm40 (snoc40 Ξ“ A) B β†’ Tm40 Ξ“ (arr40 A B)) (app : βˆ€ Ξ“ A B , Tm40 Ξ“ (arr40 A B) β†’ Tm40 Ξ“ A β†’ Tm40 Ξ“ B) , Tm40 Ξ“ A def var40 {Ξ“ A} : Var40 Ξ“ A β†’ Tm40 Ξ“ A := Ξ» x Tm40 var40 lam app => var40 _ _ x def lam40 {Ξ“ A B} : Tm40 (snoc40 Ξ“ A) B β†’ Tm40 Ξ“ (arr40 A B) := Ξ» t Tm40 var40 lam40 app => lam40 _ _ _ (t Tm40 var40 lam40 app) def app40 {Ξ“ A B} : Tm40 Ξ“ (arr40 A B) β†’ Tm40 Ξ“ A β†’ Tm40 Ξ“ B := Ξ» t u Tm40 var40 lam40 app40 => app40 _ _ _ (t Tm40 var40 lam40 app40) (u Tm40 var40 lam40 app40) def v040 {Ξ“ A} : Tm40 (snoc40 Ξ“ A) A := var40 vz40 def v140 {Ξ“ A B} : Tm40 (snoc40 (snoc40 Ξ“ A) B) A := var40 (vs40 vz40) def v240 {Ξ“ A B C} : Tm40 (snoc40 (snoc40 (snoc40 Ξ“ A) B) C) A := var40 (vs40 (vs40 vz40)) def v340 {Ξ“ A B C D} : Tm40 (snoc40 (snoc40 (snoc40 (snoc40 Ξ“ A) B) C) D) A := var40 (vs40 (vs40 (vs40 vz40))) def v440 {Ξ“ A B C D E} : Tm40 (snoc40 (snoc40 (snoc40 (snoc40 (snoc40 Ξ“ A) B) C) D) E) A := var40 (vs40 (vs40 (vs40 (vs40 vz40)))) def test40 {Ξ“ A} : Tm40 Ξ“ (arr40 (arr40 A A) (arr40 A A)) := lam40 (lam40 (app40 v140 (app40 v140 (app40 v140 (app40 v140 (app40 v140 (app40 v140 v040))))))) def Ty41 : Type 1 := βˆ€ (Ty41 : Type) (ΞΉ : Ty41) (arr : Ty41 β†’ Ty41 β†’ Ty41) , Ty41 def ΞΉ41 : Ty41 := Ξ» _ ΞΉ41 _ => ΞΉ41 def arr41 : Ty41 β†’ Ty41 β†’ Ty41 := Ξ» A B Ty41 ΞΉ41 arr41 => arr41 (A Ty41 ΞΉ41 arr41) (B Ty41 ΞΉ41 arr41) def Con41 : Type 1 := βˆ€ (Con41 : Type) (nil : Con41) (snoc : Con41 β†’ Ty41 β†’ Con41) , Con41 def nil41 : Con41 := Ξ» Con41 nil41 snoc => nil41 def snoc41 : Con41 β†’ Ty41 β†’ Con41 := Ξ» Ξ“ A Con41 nil41 snoc41 => snoc41 (Ξ“ Con41 nil41 snoc41) A def Var41 : Con41 β†’ Ty41 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var41 : Con41 β†’ Ty41 β†’ Type) (vz : βˆ€ Ξ“ A, Var41 (snoc41 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var41 Ξ“ A β†’ Var41 (snoc41 Ξ“ B) A) , Var41 Ξ“ A def vz41 {Ξ“ A} : Var41 (snoc41 Ξ“ A) A := Ξ» Var41 vz41 vs => vz41 _ _ def vs41 {Ξ“ B A} : Var41 Ξ“ A β†’ Var41 (snoc41 Ξ“ B) A := Ξ» x Var41 vz41 vs41 => vs41 _ _ _ (x Var41 vz41 vs41) def Tm41 : Con41 β†’ Ty41 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm41 : Con41 β†’ Ty41 β†’ Type) (var : βˆ€ Ξ“ A , Var41 Ξ“ A β†’ Tm41 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm41 (snoc41 Ξ“ A) B β†’ Tm41 Ξ“ (arr41 A B)) (app : βˆ€ Ξ“ A B , Tm41 Ξ“ (arr41 A B) β†’ Tm41 Ξ“ A β†’ Tm41 Ξ“ B) , Tm41 Ξ“ A def var41 {Ξ“ A} : Var41 Ξ“ A β†’ Tm41 Ξ“ A := Ξ» x Tm41 var41 lam app => var41 _ _ x def lam41 {Ξ“ A B} : Tm41 (snoc41 Ξ“ A) B β†’ Tm41 Ξ“ (arr41 A B) := Ξ» t Tm41 var41 lam41 app => lam41 _ _ _ (t Tm41 var41 lam41 app) def app41 {Ξ“ A B} : Tm41 Ξ“ (arr41 A B) β†’ Tm41 Ξ“ A β†’ Tm41 Ξ“ B := Ξ» t u Tm41 var41 lam41 app41 => app41 _ _ _ (t Tm41 var41 lam41 app41) (u Tm41 var41 lam41 app41) def v041 {Ξ“ A} : Tm41 (snoc41 Ξ“ A) A := var41 vz41 def v141 {Ξ“ A B} : Tm41 (snoc41 (snoc41 Ξ“ A) B) A := var41 (vs41 vz41) def v241 {Ξ“ A B C} : Tm41 (snoc41 (snoc41 (snoc41 Ξ“ A) B) C) A := var41 (vs41 (vs41 vz41)) def v341 {Ξ“ A B C D} : Tm41 (snoc41 (snoc41 (snoc41 (snoc41 Ξ“ A) B) C) D) A := var41 (vs41 (vs41 (vs41 vz41))) def v441 {Ξ“ A B C D E} : Tm41 (snoc41 (snoc41 (snoc41 (snoc41 (snoc41 Ξ“ A) B) C) D) E) A := var41 (vs41 (vs41 (vs41 (vs41 vz41)))) def test41 {Ξ“ A} : Tm41 Ξ“ (arr41 (arr41 A A) (arr41 A A)) := lam41 (lam41 (app41 v141 (app41 v141 (app41 v141 (app41 v141 (app41 v141 (app41 v141 v041))))))) def Ty42 : Type 1 := βˆ€ (Ty42 : Type) (ΞΉ : Ty42) (arr : Ty42 β†’ Ty42 β†’ Ty42) , Ty42 def ΞΉ42 : Ty42 := Ξ» _ ΞΉ42 _ => ΞΉ42 def arr42 : Ty42 β†’ Ty42 β†’ Ty42 := Ξ» A B Ty42 ΞΉ42 arr42 => arr42 (A Ty42 ΞΉ42 arr42) (B Ty42 ΞΉ42 arr42) def Con42 : Type 1 := βˆ€ (Con42 : Type) (nil : Con42) (snoc : Con42 β†’ Ty42 β†’ Con42) , Con42 def nil42 : Con42 := Ξ» Con42 nil42 snoc => nil42 def snoc42 : Con42 β†’ Ty42 β†’ Con42 := Ξ» Ξ“ A Con42 nil42 snoc42 => snoc42 (Ξ“ Con42 nil42 snoc42) A def Var42 : Con42 β†’ Ty42 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var42 : Con42 β†’ Ty42 β†’ Type) (vz : βˆ€ Ξ“ A, Var42 (snoc42 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var42 Ξ“ A β†’ Var42 (snoc42 Ξ“ B) A) , Var42 Ξ“ A def vz42 {Ξ“ A} : Var42 (snoc42 Ξ“ A) A := Ξ» Var42 vz42 vs => vz42 _ _ def vs42 {Ξ“ B A} : Var42 Ξ“ A β†’ Var42 (snoc42 Ξ“ B) A := Ξ» x Var42 vz42 vs42 => vs42 _ _ _ (x Var42 vz42 vs42) def Tm42 : Con42 β†’ Ty42 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm42 : Con42 β†’ Ty42 β†’ Type) (var : βˆ€ Ξ“ A , Var42 Ξ“ A β†’ Tm42 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm42 (snoc42 Ξ“ A) B β†’ Tm42 Ξ“ (arr42 A B)) (app : βˆ€ Ξ“ A B , Tm42 Ξ“ (arr42 A B) β†’ Tm42 Ξ“ A β†’ Tm42 Ξ“ B) , Tm42 Ξ“ A def var42 {Ξ“ A} : Var42 Ξ“ A β†’ Tm42 Ξ“ A := Ξ» x Tm42 var42 lam app => var42 _ _ x def lam42 {Ξ“ A B} : Tm42 (snoc42 Ξ“ A) B β†’ Tm42 Ξ“ (arr42 A B) := Ξ» t Tm42 var42 lam42 app => lam42 _ _ _ (t Tm42 var42 lam42 app) def app42 {Ξ“ A B} : Tm42 Ξ“ (arr42 A B) β†’ Tm42 Ξ“ A β†’ Tm42 Ξ“ B := Ξ» t u Tm42 var42 lam42 app42 => app42 _ _ _ (t Tm42 var42 lam42 app42) (u Tm42 var42 lam42 app42) def v042 {Ξ“ A} : Tm42 (snoc42 Ξ“ A) A := var42 vz42 def v142 {Ξ“ A B} : Tm42 (snoc42 (snoc42 Ξ“ A) B) A := var42 (vs42 vz42) def v242 {Ξ“ A B C} : Tm42 (snoc42 (snoc42 (snoc42 Ξ“ A) B) C) A := var42 (vs42 (vs42 vz42)) def v342 {Ξ“ A B C D} : Tm42 (snoc42 (snoc42 (snoc42 (snoc42 Ξ“ A) B) C) D) A := var42 (vs42 (vs42 (vs42 vz42))) def v442 {Ξ“ A B C D E} : Tm42 (snoc42 (snoc42 (snoc42 (snoc42 (snoc42 Ξ“ A) B) C) D) E) A := var42 (vs42 (vs42 (vs42 (vs42 vz42)))) def test42 {Ξ“ A} : Tm42 Ξ“ (arr42 (arr42 A A) (arr42 A A)) := lam42 (lam42 (app42 v142 (app42 v142 (app42 v142 (app42 v142 (app42 v142 (app42 v142 v042))))))) def Ty43 : Type 1 := βˆ€ (Ty43 : Type) (ΞΉ : Ty43) (arr : Ty43 β†’ Ty43 β†’ Ty43) , Ty43 def ΞΉ43 : Ty43 := Ξ» _ ΞΉ43 _ => ΞΉ43 def arr43 : Ty43 β†’ Ty43 β†’ Ty43 := Ξ» A B Ty43 ΞΉ43 arr43 => arr43 (A Ty43 ΞΉ43 arr43) (B Ty43 ΞΉ43 arr43) def Con43 : Type 1 := βˆ€ (Con43 : Type) (nil : Con43) (snoc : Con43 β†’ Ty43 β†’ Con43) , Con43 def nil43 : Con43 := Ξ» Con43 nil43 snoc => nil43 def snoc43 : Con43 β†’ Ty43 β†’ Con43 := Ξ» Ξ“ A Con43 nil43 snoc43 => snoc43 (Ξ“ Con43 nil43 snoc43) A def Var43 : Con43 β†’ Ty43 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var43 : Con43 β†’ Ty43 β†’ Type) (vz : βˆ€ Ξ“ A, Var43 (snoc43 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var43 Ξ“ A β†’ Var43 (snoc43 Ξ“ B) A) , Var43 Ξ“ A def vz43 {Ξ“ A} : Var43 (snoc43 Ξ“ A) A := Ξ» Var43 vz43 vs => vz43 _ _ def vs43 {Ξ“ B A} : Var43 Ξ“ A β†’ Var43 (snoc43 Ξ“ B) A := Ξ» x Var43 vz43 vs43 => vs43 _ _ _ (x Var43 vz43 vs43) def Tm43 : Con43 β†’ Ty43 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm43 : Con43 β†’ Ty43 β†’ Type) (var : βˆ€ Ξ“ A , Var43 Ξ“ A β†’ Tm43 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm43 (snoc43 Ξ“ A) B β†’ Tm43 Ξ“ (arr43 A B)) (app : βˆ€ Ξ“ A B , Tm43 Ξ“ (arr43 A B) β†’ Tm43 Ξ“ A β†’ Tm43 Ξ“ B) , Tm43 Ξ“ A def var43 {Ξ“ A} : Var43 Ξ“ A β†’ Tm43 Ξ“ A := Ξ» x Tm43 var43 lam app => var43 _ _ x def lam43 {Ξ“ A B} : Tm43 (snoc43 Ξ“ A) B β†’ Tm43 Ξ“ (arr43 A B) := Ξ» t Tm43 var43 lam43 app => lam43 _ _ _ (t Tm43 var43 lam43 app) def app43 {Ξ“ A B} : Tm43 Ξ“ (arr43 A B) β†’ Tm43 Ξ“ A β†’ Tm43 Ξ“ B := Ξ» t u Tm43 var43 lam43 app43 => app43 _ _ _ (t Tm43 var43 lam43 app43) (u Tm43 var43 lam43 app43) def v043 {Ξ“ A} : Tm43 (snoc43 Ξ“ A) A := var43 vz43 def v143 {Ξ“ A B} : Tm43 (snoc43 (snoc43 Ξ“ A) B) A := var43 (vs43 vz43) def v243 {Ξ“ A B C} : Tm43 (snoc43 (snoc43 (snoc43 Ξ“ A) B) C) A := var43 (vs43 (vs43 vz43)) def v343 {Ξ“ A B C D} : Tm43 (snoc43 (snoc43 (snoc43 (snoc43 Ξ“ A) B) C) D) A := var43 (vs43 (vs43 (vs43 vz43))) def v443 {Ξ“ A B C D E} : Tm43 (snoc43 (snoc43 (snoc43 (snoc43 (snoc43 Ξ“ A) B) C) D) E) A := var43 (vs43 (vs43 (vs43 (vs43 vz43)))) def test43 {Ξ“ A} : Tm43 Ξ“ (arr43 (arr43 A A) (arr43 A A)) := lam43 (lam43 (app43 v143 (app43 v143 (app43 v143 (app43 v143 (app43 v143 (app43 v143 v043))))))) def Ty44 : Type 1 := βˆ€ (Ty44 : Type) (ΞΉ : Ty44) (arr : Ty44 β†’ Ty44 β†’ Ty44) , Ty44 def ΞΉ44 : Ty44 := Ξ» _ ΞΉ44 _ => ΞΉ44 def arr44 : Ty44 β†’ Ty44 β†’ Ty44 := Ξ» A B Ty44 ΞΉ44 arr44 => arr44 (A Ty44 ΞΉ44 arr44) (B Ty44 ΞΉ44 arr44) def Con44 : Type 1 := βˆ€ (Con44 : Type) (nil : Con44) (snoc : Con44 β†’ Ty44 β†’ Con44) , Con44 def nil44 : Con44 := Ξ» Con44 nil44 snoc => nil44 def snoc44 : Con44 β†’ Ty44 β†’ Con44 := Ξ» Ξ“ A Con44 nil44 snoc44 => snoc44 (Ξ“ Con44 nil44 snoc44) A def Var44 : Con44 β†’ Ty44 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var44 : Con44 β†’ Ty44 β†’ Type) (vz : βˆ€ Ξ“ A, Var44 (snoc44 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var44 Ξ“ A β†’ Var44 (snoc44 Ξ“ B) A) , Var44 Ξ“ A def vz44 {Ξ“ A} : Var44 (snoc44 Ξ“ A) A := Ξ» Var44 vz44 vs => vz44 _ _ def vs44 {Ξ“ B A} : Var44 Ξ“ A β†’ Var44 (snoc44 Ξ“ B) A := Ξ» x Var44 vz44 vs44 => vs44 _ _ _ (x Var44 vz44 vs44) def Tm44 : Con44 β†’ Ty44 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm44 : Con44 β†’ Ty44 β†’ Type) (var : βˆ€ Ξ“ A , Var44 Ξ“ A β†’ Tm44 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm44 (snoc44 Ξ“ A) B β†’ Tm44 Ξ“ (arr44 A B)) (app : βˆ€ Ξ“ A B , Tm44 Ξ“ (arr44 A B) β†’ Tm44 Ξ“ A β†’ Tm44 Ξ“ B) , Tm44 Ξ“ A def var44 {Ξ“ A} : Var44 Ξ“ A β†’ Tm44 Ξ“ A := Ξ» x Tm44 var44 lam app => var44 _ _ x def lam44 {Ξ“ A B} : Tm44 (snoc44 Ξ“ A) B β†’ Tm44 Ξ“ (arr44 A B) := Ξ» t Tm44 var44 lam44 app => lam44 _ _ _ (t Tm44 var44 lam44 app) def app44 {Ξ“ A B} : Tm44 Ξ“ (arr44 A B) β†’ Tm44 Ξ“ A β†’ Tm44 Ξ“ B := Ξ» t u Tm44 var44 lam44 app44 => app44 _ _ _ (t Tm44 var44 lam44 app44) (u Tm44 var44 lam44 app44) def v044 {Ξ“ A} : Tm44 (snoc44 Ξ“ A) A := var44 vz44 def v144 {Ξ“ A B} : Tm44 (snoc44 (snoc44 Ξ“ A) B) A := var44 (vs44 vz44) def v244 {Ξ“ A B C} : Tm44 (snoc44 (snoc44 (snoc44 Ξ“ A) B) C) A := var44 (vs44 (vs44 vz44)) def v344 {Ξ“ A B C D} : Tm44 (snoc44 (snoc44 (snoc44 (snoc44 Ξ“ A) B) C) D) A := var44 (vs44 (vs44 (vs44 vz44))) def v444 {Ξ“ A B C D E} : Tm44 (snoc44 (snoc44 (snoc44 (snoc44 (snoc44 Ξ“ A) B) C) D) E) A := var44 (vs44 (vs44 (vs44 (vs44 vz44)))) def test44 {Ξ“ A} : Tm44 Ξ“ (arr44 (arr44 A A) (arr44 A A)) := lam44 (lam44 (app44 v144 (app44 v144 (app44 v144 (app44 v144 (app44 v144 (app44 v144 v044))))))) def Ty45 : Type 1 := βˆ€ (Ty45 : Type) (ΞΉ : Ty45) (arr : Ty45 β†’ Ty45 β†’ Ty45) , Ty45 def ΞΉ45 : Ty45 := Ξ» _ ΞΉ45 _ => ΞΉ45 def arr45 : Ty45 β†’ Ty45 β†’ Ty45 := Ξ» A B Ty45 ΞΉ45 arr45 => arr45 (A Ty45 ΞΉ45 arr45) (B Ty45 ΞΉ45 arr45) def Con45 : Type 1 := βˆ€ (Con45 : Type) (nil : Con45) (snoc : Con45 β†’ Ty45 β†’ Con45) , Con45 def nil45 : Con45 := Ξ» Con45 nil45 snoc => nil45 def snoc45 : Con45 β†’ Ty45 β†’ Con45 := Ξ» Ξ“ A Con45 nil45 snoc45 => snoc45 (Ξ“ Con45 nil45 snoc45) A def Var45 : Con45 β†’ Ty45 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var45 : Con45 β†’ Ty45 β†’ Type) (vz : βˆ€ Ξ“ A, Var45 (snoc45 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var45 Ξ“ A β†’ Var45 (snoc45 Ξ“ B) A) , Var45 Ξ“ A def vz45 {Ξ“ A} : Var45 (snoc45 Ξ“ A) A := Ξ» Var45 vz45 vs => vz45 _ _ def vs45 {Ξ“ B A} : Var45 Ξ“ A β†’ Var45 (snoc45 Ξ“ B) A := Ξ» x Var45 vz45 vs45 => vs45 _ _ _ (x Var45 vz45 vs45) def Tm45 : Con45 β†’ Ty45 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm45 : Con45 β†’ Ty45 β†’ Type) (var : βˆ€ Ξ“ A , Var45 Ξ“ A β†’ Tm45 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm45 (snoc45 Ξ“ A) B β†’ Tm45 Ξ“ (arr45 A B)) (app : βˆ€ Ξ“ A B , Tm45 Ξ“ (arr45 A B) β†’ Tm45 Ξ“ A β†’ Tm45 Ξ“ B) , Tm45 Ξ“ A def var45 {Ξ“ A} : Var45 Ξ“ A β†’ Tm45 Ξ“ A := Ξ» x Tm45 var45 lam app => var45 _ _ x def lam45 {Ξ“ A B} : Tm45 (snoc45 Ξ“ A) B β†’ Tm45 Ξ“ (arr45 A B) := Ξ» t Tm45 var45 lam45 app => lam45 _ _ _ (t Tm45 var45 lam45 app) def app45 {Ξ“ A B} : Tm45 Ξ“ (arr45 A B) β†’ Tm45 Ξ“ A β†’ Tm45 Ξ“ B := Ξ» t u Tm45 var45 lam45 app45 => app45 _ _ _ (t Tm45 var45 lam45 app45) (u Tm45 var45 lam45 app45) def v045 {Ξ“ A} : Tm45 (snoc45 Ξ“ A) A := var45 vz45 def v145 {Ξ“ A B} : Tm45 (snoc45 (snoc45 Ξ“ A) B) A := var45 (vs45 vz45) def v245 {Ξ“ A B C} : Tm45 (snoc45 (snoc45 (snoc45 Ξ“ A) B) C) A := var45 (vs45 (vs45 vz45)) def v345 {Ξ“ A B C D} : Tm45 (snoc45 (snoc45 (snoc45 (snoc45 Ξ“ A) B) C) D) A := var45 (vs45 (vs45 (vs45 vz45))) def v445 {Ξ“ A B C D E} : Tm45 (snoc45 (snoc45 (snoc45 (snoc45 (snoc45 Ξ“ A) B) C) D) E) A := var45 (vs45 (vs45 (vs45 (vs45 vz45)))) def test45 {Ξ“ A} : Tm45 Ξ“ (arr45 (arr45 A A) (arr45 A A)) := lam45 (lam45 (app45 v145 (app45 v145 (app45 v145 (app45 v145 (app45 v145 (app45 v145 v045))))))) def Ty46 : Type 1 := βˆ€ (Ty46 : Type) (ΞΉ : Ty46) (arr : Ty46 β†’ Ty46 β†’ Ty46) , Ty46 def ΞΉ46 : Ty46 := Ξ» _ ΞΉ46 _ => ΞΉ46 def arr46 : Ty46 β†’ Ty46 β†’ Ty46 := Ξ» A B Ty46 ΞΉ46 arr46 => arr46 (A Ty46 ΞΉ46 arr46) (B Ty46 ΞΉ46 arr46) def Con46 : Type 1 := βˆ€ (Con46 : Type) (nil : Con46) (snoc : Con46 β†’ Ty46 β†’ Con46) , Con46 def nil46 : Con46 := Ξ» Con46 nil46 snoc => nil46 def snoc46 : Con46 β†’ Ty46 β†’ Con46 := Ξ» Ξ“ A Con46 nil46 snoc46 => snoc46 (Ξ“ Con46 nil46 snoc46) A def Var46 : Con46 β†’ Ty46 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var46 : Con46 β†’ Ty46 β†’ Type) (vz : βˆ€ Ξ“ A, Var46 (snoc46 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var46 Ξ“ A β†’ Var46 (snoc46 Ξ“ B) A) , Var46 Ξ“ A def vz46 {Ξ“ A} : Var46 (snoc46 Ξ“ A) A := Ξ» Var46 vz46 vs => vz46 _ _ def vs46 {Ξ“ B A} : Var46 Ξ“ A β†’ Var46 (snoc46 Ξ“ B) A := Ξ» x Var46 vz46 vs46 => vs46 _ _ _ (x Var46 vz46 vs46) def Tm46 : Con46 β†’ Ty46 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm46 : Con46 β†’ Ty46 β†’ Type) (var : βˆ€ Ξ“ A , Var46 Ξ“ A β†’ Tm46 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm46 (snoc46 Ξ“ A) B β†’ Tm46 Ξ“ (arr46 A B)) (app : βˆ€ Ξ“ A B , Tm46 Ξ“ (arr46 A B) β†’ Tm46 Ξ“ A β†’ Tm46 Ξ“ B) , Tm46 Ξ“ A def var46 {Ξ“ A} : Var46 Ξ“ A β†’ Tm46 Ξ“ A := Ξ» x Tm46 var46 lam app => var46 _ _ x def lam46 {Ξ“ A B} : Tm46 (snoc46 Ξ“ A) B β†’ Tm46 Ξ“ (arr46 A B) := Ξ» t Tm46 var46 lam46 app => lam46 _ _ _ (t Tm46 var46 lam46 app) def app46 {Ξ“ A B} : Tm46 Ξ“ (arr46 A B) β†’ Tm46 Ξ“ A β†’ Tm46 Ξ“ B := Ξ» t u Tm46 var46 lam46 app46 => app46 _ _ _ (t Tm46 var46 lam46 app46) (u Tm46 var46 lam46 app46) def v046 {Ξ“ A} : Tm46 (snoc46 Ξ“ A) A := var46 vz46 def v146 {Ξ“ A B} : Tm46 (snoc46 (snoc46 Ξ“ A) B) A := var46 (vs46 vz46) def v246 {Ξ“ A B C} : Tm46 (snoc46 (snoc46 (snoc46 Ξ“ A) B) C) A := var46 (vs46 (vs46 vz46)) def v346 {Ξ“ A B C D} : Tm46 (snoc46 (snoc46 (snoc46 (snoc46 Ξ“ A) B) C) D) A := var46 (vs46 (vs46 (vs46 vz46))) def v446 {Ξ“ A B C D E} : Tm46 (snoc46 (snoc46 (snoc46 (snoc46 (snoc46 Ξ“ A) B) C) D) E) A := var46 (vs46 (vs46 (vs46 (vs46 vz46)))) def test46 {Ξ“ A} : Tm46 Ξ“ (arr46 (arr46 A A) (arr46 A A)) := lam46 (lam46 (app46 v146 (app46 v146 (app46 v146 (app46 v146 (app46 v146 (app46 v146 v046))))))) def Ty47 : Type 1 := βˆ€ (Ty47 : Type) (ΞΉ : Ty47) (arr : Ty47 β†’ Ty47 β†’ Ty47) , Ty47 def ΞΉ47 : Ty47 := Ξ» _ ΞΉ47 _ => ΞΉ47 def arr47 : Ty47 β†’ Ty47 β†’ Ty47 := Ξ» A B Ty47 ΞΉ47 arr47 => arr47 (A Ty47 ΞΉ47 arr47) (B Ty47 ΞΉ47 arr47) def Con47 : Type 1 := βˆ€ (Con47 : Type) (nil : Con47) (snoc : Con47 β†’ Ty47 β†’ Con47) , Con47 def nil47 : Con47 := Ξ» Con47 nil47 snoc => nil47 def snoc47 : Con47 β†’ Ty47 β†’ Con47 := Ξ» Ξ“ A Con47 nil47 snoc47 => snoc47 (Ξ“ Con47 nil47 snoc47) A def Var47 : Con47 β†’ Ty47 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var47 : Con47 β†’ Ty47 β†’ Type) (vz : βˆ€ Ξ“ A, Var47 (snoc47 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var47 Ξ“ A β†’ Var47 (snoc47 Ξ“ B) A) , Var47 Ξ“ A def vz47 {Ξ“ A} : Var47 (snoc47 Ξ“ A) A := Ξ» Var47 vz47 vs => vz47 _ _ def vs47 {Ξ“ B A} : Var47 Ξ“ A β†’ Var47 (snoc47 Ξ“ B) A := Ξ» x Var47 vz47 vs47 => vs47 _ _ _ (x Var47 vz47 vs47) def Tm47 : Con47 β†’ Ty47 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm47 : Con47 β†’ Ty47 β†’ Type) (var : βˆ€ Ξ“ A , Var47 Ξ“ A β†’ Tm47 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm47 (snoc47 Ξ“ A) B β†’ Tm47 Ξ“ (arr47 A B)) (app : βˆ€ Ξ“ A B , Tm47 Ξ“ (arr47 A B) β†’ Tm47 Ξ“ A β†’ Tm47 Ξ“ B) , Tm47 Ξ“ A def var47 {Ξ“ A} : Var47 Ξ“ A β†’ Tm47 Ξ“ A := Ξ» x Tm47 var47 lam app => var47 _ _ x def lam47 {Ξ“ A B} : Tm47 (snoc47 Ξ“ A) B β†’ Tm47 Ξ“ (arr47 A B) := Ξ» t Tm47 var47 lam47 app => lam47 _ _ _ (t Tm47 var47 lam47 app) def app47 {Ξ“ A B} : Tm47 Ξ“ (arr47 A B) β†’ Tm47 Ξ“ A β†’ Tm47 Ξ“ B := Ξ» t u Tm47 var47 lam47 app47 => app47 _ _ _ (t Tm47 var47 lam47 app47) (u Tm47 var47 lam47 app47) def v047 {Ξ“ A} : Tm47 (snoc47 Ξ“ A) A := var47 vz47 def v147 {Ξ“ A B} : Tm47 (snoc47 (snoc47 Ξ“ A) B) A := var47 (vs47 vz47) def v247 {Ξ“ A B C} : Tm47 (snoc47 (snoc47 (snoc47 Ξ“ A) B) C) A := var47 (vs47 (vs47 vz47)) def v347 {Ξ“ A B C D} : Tm47 (snoc47 (snoc47 (snoc47 (snoc47 Ξ“ A) B) C) D) A := var47 (vs47 (vs47 (vs47 vz47))) def v447 {Ξ“ A B C D E} : Tm47 (snoc47 (snoc47 (snoc47 (snoc47 (snoc47 Ξ“ A) B) C) D) E) A := var47 (vs47 (vs47 (vs47 (vs47 vz47)))) def test47 {Ξ“ A} : Tm47 Ξ“ (arr47 (arr47 A A) (arr47 A A)) := lam47 (lam47 (app47 v147 (app47 v147 (app47 v147 (app47 v147 (app47 v147 (app47 v147 v047))))))) def Ty48 : Type 1 := βˆ€ (Ty48 : Type) (ΞΉ : Ty48) (arr : Ty48 β†’ Ty48 β†’ Ty48) , Ty48 def ΞΉ48 : Ty48 := Ξ» _ ΞΉ48 _ => ΞΉ48 def arr48 : Ty48 β†’ Ty48 β†’ Ty48 := Ξ» A B Ty48 ΞΉ48 arr48 => arr48 (A Ty48 ΞΉ48 arr48) (B Ty48 ΞΉ48 arr48) def Con48 : Type 1 := βˆ€ (Con48 : Type) (nil : Con48) (snoc : Con48 β†’ Ty48 β†’ Con48) , Con48 def nil48 : Con48 := Ξ» Con48 nil48 snoc => nil48 def snoc48 : Con48 β†’ Ty48 β†’ Con48 := Ξ» Ξ“ A Con48 nil48 snoc48 => snoc48 (Ξ“ Con48 nil48 snoc48) A def Var48 : Con48 β†’ Ty48 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var48 : Con48 β†’ Ty48 β†’ Type) (vz : βˆ€ Ξ“ A, Var48 (snoc48 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var48 Ξ“ A β†’ Var48 (snoc48 Ξ“ B) A) , Var48 Ξ“ A def vz48 {Ξ“ A} : Var48 (snoc48 Ξ“ A) A := Ξ» Var48 vz48 vs => vz48 _ _ def vs48 {Ξ“ B A} : Var48 Ξ“ A β†’ Var48 (snoc48 Ξ“ B) A := Ξ» x Var48 vz48 vs48 => vs48 _ _ _ (x Var48 vz48 vs48) def Tm48 : Con48 β†’ Ty48 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm48 : Con48 β†’ Ty48 β†’ Type) (var : βˆ€ Ξ“ A , Var48 Ξ“ A β†’ Tm48 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm48 (snoc48 Ξ“ A) B β†’ Tm48 Ξ“ (arr48 A B)) (app : βˆ€ Ξ“ A B , Tm48 Ξ“ (arr48 A B) β†’ Tm48 Ξ“ A β†’ Tm48 Ξ“ B) , Tm48 Ξ“ A def var48 {Ξ“ A} : Var48 Ξ“ A β†’ Tm48 Ξ“ A := Ξ» x Tm48 var48 lam app => var48 _ _ x def lam48 {Ξ“ A B} : Tm48 (snoc48 Ξ“ A) B β†’ Tm48 Ξ“ (arr48 A B) := Ξ» t Tm48 var48 lam48 app => lam48 _ _ _ (t Tm48 var48 lam48 app) def app48 {Ξ“ A B} : Tm48 Ξ“ (arr48 A B) β†’ Tm48 Ξ“ A β†’ Tm48 Ξ“ B := Ξ» t u Tm48 var48 lam48 app48 => app48 _ _ _ (t Tm48 var48 lam48 app48) (u Tm48 var48 lam48 app48) def v048 {Ξ“ A} : Tm48 (snoc48 Ξ“ A) A := var48 vz48 def v148 {Ξ“ A B} : Tm48 (snoc48 (snoc48 Ξ“ A) B) A := var48 (vs48 vz48) def v248 {Ξ“ A B C} : Tm48 (snoc48 (snoc48 (snoc48 Ξ“ A) B) C) A := var48 (vs48 (vs48 vz48)) def v348 {Ξ“ A B C D} : Tm48 (snoc48 (snoc48 (snoc48 (snoc48 Ξ“ A) B) C) D) A := var48 (vs48 (vs48 (vs48 vz48))) def v448 {Ξ“ A B C D E} : Tm48 (snoc48 (snoc48 (snoc48 (snoc48 (snoc48 Ξ“ A) B) C) D) E) A := var48 (vs48 (vs48 (vs48 (vs48 vz48)))) def test48 {Ξ“ A} : Tm48 Ξ“ (arr48 (arr48 A A) (arr48 A A)) := lam48 (lam48 (app48 v148 (app48 v148 (app48 v148 (app48 v148 (app48 v148 (app48 v148 v048))))))) def Ty49 : Type 1 := βˆ€ (Ty49 : Type) (ΞΉ : Ty49) (arr : Ty49 β†’ Ty49 β†’ Ty49) , Ty49 def ΞΉ49 : Ty49 := Ξ» _ ΞΉ49 _ => ΞΉ49 def arr49 : Ty49 β†’ Ty49 β†’ Ty49 := Ξ» A B Ty49 ΞΉ49 arr49 => arr49 (A Ty49 ΞΉ49 arr49) (B Ty49 ΞΉ49 arr49) def Con49 : Type 1 := βˆ€ (Con49 : Type) (nil : Con49) (snoc : Con49 β†’ Ty49 β†’ Con49) , Con49 def nil49 : Con49 := Ξ» Con49 nil49 snoc => nil49 def snoc49 : Con49 β†’ Ty49 β†’ Con49 := Ξ» Ξ“ A Con49 nil49 snoc49 => snoc49 (Ξ“ Con49 nil49 snoc49) A def Var49 : Con49 β†’ Ty49 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var49 : Con49 β†’ Ty49 β†’ Type) (vz : βˆ€ Ξ“ A, Var49 (snoc49 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var49 Ξ“ A β†’ Var49 (snoc49 Ξ“ B) A) , Var49 Ξ“ A def vz49 {Ξ“ A} : Var49 (snoc49 Ξ“ A) A := Ξ» Var49 vz49 vs => vz49 _ _ def vs49 {Ξ“ B A} : Var49 Ξ“ A β†’ Var49 (snoc49 Ξ“ B) A := Ξ» x Var49 vz49 vs49 => vs49 _ _ _ (x Var49 vz49 vs49) def Tm49 : Con49 β†’ Ty49 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm49 : Con49 β†’ Ty49 β†’ Type) (var : βˆ€ Ξ“ A , Var49 Ξ“ A β†’ Tm49 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm49 (snoc49 Ξ“ A) B β†’ Tm49 Ξ“ (arr49 A B)) (app : βˆ€ Ξ“ A B , Tm49 Ξ“ (arr49 A B) β†’ Tm49 Ξ“ A β†’ Tm49 Ξ“ B) , Tm49 Ξ“ A def var49 {Ξ“ A} : Var49 Ξ“ A β†’ Tm49 Ξ“ A := Ξ» x Tm49 var49 lam app => var49 _ _ x def lam49 {Ξ“ A B} : Tm49 (snoc49 Ξ“ A) B β†’ Tm49 Ξ“ (arr49 A B) := Ξ» t Tm49 var49 lam49 app => lam49 _ _ _ (t Tm49 var49 lam49 app) def app49 {Ξ“ A B} : Tm49 Ξ“ (arr49 A B) β†’ Tm49 Ξ“ A β†’ Tm49 Ξ“ B := Ξ» t u Tm49 var49 lam49 app49 => app49 _ _ _ (t Tm49 var49 lam49 app49) (u Tm49 var49 lam49 app49) def v049 {Ξ“ A} : Tm49 (snoc49 Ξ“ A) A := var49 vz49 def v149 {Ξ“ A B} : Tm49 (snoc49 (snoc49 Ξ“ A) B) A := var49 (vs49 vz49) def v249 {Ξ“ A B C} : Tm49 (snoc49 (snoc49 (snoc49 Ξ“ A) B) C) A := var49 (vs49 (vs49 vz49)) def v349 {Ξ“ A B C D} : Tm49 (snoc49 (snoc49 (snoc49 (snoc49 Ξ“ A) B) C) D) A := var49 (vs49 (vs49 (vs49 vz49))) def v449 {Ξ“ A B C D E} : Tm49 (snoc49 (snoc49 (snoc49 (snoc49 (snoc49 Ξ“ A) B) C) D) E) A := var49 (vs49 (vs49 (vs49 (vs49 vz49)))) def test49 {Ξ“ A} : Tm49 Ξ“ (arr49 (arr49 A A) (arr49 A A)) := lam49 (lam49 (app49 v149 (app49 v149 (app49 v149 (app49 v149 (app49 v149 (app49 v149 v049))))))) def Ty50 : Type 1 := βˆ€ (Ty50 : Type) (ΞΉ : Ty50) (arr : Ty50 β†’ Ty50 β†’ Ty50) , Ty50 def ΞΉ50 : Ty50 := Ξ» _ ΞΉ50 _ => ΞΉ50 def arr50 : Ty50 β†’ Ty50 β†’ Ty50 := Ξ» A B Ty50 ΞΉ50 arr50 => arr50 (A Ty50 ΞΉ50 arr50) (B Ty50 ΞΉ50 arr50) def Con50 : Type 1 := βˆ€ (Con50 : Type) (nil : Con50) (snoc : Con50 β†’ Ty50 β†’ Con50) , Con50 def nil50 : Con50 := Ξ» Con50 nil50 snoc => nil50 def snoc50 : Con50 β†’ Ty50 β†’ Con50 := Ξ» Ξ“ A Con50 nil50 snoc50 => snoc50 (Ξ“ Con50 nil50 snoc50) A def Var50 : Con50 β†’ Ty50 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var50 : Con50 β†’ Ty50 β†’ Type) (vz : βˆ€ Ξ“ A, Var50 (snoc50 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var50 Ξ“ A β†’ Var50 (snoc50 Ξ“ B) A) , Var50 Ξ“ A def vz50 {Ξ“ A} : Var50 (snoc50 Ξ“ A) A := Ξ» Var50 vz50 vs => vz50 _ _ def vs50 {Ξ“ B A} : Var50 Ξ“ A β†’ Var50 (snoc50 Ξ“ B) A := Ξ» x Var50 vz50 vs50 => vs50 _ _ _ (x Var50 vz50 vs50) def Tm50 : Con50 β†’ Ty50 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm50 : Con50 β†’ Ty50 β†’ Type) (var : βˆ€ Ξ“ A , Var50 Ξ“ A β†’ Tm50 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm50 (snoc50 Ξ“ A) B β†’ Tm50 Ξ“ (arr50 A B)) (app : βˆ€ Ξ“ A B , Tm50 Ξ“ (arr50 A B) β†’ Tm50 Ξ“ A β†’ Tm50 Ξ“ B) , Tm50 Ξ“ A def var50 {Ξ“ A} : Var50 Ξ“ A β†’ Tm50 Ξ“ A := Ξ» x Tm50 var50 lam app => var50 _ _ x def lam50 {Ξ“ A B} : Tm50 (snoc50 Ξ“ A) B β†’ Tm50 Ξ“ (arr50 A B) := Ξ» t Tm50 var50 lam50 app => lam50 _ _ _ (t Tm50 var50 lam50 app) def app50 {Ξ“ A B} : Tm50 Ξ“ (arr50 A B) β†’ Tm50 Ξ“ A β†’ Tm50 Ξ“ B := Ξ» t u Tm50 var50 lam50 app50 => app50 _ _ _ (t Tm50 var50 lam50 app50) (u Tm50 var50 lam50 app50) def v050 {Ξ“ A} : Tm50 (snoc50 Ξ“ A) A := var50 vz50 def v150 {Ξ“ A B} : Tm50 (snoc50 (snoc50 Ξ“ A) B) A := var50 (vs50 vz50) def v250 {Ξ“ A B C} : Tm50 (snoc50 (snoc50 (snoc50 Ξ“ A) B) C) A := var50 (vs50 (vs50 vz50)) def v350 {Ξ“ A B C D} : Tm50 (snoc50 (snoc50 (snoc50 (snoc50 Ξ“ A) B) C) D) A := var50 (vs50 (vs50 (vs50 vz50))) def v450 {Ξ“ A B C D E} : Tm50 (snoc50 (snoc50 (snoc50 (snoc50 (snoc50 Ξ“ A) B) C) D) E) A := var50 (vs50 (vs50 (vs50 (vs50 vz50)))) def test50 {Ξ“ A} : Tm50 Ξ“ (arr50 (arr50 A A) (arr50 A A)) := lam50 (lam50 (app50 v150 (app50 v150 (app50 v150 (app50 v150 (app50 v150 (app50 v150 v050))))))) def Ty51 : Type 1 := βˆ€ (Ty51 : Type) (ΞΉ : Ty51) (arr : Ty51 β†’ Ty51 β†’ Ty51) , Ty51 def ΞΉ51 : Ty51 := Ξ» _ ΞΉ51 _ => ΞΉ51 def arr51 : Ty51 β†’ Ty51 β†’ Ty51 := Ξ» A B Ty51 ΞΉ51 arr51 => arr51 (A Ty51 ΞΉ51 arr51) (B Ty51 ΞΉ51 arr51) def Con51 : Type 1 := βˆ€ (Con51 : Type) (nil : Con51) (snoc : Con51 β†’ Ty51 β†’ Con51) , Con51 def nil51 : Con51 := Ξ» Con51 nil51 snoc => nil51 def snoc51 : Con51 β†’ Ty51 β†’ Con51 := Ξ» Ξ“ A Con51 nil51 snoc51 => snoc51 (Ξ“ Con51 nil51 snoc51) A def Var51 : Con51 β†’ Ty51 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var51 : Con51 β†’ Ty51 β†’ Type) (vz : βˆ€ Ξ“ A, Var51 (snoc51 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var51 Ξ“ A β†’ Var51 (snoc51 Ξ“ B) A) , Var51 Ξ“ A def vz51 {Ξ“ A} : Var51 (snoc51 Ξ“ A) A := Ξ» Var51 vz51 vs => vz51 _ _ def vs51 {Ξ“ B A} : Var51 Ξ“ A β†’ Var51 (snoc51 Ξ“ B) A := Ξ» x Var51 vz51 vs51 => vs51 _ _ _ (x Var51 vz51 vs51) def Tm51 : Con51 β†’ Ty51 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm51 : Con51 β†’ Ty51 β†’ Type) (var : βˆ€ Ξ“ A , Var51 Ξ“ A β†’ Tm51 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm51 (snoc51 Ξ“ A) B β†’ Tm51 Ξ“ (arr51 A B)) (app : βˆ€ Ξ“ A B , Tm51 Ξ“ (arr51 A B) β†’ Tm51 Ξ“ A β†’ Tm51 Ξ“ B) , Tm51 Ξ“ A def var51 {Ξ“ A} : Var51 Ξ“ A β†’ Tm51 Ξ“ A := Ξ» x Tm51 var51 lam app => var51 _ _ x def lam51 {Ξ“ A B} : Tm51 (snoc51 Ξ“ A) B β†’ Tm51 Ξ“ (arr51 A B) := Ξ» t Tm51 var51 lam51 app => lam51 _ _ _ (t Tm51 var51 lam51 app) def app51 {Ξ“ A B} : Tm51 Ξ“ (arr51 A B) β†’ Tm51 Ξ“ A β†’ Tm51 Ξ“ B := Ξ» t u Tm51 var51 lam51 app51 => app51 _ _ _ (t Tm51 var51 lam51 app51) (u Tm51 var51 lam51 app51) def v051 {Ξ“ A} : Tm51 (snoc51 Ξ“ A) A := var51 vz51 def v151 {Ξ“ A B} : Tm51 (snoc51 (snoc51 Ξ“ A) B) A := var51 (vs51 vz51) def v251 {Ξ“ A B C} : Tm51 (snoc51 (snoc51 (snoc51 Ξ“ A) B) C) A := var51 (vs51 (vs51 vz51)) def v351 {Ξ“ A B C D} : Tm51 (snoc51 (snoc51 (snoc51 (snoc51 Ξ“ A) B) C) D) A := var51 (vs51 (vs51 (vs51 vz51))) def v451 {Ξ“ A B C D E} : Tm51 (snoc51 (snoc51 (snoc51 (snoc51 (snoc51 Ξ“ A) B) C) D) E) A := var51 (vs51 (vs51 (vs51 (vs51 vz51)))) def test51 {Ξ“ A} : Tm51 Ξ“ (arr51 (arr51 A A) (arr51 A A)) := lam51 (lam51 (app51 v151 (app51 v151 (app51 v151 (app51 v151 (app51 v151 (app51 v151 v051))))))) def Ty52 : Type 1 := βˆ€ (Ty52 : Type) (ΞΉ : Ty52) (arr : Ty52 β†’ Ty52 β†’ Ty52) , Ty52 def ΞΉ52 : Ty52 := Ξ» _ ΞΉ52 _ => ΞΉ52 def arr52 : Ty52 β†’ Ty52 β†’ Ty52 := Ξ» A B Ty52 ΞΉ52 arr52 => arr52 (A Ty52 ΞΉ52 arr52) (B Ty52 ΞΉ52 arr52) def Con52 : Type 1 := βˆ€ (Con52 : Type) (nil : Con52) (snoc : Con52 β†’ Ty52 β†’ Con52) , Con52 def nil52 : Con52 := Ξ» Con52 nil52 snoc => nil52 def snoc52 : Con52 β†’ Ty52 β†’ Con52 := Ξ» Ξ“ A Con52 nil52 snoc52 => snoc52 (Ξ“ Con52 nil52 snoc52) A def Var52 : Con52 β†’ Ty52 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var52 : Con52 β†’ Ty52 β†’ Type) (vz : βˆ€ Ξ“ A, Var52 (snoc52 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var52 Ξ“ A β†’ Var52 (snoc52 Ξ“ B) A) , Var52 Ξ“ A def vz52 {Ξ“ A} : Var52 (snoc52 Ξ“ A) A := Ξ» Var52 vz52 vs => vz52 _ _ def vs52 {Ξ“ B A} : Var52 Ξ“ A β†’ Var52 (snoc52 Ξ“ B) A := Ξ» x Var52 vz52 vs52 => vs52 _ _ _ (x Var52 vz52 vs52) def Tm52 : Con52 β†’ Ty52 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm52 : Con52 β†’ Ty52 β†’ Type) (var : βˆ€ Ξ“ A , Var52 Ξ“ A β†’ Tm52 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm52 (snoc52 Ξ“ A) B β†’ Tm52 Ξ“ (arr52 A B)) (app : βˆ€ Ξ“ A B , Tm52 Ξ“ (arr52 A B) β†’ Tm52 Ξ“ A β†’ Tm52 Ξ“ B) , Tm52 Ξ“ A def var52 {Ξ“ A} : Var52 Ξ“ A β†’ Tm52 Ξ“ A := Ξ» x Tm52 var52 lam app => var52 _ _ x def lam52 {Ξ“ A B} : Tm52 (snoc52 Ξ“ A) B β†’ Tm52 Ξ“ (arr52 A B) := Ξ» t Tm52 var52 lam52 app => lam52 _ _ _ (t Tm52 var52 lam52 app) def app52 {Ξ“ A B} : Tm52 Ξ“ (arr52 A B) β†’ Tm52 Ξ“ A β†’ Tm52 Ξ“ B := Ξ» t u Tm52 var52 lam52 app52 => app52 _ _ _ (t Tm52 var52 lam52 app52) (u Tm52 var52 lam52 app52) def v052 {Ξ“ A} : Tm52 (snoc52 Ξ“ A) A := var52 vz52 def v152 {Ξ“ A B} : Tm52 (snoc52 (snoc52 Ξ“ A) B) A := var52 (vs52 vz52) def v252 {Ξ“ A B C} : Tm52 (snoc52 (snoc52 (snoc52 Ξ“ A) B) C) A := var52 (vs52 (vs52 vz52)) def v352 {Ξ“ A B C D} : Tm52 (snoc52 (snoc52 (snoc52 (snoc52 Ξ“ A) B) C) D) A := var52 (vs52 (vs52 (vs52 vz52))) def v452 {Ξ“ A B C D E} : Tm52 (snoc52 (snoc52 (snoc52 (snoc52 (snoc52 Ξ“ A) B) C) D) E) A := var52 (vs52 (vs52 (vs52 (vs52 vz52)))) def test52 {Ξ“ A} : Tm52 Ξ“ (arr52 (arr52 A A) (arr52 A A)) := lam52 (lam52 (app52 v152 (app52 v152 (app52 v152 (app52 v152 (app52 v152 (app52 v152 v052))))))) def Ty53 : Type 1 := βˆ€ (Ty53 : Type) (ΞΉ : Ty53) (arr : Ty53 β†’ Ty53 β†’ Ty53) , Ty53 def ΞΉ53 : Ty53 := Ξ» _ ΞΉ53 _ => ΞΉ53 def arr53 : Ty53 β†’ Ty53 β†’ Ty53 := Ξ» A B Ty53 ΞΉ53 arr53 => arr53 (A Ty53 ΞΉ53 arr53) (B Ty53 ΞΉ53 arr53) def Con53 : Type 1 := βˆ€ (Con53 : Type) (nil : Con53) (snoc : Con53 β†’ Ty53 β†’ Con53) , Con53 def nil53 : Con53 := Ξ» Con53 nil53 snoc => nil53 def snoc53 : Con53 β†’ Ty53 β†’ Con53 := Ξ» Ξ“ A Con53 nil53 snoc53 => snoc53 (Ξ“ Con53 nil53 snoc53) A def Var53 : Con53 β†’ Ty53 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var53 : Con53 β†’ Ty53 β†’ Type) (vz : βˆ€ Ξ“ A, Var53 (snoc53 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var53 Ξ“ A β†’ Var53 (snoc53 Ξ“ B) A) , Var53 Ξ“ A def vz53 {Ξ“ A} : Var53 (snoc53 Ξ“ A) A := Ξ» Var53 vz53 vs => vz53 _ _ def vs53 {Ξ“ B A} : Var53 Ξ“ A β†’ Var53 (snoc53 Ξ“ B) A := Ξ» x Var53 vz53 vs53 => vs53 _ _ _ (x Var53 vz53 vs53) def Tm53 : Con53 β†’ Ty53 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm53 : Con53 β†’ Ty53 β†’ Type) (var : βˆ€ Ξ“ A , Var53 Ξ“ A β†’ Tm53 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm53 (snoc53 Ξ“ A) B β†’ Tm53 Ξ“ (arr53 A B)) (app : βˆ€ Ξ“ A B , Tm53 Ξ“ (arr53 A B) β†’ Tm53 Ξ“ A β†’ Tm53 Ξ“ B) , Tm53 Ξ“ A def var53 {Ξ“ A} : Var53 Ξ“ A β†’ Tm53 Ξ“ A := Ξ» x Tm53 var53 lam app => var53 _ _ x def lam53 {Ξ“ A B} : Tm53 (snoc53 Ξ“ A) B β†’ Tm53 Ξ“ (arr53 A B) := Ξ» t Tm53 var53 lam53 app => lam53 _ _ _ (t Tm53 var53 lam53 app) def app53 {Ξ“ A B} : Tm53 Ξ“ (arr53 A B) β†’ Tm53 Ξ“ A β†’ Tm53 Ξ“ B := Ξ» t u Tm53 var53 lam53 app53 => app53 _ _ _ (t Tm53 var53 lam53 app53) (u Tm53 var53 lam53 app53) def v053 {Ξ“ A} : Tm53 (snoc53 Ξ“ A) A := var53 vz53 def v153 {Ξ“ A B} : Tm53 (snoc53 (snoc53 Ξ“ A) B) A := var53 (vs53 vz53) def v253 {Ξ“ A B C} : Tm53 (snoc53 (snoc53 (snoc53 Ξ“ A) B) C) A := var53 (vs53 (vs53 vz53)) def v353 {Ξ“ A B C D} : Tm53 (snoc53 (snoc53 (snoc53 (snoc53 Ξ“ A) B) C) D) A := var53 (vs53 (vs53 (vs53 vz53))) def v453 {Ξ“ A B C D E} : Tm53 (snoc53 (snoc53 (snoc53 (snoc53 (snoc53 Ξ“ A) B) C) D) E) A := var53 (vs53 (vs53 (vs53 (vs53 vz53)))) def test53 {Ξ“ A} : Tm53 Ξ“ (arr53 (arr53 A A) (arr53 A A)) := lam53 (lam53 (app53 v153 (app53 v153 (app53 v153 (app53 v153 (app53 v153 (app53 v153 v053))))))) def Ty54 : Type 1 := βˆ€ (Ty54 : Type) (ΞΉ : Ty54) (arr : Ty54 β†’ Ty54 β†’ Ty54) , Ty54 def ΞΉ54 : Ty54 := Ξ» _ ΞΉ54 _ => ΞΉ54 def arr54 : Ty54 β†’ Ty54 β†’ Ty54 := Ξ» A B Ty54 ΞΉ54 arr54 => arr54 (A Ty54 ΞΉ54 arr54) (B Ty54 ΞΉ54 arr54) def Con54 : Type 1 := βˆ€ (Con54 : Type) (nil : Con54) (snoc : Con54 β†’ Ty54 β†’ Con54) , Con54 def nil54 : Con54 := Ξ» Con54 nil54 snoc => nil54 def snoc54 : Con54 β†’ Ty54 β†’ Con54 := Ξ» Ξ“ A Con54 nil54 snoc54 => snoc54 (Ξ“ Con54 nil54 snoc54) A def Var54 : Con54 β†’ Ty54 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var54 : Con54 β†’ Ty54 β†’ Type) (vz : βˆ€ Ξ“ A, Var54 (snoc54 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var54 Ξ“ A β†’ Var54 (snoc54 Ξ“ B) A) , Var54 Ξ“ A def vz54 {Ξ“ A} : Var54 (snoc54 Ξ“ A) A := Ξ» Var54 vz54 vs => vz54 _ _ def vs54 {Ξ“ B A} : Var54 Ξ“ A β†’ Var54 (snoc54 Ξ“ B) A := Ξ» x Var54 vz54 vs54 => vs54 _ _ _ (x Var54 vz54 vs54) def Tm54 : Con54 β†’ Ty54 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm54 : Con54 β†’ Ty54 β†’ Type) (var : βˆ€ Ξ“ A , Var54 Ξ“ A β†’ Tm54 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm54 (snoc54 Ξ“ A) B β†’ Tm54 Ξ“ (arr54 A B)) (app : βˆ€ Ξ“ A B , Tm54 Ξ“ (arr54 A B) β†’ Tm54 Ξ“ A β†’ Tm54 Ξ“ B) , Tm54 Ξ“ A def var54 {Ξ“ A} : Var54 Ξ“ A β†’ Tm54 Ξ“ A := Ξ» x Tm54 var54 lam app => var54 _ _ x def lam54 {Ξ“ A B} : Tm54 (snoc54 Ξ“ A) B β†’ Tm54 Ξ“ (arr54 A B) := Ξ» t Tm54 var54 lam54 app => lam54 _ _ _ (t Tm54 var54 lam54 app) def app54 {Ξ“ A B} : Tm54 Ξ“ (arr54 A B) β†’ Tm54 Ξ“ A β†’ Tm54 Ξ“ B := Ξ» t u Tm54 var54 lam54 app54 => app54 _ _ _ (t Tm54 var54 lam54 app54) (u Tm54 var54 lam54 app54) def v054 {Ξ“ A} : Tm54 (snoc54 Ξ“ A) A := var54 vz54 def v154 {Ξ“ A B} : Tm54 (snoc54 (snoc54 Ξ“ A) B) A := var54 (vs54 vz54) def v254 {Ξ“ A B C} : Tm54 (snoc54 (snoc54 (snoc54 Ξ“ A) B) C) A := var54 (vs54 (vs54 vz54)) def v354 {Ξ“ A B C D} : Tm54 (snoc54 (snoc54 (snoc54 (snoc54 Ξ“ A) B) C) D) A := var54 (vs54 (vs54 (vs54 vz54))) def v454 {Ξ“ A B C D E} : Tm54 (snoc54 (snoc54 (snoc54 (snoc54 (snoc54 Ξ“ A) B) C) D) E) A := var54 (vs54 (vs54 (vs54 (vs54 vz54)))) def test54 {Ξ“ A} : Tm54 Ξ“ (arr54 (arr54 A A) (arr54 A A)) := lam54 (lam54 (app54 v154 (app54 v154 (app54 v154 (app54 v154 (app54 v154 (app54 v154 v054))))))) def Ty55 : Type 1 := βˆ€ (Ty55 : Type) (ΞΉ : Ty55) (arr : Ty55 β†’ Ty55 β†’ Ty55) , Ty55 def ΞΉ55 : Ty55 := Ξ» _ ΞΉ55 _ => ΞΉ55 def arr55 : Ty55 β†’ Ty55 β†’ Ty55 := Ξ» A B Ty55 ΞΉ55 arr55 => arr55 (A Ty55 ΞΉ55 arr55) (B Ty55 ΞΉ55 arr55) def Con55 : Type 1 := βˆ€ (Con55 : Type) (nil : Con55) (snoc : Con55 β†’ Ty55 β†’ Con55) , Con55 def nil55 : Con55 := Ξ» Con55 nil55 snoc => nil55 def snoc55 : Con55 β†’ Ty55 β†’ Con55 := Ξ» Ξ“ A Con55 nil55 snoc55 => snoc55 (Ξ“ Con55 nil55 snoc55) A def Var55 : Con55 β†’ Ty55 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var55 : Con55 β†’ Ty55 β†’ Type) (vz : βˆ€ Ξ“ A, Var55 (snoc55 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var55 Ξ“ A β†’ Var55 (snoc55 Ξ“ B) A) , Var55 Ξ“ A def vz55 {Ξ“ A} : Var55 (snoc55 Ξ“ A) A := Ξ» Var55 vz55 vs => vz55 _ _ def vs55 {Ξ“ B A} : Var55 Ξ“ A β†’ Var55 (snoc55 Ξ“ B) A := Ξ» x Var55 vz55 vs55 => vs55 _ _ _ (x Var55 vz55 vs55) def Tm55 : Con55 β†’ Ty55 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm55 : Con55 β†’ Ty55 β†’ Type) (var : βˆ€ Ξ“ A , Var55 Ξ“ A β†’ Tm55 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm55 (snoc55 Ξ“ A) B β†’ Tm55 Ξ“ (arr55 A B)) (app : βˆ€ Ξ“ A B , Tm55 Ξ“ (arr55 A B) β†’ Tm55 Ξ“ A β†’ Tm55 Ξ“ B) , Tm55 Ξ“ A def var55 {Ξ“ A} : Var55 Ξ“ A β†’ Tm55 Ξ“ A := Ξ» x Tm55 var55 lam app => var55 _ _ x def lam55 {Ξ“ A B} : Tm55 (snoc55 Ξ“ A) B β†’ Tm55 Ξ“ (arr55 A B) := Ξ» t Tm55 var55 lam55 app => lam55 _ _ _ (t Tm55 var55 lam55 app) def app55 {Ξ“ A B} : Tm55 Ξ“ (arr55 A B) β†’ Tm55 Ξ“ A β†’ Tm55 Ξ“ B := Ξ» t u Tm55 var55 lam55 app55 => app55 _ _ _ (t Tm55 var55 lam55 app55) (u Tm55 var55 lam55 app55) def v055 {Ξ“ A} : Tm55 (snoc55 Ξ“ A) A := var55 vz55 def v155 {Ξ“ A B} : Tm55 (snoc55 (snoc55 Ξ“ A) B) A := var55 (vs55 vz55) def v255 {Ξ“ A B C} : Tm55 (snoc55 (snoc55 (snoc55 Ξ“ A) B) C) A := var55 (vs55 (vs55 vz55)) def v355 {Ξ“ A B C D} : Tm55 (snoc55 (snoc55 (snoc55 (snoc55 Ξ“ A) B) C) D) A := var55 (vs55 (vs55 (vs55 vz55))) def v455 {Ξ“ A B C D E} : Tm55 (snoc55 (snoc55 (snoc55 (snoc55 (snoc55 Ξ“ A) B) C) D) E) A := var55 (vs55 (vs55 (vs55 (vs55 vz55)))) def test55 {Ξ“ A} : Tm55 Ξ“ (arr55 (arr55 A A) (arr55 A A)) := lam55 (lam55 (app55 v155 (app55 v155 (app55 v155 (app55 v155 (app55 v155 (app55 v155 v055))))))) def Ty56 : Type 1 := βˆ€ (Ty56 : Type) (ΞΉ : Ty56) (arr : Ty56 β†’ Ty56 β†’ Ty56) , Ty56 def ΞΉ56 : Ty56 := Ξ» _ ΞΉ56 _ => ΞΉ56 def arr56 : Ty56 β†’ Ty56 β†’ Ty56 := Ξ» A B Ty56 ΞΉ56 arr56 => arr56 (A Ty56 ΞΉ56 arr56) (B Ty56 ΞΉ56 arr56) def Con56 : Type 1 := βˆ€ (Con56 : Type) (nil : Con56) (snoc : Con56 β†’ Ty56 β†’ Con56) , Con56 def nil56 : Con56 := Ξ» Con56 nil56 snoc => nil56 def snoc56 : Con56 β†’ Ty56 β†’ Con56 := Ξ» Ξ“ A Con56 nil56 snoc56 => snoc56 (Ξ“ Con56 nil56 snoc56) A def Var56 : Con56 β†’ Ty56 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var56 : Con56 β†’ Ty56 β†’ Type) (vz : βˆ€ Ξ“ A, Var56 (snoc56 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var56 Ξ“ A β†’ Var56 (snoc56 Ξ“ B) A) , Var56 Ξ“ A def vz56 {Ξ“ A} : Var56 (snoc56 Ξ“ A) A := Ξ» Var56 vz56 vs => vz56 _ _ def vs56 {Ξ“ B A} : Var56 Ξ“ A β†’ Var56 (snoc56 Ξ“ B) A := Ξ» x Var56 vz56 vs56 => vs56 _ _ _ (x Var56 vz56 vs56) def Tm56 : Con56 β†’ Ty56 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm56 : Con56 β†’ Ty56 β†’ Type) (var : βˆ€ Ξ“ A , Var56 Ξ“ A β†’ Tm56 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm56 (snoc56 Ξ“ A) B β†’ Tm56 Ξ“ (arr56 A B)) (app : βˆ€ Ξ“ A B , Tm56 Ξ“ (arr56 A B) β†’ Tm56 Ξ“ A β†’ Tm56 Ξ“ B) , Tm56 Ξ“ A def var56 {Ξ“ A} : Var56 Ξ“ A β†’ Tm56 Ξ“ A := Ξ» x Tm56 var56 lam app => var56 _ _ x def lam56 {Ξ“ A B} : Tm56 (snoc56 Ξ“ A) B β†’ Tm56 Ξ“ (arr56 A B) := Ξ» t Tm56 var56 lam56 app => lam56 _ _ _ (t Tm56 var56 lam56 app) def app56 {Ξ“ A B} : Tm56 Ξ“ (arr56 A B) β†’ Tm56 Ξ“ A β†’ Tm56 Ξ“ B := Ξ» t u Tm56 var56 lam56 app56 => app56 _ _ _ (t Tm56 var56 lam56 app56) (u Tm56 var56 lam56 app56) def v056 {Ξ“ A} : Tm56 (snoc56 Ξ“ A) A := var56 vz56 def v156 {Ξ“ A B} : Tm56 (snoc56 (snoc56 Ξ“ A) B) A := var56 (vs56 vz56) def v256 {Ξ“ A B C} : Tm56 (snoc56 (snoc56 (snoc56 Ξ“ A) B) C) A := var56 (vs56 (vs56 vz56)) def v356 {Ξ“ A B C D} : Tm56 (snoc56 (snoc56 (snoc56 (snoc56 Ξ“ A) B) C) D) A := var56 (vs56 (vs56 (vs56 vz56))) def v456 {Ξ“ A B C D E} : Tm56 (snoc56 (snoc56 (snoc56 (snoc56 (snoc56 Ξ“ A) B) C) D) E) A := var56 (vs56 (vs56 (vs56 (vs56 vz56)))) def test56 {Ξ“ A} : Tm56 Ξ“ (arr56 (arr56 A A) (arr56 A A)) := lam56 (lam56 (app56 v156 (app56 v156 (app56 v156 (app56 v156 (app56 v156 (app56 v156 v056))))))) def Ty57 : Type 1 := βˆ€ (Ty57 : Type) (ΞΉ : Ty57) (arr : Ty57 β†’ Ty57 β†’ Ty57) , Ty57 def ΞΉ57 : Ty57 := Ξ» _ ΞΉ57 _ => ΞΉ57 def arr57 : Ty57 β†’ Ty57 β†’ Ty57 := Ξ» A B Ty57 ΞΉ57 arr57 => arr57 (A Ty57 ΞΉ57 arr57) (B Ty57 ΞΉ57 arr57) def Con57 : Type 1 := βˆ€ (Con57 : Type) (nil : Con57) (snoc : Con57 β†’ Ty57 β†’ Con57) , Con57 def nil57 : Con57 := Ξ» Con57 nil57 snoc => nil57 def snoc57 : Con57 β†’ Ty57 β†’ Con57 := Ξ» Ξ“ A Con57 nil57 snoc57 => snoc57 (Ξ“ Con57 nil57 snoc57) A def Var57 : Con57 β†’ Ty57 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var57 : Con57 β†’ Ty57 β†’ Type) (vz : βˆ€ Ξ“ A, Var57 (snoc57 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var57 Ξ“ A β†’ Var57 (snoc57 Ξ“ B) A) , Var57 Ξ“ A def vz57 {Ξ“ A} : Var57 (snoc57 Ξ“ A) A := Ξ» Var57 vz57 vs => vz57 _ _ def vs57 {Ξ“ B A} : Var57 Ξ“ A β†’ Var57 (snoc57 Ξ“ B) A := Ξ» x Var57 vz57 vs57 => vs57 _ _ _ (x Var57 vz57 vs57) def Tm57 : Con57 β†’ Ty57 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm57 : Con57 β†’ Ty57 β†’ Type) (var : βˆ€ Ξ“ A , Var57 Ξ“ A β†’ Tm57 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm57 (snoc57 Ξ“ A) B β†’ Tm57 Ξ“ (arr57 A B)) (app : βˆ€ Ξ“ A B , Tm57 Ξ“ (arr57 A B) β†’ Tm57 Ξ“ A β†’ Tm57 Ξ“ B) , Tm57 Ξ“ A def var57 {Ξ“ A} : Var57 Ξ“ A β†’ Tm57 Ξ“ A := Ξ» x Tm57 var57 lam app => var57 _ _ x def lam57 {Ξ“ A B} : Tm57 (snoc57 Ξ“ A) B β†’ Tm57 Ξ“ (arr57 A B) := Ξ» t Tm57 var57 lam57 app => lam57 _ _ _ (t Tm57 var57 lam57 app) def app57 {Ξ“ A B} : Tm57 Ξ“ (arr57 A B) β†’ Tm57 Ξ“ A β†’ Tm57 Ξ“ B := Ξ» t u Tm57 var57 lam57 app57 => app57 _ _ _ (t Tm57 var57 lam57 app57) (u Tm57 var57 lam57 app57) def v057 {Ξ“ A} : Tm57 (snoc57 Ξ“ A) A := var57 vz57 def v157 {Ξ“ A B} : Tm57 (snoc57 (snoc57 Ξ“ A) B) A := var57 (vs57 vz57) def v257 {Ξ“ A B C} : Tm57 (snoc57 (snoc57 (snoc57 Ξ“ A) B) C) A := var57 (vs57 (vs57 vz57)) def v357 {Ξ“ A B C D} : Tm57 (snoc57 (snoc57 (snoc57 (snoc57 Ξ“ A) B) C) D) A := var57 (vs57 (vs57 (vs57 vz57))) def v457 {Ξ“ A B C D E} : Tm57 (snoc57 (snoc57 (snoc57 (snoc57 (snoc57 Ξ“ A) B) C) D) E) A := var57 (vs57 (vs57 (vs57 (vs57 vz57)))) def test57 {Ξ“ A} : Tm57 Ξ“ (arr57 (arr57 A A) (arr57 A A)) := lam57 (lam57 (app57 v157 (app57 v157 (app57 v157 (app57 v157 (app57 v157 (app57 v157 v057))))))) def Ty58 : Type 1 := βˆ€ (Ty58 : Type) (ΞΉ : Ty58) (arr : Ty58 β†’ Ty58 β†’ Ty58) , Ty58 def ΞΉ58 : Ty58 := Ξ» _ ΞΉ58 _ => ΞΉ58 def arr58 : Ty58 β†’ Ty58 β†’ Ty58 := Ξ» A B Ty58 ΞΉ58 arr58 => arr58 (A Ty58 ΞΉ58 arr58) (B Ty58 ΞΉ58 arr58) def Con58 : Type 1 := βˆ€ (Con58 : Type) (nil : Con58) (snoc : Con58 β†’ Ty58 β†’ Con58) , Con58 def nil58 : Con58 := Ξ» Con58 nil58 snoc => nil58 def snoc58 : Con58 β†’ Ty58 β†’ Con58 := Ξ» Ξ“ A Con58 nil58 snoc58 => snoc58 (Ξ“ Con58 nil58 snoc58) A def Var58 : Con58 β†’ Ty58 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var58 : Con58 β†’ Ty58 β†’ Type) (vz : βˆ€ Ξ“ A, Var58 (snoc58 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var58 Ξ“ A β†’ Var58 (snoc58 Ξ“ B) A) , Var58 Ξ“ A def vz58 {Ξ“ A} : Var58 (snoc58 Ξ“ A) A := Ξ» Var58 vz58 vs => vz58 _ _ def vs58 {Ξ“ B A} : Var58 Ξ“ A β†’ Var58 (snoc58 Ξ“ B) A := Ξ» x Var58 vz58 vs58 => vs58 _ _ _ (x Var58 vz58 vs58) def Tm58 : Con58 β†’ Ty58 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm58 : Con58 β†’ Ty58 β†’ Type) (var : βˆ€ Ξ“ A , Var58 Ξ“ A β†’ Tm58 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm58 (snoc58 Ξ“ A) B β†’ Tm58 Ξ“ (arr58 A B)) (app : βˆ€ Ξ“ A B , Tm58 Ξ“ (arr58 A B) β†’ Tm58 Ξ“ A β†’ Tm58 Ξ“ B) , Tm58 Ξ“ A def var58 {Ξ“ A} : Var58 Ξ“ A β†’ Tm58 Ξ“ A := Ξ» x Tm58 var58 lam app => var58 _ _ x def lam58 {Ξ“ A B} : Tm58 (snoc58 Ξ“ A) B β†’ Tm58 Ξ“ (arr58 A B) := Ξ» t Tm58 var58 lam58 app => lam58 _ _ _ (t Tm58 var58 lam58 app) def app58 {Ξ“ A B} : Tm58 Ξ“ (arr58 A B) β†’ Tm58 Ξ“ A β†’ Tm58 Ξ“ B := Ξ» t u Tm58 var58 lam58 app58 => app58 _ _ _ (t Tm58 var58 lam58 app58) (u Tm58 var58 lam58 app58) def v058 {Ξ“ A} : Tm58 (snoc58 Ξ“ A) A := var58 vz58 def v158 {Ξ“ A B} : Tm58 (snoc58 (snoc58 Ξ“ A) B) A := var58 (vs58 vz58) def v258 {Ξ“ A B C} : Tm58 (snoc58 (snoc58 (snoc58 Ξ“ A) B) C) A := var58 (vs58 (vs58 vz58)) def v358 {Ξ“ A B C D} : Tm58 (snoc58 (snoc58 (snoc58 (snoc58 Ξ“ A) B) C) D) A := var58 (vs58 (vs58 (vs58 vz58))) def v458 {Ξ“ A B C D E} : Tm58 (snoc58 (snoc58 (snoc58 (snoc58 (snoc58 Ξ“ A) B) C) D) E) A := var58 (vs58 (vs58 (vs58 (vs58 vz58)))) def test58 {Ξ“ A} : Tm58 Ξ“ (arr58 (arr58 A A) (arr58 A A)) := lam58 (lam58 (app58 v158 (app58 v158 (app58 v158 (app58 v158 (app58 v158 (app58 v158 v058))))))) def Ty59 : Type 1 := βˆ€ (Ty59 : Type) (ΞΉ : Ty59) (arr : Ty59 β†’ Ty59 β†’ Ty59) , Ty59 def ΞΉ59 : Ty59 := Ξ» _ ΞΉ59 _ => ΞΉ59 def arr59 : Ty59 β†’ Ty59 β†’ Ty59 := Ξ» A B Ty59 ΞΉ59 arr59 => arr59 (A Ty59 ΞΉ59 arr59) (B Ty59 ΞΉ59 arr59) def Con59 : Type 1 := βˆ€ (Con59 : Type) (nil : Con59) (snoc : Con59 β†’ Ty59 β†’ Con59) , Con59 def nil59 : Con59 := Ξ» Con59 nil59 snoc => nil59 def snoc59 : Con59 β†’ Ty59 β†’ Con59 := Ξ» Ξ“ A Con59 nil59 snoc59 => snoc59 (Ξ“ Con59 nil59 snoc59) A def Var59 : Con59 β†’ Ty59 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var59 : Con59 β†’ Ty59 β†’ Type) (vz : βˆ€ Ξ“ A, Var59 (snoc59 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var59 Ξ“ A β†’ Var59 (snoc59 Ξ“ B) A) , Var59 Ξ“ A def vz59 {Ξ“ A} : Var59 (snoc59 Ξ“ A) A := Ξ» Var59 vz59 vs => vz59 _ _ def vs59 {Ξ“ B A} : Var59 Ξ“ A β†’ Var59 (snoc59 Ξ“ B) A := Ξ» x Var59 vz59 vs59 => vs59 _ _ _ (x Var59 vz59 vs59) def Tm59 : Con59 β†’ Ty59 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm59 : Con59 β†’ Ty59 β†’ Type) (var : βˆ€ Ξ“ A , Var59 Ξ“ A β†’ Tm59 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm59 (snoc59 Ξ“ A) B β†’ Tm59 Ξ“ (arr59 A B)) (app : βˆ€ Ξ“ A B , Tm59 Ξ“ (arr59 A B) β†’ Tm59 Ξ“ A β†’ Tm59 Ξ“ B) , Tm59 Ξ“ A def var59 {Ξ“ A} : Var59 Ξ“ A β†’ Tm59 Ξ“ A := Ξ» x Tm59 var59 lam app => var59 _ _ x def lam59 {Ξ“ A B} : Tm59 (snoc59 Ξ“ A) B β†’ Tm59 Ξ“ (arr59 A B) := Ξ» t Tm59 var59 lam59 app => lam59 _ _ _ (t Tm59 var59 lam59 app) def app59 {Ξ“ A B} : Tm59 Ξ“ (arr59 A B) β†’ Tm59 Ξ“ A β†’ Tm59 Ξ“ B := Ξ» t u Tm59 var59 lam59 app59 => app59 _ _ _ (t Tm59 var59 lam59 app59) (u Tm59 var59 lam59 app59) def v059 {Ξ“ A} : Tm59 (snoc59 Ξ“ A) A := var59 vz59 def v159 {Ξ“ A B} : Tm59 (snoc59 (snoc59 Ξ“ A) B) A := var59 (vs59 vz59) def v259 {Ξ“ A B C} : Tm59 (snoc59 (snoc59 (snoc59 Ξ“ A) B) C) A := var59 (vs59 (vs59 vz59)) def v359 {Ξ“ A B C D} : Tm59 (snoc59 (snoc59 (snoc59 (snoc59 Ξ“ A) B) C) D) A := var59 (vs59 (vs59 (vs59 vz59))) def v459 {Ξ“ A B C D E} : Tm59 (snoc59 (snoc59 (snoc59 (snoc59 (snoc59 Ξ“ A) B) C) D) E) A := var59 (vs59 (vs59 (vs59 (vs59 vz59)))) def test59 {Ξ“ A} : Tm59 Ξ“ (arr59 (arr59 A A) (arr59 A A)) := lam59 (lam59 (app59 v159 (app59 v159 (app59 v159 (app59 v159 (app59 v159 (app59 v159 v059))))))) def Ty60 : Type 1 := βˆ€ (Ty60 : Type) (ΞΉ : Ty60) (arr : Ty60 β†’ Ty60 β†’ Ty60) , Ty60 def ΞΉ60 : Ty60 := Ξ» _ ΞΉ60 _ => ΞΉ60 def arr60 : Ty60 β†’ Ty60 β†’ Ty60 := Ξ» A B Ty60 ΞΉ60 arr60 => arr60 (A Ty60 ΞΉ60 arr60) (B Ty60 ΞΉ60 arr60) def Con60 : Type 1 := βˆ€ (Con60 : Type) (nil : Con60) (snoc : Con60 β†’ Ty60 β†’ Con60) , Con60 def nil60 : Con60 := Ξ» Con60 nil60 snoc => nil60 def snoc60 : Con60 β†’ Ty60 β†’ Con60 := Ξ» Ξ“ A Con60 nil60 snoc60 => snoc60 (Ξ“ Con60 nil60 snoc60) A def Var60 : Con60 β†’ Ty60 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var60 : Con60 β†’ Ty60 β†’ Type) (vz : βˆ€ Ξ“ A, Var60 (snoc60 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var60 Ξ“ A β†’ Var60 (snoc60 Ξ“ B) A) , Var60 Ξ“ A def vz60 {Ξ“ A} : Var60 (snoc60 Ξ“ A) A := Ξ» Var60 vz60 vs => vz60 _ _ def vs60 {Ξ“ B A} : Var60 Ξ“ A β†’ Var60 (snoc60 Ξ“ B) A := Ξ» x Var60 vz60 vs60 => vs60 _ _ _ (x Var60 vz60 vs60) def Tm60 : Con60 β†’ Ty60 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm60 : Con60 β†’ Ty60 β†’ Type) (var : βˆ€ Ξ“ A , Var60 Ξ“ A β†’ Tm60 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm60 (snoc60 Ξ“ A) B β†’ Tm60 Ξ“ (arr60 A B)) (app : βˆ€ Ξ“ A B , Tm60 Ξ“ (arr60 A B) β†’ Tm60 Ξ“ A β†’ Tm60 Ξ“ B) , Tm60 Ξ“ A def var60 {Ξ“ A} : Var60 Ξ“ A β†’ Tm60 Ξ“ A := Ξ» x Tm60 var60 lam app => var60 _ _ x def lam60 {Ξ“ A B} : Tm60 (snoc60 Ξ“ A) B β†’ Tm60 Ξ“ (arr60 A B) := Ξ» t Tm60 var60 lam60 app => lam60 _ _ _ (t Tm60 var60 lam60 app) def app60 {Ξ“ A B} : Tm60 Ξ“ (arr60 A B) β†’ Tm60 Ξ“ A β†’ Tm60 Ξ“ B := Ξ» t u Tm60 var60 lam60 app60 => app60 _ _ _ (t Tm60 var60 lam60 app60) (u Tm60 var60 lam60 app60) def v060 {Ξ“ A} : Tm60 (snoc60 Ξ“ A) A := var60 vz60 def v160 {Ξ“ A B} : Tm60 (snoc60 (snoc60 Ξ“ A) B) A := var60 (vs60 vz60) def v260 {Ξ“ A B C} : Tm60 (snoc60 (snoc60 (snoc60 Ξ“ A) B) C) A := var60 (vs60 (vs60 vz60)) def v360 {Ξ“ A B C D} : Tm60 (snoc60 (snoc60 (snoc60 (snoc60 Ξ“ A) B) C) D) A := var60 (vs60 (vs60 (vs60 vz60))) def v460 {Ξ“ A B C D E} : Tm60 (snoc60 (snoc60 (snoc60 (snoc60 (snoc60 Ξ“ A) B) C) D) E) A := var60 (vs60 (vs60 (vs60 (vs60 vz60)))) def test60 {Ξ“ A} : Tm60 Ξ“ (arr60 (arr60 A A) (arr60 A A)) := lam60 (lam60 (app60 v160 (app60 v160 (app60 v160 (app60 v160 (app60 v160 (app60 v160 v060))))))) def Ty61 : Type 1 := βˆ€ (Ty61 : Type) (ΞΉ : Ty61) (arr : Ty61 β†’ Ty61 β†’ Ty61) , Ty61 def ΞΉ61 : Ty61 := Ξ» _ ΞΉ61 _ => ΞΉ61 def arr61 : Ty61 β†’ Ty61 β†’ Ty61 := Ξ» A B Ty61 ΞΉ61 arr61 => arr61 (A Ty61 ΞΉ61 arr61) (B Ty61 ΞΉ61 arr61) def Con61 : Type 1 := βˆ€ (Con61 : Type) (nil : Con61) (snoc : Con61 β†’ Ty61 β†’ Con61) , Con61 def nil61 : Con61 := Ξ» Con61 nil61 snoc => nil61 def snoc61 : Con61 β†’ Ty61 β†’ Con61 := Ξ» Ξ“ A Con61 nil61 snoc61 => snoc61 (Ξ“ Con61 nil61 snoc61) A def Var61 : Con61 β†’ Ty61 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var61 : Con61 β†’ Ty61 β†’ Type) (vz : βˆ€ Ξ“ A, Var61 (snoc61 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var61 Ξ“ A β†’ Var61 (snoc61 Ξ“ B) A) , Var61 Ξ“ A def vz61 {Ξ“ A} : Var61 (snoc61 Ξ“ A) A := Ξ» Var61 vz61 vs => vz61 _ _ def vs61 {Ξ“ B A} : Var61 Ξ“ A β†’ Var61 (snoc61 Ξ“ B) A := Ξ» x Var61 vz61 vs61 => vs61 _ _ _ (x Var61 vz61 vs61) def Tm61 : Con61 β†’ Ty61 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm61 : Con61 β†’ Ty61 β†’ Type) (var : βˆ€ Ξ“ A , Var61 Ξ“ A β†’ Tm61 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm61 (snoc61 Ξ“ A) B β†’ Tm61 Ξ“ (arr61 A B)) (app : βˆ€ Ξ“ A B , Tm61 Ξ“ (arr61 A B) β†’ Tm61 Ξ“ A β†’ Tm61 Ξ“ B) , Tm61 Ξ“ A def var61 {Ξ“ A} : Var61 Ξ“ A β†’ Tm61 Ξ“ A := Ξ» x Tm61 var61 lam app => var61 _ _ x def lam61 {Ξ“ A B} : Tm61 (snoc61 Ξ“ A) B β†’ Tm61 Ξ“ (arr61 A B) := Ξ» t Tm61 var61 lam61 app => lam61 _ _ _ (t Tm61 var61 lam61 app) def app61 {Ξ“ A B} : Tm61 Ξ“ (arr61 A B) β†’ Tm61 Ξ“ A β†’ Tm61 Ξ“ B := Ξ» t u Tm61 var61 lam61 app61 => app61 _ _ _ (t Tm61 var61 lam61 app61) (u Tm61 var61 lam61 app61) def v061 {Ξ“ A} : Tm61 (snoc61 Ξ“ A) A := var61 vz61 def v161 {Ξ“ A B} : Tm61 (snoc61 (snoc61 Ξ“ A) B) A := var61 (vs61 vz61) def v261 {Ξ“ A B C} : Tm61 (snoc61 (snoc61 (snoc61 Ξ“ A) B) C) A := var61 (vs61 (vs61 vz61)) def v361 {Ξ“ A B C D} : Tm61 (snoc61 (snoc61 (snoc61 (snoc61 Ξ“ A) B) C) D) A := var61 (vs61 (vs61 (vs61 vz61))) def v461 {Ξ“ A B C D E} : Tm61 (snoc61 (snoc61 (snoc61 (snoc61 (snoc61 Ξ“ A) B) C) D) E) A := var61 (vs61 (vs61 (vs61 (vs61 vz61)))) def test61 {Ξ“ A} : Tm61 Ξ“ (arr61 (arr61 A A) (arr61 A A)) := lam61 (lam61 (app61 v161 (app61 v161 (app61 v161 (app61 v161 (app61 v161 (app61 v161 v061))))))) def Ty62 : Type 1 := βˆ€ (Ty62 : Type) (ΞΉ : Ty62) (arr : Ty62 β†’ Ty62 β†’ Ty62) , Ty62 def ΞΉ62 : Ty62 := Ξ» _ ΞΉ62 _ => ΞΉ62 def arr62 : Ty62 β†’ Ty62 β†’ Ty62 := Ξ» A B Ty62 ΞΉ62 arr62 => arr62 (A Ty62 ΞΉ62 arr62) (B Ty62 ΞΉ62 arr62) def Con62 : Type 1 := βˆ€ (Con62 : Type) (nil : Con62) (snoc : Con62 β†’ Ty62 β†’ Con62) , Con62 def nil62 : Con62 := Ξ» Con62 nil62 snoc => nil62 def snoc62 : Con62 β†’ Ty62 β†’ Con62 := Ξ» Ξ“ A Con62 nil62 snoc62 => snoc62 (Ξ“ Con62 nil62 snoc62) A def Var62 : Con62 β†’ Ty62 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var62 : Con62 β†’ Ty62 β†’ Type) (vz : βˆ€ Ξ“ A, Var62 (snoc62 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var62 Ξ“ A β†’ Var62 (snoc62 Ξ“ B) A) , Var62 Ξ“ A def vz62 {Ξ“ A} : Var62 (snoc62 Ξ“ A) A := Ξ» Var62 vz62 vs => vz62 _ _ def vs62 {Ξ“ B A} : Var62 Ξ“ A β†’ Var62 (snoc62 Ξ“ B) A := Ξ» x Var62 vz62 vs62 => vs62 _ _ _ (x Var62 vz62 vs62) def Tm62 : Con62 β†’ Ty62 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm62 : Con62 β†’ Ty62 β†’ Type) (var : βˆ€ Ξ“ A , Var62 Ξ“ A β†’ Tm62 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm62 (snoc62 Ξ“ A) B β†’ Tm62 Ξ“ (arr62 A B)) (app : βˆ€ Ξ“ A B , Tm62 Ξ“ (arr62 A B) β†’ Tm62 Ξ“ A β†’ Tm62 Ξ“ B) , Tm62 Ξ“ A def var62 {Ξ“ A} : Var62 Ξ“ A β†’ Tm62 Ξ“ A := Ξ» x Tm62 var62 lam app => var62 _ _ x def lam62 {Ξ“ A B} : Tm62 (snoc62 Ξ“ A) B β†’ Tm62 Ξ“ (arr62 A B) := Ξ» t Tm62 var62 lam62 app => lam62 _ _ _ (t Tm62 var62 lam62 app) def app62 {Ξ“ A B} : Tm62 Ξ“ (arr62 A B) β†’ Tm62 Ξ“ A β†’ Tm62 Ξ“ B := Ξ» t u Tm62 var62 lam62 app62 => app62 _ _ _ (t Tm62 var62 lam62 app62) (u Tm62 var62 lam62 app62) def v062 {Ξ“ A} : Tm62 (snoc62 Ξ“ A) A := var62 vz62 def v162 {Ξ“ A B} : Tm62 (snoc62 (snoc62 Ξ“ A) B) A := var62 (vs62 vz62) def v262 {Ξ“ A B C} : Tm62 (snoc62 (snoc62 (snoc62 Ξ“ A) B) C) A := var62 (vs62 (vs62 vz62)) def v362 {Ξ“ A B C D} : Tm62 (snoc62 (snoc62 (snoc62 (snoc62 Ξ“ A) B) C) D) A := var62 (vs62 (vs62 (vs62 vz62))) def v462 {Ξ“ A B C D E} : Tm62 (snoc62 (snoc62 (snoc62 (snoc62 (snoc62 Ξ“ A) B) C) D) E) A := var62 (vs62 (vs62 (vs62 (vs62 vz62)))) def test62 {Ξ“ A} : Tm62 Ξ“ (arr62 (arr62 A A) (arr62 A A)) := lam62 (lam62 (app62 v162 (app62 v162 (app62 v162 (app62 v162 (app62 v162 (app62 v162 v062))))))) def Ty63 : Type 1 := βˆ€ (Ty63 : Type) (ΞΉ : Ty63) (arr : Ty63 β†’ Ty63 β†’ Ty63) , Ty63 def ΞΉ63 : Ty63 := Ξ» _ ΞΉ63 _ => ΞΉ63 def arr63 : Ty63 β†’ Ty63 β†’ Ty63 := Ξ» A B Ty63 ΞΉ63 arr63 => arr63 (A Ty63 ΞΉ63 arr63) (B Ty63 ΞΉ63 arr63) def Con63 : Type 1 := βˆ€ (Con63 : Type) (nil : Con63) (snoc : Con63 β†’ Ty63 β†’ Con63) , Con63 def nil63 : Con63 := Ξ» Con63 nil63 snoc => nil63 def snoc63 : Con63 β†’ Ty63 β†’ Con63 := Ξ» Ξ“ A Con63 nil63 snoc63 => snoc63 (Ξ“ Con63 nil63 snoc63) A def Var63 : Con63 β†’ Ty63 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var63 : Con63 β†’ Ty63 β†’ Type) (vz : βˆ€ Ξ“ A, Var63 (snoc63 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var63 Ξ“ A β†’ Var63 (snoc63 Ξ“ B) A) , Var63 Ξ“ A def vz63 {Ξ“ A} : Var63 (snoc63 Ξ“ A) A := Ξ» Var63 vz63 vs => vz63 _ _ def vs63 {Ξ“ B A} : Var63 Ξ“ A β†’ Var63 (snoc63 Ξ“ B) A := Ξ» x Var63 vz63 vs63 => vs63 _ _ _ (x Var63 vz63 vs63) def Tm63 : Con63 β†’ Ty63 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm63 : Con63 β†’ Ty63 β†’ Type) (var : βˆ€ Ξ“ A , Var63 Ξ“ A β†’ Tm63 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm63 (snoc63 Ξ“ A) B β†’ Tm63 Ξ“ (arr63 A B)) (app : βˆ€ Ξ“ A B , Tm63 Ξ“ (arr63 A B) β†’ Tm63 Ξ“ A β†’ Tm63 Ξ“ B) , Tm63 Ξ“ A def var63 {Ξ“ A} : Var63 Ξ“ A β†’ Tm63 Ξ“ A := Ξ» x Tm63 var63 lam app => var63 _ _ x def lam63 {Ξ“ A B} : Tm63 (snoc63 Ξ“ A) B β†’ Tm63 Ξ“ (arr63 A B) := Ξ» t Tm63 var63 lam63 app => lam63 _ _ _ (t Tm63 var63 lam63 app) def app63 {Ξ“ A B} : Tm63 Ξ“ (arr63 A B) β†’ Tm63 Ξ“ A β†’ Tm63 Ξ“ B := Ξ» t u Tm63 var63 lam63 app63 => app63 _ _ _ (t Tm63 var63 lam63 app63) (u Tm63 var63 lam63 app63) def v063 {Ξ“ A} : Tm63 (snoc63 Ξ“ A) A := var63 vz63 def v163 {Ξ“ A B} : Tm63 (snoc63 (snoc63 Ξ“ A) B) A := var63 (vs63 vz63) def v263 {Ξ“ A B C} : Tm63 (snoc63 (snoc63 (snoc63 Ξ“ A) B) C) A := var63 (vs63 (vs63 vz63)) def v363 {Ξ“ A B C D} : Tm63 (snoc63 (snoc63 (snoc63 (snoc63 Ξ“ A) B) C) D) A := var63 (vs63 (vs63 (vs63 vz63))) def v463 {Ξ“ A B C D E} : Tm63 (snoc63 (snoc63 (snoc63 (snoc63 (snoc63 Ξ“ A) B) C) D) E) A := var63 (vs63 (vs63 (vs63 (vs63 vz63)))) def test63 {Ξ“ A} : Tm63 Ξ“ (arr63 (arr63 A A) (arr63 A A)) := lam63 (lam63 (app63 v163 (app63 v163 (app63 v163 (app63 v163 (app63 v163 (app63 v163 v063))))))) def Ty64 : Type 1 := βˆ€ (Ty64 : Type) (ΞΉ : Ty64) (arr : Ty64 β†’ Ty64 β†’ Ty64) , Ty64 def ΞΉ64 : Ty64 := Ξ» _ ΞΉ64 _ => ΞΉ64 def arr64 : Ty64 β†’ Ty64 β†’ Ty64 := Ξ» A B Ty64 ΞΉ64 arr64 => arr64 (A Ty64 ΞΉ64 arr64) (B Ty64 ΞΉ64 arr64) def Con64 : Type 1 := βˆ€ (Con64 : Type) (nil : Con64) (snoc : Con64 β†’ Ty64 β†’ Con64) , Con64 def nil64 : Con64 := Ξ» Con64 nil64 snoc => nil64 def snoc64 : Con64 β†’ Ty64 β†’ Con64 := Ξ» Ξ“ A Con64 nil64 snoc64 => snoc64 (Ξ“ Con64 nil64 snoc64) A def Var64 : Con64 β†’ Ty64 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var64 : Con64 β†’ Ty64 β†’ Type) (vz : βˆ€ Ξ“ A, Var64 (snoc64 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var64 Ξ“ A β†’ Var64 (snoc64 Ξ“ B) A) , Var64 Ξ“ A def vz64 {Ξ“ A} : Var64 (snoc64 Ξ“ A) A := Ξ» Var64 vz64 vs => vz64 _ _ def vs64 {Ξ“ B A} : Var64 Ξ“ A β†’ Var64 (snoc64 Ξ“ B) A := Ξ» x Var64 vz64 vs64 => vs64 _ _ _ (x Var64 vz64 vs64) def Tm64 : Con64 β†’ Ty64 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm64 : Con64 β†’ Ty64 β†’ Type) (var : βˆ€ Ξ“ A , Var64 Ξ“ A β†’ Tm64 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm64 (snoc64 Ξ“ A) B β†’ Tm64 Ξ“ (arr64 A B)) (app : βˆ€ Ξ“ A B , Tm64 Ξ“ (arr64 A B) β†’ Tm64 Ξ“ A β†’ Tm64 Ξ“ B) , Tm64 Ξ“ A def var64 {Ξ“ A} : Var64 Ξ“ A β†’ Tm64 Ξ“ A := Ξ» x Tm64 var64 lam app => var64 _ _ x def lam64 {Ξ“ A B} : Tm64 (snoc64 Ξ“ A) B β†’ Tm64 Ξ“ (arr64 A B) := Ξ» t Tm64 var64 lam64 app => lam64 _ _ _ (t Tm64 var64 lam64 app) def app64 {Ξ“ A B} : Tm64 Ξ“ (arr64 A B) β†’ Tm64 Ξ“ A β†’ Tm64 Ξ“ B := Ξ» t u Tm64 var64 lam64 app64 => app64 _ _ _ (t Tm64 var64 lam64 app64) (u Tm64 var64 lam64 app64) def v064 {Ξ“ A} : Tm64 (snoc64 Ξ“ A) A := var64 vz64 def v164 {Ξ“ A B} : Tm64 (snoc64 (snoc64 Ξ“ A) B) A := var64 (vs64 vz64) def v264 {Ξ“ A B C} : Tm64 (snoc64 (snoc64 (snoc64 Ξ“ A) B) C) A := var64 (vs64 (vs64 vz64)) def v364 {Ξ“ A B C D} : Tm64 (snoc64 (snoc64 (snoc64 (snoc64 Ξ“ A) B) C) D) A := var64 (vs64 (vs64 (vs64 vz64))) def v464 {Ξ“ A B C D E} : Tm64 (snoc64 (snoc64 (snoc64 (snoc64 (snoc64 Ξ“ A) B) C) D) E) A := var64 (vs64 (vs64 (vs64 (vs64 vz64)))) def test64 {Ξ“ A} : Tm64 Ξ“ (arr64 (arr64 A A) (arr64 A A)) := lam64 (lam64 (app64 v164 (app64 v164 (app64 v164 (app64 v164 (app64 v164 (app64 v164 v064))))))) def Ty65 : Type 1 := βˆ€ (Ty65 : Type) (ΞΉ : Ty65) (arr : Ty65 β†’ Ty65 β†’ Ty65) , Ty65 def ΞΉ65 : Ty65 := Ξ» _ ΞΉ65 _ => ΞΉ65 def arr65 : Ty65 β†’ Ty65 β†’ Ty65 := Ξ» A B Ty65 ΞΉ65 arr65 => arr65 (A Ty65 ΞΉ65 arr65) (B Ty65 ΞΉ65 arr65) def Con65 : Type 1 := βˆ€ (Con65 : Type) (nil : Con65) (snoc : Con65 β†’ Ty65 β†’ Con65) , Con65 def nil65 : Con65 := Ξ» Con65 nil65 snoc => nil65 def snoc65 : Con65 β†’ Ty65 β†’ Con65 := Ξ» Ξ“ A Con65 nil65 snoc65 => snoc65 (Ξ“ Con65 nil65 snoc65) A def Var65 : Con65 β†’ Ty65 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var65 : Con65 β†’ Ty65 β†’ Type) (vz : βˆ€ Ξ“ A, Var65 (snoc65 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var65 Ξ“ A β†’ Var65 (snoc65 Ξ“ B) A) , Var65 Ξ“ A def vz65 {Ξ“ A} : Var65 (snoc65 Ξ“ A) A := Ξ» Var65 vz65 vs => vz65 _ _ def vs65 {Ξ“ B A} : Var65 Ξ“ A β†’ Var65 (snoc65 Ξ“ B) A := Ξ» x Var65 vz65 vs65 => vs65 _ _ _ (x Var65 vz65 vs65) def Tm65 : Con65 β†’ Ty65 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm65 : Con65 β†’ Ty65 β†’ Type) (var : βˆ€ Ξ“ A , Var65 Ξ“ A β†’ Tm65 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm65 (snoc65 Ξ“ A) B β†’ Tm65 Ξ“ (arr65 A B)) (app : βˆ€ Ξ“ A B , Tm65 Ξ“ (arr65 A B) β†’ Tm65 Ξ“ A β†’ Tm65 Ξ“ B) , Tm65 Ξ“ A def var65 {Ξ“ A} : Var65 Ξ“ A β†’ Tm65 Ξ“ A := Ξ» x Tm65 var65 lam app => var65 _ _ x def lam65 {Ξ“ A B} : Tm65 (snoc65 Ξ“ A) B β†’ Tm65 Ξ“ (arr65 A B) := Ξ» t Tm65 var65 lam65 app => lam65 _ _ _ (t Tm65 var65 lam65 app) def app65 {Ξ“ A B} : Tm65 Ξ“ (arr65 A B) β†’ Tm65 Ξ“ A β†’ Tm65 Ξ“ B := Ξ» t u Tm65 var65 lam65 app65 => app65 _ _ _ (t Tm65 var65 lam65 app65) (u Tm65 var65 lam65 app65) def v065 {Ξ“ A} : Tm65 (snoc65 Ξ“ A) A := var65 vz65 def v165 {Ξ“ A B} : Tm65 (snoc65 (snoc65 Ξ“ A) B) A := var65 (vs65 vz65) def v265 {Ξ“ A B C} : Tm65 (snoc65 (snoc65 (snoc65 Ξ“ A) B) C) A := var65 (vs65 (vs65 vz65)) def v365 {Ξ“ A B C D} : Tm65 (snoc65 (snoc65 (snoc65 (snoc65 Ξ“ A) B) C) D) A := var65 (vs65 (vs65 (vs65 vz65))) def v465 {Ξ“ A B C D E} : Tm65 (snoc65 (snoc65 (snoc65 (snoc65 (snoc65 Ξ“ A) B) C) D) E) A := var65 (vs65 (vs65 (vs65 (vs65 vz65)))) def test65 {Ξ“ A} : Tm65 Ξ“ (arr65 (arr65 A A) (arr65 A A)) := lam65 (lam65 (app65 v165 (app65 v165 (app65 v165 (app65 v165 (app65 v165 (app65 v165 v065))))))) def Ty66 : Type 1 := βˆ€ (Ty66 : Type) (ΞΉ : Ty66) (arr : Ty66 β†’ Ty66 β†’ Ty66) , Ty66 def ΞΉ66 : Ty66 := Ξ» _ ΞΉ66 _ => ΞΉ66 def arr66 : Ty66 β†’ Ty66 β†’ Ty66 := Ξ» A B Ty66 ΞΉ66 arr66 => arr66 (A Ty66 ΞΉ66 arr66) (B Ty66 ΞΉ66 arr66) def Con66 : Type 1 := βˆ€ (Con66 : Type) (nil : Con66) (snoc : Con66 β†’ Ty66 β†’ Con66) , Con66 def nil66 : Con66 := Ξ» Con66 nil66 snoc => nil66 def snoc66 : Con66 β†’ Ty66 β†’ Con66 := Ξ» Ξ“ A Con66 nil66 snoc66 => snoc66 (Ξ“ Con66 nil66 snoc66) A def Var66 : Con66 β†’ Ty66 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var66 : Con66 β†’ Ty66 β†’ Type) (vz : βˆ€ Ξ“ A, Var66 (snoc66 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var66 Ξ“ A β†’ Var66 (snoc66 Ξ“ B) A) , Var66 Ξ“ A def vz66 {Ξ“ A} : Var66 (snoc66 Ξ“ A) A := Ξ» Var66 vz66 vs => vz66 _ _ def vs66 {Ξ“ B A} : Var66 Ξ“ A β†’ Var66 (snoc66 Ξ“ B) A := Ξ» x Var66 vz66 vs66 => vs66 _ _ _ (x Var66 vz66 vs66) def Tm66 : Con66 β†’ Ty66 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm66 : Con66 β†’ Ty66 β†’ Type) (var : βˆ€ Ξ“ A , Var66 Ξ“ A β†’ Tm66 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm66 (snoc66 Ξ“ A) B β†’ Tm66 Ξ“ (arr66 A B)) (app : βˆ€ Ξ“ A B , Tm66 Ξ“ (arr66 A B) β†’ Tm66 Ξ“ A β†’ Tm66 Ξ“ B) , Tm66 Ξ“ A def var66 {Ξ“ A} : Var66 Ξ“ A β†’ Tm66 Ξ“ A := Ξ» x Tm66 var66 lam app => var66 _ _ x def lam66 {Ξ“ A B} : Tm66 (snoc66 Ξ“ A) B β†’ Tm66 Ξ“ (arr66 A B) := Ξ» t Tm66 var66 lam66 app => lam66 _ _ _ (t Tm66 var66 lam66 app) def app66 {Ξ“ A B} : Tm66 Ξ“ (arr66 A B) β†’ Tm66 Ξ“ A β†’ Tm66 Ξ“ B := Ξ» t u Tm66 var66 lam66 app66 => app66 _ _ _ (t Tm66 var66 lam66 app66) (u Tm66 var66 lam66 app66) def v066 {Ξ“ A} : Tm66 (snoc66 Ξ“ A) A := var66 vz66 def v166 {Ξ“ A B} : Tm66 (snoc66 (snoc66 Ξ“ A) B) A := var66 (vs66 vz66) def v266 {Ξ“ A B C} : Tm66 (snoc66 (snoc66 (snoc66 Ξ“ A) B) C) A := var66 (vs66 (vs66 vz66)) def v366 {Ξ“ A B C D} : Tm66 (snoc66 (snoc66 (snoc66 (snoc66 Ξ“ A) B) C) D) A := var66 (vs66 (vs66 (vs66 vz66))) def v466 {Ξ“ A B C D E} : Tm66 (snoc66 (snoc66 (snoc66 (snoc66 (snoc66 Ξ“ A) B) C) D) E) A := var66 (vs66 (vs66 (vs66 (vs66 vz66)))) def test66 {Ξ“ A} : Tm66 Ξ“ (arr66 (arr66 A A) (arr66 A A)) := lam66 (lam66 (app66 v166 (app66 v166 (app66 v166 (app66 v166 (app66 v166 (app66 v166 v066))))))) def Ty67 : Type 1 := βˆ€ (Ty67 : Type) (ΞΉ : Ty67) (arr : Ty67 β†’ Ty67 β†’ Ty67) , Ty67 def ΞΉ67 : Ty67 := Ξ» _ ΞΉ67 _ => ΞΉ67 def arr67 : Ty67 β†’ Ty67 β†’ Ty67 := Ξ» A B Ty67 ΞΉ67 arr67 => arr67 (A Ty67 ΞΉ67 arr67) (B Ty67 ΞΉ67 arr67) def Con67 : Type 1 := βˆ€ (Con67 : Type) (nil : Con67) (snoc : Con67 β†’ Ty67 β†’ Con67) , Con67 def nil67 : Con67 := Ξ» Con67 nil67 snoc => nil67 def snoc67 : Con67 β†’ Ty67 β†’ Con67 := Ξ» Ξ“ A Con67 nil67 snoc67 => snoc67 (Ξ“ Con67 nil67 snoc67) A def Var67 : Con67 β†’ Ty67 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var67 : Con67 β†’ Ty67 β†’ Type) (vz : βˆ€ Ξ“ A, Var67 (snoc67 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var67 Ξ“ A β†’ Var67 (snoc67 Ξ“ B) A) , Var67 Ξ“ A def vz67 {Ξ“ A} : Var67 (snoc67 Ξ“ A) A := Ξ» Var67 vz67 vs => vz67 _ _ def vs67 {Ξ“ B A} : Var67 Ξ“ A β†’ Var67 (snoc67 Ξ“ B) A := Ξ» x Var67 vz67 vs67 => vs67 _ _ _ (x Var67 vz67 vs67) def Tm67 : Con67 β†’ Ty67 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm67 : Con67 β†’ Ty67 β†’ Type) (var : βˆ€ Ξ“ A , Var67 Ξ“ A β†’ Tm67 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm67 (snoc67 Ξ“ A) B β†’ Tm67 Ξ“ (arr67 A B)) (app : βˆ€ Ξ“ A B , Tm67 Ξ“ (arr67 A B) β†’ Tm67 Ξ“ A β†’ Tm67 Ξ“ B) , Tm67 Ξ“ A def var67 {Ξ“ A} : Var67 Ξ“ A β†’ Tm67 Ξ“ A := Ξ» x Tm67 var67 lam app => var67 _ _ x def lam67 {Ξ“ A B} : Tm67 (snoc67 Ξ“ A) B β†’ Tm67 Ξ“ (arr67 A B) := Ξ» t Tm67 var67 lam67 app => lam67 _ _ _ (t Tm67 var67 lam67 app) def app67 {Ξ“ A B} : Tm67 Ξ“ (arr67 A B) β†’ Tm67 Ξ“ A β†’ Tm67 Ξ“ B := Ξ» t u Tm67 var67 lam67 app67 => app67 _ _ _ (t Tm67 var67 lam67 app67) (u Tm67 var67 lam67 app67) def v067 {Ξ“ A} : Tm67 (snoc67 Ξ“ A) A := var67 vz67 def v167 {Ξ“ A B} : Tm67 (snoc67 (snoc67 Ξ“ A) B) A := var67 (vs67 vz67) def v267 {Ξ“ A B C} : Tm67 (snoc67 (snoc67 (snoc67 Ξ“ A) B) C) A := var67 (vs67 (vs67 vz67)) def v367 {Ξ“ A B C D} : Tm67 (snoc67 (snoc67 (snoc67 (snoc67 Ξ“ A) B) C) D) A := var67 (vs67 (vs67 (vs67 vz67))) def v467 {Ξ“ A B C D E} : Tm67 (snoc67 (snoc67 (snoc67 (snoc67 (snoc67 Ξ“ A) B) C) D) E) A := var67 (vs67 (vs67 (vs67 (vs67 vz67)))) def test67 {Ξ“ A} : Tm67 Ξ“ (arr67 (arr67 A A) (arr67 A A)) := lam67 (lam67 (app67 v167 (app67 v167 (app67 v167 (app67 v167 (app67 v167 (app67 v167 v067))))))) def Ty68 : Type 1 := βˆ€ (Ty68 : Type) (ΞΉ : Ty68) (arr : Ty68 β†’ Ty68 β†’ Ty68) , Ty68 def ΞΉ68 : Ty68 := Ξ» _ ΞΉ68 _ => ΞΉ68 def arr68 : Ty68 β†’ Ty68 β†’ Ty68 := Ξ» A B Ty68 ΞΉ68 arr68 => arr68 (A Ty68 ΞΉ68 arr68) (B Ty68 ΞΉ68 arr68) def Con68 : Type 1 := βˆ€ (Con68 : Type) (nil : Con68) (snoc : Con68 β†’ Ty68 β†’ Con68) , Con68 def nil68 : Con68 := Ξ» Con68 nil68 snoc => nil68 def snoc68 : Con68 β†’ Ty68 β†’ Con68 := Ξ» Ξ“ A Con68 nil68 snoc68 => snoc68 (Ξ“ Con68 nil68 snoc68) A def Var68 : Con68 β†’ Ty68 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var68 : Con68 β†’ Ty68 β†’ Type) (vz : βˆ€ Ξ“ A, Var68 (snoc68 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var68 Ξ“ A β†’ Var68 (snoc68 Ξ“ B) A) , Var68 Ξ“ A def vz68 {Ξ“ A} : Var68 (snoc68 Ξ“ A) A := Ξ» Var68 vz68 vs => vz68 _ _ def vs68 {Ξ“ B A} : Var68 Ξ“ A β†’ Var68 (snoc68 Ξ“ B) A := Ξ» x Var68 vz68 vs68 => vs68 _ _ _ (x Var68 vz68 vs68) def Tm68 : Con68 β†’ Ty68 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm68 : Con68 β†’ Ty68 β†’ Type) (var : βˆ€ Ξ“ A , Var68 Ξ“ A β†’ Tm68 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm68 (snoc68 Ξ“ A) B β†’ Tm68 Ξ“ (arr68 A B)) (app : βˆ€ Ξ“ A B , Tm68 Ξ“ (arr68 A B) β†’ Tm68 Ξ“ A β†’ Tm68 Ξ“ B) , Tm68 Ξ“ A def var68 {Ξ“ A} : Var68 Ξ“ A β†’ Tm68 Ξ“ A := Ξ» x Tm68 var68 lam app => var68 _ _ x def lam68 {Ξ“ A B} : Tm68 (snoc68 Ξ“ A) B β†’ Tm68 Ξ“ (arr68 A B) := Ξ» t Tm68 var68 lam68 app => lam68 _ _ _ (t Tm68 var68 lam68 app) def app68 {Ξ“ A B} : Tm68 Ξ“ (arr68 A B) β†’ Tm68 Ξ“ A β†’ Tm68 Ξ“ B := Ξ» t u Tm68 var68 lam68 app68 => app68 _ _ _ (t Tm68 var68 lam68 app68) (u Tm68 var68 lam68 app68) def v068 {Ξ“ A} : Tm68 (snoc68 Ξ“ A) A := var68 vz68 def v168 {Ξ“ A B} : Tm68 (snoc68 (snoc68 Ξ“ A) B) A := var68 (vs68 vz68) def v268 {Ξ“ A B C} : Tm68 (snoc68 (snoc68 (snoc68 Ξ“ A) B) C) A := var68 (vs68 (vs68 vz68)) def v368 {Ξ“ A B C D} : Tm68 (snoc68 (snoc68 (snoc68 (snoc68 Ξ“ A) B) C) D) A := var68 (vs68 (vs68 (vs68 vz68))) def v468 {Ξ“ A B C D E} : Tm68 (snoc68 (snoc68 (snoc68 (snoc68 (snoc68 Ξ“ A) B) C) D) E) A := var68 (vs68 (vs68 (vs68 (vs68 vz68)))) def test68 {Ξ“ A} : Tm68 Ξ“ (arr68 (arr68 A A) (arr68 A A)) := lam68 (lam68 (app68 v168 (app68 v168 (app68 v168 (app68 v168 (app68 v168 (app68 v168 v068))))))) def Ty69 : Type 1 := βˆ€ (Ty69 : Type) (ΞΉ : Ty69) (arr : Ty69 β†’ Ty69 β†’ Ty69) , Ty69 def ΞΉ69 : Ty69 := Ξ» _ ΞΉ69 _ => ΞΉ69 def arr69 : Ty69 β†’ Ty69 β†’ Ty69 := Ξ» A B Ty69 ΞΉ69 arr69 => arr69 (A Ty69 ΞΉ69 arr69) (B Ty69 ΞΉ69 arr69) def Con69 : Type 1 := βˆ€ (Con69 : Type) (nil : Con69) (snoc : Con69 β†’ Ty69 β†’ Con69) , Con69 def nil69 : Con69 := Ξ» Con69 nil69 snoc => nil69 def snoc69 : Con69 β†’ Ty69 β†’ Con69 := Ξ» Ξ“ A Con69 nil69 snoc69 => snoc69 (Ξ“ Con69 nil69 snoc69) A def Var69 : Con69 β†’ Ty69 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var69 : Con69 β†’ Ty69 β†’ Type) (vz : βˆ€ Ξ“ A, Var69 (snoc69 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var69 Ξ“ A β†’ Var69 (snoc69 Ξ“ B) A) , Var69 Ξ“ A def vz69 {Ξ“ A} : Var69 (snoc69 Ξ“ A) A := Ξ» Var69 vz69 vs => vz69 _ _ def vs69 {Ξ“ B A} : Var69 Ξ“ A β†’ Var69 (snoc69 Ξ“ B) A := Ξ» x Var69 vz69 vs69 => vs69 _ _ _ (x Var69 vz69 vs69) def Tm69 : Con69 β†’ Ty69 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm69 : Con69 β†’ Ty69 β†’ Type) (var : βˆ€ Ξ“ A , Var69 Ξ“ A β†’ Tm69 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm69 (snoc69 Ξ“ A) B β†’ Tm69 Ξ“ (arr69 A B)) (app : βˆ€ Ξ“ A B , Tm69 Ξ“ (arr69 A B) β†’ Tm69 Ξ“ A β†’ Tm69 Ξ“ B) , Tm69 Ξ“ A def var69 {Ξ“ A} : Var69 Ξ“ A β†’ Tm69 Ξ“ A := Ξ» x Tm69 var69 lam app => var69 _ _ x def lam69 {Ξ“ A B} : Tm69 (snoc69 Ξ“ A) B β†’ Tm69 Ξ“ (arr69 A B) := Ξ» t Tm69 var69 lam69 app => lam69 _ _ _ (t Tm69 var69 lam69 app) def app69 {Ξ“ A B} : Tm69 Ξ“ (arr69 A B) β†’ Tm69 Ξ“ A β†’ Tm69 Ξ“ B := Ξ» t u Tm69 var69 lam69 app69 => app69 _ _ _ (t Tm69 var69 lam69 app69) (u Tm69 var69 lam69 app69) def v069 {Ξ“ A} : Tm69 (snoc69 Ξ“ A) A := var69 vz69 def v169 {Ξ“ A B} : Tm69 (snoc69 (snoc69 Ξ“ A) B) A := var69 (vs69 vz69) def v269 {Ξ“ A B C} : Tm69 (snoc69 (snoc69 (snoc69 Ξ“ A) B) C) A := var69 (vs69 (vs69 vz69)) def v369 {Ξ“ A B C D} : Tm69 (snoc69 (snoc69 (snoc69 (snoc69 Ξ“ A) B) C) D) A := var69 (vs69 (vs69 (vs69 vz69))) def v469 {Ξ“ A B C D E} : Tm69 (snoc69 (snoc69 (snoc69 (snoc69 (snoc69 Ξ“ A) B) C) D) E) A := var69 (vs69 (vs69 (vs69 (vs69 vz69)))) def test69 {Ξ“ A} : Tm69 Ξ“ (arr69 (arr69 A A) (arr69 A A)) := lam69 (lam69 (app69 v169 (app69 v169 (app69 v169 (app69 v169 (app69 v169 (app69 v169 v069))))))) def Ty70 : Type 1 := βˆ€ (Ty70 : Type) (ΞΉ : Ty70) (arr : Ty70 β†’ Ty70 β†’ Ty70) , Ty70 def ΞΉ70 : Ty70 := Ξ» _ ΞΉ70 _ => ΞΉ70 def arr70 : Ty70 β†’ Ty70 β†’ Ty70 := Ξ» A B Ty70 ΞΉ70 arr70 => arr70 (A Ty70 ΞΉ70 arr70) (B Ty70 ΞΉ70 arr70) def Con70 : Type 1 := βˆ€ (Con70 : Type) (nil : Con70) (snoc : Con70 β†’ Ty70 β†’ Con70) , Con70 def nil70 : Con70 := Ξ» Con70 nil70 snoc => nil70 def snoc70 : Con70 β†’ Ty70 β†’ Con70 := Ξ» Ξ“ A Con70 nil70 snoc70 => snoc70 (Ξ“ Con70 nil70 snoc70) A def Var70 : Con70 β†’ Ty70 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var70 : Con70 β†’ Ty70 β†’ Type) (vz : βˆ€ Ξ“ A, Var70 (snoc70 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var70 Ξ“ A β†’ Var70 (snoc70 Ξ“ B) A) , Var70 Ξ“ A def vz70 {Ξ“ A} : Var70 (snoc70 Ξ“ A) A := Ξ» Var70 vz70 vs => vz70 _ _ def vs70 {Ξ“ B A} : Var70 Ξ“ A β†’ Var70 (snoc70 Ξ“ B) A := Ξ» x Var70 vz70 vs70 => vs70 _ _ _ (x Var70 vz70 vs70) def Tm70 : Con70 β†’ Ty70 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm70 : Con70 β†’ Ty70 β†’ Type) (var : βˆ€ Ξ“ A , Var70 Ξ“ A β†’ Tm70 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm70 (snoc70 Ξ“ A) B β†’ Tm70 Ξ“ (arr70 A B)) (app : βˆ€ Ξ“ A B , Tm70 Ξ“ (arr70 A B) β†’ Tm70 Ξ“ A β†’ Tm70 Ξ“ B) , Tm70 Ξ“ A def var70 {Ξ“ A} : Var70 Ξ“ A β†’ Tm70 Ξ“ A := Ξ» x Tm70 var70 lam app => var70 _ _ x def lam70 {Ξ“ A B} : Tm70 (snoc70 Ξ“ A) B β†’ Tm70 Ξ“ (arr70 A B) := Ξ» t Tm70 var70 lam70 app => lam70 _ _ _ (t Tm70 var70 lam70 app) def app70 {Ξ“ A B} : Tm70 Ξ“ (arr70 A B) β†’ Tm70 Ξ“ A β†’ Tm70 Ξ“ B := Ξ» t u Tm70 var70 lam70 app70 => app70 _ _ _ (t Tm70 var70 lam70 app70) (u Tm70 var70 lam70 app70) def v070 {Ξ“ A} : Tm70 (snoc70 Ξ“ A) A := var70 vz70 def v170 {Ξ“ A B} : Tm70 (snoc70 (snoc70 Ξ“ A) B) A := var70 (vs70 vz70) def v270 {Ξ“ A B C} : Tm70 (snoc70 (snoc70 (snoc70 Ξ“ A) B) C) A := var70 (vs70 (vs70 vz70)) def v370 {Ξ“ A B C D} : Tm70 (snoc70 (snoc70 (snoc70 (snoc70 Ξ“ A) B) C) D) A := var70 (vs70 (vs70 (vs70 vz70))) def v470 {Ξ“ A B C D E} : Tm70 (snoc70 (snoc70 (snoc70 (snoc70 (snoc70 Ξ“ A) B) C) D) E) A := var70 (vs70 (vs70 (vs70 (vs70 vz70)))) def test70 {Ξ“ A} : Tm70 Ξ“ (arr70 (arr70 A A) (arr70 A A)) := lam70 (lam70 (app70 v170 (app70 v170 (app70 v170 (app70 v170 (app70 v170 (app70 v170 v070))))))) def Ty71 : Type 1 := βˆ€ (Ty71 : Type) (ΞΉ : Ty71) (arr : Ty71 β†’ Ty71 β†’ Ty71) , Ty71 def ΞΉ71 : Ty71 := Ξ» _ ΞΉ71 _ => ΞΉ71 def arr71 : Ty71 β†’ Ty71 β†’ Ty71 := Ξ» A B Ty71 ΞΉ71 arr71 => arr71 (A Ty71 ΞΉ71 arr71) (B Ty71 ΞΉ71 arr71) def Con71 : Type 1 := βˆ€ (Con71 : Type) (nil : Con71) (snoc : Con71 β†’ Ty71 β†’ Con71) , Con71 def nil71 : Con71 := Ξ» Con71 nil71 snoc => nil71 def snoc71 : Con71 β†’ Ty71 β†’ Con71 := Ξ» Ξ“ A Con71 nil71 snoc71 => snoc71 (Ξ“ Con71 nil71 snoc71) A def Var71 : Con71 β†’ Ty71 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var71 : Con71 β†’ Ty71 β†’ Type) (vz : βˆ€ Ξ“ A, Var71 (snoc71 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var71 Ξ“ A β†’ Var71 (snoc71 Ξ“ B) A) , Var71 Ξ“ A def vz71 {Ξ“ A} : Var71 (snoc71 Ξ“ A) A := Ξ» Var71 vz71 vs => vz71 _ _ def vs71 {Ξ“ B A} : Var71 Ξ“ A β†’ Var71 (snoc71 Ξ“ B) A := Ξ» x Var71 vz71 vs71 => vs71 _ _ _ (x Var71 vz71 vs71) def Tm71 : Con71 β†’ Ty71 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm71 : Con71 β†’ Ty71 β†’ Type) (var : βˆ€ Ξ“ A , Var71 Ξ“ A β†’ Tm71 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm71 (snoc71 Ξ“ A) B β†’ Tm71 Ξ“ (arr71 A B)) (app : βˆ€ Ξ“ A B , Tm71 Ξ“ (arr71 A B) β†’ Tm71 Ξ“ A β†’ Tm71 Ξ“ B) , Tm71 Ξ“ A def var71 {Ξ“ A} : Var71 Ξ“ A β†’ Tm71 Ξ“ A := Ξ» x Tm71 var71 lam app => var71 _ _ x def lam71 {Ξ“ A B} : Tm71 (snoc71 Ξ“ A) B β†’ Tm71 Ξ“ (arr71 A B) := Ξ» t Tm71 var71 lam71 app => lam71 _ _ _ (t Tm71 var71 lam71 app) def app71 {Ξ“ A B} : Tm71 Ξ“ (arr71 A B) β†’ Tm71 Ξ“ A β†’ Tm71 Ξ“ B := Ξ» t u Tm71 var71 lam71 app71 => app71 _ _ _ (t Tm71 var71 lam71 app71) (u Tm71 var71 lam71 app71) def v071 {Ξ“ A} : Tm71 (snoc71 Ξ“ A) A := var71 vz71 def v171 {Ξ“ A B} : Tm71 (snoc71 (snoc71 Ξ“ A) B) A := var71 (vs71 vz71) def v271 {Ξ“ A B C} : Tm71 (snoc71 (snoc71 (snoc71 Ξ“ A) B) C) A := var71 (vs71 (vs71 vz71)) def v371 {Ξ“ A B C D} : Tm71 (snoc71 (snoc71 (snoc71 (snoc71 Ξ“ A) B) C) D) A := var71 (vs71 (vs71 (vs71 vz71))) def v471 {Ξ“ A B C D E} : Tm71 (snoc71 (snoc71 (snoc71 (snoc71 (snoc71 Ξ“ A) B) C) D) E) A := var71 (vs71 (vs71 (vs71 (vs71 vz71)))) def test71 {Ξ“ A} : Tm71 Ξ“ (arr71 (arr71 A A) (arr71 A A)) := lam71 (lam71 (app71 v171 (app71 v171 (app71 v171 (app71 v171 (app71 v171 (app71 v171 v071))))))) def Ty72 : Type 1 := βˆ€ (Ty72 : Type) (ΞΉ : Ty72) (arr : Ty72 β†’ Ty72 β†’ Ty72) , Ty72 def ΞΉ72 : Ty72 := Ξ» _ ΞΉ72 _ => ΞΉ72 def arr72 : Ty72 β†’ Ty72 β†’ Ty72 := Ξ» A B Ty72 ΞΉ72 arr72 => arr72 (A Ty72 ΞΉ72 arr72) (B Ty72 ΞΉ72 arr72) def Con72 : Type 1 := βˆ€ (Con72 : Type) (nil : Con72) (snoc : Con72 β†’ Ty72 β†’ Con72) , Con72 def nil72 : Con72 := Ξ» Con72 nil72 snoc => nil72 def snoc72 : Con72 β†’ Ty72 β†’ Con72 := Ξ» Ξ“ A Con72 nil72 snoc72 => snoc72 (Ξ“ Con72 nil72 snoc72) A def Var72 : Con72 β†’ Ty72 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var72 : Con72 β†’ Ty72 β†’ Type) (vz : βˆ€ Ξ“ A, Var72 (snoc72 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var72 Ξ“ A β†’ Var72 (snoc72 Ξ“ B) A) , Var72 Ξ“ A def vz72 {Ξ“ A} : Var72 (snoc72 Ξ“ A) A := Ξ» Var72 vz72 vs => vz72 _ _ def vs72 {Ξ“ B A} : Var72 Ξ“ A β†’ Var72 (snoc72 Ξ“ B) A := Ξ» x Var72 vz72 vs72 => vs72 _ _ _ (x Var72 vz72 vs72) def Tm72 : Con72 β†’ Ty72 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm72 : Con72 β†’ Ty72 β†’ Type) (var : βˆ€ Ξ“ A , Var72 Ξ“ A β†’ Tm72 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm72 (snoc72 Ξ“ A) B β†’ Tm72 Ξ“ (arr72 A B)) (app : βˆ€ Ξ“ A B , Tm72 Ξ“ (arr72 A B) β†’ Tm72 Ξ“ A β†’ Tm72 Ξ“ B) , Tm72 Ξ“ A def var72 {Ξ“ A} : Var72 Ξ“ A β†’ Tm72 Ξ“ A := Ξ» x Tm72 var72 lam app => var72 _ _ x def lam72 {Ξ“ A B} : Tm72 (snoc72 Ξ“ A) B β†’ Tm72 Ξ“ (arr72 A B) := Ξ» t Tm72 var72 lam72 app => lam72 _ _ _ (t Tm72 var72 lam72 app) def app72 {Ξ“ A B} : Tm72 Ξ“ (arr72 A B) β†’ Tm72 Ξ“ A β†’ Tm72 Ξ“ B := Ξ» t u Tm72 var72 lam72 app72 => app72 _ _ _ (t Tm72 var72 lam72 app72) (u Tm72 var72 lam72 app72) def v072 {Ξ“ A} : Tm72 (snoc72 Ξ“ A) A := var72 vz72 def v172 {Ξ“ A B} : Tm72 (snoc72 (snoc72 Ξ“ A) B) A := var72 (vs72 vz72) def v272 {Ξ“ A B C} : Tm72 (snoc72 (snoc72 (snoc72 Ξ“ A) B) C) A := var72 (vs72 (vs72 vz72)) def v372 {Ξ“ A B C D} : Tm72 (snoc72 (snoc72 (snoc72 (snoc72 Ξ“ A) B) C) D) A := var72 (vs72 (vs72 (vs72 vz72))) def v472 {Ξ“ A B C D E} : Tm72 (snoc72 (snoc72 (snoc72 (snoc72 (snoc72 Ξ“ A) B) C) D) E) A := var72 (vs72 (vs72 (vs72 (vs72 vz72)))) def test72 {Ξ“ A} : Tm72 Ξ“ (arr72 (arr72 A A) (arr72 A A)) := lam72 (lam72 (app72 v172 (app72 v172 (app72 v172 (app72 v172 (app72 v172 (app72 v172 v072))))))) def Ty73 : Type 1 := βˆ€ (Ty73 : Type) (ΞΉ : Ty73) (arr : Ty73 β†’ Ty73 β†’ Ty73) , Ty73 def ΞΉ73 : Ty73 := Ξ» _ ΞΉ73 _ => ΞΉ73 def arr73 : Ty73 β†’ Ty73 β†’ Ty73 := Ξ» A B Ty73 ΞΉ73 arr73 => arr73 (A Ty73 ΞΉ73 arr73) (B Ty73 ΞΉ73 arr73) def Con73 : Type 1 := βˆ€ (Con73 : Type) (nil : Con73) (snoc : Con73 β†’ Ty73 β†’ Con73) , Con73 def nil73 : Con73 := Ξ» Con73 nil73 snoc => nil73 def snoc73 : Con73 β†’ Ty73 β†’ Con73 := Ξ» Ξ“ A Con73 nil73 snoc73 => snoc73 (Ξ“ Con73 nil73 snoc73) A def Var73 : Con73 β†’ Ty73 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var73 : Con73 β†’ Ty73 β†’ Type) (vz : βˆ€ Ξ“ A, Var73 (snoc73 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var73 Ξ“ A β†’ Var73 (snoc73 Ξ“ B) A) , Var73 Ξ“ A def vz73 {Ξ“ A} : Var73 (snoc73 Ξ“ A) A := Ξ» Var73 vz73 vs => vz73 _ _ def vs73 {Ξ“ B A} : Var73 Ξ“ A β†’ Var73 (snoc73 Ξ“ B) A := Ξ» x Var73 vz73 vs73 => vs73 _ _ _ (x Var73 vz73 vs73) def Tm73 : Con73 β†’ Ty73 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm73 : Con73 β†’ Ty73 β†’ Type) (var : βˆ€ Ξ“ A , Var73 Ξ“ A β†’ Tm73 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm73 (snoc73 Ξ“ A) B β†’ Tm73 Ξ“ (arr73 A B)) (app : βˆ€ Ξ“ A B , Tm73 Ξ“ (arr73 A B) β†’ Tm73 Ξ“ A β†’ Tm73 Ξ“ B) , Tm73 Ξ“ A def var73 {Ξ“ A} : Var73 Ξ“ A β†’ Tm73 Ξ“ A := Ξ» x Tm73 var73 lam app => var73 _ _ x def lam73 {Ξ“ A B} : Tm73 (snoc73 Ξ“ A) B β†’ Tm73 Ξ“ (arr73 A B) := Ξ» t Tm73 var73 lam73 app => lam73 _ _ _ (t Tm73 var73 lam73 app) def app73 {Ξ“ A B} : Tm73 Ξ“ (arr73 A B) β†’ Tm73 Ξ“ A β†’ Tm73 Ξ“ B := Ξ» t u Tm73 var73 lam73 app73 => app73 _ _ _ (t Tm73 var73 lam73 app73) (u Tm73 var73 lam73 app73) def v073 {Ξ“ A} : Tm73 (snoc73 Ξ“ A) A := var73 vz73 def v173 {Ξ“ A B} : Tm73 (snoc73 (snoc73 Ξ“ A) B) A := var73 (vs73 vz73) def v273 {Ξ“ A B C} : Tm73 (snoc73 (snoc73 (snoc73 Ξ“ A) B) C) A := var73 (vs73 (vs73 vz73)) def v373 {Ξ“ A B C D} : Tm73 (snoc73 (snoc73 (snoc73 (snoc73 Ξ“ A) B) C) D) A := var73 (vs73 (vs73 (vs73 vz73))) def v473 {Ξ“ A B C D E} : Tm73 (snoc73 (snoc73 (snoc73 (snoc73 (snoc73 Ξ“ A) B) C) D) E) A := var73 (vs73 (vs73 (vs73 (vs73 vz73)))) def test73 {Ξ“ A} : Tm73 Ξ“ (arr73 (arr73 A A) (arr73 A A)) := lam73 (lam73 (app73 v173 (app73 v173 (app73 v173 (app73 v173 (app73 v173 (app73 v173 v073))))))) def Ty74 : Type 1 := βˆ€ (Ty74 : Type) (ΞΉ : Ty74) (arr : Ty74 β†’ Ty74 β†’ Ty74) , Ty74 def ΞΉ74 : Ty74 := Ξ» _ ΞΉ74 _ => ΞΉ74 def arr74 : Ty74 β†’ Ty74 β†’ Ty74 := Ξ» A B Ty74 ΞΉ74 arr74 => arr74 (A Ty74 ΞΉ74 arr74) (B Ty74 ΞΉ74 arr74) def Con74 : Type 1 := βˆ€ (Con74 : Type) (nil : Con74) (snoc : Con74 β†’ Ty74 β†’ Con74) , Con74 def nil74 : Con74 := Ξ» Con74 nil74 snoc => nil74 def snoc74 : Con74 β†’ Ty74 β†’ Con74 := Ξ» Ξ“ A Con74 nil74 snoc74 => snoc74 (Ξ“ Con74 nil74 snoc74) A def Var74 : Con74 β†’ Ty74 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var74 : Con74 β†’ Ty74 β†’ Type) (vz : βˆ€ Ξ“ A, Var74 (snoc74 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var74 Ξ“ A β†’ Var74 (snoc74 Ξ“ B) A) , Var74 Ξ“ A def vz74 {Ξ“ A} : Var74 (snoc74 Ξ“ A) A := Ξ» Var74 vz74 vs => vz74 _ _ def vs74 {Ξ“ B A} : Var74 Ξ“ A β†’ Var74 (snoc74 Ξ“ B) A := Ξ» x Var74 vz74 vs74 => vs74 _ _ _ (x Var74 vz74 vs74) def Tm74 : Con74 β†’ Ty74 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm74 : Con74 β†’ Ty74 β†’ Type) (var : βˆ€ Ξ“ A , Var74 Ξ“ A β†’ Tm74 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm74 (snoc74 Ξ“ A) B β†’ Tm74 Ξ“ (arr74 A B)) (app : βˆ€ Ξ“ A B , Tm74 Ξ“ (arr74 A B) β†’ Tm74 Ξ“ A β†’ Tm74 Ξ“ B) , Tm74 Ξ“ A def var74 {Ξ“ A} : Var74 Ξ“ A β†’ Tm74 Ξ“ A := Ξ» x Tm74 var74 lam app => var74 _ _ x def lam74 {Ξ“ A B} : Tm74 (snoc74 Ξ“ A) B β†’ Tm74 Ξ“ (arr74 A B) := Ξ» t Tm74 var74 lam74 app => lam74 _ _ _ (t Tm74 var74 lam74 app) def app74 {Ξ“ A B} : Tm74 Ξ“ (arr74 A B) β†’ Tm74 Ξ“ A β†’ Tm74 Ξ“ B := Ξ» t u Tm74 var74 lam74 app74 => app74 _ _ _ (t Tm74 var74 lam74 app74) (u Tm74 var74 lam74 app74) def v074 {Ξ“ A} : Tm74 (snoc74 Ξ“ A) A := var74 vz74 def v174 {Ξ“ A B} : Tm74 (snoc74 (snoc74 Ξ“ A) B) A := var74 (vs74 vz74) def v274 {Ξ“ A B C} : Tm74 (snoc74 (snoc74 (snoc74 Ξ“ A) B) C) A := var74 (vs74 (vs74 vz74)) def v374 {Ξ“ A B C D} : Tm74 (snoc74 (snoc74 (snoc74 (snoc74 Ξ“ A) B) C) D) A := var74 (vs74 (vs74 (vs74 vz74))) def v474 {Ξ“ A B C D E} : Tm74 (snoc74 (snoc74 (snoc74 (snoc74 (snoc74 Ξ“ A) B) C) D) E) A := var74 (vs74 (vs74 (vs74 (vs74 vz74)))) def test74 {Ξ“ A} : Tm74 Ξ“ (arr74 (arr74 A A) (arr74 A A)) := lam74 (lam74 (app74 v174 (app74 v174 (app74 v174 (app74 v174 (app74 v174 (app74 v174 v074))))))) def Ty75 : Type 1 := βˆ€ (Ty75 : Type) (ΞΉ : Ty75) (arr : Ty75 β†’ Ty75 β†’ Ty75) , Ty75 def ΞΉ75 : Ty75 := Ξ» _ ΞΉ75 _ => ΞΉ75 def arr75 : Ty75 β†’ Ty75 β†’ Ty75 := Ξ» A B Ty75 ΞΉ75 arr75 => arr75 (A Ty75 ΞΉ75 arr75) (B Ty75 ΞΉ75 arr75) def Con75 : Type 1 := βˆ€ (Con75 : Type) (nil : Con75) (snoc : Con75 β†’ Ty75 β†’ Con75) , Con75 def nil75 : Con75 := Ξ» Con75 nil75 snoc => nil75 def snoc75 : Con75 β†’ Ty75 β†’ Con75 := Ξ» Ξ“ A Con75 nil75 snoc75 => snoc75 (Ξ“ Con75 nil75 snoc75) A def Var75 : Con75 β†’ Ty75 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var75 : Con75 β†’ Ty75 β†’ Type) (vz : βˆ€ Ξ“ A, Var75 (snoc75 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var75 Ξ“ A β†’ Var75 (snoc75 Ξ“ B) A) , Var75 Ξ“ A def vz75 {Ξ“ A} : Var75 (snoc75 Ξ“ A) A := Ξ» Var75 vz75 vs => vz75 _ _ def vs75 {Ξ“ B A} : Var75 Ξ“ A β†’ Var75 (snoc75 Ξ“ B) A := Ξ» x Var75 vz75 vs75 => vs75 _ _ _ (x Var75 vz75 vs75) def Tm75 : Con75 β†’ Ty75 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm75 : Con75 β†’ Ty75 β†’ Type) (var : βˆ€ Ξ“ A , Var75 Ξ“ A β†’ Tm75 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm75 (snoc75 Ξ“ A) B β†’ Tm75 Ξ“ (arr75 A B)) (app : βˆ€ Ξ“ A B , Tm75 Ξ“ (arr75 A B) β†’ Tm75 Ξ“ A β†’ Tm75 Ξ“ B) , Tm75 Ξ“ A def var75 {Ξ“ A} : Var75 Ξ“ A β†’ Tm75 Ξ“ A := Ξ» x Tm75 var75 lam app => var75 _ _ x def lam75 {Ξ“ A B} : Tm75 (snoc75 Ξ“ A) B β†’ Tm75 Ξ“ (arr75 A B) := Ξ» t Tm75 var75 lam75 app => lam75 _ _ _ (t Tm75 var75 lam75 app) def app75 {Ξ“ A B} : Tm75 Ξ“ (arr75 A B) β†’ Tm75 Ξ“ A β†’ Tm75 Ξ“ B := Ξ» t u Tm75 var75 lam75 app75 => app75 _ _ _ (t Tm75 var75 lam75 app75) (u Tm75 var75 lam75 app75) def v075 {Ξ“ A} : Tm75 (snoc75 Ξ“ A) A := var75 vz75 def v175 {Ξ“ A B} : Tm75 (snoc75 (snoc75 Ξ“ A) B) A := var75 (vs75 vz75) def v275 {Ξ“ A B C} : Tm75 (snoc75 (snoc75 (snoc75 Ξ“ A) B) C) A := var75 (vs75 (vs75 vz75)) def v375 {Ξ“ A B C D} : Tm75 (snoc75 (snoc75 (snoc75 (snoc75 Ξ“ A) B) C) D) A := var75 (vs75 (vs75 (vs75 vz75))) def v475 {Ξ“ A B C D E} : Tm75 (snoc75 (snoc75 (snoc75 (snoc75 (snoc75 Ξ“ A) B) C) D) E) A := var75 (vs75 (vs75 (vs75 (vs75 vz75)))) def test75 {Ξ“ A} : Tm75 Ξ“ (arr75 (arr75 A A) (arr75 A A)) := lam75 (lam75 (app75 v175 (app75 v175 (app75 v175 (app75 v175 (app75 v175 (app75 v175 v075))))))) def Ty76 : Type 1 := βˆ€ (Ty76 : Type) (ΞΉ : Ty76) (arr : Ty76 β†’ Ty76 β†’ Ty76) , Ty76 def ΞΉ76 : Ty76 := Ξ» _ ΞΉ76 _ => ΞΉ76 def arr76 : Ty76 β†’ Ty76 β†’ Ty76 := Ξ» A B Ty76 ΞΉ76 arr76 => arr76 (A Ty76 ΞΉ76 arr76) (B Ty76 ΞΉ76 arr76) def Con76 : Type 1 := βˆ€ (Con76 : Type) (nil : Con76) (snoc : Con76 β†’ Ty76 β†’ Con76) , Con76 def nil76 : Con76 := Ξ» Con76 nil76 snoc => nil76 def snoc76 : Con76 β†’ Ty76 β†’ Con76 := Ξ» Ξ“ A Con76 nil76 snoc76 => snoc76 (Ξ“ Con76 nil76 snoc76) A def Var76 : Con76 β†’ Ty76 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var76 : Con76 β†’ Ty76 β†’ Type) (vz : βˆ€ Ξ“ A, Var76 (snoc76 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var76 Ξ“ A β†’ Var76 (snoc76 Ξ“ B) A) , Var76 Ξ“ A def vz76 {Ξ“ A} : Var76 (snoc76 Ξ“ A) A := Ξ» Var76 vz76 vs => vz76 _ _ def vs76 {Ξ“ B A} : Var76 Ξ“ A β†’ Var76 (snoc76 Ξ“ B) A := Ξ» x Var76 vz76 vs76 => vs76 _ _ _ (x Var76 vz76 vs76) def Tm76 : Con76 β†’ Ty76 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm76 : Con76 β†’ Ty76 β†’ Type) (var : βˆ€ Ξ“ A , Var76 Ξ“ A β†’ Tm76 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm76 (snoc76 Ξ“ A) B β†’ Tm76 Ξ“ (arr76 A B)) (app : βˆ€ Ξ“ A B , Tm76 Ξ“ (arr76 A B) β†’ Tm76 Ξ“ A β†’ Tm76 Ξ“ B) , Tm76 Ξ“ A def var76 {Ξ“ A} : Var76 Ξ“ A β†’ Tm76 Ξ“ A := Ξ» x Tm76 var76 lam app => var76 _ _ x def lam76 {Ξ“ A B} : Tm76 (snoc76 Ξ“ A) B β†’ Tm76 Ξ“ (arr76 A B) := Ξ» t Tm76 var76 lam76 app => lam76 _ _ _ (t Tm76 var76 lam76 app) def app76 {Ξ“ A B} : Tm76 Ξ“ (arr76 A B) β†’ Tm76 Ξ“ A β†’ Tm76 Ξ“ B := Ξ» t u Tm76 var76 lam76 app76 => app76 _ _ _ (t Tm76 var76 lam76 app76) (u Tm76 var76 lam76 app76) def v076 {Ξ“ A} : Tm76 (snoc76 Ξ“ A) A := var76 vz76 def v176 {Ξ“ A B} : Tm76 (snoc76 (snoc76 Ξ“ A) B) A := var76 (vs76 vz76) def v276 {Ξ“ A B C} : Tm76 (snoc76 (snoc76 (snoc76 Ξ“ A) B) C) A := var76 (vs76 (vs76 vz76)) def v376 {Ξ“ A B C D} : Tm76 (snoc76 (snoc76 (snoc76 (snoc76 Ξ“ A) B) C) D) A := var76 (vs76 (vs76 (vs76 vz76))) def v476 {Ξ“ A B C D E} : Tm76 (snoc76 (snoc76 (snoc76 (snoc76 (snoc76 Ξ“ A) B) C) D) E) A := var76 (vs76 (vs76 (vs76 (vs76 vz76)))) def test76 {Ξ“ A} : Tm76 Ξ“ (arr76 (arr76 A A) (arr76 A A)) := lam76 (lam76 (app76 v176 (app76 v176 (app76 v176 (app76 v176 (app76 v176 (app76 v176 v076))))))) def Ty77 : Type 1 := βˆ€ (Ty77 : Type) (ΞΉ : Ty77) (arr : Ty77 β†’ Ty77 β†’ Ty77) , Ty77 def ΞΉ77 : Ty77 := Ξ» _ ΞΉ77 _ => ΞΉ77 def arr77 : Ty77 β†’ Ty77 β†’ Ty77 := Ξ» A B Ty77 ΞΉ77 arr77 => arr77 (A Ty77 ΞΉ77 arr77) (B Ty77 ΞΉ77 arr77) def Con77 : Type 1 := βˆ€ (Con77 : Type) (nil : Con77) (snoc : Con77 β†’ Ty77 β†’ Con77) , Con77 def nil77 : Con77 := Ξ» Con77 nil77 snoc => nil77 def snoc77 : Con77 β†’ Ty77 β†’ Con77 := Ξ» Ξ“ A Con77 nil77 snoc77 => snoc77 (Ξ“ Con77 nil77 snoc77) A def Var77 : Con77 β†’ Ty77 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var77 : Con77 β†’ Ty77 β†’ Type) (vz : βˆ€ Ξ“ A, Var77 (snoc77 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var77 Ξ“ A β†’ Var77 (snoc77 Ξ“ B) A) , Var77 Ξ“ A def vz77 {Ξ“ A} : Var77 (snoc77 Ξ“ A) A := Ξ» Var77 vz77 vs => vz77 _ _ def vs77 {Ξ“ B A} : Var77 Ξ“ A β†’ Var77 (snoc77 Ξ“ B) A := Ξ» x Var77 vz77 vs77 => vs77 _ _ _ (x Var77 vz77 vs77) def Tm77 : Con77 β†’ Ty77 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm77 : Con77 β†’ Ty77 β†’ Type) (var : βˆ€ Ξ“ A , Var77 Ξ“ A β†’ Tm77 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm77 (snoc77 Ξ“ A) B β†’ Tm77 Ξ“ (arr77 A B)) (app : βˆ€ Ξ“ A B , Tm77 Ξ“ (arr77 A B) β†’ Tm77 Ξ“ A β†’ Tm77 Ξ“ B) , Tm77 Ξ“ A def var77 {Ξ“ A} : Var77 Ξ“ A β†’ Tm77 Ξ“ A := Ξ» x Tm77 var77 lam app => var77 _ _ x def lam77 {Ξ“ A B} : Tm77 (snoc77 Ξ“ A) B β†’ Tm77 Ξ“ (arr77 A B) := Ξ» t Tm77 var77 lam77 app => lam77 _ _ _ (t Tm77 var77 lam77 app) def app77 {Ξ“ A B} : Tm77 Ξ“ (arr77 A B) β†’ Tm77 Ξ“ A β†’ Tm77 Ξ“ B := Ξ» t u Tm77 var77 lam77 app77 => app77 _ _ _ (t Tm77 var77 lam77 app77) (u Tm77 var77 lam77 app77) def v077 {Ξ“ A} : Tm77 (snoc77 Ξ“ A) A := var77 vz77 def v177 {Ξ“ A B} : Tm77 (snoc77 (snoc77 Ξ“ A) B) A := var77 (vs77 vz77) def v277 {Ξ“ A B C} : Tm77 (snoc77 (snoc77 (snoc77 Ξ“ A) B) C) A := var77 (vs77 (vs77 vz77)) def v377 {Ξ“ A B C D} : Tm77 (snoc77 (snoc77 (snoc77 (snoc77 Ξ“ A) B) C) D) A := var77 (vs77 (vs77 (vs77 vz77))) def v477 {Ξ“ A B C D E} : Tm77 (snoc77 (snoc77 (snoc77 (snoc77 (snoc77 Ξ“ A) B) C) D) E) A := var77 (vs77 (vs77 (vs77 (vs77 vz77)))) def test77 {Ξ“ A} : Tm77 Ξ“ (arr77 (arr77 A A) (arr77 A A)) := lam77 (lam77 (app77 v177 (app77 v177 (app77 v177 (app77 v177 (app77 v177 (app77 v177 v077))))))) def Ty78 : Type 1 := βˆ€ (Ty78 : Type) (ΞΉ : Ty78) (arr : Ty78 β†’ Ty78 β†’ Ty78) , Ty78 def ΞΉ78 : Ty78 := Ξ» _ ΞΉ78 _ => ΞΉ78 def arr78 : Ty78 β†’ Ty78 β†’ Ty78 := Ξ» A B Ty78 ΞΉ78 arr78 => arr78 (A Ty78 ΞΉ78 arr78) (B Ty78 ΞΉ78 arr78) def Con78 : Type 1 := βˆ€ (Con78 : Type) (nil : Con78) (snoc : Con78 β†’ Ty78 β†’ Con78) , Con78 def nil78 : Con78 := Ξ» Con78 nil78 snoc => nil78 def snoc78 : Con78 β†’ Ty78 β†’ Con78 := Ξ» Ξ“ A Con78 nil78 snoc78 => snoc78 (Ξ“ Con78 nil78 snoc78) A def Var78 : Con78 β†’ Ty78 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var78 : Con78 β†’ Ty78 β†’ Type) (vz : βˆ€ Ξ“ A, Var78 (snoc78 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var78 Ξ“ A β†’ Var78 (snoc78 Ξ“ B) A) , Var78 Ξ“ A def vz78 {Ξ“ A} : Var78 (snoc78 Ξ“ A) A := Ξ» Var78 vz78 vs => vz78 _ _ def vs78 {Ξ“ B A} : Var78 Ξ“ A β†’ Var78 (snoc78 Ξ“ B) A := Ξ» x Var78 vz78 vs78 => vs78 _ _ _ (x Var78 vz78 vs78) def Tm78 : Con78 β†’ Ty78 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm78 : Con78 β†’ Ty78 β†’ Type) (var : βˆ€ Ξ“ A , Var78 Ξ“ A β†’ Tm78 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm78 (snoc78 Ξ“ A) B β†’ Tm78 Ξ“ (arr78 A B)) (app : βˆ€ Ξ“ A B , Tm78 Ξ“ (arr78 A B) β†’ Tm78 Ξ“ A β†’ Tm78 Ξ“ B) , Tm78 Ξ“ A def var78 {Ξ“ A} : Var78 Ξ“ A β†’ Tm78 Ξ“ A := Ξ» x Tm78 var78 lam app => var78 _ _ x def lam78 {Ξ“ A B} : Tm78 (snoc78 Ξ“ A) B β†’ Tm78 Ξ“ (arr78 A B) := Ξ» t Tm78 var78 lam78 app => lam78 _ _ _ (t Tm78 var78 lam78 app) def app78 {Ξ“ A B} : Tm78 Ξ“ (arr78 A B) β†’ Tm78 Ξ“ A β†’ Tm78 Ξ“ B := Ξ» t u Tm78 var78 lam78 app78 => app78 _ _ _ (t Tm78 var78 lam78 app78) (u Tm78 var78 lam78 app78) def v078 {Ξ“ A} : Tm78 (snoc78 Ξ“ A) A := var78 vz78 def v178 {Ξ“ A B} : Tm78 (snoc78 (snoc78 Ξ“ A) B) A := var78 (vs78 vz78) def v278 {Ξ“ A B C} : Tm78 (snoc78 (snoc78 (snoc78 Ξ“ A) B) C) A := var78 (vs78 (vs78 vz78)) def v378 {Ξ“ A B C D} : Tm78 (snoc78 (snoc78 (snoc78 (snoc78 Ξ“ A) B) C) D) A := var78 (vs78 (vs78 (vs78 vz78))) def v478 {Ξ“ A B C D E} : Tm78 (snoc78 (snoc78 (snoc78 (snoc78 (snoc78 Ξ“ A) B) C) D) E) A := var78 (vs78 (vs78 (vs78 (vs78 vz78)))) def test78 {Ξ“ A} : Tm78 Ξ“ (arr78 (arr78 A A) (arr78 A A)) := lam78 (lam78 (app78 v178 (app78 v178 (app78 v178 (app78 v178 (app78 v178 (app78 v178 v078))))))) def Ty79 : Type 1 := βˆ€ (Ty79 : Type) (ΞΉ : Ty79) (arr : Ty79 β†’ Ty79 β†’ Ty79) , Ty79 def ΞΉ79 : Ty79 := Ξ» _ ΞΉ79 _ => ΞΉ79 def arr79 : Ty79 β†’ Ty79 β†’ Ty79 := Ξ» A B Ty79 ΞΉ79 arr79 => arr79 (A Ty79 ΞΉ79 arr79) (B Ty79 ΞΉ79 arr79) def Con79 : Type 1 := βˆ€ (Con79 : Type) (nil : Con79) (snoc : Con79 β†’ Ty79 β†’ Con79) , Con79 def nil79 : Con79 := Ξ» Con79 nil79 snoc => nil79 def snoc79 : Con79 β†’ Ty79 β†’ Con79 := Ξ» Ξ“ A Con79 nil79 snoc79 => snoc79 (Ξ“ Con79 nil79 snoc79) A def Var79 : Con79 β†’ Ty79 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var79 : Con79 β†’ Ty79 β†’ Type) (vz : βˆ€ Ξ“ A, Var79 (snoc79 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var79 Ξ“ A β†’ Var79 (snoc79 Ξ“ B) A) , Var79 Ξ“ A def vz79 {Ξ“ A} : Var79 (snoc79 Ξ“ A) A := Ξ» Var79 vz79 vs => vz79 _ _ def vs79 {Ξ“ B A} : Var79 Ξ“ A β†’ Var79 (snoc79 Ξ“ B) A := Ξ» x Var79 vz79 vs79 => vs79 _ _ _ (x Var79 vz79 vs79) def Tm79 : Con79 β†’ Ty79 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm79 : Con79 β†’ Ty79 β†’ Type) (var : βˆ€ Ξ“ A , Var79 Ξ“ A β†’ Tm79 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm79 (snoc79 Ξ“ A) B β†’ Tm79 Ξ“ (arr79 A B)) (app : βˆ€ Ξ“ A B , Tm79 Ξ“ (arr79 A B) β†’ Tm79 Ξ“ A β†’ Tm79 Ξ“ B) , Tm79 Ξ“ A def var79 {Ξ“ A} : Var79 Ξ“ A β†’ Tm79 Ξ“ A := Ξ» x Tm79 var79 lam app => var79 _ _ x def lam79 {Ξ“ A B} : Tm79 (snoc79 Ξ“ A) B β†’ Tm79 Ξ“ (arr79 A B) := Ξ» t Tm79 var79 lam79 app => lam79 _ _ _ (t Tm79 var79 lam79 app) def app79 {Ξ“ A B} : Tm79 Ξ“ (arr79 A B) β†’ Tm79 Ξ“ A β†’ Tm79 Ξ“ B := Ξ» t u Tm79 var79 lam79 app79 => app79 _ _ _ (t Tm79 var79 lam79 app79) (u Tm79 var79 lam79 app79) def v079 {Ξ“ A} : Tm79 (snoc79 Ξ“ A) A := var79 vz79 def v179 {Ξ“ A B} : Tm79 (snoc79 (snoc79 Ξ“ A) B) A := var79 (vs79 vz79) def v279 {Ξ“ A B C} : Tm79 (snoc79 (snoc79 (snoc79 Ξ“ A) B) C) A := var79 (vs79 (vs79 vz79)) def v379 {Ξ“ A B C D} : Tm79 (snoc79 (snoc79 (snoc79 (snoc79 Ξ“ A) B) C) D) A := var79 (vs79 (vs79 (vs79 vz79))) def v479 {Ξ“ A B C D E} : Tm79 (snoc79 (snoc79 (snoc79 (snoc79 (snoc79 Ξ“ A) B) C) D) E) A := var79 (vs79 (vs79 (vs79 (vs79 vz79)))) def test79 {Ξ“ A} : Tm79 Ξ“ (arr79 (arr79 A A) (arr79 A A)) := lam79 (lam79 (app79 v179 (app79 v179 (app79 v179 (app79 v179 (app79 v179 (app79 v179 v079))))))) def Ty80 : Type 1 := βˆ€ (Ty80 : Type) (ΞΉ : Ty80) (arr : Ty80 β†’ Ty80 β†’ Ty80) , Ty80 def ΞΉ80 : Ty80 := Ξ» _ ΞΉ80 _ => ΞΉ80 def arr80 : Ty80 β†’ Ty80 β†’ Ty80 := Ξ» A B Ty80 ΞΉ80 arr80 => arr80 (A Ty80 ΞΉ80 arr80) (B Ty80 ΞΉ80 arr80) def Con80 : Type 1 := βˆ€ (Con80 : Type) (nil : Con80) (snoc : Con80 β†’ Ty80 β†’ Con80) , Con80 def nil80 : Con80 := Ξ» Con80 nil80 snoc => nil80 def snoc80 : Con80 β†’ Ty80 β†’ Con80 := Ξ» Ξ“ A Con80 nil80 snoc80 => snoc80 (Ξ“ Con80 nil80 snoc80) A def Var80 : Con80 β†’ Ty80 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var80 : Con80 β†’ Ty80 β†’ Type) (vz : βˆ€ Ξ“ A, Var80 (snoc80 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var80 Ξ“ A β†’ Var80 (snoc80 Ξ“ B) A) , Var80 Ξ“ A def vz80 {Ξ“ A} : Var80 (snoc80 Ξ“ A) A := Ξ» Var80 vz80 vs => vz80 _ _ def vs80 {Ξ“ B A} : Var80 Ξ“ A β†’ Var80 (snoc80 Ξ“ B) A := Ξ» x Var80 vz80 vs80 => vs80 _ _ _ (x Var80 vz80 vs80) def Tm80 : Con80 β†’ Ty80 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm80 : Con80 β†’ Ty80 β†’ Type) (var : βˆ€ Ξ“ A , Var80 Ξ“ A β†’ Tm80 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm80 (snoc80 Ξ“ A) B β†’ Tm80 Ξ“ (arr80 A B)) (app : βˆ€ Ξ“ A B , Tm80 Ξ“ (arr80 A B) β†’ Tm80 Ξ“ A β†’ Tm80 Ξ“ B) , Tm80 Ξ“ A def var80 {Ξ“ A} : Var80 Ξ“ A β†’ Tm80 Ξ“ A := Ξ» x Tm80 var80 lam app => var80 _ _ x def lam80 {Ξ“ A B} : Tm80 (snoc80 Ξ“ A) B β†’ Tm80 Ξ“ (arr80 A B) := Ξ» t Tm80 var80 lam80 app => lam80 _ _ _ (t Tm80 var80 lam80 app) def app80 {Ξ“ A B} : Tm80 Ξ“ (arr80 A B) β†’ Tm80 Ξ“ A β†’ Tm80 Ξ“ B := Ξ» t u Tm80 var80 lam80 app80 => app80 _ _ _ (t Tm80 var80 lam80 app80) (u Tm80 var80 lam80 app80) def v080 {Ξ“ A} : Tm80 (snoc80 Ξ“ A) A := var80 vz80 def v180 {Ξ“ A B} : Tm80 (snoc80 (snoc80 Ξ“ A) B) A := var80 (vs80 vz80) def v280 {Ξ“ A B C} : Tm80 (snoc80 (snoc80 (snoc80 Ξ“ A) B) C) A := var80 (vs80 (vs80 vz80)) def v380 {Ξ“ A B C D} : Tm80 (snoc80 (snoc80 (snoc80 (snoc80 Ξ“ A) B) C) D) A := var80 (vs80 (vs80 (vs80 vz80))) def v480 {Ξ“ A B C D E} : Tm80 (snoc80 (snoc80 (snoc80 (snoc80 (snoc80 Ξ“ A) B) C) D) E) A := var80 (vs80 (vs80 (vs80 (vs80 vz80)))) def test80 {Ξ“ A} : Tm80 Ξ“ (arr80 (arr80 A A) (arr80 A A)) := lam80 (lam80 (app80 v180 (app80 v180 (app80 v180 (app80 v180 (app80 v180 (app80 v180 v080))))))) def Ty81 : Type 1 := βˆ€ (Ty81 : Type) (ΞΉ : Ty81) (arr : Ty81 β†’ Ty81 β†’ Ty81) , Ty81 def ΞΉ81 : Ty81 := Ξ» _ ΞΉ81 _ => ΞΉ81 def arr81 : Ty81 β†’ Ty81 β†’ Ty81 := Ξ» A B Ty81 ΞΉ81 arr81 => arr81 (A Ty81 ΞΉ81 arr81) (B Ty81 ΞΉ81 arr81) def Con81 : Type 1 := βˆ€ (Con81 : Type) (nil : Con81) (snoc : Con81 β†’ Ty81 β†’ Con81) , Con81 def nil81 : Con81 := Ξ» Con81 nil81 snoc => nil81 def snoc81 : Con81 β†’ Ty81 β†’ Con81 := Ξ» Ξ“ A Con81 nil81 snoc81 => snoc81 (Ξ“ Con81 nil81 snoc81) A def Var81 : Con81 β†’ Ty81 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var81 : Con81 β†’ Ty81 β†’ Type) (vz : βˆ€ Ξ“ A, Var81 (snoc81 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var81 Ξ“ A β†’ Var81 (snoc81 Ξ“ B) A) , Var81 Ξ“ A def vz81 {Ξ“ A} : Var81 (snoc81 Ξ“ A) A := Ξ» Var81 vz81 vs => vz81 _ _ def vs81 {Ξ“ B A} : Var81 Ξ“ A β†’ Var81 (snoc81 Ξ“ B) A := Ξ» x Var81 vz81 vs81 => vs81 _ _ _ (x Var81 vz81 vs81) def Tm81 : Con81 β†’ Ty81 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm81 : Con81 β†’ Ty81 β†’ Type) (var : βˆ€ Ξ“ A , Var81 Ξ“ A β†’ Tm81 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm81 (snoc81 Ξ“ A) B β†’ Tm81 Ξ“ (arr81 A B)) (app : βˆ€ Ξ“ A B , Tm81 Ξ“ (arr81 A B) β†’ Tm81 Ξ“ A β†’ Tm81 Ξ“ B) , Tm81 Ξ“ A def var81 {Ξ“ A} : Var81 Ξ“ A β†’ Tm81 Ξ“ A := Ξ» x Tm81 var81 lam app => var81 _ _ x def lam81 {Ξ“ A B} : Tm81 (snoc81 Ξ“ A) B β†’ Tm81 Ξ“ (arr81 A B) := Ξ» t Tm81 var81 lam81 app => lam81 _ _ _ (t Tm81 var81 lam81 app) def app81 {Ξ“ A B} : Tm81 Ξ“ (arr81 A B) β†’ Tm81 Ξ“ A β†’ Tm81 Ξ“ B := Ξ» t u Tm81 var81 lam81 app81 => app81 _ _ _ (t Tm81 var81 lam81 app81) (u Tm81 var81 lam81 app81) def v081 {Ξ“ A} : Tm81 (snoc81 Ξ“ A) A := var81 vz81 def v181 {Ξ“ A B} : Tm81 (snoc81 (snoc81 Ξ“ A) B) A := var81 (vs81 vz81) def v281 {Ξ“ A B C} : Tm81 (snoc81 (snoc81 (snoc81 Ξ“ A) B) C) A := var81 (vs81 (vs81 vz81)) def v381 {Ξ“ A B C D} : Tm81 (snoc81 (snoc81 (snoc81 (snoc81 Ξ“ A) B) C) D) A := var81 (vs81 (vs81 (vs81 vz81))) def v481 {Ξ“ A B C D E} : Tm81 (snoc81 (snoc81 (snoc81 (snoc81 (snoc81 Ξ“ A) B) C) D) E) A := var81 (vs81 (vs81 (vs81 (vs81 vz81)))) def test81 {Ξ“ A} : Tm81 Ξ“ (arr81 (arr81 A A) (arr81 A A)) := lam81 (lam81 (app81 v181 (app81 v181 (app81 v181 (app81 v181 (app81 v181 (app81 v181 v081))))))) def Ty82 : Type 1 := βˆ€ (Ty82 : Type) (ΞΉ : Ty82) (arr : Ty82 β†’ Ty82 β†’ Ty82) , Ty82 def ΞΉ82 : Ty82 := Ξ» _ ΞΉ82 _ => ΞΉ82 def arr82 : Ty82 β†’ Ty82 β†’ Ty82 := Ξ» A B Ty82 ΞΉ82 arr82 => arr82 (A Ty82 ΞΉ82 arr82) (B Ty82 ΞΉ82 arr82) def Con82 : Type 1 := βˆ€ (Con82 : Type) (nil : Con82) (snoc : Con82 β†’ Ty82 β†’ Con82) , Con82 def nil82 : Con82 := Ξ» Con82 nil82 snoc => nil82 def snoc82 : Con82 β†’ Ty82 β†’ Con82 := Ξ» Ξ“ A Con82 nil82 snoc82 => snoc82 (Ξ“ Con82 nil82 snoc82) A def Var82 : Con82 β†’ Ty82 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var82 : Con82 β†’ Ty82 β†’ Type) (vz : βˆ€ Ξ“ A, Var82 (snoc82 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var82 Ξ“ A β†’ Var82 (snoc82 Ξ“ B) A) , Var82 Ξ“ A def vz82 {Ξ“ A} : Var82 (snoc82 Ξ“ A) A := Ξ» Var82 vz82 vs => vz82 _ _ def vs82 {Ξ“ B A} : Var82 Ξ“ A β†’ Var82 (snoc82 Ξ“ B) A := Ξ» x Var82 vz82 vs82 => vs82 _ _ _ (x Var82 vz82 vs82) def Tm82 : Con82 β†’ Ty82 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm82 : Con82 β†’ Ty82 β†’ Type) (var : βˆ€ Ξ“ A , Var82 Ξ“ A β†’ Tm82 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm82 (snoc82 Ξ“ A) B β†’ Tm82 Ξ“ (arr82 A B)) (app : βˆ€ Ξ“ A B , Tm82 Ξ“ (arr82 A B) β†’ Tm82 Ξ“ A β†’ Tm82 Ξ“ B) , Tm82 Ξ“ A def var82 {Ξ“ A} : Var82 Ξ“ A β†’ Tm82 Ξ“ A := Ξ» x Tm82 var82 lam app => var82 _ _ x def lam82 {Ξ“ A B} : Tm82 (snoc82 Ξ“ A) B β†’ Tm82 Ξ“ (arr82 A B) := Ξ» t Tm82 var82 lam82 app => lam82 _ _ _ (t Tm82 var82 lam82 app) def app82 {Ξ“ A B} : Tm82 Ξ“ (arr82 A B) β†’ Tm82 Ξ“ A β†’ Tm82 Ξ“ B := Ξ» t u Tm82 var82 lam82 app82 => app82 _ _ _ (t Tm82 var82 lam82 app82) (u Tm82 var82 lam82 app82) def v082 {Ξ“ A} : Tm82 (snoc82 Ξ“ A) A := var82 vz82 def v182 {Ξ“ A B} : Tm82 (snoc82 (snoc82 Ξ“ A) B) A := var82 (vs82 vz82) def v282 {Ξ“ A B C} : Tm82 (snoc82 (snoc82 (snoc82 Ξ“ A) B) C) A := var82 (vs82 (vs82 vz82)) def v382 {Ξ“ A B C D} : Tm82 (snoc82 (snoc82 (snoc82 (snoc82 Ξ“ A) B) C) D) A := var82 (vs82 (vs82 (vs82 vz82))) def v482 {Ξ“ A B C D E} : Tm82 (snoc82 (snoc82 (snoc82 (snoc82 (snoc82 Ξ“ A) B) C) D) E) A := var82 (vs82 (vs82 (vs82 (vs82 vz82)))) def test82 {Ξ“ A} : Tm82 Ξ“ (arr82 (arr82 A A) (arr82 A A)) := lam82 (lam82 (app82 v182 (app82 v182 (app82 v182 (app82 v182 (app82 v182 (app82 v182 v082))))))) def Ty83 : Type 1 := βˆ€ (Ty83 : Type) (ΞΉ : Ty83) (arr : Ty83 β†’ Ty83 β†’ Ty83) , Ty83 def ΞΉ83 : Ty83 := Ξ» _ ΞΉ83 _ => ΞΉ83 def arr83 : Ty83 β†’ Ty83 β†’ Ty83 := Ξ» A B Ty83 ΞΉ83 arr83 => arr83 (A Ty83 ΞΉ83 arr83) (B Ty83 ΞΉ83 arr83) def Con83 : Type 1 := βˆ€ (Con83 : Type) (nil : Con83) (snoc : Con83 β†’ Ty83 β†’ Con83) , Con83 def nil83 : Con83 := Ξ» Con83 nil83 snoc => nil83 def snoc83 : Con83 β†’ Ty83 β†’ Con83 := Ξ» Ξ“ A Con83 nil83 snoc83 => snoc83 (Ξ“ Con83 nil83 snoc83) A def Var83 : Con83 β†’ Ty83 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var83 : Con83 β†’ Ty83 β†’ Type) (vz : βˆ€ Ξ“ A, Var83 (snoc83 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var83 Ξ“ A β†’ Var83 (snoc83 Ξ“ B) A) , Var83 Ξ“ A def vz83 {Ξ“ A} : Var83 (snoc83 Ξ“ A) A := Ξ» Var83 vz83 vs => vz83 _ _ def vs83 {Ξ“ B A} : Var83 Ξ“ A β†’ Var83 (snoc83 Ξ“ B) A := Ξ» x Var83 vz83 vs83 => vs83 _ _ _ (x Var83 vz83 vs83) def Tm83 : Con83 β†’ Ty83 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm83 : Con83 β†’ Ty83 β†’ Type) (var : βˆ€ Ξ“ A , Var83 Ξ“ A β†’ Tm83 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm83 (snoc83 Ξ“ A) B β†’ Tm83 Ξ“ (arr83 A B)) (app : βˆ€ Ξ“ A B , Tm83 Ξ“ (arr83 A B) β†’ Tm83 Ξ“ A β†’ Tm83 Ξ“ B) , Tm83 Ξ“ A def var83 {Ξ“ A} : Var83 Ξ“ A β†’ Tm83 Ξ“ A := Ξ» x Tm83 var83 lam app => var83 _ _ x def lam83 {Ξ“ A B} : Tm83 (snoc83 Ξ“ A) B β†’ Tm83 Ξ“ (arr83 A B) := Ξ» t Tm83 var83 lam83 app => lam83 _ _ _ (t Tm83 var83 lam83 app) def app83 {Ξ“ A B} : Tm83 Ξ“ (arr83 A B) β†’ Tm83 Ξ“ A β†’ Tm83 Ξ“ B := Ξ» t u Tm83 var83 lam83 app83 => app83 _ _ _ (t Tm83 var83 lam83 app83) (u Tm83 var83 lam83 app83) def v083 {Ξ“ A} : Tm83 (snoc83 Ξ“ A) A := var83 vz83 def v183 {Ξ“ A B} : Tm83 (snoc83 (snoc83 Ξ“ A) B) A := var83 (vs83 vz83) def v283 {Ξ“ A B C} : Tm83 (snoc83 (snoc83 (snoc83 Ξ“ A) B) C) A := var83 (vs83 (vs83 vz83)) def v383 {Ξ“ A B C D} : Tm83 (snoc83 (snoc83 (snoc83 (snoc83 Ξ“ A) B) C) D) A := var83 (vs83 (vs83 (vs83 vz83))) def v483 {Ξ“ A B C D E} : Tm83 (snoc83 (snoc83 (snoc83 (snoc83 (snoc83 Ξ“ A) B) C) D) E) A := var83 (vs83 (vs83 (vs83 (vs83 vz83)))) def test83 {Ξ“ A} : Tm83 Ξ“ (arr83 (arr83 A A) (arr83 A A)) := lam83 (lam83 (app83 v183 (app83 v183 (app83 v183 (app83 v183 (app83 v183 (app83 v183 v083))))))) def Ty84 : Type 1 := βˆ€ (Ty84 : Type) (ΞΉ : Ty84) (arr : Ty84 β†’ Ty84 β†’ Ty84) , Ty84 def ΞΉ84 : Ty84 := Ξ» _ ΞΉ84 _ => ΞΉ84 def arr84 : Ty84 β†’ Ty84 β†’ Ty84 := Ξ» A B Ty84 ΞΉ84 arr84 => arr84 (A Ty84 ΞΉ84 arr84) (B Ty84 ΞΉ84 arr84) def Con84 : Type 1 := βˆ€ (Con84 : Type) (nil : Con84) (snoc : Con84 β†’ Ty84 β†’ Con84) , Con84 def nil84 : Con84 := Ξ» Con84 nil84 snoc => nil84 def snoc84 : Con84 β†’ Ty84 β†’ Con84 := Ξ» Ξ“ A Con84 nil84 snoc84 => snoc84 (Ξ“ Con84 nil84 snoc84) A def Var84 : Con84 β†’ Ty84 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var84 : Con84 β†’ Ty84 β†’ Type) (vz : βˆ€ Ξ“ A, Var84 (snoc84 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var84 Ξ“ A β†’ Var84 (snoc84 Ξ“ B) A) , Var84 Ξ“ A def vz84 {Ξ“ A} : Var84 (snoc84 Ξ“ A) A := Ξ» Var84 vz84 vs => vz84 _ _ def vs84 {Ξ“ B A} : Var84 Ξ“ A β†’ Var84 (snoc84 Ξ“ B) A := Ξ» x Var84 vz84 vs84 => vs84 _ _ _ (x Var84 vz84 vs84) def Tm84 : Con84 β†’ Ty84 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm84 : Con84 β†’ Ty84 β†’ Type) (var : βˆ€ Ξ“ A , Var84 Ξ“ A β†’ Tm84 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm84 (snoc84 Ξ“ A) B β†’ Tm84 Ξ“ (arr84 A B)) (app : βˆ€ Ξ“ A B , Tm84 Ξ“ (arr84 A B) β†’ Tm84 Ξ“ A β†’ Tm84 Ξ“ B) , Tm84 Ξ“ A def var84 {Ξ“ A} : Var84 Ξ“ A β†’ Tm84 Ξ“ A := Ξ» x Tm84 var84 lam app => var84 _ _ x def lam84 {Ξ“ A B} : Tm84 (snoc84 Ξ“ A) B β†’ Tm84 Ξ“ (arr84 A B) := Ξ» t Tm84 var84 lam84 app => lam84 _ _ _ (t Tm84 var84 lam84 app) def app84 {Ξ“ A B} : Tm84 Ξ“ (arr84 A B) β†’ Tm84 Ξ“ A β†’ Tm84 Ξ“ B := Ξ» t u Tm84 var84 lam84 app84 => app84 _ _ _ (t Tm84 var84 lam84 app84) (u Tm84 var84 lam84 app84) def v084 {Ξ“ A} : Tm84 (snoc84 Ξ“ A) A := var84 vz84 def v184 {Ξ“ A B} : Tm84 (snoc84 (snoc84 Ξ“ A) B) A := var84 (vs84 vz84) def v284 {Ξ“ A B C} : Tm84 (snoc84 (snoc84 (snoc84 Ξ“ A) B) C) A := var84 (vs84 (vs84 vz84)) def v384 {Ξ“ A B C D} : Tm84 (snoc84 (snoc84 (snoc84 (snoc84 Ξ“ A) B) C) D) A := var84 (vs84 (vs84 (vs84 vz84))) def v484 {Ξ“ A B C D E} : Tm84 (snoc84 (snoc84 (snoc84 (snoc84 (snoc84 Ξ“ A) B) C) D) E) A := var84 (vs84 (vs84 (vs84 (vs84 vz84)))) def test84 {Ξ“ A} : Tm84 Ξ“ (arr84 (arr84 A A) (arr84 A A)) := lam84 (lam84 (app84 v184 (app84 v184 (app84 v184 (app84 v184 (app84 v184 (app84 v184 v084))))))) def Ty85 : Type 1 := βˆ€ (Ty85 : Type) (ΞΉ : Ty85) (arr : Ty85 β†’ Ty85 β†’ Ty85) , Ty85 def ΞΉ85 : Ty85 := Ξ» _ ΞΉ85 _ => ΞΉ85 def arr85 : Ty85 β†’ Ty85 β†’ Ty85 := Ξ» A B Ty85 ΞΉ85 arr85 => arr85 (A Ty85 ΞΉ85 arr85) (B Ty85 ΞΉ85 arr85) def Con85 : Type 1 := βˆ€ (Con85 : Type) (nil : Con85) (snoc : Con85 β†’ Ty85 β†’ Con85) , Con85 def nil85 : Con85 := Ξ» Con85 nil85 snoc => nil85 def snoc85 : Con85 β†’ Ty85 β†’ Con85 := Ξ» Ξ“ A Con85 nil85 snoc85 => snoc85 (Ξ“ Con85 nil85 snoc85) A def Var85 : Con85 β†’ Ty85 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var85 : Con85 β†’ Ty85 β†’ Type) (vz : βˆ€ Ξ“ A, Var85 (snoc85 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var85 Ξ“ A β†’ Var85 (snoc85 Ξ“ B) A) , Var85 Ξ“ A def vz85 {Ξ“ A} : Var85 (snoc85 Ξ“ A) A := Ξ» Var85 vz85 vs => vz85 _ _ def vs85 {Ξ“ B A} : Var85 Ξ“ A β†’ Var85 (snoc85 Ξ“ B) A := Ξ» x Var85 vz85 vs85 => vs85 _ _ _ (x Var85 vz85 vs85) def Tm85 : Con85 β†’ Ty85 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm85 : Con85 β†’ Ty85 β†’ Type) (var : βˆ€ Ξ“ A , Var85 Ξ“ A β†’ Tm85 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm85 (snoc85 Ξ“ A) B β†’ Tm85 Ξ“ (arr85 A B)) (app : βˆ€ Ξ“ A B , Tm85 Ξ“ (arr85 A B) β†’ Tm85 Ξ“ A β†’ Tm85 Ξ“ B) , Tm85 Ξ“ A def var85 {Ξ“ A} : Var85 Ξ“ A β†’ Tm85 Ξ“ A := Ξ» x Tm85 var85 lam app => var85 _ _ x def lam85 {Ξ“ A B} : Tm85 (snoc85 Ξ“ A) B β†’ Tm85 Ξ“ (arr85 A B) := Ξ» t Tm85 var85 lam85 app => lam85 _ _ _ (t Tm85 var85 lam85 app) def app85 {Ξ“ A B} : Tm85 Ξ“ (arr85 A B) β†’ Tm85 Ξ“ A β†’ Tm85 Ξ“ B := Ξ» t u Tm85 var85 lam85 app85 => app85 _ _ _ (t Tm85 var85 lam85 app85) (u Tm85 var85 lam85 app85) def v085 {Ξ“ A} : Tm85 (snoc85 Ξ“ A) A := var85 vz85 def v185 {Ξ“ A B} : Tm85 (snoc85 (snoc85 Ξ“ A) B) A := var85 (vs85 vz85) def v285 {Ξ“ A B C} : Tm85 (snoc85 (snoc85 (snoc85 Ξ“ A) B) C) A := var85 (vs85 (vs85 vz85)) def v385 {Ξ“ A B C D} : Tm85 (snoc85 (snoc85 (snoc85 (snoc85 Ξ“ A) B) C) D) A := var85 (vs85 (vs85 (vs85 vz85))) def v485 {Ξ“ A B C D E} : Tm85 (snoc85 (snoc85 (snoc85 (snoc85 (snoc85 Ξ“ A) B) C) D) E) A := var85 (vs85 (vs85 (vs85 (vs85 vz85)))) def test85 {Ξ“ A} : Tm85 Ξ“ (arr85 (arr85 A A) (arr85 A A)) := lam85 (lam85 (app85 v185 (app85 v185 (app85 v185 (app85 v185 (app85 v185 (app85 v185 v085))))))) def Ty86 : Type 1 := βˆ€ (Ty86 : Type) (ΞΉ : Ty86) (arr : Ty86 β†’ Ty86 β†’ Ty86) , Ty86 def ΞΉ86 : Ty86 := Ξ» _ ΞΉ86 _ => ΞΉ86 def arr86 : Ty86 β†’ Ty86 β†’ Ty86 := Ξ» A B Ty86 ΞΉ86 arr86 => arr86 (A Ty86 ΞΉ86 arr86) (B Ty86 ΞΉ86 arr86) def Con86 : Type 1 := βˆ€ (Con86 : Type) (nil : Con86) (snoc : Con86 β†’ Ty86 β†’ Con86) , Con86 def nil86 : Con86 := Ξ» Con86 nil86 snoc => nil86 def snoc86 : Con86 β†’ Ty86 β†’ Con86 := Ξ» Ξ“ A Con86 nil86 snoc86 => snoc86 (Ξ“ Con86 nil86 snoc86) A def Var86 : Con86 β†’ Ty86 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var86 : Con86 β†’ Ty86 β†’ Type) (vz : βˆ€ Ξ“ A, Var86 (snoc86 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var86 Ξ“ A β†’ Var86 (snoc86 Ξ“ B) A) , Var86 Ξ“ A def vz86 {Ξ“ A} : Var86 (snoc86 Ξ“ A) A := Ξ» Var86 vz86 vs => vz86 _ _ def vs86 {Ξ“ B A} : Var86 Ξ“ A β†’ Var86 (snoc86 Ξ“ B) A := Ξ» x Var86 vz86 vs86 => vs86 _ _ _ (x Var86 vz86 vs86) def Tm86 : Con86 β†’ Ty86 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm86 : Con86 β†’ Ty86 β†’ Type) (var : βˆ€ Ξ“ A , Var86 Ξ“ A β†’ Tm86 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm86 (snoc86 Ξ“ A) B β†’ Tm86 Ξ“ (arr86 A B)) (app : βˆ€ Ξ“ A B , Tm86 Ξ“ (arr86 A B) β†’ Tm86 Ξ“ A β†’ Tm86 Ξ“ B) , Tm86 Ξ“ A def var86 {Ξ“ A} : Var86 Ξ“ A β†’ Tm86 Ξ“ A := Ξ» x Tm86 var86 lam app => var86 _ _ x def lam86 {Ξ“ A B} : Tm86 (snoc86 Ξ“ A) B β†’ Tm86 Ξ“ (arr86 A B) := Ξ» t Tm86 var86 lam86 app => lam86 _ _ _ (t Tm86 var86 lam86 app) def app86 {Ξ“ A B} : Tm86 Ξ“ (arr86 A B) β†’ Tm86 Ξ“ A β†’ Tm86 Ξ“ B := Ξ» t u Tm86 var86 lam86 app86 => app86 _ _ _ (t Tm86 var86 lam86 app86) (u Tm86 var86 lam86 app86) def v086 {Ξ“ A} : Tm86 (snoc86 Ξ“ A) A := var86 vz86 def v186 {Ξ“ A B} : Tm86 (snoc86 (snoc86 Ξ“ A) B) A := var86 (vs86 vz86) def v286 {Ξ“ A B C} : Tm86 (snoc86 (snoc86 (snoc86 Ξ“ A) B) C) A := var86 (vs86 (vs86 vz86)) def v386 {Ξ“ A B C D} : Tm86 (snoc86 (snoc86 (snoc86 (snoc86 Ξ“ A) B) C) D) A := var86 (vs86 (vs86 (vs86 vz86))) def v486 {Ξ“ A B C D E} : Tm86 (snoc86 (snoc86 (snoc86 (snoc86 (snoc86 Ξ“ A) B) C) D) E) A := var86 (vs86 (vs86 (vs86 (vs86 vz86)))) def test86 {Ξ“ A} : Tm86 Ξ“ (arr86 (arr86 A A) (arr86 A A)) := lam86 (lam86 (app86 v186 (app86 v186 (app86 v186 (app86 v186 (app86 v186 (app86 v186 v086))))))) def Ty87 : Type 1 := βˆ€ (Ty87 : Type) (ΞΉ : Ty87) (arr : Ty87 β†’ Ty87 β†’ Ty87) , Ty87 def ΞΉ87 : Ty87 := Ξ» _ ΞΉ87 _ => ΞΉ87 def arr87 : Ty87 β†’ Ty87 β†’ Ty87 := Ξ» A B Ty87 ΞΉ87 arr87 => arr87 (A Ty87 ΞΉ87 arr87) (B Ty87 ΞΉ87 arr87) def Con87 : Type 1 := βˆ€ (Con87 : Type) (nil : Con87) (snoc : Con87 β†’ Ty87 β†’ Con87) , Con87 def nil87 : Con87 := Ξ» Con87 nil87 snoc => nil87 def snoc87 : Con87 β†’ Ty87 β†’ Con87 := Ξ» Ξ“ A Con87 nil87 snoc87 => snoc87 (Ξ“ Con87 nil87 snoc87) A def Var87 : Con87 β†’ Ty87 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var87 : Con87 β†’ Ty87 β†’ Type) (vz : βˆ€ Ξ“ A, Var87 (snoc87 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var87 Ξ“ A β†’ Var87 (snoc87 Ξ“ B) A) , Var87 Ξ“ A def vz87 {Ξ“ A} : Var87 (snoc87 Ξ“ A) A := Ξ» Var87 vz87 vs => vz87 _ _ def vs87 {Ξ“ B A} : Var87 Ξ“ A β†’ Var87 (snoc87 Ξ“ B) A := Ξ» x Var87 vz87 vs87 => vs87 _ _ _ (x Var87 vz87 vs87) def Tm87 : Con87 β†’ Ty87 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm87 : Con87 β†’ Ty87 β†’ Type) (var : βˆ€ Ξ“ A , Var87 Ξ“ A β†’ Tm87 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm87 (snoc87 Ξ“ A) B β†’ Tm87 Ξ“ (arr87 A B)) (app : βˆ€ Ξ“ A B , Tm87 Ξ“ (arr87 A B) β†’ Tm87 Ξ“ A β†’ Tm87 Ξ“ B) , Tm87 Ξ“ A def var87 {Ξ“ A} : Var87 Ξ“ A β†’ Tm87 Ξ“ A := Ξ» x Tm87 var87 lam app => var87 _ _ x def lam87 {Ξ“ A B} : Tm87 (snoc87 Ξ“ A) B β†’ Tm87 Ξ“ (arr87 A B) := Ξ» t Tm87 var87 lam87 app => lam87 _ _ _ (t Tm87 var87 lam87 app) def app87 {Ξ“ A B} : Tm87 Ξ“ (arr87 A B) β†’ Tm87 Ξ“ A β†’ Tm87 Ξ“ B := Ξ» t u Tm87 var87 lam87 app87 => app87 _ _ _ (t Tm87 var87 lam87 app87) (u Tm87 var87 lam87 app87) def v087 {Ξ“ A} : Tm87 (snoc87 Ξ“ A) A := var87 vz87 def v187 {Ξ“ A B} : Tm87 (snoc87 (snoc87 Ξ“ A) B) A := var87 (vs87 vz87) def v287 {Ξ“ A B C} : Tm87 (snoc87 (snoc87 (snoc87 Ξ“ A) B) C) A := var87 (vs87 (vs87 vz87)) def v387 {Ξ“ A B C D} : Tm87 (snoc87 (snoc87 (snoc87 (snoc87 Ξ“ A) B) C) D) A := var87 (vs87 (vs87 (vs87 vz87))) def v487 {Ξ“ A B C D E} : Tm87 (snoc87 (snoc87 (snoc87 (snoc87 (snoc87 Ξ“ A) B) C) D) E) A := var87 (vs87 (vs87 (vs87 (vs87 vz87)))) def test87 {Ξ“ A} : Tm87 Ξ“ (arr87 (arr87 A A) (arr87 A A)) := lam87 (lam87 (app87 v187 (app87 v187 (app87 v187 (app87 v187 (app87 v187 (app87 v187 v087))))))) def Ty88 : Type 1 := βˆ€ (Ty88 : Type) (ΞΉ : Ty88) (arr : Ty88 β†’ Ty88 β†’ Ty88) , Ty88 def ΞΉ88 : Ty88 := Ξ» _ ΞΉ88 _ => ΞΉ88 def arr88 : Ty88 β†’ Ty88 β†’ Ty88 := Ξ» A B Ty88 ΞΉ88 arr88 => arr88 (A Ty88 ΞΉ88 arr88) (B Ty88 ΞΉ88 arr88) def Con88 : Type 1 := βˆ€ (Con88 : Type) (nil : Con88) (snoc : Con88 β†’ Ty88 β†’ Con88) , Con88 def nil88 : Con88 := Ξ» Con88 nil88 snoc => nil88 def snoc88 : Con88 β†’ Ty88 β†’ Con88 := Ξ» Ξ“ A Con88 nil88 snoc88 => snoc88 (Ξ“ Con88 nil88 snoc88) A def Var88 : Con88 β†’ Ty88 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var88 : Con88 β†’ Ty88 β†’ Type) (vz : βˆ€ Ξ“ A, Var88 (snoc88 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var88 Ξ“ A β†’ Var88 (snoc88 Ξ“ B) A) , Var88 Ξ“ A def vz88 {Ξ“ A} : Var88 (snoc88 Ξ“ A) A := Ξ» Var88 vz88 vs => vz88 _ _ def vs88 {Ξ“ B A} : Var88 Ξ“ A β†’ Var88 (snoc88 Ξ“ B) A := Ξ» x Var88 vz88 vs88 => vs88 _ _ _ (x Var88 vz88 vs88) def Tm88 : Con88 β†’ Ty88 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm88 : Con88 β†’ Ty88 β†’ Type) (var : βˆ€ Ξ“ A , Var88 Ξ“ A β†’ Tm88 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm88 (snoc88 Ξ“ A) B β†’ Tm88 Ξ“ (arr88 A B)) (app : βˆ€ Ξ“ A B , Tm88 Ξ“ (arr88 A B) β†’ Tm88 Ξ“ A β†’ Tm88 Ξ“ B) , Tm88 Ξ“ A def var88 {Ξ“ A} : Var88 Ξ“ A β†’ Tm88 Ξ“ A := Ξ» x Tm88 var88 lam app => var88 _ _ x def lam88 {Ξ“ A B} : Tm88 (snoc88 Ξ“ A) B β†’ Tm88 Ξ“ (arr88 A B) := Ξ» t Tm88 var88 lam88 app => lam88 _ _ _ (t Tm88 var88 lam88 app) def app88 {Ξ“ A B} : Tm88 Ξ“ (arr88 A B) β†’ Tm88 Ξ“ A β†’ Tm88 Ξ“ B := Ξ» t u Tm88 var88 lam88 app88 => app88 _ _ _ (t Tm88 var88 lam88 app88) (u Tm88 var88 lam88 app88) def v088 {Ξ“ A} : Tm88 (snoc88 Ξ“ A) A := var88 vz88 def v188 {Ξ“ A B} : Tm88 (snoc88 (snoc88 Ξ“ A) B) A := var88 (vs88 vz88) def v288 {Ξ“ A B C} : Tm88 (snoc88 (snoc88 (snoc88 Ξ“ A) B) C) A := var88 (vs88 (vs88 vz88)) def v388 {Ξ“ A B C D} : Tm88 (snoc88 (snoc88 (snoc88 (snoc88 Ξ“ A) B) C) D) A := var88 (vs88 (vs88 (vs88 vz88))) def v488 {Ξ“ A B C D E} : Tm88 (snoc88 (snoc88 (snoc88 (snoc88 (snoc88 Ξ“ A) B) C) D) E) A := var88 (vs88 (vs88 (vs88 (vs88 vz88)))) def test88 {Ξ“ A} : Tm88 Ξ“ (arr88 (arr88 A A) (arr88 A A)) := lam88 (lam88 (app88 v188 (app88 v188 (app88 v188 (app88 v188 (app88 v188 (app88 v188 v088))))))) def Ty89 : Type 1 := βˆ€ (Ty89 : Type) (ΞΉ : Ty89) (arr : Ty89 β†’ Ty89 β†’ Ty89) , Ty89 def ΞΉ89 : Ty89 := Ξ» _ ΞΉ89 _ => ΞΉ89 def arr89 : Ty89 β†’ Ty89 β†’ Ty89 := Ξ» A B Ty89 ΞΉ89 arr89 => arr89 (A Ty89 ΞΉ89 arr89) (B Ty89 ΞΉ89 arr89) def Con89 : Type 1 := βˆ€ (Con89 : Type) (nil : Con89) (snoc : Con89 β†’ Ty89 β†’ Con89) , Con89 def nil89 : Con89 := Ξ» Con89 nil89 snoc => nil89 def snoc89 : Con89 β†’ Ty89 β†’ Con89 := Ξ» Ξ“ A Con89 nil89 snoc89 => snoc89 (Ξ“ Con89 nil89 snoc89) A def Var89 : Con89 β†’ Ty89 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var89 : Con89 β†’ Ty89 β†’ Type) (vz : βˆ€ Ξ“ A, Var89 (snoc89 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var89 Ξ“ A β†’ Var89 (snoc89 Ξ“ B) A) , Var89 Ξ“ A def vz89 {Ξ“ A} : Var89 (snoc89 Ξ“ A) A := Ξ» Var89 vz89 vs => vz89 _ _ def vs89 {Ξ“ B A} : Var89 Ξ“ A β†’ Var89 (snoc89 Ξ“ B) A := Ξ» x Var89 vz89 vs89 => vs89 _ _ _ (x Var89 vz89 vs89) def Tm89 : Con89 β†’ Ty89 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm89 : Con89 β†’ Ty89 β†’ Type) (var : βˆ€ Ξ“ A , Var89 Ξ“ A β†’ Tm89 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm89 (snoc89 Ξ“ A) B β†’ Tm89 Ξ“ (arr89 A B)) (app : βˆ€ Ξ“ A B , Tm89 Ξ“ (arr89 A B) β†’ Tm89 Ξ“ A β†’ Tm89 Ξ“ B) , Tm89 Ξ“ A def var89 {Ξ“ A} : Var89 Ξ“ A β†’ Tm89 Ξ“ A := Ξ» x Tm89 var89 lam app => var89 _ _ x def lam89 {Ξ“ A B} : Tm89 (snoc89 Ξ“ A) B β†’ Tm89 Ξ“ (arr89 A B) := Ξ» t Tm89 var89 lam89 app => lam89 _ _ _ (t Tm89 var89 lam89 app) def app89 {Ξ“ A B} : Tm89 Ξ“ (arr89 A B) β†’ Tm89 Ξ“ A β†’ Tm89 Ξ“ B := Ξ» t u Tm89 var89 lam89 app89 => app89 _ _ _ (t Tm89 var89 lam89 app89) (u Tm89 var89 lam89 app89) def v089 {Ξ“ A} : Tm89 (snoc89 Ξ“ A) A := var89 vz89 def v189 {Ξ“ A B} : Tm89 (snoc89 (snoc89 Ξ“ A) B) A := var89 (vs89 vz89) def v289 {Ξ“ A B C} : Tm89 (snoc89 (snoc89 (snoc89 Ξ“ A) B) C) A := var89 (vs89 (vs89 vz89)) def v389 {Ξ“ A B C D} : Tm89 (snoc89 (snoc89 (snoc89 (snoc89 Ξ“ A) B) C) D) A := var89 (vs89 (vs89 (vs89 vz89))) def v489 {Ξ“ A B C D E} : Tm89 (snoc89 (snoc89 (snoc89 (snoc89 (snoc89 Ξ“ A) B) C) D) E) A := var89 (vs89 (vs89 (vs89 (vs89 vz89)))) def test89 {Ξ“ A} : Tm89 Ξ“ (arr89 (arr89 A A) (arr89 A A)) := lam89 (lam89 (app89 v189 (app89 v189 (app89 v189 (app89 v189 (app89 v189 (app89 v189 v089))))))) def Ty90 : Type 1 := βˆ€ (Ty90 : Type) (ΞΉ : Ty90) (arr : Ty90 β†’ Ty90 β†’ Ty90) , Ty90 def ΞΉ90 : Ty90 := Ξ» _ ΞΉ90 _ => ΞΉ90 def arr90 : Ty90 β†’ Ty90 β†’ Ty90 := Ξ» A B Ty90 ΞΉ90 arr90 => arr90 (A Ty90 ΞΉ90 arr90) (B Ty90 ΞΉ90 arr90) def Con90 : Type 1 := βˆ€ (Con90 : Type) (nil : Con90) (snoc : Con90 β†’ Ty90 β†’ Con90) , Con90 def nil90 : Con90 := Ξ» Con90 nil90 snoc => nil90 def snoc90 : Con90 β†’ Ty90 β†’ Con90 := Ξ» Ξ“ A Con90 nil90 snoc90 => snoc90 (Ξ“ Con90 nil90 snoc90) A def Var90 : Con90 β†’ Ty90 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var90 : Con90 β†’ Ty90 β†’ Type) (vz : βˆ€ Ξ“ A, Var90 (snoc90 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var90 Ξ“ A β†’ Var90 (snoc90 Ξ“ B) A) , Var90 Ξ“ A def vz90 {Ξ“ A} : Var90 (snoc90 Ξ“ A) A := Ξ» Var90 vz90 vs => vz90 _ _ def vs90 {Ξ“ B A} : Var90 Ξ“ A β†’ Var90 (snoc90 Ξ“ B) A := Ξ» x Var90 vz90 vs90 => vs90 _ _ _ (x Var90 vz90 vs90) def Tm90 : Con90 β†’ Ty90 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm90 : Con90 β†’ Ty90 β†’ Type) (var : βˆ€ Ξ“ A , Var90 Ξ“ A β†’ Tm90 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm90 (snoc90 Ξ“ A) B β†’ Tm90 Ξ“ (arr90 A B)) (app : βˆ€ Ξ“ A B , Tm90 Ξ“ (arr90 A B) β†’ Tm90 Ξ“ A β†’ Tm90 Ξ“ B) , Tm90 Ξ“ A def var90 {Ξ“ A} : Var90 Ξ“ A β†’ Tm90 Ξ“ A := Ξ» x Tm90 var90 lam app => var90 _ _ x def lam90 {Ξ“ A B} : Tm90 (snoc90 Ξ“ A) B β†’ Tm90 Ξ“ (arr90 A B) := Ξ» t Tm90 var90 lam90 app => lam90 _ _ _ (t Tm90 var90 lam90 app) def app90 {Ξ“ A B} : Tm90 Ξ“ (arr90 A B) β†’ Tm90 Ξ“ A β†’ Tm90 Ξ“ B := Ξ» t u Tm90 var90 lam90 app90 => app90 _ _ _ (t Tm90 var90 lam90 app90) (u Tm90 var90 lam90 app90) def v090 {Ξ“ A} : Tm90 (snoc90 Ξ“ A) A := var90 vz90 def v190 {Ξ“ A B} : Tm90 (snoc90 (snoc90 Ξ“ A) B) A := var90 (vs90 vz90) def v290 {Ξ“ A B C} : Tm90 (snoc90 (snoc90 (snoc90 Ξ“ A) B) C) A := var90 (vs90 (vs90 vz90)) def v390 {Ξ“ A B C D} : Tm90 (snoc90 (snoc90 (snoc90 (snoc90 Ξ“ A) B) C) D) A := var90 (vs90 (vs90 (vs90 vz90))) def v490 {Ξ“ A B C D E} : Tm90 (snoc90 (snoc90 (snoc90 (snoc90 (snoc90 Ξ“ A) B) C) D) E) A := var90 (vs90 (vs90 (vs90 (vs90 vz90)))) def test90 {Ξ“ A} : Tm90 Ξ“ (arr90 (arr90 A A) (arr90 A A)) := lam90 (lam90 (app90 v190 (app90 v190 (app90 v190 (app90 v190 (app90 v190 (app90 v190 v090))))))) def Ty91 : Type 1 := βˆ€ (Ty91 : Type) (ΞΉ : Ty91) (arr : Ty91 β†’ Ty91 β†’ Ty91) , Ty91 def ΞΉ91 : Ty91 := Ξ» _ ΞΉ91 _ => ΞΉ91 def arr91 : Ty91 β†’ Ty91 β†’ Ty91 := Ξ» A B Ty91 ΞΉ91 arr91 => arr91 (A Ty91 ΞΉ91 arr91) (B Ty91 ΞΉ91 arr91) def Con91 : Type 1 := βˆ€ (Con91 : Type) (nil : Con91) (snoc : Con91 β†’ Ty91 β†’ Con91) , Con91 def nil91 : Con91 := Ξ» Con91 nil91 snoc => nil91 def snoc91 : Con91 β†’ Ty91 β†’ Con91 := Ξ» Ξ“ A Con91 nil91 snoc91 => snoc91 (Ξ“ Con91 nil91 snoc91) A def Var91 : Con91 β†’ Ty91 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var91 : Con91 β†’ Ty91 β†’ Type) (vz : βˆ€ Ξ“ A, Var91 (snoc91 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var91 Ξ“ A β†’ Var91 (snoc91 Ξ“ B) A) , Var91 Ξ“ A def vz91 {Ξ“ A} : Var91 (snoc91 Ξ“ A) A := Ξ» Var91 vz91 vs => vz91 _ _ def vs91 {Ξ“ B A} : Var91 Ξ“ A β†’ Var91 (snoc91 Ξ“ B) A := Ξ» x Var91 vz91 vs91 => vs91 _ _ _ (x Var91 vz91 vs91) def Tm91 : Con91 β†’ Ty91 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm91 : Con91 β†’ Ty91 β†’ Type) (var : βˆ€ Ξ“ A , Var91 Ξ“ A β†’ Tm91 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm91 (snoc91 Ξ“ A) B β†’ Tm91 Ξ“ (arr91 A B)) (app : βˆ€ Ξ“ A B , Tm91 Ξ“ (arr91 A B) β†’ Tm91 Ξ“ A β†’ Tm91 Ξ“ B) , Tm91 Ξ“ A def var91 {Ξ“ A} : Var91 Ξ“ A β†’ Tm91 Ξ“ A := Ξ» x Tm91 var91 lam app => var91 _ _ x def lam91 {Ξ“ A B} : Tm91 (snoc91 Ξ“ A) B β†’ Tm91 Ξ“ (arr91 A B) := Ξ» t Tm91 var91 lam91 app => lam91 _ _ _ (t Tm91 var91 lam91 app) def app91 {Ξ“ A B} : Tm91 Ξ“ (arr91 A B) β†’ Tm91 Ξ“ A β†’ Tm91 Ξ“ B := Ξ» t u Tm91 var91 lam91 app91 => app91 _ _ _ (t Tm91 var91 lam91 app91) (u Tm91 var91 lam91 app91) def v091 {Ξ“ A} : Tm91 (snoc91 Ξ“ A) A := var91 vz91 def v191 {Ξ“ A B} : Tm91 (snoc91 (snoc91 Ξ“ A) B) A := var91 (vs91 vz91) def v291 {Ξ“ A B C} : Tm91 (snoc91 (snoc91 (snoc91 Ξ“ A) B) C) A := var91 (vs91 (vs91 vz91)) def v391 {Ξ“ A B C D} : Tm91 (snoc91 (snoc91 (snoc91 (snoc91 Ξ“ A) B) C) D) A := var91 (vs91 (vs91 (vs91 vz91))) def v491 {Ξ“ A B C D E} : Tm91 (snoc91 (snoc91 (snoc91 (snoc91 (snoc91 Ξ“ A) B) C) D) E) A := var91 (vs91 (vs91 (vs91 (vs91 vz91)))) def test91 {Ξ“ A} : Tm91 Ξ“ (arr91 (arr91 A A) (arr91 A A)) := lam91 (lam91 (app91 v191 (app91 v191 (app91 v191 (app91 v191 (app91 v191 (app91 v191 v091))))))) def Ty92 : Type 1 := βˆ€ (Ty92 : Type) (ΞΉ : Ty92) (arr : Ty92 β†’ Ty92 β†’ Ty92) , Ty92 def ΞΉ92 : Ty92 := Ξ» _ ΞΉ92 _ => ΞΉ92 def arr92 : Ty92 β†’ Ty92 β†’ Ty92 := Ξ» A B Ty92 ΞΉ92 arr92 => arr92 (A Ty92 ΞΉ92 arr92) (B Ty92 ΞΉ92 arr92) def Con92 : Type 1 := βˆ€ (Con92 : Type) (nil : Con92) (snoc : Con92 β†’ Ty92 β†’ Con92) , Con92 def nil92 : Con92 := Ξ» Con92 nil92 snoc => nil92 def snoc92 : Con92 β†’ Ty92 β†’ Con92 := Ξ» Ξ“ A Con92 nil92 snoc92 => snoc92 (Ξ“ Con92 nil92 snoc92) A def Var92 : Con92 β†’ Ty92 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var92 : Con92 β†’ Ty92 β†’ Type) (vz : βˆ€ Ξ“ A, Var92 (snoc92 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var92 Ξ“ A β†’ Var92 (snoc92 Ξ“ B) A) , Var92 Ξ“ A def vz92 {Ξ“ A} : Var92 (snoc92 Ξ“ A) A := Ξ» Var92 vz92 vs => vz92 _ _ def vs92 {Ξ“ B A} : Var92 Ξ“ A β†’ Var92 (snoc92 Ξ“ B) A := Ξ» x Var92 vz92 vs92 => vs92 _ _ _ (x Var92 vz92 vs92) def Tm92 : Con92 β†’ Ty92 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm92 : Con92 β†’ Ty92 β†’ Type) (var : βˆ€ Ξ“ A , Var92 Ξ“ A β†’ Tm92 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm92 (snoc92 Ξ“ A) B β†’ Tm92 Ξ“ (arr92 A B)) (app : βˆ€ Ξ“ A B , Tm92 Ξ“ (arr92 A B) β†’ Tm92 Ξ“ A β†’ Tm92 Ξ“ B) , Tm92 Ξ“ A def var92 {Ξ“ A} : Var92 Ξ“ A β†’ Tm92 Ξ“ A := Ξ» x Tm92 var92 lam app => var92 _ _ x def lam92 {Ξ“ A B} : Tm92 (snoc92 Ξ“ A) B β†’ Tm92 Ξ“ (arr92 A B) := Ξ» t Tm92 var92 lam92 app => lam92 _ _ _ (t Tm92 var92 lam92 app) def app92 {Ξ“ A B} : Tm92 Ξ“ (arr92 A B) β†’ Tm92 Ξ“ A β†’ Tm92 Ξ“ B := Ξ» t u Tm92 var92 lam92 app92 => app92 _ _ _ (t Tm92 var92 lam92 app92) (u Tm92 var92 lam92 app92) def v092 {Ξ“ A} : Tm92 (snoc92 Ξ“ A) A := var92 vz92 def v192 {Ξ“ A B} : Tm92 (snoc92 (snoc92 Ξ“ A) B) A := var92 (vs92 vz92) def v292 {Ξ“ A B C} : Tm92 (snoc92 (snoc92 (snoc92 Ξ“ A) B) C) A := var92 (vs92 (vs92 vz92)) def v392 {Ξ“ A B C D} : Tm92 (snoc92 (snoc92 (snoc92 (snoc92 Ξ“ A) B) C) D) A := var92 (vs92 (vs92 (vs92 vz92))) def v492 {Ξ“ A B C D E} : Tm92 (snoc92 (snoc92 (snoc92 (snoc92 (snoc92 Ξ“ A) B) C) D) E) A := var92 (vs92 (vs92 (vs92 (vs92 vz92)))) def test92 {Ξ“ A} : Tm92 Ξ“ (arr92 (arr92 A A) (arr92 A A)) := lam92 (lam92 (app92 v192 (app92 v192 (app92 v192 (app92 v192 (app92 v192 (app92 v192 v092))))))) def Ty93 : Type 1 := βˆ€ (Ty93 : Type) (ΞΉ : Ty93) (arr : Ty93 β†’ Ty93 β†’ Ty93) , Ty93 def ΞΉ93 : Ty93 := Ξ» _ ΞΉ93 _ => ΞΉ93 def arr93 : Ty93 β†’ Ty93 β†’ Ty93 := Ξ» A B Ty93 ΞΉ93 arr93 => arr93 (A Ty93 ΞΉ93 arr93) (B Ty93 ΞΉ93 arr93) def Con93 : Type 1 := βˆ€ (Con93 : Type) (nil : Con93) (snoc : Con93 β†’ Ty93 β†’ Con93) , Con93 def nil93 : Con93 := Ξ» Con93 nil93 snoc => nil93 def snoc93 : Con93 β†’ Ty93 β†’ Con93 := Ξ» Ξ“ A Con93 nil93 snoc93 => snoc93 (Ξ“ Con93 nil93 snoc93) A def Var93 : Con93 β†’ Ty93 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var93 : Con93 β†’ Ty93 β†’ Type) (vz : βˆ€ Ξ“ A, Var93 (snoc93 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var93 Ξ“ A β†’ Var93 (snoc93 Ξ“ B) A) , Var93 Ξ“ A def vz93 {Ξ“ A} : Var93 (snoc93 Ξ“ A) A := Ξ» Var93 vz93 vs => vz93 _ _ def vs93 {Ξ“ B A} : Var93 Ξ“ A β†’ Var93 (snoc93 Ξ“ B) A := Ξ» x Var93 vz93 vs93 => vs93 _ _ _ (x Var93 vz93 vs93) def Tm93 : Con93 β†’ Ty93 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm93 : Con93 β†’ Ty93 β†’ Type) (var : βˆ€ Ξ“ A , Var93 Ξ“ A β†’ Tm93 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm93 (snoc93 Ξ“ A) B β†’ Tm93 Ξ“ (arr93 A B)) (app : βˆ€ Ξ“ A B , Tm93 Ξ“ (arr93 A B) β†’ Tm93 Ξ“ A β†’ Tm93 Ξ“ B) , Tm93 Ξ“ A def var93 {Ξ“ A} : Var93 Ξ“ A β†’ Tm93 Ξ“ A := Ξ» x Tm93 var93 lam app => var93 _ _ x def lam93 {Ξ“ A B} : Tm93 (snoc93 Ξ“ A) B β†’ Tm93 Ξ“ (arr93 A B) := Ξ» t Tm93 var93 lam93 app => lam93 _ _ _ (t Tm93 var93 lam93 app) def app93 {Ξ“ A B} : Tm93 Ξ“ (arr93 A B) β†’ Tm93 Ξ“ A β†’ Tm93 Ξ“ B := Ξ» t u Tm93 var93 lam93 app93 => app93 _ _ _ (t Tm93 var93 lam93 app93) (u Tm93 var93 lam93 app93) def v093 {Ξ“ A} : Tm93 (snoc93 Ξ“ A) A := var93 vz93 def v193 {Ξ“ A B} : Tm93 (snoc93 (snoc93 Ξ“ A) B) A := var93 (vs93 vz93) def v293 {Ξ“ A B C} : Tm93 (snoc93 (snoc93 (snoc93 Ξ“ A) B) C) A := var93 (vs93 (vs93 vz93)) def v393 {Ξ“ A B C D} : Tm93 (snoc93 (snoc93 (snoc93 (snoc93 Ξ“ A) B) C) D) A := var93 (vs93 (vs93 (vs93 vz93))) def v493 {Ξ“ A B C D E} : Tm93 (snoc93 (snoc93 (snoc93 (snoc93 (snoc93 Ξ“ A) B) C) D) E) A := var93 (vs93 (vs93 (vs93 (vs93 vz93)))) def test93 {Ξ“ A} : Tm93 Ξ“ (arr93 (arr93 A A) (arr93 A A)) := lam93 (lam93 (app93 v193 (app93 v193 (app93 v193 (app93 v193 (app93 v193 (app93 v193 v093))))))) def Ty94 : Type 1 := βˆ€ (Ty94 : Type) (ΞΉ : Ty94) (arr : Ty94 β†’ Ty94 β†’ Ty94) , Ty94 def ΞΉ94 : Ty94 := Ξ» _ ΞΉ94 _ => ΞΉ94 def arr94 : Ty94 β†’ Ty94 β†’ Ty94 := Ξ» A B Ty94 ΞΉ94 arr94 => arr94 (A Ty94 ΞΉ94 arr94) (B Ty94 ΞΉ94 arr94) def Con94 : Type 1 := βˆ€ (Con94 : Type) (nil : Con94) (snoc : Con94 β†’ Ty94 β†’ Con94) , Con94 def nil94 : Con94 := Ξ» Con94 nil94 snoc => nil94 def snoc94 : Con94 β†’ Ty94 β†’ Con94 := Ξ» Ξ“ A Con94 nil94 snoc94 => snoc94 (Ξ“ Con94 nil94 snoc94) A def Var94 : Con94 β†’ Ty94 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var94 : Con94 β†’ Ty94 β†’ Type) (vz : βˆ€ Ξ“ A, Var94 (snoc94 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var94 Ξ“ A β†’ Var94 (snoc94 Ξ“ B) A) , Var94 Ξ“ A def vz94 {Ξ“ A} : Var94 (snoc94 Ξ“ A) A := Ξ» Var94 vz94 vs => vz94 _ _ def vs94 {Ξ“ B A} : Var94 Ξ“ A β†’ Var94 (snoc94 Ξ“ B) A := Ξ» x Var94 vz94 vs94 => vs94 _ _ _ (x Var94 vz94 vs94) def Tm94 : Con94 β†’ Ty94 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm94 : Con94 β†’ Ty94 β†’ Type) (var : βˆ€ Ξ“ A , Var94 Ξ“ A β†’ Tm94 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm94 (snoc94 Ξ“ A) B β†’ Tm94 Ξ“ (arr94 A B)) (app : βˆ€ Ξ“ A B , Tm94 Ξ“ (arr94 A B) β†’ Tm94 Ξ“ A β†’ Tm94 Ξ“ B) , Tm94 Ξ“ A def var94 {Ξ“ A} : Var94 Ξ“ A β†’ Tm94 Ξ“ A := Ξ» x Tm94 var94 lam app => var94 _ _ x def lam94 {Ξ“ A B} : Tm94 (snoc94 Ξ“ A) B β†’ Tm94 Ξ“ (arr94 A B) := Ξ» t Tm94 var94 lam94 app => lam94 _ _ _ (t Tm94 var94 lam94 app) def app94 {Ξ“ A B} : Tm94 Ξ“ (arr94 A B) β†’ Tm94 Ξ“ A β†’ Tm94 Ξ“ B := Ξ» t u Tm94 var94 lam94 app94 => app94 _ _ _ (t Tm94 var94 lam94 app94) (u Tm94 var94 lam94 app94) def v094 {Ξ“ A} : Tm94 (snoc94 Ξ“ A) A := var94 vz94 def v194 {Ξ“ A B} : Tm94 (snoc94 (snoc94 Ξ“ A) B) A := var94 (vs94 vz94) def v294 {Ξ“ A B C} : Tm94 (snoc94 (snoc94 (snoc94 Ξ“ A) B) C) A := var94 (vs94 (vs94 vz94)) def v394 {Ξ“ A B C D} : Tm94 (snoc94 (snoc94 (snoc94 (snoc94 Ξ“ A) B) C) D) A := var94 (vs94 (vs94 (vs94 vz94))) def v494 {Ξ“ A B C D E} : Tm94 (snoc94 (snoc94 (snoc94 (snoc94 (snoc94 Ξ“ A) B) C) D) E) A := var94 (vs94 (vs94 (vs94 (vs94 vz94)))) def test94 {Ξ“ A} : Tm94 Ξ“ (arr94 (arr94 A A) (arr94 A A)) := lam94 (lam94 (app94 v194 (app94 v194 (app94 v194 (app94 v194 (app94 v194 (app94 v194 v094))))))) def Ty95 : Type 1 := βˆ€ (Ty95 : Type) (ΞΉ : Ty95) (arr : Ty95 β†’ Ty95 β†’ Ty95) , Ty95 def ΞΉ95 : Ty95 := Ξ» _ ΞΉ95 _ => ΞΉ95 def arr95 : Ty95 β†’ Ty95 β†’ Ty95 := Ξ» A B Ty95 ΞΉ95 arr95 => arr95 (A Ty95 ΞΉ95 arr95) (B Ty95 ΞΉ95 arr95) def Con95 : Type 1 := βˆ€ (Con95 : Type) (nil : Con95) (snoc : Con95 β†’ Ty95 β†’ Con95) , Con95 def nil95 : Con95 := Ξ» Con95 nil95 snoc => nil95 def snoc95 : Con95 β†’ Ty95 β†’ Con95 := Ξ» Ξ“ A Con95 nil95 snoc95 => snoc95 (Ξ“ Con95 nil95 snoc95) A def Var95 : Con95 β†’ Ty95 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Var95 : Con95 β†’ Ty95 β†’ Type) (vz : βˆ€ Ξ“ A, Var95 (snoc95 Ξ“ A) A) (vs : βˆ€ Ξ“ B A, Var95 Ξ“ A β†’ Var95 (snoc95 Ξ“ B) A) , Var95 Ξ“ A def vz95 {Ξ“ A} : Var95 (snoc95 Ξ“ A) A := Ξ» Var95 vz95 vs => vz95 _ _ def vs95 {Ξ“ B A} : Var95 Ξ“ A β†’ Var95 (snoc95 Ξ“ B) A := Ξ» x Var95 vz95 vs95 => vs95 _ _ _ (x Var95 vz95 vs95) def Tm95 : Con95 β†’ Ty95 β†’ Type 1 := Ξ» Ξ“ A => βˆ€ (Tm95 : Con95 β†’ Ty95 β†’ Type) (var : βˆ€ Ξ“ A , Var95 Ξ“ A β†’ Tm95 Ξ“ A) (lam : βˆ€ Ξ“ A B , Tm95 (snoc95 Ξ“ A) B β†’ Tm95 Ξ“ (arr95 A B)) (app : βˆ€ Ξ“ A B , Tm95 Ξ“ (arr95 A B) β†’ Tm95 Ξ“ A β†’ Tm95 Ξ“ B) , Tm95 Ξ“ A def var95 {Ξ“ A} : Var95 Ξ“ A β†’ Tm95 Ξ“ A := Ξ» x Tm95 var95 lam app => var95 _ _ x def lam95 {Ξ“ A B} : Tm95 (snoc95 Ξ“ A) B β†’ Tm95 Ξ“ (arr95 A B) := Ξ» t Tm95 var95 lam95 app => lam95 _ _ _ (t Tm95 var95 lam95 app) def app95 {Ξ“ A B} : Tm95 Ξ“ (arr95 A B) β†’ Tm95 Ξ“ A β†’ Tm95 Ξ“ B := Ξ» t u Tm95 var95 lam95 app95 => app95 _ _ _ (t Tm95 var95 lam95 app95) (u Tm95 var95 lam95 app95) def v095 {Ξ“ A} : Tm95 (snoc95 Ξ“ A) A := var95 vz95 def v195 {Ξ“ A B} : Tm95 (snoc95 (snoc95 Ξ“ A) B) A := var95 (vs95 vz95) def v295 {Ξ“ A B C} : Tm95 (snoc95 (snoc95 (snoc95 Ξ“ A) B) C) A := var95 (vs95 (vs95 vz95)) def v395 {Ξ“ A B C D} : Tm95 (snoc95 (snoc95 (snoc95 (snoc95 Ξ“ A) B) C) D) A := var95 (vs95 (vs95 (vs95 vz95))) def v495 {Ξ“ A B C D E} : Tm95 (snoc95 (snoc95 (snoc95 (snoc95 (snoc95 Ξ“ A) B) C) D) E) A := var95 (vs95 (vs95 (vs95 (vs95 vz95)))) def test95 {Ξ“ A} : Tm95 Ξ“ (arr95 (arr95 A A) (arr95 A A)) := lam95 (lam95 (app95 v195 (app95 v195 (app95 v195 (app95 v195 (app95 v195 (app95 v195 v095)))))))
7fb5c1b35ce2f8c87b92c26cd06c13894eab39cc
e39f04f6ff425fe3b3f5e26a8998b817d1dba80f
/data/polynomial.lean
e39fdd5288cdc3e86f6b9ffc1b15542eeb1ac617
[ "Apache-2.0" ]
permissive
kristychoi/mathlib
c504b5e8f84e272ea1d8966693c42de7523bf0ec
257fd84fe98927ff4a5ffe044f68c4e9d235cc75
refs/heads/master
1,586,520,722,896
1,544,030,145,000
1,544,031,933,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
66,598
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes HΓΆlzl, Jens Wagemaker Theory of univariate polynomials, represented as `β„• β†’β‚€ Ξ±`, where Ξ± is a commutative semiring. -/ import data.finsupp algebra.euclidean_domain tactic.ring /-- `polynomial Ξ±` is the type of univariate polynomials over `Ξ±`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from Ξ± is called `C`. -/ def polynomial (Ξ± : Type*) [comm_semiring Ξ±] := β„• β†’β‚€ Ξ± open finsupp finset lattice namespace polynomial universes u v variables {Ξ± : Type u} {Ξ² : Type v} {a b : Ξ±} {m n : β„•} variables [decidable_eq Ξ±] section comm_semiring variables [comm_semiring Ξ±] {p q r : polynomial Ξ±} instance : has_zero (polynomial Ξ±) := finsupp.has_zero instance : has_one (polynomial Ξ±) := finsupp.has_one instance : has_add (polynomial Ξ±) := finsupp.has_add instance : has_mul (polynomial Ξ±) := finsupp.has_mul instance : comm_semiring (polynomial Ξ±) := finsupp.to_comm_semiring instance : decidable_eq (polynomial Ξ±) := finsupp.decidable_eq def polynomial.has_coe_to_fun : has_coe_to_fun (polynomial Ξ±) := finsupp.has_coe_to_fun local attribute [instance] finsupp.to_comm_semiring polynomial.has_coe_to_fun @[simp] lemma support_zero : (0 : polynomial Ξ±).support = βˆ… := rfl /-- `C a` is the constant polynomial `a`. -/ def C (a : Ξ±) : polynomial Ξ± := single 0 a /-- `X` is the polynomial variable (aka indeterminant). -/ def X : polynomial Ξ± := single 1 1 /-- coeff p n is the coefficient of X^n in p -/ def coeff (p : polynomial Ξ±) := p.to_fun instance [has_repr Ξ±] : has_repr (polynomial Ξ±) := ⟨λ p, if p = 0 then "0" else (p.support.sort (≀)).foldr (Ξ» n a, a ++ (if a = "" then "" else " + ") ++ if n = 0 then "C (" ++ repr (coeff p n) ++ ")" else if n = 1 then if (coeff p n) = 1 then "X" else "C (" ++ repr (coeff p n) ++ ") * X" else if (coeff p n) = 1 then "X ^ " ++ repr n else "C (" ++ repr (coeff p n) ++ ") * X ^ " ++ repr n) ""⟩ theorem ext {p q : polynomial Ξ±} : p = q ↔ βˆ€ n, coeff p n = coeff q n := ⟨λ h n, h β–Έ rfl, finsupp.ext⟩ /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p β‰  0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = βŠ₯`. -/ def degree (p : polynomial Ξ±) : with_bot β„• := p.support.sup some def degree_lt_wf : well_founded (Ξ»p q : polynomial Ξ±, degree p < degree q) := inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf) /-- `nat_degree p` forces `degree p` to β„•, by defining nat_degree 0 = 0. -/ def nat_degree (p : polynomial Ξ±) : β„• := (degree p).get_or_else 0 lemma single_eq_C_mul_X : βˆ€{n}, single n a = C a * X^n | 0 := (mul_one _).symm | (n+1) := calc single (n + 1) a = single n a * X : by rw [X, single_mul_single, mul_one] ... = (C a * X^n) * X : by rw [single_eq_C_mul_X] ... = C a * X^(n+1) : by simp only [pow_add, mul_assoc, pow_one] lemma sum_C_mul_X_eq (p : polynomial Ξ±) : p.sum (Ξ»n a, C a * X^n) = p := eq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _) @[elab_as_eliminator] protected lemma induction_on {M : polynomial Ξ± β†’ Prop} (p : polynomial Ξ±) (h_C : βˆ€a, M (C a)) (h_add : βˆ€p q, M p β†’ M q β†’ M (p + q)) (h_monomial : βˆ€(n : β„•) (a : Ξ±), M (C a * X^n) β†’ M (C a * X^(n+1))) : M p := have βˆ€{n:β„•} {a}, M (C a * X^n), begin assume n a, induction n with n ih, { simp only [pow_zero, mul_one, h_C] }, { exact h_monomial _ _ ih } end, finsupp.induction p (suffices M (C 0), by simpa only [C, single_zero], h_C 0) (assume n a p _ _ hp, suffices M (C a * X^n + p), by rwa [single_eq_C_mul_X], h_add _ _ this hp) @[simp] lemma C_0 : C (0 : Ξ±) = 0 := single_zero @[simp] lemma C_1 : C (1 : Ξ±) = 1 := rfl @[simp] lemma C_mul : C (a * b) = C a * C b := (@single_mul_single _ _ _ _ _ _ 0 0 a b).symm @[simp] lemma C_add : C (a + b) = C a + C b := finsupp.single_add instance C.is_semiring_hom : is_semiring_hom (C : Ξ± β†’ polynomial Ξ±) := ⟨C_0, C_1, Ξ» _ _, C_add, Ξ» _ _, C_mul⟩ @[simp] lemma C_pow : C (a ^ n) = C a ^ n := is_semiring_hom.map_pow _ _ _ section coeff lemma apply_eq_coeff : p n = coeff p n := rfl @[simp] lemma coeff_zero (n : β„•) : coeff (0 : polynomial Ξ±) n = 0 := rfl @[simp] lemma coeff_one_zero (n : β„•) : coeff (1 : polynomial Ξ±) 0 = 1 := rfl @[simp] lemma coeff_add (p q : polynomial Ξ±) (n : β„•) : coeff (p + q) n = coeff p n + coeff q n := finsupp.add_apply lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 := by simp [coeff, eq_comm, C, single]; congr @[simp] lemma coeff_C_zero : coeff (C a) 0 = a := rfl @[simp] lemma coeff_X_one : coeff (X : polynomial Ξ±) 1 = 1 := rfl @[simp] lemma coeff_C_mul_X (x : Ξ±) (k n : β„•) : coeff (C x * X^k : polynomial Ξ±) n = if n = k then x else 0 := by rw [← single_eq_C_mul_X]; simp [single, eq_comm, coeff]; congr lemma coeff_sum (n : β„•) (f : β„• β†’ Ξ± β†’ polynomial Ξ±) : coeff (p.sum f) n = p.sum (Ξ» a b, coeff (f a b) n) := finsupp.sum_apply lemma coeff_single : coeff (single n a) m = if n = m then a else 0 := rfl @[simp] lemma coeff_C_mul (p : polynomial Ξ±) : coeff (C a * p) n = a * coeff p n := begin conv in (a * _) { rw [← @sum_single _ _ _ _ _ p, coeff_sum] }, rw [mul_def, C, sum_single_index], { simp [coeff_single, finsupp.mul_sum, coeff_sum], apply sum_congr rfl, assume i hi, by_cases i = n; simp [h] }, simp end @[simp] lemma coeff_one (n : β„•) : coeff (1 : polynomial Ξ±) n = if 0 = n then 1 else 0 := rfl @[simp] lemma coeff_X_pow (k n : β„•) : coeff (X^k : polynomial Ξ±) n = if n = k then 1 else 0 := by simpa only [C_1, one_mul] using coeff_C_mul_X (1:Ξ±) k n lemma coeff_mul_left (p q : polynomial Ξ±) (n : β„•) : coeff (p * q) n = (range (n+1)).sum (Ξ» k, coeff p k * coeff q (n-k)) := have hite : βˆ€ a : β„• Γ— β„•, ite (a.1 + a.2 = n) (coeff p (a.fst) * coeff q (a.snd)) 0 β‰  0 β†’ a.1 + a.2 = n, from Ξ» a ha, by_contradiction (Ξ» h, absurd (eq.refl (0 : Ξ±)) (by rwa if_neg h at ha)), calc coeff (p * q) n = sum (p.support) (Ξ» a, sum (q.support) (Ξ» b, ite (a + b = n) (coeff p a * coeff q b) 0)) : by simp only [finsupp.mul_def, coeff_sum, coeff_single]; refl ... = (p.support.product q.support).sum (Ξ» v : β„• Γ— β„•, ite (v.1 + v.2 = n) (coeff p v.1 * coeff q v.2) 0) : by rw sum_product ... = (range (n+1)).sum (Ξ» k, coeff p k * coeff q (n-k)) : sum_bij_ne_zero (Ξ» a _ _, a.1) (Ξ» a _ ha, mem_range.2 (nat.lt_succ_of_le (hite a ha β–Έ le_add_right (le_refl _)))) (Ξ» a₁ aβ‚‚ _ h₁ _ hβ‚‚ h, prod.ext h ((add_left_inj a₁.1).1 (by rw [hite a₁ h₁, h, hite aβ‚‚ hβ‚‚]))) (Ξ» a h₁ hβ‚‚, ⟨(a, n - a), mem_product.2 ⟨mem_support_iff.2 (ne_zero_of_mul_ne_zero_right hβ‚‚), mem_support_iff.2 (ne_zero_of_mul_ne_zero_left hβ‚‚)⟩, by simpa [nat.add_sub_cancel' (nat.le_of_lt_succ (mem_range.1 h₁))], rfl⟩) (Ξ» a _ ha, by rw [← hite a ha, if_pos rfl, nat.add_sub_cancel_left]) lemma coeff_mul_right (p q : polynomial Ξ±) (n : β„•) : coeff (p * q) n = (range (n+1)).sum (Ξ» k, coeff p (n-k) * coeff q k) := by rw [mul_comm, coeff_mul_left]; simp only [mul_comm] theorem coeff_mul_X_pow (p : polynomial Ξ±) (n d : β„•) : coeff (p * polynomial.X ^ n) (d + n) = coeff p d := begin rw [coeff_mul_right, sum_eq_single n, coeff_X_pow, if_pos rfl, mul_one, nat.add_sub_cancel], { intros b h1 h2, rw [coeff_X_pow, if_neg h2, mul_zero] }, { exact Ξ» h1, (h1 (mem_range.2 (nat.le_add_left _ _))).elim } end theorem coeff_mul_X (p : polynomial Ξ±) (n : β„•) : coeff (p * X) (n + 1) = coeff p n := by simpa only [pow_one] using coeff_mul_X_pow p 1 n theorem mul_X_pow_eq_zero {p : polynomial Ξ±} {n : β„•} (H : p * X ^ n = 0) : p = 0 := ext.2 $ Ξ» k, (coeff_mul_X_pow p n k).symm.trans $ ext.1 H (k+n) end coeff lemma C_inj : C a = C b ↔ a = b := ⟨λ h, coeff_C_zero.symm.trans (h.symm β–Έ coeff_C_zero), congr_arg C⟩ section evalβ‚‚ variables [semiring Ξ²] variables (f : Ξ± β†’ Ξ²) (x : Ξ²) open is_semiring_hom /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ def evalβ‚‚ (p : polynomial Ξ±) : Ξ² := p.sum (Ξ» e a, f a * x ^ e) variables [is_semiring_hom f] @[simp] lemma evalβ‚‚_C : (C a).evalβ‚‚ f x = f a := (sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [pow_zero, mul_one] @[simp] lemma evalβ‚‚_X : X.evalβ‚‚ f x = x := (sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [map_one f, one_mul, pow_one] @[simp] lemma evalβ‚‚_zero : (0 : polynomial Ξ±).evalβ‚‚ f x = 0 := finsupp.sum_zero_index @[simp] lemma evalβ‚‚_add : (p + q).evalβ‚‚ f x = p.evalβ‚‚ f x + q.evalβ‚‚ f x := finsupp.sum_add_index (Ξ» _, by rw [map_zero f, zero_mul]) (Ξ» _ _ _, by rw [map_add f, add_mul]) @[simp] lemma evalβ‚‚_one : (1 : polynomial Ξ±).evalβ‚‚ f x = 1 := by rw [← C_1, evalβ‚‚_C, map_one f] instance evalβ‚‚.is_add_monoid_hom : is_add_monoid_hom (evalβ‚‚ f x) := ⟨evalβ‚‚_zero _ _, Ξ» _ _, evalβ‚‚_add _ _⟩ end evalβ‚‚ section evalβ‚‚ variables [comm_semiring Ξ²] variables (f : Ξ± β†’ Ξ²) [is_semiring_hom f] (x : Ξ²) open is_semiring_hom @[simp] lemma evalβ‚‚_mul : (p * q).evalβ‚‚ f x = p.evalβ‚‚ f x * q.evalβ‚‚ f x := begin dunfold evalβ‚‚, rw [mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index], { apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index], { apply sum_congr rfl, assume j hj, dsimp only, rw [sum_single_index, map_mul f, pow_add], { simp only [mul_assoc, mul_left_comm] }, { rw [map_zero f, zero_mul] } }, { intro, rw [map_zero f, zero_mul] }, { intros, rw [map_add f, add_mul] } }, { intro, rw [map_zero f, zero_mul] }, { intros, rw [map_add f, add_mul] } end instance evalβ‚‚.is_semiring_hom : is_semiring_hom (evalβ‚‚ f x) := ⟨evalβ‚‚_zero _ _, evalβ‚‚_one _ _, Ξ» _ _, evalβ‚‚_add _ _, Ξ» _ _, evalβ‚‚_mul _ _⟩ lemma evalβ‚‚_pow (n : β„•) : (p ^ n).evalβ‚‚ f x = p.evalβ‚‚ f x ^ n := map_pow _ _ _ lemma evalβ‚‚_sum (p : polynomial Ξ±) (g : β„• β†’ Ξ± β†’ polynomial Ξ±) (x : Ξ²) : (p.sum g).evalβ‚‚ f x = p.sum (Ξ» n a, (g n a).evalβ‚‚ f x) := finsupp.sum_sum_index (by simp [is_add_monoid_hom.map_zero f]) (by intros; simp [right_distrib, is_add_monoid_hom.map_add f]) end evalβ‚‚ section eval variable {x : Ξ±} /-- `eval x p` is the evaluation of the polynomial `p` at `x` -/ def eval : Ξ± β†’ polynomial Ξ± β†’ Ξ± := evalβ‚‚ id @[simp] lemma eval_C : (C a).eval x = a := evalβ‚‚_C _ _ @[simp] lemma eval_X : X.eval x = x := evalβ‚‚_X _ _ @[simp] lemma eval_zero : (0 : polynomial Ξ±).eval x = 0 := evalβ‚‚_zero _ _ @[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := evalβ‚‚_add _ _ @[simp] lemma eval_one : (1 : polynomial Ξ±).eval x = 1 := evalβ‚‚_one _ _ @[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := evalβ‚‚_mul _ _ instance eval.is_semiring_hom : is_semiring_hom (eval x) := evalβ‚‚.is_semiring_hom _ _ lemma eval_pow (n : β„•) : (p ^ n).eval x = p.eval x ^ n := evalβ‚‚_pow _ _ _ lemma eval_sum (p : polynomial Ξ±) (f : β„• β†’ Ξ± β†’ polynomial Ξ±) (x : Ξ±) : (p.sum f).eval x = p.sum (Ξ» n a, (f n a).eval x) := evalβ‚‚_sum _ _ _ _ /-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/ def is_root (p : polynomial Ξ±) (a : Ξ±) : Prop := p.eval a = 0 instance : decidable (is_root p a) := by unfold is_root; apply_instance @[simp] lemma is_root.def : is_root p a ↔ p.eval a = 0 := iff.rfl lemma root_mul_left_of_is_root (p : polynomial Ξ±) {q : polynomial Ξ±} : is_root q a β†’ is_root (p * q) a := Ξ» H, by rw [is_root, eval_mul, is_root.def.1 H, mul_zero] lemma root_mul_right_of_is_root {p : polynomial Ξ±} (q : polynomial Ξ±) : is_root p a β†’ is_root (p * q) a := Ξ» H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul] end eval section comp def comp (p q : polynomial Ξ±) : polynomial Ξ± := p.evalβ‚‚ C q lemma evalβ‚‚_comp [comm_semiring Ξ²] (f : Ξ± β†’ Ξ²) [is_semiring_hom f] {x : Ξ²} : (p.comp q).evalβ‚‚ f x = p.evalβ‚‚ f (q.evalβ‚‚ f x) := show (p.sum (Ξ» e a, C a * q ^ e)).evalβ‚‚ f x = p.evalβ‚‚ f (evalβ‚‚ f x q), by simp only [evalβ‚‚_mul, evalβ‚‚_C, evalβ‚‚_pow, evalβ‚‚_sum]; refl lemma eval_comp : (p.comp q).eval a = p.eval (q.eval a) := evalβ‚‚_comp _ @[simp] lemma comp_X : p.comp X = p := begin refine polynomial.ext.2 (Ξ» n, _), rw [comp, evalβ‚‚], conv in (C _ * _) { rw ← single_eq_C_mul_X }, rw finsupp.sum_single end @[simp] lemma X_comp : X.comp p = p := evalβ‚‚_X _ _ @[simp] lemma comp_C : p.comp (C a) = C (p.eval a) := begin dsimp [comp, evalβ‚‚, eval, finsupp.sum], rw [← sum_hom C (@C_0 Ξ± _ _) (Ξ» _ _, @C_add _ _ _ _ _)], apply finset.sum_congr rfl; simp end @[simp] lemma C_comp : (C a).comp p = C a := evalβ‚‚_C _ _ @[simp] lemma comp_zero : p.comp (0 : polynomial Ξ±) = C (p.eval 0) := by rw [← C_0, comp_C] @[simp] lemma zero_comp : comp (0 : polynomial Ξ±) p = 0 := by rw [← C_0, C_comp] @[simp] lemma comp_one : p.comp 1 = C (p.eval 1) := by rw [← C_1, comp_C] @[simp] lemma one_comp : comp (1 : polynomial Ξ±) p = 1 := by rw [← C_1, C_comp] instance : is_semiring_hom (Ξ» q : polynomial Ξ±, q.comp p) := by unfold comp; apply_instance @[simp] lemma add_comp : (p + q).comp r = p.comp r + q.comp r := evalβ‚‚_add _ _ @[simp] lemma mul_comp : (p * q).comp r = p.comp r * q.comp r := evalβ‚‚_mul _ _ end comp section map variables [comm_semiring Ξ²] [decidable_eq Ξ²] variables (f : Ξ± β†’ Ξ²) [is_semiring_hom f] /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : polynomial Ξ± β†’ polynomial Ξ² := evalβ‚‚ (C ∘ f) X @[simp] lemma map_C : (C a).map f = C (f a) := evalβ‚‚_C _ _ @[simp] lemma map_X : X.map f = X := evalβ‚‚_X _ _ @[simp] lemma map_zero : (0 : polynomial Ξ±).map f = 0 := evalβ‚‚_zero _ _ @[simp] lemma map_add : (p + q).map f = p.map f + q.map f := evalβ‚‚_add _ _ @[simp] lemma map_one : (1 : polynomial Ξ±).map f = 1 := evalβ‚‚_one _ _ @[simp] lemma map_mul : (p * q).map f = p.map f * q.map f := evalβ‚‚_mul _ _ instance map.is_semiring_hom : is_semiring_hom (map f) := evalβ‚‚.is_semiring_hom _ _ lemma map_pow (n : β„•) : (p ^ n).map f = p.map f ^ n := evalβ‚‚_pow _ _ _ end map /-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/ def leading_coeff (p : polynomial Ξ±) : Ξ± := coeff p (nat_degree p) /-- a polynomial is `monic` if its leading coefficient is 1 -/ def monic (p : polynomial Ξ±) := leading_coeff p = (1 : Ξ±) lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl instance monic.decidable : decidable (monic p) := by unfold monic; apply_instance @[simp] lemma degree_zero : degree (0 : polynomial Ξ±) = βŠ₯ := rfl @[simp] lemma nat_degree_zero : nat_degree (0 : polynomial Ξ±) = 0 := rfl @[simp] lemma degree_C (ha : a β‰  0) : degree (C a) = (0 : with_bot β„•) := show sup (ite (a = 0) βˆ… {0}) some = 0, by rw if_neg ha; refl lemma degree_C_le : degree (C a) ≀ (0 : with_bot β„•) := by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _] lemma degree_one_le : degree (1 : polynomial Ξ±) ≀ (0 : with_bot β„•) := by rw [← C_1]; exact degree_C_le lemma degree_eq_bot : degree p = βŠ₯ ↔ p = 0 := ⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h; exact support_eq_empty.1 (max_eq_none.1 h), Ξ» h, h.symm β–Έ rfl⟩ lemma degree_eq_nat_degree (hp : p β‰  0) : degree p = (nat_degree p : with_bot β„•) := let ⟨n, hn⟩ := classical.not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in have hn : degree p = some n := not_not.1 hn, by rw [nat_degree, hn]; refl @[simp] lemma degree_le_nat_degree : degree p ≀ nat_degree p := begin by_cases hp : p = 0, { rw hp, exact bot_le }, rw [degree_eq_nat_degree hp], exact le_refl _ end lemma nat_degree_eq_of_degree_eq (h : degree p = degree q) : nat_degree p = nat_degree q := by unfold nat_degree; rw h lemma le_degree_of_ne_zero (h : coeff p n β‰  0) : (n : with_bot β„•) ≀ degree p := show @has_le.le (with_bot β„•) _ (some n : with_bot β„•) (p.support.sup some : with_bot β„•), from finset.le_sup (finsupp.mem_support_iff.2 h) lemma le_nat_degree_of_ne_zero (h : coeff p n β‰  0) : n ≀ nat_degree p := begin rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree], exact le_degree_of_ne_zero h, { assume h, subst h, exact h rfl } end lemma degree_le_degree (h : coeff q (nat_degree p) β‰  0) : degree p ≀ degree q := begin by_cases hp : p = 0, { rw hp, exact bot_le }, { rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h } end @[simp] lemma nat_degree_C (a : Ξ±) : nat_degree (C a) = 0 := begin by_cases ha : a = 0, { have : C a = 0, { rw [ha, C_0] }, rw [nat_degree, degree_eq_bot.2 this], refl }, { rw [nat_degree, degree_C ha], refl } end @[simp] lemma nat_degree_one : nat_degree (1 : polynomial Ξ±) = 0 := nat_degree_C 1 @[simp] lemma degree_monomial (n : β„•) (ha : a β‰  0) : degree (C a * X ^ n) = n := by rw [← single_eq_C_mul_X, degree, support_single_ne_zero ha]; refl lemma degree_monomial_le (n : β„•) (a : Ξ±) : degree (C a * X ^ n) ≀ n := if h : a = 0 then by rw [h, C_0, zero_mul]; exact bot_le else le_of_eq (degree_monomial n h) lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 := not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h)) lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (nat_degree q) = 0 := coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree) lemma ne_zero_of_degree_gt {n : with_bot β„•} (h : n < degree p) : p β‰  0 := mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h))) lemma eq_C_of_degree_le_zero (h : degree p ≀ 0) : p = C (coeff p 0) := begin refine polynomial.ext.2 (Ξ» n, _), cases n, { refl }, { have : degree p < ↑(nat.succ n) := lt_of_le_of_lt h (with_bot.some_lt_some.2 (nat.succ_pos _)), rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt this] } end lemma degree_add_le (p q : polynomial Ξ±) : degree (p + q) ≀ max (degree p) (degree q) := calc degree (p + q) = ((p + q).support).sup some : rfl ... ≀ (p.support βˆͺ q.support).sup some : sup_mono support_add ... = p.support.sup some βŠ” q.support.sup some : sup_union ... = _ : with_bot.sup_eq_max _ _ @[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial Ξ±) = 0 := rfl @[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 := ⟨λ h, by_contradiction $ Ξ» hp, mt mem_support_iff.1 (not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)), Ξ» h, h.symm β–Έ leading_coeff_zero⟩ lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = βŠ₯ := by rw [leading_coeff_eq_zero, degree_eq_bot] lemma degree_add_eq_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := le_antisymm (max_eq_right_of_lt h β–Έ degree_add_le _ _) $ degree_le_degree $ begin rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, zero_add], exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h) end lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q β‰  0) : degree (p + q) = max p.degree q.degree := le_antisymm (degree_add_le _ _) $ match lt_trichotomy (degree p) (degree q) with | or.inl hlt := by rw [degree_add_eq_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _ | or.inr (or.inl heq) := le_of_not_gt $ assume hlt : max (degree p) (degree q) > degree (p + q), h $ show leading_coeff p + leading_coeff q = 0, begin rw [heq, max_self] at hlt, rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add], exact coeff_nat_degree_eq_zero_of_degree_lt hlt end | or.inr (or.inr hlt) := by rw [add_comm, degree_add_eq_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _ end lemma degree_erase_le (p : polynomial Ξ±) (n : β„•) : degree (p.erase n) ≀ degree p := sup_mono (erase_subset _ _) lemma degree_erase_lt (hp : p β‰  0) : degree (p.erase (nat_degree p)) < degree p := lt_of_le_of_ne (degree_erase_le _ _) $ (degree_eq_nat_degree hp).symm β–Έ Ξ» h, not_mem_erase _ _ (mem_of_max h) lemma degree_sum_le [decidable_eq Ξ²] (s : finset Ξ²) (f : Ξ² β†’ polynomial Ξ±) : degree (s.sum f) ≀ s.sup (Ξ» b, degree (f b)) := finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $ assume a s has ih, calc degree (sum (insert a s) f) ≀ max (degree (f a)) (degree (s.sum f)) : by rw sum_insert has; exact degree_add_le _ _ ... ≀ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih lemma degree_mul_le (p q : polynomial Ξ±) : degree (p * q) ≀ degree p + degree q := calc degree (p * q) ≀ (p.support).sup (Ξ»i, degree (sum q (Ξ»j a, C (coeff p i * a) * X ^ (i + j)))) : by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _ ... ≀ p.support.sup (Ξ»i, q.support.sup (Ξ»j, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) : finset.sup_mono_fun (assume i hi, degree_sum_le _ _) ... ≀ degree p + degree q : begin refine finset.sup_le (Ξ» a ha, finset.sup_le (Ξ» b hb, le_trans (degree_monomial_le _ _) _)), rw [with_bot.coe_add], rw mem_support_iff at ha hb, exact add_le_add' (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb) end lemma degree_pow_le (p : polynomial Ξ±) : βˆ€ n, degree (p ^ n) ≀ add_monoid.smul n (degree p) | 0 := by rw [pow_zero, add_monoid.zero_smul]; exact degree_one_le | (n+1) := calc degree (p ^ (n + 1)) ≀ degree p + degree (p ^ n) : by rw pow_succ; exact degree_mul_le _ _ ... ≀ _ : by rw succ_smul; exact add_le_add' (le_refl _) (degree_pow_le _) @[simp] lemma leading_coeff_monomial (a : Ξ±) (n : β„•) : leading_coeff (C a * X ^ n) = a := begin by_cases ha : a = 0, { simp only [ha, C_0, zero_mul, leading_coeff_zero] }, { rw [leading_coeff, nat_degree, degree_monomial _ ha, ← single_eq_C_mul_X], exact @finsupp.single_eq_same _ _ _ _ _ n a } end @[simp] lemma leading_coeff_C (a : Ξ±) : leading_coeff (C a) = a := suffices leading_coeff (C a * X^0) = a, by rwa [pow_zero, mul_one] at this, leading_coeff_monomial a 0 @[simp] lemma leading_coeff_X : leading_coeff (X : polynomial Ξ±) = 1 := suffices leading_coeff (C (1:Ξ±) * X^1) = 1, by rwa [C_1, pow_one, one_mul] at this, leading_coeff_monomial 1 1 @[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial Ξ±) = 1 := suffices leading_coeff (C (1:Ξ±) * X^0) = 1, by rwa [C_1, pow_zero, mul_one] at this, leading_coeff_monomial 1 0 @[simp] lemma monic_one : monic (1 : polynomial Ξ±) := leading_coeff_C _ lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) : leading_coeff (p + q) = leading_coeff q := have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h, by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_of_degree_lt h), this, coeff_add, zero_add] lemma leading_coeff_add_of_degree_eq (h : degree p = degree q) (hlc : leading_coeff p + leading_coeff q β‰  0) : leading_coeff (p + q) = leading_coeff p + leading_coeff q := have nat_degree (p + q) = nat_degree p, by apply nat_degree_eq_of_degree_eq; rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self], by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add] @[simp] lemma coeff_mul_degree_add_degree (p q : polynomial Ξ±) : coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q := calc coeff (p * q) (nat_degree p + nat_degree q) = (range (nat_degree p + nat_degree q + 1)).sum (Ξ» k, coeff p k * coeff q (nat_degree p + nat_degree q - k)) : coeff_mul_left _ _ _ ... = coeff p (nat_degree p) * coeff q (nat_degree p + nat_degree q - nat_degree p) : finset.sum_eq_single _ (Ξ» n hn₁ hnβ‚‚, (le_total n (nat_degree p)).elim (Ξ» h, have degree q < (nat_degree p + nat_degree q - n : β„•), from lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_sub_left_iff_add_lt.2 (add_lt_add_right (lt_of_le_of_ne h hnβ‚‚) _))), by simp [coeff_eq_zero_of_degree_lt this]) (Ξ» h, have degree p < n, from lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (lt_of_le_of_ne h hnβ‚‚.symm)), by simp [coeff_eq_zero_of_degree_lt this])) (Ξ» h, false.elim (h (mem_range.2 (lt_of_le_of_lt (nat.le_add_right _ _) (nat.lt_succ_self _))))) ... = _ : by simp [leading_coeff, nat.add_sub_cancel_left] lemma degree_mul_eq' (h : leading_coeff p * leading_coeff q β‰  0) : degree (p * q) = degree p + degree q := have hp : p β‰  0 := by refine mt _ h; exact Ξ» hp, by rw [hp, leading_coeff_zero, zero_mul], have hq : q β‰  0 := by refine mt _ h; exact Ξ» hq, by rw [hq, leading_coeff_zero, mul_zero], le_antisymm (degree_mul_le _ _) begin rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq], refine le_degree_of_ne_zero _, rwa coeff_mul_degree_add_degree end lemma nat_degree_mul_eq' (h : leading_coeff p * leading_coeff q β‰  0) : nat_degree (p * q) = nat_degree p + nat_degree q := have hp : p β‰  0 := mt leading_coeff_eq_zero.2 (Ξ» h₁, h $ by rw [h₁, zero_mul]), have hq : q β‰  0 := mt leading_coeff_eq_zero.2 (Ξ» h₁, h $ by rw [h₁, mul_zero]), have hpq : p * q β‰  0 := Ξ» hpq, by rw [← coeff_mul_degree_add_degree, hpq, coeff_zero] at h; exact h rfl, option.some_inj.1 (show (nat_degree (p * q) : with_bot β„•) = nat_degree p + nat_degree q, by rw [← degree_eq_nat_degree hpq, degree_mul_eq' h, degree_eq_nat_degree hp, degree_eq_nat_degree hq]) lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q β‰  0) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := begin unfold leading_coeff, rw [nat_degree_mul_eq' h, coeff_mul_degree_add_degree], refl end lemma leading_coeff_pow' : leading_coeff p ^ n β‰  0 β†’ leading_coeff (p ^ n) = leading_coeff p ^ n := nat.rec_on n (by simp) $ Ξ» n ih h, have h₁ : leading_coeff p ^ n β‰  0 := Ξ» h₁, h $ by rw [pow_succ, h₁, mul_zero], have hβ‚‚ : leading_coeff p * leading_coeff (p ^ n) β‰  0 := by rwa [pow_succ, ← ih h₁] at h, by rw [pow_succ, pow_succ, leading_coeff_mul' hβ‚‚, ih h₁] lemma degree_pow_eq' : βˆ€ {n}, leading_coeff p ^ n β‰  0 β†’ degree (p ^ n) = add_monoid.smul n (degree p) | 0 := Ξ» h, by rw [pow_zero, ← C_1] at *; rw [degree_C h, add_monoid.zero_smul] | (n+1) := Ξ» h, have h₁ : leading_coeff p ^ n β‰  0 := Ξ» h₁, h $ by rw [pow_succ, h₁, mul_zero], have hβ‚‚ : leading_coeff p * leading_coeff (p ^ n) β‰  0 := by rwa [pow_succ, ← leading_coeff_pow' h₁] at h, by rw [pow_succ, degree_mul_eq' hβ‚‚, succ_smul, degree_pow_eq' h₁] lemma nat_degree_pow_eq' {n : β„•} (h : leading_coeff p ^ n β‰  0) : nat_degree (p ^ n) = n * nat_degree p := if hp0 : p = 0 then if hn0 : n = 0 then by simp * else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp else have hpn : p ^ n β‰  0, from Ξ» hpn0, have h1 : _ := h, by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h; exact h rfl, option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot β„•) = (n * nat_degree p : β„•), by rw [← degree_eq_nat_degree hpn, degree_pow_eq' h, degree_eq_nat_degree hp0, ← with_bot.coe_smul]; simp @[simp] lemma leading_coeff_X_pow : βˆ€ n : β„•, leading_coeff ((X : polynomial Ξ±) ^ n) = 1 | 0 := by simp | (n+1) := if h10 : (1 : Ξ±) = 0 then by rw [pow_succ, ← one_mul X, ← C_1, h10]; simp else have h : leading_coeff (X : polynomial Ξ±) * leading_coeff (X ^ n) β‰  0, by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul]; exact h10, by rw [pow_succ, leading_coeff_mul' h, leading_coeff_X, leading_coeff_X_pow, one_mul] lemma nat_degree_comp_le : nat_degree (p.comp q) ≀ nat_degree p * nat_degree q := if h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _ else with_bot.coe_le_coe.1 $ calc ↑(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm ... ≀ _ : degree_sum_le _ _ ... ≀ _ : sup_le (Ξ» n hn, calc degree (C (coeff p n) * q ^ n) ≀ degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _ ... ≀ nat_degree (C (coeff p n)) + add_monoid.smul n (degree q) : add_le_add' degree_le_nat_degree (degree_pow_le _ _) ... ≀ nat_degree (C (coeff p n)) + add_monoid.smul n (nat_degree q) : add_le_add_left' (add_monoid.smul_le_smul_of_le_right (@degree_le_nat_degree _ _ _ q) n) ... = (n * nat_degree q : β„•) : by rw [nat_degree_C, with_bot.coe_zero, zero_add, ← with_bot.coe_smul, add_monoid.smul_eq_mul]; simp ... ≀ (nat_degree p * nat_degree q : β„•) : with_bot.coe_le_coe.2 $ mul_le_mul_of_nonneg_right (le_nat_degree_of_ne_zero (finsupp.mem_support_iff.1 hn)) (nat.zero_le _)) end comm_semiring section comm_ring variables [comm_ring Ξ±] {p q : polynomial Ξ±} instance : comm_ring (polynomial Ξ±) := finsupp.to_comm_ring instance : has_scalar Ξ± (polynomial Ξ±) := finsupp.to_has_scalar -- TODO if this becomes a semimodule then the below lemma could be proved for semimodules instance : module Ξ± (polynomial Ξ±) := finsupp.to_module β„• Ξ± -- TODO -- this is OK for semimodules @[simp] lemma coeff_smul (p : polynomial Ξ±) (r : Ξ±) (n : β„•) : coeff (r β€’ p) n = r * coeff p n := finsupp.smul_apply -- TODO -- this is OK for semimodules lemma C_mul' (a : Ξ±) (f : polynomial Ξ±) : C a * f = a β€’ f := ext.2 $ Ξ» n, coeff_C_mul f variable (Ξ±) def lcoeff (n : β„•) : polynomial Ξ± β†’β‚— Ξ± := { to_fun := Ξ» f, coeff f n, add := Ξ» f g, coeff_add f g n, smul := Ξ» r p, coeff_smul p r n } variable {Ξ±} @[simp] lemma lcoeff_apply (n : β„•) (f : polynomial Ξ±) : lcoeff Ξ± n f = coeff f n := rfl instance C.is_ring_hom : is_ring_hom (@C Ξ± _ _) := by apply is_ring_hom.of_semiring instance evalβ‚‚.is_ring_hom {Ξ²} [comm_ring Ξ²] (f : Ξ± β†’ Ξ²) [is_ring_hom f] {x : Ξ²} : is_ring_hom (evalβ‚‚ f x) := by apply is_ring_hom.of_semiring instance eval.is_ring_hom {x : Ξ±} : is_ring_hom (eval x) := evalβ‚‚.is_ring_hom _ instance map.is_ring_hom {Ξ²} [comm_ring Ξ²] [decidable_eq Ξ²] (f : Ξ± β†’ Ξ²) [is_ring_hom f] : is_ring_hom (map f) := evalβ‚‚.is_ring_hom (C ∘ f) @[simp] lemma degree_neg (p : polynomial Ξ±) : degree (-p) = degree p := by unfold degree; rw support_neg @[simp] lemma coeff_neg (p : polynomial Ξ±) (n : β„•) : coeff (-p) n = -coeff p n := neg_apply @[simp] lemma eval_neg (p : polynomial Ξ±) (x : Ξ±) : (-p).eval x = -p.eval x := is_ring_hom.map_neg _ @[simp] lemma eval_sub (p q : polynomial Ξ±) (x : Ξ±) : (p - q).eval x = p.eval x - q.eval x := is_ring_hom.map_sub _ lemma degree_sub_lt (hd : degree p = degree q) (hp0 : p β‰  0) (hlc : leading_coeff p = leading_coeff q) : degree (p - q) < degree p := have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p := finsupp.single_add_erase, have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q := finsupp.single_add_erase, have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd, have hq0 : q β‰  0 := mt degree_eq_bot.2 (hd β–Έ mt degree_eq_bot.1 hp0), calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) : by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]} ... ≀ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q)) : degree_neg (erase (nat_degree q) q) β–Έ degree_add_le _ _ ... < degree p : max_lt_iff.2 ⟨hd' β–Έ degree_erase_lt hp0, hd.symm β–Έ degree_erase_lt hq0⟩ instance : has_well_founded (polynomial Ξ±) := ⟨_, degree_lt_wf⟩ lemma ne_zero_of_ne_zero_of_monic (hp : p β‰  0) (hq : monic q) : q β‰  0 | h := begin rw [h, monic.def, leading_coeff_zero] at hq, rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp, exact hp rfl end lemma div_wf_lemma (h : degree q ≀ degree p ∧ p β‰  0) (hq : monic q) : degree (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) < degree p := have hp : leading_coeff p β‰  0 := mt leading_coeff_eq_zero.1 h.2, have hpq : leading_coeff (C (leading_coeff p) * X ^ (nat_degree p - nat_degree q)) * leading_coeff q β‰  0, by rwa [leading_coeff_monomial, monic.def.1 hq, mul_one], if h0 : p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q = 0 then h0.symm β–Έ (lt_of_not_ge $ mt le_bot_iff.1 (mt degree_eq_bot.1 h.2)) else have hq0 : q β‰  0 := ne_zero_of_ne_zero_of_monic h.2 hq, have hlt : nat_degree q ≀ nat_degree p := with_bot.coe_le_coe.1 (by rw [← degree_eq_nat_degree h.2, ← degree_eq_nat_degree hq0]; exact h.1), degree_sub_lt (by rw [degree_mul_eq' hpq, degree_monomial _ hp, degree_eq_nat_degree h.2, degree_eq_nat_degree hq0, ← with_bot.coe_add, nat.sub_add_cancel hlt]) h.2 (by rw [leading_coeff_mul' hpq, leading_coeff_monomial, monic.def.1 hq, mul_one]) def div_mod_by_monic_aux : Ξ  (p : polynomial Ξ±) {q : polynomial Ξ±}, monic q β†’ polynomial Ξ± Γ— polynomial Ξ± | p := Ξ» q hq, if h : degree q ≀ degree p ∧ p β‰  0 then let z := C (leading_coeff p) * X^(nat_degree p - nat_degree q) in have wf : _ := div_wf_lemma h hq, let dm := div_mod_by_monic_aux (p - z * q) hq in ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ using_well_founded {dec_tac := tactic.assumption} /-- `div_by_monic` gives the quotient of `p` by a monic polynomial `q`. -/ def div_by_monic (p q : polynomial Ξ±) : polynomial Ξ± := if hq : monic q then (div_mod_by_monic_aux p hq).1 else 0 /-- `mod_by_monic` gives the remainder of `p` by a monic polynomial `q`. -/ def mod_by_monic (p q : polynomial Ξ±) : polynomial Ξ± := if hq : monic q then (div_mod_by_monic_aux p hq).2 else p infixl ` /β‚˜ ` : 70 := div_by_monic infixl ` %β‚˜ ` : 70 := mod_by_monic lemma degree_mod_by_monic_lt : βˆ€ (p : polynomial Ξ±) {q : polynomial Ξ±} (hq : monic q) (hq0 : q β‰  0), degree (p %β‚˜ q) < degree q | p := Ξ» q hq hq0, if h : degree q ≀ degree p ∧ p β‰  0 then have wf : _ := div_wf_lemma ⟨h.1, h.2⟩ hq, have degree ((p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) %β‚˜ q) < degree q := degree_mod_by_monic_lt (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq hq0, begin unfold mod_by_monic at this ⊒, unfold div_mod_by_monic_aux, rw dif_pos hq at this ⊒, rw if_pos h, exact this end else or.cases_on (not_and_distrib.1 h) begin unfold mod_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h], exact lt_of_not_ge, end begin assume hp, unfold mod_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h, not_not.1 hp], exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 hq0)), end using_well_founded {dec_tac := tactic.assumption} lemma mod_by_monic_eq_sub_mul_div : βˆ€ (p : polynomial Ξ±) {q : polynomial Ξ±} (hq : monic q), p %β‚˜ q = p - q * (p /β‚˜ q) | p := Ξ» q hq, if h : degree q ≀ degree p ∧ p β‰  0 then have wf : _ := div_wf_lemma h hq, have ih : _ := mod_by_monic_eq_sub_mul_div (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq, begin unfold mod_by_monic div_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_pos h], rw [mod_by_monic, dif_pos hq] at ih, refine ih.trans _, unfold div_by_monic, rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm] end else begin unfold mod_by_monic div_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] end using_well_founded {dec_tac := tactic.assumption} lemma subsingleton_of_monic_zero (h : monic (0 : polynomial Ξ±)) : (βˆ€ p q : polynomial Ξ±, p = q) ∧ (βˆ€ a b : Ξ±, a = b) := by rw [monic.def, leading_coeff_zero] at h; exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero], Ξ» a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩ lemma mod_by_monic_add_div (p : polynomial Ξ±) {q : polynomial Ξ±} (hq : monic q) : p %β‚˜ q + q * (p /β‚˜ q) = p := eq_sub_iff_add_eq.1 (mod_by_monic_eq_sub_mul_div p hq) @[simp] lemma zero_mod_by_monic (p : polynomial Ξ±) : 0 %β‚˜ p = 0 := begin unfold mod_by_monic div_mod_by_monic_aux, by_cases hp : monic p, { rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] }, { rw [dif_neg hp] } end @[simp] lemma zero_div_by_monic (p : polynomial Ξ±) : 0 /β‚˜ p = 0 := begin unfold div_by_monic div_mod_by_monic_aux, by_cases hp : monic p, { rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] }, { rw [dif_neg hp] } end @[simp] lemma mod_by_monic_zero (p : polynomial Ξ±) : p %β‚˜ 0 = p := if h : monic (0 : polynomial Ξ±) then (subsingleton_of_monic_zero h).1 _ _ else by unfold mod_by_monic div_mod_by_monic_aux; rw dif_neg h @[simp] lemma div_by_monic_zero (p : polynomial Ξ±) : p /β‚˜ 0 = 0 := if h : monic (0 : polynomial Ξ±) then (subsingleton_of_monic_zero h).1 _ _ else by unfold div_by_monic div_mod_by_monic_aux; rw dif_neg h lemma div_by_monic_eq_of_not_monic (p : polynomial Ξ±) (hq : Β¬monic q) : p /β‚˜ q = 0 := dif_neg hq lemma mod_by_monic_eq_of_not_monic (p : polynomial Ξ±) (hq : Β¬monic q) : p %β‚˜ q = p := dif_neg hq lemma mod_by_monic_eq_self_iff (hq : monic q) (hq0 : q β‰  0) : p %β‚˜ q = p ↔ degree p < degree q := ⟨λ h, h β–Έ degree_mod_by_monic_lt _ hq hq0, Ξ» h, have Β¬ degree q ≀ degree p := not_le_of_gt h, by unfold mod_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩ lemma div_by_monic_eq_zero_iff (hq : monic q) (hq0 : q β‰  0) : p /β‚˜ q = 0 ↔ degree p < degree q := ⟨λ h, by have := mod_by_monic_add_div p hq; rwa [h, mul_zero, add_zero, mod_by_monic_eq_self_iff hq hq0] at this, Ξ» h, have Β¬ degree q ≀ degree p := not_le_of_gt h, by unfold div_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩ lemma degree_add_div_by_monic (hq : monic q) (h : degree q ≀ degree p) : degree q + degree (p /β‚˜ q) = degree p := if hq0 : q = 0 then have βˆ€ (p : polynomial Ξ±), p = 0, from Ξ» p, (@subsingleton_of_monic_zero Ξ± _ _ (hq0 β–Έ hq)).1 _ _, by rw [this (p /β‚˜ q), this p, this q]; refl else have hdiv0 : p /β‚˜ q β‰  0 := by rwa [(β‰ ), div_by_monic_eq_zero_iff hq hq0, not_lt], have hlc : leading_coeff q * leading_coeff (p /β‚˜ q) β‰  0 := by rwa [monic.def.1 hq, one_mul, (β‰ ), leading_coeff_eq_zero], have hmod : degree (p %β‚˜ q) < degree (q * (p /β‚˜ q)) := calc degree (p %β‚˜ q) < degree q : degree_mod_by_monic_lt _ hq hq0 ... ≀ _ : by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0, degree_eq_nat_degree hdiv0, ← with_bot.coe_add, with_bot.coe_le_coe]; exact nat.le_add_right _ _, calc degree q + degree (p /β‚˜ q) = degree (q * (p /β‚˜ q)) : eq.symm (degree_mul_eq' hlc) ... = degree (p %β‚˜ q + q * (p /β‚˜ q)) : (degree_add_eq_of_degree_lt hmod).symm ... = _ : congr_arg _ (mod_by_monic_add_div _ hq) lemma degree_div_by_monic_le (p q : polynomial Ξ±) : degree (p /β‚˜ q) ≀ degree p := if hp0 : p = 0 then by simp only [hp0, zero_div_by_monic, le_refl] else if hq : monic q then have hq0 : q β‰  0 := ne_zero_of_ne_zero_of_monic hp0 hq, if h : degree q ≀ degree p then by rw [← degree_add_div_by_monic hq h, degree_eq_nat_degree hq0, degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 (not_lt.2 h))]; exact with_bot.coe_le_coe.2 (nat.le_add_left _ _) else by unfold div_by_monic div_mod_by_monic_aux; simp only [dif_pos hq, h, false_and, if_false, degree_zero, bot_le] else (div_by_monic_eq_of_not_monic p hq).symm β–Έ bot_le lemma degree_div_by_monic_lt (p : polynomial Ξ±) {q : polynomial Ξ±} (hq : monic q) (hp0 : p β‰  0) (h0q : 0 < degree q) : degree (p /β‚˜ q) < degree p := have hq0 : q β‰  0 := ne_zero_of_ne_zero_of_monic hp0 hq, if hpq : degree p < degree q then begin rw [(div_by_monic_eq_zero_iff hq hq0).2 hpq, degree_eq_nat_degree hp0], exact with_bot.bot_lt_some _ end else begin rw [← degree_add_div_by_monic hq (not_lt.1 hpq), degree_eq_nat_degree hq0, degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 hpq)], exact with_bot.coe_lt_coe.2 (nat.lt_add_of_pos_left (with_bot.coe_lt_coe.1 $ (degree_eq_nat_degree hq0) β–Έ h0q)) end lemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %β‚˜ q = 0 ↔ q ∣ p := ⟨λ h, by rw [← mod_by_monic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, Ξ» h, if hq0 : q = 0 then by rw hq0 at hq; exact (subsingleton_of_monic_zero hq).1 _ _ else let ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h in by_contradiction (Ξ» hpq0, have hmod : p %β‚˜ q = q * (r - p /β‚˜ q) := by rw [mod_by_monic_eq_sub_mul_div _ hq, mul_sub, ← hr], have degree (q * (r - p /β‚˜ q)) < degree q := hmod β–Έ degree_mod_by_monic_lt _ hq hq0, have hrpq0 : leading_coeff (r - p /β‚˜ q) β‰  0 := Ξ» h, hpq0 $ leading_coeff_eq_zero.1 (by rw [hmod, leading_coeff_eq_zero.1 h, mul_zero, leading_coeff_zero]), have hlc : leading_coeff q * leading_coeff (r - p /β‚˜ q) β‰  0 := by rwa [monic.def.1 hq, one_mul], by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0, degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this; exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩ lemma degree_pos_of_root (hp : p β‰  0) (h : is_root p a) : 0 < degree p := lt_of_not_ge $ Ξ» hlt, begin have := eq_C_of_degree_le_zero hlt, rw [is_root, this, eval_C] at h, exact hp (finsupp.ext (Ξ» n, show coeff p n = 0, from nat.cases_on n h (Ξ» _, coeff_eq_zero_of_degree_lt (lt_of_le_of_lt hlt (with_bot.coe_lt_coe.2 (nat.succ_pos _)))))), end end comm_ring section nonzero_comm_ring variables [nonzero_comm_ring Ξ±] {p q : polynomial Ξ±} instance : nonzero_comm_ring (polynomial Ξ±) := { zero_ne_one := Ξ» (h : (0 : polynomial Ξ±) = 1), @zero_ne_one Ξ± _ $ calc (0 : Ξ±) = eval 0 0 : eval_zero.symm ... = eval 0 1 : congr_arg _ h ... = 1 : eval_C, ..polynomial.comm_ring } @[simp] lemma degree_one : degree (1 : polynomial Ξ±) = (0 : with_bot β„•) := degree_C (show (1 : Ξ±) β‰  0, from zero_ne_one.symm) @[simp] lemma degree_X : degree (X : polynomial Ξ±) = 1 := begin unfold X degree single finsupp.support, rw if_neg (zero_ne_one).symm, refl end @[simp] lemma degree_X_sub_C (a : Ξ±) : degree (X - C a) = 1 := begin rw [sub_eq_add_neg, add_comm, ← @degree_X Ξ±], by_cases ha : a = 0, { simp only [ha, C_0, neg_zero, zero_add] }, exact degree_add_eq_of_degree_lt (by rw [degree_X, degree_neg, degree_C ha]; exact dec_trivial) end @[simp] lemma degree_X_pow : βˆ€ (n : β„•), degree ((X : polynomial Ξ±) ^ n) = n | 0 := by simp only [pow_zero, degree_one]; refl | (n+1) := have h : leading_coeff (X : polynomial Ξ±) * leading_coeff (X ^ n) β‰  0, by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul]; exact zero_ne_one.symm, by rw [pow_succ, degree_mul_eq' h, degree_X, degree_X_pow, add_comm]; refl lemma degree_X_pow_sub_C {n : β„•} (hn : 0 < n) (a : Ξ±) : degree ((X : polynomial Ξ±) ^ n - C a) = n := have degree (-C a) < degree ((X : polynomial Ξ±) ^ n), from calc degree (-C a) ≀ 0 : by rw degree_neg; exact degree_C_le ... < degree ((X : polynomial Ξ±) ^ n) : by rwa [degree_X_pow]; exact with_bot.coe_lt_coe.2 hn, by rw [sub_eq_add_neg, add_comm, degree_add_eq_of_degree_lt this, degree_X_pow] lemma X_pow_sub_C_ne_zero {n : β„•} (hn : 0 < n) (a : Ξ±) : (X : polynomial Ξ±) ^ n - C a β‰  0 := mt degree_eq_bot.2 (show degree ((X : polynomial Ξ±) ^ n - C a) β‰  βŠ₯, by rw degree_X_pow_sub_C hn; exact dec_trivial) @[simp] lemma not_monic_zero : Β¬monic (0 : polynomial Ξ±) := by simpa only [monic, leading_coeff_zero] using zero_ne_one lemma ne_zero_of_monic (h : monic p) : p β‰  0 := Ξ» h₁, @not_monic_zero Ξ± _ _ (h₁ β–Έ h) lemma monic_X_sub_C (a : Ξ±) : monic (X - C a) := have degree (-C a) < degree (X : polynomial Ξ±) := if ha : a = 0 then by simp only [ha, degree_zero, C_0, degree_X, neg_zero]; exact with_bot.bot_lt_some _ else by simp only [degree_C ha, degree_neg, degree_X]; exact dec_trivial, by unfold monic; rw [sub_eq_add_neg, add_comm, leading_coeff_add_of_degree_lt this, leading_coeff_X] lemma root_X_sub_C : is_root (X - C a) b ↔ a = b := by rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero_iff_eq, eq_comm] @[simp] lemma mod_by_monic_X_sub_C_eq_C_eval (p : polynomial Ξ±) (a : Ξ±) : p %β‚˜ (X - C a) = C (p.eval a) := have h : (p %β‚˜ (X - C a)).eval a = p.eval a := by rw [mod_by_monic_eq_sub_mul_div _ (monic_X_sub_C a), eval_sub, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul, sub_zero], have degree (p %β‚˜ (X - C a)) < 1 := degree_X_sub_C a β–Έ degree_mod_by_monic_lt p (monic_X_sub_C a) ((degree_X_sub_C a).symm β–Έ ne_zero_of_monic (monic_X_sub_C _)), have degree (p %β‚˜ (X - C a)) ≀ 0 := begin cases (degree (p %β‚˜ (X - C a))), { exact bot_le }, { exact with_bot.some_le_some.2 (nat.le_of_lt_succ (with_bot.some_lt_some.1 this)) } end, begin rw [eq_C_of_degree_le_zero this, eval_C] at h, rw [eq_C_of_degree_le_zero this, h] end lemma mul_div_by_monic_eq_iff_is_root : (X - C a) * (p /β‚˜ (X - C a)) = p ↔ is_root p a := ⟨λ h, by rw [← h, is_root.def, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul], Ξ» h : p.eval a = 0, by conv {to_rhs, rw ← mod_by_monic_add_div p (monic_X_sub_C a)}; rw [mod_by_monic_X_sub_C_eq_C_eval, h, C_0, zero_add]⟩ lemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a := ⟨λ h, by rwa [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _), mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h, Ξ» h, ⟨(p /β‚˜ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩ end nonzero_comm_ring section integral_domain variables [integral_domain Ξ±] {p q : polynomial Ξ±} @[simp] lemma degree_mul_eq : degree (p * q) = degree p + degree q := if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add] else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot] else degree_mul_eq' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0) (mt leading_coeff_eq_zero.1 hq0) @[simp] lemma degree_pow_eq (p : polynomial Ξ±) (n : β„•) : degree (p ^ n) = add_monoid.smul n (degree p) := by induction n; [simp only [pow_zero, degree_one, add_monoid.zero_smul], simp only [*, pow_succ, succ_smul, degree_mul_eq]] @[simp] lemma leading_coeff_mul (p q : polynomial Ξ±) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := begin by_cases hp : p = 0, { simp only [hp, zero_mul, leading_coeff_zero] }, { by_cases hq : q = 0, { simp only [hq, mul_zero, leading_coeff_zero] }, { rw [leading_coeff_mul'], exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } } end @[simp] lemma leading_coeff_pow (p : polynomial Ξ±) (n : β„•) : leading_coeff (p ^ n) = leading_coeff p ^ n := by induction n; [simp only [pow_zero, leading_coeff_one], simp only [*, pow_succ, leading_coeff_mul]] instance : integral_domain (polynomial Ξ±) := { eq_zero_or_eq_zero_of_mul_eq_zero := Ξ» a b h, begin have : leading_coeff 0 = leading_coeff a * leading_coeff b := h β–Έ leading_coeff_mul a b, rw [leading_coeff_zero, eq_comm] at this, rw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero], exact eq_zero_or_eq_zero_of_mul_eq_zero this end, ..polynomial.nonzero_comm_ring } @[simp] lemma nat_degree_pow_eq (p : polynomial Ξ±) (n : β„•) : nat_degree (p ^ n) = n * nat_degree p := if hp0 : p = 0 then if hn0 : n = 0 then by simp [hp0, hn0] else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp else nat_degree_pow_eq' (by rw [← leading_coeff_pow, ne.def, leading_coeff_eq_zero]; exact pow_ne_zero _ hp0) lemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a := by rw [is_root, eval_mul] at h; exact eq_zero_or_eq_zero_of_mul_eq_zero h lemma degree_le_mul_left (p : polynomial Ξ±) (hq : q β‰  0) : degree p ≀ degree (p * q) := if hp : p = 0 then by simp only [hp, zero_mul, le_refl] else by rw [degree_mul_eq, degree_eq_nat_degree hp, degree_eq_nat_degree hq]; exact with_bot.coe_le_coe.2 (nat.le_add_right _ _) lemma exists_finset_roots : βˆ€ {p : polynomial Ξ±} (hp : p β‰  0), βˆƒ s : finset Ξ±, (s.card : with_bot β„•) ≀ degree p ∧ βˆ€ x, x ∈ s ↔ is_root p x | p := Ξ» hp, by haveI := classical.prop_decidable (βˆƒ x, is_root p x); exact if h : βˆƒ x, is_root p x then let ⟨x, hx⟩ := h in have hpd : 0 < degree p := degree_pos_of_root hp hx, have hd0 : p /β‚˜ (X - C x) β‰  0 := Ξ» h, by rw [← mul_div_by_monic_eq_iff_is_root.2 hx, h, mul_zero] at hp; exact hp rfl, have wf : degree (p /β‚˜ _) < degree p := degree_div_by_monic_lt _ (monic_X_sub_C x) hp ((degree_X_sub_C x).symm β–Έ dec_trivial), let ⟨t, htd, htr⟩ := @exists_finset_roots (p /β‚˜ (X - C x)) hd0 in have hdeg : degree (X - C x) ≀ degree p := begin rw [degree_X_sub_C, degree_eq_nat_degree hp], rw degree_eq_nat_degree hp at hpd, exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd) end, have hdiv0 : p /β‚˜ (X - C x) β‰  0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x) (ne_zero_of_monic (monic_X_sub_C x))).1 $ not_lt.2 hdeg, ⟨insert x t, calc (card (insert x t) : with_bot β„•) ≀ card t + 1 : with_bot.coe_le_coe.2 $ finset.card_insert_le _ _ ... ≀ degree p : by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg, degree_X_sub_C, add_comm]; exact add_le_add' (le_refl (1 : with_bot β„•)) htd, begin assume y, rw [mem_insert, htr, eq_comm, ← root_X_sub_C], conv {to_rhs, rw ← mul_div_by_monic_eq_iff_is_root.2 hx}, exact ⟨λ h, or.cases_on h (root_mul_right_of_is_root _) (root_mul_left_of_is_root _), root_or_root_of_root_mul⟩ end⟩ else βŸ¨βˆ…, (degree_eq_nat_degree hp).symm β–Έ with_bot.coe_le_coe.2 (nat.zero_le _), by simpa only [not_mem_empty, false_iff, not_exists] using h⟩ using_well_founded {dec_tac := tactic.assumption} /-- `roots p` noncomputably gives a finset containing all the roots of `p` -/ noncomputable def roots (p : polynomial Ξ±) : finset Ξ± := if h : p = 0 then βˆ… else classical.some (exists_finset_roots h) lemma card_roots (hp0 : p β‰  0) : ((roots p).card : with_bot β„•) ≀ degree p := begin unfold roots, rw dif_neg hp0, exact (classical.some_spec (exists_finset_roots hp0)).1 end @[simp] lemma mem_roots (hp : p β‰  0) : a ∈ p.roots ↔ is_root p a := by unfold roots; rw dif_neg hp; exact (classical.some_spec (exists_finset_roots hp)).2 _ lemma card_roots_X_pow_sub_C {n : β„•} (hn : 0 < n) (a : Ξ±) : (roots ((X : polynomial Ξ±) ^ n - C a)).card ≀ n := with_bot.coe_le_coe.1 $ calc ((roots ((X : polynomial Ξ±) ^ n - C a)).card : with_bot β„•) ≀ degree ((X : polynomial Ξ±) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a) ... = n : degree_X_pow_sub_C hn a /-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/ noncomputable def nth_roots {Ξ± : Type*} [integral_domain Ξ±] (n : β„•) (a : Ξ±) : finset Ξ± := by letI := classical.prop_decidable; exact roots ((X : polynomial Ξ±) ^ n - C a) @[simp] lemma mem_nth_roots {Ξ± : Type*} [integral_domain Ξ±] {n : β„•} (hn : 0 < n) {a x : Ξ±} : x ∈ nth_roots n a ↔ x ^ n = a := by letI := classical.prop_decidable; rw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a), is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero_iff_eq] lemma card_nth_roots {Ξ± : Type*} [integral_domain Ξ±] (n : β„•) (a : Ξ±) : (nth_roots n a).card ≀ n := by letI := classical.prop_decidable; exact if hn : n = 0 then if h : (X : polynomial Ξ±) ^ n - C a = 0 then by simp only [nat.zero_le, nth_roots, roots, h, dif_pos rfl, card_empty] else with_bot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← @C_1 Ξ± _, ← is_ring_hom.map_sub (@C Ξ± _ _)]; exact degree_C_le)) else by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a]; exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a) lemma coeff_comp_degree_mul_degree (hqd0 : nat_degree q β‰  0) : coeff (p.comp q) (nat_degree p * nat_degree q) = leading_coeff p * leading_coeff q ^ nat_degree p := if hp0 : p = 0 then by simp [hp0] else calc coeff (p.comp q) (nat_degree p * nat_degree q) = p.sum (Ξ» n a, coeff (C a * q ^ n) (nat_degree p * nat_degree q)) : by rw [comp, evalβ‚‚, coeff_sum] ... = coeff (C (leading_coeff p) * q ^ nat_degree p) (nat_degree p * nat_degree q) : finset.sum_eq_single _ begin assume b hbs hbp, have hq0 : q β‰  0, from Ξ» hq0, hqd0 (by rw [hq0, nat_degree_zero]), have : coeff p b β‰  0, rwa [← apply_eq_coeff, ← finsupp.mem_support_iff], dsimp [apply_eq_coeff], refine coeff_eq_zero_of_degree_lt _, rw [degree_mul_eq, degree_C this, degree_pow_eq, zero_add, degree_eq_nat_degree hq0, ← with_bot.coe_smul, add_monoid.smul_eq_mul, with_bot.coe_lt_coe, nat.cast_id], exact (mul_lt_mul_right (nat.pos_of_ne_zero hqd0)).2 (lt_of_le_of_ne (with_bot.coe_le_coe.1 (by rw ← degree_eq_nat_degree hp0; exact le_sup hbs)) hbp) end (by rw [finsupp.mem_support_iff, apply_eq_coeff, ← leading_coeff, ne.def, leading_coeff_eq_zero, classical.not_not]; simp {contextual := tt}) ... = _ : have coeff (q ^ nat_degree p) (nat_degree p * nat_degree q) = leading_coeff (q ^ nat_degree p), by rw [leading_coeff, nat_degree_pow_eq], by rw [coeff_C_mul, this, leading_coeff_pow] lemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q := le_antisymm nat_degree_comp_le (if hp0 : p = 0 then by rw [hp0, zero_comp, nat_degree_zero, zero_mul] else if hqd0 : nat_degree q = 0 then have degree q ≀ 0, by rw [← with_bot.coe_zero, ← hqd0]; exact degree_le_nat_degree, by rw [eq_C_of_degree_le_zero this]; simp else le_nat_degree_of_ne_zero $ have hq0 : q β‰  0, from Ξ» hq0, hqd0 $ by rw [hq0, nat_degree_zero], calc coeff (p.comp q) (nat_degree p * nat_degree q) = leading_coeff p * leading_coeff q ^ nat_degree p : coeff_comp_degree_mul_degree hqd0 ... β‰  0 : mul_ne_zero (mt leading_coeff_eq_zero.1 hp0) (pow_ne_zero _ (mt leading_coeff_eq_zero.1 hq0))) lemma leading_coeff_comp (hq : nat_degree q β‰  0): leading_coeff (p.comp q) = leading_coeff p * leading_coeff q ^ nat_degree p := by rw [← coeff_comp_degree_mul_degree hq, ← nat_degree_comp]; refl end integral_domain section field variables [discrete_field Ξ±] {p q : polynomial Ξ±} instance : vector_space Ξ± (polynomial Ξ±) := { ..finsupp.to_module β„• Ξ± } lemma monic_mul_leading_coeff_inv (h : p β‰  0) : monic (p * C (leading_coeff p)⁻¹) := by rw [monic, leading_coeff_mul, leading_coeff_C, mul_inv_cancel (show leading_coeff p β‰  0, from mt leading_coeff_eq_zero.1 h)] lemma degree_mul_leading_coeff_inv (h : p β‰  0) : degree (p * C (leading_coeff p)⁻¹) = degree p := have h₁ : (leading_coeff p)⁻¹ β‰  0 := inv_ne_zero (mt leading_coeff_eq_zero.1 h), by rw [degree_mul_eq, degree_C h₁, add_zero] def div (p q : polynomial Ξ±) := C (leading_coeff q)⁻¹ * (p /β‚˜ (q * C (leading_coeff q)⁻¹)) def mod (p q : polynomial Ξ±) := p %β‚˜ (q * C (leading_coeff q)⁻¹) private lemma quotient_mul_add_remainder_eq_aux (p q : polynomial Ξ±) : q * div p q + mod p q = p := if h : q = 0 then by simp only [h, zero_mul, mod, mod_by_monic_zero, zero_add] else begin conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)}, rw [div, mod, add_comm, mul_assoc] end private lemma remainder_lt_aux (p : polynomial Ξ±) (hq : q β‰  0) : degree (mod p q) < degree q := degree_mul_leading_coeff_inv hq β–Έ degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq) (mul_ne_zero hq (mt leading_coeff_eq_zero.2 (by rw leading_coeff_C; exact inv_ne_zero (mt leading_coeff_eq_zero.1 hq)))) instance : has_div (polynomial Ξ±) := ⟨div⟩ instance : has_mod (polynomial Ξ±) := ⟨mod⟩ lemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /β‚˜ (q * C (leading_coeff q)⁻¹)) := rfl lemma mod_def : p % q = p %β‚˜ (q * C (leading_coeff q)⁻¹) := rfl lemma mod_by_monic_eq_mod (p : polynomial Ξ±) (hq : monic q) : p %β‚˜ q = p % q := show p %β‚˜ q = p %β‚˜ (q * C (leading_coeff q)⁻¹), by simp only [monic.def.1 hq, inv_one, mul_one, C_1] lemma div_by_monic_eq_div (p : polynomial Ξ±) (hq : monic q) : p /β‚˜ q = p / q := show p /β‚˜ q = C (leading_coeff q)⁻¹ * (p /β‚˜ (q * C (leading_coeff q)⁻¹)), by simp only [monic.def.1 hq, inv_one, C_1, one_mul, mul_one] lemma mod_X_sub_C_eq_C_eval (p : polynomial Ξ±) (a : Ξ±) : p % (X - C a) = C (p.eval a) := mod_by_monic_eq_mod p (monic_X_sub_C a) β–Έ mod_by_monic_X_sub_C_eq_C_eval _ _ lemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a := div_by_monic_eq_div p (monic_X_sub_C a) β–Έ mul_div_by_monic_eq_iff_is_root instance : euclidean_domain (polynomial Ξ±) := { quotient := (/), remainder := (%), r := _, r_well_founded := degree_lt_wf, quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux, remainder_lt := Ξ» p q hq, remainder_lt_aux _ hq, mul_left_not_lt := Ξ» p q hq, not_lt_of_ge (degree_le_mul_left _ hq) } lemma mod_eq_self_iff (hq0 : q β‰  0) : p % q = p ↔ degree p < degree q := ⟨λ h, h β–Έ euclidean_domain.mod_lt _ hq0, Ξ» h, have Β¬degree (q * C (leading_coeff q)⁻¹) ≀ degree p := not_le_of_gt $ by rwa degree_mul_leading_coeff_inv hq0, begin rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)], unfold div_mod_by_monic_aux, simp only [this, false_and, if_false] end⟩ lemma div_eq_zero_iff (hq0 : q β‰  0) : p / q = 0 ↔ degree p < degree q := ⟨λ h, by have := euclidean_domain.div_add_mod p q; rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this, Ξ» h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹), by rwa degree_mul_leading_coeff_inv hq0, have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0, by rw [div_def, (div_by_monic_eq_zero_iff hm (ne_zero_of_monic hm)).2 hlt, mul_zero]⟩ lemma degree_add_div (hq0 : q β‰  0) (hpq : degree q ≀ degree p) : degree q + degree (p / q) = degree p := have degree (p % q) < degree (q * (p / q)) := calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0 ... ≀ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)), by conv {to_rhs, rw [← euclidean_domain.div_add_mod p q, add_comm, degree_add_eq_of_degree_lt this, degree_mul_eq]} end field section derivative variables [comm_semiring Ξ±] /-- `derivative p` formal derivative of the polynomial `p` -/ def derivative (p : polynomial Ξ±) : polynomial Ξ± := p.sum (Ξ»n a, C (a * n) * X^(n - 1)) lemma coeff_derivative (p : polynomial Ξ±) (n : β„•) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := begin rw [derivative], simp only [coeff_X_pow, coeff_sum, coeff_C_mul], rw [finsupp.sum, finset.sum_eq_single (n + 1), apply_eq_coeff], { rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one] }, { assume b, cases b, { intros, rw [nat.cast_zero, mul_zero, zero_mul] }, { intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } }, { intro H, rw [not_mem_support_iff.1 H, zero_mul, zero_mul] } end @[simp] lemma derivative_zero : derivative (0 : polynomial Ξ±) = 0 := finsupp.sum_zero_index lemma derivative_monomial (a : Ξ±) (n : β„•) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) := by rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, sum_single_index, single_eq_C_mul_X]; simp only [zero_mul, C_0]; refl @[simp] lemma derivative_C {a : Ξ±} : derivative (C a) = 0 := suffices derivative (C a * X^0) = C (a * 0:Ξ±) * X ^ 0, by simpa only [mul_one, zero_mul, C_0, mul_zero, pow_zero], derivative_monomial a 0 @[simp] lemma derivative_X : derivative (X : polynomial Ξ±) = 1 := suffices derivative (C (1:Ξ±) * X^1) = C (1 * (1:β„•)) * X ^ 0, by simpa only [mul_one, one_mul, C_1, pow_one, nat.cast_one, pow_zero], derivative_monomial 1 1 @[simp] lemma derivative_one : derivative (1 : polynomial Ξ±) = 0 := derivative_C @[simp] lemma derivative_add {f g : polynomial Ξ±} : derivative (f + g) = derivative f + derivative g := by refine finsupp.sum_add_index _ _; intros; simp only [add_mul, zero_mul, C_0, C_add, C_mul] @[simp] lemma derivative_sum {s : finset Ξ²} {f : Ξ² β†’ polynomial Ξ±} : derivative (s.sum f) = s.sum (Ξ»b, derivative (f b)) := begin apply (finset.sum_hom derivative _ _).symm, exact derivative_zero, exact assume x y, derivative_add end @[simp] lemma derivative_mul {f g : polynomial Ξ±} : derivative (f * g) = derivative f * g + f * derivative g := calc derivative (f * g) = f.sum (Ξ»n a, g.sum (Ξ»m b, C ((a * b) * (n + m : β„•)) * X^((n + m) - 1))) : begin transitivity, exact derivative_sum, transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum }, apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm, transitivity, { apply congr_arg, exact single_eq_C_mul_X }, exact derivative_monomial _ _ end ... = f.sum (Ξ»n a, g.sum (Ξ»m b, (C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) : sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm, by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul]; cases n; simp only [nat.succ_sub_succ, pow_zero]; cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero, nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm] ... = derivative f * g + f * derivative g : begin conv { to_rhs, congr, { rw [← sum_C_mul_X_eq g] }, { rw [← sum_C_mul_X_eq f] } }, unfold derivative finsupp.sum, simp only [sum_add_distrib, finset.mul_sum, finset.sum_mul] end lemma derivative_eval (p : polynomial Ξ±) (x : Ξ±) : p.derivative.eval x = p.sum (Ξ» n a, (a * n)*x^(n-1)) := by simp [derivative, eval_sum, eval_pow] end derivative section domain variables [integral_domain Ξ±] lemma mem_support_derivative [char_zero Ξ±] (p : polynomial Ξ±) (n : β„•) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := suffices (Β¬(coeff p (n + 1) = 0 ∨ ((n + 1:β„•) : Ξ±) = 0)) ↔ coeff p (n + 1) β‰  0, by simpa only [coeff_derivative, apply_eq_coeff, mem_support_iff, ne.def, mul_eq_zero], by rw [nat.cast_eq_zero]; simp only [nat.succ_ne_zero, or_false] @[simp] lemma degree_derivative_eq [char_zero Ξ±] (p : polynomial Ξ±) (hp : 0 < nat_degree p) : degree (derivative p) = (nat_degree p - 1 : β„•) := le_antisymm (le_trans (degree_sum_le _ _) $ sup_le $ assume n hn, have n ≀ nat_degree p, begin rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree], { refine le_degree_of_ne_zero _, simpa only [mem_support_iff] using hn }, { assume h, simpa only [h, support_zero] using hn } end, le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _) begin refine le_sup _, rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff], { show Β¬ leading_coeff p = 0, rw [leading_coeff_eq_zero], assume h, rw [h, nat_degree_zero] at hp, exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), }, exact hp end end domain section identities /- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring Maybe use data.nat.choose to prove it. -/ def pow_add_expansion {Ξ± : Type*} [comm_semiring Ξ±] (x y : Ξ±) : βˆ€ (n : β„•), {k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2} | 0 := ⟨0, by simp⟩ | 1 := ⟨0, by simp⟩ | (n+2) := begin cases pow_add_expansion (n+1) with z hz, rw [_root_.pow_succ, hz], existsi (x*z + (n+1)*x^n+z*y), simp [_root_.pow_succ], ring -- expensive! end variable [comm_ring Ξ±] private def poly_binom_aux1 (x y : Ξ±) (e : β„•) (a : Ξ±) : {k : Ξ± // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} := begin existsi (pow_add_expansion x y e).val, congr, apply (pow_add_expansion _ _ _).property end private lemma poly_binom_aux2 (f : polynomial Ξ±) (x y : Ξ±) : f.eval (x + y) = f.sum (Ξ» e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) := begin unfold eval evalβ‚‚, congr, ext, apply (poly_binom_aux1 x y _ _).property end private lemma poly_binom_aux3 (f : polynomial Ξ±) (x y : Ξ±) : f.eval (x + y) = f.sum (Ξ» e a, a * x^e) + f.sum (Ξ» e a, (a * e * x^(e-1)) * y) + f.sum (Ξ» e a, (a *(poly_binom_aux1 x y e a).val)*y^2) := by rw poly_binom_aux2; simp [left_distrib, finsupp.sum_add, mul_assoc] def binom_expansion (f : polynomial Ξ±) (x y : Ξ±) : {k : Ξ± // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} := begin existsi f.sum (Ξ» e a, a *((poly_binom_aux1 x y e a).val)), rw poly_binom_aux3, congr, { rw derivative_eval, symmetry, apply finsupp.sum_mul }, { symmetry, apply finsupp.sum_mul } end def pow_sub_pow_factor (x y : Ξ±) : Ξ  {i : β„•},{z : Ξ± // x^i - y^i = z*(x - y)} | 0 := ⟨0, by simp⟩ --sorry --false.elim $ not_lt_of_ge h zero_lt_one | 1 := ⟨1, by simp⟩ | (k+2) := begin cases pow_sub_pow_factor with z hz, existsi z*x + y^(k+1), rw [_root_.pow_succ x, _root_.pow_succ y, ←sub_add_sub_cancel (x*x^(k+1)) (x*y^(k+1)), ←mul_sub x, hz], simp only [_root_.pow_succ], ring end def eval_sub_factor (f : polynomial Ξ±) (x y : Ξ±) : {z : Ξ± // f.eval x - f.eval y = z*(x - y)} := begin existsi f.sum (Ξ» a b, b * (pow_sub_pow_factor x y).val), unfold eval evalβ‚‚, rw [←finsupp.sum_sub], have : finsupp.sum f (Ξ» (a : β„•) (b : Ξ±), b * (pow_sub_pow_factor x y).val) * (x - y) = finsupp.sum f (Ξ» (a : β„•) (b : Ξ±), b * (pow_sub_pow_factor x y).val * (x - y)), { apply finsupp.sum_mul }, rw this, congr, ext e a, rw [mul_assoc, ←(pow_sub_pow_factor x y).property], simp [left_distrib] end end identities end polynomial
d4584f1eef8c122f286c418eb9f0b92658e19f4c
a4673261e60b025e2c8c825dfa4ab9108246c32e
/tests/lean/run/depElim1.lean
148e9932d741664279e5a0b344c6a821e51c6233
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
13,768
lean
import Lean.Meta.Match open Lean open Lean.Meta open Lean.Meta.Match /- Infrastructure for testing -/ universes u v def check (x : Bool) : IO Unit := do unless x do throw $ IO.userError "check failed" def inaccessible {Ξ± : Sort u} (a : Ξ±) : Ξ± := a def val {Ξ± : Sort u} (a : Ξ±) : Ξ± := a def As {Ξ± : Sort u} (v a : Ξ±) : Ξ± := a inductive Pat {Ξ± : Sort u} (a : Ξ±) : Type u | mk : Pat a inductive ArrayLit0 (Ξ± : Sort u) : Type u | mk : ArrayLit0 Ξ± inductive ArrayLit1 {Ξ± : Sort u} (a : Ξ±) : Type u | mk : ArrayLit1 a inductive ArrayLit2 {Ξ± : Sort u} (a b : Ξ±) : Type u | mk : ArrayLit2 a b inductive ArrayLit3 {Ξ± : Sort u} (a b c : Ξ±) : Type u | mk : ArrayLit3 a b c inductive ArrayLit4 {Ξ± : Sort u} (a b c d : Ξ±) : Type u | mk : ArrayLit4 a b c d private def getConstructorVal (ctorName : Name) (fn : Expr) (args : Array Expr) : MetaM (Option (ConstructorVal Γ— Expr Γ— Array Expr)) := do let env ← getEnv match env.find? ctorName with | some (ConstantInfo.ctorInfo v) => if args.size == v.nparams + v.nfields then return some (v, fn, args) else return none | _ => return none private def constructorApp? (e : Expr) : MetaM (Option (ConstructorVal Γ— Expr Γ— Array Expr)) := do let env ← getEnv match e with | Expr.lit (Literal.natVal n) _ => if n == 0 then getConstructorVal `Nat.zero (mkConst `Nat.zero) #[] else getConstructorVal `Nat.succ (mkConst `Nat.succ) #[mkNatLit (n-1)] | _ => let fn := e.getAppFn match fn with | Expr.const n _ _ => getConstructorVal n fn e.getAppArgs | _ => pure none /- Convert expression using auxiliary hints `inaccessible` and `val` into a pattern -/ partial def mkPattern : Expr β†’ MetaM Pattern | e => do if e.isAppOfArity `val 2 then return Pattern.val e.appArg! else if e.isAppOfArity `inaccessible 2 then return Pattern.inaccessible e.appArg! else if e.isFVar then return Pattern.var e.fvarId! else if e.isAppOfArity `As 3 && (e.getArg! 1).isFVar then let v := e.getArg! 1 let p := e.getArg! 2 let p ← mkPattern p return Pattern.as v.fvarId! p else if e.isAppOfArity `ArrayLit0 1 || e.isAppOfArity `ArrayLit1 2 || e.isAppOfArity `ArrayLit2 3 || e.isAppOfArity `ArrayLit3 4 || e.isAppOfArity `ArrayLit4 5 then let args := e.getAppArgs let type := args[0] let ps := args.extract 1 args.size let ps ← ps.toList.mapM mkPattern return Pattern.arrayLit type ps else match e.arrayLit? with | some (_, es) => let pats ← es.mapM mkPattern let type ← inferType e let type ← whnfD type let elemType := type.appArg! return Pattern.arrayLit elemType pats | none => let e ← whnfD e let r? ← constructorApp? e match r? with | none => throwError "unexpected pattern" | some (cval, fn, args) => let params := args.extract 0 cval.nparams let fields := args.extract cval.nparams args.size let pats ← fields.toList.mapM mkPattern return Pattern.ctor cval.name fn.constLevels! params.toList pats partial def decodePats : Expr β†’ MetaM (List Pattern) | e => do match e.app2? `Pat with | some (_, pat) => let pat ← mkPattern pat; return [pat] | none => match e.prod? with | none => throwError "unexpected pattern" | some (pat, pats) => let pat ← decodePats pat let pats ← decodePats pats return pat ++ pats partial def decodeAltLHS (e : Expr) : MetaM AltLHS := forallTelescopeReducing e fun args body => do let decls ← args.toList.mapM (fun arg => getLocalDecl arg.fvarId!) let pats ← decodePats body return { ref := Syntax.missing, fvarDecls := decls, patterns := pats } partial def decodeAltLHSs : Expr β†’ MetaM (List AltLHS) | e => do match e.app2? `LHS with | some (_, lhs) => let lhs ← decodeAltLHS lhs; return [lhs] | none => match e.prod? with | none => throwError "unexpected LHS" | some (lhs, lhss) => let lhs ← decodeAltLHSs lhs let lhss ← decodeAltLHSs lhss return lhs ++ lhss def withDepElimFrom {Ξ±} (declName : Name) (numPats : Nat) (k : List FVarId β†’ List AltLHS β†’ MetaM Ξ±) : MetaM Ξ± := do let cinfo ← getConstInfo declName forallTelescopeReducing cinfo.type fun args body => if args.size < numPats then throwError "insufficient number of parameters" else do let xs := (args.extract (args.size - numPats) args.size).toList.map $ Expr.fvarId! let alts ← decodeAltLHSs body k xs alts inductive LHS {Ξ± : Sort u} (a : Ξ±) : Type u | mk : LHS a instance LHS.inhabited {Ξ±} (a : Ξ±) : Inhabited (LHS a) := ⟨LHS.mk⟩ -- set_option trace.Meta.debug true -- set_option trace.Meta.Tactic.cases true -- set_option trace.Meta.Tactic.subst true @[init] def register : IO Unit := registerTraceClass `Meta.mkElim /- Helper methods for testins mkElim -/ private def getUnusedLevelParam (majors : List Expr) (lhss : List AltLHS) : MetaM Level := do let mut s := {} for major in majors do let major ← instantiateMVars major let majorType ← inferType major let majorType ← instantiateMVars majorType s := collectLevelParams s major s := collectLevelParams s majorType return s.getUnusedLevelParam /- Return `Prop` if `inProf == true` and `Sort u` otherwise, where `u` is a fresh universe level parameter. -/ private def mkElimSort (majors : List Expr) (lhss : List AltLHS) (inProp : Bool) : MetaM Expr := do if inProp then return mkSort levelZero else let v ← getUnusedLevelParam majors lhss return mkSort $ v def mkTester (elimName : Name) (majors : List Expr) (lhss : List AltLHS) (inProp : Bool := false) : MetaM MatcherResult := do generalizeTelescope majors.toArray fun majors => do let resultType := if inProp then mkConst `True /- some proposition -/ else mkConst `Nat let matchType ← mkForallFVars majors resultType Match.mkMatcher elimName matchType majors.size lhss def test (ex : Name) (numPats : Nat) (elimName : Name) (inProp : Bool := false) : MetaM Unit := withDepElimFrom ex numPats fun majors alts => do let majors := majors.map mkFVar trace[Meta.debug]! m!"majors: {majors.toArray}" let r ← mkTester elimName majors alts inProp unless r.counterExamples.isEmpty do throwError m!"missing cases:\n{counterExamplesToMessageData r.counterExamples}" unless r.unusedAltIdxs.isEmpty do throwError ("unused alternatives: " ++ toString (r.unusedAltIdxs.map fun idx => "#" ++ toString (idx+1))) let cinfo ← getConstInfo elimName IO.println (toString cinfo.name ++ " : " ++ toString cinfo.type) pure () def testFailure (ex : Name) (numPats : Nat) (elimName : Name) (inProp : Bool := false) : MetaM Unit := do let worked ← tryCatch (do test ex numPats elimName inProp; pure true) (fun ex => pure false) if worked then throwError "unexpected success" def ex0 (x : Nat) : LHS (forall (y : Nat), Pat y) := arbitrary #eval test `ex0 1 `elimTest0 #print elimTest0 def ex1 (Ξ± : Type u) (Ξ² : Type v) (n : Nat) (x : List Ξ±) (y : List Ξ²) : LHS (Pat ([] : List Ξ±) Γ— Pat ([] : List Ξ²)) Γ— LHS (forall (a : Ξ±) (as : List Ξ±) (b : Ξ²) (bs : List Ξ²), Pat (a::as) Γ— Pat (b::bs)) Γ— LHS (forall (a : Ξ±) (as : List Ξ±), Pat (a::as) Γ— Pat ([] : List Ξ²)) Γ— LHS (forall (b : Ξ²) (bs : List Ξ²), Pat ([] : List Ξ±) Γ— Pat (b::bs)) := arbitrary #eval test `ex1 2 `elimTest1 #print elimTest1 inductive Vec (Ξ± : Type u) : Nat β†’ Type u | nil : Vec Ξ± 0 | cons {n : Nat} : Ξ± β†’ Vec Ξ± n β†’ Vec Ξ± (n+1) def ex2 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) (ys : Vec Ξ± n) : LHS (Pat (inaccessible 0) Γ— Pat (Vec.nil : Vec Ξ± 0) Γ— Pat (Vec.nil : Vec Ξ± 0)) Γ— LHS (forall (n : Nat) (x : Ξ±) (xs : Vec Ξ± n) (y : Ξ±) (ys : Vec Ξ± n), Pat (inaccessible (n+1)) Γ— Pat (Vec.cons x xs) Γ— Pat (Vec.cons y ys)) := arbitrary #eval test `ex2 3 `elimTest2 #print elimTest2 def ex3 (Ξ± : Type u) (Ξ² : Type v) (n : Nat) (x : List Ξ±) (y : List Ξ²) : LHS (Pat ([] : List Ξ±) Γ— Pat ([] : List Ξ²)) Γ— LHS (forall (a : Ξ±) (b : Ξ²), Pat [a] Γ— Pat [b]) Γ— LHS (forall (a₁ aβ‚‚ : Ξ±) (as : List Ξ±) (b₁ bβ‚‚ : Ξ²) (bs : List Ξ²), Pat (a₁::aβ‚‚::as) Γ— Pat (b₁::bβ‚‚::bs)) Γ— LHS (forall (as : List Ξ±) (bs : List Ξ²), Pat as Γ— Pat bs) := arbitrary -- set_option trace.Meta.EqnCompiler.match true -- set_option trace.Meta.EqnCompiler.matchDebug true #eval test `ex3 2 `elimTest3 #print elimTest3 def ex4 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) : LHS (Pat (inaccessible 0) Γ— Pat (Vec.nil : Vec Ξ± 0)) Γ— LHS (forall (n : Nat) (xs : Vec Ξ± (n+1)), Pat (inaccessible (n+1)) Γ— Pat xs) := arbitrary #eval test `ex4 2 `elimTest4 #print elimTest4 def ex5 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) : LHS (Pat Nat.zero Γ— Pat (Vec.nil : Vec Ξ± 0)) Γ— LHS (forall (n : Nat) (xs : Vec Ξ± (n+1)), Pat (Nat.succ n) Γ— Pat xs) := arbitrary #eval test `ex5 2 `elimTest5 #print elimTest5 def ex6 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) : LHS (Pat (inaccessible Nat.zero) Γ— Pat (Vec.nil : Vec Ξ± 0)) Γ— LHS (forall (N : Nat) (XS : Vec Ξ± N), Pat (inaccessible N) Γ— Pat XS) := arbitrary -- set_option trace.Meta.Match.match true -- set_option trace.Meta.Match.debug true #eval test `ex6 2 `elimTest6 -- #print elimTest6 def ex7 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) : LHS (forall (a : Ξ±), Pat (inaccessible 1) Γ— Pat (Vec.cons a Vec.nil)) Γ— LHS (forall (N : Nat) (XS : Vec Ξ± N), Pat (inaccessible N) Γ— Pat XS) := arbitrary #eval test `ex7 2 `elimTest7 -- #check elimTest7 def isSizeOne {n : Nat} (xs : Vec Nat n) : Bool := elimTest7 _ (fun _ _ => Bool) n xs (fun _ => true) (fun _ _ => false) #eval isSizeOne Vec.nil #eval isSizeOne (Vec.cons 1 Vec.nil) #eval isSizeOne (Vec.cons 2 (Vec.cons 1 Vec.nil)) def singleton? {n : Nat} (xs : Vec Nat n) : Option Nat := elimTest7 _ (fun _ _ => Option Nat) n xs (fun a => some a) (fun _ _ => none) #eval singleton? Vec.nil #eval singleton? (Vec.cons 10 Vec.nil) #eval singleton? (Vec.cons 20 (Vec.cons 10 Vec.nil)) def ex8 (Ξ± : Type u) (n : Nat) (xs : Vec Ξ± n) : LHS (forall (a b : Ξ±), Pat (inaccessible 2) Γ— Pat (Vec.cons a (Vec.cons b Vec.nil))) Γ— LHS (forall (N : Nat) (XS : Vec Ξ± N), Pat (inaccessible N) Γ— Pat XS) := arbitrary #eval test `ex8 2 `elimTest8 #print elimTest8 def pair? {n : Nat} (xs : Vec Nat n) : Option (Nat Γ— Nat) := elimTest8 _ (fun _ _ => Option (Nat Γ— Nat)) n xs (fun a b => some (a, b)) (fun _ _ => none) #eval pair? Vec.nil #eval pair? (Vec.cons 10 Vec.nil) #eval pair? (Vec.cons 20 (Vec.cons 10 Vec.nil)) inductive Op : Nat β†’ Nat β†’ Type | mk : βˆ€ n, Op n n structure Node : Type := (id₁ idβ‚‚ : Nat) (o : Op id₁ idβ‚‚) def ex9 (xs : List Node) : LHS (forall (h : Node) (t : List Node), Pat (h :: Node.mk 1 1 (Op.mk 1) :: t)) Γ— LHS (forall (ys : List Node), Pat ys) := arbitrary #eval test `ex9 1 `elimTest9 #print elimTest9 def f (xs : List Node) : Bool := elimTest9 (fun _ => Bool) xs (fun _ _ => true) (fun _ => false) #eval check (f [] == false) #eval check (f [⟨0, 0, Op.mk 0⟩] == false) #eval check (f [⟨0, 0, Op.mk 0⟩, ⟨1, 1, Op.mk 1⟩]) #eval check (f [⟨0, 0, Op.mk 0⟩, ⟨2, 2, Op.mk 2⟩] == false) inductive Foo : Bool β†’ Prop | bar : Foo false | baz : Foo false def ex10 (x : Bool) (y : Foo x) : LHS (Pat (inaccessible false) Γ— Pat Foo.bar) Γ— LHS (forall (x : Bool) (y : Foo x), Pat (inaccessible x) Γ— Pat y) := arbitrary #eval test `ex10 2 `elimTest10 true def ex11 (xs : List Node) : LHS (forall (h : Node) (t : List Node), Pat (h :: Node.mk 1 1 (Op.mk 1) :: t)) Γ— LHS (Pat ([] : List Node)) := arbitrary #eval testFailure `ex11 1 `elimTest11 -- should produce error message def ex12 (x y z : Bool) : LHS (forall (x y : Bool), Pat x Γ— Pat y Γ— Pat true) Γ— LHS (forall (x z : Bool), Pat false Γ— Pat true Γ— Pat z) Γ— LHS (forall (y z : Bool), Pat true Γ— Pat false Γ— Pat z) := arbitrary #eval testFailure `ex12 3 `elimTest12 -- should produce error message def ex13 (xs : List Node) : LHS (forall (h : Node) (t : List Node), Pat (h :: Node.mk 1 1 (Op.mk 1) :: t)) Γ— LHS (forall (ys : List Node), Pat ys) Γ— LHS (forall (ys : List Node), Pat ys) := arbitrary #eval testFailure `ex13 1 `elimTest13 -- should produce error message def ex14 (x y : Nat) : LHS (Pat (val 1) Γ— Pat (val 2)) Γ— LHS (Pat (val 2) Γ— Pat (val 3)) Γ— LHS (forall (x y : Nat), Pat x Γ— Pat y) := arbitrary -- set_option trace.Meta.Match true #eval test `ex14 2 `elimTest14 #print elimTest14 def h2 (x y : Nat) : Nat := elimTest14 (fun _ _ => Nat) x y (fun _ => 0) (fun _ => 1) (fun x y => x + y) #eval check (h2 1 2 == 0) #eval check (h2 1 4 == 5) #eval check (h2 2 3 == 1) #eval check (h2 2 4 == 6) #eval check (h2 3 4 == 7) def ex15 (xs : Array (List Nat)) : LHS (forall (a : Nat), Pat (ArrayLit1 [a])) Γ— LHS (forall (a b : Nat), Pat (ArrayLit2 [a] [b])) Γ— LHS (forall (ys : Array (List Nat)), Pat ys) := arbitrary #eval test `ex15 1 `elimTest15 -- #check elimTest15 def h3 (xs : Array (List Nat)) : Nat := elimTest15 (fun _ => Nat) xs (fun a => a + 1) (fun a b => a + b) (fun ys => ys.size) #eval check (h3 #[[1]] == 2) #eval check (h3 #[[3], [2]] == 5) #eval check (h3 #[[1, 2]] == 1) #eval check (h3 #[[1, 2], [2, 3], [3]] == 3) def ex16 (xs : List Nat) : LHS (forall (a : Nat) (xs : List Nat) (b : Nat) (as : List Nat), Pat (a :: As xs (b :: as))) Γ— LHS (forall (a : Nat), Pat ([a])) Γ— LHS (Pat ([] : List Nat)) := arbitrary #eval test `ex16 1 `elimTest16 -- #check elimTest16 #print elimTest16 def h4 (xs : List Nat) : List Nat := elimTest16 (fun _ => List Nat) xs (fun a xs b ys => xs) (fun a => []) (fun _ => [1]) #eval check (h4 [1, 2, 3] == [2, 3]) #eval check (h4 [1] == []) #eval check (h4 [] == [1])
54f05c74b67a4e438c576a77dd28643e18bf221e
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/linear_algebra/free_module/determinant.lean
326f70dbf3d0493340bdcda25cb25f3c1800bd7d
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
973
lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Alex J. Best -/ import linear_algebra.determinant import linear_algebra.free_module.finite.basic /-! # Determinants in free (finite) modules Quite a lot of our results on determinants (that you might know in vector spaces) will work for all free (finite) modules over any commutative ring. ## Main results * `linear_map.det_zero''`: The determinant of the constant zero map is zero, in a finite free nontrivial module. -/ @[simp] lemma linear_map.det_zero'' {R M : Type*} [comm_ring R] [add_comm_group M] [module R M] [module.free R M] [module.finite R M] [nontrivial M] : linear_map.det (0 : M β†’β‚—[R] M) = 0 := begin letI : nonempty (module.free.choose_basis_index R M) := (module.free.choose_basis R M).index_nonempty, nontriviality R, exact linear_map.det_zero' (module.free.choose_basis R M) end
01d40e9178ede41a0d78ee3908355e9c9fd3bce4
37becf0efe4d7dede56551dfb45910cf3f9f579e
/src/chromatic/chromatic.lean
d7446a4944c6e0a2edac7a230df9c20c6f68ee8a
[]
no_license
Pazzaz/lean-math
c66ff4ea9e99d4fbd9c3143e1a055f72a7bb936d
a61df645dcc7d91d1454129dd68833821ff02fb7
refs/heads/master
1,679,198,234,708
1,615,995,023,000
1,615,995,023,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
15,112
lean
-- TODO: Rewrite things using paritions / setoids? -- The relation would then be "are the same color". -- see `data.setoid.partition`. import topology.metric_space.basic import data.fintype.basic import data.real.basic import mod_two import analysis.normed_space.inner_product import data.setoid.partition import data.int.sqrt universe u /-- Whether a space can be colored using n colors while avoiding monochrome pairs with distances in `D`. -/ def space_colorable (X : Type u) [has_dist X] (D : finset ℝ) (n : β„•) : Prop := βˆƒ (f : X β†’ β„•), (βˆ€ a, f a < n) ∧ βˆ€ a b, (dist a b) ∈ D β†’ f a β‰  f b -- In our application `r_in` is a more "fine-grained" equivalence relation than `r_out` but that -- isn't needed for this theorem. -- It is a little annoying to have to write out `r_in.rel` instead of `β‰ˆ` but that is necessary when working with two setoids. theorem separation {X : Type u} [has_dist X] (d : ℝ) (r_in : setoid X) (r_out : setoid X) (h1 : βˆ€ (a b : X), r_in.rel a b β†’ dist a b < d) (h2 : βˆ€ (a b : X), (Β¬r_in.rel a b) β†’ r_out.rel a b β†’ dist a b > d) (x y : X) (h3 : r_out.rel x y) : dist x y β‰  d := begin by_contradiction hhh, rw not_not at hhh, have eq_imp_not_less : dist x y = d β†’ Β¬(dist x y) < d := by { intros bb, linarith, }, have := (h2 x y ((mt (h1 x y)) (eq_imp_not_less hhh))) h3, linarith, end def hex_open_f (r : ℝ) (x y : ℝ) : Prop := (real.sqrt 3)⁻¹ + y - r < 0 ∧ (real.sqrt 3)⁻¹ - y - r < 0 ∧ -(real.sqrt 3)⁻¹ + y - r < 0 ∧ -(real.sqrt 3)⁻¹ - y - r < 0 ∧ x - (real.sqrt 3)*2⁻¹*r < 0 ∧ -x - (real.sqrt 3)*2⁻¹*r < 0 def hex_left_up_ioo (r : ℝ) (x y : ℝ) : Prop := -(real.sqrt 3)*2⁻¹*r < x ∧ x < 0 ∧ y = x * (real.sqrt 3)⁻¹ + r def hex_left_side_icc (r : ℝ) (x y : ℝ) : Prop := -(r / 2) <= y ∧ y <= r / 2 ∧ x = -(r * (real.sqrt 3)⁻¹) def hex_left_down_ioc (r : ℝ) (x y : ℝ) : Prop := -(real.sqrt 3)*2⁻¹*r < x ∧ x <= 0 ∧ y = -(x * (real.sqrt 3)⁻¹ + r) -- A `hex_tile` is the open hexagon together with the three sides on the left def hex_tile (r : ℝ) : set (ℝ×ℝ) := set_of (Ξ» p, hex_open_f r p.1 p.2 ∨ hex_left_up_ioo r p.1 p.2 ∨ hex_left_side_icc r p.1 p.2 ∨ hex_left_down_ioc r p.1 p.2) def shift (k : (ℝ×ℝ)) (s : set (ℝ×ℝ)) : set (ℝ×ℝ) := set_of (Ξ» p, s (p - k)) -- theorem hex_inter_hex_shift_right_eq_empty -- : set.inter (hex_tile 1) (shift (⟨real.sqrt 3, 0⟩) (hex_tile 1)) = βˆ… -- := begin -- by_contradiction, -- let hhh : βˆƒ(x : ℝ×ℝ), (x : hex_tile 1) ∧ (x : (shift (⟨real.sqrt 3, 0⟩) (hex_tile 1))) := begin -- end, -- end theorem inv_eq_2 (a b : ℝ) (h : b β‰  0) : (1 / a) = b / (b*a) := begin exact (div_mul_right a h).symm, end theorem inv_eq_3 (a b c: ℝ) (h : c β‰  0) : a / b = (a*c) / (b*c) := begin exact (mul_div_mul_right a b h).symm, end theorem inv_eq_4 (a : ℝ) (h : a > 0) : real.sqrt a β‰  0 := begin exact real.sqrt_ne_zero'.mpr h, end theorem inv_eq_5 (a : ℝ) (h : 0 ≀ a) : (real.sqrt a) * (real.sqrt a) = a := begin exact real.mul_self_sqrt h, end theorem zero_le_three : 0 ≀ (3 : ℝ) := begin linarith, end theorem sub_div_add_div_eq_thing (a b c : ℝ) : -(a/b) + (c/b) = (-a + c) / b := begin ring, end theorem div_lt_zero_imp_numerator_lt_zero (a : ℝ) {b : ℝ} (h : b > 0) : (a / b) < 0 -> a < 0 := begin intro k, have ggg : b * (a/b) < b * 0 := (mul_lt_mul_left h).mpr k, rw [mul_zero b, (mul_div_cancel' a (ne_of_gt h))] at ggg, exact ggg, end theorem gfgfgdfgdsf (a b: ℝ) (h1 : a > 0) (h2 : b > 0) : a * real.sqrt b > 0 := begin exact mul_pos h1 (real.sqrt_pos.mpr h2), end theorem sqrt_three_gt_zero : real.sqrt 3 > 0 := begin norm_num, end #check real.sqrt_one theorem one_le_sqrt_three : 1 ≀ real.sqrt 3 := begin nth_rewrite 0 ←real.sqrt_one, refine real.sqrt_le_sqrt _, linarith, end theorem one_lt_sqrt_three : 1 < real.sqrt 3 := begin nth_rewrite 0 ←real.sqrt_one, refine (real.sqrt_lt zero_le_one).mpr _, linarith, end theorem sqrt_three_equat_pos : real.sqrt 3 + (1 / real.sqrt 3) - real.sqrt 3 * (1 / 2) β‰₯ 0 := begin calc real.sqrt 3 + (1 / real.sqrt 3) - real.sqrt 3 * (1 / 2) = real.sqrt 3 + (1 / real.sqrt 3) - (real.sqrt 3 / 2) : by rw mul_one_div (real.sqrt 3) 2 ... = (real.sqrt 3) / 2 + (1 / real.sqrt 3) : by linarith ... β‰₯ 0 : by { refine add_nonneg _ _, exact div_nonneg (le_of_lt sqrt_three_gt_zero) zero_le_two, exact div_nonneg zero_le_one (le_of_lt sqrt_three_gt_zero), } end theorem sqrt_three_equat_neg : -(1 / real.sqrt 3) + real.sqrt 3 * (1 / 2) - real.sqrt 3 < 0 := begin calc -(1 / real.sqrt 3) + real.sqrt 3 * (1 / 2) - real.sqrt 3 = -(1 / real.sqrt 3) + -(real.sqrt 3) / 2 : begin linarith, end ... < 0 : by { refine add_neg _ _, exact neg_neg_of_pos (div_pos zero_lt_one (gt.lt sqrt_three_gt_zero)), rw neg_div 2 (real.sqrt 3), exact neg_neg_of_pos (div_pos (gt.lt sqrt_three_gt_zero) zero_lt_two), } end theorem hfhfhf (a b: ℝ) : (-a) / b = - (a/b) := begin exact neg_div b a end theorem inv_leq_one {a : ℝ} (h2 : 1 ≀ a) : (1 / a) ≀ 1 := begin refine (div_le_one _).mpr h2, linarith, end theorem ge_one_imp_sub_inv_ge_zero (x: ℝ) (h : 1 ≀ x) : x - (1/x) β‰₯ 0 := begin have jdjdj : βˆ€ (x1 : ℝ), 1 ≀ x1 -> 1/x1 ≀ x1 := by { intros xxx leee, calc (1 / xxx) ≀ 1 : inv_leq_one leee ... ≀ xxx : leee }, exact sub_nonneg.mpr (jdjdj x h), end /- Not actually used -/ theorem sub_lt_zero_iff {X : Type*} [ordered_add_comm_group X] {a b : X} : a - b < 0 ↔ b - a > 0 := begin refine (iff.intro _ _), intro h, have hue := neg_lt_neg h, rw [neg_zero, neg_sub a b] at hue, exact hue, intro h, have hue := neg_lt_neg h, rw [neg_zero, neg_sub b a] at hue, exact hue, end theorem ge_one_imp_sub_inv_gt_zero (x: ℝ) (h : 1 < x) : x - (1/x) > 0 := begin have jdjdj : βˆ€ (x1 : ℝ), 1 < x1 -> 1/x1 < x1 := by { intros xxx leee, calc (1 / xxx) = xxx⁻¹ : one_div xxx ... < 1 : inv_lt_one leee ... < xxx : leee }, exact sub_pos.mpr (jdjdj x h), end theorem another_case {x : ℝ} (hh7: x = -(1 / real.sqrt 3)) (hh13: x - real.sqrt 3 = -(1 / real.sqrt 3)) : false := begin rw hh7 at hh13, have sqrt_three_eq_zero : real.sqrt 3 = 0 := by linarith, rw ←real.sqrt_zero at sqrt_three_eq_zero, have yepp : (3 : ℝ) = 0 := by { refine (real.sqrt_inj _ _).mp (sqrt_three_eq_zero), exact zero_le_three, exact rfl.ge, }, linarith, end -- How can I avoid the annoying case analysis? I should probably use rcases. theorem in_the_middle (x : ℝ×ℝ) (h : (x ∈ hex_tile 1)) (h2 : (x ∈ shift (⟨real.sqrt 3, 0⟩) (hex_tile 1))) : false := begin rw [hex_tile] at h, simp at *, rw [shift] at h2, rw [hex_tile] at h2, simp at h2, rw set.set_of_app_iff at h2, unfold hex_open_f hex_left_up_ioo hex_left_side_icc hex_left_down_ioc at h, unfold hex_open_f hex_left_up_ioo hex_left_side_icc hex_left_down_ioc at h2, simp at h, simp at h2, set xx : ℝ := x.fst, set yy : ℝ := x.snd, cases h, cases h2, have huehue21 : xx < real.sqrt 3 / 2 := by tauto, have huehue22 : real.sqrt 3 - xx < real.sqrt 3 / 2 := by tauto, linarith only [huehue21, huehue22], cases h2, have hh5 := h.2.2.2.2.1, have hh7 := h2.1, have huehue21 : xx < real.sqrt 3 / 2 := by tauto, have huehue22 : real.sqrt 3 < xx + real.sqrt 3 / 2 := by tauto, linarith only [huehue21, huehue22], rw [inv_eq_one_div (real.sqrt 3), inv_eq_one_div (2 : ℝ)] at h, rw [inv_eq_one_div (real.sqrt 3), inv_eq_one_div (2 : ℝ)] at h2, cases h2, have hh9 := h.2.2.2.2.1, have hh13 := h2.2.2, have xxx3 : -(1 / real.sqrt 3) + (real.sqrt 3) / 2 < 0 := by linarith, rw (div_mul_right (real.sqrt 3) two_ne_zero).symm at xxx3, rw ((mul_div_mul_right (real.sqrt 3) 2 (real.sqrt_ne_zero'.mpr zero_lt_three)).symm ) at xxx3, rw (real.mul_self_sqrt (zero_le_three)) at xxx3, rw (sub_div_add_div_eq_thing 2 (2 * real.sqrt 3) 3) at xxx3, let kkkkk := div_lt_zero_imp_numerator_lt_zero (-2 + 3) (mul_pos (zero_lt_two) sqrt_three_gt_zero) xxx3, linarith only [kkkkk], linarith, rw [inv_eq_one_div (real.sqrt 3), inv_eq_one_div (2 : ℝ)] at h, rw [inv_eq_one_div (real.sqrt 3), inv_eq_one_div (2 : ℝ)] at h2, cases h2, cases h, linarith, cases h, have hh10 := h2.2.2.2.2.2, have hh13 := h.2.2, rw hh13 at hh10, norm_num at hh10, have huehue : real.sqrt 3 + (1 / real.sqrt 3) - real.sqrt 3 * (1 / 2) < 0 := sub_lt_zero.mpr hh10, let llll := sqrt_three_equat_pos, linarith, linarith, cases h2, cases h, linarith, cases h, have hh7 := h.2.2, have hh11 := h2.1, rw hh7 at hh11, have huehue : 0 < -(1 / real.sqrt 3) + real.sqrt 3 * (1 / 2) - real.sqrt 3 := sub_pos.mpr hh11, let llll := sqrt_three_equat_neg, linarith, linarith, cases h2, cases h, have hh6 := h.2.1, have hh13 := h2.2.2, have djdjdjdj : xx = -(1 / real.sqrt 3) + real.sqrt 3 := begin linarith, end, rw djdjdjdj at hh6, have hh99 : (real.sqrt 3) - (1/ (real.sqrt 3)) β‰₯ 0 := begin exact ge_one_imp_sub_inv_ge_zero (real.sqrt 3) one_le_sqrt_three, end, linarith, cases h, exact another_case h.2.2 h2.2.2, have hh6 := h.2.1, have hh13 := h2.2.2, have djdjdjdj : xx = -(1 / real.sqrt 3) + real.sqrt 3 := begin linarith, end, rw djdjdjdj at hh6, have hh99 : (real.sqrt 3) - (1/ (real.sqrt 3)) > 0 := begin exact ge_one_imp_sub_inv_gt_zero (real.sqrt 3) one_lt_sqrt_three, end, linarith, cases h, linarith, cases h, sorry, sorry, end theorem simple_hfhfhf : ((1*1) - 1)/1 = 0 := by simp -- theorem step_simple_hfhfhf -- (h1: xx = -(1 / real.sqrt 3)) -- hh11: -(1 / 2) ≀ yy -- hh12: yy ≀ 1 / 2 -- hh13: xx - real.sqrt 3 = -(1 / real.sqrt 3) -- := begin -- ring, -- finish, -- end /- have hh5 := h.1, have hh6 := h.2.1, have hh7 := h.2.2.1, have hh8 := h.2.2.2.1, have hh9 := h.2.2.2.2.1, have hh10 := h.2.2.2.2.2, have hh11 := h2.1, have hh12 := h2.2.1, have hh13 := h2.2.2, -/ /- -(Sqrt[3] * (1 / 2)) < x && x ≀ 0 && y = -1 + -(x * (1 / Sqrt[3])) && -(1 / 2) ≀ y && y ≀ 1 / 2 && x - Sqrt[3] = -(1 / Sqrt[3]) -/ theorem hex_inter_hex_shift_right_eq_empty_imp_shift_le_sqrt_three (x : ℝ) : set.inter (hex_tile 1) (shift (⟨x, 0⟩) (hex_tile 1)) = βˆ… β†’ real.sqrt 3 ≀ x := sorry theorem hex_inter_hex_shift_right_eq_empty_imp_shift_le_scale_mul_sqrt_three (x : ℝ) (s : ℝ) : set.inter (hex_tile s) (shift (⟨x, 0⟩) (hex_tile s)) = βˆ… β†’ s * real.sqrt 3 ≀ x := sorry /-- An inhabitated space cannot be colored with 0 colors -/ theorem chrom_absurd (X : Type u) [has_dist X] [inhabited X] (D : finset ℝ) (n : β„•) : Β¬space_colorable X D 0 := begin rw space_colorable, simp, end theorem chrom_larger (X : Type u) [has_dist X] (D : finset ℝ) (n : β„•) : space_colorable X D n β†’ space_colorable X D (n+1) := begin rw [space_colorable, space_colorable], intro f1, refine exists.elim f1 _, intros k1 k2, have : βˆ€(a : X), k1 a < n+1 := begin intro a, exact nat.lt.step (k2.left a), end, tidy, end theorem chrom_smaller (X : Type u) [has_dist X] (D : finset ℝ) (n : β„•) : Β¬space_colorable X D n β†’ Β¬space_colorable X D (n-1) := begin refine not_imp_not.mpr _, induction n, exact id, intro k, exact chrom_larger X D _ k, end theorem if_eq_else_imp_false {c : Prop} [decidable c] {Ξ± : Type*} {t e : Ξ±} (h_eq : ite c t e = e) (h_ne : t β‰  e) : Β¬c := begin by_contradiction p_pos, exact h_ne ((rfl.congr (if_pos p_pos)).mp (h_eq.symm)).symm, end theorem if_eq_then_imp_true {c : Prop} [decidable c] {Ξ± : Type*} {t e : Ξ±} (h_eq : ite c t e = t) (h_ne : t β‰  e) : c := begin by_contradiction p_neg, exact h_ne ((rfl.congr (if_neg p_neg)).mp (h_eq.symm)), end theorem chrom_of_real_line_bounded_contradiction {a b: ℝ} (αΎ°: dist a b = 1) (αΎ°_1: ite (mod_two a < 1) 0 1 = ite (mod_two b < 1) 0 1) (al : 0 ≀ a) (au : a < 2) (bl : 0 ≀ b) (bu : b < 2) : false := begin cases decidable.em (mod_two a < 1) with hat haf, rw (if_pos hat) at αΎ°_1, cases decidable.em (mod_two b < 1) with hbt hbf, rw (if_pos hbt) at αΎ°_1, rw real.dist_eq at αΎ°, have hhha : a < 1 := bounding_mod_two a au al hat, have hhhb : b < 1 := bounding_mod_two b bu bl hbt, have hpos : a - b < 1, by linarith, have hpos_neg : -(a - b) < 1, by linarith, have abs_bound : abs (a - b) < 1, by { exact max_lt hpos hpos_neg }, linarith, have hmtb : ite (mod_two b < 1) 0 1 = 1, { exact if_neg hbf }, linarith, have hmta : ite (mod_two a < 1) 0 1 = 1, { exact if_neg haf }, rw hmta at αΎ°_1, have hbf : Β¬(mod_two b < 1) := if_eq_else_imp_false αΎ°_1.symm zero_ne_one, rw (bounding_id b bu bl) at hbf, have haf_expand : Β¬mod_two a < 1 := haf, rw (bounding_id a au al) at haf_expand, have hpos : a - b < 1, by linarith, have hpos_neg : -(a - b) < 1, by linarith, have abs_bound : abs (a - b) < 1, by { exact max_lt hpos hpos_neg }, rw real.dist_eq at αΎ°, exact ne_of_lt abs_bound αΎ°, end theorem dist_mod_two_eq_dist (x y : ℝ) (h : dist x y = 1) : dist (mod_two x) (mod_two y) = 1 := begin rw real.dist_eq at h, rw real.dist_eq, cases decidable.em (x > y) with x_ge_y ne_x_ge_y, by { rw (abs_of_pos (sub_pos.mpr x_ge_y)) at h, have y_simp : y = x-1, by linarith, rw y_simp, exact (abs_of_mod_two_sub_mod_two_of_sub_one_eq_one x), }, { have abs_simp : abs (x - y) = y - x, by { have := abs_sub x y, finish, }, rw abs_simp at h, have y_simp : x = y-1, by linarith, rw y_simp, rw abs_sub (mod_two (y - 1)) (mod_two y), exact (abs_of_mod_two_sub_mod_two_of_sub_one_eq_one y), } end /-- A coloring of the real line used in `real_line_colorable_avoiding_one_with_two`. -/ private noncomputable def line_color (x : ℝ) : β„• := ite (mod_two x < 1) 0 1 /-- The real number line can be colored with two colors while avoiding monochrome unit distances. --/ theorem colorable_real_line_avoiding_one_with_two : space_colorable ℝ {1} 2 := begin tidy, exact (line_color αΎ°), rw line_color, cases decidable.em (mod_two a < 1) with H1 H2, rw (if_pos H1), exact zero_lt_two, rw (if_neg H2), exact one_lt_two, rw [line_color, line_color] at αΎ°_1, rw ←mod_two_idempotent a at αΎ°_1, rw ←mod_two_idempotent b at αΎ°_1, exact (chrom_of_real_line_bounded_contradiction (dist_mod_two_eq_dist a b αΎ°) αΎ°_1 (ge_iff_le.mp (mod_two_geq_0 a)) (mod_two_le_2 a) (ge_iff_le.mp (mod_two_geq_0 b)) (mod_two_le_2 b) ), end
9e2cd8fd234a183e9ca052085426f0c5626f2b22
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/library/init/quot.lean
52b96ca0e8a1b6c8e2dc0cd29985a2418cda4ae8
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
7,790
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura Quotient types. -/ prelude import init.sigma init.setoid init.logic open sigma.ops setoid universe variables u v constant quot : Ξ  {A : Type u}, setoid A β†’ Type u -- Remark: if we do not use propext here, then we would need a quot.lift for propositions. constant propext {a b : Prop} : (a ↔ b) β†’ a = b -- iff can now be used to do substitutions in a calculation attribute [subst] theorem iff_subst {a b : Prop} {P : Prop β†’ Prop} (H₁ : a ↔ b) (Hβ‚‚ : P a) : P b := eq.subst (propext H₁) Hβ‚‚ namespace quot protected constant mk : Ξ  {A : Type u} [s : setoid A], A β†’ quot s notation `⟦`:max a `⟧`:0 := quot.mk a constant sound : Ξ  {A : Type u} [s : setoid A] {a b : A}, a β‰ˆ b β†’ ⟦a⟧ = ⟦b⟧ constant lift : Ξ  {A : Type u} {B : Type v} [s : setoid A] (f : A β†’ B), (βˆ€ a b, a β‰ˆ b β†’ f a = f b) β†’ quot s β†’ B constant ind : βˆ€ {A : Type u} [s : setoid A] {B : quot s β†’ Prop}, (βˆ€ a, B ⟦a⟧) β†’ βˆ€ q, B q attribute [elab_as_eliminator] lift ind init_quotient protected theorem lift_beta {A : Type u} {B : Type v} [setoid A] (f : A β†’ B) (c : βˆ€ a b, a β‰ˆ b β†’ f a = f b) (a : A) : lift f c ⟦a⟧ = f a := rfl protected theorem ind_beta {A : Type u} [s : setoid A] {B : quot s β†’ Prop} (p : βˆ€ a, B ⟦a⟧) (a : A) : (ind p ⟦a⟧ : B ⟦a⟧) = p a := rfl attribute [reducible, elab_as_eliminator] protected definition lift_on {A : Type u} {B : Type v} [s : setoid A] (q : quot s) (f : A β†’ B) (c : βˆ€ a b, a β‰ˆ b β†’ f a = f b) : B := lift f c q attribute [elab_as_eliminator] protected theorem induction_on {A : Type u} [s : setoid A] {B : quot s β†’ Prop} (q : quot s) (H : βˆ€ a, B ⟦a⟧) : B q := ind H q theorem exists_rep {A : Type u} [s : setoid A] (q : quot s) : βˆƒ a : A, ⟦a⟧ = q := quot.induction_on q (Ξ» a, ⟨a, rfl⟩) section variable {A : Type u} variable [s : setoid A] variable {B : quot s β†’ Type v} include s attribute [reducible] protected definition indep (f : Ξ  a, B ⟦a⟧) (a : A) : Ξ£ q, B q := ⟨⟦a⟧, f a⟩ protected lemma indep_coherent (f : Ξ  a, B ⟦a⟧) (H : βˆ€ (a b : A) (p : a β‰ˆ b), (eq.rec (f a) (sound p) : B ⟦b⟧) = f b) : βˆ€ a b, a β‰ˆ b β†’ quot.indep f a = quot.indep f b := Ξ» a b e, sigma.eq (sound e) (H a b e) protected lemma lift_indep_pr1 (f : Ξ  a, B ⟦a⟧) (H : βˆ€ (a b : A) (p : a β‰ˆ b), (eq.rec (f a) (sound p) : B ⟦b⟧) = f b) (q : quot s) : (lift (quot.indep f) (quot.indep_coherent f H) q).1 = q := quot.ind (Ξ» (a : A), eq.refl (quot.indep f a).1) q attribute [reducible, elab_as_eliminator] protected definition rec (f : Ξ  a, B ⟦a⟧) (H : βˆ€ (a b : A) (p : a β‰ˆ b), (eq.rec (f a) (sound p) : B ⟦b⟧) = f b) (q : quot s) : B q := eq.rec_on (quot.lift_indep_pr1 f H q) ((lift (quot.indep f) (quot.indep_coherent f H) q).2) attribute [reducible, elab_as_eliminator] protected definition rec_on (q : quot s) (f : Ξ  a, B ⟦a⟧) (H : βˆ€ (a b : A) (p : a β‰ˆ b), (eq.rec (f a) (sound p) : B ⟦b⟧) = f b) : B q := quot.rec f H q attribute [reducible, elab_as_eliminator] protected definition rec_on_subsingleton [H : βˆ€ a, subsingleton (B ⟦a⟧)] (q : quot s) (f : Ξ  a, B ⟦a⟧) : B q := quot.rec f (Ξ» a b h, subsingleton.elim _ (f b)) q attribute [reducible, elab_as_eliminator] protected definition hrec_on (q : quot s) (f : Ξ  a, B ⟦a⟧) (c : βˆ€ (a b : A) (p : a β‰ˆ b), f a == f b) : B q := quot.rec_on q f (Ξ» a b p, eq_of_heq (calc (eq.rec (f a) (sound p) : B ⟦b⟧) == f a : eq_rec_heq (sound p) (f a) ... == f b : c a b p)) end section universe variables u_a u_b u_c variables {A : Type u_a} {B : Type u_b} {C : Type u_c} variables [s₁ : setoid A] [sβ‚‚ : setoid B] include s₁ sβ‚‚ attribute [reducible, elab_as_eliminator] protected definition liftβ‚‚ (f : A β†’ B β†’ C)(c : βˆ€ a₁ aβ‚‚ b₁ bβ‚‚, a₁ β‰ˆ b₁ β†’ aβ‚‚ β‰ˆ bβ‚‚ β†’ f a₁ aβ‚‚ = f b₁ bβ‚‚) (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) : C := quot.lift (Ξ» (a₁ : A), quot.lift (f a₁) (Ξ» (a b : B), c a₁ a a₁ b (setoid.refl a₁)) qβ‚‚) (Ξ» (a b : A) (H : a β‰ˆ b), @quot.ind B sβ‚‚ (Ξ» (a_1 : quot sβ‚‚), (quot.lift (f a) (Ξ» (a_1 b : B), c a a_1 a b (setoid.refl a)) a_1) = (quot.lift (f b) (Ξ» (a b_1 : B), c b a b b_1 (setoid.refl b)) a_1)) (Ξ» (a' : B), c a a' b a' H (setoid.refl a')) qβ‚‚) q₁ attribute [reducible, elab_as_eliminator] protected definition lift_onβ‚‚ (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) (f : A β†’ B β†’ C) (c : βˆ€ a₁ aβ‚‚ b₁ bβ‚‚, a₁ β‰ˆ b₁ β†’ aβ‚‚ β‰ˆ bβ‚‚ β†’ f a₁ aβ‚‚ = f b₁ bβ‚‚) : C := quot.liftβ‚‚ f c q₁ qβ‚‚ attribute [elab_as_eliminator] protected theorem indβ‚‚ {C : quot s₁ β†’ quot sβ‚‚ β†’ Prop} (H : βˆ€ a b, C ⟦a⟧ ⟦b⟧) (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) : C q₁ qβ‚‚ := quot.ind (Ξ» a₁, quot.ind (Ξ» aβ‚‚, H a₁ aβ‚‚) qβ‚‚) q₁ attribute [elab_as_eliminator] protected theorem induction_onβ‚‚ {C : quot s₁ β†’ quot sβ‚‚ β†’ Prop} (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) (H : βˆ€ a b, C ⟦a⟧ ⟦b⟧) : C q₁ qβ‚‚ := quot.ind (Ξ» a₁, quot.ind (Ξ» aβ‚‚, H a₁ aβ‚‚) qβ‚‚) q₁ attribute [elab_as_eliminator] protected theorem induction_on₃ [s₃ : setoid C] {D : quot s₁ β†’ quot sβ‚‚ β†’ quot s₃ β†’ Prop} (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) (q₃ : quot s₃) (H : βˆ€ a b c, D ⟦a⟧ ⟦b⟧ ⟦c⟧) : D q₁ qβ‚‚ q₃ := quot.ind (Ξ» a₁, quot.ind (Ξ» aβ‚‚, quot.ind (Ξ» a₃, H a₁ aβ‚‚ a₃) q₃) qβ‚‚) q₁ end section exact variable {A : Type u} variable [s : setoid A] include s private definition rel (q₁ qβ‚‚ : quot s) : Prop := quot.lift_onβ‚‚ q₁ qβ‚‚ (Ξ» a₁ aβ‚‚, a₁ β‰ˆ aβ‚‚) (Ξ» a₁ aβ‚‚ b₁ bβ‚‚ a₁b₁ aβ‚‚bβ‚‚, propext (iff.intro (Ξ» a₁aβ‚‚, setoid.trans (setoid.symm a₁b₁) (setoid.trans a₁aβ‚‚ aβ‚‚bβ‚‚)) (Ξ» b₁bβ‚‚, setoid.trans a₁b₁ (setoid.trans b₁bβ‚‚ (setoid.symm aβ‚‚bβ‚‚))))) local infix `~` := rel private lemma rel.refl : βˆ€ q : quot s, q ~ q := Ξ» q, quot.induction_on q (Ξ» a, setoid.refl a) private lemma eq_imp_rel {q₁ qβ‚‚ : quot s} : q₁ = qβ‚‚ β†’ q₁ ~ qβ‚‚ := assume h, eq.rec_on h (rel.refl q₁) theorem exact {a b : A} : ⟦a⟧ = ⟦b⟧ β†’ a β‰ˆ b := assume h, eq_imp_rel h end exact section universe variables u_a u_b u_c variables {A : Type u_a} {B : Type u_b} variables [s₁ : setoid A] [sβ‚‚ : setoid B] include s₁ sβ‚‚ attribute [reducible, elab_as_eliminator] protected definition rec_on_subsingletonβ‚‚ {C : quot s₁ β†’ quot sβ‚‚ β†’ Type u_c} [H : βˆ€ a b, subsingleton (C ⟦a⟧ ⟦b⟧)] (q₁ : quot s₁) (qβ‚‚ : quot sβ‚‚) (f : Ξ  a b, C ⟦a⟧ ⟦b⟧) : C q₁ qβ‚‚:= @quot.rec_on_subsingleton _ s₁ (Ξ» q, C q qβ‚‚) (Ξ» a, quot.ind (Ξ» b, H a b) qβ‚‚) q₁ (Ξ» a, quot.rec_on_subsingleton qβ‚‚ (Ξ» b, f a b)) end end quot attribute quot.mk open decidable attribute [instance] definition quot.has_decidable_eq {A : Type u} {s : setoid A} [decR : βˆ€ a b : A, decidable (a β‰ˆ b)] : decidable_eq (quot s) := Ξ» q₁ qβ‚‚ : quot s, quot.rec_on_subsingletonβ‚‚ q₁ qβ‚‚ (Ξ» a₁ aβ‚‚, match (decR a₁ aβ‚‚) with | (is_true h₁) := is_true (quot.sound h₁) | (is_false hβ‚‚) := is_false (Ξ» h, absurd (quot.exact h) hβ‚‚) end)
e26f6c028b06b97796ffdc275b9963b403ef23d1
92e157ec9825b5e4597a6d715a8928703bc8e3b2
/src/mywork/lecture_4.lean
05178cf8e57ecd2cfdc41e163f3865b4adeb7070
[]
no_license
exb3dg/cs2120f21
9e566bc508762573c023d3e70f83cb839c199ec8
319b8bf0d63bf96437bf17970ce0198d0b3525cd
refs/heads/main
1,692,970,909,568
1,634,584,540,000
1,634,584,540,000
399,947,025
0
0
null
null
null
null
UTF-8
Lean
false
false
3,396
lean
/- In this file, we give formal statements (our version) of the two axioms of equality. We also present Lean's versions of these rules, and show how you can use them without giving all of the arguments explicitly. -/ /- AXIOMS Everything is equal to itself. A bit more formally, if one is given a type, T, and a value, t, of this type, then you may have a proof of t = t "for free." -/ axiom eq_refl : βˆ€ (T : Type) -- if T is any type (of thing) (t : T), -- and t is thing of that type, T t = t -- the result type: proof of t = t /- INFERENCE RULE #2/2: SUBSTITUTION OF EQUALS FOR EQUALS Given any type, T, of objects, and any *property*, P, of objects of this type, if you know x has property P (written as P x) and you know that x = y, then you can deduce that y has property P. -/ axiom eq_subst : βˆ€ (T : Type) -- if T is a type (P : T β†’ Prop) -- and P is a property of T objects (x y : T) -- and x and y are T objects (e : x = y) -- and you have a proof that x = y (px : P x), -- and you have a proof that x has property P P y -- then you can deduce (and get a proof) of P y /- The Lean versions of these axioms are called eq.refl and eq.subst. They're defined in ways that allow (and require) one not to give the T, P, x, or y parameters explicitly when applying eq_subst. More details come later. -/ /- We will now present formal proofs of our two theorems in this style. -/ /- CONJECTURES -/ -- We define eq_symm to be the proposition at issue -- Note: Prop is the type of all propositions in Lean -- And each proposition is itself a type: of it proofs def eq_symm : Prop := βˆ€ (T : Type) -- for all T of type Type (x y : T), -- for objects x and y of Type T x = y β†’ -- x = y and y = x -- y -x -- We define eq_trans formally in the same basic way def eq_trans : Prop := βˆ€ (T : Type) (x y z : T), x = y β†’ y = z β†’ x = z /- PROOFS: From conjectures to theorems -/ /- Proofs: equality is symmetric. -/ example : eq_symm := begin unfold eq_symm, -- replace name with definition assume T x y e, -- assume arbitrary values rw e, -- rw uses eq.subst to replace x with y -- and then applies eq.refl automatically -- QED. end /- A fundamental idea is that any proof is as good as any other for establishing the truth of a proposition. Here is an equally good alternative proof (or to be correct, proof-generating scripts in the "proof tactic" language" of the Lean Prover. -/ example : eq_symm := begin unfold eq_symm, -- replace name with definition assume T x y e, -- assume arbitrary values apply eq.subst e, -- apply axiom 2, substitutability exact eq.refl x, -- apply axiom 1, reflexivity -- QED. end /- Proof: equality is transitive. -/ example : eq_trans := begin unfold eq_trans, assume T, assume x y z, assume e1, assume e2, rw e1, exact e2, end /- Note: Lean defines these rules as - eq.refl - eq.subst - eq.symm - eq.trans -/ /- Practice -/ example : βˆ€ (T : Type), βˆ€ (x y z : T), x = y β†’ y = z β†’ z = x := begin /- assume T, assume (x :T ), assume (y : T), assume (z : T), assume h1, assume h2, rw h1, -/ assume T x y z, assume h1 h2, apply eq.symm _, apply eq.trans h1 h2, end /- INTRODUCTION and ELIMINATION RULES -/
6a6fba1c22868da711e9e9c883f3b28085e95ede
63abd62053d479eae5abf4951554e1064a4c45b4
/src/category_theory/filtered.lean
2628c823c3cad8449507a2fa927fe067d80faae6
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
8,762
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import category_theory.fin_category import category_theory.limits.cones import order.bounded_lattice /-! # Filtered categories A category is filtered if every finite diagram admits a cocone. We give a simple characterisation of this condition as 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. Filtered colimits are often better behaved than arbitrary colimits. See `category_theory/limits/types` for some details. Filtered categories are nice because colimits indexed by filtered categories tend to be easier to describe than general colimits (and often often preserved by functors). In this file we show that any functor from a finite category to a filtered category admits a cocone: * `cocone_nonempty [fin_category J] [is_filtered C] (F : J β₯€ C) : nonempty (cocone F)` More generally, for any finite collection of objects and morphisms between them in a filtered category (even if not closed under composition) there exists some object `Z` receiving maps from all of them, so that all the triangles (one edge from the finite set, two from morphisms to `Z`) commute. This formulation is often more useful in practice. We give two variants, `sup_exists'`, which takes a single finset of objects, and a finset of morphisms (bundled with their sources and targets), and `sup_exists`, which takes a finset of objects, and an indexed family (indexed by source and target) of finsets of morphisms. ## Future work * Finite limits commute with filtered colimits * Forgetful functors for algebraic categories typically preserve filtered colimits. -/ universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation namespace category_theory variables (C : Type u) [category.{v} C] /-- A category `is_filtered_or_empty` if 1. for every pair of objects there exists another object "to the right", and 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal. -/ class is_filtered_or_empty : Prop := (cocone_objs : βˆ€ (X Y : C), βˆƒ Z (f : X ⟢ Z) (g : Y ⟢ Z), true) (cocone_maps : βˆ€ ⦃X Y : C⦄ (f g : X ⟢ Y), βˆƒ Z (h : Y ⟢ Z), f ≫ h = g ≫ h) /-- A category `is_filtered` if 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. See https://stacks.math.columbia.edu/tag/002V. (They also define a diagram being filtered.) -/ class is_filtered extends is_filtered_or_empty C : Prop := [nonempty : nonempty C] @[priority 100] instance is_filtered_or_empty_of_semilattice_sup (Ξ± : Type u) [semilattice_sup Ξ±] : is_filtered_or_empty Ξ± := { cocone_objs := Ξ» X Y, ⟨X βŠ” Y, hom_of_le le_sup_left, hom_of_le le_sup_right, trivial⟩, cocone_maps := Ξ» X Y f g, ⟨Y, πŸ™ _, (by ext)⟩, } @[priority 100] instance is_filtered_of_semilattice_sup_top (Ξ± : Type u) [semilattice_sup_top Ξ±] : is_filtered Ξ± := { nonempty := ⟨⊀⟩, ..category_theory.is_filtered_or_empty_of_semilattice_sup Ξ± } namespace is_filtered variables {C} [is_filtered C] /-- `max j j'` is an arbitrary choice of object to the right of both `j` and `j'`, whose existence is ensured by `is_filtered`. -/ noncomputable def max (j j' : C) : C := (is_filtered_or_empty.cocone_objs j j').some /-- `left_to_max j j'` is an arbitrarily choice of morphism from `j` to `max j j'`, whose existence is ensured by `is_filtered`. -/ noncomputable def left_to_max (j j' : C) : j ⟢ max j j' := (is_filtered_or_empty.cocone_objs j j').some_spec.some /-- `right_to_max j j'` is an arbitrarily choice of morphism from `j'` to `max j j'`, whose existence is ensured by `is_filtered`. -/ noncomputable def right_to_max (j j' : C) : j' ⟢ max j j' := (is_filtered_or_empty.cocone_objs j j').some_spec.some_spec.some /-- `coeq f f'`, for morphisms `f f' : j ⟢ j'`, is an arbitrary choice of object which admits a morphism `coeq_hom f f' : j' ⟢ coeq f f'` such that `coeq_condition : f ≫ coeq_hom f f' = f' ≫ coeq_hom f f'`. Its existence is ensured by `is_filtered`. -/ noncomputable def coeq {j j' : C} (f f' : j ⟢ j') : C := (is_filtered_or_empty.cocone_maps f f').some /-- `coeq_hom f f'`, for morphisms `f f' : j ⟢ j'`, is an arbitrary choice of morphism `coeq_hom f f' : j' ⟢ coeq f f'` such that `coeq_condition : f ≫ coeq_hom f f' = f' ≫ coeq_hom f f'`. Its existence is ensured by `is_filtered`. -/ noncomputable def coeq_hom {j j' : C} (f f' : j ⟢ j') : j' ⟢ coeq f f' := (is_filtered_or_empty.cocone_maps f f').some_spec.some /-- `coeq_condition f f'`, for morphisms `f f' : j ⟢ j'`, is the proof that `f ≫ coeq_hom f f' = f' ≫ coeq_hom f f'`. -/ lemma coeq_condition {j j' : C} (f f' : j ⟢ j') : f ≫ coeq_hom f f' = f' ≫ coeq_hom f f' := (is_filtered_or_empty.cocone_maps f f').some_spec.some_spec open category_theory.limits /-- Any finite collection of objects in a filtered category has an object "to the right". -/ lemma sup_objs_exists (O : finset C) : βˆƒ (S : C), βˆ€ {X}, X ∈ O β†’ _root_.nonempty (X ⟢ S) := begin classical, apply finset.induction_on O, { exact ⟨is_filtered.nonempty.some, (by rintros - ⟨⟩)⟩, }, { rintros X O' nm ⟨S', w'⟩, use max X S', rintros Y mY, by_cases h : X = Y, { subst h, exact ⟨left_to_max _ _⟩, }, { exact ⟨(w' (by finish)).some ≫ right_to_max _ _⟩, }, } end variables (O : finset C) (H : finset (Ξ£' (X Y : C) (mX : X ∈ O) (mY : Y ∈ O), X ⟢ Y)) /-- Given any `finset` of objects `{X, ...}` and indexed collection of `finset`s of morphisms `{f, ...}` in `C`, there exists an object `S`, with a morphism `T X : X ⟢ S` from each `X`, such that the triangles commute: `f ≫ T X = T Y`, for `f : X ⟢ Y` in the `finset`. -/ lemma sup_exists : βˆƒ (S : C) (T : Ξ  {X : C}, X ∈ O β†’ (X ⟢ S)), βˆ€ {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟢ Y}, (⟨X, Y, mX, mY, f⟩ : (Ξ£' (X Y : C) (mX : X ∈ O) (mY : Y ∈ O), X ⟢ Y)) ∈ H β†’ f ≫ T mY = T mX := begin classical, apply finset.induction_on H, { obtain ⟨S, f⟩ := sup_objs_exists O, refine ⟨S, Ξ» X mX, (f mX).some, _⟩, rintros - - - - - ⟨⟩, }, { rintros ⟨X, Y, mX, mY, f⟩ H' nmf ⟨S', T', w'⟩, refine ⟨coeq (f ≫ T' mY) (T' mX), Ξ» Z mZ, T' mZ ≫ coeq_hom (f ≫ T' mY) (T' mX), _⟩, intros X' Y' mX' mY' f' mf', rw [←category.assoc], by_cases h : X = X' ∧ Y = Y', { rcases h with ⟨rfl, rfl⟩, by_cases hf : f = f', { subst hf, apply coeq_condition, }, { rw w' _ _ (by finish), }, }, { rw w' _ _ (by finish), }, }, end /-- An arbitrary choice of object "to the right" of a finite collection of objects `O` and morphisms `H`, making all the triangles commute. -/ noncomputable def sup : C := (sup_exists O H).some /-- The morphisms to `sup O H`. -/ noncomputable def to_sup {X : C} (m : X ∈ O) : X ⟢ sup O H := (sup_exists O H).some_spec.some m /-- The triangles of consisting of a morphism in `H` and the maps to `sup O H` commute. -/ lemma to_sup_commutes {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟢ Y} (mf : (⟨X, Y, mX, mY, f⟩ : Ξ£' (X Y : C) (mX : X ∈ O) (mY : Y ∈ O), X ⟢ Y) ∈ H) : f ≫ to_sup O H mY = to_sup O H mX := (sup_exists O H).some_spec.some_spec mX mY mf variables {J : Type v} [small_category J] [fin_category J] /-- If we have `is_filtered C`, then for any functor `F : J β₯€ C` with `fin_category J`, there exists a cocone over `F`. -/ lemma cocone_nonempty (F : J β₯€ C) : _root_.nonempty (cocone F) := begin classical, let O := (finset.univ.image F.obj), let H : finset (Ξ£' (X Y : C) (mX : X ∈ O) (mY : Y ∈ O), X ⟢ Y) := finset.univ.bind (Ξ» X : J, finset.univ.bind (Ξ» Y : J, finset.univ.image (Ξ» f : X ⟢ Y, ⟨F.obj X, F.obj Y, by simp, by simp, F.map f⟩))), obtain ⟨Z, f, w⟩ := sup_exists O H, refine ⟨⟨Z, ⟨λ X, f (by simp), _⟩⟩⟩, intros j j' g, dsimp, simp only [category.comp_id], apply w, simp only [finset.mem_univ, finset.mem_bind, exists_and_distrib_left, exists_prop_of_true, finset.mem_image], exact ⟨j, rfl, j', g, (by simp)⟩, end /-- An arbitrary choice of cocone over `F : J β₯€ C`, for `fin_category J` and `is_filtered C`. -/ noncomputable def cocone (F : J β₯€ C) : cocone F := (cocone_nonempty F).some end is_filtered end category_theory
fee96a184811f31a8e4e5e87abc7ac358e1c9be6
92b50235facfbc08dfe7f334827d47281471333b
/hott/types/equiv.hlean
18484931f355641edb875a769ab73428921f7529
[ "Apache-2.0" ]
permissive
htzh/lean
24f6ed7510ab637379ec31af406d12584d31792c
d70c79f4e30aafecdfc4a60b5d3512199200ab6e
refs/heads/master
1,607,677,731,270
1,437,089,952,000
1,437,089,952,000
37,078,816
0
0
null
1,433,780,956,000
1,433,780,955,000
null
UTF-8
Lean
false
false
6,351
hlean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn Ported from Coq HoTT Theorems about the types equiv and is_equiv -/ import .fiber .arrow arity .hprop_trunc open eq is_trunc sigma sigma.ops pi fiber function equiv namespace is_equiv variables {A B : Type} (f : A β†’ B) [H : is_equiv f] include H /- is_equiv f is a mere proposition -/ definition is_contr_fiber_of_is_equiv [instance] (b : B) : is_contr (fiber f b) := is_contr.mk (fiber.mk (f⁻¹ b) (right_inv f b)) (Ξ»z, fiber.rec_on z (Ξ»a p, fiber_eq ((ap f⁻¹ p)⁻¹ ⬝ left_inv f a) (calc right_inv f b = (ap (f ∘ f⁻¹) p)⁻¹ ⬝ ((ap (f ∘ f⁻¹) p) ⬝ right_inv f b) : by rewrite inv_con_cancel_left ... = (ap (f ∘ f⁻¹) p)⁻¹ ⬝ (right_inv f (f a) ⬝ p) : by rewrite ap_con_eq_con ... = (ap (f ∘ f⁻¹) p)⁻¹ ⬝ (ap f (left_inv f a) ⬝ p) : by rewrite adj ... = (ap (f ∘ f⁻¹) p)⁻¹ ⬝ ap f (left_inv f a) ⬝ p : by rewrite con.assoc ... = (ap f (ap f⁻¹ p))⁻¹ ⬝ ap f (left_inv f a) ⬝ p : by rewrite ap_compose ... = ap f (ap f⁻¹ p)⁻¹ ⬝ ap f (left_inv f a) ⬝ p : by rewrite ap_inv ... = ap f ((ap f⁻¹ p)⁻¹ ⬝ left_inv f a) ⬝ p : by rewrite ap_con))) definition is_contr_right_inverse : is_contr (Ξ£(g : B β†’ A), f ∘ g ~ id) := begin fapply is_trunc_equiv_closed, {apply sigma_equiv_sigma_id, intro g, apply eq_equiv_homotopy}, fapply is_trunc_equiv_closed, {apply fiber.sigma_char}, fapply is_contr_fiber_of_is_equiv, apply (to_is_equiv (arrow_equiv_arrow_right (equiv.mk f H))), end definition is_contr_right_coherence (u : Ξ£(g : B β†’ A), f ∘ g ~ id) : is_contr (Ξ£(Ξ· : u.1 ∘ f ~ id), Ξ (a : A), u.2 (f a) = ap f (Ξ· a)) := begin fapply is_trunc_equiv_closed, {apply equiv.symm, apply sigma_pi_equiv_pi_sigma}, fapply is_trunc_equiv_closed, {apply pi_equiv_pi_id, intro a, apply (fiber_eq_equiv (fiber.mk (u.1 (f a)) (u.2 (f a))) (fiber.mk a idp))}, end omit H protected definition sigma_char : (is_equiv f) ≃ (Ξ£(g : B β†’ A) (Ξ΅ : f ∘ g ~ id) (Ξ· : g ∘ f ~ id), Ξ (a : A), Ξ΅ (f a) = ap f (Ξ· a)) := equiv.MK (Ξ»H, ⟨inv f, right_inv f, left_inv f, adj f⟩) (Ξ»p, is_equiv.mk f p.1 p.2.1 p.2.2.1 p.2.2.2) (Ξ»p, begin cases p with p1 p2, cases p2 with p21 p22, cases p22 with p221 p222, apply idp end) (Ξ»H, is_equiv.rec_on H (Ξ»H1 H2 H3 H4, idp)) protected definition sigma_char' : (is_equiv f) ≃ (Ξ£(u : Ξ£(g : B β†’ A), f ∘ g ~ id), Ξ£(Ξ· : u.1 ∘ f ~ id), Ξ (a : A), u.2 (f a) = ap f (Ξ· a)) := calc (is_equiv f) ≃ (Ξ£(g : B β†’ A) (Ξ΅ : f ∘ g ~ id) (Ξ· : g ∘ f ~ id), Ξ (a : A), Ξ΅ (f a) = ap f (Ξ· a)) : is_equiv.sigma_char ... ≃ (Ξ£(u : Ξ£(g : B β†’ A), f ∘ g ~ id), Ξ£(Ξ· : u.1 ∘ f ~ id), Ξ (a : A), u.2 (f a) = ap f (Ξ· a)) : {sigma_assoc_equiv (Ξ»u, Ξ£(Ξ· : u.1 ∘ f ~ id), Ξ (a : A), u.2 (f a) = ap f (Ξ· a))} local attribute is_contr_right_inverse [instance] [priority 1600] local attribute is_contr_right_coherence [instance] [priority 1600] theorem is_hprop_is_equiv [instance] : is_hprop (is_equiv f) := is_hprop_of_imp_is_contr (Ξ»(H : is_equiv f), is_trunc_equiv_closed -2 (equiv.symm !is_equiv.sigma_char')) definition inv_eq_inv {A B : Type} {f f' : A β†’ B} {Hf : is_equiv f} {Hf' : is_equiv f'} (p : f = f') : f⁻¹ = f'⁻¹ := apd011 inv p !is_hprop.elim /- contractible fibers -/ definition is_contr_fun [reducible] (f : A β†’ B) := Ξ (b : B), is_contr (fiber f b) definition is_contr_fun_of_is_equiv [H : is_equiv f] : is_contr_fun f := is_contr_fiber_of_is_equiv f definition is_hprop_is_contr_fun (f : A β†’ B) : is_hprop (is_contr_fun f) := _ /- we cannot make the next theorem an instance, because it loops together with is_contr_fiber_of_is_equiv -/ definition is_equiv_of_is_contr_fun [H : is_contr_fun f] : is_equiv f := adjointify _ (Ξ»b, point (center (fiber f b))) (Ξ»b, point_eq (center (fiber f b))) (Ξ»a, ap point (center_eq (fiber.mk a idp))) definition is_equiv_of_imp_is_equiv (H : B β†’ is_equiv f) : is_equiv f := @is_equiv_of_is_contr_fun _ _ f (Ξ»b, @is_contr_fiber_of_is_equiv _ _ _ (H b) _) definition is_equiv_equiv_is_contr_fun : is_equiv f ≃ is_contr_fun f := equiv_of_is_hprop _ (Ξ»H, !is_equiv_of_is_contr_fun) end is_equiv namespace equiv open is_equiv variables {A B : Type} definition equiv_mk_eq {f f' : A β†’ B} [H : is_equiv f] [H' : is_equiv f'] (p : f = f') : equiv.mk f H = equiv.mk f' H' := apd011 equiv.mk p !is_hprop.elim definition equiv_eq {f f' : A ≃ B} (p : to_fun f = to_fun f') : f = f' := by (cases f; cases f'; apply (equiv_mk_eq p)) protected definition equiv.sigma_char (A B : Type) : (A ≃ B) ≃ Ξ£(f : A β†’ B), is_equiv f := begin fapply equiv.MK, {intro F, exact ⟨to_fun F, to_is_equiv F⟩}, {intro p, cases p with f H, exact (equiv.mk f H)}, {intro p, cases p, exact idp}, {intro F, cases F, exact idp}, end definition equiv_eq_char (f f' : A ≃ B) : (f = f') ≃ (to_fun f = to_fun f') := calc (f = f') ≃ (to_fun !equiv.sigma_char f = to_fun !equiv.sigma_char f') : eq_equiv_fn_eq (to_fun !equiv.sigma_char) ... ≃ ((to_fun !equiv.sigma_char f).1 = (to_fun !equiv.sigma_char f').1 ) : equiv_subtype ... ≃ (to_fun f = to_fun f') : equiv.refl definition is_equiv_ap_to_fun (f f' : A ≃ B) : is_equiv (ap to_fun : f = f' β†’ to_fun f = to_fun f') := begin fapply adjointify, {intro p, cases f with f H, cases f' with f' H', cases p, apply ap (mk f'), apply is_hprop.elim}, {intro p, cases f with f H, cases f' with f' H', cases p, apply @concat _ _ (ap to_fun (ap (equiv.mk f') (is_hprop.elim H H'))), {apply idp}, generalize is_hprop.elim H H', intro q, cases q, apply idp}, {intro p, cases p, cases f with f H, apply ap (ap (equiv.mk f)), apply is_hset.elim} end end equiv
e14b451ae214ba652685794d6748ae61ffb69a20
dcf093fda1f51c094394c50e182cfb9dec39635a
/keith.lean
d8aaf8fb2d7182f0de2d7c8c613070ab4453214e
[]
no_license
dselsam/cs103
7ac496d0293befca95d3045add91c5270a5d291f
31ab9784a6f65f226efb702a0da52f907c616a71
refs/heads/master
1,611,092,644,140
1,492,571,015,000
1,492,571,015,000
88,693,969
1
0
null
null
null
null
UTF-8
Lean
false
false
47,185
lean
-- Keith -- Chapter 2 import data.set algebra.binary algebra.group classical open nat -- I. Proofs about parity --[KS] An integer x is called even if there is some integer k such that x = 2k. definition even (x : nat) := βˆƒ k, x = 2 * k. --[KS] An integer x is called odd if there is some integer k such that x = 2k + 1. definition odd (x : nat) := βˆƒ k, x = 2 * k + 1. notation x `Β²` := (x * x) /- [KS] Theorem: If x is even, then x^2 is even. Proof: Let x be any even integer. Since x is even, there is some integer k such that x = 2k. This means that x^2 = (2k)^2 = 4k = 2(2k)^2. Since (2k)^2 is an integer, this means that there is some integer m (namely, (2k)^2) such that x^2 = 2m. Thus x^2 is even." -/ theorem x_even_x2_even : βˆ€ (x : nat), even x β†’ even (xΒ²) := -- Let x be an even integer take (x : nat), assume (even_x : even x), -- Since x is even, there is some integer k such that x = 2k. obtain (k : nat) (x_eq_2k : x = 2 * k), from even_x, -- This means that x^2 = (2k)^2 = 4k = 2(2k)^2 have x2_eq_2m : xΒ² = 2 * (2 * kΒ²), from calc xΒ² = (2 * k)Β² : x_eq_2k ... = 4 * kΒ² : sorry ... = 2 * (2 * kΒ²) : sorry, -- this means that there is some integer m (namely, (2k)^2) such that x^2 = 2m. have x2_div2 : βˆƒ m, xΒ² = 2 * m, from exists.intro (2 * kΒ²) x2_eq_2m, -- Thus x^2 is even. show even (xΒ²), from x2_div2 /- [KS] Theorem: If m is even and n is odd, then mn is even. Proof: Let m be any even number and n be any odd number. Then m = 2r for some integer r, and n = 2s + 1 for some integer s. This means that mn = (2r)(2s + 1) = 2(r(2s + 1)). This means that mn = 2k for some integer k (namely, r(2s + 1)), so mn is even. -/ theorem even_mul_odd_even : βˆ€ (m n : nat), even m β†’ odd n β†’ even (m * n) := -- Let m be any even number and n be any odd number. take (m n : nat), assume (even_m : even m) (odd_n : odd n), -- Then m = 2r for some integer r, obtain (r : nat) (m_eq_2r : m = 2 * r), from even_m, -- and n = 2s + 1 for some integer s. obtain (s : nat) (n_eq_2s_p1 : n = 2 * s + 1), from odd_n, -- This means that mn = (2r)(2s + 1) = 2(r(2s + 1)). have mn_eq_2t : m * n = 2 * (r * (2 * s + 1)), from calc m * n = (2 * r) * (2 * s + 1) : sorry ... = 2 * (r * (2 * s + 1)) : sorry, -- This means that mn = 2k for some integer k (namely, r(2s + 1)), so mn is even. show even (m * n), from exists.intro (r * (2 * s + 1)) mn_eq_2t -- [KS] Two numbers have the same parity if they are both odd or both even definition both {T : Type} (h : T β†’ Prop) (x y : T) := h x ∧ h y definition same_parity (x y : nat) := both even x y ∨ both odd x y definition same_parity_odd1 {x y : nat} : same_parity x y β†’ odd x β†’ odd y := sorry definition same_parity_odd2 {x y : nat} : same_parity x y β†’ odd y β†’ odd x := sorry /- [KS] Theorem: If m and n have the same parity, then m + n is even. Proof: Let m and n be any two integers with the same parity. Then there are two cases to consider: Case 1: m and n are even. Then m = 2r for some integer r and n = 2s for some integer s. Therefore, m + n = 2r + 2s = 2(r + s). Thus m + n = 2k for some integer k (namely, r + s), so m + n is even. Case 2: m and n are odd. Then m = 2r + 1 for some integer r and n = 2s + 1 for some integer s. Therefore, m + n = 2r + 1 + 2s + 1 = 2r + 2s + 2 = 2(r + s + 1). Thus m + n = 2k for some integer k (namely, r + s + 1), so m + n is even. -/ theorem same_parity_add_even : βˆ€ {x y : nat}, same_parity x y β†’ even (x + y) := -- Let m and n be any two integers with the same parity. take (x y : nat), assume (sp_xy : same_parity x y), -- Then there are two cases to consider: have two_cases : (even x ∧ even y) ∨ (odd x ∧ odd y), from sp_xy, or.elim two_cases (-- Case 1: m and n are even. take (both_even : even x ∧ even y), have even_x : even x, from and.elim_left both_even, have even_y : even y, from and.elim_right both_even, -- Then m = 2r for some integer r and n = 2s for some integer s. obtain (r : nat) (x_eq_2r : x = 2 * r), from even_x, obtain (s : nat) (y_eq_2s : y = 2 * s), from even_y, -- Therefore, m + n = 2r + 2s = 2(r + s). have xpy_eq_2t : x + y = 2 * (r + s), from calc x + y = 2 * r + 2 * s : sorry ... = 2 * (r + s) : sorry, -- Thus m + n = 2k for some integer k (namely, r + s), so m + n is even. show even (x + y), from exists.intro (r + s) xpy_eq_2t) (-- Case 2: m and n are odd. take (both_odd : odd x ∧ odd y), have odd_x : odd x, from and.elim_left both_odd, have odd_y : odd y, from and.elim_right both_odd, -- Then m = 2r + 1 for some integer r and n = 2s + 1 for some integer s. obtain (r : nat) (x_eq_2r_p1 : x = 2 * r + 1), from odd_x, obtain (s : nat) (y_eq_2s_p1 : y = 2 * s + 1), from odd_y, -- Therefore, m + n = 2r + 1 + 2s + 1 = 2r + 2s + 2 = 2(r + s + 1). have xpy_eq_2t : x + y = 2 * (r + s + 1), from calc x + y = 2 * r + 1 + 2 * s + 1 : sorry ... = 2 * r + 2 * s + 2 : sorry ... = 2 * (r + s + 1) : sorry, -- Thus m + n = 2k for some integer k (namely, r + s + 1), so m + n is even. show even (x + y), from exists.intro (r + s + 1) xpy_eq_2t) theorem even_or_odd : βˆ€ (n : nat), even n ∨ odd n := sorry theorem not_even_and_odd : βˆ€ {n : nat}, even n β†’ odd n β†’ false := sorry /- [KS] Theorem: If n is even and m is an integer, then n + m has the same parity as m. Proof: Consider any even integer n. Now, consider any integer m and the sum n + m. We consider two possibilities for m: Case 1: m is even. Then m and n have the same parity, so by our previous result (if m and n have the same parity, then m + n is even) we know that m + n is even. Therefore m and m + n have the same parity. Case 2: m is odd. Since n is even, n = 2r for some integer r, and since m is odd, m = 2s + 1 for some integer s. Then n + m = 2r + 2s + 1 = 2(r + s) + 1. This means that n + m = 2k + 1 for some k (namely, r + s), so n + m is odd. Therefore m and m + n have the same parity. -/ theorem even_add_sp : βˆ€ {n : nat}, even n β†’ βˆ€ (m : nat), same_parity (n + m) m := -- Consider any even integer n. take (n : nat), assume (even_n : even n), -- Now, consider any integer m [and the sum n + m]. We consider two possibilities for m: take (m : nat), or.elim (even_or_odd m) (-- Case 1: m is even. assume (even_m : even m), -- Then m and n have the same parity, have sp_nm : same_parity n m, from or.inl (and.intro even_n even_m), -- so by our previous result (if m and n have the same parity, then m + n is even) we know that m + n is even. have even_mpn : even (n + m), from same_parity_add_even sp_nm, -- Therefore m and m + n have the same parity. show same_parity (n + m) m, from or.inl (and.intro even_mpn even_m)) (-- Case 2: m is odd. assume (odd_m : odd m), -- Since n is even, n = 2r for some integer r, obtain (r : nat) (n_eq_2r : n = 2 * r), from even_n, -- and since m is odd, m = 2s + 1 for some integer s. obtain (s : nat) (m_eq_2s_p1 : m = 2 * s + 1), from odd_m, -- Then n + m = 2r + 2s + 1 = 2(r + s) + 1. have npm_eq_2t_p1 : n + m = 2 * (r + s) + 1, from calc n + m = 2 * r + 2 * s + 1 : sorry ... = 2 * (r + s) + 1 : sorry, -- This means that n + m = 2k + 1 for some k (namely, r + s), so n + m is odd. have odd_npm : odd (n + m), from exists.intro (r + s) npm_eq_2t_p1, -- Therefore m and m + n have the same parity. show same_parity (n + m) m, from or.inr (and.intro odd_npm odd_m)) -- Keith, chapter 2 -- proofs about parity open set binary variable {T : Type} /- [KS] Theorem: For any sets A and B, A ∩ B βŠ† A. Proof: Consider any sets A and B. We want to show that A ∩ B βŠ† A. By the definition of subset, this means that we need to show that for any x ∈ A ∩ B, x ∈ A. So consider any x ∈ A ∩ B. By the definition of intersection, x ∈ A ∩ B means that x ∈ A and x ∈ B. Therefore, if x ∈ A ∩ B, x ∈ A. Since our choice of x was arbitrary, A ∩ B βŠ† A. -/ theorem inter_sub : βˆ€ (A B : set T), A ∩ B βŠ† A := -- Consider any sets A and B. take (A B : set T), -- We want to show that A ∩ B βŠ† A. show A ∩ B βŠ† A, from -- By the definition of subset, this means that we need to show that for any x ∈ A ∩ B, x ∈ A. show βˆ€ x, x ∈ A ∩ B β†’ x ∈ A, from -- So consider any x ∈ A ∩ B. take (x : T), assume (x_in_inter : x ∈ A ∩ B), -- By the definition of intersection, x ∈ A ∩ B means that x ∈ A and x ∈ B. have x_in_A : x ∈ A, from and.elim_left x_in_inter, have x_in_B : x ∈ B, from and.elim_right x_in_inter, -- Therefore, [if x ∈ A ∩ B], x ∈ A. show x ∈ A, from x_in_A -- Since our choice of x was arbitrary, A ∩ B βŠ† A. /- [KS] Theorem: For any sets A and B, A βŠ† A βˆͺ B. Proof: Consider any sets A and B. We want to show that A βŠ† A βˆͺ B. To do this, we show that for any x ∈ A, that x ∈ A βˆͺ B as well. Note that by definition, x ∈ A βˆͺ B iff x ∈ A or x ∈ B. Consider any x ∈ A. It is therefore true that x ∈ A or x ∈ B, since we know x ∈ A. Consequently, x ∈ A βˆͺ B. Since our choice of x was arbitrary, this shows that any x ∈ A also satisfies x ∈ A βˆͺ B. Consequently, A βŠ† A βˆͺ B, as required. -/ theorem union_sup : βˆ€ (A B : set T), A βŠ† A βˆͺ B := -- Consider any sets A and B. take (A B : set T), -- We want to show that A βŠ† A βˆͺ B. show A βŠ† A βˆͺ B, from -- To do this, we show that for any x ∈ A, that x ∈ A βˆͺ B as well. show βˆ€ x, x ∈ A β†’ x ∈ A βˆͺ B, from -- [Note that by definition, x ∈ A βˆͺ B iff x ∈ A or x ∈ B.] -- Consider any x ∈ A. take (x : T), assume (x_in_A : x ∈ A), -- It is therefore true that x ∈ A or x ∈ B, since we know x ∈ A. have x_in_A_or_B : x ∈ A ∨ x ∈ B, from or.inl x_in_A, -- Consequently, x ∈ A βˆͺ B. show x ∈ A βˆͺ B, from x_in_A_or_B -- Since our choice of x was arbitrary, this shows that any x ∈ A also satisfies x ∈ A βˆͺ B. Consequently, A βŠ† A βˆͺ B, as required. definition set_minus [reducible] (A B : set T) := Ξ» x, x ∈ A ∧ Β¬ x ∈ B notation a - b := set_minus a b -- probably in the 'classical' library theorem prop_demorgan : βˆ€ {A B : Prop}, Β¬ (A ∧ B) β†’ Β¬ A ∨ Β¬ B := take (A B : Prop), take notAandB : Β¬ (A ∧ B), or.elim (em A) (take a : A, or.elim (em B) (take b : B, absurd (and.intro a b) notAandB) (take nb : Β¬ B, or.inr nb)) (take na : Β¬ A, or.inl na) /- [KS] Theorem: For any sets A, B, and C, we have C – (A ∩ B) βŠ† (C – A) βˆͺ (C – B) Proof: Consider any sets A, B, and C. We will show C – (A ∩ B) βŠ† (C – A) βˆͺ (C – B). By definition, this is true if for any x ∈ C – (A ∩ B), we also have x ∈ (C – A) βˆͺ (C – B). So consider any x ∈ C – (A ∩ B). By the definition of set difference, this means that x ∈ C and x βˆ‰ A ∩ B. Since x βˆ‰ A ∩ B, we know that it is not the case that both x ∈ A and x ∈ B. Consequently, it must be true that either x βˆ‰ A or x βˆ‰ B. We consider these two cases individually: Case 1: x βˆ‰ A. Since we know that x ∈ C and x βˆ‰ A, we know that x ∈ C – A. By our earlier result, we therefore have that x ∈ (C – A) βˆͺ (C – B). Case 2: x βˆ‰ B. Since we know that x ∈ C and x βˆ‰ B, we know that x ∈ C – B. By our earlier result, we therefore have that x ∈ (C – A) βˆͺ (C – B). In either case we have that x ∈ (C – A) βˆͺ (C – B). Since our choice of x was arbitrary, we have that C – (A ∩ B) βŠ† (C – A) βˆͺ (C – B) as required. -/ theorem sm_inter_ss_union_sm : βˆ€ (A B C : set T), C - (A ∩ B) βŠ† (C - A) βˆͺ (C - B) := -- Consider any sets A, B, and C. take (A B C : set T), -- We will show C – (A ∩ B) βŠ† (C – A) βˆͺ (C – B). show C - (A ∩ B) βŠ† (C - A) βˆͺ (C - B), from -- By definition, this is true if for any x ∈ C – (A ∩ B), we also have x ∈ (C – A) βˆͺ (C – B). show βˆ€ x, x ∈ C - (A ∩ B) β†’ x ∈ (C - A) βˆͺ (C - B), from -- So consider any x ∈ C – (A ∩ B). take (x : T), assume (x_in_lhs : x ∈ C - (A ∩ B)), -- By the definition of set difference, this means that x ∈ C and x βˆ‰ A ∩ B. have x_in_C : x ∈ C, from and.elim_left x_in_lhs, have x_nin_AcapB : Β¬ x ∈ A ∩ B, from and.elim_right x_in_lhs, -- Since x βˆ‰ A ∩ B, we know that it is not the case that both x ∈ A and x ∈ B. have x_nin_A_and_B : Β¬ (x ∈ A ∩ B), from and.elim_right x_in_lhs, -- Consequently, it must be true that either x βˆ‰ A or x βˆ‰ B. have two_cases : Β¬ x ∈ A ∨ Β¬ x ∈ B, from prop_demorgan x_nin_A_and_B, -- We consider these two cases individually: or.elim two_cases (-- Case 1: x βˆ‰ A. assume (x_nin_A : Β¬ x ∈ A), -- Since we know that x ∈ C and x βˆ‰ A, we know that x ∈ C – A. have x_in_CmA : x ∈ C - A, from and.intro x_in_C x_nin_A, -- [By our earlier result], we therefore have that x ∈ (C – A) βˆͺ (C – B). show x ∈ (C - A) βˆͺ (C - B), from or.inl x_in_CmA) (-- Case 2: x βˆ‰ B. assume (x_nin_B : Β¬ x ∈ B), -- Since we know that x ∈ C and x βˆ‰ B, we know that x ∈ C – B. have x_in_CmB : x ∈ C - B, from and.intro x_in_C x_nin_B, -- [By our earlier result], we therefore have that x ∈ (C – A) βˆͺ (C – B). [DHS: not without commutativity you don't] show x ∈ (C - A) βˆͺ (C - B), from or.inr (and.intro x_in_C x_nin_B)) --In either case we have that x ∈ (C – A) βˆͺ (C – B). Since our choice of x was arbitrary, we have that C – (A ∩ B) βŠ† (C – A) βˆͺ (C – B) as required. /- [KS] Lemma: For any sets A and B, A = B if and only if A βŠ† B and B βŠ† A. Proof: We prove both directions of implication. ( β‡’ ) First, we show that, for any sets A and B, if A = B, then A βŠ† B and B βŠ† A. If A = B, consider any x ∈ A. Since A = B, this means that x ∈ B. Since our choice of x was arbitrary, any x ∈ A satisfies x ∈ B, so A βŠ† B. Similarly, consider any x ∈ B, then since A = B, x ∈ A as well. Since our choice of x was arbitrary, any x ∈ B satisfies x ∈ A, so B βŠ† A. ( ⇐) Next, we prove that if A βŠ† B and B βŠ† A, then A = B. Consider any two sets A and B where A βŠ† B and B βŠ† A. We need to prove that A = B. Since A βŠ† B, for any x ∈ A, x ∈ B as well. Since B βŠ† A, for any x ∈ B, x ∈ A as well. Thus every element of A is in B and vice-versa, so the two sets have the same elements. -/ lemma eqv_ss : βˆ€ {A B : set T}, A ∼ B ↔ A βŠ† B ∧ B βŠ† A := -- We prove both directions of implication. take (A B : set T), iff.intro (-- ( β‡’ ) First, we show that, for any sets A and B, if A = B, then A βŠ† B and B βŠ† A. show A ∼ B β†’ A βŠ† B ∧ B βŠ† A, from -- If A = B, take A_eqv_B : A ∼ B, -- [DHS] states the goal later have A_ss_B : A βŠ† B, from -- consider any x ∈ A. assume (x : T) (x_in_A : x ∈ A), -- Since A = B, this means that x ∈ B. have x_in_B : x ∈ B, from iff.elim_left (A_eqv_B x) x_in_A, -- [Since our choice of x was arbitrary, any x ∈ A satisfies x ∈ B, so A βŠ† B.] show x ∈ B, from x_in_B, -- [DHS] states the goal later, have B_ss_A : B βŠ† A, from -- Similarly, consider any x ∈ B, assume (x : T) (x_in_B : x ∈ B), -- then since A = B, x ∈ A as well. have x_in_A : x ∈ A, from iff.elim_right (A_eqv_B x) x_in_B, -- [Since our choice of x was arbitrary, any x ∈ B satisfies x ∈ A, so B βŠ† A.] show x ∈ A, from x_in_A, and.intro A_ss_B B_ss_A) (-- ( ⇐) Next, we prove that if A βŠ† B and B βŠ† A, then A = B. show A βŠ† B ∧ B βŠ† A β†’ A ∼ B, from -- Consider any two sets A and B where A βŠ† B and B βŠ† A. take H : A βŠ† B ∧ B βŠ† A, have A_ss_B : A βŠ† B, from and.elim_left H, have B_ss_A : B βŠ† A, from and.elim_right H, -- We need to prove that A = B. show A ∼ B, from take x, -- [DHS] states strategy afterwards iff.intro (-- Since A βŠ† B, for any x ∈ A, x ∈ B as well. assume x_in_A : x ∈ A, show x ∈ B, from A_ss_B x x_in_A) (-- Since B βŠ† A, for any x ∈ B, x ∈ A as well. assume x_in_B : x ∈ B, show x ∈ A, from B_ss_A x x_in_B) -- Thus every element of A is in B and vice-versa, so the two sets have the same elements. ) definition sym_diff [reducible] (A B : set T) : set T := Ξ» x, (x ∈ A ∧ Β¬ x ∈ B) ∨ (x ∈ B ∧ Β¬ x ∈ A) infix `Ξ”`:101 := sym_diff -- (taken implicitly as a lemma in Keith's notes) lemma sym_diff_nocases : βˆ€ {A B : set T} (x : T), (x ∈ A ∨ x ∈ B) β†’ (Β¬ x ∈ A ∨ Β¬ x ∈ B) β†’ x ∈ A Ξ” B := take (A B : set T), take x : T, assume x_in_A_or_B : x ∈ A ∨ x ∈ B, assume x_nin_A_or_B : Β¬ x ∈ A ∨ Β¬ x ∈ B, or.elim x_in_A_or_B (take x_in_A : x ∈ A, or.elim x_nin_A_or_B (take x_nin_A : Β¬ x ∈ A, absurd x_in_A x_nin_A) (take x_nin_B : Β¬ x ∈ B, or.inl (and.intro x_in_A x_nin_B))) (take x_in_B : x ∈ B, or.elim x_nin_A_or_B (take x_nin_A : Β¬ x ∈ A, or.inr (and.intro x_in_B x_nin_A)) (take x_nin_B : Β¬ x ∈ B, absurd x_in_B x_nin_B)) /- [KS] Lemma 1: (A βˆͺ B) – (A ∩ B) βŠ† A Ξ” B. Proof of Lemma 1: We will show that for any x ∈ (A βˆͺ B) – (A ∩ B), x ∈ A Ξ” B. So consider any x ∈ (A βˆͺ B) – (A ∩ B). This means that x ∈ A βˆͺ B, but x βˆ‰ A ∩ B. Since x ∈ A βˆͺ B, we know that x ∈ A or x ∈ B. Since x βˆ‰ A ∩ B, we know that x is not contained in both A and B. We thus have that x is in at least one of A and B, but not both. Consequently, x ∈ A Ξ” B. Since our choice of x was arbitrary, we therefore have that (A βˆͺ B) – (A ∩ B) βŠ† A Ξ” B. -/ -- [DHS]#DESIGN Keith uses an unstated and unproved lemma, arguably lemma sym_diff_alt_1 : βˆ€ {A B : set T}, (A βˆͺ B) - (A ∩ B) βŠ† A Ξ” B := take (A B : set T), -- We will show that for any x ∈ (A βˆͺ B) – (A ∩ B), x ∈ A Ξ” B. show βˆ€ x, x ∈ (A βˆͺ B) - (A ∩ B) β†’ x ∈ A Ξ” B, from -- So consider any x ∈ (A βˆͺ B) – (A ∩ B). take (x : T), assume (x_in_lhs : x ∈ (A βˆͺ B) - (A ∩ B)), -- This means that x ∈ A βˆͺ B, have x_in_A_cup_B : x ∈ A βˆͺ B, from and.elim_left x_in_lhs, -- but x βˆ‰ A ∩ B. have x_nin_A_cap_B : Β¬ x ∈ A ∩ B, from and.elim_right x_in_lhs, -- Since x ∈ A βˆͺ B, we know that x ∈ A or x ∈ B. have x_in_A_or_B : x ∈ A ∨ x ∈ B, from x_in_A_cup_B, -- Since x βˆ‰ A ∩ B, we know that x is not contained in both A and B. We thus have that x is in at least one of A and B, but not both. have x_nin_A_or_x_nin_B : Β¬ x ∈ A ∨ Β¬ x ∈ B, from prop_demorgan x_nin_A_cap_B, -- Consequently, x ∈ A Ξ” B. show x ∈ A Ξ” B, from sym_diff_nocases x x_in_A_or_B x_nin_A_or_x_nin_B -- Since our choice of x was arbitrary, we therefore have that (A βˆͺ B) – (A ∩ B) βŠ† A Ξ” B. /- [KS] Lemma 2: A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B) Proof of Lemma 2: We will show that for any x ∈ A Ξ” B, x ∈ (A βˆͺ B) – (A ∩ B). Consider any x ∈ A Ξ” B. Then either x ∈ A and x βˆ‰ B, or x ∈ B and x βˆ‰ A. We consider these cases separately: Case 1: x ∈ A and x βˆ‰ B. Since x ∈ A, x ∈ A βˆͺ B. Since x βˆ‰ B, x βˆ‰ A ∩ B. Consequently, x ∈ (A βˆͺ B) – (A ∩ B). Case 2: x ∈ B and x βˆ‰ A. Since x ∈ B, x ∈ A βˆͺ B. Since x βˆ‰ A, x βˆ‰ A ∩ B. Consequently, x ∈ (A βˆͺ B) – (A ∩ B). In either case, x ∈ (A βˆͺ B) – (A ∩ B). Since our choice of x was arbitrary, we have that A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B). -/ lemma sym_diff_alt_2 : βˆ€ {A B : set T}, A Ξ” B βŠ† (A βˆͺ B) - (A ∩ B) := take (A B : set T), -- We will show that for any x ∈ A Ξ” B, x ∈ (A βˆͺ B) – (A ∩ B). show βˆ€ x, x ∈ A Ξ” B β†’ x ∈ (A βˆͺ B) - (A ∩ B), from -- Consider any x ∈ A Ξ” B. take (x : T), assume (x_in_sdAB : x ∈ A Ξ” B), -- Then either x ∈ A and x βˆ‰ B, or x ∈ B and x βˆ‰ A. We consider these cases separately: or.elim x_in_sdAB (-- Case 1: x ∈ A and x βˆ‰ B. assume H : x ∈ A ∧ Β¬ x ∈ B, have x_in_A : x ∈ A, from and.elim_left H, have x_nin_B : Β¬ x ∈ B, from and.elim_right H, -- Since x ∈ A, x ∈ A βˆͺ B. have x_in_AcupB : x ∈ A βˆͺ B, from or.inl x_in_A, -- Since x βˆ‰ B, x βˆ‰ A ∩ B. have x_nin_AcapB : Β¬ x ∈ A ∩ B, from take x_in_AcapB, absurd (and.elim_right x_in_AcapB) x_nin_B, -- Consequently, x ∈ (A βˆͺ B) – (A ∩ B). show x ∈ (A βˆͺ B) - (A ∩ B), from and.intro x_in_AcupB x_nin_AcapB) (-- Case 2: x ∈ B and x βˆ‰ A. assume H : x ∈ B ∧ Β¬ x ∈ A, have x_in_B : x ∈ B, from and.elim_left H, have x_nin_A : Β¬ x ∈ A, from and.elim_right H, -- Since x ∈ B, x ∈ A βˆͺ B. have x_in_AcupB : x ∈ A βˆͺ B, from or.inr x_in_B, -- Since x βˆ‰ A, x βˆ‰ A ∩ B. have x_nin_AcapB : Β¬ x ∈ A ∩ B, from take x_in_AcapB, absurd (and.elim_left x_in_AcapB) x_nin_A, -- Consequently, x ∈ (A βˆͺ B) – (A ∩ B). show x ∈ (A βˆͺ B) - (A ∩ B), from and.intro x_in_AcupB x_nin_AcapB) -- In either case, x ∈ (A βˆͺ B) – (A ∩ B). Since our choice of x was arbitrary, we have that A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B). /- Proof of Lemma 2: We will show that for any x ∈ A Ξ” B, x ∈ (A βˆͺ B) – (A ∩ B). Consider any x ∈ A Ξ” B. Then either x ∈ A and x βˆ‰ B, or x ∈ B and x βˆ‰ A. Assume without loss of generality that x ∈ A and x βˆ‰ B. Since x ∈ A, x ∈ A βˆͺ B. Since x βˆ‰ B, x βˆ‰ A ∩ B, so x ∈ (A βˆͺ B) – (A ∩ B). Since our choice of x was arbitrary, we have that A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B). -/ -- [DHS]#DESIGN w.l.o.g. actually quite subtle, since it depends on 2(!) commutativity lemmas theorem union_com : commutative (@union T) := sorry theorem inter_com : commutative (@inter T) := sorry -- Here is the abstract lemma, that Keith does not show explicitly lemma sym_diff_alt_2a : βˆ€ {A B : set T} {x : T}, x ∈ A - B β†’ x ∈ (A βˆͺ B) - (A ∩ B) := take (A B : set T) (x : T), -- Assume [without loss of generality] that x ∈ A and x βˆ‰ B. assume (x_in_AmB : x ∈ A - B), have x_in_A : x ∈ A, from and.elim_left x_in_AmB, have x_nin_B : Β¬ x ∈ B, from and.elim_right x_in_AmB, -- Since x ∈ A, x ∈ A βˆͺ B. have x_in_AcupB : x ∈ A βˆͺ B, from or.inl x_in_A, -- Since x βˆ‰ B, x βˆ‰ A ∩ B, have x_nin_AcapB : Β¬ x ∈ A ∩ B, from take x_in_AcapB, absurd (and.elim_right x_in_AcapB) x_nin_B, -- so x ∈ (A βˆͺ B) – (A ∩ B) show x ∈ (A βˆͺ B) - (A ∩ B), from and.intro x_in_AcupB x_nin_AcapB open eq.ops definition wlog (xy : A ∨ B) (b1 : A β†’ C) : C := or.elim xy b1 b1 lemma sym_diff_alt_2b : βˆ€ {A B : set T}, A Ξ” B βŠ† (A βˆͺ B) - (A ∩ B) := take (A B : set T), -- We will show that for any x ∈ A Ξ” B, x ∈ (A βˆͺ B) – (A ∩ B). show βˆ€ x, x ∈ A Ξ” B β†’ x ∈ (A βˆͺ B) - (A ∩ B), from -- Consider any x ∈ A Ξ” B. take x, assume (x_in_sdAB : x ∈ A Ξ” B), -- Then either x ∈ A and x βˆ‰ B, or x ∈ B and x βˆ‰ A. wlog x_in_sdAB (assume x_in_AmB : x ∈ A - B, sym_diff_alt_2a x_in_AmB) /- or.elim x_in_sdAB (assume x_in_AmB : x ∈ A - B, sym_diff_alt_2a x_in_AmB) (assume x_in_BmA : x ∈ B - A, (inter_com B A) β–Έ (union_com B A) β–Έ sym_diff_alt_2a x_in_BmA) -/ /- [KS] Theorem: For any sets A and B, (A βˆͺ B) – (A ∩ B) = A Ξ” B. Proof of Theorem: By Lemma 1, (A βˆͺ B) – (A ∩ B) βŠ† A Ξ” B. By Lemma 2, A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B). Since each set is a subset of the other, by our earlier lemma we have that (A βˆͺ B) – (A ∩ B) = A Ξ” B -/ theorem sym_diff_alt : βˆ€ (A B : set T), (A βˆͺ B) - (A ∩ B) ∼ A Ξ” B := take (A B : set T), -- By Lemma 1, (A βˆͺ B) – (A ∩ B) βŠ† A Ξ” B. have l_to_r : (A βˆͺ B) - (A ∩ B) βŠ† A Ξ” B, from sym_diff_alt_1, -- By Lemma 2, A Ξ” B βŠ† (A βˆͺ B) – (A ∩ B). have r_to_l : A Ξ” B βŠ† (A βˆͺ B) - (A ∩ B), from sym_diff_alt_2, -- Since each set is a subset of the other, by our earlier lemma we have that (A βˆͺ B) – (A ∩ B) = A Ξ” B show (A βˆͺ B) - (A ∩ B) ∼ A Ξ” B, from iff.elim_right eqv_ss (and.intro sym_diff_alt_1 sym_diff_alt_2) -- [DHS] -- #DESGN -- Issue #1: naming hypotheses -- Issue #2: 'obvious' lemmas -- Issue #3: w.l.o.g. /- [KS] Theorem: If m and n have opposite parity, m + n is odd. Proof: Without loss of generality, assume that m is odd and n is even. Since m is odd, there exists an integer r such that m = 2r + 1. Since n is even, there exists an integer s such that n = 2s. Then m + n = 2r + 1 + 2s = 2(r + s) + 1. Consequently, m + n is odd. -/ definition opposite_parity (x y : nat) := (odd x ∧ even y) ∨ (odd y ∧ even x) lemma add_comm : βˆ€ (x y : nat), x + y = y + x := sorry set_option formatter.hide_full_terms false /- [DHS]#DESIGN how is [suffices_to_show]? I think it is pretty reasonable. -/ definition suffices_to_show {Goal : Prop} (P : Prop) (H : P β†’ Goal) (p : P) : Goal := H p lemma opposite_parity_sum_odd : βˆ€ (m n : nat), opposite_parity m n β†’ odd (m + n) := -- Without loss of generality, assume that m is odd and n is even. suffices_to_show (βˆ€ (m n : nat), odd m ∧ even n β†’ odd (m + n)) (assume (lem : βˆ€ (m n : nat), odd m ∧ even n β†’ odd (m + n)) (m n : nat) (opp_mn : opposite_parity m n), or.elim opp_mn (assume H : odd m ∧ even n, lem m n H) (assume H : odd n ∧ even m, (add_comm n m) β–Έ (lem n m H))) (take (m n : nat), assume H : odd m ∧ even n, -- Since m is odd, there exists an integer r such that m = 2r + 1. obtain r (m_eq_2r_p1 : m = 2 * r + 1), from and.elim_left H, -- Since n is even, there exists an integer s such that n = 2s. obtain s (n_eq_2s : n = 2 * s), from and.elim_right H, -- Then m + n = 2r + 1 + 2s = 2(r + s) + 1. have mpn_eq_2t_p1 : m + n = 2 * (r + s) + 1, from calc m + n = 2 * r + 1 + 2 * s : by rewrite [m_eq_2r_p1, n_eq_2s] ...= 2 * (r + s) + 1 : sorry, -- Consequently, m + n is odd. show odd (m + n), from exists.intro (r + s) mpn_eq_2t_p1) -- Proofs with vacuous truths /- [KS] Theorem: For any sets A and B, if A βŠ† B, then A – B = Ø. Lemma 1: For any sets A and B, if A βŠ† B, then Ø βŠ† A – B. Lemma 2: For any sets A and B, if A βŠ† B, then A – B βŠ† Ø. Proof of Lemma 1: We need to show that every element x ∈ Ø also satisfies x ∈ A – B. But this is vacuously true, as there are no x satisfying x ∈ Ø. Proof of Lemma 2: We need to show that any x ∈ A – B also satisfies x ∈ Ø. Consider any x ∈ A – B. This means that x ∈ A and x βˆ‰ B. Since A βŠ† B and since x ∈ A, we know that x ∈ B. But this means simultaneously that x ∈ B and x βˆ‰ B. Consequently, there are no x ∈ A – B, so the claim that any x ∈ A – B also satisfies x ∈ Ø is vacuously true. Proof of Theorem: Consider any sets A and B such that A βŠ† B. By Lemma 1, we have that Ø βŠ† A – B. By Lemma 2, we have that A – B βŠ† Ø. Thus by our earlier lemma, A – B = Ø as required. -/ lemma vacuous_set1a : βˆ€ {A B : set T}, A βŠ† B β†’ βˆ… βŠ† A - B := take (A B : set T) (A_ss_B : A βŠ† B), -- We need to show that every element x ∈ Ø also satisfies x ∈ A – B. show βˆ€ x, x ∈ βˆ… β†’ x ∈ A - B, from -- But this is vacuously true, as there are no x satisfying x ∈ Ø. assume x x_in_empty, false.rec _ x_in_empty lemma vacuous_set1b : βˆ€ {A B : set T}, A βŠ† B β†’ A - B βŠ† βˆ… := take (A B : set T) (A_ss_B : A βŠ† B), -- We need to show that any x ∈ A – B also satisfies x ∈ Ø. show βˆ€ x, x ∈ A - B β†’ x ∈ βˆ…, from -- Consider any x ∈ A – B. take x (x_in_AmB : x ∈ A - B), -- This means that x ∈ A and x βˆ‰ B. have x_in_A : x ∈ A, from and.elim_left x_in_AmB, have x_nin_B : Β¬ x ∈ B, from and.elim_right x_in_AmB, -- Since A βŠ† B and since x ∈ A, we know that x ∈ B. have x_in_B : x ∈ B, from A_ss_B x x_in_A, -- But this means simultaneously that x ∈ B and x βˆ‰ B. -- Consequently, there are no x ∈ A – B, so the claim that any x ∈ A – B also satisfies x ∈ Ø is vacuously true. absurd x_in_B x_nin_B theorem vacuous_set1 : βˆ€ {A B : set T}, A βŠ† B β†’ A - B ∼ βˆ… := -- Consider any sets A and B such that A βŠ† B. take (A B : set T) (A_ss_B : A βŠ† B), -- By Lemma 1, we have that Ø βŠ† A – B. have empty_ss_lhs : βˆ… βŠ† A - B, from vacuous_set1a A_ss_B, -- By Lemma 2, we have that A – B βŠ† Ø. have lhs_ss_empty : A - B βŠ† βˆ…, from vacuous_set1b A_ss_B, -- Thus by our earlier lemma, A – B = Ø as required. show A - B ∼ βˆ…, from iff.elim_right eqv_ss (and.intro lhs_ss_empty empty_ss_lhs) -- 2.3 Indirect Proofs /- [KS] Theorem: If nΒ² is even, then n is even. Proof: By contradiction; assume that nΒ² is even but that n is odd. Since n is odd, n = 2k + 1 for some integer k. Therefore nΒ² = (2k + 1)Β² = 4kΒ² + 4k + 1 = 2(2kΒ² + 2k) + 1. This means that nΒ² is odd, contradicting the fact that we know that nΒ² is even. We have reached a contradiction, so our assumption must have been wrong. Therefore, if nΒ² is even, n must be even. -/ theorem n2_even_n_even : βˆ€ (n:nat), even (nΒ²) β†’ even n := -- By contradiction; assume that nΒ² is even but that n is odd. assume n (even_n2 : even (nΒ²)), by_contradiction (take neven_n : Β¬ even n, have odd_n : odd n, from or.elim (even_or_odd n) (take even_n, absurd even_n neven_n) (take odd_n, odd_n), -- Since n is odd, n = 2k + 1 for some integer k. obtain k (n_eq_2k_p1 : n = 2 * k + 1), from odd_n, -- Therefore nΒ² = (2k + 1)Β² = 4kΒ² + 4k + 1 = 2(2kΒ² + 2k) + 1. have n2_eq_2l_p1 : nΒ² = 2 * (2 * kΒ² + 2 * k) + 1, from calc nΒ² = (2 * k + 1)Β² : n_eq_2k_p1 ... = 4*kΒ² + 4*k + 1 : sorry ... = 2 * (2 * kΒ² + 2 * k) + 1 : sorry, -- This means that nΒ² is odd, contradicting the fact that we know that nΒ² is even. have odd_n2 : odd (nΒ²), from exists.intro _ n2_eq_2l_p1, not_even_and_odd even_n2 odd_n2) -- We have reached a contradiction, so our assumption must have been wrong. Therefore, if nΒ² is even, n must be even. /- [KS] You have 2,718 balls and five bins. Prove that you cannot distribute all of the balls into the bins such that each bin contains an odd number of balls. Proof: By contradiction; assume that there is a way to distribute all 2,718 balls into five bins such that each bin has an odd number of balls in it. Consider any such way of distributing the balls, and let the number of balls in the five bins be a, b, c, d, and e. Write the sum a + b + c + d + e as ((a + b) + (c + d)) + e. Since all five numbers have the same parity, both (a + b) and (c + d) are even. Since (a + b) and (c + d) have the same parity, ((a + b) + (c + d)) must be even. Then, since ((a + b) + (c + d)) is even, the sum ((a + b) + (c + d)) + e must have the same parity as e. Since e is odd, this means that sum of the number of balls in the five bins is odd, contradicting the fact that there are an even number of balls distributed across the bins (2,718). We have reached a contradiction, so our initial assumption must have been wrong and there is no way to distribute 2,718 balls into five bins such that each bin has an odd number of balls. -/ /- [DHS]#DESIGN interesting challenge, since we really start with 5 of something, and only later provide variables for each individual -/ open list definition list.sum (f : T β†’ nat) (l : list T) : nat := list.foldr (Ξ» x acc, f x + acc ) 0 l lemma balls_in_bins_verbose : βˆ€ (a b c d e : nat), odd a β†’ odd b β†’ odd c β†’ odd d β†’ odd e β†’ Β¬ (a + b + c + d + e = 2718) := -- By contradiction; assume that there is a way to distribute all 2,718 balls into five bins such that -- each bin has an odd number of balls in it. -- Consider any such way of distributing the balls, and let the number of balls in the five bins be a, b, c, d, and e. take a b c d e, assume odd_a odd_b odd_c odd_d odd_e, assume sum_2718 : a + b + c + d + e = 2718, have div2_2718 : 2718 = 2 * 1359, from rfl, have even_sum : even 2718, from exists.intro _ div2_2718, -- Write the sum a + b + c + d + e as ((a + b) + (c + d)) + e. have sum_parens : a + b + c + d + e = ((a + b) + (c + d)) + e, from sorry, -- Since all five numbers have the same parity, both (a + b) and (c + d) are even. have even_ab : even (a + b), from same_parity_add_even (or.inr (and.intro odd_a odd_b)), have even_cd : even (c + d), from same_parity_add_even (or.inr (and.intro odd_c odd_d)), -- Since (a + b) and (c + d) have the same parity, ((a + b) + (c + d)) must be even. have even_abcd : even ((a+b)+(c+d)), from same_parity_add_even (or.inl (and.intro even_ab even_cd)), -- Then, since ((a + b) + (c + d)) is even, the sum ((a + b) + (c + d)) + e must have the same parity as e. have sp_e : same_parity (((a + b) + (c + d)) + e) e, from even_add_sp even_abcd e, -- Since e is odd, this means that sum of the number of balls in the five bins is odd, have odd_sum : odd (((a + b) + (c + d)) + e), from same_parity_odd2 sp_e odd_e, -- contradicting the fact that there are an even number of balls distributed across the bins (2,718). not_even_and_odd even_sum (sum_2718 β–Έ sum_parens⁻¹ β–Έ odd_sum) -- We have reached a contradiction, so our initial assumption must have been wrong and there is no way to distribute 2,718 balls into five bins such that each bin has an odd number of balls. -- Proof by contrapositive /- [KS] Theorem: If not Q β†’ not P, then P β†’ Q. Proof: By contradiction; assume that not Q β†’ not P, but that P β†’ Q is false. Since P β†’ Q is false, we know that P is true but Q is false. Since Q is false and not Q β†’ not P, we have that P must be false. But this contradicts the fact that we know that P is true. We have reached a contradiction, so our initial assumption must have been false. Thus if not Q β†’ not P, then P β†’ Q. -/ definition neg_imp : βˆ€ {P Q : Prop}, Β¬ (P β†’ Q) β†’ (P ∧ Β¬ Q) := take P Q, assume n_P_to_Q, or.elim (em Q) (take q : Q, absurd (Ξ» p:P, q) n_P_to_Q) (take nq : Β¬ Q, (or.elim (em P) (take p : P, and.intro p nq) (take np : Β¬ P, absurd (Ξ» p, absurd p np) n_P_to_Q))) theorem by_contrapositive : βˆ€ {P Q : Prop}, (Β¬ Q β†’ Β¬ P) β†’ (P β†’ Q) := take P Q, -- By contradiction; assume that not Q β†’ not P, but that P β†’ Q is false. assume nQ_to_nP : Β¬ Q β†’ Β¬ P, by_contradiction (assume n_P_to_Q : Β¬ (P β†’ Q), -- Since P β†’ Q is false, we know that P is true but Q is false. have p : P, from and.elim_left (neg_imp n_P_to_Q), have nq : Β¬ Q, from and.elim_right (neg_imp n_P_to_Q), -- Since Q is false and not Q β†’ not P, we have that P must be false. have np : Β¬ P, from nQ_to_nP nq, -- But this contradicts the fact that we know that P is true. absurd p np) -- We have reached a contradiction, so our initial assumption must have been false. Thus if not Q β†’ not P, then P β†’ Q. /- [KS] Theorem: If nΒ² is even, then n is even. Proof: By contrapositive; we prove that if n is odd, then nΒ² is odd. Let n be any odd integer. Since n is odd, n = 2k + 1 for some integer k. Therefore, nΒ² = (2k + 1)Β² = 4kΒ² + 4k + 1 = 2(2kΒ² + 2k) + 1. Thus nΒ² is odd. -/ lemma not_even_then_odd : βˆ€ {n : nat}, Β¬ even n β†’ odd n := take n not_even_n, or.elim (even_or_odd n) (take even_n, absurd even_n not_even_n) (take odd_n, odd_n) lemma not_odd_then_even : βˆ€ {n : nat}, Β¬ odd n β†’ even n := take n not_odd_n, or.elim (even_or_odd n) (take even_n, even_n) (take odd_n, absurd odd_n not_odd_n) lemma double_negation : βˆ€ {P : Prop}, Β¬ Β¬ P = P := sorry lemma even_then_not_odd : βˆ€ {n : nat}, even n β†’ Β¬ odd n := sorry lemma odd_then_not_even : βˆ€ {n : nat}, odd n β†’ Β¬ (even n) := sorry theorem n2_even_n_even_by_contrapositive : βˆ€ (n:nat), even (nΒ²) β†’ even n := take n, by_contrapositive (assume not_even_n : Β¬ (even n), show Β¬ even (nΒ²), from have odd_n : odd n, from not_even_then_odd not_even_n, obtain k n_eq_2k_p1, from odd_n, have n2_eq_2l_p1 : nΒ² = 2 * (2 * kΒ² + 2 * k) + 1, from calc nΒ² = (2 * k + 1)Β² : n_eq_2k_p1 ... = 4 * kΒ² + 4 * k + 1 : sorry ... = 2 * (2 * kΒ² + 2 * k) + 1 : sorry, odd_then_not_even (exists.intro _ n2_eq_2l_p1)) -- Chapter 3. Induction /- [KS] Theorem: The sum of the first n positive natural numbers is n(n + 1) / 2. Proof: By induction. Let P(n) be β€œthe sum of the first n positive natural numbers is n(n + 1) / 2.” We prove that P(n) is true for all n ∈ β„•, from which the result immediately follows. For our base case, we prove P(0), that the sum of the first 0 positive natural numbers is 0(0 + 1) / 2. The sum of zero numbers is 0, and 0 = 0(0 + 1)/2. Consequently, P(0) holds. For the inductive step, assume that for some n ∈ β„• that P(n) is true and the sum of the first n positive natural numbers is n(n + 1) / 2. We will prove that P(n + 1) is true; that is, the sum of the first n + 1 positive natural numbers is (n + 1)(n + 2) / 2. Consider the sum of the first n + 1 positive natural numbers. This is the sum of the first n positive natural numbers, plus n + 1. By our inductive hypothesis, the sum of the first n positive natural numbers is n(n + 1) / 2. Thus the sum of the first n + 1 positive natural numbers is n(n+ 1)/2 + n+ 1 = n(n+ 1)/2 + 2(n+ 1)/2 = (n(n+ 1)+ 2 (n+ 1))/2 = (n+2)(n+ 1)/2 Thus P(n + 1) is true, completing the induction. -/ definition sum_of_pos : nat β†’ (nat β†’ nat) β†’ nat | zero f := 0 | (succ n) f := f (n+1) + sum_of_pos n f theorem sum_of_pos_closed_form : βˆ€ (n : nat), 2 * sum_of_pos n (Ξ»n,n) = n * (n + 1) := take n, -- By induction. Let P(n) be β€œthe sum of the first n positive natural numbers is -- n(n + 1) / 2.” We prove that P(n) is true for all n ∈ β„•, from which the result immediately follows. nat.induction_on n (-- For our base case, we prove P(0), that the sum of the first 0 positive natural numbers is 0(0 + 1) / 2. -- The sum of zero numbers is 0, and 0 = 0(0 + 1)/2. Consequently, P(0) holds. show 2 * sum_of_pos 0 (Ξ»n,n) = 0 * (0 + 1), from sorry) (-- For the inductive step, assume that for some n ∈ β„• that P(n) is true and the sum of the first n positive natural numbers is n(n + 1) / 2. take n, assume IHn : 2 * sum_of_pos n (Ξ»n,n) = n * (n + 1), -- We will prove that P(n + 1) is true; that is, the sum of the first n + 1 positive natural numbers is (n + 1)(n + 2) / 2. show 2 * sum_of_pos (n + 1) (Ξ»n,n) = (n + 1) * (n + 2), from -- Consider the sum of the first n + 1 positive natural numbers. This is the sum of the first n positive natural numbers, plus n + 1. calc 2 * sum_of_pos (n + 1) (Ξ»n,n) = 2 * (n+1 + sum_of_pos n (Ξ»n,n)) : rfl ... = 2 * (n+1) + 2 * sum_of_pos n (Ξ»n,n) : sorry -- By our inductive hypothesis, the sum of the first n positive natural numbers is n(n + 1) / 2. ... = 2 * (n+1) + n * (n + 1) : IHn -- [DHS] (Keith's calculations are more cumbersome due to the division) ... = n*n + 3*n + 2 : sorry ... = (n+1)*(n+2) : sorry -- Thus P(n + 1) is true, completing the induction. ) /- [KS] Theorem: For any natural number n, βˆ‘_{i=0}^{n-1} (2i + 1) = nΒ² Proof: By induction. Let P(n) be defined as P(n)β‰‘βˆ‘ i=0 nβˆ’1 (2i+ 1)=n 2 We prove that P(n) is true for all n ∈ β„• by induction on n. As our base case, we prove P(0), that βˆ‘_{i=0}^{-1} (2 i+ 1)=0Β². The left-hand side of this equality is the empty sum, which is 0. The right-hand side of the equality is also 0, so P(0) holds. For the inductive step, assume that for some natural number n, P(n) holds, meaning that βˆ‘_{i=0}^{nβˆ’1} (2 i+ 1) = nΒ². We will prove P(n + 1), meaning that βˆ‘_{i=0}^{n} (2 i+ 1) = (n+1)Β². To see this, note that βˆ‘_{i=0}^{n} (2i+ 1)=(n+ 1)Β² = βˆ‘_{i=0}^{nβˆ’1} (2i+ 1)+ 2 n+ 1 = nΒ² + 2n+ 1 =(n+ 1)Β² Thus P(n + 1) holds, completing the induction. -/ theorem sum_odd_nats : βˆ€ (n:nat), sum_of_pos n (Ξ» n, 2 * n + 1) = (n+1)Β² := take n, nat.induction_on n (show sum_of_pos 0 (Ξ» n, 2 * n + 1) = (0+1)Β², from sorry) (assume n (IHn : sum_of_pos n (Ξ» n, 2*n+1) = (n+1)Β²), show sum_of_pos (n+1) (Ξ» n,2*n+1) = (n+2)Β², from calc sum_of_pos (n+1) (Ξ» n,2*n+1) = 2 * (n+1) + 1 + sum_of_pos n (Ξ» n,2*n+1) : rfl ... = 2 * (n+1) + 1 + (n+1)Β² : sorry ... = nΒ² + 4*n + 4 : sorry ... = (n+2)Β² : sorry) /- [KS] Theorem: For any natural number n, βˆ‘_{i=0}^{nβˆ’1} i = n. Proof: <too many annoying symbols> -/ definition constant_fn (i : nat) : nat β†’ nat := Ξ» n, i theorem sum_constant : βˆ€ (n:nat), sum_of_pos n (constant_fn 1) = n := take n, nat.induction_on n (show sum_of_pos 0 (constant_fn 1) = 0, from rfl) (assume n (IHn : sum_of_pos n (constant_fn 1) = n), show sum_of_pos (n+1) (constant_fn 1) = n+1, from calc sum_of_pos (n+1) (constant_fn 1) = 1 + sum_of_pos n (constant_fn 1) : rfl ... = 1 + n : IHn ... = n + 1 : add_comm) -- Variants on Induction /- [KS] Theorem: Let P(n) be a property that applies to natural numbers and let k be a natural number. If the following are true: - P(k) is true - For any n ∈ β„• with n β‰₯ k, P(n) β†’ P(n + 1) Then for any n ∈ β„• with n β‰₯ k, P(n) is true. Proof: Consider any property P(n) of the natural numbers for which the above is true. Now, define Q(n) ≑ P(n + k). This proof will work in two parts: first, we will prove, by induction, that Q(n) is true for all n . Next, we will show that this implies that ∈ β„• P(n) is true for all n where ∈ β„• n β‰₯ k. First, we prove that Q(n) is true for all n by induction. As our base case, we prove ∈ β„• Q(0), meaning that P(k) holds. By our choice of P, we know that this is true. Thus Q(0) holds. For the inductive step, assume that for some n that ∈ β„• Q(n) is true, meaning that P(n + k) holds. We will prove that Q(n + 1) is true, meaning that P(n + k + 1) holds. Now, since n ∈ β„• , we know that n β‰₯ 0. Consequently, we know that n + k β‰₯ k. Thus by the properties of P, we know that P(n + k) implies P(n + k + 1). Since Q(n + 1) ≑ P(n + k + 1), this proves that Q(n + 1) holds, completing the induction. Thus Q(n) is true for all natural numbers n. Now, we use this result to prove that P(n) is true for all natural numbers n β‰₯ k. Consider any arbitrary natural number n β‰₯ k. Thus n – k β‰₯ 0, so n – k is a natural number. Therefore, Q(n – k) holds. Since (n – k) + k = n, this means that P(n) holds. Since our choice of n was arbitrary, this shows that P(n) is true for all natural numbers n β‰₯ k. -/ -- [DHS]#TODO tricky to avoid burdens, need the elaborator to kick-ass mod AC open nat definition shift (P : nat β†’ Prop) (k : nat) : nat β†’ Prop := Ξ» m, P (m + k) theorem nat.late_induction_on {P : nat β†’ Prop} (k : nat) (base : P k) (step : βˆ€ (n:nat), n β‰₯ k β†’ P n β†’ P (n+1)) : βˆ€ (n:nat), n β‰₯ k β†’ P n := -- Consider any property P(n) of the natural numbers for which the above is true. -- Now, define Q(n) ≑ P(n + k). let Q := shift P k in let Q := Ξ» n, P (n + k) in -- This proof will work in two parts: first, we will prove, by induction, that Q(n) is true for all n. -- Next, we will show that this implies that ∈ β„• P(n) is true for all n where ∈ β„• n β‰₯ k. -- First, we prove that Q(n) is true for all n have Q_holds : βˆ€ n, Q n, from take n, -- by induction. nat.induction_on n (-- As our base case, we prove ∈ β„• Q(0), meaning that P(k) holds. show Q 0, from -- By our choice of P, we know that this is true. Thus Q(0) holds. (zero_add k)⁻¹ β–Έ base) (-- For the inductive step, assume that for some n that ∈ β„• Q(n) is true, (assume n (Qn : Q n), -- meaning that P(n + k) holds. have pnk : P (n + k), from Qn, -- We will prove that Q(n + 1) is true, meaning that P(n + k + 1) holds. show Q (n+1), from -- Now, since n ∈ β„• , we know that n β‰₯ 0. Consequently, we know that n + k β‰₯ k. have npk_ge_k : n + k β‰₯ k, from le_add_left k n, -- Thus by the properties of P, we know that P(n + k) implies P(n + k + 1). have pnk_p1 : P (n + k + 1), from step (n+k) npk_ge_k Qn, -- Since Q(n + 1) ≑ P(n + k + 1), this proves that Q(n + 1) holds, completing the induction. (add.right_comm n k 1) β–Έ pnk_p1 -- Thus Q(n) is true for all natural numbers n. ) -- Now, we use this result to prove that P(n) is true for all natural numbers n β‰₯ k. show βˆ€ (n : nat), n β‰₯ k β†’ P n, from -- Consider any arbitrary natural number n β‰₯ k. take (n : nat) (n_ge_k : n β‰₯ k), -- Thus n – k β‰₯ 0, so n – k is a natural number. -- Therefore, Q(n – k) holds. Since (n – k) + k = n, this means that P(n) holds. have n_mk_pk : (n - k) + k = n, from sub_add_cancel n_ge_k, have Q_nmk : Q (n - k), from Q_holds (n-k), n_mk_pk β–Έ Q_nmk -- Since our choice of n was arbitrary, this shows that P(n) is true for all natural numbers n β‰₯ k.
ded75625c80889d53fcff37faf6ba640956a5673
618003631150032a5676f229d13a079ac875ff77
/src/analysis/calculus/darboux.lean
d3552d90d17eee06dd14ed930957769174855529
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
4,776
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.calculus.mean_value /-! # Darboux's theorem In this file we prove that the derivative of a differentiable function on an interval takes all intermediate values. The proof is based on the [Wikipedia](https://en.wikipedia.org/wiki/Darboux%27s_theorem_(analysis)) page about this theorem. -/ open filter set open_locale topological_space classical variables {a b : ℝ} {f f' : ℝ β†’ ℝ} /-- Darboux's theorem: if `a ≀ b` and `f' a < m < f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_has_deriv_within_at_eq_of_gt_of_lt (hab : a ≀ b) (hf : βˆ€ x ∈ (Icc a b), has_deriv_within_at f (f' x) (Icc a b) x) {m : ℝ} (hma : f' a < m) (hmb : m < f' b) : m ∈ f' '' (Icc a b) := begin have hab' : a < b, { refine lt_of_le_of_ne hab (Ξ» hab', _), subst b, exact lt_asymm hma hmb }, set g : ℝ β†’ ℝ := Ξ» x, f x - m * x, have hg : βˆ€ x ∈ Icc a b, has_deriv_within_at g (f' x - m) (Icc a b) x, { intros x hx, simpa using (hf x hx).sub ((has_deriv_within_at_id x _).const_mul m) }, obtain ⟨c, cmem, hc⟩ : βˆƒ c ∈ Icc a b, is_min_on g (Icc a b) c, from compact_Icc.exists_forall_le (nonempty_Icc.2 $ hab) (Ξ» x hx, (hg x hx).continuous_within_at), have cmem' : c ∈ Ioo a b, { cases eq_or_lt_of_le cmem.1 with hac hac, -- Show that `c` can't be equal to `a` { subst c, refine absurd (sub_nonneg.1 $ nonneg_of_mul_nonneg_left _ (sub_pos.2 hab')) (not_le_of_lt hma), have : b - a ∈ pos_tangent_cone_at (Icc a b) a, from mem_pos_tangent_cone_at_of_segment_subset (segment_eq_Icc hab β–Έ subset.refl _), simpa [-sub_nonneg, -continuous_linear_map.map_sub] using hc.localize.has_fderiv_within_at_nonneg (hg a (left_mem_Icc.2 hab)) this }, cases eq_or_lt_of_le cmem.2 with hbc hbc, -- Show that `c` can't be equal to `a` { subst c, refine absurd (sub_nonpos.1 $ nonpos_of_mul_nonneg_right _ (sub_lt_zero.2 hab')) (not_le_of_lt hmb), have : a - b ∈ pos_tangent_cone_at (Icc a b) b, from mem_pos_tangent_cone_at_of_segment_subset (by rw [segment_symm, segment_eq_Icc hab]), simpa [-sub_nonneg, -continuous_linear_map.map_sub] using hc.localize.has_fderiv_within_at_nonneg (hg b (right_mem_Icc.2 hab)) this }, exact ⟨hac, hbc⟩ }, use [c, cmem], rw [← sub_eq_zero], have : Icc a b ∈ 𝓝 c, by rwa [← mem_interior_iff_mem_nhds, interior_Icc], exact (hc.is_local_min this).has_deriv_at_eq_zero ((hg c cmem).has_deriv_at this) end /-- Darboux's theorem: if `a ≀ b` and `f' a > m > f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_has_deriv_within_at_eq_of_lt_of_gt (hab : a ≀ b) (hf : βˆ€ x ∈ (Icc a b), has_deriv_within_at f (f' x) (Icc a b) x) {m : ℝ} (hma : m < f' a) (hmb : f' b < m) : m ∈ f' '' (Icc a b) := let ⟨c, cmem, hc⟩ := exists_has_deriv_within_at_eq_of_gt_of_lt hab (Ξ» x hx, (hf x hx).neg) (neg_lt_neg hma) (neg_lt_neg hmb) in ⟨c, cmem, neg_inj hc⟩ /-- Darboux's theorem: the image of a convex set under `f'` is a convex set. -/ theorem convex_image_has_deriv_at {s : set ℝ} (hs : convex s) (hf : βˆ€ x ∈ s, has_deriv_at f (f' x) x) : convex (f' '' s) := begin refine convex_real_iff.2 _, rintros _ _ ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩ m ⟨hma, hmb⟩, cases eq_or_lt_of_le hma with hma hma, by exact hma β–Έ mem_image_of_mem f' ha, cases eq_or_lt_of_le hmb with hmb hmb, by exact hmb.symm β–Έ mem_image_of_mem f' hb, cases le_total a b with hab hab, { have : Icc a b βŠ† s, from convex_real_iff.1 hs ha hb, rcases exists_has_deriv_within_at_eq_of_gt_of_lt hab (Ξ» x hx, (hf x $ this hx).has_deriv_within_at) hma hmb with ⟨c, cmem, hc⟩, exact ⟨c, this cmem, hc⟩ }, { have : Icc b a βŠ† s, from convex_real_iff.1 hs hb ha, rcases exists_has_deriv_within_at_eq_of_lt_of_gt hab (Ξ» x hx, (hf x $ this hx).has_deriv_within_at) hmb hma with ⟨c, cmem, hc⟩, exact ⟨c, this cmem, hc⟩ } end /-- If the derivative of a function is never equal to `m`, then either it is always greater than `m`, or it is always less than `m`. -/ theorem deriv_forall_lt_or_forall_gt_of_forall_ne {s : set ℝ} (hs : convex s) (hf : βˆ€ x ∈ s, has_deriv_at f (f' x) x) {m : ℝ} (hf' : βˆ€ x ∈ s, f' x β‰  m) : (βˆ€ x ∈ s, f' x < m) ∨ (βˆ€ x ∈ s, m < f' x) := begin contrapose! hf', rcases hf' with ⟨⟨b, hb, hmb⟩, ⟨a, ha, hma⟩⟩, exact convex_real_iff.1 (convex_image_has_deriv_at hs hf) (mem_image_of_mem f' ha) (mem_image_of_mem f' hb) ⟨hma, hmb⟩ end
6118db58126728211fb98f68df9717042061f089
d11a77796ce855e9f8d9d84892d54616b7d5a758
/src/myoption.lean
ef372bd92a88a7dc37be3cf8e9fd35b1e84c8f26
[]
no_license
kmill/lean-graphcoloring
014f2bfb8c0d4b2ddda9d7d4de3de2ecdbb40ad7
1bb2050ed358ff647186f89922d6a09b838444e5
refs/heads/master
1,666,902,260,074
1,591,913,639,000
1,591,913,639,000
271,116,459
2
0
null
null
null
null
UTF-8
Lean
false
false
394
lean
import tactic import data.option.basic namespace option instance coe_option {A B} [has_lift_t A B]: has_lift_t (option A) (option B) := ⟨λ (x : option A), x.map (Ξ» a, ↑a)⟩ @[norm_cast] lemma coe_option_get_or_else {A B} [has_lift_t A B] (o : option A) (a : A) : (↑(o.get_or_else a) : B) = ((↑o : option B).get_or_else (↑a : B)) := begin cases o, simpa, simpa, end end option
9071cde215625184bf7555b5d0f0501eb80f806c
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/redundantAlt.lean
fa1eb81dcdf9f39940f145116b0bf264f48727e1
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
118
lean
def f (x : Nat) : Nat := match x with | 0 => 1 | Nat.succ (Nat.succ x) => 3 | 2 => 4 | Nat.succ x => 5 | 3 => 6
008722ae47c683964cb7bcbb6b8b94af52a582db
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/error_full_names.lean
04e7d86c1c2bf3a122ac9c51b8d5c4fed3aea5c6
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
166
lean
namespace foo open nat inductive nat : Type := zero | foosucc : nat β†’ nat check 0 + nat.zero --error end foo namespace foo check nat.succ nat.zero --error end foo
798bc3046222b937dde5ff865203c7e912d37a8e
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/uniform_space/basic.lean
16bfa5185232aa0afa7b1b3676e1caa4eaa74acc
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
71,253
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro, Patrick Massot -/ import order.filter.lift import topology.separation /-! # Uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * uniform continuity (in this file) * completeness (in `cauchy.lean`) * extension of uniform continuous functions to complete spaces (in `uniform_embedding.lean`) * totally bounded sets (in `cauchy.lean`) * totally bounded complete sets are compact (in `cauchy.lean`) A uniform structure on a type `X` is a filter `𝓀 X` on `X Γ— X` satisfying some conditions which makes it reasonable to say that `βˆ€αΆ  (p : X Γ— X) in 𝓀 X, ...` means "for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages of `X`. The two main examples are: * If `X` is a metric space, `V ∈ 𝓀 X ↔ βˆƒ Ξ΅ > 0, { p | dist p.1 p.2 < Ξ΅ } βŠ† V` * If `G` is an additive topological group, `V ∈ 𝓀 G ↔ βˆƒ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} βŠ† V` Those examples are generalizations in two different directions of the elementary example where `X = ℝ` and `V ∈ 𝓀 ℝ ↔ βˆƒ Ξ΅ > 0, { p | |p.2 - p.1| < Ξ΅ } βŠ† V` which features both the topological group structure on `ℝ` and its metric space structure. Each uniform structure on `X` induces a topology on `X` characterized by > `nhds_eq_comap_uniformity : βˆ€ {x : X}, 𝓝 x = comap (prod.mk x) (𝓀 X)` where `prod.mk x : X β†’ X Γ— X := (Ξ» y, (x, y))` is the partial evaluation of the product constructor. The dictionary with metric spaces includes: * an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓀 X` * a ball `ball x r` roughly corresponds to `uniform_space.ball x V := {y | (x, y) ∈ V}` for some `V ∈ 𝓀 X`, but the later is more general (it includes in particular both open and closed balls for suitable `V`). In particular we have: `is_open_iff_ball_subset {s : set X} : is_open s ↔ βˆ€ x ∈ s, βˆƒ V ∈ 𝓀 X, ball x V βŠ† s` The triangle inequality is abstracted to a statement involving the composition of relations in `X`. First note that the triangle inequality in a metric space is equivalent to `βˆ€ (x y z : X) (r r' : ℝ), dist x y ≀ r β†’ dist y z ≀ r' β†’ dist x z ≀ r + r'`. Then, for any `V` and `W` with type `set (X Γ— X)`, the composition `V β—‹ W : set (X Γ— X)` is defined as `{ p : X Γ— X | βˆƒ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`. In the metric space case, if `V = { p | dist p.1 p.2 ≀ r }` and `W = { p | dist p.1 p.2 ≀ r' }` then the triangle inequality, as reformulated above, says `V β—‹ W` is contained in `{p | dist p.1 p.2 ≀ r + r'}` which is the entourage associated to the radius `r + r'`. In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V β—‹ W)`. Note that this discussion does not depend on any axiom imposed on the uniformity filter, it is simply captured by the definition of composition. The uniform space axioms ask the filter `𝓀 X` to satisfy the following: * every `V ∈ 𝓀 X` contains the diagonal `id_rel = { p | p.1 = p.2 }`. This abstracts the fact that `dist x x ≀ r` for every non-negative radius `r` in the metric space case and also that `x - x` belongs to every neighborhood of zero in the topological group case. * `V ∈ 𝓀 X β†’ prod.swap '' V ∈ 𝓀 X`. This is tightly related the fact that `dist x y = dist y x` in a metric space, and to continuity of negation in the topological group case. * `βˆ€ V ∈ 𝓀 X, βˆƒ W ∈ 𝓀 X, W β—‹ W βŠ† V`. In the metric space case, it corresponds to cutting the radius of a ball in half and applying the triangle inequality. In the topological group case, it comes from continuity of addition at `(0, 0)`. These three axioms are stated more abstractly in the definition below, in terms of operations on filters, without directly manipulating entourages. ##Β Main definitions * `uniform_space X` is a uniform space structure on a type `X` * `uniform_continuous f` is a predicate saying a function `f : Ξ± β†’ Ξ²` between uniform spaces is uniformly continuous : `βˆ€ r ∈ 𝓀 Ξ², βˆ€αΆ  (x : Ξ± Γ— Ξ±) in 𝓀 Ξ±, (f x.1, f x.2) ∈ r` In this file we also define a complete lattice structure on the type `uniform_space X` of uniform structures on `X`, as well as the pullback (`uniform_space.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `uniformity`, we have the notation `𝓀 X` for the uniformity on a uniform space `X`, and `β—‹` for composition of relations, seen as terms with type `set (X Γ— X)`. ## Implementation notes There is already a theory of relations in `data/rel.lean` where the main definition is `def rel (Ξ± Ξ² : Type*) := Ξ± β†’ Ξ² β†’ Prop`. The relations used in the current file involve only one type, but this is not the reason why we don't reuse `data/rel.lean`. We use `set (Ξ± Γ— Ξ±)` instead of `rel Ξ± Ξ±` because we really need sets to use the filter library, and elements of filters on `Ξ± Γ— Ξ±` have type `set (Ξ± Γ— Ξ±)`. The structure `uniform_space X` bundles a uniform structure on `X`, a topology on `X` and an assumption saying those are compatible. This may not seem mathematically reasonable at first, but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance] below. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open set filter classical open_locale classical topological_space filter set_option eqn_compiler.zeta true universes u /-! ### Relations, seen as `set (Ξ± Γ— Ξ±)` -/ variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} {ΞΉ : Sort*} /-- The identity relation, or the graph of the identity function -/ def id_rel {Ξ± : Type*} := {p : Ξ± Γ— Ξ± | p.1 = p.2} @[simp] theorem mem_id_rel {a b : Ξ±} : (a, b) ∈ @id_rel Ξ± ↔ a = b := iff.rfl @[simp] theorem id_rel_subset {s : set (Ξ± Γ— Ξ±)} : id_rel βŠ† s ↔ βˆ€ a, (a, a) ∈ s := by simp [subset_def]; exact forall_congr (Ξ» a, by simp) /-- The composition of relations -/ def comp_rel {Ξ± : Type u} (r₁ rβ‚‚ : set (Ξ±Γ—Ξ±)) := {p : Ξ± Γ— Ξ± | βˆƒz:Ξ±, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ rβ‚‚} localized "infix ` β—‹ `:55 := comp_rel" in uniformity @[simp] theorem mem_comp_rel {r₁ rβ‚‚ : set (Ξ±Γ—Ξ±)} {x y : Ξ±} : (x, y) ∈ r₁ β—‹ rβ‚‚ ↔ βˆƒ z, (x, z) ∈ r₁ ∧ (z, y) ∈ rβ‚‚ := iff.rfl @[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel Ξ± := set.ext $ assume ⟨a, b⟩, by simp [image_swap_eq_preimage_swap]; exact eq_comm theorem monotone_comp_rel [preorder Ξ²] {f g : Ξ² β†’ set (Ξ±Γ—Ξ±)} (hf : monotone f) (hg : monotone g) : monotone (Ξ»x, (f x) β—‹ (g x)) := assume a b h p ⟨z, h₁, hβ‚‚βŸ©, ⟨z, hf h h₁, hg h hβ‚‚βŸ© @[mono] lemma comp_rel_mono {f g h k: set (Ξ±Γ—Ξ±)} (h₁ : f βŠ† h) (hβ‚‚ : g βŠ† k) : f β—‹ g βŠ† h β—‹ k := Ξ» ⟨x, y⟩ ⟨z, h, h'⟩, ⟨z, h₁ h, hβ‚‚ h'⟩ lemma prod_mk_mem_comp_rel {a b c : Ξ±} {s t : set (Ξ±Γ—Ξ±)} (h₁ : (a, c) ∈ s) (hβ‚‚ : (c, b) ∈ t) : (a, b) ∈ s β—‹ t := ⟨c, h₁, hβ‚‚βŸ© @[simp] lemma id_comp_rel {r : set (Ξ±Γ—Ξ±)} : id_rel β—‹ r = r := set.ext $ assume ⟨a, b⟩, by simp lemma comp_rel_assoc {r s t : set (Ξ±Γ—Ξ±)} : (r β—‹ s) β—‹ t = r β—‹ (s β—‹ t) := by ext p; cases p; simp only [mem_comp_rel]; tauto lemma subset_comp_self {Ξ± : Type*} {s : set (Ξ± Γ— Ξ±)} (h : id_rel βŠ† s) : s βŠ† s β—‹ s := Ξ» ⟨x, y⟩ xy_in, ⟨x, h (by rw mem_id_rel), xy_in⟩ /-- The relation is invariant under swapping factors. -/ def symmetric_rel (V : set (Ξ± Γ— Ξ±)) : Prop := prod.swap ⁻¹' V = V /-- The maximal symmetric relation contained in a given relation. -/ def symmetrize_rel (V : set (Ξ± Γ— Ξ±)) : set (Ξ± Γ— Ξ±) := V ∩ prod.swap ⁻¹' V lemma symmetric_symmetrize_rel (V : set (Ξ± Γ— Ξ±)) : symmetric_rel (symmetrize_rel V) := by simp [symmetric_rel, symmetrize_rel, preimage_inter, inter_comm, ← preimage_comp] lemma symmetrize_rel_subset_self (V : set (Ξ± Γ— Ξ±)) : symmetrize_rel V βŠ† V := sep_subset _ _ @[mono] lemma symmetrize_mono {V W: set (Ξ± Γ— Ξ±)} (h : V βŠ† W) : symmetrize_rel V βŠ† symmetrize_rel W := inter_subset_inter h $ preimage_mono h lemma symmetric_rel_inter {U V : set (Ξ± Γ— Ξ±)} (hU : symmetric_rel U) (hV : symmetric_rel V) : symmetric_rel (U ∩ V) := begin unfold symmetric_rel at *, rw [preimage_inter, hU, hV], end /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure uniform_space.core (Ξ± : Type u) := (uniformity : filter (Ξ± Γ— Ξ±)) (refl : π“Ÿ id_rel ≀ uniformity) (symm : tendsto prod.swap uniformity uniformity) (comp : uniformity.lift' (Ξ»s, s β—‹ s) ≀ uniformity) /-- An alternative constructor for `uniform_space.core`. This version unfolds various `filter`-related definitions. -/ def uniform_space.core.mk' {Ξ± : Type u} (U : filter (Ξ± Γ— Ξ±)) (refl : βˆ€ (r ∈ U) x, (x, x) ∈ r) (symm : βˆ€ r ∈ U, prod.swap ⁻¹' r ∈ U) (comp : βˆ€ r ∈ U, βˆƒ t ∈ U, t β—‹ t βŠ† r) : uniform_space.core Ξ± := ⟨U, Ξ» r ru, id_rel_subset.2 (refl _ ru), symm, begin intros r ru, rw [mem_lift'_sets], exact comp _ ru, apply monotone_comp_rel; exact monotone_id, end⟩ /-- A uniform space generates a topological space -/ def uniform_space.core.to_topological_space {Ξ± : Type u} (u : uniform_space.core Ξ±) : topological_space Ξ± := { is_open := Ξ»s, βˆ€x∈s, { p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s } ∈ u.uniformity, is_open_univ := by simp; intro; exact univ_mem, is_open_inter := assume s t hs ht x ⟨xs, xt⟩, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt}, is_open_sUnion := assume s hs x ⟨t, ts, xt⟩, by filter_upwards [hs t ts x xt] assume p ph h, ⟨t, ts, ph h⟩ } lemma uniform_space.core_eq : βˆ€{u₁ uβ‚‚ : uniform_space.core Ξ±}, u₁.uniformity = uβ‚‚.uniformity β†’ u₁ = uβ‚‚ | ⟨u₁, _, _, _⟩ ⟨uβ‚‚, _, _, _⟩ h := by { congr, exact h } -- the topological structure is embedded in the uniform structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `Ξ± Γ— Ξ±` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class uniform_space (Ξ± : Type u) extends topological_space Ξ±, uniform_space.core Ξ± := (is_open_uniformity : βˆ€s, is_open s ↔ (βˆ€x∈s, { p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s } ∈ uniformity)) /-- Alternative constructor for `uniform_space Ξ±` when a topology is already given. -/ @[pattern] def uniform_space.mk' {Ξ±} (t : topological_space Ξ±) (c : uniform_space.core Ξ±) (is_open_uniformity : βˆ€s:set Ξ±, t.is_open s ↔ (βˆ€x∈s, { p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s } ∈ c.uniformity)) : uniform_space Ξ± := ⟨c, is_open_uniformity⟩ /-- Construct a `uniform_space` from a `uniform_space.core`. -/ def uniform_space.of_core {Ξ± : Type u} (u : uniform_space.core Ξ±) : uniform_space Ξ± := { to_core := u, to_topological_space := u.to_topological_space, is_open_uniformity := assume a, iff.rfl } /-- Construct a `uniform_space` from a `u : uniform_space.core` and a `topological_space` structure that is equal to `u.to_topological_space`. -/ def uniform_space.of_core_eq {Ξ± : Type u} (u : uniform_space.core Ξ±) (t : topological_space Ξ±) (h : t = u.to_topological_space) : uniform_space Ξ± := { to_core := u, to_topological_space := t, is_open_uniformity := assume a, h.symm β–Έ iff.rfl } lemma uniform_space.to_core_to_topological_space (u : uniform_space Ξ±) : u.to_core.to_topological_space = u.to_topological_space := topological_space_eq $ funext $ assume s, by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity] @[ext] lemma uniform_space_eq : βˆ€{u₁ uβ‚‚ : uniform_space Ξ±}, u₁.uniformity = uβ‚‚.uniformity β†’ u₁ = uβ‚‚ | (uniform_space.mk' t₁ u₁ o₁) (uniform_space.mk' tβ‚‚ uβ‚‚ oβ‚‚) h := have u₁ = uβ‚‚, from uniform_space.core_eq h, have t₁ = tβ‚‚, from topological_space_eq $ funext $ assume s, by rw [o₁, oβ‚‚]; simp [this], by simp [*] lemma uniform_space.of_core_eq_to_core (u : uniform_space Ξ±) (t : topological_space Ξ±) (h : t = u.to_core.to_topological_space) : uniform_space.of_core_eq u.to_core t h = u := uniform_space_eq rfl section uniform_space variables [uniform_space Ξ±] /-- The uniformity is a filter on Ξ± Γ— Ξ± (inferred from an ambient uniform space structure on Ξ±). -/ def uniformity (Ξ± : Type u) [uniform_space Ξ±] : filter (Ξ± Γ— Ξ±) := (@uniform_space.to_core Ξ± _).uniformity localized "notation `𝓀` := uniformity" in uniformity lemma is_open_uniformity {s : set Ξ±} : is_open s ↔ (βˆ€x∈s, { p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s } ∈ 𝓀 Ξ±) := uniform_space.is_open_uniformity s lemma refl_le_uniformity : π“Ÿ id_rel ≀ 𝓀 Ξ± := (@uniform_space.to_core Ξ± _).refl lemma refl_mem_uniformity {x : Ξ±} {s : set (Ξ± Γ— Ξ±)} (h : s ∈ 𝓀 Ξ±) : (x, x) ∈ s := refl_le_uniformity h rfl lemma mem_uniformity_of_eq {x y : Ξ±} {s : set (Ξ± Γ— Ξ±)} (h : s ∈ 𝓀 Ξ±) (hx : x = y) : (x, y) ∈ s := hx β–Έ refl_mem_uniformity h lemma symm_le_uniformity : map (@prod.swap Ξ± Ξ±) (𝓀 _) ≀ (𝓀 _) := (@uniform_space.to_core Ξ± _).symm lemma comp_le_uniformity : (𝓀 Ξ±).lift' (Ξ»s:set (Ξ±Γ—Ξ±), s β—‹ s) ≀ 𝓀 Ξ± := (@uniform_space.to_core Ξ± _).comp lemma tendsto_swap_uniformity : tendsto (@prod.swap Ξ± Ξ±) (𝓀 Ξ±) (𝓀 Ξ±) := symm_le_uniformity lemma comp_mem_uniformity_sets {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, t β—‹ t βŠ† s := have s ∈ (𝓀 Ξ±).lift' (Ξ»t:set (Ξ±Γ—Ξ±), t β—‹ t), from comp_le_uniformity hs, (mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this /-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (𝓀 Ξ±)` is transitive. -/ lemma filter.tendsto.uniformity_trans {l : filter Ξ²} {f₁ fβ‚‚ f₃ : Ξ² β†’ Ξ±} (h₁₂ : tendsto (Ξ» x, (f₁ x, fβ‚‚ x)) l (𝓀 Ξ±)) (h₂₃ : tendsto (Ξ» x, (fβ‚‚ x, f₃ x)) l (𝓀 Ξ±)) : tendsto (Ξ» x, (f₁ x, f₃ x)) l (𝓀 Ξ±) := begin refine le_trans (le_lift' $ Ξ» s hs, mem_map.2 _) comp_le_uniformity, filter_upwards [h₁₂ hs, h₂₃ hs], exact Ξ» x hx₁₂ hx₂₃, ⟨_, hx₁₂, hxβ‚‚β‚ƒβŸ© end /-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (𝓀 Ξ±)` is symmetric -/ lemma filter.tendsto.uniformity_symm {l : filter Ξ²} {f : Ξ² β†’ Ξ± Γ— Ξ±} (h : tendsto f l (𝓀 Ξ±)) : tendsto (Ξ» x, ((f x).2, (f x).1)) l (𝓀 Ξ±) := tendsto_swap_uniformity.comp h /-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (𝓀 Ξ±)` is reflexive. -/ lemma tendsto_diag_uniformity (f : Ξ² β†’ Ξ±) (l : filter Ξ²) : tendsto (Ξ» x, (f x, f x)) l (𝓀 Ξ±) := assume s hs, mem_map.2 $ univ_mem' $ Ξ» x, refl_mem_uniformity hs lemma tendsto_const_uniformity {a : Ξ±} {f : filter Ξ²} : tendsto (Ξ» _, (a, a)) f (𝓀 Ξ±) := tendsto_diag_uniformity (Ξ» _, a) f lemma symm_of_uniformity {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, (βˆ€a b, (a, b) ∈ t β†’ (b, a) ∈ t) ∧ t βŠ† s := have preimage prod.swap s ∈ 𝓀 Ξ±, from symm_le_uniformity hs, ⟨s ∩ preimage prod.swap s, inter_mem hs this, Ξ» a b ⟨h₁, hβ‚‚βŸ©, ⟨hβ‚‚, hβ‚βŸ©, inter_subset_left _ _⟩ lemma comp_symm_of_uniformity {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, (βˆ€{a b}, (a, b) ∈ t β†’ (b, a) ∈ t) ∧ t β—‹ t βŠ† s := let ⟨t, ht₁, htβ‚‚βŸ© := comp_mem_uniformity_sets hs in let ⟨t', ht', ht'₁, ht'β‚‚βŸ© := symm_of_uniformity ht₁ in ⟨t', ht', ht'₁, subset.trans (monotone_comp_rel monotone_id monotone_id ht'β‚‚) htβ‚‚βŸ© lemma uniformity_le_symm : 𝓀 Ξ± ≀ (@prod.swap Ξ± Ξ±) <$> 𝓀 Ξ± := by rw [map_swap_eq_comap_swap]; from map_le_iff_le_comap.1 tendsto_swap_uniformity lemma uniformity_eq_symm : 𝓀 Ξ± = (@prod.swap Ξ± Ξ±) <$> 𝓀 Ξ± := le_antisymm uniformity_le_symm symm_le_uniformity lemma symmetrize_mem_uniformity {V : set (Ξ± Γ— Ξ±)} (h : V ∈ 𝓀 Ξ±) : symmetrize_rel V ∈ 𝓀 Ξ± := begin apply (𝓀 Ξ±).inter_sets h, rw [← image_swap_eq_preimage_swap, uniformity_eq_symm], exact image_mem_map h, end theorem uniformity_lift_le_swap {g : set (Ξ±Γ—Ξ±) β†’ filter Ξ²} {f : filter Ξ²} (hg : monotone g) (h : (𝓀 Ξ±).lift (Ξ»s, g (preimage prod.swap s)) ≀ f) : (𝓀 Ξ±).lift g ≀ f := calc (𝓀 Ξ±).lift g ≀ (filter.map (@prod.swap Ξ± Ξ±) $ 𝓀 Ξ±).lift g : lift_mono uniformity_le_symm (le_refl _) ... ≀ _ : by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h lemma uniformity_lift_le_comp {f : set (Ξ±Γ—Ξ±) β†’ filter Ξ²} (h : monotone f) : (𝓀 Ξ±).lift (Ξ»s, f (s β—‹ s)) ≀ (𝓀 Ξ±).lift f := calc (𝓀 Ξ±).lift (Ξ»s, f (s β—‹ s)) = ((𝓀 Ξ±).lift' (Ξ»s:set (Ξ±Γ—Ξ±), s β—‹ s)).lift f : begin rw [lift_lift'_assoc], exact monotone_comp_rel monotone_id monotone_id, exact h end ... ≀ (𝓀 Ξ±).lift f : lift_mono comp_le_uniformity (le_refl _) lemma comp_le_uniformity3 : (𝓀 Ξ±).lift' (Ξ»s:set (Ξ±Γ—Ξ±), s β—‹ (s β—‹ s)) ≀ (𝓀 Ξ±) := calc (𝓀 Ξ±).lift' (Ξ»d, d β—‹ (d β—‹ d)) = (𝓀 Ξ±).lift (Ξ»s, (𝓀 Ξ±).lift' (Ξ»t:set(Ξ±Γ—Ξ±), s β—‹ (t β—‹ t))) : begin rw [lift_lift'_same_eq_lift'], exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id), exact (assume x, monotone_comp_rel monotone_id monotone_const), end ... ≀ (𝓀 Ξ±).lift (Ξ»s, (𝓀 Ξ±).lift' (Ξ»t:set(Ξ±Γ—Ξ±), s β—‹ t)) : lift_mono' $ assume s hs, @uniformity_lift_le_comp Ξ± _ _ (π“Ÿ ∘ (β—‹) s) $ monotone_principal.comp (monotone_comp_rel monotone_const monotone_id) ... = (𝓀 Ξ±).lift' (Ξ»s:set(Ξ±Γ—Ξ±), s β—‹ s) : lift_lift'_same_eq_lift' (assume s, monotone_comp_rel monotone_const monotone_id) (assume s, monotone_comp_rel monotone_id monotone_const) ... ≀ (𝓀 Ξ±) : comp_le_uniformity /-- See also `comp_open_symm_mem_uniformity_sets`. -/ lemma comp_symm_mem_uniformity_sets {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, symmetric_rel t ∧ t β—‹ t βŠ† s := begin obtain ⟨w, w_in, w_sub⟩ : βˆƒ w ∈ 𝓀 Ξ±, w β—‹ w βŠ† s := comp_mem_uniformity_sets hs, use [symmetrize_rel w, symmetrize_mem_uniformity w_in, symmetric_symmetrize_rel w], have : symmetrize_rel w βŠ† w := symmetrize_rel_subset_self w, calc symmetrize_rel w β—‹ symmetrize_rel w βŠ† w β—‹ w : by mono ... βŠ† s : w_sub, end lemma subset_comp_self_of_mem_uniformity {s : set (Ξ± Γ— Ξ±)} (h : s ∈ 𝓀 Ξ±) : s βŠ† s β—‹ s := subset_comp_self (refl_le_uniformity h) lemma comp_comp_symm_mem_uniformity_sets {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, symmetric_rel t ∧ t β—‹ t β—‹ t βŠ† s := begin rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, w_symm, w_sub⟩, rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩, use [t, t_in, t_symm], have : t βŠ† t β—‹ t := subset_comp_self_of_mem_uniformity t_in, calc t β—‹ t β—‹ t βŠ† w β—‹ t : by mono ... βŠ† w β—‹ (t β—‹ t) : by mono ... βŠ† w β—‹ w : by mono ... βŠ† s : w_sub, end /-! ###Β Balls in uniform spaces -/ /-- The ball around `(x : Ξ²)` with respect to `(V : set (Ξ² Γ— Ξ²))`. Intended to be used for `V ∈ 𝓀 Ξ²`, but this is not needed for the definition. Recovers the notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/ def uniform_space.ball (x : Ξ²) (V : set (Ξ² Γ— Ξ²)) : set Ξ² := (prod.mk x) ⁻¹' V open uniform_space (ball) lemma uniform_space.mem_ball_self (x : Ξ±) {V : set (Ξ± Γ— Ξ±)} (hV : V ∈ 𝓀 Ξ±) : x ∈ ball x V := refl_mem_uniformity hV /-- The triangle inequality for `uniform_space.ball` -/ lemma mem_ball_comp {V W : set (Ξ² Γ— Ξ²)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V β—‹ W) := prod_mk_mem_comp_rel h h' lemma ball_subset_of_comp_subset {V W : set (Ξ² Γ— Ξ²)} {x y} (h : x ∈ ball y W) (h' : W β—‹ W βŠ† V) : ball x W βŠ† ball y V := Ξ» z z_in, h' (mem_ball_comp h z_in) lemma ball_mono {V W : set (Ξ² Γ— Ξ²)} (h : V βŠ† W) (x : Ξ²) : ball x V βŠ† ball x W := by tauto lemma ball_inter_left (x : Ξ²) (V W : set (Ξ² Γ— Ξ²)) : ball x (V ∩ W) βŠ† ball x V := ball_mono (inter_subset_left V W) x lemma ball_inter_right (x : Ξ²) (V W : set (Ξ² Γ— Ξ²)) : ball x (V ∩ W) βŠ† ball x W := ball_mono (inter_subset_right V W) x lemma mem_ball_symmetry {V : set (Ξ² Γ— Ξ²)} (hV : symmetric_rel V) {x y} : x ∈ ball y V ↔ y ∈ ball x V := show (x, y) ∈ prod.swap ⁻¹' V ↔ (x, y) ∈ V, by { unfold symmetric_rel at hV, rw hV } lemma ball_eq_of_symmetry {V : set (Ξ² Γ— Ξ²)} (hV : symmetric_rel V) {x} : ball x V = {y | (y, x) ∈ V} := by { ext y, rw mem_ball_symmetry hV, exact iff.rfl } lemma mem_comp_of_mem_ball {V W : set (Ξ² Γ— Ξ²)} {x y z : Ξ²} (hV : symmetric_rel V) (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V β—‹ W := begin rw mem_ball_symmetry hV at hx, exact ⟨z, hx, hy⟩ end lemma uniform_space.is_open_ball (x : Ξ±) {V : set (Ξ± Γ— Ξ±)} (hV : is_open V) : is_open (ball x V) := hV.preimage $ continuous_const.prod_mk continuous_id lemma mem_comp_comp {V W M : set (Ξ² Γ— Ξ²)} (hW' : symmetric_rel W) {p : Ξ² Γ— Ξ²} : p ∈ V β—‹ M β—‹ W ↔ ((ball p.1 V).prod (ball p.2 W) ∩ M).nonempty := begin cases p with x y, split, { rintros ⟨z, ⟨w, hpw, hwz⟩, hzy⟩, exact ⟨(w, z), ⟨hpw, by rwa mem_ball_symmetry hW'⟩, hwz⟩, }, { rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩, rwa mem_ball_symmetry hW' at z_in, use [z, w] ; tauto }, end /-! ### Neighborhoods in uniform spaces -/ lemma mem_nhds_uniformity_iff_right {x : Ξ±} {s : set Ξ±} : s ∈ 𝓝 x ↔ {p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s} ∈ 𝓀 Ξ± := ⟨ begin simp only [mem_nhds_iff, is_open_uniformity, and_imp, exists_imp_distrib], exact assume t ts ht xt, by filter_upwards [ht x xt] assume ⟨x', y⟩ h eq, ts $ h eq end, assume hs, mem_nhds_iff.mpr ⟨{x | {p : Ξ± Γ— Ξ± | p.1 = x β†’ p.2 ∈ s} ∈ 𝓀 Ξ±}, assume x' hx', refl_mem_uniformity hx' rfl, is_open_uniformity.mpr $ assume x' hx', let ⟨t, ht, tr⟩ := comp_mem_uniformity_sets hx' in by filter_upwards [ht] assume ⟨a, b⟩ hp' (hax' : a = x'), by filter_upwards [ht] assume ⟨a, b'⟩ hp'' (hab : a = b), have hp : (x', b) ∈ t, from hax' β–Έ hp', have (b, b') ∈ t, from hab β–Έ hp'', have (x', b') ∈ t β—‹ t, from ⟨b, hp, this⟩, show b' ∈ s, from tr this rfl, hs⟩⟩ lemma mem_nhds_uniformity_iff_left {x : Ξ±} {s : set Ξ±} : s ∈ 𝓝 x ↔ {p : Ξ± Γ— Ξ± | p.2 = x β†’ p.1 ∈ s} ∈ 𝓀 Ξ± := by { rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right], refl } lemma nhds_eq_comap_uniformity_aux {Ξ± : Type u} {x : Ξ±} {s : set Ξ±} {F : filter (Ξ± Γ— Ξ±)} : {p : Ξ± Γ— Ξ± | p.fst = x β†’ p.snd ∈ s} ∈ F ↔ s ∈ comap (prod.mk x) F := by rw mem_comap ; from iff.intro (assume hs, ⟨_, hs, assume x hx, hx rfl⟩) (assume ⟨t, h, ht⟩, F.sets_of_superset h $ assume ⟨p₁, pβ‚‚βŸ© hp (h : p₁ = x), ht $ by simp [h.symm, hp]) lemma nhds_eq_comap_uniformity {x : Ξ±} : 𝓝 x = (𝓀 Ξ±).comap (prod.mk x) := by { ext s, rw [mem_nhds_uniformity_iff_right], exact nhds_eq_comap_uniformity_aux } /-- See also `is_open_iff_open_ball_subset`. -/ lemma is_open_iff_ball_subset {s : set Ξ±} : is_open s ↔ βˆ€ x ∈ s, βˆƒ V ∈ 𝓀 Ξ±, ball x V βŠ† s := begin simp_rw [is_open_iff_mem_nhds, nhds_eq_comap_uniformity], exact iff.rfl, end lemma nhds_basis_uniformity' {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ set (Ξ± Γ— Ξ±)} (h : (𝓀 Ξ±).has_basis p s) {x : Ξ±} : (𝓝 x).has_basis p (Ξ» i, ball x (s i)) := by { rw [nhds_eq_comap_uniformity], exact h.comap (prod.mk x) } lemma nhds_basis_uniformity {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ set (Ξ± Γ— Ξ±)} (h : (𝓀 Ξ±).has_basis p s) {x : Ξ±} : (𝓝 x).has_basis p (Ξ» i, {y | (y, x) ∈ s i}) := begin replace h := h.comap prod.swap, rw [← map_swap_eq_comap_swap, ← uniformity_eq_symm] at h, exact nhds_basis_uniformity' h end lemma uniform_space.mem_nhds_iff {x : Ξ±} {s : set Ξ±} : s ∈ 𝓝 x ↔ βˆƒ V ∈ 𝓀 Ξ±, ball x V βŠ† s := begin rw [nhds_eq_comap_uniformity, mem_comap], exact iff.rfl, end lemma uniform_space.ball_mem_nhds (x : Ξ±) ⦃V : set (Ξ± Γ— Ξ±)⦄ (V_in : V ∈ 𝓀 Ξ±) : ball x V ∈ 𝓝 x := begin rw uniform_space.mem_nhds_iff, exact ⟨V, V_in, subset.refl _⟩ end lemma uniform_space.mem_nhds_iff_symm {x : Ξ±} {s : set Ξ±} : s ∈ 𝓝 x ↔ βˆƒ V ∈ 𝓀 Ξ±, symmetric_rel V ∧ ball x V βŠ† s := begin rw uniform_space.mem_nhds_iff, split, { rintros ⟨V, V_in, V_sub⟩, use [symmetrize_rel V, symmetrize_mem_uniformity V_in, symmetric_symmetrize_rel V], exact subset.trans (ball_mono (symmetrize_rel_subset_self V) x) V_sub }, { rintros ⟨V, V_in, V_symm, V_sub⟩, exact ⟨V, V_in, V_sub⟩ } end lemma uniform_space.has_basis_nhds (x : Ξ±) : has_basis (𝓝 x) (Ξ» s : set (Ξ± Γ— Ξ±), s ∈ 𝓀 Ξ± ∧ symmetric_rel s) (Ξ» s, ball x s) := ⟨λ t, by simp [uniform_space.mem_nhds_iff_symm, and_assoc]⟩ open uniform_space lemma uniform_space.mem_closure_iff_symm_ball {s : set Ξ±} {x} : x ∈ closure s ↔ βˆ€ {V}, V ∈ 𝓀 Ξ± β†’ symmetric_rel V β†’ (s ∩ ball x V).nonempty := by simp [mem_closure_iff_nhds_basis (has_basis_nhds x), set.nonempty] lemma uniform_space.mem_closure_iff_ball {s : set Ξ±} {x} : x ∈ closure s ↔ βˆ€ {V}, V ∈ 𝓀 Ξ± β†’ (ball x V ∩ s).nonempty := by simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓀 Ξ±).basis_sets)] lemma uniform_space.has_basis_nhds_prod (x y : Ξ±) : has_basis (𝓝 (x, y)) (Ξ» s, s ∈ 𝓀 Ξ± ∧ symmetric_rel s) $ Ξ» s, (ball x s).prod (ball y s) := begin rw nhds_prod_eq, apply (has_basis_nhds x).prod' (has_basis_nhds y), rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩, exact ⟨U ∩ V, ⟨(𝓀 Ξ±).inter_sets U_in V_in, symmetric_rel_inter U_symm V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩, end lemma nhds_eq_uniformity {x : Ξ±} : 𝓝 x = (𝓀 Ξ±).lift' (ball x) := (nhds_basis_uniformity' (𝓀 Ξ±).basis_sets).eq_binfi lemma mem_nhds_left (x : Ξ±) {s : set (Ξ±Γ—Ξ±)} (h : s ∈ 𝓀 Ξ±) : {y : Ξ± | (x, y) ∈ s} ∈ 𝓝 x := ball_mem_nhds x h lemma mem_nhds_right (y : Ξ±) {s : set (Ξ±Γ—Ξ±)} (h : s ∈ 𝓀 Ξ±) : {x : Ξ± | (x, y) ∈ s} ∈ 𝓝 y := mem_nhds_left _ (symm_le_uniformity h) lemma tendsto_right_nhds_uniformity {a : Ξ±} : tendsto (Ξ»a', (a', a)) (𝓝 a) (𝓀 Ξ±) := assume s, mem_nhds_right a lemma tendsto_left_nhds_uniformity {a : Ξ±} : tendsto (Ξ»a', (a, a')) (𝓝 a) (𝓀 Ξ±) := assume s, mem_nhds_left a lemma lift_nhds_left {x : Ξ±} {g : set Ξ± β†’ filter Ξ²} (hg : monotone g) : (𝓝 x).lift g = (𝓀 Ξ±).lift (Ξ»s:set (Ξ±Γ—Ξ±), g {y | (x, y) ∈ s}) := eq.trans begin rw [nhds_eq_uniformity], exact (filter.lift_assoc $ monotone_principal.comp $ monotone_preimage.comp monotone_preimage ) end (congr_arg _ $ funext $ assume s, filter.lift_principal hg) lemma lift_nhds_right {x : Ξ±} {g : set Ξ± β†’ filter Ξ²} (hg : monotone g) : (𝓝 x).lift g = (𝓀 Ξ±).lift (Ξ»s:set (Ξ±Γ—Ξ±), g {y | (y, x) ∈ s}) := calc (𝓝 x).lift g = (𝓀 Ξ±).lift (Ξ»s:set (Ξ±Γ—Ξ±), g {y | (x, y) ∈ s}) : lift_nhds_left hg ... = ((@prod.swap Ξ± Ξ±) <$> (𝓀 Ξ±)).lift (Ξ»s:set (Ξ±Γ—Ξ±), g {y | (x, y) ∈ s}) : by rw [←uniformity_eq_symm] ... = (𝓀 Ξ±).lift (Ξ»s:set (Ξ±Γ—Ξ±), g {y | (x, y) ∈ image prod.swap s}) : map_lift_eq2 $ hg.comp monotone_preimage ... = _ : by simp [image_swap_eq_preimage_swap] lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : Ξ±} : 𝓝 a Γ—αΆ  𝓝 b = (𝓀 Ξ±).lift (Ξ»s:set (Ξ±Γ—Ξ±), (𝓀 Ξ±).lift' (Ξ»t:set (Ξ±Γ—Ξ±), set.prod {y : Ξ± | (y, a) ∈ s} {y : Ξ± | (b, y) ∈ t})) := begin rw [prod_def], show (𝓝 a).lift (Ξ»s:set Ξ±, (𝓝 b).lift (Ξ»t:set Ξ±, π“Ÿ (set.prod s t))) = _, rw [lift_nhds_right], apply congr_arg, funext s, rw [lift_nhds_left], refl, exact monotone_principal.comp (monotone_prod monotone_const monotone_id), exact (monotone_lift' monotone_const $ monotone_lam $ assume x, monotone_prod monotone_id monotone_const) end lemma nhds_eq_uniformity_prod {a b : Ξ±} : 𝓝 (a, b) = (𝓀 Ξ±).lift' (Ξ»s:set (Ξ±Γ—Ξ±), set.prod {y : Ξ± | (y, a) ∈ s} {y : Ξ± | (b, y) ∈ s}) := begin rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'], { intro s, exact monotone_prod monotone_const monotone_preimage }, { intro t, exact monotone_prod monotone_preimage monotone_const } end lemma nhdset_of_mem_uniformity {d : set (Ξ±Γ—Ξ±)} (s : set (Ξ±Γ—Ξ±)) (hd : d ∈ 𝓀 Ξ±) : βˆƒ(t : set (Ξ±Γ—Ξ±)), is_open t ∧ s βŠ† t ∧ t βŠ† {p | βˆƒx y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} := let cl_d := {p:Ξ±Γ—Ξ± | βˆƒx y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} in have βˆ€p ∈ s, βˆƒt βŠ† cl_d, is_open t ∧ p ∈ t, from assume ⟨x, y⟩ hp, _root_.mem_nhds_iff.mp $ show cl_d ∈ 𝓝 (x, y), begin rw [nhds_eq_uniformity_prod, mem_lift'_sets], exact ⟨d, hd, assume ⟨a, b⟩ ⟨ha, hb⟩, ⟨x, y, ha, hp, hb⟩⟩, exact monotone_prod monotone_preimage monotone_preimage end, have βˆƒt:(Ξ (p:Ξ±Γ—Ξ±) (h:p ∈ s), set (Ξ±Γ—Ξ±)), βˆ€p, βˆ€h:p ∈ s, t p h βŠ† cl_d ∧ is_open (t p h) ∧ p ∈ t p h, by simp [classical.skolem] at this; simp; assumption, match this with | ⟨t, ht⟩ := ⟨(⋃ p:Ξ±Γ—Ξ±, ⋃ h : p ∈ s, t p h : set (Ξ±Γ—Ξ±)), is_open_Union $ assume (p:Ξ±Γ—Ξ±), is_open_Union $ assume hp, (ht p hp).right.left, assume ⟨a, b⟩ hp, begin simp; exact ⟨a, b, hp, (ht (a,b) hp).right.right⟩ end, Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).left⟩ end /-- Entourages are neighborhoods of the diagonal. -/ lemma nhds_le_uniformity (x : Ξ±) : 𝓝 (x, x) ≀ 𝓀 Ξ± := begin intros V V_in, rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩, have : (ball x w).prod (ball x w) ∈ 𝓝 (x, x), { rw nhds_prod_eq, exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) }, apply mem_of_superset this, rintros ⟨u, v⟩ ⟨u_in, v_in⟩, exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) end /-- Entourages are neighborhoods of the diagonal. -/ lemma supr_nhds_le_uniformity : (⨆ x : Ξ±, 𝓝 (x, x)) ≀ 𝓀 Ξ± := supr_le nhds_le_uniformity /-! ### Closure and interior in uniform spaces -/ lemma closure_eq_uniformity (s : set $ Ξ± Γ— Ξ±) : closure s = β‹‚ V ∈ {V | V ∈ 𝓀 Ξ± ∧ symmetric_rel V}, V β—‹ s β—‹ V := begin ext ⟨x, y⟩, simp_rw [mem_closure_iff_nhds_basis (uniform_space.has_basis_nhds_prod x y), mem_Inter, mem_set_of_eq], apply forall_congr, intro V, apply forall_congr, rintros ⟨V_in, V_symm⟩, simp_rw [mem_comp_comp V_symm, inter_comm, exists_prop], exact iff.rfl, end lemma uniformity_has_basis_closed : has_basis (𝓀 Ξ±) (Ξ» V : set (Ξ± Γ— Ξ±), V ∈ 𝓀 Ξ± ∧ is_closed V) id := begin refine filter.has_basis_self.2 (Ξ» t h, _), rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩, refine ⟨closure w, mem_of_superset w_in subset_closure, is_closed_closure, _⟩, refine subset.trans _ r, rw closure_eq_uniformity, apply Inter_subset_of_subset, apply Inter_subset, exact ⟨w_in, w_symm⟩ end /-- Closed entourages form a basis of the uniformity filter. -/ lemma uniformity_has_basis_closure : has_basis (𝓀 Ξ±) (Ξ» V : set (Ξ± Γ— Ξ±), V ∈ 𝓀 Ξ±) closure := ⟨begin intro t, rw uniformity_has_basis_closed.mem_iff, split, { rintros ⟨r, ⟨r_in, r_closed⟩, r_sub⟩, use [r, r_in], convert r_sub, rw r_closed.closure_eq, refl }, { rintros ⟨r, r_in, r_sub⟩, exact ⟨closure r, ⟨mem_of_superset r_in subset_closure, is_closed_closure⟩, r_sub⟩ } end⟩ lemma closure_eq_inter_uniformity {t : set (Ξ±Γ—Ξ±)} : closure t = (β‹‚ d ∈ 𝓀 Ξ±, d β—‹ (t β—‹ d)) := set.ext $ assume ⟨a, b⟩, calc (a, b) ∈ closure t ↔ (𝓝 (a, b) βŠ“ π“Ÿ t β‰  βŠ₯) : mem_closure_iff_nhds_ne_bot ... ↔ (((@prod.swap Ξ± Ξ±) <$> 𝓀 Ξ±).lift' (Ξ» (s : set (Ξ± Γ— Ξ±)), set.prod {x : Ξ± | (x, a) ∈ s} {y : Ξ± | (b, y) ∈ s}) βŠ“ π“Ÿ t β‰  βŠ₯) : by rw [←uniformity_eq_symm, nhds_eq_uniformity_prod] ... ↔ ((map (@prod.swap Ξ± Ξ±) (𝓀 Ξ±)).lift' (Ξ» (s : set (Ξ± Γ— Ξ±)), set.prod {x : Ξ± | (x, a) ∈ s} {y : Ξ± | (b, y) ∈ s}) βŠ“ π“Ÿ t β‰  βŠ₯) : by refl ... ↔ ((𝓀 Ξ±).lift' (Ξ» (s : set (Ξ± Γ— Ξ±)), set.prod {y : Ξ± | (a, y) ∈ s} {x : Ξ± | (x, b) ∈ s}) βŠ“ π“Ÿ t β‰  βŠ₯) : begin rw [map_lift'_eq2], simp [image_swap_eq_preimage_swap, function.comp], exact monotone_prod monotone_preimage monotone_preimage end ... ↔ (βˆ€s ∈ 𝓀 Ξ±, (set.prod {y : Ξ± | (a, y) ∈ s} {x : Ξ± | (x, b) ∈ s} ∩ t).nonempty) : begin rw [lift'_inf_principal_eq, ← ne_bot_iff, lift'_ne_bot_iff], exact monotone_inter (monotone_prod monotone_preimage monotone_preimage) monotone_const end ... ↔ (βˆ€ s ∈ 𝓀 Ξ±, (a, b) ∈ s β—‹ (t β—‹ s)) : forall_congr $ assume s, forall_congr $ assume hs, ⟨assume ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩, ⟨x, hx, y, hxyt, hy⟩, assume ⟨x, hx, y, hxyt, hy⟩, ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩⟩ ... ↔ _ : by simp lemma uniformity_eq_uniformity_closure : 𝓀 Ξ± = (𝓀 Ξ±).lift' closure := le_antisymm (le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] subset_closure) (calc (𝓀 Ξ±).lift' closure ≀ (𝓀 Ξ±).lift' (Ξ»d, d β—‹ (d β—‹ d)) : lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs) ... ≀ (𝓀 Ξ±) : comp_le_uniformity3) lemma uniformity_eq_uniformity_interior : 𝓀 Ξ± = (𝓀 Ξ±).lift' interior := le_antisymm (le_infi $ assume d, le_infi $ assume hd, let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $ monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs in have s βŠ† interior d, from calc s βŠ† t : hst ... βŠ† interior d : (subset_interior_iff_subset_of_open ht).mpr $ Ξ» x (hx : x ∈ t), let ⟨x, y, h₁, hβ‚‚, hβ‚ƒβŸ© := ht_comp hx in hs_comp ⟨x, h₁, y, hβ‚‚, hβ‚ƒβŸ©, have interior d ∈ 𝓀 Ξ±, by filter_upwards [hs] this, by simp [this]) (assume s hs, ((𝓀 Ξ±).lift' interior).sets_of_superset (mem_lift' hs) interior_subset) lemma interior_mem_uniformity {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : interior s ∈ 𝓀 Ξ± := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs lemma mem_uniformity_is_closed {s : set (Ξ±Γ—Ξ±)} (h : s ∈ 𝓀 Ξ±) : βˆƒt ∈ 𝓀 Ξ±, is_closed t ∧ t βŠ† s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_has_basis_closed.mem_iff.1 h in ⟨t, ht_mem, htc, hts⟩ lemma is_open_iff_open_ball_subset {s : set Ξ±} : is_open s ↔ βˆ€ x ∈ s, βˆƒ V ∈ 𝓀 Ξ±, is_open V ∧ ball x V βŠ† s := begin rw is_open_iff_ball_subset, split; intros h x hx, { obtain ⟨V, hV, hV'⟩ := h x hx, exact ⟨interior V, interior_mem_uniformity hV, is_open_interior, (ball_mono interior_subset x).trans hV'⟩, }, { obtain ⟨V, hV, -, hV'⟩ := h x hx, exact ⟨V, hV, hV'⟩, }, end /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ lemma dense.bUnion_uniformity_ball {s : set Ξ±} {U : set (Ξ± Γ— Ξ±)} (hs : dense s) (hU : U ∈ 𝓀 Ξ±) : (⋃ x ∈ s, ball x U) = univ := begin refine bUnion_eq_univ_iff.2 (Ξ» y, _), rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩, exact ⟨x, hxs, hxy⟩ end /-! ### Uniformity bases -/ /-- Open elements of `𝓀 Ξ±` form a basis of `𝓀 Ξ±`. -/ lemma uniformity_has_basis_open : has_basis (𝓀 Ξ±) (Ξ» V : set (Ξ± Γ— Ξ±), V ∈ 𝓀 Ξ± ∧ is_open V) id := has_basis_self.2 $ Ξ» s hs, ⟨interior s, interior_mem_uniformity hs, is_open_interior, interior_subset⟩ lemma filter.has_basis.mem_uniformity_iff {p : Ξ² β†’ Prop} {s : Ξ² β†’ set (Ξ±Γ—Ξ±)} (h : (𝓀 Ξ±).has_basis p s) {t : set (Ξ± Γ— Ξ±)} : t ∈ 𝓀 Ξ± ↔ βˆƒ i (hi : p i), βˆ€ a b, (a, b) ∈ s i β†’ (a, b) ∈ t := h.mem_iff.trans $ by simp only [prod.forall, subset_def] /-- Symmetric entourages form a basis of `𝓀 Ξ±` -/ lemma uniform_space.has_basis_symmetric : (𝓀 Ξ±).has_basis (Ξ» s : set (Ξ± Γ— Ξ±), s ∈ 𝓀 Ξ± ∧ symmetric_rel s) id := has_basis_self.2 $ Ξ» t t_in, ⟨symmetrize_rel t, symmetrize_mem_uniformity t_in, symmetric_symmetrize_rel t, symmetrize_rel_subset_self t⟩ /-- Open elements `s : set (Ξ± Γ— Ξ±)` of `𝓀 Ξ±` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓀 Ξ±`. -/ lemma uniformity_has_basis_open_symmetric : has_basis (𝓀 Ξ±) (Ξ» V : set (Ξ± Γ— Ξ±), V ∈ 𝓀 Ξ± ∧ is_open V ∧ symmetric_rel V) id := begin simp only [← and_assoc], refine uniformity_has_basis_open.restrict (Ξ» s hs, ⟨symmetrize_rel s, _⟩), exact ⟨⟨symmetrize_mem_uniformity hs.1, is_open.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrize_rel s, symmetrize_rel_subset_self s⟩ end lemma comp_open_symm_mem_uniformity_sets {s : set (Ξ± Γ— Ξ±)} (hs : s ∈ 𝓀 Ξ±) : βˆƒ t ∈ 𝓀 Ξ±, is_open t ∧ symmetric_rel t ∧ t β—‹ t βŠ† s := begin obtain ⟨t, ht₁, htβ‚‚βŸ© := comp_mem_uniformity_sets hs, obtain ⟨u, ⟨hu₁, huβ‚‚, huβ‚ƒβŸ©, huβ‚„ : u βŠ† t⟩ := uniformity_has_basis_open_symmetric.mem_iff.mp ht₁, exact ⟨u, hu₁, huβ‚‚, hu₃, (comp_rel_mono huβ‚„ huβ‚„).trans htβ‚‚βŸ©, end section variable (Ξ±) lemma uniform_space.has_seq_basis [is_countably_generated $ 𝓀 Ξ±] : βˆƒ V : β„• β†’ set (Ξ± Γ— Ξ±), has_antitone_basis (𝓀 Ξ±) (Ξ» _, true) V ∧ βˆ€ n, symmetric_rel (V n) := let ⟨U, hsym, hbasis⟩ := uniform_space.has_basis_symmetric.exists_antitone_subbasis in ⟨U, hbasis, Ξ» n, (hsym n).2⟩ end lemma filter.has_basis.bInter_bUnion_ball {p : ΞΉ β†’ Prop} {U : ΞΉ β†’ set (Ξ± Γ— Ξ±)} (h : has_basis (𝓀 Ξ±) p U) (s : set Ξ±) : (β‹‚ i (hi : p i), ⋃ x ∈ s, ball x (U i)) = closure s := begin ext x, simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball] end /-! ### Uniform continuity -/ /-- A function `f : Ξ± β†’ Ξ²` is *uniformly continuous* if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `Ξ±`. -/ def uniform_continuous [uniform_space Ξ²] (f : Ξ± β†’ Ξ²) := tendsto (Ξ»x:Ξ±Γ—Ξ±, (f x.1, f x.2)) (𝓀 Ξ±) (𝓀 Ξ²) /-- A function `f : Ξ± β†’ Ξ²` is *uniformly continuous* on `s : set Ξ±` if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal while remaining in `s.prod s`. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `s`.-/ def uniform_continuous_on [uniform_space Ξ²] (f : Ξ± β†’ Ξ²) (s : set Ξ±) : Prop := tendsto (Ξ» x : Ξ± Γ— Ξ±, (f x.1, f x.2)) (𝓀 Ξ± βŠ“ principal (s.prod s)) (𝓀 Ξ²) theorem uniform_continuous_def [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} : uniform_continuous f ↔ βˆ€ r ∈ 𝓀 Ξ², { x : Ξ± Γ— Ξ± | (f x.1, f x.2) ∈ r} ∈ 𝓀 Ξ± := iff.rfl theorem uniform_continuous_iff_eventually [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} : uniform_continuous f ↔ βˆ€ r ∈ 𝓀 Ξ², βˆ€αΆ  (x : Ξ± Γ— Ξ±) in 𝓀 Ξ±, (f x.1, f x.2) ∈ r := iff.rfl theorem uniform_continuous_on_univ [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} : uniform_continuous_on f univ ↔ uniform_continuous f := by rw [uniform_continuous_on, uniform_continuous, univ_prod_univ, principal_univ, inf_top_eq] lemma uniform_continuous_of_const [uniform_space Ξ²] {c : Ξ± β†’ Ξ²} (h : βˆ€a b, c a = c b) : uniform_continuous c := have (Ξ» (x : Ξ± Γ— Ξ±), (c (x.fst), c (x.snd))) ⁻¹' id_rel = univ, from eq_univ_iff_forall.2 $ assume ⟨a, b⟩, h a b, le_trans (map_le_iff_le_comap.2 $ by simp [comap_principal, this, univ_mem]) refl_le_uniformity lemma uniform_continuous_id : uniform_continuous (@id Ξ±) := by simp [uniform_continuous]; exact tendsto_id lemma uniform_continuous_const [uniform_space Ξ²] {b : Ξ²} : uniform_continuous (Ξ»a:Ξ±, b) := uniform_continuous_of_const $ Ξ» _ _, rfl lemma uniform_continuous.comp [uniform_space Ξ²] [uniform_space Ξ³] {g : Ξ² β†’ Ξ³} {f : Ξ± β†’ Ξ²} (hg : uniform_continuous g) (hf : uniform_continuous f) : uniform_continuous (g ∘ f) := hg.comp hf lemma filter.has_basis.uniform_continuous_iff [uniform_space Ξ²] {p : Ξ³ β†’ Prop} {s : Ξ³ β†’ set (Ξ±Γ—Ξ±)} (ha : (𝓀 Ξ±).has_basis p s) {q : Ξ΄ β†’ Prop} {t : Ξ΄ β†’ set (Ξ²Γ—Ξ²)} (hb : (𝓀 Ξ²).has_basis q t) {f : Ξ± β†’ Ξ²} : uniform_continuous f ↔ βˆ€ i (hi : q i), βˆƒ j (hj : p j), βˆ€ x y, (x, y) ∈ s j β†’ (f x, f y) ∈ t i := (ha.tendsto_iff hb).trans $ by simp only [prod.forall] lemma filter.has_basis.uniform_continuous_on_iff [uniform_space Ξ²] {p : Ξ³ β†’ Prop} {s : Ξ³ β†’ set (Ξ±Γ—Ξ±)} (ha : (𝓀 Ξ±).has_basis p s) {q : Ξ΄ β†’ Prop} {t : Ξ΄ β†’ set (Ξ²Γ—Ξ²)} (hb : (𝓀 Ξ²).has_basis q t) {f : Ξ± β†’ Ξ²} {S : set Ξ±} : uniform_continuous_on f S ↔ βˆ€ i (hi : q i), βˆƒ j (hj : p j), βˆ€ x y ∈ S, (x, y) ∈ s j β†’ (f x, f y) ∈ t i := ((ha.inf_principal (S.prod S)).tendsto_iff hb).trans $ by finish [prod.forall] end uniform_space open_locale uniformity section constructions instance : partial_order (uniform_space Ξ±) := { le := Ξ»t s, t.uniformity ≀ s.uniformity, le_antisymm := assume t s h₁ hβ‚‚, uniform_space_eq $ le_antisymm h₁ hβ‚‚, le_refl := assume t, le_refl _, le_trans := assume a b c h₁ hβ‚‚, le_trans h₁ hβ‚‚ } instance : has_Inf (uniform_space Ξ±) := ⟨assume s, uniform_space.of_core { uniformity := (β¨…u∈s, @uniformity Ξ± u), refl := le_infi $ assume u, le_infi $ assume hu, u.refl, symm := le_infi $ assume u, le_infi $ assume hu, le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm, comp := le_infi $ assume u, le_infi $ assume hu, le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_refl _) u.comp }⟩ private lemma Inf_le {tt : set (uniform_space Ξ±)} {t : uniform_space Ξ±} (h : t ∈ tt) : Inf tt ≀ t := show (β¨…u∈tt, @uniformity Ξ± u) ≀ t.uniformity, from infi_le_of_le t $ infi_le _ h private lemma le_Inf {tt : set (uniform_space Ξ±)} {t : uniform_space Ξ±} (h : βˆ€t'∈tt, t ≀ t') : t ≀ Inf tt := show t.uniformity ≀ (β¨…u∈tt, @uniformity Ξ± u), from le_infi $ assume t', le_infi $ assume ht', h t' ht' instance : has_top (uniform_space Ξ±) := ⟨uniform_space.of_core { uniformity := ⊀, refl := le_top, symm := le_top, comp := le_top }⟩ instance : has_bot (uniform_space Ξ±) := ⟨{ to_topological_space := βŠ₯, uniformity := π“Ÿ id_rel, refl := le_refl _, symm := by simp [tendsto]; apply subset.refl, comp := begin rw [lift'_principal], {simp}, exact monotone_comp_rel monotone_id monotone_id end, is_open_uniformity := assume s, by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } ⟩ instance : complete_lattice (uniform_space Ξ±) := { sup := Ξ»a b, Inf {x | a ≀ x ∧ b ≀ x}, le_sup_left := Ξ» a b, le_Inf (Ξ» _ ⟨h, _⟩, h), le_sup_right := Ξ» a b, le_Inf (Ξ» _ ⟨_, h⟩, h), sup_le := Ξ» a b c h₁ hβ‚‚, Inf_le ⟨h₁, hβ‚‚βŸ©, inf := Ξ» a b, Inf {a, b}, le_inf := Ξ» a b c h₁ hβ‚‚, le_Inf (Ξ» u h, by { cases h, exact h.symm β–Έ h₁, exact (mem_singleton_iff.1 h).symm β–Έ hβ‚‚ }), inf_le_left := Ξ» a b, Inf_le (by simp), inf_le_right := Ξ» a b, Inf_le (by simp), top := ⊀, le_top := Ξ» a, show a.uniformity ≀ ⊀, from le_top, bot := βŠ₯, bot_le := Ξ» u, u.refl, Sup := Ξ» tt, Inf {t | βˆ€ t' ∈ tt, t' ≀ t}, le_Sup := Ξ» s u h, le_Inf (Ξ» u' h', h' u h), Sup_le := Ξ» s u h, Inf_le h, Inf := Inf, le_Inf := Ξ» s a hs, le_Inf hs, Inf_le := Ξ» s a ha, Inf_le ha, ..uniform_space.partial_order } lemma infi_uniformity {ΞΉ : Sort*} {u : ΞΉ β†’ uniform_space Ξ±} : (infi u).uniformity = (β¨…i, (u i).uniformity) := show (β¨…a (h : βˆƒi:ΞΉ, u i = a), a.uniformity) = _, from le_antisymm (le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ ⟨i, rfl⟩) (le_infi $ assume a, le_infi $ assume ⟨i, (ha : u i = a)⟩, ha β–Έ infi_le _ _) lemma inf_uniformity {u v : uniform_space Ξ±} : (u βŠ“ v).uniformity = u.uniformity βŠ“ v.uniformity := have (u βŠ“ v) = (β¨…i (h : i = u ∨ i = v), i), by simp [infi_or, infi_inf_eq], calc (u βŠ“ v).uniformity = ((β¨…i (h : i = u ∨ i = v), i) : uniform_space Ξ±).uniformity : by rw [this] ... = _ : by simp [infi_uniformity, infi_or, infi_inf_eq] instance inhabited_uniform_space : inhabited (uniform_space Ξ±) := ⟨βŠ₯⟩ instance inhabited_uniform_space_core : inhabited (uniform_space.core Ξ±) := ⟨@uniform_space.to_core _ (default _)⟩ /-- Given `f : Ξ± β†’ Ξ²` and a uniformity `u` on `Ξ²`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `Ξ± Γ— Ξ± β†’ Ξ² Γ— Ξ²`. -/ def uniform_space.comap (f : Ξ± β†’ Ξ²) (u : uniform_space Ξ²) : uniform_space Ξ± := { uniformity := u.uniformity.comap (Ξ»p:Ξ±Γ—Ξ±, (f p.1, f p.2)), to_topological_space := u.to_topological_space.induced f, refl := le_trans (by simp; exact assume ⟨a, b⟩ (h : a = b), h β–Έ rfl) (comap_mono u.refl), symm := by simp [tendsto_comap_iff, prod.swap, (∘)]; exact tendsto_swap_uniformity.comp tendsto_comap, comp := le_trans begin rw [comap_lift'_eq, comap_lift'_eq2], exact (lift'_mono' $ assume s hs ⟨a₁, aβ‚‚βŸ© ⟨x, h₁, hβ‚‚βŸ©, ⟨f x, h₁, hβ‚‚βŸ©), repeat { exact monotone_comp_rel monotone_id monotone_id } end (comap_mono u.comp), is_open_uniformity := Ξ» s, begin change (@is_open Ξ± (u.to_topological_space.induced f) s ↔ _), simp [is_open_iff_nhds, nhds_induced, mem_nhds_uniformity_iff_right, filter.comap, and_comm], refine ball_congr (Ξ» x hx, ⟨_, _⟩), { rintro ⟨t, hts, ht⟩, refine ⟨_, ht, _⟩, rintro ⟨x₁, xβ‚‚βŸ© h rfl, exact hts (h rfl) }, { rintro ⟨t, ht, hts⟩, exact ⟨{y | (f x, y) ∈ t}, Ξ» y hy, @hts (x, y) hy rfl, mem_nhds_uniformity_iff_right.1 $ mem_nhds_left _ ht⟩ } end } lemma uniformity_comap [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} (h : β€Ήuniform_space Ξ±β€Ί = uniform_space.comap f β€Ήuniform_space Ξ²β€Ί) : 𝓀 Ξ± = comap (prod.map f f) (𝓀 Ξ²) := by { rw h, refl } lemma uniform_space_comap_id {Ξ± : Type*} : uniform_space.comap (id : Ξ± β†’ Ξ±) = id := by ext u ; dsimp [uniform_space.comap] ; rw [prod.id_prod, filter.comap_id] lemma uniform_space.comap_comap {Ξ± Ξ² Ξ³} [uΞ³ : uniform_space Ξ³] {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} : uniform_space.comap (g ∘ f) uΞ³ = uniform_space.comap f (uniform_space.comap g uΞ³) := by ext ; dsimp [uniform_space.comap] ; rw filter.comap_comap lemma uniform_continuous_iff {Ξ± Ξ²} [uΞ± : uniform_space Ξ±] [uΞ² : uniform_space Ξ²] {f : Ξ± β†’ Ξ²} : uniform_continuous f ↔ uΞ± ≀ uΞ².comap f := filter.map_le_iff_le_comap lemma uniform_continuous_comap {f : Ξ± β†’ Ξ²} [u : uniform_space Ξ²] : @uniform_continuous Ξ± Ξ² (uniform_space.comap f u) u f := tendsto_comap theorem to_topological_space_comap {f : Ξ± β†’ Ξ²} {u : uniform_space Ξ²} : @uniform_space.to_topological_space _ (uniform_space.comap f u) = topological_space.induced f (@uniform_space.to_topological_space Ξ² u) := rfl lemma uniform_continuous_comap' {f : Ξ³ β†’ Ξ²} {g : Ξ± β†’ Ξ³} [v : uniform_space Ξ²] [u : uniform_space Ξ±] (h : uniform_continuous (f ∘ g)) : @uniform_continuous Ξ± Ξ³ u (uniform_space.comap f v) g := tendsto_comap_iff.2 h lemma to_nhds_mono {u₁ uβ‚‚ : uniform_space Ξ±} (h : u₁ ≀ uβ‚‚) (a : Ξ±) : @nhds _ (@uniform_space.to_topological_space _ u₁) a ≀ @nhds _ (@uniform_space.to_topological_space _ uβ‚‚) a := by rw [@nhds_eq_uniformity Ξ± u₁ a, @nhds_eq_uniformity Ξ± uβ‚‚ a]; exact (lift'_mono h le_rfl) lemma to_topological_space_mono {u₁ uβ‚‚ : uniform_space Ξ±} (h : u₁ ≀ uβ‚‚) : @uniform_space.to_topological_space _ u₁ ≀ @uniform_space.to_topological_space _ uβ‚‚ := le_of_nhds_le_nhds $ to_nhds_mono h lemma uniform_continuous.continuous [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} (hf : uniform_continuous f) : continuous f := continuous_iff_le_induced.mpr $ to_topological_space_mono $ uniform_continuous_iff.1 hf lemma to_topological_space_bot : @uniform_space.to_topological_space Ξ± βŠ₯ = βŠ₯ := rfl lemma to_topological_space_top : @uniform_space.to_topological_space Ξ± ⊀ = ⊀ := top_unique $ assume s hs, s.eq_empty_or_nonempty.elim (assume : s = βˆ…, this.symm β–Έ @is_open_empty _ ⊀) (assume ⟨x, hx⟩, have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl, this.symm β–Έ @is_open_univ _ ⊀) lemma to_topological_space_infi {ΞΉ : Sort*} {u : ΞΉ β†’ uniform_space Ξ±} : (infi u).to_topological_space = β¨…i, (u i).to_topological_space := begin casesI is_empty_or_nonempty ΞΉ, { rw [infi_of_empty, infi_of_empty, to_topological_space_top] }, { refine (eq_of_nhds_eq_nhds $ assume a, _), rw [nhds_infi, nhds_eq_uniformity], change (infi u).uniformity.lift' (preimage $ prod.mk a) = _, rw [infi_uniformity, lift'_infi], { simp only [nhds_eq_uniformity], refl }, { exact assume a b, rfl } }, end lemma to_topological_space_Inf {s : set (uniform_space Ξ±)} : (Inf s).to_topological_space = (β¨…i∈s, @uniform_space.to_topological_space Ξ± i) := begin rw [Inf_eq_infi], simp only [← to_topological_space_infi], end lemma to_topological_space_inf {u v : uniform_space Ξ±} : (u βŠ“ v).to_topological_space = u.to_topological_space βŠ“ v.to_topological_space := by rw [to_topological_space_Inf, infi_pair] instance : uniform_space empty := βŠ₯ instance : uniform_space punit := βŠ₯ instance : uniform_space bool := βŠ₯ instance : uniform_space β„• := βŠ₯ instance : uniform_space β„€ := βŠ₯ instance {p : Ξ± β†’ Prop} [t : uniform_space Ξ±] : uniform_space (subtype p) := uniform_space.comap subtype.val t lemma uniformity_subtype {p : Ξ± β†’ Prop} [t : uniform_space Ξ±] : 𝓀 (subtype p) = comap (Ξ»q:subtype p Γ— subtype p, (q.1.1, q.2.1)) (𝓀 Ξ±) := rfl lemma uniform_continuous_subtype_val {p : Ξ± β†’ Prop} [uniform_space Ξ±] : uniform_continuous (subtype.val : {a : Ξ± // p a} β†’ Ξ±) := uniform_continuous_comap lemma uniform_continuous_subtype_mk {p : Ξ± β†’ Prop} [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ² β†’ Ξ±} (hf : uniform_continuous f) (h : βˆ€x, p (f x)) : uniform_continuous (Ξ»x, ⟨f x, h x⟩ : Ξ² β†’ subtype p) := uniform_continuous_comap' hf lemma uniform_continuous_on_iff_restrict [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} {s : set Ξ±} : uniform_continuous_on f s ↔ uniform_continuous (s.restrict f) := begin unfold uniform_continuous_on set.restrict uniform_continuous tendsto, rw [show (Ξ» x : s Γ— s, (f x.1, f x.2)) = prod.map f f ∘ coe, by ext x; cases x; refl, uniformity_comap rfl, show prod.map subtype.val subtype.val = (coe : s Γ— s β†’ Ξ± Γ— Ξ±), by ext x; cases x; refl], conv in (map _ (comap _ _)) { rw ← filter.map_map }, rw subtype_coe_map_comap_prod, refl, end lemma tendsto_of_uniform_continuous_subtype [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} {s : set Ξ±} {a : Ξ±} (hf : uniform_continuous (Ξ»x:s, f x.val)) (ha : s ∈ 𝓝 a) : tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq Ξ± _ s a (mem_of_mem_nhds ha) ha).symm]; exact tendsto_map' (continuous_iff_continuous_at.mp hf.continuous _) lemma uniform_continuous_on.continuous_on [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β†’ Ξ²} {s : set Ξ±} (h : uniform_continuous_on f s) : continuous_on f s := begin rw uniform_continuous_on_iff_restrict at h, rw continuous_on_iff_continuous_restrict, exact h.continuous end section prod /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance [u₁ : uniform_space Ξ±] [uβ‚‚ : uniform_space Ξ²] : uniform_space (Ξ± Γ— Ξ²) := uniform_space.of_core_eq (u₁.comap prod.fst βŠ“ uβ‚‚.comap prod.snd).to_core prod.topological_space (calc prod.topological_space = (u₁.comap prod.fst βŠ“ uβ‚‚.comap prod.snd).to_topological_space : by rw [to_topological_space_inf, to_topological_space_comap, to_topological_space_comap]; refl ... = _ : by rw [uniform_space.to_core_to_topological_space]) theorem uniformity_prod [uniform_space Ξ±] [uniform_space Ξ²] : 𝓀 (Ξ± Γ— Ξ²) = (𝓀 Ξ±).comap (Ξ»p:(Ξ± Γ— Ξ²) Γ— Ξ± Γ— Ξ², (p.1.1, p.2.1)) βŠ“ (𝓀 Ξ²).comap (Ξ»p:(Ξ± Γ— Ξ²) Γ— Ξ± Γ— Ξ², (p.1.2, p.2.2)) := inf_uniformity lemma uniformity_prod_eq_prod [uniform_space Ξ±] [uniform_space Ξ²] : 𝓀 (Ξ±Γ—Ξ²) = map (Ξ»p:(Ξ±Γ—Ξ±)Γ—(Ξ²Γ—Ξ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓀 Ξ± Γ—αΆ  𝓀 Ξ²) := have map (Ξ»p:(Ξ±Γ—Ξ±)Γ—(Ξ²Γ—Ξ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))) = comap (Ξ»p:(Ξ±Γ—Ξ²)Γ—(Ξ±Γ—Ξ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))), from funext $ assume f, map_eq_comap_of_inverse (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl) (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl), by rw [this, uniformity_prod, filter.prod, comap_inf, comap_comap, comap_comap] lemma mem_map_iff_exists_image' {Ξ± : Type*} {Ξ² : Type*} {f : filter Ξ±} {m : Ξ± β†’ Ξ²} {t : set Ξ²} : t ∈ (map m f).sets ↔ (βˆƒs∈f, m '' s βŠ† t) := mem_map_iff_exists_image lemma mem_uniformity_of_uniform_continuous_invariant [uniform_space Ξ±] {s:set (Ξ±Γ—Ξ±)} {f : Ξ± β†’ Ξ± β†’ Ξ±} (hf : uniform_continuous (Ξ»p:Ξ±Γ—Ξ±, f p.1 p.2)) (hs : s ∈ 𝓀 Ξ±) : βˆƒuβˆˆπ“€ Ξ±, βˆ€a b c, (a, b) ∈ u β†’ (f a c, f b c) ∈ s := begin rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff, (∘)] at hf, rcases mem_map_iff_exists_image'.1 (hf hs) with ⟨t, ht, hts⟩, clear hf, rcases mem_prod_iff.1 ht with ⟨u, hu, v, hv, huvt⟩, clear ht, refine ⟨u, hu, assume a b c hab, hts $ (mem_image _ _ _).2 ⟨⟨⟨a, b⟩, ⟨c, c⟩⟩, huvt ⟨_, _⟩, _⟩⟩, exact hab, exact refl_mem_uniformity hv, refl end lemma mem_uniform_prod [t₁ : uniform_space Ξ±] [tβ‚‚ : uniform_space Ξ²] {a : set (Ξ± Γ— Ξ±)} {b : set (Ξ² Γ— Ξ²)} (ha : a ∈ 𝓀 Ξ±) (hb : b ∈ 𝓀 Ξ²) : {p:(Ξ±Γ—Ξ²)Γ—(Ξ±Γ—Ξ²) | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ (@uniformity (Ξ± Γ— Ξ²) _) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap ha) (preimage_mem_comap hb) lemma tendsto_prod_uniformity_fst [uniform_space Ξ±] [uniform_space Ξ²] : tendsto (Ξ»p:(Ξ±Γ—Ξ²)Γ—(Ξ±Γ—Ξ²), (p.1.1, p.2.1)) (𝓀 (Ξ± Γ— Ξ²)) (𝓀 Ξ±) := le_trans (map_mono (@inf_le_left (uniform_space (Ξ±Γ—Ξ²)) _ _ _)) map_comap_le lemma tendsto_prod_uniformity_snd [uniform_space Ξ±] [uniform_space Ξ²] : tendsto (Ξ»p:(Ξ±Γ—Ξ²)Γ—(Ξ±Γ—Ξ²), (p.1.2, p.2.2)) (𝓀 (Ξ± Γ— Ξ²)) (𝓀 Ξ²) := le_trans (map_mono (@inf_le_right (uniform_space (Ξ±Γ—Ξ²)) _ _ _)) map_comap_le lemma uniform_continuous_fst [uniform_space Ξ±] [uniform_space Ξ²] : uniform_continuous (Ξ»p:Ξ±Γ—Ξ², p.1) := tendsto_prod_uniformity_fst lemma uniform_continuous_snd [uniform_space Ξ±] [uniform_space Ξ²] : uniform_continuous (Ξ»p:Ξ±Γ—Ξ², p.2) := tendsto_prod_uniformity_snd variables [uniform_space Ξ±] [uniform_space Ξ²] [uniform_space Ξ³] lemma uniform_continuous.prod_mk {f₁ : Ξ± β†’ Ξ²} {fβ‚‚ : Ξ± β†’ Ξ³} (h₁ : uniform_continuous f₁) (hβ‚‚ : uniform_continuous fβ‚‚) : uniform_continuous (Ξ»a, (f₁ a, fβ‚‚ a)) := by rw [uniform_continuous, uniformity_prod]; exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 hβ‚‚βŸ© lemma uniform_continuous.prod_mk_left {f : Ξ± Γ— Ξ² β†’ Ξ³} (h : uniform_continuous f) (b) : uniform_continuous (Ξ» a, f (a,b)) := h.comp (uniform_continuous_id.prod_mk uniform_continuous_const) lemma uniform_continuous.prod_mk_right {f : Ξ± Γ— Ξ² β†’ Ξ³} (h : uniform_continuous f) (a) : uniform_continuous (Ξ» b, f (a,b)) := h.comp (uniform_continuous_const.prod_mk uniform_continuous_id) lemma uniform_continuous.prod_map [uniform_space Ξ΄] {f : Ξ± β†’ Ξ³} {g : Ξ² β†’ Ξ΄} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (prod.map f g) := (hf.comp uniform_continuous_fst).prod_mk (hg.comp uniform_continuous_snd) lemma to_topological_space_prod {Ξ±} {Ξ²} [u : uniform_space Ξ±] [v : uniform_space Ξ²] : @uniform_space.to_topological_space (Ξ± Γ— Ξ²) prod.uniform_space = @prod.topological_space Ξ± Ξ² u.to_topological_space v.to_topological_space := rfl end prod section open uniform_space function variables {Ξ΄' : Type*} [uniform_space Ξ±] [uniform_space Ξ²] [uniform_space Ξ³] [uniform_space Ξ΄] [uniform_space Ξ΄'] local notation f `βˆ˜β‚‚` g := function.bicompr f g /-- Uniform continuity for functions of two variables. -/ def uniform_continuousβ‚‚ (f : Ξ± β†’ Ξ² β†’ Ξ³) := uniform_continuous (uncurry f) lemma uniform_continuousβ‚‚_def (f : Ξ± β†’ Ξ² β†’ Ξ³) : uniform_continuousβ‚‚ f ↔ uniform_continuous (uncurry f) := iff.rfl lemma uniform_continuousβ‚‚.uniform_continuous {f : Ξ± β†’ Ξ² β†’ Ξ³} (h : uniform_continuousβ‚‚ f) : uniform_continuous (uncurry f) := h lemma uniform_continuousβ‚‚_curry (f : Ξ± Γ— Ξ² β†’ Ξ³) : uniform_continuousβ‚‚ (function.curry f) ↔ uniform_continuous f := by rw [uniform_continuousβ‚‚, uncurry_curry] lemma uniform_continuousβ‚‚.comp {f : Ξ± β†’ Ξ² β†’ Ξ³} {g : Ξ³ β†’ Ξ΄} (hg : uniform_continuous g) (hf : uniform_continuousβ‚‚ f) : uniform_continuousβ‚‚ (g βˆ˜β‚‚ f) := hg.comp hf lemma uniform_continuousβ‚‚.bicompl {f : Ξ± β†’ Ξ² β†’ Ξ³} {ga : Ξ΄ β†’ Ξ±} {gb : Ξ΄' β†’ Ξ²} (hf : uniform_continuousβ‚‚ f) (hga : uniform_continuous ga) (hgb : uniform_continuous gb) : uniform_continuousβ‚‚ (bicompl f ga gb) := hf.uniform_continuous.comp (hga.prod_map hgb) end lemma to_topological_space_subtype [u : uniform_space Ξ±] {p : Ξ± β†’ Prop} : @uniform_space.to_topological_space (subtype p) subtype.uniform_space = @subtype.topological_space Ξ± p u.to_topological_space := rfl section sum variables [uniform_space Ξ±] [uniform_space Ξ²] open sum /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ def uniform_space.core.sum : uniform_space.core (Ξ± βŠ• Ξ²) := uniform_space.core.mk' (map (Ξ» p : Ξ± Γ— Ξ±, (inl p.1, inl p.2)) (𝓀 Ξ±) βŠ” map (Ξ» p : Ξ² Γ— Ξ², (inr p.1, inr p.2)) (𝓀 Ξ²)) (Ξ» r ⟨H₁, Hβ‚‚βŸ© x, by cases x; [apply refl_mem_uniformity H₁, apply refl_mem_uniformity Hβ‚‚]) (Ξ» r ⟨H₁, Hβ‚‚βŸ©, ⟨symm_le_uniformity H₁, symm_le_uniformity Hβ‚‚βŸ©) (Ξ» r ⟨HrΞ±, Hrβ⟩, begin rcases comp_mem_uniformity_sets HrΞ± with ⟨tΞ±, htΞ±, Htα⟩, rcases comp_mem_uniformity_sets HrΞ² with ⟨tΞ², htΞ², Htβ⟩, refine ⟨_, ⟨mem_map_iff_exists_image.2 ⟨tΞ±, htΞ±, subset_union_left _ _⟩, mem_map_iff_exists_image.2 ⟨tΞ², htΞ², subset_union_right _ _⟩⟩, _⟩, rintros ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩, { have A : (a, c) ∈ tΞ± β—‹ tΞ± := ⟨b, hab, hbc⟩, exact HtΞ± A }, { have A : (a, c) ∈ tΞ² β—‹ tΞ² := ⟨b, hab, hbc⟩, exact HtΞ² A } end) /-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage of the diagonal. -/ lemma union_mem_uniformity_sum {a : set (Ξ± Γ— Ξ±)} (ha : a ∈ 𝓀 Ξ±) {b : set (Ξ² Γ— Ξ²)} (hb : b ∈ 𝓀 Ξ²) : ((Ξ» p : (Ξ± Γ— Ξ±), (inl p.1, inl p.2)) '' a βˆͺ (Ξ» p : (Ξ² Γ— Ξ²), (inr p.1, inr p.2)) '' b) ∈ (@uniform_space.core.sum Ξ± Ξ² _ _).uniformity := ⟨mem_map_iff_exists_image.2 ⟨_, ha, subset_union_left _ _⟩, mem_map_iff_exists_image.2 ⟨_, hb, subset_union_right _ _⟩⟩ /- To prove that the topology defined by the uniform structure on the disjoint union coincides with the disjoint union topology, we need two lemmas saying that open sets can be characterized by the uniform structure -/ lemma uniformity_sum_of_open_aux {s : set (Ξ± βŠ• Ξ²)} (hs : is_open s) {x : Ξ± βŠ• Ξ²} (xs : x ∈ s) : { p : ((Ξ± βŠ• Ξ²) Γ— (Ξ± βŠ• Ξ²)) | p.1 = x β†’ p.2 ∈ s } ∈ (@uniform_space.core.sum Ξ± Ξ² _ _).uniformity := begin cases x, { refine mem_of_superset (union_mem_uniformity_sum (mem_nhds_uniformity_iff_right.1 (is_open.mem_nhds hs.1 xs)) univ_mem) (union_subset _ _); rintro _ ⟨⟨_, b⟩, h, ⟨⟩⟩ ⟨⟩, exact h rfl }, { refine mem_of_superset (union_mem_uniformity_sum univ_mem (mem_nhds_uniformity_iff_right.1 (is_open.mem_nhds hs.2 xs))) (union_subset _ _); rintro _ ⟨⟨a, _⟩, h, ⟨⟩⟩ ⟨⟩, exact h rfl }, end lemma open_of_uniformity_sum_aux {s : set (Ξ± βŠ• Ξ²)} (hs : βˆ€x ∈ s, { p : ((Ξ± βŠ• Ξ²) Γ— (Ξ± βŠ• Ξ²)) | p.1 = x β†’ p.2 ∈ s } ∈ (@uniform_space.core.sum Ξ± Ξ² _ _).uniformity) : is_open s := begin split, { refine (@is_open_iff_mem_nhds Ξ± _ _).2 (Ξ» a ha, mem_nhds_uniformity_iff_right.2 _), rcases mem_map_iff_exists_image.1 (hs _ ha).1 with ⟨t, ht, st⟩, refine mem_of_superset ht _, rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl }, { refine (@is_open_iff_mem_nhds Ξ² _ _).2 (Ξ» b hb, mem_nhds_uniformity_iff_right.2 _), rcases mem_map_iff_exists_image.1 (hs _ hb).2 with ⟨t, ht, st⟩, refine mem_of_superset ht _, rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl } end /- We can now define the uniform structure on the disjoint union -/ instance sum.uniform_space : uniform_space (Ξ± βŠ• Ξ²) := { to_core := uniform_space.core.sum, is_open_uniformity := Ξ» s, ⟨uniformity_sum_of_open_aux, open_of_uniformity_sum_aux⟩ } lemma sum.uniformity : 𝓀 (Ξ± βŠ• Ξ²) = map (Ξ» p : Ξ± Γ— Ξ±, (inl p.1, inl p.2)) (𝓀 Ξ±) βŠ” map (Ξ» p : Ξ² Γ— Ξ², (inr p.1, inr p.2)) (𝓀 Ξ²) := rfl end sum end constructions -- For a version of the Lebesgue number lemma assuming only a sequentially compact space, -- see topology/sequences.lean /-- Let `c : ΞΉ β†’ set Ξ±` be an open cover of a compact set `s`. Then there exists an entourage `n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `c i`. -/ lemma lebesgue_number_lemma {Ξ± : Type u} [uniform_space Ξ±] {s : set Ξ±} {ΞΉ} {c : ΞΉ β†’ set Ξ±} (hs : is_compact s) (hc₁ : βˆ€ i, is_open (c i)) (hcβ‚‚ : s βŠ† ⋃ i, c i) : βˆƒ n ∈ 𝓀 Ξ±, βˆ€ x ∈ s, βˆƒ i, {y | (x, y) ∈ n} βŠ† c i := begin let u := Ξ» n, {x | βˆƒ i (m ∈ 𝓀 Ξ±), {y | (x, y) ∈ m β—‹ n} βŠ† c i}, have hu₁ : βˆ€ n ∈ 𝓀 Ξ±, is_open (u n), { refine Ξ» n hn, is_open_uniformity.2 _, rintro x ⟨i, m, hm, h⟩, rcases comp_mem_uniformity_sets hm with ⟨m', hm', mm'⟩, apply (𝓀 Ξ±).sets_of_superset hm', rintros ⟨x, y⟩ hp rfl, refine ⟨i, m', hm', Ξ» z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)⟩, dsimp at hz ⊒, rw comp_rel_assoc, exact ⟨y, hp, hz⟩ }, have huβ‚‚ : s βŠ† ⋃ n ∈ 𝓀 Ξ±, u n, { intros x hx, rcases mem_Union.1 (hcβ‚‚ hx) with ⟨i, h⟩, rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hc₁ i) x h) with ⟨m', hm', mm'⟩, exact mem_bUnion hm' ⟨i, _, hm', Ξ» y hy, mm' hy rfl⟩ }, rcases hs.elim_finite_subcover_image hu₁ huβ‚‚ with ⟨b, bu, b_fin, b_cover⟩, refine ⟨_, (bInter_mem b_fin).2 bu, Ξ» x hx, _⟩, rcases mem_bUnion_iff.1 (b_cover hx) with ⟨n, bn, i, m, hm, h⟩, refine ⟨i, Ξ» y hy, h _⟩, exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy) end /-- Let `c : set (set Ξ±)` be an open cover of a compact set `s`. Then there exists an entourage `n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `t ∈ c`. -/ lemma lebesgue_number_lemma_sUnion {Ξ± : Type u} [uniform_space Ξ±] {s : set Ξ±} {c : set (set Ξ±)} (hs : is_compact s) (hc₁ : βˆ€ t ∈ c, is_open t) (hcβ‚‚ : s βŠ† ⋃₀ c) : βˆƒ n ∈ 𝓀 Ξ±, βˆ€ x ∈ s, βˆƒ t ∈ c, βˆ€ y, (x, y) ∈ n β†’ y ∈ t := by rw sUnion_eq_Union at hcβ‚‚; simpa using lebesgue_number_lemma hs (by simpa) hcβ‚‚ /-- A useful consequence of the Lebesgue number lemma: given any compact set `K` contained in an open set `U`, we can find an (open) entourage `V` such that the ball of size `V` about any point of `K` is contained in `U`. -/ lemma lebesgue_number_of_compact_open [uniform_space Ξ±] {K U : set Ξ±} (hK : is_compact K) (hU : is_open U) (hKU : K βŠ† U) : βˆƒ V ∈ 𝓀 Ξ±, is_open V ∧ βˆ€ x ∈ K, uniform_space.ball x V βŠ† U := begin let W : K β†’ set (Ξ± Γ— Ξ±) := Ξ» k, classical.some $ is_open_iff_open_ball_subset.mp hU k.1 $ hKU k.2, have hW : βˆ€ k, W k ∈ 𝓀 Ξ± ∧ is_open (W k) ∧ uniform_space.ball k.1 (W k) βŠ† U, { intros k, obtain ⟨h₁, hβ‚‚, hβ‚ƒβŸ© := classical.some_spec (is_open_iff_open_ball_subset.mp hU k.1 (hKU k.2)), exact ⟨h₁, hβ‚‚, hβ‚ƒβŸ©, }, let c : K β†’ set Ξ± := Ξ» k, uniform_space.ball k.1 (W k), have hc₁ : βˆ€ k, is_open (c k), { exact Ξ» k, uniform_space.is_open_ball k.1 (hW k).2.1, }, have hcβ‚‚ : K βŠ† ⋃ i, c i, { intros k hk, simp only [mem_Union, set_coe.exists], exact ⟨k, hk, uniform_space.mem_ball_self k (hW ⟨k, hk⟩).1⟩, }, have hc₃ : βˆ€ k, c k βŠ† U, { exact Ξ» k, (hW k).2.2, }, obtain ⟨V, hV, hV'⟩ := lebesgue_number_lemma hK hc₁ hcβ‚‚, refine ⟨interior V, interior_mem_uniformity hV, is_open_interior, _⟩, intros k hk, obtain ⟨k', hk'⟩ := hV' k hk, exact ((ball_mono interior_subset k).trans hk').trans (hc₃ k'), end /-! ### Expressing continuity properties in uniform spaces We reformulate the various continuity properties of functions taking values in a uniform space in terms of the uniformity in the target. Since the same lemmas (essentially with the same names) also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or the edistance in the target), we put them in a namespace `uniform` here. In the metric and emetric space setting, there are also similar lemmas where one assumes that both the source and the target are metric spaces, reformulating things in terms of the distance on both sides. These lemmas are generally written without primes, and the versions where only the target is a metric space is primed. We follow the same convention here, thus giving lemmas with primes. -/ namespace uniform variables [uniform_space Ξ±] theorem tendsto_nhds_right {f : filter Ξ²} {u : Ξ² β†’ Ξ±} {a : Ξ±} : tendsto u f (𝓝 a) ↔ tendsto (Ξ» x, (a, u x)) f (𝓀 Ξ±) := ⟨λ H, tendsto_left_nhds_uniformity.comp H, Ξ» H s hs, by simpa [mem_of_mem_nhds hs] using H (mem_nhds_uniformity_iff_right.1 hs)⟩ theorem tendsto_nhds_left {f : filter Ξ²} {u : Ξ² β†’ Ξ±} {a : Ξ±} : tendsto u f (𝓝 a) ↔ tendsto (Ξ» x, (u x, a)) f (𝓀 Ξ±) := ⟨λ H, tendsto_right_nhds_uniformity.comp H, Ξ» H s hs, by simpa [mem_of_mem_nhds hs] using H (mem_nhds_uniformity_iff_left.1 hs)⟩ theorem continuous_at_iff'_right [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {b : Ξ²} : continuous_at f b ↔ tendsto (Ξ» x, (f b, f x)) (𝓝 b) (𝓀 Ξ±) := by rw [continuous_at, tendsto_nhds_right] theorem continuous_at_iff'_left [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {b : Ξ²} : continuous_at f b ↔ tendsto (Ξ» x, (f x, f b)) (𝓝 b) (𝓀 Ξ±) := by rw [continuous_at, tendsto_nhds_left] theorem continuous_at_iff_prod [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {b : Ξ²} : continuous_at f b ↔ tendsto (Ξ» x : Ξ² Γ— Ξ², (f x.1, f x.2)) (𝓝 (b, b)) (𝓀 Ξ±) := ⟨λ H, le_trans (H.prod_map' H) (nhds_le_uniformity _), Ξ» H, continuous_at_iff'_left.2 $ H.comp $ tendsto_id.prod_mk_nhds tendsto_const_nhds⟩ theorem continuous_within_at_iff'_right [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {b : Ξ²} {s : set Ξ²} : continuous_within_at f s b ↔ tendsto (Ξ» x, (f b, f x)) (𝓝[s] b) (𝓀 Ξ±) := by rw [continuous_within_at, tendsto_nhds_right] theorem continuous_within_at_iff'_left [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {b : Ξ²} {s : set Ξ²} : continuous_within_at f s b ↔ tendsto (Ξ» x, (f x, f b)) (𝓝[s] b) (𝓀 Ξ±) := by rw [continuous_within_at, tendsto_nhds_left] theorem continuous_on_iff'_right [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {s : set Ξ²} : continuous_on f s ↔ βˆ€ b ∈ s, tendsto (Ξ» x, (f b, f x)) (𝓝[s] b) (𝓀 Ξ±) := by simp [continuous_on, continuous_within_at_iff'_right] theorem continuous_on_iff'_left [topological_space Ξ²] {f : Ξ² β†’ Ξ±} {s : set Ξ²} : continuous_on f s ↔ βˆ€ b ∈ s, tendsto (Ξ» x, (f x, f b)) (𝓝[s] b) (𝓀 Ξ±) := by simp [continuous_on, continuous_within_at_iff'_left] theorem continuous_iff'_right [topological_space Ξ²] {f : Ξ² β†’ Ξ±} : continuous f ↔ βˆ€ b, tendsto (Ξ» x, (f b, f x)) (𝓝 b) (𝓀 Ξ±) := continuous_iff_continuous_at.trans $ forall_congr $ Ξ» b, tendsto_nhds_right theorem continuous_iff'_left [topological_space Ξ²] {f : Ξ² β†’ Ξ±} : continuous f ↔ βˆ€ b, tendsto (Ξ» x, (f x, f b)) (𝓝 b) (𝓀 Ξ±) := continuous_iff_continuous_at.trans $ forall_congr $ Ξ» b, tendsto_nhds_left end uniform lemma filter.tendsto.congr_uniformity {Ξ± Ξ²} [uniform_space Ξ²] {f g : Ξ± β†’ Ξ²} {l : filter Ξ±} {b : Ξ²} (hf : tendsto f l (𝓝 b)) (hg : tendsto (Ξ» x, (f x, g x)) l (𝓀 Ξ²)) : tendsto g l (𝓝 b) := uniform.tendsto_nhds_right.2 $ (uniform.tendsto_nhds_right.1 hf).uniformity_trans hg lemma uniform.tendsto_congr {Ξ± Ξ²} [uniform_space Ξ²] {f g : Ξ± β†’ Ξ²} {l : filter Ξ±} {b : Ξ²} (hfg : tendsto (Ξ» x, (f x, g x)) l (𝓀 Ξ²)) : tendsto f l (𝓝 b) ↔ tendsto g l (𝓝 b) := ⟨λ h, h.congr_uniformity hfg, Ξ» h, h.congr_uniformity hfg.uniformity_symm⟩
e9e92ab2eab2ac4d138eb7205ec9c5fb0f59f1bd
66a6486e19b71391cc438afee5f081a4257564ec
/algebra/free_abelian_group.hlean
d34fef9f25b4f379f098bb83d84941c21f15ee53
[ "Apache-2.0" ]
permissive
spiceghello/Spectral
c8ccd1e32d4b6a9132ccee20fcba44b477cd0331
20023aa3de27c22ab9f9b4a177f5a1efdec2b19f
refs/heads/master
1,611,263,374,078
1,523,349,717,000
1,523,349,717,000
92,312,239
0
0
null
1,495,642,470,000
1,495,642,470,000
null
UTF-8
Lean
false
false
8,772
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Egbert Rijke Constructions with groups -/ import algebra.group_theory hit.set_quotient types.list types.sum .free_group open eq algebra is_trunc set_quotient relation sigma sigma.ops prod sum list trunc function equiv trunc_index group namespace group variables {G G' : Group} {g g' h h' k : G} {A B : AbGroup} variables (X : Type) {Y : Type} [is_set X] [is_set Y] {l l' : list (X ⊎ X)} /- Free Abelian Group of a set -/ namespace free_ab_group inductive fcg_rel : list (X ⊎ X) β†’ list (X ⊎ X) β†’ Type := | rrefl : Ξ l, fcg_rel l l | cancel1 : Ξ x, fcg_rel [inl x, inr x] [] | cancel2 : Ξ x, fcg_rel [inr x, inl x] [] | rflip : Ξ x y, fcg_rel [x, y] [y, x] | resp_append : Ξ {l₁ lβ‚‚ l₃ lβ‚„}, fcg_rel l₁ lβ‚‚ β†’ fcg_rel l₃ lβ‚„ β†’ fcg_rel (l₁ ++ l₃) (lβ‚‚ ++ lβ‚„) | rtrans : Ξ {l₁ lβ‚‚ l₃}, fcg_rel l₁ lβ‚‚ β†’ fcg_rel lβ‚‚ l₃ β†’ fcg_rel l₁ l₃ open fcg_rel local abbreviation R [reducible] := fcg_rel attribute fcg_rel.rrefl [refl] attribute fcg_rel.rtrans [trans] definition fcg_carrier [reducible] : Type := set_quotient (Ξ»x y, βˆ₯R X x yβˆ₯) local abbreviation FG := fcg_carrier definition is_reflexive_R : is_reflexive (Ξ»x y, βˆ₯R X x yβˆ₯) := begin constructor, intro s, apply tr, unfold R end local attribute is_reflexive_R [instance] variable {X} theorem rel_respect_flip (r : R X l l') : R X (map sum.flip l) (map sum.flip l') := begin induction r with l x x x y l₁ lβ‚‚ l₃ lβ‚„ r₁ rβ‚‚ IH₁ IHβ‚‚ l₁ lβ‚‚ l₃ r₁ rβ‚‚ IH₁ IHβ‚‚, { reflexivity}, { repeat esimp [map], exact cancel2 x}, { repeat esimp [map], exact cancel1 x}, { repeat esimp [map], apply rflip}, { rewrite [+map_append], exact resp_append IH₁ IHβ‚‚}, { exact rtrans IH₁ IHβ‚‚} end theorem rel_respect_reverse (r : R X l l') : R X (reverse l) (reverse l') := begin induction r with l x x x y l₁ lβ‚‚ l₃ lβ‚„ r₁ rβ‚‚ IH₁ IHβ‚‚ l₁ lβ‚‚ l₃ r₁ rβ‚‚ IH₁ IHβ‚‚, { reflexivity}, { repeat esimp [map], exact cancel2 x}, { repeat esimp [map], exact cancel1 x}, { repeat esimp [map], apply rflip}, { rewrite [+reverse_append], exact resp_append IHβ‚‚ IH₁}, { exact rtrans IH₁ IHβ‚‚} end theorem rel_cons_concat (l s) : R X (s :: l) (concat s l) := begin induction l with t l IH, { reflexivity}, { rewrite [concat_cons], transitivity (t :: s :: l), { exact resp_append !rflip !rrefl}, { exact resp_append (rrefl [t]) IH}} end definition fcg_one [constructor] : FG X := class_of [] definition fcg_inv [unfold 3] : FG X β†’ FG X := quotient_unary_map (reverse ∘ map sum.flip) (Ξ»l l', trunc_functor -1 (rel_respect_reverse ∘ rel_respect_flip)) definition fcg_mul [unfold 3 4] : FG X β†’ FG X β†’ FG X := quotient_binary_map append (Ξ»l l', trunc.elim (Ξ»r m m', trunc.elim (Ξ»s, tr (resp_append r s)))) section local notation 1 := fcg_one local postfix ⁻¹ := fcg_inv local infix * := fcg_mul theorem fcg_mul_assoc (g₁ gβ‚‚ g₃ : FG X) : g₁ * gβ‚‚ * g₃ = g₁ * (gβ‚‚ * g₃) := begin refine set_quotient.rec_prop _ g₁, refine set_quotient.rec_prop _ gβ‚‚, refine set_quotient.rec_prop _ g₃, clear g₁ gβ‚‚ g₃, intro g₁ gβ‚‚ g₃, exact ap class_of !append.assoc end theorem fcg_one_mul (g : FG X) : 1 * g = g := begin refine set_quotient.rec_prop _ g, clear g, intro g, exact ap class_of !append_nil_left end theorem fcg_mul_one (g : FG X) : g * 1 = g := begin refine set_quotient.rec_prop _ g, clear g, intro g, exact ap class_of !append_nil_right end theorem fcg_mul_left_inv (g : FG X) : g⁻¹ * g = 1 := begin refine set_quotient.rec_prop _ g, clear g, intro g, apply eq_of_rel, apply tr, induction g with s l IH, { reflexivity}, { rewrite [β–Έ*, map_cons, reverse_cons, concat_append], refine rtrans _ IH, apply resp_append, reflexivity, change R X ([flip s, s] ++ l) ([] ++ l), apply resp_append, induction s, apply cancel2, apply cancel1, reflexivity} end theorem fcg_mul_comm (g h : FG X) : g * h = h * g := begin refine set_quotient.rec_prop _ g, clear g, intro g, refine set_quotient.rec_prop _ h, clear h, intro h, apply eq_of_rel, apply tr, revert h, induction g with s l IH: intro h, { rewrite [append_nil_left, append_nil_right]}, { rewrite [append_cons,-concat_append], transitivity concat s (l ++ h), apply rel_cons_concat, rewrite [-append_concat], apply IH} end end end free_ab_group open free_ab_group variables (X) definition group_free_ab_group [constructor] : ab_group (fcg_carrier X) := ab_group.mk _ fcg_mul fcg_mul_assoc fcg_one fcg_one_mul fcg_mul_one fcg_inv fcg_mul_left_inv fcg_mul_comm definition free_ab_group [constructor] : AbGroup := AbGroup.mk _ (group_free_ab_group X) /- The universal property of the free commutative group -/ variables {X A} definition free_ab_group_inclusion [constructor] (x : X) : free_ab_group X := class_of [inl x] theorem fgh_helper_respect_fcg_rel (f : X β†’ A) (r : fcg_rel X l l') : Ξ (g : A), foldl (fgh_helper f) g l = foldl (fgh_helper f) g l' := begin induction r with l x x x y l₁ lβ‚‚ l₃ lβ‚„ r₁ rβ‚‚ IH₁ IHβ‚‚ l₁ lβ‚‚ l₃ r₁ rβ‚‚ IH₁ IHβ‚‚: intro g, { reflexivity}, { unfold [foldl], apply mul_inv_cancel_right}, { unfold [foldl], apply inv_mul_cancel_right}, { unfold [foldl, fgh_helper], apply mul.right_comm}, { rewrite [+foldl_append, IH₁, IHβ‚‚]}, { exact !IH₁ ⬝ !IHβ‚‚} end definition free_ab_group_elim [constructor] (f : X β†’ A) : free_ab_group X β†’g A := begin fapply homomorphism.mk, { intro g, refine set_quotient.elim _ _ g, { intro l, exact foldl (fgh_helper f) 1 l}, { intro l l' r, esimp at *, refine trunc.rec _ r, clear r, intro r, exact fgh_helper_respect_fcg_rel f r 1}}, { refine set_quotient.rec_prop _, intro l, refine set_quotient.rec_prop _, intro l', esimp, refine !foldl_append ⬝ _, esimp, apply fgh_helper_mul} end definition fn_of_free_ab_group_elim [unfold_full] (Ο† : free_ab_group X β†’g A) : X β†’ A := Ο† ∘ free_ab_group_inclusion definition free_ab_group_elim_unique [constructor] (f : X β†’ A) (k : free_ab_group X β†’g A) (H : k ∘ free_ab_group_inclusion ~ f) : k ~ free_ab_group_elim f := begin refine set_quotient.rec_prop _, intro l, esimp, induction l with s l IH, { esimp [foldl], exact to_respect_one k}, { rewrite [foldl_cons, fgh_helper_mul], refine to_respect_mul k (class_of [s]) (class_of l) ⬝ _, rewrite [IH], apply ap (Ξ»x, x * _), induction s: rewrite [β–Έ*, one_mul, -H a], apply to_respect_inv } end variables (X A) definition free_ab_group_elim_equiv_fn [constructor] : (free_ab_group X β†’g A) ≃ (X β†’ A) := begin fapply equiv.MK, { exact fn_of_free_ab_group_elim}, { exact free_ab_group_elim}, { intro f, apply eq_of_homotopy, intro x, esimp, unfold [foldl], apply one_mul}, { intro k, symmetry, apply homomorphism_eq, apply free_ab_group_elim_unique, reflexivity } end definition free_ab_group_functor (f : X β†’ Y) : free_ab_group X β†’g free_ab_group Y := free_ab_group_elim (free_ab_group_inclusion ∘ f) -- set_option pp.all true -- definition free_ab_group.rec {P : free_ab_group X β†’ Type} [H : Ξ g, is_prop (P g)] -- (h₁ : Ξ x, P (free_ab_group_inclusion x)) -- (hβ‚‚ : P 0) -- (h₃ : Ξ g h, P g β†’ P h β†’ P (g * h)) -- (hβ‚„ : Ξ g, P g β†’ P g⁻¹) : -- Ξ g, P g := -- begin -- refine @set_quotient.rec_prop _ _ _ H _, -- refine @set_quotient.rec_prop _ _ _ (Ξ»x, !H) _, -- esimp, intro l, induction l with s l ih, -- exact hβ‚‚, -- induction s with v v, -- induction v with i y, -- exact h₃ _ _ (h₁ i y) ih, -- induction v with i y, -- refine h₃ (gqg_map _ _ (class_of [inr ⟨i, y⟩])) _ _ ih, -- refine transport P _ (h₁ i y⁻¹), -- refine _ ⬝ !mul_one, -- refine _ ⬝ ap (mul _) (to_respect_one (dirsum_incl i)), -- apply gqg_eq_of_rel', -- apply tr, esimp, -- refine transport dirsum_rel _ (dirsum_rel.rmk i y⁻¹ y), -- rewrite [mul.left_inv, mul.assoc], -- apply ap (mul _), -- refine _ ⬝ (mul_inv (class_of [inr ⟨i, y⟩]) (ΞΉ ⟨i, 1⟩))⁻¹ᡖ, -- refine ap011 mul _ _, -- end end group
0b34d3dc9e696a5f1ff9ea9b4a36848464540ca8
1d265c7dd8cb3d0e1d645a19fd6157a2084c3921
/src/chapter_exercises/chap2_exercises.lean
f2a69d416a83dca4c017bca7f2d32885e51d62bd
[ "MIT" ]
permissive
hanzhi713/lean-proofs
de432372f220d302be09b5ca4227f8986567e4fd
4d8356a878645b9ba7cb036f87737f3f1e68ede5
refs/heads/master
1,585,580,245,658
1,553,646,623,000
1,553,646,623,000
151,342,188
0
1
null
null
null
null
UTF-8
Lean
false
false
4,781
lean
-- Exercise 1 -- Define the function Do_Twice, as described in Section 2.4. def double_ (a : β„•) : β„• := a + a def double : β„• β†’ β„• := Ξ» x, x + x def square : β„• β†’ β„• := Ξ» x, x * x def times2plus1 : β„• β†’ β„• := Ξ» x, x * 2 + 1 def do_twice_ (f : β„• β†’ β„•) (x : β„•) : β„• := f (f x) def do_twice : (β„• β†’ β„•) β†’ β„• β†’ β„• := Ξ» f x, f (f x) def do_three_times : (β„• β†’ β„•) β†’ β„• β†’ β„• := Ξ» f x, f (f (f x)) #check do_twice #reduce do_three_times square 2 -- 256 #reduce do_twice square 2 -- 16 def quadruple : β„• β†’ β„• := Ξ» x, do_twice double x #reduce quadruple 2 -- 8 -- Do_Twice -- if (f: (β„• β†’ β„•) β†’ (β„• β†’ β„•)) is a function that applies -- (g : β„• β†’ β„•) on its argument x A times, -- then (Do_Twice f g) applies g on its argument AΒ² times. def Do_Twice (f : (β„• β†’ β„•) β†’ (β„• β†’ β„•)) (x : β„• β†’ β„•) : β„• β†’ β„• := f (f x) def Do_Twice_ : ((β„• β†’ β„•) β†’ (β„• β†’ β„•)) β†’ (β„• β†’ β„•) β†’ (β„• β†’ β„•) := Ξ» f x, f (f x) -- Another version of Do_Twice -- if (f: (β„• β†’ β„•) β†’ (β„• β†’ β„•)) -- is a function that applies (g : β„• β†’ β„•) on its argument A times, -- then (Do_Twice f g) applies g on its argument 2A times. def Do_Twice' : ((β„• β†’ β„•) β†’ (β„• β†’ β„•)) β†’ (β„• β†’ β„•) β†’ (β„• β†’ β„•) := Ξ» f g x, f g (f g x) def Do_Twice'_ (f: (β„• β†’ β„•) β†’ (β„• β†’ β„•)) (g: β„• β†’ β„•) (x : β„•) : β„• := f g (f g x) -- count the number of β„• β†’ β„• being applied, you'll find that there're 3^2=9 of them. #reduce Do_Twice do_three_times -- count the number of β„• β†’ β„• being applied, you'll find that there're 3*2=6 of them. #reduce Do_Twice' do_three_times #reduce Do_Twice do_twice double 2 -- 32 #eval Do_Twice do_twice times2plus1 2 -- 47 #eval Do_Twice do_three_times times2plus1 2 -- 1535 #eval (((((((((2*2)+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1 -- 1535 : (x*2+1) being applied (3^3=9) times #eval Do_Twice do_twice square 2 -- 65536 #reduce do_three_times square 2 -- 256 #eval Do_Twice' do_three_times square 2 -- 18446744073709551616 #eval (((((2^2)^2)^2)^2)^2)^2 -- 18446744073709551616 #eval Do_Twice do_twice square 2 -- 65536 -- Exercise 2 -- Define the functions curry and uncurry, as described in Section 2.4. def compose (Ξ± Ξ² Ξ³ : Type) (g : Ξ² β†’ Ξ³) (f : Ξ± β†’ Ξ²) (x : Ξ±) : Ξ³ := g (f x) def curry (Ξ± Ξ² Ξ³ : Type): (Ξ± Γ— Ξ² β†’ Ξ³) β†’ Ξ± β†’ Ξ² β†’ Ξ³ := Ξ» f a b, f (a, b) def uncurry (Ξ± Ξ² Ξ³ : Type): (Ξ± β†’ Ξ² β†’ Ξ³) β†’ Ξ± Γ— Ξ² β†’ Ξ³ := Ξ» f ⟨a, b⟩, f a b -- Exercise 3 -- Above, we used the example vec Ξ± n for vectors of elements -- of type Ξ± of length n. Declare a constant vec_add that could -- represent a function that adds two vectors of natural numbers -- of the same length, and a constant vec_reverse that can represent -- a function that reverses its argument. -- Use implicit arguments for parameters that can be inferred. -- Declare some variables and check some expressions involving -- the constants that you have declared. universe u constant vec : Type u β†’ β„• β†’ Type u namespace vec constant empty : Ξ  Ξ± : Type u, vec Ξ± 0 constant cons : Ξ  {Ξ± : Type u} {n : β„•}, Ξ± β†’ vec Ξ± n β†’ vec Ξ± (n + 1) constant append : Ξ  (Ξ± : Type u) (n m : β„•), vec Ξ± m β†’ vec Ξ± n β†’ vec Ξ± (n + m) end vec constant vec_add : Ξ  {m : β„•}, vec β„• m β†’ vec β„• m β†’ vec β„• m constant vec_reverse : Ξ  {Ξ± : Type u} {m : β„•}, vec Ξ± m β†’ vec Ξ± m variable vecA : vec β„• 4 variable vecB : vec β„• 4 variable vecC : vec β„• 5 #check vec_add vecA vecB #check vec_reverse vecA #check vec_add (vec.cons 1 vecA) vecC -- Exercise 4 -- Similarly, declare a constant matrix so that matrix Ξ± m n could -- represent the type of m by n matrices. Declare some constants -- to represent functions on this type, such as matrix addition and -- multiplication, and (using vec) multiplication of a matrix by a vector. -- Once again, declare some variables and check some expressions involving -- the constants that you have declared. constant matrix : Type u β†’ β„• β†’ β„• β†’ Type u namespace matrix constant empty : Ξ  Ξ± : Type u, matrix Ξ± 0 0 constant add : Ξ  {Ξ± : Type u} {m n : β„•}, matrix Ξ± m n β†’ matrix Ξ± m n β†’ matrix Ξ± m n constant multiply : Ξ  {Ξ± : Type u} {m n p: β„•}, matrix Ξ± m n β†’ matrix Ξ± n p β†’ matrix Ξ± m p constant multiply_by_vec : Ξ  {Ξ± : Type u} {m n: β„•}, matrix Ξ± m n β†’ vec Ξ± n β†’ vec Ξ± m end matrix variable matA : matrix β„• 5 4 variable matB : matrix β„• 4 3 variable matC : matrix β„• 4 3 #check matrix.add matB matC #check matrix.multiply matA matB #check matrix.multiply_by_vec matA vecA
3bac41a74a43cc08dc1dbc6fe14cfd929a1a4c09
f20db13587f4dd28a4b1fbd31953afd491691fa0
/library/init/meta/smt/interactive.lean
47b6e92151c2dae525d150b96aefa2d96ad839ab
[ "Apache-2.0" ]
permissive
AHartNtkn/lean
9a971edfc6857c63edcbf96bea6841b9a84cf916
0d83a74b26541421fc1aa33044c35b03759710ed
refs/heads/master
1,620,592,591,236
1,516,749,881,000
1,516,749,881,000
118,697,288
1
0
null
1,516,759,470,000
1,516,759,470,000
null
UTF-8
Lean
false
false
9,918
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import init.meta.smt.smt_tactic init.meta.interactive_base import init.meta.smt.rsimp namespace smt_tactic meta def save_info (p : pos) : smt_tactic unit := do (ss, ts) ← smt_tactic.read, tactic.save_info_thunk p (Ξ» _, smt_state.to_format ss ts) meta def skip : smt_tactic unit := return () meta def solve_goals : smt_tactic unit := iterate close meta def step {Ξ± : Type} (tac : smt_tactic Ξ±) : smt_tactic unit := tac >> solve_goals meta def istep {Ξ± : Type} (line0 col0 line col : nat) (tac : smt_tactic Ξ±) : smt_tactic unit := Ξ» ss ts, (@scope_trace _ line col (Ξ» _, (tac >> solve_goals) ss ts)).clamp_pos line0 line col meta def execute (tac : smt_tactic unit) : tactic unit := using_smt tac meta def execute_with (cfg : smt_config) (tac : smt_tactic unit) : tactic unit := using_smt tac cfg namespace interactive open lean.parser open interactive open interactive.types local postfix `?`:9001 := optional local postfix *:9001 := many meta def itactic : Type := smt_tactic unit meta def intros : parse ident* β†’ smt_tactic unit | [] := smt_tactic.intros | hs := smt_tactic.intro_lst hs /-- Try to close main goal by using equalities implied by the congruence closure module. -/ meta def close : smt_tactic unit := smt_tactic.close /-- Produce new facts using heuristic lemma instantiation based on E-matching. This tactic tries to match patterns from lemmas in the main goal with terms in the main goal. The set of lemmas is populated with theorems tagged with the attribute specified at smt_config.em_attr, and lemmas added using tactics such as `smt_tactic.add_lemmas`. The current set of lemmas can be retrieved using the tactic `smt_tactic.get_lemmas`. -/ meta def ematch : smt_tactic unit := smt_tactic.ematch meta def apply (q : parse texpr) : smt_tactic unit := tactic.interactive.apply q meta def fapply (q : parse texpr) : smt_tactic unit := tactic.interactive.fapply q meta def apply_instance : smt_tactic unit := tactic.apply_instance meta def change (q : parse texpr) : smt_tactic unit := tactic.interactive.change q none (loc.ns [none]) meta def exact (q : parse texpr) : smt_tactic unit := tactic.interactive.exact q meta def Β«fromΒ» := exact meta def Β«assumeΒ» := tactic.interactive.assume meta def Β«haveΒ» (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (qβ‚‚ : parse $ (tk ":=" *> texpr)?) : smt_tactic unit := let h := h.get_or_else `this in match q₁, qβ‚‚ with | some e, some p := do t ← tactic.to_expr e, v ← tactic.to_expr ``(%%p : %%t), smt_tactic.assertv h t v | none, some p := do p ← tactic.to_expr p, smt_tactic.note h none p | some e, none := tactic.to_expr e >>= smt_tactic.assert h | none, none := do u ← tactic.mk_meta_univ, e ← tactic.mk_meta_var (expr.sort u), smt_tactic.assert h e end >> return () meta def Β«letΒ» (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (qβ‚‚ : parse $ (tk ":=" *> texpr)?) : smt_tactic unit := let h := h.get_or_else `this in match q₁, qβ‚‚ with | some e, some p := do t ← tactic.to_expr e, v ← tactic.to_expr ``(%%p : %%t), smt_tactic.definev h t v | none, some p := do p ← tactic.to_expr p, smt_tactic.pose h none p | some e, none := tactic.to_expr e >>= smt_tactic.define h | none, none := do u ← tactic.mk_meta_univ, e ← tactic.mk_meta_var (expr.sort u), smt_tactic.define h e end >> return () meta def add_fact (q : parse texpr) : smt_tactic unit := do h ← tactic.get_unused_name `h none, p ← tactic.to_expr_strict q, smt_tactic.note h none p meta def trace_state : smt_tactic unit := smt_tactic.trace_state meta def trace {Ξ± : Type} [has_to_tactic_format Ξ±] (a : Ξ±) : smt_tactic unit := tactic.trace a meta def destruct (q : parse texpr) : smt_tactic unit := do p ← tactic.to_expr_strict q, smt_tactic.destruct p meta def by_cases (q : parse texpr) : smt_tactic unit := do p ← tactic.to_expr_strict q, smt_tactic.by_cases p meta def by_contradiction : smt_tactic unit := smt_tactic.by_contradiction meta def by_contra : smt_tactic unit := smt_tactic.by_contradiction open tactic (resolve_name transparency to_expr) private meta def report_invalid_em_lemma {Ξ± : Type} (n : name) : smt_tactic Ξ± := fail format!"invalid ematch lemma '{n}'" private meta def add_lemma_name (md : transparency) (lhs_lemma : bool) (n : name) (ref : pexpr) : smt_tactic unit := do p ← resolve_name n, match p with | expr.const n _ := (add_ematch_lemma_from_decl_core md lhs_lemma n >> tactic.save_const_type_info n ref) <|> report_invalid_em_lemma n | _ := (do e ← to_expr p, add_ematch_lemma_core md lhs_lemma e >> try (tactic.save_type_info e ref)) <|> report_invalid_em_lemma n end private meta def add_lemma_pexpr (md : transparency) (lhs_lemma : bool) (p : pexpr) : smt_tactic unit := match p with | (expr.const c []) := add_lemma_name md lhs_lemma c p | (expr.local_const c _ _ _) := add_lemma_name md lhs_lemma c p | _ := do new_e ← to_expr p, add_ematch_lemma_core md lhs_lemma new_e end private meta def add_lemma_pexprs (md : transparency) (lhs_lemma : bool) : list pexpr β†’ smt_tactic unit | [] := return () | (p::ps) := add_lemma_pexpr md lhs_lemma p >> add_lemma_pexprs ps meta def add_lemma (l : parse pexpr_list_or_texpr) : smt_tactic unit := add_lemma_pexprs reducible ff l meta def add_lhs_lemma (l : parse pexpr_list_or_texpr) : smt_tactic unit := add_lemma_pexprs reducible tt l private meta def add_eqn_lemmas_for_core (md : transparency) : list name β†’ smt_tactic unit | [] := return () | (c::cs) := do p ← resolve_name c, match p with | expr.const n _ := add_ematch_eqn_lemmas_for_core md n >> add_eqn_lemmas_for_core cs | _ := fail format!"'{c}' is not a constant" end meta def add_eqn_lemmas_for (ids : parse ident*) : smt_tactic unit := add_eqn_lemmas_for_core reducible ids meta def add_eqn_lemmas (ids : parse ident*) : smt_tactic unit := add_eqn_lemmas_for ids private meta def add_hinst_lemma_from_name (md : transparency) (lhs_lemma : bool) (n : name) (hs : hinst_lemmas) (ref : pexpr) : smt_tactic hinst_lemmas := do p ← resolve_name n, match p with | expr.const n _ := (do h ← hinst_lemma.mk_from_decl_core md n lhs_lemma, tactic.save_const_type_info n ref, return $ hs.add h) <|> (do hs₁ ← mk_ematch_eqn_lemmas_for_core md n, tactic.save_const_type_info n ref, return $ hs.merge hs₁) <|> report_invalid_em_lemma n | _ := (do e ← to_expr p, h ← hinst_lemma.mk_core md e lhs_lemma, try (tactic.save_type_info e ref), return $ hs.add h) <|> report_invalid_em_lemma n end private meta def add_hinst_lemma_from_pexpr (md : transparency) (lhs_lemma : bool) (p : pexpr) (hs : hinst_lemmas) : smt_tactic hinst_lemmas := match p with | (expr.const c []) := add_hinst_lemma_from_name md lhs_lemma c hs p | (expr.local_const c _ _ _) := add_hinst_lemma_from_name md lhs_lemma c hs p | _ := do new_e ← to_expr p, h ← hinst_lemma.mk_core md new_e lhs_lemma, return $ hs.add h end private meta def add_hinst_lemmas_from_pexprs (md : transparency) (lhs_lemma : bool) : list pexpr β†’ hinst_lemmas β†’ smt_tactic hinst_lemmas | [] hs := return hs | (p::ps) hs := do hs₁ ← add_hinst_lemma_from_pexpr md lhs_lemma p hs, add_hinst_lemmas_from_pexprs ps hs₁ meta def ematch_using (l : parse pexpr_list_or_texpr) : smt_tactic unit := do hs ← add_hinst_lemmas_from_pexprs reducible ff l hinst_lemmas.mk, smt_tactic.ematch_using hs /-- Try the given tactic, and do nothing if it fails. -/ meta def try (t : itactic) : smt_tactic unit := smt_tactic.try t /-- Keep applying the given tactic until it fails. -/ meta def iterate (t : itactic) : smt_tactic unit := smt_tactic.iterate t /-- Apply the given tactic to all remaining goals. -/ meta def all_goals (t : itactic) : smt_tactic unit := smt_tactic.all_goals t meta def induction (p : parse tactic.interactive.cases_arg_p) (rec_name : parse using_ident) (ids : parse with_ident_list) (revert : parse $ (tk "generalizing" *> ident*)?) : smt_tactic unit := slift (tactic.interactive.induction p rec_name ids revert) open tactic /-- Simplify the target type of the main goal. -/ meta def simp (use_iota_eqn : parse $ (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (cfg : simp_config_ext := {}) : smt_tactic unit := tactic.interactive.simp use_iota_eqn no_dflt hs attr_names (loc.ns [none]) cfg meta def dsimp (no_dflt : parse only_flag) (es : parse simp_arg_list) (attr_names : parse with_ident_list) : smt_tactic unit := tactic.interactive.dsimp no_dflt es attr_names (loc.ns [none]) meta def rsimp : smt_tactic unit := do ccs ← to_cc_state, _root_.rsimp.rsimplify_goal ccs meta def add_simp_lemmas : smt_tactic unit := get_hinst_lemmas_for_attr `rsimp_attr >>= add_lemmas /-- Keep applying heuristic instantiation until the current goal is solved, or it fails. -/ meta def eblast : smt_tactic unit := smt_tactic.eblast /-- Keep applying heuristic instantiation using the given lemmas until the current goal is solved, or it fails. -/ meta def eblast_using (l : parse pexpr_list_or_texpr) : smt_tactic unit := do hs ← add_hinst_lemmas_from_pexprs reducible ff l hinst_lemmas.mk, smt_tactic.iterate (smt_tactic.ematch_using hs >> smt_tactic.try smt_tactic.close) meta def guard_expr_eq (t : expr) (p : parse $ tk ":=" *> texpr) : smt_tactic unit := do e ← to_expr p, guard (expr.alpha_eqv t e) meta def guard_target (p : parse texpr) : smt_tactic unit := do t ← target, guard_expr_eq t p end interactive end smt_tactic
c25dedc9abd0d36ab24c0c8717c9769998f0cd0d
46125763b4dbf50619e8846a1371029346f4c3db
/src/data/nat/basic.lean
39fe31339475f5227aad115408393a41dae89b1d
[ "Apache-2.0" ]
permissive
thjread/mathlib
a9d97612cedc2c3101060737233df15abcdb9eb1
7cffe2520a5518bba19227a107078d83fa725ddc
refs/heads/master
1,615,637,696,376
1,583,953,063,000
1,583,953,063,000
246,680,271
0
0
Apache-2.0
1,583,960,875,000
1,583,960,875,000
null
UTF-8
Lean
false
false
56,515
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import logic.basic algebra.ordered_ring data.option.basic algebra.order_functions /-! # Basic operations on the natural numbers This files has some basic lemmas about natural numbers, definition of the `choice` function, and extra recursors: * `le_rec_on`, `le_induction`: recursion and induction principles starting at non-zero numbers. * `decreasing_induction` : recursion gowing downwards. * `strong_rec'` : recursion based on strong inequalities. -/ universes u v namespace nat variables {m n k : β„•} -- Sometimes a bare `nat.add` or similar appears as a consequence of unfolding -- during pattern matching. These lemmas package them back up as typeclass -- mediated operations. @[simp] theorem add_def {a b : β„•} : nat.add a b = a + b := rfl @[simp] theorem mul_def {a b : β„•} : nat.mul a b = a * b := rfl attribute [simp] nat.add_sub_cancel nat.add_sub_cancel_left attribute [simp] nat.sub_self @[simp] lemma succ_pos' {n : β„•} : 0 < succ n := succ_pos n theorem succ_inj' {n m : β„•} : succ n = succ m ↔ n = m := ⟨succ_inj, congr_arg _⟩ theorem succ_le_succ_iff {m n : β„•} : succ m ≀ succ n ↔ m ≀ n := ⟨le_of_succ_le_succ, succ_le_succ⟩ lemma zero_max {m : nat} : max 0 m = m := max_eq_right (zero_le _) theorem max_succ_succ {m n : β„•} : max (succ m) (succ n) = succ (max m n) := begin by_cases h1 : m ≀ n, rw [max_eq_right h1, max_eq_right (succ_le_succ h1)], { rw not_le at h1, have h2 := le_of_lt h1, rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] } end lemma not_succ_lt_self {n : β„•} : Β¬succ n < n := not_lt_of_ge (nat.le_succ _) theorem lt_succ_iff {m n : β„•} : m < succ n ↔ m ≀ n := succ_le_succ_iff lemma succ_le_iff {m n : β„•} : succ m ≀ n ↔ m < n := ⟨lt_of_succ_le, succ_le_of_lt⟩ lemma lt_iff_add_one_le {m n : β„•} : m < n ↔ m + 1 ≀ n := by rw succ_le_iff -- Just a restatement of `nat.lt_succ_iff` using `+1`. lemma lt_add_one_iff {a b : β„•} : a < b + 1 ↔ a ≀ b := lt_succ_iff -- A flipped version of `lt_add_one_iff`. lemma lt_one_add_iff {a b : β„•} : a < 1 + b ↔ a ≀ b := by simp only [add_comm, lt_succ_iff] -- This is true reflexively, by the definition of `≀` on β„•, -- but it's still useful to have, to convince Lean to change the syntactic type. lemma add_one_le_iff {a b : β„•} : a + 1 ≀ b ↔ a < b := iff.refl _ lemma one_add_le_iff {a b : β„•} : 1 + a ≀ b ↔ a < b := by simp only [add_comm, add_one_le_iff] theorem of_le_succ {n m : β„•} (H : n ≀ m.succ) : n ≀ m ∨ n = m.succ := (lt_or_eq_of_le H).imp le_of_lt_succ id /-- Recursion starting at a non-zero number: given a map `C k β†’ C (k+1)` for each `k`, there is a map from `C n` to each `C m`, `n ≀ m`. -/ @[elab_as_eliminator] def le_rec_on {C : β„• β†’ Sort u} {n : β„•} : Ξ  {m : β„•}, n ≀ m β†’ (Ξ  {k}, C k β†’ C (k+1)) β†’ C n β†’ C m | 0 H next x := eq.rec_on (eq_zero_of_le_zero H) x | (m+1) H next x := or.by_cases (of_le_succ H) (Ξ» h : n ≀ m, next $ le_rec_on h @next x) (Ξ» h : n = m + 1, eq.rec_on h x) theorem le_rec_on_self {C : β„• β†’ Sort u} {n} {h : n ≀ n} {next} (x : C n) : (le_rec_on h next x : C n) = x := by cases n; unfold le_rec_on or.by_cases; rw [dif_neg n.not_succ_le_self, dif_pos rfl] theorem le_rec_on_succ {C : β„• β†’ Sort u} {n m} (h1 : n ≀ m) {h2 : n ≀ m+1} {next} (x : C n) : (le_rec_on h2 @next x : C (m+1)) = next (le_rec_on h1 @next x : C m) := by conv { to_lhs, rw [le_rec_on, or.by_cases, dif_pos h1] } theorem le_rec_on_succ' {C : β„• β†’ Sort u} {n} {h : n ≀ n+1} {next} (x : C n) : (le_rec_on h next x : C (n+1)) = next x := by rw [le_rec_on_succ (le_refl n), le_rec_on_self] theorem le_rec_on_trans {C : β„• β†’ Sort u} {n m k} (hnm : n ≀ m) (hmk : m ≀ k) {next} (x : C n) : (le_rec_on (le_trans hnm hmk) @next x : C k) = le_rec_on hmk @next (le_rec_on hnm @next x) := begin induction hmk with k hmk ih, { rw le_rec_on_self }, rw [le_rec_on_succ (le_trans hnm hmk), ih, le_rec_on_succ] end theorem le_rec_on_succ_left {C : β„• β†’ Sort u} {n m} (h1 : n ≀ m) (h2 : n+1 ≀ m) {next : Ξ {{k}}, C k β†’ C (k+1)} (x : C n) : (le_rec_on h2 next (next x) : C m) = (le_rec_on h1 next x : C m) := begin rw [subsingleton.elim h1 (le_trans (le_succ n) h2), le_rec_on_trans (le_succ n) h2, le_rec_on_succ'] end theorem le_rec_on_injective {C : β„• β†’ Sort u} {n m} (hnm : n ≀ m) (next : Ξ  n, C n β†’ C (n+1)) (Hnext : βˆ€ n, function.injective (next n)) : function.injective (le_rec_on hnm next) := begin induction hnm with m hnm ih, { intros x y H, rwa [le_rec_on_self, le_rec_on_self] at H }, intros x y H, rw [le_rec_on_succ hnm, le_rec_on_succ hnm] at H, exact ih (Hnext _ H) end theorem le_rec_on_surjective {C : β„• β†’ Sort u} {n m} (hnm : n ≀ m) (next : Ξ  n, C n β†’ C (n+1)) (Hnext : βˆ€ n, function.surjective (next n)) : function.surjective (le_rec_on hnm next) := begin induction hnm with m hnm ih, { intros x, use x, rw le_rec_on_self }, intros x, rcases Hnext _ x with ⟨w, rfl⟩, rcases ih w with ⟨x, rfl⟩, use x, rw le_rec_on_succ end theorem pred_eq_of_eq_succ {m n : β„•} (H : m = n.succ) : m.pred = n := by simp [H] @[simp] lemma pred_eq_succ_iff {n m : β„•} : pred n = succ m ↔ n = m + 2 := by cases n; split; rintro ⟨⟩; refl theorem pred_sub (n m : β„•) : pred n - m = pred (n - m) := by rw [← sub_one, nat.sub_sub, one_add]; refl lemma pred_eq_sub_one (n : β„•) : pred n = n - 1 := rfl lemma one_le_of_lt {n m : β„•} (h : n < m) : 1 ≀ m := lt_of_le_of_lt (nat.zero_le _) h lemma le_pred_of_lt {n m : β„•} (h : m < n) : m ≀ n - 1 := nat.sub_le_sub_right h 1 lemma le_of_pred_lt {m n : β„•} : pred m < n β†’ m ≀ n := match m with | 0 := le_of_lt | m+1 := id end /-- This ensures that `simp` succeeds on `pred (n + 1) = n`. -/ @[simp] lemma pred_one_add (n : β„•) : pred (1 + n) = n := by rw [add_comm, add_one, pred_succ] theorem pos_iff_ne_zero : 0 < n ↔ n β‰  0 := ⟨ne_of_gt, nat.pos_of_ne_zero⟩ lemma one_lt_iff_ne_zero_and_ne_one : βˆ€ {n : β„•}, 1 < n ↔ n β‰  0 ∧ n β‰  1 | 0 := dec_trivial | 1 := dec_trivial | (n+2) := dec_trivial theorem eq_of_lt_succ_of_not_lt {a b : β„•} (h1 : a < b + 1) (h2 : Β¬ a < b) : a = b := have h3 : a ≀ b, from le_of_lt_succ h1, or.elim (eq_or_lt_of_not_lt h2) (Ξ» h, h) (Ξ» h, absurd h (not_lt_of_ge h3)) protected theorem le_sub_add (n m : β„•) : n ≀ n - m + m := or.elim (le_total n m) (assume : n ≀ m, begin rw [sub_eq_zero_of_le this, zero_add], exact this end) (assume : m ≀ n, begin rw (nat.sub_add_cancel this) end) theorem sub_add_eq_max (n m : β„•) : n - m + m = max n m := eq_max (nat.le_sub_add _ _) (le_add_left _ _) $ Ξ» k h₁ hβ‚‚, by rw ← nat.sub_add_cancel hβ‚‚; exact add_le_add_right (nat.sub_le_sub_right h₁ _) _ theorem sub_add_min (n m : β„•) : n - m + min n m = n := (le_total n m).elim (Ξ» h, by rw [min_eq_left h, sub_eq_zero_of_le h, zero_add]) (Ξ» h, by rw [min_eq_right h, nat.sub_add_cancel h]) protected theorem add_sub_cancel' {n m : β„•} (h : m ≀ n) : m + (n - m) = n := by rw [add_comm, nat.sub_add_cancel h] protected theorem sub_eq_of_eq_add (h : k = m + n) : k - m = n := begin rw [h, nat.add_sub_cancel_left] end theorem sub_cancel {a b c : β„•} (h₁ : a ≀ b) (hβ‚‚ : a ≀ c) (w : b - a = c - a) : b = c := by rw [←nat.sub_add_cancel h₁, ←nat.sub_add_cancel hβ‚‚, w] lemma sub_sub_sub_cancel_right {a b c : β„•} (hβ‚‚ : c ≀ b) : (a - c) - (b - c) = a - b := by rw [nat.sub_sub, ←nat.add_sub_assoc hβ‚‚, nat.add_sub_cancel_left] lemma add_sub_cancel_right (n m k : β„•) : n + (m + k) - k = n + m := by { rw [nat.add_sub_assoc, nat.add_sub_cancel], apply k.le_add_left } protected lemma sub_add_eq_add_sub {a b c : β„•} (h : b ≀ a) : (a - b) + c = (a + c) - b := by rw [add_comm a, nat.add_sub_assoc h, add_comm] theorem sub_min (n m : β„•) : n - min n m = n - m := nat.sub_eq_of_eq_add $ by rw [add_comm, sub_add_min] theorem sub_sub_assoc {a b c : β„•} (h₁ : b ≀ a) (hβ‚‚ : c ≀ b) : a - (b - c) = a - b + c := (nat.sub_eq_iff_eq_add (le_trans (nat.sub_le _ _) h₁)).2 $ by rw [add_right_comm, add_assoc, nat.sub_add_cancel hβ‚‚, nat.sub_add_cancel h₁] protected theorem lt_of_sub_pos (h : 0 < n - m) : m < n := lt_of_not_ge (assume : n ≀ m, have n - m = 0, from sub_eq_zero_of_le this, begin rw this at h, exact lt_irrefl _ h end) protected theorem lt_of_sub_lt_sub_right : m - k < n - k β†’ m < n := lt_imp_lt_of_le_imp_le (Ξ» h, nat.sub_le_sub_right h _) protected theorem lt_of_sub_lt_sub_left : m - n < m - k β†’ k < n := lt_imp_lt_of_le_imp_le (nat.sub_le_sub_left _) protected theorem sub_lt_self (h₁ : 0 < m) (hβ‚‚ : 0 < n) : m - n < m := calc m - n = succ (pred m) - succ (pred n) : by rw [succ_pred_eq_of_pos h₁, succ_pred_eq_of_pos hβ‚‚] ... = pred m - pred n : by rw succ_sub_succ ... ≀ pred m : sub_le _ _ ... < succ (pred m) : lt_succ_self _ ... = m : succ_pred_eq_of_pos h₁ protected theorem le_sub_right_of_add_le (h : m + k ≀ n) : m ≀ n - k := by rw ← nat.add_sub_cancel m k; exact nat.sub_le_sub_right h k protected theorem le_sub_left_of_add_le (h : k + m ≀ n) : m ≀ n - k := nat.le_sub_right_of_add_le (by rwa add_comm at h) protected theorem lt_sub_right_of_add_lt (h : m + k < n) : m < n - k := lt_of_succ_le $ nat.le_sub_right_of_add_le $ by rw succ_add; exact succ_le_of_lt h protected theorem lt_sub_left_of_add_lt (h : k + m < n) : m < n - k := nat.lt_sub_right_of_add_lt (by rwa add_comm at h) protected theorem add_lt_of_lt_sub_right (h : m < n - k) : m + k < n := @nat.lt_of_sub_lt_sub_right _ _ k (by rwa nat.add_sub_cancel) protected theorem add_lt_of_lt_sub_left (h : m < n - k) : k + m < n := by rw add_comm; exact nat.add_lt_of_lt_sub_right h protected theorem le_add_of_sub_le_right : n - k ≀ m β†’ n ≀ m + k := le_imp_le_of_lt_imp_lt nat.lt_sub_right_of_add_lt protected theorem le_add_of_sub_le_left : n - k ≀ m β†’ n ≀ k + m := le_imp_le_of_lt_imp_lt nat.lt_sub_left_of_add_lt protected theorem lt_add_of_sub_lt_right : n - k < m β†’ n < m + k := lt_imp_lt_of_le_imp_le nat.le_sub_right_of_add_le protected theorem lt_add_of_sub_lt_left : n - k < m β†’ n < k + m := lt_imp_lt_of_le_imp_le nat.le_sub_left_of_add_le protected theorem sub_le_left_of_le_add : n ≀ k + m β†’ n - k ≀ m := le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_left protected theorem sub_le_right_of_le_add : n ≀ m + k β†’ n - k ≀ m := le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_right protected theorem sub_lt_left_iff_lt_add (H : n ≀ k) : k - n < m ↔ k < n + m := ⟨nat.lt_add_of_sub_lt_left, Ξ» h₁, have succ k ≀ n + m, from succ_le_of_lt h₁, have succ (k - n) ≀ m, from calc succ (k - n) = succ k - n : by rw (succ_sub H) ... ≀ n + m - n : nat.sub_le_sub_right this n ... = m : by rw nat.add_sub_cancel_left, lt_of_succ_le this⟩ protected theorem le_sub_left_iff_add_le (H : m ≀ k) : n ≀ k - m ↔ m + n ≀ k := le_iff_le_iff_lt_iff_lt.2 (nat.sub_lt_left_iff_lt_add H) protected theorem le_sub_right_iff_add_le (H : n ≀ k) : m ≀ k - n ↔ m + n ≀ k := by rw [nat.le_sub_left_iff_add_le H, add_comm] protected theorem lt_sub_left_iff_add_lt : n < k - m ↔ m + n < k := ⟨nat.add_lt_of_lt_sub_left, nat.lt_sub_left_of_add_lt⟩ protected theorem lt_sub_right_iff_add_lt : m < k - n ↔ m + n < k := by rw [nat.lt_sub_left_iff_add_lt, add_comm] theorem sub_le_left_iff_le_add : m - n ≀ k ↔ m ≀ n + k := le_iff_le_iff_lt_iff_lt.2 nat.lt_sub_left_iff_add_lt theorem sub_le_right_iff_le_add : m - k ≀ n ↔ m ≀ n + k := by rw [nat.sub_le_left_iff_le_add, add_comm] protected theorem sub_lt_right_iff_lt_add (H : k ≀ m) : m - k < n ↔ m < n + k := by rw [nat.sub_lt_left_iff_lt_add H, add_comm] protected theorem sub_le_sub_left_iff (H : k ≀ m) : m - n ≀ m - k ↔ k ≀ n := ⟨λ h, have k + (m - k) - n ≀ m - k, by rwa nat.add_sub_cancel' H, nat.le_of_add_le_add_right (nat.le_add_of_sub_le_left this), nat.sub_le_sub_left _⟩ protected theorem sub_lt_sub_right_iff (H : k ≀ m) : m - k < n - k ↔ m < n := lt_iff_lt_of_le_iff_le (nat.sub_le_sub_right_iff _ _ _ H) protected theorem sub_lt_sub_left_iff (H : n ≀ m) : m - n < m - k ↔ k < n := lt_iff_lt_of_le_iff_le (nat.sub_le_sub_left_iff H) protected theorem sub_le_iff : m - n ≀ k ↔ m - k ≀ n := nat.sub_le_left_iff_le_add.trans nat.sub_le_right_iff_le_add.symm protected lemma sub_le_self (n m : β„•) : n - m ≀ n := nat.sub_le_left_of_le_add (nat.le_add_left _ _) protected theorem sub_lt_iff (h₁ : n ≀ m) (hβ‚‚ : k ≀ m) : m - n < k ↔ m - k < n := (nat.sub_lt_left_iff_lt_add h₁).trans (nat.sub_lt_right_iff_lt_add hβ‚‚).symm lemma pred_le_iff {n m : β„•} : pred n ≀ m ↔ n ≀ succ m := @nat.sub_le_right_iff_le_add n m 1 lemma lt_pred_iff {n m : β„•} : n < pred m ↔ succ n < m := @nat.lt_sub_right_iff_add_lt n 1 m protected theorem mul_ne_zero {n m : β„•} (n0 : n β‰  0) (m0 : m β‰  0) : n * m β‰  0 | nm := (eq_zero_of_mul_eq_zero nm).elim n0 m0 @[simp] protected theorem mul_eq_zero {a b : β„•} : a * b = 0 ↔ a = 0 ∨ b = 0 := iff.intro eq_zero_of_mul_eq_zero (by simp [or_imp_distrib] {contextual := tt}) @[simp] protected theorem zero_eq_mul {a b : β„•} : 0 = a * b ↔ a = 0 ∨ b = 0 := by rw [eq_comm, nat.mul_eq_zero] lemma eq_zero_of_double_le {a : β„•} (h : 2 * a ≀ a) : a = 0 := nat.eq_zero_of_le_zero $ by rwa [two_mul, nat.add_le_to_le_sub, nat.sub_self] at h; refl lemma eq_zero_of_mul_le {a b : β„•} (hb : 2 ≀ b) (h : b * a ≀ a) : a = 0 := eq_zero_of_double_le $ le_trans (nat.mul_le_mul_right _ hb) h lemma le_mul_of_pos_left {m n : β„•} (h : 0 < n) : m ≀ n * m := begin conv {to_lhs, rw [← one_mul(m)]}, exact mul_le_mul_of_nonneg_right (nat.succ_le_of_lt h) dec_trivial, end lemma le_mul_of_pos_right {m n : β„•} (h : 0 < n) : m ≀ m * n := begin conv {to_lhs, rw [← mul_one(m)]}, exact mul_le_mul_of_nonneg_left (nat.succ_le_of_lt h) dec_trivial, end theorem two_mul_ne_two_mul_add_one {n m} : 2 * n β‰  2 * m + 1 := mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial) /-- Recursion principle based on `<`. -/ @[elab_as_eliminator] protected def strong_rec' {p : β„• β†’ Sort u} (H : βˆ€ n, (βˆ€ m, m < n β†’ p m) β†’ p n) : βˆ€ (n : β„•), p n | n := H n (Ξ» m hm, strong_rec' m) attribute [simp] nat.div_self protected lemma div_le_of_le_mul' {m n : β„•} {k} (h : m ≀ k * n) : m / k ≀ n := (eq_zero_or_pos k).elim (Ξ» k0, by rw [k0, nat.div_zero]; apply zero_le) (Ξ» k0, (decidable.mul_le_mul_left k0).1 $ calc k * (m / k) ≀ m % k + k * (m / k) : le_add_left _ _ ... = m : mod_add_div _ _ ... ≀ k * n : h) protected lemma div_le_self' (m n : β„•) : m / n ≀ m := (eq_zero_or_pos n).elim (Ξ» n0, by rw [n0, nat.div_zero]; apply zero_le) (Ξ» n0, nat.div_le_of_le_mul' $ calc m = 1 * m : (one_mul _).symm ... ≀ n * m : mul_le_mul_right _ n0) theorem le_div_iff_mul_le' {x y : β„•} {k : β„•} (k0 : 0 < k) : x ≀ y / k ↔ x * k ≀ y := begin revert x, refine nat.strong_rec' _ y, clear y, intros y IH x, cases decidable.lt_or_le y k with h h, { rw [div_eq_of_lt h], cases x with x, { simp [zero_mul, zero_le] }, { rw succ_mul, exact iff_of_false (not_succ_le_zero _) (not_le_of_lt $ lt_of_lt_of_le h (le_add_left _ _)) } }, { rw [div_eq_sub_div k0 h], cases x with x, { simp [zero_mul, zero_le] }, { rw [← add_one, nat.add_le_add_iff_le_right, succ_mul, IH _ (sub_lt_of_pos_le _ _ k0 h), add_le_to_le_sub _ h] } } end theorem div_mul_le_self' (m n : β„•) : m / n * n ≀ m := (nat.eq_zero_or_pos n).elim (Ξ» n0, by simp [n0, zero_le]) $ Ξ» n0, (le_div_iff_mul_le' n0).1 (le_refl _) theorem div_lt_iff_lt_mul' {x y : β„•} {k : β„•} (k0 : 0 < k) : x / k < y ↔ x < y * k := lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le' k0 protected theorem div_le_div_right {n m : β„•} (h : n ≀ m) {k : β„•} : n / k ≀ m / k := (nat.eq_zero_or_pos k).elim (Ξ» k0, by simp [k0]) $ Ξ» hk, (le_div_iff_mul_le' hk).2 $ le_trans (nat.div_mul_le_self' _ _) h lemma lt_of_div_lt_div {m n k : β„•} (h : m / k < n / k) : m < n := by_contradiction $ Ξ» h₁, absurd h (not_lt_of_ge (nat.div_le_div_right (not_lt.1 h₁))) protected theorem eq_mul_of_div_eq_right {a b c : β„•} (H1 : b ∣ a) (H2 : a / b = c) : a = b * c := by rw [← H2, nat.mul_div_cancel' H1] protected theorem div_eq_iff_eq_mul_right {a b c : β„•} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = b * c := ⟨nat.eq_mul_of_div_eq_right H', nat.div_eq_of_eq_mul_right H⟩ protected theorem div_eq_iff_eq_mul_left {a b c : β„•} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = c * b := by rw mul_comm; exact nat.div_eq_iff_eq_mul_right H H' protected theorem eq_mul_of_div_eq_left {a b c : β„•} (H1 : b ∣ a) (H2 : a / b = c) : a = c * b := by rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2] protected theorem mul_div_cancel_left' {a b : β„•} (Hd : a ∣ b) : a * (b / a) = b := by rw [mul_comm,nat.div_mul_cancel Hd] protected theorem div_mod_unique {n k m d : β„•} (h : 0 < k) : n / k = d ∧ n % k = m ↔ m + k * d = n ∧ m < k := ⟨λ ⟨e₁, eβ‚‚βŸ©, e₁ β–Έ eβ‚‚ β–Έ ⟨mod_add_div _ _, mod_lt _ h⟩, Ξ» ⟨h₁, hβ‚‚βŸ©, h₁ β–Έ by rw [add_mul_div_left _ _ h, add_mul_mod_self_left]; simp [div_eq_of_lt, mod_eq_of_lt, hβ‚‚]⟩ lemma two_mul_odd_div_two {n : β„•} (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 := by conv {to_rhs, rw [← nat.mod_add_div n 2, hn, nat.add_sub_cancel_left]} lemma div_dvd_of_dvd {a b : β„•} (h : b ∣ a) : (a / b) ∣ a := ⟨b, (nat.div_mul_cancel h).symm⟩ protected lemma div_pos {a b : β„•} (hba : b ≀ a) (hb : 0 < b) : 0 < a / b := nat.pos_of_ne_zero (Ξ» h, lt_irrefl a (calc a = a % b : by simpa [h] using (mod_add_div a b).symm ... < b : nat.mod_lt a hb ... ≀ a : hba)) protected theorem mul_right_inj {a b c : β„•} (ha : 0 < a) : b * a = c * a ↔ b = c := ⟨nat.eq_of_mul_eq_mul_right ha, Ξ» e, e β–Έ rfl⟩ protected theorem mul_left_inj {a b c : β„•} (ha : 0 < a) : a * b = a * c ↔ b = c := ⟨nat.eq_of_mul_eq_mul_left ha, Ξ» e, e β–Έ rfl⟩ protected lemma div_div_self : βˆ€ {a b : β„•}, b ∣ a β†’ 0 < a β†’ a / (a / b) = b | a 0 h₁ hβ‚‚ := by rw eq_zero_of_zero_dvd h₁; refl | 0 b h₁ hβ‚‚ := absurd hβ‚‚ dec_trivial | (a+1) (b+1) h₁ hβ‚‚ := (nat.mul_right_inj (nat.div_pos (le_of_dvd (succ_pos a) h₁) (succ_pos b))).1 $ by rw [nat.div_mul_cancel (div_dvd_of_dvd h₁), nat.mul_div_cancel' h₁] protected lemma div_lt_of_lt_mul {m n k : β„•} (h : m < n * k) : m / n < k := lt_of_mul_lt_mul_left (calc n * (m / n) ≀ m % n + n * (m / n) : nat.le_add_left _ _ ... = m : mod_add_div _ _ ... < n * k : h) (nat.zero_le n) lemma lt_mul_of_div_lt {a b c : β„•} (h : a / c < b) (w : 0 < c) : a < b * c := lt_of_not_ge $ not_le_of_gt h ∘ (nat.le_div_iff_mul_le _ _ w).2 protected lemma div_eq_zero_iff {a b : β„•} (hb : 0 < b) : a / b = 0 ↔ a < b := ⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb, Ξ» h, by rw [← nat.mul_left_inj hb, ← @add_left_cancel_iff _ _ (a % b), mod_add_div, mod_eq_of_lt h, mul_zero, add_zero]⟩ lemma eq_zero_of_le_div {a b : β„•} (hb : 2 ≀ b) (h : a ≀ a / b) : a = 0 := eq_zero_of_mul_le hb $ by rw mul_comm; exact (nat.le_div_iff_mul_le' (lt_of_lt_of_le dec_trivial hb)).1 h lemma mul_div_le_mul_div_assoc (a b c : β„•) : a * (b / c) ≀ (a * b) / c := if hc0 : c = 0 then by simp [hc0] else (nat.le_div_iff_mul_le _ _ (nat.pos_of_ne_zero hc0)).2 (by rw [mul_assoc]; exact mul_le_mul_left _ (nat.div_mul_le_self _ _)) lemma div_mul_div_le_div (a b c : β„•) : ((a / c) * b) / a ≀ b / c := if ha0 : a = 0 then by simp [ha0] else calc a / c * b / a ≀ b * a / c / a : nat.div_le_div_right (by rw [mul_comm]; exact mul_div_le_mul_div_assoc _ _ _) ... = b / c : by rw [nat.div_div_eq_div_mul, mul_comm b, mul_comm c, nat.mul_div_mul _ _ (nat.pos_of_ne_zero ha0)] lemma eq_zero_of_le_half {a : β„•} (h : a ≀ a / 2) : a = 0 := eq_zero_of_le_div (le_refl _) h lemma mod_mul_right_div_self (a b c : β„•) : a % (b * c) / b = (a / b) % c := if hb : b = 0 then by simp [hb] else if hc : c = 0 then by simp [hc] else by conv {to_rhs, rw ← mod_add_div a (b * c)}; rw [mul_assoc, nat.add_mul_div_left _ _ (nat.pos_of_ne_zero hb), add_mul_mod_self_left, mod_eq_of_lt (nat.div_lt_of_lt_mul (mod_lt _ (mul_pos (nat.pos_of_ne_zero hb) (nat.pos_of_ne_zero hc))))] lemma mod_mul_left_div_self (a b c : β„•) : a % (c * b) / b = (a / b) % c := by rw [mul_comm c, mod_mul_right_div_self] /- The `n+1`-st triangle number is `n` more than the `n`-th triangle number -/ lemma triangle_succ (n : β„•) : (n + 1) * ((n + 1) - 1) / 2 = n * (n - 1) / 2 + n := begin rw [← add_mul_div_left, mul_comm 2 n, ← mul_add, nat.add_sub_cancel, mul_comm], cases n; refl, apply zero_lt_succ end @[simp] protected theorem dvd_one {n : β„•} : n ∣ 1 ↔ n = 1 := ⟨eq_one_of_dvd_one, Ξ» e, e.symm β–Έ dvd_refl _⟩ protected theorem dvd_add_left {k m n : β„•} (h : k ∣ n) : k ∣ m + n ↔ k ∣ m := (nat.dvd_add_iff_left h).symm protected theorem dvd_add_right {k m n : β„•} (h : k ∣ m) : k ∣ m + n ↔ k ∣ n := (nat.dvd_add_iff_right h).symm /-- A natural number m divides the sum m + n if and only if m divides b.-/ @[simp] protected lemma dvd_add_self_left {m n : β„•} : m ∣ m + n ↔ m ∣ n := nat.dvd_add_right (dvd_refl m) /-- A natural number m divides the sum n + m if and only if m divides b.-/ @[simp] protected lemma dvd_add_self_right {m n : β„•} : m ∣ n + m ↔ m ∣ n := nat.dvd_add_left (dvd_refl m) protected theorem mul_dvd_mul_iff_left {a b c : β„•} (ha : 0 < a) : a * b ∣ a * c ↔ b ∣ c := exists_congr $ Ξ» d, by rw [mul_assoc, nat.mul_left_inj ha] protected theorem mul_dvd_mul_iff_right {a b c : β„•} (hc : 0 < c) : a * c ∣ b * c ↔ a ∣ b := exists_congr $ Ξ» d, by rw [mul_right_comm, nat.mul_right_inj hc] lemma succ_div : βˆ€ (a b : β„•), (a + 1) / b = a / b + if b ∣ a + 1 then 1 else 0 | a 0 := by simp | 0 1 := rfl | 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial, by simp [ne_of_gt hb2, div_eq_of_lt hb2] | (a+1) (b+1) := begin rw [nat.div_def], conv_rhs { rw nat.div_def }, by_cases hb_eq_a : b = a + 1, { simp [hb_eq_a, le_refl] }, by_cases hb_le_a1 : b ≀ a + 1, { have hb_le_a : b ≀ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a), have h₁ : (0 < b + 1 ∧ b + 1 ≀ a + 1 + 1), from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩, have hβ‚‚ : (0 < b + 1 ∧ b + 1 ≀ a + 1), from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩, have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1, { rw [nat.dvd_add_iff_left (dvd_refl (b + 1)), ← nat.add_sub_add_right a 1 b, add_comm (_ - _), add_assoc, nat.sub_add_cancel (succ_le_succ hb_le_a), add_comm 1] }, have wf : a - b < a + 1, from lt_succ_of_le (nat.sub_le_self _ _), rw [if_pos h₁, if_pos hβ‚‚, nat.add_sub_add_right, nat.sub_add_comm hb_le_a, by exact have _ := wf, succ_div (a - b), nat.add_sub_add_right], simp [dvd_iff, succ_eq_add_one, add_comm 1], congr }, { have hba : Β¬ b ≀ a, from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)), have hb_dvd_a : Β¬ b + 1 ∣ a + 2, from Ξ» h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)), simp [hba, hb_le_a1, hb_dvd_a], } end lemma succ_div_of_dvd {a b : β„•} (hba : b ∣ a + 1) : (a + 1) / b = a / b + 1 := by rw [succ_div, if_pos hba] lemma succ_div_of_not_dvd {a b : β„•} (hba : Β¬ b ∣ a + 1) : (a + 1) / b = a / b := by rw [succ_div, if_neg hba, add_zero] @[simp] theorem mod_mod_of_dvd (n : nat) {m k : nat} (h : m ∣ k) : n % k % m = n % m := begin conv { to_rhs, rw ←mod_add_div n k }, rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left] end @[simp] theorem mod_mod (a n : β„•) : (a % n) % n = a % n := (eq_zero_or_pos n).elim (Ξ» n0, by simp [n0]) (Ξ» npos, mod_eq_of_lt (mod_lt _ npos)) theorem add_pos_left {m : β„•} (h : 0 < m) (n : β„•) : 0 < m + n := calc m + n > 0 + n : nat.add_lt_add_right h n ... = n : nat.zero_add n ... β‰₯ 0 : zero_le n theorem add_pos_right (m : β„•) {n : β„•} (h : 0 < n) : 0 < m + n := begin rw add_comm, exact add_pos_left h m end theorem add_pos_iff_pos_or_pos (m n : β„•) : 0 < m + n ↔ 0 < m ∨ 0 < n := iff.intro begin intro h, cases m with m, {simp [zero_add] at h, exact or.inr h}, exact or.inl (succ_pos _) end begin intro h, cases h with mpos npos, { apply add_pos_left mpos }, apply add_pos_right _ npos end lemma add_eq_one_iff : βˆ€ {a b : β„•}, a + b = 1 ↔ (a = 0 ∧ b = 1) ∨ (a = 1 ∧ b = 0) | 0 0 := dec_trivial | 0 1 := dec_trivial | 1 0 := dec_trivial | 1 1 := dec_trivial | (a+2) _ := by rw add_right_comm; exact dec_trivial | _ (b+2) := by rw [← add_assoc]; simp only [nat.succ_inj', nat.succ_ne_zero]; simp lemma mul_eq_one_iff : βˆ€ {a b : β„•}, a * b = 1 ↔ a = 1 ∧ b = 1 | 0 0 := dec_trivial | 0 1 := dec_trivial | 1 0 := dec_trivial | (a+2) 0 := by simp | 0 (b+2) := by simp | (a+1) (b+1) := ⟨λ h, by simp only [add_mul, mul_add, mul_add, one_mul, mul_one, (add_assoc _ _ _).symm, nat.succ_inj', add_eq_zero_iff] at h; simp [h.1.2, h.2], by clear_aux_decl; finish⟩ lemma mul_right_eq_self_iff {a b : β„•} (ha : 0 < a) : a * b = a ↔ b = 1 := suffices a * b = a * 1 ↔ b = 1, by rwa mul_one at this, nat.mul_left_inj ha lemma mul_left_eq_self_iff {a b : β„•} (hb : 0 < b) : a * b = b ↔ a = 1 := by rw [mul_comm, nat.mul_right_eq_self_iff hb] lemma lt_succ_iff_lt_or_eq {n i : β„•} : n < i.succ ↔ (n < i ∨ n = i) := lt_succ_iff.trans le_iff_lt_or_eq theorem le_zero_iff {i : β„•} : i ≀ 0 ↔ i = 0 := ⟨nat.eq_zero_of_le_zero, assume h, h β–Έ le_refl i⟩ theorem le_add_one_iff {i j : β„•} : i ≀ j + 1 ↔ (i ≀ j ∨ i = j + 1) := ⟨assume h, match nat.eq_or_lt_of_le h with | or.inl h := or.inr h | or.inr h := or.inl $ nat.le_of_succ_le_succ h end, or.rec (assume h, le_trans h $ nat.le_add_right _ _) le_of_eq⟩ theorem mul_self_inj {n m : β„•} : n * n = m * m ↔ n = m := le_antisymm_iff.trans (le_antisymm_iff.trans (and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm instance decidable_ball_lt (n : nat) (P : Ξ  k < n, Prop) : βˆ€ [H : βˆ€ n h, decidable (P n h)], decidable (βˆ€ n h, P n h) := begin induction n with n IH; intro; resetI, { exact is_true (Ξ» n, dec_trivial) }, cases IH (Ξ» k h, P k (lt_succ_of_lt h)) with h, { refine is_false (mt _ h), intros hn k h, apply hn }, by_cases p : P n (lt_succ_self n), { exact is_true (Ξ» k h', (lt_or_eq_of_le $ le_of_lt_succ h').elim (h _) (Ξ» e, match k, e, h' with _, rfl, h := p end)) }, { exact is_false (mt (Ξ» hn, hn _ _) p) } end instance decidable_forall_fin {n : β„•} (P : fin n β†’ Prop) [H : decidable_pred P] : decidable (βˆ€ i, P i) := decidable_of_iff (βˆ€ k h, P ⟨k, h⟩) ⟨λ a ⟨k, h⟩, a k h, Ξ» a k h, a ⟨k, h⟩⟩ instance decidable_ball_le (n : β„•) (P : Ξ  k ≀ n, Prop) [H : βˆ€ n h, decidable (P n h)] : decidable (βˆ€ n h, P n h) := decidable_of_iff (βˆ€ k (h : k < succ n), P k (le_of_lt_succ h)) ⟨λ a k h, a k (lt_succ_of_le h), Ξ» a k h, a k _⟩ instance decidable_lo_hi (lo hi : β„•) (P : β„• β†’ Prop) [H : decidable_pred P] : decidable (βˆ€x, lo ≀ x β†’ x < hi β†’ P x) := decidable_of_iff (βˆ€ x < hi - lo, P (lo + x)) ⟨λal x hl hh, by have := al (x - lo) (lt_of_not_ge $ (not_congr (nat.sub_le_sub_right_iff _ _ _ hl)).2 $ not_le_of_gt hh); rwa [nat.add_sub_of_le hl] at this, Ξ»al x h, al _ (nat.le_add_right _ _) (nat.add_lt_of_lt_sub_left h)⟩ instance decidable_lo_hi_le (lo hi : β„•) (P : β„• β†’ Prop) [H : decidable_pred P] : decidable (βˆ€x, lo ≀ x β†’ x ≀ hi β†’ P x) := decidable_of_iff (βˆ€x, lo ≀ x β†’ x < hi + 1 β†’ P x) $ ball_congr $ Ξ» x hl, imp_congr lt_succ_iff iff.rfl protected theorem bit0_le {n m : β„•} (h : n ≀ m) : bit0 n ≀ bit0 m := add_le_add h h protected theorem bit1_le {n m : β„•} (h : n ≀ m) : bit1 n ≀ bit1 m := succ_le_succ (add_le_add h h) theorem bit_le : βˆ€ (b : bool) {n m : β„•}, n ≀ m β†’ bit b n ≀ bit b m | tt n m h := nat.bit1_le h | ff n m h := nat.bit0_le h theorem bit_ne_zero (b) {n} (h : n β‰  0) : bit b n β‰  0 := by cases b; [exact nat.bit0_ne_zero h, exact nat.bit1_ne_zero _] theorem bit0_le_bit : βˆ€ (b) {m n : β„•}, m ≀ n β†’ bit0 m ≀ bit b n | tt m n h := le_of_lt $ nat.bit0_lt_bit1 h | ff m n h := nat.bit0_le h theorem bit_le_bit1 : βˆ€ (b) {m n : β„•}, m ≀ n β†’ bit b m ≀ bit1 n | ff m n h := le_of_lt $ nat.bit0_lt_bit1 h | tt m n h := nat.bit1_le h theorem bit_lt_bit0 : βˆ€ (b) {n m : β„•}, n < m β†’ bit b n < bit0 m | tt n m h := nat.bit1_lt_bit0 h | ff n m h := nat.bit0_lt h theorem bit_lt_bit (a b) {n m : β„•} (h : n < m) : bit a n < bit b m := lt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ (le_refl _)) lemma pos_of_bit0_pos {n : β„•} (h : 0 < bit0 n) : 0 < n := by { cases n, cases h, apply succ_pos, } /- partial subtraction -/ /-- Partial predecessor operation. Returns `ppred n = some m` if `n = m + 1`, otherwise `none`. -/ @[simp] def ppred : β„• β†’ option β„• | 0 := none | (n+1) := some n /-- Partial subtraction operation. Returns `psub m n = some k` if `m = n + k`, otherwise `none`. -/ @[simp] def psub (m : β„•) : β„• β†’ option β„• | 0 := some m | (n+1) := psub n >>= ppred theorem pred_eq_ppred (n : β„•) : pred n = (ppred n).get_or_else 0 := by cases n; refl theorem sub_eq_psub (m : β„•) : βˆ€ n, m - n = (psub m n).get_or_else 0 | 0 := rfl | (n+1) := (pred_eq_ppred (m-n)).trans $ by rw [sub_eq_psub, psub]; cases psub m n; refl @[simp] theorem ppred_eq_some {m : β„•} : βˆ€ {n}, ppred n = some m ↔ succ m = n | 0 := by split; intro h; contradiction | (n+1) := by dsimp; split; intro h; injection h; subst n @[simp] theorem ppred_eq_none : βˆ€ {n : β„•}, ppred n = none ↔ n = 0 | 0 := by simp | (n+1) := by dsimp; split; contradiction theorem psub_eq_some {m : β„•} : βˆ€ {n k}, psub m n = some k ↔ k + n = m | 0 k := by simp [eq_comm] | (n+1) k := begin dsimp, apply option.bind_eq_some.trans, simp [psub_eq_some, add_comm, add_left_comm, nat.succ_eq_add_one] end theorem psub_eq_none (m n : β„•) : psub m n = none ↔ m < n := begin cases s : psub m n; simp [eq_comm], { show m < n, refine lt_of_not_ge (Ξ» h, _), cases le.dest h with k e, injection s.symm.trans (psub_eq_some.2 $ (add_comm _ _).trans e) }, { show n ≀ m, rw ← psub_eq_some.1 s, apply le_add_left } end theorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) := ppred_eq_some.2 $ succ_pred_eq_of_pos h theorem psub_eq_sub {m n} (h : n ≀ m) : psub m n = some (m - n) := psub_eq_some.2 $ nat.sub_add_cancel h theorem psub_add (m n k) : psub m (n + k) = do x ← psub m n, psub x k := by induction k; simp [*, add_succ, bind_assoc] /- pow -/ attribute [simp] nat.pow_zero nat.pow_one @[simp] lemma one_pow : βˆ€ n : β„•, 1 ^ n = 1 | 0 := rfl | (k+1) := show 1^k * 1 = 1, by rw [mul_one, one_pow] theorem pow_add (a m n : β„•) : a^(m + n) = a^m * a^n := by induction n; simp [*, pow_succ, mul_assoc] theorem pow_two (a : β„•) : a ^ 2 = a * a := show (1 * a) * a = _, by rw one_mul theorem pow_dvd_pow (a : β„•) {m n : β„•} (h : m ≀ n) : a^m ∣ a^n := by rw [← nat.add_sub_cancel' h, pow_add]; apply dvd_mul_right theorem pow_dvd_pow_of_dvd {a b : β„•} (h : a ∣ b) : βˆ€ n:β„•, a^n ∣ b^n | 0 := dvd_refl _ | (n+1) := mul_dvd_mul (pow_dvd_pow_of_dvd n) h theorem mul_pow (a b n : β„•) : (a * b) ^ n = a ^ n * b ^ n := by induction n; simp [*, nat.pow_succ, mul_comm, mul_assoc, mul_left_comm] protected theorem pow_mul (a b n : β„•) : n ^ (a * b) = (n ^ a) ^ b := by induction b; simp [*, nat.succ_eq_add_one, nat.pow_add, mul_add, mul_comm] theorem pow_pos {p : β„•} (hp : 0 < p) : βˆ€ n : β„•, 0 < p ^ n | 0 := by simp | (k+1) := mul_pos (pow_pos _) hp lemma pow_eq_mul_pow_sub (p : β„•) {m n : β„•} (h : m ≀ n) : p ^ m * p ^ (n - m) = p ^ n := by rw [←nat.pow_add, nat.add_sub_cancel' h] lemma pow_lt_pow_succ {p : β„•} (h : 1 < p) (n : β„•) : p^n < p^(n+1) := suffices p^n*1 < p^n*p, by simpa, nat.mul_lt_mul_of_pos_left h (nat.pow_pos (lt_of_succ_lt h) n) lemma lt_pow_self {p : β„•} (h : 1 < p) : βˆ€ n : β„•, n < p ^ n | 0 := by simp [zero_lt_one] | (n+1) := calc n + 1 < p^n + 1 : nat.add_lt_add_right (lt_pow_self _) _ ... ≀ p ^ (n+1) : pow_lt_pow_succ h _ lemma pow_right_strict_mono {x : β„•} (k : 2 ≀ x) : strict_mono (nat.pow x) := Ξ» _ _, pow_lt_pow_of_lt_right k lemma pow_le_iff_le_right {x m n : β„•} (k : 2 ≀ x) : x^m ≀ x^n ↔ m ≀ n := strict_mono.le_iff_le (pow_right_strict_mono k) lemma pow_lt_iff_lt_right {x m n : β„•} (k : 2 ≀ x) : x^m < x^n ↔ m < n := strict_mono.lt_iff_lt (pow_right_strict_mono k) lemma pow_right_injective {x : β„•} (k : 2 ≀ x) : function.injective (nat.pow x) := strict_mono.injective (pow_right_strict_mono k) lemma pow_left_strict_mono {m : β„•} (k : 1 ≀ m) : strict_mono (Ξ» (x : β„•), x^m) := Ξ» _ _ h, pow_lt_pow_of_lt_left h k lemma pow_le_iff_le_left {m x y : β„•} (k : 1 ≀ m) : x^m ≀ y^m ↔ x ≀ y := strict_mono.le_iff_le (pow_left_strict_mono k) lemma pow_lt_iff_lt_left {m x y : β„•} (k : 1 ≀ m) : x^m < y^m ↔ x < y := strict_mono.lt_iff_lt (pow_left_strict_mono k) lemma pow_left_injective {m : β„•} (k : 1 ≀ m) : function.injective (Ξ» (x : β„•), x^m) := strict_mono.injective (pow_left_strict_mono k) lemma not_pos_pow_dvd : βˆ€ {p k : β„•} (hp : 1 < p) (hk : 1 < k), Β¬ p^k ∣ p | (succ p) (succ k) hp hk h := have (succ p)^k * succ p ∣ 1 * succ p, by simpa, have (succ p) ^ k ∣ 1, from dvd_of_mul_dvd_mul_right (succ_pos _) this, have he : (succ p) ^ k = 1, from eq_one_of_dvd_one this, have k < (succ p) ^ k, from lt_pow_self hp k, have k < 1, by rwa [he] at this, have k = 0, from eq_zero_of_le_zero $ le_of_lt_succ this, have 1 < 1, by rwa [this] at hk, absurd this dec_trivial @[simp] theorem bodd_div2_eq (n : β„•) : bodd_div2 n = (bodd n, div2 n) := by unfold bodd div2; cases bodd_div2 n; refl @[simp] lemma bodd_bit0 (n) : bodd (bit0 n) = ff := bodd_bit ff n @[simp] lemma bodd_bit1 (n) : bodd (bit1 n) = tt := bodd_bit tt n @[simp] lemma div2_bit0 (n) : div2 (bit0 n) = n := div2_bit ff n @[simp] lemma div2_bit1 (n) : div2 (bit1 n) = n := div2_bit tt n /- iterate -/ section variables {Ξ± : Sort*} (op : Ξ± β†’ Ξ±) @[simp] theorem iterate_zero (a : Ξ±) : op^[0] a = a := rfl @[simp] theorem iterate_succ (n : β„•) (a : Ξ±) : op^[succ n] a = (op^[n]) (op a) := rfl theorem iterate_add : βˆ€ (m n : β„•) (a : Ξ±), op^[m + n] a = (op^[m]) (op^[n] a) | m 0 a := rfl | m (succ n) a := iterate_add m n _ theorem iterate_succ' (n : β„•) (a : Ξ±) : op^[succ n] a = op (op^[n] a) := by rw [← one_add, iterate_add]; refl theorem iterateβ‚€ {Ξ± : Type u} {op : Ξ± β†’ Ξ±} {x : Ξ±} (H : op x = x) {n : β„•} : op^[n] x = x := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterate₁ {Ξ± : Type u} {Ξ² : Type v} {op : Ξ± β†’ Ξ±} {op' : Ξ² β†’ Ξ²} {op'' : Ξ± β†’ Ξ²} (H : βˆ€ x, op' (op'' x) = op'' (op x)) {n : β„•} {x : Ξ±} : op'^[n] (op'' x) = op'' (op^[n] x) := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterateβ‚‚ {Ξ± : Type u} {op : Ξ± β†’ Ξ±} {op' : Ξ± β†’ Ξ± β†’ Ξ±} (H : βˆ€ x y, op (op' x y) = op' (op x) (op y)) {n : β„•} {x y : Ξ±} : op^[n] (op' x y) = op' (op^[n] x) (op^[n] y) := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterate_cancel {Ξ± : Type u} {op op' : Ξ± β†’ Ξ±} (H : βˆ€ x, op (op' x) = x) {n : β„•} {x : Ξ±} : op^[n] (op'^[n] x) = x := by induction n; [refl, rwa [iterate_succ, iterate_succ', H]] theorem iterate_inj {Ξ± : Type u} {op : Ξ± β†’ Ξ±} (Hinj : function.injective op) (n : β„•) (x y : Ξ±) (H : (op^[n] x) = (op^[n] y)) : x = y := by induction n with n ih; simp only [iterate_zero, iterate_succ'] at H; [exact H, exact ih (Hinj H)] end /- size and shift -/ theorem shiftl'_ne_zero_left (b) {m} (h : m β‰  0) (n) : shiftl' b m n β‰  0 := by induction n; simp [shiftl', bit_ne_zero, *] theorem shiftl'_tt_ne_zero (m) : βˆ€ {n} (h : n β‰  0), shiftl' tt m n β‰  0 | 0 h := absurd rfl h | (succ n) _ := nat.bit1_ne_zero _ @[simp] theorem size_zero : size 0 = 0 := rfl @[simp] theorem size_bit {b n} (h : bit b n β‰  0) : size (bit b n) = succ (size n) := begin rw size, conv { to_lhs, rw [binary_rec], simp [h] }, rw div2_bit, refl end @[simp] theorem size_bit0 {n} (h : n β‰  0) : size (bit0 n) = succ (size n) := @size_bit ff n (nat.bit0_ne_zero h) @[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) := @size_bit tt n (nat.bit1_ne_zero n) @[simp] theorem size_one : size 1 = 1 := by apply size_bit1 0 @[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n β‰  0) : size (shiftl' b m n) = size m + n := begin induction n with n IH; simp [shiftl'] at h ⊒, rw [size_bit h, nat.add_succ], by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]], rw s0 at h ⊒, cases b, {exact absurd rfl h}, have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0, rw [shiftl'_tt_eq_mul_pow] at this, have m0 := succ_inj (eq_one_of_dvd_one ⟨_, this.symm⟩), subst m0, simp at this, have : n = 0 := eq_zero_of_le_zero (le_of_not_gt $ Ξ» hn, ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this), subst n, refl end @[simp] theorem size_shiftl {m} (h : m β‰  0) (n) : size (shiftl m n) = size m + n := size_shiftl' (shiftl'_ne_zero_left _ h _) theorem lt_size_self (n : β„•) : n < 2^size n := begin rw [← one_shiftl], have : βˆ€ {n}, n = 0 β†’ n < shiftl 1 (size n) := Ξ» n e, by subst e; exact dec_trivial, apply binary_rec _ _ n, {apply this rfl}, intros b n IH, by_cases bit b n = 0, {apply this h}, rw [size_bit h, shiftl_succ], exact bit_lt_bit0 _ IH end theorem size_le {m n : β„•} : size m ≀ n ↔ m < 2^n := ⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h), begin rw [← one_shiftl], revert n, apply binary_rec _ _ m, { intros n h, apply zero_le }, { intros b m IH n h, by_cases e : bit b m = 0, { rw e, apply zero_le }, rw [size_bit e], cases n with n, { exact e.elim (eq_zero_of_le_zero (le_of_lt_succ h)) }, { apply succ_le_succ (IH _), apply lt_imp_lt_of_le_imp_le (Ξ» h', bit0_le_bit _ h') h } } end⟩ theorem lt_size {m n : β„•} : m < size n ↔ 2^m ≀ n := by rw [← not_lt, iff_not_comm, not_lt, size_le] theorem size_pos {n : β„•} : 0 < size n ↔ 0 < n := by rw lt_size; refl theorem size_eq_zero {n : β„•} : size n = 0 ↔ n = 0 := by have := @size_pos n; simp [pos_iff_ne_zero] at this; exact not_iff_not.1 this theorem size_pow {n : β„•} : size (2^n) = n+1 := le_antisymm (size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _)) (lt_size.2 $ le_refl _) theorem size_le_size {m n : β„•} (h : m ≀ n) : size m ≀ size n := size_le.2 $ lt_of_le_of_lt h (lt_size_self _) /- factorial -/ /-- `fact n` is the factorial of `n`. -/ @[simp] def fact : nat β†’ nat | 0 := 1 | (succ n) := succ n * fact n @[simp] theorem fact_zero : fact 0 = 1 := rfl @[simp] theorem fact_succ (n) : fact (succ n) = succ n * fact n := rfl @[simp] theorem fact_one : fact 1 = 1 := rfl theorem fact_pos : βˆ€ n, 0 < fact n | 0 := zero_lt_one | (succ n) := mul_pos (succ_pos _) (fact_pos n) theorem fact_ne_zero (n : β„•) : fact n β‰  0 := ne_of_gt (fact_pos _) theorem fact_dvd_fact {m n} (h : m ≀ n) : fact m ∣ fact n := begin induction n with n IH; simp, { have := eq_zero_of_le_zero h, subst m, simp }, { cases eq_or_lt_of_le h with he hl, { subst m, simp }, { apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } } end theorem dvd_fact : βˆ€ {m n}, 0 < m β†’ m ≀ n β†’ m ∣ fact n | (succ m) n _ h := dvd_of_mul_right_dvd (fact_dvd_fact h) theorem fact_le {m n} (h : m ≀ n) : fact m ≀ fact n := le_of_dvd (fact_pos _) (fact_dvd_fact h) lemma fact_mul_pow_le_fact : βˆ€ {m n : β„•}, m.fact * m.succ ^ n ≀ (m + n).fact | m 0 := by simp | m (n+1) := by rw [← add_assoc, nat.fact_succ, mul_comm (nat.succ _), nat.pow_succ, ← mul_assoc]; exact mul_le_mul fact_mul_pow_le_fact (nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _) lemma monotone_fact : monotone fact := Ξ» n m, fact_le lemma fact_lt (h0 : 0 < n) : n.fact < m.fact ↔ n < m := begin split; intro h, { rw [← not_le], intro hmn, apply not_le_of_lt h (fact_le hmn) }, { have : βˆ€(n : β„•), 0 < n β†’ n.fact < n.succ.fact, { intros k hk, rw [fact_succ, succ_mul, lt_add_iff_pos_left], apply mul_pos hk (fact_pos k) }, induction h generalizing h0, { exact this _ h0, }, { refine lt_trans (h_ih h0) (this _ _), exact lt_trans h0 (lt_of_succ_le h_a) }} end lemma one_lt_fact : 1 < n.fact ↔ 1 < n := by { convert fact_lt _, refl, exact one_pos } lemma fact_eq_one : n.fact = 1 ↔ n ≀ 1 := begin split; intro h, { rw [← not_lt, ← one_lt_fact, h], apply lt_irrefl }, { cases h with h h, refl, cases h, refl } end lemma fact_inj (h0 : 1 < n.fact) : n.fact = m.fact ↔ n = m := begin split; intro h, { rcases lt_trichotomy n m with hnm|hnm|hnm, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [one_lt_fact] at h0, exact lt_trans one_pos h0 }, { exact hnm }, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [h, one_lt_fact] at h0, exact lt_trans one_pos h0 }}, { rw h } end /- choose -/ /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. -/ def choose : β„• β†’ β„• β†’ β„• | _ 0 := 1 | 0 (k + 1) := 0 | (n + 1) (k + 1) := choose n k + choose n (k + 1) @[simp] lemma choose_zero_right (n : β„•) : choose n 0 = 1 := by cases n; refl @[simp] lemma choose_zero_succ (k : β„•) : choose 0 (succ k) = 0 := rfl lemma choose_succ_succ (n k : β„•) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl lemma choose_eq_zero_of_lt : βˆ€ {n k}, n < k β†’ choose n k = 0 | _ 0 hk := absurd hk dec_trivial | 0 (k + 1) hk := choose_zero_succ _ | (n + 1) (k + 1) hk := have hnk : n < k, from lt_of_succ_lt_succ hk, have hnk1 : n < k + 1, from lt_of_succ_lt hk, by rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] @[simp] lemma choose_self (n : β„•) : choose n n = 1 := by induction n; simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] @[simp] lemma choose_succ_self (n : β„•) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) @[simp] lemma choose_one_right (n : β„•) : choose n 1 = n := by induction n; simp [*, choose, add_comm] /-- `choose n 2` is the `n`-th triangle number. -/ lemma choose_two_right (n : β„•) : choose n 2 = n * (n - 1) / 2 := begin induction n with n ih, simp, {rw triangle_succ n, simp [choose, ih], rw add_comm}, end lemma choose_pos : βˆ€ {n k}, k ≀ n β†’ 0 < choose n k | 0 _ hk := by rw [eq_zero_of_le_zero hk]; exact dec_trivial | (n + 1) 0 hk := by simp; exact dec_trivial | (n + 1) (k + 1) hk := by rw choose_succ_succ; exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (nat.zero_le _) lemma succ_mul_choose_eq : βˆ€ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0 0 := dec_trivial | 0 (k + 1) := by simp [choose] | (n + 1) 0 := by simp | (n + 1) (k + 1) := by rw [choose_succ_succ (succ n) (succ k), add_mul, ←succ_mul_choose_eq, mul_succ, ←succ_mul_choose_eq, add_right_comm, ←mul_add, ←choose_succ_succ, ←succ_mul] lemma choose_mul_fact_mul_fact : βˆ€ {n k}, k ≀ n β†’ choose n k * fact k * fact (n - k) = fact n | 0 _ hk := by simp [eq_zero_of_le_zero hk] | (n + 1) 0 hk := by simp | (n + 1) (succ k) hk := begin cases lt_or_eq_of_le hk with hk₁ hk₁, { have h : choose n k * fact (succ k) * fact (n - k) = succ k * fact n := by rw ← choose_mul_fact_mul_fact (le_of_succ_le_succ hk); simp [fact_succ, mul_comm, mul_left_comm], have h₁ : fact (n - k) = (n - k) * fact (n - succ k) := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), fact_succ], have hβ‚‚ : choose n (succ k) * fact (succ k) * ((n - k) * fact (n - succ k)) = (n - k) * fact n := by rw ← choose_mul_fact_mul_fact (le_of_lt_succ hk₁); simp [fact_succ, mul_comm, mul_left_comm, mul_assoc], have h₃ : k * fact n ≀ n * fact n := mul_le_mul_right _ (le_of_succ_le_succ hk), rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h₁, hβ‚‚, ← add_one, add_mul, nat.mul_sub_right_distrib, fact_succ, ← nat.add_sub_assoc h₃, add_assoc, ← add_mul, nat.add_sub_cancel_left, add_comm] }, { simp [hk₁, mul_comm, choose, nat.sub_self] } end theorem choose_eq_fact_div_fact {n k : β„•} (hk : k ≀ n) : choose n k = fact n / (fact k * fact (n - k)) := begin have : fact n = choose n k * (fact k * fact (n - k)) := by rw ← mul_assoc; exact (choose_mul_fact_mul_fact hk).symm, exact (nat.div_eq_of_eq_mul_left (mul_pos (fact_pos _) (fact_pos _)) this).symm end theorem fact_mul_fact_dvd_fact {n k : β„•} (hk : k ≀ n) : fact k * fact (n - k) ∣ fact n := by rw [←choose_mul_fact_mul_fact hk, mul_assoc]; exact dvd_mul_left _ _ @[simp] lemma choose_symm {n k : β„•} (hk : k ≀ n) : choose n (n-k) = choose n k := by rw [choose_eq_fact_div_fact hk, choose_eq_fact_div_fact (sub_le _ _), nat.sub_sub_self hk, mul_comm] lemma choose_succ_right_eq (n k : β„•) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := begin have e : (n+1) * choose n k = choose n k * (k+1) + choose n (k+1) * (k+1), rw [← right_distrib, ← choose_succ_succ, succ_mul_choose_eq], rw [← nat.sub_eq_of_eq_add e, mul_comm, ← nat.mul_sub_left_distrib, nat.add_sub_add_right] end @[simp] lemma choose_succ_self_right : βˆ€ (n:β„•), (n+1).choose n = n+1 | 0 := rfl | (n+1) := by rw [choose_succ_succ, choose_succ_self_right, choose_self] lemma choose_mul_succ_eq (n k : β„•) : (n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) := begin induction k with k ih, { simp }, by_cases hk : n < k + 1, { rw [choose_eq_zero_of_lt hk, sub_eq_zero_of_le hk, zero_mul, mul_zero] }, push_neg at hk, replace hk : k + 1 ≀ n + 1 := _root_.le_add_right hk, rw [choose_succ_succ], rw [add_mul, succ_sub_succ], rw [← choose_succ_right_eq], rw [← succ_sub_succ, nat.mul_sub_left_distrib], symmetry, apply nat.add_sub_cancel', exact mul_le_mul_left _ hk, end section find_greatest /-- `find_greatest P b` is the largest `i ≀ bound` such that `P i` holds, or `0` if no such `i` exists -/ protected def find_greatest (P : β„• β†’ Prop) [decidable_pred P] : β„• β†’ β„• | 0 := 0 | (n + 1) := if P (n + 1) then n + 1 else find_greatest n variables {P : β„• β†’ Prop} [decidable_pred P] @[simp] lemma find_greatest_zero : nat.find_greatest P 0 = 0 := rfl @[simp] lemma find_greatest_eq : βˆ€{b}, P b β†’ nat.find_greatest P b = b | 0 h := rfl | (n + 1) h := by simp [nat.find_greatest, h] @[simp] lemma find_greatest_of_not {b} (h : Β¬ P (b + 1)) : nat.find_greatest P (b + 1) = nat.find_greatest P b := by simp [nat.find_greatest, h] lemma find_greatest_spec_and_le : βˆ€{b m}, m ≀ b β†’ P m β†’ P (nat.find_greatest P b) ∧ m ≀ nat.find_greatest P b | 0 m hm hP := have m = 0, from le_antisymm hm (nat.zero_le _), show P 0 ∧ m ≀ 0, from this β–Έ ⟨hP, le_refl _⟩ | (b + 1) m hm hP := begin by_cases h : P (b + 1), { simp [h, hm] }, { have : m β‰  b + 1 := assume this, h $ this β–Έ hP, have : m ≀ b := (le_of_not_gt $ assume h : b + 1 ≀ m, this $ le_antisymm hm h), have : P (nat.find_greatest P b) ∧ m ≀ nat.find_greatest P b := find_greatest_spec_and_le this hP, simp [h, this] } end lemma find_greatest_spec {b} : (βˆƒm, m ≀ b ∧ P m) β†’ P (nat.find_greatest P b) | ⟨m, hmb, hm⟩ := (find_greatest_spec_and_le hmb hm).1 lemma find_greatest_le : βˆ€ {b}, nat.find_greatest P b ≀ b | 0 := le_refl _ | (b + 1) := have nat.find_greatest P b ≀ b + 1, from le_trans find_greatest_le (nat.le_succ b), by by_cases P (b + 1); simp [h, this] lemma le_find_greatest {b m} (hmb : m ≀ b) (hm : P m) : m ≀ nat.find_greatest P b := (find_greatest_spec_and_le hmb hm).2 lemma find_greatest_is_greatest {P : β„• β†’ Prop} [decidable_pred P] {b} : (βˆƒ m, m ≀ b ∧ P m) β†’ βˆ€ k, nat.find_greatest P b < k ∧ k ≀ b β†’ Β¬ P k | ⟨m, hmb, hP⟩ k ⟨hk, hkb⟩ hPk := lt_irrefl k $ lt_of_le_of_lt (le_find_greatest hkb hPk) hk lemma find_greatest_eq_zero {P : β„• β†’ Prop} [decidable_pred P] : βˆ€ {b}, (βˆ€ n ≀ b, Β¬ P n) β†’ nat.find_greatest P b = 0 | 0 h := find_greatest_zero | (n + 1) h := begin have := nat.find_greatest_of_not (h (n + 1) (le_refl _)), rw this, exact find_greatest_eq_zero (assume k hk, h k (le_trans hk $ nat.le_succ _)) end lemma find_greatest_of_ne_zero {P : β„• β†’ Prop} [decidable_pred P] : βˆ€ {b m}, nat.find_greatest P b = m β†’ m β‰  0 β†’ P m | 0 m rfl h := by { have := @find_greatest_zero P _, contradiction } | (b + 1) m rfl h := decidable.by_cases (assume hb : P (b + 1), by { have := find_greatest_eq hb, rw this, exact hb }) (assume hb : Β¬ P (b + 1), find_greatest_of_ne_zero (find_greatest_of_not hb).symm h) end find_greatest section div lemma dvd_div_of_mul_dvd {a b c : β„•} (h : a * b ∣ c) : b ∣ c / a := if ha : a = 0 then by simp [ha] else have ha : 0 < a, from nat.pos_of_ne_zero ha, have h1 : βˆƒ d, c = a * b * d, from h, let ⟨d, hd⟩ := h1 in have hac : a ∣ c, from dvd_of_mul_right_dvd h, have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd), show βˆƒ d, c / a = b * d, from ⟨d, h2⟩ lemma mul_dvd_of_dvd_div {a b c : β„•} (hab : c ∣ b) (h : a ∣ b / c) : c * a ∣ b := have h1 : βˆƒ d, b / c = a * d, from h, have h2 : βˆƒ e, b = c * e, from hab, let ⟨d, hd⟩ := h1, ⟨e, he⟩ := h2 in have h3 : b = a * d * c, from nat.eq_mul_of_div_eq_left hab hd, show βˆƒ d, b = c * a * d, from ⟨d, by cc⟩ lemma div_mul_div {a b c d : β„•} (hab : b ∣ a) (hcd : d ∣ c) : (a / b) * (c / d) = (a * c) / (b * d) := have exi1 : βˆƒ x, a = b * x, from hab, have exi2 : βˆƒ y, c = d * y, from hcd, if hb : b = 0 then by simp [hb] else have 0 < b, from nat.pos_of_ne_zero hb, if hd : d = 0 then by simp [hd] else have 0 < d, from nat.pos_of_ne_zero hd, begin cases exi1 with x hx, cases exi2 with y hy, rw [hx, hy, nat.mul_div_cancel_left, nat.mul_div_cancel_left], symmetry, apply nat.div_eq_of_eq_mul_left, apply mul_pos, repeat {assumption}, cc end lemma pow_dvd_of_le_of_pow_dvd {p m n k : β„•} (hmn : m ≀ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k := have p ^ m ∣ p ^ n, from pow_dvd_pow _ hmn, dvd_trans this hdiv lemma dvd_of_pow_dvd {p k m : β„•} (hk : 1 ≀ k) (hpk : p^k ∣ m) : p ∣ m := by rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk lemma eq_of_dvd_of_div_eq_one {a b : β„•} (w : a ∣ b) (h : b / a = 1) : a = b := by rw [←nat.div_mul_cancel w, h, one_mul] lemma eq_zero_of_dvd_of_div_eq_zero {a b : β„•} (w : a ∣ b) (h : b / a = 0) : b = 0 := by rw [←nat.div_mul_cancel w, h, zero_mul] lemma div_le_div_left {a b c : β„•} (h₁ : c ≀ b) (hβ‚‚ : 0 < c) : a / b ≀ a / c := (nat.le_div_iff_mul_le _ _ hβ‚‚).2 $ le_trans (mul_le_mul_left _ h₁) (div_mul_le_self _ _) lemma div_eq_self {a b : β„•} : a / b = a ↔ a = 0 ∨ b = 1 := begin split, { intro, cases b, { simp * at * }, { cases b, { right, refl }, { left, have : a / (b + 2) ≀ a / 2 := div_le_div_left (by simp) dec_trivial, refine eq_zero_of_le_half _, simp * at * } } }, { rintros (rfl|rfl); simp } end end div lemma exists_eq_add_of_le : βˆ€ {m n : β„•}, m ≀ n β†’ βˆƒ k : β„•, n = m + k | 0 0 h := ⟨0, by simp⟩ | 0 (n+1) h := ⟨n+1, by simp⟩ | (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk, add_comm, add_left_comm]⟩ lemma exists_eq_add_of_lt : βˆ€ {m n : β„•}, m < n β†’ βˆƒ k : β„•, n = m + k + 1 | 0 0 h := false.elim $ lt_irrefl _ h | 0 (n+1) h := ⟨n, by simp⟩ | (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk]⟩ lemma with_bot.add_eq_zero_iff : βˆ€ {n m : with_bot β„•}, n + m = 0 ↔ n = 0 ∧ m = 0 | none m := iff_of_false dec_trivial (Ξ» h, absurd h.1 dec_trivial) | n none := iff_of_false (by cases n; exact dec_trivial) (Ξ» h, absurd h.2 dec_trivial) | (some n) (some m) := show (n + m : with_bot β„•) = (0 : β„•) ↔ (n : with_bot β„•) = (0 : β„•) ∧ (m : with_bot β„•) = (0 : β„•), by rw [← with_bot.coe_add, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, add_eq_zero_iff' (nat.zero_le _) (nat.zero_le _)] lemma with_bot.add_eq_one_iff : βˆ€ {n m : with_bot β„•}, n + m = 1 ↔ (n = 0 ∧ m = 1) ∨ (n = 1 ∧ m = 0) | none none := dec_trivial | none (some m) := dec_trivial | (some n) none := iff_of_false dec_trivial (Ξ» h, h.elim (Ξ» h, absurd h.2 dec_trivial) (Ξ» h, absurd h.2 dec_trivial)) | (some n) (some 0) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp | (some n) (some (m + 1)) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp [nat.add_succ, nat.succ_inj', nat.succ_ne_zero] -- induction /-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/ @[elab_as_eliminator] lemma le_induction {P : nat β†’ Prop} {m} (h0 : P m) (h1 : βˆ€ n, m ≀ n β†’ P n β†’ P (n + 1)) : βˆ€ n, m ≀ n β†’ P n := by apply nat.less_than_or_equal.rec h0; exact h1 /-- Decreasing induction: if `P (k+1)` implies `P k`, then `P n` implies `P m` for all `m ≀ n`. Also works for functions to `Sort*`. -/ @[elab_as_eliminator] def decreasing_induction {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {m n : β„•} (mn : m ≀ n) (hP : P n) : P m := le_rec_on mn (Ξ» k ih hsk, ih $ h k hsk) (Ξ» h, h) hP @[simp] lemma decreasing_induction_self {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {n : β„•} (nn : n ≀ n) (hP : P n) : (decreasing_induction h nn hP : P n) = hP := by { dunfold decreasing_induction, rw [le_rec_on_self] } lemma decreasing_induction_succ {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {m n : β„•} (mn : m ≀ n) (msn : m ≀ n + 1) (hP : P (n+1)) : (decreasing_induction h msn hP : P m) = decreasing_induction h mn (h n hP) := by { dunfold decreasing_induction, rw [le_rec_on_succ] } @[simp] lemma decreasing_induction_succ' {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {m : β„•} (msm : m ≀ m + 1) (hP : P (m+1)) : (decreasing_induction h msm hP : P m) = h m hP := by { dunfold decreasing_induction, rw [le_rec_on_succ'] } lemma decreasing_induction_trans {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {m n k : β„•} (mn : m ≀ n) (nk : n ≀ k) (hP : P k) : (decreasing_induction h (le_trans mn nk) hP : P m) = decreasing_induction h mn (decreasing_induction h nk hP) := by { induction nk with k nk ih, rw [decreasing_induction_self], rw [decreasing_induction_succ h (le_trans mn nk), ih, decreasing_induction_succ] } lemma decreasing_induction_succ_left {P : β„• β†’ Sort*} (h : βˆ€n, P (n+1) β†’ P n) {m n : β„•} (smn : m + 1 ≀ n) (mn : m ≀ n) (hP : P n) : (decreasing_induction h mn hP : P m) = h m (decreasing_induction h smn hP) := by { rw [subsingleton.elim mn (le_trans (le_succ m) smn), decreasing_induction_trans, decreasing_induction_succ'] } end nat
747ee4ac3788cd24ede35c127866480cffd484d0
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
/stage0/src/Lean/Structure.lean
13ed9a67be63d25562856c0703cd0d44e055bc10
[ "Apache-2.0" ]
permissive
subfish-zhou/leanprover-zh_CN.github.io
30b9fba9bd790720bd95764e61ae796697d2f603
8b2985d4a3d458ceda9361ac454c28168d920d3f
refs/heads/master
1,689,709,967,820
1,632,503,056,000
1,632,503,056,000
409,962,097
1
0
null
null
null
null
UTF-8
Lean
false
false
8,253
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura Helper functions for retrieving structure information. -/ import Lean.Environment import Lean.ProjFns namespace Lean structure StructureFieldInfo where fieldName : Name projFn : Name subobject? : Option Name -- It is `some parentStructName` if it is a subobject, and `parentStructName` is the name of the parent structure binderInfo : BinderInfo inferMod : Bool -- true if user used the `{}` when declaring the field deriving Inhabited, Repr def StructureFieldInfo.lt (i₁ iβ‚‚ : StructureFieldInfo) : Bool := Name.quickLt i₁.fieldName iβ‚‚.fieldName structure StructureInfo where structName : Name fieldNames : Array Name := #[] -- sorted by field position in the structure fieldInfo : Array StructureFieldInfo := #[] -- sorted by `fieldName` deriving Inhabited def StructureInfo.lt (i₁ iβ‚‚ : StructureInfo) : Bool := Name.quickLt i₁.structName iβ‚‚.structName /-- Auxiliary state for structures defined in the current module. -/ private structure StructureState where map : Std.PersistentHashMap Name StructureInfo := {} deriving Inhabited builtin_initialize structureExt : SimplePersistentEnvExtension StructureInfo StructureState ← registerSimplePersistentEnvExtension { name := `structExt addImportedFn := fun _ => {} addEntryFn := fun s e => { s with map := s.map.insert e.structName e } toArrayFn := fun es => es.toArray.qsort StructureInfo.lt } structure StructureDescr where structName : Name fields : Array StructureFieldInfo -- Should use the order the field appear in the constructor. deriving Inhabited def registerStructure (env : Environment) (e : StructureDescr) : Environment := structureExt.addEntry env { structName := e.structName fieldNames := e.fields.map fun e => e.fieldName fieldInfo := e.fields.qsort StructureFieldInfo.lt } def getStructureInfo? (env : Environment) (structName : Name) : Option StructureInfo := match env.getModuleIdxFor? structName with | some modIdx => structureExt.getModuleEntries env modIdx |>.binSearch { structName } StructureInfo.lt | none => structureExt.getState env |>.map.find? structName def getStructureCtor (env : Environment) (constName : Name) : ConstructorVal := match env.find? constName with | some (ConstantInfo.inductInfo { isRec := false, ctors := [ctorName], .. }) => match env.find? ctorName with | some (ConstantInfo.ctorInfo val) => val | _ => panic! "ill-formed environment" | _ => panic! "structure expected" /-- Get direct field names for the given structure. -/ def getStructureFields (env : Environment) (structName : Name) : Array Name := if let some info := getStructureInfo? env structName then info.fieldNames else panic! "structure expected" def getFieldInfo? (env : Environment) (structName : Name) (fieldName : Name) : Option StructureFieldInfo := if let some info := getStructureInfo? env structName then info.fieldInfo.binSearch { fieldName := fieldName, projFn := arbitrary, subobject? := none, binderInfo := arbitrary, inferMod := false } StructureFieldInfo.lt else none /-- If `fieldName` represents the relation to a parent structure `S`, return `S` -/ def isSubobjectField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name := if let some fieldInfo := getFieldInfo? env structName fieldName then fieldInfo.subobject? else none /-- Return immediate parent structures -/ def getParentStructures (env : Environment) (structName : Name) : Array Name := let fieldNames := getStructureFields env structName; fieldNames.foldl (init := #[]) fun acc fieldName => match isSubobjectField? env structName fieldName with | some parentStructName => acc.push parentStructName | none => acc /-- Return all parent structures -/ partial def getAllParentStructures (env : Environment) (structName : Name) : Array Name := visit structName |>.run #[] |>.2 where visit (structName : Name) : StateT (Array Name) Id Unit := do for p in getParentStructures env structName do modify fun s => s.push p visit p /-- `findField? env S fname`. If `fname` is defined in a parent `S'` of `S`, return `S'` -/ partial def findField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name := if (getStructureFields env structName).contains fieldName then some structName else getParentStructures env structName |>.findSome? fun parentStructName => findField? env parentStructName fieldName private partial def getStructureFieldsFlattenedAux (env : Environment) (structName : Name) (fullNames : Array Name) (includeSubobjectFields : Bool) : Array Name := (getStructureFields env structName).foldl (init := fullNames) fun fullNames fieldName => match isSubobjectField? env structName fieldName with | some parentStructName => let fullNames := if includeSubobjectFields then fullNames.push fieldName else fullNames getStructureFieldsFlattenedAux env parentStructName fullNames includeSubobjectFields | none => fullNames.push fieldName def getStructureFieldsFlattened (env : Environment) (structName : Name) (includeSubobjectFields := true) : Array Name := getStructureFieldsFlattenedAux env structName #[] includeSubobjectFields /-- Return true if `constName` is the name of an inductive datatype created using the `structure` or `class` commands. We perform the check by testing whether auxiliary projection functions have been created. -/ def isStructure (env : Environment) (constName : Name) : Bool := getStructureInfo? env constName |>.isSome def getProjFnForField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name := if let some fieldInfo := getFieldInfo? env structName fieldName then some fieldInfo.projFn else none def mkDefaultFnOfProjFn (projFn : Name) : Name := projFn ++ `_default def getDefaultFnForField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name := if let some projName := getProjFnForField? env structName fieldName then let defFn := mkDefaultFnOfProjFn projName if env.contains defFn then defFn else none else -- Check if we have a default function for a default values overriden by substructure. let defFn := mkDefaultFnOfProjFn (structName ++ fieldName) if env.contains defFn then defFn else none partial def getPathToBaseStructureAux (env : Environment) (baseStructName : Name) (structName : Name) (path : List Name) : Option (List Name) := if baseStructName == structName then some path.reverse else let fieldNames := getStructureFields env structName; fieldNames.findSome? fun fieldName => match isSubobjectField? env structName fieldName with | none => none | some parentStructName => match getProjFnForField? env structName fieldName with | none => none | some projFn => getPathToBaseStructureAux env baseStructName parentStructName (projFn :: path) /-- If `baseStructName` is an ancestor structure for `structName`, then return a sequence of projection functions to go from `structName` to `baseStructName`. -/ def getPathToBaseStructure? (env : Environment) (baseStructName : Name) (structName : Name) : Option (List Name) := getPathToBaseStructureAux env baseStructName structName [] /-- Return true iff `constName` is the a non-recursive inductive datatype that has only one constructor. -/ def isStructureLike (env : Environment) (constName : Name) : Bool := match env.find? constName with | some (ConstantInfo.inductInfo { isRec := false, ctors := [ctor], .. }) => true | _ => false /-- Return number of fields for a structure-like type -/ def getStructureLikeNumFields (env : Environment) (constName : Name) : Nat := match env.find? constName with | some (ConstantInfo.inductInfo { isRec := false, ctors := [ctor], .. }) => match env.find? ctor with | some (ConstantInfo.ctorInfo { numFields := n, .. }) => n | _ => 0 | _ => 0 end Lean
d5b159bc0a8597500c2a1dca929782d9e147251d
453dcd7c0d1ef170b0843a81d7d8caedc9741dce
/tactic/interactive.lean
e56a92e47f54d627a05f664f876cbb803a426ed5
[ "Apache-2.0" ]
permissive
amswerdlow/mathlib
9af77a1f08486d8fa059448ae2d97795bd12ec0c
27f96e30b9c9bf518341705c99d641c38638dfd0
refs/heads/master
1,585,200,953,598
1,534,275,532,000
1,534,275,532,000
144,564,700
0
0
null
1,534,156,197,000
1,534,156,197,000
null
UTF-8
Lean
false
false
22,922
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Simon Hudon, Sebastien Gouezel -/ import data.dlist data.dlist.basic data.prod category.basic tactic.basic tactic.rcases tactic.generalize_proofs tactic.split_ifs meta.expr logic.basic tactic.ext tactic.tauto tactic.replacer open lean open lean.parser local postfix `?`:9001 := optional local postfix *:9001 := many namespace tactic namespace interactive open interactive interactive.types expr local notation `listΞ£` := list_Sigma local notation `listΞ ` := list_Pi meta def rcases_patt_parse_core (rcases_patt_parse_list : parser (listΞ£ rcases_patt_inverted)) : parser rcases_patt_inverted | x := ((rcases_patt_inverted.one <$> ident_) <|> (rcases_patt_inverted.many <$> brackets "⟨" "⟩" (sep_by (tk ",") rcases_patt_parse_list))) x meta def rcases_patt_parse_list : parser (listΞ£ rcases_patt_inverted) := with_desc "patt" $ list.cons <$> rcases_patt_parse_core rcases_patt_parse_list <*> (tk "|" *> rcases_patt_parse_core rcases_patt_parse_list)* meta def rcases_patt_parse : parser rcases_patt_inverted := with_desc "patt_list" $ rcases_patt_parse_core rcases_patt_parse_list meta def rcases_parse_depth : parser nat := do o ← (tk ":" *> small_nat)?, pure $ o.get_or_else 5 meta def rcases_parse : parser (pexpr Γ— (listΞ£ (listΞ  rcases_patt) βŠ• nat)) := do hint ← (tk "?")?, p ← texpr, match hint with | none := do ids ← (tk "with" *> rcases_patt_parse_list)?, pure (p, sum.inl $ rcases_patt_inverted.invert_list (ids.get_or_else [default _])) | some _ := do depth ← rcases_parse_depth, pure (p, sum.inr depth) end /-- The `rcases` tactic is the same as `cases`, but with more flexibility in the `with` pattern syntax to allow for recursive case splitting. The pattern syntax uses the following recursive grammar: ``` patt ::= (patt_list "|")* patt_list patt_list ::= id | "_" | "⟨" (patt ",")* patt "⟩" ``` A pattern like `⟨a, b, c⟩ | ⟨d, e⟩` will do a split over the inductive datatype, naming the first three parameters of the first constructor as `a,b,c` and the first two of the second constructor `d,e`. If the list is not as long as the number of arguments to the constructor or the number of constructors, the remaining variables will be automatically named. If there are nested brackets such as `⟨⟨a⟩, b | c⟩ | d` then these will cause more case splits as necessary. If there are too many arguments, such as `⟨a, b, c⟩` for splitting on `βˆƒ x, βˆƒ y, p x`, then it will be treated as `⟨a, ⟨b, c⟩⟩`, splitting the last parameter as necessary. `rcases? e` will perform case splits on `e` in the same way as `rcases e`, but rather than accepting a pattern, it does a maximal cases and prints the pattern that would produce this case splitting. The default maximum depth is 5, but this can be modified with `rcases? e : n`. -/ meta def rcases : parse rcases_parse β†’ tactic unit | (p, sum.inl ids) := tactic.rcases p ids | (p, sum.inr depth) := do patt ← tactic.rcases_hint p depth, pe ← pp p, trace $ ↑"snippet: rcases " ++ pe ++ " with " ++ to_fmt patt meta def rintro_parse : parser (listΞ  rcases_patt βŠ• nat) := (tk "?" >> sum.inr <$> rcases_parse_depth) <|> sum.inl <$> (rcases_patt_inverted.invert <$> (brackets "(" ")" rcases_patt_parse_list <|> (Ξ» x, [x]) <$> rcases_patt_parse))* /-- The `rintro` tactic is a combination of the `intros` tactic with `rcases` to allow for destructuring patterns while introducing variables. See `rcases` for a description of supported patterns. For example, `rintros (a | ⟨b, c⟩) ⟨d, e⟩` will introduce two variables, and then do case splits on both of them producing two subgoals, one with variables `a d e` and the other with `b c d e`. `rintro?` will introduce and case split on variables in the same way as `rintro`, but will also print the `rintro` invocation that would have the same result. Like `rcases?`, `rintro? : n` allows for modifying the depth of splitting; the default is 5. -/ meta def rintro : parse rintro_parse β†’ tactic unit | (sum.inl []) := intros [] | (sum.inl l) := tactic.rintro l | (sum.inr depth) := do ps ← tactic.rintro_hint depth, trace $ ↑"snippet: rintro" ++ format.join (ps.map $ Ξ» p, format.space ++ format.group (p.format tt)) /-- Alias for `rintro`. -/ meta def rintros := rintro /-- This is a "finishing" tactic modification of `simp`. The tactic `simpa [rules, ...] using e` will simplify the hypothesis `e` using `rules`, then simplify the goal using `rules`, and try to close the goal using `assumption`. If `e` is a term instead of a local constant, it is first added to the local context using `have`. -/ meta def simpa (use_iota_eqn : parse $ (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (tgt : parse (tk "using" *> texpr)?) (cfg : simp_config_ext := {}) : tactic unit := let simp_at (lc) := simp use_iota_eqn no_dflt hs attr_names (loc.ns lc) cfg >> try (assumption <|> trivial) in match tgt with | none := get_local `this >> simp_at [some `this, none] <|> simp_at [none] | some e := (do e ← i_to_expr e, match e with | local_const _ lc _ _ := simp_at [some lc, none] | e := do t ← infer_type e, assertv `this t e >> simp_at [some `this, none] end) <|> (do simp_at [none], ty ← target, e ← i_to_expr_strict ``(%%e : %%ty), -- for positional error messages, don't care about the result pty ← pp ty, ptgt ← pp e, -- Fail deliberately, to advise regarding `simp; exact` usage fail ("simpa failed, 'using' expression type not directly " ++ "inferrable. Try:\n\nsimpa ... using\nshow " ++ to_fmt pty ++ ",\nfrom " ++ ptgt : format)) end /-- `try_for n { tac }` executes `tac` for `n` ticks, otherwise uses `sorry` to close the goal. Never fails. Useful for debugging. -/ meta def try_for (max : parse parser.pexpr) (tac : itactic) : tactic unit := do max ← i_to_expr_strict max >>= tactic.eval_expr nat, Ξ» s, match _root_.try_for max (tac s) with | some r := r | none := (tactic.trace "try_for timeout, using sorry" >> admit) s end /-- Multiple subst. `substs x y z` is the same as `subst x, subst y, subst z`. -/ meta def substs (l : parse ident*) : tactic unit := l.mmap' (Ξ» h, get_local h >>= tactic.subst) /-- Unfold coercion-related definitions -/ meta def unfold_coes (loc : parse location) : tactic unit := unfold [``coe,``lift_t,``has_lift_t.lift,``coe_t,``has_coe_t.coe,``coe_b,``has_coe.coe, ``coe_fn, ``has_coe_to_fun.coe, ``coe_sort, ``has_coe_to_sort.coe] loc /-- For debugging only. This tactic checks the current state for any missing dropped goals and restores them. Useful when there are no goals to solve but "result contains meta-variables". -/ meta def recover : tactic unit := do r ← tactic.result, tactic.set_goals $ r.fold [] $ Ξ» e _ l, match e with | expr.mvar _ _ _ := insert e l | _ := l end /-- Like `try { tac }`, but in the case of failure it continues from the failure state instead of reverting to the original state. -/ meta def continue (tac : itactic) : tactic unit := Ξ» s, result.cases_on (tac s) (Ξ» a, result.success ()) (Ξ» e ref, result.success ()) /-- Move goal `n` to the front. -/ meta def swap (n := 2) : tactic unit := do gs ← get_goals, match gs.nth (n-1) with | (some g) := set_goals (g :: gs.remove_nth (n-1)) | _ := skip end /-- Generalize proofs in the goal, naming them with the provided list. -/ meta def generalize_proofs : parse ident_* β†’ tactic unit := tactic.generalize_proofs /-- Clear all hypotheses starting with `_`, like `_match` and `_let_match`. -/ meta def clear_ : tactic unit := tactic.repeat $ do l ← local_context, l.reverse.mfirst $ Ξ» h, do name.mk_string s p ← return $ local_pp_name h, guard (s.front = '_'), cl ← infer_type h >>= is_class, guard (Β¬ cl), tactic.clear h /-- Same as the `congr` tactic, but takes an optional argument which gives the depth of recursive applications. This is useful when `congr` is too aggressive in breaking down the goal. For example, given `⊒ f (g (x + y)) = f (g (y + x))`, `congr'` produces the goals `⊒ x = y` and `⊒ y = x`, while `congr' 2` produces the intended `⊒ x + y = y + x`. -/ meta def congr' : parse (with_desc "n" small_nat)? β†’ tactic unit | (some 0) := failed | o := focus1 (assumption <|> (congr_core >> all_goals (reflexivity <|> try (congr' (nat.pred <$> o))))) /-- Acts like `have`, but removes a hypothesis with the same name as this one. For example if the state is `h : p ⊒ goal` and `f : p β†’ q`, then after `replace h := f h` the goal will be `h : q ⊒ goal`, where `have h := f h` would result in the state `h : p, h : q ⊒ goal`. This can be used to simulate the `specialize` and `apply at` tactics of Coq. -/ meta def replace (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (qβ‚‚ : parse $ (tk ":=" *> texpr)?) : tactic unit := do let h := h.get_or_else `this, old ← try_core (get_local h), Β«haveΒ» h q₁ qβ‚‚, match old, qβ‚‚ with | none, _ := skip | some o, some _ := tactic.clear o | some o, none := swap >> tactic.clear o >> swap end /-- `apply_assumption` looks for an assumption of the form `... β†’ βˆ€ _, ... β†’ head` where `head` matches the current goal. alternatively, when encountering an assumption of the form `sgβ‚€ β†’ Β¬ sg₁`, after the main approach failed, the goal is dismissed and `sgβ‚€` and `sg₁` are made into the new goal. optional arguments: - asms: list of rules to consider instead of the local constants - tac: a tactic to run on each subgoals after applying an assumption; if this tactic fails, the corresponding assumption will be rejected and the next one will be attempted. -/ meta def apply_assumption (asms : option (list expr) := none) (tac : tactic unit := return ()) : tactic unit := tactic.apply_assumption asms tac open nat /-- `solve_by_elim` calls `apply_assumption` on the main goal to find an assumption whose head matches and repeated calls `apply_assumption` on the generated subgoals until no subgoals remains or up to `depth` times. `solve_by_elim` discharges the current goal or fails `solve_by_elim` does some back-tracking if `apply_assumption` chooses an unproductive assumption optional arguments: - discharger: a subsidiary tactic to try at each step (`cc` is often helpful) - asms: list of assumptions / rules to consider instead of local constants - depth: number of attempts at discharging generated sub-goals -/ meta def solve_by_elim (opt : by_elim_opt := { }) : tactic unit := tactic.solve_by_elim opt /-- `tautology` breaks down assumptions of the form `_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `βˆƒ _, _` and splits a goal of the form `_ ∧ _`, `_ ↔ _` or `βˆƒ _, _` until it can be discharged using `reflexivity` or `solve_by_elim` -/ meta def tautology := tactic.tautology /-- Shorter name for the tactic `tautology`. -/ meta def tauto := tautology private meta def generalize_arg_p_aux : pexpr β†’ parser (pexpr Γ— name) | (app (app (macro _ [const `eq _ ]) h) (local_const x _ _ _)) := pure (h, x) | _ := fail "parse error" private meta def generalize_arg_p : parser (pexpr Γ— name) := with_desc "expr = id" $ parser.pexpr 0 >>= generalize_arg_p_aux lemma {u} generalize_a_aux {Ξ± : Sort u} (h : βˆ€ x : Sort u, (Ξ± β†’ x) β†’ x) : Ξ± := h Ξ± id /-- Like `generalize` but also considers assumptions specified by the user. The user can also specify to omit the goal. -/ meta def generalize_hyp (h : parse ident?) (_ : parse $ tk ":") (p : parse generalize_arg_p) (l : parse location) : tactic unit := do h' ← get_unused_name `h, x' ← get_unused_name `x, g ← if Β¬ l.include_goal then do refine ``(generalize_a_aux _), some <$> (prod.mk <$> tactic.intro x' <*> tactic.intro h') else pure none, n ← l.get_locals >>= tactic.revert_lst, generalize h () p, intron n, match g with | some (x',h') := do tactic.apply h', tactic.clear h', tactic.clear x' | none := return () end /-- Similar to `refine` but generates equality proof obligations for every discrepancy between the goal and the type of the rule. -/ meta def convert (sym : parse (with_desc "←" (tk "<-")?)) (r : parse texpr) (n : parse (tk "using" *> small_nat)?) : tactic unit := do v ← mk_mvar, if sym.is_some then refine ``(eq.mp %%v %%r) else refine ``(eq.mpr %%v %%r), gs ← get_goals, set_goals [v], congr' n, gs' ← get_goals, set_goals $ gs' ++ gs meta def clean_ids : list name := [``id, ``id_rhs, ``id_delta] /-- Remove identity functions from a term. These are normally automatically generated with terms like `show t, from p` or `(p : t)` which translate to some variant on `@id t p` in order to retain the type. -/ meta def clean (q : parse texpr) : tactic unit := do tgt : expr ← target, e ← i_to_expr_strict ``(%%q : %%tgt), tactic.exact $ e.replace (Ξ» e n, match e with | (app (app (const n _) _) e') := if n ∈ clean_ids then some e' else none | (app (lam _ _ _ (var 0)) e') := some e' | _ := none end) meta def source_fields (missing : list name) (e : pexpr) : tactic (list (name Γ— pexpr)) := do e ← to_expr e, t ← infer_type e, let struct_n : name := t.get_app_fn.const_name, fields ← expanded_field_list struct_n, let exp_fields := fields.filter (Ξ» x, x.2 ∈ missing), exp_fields.mmap $ Ξ» ⟨p,n⟩, (prod.mk n ∘ to_pexpr) <$> mk_mapp (n.update_prefix p) [none,some e] meta def collect_struct' : pexpr β†’ state_t (list $ exprΓ—structure_instance_info) tactic pexpr | e := do some str ← pure (e.get_structure_instance_info) | e.traverse collect_struct', v ← monad_lift mk_mvar, modify (list.cons (v,str)), pure $ to_pexpr v meta def collect_struct (e : pexpr) : tactic $ pexpr Γ— list (exprΓ—structure_instance_info) := prod.map id list.reverse <$> (collect_struct' e).run [] meta def refine_one (str : structure_instance_info) : tactic $ list (exprΓ—structure_instance_info) := do tgt ← target, let struct_n : name := tgt.get_app_fn.const_name, exp_fields ← expanded_field_list struct_n, let missing_f := exp_fields.filter (Ξ» f, (f.2 : name) βˆ‰ str.field_names), (src_field_names,src_field_vals) ← (@list.unzip name _ ∘ list.join) <$> str.sources.mmap (source_fields $ missing_f.map prod.snd), let provided := exp_fields.filter (Ξ» f, (f.2 : name) ∈ str.field_names), let missing_f' := missing_f.filter (Ξ» x, x.2 βˆ‰ src_field_names), vs ← mk_mvar_list missing_f'.length, (field_values,new_goals) ← list.unzip <$> (str.field_values.mmap collect_struct : tactic _), e' ← to_expr $ pexpr.mk_structure_instance { struct := some struct_n , field_names := str.field_names ++ missing_f'.map prod.snd ++ src_field_names , field_values := field_values ++ vs.map to_pexpr ++ src_field_vals }, tactic.exact e', gs ← with_enable_tags ( mzip_with (Ξ» (n : name Γ— name) v, do set_goals [v], try (interactive.unfold (provided.map $ Ξ» ⟨s,f⟩, f.update_prefix s) (loc.ns [none])), apply_auto_param <|> apply_opt_param <|> (set_main_tag [`_field,n.2,n.1]), get_goals) missing_f' vs), set_goals gs.join, return new_goals.join meta def refine_recursively : expr Γ— structure_instance_info β†’ tactic (list expr) | (e,str) := do set_goals [e], rs ← refine_one str, gs ← get_goals, gs' ← rs.mmap refine_recursively, return $ gs'.join ++ gs /-- `refine_struct { .. }` acts like `refine` but works only with structure instance literals. It creates a goal for each missing field and tags it with the name of the field so that `have_field` can be used to generically refer to the field currently being refined. As an example, we can use `refine_struct` to automate the construction semigroup instances: ``` refine_struct ( { .. } : semigroup Ξ± ), -- case semigroup, mul -- Ξ± : Type u, -- ⊒ Ξ± β†’ Ξ± β†’ Ξ± -- case semigroup, mul_assoc -- Ξ± : Type u, -- ⊒ βˆ€ (a b c : Ξ±), a * b * c = a * (b * c) ``` -/ meta def refine_struct : parse texpr β†’ tactic unit | e := do (x,xs) ← collect_struct e, refine x, gs ← get_goals, xs' ← xs.mmap refine_recursively, set_goals (xs'.join ++ gs) /-- `guard_hyp h := t` fails if the hypothesis `h` does not have type `t`. We use this tactic for writing tests. Fixes `guard_hyp` by instantiating meta variables -/ meta def guard_hyp' (n : parse ident) (p : parse $ tk ":=" *> texpr) : tactic unit := do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_eq h p meta def guard_hyp_nums (n : β„•) : tactic unit := do k ← local_context, guard (n = k.length) <|> fail format!"{k.length} hypotheses found" meta def guard_tags (tags : parse ident*) : tactic unit := do (t : list name) ← get_main_tag, guard (t = tags) meta def get_current_field : tactic name := do [_,field,str] ← get_main_tag, expr.const_name <$> resolve_name (field.update_prefix str) meta def field (n : parse ident) (tac : itactic) : tactic unit := do gs ← get_goals, ts ← gs.mmap get_tag, ([g],gs') ← pure $ (list.zip gs ts).partition (Ξ» x, x.snd.nth 1 = some n), set_goals [g.1], tac, done, set_goals $ gs'.map prod.fst /-- `have_field`, used after `refine_struct _` poses `field` as a local constant with the type of the field of the current goal: ``` refine_struct ({ .. } : semigroup Ξ±), { have_field, ... }, { have_field, ... }, ``` behaves like ``` refine_struct ({ .. } : semigroup Ξ±), { have field := @semigroup.mul, ... }, { have field := @semigroup.mul_assoc, ... }, ``` -/ meta def have_field : tactic unit := propagate_tags $ get_current_field >>= mk_const >>= note `field none >> return () /-- `apply_field` functions as `have_field, apply field, clear field` -/ meta def apply_field : tactic unit := propagate_tags $ get_current_field >>= applyc /--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the first goal and the resulting subgoals, iteratively, at most `n` times. `n` is 50 by default. `hs` can contain user attributes: in this case all theorems with this attribute are added to the list of rules. example, with or without user attribute: ``` @[user_attribute] meta def mono_rules : user_attribute := { name := `mono_rules, descr := "lemmas usable to prove monotonicity" } attribute [mono_rules] add_le_add mul_le_mul_of_nonneg_right lemma my_test {a b c d e : real} (h1 : a ≀ b) (h2 : c ≀ d) (h3 : 0 ≀ e) : a + c * e + a + c + 0 ≀ b + d * e + b + d + e := by apply_rules mono_rules -- any of the following lines would also work: -- add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3 -- by apply_rules [add_le_add, mul_le_mul_of_nonneg_right] -- by apply_rules [mono_rules] ``` -/ meta def apply_rules (hs : parse pexpr_list_or_texpr) (n : nat := 50) : tactic unit := tactic.apply_rules hs n meta def return_cast (f : option expr) (t : option (expr Γ— expr)) (es : list (expr Γ— expr Γ— expr)) (e x x' eq_h : expr) : tactic (option (expr Γ— expr) Γ— list (expr Γ— expr Γ— expr)) := (do guard (Β¬ e.has_var), unify x x', u ← mk_meta_univ, f ← f <|> to_expr ``(@id %%(expr.sort u : expr)), t' ← infer_type e, some (f',t) ← pure t | return (some (f,t'), (e,x',eq_h) :: es), infer_type e >>= is_def_eq t, unify f f', return (some (f,t), (e,x',eq_h) :: es)) <|> return (t, es) meta def list_cast_of_aux (x : expr) (t : option (expr Γ— expr)) (es : list (expr Γ— expr Γ— expr)) : expr β†’ tactic (option (expr Γ— expr) Γ— list (expr Γ— expr Γ— expr)) | e@`(cast %%eq_h %%x') := return_cast none t es e x x' eq_h | e@`(eq.mp %%eq_h %%x') := return_cast none t es e x x' eq_h | e@`(eq.mpr %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast none t es e x x' | e@`(@eq.subst %%Ξ± %%p %%a %%b %%eq_h %%x') := return_cast p t es e x x' eq_h | e@`(@eq.substr %%Ξ± %%p %%a %%b %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast p t es e x x' | e@`(@eq.rec %%Ξ± %%a %%f %%x' _ %%eq_h) := return_cast f t es e x x' eq_h | e@`(@eq.rec_on %%Ξ± %%a %%f %%b %%eq_h %%x') := return_cast f t es e x x' eq_h | e := return (t,es) meta def list_cast_of (x tgt : expr) : tactic (list (expr Γ— expr Γ— expr)) := (list.reverse ∘ prod.snd) <$> tgt.mfold (none, []) (Ξ» e i es, list_cast_of_aux x es.1 es.2 e) private meta def h_generalize_arg_p_aux : pexpr β†’ parser (pexpr Γ— name) | (app (app (macro _ [const `heq _ ]) h) (local_const x _ _ _)) := pure (h, x) | _ := fail "parse error" private meta def h_generalize_arg_p : parser (pexpr Γ— name) := with_desc "expr == id" $ parser.pexpr 0 >>= h_generalize_arg_p_aux /-- `h_generalize Hx : e == x` matches on `cast _ e` in the goal and replaces it with `x`. It also adds `Hx : e == x` as an assumption. If `cast _ e` appears multiple times (not necessarily with the same proof), they are all replaced by `x`. `cast` `eq.mp`, `eq.mpr`, `eq.subst`, `eq.substr`, `eq.rec` and `eq.rec_on` are all treated as casts. `h_generalize Hx : e == x with h` adds hypothesis `Ξ± = Ξ²` with `e : Ξ±, x : Ξ²`. `h_generalize Hx : e == x with _` chooses automatically chooses the name of assumption `Ξ± = Ξ²`. `h_generalize! Hx : e == x` reverts `Hx`. when `Hx` is omitted, assumption `Hx : e == x` is not added. -/ meta def h_generalize (rev : parse (tk "!")?) (h : parse ident_?) (_ : parse (tk ":")) (arg : parse h_generalize_arg_p) (eqs_h : parse ( (tk "with" >> pure <$> ident_) <|> pure [])) : tactic unit := do let (e,n) := arg, let h' := if h = `_ then none else h, h' ← (h' : tactic name) <|> get_unused_name ("h" ++ n.to_string : string), e ← to_expr e, tgt ← target, ((e,x,eq_h)::es) ← list_cast_of e tgt | fail "no cast found", interactive.generalize h' () (to_pexpr e, n), asm ← get_local h', v ← get_local n, hs ← es.mmap (Ξ» ⟨e,_⟩, mk_app `eq [e,v]), (eqs_h.zip [e]).mmap' (Ξ» ⟨h,e⟩, do h ← if h β‰  `_ then pure h else get_unused_name `h, () <$ note h none eq_h ), hs.mmap' (Ξ» h, do h' ← assert `h h, tactic.exact asm, try (rewrite_target h'), tactic.clear h' ), when h.is_some (do (to_expr ``(heq_of_eq_rec_left %%eq_h %%asm) <|> to_expr ``(heq_of_eq_mp %%eq_h %%asm)) >>= note h' none >> pure ()), tactic.clear asm, when rev.is_some (interactive.revert [n]) end interactive end tactic
e389b6a338326fa7af5f5ff5b6c9eb215ab39a55
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/ring_theory/witt_vector/basic.lean
c65dece4aa911f8e587e8a288d95a42cf3e06136
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,171
lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import data.mv_polynomial.counit import data.mv_polynomial.invertible import ring_theory.witt_vector.defs /-! # Witt vectors This file verifies that the ring operations on `witt_vector p R` satisfy the axioms of a commutative ring. ## Main definitions * `witt_vector.map`: lifts a ring homomorphism `R β†’+* S` to a ring homomorphism `π•Ž R β†’+* π•Ž S`. * `witt_vector.ghost_component n x`: evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`, producing a value in `R`. This is a ring homomorphism. * `witt_vector.ghost_map`: a ring homomorphism `π•Ž R β†’+* (β„• β†’ R)`, obtained by packaging all the ghost components together. If `p` is invertible in `R`, then the ghost map is an equivalence, which we use to define the ring operations on `π•Ž R`. * `witt_vector.comm_ring`: the ring structure induced by the ghost components. ## Notation We use notation `π•Ž R`, entered `\bbW`, for the Witt vectors over `R`. ## Implementation details As we prove that the ghost components respect the ring operations, we face a number of repetitive proofs. To avoid duplicating code we factor these proofs into a custom tactic, only slightly more powerful than a tactic macro. This tactic is not particularly useful outside of its applications in this file. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable theory open mv_polynomial function open_locale big_operators variables {p : β„•} {R S T : Type*} [hp : fact p.prime] [comm_ring R] [comm_ring S] [comm_ring T] variables {Ξ± : Type*} {Ξ² : Type*} local notation `π•Ž` := witt_vector p -- type as `\bbW` open_locale witt namespace witt_vector /-- `f : Ξ± β†’ Ξ²` induces a map from `π•Ž Ξ±` to `π•Ž Ξ²` by applying `f` componentwise. If `f` is a ring homomorphism, then so is `f`, see `witt_vector.map f`. -/ def map_fun (f : Ξ± β†’ Ξ²) : π•Ž Ξ± β†’ π•Ž Ξ² := Ξ» x, mk _ (f ∘ x.coeff) namespace map_fun lemma injective (f : Ξ± β†’ Ξ²) (hf : injective f) : injective (map_fun f : π•Ž Ξ± β†’ π•Ž Ξ²) := Ξ» x y h, ext $ Ξ» n, hf (congr_arg (Ξ» x, coeff x n) h : _) lemma surjective (f : Ξ± β†’ Ξ²) (hf : surjective f) : surjective (map_fun f : π•Ž Ξ± β†’ π•Ž Ξ²) := Ξ» x, ⟨mk _ (Ξ» n, classical.some $ hf $ x.coeff n), by { ext n, dsimp [map_fun], rw classical.some_spec (hf (x.coeff n)) }⟩ variables (f : R β†’+* S) (x y : π•Ž R) /-- Auxiliary tactic for showing that `map_fun` respects the ring operations. -/ meta def map_fun_tac : tactic unit := `[ext n, show f (aeval _ _) = aeval _ _, rw map_aeval, apply evalβ‚‚_hom_congr (ring_hom.ext_int _ _) _ rfl, ext ⟨i, k⟩, fin_cases i; refl] include hp /- We do not tag these lemmas as `@[simp]` because they will be bundled in `map` later on. -/ lemma zero : map_fun f (0 : π•Ž R) = 0 := by map_fun_tac lemma one : map_fun f (1 : π•Ž R) = 1 := by map_fun_tac lemma add : map_fun f (x + y) = map_fun f x + map_fun f y := by map_fun_tac lemma sub : map_fun f (x - y) = map_fun f x - map_fun f y := by map_fun_tac lemma mul : map_fun f (x * y) = map_fun f x * map_fun f y := by map_fun_tac lemma neg : map_fun f (-x) = -map_fun f x := by map_fun_tac end map_fun end witt_vector section tactic setup_tactic_parser open tactic /-- An auxiliary tactic for proving that `ghost_fun` respects the ring operations. -/ meta def tactic.interactive.ghost_fun_tac (Ο† fn : parse parser.pexpr) : tactic unit := do fn ← to_expr ```(%%fn : fin _ β†’ β„• β†’ R), `(fin %%k β†’ _ β†’ _) ← infer_type fn, `[ext n], `[dunfold witt_vector.has_zero witt_zero witt_vector.has_one witt_one witt_vector.has_neg witt_neg witt_vector.has_mul witt_mul witt_vector.has_sub witt_sub witt_vector.has_add witt_add ], to_expr ```(congr_fun (congr_arg (@peval R _ %%k) (witt_structure_int_prop p %%Ο† n)) %%fn) >>= note `this none, `[simpa [ghost_fun, aeval_rename, aeval_bind₁, (∘), uncurry, peval, eval] using this] end tactic namespace witt_vector /-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`, producing a value in `R`. This function will be bundled as the ring homomorphism `witt_vector.ghost_map` once the ring structure is available, but we rely on it to set up the ring structure in the first place. -/ private def ghost_fun : π•Ž R β†’ (β„• β†’ R) := Ξ» x n, aeval x.coeff (W_ β„€ n) section ghost_fun include hp /- The following lemmas are not `@[simp]` because they will be bundled in `ghost_map` later on. -/ variables (x y : π•Ž R) omit hp local attribute [simp] lemma matrix_vec_empty_coeff {R} (i j) : @coeff p R (matrix.vec_empty i) j = (matrix.vec_empty i : β„• β†’ R) j := by rcases i with ⟨_ | _ | _ | _ | i_val, ⟨⟩⟩ include hp private lemma ghost_fun_zero : ghost_fun (0 : π•Ž R) = 0 := by ghost_fun_tac 0 ![] private lemma ghost_fun_one : ghost_fun (1 : π•Ž R) = 1 := by ghost_fun_tac 1 ![] private lemma ghost_fun_add : ghost_fun (x + y) = ghost_fun x + ghost_fun y := by ghost_fun_tac (X 0 + X 1) ![x.coeff, y.coeff] private lemma ghost_fun_sub : ghost_fun (x - y) = ghost_fun x - ghost_fun y := by ghost_fun_tac (X 0 - X 1) ![x.coeff, y.coeff] private lemma ghost_fun_mul : ghost_fun (x * y) = ghost_fun x * ghost_fun y := by ghost_fun_tac (X 0 * X 1) ![x.coeff, y.coeff] private lemma ghost_fun_neg : ghost_fun (-x) = - ghost_fun x := by ghost_fun_tac (-X 0) ![x.coeff] end ghost_fun variables (p) (R) /-- The bijection between `π•Ž R` and `β„• β†’ R`, under the assumption that `p` is invertible in `R`. In `witt_vector.ghost_equiv` we upgrade this to an isomorphism of rings. -/ private def ghost_equiv' [invertible (p : R)] : π•Ž R ≃ (β„• β†’ R) := { to_fun := ghost_fun, inv_fun := Ξ» x, mk p $ Ξ» n, aeval x (X_in_terms_of_W p R n), left_inv := begin intro x, ext n, have := bind₁_witt_polynomial_X_in_terms_of_W p R n, apply_fun (aeval x.coeff) at this, simpa only [aeval_bind₁, aeval_X, ghost_fun, aeval_witt_polynomial] end, right_inv := begin intro x, ext n, have := bind₁_X_in_terms_of_W_witt_polynomial p R n, apply_fun (aeval x) at this, simpa only [aeval_bind₁, aeval_X, ghost_fun, aeval_witt_polynomial] end } include hp local attribute [instance] private def comm_ring_aux₁ : comm_ring (π•Ž (mv_polynomial R β„š)) := (ghost_equiv' p (mv_polynomial R β„š)).injective.comm_ring (ghost_fun) ghost_fun_zero ghost_fun_one ghost_fun_add ghost_fun_mul ghost_fun_neg ghost_fun_sub local attribute [instance] private def comm_ring_auxβ‚‚ : comm_ring (π•Ž (mv_polynomial R β„€)) := (map_fun.injective _ $ map_injective (int.cast_ring_hom β„š) int.cast_injective).comm_ring _ (map_fun.zero _) (map_fun.one _) (map_fun.add _) (map_fun.mul _) (map_fun.neg _) (map_fun.sub _) /-- The commutative ring structure on `π•Ž R`. -/ instance : comm_ring (π•Ž R) := (map_fun.surjective _ $ counit_surjective _).comm_ring (map_fun $ mv_polynomial.counit _) (map_fun.zero _) (map_fun.one _) (map_fun.add _) (map_fun.mul _) (map_fun.neg _) (map_fun.sub _) variables {p R} /-- `witt_vector.map f` is the ring homomorphism `π•Ž R β†’+* π•Ž S` naturally induced by a ring homomorphism `f : R β†’+* S`. It acts coefficientwise. -/ def map (f : R β†’+* S) : π•Ž R β†’+* π•Ž S := { to_fun := map_fun f, map_zero' := map_fun.zero f, map_one' := map_fun.one f, map_add' := map_fun.add f, map_mul' := map_fun.mul f } lemma map_injective (f : R β†’+* S) (hf : injective f) : injective (map f : π•Ž R β†’ π•Ž S) := map_fun.injective f hf lemma map_surjective (f : R β†’+* S) (hf : surjective f) : surjective (map f : π•Ž R β†’ π•Ž S) := map_fun.surjective f hf @[simp] lemma map_coeff (f : R β†’+* S) (x : π•Ž R) (n : β„•) : (map f x).coeff n = f (x.coeff n) := rfl /-- `witt_vector.ghost_map` is a ring homomorphism that maps each Witt vector to the sequence of its ghost components. -/ def ghost_map : π•Ž R β†’+* β„• β†’ R := { to_fun := ghost_fun, map_zero' := ghost_fun_zero, map_one' := ghost_fun_one, map_add' := ghost_fun_add, map_mul' := ghost_fun_mul } /-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`, producing a value in `R`. -/ def ghost_component (n : β„•) : π•Ž R β†’+* R := (ring_hom.apply _ n).comp ghost_map lemma ghost_component_apply (n : β„•) (x : π•Ž R) : ghost_component n x = aeval x.coeff (W_ β„€ n) := rfl @[simp] lemma ghost_map_apply (x : π•Ž R) (n : β„•) : ghost_map x n = ghost_component n x := rfl variables (p R) [invertible (p : R)] /-- `witt_vector.ghost_map` is a ring isomorphism when `p` is invertible in `R`. -/ def ghost_equiv : π•Ž R ≃+* (β„• β†’ R) := { .. (ghost_map : π•Ž R β†’+* (β„• β†’ R)), .. (ghost_equiv' p R) } @[simp] lemma ghost_equiv_coe : (ghost_equiv p R : π•Ž R β†’+* (β„• β†’ R)) = ghost_map := rfl lemma ghost_map.bijective_of_invertible : function.bijective (ghost_map : π•Ž R β†’ β„• β†’ R) := (ghost_equiv p R).bijective end witt_vector
81451fabb74ded7299faec7a17e309ce05a840bf
1a61aba1b67cddccce19532a9596efe44be4285f
/hott/algebra/e_closure.hlean
97b2365db6212ccd4bdee36e2954da7bea36b967
[ "Apache-2.0" ]
permissive
eigengrau/lean
07986a0f2548688c13ba36231f6cdbee82abf4c6
f8a773be1112015e2d232661ce616d23f12874d0
refs/heads/master
1,610,939,198,566
1,441,352,386,000
1,441,352,494,000
41,903,576
0
0
null
1,441,352,210,000
1,441,352,210,000
null
UTF-8
Lean
false
false
4,337
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn The "equivalence closure" of a type-valued relation. Given a binary type-valued relation (fibration), we add reflexivity, symmetry and transitivity terms -/ import .relation eq2 arity open eq inductive e_closure {A : Type} (R : A β†’ A β†’ Type) : A β†’ A β†’ Type := | of_rel : Ξ {a a'} (r : R a a'), e_closure R a a' | refl : Ξ a, e_closure R a a | symm : Ξ {a a'} (r : e_closure R a a'), e_closure R a' a | trans : Ξ {a a' a''} (r : e_closure R a a') (r' : e_closure R a' a''), e_closure R a a'' namespace e_closure infix `⬝r`:75 := e_closure.trans postfix `⁻¹ʳ`:(max+10) := e_closure.symm notation `[`:max a `]`:0 := e_closure.of_rel a abbreviation rfl {A : Type} {R : A β†’ A β†’ Type} {a : A} := refl R a end e_closure namespace relation section parameters {A : Type} (R : A β†’ A β†’ Type) local abbreviation T := e_closure R variables ⦃a a' : A⦄ {s : R a a'} {r : T a a} parameter {R} protected definition e_closure.elim [unfold 8] {B : Type} {f : A β†’ B} (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') (t : T a a') : f a = f a' := begin induction t, exact e r, reflexivity, exact v_0⁻¹, exact v_0 ⬝ v_1 end definition ap_e_closure_elim_h [unfold 12] {B C : Type} {f : A β†’ B} {g : B β†’ C} (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') {e' : Π⦃a a' : A⦄, R a a' β†’ g (f a) = g (f a')} (p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a') : ap g (e_closure.elim e t) = e_closure.elim e' t := begin induction t, apply p, reflexivity, exact ap_inv g (e_closure.elim e r) ⬝ inverse2 v_0, exact ap_con g (e_closure.elim e r) (e_closure.elim e r') ⬝ (v_0 β—Ύ v_1) end definition ap_e_closure_elim {B C : Type} {f : A β†’ B} (g : B β†’ C) (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') (t : T a a') : ap g (e_closure.elim e t) = e_closure.elim (Ξ»a a' r, ap g (e r)) t := ap_e_closure_elim_h e (Ξ»a a' s, idp) t definition ap_e_closure_elim_h_eq {B C : Type} {f : A β†’ B} {g : B β†’ C} (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') {e' : Π⦃a a' : A⦄, R a a' β†’ g (f a) = g (f a')} (p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a') : ap_e_closure_elim_h e p t = ap_e_closure_elim g e t ⬝ ap (Ξ»x, e_closure.elim x t) (eq_of_homotopy3 p) := begin fapply homotopy3.rec_on p, intro q, esimp at q, induction q, esimp, rewrite eq_of_homotopy3_id end theorem ap_ap_e_closure_elim_h {B C D : Type} {f : A β†’ B} {g : B β†’ C} (h : C β†’ D) (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') {e' : Π⦃a a' : A⦄, R a a' β†’ g (f a) = g (f a')} (p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a') : square (ap (ap h) (ap_e_closure_elim_h e p t)) (ap_e_closure_elim_h e (Ξ»a a' s, ap_compose h g (e s)) t) (ap_compose h g (e_closure.elim e t))⁻¹ (ap_e_closure_elim_h e' (Ξ»a a' s, (ap (ap h) (p s))⁻¹) t) := begin induction t, { esimp, apply square_of_eq, exact !con.right_inv ⬝ !con.left_inv⁻¹}, { apply ids}, { rewrite [β–Έ*,ap_con (ap h)], refine (transpose !ap_compose_inv)⁻¹ᡛ ⬝h _, rewrite [con_inv,inv_inv,-inv2_inv], exact !ap_inv2 ⬝v square_inv2 v_0}, { rewrite [β–Έ*,ap_con (ap h)], refine (transpose !ap_compose_con)⁻¹ᡛ ⬝h _, rewrite [con_inv,inv_inv,con2_inv], refine !ap_con2 ⬝v square_con2 v_0 v_1}, end theorem ap_ap_e_closure_elim {B C D : Type} {f : A β†’ B} (g : B β†’ C) (h : C β†’ D) (e : Π⦃a a' : A⦄, R a a' β†’ f a = f a') (t : T a a') : square (ap (ap h) (ap_e_closure_elim g e t)) (ap_e_closure_elim_h e (Ξ»a a' s, ap_compose h g (e s)) t) (ap_compose h g (e_closure.elim e t))⁻¹ (ap_e_closure_elim h (Ξ»a a' r, ap g (e r)) t) := !ap_ap_e_closure_elim_h open e_closure definition is_equivalence_e_closure : is_equivalence T := begin constructor, intro a, exact rfl, intro a a' t, exact t⁻¹ʳ, intro a a' a'' t t', exact t ⬝r t', end end end relation
02b3b3b53a6736e5451d85067752f2834f88b457
c777c32c8e484e195053731103c5e52af26a25d1
/src/analysis/special_functions/log/monotone.lean
f0981e4f14658b2b0e030afdf213a6661890a7f3
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
3,228
lean
/- Copyright (c) 2021 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey -/ import analysis.special_functions.pow /-! # Logarithm Tonality In this file we describe the tonality of the logarithm function when multiplied by functions of the form `x ^ a`. ## Tags logarithm, tonality -/ open set filter function open_locale topology noncomputable theory namespace real variables {x y : ℝ} lemma log_mul_self_monotone_on : monotone_on (Ξ» x : ℝ, log x * x) {x | 1 ≀ x} := begin -- TODO: can be strengthened to exp (-1) ≀ x simp only [monotone_on, mem_set_of_eq], intros x hex y hey hxy, have x_pos : 0 < x := lt_of_lt_of_le zero_lt_one hex, have y_pos : 0 < y := lt_of_lt_of_le zero_lt_one hey, refine mul_le_mul ((log_le_log x_pos y_pos).mpr hxy) hxy (le_of_lt x_pos) _, rwa [le_log_iff_exp_le y_pos, real.exp_zero], end lemma log_div_self_antitone_on : antitone_on (Ξ» x : ℝ, log x / x) {x | exp 1 ≀ x} := begin simp only [antitone_on, mem_set_of_eq], intros x hex y hey hxy, have x_pos : 0 < x := (exp_pos 1).trans_le hex, have y_pos : 0 < y := (exp_pos 1).trans_le hey, have hlogx : 1 ≀ log x := by rwa le_log_iff_exp_le x_pos, have hyx : 0 ≀ y / x - 1 := by rwa [le_sub_iff_add_le, le_div_iff x_pos, zero_add, one_mul], rw [div_le_iff y_pos, ←sub_le_sub_iff_right (log x)], calc log y - log x = log (y / x) : by rw [log_div (y_pos.ne') (x_pos.ne')] ... ≀ (y / x) - 1 : log_le_sub_one_of_pos (div_pos y_pos x_pos) ... ≀ log x * (y / x - 1) : le_mul_of_one_le_left hyx hlogx ... = log x / x * y - log x : by ring, end lemma log_div_self_rpow_antitone_on {a : ℝ} (ha : 0 < a) : antitone_on (Ξ» x : ℝ, log x / x ^ a) {x | exp (1 / a) ≀ x} := begin simp only [antitone_on, mem_set_of_eq], intros x hex y hey hxy, have x_pos : 0 < x := lt_of_lt_of_le (exp_pos (1 / a)) hex, have y_pos : 0 < y := by linarith, have x_nonneg : 0 ≀ x := le_trans (le_of_lt (exp_pos (1 / a))) hex, have y_nonneg : 0 ≀ y := by linarith, nth_rewrite 0 ←rpow_one y, nth_rewrite 0 ←rpow_one x, rw [←div_self (ne_of_lt ha).symm, div_eq_mul_one_div a a, rpow_mul y_nonneg, rpow_mul x_nonneg, log_rpow (rpow_pos_of_pos y_pos a), log_rpow (rpow_pos_of_pos x_pos a), mul_div_assoc, mul_div_assoc, mul_le_mul_left (one_div_pos.mpr ha)], { refine log_div_self_antitone_on _ _ _, { simp only [set.mem_set_of_eq], convert rpow_le_rpow _ hex (le_of_lt ha), rw ←exp_mul, simp only [real.exp_eq_exp], field_simp [(ne_of_lt ha).symm], exact le_of_lt (exp_pos (1 / a)), }, { simp only [set.mem_set_of_eq], convert rpow_le_rpow _ (trans hex hxy) (le_of_lt ha), rw ←exp_mul, simp only [real.exp_eq_exp], field_simp [(ne_of_lt ha).symm], exact le_of_lt (exp_pos (1 / a)), }, exact rpow_le_rpow x_nonneg hxy (le_of_lt ha), }, end lemma log_div_sqrt_antitone_on : antitone_on (Ξ» x : ℝ, log x / sqrt x) {x | exp 2 ≀ x} := begin simp_rw sqrt_eq_rpow, convert @log_div_self_rpow_antitone_on (1 / 2) (by norm_num), norm_num, end end real
c617e7160b52599840cb0a045e6cfab33615129d
0845ae2ca02071debcfd4ac24be871236c01784f
/library/init/data/dlist.lean
51a41cec0d7b9149ac8290985bd14e75e8fa7b60
[ "Apache-2.0" ]
permissive
GaloisInc/lean4
74c267eb0e900bfaa23df8de86039483ecbd60b7
228ddd5fdcd98dd4e9c009f425284e86917938aa
refs/heads/master
1,643,131,356,301
1,562,715,572,000
1,562,715,572,000
192,390,898
0
0
null
1,560,792,750,000
1,560,792,749,000
null
UTF-8
Lean
false
false
1,778
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import init.data.list.basic universes u /-- A difference List is a Function that, given a List, returns the original contents of the difference List prepended to the given List. This structure supports `O(1)` `append` and `concat` operations on lists, making it useful for append-heavy uses such as logging and pretty printing. -/ structure DList (Ξ± : Type u) := (apply : List Ξ± β†’ List Ξ±) (invariant : βˆ€ l, apply l = apply [] ++ l) namespace DList variables {Ξ± : Type u} open List def ofList (l : List Ξ±) : DList Ξ± := ⟨append l, fun t => (appendNil l).symm β–Έ rfl⟩ def empty : DList Ξ± := ⟨id, fun t => rfl⟩ instance : HasEmptyc (DList Ξ±) := ⟨DList.empty⟩ def toList : DList Ξ± β†’ List Ξ± | ⟨f, h⟩ := f [] def singleton (a : Ξ±) : DList Ξ± := ⟨fun t => a :: t, fun t => rfl⟩ def cons : Ξ± β†’ DList Ξ± β†’ DList Ξ± | a ⟨f, h⟩ := ⟨fun t => a :: f t, fun t => show a :: f t = a :: f [] ++ t from have h₁ : a :: f t = a :: (f nil ++ t) := h t β–Έ rfl; have hβ‚‚ : a :: (f nil ++ t) = a :: f nil ++ t := (consAppend _ _ _).symm; Eq.trans h₁ hβ‚‚βŸ© def append : DList Ξ± β†’ DList Ξ± β†’ DList Ξ± | ⟨f, hβ‚βŸ© ⟨g, hβ‚‚βŸ© := ⟨f ∘ g, fun t => show f (g t) = (f (g [])) ++ t from (h₁ (g [])).symm β–Έ (appendAssoc (f []) (g []) t).symm β–Έ hβ‚‚ t β–Έ h₁ (g t) β–Έ rfl⟩ def push : DList Ξ± β†’ Ξ± β†’ DList Ξ± | ⟨f, h⟩ a := ⟨fun t => f (a :: t), fun t => (h (a::t)).symm β–Έ (h [a]).symm β–Έ (appendAssoc (f []) [a] t).symm β–Έ rfl⟩ instance : HasAppend (DList Ξ±) := ⟨DList.append⟩ end DList
5871f6ef68d0d0fa218b81051f0693797e476cb9
947b78d97130d56365ae2ec264df196ce769371a
/tests/lean/run/newfrontend3.lean
a37b013e91739885d576147798d567fc34719962
[ "Apache-2.0" ]
permissive
shyamalschandra/lean4
27044812be8698f0c79147615b1d5090b9f4b037
6e7a883b21eaf62831e8111b251dc9b18f40e604
refs/heads/master
1,671,417,126,371
1,601,859,995,000
1,601,860,020,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
494
lean
new_frontend structure S := (g {Ξ±} : Ξ± β†’ Ξ±) def f (h : Nat β†’ ({Ξ± : Type} β†’ Ξ± β†’ Ξ±) Γ— Bool) : Nat := (h 0).1 1 def tst : Nat := f fun n => (fun x => x, true) theorem ex : id (Nat β†’ Nat) := by { intro; assumption } def g (i j k : Nat) (a : Array Nat) (h₁ : i < k) (hβ‚‚ : k < j) (h₃ : j < a.size) : Nat := let vj := a.get ⟨j, hβ‚ƒβŸ©; let vi := a.get ⟨i, Nat.ltTrans h₁ (Nat.ltTrans hβ‚‚ h₃)⟩; vi + vj set_option pp.all true in #print g #check g.proof_1
86546f11b324e5780013ad2136665859cde10b36
957a80ea22c5abb4f4670b250d55534d9db99108
/library/init/meta/congr_tactic.lean
2d850fb7493b11a9d9bd5f83da4f4896ff83ea42
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
2,005
lean
/- Copyright (c) 2017 Daniel Selsam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Daniel Selsam -/ prelude import init.meta.tactic init.meta.congr_lemma init.meta.relation_tactics init.function namespace tactic meta def apply_congr_core (clemma : congr_lemma) : tactic unit := do assert `H_congr_lemma clemma.type, exact clemma.proof, get_local `H_congr_lemma >>= apply, all_goals $ do try (applyc `heq_of_eq), get_local `H_congr_lemma >>= clear meta def apply_eq_congr_core (tgt : expr) : tactic unit := do (lhs, rhs) ← match_eq tgt, guard lhs.is_app, clemma ← mk_specialized_congr_lemma lhs, apply_congr_core clemma meta def apply_heq_congr_core : tactic unit := do try (applyc `eq_of_heq), (Ξ±, lhs, Ξ², rhs) ← target >>= match_heq, guard lhs.is_app, clemma ← mk_hcongr_lemma lhs.get_app_fn lhs.get_app_num_args, apply_congr_core clemma meta def apply_rel_iff_congr_core (tgt : expr) : tactic unit := do (lhs, rhs) ← match_iff tgt, guard lhs.is_app, clemma ← mk_rel_iff_congr_lemma lhs.get_app_fn, apply_congr_core clemma meta def apply_rel_eq_congr_core (tgt : expr) : tactic unit := do (lhs, rhs) ← match_eq tgt, guard lhs.is_app, clemma ← mk_rel_eq_congr_lemma lhs.get_app_fn, apply_congr_core clemma meta def congr_core : tactic unit := do tgt ← target, apply_eq_congr_core tgt <|> apply_heq_congr_core <|> fail "congr tactic failed" meta def rel_congr_core : tactic unit := do tgt ← target, apply_rel_iff_congr_core tgt <|> apply_rel_eq_congr_core tgt <|> fail "rel_congr tactic failed" meta def congr : tactic unit := do focus1 (try assumption >> congr_core >> all_goals (try reflexivity >> try congr)) meta def rel_congr : tactic unit := do focus1 (try assumption >> rel_congr_core >> all_goals (try reflexivity)) namespace interactive meta def congr := tactic.congr meta def rel_congr := tactic.rel_congr end interactive end tactic
b1dfe3e0d71eea14ba0b9f13095a1797bef918d0
a9fe717b93ccfa4b2e64faeb24f96dfefb390240
/int/dnf.lean
5ee5c661be6cda034f9fe91ba532ab1e0d28ed31
[]
no_license
skbaek/omega
ab1f4a6daadfc8c855f14c39d9459ab841527141
715e384ed14e8eb177a326700066e7c98269e078
refs/heads/master
1,588,000,876,352
1,552,645,917,000
1,552,645,917,000
174,442,914
1
0
null
null
null
null
UTF-8
Lean
false
false
7,516
lean
import .form ..clause namespace int @[omega] def push_neg : form β†’ form | (p ∨* q) := (push_neg p) ∧* (push_neg q) | (p ∧* q) := (push_neg p) ∨* (push_neg q) | (Β¬*p) := p | p := Β¬* p lemma push_neg_equiv : βˆ€ {p}, form.equiv (push_neg p) (Β¬* p) := begin form.induce `[intros v; try {refl}], { simp_omega [classical.not_not] }, { simp only [form.holds, push_neg, not_or_distrib, ihp v, ihq v] }, { simp only [form.holds, push_neg, classical.not_and_distrib, ihp v, ihq v] } end def nnf : form β†’ form | (Β¬* p) := push_neg (nnf p) | (p ∨* q) := (nnf p) ∨* (nnf q) | (p ∧* q) := (nnf p) ∧* (nnf q) | a := a def is_nnf : form β†’ Prop | (t =* s) := true | (t ≀* s) := true | Β¬*(t =* s) := true | Β¬*(t ≀* s) := true | (p ∨* q) := is_nnf p ∧ is_nnf q | (p ∧* q) := is_nnf p ∧ is_nnf q | _ := false lemma is_nnf_push_neg : βˆ€ p, is_nnf p β†’ is_nnf (push_neg p) := begin form.induce `[intro h1; try {trivial}], { cases p; try {cases h1}; trivial }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption } end def neg_free : form β†’ Prop | (t =* s) := true | (t ≀* s) := true | (p ∨* q) := neg_free p ∧ neg_free q | (p ∧* q) := neg_free p ∧ neg_free q | _ := false lemma is_nnf_nnf : βˆ€ p, is_nnf (nnf p) := begin form.induce `[try {trivial}], { apply is_nnf_push_neg _ ih }, { constructor; assumption }, { constructor; assumption } end lemma nnf_equiv : βˆ€ {p : form}, form.equiv (nnf p) p := begin form.induce `[intros v; try {refl}; simp only [nnf]], { rw push_neg_equiv, apply not_iff_not_of_iff, apply ih }, { apply or_iff_or (ihp v) (ihq v) }, { apply and_iff_and (ihp v) (ihq v) } end @[omega] def neg_elim : form β†’ form | (Β¬* (t =* s)) := (t.succ ≀* s) ∨* (s.succ ≀* t) | (Β¬* (t ≀* s)) := s.succ ≀* t | (p ∨* q) := (neg_elim p) ∨* (neg_elim q) | (p ∧* q) := (neg_elim p) ∧* (neg_elim q) | p := p lemma neg_free_neg_elim : βˆ€ p, is_nnf p β†’ neg_free (neg_elim p) := begin form.induce `[intro h1, try {simp only [neg_free, neg_elim]}, try {trivial}], { cases p; try {cases h1}; try {trivial}, constructor; trivial }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption } end lemma le_and_le_iff_eq {Ξ± : Type} [partial_order Ξ±] {a b : Ξ±} : (a ≀ b ∧ b ≀ a) ↔ a = b := begin constructor; intro h1, { cases h1, apply le_antisymm; assumption }, { constructor; apply le_of_eq; rw h1 } end lemma implies_neg_elim : βˆ€ {p : form}, form.implies p (neg_elim p) := begin form.induce `[intros v h, try {apply h}], { cases p with t s t s; try {apply h}, { simp_omega [le_and_le_iff_eq.symm, classical.not_and_distrib, not_le] at h, simp_omega [int.add_one_le_iff], rw or.comm, assumption }, { simp_omega [not_le, int.add_one_le_iff] at *, assumption} }, { simp only [neg_elim], cases h; [{left, apply ihp}, {right, apply ihq}]; assumption }, { apply and_of_and (ihp _) (ihq _) h } end @[omega] def dnf_core : form β†’ list clause | (p ∨* q) := (dnf_core p) ++ (dnf_core q) | (p ∧* q) := (list.product (dnf_core p) (dnf_core q)).map (Ξ» pq, clause.append pq.fst pq.snd) | (t =* s) := [([term.sub (canonize s) (canonize t)],[])] | (t ≀* s) := [([],[term.sub (canonize s) (canonize t)])] | (Β¬* _) := [] def dnf (p : form) : list clause := dnf_core $ neg_elim $ nnf p lemma exists_clause_holds {v} : βˆ€ {p : form}, neg_free p β†’ p.holds v β†’ βˆƒ c ∈ (dnf_core p), clause.holds v c := begin form.induce `[intros h1 h2], { apply list.exists_mem_cons_of, constructor, { simp_omega at h2, rw [list.forall_mem_singleton], simp_omega [h2] }, { apply list.forall_mem_nil } }, { apply list.exists_mem_cons_of, constructor, { apply list.forall_mem_nil }, { simp_omega at h2, rw [list.forall_mem_singleton], simp_omega, rw [le_sub, sub_zero], assumption } }, { cases h1 }, { cases h2 with h2 h2; [ {cases (ihp h1.left h2) with c h3}, {cases (ihq h1.right h2) with c h3}]; cases h3 with h3 h4; refine ⟨c, list.mem_append.elim_right _, h4⟩; [left,right]; assumption }, { rcases (ihp h1.left h2.left) with ⟨cp, hp1, hp2⟩, rcases (ihq h1.right h2.right) with ⟨cq, hq1, hq2⟩, constructor, constructor, simp_omega, rw list.mem_map, constructor, constructor, rw list.mem_product, constructor; assumption, refl, apply clause.holds_append; assumption } end lemma clauses_sat_dnf_core {p : form} : neg_free p β†’ p.sat β†’ clauses.sat (dnf_core p) := begin intros h1 h2, cases h2 with v h2, rcases (exists_clause_holds h1 h2) with ⟨c,h3,h4⟩, refine ⟨c,h3,v,h4⟩ end lemma unsat_of_clauses_unsat {p : form} : clauses.unsat (dnf p) β†’ p.unsat := begin intros h1 h2, apply h1, apply clauses_sat_dnf_core, apply neg_free_neg_elim _ (is_nnf_nnf _), apply form.sat_of_implies_of_sat implies_neg_elim, have hrw := exists_iff_exists (@nnf_equiv p), apply hrw.elim_right h2 end #exit @[omega] def dnf_core : form β†’ list polytope | (p ∨* q) := (dnf_core p) ++ (dnf_core q) | (p ∧* q) := (list.product (dnf_core p) (dnf_core q)).map (Ξ» pq, pq.fst ++ pq.snd) | (t =* s) := [[term.sub (canonize s) (canonize t), term.sub (canonize t) (canonize s)]] | (t ≀* s) := [[term.sub (canonize s) (canonize t)]] | (Β¬* _) := [] def dnf (p : form) : list polytope := dnf_core $ nf $ nnf p lemma exists_polytope_holds {v} : βˆ€ {p : form}, neg_free p β†’ p.holds v β†’ βˆƒ c ∈ (dnf_core p), polytope.holds v c := begin form.induce `[intros h1 h2], { apply list.exists_mem_cons_of, --constructor, simp only [polytope.holds], rw list.forall_mem_cons, constructor, { simp_omega at *, rw [h2, sub_self] }, { rw list.forall_mem_singleton, simp_omega at *, rw [h2, sub_self] } }, { apply list.exists_mem_cons_of, simp only [polytope.holds], rw list.forall_mem_singleton, simp_omega at *, rw [le_sub, sub_zero], assumption }, { cases h1 }, { cases h2 with h2 h2; [ {cases (ihp h1.left h2) with c h3}, {cases (ihq h1.right h2) with c h3}]; cases h3 with h3 h4; refine ⟨c, list.mem_append.elim_right _, h4⟩; [left,right]; assumption }, { rcases (ihp h1.left h2.left) with ⟨cp, hp1, hp2⟩, rcases (ihq h1.right h2.right) with ⟨cq, hq1, hq2⟩, constructor, constructor, simp_omega, rw list.mem_map, constructor, constructor, rw list.mem_product, constructor; assumption, refl, simp only [polytope.holds, list.forall_mem_append], apply and.intro hp2 hq2 } end lemma exists_polytope_sat {p : form} : neg_free p β†’ p.sat β†’ βˆƒ c ∈ (dnf_core p), polytope.sat c := begin intros h1 h2, cases h2 with v h2, rcases (exists_polytope_holds h1 h2) with ⟨c,h3,h4⟩, refine ⟨c,h3,v,h4⟩ end lemma unsat_of_unsat_dnf {p : form} : polytopes.unsat (dnf p) β†’ p.unsat := begin intros h1 h2, dsimp only [polytopes.unsat] at h1, rw ← list.not_exists_mem_not at h1, apply h1, simp only [polytope.unsat, classical.not_not], apply exists_polytope_sat (neg_free_nf _ (is_nnf_nnf _)), apply form.sat_of_implies_of_sat implies_nf, have hrw := exists_iff_exists (@nnf_equiv p), apply hrw.elim_right h2 end end int
ebd760eb00396fc0755d4a9651800de7c2a98829
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/complex/phragmen_lindelof.lean
f243effb84056507b98ffe650716eb425c9d17c7
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
49,501
lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.complex.abs_max import analysis.asymptotics.superpolynomial_decay /-! # Phragmen-LindelΓΆf principle In this file we prove several versions of the Phragmen-LindelΓΆf principle, a version of the maximum modulus principle for an unbounded domain. ## Main statements * `phragmen_lindelof.horizontal_strip`: the Phragmen-LindelΓΆf principle in a horizontal strip `{z : β„‚ | a < complex.im z < b}`; * `phragmen_lindelof.eq_zero_on_horizontal_strip`, `phragmen_lindelof.eq_on_horizontal_strip`: extensionality lemmas based on the Phragmen-LindelΓΆf principle in a horizontal strip; * `phragmen_lindelof.vertical_strip`: the Phragmen-LindelΓΆf principle in a vertical strip `{z : β„‚ | a < complex.re z < b}`; * `phragmen_lindelof.eq_zero_on_vertical_strip`, `phragmen_lindelof.eq_on_vertical_strip`: extensionality lemmas based on the Phragmen-LindelΓΆf principle in a vertical strip; * `phragmen_lindelof.quadrant_I`, `phragmen_lindelof.quadrant_II`, `phragmen_lindelof.quadrant_III`, `phragmen_lindelof.quadrant_IV`: the Phragmen-LindelΓΆf principle in the coordinate quadrants; * `phragmen_lindelof.right_half_plane_of_tendsto_zero_on_real`, `phragmen_lindelof.right_half_plane_of_bounded_on_real`: two versions of the Phragmen-LindelΓΆf principle in the right half-plane; * `phragmen_lindelof.eq_zero_on_right_half_plane_of_superexponential_decay`, `phragmen_lindelof.eq_on_right_half_plane_of_superexponential_decay`: extensionality lemmas based on the Phragmen-LindelΓΆf principle in the right half-plane. In the case of the right half-plane, we prove a version of the Phragmen-LindelΓΆf principle that is useful for Ilyashenko's proof of the individual finiteness theorem (a polynomial vector field on the real plane has only finitely many limit cycles). -/ open set function filter asymptotics metric complex open_locale topological_space filter real local notation `expR` := real.exp namespace phragmen_lindelof /-! ### Auxiliary lemmas -/ variables {E : Type*} [normed_group E] /-- An auxiliary lemma that combines two double exponential estimates into a similar estimate on the difference of the functions. -/ lemma is_O_sub_exp_exp {a : ℝ} {f g : β„‚ β†’ E} {l : filter β„‚} {u : β„‚ β†’ ℝ} (hBf : βˆƒ (c < a) B, f =O[l] (Ξ» z, expR (B * expR (c * |u z|)))) (hBg : βˆƒ (c < a) B, g =O[l] (Ξ» z, expR (B * expR (c * |u z|)))) : βˆƒ (c < a) B, (f - g) =O[l] (Ξ» z, expR (B * expR (c * |u z|))) := begin have : βˆ€ {c₁ cβ‚‚ B₁ Bβ‚‚}, c₁ ≀ cβ‚‚ β†’ 0 ≀ Bβ‚‚ β†’ B₁ ≀ Bβ‚‚ β†’ βˆ€ z, βˆ₯expR (B₁ * expR (c₁ * |u z|))βˆ₯ ≀ βˆ₯expR (Bβ‚‚ * expR (cβ‚‚ * |u z|))βˆ₯, { intros c₁ cβ‚‚ B₁ Bβ‚‚ hc hBβ‚€ hB z, rw [real.norm_eq_abs, real.norm_eq_abs, real.abs_exp, real.abs_exp, real.exp_le_exp], exact mul_le_mul hB (real.exp_le_exp.2 $ mul_le_mul_of_nonneg_right hc $ abs_nonneg _) (real.exp_pos _).le hBβ‚€ }, rcases hBf with ⟨cf, hcf, Bf, hOf⟩, rcases hBg with ⟨cg, hcg, Bg, hOg⟩, refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩, refine (hOf.trans_le $ this _ _ _).sub (hOg.trans_le $ this _ _ _), exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _), le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)] end /-- An auxiliary lemma that combines two β€œexponential of a power” estimates into a similar estimate on the difference of the functions. -/ lemma is_O_sub_exp_rpow {a : ℝ} {f g : β„‚ β†’ E} {l : filter β„‚} (hBf : βˆƒ (c < a) B, f =O[comap complex.abs at_top βŠ“ l] (Ξ» z, expR (B * (abs z) ^ c))) (hBg : βˆƒ (c < a) B, g =O[comap complex.abs at_top βŠ“ l] (Ξ» z, expR (B * (abs z) ^ c))) : βˆƒ (c < a) B, (f - g) =O[comap complex.abs at_top βŠ“ l] (Ξ» z, expR (B * (abs z) ^ c)) := begin have : βˆ€ {c₁ cβ‚‚ B₁ Bβ‚‚ : ℝ}, c₁ ≀ cβ‚‚ β†’ 0 ≀ Bβ‚‚ β†’ B₁ ≀ Bβ‚‚ β†’ (Ξ» z : β„‚, expR (B₁ * (abs z) ^ c₁)) =O[comap complex.abs at_top βŠ“ l] (Ξ» z, expR (Bβ‚‚ * (abs z) ^ cβ‚‚)), { have : βˆ€αΆ  z : β„‚ in comap abs at_top βŠ“ l, 1 ≀ abs z, from ((eventually_ge_at_top 1).comap _).filter_mono inf_le_left, refine Ξ» c₁ cβ‚‚ B₁ Bβ‚‚ hc hBβ‚€ hB, is_O.of_bound 1 (this.mono $ Ξ» z hz, _), rw [one_mul, real.norm_eq_abs, real.norm_eq_abs, real.abs_exp, real.abs_exp, real.exp_le_exp], exact mul_le_mul hB (real.rpow_le_rpow_of_exponent_le hz hc) (real.rpow_nonneg_of_nonneg (abs_nonneg _) _) hBβ‚€ }, rcases hBf with ⟨cf, hcf, Bf, hOf⟩, rcases hBg with ⟨cg, hcg, Bg, hOg⟩, refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩, refine (hOf.trans $ this _ _ _).sub (hOg.trans $ this _ _ _), exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _), le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)] end variables [normed_space β„‚ E] {a b C : ℝ} {f g : β„‚ β†’ E} {z : β„‚} /-! ### Phragmen-LindelΓΆf principle in a horizontal strip -/ /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < im z < b}`. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable on `U` and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < Ο€ / (b - a)`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of `U`. Then `βˆ₯f zβˆ₯` is bounded by the same constant on the closed strip `{z : β„‚ | a ≀ im z ≀ b}`. Moreover, it suffices to verify the second assumption only for sufficiently large values of `|re z|`. -/ lemma horizontal_strip (hfd : diff_cont_on_cl β„‚ f (im ⁻¹' Ioo a b)) (hB : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top βŠ“ π“Ÿ (im ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.re|)))) (hle_a : βˆ€ z : β„‚, im z = a β†’ βˆ₯f zβˆ₯ ≀ C) (hle_b : βˆ€ z, im z = b β†’ βˆ₯f zβˆ₯ ≀ C) (hza : a ≀ im z) (hzb : im z ≀ b) : βˆ₯f zβˆ₯ ≀ C := begin -- If `im z = a` or `im z = b`, then we apply `hle_a` or `hle_b`, otherwise `im z ∈ Ioo a b`. rw le_iff_eq_or_lt at hza hzb, cases hza with hza hza, { exact hle_a _ hza.symm }, cases hzb with hzb hzb, { exact hle_b _ hzb }, -- WLOG, `0 < C`. suffices : βˆ€ C' : ℝ, 0 < C' β†’ (βˆ€ w : β„‚, im w = a β†’ βˆ₯f wβˆ₯ ≀ C') β†’ (βˆ€ w : β„‚, im w = b β†’ βˆ₯f wβˆ₯ ≀ C') β†’ βˆ₯f zβˆ₯ ≀ C', { refine le_of_forall_le_of_dense (Ξ» C' hC', this C' _ (Ξ» w hw, _) (Ξ» w hw, _)), { refine ((norm_nonneg (f (a * I))).trans (hle_a _ _)).trans_lt hC', rw [mul_I_im, of_real_re] }, exacts [(hle_a _ hw).trans hC'.le, (hle_b _ hw).trans hC'.le] }, clear_dependent C, intros C hCβ‚€ hle_a hle_b, -- After a change of variables, we deal with the strip `a - b < im z < a + b` instead -- of `a < im z < b` obtain ⟨a, b, rfl, rfl⟩ : βˆƒ a' b', a = a' - b' ∧ b = a' + b' := ⟨(a + b) / 2, (b - a) / 2, by ring, by ring⟩, have hab : a - b < a + b, from hza.trans hzb, have hb : 0 < b, by simpa only [sub_eq_add_neg, add_lt_add_iff_left, neg_lt_self_iff] using hab, rw [add_sub_sub_cancel, ← two_mul, div_mul_eq_div_div] at hB, have hΟ€b : 0 < Ο€ / 2 / b, from div_pos real.pi_div_two_pos hb, -- Choose some `c B : ℝ` satisfying `hB`, then choose `max c 0 < d < Ο€ / 2 / b`. rcases hB with ⟨c, hc, B, hO⟩, obtain ⟨d, ⟨hcd, hdβ‚€βŸ©, hd⟩ : βˆƒ d, (c < d ∧ 0 < d) ∧ d < Ο€ / 2 / b, by simpa only [max_lt_iff] using exists_between (max_lt hc hΟ€b), have hb' : d * b < Ο€ / 2, from (lt_div_iff hb).1 hd, set aff : β„‚ β†’ β„‚ := Ξ» w, d * (w - a * I), set g : ℝ β†’ β„‚ β†’ β„‚ := Ξ» Ξ΅ w, exp (Ξ΅ * (exp (aff w) + exp (-aff w))), /- Since `g Ξ΅ z β†’ 1` as `Ξ΅ β†’ 0⁻`, it suffices to prove that `βˆ₯g Ξ΅ z β€’ f zβˆ₯ ≀ C` for all negative `Ξ΅`. -/ suffices : βˆ€αΆ  Ξ΅ : ℝ in 𝓝[<] 0, βˆ₯g Ξ΅ z β€’ f zβˆ₯ ≀ C, { refine le_of_tendsto (tendsto.mono_left _ nhds_within_le_nhds) this, apply ((continuous_of_real.mul continuous_const).cexp.smul continuous_const).norm.tendsto', simp, apply_instance }, filter_upwards [self_mem_nhds_within] with Ξ΅ Ξ΅β‚€, change Ξ΅ < 0 at Ξ΅β‚€, -- An upper estimate on `βˆ₯g Ξ΅ wβˆ₯` that will be used in two branches of the proof. obtain ⟨δ, Ξ΄β‚€, hδ⟩ : βˆƒ Ξ΄ : ℝ, Ξ΄ < 0 ∧ βˆ€ ⦃w⦄, im w ∈ Icc (a - b) (a + b) β†’ abs (g Ξ΅ w) ≀ expR (Ξ΄ * expR (d * |re w|)), { refine ⟨Ρ * real.cos (d * b), mul_neg_of_neg_of_pos Ξ΅β‚€ (real.cos_pos_of_mem_Ioo $ abs_lt.1 $ (abs_of_pos (mul_pos hdβ‚€ hb)).symm β–Έ hb'), Ξ» w hw, _⟩, replace hw : |im (aff w)| ≀ d * b, { rw [← real.closed_ball_eq_Icc] at hw, rwa [of_real_mul_im, sub_im, mul_I_im, of_real_re, _root_.abs_mul, abs_of_pos hdβ‚€, mul_le_mul_left hdβ‚€] }, simpa only [of_real_mul_re, _root_.abs_mul, abs_of_pos hdβ‚€, sub_re, mul_I_re, of_real_im, zero_mul, neg_zero, sub_zero] using abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le Ξ΅β‚€.le hw hb'.le }, -- `abs (g Ξ΅ w) ≀ 1` on the lines `w.im = a Β± b` (actually, it holds everywhere in the strip) have hg₁ : βˆ€ w, (im w = a - b ∨ im w = a + b) β†’ abs (g Ξ΅ w) ≀ 1, { refine Ξ» w hw, (hΞ΄ $ hw.by_cases _ _).trans (real.exp_le_one_iff.2 _), exacts [Ξ» h, h.symm β–Έ left_mem_Icc.2 hab.le, Ξ» h, h.symm β–Έ right_mem_Icc.2 hab.le, mul_nonpos_of_nonpos_of_nonneg Ξ΄β‚€.le (real.exp_pos _).le] }, /- Our apriori estimate on `f` implies that `g Ξ΅ w β€’ f w β†’ 0` as `|w.re| β†’ ∞` along the strip. In particular, its norm is less than or equal to `C` for sufficiently large `|w.re|`. -/ obtain ⟨R, hzR, hR⟩ : βˆƒ R : ℝ, |z.re| < R ∧ βˆ€ w, |re w| = R β†’ im w ∈ Ioo (a - b) (a + b) β†’ βˆ₯g Ξ΅ w β€’ f wβˆ₯ ≀ C, { refine ((eventually_gt_at_top _).and _).exists, rcases hO.exists_pos with ⟨A, hAβ‚€, hA⟩, simp only [is_O_with_iff, eventually_inf_principal, eventually_comap, mem_Ioo, ← abs_lt, mem_preimage, (∘), real.norm_eq_abs, abs_of_pos (real.exp_pos _)] at hA, suffices : tendsto (Ξ» R, expR (Ξ΄ * expR (d * R) + B * expR (c * R) + real.log A)) at_top (𝓝 0), { filter_upwards [this.eventually (ge_mem_nhds hCβ‚€), hA] with R hR Hle w hre him, calc βˆ₯g Ξ΅ w β€’ f wβˆ₯ ≀ expR (Ξ΄ * expR (d * R) + B * expR (c * R) + real.log A) : _ ... ≀ C : hR, rw [norm_smul, real.exp_add, ← hre, real.exp_add, real.exp_log hAβ‚€, mul_assoc, mul_comm _ A], exact mul_le_mul (hΞ΄ $ Ioo_subset_Icc_self him) (Hle _ hre him) (norm_nonneg _) (real.exp_pos _).le }, refine real.tendsto_exp_at_bot.comp _, suffices H : tendsto (Ξ» R, Ξ΄ + B * (expR ((d - c) * R))⁻¹) at_top (𝓝 (Ξ΄ + B * 0)), { rw [mul_zero, add_zero] at H, refine tendsto.at_bot_add _ tendsto_const_nhds, simpa only [id, (∘), add_mul, mul_assoc, ← div_eq_inv_mul, ← real.exp_sub, ← sub_mul, sub_sub_cancel] using H.neg_mul_at_top Ξ΄β‚€ (real.tendsto_exp_at_top.comp $ tendsto_const_nhds.mul_at_top hdβ‚€ tendsto_id) }, refine tendsto_const_nhds.add (tendsto_const_nhds.mul _), exact tendsto_inv_at_top_zero.comp (real.tendsto_exp_at_top.comp $ tendsto_const_nhds.mul_at_top (sub_pos.2 hcd) tendsto_id) }, have hRβ‚€ : 0 < R, from (_root_.abs_nonneg _).trans_lt hzR, /- Finally, we apply the bounded version of the maximum modulus principle to the rectangle `(-R, R) Γ— (a - b, a + b)`. The function is bounded by `C` on the horizontal sides by assumption (and because `βˆ₯g Ξ΅ wβˆ₯ ≀ 1`) and on the vertical sides by the choice of `R`. -/ have hgd : differentiable β„‚ (g Ξ΅), from ((((differentiable_id.sub_const _).const_mul _).cexp.add ((differentiable_id.sub_const _).const_mul _).neg.cexp).const_mul _).cexp, replace hd : diff_cont_on_cl β„‚ (Ξ» w, g Ξ΅ w β€’ f w) (Ioo (-R) R Γ—β„‚ Ioo (a - b) (a + b)), from (hgd.diff_cont_on_cl.smul hfd).mono (inter_subset_right _ _), convert norm_le_of_forall_mem_frontier_norm_le ((bounded_Ioo _ _).re_prod_im (bounded_Ioo _ _)) hd (Ξ» w hw, _) _, { have hwc := frontier_subset_closure hw, rw [frontier_re_prod_im, closure_Ioo (neg_lt_self hRβ‚€).ne, frontier_Ioo hab, closure_Ioo hab.ne, frontier_Ioo (neg_lt_self hRβ‚€)] at hw, by_cases him : w.im = a - b ∨ w.im = a + b, { rw [closure_re_prod_im, closure_Ioo (neg_lt_self hRβ‚€).ne] at hwc, rw [norm_smul, ← one_mul C], exact mul_le_mul (hg₁ _ him) (him.by_cases (hle_a _) (hle_b _)) (norm_nonneg _) zero_le_one }, { replace hw : w ∈ {-R, R} Γ—β„‚ Icc (a - b) (a + b), from hw.resolve_left (Ξ» h, him h.2), have hw' := eq_endpoints_or_mem_Ioo_of_mem_Icc hw.2, rw ← or.assoc at hw', exact hR _ ((abs_eq hRβ‚€.le).2 hw.1.symm) (hw'.resolve_left him) } }, { rw [closure_re_prod_im, closure_Ioo hab.ne, closure_Ioo (neg_lt_self hRβ‚€).ne], exact ⟨abs_le.1 hzR.le, ⟨hza.le, hzb.le⟩⟩ } end /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < im z < b}`. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable on `U` and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < Ο€ / (b - a)`; * `f z = 0` on the boundary of `U`. Then `f` is equal to zero on the closed strip `{z : β„‚ | a ≀ im z ≀ b}`. -/ lemma eq_zero_on_horizontal_strip (hd : diff_cont_on_cl β„‚ f (im ⁻¹' Ioo a b)) (hB : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top βŠ“ π“Ÿ (im ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.re|)))) (ha : βˆ€ z : β„‚, z.im = a β†’ f z = 0) (hb : βˆ€ z : β„‚, z.im = b β†’ f z = 0) : eq_on f 0 (im ⁻¹' Icc a b) := Ξ» z hz, norm_le_zero_iff.1 $ horizontal_strip hd hB (Ξ» z hz, (ha z hz).symm β–Έ norm_zero.le) (Ξ» z hz, (hb z hz).symm β–Έ norm_zero.le) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < im z < b}`. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable on `U` and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < Ο€ / (b - a)`; * `f z = g z` on the boundary of `U`. Then `f` is equal to `g` on the closed strip `{z : β„‚ | a ≀ im z ≀ b}`. -/ lemma eq_on_horizontal_strip {g : β„‚ β†’ E} (hdf : diff_cont_on_cl β„‚ f (im ⁻¹' Ioo a b)) (hBf : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top βŠ“ π“Ÿ (im ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.re|)))) (hdg : diff_cont_on_cl β„‚ g (im ⁻¹' Ioo a b)) (hBg : βˆƒ (c < Ο€ / (b - a)) B, g =O[comap (has_abs.abs ∘ re) at_top βŠ“ π“Ÿ (im ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.re|)))) (ha : βˆ€ z : β„‚, z.im = a β†’ f z = g z) (hb : βˆ€ z : β„‚, z.im = b β†’ f z = g z) : eq_on f g (im ⁻¹' Icc a b) := Ξ» z hz, sub_eq_zero.1 (eq_zero_on_horizontal_strip (hdf.sub hdg) (is_O_sub_exp_exp hBf hBg) (Ξ» w hw, sub_eq_zero.2 (ha w hw)) (Ξ» w hw, sub_eq_zero.2 (hb w hw)) hz) /-! ### Phragmen-LindelΓΆf principle in a vertical strip -/ /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < re z < b}`. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable on `U` and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < Ο€ / (b - a)`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of `U`. Then `βˆ₯f zβˆ₯` is bounded by the same constant on the closed strip `{z : β„‚ | a ≀ re z ≀ b}`. Moreover, it suffices to verify the second assumption only for sufficiently large values of `|im z|`. -/ lemma vertical_strip (hfd : diff_cont_on_cl β„‚ f (re ⁻¹' Ioo a b)) (hB : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top βŠ“ π“Ÿ (re ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.im|)))) (hle_a : βˆ€ z : β„‚, re z = a β†’ βˆ₯f zβˆ₯ ≀ C) (hle_b : βˆ€ z, re z = b β†’ βˆ₯f zβˆ₯ ≀ C) (hza : a ≀ re z) (hzb : re z ≀ b) : βˆ₯f zβˆ₯ ≀ C := begin suffices : βˆ₯(Ξ» z, f (z * (-I))) (z * I)βˆ₯ ≀ C, by simpa [mul_assoc] using this, have H : maps_to (Ξ» z, z * (-I)) (im ⁻¹' Ioo a b) (re ⁻¹' Ioo a b), { intros z hz, simpa using hz }, refine horizontal_strip (hfd.comp (differentiable_id.mul_const _).diff_cont_on_cl H) _ (Ξ» z hz, hle_a _ _) (Ξ» z hz, hle_b _ _) _ _, { refine Exists₃.imp (Ξ» c hc B hO, _) hB, have : tendsto (Ξ» z, z * (-I)) (comap (has_abs.abs ∘ re) at_top βŠ“ π“Ÿ (im ⁻¹' Ioo a b)) (comap (has_abs.abs ∘ im) at_top βŠ“ π“Ÿ (re ⁻¹' Ioo a b)), { refine (tendsto_comap_iff.2 _).inf H.tendsto, simpa [(∘)] using tendsto_comap }, simpa [(∘)] using hO.comp_tendsto this }, all_goals { simpa } end /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < re z < b}`. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable on `U` and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < Ο€ / (b - a)`; * `f z = 0` on the boundary of `U`. Then `f` is equal to zero on the closed strip `{z : β„‚ | a ≀ re z ≀ b}`. -/ lemma eq_zero_on_vertical_strip (hd : diff_cont_on_cl β„‚ f (re ⁻¹' Ioo a b)) (hB : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top βŠ“ π“Ÿ (re ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.im|)))) (ha : βˆ€ z : β„‚, re z = a β†’ f z = 0) (hb : βˆ€ z : β„‚, re z = b β†’ f z = 0) : eq_on f 0 (re ⁻¹' Icc a b) := Ξ» z hz, norm_le_zero_iff.1 $ vertical_strip hd hB (Ξ» z hz, (ha z hz).symm β–Έ norm_zero.le) (Ξ» z hz, (hb z hz).symm β–Έ norm_zero.le) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in a strip `U = {z : β„‚ | a < re z < b}`. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable on `U` and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < Ο€ / (b - a)`; * `f z = g z` on the boundary of `U`. Then `f` is equal to `g` on the closed strip `{z : β„‚ | a ≀ re z ≀ b}`. -/ lemma eq_on_vertical_strip {g : β„‚ β†’ E} (hdf : diff_cont_on_cl β„‚ f (re ⁻¹' Ioo a b)) (hBf : βˆƒ (c < Ο€ / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top βŠ“ π“Ÿ (re ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.im|)))) (hdg : diff_cont_on_cl β„‚ g (re ⁻¹' Ioo a b)) (hBg : βˆƒ (c < Ο€ / (b - a)) B, g =O[comap (has_abs.abs ∘ im) at_top βŠ“ π“Ÿ (re ⁻¹' Ioo a b)] (Ξ» z, expR (B * expR (c * |z.im|)))) (ha : βˆ€ z : β„‚, re z = a β†’ f z = g z) (hb : βˆ€ z : β„‚, re z = b β†’ f z = g z) : eq_on f g (re ⁻¹' Icc a b) := Ξ» z hz, sub_eq_zero.1 (eq_zero_on_vertical_strip (hdf.sub hdg) (is_O_sub_exp_exp hBf hBg) (Ξ» w hw, sub_eq_zero.2 (ha w hw)) (Ξ» w hw, sub_eq_zero.2 (hb w hw)) hz) /-! ### Phragmen-LindelΓΆf principle in coordinate quadrants -/ /-- **Phragmen-LindelΓΆf principle** in the first quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open first quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of the first quadrant. Then `βˆ₯f zβˆ₯` is bounded from above by the same constant on the closed first quadrant. -/ lemma quadrant_I (hd : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Ioi 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ βˆ₯f xβˆ₯ ≀ C) (him : βˆ€ x : ℝ, 0 ≀ x β†’ βˆ₯f (x * I)βˆ₯ ≀ C) (hz_re : 0 ≀ z.re) (hz_im : 0 ≀ z.im) : βˆ₯f zβˆ₯ ≀ C := begin -- The case `z = 0` is trivial. rcases eq_or_ne z 0 with rfl|hzne, { exact hre 0 le_rfl }, -- Otherwise, `z = e ^ ΞΆ` for some `ΞΆ : β„‚`, `0 < Im ΞΆ < Ο€ / 2`. obtain ⟨΢, hΞΆ, rfl⟩ : βˆƒ ΞΆ : β„‚, ΞΆ.im ∈ Icc 0 (Ο€ / 2) ∧ exp ΞΆ = z, { refine ⟨log z, _, exp_log hzne⟩, rw log_im, exact ⟨arg_nonneg_iff.2 hz_im, arg_le_pi_div_two_iff.2 (or.inl hz_re)⟩ }, clear hz_re hz_im hzne, -- We are going to apply `phragmen_lindelof.horizontal_strip` to `f ∘ complex.exp` and `ΞΆ`. change βˆ₯(f ∘ exp) ΞΆβˆ₯ ≀ C, have H : maps_to exp (im ⁻¹' Ioo 0 (Ο€ / 2)) (Ioi 0 Γ—β„‚ Ioi 0), { intros z hz, rw [mem_re_prod_im, exp_re, exp_im, mem_Ioi, mem_Ioi], refine ⟨mul_pos (real.exp_pos _) (real.cos_pos_of_mem_Ioo ⟨(neg_lt_zero.2 $ div_pos real.pi_pos two_pos).trans hz.1, hz.2⟩), mul_pos (real.exp_pos _) (real.sin_pos_of_mem_Ioo ⟨hz.1, hz.2.trans (half_lt_self real.pi_pos)⟩)⟩ }, refine horizontal_strip (hd.comp differentiable_exp.diff_cont_on_cl H) _ _ _ hΞΆ.1 hΞΆ.2; clear hΞΆ ΞΆ, { -- The estimate `hB` on `f` implies the required estimate on -- `f ∘ exp` with the same `c` and `B' = max B 0`. rw [sub_zero, div_div_cancel' real.pi_pos.ne'], rcases hB with ⟨c, hc, B, hO⟩, refine ⟨c, hc, max B 0, _⟩, rw [← comap_comap, comap_abs_at_top, comap_sup, inf_sup_right], -- We prove separately the estimates as `ΞΆ.re β†’ ∞` and as `ΞΆ.re β†’ -∞` refine is_O.sup _ ((hO.comp_tendsto $ tendsto_exp_comap_re_at_top.inf H.tendsto).trans $ is_O.of_bound 1 _), { -- For the estimate as `ΞΆ.re β†’ -∞`, note that `f` is continuous within the first quadrant at -- zero, hence `f (exp ΞΆ)` has a limit as `ΞΆ.re β†’ -∞`, `0 < ΞΆ.im < Ο€ / 2`. have hc : continuous_within_at f (Ioi 0 Γ—β„‚ Ioi 0) 0, { refine (hd.continuous_on _ _).mono subset_closure, simp [closure_re_prod_im, mem_re_prod_im] }, refine ((hc.tendsto.comp $ tendsto_exp_comap_re_at_bot.inf H.tendsto).is_O_one ℝ).trans (is_O_of_le _ (Ξ» w, _)), rw [norm_one, real.norm_of_nonneg (real.exp_pos _).le, real.one_le_exp_iff], exact mul_nonneg (le_max_right _ _) (real.exp_pos _).le }, { -- For the estimate as `ΞΆ.re β†’ ∞`, we reuse the uppoer estimate on `f` simp only [eventually_inf_principal, eventually_comap, comp_app, one_mul, real.norm_of_nonneg (real.exp_pos _).le, abs_exp, ← real.exp_mul, real.exp_le_exp], refine (eventually_ge_at_top 0).mono (Ξ» x hx z hz hz', _), rw [hz, _root_.abs_of_nonneg hx, mul_comm _ c], exact mul_le_mul_of_nonneg_right (le_max_left _ _) (real.exp_pos _).le } }, { -- If `ΞΆ.im = 0`, then `complex.exp ΞΆ` is a positive real number intros ΞΆ hΞΆ, lift ΞΆ to ℝ using hΞΆ, rw [comp_app, ← of_real_exp], exact hre _ (real.exp_pos _).le }, { -- If `ΞΆ.im = Ο€ / 2`, then `complex.exp ΞΆ` is a purely imaginary number with positive `im` intros ΞΆ hΞΆ, rw [← re_add_im ΞΆ, hΞΆ, comp_app, exp_add_mul_I, ← of_real_cos, ← of_real_sin, real.cos_pi_div_two, real.sin_pi_div_two, of_real_zero, of_real_one, one_mul, zero_add, ← of_real_exp], exact him _ (real.exp_pos _).le } end /-- **Phragmen-LindelΓΆf principle** in the first quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open first quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the first quadrant. Then `f` is equal to zero on the closed first quadrant. -/ lemma eq_zero_on_quadrant_I (hd : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Ioi 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ f x = 0) (him : βˆ€ x : ℝ, 0 ≀ x β†’ f (x * I) = 0) : eq_on f 0 {z | 0 ≀ z.re ∧ 0 ≀ z.im} := Ξ» z hz, norm_le_zero_iff.1 $ quadrant_I hd hB (Ξ» x hx, norm_le_zero_iff.2 $ hre x hx) (Ξ» x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in the first quadrant. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable in the open first quadrant and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the first quadrant. Then `f` is equal to `g` on the closed first quadrant. -/ lemma eq_on_quadrant_I (hdf : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Ioi 0)) (hBf : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hdg : diff_cont_on_cl β„‚ g (Ioi 0 Γ—β„‚ Ioi 0)) (hBg : βˆƒ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ f x = g x) (him : βˆ€ x : ℝ, 0 ≀ x β†’ f (x * I) = g (x * I)) : eq_on f g {z | 0 ≀ z.re ∧ 0 ≀ z.im} := Ξ» z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_I (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg) (Ξ» x hx, sub_eq_zero.2 $ hre x hx) (Ξ» x hx, sub_eq_zero.2 $ him x hx) hz /-- **Phragmen-LindelΓΆf principle** in the second quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open second quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of the second quadrant. Then `βˆ₯f zβˆ₯` is bounded from above by the same constant on the closed second quadrant. -/ lemma quadrant_II (hd : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Ioi 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ βˆ₯f xβˆ₯ ≀ C) (him : βˆ€ x : ℝ, 0 ≀ x β†’ βˆ₯f (x * I)βˆ₯ ≀ C) (hz_re : z.re ≀ 0) (hz_im : 0 ≀ z.im) : βˆ₯f zβˆ₯ ≀ C := begin obtain ⟨z, rfl⟩ : βˆƒ z', z' * I = z, from ⟨z / I, div_mul_cancel _ I_ne_zero⟩, simp only [mul_I_re, mul_I_im, neg_nonpos] at hz_re hz_im, change βˆ₯(f ∘ (* I)) zβˆ₯ ≀ C, have H : maps_to (* I) (Ioi 0 Γ—β„‚ Ioi 0) (Iio 0 Γ—β„‚ Ioi 0), { intros w hw, simpa only [mem_re_prod_im, mul_I_re, mul_I_im, neg_lt_zero, mem_Iio] using hw.symm }, refine quadrant_I (hd.comp (differentiable_id.mul_const _).diff_cont_on_cl H) (Exists₃.imp (Ξ» c hc B hO, _) hB) him (Ξ» x hx, _) hz_im hz_re, { simpa only [(∘), complex.abs_mul, abs_I, mul_one] using hO.comp_tendsto ((tendsto_mul_right_cobounded I_ne_zero).inf H.tendsto) }, { rw [comp_app, mul_assoc, I_mul_I, mul_neg_one, ← of_real_neg], exact hre _ (neg_nonpos.2 hx) } end /-- **Phragmen-LindelΓΆf principle** in the second quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open second quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the second quadrant. Then `f` is equal to zero on the closed second quadrant. -/ lemma eq_zero_on_quadrant_II (hd : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Ioi 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ f x = 0) (him : βˆ€ x : ℝ, 0 ≀ x β†’ f (x * I) = 0) : eq_on f 0 {z | z.re ≀ 0 ∧ 0 ≀ z.im} := Ξ» z hz, norm_le_zero_iff.1 $ quadrant_II hd hB (Ξ» x hx, norm_le_zero_iff.2 $ hre x hx) (Ξ» x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in the second quadrant. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable in the open second quadrant and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the second quadrant. Then `f` is equal to `g` on the closed second quadrant. -/ lemma eq_on_quadrant_II (hdf : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Ioi 0)) (hBf : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hdg : diff_cont_on_cl β„‚ g (Iio 0 Γ—β„‚ Ioi 0)) (hBg : βˆƒ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Ioi 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ f x = g x) (him : βˆ€ x : ℝ, 0 ≀ x β†’ f (x * I) = g (x * I)) : eq_on f g {z | z.re ≀ 0 ∧ 0 ≀ z.im} := Ξ» z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_II (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg) (Ξ» x hx, sub_eq_zero.2 $ hre x hx) (Ξ» x hx, sub_eq_zero.2 $ him x hx) hz /-- **Phragmen-LindelΓΆf principle** in the third quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open third quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp (B * (abs z) ^ c)` on the open third quadrant for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of the third quadrant. Then `βˆ₯f zβˆ₯` is bounded from above by the same constant on the closed third quadrant. -/ lemma quadrant_III (hd : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Iio 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ βˆ₯f xβˆ₯ ≀ C) (him : βˆ€ x : ℝ, x ≀ 0 β†’ βˆ₯f (x * I)βˆ₯ ≀ C) (hz_re : z.re ≀ 0) (hz_im : z.im ≀ 0) : βˆ₯f zβˆ₯ ≀ C := begin obtain ⟨z, rfl⟩ : βˆƒ z', -z' = z, from ⟨-z, neg_neg z⟩, simp only [neg_re, neg_im, neg_nonpos] at hz_re hz_im, change βˆ₯(f ∘ has_neg.neg) zβˆ₯ ≀ C, have H : maps_to has_neg.neg (Ioi 0 Γ—β„‚ Ioi 0) (Iio 0 Γ—β„‚ Iio 0), { intros w hw, simpa only [mem_re_prod_im, neg_re, neg_im, neg_lt_zero, mem_Iio] using hw }, refine quadrant_I (hd.comp differentiable_neg.diff_cont_on_cl H) _ (Ξ» x hx, _) (Ξ» x hx, _) hz_re hz_im, { refine Exists₃.imp (Ξ» c hc B hO, _) hB, simpa only [(∘), complex.abs_neg] using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) }, { rw [comp_app, ← of_real_neg], exact hre (-x) (neg_nonpos.2 hx) }, { rw [comp_app, ← neg_mul, ← of_real_neg], exact him (-x) (neg_nonpos.2 hx) } end /-- **Phragmen-LindelΓΆf principle** in the third quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open third quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open third quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the third quadrant. Then `f` is equal to zero on the closed third quadrant. -/ lemma eq_zero_on_quadrant_III (hd : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Iio 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ f x = 0) (him : βˆ€ x : ℝ, x ≀ 0 β†’ f (x * I) = 0) : eq_on f 0 {z | z.re ≀ 0 ∧ z.im ≀ 0} := Ξ» z hz, norm_le_zero_iff.1 $ quadrant_III hd hB (Ξ» x hx, norm_le_zero_iff.2 $ hre x hx) (Ξ» x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in the third quadrant. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable in the open third quadrant and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open third quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the third quadrant. Then `f` is equal to `g` on the closed third quadrant. -/ lemma eq_on_quadrant_III (hdf : diff_cont_on_cl β„‚ f (Iio 0 Γ—β„‚ Iio 0)) (hBf : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hdg : diff_cont_on_cl β„‚ g (Iio 0 Γ—β„‚ Iio 0)) (hBg : βˆƒ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top βŠ“ π“Ÿ (Iio 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, x ≀ 0 β†’ f x = g x) (him : βˆ€ x : ℝ, x ≀ 0 β†’ f (x * I) = g (x * I)) : eq_on f g {z | z.re ≀ 0 ∧ z.im ≀ 0} := Ξ» z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_III (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg) (Ξ» x hx, sub_eq_zero.2 $ hre x hx) (Ξ» x hx, sub_eq_zero.2 $ him x hx) hz /-- **Phragmen-LindelΓΆf principle** in the fourth quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open fourth quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the boundary of the fourth quadrant. Then `βˆ₯f zβˆ₯` is bounded from above by the same constant on the closed fourth quadrant. -/ lemma quadrant_IV (hd : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Iio 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ βˆ₯f xβˆ₯ ≀ C) (him : βˆ€ x : ℝ, x ≀ 0 β†’ βˆ₯f (x * I)βˆ₯ ≀ C) (hz_re : 0 ≀ z.re) (hz_im : z.im ≀ 0) : βˆ₯f zβˆ₯ ≀ C := begin obtain ⟨z, rfl⟩ : βˆƒ z', -z' = z, from ⟨-z, neg_neg z⟩, simp only [neg_re, neg_im, neg_nonpos, neg_nonneg] at hz_re hz_im, change βˆ₯(f ∘ has_neg.neg) zβˆ₯ ≀ C, have H : maps_to has_neg.neg (Iio 0 Γ—β„‚ Ioi 0) (Ioi 0 Γ—β„‚ Iio 0), { intros w hw, simpa only [mem_re_prod_im, neg_re, neg_im, neg_lt_zero, neg_pos, mem_Ioi, mem_Iio] using hw }, refine quadrant_II (hd.comp differentiable_neg.diff_cont_on_cl H) _ (Ξ» x hx, _) (Ξ» x hx, _) hz_re hz_im, { refine Exists₃.imp (Ξ» c hc B hO, _) hB, simpa only [(∘), complex.abs_neg] using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) }, { rw [comp_app, ← of_real_neg], exact hre (-x) (neg_nonneg.2 hx) }, { rw [comp_app, ← neg_mul, ← of_real_neg], exact him (-x) (neg_nonpos.2 hx) } end /-- **Phragmen-LindelΓΆf principle** in the fourth quadrant. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open fourth quadrant and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the fourth quadrant. Then `f` is equal to zero on the closed fourth quadrant. -/ lemma eq_zero_on_quadrant_IV (hd : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Iio 0)) (hB : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ f x = 0) (him : βˆ€ x : ℝ, x ≀ 0 β†’ f (x * I) = 0) : eq_on f 0 {z | 0 ≀ z.re ∧ z.im ≀ 0} := Ξ» z hz, norm_le_zero_iff.1 $ quadrant_IV hd hB (Ξ» x hx, norm_le_zero_iff.2 $ hre x hx) (Ξ» x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2 /-- **Phragmen-LindelΓΆf principle** in the fourth quadrant. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable in the open fourth quadrant and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the fourth quadrant. Then `f` is equal to `g` on the closed fourth quadrant. -/ lemma eq_on_quadrant_IV (hdf : diff_cont_on_cl β„‚ f (Ioi 0 Γ—β„‚ Iio 0)) (hBf : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hdg : diff_cont_on_cl β„‚ g (Ioi 0 Γ—β„‚ Iio 0)) (hBg : βˆƒ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top βŠ“ π“Ÿ (Ioi 0 Γ—β„‚ Iio 0)] (Ξ» z, expR (B * (abs z) ^ c))) (hre : βˆ€ x : ℝ, 0 ≀ x β†’ f x = g x) (him : βˆ€ x : ℝ, x ≀ 0 β†’ f (x * I) = g (x * I)) : eq_on f g {z | 0 ≀ z.re ∧ z.im ≀ 0} := Ξ» z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_IV (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg) (Ξ» x hx, sub_eq_zero.2 $ hre x hx) (Ξ» x hx, sub_eq_zero.2 $ him x hx) hz /-! ### Phragmen-LindelΓΆf principle in the right half-plane -/ /-- **Phragmen-LindelΓΆf principle** in the right half-plane. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the imaginary axis; * `f x β†’ 0` as `x : ℝ` tends to infinity. Then `βˆ₯f zβˆ₯` is bounded from above by the same constant on the closed right half-plane. See also `phragmen_lindelof.right_half_plane_of_bounded_on_real` for a stronger version. -/ lemma right_half_plane_of_tendsto_zero_on_real (hd : diff_cont_on_cl β„‚ f {z | 0 < z.re}) (hexp : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ {z | 0 < z.re}] (Ξ» z, expR (B * (abs z) ^ c))) (hre : tendsto (Ξ» x : ℝ, f x) at_top (𝓝 0)) (him : βˆ€ x : ℝ, βˆ₯f (x * I)βˆ₯ ≀ C) (hz : 0 ≀ z.re) : βˆ₯f zβˆ₯ ≀ C := begin /- We are going to apply the Phragmen-LindelΓΆf principle in the first and fourth quadrants. The lemmas immediately imply that for any upper estimate `C'` on `βˆ₯f xβˆ₯`, `x : ℝ`, `0 ≀ x`, the number `max C C'` is an upper estimate on `f` in the whole right half-plane. -/ revert z, have hle : βˆ€ C', (βˆ€ x : ℝ, 0 ≀ x β†’ βˆ₯f xβˆ₯ ≀ C') β†’ βˆ€ z : β„‚, 0 ≀ z.re β†’ βˆ₯f zβˆ₯ ≀ max C C', { intros C' hC' z hz, cases le_total z.im 0, { refine quadrant_IV (hd.mono $ Ξ» _, and.left) (Exists₃.imp (Ξ» c hc B hO, _) hexp) (Ξ» x hx, (hC' x hx).trans $ le_max_right _ _) (Ξ» x hx, (him x).trans (le_max_left _ _)) hz h, exact hO.mono (inf_le_inf_left _ $ principal_mono.2 $ Ξ» _, and.left) }, { refine quadrant_I (hd.mono $ Ξ» _, and.left) (Exists₃.imp (Ξ» c hc B hO, _) hexp) (Ξ» x hx, (hC' x hx).trans $ le_max_right _ _) (Ξ» x hx, (him x).trans (le_max_left _ _)) hz h, exact hO.mono (inf_le_inf_left _ $ principal_mono.2 $ Ξ» _, and.left) } }, -- Since `f` is continuous on `Ici 0` and `βˆ₯f xβˆ₯` tends to zero as `x β†’ ∞`, -- the norm `βˆ₯f xβˆ₯` takes its maximum value at some `xβ‚€ : ℝ`. obtain ⟨xβ‚€, hxβ‚€, hmax⟩ : βˆƒ x : ℝ, 0 ≀ x ∧ βˆ€ y : ℝ, 0 ≀ y β†’ βˆ₯f yβˆ₯ ≀ βˆ₯f xβˆ₯, { have hfc : continuous_on (Ξ» x : ℝ, f x) (Ici 0), { refine hd.continuous_on.comp continuous_of_real.continuous_on (Ξ» x hx, _), rwa closure_set_of_lt_re }, by_cases hβ‚€ : βˆ€ x : ℝ, 0 ≀ x β†’ f x = 0, { refine ⟨0, le_rfl, Ξ» y hy, _⟩, rw [hβ‚€ y hy, hβ‚€ 0 le_rfl] }, push_neg at hβ‚€, rcases hβ‚€ with ⟨xβ‚€, hxβ‚€, hne⟩, have hlt : βˆ₯(0 : E)βˆ₯ < βˆ₯f xβ‚€βˆ₯, by rwa [norm_zero, norm_pos_iff], suffices : βˆ€αΆ  x : ℝ in cocompact ℝ βŠ“ π“Ÿ (Ici 0), βˆ₯f xβˆ₯ ≀ βˆ₯f xβ‚€βˆ₯, by simpa only [exists_prop] using hfc.norm.exists_forall_ge' is_closed_Ici hxβ‚€ this, rw [real.cocompact_eq, inf_sup_right, (disjoint_at_bot_principal_Ici (0 : ℝ)).eq_bot, bot_sup_eq], exact (hre.norm.eventually $ ge_mem_nhds hlt).filter_mono inf_le_left }, cases le_or_lt (βˆ₯f xβ‚€βˆ₯) C, { -- If `βˆ₯f xβ‚€βˆ₯ ≀ C`, then `hle` implies the required estimate simpa only [max_eq_left h] using hle _ hmax }, { -- Otherwise, `βˆ₯f zβˆ₯ ≀ βˆ₯f xβ‚€βˆ₯` for all `z` in the right half-plane due to `hle`. replace hmax : is_max_on (norm ∘ f) {z | 0 < z.re} xβ‚€, { rintros z (hz : 0 < z.re), simpa [max_eq_right h.le] using hle _ hmax _ hz.le }, -- Due to the maximum modulus principle applied to the closed ball of radius `xβ‚€.re`, -- `βˆ₯f 0βˆ₯ = βˆ₯f xβ‚€βˆ₯`. have : βˆ₯f 0βˆ₯ = βˆ₯f xβ‚€βˆ₯, { apply norm_eq_norm_of_is_max_on_of_ball_subset hd hmax, -- move to a lemma? intros z hz, rw [mem_ball, dist_zero_left, dist_eq, norm_eq_abs, complex.abs_of_nonneg hxβ‚€] at hz, rw mem_set_of_eq, contrapose! hz, calc xβ‚€ ≀ xβ‚€ - z.re : (le_sub_self_iff _).2 hz ... ≀ |xβ‚€ - z.re| : le_abs_self _ ... = |(z - xβ‚€).re| : by rw [sub_re, of_real_re, _root_.abs_sub_comm] ... ≀ abs (z - xβ‚€) : abs_re_le_abs _ }, -- Thus we have `C < βˆ₯f xβ‚€βˆ₯ = βˆ₯f 0βˆ₯ ≀ C`. Contradiction completes the proof. refine (h.not_le $ this β–Έ _).elim, simpa using him 0 } end /-- **Phragmen-LindelΓΆf principle** in the right half-plane. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant `C` on the imaginary axis; * `βˆ₯f xβˆ₯` is bounded from above by a constant for large real values of `x`. Then `βˆ₯f zβˆ₯` is bounded from above by `C` on the closed right half-plane. See also `phragmen_lindelof.right_half_plane_of_tendsto_zero_on_real` for a weaker version. -/ lemma right_half_plane_of_bounded_on_real (hd : diff_cont_on_cl β„‚ f {z | 0 < z.re}) (hexp : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ {z | 0 < z.re}] (Ξ» z, expR (B * (abs z) ^ c))) (hre : is_bounded_under (≀) at_top (Ξ» x : ℝ, βˆ₯f xβˆ₯)) (him : βˆ€ x : ℝ, βˆ₯f (x * I)βˆ₯ ≀ C) (hz : 0 ≀ z.re) : βˆ₯f zβˆ₯ ≀ C := begin -- For each `Ξ΅ < 0`, the function `Ξ» z, exp (Ξ΅ * z) β€’ f z` satisfies assumptions of -- `right_half_plane_of_tendsto_zero_on_real`, hence `βˆ₯exp (Ξ΅ * z) β€’ f zβˆ₯ ≀ C` for all `Ξ΅ < 0`. -- Taking the limit as `Ξ΅ β†’ 0`, we obtain the required inequality. suffices : βˆ€αΆ  Ξ΅ : ℝ in 𝓝[<] 0, βˆ₯exp (Ξ΅ * z) β€’ f zβˆ₯ ≀ C, { refine le_of_tendsto (tendsto.mono_left _ nhds_within_le_nhds) this, apply ((continuous_of_real.mul continuous_const).cexp.smul continuous_const).norm.tendsto', simp, apply_instance }, filter_upwards [self_mem_nhds_within] with Ξ΅ Ξ΅β‚€, change Ξ΅ < 0 at Ξ΅β‚€, set g : β„‚ β†’ E := Ξ» z, exp (Ξ΅ * z) β€’ f z, change βˆ₯g zβˆ₯ ≀ C, replace hd : diff_cont_on_cl β„‚ g {z : β„‚ | 0 < z.re}, from (differentiable_id.const_mul _).cexp.diff_cont_on_cl.smul hd, have hgn : βˆ€ z, βˆ₯g zβˆ₯ = expR (Ξ΅ * z.re) * βˆ₯f zβˆ₯, { intro z, rw [norm_smul, norm_eq_abs, abs_exp, of_real_mul_re] }, refine right_half_plane_of_tendsto_zero_on_real hd _ _ (Ξ» y, _) hz, { refine Exists₃.imp (Ξ» c hc B hO, (is_O.of_bound 1 _).trans hO) hexp, refine (eventually_inf_principal.2 $ eventually_of_forall $ Ξ» z hz, _), rw [hgn, one_mul], refine mul_le_of_le_one_left (norm_nonneg _) (real.exp_le_one_iff.2 _), exact mul_nonpos_of_nonpos_of_nonneg Ξ΅β‚€.le (le_of_lt hz) }, { simp_rw [g, ← of_real_mul, ← of_real_exp, coe_smul], have hβ‚€ : tendsto (Ξ» x : ℝ, expR (Ξ΅ * x)) at_top (𝓝 0), from real.tendsto_exp_at_bot.comp (tendsto_const_nhds.neg_mul_at_top Ξ΅β‚€ tendsto_id), exact hβ‚€.zero_smul_is_bounded_under_le hre }, { rw [hgn, of_real_mul_re, I_re, mul_zero, mul_zero, real.exp_zero, one_mul], exact him y } end /-- **Phragmen-LindelΓΆf principle** in the right half-plane. Let `f : β„‚ β†’ E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `βˆ₯f zβˆ₯` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `βˆ₯f zβˆ₯` is bounded from above by a constant on the imaginary axis; * `f x`, `x : ℝ`, tends to zero superexponentially fast as `x β†’ ∞`: for any natural `n`, `exp (n * x) * βˆ₯f xβˆ₯` tends to zero as `x β†’ ∞`. Then `f` is equal to zero on the closed right half-plane. -/ lemma eq_zero_on_right_half_plane_of_superexponential_decay (hd : diff_cont_on_cl β„‚ f {z | 0 < z.re}) (hexp : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ {z | 0 < z.re}] (Ξ» z, expR (B * (abs z) ^ c))) (hre : superpolynomial_decay at_top expR (Ξ» x, βˆ₯f xβˆ₯)) (him : βˆƒ C, βˆ€ x : ℝ, βˆ₯f (x * I)βˆ₯ ≀ C) : eq_on f 0 {z : β„‚ | 0 ≀ z.re} := begin rcases him with ⟨C, hC⟩, -- Due to continuity, it suffices to prove the equality on the open right half-plane. suffices : βˆ€ z : β„‚, 0 < z.re β†’ f z = 0, { simpa only [closure_set_of_lt_re] using eq_on.of_subset_closure this hd.continuous_on continuous_on_const subset_closure subset.rfl }, -- Consider $g_n(z)=e^{nz}f(z)$. set g : β„• β†’ β„‚ β†’ E := Ξ» n z, (exp z) ^ n β€’ f z, have hg : βˆ€ n z, βˆ₯g n zβˆ₯ = (expR z.re) ^ n * βˆ₯f zβˆ₯, { intros n z, simp only [norm_smul, norm_eq_abs, complex.abs_pow, abs_exp] }, intros z hz, -- Since `e^{nz} β†’ ∞` as `n β†’ ∞`, it suffices to show that each `g_n` is bounded from above by `C` suffices H : βˆ€ n : β„•, βˆ₯g n zβˆ₯ ≀ C, { contrapose! H, simp only [hg], exact (((tendsto_pow_at_top_at_top_of_one_lt (real.one_lt_exp_iff.2 hz)).at_top_mul (norm_pos_iff.2 H) tendsto_const_nhds).eventually (eventually_gt_at_top C)).exists }, intro n, -- This estimate follows from the Phragmen-LindelΓΆf principle in the right half-plane. refine right_half_plane_of_tendsto_zero_on_real ((differentiable_exp.pow n).diff_cont_on_cl.smul hd) _ _ (Ξ» y, _) hz.le, { rcases hexp with ⟨c, hc, B, hO⟩, refine ⟨max c 1, max_lt hc one_lt_two, n + max B 0, is_O.of_norm_left _⟩, simp only [hg], refine ((is_O_refl (Ξ» z : β„‚, expR z.re ^ n) _).mul hO.norm_left).trans (is_O.of_bound 1 _), simp only [← real.exp_nat_mul, ← real.exp_add, real.norm_of_nonneg (real.exp_pos _).le, real.exp_le_exp, add_mul, eventually_inf_principal, eventually_comap, one_mul], filter_upwards [eventually_ge_at_top (1 : ℝ)] with r hr z hzr hre, subst r, refine add_le_add (mul_le_mul_of_nonneg_left _ n.cast_nonneg) _, { calc z.re ≀ abs z : re_le_abs _ ... = abs z ^ (1 : ℝ) : (real.rpow_one _).symm ... ≀ abs z ^ (max c 1) : real.rpow_le_rpow_of_exponent_le hr (le_max_right _ _) }, { exact mul_le_mul (le_max_left _ _) (real.rpow_le_rpow_of_exponent_le hr (le_max_left _ _)) (real.rpow_nonneg_of_nonneg (abs_nonneg _) _) (le_max_right _ _) } }, { rw tendsto_zero_iff_norm_tendsto_zero, simp only [hg], exact hre n }, { rw [hg, of_real_mul_re, I_re, mul_zero, real.exp_zero, one_pow, one_mul], exact hC y } end /-- **Phragmen-LindelΓΆf principle** in the right half-plane. Let `f g : β„‚ β†’ E` be functions such that * `f` and `g` are differentiable in the open right half-plane and are continuous on its closure; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `βˆ₯f zβˆ₯` and `βˆ₯g zβˆ₯` are bounded from above by constants on the imaginary axis; * `f x - g x`, `x : ℝ`, tends to zero superexponentially fast as `x β†’ ∞`: for any natural `n`, `exp (n * x) * βˆ₯f x - g xβˆ₯` tends to zero as `x β†’ ∞`. Then `f` is equal to `g` on the closed right half-plane. -/ lemma eq_on_right_half_plane_of_superexponential_decay {g : β„‚ β†’ E} (hfd : diff_cont_on_cl β„‚ f {z | 0 < z.re}) (hgd : diff_cont_on_cl β„‚ g {z | 0 < z.re}) (hfexp : βˆƒ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top βŠ“ π“Ÿ {z | 0 < z.re}] (Ξ» z, expR (B * (abs z) ^ c))) (hgexp : βˆƒ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top βŠ“ π“Ÿ {z | 0 < z.re}] (Ξ» z, expR (B * (abs z) ^ c))) (hre : superpolynomial_decay at_top expR (Ξ» x, βˆ₯f x - g xβˆ₯)) (hfim : βˆƒ C, βˆ€ x : ℝ, βˆ₯f (x * I)βˆ₯ ≀ C) (hgim : βˆƒ C, βˆ€ x : ℝ, βˆ₯g (x * I)βˆ₯ ≀ C) : eq_on f g {z : β„‚ | 0 ≀ z.re} := begin suffices : eq_on (f - g) 0 {z : β„‚ | 0 ≀ z.re}, by simpa only [eq_on, pi.sub_apply, pi.zero_apply, sub_eq_zero] using this, refine eq_zero_on_right_half_plane_of_superexponential_decay (hfd.sub hgd) _ hre _, { set l : filter β„‚ := comap abs at_top βŠ“ π“Ÿ {z : β„‚ | 0 < z.re}, suffices : βˆ€ {c₁ cβ‚‚ B₁ Bβ‚‚ : ℝ}, c₁ ≀ cβ‚‚ β†’ B₁ ≀ Bβ‚‚ β†’ 0 ≀ Bβ‚‚ β†’ (Ξ» z, expR (B₁ * abs z ^ c₁)) =O[l] (Ξ» z, expR (Bβ‚‚ * abs z ^ cβ‚‚)), { rcases hfexp with ⟨cf, hcf, Bf, hOf⟩, rcases hgexp with ⟨cg, hcg, Bg, hOg⟩, refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩, refine is_O.sub (hOf.trans $ this _ _ _) (hOg.trans $ this _ _ _); simp }, intros c₁ cβ‚‚ B₁ Bβ‚‚ hc hB hBβ‚‚, have : βˆ€αΆ  z : β„‚ in l, 1 ≀ abs z, from ((eventually_ge_at_top 1).comap _).filter_mono inf_le_left, refine is_O.of_bound 1 (this.mono $ Ξ» z hz, _), simp only [real.norm_of_nonneg (real.exp_pos _).le, real.exp_le_exp, one_mul], exact mul_le_mul hB (real.rpow_le_rpow_of_exponent_le hz hc) (real.rpow_nonneg_of_nonneg (abs_nonneg _) _) hBβ‚‚ }, { rcases hfim with ⟨Cf, hCf⟩, rcases hgim with ⟨Cg, hCg⟩, exact ⟨Cf + Cg, Ξ» x, norm_sub_le_of_le (hCf x) (hCg x)⟩ } end end phragmen_lindelof
92b74f6d110e9fd9b30414dea239cf89559cc0ef
130c49f47783503e462c16b2eff31933442be6ff
/src/Init/Meta.lean
3b7071c6b27b61db552df1f7266a669a85ad420e
[ "Apache-2.0" ]
permissive
Hazel-Brown/lean4
8aa5860e282435ffc30dcdfccd34006c59d1d39c
79e6732fc6bbf5af831b76f310f9c488d44e7a16
refs/heads/master
1,689,218,208,951
1,629,736,869,000
1,629,736,896,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
32,480
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura and Sebastian Ullrich Additional goodies for writing macros -/ prelude import Init.Data.Array.Basic namespace Lean @[extern c inline "lean_box(LEAN_VERSION_MAJOR)"] private constant version.getMajor (u : Unit) : Nat def version.major : Nat := version.getMajor () @[extern c inline "lean_box(LEAN_VERSION_MINOR)"] private constant version.getMinor (u : Unit) : Nat def version.minor : Nat := version.getMinor () @[extern c inline "lean_box(LEAN_VERSION_PATCH)"] private constant version.getPatch (u : Unit) : Nat def version.patch : Nat := version.getPatch () -- @[extern c inline "lean_mk_string(LEAN_GITHASH)"] -- constant getGithash (u : Unit) : String -- def githash : String := getGithash () @[extern c inline "LEAN_VERSION_IS_RELEASE"] constant version.getIsRelease (u : Unit) : Bool def version.isRelease : Bool := version.getIsRelease () /-- Additional version description like "nightly-2018-03-11" -/ @[extern c inline "lean_mk_string(LEAN_SPECIAL_VERSION_DESC)"] constant version.getSpecialDesc (u : Unit) : String def version.specialDesc : String := version.getSpecialDesc () /- Valid identifier names -/ def isGreek (c : Char) : Bool := 0x391 ≀ c.val && c.val ≀ 0x3dd def isLetterLike (c : Char) : Bool := (0x3b1 ≀ c.val && c.val ≀ 0x3c9 && c.val β‰  0x3bb) || -- Lower greek, but lambda (0x391 ≀ c.val && c.val ≀ 0x3A9 && c.val β‰  0x3A0 && c.val β‰  0x3A3) || -- Upper greek, but Pi and Sigma (0x3ca ≀ c.val && c.val ≀ 0x3fb) || -- Coptic letters (0x1f00 ≀ c.val && c.val ≀ 0x1ffe) || -- Polytonic Greek Extended Character Set (0x2100 ≀ c.val && c.val ≀ 0x214f) || -- Letter like block (0x1d49c ≀ c.val && c.val ≀ 0x1d59f) -- Latin letters, Script, Double-struck, Fractur def isNumericSubscript (c : Char) : Bool := 0x2080 ≀ c.val && c.val ≀ 0x2089 def isSubScriptAlnum (c : Char) : Bool := isNumericSubscript c || (0x2090 ≀ c.val && c.val ≀ 0x209c) || (0x1d62 ≀ c.val && c.val ≀ 0x1d6a) def isIdFirst (c : Char) : Bool := c.isAlpha || c = '_' || isLetterLike c def isIdRest (c : Char) : Bool := c.isAlphanum || c = '_' || c = '\'' || c == '!' || c == '?' || isLetterLike c || isSubScriptAlnum c def idBeginEscape := 'Β«' def idEndEscape := 'Β»' def isIdBeginEscape (c : Char) : Bool := c = idBeginEscape def isIdEndEscape (c : Char) : Bool := c = idEndEscape namespace Name def getRoot : Name β†’ Name | anonymous => anonymous | n@(str anonymous _ _) => n | n@(num anonymous _ _) => n | str n _ _ => getRoot n | num n _ _ => getRoot n @[export lean_is_inaccessible_user_name] def isInaccessibleUserName : Name β†’ Bool | Name.str _ s _ => s.contains '✝' || s == "_inaccessible" | Name.num p idx _ => isInaccessibleUserName p | _ => false def escapePart (s : String) : Option String := if s.length > 0 && isIdFirst s[0] && (s.toSubstring.drop 1).all isIdRest then s else if s.any isIdEndEscape then none else some <| idBeginEscape.toString ++ s ++ idEndEscape.toString -- NOTE: does not roundtrip even with `escape = true` if name is anonymous or contains numeric part or `idEndEscape` variable (sep : String) (escape : Bool) def toStringWithSep : Name β†’ String | anonymous => "[anonymous]" | str anonymous s _ => maybeEscape s | num anonymous v _ => toString v | str n s _ => toStringWithSep n ++ sep ++ maybeEscape s | num n v _ => toStringWithSep n ++ sep ++ Nat.repr v where maybeEscape s := if escape then escapePart s |>.getD s else s protected def toString (n : Name) (escape := true) : String := -- never escape "prettified" inaccessible names or macro scopes or pseudo-syntax introduced by the delaborator toStringWithSep "." (escape && !n.isInaccessibleUserName && !n.hasMacroScopes && !maybePseudoSyntax) n where maybePseudoSyntax := if let Name.str _ s _ := n.getRoot then -- could be pseudo-syntax for loose bvar or universe mvar, output as is "#".isPrefixOf s || "?".isPrefixOf s else false instance : ToString Name where toString n := n.toString instance : Repr Name where reprPrec n _ := Std.Format.text "`" ++ n.toString def capitalize : Name β†’ Name | Name.str p s _ => Name.mkStr p s.capitalize | n => n def replacePrefix : Name β†’ Name β†’ Name β†’ Name | anonymous, anonymous, newP => newP | anonymous, _, _ => anonymous | n@(str p s _), queryP, newP => if n == queryP then newP else Name.mkStr (p.replacePrefix queryP newP) s | n@(num p s _), queryP, newP => if n == queryP then newP else Name.mkNum (p.replacePrefix queryP newP) s /-- Remove macros scopes, apply `f`, and put them back -/ @[inline] def modifyBase (n : Name) (f : Name β†’ Name) : Name := if n.hasMacroScopes then let view := extractMacroScopes n { view with name := f view.name }.review else f n @[export lean_name_append_after] def appendAfter (n : Name) (suffix : String) : Name := n.modifyBase fun | str p s _ => Name.mkStr p (s ++ suffix) | n => Name.mkStr n suffix @[export lean_name_append_index_after] def appendIndexAfter (n : Name) (idx : Nat) : Name := n.modifyBase fun | str p s _ => Name.mkStr p (s ++ "_" ++ toString idx) | n => Name.mkStr n ("_" ++ toString idx) @[export lean_name_append_before] def appendBefore (n : Name) (pre : String) : Name := n.modifyBase fun | anonymous => Name.mkStr anonymous pre | str p s _ => Name.mkStr p (pre ++ s) | num p n _ => Name.mkNum (Name.mkStr p pre) n end Name structure NameGenerator where namePrefix : Name := `_uniq idx : Nat := 1 deriving Inhabited namespace NameGenerator @[inline] def curr (g : NameGenerator) : Name := Name.mkNum g.namePrefix g.idx @[inline] def next (g : NameGenerator) : NameGenerator := { g with idx := g.idx + 1 } @[inline] def mkChild (g : NameGenerator) : NameGenerator Γ— NameGenerator := ({ namePrefix := Name.mkNum g.namePrefix g.idx, idx := 1 }, { g with idx := g.idx + 1 }) end NameGenerator class MonadNameGenerator (m : Type β†’ Type) where getNGen : m NameGenerator setNGen : NameGenerator β†’ m Unit export MonadNameGenerator (getNGen setNGen) def mkFreshId {m : Type β†’ Type} [Monad m] [MonadNameGenerator m] : m Name := do let ngen ← getNGen let r := ngen.curr setNGen ngen.next pure r instance monadNameGeneratorLift (m n : Type β†’ Type) [MonadLift m n] [MonadNameGenerator m] : MonadNameGenerator n := { getNGen := liftM (getNGen : m _), setNGen := fun ngen => liftM (setNGen ngen : m _) } namespace Syntax partial def structEq : Syntax β†’ Syntax β†’ Bool | Syntax.missing, Syntax.missing => true | Syntax.node k args, Syntax.node k' args' => k == k' && args.isEqv args' structEq | Syntax.atom _ val, Syntax.atom _ val' => val == val' | Syntax.ident _ rawVal val preresolved, Syntax.ident _ rawVal' val' preresolved' => rawVal == rawVal' && val == val' && preresolved == preresolved' | _, _ => false instance : BEq Lean.Syntax := ⟨structEq⟩ partial def getTailInfo? : Syntax β†’ Option SourceInfo | atom info _ => info | ident info .. => info | node _ args => args.findSomeRev? getTailInfo? | _ => none def getTailInfo (stx : Syntax) : SourceInfo := stx.getTailInfo?.getD SourceInfo.none def getTrailingSize (stx : Syntax) : Nat := match stx.getTailInfo? with | some (SourceInfo.original (trailing := trailing) ..) => trailing.bsize | _ => 0 @[specialize] private partial def updateLast {Ξ±} [Inhabited Ξ±] (a : Array Ξ±) (f : Ξ± β†’ Option Ξ±) (i : Nat) : Option (Array Ξ±) := if i == 0 then none else let i := i - 1 let v := a[i] match f v with | some v => some <| a.set! i v | none => updateLast a f i partial def setTailInfoAux (info : SourceInfo) : Syntax β†’ Option Syntax | atom _ val => some <| atom info val | ident _ rawVal val pre => some <| ident info rawVal val pre | node k args => match updateLast args (setTailInfoAux info) args.size with | some args => some <| node k args | none => none | stx => none def setTailInfo (stx : Syntax) (info : SourceInfo) : Syntax := match setTailInfoAux info stx with | some stx => stx | none => stx def unsetTrailing (stx : Syntax) : Syntax := match stx.getTailInfo with | SourceInfo.original lead pos trail endPos => stx.setTailInfo (SourceInfo.original lead pos "".toSubstring endPos) | _ => stx @[specialize] private partial def updateFirst {Ξ±} [Inhabited Ξ±] (a : Array Ξ±) (f : Ξ± β†’ Option Ξ±) (i : Nat) : Option (Array Ξ±) := if h : i < a.size then let v := a.get ⟨i, h⟩; match f v with | some v => some <| a.set ⟨i, h⟩ v | none => updateFirst a f (i+1) else none partial def setHeadInfoAux (info : SourceInfo) : Syntax β†’ Option Syntax | atom _ val => some <| atom info val | ident _ rawVal val pre => some <| ident info rawVal val pre | node k args => match updateFirst args (setHeadInfoAux info) 0 with | some args => some <| node k args | noxne => none | stx => none def setHeadInfo (stx : Syntax) (info : SourceInfo) : Syntax := match setHeadInfoAux info stx with | some stx => stx | none => stx def setInfo (info : SourceInfo) : Syntax β†’ Syntax | atom _ val => atom info val | ident _ rawVal val pre => ident info rawVal val pre | stx => stx /-- Return the first atom/identifier that has position information -/ partial def getHead? : Syntax β†’ Option Syntax | stx@(atom info ..) => info.getPos?.map fun _ => stx | stx@(ident info ..) => info.getPos?.map fun _ => stx | node _ args => args.findSome? getHead? | _ => none def copyHeadTailInfoFrom (target source : Syntax) : Syntax := target.setHeadInfo source.getHeadInfo |>.setTailInfo source.getTailInfo end Syntax /-- Use the head atom/identifier of the current `ref` as the `ref` -/ @[inline] def withHeadRefOnly {m : Type β†’ Type} [Monad m] [MonadRef m] {Ξ±} (x : m Ξ±) : m Ξ± := do match (← getRef).getHead? with | none => x | some ref => withRef ref x @[inline] def mkNode (k : SyntaxNodeKind) (args : Array Syntax) : Syntax := Syntax.node k args /- Syntax objects for a Lean module. -/ structure Module where header : Syntax commands : Array Syntax /-- Expand all macros in the given syntax -/ partial def expandMacros : Syntax β†’ MacroM Syntax | stx@(Syntax.node k args) => do match (← expandMacro? stx) with | some stxNew => expandMacros stxNew | none => do let args ← Macro.withIncRecDepth stx <| args.mapM expandMacros pure <| Syntax.node k args | stx => pure stx /- Helper functions for processing Syntax programmatically -/ /-- Create an identifier copying the position from `src`. To refer to a specific constant, use `mkCIdentFrom` instead. -/ def mkIdentFrom (src : Syntax) (val : Name) : Syntax := Syntax.ident (SourceInfo.fromRef src) (toString val).toSubstring val [] def mkIdentFromRef [Monad m] [MonadRef m] (val : Name) : m Syntax := do return mkIdentFrom (← getRef) val /-- Create an identifier referring to a constant `c` copying the position from `src`. This variant of `mkIdentFrom` makes sure that the identifier cannot accidentally be captured. -/ def mkCIdentFrom (src : Syntax) (c : Name) : Syntax := -- Remark: We use the reserved macro scope to make sure there are no accidental collision with our frontend let id := addMacroScope `_internal c reservedMacroScope Syntax.ident (SourceInfo.fromRef src) (toString id).toSubstring id [(c, [])] def mkCIdentFromRef [Monad m] [MonadRef m] (c : Name) : m Syntax := do return mkCIdentFrom (← getRef) c def mkCIdent (c : Name) : Syntax := mkCIdentFrom Syntax.missing c @[export lean_mk_syntax_ident] def mkIdent (val : Name) : Syntax := Syntax.ident SourceInfo.none (toString val).toSubstring val [] @[inline] def mkNullNode (args : Array Syntax := #[]) : Syntax := Syntax.node nullKind args @[inline] def mkGroupNode (args : Array Syntax := #[]) : Syntax := Syntax.node groupKind args def mkSepArray (as : Array Syntax) (sep : Syntax) : Array Syntax := do let mut i := 0 let mut r := #[] for a in as do if i > 0 then r := r.push sep |>.push a else r := r.push a i := i + 1 return r def mkOptionalNode (arg : Option Syntax) : Syntax := match arg with | some arg => Syntax.node nullKind #[arg] | none => Syntax.node nullKind #[] def mkHole (ref : Syntax) : Syntax := Syntax.node `Lean.Parser.Term.hole #[mkAtomFrom ref "_"] namespace Syntax def mkSep (a : Array Syntax) (sep : Syntax) : Syntax := mkNullNode <| mkSepArray a sep def SepArray.ofElems {sep} (elems : Array Syntax) : SepArray sep := ⟨mkSepArray elems (mkAtom sep)⟩ def SepArray.ofElemsUsingRef [Monad m] [MonadRef m] {sep} (elems : Array Syntax) : m (SepArray sep) := do let ref ← getRef; return ⟨mkSepArray elems (mkAtomFrom ref sep)⟩ instance (sep) : Coe (Array Syntax) (SepArray sep) where coe := SepArray.ofElems /-- Create syntax representing a Lean term application, but avoid degenerate empty applications. -/ def mkApp (fn : Syntax) : (args : Array Syntax) β†’ Syntax | #[] => fn | args => Syntax.node `Lean.Parser.Term.app #[fn, mkNullNode args] def mkCApp (fn : Name) (args : Array Syntax) : Syntax := mkApp (mkCIdent fn) args def mkLit (kind : SyntaxNodeKind) (val : String) (info := SourceInfo.none) : Syntax := let atom : Syntax := Syntax.atom info val Syntax.node kind #[atom] def mkStrLit (val : String) (info := SourceInfo.none) : Syntax := mkLit strLitKind (String.quote val) info def mkNumLit (val : String) (info := SourceInfo.none) : Syntax := mkLit numLitKind val info def mkScientificLit (val : String) (info := SourceInfo.none) : Syntax := mkLit scientificLitKind val info def mkNameLit (val : String) (info := SourceInfo.none) : Syntax := mkLit nameLitKind val info /- Recall that we don't have special Syntax constructors for storing numeric and string atoms. The idea is to have an extensible approach where embedded DSLs may have new kind of atoms and/or different ways of representing them. So, our atoms contain just the parsed string. The main Lean parser uses the kind `numLitKind` for storing natural numbers that can be encoded in binary, octal, decimal and hexadecimal format. `isNatLit` implements a "decoder" for Syntax objects representing these numerals. -/ private partial def decodeBinLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat := if s.atEnd i then some val else let c := s.get i if c == '0' then decodeBinLitAux s (s.next i) (2*val) else if c == '1' then decodeBinLitAux s (s.next i) (2*val + 1) else none private partial def decodeOctalLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat := if s.atEnd i then some val else let c := s.get i if '0' ≀ c && c ≀ '7' then decodeOctalLitAux s (s.next i) (8*val + c.toNat - '0'.toNat) else none private def decodeHexDigit (s : String) (i : String.Pos) : Option (Nat Γ— String.Pos) := let c := s.get i let i := s.next i if '0' ≀ c && c ≀ '9' then some (c.toNat - '0'.toNat, i) else if 'a' ≀ c && c ≀ 'f' then some (10 + c.toNat - 'a'.toNat, i) else if 'A' ≀ c && c ≀ 'F' then some (10 + c.toNat - 'A'.toNat, i) else none private partial def decodeHexLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat := if s.atEnd i then some val else match decodeHexDigit s i with | some (d, i) => decodeHexLitAux s i (16*val + d) | none => none private partial def decodeDecimalLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat := if s.atEnd i then some val else let c := s.get i if '0' ≀ c && c ≀ '9' then decodeDecimalLitAux s (s.next i) (10*val + c.toNat - '0'.toNat) else none def decodeNatLitVal? (s : String) : Option Nat := let len := s.length if len == 0 then none else let c := s.get 0 if c == '0' then if len == 1 then some 0 else let c := s.get 1 if c == 'x' || c == 'X' then decodeHexLitAux s 2 0 else if c == 'b' || c == 'B' then decodeBinLitAux s 2 0 else if c == 'o' || c == 'O' then decodeOctalLitAux s 2 0 else if c.isDigit then decodeDecimalLitAux s 0 0 else none else if c.isDigit then decodeDecimalLitAux s 0 0 else none def isLit? (litKind : SyntaxNodeKind) (stx : Syntax) : Option String := match stx with | Syntax.node k args => if k == litKind && args.size == 1 then match args.get! 0 with | (Syntax.atom _ val) => some val | _ => none else none | _ => none private def isNatLitAux (litKind : SyntaxNodeKind) (stx : Syntax) : Option Nat := match isLit? litKind stx with | some val => decodeNatLitVal? val | _ => none def isNatLit? (s : Syntax) : Option Nat := isNatLitAux numLitKind s def isFieldIdx? (s : Syntax) : Option Nat := isNatLitAux fieldIdxKind s partial def decodeScientificLitVal? (s : String) : Option (Nat Γ— Bool Γ— Nat) := let len := s.length if len == 0 then none else let c := s.get 0 if c.isDigit then decode 0 0 else none where decodeAfterExp (i : String.Pos) (val : Nat) (e : Nat) (sign : Bool) (exp : Nat) : Option (Nat Γ— Bool Γ— Nat) := if s.atEnd i then if sign then some (val, sign, exp + e) else if exp >= e then some (val, sign, exp - e) else some (val, true, e - exp) else let c := s.get i if '0' ≀ c && c ≀ '9' then decodeAfterExp (s.next i) val e sign (10*exp + c.toNat - '0'.toNat) else none decodeExp (i : String.Pos) (val : Nat) (e : Nat) : Option (Nat Γ— Bool Γ— Nat) := let c := s.get i if c == '-' then decodeAfterExp (s.next i) val e true 0 else decodeAfterExp i val e false 0 decodeAfterDot (i : String.Pos) (val : Nat) (e : Nat) : Option (Nat Γ— Bool Γ— Nat) := if s.atEnd i then some (val, true, e) else let c := s.get i if '0' ≀ c && c ≀ '9' then decodeAfterDot (s.next i) (10*val + c.toNat - '0'.toNat) (e+1) else if c == 'e' || c == 'E' then decodeExp (s.next i) val e else none decode (i : String.Pos) (val : Nat) : Option (Nat Γ— Bool Γ— Nat) := if s.atEnd i then none else let c := s.get i if '0' ≀ c && c ≀ '9' then decode (s.next i) (10*val + c.toNat - '0'.toNat) else if c == '.' then decodeAfterDot (s.next i) val 0 else if c == 'e' || c == 'E' then decodeExp (s.next i) val 0 else none def isScientificLit? (stx : Syntax) : Option (Nat Γ— Bool Γ— Nat) := match isLit? scientificLitKind stx with | some val => decodeScientificLitVal? val | _ => none def isIdOrAtom? : Syntax β†’ Option String | Syntax.atom _ val => some val | Syntax.ident _ rawVal _ _ => some rawVal.toString | _ => none def toNat (stx : Syntax) : Nat := match stx.isNatLit? with | some val => val | none => 0 def decodeQuotedChar (s : String) (i : String.Pos) : Option (Char Γ— String.Pos) := OptionM.run do let c := s.get i let i := s.next i if c == '\\' then pure ('\\', i) else if c = '\"' then pure ('\"', i) else if c = '\'' then pure ('\'', i) else if c = 'r' then pure ('\r', i) else if c = 'n' then pure ('\n', i) else if c = 't' then pure ('\t', i) else if c = 'x' then let (d₁, i) ← decodeHexDigit s i let (dβ‚‚, i) ← decodeHexDigit s i pure (Char.ofNat (16*d₁ + dβ‚‚), i) else if c = 'u' then do let (d₁, i) ← decodeHexDigit s i let (dβ‚‚, i) ← decodeHexDigit s i let (d₃, i) ← decodeHexDigit s i let (dβ‚„, i) ← decodeHexDigit s i pure (Char.ofNat (16*(16*(16*d₁ + dβ‚‚) + d₃) + dβ‚„), i) else none partial def decodeStrLitAux (s : String) (i : String.Pos) (acc : String) : Option String := OptionM.run do let c := s.get i let i := s.next i if c == '\"' then pure acc else if s.atEnd i then none else if c == '\\' then do let (c, i) ← decodeQuotedChar s i decodeStrLitAux s i (acc.push c) else decodeStrLitAux s i (acc.push c) def decodeStrLit (s : String) : Option String := decodeStrLitAux s 1 "" def isStrLit? (stx : Syntax) : Option String := match isLit? strLitKind stx with | some val => decodeStrLit val | _ => none def decodeCharLit (s : String) : Option Char := OptionM.run do let c := s.get 1 if c == '\\' then do let (c, _) ← decodeQuotedChar s 2 pure c else pure c def isCharLit? (stx : Syntax) : Option Char := match isLit? charLitKind stx with | some val => decodeCharLit val | _ => none private partial def splitNameLitAux (ss : Substring) (acc : List Substring) : List Substring := let splitRest (ss : Substring) (acc : List Substring) : List Substring := if ss.front == '.' then splitNameLitAux (ss.drop 1) acc else if ss.isEmpty then acc else [] if ss.isEmpty then [] else let curr := ss.front if isIdBeginEscape curr then let escapedPart := ss.takeWhile (!isIdEndEscape Β·) let escapedPart := { escapedPart with stopPos := ss.stopPos.min (escapedPart.str.next escapedPart.stopPos) } if !isIdEndEscape (escapedPart.get <| escapedPart.prev escapedPart.bsize) then [] else splitRest (ss.extract escapedPart.bsize ss.bsize) (escapedPart :: acc) else if isIdFirst curr then let idPart := ss.takeWhile isIdRest splitRest (ss.extract idPart.bsize ss.bsize) (idPart :: acc) else [] /-- Split a name literal (without the backtick) into its dot-separated components. For example, `foo.bla.Β«bo.oΒ»` ↦ `["foo", "bla", "Β«bo.oΒ»"]`. If the literal cannot be parsed, return `[]`. -/ def splitNameLit (ss : Substring) : List Substring := splitNameLitAux ss [] |>.reverse def decodeNameLit (s : String) : Option Name := if s.get 0 == '`' then match splitNameLitAux (s.toSubstring.drop 1) [] with | [] => none | comps => some <| comps.foldr (init := Name.anonymous) fun comp n => let comp := if isIdBeginEscape comp.front then comp.drop 1 |>.dropRight 1 else comp Name.mkStr n comp.toString else none def isNameLit? (stx : Syntax) : Option Name := match isLit? nameLitKind stx with | some val => decodeNameLit val | _ => none def hasArgs : Syntax β†’ Bool | Syntax.node _ args => args.size > 0 | _ => false def isAtom : Syntax β†’ Bool | atom _ _ => true | _ => false def isToken (token : String) : Syntax β†’ Bool | atom _ val => val.trim == token.trim | _ => false def isNone (stx : Syntax) : Bool := match stx with | Syntax.node k args => k == nullKind && args.size == 0 -- when elaborating partial syntax trees, it's reasonable to interpret missing parts as `none` | Syntax.missing => true | _ => false def getOptional? (stx : Syntax) : Option Syntax := match stx with | Syntax.node k args => if k == nullKind && args.size == 1 then some (args.get! 0) else none | _ => none def getOptionalIdent? (stx : Syntax) : Option Name := match stx.getOptional? with | some stx => some stx.getId | none => none partial def findAux (p : Syntax β†’ Bool) : Syntax β†’ Option Syntax | stx@(Syntax.node _ args) => if p stx then some stx else args.findSome? (findAux p) | stx => if p stx then some stx else none def find? (stx : Syntax) (p : Syntax β†’ Bool) : Option Syntax := findAux p stx end Syntax /-- Reflect a runtime datum back to surface syntax (best-effort). -/ class Quote (Ξ± : Type) where quote : Ξ± β†’ Syntax export Quote (quote) instance : Quote Syntax := ⟨id⟩ instance : Quote Bool := ⟨fun | true => mkCIdent `Bool.true | false => mkCIdent `Bool.false⟩ instance : Quote String := ⟨Syntax.mkStrLit⟩ instance : Quote Nat := ⟨fun n => Syntax.mkNumLit <| toString n⟩ instance : Quote Substring := ⟨fun s => Syntax.mkCApp `String.toSubstring #[quote s.toString]⟩ -- in contrast to `Name.toString`, we can, and want to be, precise here private def getEscapedNameParts? (acc : List String) : Name β†’ OptionM (List String) | Name.anonymous => acc | Name.str n s _ => do let s ← Name.escapePart s getEscapedNameParts? (s::acc) n | Name.num n i _ => none private def quoteNameMk : Name β†’ Syntax | Name.anonymous => mkCIdent ``Name.anonymous | Name.str n s _ => Syntax.mkCApp ``Name.mkStr #[quoteNameMk n, quote s] | Name.num n i _ => Syntax.mkCApp ``Name.mkNum #[quoteNameMk n, quote i] instance : Quote Name where quote n := match getEscapedNameParts? [] n with | some ss => mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit ("`" ++ ".".intercalate ss)] | none => quoteNameMk n instance {Ξ± Ξ² : Type} [Quote Ξ±] [Quote Ξ²] : Quote (Ξ± Γ— Ξ²) where quote | ⟨a, b⟩ => Syntax.mkCApp ``Prod.mk #[quote a, quote b] private def quoteList {Ξ± : Type} [Quote Ξ±] : List Ξ± β†’ Syntax | [] => mkCIdent ``List.nil | (x::xs) => Syntax.mkCApp ``List.cons #[quote x, quoteList xs] instance {Ξ± : Type} [Quote Ξ±] : Quote (List Ξ±) where quote := quoteList instance {Ξ± : Type} [Quote Ξ±] : Quote (Array Ξ±) where quote xs := Syntax.mkCApp ``List.toArray #[quote xs.toList] private def quoteOption {Ξ± : Type} [Quote Ξ±] : Option Ξ± β†’ Syntax | none => mkIdent ``none | (some x) => Syntax.mkCApp ``some #[quote x] instance Option.hasQuote {Ξ± : Type} [Quote Ξ±] : Quote (Option Ξ±) where quote := quoteOption /- Evaluator for `prec` DSL -/ def evalPrec (stx : Syntax) : MacroM Nat := Macro.withIncRecDepth stx do let stx ← expandMacros stx match stx with | `(prec| $num:numLit) => return num.isNatLit?.getD 0 | _ => Macro.throwErrorAt stx "unexpected precedence" macro_rules | `(prec| $a + $b) => do `(prec| $(quote <| (← evalPrec a) + (← evalPrec b)):numLit) macro_rules | `(prec| $a - $b) => do `(prec| $(quote <| (← evalPrec a) - (← evalPrec b)):numLit) macro "eval_prec " p:prec:max : term => return quote (← evalPrec p) /- Evaluator for `prio` DSL -/ def evalPrio (stx : Syntax) : MacroM Nat := Macro.withIncRecDepth stx do let stx ← expandMacros stx match stx with | `(prio| $num:numLit) => return num.isNatLit?.getD 0 | _ => Macro.throwErrorAt stx "unexpected priority" macro_rules | `(prio| $a + $b) => do `(prio| $(quote <| (← evalPrio a) + (← evalPrio b)):numLit) macro_rules | `(prio| $a - $b) => do `(prio| $(quote <| (← evalPrio a) - (← evalPrio b)):numLit) macro "eval_prio " p:prio:max : term => return quote (← evalPrio p) def evalOptPrio : Option Syntax β†’ MacroM Nat | some prio => evalPrio prio | none => return eval_prio default end Lean namespace Array abbrev getSepElems := @getEvenElems open Lean private partial def filterSepElemsMAux {m : Type β†’ Type} [Monad m] (a : Array Syntax) (p : Syntax β†’ m Bool) (i : Nat) (acc : Array Syntax) : m (Array Syntax) := do if h : i < a.size then let stx := a.get ⟨i, h⟩ if (← p stx) then if acc.isEmpty then filterSepElemsMAux a p (i+2) (acc.push stx) else if hz : i β‰  0 then have : i.pred < i := Nat.pred_lt hz let sepStx := a.get ⟨i.pred, Nat.lt_trans this h⟩ filterSepElemsMAux a p (i+2) ((acc.push sepStx).push stx) else filterSepElemsMAux a p (i+2) (acc.push stx) else filterSepElemsMAux a p (i+2) acc else pure acc def filterSepElemsM {m : Type β†’ Type} [Monad m] (a : Array Syntax) (p : Syntax β†’ m Bool) : m (Array Syntax) := filterSepElemsMAux a p 0 #[] def filterSepElems (a : Array Syntax) (p : Syntax β†’ Bool) : Array Syntax := Id.run <| a.filterSepElemsM p private partial def mapSepElemsMAux {m : Type β†’ Type} [Monad m] (a : Array Syntax) (f : Syntax β†’ m Syntax) (i : Nat) (acc : Array Syntax) : m (Array Syntax) := do if h : i < a.size then let stx := a.get ⟨i, h⟩ if i % 2 == 0 then do let stx ← f stx mapSepElemsMAux a f (i+1) (acc.push stx) else mapSepElemsMAux a f (i+1) (acc.push stx) else pure acc def mapSepElemsM {m : Type β†’ Type} [Monad m] (a : Array Syntax) (f : Syntax β†’ m Syntax) : m (Array Syntax) := mapSepElemsMAux a f 0 #[] def mapSepElems (a : Array Syntax) (f : Syntax β†’ Syntax) : Array Syntax := Id.run <| a.mapSepElemsM f end Array namespace Lean.Syntax.SepArray def getElems {sep} (sa : SepArray sep) : Array Syntax := sa.elemsAndSeps.getSepElems /- We use `CoeTail` here instead of `Coe` to avoid a "loop" when computing `CoeTC`. The "loop" is interrupted using the maximum instance size threshold, but it is a performance bottleneck. The loop occurs because the predicate `isNewAnswer` is too imprecise. -/ instance (sep) : CoeTail (SepArray sep) (Array Syntax) where coe := getElems end Lean.Syntax.SepArray /-- Gadget for automatic parameter support. This is similar to the `optParam` gadget, but it uses the given tactic. Like `optParam`, this gadget only affects elaboration. For example, the tactic will *not* be invoked during type class resolution. -/ abbrev autoParam.{u} (Ξ± : Sort u) (tactic : Lean.Syntax) : Sort u := Ξ± /- Helper functions for manipulating interpolated strings -/ namespace Lean.Syntax private def decodeInterpStrQuotedChar (s : String) (i : String.Pos) : Option (Char Γ— String.Pos) := OptionM.run do match decodeQuotedChar s i with | some r => some r | none => let c := s.get i let i := s.next i if c == '{' then pure ('{', i) else none private partial def decodeInterpStrLit (s : String) : Option String := let rec loop (i : String.Pos) (acc : String) : OptionM String := let c := s.get i let i := s.next i if c == '\"' || c == '{' then pure acc else if s.atEnd i then none else if c == '\\' then do let (c, i) ← decodeInterpStrQuotedChar s i loop i (acc.push c) else loop i (acc.push c) loop 1 "" partial def isInterpolatedStrLit? (stx : Syntax) : Option String := match isLit? interpolatedStrLitKind stx with | none => none | some val => decodeInterpStrLit val def expandInterpolatedStrChunks (chunks : Array Syntax) (mkAppend : Syntax β†’ Syntax β†’ MacroM Syntax) (mkElem : Syntax β†’ MacroM Syntax) : MacroM Syntax := do let mut i := 0 let mut result := Syntax.missing for elem in chunks do let elem ← match elem.isInterpolatedStrLit? with | none => mkElem elem | some str => mkElem (Syntax.mkStrLit str) if i == 0 then result := elem else result ← mkAppend result elem i := i+1 return result def expandInterpolatedStr (interpStr : Syntax) (type : Syntax) (toTypeFn : Syntax) : MacroM Syntax := do let ref := interpStr let r ← expandInterpolatedStrChunks interpStr.getArgs (fun a b => `($a ++ $b)) (fun a => `($toTypeFn $a)) `(($r : $type)) def getSepArgs (stx : Syntax) : Array Syntax := stx.getArgs.getSepElems end Syntax namespace Meta.Simp def defaultMaxSteps := 100000 structure Config where maxSteps : Nat := defaultMaxSteps maxDischargeDepth : Nat := 2 contextual : Bool := false memoize : Bool := true singlePass : Bool := false zeta : Bool := true beta : Bool := true eta : Bool := true iota : Bool := true proj : Bool := true decide : Bool := true deriving Inhabited, BEq, Repr -- Configuration object for `simp_all` structure ConfigCtx extends Config where contextual := true end Meta.Simp end Lean
96f8925276acc0f026c180ee707faef33558ff41
46125763b4dbf50619e8846a1371029346f4c3db
/src/topology/sequences.lean
9540a5a2722be5273f58f623f5b777173a45646d
[ "Apache-2.0" ]
permissive
thjread/mathlib
a9d97612cedc2c3101060737233df15abcdb9eb1
7cffe2520a5518bba19227a107078d83fa725ddc
refs/heads/master
1,615,637,696,376
1,583,953,063,000
1,583,953,063,000
246,680,271
0
0
Apache-2.0
1,583,960,875,000
1,583,960,875,000
null
UTF-8
Lean
false
false
9,094
lean
/- Copyright (c) 2018 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow -/ import topology.basic import topology.bases /-! # Sequences in topological spaces In this file we define sequences in topological spaces and show how they are related to filters and the topology. In particular, we * associate a filter with a sequence and prove equivalence of convergence of the two, * define the sequential closure of a set and prove that it's contained in the closure, * define a type class "sequential_space" in which closure and sequential closure agree, * define sequential continuity and show that it coincides with continuity in sequential spaces, * provide an instance that shows that every first-countable (and in particular metric) space is a sequential space. # TODO * Sequential compactness should be handled here. -/ open set filter open_locale topological_space variables {Ξ± : Type*} {Ξ² : Type*} local notation f ` ⟢ ` limit := tendsto f at_top (𝓝 limit) /-! ### Statements about sequences in general topological spaces. -/ section topological_space variables [topological_space Ξ±] [topological_space Ξ²] /-- A sequence converges in the sence of topological spaces iff the associated statement for filter holds. -/ lemma topological_space.seq_tendsto_iff {x : β„• β†’ Ξ±} {limit : Ξ±} : tendsto x at_top (𝓝 limit) ↔ βˆ€ U : set Ξ±, limit ∈ U β†’ is_open U β†’ βˆƒ n0 : β„•, βˆ€ n β‰₯ n0, (x n) ∈ U := (at_top_basis.tendsto_iff (nhds_basis_opens limit)).trans $ by simp only [and_imp, exists_prop, true_and, set.mem_Ici, ge_iff_le, id] /-- The sequential closure of a subset M βŠ† Ξ± of a topological space Ξ± is the set of all p ∈ Ξ± which arise as limit of sequences in M. -/ def sequential_closure (M : set Ξ±) : set Ξ± := {p | βˆƒ x : β„• β†’ Ξ±, (βˆ€ n : β„•, x n ∈ M) ∧ (x ⟢ p)} lemma subset_sequential_closure (M : set Ξ±) : M βŠ† sequential_closure M := assume p (_ : p ∈ M), show p ∈ sequential_closure M, from ⟨λ n, p, assume n, β€Ήp ∈ Mβ€Ί, tendsto_const_nhds⟩ /-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`, the limit belongs to `s` as well. -/ def is_seq_closed (s : set Ξ±) : Prop := s = sequential_closure s /-- A convenience lemma for showing that a set is sequentially closed. -/ lemma is_seq_closed_of_def {A : set Ξ±} (h : βˆ€(x : β„• β†’ Ξ±) (p : Ξ±), (βˆ€ n : β„•, x n ∈ A) β†’ (x ⟢ p) β†’ p ∈ A) : is_seq_closed A := show A = sequential_closure A, from subset.antisymm (subset_sequential_closure A) (show βˆ€ p, p ∈ sequential_closure A β†’ p ∈ A, from (assume p ⟨x, _, _⟩, show p ∈ A, from h x p β€Ήβˆ€ n : β„•, ((x n) ∈ A)β€Ί β€Ή(x ⟢ p)β€Ί)) /-- The sequential closure of a set is contained in the closure of that set. The converse is not true. -/ lemma sequential_closure_subset_closure (M : set Ξ±) : sequential_closure M βŠ† closure M := assume p ⟨x, xM, xp⟩, mem_closure_of_tendsto at_top_ne_bot xp (univ_mem_sets' xM) /-- A set is sequentially closed if it is closed. -/ lemma is_seq_closed_of_is_closed (M : set Ξ±) (_ : is_closed M) : is_seq_closed M := suffices sequential_closure M βŠ† M, from set.eq_of_subset_of_subset (subset_sequential_closure M) this, calc sequential_closure M βŠ† closure M : sequential_closure_subset_closure M ... = M : closure_eq_of_is_closed β€Ήis_closed Mβ€Ί /-- The limit of a convergent sequence in a sequentially closed set is in that set.-/ lemma mem_of_is_seq_closed {A : set Ξ±} (_ : is_seq_closed A) {x : β„• β†’ Ξ±} (_ : βˆ€ n, x n ∈ A) {limit : Ξ±} (_ : (x ⟢ limit)) : limit ∈ A := have limit ∈ sequential_closure A, from show βˆƒ x : β„• β†’ Ξ±, (βˆ€ n : β„•, x n ∈ A) ∧ (x ⟢ limit), from ⟨x, β€Ήβˆ€ n, x n ∈ Aβ€Ί, β€Ή(x ⟢ limit)β€ΊβŸ©, eq.subst (eq.symm β€Ήis_seq_closed Aβ€Ί) β€Ήlimit ∈ sequential_closure Aβ€Ί /-- The limit of a convergent sequence in a closed set is in that set.-/ lemma mem_of_is_closed_sequential {A : set Ξ±} (_ : is_closed A) {x : β„• β†’ Ξ±} (_ : βˆ€ n, x n ∈ A) {limit : Ξ±} (_ : x ⟢ limit) : limit ∈ A := mem_of_is_seq_closed (is_seq_closed_of_is_closed A β€Ήis_closed Aβ€Ί) β€Ήβˆ€ n, x n ∈ Aβ€Ί β€Ή(x ⟢ limit)β€Ί /-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be formalised by demanding that the sequential closure and the closure coincide. The following statements show that other topological properties can be deduced from sequences in sequential spaces. -/ class sequential_space (Ξ± : Type*) [topological_space Ξ±] : Prop := (sequential_closure_eq_closure : βˆ€ M : set Ξ±, sequential_closure M = closure M) /-- In a sequential space, a set is closed iff it's sequentially closed. -/ lemma is_seq_closed_iff_is_closed [sequential_space Ξ±] {M : set Ξ±} : is_seq_closed M ↔ is_closed M := iff.intro (assume _, closure_eq_iff_is_closed.mp (eq.symm (calc M = sequential_closure M : by assumption ... = closure M : sequential_space.sequential_closure_eq_closure M))) (is_seq_closed_of_is_closed M) /-- In a sequential space, a point belongs to the closure of a set iff it is a limit of a sequence taking values in this set. -/ lemma mem_closure_iff_seq_limit [sequential_space Ξ±] {s : set Ξ±} {a : Ξ±} : a ∈ closure s ↔ βˆƒ x : β„• β†’ Ξ±, (βˆ€ n : β„•, x n ∈ s) ∧ (x ⟢ a) := by { rw ← sequential_space.sequential_closure_eq_closure, exact iff.rfl } /-- A function between topological spaces is sequentially continuous if it commutes with limit of convergent sequences. -/ def sequentially_continuous (f : Ξ± β†’ Ξ²) : Prop := βˆ€ (x : β„• β†’ Ξ±), βˆ€ {limit : Ξ±}, (x ⟢ limit) β†’ (f∘x ⟢ f limit) /- A continuous function is sequentially continuous. -/ lemma continuous.to_sequentially_continuous {f : Ξ± β†’ Ξ²} (_ : continuous f) : sequentially_continuous f := assume x limit (_ : x ⟢ limit), have tendsto f (𝓝 limit) (𝓝 (f limit)), from continuous.tendsto β€Ήcontinuous fβ€Ί limit, show (f ∘ x) ⟢ (f limit), from tendsto.comp this β€Ή(x ⟢ limit)β€Ί /-- In a sequential space, continuity and sequential continuity coincide. -/ lemma continuous_iff_sequentially_continuous {f : Ξ± β†’ Ξ²} [sequential_space Ξ±] : continuous f ↔ sequentially_continuous f := iff.intro (assume _, β€Ήcontinuous fβ€Ί.to_sequentially_continuous) (assume : sequentially_continuous f, show continuous f, from suffices h : βˆ€ {A : set Ξ²}, is_closed A β†’ is_seq_closed (f ⁻¹' A), from continuous_iff_is_closed.mpr (assume A _, is_seq_closed_iff_is_closed.mp $ h β€Ήis_closed Aβ€Ί), assume A (_ : is_closed A), is_seq_closed_of_def $ assume (x : β„• β†’ Ξ±) p (_ : βˆ€ n, f (x n) ∈ A) (_ : x ⟢ p), have (f ∘ x) ⟢ (f p), from β€Ήsequentially_continuous fβ€Ί x β€Ή(x ⟢ p)β€Ί, show f p ∈ A, from mem_of_is_closed_sequential β€Ήis_closed Aβ€Ί β€Ήβˆ€ n, f (x n) ∈ Aβ€Ί β€Ή(f∘x ⟢ f p)β€Ί) end topological_space namespace topological_space namespace first_countable_topology /-- Every first-countable space is sequential. -/ @[priority 100] -- see Note [lower instance priority] instance [topological_space Ξ±] [first_countable_topology Ξ±] : sequential_space Ξ± := ⟨show βˆ€ M, sequential_closure M = closure M, from assume M, suffices closure M βŠ† sequential_closure M, from set.subset.antisymm (sequential_closure_subset_closure M) this, -- For every p ∈ closure M, we need to construct a sequence x in M that converges to p: assume (p : Ξ±) (hp : p ∈ closure M), -- Since we are in a first-countable space, there exists a monotonically decreasing -- sequence g of sets generating the neighborhood filter around p: exists.elim (mono_seq_of_has_countable_basis _ (nhds_generated_countable p)) $ assume g ⟨gmon, gbasis⟩, -- (g i) is a neighborhood of p and hence intersects M. -- Via choice we obtain the sequence x such that (x i).val ∈ g i ∩ M: have x : Ξ  i, g i ∩ M, { rw mem_closure_iff_nhds at hp, intro i, apply classical.indefinite_description, apply hp, rw gbasis, rw ← le_principal_iff, apply lattice.infi_le_of_le i _, apply le_refl _ }, -- It remains to show that x converges to p. Intuitively this is the case -- because x i ∈ g i, and the g i get "arbitrarily small" around p. Formally: have gssnhds : βˆ€ s ∈ 𝓝 p, βˆƒ i, g i βŠ† s, { intro s, rw gbasis, rw mem_infi, { simp, intros i hi, use i, assumption }, { apply lattice.directed_of_mono, intros, apply principal_mono.mpr, apply gmon, assumption }, { apply_instance } }, -- For the sequence (x i) we can now show that a) it lies in M, and b) converges to p. ⟨λ i, (x i).val, by intro i; simp [(x i).property.right], begin rw tendsto_at_top', intros s nhdss, rcases gssnhds s nhdss with ⟨i, hi⟩, use i, intros j hij, apply hi, apply gmon _ _ hij, simp [(x j).property.left] end⟩⟩ end first_countable_topology end topological_space
2ae763fff1704578ef597aa1a91a2d21bfca9a16
6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf
/src/my_solutions/world1_addition.lean
b4cff42dc253b16543f96523b22d3c6d3633f239
[ "Apache-2.0" ]
permissive
arolihas/natural_number_game
4f0c93feefec93b8824b2b96adff8b702b8b43ce
8e4f7b4b42888a3b77429f90cce16292bd288138
refs/heads/master
1,621,872,426,808
1,586,270,467,000
1,586,270,467,000
253,648,466
0
0
null
1,586,219,694,000
1,586,219,694,000
null
UTF-8
Lean
false
false
6,095
lean
import mynat.definition -- Imports the natural numbers. /- Here's what you get from the import: 1) The following data: * a type called `mynat` * a term `0 : mynat`, interpreted as the number zero. * a function `succ : mynat β†’ mynat`, with `succ n` interpreted as "the number after n". * Usual numerical notation 0,1,2,3,4,5 etc. 2) The following axioms: * `zero_ne_succ : βˆ€ (a : mynat), zero β‰  succ(a)`, the statement that zero isn't a successor. -- this ensures that there is more than one natural number. * `succ_inj : βˆ€ {a b : mynat}, succ(a) = succ(b) β†’ a = b`, the statement that if succ(a) = succ(b) then a = b. -- this ensures that there are infinitely many natural numbers. 3) The principle of mathematical induction. * In practice this means that if you have `n : mynat` then you can use the tactic `induction n`. 4) A few useful extra things: * The theorem `one_eq_succ_zero : 1 = succ 0` * The theorem `ne_iff_implies_false : a β‰  b ↔ (a = b) β†’ false` -/ import mynat.add -- definition of addition /- Here's what you get from the import: 1) The following data: * a function called mynat.add, and notation a + b for this function 2) The following axioms: * `add_zero : βˆ€ a : mynat, a + 0 = a` * `add_succ : βˆ€ a b : mynat, a + succ(b) = succ(a + b)` These axiom between them tell you how to work out a + x for every x; use induction on x to reduce to the case either `x = 0` or `x = succ b`, and then use `add_zero` or `add_succ` appropriately. -/ namespace mynat -- Summary: -- Naturals: -- 1) 0 and succ are constants -- 2) succ_inj and zero_ne_succ are axioms -- 3) Induction works. -- Addition: -- 1) add_zero and add_succ are the axioms -- 2) notation is a + b /- Collectibles in this level: add_comm_monoid -- collectible_02 add_monoid [zero_add] -- collectible_01 (has_zero) add_semigroup [add_assoc] (has_add) add_comm_semigroup [add_comm] add_semigroup (see above) -/ /- Instructions: First carefully explain definition of nat and add. Then guide them through the first level. "We're going to prove this by induction on n, which is a natural thing to do because we defined addition by recursion on n (you prove things by induction and define them by recursion). For the base case, we are going to use the axiom that a + 0 = 0. refl closes a goal of the form x = x. how to use add_succ here? etc. Full solution to zero_add: induction n with d hd, rw add_zero, refl, rw add_succ, rw hd, refl, " -/ lemma zero_add (n : mynat) : 0 + n = n := begin [nat_num_game] induction n with d hd, rw add_zero, refl, rw add_succ, rw hd, refl, end lemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) := begin [nat_num_game] induction c with n hd, rw add_zero, rw add_zero, refl, rw add_succ, rw add_succ, rw add_succ, rw hd, refl, end -- first point: needs add_assoc, zero_add, add_zero def collectible_01 : add_monoid mynat := by structure_helper --#print axioms collectible_01 -- prove you got this by uncommenting -- proving add_comm immediately is still tricky; trying it -- reveals a natural intermediate lemma which we prove first. lemma succ_add (a b : mynat) : succ a + b = succ (a + b) := begin [nat_num_game] induction b with n hd, rw add_zero, rw add_zero, refl, rw add_succ, rw add_succ, rw hd, refl, end lemma add_comm (a b : mynat) : a + b = b + a := begin [nat_num_game] induction b with n hd, rw add_zero, rw zero_add, refl, rw add_succ, rw succ_add, rw hd, refl, end -- level up def collectible_02 : add_comm_monoid mynat := by structure_helper --#print axioms collectible_02 -- no more collectibles beyond this point in this file, however -- stuff below is used in other collectibles in other files. theorem succ_ne_zero : βˆ€ {{a : mynat}}, succ a β‰  0 := begin [nat_num_game] intro a, symmetry, exact zero_ne_succ a, end theorem eq_iff_succ_eq_succ (a b : mynat) : succ a = succ b ↔ a = b := begin [nat_num_game] split, exact succ_inj, intro n, rw n, refl, end theorem succ_eq_add_one (n : mynat) : succ n = n + 1 := begin [nat_num_game] rw one_eq_succ_zero, rw add_succ, rw add_zero, refl, end lemma add_right_comm (a b c : mynat) : a + b + c = a + c + b := begin [nat_num_game] rw add_assoc, rw add_assoc, rw add_comm b, refl, end theorem add_left_cancel ⦃ a b c : mynat⦄ : a + b = a + c β†’ b = c := begin [nat_num_game] intro n, revert b c, induction a with d hd, intros b c h, rw zero_add at h, rw zero_add at h, exact h, intros b c h, rw succ_add at h, rw succ_add at h, rw ← add_succ at h, rw ← add_succ at h, apply succ_inj, exact hd h, end theorem add_right_cancel ⦃a b c : mynat⦄ : a + b = c + b β†’ a = c := begin [nat_num_game] intro h, rw add_comm at h, rw add_comm c at h, exact add_left_cancel h, end theorem add_right_cancel_iff (t a b : mynat) : a + t = b + t ↔ a = b := begin [nat_num_game] split, apply add_right_cancel, intro h, rw h, refl, end -- this is used for antisymmetry of ≀ lemma eq_zero_of_add_right_eq_self {{a b : mynat}} : a + b = a β†’ b = 0 := begin [nat_num_game] intro h, induction a with n hd, rw zero_add at h, exact h, apply hd, apply succ_inj, rw succ_add at h, exact h, end -- now used for antisymmetry of ≀ lemma add_left_eq_zero {{a b : mynat}} : a + b = 0 β†’ b = 0 := begin [nat_num_game] intro h, induction b with n hd, refl, rw add_succ at h, exfalso, apply zero_ne_succ, rw h, refl, end lemma add_right_eq_zero {{a b : mynat}} : a + b = 0 β†’ a = 0 := begin [nat_num_game] intro h, rw add_comm a at h, exact add_left_eq_zero h, end theorem add_one_eq_succ (d : mynat) : d + 1 = succ d := begin [nat_num_game] induction d with n hd, apply succ_eq_add_one, rw succ_add, rw hd, refl, end def ne_succ_self (n : mynat) : n β‰  succ n := begin [nat_num_game] induction n with d hd, apply zero_ne_succ, intro h, apply hd, apply succ_inj, exact h, end end mynat
a9822294117d54a0365e16dd06f8e4ed8c69b54b
e00ea76a720126cf9f6d732ad6216b5b824d20a7
/src/data/option/defs.lean
0ba5d155a2a5078bec2244700c5ce9aa4292712a
[ "Apache-2.0" ]
permissive
vaibhavkarve/mathlib
a574aaf68c0a431a47fa82ce0637f0f769826bfe
17f8340912468f49bdc30acdb9a9fa02eeb0473a
refs/heads/master
1,621,263,802,637
1,585,399,588,000
1,585,399,588,000
250,833,447
0
0
Apache-2.0
1,585,410,341,000
1,585,410,341,000
null
UTF-8
Lean
false
false
3,782
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Extra definitions on option. -/ namespace option variables {Ξ± : Type*} {Ξ² : Type*} /-- An elimination principle for `option`. It is a nondependent version of `option.rec_on`. -/ protected def elim : option Ξ± β†’ Ξ² β†’ (Ξ± β†’ Ξ²) β†’ Ξ² | (some x) y f := f x | none y f := y instance has_mem : has_mem Ξ± (option Ξ±) := ⟨λ a b, b = some a⟩ @[simp] theorem mem_def {a : Ξ±} {b : option Ξ±} : a ∈ b ↔ b = some a := iff.rfl theorem is_none_iff_eq_none {o : option Ξ±} : o.is_none = tt ↔ o = none := ⟨option.eq_none_of_is_none, Ξ» e, e.symm β–Έ rfl⟩ theorem some_inj {a b : Ξ±} : some a = some b ↔ a = b := by simp instance decidable_eq_none {o : option Ξ±} : decidable (o = none) := decidable_of_decidable_of_iff (bool.decidable_eq _ _) is_none_iff_eq_none instance decidable_forall_mem {p : Ξ± β†’ Prop} [decidable_pred p] : βˆ€ o : option Ξ±, decidable (βˆ€ a ∈ o, p a) | none := is_true (by simp) | (some a) := if h : p a then is_true $ Ξ» o e, some_inj.1 e β–Έ h else is_false $ mt (Ξ» H, H _ rfl) h instance decidable_exists_mem {p : Ξ± β†’ Prop} [decidable_pred p] : βˆ€ o : option Ξ±, decidable (βˆƒ a ∈ o, p a) | none := is_false (Ξ» ⟨a, ⟨h, _⟩⟩, by cases h) | (some a) := if h : p a then is_true $ ⟨_, rfl, h⟩ else is_false $ Ξ» ⟨_, ⟨rfl, hn⟩⟩, h hn /-- inhabited `get` function. Returns `a` if the input is `some a`, otherwise returns `default`. -/ @[reducible] def iget [inhabited Ξ±] : option Ξ± β†’ Ξ± | (some x) := x | none := default Ξ± @[simp] theorem iget_some [inhabited Ξ±] {a : Ξ±} : (some a).iget = a := rfl /-- `guard p a` returns `some a` if `p a` holds, otherwise `none`. -/ def guard (p : Ξ± β†’ Prop) [decidable_pred p] (a : Ξ±) : option Ξ± := if p a then some a else none /-- `filter p o` returns `some a` if `o` is `some a` and `p a` holds, otherwise `none`. -/ def filter (p : Ξ± β†’ Prop) [decidable_pred p] (o : option Ξ±) : option Ξ± := o.bind (guard p) def to_list : option Ξ± β†’ list Ξ± | none := [] | (some a) := [a] @[simp] theorem mem_to_list {a : Ξ±} {o : option Ξ±} : a ∈ to_list o ↔ a ∈ o := by cases o; simp [to_list, eq_comm] def lift_or_get (f : Ξ± β†’ Ξ± β†’ Ξ±) : option Ξ± β†’ option Ξ± β†’ option Ξ± | none none := none | (some a) none := some a -- get a | none (some b) := some b -- get b | (some a) (some b) := some (f a b) -- lift f instance lift_or_get_comm (f : Ξ± β†’ Ξ± β†’ Ξ±) [h : is_commutative Ξ± f] : is_commutative (option Ξ±) (lift_or_get f) := ⟨λ a b, by cases a; cases b; simp [lift_or_get, h.comm]⟩ instance lift_or_get_assoc (f : Ξ± β†’ Ξ± β†’ Ξ±) [h : is_associative Ξ± f] : is_associative (option Ξ±) (lift_or_get f) := ⟨λ a b c, by cases a; cases b; cases c; simp [lift_or_get, h.assoc]⟩ instance lift_or_get_idem (f : Ξ± β†’ Ξ± β†’ Ξ±) [h : is_idempotent Ξ± f] : is_idempotent (option Ξ±) (lift_or_get f) := ⟨λ a, by cases a; simp [lift_or_get, h.idempotent]⟩ instance lift_or_get_is_left_id (f : Ξ± β†’ Ξ± β†’ Ξ±) : is_left_id (option Ξ±) (lift_or_get f) none := ⟨λ a, by cases a; simp [lift_or_get]⟩ instance lift_or_get_is_right_id (f : Ξ± β†’ Ξ± β†’ Ξ±) : is_right_id (option Ξ±) (lift_or_get f) none := ⟨λ a, by cases a; simp [lift_or_get]⟩ inductive rel (r : Ξ± β†’ Ξ² β†’ Prop) : option Ξ± β†’ option Ξ² β†’ Prop | some {a b} : r a b β†’ rel (some a) (some b) | none {} : rel none none protected def {u v} traverse {F : Type u β†’ Type v} [applicative F] {Ξ± Ξ² : Type*} (f : Ξ± β†’ F Ξ²) : option Ξ± β†’ F (option Ξ²) | none := pure none | (some x) := some <$> f x end option
fc7e42cfd65f000488ac1bfdc06cb97f137b29f8
ac92829298855d39b757cf1fddca8f058436f027
/hott/eq2.hlean
975344cc9fdba71f27cf085a8d98d66e8cb31536
[ "Apache-2.0" ]
permissive
avigad/lean2
7af27190b9697b69a13268a133c1d3c8df85d2cf
34dbd6c3ae612186b8f0f80d12fbf5ae7a059ec9
refs/heads/master
1,592,027,477,851
1,500,732,234,000
1,500,732,234,000
75,484,066
0
0
null
1,480,781,056,000
1,480,781,056,000
null
UTF-8
Lean
false
false
11,985
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn Theorems about 2-dimensional paths -/ import .cubical.square .function open function is_equiv equiv namespace eq variables {A B C : Type} {f : A β†’ B} {a a' a₁ aβ‚‚ a₃ aβ‚„ : A} {b b' : B} theorem ap_is_constant_eq (p : Ξ x, f x = b) (q : a = a') : ap_is_constant p q = eq_con_inv_of_con_eq ((eq_of_square (square_of_pathover (apd p q)))⁻¹ ⬝ whisker_left (p a) (ap_constant q b)) := begin induction q, esimp, generalize (p a), intro p, cases p, apply idpath idp end definition ap_inv2 {p q : a = a'} (r : p = q) : square (ap (ap f) (inverse2 r)) (inverse2 (ap (ap f) r)) (ap_inv f p) (ap_inv f q) := by induction r;exact hrfl definition ap_con2 {p₁ q₁ : a₁ = aβ‚‚} {pβ‚‚ qβ‚‚ : aβ‚‚ = a₃} (r₁ : p₁ = q₁) (rβ‚‚ : pβ‚‚ = qβ‚‚) : square (ap (ap f) (r₁ β—Ύ rβ‚‚)) (ap (ap f) r₁ β—Ύ ap (ap f) rβ‚‚) (ap_con f p₁ pβ‚‚) (ap_con f q₁ qβ‚‚) := by induction rβ‚‚;induction r₁;exact hrfl theorem ap_con_right_inv_sq {A B : Type} {a1 a2 : A} (f : A β†’ B) (p : a1 = a2) : square (ap (ap f) (con.right_inv p)) (con.right_inv (ap f p)) (ap_con f p p⁻¹ ⬝ whisker_left _ (ap_inv f p)) idp := by cases p;apply hrefl theorem ap_con_left_inv_sq {A B : Type} {a1 a2 : A} (f : A β†’ B) (p : a1 = a2) : square (ap (ap f) (con.left_inv p)) (con.left_inv (ap f p)) (ap_con f p⁻¹ p ⬝ whisker_right _ (ap_inv f p)) idp := by cases p;apply vrefl definition ap02_compose {A B C : Type} (g : B β†’ C) (f : A β†’ B) {a a' : A} {p₁ pβ‚‚ : a = a'} (q : p₁ = pβ‚‚) : square (ap_compose g f p₁) (ap_compose g f pβ‚‚) (ap02 (g ∘ f) q) (ap02 g (ap02 f q)) := by induction q; exact vrfl definition ap02_id {A : Type} {a a' : A} {p₁ pβ‚‚ : a = a'} (q : p₁ = pβ‚‚) : square (ap_id p₁) (ap_id pβ‚‚) (ap02 id q) q := by induction q; exact vrfl theorem ap_ap_is_constant {A B C : Type} (g : B β†’ C) {f : A β†’ B} {b : B} (p : Ξ x, f x = b) {x y : A} (q : x = y) : square (ap (ap g) (ap_is_constant p q)) (ap_is_constant (Ξ»a, ap g (p a)) q) (ap_compose g f q)⁻¹ (!ap_con ⬝ whisker_left _ !ap_inv) := begin induction q, esimp, generalize (p x), intro p, cases p, apply ids -- induction q, rewrite [↑ap_compose,ap_inv], apply hinverse, apply ap_con_right_inv_sq, end theorem ap_ap_compose {A B C D : Type} (h : C β†’ D) (g : B β†’ C) (f : A β†’ B) {x y : A} (p : x = y) : square (ap_compose (h ∘ g) f p) (ap (ap h) (ap_compose g f p)) (ap_compose h (g ∘ f) p) (ap_compose h g (ap f p)) := by induction p;exact ids theorem ap_compose_inv {A B C : Type} (g : B β†’ C) (f : A β†’ B) {x y : A} (p : x = y) : square (ap_compose g f p⁻¹) (inverse2 (ap_compose g f p) ⬝ (ap_inv g (ap f p))⁻¹) (ap_inv (g ∘ f) p) (ap (ap g) (ap_inv f p)) := by induction p;exact ids theorem ap_compose_con (g : B β†’ C) (f : A β†’ B) (p : a₁ = aβ‚‚) (q : aβ‚‚ = a₃) : square (ap_compose g f (p ⬝ q)) (ap_compose g f p β—Ύ ap_compose g f q ⬝ (ap_con g (ap f p) (ap f q))⁻¹) (ap_con (g ∘ f) p q) (ap (ap g) (ap_con f p q)) := by induction q;induction p;exact ids theorem ap_compose_natural {A B C : Type} (g : B β†’ C) (f : A β†’ B) {x y : A} {p q : x = y} (r : p = q) : square (ap (ap (g ∘ f)) r) (ap (ap g ∘ ap f) r) (ap_compose g f p) (ap_compose g f q) := natural_square_tr (ap_compose g f) r theorem whisker_right_eq_of_con_inv_eq_idp {p q : a₁ = aβ‚‚} (r : p ⬝ q⁻¹ = idp) : whisker_right q⁻¹ (eq_of_con_inv_eq_idp r) ⬝ con.right_inv q = r := by induction q; esimp at r; cases r; reflexivity theorem ap_eq_of_con_inv_eq_idp (f : A β†’ B) {p q : a₁ = aβ‚‚} (r : p ⬝ q⁻¹ = idp) : ap02 f (eq_of_con_inv_eq_idp r) = eq_of_con_inv_eq_idp (whisker_left _ !ap_inv⁻¹ ⬝ !ap_con⁻¹ ⬝ ap02 f r) := by induction q;esimp at *;cases r;reflexivity theorem eq_of_con_inv_eq_idp_con2 {p p' q q' : a₁ = aβ‚‚} (r : p = p') (s : q = q') (t : p' ⬝ q'⁻¹ = idp) : eq_of_con_inv_eq_idp (r β—Ύ inverse2 s ⬝ t) = r ⬝ eq_of_con_inv_eq_idp t ⬝ s⁻¹ := by induction s;induction r;induction q;reflexivity definition naturality_apd_eq {A : Type} {B : A β†’ Type} {a aβ‚‚ : A} {f g : Ξ a, B a} (H : f ~ g) (p : a = aβ‚‚) : apd f p = concato_eq (eq_concato (H a) (apd g p)) (H aβ‚‚)⁻¹ := begin induction p, esimp, generalizes [H a, g a], intro ga Ha, induction Ha, reflexivity end theorem con_tr_idp {P : A β†’ Type} {x y : A} (q : x = y) (u : P x) : con_tr idp q u = ap (Ξ»p, p β–Έ u) (idp_con q) := by induction q;reflexivity definition eq_transport_Fl_idp_left {A B : Type} {a : A} {b : B} (f : A β†’ B) (q : f a = b) : eq_transport_Fl idp q = !idp_con⁻¹ := by induction q; reflexivity definition whisker_left_idp_con_eq_assoc {A : Type} {a₁ aβ‚‚ a₃ : A} (p : a₁ = aβ‚‚) (q : aβ‚‚ = a₃) : whisker_left p (idp_con q)⁻¹ = con.assoc p idp q := by induction q; reflexivity definition whisker_left_inverse2 {A : Type} {a : A} {p : a = a} (q : p = idp) : whisker_left p q⁻² ⬝ q = con.right_inv p := by cases q; reflexivity definition cast_fn_cast_square {A : Type} {B C : A β†’ Type} (f : Π⦃a⦄, B a β†’ C a) {a₁ aβ‚‚ : A} (p : a₁ = aβ‚‚) (q : aβ‚‚ = a₁) (r : p ⬝ q = idp) (b : B a₁) : cast (ap C q) (f (cast (ap B p) b)) = f b := have q⁻¹ = p, from inv_eq_of_idp_eq_con r⁻¹, begin induction this, induction q, reflexivity end definition ap011_ap_square_right {A B C : Type} (f : A β†’ B β†’ C) {a a' : A} (p : a = a') {b₁ bβ‚‚ b₃ : B} {q₁₂ : b₁ = bβ‚‚} {q₂₃ : bβ‚‚ = b₃} {q₁₃ : b₁ = b₃} (r : q₁₂ ⬝ q₂₃ = q₁₃) : square (ap011 f p q₁₂) (ap (Ξ»x, f x b₃) p) (ap (f a) q₁₃) (ap (f a') q₂₃) := by induction r; induction q₂₃; induction q₁₂; induction p; exact ids definition ap011_ap_square_left {A B C : Type} (f : B β†’ A β†’ C) {a a' : A} (p : a = a') {b₁ bβ‚‚ b₃ : B} {q₁₂ : b₁ = bβ‚‚} {q₂₃ : bβ‚‚ = b₃} {q₁₃ : b₁ = b₃} (r : q₁₂ ⬝ q₂₃ = q₁₃) : square (ap011 f q₁₂ p) (ap (f b₃) p) (ap (Ξ»x, f x a) q₁₃) (ap (Ξ»x, f x a') q₂₃) := by induction r; induction q₂₃; induction q₁₂; induction p; exact ids definition con2_assoc {A : Type} {x y z t : A} {p p' : x = y} {q q' : y = z} {r r' : z = t} (h : p = p') (h' : q = q') (h'' : r = r') : square ((h β—Ύ h') β—Ύ h'') (h β—Ύ (h' β—Ύ h'')) (con.assoc p q r) (con.assoc p' q' r') := by induction h; induction h'; induction h''; exact hrfl definition con_left_inv_idp {A : Type} {x : A} {p : x = x} (q : p = idp) : con.left_inv p = q⁻² β—Ύ q := by cases q; reflexivity definition eckmann_hilton_con2 {A : Type} {x : A} {p p' q q': idp = idp :> x = x} (h : p = p') (h' : q = q') : square (h β—Ύ h') (h' β—Ύ h) (eckmann_hilton p q) (eckmann_hilton p' q') := by induction h; induction h'; exact hrfl definition ap_con_fn {A B : Type} {a a' : A} {b : B} (g h : A β†’ b = b) (p : a = a') : ap (Ξ»a, g a ⬝ h a) p = ap g p β—Ύ ap h p := by induction p; reflexivity definition ap_eq_ap011 {A B C X : Type} (f : A β†’ B β†’ C) (g : X β†’ A) (h : X β†’ B) {x x' : X} (p : x = x') : ap (Ξ»x, f (g x) (h x)) p = ap011 f (ap g p) (ap h p) := by induction p; reflexivity definition ap_is_weakly_constant {A B : Type} {f : A β†’ B} (h : is_weakly_constant f) {a a' : A} (p : a = a') : ap f p = (h a a)⁻¹ ⬝ h a a' := by induction p; exact !con.left_inv⁻¹ definition ap_is_constant_idp {A B : Type} {f : A β†’ B} {b : B} (p : Ξ a, f a = b) {a : A} (q : a = a) (r : q = idp) : ap_is_constant p q = ap02 f r ⬝ (con.right_inv (p a))⁻¹ := by cases r; exact !idp_con⁻¹ definition con_right_inv_natural {A : Type} {a a' : A} {p p' : a = a'} (q : p = p') : con.right_inv p = q β—Ύ q⁻² ⬝ con.right_inv p' := by induction q; induction p; reflexivity definition whisker_right_ap {A B : Type} {a a' : A}{b₁ bβ‚‚ b₃ : B} (q : bβ‚‚ = b₃) (f : A β†’ b₁ = bβ‚‚) (p : a = a') : whisker_right q (ap f p) = ap (Ξ»a, f a ⬝ q) p := by induction p; reflexivity definition ap02_ap_constant {A B C : Type} {a a' : A} (f : B β†’ C) (b : B) (p : a = a') : square (ap_constant p (f b)) (ap02 f (ap_constant p b)) (ap_compose f (Ξ»x, b) p) idp := by induction p; exact ids definition ap_constant_compose {A B C : Type} {a a' : A} (c : C) (f : A β†’ B) (p : a = a') : square (ap_constant p c) (ap_constant (ap f p) c) (ap_compose (Ξ»x, c) f p) idp := by induction p; exact ids definition ap02_constant {A B : Type} {a a' : A} (b : B) {p p' : a = a'} (q : p = p') : square (ap_constant p b) (ap_constant p' b) (ap02 (Ξ»x, b) q) idp := by induction q; exact vrfl section hsquare variables {Aβ‚€β‚€ Aβ‚‚β‚€ Aβ‚„β‚€ Aβ‚€β‚‚ Aβ‚‚β‚‚ Aβ‚„β‚‚ Aβ‚€β‚„ Aβ‚‚β‚„ Aβ‚„β‚„ : Type} {f₁₀ : Aβ‚€β‚€ β†’ Aβ‚‚β‚€} {f₃₀ : Aβ‚‚β‚€ β†’ Aβ‚„β‚€} {f₀₁ : Aβ‚€β‚€ β†’ Aβ‚€β‚‚} {f₂₁ : Aβ‚‚β‚€ β†’ Aβ‚‚β‚‚} {f₄₁ : Aβ‚„β‚€ β†’ Aβ‚„β‚‚} {f₁₂ : Aβ‚€β‚‚ β†’ Aβ‚‚β‚‚} {f₃₂ : Aβ‚‚β‚‚ β†’ Aβ‚„β‚‚} {f₀₃ : Aβ‚€β‚‚ β†’ Aβ‚€β‚„} {f₂₃ : Aβ‚‚β‚‚ β†’ Aβ‚‚β‚„} {f₄₃ : Aβ‚„β‚‚ β†’ Aβ‚„β‚„} {f₁₄ : Aβ‚€β‚„ β†’ Aβ‚‚β‚„} {f₃₄ : Aβ‚‚β‚„ β†’ Aβ‚„β‚„} definition hsquare [reducible] (f₁₀ : Aβ‚€β‚€ β†’ Aβ‚‚β‚€) (f₁₂ : Aβ‚€β‚‚ β†’ Aβ‚‚β‚‚) (f₀₁ : Aβ‚€β‚€ β†’ Aβ‚€β‚‚) (f₂₁ : Aβ‚‚β‚€ β†’ Aβ‚‚β‚‚) : Type := f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁ definition hsquare_of_homotopy (p : f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁) : hsquare f₁₀ f₁₂ f₀₁ f₂₁ := p definition homotopy_of_hsquare (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁ := p definition homotopy_top_of_hsquare {f₂₁ : Aβ‚‚β‚€ ≃ Aβ‚‚β‚‚} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : f₁₀ ~ f₂₁⁻¹ ∘ f₁₂ ∘ f₀₁ := homotopy_inv_of_homotopy_post _ _ _ p definition homotopy_top_of_hsquare' [is_equiv f₂₁] (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : f₁₀ ~ f₂₁⁻¹ ∘ f₁₂ ∘ f₀₁ := homotopy_inv_of_homotopy_post _ _ _ p definition hhconcat (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) : hsquare (f₃₀ ∘ f₁₀) (f₃₂ ∘ f₁₂) f₀₁ f₄₁ := hwhisker_right f₁₀ q ⬝hty hwhisker_left f₃₂ p definition hvconcat (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (q : hsquare f₁₂ f₁₄ f₀₃ f₂₃) : hsquare f₁₀ f₁₄ (f₀₃ ∘ f₀₁) (f₂₃ ∘ f₂₁) := (hhconcat p⁻¹ʰᡗʸ q⁻¹ʰᡗʸ)⁻¹ʰᡗʸ definition hhinverse {f₁₀ : Aβ‚€β‚€ ≃ Aβ‚‚β‚€} {f₁₂ : Aβ‚€β‚‚ ≃ Aβ‚‚β‚‚} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : hsquare f₁₀⁻¹ᡉ f₁₂⁻¹ᡉ f₂₁ f₀₁ := Ξ»b, eq_inv_of_eq ((p (f₁₀⁻¹ᡉ b))⁻¹ ⬝ ap f₂₁ (to_right_inv f₁₀ b)) definition hvinverse {f₀₁ : Aβ‚€β‚€ ≃ Aβ‚€β‚‚} {f₂₁ : Aβ‚‚β‚€ ≃ Aβ‚‚β‚‚} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : hsquare f₁₂ f₁₀ f₀₁⁻¹ᡉ f₂₁⁻¹ᡉ := (hhinverse p⁻¹ʰᡗʸ)⁻¹ʰᡗʸ infix ` ⬝htyh `:73 := hhconcat infix ` ⬝htyv `:73 := hvconcat postfix `⁻¹ʰᡗʸʰ`:(max+1) := hhinverse postfix `⁻¹ʰᡗʸᡛ`:(max+1) := hvinverse end hsquare end eq
3c5a877743a76df46761646facb055c9abec6bfb
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/ring_theory/mv_polynomial/basic.lean
6d68cb3780924af8f52ef1891955d2d96fb29eed
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,369
lean
/- Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import algebra.char_p.basic import data.polynomial.algebra_map import data.mv_polynomial.variables import linear_algebra.finsupp_vector_space /-! # Multivariate polynomials over commutative rings > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains basic facts about multivariate polynomials over commutative rings, for example that the monomials form a basis. ## Main definitions * `restrict_total_degree Οƒ R m`: the subspace of multivariate polynomials indexed by `Οƒ` over the commutative ring `R` of total degree at most `m`. * `restrict_degree Οƒ R m`: the subspace of multivariate polynomials indexed by `Οƒ` over the commutative ring `R` such that the degree in each individual variable is at most `m`. ## Main statements * The multivariate polynomial ring over a commutative ring of positive characteristic has positive characteristic. * `basis_monomials`: shows that the monomials form a basis of the vector space of multivariate polynomials. ## TODO Generalise to noncommutative (semi)rings -/ noncomputable theory open set linear_map submodule open_locale big_operators polynomial universes u v variables (Οƒ : Type u) (R : Type v) [comm_ring R] (p m : β„•) namespace mv_polynomial section char_p instance [char_p R p] : char_p (mv_polynomial Οƒ R) p := { cast_eq_zero_iff := Ξ» n, by rw [← C_eq_coe_nat, ← C_0, C_inj, char_p.cast_eq_zero_iff R p] } end char_p section homomorphism lemma map_range_eq_map {R S : Type*} [comm_ring R] [comm_ring S] (p : mv_polynomial Οƒ R) (f : R β†’+* S) : finsupp.map_range f f.map_zero p = map f p := begin -- `finsupp.map_range_finset_sum` expects `f : R β†’+ S` change finsupp.map_range (f : R β†’+ S) (f : R β†’+ S).map_zero p = map f p, rw [p.as_sum, finsupp.map_range_finset_sum, (map f).map_sum], refine finset.sum_congr rfl (assume n _, _), rw [map_monomial, ← single_eq_monomial, finsupp.map_range_single, single_eq_monomial, f.coe_add_monoid_hom], end end homomorphism section degree /-- The submodule of polynomials of total degree less than or equal to `m`.-/ def restrict_total_degree : submodule R (mv_polynomial Οƒ R) := finsupp.supported _ _ {n | n.sum (Ξ»n e, e) ≀ m } /-- The submodule of polynomials such that the degree with respect to each individual variable is less than or equal to `m`.-/ def restrict_degree (m : β„•) : submodule R (mv_polynomial Οƒ R) := finsupp.supported _ _ {n | βˆ€i, n i ≀ m } variable {R} lemma mem_restrict_total_degree (p : mv_polynomial Οƒ R) : p ∈ restrict_total_degree Οƒ R m ↔ p.total_degree ≀ m := begin rw [total_degree, finset.sup_le_iff], refl end lemma mem_restrict_degree (p : mv_polynomial Οƒ R) (n : β„•) : p ∈ restrict_degree Οƒ R n ↔ (βˆ€s ∈ p.support, βˆ€i, (s : Οƒ β†’β‚€ β„•) i ≀ n) := begin rw [restrict_degree, finsupp.mem_supported], refl end lemma mem_restrict_degree_iff_sup [decidable_eq Οƒ] (p : mv_polynomial Οƒ R) (n : β„•) : p ∈ restrict_degree Οƒ R n ↔ βˆ€i, p.degrees.count i ≀ n := begin simp only [mem_restrict_degree, degrees_def, multiset.count_finset_sup, finsupp.count_to_multiset, finset.sup_le_iff], exact ⟨assume h n s hs, h s hs n, assume h s hs n, h n s hs⟩ end variables (Οƒ R) /-- The monomials form a basis on `mv_polynomial Οƒ R`. -/ def basis_monomials : basis (Οƒ β†’β‚€ β„•) R (mv_polynomial Οƒ R) := finsupp.basis_single_one @[simp] lemma coe_basis_monomials : (basis_monomials Οƒ R : (Οƒ β†’β‚€ β„•) β†’ mv_polynomial Οƒ R) = Ξ» s, monomial s 1 := rfl lemma linear_independent_X : linear_independent R (X : Οƒ β†’ mv_polynomial Οƒ R) := (basis_monomials Οƒ R).linear_independent.comp (Ξ» s : Οƒ, finsupp.single s 1) (finsupp.single_left_injective one_ne_zero) end degree end mv_polynomial /- this is here to avoid import cycle issues -/ namespace polynomial /-- The monomials form a basis on `R[X]`. -/ noncomputable def basis_monomials : basis β„• R R[X] := basis.of_repr (to_finsupp_iso_alg R).to_linear_equiv @[simp] lemma coe_basis_monomials : (basis_monomials R : β„• β†’ R[X]) = Ξ» s, monomial s 1 := _root_.funext $ Ξ» n, of_finsupp_single _ _ end polynomial
7f0eeabe022a7e2c49def40d996abccb0036dd98
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/test/ext.lean
f7cd745d20848a299721c1412ed0e357dbc600af
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,734
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import tactic.ext import tactic.solve_by_elim import data.stream.basic import data.finset.basic import tactic.rcases section ext_trace_test setup_tactic_parser namespace tactic namespace interactive meta def ext_trace_test (patts : parse rcases_patt_parse_hi*) (fuel : parse (tk ":" *> small_nat)?) (tgt_trace : string) : tactic unit := do ⟨_, ΟƒβŸ© ← state_t.run (ext_core {}) ⟨patts, [], fuel⟩, guard $ ", ".intercalate Οƒ.trace_msg = tgt_trace end interactive end tactic end ext_trace_test example (Ξ± Ξ² Ξ³ : Type) (f g : Ξ± Γ— Ξ² β†’ Ξ³) (H : βˆ€ a : Ξ±, βˆ€ b : Ξ², f (a,b) = g (a,b)) : f = g := begin ext_trace_test ⟨a,b⟩ "apply funext, rintro ⟨a, b⟩", apply H end example : subsingleton unit := begin split, intros, ext end example (x y : β„•) : true := begin have : x = y, { ext <|> admit }, have : x = y, { ext i <|> admit }, have : x = y, { ext : 1 <|> admit }, trivial end example (X Y : β„• Γ— β„•) (h : X.1 = Y.1) (h : X.2 = Y.2) : X = Y := begin ext; assumption end example (X Y : (β„• β†’ β„•) Γ— β„•) (h : βˆ€ i, X.1 i = Y.1 i) (h : X.2 = Y.2) : X = Y := begin ext x; solve_by_elim, end example (X Y : β„• β†’ β„• Γ— β„•) (h : βˆ€ i, X i = Y i) : true := begin have : X = Y, { ext i : 1, guard_target X i = Y i, admit }, have : X = Y, { ext i, guard_target (X i).fst = (Y i).fst, admit, guard_target (X i).snd = (Y i).snd, admit, }, have : X = Y, { ext : 1, guard_target X x = Y x, admit }, trivial, end example (sβ‚€ s₁ : set β„•) (h : s₁ = sβ‚€) : sβ‚€ = s₁ := by { ext1, guard_target x ∈ sβ‚€ ↔ x ∈ s₁, simp * } example (sβ‚€ s₁ : stream β„•) (h : s₁ = sβ‚€) : sβ‚€ = s₁ := by { ext1, guard_target sβ‚€.nth n = s₁.nth n, simp * } example (sβ‚€ s₁ : β„€ β†’ set (β„• Γ— β„•)) (h : βˆ€ i a b, (a,b) ∈ sβ‚€ i ↔ (a,b) ∈ s₁ i) : sβ‚€ = s₁ := begin ext i ⟨a,b⟩, apply h end example (sβ‚€ s₁ : β„€ β†’ set (β„• Γ— β„•)) (h : βˆ€ i a b, (a,b) ∈ sβ‚€ i ↔ (a,b) ∈ s₁ i) : sβ‚€ = s₁ := begin ext_trace_test i ⟨a,b⟩ "apply funext, rintro i, apply set.ext, rintro ⟨a, b⟩", apply h end /- extensionality -/ example : true := begin have : βˆ€ (sβ‚€ s₁ : set β„€), sβ‚€ = s₁, { intros, ext1, guard_target x ∈ sβ‚€ ↔ x ∈ s₁, admit }, have : βˆ€ (sβ‚€ s₁ : finset β„•), sβ‚€ = s₁, { intros, ext1, guard_target a ∈ sβ‚€ ↔ a ∈ s₁, admit }, have : βˆ€ (sβ‚€ s₁ : multiset β„•), sβ‚€ = s₁, { intros, ext1, guard_target multiset.count a sβ‚€ = multiset.count a s₁, admit }, have : βˆ€ (sβ‚€ s₁ : list β„•), sβ‚€ = s₁, { intros, ext1, guard_target list.nth sβ‚€ n = list.nth s₁ n, admit }, have : βˆ€ (sβ‚€ s₁ : stream β„•), sβ‚€ = s₁, { intros, ext1, guard_target stream.nth n sβ‚€ = stream.nth n s₁, admit }, have : βˆ€ n (sβ‚€ s₁ : array n β„•), sβ‚€ = s₁, { intros, ext1, guard_target array.read sβ‚€ i = array.read s₁ i, admit }, trivial end structure dependent_fields := (a : bool) (v : if a then β„• else β„€) @[ext] lemma df.ext (s t : dependent_fields) (h : s.a = t.a) (w : (@eq.rec _ s.a (Ξ» b, if b then β„• else β„€) s.v t.a h) = t.v) : s = t := begin cases s, cases t, dsimp at *, congr, exact h, subst h, simp, simp at w, exact w, end example (s : dependent_fields) : s = s := begin tactic.ext1 [] {tactic.apply_cfg . new_goals := tactic.new_goals.all}, guard_target s.a = s.a, refl, refl, end @[ext] structure dumb (V : Type) := (val : V)
9aec1436a8c638097a624ac78958a061fd06a216
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/topology/sheaves/sheaf_condition/unique_gluing.lean
7e9b68806d3b16848a9ae83697e402c7893edf2d
[ "Apache-2.0" ]
permissive
ramonfmir/mathlib
c5dc8b33155473fab97c38bd3aa6723dc289beaa
14c52e990c17f5a00c0cc9e09847af16fabbed25
refs/heads/master
1,661,979,343,526
1,660,830,384,000
1,660,830,384,000
182,072,989
0
0
null
1,555,585,876,000
1,555,585,876,000
null
UTF-8
Lean
false
false
10,874
lean
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import topology.sheaves.forget import category_theory.limits.shapes.types import topology.sheaves.sheaf import category_theory.types /-! # The sheaf condition in terms of unique gluings We provide an alternative formulation of the sheaf condition in terms of unique gluings. We work with sheaves valued in a concrete category `C` admitting all limits, whose forgetful functor `C β₯€ Type` preserves limits and reflects isomorphisms. The usual categories of algebraic structures, such as `Mon`, `AddCommGroup`, `Ring`, `CommRing` etc. are all examples of this kind of category. A presheaf `F : presheaf C X` satisfies the sheaf condition if and only if, for every compatible family of sections `sf : Ξ  i : ΞΉ, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. Here, the family `sf` is called compatible, if for all `i j : ΞΉ`, the restrictions of `sf i` and `sf j` to `U i βŠ“ U j` agree. A section `s : F.obj (op (supr U))` is a gluing for the family `sf`, if `s` restricts to `sf i` on `U i` for all `i : ΞΉ` We show that the sheaf condition in terms of unique gluings is equivalent to the definition in terms of equalizers. Our approach is as follows: First, we show them to be equivalent for `Type`-valued presheaves. Then we use that composing a presheaf with a limit-preserving and isomorphism-reflecting functor leaves the sheaf condition invariant, as shown in `topology/sheaves/forget.lean`. -/ noncomputable theory open Top open Top.presheaf open Top.presheaf.sheaf_condition_equalizer_products open category_theory open category_theory.limits open topological_space open topological_space.opens open opposite universes u v variables {C : Type u} [category.{v} C] [concrete_category.{v} C] namespace Top namespace presheaf section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables {X : Top.{v}} (F : presheaf C X) {ΞΉ : Type v} (U : ΞΉ β†’ opens X) /-- A family of sections `sf` is compatible, if the restrictions of `sf i` and `sf j` to `U i βŠ“ U j` agree, for all `i` and `j` -/ def is_compatible (sf : Ξ  i : ΞΉ, F.obj (op (U i))) : Prop := βˆ€ i j : ΞΉ, F.map (inf_le_left (U i) (U j)).op (sf i) = F.map (inf_le_right (U i) (U j)).op (sf j) /-- A section `s` is a gluing for a family of sections `sf` if it restricts to `sf i` on `U i`, for all `i` -/ def is_gluing (sf : Ξ  i : ΞΉ, F.obj (op (U i))) (s : F.obj (op (supr U))) : Prop := βˆ€ i : ΞΉ, F.map (opens.le_supr U i).op s = sf i /-- The sheaf condition in terms of unique gluings. A presheaf `F : presheaf C X` satisfies this sheaf condition if and only if, for every compatible family of sections `sf : Ξ  i : ΞΉ, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. We prove this to be equivalent to the usual one below in `is_sheaf_iff_is_sheaf_unique_gluing` -/ def is_sheaf_unique_gluing : Prop := βˆ€ ⦃ι : Type v⦄ (U : ΞΉ β†’ opens X) (sf : Ξ  i : ΞΉ, F.obj (op (U i))), is_compatible F U sf β†’ βˆƒ! s : F.obj (op (supr U)), is_gluing F U sf s end section type_valued variables {X : Top.{v}} (F : presheaf (Type v) X) {ΞΉ : Type v} (U : ΞΉ β†’ opens X) /-- For presheaves of types, terms of `pi_opens F U` are just families of sections. -/ def pi_opens_iso_sections_family : pi_opens F U β‰… Ξ  i : ΞΉ, F.obj (op (U i)) := limits.is_limit.cone_point_unique_up_to_iso (limit.is_limit (discrete.functor (Ξ» i : ΞΉ, F.obj (op (U i))))) ((types.product_limit_cone (Ξ» i : ΞΉ, F.obj (op (U i)))).is_limit) /-- Under the isomorphism `pi_opens_iso_sections_family`, compatibility of sections is the same as being equalized by the arrows `left_res` and `right_res` of the equalizer diagram. -/ lemma compatible_iff_left_res_eq_right_res (sf : pi_opens F U) : is_compatible F U ((pi_opens_iso_sections_family F U).hom sf) ↔ left_res F U sf = right_res F U sf := begin split ; intros h, { ext ⟨i, j⟩, rw [left_res, types.limit.lift_Ο€_apply', fan.mk_Ο€_app, right_res, types.limit.lift_Ο€_apply', fan.mk_Ο€_app], exact h i j, }, { intros i j, convert congr_arg (limits.pi.Ο€ (Ξ» p : ΞΉ Γ— ΞΉ, F.obj (op (U p.1 βŠ“ U p.2))) (i,j)) h, { rw [left_res, types.pi_lift_Ο€_apply], refl }, { rw [right_res, types.pi_lift_Ο€_apply], refl } } end /-- Under the isomorphism `pi_opens_iso_sections_family`, being a gluing of a family of sections `sf` is the same as lying in the preimage of `res` (the leftmost arrow of the equalizer diagram). -/ @[simp] lemma is_gluing_iff_eq_res (sf : pi_opens F U) (s : F.obj (op (supr U))): is_gluing F U ((pi_opens_iso_sections_family F U).hom sf) s ↔ res F U s = sf := begin split ; intros h, { ext ⟨i⟩, rw [res, types.limit.lift_Ο€_apply', fan.mk_Ο€_app], exact h i, }, { intro i, convert congr_arg (limits.pi.Ο€ (Ξ» i : ΞΉ, F.obj (op (U i))) i) h, rw [res, types.pi_lift_Ο€_apply], refl }, end /-- The "equalizer" sheaf condition can be obtained from the sheaf condition in terms of unique gluings. -/ lemma is_sheaf_of_is_sheaf_unique_gluing_types (Fsh : F.is_sheaf_unique_gluing) : F.is_sheaf := begin rw is_sheaf_iff_is_sheaf_equalizer_products, intros ΞΉ U, refine ⟨fork.is_limit.mk' _ _⟩, intro s, have h_compatible : βˆ€ x : s.X, F.is_compatible U ((F.pi_opens_iso_sections_family U).hom (s.ΞΉ x)), { intro x, rw compatible_iff_left_res_eq_right_res, convert congr_fun s.condition x, }, choose m m_spec m_uniq using Ξ» x : s.X, Fsh U ((pi_opens_iso_sections_family F U).hom (s.ΞΉ x)) (h_compatible x), refine ⟨m, _, _⟩, { ext ⟨i⟩ x, simp [res], exact m_spec x i, }, { intros l hl, ext x, apply m_uniq, rw is_gluing_iff_eq_res, exact congr_fun hl x }, end /-- The sheaf condition in terms of unique gluings can be obtained from the usual "equalizer" sheaf condition. -/ lemma is_sheaf_unique_gluing_of_is_sheaf_types (Fsh : F.is_sheaf) : F.is_sheaf_unique_gluing := begin rw is_sheaf_iff_is_sheaf_equalizer_products at Fsh, intros ΞΉ U sf hsf, let sf' := (pi_opens_iso_sections_family F U).inv sf, have hsf' : left_res F U sf' = right_res F U sf', { rwa [← compatible_iff_left_res_eq_right_res F U sf', inv_hom_id_apply] }, choose s s_spec s_uniq using types.unique_of_type_equalizer _ _ (Fsh U).some sf' hsf', use s, dsimp, split, { convert (is_gluing_iff_eq_res F U sf' _).mpr s_spec, rw inv_hom_id_apply }, { intros y hy, apply s_uniq, rw ← is_gluing_iff_eq_res F U, convert hy, rw inv_hom_id_apply, }, end /-- For type-valued presheaves, the sheaf condition in terms of unique gluings is equivalent to the usual sheaf condition in terms of equalizer diagrams. -/ lemma is_sheaf_iff_is_sheaf_unique_gluing_types : F.is_sheaf ↔ F.is_sheaf_unique_gluing := iff.intro (is_sheaf_unique_gluing_of_is_sheaf_types F) (is_sheaf_of_is_sheaf_unique_gluing_types F) end type_valued section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables [has_limits C] [reflects_isomorphisms (forget C)] [preserves_limits (forget C)] variables {X : Top.{v}} (F : presheaf C X) {ΞΉ : Type v} (U : ΞΉ β†’ opens X) /-- For presheaves valued in a concrete category, whose forgetful functor reflects isomorphisms and preserves limits, the sheaf condition in terms of unique gluings is equivalent to the usual one in terms of equalizer diagrams. -/ lemma is_sheaf_iff_is_sheaf_unique_gluing : F.is_sheaf ↔ F.is_sheaf_unique_gluing := iff.trans (is_sheaf_iff_is_sheaf_comp (forget C) F) (is_sheaf_iff_is_sheaf_unique_gluing_types (F β‹™ forget C)) end end presheaf namespace sheaf open presheaf open category_theory section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables [has_limits C] [reflects_isomorphisms (concrete_category.forget C)] variables [preserves_limits (concrete_category.forget C)] variables {X : Top.{v}} (F : sheaf C X) {ΞΉ : Type v} (U : ΞΉ β†’ opens X) /-- A more convenient way of obtaining a unique gluing of sections for a sheaf. -/ lemma exists_unique_gluing (sf : Ξ  i : ΞΉ, F.1.obj (op (U i))) (h : is_compatible F.1 U sf ) : βˆƒ! s : F.1.obj (op (supr U)), is_gluing F.1 U sf s := (is_sheaf_iff_is_sheaf_unique_gluing F.1).mp F.cond U sf h /-- In this version of the lemma, the inclusion homs `iUV` can be specified directly by the user, which can be more convenient in practice. -/ lemma exists_unique_gluing' (V : opens X) (iUV : Ξ  i : ΞΉ, U i ⟢ V) (hcover : V ≀ supr U) (sf : Ξ  i : ΞΉ, F.1.obj (op (U i))) (h : is_compatible F.1 U sf) : βˆƒ! s : F.1.obj (op V), βˆ€ i : ΞΉ, F.1.map (iUV i).op s = sf i := begin have V_eq_supr_U : V = supr U := le_antisymm hcover (supr_le (Ξ» i, (iUV i).le)), obtain ⟨gl, gl_spec, gl_uniq⟩ := F.exists_unique_gluing U sf h, refine ⟨F.1.map (eq_to_hom V_eq_supr_U).op gl, _, _⟩, { intro i, rw [← comp_apply, ← F.1.map_comp], exact gl_spec i }, { intros gl' gl'_spec, convert congr_arg _ (gl_uniq (F.1.map (eq_to_hom V_eq_supr_U.symm).op gl') (Ξ» i,_)) ; rw [← comp_apply, ← F.1.map_comp], { rw [eq_to_hom_op, eq_to_hom_op, eq_to_hom_trans, eq_to_hom_refl, F.1.map_id, id_apply] }, { convert gl'_spec i } } end @[ext] lemma eq_of_locally_eq (s t : F.1.obj (op (supr U))) (h : βˆ€ i, F.1.map (opens.le_supr U i).op s = F.1.map (opens.le_supr U i).op t) : s = t := begin let sf : Ξ  i : ΞΉ, F.1.obj (op (U i)) := Ξ» i, F.1.map (opens.le_supr U i).op s, have sf_compatible : is_compatible _ U sf, { intros i j, simp_rw [← comp_apply, ← F.1.map_comp], refl }, obtain ⟨gl, -, gl_uniq⟩ := F.exists_unique_gluing U sf sf_compatible, transitivity gl, { apply gl_uniq, intro i, refl }, { symmetry, apply gl_uniq, intro i, rw ← h }, end /-- In this version of the lemma, the inclusion homs `iUV` can be specified directly by the user, which can be more convenient in practice. -/ lemma eq_of_locally_eq' (V : opens X) (iUV : Ξ  i : ΞΉ, U i ⟢ V) (hcover : V ≀ supr U) (s t : F.1.obj (op V)) (h : βˆ€ i, F.1.map (iUV i).op s = F.1.map (iUV i).op t) : s = t := begin have V_eq_supr_U : V = supr U := le_antisymm hcover (supr_le (Ξ» i, (iUV i).le)), suffices : F.1.map (eq_to_hom V_eq_supr_U.symm).op s = F.1.map (eq_to_hom V_eq_supr_U.symm).op t, { convert congr_arg (F.1.map (eq_to_hom V_eq_supr_U).op) this ; rw [← comp_apply, ← F.1.map_comp, eq_to_hom_op, eq_to_hom_op, eq_to_hom_trans, eq_to_hom_refl, F.1.map_id, id_apply] }, apply eq_of_locally_eq, intro i, rw [← comp_apply, ← comp_apply, ← F.1.map_comp], convert h i, end end end sheaf end Top
bfb34bb064f61518fd8c259f9437c7dc12aa02c2
5749d8999a76f3a8fddceca1f6941981e33aaa96
/src/tactic/basic.lean
be3f0d223c2847e368aecd372aa0eca81c0b0c2b
[ "Apache-2.0" ]
permissive
jdsalchow/mathlib
13ab43ef0d0515a17e550b16d09bd14b76125276
497e692b946d93906900bb33a51fd243e7649406
refs/heads/master
1,585,819,143,348
1,580,072,892,000
1,580,072,892,000
154,287,128
0
0
Apache-2.0
1,540,281,610,000
1,540,281,609,000
null
UTF-8
Lean
false
false
459
lean
import tactic.alias tactic.cache tactic.clear tactic.converter.interactive tactic.core tactic.ext tactic.generalize_proofs tactic.interactive tactic.suggest tactic.lift tactic.localized tactic.mk_iff_of_inductive_prop tactic.push_neg tactic.rcases tactic.replacer tactic.restate_axiom tactic.rewrite tactic.lint tactic.simpa tactic.simps tactic.split_ifs tactic.squeeze tactic.well_founded_tactics tactic.where
9cfbce061af05dca2d485cb34059d83574b6235d
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
/library/data/nat/default.lean
0ef7dd7224d011889e668f11b4728c8ef861c33c
[ "Apache-2.0" ]
permissive
respu/lean
6582d19a2f2838a28ecd2b3c6f81c32d07b5341d
8c76419c60b63d0d9f7bc04ebb0b99812d0ec654
refs/heads/master
1,610,882,451,231
1,427,747,084,000
1,427,747,429,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
198
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad -/ import .basic .order .sub .div .bquant
d5ded902fc735e4ec410d7d3eba003fae502b3dc
94e33a31faa76775069b071adea97e86e218a8ee
/src/algebra/homology/additive.lean
19b104a07db11d5b3ed1db5c23fd5538e32bc4fc
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
11,240
lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.homology.homology import algebra.homology.single import category_theory.preadditive.additive_functor /-! # Homology is an additive functor When `V` is preadditive, `homological_complex V c` is also preadditive, and `homology_functor` is additive. TODO: similarly for `R`-linear. -/ universes v u open_locale classical noncomputable theory open category_theory category_theory.category category_theory.limits homological_complex variables {ΞΉ : Type*} variables {V : Type u} [category.{v} V] [preadditive V] variables {c : complex_shape ΞΉ} {C D E : homological_complex V c} variables (f g : C ⟢ D) (h k : D ⟢ E) (i : ΞΉ) namespace homological_complex instance : has_zero (C ⟢ D) := ⟨{ f := Ξ» i, 0 }⟩ instance : has_add (C ⟢ D) := ⟨λ f g, { f := Ξ» i, f.f i + g.f i, }⟩ instance : has_neg (C ⟢ D) := ⟨λ f, { f := Ξ» i, -(f.f i) }⟩ instance : has_sub (C ⟢ D) := ⟨λ f g, { f := Ξ» i, f.f i - g.f i, }⟩ instance has_nat_scalar : has_smul β„• (C ⟢ D) := ⟨λ n f, { f := Ξ» i, n β€’ f.f i, comm' := Ξ» i j h, by simp [preadditive.nsmul_comp, preadditive.comp_nsmul] }⟩ instance has_int_scalar : has_smul β„€ (C ⟢ D) := ⟨λ n f, { f := Ξ» i, n β€’ f.f i, comm' := Ξ» i j h, by simp [preadditive.zsmul_comp, preadditive.comp_zsmul] }⟩ @[simp] lemma zero_f_apply (i : ΞΉ) : (0 : C ⟢ D).f i = 0 := rfl @[simp] lemma add_f_apply (f g : C ⟢ D) (i : ΞΉ) : (f + g).f i = f.f i + g.f i := rfl @[simp] lemma neg_f_apply (f : C ⟢ D) (i : ΞΉ) : (-f).f i = -(f.f i) := rfl @[simp] lemma sub_f_apply (f g : C ⟢ D) (i : ΞΉ) : (f - g).f i = f.f i - g.f i := rfl @[simp] lemma nsmul_f_apply (n : β„•) (f : C ⟢ D) (i : ΞΉ) : (n β€’ f).f i = n β€’ f.f i := rfl @[simp] lemma zsmul_f_apply (n : β„€) (f : C ⟢ D) (i : ΞΉ) : (n β€’ f).f i = n β€’ f.f i := rfl instance : add_comm_group (C ⟢ D) := function.injective.add_comm_group hom.f homological_complex.hom_f_injective (by tidy) (by tidy) (by tidy) (by tidy) (by tidy) (by tidy) instance : preadditive (homological_complex V c) := {} /-- The `i`-th component of a chain map, as an additive map from chain maps to morphisms. -/ @[simps] def hom.f_add_monoid_hom {C₁ Cβ‚‚ : homological_complex V c} (i : ΞΉ) : (C₁ ⟢ Cβ‚‚) β†’+ (C₁.X i ⟢ Cβ‚‚.X i) := add_monoid_hom.mk' (Ξ» f, hom.f f i) (Ξ» _ _, rfl) end homological_complex namespace homological_complex instance eval_additive (i : ΞΉ) : (eval V c i).additive := {} variables [has_zero_object V] instance cycles_additive [has_equalizers V] : (cycles_functor V c i).additive := {} variables [has_images V] [has_image_maps V] instance boundaries_additive : (boundaries_functor V c i).additive := {} variables [has_equalizers V] [has_cokernels V] instance homology_additive : (homology_functor V c i).additive := { map_add' := Ξ» C D f g, begin dsimp [homology_functor], ext, simp only [homology.Ο€_map, preadditive.comp_add, ←preadditive.add_comp], congr, ext, simp, end } end homological_complex namespace category_theory variables {W : Type*} [category W] [preadditive W] /-- An additive functor induces a functor between homological complexes. This is sometimes called the "prolongation". -/ @[simps] def functor.map_homological_complex (F : V β₯€ W) [F.additive] (c : complex_shape ΞΉ) : homological_complex V c β₯€ homological_complex W c := { obj := Ξ» C, { X := Ξ» i, F.obj (C.X i), d := Ξ» i j, F.map (C.d i j), shape' := Ξ» i j w, by rw [C.shape _ _ w, F.map_zero], d_comp_d' := Ξ» i j k _ _, by rw [←F.map_comp, C.d_comp_d, F.map_zero], }, map := Ξ» C D f, { f := Ξ» i, F.map (f.f i), comm' := Ξ» i j h, by { dsimp, rw [←F.map_comp, ←F.map_comp, f.comm], }, }, }. instance functor.map_homogical_complex_additive (F : V β₯€ W) [F.additive] (c : complex_shape ΞΉ) : (F.map_homological_complex c).additive := {} /-- A natural transformation between functors induces a natural transformation between those functors applied to homological complexes. -/ @[simps] def nat_trans.map_homological_complex {F G : V β₯€ W} [F.additive] [G.additive] (Ξ± : F ⟢ G) (c : complex_shape ΞΉ) : F.map_homological_complex c ⟢ G.map_homological_complex c := { app := Ξ» C, { f := Ξ» i, Ξ±.app _, }, } @[simp] lemma nat_trans.map_homological_complex_id (c : complex_shape ΞΉ) (F : V β₯€ W) [F.additive] : nat_trans.map_homological_complex (πŸ™ F) c = πŸ™ (F.map_homological_complex c) := by tidy @[simp] lemma nat_trans.map_homological_complex_comp (c : complex_shape ΞΉ) {F G H : V β₯€ W} [F.additive] [G.additive] [H.additive] (Ξ± : F ⟢ G) (Ξ² : G ⟢ H): nat_trans.map_homological_complex (Ξ± ≫ Ξ²) c = nat_trans.map_homological_complex Ξ± c ≫ nat_trans.map_homological_complex Ξ² c := by tidy @[simp, reassoc] lemma nat_trans.map_homological_complex_naturality {c : complex_shape ΞΉ} {F G : V β₯€ W} [F.additive] [G.additive] (Ξ± : F ⟢ G) {C D : homological_complex V c} (f : C ⟢ D) : (F.map_homological_complex c).map f ≫ (nat_trans.map_homological_complex Ξ± c).app D = (nat_trans.map_homological_complex Ξ± c).app C ≫ (G.map_homological_complex c).map f := by tidy end category_theory namespace chain_complex variables {W : Type*} [category W] [preadditive W] variables {Ξ± : Type*} [add_right_cancel_semigroup Ξ±] [has_one Ξ±] [decidable_eq Ξ±] lemma map_chain_complex_of (F : V β₯€ W) [F.additive] (X : Ξ± β†’ V) (d : Ξ  n, X (n+1) ⟢ X n) (sq : βˆ€ n, d (n+1) ≫ d n = 0) : (F.map_homological_complex _).obj (chain_complex.of X d sq) = chain_complex.of (Ξ» n, F.obj (X n)) (Ξ» n, F.map (d n)) (Ξ» n, by rw [ ← F.map_comp, sq n, functor.map_zero]) := begin refine homological_complex.ext rfl _, rintro i j (rfl : j + 1 = i), simp only [category_theory.functor.map_homological_complex_obj_d, of_d, eq_to_hom_refl, comp_id, id_comp], end end chain_complex variables [has_zero_object V] {W : Type*} [category W] [preadditive W] [has_zero_object W] namespace homological_complex local attribute [simp] eq_to_hom_map /-- Turning an object into a complex supported at `j` then applying a functor is the same as applying the functor then forming the complex. -/ def single_map_homological_complex (F : V β₯€ W) [F.additive] (c : complex_shape ΞΉ) (j : ΞΉ): single V c j β‹™ F.map_homological_complex _ β‰… F β‹™ single W c j := nat_iso.of_components (Ξ» X, { hom := { f := Ξ» i, if h : i = j then eq_to_hom (by simp [h]) else 0, }, inv := { f := Ξ» i, if h : i = j then eq_to_hom (by simp [h]) else 0, }, hom_inv_id' := begin ext i, dsimp, split_ifs with h, { simp [h] }, { rw [zero_comp, if_neg h], exact (zero_of_source_iso_zero _ F.map_zero_object).symm, }, end, inv_hom_id' := begin ext i, dsimp, split_ifs with h, { simp [h] }, { rw [zero_comp, if_neg h], simp, }, end, }) (Ξ» X Y f, begin ext i, dsimp, split_ifs with h; simp [h], end). variables (F : V β₯€ W) [functor.additive F] (c) @[simp] lemma single_map_homological_complex_hom_app_self (j : ΞΉ) (X : V) : ((single_map_homological_complex F c j).hom.app X).f j = eq_to_hom (by simp) := by simp [single_map_homological_complex] @[simp] lemma single_map_homological_complex_hom_app_ne {i j : ΞΉ} (h : i β‰  j) (X : V) : ((single_map_homological_complex F c j).hom.app X).f i = 0 := by simp [single_map_homological_complex, h] @[simp] lemma single_map_homological_complex_inv_app_self (j : ΞΉ) (X : V) : ((single_map_homological_complex F c j).inv.app X).f j = eq_to_hom (by simp) := by simp [single_map_homological_complex] @[simp] lemma single_map_homological_complex_inv_app_ne {i j : ΞΉ} (h : i β‰  j) (X : V): ((single_map_homological_complex F c j).inv.app X).f i = 0 := by simp [single_map_homological_complex, h] end homological_complex namespace chain_complex /-- Turning an object into a chain complex supported at zero then applying a functor is the same as applying the functor then forming the complex. -/ def singleβ‚€_map_homological_complex (F : V β₯€ W) [F.additive] : singleβ‚€ V β‹™ F.map_homological_complex _ β‰… F β‹™ singleβ‚€ W := nat_iso.of_components (Ξ» X, { hom := { f := Ξ» i, match i with | 0 := πŸ™ _ | (i+1) := F.map_zero_object.hom end, }, inv := { f := Ξ» i, match i with | 0 := πŸ™ _ | (i+1) := F.map_zero_object.inv end, }, hom_inv_id' := begin ext (_|i), { unfold_aux, simp, }, { unfold_aux, dsimp, simp only [comp_f, id_f, zero_comp], exact (zero_of_source_iso_zero _ F.map_zero_object).symm, } end, inv_hom_id' := by { ext (_|i); { unfold_aux, dsimp, simp, }, }, }) (Ξ» X Y f, by { ext (_|i); { unfold_aux, dsimp, simp, }, }). @[simp] lemma singleβ‚€_map_homological_complex_hom_app_zero (F : V β₯€ W) [F.additive] (X : V) : ((singleβ‚€_map_homological_complex F).hom.app X).f 0 = πŸ™ _ := rfl @[simp] lemma singleβ‚€_map_homological_complex_hom_app_succ (F : V β₯€ W) [F.additive] (X : V) (n : β„•) : ((singleβ‚€_map_homological_complex F).hom.app X).f (n+1) = 0 := rfl @[simp] lemma singleβ‚€_map_homological_complex_inv_app_zero (F : V β₯€ W) [F.additive] (X : V) : ((singleβ‚€_map_homological_complex F).inv.app X).f 0 = πŸ™ _ := rfl @[simp] lemma singleβ‚€_map_homological_complex_inv_app_succ (F : V β₯€ W) [F.additive] (X : V) (n : β„•) : ((singleβ‚€_map_homological_complex F).inv.app X).f (n+1) = 0 := rfl end chain_complex namespace cochain_complex /-- Turning an object into a cochain complex supported at zero then applying a functor is the same as applying the functor then forming the cochain complex. -/ def singleβ‚€_map_homological_complex (F : V β₯€ W) [F.additive] : singleβ‚€ V β‹™ F.map_homological_complex _ β‰… F β‹™ singleβ‚€ W := nat_iso.of_components (Ξ» X, { hom := { f := Ξ» i, match i with | 0 := πŸ™ _ | (i+1) := F.map_zero_object.hom end, }, inv := { f := Ξ» i, match i with | 0 := πŸ™ _ | (i+1) := F.map_zero_object.inv end, }, hom_inv_id' := begin ext (_|i), { unfold_aux, simp, }, { unfold_aux, dsimp, simp only [comp_f, id_f, zero_comp], exact (zero_of_source_iso_zero _ F.map_zero_object).symm, } end, inv_hom_id' := by { ext (_|i); { unfold_aux, dsimp, simp, }, }, }) (Ξ» X Y f, by { ext (_|i); { unfold_aux, dsimp, simp, }, }). @[simp] lemma singleβ‚€_map_homological_complex_hom_app_zero (F : V β₯€ W) [F.additive] (X : V) : ((singleβ‚€_map_homological_complex F).hom.app X).f 0 = πŸ™ _ := rfl @[simp] lemma singleβ‚€_map_homological_complex_hom_app_succ (F : V β₯€ W) [F.additive] (X : V) (n : β„•) : ((singleβ‚€_map_homological_complex F).hom.app X).f (n+1) = 0 := rfl @[simp] lemma singleβ‚€_map_homological_complex_inv_app_zero (F : V β₯€ W) [F.additive] (X : V) : ((singleβ‚€_map_homological_complex F).inv.app X).f 0 = πŸ™ _ := rfl @[simp] lemma singleβ‚€_map_homological_complex_inv_app_succ (F : V β₯€ W) [F.additive] (X : V) (n : β„•) : ((singleβ‚€_map_homological_complex F).inv.app X).f (n+1) = 0 := rfl end cochain_complex
e6e9bb997ebba9c7981f9c49744b5286deba50fc
7c2dd01406c42053207061adb11703dc7ce0b5e5
/src/exercises/03_forall_or.lean
c89db5c91514b4fe2a237288a011b5c887f7dedb
[ "Apache-2.0" ]
permissive
leanprover-community/tutorials
50ec79564cbf2ad1afd1ac43d8ee3c592c2883a8
79a6872a755c4ae0c2aca57e1adfdac38b1d8bb1
refs/heads/master
1,687,466,144,386
1,672,061,276,000
1,672,061,276,000
189,169,918
186
81
Apache-2.0
1,686,350,300,000
1,559,113,678,000
Lean
UTF-8
Lean
false
false
8,145
lean
import data.real.basic import algebra.group.pi set_option pp.beta true /- In this file, we'll learn about the βˆ€ quantifier, and the disjunction operator ∨ (logical OR). Let P be a predicate on a type X. This means for every mathematical object x with type X, we get a mathematical statement P x. In Lean, P x has type Prop. Lean sees a proof h of `βˆ€ x, P x` as a function sending any `x : X` to a proof `h x` of `P x`. This already explains the main way to use an assumption or lemma which starts with a βˆ€. In order to prove `βˆ€ x, P x`, we use `intros x` to fix an arbitrary object with type X, and call it x. Note also we don't need to give the type of x in the expression `βˆ€ x, P x` as long as the type of P is clear to Lean, which can then infer the type of x. Let's define two predicates to play with βˆ€. -/ def even_fun (f : ℝ β†’ ℝ) := βˆ€ x, f (-x) = f x def odd_fun (f : ℝ β†’ ℝ) := βˆ€ x, f (-x) = -f x /- In the next proof, we also take the opportunity to introduce the `unfold` tactic, which simply unfolds definitions. Here this is purely for didactic reason, Lean doesn't need those `unfold` invocations. We will also use `rfl` which is a term proving equalities that are true by definition (in a very strong sense to be discussed later). -/ example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun g β†’ even_fun (f + g) := begin -- Assume f is even intros hf, -- which means βˆ€ x, f (-x) = f x unfold even_fun at hf, -- and the same for g intros hg, unfold even_fun at hg, -- We need to prove βˆ€ x, (f+g)(-x) = (f+g)(x) unfold even_fun, -- Let x be any real number intros x, -- and let's compute calc (f + g) (-x) = f (-x) + g (-x) : rfl ... = f x + g (-x) : by rw hf x ... = f x + g x : by rw hg x ... = (f + g) x : rfl end /- In the preceding proof, all `unfold` lines are purely for psychological comfort. Sometimes unfolding is necessary because we want to apply a tactic that operates purely on the syntactical level. The main such tactic is `rw`. The same property of `rw` explain why the first computation line is necessary, although its proof is simply `rfl`. Before that line, `rw hf x` won't find anything like `f (-x)` hence will give up. The last line is not necessary however, since it only proves something that is true by definition, and is not followed by a `rw`. Also, Lean doesn't need to be told that hf should be specialized to x before rewriting, exactly as in the first file 01_equality_rewriting. We can also gather several rewrites using a list of expressions. One last trick is that `rw` can take a list of expressions to use for rewriting. For instance `rw [h₁, hβ‚‚, h₃]` is equivalent to three lines `rw h₁`, `rw hβ‚‚` and `rw h₃`. Note that you can inspect the tactic state between those rewrites when reading a proof using this syntax. You simply need to move the cursor inside the list. Hence we can compress the above proof to: -/ example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun g β†’ even_fun (f + g) := begin intros hf hg x, calc (f + g) (-x) = f (-x) + g (-x) : rfl ... = f x + g x : by rw [hf, hg] end /- Now let's practice. If you need to learn how to type a unicode symbol, you can put your mouse cursor above the symbol and wait for one second. -/ -- 0023 example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun (g ∘ f) := begin sorry end -- 0024 example (f g : ℝ β†’ ℝ) : odd_fun f β†’ odd_fun g β†’ odd_fun (g ∘ f) := begin sorry end /- Let's have more quantifiers, and play with forward and backward reasoning. In the next definitions, note how `βˆ€ x₁, βˆ€ xβ‚‚` is abreviated to `βˆ€ x₁ xβ‚‚`. -/ def non_decreasing (f : ℝ β†’ ℝ) := βˆ€ x₁ xβ‚‚, x₁ ≀ xβ‚‚ β†’ f x₁ ≀ f xβ‚‚ def non_increasing (f : ℝ β†’ ℝ) := βˆ€ x₁ xβ‚‚, x₁ ≀ xβ‚‚ β†’ f x₁ β‰₯ f xβ‚‚ /- Let's be very explicit and use forward reasoning first. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin -- Let x₁ and xβ‚‚ be real numbers such that x₁ ≀ xβ‚‚ intros x₁ xβ‚‚ h, -- Since f is non-decreasing, f x₁ ≀ f xβ‚‚. have step₁ : f x₁ ≀ f xβ‚‚, exact hf x₁ xβ‚‚ h, -- Since g is non-decreasing, we then get g (f x₁) ≀ g (f xβ‚‚). exact hg (f x₁) (f xβ‚‚) step₁, end /- In the above proof, note how inconvenient it is to specify x₁ and xβ‚‚ in `hf x₁ xβ‚‚ h` since they could be inferred from the type of h. We could have written `hf _ _ h` and Lean would have filled the holes denoted by _. Even better we could have written the definition of `non_decreasing` as: βˆ€ {x₁ xβ‚‚}, x₁ ≀ xβ‚‚ β†’ f x₁ ≀ f xβ‚‚, with curly braces to denote implicit arguments. But let's leave that aside for now. One possible variation on the above proof is to use the `specialize` tactic to replace hf by its specialization to the relevant value. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros x₁ xβ‚‚ h, specialize hf x₁ xβ‚‚ h, exact hg (f x₁) (f xβ‚‚) hf, end /- This `specialize` tactic is mostly useful for exploration, or in preparation for rewriting in the assumption. One can very often replace its use by using more complicated expressions directly involving the original assumption, as in the next variation: -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros x₁ xβ‚‚ h, exact hg (f x₁) (f xβ‚‚) (hf x₁ xβ‚‚ h), end /- Since the above proof uses only `intros` and `exact`, we could very easily replace it by the raw proof term: -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := Ξ» x₁ xβ‚‚ h, hg (f x₁) (f xβ‚‚) (hf x₁ xβ‚‚ h) /- Of course the above proof is difficult to decipher. The principle in mathlib is to use such a proof when the result is obvious and you don't want to read the proof anyway. Instead of pursuing this style, let's see how backward reasoning would look like here. As usual with this style, we use `apply` and enjoy Lean specializing assumptions for us using unification. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin -- Let x₁ and xβ‚‚ be real numbers such that x₁ ≀ xβ‚‚ intros x₁ xβ‚‚ h, -- We need to prove (g ∘ f) x₁ ≀ (g ∘ f) xβ‚‚. -- Since g is non-decreasing, it suffices to prove f x₁ ≀ f xβ‚‚ apply hg, -- which follows from our assumption on f apply hf, -- and on x₁ and xβ‚‚ exact h end -- 0025 example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_increasing g) : non_increasing (g ∘ f) := begin sorry end /- Let's switch to disjunctions now. Lean denotes by ∨ the logical OR operator. In order to make use of an assumption hyp : P ∨ Q we use the cases tactic: cases hyp with hP hQ which creates two proof branches: one branch assuming hP : P, and one branch assuming hQ : Q. In order to directly prove a goal P ∨ Q, we use either the `left` tactic and prove P or the `right` tactic and prove Q. In the next proof we use `ring` and `linarith` to get rid of easy computations or inequalities, as well as one lemma: mul_eq_zero : a*b = 0 ↔ a = 0 ∨ b = 0 -/ example (a b : ℝ) : a = a*b β†’ a = 0 ∨ b = 1 := begin intro hyp, have H : a*(1 - b) = 0, { calc a*(1 - b) = a - a*b : by ring ... = 0 : by linarith, }, rw mul_eq_zero at H, cases H with Ha Hb, { left, exact Ha, }, { right, linarith, }, end -- 0026 example (x y : ℝ) : x^2 = y^2 β†’ x = y ∨ x = -y := begin sorry end /- In the next exercise, we can use: eq_or_lt_of_le : x ≀ y β†’ x = y ∨ x < y -/ -- 0027 example (f : ℝ β†’ ℝ) : non_decreasing f ↔ βˆ€ x y, x < y β†’ f x ≀ f y := begin sorry end /- In the next exercise, we can use: le_total x y : x ≀ y ∨ y ≀ x -/ -- 0028 example (f : ℝ β†’ ℝ) (h : non_decreasing f) (h' : βˆ€ x, f (f x) = x) : βˆ€ x, f x = x := begin sorry end
e9e146e7829bb3baa9dab4af86c161811cabd23b
3446e92e64a5de7ed1f2109cfb024f83cd904c34
/src/game/world4/level7.lean
a0e03d4957ae6b06f1136cff25aafd1ed5156da4
[]
no_license
kckennylau/natural_number_game
019f4a5f419c9681e65234ecd124c564f9a0a246
ad8c0adaa725975be8a9f978c8494a39311029be
refs/heads/master
1,598,784,137,722
1,571,905,156,000
1,571,905,156,000
218,354,686
0
0
null
1,572,373,319,000
1,572,373,318,000
null
UTF-8
Lean
false
false
540
lean
import game.world4.level6 -- hide namespace mynat -- hide /- # World 4 : Power World ## Level 7 of 7: `pow_pow` -/ /- Lemma For all naturals $m$, $a$, $b$, we have $(m ^ a) ^ b = m ^ {ab}$. -/ lemma pow_pow (m a b : mynat) : (m ^ a) ^ b = m ^ (a * b) := begin [less_leaky] induction' b with t Ht, rw [mul_zero, pow_zero, pow_zero], refl, rw [pow_succ, Ht, mul_succ, pow_add], refl, end /- The next world is inequality world, and you will have to learn some new tactics to get through this one. -/ end mynat -- hide
ad65c2a00c2e260ee931a9de30164330df76f949
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/sigma/order.lean
ea81a76603b94f0a5f8c6aca15b3ecd7eeb288dc
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
6,656
lean
/- Copyright (c) 2021 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import data.sigma.lex import order.bounded_order /-! # Orders on a sigma type This file defines two orders on a sigma type: * The disjoint sum of orders. `a` is less `b` iff `a` and `b` are in the same summand and `a` is less than `b` there. * The lexicographical order. `a` is less than `b` if its summand is strictly less than the summand of `b` or they are in the same summand and `a` is less than `b` there. We make the disjoint sum of orders the default set of instances. The lexicographic order goes on a type synonym. ## Notation * `Ξ£β‚— i, Ξ± i`: Sigma type equipped with the lexicographic order. Type synonym of `Ξ£ i, Ξ± i`. ## See also Related files are: * `data.finset.colex`: Colexicographic order on finite sets. * `data.list.lex`: Lexicographic order on lists. * `data.pi.lex`: Lexicographic order on `Ξ β‚— i, Ξ± i`. * `data.psigma.order`: Lexicographic order on `Ξ£β‚—' i, Ξ± i`. Basically a twin of this file. * `data.prod.lex`: Lexicographic order on `Ξ± Γ— Ξ²`. ## TODO Prove that a sigma type is a `no_max_order`, `no_min_order`, `densely_ordered` when its summands are. Upgrade `equiv.sigma_congr_left`, `equiv.sigma_congr`, `equiv.sigma_assoc`, `equiv.sigma_prod_of_equiv`, `equiv.sigma_equiv_prod`, ... to order isomorphisms. -/ namespace sigma variables {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} /-! ### Disjoint sum of orders on `sigma` -/ /-- Disjoint sum of orders. `⟨i, a⟩ ≀ ⟨j, b⟩` iff `i = j` and `a ≀ b`. -/ inductive le [Ξ  i, has_le (Ξ± i)] : Ξ  a b : Ξ£ i, Ξ± i, Prop | fiber (i : ΞΉ) (a b : Ξ± i) : a ≀ b β†’ le ⟨i, a⟩ ⟨i, b⟩ /-- Disjoint sum of orders. `⟨i, a⟩ < ⟨j, b⟩` iff `i = j` and `a < b`. -/ inductive lt [Ξ  i, has_lt (Ξ± i)] : Ξ  a b : Ξ£ i, Ξ± i, Prop | fiber (i : ΞΉ) (a b : Ξ± i) : a < b β†’ lt ⟨i, a⟩ ⟨i, b⟩ instance [Ξ  i, has_le (Ξ± i)] : has_le (Ξ£ i, Ξ± i) := ⟨le⟩ instance [Ξ  i, has_lt (Ξ± i)] : has_lt (Ξ£ i, Ξ± i) := ⟨lt⟩ @[simp] lemma mk_le_mk_iff [Ξ  i, has_le (Ξ± i)] {i : ΞΉ} {a b : Ξ± i} : (⟨i, a⟩ : sigma Ξ±) ≀ ⟨i, b⟩ ↔ a ≀ b := ⟨λ ⟨_, _, _, h⟩, h, le.fiber _ _ _⟩ @[simp] lemma mk_lt_mk_iff [Ξ  i, has_lt (Ξ± i)] {i : ΞΉ} {a b : Ξ± i} : (⟨i, a⟩ : sigma Ξ±) < ⟨i, b⟩ ↔ a < b := ⟨λ ⟨_, _, _, h⟩, h, lt.fiber _ _ _⟩ lemma le_def [Ξ  i, has_le (Ξ± i)] {a b : Ξ£ i, Ξ± i} : a ≀ b ↔ βˆƒ h : a.1 = b.1, h.rec a.2 ≀ b.2 := begin split, { rintro ⟨i, a, b, h⟩, exact ⟨rfl, h⟩ }, { obtain ⟨i, a⟩ := a, obtain ⟨j, b⟩ := b, rintro ⟨(rfl : i = j), h⟩, exact le.fiber _ _ _ h } end lemma lt_def [Ξ  i, has_lt (Ξ± i)] {a b : Ξ£ i, Ξ± i} : a < b ↔ βˆƒ h : a.1 = b.1, h.rec a.2 < b.2 := begin split, { rintro ⟨i, a, b, h⟩, exact ⟨rfl, h⟩ }, { obtain ⟨i, a⟩ := a, obtain ⟨j, b⟩ := b, rintro ⟨(rfl : i = j), h⟩, exact lt.fiber _ _ _ h } end instance [Ξ  i, preorder (Ξ± i)] : preorder (Ξ£ i, Ξ± i) := { le_refl := Ξ» ⟨i, a⟩, le.fiber i a a le_rfl, le_trans := begin rintro _ _ _ ⟨i, a, b, hab⟩ ⟨_, _, c, hbc⟩, exact le.fiber i a c (hab.trans hbc), end, lt_iff_le_not_le := Ξ» _ _, begin split, { rintro ⟨i, a, b, hab⟩, rwa [mk_le_mk_iff, mk_le_mk_iff, ←lt_iff_le_not_le] }, { rintro ⟨⟨i, a, b, hab⟩, h⟩, rw mk_le_mk_iff at h, exact mk_lt_mk_iff.2 (hab.lt_of_not_le h) } end, .. sigma.has_le, .. sigma.has_lt } instance [Ξ  i, partial_order (Ξ± i)] : partial_order (Ξ£ i, Ξ± i) := { le_antisymm := begin rintro _ _ ⟨i, a, b, hab⟩ ⟨_, _, _, hba⟩, exact ext rfl (heq_of_eq $ hab.antisymm hba), end, .. sigma.preorder } /-! ### Lexicographical order on `sigma` -/ namespace lex notation `Ξ£β‚—` binders `, ` r:(scoped p, _root_.lex (sigma p)) := r /-- The lexicographical `≀` on a sigma type. -/ instance has_le [has_lt ΞΉ] [Ξ  i, has_le (Ξ± i)] : has_le (Ξ£β‚— i, Ξ± i) := ⟨lex (<) (Ξ» i, (≀))⟩ /-- The lexicographical `<` on a sigma type. -/ instance has_lt [has_lt ΞΉ] [Ξ  i, has_lt (Ξ± i)] : has_lt (Ξ£β‚— i, Ξ± i) := ⟨lex (<) (Ξ» i, (<))⟩ /-- The lexicographical preorder on a sigma type. -/ instance preorder [preorder ΞΉ] [Ξ  i, preorder (Ξ± i)] : preorder (Ξ£β‚— i, Ξ± i) := { le_refl := Ξ» ⟨i, a⟩, lex.right a a le_rfl, le_trans := Ξ» _ _ _, trans_of (lex (<) $ Ξ» _, (≀)), lt_iff_le_not_le := begin refine Ξ» a b, ⟨λ hab, ⟨hab.mono_right (Ξ» i a b, le_of_lt), _⟩, _⟩, { rintro (⟨j, i, b, a, hji⟩ | ⟨i, b, a, hba⟩); obtain (⟨_, _, _, _, hij⟩ | ⟨_, _, _, hab⟩) := hab, { exact hij.not_lt hji }, { exact lt_irrefl _ hji }, { exact lt_irrefl _ hij }, { exact hab.not_le hba } }, { rintro ⟨⟨i, j, a, b, hij⟩ |⟨i, a, b, hab⟩, hba⟩, { exact lex.left _ _ hij }, { exact lex.right _ _ (hab.lt_of_not_le $ Ξ» h, hba $ lex.right _ _ h) } } end, .. lex.has_le, .. lex.has_lt } /-- The lexicographical partial order on a sigma type. -/ instance partial_order [preorder ΞΉ] [Ξ  i, partial_order (Ξ± i)] : partial_order (Ξ£β‚— i, Ξ± i) := { le_antisymm := Ξ» _ _, antisymm_of (lex (<) $ Ξ» _, (≀)), .. lex.preorder } /-- The lexicographical linear order on a sigma type. -/ instance linear_order [linear_order ΞΉ] [Ξ  i, linear_order (Ξ± i)] : linear_order (Ξ£β‚— i, Ξ± i) := { le_total := total_of (lex (<) $ Ξ» _, (≀)), decidable_eq := sigma.decidable_eq, decidable_le := lex.decidable _ _, .. lex.partial_order } /-- The lexicographical linear order on a sigma type. -/ instance order_bot [partial_order ΞΉ] [order_bot ΞΉ] [Ξ  i, preorder (Ξ± i)] [order_bot (Ξ± βŠ₯)] : order_bot (Ξ£β‚— i, Ξ± i) := { bot := ⟨βŠ₯, βŠ₯⟩, bot_le := Ξ» ⟨a, b⟩, begin obtain rfl | ha := eq_bot_or_bot_lt a, { exact lex.right _ _ bot_le }, { exact lex.left _ _ ha } end } /-- The lexicographical linear order on a sigma type. -/ instance order_top [partial_order ΞΉ] [order_top ΞΉ] [Ξ  i, preorder (Ξ± i)] [order_top (Ξ± ⊀)] : order_top (Ξ£β‚— i, Ξ± i) := { top := ⟨⊀, ⊀⟩, le_top := Ξ» ⟨a, b⟩, begin obtain rfl | ha := eq_top_or_lt_top a, { exact lex.right _ _ le_top }, { exact lex.left _ _ ha } end } /-- The lexicographical linear order on a sigma type. -/ instance bounded_order [partial_order ΞΉ] [bounded_order ΞΉ] [Ξ  i, preorder (Ξ± i)] [order_bot (Ξ± βŠ₯)] [order_top (Ξ± ⊀)] : bounded_order (Ξ£β‚— i, Ξ± i) := { .. lex.order_bot, .. lex.order_top } end lex end sigma
54a58d48b635b1ecb52399dfec898d30b41cd1ca
8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3
/src/number_theory/padics/padic_norm.lean
a8b137ff67f99e6e685aff08d39aa86c769d1965
[ "Apache-2.0" ]
permissive
troyjlee/mathlib
e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5
45e7eb8447555247246e3fe91c87066506c14875
refs/heads/master
1,689,248,035,046
1,629,470,528,000
1,629,470,528,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
27,986
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import ring_theory.int.basic import algebra.field_power import ring_theory.multiplicity import data.real.cau_seq import tactic.ring_exp import tactic.basic /-! # p-adic norm This file defines the p-adic valuation and the p-adic norm on β„š. The p-adic valuation on β„š is the difference of the multiplicities of `p` in the numerator and denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate assumptions on p. The valuation induces a norm on β„š. This norm is a nonarchimedean absolute value. It takes values in {0} βˆͺ {1/p^k | k ∈ β„€}. ## Notations This file uses the local notation `/.` for `rat.mk`. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[fact (prime p)]` as a type class argument. ## References * [F. Q. GouΓͺva, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation -/ universe u open nat open_locale rat open multiplicity /-- For `p β‰  1`, the p-adic valuation of an integer `z β‰  0` is the largest natural number `n` such that p^n divides z. `padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the valuation of `q.denom`. If `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0. -/ def padic_val_rat (p : β„•) (q : β„š) : β„€ := if h : q β‰  0 ∧ p β‰  1 then (multiplicity (p : β„€) q.num).get (multiplicity.finite_int_iff.2 ⟨h.2, rat.num_ne_zero_of_ne_zero h.1⟩) - (multiplicity (p : β„€) q.denom).get (multiplicity.finite_int_iff.2 ⟨h.2, by exact_mod_cast rat.denom_ne_zero _⟩) else 0 /-- A simplification of the definition of `padic_val_rat p q` when `q β‰  0` and `p` is prime. -/ lemma padic_val_rat_def (p : β„•) [hp : fact p.prime] {q : β„š} (hq : q β‰  0) : padic_val_rat p q = (multiplicity (p : β„€) q.num).get (finite_int_iff.2 ⟨hp.1.ne_one, rat.num_ne_zero_of_ne_zero hq⟩) - (multiplicity (p : β„€) q.denom).get (finite_int_iff.2 ⟨hp.1.ne_one, by exact_mod_cast rat.denom_ne_zero _⟩) := dif_pos ⟨hq, hp.1.ne_one⟩ namespace padic_val_rat open multiplicity variables {p : β„•} /-- `padic_val_rat p q` is symmetric in `q`. -/ @[simp] protected lemma neg (q : β„š) : padic_val_rat p (-q) = padic_val_rat p q := begin unfold padic_val_rat, split_ifs, { simp [-add_comm]; refl }, { exfalso, simp * at * }, { exfalso, simp * at * }, { refl } end /-- `padic_val_rat p 1` is 0 for any `p`. -/ @[simp] protected lemma one : padic_val_rat p 1 = 0 := by unfold padic_val_rat; split_ifs; simp * /-- For `p β‰  0, p β‰  1, `padic_val_rat p p` is 1. -/ @[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 := by unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at * /-- The p-adic value of an integer `z β‰  0` is the multiplicity of `p` in `z`. -/ lemma padic_val_rat_of_int (z : β„€) (hp : p β‰  1) (hz : z β‰  0) : padic_val_rat p (z : β„š) = (multiplicity (p : β„€) z).get (finite_int_iff.2 ⟨hp, hz⟩) := by rw [padic_val_rat, dif_pos]; simp *; refl end padic_val_rat /-- A convenience function for the case of `padic_val_rat` when both inputs are natural numbers. -/ def padic_val_nat (p : β„•) (n : β„•) : β„• := int.to_nat (padic_val_rat p n) section padic_val_nat /-- `padic_val_nat` is defined as an `int.to_nat` cast; this lemma ensures that the cast is well-behaved. -/ lemma zero_le_padic_val_rat_of_nat (p n : β„•) : 0 ≀ padic_val_rat p n := begin unfold padic_val_rat, split_ifs, { simp, }, { trivial, }, end /-- `padic_val_rat` coincides with `padic_val_nat`. -/ @[simp, norm_cast] lemma padic_val_rat_of_nat (p n : β„•) : ↑(padic_val_nat p n) = padic_val_rat p n := begin unfold padic_val_nat, rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n), end /-- A simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`. -/ lemma padic_val_nat_def {p : β„•} [hp : fact p.prime] {n : β„•} (hn : n β‰  0) : padic_val_nat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨nat.prime.ne_one hp.1, bot_lt_iff_ne_bot.mpr hn⟩) := begin have n_nonzero : (n : β„š) β‰  0, by simpa only [cast_eq_zero, ne.def], -- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here, -- hence the very long list simpa only [ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm, int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add, rat.coe_nat_num ] using padic_val_rat_def p n_nonzero, end lemma one_le_padic_val_nat_of_dvd {n p : nat} [prime : fact p.prime] (nonzero : n β‰  0) (div : p ∣ n) : 1 ≀ padic_val_nat p n := begin rw @padic_val_nat_def _ prime _ nonzero, let one_le_mul : _ ≀ multiplicity p n := @multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end), simp only [enat.coe_one] at one_le_mul, rcases one_le_mul with ⟨_, q⟩, dsimp at q, solve_by_elim, end @[simp] lemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := by simpa @[simp] lemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat] end padic_val_nat namespace padic_val_rat open multiplicity variables (p : β„•) [p_prime : fact p.prime] include p_prime /-- The multiplicity of `p : β„•` in `a : β„€` is finite exactly when `a β‰  0`. -/ lemma finite_int_prime_iff {p : β„•} [p_prime : fact p.prime] {a : β„€} : finite (p : β„€) a ↔ a β‰  0 := by simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))] /-- A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`. -/ protected lemma defn {q : β„š} {n d : β„€} (hqz : q β‰  0) (qdf : q = n /. d) : padic_val_rat p q = (multiplicity (p : β„€) n).get (finite_int_iff.2 ⟨ne.symm $ ne_of_lt p_prime.1.one_lt, Ξ» hn, by simp * at *⟩) - (multiplicity (p : β„€) d).get (finite_int_iff.2 ⟨ne.symm $ ne_of_lt p_prime.1.one_lt, Ξ» hd, by simp * at *⟩) := have hn : n β‰  0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf, have hd : d β‰  0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf, let ⟨c, hc1, hc2⟩ := rat.num_denom_mk hn hd qdf in by rw [padic_val_rat, dif_pos]; simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1), (ne.symm (ne_of_lt p_prime.1.one_lt)), hqz] /-- A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma mul {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) : padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r := have q*r = (q.num * r.num) /. (↑q.denom * ↑r.denom), by rw_mod_cast rat.mul_num_denom, have hq' : q.num /. q.denom β‰  0, by rw rat.num_denom; exact hq, have hr' : r.num /. r.denom β‰  0, by rw rat.num_denom; exact hr, have hp' : _root_.prime (p : β„€), from nat.prime_iff_prime_int.1 p_prime.1, begin rw [padic_val_rat.defn p (mul_ne_zero hq hr) this], conv_rhs { rw [←(@rat.num_denom q), padic_val_rat.defn p hq', ←(@rat.num_denom r), padic_val_rat.defn p hr'] }, rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg] end /-- A rewrite lemma for `padic_val_rat p (q^k) with condition `q β‰  0`. -/ protected lemma pow {q : β„š} (hq : q β‰  0) {k : β„•} : padic_val_rat p (q ^ k) = k * padic_val_rat p q := by induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq), pow_succ, add_mul, add_comm] /-- A rewrite lemma for `padic_val_rat p (q⁻¹)` with condition `q β‰  0`. -/ protected lemma inv {q : β„š} (hq : q β‰  0) : padic_val_rat p (q⁻¹) = -padic_val_rat p q := by rw [eq_neg_iff_add_eq_zero, ← padic_val_rat.mul p (inv_ne_zero hq) hq, inv_mul_cancel hq, padic_val_rat.one] /-- A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma div {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) : padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r := by rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr), padic_val_rat.inv p hr, sub_eq_add_neg] /-- A condition for `padic_val_rat p (n₁ / d₁) ≀ padic_val_rat p (nβ‚‚ / dβ‚‚), in terms of divisibility by `p^n`. -/ lemma padic_val_rat_le_padic_val_rat_iff {n₁ nβ‚‚ d₁ dβ‚‚ : β„€} (hn₁ : n₁ β‰  0) (hnβ‚‚ : nβ‚‚ β‰  0) (hd₁ : d₁ β‰  0) (hdβ‚‚ : dβ‚‚ β‰  0) : padic_val_rat p (n₁ /. d₁) ≀ padic_val_rat p (nβ‚‚ /. dβ‚‚) ↔ βˆ€ (n : β„•), ↑p ^ n ∣ n₁ * dβ‚‚ β†’ ↑p ^ n ∣ nβ‚‚ * d₁ := have hf1 : finite (p : β„€) (n₁ * dβ‚‚), from finite_int_prime_iff.2 (mul_ne_zero hn₁ hdβ‚‚), have hf2 : finite (p : β„€) (nβ‚‚ * d₁), from finite_int_prime_iff.2 (mul_ne_zero hnβ‚‚ hd₁), by conv { to_lhs, rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn₁ hd₁) rfl, padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hnβ‚‚ hdβ‚‚) rfl, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le], norm_cast, rw [← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm, ← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2, enat.get_le_get, multiplicity_le_multiplicity_iff] } /-- Sufficient conditions to show that the p-adic valuation of `q` is less than or equal to the p-adic vlauation of `q + r`. -/ theorem le_padic_val_rat_add_of_le {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) (hqr : q + r β‰  0) (h : padic_val_rat p q ≀ padic_val_rat p r) : padic_val_rat p q ≀ padic_val_rat p (q + r) := have hqn : q.num β‰  0, from rat.num_ne_zero_of_ne_zero hq, have hqd : (q.denom : β„€) β‰  0, by exact_mod_cast rat.denom_ne_zero _, have hrn : r.num β‰  0, from rat.num_ne_zero_of_ne_zero hr, have hrd : (r.denom : β„€) β‰  0, by exact_mod_cast rat.denom_ne_zero _, have hqreq : q + r = (((q.num * r.denom + q.denom * r.num : β„€)) /. (↑q.denom * ↑r.denom : β„€)), from rat.add_num_denom _ _, have hqrd : q.num * ↑(r.denom) + ↑(q.denom) * r.num β‰  0, from rat.mk_num_ne_zero_of_ne_zero hqr hqreq, begin conv_lhs { rw ←(@rat.num_denom q) }, rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd), ← multiplicity_le_multiplicity_iff, mul_left_comm, multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul], rw [←(@rat.num_denom q), ←(@rat.num_denom r), padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, ← multiplicity_le_multiplicity_iff] at h, calc _ ≀ min (multiplicity ↑p (q.num * ↑(r.denom) * ↑(q.denom))) (multiplicity ↑p (↑(q.denom) * r.num * ↑(q.denom))) : (le_min (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm]) (by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : β„€) (_ * _) (nat.prime_iff_prime_int.1 p_prime.1)]; exact add_le_add_left h _)) ... ≀ _ : min_le_multiplicity_add end /-- The minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`. -/ theorem min_le_padic_val_rat_add {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) (hqr : q + r β‰  0) : min (padic_val_rat p q) (padic_val_rat p r) ≀ padic_val_rat p (q + r) := (le_total (padic_val_rat p q) (padic_val_rat p r)).elim (Ξ» h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hq hr hqr h) (Ξ» h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _ hr hq (by rwa add_comm) h) open_locale big_operators /-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation (if the sum is non-zero). -/ theorem sum_pos_of_pos {n : β„•} {F : β„• β†’ β„š} (hF : βˆ€ i, i < n β†’ 0 < padic_val_rat p (F i)) (hn0 : βˆ‘ i in finset.range n, F i β‰  0) : 0 < padic_val_rat p (βˆ‘ i in finset.range n, F i) := begin induction n with d hd, { exact false.elim (hn0 rfl) }, { rw finset.sum_range_succ at hn0 ⊒, by_cases h : βˆ‘ (x : β„•) in finset.range d, F x = 0, { rw [h, zero_add], exact hF d (lt_add_one _) }, { refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p h (Ξ» h1, _) hn0), { refine lt_min (hd (Ξ» i hi, _) h) (hF d (lt_add_one _)), exact hF _ (lt_trans hi (lt_add_one _)) }, { have h2 := hF d (lt_add_one _), rw h1 at h2, exact lt_irrefl _ h2 } } } end end padic_val_rat namespace padic_val_nat /-- A rewrite lemma for `padic_val_nat p (q * r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma mul (p : β„•) [p_prime : fact p.prime] {q r : β„•} (hq : q β‰  0) (hr : r β‰  0) : padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r := begin apply int.coe_nat_inj, simp only [padic_val_rat_of_nat, nat.cast_mul], rw padic_val_rat.mul, norm_cast, exact cast_ne_zero.mpr hq, exact cast_ne_zero.mpr hr, end /-- Dividing out by a prime factor reduces the padic_val_nat by 1. -/ protected lemma div {p : β„•} [p_prime : fact p.prime] {b : β„•} (dvd : p ∣ b) : (padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 := begin by_cases b_split : (b = 0), { simp [b_split], }, { have split_frac : padic_val_rat p (b / p) = padic_val_rat p b - padic_val_rat p p := padic_val_rat.div p (nat.cast_ne_zero.mpr b_split) (nat.cast_ne_zero.mpr (nat.prime.ne_zero p_prime.1)), rw padic_val_rat.padic_val_rat_self (nat.prime.one_lt p_prime.1) at split_frac, have r : 1 ≀ padic_val_nat p b := one_le_padic_val_nat_of_dvd b_split dvd, exact_mod_cast split_frac, } end /-- A version of `padic_val_rat.pow` for `padic_val_nat` -/ protected lemma pow (p q n : β„•) [fact p.prime] (hq : q β‰  0) : padic_val_nat p (q ^ n) = n * padic_val_nat p q := begin apply @nat.cast_injective β„€, push_cast, exact padic_val_rat.pow _ (cast_ne_zero.mpr hq), end end padic_val_nat section padic_val_nat /-- If a prime doesn't appear in `n`, `padic_val_nat p n` is `0`. -/ lemma padic_val_nat_of_not_dvd {p : β„•} [fact p.prime] {n : β„•} (not_dvd : Β¬(p ∣ n)) : padic_val_nat p n = 0 := begin by_cases hn : n = 0, { subst hn, simp at not_dvd, trivial, }, { rw padic_val_nat_def hn, exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm, assumption, }, end lemma dvd_of_one_le_padic_val_nat {n p : nat} [prime : fact p.prime] (hp : 1 ≀ padic_val_nat p n) : p ∣ n := begin by_contra h, rw padic_val_nat_of_not_dvd h at hp, exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp), end lemma pow_padic_val_nat_dvd {p n : β„•} [fact (nat.prime p)] : p ^ (padic_val_nat p n) ∣ n := begin cases nat.eq_zero_or_pos n with hn hn, { rw hn, exact dvd_zero (p ^ padic_val_nat p 0) }, { rw multiplicity.pow_dvd_iff_le_multiplicity, apply le_of_eq, rw padic_val_nat_def (ne_of_gt hn), { apply enat.coe_get }, { apply_instance } } end lemma pow_succ_padic_val_nat_not_dvd {p n : β„•} [hp : fact (nat.prime p)] (hn : 0 < n) : Β¬ p ^ (padic_val_nat p n + 1) ∣ n := begin { rw multiplicity.pow_dvd_iff_le_multiplicity, rw padic_val_nat_def (ne_of_gt hn), { rw [enat.coe_add, enat.coe_get], simp only [enat.coe_one, not_le], apply enat.lt_add_one (ne_top_iff_finite.2 (finite_nat_iff.2 ⟨hp.elim.ne_one, hn⟩)) }, { apply_instance } } end lemma padic_val_nat_primes {p q : β„•} [p_prime : fact p.prime] [q_prime : fact q.prime] (neq : p β‰  q) : padic_val_nat p q = 0 := @padic_val_nat_of_not_dvd p p_prime q $ (not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq protected lemma padic_val_nat.div' {p : β„•} [p_prime : fact p.prime] : βˆ€ {m : β„•} (cpm : coprime p m) {b : β„•} (dvd : m ∣ b), padic_val_nat p (b / m) = padic_val_nat p b | 0 := Ξ» cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], } | (n + 1) := Ξ» cpm b dvd, begin rcases dvd with ⟨c, rfl⟩, rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0, { rw [hc, mul_zero] }, { rw padic_val_nat.mul, { suffices : Β¬ p ∣ (n+1), { rw [padic_val_nat_of_not_dvd this, zero_add] }, contrapose! cpm, exact p_prime.1.dvd_iff_not_coprime.mp cpm }, { exact nat.succ_ne_zero _ }, { exact hc } }, end lemma padic_val_nat_eq_factors_count (p : β„•) [hp : fact p.prime] : βˆ€ (n : β„•), padic_val_nat p n = (factors n).count p | 0 := by simp | 1 := by simp | (m + 2) := let n := m + 2 in let q := min_fac n in have hq : fact q.prime := ⟨min_fac_prime (show m + 2 β‰  1, by linarith)⟩, have wf : n / q < n := nat.div_lt_self (nat.succ_pos _) hq.1.one_lt, begin rw factors_add_two, show padic_val_nat p n = list.count p (q :: (factors (n / q))), rw [list.count_cons', ← padic_val_nat_eq_factors_count], split_ifs with h, have p_dvd_n : p ∣ n, { have: q ∣ n := nat.min_fac_dvd n, cc }, { rw [←h, padic_val_nat.div], { have: 1 ≀ padic_val_nat p n := one_le_padic_val_nat_of_dvd (by linarith) p_dvd_n, exact (nat.sub_eq_iff_eq_add this).mp rfl, }, { exact p_dvd_n, }, }, { suffices : p.coprime q, { rw [padic_val_nat.div' this (min_fac_dvd n), add_zero], }, rwa nat.coprime_primes hp.1 hq.1, }, end @[simp] lemma padic_val_nat_self (p : β„•) [fact p.prime] : padic_val_nat p p = 1 := by simp [padic_val_nat_def (fact.out p.prime).ne_zero] @[simp] lemma padic_val_nat_prime_pow (p n : β„•) [fact p.prime] : padic_val_nat p (p ^ n) = n := by rw [padic_val_nat.pow p _ _ (fact.out p.prime).ne_zero, padic_val_nat_self p, mul_one] open_locale big_operators lemma prod_pow_prime_padic_val_nat (n : nat) (hn : n β‰  0) (m : nat) (pr : n < m) : ∏ p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n := begin rw ← pos_iff_ne_zero at hn, have H : (factors n : multiset β„•).prod = n, { rw [multiset.coe_prod, prod_factors hn], }, rw finset.prod_multiset_count at H, conv_rhs { rw ← H, }, refine finset.prod_bij_ne_one (Ξ» p hp hp', p) _ _ _ _, { rintro p hp hpn, rw [finset.mem_filter, finset.mem_range] at hp, rw [multiset.mem_to_finset, multiset.mem_coe, mem_factors_iff_dvd hn hp.2], contrapose! hpn, haveI Hp : fact p.prime := ⟨hp.2⟩, rw [padic_val_nat_of_not_dvd hpn, pow_zero], }, { intros, assumption }, { intros p hp hpn, rw [multiset.mem_to_finset, multiset.mem_coe] at hp, haveI Hp : fact p.prime := ⟨prime_of_mem_factors hp⟩, simp only [exists_prop, ne.def, finset.mem_filter, finset.mem_range], refine ⟨p, ⟨_, Hp.1⟩, ⟨_, rfl⟩⟩, { rw mem_factors_iff_dvd hn Hp.1 at hp, exact lt_of_le_of_lt (le_of_dvd hn hp) pr }, { rw padic_val_nat_eq_factors_count, simpa [ne.def, multiset.coe_count] using hpn } }, { intros p hp hpn, rw [finset.mem_filter, finset.mem_range] at hp, haveI Hp : fact p.prime := ⟨hp.2⟩, rw [padic_val_nat_eq_factors_count, multiset.coe_count] } end end padic_val_nat /-- If `q β‰  0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`. If `q = 0`, the p-adic norm of `q` is 0. -/ def padic_norm (p : β„•) (q : β„š) : β„š := if q = 0 then 0 else (↑p : β„š) ^ (-(padic_val_rat p q)) namespace padic_norm section padic_norm open padic_val_rat variables (p : β„•) /-- Unfolds the definition of the p-adic norm of `q` when `q β‰  0`. -/ @[simp] protected lemma eq_fpow_of_nonzero {q : β„š} (hq : q β‰  0) : padic_norm p q = p ^ (-(padic_val_rat p q)) := by simp [hq, padic_norm] /-- The p-adic norm is nonnegative. -/ protected lemma nonneg (q : β„š) : 0 ≀ padic_norm p q := if hq : q = 0 then by simp [hq, padic_norm] else begin unfold padic_norm; split_ifs, apply fpow_nonneg, exact_mod_cast nat.zero_le _ end /-- The p-adic norm of 0 is 0. -/ @[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm] /-- The p-adic norm of 1 is 1. -/ @[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm] /-- The p-adic norm of `p` is `1/p` if `p > 1`. See also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime. -/ lemma padic_norm_p {p : β„•} (hp : 1 < p) : padic_norm p p = 1 / p := by simp [padic_norm, (show p β‰  0, by linarith), padic_val_rat.padic_val_rat_self hp] /-- The p-adic norm of `p` is `1/p` if `p` is prime. See also `padic_norm.padic_norm_p` for a version that assumes `1 < p`. -/ @[simp] lemma padic_norm_p_of_prime (p : β„•) [fact p.prime] : padic_norm p p = 1 / p := padic_norm_p $ nat.prime.one_lt (fact.out _) /-- The p-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/ lemma padic_norm_of_prime_of_ne {p q : β„•} [p_prime : fact p.prime] [q_prime : fact q.prime] (neq : p β‰  q) : padic_norm p q = 1 := begin have p : padic_val_rat p q = 0, { exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq }, simp [padic_norm, p, q_prime.1.1, q_prime.1.ne_zero], end /-- The p-adic norm of `p` is less than 1 if `1 < p`. See also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`. -/ lemma padic_norm_p_lt_one {p : β„•} (hp : 1 < p) : padic_norm p p < 1 := begin rw [padic_norm_p hp, div_lt_iff, one_mul], { exact_mod_cast hp }, { exact_mod_cast zero_lt_one.trans hp }, end /-- The p-adic norm of `p` is less than 1 if `p` is prime. See also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`. -/ lemma padic_norm_p_lt_one_of_prime (p : β„•) [fact p.prime] : padic_norm p p < 1 := padic_norm_p_lt_one $ nat.prime.one_lt (fact.out _) /-- `padic_norm p q` takes discrete values `p ^ -z` for `z : β„€`. -/ protected theorem values_discrete {q : β„š} (hq : q β‰  0) : βˆƒ z : β„€, padic_norm p q = p ^ (-z) := ⟨ (padic_val_rat p q), by simp [padic_norm, hq] ⟩ /-- `padic_norm p` is symmetric. -/ @[simp] protected lemma neg (q : β„š) : padic_norm p (-q) = padic_norm p q := if hq : q = 0 then by simp [hq] else by simp [padic_norm, hq] variable [hp : fact p.prime] include hp /-- If `q β‰  0`, then `padic_norm p q β‰  0`. -/ protected lemma nonzero {q : β„š} (hq : q β‰  0) : padic_norm p q β‰  0 := begin rw padic_norm.eq_fpow_of_nonzero p hq, apply fpow_ne_zero_of_ne_zero, exact_mod_cast ne_of_gt hp.1.pos end /-- If the p-adic norm of `q` is 0, then `q` is 0. -/ lemma zero_of_padic_norm_eq_zero {q : β„š} (h : padic_norm p q = 0) : q = 0 := begin apply by_contradiction, intro hq, unfold padic_norm at h, rw if_neg hq at h, apply absurd h, apply fpow_ne_zero_of_ne_zero, exact_mod_cast hp.1.ne_zero end /-- The p-adic norm is multiplicative. -/ @[simp] protected theorem mul (q r : β„š) : padic_norm p (q*r) = padic_norm p q * padic_norm p r := if hq : q = 0 then by simp [hq] else if hr : r = 0 then by simp [hr] else have q*r β‰  0, from mul_ne_zero hq hr, have (↑p : β„š) β‰  0, by simp [hp.1.ne_zero], by simp [padic_norm, *, padic_val_rat.mul, fpow_add this, mul_comm] /-- The p-adic norm respects division. -/ @[simp] protected theorem div (q r : β„š) : padic_norm p (q / r) = padic_norm p q / padic_norm p r := if hr : r = 0 then by simp [hr] else eq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [←padic_norm.mul, div_mul_cancel _ hr]) /-- The p-adic norm of an integer is at most 1. -/ protected theorem of_int (z : β„€) : padic_norm p ↑z ≀ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else begin unfold padic_norm, rw [if_neg _], { refine fpow_le_one_of_nonpos _ _, { exact_mod_cast le_of_lt hp.1.one_lt, }, { rw [padic_val_rat_of_int _ hp.1.ne_one hz, neg_nonpos], norm_cast, simp }}, exact_mod_cast hz end private lemma nonarchimedean_aux {q r : β„š} (h : padic_val_rat p q ≀ padic_val_rat p r) : padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) := have hnqp : padic_norm p q β‰₯ 0, from padic_norm.nonneg _ _, have hnrp : padic_norm p r β‰₯ 0, from padic_norm.nonneg _ _, if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right] else if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left] else if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _) else begin unfold padic_norm, split_ifs, apply le_max_iff.2, left, apply fpow_le_of_le, { exact_mod_cast le_of_lt hp.1.one_lt }, { apply neg_le_neg, have : padic_val_rat p q = min (padic_val_rat p q) (padic_val_rat p r), from (min_eq_left h).symm, rw this, apply min_le_padic_val_rat_add; assumption } end /-- The p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and the norm of `q`. -/ protected theorem nonarchimedean {q r : β„š} : padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) := begin wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r], exact nonarchimedean_aux p hle end /-- The p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p` plus the norm of `q`. -/ theorem triangle_ineq (q r : β„š) : padic_norm p (q + r) ≀ padic_norm p q + padic_norm p r := calc padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p ... ≀ padic_norm p q + padic_norm p r : max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _) /-- The p-adic norm of a difference is at most the max of each component. Restates the archimedean property of the p-adic norm. -/ protected theorem sub {q r : β„š} : padic_norm p (q - r) ≀ max (padic_norm p q) (padic_norm p r) := by rw [sub_eq_add_neg, ←padic_norm.neg p r]; apply padic_norm.nonarchimedean /-- If the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of the norms of `q` and `r`. -/ lemma add_eq_max_of_ne {q r : β„š} (hne : padic_norm p q β‰  padic_norm p r) : padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) := begin wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r], have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm, have : padic_norm p q ≀ max (padic_norm p (q + r)) (padic_norm p r), from calc padic_norm p q = padic_norm p (q + r - r) : by congr; ring ... ≀ max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p ... = max (padic_norm p (q + r)) (padic_norm p r) : by simp, have hnge : padic_norm p r ≀ padic_norm p (q + r), { apply le_of_not_gt, intro hgt, rw max_eq_right_of_lt hgt at this, apply not_lt_of_ge this, assumption }, have : padic_norm p q ≀ padic_norm p (q + r), by rwa [max_eq_left hnge] at this, apply _root_.le_antisymm, { apply padic_norm.nonarchimedean p }, { rw max_eq_left_of_lt hlt, assumption } end /-- The p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle inequality. -/ instance : is_absolute_value (padic_norm p) := { abv_nonneg := padic_norm.nonneg p, abv_eq_zero := begin intros, constructor; intro, { apply zero_of_padic_norm_eq_zero p, assumption }, { simp [*] } end, abv_add := padic_norm.triangle_ineq p, abv_mul := padic_norm.mul p } variable {p} lemma dvd_iff_norm_le {n : β„•} {z : β„€} : ↑(p^n) ∣ z ↔ padic_norm p z ≀ ↑p ^ (-n : β„€) := begin unfold padic_norm, split_ifs with hz, { norm_cast at hz, have : 0 ≀ (p^n : β„š), {apply pow_nonneg, exact_mod_cast le_of_lt hp.1.pos }, simp [hz, this] }, { rw [fpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.1.ne_one _], { norm_cast, rw [← enat.coe_le_coe, enat.coe_get, ← multiplicity.pow_dvd_iff_le_multiplicity], simp }, { exact_mod_cast hz }, { exact_mod_cast hp.1.one_lt } } end end padic_norm end padic_norm
87b4cf12156e304b7f51c8c585f8458960ac26c9
947b78d97130d56365ae2ec264df196ce769371a
/tests/lean/StxQuot.lean
77e9993b56d5deda2815f6d6469a94205429ba40
[ "Apache-2.0" ]
permissive
shyamalschandra/lean4
27044812be8698f0c79147615b1d5090b9f4b037
6e7a883b21eaf62831e8111b251dc9b18f40e604
refs/heads/master
1,671,417,126,371
1,601,859,995,000
1,601,860,020,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,204
lean
import Lean new_frontend namespace Lean open Lean.Elab def run {Ξ±} [HasToString Ξ±] : Unhygienic Ξ± β†’ String := toString ∘ Unhygienic.run #eval run `(Nat.one) #eval run `($Syntax.missing) namespace Syntax #eval run `($missing) #eval run `($(missing)) #eval run `($(id Syntax.missing) + 1) #eval run $ let id := Syntax.missing; `($id + 1) end Syntax #eval run `(1 + 1) #eval run $ `(fun a => a) >>= pure #eval run $ `(def foo := 1) #eval run $ `(def foo := 1 def bar := 2) #eval run $ do let a ← `(Nat.one); `($a) #eval run $ do let a ← `(Nat.one); `(f $a $a) #eval run $ do let a ← `(Nat.one); `(f $ f $a 1) #eval run $ do let a ← `(Nat.one); `(f $(id a)) #eval run $ do let a ← `(Nat.one); `($(a).b) #eval run $ do let a ← `(1 + 2); match_syntax a with `($a + $b) => `($b + $a) | _ => pure Syntax.missing #eval run $ do let a ← `(def foo := 1); match_syntax a with `($f:command) => pure f | _ => pure Syntax.missing #eval run $ do let a ← `(def foo := 1 def bar := 2); match_syntax a with `($f:command $g:command) => `($g:command $f:command) | _ => pure Syntax.missing #eval run $ do let a ← `(aa); match_syntax a with `($id:ident) => pure 0 | `($e) => pure 1 | _ => pure 2 #eval run $ do let a ← `(1 + 2); match_syntax a with `($id:ident) => pure 0 | `($e) => pure 1 | _ => pure 2 #eval run $ do let params ← #[`(a), `((b : Nat))].mapM id; `(fun $params* => 1) #eval run $ do let a ← `(fun (a : Nat) b => c); match_syntax a with `(fun $aa* => $e) => pure aa | _ => pure #[] #eval run $ do let a ← `(βˆ€ a, c); match_syntax a with `(βˆ€ $id:ident, $e) => pure id | _ => pure a #eval run $ do let a ← `(βˆ€ _, c); match_syntax a with `(βˆ€ $id:ident, $e) => pure id | _ => pure a -- this one should NOT check the kind of the matched node #eval run $ do let a ← `(βˆ€ _, c); match_syntax a with `(βˆ€ $a, $e) => pure a | _ => pure a #eval run $ do let a ← `(a); match_syntax a with `($id:ident) => pure id | _ => pure a #eval run $ do let a ← `(a.{0}); match_syntax a with `($id:ident) => pure id | _ => pure a #eval run $ do let a ← `(match a with | a => 1 | _ => 2); match_syntax a with `(match $e with $eqns:matchAlt*) => pure eqns | _ => pure #[] end Lean
6419aca616ab96b2c4e40782e27e6cc6e552b3f1
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/topology/instances/matrix.lean
ad02ee006beb20b3565059d0390609c5ea3916b1
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
18,634
lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash, Eric Wieser -/ import topology.algebra.infinite_sum.basic import topology.algebra.ring.basic import topology.algebra.star import linear_algebra.matrix.nonsingular_inverse import linear_algebra.matrix.trace /-! # Topological properties of matrices > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file is a place to collect topological results about matrices. ## Main definitions: * `matrix.topological_ring`: square matrices form a topological ring ## Main results * Continuity: * `continuous.matrix_det`: the determinant is continuous over a topological ring. * `continuous.matrix_adjugate`: the adjugate is continuous over a topological ring. * Infinite sums * `matrix.transpose_tsum`: transpose commutes with infinite sums * `matrix.diagonal_tsum`: diagonal commutes with infinite sums * `matrix.block_diagonal_tsum`: block diagonal commutes with infinite sums * `matrix.block_diagonal'_tsum`: non-uniform block diagonal commutes with infinite sums -/ open matrix open_locale matrix variables {X Ξ± l m n p S R : Type*} {m' n' : l β†’ Type*} instance [topological_space R] : topological_space (matrix m n R) := Pi.topological_space instance [topological_space R] [t2_space R] : t2_space (matrix m n R) := Pi.t2_space /-! ### Lemmas about continuity of operations -/ section continuity variables [topological_space X] [topological_space R] instance [has_smul Ξ± R] [has_continuous_const_smul Ξ± R] : has_continuous_const_smul Ξ± (matrix m n R) := pi.has_continuous_const_smul instance [topological_space Ξ±] [has_smul Ξ± R] [has_continuous_smul Ξ± R] : has_continuous_smul Ξ± (matrix m n R) := pi.has_continuous_smul instance [has_add R] [has_continuous_add R] : has_continuous_add (matrix m n R) := pi.has_continuous_add instance [has_neg R] [has_continuous_neg R] : has_continuous_neg (matrix m n R) := pi.has_continuous_neg instance [add_group R] [topological_add_group R] : topological_add_group (matrix m n R) := pi.topological_add_group /-- To show a function into matrices is continuous it suffices to show the coefficients of the resulting matrix are continuous -/ @[continuity] lemma continuous_matrix [topological_space Ξ±] {f : Ξ± β†’ matrix m n R} (h : βˆ€ i j, continuous (Ξ» a, f a i j)) : continuous f := continuous_pi $ Ξ» _, continuous_pi $ Ξ» j, h _ _ lemma continuous.matrix_elem {A : X β†’ matrix m n R} (hA : continuous A) (i : m) (j : n) : continuous (Ξ» x, A x i j) := (continuous_apply_apply i j).comp hA @[continuity] lemma continuous.matrix_map [topological_space S] {A : X β†’ matrix m n S} {f : S β†’ R} (hA : continuous A) (hf : continuous f) : continuous (Ξ» x, (A x).map f) := continuous_matrix $ Ξ» i j, hf.comp $ hA.matrix_elem _ _ @[continuity] lemma continuous.matrix_transpose {A : X β†’ matrix m n R} (hA : continuous A) : continuous (Ξ» x, (A x)α΅€) := continuous_matrix $ Ξ» i j, hA.matrix_elem j i lemma continuous.matrix_conj_transpose [has_star R] [has_continuous_star R] {A : X β†’ matrix m n R} (hA : continuous A) : continuous (Ξ» x, (A x)α΄΄) := hA.matrix_transpose.matrix_map continuous_star instance [has_star R] [has_continuous_star R] : has_continuous_star (matrix m m R) := ⟨continuous_id.matrix_conj_transpose⟩ @[continuity] lemma continuous.matrix_col {A : X β†’ n β†’ R} (hA : continuous A) : continuous (Ξ» x, col (A x)) := continuous_matrix $ Ξ» i j, (continuous_apply _).comp hA @[continuity] lemma continuous.matrix_row {A : X β†’ n β†’ R} (hA : continuous A) : continuous (Ξ» x, row (A x)) := continuous_matrix $ Ξ» i j, (continuous_apply _).comp hA @[continuity] lemma continuous.matrix_diagonal [has_zero R] [decidable_eq n] {A : X β†’ n β†’ R} (hA : continuous A) : continuous (Ξ» x, diagonal (A x)) := continuous_matrix $ Ξ» i j, ((continuous_apply i).comp hA).if_const _ continuous_zero @[continuity] lemma continuous.matrix_dot_product [fintype n] [has_mul R] [add_comm_monoid R] [has_continuous_add R] [has_continuous_mul R] {A : X β†’ n β†’ R} {B : X β†’ n β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, dot_product (A x) (B x)) := continuous_finset_sum _ $ Ξ» i _, ((continuous_apply i).comp hA).mul ((continuous_apply i).comp hB) /-- For square matrices the usual `continuous_mul` can be used. -/ @[continuity] lemma continuous.matrix_mul [fintype n] [has_mul R] [add_comm_monoid R] [has_continuous_add R] [has_continuous_mul R] {A : X β†’ matrix m n R} {B : X β†’ matrix n p R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, (A x).mul (B x)) := continuous_matrix $ Ξ» i j, continuous_finset_sum _ $ Ξ» k _, (hA.matrix_elem _ _).mul (hB.matrix_elem _ _) instance [fintype n] [has_mul R] [add_comm_monoid R] [has_continuous_add R] [has_continuous_mul R] : has_continuous_mul (matrix n n R) := ⟨continuous_fst.matrix_mul continuous_snd⟩ instance [fintype n] [non_unital_non_assoc_semiring R] [topological_semiring R] : topological_semiring (matrix n n R) := {} instance [fintype n] [non_unital_non_assoc_ring R] [topological_ring R] : topological_ring (matrix n n R) := {} @[continuity] lemma continuous.matrix_vec_mul_vec [has_mul R] [has_continuous_mul R] {A : X β†’ m β†’ R} {B : X β†’ n β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, vec_mul_vec (A x) (B x)) := continuous_matrix $ Ξ» i j, ((continuous_apply _).comp hA).mul ((continuous_apply _).comp hB) @[continuity] lemma continuous.matrix_mul_vec [non_unital_non_assoc_semiring R] [has_continuous_add R] [has_continuous_mul R] [fintype n] {A : X β†’ matrix m n R} {B : X β†’ n β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, (A x).mul_vec (B x)) := continuous_pi $ Ξ» i, ((continuous_apply i).comp hA).matrix_dot_product hB @[continuity] lemma continuous.matrix_vec_mul [non_unital_non_assoc_semiring R] [has_continuous_add R] [has_continuous_mul R] [fintype m] {A : X β†’ m β†’ R} {B : X β†’ matrix m n R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, vec_mul (A x) (B x)) := continuous_pi $ Ξ» i, hA.matrix_dot_product $ continuous_pi $ Ξ» j, hB.matrix_elem _ _ @[continuity] lemma continuous.matrix_submatrix {A : X β†’ matrix l n R} (hA : continuous A) (e₁ : m β†’ l) (eβ‚‚ : p β†’ n) : continuous (Ξ» x, (A x).submatrix e₁ eβ‚‚) := continuous_matrix $ Ξ» i j, hA.matrix_elem _ _ @[continuity] lemma continuous.matrix_reindex {A : X β†’ matrix l n R} (hA : continuous A) (e₁ : l ≃ m) (eβ‚‚ : n ≃ p) : continuous (Ξ» x, reindex e₁ eβ‚‚ (A x)) := hA.matrix_submatrix _ _ @[continuity] lemma continuous.matrix_diag {A : X β†’ matrix n n R} (hA : continuous A) : continuous (Ξ» x, matrix.diag (A x)) := continuous_pi $ Ξ» _, hA.matrix_elem _ _ -- note this doesn't elaborate well from the above lemma continuous_matrix_diag : continuous (matrix.diag : matrix n n R β†’ n β†’ R) := show continuous (Ξ» x : matrix n n R, matrix.diag x), from continuous_id.matrix_diag @[continuity] lemma continuous.matrix_trace [fintype n] [add_comm_monoid R] [has_continuous_add R] {A : X β†’ matrix n n R} (hA : continuous A) : continuous (Ξ» x, trace (A x)) := continuous_finset_sum _ $ Ξ» i hi, hA.matrix_elem _ _ @[continuity] lemma continuous.matrix_det [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R] {A : X β†’ matrix n n R} (hA : continuous A) : continuous (Ξ» x, (A x).det) := begin simp_rw matrix.det_apply, refine continuous_finset_sum _ (Ξ» l _, continuous.const_smul _ _), refine continuous_finset_prod _ (Ξ» l _, hA.matrix_elem _ _), end @[continuity] lemma continuous.matrix_update_column [decidable_eq n] (i : n) {A : X β†’ matrix m n R} {B : X β†’ m β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, (A x).update_column i (B x)) := continuous_matrix $ Ξ» j k, (continuous_apply k).comp $ ((continuous_apply _).comp hA).update i ((continuous_apply _).comp hB) @[continuity] lemma continuous.matrix_update_row [decidable_eq m] (i : m) {A : X β†’ matrix m n R} {B : X β†’ n β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, (A x).update_row i (B x)) := hA.update i hB @[continuity] lemma continuous.matrix_cramer [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R] {A : X β†’ matrix n n R} {B : X β†’ n β†’ R} (hA : continuous A) (hB : continuous B) : continuous (Ξ» x, (A x).cramer (B x)) := continuous_pi $ Ξ» i, (hA.matrix_update_column _ hB).matrix_det @[continuity] lemma continuous.matrix_adjugate [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R] {A : X β†’ matrix n n R} (hA : continuous A) : continuous (Ξ» x, (A x).adjugate) := continuous_matrix $ Ξ» j k, (hA.matrix_transpose.matrix_update_column k continuous_const).matrix_det /-- When `ring.inverse` is continuous at the determinant (such as in a `normed_ring`, or a `topological_field`), so is `matrix.has_inv`. -/ lemma continuous_at_matrix_inv [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R] (A : matrix n n R) (h : continuous_at ring.inverse A.det) : continuous_at has_inv.inv A := (h.comp continuous_id.matrix_det.continuous_at).smul continuous_id.matrix_adjugate.continuous_at -- lemmas about functions in `data/matrix/block.lean` section block_matrices @[continuity] lemma continuous.matrix_from_blocks {A : X β†’ matrix n l R} {B : X β†’ matrix n m R} {C : X β†’ matrix p l R} {D : X β†’ matrix p m R} (hA : continuous A) (hB : continuous B) (hC : continuous C) (hD : continuous D) : continuous (Ξ» x, matrix.from_blocks (A x) (B x) (C x) (D x)) := continuous_matrix $ Ξ» i j, by cases i; cases j; refine continuous.matrix_elem _ i j; assumption @[continuity] lemma continuous.matrix_block_diagonal [has_zero R] [decidable_eq p] {A : X β†’ p β†’ matrix m n R} (hA : continuous A) : continuous (Ξ» x, block_diagonal (A x)) := continuous_matrix $ Ξ» ⟨i₁, iβ‚‚βŸ© ⟨j₁, jβ‚‚βŸ©, (((continuous_apply iβ‚‚).comp hA).matrix_elem i₁ j₁).if_const _ continuous_zero @[continuity] lemma continuous.matrix_block_diag {A : X β†’ matrix (m Γ— p) (n Γ— p) R} (hA : continuous A) : continuous (Ξ» x, block_diag (A x)) := continuous_pi $ Ξ» i, continuous_matrix $ Ξ» j k, hA.matrix_elem _ _ @[continuity] lemma continuous.matrix_block_diagonal' [has_zero R] [decidable_eq l] {A : X β†’ Ξ  i, matrix (m' i) (n' i) R} (hA : continuous A) : continuous (Ξ» x, block_diagonal' (A x)) := continuous_matrix $ Ξ» ⟨i₁, iβ‚‚βŸ© ⟨j₁, jβ‚‚βŸ©, begin dsimp only [block_diagonal'_apply'], split_ifs, { subst h, exact ((continuous_apply i₁).comp hA).matrix_elem iβ‚‚ jβ‚‚ }, { exact continuous_const }, end @[continuity] lemma continuous.matrix_block_diag' {A : X β†’ matrix (Ξ£ i, m' i) (Ξ£ i, n' i) R} (hA : continuous A) : continuous (Ξ» x, block_diag' (A x)) := continuous_pi $ Ξ» i, continuous_matrix $ Ξ» j k, hA.matrix_elem _ _ end block_matrices end continuity /-! ### Lemmas about infinite sums -/ section tsum variables [semiring Ξ±] [add_comm_monoid R] [topological_space R] [module Ξ± R] lemma has_sum.matrix_transpose {f : X β†’ matrix m n R} {a : matrix m n R} (hf : has_sum f a) : has_sum (Ξ» x, (f x)α΅€) aα΅€ := (hf.map (matrix.transpose_add_equiv m n R) continuous_id.matrix_transpose : _) lemma summable.matrix_transpose {f : X β†’ matrix m n R} (hf : summable f) : summable (Ξ» x, (f x)α΅€) := hf.has_sum.matrix_transpose.summable @[simp] lemma summable_matrix_transpose {f : X β†’ matrix m n R} : summable (Ξ» x, (f x)α΅€) ↔ summable f := (summable.map_iff_of_equiv (matrix.transpose_add_equiv m n R) (@continuous_id (matrix m n R) _).matrix_transpose (continuous_id.matrix_transpose) : _) lemma matrix.transpose_tsum [t2_space R] {f : X β†’ matrix m n R} : (βˆ‘' x, f x)α΅€ = βˆ‘' x, (f x)α΅€ := begin by_cases hf : summable f, { exact hf.has_sum.matrix_transpose.tsum_eq.symm }, { have hft := summable_matrix_transpose.not.mpr hf, rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, transpose_zero] }, end lemma has_sum.matrix_conj_transpose [star_add_monoid R] [has_continuous_star R] {f : X β†’ matrix m n R} {a : matrix m n R} (hf : has_sum f a) : has_sum (Ξ» x, (f x)α΄΄) aα΄΄ := (hf.map (matrix.conj_transpose_add_equiv m n R) continuous_id.matrix_conj_transpose : _) lemma summable.matrix_conj_transpose [star_add_monoid R] [has_continuous_star R] {f : X β†’ matrix m n R} (hf : summable f) : summable (Ξ» x, (f x)α΄΄) := hf.has_sum.matrix_conj_transpose.summable @[simp] lemma summable_matrix_conj_transpose [star_add_monoid R] [has_continuous_star R] {f : X β†’ matrix m n R} : summable (Ξ» x, (f x)α΄΄) ↔ summable f := (summable.map_iff_of_equiv (matrix.conj_transpose_add_equiv m n R) (@continuous_id (matrix m n R) _).matrix_conj_transpose (continuous_id.matrix_conj_transpose) : _) lemma matrix.conj_transpose_tsum [star_add_monoid R] [has_continuous_star R] [t2_space R] {f : X β†’ matrix m n R} : (βˆ‘' x, f x)α΄΄ = βˆ‘' x, (f x)α΄΄ := begin by_cases hf : summable f, { exact hf.has_sum.matrix_conj_transpose.tsum_eq.symm }, { have hft := summable_matrix_conj_transpose.not.mpr hf, rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, conj_transpose_zero] }, end lemma has_sum.matrix_diagonal [decidable_eq n] {f : X β†’ n β†’ R} {a : n β†’ R} (hf : has_sum f a) : has_sum (Ξ» x, diagonal (f x)) (diagonal a) := (hf.map (diagonal_add_monoid_hom n R) $ continuous.matrix_diagonal $ by exact continuous_id : _) lemma summable.matrix_diagonal [decidable_eq n] {f : X β†’ n β†’ R} (hf : summable f) : summable (Ξ» x, diagonal (f x)) := hf.has_sum.matrix_diagonal.summable @[simp] lemma summable_matrix_diagonal [decidable_eq n] {f : X β†’ n β†’ R} : summable (Ξ» x, diagonal (f x)) ↔ summable f := (summable.map_iff_of_left_inverse (@matrix.diagonal_add_monoid_hom n R _ _) (matrix.diag_add_monoid_hom n R) (by exact continuous.matrix_diagonal continuous_id) continuous_matrix_diag (Ξ» A, diag_diagonal A) : _) lemma matrix.diagonal_tsum [decidable_eq n] [t2_space R] {f : X β†’ n β†’ R} : diagonal (βˆ‘' x, f x) = βˆ‘' x, diagonal (f x) := begin by_cases hf : summable f, { exact hf.has_sum.matrix_diagonal.tsum_eq.symm }, { have hft := summable_matrix_diagonal.not.mpr hf, rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft], exact diagonal_zero }, end lemma has_sum.matrix_diag {f : X β†’ matrix n n R} {a : matrix n n R} (hf : has_sum f a) : has_sum (Ξ» x, diag (f x)) (diag a) := (hf.map (diag_add_monoid_hom n R) continuous_matrix_diag : _) lemma summable.matrix_diag {f : X β†’ matrix n n R} (hf : summable f) : summable (Ξ» x, diag (f x)) := hf.has_sum.matrix_diag.summable section block_matrices lemma has_sum.matrix_block_diagonal [decidable_eq p] {f : X β†’ p β†’ matrix m n R} {a : p β†’ matrix m n R} (hf : has_sum f a) : has_sum (Ξ» x, block_diagonal (f x)) (block_diagonal a) := (hf.map (block_diagonal_add_monoid_hom m n p R) $ continuous.matrix_block_diagonal $ by exact continuous_id : _) lemma summable.matrix_block_diagonal [decidable_eq p] {f : X β†’ p β†’ matrix m n R} (hf : summable f) : summable (Ξ» x, block_diagonal (f x)) := hf.has_sum.matrix_block_diagonal.summable lemma summable_matrix_block_diagonal [decidable_eq p] {f : X β†’ p β†’ matrix m n R} : summable (Ξ» x, block_diagonal (f x)) ↔ summable f := (summable.map_iff_of_left_inverse (matrix.block_diagonal_add_monoid_hom m n p R) (matrix.block_diag_add_monoid_hom m n p R) (by exact continuous.matrix_block_diagonal continuous_id) (by exact continuous.matrix_block_diag continuous_id) (Ξ» A, block_diag_block_diagonal A) : _) lemma matrix.block_diagonal_tsum [decidable_eq p] [t2_space R] {f : X β†’ p β†’ matrix m n R} : block_diagonal (βˆ‘' x, f x) = βˆ‘' x, block_diagonal (f x) := begin by_cases hf : summable f, { exact hf.has_sum.matrix_block_diagonal.tsum_eq.symm }, { have hft := summable_matrix_block_diagonal.not.mpr hf, rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft], exact block_diagonal_zero }, end lemma has_sum.matrix_block_diag {f : X β†’ matrix (m Γ— p) (n Γ— p) R} {a : matrix (m Γ— p) (n Γ— p) R} (hf : has_sum f a) : has_sum (Ξ» x, block_diag (f x)) (block_diag a) := (hf.map (block_diag_add_monoid_hom m n p R) $ continuous.matrix_block_diag continuous_id : _) lemma summable.matrix_block_diag {f : X β†’ matrix (m Γ— p) (n Γ— p) R} (hf : summable f) : summable (Ξ» x, block_diag (f x)) := hf.has_sum.matrix_block_diag.summable lemma has_sum.matrix_block_diagonal' [decidable_eq l] {f : X β†’ Ξ  i, matrix (m' i) (n' i) R} {a : Ξ  i, matrix (m' i) (n' i) R} (hf : has_sum f a) : has_sum (Ξ» x, block_diagonal' (f x)) (block_diagonal' a) := (hf.map (block_diagonal'_add_monoid_hom m' n' R) $ continuous.matrix_block_diagonal' $ by exact continuous_id : _) lemma summable.matrix_block_diagonal' [decidable_eq l] {f : X β†’ Ξ  i, matrix (m' i) (n' i) R} (hf : summable f) : summable (Ξ» x, block_diagonal' (f x)) := hf.has_sum.matrix_block_diagonal'.summable lemma summable_matrix_block_diagonal' [decidable_eq l] {f : X β†’ Ξ  i, matrix (m' i) (n' i) R} : summable (Ξ» x, block_diagonal' (f x)) ↔ summable f := (summable.map_iff_of_left_inverse (matrix.block_diagonal'_add_monoid_hom m' n' R) (matrix.block_diag'_add_monoid_hom m' n' R) (by exact continuous.matrix_block_diagonal' continuous_id) (by exact continuous.matrix_block_diag' continuous_id) (Ξ» A, block_diag'_block_diagonal' A) : _) lemma matrix.block_diagonal'_tsum [decidable_eq l] [t2_space R] {f : X β†’ Ξ  i, matrix (m' i) (n' i) R} : block_diagonal' (βˆ‘' x, f x) = βˆ‘' x, block_diagonal' (f x) := begin by_cases hf : summable f, { exact hf.has_sum.matrix_block_diagonal'.tsum_eq.symm }, { have hft := summable_matrix_block_diagonal'.not.mpr hf, rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft], exact block_diagonal'_zero }, end lemma has_sum.matrix_block_diag' {f : X β†’ matrix (Ξ£ i, m' i) (Ξ£ i, n' i) R} {a : matrix (Ξ£ i, m' i) (Ξ£ i, n' i) R} (hf : has_sum f a) : has_sum (Ξ» x, block_diag' (f x)) (block_diag' a) := (hf.map (block_diag'_add_monoid_hom m' n' R) $ continuous.matrix_block_diag' continuous_id : _) lemma summable.matrix_block_diag' {f : X β†’ matrix (Ξ£ i, m' i) (Ξ£ i, n' i) R} (hf : summable f) : summable (Ξ» x, block_diag' (f x)) := hf.has_sum.matrix_block_diag'.summable end block_matrices end tsum
527cae36f39eee9f53608dd9a77f5266a624f8b6
b2fe74b11b57d362c13326bc5651244f111fa6f4
/src/algebra/algebra/basic.lean
07e9c26f90e594567f7889d77f46e75fd59f042e
[ "Apache-2.0" ]
permissive
midfield/mathlib
c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7
775edc615ecec631d65b6180dbcc7bc26c3abc26
refs/heads/master
1,675,330,551,921
1,608,304,514,000
1,608,304,514,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
49,999
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import tactic.nth_rewrite import data.matrix.basic import data.equiv.ring_aut import linear_algebra.tensor_product import ring_theory.subring import deprecated.subring import algebra.opposites /-! # Algebra over Commutative Semiring In this file we define `algebra`s over commutative (semi)rings, algebra homomorphisms `alg_hom`, algebra equivalences `alg_equiv`. We also define usual operations on `alg_hom`s (`id`, `comp`). `subalgebra`s are defined in `algebra.algebra.subalgebra`. If `S` is an `R`-algebra and `A` is an `S`-algebra then `algebra.comap.algebra R S A` can be used to provide `A` with a structure of an `R`-algebra. Other than that, `algebra.comap` is now deprecated and replaced with `is_scalar_tower`. For the category of `R`-algebras, denoted `Algebra R`, see the file `algebra/category/Algebra/basic.lean`. ## Notations * `A →ₐ[R] B` : `R`-algebra homomorphism from `A` to `B`. * `A ≃ₐ[R] B` : `R`-algebra equivalence from `A` to `B`. -/ universes u v w u₁ v₁ open_locale tensor_product big_operators section prio -- We set this priority to 0 later in this file set_option extends_priority 200 /- control priority of `instance [algebra R A] : has_scalar R A` -/ /-- Given a commutative (semi)ring `R`, an `R`-algebra is a (possibly noncommutative) (semi)ring `A` endowed with a morphism of rings `R β†’+* A` which lands in the center of `A`. For convenience, this typeclass extends `has_scalar R A` where the scalar action must agree with left multiplication by the image of the structure morphism. Given an `algebra R A` instance, the structure morphism `R β†’+* A` is denoted `algebra_map R A`. -/ @[nolint has_inhabited_instance] class algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A] extends has_scalar R A, R β†’+* A := (commutes' : βˆ€ r x, to_fun r * x = x * to_fun r) (smul_def' : βˆ€ r x, r β€’ x = to_fun r * x) end prio /-- Embedding `R β†’+* A` given by `algebra` structure. -/ def algebra_map (R : Type u) (A : Type v) [comm_semiring R] [semiring A] [algebra R A] : R β†’+* A := algebra.to_ring_hom /-- Creating an algebra from a morphism to the center of a semiring. -/ def ring_hom.to_algebra' {R S} [comm_semiring R] [semiring S] (i : R β†’+* S) (h : βˆ€ c x, i c * x = x * i c) : algebra R S := { smul := Ξ» c x, i c * x, commutes' := h, smul_def' := Ξ» c x, rfl, to_ring_hom := i} /-- Creating an algebra from a morphism to a commutative semiring. -/ def ring_hom.to_algebra {R S} [comm_semiring R] [comm_semiring S] (i : R β†’+* S) : algebra R S := i.to_algebra' $ Ξ» _, mul_comm _ lemma ring_hom.algebra_map_to_algebra {R S} [comm_semiring R] [comm_semiring S] (i : R β†’+* S) : @algebra_map R S _ _ i.to_algebra = i := rfl namespace algebra variables {R : Type u} {S : Type v} {A : Type w} {B : Type*} /-- Let `R` be a commutative semiring, let `A` be a semiring with a `semimodule R` structure. If `(r β€’ 1) * x = x * (r β€’ 1) = r β€’ x` for all `r : R` and `x : A`, then `A` is an `algebra` over `R`. -/ def of_semimodule' [comm_semiring R] [semiring A] [semimodule R A] (h₁ : βˆ€ (r : R) (x : A), (r β€’ 1) * x = r β€’ x) (hβ‚‚ : βˆ€ (r : R) (x : A), x * (r β€’ 1) = r β€’ x) : algebra R A := { to_fun := Ξ» r, r β€’ 1, map_one' := one_smul _ _, map_mul' := Ξ» r₁ rβ‚‚, by rw [h₁, mul_smul], map_zero' := zero_smul _ _, map_add' := Ξ» r₁ rβ‚‚, add_smul r₁ rβ‚‚ 1, commutes' := Ξ» r x, by simp only [h₁, hβ‚‚], smul_def' := Ξ» r x, by simp only [h₁] } /-- Let `R` be a commutative semiring, let `A` be a semiring with a `semimodule R` structure. If `(r β€’ x) * y = x * (r β€’ y) = r β€’ (x * y)` for all `r : R` and `x y : A`, then `A` is an `algebra` over `R`. -/ def of_semimodule [comm_semiring R] [semiring A] [semimodule R A] (h₁ : βˆ€ (r : R) (x y : A), (r β€’ x) * y = r β€’ (x * y)) (hβ‚‚ : βˆ€ (r : R) (x y : A), x * (r β€’ y) = r β€’ (x * y)) : algebra R A := of_semimodule' (Ξ» r x, by rw [h₁, one_mul]) (Ξ» r x, by rw [hβ‚‚, mul_one]) section semiring variables [comm_semiring R] [comm_semiring S] variables [semiring A] [algebra R A] [semiring B] [algebra R B] lemma smul_def'' (r : R) (x : A) : r β€’ x = algebra_map R A r * x := algebra.smul_def' r x /-- To prove two algebra structures on a fixed `[comm_semiring R] [semiring A]` agree, it suffices to check the `algebra_map`s agree. -/ -- We'll later use this to show `algebra β„€ M` is a subsingleton. @[ext] lemma algebra_ext {R : Type*} [comm_semiring R] {A : Type*} [semiring A] (P Q : algebra R A) (w : βˆ€ (r : R), by { haveI := P, exact algebra_map R A r } = by { haveI := Q, exact algebra_map R A r }) : P = Q := begin unfreezingI { rcases P with ⟨⟨P⟩⟩, rcases Q with ⟨⟨Q⟩⟩ }, congr, { funext r a, replace w := congr_arg (Ξ» s, s * a) (w r), simp only [←algebra.smul_def''] at w, apply w, }, { ext r, exact w r, }, { apply proof_irrel_heq, }, { apply proof_irrel_heq, }, end @[priority 200] -- see Note [lower instance priority] instance to_semimodule : semimodule R A := { one_smul := by simp [smul_def''], mul_smul := by simp [smul_def'', mul_assoc], smul_add := by simp [smul_def'', mul_add], smul_zero := by simp [smul_def''], add_smul := by simp [smul_def'', add_mul], zero_smul := by simp [smul_def''] } -- from now on, we don't want to use the following instance anymore attribute [instance, priority 0] algebra.to_has_scalar lemma smul_def (r : R) (x : A) : r β€’ x = algebra_map R A r * x := algebra.smul_def' r x lemma algebra_map_eq_smul_one (r : R) : algebra_map R A r = r β€’ 1 := calc algebra_map R A r = algebra_map R A r * 1 : (mul_one _).symm ... = r β€’ 1 : (algebra.smul_def r 1).symm theorem commutes (r : R) (x : A) : algebra_map R A r * x = x * algebra_map R A r := algebra.commutes' r x theorem left_comm (r : R) (x y : A) : x * (algebra_map R A r * y) = algebra_map R A r * (x * y) := by rw [← mul_assoc, ← commutes, mul_assoc] @[simp] lemma mul_smul_comm (s : R) (x y : A) : x * (s β€’ y) = s β€’ (x * y) := by rw [smul_def, smul_def, left_comm] @[simp] lemma smul_mul_assoc (r : R) (x y : A) : (r β€’ x) * y = r β€’ (x * y) := by rw [smul_def, smul_def, mul_assoc] section variables {r : R} {a : A} @[simp] lemma bit0_smul_one : bit0 r β€’ (1 : A) = r β€’ 2 := by simp [bit0, add_smul, smul_add] @[simp] lemma bit0_smul_bit0 : bit0 r β€’ bit0 a = r β€’ (bit0 (bit0 a)) := by simp [bit0, add_smul, smul_add] @[simp] lemma bit0_smul_bit1 : bit0 r β€’ bit1 a = r β€’ (bit0 (bit1 a)) := by simp [bit0, add_smul, smul_add] @[simp] lemma bit1_smul_one : bit1 r β€’ (1 : A) = r β€’ 2 + 1 := by simp [bit1, add_smul, smul_add] @[simp] lemma bit1_smul_bit0 : bit1 r β€’ bit0 a = r β€’ (bit0 (bit0 a)) + bit0 a := by simp [bit1, add_smul, smul_add] @[simp] lemma bit1_smul_bit1 : bit1 r β€’ bit1 a = r β€’ (bit0 (bit1 a)) + bit1 a := by { simp only [bit0, bit1, add_smul, smul_add, one_smul], abel } end variables (R A) /-- The canonical ring homomorphism `algebra_map R A : R β†’* A` for any `R`-algebra `A`, packaged as an `R`-linear map. -/ protected def linear_map : R β†’β‚—[R] A := { map_smul' := Ξ» x y, begin dsimp, simp [algebra.smul_def], end, ..algebra_map R A } @[simp] lemma linear_map_apply (r : R) : algebra.linear_map R A r = algebra_map R A r := rfl instance id : algebra R R := (ring_hom.id R).to_algebra variables {R A} namespace id @[simp] lemma map_eq_self (x : R) : algebra_map R R x = x := rfl @[simp] lemma smul_eq_mul (x y : R) : x β€’ y = x * y := rfl end id section prod variables (R A B) instance : algebra R (A Γ— B) := { commutes' := by { rintro r ⟨a, b⟩, dsimp, rw [commutes r a, commutes r b] }, smul_def' := by { rintro r ⟨a, b⟩, dsimp, rw [smul_def r a, smul_def r b] }, .. prod.semimodule, .. ring_hom.prod (algebra_map R A) (algebra_map R B) } variables {R A B} @[simp] lemma algebra_map_prod_apply (r : R) : algebra_map R (A Γ— B) r = (algebra_map R A r, algebra_map R B r) := rfl end prod /-- Algebra over a subsemiring. -/ instance of_subsemiring (S : subsemiring R) : algebra S A := { smul := Ξ» s x, (s : R) β€’ x, commutes' := Ξ» r x, algebra.commutes r x, smul_def' := Ξ» r x, algebra.smul_def r x, .. (algebra_map R A).comp (subsemiring.subtype S) } /-- Algebra over a subring. -/ instance of_subring {R A : Type*} [comm_ring R] [ring A] [algebra R A] (S : subring R) : algebra S A := { smul := Ξ» s x, (s : R) β€’ x, commutes' := Ξ» r x, algebra.commutes r x, smul_def' := Ξ» r x, algebra.smul_def r x, .. (algebra_map R A).comp (subring.subtype S) } lemma algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) : (algebra_map S R : S β†’+* R) = subring.subtype S := rfl lemma coe_algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) : (algebra_map S R : S β†’ R) = subtype.val := rfl lemma algebra_map_of_subring_apply {R : Type*} [comm_ring R] (S : subring R) (x : S) : algebra_map S R x = x := rfl section local attribute [instance] subset.comm_ring /-- Algebra over a set that is closed under the ring operations. -/ local attribute [instance] def of_is_subring {R A : Type*} [comm_ring R] [ring A] [algebra R A] (S : set R) [is_subring S] : algebra S A := algebra.of_subring S.to_subring lemma is_subring_coe_algebra_map_hom {R : Type*} [comm_ring R] (S : set R) [is_subring S] : (algebra_map S R : S β†’+* R) = is_subring.subtype S := rfl lemma is_subring_coe_algebra_map {R : Type*} [comm_ring R] (S : set R) [is_subring S] : (algebra_map S R : S β†’ R) = subtype.val := rfl lemma is_subring_algebra_map_apply {R : Type*} [comm_ring R] (S : set R) [is_subring S] (x : S) : algebra_map S R x = x := rfl lemma set_range_subset {R : Type*} [comm_ring R] {T₁ Tβ‚‚ : set R} [is_subring T₁] (hyp : T₁ βŠ† Tβ‚‚) : set.range (algebra_map T₁ R) βŠ† Tβ‚‚ := begin rintros x ⟨⟨t, ht⟩, rfl⟩, exact hyp ht, end end /-- Explicit characterization of the submonoid map in the case of an algebra. `S` is made explicit to help with type inference -/ def algebra_map_submonoid (S : Type*) [semiring S] [algebra R S] (M : submonoid R) : (submonoid S) := submonoid.map (algebra_map R S : R β†’* S) M lemma mem_algebra_map_submonoid_of_mem [algebra R S] {M : submonoid R} (x : M) : (algebra_map R S x) ∈ algebra_map_submonoid S M := set.mem_image_of_mem (algebra_map R S) x.2 end semiring section ring variables [comm_ring R] variables (R) /-- A `semiring` that is an `algebra` over a commutative ring carries a natural `ring` structure. -/ def semiring_to_ring [semiring A] [algebra R A] : ring A := { ..semimodule.add_comm_monoid_to_add_comm_group R, ..(infer_instance : semiring A) } variables {R} lemma mul_sub_algebra_map_commutes [ring A] [algebra R A] (x : A) (r : R) : x * (x - algebra_map R A r) = (x - algebra_map R A r) * x := by rw [mul_sub, ←commutes, sub_mul] lemma mul_sub_algebra_map_pow_commutes [ring A] [algebra R A] (x : A) (r : R) (n : β„•) : x * (x - algebra_map R A r) ^ n = (x - algebra_map R A r) ^ n * x := begin induction n with n ih, { simp }, { rw [pow_succ, ←mul_assoc, mul_sub_algebra_map_commutes, mul_assoc, ih, ←mul_assoc], } end end ring end algebra namespace opposite variables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] instance : algebra R Aα΅’α΅– := { to_ring_hom := (algebra_map R A).to_opposite $ Ξ» x y, algebra.commutes _ _, smul_def' := Ξ» c x, unop_injective $ by { dsimp, simp only [op_mul, algebra.smul_def, algebra.commutes, op_unop] }, commutes' := Ξ» r, op_induction $ Ξ» x, by dsimp; simp only [← op_mul, algebra.commutes], ..opposite.has_scalar A R } @[simp] lemma algebra_map_apply (c : R) : algebra_map R Aα΅’α΅– c = op (algebra_map R A c) := rfl end opposite namespace module variables (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [semimodule R M] instance endomorphism_algebra : algebra R (M β†’β‚—[R] M) := { to_fun := Ξ» r, r β€’ linear_map.id, map_one' := one_smul _ _, map_zero' := zero_smul _ _, map_add' := Ξ» r₁ rβ‚‚, add_smul _ _ _, map_mul' := Ξ» r₁ rβ‚‚, by { ext x, simp [mul_smul] }, commutes' := by { intros, ext, simp }, smul_def' := by { intros, ext, simp } } lemma algebra_map_End_eq_smul_id (a : R) : (algebra_map R (End R M)) a = a β€’ linear_map.id := rfl @[simp] lemma algebra_map_End_apply (a : R) (m : M) : (algebra_map R (End R M)) a m = a β€’ m := rfl @[simp] lemma ker_algebra_map_End (K : Type u) (V : Type v) [field K] [add_comm_group V] [vector_space K V] (a : K) (ha : a β‰  0) : ((algebra_map K (End K V)) a).ker = βŠ₯ := linear_map.ker_smul _ _ ha end module instance matrix_algebra (n : Type u) (R : Type v) [decidable_eq n] [fintype n] [comm_semiring R] : algebra R (matrix n n R) := { commutes' := by { intros, simp [matrix.scalar], }, smul_def' := by { intros, simp [matrix.scalar], }, ..(matrix.scalar n) } set_option old_structure_cmd true /-- Defining the homomorphism in the category R-Alg. -/ @[nolint has_inhabited_instance] structure alg_hom (R : Type u) (A : Type v) (B : Type w) [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B := (commutes' : βˆ€ r : R, to_fun (algebra_map R A r) = algebra_map R B r) run_cmd tactic.add_doc_string `alg_hom.to_ring_hom "Reinterpret an `alg_hom` as a `ring_hom`" infixr ` →ₐ `:25 := alg_hom _ notation A ` →ₐ[`:25 R `] ` B := alg_hom R A B namespace alg_hom variables {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁} section semiring variables [comm_semiring R] [semiring A] [semiring B] [semiring C] [semiring D] variables [algebra R A] [algebra R B] [algebra R C] [algebra R D] instance : has_coe_to_fun (A →ₐ[R] B) := ⟨_, Ξ» f, f.to_fun⟩ initialize_simps_projections alg_hom (to_fun β†’ apply) instance coe_ring_hom : has_coe (A →ₐ[R] B) (A β†’+* B) := ⟨alg_hom.to_ring_hom⟩ instance coe_monoid_hom : has_coe (A →ₐ[R] B) (A β†’* B) := ⟨λ f, ↑(f : A β†’+* B)⟩ instance coe_add_monoid_hom : has_coe (A →ₐ[R] B) (A β†’+ B) := ⟨λ f, ↑(f : A β†’+* B)⟩ @[simp, norm_cast] lemma coe_mk {f : A β†’ B} (h₁ hβ‚‚ h₃ hβ‚„ hβ‚…) : ⇑(⟨f, h₁, hβ‚‚, h₃, hβ‚„, hβ‚…βŸ© : A →ₐ[R] B) = f := rfl @[simp, norm_cast] lemma coe_to_ring_hom (f : A →ₐ[R] B) : ⇑(f : A β†’+* B) = f := rfl -- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute. @[norm_cast] lemma coe_to_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A β†’* B) = f := rfl -- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute. @[norm_cast] lemma coe_to_add_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A β†’+ B) = f := rfl variables (Ο† : A →ₐ[R] B) theorem coe_fn_inj ⦃φ₁ Ο†β‚‚ : A →ₐ[R] B⦄ (H : ⇑φ₁ = Ο†β‚‚) : φ₁ = Ο†β‚‚ := by { cases φ₁, cases Ο†β‚‚, congr, exact H } theorem coe_ring_hom_injective : function.injective (coe : (A →ₐ[R] B) β†’ (A β†’+* B)) := Ξ» φ₁ Ο†β‚‚ H, coe_fn_inj $ show ((φ₁ : (A β†’+* B)) : A β†’ B) = ((Ο†β‚‚ : (A β†’+* B)) : A β†’ B), from congr_arg _ H theorem coe_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) β†’ (A β†’* B)) := ring_hom.coe_monoid_hom_injective.comp coe_ring_hom_injective theorem coe_add_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) β†’ (A β†’+ B)) := ring_hom.coe_add_monoid_hom_injective.comp coe_ring_hom_injective protected lemma congr_fun {φ₁ Ο†β‚‚ : A →ₐ[R] B} (H : φ₁ = Ο†β‚‚) (x : A) : φ₁ x = Ο†β‚‚ x := H β–Έ rfl protected lemma congr_arg (Ο† : A →ₐ[R] B) {x y : A} (h : x = y) : Ο† x = Ο† y := h β–Έ rfl @[ext] theorem ext {φ₁ Ο†β‚‚ : A →ₐ[R] B} (H : βˆ€ x, φ₁ x = Ο†β‚‚ x) : φ₁ = Ο†β‚‚ := coe_fn_inj $ funext H theorem ext_iff {φ₁ Ο†β‚‚ : A →ₐ[R] B} : φ₁ = Ο†β‚‚ ↔ βˆ€ x, φ₁ x = Ο†β‚‚ x := ⟨alg_hom.congr_fun, ext⟩ @[simp] theorem commutes (r : R) : Ο† (algebra_map R A r) = algebra_map R B r := Ο†.commutes' r theorem comp_algebra_map : (Ο† : A β†’+* B).comp (algebra_map R A) = algebra_map R B := ring_hom.ext $ Ο†.commutes @[simp] lemma map_add (r s : A) : Ο† (r + s) = Ο† r + Ο† s := Ο†.to_ring_hom.map_add r s @[simp] lemma map_zero : Ο† 0 = 0 := Ο†.to_ring_hom.map_zero @[simp] lemma map_mul (x y) : Ο† (x * y) = Ο† x * Ο† y := Ο†.to_ring_hom.map_mul x y @[simp] lemma map_one : Ο† 1 = 1 := Ο†.to_ring_hom.map_one @[simp] lemma map_smul (r : R) (x : A) : Ο† (r β€’ x) = r β€’ Ο† x := by simp only [algebra.smul_def, map_mul, commutes] @[simp] lemma map_pow (x : A) (n : β„•) : Ο† (x ^ n) = (Ο† x) ^ n := Ο†.to_ring_hom.map_pow x n lemma map_sum {ΞΉ : Type*} (f : ΞΉ β†’ A) (s : finset ΞΉ) : Ο† (βˆ‘ x in s, f x) = βˆ‘ x in s, Ο† (f x) := Ο†.to_ring_hom.map_sum f s lemma map_finsupp_sum {Ξ± : Type*} [has_zero Ξ±] {ΞΉ : Type*} (f : ΞΉ β†’β‚€ Ξ±) (g : ΞΉ β†’ Ξ± β†’ A) : Ο† (f.sum g) = f.sum (Ξ» i a, Ο† (g i a)) := Ο†.map_sum _ _ @[simp] lemma map_nat_cast (n : β„•) : Ο† n = n := Ο†.to_ring_hom.map_nat_cast n @[simp] lemma map_bit0 (x) : Ο† (bit0 x) = bit0 (Ο† x) := Ο†.to_ring_hom.map_bit0 x @[simp] lemma map_bit1 (x) : Ο† (bit1 x) = bit1 (Ο† x) := Ο†.to_ring_hom.map_bit1 x section variables (R A) /-- Identity map as an `alg_hom`. -/ protected def id : A →ₐ[R] A := { commutes' := Ξ» _, rfl, ..ring_hom.id A } end @[simp] lemma id_apply (p : A) : alg_hom.id R A p = p := rfl /-- Composition of algebra homeomorphisms. -/ def comp (φ₁ : B →ₐ[R] C) (Ο†β‚‚ : A →ₐ[R] B) : A →ₐ[R] C := { commutes' := Ξ» r : R, by rw [← φ₁.commutes, ← Ο†β‚‚.commutes]; refl, .. φ₁.to_ring_hom.comp ↑φ₂ } @[simp] lemma comp_apply (φ₁ : B →ₐ[R] C) (Ο†β‚‚ : A →ₐ[R] B) (p : A) : φ₁.comp Ο†β‚‚ p = φ₁ (Ο†β‚‚ p) := rfl @[simp] theorem comp_id : Ο†.comp (alg_hom.id R A) = Ο† := ext $ Ξ» x, rfl @[simp] theorem id_comp : (alg_hom.id R B).comp Ο† = Ο† := ext $ Ξ» x, rfl theorem comp_assoc (φ₁ : C →ₐ[R] D) (Ο†β‚‚ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) : (φ₁.comp Ο†β‚‚).comp φ₃ = φ₁.comp (Ο†β‚‚.comp φ₃) := ext $ Ξ» x, rfl /-- R-Alg β₯€ R-Mod -/ def to_linear_map : A β†’β‚— B := { to_fun := Ο†, map_add' := Ο†.map_add, map_smul' := Ο†.map_smul } @[simp] lemma to_linear_map_apply (p : A) : Ο†.to_linear_map p = Ο† p := rfl theorem to_linear_map_inj {φ₁ Ο†β‚‚ : A →ₐ[R] B} (H : φ₁.to_linear_map = Ο†β‚‚.to_linear_map) : φ₁ = Ο†β‚‚ := ext $ Ξ» x, show φ₁.to_linear_map x = Ο†β‚‚.to_linear_map x, by rw H @[simp] lemma comp_to_linear_map (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl end semiring section comm_semiring variables [comm_semiring R] [comm_semiring A] [comm_semiring B] variables [algebra R A] [algebra R B] (Ο† : A →ₐ[R] B) lemma map_prod {ΞΉ : Type*} (f : ΞΉ β†’ A) (s : finset ΞΉ) : Ο† (∏ x in s, f x) = ∏ x in s, Ο† (f x) := Ο†.to_ring_hom.map_prod f s lemma map_finsupp_prod {Ξ± : Type*} [has_zero Ξ±] {ΞΉ : Type*} (f : ΞΉ β†’β‚€ Ξ±) (g : ΞΉ β†’ Ξ± β†’ A) : Ο† (f.prod g) = f.prod (Ξ» i a, Ο† (g i a)) := Ο†.map_prod _ _ end comm_semiring section ring variables [comm_semiring R] [ring A] [ring B] variables [algebra R A] [algebra R B] (Ο† : A →ₐ[R] B) @[simp] lemma map_neg (x) : Ο† (-x) = -Ο† x := Ο†.to_ring_hom.map_neg x @[simp] lemma map_sub (x y) : Ο† (x - y) = Ο† x - Ο† y := Ο†.to_ring_hom.map_sub x y @[simp] lemma map_int_cast (n : β„€) : Ο† n = n := Ο†.to_ring_hom.map_int_cast n end ring section division_ring variables [comm_ring R] [division_ring A] [division_ring B] variables [algebra R A] [algebra R B] (Ο† : A →ₐ[R] B) @[simp] lemma map_inv (x) : Ο† (x⁻¹) = (Ο† x)⁻¹ := Ο†.to_ring_hom.map_inv x @[simp] lemma map_div (x y) : Ο† (x / y) = Ο† x / Ο† y := Ο†.to_ring_hom.map_div x y end division_ring theorem injective_iff {R A B : Type*} [comm_semiring R] [ring A] [semiring B] [algebra R A] [algebra R B] (f : A →ₐ[R] B) : function.injective f ↔ (βˆ€ x, f x = 0 β†’ x = 0) := ring_hom.injective_iff (f : A β†’+* B) end alg_hom set_option old_structure_cmd true /-- An equivalence of algebras is an equivalence of rings commuting with the actions of scalars. -/ structure alg_equiv (R : Type u) (A : Type v) (B : Type w) [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends A ≃ B, A ≃* B, A ≃+ B, A ≃+* B := (commutes' : βˆ€ r : R, to_fun (algebra_map R A r) = algebra_map R B r) attribute [nolint doc_blame] alg_equiv.to_ring_equiv attribute [nolint doc_blame] alg_equiv.to_equiv attribute [nolint doc_blame] alg_equiv.to_add_equiv attribute [nolint doc_blame] alg_equiv.to_mul_equiv notation A ` ≃ₐ[`:50 R `] ` A' := alg_equiv R A A' namespace alg_equiv variables {R : Type u} {A₁ : Type v} {Aβ‚‚ : Type w} {A₃ : Type u₁} section semiring variables [comm_semiring R] [semiring A₁] [semiring Aβ‚‚] [semiring A₃] variables [algebra R A₁] [algebra R Aβ‚‚] [algebra R A₃] variables (e : A₁ ≃ₐ[R] Aβ‚‚) instance : has_coe_to_fun (A₁ ≃ₐ[R] Aβ‚‚) := ⟨_, alg_equiv.to_fun⟩ @[ext] lemma ext {f g : A₁ ≃ₐ[R] Aβ‚‚} (h : βˆ€ a, f a = g a) : f = g := begin have h₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end protected lemma congr_arg {f : A₁ ≃ₐ[R] Aβ‚‚} : Ξ  {x x' : A₁}, x = x' β†’ f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : A₁ ≃ₐ[R] Aβ‚‚} (h : f = g) (x : A₁) : f x = g x := h β–Έ rfl lemma ext_iff {f g : A₁ ≃ₐ[R] Aβ‚‚} : f = g ↔ βˆ€ x, f x = g x := ⟨λ h x, h β–Έ rfl, ext⟩ lemma coe_fun_injective : @function.injective (A₁ ≃ₐ[R] Aβ‚‚) (A₁ β†’ Aβ‚‚) (Ξ» e, (e : A₁ β†’ Aβ‚‚)) := begin intros f g w, ext, exact congr_fun w a, end instance has_coe_to_ring_equiv : has_coe (A₁ ≃ₐ[R] Aβ‚‚) (A₁ ≃+* Aβ‚‚) := ⟨alg_equiv.to_ring_equiv⟩ @[simp] lemma mk_apply {to_fun inv_fun left_inv right_inv map_mul map_add commutes a} : (⟨to_fun, inv_fun, left_inv, right_inv, map_mul, map_add, commutes⟩ : A₁ ≃ₐ[R] Aβ‚‚) a = to_fun a := rfl @[simp] lemma to_fun_apply {e : A₁ ≃ₐ[R] Aβ‚‚} {a : A₁} : e.to_fun a = e a := rfl @[simp, norm_cast] lemma coe_ring_equiv : ((e : A₁ ≃+* Aβ‚‚) : A₁ β†’ Aβ‚‚) = e := rfl lemma coe_ring_equiv_injective : function.injective (Ξ» e : A₁ ≃ₐ[R] Aβ‚‚, (e : A₁ ≃+* Aβ‚‚)) := begin intros f g w, ext, replace w : ((f : A₁ ≃+* Aβ‚‚) : A₁ β†’ Aβ‚‚) = ((g : A₁ ≃+* Aβ‚‚) : A₁ β†’ Aβ‚‚) := congr_arg (Ξ» e : A₁ ≃+* Aβ‚‚, (e : A₁ β†’ Aβ‚‚)) w, exact congr_fun w a, end @[simp] lemma map_add : βˆ€ x y, e (x + y) = e x + e y := e.to_add_equiv.map_add @[simp] lemma map_zero : e 0 = 0 := e.to_add_equiv.map_zero @[simp] lemma map_mul : βˆ€ x y, e (x * y) = (e x) * (e y) := e.to_mul_equiv.map_mul @[simp] lemma map_one : e 1 = 1 := e.to_mul_equiv.map_one @[simp] lemma commutes : βˆ€ (r : R), e (algebra_map R A₁ r) = algebra_map R Aβ‚‚ r := e.commutes' lemma map_sum {ΞΉ : Type*} (f : ΞΉ β†’ A₁) (s : finset ΞΉ) : e (βˆ‘ x in s, f x) = βˆ‘ x in s, e (f x) := e.to_add_equiv.map_sum f s lemma map_finsupp_sum {Ξ± : Type*} [has_zero Ξ±] {ΞΉ : Type*} (f : ΞΉ β†’β‚€ Ξ±) (g : ΞΉ β†’ Ξ± β†’ A₁) : e (f.sum g) = f.sum (Ξ» i b, e (g i b)) := e.map_sum _ _ /-- Interpret an algebra equivalence as an algebra homomorphism. This definition is included for symmetry with the other `to_*_hom` projections. The `simp` normal form is to use the coercion of the `has_coe_to_alg_hom` instance. -/ def to_alg_hom : A₁ →ₐ[R] Aβ‚‚ := { map_one' := e.map_one, map_zero' := e.map_zero, ..e } instance has_coe_to_alg_hom : has_coe (A₁ ≃ₐ[R] Aβ‚‚) (A₁ →ₐ[R] Aβ‚‚) := ⟨to_alg_hom⟩ @[simp] lemma to_alg_hom_eq_coe : e.to_alg_hom = e := rfl @[simp, norm_cast] lemma coe_alg_hom : ((e : A₁ →ₐ[R] Aβ‚‚) : A₁ β†’ Aβ‚‚) = e := rfl @[simp] lemma map_pow : βˆ€ (x : A₁) (n : β„•), e (x ^ n) = (e x) ^ n := e.to_alg_hom.map_pow lemma injective : function.injective e := e.to_equiv.injective lemma surjective : function.surjective e := e.to_equiv.surjective lemma bijective : function.bijective e := e.to_equiv.bijective instance : has_one (A₁ ≃ₐ[R] A₁) := ⟨{commutes' := Ξ» r, rfl, ..(1 : A₁ ≃+* A₁)}⟩ instance : inhabited (A₁ ≃ₐ[R] A₁) := ⟨1⟩ /-- Algebra equivalences are reflexive. -/ @[refl] def refl : A₁ ≃ₐ[R] A₁ := 1 @[simp] lemma coe_refl : (@refl R A₁ _ _ _ : A₁ →ₐ[R] A₁) = alg_hom.id R A₁ := alg_hom.ext (Ξ» x, rfl) /-- Algebra equivalences are symmetric. -/ @[symm] def symm (e : A₁ ≃ₐ[R] Aβ‚‚) : Aβ‚‚ ≃ₐ[R] A₁ := { commutes' := Ξ» r, by { rw ←e.to_ring_equiv.symm_apply_apply (algebra_map R A₁ r), congr, change _ = e _, rw e.commutes, }, ..e.to_ring_equiv.symm, } /-- See Note [custom simps projection] -/ def simps.inv_fun (e : A₁ ≃ₐ[R] Aβ‚‚) : Aβ‚‚ β†’ A₁ := e.symm initialize_simps_projections alg_equiv (to_fun β†’ apply, inv_fun β†’ symm_apply) @[simp] lemma inv_fun_apply {e : A₁ ≃ₐ[R] Aβ‚‚} {a : Aβ‚‚} : e.inv_fun a = e.symm a := rfl @[simp] lemma symm_symm {e : A₁ ≃ₐ[R] Aβ‚‚} : e.symm.symm = e := by { ext, refl, } /-- Algebra equivalences are transitive. -/ @[trans] def trans (e₁ : A₁ ≃ₐ[R] Aβ‚‚) (eβ‚‚ : Aβ‚‚ ≃ₐ[R] A₃) : A₁ ≃ₐ[R] A₃ := { commutes' := Ξ» r, show eβ‚‚.to_fun (e₁.to_fun _) = _, by rw [e₁.commutes', eβ‚‚.commutes'], ..(e₁.to_ring_equiv.trans eβ‚‚.to_ring_equiv), } @[simp] lemma apply_symm_apply (e : A₁ ≃ₐ[R] Aβ‚‚) : βˆ€ x, e (e.symm x) = x := e.to_equiv.apply_symm_apply @[simp] lemma symm_apply_apply (e : A₁ ≃ₐ[R] Aβ‚‚) : βˆ€ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply @[simp] lemma trans_apply (e₁ : A₁ ≃ₐ[R] Aβ‚‚) (eβ‚‚ : Aβ‚‚ ≃ₐ[R] A₃) (x : A₁) : (e₁.trans eβ‚‚) x = eβ‚‚ (e₁ x) := rfl @[simp] lemma comp_symm (e : A₁ ≃ₐ[R] Aβ‚‚) : alg_hom.comp (e : A₁ →ₐ[R] Aβ‚‚) ↑e.symm = alg_hom.id R Aβ‚‚ := by { ext, simp } @[simp] lemma symm_comp (e : A₁ ≃ₐ[R] Aβ‚‚) : alg_hom.comp ↑e.symm (e : A₁ →ₐ[R] Aβ‚‚) = alg_hom.id R A₁ := by { ext, simp } /-- If `A₁` is equivalent to `A₁'` and `Aβ‚‚` is equivalent to `Aβ‚‚'`, then the type of maps `A₁ →ₐ[R] Aβ‚‚` is equivalent to the type of maps `A₁' →ₐ[R] Aβ‚‚'`. -/ def arrow_congr {A₁' Aβ‚‚' : Type*} [semiring A₁'] [semiring Aβ‚‚'] [algebra R A₁'] [algebra R Aβ‚‚'] (e₁ : A₁ ≃ₐ[R] A₁') (eβ‚‚ : Aβ‚‚ ≃ₐ[R] Aβ‚‚') : (A₁ →ₐ[R] Aβ‚‚) ≃ (A₁' →ₐ[R] Aβ‚‚') := { to_fun := Ξ» f, (eβ‚‚.to_alg_hom.comp f).comp e₁.symm.to_alg_hom, inv_fun := Ξ» f, (eβ‚‚.symm.to_alg_hom.comp f).comp e₁.to_alg_hom, left_inv := Ξ» f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, symm_comp], simp only [←alg_hom.comp_assoc, symm_comp, alg_hom.id_comp, alg_hom.comp_id] }, right_inv := Ξ» f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, comp_symm], simp only [←alg_hom.comp_assoc, comp_symm, alg_hom.id_comp, alg_hom.comp_id] } } lemma arrow_congr_comp {A₁' Aβ‚‚' A₃' : Type*} [semiring A₁'] [semiring Aβ‚‚'] [semiring A₃'] [algebra R A₁'] [algebra R Aβ‚‚'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] A₁') (eβ‚‚ : Aβ‚‚ ≃ₐ[R] Aβ‚‚') (e₃ : A₃ ≃ₐ[R] A₃') (f : A₁ →ₐ[R] Aβ‚‚) (g : Aβ‚‚ →ₐ[R] A₃) : arrow_congr e₁ e₃ (g.comp f) = (arrow_congr eβ‚‚ e₃ g).comp (arrow_congr e₁ eβ‚‚ f) := by { ext, simp only [arrow_congr, equiv.coe_fn_mk, alg_hom.comp_apply], congr, exact (eβ‚‚.symm_apply_apply _).symm } @[simp] lemma arrow_congr_refl : arrow_congr alg_equiv.refl alg_equiv.refl = equiv.refl (A₁ →ₐ[R] Aβ‚‚) := by { ext, refl } @[simp] lemma arrow_congr_trans {A₁' Aβ‚‚' A₃' : Type*} [semiring A₁'] [semiring Aβ‚‚'] [semiring A₃'] [algebra R A₁'] [algebra R Aβ‚‚'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] Aβ‚‚) (e₁' : A₁' ≃ₐ[R] Aβ‚‚') (eβ‚‚ : Aβ‚‚ ≃ₐ[R] A₃) (eβ‚‚' : Aβ‚‚' ≃ₐ[R] A₃') : arrow_congr (e₁.trans eβ‚‚) (e₁'.trans eβ‚‚') = (arrow_congr e₁ e₁').trans (arrow_congr eβ‚‚ eβ‚‚') := by { ext, refl } @[simp] lemma arrow_congr_symm {A₁' Aβ‚‚' : Type*} [semiring A₁'] [semiring Aβ‚‚'] [algebra R A₁'] [algebra R Aβ‚‚'] (e₁ : A₁ ≃ₐ[R] A₁') (eβ‚‚ : Aβ‚‚ ≃ₐ[R] Aβ‚‚') : (arrow_congr e₁ eβ‚‚).symm = arrow_congr e₁.symm eβ‚‚.symm := by { ext, refl } /-- If an algebra morphism has an inverse, it is a algebra isomorphism. -/ def of_alg_hom (f : A₁ →ₐ[R] Aβ‚‚) (g : Aβ‚‚ →ₐ[R] A₁) (h₁ : f.comp g = alg_hom.id R Aβ‚‚) (hβ‚‚ : g.comp f = alg_hom.id R A₁) : A₁ ≃ₐ[R] Aβ‚‚ := { inv_fun := g, left_inv := alg_hom.ext_iff.1 hβ‚‚, right_inv := alg_hom.ext_iff.1 h₁, ..f } /-- Promotes a bijective algebra homomorphism to an algebra equivalence. -/ noncomputable def of_bijective (f : A₁ →ₐ[R] Aβ‚‚) (hf : function.bijective f) : A₁ ≃ₐ[R] Aβ‚‚ := { .. ring_equiv.of_bijective (f : A₁ β†’+* Aβ‚‚) hf, .. f } /-- Forgetting the multiplicative structures, an equivalence of algebras is a linear equivalence. -/ def to_linear_equiv (e : A₁ ≃ₐ[R] Aβ‚‚) : A₁ ≃ₗ[R] Aβ‚‚ := { to_fun := e.to_fun, map_add' := Ξ» x y, by simp, map_smul' := Ξ» r x, by simp [algebra.smul_def''], inv_fun := e.symm.to_fun, left_inv := e.left_inv, right_inv := e.right_inv, } @[simp] lemma to_linear_equiv_apply (e : A₁ ≃ₐ[R] Aβ‚‚) (x : A₁) : e.to_linear_equiv x = e x := rfl theorem to_linear_equiv_inj {e₁ eβ‚‚ : A₁ ≃ₐ[R] Aβ‚‚} (H : e₁.to_linear_equiv = eβ‚‚.to_linear_equiv) : e₁ = eβ‚‚ := ext $ Ξ» x, show e₁.to_linear_equiv x = eβ‚‚.to_linear_equiv x, by rw H /-- Interpret an algebra equivalence as a linear map. -/ def to_linear_map : A₁ β†’β‚—[R] Aβ‚‚ := e.to_alg_hom.to_linear_map @[simp] lemma to_alg_hom_to_linear_map : (e : A₁ →ₐ[R] Aβ‚‚).to_linear_map = e.to_linear_map := rfl @[simp] lemma to_linear_equiv_to_linear_map : e.to_linear_equiv.to_linear_map = e.to_linear_map := rfl @[simp] lemma to_linear_map_apply (x : A₁) : e.to_linear_map x = e x := rfl theorem to_linear_map_inj {e₁ eβ‚‚ : A₁ ≃ₐ[R] Aβ‚‚} (H : e₁.to_linear_map = eβ‚‚.to_linear_map) : e₁ = eβ‚‚ := ext $ Ξ» x, show e₁.to_linear_map x = eβ‚‚.to_linear_map x, by rw H @[simp] lemma trans_to_linear_map (f : A₁ ≃ₐ[R] Aβ‚‚) (g : Aβ‚‚ ≃ₐ[R] A₃) : (f.trans g).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl instance aut : group (A₁ ≃ₐ[R] A₁) := { mul := Ξ» Ο• ψ, ψ.trans Ο•, mul_assoc := Ξ» Ο• ψ Ο‡, rfl, one := 1, one_mul := Ξ» Ο•, by { ext, refl }, mul_one := Ξ» Ο•, by { ext, refl }, inv := symm, mul_left_inv := Ξ» Ο•, by { ext, exact symm_apply_apply Ο• a } } end semiring section comm_semiring variables [comm_semiring R] [comm_semiring A₁] [comm_semiring Aβ‚‚] variables [algebra R A₁] [algebra R Aβ‚‚] (e : A₁ ≃ₐ[R] Aβ‚‚) lemma map_prod {ΞΉ : Type*} (f : ΞΉ β†’ A₁) (s : finset ΞΉ) : e (∏ x in s, f x) = ∏ x in s, e (f x) := e.to_alg_hom.map_prod f s lemma map_finsupp_prod {Ξ± : Type*} [has_zero Ξ±] {ΞΉ : Type*} (f : ΞΉ β†’β‚€ Ξ±) (g : ΞΉ β†’ Ξ± β†’ A₁) : e (f.prod g) = f.prod (Ξ» i a, e (g i a)) := e.to_alg_hom.map_finsupp_prod f g end comm_semiring section ring variables [comm_ring R] [ring A₁] [ring Aβ‚‚] variables [algebra R A₁] [algebra R Aβ‚‚] (e : A₁ ≃ₐ[R] Aβ‚‚) @[simp] lemma map_neg (x) : e (-x) = -e x := e.to_alg_hom.map_neg x @[simp] lemma map_sub (x y) : e (x - y) = e x - e y := e.to_alg_hom.map_sub x y end ring section division_ring variables [comm_ring R] [division_ring A₁] [division_ring Aβ‚‚] variables [algebra R A₁] [algebra R Aβ‚‚] (e : A₁ ≃ₐ[R] Aβ‚‚) @[simp] lemma map_inv (x) : e (x⁻¹) = (e x)⁻¹ := e.to_alg_hom.map_inv x @[simp] lemma map_div (x y) : e (x / y) = e x / e y := e.to_alg_hom.map_div x y end division_ring end alg_equiv namespace matrix /-! ### `matrix` section Specialize `matrix.one_map` and `matrix.zero_map` to `alg_hom` and `alg_equiv`. TODO: there should be a way to avoid restating these for each `foo_hom`. -/ variables {R A₁ Aβ‚‚ n : Type*} [fintype n] section semiring variables [comm_semiring R] [semiring A₁] [algebra R A₁] [semiring Aβ‚‚] [algebra R Aβ‚‚] /-- A version of `matrix.one_map` where `f` is an `alg_hom`. -/ @[simp] lemma alg_hom_map_one [decidable_eq n] (f : A₁ →ₐ[R] Aβ‚‚) : (1 : matrix n n A₁).map f = 1 := one_map f.map_zero f.map_one /-- A version of `matrix.one_map` where `f` is an `alg_equiv`. -/ @[simp] lemma alg_equiv_map_one [decidable_eq n] (f : A₁ ≃ₐ[R] Aβ‚‚) : (1 : matrix n n A₁).map f = 1 := one_map f.map_zero f.map_one /-- A version of `matrix.zero_map` where `f` is an `alg_hom`. -/ @[simp] lemma alg_hom_map_zero (f : A₁ →ₐ[R] Aβ‚‚) : (0 : matrix n n A₁).map f = 0 := map_zero f.map_zero /-- A version of `matrix.zero_map` where `f` is an `alg_equiv`. -/ @[simp] lemma alg_equiv_map_zero (f : A₁ ≃ₐ[R] Aβ‚‚) : (0 : matrix n n A₁).map f = 0 := map_zero f.map_zero end semiring end matrix namespace algebra variables (R : Type u) (S : Type v) (A : Type w) include R S A /-- `comap R S A` is a type alias for `A`, and has an R-algebra structure defined on it when `algebra R S` and `algebra S A`. If `S` is an `R`-algebra and `A` is an `S`-algebra then `algebra.comap.algebra R S A` can be used to provide `A` with a structure of an `R`-algebra. Other than that, `algebra.comap` is now deprecated and replaced with `is_scalar_tower`. -/ /- This is done to avoid a type class search with meta-variables `algebra R ?m_1` and `algebra ?m_1 A -/ /- The `nolint` attribute is added because it has unused arguments `R` and `S`, but these are necessary for synthesizing the appropriate type classes -/ @[nolint unused_arguments] def comap : Type w := A instance comap.inhabited [h : inhabited A] : inhabited (comap R S A) := h instance comap.semiring [h : semiring A] : semiring (comap R S A) := h instance comap.ring [h : ring A] : ring (comap R S A) := h instance comap.comm_semiring [h : comm_semiring A] : comm_semiring (comap R S A) := h instance comap.comm_ring [h : comm_ring A] : comm_ring (comap R S A) := h instance comap.algebra' [comm_semiring S] [semiring A] [h : algebra S A] : algebra S (comap R S A) := h /-- Identity homomorphism `A →ₐ[S] comap R S A`. -/ def comap.to_comap [comm_semiring S] [semiring A] [algebra S A] : A →ₐ[S] comap R S A := alg_hom.id S A /-- Identity homomorphism `comap R S A →ₐ[S] A`. -/ def comap.of_comap [comm_semiring S] [semiring A] [algebra S A] : comap R S A →ₐ[S] A := alg_hom.id S A variables [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] /-- `R ⟢ S` induces `S-Alg β₯€ R-Alg` -/ instance comap.algebra : algebra R (comap R S A) := { smul := Ξ» r x, (algebra_map R S r β€’ x : A), commutes' := Ξ» r x, algebra.commutes _ _, smul_def' := Ξ» _ _, algebra.smul_def _ _, .. (algebra_map S A).comp (algebra_map R S) } /-- Embedding of `S` into `comap R S A`. -/ def to_comap : S →ₐ[R] comap R S A := { commutes' := Ξ» r, rfl, .. algebra_map S A } theorem to_comap_apply (x) : to_comap R S A x = algebra_map S A x := rfl end algebra namespace alg_hom variables {R : Type u} {S : Type v} {A : Type w} {B : Type u₁} variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] variables [algebra R S] [algebra S A] [algebra S B] (Ο† : A →ₐ[S] B) include R /-- R ⟢ S induces S-Alg β₯€ R-Alg -/ def comap : algebra.comap R S A →ₐ[R] algebra.comap R S B := { commutes' := Ξ» r, Ο†.commutes (algebra_map R S r) ..Ο† } end alg_hom namespace rat instance algebra_rat {Ξ±} [division_ring Ξ±] [char_zero Ξ±] : algebra β„š Ξ± := (rat.cast_hom Ξ±).to_algebra' $ Ξ» r x, r.cast_commute x end rat namespace algebra open module variables (R : Type u) (A : Type v) variables [comm_semiring R] [semiring A] [algebra R A] /-- `algebra_map` as an `alg_hom`. -/ def of_id : R →ₐ[R] A := { commutes' := Ξ» _, rfl, .. algebra_map R A } variables {R} theorem of_id_apply (r) : of_id R A r = algebra_map R A r := rfl variables (R A) /-- The multiplication in an algebra is a bilinear map. -/ def lmul : A →ₐ[R] (End R A) := { map_one' := by { ext a, exact one_mul a }, map_mul' := by { intros a b, ext c, exact mul_assoc a b c }, map_zero' := by { ext a, exact zero_mul a }, commutes' := by { intro r, ext a, dsimp, rw [smul_def] }, .. (show A β†’β‚—[R] A β†’β‚—[R] A, from linear_map.mkβ‚‚ R (*) (Ξ» x y z, add_mul x y z) (Ξ» c x y, by rw [smul_def, smul_def, mul_assoc _ x y]) (Ξ» x y z, mul_add x y z) (Ξ» c x y, by rw [smul_def, smul_def, left_comm])) } variables {A} /-- The multiplication on the left in an algebra is a linear map. -/ def lmul_left (r : A) : A β†’β‚— A := lmul R A r /-- The multiplication on the right in an algebra is a linear map. -/ def lmul_right (r : A) : A β†’β‚— A := (lmul R A).to_linear_map.flip r /-- Simultaneous multiplication on the left and right is a linear map. -/ def lmul_left_right (vw: A Γ— A) : A β†’β‚—[R] A := (lmul_right R vw.2).comp (lmul_left R vw.1) /-- The multiplication map on an algebra, as an `R`-linear map from `A βŠ—[R] A` to `A`. -/ def lmul' : A βŠ—[R] A β†’β‚—[R] A := tensor_product.lift (lmul R A).to_linear_map variables {R A} @[simp] lemma lmul_apply (p q : A) : lmul R A p q = p * q := rfl @[simp] lemma lmul_left_apply (p q : A) : lmul_left R p q = p * q := rfl @[simp] lemma lmul_right_apply (p q : A) : lmul_right R p q = q * p := rfl @[simp] lemma lmul_left_right_apply (vw : A Γ— A) (p : A) : lmul_left_right R vw p = vw.1 * p * vw.2 := rfl @[simp] lemma lmul_left_one : lmul_left R (1:A) = linear_map.id := by { ext, simp only [linear_map.id_coe, one_mul, id.def, lmul_left_apply] } @[simp] lemma lmul_left_mul (a b : A) : lmul_left R (a * b) = (lmul_left R a).comp (lmul_left R b) := by { ext, simp only [lmul_left_apply, linear_map.comp_apply, mul_assoc] } @[simp] lemma lmul_right_one : lmul_right R (1:A) = linear_map.id := by { ext, simp only [linear_map.id_coe, mul_one, id.def, lmul_right_apply] } @[simp] lemma lmul_right_mul (a b : A) : lmul_right R (a * b) = (lmul_right R b).comp (lmul_right R a) := by { ext, simp only [lmul_right_apply, linear_map.comp_apply, mul_assoc] } @[simp] lemma lmul'_apply {x y : A} : lmul' R (x βŠ—β‚œ y) = x * y := by simp only [algebra.lmul', tensor_product.lift.tmul, alg_hom.to_linear_map_apply, lmul_apply] instance linear_map.semimodule' (R : Type u) [comm_semiring R] (M : Type v) [add_comm_monoid M] [semimodule R M] (S : Type w) [comm_semiring S] [algebra R S] : semimodule S (M β†’β‚—[R] S) := { smul := Ξ» s f, linear_map.llcomp _ _ _ _ (algebra.lmul R S s) f, one_smul := Ξ» f, linear_map.ext $ Ξ» x, one_mul _, mul_smul := Ξ» s₁ sβ‚‚ f, linear_map.ext $ Ξ» x, mul_assoc _ _ _, smul_add := Ξ» s f g, linear_map.map_add _ _ _, smul_zero := Ξ» s, linear_map.map_zero _, add_smul := Ξ» s₁ sβ‚‚ f, linear_map.ext $ Ξ» x, add_mul _ _ _, zero_smul := Ξ» f, linear_map.ext $ Ξ» x, zero_mul _ } end algebra section nat variables (R : Type*) [semiring R] /-- Reinterpret a `ring_hom` as an `β„•`-algebra homomorphism. -/ def alg_hom_nat {R : Type u} [semiring R] [algebra β„• R] {S : Type v} [semiring S] [algebra β„• S] (f : R β†’+* S) : R →ₐ[β„•] S := { commutes' := Ξ» i, show f _ = _, by simp, .. f } /-- Semiring β₯€ β„•-Alg -/ instance algebra_nat : algebra β„• R := { commutes' := nat.cast_commute, smul_def' := Ξ» _ _, nsmul_eq_mul _ _, .. nat.cast_ring_hom R } section span_nat open submodule lemma span_nat_eq_add_group_closure (s : set R) : (span β„• s).to_add_submonoid = add_submonoid.closure s := eq.symm $ add_submonoid.closure_eq_of_le subset_span $ Ξ» x hx, span_induction hx (Ξ» x hx, add_submonoid.subset_closure hx) (add_submonoid.zero_mem _) (Ξ» _ _, add_submonoid.add_mem _) (Ξ» _ _ _, add_submonoid.nsmul_mem _ β€Ή_β€Ί _) @[simp] lemma span_nat_eq (s : add_submonoid R) : (span β„• (s : set R)).to_add_submonoid = s := by rw [span_nat_eq_add_group_closure, s.closure_eq] end span_nat end nat section int variables (R : Type*) [ring R] /-- Reinterpret a `ring_hom` as a `β„€`-algebra homomorphism. -/ def alg_hom_int {R : Type u} [comm_ring R] [algebra β„€ R] {S : Type v} [comm_ring S] [algebra β„€ S] (f : R β†’+* S) : R →ₐ[β„€] S := { commutes' := Ξ» i, show f _ = _, by simp, .. f } /-- Ring β₯€ β„€-Alg -/ instance algebra_int : algebra β„€ R := { commutes' := int.cast_commute, smul_def' := Ξ» _ _, gsmul_eq_mul _ _, .. int.cast_ring_hom R } /-- Promote a ring homomorphisms to a `β„€`-algebra homomorphism. -/ def ring_hom.to_int_alg_hom {R S : Type*} [ring R] [ring S] (f : R β†’+* S) : R →ₐ[β„€] S := { commutes' := Ξ» n, by simp, .. f } variables {R} section variables {S : Type*} [ring S] instance int_algebra_subsingleton : subsingleton (algebra β„€ S) := ⟨λ P Q, by { ext, simp, }⟩ end section variables {S : Type*} [semiring S] instance nat_algebra_subsingleton : subsingleton (algebra β„• S) := ⟨λ P Q, by { ext, simp, }⟩ end section span_int open submodule lemma span_int_eq_add_group_closure (s : set R) : (span β„€ s).to_add_subgroup = add_subgroup.closure s := eq.symm $ add_subgroup.closure_eq_of_le _ subset_span $ Ξ» x hx, span_induction hx (Ξ» x hx, add_subgroup.subset_closure hx) (add_subgroup.zero_mem _) (Ξ» _ _, add_subgroup.add_mem _) (Ξ» _ _ _, add_subgroup.gsmul_mem _ β€Ή_β€Ί _) @[simp] lemma span_int_eq (s : add_subgroup R) : (span β„€ (s : set R)).to_add_subgroup = s := by rw [span_int_eq_add_group_closure, s.closure_eq] end span_int end int /-! The R-algebra structure on `Ξ  i : I, A i` when each `A i` is an R-algebra. We couldn't set this up back in `algebra.pi_instances` because this file imports it. -/ namespace pi variable {I : Type u} -- The indexing type variable {f : I β†’ Type v} -- The family of types already equipped with instances variables (x y : Ξ  i, f i) (i : I) variables (I f) instance algebra (Ξ±) {r : comm_semiring Ξ±} [s : βˆ€ i, semiring (f i)] [βˆ€ i, algebra Ξ± (f i)] : algebra Ξ± (Ξ  i : I, f i) := { commutes' := Ξ» a f, begin ext, simp [algebra.commutes], end, smul_def' := Ξ» a f, begin ext, simp [algebra.smul_def''], end, ..pi.ring_hom (Ξ» i, algebra_map Ξ± (f i)) } @[simp] lemma algebra_map_apply (Ξ±) {r : comm_semiring Ξ±} [s : βˆ€ i, semiring (f i)] [βˆ€ i, algebra Ξ± (f i)] (a : Ξ±) (i : I) : algebra_map Ξ± (Ξ  i, f i) a i = algebra_map Ξ± (f i) a := rfl -- One could also build a `Ξ  i, R i`-algebra structure on `Ξ  i, A i`, -- when each `A i` is an `R i`-algebra, although I'm not sure that it's useful. end pi section is_scalar_tower variables {R : Type*} [comm_semiring R] variables (A : Type*) [semiring A] [algebra R A] variables {M : Type*} [add_comm_monoid M] [semimodule A M] [semimodule R M] [is_scalar_tower R A M] variables {N : Type*} [add_comm_monoid N] [semimodule A N] [semimodule R N] [is_scalar_tower R A N] lemma algebra_compatible_smul (r : R) (m : M) : r β€’ m = ((algebra_map R A) r) β€’ m := by rw [←(one_smul A m), ←smul_assoc, algebra.smul_def, mul_one, one_smul] @[simp] lemma algebra_map_smul (r : R) (m : M) : ((algebra_map R A) r) β€’ m = r β€’ m := (algebra_compatible_smul A r m).symm variable {A} @[priority 100] -- see Note [lower instance priority] instance is_scalar_tower.to_smul_comm_class : smul_comm_class R A M := ⟨λ r a m, by rw [algebra_compatible_smul A r (a β€’ m), smul_smul, algebra.commutes, mul_smul, ←algebra_compatible_smul]⟩ @[priority 100] -- see Note [lower instance priority] instance is_scalar_tower.to_smul_comm_class' : smul_comm_class A R M := smul_comm_class.symm _ _ _ lemma smul_algebra_smul_comm (r : R) (a : A) (m : M) : a β€’ r β€’ m = r β€’ a β€’ m := smul_comm _ _ _ namespace linear_map instance coe_is_scalar_tower : has_coe (M β†’β‚—[A] N) (M β†’β‚—[R] N) := ⟨restrict_scalars R⟩ variables (R) {A M N} @[simp, norm_cast squash] lemma coe_restrict_scalars_eq_coe (f : M β†’β‚—[A] N) : (f.restrict_scalars R : M β†’ N) = f := rfl @[simp, norm_cast squash] lemma coe_coe_is_scalar_tower (f : M β†’β‚—[A] N) : ((f : M β†’β‚—[R] N) : M β†’ N) = f := rfl /-- `A`-linearly coerce a `R`-linear map from `M` to `A` to a function, given an algebra `A` over a commutative semiring `R` and `M` a semimodule over `R`. -/ def lto_fun (R : Type u) (M : Type v) (A : Type w) [comm_semiring R] [add_comm_monoid M] [semimodule R M] [comm_ring A] [algebra R A] : (M β†’β‚—[R] A) β†’β‚—[A] (M β†’ A) := { to_fun := linear_map.to_fun, map_add' := Ξ» f g, rfl, map_smul' := Ξ» c f, rfl } end linear_map end is_scalar_tower section restrict_scalars /- In this section, we describe restriction of scalars: if `S` is an algebra over `R`, then `S`-modules are also `R`-modules. -/ section type_synonym variables (R A M : Type*) /-- Warning: use this type synonym judiciously! The preferred way of working with an `A`-module `M` as `R`-module (where `A` is an `R`-algebra), is by `[module R M] [module A M] [is_scalar_tower R A M]`. When `M` is a module over a ring `A`, and `A` is an algebra over `R`, then `M` inherits a module structure over `R`, provided as a type synonym `module.restrict_scalars R A M := M`. -/ @[nolint unused_arguments] def restrict_scalars (R A M : Type*) : Type* := M instance [I : inhabited M] : inhabited (restrict_scalars R A M) := I instance [I : add_comm_monoid M] : add_comm_monoid (restrict_scalars R A M) := I instance [I : add_comm_group M] : add_comm_group (restrict_scalars R A M) := I instance restrict_scalars.module_orig [semiring A] [add_comm_monoid M] [I : semimodule A M] : semimodule A (restrict_scalars R A M) := I variables [comm_semiring R] [semiring A] [algebra R A] variables [add_comm_monoid M] [semimodule A M] /-- When `M` is a module over a ring `A`, and `A` is an algebra over `R`, then `M` inherits a module structure over `R`. The preferred way of setting this up is `[module R M] [module A M] [is_scalar_tower R A M]`. -/ instance : semimodule R (restrict_scalars R A M) := { smul := Ξ» c x, (algebra_map R A c) β€’ x, one_smul := by simp, mul_smul := by simp [mul_smul], smul_add := by simp [smul_add], smul_zero := by simp [smul_zero], add_smul := by simp [add_smul], zero_smul := by simp [zero_smul] } lemma restrict_scalars_smul_def (c : R) (x : restrict_scalars R A M) : c β€’ x = ((algebra_map R A c) β€’ x : M) := rfl instance : is_scalar_tower R A (restrict_scalars R A M) := ⟨λ r A M, by { rw [algebra.smul_def, mul_smul], refl }⟩ instance submodule.restricted_module (V : submodule A M) : semimodule R V := restrict_scalars.semimodule R A V instance submodule.restricted_module_is_scalar_tower (V : submodule A M) : is_scalar_tower R A V := restrict_scalars.is_scalar_tower R A V end type_synonym section semimodule open semimodule variables (R A M N : Type*) [comm_semiring R] [semiring A] [algebra R A] variables [add_comm_monoid M] [semimodule R M] [semimodule A M] [is_scalar_tower R A M] variables [add_comm_monoid N] [semimodule R N] [semimodule A N] [is_scalar_tower R A N] variables {A M N} namespace submodule /-- `V.restrict_scalars R` is the `R`-submodule of the `R`-module given by restriction of scalars, corresponding to `V`, an `S`-submodule of the original `S`-module. -/ @[simps] def restrict_scalars (V : submodule A M) : submodule R M := { carrier := V.carrier, zero_mem' := V.zero_mem, smul_mem' := Ξ» c m h, by { rw algebra_compatible_smul A c m, exact V.smul_mem _ h }, add_mem' := Ξ» x y hx hy, V.add_mem hx hy } @[simp] lemma restrict_scalars_mem (V : submodule A M) (m : M) : m ∈ V.restrict_scalars R ↔ m ∈ V := iff.refl _ variables (R A M) lemma restrict_scalars_injective : function.injective (restrict_scalars R : submodule A M β†’ submodule R M) := Ξ» V₁ Vβ‚‚ h, ext $ by convert set.ext_iff.1 (ext'_iff.1 h); refl @[simp] lemma restrict_scalars_inj {V₁ Vβ‚‚ : submodule A M} : restrict_scalars R V₁ = restrict_scalars R Vβ‚‚ ↔ V₁ = Vβ‚‚ := ⟨λ h, restrict_scalars_injective R _ _ h, congr_arg _⟩ @[simp] lemma restrict_scalars_bot : restrict_scalars R (βŠ₯ : submodule A M) = βŠ₯ := rfl @[simp] lemma restrict_scalars_top : restrict_scalars R (⊀ : submodule A M) = ⊀ := rfl end submodule @[simp] lemma linear_map.ker_restrict_scalars (f : M β†’β‚—[A] N) : (f.restrict_scalars R).ker = submodule.restrict_scalars R f.ker := rfl end semimodule end restrict_scalars namespace linear_map section extend_scalars /-! When `V` is an `R`-module and `W` is an `S`-module, where `S` is an algebra over `R`, then the collection of `R`-linear maps from `V` to `W` admits an `S`-module structure, given by multiplication in the target. -/ variables (R : Type*) [comm_semiring R] (S : Type*) [semiring S] [algebra R S] (V : Type*) [add_comm_monoid V] [semimodule R V] (W : Type*) [add_comm_monoid W] [semimodule R W] [semimodule S W] [is_scalar_tower R S W] instance is_scalar_tower_extend_scalars : is_scalar_tower R S (V β†’β‚—[R] W) := { smul_assoc := Ξ» r s f, by simp only [(β€’), coe_mk, smul_assoc] } variables {R S V W} /-- When `f` is a linear map taking values in `S`, then `Ξ»b, f b β€’ x` is a linear map. -/ def smul_algebra_right (f : V β†’β‚—[R] S) (x : W) : V β†’β‚—[R] W := { to_fun := Ξ»b, f b β€’ x, map_add' := by simp [add_smul], map_smul' := Ξ» b y, by { simp [algebra.smul_def, ← smul_smul], } } @[simp] theorem smul_algebra_right_apply (f : V β†’β‚—[R] S) (x : W) (c : V) : smul_algebra_right f x c = f c β€’ x := rfl end extend_scalars end linear_map
698601419c9366b1355666dbaa018fb5a5401593
94e33a31faa76775069b071adea97e86e218a8ee
/src/ring_theory/adjoin/basic.lean
51357c46d4265824fff45be76a293cf5b86892ab
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
14,773
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.algebra.tower import linear_algebra.prod import linear_algebra.finsupp import algebra.algebra.operations /-! # Adjoining elements to form subalgebras This file develops the basic theory of subalgebras of an R-algebra generated by a set of elements. A basic interface for `adjoin` is set up. ## Tags adjoin, algebra -/ universes u v w open_locale pointwise open submodule subsemiring variables {R : Type u} {A : Type v} {B : Type w} namespace algebra section semiring variables [comm_semiring R] [semiring A] [semiring B] variables [algebra R A] [algebra R B] {s t : set A} theorem subset_adjoin : s βŠ† adjoin R s := algebra.gc.le_u_l s theorem adjoin_le {S : subalgebra R A} (H : s βŠ† S) : adjoin R s ≀ S := algebra.gc.l_le H lemma adjoin_eq_Inf : adjoin R s = Inf {p | s βŠ† p} := le_antisymm (le_Inf (Ξ» _ h, adjoin_le h)) (Inf_le subset_adjoin) theorem adjoin_le_iff {S : subalgebra R A} : adjoin R s ≀ S ↔ s βŠ† S:= algebra.gc _ _ theorem adjoin_mono (H : s βŠ† t) : adjoin R s ≀ adjoin R t := algebra.gc.monotone_l H theorem adjoin_eq_of_le (S : subalgebra R A) (h₁ : s βŠ† S) (hβ‚‚ : S ≀ adjoin R s) : adjoin R s = S := le_antisymm (adjoin_le h₁) hβ‚‚ theorem adjoin_eq (S : subalgebra R A) : adjoin R ↑S = S := adjoin_eq_of_le _ (set.subset.refl _) subset_adjoin lemma adjoin_Union {Ξ± : Type*} (s : Ξ± β†’ set A) : adjoin R (set.Union s) = ⨆ (i : Ξ±), adjoin R (s i) := (@algebra.gc R A _ _ _).l_supr lemma adjoin_attach_bUnion [decidable_eq A] {Ξ± : Type*} {s : finset Ξ±} (f : s β†’ finset A) : adjoin R (s.attach.bUnion f : set A) = ⨆ x, adjoin R (f x) := by simpa [adjoin_Union] @[elab_as_eliminator] theorem adjoin_induction {p : A β†’ Prop} {x : A} (h : x ∈ adjoin R s) (Hs : βˆ€ x ∈ s, p x) (Halg : βˆ€ r, p (algebra_map R A r)) (Hadd : βˆ€ x y, p x β†’ p y β†’ p (x + y)) (Hmul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) : p x := let S : subalgebra R A := { carrier := p, mul_mem' := Hmul, add_mem' := Hadd, algebra_map_mem' := Halg } in adjoin_le (show s ≀ S, from Hs) h /-- Induction principle for the algebra generated by a set `s`: show that `p x y` holds for any `x y ∈ adjoin R s` given that that it holds for `x y ∈ s` and that it satisfies a number of natural properties. -/ @[elab_as_eliminator] lemma adjoin_inductionβ‚‚ {p : A β†’ A β†’ Prop} {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) (Hs : βˆ€ (x ∈ s) (y ∈ s), p x y) (Halg : βˆ€ r₁ rβ‚‚, p (algebra_map R A r₁) (algebra_map R A rβ‚‚)) (Halg_left : βˆ€ r (x ∈ s), p (algebra_map R A r) x) (Halg_right : βˆ€ r (x ∈ s), p x (algebra_map R A r)) (Hadd_left : βˆ€ x₁ xβ‚‚ y, p x₁ y β†’ p xβ‚‚ y β†’ p (x₁ + xβ‚‚) y) (Hadd_right : βˆ€ x y₁ yβ‚‚, p x y₁ β†’ p x yβ‚‚ β†’ p x (y₁ + yβ‚‚)) (Hmul_left : βˆ€ x₁ xβ‚‚ y, p x₁ y β†’ p xβ‚‚ y β†’ p (x₁ * xβ‚‚) y) (Hmul_right : βˆ€ x y₁ yβ‚‚, p x y₁ β†’ p x yβ‚‚ β†’ p x (y₁ * yβ‚‚)) : p a b := begin refine adjoin_induction hb _ (Ξ» r, _) (Hadd_right a) (Hmul_right a), { exact adjoin_induction ha Hs Halg_left (Ξ» x y Hx Hy z hz, Hadd_left x y z (Hx z hz) (Hy z hz)) (Ξ» x y Hx Hy z hz, Hmul_left x y z (Hx z hz) (Hy z hz)) }, { exact adjoin_induction ha (Halg_right r) (Ξ» r', Halg r' r) (Ξ» x y, Hadd_left x y ((algebra_map R A) r)) (Ξ» x y, Hmul_left x y ((algebra_map R A) r)) }, end /-- The difference with `algebra.adjoin_induction` is that this acts on the subtype. -/ lemma adjoin_induction' {p : adjoin R s β†’ Prop} (Hs : βˆ€ x (h : x ∈ s), p ⟨x, subset_adjoin h⟩) (Halg : βˆ€ r, p (algebra_map R _ r)) (Hadd : βˆ€ x y, p x β†’ p y β†’ p (x + y)) (Hmul : βˆ€ x y, p x β†’ p y β†’ p (x * y)) (x : adjoin R s) : p x := subtype.rec_on x $ Ξ» x hx, begin refine exists.elim _ (Ξ» (hx : x ∈ adjoin R s) (hc : p ⟨x, hx⟩), hc), exact adjoin_induction hx (Ξ» x hx, ⟨subset_adjoin hx, Hs x hx⟩) (Ξ» r, ⟨subalgebra.algebra_map_mem _ r, Halg r⟩) (Ξ» x y hx hy, exists.elim hx $ Ξ» hx' hx, exists.elim hy $ Ξ» hy' hy, ⟨subalgebra.add_mem _ hx' hy', Hadd _ _ hx hy⟩) (Ξ» x y hx hy, exists.elim hx $ Ξ» hx' hx, exists.elim hy $ Ξ» hy' hy, ⟨subalgebra.mul_mem _ hx' hy', Hmul _ _ hx hy⟩), end @[simp] lemma adjoin_adjoin_coe_preimage {s : set A} : adjoin R ((coe : adjoin R s β†’ A) ⁻¹' s) = ⊀ := begin refine eq_top_iff.2 (Ξ» x, adjoin_induction' (Ξ» a ha, _) (Ξ» r, _) (Ξ» _ _, _) (Ξ» _ _, _) x), { exact subset_adjoin ha }, { exact subalgebra.algebra_map_mem _ r }, { exact subalgebra.add_mem _ }, { exact subalgebra.mul_mem _ } end lemma adjoin_union (s t : set A) : adjoin R (s βˆͺ t) = adjoin R s βŠ” adjoin R t := (algebra.gc : galois_connection _ (coe : subalgebra R A β†’ set A)).l_sup variables (R A) @[simp] theorem adjoin_empty : adjoin R (βˆ… : set A) = βŠ₯ := show adjoin R βŠ₯ = βŠ₯, by { apply galois_connection.l_bot, exact algebra.gc } @[simp] theorem adjoin_univ : adjoin R (set.univ : set A) = ⊀ := eq_top_iff.2 $ Ξ» x, subset_adjoin $ set.mem_univ _ variables (R) {A} (s) theorem adjoin_eq_span : (adjoin R s).to_submodule = span R (submonoid.closure s) := begin apply le_antisymm, { intros r hr, rcases subsemiring.mem_closure_iff_exists_list.1 hr with ⟨L, HL, rfl⟩, clear hr, induction L with hd tl ih, { exact zero_mem _ }, rw list.forall_mem_cons at HL, rw [list.map_cons, list.sum_cons], refine submodule.add_mem _ _ (ih HL.2), replace HL := HL.1, clear ih tl, suffices : βˆƒ z r (hr : r ∈ submonoid.closure s), has_smul.smul z r = list.prod hd, { rcases this with ⟨z, r, hr, hzr⟩, rw ← hzr, exact smul_mem _ _ (subset_span hr) }, induction hd with hd tl ih, { exact ⟨1, 1, (submonoid.closure s).one_mem', one_smul _ _⟩ }, rw list.forall_mem_cons at HL, rcases (ih HL.2) with ⟨z, r, hr, hzr⟩, rw [list.prod_cons, ← hzr], rcases HL.1 with ⟨hd, rfl⟩ | hs, { refine ⟨hd * z, r, hr, _⟩, rw [algebra.smul_def, algebra.smul_def, (algebra_map _ _).map_mul, _root_.mul_assoc] }, { exact ⟨z, hd * r, submonoid.mul_mem _ (submonoid.subset_closure hs) hr, (mul_smul_comm _ _ _).symm⟩ } }, refine span_le.2 _, change submonoid.closure s ≀ (adjoin R s).to_subsemiring.to_submonoid, exact submonoid.closure_le.2 subset_adjoin end lemma span_le_adjoin (s : set A) : span R s ≀ (adjoin R s).to_submodule := span_le.mpr subset_adjoin lemma adjoin_to_submodule_le {s : set A} {t : submodule R A} : (adjoin R s).to_submodule ≀ t ↔ ↑(submonoid.closure s) βŠ† (t : set A) := by rw [adjoin_eq_span, span_le] lemma adjoin_eq_span_of_subset {s : set A} (hs : ↑(submonoid.closure s) βŠ† (span R s : set A)) : (adjoin R s).to_submodule = span R s := le_antisymm ((adjoin_to_submodule_le R).mpr hs) (span_le_adjoin R s) @[simp] lemma adjoin_span {s : set A} : adjoin R (submodule.span R s : set A) = adjoin R s := le_antisymm (adjoin_le (span_le_adjoin _ _)) (adjoin_mono submodule.subset_span) lemma adjoin_image (f : A →ₐ[R] B) (s : set A) : adjoin R (f '' s) = (adjoin R s).map f := le_antisymm (adjoin_le $ set.image_subset _ subset_adjoin) $ subalgebra.map_le.2 $ adjoin_le $ set.image_subset_iff.1 subset_adjoin @[simp] lemma adjoin_insert_adjoin (x : A) : adjoin R (insert x ↑(adjoin R s)) = adjoin R (insert x s) := le_antisymm (adjoin_le (set.insert_subset.mpr ⟨subset_adjoin (set.mem_insert _ _), adjoin_mono (set.subset_insert _ _)⟩)) (algebra.adjoin_mono (set.insert_subset_insert algebra.subset_adjoin)) lemma adjoin_prod_le (s : set A) (t : set B) : adjoin R (s Γ—Λ’ t) ≀ (adjoin R s).prod (adjoin R t) := adjoin_le $ set.prod_mono subset_adjoin subset_adjoin lemma mem_adjoin_of_map_mul {s} {x : A} {f : A β†’β‚—[R] B} (hf : βˆ€ a₁ aβ‚‚, f(a₁ * aβ‚‚) = f a₁ * f aβ‚‚) (h : x ∈ adjoin R s) : f x ∈ adjoin R (f '' (s βˆͺ {1})) := begin refine @adjoin_induction R A _ _ _ _ (Ξ» a, f a ∈ adjoin R (f '' (s βˆͺ {1}))) x h (Ξ» a ha, subset_adjoin ⟨a, ⟨set.subset_union_left _ _ ha, rfl⟩⟩) (Ξ» r, _) (Ξ» y z hy hz, by simpa [hy, hz] using subalgebra.add_mem _ hy hz) (Ξ» y z hy hz, by simpa [hy, hz, hf y z] using subalgebra.mul_mem _ hy hz), have : f 1 ∈ adjoin R (f '' (s βˆͺ {1})) := subset_adjoin ⟨1, ⟨set.subset_union_right _ _ $ set.mem_singleton 1, rfl⟩⟩, replace this := subalgebra.smul_mem (adjoin R (f '' (s βˆͺ {1}))) this r, convert this, rw algebra_map_eq_smul_one, exact f.map_smul _ _ end lemma adjoin_inl_union_inr_eq_prod (s) (t) : adjoin R (linear_map.inl R A B '' (s βˆͺ {1}) βˆͺ linear_map.inr R A B '' (t βˆͺ {1})) = (adjoin R s).prod (adjoin R t) := begin apply le_antisymm, { simp only [adjoin_le_iff, set.insert_subset, subalgebra.zero_mem, subalgebra.one_mem, subset_adjoin, -- the rest comes from `squeeze_simp` set.union_subset_iff, linear_map.coe_inl, set.mk_preimage_prod_right, set.image_subset_iff, set_like.mem_coe, set.mk_preimage_prod_left, linear_map.coe_inr, and_self, set.union_singleton, subalgebra.coe_prod] }, { rintro ⟨a, b⟩ ⟨ha, hb⟩, let P := adjoin R (linear_map.inl R A B '' (s βˆͺ {1}) βˆͺ linear_map.inr R A B '' (t βˆͺ {1})), have Ha : (a, (0 : B)) ∈ adjoin R ((linear_map.inl R A B) '' (s βˆͺ {1})) := mem_adjoin_of_map_mul R (linear_map.inl_map_mul) ha, have Hb : ((0 : A), b) ∈ adjoin R ((linear_map.inr R A B) '' (t βˆͺ {1})) := mem_adjoin_of_map_mul R (linear_map.inr_map_mul) hb, replace Ha : (a, (0 : B)) ∈ P := adjoin_mono (set.subset_union_left _ _) Ha, replace Hb : ((0 : A), b) ∈ P := adjoin_mono (set.subset_union_right _ _) Hb, simpa using subalgebra.add_mem _ Ha Hb } end /-- If all elements of `s : set A` commute pairwise, then `adjoin R s` is a commutative semiring. -/ def adjoin_comm_semiring_of_comm {s : set A} (hcomm : βˆ€ (a ∈ s) (b ∈ s), a * b = b * a) : comm_semiring (adjoin R s) := { mul_comm := Ξ» x y, begin ext, simp only [subalgebra.coe_mul], exact adjoin_inductionβ‚‚ x.prop y.prop hcomm (Ξ» _ _, by rw [commutes]) (Ξ» r x hx, commutes r x) (Ξ» r x hx, (commutes r x).symm) (Ξ» _ _ _ h₁ hβ‚‚, by simp only [add_mul, mul_add, h₁, hβ‚‚]) (Ξ» _ _ _ h₁ hβ‚‚, by simp only [add_mul, mul_add, h₁, hβ‚‚]) (Ξ» x₁ xβ‚‚ y₁ h₁ hβ‚‚, by rw [mul_assoc, hβ‚‚, ←mul_assoc y₁, ←h₁, mul_assoc x₁]) (Ξ» x₁ xβ‚‚ y₁ h₁ hβ‚‚, by rw [mul_assoc xβ‚‚, ←hβ‚‚, ←mul_assoc xβ‚‚, ←h₁, ←mul_assoc]) end, ..(adjoin R s).to_semiring } lemma adjoin_singleton_one : adjoin R ({1} : set A) = βŠ₯ := eq_bot_iff.2 $ adjoin_le $ set.singleton_subset_iff.2 $ set_like.mem_coe.2 $ one_mem _ lemma self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : set A) := algebra.subset_adjoin (set.mem_singleton_iff.mpr rfl) end semiring section comm_semiring variables [comm_semiring R] [comm_semiring A] variables [algebra R A] {s t : set A} variables (R s t) theorem adjoin_union_eq_adjoin_adjoin : adjoin R (s βˆͺ t) = (adjoin (adjoin R s) t).restrict_scalars R := le_antisymm (closure_mono $ set.union_subset (set.range_subset_iff.2 $ Ξ» r, or.inl ⟨algebra_map R (adjoin R s) r, rfl⟩) (set.union_subset_union_left _ $ Ξ» x hxs, ⟨⟨_, subset_adjoin hxs⟩, rfl⟩)) (closure_le.2 $ set.union_subset (set.range_subset_iff.2 $ Ξ» x, adjoin_mono (set.subset_union_left _ _) x.2) (set.subset.trans (set.subset_union_right _ _) subset_adjoin)) theorem adjoin_union_coe_submodule : (adjoin R (s βˆͺ t)).to_submodule = (adjoin R s).to_submodule * (adjoin R t).to_submodule := begin rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span], congr' 1 with z, simp [submonoid.closure_union, submonoid.mem_sup, set.mem_mul] end lemma pow_smul_mem_adjoin_smul (r : R) (s : set A) {x : A} (hx : x ∈ adjoin R s) : βˆƒ nβ‚€ : β„•, βˆ€ n β‰₯ nβ‚€, r ^ n β€’ x ∈ adjoin R (r β€’ s) := begin change x ∈ (adjoin R s).to_submodule at hx, rw [adjoin_eq_span, finsupp.mem_span_iff_total] at hx, rcases hx with ⟨l, rfl : l.sum (Ξ» (i : submonoid.closure s) (c : R), c β€’ ↑i) = x⟩, choose n₁ nβ‚‚ using (Ξ» x : submonoid.closure s, submonoid.pow_smul_mem_closure_smul r s x.prop), use l.support.sup n₁, intros n hn, rw finsupp.smul_sum, refine (adjoin R (r β€’ s)).to_submodule.sum_mem _, intros a ha, have : n β‰₯ n₁ a := le_trans (finset.le_sup ha) hn, dsimp only, rw [← tsub_add_cancel_of_le this, pow_add, ← smul_smul, smul_smul _ (l a), mul_comm, ← smul_smul, adjoin_eq_span], refine submodule.smul_mem _ _ _, exact submodule.smul_mem _ _ (submodule.subset_span (nβ‚‚ a)) end end comm_semiring section ring variables [comm_ring R] [ring A] variables [algebra R A] {s t : set A} variables {R s t} theorem adjoin_int (s : set R) : adjoin β„€ s = subalgebra_of_subring (subring.closure s) := le_antisymm (adjoin_le subring.subset_closure) (subring.closure_le.2 subset_adjoin : subring.closure s ≀ (adjoin β„€ s).to_subring) theorem mem_adjoin_iff {s : set A} {x : A} : x ∈ adjoin R s ↔ x ∈ subring.closure (set.range (algebra_map R A) βˆͺ s) := ⟨λ hx, subsemiring.closure_induction hx subring.subset_closure (subring.zero_mem _) (subring.one_mem _) (Ξ» _ _, subring.add_mem _) ( Ξ» _ _, subring.mul_mem _), suffices subring.closure (set.range ⇑(algebra_map R A) βˆͺ s) ≀ (adjoin R s).to_subring, from @this x, subring.closure_le.2 subsemiring.subset_closure⟩ theorem adjoin_eq_ring_closure (s : set A) : (adjoin R s).to_subring = subring.closure (set.range (algebra_map R A) βˆͺ s) := subring.ext $ Ξ» x, mem_adjoin_iff variables (R) /-- If all elements of `s : set A` commute pairwise, then `adjoin R s` is a commutative ring. -/ def adjoin_comm_ring_of_comm {s : set A} (hcomm : βˆ€ (a ∈ s) (b ∈ s), a * b = b * a) : comm_ring (adjoin R s) := { ..(adjoin R s).to_ring, ..adjoin_comm_semiring_of_comm R hcomm } end ring end algebra open algebra subalgebra namespace alg_hom variables [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] lemma map_adjoin (Ο† : A →ₐ[R] B) (s : set A) : (adjoin R s).map Ο† = adjoin R (Ο† '' s) := (adjoin_image _ _ _).symm lemma adjoin_le_equalizer (φ₁ Ο†β‚‚ : A →ₐ[R] B) {s : set A} (h : s.eq_on φ₁ Ο†β‚‚) : adjoin R s ≀ φ₁.equalizer Ο†β‚‚ := adjoin_le h lemma ext_of_adjoin_eq_top {s : set A} (h : adjoin R s = ⊀) ⦃φ₁ Ο†β‚‚ : A →ₐ[R] B⦄ (hs : s.eq_on φ₁ Ο†β‚‚) : φ₁ = Ο†β‚‚ := ext $ Ξ» x, adjoin_le_equalizer φ₁ Ο†β‚‚ hs $ h.symm β–Έ trivial end alg_hom
f7031435ec051f1657c9fa233bd7be69816fc5a7
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/data/list/sort.lean
7b286c2a0694786a3be4647de37f48275a5f92a0
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
10,221
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Insertion sort and merge sort. -/ import data.list.perm open list.perm namespace list section sorted universe variable uu variables {Ξ± : Type uu} {r : Ξ± β†’ Ξ± β†’ Prop} /-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r` is a `<` or `≀`-like relation (transitive and antisymmetric or asymmetric) -/ def sorted := @pairwise @[simp] theorem sorted_nil : sorted r [] := pairwise.nil @[simp] theorem sorted_singleton (a : Ξ±) : sorted r [a] := pairwise_singleton _ _ theorem sorted_of_sorted_cons {a : Ξ±} {l : list Ξ±} : sorted r (a :: l) β†’ sorted r l := pairwise_of_pairwise_cons theorem rel_of_sorted_cons {a : Ξ±} {l : list Ξ±} : sorted r (a :: l) β†’ βˆ€ b ∈ l, r a b := rel_of_pairwise_cons @[simp] theorem sorted_cons {a : Ξ±} {l : list Ξ±} : sorted r (a :: l) ↔ (βˆ€ b ∈ l, r a b) ∧ sorted r l := pairwise_cons theorem eq_of_sorted_of_perm [is_antisymm Ξ± r] {l₁ lβ‚‚ : list Ξ±} (p : l₁ ~ lβ‚‚) (s₁ : sorted r l₁) (sβ‚‚ : sorted r lβ‚‚) : l₁ = lβ‚‚ := begin induction s₁ with a l₁ h₁ s₁ IH generalizing lβ‚‚, { rw eq_nil_of_perm_nil p }, { have : a ∈ lβ‚‚ := perm_subset p (mem_cons_self _ _), rcases mem_split this with ⟨uβ‚‚, vβ‚‚, rfl⟩, have p' := (perm_cons a).1 (p.trans perm_middle), have := IH p' (pairwise_of_sublist (by simp) sβ‚‚), subst l₁, change a::uβ‚‚ ++ vβ‚‚ = uβ‚‚ ++ ([a] ++ vβ‚‚), rw ← append_assoc, congr, have : βˆ€ (x : Ξ±) (h : x ∈ uβ‚‚), x = a := Ξ» x m, antisymm ((pairwise_append.1 sβ‚‚).2.2 _ m a (mem_cons_self _ _)) (h₁ _ (by simp [m])), rw [(@eq_repeat _ a (length uβ‚‚ + 1) (a::uβ‚‚)).2, (@eq_repeat _ a (length uβ‚‚ + 1) (uβ‚‚++[a])).2]; split; simp [iff_true_intro this, or_comm] } end end sorted /- sorting procedures -/ section sort universe variable uu parameters {Ξ± : Type uu} (r : Ξ± β†’ Ξ± β†’ Prop) [decidable_rel r] local infix `β‰Ό` : 50 := r /- insertion sort -/ section insertion_sort /-- `ordered_insert a l` inserts `a` into `l` at such that `ordered_insert a l` is sorted if `l` is. -/ @[simp] def ordered_insert (a : Ξ±) : list Ξ± β†’ list Ξ± | [] := [a] | (b :: l) := if a β‰Ό b then a :: b :: l else b :: ordered_insert l /-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/ @[simp] def insertion_sort : list Ξ± β†’ list Ξ± | [] := [] | (b :: l) := ordered_insert b (insertion_sort l) section correctness open perm theorem perm_ordered_insert (a) : βˆ€ l : list Ξ±, ordered_insert a l ~ a :: l | [] := perm.refl _ | (b :: l) := by by_cases a β‰Ό b; [simp [ordered_insert, h], simpa [ordered_insert, h] using (perm.skip _ (perm_ordered_insert l)).trans (perm.swap _ _ _)] theorem perm_insertion_sort : βˆ€ l : list Ξ±, insertion_sort l ~ l | [] := perm.nil | (b :: l) := by simpa [insertion_sort] using (perm_ordered_insert _ _ _).trans (perm.skip b (perm_insertion_sort l)) section total_and_transitive variables [is_total Ξ± r] [is_trans Ξ± r] theorem sorted_ordered_insert (a : Ξ±) : βˆ€ l, sorted r l β†’ sorted r (ordered_insert a l) | [] h := sorted_singleton a | (b :: l) h := begin by_cases h' : a β‰Ό b, { simpa [ordered_insert, h', h] using Ξ» b' bm, trans h' (rel_of_sorted_cons h _ bm) }, { suffices : βˆ€ (b' : Ξ±), b' ∈ ordered_insert r a l β†’ r b b', { simpa [ordered_insert, h', sorted_ordered_insert l (sorted_of_sorted_cons h)] }, intros b' bm, cases (show b' = a ∨ b' ∈ l, by simpa using perm_subset (perm_ordered_insert _ _ _) bm) with be bm, { subst b', exact (total_of r _ _).resolve_left h' }, { exact rel_of_sorted_cons h _ bm } } end theorem sorted_insertion_sort : βˆ€ l, sorted r (insertion_sort l) | [] := sorted_nil | (a :: l) := sorted_ordered_insert a _ (sorted_insertion_sort l) end total_and_transitive end correctness end insertion_sort /- merge sort -/ section merge_sort -- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the -- equation compiler can't prove the third equation /-- Split `l` into two lists of approximately equal length. split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/ @[simp] def split : list Ξ± β†’ list Ξ± Γ— list Ξ± | [] := ([], []) | (a :: l) := let (l₁, lβ‚‚) := split l in (a :: lβ‚‚, l₁) theorem split_cons_of_eq (a : Ξ±) {l l₁ lβ‚‚ : list Ξ±} (h : split l = (l₁, lβ‚‚)) : split (a :: l) = (a :: lβ‚‚, l₁) := by rw [split, h]; refl theorem length_split_le : βˆ€ {l l₁ lβ‚‚ : list Ξ±}, split l = (l₁, lβ‚‚) β†’ length l₁ ≀ length l ∧ length lβ‚‚ ≀ length l | [] ._ ._ rfl := ⟨nat.le_refl 0, nat.le_refl 0⟩ | (a::l) l₁' lβ‚‚' h := begin cases e : split l with l₁ lβ‚‚, injection (split_cons_of_eq _ e).symm.trans h, substs l₁' lβ‚‚', cases length_split_le e with h₁ hβ‚‚, exact ⟨nat.succ_le_succ hβ‚‚, nat.le_succ_of_le hβ‚βŸ© end theorem length_split_lt {a b} {l l₁ lβ‚‚ : list Ξ±} (h : split (a::b::l) = (l₁, lβ‚‚)) : length l₁ < length (a::b::l) ∧ length lβ‚‚ < length (a::b::l) := begin cases e : split l with l₁' lβ‚‚', injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l₁ lβ‚‚, cases length_split_le e with h₁ hβ‚‚, exact ⟨nat.succ_le_succ (nat.succ_le_succ h₁), nat.succ_le_succ (nat.succ_le_succ hβ‚‚)⟩ end theorem perm_split : βˆ€ {l l₁ lβ‚‚ : list Ξ±}, split l = (l₁, lβ‚‚) β†’ l ~ l₁ ++ lβ‚‚ | [] ._ ._ rfl := perm.refl _ | (a::l) l₁' lβ‚‚' h := begin cases e : split l with l₁ lβ‚‚, injection (split_cons_of_eq _ e).symm.trans h, substs l₁' lβ‚‚', exact perm.skip a ((perm_split e).trans perm_app_comm), end /-- Merge two sorted lists into one in linear time. merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/ def merge : list Ξ± β†’ list Ξ± β†’ list Ξ± | [] l' := l' | l [] := l | (a :: l) (b :: l') := if a β‰Ό b then a :: merge l (b :: l') else b :: merge (a :: l) l' include r /-- Implementation of a merge sort algorithm to sort a list. -/ def merge_sort : list Ξ± β†’ list Ξ± | [] := [] | [a] := [a] | (a::b::l) := begin cases e : split (a::b::l) with l₁ lβ‚‚, cases length_split_lt e with h₁ hβ‚‚, exact merge r (merge_sort l₁) (merge_sort lβ‚‚) end using_well_founded { rel_tac := Ξ»_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } theorem merge_sort_cons_cons {a b} {l l₁ lβ‚‚ : list Ξ±} (h : split (a::b::l) = (l₁, lβ‚‚)) : merge_sort (a::b::l) = merge (merge_sort l₁) (merge_sort lβ‚‚) := begin suffices : βˆ€ (L : list Ξ±) h1, @@and.rec (Ξ» a a (_ : length l₁ < length l + 1 + 1 ∧ length lβ‚‚ < length l + 1 + 1), L) h1 h1 = L, { simp [merge_sort, h], apply this }, intros, cases h1, refl end section correctness theorem perm_merge : βˆ€ (l l' : list Ξ±), merge l l' ~ l ++ l' | [] [] := perm.nil | [] (b :: l') := by simp [merge] | (a :: l) [] := by simp [merge] | (a :: l) (b :: l') := begin by_cases a β‰Ό b, { simpa [merge, h] using skip _ (perm_merge _ _) }, { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]}, exact (skip _ (perm_merge _ _)).trans ((swap _ _ _).trans (skip _ perm_middle.symm)) } end theorem perm_merge_sort : βˆ€ l : list Ξ±, merge_sort l ~ l | [] := perm.refl _ | [a] := perm.refl _ | (a::b::l) := begin cases e : split (a::b::l) with l₁ lβ‚‚, cases length_split_lt e with h₁ hβ‚‚, rw [merge_sort_cons_cons r e], apply (perm_merge r _ _).trans, exact (perm_app (perm_merge_sort l₁) (perm_merge_sort lβ‚‚)).trans (perm_split e).symm end using_well_founded { rel_tac := Ξ»_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } section total_and_transitive variables [is_total Ξ± r] [is_trans Ξ± r] theorem sorted_merge : βˆ€ {l l' : list Ξ±}, sorted r l β†’ sorted r l' β†’ sorted r (merge l l') | [] [] h₁ hβ‚‚ := sorted_nil | [] (b :: l') h₁ hβ‚‚ := by simpa [merge] using hβ‚‚ | (a :: l) [] h₁ hβ‚‚ := by simpa [merge] using h₁ | (a :: l) (b :: l') h₁ hβ‚‚ := begin by_cases a β‰Ό b, { suffices : βˆ€ (b' : Ξ±) (_ : b' ∈ merge r l (b :: l')), r a b', { simpa [merge, h, sorted_merge (sorted_of_sorted_cons h₁) hβ‚‚] }, intros b' bm, rcases (show b' = b ∨ b' ∈ l ∨ b' ∈ l', by simpa [or.left_comm] using perm_subset (perm_merge _ _ _) bm) with be | bl | bl', { subst b', assumption }, { exact rel_of_sorted_cons h₁ _ bl }, { exact trans h (rel_of_sorted_cons hβ‚‚ _ bl') } }, { suffices : βˆ€ (b' : Ξ±) (_ : b' ∈ merge r (a :: l) l'), r b b', { simpa [merge, h, sorted_merge h₁ (sorted_of_sorted_cons hβ‚‚)] }, intros b' bm, have ba : b β‰Ό a := (total_of r _ _).resolve_left h, rcases (show b' = a ∨ b' ∈ l ∨ b' ∈ l', by simpa using perm_subset (perm_merge _ _ _) bm) with be | bl | bl', { subst b', assumption }, { exact trans ba (rel_of_sorted_cons h₁ _ bl) }, { exact rel_of_sorted_cons hβ‚‚ _ bl' } } end theorem sorted_merge_sort : βˆ€ l : list Ξ±, sorted r (merge_sort l) | [] := sorted_nil | [a] := sorted_singleton _ | (a::b::l) := begin cases e : split (a::b::l) with l₁ lβ‚‚, cases length_split_lt e with h₁ hβ‚‚, rw [merge_sort_cons_cons r e], exact sorted_merge r (sorted_merge_sort l₁) (sorted_merge_sort lβ‚‚) end using_well_founded { rel_tac := Ξ»_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } theorem merge_sort_eq_self [is_antisymm Ξ± r] {l : list Ξ±} : sorted r l β†’ merge_sort l = l := eq_of_sorted_of_perm (perm_merge_sort _) (sorted_merge_sort _) end total_and_transitive end correctness end merge_sort end sort /- try them out! -/ --#eval insertion_sort (Ξ» m n : β„•, m ≀ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12] --#eval merge_sort (Ξ» m n : β„•, m ≀ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12] end list
2bc8b4576fbec4444e37e9b5a83ba183a7d2bf61
7cef822f3b952965621309e88eadf618da0c8ae9
/src/category_theory/types.lean
b9e83c01f0648afe1186b61a6b6ec85793007ef8
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
6,265
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Scott Morrison, Johannes HΓΆlzl -/ import category_theory.functor_category import category_theory.fully_faithful import data.equiv.basic namespace category_theory universes v v' w u u' -- declare the `v`'s first; see `category_theory.category` for an explanation instance types : large_category (Type u) := { hom := Ξ» a b, (a β†’ b), id := Ξ» a, id, comp := Ξ» _ _ _ f g, g ∘ f } @[simp] lemma types_hom {Ξ± Ξ² : Type u} : (Ξ± ⟢ Ξ²) = (Ξ± β†’ Ξ²) := rfl @[simp] lemma types_id (X : Type u) : πŸ™ X = id := rfl @[simp] lemma types_comp {X Y Z : Type u} (f : X ⟢ Y) (g : Y ⟢ Z) : f ≫ g = g ∘ f := rfl namespace functor variables {J : Type u} [π’₯ : category.{v} J] include π’₯ def sections (F : J β₯€ Type w) : set (Ξ  j, F.obj j) := { u | βˆ€ {j j'} (f : j ⟢ j'), F.map f (u j) = u j'} end functor namespace functor_to_types variables {C : Type u} [π’ž : category.{v} C] (F G H : C β₯€ Type w) {X Y Z : C} include π’ž variables (Οƒ : F ⟢ G) (Ο„ : G ⟢ H) @[simp] lemma map_comp (f : X ⟢ Y) (g : Y ⟢ Z) (a : F.obj X) : (F.map (f ≫ g)) a = (F.map g) ((F.map f) a) := by simp @[simp] lemma map_id (a : F.obj X) : (F.map (πŸ™ X)) a = a := by simp lemma naturality (f : X ⟢ Y) (x : F.obj X) : Οƒ.app Y ((F.map f) x) = (G.map f) (Οƒ.app X x) := congr_fun (Οƒ.naturality f) x @[simp] lemma comp (x : F.obj X) : (Οƒ ≫ Ο„).app X x = Ο„.app X (Οƒ.app X x) := rfl variables {D : Type u'} [π’Ÿ : category.{u'} D] (I J : D β₯€ C) (ρ : I ⟢ J) {W : D} @[simp] lemma hcomp (x : (I β‹™ F).obj W) : (ρ β—« Οƒ).app W x = (G.map (ρ.app W)) (Οƒ.app (I.obj W) x) := rfl end functor_to_types def ulift_trivial (V : Type u) : ulift.{u} V β‰… V := by tidy def ulift_functor : Type u β₯€ Type (max u v) := { obj := Ξ» X, ulift.{v} X, map := Ξ» X Y f, Ξ» x : ulift.{v} X, ulift.up (f x.down) } @[simp] lemma ulift_functor_map {X Y : Type u} (f : X ⟢ Y) (x : ulift.{v} X) : ulift_functor.map f x = ulift.up (f x.down) := rfl instance ulift_functor_full : full ulift_functor := { preimage := Ξ» X Y f x, (f (ulift.up x)).down } instance ulift_functor_faithful : faithful ulift_functor := { injectivity' := Ξ» X Y f g p, funext $ Ξ» x, congr_arg ulift.down ((congr_fun p (ulift.up x)) : ((ulift.up (f x)) = (ulift.up (g x)))) } def hom_of_element {X : Type u} (x : X) : punit ⟢ X := Ξ» _, x lemma hom_of_element_eq_iff {X : Type u} (x y : X) : hom_of_element x = hom_of_element y ↔ x = y := ⟨λ H, congr_fun H punit.star, by cc⟩ lemma mono_iff_injective {X Y : Type u} (f : X ⟢ Y) : mono f ↔ function.injective f := begin split, { intros H x x' h, resetI, rw ←hom_of_element_eq_iff at ⊒ h, exact (cancel_mono f).mp h }, { refine Ξ» H, ⟨λ Z g h Hβ‚‚, _⟩, ext z, replace Hβ‚‚ := congr_fun Hβ‚‚ z, exact H Hβ‚‚ } end lemma epi_iff_surjective {X Y : Type u} (f : X ⟢ Y) : epi f ↔ function.surjective f := begin split, { intros H, let g : Y ⟢ ulift Prop := Ξ» y, ⟨true⟩, let h : Y ⟢ ulift Prop := Ξ» y, βŸ¨βˆƒ x, f x = y⟩, suffices : f ≫ g = f ≫ h, { resetI, rw cancel_epi at this, intro y, replace this := congr_fun this y, replace this : true = βˆƒ x, f x = y := congr_arg ulift.down this, rw ←this, trivial }, ext x, change true ↔ βˆƒ x', f x' = f x, rw true_iff, exact ⟨x, rfl⟩ }, { intro H, constructor, intros Z g h Hβ‚‚, apply funext, rw ←forall_iff_forall_surj H, intro x, exact (congr_fun Hβ‚‚ x : _) } end section /-- `of_type_functor m` converts from Lean's `Type`-based `category` to `category_theory`. This allows us to use these functors in category theory. -/ def of_type_functor (m : Type u β†’ Type v) [_root_.functor m] [is_lawful_functor m] : Type u β₯€ Type v := { obj := m, map := λα Ξ², _root_.functor.map, map_id' := assume Ξ±, _root_.functor.map_id, map_comp' := assume Ξ± Ξ² Ξ³ f g, funext $ assume a, is_lawful_functor.comp_map f g _ } variables (m : Type u β†’ Type v) [_root_.functor m] [is_lawful_functor m] @[simp] lemma of_type_functor_obj : (of_type_functor m).obj = m := rfl @[simp] lemma of_type_functor_map {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) : (of_type_functor m).map f = (_root_.functor.map f : m Ξ± β†’ m Ξ²) := rfl end end category_theory -- Isomorphisms in Type and equivalences. namespace equiv universe u variables {X Y : Type u} def to_iso (e : X ≃ Y) : X β‰… Y := { hom := e.to_fun, inv := e.inv_fun, hom_inv_id' := funext e.left_inv, inv_hom_id' := funext e.right_inv } @[simp] lemma to_iso_hom {e : X ≃ Y} : e.to_iso.hom = e := rfl @[simp] lemma to_iso_inv {e : X ≃ Y} : e.to_iso.inv = e.symm := rfl end equiv namespace category_theory.iso universe u variables {X Y : Type u} def to_equiv (i : X β‰… Y) : X ≃ Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := Ξ» x, congr_fun i.hom_inv_id x, right_inv := Ξ» y, congr_fun i.inv_hom_id y } @[simp] lemma to_equiv_fun (i : X β‰… Y) : (i.to_equiv : X β†’ Y) = i.hom := rfl @[simp] lemma to_equiv_symm_fun (i : X β‰… Y) : (i.to_equiv.symm : Y β†’ X) = i.inv := rfl end category_theory.iso universe u -- We prove `equiv_iso_iso` and then use that to sneakily construct `equiv_equiv_iso`. -- (In this order the proofs are handled by `obviously`.) /-- equivalences (between types in the same universe) are the same as (isomorphic to) isomorphisms of types -/ @[simps] def equiv_iso_iso {X Y : Type u} : (X ≃ Y) β‰… (X β‰… Y) := { hom := Ξ» e, e.to_iso, inv := Ξ» i, i.to_equiv, } /-- equivalences (between types in the same universe) are the same as (equivalent to) isomorphisms of types -/ -- We leave `X` and `Y` as explicit arguments here, because the coercions from `equiv` to a function won't fire without them. def equiv_equiv_iso (X Y : Type u) : (X ≃ Y) ≃ (X β‰… Y) := (equiv_iso_iso).to_equiv @[simp] lemma equiv_equiv_iso_hom {X Y : Type u} (e : X ≃ Y) : (equiv_equiv_iso X Y) e = e.to_iso := rfl @[simp] lemma equiv_equiv_iso_inv {X Y : Type u} (e : X β‰… Y) : (equiv_equiv_iso X Y).symm e = e.to_equiv := rfl
16a9569a13128a375ef5cd0f4a338e430a8aebe5
89793396560dbc54fe665669485dab75e31828d3
/classes/identities.lean
80bef6ed220da50dbb029b71ee7397a6e64090d8
[ "Apache-2.0" ]
permissive
jipsen/lean-prover-universal-algebra
78cb22e8f9008e4692117e18820be07c54350822
5decd84053f30f175ebb86c39df4fd6b6d72400e
refs/heads/master
1,621,084,439,950
1,531,936,337,000
1,531,936,337,000
107,141,703
2
0
null
null
null
null
UTF-8
Lean
false
false
7,850
lean
universes u v section formulas variables {Ξ±: Type u} {Ξ²: Type v} variables f g: Ξ± β†’ Ξ± β†’ Ξ± variables h k: Ξ± β†’ Ξ± variables c d: Ξ± variables R S: Ξ± β†’ Ξ± β†’ Prop local infix `⬝`:70 := f local notation x+y := g x y local notation x\y := g x y local notation x/y := g x y local notation x⁻¹ := h x local notation `Β¬`:80 := k local notation 1 := c local notation 0 := d local notation x≀y := R x y def involutive := βˆ€x, h(h x) = x def inverse_ops := βˆ€x, h(k x) = x def unary_absorption_l := βˆ€x, h(k x) = k x def unary_absorption_r := βˆ€x, h(k x) = h x def unary_idempotent := βˆ€x, h(h x) = h x def idempotent := βˆ€x, x⬝x = x def identity_l := βˆ€x, 1⬝x = x def identity_r := βˆ€x, x⬝1 = x def zero_l := βˆ€x, 0⬝x = 0 def zero_r := βˆ€x, x⬝0 = 0 def inverse_l := βˆ€x, x⁻¹⬝x = 1 def inverse_r := βˆ€x, x⬝x⁻¹ = 1 def const_mult_l := βˆ€x, c⬝x = h x def const_mult_r := βˆ€x, x⬝c = h x def square_constant := βˆ€x, x⬝x = c def square_unary := βˆ€x, x⬝x = h x def unary_identity_l := βˆ€x, (h x)⬝x = x def unary_identity_r := βˆ€x, x⬝(h x) = x def unary_const_mult_l := βˆ€x, h(c⬝x) = c⬝(h x) def unary_const_mult_r := βˆ€x, h(x⬝c) = (h x)⬝c --def commutative := βˆ€x y, x⬝y = y⬝x defined in logic.lean def unary_projection_l := βˆ€x y, x⬝y = h x def unary_projection_r := βˆ€x y, x⬝y = h y def idempotent_l := βˆ€x y, x⬝(x⬝y) = x⬝y def idempotent_r := βˆ€x y, (x⬝y)⬝y = x⬝y def idempotent_l' := βˆ€x y, x⬝(y⬝x) = x⬝y def idempotent_r' := βˆ€x y, (x⬝y)⬝x = x⬝y def rectangular_l := βˆ€x y, (x⬝y)⬝x = x def rectangular_r := βˆ€x y, x⬝(y⬝x) = x def absorption := βˆ€x y, (x⬝y)+x = x def absorption' := βˆ€x y, x+(y⬝x) = x def division_l := βˆ€x y, x⬝(x\y) = y def division_r := βˆ€x y, (x/y)⬝y = x def division_l' := βˆ€x y, x\(x⬝y) = y def division_r' := βˆ€x y, (x⬝y)/y = x def unary_commutative := βˆ€x y, (h x)⬝(h y) = (h y)⬝(h x) def unary_involutive := βˆ€x y, h(x⬝y) = (h y)⬝(h x) def interdistributive := βˆ€x y, h(x⬝y) = (h x)+(h y) def unary_distributive := βˆ€x y, h(x⬝y) = (h x)⬝(h y) def twisted_l := βˆ€x y, (h(x⬝y))⬝x = x⬝(h y) def twisted_r := βˆ€x y, x⬝(h(y⬝x)) = (h y)⬝x def locality_l := βˆ€x y, h((h x)⬝y) = h(x⬝y) def locality_r := βˆ€x y, h(x⬝(h y)) = h(x⬝y) def unary_distributive_l := βˆ€x y, h((h x)⬝y) = (h x)⬝(h y) def unary_distributive_r := βˆ€x y, h(x⬝(h y)) = (h x)⬝(h y) def absorbtive_l := βˆ€x y, (h x)⬝(h(x⬝y)) = h(x⬝y) def absorbtive_r := βˆ€x y, (h(x⬝y))⬝(h y) = h(x⬝y) def flexible := βˆ€x y, (x⬝y)⬝x = x⬝(y⬝x) --def associative := βˆ€x y z, x⬝(y⬝z) = (x⬝y)⬝z defined in logic.lean def commutative_l := βˆ€x y z, x⬝(y⬝z) = y⬝(x⬝z) def commutative_r := βˆ€x y z, (x⬝y)⬝z = (x⬝z)⬝y def interassociative_1 := βˆ€x y z, x⬝(y+z) = (x⬝y)+z def interassociative_2 := βˆ€x y z, x⬝(y+z) = (x+y)⬝z def distributive_l := βˆ€x y z, x⬝(y+z) = (x⬝y)+(x⬝z) def distributive_r := βˆ€x y z, (x+y)⬝z = (x⬝z)+(y⬝z) def self_distributive_l := βˆ€x y z, x⬝(y⬝z) = (x⬝y)⬝(x⬝z) def self_distributive_r := βˆ€x y z, (x⬝y)⬝z = (x⬝z)⬝(y⬝z) def central := βˆ€x y z, (x⬝y)⬝(y⬝z) = y -- T. Evans: Am. Math. Monthly, April 1967, 362–372 def directoid_absorption := βˆ€x y z, x⬝((x⬝y)⬝z) = (x⬝y)⬝z def directoid_absorbtion' := βˆ€x y z, (x⬝(y⬝z))⬝z = x⬝(y⬝z) def Moufang1 := βˆ€x y z, ((x⬝y)⬝x)⬝z = x⬝(y⬝(x⬝z)) def Moufang2 := βˆ€x y z, ((x⬝y)⬝z)⬝y = x⬝(y⬝(z⬝y)) def Moufang3 := βˆ€x y z, (x⬝y)⬝(z⬝x) = (x⬝(y⬝z))⬝x def Moufang4 := βˆ€x y z, (x⬝y)⬝(z⬝x) = x⬝((y⬝z)⬝x) def entropic := βˆ€x y z w, (x⬝y)⬝(z⬝w) = (x⬝z)⬝(y⬝w) -- = medial def paramedial := βˆ€x y z w, (x⬝y)⬝(z⬝w) = (w⬝y)⬝(z⬝x) def complemented := βˆ€x, x⬝¬x = 0 ∧ x+Β¬x = 1 def order_preserving_u := βˆ€x y, x ≀ y β†’ h x ≀ h y def order_reversing_u := βˆ€x y, x ≀ y β†’ h y ≀ h x def cancelative_l := βˆ€x y z, x⬝y = x⬝z β†’ y = z def cancelative_r := βˆ€x y z, x⬝y = z⬝y β†’ x = z def naturally_ordered_l := βˆ€x y, x ≀ y ↔ βˆƒz, z⬝x = y def naturally_ordered_r := βˆ€x y, x ≀ y ↔ βˆƒz, x⬝z = y --def transitive := βˆ€x y z, x ≀ y β†’ y ≀ z β†’ x ≀ z defined in logic.lean def order_preserving_l := βˆ€x y z, x ≀ y β†’ x⬝z ≀ y⬝z def order_preserving_r := βˆ€x y z, x ≀ y β†’ z⬝x ≀ z⬝y def order_reversing_l := βˆ€x y z, x ≀ y β†’ y\z ≀ x\z def order_reversing_r := βˆ€x y z, x ≀ y β†’ z/y ≀ z/x def join_r1 := βˆ€x y z, x ≀ y β†’ x ≀ y+z def join_r2 := βˆ€x y z, x ≀ z β†’ x ≀ y+z def meet_l1 := βˆ€x y z, x ≀ z β†’ x⬝y ≀ z def meet_l2 := βˆ€x y z, y ≀ z β†’ x⬝y ≀ z def join_l := βˆ€x y z, x ≀ z ∧ y ≀ z β†’ x+y ≀ z def meet_r := βˆ€x y z, x ≀ y ∧ x ≀ z β†’ x ≀ y⬝z def residuated_l := βˆ€x y z, x⬝y ≀ z ↔ y ≀ x\z def residuated_r := βˆ€x y z, x⬝y ≀ z ↔ x ≀ z/y def commutative1_l (h: Ξ±β†’Ξ² β†’ Ξ²) := βˆ€x₁ xβ‚‚ y, h x₁(h xβ‚‚ y) = h xβ‚‚(h x₁ y) def commutative1_r (h: Ξ²β†’Ξ± β†’ Ξ²) := βˆ€y x₁ xβ‚‚, h(h y x₁) xβ‚‚ = h(h y xβ‚‚) x₁ -- example proofs from logic.lean lemma comm_l : commutative f β†’ associative f β†’ commutative1_l f := assume hcomm hassoc, assume x y z, calc x⬝(y⬝z) = (x⬝y)⬝z : (hassoc x y z).symm ... = (y⬝x)⬝z : hcomm x y β–Έ rfl ... = y⬝(x⬝z) : hassoc y x z lemma comm_r : commutative f β†’ associative f β†’ commutative1_r f := assume hcomm hassoc, assume x y z, calc (x⬝y)⬝z = x⬝(y⬝z) : hassoc x y z ... = x⬝(z⬝y) : hcomm y z β–Έ rfl ... = (x⬝z)⬝y : (hassoc x z y).symm end formulas /- def reflexive := βˆ€x, x ≀ x defined in logic.lean def irreflexive := βˆ€x, Β¬ x ≀ x def symmetric := βˆ€x y, x ≀ y β†’ y ≀ x def anti_symmetric := βˆ€x y, x ≀ y β†’ y ≀ x β†’ x = y def total := βˆ€x y, x ≀ y ∨ y ≀ x -/ --local infix `β‰Ί`:50 := R -- not used /- some more definitions from logic.lean def equivalence := reflexive R ∧ symmetric R ∧ transitive R def mk_equivalence (refl: reflexive R)(symm: symmetric R)(tran: transitive R): equivalence R := ⟨refl, symm, tran⟩ def empty_relation := Ξ»x₁ xβ‚‚:Ξ±, false def subrelation (R S: Ξ±β†’Ξ± β†’ Prop) := βˆ€β¦ƒx y⦄, R x y β†’ S x y def inv_image (f: Ξ² β†’ Ξ±): Ξ²β†’Ξ² β†’ Prop := Ξ»x₁ xβ‚‚, f x₁ ≀ f xβ‚‚ lemma inv_image.trans (f:Ξ² β†’ Ξ±) (h: transitive R): transitive (inv_image R f) := Ξ»(x₁ xβ‚‚ x₃:Ξ²) (h₁: inv_image R f x₁ xβ‚‚) (hβ‚‚: inv_image R f xβ‚‚ x₃), h h₁ hβ‚‚ lemma inv_image.irreflexive (f:Ξ² β†’ Ξ±)(h: irreflexive R): irreflexive (inv_image R f) := Ξ»(x:Ξ²)(h₁: inv_image R f x x), h(f x)h₁ --transitive closure of R inductive tc {Ξ±: Sort u}(R: Ξ±β†’Ξ± β†’ Prop): Ξ±β†’Ξ± β†’ Prop | base : βˆ€ x y, R x y β†’ tc x y | trans : βˆ€ x y z, tc x y β†’ tc y z β†’ tc y z -/
9dd155efddb80aa5a8840e45d95951f879a40884
1e561612e7479c100cd9302e3fe08cbd2914aa25
/mathlib4_experiments/Data/Equiv.lean
902c1f5ba969f7686bb21e9f4eee384d8155a942
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib4_experiments
8de8ed7193f70748a7529e05d831203a7c64eedb
87cb879b4d602c8ecfd9283b7c0b06015abdbab1
refs/heads/master
1,687,971,389,316
1,620,336,942,000
1,620,336,942,000
353,994,588
7
4
Apache-2.0
1,622,410,748,000
1,617,361,732,000
Lean
UTF-8
Lean
false
false
45
lean
import mathlib4_experiments.Data.Equiv.Basic
fa0333f3917655471b284f892f0cac88c0c598fb
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/04_Quantifiers_and_Equality.org.34.lean
0855feafa23ef037ddd69e9552094fd0a7ab51ab
[]
no_license
cjmazey/lean-tutorial
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
refs/heads/master
1,610,286,098,832
1,447,124,923,000
1,447,124,923,000
43,082,433
0
0
null
null
null
null
UTF-8
Lean
false
false
250
lean
/- page 60 -/ import standard import data.nat open nat -- BEGIN definition idnat : β„• β†’ β„• := take `β„•`, `β„•` print idnat definition idnat2 : β„• β†’ β„• β†’ β„• := take `β„•` `β„•`, `β„•` print idnat2 eval idnat2 0 1 -- returns 1 -- END
140e080a2c8368110c6da0752a6362bcbcc3f835
592ee40978ac7604005a4e0d35bbc4b467389241
/Library/generated/mathscheme-lean/InvolutiveMagmaSig.lean
f1dcb730477212aa5b7f1c50944ca2cdc592ed5f
[]
no_license
ysharoda/Deriving-Definitions
3e149e6641fae440badd35ac110a0bd705a49ad2
dfecb27572022de3d4aa702cae8db19957523a59
refs/heads/master
1,679,127,857,700
1,615,939,007,000
1,615,939,007,000
229,785,731
4
0
null
null
null
null
UTF-8
Lean
false
false
8,194
lean
import init.data.nat.basic import init.data.fin.basic import data.vector import .Prelude open Staged open nat open fin open vector section InvolutiveMagmaSig structure InvolutiveMagmaSig (A : Type) : Type := (prim : (A β†’ A)) (op : (A β†’ (A β†’ A))) open InvolutiveMagmaSig structure Sig (AS : Type) : Type := (primS : (AS β†’ AS)) (opS : (AS β†’ (AS β†’ AS))) structure Product (A : Type) : Type := (primP : ((Prod A A) β†’ (Prod A A))) (opP : ((Prod A A) β†’ ((Prod A A) β†’ (Prod A A)))) structure Hom {A1 : Type} {A2 : Type} (In1 : (InvolutiveMagmaSig A1)) (In2 : (InvolutiveMagmaSig A2)) : Type := (hom : (A1 β†’ A2)) (pres_prim : (βˆ€ {x1 : A1} , (hom ((prim In1) x1)) = ((prim In2) (hom x1)))) (pres_op : (βˆ€ {x1 x2 : A1} , (hom ((op In1) x1 x2)) = ((op In2) (hom x1) (hom x2)))) structure RelInterp {A1 : Type} {A2 : Type} (In1 : (InvolutiveMagmaSig A1)) (In2 : (InvolutiveMagmaSig A2)) : Type 1 := (interp : (A1 β†’ (A2 β†’ Type))) (interp_prim : (βˆ€ {x1 : A1} {y1 : A2} , ((interp x1 y1) β†’ (interp ((prim In1) x1) ((prim In2) y1))))) (interp_op : (βˆ€ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) β†’ ((interp x2 y2) β†’ (interp ((op In1) x1 x2) ((op In2) y1 y2)))))) inductive InvolutiveMagmaSigTerm : Type | primL : (InvolutiveMagmaSigTerm β†’ InvolutiveMagmaSigTerm) | opL : (InvolutiveMagmaSigTerm β†’ (InvolutiveMagmaSigTerm β†’ InvolutiveMagmaSigTerm)) open InvolutiveMagmaSigTerm inductive ClInvolutiveMagmaSigTerm (A : Type) : Type | sing : (A β†’ ClInvolutiveMagmaSigTerm) | primCl : (ClInvolutiveMagmaSigTerm β†’ ClInvolutiveMagmaSigTerm) | opCl : (ClInvolutiveMagmaSigTerm β†’ (ClInvolutiveMagmaSigTerm β†’ ClInvolutiveMagmaSigTerm)) open ClInvolutiveMagmaSigTerm inductive OpInvolutiveMagmaSigTerm (n : β„•) : Type | v : ((fin n) β†’ OpInvolutiveMagmaSigTerm) | primOL : (OpInvolutiveMagmaSigTerm β†’ OpInvolutiveMagmaSigTerm) | opOL : (OpInvolutiveMagmaSigTerm β†’ (OpInvolutiveMagmaSigTerm β†’ OpInvolutiveMagmaSigTerm)) open OpInvolutiveMagmaSigTerm inductive OpInvolutiveMagmaSigTerm2 (n : β„•) (A : Type) : Type | v2 : ((fin n) β†’ OpInvolutiveMagmaSigTerm2) | sing2 : (A β†’ OpInvolutiveMagmaSigTerm2) | primOL2 : (OpInvolutiveMagmaSigTerm2 β†’ OpInvolutiveMagmaSigTerm2) | opOL2 : (OpInvolutiveMagmaSigTerm2 β†’ (OpInvolutiveMagmaSigTerm2 β†’ OpInvolutiveMagmaSigTerm2)) open OpInvolutiveMagmaSigTerm2 def simplifyCl {A : Type} : ((ClInvolutiveMagmaSigTerm A) β†’ (ClInvolutiveMagmaSigTerm A)) | (primCl x1) := (primCl (simplifyCl x1)) | (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2)) | (sing x1) := (sing x1) def simplifyOpB {n : β„•} : ((OpInvolutiveMagmaSigTerm n) β†’ (OpInvolutiveMagmaSigTerm n)) | (primOL x1) := (primOL (simplifyOpB x1)) | (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2)) | (v x1) := (v x1) def simplifyOp {n : β„•} {A : Type} : ((OpInvolutiveMagmaSigTerm2 n A) β†’ (OpInvolutiveMagmaSigTerm2 n A)) | (primOL2 x1) := (primOL2 (simplifyOp x1)) | (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2)) | (v2 x1) := (v2 x1) | (sing2 x1) := (sing2 x1) def evalB {A : Type} : ((InvolutiveMagmaSig A) β†’ (InvolutiveMagmaSigTerm β†’ A)) | In (primL x1) := ((prim In) (evalB In x1)) | In (opL x1 x2) := ((op In) (evalB In x1) (evalB In x2)) def evalCl {A : Type} : ((InvolutiveMagmaSig A) β†’ ((ClInvolutiveMagmaSigTerm A) β†’ A)) | In (sing x1) := x1 | In (primCl x1) := ((prim In) (evalCl In x1)) | In (opCl x1 x2) := ((op In) (evalCl In x1) (evalCl In x2)) def evalOpB {A : Type} {n : β„•} : ((InvolutiveMagmaSig A) β†’ ((vector A n) β†’ ((OpInvolutiveMagmaSigTerm n) β†’ A))) | In vars (v x1) := (nth vars x1) | In vars (primOL x1) := ((prim In) (evalOpB In vars x1)) | In vars (opOL x1 x2) := ((op In) (evalOpB In vars x1) (evalOpB In vars x2)) def evalOp {A : Type} {n : β„•} : ((InvolutiveMagmaSig A) β†’ ((vector A n) β†’ ((OpInvolutiveMagmaSigTerm2 n A) β†’ A))) | In vars (v2 x1) := (nth vars x1) | In vars (sing2 x1) := x1 | In vars (primOL2 x1) := ((prim In) (evalOp In vars x1)) | In vars (opOL2 x1 x2) := ((op In) (evalOp In vars x1) (evalOp In vars x2)) def inductionB {P : (InvolutiveMagmaSigTerm β†’ Type)} : ((βˆ€ (x1 : InvolutiveMagmaSigTerm) , ((P x1) β†’ (P (primL x1)))) β†’ ((βˆ€ (x1 x2 : InvolutiveMagmaSigTerm) , ((P x1) β†’ ((P x2) β†’ (P (opL x1 x2))))) β†’ (βˆ€ (x : InvolutiveMagmaSigTerm) , (P x)))) | ppriml popl (primL x1) := (ppriml _ (inductionB ppriml popl x1)) | ppriml popl (opL x1 x2) := (popl _ _ (inductionB ppriml popl x1) (inductionB ppriml popl x2)) def inductionCl {A : Type} {P : ((ClInvolutiveMagmaSigTerm A) β†’ Type)} : ((βˆ€ (x1 : A) , (P (sing x1))) β†’ ((βˆ€ (x1 : (ClInvolutiveMagmaSigTerm A)) , ((P x1) β†’ (P (primCl x1)))) β†’ ((βˆ€ (x1 x2 : (ClInvolutiveMagmaSigTerm A)) , ((P x1) β†’ ((P x2) β†’ (P (opCl x1 x2))))) β†’ (βˆ€ (x : (ClInvolutiveMagmaSigTerm A)) , (P x))))) | psing pprimcl popcl (sing x1) := (psing x1) | psing pprimcl popcl (primCl x1) := (pprimcl _ (inductionCl psing pprimcl popcl x1)) | psing pprimcl popcl (opCl x1 x2) := (popcl _ _ (inductionCl psing pprimcl popcl x1) (inductionCl psing pprimcl popcl x2)) def inductionOpB {n : β„•} {P : ((OpInvolutiveMagmaSigTerm n) β†’ Type)} : ((βˆ€ (fin : (fin n)) , (P (v fin))) β†’ ((βˆ€ (x1 : (OpInvolutiveMagmaSigTerm n)) , ((P x1) β†’ (P (primOL x1)))) β†’ ((βˆ€ (x1 x2 : (OpInvolutiveMagmaSigTerm n)) , ((P x1) β†’ ((P x2) β†’ (P (opOL x1 x2))))) β†’ (βˆ€ (x : (OpInvolutiveMagmaSigTerm n)) , (P x))))) | pv pprimol popol (v x1) := (pv x1) | pv pprimol popol (primOL x1) := (pprimol _ (inductionOpB pv pprimol popol x1)) | pv pprimol popol (opOL x1 x2) := (popol _ _ (inductionOpB pv pprimol popol x1) (inductionOpB pv pprimol popol x2)) def inductionOp {n : β„•} {A : Type} {P : ((OpInvolutiveMagmaSigTerm2 n A) β†’ Type)} : ((βˆ€ (fin : (fin n)) , (P (v2 fin))) β†’ ((βˆ€ (x1 : A) , (P (sing2 x1))) β†’ ((βˆ€ (x1 : (OpInvolutiveMagmaSigTerm2 n A)) , ((P x1) β†’ (P (primOL2 x1)))) β†’ ((βˆ€ (x1 x2 : (OpInvolutiveMagmaSigTerm2 n A)) , ((P x1) β†’ ((P x2) β†’ (P (opOL2 x1 x2))))) β†’ (βˆ€ (x : (OpInvolutiveMagmaSigTerm2 n A)) , (P x)))))) | pv2 psing2 pprimol2 popol2 (v2 x1) := (pv2 x1) | pv2 psing2 pprimol2 popol2 (sing2 x1) := (psing2 x1) | pv2 psing2 pprimol2 popol2 (primOL2 x1) := (pprimol2 _ (inductionOp pv2 psing2 pprimol2 popol2 x1)) | pv2 psing2 pprimol2 popol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 pprimol2 popol2 x1) (inductionOp pv2 psing2 pprimol2 popol2 x2)) def stageB : (InvolutiveMagmaSigTerm β†’ (Staged InvolutiveMagmaSigTerm)) | (primL x1) := (stage1 primL (codeLift1 primL) (stageB x1)) | (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2)) def stageCl {A : Type} : ((ClInvolutiveMagmaSigTerm A) β†’ (Staged (ClInvolutiveMagmaSigTerm A))) | (sing x1) := (Now (sing x1)) | (primCl x1) := (stage1 primCl (codeLift1 primCl) (stageCl x1)) | (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2)) def stageOpB {n : β„•} : ((OpInvolutiveMagmaSigTerm n) β†’ (Staged (OpInvolutiveMagmaSigTerm n))) | (v x1) := (const (code (v x1))) | (primOL x1) := (stage1 primOL (codeLift1 primOL) (stageOpB x1)) | (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2)) def stageOp {n : β„•} {A : Type} : ((OpInvolutiveMagmaSigTerm2 n A) β†’ (Staged (OpInvolutiveMagmaSigTerm2 n A))) | (sing2 x1) := (Now (sing2 x1)) | (v2 x1) := (const (code (v2 x1))) | (primOL2 x1) := (stage1 primOL2 (codeLift1 primOL2) (stageOp x1)) | (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2)) structure StagedRepr (A : Type) (Repr : (Type β†’ Type)) : Type := (primT : ((Repr A) β†’ (Repr A))) (opT : ((Repr A) β†’ ((Repr A) β†’ (Repr A)))) end InvolutiveMagmaSig
ff6f425a30c83aefdb56c9e557c7c2a92d863053
4727251e0cd73359b15b664c3170e5d754078599
/src/group_theory/subsemigroup/operations.lean
bb6b6af81a71099db1d94909c3fb23bcda1e6a72
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
28,598
lean
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov, Yakov Pechersky, Jireh Loreaux -/ import group_theory.subsemigroup.basic /-! # Operations on `subsemigroup`s In this file we define various operations on `subsemigroup`s and `mul_hom`s. ## Main definitions ### Conversion between multiplicative and additive definitions * `subsemigroup.to_add_subsemigroup`, `subsemigroup.to_add_subsemigroup'`, `add_subsemigroup.to_subsemigroup`, `add_subsemigroup.to_subsemigroup'`: convert between multiplicative and additive subsemigroups of `M`, `multiplicative M`, and `additive M`. These are stated as `order_iso`s. ### (Commutative) semigroup structure on a subsemigroup * `subsemigroup.to_semigroup`, `subsemigroup.to_comm_semigroup`: a subsemigroup inherits a (commutative) semigroup structure. ### Operations on subsemigroups * `subsemigroup.comap`: preimage of a subsemigroup under a semigroup homomorphism as a subsemigroup of the domain; * `subsemigroup.map`: image of a subsemigroup under a semigroup homomorphism as a subsemigroup of the codomain; * `subsemigroup.prod`: product of two subsemigroups `s : subsemigroup M` and `t : subsemigroup N` as a subsemigroup of `M Γ— N`; ### Semigroup homomorphisms between subsemigroups * `subsemigroup.subtype`: embedding of a subsemigroup into the ambient semigroup. * `subsemigroup.inclusion`: given two subsemigroups `S`, `T` such that `S ≀ T`, `S.inclusion T` is the inclusion of `S` into `T` as a semigroup homomorphism; * `mul_equiv.subsemigroup_congr`: converts a proof of `S = T` into a semigroup isomorphism between `S` and `T`. * `subsemigroup.prod_equiv`: semigroup isomorphism between `s.prod t` and `s Γ— t`; ### Operations on `mul_hom`s * `mul_hom.srange`: range of a semigroup homomorphism as a subsemigroup of the codomain; * `mul_hom.srestrict`: restrict a semigroup homomorphism to a subsemigroup; * `mul_hom.cod_srestrict`: restrict the codomain of a semigroup homomorphism to a subsemigroup; * `mul_hom.srange_restrict`: restrict a semigroup homomorphism to its range; ### Implementation notes This file follows closely `group_theory/submonoid/operations.lean`, omitting only that which is necessary. ## Tags subsemigroup, range, product, map, comap -/ variables {M N P : Type*} /-! ### Conversion to/from `additive`/`multiplicative` -/ section variables [has_mul M] /-- Subsemigroups of semigroup `M` are isomorphic to additive subsemigroups of `additive M`. -/ @[simps] def subsemigroup.to_add_subsemigroup : subsemigroup M ≃o add_subsemigroup (additive M) := { to_fun := Ξ» S, { carrier := additive.to_mul ⁻¹' S, add_mem' := S.mul_mem' }, inv_fun := Ξ» S, { carrier := additive.of_mul ⁻¹' S, mul_mem' := S.add_mem' }, left_inv := Ξ» x, by cases x; refl, right_inv := Ξ» x, by cases x; refl, map_rel_iff' := Ξ» a b, iff.rfl, } /-- Additive subsemigroups of an additive semigroup `additive M` are isomorphic to subsemigroups of `M`. -/ abbreviation add_subsemigroup.to_subsemigroup' : add_subsemigroup (additive M) ≃o subsemigroup M := subsemigroup.to_add_subsemigroup.symm lemma subsemigroup.to_add_subsemigroup_closure (S : set M) : (subsemigroup.closure S).to_add_subsemigroup = add_subsemigroup.closure (additive.to_mul ⁻¹' S) := le_antisymm (subsemigroup.to_add_subsemigroup.le_symm_apply.1 $ subsemigroup.closure_le.2 add_subsemigroup.subset_closure) (add_subsemigroup.closure_le.2 subsemigroup.subset_closure) lemma add_subsemigroup.to_subsemigroup'_closure (S : set (additive M)) : (add_subsemigroup.closure S).to_subsemigroup' = subsemigroup.closure (multiplicative.of_add ⁻¹' S) := le_antisymm (add_subsemigroup.to_subsemigroup'.le_symm_apply.1 $ add_subsemigroup.closure_le.2 subsemigroup.subset_closure) (subsemigroup.closure_le.2 add_subsemigroup.subset_closure) end section variables {A : Type*} [has_add A] /-- Additive subsemigroups of an additive semigroup `A` are isomorphic to multiplicative subsemigroups of `multiplicative A`. -/ @[simps] def add_subsemigroup.to_subsemigroup : add_subsemigroup A ≃o subsemigroup (multiplicative A) := { to_fun := Ξ» S, { carrier := multiplicative.to_add ⁻¹' S, mul_mem' := S.add_mem' }, inv_fun := Ξ» S, { carrier := multiplicative.of_add ⁻¹' S, add_mem' := S.mul_mem' }, left_inv := Ξ» x, by cases x; refl, right_inv := Ξ» x, by cases x; refl, map_rel_iff' := Ξ» a b, iff.rfl, } /-- Subsemigroups of a semigroup `multiplicative A` are isomorphic to additive subsemigroups of `A`. -/ abbreviation subsemigroup.to_add_subsemigroup' : subsemigroup (multiplicative A) ≃o add_subsemigroup A := add_subsemigroup.to_subsemigroup.symm lemma add_subsemigroup.to_subsemigroup_closure (S : set A) : (add_subsemigroup.closure S).to_subsemigroup = subsemigroup.closure (multiplicative.to_add ⁻¹' S) := le_antisymm (add_subsemigroup.to_subsemigroup.to_galois_connection.l_le $ add_subsemigroup.closure_le.2 subsemigroup.subset_closure) (subsemigroup.closure_le.2 add_subsemigroup.subset_closure) lemma subsemigroup.to_add_subsemigroup'_closure (S : set (multiplicative A)) : (subsemigroup.closure S).to_add_subsemigroup' = add_subsemigroup.closure (additive.of_mul ⁻¹' S) := le_antisymm (subsemigroup.to_add_subsemigroup'.to_galois_connection.l_le $ subsemigroup.closure_le.2 add_subsemigroup.subset_closure) (add_subsemigroup.closure_le.2 subsemigroup.subset_closure) end namespace subsemigroup open set /-! ### `comap` and `map` -/ variables [has_mul M] [has_mul N] [has_mul P] (S : subsemigroup M) /-- The preimage of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The preimage of an `add_subsemigroup` along an `add_semigroup` homomorphism is an `add_subsemigroup`."] def comap (f : M β†’β‚™* N) (S : subsemigroup N) : subsemigroup M := { carrier := (f ⁻¹' S), mul_mem' := Ξ» a b ha hb, show f (a * b) ∈ S, by rw map_mul; exact mul_mem ha hb } @[simp, to_additive] lemma coe_comap (S : subsemigroup N) (f : M β†’β‚™* N) : (S.comap f : set M) = f ⁻¹' S := rfl @[simp, to_additive] lemma mem_comap {S : subsemigroup N} {f : M β†’β‚™* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl @[to_additive] lemma comap_comap (S : subsemigroup P) (g : N β†’β‚™* P) (f : M β†’β‚™* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[simp, to_additive] lemma comap_id (S : subsemigroup P) : S.comap (mul_hom.id _) = S := ext (by simp) /-- The image of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The image of an `add_subsemigroup` along an `add_semigroup` homomorphism is an `add_subsemigroup`."] def map (f : M β†’β‚™* N) (S : subsemigroup M) : subsemigroup N := { carrier := (f '' S), mul_mem' := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩, exact ⟨x * y, @mul_mem (subsemigroup M) M _ _ _ _ _ _ hx hy, by rw map_mul; refl⟩ end } @[simp, to_additive] lemma coe_map (f : M β†’β‚™* N) (S : subsemigroup M) : (S.map f : set N) = f '' S := rfl @[simp, to_additive] lemma mem_map {f : M β†’β‚™* N} {S : subsemigroup M} {y : N} : y ∈ S.map f ↔ βˆƒ x ∈ S, f x = y := mem_image_iff_bex @[to_additive] lemma mem_map_of_mem (f : M β†’β‚™* N) {S : subsemigroup M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx @[to_additive] lemma apply_coe_mem_map (f : M β†’β‚™* N) (S : subsemigroup M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.prop @[to_additive] lemma map_map (g : N β†’β‚™* P) (f : M β†’β‚™* N) : (S.map f).map g = S.map (g.comp f) := set_like.coe_injective $ image_image _ _ _ @[to_additive] lemma mem_map_iff_mem {f : M β†’β‚™* N} (hf : function.injective f) {S : subsemigroup M} {x : M} : f x ∈ S.map f ↔ x ∈ S := hf.mem_set_image @[to_additive] lemma map_le_iff_le_comap {f : M β†’β‚™* N} {S : subsemigroup M} {T : subsemigroup N} : S.map f ≀ T ↔ S ≀ T.comap f := image_subset_iff @[to_additive] lemma gc_map_comap (f : M β†’β‚™* N) : galois_connection (map f) (comap f) := Ξ» S T, map_le_iff_le_comap @[to_additive] lemma map_le_of_le_comap {T : subsemigroup N} {f : M β†’β‚™* N} : S ≀ T.comap f β†’ S.map f ≀ T := (gc_map_comap f).l_le @[to_additive] lemma le_comap_of_map_le {T : subsemigroup N} {f : M β†’β‚™* N} : S.map f ≀ T β†’ S ≀ T.comap f := (gc_map_comap f).le_u @[to_additive] lemma le_comap_map {f : M β†’β‚™* N} : S ≀ (S.map f).comap f := (gc_map_comap f).le_u_l _ @[to_additive] lemma map_comap_le {S : subsemigroup N} {f : M β†’β‚™* N} : (S.comap f).map f ≀ S := (gc_map_comap f).l_u_le _ @[to_additive] lemma monotone_map {f : M β†’β‚™* N} : monotone (map f) := (gc_map_comap f).monotone_l @[to_additive] lemma monotone_comap {f : M β†’β‚™* N} : monotone (comap f) := (gc_map_comap f).monotone_u @[simp, to_additive] lemma map_comap_map {f : M β†’β‚™* N} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ @[simp, to_additive] lemma comap_map_comap {S : subsemigroup N} {f : M β†’β‚™* N} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ @[to_additive] lemma map_sup (S T : subsemigroup M) (f : M β†’β‚™* N) : (S βŠ” T).map f = S.map f βŠ” T.map f := (gc_map_comap f).l_sup @[to_additive] lemma map_supr {ΞΉ : Sort*} (f : M β†’β‚™* N) (s : ΞΉ β†’ subsemigroup M) : (supr s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_supr @[to_additive] lemma comap_inf (S T : subsemigroup N) (f : M β†’β‚™* N) : (S βŠ“ T).comap f = S.comap f βŠ“ T.comap f := (gc_map_comap f).u_inf @[to_additive] lemma comap_infi {ΞΉ : Sort*} (f : M β†’β‚™* N) (s : ΞΉ β†’ subsemigroup N) : (infi s).comap f = β¨… i, (s i).comap f := (gc_map_comap f).u_infi @[simp, to_additive] lemma map_bot (f : M β†’β‚™* N) : (βŠ₯ : subsemigroup M).map f = βŠ₯ := (gc_map_comap f).l_bot @[simp, to_additive] lemma comap_top (f : M β†’β‚™* N) : (⊀ : subsemigroup N).comap f = ⊀ := (gc_map_comap f).u_top @[simp, to_additive] lemma map_id (S : subsemigroup M) : S.map (mul_hom.id M) = S := ext (Ξ» x, ⟨λ ⟨_, h, rfl⟩, h, Ξ» h, ⟨_, h, rfl⟩⟩) section galois_coinsertion variables {ΞΉ : Type*} {f : M β†’β‚™* N} (hf : function.injective f) include hf /-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/ @[to_additive /-" `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. "-/] def gci_map_comap : galois_coinsertion (map f) (comap f) := (gc_map_comap f).to_galois_coinsertion (Ξ» S x, by simp [mem_comap, mem_map, hf.eq_iff]) @[to_additive] lemma comap_map_eq_of_injective (S : subsemigroup M) : (S.map f).comap f = S := (gci_map_comap hf).u_l_eq _ @[to_additive] lemma comap_surjective_of_injective : function.surjective (comap f) := (gci_map_comap hf).u_surjective @[to_additive] lemma map_injective_of_injective : function.injective (map f) := (gci_map_comap hf).l_injective @[to_additive] lemma comap_inf_map_of_injective (S T : subsemigroup M) : (S.map f βŠ“ T.map f).comap f = S βŠ“ T := (gci_map_comap hf).u_inf_l _ _ @[to_additive] lemma comap_infi_map_of_injective (S : ΞΉ β†’ subsemigroup M) : (β¨… i, (S i).map f).comap f = infi S := (gci_map_comap hf).u_infi_l _ @[to_additive] lemma comap_sup_map_of_injective (S T : subsemigroup M) : (S.map f βŠ” T.map f).comap f = S βŠ” T := (gci_map_comap hf).u_sup_l _ _ @[to_additive] lemma comap_supr_map_of_injective (S : ΞΉ β†’ subsemigroup M) : (⨆ i, (S i).map f).comap f = supr S := (gci_map_comap hf).u_supr_l _ @[to_additive] lemma map_le_map_iff_of_injective {S T : subsemigroup M} : S.map f ≀ T.map f ↔ S ≀ T := (gci_map_comap hf).l_le_l_iff @[to_additive] lemma map_strict_mono_of_injective : strict_mono (map f) := (gci_map_comap hf).strict_mono_l end galois_coinsertion section galois_insertion variables {ΞΉ : Type*} {f : M β†’β‚™* N} (hf : function.surjective f) include hf /-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/ @[to_additive /-" `map f` and `comap f` form a `galois_insertion` when `f` is surjective. "-/] def gi_map_comap : galois_insertion (map f) (comap f) := (gc_map_comap f).to_galois_insertion (Ξ» S x h, let ⟨y, hy⟩ := hf x in mem_map.2 ⟨y, by simp [hy, h]⟩) @[to_additive] lemma map_comap_eq_of_surjective (S : subsemigroup N) : (S.comap f).map f = S := (gi_map_comap hf).l_u_eq _ @[to_additive] lemma map_surjective_of_surjective : function.surjective (map f) := (gi_map_comap hf).l_surjective @[to_additive] lemma comap_injective_of_surjective : function.injective (comap f) := (gi_map_comap hf).u_injective @[to_additive] lemma map_inf_comap_of_surjective (S T : subsemigroup N) : (S.comap f βŠ“ T.comap f).map f = S βŠ“ T := (gi_map_comap hf).l_inf_u _ _ @[to_additive] lemma map_infi_comap_of_surjective (S : ΞΉ β†’ subsemigroup N) : (β¨… i, (S i).comap f).map f = infi S := (gi_map_comap hf).l_infi_u _ @[to_additive] lemma map_sup_comap_of_surjective (S T : subsemigroup N) : (S.comap f βŠ” T.comap f).map f = S βŠ” T := (gi_map_comap hf).l_sup_u _ _ @[to_additive] lemma map_supr_comap_of_surjective (S : ΞΉ β†’ subsemigroup N) : (⨆ i, (S i).comap f).map f = supr S := (gi_map_comap hf).l_supr_u _ @[to_additive] lemma comap_le_comap_iff_of_surjective {S T : subsemigroup N} : S.comap f ≀ T.comap f ↔ S ≀ T := (gi_map_comap hf).u_le_u_iff @[to_additive] lemma comap_strict_mono_of_surjective : strict_mono (comap f) := (gi_map_comap hf).strict_mono_u end galois_insertion end subsemigroup namespace mul_mem_class variables {A : Type*} [has_mul M] [set_like A M] [hA : mul_mem_class A M] (S' : A) include hA /-- A submagma of a magma inherits a multiplication. -/ @[to_additive "An additive submagma of an additive magma inherits an addition.", priority 900] -- lower priority so other instances are found first instance has_mul : has_mul S' := ⟨λ a b, ⟨a.1 * b.1, mul_mem a.2 b.2⟩⟩ @[simp, norm_cast, to_additive, priority 900] -- lower priority so later simp lemmas are used first; to appease simp_nf lemma coe_mul (x y : S') : (↑(x * y) : M) = ↑x * ↑y := rfl @[simp, to_additive, priority 900] -- lower priority so later simp lemmas are used first; to appease simp_nf lemma mk_mul_mk (x y : M) (hx : x ∈ S') (hy : y ∈ S') : (⟨x, hx⟩ : S') * ⟨y, hy⟩ = ⟨x * y, mul_mem hx hy⟩ := rfl @[to_additive] lemma mul_def (x y : S') : x * y = ⟨x * y, mul_mem x.2 y.2⟩ := rfl omit hA /-- A subsemigroup of a semigroup inherits a semigroup structure. -/ @[to_additive "An `add_subsemigroup` of an `add_semigroup` inherits an `add_semigroup` structure."] instance to_semigroup {M : Type*} [semigroup M] {A : Type*} [set_like A M] [mul_mem_class A M] (S : A) : semigroup S := subtype.coe_injective.semigroup coe (Ξ» _ _, rfl) /-- A subsemigroup of a `comm_semigroup` is a `comm_semigroup`. -/ @[to_additive "An `add_subsemigroup` of an `add_comm_semigroup` is an `add_comm_semigroup`."] instance to_comm_semigroup {M} [comm_semigroup M] {A : Type*} [set_like A M] [mul_mem_class A M] (S : A) : comm_semigroup S := subtype.coe_injective.comm_semigroup coe (Ξ» _ _, rfl) include hA /-- The natural semigroup hom from a subsemigroup of semigroup `M` to `M`. -/ @[to_additive "The natural semigroup hom from an `add_subsemigroup` of `add_semigroup` `M` to `M`."] def subtype : S' β†’β‚™* M := ⟨coe, Ξ» _ _, rfl⟩ @[simp, to_additive] theorem coe_subtype : (mul_mem_class.subtype S' : S' β†’ M) = coe := rfl end mul_mem_class namespace subsemigroup variables [has_mul M] [has_mul N] [has_mul P] (S : subsemigroup M) /-- The top subsemigroup is isomorphic to the semigroup. -/ @[to_additive "The top additive subsemigroup is isomorphic to the additive semigroup.", simps] def top_equiv : (⊀ : subsemigroup M) ≃* M := { to_fun := Ξ» x, x, inv_fun := Ξ» x, ⟨x, mem_top x⟩, left_inv := Ξ» x, x.eta _, right_inv := Ξ» _, rfl, map_mul' := Ξ» _ _, rfl } @[simp, to_additive] lemma top_equiv_to_mul_hom : (top_equiv : _ ≃* M).to_mul_hom = mul_mem_class.subtype (⊀ : subsemigroup M) := rfl /-- A subsemigroup is isomorphic to its image under an injective function -/ @[to_additive "An additive subsemigroup is isomorphic to its image under an injective function"] noncomputable def equiv_map_of_injective (f : M β†’β‚™* N) (hf : function.injective f) : S ≃* S.map f := { map_mul' := Ξ» _ _, subtype.ext (map_mul f _ _), ..equiv.set.image f S hf } @[simp, to_additive] lemma coe_equiv_map_of_injective_apply (f : M β†’β‚™* N) (hf : function.injective f) (x : S) : (equiv_map_of_injective S f hf x : N) = f x := rfl @[simp, to_additive] lemma closure_closure_coe_preimage {s : set M} : closure ((coe : closure s β†’ M) ⁻¹' s) = ⊀ := eq_top_iff.2 $ Ξ» x, subtype.rec_on x $ Ξ» x hx _, begin refine closure_induction' _ (Ξ» g hg, _) (Ξ» g₁ gβ‚‚ hg₁ hgβ‚‚, _) hx, { exact subset_closure hg }, { exact subsemigroup.mul_mem _ }, end /-- Given `subsemigroup`s `s`, `t` of semigroups `M`, `N` respectively, `s Γ— t` as a subsemigroup of `M Γ— N`. -/ @[to_additive prod "Given `add_subsemigroup`s `s`, `t` of `add_semigroup`s `A`, `B` respectively, `s Γ— t` as an `add_subsemigroup` of `A Γ— B`."] def prod (s : subsemigroup M) (t : subsemigroup N) : subsemigroup (M Γ— N) := { carrier := (s : set M) Γ—Λ’ (t : set N), mul_mem' := Ξ» p q hp hq, ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ } @[to_additive coe_prod] lemma coe_prod (s : subsemigroup M) (t : subsemigroup N) : (s.prod t : set (M Γ— N)) = (s : set M) Γ—Λ’ (t : set N) := rfl @[to_additive mem_prod] lemma mem_prod {s : subsemigroup M} {t : subsemigroup N} {p : M Γ— N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl @[to_additive prod_mono] lemma prod_mono {s₁ sβ‚‚ : subsemigroup M} {t₁ tβ‚‚ : subsemigroup N} (hs : s₁ ≀ sβ‚‚) (ht : t₁ ≀ tβ‚‚) : s₁.prod t₁ ≀ sβ‚‚.prod tβ‚‚ := set.prod_mono hs ht @[to_additive prod_top] lemma prod_top (s : subsemigroup M) : s.prod (⊀ : subsemigroup N) = s.comap (mul_hom.fst M N) := ext $ Ξ» x, by simp [mem_prod, mul_hom.coe_fst] @[to_additive top_prod] lemma top_prod (s : subsemigroup N) : (⊀ : subsemigroup M).prod s = s.comap (mul_hom.snd M N) := ext $ Ξ» x, by simp [mem_prod, mul_hom.coe_snd] @[simp, to_additive top_prod_top] lemma top_prod_top : (⊀ : subsemigroup M).prod (⊀ : subsemigroup N) = ⊀ := (top_prod _).trans $ comap_top _ @[to_additive] lemma bot_prod_bot : (βŠ₯ : subsemigroup M).prod (βŠ₯ : subsemigroup N) = βŠ₯ := set_like.coe_injective $ by simp [coe_prod, prod.one_eq_mk] /-- The product of subsemigroups is isomorphic to their product as semigroups. -/ @[to_additive prod_equiv "The product of additive subsemigroups is isomorphic to their product as additive semigroups"] def prod_equiv (s : subsemigroup M) (t : subsemigroup N) : s.prod t ≃* s Γ— t := { map_mul' := Ξ» x y, rfl, .. equiv.set.prod ↑s ↑t } open mul_hom @[to_additive] lemma mem_map_equiv {f : M ≃* N} {K : subsemigroup M} {x : N} : x ∈ K.map f.to_mul_hom ↔ f.symm x ∈ K := @set.mem_image_equiv _ _ ↑K f.to_equiv x @[to_additive] lemma map_equiv_eq_comap_symm (f : M ≃* N) (K : subsemigroup M) : K.map f.to_mul_hom = K.comap f.symm.to_mul_hom := set_like.coe_injective (f.to_equiv.image_eq_preimage K) @[to_additive] lemma comap_equiv_eq_map_symm (f : N ≃* M) (K : subsemigroup M) : K.comap f.to_mul_hom = K.map f.symm.to_mul_hom := (map_equiv_eq_comap_symm f.symm K).symm @[simp, to_additive] lemma map_equiv_top (f : M ≃* N) : (⊀ : subsemigroup M).map f.to_mul_hom = ⊀ := set_like.coe_injective $ set.image_univ.trans f.surjective.range_eq @[to_additive le_prod_iff] lemma le_prod_iff {s : subsemigroup M} {t : subsemigroup N} {u : subsemigroup (M Γ— N)} : u ≀ s.prod t ↔ u.map (fst M N) ≀ s ∧ u.map (snd M N) ≀ t := begin split, { intros h, split, { rintros x ⟨⟨y1,y2⟩, ⟨hy1,rfl⟩⟩, exact (h hy1).1 }, { rintros x ⟨⟨y1,y2⟩, ⟨hy1,rfl⟩⟩, exact (h hy1).2 }, }, { rintros ⟨hH, hK⟩ ⟨x1, x2⟩ h, exact ⟨hH ⟨_ , h, rfl⟩, hK ⟨ _, h, rfl⟩⟩, } end end subsemigroup namespace mul_hom open subsemigroup variables [has_mul M] [has_mul N] [has_mul P] (S : subsemigroup M) /-- The range of a semigroup homomorphism is a subsemigroup. See Note [range copy pattern]. -/ @[to_additive "The range of an `add_hom` is an `add_subsemigroup`."] def srange (f : M β†’β‚™* N) : subsemigroup N := ((⊀ : subsemigroup M).map f).copy (set.range f) set.image_univ.symm @[simp, to_additive] lemma coe_srange (f : M β†’β‚™* N) : (f.srange : set N) = set.range f := rfl @[simp, to_additive] lemma mem_srange {f : M β†’β‚™* N} {y : N} : y ∈ f.srange ↔ βˆƒ x, f x = y := iff.rfl @[to_additive] lemma srange_eq_map (f : M β†’β‚™* N) : f.srange = (⊀ : subsemigroup M).map f := copy_eq _ @[to_additive] lemma map_srange (g : N β†’β‚™* P) (f : M β†’β‚™* N) : f.srange.map g = (g.comp f).srange := by simpa only [srange_eq_map] using (⊀ : subsemigroup M).map_map g f @[to_additive] lemma srange_top_iff_surjective {N} [has_mul N] {f : M β†’β‚™* N} : f.srange = (⊀ : subsemigroup N) ↔ function.surjective f := set_like.ext'_iff.trans $ iff.trans (by rw [coe_srange, coe_top]) set.range_iff_surjective /-- The range of a surjective semigroup hom is the whole of the codomain. -/ @[to_additive "The range of a surjective `add_semigroup` hom is the whole of the codomain."] lemma srange_top_of_surjective {N} [has_mul N] (f : M β†’β‚™* N) (hf : function.surjective f) : f.srange = (⊀ : subsemigroup N) := srange_top_iff_surjective.2 hf @[to_additive] lemma mclosure_preimage_le (f : M β†’β‚™* N) (s : set N) : closure (f ⁻¹' s) ≀ (closure s).comap f := closure_le.2 $ Ξ» x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx /-- The image under a semigroup hom of the subsemigroup generated by a set equals the subsemigroup generated by the image of the set. -/ @[to_additive "The image under an `add_semigroup` hom of the `add_subsemigroup` generated by a set equals the `add_subsemigroup` generated by the image of the set."] lemma map_mclosure (f : M β†’β‚™* N) (s : set M) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _) (mclosure_preimage_le _ _)) (closure_le.2 $ set.image_subset _ subset_closure) /-- Restriction of a semigroup hom to a subsemigroup of the domain. -/ @[to_additive "Restriction of an add_semigroup hom to an `add_subsemigroup` of the domain."] def srestrict {N : Type*} [has_mul N] (f : M β†’β‚™* N) (S : subsemigroup M) : S β†’β‚™* N := f.comp (mul_mem_class.subtype S) @[simp, to_additive] lemma srestrict_apply {N : Type*} [has_mul N] (f : M β†’β‚™* N) (x : S) : f.srestrict S x = f x := rfl /-- Restriction of a semigroup hom to a subsemigroup of the codomain. -/ @[to_additive "Restriction of an `add_semigroup` hom to an `add_subsemigroup` of the codomain.", simps] def cod_srestrict (f : M β†’β‚™* N) (S : subsemigroup N) (h : βˆ€ x, f x ∈ S) : M β†’β‚™* S := { to_fun := Ξ» n, ⟨f n, h n⟩, map_mul' := Ξ» x y, subtype.eq (map_mul f x y) } /-- Restriction of a semigroup hom to its range interpreted as a subsemigroup. -/ @[to_additive "Restriction of an `add_semigroup` hom to its range interpreted as a subsemigroup."] def srange_restrict {N} [has_mul N] (f : M β†’β‚™* N) : M β†’β‚™* f.srange := f.cod_srestrict f.srange $ Ξ» x, ⟨x, rfl⟩ @[simp, to_additive] lemma coe_srange_restrict {N} [has_mul N] (f : M β†’β‚™* N) (x : M) : (f.srange_restrict x : N) = f x := rfl @[to_additive] lemma srange_restrict_surjective (f : M β†’β‚™* N) : function.surjective f.srange_restrict := Ξ» ⟨_, ⟨x, rfl⟩⟩, ⟨x, rfl⟩ @[to_additive] lemma prod_map_comap_prod' {M' : Type*} {N' : Type*} [has_mul M'] [has_mul N'] (f : M β†’β‚™* N) (g : M' β†’β‚™* N') (S : subsemigroup N) (S' : subsemigroup N') : (S.prod S').comap (prod_map f g) = (S.comap f).prod (S'.comap g) := set_like.coe_injective $ set.preimage_prod_map_prod f g _ _ /-- The `mul_hom` from the preimage of a subsemigroup to itself. -/ @[to_additive "the `add_hom` from the preimage of an additive subsemigroup to itself.", simps] def subsemigroup_comap (f : M β†’β‚™* N) (N' : subsemigroup N) : N'.comap f β†’β‚™* N' := { to_fun := Ξ» x, ⟨f x, x.prop⟩, map_mul' := Ξ» x y, subtype.eq (@map_mul M N _ _ _ _ f x y) } /-- The `mul_hom` from a subsemigroup to its image. See `mul_equiv.subsemigroup_map` for a variant for `mul_equiv`s. -/ @[to_additive "the `add_hom` from an additive subsemigroup to its image. See `add_equiv.add_subsemigroup_map` for a variant for `add_equiv`s.", simps] def subsemigroup_map (f : M β†’β‚™* N) (M' : subsemigroup M) : M' β†’β‚™* M'.map f := { to_fun := Ξ» x, ⟨f x, ⟨x, x.prop, rfl⟩⟩, map_mul' := Ξ» x y, subtype.eq $ @map_mul M N _ _ _ _ f x y } @[to_additive] lemma subsemigroup_map_surjective (f : M β†’β‚™* N) (M' : subsemigroup M) : function.surjective (f.subsemigroup_map M') := by { rintro ⟨_, x, hx, rfl⟩, exact ⟨⟨x, hx⟩, rfl⟩ } end mul_hom namespace subsemigroup open mul_hom variables [has_mul M] [has_mul N] [has_mul P] (S : subsemigroup M) @[simp, to_additive] lemma srange_fst [nonempty N] : (fst M N).srange = ⊀ := (fst M N).srange_top_of_surjective $ prod.fst_surjective @[simp, to_additive] lemma srange_snd [nonempty M] : (snd M N).srange = ⊀ := (snd M N).srange_top_of_surjective $ prod.snd_surjective @[to_additive] lemma prod_eq_top_iff [nonempty M] [nonempty N] {s : subsemigroup M} {t : subsemigroup N} : s.prod t = ⊀ ↔ s = ⊀ ∧ t = ⊀ := by simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, ← srange_eq_map, srange_fst, srange_snd] /-- The semigroup hom associated to an inclusion of subsemigroups. -/ @[to_additive "The `add_semigroup` hom associated to an inclusion of subsemigroups."] def inclusion {S T : subsemigroup M} (h : S ≀ T) : S β†’β‚™* T := (mul_mem_class.subtype S).cod_srestrict _ (Ξ» x, h x.2) @[simp, to_additive] lemma range_subtype (s : subsemigroup M) : (mul_mem_class.subtype s).srange = s := set_like.coe_injective $ (coe_srange _).trans $ subtype.range_coe @[to_additive] lemma eq_top_iff' : S = ⊀ ↔ βˆ€ x : M, x ∈ S := eq_top_iff.trans ⟨λ h m, h $ mem_top m, Ξ» h m _, h m⟩ end subsemigroup namespace mul_equiv variables [has_mul M] [has_mul N] {S T : subsemigroup M} /-- Makes the identity isomorphism from a proof that two subsemigroups of a multiplicative semigroup are equal. -/ @[to_additive "Makes the identity additive isomorphism from a proof two subsemigroups of an additive semigroup are equal."] def subsemigroup_congr (h : S = T) : S ≃* T := { map_mul' := Ξ» _ _, rfl, ..equiv.set_congr $ congr_arg _ h } -- this name is primed so that the version to `f.range` instead of `f.srange` can be unprimed. /-- A semigroup homomorphism `f : M β†’β‚™* N` with a left-inverse `g : N β†’ M` defines a multiplicative equivalence between `M` and `f.srange`. This is a bidirectional version of `mul_hom.srange_restrict`. -/ @[to_additive /-" An additive semigroup homomorphism `f : M β†’+ N` with a left-inverse `g : N β†’ M` defines an additive equivalence between `M` and `f.srange`. This is a bidirectional version of `add_hom.srange_restrict`. "-/, simps {simp_rhs := tt}] def of_left_inverse (f : M β†’β‚™* N) {g : N β†’ M} (h : function.left_inverse g f) : M ≃* f.srange := { to_fun := f.srange_restrict, inv_fun := g ∘ (mul_mem_class.subtype f.srange), left_inv := h, right_inv := Ξ» x, subtype.ext $ let ⟨x', hx'⟩ := mul_hom.mem_srange.mp x.prop in show f (g x) = x, by rw [←hx', h x'], .. f.srange_restrict } /-- A `mul_equiv` `Ο†` between two semigroups `M` and `N` induces a `mul_equiv` between a subsemigroup `S ≀ M` and the subsemigroup `Ο†(S) ≀ N`. See `mul_hom.subsemigroup_map` for a variant for `mul_hom`s. -/ @[to_additive "An `add_equiv` `Ο†` between two additive semigroups `M` and `N` induces an `add_equiv` between a subsemigroup `S ≀ M` and the subsemigroup `Ο†(S) ≀ N`. See `add_hom.add_subsemigroup_map` for a variant for `add_hom`s.", simps] def subsemigroup_map (e : M ≃* N) (S : subsemigroup M) : S ≃* S.map e.to_mul_hom := { to_fun := Ξ» x, ⟨e x, _⟩, inv_fun := Ξ» x, ⟨e.symm x, _⟩, -- we restate this for `simps` to avoid `⇑e.symm.to_equiv x` ..e.to_mul_hom.subsemigroup_map S, ..e.to_equiv.image S } end mul_equiv
8a954a60105ab48d10502eebc4015e015674c56c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/normed_space/dual.lean
ab0cb02b407cc16bbb7b1cdef4660d7f37bb7be8
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
10,447
lean
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import analysis.normed_space.hahn_banach.extension import analysis.normed_space.is_R_or_C import analysis.locally_convex.polar /-! # The topological dual of a normed space > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define the topological dual `normed_space.dual` of a normed space, and the continuous linear map `normed_space.inclusion_in_double_dual` from a normed space into its double dual. For base field `π•œ = ℝ` or `π•œ = β„‚`, this map is actually an isometric embedding; we provide a version `normed_space.inclusion_in_double_dual_li` of the map which is of type a bundled linear isometric embedding, `E β†’β‚—α΅’[π•œ] (dual π•œ (dual π•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `seminormed_add_comm_group` and we specialize to `normed_add_comm_group` when needed. ## Main definitions * `inclusion_in_double_dual` and `inclusion_in_double_dual_li` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar π•œ s` is the subset of `dual π•œ E` consisting of those functionals `x'` for which `β€–x' zβ€– ≀ 1` for every `z ∈ s`. ## Tags dual -/ noncomputable theory open_locale classical topology universes u v namespace normed_space section general variables (π•œ : Type*) [nontrivially_normed_field π•œ] variables (E : Type*) [seminormed_add_comm_group E] [normed_space π•œ E] variables (F : Type*) [normed_add_comm_group F] [normed_space π•œ F] /-- The topological dual of a seminormed space `E`. -/ @[derive [inhabited, seminormed_add_comm_group, normed_space π•œ]] def dual := E β†’L[π•œ] π•œ instance : continuous_linear_map_class (dual π•œ E) π•œ E π•œ := continuous_linear_map.continuous_semilinear_map_class instance : has_coe_to_fun (dual π•œ E) (Ξ» _, E β†’ π•œ) := continuous_linear_map.to_fun instance : normed_add_comm_group (dual π•œ F) := continuous_linear_map.to_normed_add_comm_group instance [finite_dimensional π•œ E] : finite_dimensional π•œ (dual π•œ E) := continuous_linear_map.finite_dimensional /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusion_in_double_dual : E β†’L[π•œ] (dual π•œ (dual π•œ E)) := continuous_linear_map.apply π•œ π•œ @[simp] lemma dual_def (x : E) (f : dual π•œ E) : inclusion_in_double_dual π•œ E x f = f x := rfl lemma inclusion_in_double_dual_norm_eq : β€–inclusion_in_double_dual π•œ Eβ€– = β€–(continuous_linear_map.id π•œ (dual π•œ E))β€– := continuous_linear_map.op_norm_flip _ lemma inclusion_in_double_dual_norm_le : β€–inclusion_in_double_dual π•œ Eβ€– ≀ 1 := by { rw inclusion_in_double_dual_norm_eq, exact continuous_linear_map.norm_id_le } lemma double_dual_bound (x : E) : β€–(inclusion_in_double_dual π•œ E) xβ€– ≀ β€–xβ€– := by simpa using continuous_linear_map.le_of_op_norm_le _ (inclusion_in_double_dual_norm_le π•œ E) x /-- The dual pairing as a bilinear form. -/ def dual_pairing : (dual π•œ E) β†’β‚—[π•œ] E β†’β‚—[π•œ] π•œ := continuous_linear_map.coe_lm π•œ @[simp] lemma dual_pairing_apply {v : dual π•œ E} {x : E} : dual_pairing π•œ E v x = v x := rfl lemma dual_pairing_separating_left : (dual_pairing π•œ E).separating_left := begin rw [linear_map.separating_left_iff_ker_eq_bot, linear_map.ker_eq_bot], exact continuous_linear_map.coe_injective, end end general section bidual_isometry variables (π•œ : Type v) [is_R_or_C π•œ] {E : Type u} [normed_add_comm_group E] [normed_space π•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `continuous_linear_map.op_norm_le_bound`. -/ lemma norm_le_dual_bound (x : E) {M : ℝ} (hMp: 0 ≀ M) (hM : βˆ€ (f : dual π•œ E), β€–f xβ€– ≀ M * β€–fβ€–) : β€–xβ€– ≀ M := begin classical, by_cases h : x = 0, { simp only [h, hMp, norm_zero] }, { obtain ⟨f, hf₁, hfx⟩ : βˆƒ f : E β†’L[π•œ] π•œ, β€–fβ€– = 1 ∧ f x = β€–xβ€– := exists_dual_vector π•œ x h, calc β€–xβ€– = β€–(β€–xβ€– : π•œ)β€– : is_R_or_C.norm_coe_norm.symm ... = β€–f xβ€– : by rw hfx ... ≀ M * β€–fβ€– : hM f ... = M : by rw [hf₁, mul_one] } end lemma eq_zero_of_forall_dual_eq_zero {x : E} (h : βˆ€ f : dual π•œ E, f x = (0 : π•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound π•œ x le_rfl (Ξ» f, by simp [h f])) lemma eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 ↔ βˆ€ g : dual π•œ E, g x = 0 := ⟨λ hx, by simp [hx], Ξ» h, eq_zero_of_forall_dual_eq_zero π•œ h⟩ /-- See also `geometric_hahn_banach_point_point`. -/ lemma eq_iff_forall_dual_eq {x y : E} : x = y ↔ βˆ€ g : dual π•œ E, g x = g y := begin rw [← sub_eq_zero, eq_zero_iff_forall_dual_eq_zero π•œ (x - y)], simp [sub_eq_zero], end /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusion_in_double_dual_li : E β†’β‚—α΅’[π•œ] (dual π•œ (dual π•œ E)) := { norm_map' := begin intros x, apply le_antisymm, { exact double_dual_bound π•œ E x }, rw continuous_linear_map.norm_def, refine le_cInf continuous_linear_map.bounds_nonempty _, rintros c ⟨hc1, hc2⟩, exact norm_le_dual_bound π•œ x hc1 hc2 end, .. inclusion_in_double_dual π•œ E } end bidual_isometry section polar_sets open metric set normed_space /-- Given a subset `s` in a normed space `E` (over a field `π•œ`), the polar `polar π•œ s` is the subset of `dual π•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z ∈ s`. -/ def polar (π•œ : Type*) [nontrivially_normed_field π•œ] {E : Type*} [seminormed_add_comm_group E] [normed_space π•œ E] : set E β†’ set (dual π•œ E) := (dual_pairing π•œ E).flip.polar variables (π•œ : Type*) [nontrivially_normed_field π•œ] variables {E : Type*} [seminormed_add_comm_group E] [normed_space π•œ E] lemma mem_polar_iff {x' : dual π•œ E} (s : set E) : x' ∈ polar π•œ s ↔ βˆ€ z ∈ s, β€–x' zβ€– ≀ 1 := iff.rfl @[simp] lemma polar_univ : polar π•œ (univ : set E) = {(0 : dual π•œ E)} := (dual_pairing π•œ E).flip.polar_univ (linear_map.flip_separating_right.mpr (dual_pairing_separating_left π•œ E)) lemma is_closed_polar (s : set E) : is_closed (polar π•œ s) := begin dunfold normed_space.polar, simp only [linear_map.polar_eq_Inter, linear_map.flip_apply], refine is_closed_bInter (Ξ» z hz, _), exact is_closed_Iic.preimage (continuous_linear_map.apply π•œ π•œ z).continuous.norm end @[simp] lemma polar_closure (s : set E) : polar π•œ (closure s) = polar π•œ s := ((dual_pairing π•œ E).flip.polar_antitone subset_closure).antisymm $ (dual_pairing π•œ E).flip.polar_gc.l_le $ closure_minimal ((dual_pairing π•œ E).flip.polar_gc.le_u_l s) $ by simpa [linear_map.flip_flip] using (is_closed_polar _ _).preimage (inclusion_in_double_dual π•œ E).continuous variables {π•œ} /-- If `x'` is a dual element such that the norms `β€–x' zβ€–` are bounded for `z ∈ s`, then a small scalar multiple of `x'` is in `polar π•œ s`. -/ lemma smul_mem_polar {s : set E} {x' : dual π•œ E} {c : π•œ} (hc : βˆ€ z, z ∈ s β†’ β€– x' z β€– ≀ β€–cβ€–) : c⁻¹ β€’ x' ∈ polar π•œ s := begin by_cases c_zero : c = 0, { simp only [c_zero, inv_zero, zero_smul], exact (dual_pairing π•œ E).flip.zero_mem_polar _ }, have eq : βˆ€ z, β€– c⁻¹ β€’ (x' z) β€– = β€– c⁻¹ β€– * β€– x' z β€– := Ξ» z, norm_smul c⁻¹ _, have le : βˆ€ z, z ∈ s β†’ β€– c⁻¹ β€’ (x' z) β€– ≀ β€– c⁻¹ β€– * β€– c β€–, { intros z hzs, rw eq z, apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _), }, have cancel : β€– c⁻¹ β€– * β€– c β€– = 1, by simp only [c_zero, norm_eq_zero, ne.def, not_false_iff, inv_mul_cancel, norm_inv], rwa cancel at le, end lemma polar_ball_subset_closed_ball_div {c : π•œ} (hc : 1 < β€–cβ€–) {r : ℝ} (hr : 0 < r) : polar π•œ (ball (0 : E) r) βŠ† closed_ball (0 : dual π•œ E) (β€–cβ€– / r) := begin intros x' hx', rw mem_polar_iff at hx', simp only [polar, mem_set_of_eq, mem_closed_ball_zero_iff, mem_ball_zero_iff] at *, have hcr : 0 < β€–cβ€– / r, from div_pos (zero_lt_one.trans hc) hr, refine continuous_linear_map.op_norm_le_of_shell hr hcr.le hc (Ξ» x h₁ hβ‚‚, _), calc β€–x' xβ€– ≀ 1 : hx' _ hβ‚‚ ... ≀ (β€–cβ€– / r) * β€–xβ€– : (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa inv_div) end variables (π•œ) lemma closed_ball_inv_subset_polar_closed_ball {r : ℝ} : closed_ball (0 : dual π•œ E) r⁻¹ βŠ† polar π•œ (closed_ball (0 : E) r) := Ξ» x' hx' x hx, calc β€–x' xβ€– ≀ β€–x'β€– * β€–xβ€– : x'.le_op_norm x ... ≀ r⁻¹ * r : mul_le_mul (mem_closed_ball_zero_iff.1 hx') (mem_closed_ball_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx') ... = r / r : inv_mul_eq_div _ _ ... ≀ 1 : div_self_le_one r /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ lemma polar_closed_ball {π•œ E : Type*} [is_R_or_C π•œ] [normed_add_comm_group E] [normed_space π•œ E] {r : ℝ} (hr : 0 < r) : polar π•œ (closed_ball (0 : E) r) = closed_ball (0 : dual π•œ E) r⁻¹ := begin refine subset.antisymm _ (closed_ball_inv_subset_polar_closed_ball _), intros x' h, simp only [mem_closed_ball_zero_iff], refine continuous_linear_map.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) (Ξ» z hz, _), simpa only [one_div] using linear_map.bound_of_ball_bound' hr 1 x'.to_linear_map h z end /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar π•œ s` are bounded by a constant. -/ lemma bounded_polar_of_mem_nhds_zero {s : set E} (s_nhd : s ∈ 𝓝 (0 : E)) : bounded (polar π•œ s) := begin obtain ⟨a, ha⟩ : βˆƒ a : π•œ, 1 < β€–aβ€– := normed_field.exists_one_lt_norm π•œ, obtain ⟨r, r_pos, r_ball⟩ : βˆƒ (r : ℝ) (hr : 0 < r), ball 0 r βŠ† s := metric.mem_nhds_iff.1 s_nhd, exact bounded_closed_ball.mono (((dual_pairing π•œ E).flip.polar_antitone r_ball).trans $ polar_ball_subset_closed_ball_div ha r_pos) end end polar_sets end normed_space
7723ee34f572a2cde00ace2e369020fe4a137c3c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebra/divisibility/basic.lean
3495d550e3400e1f593d9166726e85a4d0d49f6b
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,925
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland, Aaron Anderson -/ import algebra.hom.group /-! # Divisibility > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s. ## Main definitions * `monoid.has_dvd` ## Implementation notes The divisibility relation is defined for all monoids, and as such, depends on the order of multiplication if the monoid is not commutative. There are two possible conventions for divisibility in the noncommutative context, and this relation follows the convention for ordinals, so `a | b` is defined as `βˆƒ c, b = a * c`. ## Tags divisibility, divides -/ variables {Ξ± : Type*} section semigroup variables [semigroup Ξ±] {a b c : Ξ±} /-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`. This matches the convention for ordinals. -/ @[priority 100] instance semigroup_has_dvd : has_dvd Ξ± := has_dvd.mk (Ξ» a b, βˆƒ c, b = a * c) -- TODO: this used to not have `c` explicit, but that seems to be important -- for use with tactics, similar to `exists.intro` theorem dvd.intro (c : Ξ±) (h : a * c = b) : a ∣ b := exists.intro c h^.symm alias dvd.intro ← dvd_of_mul_right_eq theorem exists_eq_mul_right_of_dvd (h : a ∣ b) : βˆƒ c, b = a * c := h theorem dvd.elim {P : Prop} {a b : Ξ±} (H₁ : a ∣ b) (Hβ‚‚ : βˆ€ c, b = a * c β†’ P) : P := exists.elim H₁ Hβ‚‚ local attribute [simp] mul_assoc mul_comm mul_left_comm @[trans] theorem dvd_trans : a ∣ b β†’ b ∣ c β†’ a ∣ c | ⟨d, hβ‚βŸ© ⟨e, hβ‚‚βŸ© := ⟨d * e, h₁ β–Έ hβ‚‚.trans $ mul_assoc a d e⟩ alias dvd_trans ← has_dvd.dvd.trans instance : is_trans Ξ± (∣) := ⟨λ a b c, dvd_trans⟩ @[simp] theorem dvd_mul_right (a b : Ξ±) : a ∣ a * b := dvd.intro b rfl theorem dvd_mul_of_dvd_left (h : a ∣ b) (c : Ξ±) : a ∣ b * c := h.trans (dvd_mul_right b c) alias dvd_mul_of_dvd_left ← has_dvd.dvd.mul_right theorem dvd_of_mul_right_dvd (h : a * b ∣ c) : a ∣ c := (dvd_mul_right a b).trans h section map_dvd variables {M N : Type*} [monoid M] [monoid N] lemma map_dvd {F : Type*} [mul_hom_class F M N] (f : F) {a b} : a ∣ b β†’ f a ∣ f b | ⟨c, h⟩ := ⟨f c, h.symm β–Έ map_mul f a c⟩ lemma mul_hom.map_dvd (f : M β†’β‚™* N) {a b} : a ∣ b β†’ f a ∣ f b := map_dvd f lemma monoid_hom.map_dvd (f : M β†’* N) {a b} : a ∣ b β†’ f a ∣ f b := map_dvd f end map_dvd end semigroup section monoid variables [monoid Ξ±] {a b : Ξ±} @[refl, simp] theorem dvd_refl (a : Ξ±) : a ∣ a := dvd.intro 1 (mul_one a) theorem dvd_rfl : βˆ€ {a : Ξ±}, a ∣ a := dvd_refl instance : is_refl Ξ± (∣) := ⟨dvd_refl⟩ theorem one_dvd (a : Ξ±) : 1 ∣ a := dvd.intro a (one_mul a) lemma dvd_of_eq (h : a = b) : a ∣ b := by rw h alias dvd_of_eq ← eq.dvd end monoid section comm_semigroup variables [comm_semigroup Ξ±] {a b c : Ξ±} theorem dvd.intro_left (c : Ξ±) (h : c * a = b) : a ∣ b := dvd.intro _ (begin rewrite mul_comm at h, apply h end) alias dvd.intro_left ← dvd_of_mul_left_eq theorem exists_eq_mul_left_of_dvd (h : a ∣ b) : βˆƒ c, b = c * a := dvd.elim h (assume c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul_comm a c))) lemma dvd_iff_exists_eq_mul_left : a ∣ b ↔ βˆƒ c, b = c * a := ⟨exists_eq_mul_left_of_dvd, by { rintro ⟨c, rfl⟩, exact ⟨c, mul_comm _ _⟩, }⟩ theorem dvd.elim_left {P : Prop} (h₁ : a ∣ b) (hβ‚‚ : βˆ€ c, b = c * a β†’ P) : P := exists.elim (exists_eq_mul_left_of_dvd h₁) (assume c, assume h₃ : b = c * a, hβ‚‚ c h₃) @[simp] theorem dvd_mul_left (a b : Ξ±) : a ∣ b * a := dvd.intro b (mul_comm a b) theorem dvd_mul_of_dvd_right (h : a ∣ b) (c : Ξ±) : a ∣ c * b := begin rw mul_comm, exact h.mul_right _ end alias dvd_mul_of_dvd_right ← has_dvd.dvd.mul_left local attribute [simp] mul_assoc mul_comm mul_left_comm theorem mul_dvd_mul : βˆ€ {a b c d : Ξ±}, a ∣ b β†’ c ∣ d β†’ a * c ∣ b * d | a ._ c ._ ⟨e, rfl⟩ ⟨f, rfl⟩ := ⟨e * f, by simp⟩ theorem dvd_of_mul_left_dvd (h : a * b ∣ c) : b ∣ c := dvd.elim h (Ξ» d ceq, dvd.intro (a * d) (by simp [ceq])) end comm_semigroup section comm_monoid variables [comm_monoid Ξ±] {a b : Ξ±} theorem mul_dvd_mul_left (a : Ξ±) {b c : Ξ±} (h : b ∣ c) : a * b ∣ a * c := mul_dvd_mul (dvd_refl a) h theorem mul_dvd_mul_right (h : a ∣ b) (c : Ξ±) : a * c ∣ b * c := mul_dvd_mul h (dvd_refl c) theorem pow_dvd_pow_of_dvd {a b : Ξ±} (h : a ∣ b) : βˆ€ n : β„•, a ^ n ∣ b ^ n | 0 := by rw [pow_zero, pow_zero] | (n+1) := by { rw [pow_succ, pow_succ], exact mul_dvd_mul h (pow_dvd_pow_of_dvd n) } end comm_monoid