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
5b989a25716c8d3863fe856a669ea5c9f5cf1ab3
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/category_theory/sites/subsheaf.lean
70eace616b728c1260f904cfd2eb1ca6987fecba
[ "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
15,599
lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import category_theory.elementwise import category_theory.sites.compatible_sheafification import category_theory.limits.constructions.epi_mono import category_theory.adjunction.evaluation /-! # Subsheaf of types We define the sub(pre)sheaf of a type valued presheaf. ## Main results - `category_theory.grothendieck_topology.subpresheaf` : A subpresheaf of a presheaf of types. - `category_theory.grothendieck_topology.subpresheaf.sheafify` : The sheafification of a subpresheaf as a subpresheaf. Note that this is a sheaf only when the whole sheaf is. - `category_theory.grothendieck_topology.subpresheaf.sheafify_is_sheaf` : The sheafification is a sheaf - `category_theory.grothendieck_topology.subpresheaf.sheafify_lift` : The descent of a map into a sheaf to the sheafification. - `category_theory.grothendieck_topology.image_sheaf` : The image sheaf of a morphism. - `category_theory.grothendieck_topology.image_factorization` : The image sheaf as a `limits.image_factorization`. -/ universes w v u open opposite category_theory namespace category_theory.grothendieck_topology variables {C : Type u} [category.{v} C] (J : grothendieck_topology C) /-- A subpresheaf of a presheaf consists of a subset of `F.obj U` for every `U`, compatible with the restriction maps `F.map i`. -/ @[ext] structure subpresheaf (F : Cᵒᵖ ⥤ Type w) := (obj : Π U, set (F.obj U)) (map : Π {U V : Cᵒᵖ} (i : U ⟶ V), (obj U) ⊆ (F.map i) ⁻¹' (obj V)) variables {F F' F'' : Cᵒᵖ ⥤ Type w} (G G' : subpresheaf F) instance : partial_order (subpresheaf F) := partial_order.lift subpresheaf.obj subpresheaf.ext instance : has_top (subpresheaf F) := ⟨⟨λ U, ⊤, λ U V i x h, _root_.trivial⟩⟩ instance : nonempty (subpresheaf F) := infer_instance /-- The subpresheaf as a presheaf. -/ @[simps] def subpresheaf.to_presheaf : Cᵒᵖ ⥤ Type w := { obj := λ U, G.obj U, map := λ U V i x, ⟨F.map i x, G.map i x.prop⟩, map_id' := λ X, by { ext ⟨x, _⟩, dsimp, rw F.map_id, refl }, map_comp' := λ X Y Z i j, by { ext ⟨x, _⟩, dsimp, rw F.map_comp, refl } } instance {U} : has_coe (G.to_presheaf.obj U) (F.obj U) := coe_subtype /-- The inclusion of a subpresheaf to the original presheaf. -/ @[simps] def subpresheaf.ι : G.to_presheaf ⟶ F := { app := λ U x, x } instance : mono G.ι := ⟨λ H f₁ f₂ e, nat_trans.ext f₁ f₂ $ funext $ λ U, funext $ λ x, subtype.ext $ congr_fun (congr_app e U) x⟩ /-- The inclusion of a subpresheaf to a larger subpresheaf -/ @[simps] def subpresheaf.hom_of_le {G G' : subpresheaf F} (h : G ≤ G') : G.to_presheaf ⟶ G'.to_presheaf := { app := λ U x, ⟨x, h U x.prop⟩ } instance {G G' : subpresheaf F} (h : G ≤ G') : mono (subpresheaf.hom_of_le h) := ⟨λ H f₁ f₂ e, nat_trans.ext f₁ f₂ $ funext $ λ U, funext $ λ x, subtype.ext $ (congr_arg subtype.val $ (congr_fun (congr_app e U) x : _) : _)⟩ @[simp, reassoc] lemma subpresheaf.hom_of_le_ι {G G' : subpresheaf F} (h : G ≤ G') : subpresheaf.hom_of_le h ≫ G'.ι = G.ι := by { ext, refl } /-- If the image of a morphism falls in a subpresheaf, then the morphism factors through it. -/ @[simps] def subpresheaf.lift (f : F' ⟶ F) (hf : ∀ U x, f.app U x ∈ G.obj U) : F' ⟶ G.to_presheaf := { app := λ U x, ⟨f.app U x, hf U x⟩, naturality' := by { have := elementwise_of f.naturality, intros, ext, simp [this] } } @[simp, reassoc] lemma subpresheaf.lift_ι (f : F' ⟶ F) (hf : ∀ U x, f.app U x ∈ G.obj U) : G.lift f hf ≫ G.ι = f := by { ext, refl } /-- Given a subpresheaf `G` of `F`, an `F`-section `s` on `U`, we may define a sieve of `U` consisting of all `f : V ⟶ U` such that the restriction of `s` along `f` is in `G`. -/ @[simps] def subpresheaf.sieve_of_section {U : Cᵒᵖ} (s : F.obj U) : sieve (unop U) := { arrows := λ V f, F.map f.op s ∈ G.obj (op V), downward_closed' := λ V W i hi j, by { rw [op_comp, functor_to_types.map_comp_apply], exact G.map _ hi } } /-- Given a `F`-section `s` on `U` and a subpresheaf `G`, we may define a family of elements in `G` consisting of the restrictions of `s` -/ def subpresheaf.family_of_elements_of_section {U : Cᵒᵖ} (s : F.obj U) : (G.sieve_of_section s).1.family_of_elements G.to_presheaf := λ V i hi, ⟨F.map i.op s, hi⟩ lemma subpresheaf.family_of_elements_compatible {U : Cᵒᵖ} (s : F.obj U) : (G.family_of_elements_of_section s).compatible := begin intros Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ e, ext1, change F.map g₁.op (F.map f₁.op s) = F.map g₂.op (F.map f₂.op s), rw [← functor_to_types.map_comp_apply, ← functor_to_types.map_comp_apply, ← op_comp, ← op_comp, e], end lemma subpresheaf.nat_trans_naturality (f : F' ⟶ G.to_presheaf) {U V : Cᵒᵖ} (i : U ⟶ V) (x : F'.obj U) : (f.app V (F'.map i x)).1 = F.map i (f.app U x).1 := congr_arg subtype.val (functor_to_types.naturality _ _ f i x) include J /-- The sheafification of a subpresheaf as a subpresheaf. Note that this is a sheaf only when the whole presheaf is a sheaf. -/ def subpresheaf.sheafify : subpresheaf F := { obj := λ U, { s | G.sieve_of_section s ∈ J (unop U) }, map := begin rintros U V i s hs, refine J.superset_covering _ (J.pullback_stable i.unop hs), intros _ _ h, dsimp at h ⊢, rwa ← functor_to_types.map_comp_apply, end } lemma subpresheaf.le_sheafify : G ≤ G.sheafify J := begin intros U s hs, change _ ∈ J _, convert J.top_mem _, rw eq_top_iff, rintros V i -, exact G.map i.op hs, end variable {J} lemma subpresheaf.eq_sheafify (h : presieve.is_sheaf J F) (hG : presieve.is_sheaf J G.to_presheaf) : G = G.sheafify J := begin apply (G.le_sheafify J).antisymm, intros U s hs, suffices : ((hG _ hs).amalgamate _ (G.family_of_elements_compatible s)).1 = s, { rw ← this, exact ((hG _ hs).amalgamate _ (G.family_of_elements_compatible s)).2 }, apply (h _ hs).is_separated_for.ext, intros V i hi, exact (congr_arg subtype.val ((hG _ hs).valid_glue (G.family_of_elements_compatible s) _ hi) : _) end lemma subpresheaf.sheafify_is_sheaf (hF : presieve.is_sheaf J F) : presieve.is_sheaf J (G.sheafify J).to_presheaf := begin intros U S hS x hx, let S' := sieve.bind S (λ Y f hf, G.sieve_of_section (x f hf).1), have := λ {V} {i : V ⟶ U} (hi : S' i), hi, choose W i₁ i₂ hi₂ h₁ h₂, dsimp [-sieve.bind_apply] at *, let x'' : presieve.family_of_elements F S' := λ V i hi, F.map (i₁ hi).op (x _ (hi₂ hi)), have H : ∀ s, x.is_amalgamation s ↔ x''.is_amalgamation s.1, { intro s, split, { intros H V i hi, dsimp only [x''], conv_lhs { rw ← h₂ hi }, rw ← H _ (hi₂ hi), exact functor_to_types.map_comp_apply F (i₂ hi).op (i₁ hi).op _ }, { intros H V i hi, ext1, apply (hF _ (x i hi).2).is_separated_for.ext, intros V' i' hi', have hi'' : S' (i' ≫ i) := ⟨_, _, _, hi, hi', rfl⟩, have := H _ hi'', rw [op_comp, F.map_comp] at this, refine this.trans (congr_arg subtype.val (hx _ _ (hi₂ hi'') hi (h₂ hi''))) } }, have : x''.compatible, { intros V₁ V₂ V₃ g₁ g₂ g₃ g₄ S₁ S₂ e, rw [← functor_to_types.map_comp_apply, ← functor_to_types.map_comp_apply], exact congr_arg subtype.val (hx (g₁ ≫ i₁ S₁) (g₂ ≫ i₁ S₂) (hi₂ S₁) (hi₂ S₂) (by simp only [category.assoc, h₂, e])) }, obtain ⟨t, ht, ht'⟩ := hF _ (J.bind_covering hS (λ V i hi, (x i hi).2)) _ this, refine ⟨⟨t, _⟩, (H ⟨t, _⟩).mpr ht, λ y hy, subtype.ext (ht' _ ((H _).mp hy))⟩, show G.sieve_of_section t ∈ J _, refine J.superset_covering _ (J.bind_covering hS (λ V i hi, (x i hi).2)), intros V i hi, dsimp, rw ht _ hi, exact h₁ hi end lemma subpresheaf.eq_sheafify_iff (h : presieve.is_sheaf J F) : G = G.sheafify J ↔ presieve.is_sheaf J G.to_presheaf := ⟨λ e, e.symm ▸ G.sheafify_is_sheaf h, G.eq_sheafify h⟩ lemma subpresheaf.is_sheaf_iff (h : presieve.is_sheaf J F) : presieve.is_sheaf J G.to_presheaf ↔ ∀ U (s : F.obj U), G.sieve_of_section s ∈ J (unop U) → s ∈ G.obj U := begin rw ← G.eq_sheafify_iff h, change _ ↔ G.sheafify J ≤ G, exact ⟨eq.ge, (G.le_sheafify J).antisymm⟩ end lemma subpresheaf.sheafify_sheafify (h : presieve.is_sheaf J F) : (G.sheafify J).sheafify J = G.sheafify J := ((subpresheaf.eq_sheafify_iff _ h).mpr $ G.sheafify_is_sheaf h).symm /-- The lift of a presheaf morphism onto the sheafification subpresheaf. -/ noncomputable def subpresheaf.sheafify_lift (f : G.to_presheaf ⟶ F') (h : presieve.is_sheaf J F') : (G.sheafify J).to_presheaf ⟶ F' := { app := λ U s, (h _ s.prop).amalgamate _ ((G.family_of_elements_compatible ↑s).comp_presheaf_map f), naturality' := begin intros U V i, ext s, apply (h _ ((subpresheaf.sheafify J G).to_presheaf.map i s).prop).is_separated_for.ext, intros W j hj, refine (presieve.is_sheaf_for.valid_glue _ _ _ hj).trans _, dsimp, conv_rhs { rw ← functor_to_types.map_comp_apply }, change _ = F'.map (j ≫ i.unop).op _, refine eq.trans _ (presieve.is_sheaf_for.valid_glue _ _ _ _).symm, { dsimp at ⊢ hj, rwa functor_to_types.map_comp_apply }, { dsimp [presieve.family_of_elements.comp_presheaf_map], congr' 1, ext1, exact (functor_to_types.map_comp_apply _ _ _ _).symm } end } lemma subpresheaf.to_sheafify_lift (f : G.to_presheaf ⟶ F') (h : presieve.is_sheaf J F') : subpresheaf.hom_of_le (G.le_sheafify J) ≫ G.sheafify_lift f h = f := begin ext U s, apply (h _ ((subpresheaf.hom_of_le (G.le_sheafify J)).app U s).prop).is_separated_for.ext, intros V i hi, have := elementwise_of f.naturality, exact (presieve.is_sheaf_for.valid_glue _ _ _ hi).trans (this _ _) end lemma subpresheaf.to_sheafify_lift_unique (h : presieve.is_sheaf J F') (l₁ l₂ : (G.sheafify J).to_presheaf ⟶ F') (e : subpresheaf.hom_of_le (G.le_sheafify J) ≫ l₁ = subpresheaf.hom_of_le (G.le_sheafify J) ≫ l₂) : l₁ = l₂ := begin ext U ⟨s, hs⟩, apply (h _ hs).is_separated_for.ext, rintros V i hi, dsimp at hi, erw [← functor_to_types.naturality, ← functor_to_types.naturality], exact (congr_fun (congr_app e $ op V) ⟨_, hi⟩ : _) end lemma subpresheaf.sheafify_le (h : G ≤ G') (hF : presieve.is_sheaf J F) (hG' : presieve.is_sheaf J G'.to_presheaf) : G.sheafify J ≤ G' := begin intros U x hx, convert ((G.sheafify_lift (subpresheaf.hom_of_le h) hG').app U ⟨x, hx⟩).2, apply (hF _ hx).is_separated_for.ext, intros V i hi, have := congr_arg (λ f : G.to_presheaf ⟶ G'.to_presheaf, (nat_trans.app f (op V) ⟨_, hi⟩).1) (G.to_sheafify_lift (subpresheaf.hom_of_le h) hG'), convert this.symm, erw ← subpresheaf.nat_trans_naturality, refl, end omit J section image /-- The image presheaf of a morphism, whose components are the set-theoretic images. -/ @[simps] def image_presheaf (f : F' ⟶ F) : subpresheaf F := { obj := λ U, set.range (f.app U), map := λ U V i, by { rintros _ ⟨x, rfl⟩, have := elementwise_of f.naturality, exact ⟨_, this i x⟩ } } @[simp] lemma top_subpresheaf_obj (U) : (⊤ : subpresheaf F).obj U = ⊤ := rfl @[simp] lemma image_presheaf_id : image_presheaf (𝟙 F) = ⊤ := by { ext, simp } /-- A morphism factors through the image presheaf. -/ @[simps] def to_image_presheaf (f : F' ⟶ F) : F' ⟶ (image_presheaf f).to_presheaf := (image_presheaf f).lift f (λ U x, set.mem_range_self _) @[simp, reassoc] lemma to_image_presheaf_ι (f : F' ⟶ F) : to_image_presheaf f ≫ (image_presheaf f).ι = f := (image_presheaf f).lift_ι _ _ lemma image_presheaf_comp_le (f₁ : F ⟶ F') (f₂ : F' ⟶ F'') : image_presheaf (f₁ ≫ f₂) ≤ image_presheaf f₂ := λ U x hx, ⟨f₁.app U hx.some, hx.some_spec⟩ instance {F F' : Cᵒᵖ ⥤ Type (max v w)} (f : F ⟶ F') [hf : mono f] : is_iso (to_image_presheaf f) := begin apply_with nat_iso.is_iso_of_is_iso_app { instances := ff }, intro X, rw is_iso_iff_bijective, split, { intros x y e, have := (nat_trans.mono_iff_app_mono _ _).mp hf X, rw mono_iff_injective at this, exact this (congr_arg subtype.val e : _) }, { rintro ⟨_, ⟨x, rfl⟩⟩, exact ⟨x, rfl⟩ } end /-- The image sheaf of a morphism between sheaves, defined to be the sheafification of `image_presheaf`. -/ @[simps] def image_sheaf {F F' : Sheaf J (Type w)} (f : F ⟶ F') : Sheaf J (Type w) := ⟨((image_presheaf f.1).sheafify J).to_presheaf, by { rw is_sheaf_iff_is_sheaf_of_type, apply subpresheaf.sheafify_is_sheaf, rw ← is_sheaf_iff_is_sheaf_of_type, exact F'.2 }⟩ /-- A morphism factors through the image sheaf. -/ @[simps] def to_image_sheaf {F F' : Sheaf J (Type w)} (f : F ⟶ F') : F ⟶ image_sheaf f := ⟨to_image_presheaf f.1 ≫ subpresheaf.hom_of_le ((image_presheaf f.1).le_sheafify J)⟩ /-- The inclusion of the image sheaf to the target. -/ @[simps] def image_sheaf_ι {F F' : Sheaf J (Type w)} (f : F ⟶ F') : image_sheaf f ⟶ F' := ⟨subpresheaf.ι _⟩ @[simp, reassoc] lemma to_image_sheaf_ι {F F' : Sheaf J (Type w)} (f : F ⟶ F') : to_image_sheaf f ≫ image_sheaf_ι f = f := by { ext1, simp } instance {F F' : Sheaf J (Type w)} (f : F ⟶ F') : mono (image_sheaf_ι f) := (Sheaf_to_presheaf J _).mono_of_mono_map (by { dsimp, apply_instance }) instance {F F' : Sheaf J (Type w)} (f : F ⟶ F') : epi (to_image_sheaf f) := begin refine ⟨λ G' g₁ g₂ e, _⟩, ext U ⟨s, hx⟩, apply ((is_sheaf_iff_is_sheaf_of_type J _).mp G'.2 _ hx).is_separated_for.ext, rintros V i ⟨y, e'⟩, change (g₁.val.app _ ≫ G'.val.map _) _ = (g₂.val.app _ ≫ G'.val.map _) _, rw [← nat_trans.naturality, ← nat_trans.naturality], have E : (to_image_sheaf f).val.app (op V) y = (image_sheaf f).val.map i.op ⟨s, hx⟩ := subtype.ext e', have := congr_arg (λ f : F ⟶ G', (Sheaf.hom.val f).app _ y) e, dsimp at this ⊢, convert this; exact E.symm end /-- The mono factorization given by `image_sheaf` for a morphism. -/ def image_mono_factorization {F F' : Sheaf J (Type w)} (f : F ⟶ F') : limits.mono_factorisation f := { I := image_sheaf f, m := image_sheaf_ι f, e := to_image_sheaf f } /-- The mono factorization given by `image_sheaf` for a morphism is an image. -/ noncomputable def image_factorization {F F' : Sheaf J (Type (max v u))} (f : F ⟶ F') : limits.image_factorisation f := { F := image_mono_factorization f, is_image := { lift := λ I, begin haveI := (Sheaf.hom.mono_iff_presheaf_mono J _ _).mp I.m_mono, refine ⟨subpresheaf.hom_of_le _ ≫ inv (to_image_presheaf I.m.1)⟩, apply subpresheaf.sheafify_le, { conv_lhs { rw ← I.fac }, apply image_presheaf_comp_le }, { rw ← is_sheaf_iff_is_sheaf_of_type, exact F'.2 }, { apply presieve.is_sheaf_iso J (as_iso $ to_image_presheaf I.m.1), rw ← is_sheaf_iff_is_sheaf_of_type, exact I.I.2 } end, lift_fac' := λ I, begin ext1, dsimp [image_mono_factorization], generalize_proofs h, rw [← subpresheaf.hom_of_le_ι h, category.assoc], congr' 1, rw [is_iso.inv_comp_eq, to_image_presheaf_ι], end } } instance : limits.has_images (Sheaf J (Type (max v u))) := ⟨λ _ _ f, ⟨⟨image_factorization f⟩⟩⟩ end image end category_theory.grothendieck_topology
a0772cef3ea55002a0b423dd3f491495eac86268
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/ring_theory/valuation/integers.lean
f1e917a727c7ba140a865be79530639916a61256
[ "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,331
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 ring_theory.valuation.basic /-! # Ring of integers under a given valuation > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. The elements with valuation less than or equal to 1. TODO: Define characteristic predicate. -/ universes u v w namespace valuation section ring variables {R : Type u} {Γ₀ : Type v} [ring R] [linear_ordered_comm_group_with_zero Γ₀] variables (v : valuation R Γ₀) /-- The ring of integers under a given valuation is the subring of elements with valuation ≤ 1. -/ def integer : subring R := { carrier := { x | v x ≤ 1 }, one_mem' := le_of_eq v.map_one, mul_mem' := λ x y hx hy, trans_rel_right (≤) (v.map_mul x y) (mul_le_one' hx hy), zero_mem' := trans_rel_right (≤) v.map_zero zero_le_one, add_mem' := λ x y hx hy, le_trans (v.map_add x y) (max_le hx hy), neg_mem' := λ x hx, trans_rel_right (≤) (v.map_neg x) hx } end ring section comm_ring variables {R : Type u} {Γ₀ : Type v} [comm_ring R] [linear_ordered_comm_group_with_zero Γ₀] variables (v : valuation R Γ₀) variables (O : Type w) [comm_ring O] [algebra O R] /-- Given a valuation v : R → Γ₀ and a ring homomorphism O →+* R, we say that O is the integers of v if f is injective, and its range is exactly `v.integer`. -/ structure integers : Prop := (hom_inj : function.injective (algebra_map O R)) (map_le_one : ∀ x, v (algebra_map O R x) ≤ 1) (exists_of_le_one : ∀ ⦃r⦄, v r ≤ 1 → ∃ x, algebra_map O R x = r) -- typeclass shortcut instance : algebra v.integer R := algebra.of_subring v.integer theorem integer.integers : v.integers v.integer := { hom_inj := subtype.coe_injective, map_le_one := λ r, r.2, exists_of_le_one := λ r hr, ⟨⟨r, hr⟩, rfl⟩ } namespace integers variables {v O} (hv : integers v O) include hv lemma one_of_is_unit {x : O} (hx : is_unit x) : v (algebra_map O R x) = 1 := let ⟨u, hu⟩ := hx in le_antisymm (hv.2 _) $ by { rw [← v.map_one, ← (algebra_map O R).map_one, ← u.mul_inv, ← mul_one (v (algebra_map O R x)), hu, (algebra_map O R).map_mul, v.map_mul], exact mul_le_mul_left' (hv.2 (u⁻¹ : units O)) _ } lemma is_unit_of_one {x : O} (hx : is_unit (algebra_map O R x)) (hvx : v (algebra_map O R x) = 1) : is_unit x := let ⟨u, hu⟩ := hx in have h1 : v u ≤ 1, from hu.symm ▸ hv.2 x, have h2 : v (u⁻¹ : Rˣ) ≤ 1, by rw [← one_mul (v _), ← hvx, ← v.map_mul, ← hu, u.mul_inv, hu, hvx, v.map_one], let ⟨r1, hr1⟩ := hv.3 h1, ⟨r2, hr2⟩ := hv.3 h2 in ⟨⟨r1, r2, hv.1 $ by rw [ring_hom.map_mul, ring_hom.map_one, hr1, hr2, units.mul_inv], hv.1 $ by rw [ring_hom.map_mul, ring_hom.map_one, hr1, hr2, units.inv_mul]⟩, hv.1 $ hr1.trans hu⟩ lemma le_of_dvd {x y : O} (h : x ∣ y) : v (algebra_map O R y) ≤ v (algebra_map O R x) := let ⟨z, hz⟩ := h in by { rw [← mul_one (v (algebra_map O R x)), hz, ring_hom.map_mul, v.map_mul], exact mul_le_mul_left' (hv.2 z) _ } end integers end comm_ring section field variables {F : Type u} {Γ₀ : Type v} [field F] [linear_ordered_comm_group_with_zero Γ₀] variables {v : valuation F Γ₀} {O : Type w} [comm_ring O] [algebra O F] (hv : integers v O) include hv namespace integers lemma dvd_of_le {x y : O} (h : v (algebra_map O F x) ≤ v (algebra_map O F y)) : y ∣ x := classical.by_cases (λ hy : algebra_map O F y = 0, have hx : x = 0, from hv.1 $ (algebra_map O F).map_zero.symm ▸ (v.zero_iff.1 $ le_zero_iff.1 (v.map_zero ▸ hy ▸ h)), hx.symm ▸ dvd_zero y) $ λ hy : algebra_map O F y ≠ 0, have v ((algebra_map O F y)⁻¹ * algebra_map O F x) ≤ 1, by { rw [← v.map_one, ← inv_mul_cancel hy, v.map_mul, v.map_mul], exact mul_le_mul_left' h _ }, let ⟨z, hz⟩ := hv.3 this in ⟨z, hv.1 $ ((algebra_map O F).map_mul y z).symm ▸ hz.symm ▸ (mul_inv_cancel_left₀ hy _).symm⟩ lemma dvd_iff_le {x y : O} : x ∣ y ↔ v (algebra_map O F y) ≤ v (algebra_map O F x) := ⟨hv.le_of_dvd, hv.dvd_of_le⟩ lemma le_iff_dvd {x y : O} : v (algebra_map O F x) ≤ v (algebra_map O F y) ↔ y ∣ x := ⟨hv.dvd_of_le, hv.le_of_dvd⟩ end integers end field end valuation
1e9d4a7c720afd156374173a4a2d33a0a11018cb
7453f4f6074a6d5ce92b7bee2b29c409c061fbef
/src/Interpolation/fin_lemmas.lean
00a73e0caaeee0c82a6a296ecf5e12d9d26e0e6a
[ "Apache-2.0" ]
permissive
stanescuUW/numerical-analysis-with-Lean
b7b26755b8e925279f3afc1caa16b0666fc77ef8
98e6974f8b68cc5232ceff40535d776a33444c73
refs/heads/master
1,670,371,433,242
1,598,204,960,000
1,598,204,960,000
282,081,575
0
0
null
null
null
null
UTF-8
Lean
false
false
4,380
lean
import data.fin import tactic -- This does exist in mathlib lemma fin_zero_le_any_val (n : ℕ) : ∀ i : fin (n + 2), 0 ≤ i := begin intro i, have j0 : 0 < n + 1 + 1, linarith, have j0 := @fin.coe_val_of_lt (n+1) 0 j0, have h3 : 0 ≤ i.val, linarith, apply fin.le_iff_val_le_val.mpr, rw ← j0 at h3, exact h3, end lemma fin_zero_le_any_val_v1 (n : ℕ) (i : fin (n + 1)) : 0 ≤ i := fin.le_iff_val_le_val.mpr $ nat.zero_le _ -- This exists in mathlib, but in a form that is not immediately useful lemma fin_le_last_val (n : ℕ) (i : fin (n + 2)) : i ≤ (n+1) := begin have j0 : n + 1 < n + 1 + 1, linarith, have j0 := @fin.coe_val_of_lt (n+1) (n+1) j0, have h3 : i.val ≤ n + 1, linarith [i.is_lt], apply fin.le_iff_val_le_val.mpr, rw ← j0 at h3, exact h3, end lemma fin_le_last_val_v1 (n : ℕ) (i : fin (n + 1)) : i ≤ n := fin.le_iff_val_le_val.mpr $ (fin.coe_val_of_lt $ nat.lt_succ_self n).symm ▸ nat.le_of_lt_succ i.2 lemma fin_le_last_val_v2 (n : ℕ) : ∀ i : fin (n + 2), i ≤ (n+1) := begin intro i, change i.val ≤ ((_ + _) : fin (n+2)).val, norm_cast, have := i.2, rw fin.coe_val_of_lt; omega end -- Another version with a better name from Y. Pechersky lemma fin.le_coe_last {n : ℕ} (i : fin (n + 1)) : i ≤ n := begin rw [fin.le_def, <-nat.lt_succ_iff, fin.coe_val_of_lt (lt_add_one n)], exact i.is_lt, end /- I'd also like to obtain the result this way lemma fin_le_last_val_v3 (n : ℕ) (i : fin (n + 1)) : i ≤ n := begin have h1 := fin.le_last i, have h01 := @fin.coe_last n, have h2 := fin.last_val n, have h3 := (fin.le_iff_val_le_val).mp h1, rw h2 at h3, obtain ⟨i, hi ⟩ := i, sorry end example {n : ℕ} (i j : fin n) (h : i < j) : n = ↑i + (↑j - ↑i + 1 + (n - 1 - ↑j)) := begin cases i, cases j, dsimp, change i_val < j_val at h, omega, done end -/ -- This is very particular, only needed in my own proof -- This is courtesy Shing Tak Lam lemma shing (n : ℕ) (i j : fin (n+1)) (h : (j.val : fin (n+2)) < (i.val.succ : fin (n+2))) : j.val < i.val.succ := begin change (j.val : fin (n+2)).val < (i.val.succ : fin (n+2)).val at h, rwa [fin.coe_val_of_lt (show j.1 < n + 2, by linarith [j.2]), fin.coe_val_of_lt (show i.1 + 1 < n + 2, by linarith [i.2])] at h, end -- Again thanks to Shing Tak Lam lemma fin_lt_succ (n : ℕ) (i : fin (n + 1)) : (i : fin (n+2)) < (i+1) := begin cases i with i hi, change (_ : fin (n+2)).val < (_ : fin (n+2)).val, simp only [fin.coe_mk, coe_coe], norm_cast, rw [fin.coe_val_of_lt, fin.coe_val_of_lt]; omega, end -- Some `fin` lemmas from Y. Pechersky lemma fin.coe_succ_eq_succ {n : ℕ} (i : fin n) : ((i : fin (n + 1)) + 1) = i.succ := begin rw [fin.eq_iff_veq, fin.succ_val, coe_coe], norm_cast, apply fin.coe_coe_of_lt, exact add_lt_add_right i.is_lt 1 end lemma fin.coe_eq_cast_succ {n : ℕ} (i : fin n) : (i : fin (n + 1)) = i.cast_succ := begin rw [fin.cast_succ, fin.cast_add, fin.cast_le, fin.cast_lt], obtain ⟨i, hi⟩ := i, rw fin.eq_iff_veq, have : i.succ = i + 1 := rfl, simp only [this], apply fin.coe_val_of_lt, exact nat.lt.step hi, end lemma fin.val_coe_eq_self {n : ℕ} (i : fin n) : (i : fin (n + 1)).val = i.val := by { rw fin.coe_eq_cast_succ, refl } lemma fin.lt_succ {n : ℕ} (i : fin n) : (i : fin (n + 1)) < i.succ := begin rw [fin.coe_eq_cast_succ, fin.cast_succ, fin.lt_iff_val_lt_val, fin.cast_add_val, fin.succ_val], exact lt_add_one i.val end lemma fin_lt_succ' (n : ℕ) (i : fin (n + 1)) : (i : fin (n + 2)) < (i + 1) := by { rw fin.coe_succ_eq_succ, exact fin.lt_succ _ } -- Lemmas from Y. Kudryashov @[simp] lemma mk_zero (n : ℕ) : (⟨0, n.zero_lt_succ⟩ : fin (n + 1)) = 0 := rfl @[simp] lemma mk_one (n : ℕ) (hn : 1 < n + 1) : (⟨1, hn⟩ : fin (n + 1)) = 1 := fin.eq_of_veq (nat.mod_eq_of_lt hn).symm @[simp] lemma mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨_, h⟩ : fin n) = bit0 ⟨m, (nat.le_add_right _ _).trans_lt h⟩ := fin.eq_of_veq (nat.mod_eq_of_lt h).symm @[simp] lemma mk_bit1 {m n : ℕ} (h : bit1 m < n + 1) : (⟨bit1 m, h⟩ : fin (n + 1)) = bit1 ⟨m, (nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ := begin ext, simp only [bit1, bit0] at h ⊢, simp only [fin.val_add, fin.one_val, ← nat.add_mod, nat.mod_eq_of_lt h] end
35b41cbc7f92ce628a569bb0db3c627668d2a4fd
56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3
/src/tools/all_decls.lean
b076a54bd69d88416a00bffaf98fa2304ae5028b
[ "Apache-2.0" ]
permissive
DyeKuu/lean-tpe-public
3a9968f286ca182723ef7e7d97e155d8cb6b1e70
750ade767ab28037e80b7a80360d213a875038f8
refs/heads/master
1,682,842,633,115
1,621,330,793,000
1,621,330,793,000
368,475,816
0
0
Apache-2.0
1,621,330,745,000
1,621,330,744,000
null
UTF-8
Lean
false
false
746
lean
import ..utils.util import all section main open tactic meta def main : io unit := do { args ← io.cmdline_args, let dest : string := ((args.nth 0).get_or_else "./data/mathlib_decls.log"), let ignore_decls_fn : environment → declaration → bool := (λ e d, declaration.is_auto_or_internal e d || bnot (declaration.is_theorem d) || d.to_name.is_aux), f ← io.mk_file_handle dest io.mode.append, io.run_tactic' $ do { env ← get_env, decls ← list.filter (λ d, !(ignore_decls_fn env d)) <$> lint_mathlib_decls, for_ decls $ λ decl, do { let decl_name := decl.to_name.to_string, tactic.unsafe_run_io $ io.fs.put_str_ln f decl_name, tactic.trace format!"DECL: {decl_name}" } } } end main
75e1e4f4dc5d817cb23485acfbbf78756422c285
64874bd1010548c7f5a6e3e8902efa63baaff785
/library/data/subtype.lean
67967c5defb30d9ea81bc06ea30b216ac61c54a2
[ "Apache-2.0" ]
permissive
tjiaqi/lean
4634d729795c164664d10d093f3545287c76628f
d0ce4cf62f4246b0600c07e074d86e51f2195e30
refs/heads/master
1,622,323,796,480
1,422,643,069,000
1,422,643,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,282
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: data.subtype Author: Leonardo de Moura, Jeremy Avigad -/ open decidable set_option structure.proj_mk_thm true structure subtype {A : Type} (P : A → Prop) := tag :: (elt_of : A) (has_property : P elt_of) notation `{` binders:55 `|` r:(scoped:1 P, subtype P) `}` := r namespace subtype variables {A : Type} {P : A → Prop} theorem tag_irrelevant {a : A} (H1 H2 : P a) : tag a H1 = tag a H2 := rfl theorem tag_eq {a1 a2 : A} {H1 : P a1} {H2 : P a2} (H3 : a1 = a2) : tag a1 H1 = tag a2 H2 := eq.subst H3 (take H2, tag_irrelevant H1 H2) H2 protected theorem equal {a1 a2 : {x | P x}} : ∀(H : elt_of a1 = elt_of a2), a1 = a2 := destruct a1 (take x1 H1, destruct a2 (take x2 H2 H, tag_eq H)) protected definition is_inhabited [instance] {a : A} (H : P a) : inhabited {x | P x} := inhabited.mk (tag a H) protected definition has_decidable_eq [instance] (H : decidable_eq A) : decidable_eq {x | P x} := take a1 a2 : {x | P x}, have H1 : (a1 = a2) ↔ (elt_of a1 = elt_of a2), from iff.intro (assume H, eq.subst H rfl) (assume H, equal H), decidable_of_decidable_of_iff _ (iff.symm H1) end subtype
c6c867cc3f77c0ec4f8b00c144910a73611e194f
9dc8cecdf3c4634764a18254e94d43da07142918
/src/measure_theory/integral/integral_eq_improper.lean
fe3dcabd1f97e3051bb496ed2b7968006b9e3a34
[ "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
31,858
lean
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Bhavik Mehta -/ import measure_theory.integral.interval_integral import order.filter.at_top_bot /-! # Links between an integral and its "improper" version In its current state, mathlib only knows how to talk about definite ("proper") integrals, in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over `[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**. Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral. Although definite integrals have better properties, they are hardly usable when it comes to computing integrals on unbounded sets, which is much easier using limits. Thus, in this file, we prove various ways of studying the proper integral by studying the improper one. ## Definitions The main definition of this file is `measure_theory.ae_cover`. It is a rather technical definition whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α` equipped with a measure `μ`, one should think of a hypothesis `hφ : ae_cover μ l φ` as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ i, f x ∂μ` as `i` tends to `l`. When using this definition with a measure restricted to a set `s`, which happens fairly often, one should not try too hard to use a `ae_cover` of subsets of `s`, as it often makes proofs more complicated than necessary. See for example the proof of `measure_theory.integrable_on_Iic_of_interval_integral_norm_tendsto` where we use `(λ x, Ioi x)` as an `ae_cover` w.r.t. `μ.restrict (Iic b)`, instead of using `(λ x, Ioc x b)`. ## Main statements - `measure_theory.ae_cover.lintegral_tendsto_of_countably_generated` : if `φ` is a `ae_cover μ l`, where `l` is a countably generated filter, and if `f` is a measurable `ennreal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l` - `measure_theory.ae_cover.integrable_of_integral_norm_tendsto` : if `φ` is a `ae_cover μ l`, where `l` is a countably generated filter, if `f` is measurable and integrable on each `φ n`, and if `∫ x in φ n, ∥f x∥ ∂μ` tends to some `I : ℝ` as n tends to `l`, then `f` is integrable - `measure_theory.ae_cover.integral_tendsto_of_countably_generated` : if `φ` is a `ae_cover μ l`, where `l` is a countably generated filter, and if `f` is measurable and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`. We then specialize these lemmas to various use cases involving intervals, which are frequent in analysis. -/ open measure_theory filter set topological_space open_locale ennreal nnreal topological_space namespace measure_theory section ae_cover variables {α ι : Type*} [measurable_space α] (μ : measure α) (l : filter ι) /-- A sequence `φ` of subsets of `α` is a `ae_cover` w.r.t. a measure `μ` and a filter `l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of proofs. It should be thought of as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`. See for example `measure_theory.ae_cover.lintegral_tendsto_of_countably_generated`, `measure_theory.ae_cover.integrable_of_integral_norm_tendsto` and `measure_theory.ae_cover.integral_tendsto_of_countably_generated`. -/ structure ae_cover (φ : ι → set α) : Prop := (ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i) (measurable : ∀ i, measurable_set $ φ i) variables {μ} {l} section preorder_α variables [preorder α] [topological_space α] [order_closed_topology α] [opens_measurable_space α] {a b : ι → α} (ha : tendsto a l at_bot) (hb : tendsto b l at_top) lemma ae_cover_Icc : ae_cover μ l (λ i, Icc (a i) (b i)) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_le_at_bot x).mp $ (hb.eventually $ eventually_ge_at_top x).mono $ λ i hbi hai, ⟨hai, hbi⟩ ), measurable := λ i, measurable_set_Icc } lemma ae_cover_Ici : ae_cover μ l (λ i, Ici $ a i) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_le_at_bot x).mono $ λ i hai, hai ), measurable := λ i, measurable_set_Ici } lemma ae_cover_Iic : ae_cover μ l (λ i, Iic $ b i) := { ae_eventually_mem := ae_of_all μ (λ x, (hb.eventually $ eventually_ge_at_top x).mono $ λ i hbi, hbi ), measurable := λ i, measurable_set_Iic } end preorder_α section linear_order_α variables [linear_order α] [topological_space α] [order_closed_topology α] [opens_measurable_space α] {a b : ι → α} (ha : tendsto a l at_bot) (hb : tendsto b l at_top) lemma ae_cover_Ioo [no_min_order α] [no_max_order α] : ae_cover μ l (λ i, Ioo (a i) (b i)) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_lt_at_bot x).mp $ (hb.eventually $ eventually_gt_at_top x).mono $ λ i hbi hai, ⟨hai, hbi⟩ ), measurable := λ i, measurable_set_Ioo } lemma ae_cover_Ioc [no_min_order α] : ae_cover μ l (λ i, Ioc (a i) (b i)) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_lt_at_bot x).mp $ (hb.eventually $ eventually_ge_at_top x).mono $ λ i hbi hai, ⟨hai, hbi⟩ ), measurable := λ i, measurable_set_Ioc } lemma ae_cover_Ico [no_max_order α] : ae_cover μ l (λ i, Ico (a i) (b i)) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_le_at_bot x).mp $ (hb.eventually $ eventually_gt_at_top x).mono $ λ i hbi hai, ⟨hai, hbi⟩ ), measurable := λ i, measurable_set_Ico } lemma ae_cover_Ioi [no_min_order α] : ae_cover μ l (λ i, Ioi $ a i) := { ae_eventually_mem := ae_of_all μ (λ x, (ha.eventually $ eventually_lt_at_bot x).mono $ λ i hai, hai ), measurable := λ i, measurable_set_Ioi } lemma ae_cover_Iio [no_max_order α] : ae_cover μ l (λ i, Iio $ b i) := { ae_eventually_mem := ae_of_all μ (λ x, (hb.eventually $ eventually_gt_at_top x).mono $ λ i hbi, hbi ), measurable := λ i, measurable_set_Iio } end linear_order_α section finite_intervals variables [linear_order α] [topological_space α] [order_closed_topology α] [opens_measurable_space α] {a b : ι → α} {A B : α} (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) lemma ae_cover_Ioo_of_Icc : ae_cover (μ.restrict $ Ioo A B) l (λ i, Icc (a i) (b i)) := { ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr ( ae_of_all μ (λ x hx, (ha.eventually $ eventually_le_nhds hx.left).mp $ (hb.eventually $ eventually_ge_nhds hx.right).mono $ λ i hbi hai, ⟨hai, hbi⟩)), measurable := λ i, measurable_set_Icc, } lemma ae_cover_Ioo_of_Ico : ae_cover (μ.restrict $ Ioo A B) l (λ i, Ico (a i) (b i)) := { ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr ( ae_of_all μ (λ x hx, (ha.eventually $ eventually_le_nhds hx.left).mp $ (hb.eventually $ eventually_gt_nhds hx.right).mono $ λ i hbi hai, ⟨hai, hbi⟩)), measurable := λ i, measurable_set_Ico, } lemma ae_cover_Ioo_of_Ioc : ae_cover (μ.restrict $ Ioo A B) l (λ i, Ioc (a i) (b i)) := { ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr ( ae_of_all μ (λ x hx, (ha.eventually $ eventually_lt_nhds hx.left).mp $ (hb.eventually $ eventually_ge_nhds hx.right).mono $ λ i hbi hai, ⟨hai, hbi⟩)), measurable := λ i, measurable_set_Ioc, } lemma ae_cover_Ioo_of_Ioo : ae_cover (μ.restrict $ Ioo A B) l (λ i, Ioo (a i) (b i)) := { ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr ( ae_of_all μ (λ x hx, (ha.eventually $ eventually_lt_nhds hx.left).mp $ (hb.eventually $ eventually_gt_nhds hx.right).mono $ λ i hbi hai, ⟨hai, hbi⟩)), measurable := λ i, measurable_set_Ioo, } variables [has_no_atoms μ] lemma ae_cover_Ioc_of_Icc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ioc A B) l (λ i, Icc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Icc ha hb] lemma ae_cover_Ioc_of_Ico (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ioc A B) l (λ i, Ico (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ico ha hb] lemma ae_cover_Ioc_of_Ioc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ioc A B) l (λ i, Ioc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ioc ha hb] lemma ae_cover_Ioc_of_Ioo (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ioc A B) l (λ i, Ioo (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ioo ha hb] lemma ae_cover_Ico_of_Icc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ico A B) l (λ i, Icc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Icc ha hb] lemma ae_cover_Ico_of_Ico (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ico A B) l (λ i, Ico (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ico ha hb] lemma ae_cover_Ico_of_Ioc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ico A B) l (λ i, Ioc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ioc ha hb] lemma ae_cover_Ico_of_Ioo (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Ico A B) l (λ i, Ioo (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ioo ha hb] lemma ae_cover_Icc_of_Icc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Icc A B) l (λ i, Icc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Icc ha hb] lemma ae_cover_Icc_of_Ico (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Icc A B) l (λ i, Ico (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ico ha hb] lemma ae_cover_Icc_of_Ioc (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Icc A B) l (λ i, Ioc (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ioc ha hb] lemma ae_cover_Icc_of_Ioo (ha : tendsto a l (𝓝 A)) (hb : tendsto b l (𝓝 B)) : ae_cover (μ.restrict $ Icc A B) l (λ i, Ioo (a i) (b i)) := by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ioo ha hb] end finite_intervals lemma ae_cover.restrict {φ : ι → set α} (hφ : ae_cover μ l φ) {s : set α} : ae_cover (μ.restrict s) l φ := { ae_eventually_mem := ae_restrict_of_ae hφ.ae_eventually_mem, measurable := hφ.measurable } lemma ae_cover_restrict_of_ae_imp {s : set α} {φ : ι → set α} (hs : measurable_set s) (ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n) (measurable : ∀ n, measurable_set $ φ n) : ae_cover (μ.restrict s) l φ := { ae_eventually_mem := by rwa ae_restrict_iff' hs, measurable := measurable } lemma ae_cover.inter_restrict {φ : ι → set α} (hφ : ae_cover μ l φ) {s : set α} (hs : measurable_set s) : ae_cover (μ.restrict s) l (λ i, φ i ∩ s) := ae_cover_restrict_of_ae_imp hs (hφ.ae_eventually_mem.mono (λ x hx hxs, hx.mono $ λ i hi, ⟨hi, hxs⟩)) (λ i, (hφ.measurable i).inter hs) lemma ae_cover.ae_tendsto_indicator {β : Type*} [has_zero β] [topological_space β] (f : α → β) {φ : ι → set α} (hφ : ae_cover μ l φ) : ∀ᵐ x ∂μ, tendsto (λ i, (φ i).indicator f x) l (𝓝 $ f x) := hφ.ae_eventually_mem.mono (λ x hx, tendsto_const_nhds.congr' $ hx.mono $ λ n hn, (indicator_of_mem hn _).symm) lemma ae_cover.ae_measurable {β : Type*} [measurable_space β] [l.is_countably_generated] [l.ne_bot] {f : α → β} {φ : ι → set α} (hφ : ae_cover μ l φ) (hfm : ∀ i, ae_measurable f (μ.restrict $ φ i)) : ae_measurable f μ := begin obtain ⟨u, hu⟩ := l.exists_seq_tendsto, have := ae_measurable_Union_iff.mpr (λ (n : ℕ), hfm (u n)), rwa measure.restrict_eq_self_of_ae_mem at this, filter_upwards [hφ.ae_eventually_mem] with x hx using let ⟨i, hi⟩ := (hu.eventually hx).exists in mem_Union.mpr ⟨i, hi⟩ end lemma ae_cover.ae_strongly_measurable {β : Type*} [topological_space β] [pseudo_metrizable_space β] [l.is_countably_generated] [l.ne_bot] {f : α → β} {φ : ι → set α} (hφ : ae_cover μ l φ) (hfm : ∀ i, ae_strongly_measurable f (μ.restrict $ φ i)) : ae_strongly_measurable f μ := begin obtain ⟨u, hu⟩ := l.exists_seq_tendsto, have := ae_strongly_measurable_Union_iff.mpr (λ (n : ℕ), hfm (u n)), rwa measure.restrict_eq_self_of_ae_mem at this, filter_upwards [hφ.ae_eventually_mem] with x hx using let ⟨i, hi⟩ := (hu.eventually hx).exists in mem_Union.mpr ⟨i, hi⟩ end end ae_cover lemma ae_cover.comp_tendsto {α ι ι' : Type*} [measurable_space α] {μ : measure α} {l : filter ι} {l' : filter ι'} {φ : ι → set α} (hφ : ae_cover μ l φ) {u : ι' → ι} (hu : tendsto u l' l) : ae_cover μ l' (φ ∘ u) := { ae_eventually_mem := hφ.ae_eventually_mem.mono (λ x hx, hu.eventually hx), measurable := λ i, hφ.measurable (u i) } section ae_cover_Union_Inter_countable variables {α ι : Type*} [countable ι] [measurable_space α] {μ : measure α} lemma ae_cover.bUnion_Iic_ae_cover [preorder ι] {φ : ι → set α} (hφ : ae_cover μ at_top φ) : ae_cover μ at_top (λ (n : ι), ⋃ k (h : k ∈ Iic n), φ k) := { ae_eventually_mem := hφ.ae_eventually_mem.mono (λ x h, h.mono (λ i hi, mem_bUnion right_mem_Iic hi)), measurable := λ i, measurable_set.bUnion (to_countable _) (λ n _, hφ.measurable n) } lemma ae_cover.bInter_Ici_ae_cover [semilattice_sup ι] [nonempty ι] {φ : ι → set α} (hφ : ae_cover μ at_top φ) : ae_cover μ at_top (λ (n : ι), ⋂ k (h : k ∈ Ici n), φ k) := { ae_eventually_mem := hφ.ae_eventually_mem.mono begin intros x h, rw eventually_at_top at *, rcases h with ⟨i, hi⟩, use i, intros j hj, exact mem_bInter (λ k hk, hi k (le_trans hj hk)), end, measurable := λ i, measurable_set.bInter (to_countable _) (λ n _, hφ.measurable n) } end ae_cover_Union_Inter_countable section lintegral variables {α ι : Type*} [measurable_space α] {μ : measure α} {l : filter ι} private lemma lintegral_tendsto_of_monotone_of_nat {φ : ℕ → set α} (hφ : ae_cover μ at_top φ) (hmono : monotone φ) {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) : tendsto (λ i, ∫⁻ x in φ i, f x ∂μ) at_top (𝓝 $ ∫⁻ x, f x ∂μ) := let F := λ n, (φ n).indicator f in have key₁ : ∀ n, ae_measurable (F n) μ, from λ n, hfm.indicator (hφ.measurable n), have key₂ : ∀ᵐ (x : α) ∂μ, monotone (λ n, F n x), from ae_of_all _ (λ x i j hij, indicator_le_indicator_of_subset (hmono hij) (λ x, zero_le $ f x) x), have key₃ : ∀ᵐ (x : α) ∂μ, tendsto (λ n, F n x) at_top (𝓝 (f x)), from hφ.ae_tendsto_indicator f, (lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr (λ n, lintegral_indicator f (hφ.measurable n)) lemma ae_cover.lintegral_tendsto_of_nat {φ : ℕ → set α} (hφ : ae_cover μ at_top φ) {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) : tendsto (λ i, ∫⁻ x in φ i, f x ∂μ) at_top (𝓝 $ ∫⁻ x, f x ∂μ) := begin have lim₁ := lintegral_tendsto_of_monotone_of_nat (hφ.bInter_Ici_ae_cover) (λ i j hij, bInter_subset_bInter_left (Ici_subset_Ici.mpr hij)) hfm, have lim₂ := lintegral_tendsto_of_monotone_of_nat (hφ.bUnion_Iic_ae_cover) (λ i j hij, bUnion_subset_bUnion_left (Iic_subset_Iic.mpr hij)) hfm, have le₁ := λ n, lintegral_mono_set (bInter_subset_of_mem left_mem_Ici), have le₂ := λ n, lintegral_mono_set (subset_bUnion_of_mem right_mem_Iic), exact tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ le₁ le₂ end lemma ae_cover.lintegral_tendsto_of_countably_generated [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) : tendsto (λ i, ∫⁻ x in φ i, f x ∂μ) l (𝓝 $ ∫⁻ x, f x ∂μ) := tendsto_of_seq_tendsto (λ u hu, (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm) lemma ae_cover.lintegral_eq_of_tendsto [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : ae_measurable f μ) (htendsto : tendsto (λ i, ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I := tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto lemma ae_cover.supr_lintegral_eq_of_countably_generated [nonempty ι] [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) : (⨆ (i : ι), ∫⁻ x in φ i, f x ∂μ) = ∫⁻ x, f x ∂μ := begin have := hφ.lintegral_tendsto_of_countably_generated hfm, refine csupr_eq_of_forall_le_of_forall_lt_exists_gt (λ i, lintegral_mono' measure.restrict_le_self le_rfl) (λ w hw, _), rcases exists_between hw with ⟨m, hm₁, hm₂⟩, rcases (eventually_ge_of_tendsto_gt hm₂ this).exists with ⟨i, hi⟩, exact ⟨i, lt_of_lt_of_le hm₁ hi⟩, end end lintegral section integrable variables {α ι E : Type*} [measurable_space α] {μ : measure α} {l : filter ι} [normed_add_comm_group E] lemma ae_cover.integrable_of_lintegral_nnnorm_bounded [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ) (hfm : ae_strongly_measurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ∥f x∥₊ ∂μ ≤ ennreal.of_real I) : integrable f μ := begin refine ⟨hfm, (le_of_tendsto _ hbounded).trans_lt ennreal.of_real_lt_top⟩, exact hφ.lintegral_tendsto_of_countably_generated hfm.ennnorm end lemma ae_cover.integrable_of_lintegral_nnnorm_tendsto [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ) (hfm : ae_strongly_measurable f μ) (htendsto : tendsto (λ i, ∫⁻ x in φ i, ∥f x∥₊ ∂μ) l (𝓝 $ ennreal.of_real I)) : integrable f μ := begin refine hφ.integrable_of_lintegral_nnnorm_bounded (max 1 (I + 1)) hfm _, refine htendsto.eventually (ge_mem_nhds _), refine (ennreal.of_real_lt_of_real_iff (lt_max_of_lt_left zero_lt_one)).2 _, exact lt_max_of_lt_right (lt_add_one I), end lemma ae_cover.integrable_of_lintegral_nnnorm_bounded' [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : ae_strongly_measurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ∥f x∥₊ ∂μ ≤ I) : integrable f μ := hφ.integrable_of_lintegral_nnnorm_bounded I hfm (by simpa only [ennreal.of_real_coe_nnreal] using hbounded) lemma ae_cover.integrable_of_lintegral_nnnorm_tendsto' [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : ae_strongly_measurable f μ) (htendsto : tendsto (λ i, ∫⁻ x in φ i, ∥f x∥₊ ∂μ) l (𝓝 I)) : integrable f μ := hφ.integrable_of_lintegral_nnnorm_tendsto I hfm (by simpa only [ennreal.of_real_coe_nnreal] using htendsto) lemma ae_cover.integrable_of_integral_norm_bounded [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, integrable_on f (φ i) μ) (hbounded : ∀ᶠ i in l, ∫ x in φ i, ∥f x∥ ∂μ ≤ I) : integrable f μ := begin have hfm : ae_strongly_measurable f μ := hφ.ae_strongly_measurable (λ i, (hfi i).ae_strongly_measurable), refine hφ.integrable_of_lintegral_nnnorm_bounded I hfm _, conv at hbounded in (integral _ _) { rw integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (λ x, @norm_nonneg E _ (f x))) hfm.norm.restrict }, conv at hbounded in (ennreal.of_real _) { dsimp, rw ← coe_nnnorm, rw ennreal.of_real_coe_nnreal }, refine hbounded.mono (λ i hi, _), rw ←ennreal.of_real_to_real (ne_top_of_lt (hfi i).2), apply ennreal.of_real_le_of_real hi, end lemma ae_cover.integrable_of_integral_norm_tendsto [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, integrable_on f (φ i) μ) (htendsto : tendsto (λ i, ∫ x in φ i, ∥f x∥ ∂μ) l (𝓝 I)) : integrable f μ := let ⟨I', hI'⟩ := htendsto.is_bounded_under_le in hφ.integrable_of_integral_norm_bounded I' hfi hI' lemma ae_cover.integrable_of_integral_bounded_of_nonneg_ae [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, integrable_on f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, ∫ x in φ i, f x ∂μ ≤ I) : integrable f μ := hφ.integrable_of_integral_norm_bounded I hfi $ hbounded.mono $ λ i hi, (integral_congr_ae $ ae_restrict_of_ae $ hnng.mono $ λ x, real.norm_of_nonneg).le.trans hi lemma ae_cover.integrable_of_integral_tendsto_of_nonneg_ae [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, integrable_on f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : tendsto (λ i, ∫ x in φ i, f x ∂μ) l (𝓝 I)) : integrable f μ := let ⟨I', hI'⟩ := htendsto.is_bounded_under_le in hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI' end integrable section integral variables {α ι E : Type*} [measurable_space α] {μ : measure α} {l : filter ι} [normed_add_comm_group E] [normed_space ℝ E] [complete_space E] lemma ae_cover.integral_tendsto_of_countably_generated [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (hfi : integrable f μ) : tendsto (λ i, ∫ x in φ i, f x ∂μ) l (𝓝 $ ∫ x, f x ∂μ) := suffices h : tendsto (λ i, ∫ (x : α), (φ i).indicator f x ∂μ) l (𝓝 (∫ (x : α), f x ∂μ)), by { convert h, ext n, rw integral_indicator (hφ.measurable n) }, tendsto_integral_filter_of_dominated_convergence (λ x, ∥f x∥) (eventually_of_forall $ λ i, hfi.ae_strongly_measurable.indicator $ hφ.measurable i) (eventually_of_forall $ λ i, ae_of_all _ $ λ x, norm_indicator_le_norm_self _ _) hfi.norm (hφ.ae_tendsto_indicator f) /-- Slight reformulation of `measure_theory.ae_cover.integral_tendsto_of_countably_generated`. -/ lemma ae_cover.integral_eq_of_tendsto [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → E} (I : E) (hfi : integrable f μ) (h : tendsto (λ n, ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h lemma ae_cover.integral_eq_of_tendsto_of_nonneg_ae [l.ne_bot] [l.is_countably_generated] {φ : ι → set α} (hφ : ae_cover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f) (hfi : ∀ n, integrable_on f (φ n) μ) (htendsto : tendsto (λ n, ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := have hfi' : integrable f μ, from hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto, hφ.integral_eq_of_tendsto I hfi' htendsto end integral section integrable_of_interval_integral variables {ι E : Type*} {μ : measure ℝ} {l : filter ι} [filter.ne_bot l] [is_countably_generated l] [normed_add_comm_group E] {a b : ι → ℝ} {f : ℝ → E} lemma integrable_of_interval_integral_norm_bounded (I : ℝ) (hfi : ∀ i, integrable_on f (Ioc (a i) (b i)) μ) (ha : tendsto a l at_bot) (hb : tendsto b l at_top) (h : ∀ᶠ i in l, ∫ x in a i .. b i, ∥f x∥ ∂μ ≤ I) : integrable f μ := begin have hφ : ae_cover μ l _ := ae_cover_Ioc ha hb, refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp _), filter_upwards [ha.eventually (eventually_le_at_bot 0), hb.eventually (eventually_ge_at_top 0)] with i hai hbi ht, rwa ←interval_integral.integral_of_le (hai.trans hbi) end /-- If `f` is integrable on intervals `Ioc (a i) (b i)`, where `a i` tends to -∞ and `b i` tends to ∞, and `∫ x in a i .. b i, ∥f x∥ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, ∞) -/ lemma integrable_of_interval_integral_norm_tendsto (I : ℝ) (hfi : ∀ i, integrable_on f (Ioc (a i) (b i)) μ) (ha : tendsto a l at_bot) (hb : tendsto b l at_top) (h : tendsto (λ i, ∫ x in a i .. b i, ∥f x∥ ∂μ) l (𝓝 I)) : integrable f μ := let ⟨I', hI'⟩ := h.is_bounded_under_le in integrable_of_interval_integral_norm_bounded I' hfi ha hb hI' lemma integrable_on_Iic_of_interval_integral_norm_bounded (I b : ℝ) (hfi : ∀ i, integrable_on f (Ioc (a i) b) μ) (ha : tendsto a l at_bot) (h : ∀ᶠ i in l, (∫ x in a i .. b, ∥f x∥ ∂μ) ≤ I) : integrable_on f (Iic b) μ := begin have hφ : ae_cover (μ.restrict $ Iic b) l _ := ae_cover_Ioi ha, have hfi : ∀ i, integrable_on f (Ioi (a i)) (μ.restrict $ Iic b), { intro i, rw [integrable_on, measure.restrict_restrict (hφ.measurable i)], exact hfi i }, refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp _), filter_upwards [ha.eventually (eventually_le_at_bot b)] with i hai, rw [interval_integral.integral_of_le hai, measure.restrict_restrict (hφ.measurable i)], exact id end /-- If `f` is integrable on intervals `Ioc (a i) b`, where `a i` tends to -∞, and `∫ x in a i .. b, ∥f x∥ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, b) -/ lemma integrable_on_Iic_of_interval_integral_norm_tendsto (I b : ℝ) (hfi : ∀ i, integrable_on f (Ioc (a i) b) μ) (ha : tendsto a l at_bot) (h : tendsto (λ i, ∫ x in a i .. b, ∥f x∥ ∂μ) l (𝓝 I)) : integrable_on f (Iic b) μ := let ⟨I', hI'⟩ := h.is_bounded_under_le in integrable_on_Iic_of_interval_integral_norm_bounded I' b hfi ha hI' lemma integrable_on_Ioi_of_interval_integral_norm_bounded (I a : ℝ) (hfi : ∀ i, integrable_on f (Ioc a (b i)) μ) (hb : tendsto b l at_top) (h : ∀ᶠ i in l, (∫ x in a .. b i, ∥f x∥ ∂μ) ≤ I) : integrable_on f (Ioi a) μ := begin have hφ : ae_cover (μ.restrict $ Ioi a) l _ := ae_cover_Iic hb, have hfi : ∀ i, integrable_on f (Iic (b i)) (μ.restrict $ Ioi a), { intro i, rw [integrable_on, measure.restrict_restrict (hφ.measurable i), inter_comm], exact hfi i }, refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp _), filter_upwards [hb.eventually (eventually_ge_at_top a)] with i hbi, rw [interval_integral.integral_of_le hbi, measure.restrict_restrict (hφ.measurable i), inter_comm], exact id end /-- If `f` is integrable on intervals `Ioc a (b i)`, where `b i` tends to ∞, and `∫ x in a .. b i, ∥f x∥ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (a, ∞) -/ lemma integrable_on_Ioi_of_interval_integral_norm_tendsto (I a : ℝ) (hfi : ∀ i, integrable_on f (Ioc a (b i)) μ) (hb : tendsto b l at_top) (h : tendsto (λ i, ∫ x in a .. b i, ∥f x∥ ∂μ) l (𝓝 $ I)) : integrable_on f (Ioi a) μ := let ⟨I', hI'⟩ := h.is_bounded_under_le in integrable_on_Ioi_of_interval_integral_norm_bounded I' a hfi hb hI' lemma integrable_on_Ioc_of_interval_integral_norm_bounded {I a₀ b₀ : ℝ} (hfi : ∀ i, integrable_on f $ Ioc (a i) (b i)) (ha : tendsto a l $ 𝓝 a₀) (hb : tendsto b l $ 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ∥f x∥) ≤ I) : integrable_on f (Ioc a₀ b₀) := begin refine (ae_cover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I (λ i, (hfi i).restrict measurable_set_Ioc) (eventually.mono h _), intros i hi, simp only [measure.restrict_restrict measurable_set_Ioc], refine le_trans (set_integral_mono_set (hfi i).norm _ _) hi, { apply ae_of_all, simp only [pi.zero_apply, norm_nonneg, forall_const] }, { apply ae_of_all, intros c hc, exact hc.1 }, end lemma integrable_on_Ioc_of_interval_integral_norm_bounded_left {I a₀ b : ℝ} (hfi : ∀ i, integrable_on f $ Ioc (a i) b) (ha : tendsto a l $ 𝓝 a₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ∥f x∥ ) ≤ I) : integrable_on f (Ioc a₀ b) := integrable_on_Ioc_of_interval_integral_norm_bounded hfi ha tendsto_const_nhds h lemma integrable_on_Ioc_of_interval_integral_norm_bounded_right {I a b₀ : ℝ} (hfi : ∀ i, integrable_on f $ Ioc a (b i)) (hb : tendsto b l $ 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ∥f x∥ ) ≤ I) : integrable_on f (Ioc a b₀) := integrable_on_Ioc_of_interval_integral_norm_bounded hfi tendsto_const_nhds hb h end integrable_of_interval_integral section integral_of_interval_integral variables {ι E : Type*} {μ : measure ℝ} {l : filter ι} [is_countably_generated l] [normed_add_comm_group E] [normed_space ℝ E] [complete_space E] {a b : ι → ℝ} {f : ℝ → E} lemma interval_integral_tendsto_integral (hfi : integrable f μ) (ha : tendsto a l at_bot) (hb : tendsto b l at_top) : tendsto (λ i, ∫ x in a i .. b i, f x ∂μ) l (𝓝 $ ∫ x, f x ∂μ) := begin let φ := λ i, Ioc (a i) (b i), have hφ : ae_cover μ l φ := ae_cover_Ioc ha hb, refine (hφ.integral_tendsto_of_countably_generated hfi).congr' _, filter_upwards [ha.eventually (eventually_le_at_bot 0), hb.eventually (eventually_ge_at_top 0)] with i hai hbi, exact (interval_integral.integral_of_le (hai.trans hbi)).symm end lemma interval_integral_tendsto_integral_Iic (b : ℝ) (hfi : integrable_on f (Iic b) μ) (ha : tendsto a l at_bot) : tendsto (λ i, ∫ x in a i .. b, f x ∂μ) l (𝓝 $ ∫ x in Iic b, f x ∂μ) := begin let φ := λ i, Ioi (a i), have hφ : ae_cover (μ.restrict $ Iic b) l φ := ae_cover_Ioi ha, refine (hφ.integral_tendsto_of_countably_generated hfi).congr' _, filter_upwards [ha.eventually (eventually_le_at_bot $ b)] with i hai, rw [interval_integral.integral_of_le hai, measure.restrict_restrict (hφ.measurable i)], refl, end lemma interval_integral_tendsto_integral_Ioi (a : ℝ) (hfi : integrable_on f (Ioi a) μ) (hb : tendsto b l at_top) : tendsto (λ i, ∫ x in a .. b i, f x ∂μ) l (𝓝 $ ∫ x in Ioi a, f x ∂μ) := begin let φ := λ i, Iic (b i), have hφ : ae_cover (μ.restrict $ Ioi a) l φ := ae_cover_Iic hb, refine (hφ.integral_tendsto_of_countably_generated hfi).congr' _, filter_upwards [hb.eventually (eventually_ge_at_top $ a)] with i hbi, rw [interval_integral.integral_of_le hbi, measure.restrict_restrict (hφ.measurable i), inter_comm], refl, end end integral_of_interval_integral end measure_theory
d0b6f0ffb6b0b1b5cd259c0da0f47ab97edf0528
31f556cdeb9239ffc2fad8f905e33987ff4feab9
/stage0/src/Init/Data/Float.lean
ee44c8ec5353e563a75c829cb9ff32ffb63393c2
[ "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
tobiasgrosser/lean4
ce0fd9cca0feba1100656679bf41f0bffdbabb71
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
refs/heads/master
1,673,103,412,948
1,664,930,501,000
1,664,930,501,000
186,870,185
0
0
Apache-2.0
1,665,129,237,000
1,557,939,901,000
Lean
UTF-8
Lean
false
false
5,747
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 -/ prelude import Init.Core import Init.Data.Int.Basic import Init.Data.ToString.Basic structure FloatSpec where float : Type val : float lt : float → float → Prop le : float → float → Prop decLt : DecidableRel lt decLe : DecidableRel le -- Just show FloatSpec is inhabited. opaque floatSpec : FloatSpec := { float := Unit, val := (), lt := fun _ _ => True, le := fun _ _ => True, decLt := fun _ _ => inferInstanceAs (Decidable True), decLe := fun _ _ => inferInstanceAs (Decidable True) } structure Float where val : floatSpec.float instance : Inhabited Float := ⟨{ val := floatSpec.val }⟩ @[extern "lean_float_add"] opaque Float.add : Float → Float → Float @[extern "lean_float_sub"] opaque Float.sub : Float → Float → Float @[extern "lean_float_mul"] opaque Float.mul : Float → Float → Float @[extern "lean_float_div"] opaque Float.div : Float → Float → Float @[extern "lean_float_negate"] opaque Float.neg : Float → Float set_option bootstrap.genMatcherCode false def Float.lt : Float → Float → Prop := fun a b => match a, b with | ⟨a⟩, ⟨b⟩ => floatSpec.lt a b def Float.le : Float → Float → Prop := fun a b => floatSpec.le a.val b.val instance : Add Float := ⟨Float.add⟩ instance : Sub Float := ⟨Float.sub⟩ instance : Mul Float := ⟨Float.mul⟩ instance : Div Float := ⟨Float.div⟩ instance : Neg Float := ⟨Float.neg⟩ instance : LT Float := ⟨Float.lt⟩ instance : LE Float := ⟨Float.le⟩ /-- Note: this is not reflexive since `NaN != NaN`.-/ @[extern "lean_float_beq"] opaque Float.beq (a b : Float) : Bool instance : BEq Float := ⟨Float.beq⟩ @[extern "lean_float_decLt"] opaque Float.decLt (a b : Float) : Decidable (a < b) := match a, b with | ⟨a⟩, ⟨b⟩ => floatSpec.decLt a b @[extern "lean_float_decLe"] opaque Float.decLe (a b : Float) : Decidable (a ≤ b) := match a, b with | ⟨a⟩, ⟨b⟩ => floatSpec.decLe a b instance floatDecLt (a b : Float) : Decidable (a < b) := Float.decLt a b instance floatDecLe (a b : Float) : Decidable (a ≤ b) := Float.decLe a b @[extern "lean_float_to_string"] opaque Float.toString : Float → String /-- If the given float is positive, truncates the value to the nearest positive integer. If negative or larger than the maximum value for UInt8, returns 0. -/ @[extern "lean_float_to_uint8"] opaque Float.toUInt8 : Float → UInt8 /-- If the given float is positive, truncates the value to the nearest positive integer. If negative or larger than the maximum value for UInt16, returns 0. -/ @[extern "lean_float_to_uint16"] opaque Float.toUInt16 : Float → UInt16 /-- If the given float is positive, truncates the value to the nearest positive integer. If negative or larger than the maximum value for UInt32, returns 0. -/ @[extern "lean_float_to_uint32"] opaque Float.toUInt32 : Float → UInt32 /-- If the given float is positive, truncates the value to the nearest positive integer. If negative or larger than the maximum value for UInt64, returns 0. -/ @[extern "lean_float_to_uint64"] opaque Float.toUInt64 : Float → UInt64 /-- If the given float is positive, truncates the value to the nearest positive integer. If negative or larger than the maximum value for USize, returns 0. -/ @[extern "lean_float_to_usize"] opaque Float.toUSize : Float → USize @[extern "lean_float_isnan"] opaque Float.isNaN : Float → Bool @[extern "lean_float_isfinite"] opaque Float.isFinite : Float → Bool @[extern "lean_float_isinf"] opaque Float.isInf : Float → Bool /-- Splits the given float `x` into a significand/exponent pair `(s, i)` such that `x = s * 2^i` where `s ∈ (-1;-0.5] ∪ [0.5; 1)`. Returns an undefined value if `x` is not finite. -/ @[extern "lean_float_frexp"] opaque Float.frExp : Float → Float × Int instance : ToString Float where toString := Float.toString instance : Repr Float where reprPrec n _ := Float.toString n instance : ReprAtom Float := ⟨⟩ @[extern "lean_uint64_to_float"] opaque UInt64.toFloat (n : UInt64) : Float @[extern "sin"] opaque Float.sin : Float → Float @[extern "cos"] opaque Float.cos : Float → Float @[extern "tan"] opaque Float.tan : Float → Float @[extern "asin"] opaque Float.asin : Float → Float @[extern "acos"] opaque Float.acos : Float → Float @[extern "atan"] opaque Float.atan : Float → Float @[extern "atan2"] opaque Float.atan2 : Float → Float → Float @[extern "sinh"] opaque Float.sinh : Float → Float @[extern "cosh"] opaque Float.cosh : Float → Float @[extern "tanh"] opaque Float.tanh : Float → Float @[extern "asinh"] opaque Float.asinh : Float → Float @[extern "acosh"] opaque Float.acosh : Float → Float @[extern "atanh"] opaque Float.atanh : Float → Float @[extern "exp"] opaque Float.exp : Float → Float @[extern "exp2"] opaque Float.exp2 : Float → Float @[extern "log"] opaque Float.log : Float → Float @[extern "log2"] opaque Float.log2 : Float → Float @[extern "log10"] opaque Float.log10 : Float → Float @[extern "pow"] opaque Float.pow : Float → Float → Float @[extern "sqrt"] opaque Float.sqrt : Float → Float @[extern "cbrt"] opaque Float.cbrt : Float → Float @[extern "ceil"] opaque Float.ceil : Float → Float @[extern "floor"] opaque Float.floor : Float → Float @[extern "round"] opaque Float.round : Float → Float @[extern "fabs"] opaque Float.abs : Float → Float instance : Pow Float Float := ⟨Float.pow⟩ /-- Efficiently computes `x * 2^i`. -/ @[extern "lean_float_scaleb"] opaque Float.scaleB (x : Float) (i : @& Int) : Float
53d44f46a700f6b3f517593eef3b22dafb6725ea
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/stage0/src/Init/Lean/Parser/Term.lean
c4b150ad97e682904c081493efb8cfd9e6ed52fe
[ "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
13,377
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, Sebastian Ullrich -/ prelude import Init.Lean.Parser.Parser import Init.Lean.Parser.Level namespace Lean namespace Parser @[init] def regBuiltinTacticParserAttr : IO Unit := let leadingIdentAsSymbol := true; registerBuiltinParserAttribute `builtinTacticParser `tactic leadingIdentAsSymbol @[init] def regTacticParserAttribute : IO Unit := registerBuiltinDynamicParserAttribute `tacticParser `tactic @[inline] def tacticParser (rbp : Nat := 0) : Parser := categoryParser `tactic rbp def Tactic.seq : Parser := node `Lean.Parser.Tactic.seq $ sepBy tacticParser "; " true def Tactic.nonEmptySeq : Parser := node `Lean.Parser.Tactic.seq $ sepBy1 tacticParser "; " true def darrow : Parser := unicodeSymbol "⇒" "=>" namespace Term /- Helper functions for defining simple parsers -/ def unicodeInfixR (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser := unicodeSymbol sym asciiSym lbp >> termParser (lbp - 1) def infixR (sym : String) (lbp : Nat) : TrailingParser := symbol sym lbp >> termParser (lbp - 1) def unicodeInfixL (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser := unicodeSymbol sym asciiSym lbp >> termParser lbp def infixL (sym : String) (lbp : Nat) : TrailingParser := symbol sym lbp >> termParser lbp def leadPrec := appPrec - 1 /- Built-in parsers -/ -- NOTE: `checkNoWsBefore` should be used *before* `parser!` so that it is also applied to the generated -- antiquotation. def explicitUniv := checkNoWsBefore "no space before '.{'" >> parser! ".{" >> sepBy1 levelParser ", " >> "}" def namedPattern := checkNoWsBefore "no space before '@'" >> parser! "@" >> termParser appPrec @[builtinTermParser] def id := parser! ident >> optional (explicitUniv <|> namedPattern) @[builtinTermParser] def num : Parser := parser! numLit @[builtinTermParser] def str : Parser := parser! strLit @[builtinTermParser] def char : Parser := parser! charLit @[builtinTermParser] def type := parser! symbol "Type" appPrec @[builtinTermParser] def sort := parser! symbol "Sort" appPrec @[builtinTermParser] def prop := parser! symbol "Prop" appPrec @[builtinTermParser] def hole := parser! symbol "_" appPrec @[builtinTermParser] def namedHole := parser! symbol "?" appPrec >> ident @[builtinTermParser] def «sorry» := parser! symbol "sorry" appPrec @[builtinTermParser] def cdot := parser! symbol "·" appPrec @[builtinTermParser] def emptyC := parser! symbol "∅" appPrec def typeAscription := parser! " : " >> termParser def tupleTail := parser! ", " >> sepBy1 termParser ", " def parenSpecial : Parser := optional (tupleTail <|> typeAscription) @[builtinTermParser] def paren := parser! symbol "(" appPrec >> optional (termParser >> parenSpecial) >> ")" @[builtinTermParser] def anonymousCtor := parser! symbol "⟨" appPrec >> sepBy termParser ", " >> "⟩" def optIdent : Parser := optional (try (ident >> " : ")) @[builtinTermParser] def «if» := parser! symbol "if " leadPrec >> optIdent >> termParser >> " then " >> termParser >> " else " >> termParser def fromTerm := parser! " from " >> termParser def haveAssign := parser! " := " >> termParser @[builtinTermParser] def «have» := parser! symbol "have " leadPrec >> optIdent >> termParser >> (haveAssign <|> fromTerm) >> "; " >> termParser @[builtinTermParser] def «suffices» := parser! symbol "suffices " leadPrec >> optIdent >> termParser >> fromTerm >> "; " >> termParser @[builtinTermParser] def «show» := parser! symbol "show " leadPrec >> termParser >> fromTerm def structInstArrayRef := parser! "[" >> termParser >>"]" def structInstLVal := (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef) def structInstField := parser! structInstLVal >> " := " >> termParser def structInstSource := parser! ".." >> optional termParser @[builtinTermParser] def structInst := parser! symbol "{" appPrec >> optional (try (ident >> checkWsBefore "expected space '.'" >> " . ")) >> sepBy (structInstField <|> structInstSource) ", " true >> "}" def typeSpec := parser! " : " >> termParser def optType : Parser := optional typeSpec @[builtinTermParser] def subtype := parser! "{" >> ident >> optType >> " // " >> termParser >> "}" @[builtinTermParser] def listLit := parser! symbol "[" appPrec >> sepBy termParser "," true >> "]" @[builtinTermParser] def arrayLit := parser! symbol "#[" appPrec >> sepBy termParser "," true >> "]" @[builtinTermParser] def explicit := parser! symbol "@" appPrec >> termParser appPrec @[builtinTermParser] def inaccessible := parser! symbol ".(" appPrec >> termParser >> ")" def binderIdent : Parser := ident <|> hole def binderType (requireType := false) : Parser := if requireType then group (" : " >> termParser) else optional (" : " >> termParser) def binderTactic := parser! try (" := " >> " by ") >> Tactic.nonEmptySeq def binderDefault := parser! " := " >> termParser def explicitBinder (requireType := false) := parser! "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")" def implicitBinder (requireType := false) := parser! "{" >> many1 binderIdent >> binderType requireType >> "}" def instBinder := parser! "[" >> optIdent >> termParser >> "]" def bracktedBinder (requireType := false) := explicitBinder requireType <|> implicitBinder requireType <|> instBinder @[builtinTermParser] def depArrow := parser! bracktedBinder true >> checkRBPGreater 25 "expected parentheses around dependent arrow" >> unicodeSymbol " → " " -> " >> termParser def simpleBinder := parser! many1 binderIdent @[builtinTermParser] def «forall» := parser! unicodeSymbol "∀" "forall" leadPrec >> many1 (simpleBinder <|> bracktedBinder) >> ", " >> termParser def funBinder : Parser := implicitBinder <|> instBinder <|> termParser appPrec @[builtinTermParser] def «fun» := parser! unicodeSymbol "λ" "fun" leadPrec >> many1 funBinder >> darrow >> termParser def matchAlt : Parser := nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $ sepBy1 termParser ", " >> darrow >> termParser def matchAlts (optionalFirstBar := true) : Parser := withPosition $ fun pos => (if optionalFirstBar then optional "|" else "|") >> sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|") @[builtinTermParser] def «match» := parser! symbol "match " leadPrec >> sepBy1 termParser ", " >> optType >> " with " >> matchAlts @[builtinTermParser] def «nomatch» := parser! symbol "nomatch " leadPrec >> termParser @[builtinTermParser] def «parser!» := parser! symbol "parser! " leadPrec >> termParser @[builtinTermParser] def «tparser!» := parser! symbol "tparser! " leadPrec >> termParser @[builtinTermParser] def borrowed := parser! symbol "@&" appPrec >> termParser (appPrec - 1) @[builtinTermParser] def quotedName := parser! nameLit -- NOTE: syntax quotations are defined in Init.Lean.Parser.Command @[builtinTermParser] def «match_syntax» := parser! symbol "match_syntax" leadPrec >> termParser >> " with " >> matchAlts /- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/ def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many bracktedBinder >> optType def letIdDecl : Parser := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl $ try (letIdLhs >> " := ") >> termParser def letPatDecl : Parser := node `Lean.Parser.Term.letDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser def letEqnsDecl : Parser := node `Lean.Parser.Term.letDecl $ letIdLhs >> matchAlts false def letDecl := letIdDecl <|> letPatDecl <|> letEqnsDecl @[builtinTermParser] def «let» := parser! symbol "let " leadPrec >> letDecl >> "; " >> termParser @[builtinTermParser] def «let!» := parser! symbol "let! " leadPrec >> letDecl >> "; " >> termParser def leftArrow : Parser := unicodeSymbol " ← " " <- " def doLet := parser! "let " >> letDecl def doId := parser! try (ident >> optType >> leftArrow) >> termParser def doPat := parser! try (termParser >> leftArrow) >> termParser >> optional (" | " >> termParser) def doExpr := parser! termParser def doElem := doLet <|> doId <|> doPat <|> doExpr def doSeq := sepBy1 doElem "; " def bracketedDoSeq := parser! "{" >> doSeq >> "}" @[builtinTermParser] def liftMethod := parser! leftArrow >> termParser @[builtinTermParser] def «do» := parser! symbol "do " leadPrec >> (bracketedDoSeq <|> doSeq) @[builtinTermParser] def nativeRefl := parser! "nativeRefl! " >> termParser appPrec @[builtinTermParser] def nativeDecide := parser! "nativeDecide! " >> termParser appPrec @[builtinTermParser] def decide := parser! "decide! " >> termParser appPrec @[builtinTermParser] def not := parser! symbol "¬" appPrec >> termParser 40 @[builtinTermParser] def bnot := parser! symbol "!" appPrec >> termParser 40 @[builtinTermParser] def uminus := parser! "-" >> termParser 100 def namedArgument := parser! try ("(" >> ident >> " := ") >> termParser >> ")" @[builtinTermParser] def app := tparser! many1 (namedArgument <|> termParser appPrec) def checkIsSort := checkStackTop (fun stx => stx.isOfKind `Lean.Parser.Term.type || stx.isOfKind `Lean.Parser.Term.sort) @[builtinTermParser] def sortApp := tparser! checkIsSort >> levelParser appPrec @[builtinTermParser] def proj := tparser! symbolNoWs "." (appPrec+1) >> (fieldIdx <|> ident) @[builtinTermParser] def arrow := tparser! unicodeInfixR " → " " -> " 25 @[builtinTermParser] def arrayRef := tparser! symbolNoWs "[" (appPrec+1) >> termParser >>"]" @[builtinTermParser] def dollar := tparser! try (dollarSymbol >> checkWsBefore "space expected") >> termParser 0 @[builtinTermParser] def dollarProj := tparser! symbol "$." 1 >> (fieldIdx <|> ident) @[builtinTermParser] def «where» := tparser! symbol " where " 1 >> sepBy1 letDecl (group ("; " >> " where ")) @[builtinTermParser] def fcomp := tparser! infixR " ∘ " 90 @[builtinTermParser] def prod := tparser! infixR " × " 35 @[builtinTermParser] def add := tparser! infixL " + " 65 @[builtinTermParser] def sub := tparser! infixL " - " 65 @[builtinTermParser] def mul := tparser! infixL " * " 70 @[builtinTermParser] def div := tparser! infixL " / " 70 @[builtinTermParser] def mod := tparser! infixL " % " 70 @[builtinTermParser] def modN := tparser! infixL " %ₙ " 70 @[builtinTermParser] def pow := tparser! infixR " ^ " 80 @[builtinTermParser] def le := tparser! unicodeInfixL " ≤ " " <= " 50 @[builtinTermParser] def ge := tparser! unicodeInfixL " ≥ " " >= " 50 @[builtinTermParser] def lt := tparser! infixL " < " 50 @[builtinTermParser] def gt := tparser! infixL " > " 50 @[builtinTermParser] def eq := tparser! infixL " = " 50 @[builtinTermParser] def ne := tparser! infixL " ≠ " 50 @[builtinTermParser] def beq := tparser! infixL " == " 50 @[builtinTermParser] def bne := tparser! infixL " != " 50 @[builtinTermParser] def heq := tparser! unicodeInfixL " ≅ " " ~= " 50 @[builtinTermParser] def equiv := tparser! infixL " ≈ " 50 @[builtinTermParser] def subst := tparser! symbol " ▸ " 75 >> sepBy1 (termParser 75) " ▸ " @[builtinTermParser] def and := tparser! unicodeInfixR " ∧ " " /\\ " 35 @[builtinTermParser] def or := tparser! unicodeInfixR " ∨ " " \\/ " 30 @[builtinTermParser] def iff := tparser! unicodeInfixL " ↔ " " <-> " 20 @[builtinTermParser] def band := tparser! infixL " && " 35 @[builtinTermParser] def bor := tparser! infixL " || " 30 @[builtinTermParser] def append := tparser! infixL " ++ " 65 @[builtinTermParser] def cons := tparser! infixR " :: " 67 @[builtinTermParser] def orelse := tparser! infixR " <|> " 2 @[builtinTermParser] def orM := tparser! infixR " <||> " 30 @[builtinTermParser] def andM := tparser! infixR " <&&> " 35 @[builtinTermParser] def andthen := tparser! infixR " >> " 60 @[builtinTermParser] def bindOp := tparser! infixR " >>= " 55 @[builtinTermParser] def mapRev := tparser! infixR " <&> " 100 @[builtinTermParser] def seq := tparser! infixL " <*> " 60 @[builtinTermParser] def seqLeft := tparser! infixL " <* " 60 @[builtinTermParser] def seqRight := tparser! infixR " *> " 60 @[builtinTermParser] def map := tparser! infixR " <$> " 100 @[builtinTermParser] def mapConst := tparser! infixR " <$ " 100 @[builtinTermParser] def mapConstRev := tparser! infixR " $> " 100 @[builtinTermParser] def tacticBlock := parser! symbol "begin " appPrec >> Tactic.seq >> "end" @[builtinTermParser] def byTactic := parser! symbol "by " leadPrec >> Tactic.nonEmptySeq -- Use `unboxSingleton` trick similar to the one used at Command.lean for `Term.stxQuot` @[builtinTermParser] def tacticStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(tactic|" appPrec >> sepBy1 tacticParser "; " true true >> ")" @[builtinTermParser] def levelStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(level|" appPrec >> levelParser >> ")" @[builtinTermParser] def funBinderStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(funBinder|" appPrec >> funBinder >> ")" end Term end Parser end Lean
0fd7b50309f8699850a3d6409aee16bc58186487
d1a52c3f208fa42c41df8278c3d280f075eb020c
/src/Lean/ToExpr.lean
a596974b2f6069a6b951f9630ad0b757bce574a9
[ "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
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
2,628
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 -/ import Lean.Expr universe u namespace Lean class ToExpr (α : Type u) where toExpr : α → Expr toTypeExpr : Expr export ToExpr (toExpr toTypeExpr) instance : ToExpr Nat where toExpr := mkNatLit toTypeExpr := mkConst ``Nat instance : ToExpr Bool where toExpr := fun b => if b then mkConst ``Bool.true else mkConst ``Bool.false toTypeExpr := mkConst ``Bool instance : ToExpr Char where toExpr := fun c => mkApp (mkConst ``Char.ofNat) (toExpr c.toNat) toTypeExpr := mkConst ``Char instance : ToExpr String where toExpr := mkStrLit toTypeExpr := mkConst ``String instance : ToExpr Unit where toExpr := fun _ => mkConst `Unit.unit toTypeExpr := mkConst ``Unit def Name.toExprAux : Name → Expr | Name.anonymous => mkConst `Lean.Name.anonymous | Name.str p s _ => mkAppB (mkConst ``Lean.Name.mkStr) (toExprAux p) (toExpr s) | Name.num p n _ => mkAppB (mkConst ``Lean.Name.mkNum) (toExprAux p) (toExpr n) instance : ToExpr Name where toExpr := Name.toExprAux toTypeExpr := mkConst ``Name instance {α : Type} [ToExpr α] : ToExpr (Option α) := let type := toTypeExpr α { toExpr := fun o => match o with | none => mkApp (mkConst ``Option.none [levelZero]) type | some a => mkApp2 (mkConst ``Option.some [levelZero]) type (toExpr a), toTypeExpr := mkApp (mkConst ``Option [levelZero]) type } def List.toExprAux {α} [ToExpr α] (nilFn : Expr) (consFn : Expr) : List α → Expr | [] => nilFn | a::as => mkApp2 consFn (toExpr a) (toExprAux nilFn consFn as) instance {α : Type} [ToExpr α] : ToExpr (List α) := let type := toTypeExpr α let nil := mkApp (mkConst ``List.nil [levelZero]) type let cons := mkApp (mkConst ``List.cons [levelZero]) type { toExpr := List.toExprAux nil cons, toTypeExpr := mkApp (mkConst ``List [levelZero]) type } instance {α : Type} [ToExpr α] : ToExpr (Array α) := let type := toTypeExpr α { toExpr := fun as => mkApp2 (mkConst ``List.toArray [levelZero]) type (toExpr as.toList), toTypeExpr := mkApp (mkConst ``Array [levelZero]) type } instance {α : Type} {β : Type} [ToExpr α] [ToExpr β] : ToExpr (α × β) := let αType := toTypeExpr α let βType := toTypeExpr β { toExpr := fun ⟨a, b⟩ => mkApp4 (mkConst ``Prod.mk [levelZero, levelZero]) αType βType (toExpr a) (toExpr b), toTypeExpr := mkApp2 (mkConst ``Prod [levelZero, levelZero]) αType βType } end Lean
738bf414c3af634de96b0b354ac6e964ca6b0761
9cba98daa30c0804090f963f9024147a50292fa0
/old/geom3d_stamped_test.lean
44a932969f0b24c248d0427a883a42063d2a1642
[]
no_license
kevinsullivan/phys
dcb192f7b3033797541b980f0b4a7e75d84cea1a
ebc2df3779d3605ff7a9b47eeda25c2a551e011f
refs/heads/master
1,637,490,575,500
1,629,899,064,000
1,629,899,064,000
168,012,884
0
3
null
1,629,644,436,000
1,548,699,832,000
Lean
UTF-8
Lean
false
false
3,003
lean
import .geom3d_series import tactic.linarith def ts := time_std_space def world_fr := geom3d_std_frame def world := geom3d_std_space def bl_fr := let origin := mk_position3d world 1.000000 2.000000 3.000000 in let basis0 := mk_displacement3d world 4.000000 3.000000 2.000000 in let basis1 := mk_displacement3d world 1.000000 2.000000 3.000000 in let basis2 := mk_displacement3d world 2.000000 1.000000 2.000000 in mk_geom3d_frame origin basis0 basis1 basis2 def fr1 := let origin := mk_position3d world 2.000000 4.000000 3.000000 in let basis0 := mk_displacement3d world 4.000000 3.000000 2.000000 in let basis1 := mk_displacement3d world 1.000000 2.000000 3.000000 in let basis2 := mk_displacement3d world 2.000000 1.000000 2.000000 in mk_geom3d_frame origin basis0 basis1 basis2 def fr2 := let origin := mk_position3d world 4.000000 4.000000 3.000000 in let basis0 := mk_displacement3d world 4.000000 3.000000 2.000000 in let basis1 := mk_displacement3d world 1.000000 2.000000 3.000000 in let basis2 := mk_displacement3d world 2.000000 1.000000 2.000000 in mk_geom3d_frame origin basis0 basis1 basis2 def ser : geom3d_series ts := ⟨ [ --(mk_time _ 0,world_fr), --(mk_time _ 1,fr1), --(mk_time _ 2,fr2) (mk_time _ 2), (mk_time _ 1), (mk_time _ 0) ]⟩ /-(⟨mk_time _ 0,sorry⟩-/ #eval ser def v1 := mk_displacement3d_timefixed_at_time ser (mk_time ts (0.4:ℚ)) 1 1 1 #check v1 def v2 := mk_displacement3d_timefixed_at_time ser (mk_time ts (0.5:ℚ)) 1 1 1 #check v2 #check v1 +ᵥ v2 def s1 : series_index ts ser := ⟨mk_time ts (0.5:ℚ)⟩ def s2 : series_index ts ser := ⟨mk_time ts (2.5:ℚ)⟩ #eval s1.idx.coord #eval s2.idx.coord #eval (ser.find_index s1.idx).coord #eval (ser.find_index s2.idx).coord #check quot.lift #check has_equiv /- attribute [reducible, elab_as_eliminator] protected def lift {α : Sort u} {β : Sort v} [s : setoid α] (f : α → β) : (∀ a b, a ≈ b → f a = f b) → quotient s → β := quot.lift f -/ def lift_si : series_index ts ser → time ts := λsi, (ser.find_index si.idx) def lift_ := quotient.lift lift_si begin dsimp [has_equiv.equiv], unfold lift_si, unfold setoid.r, unfold index_rel, intros a b c, exact c, end def chk := index_rel ts s1 s2 #eval chk #eval ⟦s1⟧=⟦s2⟧ #eval (lift_ ⟦s1⟧).coord #eval (lift_ ⟦s2⟧).coord #eval (lift_ ⟦s1⟧) #eval (lift_ ⟦s2⟧) def pt111 : (lift_ ⟦s1⟧).coord = (lift_ ⟦s2⟧).coord := begin simp *, end def pttt : (lift_ ⟦s1⟧).coord = (lift_ ⟦s2⟧).coord := begin unfold lift_, end def lift_2 : ℕ → ℚ := λsi, si instance : setoid ℕ := ⟨ (λn1 n2, n1=n2), sorry ⟩ def lift2_ := quotient.lift lift_2 begin --intros, -- unfold lift_2, dsimp [has_equiv.equiv], unfold setoid.r, unfold lift_2, simp *, end def ss11 := ⟦1⟧ def ss22 := ⟦1⟧ lemma a1 : ss11 = ss22 := rfl lemma a2 : lift2_ ss11 = lift2_ ss22 := rfl #eval lift2_ ss11
49c7d645f7f226dd619495c2fcd100ee82950093
ec5a7ae10c533e1b1f4b0bc7713e91ecf829a3eb
/ijcar16/examples/cc23.lean
2f46104d193c9203cc856da26debd40085e76e36
[ "MIT" ]
permissive
leanprover/leanprover.github.io
cf248934af7c7e9aeff17cf8df3c12c5e7e73f1a
071a20d2e059a2c3733e004c681d3949cac3c07a
refs/heads/master
1,692,621,047,417
1,691,396,994,000
1,691,396,994,000
19,366,263
18
27
MIT
1,693,989,071,000
1,399,006,345,000
Lean
UTF-8
Lean
false
false
1,613
lean
/- Example/test file for the congruence closure procedure described in the paper: "Congruence Closure for Intensional Type Theory" Daniel Selsam and Leonardo de Moura The tactic `by blast` has been configured in this file to use just the congruence closure procedure using the command set_option blast.strategy "cc" -/ import data.list open nat set_option blast.strategy "cc" constant f : nat → nat example (a b c d : nat) : f d = f b → succ a = f b → f d = succ c → a = c := by blast example (a b c d e : nat) : f d = f b → f e = f b → succ a = f b → f e = succ c → a = c := by blast example (a b c d e : nat) : f d = f b → f e = f b → succ a = f b → f e = zero → false := by blast example (a b c d e : nat) : f d = f b → f e = f b → succ a = f b → f e = 0 → false := by blast open list example (a b c d e f : nat) (l1 l2 l3 l4 : list nat) : l1 = l2 → l2 = l3 → l4 = [a, b, succ c] → l1 = [c, d, succ e] → l3 = l4 → c = e := by blast example (a b c d e f : nat) (l1 l2 l3 l4 : list nat) : l4 = [a, b, succ (succ c)] → l1 = [c, d, succ (succ e)] → l3 = l4 → l1 = l2 → l2 = l3 → c = e := by blast example (a b c d e f : nat) (l1 l2 l3 l4 : list nat) : l4 = [a, b, succ c] → l1 = [c, d, 0] → l3 = l4 → l1 = l2 → l2 = l3 → false := by blast example (a b c d e f : nat) (l1 l2 l3 l4 : list nat) : l4 = [a, b, succ c] → l1 = nil → l3 = l4 → l1 = l2 → l2 = l3 → false := by blast example (a b c d e f : nat) (l1 l2 l3 l4 : list nat) : l1 = l2 → l2 = l3 → l4 = [a, b, succ c] → l1 = nil → l3 = l4 → false := by blast
e2f5558dac5a032ac7c501030160690df794878c
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/traceClassScopes.lean
4ff8e70f55c7341a852adaadbfe3eb5f82c3f533
[ "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
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
366
lean
import Lean macro "t" t:interpolatedStr(term) : doElem => `(Macro.trace[Meta.debug] $t) macro "tstcmd" : command => do t "hello" `(example : Nat := 1) set_option trace.Meta.debug true in tstcmd open Lean Meta macro "r" r:interpolatedStr(term) : doElem => `(trace[Meta.debug] $r) set_option trace.Meta.debug true in #eval show MetaM _ from do r "world"
4893d6f9037a522f0fe138286d6694d03f0c79d4
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/probability/conditional_expectation.lean
beedf14825e8f93dc34c4b238fdef7341cd27c73
[ "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
3,588
lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import probability.notation import probability.independence.basic import measure_theory.function.conditional_expectation.basic /-! # Probabilistic properties of the conditional expectation > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains some properties about the conditional expectation which does not belong in the main conditional expectation file. ## Main result * `measure_theory.condexp_indep_eq`: If `m₁, m₂` are independent σ-algebras and `f` is a `m₁`-measurable function, then `𝔼[f | m₂] = 𝔼[f]` almost everywhere. -/ open topological_space filter open_locale nnreal ennreal measure_theory probability_theory big_operators namespace measure_theory open probability_theory variables {Ω E : Type*} [normed_add_comm_group E] [normed_space ℝ E] [complete_space E] {m₁ m₂ m : measurable_space Ω} {μ : measure Ω} {f : Ω → E} /-- If `m₁, m₂` are independent σ-algebras and `f` is `m₁`-measurable, then `𝔼[f | m₂] = 𝔼[f]` almost everywhere. -/ lemma condexp_indep_eq (hle₁ : m₁ ≤ m) (hle₂ : m₂ ≤ m) [sigma_finite (μ.trim hle₂)] (hf : strongly_measurable[m₁] f) (hindp : indep m₁ m₂ μ) : μ[f | m₂] =ᵐ[μ] λ x, μ[f] := begin by_cases hfint : integrable f μ, swap, { rw [condexp_undef hfint, integral_undef hfint], refl, }, have hfint₁ := hfint.trim hle₁ hf, refine (ae_eq_condexp_of_forall_set_integral_eq hle₂ hfint (λ s _ hs, integrable_on_const.2 (or.inr hs)) (λ s hms hs, _) strongly_measurable_const.ae_strongly_measurable').symm, rw set_integral_const, rw ← mem_ℒp_one_iff_integrable at hfint, refine hfint.induction_strongly_measurable hle₁ ennreal.one_ne_top _ _ _ _ _ _, { intros c t hmt ht, rw [integral_indicator (hle₁ _ hmt), set_integral_const, smul_smul, ← ennreal.to_real_mul, mul_comm, ← hindp _ _ hmt hms, set_integral_indicator (hle₁ _ hmt), set_integral_const, set.inter_comm] }, { intros u v hdisj huint hvint hu hv hu_eq hv_eq, rw mem_ℒp_one_iff_integrable at huint hvint, rw [integral_add' huint hvint, smul_add, hu_eq, hv_eq, integral_add' huint.integrable_on hvint.integrable_on], }, { have heq₁ : (λ f : Lp_meas E ℝ m₁ 1 μ, ∫ x, f x ∂μ) = (λ f : Lp E 1 μ, ∫ x, f x ∂μ) ∘ (submodule.subtypeL _), { refine funext (λ f, integral_congr_ae _), simp_rw [submodule.coe_subtypeL', submodule.coe_subtype, ← coe_fn_coe_base], }, have heq₂ : (λ f : Lp_meas E ℝ m₁ 1 μ, ∫ x in s, f x ∂μ) = (λ f : Lp E 1 μ, ∫ x in s, f x ∂μ) ∘ (submodule.subtypeL _), { refine funext (λ f, integral_congr_ae (ae_restrict_of_ae _)), simp_rw [submodule.coe_subtypeL', submodule.coe_subtype, ← coe_fn_coe_base], exact eventually_of_forall (λ _, rfl), }, refine is_closed_eq (continuous.const_smul _ _) _, { rw heq₁, exact continuous_integral.comp (continuous_linear_map.continuous _), }, { rw heq₂, exact (continuous_set_integral _).comp (continuous_linear_map.continuous _), }, }, { intros u v huv huint hueq, rwa [← integral_congr_ae huv, ← (set_integral_congr_ae (hle₂ _ hms) _ : ∫ x in s, u x ∂μ = ∫ x in s, v x ∂μ)], filter_upwards [huv] with x hx _ using hx, }, { exact ⟨f, hf, eventually_eq.rfl⟩, }, end end measure_theory
b54834511c88da8a11ebb8d879c1207d96bdab51
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/stage0/src/Init/Data/String/Extra.lean
7999265084353e593f965f47e62ace232d3a79a0
[ "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
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
2,951
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import Init.Control.Except import Init.Data.ByteArray import Init.SimpLemmas import Init.Data.Nat.Linear import Init.Util import Init.WFTactics namespace String def toNat! (s : String) : Nat := if s.isNat then s.foldl (fun n c => n*10 + (c.toNat - '0'.toNat)) 0 else panic! "Nat expected" /-- Convert a UTF-8 encoded `ByteArray` string to `String`. The result is unspecified if `a` is not properly UTF-8 encoded. -/ @[extern "lean_string_from_utf8_unchecked"] opaque fromUTF8Unchecked (a : @& ByteArray) : String @[extern "lean_string_to_utf8"] opaque toUTF8 (a : @& String) : ByteArray theorem one_le_csize (c : Char) : 1 ≤ csize c := by simp [csize, Char.utf8Size] repeat (first | split | decide) @[simp] theorem pos_lt_eq (p₁ p₂ : Pos) : (p₁ < p₂) = (p₁.1 < p₂.1) := rfl @[simp] theorem pos_add_char (p : Pos) (c : Char) : (p + c).byteIdx = p.byteIdx + csize c := rfl theorem eq_empty_of_bsize_eq_zero (h : s.endPos = {}) : s = "" := by match s with | ⟨[]⟩ => rfl | ⟨c::cs⟩ => injection h with h simp [endPos, utf8ByteSize, utf8ByteSize.go] at h have : utf8ByteSize.go cs + 1 ≤ utf8ByteSize.go cs + csize c := Nat.add_le_add_left (one_le_csize c) _ simp_arith [h] at this theorem lt_next (s : String) (i : String.Pos) : i.1 < (s.next i).1 := by simp_arith [next]; apply one_le_csize theorem Iterator.sizeOf_next_lt_of_hasNext (i : String.Iterator) (h : i.hasNext) : sizeOf i.next < sizeOf i := by cases i; rename_i s pos; simp [Iterator.next, Iterator.sizeOf_eq]; simp [Iterator.hasNext] at h have := String.lt_next s pos apply Nat.sub.elim (motive := fun k => k < _) (utf8ByteSize s) (String.next s pos).1 . intro _ k he simp [he]; rw [Nat.add_comm, Nat.add_sub_assoc (Nat.le_of_lt this)] have := Nat.zero_lt_sub_of_lt this simp_all_arith . intro; apply Nat.zero_lt_sub_of_lt h macro_rules | `(tactic| decreasing_trivial) => `(tactic| apply String.Iterator.sizeOf_next_lt_of_hasNext; assumption) theorem Iterator.sizeOf_next_lt_of_atEnd (i : String.Iterator) (h : ¬ i.atEnd = true) : sizeOf i.next < sizeOf i := have h : i.hasNext = true := by simp_arith [atEnd] at h; simp_arith [hasNext, h] sizeOf_next_lt_of_hasNext i h macro_rules | `(tactic| decreasing_trivial) => `(tactic| apply String.Iterator.sizeOf_next_lt_of_atEnd; assumption) namespace Iterator @[specialize] def find (it : Iterator) (p : Char → Bool) : Iterator := if it.atEnd then it else if p it.curr then it else find it.next p @[specialize] def foldUntil (it : Iterator) (init : α) (f : α → Char → Option α) : α × Iterator := if it.atEnd then (init, it) else if let some a := f init it.curr then foldUntil it.next a f else (init, it) end Iterator end String
5bc2c3a756bdcafca1b9a1c61c47295628a2eccf
cf39355caa609c0f33405126beee2739aa3cb77e
/leanpkg/leanpkg/manifest.lean
e27186eb9d277fd428192b21c3e289cc018219fa
[ "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
3,991
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Gabriel Ebner -/ import leanpkg.toml leanpkg.lean_version system.io namespace leanpkg inductive source | path (dir_name : string) : source | git (url rev : string) (branch : option string) : source namespace source def from_toml (v : toml.value) : option source := (do toml.value.str dir_name ← v.lookup "path" | none, return $ path dir_name) <|> (do toml.value.str url ← v.lookup "git" | none, toml.value.str rev ← v.lookup "rev" | none, match v.lookup "branch" with | none := return $ git url rev none | some (toml.value.str branch) := return $ git url rev (some branch) | _ := none end) def to_toml : ∀ (s : source), toml.value | (path dir_name) := toml.value.table [("path", toml.value.str dir_name)] | (git url rev none) := toml.value.table [("git", toml.value.str url), ("rev", toml.value.str rev)] | (git url rev (some branch)) := toml.value.table [("git", toml.value.str url), ("branch", toml.value.str branch), ("rev", toml.value.str rev)] /- TODO(Leo): has_to_string -/ instance : has_repr source := ⟨λ s, repr s.to_toml⟩ end source structure dependency := (name : string) (src : source) namespace dependency /- TODO(Leo): has_to_string -/ instance : has_repr dependency := ⟨λ d, d.name ++ " = " ++ repr d.src⟩ end dependency structure manifest := (name : string) (version : string) (lean_version : string := lean_version_string) (timeout : option nat := none) (path : option string := none) (dependencies : list dependency := []) namespace manifest def effective_path (m : manifest) : list string := [match m.path with some p := p | none := "." end] def from_toml (t : toml.value) : option manifest := do pkg ← t.lookup "package", toml.value.str n ← pkg.lookup "name" | none, toml.value.str ver ← pkg.lookup "version" | none, lean_ver ← match pkg.lookup "lean_version" with | some (toml.value.str lean_ver) := some lean_ver | none := some lean_version_string | _ := none end, tm ← match pkg.lookup "timeout" with | some (toml.value.nat timeout) := some (some timeout) | none := some none | _ := none end, path ← match pkg.lookup "path" with | some (toml.value.str path) := some (some path) | none := some none | _ := none end, toml.value.table deps ← t.lookup "dependencies" <|> some (toml.value.table []) | none, deps ← deps.mmap (λ ⟨n, src⟩, do src ← source.from_toml src, return $ dependency.mk n src), return { name := n, version := ver, lean_version := lean_ver, path := path, dependencies := deps, timeout := tm } def to_toml (d : manifest) : toml.value := let pkg := [("name", toml.value.str d.name), ("version", toml.value.str d.version), ("lean_version", toml.value.str d.lean_version)], pkg := match d.path with some p := pkg ++ [("path", toml.value.str p)] | none := pkg end, pkg := match d.timeout with some t := pkg ++ [("timeout", toml.value.nat t)] | none := pkg end, deps := toml.value.table $ d.dependencies.map $ λ dep, (dep.name, dep.src.to_toml) in toml.value.table [("package", toml.value.table pkg), ("dependencies", deps)] instance : has_repr manifest := ⟨λ d, repr d.to_toml⟩ def from_string (s : string) : option manifest := match parser.run_string toml.File s with | sum.inr toml := from_toml toml | sum.inl _ := none end def from_file (fn : string) : io manifest := do cnts ← io.fs.read_file fn, toml ← (match parser.run toml.File cnts with | sum.inl err := io.fail $ "toml parse error in " ++ fn ++ "\n\n" ++ err | sum.inr res := return res end), some manifest ← return (from_toml toml) | io.fail ("cannot read manifest from " ++ fn ++ "\n\n" ++ repr toml), return manifest end manifest def leanpkg_toml_fn := "leanpkg.toml" end leanpkg
9796d4d07eac2a3896abcc257e5abcb024ef600f
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/topology/subset_properties.lean
36361802a48f412b6282b6e8ca2a1f9ab86c32ba
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
69,488
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, Yury Kudryashov -/ import topology.bases import data.finset.order import data.set.accumulate import tactic.tfae /-! # Properties of subsets of topological spaces In this file we define various properties of subsets of a topological space, and some classes on topological spaces. ## Main definitions We define the following properties for sets in a topological space: * `is_compact`: each open cover has a finite subcover. This is defined in mathlib using filters. The main property of a compact set is `is_compact.elim_finite_subcover`. * `is_clopen`: a set that is both open and closed. * `is_irreducible`: a nonempty set that has contains no non-trivial pair of disjoint opens. See also the section below in the module doc. For each of these definitions (except for `is_clopen`), we also have a class stating that the whole space satisfies that property: `compact_space`, `irreducible_space` Furthermore, we have two more classes: * `locally_compact_space`: for every point `x`, every open neighborhood of `x` contains a compact neighborhood of `x`. The definition is formulated in terms of the neighborhood filter. * `sigma_compact_space`: a space that is the union of a countably many compact subspaces. ## On the definition of irreducible and connected sets/spaces In informal mathematics, irreducible spaces are assumed to be nonempty. We formalise the predicate without that assumption as `is_preirreducible`. In other words, the only difference is whether the empty space counts as irreducible. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open set filter classical topological_space open_locale classical topological_space filter universes u v variables {α : Type u} {β : Type v} [topological_space α] {s t : set α} /- compact sets -/ section compact /-- A set `s` is compact if for every nontrivial filter `f` that contains `s`, there exists `a ∈ s` such that every set of `f` meets every neighborhood of `a`. -/ def is_compact (s : set α) := ∀ ⦃f⦄ [ne_bot f], f ≤ 𝓟 s → ∃a∈s, cluster_pt a f /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 a ⊓ f`, `a ∈ s`. -/ lemma is_compact.compl_mem_sets (hs : is_compact s) {f : filter α} (hf : ∀ a ∈ s, sᶜ ∈ 𝓝 a ⊓ f) : sᶜ ∈ f := begin contrapose! hf, simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc, ← exists_prop] at hf ⊢, exact @hs _ hf inf_le_right end /-- The complement to a compact set belongs to a filter `f` if each `a ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ lemma is_compact.compl_mem_sets_of_nhds_within (hs : is_compact s) {f : filter α} (hf : ∀ a ∈ s, ∃ t ∈ 𝓝[s] a, tᶜ ∈ f) : sᶜ ∈ f := begin refine hs.compl_mem_sets (λ a ha, _), rcases hf a ha with ⟨t, ht, hst⟩, replace ht := mem_inf_principal.1 ht, apply mem_inf_of_inter ht hst, rintros x ⟨h₁, h₂⟩ hs, exact h₂ (h₁ hs) end /-- If `p : set α → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_eliminator] lemma is_compact.induction_on {s : set α} (hs : is_compact s) {p : set α → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := let f : filter α := { sets := {t | p tᶜ}, univ_sets := by simpa, sets_of_superset := λ t₁ t₂ ht₁ ht, hmono (compl_subset_compl.2 ht) ht₁, inter_sets := λ t₁ t₂ ht₁ ht₂, by simp [compl_inter, hunion ht₁ ht₂] } in have sᶜ ∈ f, from hs.compl_mem_sets_of_nhds_within (by simpa using hnhds), by simpa /-- The intersection of a compact set and a closed set is a compact set. -/ lemma is_compact.inter_right (hs : is_compact s) (ht : is_closed t) : is_compact (s ∩ t) := begin introsI f hnf hstf, obtain ⟨a, hsa, ha⟩ : ∃ a ∈ s, cluster_pt a f := hs (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))), have : a ∈ t := (ht.mem_of_nhds_within_ne_bot $ ha.mono $ le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))), exact ⟨a, ⟨hsa, this⟩, ha⟩ end /-- The intersection of a closed set and a compact set is a compact set. -/ lemma is_compact.inter_left (ht : is_compact t) (hs : is_closed s) : is_compact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a compact set and an open set is a compact set. -/ lemma is_compact.diff (hs : is_compact s) (ht : is_open t) : is_compact (s \ t) := hs.inter_right (is_closed_compl_iff.mpr ht) /-- A closed subset of a compact set is a compact set. -/ lemma compact_of_is_closed_subset (hs : is_compact s) (ht : is_closed t) (h : t ⊆ s) : is_compact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht lemma is_compact.adherence_nhdset {f : filter α} (hs : is_compact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : is_open t) (ht₂ : ∀a∈s, cluster_pt a f → a ∈ t) : t ∈ f := classical.by_cases mem_of_eq_bot $ assume : f ⊓ 𝓟 tᶜ ≠ ⊥, let ⟨a, ha, (hfa : cluster_pt a $ f ⊓ 𝓟 tᶜ)⟩ := @@hs ⟨this⟩ $ inf_le_of_left_le hf₂ in have a ∈ t, from ht₂ a ha (hfa.of_inf_left), have tᶜ ∩ t ∈ 𝓝[tᶜ] a, from inter_mem_nhds_within _ (is_open.mem_nhds ht₁ this), have A : 𝓝[tᶜ] a = ⊥, from empty_mem_iff_bot.1 $ compl_inter_self t ▸ this, have 𝓝[tᶜ] a ≠ ⊥, from hfa.of_inf_right.ne, absurd A this lemma is_compact_iff_ultrafilter_le_nhds : is_compact s ↔ (∀f : ultrafilter α, ↑f ≤ 𝓟 s → ∃a∈s, ↑f ≤ 𝓝 a) := begin refine (forall_ne_bot_le_iff _).trans _, { rintro f g hle ⟨a, has, haf⟩, exact ⟨a, has, haf.mono hle⟩ }, { simp only [ultrafilter.cluster_pt_iff] } end alias is_compact_iff_ultrafilter_le_nhds ↔ is_compact.ultrafilter_le_nhds _ /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ lemma is_compact.elim_directed_cover {ι : Type v} [hι : nonempty ι] (hs : is_compact s) (U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : directed (⊆) U) : ∃ i, s ⊆ U i := hι.elim $ λ i₀, is_compact.induction_on hs ⟨i₀, empty_subset _⟩ (λ s₁ s₂ hs ⟨i, hi⟩, ⟨i, subset.trans hs hi⟩) (λ s₁ s₂ ⟨i, hi⟩ ⟨j, hj⟩, let ⟨k, hki, hkj⟩ := hdU i j in ⟨k, union_subset (subset.trans hi hki) (subset.trans hj hkj)⟩) (λ x hx, let ⟨i, hi⟩ := mem_Union.1 (hsU hx) in ⟨U i, mem_nhds_within_of_mem_nhds (is_open.mem_nhds (hUo i) hi), i, subset.refl _⟩) /-- For every open cover of a compact set, there exists a finite subcover. -/ lemma is_compact.elim_finite_subcover {ι : Type v} (hs : is_compact s) (U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (λ t, is_open_bUnion $ λ i _, hUo i) (Union_eq_Union_finset U ▸ hsU) (directed_of_sup $ λ t₁ t₂ h, bUnion_subset_bUnion_left h) lemma is_compact.elim_nhds_subcover' (hs : is_compact s) (U : Π x ∈ s, set α) (hU : ∀ x ∈ s, U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_finite_subcover (λ x : s, interior (U x x.2)) (λ x, is_open_interior) (λ x hx, mem_Union.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 $ hU _ _⟩)).imp $ λ t ht, subset.trans ht $ bUnion_mono $ λ _ _, interior_subset lemma is_compact.elim_nhds_subcover (hs : is_compact s) (U : α → set α) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : finset α, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := let ⟨t, ht⟩ := hs.elim_nhds_subcover' (λ x _, U x) hU in ⟨t.image coe, λ x hx, let ⟨y, hyt, hyx⟩ := finset.mem_image.1 hx in hyx ▸ y.2, by rwa finset.set_bUnion_finset_image⟩ /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ lemma is_compact.elim_finite_subfamily_closed {s : set α} {ι : Type v} (hs : is_compact s) (Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : s ∩ (⋂ i, Z i) = ∅) : ∃ t : finset ι, s ∩ (⋂ i ∈ t, Z i) = ∅ := let ⟨t, ht⟩ := hs.elim_finite_subcover (λ i, (Z i)ᶜ) (λ i, (hZc i).is_open_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union, exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ) in ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union, exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht⟩ /-- If `s` is a compact set in a topological space `α` and `f : ι → set α` is a locally finite family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/ lemma locally_finite.finite_nonempty_inter_compact {ι : Type*} {f : ι → set α} (hf : locally_finite f) {s : set α} (hs : is_compact s) : finite {i | (f i ∩ s).nonempty} := begin choose U hxU hUf using hf, rcases hs.elim_nhds_subcover U (λ x _, hxU x) with ⟨t, -, hsU⟩, refine (t.finite_to_set.bUnion (λ x _, hUf x)).subset _, rintro i ⟨x, hx⟩, rcases mem_bUnion_iff.1 (hsU hx.2) with ⟨c, hct, hcx⟩, exact mem_bUnion hct ⟨x, hx.1, hcx⟩ end /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ lemma is_compact.inter_Inter_nonempty {s : set α} {ι : Type v} (hs : is_compact s) (Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : ∀ t : finset ι, (s ∩ ⋂ i ∈ t, Z i).nonempty) : (s ∩ ⋂ i, Z i).nonempty := begin simp only [← ne_empty_iff_nonempty] at hsZ ⊢, apply mt (hs.elim_finite_subfamily_closed Z hZc), push_neg, exact hsZ end /-- Cantor's intersection theorem: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ lemma is_compact.nonempty_Inter_of_directed_nonempty_compact_closed {ι : Type v} [hι : nonempty ι] (Z : ι → set α) (hZd : directed (⊇) Z) (hZn : ∀ i, (Z i).nonempty) (hZc : ∀ i, is_compact (Z i)) (hZcl : ∀ i, is_closed (Z i)) : (⋂ i, Z i).nonempty := begin apply hι.elim, intro i₀, let Z' := λ i, Z i ∩ Z i₀, suffices : (⋂ i, Z' i).nonempty, { exact nonempty.mono (Inter_subset_Inter $ assume i, inter_subset_left (Z i) (Z i₀)) this }, rw ← ne_empty_iff_nonempty, intro H, obtain ⟨t, ht⟩ : ∃ (t : finset ι), ((Z i₀) ∩ ⋂ (i ∈ t), Z' i) = ∅, from (hZc i₀).elim_finite_subfamily_closed Z' (assume i, is_closed.inter (hZcl i) (hZcl i₀)) (by rw [H, inter_empty]), obtain ⟨i₁, hi₁⟩ : ∃ i₁ : ι, Z i₁ ⊆ Z i₀ ∧ ∀ i ∈ t, Z i₁ ⊆ Z' i, { rcases directed.finset_le hZd t with ⟨i, hi⟩, rcases hZd i i₀ with ⟨i₁, hi₁, hi₁₀⟩, use [i₁, hi₁₀], intros j hj, exact subset_inter (subset.trans hi₁ (hi j hj)) hi₁₀ }, suffices : ((Z i₀) ∩ ⋂ (i ∈ t), Z' i).nonempty, { rw ← ne_empty_iff_nonempty at this, contradiction }, refine nonempty.mono _ (hZn i₁), exact subset_inter hi₁.left (subset_bInter hi₁.right) end /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ lemma is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed (Z : ℕ → set α) (hZd : ∀ i, Z (i+1) ⊆ Z i) (hZn : ∀ i, (Z i).nonempty) (hZ0 : is_compact (Z 0)) (hZcl : ∀ i, is_closed (Z i)) : (⋂ i, Z i).nonempty := have Zmono : antitone Z := antitone_nat_of_succ_le hZd, have hZd : directed (⊇) Z, from directed_of_sup Zmono, have ∀ i, Z i ⊆ Z 0, from assume i, Zmono $ zero_le i, have hZc : ∀ i, is_compact (Z i), from assume i, compact_of_is_closed_subset hZ0 (hZcl i) (this i), is_compact.nonempty_Inter_of_directed_nonempty_compact_closed Z hZd hZn hZc hZcl /-- For every open cover of a compact set, there exists a finite subcover. -/ lemma is_compact.elim_finite_subcover_image {b : set β} {c : β → set α} (hs : is_compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) : ∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i := begin rcases hs.elim_finite_subcover (λ i, c i : b → set α) _ _ with ⟨d, hd⟩; [skip, simpa using hc₁, simpa using hc₂], refine ⟨↑(d.image coe), _, finset.finite_to_set _, _⟩, { simp }, { rwa [finset.coe_image, bUnion_image] } end /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem is_compact_of_finite_subfamily_closed (h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) → s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) : is_compact s := assume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, cluster_pt x f), have hf : ∀x∈s, 𝓝 x ⊓ f = ⊥, by simpa only [cluster_pt, not_exists, not_not, ne_bot_iff], have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t, from assume ⟨x, hxs, hx⟩, have ∅ ∈ 𝓝 x ⊓ f, by rw [empty_mem_iff_bot, hf x hxs], let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_iff] at this; exact this in have ∅ ∈ 𝓝[t₂] x, by { rw [ht, inter_comm], exact inter_mem_nhds_within _ ht₁ }, have 𝓝[t₂] x = ⊥, by rwa [empty_mem_iff_bot] at this, by simp only [closure_eq_cluster_pts] at hx; exact (hx t₂ ht₂).ne this, let ⟨t, ht⟩ := h (λ i : f.sets, closure i.1) (λ i, is_closed_closure) (by simpa [eq_empty_iff_forall_not_mem, not_exists]) in have (⋂i∈t, subtype.val i) ∈ f, from t.Inter_mem_sets.2 $ assume i hi, i.2, have s ∩ (⋂i∈t, subtype.val i) ∈ f, from inter_mem (le_principal_iff.1 hfs) this, have ∅ ∈ f, from mem_of_superset this $ assume x ⟨hxs, hx⟩, let ⟨i, hit, hxi⟩ := (show ∃i ∈ t, x ∉ closure (subtype.val i), by { rw [eq_empty_iff_forall_not_mem] at ht, simpa [hxs, not_forall] using ht x }) in have x ∈ closure i.val, from subset_closure (mem_bInter_iff.mp hx i hit), show false, from hxi this, hfn.ne $ by rwa [empty_mem_iff_bot] at this /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ lemma is_compact_of_finite_subcover (h : Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) → s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) : is_compact s := is_compact_of_finite_subfamily_closed $ assume ι Z hZc hsZ, let ⟨t, ht⟩ := h (λ i, (Z i)ᶜ) (assume i, is_open_compl_iff.mpr $ hZc i) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union, exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ) in ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union, exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht⟩ /-- A set `s` is compact if and only if for every open cover of `s`, there exists a finite subcover. -/ lemma is_compact_iff_finite_subcover : is_compact s ↔ (Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) → s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) := ⟨assume hs ι, hs.elim_finite_subcover, is_compact_of_finite_subcover⟩ /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem is_compact_iff_finite_subfamily_closed : is_compact s ↔ (Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) → s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) := ⟨assume hs ι, hs.elim_finite_subfamily_closed, is_compact_of_finite_subfamily_closed⟩ @[simp] lemma is_compact_empty : is_compact (∅ : set α) := assume f hnf hsf, not.elim hnf.ne $ empty_mem_iff_bot.1 $ le_principal_iff.1 hsf @[simp] lemma is_compact_singleton {a : α} : is_compact ({a} : set α) := λ f hf hfa, ⟨a, rfl, cluster_pt.of_le_nhds' (hfa.trans $ by simpa only [principal_singleton] using pure_le_nhds a) hf⟩ lemma set.subsingleton.is_compact {s : set α} (hs : s.subsingleton) : is_compact s := subsingleton.induction_on hs is_compact_empty $ λ x, is_compact_singleton lemma set.finite.compact_bUnion {s : set β} {f : β → set α} (hs : finite s) (hf : ∀i ∈ s, is_compact (f i)) : is_compact (⋃i ∈ s, f i) := is_compact_of_finite_subcover $ assume ι U hUo hsU, have ∀i : subtype s, ∃t : finset ι, f i ⊆ (⋃ j ∈ t, U j), from assume ⟨i, hi⟩, (hf i hi).elim_finite_subcover _ hUo (calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi ... ⊆ ⋃j, U j : hsU), let ⟨finite_subcovers, h⟩ := axiom_of_choice this in by haveI : fintype (subtype s) := hs.fintype; exact let t := finset.bUnion finset.univ finite_subcovers in have (⋃i ∈ s, f i) ⊆ (⋃ i ∈ t, U i), from bUnion_subset $ assume i hi, calc f i ⊆ (⋃ j ∈ finite_subcovers ⟨i, hi⟩, U j) : (h ⟨i, hi⟩) ... ⊆ (⋃ j ∈ t, U j) : bUnion_subset_bUnion_left $ assume j hj, finset.mem_bUnion.mpr ⟨_, finset.mem_univ _, hj⟩, ⟨t, this⟩ lemma finset.compact_bUnion (s : finset β) {f : β → set α} (hf : ∀i ∈ s, is_compact (f i)) : is_compact (⋃i ∈ s, f i) := s.finite_to_set.compact_bUnion hf lemma compact_accumulate {K : ℕ → set α} (hK : ∀ n, is_compact (K n)) (n : ℕ) : is_compact (accumulate K n) := (finite_le_nat n).compact_bUnion $ λ k _, hK k lemma compact_Union {f : β → set α} [fintype β] (h : ∀i, is_compact (f i)) : is_compact (⋃i, f i) := by rw ← bUnion_univ; exact finite_univ.compact_bUnion (λ i _, h i) lemma set.finite.is_compact (hs : finite s) : is_compact s := bUnion_of_singleton s ▸ hs.compact_bUnion (λ _ _, is_compact_singleton) lemma finite_of_is_compact_of_discrete [discrete_topology α] (s : set α) (hs : is_compact s) : s.finite := begin have := hs.elim_finite_subcover (λ x : α, ({x} : set α)) (λ x, is_open_discrete _), simp only [set.subset_univ, forall_prop_of_true, set.Union_of_singleton] at this, rcases this with ⟨t, ht⟩, suffices : (⋃ (i : α) (H : i ∈ t), {i} : set α) = (t : set α), { rw this at ht, exact t.finite_to_set.subset ht }, ext x, simp only [exists_prop, set.mem_Union, set.mem_singleton_iff, exists_eq_right', finset.mem_coe] end lemma is_compact.union (hs : is_compact s) (ht : is_compact t) : is_compact (s ∪ t) := by rw union_eq_Union; exact compact_Union (λ b, by cases b; assumption) lemma is_compact.insert (hs : is_compact s) (a) : is_compact (insert a s) := is_compact_singleton.union hs /-- If `V : ι → set α` is a decreasing family of closed compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `α` is not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/ lemma exists_subset_nhd_of_compact' {ι : Type*} [nonempty ι] {V : ι → set α} (hV : directed (⊇) V) (hV_cpct : ∀ i, is_compact (V i)) (hV_closed : ∀ i, is_closed (V i)) {U : set α} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := begin set Y := ⋂ i, V i, obtain ⟨W, hsubW, W_op, hWU⟩ : ∃ W, Y ⊆ W ∧ is_open W ∧ W ⊆ U, from exists_open_set_nhds hU, suffices : ∃ i, V i ⊆ W, { rcases this with ⟨i, hi⟩, refine ⟨i, set.subset.trans hi hWU⟩ }, by_contradiction H, push_neg at H, replace H : ∀ i, (V i ∩ Wᶜ).nonempty := λ i, set.inter_compl_nonempty_iff.mpr (H i), have : (⋂ i, V i ∩ Wᶜ).nonempty, { apply is_compact.nonempty_Inter_of_directed_nonempty_compact_closed _ _ H, { intro i, exact (hV_cpct i).inter_right W_op.is_closed_compl }, { intro i, apply (hV_closed i).inter W_op.is_closed_compl }, { intros i j, rcases hV i j with ⟨k, hki, hkj⟩, use k, split ; intro x ; simp only [and_imp, mem_inter_eq, mem_compl_eq] ; tauto } }, have : ¬ (⋂ (i : ι), V i) ⊆ W, by simpa [← Inter_inter, inter_compl_nonempty_iff], contradiction end namespace filter /-- `filter.cocompact` is the filter generated by complements to compact sets. -/ def cocompact (α : Type*) [topological_space α] : filter α := ⨅ (s : set α) (hs : is_compact s), 𝓟 (sᶜ) lemma has_basis_cocompact : (cocompact α).has_basis is_compact compl := has_basis_binfi_principal' (λ s hs t ht, ⟨s ∪ t, hs.union ht, compl_subset_compl.2 (subset_union_left s t), compl_subset_compl.2 (subset_union_right s t)⟩) ⟨∅, is_compact_empty⟩ lemma mem_cocompact : s ∈ cocompact α ↔ ∃ t, is_compact t ∧ tᶜ ⊆ s := has_basis_cocompact.mem_iff.trans $ exists_congr $ λ t, exists_prop lemma mem_cocompact' : s ∈ cocompact α ↔ ∃ t, is_compact t ∧ sᶜ ⊆ t := mem_cocompact.trans $ exists_congr $ λ t, and_congr_right $ λ ht, compl_subset_comm lemma _root_.is_compact.compl_mem_cocompact (hs : is_compact s) : sᶜ ∈ filter.cocompact α := has_basis_cocompact.mem_of_mem hs /-- `filter.coclosed_compact` is the filter generated by complements to closed compact sets. In a Hausdorff space, this is the same as `filter.cocompact`. -/ def coclosed_compact (α : Type*) [topological_space α] : filter α := ⨅ (s : set α) (h₁ : is_closed s) (h₂ : is_compact s), 𝓟 (sᶜ) lemma has_basis_coclosed_compact : (filter.coclosed_compact α).has_basis (λ s, is_closed s ∧ is_compact s) compl := begin simp only [filter.coclosed_compact, infi_and'], refine has_basis_binfi_principal' _ ⟨∅, is_closed_empty, is_compact_empty⟩, rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩, exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 (subset_union_left _ _), compl_subset_compl.2 (subset_union_right _ _)⟩⟩ end lemma mem_coclosed_compact : s ∈ coclosed_compact α ↔ ∃ t, is_closed t ∧ is_compact t ∧ tᶜ ⊆ s := by simp [has_basis_coclosed_compact.mem_iff, and_assoc] lemma mem_coclosed_compact' : s ∈ coclosed_compact α ↔ ∃ t, is_closed t ∧ is_compact t ∧ sᶜ ⊆ t := by simp only [mem_coclosed_compact, compl_subset_comm] lemma cocompact_le_coclosed_compact : cocompact α ≤ coclosed_compact α := infi_le_infi $ λ s, le_infi $ λ _, le_rfl end filter section tube_lemma variables [topological_space β] /-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes a product of an open neighborhood of `s` by an open neighborhood of `t`. -/ def nhds_contain_boxes (s : set α) (t : set β) : Prop := ∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n), ∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n lemma nhds_contain_boxes.symm {s : set α} {t : set β} : nhds_contain_boxes s t → nhds_contain_boxes t s := assume H n hn hp, let ⟨u, v, uo, vo, su, tv, p⟩ := H (prod.swap ⁻¹' n) (hn.preimage continuous_swap) (by rwa [←image_subset_iff, image_swap_prod]) in ⟨v, u, vo, uo, tv, su, by rwa [←image_subset_iff, image_swap_prod] at p⟩ lemma nhds_contain_boxes.comm {s : set α} {t : set β} : nhds_contain_boxes s t ↔ nhds_contain_boxes t s := iff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm lemma nhds_contain_boxes_of_singleton {x : α} {y : β} : nhds_contain_boxes ({x} : set α) ({y} : set β) := assume n hn hp, let ⟨u, v, uo, vo, xu, yv, hp'⟩ := is_open_prod_iff.mp hn x y (hp $ by simp) in ⟨u, v, uo, vo, by simpa, by simpa, hp'⟩ lemma nhds_contain_boxes_of_compact {s : set α} (hs : is_compact s) (t : set β) (H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t := assume n hn hp, have ∀x : subtype s, ∃uv : set α × set β, is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n, from assume ⟨x, hx⟩, have set.prod {x} t ⊆ n, from subset.trans (prod_mono (by simpa) (subset.refl _)) hp, let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩, let ⟨uvs, h⟩ := classical.axiom_of_choice this in have us_cover : s ⊆ ⋃i, (uvs i).1, from assume x hx, subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1), let ⟨s0, s0_cover⟩ := hs.elim_finite_subcover _ (λi, (h i).1) us_cover in let u := ⋃(i ∈ s0), (uvs i).1 in let v := ⋂(i ∈ s0), (uvs i).2 in have is_open u, from is_open_bUnion (λi _, (h i).1), have is_open v, from is_open_bInter s0.finite_to_set (λi _, (h i).2.1), have t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1), have set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩, have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx', let ⟨i,is0,hi⟩ := this in (h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩, ⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩ /-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. -/ lemma generalized_tube_lemma {s : set α} (hs : is_compact s) {t : set β} (ht : is_compact t) {n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) : ∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n := have _, from nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $ nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton, this n hn hp end tube_lemma /-- Type class for compact spaces. Separation is sometimes included in the definition, especially in the French literature, but we do not include it here. -/ class compact_space (α : Type*) [topological_space α] : Prop := (compact_univ : is_compact (univ : set α)) @[priority 10] -- see Note [lower instance priority] instance subsingleton.compact_space [subsingleton α] : compact_space α := ⟨subsingleton_univ.is_compact⟩ lemma is_compact_univ_iff : is_compact (univ : set α) ↔ compact_space α := ⟨λ h, ⟨h⟩, λ h, h.1⟩ lemma compact_univ [h : compact_space α] : is_compact (univ : set α) := h.compact_univ lemma cluster_point_of_compact [compact_space α] (f : filter α) [ne_bot f] : ∃ x, cluster_pt x f := by simpa using compact_univ (show f ≤ 𝓟 univ, by simp) lemma compact_space.elim_nhds_subcover {α : Type*} [topological_space α] [compact_space α] (U : α → set α) (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : finset α, (⋃ x ∈ t, U x) = ⊤ := begin obtain ⟨t, -, s⟩ := is_compact.elim_nhds_subcover compact_univ U (λ x m, hU x), exact ⟨t, by { rw eq_top_iff, exact s }⟩, end theorem compact_space_of_finite_subfamily_closed {α : Type u} [topological_space α] (h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) → (⋂ i, Z i) = ∅ → ∃ (t : finset ι), (⋂ i ∈ t, Z i) = ∅) : compact_space α := { compact_univ := begin apply is_compact_of_finite_subfamily_closed, intros ι Z, specialize h Z, simpa using h end } lemma is_closed.is_compact [compact_space α] {s : set α} (h : is_closed s) : is_compact s := compact_of_is_closed_subset compact_univ h (subset_univ _) lemma filter.cocompact_ne_bot_tfae (α : Type*) [topological_space α] : tfae [ne_bot (filter.cocompact α), ne_bot (filter.coclosed_compact α), ¬is_compact (univ : set α), ¬compact_space α] := begin tfae_have : 1 → 2, from λ h, h.mono filter.cocompact_le_coclosed_compact, tfae_have : 3 ↔ 4, from not_congr is_compact_univ_iff, tfae_have : 2 → 3, from λ h₁ h₂, (filter.has_basis_coclosed_compact.ne_bot_iff.1 h₁ ⟨is_closed_univ, h₂⟩).ne_empty compl_univ, tfae_have : 3 → 1, { refine λ h₁, filter.has_basis_cocompact.ne_bot_iff.2 (λ s hs, _), contrapose! h₁, rw [not_nonempty_iff_eq_empty, compl_empty_iff] at h₁, rwa ← h₁ }, tfae_finish end /-- `ne_bot (cocompact α)` is the canonical way to say that `α` is not a compact space using typeclasses. -/ instance [ne_bot (filter.cocompact α)] : ne_bot (filter.coclosed_compact α) := ((filter.cocompact_ne_bot_tfae α).out 0 1).mp ‹_› /-- A compact discrete space is finite. -/ noncomputable def fintype_of_compact_of_discrete [compact_space α] [discrete_topology α] : fintype α := fintype_of_univ_finite $ finite_of_is_compact_of_discrete _ compact_univ lemma finite_cover_nhds_interior [compact_space α] {U : α → set α} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : finset α, (⋃ x ∈ t, interior (U x)) = univ := let ⟨t, ht⟩ := compact_univ.elim_finite_subcover (λ x, interior (U x)) (λ x, is_open_interior) (λ x _, mem_Union.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩) in ⟨t, univ_subset_iff.1 ht⟩ lemma finite_cover_nhds [compact_space α] {U : α → set α} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : finset α, (⋃ x ∈ t, U x) = univ := let ⟨t, ht⟩ := finite_cover_nhds_interior hU in ⟨t, univ_subset_iff.1 $ ht ▸ bUnion_mono (λ x hx, interior_subset)⟩ /-- If `α` is a compact space, then a locally finite family of sets of `α` can have only finitely many nonempty elements. -/ lemma locally_finite.finite_nonempty_of_compact {ι : Type*} [compact_space α] {f : ι → set α} (hf : locally_finite f) : finite {i | (f i).nonempty} := by simpa only [inter_univ] using hf.finite_nonempty_inter_compact compact_univ /-- If `α` is a compact space, then a locally finite family of nonempty sets of `α` can have only finitely many elements, `set.finite` version. -/ lemma locally_finite.finite_of_compact {ι : Type*} [compact_space α] {f : ι → set α} (hf : locally_finite f) (hne : ∀ i, (f i).nonempty) : finite (univ : set ι) := by simpa only [hne] using hf.finite_nonempty_of_compact /-- If `α` is a compact space, then a locally finite family of nonempty sets of `α` can have only finitely many elements, `fintype` version. -/ noncomputable def locally_finite.fintype_of_compact {ι : Type*} [compact_space α] {f : ι → set α} (hf : locally_finite f) (hne : ∀ i, (f i).nonempty) : fintype ι := fintype_of_univ_finite (hf.finite_of_compact hne) variables [topological_space β] lemma is_compact.image_of_continuous_on {f : α → β} (hs : is_compact s) (hf : continuous_on f s) : is_compact (f '' s) := begin intros l lne ls, have : ne_bot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls), obtain ⟨a, has, ha⟩ : ∃ a ∈ s, cluster_pt a (l.comap f ⊓ 𝓟 s) := @@hs this inf_le_right, use [f a, mem_image_of_mem f has], have : tendsto f (𝓝 a ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f a) ⊓ l), { convert (hf a has).inf (@tendsto_comap _ _ f l) using 1, rw nhds_within, ac_refl }, exact @@tendsto.ne_bot _ this ha, end lemma is_compact.image {f : α → β} (hs : is_compact s) (hf : continuous f) : is_compact (f '' s) := hs.image_of_continuous_on hf.continuous_on /-- The comap of the cocompact filter on `β` by a continuous function `f : α → β` is less than or equal to the cocompact filter on `α`. This is a reformulation of the fact that images of compact sets are compact. -/ lemma filter.comap_cocompact {f : α → β} (hf : continuous f) : (filter.cocompact β).comap f ≤ filter.cocompact α := begin rw (filter.has_basis_cocompact.comap f).le_basis_iff filter.has_basis_cocompact, intros t ht, refine ⟨f '' t, ht.image hf, _⟩, simpa using t.subset_preimage_image f end lemma is_compact_range [compact_space α] {f : α → β} (hf : continuous f) : is_compact (range f) := by rw ← image_univ; exact compact_univ.image hf /-- If X is is_compact then pr₂ : X × Y → Y is a closed map -/ theorem is_closed_proj_of_is_compact {X : Type*} [topological_space X] [compact_space X] {Y : Type*} [topological_space Y] : is_closed_map (prod.snd : X × Y → Y) := begin set πX := (prod.fst : X × Y → X), set πY := (prod.snd : X × Y → Y), assume C (hC : is_closed C), rw is_closed_iff_cluster_pt at hC ⊢, assume y (y_closure : cluster_pt y $ 𝓟 (πY '' C)), have : ne_bot (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)), { suffices : ne_bot (map πY (comap πY (𝓝 y) ⊓ 𝓟 C)), by simpa only [map_ne_bot_iff], convert y_closure, calc map πY (comap πY (𝓝 y) ⊓ 𝓟 C) = 𝓝 y ⊓ map πY (𝓟 C) : filter.push_pull' _ _ _ ... = 𝓝 y ⊓ 𝓟 (πY '' C) : by rw map_principal }, resetI, obtain ⟨x, hx⟩ : ∃ x, cluster_pt x (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)), from cluster_point_of_compact _, refine ⟨⟨x, y⟩, _, by simp [πY]⟩, apply hC, rw [cluster_pt, ← filter.map_ne_bot_iff πX], convert hx, calc map πX (𝓝 (x, y) ⊓ 𝓟 C) = map πX (comap πX (𝓝 x) ⊓ comap πY (𝓝 y) ⊓ 𝓟 C) : by rw [nhds_prod_eq, filter.prod] ... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C ⊓ comap πX (𝓝 x)) : by ac_refl ... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C) ⊓ 𝓝 x : by rw filter.push_pull ... = 𝓝 x ⊓ map πX (comap πY (𝓝 y) ⊓ 𝓟 C) : by rw inf_comm end lemma exists_subset_nhd_of_compact_space [compact_space α] {ι : Type*} [nonempty ι] {V : ι → set α} (hV : directed (⊇) V) (hV_closed : ∀ i, is_closed (V i)) {U : set α} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := exists_subset_nhd_of_compact' hV (λ i, (hV_closed i).is_compact) hV_closed hU lemma embedding.is_compact_iff_is_compact_image {f : α → β} (hf : embedding f) : is_compact s ↔ is_compact (f '' s) := iff.intro (assume h, h.image hf.continuous) $ assume h, begin rw is_compact_iff_ultrafilter_le_nhds at ⊢ h, intros u us', have : ↑(u.map f) ≤ 𝓟 (f '' s), begin rw [ultrafilter.coe_map, map_le_iff_le_comap, comap_principal], convert us', exact preimage_image_eq _ hf.inj end, rcases h (u.map f) this with ⟨_, ⟨a, ha, ⟨⟩⟩, _⟩, refine ⟨a, ha, _⟩, rwa [hf.induced, nhds_induced, ←map_le_iff_le_comap] end /-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts. -/ lemma closed_embedding.tendsto_cocompact {f : α → β} (hf : closed_embedding f) : tendsto f (filter.cocompact α) (filter.cocompact β) := begin rw filter.has_basis_cocompact.tendsto_iff filter.has_basis_cocompact, intros K hK, refine ⟨f ⁻¹' (K ∩ (set.range f)), _, λ x hx, by simpa using hx⟩, apply hf.to_embedding.is_compact_iff_is_compact_image.mpr, rw set.image_preimage_eq_of_subset (set.inter_subset_right _ _), exact hK.inter_right hf.closed_range, end lemma compact_iff_compact_in_subtype {p : α → Prop} {s : set {a // p a}} : is_compact s ↔ is_compact ((coe : _ → α) '' s) := embedding_subtype_coe.is_compact_iff_is_compact_image lemma is_compact_iff_is_compact_univ {s : set α} : is_compact s ↔ is_compact (univ : set s) := by rw [compact_iff_compact_in_subtype, image_univ, subtype.range_coe]; refl lemma is_compact_iff_compact_space {s : set α} : is_compact s ↔ compact_space s := is_compact_iff_is_compact_univ.trans ⟨λ h, ⟨h⟩, @compact_space.compact_univ _ _⟩ lemma is_compact.prod {s : set α} {t : set β} (hs : is_compact s) (ht : is_compact t) : is_compact (set.prod s t) := begin rw is_compact_iff_ultrafilter_le_nhds at hs ht ⊢, intros f hfs, rw le_principal_iff at hfs, obtain ⟨a : α, sa : a ∈ s, ha : map prod.fst ↑f ≤ 𝓝 a⟩ := hs (f.map prod.fst) (le_principal_iff.2 $ mem_map.2 $ mem_of_superset hfs (λ x, and.left)), obtain ⟨b : β, tb : b ∈ t, hb : map prod.snd ↑f ≤ 𝓝 b⟩ := ht (f.map prod.snd) (le_principal_iff.2 $ mem_map.2 $ mem_of_superset hfs (λ x, and.right)), rw map_le_iff_le_comap at ha hb, refine ⟨⟨a, b⟩, ⟨sa, tb⟩, _⟩, rw nhds_prod_eq, exact le_inf ha hb end lemma inducing.is_compact_iff {f : α → β} (hf : inducing f) {s : set α} : is_compact (f '' s) ↔ is_compact s := begin split, { introsI hs F F_ne_bot F_le, obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : cluster_pt (f x) (map f F)⟩ := hs (calc map f F ≤ map f (𝓟 s) : map_mono F_le ... = 𝓟 (f '' s) : map_principal), use [x, x_in], suffices : (map f (𝓝 x ⊓ F)).ne_bot, by simpa [filter.map_ne_bot_iff], rwa calc map f (𝓝 x ⊓ F) = map f ((comap f $ 𝓝 $ f x) ⊓ F) : by rw hf.nhds_eq_comap ... = 𝓝 (f x) ⊓ map f F : filter.push_pull' _ _ _ }, { intro hs, exact hs.image hf.continuous } end /-- Finite topological spaces are compact. -/ @[priority 100] instance fintype.compact_space [fintype α] : compact_space α := { compact_univ := finite_univ.is_compact } /-- The product of two compact spaces is compact. -/ instance [compact_space α] [compact_space β] : compact_space (α × β) := ⟨by { rw ← univ_prod_univ, exact compact_univ.prod compact_univ }⟩ /-- The disjoint union of two compact spaces is compact. -/ instance [compact_space α] [compact_space β] : compact_space (α ⊕ β) := ⟨begin rw ← range_inl_union_range_inr, exact (is_compact_range continuous_inl).union (is_compact_range continuous_inr) end⟩ /-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on their product. -/ lemma filter.coprod_cocompact {β : Type*} [topological_space β]: (filter.cocompact α).coprod (filter.cocompact β) = filter.cocompact (α × β) := begin ext S, simp only [mem_coprod_iff, exists_prop, mem_comap, filter.mem_cocompact], split, { rintro ⟨⟨A, ⟨t, ht, hAt⟩, hAS⟩, B, ⟨t', ht', hBt'⟩, hBS⟩, refine ⟨t.prod t', ht.prod ht', _⟩, refine subset.trans _ (union_subset hAS hBS), rw compl_subset_comm at ⊢ hAt hBt', refine subset.trans _ (set.prod_mono hAt hBt'), intros x, simp only [compl_union, mem_inter_eq, mem_prod, mem_preimage, mem_compl_eq], tauto }, { rintros ⟨t, ht, htS⟩, refine ⟨⟨(prod.fst '' t)ᶜ, _, _⟩, ⟨(prod.snd '' t)ᶜ, _, _⟩⟩, { exact ⟨prod.fst '' t, ht.image continuous_fst, subset.rfl⟩ }, { rw preimage_compl, rw compl_subset_comm at ⊢ htS, exact subset.trans htS (subset_preimage_image prod.fst _) }, { exact ⟨prod.snd '' t, ht.image continuous_snd, subset.rfl⟩ }, { rw preimage_compl, rw compl_subset_comm at ⊢ htS, exact subset.trans htS (subset_preimage_image prod.snd _) } } end section tychonoff variables {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)] /-- **Tychonoff's theorem** -/ lemma is_compact_pi_infinite {s : Π i, set (π i)} : (∀ i, is_compact (s i)) → is_compact {x : Π i, π i | ∀ i, x i ∈ s i} := begin simp only [is_compact_iff_ultrafilter_le_nhds, nhds_pi, exists_prop, mem_set_of_eq, le_infi_iff, le_principal_iff], intros h f hfs, have : ∀i:ι, ∃a, a∈s i ∧ tendsto (λx:Πi:ι, π i, x i) f (𝓝 a), { refine λ i, h i (f.map _) (mem_map.2 _), exact mem_of_superset hfs (λ x hx, hx i) }, choose a ha, exact ⟨a, assume i, (ha i).left, assume i, (ha i).right.le_comap⟩ end /-- A version of Tychonoff's theorem that uses `set.pi`. -/ lemma is_compact_univ_pi {s : Π i, set (π i)} (h : ∀ i, is_compact (s i)) : is_compact (pi univ s) := by { convert is_compact_pi_infinite h, simp only [pi, forall_prop_of_true, mem_univ] } instance pi.compact_space [∀ i, compact_space (π i)] : compact_space (Πi, π i) := ⟨by { rw [← pi_univ univ], exact is_compact_univ_pi (λ i, compact_univ) }⟩ /-- Product of compact sets is compact -/ lemma filter.Coprod_cocompact {δ : Type*} {κ : δ → Type*} [Π d, topological_space (κ d)] : filter.Coprod (λ d, filter.cocompact (κ d)) = filter.cocompact (Π d, κ d) := begin ext S, simp only [mem_coprod_iff, exists_prop, mem_comap, filter.mem_cocompact], split, { intros h, rw filter.mem_Coprod_iff at h, choose t ht1 ht2 using h, choose t1 ht11 ht12 using λ d, filter.mem_cocompact.mp (ht1 d), refine ⟨set.pi set.univ t1, _, _⟩, { convert is_compact_pi_infinite ht11, ext, simp }, { refine subset.trans _ (set.Union_subset ht2), intros x, simp only [mem_Union, mem_univ_pi, exists_imp_distrib, mem_compl_eq, not_forall], intros d h, exact ⟨d, ht12 d h⟩ } }, { rintros ⟨t, h1, h2⟩, rw filter.mem_Coprod_iff, intros d, refine ⟨((λ (k : Π (d : δ), κ d), k d) '' t)ᶜ, _, _⟩, { rw filter.mem_cocompact, refine ⟨(λ (k : Π (d : δ), κ d), k d) '' t, _, set.subset.refl _⟩, exact is_compact.image h1 (continuous_pi_iff.mp (continuous_id) d) }, refine subset.trans _ h2, intros x hx, simp only [not_exists, mem_image, mem_preimage, mem_compl_eq] at hx, simpa using mt (hx x) }, end end tychonoff instance quot.compact_space {r : α → α → Prop} [compact_space α] : compact_space (quot r) := ⟨by { rw ← range_quot_mk, exact is_compact_range continuous_quot_mk }⟩ instance quotient.compact_space {s : setoid α} [compact_space α] : compact_space (quotient s) := quot.compact_space /-- There are various definitions of "locally compact space" in the literature, which agree for Hausdorff spaces but not in general. This one is the precise condition on X needed for the evaluation `map C(X, Y) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the compact-open topology. -/ class locally_compact_space (α : Type*) [topological_space α] : Prop := (local_compact_nhds : ∀ (x : α) (n ∈ 𝓝 x), ∃ s ∈ 𝓝 x, s ⊆ n ∧ is_compact s) lemma compact_basis_nhds [locally_compact_space α] (x : α) : (𝓝 x).has_basis (λ s, s ∈ 𝓝 x ∧ is_compact s) (λ s, s) := has_basis_self.2 $ by simpa only [and_comm] using locally_compact_space.local_compact_nhds x lemma locally_compact_space_of_has_basis {ι : α → Type*} {p : Π x, ι x → Prop} {s : Π x, ι x → set α} (h : ∀ x, (𝓝 x).has_basis (p x) (s x)) (hc : ∀ x i, p x i → is_compact (s x i)) : locally_compact_space α := ⟨λ x t ht, let ⟨i, hp, ht⟩ := (h x).mem_iff.1 ht in ⟨s x i, (h x).mem_of_mem hp, ht, hc x i hp⟩⟩ instance locally_compact_space.prod (α : Type*) (β : Type*) [topological_space α] [topological_space β] [locally_compact_space α] [locally_compact_space β] : locally_compact_space (α × β) := have _ := λ x : α × β, (compact_basis_nhds x.1).prod_nhds' (compact_basis_nhds x.2), locally_compact_space_of_has_basis this $ λ x s ⟨⟨_, h₁⟩, _, h₂⟩, h₁.prod h₂ /-- A reformulation of the definition of locally compact space: In a locally compact space, every open set containing `x` has a compact subset containing `x` in its interior. -/ lemma exists_compact_subset [locally_compact_space α] {x : α} {U : set α} (hU : is_open U) (hx : x ∈ U) : ∃ (K : set α), is_compact K ∧ x ∈ interior K ∧ K ⊆ U := begin rcases locally_compact_space.local_compact_nhds x U (hU.mem_nhds hx) with ⟨K, h1K, h2K, h3K⟩, exact ⟨K, h3K, mem_interior_iff_mem_nhds.2 h1K, h2K⟩, end /-- In a locally compact space every point has a compact neighborhood. -/ lemma exists_compact_mem_nhds [locally_compact_space α] (x : α) : ∃ K, is_compact K ∧ K ∈ 𝓝 x := let ⟨K, hKc, hx, H⟩ := exists_compact_subset is_open_univ (mem_univ x) in ⟨K, hKc, mem_interior_iff_mem_nhds.1 hx⟩ /-- In a locally compact space, every compact set is contained in the interior of a compact set. -/ lemma exists_compact_superset [locally_compact_space α] {K : set α} (hK : is_compact K) : ∃ K', is_compact K' ∧ K ⊆ interior K' := begin choose U hUc hxU using λ x : K, exists_compact_mem_nhds (x : α), have : K ⊆ ⋃ x, interior (U x), from λ x hx, mem_Union.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 (hxU _)⟩, rcases hK.elim_finite_subcover _ _ this with ⟨t, ht⟩, { refine ⟨_, t.compact_bUnion (λ x _, hUc x), λ x hx, _⟩, rcases mem_bUnion_iff.1 (ht hx) with ⟨y, hyt, hy⟩, exact interior_mono (subset_bUnion_of_mem hyt) hy }, { exact λ _, is_open_interior } end lemma ultrafilter.le_nhds_Lim [compact_space α] (F : ultrafilter α) : ↑F ≤ 𝓝 (@Lim _ _ (F : filter α).nonempty_of_ne_bot F) := begin rcases compact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩, exact le_nhds_Lim ⟨x,h⟩, end theorem is_closed.exists_minimal_nonempty_closed_subset [compact_space α] {S : set α} (hS : is_closed S) (hne : S.nonempty) : ∃ (V : set α), V ⊆ S ∧ V.nonempty ∧ is_closed V ∧ (∀ (V' : set α), V' ⊆ V → V'.nonempty → is_closed V' → V' = V) := begin let opens := {U : set α | Sᶜ ⊆ U ∧ is_open U ∧ Uᶜ.nonempty}, obtain ⟨U, ⟨Uc, Uo, Ucne⟩, h⟩ := zorn.zorn_subset opens (λ c hc hz, begin by_cases hcne : c.nonempty, { obtain ⟨U₀, hU₀⟩ := hcne, haveI : nonempty {U // U ∈ c} := ⟨⟨U₀, hU₀⟩⟩, obtain ⟨U₀compl, U₀opn, U₀ne⟩ := hc hU₀, use ⋃₀ c, refine ⟨⟨_, _, _⟩, λ U hU a ha, ⟨U, hU, ha⟩⟩, { exact λ a ha, ⟨U₀, hU₀, U₀compl ha⟩ }, { exact is_open_sUnion (λ _ h, (hc h).2.1) }, { convert_to (⋂(U : {U // U ∈ c}), U.1ᶜ).nonempty, { ext, simp only [not_exists, exists_prop, not_and, set.mem_Inter, subtype.forall, set.mem_set_of_eq, set.mem_compl_eq, subtype.val_eq_coe], refl, }, apply is_compact.nonempty_Inter_of_directed_nonempty_compact_closed, { rintros ⟨U, hU⟩ ⟨U', hU'⟩, obtain ⟨V, hVc, hVU, hVU'⟩ := zorn.chain.directed_on hz U hU U' hU', exact ⟨⟨V, hVc⟩, set.compl_subset_compl.mpr hVU, set.compl_subset_compl.mpr hVU'⟩, }, { exact λ U, (hc U.2).2.2, }, { exact λ U, (is_closed_compl_iff.mpr (hc U.2).2.1).is_compact, }, { exact λ U, (is_closed_compl_iff.mpr (hc U.2).2.1), } } }, { use Sᶜ, refine ⟨⟨set.subset.refl _, is_open_compl_iff.mpr hS, _⟩, λ U Uc, (hcne ⟨U, Uc⟩).elim⟩, rw compl_compl, exact hne, } end), refine ⟨Uᶜ, set.compl_subset_comm.mp Uc, Ucne, is_closed_compl_iff.mpr Uo, _⟩, intros V' V'sub V'ne V'cls, have : V'ᶜ = U, { refine h V'ᶜ ⟨_, is_open_compl_iff.mpr V'cls, _⟩ (set.subset_compl_comm.mp V'sub), exact set.subset.trans Uc (set.subset_compl_comm.mp V'sub), simp only [compl_compl, V'ne], }, rw [←this, compl_compl], end /-- A σ-compact space is a space that is the union of a countable collection of compact subspaces. Note that a locally compact separable T₂ space need not be σ-compact. The sequence can be extracted using `topological_space.compact_covering`. -/ class sigma_compact_space (α : Type*) [topological_space α] : Prop := (exists_compact_covering : ∃ K : ℕ → set α, (∀ n, is_compact (K n)) ∧ (⋃ n, K n) = univ) @[priority 200] -- see Note [lower instance priority] instance compact_space.sigma_compact [compact_space α] : sigma_compact_space α := ⟨⟨λ _, univ, λ _, compact_univ, Union_const _⟩⟩ lemma sigma_compact_space.of_countable (S : set (set α)) (Hc : countable S) (Hcomp : ∀ s ∈ S, is_compact s) (HU : ⋃₀ S = univ) : sigma_compact_space α := ⟨(exists_seq_cover_iff_countable ⟨_, is_compact_empty⟩).2 ⟨S, Hc, Hcomp, HU⟩⟩ @[priority 100] -- see Note [lower instance priority] instance sigma_compact_space_of_locally_compact_second_countable [locally_compact_space α] [second_countable_topology α] : sigma_compact_space α := begin choose K hKc hxK using λ x : α, exists_compact_mem_nhds x, rcases countable_cover_nhds hxK with ⟨s, hsc, hsU⟩, refine sigma_compact_space.of_countable _ (hsc.image K) (ball_image_iff.2 $ λ x _, hKc x) _, rwa sUnion_image end variables (α) [sigma_compact_space α] open sigma_compact_space /-- A choice of compact covering for a `σ`-compact space, chosen to be monotone. -/ def compact_covering : ℕ → set α := accumulate exists_compact_covering.some lemma is_compact_compact_covering (n : ℕ) : is_compact (compact_covering α n) := compact_accumulate (classical.some_spec sigma_compact_space.exists_compact_covering).1 n lemma Union_compact_covering : (⋃ n, compact_covering α n) = univ := begin rw [compact_covering, Union_accumulate], exact (classical.some_spec sigma_compact_space.exists_compact_covering).2 end @[mono] lemma compact_covering_subset ⦃m n : ℕ⦄ (h : m ≤ n) : compact_covering α m ⊆ compact_covering α n := monotone_accumulate h variable {α} lemma exists_mem_compact_covering (x : α) : ∃ n, x ∈ compact_covering α n := Union_eq_univ_iff.mp (Union_compact_covering α) x /-- If `α` is a `σ`-compact space, then a locally finite family of nonempty sets of `α` can have only countably many elements, `set.countable` version. -/ lemma locally_finite.countable_of_sigma_compact {ι : Type*} {f : ι → set α} (hf : locally_finite f) (hne : ∀ i, (f i).nonempty) : countable (univ : set ι) := begin have := λ n, hf.finite_nonempty_inter_compact (is_compact_compact_covering α n), refine (countable_Union (λ n, (this n).countable)).mono (λ i hi, _), rcases hne i with ⟨x, hx⟩, rcases Union_eq_univ_iff.1 (Union_compact_covering α) x with ⟨n, hn⟩, exact mem_Union.2 ⟨n, x, hx, hn⟩ end /-- In a topological space with sigma compact topology, if `f` is a function that sends each point `x` of a closed set `s` to a neighborhood of `x` within `s`, then for some countable set `t ⊆ s`, the neighborhoods `f x`, `x ∈ t`, cover the whole set `s`. -/ lemma countable_cover_nhds_within_of_sigma_compact {f : α → set α} {s : set α} (hs : is_closed s) (hf : ∀ x ∈ s, f x ∈ 𝓝[s] x) : ∃ t ⊆ s, countable t ∧ s ⊆ ⋃ x ∈ t, f x := begin simp only [nhds_within, mem_inf_principal] at hf, choose t ht hsub using λ n, ((is_compact_compact_covering α n).inter_right hs).elim_nhds_subcover _ (λ x hx, hf x hx.right), refine ⟨⋃ n, (t n : set α), Union_subset $ λ n x hx, (ht n x hx).2, countable_Union $ λ n, (t n).countable_to_set, λ x hx, mem_bUnion_iff.2 _⟩, rcases exists_mem_compact_covering x with ⟨n, hn⟩, rcases mem_bUnion_iff.1 (hsub n ⟨hn, hx⟩) with ⟨y, hyt : y ∈ t n, hyf : x ∈ s → x ∈ f y⟩, exact ⟨y, mem_Union.2 ⟨n, hyt⟩, hyf hx⟩ end /-- In a topological space with sigma compact topology, if `f` is a function that sends each point `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`, `x ∈ s`, cover the whole space. -/ lemma countable_cover_nhds_of_sigma_compact {f : α → set α} (hf : ∀ x, f x ∈ 𝓝 x) : ∃ s : set α, countable s ∧ (⋃ x ∈ s, f x) = univ := begin simp only [← nhds_within_univ] at hf, rcases countable_cover_nhds_within_of_sigma_compact is_closed_univ (λ x _, hf x) with ⟨s, -, hsc, hsU⟩, exact ⟨s, hsc, univ_subset_iff.1 hsU⟩ end end compact /-- An [exhaustion by compact sets](https://en.wikipedia.org/wiki/Exhaustion_by_compact_sets) of a topological space is a sequence of compact sets `K n` such that `K n ⊆ interior (K (n + 1))` and `(⋃ n, K n) = univ`. If `X` is a locally compact sigma compact space, then `compact_exhaustion.choice X` provides a choice of an exhaustion by compact sets. This choice is also available as `(default : compact_exhaustion X)`. -/ structure compact_exhaustion (X : Type*) [topological_space X] := (to_fun : ℕ → set X) (is_compact' : ∀ n, is_compact (to_fun n)) (subset_interior_succ' : ∀ n, to_fun n ⊆ interior (to_fun (n + 1))) (Union_eq' : (⋃ n, to_fun n) = univ) namespace compact_exhaustion instance : has_coe_to_fun (compact_exhaustion α) := ⟨_, to_fun⟩ variables {α} (K : compact_exhaustion α) protected lemma is_compact (n : ℕ) : is_compact (K n) := K.is_compact' n lemma subset_interior_succ (n : ℕ) : K n ⊆ interior (K (n + 1)) := K.subset_interior_succ' n lemma subset_succ (n : ℕ) : K n ⊆ K (n + 1) := subset.trans (K.subset_interior_succ n) interior_subset @[mono] protected lemma subset ⦃m n : ℕ⦄ (h : m ≤ n) : K m ⊆ K n := show K m ≤ K n, from monotone_nat_of_le_succ K.subset_succ h lemma subset_interior ⦃m n : ℕ⦄ (h : m < n) : K m ⊆ interior (K n) := subset.trans (K.subset_interior_succ m) $ interior_mono $ K.subset h lemma Union_eq : (⋃ n, K n) = univ := K.Union_eq' lemma exists_mem (x : α) : ∃ n, x ∈ K n := Union_eq_univ_iff.1 K.Union_eq x /-- The minimal `n` such that `x ∈ K n`. -/ protected noncomputable def find (x : α) : ℕ := nat.find (K.exists_mem x) lemma mem_find (x : α) : x ∈ K (K.find x) := nat.find_spec (K.exists_mem x) lemma mem_iff_find_le {x : α} {n : ℕ} : x ∈ K n ↔ K.find x ≤ n := ⟨λ h, nat.find_min' (K.exists_mem x) h, λ h, K.subset h $ K.mem_find x⟩ /-- Prepend the empty set to a compact exhaustion `K n`. -/ def shiftr : compact_exhaustion α := { to_fun := λ n, nat.cases_on n ∅ K, is_compact' := λ n, nat.cases_on n is_compact_empty K.is_compact, subset_interior_succ' := λ n, nat.cases_on n (empty_subset _) K.subset_interior_succ, Union_eq' := Union_eq_univ_iff.2 $ λ x, ⟨K.find x + 1, K.mem_find x⟩ } @[simp] lemma find_shiftr (x : α) : K.shiftr.find x = K.find x + 1 := nat.find_comp_succ _ _ (not_mem_empty _) lemma mem_diff_shiftr_find (x : α) : x ∈ K.shiftr (K.find x + 1) \ K.shiftr (K.find x) := ⟨K.mem_find _, mt K.shiftr.mem_iff_find_le.1 $ by simp only [find_shiftr, not_le, nat.lt_succ_self]⟩ /-- A choice of an [exhaustion by compact sets](https://en.wikipedia.org/wiki/Exhaustion_by_compact_sets) of a locally compact sigma compact space. -/ noncomputable def choice (X : Type*) [topological_space X] [locally_compact_space X] [sigma_compact_space X] : compact_exhaustion X := begin apply classical.choice, let K : ℕ → {s : set X // is_compact s} := λ n, nat.rec_on n ⟨∅, is_compact_empty⟩ (λ n s, ⟨(exists_compact_superset s.2).some ∪ compact_covering X n, (exists_compact_superset s.2).some_spec.1.union (is_compact_compact_covering _ _)⟩), refine ⟨⟨λ n, K n, λ n, (K n).2, λ n, _, _⟩⟩, { exact subset.trans (exists_compact_superset (K n).2).some_spec.2 (interior_mono $ subset_union_left _ _) }, { refine univ_subset_iff.1 (Union_compact_covering X ▸ _), exact Union_subset_Union2 (λ n, ⟨n + 1, subset_union_right _ _⟩) } end noncomputable instance [locally_compact_space α] [sigma_compact_space α] : inhabited (compact_exhaustion α) := ⟨compact_exhaustion.choice α⟩ end compact_exhaustion section clopen /-- A set is clopen if it is both open and closed. -/ def is_clopen (s : set α) : Prop := is_open s ∧ is_closed s theorem is_clopen.union {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) := ⟨is_open.union hs.1 ht.1, is_closed.union hs.2 ht.2⟩ theorem is_clopen.inter {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) := ⟨is_open.inter hs.1 ht.1, is_closed.inter hs.2 ht.2⟩ @[simp] theorem is_clopen_empty : is_clopen (∅ : set α) := ⟨is_open_empty, is_closed_empty⟩ @[simp] theorem is_clopen_univ : is_clopen (univ : set α) := ⟨is_open_univ, is_closed_univ⟩ theorem is_clopen.compl {s : set α} (hs : is_clopen s) : is_clopen sᶜ := ⟨hs.2.is_open_compl, is_closed_compl_iff.2 hs.1⟩ @[simp] theorem is_clopen_compl_iff {s : set α} : is_clopen sᶜ ↔ is_clopen s := ⟨λ h, compl_compl s ▸ is_clopen.compl h, is_clopen.compl⟩ theorem is_clopen.diff {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \ t) := hs.inter ht.compl lemma is_clopen_Union {β : Type*} [fintype β] {s : β → set α} (h : ∀ i, is_clopen (s i)) : is_clopen (⋃ i, s i) := ⟨is_open_Union (forall_and_distrib.1 h).1, is_closed_Union (forall_and_distrib.1 h).2⟩ lemma is_clopen_bUnion {β : Type*} {s : finset β} {f : β → set α} (h : ∀i ∈ s, is_clopen $ f i) : is_clopen (⋃ i ∈ s, f i) := begin refine ⟨is_open_bUnion (λ i hi, (h i hi).1), _⟩, show is_closed (⋃ (i : β) (H : i ∈ (s : set β)), f i), rw bUnion_eq_Union, exact is_closed_Union (λ ⟨i, hi⟩,(h i hi).2) end lemma is_clopen_Inter {β : Type*} [fintype β] {s : β → set α} (h : ∀ i, is_clopen (s i)) : is_clopen (⋂ i, s i) := ⟨(is_open_Inter (forall_and_distrib.1 h).1), (is_closed_Inter (forall_and_distrib.1 h).2)⟩ lemma is_clopen_bInter {β : Type*} {s : finset β} {f : β → set α} (h : ∀i∈s, is_clopen (f i)) : is_clopen (⋂i∈s, f i) := ⟨ is_open_bInter ⟨finset_coe.fintype s⟩ (λ i hi, (h i hi).1), by {show is_closed (⋂ (i : β) (H : i ∈ (↑s : set β)), f i), rw bInter_eq_Inter, apply is_closed_Inter, rintro ⟨i, hi⟩, exact (h i hi).2}⟩ lemma continuous_on.preimage_clopen_of_clopen {β: Type*} [topological_space β] {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ f⁻¹' t) := ⟨continuous_on.preimage_open_of_open hf hs.1 ht.1, continuous_on.preimage_closed_of_closed hf hs.2 ht.2⟩ /-- The intersection of a disjoint covering by two open sets of a clopen set will be clopen. -/ theorem is_clopen_inter_of_disjoint_cover_clopen {Z a b : set α} (h : is_clopen Z) (cover : Z ⊆ a ∪ b) (ha : is_open a) (hb : is_open b) (hab : a ∩ b = ∅) : is_clopen (Z ∩ a) := begin refine ⟨is_open.inter h.1 ha, _⟩, have : is_closed (Z ∩ bᶜ) := is_closed.inter h.2 (is_closed_compl_iff.2 hb), convert this using 1, apply subset.antisymm, { exact inter_subset_inter_right Z (subset_compl_iff_disjoint.2 hab) }, { rintros x ⟨hx₁, hx₂⟩, exact ⟨hx₁, by simpa [not_mem_of_mem_compl hx₂] using cover hx₁⟩ } end @[simp] lemma is_clopen_discrete [discrete_topology α] (x : set α) : is_clopen x := ⟨is_open_discrete _, is_closed_discrete _⟩ end clopen section preirreducible /-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/ def is_preirreducible (s : set α) : Prop := ∀ (u v : set α), is_open u → is_open v → (s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty /-- An irreducible set `s` is one that is nonempty and where there is no non-trivial pair of disjoint opens on `s`. -/ def is_irreducible (s : set α) : Prop := s.nonempty ∧ is_preirreducible s lemma is_irreducible.nonempty {s : set α} (h : is_irreducible s) : s.nonempty := h.1 lemma is_irreducible.is_preirreducible {s : set α} (h : is_irreducible s) : is_preirreducible s := h.2 theorem is_preirreducible_empty : is_preirreducible (∅ : set α) := λ _ _ _ _ _ ⟨x, h1, h2⟩, h1.elim theorem is_irreducible_singleton {x} : is_irreducible ({x} : set α) := ⟨singleton_nonempty x, λ u v _ _ ⟨y, h1, h2⟩ ⟨z, h3, h4⟩, by rw mem_singleton_iff at h1 h3; substs y z; exact ⟨x, rfl, h2, h4⟩⟩ theorem is_preirreducible.closure {s : set α} (H : is_preirreducible s) : is_preirreducible (closure s) := λ u v hu hv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩, let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in let ⟨r, hrs, hruv⟩ := H u v hu hv ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in ⟨r, subset_closure hrs, hruv⟩ lemma is_irreducible.closure {s : set α} (h : is_irreducible s) : is_irreducible (closure s) := ⟨h.nonempty.closure, h.is_preirreducible.closure⟩ theorem exists_preirreducible (s : set α) (H : is_preirreducible s) : ∃ t : set α, is_preirreducible t ∧ s ⊆ t ∧ ∀ u, is_preirreducible u → t ⊆ u → u = t := let ⟨m, hm, hsm, hmm⟩ := zorn.zorn_subset_nonempty {t : set α | is_preirreducible t} (λ c hc hcc hcn, let ⟨t, htc⟩ := hcn in ⟨⋃₀ c, λ u v hu hv ⟨y, hy, hyu⟩ ⟨z, hz, hzv⟩, let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy, ⟨q, hqc, hzq⟩ := mem_sUnion.1 hz in or.cases_on (zorn.chain.total hcc hpc hqc) (assume hpq : p ⊆ q, let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv ⟨y, hpq hyp, hyu⟩ ⟨z, hzq, hzv⟩ in ⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩) (assume hqp : q ⊆ p, let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv ⟨y, hyp, hyu⟩ ⟨z, hqp hzq, hzv⟩ in ⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩), λ x hxc, subset_sUnion_of_mem hxc⟩) s H in ⟨m, hm, hsm, λ u hu hmu, hmm _ hu hmu⟩ /-- A maximal irreducible set that contains a given point. -/ def irreducible_component (x : α) : set α := classical.some (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible) lemma irreducible_component_property (x : α) : is_preirreducible (irreducible_component x) ∧ {x} ⊆ (irreducible_component x) ∧ ∀ u, is_preirreducible u → (irreducible_component x) ⊆ u → u = (irreducible_component x) := classical.some_spec (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible) theorem mem_irreducible_component {x : α} : x ∈ irreducible_component x := singleton_subset_iff.1 (irreducible_component_property x).2.1 theorem is_irreducible_irreducible_component {x : α} : is_irreducible (irreducible_component x) := ⟨⟨x, mem_irreducible_component⟩, (irreducible_component_property x).1⟩ theorem eq_irreducible_component {x : α} : ∀ {s : set α}, is_preirreducible s → irreducible_component x ⊆ s → s = irreducible_component x := (irreducible_component_property x).2.2 theorem is_closed_irreducible_component {x : α} : is_closed (irreducible_component x) := closure_eq_iff_is_closed.1 $ eq_irreducible_component is_irreducible_irreducible_component.is_preirreducible.closure subset_closure /-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/ class preirreducible_space (α : Type u) [topological_space α] : Prop := (is_preirreducible_univ [] : is_preirreducible (univ : set α)) /-- An irreducible space is one that is nonempty and where there is no non-trivial pair of disjoint opens. -/ class irreducible_space (α : Type u) [topological_space α] extends preirreducible_space α : Prop := (to_nonempty [] : nonempty α) -- see Note [lower instance priority] attribute [instance, priority 50] irreducible_space.to_nonempty theorem nonempty_preirreducible_inter [preirreducible_space α] {s t : set α} : is_open s → is_open t → s.nonempty → t.nonempty → (s ∩ t).nonempty := by simpa only [univ_inter, univ_subset_iff] using @preirreducible_space.is_preirreducible_univ α _ _ s t theorem is_preirreducible.image [topological_space β] {s : set α} (H : is_preirreducible s) (f : α → β) (hf : continuous_on f s) : is_preirreducible (f '' s) := begin rintros u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩, rw ← mem_preimage at hxu hyv, rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩, rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩, have := H u' v' hu' hv', rw [inter_comm s u', ← u'_eq] at this, rw [inter_comm s v', ← v'_eq] at this, rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨z, hzs, hzu', hzv'⟩, refine ⟨f z, mem_image_of_mem f hzs, _, _⟩, all_goals { rw ← mem_preimage, apply mem_of_mem_inter_left, show z ∈ _ ∩ s, simp [*] } end theorem is_irreducible.image [topological_space β] {s : set α} (H : is_irreducible s) (f : α → β) (hf : continuous_on f s) : is_irreducible (f '' s) := ⟨nonempty_image_iff.mpr H.nonempty, H.is_preirreducible.image f hf⟩ lemma subtype.preirreducible_space {s : set α} (h : is_preirreducible s) : preirreducible_space s := { is_preirreducible_univ := begin intros u v hu hv hsu hsv, rw is_open_induced_iff at hu hv, rcases hu with ⟨u, hu, rfl⟩, rcases hv with ⟨v, hv, rfl⟩, rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩, rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩, rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩, exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩ end } lemma subtype.irreducible_space {s : set α} (h : is_irreducible s) : irreducible_space s := { is_preirreducible_univ := (subtype.preirreducible_space h.is_preirreducible).is_preirreducible_univ, to_nonempty := h.nonempty.to_subtype } /-- A set `s` is irreducible if and only if for every finite collection of open sets all of whose members intersect `s`, `s` also intersects the intersection of the entire collection (i.e., there is an element of `s` contained in every member of the collection). -/ lemma is_irreducible_iff_sInter {s : set α} : is_irreducible s ↔ ∀ (U : finset (set α)) (hU : ∀ u ∈ U, is_open u) (H : ∀ u ∈ U, (s ∩ u).nonempty), (s ∩ ⋂₀ ↑U).nonempty := begin split; intro h, { intro U, apply finset.induction_on U, { intros, simpa using h.nonempty }, { intros u U hu IH hU H, rw [finset.coe_insert, sInter_insert], apply h.2, { solve_by_elim [finset.mem_insert_self] }, { apply is_open_sInter (finset.finite_to_set U), intros, solve_by_elim [finset.mem_insert_of_mem] }, { solve_by_elim [finset.mem_insert_self] }, { apply IH, all_goals { intros, solve_by_elim [finset.mem_insert_of_mem] } } } }, { split, { simpa using h ∅ _ _; intro u; simp }, intros u v hu hv hu' hv', simpa using h {u,v} _ _, all_goals { intro t, rw [finset.mem_insert, finset.mem_singleton], rintro (rfl|rfl); assumption } } end /-- A set is preirreducible if and only if for every cover by two closed sets, it is contained in one of the two covering sets. -/ lemma is_preirreducible_iff_closed_union_closed {s : set α} : is_preirreducible s ↔ ∀ (z₁ z₂ : set α), is_closed z₁ → is_closed z₂ → s ⊆ z₁ ∪ z₂ → s ⊆ z₁ ∨ s ⊆ z₂ := begin split, all_goals { intros h t₁ t₂ ht₁ ht₂, specialize h t₁ᶜ t₂ᶜ, simp only [is_open_compl_iff, is_closed_compl_iff] at h, specialize h ht₁ ht₂ }, { contrapose!, simp only [not_subset], rintro ⟨⟨x, hx, hx'⟩, ⟨y, hy, hy'⟩⟩, rcases h ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩ with ⟨z, hz, hz'⟩, rw ← compl_union at hz', exact ⟨z, hz, hz'⟩ }, { rintro ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩, rw ← compl_inter at h, delta set.nonempty, rw imp_iff_not_or at h, contrapose! h, split, { intros z hz hz', exact h z ⟨hz, hz'⟩ }, { split; intro H; refine H _ ‹_›; assumption } } end /-- A set is irreducible if and only if for every cover by a finite collection of closed sets, it is contained in one of the members of the collection. -/ lemma is_irreducible_iff_sUnion_closed {s : set α} : is_irreducible s ↔ ∀ (Z : finset (set α)) (hZ : ∀ z ∈ Z, is_closed z) (H : s ⊆ ⋃₀ ↑Z), ∃ z ∈ Z, s ⊆ z := begin rw [is_irreducible, is_preirreducible_iff_closed_union_closed], split; intro h, { intro Z, apply finset.induction_on Z, { intros, rw [finset.coe_empty, sUnion_empty] at H, rcases h.1 with ⟨x, hx⟩, exfalso, tauto }, { intros z Z hz IH hZ H, cases h.2 z (⋃₀ ↑Z) _ _ _ with h' h', { exact ⟨z, finset.mem_insert_self _ _, h'⟩ }, { rcases IH _ h' with ⟨z', hz', hsz'⟩, { exact ⟨z', finset.mem_insert_of_mem hz', hsz'⟩ }, { intros, solve_by_elim [finset.mem_insert_of_mem] } }, { solve_by_elim [finset.mem_insert_self] }, { rw sUnion_eq_bUnion, apply is_closed_bUnion (finset.finite_to_set Z), { intros, solve_by_elim [finset.mem_insert_of_mem] } }, { simpa using H } } }, { split, { by_contradiction hs, simpa using h ∅ _ _, { intro z, simp }, { simpa [set.nonempty] using hs } }, intros z₁ z₂ hz₁ hz₂ H, have := h {z₁, z₂} _ _, simp only [exists_prop, finset.mem_insert, finset.mem_singleton] at this, { rcases this with ⟨z, rfl|rfl, hz⟩; tauto }, { intro t, rw [finset.mem_insert, finset.mem_singleton], rintro (rfl|rfl); assumption }, { simpa using H } } end end preirreducible
c8d09d3009698eb1a488f5d5ef1ad3f04a6f8192
f5f7e6fae601a5fe3cac7cc3ed353ed781d62419
/src/category/traversable/equiv.lean
650e4adcb986de04443901964eb58699f43a1d07
[ "Apache-2.0" ]
permissive
EdAyers/mathlib
9ecfb2f14bd6caad748b64c9c131befbff0fb4e0
ca5d4c1f16f9c451cf7170b10105d0051db79e1b
refs/heads/master
1,626,189,395,845
1,555,284,396,000
1,555,284,396,000
144,004,030
0
0
Apache-2.0
1,533,727,664,000
1,533,727,663,000
null
UTF-8
Lean
false
false
4,784
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon Transferring `traversable` instances using isomorphisms. -/ import data.equiv.basic category.traversable.lemmas universes u namespace equiv section functor parameters {t t' : Type u → Type u} parameters (eqv : Π α, t α ≃ t' α) variables [functor t] open functor protected def map {α β : Type u} (f : α → β) (x : t' α) : t' β := eqv β $ map f ((eqv α).symm x) protected def functor : functor t' := { map := @equiv.map _ } variables [is_lawful_functor t] protected lemma id_map {α : Type u} (x : t' α) : equiv.map id x = x := by simp [equiv.map, id_map] protected lemma comp_map {α β γ : Type u} (g : α → β) (h : β → γ) (x : t' α) : equiv.map (h ∘ g) x = equiv.map h (equiv.map g x) := by simp [equiv.map]; apply comp_map protected def is_lawful_functor : @is_lawful_functor _ equiv.functor := { id_map := @equiv.id_map _ _, comp_map := @equiv.comp_map _ _ } protected def is_lawful_functor' [F : _root_.functor t'] (h₀ : ∀ {α β} (f : α → β), _root_.functor.map f = equiv.map f) (h₁ : ∀ {α β} (f : β), _root_.functor.map_const f = (equiv.map ∘ function.const α) f) : _root_.is_lawful_functor t' := begin have : F = equiv.functor, { unfreezeI, cases F, dsimp [equiv.functor], congr; ext; [rw ← h₀, rw ← h₁] }, constructor; intros; haveI F' := equiv.is_lawful_functor, { simp, intros, ext, rw [h₁], rw ← this at F', have k := @map_const_eq t' _ _ α β, rw this at ⊢ k, rw ← k, refl }, { rw [h₀], rw ← this at F', have k := id_map x, rw this at k, apply k }, { rw [h₀], rw ← this at F', have k := comp_map g h x, revert k, rw this, exact id }, end end functor section traversable parameters {t t' : Type u → Type u} parameters (eqv : Π α, t α ≃ t' α) variables [traversable t] variables {m : Type u → Type u} [applicative m] variables {α β : Type u} protected def traverse (f : α → m β) (x : t' α) : m (t' β) := eqv β <$> traverse f ((eqv α).symm x) protected def traversable : traversable t' := { to_functor := equiv.functor eqv, traverse := @equiv.traverse _ } end traversable section equiv parameters {t t' : Type u → Type u} parameters (eqv : Π α, t α ≃ t' α) variables [traversable t] [is_lawful_traversable t] variables {F G : Type u → Type u} [applicative F] [applicative G] variables [is_lawful_applicative F] [is_lawful_applicative G] variables (η : applicative_transformation F G) variables {α β γ : Type u} open is_lawful_traversable functor protected lemma id_traverse (x : t' α) : equiv.traverse eqv id.mk x = x := by simp! [equiv.traverse,id_bind,id_traverse,functor.map] with functor_norm protected lemma traverse_eq_map_id (f : α → β) (x : t' α) : equiv.traverse eqv (id.mk ∘ f) x = id.mk (equiv.map eqv f x) := by simp [equiv.traverse, traverse_eq_map_id] with functor_norm; refl protected lemma comp_traverse (f : β → F γ) (g : α → G β) (x : t' α) : equiv.traverse eqv (comp.mk ∘ functor.map f ∘ g) x = comp.mk (equiv.traverse eqv f <$> equiv.traverse eqv g x) := by simp [equiv.traverse,comp_traverse] with functor_norm; congr; ext; simp protected lemma naturality (f : α → F β) (x : t' α) : η (equiv.traverse eqv f x) = equiv.traverse eqv (@η _ ∘ f) x := by simp [equiv.traverse] with functor_norm protected def is_lawful_traversable : @is_lawful_traversable t' (equiv.traversable eqv) := { to_is_lawful_functor := @equiv.is_lawful_functor _ _ eqv _ _, id_traverse := @equiv.id_traverse _ _, comp_traverse := @equiv.comp_traverse _ _, traverse_eq_map_id := @equiv.traverse_eq_map_id _ _, naturality := @equiv.naturality _ _ } protected def is_lawful_traversable' [_i : traversable t'] (h₀ : ∀ {α β} (f : α → β), map f = equiv.map eqv f) (h₁ : ∀ {α β} (f : β), map_const f = (equiv.map eqv ∘ function.const α) f) (h₂ : ∀ {F : Type u → Type u} [applicative F] [is_lawful_applicative F] {α β} (f : α → F β), traverse f = equiv.traverse eqv f) : _root_.is_lawful_traversable t' := begin -- we can't use the same approach as for `is_lawful_functor'` because -- h₂ needs a `is_lawful_applicative` assumption refine {to_is_lawful_functor := equiv.is_lawful_functor' eqv @h₀ @h₁, ..}; intros; resetI, { rw [h₂, equiv.id_traverse], apply_instance }, { rw [h₂, equiv.comp_traverse f g x, h₂], congr, rw [h₂], all_goals { apply_instance } }, { rw [h₂, equiv.traverse_eq_map_id, h₀]; apply_instance }, { rw [h₂, equiv.naturality, h₂]; apply_instance } end end equiv end equiv
c87b8b48298f432d69e55c44666c3cd2b2a4d3df
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/option/basic.lean
5c1a3bd8cae1dea089cd0a7fa3bcd0532c7b8800
[ "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
18,680
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import logic.is_empty import tactic.basic import logic.relator /-! # Option of a type This file develops the basic theory of option types. If `α` is a type, then `option α` can be understood as the type with one more element than `α`. `option α` has terms `some a`, where `a : α`, and `none`, which is the added element. This is useful in multiple ways: * It is the prototype of addition of terms to a type. See for example `with_bot α` which uses `none` as an element smaller than all others. * It can be used to define failsafe partial functions, which return `some the_result_we_expect` if we can find `the_result_we_expect`, and `none` if there is no meaningful result. This forces any subsequent use of the partial function to explicitly deal with the exceptions that make it return `none`. * `option` is a monad. We love monads. `part` is an alternative to `option` that can be seen as the type of `true`/`false` values along with a term `a : α` if the value is `true`. ## Implementation notes `option` is currently defined in core Lean, but this will change in Lean 4. -/ namespace option variables {α : Type*} {β : Type*} {γ : Type*} lemma coe_def : (coe : α → option α) = some := rfl lemma some_ne_none (x : α) : some x ≠ none := λ h, option.no_confusion h protected lemma «forall» {p : option α → Prop} : (∀ x, p x) ↔ p none ∧ ∀ x, p (some x) := ⟨λ h, ⟨h _, λ x, h _⟩, λ h x, option.cases_on x h.1 h.2⟩ protected lemma «exists» {p : option α → Prop} : (∃ x, p x) ↔ p none ∨ ∃ x, p (some x) := ⟨λ ⟨x, hx⟩, (option.cases_on x or.inl $ λ x hx, or.inr ⟨x, hx⟩) hx, λ h, h.elim (λ h, ⟨_, h⟩) (λ ⟨x, hx⟩, ⟨_, hx⟩)⟩ @[simp] theorem get_mem : ∀ {o : option α} (h : is_some o), option.get h ∈ o | (some a) _ := rfl theorem get_of_mem {a : α} : ∀ {o : option α} (h : is_some o), a ∈ o → option.get h = a | _ _ rfl := rfl @[simp] lemma not_mem_none (a : α) : a ∉ (none : option α) := λ h, option.no_confusion h @[simp] lemma some_get : ∀ {x : option α} (h : is_some x), some (option.get h) = x | (some x) hx := rfl @[simp] lemma get_some (x : α) (h : is_some (some x)) : option.get h = x := rfl @[simp] lemma get_or_else_some (x y : α) : option.get_or_else (some x) y = x := rfl @[simp] lemma get_or_else_none (x : α) : option.get_or_else none x = x := rfl @[simp] lemma get_or_else_coe (x y : α) : option.get_or_else ↑x y = x := rfl lemma get_or_else_of_ne_none {x : option α} (hx : x ≠ none) (y : α) : some (x.get_or_else y) = x := by cases x; [contradiction, rw get_or_else_some] @[simp] lemma coe_get {o : option α} (h : o.is_some) : ((option.get h : α) : option α) = o := option.some_get h theorem mem_unique {o : option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b := option.some.inj $ ha.symm.trans hb theorem eq_of_mem_of_mem {a : α} {o1 o2 : option α} (h1 : a ∈ o1) (h2 : a ∈ o2) : o1 = o2 := h1.trans h2.symm theorem mem.left_unique : relator.left_unique ((∈) : α → option α → Prop) := λ a o b, mem_unique theorem some_injective (α : Type*) : function.injective (@some α) := λ _ _, some_inj.mp /-- `option.map f` is injective if `f` is injective. -/ theorem map_injective {f : α → β} (Hf : function.injective f) : function.injective (option.map f) | none none H := rfl | (some a₁) (some a₂) H := by rw Hf (option.some.inj H) @[ext] theorem ext : ∀ {o₁ o₂ : option α}, (∀ a, a ∈ o₁ ↔ a ∈ o₂) → o₁ = o₂ | none none H := rfl | (some a) o H := ((H _).1 rfl).symm | o (some b) H := (H _).2 rfl theorem eq_none_iff_forall_not_mem {o : option α} : o = none ↔ (∀ a, a ∉ o) := ⟨λ e a h, by rw e at h; cases h, λ h, ext $ by simpa⟩ @[simp] theorem none_bind {α β} (f : α → option β) : none >>= f = none := rfl @[simp] theorem some_bind {α β} (a : α) (f : α → option β) : some a >>= f = f a := rfl @[simp] theorem none_bind' (f : α → option β) : none.bind f = none := rfl @[simp] theorem some_bind' (a : α) (f : α → option β) : (some a).bind f = f a := rfl @[simp] theorem bind_some : ∀ x : option α, x >>= some = x := @bind_pure α option _ _ @[simp] theorem bind_eq_some {α β} {x : option α} {f : α → option β} {b : β} : x >>= f = some b ↔ ∃ a, x = some a ∧ f a = some b := by cases x; simp @[simp] theorem bind_eq_some' {x : option α} {f : α → option β} {b : β} : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by cases x; simp @[simp] theorem bind_eq_none' {o : option α} {f : α → option β} : o.bind f = none ↔ (∀ b a, a ∈ o → b ∉ f a) := by simp only [eq_none_iff_forall_not_mem, not_exists, not_and, mem_def, bind_eq_some'] @[simp] theorem bind_eq_none {α β} {o : option α} {f : α → option β} : o >>= f = none ↔ (∀ b a, a ∈ o → b ∉ f a) := bind_eq_none' lemma bind_comm {α β γ} {f : α → β → option γ} (a : option α) (b : option β) : a.bind (λx, b.bind (f x)) = b.bind (λy, a.bind (λx, f x y)) := by cases a; cases b; refl lemma bind_assoc (x : option α) (f : α → option β) (g : β → option γ) : (x.bind f).bind g = x.bind (λ y, (f y).bind g) := by cases x; refl lemma join_eq_some {x : option (option α)} {a : α} : x.join = some a ↔ x = some (some a) := by simp lemma join_ne_none {x : option (option α)} : x.join ≠ none ↔ ∃ z, x = some (some z) := by simp lemma join_ne_none' {x : option (option α)} : ¬(x.join = none) ↔ ∃ z, x = some (some z) := by simp lemma join_eq_none {o : option (option α)} : o.join = none ↔ o = none ∨ o = some none := by rcases o with _|_|_; simp lemma bind_id_eq_join {x : option (option α)} : x >>= id = x.join := by simp lemma join_eq_join : mjoin = @join α := funext (λ x, by rw [mjoin, bind_id_eq_join]) lemma bind_eq_bind {α β : Type*} {f : α → option β} {x : option α} : x >>= f = x.bind f := rfl @[simp] lemma map_eq_map {α β} {f : α → β} : (<$>) f = option.map f := rfl theorem map_none {α β} {f : α → β} : f <$> none = none := rfl theorem map_some {α β} {a : α} {f : α → β} : f <$> some a = some (f a) := rfl theorem map_coe {α β} {a : α} {f : α → β} : f <$> (a : option α) = ↑(f a) := rfl @[simp] theorem map_none' {f : α → β} : option.map f none = none := rfl @[simp] theorem map_some' {a : α} {f : α → β} : option.map f (some a) = some (f a) := rfl @[simp] theorem map_coe' {a : α} {f : α → β} : option.map f (a : option α) = ↑(f a) := rfl theorem map_eq_some {α β} {x : option α} {f : α → β} {b : β} : f <$> x = some b ↔ ∃ a, x = some a ∧ f a = b := by cases x; simp @[simp] theorem map_eq_some' {x : option α} {f : α → β} {b : β} : x.map f = some b ↔ ∃ a, x = some a ∧ f a = b := by cases x; simp lemma map_eq_none {α β} {x : option α} {f : α → β} : f <$> x = none ↔ x = none := by { cases x; simp only [map_none, map_some, eq_self_iff_true] } @[simp] lemma map_eq_none' {x : option α} {f : α → β} : x.map f = none ↔ x = none := by { cases x; simp only [map_none', map_some', eq_self_iff_true] } lemma map_congr {f g : α → β} {x : option α} (h : ∀ a ∈ x, f a = g a) : option.map f x = option.map g x := by { cases x; simp only [map_none', map_some', h, mem_def] } @[simp] theorem map_id' : option.map (@id α) = id := map_id @[simp] lemma map_map (h : β → γ) (g : α → β) (x : option α) : option.map h (option.map g x) = option.map (h ∘ g) x := by { cases x; simp only [map_none', map_some'] } lemma comp_map (h : β → γ) (g : α → β) (x : option α) : option.map (h ∘ g) x = option.map h (option.map g x) := (map_map _ _ _).symm @[simp] lemma map_comp_map (f : α → β) (g : β → γ) : option.map g ∘ option.map f = option.map (g ∘ f) := by { ext x, rw comp_map } lemma mem_map_of_mem {α β : Type*} {a : α} {x : option α} (g : α → β) (h : a ∈ x) : g a ∈ x.map g := mem_def.mpr ((mem_def.mp h).symm ▸ map_some') lemma bind_map_comm {α β} {x : option (option α) } {f : α → β} : x >>= option.map f = x.map (option.map f) >>= id := by { cases x; simp } lemma join_map_eq_map_join {f : α → β} {x : option (option α)} : (x.map (option.map f)).join = x.join.map f := by { rcases x with _ | _ | x; simp } lemma join_join {x : option (option (option α))} : x.join.join = (x.map join).join := by { rcases x with _ | _ | _ | x; simp } lemma mem_of_mem_join {a : α} {x : option (option α)} (h : a ∈ x.join) : some a ∈ x := mem_def.mpr ((mem_def.mp h).symm ▸ join_eq_some.mp h) section pmap variables {p : α → Prop} (f : Π (a : α), p a → β) (x : option α) @[simp] lemma pbind_eq_bind (f : α → option β) (x : option α) : x.pbind (λ a _, f a) = x.bind f := by { cases x; simp only [pbind, none_bind', some_bind'] } lemma map_bind {α β γ} (f : β → γ) (x : option α) (g : α → option β) : option.map f (x >>= g) = (x >>= λ a, option.map f (g a)) := by simp_rw [←map_eq_map, ←bind_pure_comp_eq_map,is_lawful_monad.bind_assoc] lemma map_bind' (f : β → γ) (x : option α) (g : α → option β) : option.map f (x.bind g) = x.bind (λ a, option.map f (g a)) := by { cases x; simp } lemma map_pbind (f : β → γ) (x : option α) (g : Π a, a ∈ x → option β) : option.map f (x.pbind g) = (x.pbind (λ a H, option.map f (g a H))) := by { cases x; simp only [pbind, map_none'] } lemma pbind_map (f : α → β) (x : option α) (g : Π (b : β), b ∈ x.map f → option γ) : pbind (option.map f x) g = x.pbind (λ a h, g (f a) (mem_map_of_mem _ h)) := by { cases x; refl } @[simp] lemma pmap_none (f : Π (a : α), p a → β) {H} : pmap f (@none α) H = none := rfl @[simp] lemma pmap_some (f : Π (a : α), p a → β) {x : α} (h : p x) : pmap f (some x) = λ _, some (f x h) := rfl lemma mem_pmem {a : α} (h : ∀ a ∈ x, p a) (ha : a ∈ x) : f a (h a ha) ∈ pmap f x h := by { rw mem_def at ha ⊢, subst ha, refl } lemma pmap_map (g : γ → α) (x : option γ) (H) : pmap f (x.map g) H = pmap (λ a h, f (g a) h) x (λ a h, H _ (mem_map_of_mem _ h)) := by { cases x; simp only [map_none', map_some', pmap] } lemma map_pmap (g : β → γ) (f : Π a, p a → β) (x H) : option.map g (pmap f x H) = pmap (λ a h, g (f a h)) x H := by { cases x; simp only [map_none', map_some', pmap] } @[simp] lemma pmap_eq_map (p : α → Prop) (f : α → β) (x H) : @pmap _ _ p (λ a _, f a) x H = option.map f x := by { cases x; simp only [map_none', map_some', pmap] } lemma pmap_bind {α β γ} {x : option α} {g : α → option β} {p : β → Prop} {f : Π b, p b → γ} (H) (H' : ∀ (a : α) b ∈ g a, b ∈ x >>= g) : pmap f (x >>= g) H = (x >>= λa, pmap f (g a) (λ b h, H _ (H' a _ h))) := by { cases x; simp only [pmap, none_bind, some_bind] } lemma bind_pmap {α β γ} {p : α → Prop} (f : Π a, p a → β) (x : option α) (g : β → option γ) (H) : (pmap f x H) >>= g = x.pbind (λ a h, g (f a (H _ h))) := by { cases x; simp only [pmap, none_bind, some_bind, pbind] } variables {f x} lemma pbind_eq_none {f : Π (a : α), a ∈ x → option β} (h' : ∀ a ∈ x, f a H = none → x = none) : x.pbind f = none ↔ x = none := begin cases x, { simp }, { simp only [pbind, iff_false], intro h, cases h' x rfl h } end lemma pbind_eq_some {f : Π (a : α), a ∈ x → option β} {y : β} : x.pbind f = some y ↔ ∃ (z ∈ x), f z H = some y := begin cases x, { simp }, { simp only [pbind], split, { intro h, use x, simpa only [mem_def, exists_prop_of_true] using h }, { rintro ⟨z, H, hz⟩, simp only [mem_def] at H, simpa only [H] using hz } } end @[simp] lemma pmap_eq_none_iff {h} : pmap f x h = none ↔ x = none := by { cases x; simp } @[simp] lemma pmap_eq_some_iff {hf} {y : β} : pmap f x hf = some y ↔ ∃ (a : α) (H : x = some a), f a (hf a H) = y := begin cases x, { simp only [not_mem_none, exists_false, pmap, not_false_iff, exists_prop_of_false] }, { split, { intro h, simp only [pmap] at h, exact ⟨x, rfl, h⟩ }, { rintro ⟨a, H, rfl⟩, simp only [mem_def] at H, simp only [H, pmap] } } end @[simp] lemma join_pmap_eq_pmap_join {f : Π a, p a → β} {x : option (option α)} (H) : (pmap (pmap f) x H).join = pmap f x.join (λ a h, H (some a) (mem_of_mem_join h) _ rfl) := by { rcases x with _ | _ | x; simp } end pmap @[simp] theorem seq_some {α β} {a : α} {f : α → β} : some f <*> some a = some (f a) := rfl @[simp] theorem some_orelse' (a : α) (x : option α) : (some a).orelse x = some a := rfl @[simp] theorem some_orelse (a : α) (x : option α) : (some a <|> x) = some a := rfl @[simp] theorem none_orelse' (x : option α) : none.orelse x = x := by cases x; refl @[simp] theorem none_orelse (x : option α) : (none <|> x) = x := none_orelse' x @[simp] theorem orelse_none' (x : option α) : x.orelse none = x := by cases x; refl @[simp] theorem orelse_none (x : option α) : (x <|> none) = x := orelse_none' x @[simp] theorem is_some_none : @is_some α none = ff := rfl @[simp] theorem is_some_some {a : α} : is_some (some a) = tt := rfl theorem is_some_iff_exists {x : option α} : is_some x ↔ ∃ a, x = some a := by cases x; simp [is_some]; exact ⟨_, rfl⟩ @[simp] theorem is_none_none : @is_none α none = tt := rfl @[simp] theorem is_none_some {a : α} : is_none (some a) = ff := rfl @[simp] theorem not_is_some {a : option α} : is_some a = ff ↔ a.is_none = tt := by cases a; simp lemma eq_some_iff_get_eq {o : option α} {a : α} : o = some a ↔ ∃ h : o.is_some, option.get h = a := by cases o; simp lemma not_is_some_iff_eq_none {o : option α} : ¬o.is_some ↔ o = none := by cases o; simp lemma ne_none_iff_is_some {o : option α} : o ≠ none ↔ o.is_some := by cases o; simp lemma ne_none_iff_exists {o : option α} : o ≠ none ↔ ∃ (x : α), some x = o := by {cases o; simp} lemma ne_none_iff_exists' {o : option α} : o ≠ none ↔ ∃ (x : α), o = some x := ne_none_iff_exists.trans $ exists_congr $ λ _, eq_comm lemma bex_ne_none {p : option α → Prop} : (∃ x ≠ none, p x) ↔ ∃ x, p (some x) := ⟨λ ⟨x, hx, hp⟩, ⟨get $ ne_none_iff_is_some.1 hx, by rwa [some_get]⟩, λ ⟨x, hx⟩, ⟨some x, some_ne_none x, hx⟩⟩ lemma ball_ne_none {p : option α → Prop} : (∀ x ≠ none, p x) ↔ ∀ x, p (some x) := ⟨λ h x, h (some x) (some_ne_none x), λ h x hx, by simpa only [some_get] using h (get $ ne_none_iff_is_some.1 hx)⟩ theorem iget_mem [inhabited α] : ∀ {o : option α}, is_some o → o.iget ∈ o | (some a) _ := rfl theorem iget_of_mem [inhabited α] {a : α} : ∀ {o : option α}, a ∈ o → o.iget = a | _ rfl := rfl @[simp] theorem guard_eq_some {p : α → Prop} [decidable_pred p] {a b : α} : guard p a = some b ↔ a = b ∧ p a := by by_cases p a; simp [option.guard, h]; intro; contradiction @[simp] theorem guard_eq_some' {p : Prop} [decidable p] (u) : _root_.guard p = some u ↔ p := begin cases u, by_cases p; simp [_root_.guard, h]; refl <|> contradiction, end theorem lift_or_get_choice {f : α → α → α} (h : ∀ a b, f a b = a ∨ f a b = b) : ∀ o₁ o₂, lift_or_get f o₁ o₂ = o₁ ∨ lift_or_get f o₁ o₂ = o₂ | none none := or.inl rfl | (some a) none := or.inl rfl | none (some b) := or.inr rfl | (some a) (some b) := by simpa [lift_or_get] using h a b @[simp] lemma lift_or_get_none_left {f} {b : option α} : lift_or_get f none b = b := by cases b; refl @[simp] lemma lift_or_get_none_right {f} {a : option α} : lift_or_get f a none = a := by cases a; refl @[simp] lemma lift_or_get_some_some {f} {a b : α} : lift_or_get f (some a) (some b) = f a b := rfl /-- Given an element of `a : option α`, a default element `b : β` and a function `α → β`, apply this function to `a` if it comes from `α`, and return `b` otherwise. -/ def cases_on' : option α → β → (α → β) → β | none n s := n | (some a) n s := s a @[simp] lemma cases_on'_none (x : β) (f : α → β) : cases_on' none x f = x := rfl @[simp] lemma cases_on'_some (x : β) (f : α → β) (a : α) : cases_on' (some a) x f = f a := rfl @[simp] lemma cases_on'_coe (x : β) (f : α → β) (a : α) : cases_on' (a : option α) x f = f a := rfl @[simp] lemma cases_on'_none_coe (f : option α → β) (o : option α) : cases_on' o (f none) (f ∘ coe) = f o := by cases o; refl @[simp] lemma get_or_else_map (f : α → β) (x : α) (o : option α) : get_or_else (o.map f) (f x) = f (get_or_else o x) := by cases o; refl lemma orelse_eq_some (o o' : option α) (x : α) : (o <|> o') = some x ↔ o = some x ∨ (o = none ∧ o' = some x) := begin cases o, { simp only [true_and, false_or, eq_self_iff_true, none_orelse] }, { simp only [some_orelse, or_false, false_and] } end lemma orelse_eq_some' (o o' : option α) (x : α) : o.orelse o' = some x ↔ o = some x ∨ (o = none ∧ o' = some x) := option.orelse_eq_some o o' x @[simp] lemma orelse_eq_none (o o' : option α) : (o <|> o') = none ↔ (o = none ∧ o' = none) := begin cases o, { simp only [true_and, none_orelse, eq_self_iff_true] }, { simp only [some_orelse, false_and], } end @[simp] lemma orelse_eq_none' (o o' : option α) : o.orelse o' = none ↔ (o = none ∧ o' = none) := option.orelse_eq_none o o' section open_locale classical /-- An arbitrary `some a` with `a : α` if `α` is nonempty, and otherwise `none`. -/ noncomputable def choice (α : Type*) : option α := if h : nonempty α then some h.some else none lemma choice_eq {α : Type*} [subsingleton α] (a : α) : choice α = some a := begin dsimp [choice], rw dif_pos (⟨a⟩ : nonempty α), congr, end lemma choice_eq_none (α : Type*) [is_empty α] : choice α = none := dif_neg (not_nonempty_iff_imp_false.mpr is_empty_elim) lemma choice_is_some_iff_nonempty {α : Type*} : (choice α).is_some ↔ nonempty α := begin fsplit, { intro h, exact ⟨option.get h⟩, }, { intro h, dsimp only [choice], rw dif_pos h, exact is_some_some }, end end @[simp] lemma to_list_some (a : α) : (a : option α).to_list = [a] := rfl @[simp] lemma to_list_none (α : Type*) : (none : option α).to_list = [] := rfl @[simp] lemma elim_none_some (f : option α → β) : option.elim (f none) (f ∘ some) = f := funext $ λ o, by cases o; refl end option
cc4dc497d6823a6a590965ddbb5ba7413151ed93
2a6c509a979150555f6f8a010f76e9398dd01e09
/src/dyck_words.lean
d8eaa02ba38567a60d2221b8c3efc1ef45783e1a
[]
no_license
VArtem/lean-catalan
fa053f8262b471f45ac7c3706f313ec38c831b72
7cf17acf3bdddddf8819dc3ff23774bfaa3f5d92
refs/heads/main
1,689,556,449,322
1,630,267,370,000
1,630,267,370,000
400,530,852
0
0
null
null
null
null
UTF-8
Lean
false
false
3,102
lean
import catalan def balance (l : list (fin 2)) : ℤ := (l.count 1 : ℤ) - (l.count 0) @[simp] lemma balance_def {l} : balance l = (l.count 1 : ℤ) - (l.count 0) := rfl @[simp] lemma balance_nil : balance [] = 0 := by rw [balance, list.count_nil, list.count_nil, sub_self] structure dyck_word := (chars : list (fin 2)) (total_balance : balance chars = 0) (suffix_balance : ∀ t, t <:+ chars → balance t ≥ 0) lemma list.length_eq_count0_add_count1 (l : list (fin 2)) : l.length = l.count 0 + l.count 1 := begin induction l with head tail ih, { simp only [list.count_nil, list.length], }, { fin_cases head, all_goals {simp [ih, nat.succ_eq_add_one], abel, }, } end namespace dyck_word lemma even_length (d : dyck_word) : even d.chars.length := begin use [d.chars.count 0], have h₁ := d.total_balance, rw [balance] at h₁, rw [list.length_eq_count0_add_count1], linarith, end lemma list.is_suffix_of_append {α} {l a b : list α} (h : l <:+ (a ++ b)) : (∃ k, k <:+ a ∧ k ++ b = l) ∨ (l <:+ b) := begin simp [←list.mem_tails] at h, simp_rw [list.mem_tails] at h, cases h, {left, exact h}, right, replace h := list.tail_subset _ h, rwa list.mem_tails at h, end def append (a b : dyck_word) : dyck_word := { chars := a.chars ++ b.chars, total_balance := by { have h₁ := a.total_balance, have h₂ := b.total_balance, simp [balance, list.count_append] at *, linarith, }, suffix_balance := by { rintro t ht, rcases list.is_suffix_of_append ht with ⟨ta, hta, rfl⟩ | ht₂, { have h₁ := a.suffix_balance _ hta, have h₂ := b.total_balance, simp only [int.coe_nat_add, list.count_append, balance_def] at *, linarith, }, { linarith [b.suffix_balance _ ht₂], } }, } lemma list.suffix_singleton {α} {a : α} {l} (h : l <:+ [a]) : l = [] ∨ l = [a] := begin cases l, {left, refl}, right, have h₁ := list.length_le_of_sublist (list.sublist_of_suffix h), simp [list.length_eq_zero] at h₁, subst h₁, apply list.eq_of_sublist_of_length_eq (list.sublist_of_suffix h), simp, end def wrap (a : dyck_word) : dyck_word := { chars := [0] ++ a.chars ++ [1], total_balance := by { simpa using a.total_balance, }, suffix_balance := by { rintro t ht, simp at ht, rw list.suffix_cons_iff at ht, rcases ht with rfl | _, { apply ge_of_eq, simpa using a.total_balance, }, { rcases list.is_suffix_of_append ht with ⟨ta, hta, rfl⟩ | ht₂, { have h₁ := a.suffix_balance _ hta, simp at *, linarith, }, { rcases list.suffix_singleton ht₂ with ⟨rfl, rfl⟩, { simp }, { simp [h] }, } } }, } -- TODO: unique construction through nil, append, wrap -> induction principle on dyck_word def sized_dyck_word (n : ℕ) := {d : dyck_word // d.chars.length = n} instance {n} : fintype (sized_dyck_word n) := sorry theorem catalan_eq_dyck_words_card {n : ℕ} : catalan n = fintype.card (sized_dyck_word (2 * n)) := sorry end dyck_word
f7e095e2da7736c586713336f0fc5edf1b265c73
64874bd1010548c7f5a6e3e8902efa63baaff785
/library/data/int/default.lean
2571b99c155524dc43bd31748464d43faaa1db4f
[ "Apache-2.0" ]
permissive
tjiaqi/lean
4634d729795c164664d10d093f3545287c76628f
d0ce4cf62f4246b0600c07e074d86e51f2195e30
refs/heads/master
1,622,323,796,480
1,422,643,069,000
1,422,643,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
184
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
00a8e0001a285bfaedc7cfc2357002fb0ee412bc
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/limits/preserves/shapes/products_auto.lean
6f30a41601915ebc80fe518db727e4bf9e8fbdcb
[]
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
5,171
lean
/- Copyright (c) 2020 Scott Morrison, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.limits.shapes.products import Mathlib.category_theory.limits.preserves.basic import Mathlib.PostPort universes u₁ u₂ v namespace Mathlib /-! # Preserving products Constructions to relate the notions of preserving products and reflecting products to concrete fans. In particular, we show that `pi_comparison G f` is an isomorphism iff `G` preserves the limit of `f`. -/ namespace category_theory.limits /-- The map of a fan is a limit iff the fan consisting of the mapped morphisms is a limit. This essentially lets us commute `fan.mk` with `functor.map_cone`. -/ def is_limit_map_cone_fan_mk_equiv {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) {P : C} (g : (j : J) → P ⟶ f j) : is_limit (functor.map_cone G (fan.mk P g)) ≃ is_limit (fan.mk (functor.obj G P) fun (j : J) => functor.map G (g j)) := equiv.trans (equiv.symm (is_limit.postcompose_hom_equiv (discrete.nat_iso fun (j : discrete J) => iso.refl (functor.obj G (f j))) (functor.map_cone G (fan.mk P g)))) (is_limit.equiv_iso_limit (cones.ext (iso.refl (cone.X (functor.obj (cones.postcompose (iso.hom (discrete.nat_iso fun (j : discrete J) => iso.refl (functor.obj G (f j))))) (functor.map_cone G (fan.mk P g))))) sorry)) /-- The property of preserving products expressed in terms of fans. -/ def is_limit_fan_mk_obj_of_is_limit {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [preserves_limit (discrete.functor f) G] {P : C} (g : (j : J) → P ⟶ f j) (t : is_limit (fan.mk P g)) : is_limit (fan.mk (functor.obj G P) fun (j : J) => functor.map G (g j)) := coe_fn (is_limit_map_cone_fan_mk_equiv G (fun (j : J) => f j) g) (preserves_limit.preserves t) /-- The property of reflecting products expressed in terms of fans. -/ def is_limit_of_is_limit_fan_mk_obj {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [reflects_limit (discrete.functor f) G] {P : C} (g : (j : J) → P ⟶ f j) (t : is_limit (fan.mk (functor.obj G P) fun (j : J) => functor.map G (g j))) : is_limit (fan.mk P g) := reflects_limit.reflects (coe_fn (equiv.symm (is_limit_map_cone_fan_mk_equiv G (fun (j : J) => f j) fun (j : J) => g j)) t) /-- If `G` preserves products and `C` has them, then the fan constructed of the mapped projection of a product is a limit. -/ def is_limit_of_has_product_of_preserves_limit {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [has_product f] [preserves_limit (discrete.functor f) G] : is_limit (fan.mk (functor.obj G (∏ f)) fun (j : J) => functor.map G (pi.π f j)) := is_limit_fan_mk_obj_of_is_limit G f (fun (j : J) => pi.π f j) (product_is_product fun (j : J) => f j) /-- If `pi_comparison G f` is an isomorphism, then `G` preserves the limit of `f`. -/ def preserves_product.of_iso_comparison {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [has_product f] [has_product fun (j : J) => functor.obj G (f j)] [i : is_iso (pi_comparison G f)] : preserves_limit (discrete.functor f) G := preserves_limit_of_preserves_limit_cone (product_is_product f) (coe_fn (equiv.symm (is_limit_map_cone_fan_mk_equiv G (fun (b : J) => f b) (pi.π f))) (is_limit.of_point_iso (limit.is_limit (discrete.functor fun (j : J) => functor.obj G (f j))))) /-- If `G` preserves limits, we have an isomorphism from the image of a product to the product of the images. -/ def preserves_product.iso {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [has_product f] [has_product fun (j : J) => functor.obj G (f j)] [preserves_limit (discrete.functor f) G] : functor.obj G (∏ f) ≅ ∏ fun (j : J) => functor.obj G (f j) := is_limit.cone_point_unique_up_to_iso (is_limit_of_has_product_of_preserves_limit G f) (limit.is_limit (discrete.functor fun (j : J) => functor.obj G (f j))) @[simp] theorem preserves_product.iso_hom {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [has_product f] [has_product fun (j : J) => functor.obj G (f j)] [preserves_limit (discrete.functor f) G] : iso.hom (preserves_product.iso G f) = pi_comparison G f := rfl protected instance pi_comparison.category_theory.is_iso {C : Type u₁} [category C] {D : Type u₂} [category D] (G : C ⥤ D) {J : Type v} (f : J → C) [has_product f] [has_product fun (j : J) => functor.obj G (f j)] [preserves_limit (discrete.functor f) G] : is_iso (pi_comparison G f) := eq.mpr sorry (is_iso.of_iso (preserves_product.iso G f)) end Mathlib
ef8121b19423d8eed28f99350bfb0e6ddb243cab
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/utf8.lean
0763dd872d0ee68baf2888b4029acea1b2d13437
[ "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
135
lean
--open list #eval "α₁".length #eval "α₁ → β₁".length #eval "∀ α : nat → nat, α 0 ≥ 0".length #print "------------"
df2f4454974c9eb22aa3ee2e9751e92ae53fb861
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/analytic/isolated_zeros.lean
7759f8579ca8b1f6156ff9cc2be122d498763960
[ "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
9,757
lean
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import analysis.analytic.basic import analysis.calculus.dslope import analysis.calculus.fderiv_analytic import analysis.calculus.formal_multilinear_series import analysis.analytic.uniqueness /-! # Principle of isolated zeros > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file proves the fact that the zeros of a non-constant analytic function of one variable are isolated. It also introduces a little bit of API in the `has_fpower_series_at` namespace that is useful in this setup. ## Main results * `analytic_at.eventually_eq_zero_or_eventually_ne_zero` is the main statement that if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. * `analytic_on.eq_on_of_preconnected_of_frequently_eq` is the identity theorem for analytic functions: if a function `f` is analytic on a connected set `U` and is zero on a set with an accumulation point in `U` then `f` is identically `0` on `U`. -/ open_locale classical open filter function nat formal_multilinear_series emetric set open_locale topology big_operators variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] {s : E} {p q : formal_multilinear_series 𝕜 𝕜 E} {f g : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜} {y : fin n → 𝕜} namespace has_sum variables {a : ℕ → E} lemma has_sum_at_zero (a : ℕ → E) : has_sum (λ n, (0:𝕜) ^ n • a n) (a 0) := by convert has_sum_single 0 (λ b h, _); simp [nat.pos_of_ne_zero h] <|> simp lemma exists_has_sum_smul_of_apply_eq_zero (hs : has_sum (λ m, z ^ m • a m) s) (ha : ∀ k < n, a k = 0) : ∃ t : E, z ^ n • t = s ∧ has_sum (λ m, z ^ m • a (m + n)) t := begin obtain rfl | hn := n.eq_zero_or_pos, { simpa }, by_cases h : z = 0, { have : s = 0 := hs.unique (by simpa [ha 0 hn, h] using has_sum_at_zero a), exact ⟨a n, by simp [h, hn, this], by simpa [h] using has_sum_at_zero (λ m, a (m + n))⟩ }, { refine ⟨(z ^ n)⁻¹ • s, by field_simp [smul_smul], _⟩, have h1 : ∑ i in finset.range n, z ^ i • a i = 0, from finset.sum_eq_zero (λ k hk, by simp [ha k (finset.mem_range.mp hk)]), have h2 : has_sum (λ m, z ^ (m + n) • a (m + n)) s, by simpa [h1] using (has_sum_nat_add_iff' n).mpr hs, convert h2.const_smul (z⁻¹ ^ n), { field_simp [pow_add, smul_smul] }, { simp only [inv_pow] } } end end has_sum namespace has_fpower_series_at lemma has_fpower_series_dslope_fslope (hp : has_fpower_series_at f p z₀) : has_fpower_series_at (dslope f z₀) p.fslope z₀ := begin have hpd : deriv f z₀ = p.coeff 1 := hp.deriv, have hp0 : p.coeff 0 = f z₀ := hp.coeff_zero 1, simp only [has_fpower_series_at_iff, apply_eq_pow_smul_coeff, coeff_fslope] at hp ⊢, refine hp.mono (λ x hx, _), by_cases h : x = 0, { convert has_sum_single 0 _; intros; simp [*] }, { have hxx : ∀ (n : ℕ), x⁻¹ * x ^ (n + 1) = x ^ n := λ n, by field_simp [h, pow_succ'], suffices : has_sum (λ n, x⁻¹ • x ^ (n + 1) • p.coeff (n + 1)) (x⁻¹ • (f (z₀ + x) - f z₀)), { simpa [dslope, slope, h, smul_smul, hxx] using this }, { simpa [hp0] using ((has_sum_nat_add_iff' 1).mpr hx).const_smul x⁻¹ } } end lemma has_fpower_series_iterate_dslope_fslope (n : ℕ) (hp : has_fpower_series_at f p z₀) : has_fpower_series_at ((swap dslope z₀)^[n] f) (fslope^[n] p) z₀ := begin induction n with n ih generalizing f p, { exact hp }, { simpa using ih (has_fpower_series_dslope_fslope hp) } end lemma iterate_dslope_fslope_ne_zero (hp : has_fpower_series_at f p z₀) (h : p ≠ 0) : (swap dslope z₀)^[p.order] f z₀ ≠ 0 := begin rw [← coeff_zero (has_fpower_series_iterate_dslope_fslope p.order hp) 1], simpa [coeff_eq_zero] using apply_order_ne_zero h end lemma eq_pow_order_mul_iterate_dslope (hp : has_fpower_series_at f p z₀) : ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ p.order • ((swap dslope z₀)^[p.order] f z) := begin have hq := has_fpower_series_at_iff'.mp (has_fpower_series_iterate_dslope_fslope p.order hp), filter_upwards [hq, has_fpower_series_at_iff'.mp hp] with x hx1 hx2, have : ∀ k < p.order, p.coeff k = 0, from λ k hk, by simpa [coeff_eq_zero] using apply_eq_zero_of_lt_order hk, obtain ⟨s, hs1, hs2⟩ := has_sum.exists_has_sum_smul_of_apply_eq_zero hx2 this, convert hs1.symm, simp only [coeff_iterate_fslope] at hx1, exact hx1.unique hs2 end lemma locally_ne_zero (hp : has_fpower_series_at f p z₀) (h : p ≠ 0) : ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := begin rw [eventually_nhds_within_iff], have h2 := (has_fpower_series_iterate_dslope_fslope p.order hp).continuous_at, have h3 := h2.eventually_ne (iterate_dslope_fslope_ne_zero hp h), filter_upwards [eq_pow_order_mul_iterate_dslope hp, h3] with z e1 e2 e3, simpa [e1, e2, e3] using pow_ne_zero p.order (sub_ne_zero.mpr e3), end lemma locally_zero_iff (hp : has_fpower_series_at f p z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) ↔ p = 0 := ⟨λ hf, hp.eq_zero_of_eventually hf, λ h, eventually_eq_zero (by rwa h at hp)⟩ end has_fpower_series_at namespace analytic_at /-- The *principle of isolated zeros* for an analytic function, local version: if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. -/ theorem eventually_eq_zero_or_eventually_ne_zero (hf : analytic_at 𝕜 f z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) ∨ (∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0) := begin rcases hf with ⟨p, hp⟩, by_cases h : p = 0, { exact or.inl (has_fpower_series_at.eventually_eq_zero (by rwa h at hp)) }, { exact or.inr (hp.locally_ne_zero h) } end lemma eventually_eq_or_eventually_ne (hf : analytic_at 𝕜 f z₀) (hg : analytic_at 𝕜 g z₀) : (∀ᶠ z in 𝓝 z₀, f z = g z) ∨ (∀ᶠ z in 𝓝[≠] z₀, f z ≠ g z) := by simpa [sub_eq_zero] using (hf.sub hg).eventually_eq_zero_or_eventually_ne_zero lemma frequently_zero_iff_eventually_zero {f : 𝕜 → E} {w : 𝕜} (hf : analytic_at 𝕜 f w) : (∃ᶠ z in 𝓝[≠] w, f z = 0) ↔ (∀ᶠ z in 𝓝 w, f z = 0) := ⟨hf.eventually_eq_zero_or_eventually_ne_zero.resolve_right, λ h, (h.filter_mono nhds_within_le_nhds).frequently⟩ lemma frequently_eq_iff_eventually_eq (hf : analytic_at 𝕜 f z₀) (hg : analytic_at 𝕜 g z₀) : (∃ᶠ z in 𝓝[≠] z₀, f z = g z) ↔ (∀ᶠ z in 𝓝 z₀, f z = g z) := by simpa [sub_eq_zero] using frequently_zero_iff_eventually_zero (hf.sub hg) end analytic_at namespace analytic_on variables {U : set 𝕜} /-- The *principle of isolated zeros* for an analytic function, global version: if a function is analytic on a connected set `U` and vanishes in arbitrary neighborhoods of a point `z₀ ∈ U`, then it is identically zero in `U`. For higher-dimensional versions requiring that the function vanishes in a neighborhood of `z₀`, see `eq_on_zero_of_preconnected_of_eventually_eq_zero`. -/ theorem eq_on_zero_of_preconnected_of_frequently_eq_zero (hf : analytic_on 𝕜 f U) (hU : is_preconnected U) (h₀ : z₀ ∈ U) (hfw : ∃ᶠ z in 𝓝[≠] z₀, f z = 0) : eq_on f 0 U := hf.eq_on_zero_of_preconnected_of_eventually_eq_zero hU h₀ ((hf z₀ h₀).frequently_zero_iff_eventually_zero.1 hfw) theorem eq_on_zero_of_preconnected_of_mem_closure (hf : analytic_on 𝕜 f U) (hU : is_preconnected U) (h₀ : z₀ ∈ U) (hfz₀ : z₀ ∈ closure ({z | f z = 0} \ {z₀})) : eq_on f 0 U := hf.eq_on_zero_of_preconnected_of_frequently_eq_zero hU h₀ (mem_closure_ne_iff_frequently_within.mp hfz₀) /-- The *identity principle* for analytic functions, global version: if two functions are analytic on a connected set `U` and coincide at points which accumulate to a point `z₀ ∈ U`, then they coincide globally in `U`. For higher-dimensional versions requiring that the functions coincide in a neighborhood of `z₀`, see `eq_on_of_preconnected_of_eventually_eq`. -/ theorem eq_on_of_preconnected_of_frequently_eq (hf : analytic_on 𝕜 f U) (hg : analytic_on 𝕜 g U) (hU : is_preconnected U) (h₀ : z₀ ∈ U) (hfg : ∃ᶠ z in 𝓝[≠] z₀, f z = g z) : eq_on f g U := begin have hfg' : ∃ᶠ z in 𝓝[≠] z₀, (f - g) z = 0 := hfg.mono (λ z h, by rw [pi.sub_apply, h, sub_self]), simpa [sub_eq_zero] using λ z hz, (hf.sub hg).eq_on_zero_of_preconnected_of_frequently_eq_zero hU h₀ hfg' hz end theorem eq_on_of_preconnected_of_mem_closure (hf : analytic_on 𝕜 f U) (hg : analytic_on 𝕜 g U) (hU : is_preconnected U) (h₀ : z₀ ∈ U) (hfg : z₀ ∈ closure ({z | f z = g z} \ {z₀})) : eq_on f g U := hf.eq_on_of_preconnected_of_frequently_eq hg hU h₀ (mem_closure_ne_iff_frequently_within.mp hfg) /-- The *identity principle* for analytic functions, global version: if two functions on a normed field `𝕜` are analytic everywhere and coincide at points which accumulate to a point `z₀`, then they coincide globally. For higher-dimensional versions requiring that the functions coincide in a neighborhood of `z₀`, see `eq_of_eventually_eq`. -/ theorem eq_of_frequently_eq [connected_space 𝕜] (hf : analytic_on 𝕜 f univ) (hg : analytic_on 𝕜 g univ) (hfg : ∃ᶠ z in 𝓝[≠] z₀, f z = g z) : f = g := funext (λ x, eq_on_of_preconnected_of_frequently_eq hf hg is_preconnected_univ (mem_univ z₀) hfg (mem_univ x)) end analytic_on
acbd0a0895141817877c6c68732c118960671374
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/category_theory/groupoid.lean
04da1c8b3cf57d364163c3207967fc4abaa0266d
[ "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
2,704
lean
/- Copyright (c) 2018 Reid Barton All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Scott Morrison, David Wärn -/ import category_theory.epi_mono namespace category_theory universes v v₂ u u₂ -- morphism levels before object levels. See note [category_theory universes]. /-- A `groupoid` is a category such that all morphisms are isomorphisms. -/ class groupoid (obj : Type u) extends category.{v} obj : Type (max u (v+1)) := (inv : Π {X Y : obj}, (X ⟶ Y) → (Y ⟶ X)) (inv_comp' : ∀ {X Y : obj} (f : X ⟶ Y), comp (inv f) f = id Y . obviously) (comp_inv' : ∀ {X Y : obj} (f : X ⟶ Y), comp f (inv f) = id X . obviously) restate_axiom groupoid.inv_comp' restate_axiom groupoid.comp_inv' attribute [simp] groupoid.inv_comp groupoid.comp_inv /-- A `large_groupoid` is a groupoid where the objects live in `Type (u+1)` while the morphisms live in `Type u`. -/ abbreviation large_groupoid (C : Type (u+1)) : Type (u+1) := groupoid.{u} C /-- A `small_groupoid` is a groupoid where the objects and morphisms live in the same universe. -/ abbreviation small_groupoid (C : Type u) : Type (u+1) := groupoid.{u} C section variables {C : Type u} [groupoid.{v} C] {X Y : C} @[priority 100] -- see Note [lower instance priority] instance is_iso.of_groupoid (f : X ⟶ Y) : is_iso f := ⟨⟨groupoid.inv f, by simp⟩⟩ variables (X Y) /-- In a groupoid, isomorphisms are equivalent to morphisms. -/ def groupoid.iso_equiv_hom : (X ≅ Y) ≃ (X ⟶ Y) := { to_fun := iso.hom, inv_fun := λ f, ⟨f, groupoid.inv f⟩, left_inv := λ i, iso.ext rfl, right_inv := λ f, rfl } end section variables {C : Type u} [category.{v} C] /-- A category where every morphism `is_iso` is a groupoid. -/ noncomputable def groupoid.of_is_iso (all_is_iso : ∀ {X Y : C} (f : X ⟶ Y), is_iso f) : groupoid.{v} C := { inv := λ X Y f, inv f } /-- A category where every morphism has a `trunc` retraction is computably a groupoid. -/ -- FIXME this has unnecessarily become noncomputable! noncomputable def groupoid.of_trunc_split_mono (all_split_mono : ∀ {X Y : C} (f : X ⟶ Y), trunc (split_mono f)) : groupoid.{v} C := begin apply groupoid.of_is_iso, intros X Y f, trunc_cases all_split_mono f, trunc_cases all_split_mono (retraction f), apply is_iso.of_mono_retraction, end end instance induced_category.groupoid {C : Type u} (D : Type u₂) [groupoid.{v} D] (F : C → D) : groupoid.{v} (induced_category D F) := { inv := λ X Y f, groupoid.inv f, inv_comp' := λ X Y f, groupoid.inv_comp f, comp_inv' := λ X Y f, groupoid.comp_inv f, .. induced_category.category F } end category_theory
161e5a3f310b7c442f63eaadaedb709b44d2dfe0
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/topology/algebra/mul_action.lean
c6531aab41b7864ecac7158b238910e45b94558d
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,689
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import topology.algebra.monoid import algebra.module.prod import topology.homeomorph /-! # Continuous monoid action In this file we define class `has_continuous_smul`. We say `has_continuous_smul M α` if `M` acts on `α` and the map `(c, x) ↦ c • x` is continuous on `M × α`. We reuse this class for topological (semi)modules, vector spaces and algebras. ## Main definitions * `has_continuous_smul M α` : typeclass saying that the map `(c, x) ↦ c • x` is continuous on `M × α`; * `homeomorph.smul_of_ne_zero`: if a group with zero `G₀` (e.g., a field) acts on `α` and `c : G₀` is a nonzero element of `G₀`, then scalar multiplication by `c` is a homeomorphism of `α`; * `homeomorph.smul`: scalar multiplication by an element of a group `G` acting on `α` is a homeomorphism of `α`. * `units.has_continuous_smul`: scalar multiplication by `units M` is continuous when scalar multiplication by `M` is continuous. This allows `homeomorph.smul` to be used with on monoids with `G = units M`. ## Main results Besides homeomorphisms mentioned above, in this file we provide lemmas like `continuous.smul` or `filter.tendsto.smul` that provide dot-syntax access to `continuous_smul`. -/ open_locale topological_space open filter /-- Class `has_continuous_smul M α` says that the scalar multiplication `(•) : M → α → α` is continuous in both arguments. We use the same class for all kinds of multiplicative actions, including (semi)modules and algebras. -/ class has_continuous_smul (M α : Type*) [has_scalar M α] [topological_space M] [topological_space α] : Prop := (continuous_smul : continuous (λp : M × α, p.1 • p.2)) export has_continuous_smul (continuous_smul) variables {M α β : Type*} [topological_space M] [topological_space α] section has_scalar variables [has_scalar M α] [has_continuous_smul M α] lemma filter.tendsto.smul {f : β → M} {g : β → α} {l : filter β} {c : M} {a : α} (hf : tendsto f l (𝓝 c)) (hg : tendsto g l (𝓝 a)) : tendsto (λ x, f x • g x) l (𝓝 $ c • a) := (continuous_smul.tendsto _).comp (hf.prod_mk_nhds hg) lemma filter.tendsto.const_smul {f : β → α} {l : filter β} {a : α} (hf : tendsto f l (𝓝 a)) (c : M) : tendsto (λ x, c • f x) l (𝓝 (c • a)) := tendsto_const_nhds.smul hf lemma filter.tendsto.smul_const {f : β → M} {l : filter β} {c : M} (hf : tendsto f l (𝓝 c)) (a : α) : tendsto (λ x, (f x) • a) l (𝓝 (c • a)) := hf.smul tendsto_const_nhds variables [topological_space β] {f : β → M} {g : β → α} {b : β} {s : set β} lemma continuous_within_at.smul (hf : continuous_within_at f s b) (hg : continuous_within_at g s b) : continuous_within_at (λ x, f x • g x) s b := hf.smul hg lemma continuous_within_at.const_smul (hg : continuous_within_at g s b) (c : M) : continuous_within_at (λ x, c • g x) s b := hg.const_smul c lemma continuous_at.smul (hf : continuous_at f b) (hg : continuous_at g b) : continuous_at (λ x, f x • g x) b := hf.smul hg lemma continuous_at.const_smul (hg : continuous_at g b) (c : M) : continuous_at (λ x, c • g x) b := hg.const_smul c lemma continuous_on.smul (hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λ x, f x • g x) s := λ x hx, (hf x hx).smul (hg x hx) lemma continuous_on.const_smul (hg : continuous_on g s) (c : M) : continuous_on (λ x, c • g x) s := λ x hx, (hg x hx).const_smul c @[continuity] lemma continuous.smul (hf : continuous f) (hg : continuous g) : continuous (λ x, f x • g x) := continuous_smul.comp (hf.prod_mk hg) lemma continuous.const_smul (hg : continuous g) (c : M) : continuous (λ x, c • g x) := continuous_smul.comp (continuous_const.prod_mk hg) end has_scalar section monoid variables [monoid M] [mul_action M α] [has_continuous_smul M α] instance units.has_continuous_smul : has_continuous_smul (units M) α := { continuous_smul := show continuous ((λ p : M × α, p.fst • p.snd) ∘ (λ p : units M × α, (p.1, p.2))), from continuous_smul.comp ((units.continuous_coe.comp continuous_fst).prod_mk continuous_snd) } end monoid section group variables {G : Type*} [topological_space G] [group G] [mul_action G α] [has_continuous_smul G α] lemma tendsto_const_smul_iff {f : β → α} {l : filter β} {a : α} (c : G) : tendsto (λ x, c • f x) l (𝓝 $ c • a) ↔ tendsto f l (𝓝 a) := ⟨λ h, by simpa only [inv_smul_smul] using h.const_smul c⁻¹, λ h, h.const_smul _⟩ variables [topological_space β] {f : β → α} {b : β} {s : set β} lemma continuous_within_at_const_smul_iff (c : G) : continuous_within_at (λ x, c • f x) s b ↔ continuous_within_at f s b := tendsto_const_smul_iff c lemma continuous_on_const_smul_iff (c : G) : continuous_on (λ x, c • f x) s ↔ continuous_on f s := forall_congr $ λ b, forall_congr $ λ hb, continuous_within_at_const_smul_iff c lemma continuous_at_const_smul_iff (c : G) : continuous_at (λ x, c • f x) b ↔ continuous_at f b := tendsto_const_smul_iff c lemma continuous_const_smul_iff (c : G) : continuous (λ x, c • f x) ↔ continuous f := by simp only [continuous_iff_continuous_at, continuous_at_const_smul_iff] /-- Scalar multiplication by a unit of a monoid `M` acting on `α` is a homeomorphism from `α` to itself. -/ protected def homeomorph.smul (c : G) : α ≃ₜ α := { to_equiv := mul_action.to_perm_hom G α c, continuous_to_fun := continuous_id.const_smul _, continuous_inv_fun := continuous_id.const_smul _ } lemma is_open_map_smul (c : G) : is_open_map (λ x : α, c • x) := (homeomorph.smul c).is_open_map lemma is_closed_map_smul (c : G) : is_closed_map (λ x : α, c • x) := (homeomorph.smul c).is_closed_map end group section group_with_zero variables {G₀ : Type*} [topological_space G₀] [group_with_zero G₀] [mul_action G₀ α] [has_continuous_smul G₀ α] lemma tendsto_const_smul_iff₀ {f : β → α} {l : filter β} {a : α} {c : G₀} (hc : c ≠ 0) : tendsto (λ x, c • f x) l (𝓝 $ c • a) ↔ tendsto f l (𝓝 a) := tendsto_const_smul_iff (units.mk0 c hc) variables [topological_space β] {f : β → α} {b : β} {c : G₀} {s : set β} lemma continuous_within_at_const_smul_iff₀ (hc : c ≠ 0) : continuous_within_at (λ x, c • f x) s b ↔ continuous_within_at f s b := tendsto_const_smul_iff (units.mk0 c hc) lemma continuous_on_const_smul_iff₀ (hc : c ≠ 0) : continuous_on (λ x, c • f x) s ↔ continuous_on f s := continuous_on_const_smul_iff (units.mk0 c hc) lemma continuous_at_const_smul_iff₀ (hc : c ≠ 0) : continuous_at (λ x, c • f x) b ↔ continuous_at f b := continuous_at_const_smul_iff (units.mk0 c hc) lemma continuous_const_smul_iff₀ (hc : c ≠ 0) : continuous (λ x, c • f x) ↔ continuous f := continuous_const_smul_iff (units.mk0 c hc) /-- Scalar multiplication by a non-zero element of a group with zero acting on `α` is a homeomorphism from `α` onto itself. -/ protected def homeomorph.smul_of_ne_zero (c : G₀) (hc : c ≠ 0) : α ≃ₜ α := homeomorph.smul (units.mk0 c hc) lemma is_open_map_smul₀ {c : G₀} (hc : c ≠ 0) : is_open_map (λ x : α, c • x) := (homeomorph.smul_of_ne_zero c hc).is_open_map /-- `smul` is a closed map in the second argument. The lemma that `smul` is a closed map in the first argument (for a normed space over a complete normed field) is `is_closed_map_smul_left` in `analysis.normed_space.finite_dimension`. -/ lemma is_closed_map_smul_of_ne_zero {c : G₀} (hc : c ≠ 0) : is_closed_map (λ x : α, c • x) := (homeomorph.smul_of_ne_zero c hc).is_closed_map /-- `smul` is a closed map in the second argument. The lemma that `smul` is a closed map in the first argument (for a normed space over a complete normed field) is `is_closed_map_smul_left` in `analysis.normed_space.finite_dimension`. -/ lemma is_closed_map_smul₀ {𝕜 M : Type*} [division_ring 𝕜] [add_comm_monoid M] [topological_space M] [t1_space M] [module 𝕜 M] [topological_space 𝕜] [has_continuous_smul 𝕜 M] (c : 𝕜) : is_closed_map (λ x : M, c • x) := begin rcases eq_or_ne c 0 with (rfl|hne), { simp only [zero_smul], exact is_closed_map_const }, { exact (homeomorph.smul_of_ne_zero c hne).is_closed_map }, end end group_with_zero namespace is_unit variables [monoid M] [mul_action M α] [has_continuous_smul M α] lemma tendsto_const_smul_iff {f : β → α} {l : filter β} {a : α} {c : M} (hc : is_unit c) : tendsto (λ x, c • f x) l (𝓝 $ c • a) ↔ tendsto f l (𝓝 a) := let ⟨u, hu⟩ := hc in hu ▸ tendsto_const_smul_iff u variables [topological_space β] {f : β → α} {b : β} {c : M} {s : set β} lemma continuous_within_at_const_smul_iff (hc : is_unit c) : continuous_within_at (λ x, c • f x) s b ↔ continuous_within_at f s b := let ⟨u, hu⟩ := hc in hu ▸ continuous_within_at_const_smul_iff u lemma continuous_on_const_smul_iff (hc : is_unit c) : continuous_on (λ x, c • f x) s ↔ continuous_on f s := let ⟨u, hu⟩ := hc in hu ▸ continuous_on_const_smul_iff u lemma continuous_at_const_smul_iff (hc : is_unit c) : continuous_at (λ x, c • f x) b ↔ continuous_at f b := let ⟨u, hu⟩ := hc in hu ▸ continuous_at_const_smul_iff u lemma continuous_const_smul_iff (hc : is_unit c) : continuous (λ x, c • f x) ↔ continuous f := let ⟨u, hu⟩ := hc in hu ▸ continuous_const_smul_iff u lemma is_open_map_smul (hc : is_unit c) : is_open_map (λ x : α, c • x) := let ⟨u, hu⟩ := hc in hu ▸ is_open_map_smul u lemma is_closed_map_smul (hc : is_unit c) : is_closed_map (λ x : α, c • x) := let ⟨u, hu⟩ := hc in hu ▸ is_closed_map_smul u end is_unit instance has_continuous_mul.has_continuous_smul {M : Type*} [monoid M] [topological_space M] [has_continuous_mul M] : has_continuous_smul M M := ⟨continuous_mul⟩ instance [topological_space β] [has_scalar M α] [has_scalar M β] [has_continuous_smul M α] [has_continuous_smul M β] : has_continuous_smul M (α × β) := ⟨(continuous_fst.smul (continuous_fst.comp continuous_snd)).prod_mk (continuous_fst.smul (continuous_snd.comp continuous_snd))⟩ instance {ι : Type*} {γ : ι → Type} [∀ i, topological_space (γ i)] [Π i, has_scalar M (γ i)] [∀ i, has_continuous_smul M (γ i)] : has_continuous_smul M (Π i, γ i) := ⟨continuous_pi $ λ i, (continuous_fst.smul continuous_snd).comp $ continuous_fst.prod_mk ((continuous_apply i).comp continuous_snd)⟩
e1398d99c6363e2102bad847f9d3b11468db594d
969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb
/src/algebra/module/basic.lean
62f46a058a1e7eb0acabbda7b83f623385999221
[ "Apache-2.0" ]
permissive
SAAluthwela/mathlib
62044349d72dd63983a8500214736aa7779634d3
83a4b8b990907291421de54a78988c024dc8a552
refs/heads/master
1,679,433,873,417
1,615,998,031,000
1,615,998,031,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
22,032
lean
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import algebra.big_operators.basic import algebra.group.hom import group_theory.group_action.group import algebra.smul_with_zero /-! # Modules over a ring In this file we define * `semimodule R M` : an additive commutative monoid `M` is a `semimodule` over a `semiring R` if for `r : R` and `x : M` their "scalar multiplication `r • x : M` is defined, and the operation `•` satisfies some natural associativity and distributivity axioms similar to those on a ring. * `module R M` : same as `semimodule R M` but assumes that `R` is a `ring` and `M` is an additive commutative group. * `vector_space k M` : same as `semimodule k M` and `module k M` but assumes that `k` is a `field` and `M` is an additive commutative group. * `linear_map R M M₂`, `M →ₗ[R] M₂` : a linear map between two R-`semimodule`s. ## Implementation notes * `vector_space` and `module` are abbreviations for `semimodule R M`. ## Tags semimodule, module, vector space -/ open function open_locale big_operators universes u u' v w x y z variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {M₃ : Type y} {ι : Type z} /-- A semimodule is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ @[protect_proj] class semimodule (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] extends distrib_mul_action R M := (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (zero_smul : ∀x : M, (0 : R) • x = 0) section add_comm_monoid variables [semiring R] [add_comm_monoid M] [semimodule R M] (r s : R) (x y : M) /-- A semimodule over a semiring automatically inherits a `mul_action_with_zero` structure. -/ @[priority 100] -- see Note [lower instance priority] instance semimodule.to_mul_action_with_zero : mul_action_with_zero R M := { smul_zero := smul_zero, zero_smul := semimodule.zero_smul, ..(infer_instance : mul_action R M) } theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x variables (R) theorem two_smul : (2 : R) • x = x + x := by rw [bit0, add_smul, one_smul] theorem two_smul' : (2 : R) • x = bit0 x := two_smul R x /-- Pullback a `semimodule` structure along an injective additive monoid homomorphism. -/ protected def function.injective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M₂ →+ M) (hf : injective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) : semimodule R M₂ := { smul := (•), add_smul := λ c₁ c₂ x, hf $ by simp only [smul, f.map_add, add_smul], zero_smul := λ x, hf $ by simp only [smul, zero_smul, f.map_zero], .. hf.distrib_mul_action f smul } /-- Pushforward a `semimodule` structure along a surjective additive monoid homomorphism. -/ protected def function.surjective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M →+ M₂) (hf : surjective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) : semimodule R M₂ := { smul := (•), add_smul := λ c₁ c₂ x, by { rcases hf x with ⟨x, rfl⟩, simp only [add_smul, ← smul, ← f.map_add] }, zero_smul := λ x, by { rcases hf x with ⟨x, rfl⟩, simp only [← f.map_zero, ← smul, zero_smul] }, .. hf.distrib_mul_action f smul } variable (M) /-- `(•)` as an `add_monoid_hom`. -/ def smul_add_hom : R →+ M →+ M := { to_fun := const_smul_hom M, map_zero' := add_monoid_hom.ext $ λ r, by simp, map_add' := λ x y, add_monoid_hom.ext $ λ r, by simp [add_smul] } variables {R M} @[simp] lemma smul_add_hom_apply (r : R) (x : M) : smul_add_hom R M r x = r • x := rfl lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by rw [←one_smul R x, ←zero_eq_one, zero_smul] lemma list.sum_smul {l : list R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := ((smul_add_hom R M).flip x).map_list_sum l lemma multiset.sum_smul {l : multiset R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := ((smul_add_hom R M).flip x).map_multiset_sum l lemma finset.sum_smul {f : ι → R} {s : finset ι} {x : M} : (∑ i in s, f i) • x = (∑ i in s, (f i) • x) := ((smul_add_hom R M).flip x).map_sum f s end add_comm_monoid variables (R) /-- An `add_comm_monoid` that is a `semimodule` over a `ring` carries a natural `add_comm_group` structure. -/ def semimodule.add_comm_monoid_to_add_comm_group [ring R] [add_comm_monoid M] [semimodule R M] : add_comm_group M := { neg := λ a, (-1 : R) • a, add_left_neg := λ a, show (-1 : R) • a + a = 0, by { nth_rewrite 1 ← one_smul _ a, rw [← add_smul, add_left_neg, zero_smul] }, ..(infer_instance : add_comm_monoid M), } variables {R} section add_comm_group variables (R M) [semiring R] [add_comm_group M] /-- A structure containing most informations as in a semimodule, except the fields `zero_smul` and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`, this provides a way to construct a semimodule structure by checking less properties, in `semimodule.of_core`. -/ @[nolint has_inhabited_instance] structure semimodule.core extends has_scalar R M := (smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y) (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (mul_smul : ∀(r s : R) (x : M), (r * s) • x = r • s • x) (one_smul : ∀x : M, (1 : R) • x = x) variables {R M} /-- Define `semimodule` without proving `zero_smul` and `smul_zero` by using an auxiliary structure `semimodule.core`, when the underlying space is an `add_comm_group`. -/ def semimodule.of_core (H : semimodule.core R M) : semimodule R M := by letI := H.to_has_scalar; exact { zero_smul := λ x, (add_monoid_hom.mk' (λ r : R, r • x) (λ r s, H.add_smul r s x)).map_zero, smul_zero := λ r, (add_monoid_hom.mk' ((•) r) (H.smul_add r)).map_zero, ..H } end add_comm_group /-- Modules are defined as an `abbreviation` for semimodules, if the base semiring is a ring. (A previous definition made `module` a structure defined to be `semimodule`.) This has as advantage that modules are completely transparent for type class inference, which means that all instances for semimodules are immediately picked up for modules as well. A cosmetic disadvantage is that one can not extend modules as such, in definitions such as `normed_space`. The solution is to extend `semimodule` instead. -/ library_note "module definition" /-- A module is the same as a semimodule, except the scalar semiring is actually a ring. This is the traditional generalization of spaces like `ℤ^n`, which have a natural addition operation and a way to multiply them by elements of a ring, but no multiplication operation between vectors. -/ abbreviation module (R : Type u) (M : Type v) [ring R] [add_comm_group M] := semimodule R M /-- To prove two semimodule structures on a fixed `add_comm_monoid` agree, it suffices to check the scalar multiplications agree. -/ -- We'll later use this to show `semimodule ℕ M` and `module ℤ M` are subsingletons. @[ext] lemma semimodule_ext {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] (P Q : semimodule R M) (w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) : P = Q := begin unfreezingI { rcases P with ⟨⟨⟨⟨P⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨Q⟩⟩⟩⟩ }, congr, funext r m, exact w r m, all_goals { apply proof_irrel_heq }, end section module variables [ring R] [add_comm_group M] [module R M] (r s : R) (x y : M) @[simp] theorem neg_smul : -r • x = - (r • x) := eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul]) variables (R) theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp variables {R} theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by simp [add_smul, sub_eq_add_neg] end module /-- A semimodule over a `subsingleton` semiring is a `subsingleton`. We cannot register this as an instance because Lean has no way to guess `R`. -/ theorem semimodule.subsingleton (R M : Type*) [semiring R] [subsingleton R] [add_comm_monoid M] [semimodule R M] : subsingleton M := ⟨λ x y, by rw [← one_smul R x, ← one_smul R y, subsingleton.elim (1:R) 0, zero_smul, zero_smul]⟩ @[priority 910] -- see Note [lower instance priority] instance semiring.to_semimodule [semiring R] : semimodule R R := { smul_add := mul_add, add_smul := add_mul, zero_smul := zero_mul, smul_zero := mul_zero } /-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/ def ring_hom.to_semimodule [semiring R] [semiring S] (f : R →+* S) : semimodule R S := { smul := λ r x, f r * x, smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add], add_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_add, add_mul], mul_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_mul, mul_assoc], one_smul := λ x, show f 1 * x = _, by rw [f.map_one, one_mul], zero_smul := λ x, show f 0 * x = 0, by rw [f.map_zero, zero_mul], smul_zero := λ r, mul_zero (f r) } /-- Vector spaces are defined as an `abbreviation` for semimodules, if the base ring is a field. (A previous definition made `vector_space` a structure defined to be `module`.) This has as advantage that vector spaces are completely transparent for type class inference, which means that all instances for semimodules are immediately picked up for vector spaces as well. A cosmetic disadvantage is that one can not extend vector spaces as such, in definitions such as `normed_space`. The solution is to extend `semimodule` instead. -/ library_note "vector space definition" /-- A vector space is the same as a module, except the scalar ring is actually a field. (This adds commutativity of the multiplication and existence of inverses.) This is the traditional generalization of spaces like `ℝ^n`, which have a natural addition operation and a way to multiply them by real numbers, but no multiplication operation between vectors. -/ abbreviation vector_space (R : Type u) (M : Type v) [field R] [add_comm_group M] := semimodule R M section add_comm_monoid variables [semiring R] [add_comm_monoid M] [semimodule R M] /-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/ -- We don't make this a global instance, as it results in too many instances, -- and confusing ambiguity in the notation `n • x` when `n : ℕ`. def add_comm_monoid.nat_semimodule : semimodule ℕ M := { smul := nsmul, smul_add := λ _ _ _, nsmul_add _ _ _, add_smul := λ _ _ _, add_nsmul _ _ _, mul_smul := λ _ _ _, mul_nsmul _ _ _, one_smul := one_nsmul, zero_smul := zero_nsmul, smul_zero := nsmul_zero } section local attribute [instance] add_comm_monoid.nat_semimodule /-- `nsmul` is defined as the `smul` action of `add_comm_monoid.nat_semimodule`. -/ lemma nsmul_def (n : ℕ) (x : M) : n •ℕ x = n • x := rfl end section variables (R) /-- `nsmul` is equal to any other semimodule structure via a cast. -/ lemma nsmul_eq_smul_cast (n : ℕ) (b : M) : n •ℕ b = (n : R) • b := begin rw nsmul_def, induction n with n ih, { rw [nat.cast_zero, zero_smul, zero_smul] }, { rw [nat.succ_eq_add_one, nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul] } end end /-- `nsmul` is equal to any `ℕ`-semimodule structure. -/ lemma nsmul_eq_smul [semimodule ℕ M] (n : ℕ) (b : M) : n •ℕ b = n • b := by rw [nsmul_eq_smul_cast ℕ, n.cast_id] /-- All `ℕ`-semimodule structures are equal. -/ instance add_comm_monoid.nat_semimodule.subsingleton : subsingleton (semimodule ℕ M) := ⟨λ P Q, by { ext n, rw [←nsmul_eq_smul, ←nsmul_eq_smul], }⟩ /-- Note this does not depend on the `nat_semimodule` definition above, to avoid issues when diamonds occur in finding `semimodule ℕ M` instances. -/ instance add_comm_monoid.nat_is_scalar_tower [semimodule ℕ R] [semimodule ℕ M] : is_scalar_tower ℕ R M := { smul_assoc := λ n x y, nat.rec_on n (by simp only [zero_smul]) (λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ih]) } instance add_comm_monoid.nat_smul_comm_class [semimodule ℕ M] : smul_comm_class ℕ R M := { smul_comm := λ n r m, nat.rec_on n (by simp only [zero_smul, smul_zero]) (λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) } -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop instance add_comm_monoid.nat_smul_comm_class' [semimodule ℕ M] : smul_comm_class R ℕ M := smul_comm_class.symm _ _ _ end add_comm_monoid section add_comm_group variables [semiring S] [ring R] [add_comm_group M] [semimodule S M] [semimodule R M] /-- The natural ℤ-module structure on any `add_comm_group`. -/ -- We don't immediately make this a global instance, as it results in too many instances, -- and confusing ambiguity in the notation `n • x` when `n : ℤ`. -- We do turn it into a global instance, but only at the end of this file, -- and I remain dubious whether this is a good idea. def add_comm_group.int_module : module ℤ M := { smul := gsmul, smul_add := λ _ _ _, gsmul_add _ _ _, add_smul := λ _ _ _, add_gsmul _ _ _, mul_smul := λ _ _ _, gsmul_mul _ _ _, one_smul := one_gsmul, zero_smul := zero_gsmul, smul_zero := gsmul_zero } section local attribute [instance] add_comm_group.int_module /-- `gsmul` is defined as the `smul` action of `add_comm_group.int_module`. -/ lemma gsmul_def (n : ℤ) (x : M) : gsmul n x = n • x := rfl end section variables (R) /-- `gsmul` is equal to any other module structure via a cast. -/ lemma gsmul_eq_smul_cast (n : ℤ) (b : M) : gsmul n b = (n : R) • b := begin rw gsmul_def, induction n using int.induction_on with p hp n hn, { rw [int.cast_zero, zero_smul, zero_smul] }, { rw [int.cast_add, int.cast_one, add_smul, add_smul, one_smul, one_smul, hp] }, { rw [int.cast_sub, int.cast_one, sub_smul, sub_smul, one_smul, one_smul, hn] }, end end /-- `gsmul` is equal to any `ℤ`-module structure. -/ lemma gsmul_eq_smul [semimodule ℤ M] (n : ℤ) (b : M) : n •ℤ b = n • b := by rw [gsmul_eq_smul_cast ℤ, n.cast_id] /-- All `ℤ`-module structures are equal. -/ instance add_comm_group.int_module.subsingleton : subsingleton (semimodule ℤ M) := ⟨λ P Q, by { ext n, rw [←gsmul_eq_smul, ←gsmul_eq_smul], }⟩ instance add_comm_group.int_is_scalar_tower [semimodule ℤ R] [semimodule ℤ M] : is_scalar_tower ℤ R M := { smul_assoc := λ n x y, int.induction_on n (by simp only [zero_smul]) (λ n ih, by simp only [one_smul, add_smul, ih]) (λ n ih, by simp only [one_smul, sub_smul, ih]) } instance add_comm_group.int_smul_comm_class [semimodule ℤ M] : smul_comm_class ℤ S M := { smul_comm := λ n x y, int.induction_on n (by simp only [zero_smul, smul_zero]) (λ n ih, by simp only [one_smul, add_smul, smul_add, ih]) (λ n ih, by simp only [one_smul, sub_smul, smul_sub, ih]) } -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop instance add_comm_group.int_smul_comm_class' [semimodule ℤ M] : smul_comm_class S ℤ M := smul_comm_class.symm _ _ _ end add_comm_group namespace add_monoid_hom -- We prove this without using the `add_comm_group.int_module` instance, so the `•`s here -- come from whatever the local `module ℤ` structure actually is. lemma map_int_module_smul [add_comm_group M] [add_comm_group M₂] [module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a := by simp only [←gsmul_eq_smul, f.map_gsmul] lemma map_int_cast_smul [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [←gsmul_eq_smul_cast, f.map_gsmul] lemma map_nat_cast_smul [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [←nsmul_eq_smul_cast, f.map_nsmul] lemma map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R] {E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F] (f : E →+ F) (c : ℚ) (x : E) : f ((c : R) • x) = (c : R) • f x := begin have : ∀ (x : E) (n : ℕ), 0 < n → f (((n⁻¹ : ℚ) : R) • x) = ((n⁻¹ : ℚ) : R) • f x, { intros x n hn, replace hn : (n : R) ≠ 0 := nat.cast_ne_zero.2 (ne_of_gt hn), conv_rhs { congr, skip, rw [← one_smul R x, ← mul_inv_cancel hn, mul_smul] }, rw [f.map_nat_cast_smul, smul_smul, rat.cast_inv, rat.cast_coe_nat, inv_mul_cancel hn, one_smul] }, refine c.num_denom_cases_on (λ m n hn hmn, _), rw [rat.mk_eq_div, div_eq_mul_inv, rat.cast_mul, int.cast_coe_nat, mul_smul, mul_smul, rat.cast_coe_int, f.map_int_cast_smul, this _ n hn] end lemma map_rat_module_smul {E : Type*} [add_comm_group E] [vector_space ℚ E] {F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) : f (c • x) = c • f x := rat.cast_id c ▸ f.map_rat_cast_smul c x @[simp] lemma nat_smul_apply [add_monoid M] [add_comm_monoid M₂] [semimodule ℕ (M →+ M₂)] [semimodule ℕ M₂] (n : ℕ) (f : M →+ M₂) (a : M) : (n • f) a = n • (f a) := begin induction n with n IH, { simp only [zero_smul, zero_apply] }, { simp only [nat.succ_eq_add_one, add_smul, IH, one_smul, add_apply] } end @[simp] lemma int_smul_apply [add_monoid M] [add_comm_group M₂] [module ℤ (M →+ M₂)] [module ℤ M₂] (n : ℤ) (f : M →+ M₂) (a : M) : (n • f) a = n • (f a) := begin apply int.induction_on' n 0, { simp only [zero_smul, zero_apply] }, all_goals { intros k hk IH, simp only [add_smul, sub_smul, IH, one_smul, add_apply, sub_apply] } end end add_monoid_hom section no_zero_smul_divisors /-! ### `no_zero_smul_divisors` This section defines the `no_zero_smul_divisors` class, and includes some tests for the vanishing of elements (especially in modules over division rings). -/ /-- `no_zero_smul_divisors R M` states that a scalar multiple is `0` only if either argument is `0`. The main application of `no_zero_smul_divisors R M`, when `M` is a semimodule, is the result `smul_eq_zero`: a scalar multiple is `0` iff either argument is `0`. It is a generalization of the `no_zero_divisors` class to heterogeneous multiplication. -/ class no_zero_smul_divisors (R M : Type*) [has_zero R] [has_zero M] [has_scalar R M] : Prop := (eq_zero_or_eq_zero_of_smul_eq_zero : ∀ {c : R} {x : M}, c • x = 0 → c = 0 ∨ x = 0) export no_zero_smul_divisors (eq_zero_or_eq_zero_of_smul_eq_zero) section semimodule variables [semiring R] [add_comm_monoid M] [semimodule R M] instance no_zero_smul_divisors.of_no_zero_divisors [no_zero_divisors R] : no_zero_smul_divisors R R := ⟨λ c x, no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero⟩ @[simp] theorem smul_eq_zero [no_zero_smul_divisors R M] {c : R} {x : M} : c • x = 0 ↔ c = 0 ∨ x = 0 := ⟨eq_zero_or_eq_zero_of_smul_eq_zero, λ h, h.elim (λ h, h.symm ▸ zero_smul R x) (λ h, h.symm ▸ smul_zero c)⟩ theorem smul_ne_zero [no_zero_smul_divisors R M] {c : R} {x : M} : c • x ≠ 0 ↔ c ≠ 0 ∧ x ≠ 0 := by simp only [ne.def, smul_eq_zero, not_or_distrib] section nat variables (R) (M) [no_zero_smul_divisors R M] [semimodule ℕ M] [char_zero R] include R lemma nat.no_zero_smul_divisors : no_zero_smul_divisors ℕ M := ⟨by { intros c x, rw [← nsmul_eq_smul, nsmul_eq_smul_cast R, smul_eq_zero], simp }⟩ variables {M} lemma eq_zero_of_smul_two_eq_zero {v : M} (hv : 2 • v = 0) : v = 0 := by haveI := nat.no_zero_smul_divisors R M; exact (smul_eq_zero.mp hv).resolve_left (by norm_num) end nat end semimodule section add_comm_group -- `R` can still be a semiring here variables [semiring R] [add_comm_group M] [semimodule R M] lemma smul_injective [no_zero_smul_divisors R M] {c : R} (hc : c ≠ 0) : function.injective (λ (x : M), c • x) := λ x y h, sub_eq_zero.mp ((smul_eq_zero.mp (calc c • (x - y) = c • x - c • y : smul_sub c x y ... = 0 : sub_eq_zero.mpr h)).resolve_left hc) section nat variables (R) [no_zero_smul_divisors R M] [char_zero R] include R lemma eq_zero_of_eq_neg {v : M} (hv : v = - v) : v = 0 := begin -- any semimodule will do haveI : semimodule ℕ M := add_comm_monoid.nat_semimodule, haveI := nat.no_zero_smul_divisors R M, refine eq_zero_of_smul_two_eq_zero R _, rw ←nsmul_eq_smul, convert add_eq_zero_iff_eq_neg.mpr hv, abel end end nat end add_comm_group section module section nat variables {R} [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] [char_zero R] lemma ne_neg_of_ne_zero [no_zero_divisors R] {v : R} (hv : v ≠ 0) : v ≠ -v := λ h, have semimodule ℕ R := add_comm_monoid.nat_semimodule, by exactI hv (eq_zero_of_eq_neg R h) end nat end module section division_ring variables [division_ring R] [add_comm_group M] [module R M] @[priority 100] -- see note [lower instance priority] instance no_zero_smul_divisors.of_division_ring : no_zero_smul_divisors R M := ⟨λ c x h, or_iff_not_imp_left.2 $ λ hc, (units.mk0 c hc).smul_eq_zero.1 h⟩ end division_ring end no_zero_smul_divisors -- We finally turn on these instances globally. By doing this here, we ensure that none of the -- lemmas about nat semimodules above are specific to these instances. attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
2f967af7d796b0900964d253e83f34ded5bdb071
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/src/Init/Control/Id.lean
cb2d23c7621ef48f701d0a6ae760fa72b940b87d
[ "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
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
529
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich The identity Monad. -/ prelude import Init.Core universe u def Id (type : Type u) : Type u := type namespace Id instance : Monad Id where pure x := x bind x f := f x map f x := f x def hasBind : Bind Id := inferInstance @[inline] protected def run (x : Id α) : α := x instance [OfNat α n] : OfNat (Id α) n := inferInstanceAs (OfNat α n) end Id
cf3787d06442d5eaf68ec90f6d018043d3c98ccc
54d7e71c3616d331b2ec3845d31deb08f3ff1dea
/library/init/meta/interactive.lean
3c81a554684ea3ca8a99abb23a7b6a4d4593ec71
[ "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
30,194
lean
/- Copyright (c) 2016 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.tactic init.meta.rewrite_tactic init.meta.simp_tactic import init.meta.smt.congruence_closure init.category.combinators import init.meta.lean.parser init.meta.quote open lean open lean.parser local postfix `?`:9001 := optional local postfix *:9001 := many namespace interactive /-- (parse p) as the parameter type of an interactive tactic will instruct the Lean parser to run `p` when parsing the parameter and to pass the parsed value as an argument to the tactic. -/ @[reducible] meta def parse {α : Type} [has_quote α] (p : parser α) : Type := α namespace types variables {α β : Type} -- optimized pretty printer meta def brackets (l r : string) (p : parser α) := tk l *> p <* tk r meta def list_of (p : parser α) := brackets "[" "]" $ sep_by (skip_info (tk ",")) p /-- A 'tactic expression', which uses right-binding power 2 so that it is terminated by '<|>' (rbp 2), ';' (rbp 1), and ',' (rbp 0). It should be used for any (potentially) trailing expression parameters. -/ meta def texpr := qexpr 2 /-- Parse an identifier or a '_' -/ meta def ident_ : parser name := ident <|> tk "_" *> return `_ meta def using_ident := (tk "using" *> ident)? meta def with_ident_list := (tk "with" *> ident_*) <|> return [] meta def without_ident_list := (tk "without" *> ident*) <|> return [] meta def location := (tk "at" *> ident*) <|> return [] meta def qexpr_list := list_of (qexpr 0) meta def opt_qexpr_list := qexpr_list <|> return [] meta def qexpr_list_or_texpr := qexpr_list <|> list.ret <$> texpr end types /-- Use `desc` as the interactive description of `p`. -/ meta def with_desc {α : Type} (desc : format) (p : parser α) : parser α := p open expr format tactic types private meta def maybe_paren : list format → format | [] := "" | [f] := f | fs := paren (join fs) private meta def unfold (e : expr) : tactic expr := do (expr.const f_name f_lvls) ← return e.get_app_fn | failed, env ← get_env, decl ← env.get f_name, new_f ← decl.instantiate_value_univ_params f_lvls, head_beta (expr.mk_app new_f e.get_app_args) private meta def concat (f₁ f₂ : list format) := if f₁.empty then f₂ else if f₂.empty then f₁ else f₁ ++ [" "] ++ f₂ private meta def parser_desc_aux : expr → tactic (list format) | ```(ident) := return ["id"] | ```(ident_) := return ["id"] | ```(qexpr) := return ["expr"] | ```(tk %%c) := list.ret <$> to_fmt <$> eval_expr string c | ```(cur_pos) := return [] | ```(return ._) := return [] | ```(._ <$> %%p) := parser_desc_aux p | ```(skip_info %%p) := parser_desc_aux p | ```(set_goal_info_pos %%p) := parser_desc_aux p | ```(with_desc %%desc %%p) := list.ret <$> eval_expr format desc | ```(%%p₁ <*> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | ```(%%p₁ <* %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | ```(%%p₁ *> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | ```(many %%p) := do f ← parser_desc_aux p, return [maybe_paren f ++ "*"] | ```(optional %%p) := do f ← parser_desc_aux p, return [maybe_paren f ++ "?"] | ```(sep_by %%sep %%p) := do f₁ ← parser_desc_aux sep, f₂ ← parser_desc_aux p, return [maybe_paren f₂ ++ join f₁, " ..."] | ```(%%p₁ <|> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ if f₁.empty then [maybe_paren f₂ ++ "?"] else if f₂.empty then [maybe_paren f₁ ++ "?"] else [paren $ join $ f₁ ++ [to_fmt " | "] ++ f₂] | ```(brackets %%l %%r %%p) := do f ← parser_desc_aux p, l ← eval_expr string l, r ← eval_expr string r, -- much better than the naive [l, " ", f, " ", r] return [to_fmt l ++ join f ++ to_fmt r] | e := do e' ← (do e' ← unfold e, guard $ e' ≠ e, return e') <|> (do f ← pp e, fail $ to_fmt "don't know how to pretty print " ++ f), parser_desc_aux e' meta def param_desc : expr → tactic format | ```(parse %%p) := join <$> parser_desc_aux p | ```(opt_param %%t ._) := (++ "?") <$> pp t | e := if is_constant e ∧ (const_name e).components.ilast = `itactic then return $ to_fmt "{ tactic }" else paren <$> pp e end interactive namespace tactic meta def report_resolve_name_failure {α : Type} (e : expr) (n : name) : tactic α := if e.is_choice_macro then fail ("failed to resolve name '" ++ to_string n ++ "', it is overloaded") else fail ("failed to resolve name '" ++ to_string n ++ "', unexpected result") /- allows metavars and report errors -/ meta def i_to_expr (q : pexpr) : tactic expr := to_expr q tt /- doesn't allows metavars and report errors -/ meta def i_to_expr_strict (q : pexpr) : tactic expr := to_expr q ff namespace interactive open interactive interactive.types expr /- itactic: parse a nested "interactive" tactic. That is, parse `{` tactic `}` -/ meta def itactic : Type := tactic unit /-- This tactic applies to a goal that is either a Pi/forall or starts with a let binder. If the current goal is a Pi/forall `∀ x:T, U` (resp `let x:=t in U`) then intro puts `x:T` (resp `x:=t`) in the local context. The new subgoal target is `U`. If the goal is an arrow `T → U`, then it puts in the local context either `h:T`, and the new goal target is `U`. If the goal is neither a Pi/forall nor starting with a let definition, the tactic `intro` applies the tactic `whnf` until the tactic `intro` can be applied or the goal is not `head-reducible`. -/ meta def intro : parse ident_? → tactic unit | none := intro1 >> skip | (some h) := tactic.intro h >> skip /-- Similar to `intro` tactic. The tactic `intros` will keep introducing new hypotheses until the goal target is not a Pi/forall or let binder. The variant `intros h_1 ... h_n` introduces `n` new hypotheses using the given identifiers to name them. -/ meta def intros : parse ident_* → tactic unit | [] := tactic.intros >> skip | hs := intro_lst hs >> skip /-- The tactic `rename h₁ h₂` renames hypothesis `h₁` into `h₂` in the current local context. -/ meta def rename : parse ident → parse ident → tactic unit := tactic.rename /-- This tactic applies to any goal. The argument term is a term well-formed in the local context of the main goal. The tactic apply tries to match the current goal against the conclusion of the type of term. If it succeeds, then the tactic returns as many subgoals as the number of non-dependent premises that have not been fixed by type inference or type class resolution. The tactic `apply` uses higher-order pattern matching, type class resolution, and first-order unification with dependent types. -/ meta def apply (q : parse texpr) : tactic unit := i_to_expr q >>= tactic.apply /-- Similar to the `apply` tactic, but it also creates subgoals for dependent premises that have not been fixed by type inference or type class resolution. -/ meta def fapply (q : parse texpr) : tactic unit := i_to_expr q >>= tactic.fapply /-- This tactic tries to close the main goal `... |- U` using type class resolution. It succeeds if it generates a term of type `U` using type class resolution. -/ meta def apply_instance : tactic unit := tactic.apply_instance /-- This tactic applies to any goal. It behaves like `exact` with a big difference: the user can leave some holes `_` in the term. `refine` will generate as many subgoals as there are holes in the term. Note that some holes may be implicit. The type of holes must be either synthesized by the system or declared by an explicit type ascription like (e.g., `(_ : nat → Prop)`). -/ meta def refine (q : parse texpr) : tactic unit := tactic.refine q /-- This tactic looks in the local context for an hypothesis which type is equal to the goal target. If it is the case, the subgoal is proved. Otherwise, it fails. -/ meta def assumption : tactic unit := tactic.assumption /-- This tactic applies to any goal. `change U` replaces the main goal target `T` with `U` providing that `U` is well-formed with respect to the main goal local context, and `T` and `U` are definitionally equal. -/ meta def change (q : parse texpr) : tactic unit := i_to_expr q >>= tactic.change /-- This tactic applies to any goal. It gives directly the exact proof term of the goal. Let `T` be our goal, let `p` be a term of type `U` then `exact p` succeeds iff `T` and `U` are definitionally equal. -/ meta def exact (q : parse texpr) : tactic unit := do tgt : expr ← target, i_to_expr_strict ``(%%q : %%tgt) >>= tactic.exact /-- Like `exact`, but takes a list of terms and checks that all goals are discharged after the tactic. -/ meta def exacts : parse qexpr_list_or_texpr → tactic unit | [] := now | (t :: ts) := exact t >> exacts ts private meta def get_locals : list name → tactic (list expr) | [] := return [] | (n::ns) := do h ← get_local n, hs ← get_locals ns, return (h::hs) /-- `revert h₁ ... hₙ` applies to any goal with hypotheses `h₁` ... `hₙ`. It moves the hypotheses and its dependencies to the goal target. This tactic is the inverse of `intro`. -/ meta def revert (ids : parse ident*) : tactic unit := do hs ← get_locals ids, revert_lst hs, skip private meta def resolve_name' (n : name) : tactic expr := do { p ← resolve_name n, match p.to_raw_expr with | expr.const n _ := mk_const n -- create metavars for universe levels | _ := i_to_expr p end } /- Version of to_expr that tries to bypass the elaborator if `p` is just a constant or local constant. This is not an optimization, by skipping the elaborator we make sure that no unwanted resolution is used. Example: the elaborator will force any unassigned ?A that must have be an instance of (has_one ?A) to nat. Remark: another benefit is that auxiliary temporary metavariables do not appear in error messages. -/ private meta def to_expr' (p : pexpr) : tactic expr := let e := p.to_raw_expr in match e with | (const c []) := do new_e ← resolve_name' c, save_type_info new_e e, return new_e | (local_const c _ _ _) := do new_e ← resolve_name' c, save_type_info new_e e, return new_e | _ := i_to_expr p end meta structure rw_rule := (pos : pos) (symm : bool) (rule : pexpr) meta instance rw_rule_has_quote : has_quote rw_rule := ⟨λ ⟨p, s, r⟩, ``(rw_rule.mk %%(quote p) %%(quote s) %%(quote r))⟩ private meta def rw_goal (m : transparency) (rs : list rw_rule) : tactic unit := rs.mfor' $ λ r, save_info r.pos >> to_expr' r.rule >>= rewrite_core m tt tt occurrences.all r.symm private meta def rw_hyp (m : transparency) (rs : list rw_rule) (hname : name) : tactic unit := rs.mfor' $ λ r, do h ← get_local hname, save_info r.pos, e ← to_expr' r.rule, rewrite_at_core m tt tt occurrences.all r.symm e h private meta def rw_hyps (m : transparency) (rs : list rw_rule) (hs : list name) : tactic unit := hs.mfor' (rw_hyp m rs) meta def rw_rule_p (ep : parser pexpr) : parser rw_rule := rw_rule.mk <$> cur_pos <*> (option.is_some <$> (tk "-")?) <*> ep meta structure rw_rules_t := (rules : list rw_rule) (end_pos : option pos) meta instance rw_rules_t_has_quote : has_quote rw_rules_t := ⟨λ ⟨rs, p⟩, ``(rw_rules_t.mk %%(quote rs) %%(quote p))⟩ -- accepts the same content as `qexpr_list_or_texpr`, but with correct goal info pos annotations meta def rw_rules : parser rw_rules_t := (tk "[" *> rw_rules_t.mk <$> sep_by (skip_info (tk ",")) (set_goal_info_pos $ rw_rule_p (qexpr 0)) <*> (some <$> cur_pos <* set_goal_info_pos (tk "]"))) <|> rw_rules_t.mk <$> (list.ret <$> rw_rule_p texpr) <*> return none private meta def rw_core (m : transparency) (rs : parse rw_rules) (loc : parse location) : tactic unit := match loc with | [] := rw_goal m rs.rules | hs := rw_hyps m rs.rules hs end >> try (reflexivity reducible) >> (returnopt rs.end_pos >>= save_info <|> skip) meta def rewrite : parse rw_rules → parse location → tactic unit := rw_core reducible meta def rw : parse rw_rules → parse location → tactic unit := rewrite /- rewrite followed by assumption -/ meta def rwa (q : parse rw_rules) (l : parse location) : tactic unit := rewrite q l >> try assumption meta def erewrite : parse rw_rules → parse location → tactic unit := rw_core semireducible meta def erw : parse rw_rules → parse location → tactic unit := erewrite private meta def get_type_name (e : expr) : tactic name := do e_type ← infer_type e >>= whnf, (const I ls) ← return $ get_app_fn e_type, return I precedence `generalizing` : 0 meta def induction (p : parse texpr) (rec_name : parse using_ident) (ids : parse with_ident_list) (revert : parse $ (tk "generalizing" *> ident*)?) : tactic unit := do e ← i_to_expr p, locals ← get_locals $ revert.get_or_else [], n ← revert_lst locals, tactic.induction e ids rec_name, all_goals (intron n) meta def cases (p : parse texpr) (ids : parse with_ident_list) : tactic unit := do e ← i_to_expr p, tactic.cases e ids private meta def find_case (goals : list expr) (ty : name) (idx : nat) (num_indices : nat) : option expr → expr → option (expr × expr) | case e := if e.has_meta_var then match e with | (mvar _ _) := do case ← case, guard $ e ∈ goals, pure (case, e) | (app _ _) := let idx := match e.get_app_fn with | const (name.mk_string rec ty') _ := guard (ty' = ty) >> match mk_simple_name rec with | `drec := some idx | `rec := some idx -- indices + major premise | `dcases_on := some (idx + num_indices + 1) | `cases_on := some (idx + num_indices + 1) | _ := none end | _ := none end in match idx with | none := list.foldl (<|>) none $ e.get_app_args.map (find_case case) | some idx := let args := e.get_app_args in do arg ← args.nth idx, args.enum.foldl (λ acc ⟨i, arg⟩, match acc with | some _ := acc | _ := if i ≠ idx then find_case none arg else none end) -- start recursion with likely case (find_case (some arg) arg) end | (lam _ _ _ e) := find_case case e | (macro _ n f) := list.foldl (<|>) none $ list.map (find_case case) $ macro_args_to_list n f | _ := none end else none private meta def rename_lams : expr → list name → tactic unit | (lam n _ _ e) (n'::ns) := (rename n n' >> rename_lams e ns) <|> rename_lams e (n'::ns) | _ _ := skip /-- Focuses on the `induction`/`cases` subgoal corresponding to the given introduction rule, optionally renaming introduced locals. -/ meta def case (ctor : parse ident) (ids : parse ident*) (tac : itactic) : tactic unit := do r ← result, env ← get_env, ctor ← resolve_constant ctor <|> fail ("'" ++ to_string ctor ++ "' is not a constructor"), ty ← (env.inductive_type_of ctor).to_monad <|> fail ("'" ++ to_string ctor ++ "' is not a constructor"), let ctors := env.constructors_of ty, let idx := env.inductive_num_params ty + /- motive -/ 1 + list.find ctor ctors, gs ← get_goals, (case, g) ← (find_case gs ty idx (env.inductive_num_indices ty) none r ).to_monad <|> fail "could not find open goal of given case", set_goals $ g :: gs.filter (≠ g), rename_lams case ids, solve1 tac meta def destruct (p : parse texpr) : tactic unit := i_to_expr p >>= tactic.destruct meta def generalize (p : parse qexpr) (x : parse ident) : tactic unit := do e ← i_to_expr p, tactic.generalize e x meta def generalize2 (p : parse qexpr) (x : parse ident) (h : parse ident) : tactic unit := do tgt ← target, e ← to_expr p, let e' := tgt^.replace $ λa _, if a = e then some (var 1) else none, to_expr `(Π x, %%p = x → %%e') >>= assert h, swap, t ← get_local h, exact `(%%t %%p rfl), intro x, intro h meta def ginduction (p : parse texpr) (rec_name : parse using_ident) (ids : parse with_ident_list) : tactic unit := do x ← mk_fresh_name, let (h, hs) := (match ids with | [] := (`_h, []) | (h :: hs) := (h, hs) end : name × list name), generalize2 p x h, t ← get_local x, induction (to_pexpr t) rec_name hs ([] : list name) meta def trivial : tactic unit := tactic.triv <|> tactic.reflexivity <|> tactic.contradiction <|> fail "trivial tactic failed" /-- Closes the main goal using sorry. -/ meta def admit : tactic unit := tactic.admit /-- This tactic applies to any goal. The contradiction tactic attempts to find in the current local context an hypothesis that is equivalent to an empty inductive type (e.g. `false`), a hypothesis of the form `c_1 ... = c_2 ...` where `c_1` and `c_2` are distinct constructors, or two contradictory hypotheses. -/ meta def contradiction : tactic unit := tactic.contradiction meta def repeat : itactic → tactic unit := tactic.repeat meta def try : itactic → tactic unit := tactic.try meta def skip : tactic unit := tactic.skip meta def solve1 : itactic → tactic unit := tactic.solve1 meta def abstract (id : parse ident? ) (tac : itactic) : tactic unit := tactic.abstract tac id meta def all_goals : itactic → tactic unit := tactic.all_goals meta def any_goals : itactic → tactic unit := tactic.any_goals meta def focus (tac : itactic) : tactic unit := tactic.focus [tac] /-- This tactic applies to any goal. `assert h : T` adds a new hypothesis of name `h` and type `T` to the current goal and opens a new subgoal with target `T`. The new subgoal becomes the main goal. -/ meta def assert (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit := do e ← i_to_expr_strict q, tactic.assert h e meta def define (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit := do e ← i_to_expr_strict q, tactic.define h e /-- This tactic applies to any goal. `assertv h : T := p` adds a new hypothesis of name `h` and type `T` to the current goal if `p` a term of type `T`. -/ meta def assertv (h : parse ident) (q₁ : parse $ tk ":" *> texpr) (q₂ : parse $ tk ":=" *> texpr) : tactic unit := do t ← i_to_expr_strict q₁, v ← i_to_expr_strict ``(%%q₂ : %%t), tactic.assertv h t v meta def definev (h : parse ident) (q₁ : parse $ tk ":" *> texpr) (q₂ : parse $ tk ":=" *> texpr) : tactic unit := do t ← i_to_expr_strict q₁, v ← i_to_expr_strict ``(%%q₂ : %%t), tactic.definev h t v meta def note (h : parse ident) (q : parse $ tk ":=" *> texpr) : tactic unit := do p ← i_to_expr_strict q, tactic.note h p meta def pose (h : parse ident) (q : parse $ tk ":=" *> texpr) : tactic unit := do p ← i_to_expr_strict q, tactic.pose h p /-- This tactic displays the current state in the tracing buffer. -/ meta def trace_state : tactic unit := tactic.trace_state /-- `trace a` displays `a` in the tracing buffer. -/ meta def trace {α : Type} [has_to_tactic_format α] (a : α) : tactic unit := tactic.trace a meta def existsi (e : parse texpr) : tactic unit := i_to_expr e >>= tactic.existsi /-- This tactic applies to a goal such that its conclusion is an inductive type (say `I`). It tries to apply each constructor of `I` until it succeeds. -/ meta def constructor : tactic unit := tactic.constructor meta def left : tactic unit := tactic.left meta def right : tactic unit := tactic.right meta def split : tactic unit := tactic.split meta def exfalso : tactic unit := tactic.exfalso /-- The injection tactic is based on the fact that constructors of inductive datatypes are injections. That means that if `c` is a constructor of an inductive datatype, and if `(c t₁)` and `(c t₂)` are two terms that are equal then `t₁` and `t₂` are equal too. If `q` is a proof of a statement of conclusion `t₁ = t₂`, then injection applies injectivity to derive the equality of all arguments of `t₁` and `t₂` placed in the same positions. For example, from `(a::b) = (c::d)` we derive `a=c` and `b=d`. To use this tactic `t₁` and `t₂` should be constructor applications of the same constructor. Given `h : a::b = c::d`, the tactic `injection h` adds to new hypothesis with types `a = c` and `b = d` to the main goal. The tactic `injection h with h₁ h₂` uses the names `h₁` an `h₂` to name the new hypotheses. -/ meta def injection (q : parse texpr) (hs : parse with_ident_list) : tactic unit := do e ← i_to_expr q, tactic.injection_with e hs private meta def add_simps : simp_lemmas → list name → tactic simp_lemmas | s [] := return s | s (n::ns) := do s' ← s.add_simp n, add_simps s' ns private meta def report_invalid_simp_lemma {α : Type} (n : name): tactic α := fail ("invalid simplification lemma '" ++ to_string n ++ "' (use command 'set_option trace.simp_lemmas true' for more details)") private meta def simp_lemmas.resolve_and_add (s : simp_lemmas) (n : name) (ref : expr) : tactic simp_lemmas := do p ← resolve_name n, match p.to_raw_expr with | const n _ := (do b ← is_valid_simp_lemma_cnst reducible n, guard b, save_const_type_info n ref, s.add_simp n) <|> (do eqns ← get_eqn_lemmas_for tt n, guard (eqns.length > 0), save_const_type_info n ref, add_simps s eqns) <|> report_invalid_simp_lemma n | _ := (do e ← i_to_expr p, b ← is_valid_simp_lemma reducible e, guard b, try (save_type_info e ref), s.add e) <|> report_invalid_simp_lemma n end private meta def simp_lemmas.add_pexpr (s : simp_lemmas) (p : pexpr) : tactic simp_lemmas := let e := p.to_raw_expr in match e with | (const c []) := simp_lemmas.resolve_and_add s c e | (local_const c _ _ _) := simp_lemmas.resolve_and_add s c e | _ := do new_e ← i_to_expr p, s.add new_e end private meta def simp_lemmas.append_pexprs : simp_lemmas → list pexpr → tactic simp_lemmas | s [] := return s | s (l::ls) := do new_s ← simp_lemmas.add_pexpr s l, simp_lemmas.append_pexprs new_s ls private meta def mk_simp_set (attr_names : list name) (hs : list pexpr) (ex : list name) : tactic simp_lemmas := do s₀ ← join_user_simp_lemmas attr_names, s₁ ← simp_lemmas.append_pexprs s₀ hs, -- add equational lemmas, if any ex ← ex.mfor (λ n, list.cons n <$> get_eqn_lemmas_for tt n), return $ simp_lemmas.erase s₁ $ ex.join private meta def simp_goal (cfg : simp_config) : simp_lemmas → tactic unit | s := do (new_target, Heq) ← target >>= simplify_core cfg s `eq, tactic.assert `Htarget new_target, swap, Ht ← get_local `Htarget, mk_eq_mpr Heq Ht >>= tactic.exact private meta def simp_hyp (cfg : simp_config) (s : simp_lemmas) (h_name : name) : tactic unit := do h ← get_local h_name, htype ← infer_type h, (new_htype, eqpr) ← simplify_core cfg s `eq htype, tactic.assert (expr.local_pp_name h) new_htype, mk_eq_mp eqpr h >>= tactic.exact, try $ tactic.clear h private meta def simp_hyps (cfg : simp_config) : simp_lemmas → list name → tactic unit | s [] := skip | s (h::hs) := simp_hyp cfg s h >> simp_hyps s hs private meta def simp_core (cfg : simp_config) (ctx : list expr) (hs : list pexpr) (attr_names : list name) (ids : list name) (loc : list name) : tactic unit := do s ← mk_simp_set attr_names hs ids, s ← s.append ctx, match loc : _ → tactic unit with | [] := simp_goal cfg s | _ := simp_hyps cfg s loc end, try tactic.triv, try (tactic.reflexivity reducible) /-- This tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses. It has many variants. - `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`. - `simp [h_1, ..., h_n]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `h_i`s. The `h_i`'s are terms. If a `h_i` is a definition `f`, then the equational lemmas associated with `f` are used. This is a convenient way to "unfold" `f`. - `simp without id_1 ... id_n` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`, but removes the ones named `id_i`s. - `simp at h` simplifies the non dependent hypothesis `h : T`. The tactic fails if the target or another hypothesis depends on `h`. - `simp with attr` simplifies the main goal target using the lemmas tagged with the attribute `[attr]`. -/ meta def simp (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) (loc : parse location) (cfg : simp_config := {}) : tactic unit := simp_core cfg [] hs attr_names ids loc /-- Similar to the `simp` tactic, but adds all applicable hypotheses as simplification rules. -/ meta def simp_using_hs (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit := do ctx ← collect_ctx_simps, simp_core cfg ctx hs attr_names ids [] meta def simph (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit := simp_using_hs hs attr_names ids cfg meta def simp_intros (ids : parse ident_*) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit := do s ← mk_simp_set attr_names hs wo_ids, match ids with | [] := simp_intros_using s cfg | ns := simp_intro_lst_using ns s cfg end, try triv >> try (reflexivity reducible) meta def simph_intros (ids : parse ident_*) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit := do s ← mk_simp_set attr_names hs wo_ids, match ids with | [] := simph_intros_using s cfg | ns := simph_intro_lst_using ns s cfg end, try triv >> try (reflexivity reducible) private meta def dsimp_hyps (s : simp_lemmas) : list name → tactic unit | [] := skip | (h::hs) := get_local h >>= dsimp_at_core s meta def dsimp (es : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) : parse location → tactic unit | [] := do s ← mk_simp_set attr_names es ids, tactic.dsimp_core s | hs := do s ← mk_simp_set attr_names es ids, dsimp_hyps s hs /-- This tactic applies to a goal that has the form `t ~ u` where `~` is a reflexive relation. That is, a relation which has a reflexivity lemma tagged with the attribute `[refl]`. The tactic checks whether `t` and `u` are definitionally equal and then solves the goal. -/ meta def reflexivity : tactic unit := tactic.reflexivity /-- Shorter name for the tactic `reflexivity`. -/ meta def refl : tactic unit := tactic.reflexivity meta def symmetry : tactic unit := tactic.symmetry meta def transitivity : tactic unit := tactic.transitivity meta def ac_reflexivity : tactic unit := tactic.ac_refl meta def ac_refl : tactic unit := tactic.ac_refl meta def cc : tactic unit := tactic.cc meta def subst (q : parse texpr) : tactic unit := i_to_expr q >>= tactic.subst >> try (tactic.reflexivity reducible) meta def clear : parse ident* → tactic unit := tactic.clear_lst private meta def to_qualified_name_core : name → list name → tactic name | n [] := fail $ "unknown declaration '" ++ to_string n ++ "'" | n (ns::nss) := do curr ← return $ ns ++ n, env ← get_env, if env.contains curr then return curr else to_qualified_name_core n nss private meta def to_qualified_name (n : name) : tactic name := do env ← get_env, if env.contains n then return n else do ns ← open_namespaces, to_qualified_name_core n ns private meta def to_qualified_names : list name → tactic (list name) | [] := return [] | (c::cs) := do new_c ← to_qualified_name c, new_cs ← to_qualified_names cs, return (new_c::new_cs) private meta def dunfold_hyps : list name → list name → tactic unit | cs [] := skip | cs (h::hs) := get_local h >>= dunfold_at cs >> dunfold_hyps cs hs meta def dunfold : parse ident* → parse location → tactic unit | cs [] := do new_cs ← to_qualified_names cs, tactic.dunfold new_cs | cs hs := do new_cs ← to_qualified_names cs, dunfold_hyps new_cs hs /- TODO(Leo): add support for non-refl lemmas -/ meta def unfold : parse ident* → parse location → tactic unit := dunfold private meta def dunfold_hyps_occs : name → occurrences → list name → tactic unit | c occs [] := skip | c occs (h::hs) := get_local h >>= dunfold_core_at occs [c] >> dunfold_hyps_occs c occs hs meta def dunfold_occs : parse ident → parse location → list nat → tactic unit | c [] ps := do new_c ← to_qualified_name c, tactic.dunfold_occs_of ps new_c | c hs ps := do new_c ← to_qualified_name c, dunfold_hyps_occs new_c (occurrences.pos ps) hs /- TODO(Leo): add support for non-refl lemmas -/ meta def unfold_occs : parse ident → parse location → list nat → tactic unit := dunfold_occs private meta def delta_hyps : list name → list name → tactic unit | cs [] := skip | cs (h::hs) := get_local h >>= delta_at cs >> dunfold_hyps cs hs meta def delta : parse ident* → parse location → tactic unit | cs [] := do new_cs ← to_qualified_names cs, tactic.delta new_cs | cs hs := do new_cs ← to_qualified_names cs, delta_hyps new_cs hs meta def apply_opt_param : tactic unit := tactic.apply_opt_param meta def apply_auto_param : tactic unit := tactic.apply_auto_param meta def fail_if_success (tac : itactic) : tactic unit := tactic.fail_if_success tac meta def guard_expr_eq (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit := do e ← to_expr p, guard (alpha_eqv t e) meta def guard_target (p : parse texpr) : tactic unit := do t ← target, guard_expr_eq t p end interactive end tactic
d4539468d0466888c5a8f4e42d699c0ef23f433b
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
/library/logic/connectives.lean
2810ff2dfee9b0bc37e03a852614b60907073dfe
[ "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
5,989
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: logic.connectives Authors: Jeremy Avigad, Leonardo de Moura The propositional connectives. See also init.datatypes and init.logic. -/ variables {a b c d : Prop} /- implies -/ definition imp (a b : Prop) : Prop := a → b theorem mt (H1 : a → b) (H2 : ¬b) : ¬a := assume Ha : a, absurd (H1 Ha) H2 /- false -/ theorem false.elim {c : Prop} (H : false) : c := false.rec c H /- not -/ theorem not.elim (H1 : ¬a) (H2 : a) : false := H1 H2 theorem not.intro (H : a → false) : ¬a := H theorem not_not_intro (Ha : a) : ¬¬a := assume Hna : ¬a, absurd Ha Hna theorem not_not_of_not_implies (H : ¬(a → b)) : ¬¬a := assume Hna : ¬a, absurd (assume Ha : a, absurd Ha Hna) H theorem not_of_not_implies (H : ¬(a → b)) : ¬b := assume Hb : b, absurd (assume Ha : a, Hb) H theorem not_not_em : ¬¬(a ∨ ¬a) := assume not_em : ¬(a ∨ ¬a), have Hnp : ¬a, from assume Hp : a, absurd (or.inl Hp) not_em, absurd (or.inr Hnp) not_em /- and -/ definition not_and_of_not_left (b : Prop) (Hna : ¬a) : ¬(a ∧ b) := assume H : a ∧ b, absurd (and.elim_left H) Hna definition not_and_of_not_right (a : Prop) {b : Prop} (Hnb : ¬b) : ¬(a ∧ b) := assume H : a ∧ b, absurd (and.elim_right H) Hnb theorem and.swap (H : a ∧ b) : b ∧ a := and.intro (and.elim_right H) (and.elim_left H) theorem and_of_and_of_imp_of_imp (H₁ : a ∧ b) (H₂ : a → c) (H₃ : b → d) : c ∧ d := and.elim H₁ (assume Ha : a, assume Hb : b, and.intro (H₂ Ha) (H₃ Hb)) theorem and_of_and_of_imp_left (H₁ : a ∧ c) (H : a → b) : b ∧ c := and.elim H₁ (assume Ha : a, assume Hc : c, and.intro (H Ha) Hc) theorem and_of_and_of_imp_right (H₁ : c ∧ a) (H : a → b) : c ∧ b := and.elim H₁ (assume Hc : c, assume Ha : a, and.intro Hc (H Ha)) theorem and.comm : a ∧ b ↔ b ∧ a := iff.intro (λH, and.swap H) (λH, and.swap H) theorem and.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := iff.intro (assume H, and.intro (and.elim_left (and.elim_left H)) (and.intro (and.elim_right (and.elim_left H)) (and.elim_right H))) (assume H, and.intro (and.intro (and.elim_left H) (and.elim_left (and.elim_right H))) (and.elim_right (and.elim_right H))) /- or -/ definition not_or (Hna : ¬a) (Hnb : ¬b) : ¬(a ∨ b) := assume H : a ∨ b, or.rec_on H (assume Ha, absurd Ha Hna) (assume Hb, absurd Hb Hnb) theorem or_of_or_of_imp_of_imp (H₁ : a ∨ b) (H₂ : a → c) (H₃ : b → d) : c ∨ d := or.elim H₁ (assume Ha : a, or.inl (H₂ Ha)) (assume Hb : b, or.inr (H₃ Hb)) theorem or_of_or_of_imp_left (H₁ : a ∨ c) (H : a → b) : b ∨ c := or.elim H₁ (assume H₂ : a, or.inl (H H₂)) (assume H₂ : c, or.inr H₂) theorem or_of_or_of_imp_right (H₁ : c ∨ a) (H : a → b) : c ∨ b := or.elim H₁ (assume H₂ : c, or.inl H₂) (assume H₂ : a, or.inr (H H₂)) theorem or.elim3 (H : a ∨ b ∨ c) (Ha : a → d) (Hb : b → d) (Hc : c → d) : d := or.elim H Ha (assume H₂, or.elim H₂ Hb Hc) theorem or_resolve_right (H₁ : a ∨ b) (H₂ : ¬a) : b := or.elim H₁ (assume Ha, absurd Ha H₂) (assume Hb, Hb) theorem or_resolve_left (H₁ : a ∨ b) (H₂ : ¬b) : a := or.elim H₁ (assume Ha, Ha) (assume Hb, absurd Hb H₂) theorem or.swap (H : a ∨ b) : b ∨ a := or.elim H (assume Ha, or.inr Ha) (assume Hb, or.inl Hb) theorem or.comm : a ∨ b ↔ b ∨ a := iff.intro (λH, or.swap H) (λH, or.swap H) theorem or.assoc : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) := iff.intro (assume H, or.elim H (assume H₁, or.elim H₁ (assume Ha, or.inl Ha) (assume Hb, or.inr (or.inl Hb))) (assume Hc, or.inr (or.inr Hc))) (assume H, or.elim H (assume Ha, (or.inl (or.inl Ha))) (assume H₁, or.elim H₁ (assume Hb, or.inl (or.inr Hb)) (assume Hc, or.inr Hc))) /- iff -/ definition iff.def : (a ↔ b) = ((a → b) ∧ (b → a)) := !eq.refl /- exists_unique -/ definition exists_unique {A : Type} (p : A → Prop) := ∃x, p x ∧ ∀y, p y → y = x notation `∃!` binders `,` r:(scoped P, exists_unique P) := r theorem exists_unique.intro {A : Type} {p : A → Prop} (w : A) (H1 : p w) (H2 : ∀y, p y → y = w) : ∃!x, p x := exists.intro w (and.intro H1 H2) theorem exists_unique.elim {A : Type} {p : A → Prop} {b : Prop} (H2 : ∃!x, p x) (H1 : ∀x, p x → (∀y, p y → y = x) → b) : b := obtain w Hw, from H2, H1 w (and.elim_left Hw) (and.elim_right Hw) /- if-then-else -/ section open eq.ops variables {A : Type} {c₁ c₂ : Prop} definition if_true (t e : A) : (if true then t else e) = t := if_pos trivial definition if_false (t e : A) : (if false then t else e) = e := if_neg not_false theorem if_congr_cond [H₁ : decidable c₁] [H₂ : decidable c₂] (Heq : c₁ ↔ c₂) (t e : A) : (if c₁ then t else e) = (if c₂ then t else e) := decidable.rec_on H₁ (λ Hc₁ : c₁, decidable.rec_on H₂ (λ Hc₂ : c₂, if_pos Hc₁ ⬝ (if_pos Hc₂)⁻¹) (λ Hnc₂ : ¬c₂, absurd (iff.elim_left Heq Hc₁) Hnc₂)) (λ Hnc₁ : ¬c₁, decidable.rec_on H₂ (λ Hc₂ : c₂, absurd (iff.elim_right Heq Hc₂) Hnc₁) (λ Hnc₂ : ¬c₂, if_neg Hnc₁ ⬝ (if_neg Hnc₂)⁻¹)) theorem if_congr_aux [H₁ : decidable c₁] [H₂ : decidable c₂] {t₁ t₂ e₁ e₂ : A} (Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) : (if c₁ then t₁ else e₁) = (if c₂ then t₂ else e₂) := Ht ▸ He ▸ (if_congr_cond Hc t₁ e₁) theorem if_congr [H₁ : decidable c₁] {t₁ t₂ e₁ e₂ : A} (Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) : (if c₁ then t₁ else e₁) = (@ite c₂ (decidable_of_decidable_of_iff H₁ Hc) A t₂ e₂) := assert H2 : decidable c₂, from (decidable_of_decidable_of_iff H₁ Hc), if_congr_aux Hc Ht He end
3297149b31e0e3b3d5c7cdda28fc05a0362ffd79
206422fb9edabf63def0ed2aa3f489150fb09ccb
/src/field_theory/fixed.lean
bf33b04f002961aaca97ff1ed3427efaaf9a770e
[ "Apache-2.0" ]
permissive
hamdysalah1/mathlib
b915f86b2503feeae268de369f1b16932321f097
95454452f6b3569bf967d35aab8d852b1ddf8017
refs/heads/master
1,677,154,116,545
1,611,797,994,000
1,611,797,994,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,491
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.polynomial.group_ring_action import deprecated.subfield import field_theory.normal import field_theory.separable import field_theory.tower import linear_algebra.matrix import ring_theory.polynomial /-! # Fixed field under a group action. This is the basis of the Fundamental Theorem of Galois Theory. Given a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of `G`. This subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F` then `findim (fixed_points G F) F = fintype.card G`. ## Main Definitions - `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of `G`, where `G` is a group that acts on `F`. -/ noncomputable theory open_locale classical big_operators open mul_action finset finite_dimensional universes u v w variables (G : Type u) [group G] (F : Type v) [field F] [mul_semiring_action G F] (g : G) instance fixed_by.is_subfield : is_subfield (fixed_by G F g) := { zero_mem := smul_zero g, add_mem := λ x y hx hy, (smul_add g x y).trans $ congr_arg2 _ hx hy, neg_mem := λ x hx, (smul_neg g x).trans $ congr_arg _ hx, one_mem := smul_one g, mul_mem := λ x y hx hy, (smul_mul' g x y).trans $ congr_arg2 _ hx hy, inv_mem := λ x hx, (smul_inv F g x).trans $ congr_arg _ hx } namespace fixed_points instance : is_subfield (fixed_points G F) := by convert @is_subfield.Inter F _ G (fixed_by G F) _; rw fixed_eq_Inter_fixed_by instance : is_invariant_subring G (fixed_points G F) := { smul_mem := λ g x hx g', by rw [hx, hx] } @[simp] theorem smul (g : G) (x : fixed_points G F) : g • x = x := subtype.eq $ x.2 g -- Why is this so slow? @[simp] theorem smul_polynomial (g : G) (p : polynomial (fixed_points G F)) : g • p = p := polynomial.induction_on p (λ x, by rw [polynomial.smul_C, smul]) (λ p q ihp ihq, by rw [smul_add, ihp, ihq]) (λ n x ih, by rw [smul_mul', polynomial.smul_C, smul, smul_pow, polynomial.smul_X]) instance : algebra (fixed_points G F) F := algebra.of_is_subring _ theorem coe_algebra_map : algebra_map (fixed_points G F) F = is_subring.subtype (fixed_points G F) := rfl lemma linear_independent_smul_of_linear_independent {s : finset F} : linear_independent (fixed_points G F) (λ i : (↑s : set F), (i : F)) → linear_independent F (λ i : (↑s : set F), mul_action.to_fun G F i) := begin refine finset.induction_on s (λ _, linear_independent_empty_type $ λ ⟨x⟩, x.2) (λ a s has ih hs, _), rw coe_insert at hs ⊢, rw linear_independent_insert (mt mem_coe.1 has) at hs, rw linear_independent_insert' (mt mem_coe.1 has), refine ⟨ih hs.1, λ ha, _⟩, rw finsupp.mem_span_iff_total at ha, rcases ha with ⟨l, hl, hla⟩, rw [finsupp.total_apply_of_mem_supported F hl] at hla, suffices : ∀ i ∈ s, l i ∈ fixed_points G F, { replace hla := (sum_apply _ _ (λ i, l i • to_fun G F i)).symm.trans (congr_fun hla 1), simp_rw [pi.smul_apply, to_fun_apply, one_smul] at hla, refine hs.2 (hla ▸ submodule.sum_mem _ (λ c hcs, _)), change (⟨l c, this c hcs⟩ : fixed_points G F) • c ∈ _, exact submodule.smul_mem _ _ (submodule.subset_span $ mem_coe.2 hcs) }, intros i his g, refine eq_of_sub_eq_zero (linear_independent_iff'.1 (ih hs.1) s.attach (λ i, g • l i - l i) _ ⟨i, his⟩ (mem_attach _ _) : _), refine (@sum_attach _ _ s _ (λ i, (g • l i - l i) • (to_fun G F) i)).trans _, ext g', dsimp only, conv_lhs { rw sum_apply, congr, skip, funext, rw [pi.smul_apply, sub_smul, smul_eq_mul] }, rw [sum_sub_distrib, pi.zero_apply, sub_eq_zero], conv_lhs { congr, skip, funext, rw [to_fun_apply, ← mul_inv_cancel_left g g', mul_smul, ← smul_mul', ← to_fun_apply _ x] }, show ∑ x in s, g • (λ y, l y • to_fun G F y) x (g⁻¹ * g') = ∑ x in s, (λ y, l y • to_fun G F y) x g', rw [← smul_sum, ← sum_apply _ _ (λ y, l y • to_fun G F y), ← sum_apply _ _ (λ y, l y • to_fun G F y)], dsimp only, rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left] end variables [fintype G] (x : F) /-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/ def minpoly : polynomial (fixed_points G F) := (prod_X_sub_smul G F x).to_subring _ $ λ c hc g, let ⟨hc0, n, hn⟩ := finsupp.mem_frange.1 hc in hn ▸ prod_X_sub_smul.coeff G F x g n namespace minpoly theorem monic : (minpoly G F x).monic := subtype.eq $ prod_X_sub_smul.monic G F x theorem eval₂ : polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x (minpoly G F x) = 0 := begin rw [← prod_X_sub_smul.eval G F x, polynomial.eval₂_eq_eval_map], simp [minpoly], end theorem ne_one : minpoly G F x ≠ (1 : polynomial (fixed_points G F)) := λ H, have _ := eval₂ G F x, (one_ne_zero : (1 : F) ≠ 0) $ by rwa [H, polynomial.eval₂_one] at this theorem of_eval₂ (f : polynomial (fixed_points G F)) (hf : polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x f = 0) : minpoly G F x ∣ f := begin rw [← polynomial.map_dvd_map' (is_subring.subtype $ fixed_points G F), minpoly, polynomial.map_to_subring, prod_X_sub_smul], refine fintype.prod_dvd_of_coprime (polynomial.pairwise_coprime_X_sub $ mul_action.injective_of_quotient_stabilizer G x) (λ y, quotient_group.induction_on y $ λ g, _), rw [polynomial.dvd_iff_is_root, polynomial.is_root.def, mul_action.of_quotient_stabilizer_mk, polynomial.eval_smul', ← is_invariant_subring.coe_subtype_hom' G (fixed_points G F), ← mul_semiring_action_hom.coe_polynomial, ← mul_semiring_action_hom.map_smul, smul_polynomial, mul_semiring_action_hom.coe_polynomial, is_invariant_subring.coe_subtype_hom', polynomial.eval_map, hf, smul_zero] end /- Why is this so slow? -/ theorem irreducible_aux (f g : polynomial (fixed_points G F)) (hf : f.monic) (hg : g.monic) (hfg : f * g = minpoly G F x) : f = 1 ∨ g = 1 := begin have hf2 : f ∣ minpoly G F x, { rw ← hfg, exact dvd_mul_right _ _ }, have hg2 : g ∣ minpoly G F x, { rw ← hfg, exact dvd_mul_left _ _ }, have := eval₂ G F x, rw [← hfg, polynomial.eval₂_mul, mul_eq_zero] at this, cases this, { right, have hf3 : f = minpoly G F x, { exact polynomial.eq_of_monic_of_associated hf (monic G F x) (associated_of_dvd_dvd hf2 $ @of_eval₂ G _ F _ _ _ x f this) }, rwa [← mul_one (minpoly G F x), hf3, mul_right_inj' (monic G F x).ne_zero] at hfg }, { left, have hg3 : g = minpoly G F x, { exact polynomial.eq_of_monic_of_associated hg (monic G F x) (associated_of_dvd_dvd hg2 $ @of_eval₂ G _ F _ _ _ x g this) }, rwa [← one_mul (minpoly G F x), hg3, mul_left_inj' (monic G F x).ne_zero] at hfg } end theorem irreducible : irreducible (minpoly G F x) := (polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x) end minpoly theorem is_integral : is_integral (fixed_points G F) x := ⟨minpoly G F x, minpoly.monic G F x, minpoly.eval₂ G F x⟩ theorem minpoly_eq_minpoly : minpoly G F x = _root_.minpoly (fixed_points G F) x := minpoly.unique' (is_integral G F x) (minpoly.irreducible G F x) (minpoly.eval₂ G F x) (minpoly.monic G F x) instance normal : normal (fixed_points G F) F := λ x, ⟨is_integral G F x, (polynomial.splits_id_iff_splits _).1 $ by { rw [← minpoly_eq_minpoly, minpoly, coe_algebra_map, polynomial.map_to_subring, prod_X_sub_smul], exact polynomial.splits_prod _ (λ _ _, polynomial.splits_X_sub_C _) }⟩ instance separable : is_separable (fixed_points G F) F := λ x, ⟨is_integral G F x, by { rw [← minpoly_eq_minpoly, ← polynomial.separable_map (is_subring.subtype (fixed_points G F)), minpoly, polynomial.map_to_subring], exact polynomial.separable_prod_X_sub_C_iff.2 (injective_of_quotient_stabilizer G x) }⟩ lemma dim_le_card : vector_space.dim (fixed_points G F) F ≤ fintype.card G := begin refine dim_le (λ s hs, cardinal.nat_cast_le.1 _), rw [← @dim_fun' F G, ← cardinal.lift_nat_cast.{v (max u v)}, cardinal.finset_card, ← cardinal.lift_id (vector_space.dim F (G → F))], exact linear_independent_le_dim'.{_ _ _ (max u v)} (linear_independent_smul_of_linear_independent G F hs) end instance : finite_dimensional (fixed_points G F) F := finite_dimensional.finite_dimensional_iff_dim_lt_omega.2 $ lt_of_le_of_lt (dim_le_card G F) (cardinal.nat_lt_omega _) lemma findim_le_card : findim (fixed_points G F) F ≤ fintype.card G := by exact_mod_cast trans_rel_right (≤) (findim_eq_dim _ _) (dim_le_card G F) end fixed_points lemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w) [comm_semiring R] [integral_domain A] [algebra R A] [integral_domain B] [algebra R B] : linear_independent B (alg_hom.to_linear_map : (A →ₐ[R] B) → (A →ₗ[R] B)) := have linear_independent B (linear_map.lto_fun R A B ∘ alg_hom.to_linear_map), from ((linear_independent_monoid_hom A B).comp (coe : (A →ₐ[R] B) → (A →* B)) (λ f g hfg, alg_hom.ext $ monoid_hom.ext_iff.1 hfg) : _), this.of_comp _ lemma cardinal_mk_alg_hom (K : Type u) (V : Type v) (W : Type w) [field K] [field V] [algebra K V] [finite_dimensional K V] [field W] [algebra K W] [finite_dimensional K W] : cardinal.mk (V →ₐ[K] W) ≤ findim W (V →ₗ[K] W) := cardinal_mk_le_findim_of_linear_independent $ linear_independent_to_linear_map K V W noncomputable instance alg_hom.fintype (K : Type u) (V : Type v) (W : Type w) [field K] [field V] [algebra K V] [finite_dimensional K V] [field W] [algebra K W] [finite_dimensional K W] : fintype (V →ₐ[K] W) := classical.choice $ cardinal.lt_omega_iff_fintype.1 $ lt_of_le_of_lt (cardinal_mk_alg_hom K V W) (cardinal.nat_lt_omega _) noncomputable instance alg_equiv.fintype (K : Type u) (V : Type v) [field K] [field V] [algebra K V] [finite_dimensional K V] : fintype (V ≃ₐ[K] V) := fintype.of_equiv (V →ₐ[K] V) (alg_equiv_equiv_alg_hom K V).symm lemma findim_alg_hom (K : Type u) (V : Type v) [field K] [field V] [algebra K V] [finite_dimensional K V] : fintype.card (V →ₐ[K] V) ≤ findim V (V →ₗ[K] V) := fintype_card_le_findim_of_linear_independent $ linear_independent_to_linear_map K V V namespace fixed_points /-- Embedding produced from a faithful action. -/ @[simps apply {fully_applied := ff}] def to_alg_hom (G : Type u) (F : Type v) [group G] [field F] [faithful_mul_semiring_action G F] : G ↪ (F →ₐ[fixed_points G F] F) := { to_fun := λ g, { commutes' := λ x, x.2 g, .. mul_semiring_action.to_semiring_hom G F g }, inj' := λ g₁ g₂ hg, injective_to_semiring_hom G F $ ring_hom.ext $ λ x, alg_hom.ext_iff.1 hg x, } lemma to_alg_hom_apply_apply {G : Type u} {F : Type v} [group G] [field F] [faithful_mul_semiring_action G F] (g : G) (x : F) : to_alg_hom G F g x = g • x := rfl theorem findim_eq_card (G : Type u) (F : Type v) [group G] [field F] [fintype G] [faithful_mul_semiring_action G F] : findim (fixed_points G F) F = fintype.card G := le_antisymm (fixed_points.findim_le_card G F) $ calc fintype.card G ≤ fintype.card (F →ₐ[fixed_points G F] F) : fintype.card_le_of_injective _ (to_alg_hom G F).2 ... ≤ findim F (F →ₗ[fixed_points G F] F) : findim_alg_hom (fixed_points G F) F ... = findim (fixed_points G F) F : findim_linear_map' _ _ _ theorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F] [fintype G] [faithful_mul_semiring_action G F] : function.bijective (to_alg_hom G F) := begin rw fintype.bijective_iff_injective_and_card, split, { exact (to_alg_hom G F).injective }, { apply le_antisymm, { exact fintype.card_le_of_injective _ (to_alg_hom G F).injective }, { rw ← findim_eq_card G F, exact has_le.le.trans_eq (findim_alg_hom _ F) (findim_linear_map' _ _ _) } }, end /-- Bijection between G and algebra homomorphisms that fix the fixed points -/ def to_alg_hom_equiv (G : Type u) (F : Type v) [group G] [field F] [fintype G] [faithful_mul_semiring_action G F] : G ≃ (F →ₐ[fixed_points G F] F) := function.embedding.equiv_of_surjective (to_alg_hom G F) (to_alg_hom_bijective G F).2 end fixed_points
f0fb63643420bd8b620fe533606d74a8835af85f
4727251e0cd73359b15b664c3170e5d754078599
/test/simps.lean
4acea987d25b8e8383fe00fc4cdec2a41c64599e
[ "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
35,918
lean
import algebra.hom.group import data.sum.basic import tactic.simps universes v u w -- set_option trace.simps.verbose true -- set_option trace.simps.debug true -- set_option trace.app_builder true open function tactic expr structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) (left_inv : left_inverse inv_fun to_fun) (right_inv : right_inverse inv_fun to_fun) local infix ` ≃ `:25 := equiv /- Since `prod` and `pprod` are a special case for `@[simps]`, we define a new structure to test the basic functionality.-/ structure my_prod (α β : Type*) := (fst : α) (snd : β) def myprod.map {α α' β β'} (f : α → α') (g : β → β') (x : my_prod α β) : my_prod α' β' := ⟨f x.1, g x.2⟩ namespace foo @[simps] protected def rfl {α} : α ≃ α := ⟨id, λ x, x, λ x, rfl, λ x, rfl⟩ /- simps adds declarations -/ run_cmd do e ← get_env, e.get `foo.rfl_to_fun, e.get `foo.rfl_inv_fun, success_if_fail (e.get `foo.rfl_left_inv), success_if_fail (e.get `foo.rfl_right_inv) example (n : ℕ) : foo.rfl.to_fun n = n := by rw [foo.rfl_to_fun, id] example (n : ℕ) : foo.rfl.inv_fun n = n := by rw [foo.rfl_inv_fun] /- the declarations are `simp` lemmas -/ @[simps] def foo : ℕ × ℤ := (1, 2) example : foo.1 = 1 := by simp example : foo.2 = 2 := by simp example : foo.1 = 1 := by { dsimp, refl } -- check that dsimp also unfolds example : foo.2 = 2 := by { dsimp, refl } example {α} (x : α) : foo.rfl.to_fun x = x := by simp example {α} (x : α) : foo.rfl.inv_fun x = x := by simp example {α} (x : α) : foo.rfl.to_fun = @id α := by { success_if_fail {simp}, refl } /- check some failures -/ def bar1 : ℕ := 1 -- type is not a structure noncomputable def bar2 {α} : α ≃ α := classical.choice ⟨foo.rfl⟩ run_cmd do success_if_fail_with_msg (simps_tac `foo.bar1) "Invalid `simps` attribute. Target nat is not a structure", success_if_fail_with_msg (simps_tac `foo.bar2) "Invalid `simps` attribute. The body is not a constructor application: classical.choice bar2._proof_1", e ← get_env, let nm := `foo.bar1, d ← e.get nm, let lhs : expr := const d.to_name (d.univ_params.map level.param), simps_add_projections e nm d.type lhs d.value [] d.univ_params ff {} [] [] /- test that if a non-constructor is given as definition, then `{rhs_md := semireducible, simp_rhs := tt}` is applied automatically. -/ @[simps] def rfl2 {α} : α ≃ α := foo.rfl example {α} (x : α) : rfl2.to_fun x = x ∧ rfl2.inv_fun x = x := begin dsimp only [rfl2_to_fun, rfl2_inv_fun], guard_target (x = x ∧ x = x), exact ⟨rfl, rfl⟩ end /- test `fully_applied` option -/ @[simps {fully_applied := ff}] def rfl3 {α} : α ≃ α := ⟨id, λ x, x, λ x, rfl, λ x, rfl⟩ end foo /- we reduce the type when applying [simps] -/ def my_equiv := equiv @[simps] def baz : my_equiv ℕ ℕ := ⟨id, λ x, x, λ x, rfl, λ x, rfl⟩ /- test name clashes -/ def name_clash_fst := 1 def name_clash_snd := 1 def name_clash_snd_2 := 1 @[simps] def name_clash := (2, 3) run_cmd do e ← get_env, e.get `name_clash_fst_2, e.get `name_clash_snd_3 /- check projections for nested structures -/ namespace count_nested @[simps {attrs := [`simp, `norm]}] def nested1 : my_prod ℕ $ my_prod ℤ ℕ := ⟨2, -1, 1⟩ @[simps {attrs := []}] def nested2 : ℕ × my_prod ℕ ℕ := ⟨2, myprod.map nat.succ nat.pred ⟨1, 2⟩⟩ end count_nested run_cmd do e ← get_env, e.get `count_nested.nested1_fst, e.get `count_nested.nested1_snd_fst, e.get `count_nested.nested1_snd_snd, e.get `count_nested.nested2_fst, e.get `count_nested.nested2_snd, is_simp_lemma `count_nested.nested1_fst >>= λ b, guard b, -- simp attribute is global is_simp_lemma `count_nested.nested2_fst >>= λ b, guard $ ¬b, --lemmas_only doesn't add simp lemma guard $ 7 = e.fold 0 -- there are no other lemmas generated (λ d n, n + if d.to_name.components.init.ilast = `count_nested then 1 else 0) -- testing with arguments @[simps] def bar {α : Type*} (n m : ℕ) : ℕ × ℤ := ⟨n - m, n + m⟩ structure equiv_plus_data (α β) extends α ≃ β := (P : (α → β) → Prop) (data : P to_fun) structure automorphism_plus_data α extends α ⊕ α ≃ α ⊕ α := (P : (α ⊕ α → α ⊕ α) → Prop) (data : P to_fun) (extra : bool → my_prod ℕ ℕ) @[simps] def refl_with_data {α} : equiv_plus_data α α := { P := λ f, f = id, data := rfl, ..foo.rfl } @[simps] def refl_with_data' {α} : equiv_plus_data α α := { P := λ f, f = id, data := rfl, to_equiv := foo.rfl } /- test whether eta expansions are reduced correctly -/ @[simps] def test {α} : automorphism_plus_data α := { P := λ f, f = id, data := rfl, extra := λ b, ⟨(⟨3, 5⟩ : my_prod _ _).1, (⟨3, 5⟩ : my_prod _ _).2⟩, ..foo.rfl } /- test whether this is indeed rejected as a valid eta expansion -/ @[simps] def test_sneaky {α} : automorphism_plus_data α := { P := λ f, f = id, data := rfl, extra := λ b, ⟨(3,5).1,(3,5).2⟩, ..foo.rfl } run_cmd do e ← get_env, e.get `refl_with_data_to_equiv, e.get `refl_with_data'_to_equiv, e.get `test_extra, e.get `test_sneaky_extra_fst, success_if_fail (e.get `refl_with_data_to_equiv_to_fun), success_if_fail (e.get `refl_with_data'_to_equiv_to_fun), success_if_fail (e.get `test_extra_fst), success_if_fail (e.get `test_sneaky_extra) structure partially_applied_str := (data : ℕ → my_prod ℕ ℕ) /- if we have a partially applied constructor, we treat it as if it were eta-expanded -/ @[simps] def partially_applied_term : partially_applied_str := ⟨my_prod.mk 3⟩ @[simps] def another_term : partially_applied_str := ⟨λ n, ⟨n + 1, n + 2⟩⟩ run_cmd do e ← get_env, e.get `partially_applied_term_data_fst, e.get `partially_applied_term_data_snd structure very_partially_applied_str := (data : ∀β, ℕ → β → my_prod ℕ β) /- if we have a partially applied constructor, we treat it as if it were eta-expanded. (this is not very useful, and we could remove this behavior if convenient) -/ @[simps] def very_partially_applied_term : very_partially_applied_str := ⟨@my_prod.mk ℕ⟩ run_cmd do e ← get_env, e.get `very_partially_applied_term_data_fst, e.get `very_partially_applied_term_data_snd @[simps] def let1 : ℕ × ℤ := let n := 3 in ⟨n + 4, 5⟩ @[simps] def let2 : ℕ × ℤ := let n := 3, m := 4 in let k := 5 in ⟨n + m, k⟩ @[simps] def let3 : ℕ → ℕ × ℤ := λ n, let m := 4, k := 5 in ⟨n + m, k⟩ @[simps] def let4 : ℕ → ℕ × ℤ := let m := 4, k := 5 in λ n, ⟨n + m, k⟩ run_cmd do e ← get_env, e.get `let1_fst, e.get `let2_fst, e.get `let3_fst, e.get `let4_fst, e.get `let1_snd, e.get `let2_snd, e.get `let3_snd, e.get `let4_snd namespace specify @[simps fst] def specify1 : ℕ × ℕ × ℕ := (1, 2, 3) @[simps snd] def specify2 : ℕ × ℕ × ℕ := (1, 2, 3) @[simps snd_fst] def specify3 : ℕ × ℕ × ℕ := (1, 2, 3) @[simps snd snd_snd snd_snd] def specify4 : ℕ × ℕ × ℕ := (1, 2, 3) -- last argument is ignored @[simps] noncomputable def specify5 : ℕ × ℕ × ℕ := (1, classical.choice ⟨(2, 3)⟩) end specify run_cmd do e ← get_env, e.get `specify.specify1_fst, e.get `specify.specify2_snd, e.get `specify.specify3_snd_fst, e.get `specify.specify4_snd_snd, e.get `specify.specify4_snd, e.get `specify.specify5_fst, e.get `specify.specify5_snd, guard $ 12 = e.fold 0 -- there are no other lemmas generated (λ d n, n + if d.to_name.components.init.ilast = `specify then 1 else 0), success_if_fail_with_msg (simps_tac `specify.specify1 {} ["fst_fst"]) "Invalid simp lemma specify.specify1_fst_fst. Projection fst doesn't exist, because target is not a structure.", success_if_fail_with_msg (simps_tac `specify.specify1 {} ["foo_fst"]) "Invalid simp lemma specify.specify1_foo_fst. Structure prod does not have projection foo. The known projections are: [fst, snd] You can also see this information by running `initialize_simps_projections? prod`. Note: these projection names might not correspond to the projection names of the structure.", success_if_fail_with_msg (simps_tac `specify.specify1 {} ["snd_bar"]) "Invalid simp lemma specify.specify1_snd_bar. Structure prod does not have projection bar. The known projections are: [fst, snd] You can also see this information by running `initialize_simps_projections? prod`. Note: these projection names might not correspond to the projection names of the structure.", success_if_fail_with_msg (simps_tac `specify.specify5 {} ["snd_snd"]) "Invalid simp lemma specify.specify5_snd_snd. The given definition is not a constructor application: classical.choice specify.specify5._proof_1" /- We also eta-reduce if we explicitly specify the projection. -/ attribute [simps extra] test run_cmd do e ← get_env, d1 ← e.get `test_extra, d2 ← e.get `test_extra_2, guard $ d1.type =ₐ d2.type, skip /- check simp_rhs option -/ @[simps {simp_rhs := tt}] def equiv.trans {α β γ} (f : α ≃ β) (g : β ≃ γ) : α ≃ γ := ⟨g.to_fun ∘ f.to_fun, f.inv_fun ∘ g.inv_fun, by { intro x, simp [equiv.left_inv _ _] }, by { intro x, simp [equiv.right_inv _ _] }⟩ example {α β γ : Type} (f : α ≃ β) (g : β ≃ γ) (x : α) : (f.trans g).to_fun x = (f.trans g).to_fun x := begin dsimp only [equiv.trans_to_fun], guard_target g.to_fun (f.to_fun x) = g.to_fun (f.to_fun x), refl, end local attribute [simp] nat.zero_add nat.one_mul nat.mul_one @[simps {simp_rhs := tt}] def my_nat_equiv : ℕ ≃ ℕ := ⟨λ n, 0 + n, λ n, 1 * n * 1, by { intro n, simp }, by { intro n, simp }⟩ run_cmd success_if_fail (has_attribute `_refl_lemma `my_nat_equiv_to_fun) >> has_attribute `_refl_lemma `equiv.trans_to_fun example (n : ℕ) : my_nat_equiv.to_fun (my_nat_equiv.to_fun $ my_nat_equiv.inv_fun n) = n := by { success_if_fail { refl }, simp only [my_nat_equiv_to_fun, my_nat_equiv_inv_fun] } @[simps {simp_rhs := tt}] def succeed_without_simplification_possible : ℕ ≃ ℕ := ⟨λ n, n, λ n, n, by { intro n, refl }, by { intro n, refl }⟩ /- test that we don't recursively take projections of `prod` and `pprod` -/ @[simps] def pprod_equiv_prod : pprod ℕ ℕ ≃ ℕ × ℕ := { to_fun := λ x, ⟨x.1, x.2⟩, inv_fun := λ x, ⟨x.1, x.2⟩, left_inv := λ ⟨x, y⟩, rfl, right_inv := λ ⟨x, y⟩, rfl } run_cmd do e ← get_env, e.get `pprod_equiv_prod_to_fun, e.get `pprod_equiv_prod_inv_fun attribute [simps to_fun_fst inv_fun_snd] pprod_equiv_prod run_cmd do e ← get_env, e.get `pprod_equiv_prod_to_fun_fst, e.get `pprod_equiv_prod_inv_fun_snd -- we can disable this behavior with the option `not_recursive`. @[simps {not_recursive := []}] def pprod_equiv_prod2 : pprod ℕ ℕ ≃ ℕ × ℕ := pprod_equiv_prod run_cmd do e ← get_env, e.get `pprod_equiv_prod2_to_fun_fst, e.get `pprod_equiv_prod2_to_fun_snd, e.get `pprod_equiv_prod2_inv_fun_fst, e.get `pprod_equiv_prod2_inv_fun_snd /- Tests with universe levels -/ class has_hom (obj : Type u) : Type (max u (v+1)) := (hom : obj → obj → Type v) infixr ` ⟶ `:10 := has_hom.hom -- type as \h class category_struct (obj : Type u) extends has_hom.{v} obj : Type (max u (v+1)) := (id : Π X : obj, hom X X) (comp : Π {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z)) notation `𝟙` := category_struct.id -- type as \b1 infixr ` ≫ `:80 := category_struct.comp -- type as \gg @[simps] instance types : category_struct (Type u) := { hom := λ a b, (a → b), id := λ a, id, comp := λ _ _ _ f g, g ∘ f } example (X : Type u) : (X ⟶ X) = (X → X) := by simp example (X : Type u) : 𝟙 X = (λ x, x) := by { funext, simp } example (X Y Z : Type u) (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = g ∘ f := by { funext, simp } namespace coercing structure foo_str := (c : Type) (x : c) instance : has_coe_to_sort foo_str Type := ⟨foo_str.c⟩ @[simps] def foo : foo_str := ⟨ℕ, 3⟩ @[simps] def foo2 : foo_str := ⟨ℕ, 34⟩ example : ↥foo = ℕ := by simp only [foo_c] example : foo.x = (3 : ℕ) := by simp only [foo_x] structure voo_str (n : ℕ) := (c : Type) (x : c) instance has_coe_voo_str (n : ℕ) : has_coe_to_sort (voo_str n) Type := ⟨voo_str.c⟩ @[simps] def voo : voo_str 7 := ⟨ℕ, 3⟩ @[simps] def voo2 : voo_str 4 := ⟨ℕ, 34⟩ example : ↥voo = ℕ := by simp only [voo_c] example : voo.x = (3 : ℕ) := by simp only [voo_x] structure equiv2 (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) (left_inv : left_inverse inv_fun to_fun) (right_inv : right_inverse inv_fun to_fun) instance {α β} : has_coe_to_fun (equiv2 α β) (λ _, α → β) := ⟨equiv2.to_fun⟩ @[simps] protected def rfl2 {α} : equiv2 α α := ⟨λ x, x, λ x, x, λ x, rfl, λ x, rfl⟩ example {α} (x : α) : coercing.rfl2 x = x := by rw [coercing.rfl2_to_fun] example {α} (x : α) : coercing.rfl2 x = x := by simp example {α} (x : α) : coercing.rfl2.inv_fun x = x := by simp @[simps] protected def equiv2.symm {α β} (f : equiv2 α β) : equiv2 β α := ⟨f.inv_fun, f, f.right_inv, f.left_inv⟩ @[simps] protected def equiv2.symm2 {α β} (f : equiv2 α β) : equiv2 β α := ⟨f.inv_fun, f.to_fun, f.right_inv, f.left_inv⟩ @[simps {fully_applied := ff}] protected def equiv2.symm3 {α β} (f : equiv2 α β) : equiv2 β α := ⟨f.inv_fun, f, f.right_inv, f.left_inv⟩ example {α β} (f : equiv2 α β) (y : β) : f.symm y = f.inv_fun y := by simp example {α β} (f : equiv2 α β) (x : α) : f.symm.inv_fun x = f x := by simp example {α β} (f : equiv2 α β) : f.symm.inv_fun = f := by { success_if_fail {simp}, refl } example {α β} (f : equiv2 α β) : f.symm3.inv_fun = f := by simp section set_option old_structure_cmd true class semigroup (G : Type u) extends has_mul G := (mul_assoc : ∀ a b c : G, a * b * c = a * (b * c)) end @[simps] instance {α β} [semigroup α] [semigroup β] : semigroup (α × β) := { mul := λ x y, (x.1 * y.1, x.2 * y.2), mul_assoc := by { intros, simp only [semigroup.mul_assoc], refl } } example {α β} [semigroup α] [semigroup β] (x y : α × β) : x * y = (x.1 * y.1, x.2 * y.2) := by simp example {α β} [semigroup α] [semigroup β] (x y : α × β) : (x * y).1 = x.1 * y.1 := by simp structure Semigroup := (G : Type*) (op : G → G → G) (infix * := op) (op_assoc : ∀ (x y z : G), (x * y) * z = x * (y * z)) namespace Group instance : has_coe_to_sort Semigroup Type* := ⟨Semigroup.G⟩ -- We could try to generate lemmas with this `has_mul` instance, but it is unused in mathlib. -- Therefore, this is ignored. instance (G : Semigroup) : has_mul G := ⟨G.op⟩ @[simps] def prod_Semigroup (G H : Semigroup) : Semigroup := { G := G × H, op := λ x y, (x.1 * y.1, x.2 * y.2), op_assoc := by { intros, dsimp [Group.has_mul], simp [Semigroup.op_assoc] }} end Group section set_option old_structure_cmd true class extending_stuff (G : Type u) extends has_mul G, has_zero G, has_neg G, has_subset G := (new_axiom : ∀ x : G, x * - 0 ⊆ - x) end @[simps] def bar : extending_stuff ℕ := { mul := (*), zero := 0, neg := nat.succ, subset := λ x y, true, new_axiom := λ x, trivial } section local attribute [instance] bar example (x : ℕ) : x * - 0 ⊆ - x := by simp end class new_extending_stuff (G : Type u) extends has_mul G, has_zero G, has_neg G, has_subset G := (new_axiom : ∀ x : G, x * - 0 ⊆ - x) @[simps] def new_bar : new_extending_stuff ℕ := { mul := (*), zero := 0, neg := nat.succ, subset := λ x y, true, new_axiom := λ x, trivial } section local attribute [instance] new_bar example (x : ℕ) : x * - 0 ⊆ - x := by simp end end coercing namespace manual_coercion structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := manual_coercion.equiv variables {α β γ : Sort*} instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ def equiv.simps.inv_fun (e : α ≃ β) : β → α := e.symm /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[simps {simp_rhs := tt}] protected def equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ example (e₁ : α ≃ β) (e₂ : β ≃ γ) (x : γ) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := by simp only [equiv.trans_inv_fun] end manual_coercion namespace faulty_manual_coercion structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := faulty_manual_coercion.equiv variables {α β γ : Sort*} /-- See Note [custom simps projection] -/ noncomputable def equiv.simps.inv_fun (e : α ≃ β) : β → α := classical.choice ⟨e.inv_fun⟩ run_cmd do e ← get_env, success_if_fail_with_msg (simps_get_raw_projections e `faulty_manual_coercion.equiv) "Invalid custom projection: λ {α : Sort u_1} {β : Sort u_2} (e : α ≃ β), classical.choice _ Expression is not definitionally equal to λ (α : Sort u_1) (β : Sort u_2) (x : α ≃ β), x.inv_fun" end faulty_manual_coercion namespace manual_initialize /- defining a manual coercion. -/ variables {α β γ : Sort*} structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := manual_initialize.equiv instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ -- test: intentionally using different unvierse levels for equiv.symm than for equiv def equiv.simps.inv_fun (e : α ≃ β) : β → α := e.symm initialize_simps_projections equiv run_cmd has_attribute `_simps_str `manual_initialize.equiv /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[simps {simp_rhs := tt}] protected def equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ end manual_initialize namespace faulty_universes variables {α β γ : Sort*} structure equiv (α : Sort u) (β : Sort v) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := faulty_universes.equiv instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ -- test: intentionally using different names for the universe variables for equiv.symm than for -- equiv def equiv.simps.inv_fun {α : Type u} {β : Type v} (e : α ≃ β) : β → α := e.symm run_cmd do e ← get_env, success_if_fail_with_msg (simps_get_raw_projections e `faulty_universes.equiv) "Invalid custom projection: λ {α : Type u} {β : Type v} (e : α ≃ β), ⇑(e.symm) Expression has different type than faulty_universes.equiv.inv_fun. Given type: Π {α : Type u} {β : Type v} (e : α ≃ β), (λ (_x : β ≃ α), β → α) e.symm Expected type: Π (α : Sort u) (β : Sort v), α ≃ β → β → α" end faulty_universes namespace manual_universes variables {α β γ : Sort*} structure equiv (α : Sort u) (β : Sort v) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := manual_universes.equiv instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ -- test: intentionally using different unvierse levels for equiv.symm than for equiv def equiv.simps.inv_fun {α : Sort w} {β : Sort u} (e : α ≃ β) : β → α := e.symm -- check whether we can generate custom projections even if the universe names don't match initialize_simps_projections equiv end manual_universes namespace manual_projection_names structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := manual_projection_names.equiv variables {α β γ : Sort*} instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ def equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply) run_cmd do e ← get_env, data ← simps_get_raw_projections e `manual_projection_names.equiv, guard $ data.2.map projection_data.name = [`apply, `symm_apply] @[simps {simp_rhs := tt}] protected def equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ example (e₁ : α ≃ β) (e₂ : β ≃ γ) (x : α) : (e₁.trans e₂) x = e₂ (e₁ x) := by simp only [equiv.trans_apply] example (e₁ : α ≃ β) (e₂ : β ≃ γ) (x : γ) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := by simp only [equiv.trans_symm_apply] -- the new projection names are parsed correctly (the old projection names won't work anymore) @[simps apply symm_apply] protected def equiv.trans2 (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ end manual_projection_names namespace prefix_projection_names structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := prefix_projection_names.equiv variables {α β γ : Sort*} instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ /-- See Note [custom simps projection] -/ def equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections equiv (to_fun → coe as_prefix, inv_fun → symm_apply) run_cmd do e ← get_env, data ← simps_get_raw_projections e `prefix_projection_names.equiv, guard $ data.2.map projection_data.name = [`coe, `symm_apply], guard $ data.2.map projection_data.is_prefix = [tt, ff] @[simps {simp_rhs := tt}] protected def equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ example (e₁ : α ≃ β) (e₂ : β ≃ γ) (x : α) : (e₁.trans e₂) x = e₂ (e₁ x) := by simp only [equiv.coe_trans] -- the new projection names are parsed correctly @[simps coe symm_apply] protected def equiv.trans2 (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩ -- it interacts somewhat well with multiple projections (though the generated name is not great) @[simps snd_coe_fst] def foo {α β γ δ : Type*} (x : α) (e₁ : α ≃ β) (e₂ : γ ≃ δ) : α × (α × γ ≃ β × δ) := ⟨x, prod.map e₁ e₂, prod.map e₁.symm e₂.symm⟩ example {α β γ δ : Type*} (x : α) (e₁ : α ≃ β) (e₂ : γ ≃ δ) (z : α × γ) : ((foo x e₁ e₂).2 z).1 = e₁ z.1 := by simp only [coe_foo_snd_fst] end prefix_projection_names -- test transparency setting structure set_plus (α : Type) := (s : set α) (x : α) (h : x ∈ s) @[simps] def nat_set_plus : set_plus ℕ := ⟨set.univ, 1, trivial⟩ example : nat_set_plus.s = set.univ := begin dsimp only [nat_set_plus_s], guard_target @set.univ ℕ = set.univ, refl end @[simps {type_md := semireducible}] def nat_set_plus2 : set_plus ℕ := ⟨set.univ, 1, trivial⟩ example : nat_set_plus2.s = set.univ := begin success_if_fail { dsimp only [nat_set_plus2_s] }, refl end @[simps {rhs_md := semireducible}] def nat_set_plus3 : set_plus ℕ := nat_set_plus example : nat_set_plus3.s = set.univ := begin dsimp only [nat_set_plus3_s], guard_target @set.univ ℕ = set.univ, refl end namespace nested_non_fully_applied structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) local infix ` ≃ `:25 := nested_non_fully_applied.equiv variables {α β γ : Sort*} @[simps] def equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun⟩ @[simps {rhs_md := semireducible, fully_applied := ff}] def equiv.symm2 : (α ≃ β) ≃ (β ≃ α) := ⟨equiv.symm, equiv.symm⟩ example (e : α ≃ β) : (equiv.symm2.inv_fun e).to_fun = e.inv_fun := begin dsimp only [equiv.symm2_inv_fun_to_fun], guard_target e.inv_fun = e.inv_fun, refl end /- do not prematurely unfold `equiv.symm`, unless necessary -/ @[simps to_fun to_fun_to_fun {rhs_md := semireducible}] def equiv.symm3 : (α ≃ β) ≃ (β ≃ α) := equiv.symm2 example (e : α ≃ β) (y : β) : (equiv.symm3.to_fun e).to_fun y = e.inv_fun y ∧ (equiv.symm3.to_fun e).to_fun y = e.inv_fun y := begin split, { dsimp only [equiv.symm3_to_fun], guard_target e.symm.to_fun y = e.inv_fun y, refl }, { dsimp only [equiv.symm3_to_fun_to_fun], guard_target e.inv_fun y = e.inv_fun y, refl } end end nested_non_fully_applied -- test that type classes which are props work class prop_class (n : ℕ) : Prop := (has_true : true) instance has_prop_class (n : ℕ) : prop_class n := ⟨trivial⟩ structure needs_prop_class (n : ℕ) [prop_class n] := (t : true) @[simps] def test_prop_class : needs_prop_class 1 := { t := trivial } /- check that when the coercion is given in eta-expanded form, we can also find the coercion. -/ structure alg_hom (R A B : Type*) := (to_fun : A → B) instance (R A B : Type*) : has_coe_to_fun (alg_hom R A B) (λ _, A → B) := ⟨λ f, f.to_fun⟩ @[simps] def my_alg_hom : alg_hom unit bool bool := { to_fun := id } example (x : bool) : my_alg_hom x = id x := by simp only [my_alg_hom_to_fun] structure ring_hom (A B : Type*) := (to_fun : A → B) instance (A B : Type*) : has_coe_to_fun (ring_hom A B) (λ _, A → B) := ⟨λ f, f.to_fun⟩ @[simps] def my_ring_hom : ring_hom bool bool := { to_fun := id } example (x : bool) : my_ring_hom x = id x := by simp only [my_ring_hom_to_fun] /- check interaction with the `@[to_additive]` attribute -/ @[to_additive, simps] instance {M N} [has_mul M] [has_mul N] : has_mul (M × N) := ⟨λ p q, ⟨p.1 * q.1, p.2 * q.2⟩⟩ run_cmd do get_decl `prod.has_mul_mul, get_decl `prod.has_add_add, has_attribute `to_additive `prod.has_mul, has_attribute `to_additive `prod.has_mul_mul, has_attribute `simp `prod.has_mul_mul, has_attribute `simp `prod.has_add_add example {M N} [has_mul M] [has_mul N] (p q : M × N) : p * q = ⟨p.1 * q.1, p.2 * q.2⟩ := by simp example {M N} [has_add M] [has_add N] (p q : M × N) : p + q = ⟨p.1 + q.1, p.2 + q.2⟩ := by simp /- The names of the generated simp lemmas for the additive version are not great if the definition had a custom additive name -/ @[to_additive my_add_instance, simps] instance my_instance {M N} [has_one M] [has_one N] : has_one (M × N) := ⟨(1, 1)⟩ run_cmd do get_decl `my_instance_one, get_decl `my_add_instance_zero, has_attribute `to_additive `my_instance, has_attribute `to_additive `my_instance_one, has_attribute `simp `my_instance_one, has_attribute `simp `my_add_instance_zero example {M N} [has_one M] [has_one N] : (1 : M × N) = ⟨1, 1⟩ := by simp example {M N} [has_zero M] [has_zero N] : (0 : M × N) = ⟨0, 0⟩ := by simp section /-! Test `dsimp, simp` with the option `simp_rhs` -/ local attribute [simp] nat.add structure my_type := (A : Type) @[simps {simp_rhs := tt}] def my_type_def : my_type := ⟨{ x : fin (nat.add 3 0) // 1 + 1 = 2 }⟩ example (h : false) (x y : { x : fin (nat.add 3 0) // 1 + 1 = 2 }) : my_type_def.A = unit := begin simp only [my_type_def_A], guard_target ({ x : fin 3 // true } = unit), /- note: calling only one of `simp` or `dsimp` does not produce the current target, as the following tests show. -/ success_if_fail { guard_hyp x : { x : fin 3 // true } }, dsimp at x, success_if_fail { guard_hyp x : { x : fin 3 // true } }, simp at y, success_if_fail { guard_hyp y : { x : fin 3 // true } }, simp at x, dsimp at y, guard_hyp x : { x : fin 3 // true }, guard_hyp y : { x : fin 3 // true }, contradiction end /- Test that `to_additive` copies the `@[_refl_lemma]` attribute correctly -/ @[to_additive, simps] def monoid_hom.my_comp {M N P : Type*} [mul_one_class M] [mul_one_class N] [mul_one_class P] (hnp : N →* P) (hmn : M →* N) : M →* P := { to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp, } -- `simps` adds the `_refl_lemma` attribute to `monoid_hom.my_comp_apply` example {M N P : Type*} [mul_one_class M] [mul_one_class N] [mul_one_class P] (hnp : N →* P) (hmn : M →* N) (m : M) : hnp.my_comp hmn m = hnp (hmn m) := by { dsimp, guard_target (hnp (hmn m) = hnp (hmn m)), refl } -- `to_additive` adds the `_refl_lemma` attribute to `add_monoid_hom.my_comp_apply` example {M N P : Type*} [add_zero_class M] [add_zero_class N] [add_zero_class P] (hnp : N →+ P) (hmn : M →+ N) (m : M) : hnp.my_comp hmn m = hnp (hmn m) := by { dsimp, guard_target (hnp (hmn m) = hnp (hmn m)), refl } -- test that `to_additive` works with a custom name @[to_additive some_test2, simps] def some_test1 (M : Type*) [comm_monoid M] : subtype (λ f : M, true) := ⟨1, trivial⟩ run_cmd get_decl `some_test2_coe end /- Test custom compositions of projections. -/ section comp_projs instance {α β} : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨equiv.to_fun⟩ @[simps] protected def equiv.symm {α β} (f : α ≃ β) : β ≃ α := ⟨f.inv_fun, f, f.right_inv, f.left_inv⟩ structure decorated_equiv (α : Sort*) (β : Sort*) extends equiv α β := (P_to_fun : function.injective to_fun ) (P_inv_fun : function.injective inv_fun) instance {α β} : has_coe_to_fun (decorated_equiv α β) (λ _, α → β) := ⟨λ f, f.to_equiv⟩ def decorated_equiv.symm {α β : Sort*} (e : decorated_equiv α β) : decorated_equiv β α := { to_equiv := e.to_equiv.symm, P_to_fun := e.P_inv_fun, P_inv_fun := e.P_to_fun } def decorated_equiv.simps.apply {α β : Sort*} (e : decorated_equiv α β) : α → β := e def decorated_equiv.simps.symm_apply {α β : Sort*} (e : decorated_equiv α β) : β → α := e.symm initialize_simps_projections decorated_equiv (to_equiv_to_fun → apply, to_equiv_inv_fun → symm_apply, -to_equiv) @[simps] def foo (α : Type) : decorated_equiv α α := { to_fun := λ x, x, inv_fun := λ x, x, left_inv := λ x, rfl, right_inv := λ x, rfl, P_to_fun := λ x y h, h, P_inv_fun := λ x y h, h } example {α : Type} (x : α) : (foo α).symm x = x := by { dsimp, guard_target (x = x), refl } @[simps to_equiv apply symm_apply] def foo2 (α : Type) : decorated_equiv α α := { P_to_fun := λ x y h, h, P_inv_fun := λ x y h, h, ..foo.rfl } example {α : Type} (x : α) : (foo2 α).to_equiv x = x := by { dsimp, guard_target (foo.rfl x = x), refl } example {α : Type} (x : α) : foo2 α x = x := by { dsimp, guard_target (x = x), refl } structure further_decorated_equiv (α : Sort*) (β : Sort*) extends decorated_equiv α β := (Q_to_fun : function.surjective to_fun ) (Q_inv_fun : function.surjective inv_fun ) instance {α β} : has_coe_to_fun (further_decorated_equiv α β) (λ _, α → β) := ⟨λ f, f.to_decorated_equiv⟩ def further_decorated_equiv.symm {α β : Sort*} (e : further_decorated_equiv α β) : further_decorated_equiv β α := { to_decorated_equiv := e.to_decorated_equiv.symm, Q_to_fun := e.Q_inv_fun, Q_inv_fun := e.Q_to_fun } def further_decorated_equiv.simps.apply {α β : Sort*} (e : further_decorated_equiv α β) : α → β := e def further_decorated_equiv.simps.symm_apply {α β : Sort*} (e : further_decorated_equiv α β) : β → α := e.symm initialize_simps_projections further_decorated_equiv (to_decorated_equiv_to_equiv_to_fun → apply, to_decorated_equiv_to_equiv_inv_fun → symm_apply, -to_decorated_equiv, to_decorated_equiv_to_equiv → to_equiv, -to_equiv) @[simps] def ffoo (α : Type) : further_decorated_equiv α α := { to_fun := λ x, x, inv_fun := λ x, x, left_inv := λ x, rfl, right_inv := λ x, rfl, P_to_fun := λ x y h, h, P_inv_fun := λ x y h, h, Q_to_fun := λ y, ⟨y, rfl⟩, Q_inv_fun := λ y, ⟨y, rfl⟩ } example {α : Type} (x : α) : (ffoo α).symm x = x := by { dsimp, guard_target (x = x), refl } @[simps] def ffoo3 (α : Type) : further_decorated_equiv α α := { Q_to_fun := λ y, ⟨y, rfl⟩, Q_inv_fun := λ y, ⟨y, rfl⟩, .. foo α } @[simps apply to_equiv_to_fun to_decorated_equiv_apply] def ffoo4 (α : Type) : further_decorated_equiv α α := { Q_to_fun := λ y, ⟨y, rfl⟩, Q_inv_fun := λ y, ⟨y, rfl⟩, to_decorated_equiv := foo α } structure one_more (α : Sort*) (β : Sort*) extends further_decorated_equiv α β instance {α β} : has_coe_to_fun (one_more α β) (λ _, α → β) := ⟨λ f, f.to_further_decorated_equiv⟩ def one_more.symm {α β : Sort*} (e : one_more α β) : one_more β α := { to_further_decorated_equiv := e.to_further_decorated_equiv.symm } def one_more.simps.apply {α β : Sort*} (e : one_more α β) : α → β := e def one_more.simps.symm_apply {α β : Sort*} (e : one_more α β) : β → α := e.symm initialize_simps_projections one_more (to_further_decorated_equiv_to_decorated_equiv_to_equiv_to_fun → apply, to_further_decorated_equiv_to_decorated_equiv_to_equiv_inv_fun → symm_apply, -to_further_decorated_equiv, to_further_decorated_equiv_to_decorated_equiv → to_dequiv, -to_dequiv) @[simps] def fffoo (α : Type) : one_more α α := { to_fun := λ x, x, inv_fun := λ x, x, left_inv := λ x, rfl, right_inv := λ x, rfl, P_to_fun := λ x y h, h, P_inv_fun := λ x y h, h, Q_to_fun := λ y, ⟨y, rfl⟩, Q_inv_fun := λ y, ⟨y, rfl⟩ } example {α : Type} (x : α) : (fffoo α).symm x = x := by { dsimp, guard_target (x = x), refl } @[simps apply to_dequiv_apply to_further_decorated_equiv_apply to_dequiv] def fffoo2 (α : Type) : one_more α α := fffoo α /- test the case where a projection takes additional arguments. -/ variables {ι : Type*} [decidable_eq ι] (A : ι → Type*) class something [has_add ι] [Π i, add_comm_monoid (A i)] := (mul {i} : A i →+ A i) def something.simps.apply [has_add ι] [Π i, add_comm_monoid (A i)] [something A] {i : ι} (x : A i) : A i := something.mul ι x initialize_simps_projections something (mul_to_fun → apply, -mul) class something2 [has_add ι] := (mul {i j} : A i ≃ (A j ≃ A (i + j))) def something2.simps.mul [has_add ι] [something2 A] {i j : ι} (x : A i) (y : A j) : A (i + j) := something2.mul x y initialize_simps_projections something2 (mul → mul', mul_to_fun_to_fun → mul, -mul') attribute [ext] equiv @[simps] def thing (h : bool ≃ (bool ≃ bool)) : something2 (λ x : ℕ, bool) := { mul := λ i j, { to_fun := λ b, { to_fun := h b, inv_fun := (h b).symm, left_inv := (h b).left_inv, right_inv := (h b).right_inv }, inv_fun := h.symm, left_inv := by { convert h.left_inv, ext x; refl }, right_inv := by { convert h.right_inv, ext x; refl } } } example (h : bool ≃ (bool ≃ bool)) (i j : ℕ) (b1 b2 : bool) : @something2.mul _ _ _ _ (thing h) i j b1 b2 = h b1 b2 := by simp only [thing_mul] end comp_projs section /-! Check that the tactic also works if the elaborated type of `type` reduces to `Sort*`, but is not `Sort*` itself. -/ structure my_functor (C D : Type*) := (obj [] : C → D) local infixr ` ⥤ `:26 := my_functor @[simps] def foo_sum {I J : Type*} (C : I → Type*) {D : J → Type*} : (Π i, C i) ⥤ (Π j, D j) ⥤ (Π s : I ⊕ J, sum.elim C D s) := { obj := λ f, { obj := λ g s, sum.rec f g s }} end
d3b9af32f750d5e2b361e3f98c064b1fb6860367
491068d2ad28831e7dade8d6dff871c3e49d9431
/hott/homotopy/connectedness.hlean
b6e2bbb1ce1bc3a10ba4c71d6d6eb4c1e9a0b564
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,150
hlean
/- Copyright (c) 2015 Ulrik Buchholtz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ulrik Buchholtz -/ import types.trunc types.arrow_2 types.fiber open eq is_trunc is_equiv nat equiv trunc function namespace homotopy definition is_conn [reducible] (n : trunc_index) (A : Type) : Type := is_contr (trunc n A) definition is_conn_map (n : trunc_index) {A B : Type} (f : A → B) : Type := Πb : B, is_conn n (fiber f b) definition is_conn_of_map_to_unit (n : trunc_index) (A : Type) : is_conn_map n (λx : A, unit.star) → is_conn n A := begin intro H, unfold is_conn_map at H, rewrite [-(ua (fiber.fiber_star_equiv A))], exact (H unit.star) end -- Lemma 7.5.2 definition minus_one_conn_of_surjective {A B : Type} (f : A → B) : is_surjective f → is_conn_map -1 f := begin intro H, intro b, exact @is_contr_of_inhabited_hprop (∥fiber f b∥) (is_trunc_trunc -1 (fiber f b)) (H b), end definition is_surjection_of_minus_one_conn {A B : Type} (f : A → B) : is_conn_map -1 f → is_surjective f := begin intro H, intro b, exact @center (∥fiber f b∥) (H b), end definition merely_of_minus_one_conn {A : Type} : is_conn -1 A → ∥A∥ := λH, @center (∥A∥) H definition minus_one_conn_of_merely {A : Type} : ∥A∥ → is_conn -1 A := @is_contr_of_inhabited_hprop (∥A∥) (is_trunc_trunc -1 A) section open arrow variables {f g : arrow} -- Lemma 7.5.4 definition retract_of_conn_is_conn [instance] (r : arrow_hom f g) [H : is_retraction r] (n : trunc_index) [K : is_conn_map n f] : is_conn_map n g := begin intro b, unfold is_conn, apply is_contr_retract (trunc_functor n (retraction_on_fiber r b)), exact K (on_cod (arrow.is_retraction.sect r) b) end end -- Corollary 7.5.5 definition is_conn_homotopy (n : trunc_index) {A B : Type} {f g : A → B} (p : f ~ g) (H : is_conn_map n f) : is_conn_map n g := @retract_of_conn_is_conn _ _ (arrow.arrow_hom_of_homotopy p) (arrow.is_retraction_arrow_hom_of_homotopy p) n H end homotopy
513ec1081ab7120e4a605c60cc8aa0790adc75bb
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/lean/run/generalize.lean
77496d063e0e2eeb2708bf27ea59023a49336aae
[ "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
665
lean
new_frontend theorem tst0 (x : Nat) : x + 0 = x + 0 := begin generalize x + 0 = y; exact (Eq.refl y) end theorem tst1 (x : Nat) : x + 0 = x + 0 := begin generalize h : x + 0 = y; exact (Eq.refl y) end theorem tst2 (x y w : Nat) (h : y = w) : (x + x) + w = (x + x) + y := begin generalize h' : x + x = z; subst y; exact Eq.refl $ z + w end theorem tst3 (x y w : Nat) (h : x + x = y) : (x + x) + (x+x) = (x + x) + y := begin generalize h' : x + x = z; subst z; subst y; exact rfl end theorem tst4 (x y w : Nat) (h : y = w) : (x + x) + w = (x + x) + y := begin generalize h' : x + y = z; -- just add equality subst h; exact rfl end
86fa8303de1342897712af9ded621a4514555254
9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e
/src/undergraduate/MAS114/Semester 1/Q16.lean
5a0a1ffcd95998c8e229160a1359381ab999b28e
[]
no_license
agusakov/lean_lib
c0e9cc29fc7d2518004e224376adeb5e69b5cc1a
f88d162da2f990b87c4d34f5f46bbca2bbc5948e
refs/heads/master
1,642,141,461,087
1,557,395,798,000
1,557,395,798,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,612
lean
import data.real.basic data.fintype algebra.big_operators data.nat.modeq import tactic.find tactic.squeeze namespace MAS114 namespace exercises_1 namespace Q16 lemma nat.bodd_even (n : ℕ) : (2 * n).bodd = ff := by {rw[nat.bodd_mul,nat.bodd_two,band],} lemma nat.bodd_odd (n : ℕ) : (2 * n + 1).bodd = tt := by {rw[nat.bodd_add,nat.bodd_even],refl} lemma nat.div2_even : ∀ (n : ℕ), (2 * n).div2 = n | 0 := rfl | (n + 1) := begin have : 2 * (n + 1) = (2 * n + 1).succ := by ring, rw[this,nat.div2_succ,nat.bodd_odd,bool.cond_tt], rw[nat.div2_succ,nat.bodd_even,bool.cond_ff], rw[nat.div2_even n], end lemma nat.div2_odd (n : ℕ) : (2 * n + 1).div2 = n := by {rw[nat.div2_succ,nat.bodd_even,bool.cond_ff,nat.div2_even]} lemma wf_lemma : ∀ (m : ℕ), m.succ.div2 < m.succ | 0 := dec_trivial | (nat.succ m) := begin rw[nat.div2_succ], cases m.succ.bodd; simp only[bool.cond_tt,bool.cond_ff], exact lt_trans (wf_lemma m) m.succ.lt_succ_self, exact nat.succ_lt_succ (wf_lemma m) end lemma wf_lemma' (m : ℕ) : cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m := begin cases m, {exact dec_trivial,}, let u := wf_lemma m, cases m.succ.bodd; simp only[bool.cond_tt,bool.cond_ff], exact lt_trans u m.succ.lt_succ_self, exact nat.succ_lt_succ u, end def f : bool → ℕ → ℕ | ff u := 4 * u + 1 | tt u := 9 * u + 2 def a : ℕ → ℕ | 0 := 0 | (nat.succ m) := have cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m := wf_lemma' m, f m.succ.bodd (a m.succ.div2) lemma a_even (n : ℕ) : n > 0 → a (2 * n) = 4 * (a n) + 1 := begin intro n_pos, let k := n.pred, have e0 : n = k + 1 := (nat.succ_pred_eq_of_pos n_pos).symm, let m := 2 * k + 1, have e1 : 2 * n = m.succ := calc 2 * n = 2 * (k + 1) : by rw[e0] ... = 2 * k + 2 : by rw[mul_add,mul_one] ... = m.succ : rfl, rw[e1,a,← e1,nat.bodd_even,nat.div2_even,f], end lemma a_odd (n : ℕ) : a (2 * n + 1) = 9 * (a n) + 2 := begin change a (2 * n).succ = 9 * (a n) + 2, rw[a,nat.bodd_odd,nat.div2_odd,f], end lemma a_even_step (n : ℕ) : n > 0 → n ^ 2 ≤ a n → (2 * n) ^ 2 ≤ a (2 * n) := begin intros n_pos ih, rw[a_even n n_pos], exact calc (2 * n) ^ 2 = 4 * n ^ 2 : by ring ... ≤ 4 * a n : nat.mul_le_mul_left 4 ih ... ≤ 4 * a n + 1 : nat.le_succ _ end lemma a_odd_step (n : ℕ) : n ^ 2 ≤ a n → (2 * n + 1) ^ 2 ≤ a (2 * n + 1) := begin intro ih, rw[a_odd n], exact calc (2 * n + 1) ^ 2 = 4 * n + (4 * n ^ 2 + 1) : by ring ... ≤ 4 * n ^ 2 + (4 * n ^ 2 + 1) : by {apply (nat.add_le_add_iff_le_right _ _ _).mpr, rw[nat.pow_two], exact nat.mul_le_mul_left 4 (nat.le_mul_self n),} ... = 8 * n ^ 2 + 1 : by ring ... ≤ 9 * n ^ 2 + 2 : by linarith ... ≤ 9 * a n + 2 : by {apply (nat.add_le_add_iff_le_right _ _ _).mpr, exact nat.mul_le_mul_left 9 ih,} end lemma square_le : ∀ n, n ^ 2 ≤ a n | 0 := le_refl 0 | (nat.succ m) := have cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m := wf_lemma' m, begin let e := nat.bodd_add_div2 m.succ, rw[nat.bodd_succ] at e, rw[← e], rcases m.bodd; simp only[bnot,bool.cond_ff,bool.cond_tt,zero_add], {intros u0 u1, rw[nat.add_comm 1], exact a_odd_step m.succ.div2 (square_le m.succ.div2), },{ intros u0 u1, by_cases h : m.succ.div2 = 0, {exfalso,rw[h,mul_zero] at u0,exact nat.succ_ne_zero m u0.symm}, exact a_even_step m.succ.div2 (nat.pos_of_ne_zero h) (square_le m.succ.div2), } end end Q16 end exercises_1 end MAS114
a0c5879cf3edf8ebd48b0f9dcf8b583bf3e9b0df
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
/tests/lean/run/super_tests.lean
7d0c29fae92c1a4607e5b76ea4e6981ad60a4678
[ "Apache-2.0" ]
permissive
leodemoura/lean_clone
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
cc077554b584d39bab55c360bc12a6fe7957afe6
refs/heads/master
1,610,506,475,484
1,482,348,354,000
1,482,348,543,000
77,091,586
0
0
null
null
null
null
UTF-8
Lean
false
false
2,983
lean
import tools.super section open super tactic example (i : Type) (a b : i) (p : i → Prop) (H : a = b) (Hpa : p a) : true := by do H ← get_local `H >>= clause.of_classical_proof, Hpa ← get_local `Hpa >>= clause.of_classical_proof, a ← get_local `a, try_sup (λx y, ff) H Hpa 0 0 [0] tt ``super.sup_ltr >>= clause.validate, to_expr `(trivial) >>= apply example (i : Type) (a b : i) (p : i → Prop) (H : a = b) (Hpa : p a → false) (Hpb : p b → false) : true := by do H ← get_local `H >>= clause.of_classical_proof, Hpa ← get_local `Hpa >>= clause.of_classical_proof, Hpb ← get_local `Hpb >>= clause.of_classical_proof, try_sup (λx y, ff) H Hpa 0 0 [0] tt ``super.sup_ltr >>= clause.validate, try_sup (λx y, ff) H Hpb 0 0 [0] ff ``super.sup_rtl >>= clause.validate, to_expr `(trivial) >>= apply example (i : Type) (p q : i → Prop) (H : ∀x y, p x → q y → false) : true := by do h ← get_local `H >>= clause.of_classical_proof, (op, lcs) ← h↣open_constn h↣num_binders, guard $ (get_components lcs)↣length = 2, triv example (i : Type) (p : i → i → Prop) (H : ∀x y z, p x y → p y z → false) : true := by do h ← get_local `H >>= clause.of_classical_proof, (op, lcs) ← h↣open_constn h↣num_binders, guard $ (get_components lcs)↣length = 1, triv example (i : Type) (p : i → i → Type) (c : i) (h : ∀ (x : i), p x c → p x c) : true := by do h ← get_local `h, hcls ← clause.of_classical_proof h, taut ← is_taut hcls, when (¬taut) failed, to_expr `(trivial) >>= apply open tactic example (m n : ℕ) : true := by do e₁ ← to_expr `((0 + (m : ℕ)) + 0), e₂ ← to_expr `(0 + (0 + (m : ℕ))), e₃ ← to_expr `(0 + (m : ℕ)), prec ← return (contained_funsyms e₁)↣keys, prec_gt ← return $ prec_gt_of_name_list prec, guard $ lpo prec_gt e₁ e₃, guard $ lpo prec_gt e₂ e₃, to_expr `(trivial) >>= apply /- open tactic example (i : Type) (f : i → i) (c d x : i) : true := by do ef ← get_local `f, ec ← get_local `c, ed ← get_local `d, syms ← return [ef,ec,ed], prec_gt ← return $ prec_gt_of_name_list (list.map local_uniq_name [ef, ec, ed]), sequence' (do s1 ← syms, s2 ← syms, return (do s1_fmt ← pp s1, s2_fmt ← pp s2, trace (s1_fmt ++ to_fmt " > " ++ s2_fmt ++ to_fmt ": " ++ to_fmt (prec_gt s1 s2)) )), exprs ← @mapM tactic _ _ _ to_expr [`(f c), `(f (f c)), `(f d), `(f x), `(f (f x))], sequence' (do e1 ← exprs, e2 ← exprs, return (do e1_fmt ← pp e1, e2_fmt ← pp e2, trace (e1_fmt ++ to_fmt" > " ++ e2_fmt ++ to_fmt": " ++ to_fmt (lpo prec_gt e1 e2)) )), mk_const ``true.intro >>= apply -/ open monad example (x y : ℕ) (h : nat.zero = nat.succ nat.zero) (h2 : nat.succ x = nat.succ y) : true := by do h ← get_local `h >>= clause.of_classical_proof, h2 ← get_local `h2 >>= clause.of_classical_proof, cs ← try_no_confusion_eq_r h 0, for' cs clause.validate, cs ← try_no_confusion_eq_r h2 0, for' cs clause.validate, to_expr `(trivial) >>= exact end
95d0e3b4734a6cb6444068444a1f55a5d5557185
c777c32c8e484e195053731103c5e52af26a25d1
/src/field_theory/chevalley_warning.lean
3e0de4a8b463ba2a4f4a6a7599d36395d54e3b80
[ "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
9,849
lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import field_theory.finite.basic /-! # The Chevalley–Warning theorem This file contains a proof of the Chevalley–Warning theorem. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Main results 1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`) such that the total degree of `f` is less than `(q-1)` times the cardinality of `σ`. Then the evaluation of `f` on all points of `σ → K` (aka `K^σ`) sums to `0`. (`sum_eval_eq_zero`) 2. The Chevalley–Warning theorem (`char_dvd_card_solutions_of_sum_lt`). Let `f i` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) such that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by the characteristic of `K`. ## Notation - `K` is a finite field - `q` is notation for the cardinality of `K` - `σ` is the indexing type for the variables of a multivariate polynomial ring over `K` -/ universes u v open_locale big_operators section finite_field open mv_polynomial function (hiding eval) finset finite_field variables {K σ ι : Type*} [fintype K] [field K] [fintype σ] [decidable_eq σ] local notation `q` := fintype.card K lemma mv_polynomial.sum_eval_eq_zero (f : mv_polynomial σ K) (h : f.total_degree < (q - 1) * fintype.card σ) : ∑ x, eval x f = 0 := begin haveI : decidable_eq K := classical.dec_eq K, calc (∑ x, eval x f) = ∑ x : σ → K, ∑ d in f.support, f.coeff d * ∏ i, x i ^ d i : by simp only [eval_eq'] ... = ∑ d in f.support, ∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i : sum_comm ... = 0 : sum_eq_zero _, intros d hd, obtain ⟨i, hi⟩ : ∃ i, d i < q - 1, from f.exists_degree_lt (q - 1) h hd, calc (∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i) = f.coeff d * (∑ x : σ → K, ∏ i, x i ^ d i) : mul_sum.symm ... = 0 : (mul_eq_zero.mpr ∘ or.inr) _, calc (∑ x : σ → K, ∏ i, x i ^ d i) = ∑ (x₀ : {j // j ≠ i} → K) (x : {x : σ → K // x ∘ coe = x₀}), ∏ j, (x : σ → K) j ^ d j : (fintype.sum_fiberwise _ _).symm ... = 0 : fintype.sum_eq_zero _ _, intros x₀, let e : K ≃ {x // x ∘ coe = x₀} := (equiv.subtype_equiv_codomain _).symm, calc (∑ x : {x : σ → K // x ∘ coe = x₀}, ∏ j, (x : σ → K) j ^ d j) = ∑ a : K, ∏ j : σ, (e a : σ → K) j ^ d j : (e.sum_comp _).symm ... = ∑ a : K, (∏ j, x₀ j ^ d j) * a ^ d i : fintype.sum_congr _ _ _ ... = (∏ j, x₀ j ^ d j) * ∑ a : K, a ^ d i : by rw mul_sum ... = 0 : by rw [sum_pow_lt_card_sub_one _ hi, mul_zero], intros a, let e' : {j // j = i} ⊕ {j // j ≠ i} ≃ σ := equiv.sum_compl _, letI : unique {j // j = i} := { default := ⟨i, rfl⟩, uniq := λ ⟨j, h⟩, subtype.val_injective h }, calc (∏ j : σ, (e a : σ → K) j ^ d j) = (e a : σ → K) i ^ d i * (∏ (j : {j // j ≠ i}), (e a : σ → K) j ^ d j) : by { rw [← e'.prod_comp, fintype.prod_sum_type, univ_unique, prod_singleton], refl } ... = a ^ d i * (∏ (j : {j // j ≠ i}), (e a : σ → K) j ^ d j) : by rw equiv.subtype_equiv_codomain_symm_apply_eq ... = a ^ d i * (∏ j, x₀ j ^ d j) : congr_arg _ (fintype.prod_congr _ _ _) -- see below ... = (∏ j, x₀ j ^ d j) * a ^ d i : mul_comm _ _, { -- the remaining step of the calculation above rintros ⟨j, hj⟩, show (e a : σ → K) j ^ d j = x₀ ⟨j, hj⟩ ^ d j, rw equiv.subtype_equiv_codomain_symm_apply_ne, } end variables [decidable_eq K] (p : ℕ) [char_p K p] /-- The **Chevalley–Warning theorem**, finitary version. Let `(f i)` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_sum_lt {s : finset ι} {f : ι → mv_polynomial σ K} (h : (∑ i in s, (f i).total_degree) < fintype.card σ) : p ∣ fintype.card {x : σ → K // ∀ i ∈ s, eval x (f i) = 0} := begin have hq : 0 < q - 1, { rw [← fintype.card_units, fintype.card_pos_iff], exact ⟨1⟩ }, let S : finset (σ → K) := { x ∈ univ | ∀ i ∈ s, eval x (f i) = 0 }, have hS : ∀ (x : σ → K), x ∈ S ↔ ∀ (i : ι), i ∈ s → eval x (f i) = 0, { intros x, simp only [S, true_and, sep_def, mem_filter, mem_univ], }, /- The polynomial `F = ∏ i in s, (1 - (f i)^(q - 1))` has the nice property that it takes the value `1` on elements of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` while it is `0` outside that locus. Hence the sum of its values is equal to the cardinality of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` modulo `p`. -/ let F : mv_polynomial σ K := ∏ i in s, (1 - (f i)^(q - 1)), have hF : ∀ x, eval x F = if x ∈ S then 1 else 0, { intro x, calc eval x F = ∏ i in s, eval x (1 - f i ^ (q - 1)) : eval_prod s _ x ... = if x ∈ S then 1 else 0 : _, simp only [(eval x).map_sub, (eval x).map_pow, (eval x).map_one], split_ifs with hx hx, { apply finset.prod_eq_one, intros i hi, rw hS at hx, rw [hx i hi, zero_pow hq, sub_zero], }, { obtain ⟨i, hi, hx⟩ : ∃ (i : ι), i ∈ s ∧ eval x (f i) ≠ 0, { simpa only [hS, not_forall, not_imp] using hx }, apply finset.prod_eq_zero hi, rw [pow_card_sub_one_eq_one (eval x (f i)) hx, sub_self], } }, -- In particular, we can now show: have key : ∑ x, eval x F = fintype.card {x : σ → K // ∀ i ∈ s, eval x (f i) = 0}, rw [fintype.card_of_subtype S hS, card_eq_sum_ones, nat.cast_sum, nat.cast_one, ← fintype.sum_extend_by_zero S, sum_congr rfl (λ x hx, hF x)], -- With these preparations under our belt, we will approach the main goal. show p ∣ fintype.card {x // ∀ (i : ι), i ∈ s → eval x (f i) = 0}, rw [← char_p.cast_eq_zero_iff K, ← key], show ∑ x, eval x F = 0, -- We are now ready to apply the main machine, proven before. apply F.sum_eval_eq_zero, -- It remains to verify the crucial assumption of this machine show F.total_degree < (q - 1) * fintype.card σ, calc F.total_degree ≤ ∑ i in s, (1 - (f i)^(q - 1)).total_degree : total_degree_finset_prod s _ ... ≤ ∑ i in s, (q - 1) * (f i).total_degree : sum_le_sum $ λ i hi, _ -- see ↓ ... = (q - 1) * (∑ i in s, (f i).total_degree) : mul_sum.symm ... < (q - 1) * (fintype.card σ) : by rwa mul_lt_mul_left hq, -- Now we prove the remaining step from the preceding calculation show (1 - f i ^ (q - 1)).total_degree ≤ (q - 1) * (f i).total_degree, calc (1 - f i ^ (q - 1)).total_degree ≤ max (1 : mv_polynomial σ K).total_degree (f i ^ (q - 1)).total_degree : total_degree_sub _ _ ... ≤ (f i ^ (q - 1)).total_degree : by simp only [max_eq_right, nat.zero_le, total_degree_one] ... ≤ (q - 1) * (f i).total_degree : total_degree_pow _ _ end /-- The **Chevalley–Warning theorem**, fintype version. Let `(f i)` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_fintype_sum_lt [fintype ι] {f : ι → mv_polynomial σ K} (h : (∑ i, (f i).total_degree) < fintype.card σ) : p ∣ fintype.card {x : σ → K // ∀ i, eval x (f i) = 0} := by simpa using char_dvd_card_solutions_of_sum_lt p h /-- The **Chevalley–Warning theorem**, unary version. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the total degree of `f` is less than the cardinality of `σ`. Then the number of solutions of `f` is divisible by `p`. See `char_dvd_card_solutions_of_sum_lt` for a version that takes a family of polynomials `f i`. -/ theorem char_dvd_card_solutions {f : mv_polynomial σ K} (h : f.total_degree < fintype.card σ) : p ∣ fintype.card {x : σ → K // eval x f = 0} := begin let F : unit → mv_polynomial σ K := λ _, f, have : ∑ i : unit, (F i).total_degree < fintype.card σ := h, simpa only [F, fintype.univ_punit, forall_eq, mem_singleton] using char_dvd_card_solutions_of_sum_lt p this, end /-- The **Chevalley–Warning theorem**, binary version. Let `f₁`, `f₂` be two multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of `f₁` and `f₂` is less than the cardinality of `σ`. Then the number of common solutions of the `f₁` and `f₂` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_add_lt {f₁ f₂ : mv_polynomial σ K} (h : f₁.total_degree + f₂.total_degree < fintype.card σ) : p ∣ fintype.card {x : σ → K // eval x f₁ = 0 ∧ eval x f₂ = 0} := begin let F : bool → mv_polynomial σ K := λ b, cond b f₂ f₁, have : ∑ b : bool, (F b).total_degree < fintype.card σ := (add_comm _ _).trans_lt h, simpa only [F, bool.forall_bool] using char_dvd_card_solutions_of_fintype_sum_lt p this, end end finite_field
06b1b73a2f24c1b2588aa8f4aa16c2c2f5ee4484
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/linear_algebra/affine_space/affine_equiv.lean
034e8ff08416355908a9eb06fd6aebd88f5a76fd
[]
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
28,562
lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Yury G. Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.linear_algebra.affine_space.affine_map import Mathlib.algebra.invertible import Mathlib.PostPort universes u_1 u_2 u_3 u_4 u_5 l u_6 u_7 u_8 u_9 u_10 namespace Mathlib /-! # Affine equivalences In this file we define `affine_equiv k P₁ P₂` (notation: `P₁ ≃ᵃ[k] P₂`) to be the type of affine equivalences between `P₁` and `P₂, i.e., equivalences such that both forward and inverse maps are affine maps. We define the following equivalences: * `affine_equiv.refl k P`: the identity map as an `affine_equiv`; * `e.symm`: the inverse map of an `affine_equiv` as an `affine_equiv`; * `e.trans e'`: composition of two `affine_equiv`s; note that the order follows `mathlib`'s `category_theory` convention (apply `e`, then `e'`), not the convention used in function composition and compositions of bundled morphisms. ## Tags affine space, affine equivalence -/ /-- An affine equivalence is an equivalence between affine spaces such that both forward and inverse maps are affine. We define it using an `equiv` for the map and a `linear_equiv` for the linear part in order to allow affine equivalences with good definitional equalities. -/ structure affine_equiv (k : Type u_1) (P₁ : Type u_2) (P₂ : Type u_3) {V₁ : Type u_4} {V₂ : Type u_5} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] extends P₁ ≃ P₂ where linear : linear_equiv k V₁ V₂ map_vadd' : ∀ (p : P₁) (v : V₁), coe_fn _to_equiv (v +ᵥ p) = coe_fn linear v +ᵥ coe_fn _to_equiv p protected instance affine_equiv.has_coe_to_fun (k : Type u_1) {V1 : Type u_2} (P1 : Type u_3) {V2 : Type u_4} (P2 : Type u_5) [ring k] [add_comm_group V1] [module k V1] [add_torsor V1 P1] [add_comm_group V2] [module k V2] [add_torsor V2 P2] : has_coe_to_fun (affine_equiv k P1 P2) := has_coe_to_fun.mk (fun (e : affine_equiv k P1 P2) => P1 → P2) fun (e : affine_equiv k P1 P2) => equiv.to_fun (affine_equiv.to_equiv e) namespace linear_equiv /-- Interpret a linear equivalence between modules as an affine equivalence. -/ def to_affine_equiv {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_comm_group V₂] [semimodule k V₂] (e : linear_equiv k V₁ V₂) : affine_equiv k V₁ V₂ := affine_equiv.mk (to_equiv e) e sorry @[simp] theorem coe_to_affine_equiv {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_comm_group V₂] [semimodule k V₂] (e : linear_equiv k V₁ V₂) : ⇑(to_affine_equiv e) = ⇑e := rfl end linear_equiv namespace affine_equiv /-- Identity map as an `affine_equiv`. -/ def refl (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : affine_equiv k P₁ P₁ := mk (equiv.refl P₁) (linear_equiv.refl k V₁) sorry @[simp] theorem coe_refl (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : ⇑(refl k P₁) = id := rfl theorem refl_apply (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : coe_fn (refl k P₁) x = x := rfl @[simp] theorem to_equiv_refl (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : to_equiv (refl k P₁) = equiv.refl P₁ := rfl @[simp] theorem linear_refl (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : linear (refl k P₁) = linear_equiv.refl k V₁ := rfl @[simp] theorem map_vadd {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) (p : P₁) (v : V₁) : coe_fn e (v +ᵥ p) = coe_fn (linear e) v +ᵥ coe_fn e p := map_vadd' e p v @[simp] theorem coe_to_equiv {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : ⇑(to_equiv e) = ⇑e := rfl /-- Reinterpret an `affine_equiv` as an `affine_map`. -/ def to_affine_map {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : affine_map k P₁ P₂ := affine_map.mk (⇑e) (↑(linear e)) (map_vadd' e) @[simp] theorem coe_to_affine_map {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : ⇑(to_affine_map e) = ⇑e := rfl @[simp] theorem to_affine_map_mk {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (f : P₁ ≃ P₂) (f' : linear_equiv k V₁ V₂) (h : ∀ (p : P₁) (v : V₁), coe_fn f (v +ᵥ p) = coe_fn f' v +ᵥ coe_fn f p) : to_affine_map (mk f f' h) = affine_map.mk (⇑f) (↑f') h := rfl @[simp] theorem linear_to_affine_map {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : affine_map.linear (to_affine_map e) = ↑(linear e) := rfl theorem injective_to_affine_map {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] : function.injective to_affine_map := sorry @[simp] theorem to_affine_map_inj {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] {e : affine_equiv k P₁ P₂} {e' : affine_equiv k P₁ P₂} : to_affine_map e = to_affine_map e' ↔ e = e' := function.injective.eq_iff injective_to_affine_map theorem ext {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] {e : affine_equiv k P₁ P₂} {e' : affine_equiv k P₁ P₂} (h : ∀ (x : P₁), coe_fn e x = coe_fn e' x) : e = e' := injective_to_affine_map (affine_map.ext h) theorem injective_coe_fn {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] : function.injective fun (e : affine_equiv k P₁ P₂) (x : P₁) => coe_fn e x := sorry @[simp] theorem coe_fn_inj {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] {e : affine_equiv k P₁ P₂} {e' : affine_equiv k P₁ P₂} : ⇑e = ⇑e' ↔ e = e' := function.injective.eq_iff injective_coe_fn theorem injective_to_equiv {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] : function.injective to_equiv := fun (e e' : affine_equiv k P₁ P₂) (H : to_equiv e = to_equiv e') => ext (iff.mp equiv.ext_iff H) @[simp] theorem to_equiv_inj {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] {e : affine_equiv k P₁ P₂} {e' : affine_equiv k P₁ P₂} : to_equiv e = to_equiv e' ↔ e = e' := function.injective.eq_iff injective_to_equiv /-- Construct an affine equivalence by verifying the relation between the map and its linear part at one base point. Namely, this function takes an equivalence `e : P₁ ≃ P₂`, a linear equivalece `e' : V₁ ≃ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `e p' = e' (p' -ᵥ p) +ᵥ e p`. -/ def mk' {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : P₁ ≃ P₂) (e' : linear_equiv k V₁ V₂) (p : P₁) (h : ∀ (p' : P₁), coe_fn e p' = coe_fn e' (p' -ᵥ p) +ᵥ coe_fn e p) : affine_equiv k P₁ P₂ := mk e e' sorry @[simp] theorem coe_mk' {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : P₁ ≃ P₂) (e' : linear_equiv k V₁ V₂) (p : P₁) (h : ∀ (p' : P₁), coe_fn e p' = coe_fn e' (p' -ᵥ p) +ᵥ coe_fn e p) : ⇑(mk' e e' p h) = ⇑e := rfl @[simp] theorem to_equiv_mk' {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : P₁ ≃ P₂) (e' : linear_equiv k V₁ V₂) (p : P₁) (h : ∀ (p' : P₁), coe_fn e p' = coe_fn e' (p' -ᵥ p) +ᵥ coe_fn e p) : to_equiv (mk' e e' p h) = e := rfl @[simp] theorem linear_mk' {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : P₁ ≃ P₂) (e' : linear_equiv k V₁ V₂) (p : P₁) (h : ∀ (p' : P₁), coe_fn e p' = coe_fn e' (p' -ᵥ p) +ᵥ coe_fn e p) : linear (mk' e e' p h) = e' := rfl /-- Inverse of an affine equivalence as an affine equivalence. -/ def symm {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : affine_equiv k P₂ P₁ := mk (equiv.symm (to_equiv e)) (linear_equiv.symm (linear e)) sorry @[simp] theorem symm_to_equiv {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : equiv.symm (to_equiv e) = to_equiv (symm e) := rfl @[simp] theorem symm_linear {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : linear_equiv.symm (linear e) = linear (symm e) := rfl protected theorem bijective {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : function.bijective ⇑e := equiv.bijective (to_equiv e) protected theorem surjective {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : function.surjective ⇑e := equiv.surjective (to_equiv e) protected theorem injective {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : function.injective ⇑e := equiv.injective (to_equiv e) @[simp] theorem range_eq {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : set.range ⇑e = set.univ := function.surjective.range_eq (affine_equiv.surjective e) @[simp] theorem apply_symm_apply {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) (p : P₂) : coe_fn e (coe_fn (symm e) p) = p := equiv.apply_symm_apply (to_equiv e) p @[simp] theorem symm_apply_apply {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) (p : P₁) : coe_fn (symm e) (coe_fn e p) = p := equiv.symm_apply_apply (to_equiv e) p theorem apply_eq_iff_eq_symm_apply {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) {p₁ : P₁} {p₂ : P₂} : coe_fn e p₁ = p₂ ↔ p₁ = coe_fn (symm e) p₂ := equiv.apply_eq_iff_eq_symm_apply (to_equiv e) @[simp] theorem apply_eq_iff_eq {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) {p₁ : P₁} {p₂ : P₁} : coe_fn e p₁ = coe_fn e p₂ ↔ p₁ = p₂ := equiv.apply_eq_iff_eq (to_equiv e) @[simp] theorem symm_refl {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : symm (refl k P₁) = refl k P₁ := rfl /-- Composition of two `affine_equiv`alences, applied left to right. -/ def trans {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {V₃ : Type u_4} {P₁ : Type u_6} {P₂ : Type u_7} {P₃ : Type u_8} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] [add_comm_group V₃] [semimodule k V₃] [add_torsor V₃ P₃] (e : affine_equiv k P₁ P₂) (e' : affine_equiv k P₂ P₃) : affine_equiv k P₁ P₃ := mk (equiv.trans (to_equiv e) (to_equiv e')) (linear_equiv.trans (linear e) (linear e')) sorry @[simp] theorem coe_trans {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {V₃ : Type u_4} {P₁ : Type u_6} {P₂ : Type u_7} {P₃ : Type u_8} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] [add_comm_group V₃] [semimodule k V₃] [add_torsor V₃ P₃] (e : affine_equiv k P₁ P₂) (e' : affine_equiv k P₂ P₃) : ⇑(trans e e') = ⇑e' ∘ ⇑e := rfl theorem trans_apply {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {V₃ : Type u_4} {P₁ : Type u_6} {P₂ : Type u_7} {P₃ : Type u_8} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] [add_comm_group V₃] [semimodule k V₃] [add_torsor V₃ P₃] (e : affine_equiv k P₁ P₂) (e' : affine_equiv k P₂ P₃) (p : P₁) : coe_fn (trans e e') p = coe_fn e' (coe_fn e p) := rfl theorem trans_assoc {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {V₃ : Type u_4} {V₄ : Type u_5} {P₁ : Type u_6} {P₂ : Type u_7} {P₃ : Type u_8} {P₄ : Type u_9} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] [add_comm_group V₃] [semimodule k V₃] [add_torsor V₃ P₃] [add_comm_group V₄] [semimodule k V₄] [add_torsor V₄ P₄] (e₁ : affine_equiv k P₁ P₂) (e₂ : affine_equiv k P₂ P₃) (e₃ : affine_equiv k P₃ P₄) : trans (trans e₁ e₂) e₃ = trans e₁ (trans e₂ e₃) := ext fun (_x : P₁) => rfl @[simp] theorem trans_refl {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : trans e (refl k P₂) = e := ext fun (_x : P₁) => rfl @[simp] theorem refl_trans {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : trans (refl k P₁) e = e := ext fun (_x : P₁) => rfl @[simp] theorem trans_symm {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : trans e (symm e) = refl k P₁ := ext (symm_apply_apply e) @[simp] theorem symm_trans {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) : trans (symm e) e = refl k P₂ := ext (apply_symm_apply e) @[simp] theorem apply_line_map {k : Type u_1} {V₁ : Type u_2} {V₂ : Type u_3} {P₁ : Type u_6} {P₂ : Type u_7} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [add_comm_group V₂] [semimodule k V₂] [add_torsor V₂ P₂] (e : affine_equiv k P₁ P₂) (a : P₁) (b : P₁) (c : k) : coe_fn e (coe_fn (affine_map.line_map a b) c) = coe_fn (affine_map.line_map (coe_fn e a) (coe_fn e b)) c := affine_map.apply_line_map (to_affine_map e) a b c protected instance group {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : group (affine_equiv k P₁ P₁) := group.mk (fun (e e' : affine_equiv k P₁ P₁) => trans e' e) sorry (refl k P₁) trans_refl refl_trans symm (div_inv_monoid.div._default (fun (e e' : affine_equiv k P₁ P₁) => trans e' e) sorry (refl k P₁) trans_refl refl_trans symm) trans_symm theorem one_def {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : 1 = refl k P₁ := rfl @[simp] theorem coe_one {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] : ⇑1 = id := rfl theorem mul_def {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (e : affine_equiv k P₁ P₁) (e' : affine_equiv k P₁ P₁) : e * e' = trans e' e := rfl @[simp] theorem coe_mul {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (e : affine_equiv k P₁ P₁) (e' : affine_equiv k P₁ P₁) : ⇑(e * e') = ⇑e ∘ ⇑e' := rfl theorem inv_def {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (e : affine_equiv k P₁ P₁) : e⁻¹ = symm e := rfl /-- The map `v ↦ v +ᵥ b` as an affine equivalence between a module `V` and an affine space `P` with tangent space `V`. -/ def vadd_const (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (b : P₁) : affine_equiv k V₁ P₁ := mk (equiv.vadd_const b) (linear_equiv.refl k V₁) sorry @[simp] theorem linear_vadd_const (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (b : P₁) : linear (vadd_const k b) = linear_equiv.refl k V₁ := rfl @[simp] theorem vadd_const_apply (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (b : P₁) (v : V₁) : coe_fn (vadd_const k b) v = v +ᵥ b := rfl @[simp] theorem vadd_const_symm_apply (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (b : P₁) (p : P₁) : coe_fn (symm (vadd_const k b)) p = p -ᵥ b := rfl /-- `p' ↦ p -ᵥ p'` as an equivalence. -/ def const_vsub (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (p : P₁) : affine_equiv k P₁ V₁ := mk (equiv.const_vsub p) (linear_equiv.neg k) sorry @[simp] theorem coe_const_vsub (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (p : P₁) : ⇑(const_vsub k p) = has_vsub.vsub p := rfl @[simp] theorem coe_const_vsub_symm (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (p : P₁) : ⇑(symm (const_vsub k p)) = fun (v : V₁) => -v +ᵥ p := rfl /-- The map `p ↦ v +ᵥ p` as an affine automorphism of an affine space. -/ def const_vadd (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) : affine_equiv k P₁ P₁ := mk (equiv.const_vadd P₁ v) (linear_equiv.refl k V₁) sorry @[simp] theorem linear_const_vadd (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) : linear (const_vadd k P₁ v) = linear_equiv.refl k V₁ := rfl @[simp] theorem const_vadd_apply (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) (p : P₁) : coe_fn (const_vadd k P₁ v) p = v +ᵥ p := rfl @[simp] theorem const_vadd_symm_apply (k : Type u_1) {V₁ : Type u_2} (P₁ : Type u_6) [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) (p : P₁) : coe_fn (symm (const_vadd k P₁ v)) p = -v +ᵥ p := rfl /-- Point reflection in `x` as a permutation. -/ def point_reflection (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : affine_equiv k P₁ P₁ := trans (const_vsub k x) (vadd_const k x) theorem point_reflection_apply (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) (y : P₁) : coe_fn (point_reflection k x) y = x -ᵥ y +ᵥ x := rfl @[simp] theorem point_reflection_symm (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : symm (point_reflection k x) = point_reflection k x := injective_to_equiv (equiv.point_reflection_symm x) @[simp] theorem to_equiv_point_reflection (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : to_equiv (point_reflection k x) = equiv.point_reflection x := rfl @[simp] theorem point_reflection_self (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : coe_fn (point_reflection k x) x = x := vsub_vadd x x theorem point_reflection_involutive (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (x : P₁) : function.involutive ⇑(point_reflection k x) := equiv.point_reflection_involutive x /-- `x` is the only fixed point of `point_reflection x`. This lemma requires `x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/ theorem point_reflection_fixed_iff_of_injective_bit0 (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] {x : P₁} {y : P₁} (h : function.injective bit0) : coe_fn (point_reflection k x) y = y ↔ y = x := equiv.point_reflection_fixed_iff_of_injective_bit0 h theorem injective_point_reflection_left_of_injective_bit0 (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (h : function.injective bit0) (y : P₁) : function.injective fun (x : P₁) => coe_fn (point_reflection k x) y := equiv.injective_point_reflection_left_of_injective_bit0 h y theorem injective_point_reflection_left_of_module (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [invertible (bit0 1)] (y : P₁) : function.injective fun (x : P₁) => coe_fn (point_reflection k x) y := sorry theorem point_reflection_fixed_iff_of_module (k : Type u_1) {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] [invertible (bit0 1)] {x : P₁} {y : P₁} : coe_fn (point_reflection k x) y = y ↔ y = x := iff.trans (function.injective.eq_iff' (injective_point_reflection_left_of_module k y) (point_reflection_self k y)) eq_comm end affine_equiv namespace affine_map theorem line_map_vadd {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) (v' : V₁) (p : P₁) (c : k) : coe_fn (line_map v v') c +ᵥ p = coe_fn (line_map (v +ᵥ p) (v' +ᵥ p)) c := affine_equiv.apply_line_map (affine_equiv.vadd_const k p) v v' c theorem line_map_vsub {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (p₁ : P₁) (p₂ : P₁) (p₃ : P₁) (c : k) : coe_fn (line_map p₁ p₂) c -ᵥ p₃ = coe_fn (line_map (p₁ -ᵥ p₃) (p₂ -ᵥ p₃)) c := affine_equiv.apply_line_map (affine_equiv.symm (affine_equiv.vadd_const k p₃)) p₁ p₂ c theorem vsub_line_map {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (p₁ : P₁) (p₂ : P₁) (p₃ : P₁) (c : k) : p₁ -ᵥ coe_fn (line_map p₂ p₃) c = coe_fn (line_map (p₁ -ᵥ p₂) (p₁ -ᵥ p₃)) c := affine_equiv.apply_line_map (affine_equiv.const_vsub k p₁) p₂ p₃ c theorem vadd_line_map {k : Type u_1} {V₁ : Type u_2} {P₁ : Type u_6} [ring k] [add_comm_group V₁] [semimodule k V₁] [add_torsor V₁ P₁] (v : V₁) (p₁ : P₁) (p₂ : P₁) (c : k) : v +ᵥ coe_fn (line_map p₁ p₂) c = coe_fn (line_map (v +ᵥ p₁) (v +ᵥ p₂)) c := affine_equiv.apply_line_map (affine_equiv.const_vadd k P₁ v) p₁ p₂ c theorem homothety_neg_one_apply {V₁ : Type u_2} {P₁ : Type u_6} [add_comm_group V₁] [add_torsor V₁ P₁] {R' : Type u_10} [comm_ring R'] [semimodule R' V₁] (c : P₁) (p : P₁) : coe_fn (homothety c (-1)) p = coe_fn (affine_equiv.point_reflection R' c) p := sorry
ebf8379e7dbb145c64f737db620e305c8a06ffb9
f1dc39e1c68f71465c8bf79910c4664d03824751
/library/init/meta/expr.lean
452c51562f835d23ae5f027328a99543b45a0cc3
[ "Apache-2.0" ]
permissive
kckennylau/lean-2
6504f45da07bc98b098d726b74130103be25885c
c9a9368bc0fd600d832bd56c5cb2124b8a523ef9
refs/heads/master
1,659,140,308,864
1,589,361,166,000
1,589,361,166,000
263,748,786
0
0
null
1,589,405,915,000
1,589,405,915,000
null
UTF-8
Lean
false
false
21,843
lean
/- Copyright (c) 2016 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.level init.control.monad init.meta.rb_map universes u v open native /-- Column and line position in a Lean source file. -/ structure pos := (line : nat) (column : nat) instance : decidable_eq pos | ⟨l₁, c₁⟩ ⟨l₂, c₂⟩ := if h₁ : l₁ = l₂ then if h₂ : c₁ = c₂ then is_true (eq.rec_on h₁ (eq.rec_on h₂ rfl)) else is_false (λ contra, pos.no_confusion contra (λ e₁ e₂, absurd e₂ h₂)) else is_false (λ contra, pos.no_confusion contra (λ e₁ e₂, absurd e₁ h₁)) meta instance : has_to_format pos := ⟨λ ⟨l, c⟩, "⟨" ++ l ++ ", " ++ c ++ "⟩"⟩ /-- Auxiliary annotation for binders (Lambda and Pi). This information is only used for elaboration. The difference between `{}` and `⦃⦄` is how implicit arguments are treated that are *not* followed by explicit arguments. `{}` arguments are applied eagerly, while `⦃⦄` arguments are left partially applied: ```lean def foo {x : ℕ} : ℕ := x def bar ⦃x : ℕ⦄ : ℕ := x #check foo -- foo : ℕ #check bar -- bar : Π ⦃x : ℕ⦄, ℕ ``` -/ inductive binder_info /- `(x : α)` -/ | default /- `{x : α}` -/ | implicit /- `⦃x:α⦄` -/ | strict_implicit /- `[x : α]`. Should be inferred with typeclass resolution. -/ | inst_implicit /- Auxiliary internal attribute used to mark local constants representing recursive functions in recursive equations and `match` statements. -/ | aux_decl instance : has_repr binder_info := ⟨λ bi, match bi with | binder_info.default := "default" | binder_info.implicit := "implicit" | binder_info.strict_implicit := "strict_implicit" | binder_info.inst_implicit := "inst_implicit" | binder_info.aux_decl := "aux_decl" end⟩ /-- Macros are basically "promises" to build an expr by some C++ code, you can't build them in Lean. You can unfold a macro and force it to evaluate. They are used for - `sorry`. - Term placeholders (`_`) in `pexpr`s. - Expression annotations. See `expr.is_annotation`. - Meta-recursive calls. Eg: ``` meta def Y : (α → α) → α | f := f (Y f) ``` The `Y` that appears in `f (Y f)` is a macro. - Builtin projections: ``` structure foo := (mynat : ℕ) #print foo.mynat -- @[reducible] -- def foo.mynat : foo → ℕ := -- λ (c : foo), [foo.mynat c] ``` The thing in square brackets is a macro. - Ephemeral structures inside certain specialised C++ implemented tactics. -/ meta constant macro_def : Type /-- An expression. eg ```(4+5)```. The `elab` flag is indicates whether the `expr` has been elaborated and doesn't contain any placeholder macros. For example the equality `x = x` is represented in `expr ff` as ``app (app (const `eq _) x) x`` while in `expr tt` it is represented as ``app (app (app (const `eq _) t) x) x`` (one more argument). The VM replaces instances of this datatype with the C++ implementation. -/ meta inductive expr (elaborated : bool := tt) /- A bound variable with a de-Bruijn index. -/ | var : nat → expr /- A type universe: `Sort u` -/ | sort : level → expr /- A global constant. These include definitions, constants and inductive type stuff present in the environment as well as hard-coded definitions. -/ | const : name → list level → expr /- [WARNING] Do not trust the types for `mvar` and `local_const`, they are sometimes dummy values. Use `tactic.infer_type` instead. -/ /- An `mvar` is a 'hole' yet to be filled in by the elaborator or tactic state. -/ | mvar (unique : name) (pretty : name) (type : expr) : expr /- A local constant. For example, if our tactic state was `h : P ⊢ Q`, `h` would be a local constant. -/ | local_const (unique : name) (pretty : name) (bi : binder_info) (type : expr) : expr /- Function application. -/ | app : expr → expr → expr /- Lambda abstraction. eg ```(λ a : α, x)`` -/ | lam (var_name : name) (bi : binder_info) (var_type : expr) (body : expr) : expr /- Pi type constructor. eg ```(Π a : α, x)`` and ```(α → β)`` -/ | pi (var_name : name) (bi : binder_info) (var_type : expr) (body : expr) : expr /- An explicit let binding. -/ | elet (var_name : name) (type : expr) (assignment : expr) (body : expr) : expr /- A macro, see the docstring for `macro_def`. The list of expressions are local constants and metavariables that the macro depends on. -/ | macro : macro_def → list expr → expr variable {elab : bool} meta instance : inhabited expr := ⟨expr.sort level.zero⟩ /-- Get the name of the macro definition. -/ meta constant expr.macro_def_name (d : macro_def) : name meta def expr.mk_var (n : nat) : expr := expr.var n /-- Expressions can be annotated using an annotation macro during compilation. For example, a `have x:X, from p, q` expression will be compiled to `(λ x:X,q)(p)`, but nested in an annotation macro with the name `"have"`. These annotations have no real semantic meaning, but are useful for helping Lean's pretty printer. -/ meta constant expr.is_annotation : expr elab → option (name × expr elab) /-- Remove all macro annotations from the given `expr`. -/ meta def expr.erase_annotations : expr elab → expr elab | e := match e.is_annotation with | some (_, a) := expr.erase_annotations a | none := e end /-- Compares expressions, including binder names. -/ meta constant expr.has_decidable_eq : decidable_eq expr attribute [instance] expr.has_decidable_eq /-- Compares expressions while ignoring binder names. -/ meta constant expr.alpha_eqv : expr → expr → bool notation a ` =ₐ `:50 b:50 := expr.alpha_eqv a b = bool.tt protected meta constant expr.to_string : expr elab → string meta instance : has_to_string (expr elab) := ⟨expr.to_string⟩ meta instance : has_to_format (expr elab) := ⟨λ e, e.to_string⟩ /-- Coercion for letting users write (f a) instead of (expr.app f a) -/ meta instance : has_coe_to_fun (expr elab) := { F := λ e, expr elab → expr elab, coe := λ e, expr.app e } /-- Each expression created by Lean carries a hash. This is calculated upon creation of the expression. Two structurally equal expressions will have the same hash. -/ meta constant expr.hash : expr → nat /-- Compares expressions, ignoring binder names, and sorting by hash. -/ meta constant expr.lt : expr → expr → bool /-- Compares expressions, ignoring binder names. -/ meta constant expr.lex_lt : expr → expr → bool /-- `expr.fold e a f`: Traverses each subexpression of `e`. The `nat` passed to the folder `f` is the binder depth. -/ meta constant expr.fold {α : Type} : expr → α → (expr → nat → α → α) → α /-- `expr.replace e f` Traverse over an expr `e` with a function `f` which can decide to replace subexpressions or not. For each subexpression `s` in the expression tree, `f s n` is called where `n` is how many binders are present above the given subexpression `s`. If `f s n` returns `none`, the children of `s` will be traversed. Otherwise if `some s'` is returned, `s'` will replace `s` and this subexpression will not be traversed further. -/ meta constant expr.replace : expr → (expr → nat → option expr) → expr /-- `abstract_local e n` replaces each instance of the local constant with unique (not pretty) name `n` in `e` with a de-Bruijn variable. -/ meta constant expr.abstract_local : expr → name → expr /-- Multi version of `abstract_local`. Note that the given expression will only be traversed once, so this is not the same as `list.foldl expr.abstract_local`.-/ meta constant expr.abstract_locals : expr → list name → expr /-- `abstract e x` Abstracts the expression `e` over the local constant `x`. -/ meta def expr.abstract : expr → expr → expr | e (expr.local_const n m bi t) := e.abstract_local n | e _ := e /-- Expressions depend on `level`s, and these may depend on universe parameters which have names. `instantiate_univ_params e [(n₁,l₁), ...]` will traverse `e` and replace any universe parameters with name `nᵢ` with the corresponding level `lᵢ`. -/ meta constant expr.instantiate_univ_params : expr → list (name × level) → expr /-- `instantiate_nth_var n a b` takes the `n`th de-Bruijn variable in `a` and replaces each occurrence with `b`. -/ meta constant expr.instantiate_nth_var : nat → expr → expr → expr /-- `instantiate_var a b` takes the 0th de-Bruijn variable in `a` and replaces each occurrence with `b`. -/ meta constant expr.instantiate_var : expr → expr → expr /-- ``instantiate_vars `(#0 #1 #2) [x,y,z] = `(%%x %%y %%z)`` -/ meta constant expr.instantiate_vars : expr → list expr → expr /-- Perform beta-reduction if the left expression is a lambda, or construct an application otherwise. That is: ``expr.subst `(λ x, %%Y) Z = Y[x/Z]``, and ``expr.subst X Z = X.app Z`` otherwise -/ protected meta constant expr.subst : expr elab → expr elab → expr elab /-- `get_free_var_range e` returns one plus the maximum de-Bruijn value in `e`. Eg `get_free_var_range `(#1 #0)` yields `2` -/ meta constant expr.get_free_var_range : expr → nat /-- `has_var e` returns true iff e has free variables. -/ meta constant expr.has_var : expr → bool /-- `has_var_idx e n` returns true iff `e` has a free variable with de-Bruijn index `n`. -/ meta constant expr.has_var_idx : expr → nat → bool /-- `has_local e` returns true if `e` contains a local constant. -/ meta constant expr.has_local : expr → bool /-- `has_meta_var e` returns true iff `e` contains a metavariable. -/ meta constant expr.has_meta_var : expr → bool /-- `lower_vars e s d` lowers the free variables >= s in `e` by `d`. Note that this can cause variable clashes. examples: - ``lower_vars `(#2 #1 #0) 1 1 = `(#1 #0 #0)`` - ``lower_vars `(λ x, #2 #1 #0) 1 1 = `(λ x, #1 #1 #0 )`` -/ meta constant expr.lower_vars : expr → nat → nat → expr /-- Lifts free variables. `lift_vars e s d` will lift all free variables with index `≥ s` in `e` by `d`. -/ meta constant expr.lift_vars : expr → nat → nat → expr /-- Get the position of the given expression in the Lean source file, if anywhere. -/ protected meta constant expr.pos : expr elab → option pos /-- `copy_pos_info src tgt` copies position information from `src` to `tgt`. -/ meta constant expr.copy_pos_info : expr → expr → expr /-- Returns `some n` when the given expression is a constant with the name `..._cnstr.n` ``` is_internal_cnstr : expr → option unsigned |(const (mk_numeral n (mk_string "_cnstr" _)) _) := some n |_ := none ``` [NOTE] This is not used anywhere in core Lean. -/ meta constant expr.is_internal_cnstr : expr → option unsigned /-- There is a macro called a "nat_value_macro" holding a natural number which are used during compilation. This function extracts that to a natural number. [NOTE] This is not used anywhere in Lean. -/ meta constant expr.get_nat_value : expr → option nat /-- Get a list of all of the universe parameters that the given expression depends on. -/ meta constant expr.collect_univ_params : expr → list name /-- `occurs e t` returns `tt` iff `e` occurs in `t` up to α-equivalence. Purely structural: no unification or definitional equality. -/ meta constant expr.occurs : expr → expr → bool /-- Returns true if any of the names in the given `name_set` are present in the given `expr`. -/ meta constant expr.has_local_in : expr → name_set → bool /-- Computes the number of sub-expressions (constant time). -/ meta constant expr.get_weight : expr → ℕ /-- Computes the maximum depth of the expression (constant time). -/ meta constant expr.get_depth : expr → ℕ /-- `mk_delayed_abstraction m ls` creates a delayed abstraction on the metavariable `m` with the unique names of the local constants `ls`. If `m` is not a metavariable then this is equivalent to `abstract_locals`. -/ meta constant expr.mk_delayed_abstraction : expr → list name → expr /-- (reflected a) is a special opaque container for a closed `expr` representing `a`. It can only be obtained via type class inference, which will use the representation of `a` in the calling context. Local constants in the representation are replaced by nested inference of `reflected` instances. The quotation expression `` `(a) `` (outside of patterns) is equivalent to `reflect a` and thus can be used as an explicit way of inferring an instance of `reflected a`. -/ @[class] meta def reflected {α : Sort u} : α → Type := λ _, expr @[inline] meta def reflected.to_expr {α : Sort u} {a : α} : reflected a → expr := id @[inline] meta def reflected.subst {α : Sort v} {β : α → Sort u} {f : Π a : α, β a} {a : α} : reflected f → reflected a → reflected (f a) := expr.subst attribute [irreducible] reflected reflected.subst reflected.to_expr @[instance] protected meta constant expr.reflect (e : expr elab) : reflected e @[instance] protected meta constant string.reflect (s : string) : reflected s @[inline] meta instance {α : Sort u} (a : α) : has_coe (reflected a) expr := ⟨reflected.to_expr⟩ protected meta def reflect {α : Sort u} (a : α) [h : reflected a] : reflected a := h meta instance {α} (a : α) : has_to_format (reflected a) := ⟨λ h, to_fmt h.to_expr⟩ namespace expr open decidable meta def expr.lt_prop (a b : expr) : Prop := expr.lt a b = tt meta instance : decidable_rel expr.lt_prop := λ a b, bool.decidable_eq _ _ /-- Compares expressions, ignoring binder names, and sorting by hash. -/ meta instance : has_lt expr := ⟨ expr.lt_prop ⟩ meta def mk_true : expr := const `true [] meta def mk_false : expr := const `false [] /-- Returns the sorry macro with the given type. -/ meta constant mk_sorry (type : expr) : expr /-- Checks whether e is sorry, and returns its type. -/ meta constant is_sorry (e : expr) : option expr /-- Replace each instance of the local constant with name `n` by the expression `s` in `e`. -/ meta def instantiate_local (n : name) (s : expr) (e : expr) : expr := instantiate_var (abstract_local e n) s meta def instantiate_locals (s : list (name × expr)) (e : expr) : expr := instantiate_vars (abstract_locals e (list.reverse (list.map prod.fst s))) (list.map prod.snd s) meta def is_var : expr → bool | (var _) := tt | _ := ff meta def app_of_list : expr → list expr → expr | f [] := f | f (p::ps) := app_of_list (f p) ps meta def is_app : expr → bool | (app f a) := tt | e := ff meta def app_fn : expr → expr | (app f a) := f | a := a meta def app_arg : expr → expr | (app f a) := a | a := a meta def get_app_fn : expr elab → expr elab | (app f a) := get_app_fn f | a := a meta def get_app_num_args : expr → nat | (app f a) := get_app_num_args f + 1 | e := 0 meta def get_app_args_aux : list expr → expr → list expr | r (app f a) := get_app_args_aux (a::r) f | r e := r meta def get_app_args : expr → list expr := get_app_args_aux [] meta def mk_app : expr → list expr → expr | e [] := e | e (x::xs) := mk_app (e x) xs meta def mk_binding (ctor : name → binder_info → expr → expr → expr) (e : expr) : Π (l : expr), expr | (local_const n pp_n bi ty) := ctor pp_n bi ty (e.abstract_local n) | _ := e /-- (bind_pi e l) abstracts and pi-binds the local `l` in `e` -/ meta def bind_pi := mk_binding pi /-- (bind_lambda e l) abstracts and lambda-binds the local `l` in `e` -/ meta def bind_lambda := mk_binding lam meta def ith_arg_aux : expr → nat → expr | (app f a) 0 := a | (app f a) (n+1) := ith_arg_aux f n | e _ := e meta def ith_arg (e : expr) (i : nat) : expr := ith_arg_aux e (get_app_num_args e - i - 1) meta def const_name : expr elab → name | (const n ls) := n | e := name.anonymous meta def is_constant : expr elab → bool | (const n ls) := tt | e := ff meta def is_local_constant : expr → bool | (local_const n m bi t) := tt | e := ff meta def local_uniq_name : expr → name | (local_const n m bi t) := n | e := name.anonymous meta def local_pp_name : expr elab → name | (local_const x n bi t) := n | e := name.anonymous meta def local_type : expr elab → expr elab | (local_const _ _ _ t) := t | e := e meta def is_aux_decl : expr → bool | (local_const _ _ binder_info.aux_decl _) := tt | _ := ff meta def is_constant_of : expr elab → name → bool | (const n₁ ls) n₂ := n₁ = n₂ | e n := ff meta def is_app_of (e : expr) (n : name) : bool := is_constant_of (get_app_fn e) n /-- The same as `is_app_of` but must also have exactly `n` arguments. -/ meta def is_napp_of (e : expr) (c : name) (n : nat) : bool := is_app_of e c ∧ get_app_num_args e = n meta def is_false : expr → bool | `(false) := tt | _ := ff meta def is_not : expr → option expr | `(not %%a) := some a | `(%%a → false) := some a | e := none meta def is_and : expr → option (expr × expr) | `(and %%α %%β) := some (α, β) | _ := none meta def is_or : expr → option (expr × expr) | `(or %%α %%β) := some (α, β) | _ := none meta def is_iff : expr → option (expr × expr) | `((%%a : Prop) ↔ %%b) := some (a, b) | _ := none meta def is_eq : expr → option (expr × expr) | `((%%a : %%_) = %%b) := some (a, b) | _ := none meta def is_ne : expr → option (expr × expr) | `((%%a : %%_) ≠ %%b) := some (a, b) | _ := none meta def is_bin_arith_app (e : expr) (op : name) : option (expr × expr) := if is_napp_of e op 4 then some (app_arg (app_fn e), app_arg e) else none meta def is_lt (e : expr) : option (expr × expr) := is_bin_arith_app e ``has_lt.lt meta def is_gt (e : expr) : option (expr × expr) := is_bin_arith_app e ``gt meta def is_le (e : expr) : option (expr × expr) := is_bin_arith_app e ``has_le.le meta def is_ge (e : expr) : option (expr × expr) := is_bin_arith_app e ``ge meta def is_heq : expr → option (expr × expr × expr × expr) | `(@heq %%α %%a %%β %%b) := some (α, a, β, b) | _ := none meta def is_lambda : expr → bool | (lam _ _ _ _) := tt | e := ff meta def is_pi : expr → bool | (pi _ _ _ _) := tt | e := ff meta def is_arrow : expr → bool | (pi _ _ _ b) := bnot (has_var b) | e := ff meta def is_let : expr → bool | (elet _ _ _ _) := tt | e := ff meta def binding_name : expr → name | (pi n _ _ _) := n | (lam n _ _ _) := n | e := name.anonymous meta def binding_info : expr → binder_info | (pi _ bi _ _) := bi | (lam _ bi _ _) := bi | e := binder_info.default meta def binding_domain : expr → expr | (pi _ _ d _) := d | (lam _ _ d _) := d | e := e meta def binding_body : expr → expr | (pi _ _ _ b) := b | (lam _ _ _ b) := b | e := e meta def is_macro : expr → bool | (macro d a) := tt | e := ff meta def is_numeral : expr → bool | `(@has_zero.zero %%α %%s) := tt | `(@has_one.one %%α %%s) := tt | `(@bit0 %%α %%s %%v) := is_numeral v | `(@bit1 %%α %%s₁ %%s₂ %%v) := is_numeral v | _ := ff meta def imp (a b : expr) : expr := pi `_ binder_info.default a b /-- `lambdas cs e` lambda binds `e` with each of the local constants in `cs`. -/ meta def lambdas : list expr → expr → expr | (local_const uniq pp info t :: es) f := lam pp info t (abstract_local (lambdas es f) uniq) | _ f := f /-- Same as `expr.lambdas` but with `pi`. -/ meta def pis : list expr → expr → expr | (local_const uniq pp info t :: es) f := pi pp info t (abstract_local (pis es f) uniq) | _ f := f meta def extract_opt_auto_param : expr → expr | `(@opt_param %%t _) := extract_opt_auto_param t | `(@auto_param %%t _) := extract_opt_auto_param t | e := e open format private meta def p := λ xs, paren (format.join (list.intersperse " " xs)) meta def to_raw_fmt : expr elab → format | (var n) := p ["var", to_fmt n] | (sort l) := p ["sort", to_fmt l] | (const n ls) := p ["const", to_fmt n, to_fmt ls] | (mvar n m t) := p ["mvar", to_fmt n, to_fmt m, to_raw_fmt t] | (local_const n m bi t) := p ["local_const", to_fmt n, to_fmt m, to_raw_fmt t] | (app e f) := p ["app", to_raw_fmt e, to_raw_fmt f] | (lam n bi e t) := p ["lam", to_fmt n, repr bi, to_raw_fmt e, to_raw_fmt t] | (pi n bi e t) := p ["pi", to_fmt n, repr bi, to_raw_fmt e, to_raw_fmt t] | (elet n g e f) := p ["elet", to_fmt n, to_raw_fmt g, to_raw_fmt e, to_raw_fmt f] | (macro d args) := sbracket (format.join (list.intersperse " " ("macro" :: to_fmt (macro_def_name d) :: args.map to_raw_fmt))) /-- Fold an accumulator `a` over each subexpression in the expression `e`. The `nat` passed to `fn` is the number of binders above the subexpression. -/ meta def mfold {α : Type} {m : Type → Type} [monad m] (e : expr) (a : α) (fn : expr → nat → α → m α) : m α := fold e (return a) (λ e n a, a >>= fn e n) end expr /-- An dictionary from `data` to expressions. -/ @[reducible] meta def expr_map (data : Type) := rb_map expr data namespace expr_map export native.rb_map (hiding mk) meta def mk (data : Type) : expr_map data := rb_map.mk expr data end expr_map meta def mk_expr_map {data : Type} : expr_map data := expr_map.mk data @[reducible] meta def expr_set := rb_set expr meta def mk_expr_set : expr_set := mk_rb_set
059e67f6e15f71dca3a5a357a82a697b185fffc6
041929c569a4eeeafb4efdddab8a644f6df383c5
/src/mazes/gcd_maze/level_challenge.lean
18546400e5fe1c0db4ad920e27eb61a44dac6fa0
[]
no_license
kbuzzard/xena-maze-game
30ffbe956762dd6603e74efd823d375649e037c3
098454dd6acc4c06beccf52b6547bf4cd99cc581
refs/heads/master
1,670,840,300,174
1,598,554,198,000
1,598,554,198,000
290,856,036
4
0
null
null
null
null
UTF-8
Lean
false
false
1,968
lean
-- import the definition of the gcd maze import mazes.gcd_maze.definition import data.int.gcd open maze direction /- # Prove Bezout's Theorem You are in a maze of integers, all distinct. You can go north, south east or west. North adds `a` to your integer, South subtracts `a`. East adds `b` to your integer, West subtracts `b`. You start at 0. The exit is at `nat.gcd a b`. Can you prove you can always exit? Solver remark : there are infinitely many mazes. -/ /- Lemma : no-side-bar Can you prove you can escape in the general case? -/ theorem challenge (A B : ℕ) : can_escape A B 0 := begin have solution : can_escape A B (nat.gcd A B), out, have hs : ∀ t l : ℕ, can_escape A B t → can_escape A B (t + l*A), { intros t l, induction l with d hd, { intro h, convert h, simp }, intro h, specialize hd h, s, convert hd, ring }, have hns : ∀ t : ℤ, ∀ l : ℤ, can_escape A B t → can_escape A B (t + l * A), { intros t l, apply int.induction_on l; clear l, { intro h, convert h, ring}, { intros d hd, intro h, specialize hd h, s, convert hd, ring, }, { intros d hd, intro h, specialize hd h, n, convert hd using 1, ring, } }, have hew : ∀ t : ℤ, ∀ m : ℤ, can_escape A B t → can_escape A B (t + m * B), { intros t l, apply int.induction_on l; clear l, { intro h, convert h, ring}, { intros d hd, intro h, specialize hd h, w, convert hd, ring, }, { intros d hd, intro h, specialize hd h, e, convert hd using 1, ring, } }, suffices : ∃ L M : ℤ, L * A + M * B = nat.gcd A B, { rcases this with ⟨L, M, h⟩, rw ← h at solution, specialize hew _ (-M) solution, simp at hew, specialize hns _ (-L) hew, convert hns, ring, }, have h := nat.gcd_eq_gcd_ab A B, rw h, use [A.gcd_a B, A.gcd_b B], ring, end
6ac84a590746728b89f0da0c0b228b7074ce1f59
4727251e0cd73359b15b664c3170e5d754078599
/archive/imo/imo1981_q3.lean
ea34d76d03bf25a877b304e16002a3f60ab57cee
[ "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
6,835
lean
/- Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import data.nat.fib import tactic.linarith /-! # IMO 1981 Q3 Determine the maximum value of `m ^ 2 + n ^ 2`, where `m` and `n` are integers in `{1, 2, ..., 1981}` and `(n ^ 2 - m * n - m ^ 2) ^ 2 = 1`. The trick to this problem is that `m` and `n` have to be consecutive Fibonacci numbers, because you can reduce any solution to a smaller one using the Fibonacci recurrence. -/ /- First, define the problem in terms of finding the maximum of a set. We first generalize the problem to `{1, 2, ..., N}` and specialize to `N = 1981` at the very end. -/ open int nat set section variable (N : ℕ) -- N = 1981 @[mk_iff] structure problem_predicate (m n : ℤ) : Prop := (m_range : m ∈ Ioc 0 (N : ℤ)) (n_range : n ∈ Ioc 0 (N : ℤ)) (eq_one : (n ^ 2 - m * n - m ^ 2) ^ 2 = 1) def specified_set : set ℤ := {k : ℤ | ∃ m : ℤ, ∃ n : ℤ, k = m ^ 2 + n ^ 2 ∧ problem_predicate N m n} /- We want to reduce every solution to a smaller solution. Specifically, we show that when `(m, n)` is a solution, `(n - m, m)` is also a solution, except for the base case of `(1, 1)`. -/ namespace problem_predicate variable {N} lemma m_le_n {m n : ℤ} (h1 : problem_predicate N m n) : m ≤ n := begin by_contradiction h2, have h3 : 1 = (n * (n - m) - m ^ 2) ^ 2, { calc 1 = (n ^ 2 - m * n - m ^ 2) ^ 2 : h1.eq_one.symm ... = (n * (n - m) - m ^ 2) ^ 2 : by ring }, have h4 : n * (n - m) - m ^ 2 < -1, by nlinarith [h1.n_range.left], have h5 : 1 < (n * (n - m) - m ^ 2) ^ 2, by nlinarith, exact h5.ne h3 end lemma eq_imp_1 {n : ℤ} (h1 : problem_predicate N n n) : n = 1 := begin have : n * (n * (n * n)) = 1, { calc _ = (n ^ 2 - n * n - n ^ 2) ^ 2 : by simp [sq, mul_assoc] ... = 1 : h1.eq_one }, exact eq_one_of_mul_eq_one_right h1.m_range.left.le this, end lemma reduction {m n : ℤ} (h1 : problem_predicate N m n) (h2 : 1 < n) : problem_predicate N (n - m) m := begin obtain (rfl : m = n) | (h3 : m < n) := h1.m_le_n.eq_or_lt, { have h4 : m = 1, from h1.eq_imp_1, exact absurd h4.symm h2.ne }, refine_struct { n_range := h1.m_range, .. }, -- m_range: { have h5 : 0 < n - m, from sub_pos.mpr h3, have h6 : n - m < N, { calc _ < n : sub_lt_self n h1.m_range.left ... ≤ N : h1.n_range.right }, exact ⟨h5, h6.le⟩ }, -- eq_one: { calc _ = (n ^ 2 - m * n - m ^ 2) ^ 2 : by ring ... = 1 : h1.eq_one }, end end problem_predicate /- It will be convenient to have the lemmas above in their natural number form. Most of these can be proved with the `norm_cast` family of tactics. -/ def nat_predicate (m n : ℕ) : Prop := problem_predicate N ↑m ↑n namespace nat_predicate variable {N} lemma m_le_n {m n : ℕ} (h1 : nat_predicate N m n) : m ≤ n := by exact_mod_cast h1.m_le_n lemma eq_imp_1 {n : ℕ} (h1 : nat_predicate N n n) : n = 1 := by exact_mod_cast h1.eq_imp_1 lemma reduction {m n : ℕ} (h1 : nat_predicate N m n) (h2 : 1 < n) : nat_predicate N (n - m) m := have m ≤ n, from h1.m_le_n, by exact_mod_cast h1.reduction (by exact_mod_cast h2) lemma n_pos {m n : ℕ} (h1 : nat_predicate N m n) : 0 < n := by exact_mod_cast h1.n_range.left lemma m_pos {m n : ℕ} (h1 : nat_predicate N m n) : 0 < m := by exact_mod_cast h1.m_range.left lemma n_le_N {m n : ℕ} (h1 : nat_predicate N m n) : n ≤ N := by exact_mod_cast h1.n_range.right /- Now we can use induction to show that solutions must be Fibonacci numbers. -/ lemma imp_fib {n : ℕ} : ∀ m : ℕ, nat_predicate N m n → ∃ k : ℕ, m = fib k ∧ n = fib (k + 1) := begin apply nat.strong_induction_on n _, intros n h1 m h2, have h3 : m ≤ n, from h2.m_le_n, obtain (rfl : 1 = n) | (h4 : 1 < n) := (succ_le_iff.mpr h2.n_pos).eq_or_lt, { use 1, have h5 : 1 ≤ m, from succ_le_iff.mpr h2.m_pos, simpa [fib_one, fib_two] using (h3.antisymm h5 : m = 1) }, { obtain (rfl : m = n) | (h6 : m < n) := h3.eq_or_lt, { exact absurd h2.eq_imp_1 (ne_of_gt h4) }, { have h7 : nat_predicate N (n - m) m, from h2.reduction h4, obtain ⟨k : ℕ, hnm : n - m = fib k, rfl : m = fib (k+1)⟩ := h1 m h6 (n - m) h7, use [k + 1, rfl], rw [fib_add_two, ← hnm, tsub_add_cancel_of_le h3] } } end end nat_predicate /- Next, we prove that if `N < fib K + fib (K+1)`, then the largest `m` and `n` satisfying `nat_predicate m n N` are `fib K` and `fib (K+1)`, respectively. -/ variables {K : ℕ} (HK : N < fib K + fib (K+1)) {N} include HK lemma m_n_bounds {m n : ℕ} (h1 : nat_predicate N m n) : m ≤ fib K ∧ n ≤ fib (K+1) := begin obtain ⟨k : ℕ, hm : m = fib k, hn : n = fib (k+1)⟩ := h1.imp_fib m, by_cases h2 : k < K + 1, { have h3 : k ≤ K, from lt_succ_iff.mp h2, split, { calc m = fib k : hm ... ≤ fib K : fib_mono h3, }, { have h6 : k + 1 ≤ K + 1, from succ_le_succ h3, calc n = fib (k+1) : hn ... ≤ fib (K+1) : fib_mono h6 } }, { have h7 : N < n, { have h8 : K + 2 ≤ k + 1, from succ_le_succ (not_lt.mp h2), rw ← fib_add_two at HK, calc N < fib (K+2) : HK ... ≤ fib (k+1) : fib_mono h8 ... = n : hn.symm, }, have h9 : n ≤ N, from h1.n_le_N, exact absurd h7 h9.not_lt } end /- We spell out the consequences of this result for `specified_set N` here. -/ variables {M : ℕ} (HM : M = (fib K) ^ 2 + (fib (K+1)) ^ 2) include HM lemma k_bound {m n : ℤ} (h1 : problem_predicate N m n) : m ^ 2 + n ^ 2 ≤ M := begin have h2 : 0 ≤ m, from h1.m_range.left.le, have h3 : 0 ≤ n, from h1.n_range.left.le, rw [← nat_abs_of_nonneg h2, ← nat_abs_of_nonneg h3] at h1, clear h2 h3, obtain ⟨h4 : m.nat_abs ≤ fib K, h5 : n.nat_abs ≤ fib (K+1)⟩ := m_n_bounds HK h1, have h6 : m ^ 2 ≤ (fib K) ^ 2, from nat_abs_le_iff_sq_le.mp h4, have h7 : n ^ 2 ≤ (fib (K+1)) ^ 2, from nat_abs_le_iff_sq_le.mp h5, linarith end lemma solution_bound : ∀ {k : ℤ}, k ∈ specified_set N → k ≤ M | _ ⟨_, _, rfl, h⟩ := k_bound HK HM h theorem solution_greatest (H : problem_predicate N (fib K) (fib (K + 1))) : is_greatest (specified_set N) M := ⟨⟨fib K, fib (K+1), by simp [HM], H⟩, λ k h, solution_bound HK HM h⟩ end /- Now we just have to demonstrate that 987 and 1597 are in fact the largest Fibonacci numbers in this range, and thus provide the maximum of `specified_set`. -/ theorem imo1981_q3 : is_greatest (specified_set 1981) 3524578 := begin have := λ h, @solution_greatest 1981 16 h 3524578, simp only [show fib (16:ℕ) = 987 ∧ fib (16+1:ℕ) = 1597, by norm_num [fib_add_two]] at this, apply_mod_cast this; norm_num [problem_predicate_iff], end
b88200ee45693516e65f68825294a9eda95258db
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/stage0/src/Init/Lean/Parser/Parser.lean
c8d57d0e058f717ca8691013b6b2325599205d3b
[ "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
78,665
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, Sebastian Ullrich -/ prelude import Init.Lean.Data.Trie import Init.Lean.Data.Position import Init.Lean.Syntax import Init.Lean.ToExpr import Init.Lean.Environment import Init.Lean.Attributes import Init.Lean.Message import Init.Lean.Compiler.InitAttr namespace Lean namespace Parser def isLitKind (k : SyntaxNodeKind) : Bool := k == strLitKind || k == numLitKind || k == charLitKind || k == nameLitKind abbrev mkAtom (info : SourceInfo) (val : String) : Syntax := Syntax.atom info val abbrev mkIdent (info : SourceInfo) (rawVal : Substring) (val : Name) : Syntax := Syntax.ident (some info) rawVal val [] /- Return character after position `pos` -/ def getNext (input : String) (pos : Nat) : Char := input.get (input.next pos) /- Function application precedence. In the standard lean language, only two tokens have precedence higher that `appPrec`. - The token `.` has precedence `appPrec+1`. Thus, field accesses like `g (h x).f` are parsed as `g ((h x).f)`, not `(g (h x)).f` - The token `[` when not preceded with whitespace has precedence `appPrec+1`. If there is whitespace before `[`, then its precedence is `appPrec`. Thus, `f a[i]` is parsed as `f (a[i])` where `a[i]` is an "find-like operation" (e.g., array access, map access, etc.). `f a [i]` is parsed as `(f a) [i]` where `[i]` is a singleton collection (e.g., a list). -/ def appPrec : Nat := 1024 structure TokenConfig := (val : String) (lbp : Option Nat := none) (lbpNoWs : Option Nat := none) -- optional left-binding power when there is not whitespace before the token. namespace TokenConfig def beq : TokenConfig → TokenConfig → Bool | ⟨val₁, lbp₁, lbpnws₁⟩, ⟨val₂, lbp₂, lbpnws₂⟩ => val₁ == val₂ && lbp₁ == lbp₂ && lbpnws₁ == lbpnws₂ instance : HasBeq TokenConfig := ⟨beq⟩ def toStr : TokenConfig → String | ⟨val, some lbp, some lbpnws⟩ => val ++ ":" ++ toString lbp ++ ":" ++ toString lbpnws | ⟨val, some lbp, none⟩ => val ++ ":" ++ toString lbp | ⟨val, none, some lbpnws⟩ => val ++ ":none:" ++ toString lbpnws | ⟨val, none, none⟩ => val instance : HasToString TokenConfig := ⟨toStr⟩ end TokenConfig structure TokenCacheEntry := (startPos stopPos : String.Pos := 0) (token : Syntax := Syntax.missing) structure ParserCache := (tokenCache : TokenCacheEntry := {}) def initCacheForInput (input : String) : ParserCache := { tokenCache := { startPos := input.bsize + 1 /- make sure it is not a valid position -/} } abbrev TokenTable := Trie TokenConfig abbrev SyntaxNodeKindSet := PersistentHashMap SyntaxNodeKind Unit def SyntaxNodeKindSet.insert (s : SyntaxNodeKindSet) (k : SyntaxNodeKind) : SyntaxNodeKindSet := s.insert k () /- Input string and related data. Recall that the `FileMap` is a helper structure for mapping `String.Pos` in the input string to line/column information. -/ structure InputContext := (input : String) (fileName : String) (fileMap : FileMap) instance InputContext.inhabited : Inhabited InputContext := ⟨{ input := "", fileName := "", fileMap := arbitrary _ }⟩ structure ParserContext extends InputContext := (rbp : Nat) (env : Environment) (tokens : TokenTable) structure Error := (unexpected : String := "") (expected : List String := []) namespace Error instance : Inhabited Error := ⟨{}⟩ private def expectedToString : List String → String | [] => "" | [e] => e | [e1, e2] => e1 ++ " or " ++ e2 | e::es => e ++ ", " ++ expectedToString es protected def toString (e : Error) : String := let unexpected := if e.unexpected == "" then [] else [e.unexpected]; let expected := if e.expected == [] then [] else let expected := e.expected.toArray.qsort (fun e e' => e < e'); let expected := expected.toList.eraseReps; ["expected " ++ expectedToString expected]; "; ".intercalate $ unexpected ++ expected instance : HasToString Error := ⟨Error.toString⟩ protected def beq (e₁ e₂ : Error) : Bool := e₁.unexpected == e₂.unexpected && e₁.expected == e₂.expected instance : HasBeq Error := ⟨Error.beq⟩ def merge (e₁ e₂ : Error) : Error := match e₂ with | { unexpected := u, .. } => { unexpected := if u == "" then e₁.unexpected else u, expected := e₁.expected ++ e₂.expected } end Error structure ParserState := (stxStack : Array Syntax := #[]) (pos : String.Pos := 0) (cache : ParserCache := {}) (errorMsg : Option Error := none) namespace ParserState @[inline] def hasError (s : ParserState) : Bool := s.errorMsg != none @[inline] def stackSize (s : ParserState) : Nat := s.stxStack.size def restore (s : ParserState) (iniStackSz : Nat) (iniPos : Nat) : ParserState := { stxStack := s.stxStack.shrink iniStackSz, errorMsg := none, pos := iniPos, .. s} def setPos (s : ParserState) (pos : Nat) : ParserState := { pos := pos, .. s } def setCache (s : ParserState) (cache : ParserCache) : ParserState := { cache := cache, .. s } def pushSyntax (s : ParserState) (n : Syntax) : ParserState := { stxStack := s.stxStack.push n, .. s } def popSyntax (s : ParserState) : ParserState := { stxStack := s.stxStack.pop, .. s } def shrinkStack (s : ParserState) (iniStackSz : Nat) : ParserState := { stxStack := s.stxStack.shrink iniStackSz, .. s } def next (s : ParserState) (input : String) (pos : Nat) : ParserState := { pos := input.next pos, .. s } def toErrorMsg (ctx : ParserContext) (s : ParserState) : String := match s.errorMsg with | none => "" | some msg => let pos := ctx.fileMap.toPosition s.pos; mkErrorStringWithPos ctx.fileName pos.line pos.column (toString msg) def mkNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, pos, cache, err⟩ => if err != none && stack.size == iniStackSz then -- If there is an error but there are no new nodes on the stack, we just return `s` s else let newNode := Syntax.node k (stack.extract iniStackSz stack.size); let stack := stack.shrink iniStackSz; let stack := stack.push newNode; ⟨stack, pos, cache, err⟩ def mkTrailingNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, pos, cache, err⟩ => let newNode := Syntax.node k (stack.extract (iniStackSz - 1) stack.size); let stack := stack.shrink iniStackSz; let stack := stack.push newNode; ⟨stack, pos, cache, err⟩ def mkError (s : ParserState) (msg : String) : ParserState := match s with | ⟨stack, pos, cache, _⟩ => ⟨stack, pos, cache, some { expected := [ msg ] }⟩ def mkUnexpectedError (s : ParserState) (msg : String) : ParserState := match s with | ⟨stack, pos, cache, _⟩ => ⟨stack, pos, cache, some { unexpected := msg }⟩ def mkEOIError (s : ParserState) : ParserState := s.mkUnexpectedError "end of input" def mkErrorAt (s : ParserState) (msg : String) (pos : String.Pos) : ParserState := match s with | ⟨stack, _, cache, _⟩ => ⟨stack, pos, cache, some { expected := [ msg ] }⟩ def mkErrorsAt (s : ParserState) (ex : List String) (pos : String.Pos) : ParserState := match s with | ⟨stack, _, cache, _⟩ => ⟨stack, pos, cache, some { expected := ex }⟩ def mkUnexpectedErrorAt (s : ParserState) (msg : String) (pos : String.Pos) : ParserState := match s with | ⟨stack, _, cache, _⟩ => ⟨stack, pos, cache, some { unexpected := msg }⟩ end ParserState def ParserFn := ParserContext → ParserState → ParserState instance ParserFn.inhabited : Inhabited ParserFn := ⟨fun _ => id⟩ inductive FirstTokens | epsilon : FirstTokens | unknown : FirstTokens | tokens : List TokenConfig → FirstTokens | optTokens : List TokenConfig → FirstTokens namespace FirstTokens def seq : FirstTokens → FirstTokens → FirstTokens | epsilon, tks => tks | optTokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | optTokens s₁, tokens s₂ => tokens (s₁ ++ s₂) | tks, _ => tks def toOptional : FirstTokens → FirstTokens | tokens tks => optTokens tks | tks => tks def merge : FirstTokens → FirstTokens → FirstTokens | epsilon, tks => toOptional tks | tks, epsilon => toOptional tks | tokens s₁, tokens s₂ => tokens (s₁ ++ s₂) | optTokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | tokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | optTokens s₁, tokens s₂ => optTokens (s₁ ++ s₂) | _, _ => unknown def toStr : FirstTokens → String | epsilon => "epsilon" | unknown => "unknown" | tokens tks => toString tks | optTokens tks => "?" ++ toString tks instance : HasToString FirstTokens := ⟨toStr⟩ end FirstTokens structure ParserInfo := (collectTokens : List TokenConfig → List TokenConfig := id) (collectKinds : SyntaxNodeKindSet → SyntaxNodeKindSet := id) (firstTokens : FirstTokens := FirstTokens.unknown) structure Parser := (info : ParserInfo := {}) (fn : ParserFn) instance Parser.inhabited : Inhabited Parser := ⟨{ fn := fun _ s => s }⟩ abbrev TrailingParser := Parser @[noinline] def epsilonInfo : ParserInfo := { firstTokens := FirstTokens.epsilon } @[inline] def checkStackTopFn (p : Syntax → Bool) : ParserFn := fun c s => if p s.stxStack.back then s else s.mkUnexpectedError "invalid leading token" @[inline] def checkStackTop (p : Syntax → Bool) : Parser := { info := epsilonInfo, fn := checkStackTopFn p } @[inline] def andthenFn (p q : ParserFn) : ParserFn := fun c s => let s := p c s; if s.hasError then s else q c s @[noinline] def andthenInfo (p q : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ q.collectTokens, collectKinds := p.collectKinds ∘ q.collectKinds, firstTokens := p.firstTokens.seq q.firstTokens } @[inline] def andthen (p q : Parser) : Parser := { info := andthenInfo p.info q.info, fn := andthenFn p.fn q.fn } instance hashAndthen : HasAndthen Parser := ⟨andthen⟩ @[inline] def nodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; let s := p c s; s.mkNode n iniSz @[inline] def trailingNodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; let s := p c s; s.mkTrailingNode n iniSz @[noinline] def nodeInfo (n : SyntaxNodeKind) (p : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens, collectKinds := fun s => (p.collectKinds s).insert n, firstTokens := p.firstTokens } @[inline] def node (n : SyntaxNodeKind) (p : Parser) : Parser := { info := nodeInfo n p.info, fn := nodeFn n p.fn } @[inline] def leadingNode (n : SyntaxNodeKind) (p : Parser) : Parser := node n p @[inline] def trailingNode (n : SyntaxNodeKind) (p : Parser) : TrailingParser := { info := nodeInfo n p.info, fn := trailingNodeFn n p.fn } @[inline] def group (p : Parser) : Parser := node nullKind p def mergeOrElseErrors (s : ParserState) (error1 : Error) (iniPos : Nat) : ParserState := match s with | ⟨stack, pos, cache, some error2⟩ => if pos == iniPos then ⟨stack, pos, cache, some (error1.merge error2)⟩ else s | other => other @[inline] def orelseFn (p q : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; let iniPos := s.pos; let s := p c s; match s.errorMsg with | some errorMsg => if s.pos == iniPos then mergeOrElseErrors (q c (s.restore iniSz iniPos)) errorMsg iniPos else s | none => s @[noinline] def orelseInfo (p q : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ q.collectTokens, collectKinds := p.collectKinds ∘ q.collectKinds, firstTokens := p.firstTokens.merge q.firstTokens } @[inline] def orelse (p q : Parser) : Parser := { info := orelseInfo p.info q.info, fn := orelseFn p.fn q.fn } instance hashOrelse : HasOrelse Parser := ⟨orelse⟩ @[noinline] def noFirstTokenInfo (info : ParserInfo) : ParserInfo := { collectTokens := info.collectTokens, collectKinds := info.collectKinds } @[inline] def tryFn (p : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; let iniPos := s.pos; match p c s with | ⟨stack, _, cache, some msg⟩ => ⟨stack.shrink iniSz, iniPos, cache, some msg⟩ | other => other @[inline] def try (p : Parser) : Parser := { info := p.info, fn := tryFn p.fn } @[inline] def optionalFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize; let iniPos := s.pos; let s := p c s; let s := if s.hasError && s.pos == iniPos then s.restore iniSz iniPos else s; s.mkNode nullKind iniSz @[noinline] def optionaInfo (p : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens, collectKinds := p.collectKinds, firstTokens := p.firstTokens.toOptional } @[inline] def optional (p : Parser) : Parser := { info := optionaInfo p.info, fn := optionalFn p.fn } @[inline] def lookaheadFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize; let iniPos := s.pos; let s := p c s; if s.hasError then s else s.restore iniSz iniPos @[inline] def lookahead (p : Parser) : Parser := { info := p.info, fn := lookaheadFn p.fn } @[specialize] partial def manyAux (p : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; let iniPos := s.pos; let s := p c s; if s.hasError then if iniPos == s.pos then s.restore iniSz iniPos else s else if iniPos == s.pos then s.mkUnexpectedError "invalid 'many' parser combinator application, parser did not consume anything" else manyAux c s @[inline] def manyFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize; let s := manyAux p c s; s.mkNode nullKind iniSz @[inline] def many (p : Parser) : Parser := { info := noFirstTokenInfo p.info, fn := manyFn p.fn } @[inline] def many1Fn (p : ParserFn) (unboxSingleton : Bool) : ParserFn := fun c s => let iniSz := s.stackSize; let s := andthenFn p (manyAux p) c s; if s.stackSize - iniSz == 1 && unboxSingleton then s else s.mkNode nullKind iniSz @[inline] def many1 (p : Parser) (unboxSingleton := false) : Parser := { info := p.info, fn := many1Fn p.fn unboxSingleton } @[specialize] private partial def sepByFnAux (p : ParserFn) (sep : ParserFn) (allowTrailingSep : Bool) (iniSz : Nat) (unboxSingleton : Bool) : Bool → ParserFn | pOpt, c, s => let sz := s.stackSize; let pos := s.pos; let s := p c s; if s.hasError then if s.pos > pos then s else if pOpt then let s := s.restore sz pos; if s.stackSize - iniSz == 2 && unboxSingleton then s.popSyntax else s.mkNode nullKind iniSz else -- append `Syntax.missing` to make clear that List is incomplete let s := s.pushSyntax Syntax.missing; s.mkNode nullKind iniSz else let sz := s.stackSize; let pos := s.pos; let s := sep c s; if s.hasError then let s := s.restore sz pos; if s.stackSize - iniSz == 1 && unboxSingleton then s else s.mkNode nullKind iniSz else sepByFnAux allowTrailingSep c s @[specialize] def sepByFn (allowTrailingSep : Bool) (p : ParserFn) (sep : ParserFn) : ParserFn | c, s => let iniSz := s.stackSize; sepByFnAux p sep allowTrailingSep iniSz false true c s @[specialize] def sepBy1Fn (allowTrailingSep : Bool) (p : ParserFn) (sep : ParserFn) (unboxSingleton : Bool) : ParserFn | c, s => let iniSz := s.stackSize; sepByFnAux p sep allowTrailingSep iniSz unboxSingleton false c s @[noinline] def sepByInfo (p sep : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ sep.collectTokens, collectKinds := p.collectKinds ∘ sep.collectKinds } @[noinline] def sepBy1Info (p sep : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ sep.collectTokens, collectKinds := p.collectKinds ∘ sep.collectKinds, firstTokens := p.firstTokens } @[inline] def sepBy (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := { info := sepByInfo p.info sep.info, fn := sepByFn allowTrailingSep p.fn sep.fn } @[inline] def sepBy1 (p sep : Parser) (allowTrailingSep : Bool := false) (unboxSingleton := false) : Parser := { info := sepBy1Info p.info sep.info, fn := sepBy1Fn allowTrailingSep p.fn sep.fn unboxSingleton } @[specialize] partial def satisfyFn (p : Char → Bool) (errorMsg : String := "unexpected character") : ParserFn | c, s => let i := s.pos; if c.input.atEnd i then s.mkEOIError else if p (c.input.get i) then s.next c.input i else s.mkUnexpectedError errorMsg @[specialize] partial def takeUntilFn (p : Char → Bool) : ParserFn | c, s => let i := s.pos; if c.input.atEnd i then s else if p (c.input.get i) then s else takeUntilFn c (s.next c.input i) @[specialize] def takeWhileFn (p : Char → Bool) : ParserFn := takeUntilFn (fun c => !p c) @[inline] def takeWhile1Fn (p : Char → Bool) (errorMsg : String) : ParserFn := andthenFn (satisfyFn p errorMsg) (takeWhileFn p) partial def finishCommentBlock : Nat → ParserFn | nesting, c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; let i := input.next i; if curr == '-' then if input.atEnd i then s.mkEOIError else let curr := input.get i; if curr == '/' then -- "-/" end of comment if nesting == 1 then s.next input i else finishCommentBlock (nesting-1) c (s.next input i) else finishCommentBlock nesting c (s.next input i) else if curr == '/' then if input.atEnd i then s.mkEOIError else let curr := input.get i; if curr == '-' then finishCommentBlock (nesting+1) c (s.next input i) else finishCommentBlock nesting c (s.setPos i) else finishCommentBlock nesting c (s.setPos i) /- Consume whitespace and comments -/ partial def whitespace : ParserFn | c, s => let input := c.input; let i := s.pos; if input.atEnd i then s else let curr := input.get i; if curr.isWhitespace then whitespace c (s.next input i) else if curr == '-' then let i := input.next i; let curr := input.get i; if curr == '-' then andthenFn (takeUntilFn (fun c => c = '\n')) whitespace c (s.next input i) else s else if curr == '/' then let i := input.next i; let curr := input.get i; if curr == '-' then let i := input.next i; let curr := input.get i; if curr == '-' then s -- "/--" doc comment is an actual token else andthenFn (finishCommentBlock 1) whitespace c (s.next input i) else s else s def mkEmptySubstringAt (s : String) (p : Nat) : Substring := {str := s, startPos := p, stopPos := p } private def rawAux (startPos : Nat) (trailingWs : Bool) : ParserFn | c, s => let input := c.input; let stopPos := s.pos; let leading := mkEmptySubstringAt input startPos; let val := input.extract startPos stopPos; if trailingWs then let s := whitespace c s; let stopPos' := s.pos; let trailing := { Substring . str := input, startPos := stopPos, stopPos := stopPos' }; let atom := mkAtom { leading := leading, pos := startPos, trailing := trailing } val; s.pushSyntax atom else let trailing := mkEmptySubstringAt input stopPos; let atom := mkAtom { leading := leading, pos := startPos, trailing := trailing } val; s.pushSyntax atom /-- Match an arbitrary Parser and return the consumed String in a `Syntax.atom`. -/ @[inline] def rawFn (p : ParserFn) (trailingWs := false) : ParserFn | c, s => let startPos := s.pos; let s := p c s; if s.hasError then s else rawAux startPos trailingWs c s @[inline] def chFn (c : Char) (trailingWs := false) : ParserFn := rawFn (satisfyFn (fun d => c == d) ("'" ++ toString c ++ "'")) trailingWs def rawCh (c : Char) (trailingWs := false) : Parser := { fn := chFn c trailingWs } def hexDigitFn : ParserFn | c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; let i := input.next i; if curr.isDigit || ('a' <= curr && curr <= 'f') || ('A' <= curr && curr <= 'F') then s.setPos i else s.mkUnexpectedError "invalid hexadecimal numeral" def quotedCharFn : ParserFn | c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; if curr == '\\' || curr == '\"' || curr == '\'' || curr == 'n' || curr == 't' then s.next input i else if curr == 'x' then andthenFn hexDigitFn hexDigitFn c (s.next input i) else if curr == 'u' then andthenFn hexDigitFn (andthenFn hexDigitFn (andthenFn hexDigitFn hexDigitFn)) c (s.next input i) else s.mkUnexpectedError "invalid escape sequence" /-- Push `(Syntax.node tk <new-atom>)` into syntax stack -/ def mkNodeToken (n : SyntaxNodeKind) (startPos : Nat) : ParserFn := fun c s => let input := c.input; let stopPos := s.pos; let leading := mkEmptySubstringAt input startPos; let val := input.extract startPos stopPos; let s := whitespace c s; let wsStopPos := s.pos; let trailing := { Substring . str := input, startPos := stopPos, stopPos := wsStopPos }; let info := { SourceInfo . leading := leading, pos := startPos, trailing := trailing }; s.pushSyntax (mkStxLit n val (some info)) def charLitFnAux (startPos : Nat) : ParserFn | c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; let s := s.setPos (input.next i); let s := if curr == '\\' then quotedCharFn c s else s; if s.hasError then s else let i := s.pos; let curr := input.get i; let s := s.setPos (input.next i); if curr == '\'' then mkNodeToken charLitKind startPos c s else s.mkUnexpectedError "missing end of character literal" partial def strLitFnAux (startPos : Nat) : ParserFn | c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; let s := s.setPos (input.next i); if curr == '\"' then mkNodeToken strLitKind startPos c s else if curr == '\\' then andthenFn quotedCharFn strLitFnAux c s else strLitFnAux c s def decimalNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhileFn (fun c => c.isDigit) c s; let input := c.input; let i := s.pos; let curr := input.get i; let s := /- TODO(Leo): should we use a different kind for numerals containing decimal points? -/ if curr == '.' then let i := input.next i; let curr := input.get i; if curr.isDigit then takeWhileFn (fun c => c.isDigit) c (s.setPos i) else s else s; mkNodeToken numLitKind startPos c s def binNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => c == '0' || c == '1') "binary number" c s; mkNodeToken numLitKind startPos c s def octalNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => '0' ≤ c && c ≤ '7') "octal number" c s; mkNodeToken numLitKind startPos c s def hexNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => ('0' ≤ c && c ≤ '9') || ('a' ≤ c && c ≤ 'f') || ('A' ≤ c && c ≤ 'F')) "hexadecimal number" c s; mkNodeToken numLitKind startPos c s def numberFnAux : ParserFn := fun c s => let input := c.input; let startPos := s.pos; if input.atEnd startPos then s.mkEOIError else let curr := input.get startPos; if curr == '0' then let i := input.next startPos; let curr := input.get i; if curr == 'b' || curr == 'B' then binNumberFn startPos c (s.next input i) else if curr == 'o' || curr == 'O' then octalNumberFn startPos c (s.next input i) else if curr == 'x' || curr == 'X' then hexNumberFn startPos c (s.next input i) else decimalNumberFn startPos c (s.setPos i) else if curr.isDigit then decimalNumberFn startPos c (s.next input startPos) else s.mkError "numeral" def isIdCont : String → ParserState → Bool | input, s => let i := s.pos; let curr := input.get i; if curr == '.' then let i := input.next i; if input.atEnd i then false else let curr := input.get i; isIdFirst curr || isIdBeginEscape curr else false private def isToken (idStartPos idStopPos : Nat) (tk : Option TokenConfig) : Bool := match tk with | none => false | some tk => -- if a token is both a symbol and a valid identifier (i.e. a keyword), -- we want it to be recognized as a symbol tk.val.bsize ≥ idStopPos - idStartPos def mkTokenAndFixPos (startPos : Nat) (tk : Option TokenConfig) : ParserFn := fun c s => match tk with | none => s.mkErrorAt "token" startPos | some tk => let input := c.input; let leading := mkEmptySubstringAt input startPos; let val := tk.val; let stopPos := startPos + val.bsize; let s := s.setPos stopPos; let s := whitespace c s; let wsStopPos := s.pos; let trailing := { Substring . str := input, startPos := stopPos, stopPos := wsStopPos }; let atom := mkAtom { leading := leading, pos := startPos, trailing := trailing } val; s.pushSyntax atom def mkIdResult (startPos : Nat) (tk : Option TokenConfig) (val : Name) : ParserFn := fun c s => let stopPos := s.pos; if isToken startPos stopPos tk then mkTokenAndFixPos startPos tk c s else let input := c.input; let rawVal := { Substring . str := input, startPos := startPos, stopPos := stopPos }; let s := whitespace c s; let trailingStopPos := s.pos; let leading := mkEmptySubstringAt input startPos; let trailing := { Substring . str := input, startPos := stopPos, stopPos := trailingStopPos }; let info := { SourceInfo . leading := leading, trailing := trailing, pos := startPos }; let atom := mkIdent info rawVal val; s.pushSyntax atom partial def identFnAux (startPos : Nat) (tk : Option TokenConfig) : Name → ParserFn | r, c, s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let curr := input.get i; if isIdBeginEscape curr then let startPart := input.next i; let s := takeUntilFn isIdEndEscape c (s.setPos startPart); let stopPart := s.pos; let s := satisfyFn isIdEndEscape "missing end of escaped identifier" c s; if s.hasError then s else let r := mkNameStr r (input.extract startPart stopPart); if isIdCont input s then let s := s.next input s.pos; identFnAux r c s else mkIdResult startPos tk r c s else if isIdFirst curr then let startPart := i; let s := takeWhileFn isIdRest c (s.next input i); let stopPart := s.pos; let r := mkNameStr r (input.extract startPart stopPart); if isIdCont input s then let s := s.next input s.pos; identFnAux r c s else mkIdResult startPos tk r c s else mkTokenAndFixPos startPos tk c s private def isIdFirstOrBeginEscape (c : Char) : Bool := isIdFirst c || isIdBeginEscape c private def nameLitAux (startPos : Nat) : ParserFn | c, s => let input := c.input; let s := identFnAux startPos none Name.anonymous c (s.next input startPos); if s.hasError then s.mkErrorAt "invalid Name literal" startPos else let stx := s.stxStack.back; match stx with | Syntax.ident _ rawStr _ _ => let s := s.popSyntax; s.pushSyntax (Syntax.node nameLitKind #[mkAtomFrom stx rawStr.toString]) | _ => s.mkError "invalid Name literal" private def tokenFnAux : ParserFn | c, s => let input := c.input; let i := s.pos; let curr := input.get i; if curr == '\"' then strLitFnAux i c (s.next input i) else if curr == '\'' then charLitFnAux i c (s.next input i) else if curr.isDigit then numberFnAux c s else if curr == '`' && isIdFirstOrBeginEscape (getNext input i) then nameLitAux i c s else let (_, tk) := c.tokens.matchPrefix input i; identFnAux i tk Name.anonymous c s private def updateCache (startPos : Nat) (s : ParserState) : ParserState := match s with | ⟨stack, pos, cache, none⟩ => if stack.size == 0 then s else let tk := stack.back; ⟨stack, pos, { tokenCache := { startPos := startPos, stopPos := pos, token := tk } }, none⟩ | other => other def tokenFn : ParserFn := fun c s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else let tkc := s.cache.tokenCache; if tkc.startPos == i then let s := s.pushSyntax tkc.token; s.setPos tkc.stopPos else let s := tokenFnAux c s; updateCache i s def peekTokenAux (c : ParserContext) (s : ParserState) : ParserState × Option Syntax := let iniSz := s.stackSize; let iniPos := s.pos; let s := tokenFn c s; if s.hasError then (s.restore iniSz iniPos, none) else let stx := s.stxStack.back; (s.restore iniSz iniPos, some stx) @[inline] def peekToken (c : ParserContext) (s : ParserState) : ParserState × Option Syntax := let tkc := s.cache.tokenCache; if tkc.startPos == s.pos then (s, some tkc.token) else peekTokenAux c s /- Treat keywords as identifiers. -/ def rawIdentFn : ParserFn := fun c s => let input := c.input; let i := s.pos; if input.atEnd i then s.mkEOIError else identFnAux i none Name.anonymous c s @[inline] def satisfySymbolFn (p : String → Bool) (expected : List String) : ParserFn := fun c s => let startPos := s.pos; let s := tokenFn c s; if s.hasError then s.mkErrorsAt expected startPos else match s.stxStack.back with | Syntax.atom _ sym => if p sym then s else s.mkErrorsAt expected startPos | _ => s.mkErrorsAt expected startPos @[inline] def symbolFnAux (sym : String) (errorMsg : String) : ParserFn := satisfySymbolFn (fun s => s == sym) [errorMsg] def symbolInfo (sym : String) (lbp : Option Nat) : ParserInfo := { collectTokens := fun tks => { val := sym, lbp := lbp } :: tks, firstTokens := FirstTokens.tokens [ { val := sym, lbp := lbp } ] } @[inline] def symbolFn (sym : String) : ParserFn := symbolFnAux sym ("'" ++ sym ++ "'") @[inline] def symbolAux (sym : String) (lbp : Option Nat := none) : Parser := let sym := sym.trim; { info := symbolInfo sym lbp, fn := symbolFn sym } @[inline] def symbol (sym : String) (lbp : Nat) : Parser := symbolAux sym lbp /-- Check if the following token is the symbol _or_ identifier `sym`. Useful for parsing local tokens that have not been added to the token table (but may have been so by some unrelated code). For example, the universe `max` Function is parsed using this combinator so that it can still be used as an identifier outside of universes (but registering it as a token in a Term Syntax would not break the universe Parser). -/ def nonReservedSymbolFnAux (sym : String) (errorMsg : String) : ParserFn := fun c s => let startPos := s.pos; let s := tokenFn c s; if s.hasError then s.mkErrorAt errorMsg startPos else match s.stxStack.back with | Syntax.atom _ sym' => if sym == sym' then s else s.mkErrorAt errorMsg startPos | Syntax.ident info rawVal _ _ => if sym == rawVal.toString then let s := s.popSyntax; s.pushSyntax (Syntax.atom info sym) else s.mkErrorAt errorMsg startPos | _ => s.mkErrorAt errorMsg startPos @[inline] def nonReservedSymbolFn (sym : String) : ParserFn := nonReservedSymbolFnAux sym ("'" ++ sym ++ "'") def nonReservedSymbolInfo (sym : String) (includeIdent : Bool) : ParserInfo := { firstTokens := if includeIdent then FirstTokens.tokens [ { val := sym }, { val := "ident" } ] else FirstTokens.tokens [ { val := sym } ] } @[inline] def nonReservedSymbol (sym : String) (includeIdent := false) : Parser := let sym := sym.trim; { info := nonReservedSymbolInfo sym includeIdent, fn := nonReservedSymbolFn sym } partial def strAux (sym : String) (errorMsg : String) : Nat → ParserFn | j, c, s => if sym.atEnd j then s else let i := s.pos; let input := c.input; if input.atEnd i || sym.get j != input.get i then s.mkError errorMsg else strAux (sym.next j) c (s.next input i) def checkTailWs (prev : Syntax) : Bool := match prev.getTailInfo with | some info => info.trailing.stopPos > info.trailing.startPos | none => false def checkWsBeforeFn (errorMsg : String) : ParserFn := fun c s => let prev := s.stxStack.back; if checkTailWs prev then s else s.mkError errorMsg def checkWsBefore (errorMsg : String) : Parser := { info := epsilonInfo, fn := checkWsBeforeFn errorMsg } def checkTailNoWs (prev : Syntax) : Bool := match prev.getTailInfo with | some info => info.trailing.stopPos == info.trailing.startPos | none => false private def pickNonNone (stack : Array Syntax) : Syntax := match stack.findRev? $ fun stx => !stx.isNone with | none => Syntax.missing | some stx => stx def checkNoWsBeforeFn (errorMsg : String) : ParserFn := fun c s => let prev := pickNonNone s.stxStack; if checkTailNoWs prev then s else s.mkError errorMsg def checkNoWsBefore (errorMsg : String) : Parser := { info := epsilonInfo, fn := checkNoWsBeforeFn errorMsg } def symbolNoWsInfo (sym : String) (lbpNoWs : Option Nat) : ParserInfo := { collectTokens := fun tks => { val := sym, lbpNoWs := lbpNoWs } :: tks, firstTokens := FirstTokens.tokens [ { val := sym, lbpNoWs := lbpNoWs } ] } @[inline] def symbolNoWsFnAux (sym : String) (errorMsg : String) : ParserFn := fun c s => let left := s.stxStack.back; if checkTailNoWs left then let startPos := s.pos; let input := c.input; let s := strAux sym errorMsg 0 c s; if s.hasError then s else let leading := mkEmptySubstringAt input startPos; let stopPos := startPos + sym.bsize; let trailing := mkEmptySubstringAt input stopPos; let atom := mkAtom { leading := leading, pos := startPos, trailing := trailing } sym; s.pushSyntax atom else s.mkError errorMsg @[inline] def symbolNoWsFn (sym : String) : ParserFn := symbolNoWsFnAux sym ("'" ++ sym ++ "' without whitespaces around it") /- Similar to `symbol`, but succeeds only if there is no space whitespace after leading term and after `sym`. -/ @[inline] def symbolNoWsAux (sym : String) (lbp : Option Nat) : Parser := let sym := sym.trim; { info := symbolNoWsInfo sym lbp, fn := symbolNoWsFn sym } @[inline] def symbolNoWs (sym : String) (lbp : Nat) : Parser := symbolNoWsAux sym lbp def unicodeSymbolFnAux (sym asciiSym : String) (expected : List String) : ParserFn := satisfySymbolFn (fun s => s == sym || s == asciiSym) expected def unicodeSymbolInfo (sym asciiSym : String) (lbp : Option Nat) : ParserInfo := { collectTokens := fun tks => { val := sym, lbp := lbp } :: { val := asciiSym, lbp := lbp } :: tks, firstTokens := FirstTokens.tokens [ { val := sym, lbp := lbp }, { val := asciiSym, lbp := lbp } ] } @[inline] def unicodeSymbolFn (sym asciiSym : String) : ParserFn := unicodeSymbolFnAux sym asciiSym ["'" ++ sym ++ "', '" ++ asciiSym ++ "'"] @[inline] def unicodeSymbol (sym asciiSym : String) (lbp : Option Nat := none) : Parser := let sym := sym.trim; let asciiSym := asciiSym.trim; { info := unicodeSymbolInfo sym asciiSym lbp, fn := unicodeSymbolFn sym asciiSym } /- Succeeds if RBP > lower -/ def checkRBPGreaterFn (lower : Nat) (errorMsg : String) : ParserFn := fun c s => if c.rbp > lower then s.mkUnexpectedError errorMsg else s def checkRBPGreater (lower : Nat) (errorMsg : String) : Parser := { info := epsilonInfo, fn := checkRBPGreaterFn lower errorMsg } def mkAtomicInfo (k : String) : ParserInfo := { firstTokens := FirstTokens.tokens [ { val := k } ] } def numLitFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || !(s.stxStack.back.isOfKind numLitKind) then s.mkErrorAt "numeral" iniPos else s @[inline] def numLitNoAntiquot : Parser := { fn := numLitFn, info := mkAtomicInfo "numLit" } def strLitFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || !(s.stxStack.back.isOfKind strLitKind) then s.mkErrorAt "string literal" iniPos else s @[inline] def strLitNoAntiquot : Parser := { fn := strLitFn, info := mkAtomicInfo "strLit" } def charLitFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || !(s.stxStack.back.isOfKind charLitKind) then s.mkErrorAt "character literal" iniPos else s @[inline] def charLitNoAntiquot : Parser := { fn := charLitFn, info := mkAtomicInfo "charLit" } def nameLitFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || !(s.stxStack.back.isOfKind nameLitKind) then s.mkErrorAt "Name literal" iniPos else s @[inline] def nameLitNoAntiquot : Parser := { fn := nameLitFn, info := mkAtomicInfo "nameLit" } def identFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || !(s.stxStack.back.isIdent) then s.mkErrorAt "identifier" iniPos else s @[inline] def identNoAntiquot : Parser := { fn := identFn, info := mkAtomicInfo "ident" } @[inline] def rawIdentNoAntiquot : Parser := { fn := rawIdentFn } def identEqFn (id : Name) : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError then s.mkErrorAt "identifier" iniPos else match s.stxStack.back with | Syntax.ident _ _ val _ => if val != id then s.mkErrorAt ("expected identifier '" ++ toString id ++ "'") iniPos else s | _ => s.mkErrorAt "identifier" iniPos @[inline] def identEq (id : Name) : Parser := { fn := identEqFn id, info := mkAtomicInfo "ident" } def quotedSymbolFn : ParserFn := nodeFn `quotedSymbol (andthenFn (andthenFn (chFn '`') (rawFn (takeUntilFn (fun c => c == '`')))) (chFn '`' true)) -- TODO: remove after old frontend is gone def quotedSymbol : Parser := { fn := quotedSymbolFn } def unquotedSymbolFn : ParserFn := fun c s => let iniPos := s.pos; let s := tokenFn c s; if s.hasError || s.stxStack.back.isIdent || isLitKind s.stxStack.back.getKind then s.mkErrorAt "symbol" iniPos else s def unquotedSymbol : Parser := { fn := unquotedSymbolFn } instance stringToParserCoe : HasCoe String Parser := ⟨symbolAux⟩ namespace ParserState def keepNewError (s : ParserState) (oldStackSize : Nat) : ParserState := match s with | ⟨stack, pos, cache, err⟩ => ⟨stack.shrink oldStackSize, pos, cache, err⟩ def keepPrevError (s : ParserState) (oldStackSize : Nat) (oldStopPos : String.Pos) (oldError : Option Error) : ParserState := match s with | ⟨stack, _, cache, _⟩ => ⟨stack.shrink oldStackSize, oldStopPos, cache, oldError⟩ def mergeErrors (s : ParserState) (oldStackSize : Nat) (oldError : Error) : ParserState := match s with | ⟨stack, pos, cache, some err⟩ => if oldError == err then s else ⟨stack.shrink oldStackSize, pos, cache, some (oldError.merge err)⟩ | other => other def mkLongestNodeAlt (s : ParserState) (startSize : Nat) : ParserState := match s with | ⟨stack, pos, cache, _⟩ => if stack.size == startSize then ⟨stack.push Syntax.missing, pos, cache, none⟩ -- parser did not create any node, then we just add `Syntax.missing` else if stack.size == startSize + 1 then s else -- parser created more than one node, combine them into a single node let node := Syntax.node nullKind (stack.extract startSize stack.size); let stack := stack.shrink startSize; ⟨stack.push node, pos, cache, none⟩ def keepLatest (s : ParserState) (startStackSize : Nat) : ParserState := match s with | ⟨stack, pos, cache, _⟩ => let node := stack.back; let stack := stack.shrink startStackSize; let stack := stack.push node; ⟨stack, pos, cache, none⟩ def replaceLongest (s : ParserState) (startStackSize : Nat) (prevStackSize : Nat) : ParserState := let s := s.mkLongestNodeAlt prevStackSize; s.keepLatest startStackSize end ParserState def longestMatchStep (startSize : Nat) (startPos : String.Pos) (p : ParserFn) : ParserFn := fun c s => let prevErrorMsg := s.errorMsg; let prevStopPos := s.pos; let prevSize := s.stackSize; let s := s.restore prevSize startPos; let s := p c s; match prevErrorMsg, s.errorMsg with | none, none => -- both succeeded if s.pos > prevStopPos then s.replaceLongest startSize prevSize -- replace else if s.pos < prevStopPos then s.restore prevSize prevStopPos -- keep prev else s.mkLongestNodeAlt prevSize -- keep both | none, some _ => -- prev succeeded, current failed s.restore prevSize prevStopPos | some oldError, some _ => -- both failed if s.pos > prevStopPos then s.keepNewError prevSize else if s.pos < prevStopPos then s.keepPrevError prevSize prevStopPos prevErrorMsg else s.mergeErrors prevSize oldError | some _, none => -- prev failed, current succeeded let s := s.mkLongestNodeAlt prevSize; -- create successful alternative on the top of the stack let successNode := s.stxStack.back; let s := s.shrinkStack startSize; -- restore stack to initial size to make sure (failure) nodes are removed from the stack s.pushSyntax successNode -- put successNode back on the stack def longestMatchMkResult (startSize : Nat) (s : ParserState) : ParserState := if !s.hasError && s.stackSize > startSize + 1 then s.mkNode choiceKind startSize else s def longestMatchFnAux (startSize : Nat) (startPos : String.Pos) : List Parser → ParserFn | [] => fun _ s => longestMatchMkResult startSize s | p::ps => fun c s => let s := longestMatchStep startSize startPos p.fn c s; longestMatchFnAux ps c s def longestMatchFn₁ (p : ParserFn) : ParserFn := fun c s => let startSize := s.stackSize; let s := p c s; if s.hasError then s else s.mkLongestNodeAlt startSize def longestMatchFn : List Parser → ParserFn | [] => fun _ s => s.mkError "longestMatch: empty list" | [p] => longestMatchFn₁ p.fn | p::ps => fun c s => let startSize := s.stackSize; let startPos := s.pos; let s := p.fn c s; if s.hasError then let s := s.shrinkStack startSize; longestMatchFnAux startSize startPos ps c s else let s := s.mkLongestNodeAlt startSize; longestMatchFnAux startSize startPos ps c s def anyOfFn : List Parser → ParserFn | [], _, s => s.mkError "anyOf: empty list" | [p], c, s => p.fn c s | p::ps, c, s => orelseFn p.fn (anyOfFn ps) c s @[inline] def checkColGeFn (col : Nat) (errorMsg : String) : ParserFn := fun c s => let pos := c.fileMap.toPosition s.pos; if pos.column ≥ col then s else s.mkError errorMsg @[inline] def checkColGe (col : Nat) (errorMsg : String) : Parser := { fn := checkColGeFn col errorMsg } @[inline] def withPosition (p : Position → Parser) : Parser := { info := (p { line := 1, column := 0 }).info, fn := fun c s => let pos := c.fileMap.toPosition s.pos; (p pos).fn c s } @[inline] def many1Indent (p : Parser) (errorMsg : String) : Parser := withPosition $ fun pos => many1 (checkColGe pos.column errorMsg >> p) /-- A multimap indexed by tokens. Used for indexing parsers by their leading token. -/ def TokenMap (α : Type) := RBMap Name (List α) Name.quickLt namespace TokenMap def insert {α : Type} (map : TokenMap α) (k : Name) (v : α) : TokenMap α := match map.find? k with | none => map.insert k [v] | some vs => map.insert k (v::vs) instance {α : Type} : Inhabited (TokenMap α) := ⟨RBMap.empty⟩ instance {α : Type} : HasEmptyc (TokenMap α) := ⟨RBMap.empty⟩ end TokenMap structure PrattParsingTables := (leadingTable : TokenMap Parser := {}) (leadingParsers : List Parser := []) -- for supporting parsers we cannot obtain first token (trailingTable : TokenMap TrailingParser := {}) (trailingParsers : List TrailingParser := []) -- for supporting parsers such as function application instance PrattParsingTables.inhabited : Inhabited PrattParsingTables := ⟨{}⟩ /-- Each parser category is implemented using Pratt's parser. The system comes equipped with the following categories: `level`, `term`, `tactic`, and `command`. Users and plugins may define extra categories. The field `leadingIdentAsSymbol` specifies how the parsing table lookup function behaves for identifiers. The function `prattParser` uses two tables `leadingTable` and `trailingTable`. They map tokens to parsers. If `leadingIdentAsSymbol == false` and the leading token is an identifier, then `prattParser` just executes the parsers associated with the auxiliary token "ident". If `leadingIdentAsSymbol == true` and the leading token is an identifier `<foo>`, then `prattParser` combines the parsers associated with the token `<foo>` with the parsers associated with the auxiliary token "ident". We use this feature and the `nonReservedSymbol` parser to implement the `tactic` parsers. We use this approach to avoid creating a reserved symbol for each builtin tactic (e.g., `apply`, `assumption`, etc.). That is, users may still use these symbols as identifiers (e.g., naming a function). -/ structure ParserCategory := (tables : PrattParsingTables) (leadingIdentAsSymbol : Bool) instance ParserCategory.inhabited : Inhabited ParserCategory := ⟨{ tables := {}, leadingIdentAsSymbol := false }⟩ abbrev ParserCategories := PersistentHashMap Name ParserCategory def currLbp (left : Syntax) (c : ParserContext) (s : ParserState) : ParserState × Nat := let (s, stx?) := peekToken c s; match stx? with | some stx@(Syntax.atom _ sym) => if sym == "$" && checkTailNoWs stx then (s, appPrec) -- TODO: split `lbpNoWs` into "before" and "after", and set right lbp for '$' in antiquotations else match c.tokens.matchPrefix sym 0 with | (_, some tk) => match tk.lbp, tk.lbpNoWs with | some lbp, none => (s, lbp) | none, some lbpNoWs => (s, lbpNoWs) | some lbp, some lbpNoWs => if checkTailNoWs left then (s, lbpNoWs) else (s, lbp) | none, none => (s, 0) | _ => (s, 0) | some (Syntax.ident _ _ _ _) => (s, appPrec) -- TODO(Leo): add support for associating lbp with syntax node kinds. | some (Syntax.node k _) => if isLitKind k || k == fieldIdxKind then (s, appPrec) else (s, 0) | _ => (s, 0) def indexed {α : Type} (map : TokenMap α) (c : ParserContext) (s : ParserState) (leadingIdentAsSymbol : Bool) : ParserState × List α := let (s, stx) := peekToken c s; let find (n : Name) : ParserState × List α := match map.find? n with | some as => (s, as) | _ => (s, []); match stx with | some (Syntax.atom _ sym) => find (mkNameSimple sym) | some (Syntax.ident _ _ val _) => if leadingIdentAsSymbol then match map.find? val with | some as => match map.find? identKind with | some as' => (s, as ++ as') | _ => (s, as) | none => find identKind else find identKind | some (Syntax.node k _) => find k | _ => (s, []) abbrev CategoryParserFn := Name → ParserFn def mkCategoryParserFnRef : IO (IO.Ref CategoryParserFn) := IO.mkRef $ fun _ => whitespace @[init mkCategoryParserFnRef] constant categoryParserFnRef : IO.Ref CategoryParserFn := arbitrary _ def mkCategoryParserFnExtension : IO (EnvExtension CategoryParserFn) := registerEnvExtension $ categoryParserFnRef.get @[init mkCategoryParserFnExtension] def categoryParserFnExtension : EnvExtension CategoryParserFn := arbitrary _ def categoryParserFn (catName : Name) : ParserFn := fun ctx s => categoryParserFnExtension.getState ctx.env catName ctx s def categoryParser (catName : Name) (rbp : Nat) : Parser := { fn := fun c s => categoryParserFn catName { rbp := rbp, .. c } s } -- Define `termParser` here because we need it for antiquotations @[inline] def termParser (rbp : Nat := 0) : Parser := categoryParser `term rbp /- ============== -/ /- Antiquotations -/ /- ============== -/ def dollarSymbol : Parser := symbol "$" 1 /-- Fail if previous token is immediately followed by ':'. -/ private def noImmediateColon : Parser := { fn := fun c s => let prev := s.stxStack.back; if checkTailNoWs prev then let input := c.input; let i := s.pos; if input.atEnd i then s else let curr := input.get i; if curr == ':' then s.mkUnexpectedError "unexpected ':'" else s else s } def setExpectedFn (expected : List String) (p : ParserFn) : ParserFn := fun c s => match p c s with | s'@{ errorMsg := some msg } => { s' with errorMsg := some { msg with expected := [] } } | s' => s' def setExpected (expected : List String) (p : Parser) : Parser := { fn := setExpectedFn expected p.fn, info := p.info } def pushNone : Parser := { fn := fun c s => s.pushSyntax mkNullNode } -- We support two kinds of antiquotations: `$id` and `$(t)`, where `id` is a term identifier and `t` is a term. private def antiquotNestedExpr : Parser := node `antiquotNestedExpr ("(" >> termParser >> ")") private def antiquotExpr : Parser := identNoAntiquot <|> antiquotNestedExpr /-- Define parser for `$e` (if anonymous == true) and `$e:name`. Both forms can also be used with an appended `*` to turn them into an antiquotation "splice". If `kind` is given, it will additionally be checked when evaluating `match_syntax`. Antiquotations can be escaped as in `$$e`, which produces the syntax tree for `$e`. -/ def mkAntiquot (name : String) (kind : Option SyntaxNodeKind) (anonymous := true) : Parser := let kind := (kind.getD Name.anonymous) ++ `antiquot; let nameP := checkNoWsBefore ("no space before ':" ++ name ++ "'") >> symbolAux ":" >> nonReservedSymbol name; -- if parsing the kind fails and `anonymous` is true, check that we're not ignoring a different -- antiquotation kind via `noImmediateColon` let nameP := if anonymous then nameP <|> noImmediateColon >> pushNone >> pushNone else nameP; -- antiquotations are not part of the "standard" syntax, so hide "expected '$'" on error node kind $ try $ setExpected [] dollarSymbol >> many (checkNoWsBefore "" >> dollarSymbol) >> checkNoWsBefore "no space before spliced term" >> antiquotExpr >> nameP >> optional (checkNoWsBefore "" >> "*") def tryAnti (c : ParserContext) (s : ParserState) : Bool := let (s, stx?) := peekToken c s; match stx? with | some stx@(Syntax.atom _ sym) => sym == "$" | _ => false @[inline] def withAntiquotFn (antiquotP p : ParserFn) : ParserFn := fun c s => if tryAnti c s then orelseFn antiquotP p c s else p c s /-- Optimized version of `mkAntiquot ... <|> p`. -/ @[inline] def withAntiquot (antiquotP p : Parser) : Parser := { fn := withAntiquotFn antiquotP.fn p.fn, info := orelseInfo antiquotP.info p.info } /- ===================== -/ /- End of Antiquotations -/ /- ===================== -/ def nodeWithAntiquot (name : String) (kind : SyntaxNodeKind) (p : Parser) : Parser := withAntiquot (mkAntiquot name kind false) $ node kind p def ident : Parser := withAntiquot (mkAntiquot "ident" identKind) identNoAntiquot -- `ident` and `rawIdent` produce the same syntax tree, so we reuse the antiquotation kind name def rawIdent : Parser := withAntiquot (mkAntiquot "ident" identKind) rawIdentNoAntiquot def numLit : Parser := withAntiquot (mkAntiquot "numLit" numLitKind) numLitNoAntiquot def strLit : Parser := withAntiquot (mkAntiquot "strLit" strLitKind) strLitNoAntiquot def charLit : Parser := withAntiquot (mkAntiquot "charLit" charLitKind) charLitNoAntiquot def nameLit : Parser := withAntiquot (mkAntiquot "nameLit" nameLitKind) nameLitNoAntiquot def categoryParserOfStackFn (offset : Nat) : ParserFn := fun ctx s => let stack := s.stxStack; if stack.size < offset + 1 then s.mkUnexpectedError ("failed to determine parser category using syntax stack, stack is too small") else match stack.get! (stack.size - offset - 1) with | Syntax.ident _ _ catName _ => categoryParserFn catName ctx s | _ => s.mkUnexpectedError ("failed to determine parser category using syntax stack, the specified element on the stack is not an identifier") def categoryParserOfStack (offset : Nat) (rbp : Nat := 0) : Parser := { fn := fun c s => categoryParserOfStackFn offset { rbp := rbp, .. c } s } private def mkResult (s : ParserState) (iniSz : Nat) : ParserState := if s.stackSize == iniSz + 1 then s else s.mkNode nullKind iniSz -- throw error instead? def leadingParserAux (kind : Name) (tables : PrattParsingTables) (leadingIdentAsSymbol : Bool) : ParserFn := fun c s => let iniSz := s.stackSize; let (s, ps) := indexed tables.leadingTable c s leadingIdentAsSymbol; let ps := tables.leadingParsers ++ ps; if ps.isEmpty then s.mkError (toString kind) else let s := longestMatchFn ps c s; mkResult s iniSz @[inline] def leadingParser (kind : Name) (tables : PrattParsingTables) (leadingIdentAsSymbol : Bool) (antiquotParser : ParserFn) : ParserFn := withAntiquotFn antiquotParser (leadingParserAux kind tables leadingIdentAsSymbol) def trailingLoopStep (tables : PrattParsingTables) (ps : List Parser) : ParserFn := fun c s => orelseFn (longestMatchFn ps) (anyOfFn tables.trailingParsers) c s private def mkTrailingResult (s : ParserState) (iniSz : Nat) : ParserState := let s := mkResult s iniSz; -- Stack contains `[..., left, result]` -- We must remove `left` let result := s.stxStack.back; let s := s.popSyntax.popSyntax; s.pushSyntax result partial def trailingLoop (tables : PrattParsingTables) (c : ParserContext) : ParserState → ParserState | s => let left := s.stxStack.back; let (s, lbp) := currLbp left c s; if c.rbp ≥ lbp then s else let iniSz := s.stackSize; let identAsSymbol := false; let (s, ps) := indexed tables.trailingTable c s identAsSymbol; if ps.isEmpty && tables.trailingParsers.isEmpty then s -- no available trailing parser else let s := trailingLoopStep tables ps c s; if s.hasError then s else let s := mkTrailingResult s iniSz; trailingLoop s /-- Implements a recursive precedence parser according to Pratt's algorithm. `antiquotParser` should be a `mkAntiquot` parser (or always fail) and is tried before all other parsers. It should not be added to the regular leading parsers because it would heavily overlap with antiquotation parsers nested inside them. -/ @[inline] def prattParser (kind : Name) (tables : PrattParsingTables) (leadingIdentAsSymbol : Bool) (antiquotParser : ParserFn) : ParserFn := fun c s => let left := s.stxStack.back; let (s, lbp) := currLbp left c s; if c.rbp > lbp then s.mkUnexpectedError "unexpected token" else let s := leadingParser kind tables leadingIdentAsSymbol antiquotParser c s; if s.hasError then s else trailingLoop tables c s def mkBuiltinTokenTable : IO (IO.Ref TokenTable) := IO.mkRef {} @[init mkBuiltinTokenTable] constant builtinTokenTable : IO.Ref TokenTable := arbitrary _ /- Global table with all SyntaxNodeKind's -/ def mkBuiltinSyntaxNodeKindSetRef : IO (IO.Ref SyntaxNodeKindSet) := IO.mkRef {} @[init mkBuiltinSyntaxNodeKindSetRef] constant builtinSyntaxNodeKindSetRef : IO.Ref SyntaxNodeKindSet := arbitrary _ def mkBuiltinParserCategories : IO (IO.Ref ParserCategories) := IO.mkRef {} @[init mkBuiltinParserCategories] constant builtinParserCategoriesRef : IO.Ref ParserCategories := arbitrary _ private def throwParserCategoryAlreadyDefined {α} (catName : Name) : ExceptT String Id α := throw ("parser category '" ++ toString catName ++ "' has already been defined") private def addParserCategoryCore (categories : ParserCategories) (catName : Name) (initial : ParserCategory) : Except String ParserCategories := if categories.contains catName then throwParserCategoryAlreadyDefined catName else pure $ categories.insert catName initial /-- All builtin parser categories are Pratt's parsers -/ private def addBuiltinParserCategory (catName : Name) (leadingIdentAsSymbol : Bool) : IO Unit := do categories ← builtinParserCategoriesRef.get; categories ← IO.ofExcept $ addParserCategoryCore categories catName { tables := {}, leadingIdentAsSymbol := leadingIdentAsSymbol}; builtinParserCategoriesRef.set categories inductive ParserExtensionOleanEntry | token (val : TokenConfig) : ParserExtensionOleanEntry | kind (val : SyntaxNodeKind) : ParserExtensionOleanEntry | category (catName : Name) (leadingIdentAsSymbol : Bool) | parser (catName : Name) (declName : Name) : ParserExtensionOleanEntry inductive ParserExtensionEntry | token (val : TokenConfig) : ParserExtensionEntry | kind (val : SyntaxNodeKind) : ParserExtensionEntry | category (catName : Name) (leadingIdentAsSymbol : Bool) | parser (catName : Name) (declName : Name) (leading : Bool) (p : Parser) : ParserExtensionEntry structure ParserExtensionState := (tokens : TokenTable := {}) (kinds : SyntaxNodeKindSet := {}) (categories : ParserCategories := {}) (newEntries : List ParserExtensionOleanEntry := []) instance ParserExtensionState.inhabited : Inhabited ParserExtensionState := ⟨{}⟩ abbrev ParserExtension := PersistentEnvExtension ParserExtensionOleanEntry ParserExtensionEntry ParserExtensionState private def ParserExtension.mkInitial : IO ParserExtensionState := do tokens ← builtinTokenTable.get; kinds ← builtinSyntaxNodeKindSetRef.get; categories ← builtinParserCategoriesRef.get; pure { tokens := tokens, kinds := kinds, categories := categories } private def mergePrecendences (msgPreamble : String) (sym : String) : Option Nat → Option Nat → Except String (Option Nat) | none, b => pure b | a, none => pure a | some a, some b => if a == b then pure $ some a else throw $ msgPreamble ++ "precedence mismatch for '" ++ toString sym ++ "', previous: " ++ toString a ++ ", new: " ++ toString b private def addTokenConfig (tokens : TokenTable) (tk : TokenConfig) : Except String TokenTable := do if tk.val == "" then throw "invalid empty symbol" else match tokens.find tk.val with | none => pure $ tokens.insert tk.val tk | some oldTk => do lbp ← mergePrecendences "" tk.val oldTk.lbp tk.lbp; lbpNoWs ← mergePrecendences "(no whitespace) " tk.val oldTk.lbpNoWs tk.lbpNoWs; pure $ tokens.insert tk.val { lbp := lbp, lbpNoWs := lbpNoWs, .. tk } def throwUnknownParserCategory {α} (catName : Name) : ExceptT String Id α := throw ("unknown parser category '" ++ toString catName ++ "'") def addLeadingParser (categories : ParserCategories) (catName : Name) (parserName : Name) (p : Parser) : Except String ParserCategories := match categories.find? catName with | none => throwUnknownParserCategory catName | some cat => let addTokens (tks : List TokenConfig) : Except String ParserCategories := let tks := tks.map $ fun tk => mkNameSimple tk.val; let tables := tks.eraseDups.foldl (fun (tables : PrattParsingTables) tk => { leadingTable := tables.leadingTable.insert tk p, .. tables }) cat.tables; pure $ categories.insert catName { tables := tables, .. cat }; match p.info.firstTokens with | FirstTokens.tokens tks => addTokens tks | FirstTokens.optTokens tks => addTokens tks | _ => let tables := { leadingParsers := p :: cat.tables.leadingParsers, .. cat.tables }; pure $ categories.insert catName { tables := tables, .. cat } private def addTrailingParserAux (tables : PrattParsingTables) (p : TrailingParser) : PrattParsingTables := let addTokens (tks : List TokenConfig) : PrattParsingTables := let tks := tks.map $ fun tk => mkNameSimple tk.val; tks.eraseDups.foldl (fun (tables : PrattParsingTables) tk => { trailingTable := tables.trailingTable.insert tk p, .. tables }) tables; match p.info.firstTokens with | FirstTokens.tokens tks => addTokens tks | FirstTokens.optTokens tks => addTokens tks | _ => { trailingParsers := p :: tables.trailingParsers, .. tables } def addTrailingParser (categories : ParserCategories) (catName : Name) (p : TrailingParser) : Except String ParserCategories := match categories.find? catName with | none => throwUnknownParserCategory catName | some cat => pure $ categories.insert catName { tables := addTrailingParserAux cat.tables p, .. cat } def addParser (categories : ParserCategories) (catName : Name) (declName : Name) (leading : Bool) (p : Parser) : Except String ParserCategories := match leading, p with | true, p => addLeadingParser categories catName declName p | false, p => addTrailingParser categories catName p def addParserTokens (tokenTable : TokenTable) (info : ParserInfo) : Except String TokenTable := let newTokens := info.collectTokens []; newTokens.foldlM addTokenConfig tokenTable private def updateBuiltinTokens (info : ParserInfo) (declName : Name) : IO Unit := do tokenTable ← builtinTokenTable.swap {}; match addParserTokens tokenTable info with | Except.ok tokenTable => builtinTokenTable.set tokenTable | Except.error msg => throw (IO.userError ("invalid builtin parser '" ++ toString declName ++ "', " ++ msg)) def addBuiltinParser (catName : Name) (declName : Name) (leading : Bool) (p : Parser) : IO Unit := do categories ← builtinParserCategoriesRef.get; categories ← IO.ofExcept $ addParser categories catName declName leading p; builtinParserCategoriesRef.set categories; builtinSyntaxNodeKindSetRef.modify p.info.collectKinds; updateBuiltinTokens p.info declName def addBuiltinLeadingParser (catName : Name) (declName : Name) (p : Parser) : IO Unit := addBuiltinParser catName declName true p def addBuiltinTrailingParser (catName : Name) (declName : Name) (p : TrailingParser) : IO Unit := addBuiltinParser catName declName false p private def ParserExtension.addEntry (s : ParserExtensionState) (e : ParserExtensionEntry) : ParserExtensionState := match e with | ParserExtensionEntry.token tk => match addTokenConfig s.tokens tk with | Except.ok tokens => { tokens := tokens, newEntries := ParserExtensionOleanEntry.token tk :: s.newEntries, .. s } | _ => unreachable! | ParserExtensionEntry.kind k => { kinds := s.kinds.insert k, newEntries := ParserExtensionOleanEntry.kind k :: s.newEntries, .. s } | ParserExtensionEntry.category catName leadingIdentAsSymbol => if s.categories.contains catName then s else { categories := s.categories.insert catName { tables := {}, leadingIdentAsSymbol := leadingIdentAsSymbol }, newEntries := ParserExtensionOleanEntry.category catName leadingIdentAsSymbol :: s.newEntries, .. s } | ParserExtensionEntry.parser catName declName leading parser => match addParser s.categories catName declName leading parser with | Except.ok categories => { categories := categories, newEntries := ParserExtensionOleanEntry.parser catName declName :: s.newEntries, .. s } | _ => unreachable! def compileParserDescr (categories : ParserCategories) : ParserDescr → Except String (Parser) | ParserDescr.andthen d₁ d₂ => andthen <$> compileParserDescr d₁ <*> compileParserDescr d₂ | ParserDescr.orelse d₁ d₂ => orelse <$> compileParserDescr d₁ <*> compileParserDescr d₂ | ParserDescr.optional d => optional <$> compileParserDescr d | ParserDescr.lookahead d => lookahead <$> compileParserDescr d | ParserDescr.try d => try <$> compileParserDescr d | ParserDescr.many d => many <$> compileParserDescr d | ParserDescr.many1 d => many1 <$> compileParserDescr d | ParserDescr.sepBy d₁ d₂ => sepBy <$> compileParserDescr d₁ <*> compileParserDescr d₂ | ParserDescr.sepBy1 d₁ d₂ => sepBy1 <$> compileParserDescr d₁ <*> compileParserDescr d₂ | ParserDescr.node k d => node k <$> compileParserDescr d | ParserDescr.trailingNode k d => trailingNode k <$> compileParserDescr d | ParserDescr.symbol tk lbp => pure $ symbolAux tk lbp | ParserDescr.numLit => pure $ numLit | ParserDescr.strLit => pure $ strLit | ParserDescr.charLit => pure $ charLit | ParserDescr.nameLit => pure $ nameLit | ParserDescr.ident => pure $ ident | ParserDescr.nonReservedSymbol tk includeIdent => pure $ nonReservedSymbol tk includeIdent | ParserDescr.parser catName rbp => match categories.find? catName with | some _ => pure $ categoryParser catName rbp | none => throwUnknownParserCategory catName unsafe def mkParserOfConstantUnsafe (env : Environment) (categories : ParserCategories) (constName : Name) : Except String (Bool × Parser) := match env.find? constName with | none => throw ("unknow constant '" ++ toString constName ++ "'") | some info => match info.type with | Expr.const `Lean.Parser.TrailingParser _ _ => do p ← env.evalConst Parser constName; pure ⟨false, p⟩ | Expr.const `Lean.Parser.Parser _ _ => do p ← env.evalConst Parser constName; pure ⟨true, p⟩ | Expr.const `Lean.ParserDescr _ _ => do d ← env.evalConst ParserDescr constName; p ← compileParserDescr categories d; pure ⟨true, p⟩ | Expr.const `Lean.TrailingParserDescr _ _ => do d ← env.evalConst TrailingParserDescr constName; p ← compileParserDescr categories d; pure ⟨false, p⟩ | _ => throw ("unexpected parser type at '" ++ toString constName ++ "' (`ParserDescr`, `TrailingParserDescr`, `Parser` or `TrailingParser` expected") @[implementedBy mkParserOfConstantUnsafe] constant mkParserOfConstant (env : Environment) (categories : ParserCategories) (constName : Name) : Except String (Bool × Parser) := arbitrary _ private def ParserExtension.addImported (env : Environment) (es : Array (Array ParserExtensionOleanEntry)) : IO ParserExtensionState := do s ← ParserExtension.mkInitial; es.foldlM (fun s entries => entries.foldlM (fun s entry => match entry with | ParserExtensionOleanEntry.token tk => do tokens ← IO.ofExcept (addTokenConfig s.tokens tk); pure { tokens := tokens, .. s } | ParserExtensionOleanEntry.kind k => pure { kinds := s.kinds.insert k, .. s } | ParserExtensionOleanEntry.category catName leadingIdentAsSymbol => do categories ← IO.ofExcept (addParserCategoryCore s.categories catName { tables := {}, leadingIdentAsSymbol := leadingIdentAsSymbol}); pure { categories := categories, .. s } | ParserExtensionOleanEntry.parser catName declName => match mkParserOfConstant env s.categories declName with | Except.ok p => match addParser s.categories catName declName p.1 p.2 with | Except.ok categories => pure { categories := categories, .. s } | Except.error ex => throw (IO.userError ex) | Except.error ex => throw (IO.userError ex)) s) s def mkParserExtension : IO ParserExtension := registerPersistentEnvExtension { name := `parserExt, mkInitial := ParserExtension.mkInitial, addImportedFn := ParserExtension.addImported, addEntryFn := ParserExtension.addEntry, exportEntriesFn := fun s => s.newEntries.reverse.toArray, statsFn := fun s => format "number of local entries: " ++ format s.newEntries.length } @[init mkParserExtension] constant parserExtension : ParserExtension := arbitrary _ def isParserCategory (env : Environment) (catName : Name) : Bool := (parserExtension.getState env).categories.contains catName def addParserCategory (env : Environment) (catName : Name) (leadingIdentAsSymbol : Bool) : Except String Environment := do if isParserCategory env catName then throwParserCategoryAlreadyDefined catName else pure $ parserExtension.addEntry env $ ParserExtensionEntry.category catName leadingIdentAsSymbol /- Return true if in the given category leading identifiers in parsers may be treated as atoms/symbols. See comment at `ParserCategory`. -/ def leadingIdentAsSymbol (env : Environment) (catName : Name) : Bool := match (parserExtension.getState env).categories.find? catName with | none => false | some cat => cat.leadingIdentAsSymbol private def catNameToString : Name → String | Name.str Name.anonymous s _ => s | n => n.toString @[inline] def mkCategoryAntiquotParser (kind : Name) : ParserFn := -- allow "anonymous" antiquotations `$x` for the `term` category only -- TODO: make customizable -- one good example for a category that should not be anonymous is -- `index` in `tests/lean/run/bigop.lean`. let anonAntiquot := kind == `term; (mkAntiquot (catNameToString kind) none anonAntiquot).fn def categoryParserFnImpl (catName : Name) : ParserFn := fun ctx s => let categories := (parserExtension.getState ctx.env).categories; match categories.find? catName with | some cat => prattParser catName cat.tables cat.leadingIdentAsSymbol (mkCategoryAntiquotParser catName) ctx s | none => s.mkUnexpectedError ("unknown parser category '" ++ toString catName ++ "'") @[init] def setCategoryParserFnRef : IO Unit := categoryParserFnRef.set categoryParserFnImpl def addToken (env : Environment) (tk : TokenConfig) : Except String Environment := do -- Recall that `ParserExtension.addEntry` is pure, and assumes `addTokenConfig` does not fail. -- So, we must run it here to handle exception. addTokenConfig (parserExtension.getState env).tokens tk; pure $ parserExtension.addEntry env $ ParserExtensionEntry.token tk def addSyntaxNodeKind (env : Environment) (k : SyntaxNodeKind) : Environment := parserExtension.addEntry env $ ParserExtensionEntry.kind k def isValidSyntaxNodeKind (env : Environment) (k : SyntaxNodeKind) : Bool := let kinds := (parserExtension.getState env).kinds; kinds.contains k || k == choiceKind || k == identKind || isLitKind k def getSyntaxNodeKinds (env : Environment) : List SyntaxNodeKind := do let kinds := (parserExtension.getState env).kinds; kinds.foldl (fun ks k _ => k::ks) [] def getTokenTable (env : Environment) : TokenTable := (parserExtension.getState env).tokens def mkInputContext (input : String) (fileName : String) : InputContext := { input := input, fileName := fileName, fileMap := input.toFileMap } def mkParserContext (env : Environment) (ctx : InputContext) : ParserContext := { rbp := 0, toInputContext := ctx, env := env, tokens := getTokenTable env } def mkParserState (input : String) : ParserState := { cache := initCacheForInput input } /- convenience function for testing -/ def runParserCategory (env : Environment) (catName : Name) (input : String) (fileName := "<input>") : Except String Syntax := let c := mkParserContext env (mkInputContext input fileName); let s := mkParserState input; let s := whitespace c s; let s := categoryParserFnImpl catName c s; if s.hasError then Except.error (s.toErrorMsg c) else Except.ok s.stxStack.back def declareBuiltinParser (env : Environment) (addFnName : Name) (catName : Name) (declName : Name) : IO Environment := let name := `_regBuiltinParser ++ declName; let type := mkApp (mkConst `IO) (mkConst `Unit); let val := mkAppN (mkConst addFnName) #[toExpr catName, toExpr declName, mkConst declName]; let decl := Declaration.defnDecl { name := name, lparams := [], type := type, value := val, hints := ReducibilityHints.opaque, isUnsafe := false }; match env.addAndCompile {} decl with -- TODO: pretty print error | Except.error _ => throw (IO.userError ("failed to emit registration code for builtin parser '" ++ toString declName ++ "'")) | Except.ok env => IO.ofExcept (setInitAttr env name) def declareLeadingBuiltinParser (env : Environment) (catName : Name) (declName : Name) : IO Environment := declareBuiltinParser env `Lean.Parser.addBuiltinLeadingParser catName declName def declareTrailingBuiltinParser (env : Environment) (catName : Name) (declName : Name) : IO Environment := declareBuiltinParser env `Lean.Parser.addBuiltinTrailingParser catName declName private def BuiltinParserAttribute.add (attrName : Name) (catName : Name) (env : Environment) (declName : Name) (args : Syntax) (persistent : Bool) : IO Environment := do when args.hasArgs $ throw (IO.userError ("invalid attribute '" ++ toString attrName ++ "', unexpected argument")); unless persistent $ throw (IO.userError ("invalid attribute '" ++ toString attrName ++ "', must be persistent")); match env.find? declName with | none => throw $ IO.userError "unknown declaration" | some decl => match decl.type with | Expr.const `Lean.Parser.TrailingParser _ _ => declareTrailingBuiltinParser env catName declName | Expr.const `Lean.Parser.Parser _ _ => declareLeadingBuiltinParser env catName declName | _ => throw (IO.userError ("unexpected parser type at '" ++ toString declName ++ "' (`Parser` or `TrailingParser` expected")) /- The parsing tables for builtin parsers are "stored" in the extracted source code. -/ def registerBuiltinParserAttribute (attrName : Name) (catName : Name) (leadingIdentAsSymbol := false) : IO Unit := do addBuiltinParserCategory catName leadingIdentAsSymbol; registerBuiltinAttribute { name := attrName, descr := "Builtin parser", add := BuiltinParserAttribute.add attrName catName, applicationTime := AttributeApplicationTime.afterCompilation } private def ParserAttribute.add (attrName : Name) (catName : Name) (env : Environment) (declName : Name) (args : Syntax) (persistent : Bool) : IO Environment := do when args.hasArgs $ throw (IO.userError ("invalid attribute '" ++ toString attrName ++ "', unexpected argument")); let categories := (parserExtension.getState env).categories; match mkParserOfConstant env categories declName with | Except.error ex => throw (IO.userError ex) | Except.ok p => do let leading := p.1; let parser := p.2; let tokens := parser.info.collectTokens []; env ← tokens.foldlM (fun env token => match addToken env token with | Except.ok env => pure env | Except.error msg => throw (IO.userError ("invalid parser '" ++ toString declName ++ "', " ++ msg))) env; let kinds := parser.info.collectKinds {}; let env := kinds.foldl (fun env kind _ => addSyntaxNodeKind env kind) env; match addParser categories catName declName leading parser with | Except.ok _ => pure $ parserExtension.addEntry env $ ParserExtensionEntry.parser catName declName leading parser | Except.error ex => throw (IO.userError ex) def mkParserAttributeImpl (attrName : Name) (catName : Name) : AttributeImpl := { name := attrName, descr := "parser", add := ParserAttribute.add attrName catName, applicationTime := AttributeApplicationTime.afterCompilation } /- A builtin parser attribute that can be extended by users. -/ def registerBuiltinDynamicParserAttribute (attrName : Name) (catName : Name) : IO Unit := do registerBuiltinAttribute (mkParserAttributeImpl attrName catName) @[init] private def registerParserAttributeImplBuilder : IO Unit := registerAttributeImplBuilder `parserAttr $ fun args => match args with | [DataValue.ofName attrName, DataValue.ofName catName] => pure $ mkParserAttributeImpl attrName catName | _ => throw ("invalid parser attribute implementation builder arguments") def registerParserCategory (env : Environment) (attrName : Name) (catName : Name) (leadingIdentAsSymbol := false) : IO Environment := do env ← IO.ofExcept $ addParserCategory env catName leadingIdentAsSymbol; registerAttributeOfBuilder env `parserAttr [DataValue.ofName attrName, DataValue.ofName catName] -- declare `termParser` here since it is used everywhere via antiquotations @[init] def regBuiltinTermParserAttr : IO Unit := registerBuiltinParserAttribute `builtinTermParser `term @[init] def regTermParserAttribute : IO Unit := registerBuiltinDynamicParserAttribute `termParser `term def fieldIdxFn : ParserFn := fun c s => let iniPos := s.pos; let curr := c.input.get iniPos; if curr.isDigit && curr != '0' then let s := takeWhileFn (fun c => c.isDigit) c s; mkNodeToken fieldIdxKind iniPos c s else s.mkErrorAt "field index" iniPos @[inline] def fieldIdx : Parser := withAntiquot (mkAntiquot "fieldIdx" `fieldIdx) { fn := fieldIdxFn, info := mkAtomicInfo "fieldIdx" } end Parser namespace Syntax section variables {β : Type} {m : Type → Type} [Monad m] @[inline] def foldArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β := s.getArgs.foldlM (flip f) b @[inline] def foldArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β := Id.run (s.foldArgsM f b) @[inline] def forArgsM (s : Syntax) (f : Syntax → m Unit) : m Unit := s.foldArgsM (fun s _ => f s) () @[inline] def foldSepArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β := s.getArgs.foldlStepM (flip f) b 2 @[inline] def foldSepArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β := Id.run (s.foldSepArgsM f b) @[inline] def forSepArgsM (s : Syntax) (f : Syntax → m Unit) : m Unit := s.foldSepArgsM (fun s _ => f s) () @[inline] def foldSepRevArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β := do let args := foldSepArgs s (fun arg (args : Array Syntax) => args.push arg) #[]; args.foldrM f b @[inline] def foldSepRevArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β := do Id.run $ foldSepRevArgsM s f b end end Syntax end Lean section variables {β : Type} {m : Type → Type} [Monad m] open Lean open Lean.Syntax @[inline] def Array.foldSepByM (args : Array Syntax) (f : Syntax → β → m β) (b : β) : m β := args.foldlStepM (flip f) b 2 @[inline] def Array.foldSepBy (args : Array Syntax) (f : Syntax → β → β) (b : β) : β := Id.run $ args.foldSepByM f b end
ded7f4c562014f37ac737532350ab0a376a9154c
aa5a655c05e5359a70646b7154e7cac59f0b4132
/src/Lean/Data/SMap.lean
475ac44609360af9b13dd16098cbbe62f29824eb
[ "Apache-2.0" ]
permissive
lambdaxymox/lean4
ae943c960a42247e06eff25c35338268d07454cb
278d47c77270664ef29715faab467feac8a0f446
refs/heads/master
1,677,891,867,340
1,612,500,005,000
1,612,500,005,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,195
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 -/ import Std.Data.HashMap import Std.Data.PersistentHashMap universes u v w w' namespace Lean open Std (HashMap PHashMap) /- Staged map for implementing the Environment. The idea is to store imported entries into a hashtable and local entries into a persistent hashtable. Hypotheses: - The number of entries (i.e., declarations) coming from imported files is much bigger than the number of entries in the current file. - HashMap is faster than PersistentHashMap. - When we are reading imported files, we have exclusive access to the map, and efficient destructive updates are performed. Remarks: - We never remove declarations from the Environment. In principle, we could support deletion by using `(PHashMap α (Option β))` where the value `none` would indicate that an entry was "removed" from the hashtable. - We do not need additional bookkeeping for extracting the local entries. -/ structure SMap (α : Type u) (β : Type v) [BEq α] [Hashable α] where stage₁ : Bool := true map₁ : HashMap α β := {} map₂ : PHashMap α β := {} namespace SMap variable {α : Type u} {β : Type v} [BEq α] [Hashable α] instance : Inhabited (SMap α β) := ⟨{}⟩ def empty : SMap α β := {} @[specialize] def insert : SMap α β → α → β → SMap α β | ⟨true, m₁, m₂⟩, k, v => ⟨true, m₁.insert k v, m₂⟩ | ⟨false, m₁, m₂⟩, k, v => ⟨false, m₁, m₂.insert k v⟩ @[specialize] def find? : SMap α β → α → Option β | ⟨true, m₁, _⟩, k => m₁.find? k | ⟨false, m₁, m₂⟩, k => (m₂.find? k).orElse (m₁.find? k) @[inline] def findD (m : SMap α β) (a : α) (b₀ : β) : β := (m.find? a).getD b₀ @[inline] def find! [Inhabited β] (m : SMap α β) (a : α) : β := match m.find? a with | some b => b | none => panic! "key is not in the map" @[specialize] def contains : SMap α β → α → Bool | ⟨true, m₁, _⟩, k => m₁.contains k | ⟨false, m₁, m₂⟩, k => m₁.contains k || m₂.contains k /- Similar to `find?`, but searches for result in the hashmap first. So, the result is correct only if we never "overwrite" `map₁` entries using `map₂`. -/ @[specialize] def find?' : SMap α β → α → Option β | ⟨true, m₁, _⟩, k => m₁.find? k | ⟨false, m₁, m₂⟩, k => (m₁.find? k).orElse (m₂.find? k) /- Move from stage 1 into stage 2. -/ def switch (m : SMap α β) : SMap α β := if m.stage₁ then { m with stage₁ := false } else m @[inline] def foldStage2 {σ : Type w} (f : σ → α → β → σ) (s : σ) (m : SMap α β) : σ := m.map₂.foldl f s def fold {σ : Type w} (f : σ → α → β → σ) (s : σ) (m : SMap α β) : σ := m.map₂.foldl f $ m.map₁.fold f s def size (m : SMap α β) : Nat := m.map₁.size + m.map₂.size def stageSizes (m : SMap α β) : Nat × Nat := (m.map₁.size, m.map₂.size) def numBuckets (m : SMap α β) : Nat := m.map₁.numBuckets end SMap end Lean
b7cac13e818fcd5547be6d6d7e23c3473a1ad27c
8e6cad62ec62c6c348e5faaa3c3f2079012bdd69
/src/ring_theory/polynomial/basic.lean
2f38cff8ab693d39b2c48a178d268a3fbbfb6505
[ "Apache-2.0" ]
permissive
benjamindavidson/mathlib
8cc81c865aa8e7cf4462245f58d35ae9a56b150d
fad44b9f670670d87c8e25ff9cdf63af87ad731e
refs/heads/master
1,679,545,578,362
1,615,343,014,000
1,615,343,014,000
312,926,983
0
0
Apache-2.0
1,615,360,301,000
1,605,399,418,000
Lean
UTF-8
Lean
false
false
39,476
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.char_p.basic import data.mv_polynomial.comm_ring import data.mv_polynomial.equiv import data.polynomial.field_division import ring_theory.principal_ideal_domain import ring_theory.polynomial.content /-! # Ring-theoretic supplement of data.polynomial. ## Main results * `mv_polynomial.integral_domain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `polynomial.is_noetherian_ring`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. * `polynomial.wf_dvd_monoid`: If an integral domain is a `wf_dvd_monoid`, then so is its polynomial ring. * `polynomial.unique_factorization_monoid`: If an integral domain is a `unique_factorization_monoid`, then so is its polynomial ring. -/ noncomputable theory open_locale classical big_operators universes u v w namespace polynomial instance {R : Type u} [semiring R] (p : ℕ) [h : char_p R p] : char_p (polynomial R) p := let ⟨h⟩ := h in ⟨λ n, by rw [← C.map_nat_cast, ← C_0, C_inj, h]⟩ variables (R : Type u) [comm_ring R] /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degree_le (n : with_bot ℕ) : submodule R (polynomial R) := ⨅ k : ℕ, ⨅ h : ↑k > n, (lcoeff R k).ker /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degree_lt (n : ℕ) : submodule R (polynomial R) := ⨅ k : ℕ, ⨅ h : k ≥ n, (lcoeff R k).ker variable {R} theorem mem_degree_le {n : with_bot ℕ} {f : polynomial R} : f ∈ degree_le R n ↔ degree f ≤ n := by simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl @[mono] theorem degree_le_mono {m n : with_bot ℕ} (H : m ≤ n) : degree_le R m ≤ degree_le R n := λ f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H) theorem degree_le_eq_span_X_pow {n : ℕ} : degree_le R n = submodule.span R ↑((finset.range (n+1)).image (λ n, (X : polynomial R)^n)) := begin apply le_antisymm, { intros p hp, replace hp := mem_degree_le.1 hp, rw [← finsupp.sum_single p, finsupp.sum], refine submodule.sum_mem _ (λ k hk, _), show monomial _ _ ∈ _, have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk), rw [single_eq_C_mul_X, C_mul'], refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $ finset.mem_image.2 ⟨_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl⟩) }, rw [submodule.span_le, finset.coe_image, set.image_subset_iff], intros k hk, apply mem_degree_le.2, exact (degree_X_pow_le _).trans (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk) end theorem mem_degree_lt {n : ℕ} {f : polynomial R} : f ∈ degree_lt R n ↔ degree f < n := by { simp_rw [degree_lt, submodule.mem_infi, linear_map.mem_ker, degree, finset.sup_lt_iff (with_bot.bot_lt_coe n), finsupp.mem_support_iff, with_bot.some_eq_coe, with_bot.coe_lt_coe, lt_iff_not_ge', ne, not_imp_not], refl } @[mono] theorem degree_lt_mono {m n : ℕ} (H : m ≤ n) : degree_lt R m ≤ degree_lt R n := λ f hf, mem_degree_lt.2 (lt_of_lt_of_le (mem_degree_lt.1 hf) $ with_bot.coe_le_coe.2 H) theorem degree_lt_eq_span_X_pow {n : ℕ} : degree_lt R n = submodule.span R ↑((finset.range n).image (λ n, X^n) : finset (polynomial R)) := begin apply le_antisymm, { intros p hp, replace hp := mem_degree_lt.1 hp, rw [← finsupp.sum_single p, finsupp.sum], refine submodule.sum_mem _ (λ k hk, _), show monomial _ _ ∈ _, have := with_bot.coe_lt_coe.1 ((finset.sup_lt_iff $ with_bot.bot_lt_coe n).1 hp k hk), rw [single_eq_C_mul_X, C_mul'], refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $ finset.mem_image.2 ⟨_, finset.mem_range.2 this, rfl⟩) }, rw [submodule.span_le, finset.coe_image, set.image_subset_iff], intros k hk, apply mem_degree_lt.2, exact lt_of_le_of_lt (degree_X_pow_le _) (with_bot.coe_lt_coe.2 $ finset.mem_range.1 hk) end /-- The first `n` coefficients on `degree_lt n` form a linear equivalence with `fin n → F`. -/ def degree_lt_equiv (F : Type*) [field F] (n : ℕ) : degree_lt F n ≃ₗ[F] (fin n → F) := { to_fun := λ p n, (↑p : polynomial F).coeff n, inv_fun := λ f, ⟨∑ i : fin n, monomial i (f i), (degree_lt F n).sum_mem (λ i _, mem_degree_lt.mpr (lt_of_le_of_lt (degree_monomial_le i (f i)) (with_bot.coe_lt_coe.mpr i.is_lt)))⟩, map_add' := λ p q, by { ext, rw [submodule.coe_add, coeff_add], refl }, map_smul' := λ x p, by { ext, rw [submodule.coe_smul, coeff_smul], refl }, left_inv := begin rintro ⟨p, hp⟩, ext1, simp only [submodule.coe_mk], by_cases hp0 : p = 0, { subst hp0, simp only [coeff_zero, linear_map.map_zero, finset.sum_const_zero] }, rw [mem_degree_lt, degree_eq_nat_degree hp0, with_bot.coe_lt_coe] at hp, conv_rhs { rw [p.as_sum_range' n hp, ← fin.sum_univ_eq_sum_range] }, end, right_inv := begin intro f, ext i, simp only [finset_sum_coeff, submodule.coe_mk], rw [finset.sum_eq_single i, coeff_monomial, if_pos rfl], { rintro j - hji, rw [coeff_monomial, if_neg], rwa [← subtype.ext_iff] }, { intro h, exact (h (finset.mem_univ _)).elim } end } local attribute [instance] subset.ring /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction (p : polynomial R) : polynomial (ring.closure (↑p.frange : set R)) := ⟨p.support, λ i, ⟨p.to_fun i, if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem else ring.subset_closure $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩, λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩ @[simp] theorem coeff_restriction {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl @[simp] theorem coeff_restriction' {p : polynomial R} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := rfl section local attribute [instance] algebra.of_is_subring subring.domain subset.comm_ring @[simp] theorem map_restriction (p : polynomial R) : p.restriction.map (algebra_map _ _) = p := ext $ λ n, by rw [coeff_map, algebra.is_subring_algebra_map_apply, coeff_restriction] end @[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl @[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl @[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) ↔ monic p := ⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩ @[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl @[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 := ext $ λ i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl variables {S : Type v} [ring S] {f : R →+* S} {x : S} theorem eval₂_restriction {p : polynomial R} : eval₂ f x p = eval₂ (f.comp (is_subring.subtype _)) x p.restriction := by { dsimp only [eval₂_eq_sum], refl, } section to_subring variables (p : polynomial R) (T : set R) [is_subring T] /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T. -/ def to_subring (hp : ↑p.frange ⊆ T) : polynomial T := ⟨p.support, λ i, ⟨p.to_fun i, if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem else hp $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩, λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩ variables (hp : ↑p.frange ⊆ T) include hp @[simp] theorem coeff_to_subring {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl @[simp] theorem coeff_to_subring' {n : ℕ} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl @[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl @[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl @[simp] theorem monic_to_subring : monic (to_subring p T hp) ↔ monic p := ⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩ omit hp @[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl @[simp] theorem to_subring_one : to_subring (1 : polynomial R) T (set.subset.trans (finset.coe_subset.2 finsupp.frange_single) (finset.singleton_subset_set_iff.2 is_submonoid.one_mem)) = 1 := ext $ λ i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl @[simp] theorem map_to_subring : (p.to_subring T hp).map (is_subring.subtype T) = p := ext $ λ n, coeff_map _ _ end to_subring variables (T : set R) [is_subring T] /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefificents are in the ambient ring. -/ def of_subring (p : polynomial T) : polynomial R := ⟨p.support, subtype.val ∘ p.to_fun, λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ h, congr_arg subtype.val h, λ h, subtype.eq h⟩)⟩ @[simp] theorem frange_of_subring {p : polynomial T} : ↑(p.of_subring T).frange ⊆ T := λ y H, let ⟨hy, x, hx⟩ := finsupp.mem_frange.1 H in hx ▸ (p.to_fun x).2 end polynomial variables {R : Type u} {σ : Type v} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] namespace ideal open polynomial /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/ lemma polynomial_mem_ideal_of_coeff_mem_ideal (I : ideal (polynomial R)) (p : polynomial R) (hp : ∀ (n : ℕ), (p.coeff n) ∈ I.comap C) : p ∈ I := sum_C_mul_X_eq p ▸ submodule.sum_mem I (λ n hn, I.mul_mem_right _ (hp n)) /-- The push-forward of an ideal `I` of `R` to `polynomial R` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : ideal R} {f : polynomial R} : f ∈ (ideal.map C I : ideal (polynomial R)) ↔ ∀ n : ℕ, f.coeff n ∈ I := begin split, { intros hf, apply submodule.span_induction hf, { intros f hf n, cases (set.mem_image _ _ _).mp hf with x hx, rw [← hx.right, coeff_C], by_cases (n = 0), { simpa [h] using hx.left }, { simp [h] } }, { simp }, { exact λ f g hf hg n, by simp [I.add_mem (hf n) (hg n)] }, { refine λ f g hg n, _, rw [smul_eq_mul, coeff_mul], exact I.sum_mem (λ c hc, I.smul_mem (f.coeff c.fst) (hg c.snd)) } }, { intros hf, rw ← sum_monomial_eq f, refine (map C I : ideal (polynomial R)).sum_mem (λ n hn, _), simp [single_eq_C_mul_X], rw mul_comm, exact (map C I : ideal (polynomial R)).smul_mem _ (mem_map_of_mem (hf n)) } end lemma quotient_map_C_eq_zero {I : ideal R} : ∀ a ∈ I, ((quotient.mk (map C I : ideal (polynomial R))).comp C) a = 0 := begin intros a ha, rw [ring_hom.comp_apply, quotient.eq_zero_iff_mem], exact mem_map_of_mem ha, end lemma eval₂_C_mk_eq_zero {I : ideal R} : ∀ f ∈ (map C I : ideal (polynomial R)), eval₂_ring_hom (C.comp (quotient.mk I)) X f = 0 := begin intros a ha, rw ← sum_monomial_eq a, dsimp, rw eval₂_sum, refine finset.sum_eq_zero (λ n hn, _), dsimp, rw eval₂_monomial (C.comp (quotient.mk I)) X, refine mul_eq_zero_of_left (polynomial.ext (λ m, _)) (X ^ n), erw coeff_C, by_cases h : m = 0, { simpa [h] using quotient.eq_zero_iff_mem.2 ((mem_map_C_iff.1 ha) n) }, { simp [h] } end /-- If `I` is an ideal of `R`, then the ring polynomials over the quotient ring `I.quotient` is isomorphic to the quotient of `polynomial R` by the ideal `map C I`, where `map C I` contains exactly the polynomials whose coefficients all lie in `I` -/ def polynomial_quotient_equiv_quotient_polynomial (I : ideal R) : polynomial (I.quotient) ≃+* (map C I : ideal (polynomial R)).quotient := { to_fun := eval₂_ring_hom (quotient.lift I ((quotient.mk (map C I : ideal (polynomial R))).comp C) quotient_map_C_eq_zero) ((quotient.mk (map C I : ideal (polynomial R)) X)), inv_fun := quotient.lift (map C I : ideal (polynomial R)) (eval₂_ring_hom (C.comp (quotient.mk I)) X) eval₂_C_mk_eq_zero, map_mul' := λ f g, by simp, map_add' := λ f g, by simp, left_inv := begin intro f, apply polynomial.induction_on' f, { simp_intros p q hp hq, rw [hp, hq] }, { rintros n ⟨x⟩, simp [monomial_eq_smul_X, C_mul'] } end, right_inv := begin rintro ⟨f⟩, apply polynomial.induction_on' f, { simp_intros p q hp hq, rw [hp, hq] }, { intros n a, simp [monomial_eq_smul_X, ← C_mul' a (X ^ n)] }, end, } /-- If `P` is a prime ideal of `R`, then `R[x]/(P)` is an integral domain. -/ lemma is_integral_domain_map_C_quotient {P : ideal R} (H : is_prime P) : is_integral_domain (quotient (map C P : ideal (polynomial R))) := ring_equiv.is_integral_domain (polynomial (quotient P)) (integral_domain.to_is_integral_domain (polynomial (quotient P))) (polynomial_quotient_equiv_quotient_polynomial P).symm /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ lemma is_prime_map_C_of_is_prime {P : ideal R} (H : is_prime P) : is_prime (map C P : ideal (polynomial R)) := (quotient.is_integral_domain_iff_prime (map C P : ideal (polynomial R))).mp (is_integral_domain_map_C_quotient H) /-- Given any ring `R` and an ideal `I` of `polynomial R`, we get a map `R → R[x] → R[x]/I`. If we let `R` be the image of `R` in `R[x]/I` then we also have a map `R[x] → R'[x]`. In particular we can map `I` across this map, to get `I'` and a new map `R' → R'[x] → R'[x]/I`. This theorem shows `I'` will not contain any non-zero constant polynomials -/ lemma eq_zero_of_polynomial_mem_map_range (I : ideal (polynomial R)) (x : ((quotient.mk I).comp C).range) (hx : C x ∈ (I.map (polynomial.map_ring_hom ((quotient.mk I).comp C).range_restrict))) : x = 0 := begin let i := ((quotient.mk I).comp C).range_restrict, have hi' : (polynomial.map_ring_hom i).ker ≤ I, { refine λ f hf, polynomial_mem_ideal_of_coeff_mem_ideal I f (λ n, _), rw [mem_comap, ← quotient.eq_zero_iff_mem, ← ring_hom.comp_apply], rw [ring_hom.mem_ker, coe_map_ring_hom] at hf, replace hf := congr_arg (λ (f : polynomial _), f.coeff n) hf, simp only [coeff_map, coeff_zero] at hf, rwa [subtype.ext_iff, ring_hom.coe_range_restrict] at hf }, obtain ⟨x, hx'⟩ := x, obtain ⟨y, rfl⟩ := (ring_hom.mem_range).1 hx', refine subtype.eq _, simp only [ring_hom.comp_apply, quotient.eq_zero_iff_mem, subring.coe_zero, subtype.val_eq_coe], suffices : C (i y) ∈ (I.map (polynomial.map_ring_hom i)), { obtain ⟨f, hf⟩ := mem_image_of_mem_map_of_surjective (polynomial.map_ring_hom i) (polynomial.map_surjective _ (((quotient.mk I).comp C).range_restrict_surjective)) this, refine sub_add_cancel (C y) f ▸ I.add_mem (hi' _ : (C y - f) ∈ I) hf.1, rw [ring_hom.mem_ker, ring_hom.map_sub, hf.2, sub_eq_zero_iff_eq, coe_map_ring_hom, map_C] }, exact hx, end /-- `polynomial R` is never a field for any ring `R`. -/ lemma polynomial_not_is_field : ¬ is_field (polynomial R) := begin by_contradiction hR, by_cases hR' : ∃ (x y : R), x ≠ y, { haveI : nontrivial R := let ⟨x, y, hxy⟩ := hR' in nontrivial_of_ne x y hxy, obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero, by_cases hp0 : p = 0, { replace hp := congr_arg degree hp, rw [hp0, mul_zero, degree_zero, degree_one] at hp, contradiction }, { have : p.degree < (X * p).degree := (mul_comm p X) ▸ degree_lt_degree_mul_X hp0, rw [congr_arg degree hp, degree_one, nat.with_bot.lt_zero_iff, degree_eq_bot] at this, exact hp0 this } }, { push_neg at hR', exact let ⟨x, y, hxy⟩ := hR.exists_pair_ne in hxy (polynomial.ext (λ n, hR' _ _)) } end /-- The only constant in a maximal ideal over a field is `0`. -/ lemma eq_zero_of_constant_mem_of_maximal (hR : is_field R) (I : ideal (polynomial R)) [hI : I.is_maximal] (x : R) (hx : C x ∈ I) : x = 0 := begin refine classical.by_contradiction (λ hx0, hI.ne_top ((eq_top_iff_one I).2 _)), obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0, convert I.smul_mem (C y) hx, rw [smul_eq_mul, ← C.map_mul, mul_comm y x, hy, ring_hom.map_one], end /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) := { carrier := I.carrier, zero_mem' := I.zero_mem, add_mem' := λ _ _, I.add_mem, smul_mem' := λ c x H, by rw [← C_mul']; exact submodule.smul_mem _ _ H } variables {I : ideal (polynomial R)} theorem mem_of_polynomial (x) : x ∈ I.of_polynomial ↔ x ∈ I := iff.rfl variables (I) /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degree_le (n : with_bot ℕ) : submodule R (polynomial R) := degree_le R n ⊓ I.of_polynomial /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leading_coeff_nth (n : ℕ) : ideal R := (I.degree_le n).map $ lcoeff R n theorem mem_leading_coeff_nth (n : ℕ) (x) : x ∈ I.leading_coeff_nth n ↔ ∃ p ∈ I, degree p ≤ n ∧ leading_coeff p = x := begin simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le], split, { rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩, cases lt_or_eq_of_le hpdeg with hpdeg hpdeg, { refine ⟨0, I.zero_mem, bot_le, _⟩, rw [leading_coeff_zero, eq_comm], exact coeff_eq_zero_of_degree_lt hpdeg }, { refine ⟨p, hpI, le_of_eq hpdeg, _⟩, rw [leading_coeff, nat_degree, hpdeg], refl } }, { rintro ⟨p, hpI, hpdeg, rfl⟩, have : nat_degree p + (n - nat_degree p) = n, { exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) }, refine ⟨p * X ^ (n - nat_degree p), ⟨_, I.mul_mem_right _ hpI⟩, _⟩, { apply le_trans (degree_mul_le _ _) _, apply le_trans (add_le_add (degree_le_nat_degree) (degree_X_pow_le _)) _, rw [← with_bot.coe_add, this], exact le_refl _ }, { rw [leading_coeff, ← coeff_mul_X_pow p (n - nat_degree p), this] } } end theorem mem_leading_coeff_nth_zero (x) : x ∈ I.leading_coeff_nth 0 ↔ C x ∈ I := (mem_leading_coeff_nth _ _ _).trans ⟨λ ⟨p, hpI, hpdeg, hpx⟩, by rwa [← hpx, leading_coeff, nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg], λ hx, ⟨C x, hx, degree_C_le, leading_coeff_C x⟩⟩ theorem leading_coeff_nth_mono {m n : ℕ} (H : m ≤ n) : I.leading_coeff_nth m ≤ I.leading_coeff_nth n := begin intros r hr, simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr ⊢, rcases hr with ⟨p, hpI, hpdeg, rfl⟩, refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, _, leading_coeff_mul_X_pow⟩, refine le_trans (degree_mul_le _ _) _, refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) _, rw [← with_bot.coe_add, nat.add_sub_cancel' H], exact le_refl _ end /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leading_coeff : ideal R := ⨆ n : ℕ, I.leading_coeff_nth n theorem mem_leading_coeff (x) : x ∈ I.leading_coeff ↔ ∃ p ∈ I, polynomial.leading_coeff p = x := begin rw [leading_coeff, submodule.mem_supr_of_directed], simp only [mem_leading_coeff_nth], { split, { rintro ⟨i, p, hpI, hpdeg, rfl⟩, exact ⟨p, hpI, rfl⟩ }, rintro ⟨p, hpI, rfl⟩, exact ⟨nat_degree p, p, hpI, degree_le_nat_degree, rfl⟩ }, intros i j, exact ⟨i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _), I.leading_coeff_nth_mono (nat.le_add_left _ _)⟩ end theorem is_fg_degree_le [is_noetherian_ring R] (n : ℕ) : submodule.fg (I.degree_le n) := is_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _ ⟨_, degree_le_eq_span_X_pow.symm⟩) _ end ideal namespace polynomial @[priority 100] instance {R : Type*} [integral_domain R] [wf_dvd_monoid R] : wf_dvd_monoid (polynomial R) := { well_founded_dvd_not_unit := begin classical, refine rel_hom.well_founded ⟨λ p, (if p = 0 then ⊤ else ↑p.degree, p.leading_coeff), _⟩ (prod.lex_wf (with_top.well_founded_lt $ with_bot.well_founded_lt nat.lt_wf) _inst_5.well_founded_dvd_not_unit), rintros a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩, rw [polynomial.degree_mul, if_neg ane0], split_ifs with hac, { rw [hac, polynomial.leading_coeff_zero], apply prod.lex.left, exact lt_of_le_of_ne le_top with_top.coe_ne_top }, have cne0 : c ≠ 0 := right_ne_zero_of_mul hac, simp only [cne0, ane0, polynomial.leading_coeff_mul], by_cases hdeg : c.degree = 0, { simp only [hdeg, add_zero], refine prod.lex.right _ ⟨_, ⟨c.leading_coeff, (λ unit_c, not_unit_c _), rfl⟩⟩, { rwa [ne, polynomial.leading_coeff_eq_zero] }, rw [polynomial.is_unit_iff, polynomial.eq_C_of_degree_eq_zero hdeg], use [c.leading_coeff, unit_c], rw [polynomial.leading_coeff, polynomial.nat_degree_eq_of_degree_eq_some hdeg] }, { apply prod.lex.left, rw polynomial.degree_eq_nat_degree cne0 at *, rw [with_top.coe_lt_coe, polynomial.degree_eq_nat_degree ane0, ← with_bot.coe_add, with_bot.coe_lt_coe], exact lt_add_of_pos_right _ (nat.pos_of_ne_zero (λ h, hdeg (h.symm ▸ with_bot.coe_zero))) }, end } end polynomial /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected theorem polynomial.is_noetherian_ring [is_noetherian_ring R] : is_noetherian_ring (polynomial R) := is_noetherian_ring_iff.2 ⟨assume I : ideal (polynomial R), let M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance)) (set.range I.leading_coeff_nth) ⟨_, ⟨0, rfl⟩⟩ in have hm : M ∈ set.range I.leading_coeff_nth := well_founded.min_mem _ _ _, let ⟨N, HN⟩ := hm, ⟨s, hs⟩ := I.is_fg_degree_le N in have hm2 : ∀ k, I.leading_coeff_nth k ≤ M := λ k, or.cases_on (le_or_lt k N) (λ h, HN ▸ I.leading_coeff_nth_mono h) (λ h x hx, classical.by_contradiction $ λ hxm, have ¬M < I.leading_coeff_nth k, by refine well_founded.not_lt_min (well_founded_submodule_gt _ _) _ _ _; exact ⟨k, rfl⟩, this ⟨HN ▸ I.leading_coeff_nth_mono (le_of_lt h), λ H, hxm (H hx)⟩), have hs2 : ∀ {x}, x ∈ I.degree_le N → x ∈ ideal.span (↑s : set (polynomial R)), from hs ▸ λ x hx, submodule.span_induction hx (λ _ hx, ideal.subset_span hx) (ideal.zero_mem _) (λ _ _, ideal.add_mem _) (λ c f hf, f.C_mul' c ▸ ideal.mul_mem_left _ _ hf), ⟨s, le_antisymm (ideal.span_le.2 $ λ x hx, have x ∈ I.degree_le N, from hs ▸ submodule.subset_span hx, this.2) $ begin change I ≤ ideal.span ↑s, intros p hp, generalize hn : p.nat_degree = k, induction k using nat.strong_induction_on with k ih generalizing p, cases le_or_lt k N, { subst k, refine hs2 ⟨polynomial.mem_degree_le.2 (le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp⟩ }, { have hp0 : p ≠ 0, { rintro rfl, cases hn, exact nat.not_lt_zero _ h }, have : (0 : R) ≠ 1, { intro h, apply hp0, ext i, refine (mul_one _).symm.trans _, rw [← h, mul_zero], refl }, haveI : nontrivial R := ⟨⟨0, 1, this⟩⟩, have : p.leading_coeff ∈ I.leading_coeff_nth N, { rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2 ⟨_, hp, hn ▸ polynomial.degree_le_nat_degree, rfl⟩) }, rw I.mem_leading_coeff_nth at this, rcases this with ⟨q, hq, hdq, hlqp⟩, have hq0 : q ≠ 0, { intro H, rw [← polynomial.leading_coeff_eq_zero] at H, rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H }, have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree, { rw [polynomial.degree_mul', polynomial.degree_X_pow], rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0], rw [← with_bot.coe_add, nat.add_sub_cancel', hn], { refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) }, rw [polynomial.leading_coeff_X_pow, mul_one], exact mt polynomial.leading_coeff_eq_zero.1 hq0 }, have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff, { rw [← hlqp, polynomial.leading_coeff_mul_X_pow] }, have := polynomial.degree_sub_lt h1 hp0 h2, rw [polynomial.degree_eq_nat_degree hp0] at this, rw ← sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)), refine (ideal.span ↑s).add_mem _ ((ideal.span ↑s).mul_mem_right _ _), { by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0, { rw hpq, exact ideal.zero_mem _ }, refine ih _ _ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl, rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this }, exact hs2 ⟨polynomial.mem_degree_le.2 hdq, hq⟩ } end⟩⟩ attribute [instance] polynomial.is_noetherian_ring namespace polynomial theorem exists_irreducible_of_degree_pos {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : 0 < f.degree) : ∃ g, irreducible g ∧ g ∣ f := wf_dvd_monoid.exists_irreducible_factor (λ huf, ne_of_gt hf $ degree_eq_zero_of_is_unit huf) (λ hf0, not_lt_of_lt hf $ hf0.symm ▸ (@degree_zero R _).symm ▸ with_bot.bot_lt_coe _) theorem exists_irreducible_of_nat_degree_pos {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : 0 < f.nat_degree) : ∃ g, irreducible g ∧ g ∣ f := exists_irreducible_of_degree_pos $ by { contrapose! hf, exact nat_degree_le_of_degree_le hf } theorem exists_irreducible_of_nat_degree_ne_zero {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : f.nat_degree ≠ 0) : ∃ g, irreducible g ∧ g ∣ f := exists_irreducible_of_nat_degree_pos $ nat.pos_of_ne_zero hf lemma linear_independent_powers_iff_eval₂ (f : M →ₗ[R] M) (v : M) : linear_independent R (λ n : ℕ, (f ^ n) v) ↔ ∀ (p : polynomial R), aeval f p v = 0 → p = 0 := begin rw linear_independent_iff, simp only [finsupp.total_apply, aeval_endomorphism], refl end lemma disjoint_ker_aeval_of_coprime (f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) : disjoint (aeval f p).ker (aeval f q).ker := begin intros v hv, rcases hpq with ⟨p', q', hpq'⟩, simpa [linear_map.mem_ker.1 (submodule.mem_inf.1 hv).1, linear_map.mem_ker.1 (submodule.mem_inf.1 hv).2] using congr_arg (λ p : polynomial R, aeval f p v) hpq'.symm, end lemma sup_aeval_range_eq_top_of_coprime (f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) : (aeval f p).range ⊔ (aeval f q).range = ⊤ := begin rw eq_top_iff, intros v hv, rw submodule.mem_sup, rcases hpq with ⟨p', q', hpq'⟩, use aeval f (p * p') v, use linear_map.mem_range.2 ⟨aeval f p' v, by simp only [linear_map.mul_apply, aeval_mul]⟩, use aeval f (q * q') v, use linear_map.mem_range.2 ⟨aeval f q' v, by simp only [linear_map.mul_apply, aeval_mul]⟩, simpa only [mul_comm p p', mul_comm q q', aeval_one, aeval_add] using congr_arg (λ p : polynomial R, aeval f p v) hpq' end lemma sup_ker_aeval_le_ker_aeval_mul {f : M →ₗ[R] M} {p q : polynomial R} : (aeval f p).ker ⊔ (aeval f q).ker ≤ (aeval f (p * q)).ker := begin intros v hv, rcases submodule.mem_sup.1 hv with ⟨x, hx, y, hy, hxy⟩, have h_eval_x : aeval f (p * q) x = 0, { rw [mul_comm, aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hx, linear_map.map_zero] }, have h_eval_y : aeval f (p * q) y = 0, { rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hy, linear_map.map_zero] }, rw [linear_map.mem_ker, ←hxy, linear_map.map_add, h_eval_x, h_eval_y, add_zero], end lemma sup_ker_aeval_eq_ker_aeval_mul_of_coprime (f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) : (aeval f p).ker ⊔ (aeval f q).ker = (aeval f (p * q)).ker := begin apply le_antisymm sup_ker_aeval_le_ker_aeval_mul, intros v hv, rw submodule.mem_sup, rcases hpq with ⟨p', q', hpq'⟩, have h_eval₂_qpp' := calc aeval f (q * (p * p')) v = aeval f (p' * (p * q)) v : by rw [mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm q p] ... = 0 : by rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hv, linear_map.map_zero], have h_eval₂_pqq' := calc aeval f (p * (q * q')) v = aeval f (q' * (p * q)) v : by rw [←mul_assoc, mul_comm] ... = 0 : by rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hv, linear_map.map_zero], rw aeval_mul at h_eval₂_qpp' h_eval₂_pqq', refine ⟨aeval f (q * q') v, linear_map.mem_ker.1 h_eval₂_pqq', aeval f (p * p') v, linear_map.mem_ker.1 h_eval₂_qpp', _⟩, rw [add_comm, mul_comm p p', mul_comm q q'], simpa using congr_arg (λ p : polynomial R, aeval f p v) hpq' end end polynomial namespace mv_polynomial lemma is_noetherian_ring_fin_0 [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial (fin 0) R) := is_noetherian_ring_of_ring_equiv R ((mv_polynomial.pempty_ring_equiv R).symm.trans (rename_equiv R fin_zero_equiv'.symm).to_ring_equiv) theorem is_noetherian_ring_fin [is_noetherian_ring R] : ∀ {n : ℕ}, is_noetherian_ring (mv_polynomial (fin n) R) | 0 := is_noetherian_ring_fin_0 | (n+1) := @is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _ _ _ (mv_polynomial.fin_succ_equiv _ n).to_ring_equiv.symm (@polynomial.is_noetherian_ring (mv_polynomial (fin n) R) _ (is_noetherian_ring_fin)) /-- The multivariate polynomial ring in finitely many variables over a noetherian ring is itself a noetherian ring. -/ instance is_noetherian_ring [fintype σ] [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial σ R) := trunc.induction_on (fintype.equiv_fin σ) $ λ e, @is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) _ _ _ (rename_equiv R e.symm).to_ring_equiv is_noetherian_ring_fin lemma is_integral_domain_fin_zero (R : Type u) [comm_ring R] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial (fin 0) R) := ring_equiv.is_integral_domain R hR ((rename_equiv R fin_zero_equiv').to_ring_equiv.trans (mv_polynomial.pempty_ring_equiv R)) /-- Auxilliary lemma: Multivariate polynomials over an integral domain with variables indexed by `fin n` form an integral domain. This fact is proven inductively, and then used to prove the general case without any finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ lemma is_integral_domain_fin (R : Type u) [comm_ring R] (hR : is_integral_domain R) : ∀ (n : ℕ), is_integral_domain (mv_polynomial (fin n) R) | 0 := is_integral_domain_fin_zero R hR | (n+1) := ring_equiv.is_integral_domain (polynomial (mv_polynomial (fin n) R)) (is_integral_domain_fin n).polynomial (mv_polynomial.fin_succ_equiv _ n).to_ring_equiv lemma is_integral_domain_fintype (R : Type u) (σ : Type v) [comm_ring R] [fintype σ] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial σ R) := trunc.induction_on (fintype.equiv_fin σ) $ λ e, @ring_equiv.is_integral_domain _ (mv_polynomial (fin $ fintype.card σ) R) _ _ (mv_polynomial.is_integral_domain_fin _ hR _) (rename_equiv R e).to_ring_equiv /-- Auxilliary definition: Multivariate polynomials in finitely many variables over an integral domain form an integral domain. This fact is proven by transport of structure from the `mv_polynomial.integral_domain_fin`, and then used to prove the general case without finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ def integral_domain_fintype (R : Type u) (σ : Type v) [integral_domain R] [fintype σ] : integral_domain (mv_polynomial σ R) := @is_integral_domain.to_integral_domain _ _ $ mv_polynomial.is_integral_domain_fintype R σ $ integral_domain.to_is_integral_domain R protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {R : Type u} [integral_domain R] {σ : Type v} (p q : mv_polynomial σ R) (h : p * q = 0) : p = 0 ∨ q = 0 := begin obtain ⟨s, p, rfl⟩ := exists_finset_rename p, obtain ⟨t, q, rfl⟩ := exists_finset_rename q, have : rename (subtype.map id (finset.subset_union_left s t) : {x // x ∈ s} → {x // x ∈ s ∪ t}) p * rename (subtype.map id (finset.subset_union_right s t) : {x // x ∈ t} → {x // x ∈ s ∪ t}) q = 0, { apply rename_injective _ subtype.val_injective, simpa using h }, letI := mv_polynomial.integral_domain_fintype R {x // x ∈ (s ∪ t)}, rw mul_eq_zero at this, cases this; [left, right], all_goals { simpa using congr_arg (rename subtype.val) this } end /-- The multivariate polynomial ring over an integral domain is an integral domain. -/ instance {R : Type u} {σ : Type v} [integral_domain R] : integral_domain (mv_polynomial σ R) := { eq_zero_or_eq_zero_of_mul_eq_zero := mv_polynomial.eq_zero_or_eq_zero_of_mul_eq_zero, exists_pair_ne := ⟨0, 1, λ H, begin have : eval₂ (ring_hom.id _) (λ s, (0:R)) (0 : mv_polynomial σ R) = eval₂ (ring_hom.id _) (λ s, (0:R)) (1 : mv_polynomial σ R), { congr, exact H }, simpa, end⟩, .. (by apply_instance : comm_ring (mv_polynomial σ R)) } lemma map_mv_polynomial_eq_eval₂ {S : Type*} [comm_ring S] [fintype σ] (ϕ : mv_polynomial σ R →+* S) (p : mv_polynomial σ R) : ϕ p = mv_polynomial.eval₂ (ϕ.comp mv_polynomial.C) (λ s, ϕ (mv_polynomial.X s)) p := begin refine trans (congr_arg ϕ (mv_polynomial.as_sum p)) _, rw [mv_polynomial.eval₂_eq', ϕ.map_sum], congr, ext, simp only [monomial_eq, ϕ.map_pow, ϕ.map_prod, ϕ.comp_apply, ϕ.map_mul, finsupp.prod_pow], end lemma quotient_map_C_eq_zero {I : ideal R} {i : R} (hi : i ∈ I) : (ideal.quotient.mk (ideal.map C I : ideal (mv_polynomial σ R))).comp C i = 0 := begin simp only [function.comp_app, ring_hom.coe_comp, ideal.quotient.eq_zero_iff_mem], exact ideal.mem_map_of_mem hi end /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself, multivariate version. -/ lemma mem_ideal_of_coeff_mem_ideal (I : ideal (mv_polynomial σ R)) (p : mv_polynomial σ R) (hcoe : ∀ (m : σ →₀ ℕ), p.coeff m ∈ I.comap C) : p ∈ I := begin rw as_sum p, suffices : ∀ m ∈ p.support, monomial m (mv_polynomial.coeff m p) ∈ I, { exact submodule.sum_mem I this }, intros m hm, rw [← mul_one (coeff m p), ← C_mul_monomial], suffices : C (coeff m p) ∈ I, { exact ideal.mul_mem_right I (monomial m 1) this }, simpa [ideal.mem_comap] using hcoe m end /-- The push-forward of an ideal `I` of `R` to `mv_polynomial σ R` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : ideal R} {f : mv_polynomial σ R} : f ∈ (ideal.map C I : ideal (mv_polynomial σ R)) ↔ ∀ (m : σ →₀ ℕ), f.coeff m ∈ I := begin split, { intros hf, apply submodule.span_induction hf, { intros f hf n, cases (set.mem_image _ _ _).mp hf with x hx, rw [← hx.right, coeff_C], by_cases (n = 0), { simpa [h] using hx.left }, { simp [ne.symm h] } }, { simp }, { exact λ f g hf hg n, by simp [I.add_mem (hf n) (hg n)] }, { refine λ f g hg n, _, rw [smul_eq_mul, coeff_mul], exact I.sum_mem (λ c hc, I.smul_mem (f.coeff c.fst) (hg c.snd)) } }, { intros hf, rw as_sum f, suffices : ∀ m ∈ f.support, monomial m (coeff m f) ∈ (ideal.map C I : ideal (mv_polynomial σ R)), { exact submodule.sum_mem _ this }, intros m hm, rw [← mul_one (coeff m f), ← C_mul_monomial], suffices : C (coeff m f) ∈ (ideal.map C I : ideal (mv_polynomial σ R)), { exact ideal.mul_mem_right _ _ this }, apply ideal.mem_map_of_mem _, exact hf m } end lemma eval₂_C_mk_eq_zero {I : ideal R} {a : mv_polynomial σ R} (ha : a ∈ (ideal.map C I : ideal (mv_polynomial σ R))) : eval₂_hom (C.comp (ideal.quotient.mk I)) X a = 0 := begin rw as_sum a, rw [coe_eval₂_hom, eval₂_sum], refine finset.sum_eq_zero (λ n hn, _), simp only [eval₂_monomial, function.comp_app, ring_hom.coe_comp], refine mul_eq_zero_of_left _ _, suffices : coeff n a ∈ I, { rw [← @ideal.mk_ker R _ I, ring_hom.mem_ker] at this, simp only [this, C_0] }, exact mem_map_C_iff.1 ha n end /-- If `I` is an ideal of `R`, then the ring `mv_polynomial σ I.quotient` is isomorphic to the quotient of `mv_polynomial σ R` by the ideal generated by `I`. -/ def quotient_equiv_quotient_mv_polynomial (I : ideal R) : mv_polynomial σ (I.quotient) ≃+* (ideal.map C I : ideal (mv_polynomial σ R)).quotient := { to_fun := eval₂_hom (ideal.quotient.lift I ((ideal.quotient.mk (ideal.map C I : ideal (mv_polynomial σ R))).comp C) (λ i hi, quotient_map_C_eq_zero hi)) (λ i, ideal.quotient.mk (ideal.map C I : ideal (mv_polynomial σ R)) (X i)), inv_fun := ideal.quotient.lift (ideal.map C I : ideal (mv_polynomial σ R)) (eval₂_hom (C.comp (ideal.quotient.mk I)) X) (λ a ha, eval₂_C_mk_eq_zero ha), map_mul' := λ f g, by simp, map_add' := λ f g, by simp, left_inv := begin intro f, apply induction_on f, { rintro ⟨r⟩, rw [coe_eval₂_hom, eval₂_C], simp only [eval₂_hom_eq_bind₂, submodule.quotient.quot_mk_eq_mk, ideal.quotient.lift_mk, ideal.quotient.mk_eq_mk, bind₂_C_right, ring_hom.coe_comp] }, { simp_intros p q hp hq, rw [hp, hq] }, { simp_intros p i hp, simp only [hp, eval₂_hom_eq_bind₂, coe_eval₂_hom, ideal.quotient.lift_mk, bind₂_X_right, eval₂_mul, ring_hom.map_mul, eval₂_X] } end, right_inv := begin rintro ⟨f⟩, apply induction_on f, { intros r, simp only [submodule.quotient.quot_mk_eq_mk, ideal.quotient.lift_mk, ideal.quotient.mk_eq_mk, ring_hom.coe_comp, eval₂_hom_C] }, { simp_intros p q hp hq, rw [hp, hq] }, { simp_intros p i hp, simp only [hp] } end, } /-- If `I` is an ideal of `R`, then the ring `mv_polynomial σ I.quotient` is isomorphic, as `R`-algebra, to the quotient of `mv_polynomial σ R` by the ideal generated by `I`. -/ def quotient_alg_equiv_quotient_mv_polynomial (I : ideal R) : algebra.comap R I.quotient (mv_polynomial σ (I.quotient)) ≃ₐ[R] (ideal.map C I : ideal (mv_polynomial σ R)).quotient := { commutes' := begin intro r, change (algebra_map R (algebra.comap R I.quotient (mv_polynomial σ (I.quotient)))) r with C (ideal.quotient.mk I r), simpa [algebra_map, quotient_equiv_quotient_mv_polynomial], end, ..quotient_equiv_quotient_mv_polynomial I, } end mv_polynomial namespace polynomial open unique_factorization_monoid variables {D : Type u} [integral_domain D] [unique_factorization_monoid D] @[priority 100] instance unique_factorization_monoid : unique_factorization_monoid (polynomial D) := begin haveI := arbitrary (normalization_monoid D), haveI := to_gcd_monoid D, exact ufm_of_gcd_of_wf_dvd_monoid end end polynomial
28f6aeb00c61d8667e9733223044a3318eed0bb0
43d840497673d50aaf1058dc851b1edc51d1ab11
/src/solutions/tuesday/afternoon/numbers.lean
6fcdad79a35e46805882ce86aecf04b7e1d4ce84
[]
permissive
dhruva-divate/lftcm2020
6606bc857204fbfd8ab92812060c0e5114f67e0d
d2e1a31a4ad280eadef1d0ae6a89920b7345c823
refs/heads/master
1,668,432,237,346
1,594,377,206,000
1,594,377,206,000
278,630,020
0
0
MIT
1,594,384,713,000
1,594,384,712,000
null
UTF-8
Lean
false
false
5,019
lean
import tactic import data.real.basic import data.int.gcd import data.padics /-! ## Exercises about numbers and casts -/ /-! ## First exercises These first examples are just to get you comfortable with `norm_num`, `norm_cast`, and friends. -/ example : 12345 < 67890 := begin norm_num end example {α : Type} [linear_ordered_field α] : 123 + 45 < 67890/3 := begin norm_num end example : nat.prime 17 := begin norm_num end -- prove either this or its negation! example : ¬ 7/3 > 2 := begin norm_num end example (x : ℝ) (hx : x < 50*50) : x < 25*100 := begin norm_num at hx ⊢, assumption end example (x : ℤ) (hx : (x : ℝ) < 25*100) : x < 25*100 := begin assumption_mod_cast end example (x : ℤ) (hx : (x : ℝ) < 2500) : x < 25*100 := begin norm_num, assumption_mod_cast end example (p q r : ℕ) (h : r < p - q) (hpq : q ≤ p) : (r : ℝ) < p - q := begin end example (p q r : ℕ) (hr : r < p + 2 - p) : (r : ℤ) < 5 := begin have : p ≤ p + 2, by linarith, zify [this] at hr, linarith end /-! ## Exercise 2 This comes from the development of the p-adic numbers. `norm_cast` is very useful here, since we need to talk about values in ℕ, ℤ, ℚ, ℚ_p, and ℤ_p. We've done some work to get you started. You might look for the lemmas: -/ open padic_val_rat #check fpow_le_of_le #check fpow_nonneg_of_nonneg #check padic_val_rat_of_int example {p n : ℕ} (hp : p.prime) {z : ℤ} (hd : ↑(p^n) ∣ z) : padic_norm p z ≤ ↑p ^ (-n : ℤ) := begin -- this lemma will be useful later in the proof. -- ignore the "inst" argument; just use `apply aux_lemma` when you need it! have aux_lemma : ∀ inst, (n : ℤ) ≤ (multiplicity ↑p z).get inst, { intro, norm_cast, rw [← enat.coe_le_coe, enat.coe_get], apply multiplicity.le_multiplicity_of_pow_dvd, assumption_mod_cast }, unfold padic_norm, split_ifs with hz hz, { apply fpow_nonneg_of_nonneg, exact_mod_cast le_of_lt hp.pos }, { apply fpow_le_of_le, exact_mod_cast le_of_lt hp.one_lt, apply neg_le_neg, rw padic_val_rat_of_int _ hp.ne_one _, { apply aux_lemma }, { assumption_mod_cast } } end /-! ## Exercise 3 This seems like a very natural way to write the theorem "If `a` and `b` are coprime, then there are coefficients `u` and `v` such that `u*a + v*b = 1`." But I've made a mistake! What did I do wrong? Correct the statement of the theorem and prove it. I've started you off with a lemma that will be useful. You might find the `specialize` tactic to be handy as well: if you have `h : ∀ (x y : T), R x y` and `a, b : T` in the context, then `specialize h a b` will change the type of `h` to `R a b`. If you want to peek at the definition of coprime, you can use `unfold nat.coprime at h`. -/ -- notice that I've changed the existential to be over ℤ! example (p q : ℕ) (h : nat.coprime p q) : ∃ u v : ℤ, u*p+v*q = 1 := begin have := nat.gcd_eq_gcd_ab, specialize this p q, unfold nat.coprime at h, rw h at this, norm_cast at this, use [p.gcd_a q, p.gcd_b q], rw this, ring end /-! ## Exercise 4 We did an example together that was similar to this. This one takes a bit more arithmetic work. To save you some time, here are some lemmas that may be useful! (You may not need all of them, depending on how you approach it.) Remember you can also use `library_search` to try to find useful lemmas. A hint: you might find it helpful to do this once you've introduced `n`. ``` have n_pos: 0 < n, { ... } ``` -/ #check sub_le_iff_le_add #check add_le_add_iff_left #check div_le_iff #check mul_one_div_cancel #check mul_le_mul_left notation `|`x`|` := abs x def seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop := ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε example : seq_limit (λ n : ℕ, (n+1)/n) 1 := begin -- we start like before intros ε ε_pos, dsimp, -- the witness to the existential must be a nat: use `nat_ceil` instead of `ceil`! use nat_ceil (1/ε), intros n hn, -- this proof is used a few times below, so we separate it as an assumption have n_pos : 0 < n, -- I've written the proofs of the calc block separately, but you could inline them { calc 0 < nat_ceil (1/ε) : _ ... ≤ n : _, { rw lt_nat_ceil, simp, assumption }, { assumption } }, -- this chain of rewrites generates some side conditions that we get rid of below rw [abs_of_nonneg, sub_le_iff_le_add, div_le_iff, add_mul, one_mul, add_comm _ (n : ℝ), add_le_add_iff_left], -- this calc proof finishes the "main goal" { calc 1 = ε * (1/ε) : _ ... ≤ ε * nat_ceil (1/ε) : _ ... ≤ ε * n : _, { symmetry, apply mul_one_div_cancel, linarith }, { rw mul_le_mul_left ε_pos, apply le_nat_ceil }, { rw mul_le_mul_left ε_pos, exact_mod_cast hn } }, -- we try to discharge the side conditions with as little work as possible { assumption_mod_cast }, { field_simp, apply one_le_div_of_le; norm_cast; linarith } end
102040a3483975a6049fd302f74663c044705668
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/ring_theory/witt_vector/defs.lean
c3ba171fd8dfa0ba56ea45eeef9e6a64c9a581e3
[ "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
14,299
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 ring_theory.witt_vector.structure_polynomial /-! # Witt vectors > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define the type of `p`-typical Witt vectors and ring operations on it. The ring axioms are verified in `ring_theory/witt_vector/basic.lean`. For a fixed commutative ring `R` and prime `p`, a Witt vector `x : 𝕎 R` is an infinite sequence `ℕ → R` of elements of `R`. However, the ring operations `+` and `*` are not defined in the obvious component-wise way. Instead, these operations are defined via certain polynomials using the machinery in `structure_polynomial.lean`. The `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values of the summands. This effectively simulates a “carrying” operation. ## Main definitions * `witt_vector p R`: the type of `p`-typical Witt vectors with coefficients in `R`. * `witt_vector.coeff x n`: projects the `n`th value of the Witt vector `x`. ## Notation We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable theory /-- `witt_vector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`, where `p` is a prime number. If `p` is invertible in `R`, this ring is isomorphic to `ℕ → R` (the product of `ℕ` copies of `R`). If `R` is a ring of characteristic `p`, then `witt_vector p R` is a ring of characteristic `0`. The canonical example is `witt_vector p (zmod p)`, which is isomorphic to the `p`-adic integers `ℤ_[p]`. -/ structure witt_vector (p : ℕ) (R : Type*) := mk [] :: (coeff : ℕ → R) variables {p : ℕ} /- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left Hiding the `p` in the notation is very convenient, so we opt for repeating the `local notation` in other files that use Witt vectors. -/ local notation `𝕎` := witt_vector p -- type as `\bbW` namespace witt_vector variables (p) {R : Type*} /-- Construct a Witt vector `mk p x : 𝕎 R` from a sequence `x` of elements of `R`. -/ add_decl_doc witt_vector.mk /-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`. This concept does not have a standard name in the literature. -/ add_decl_doc witt_vector.coeff @[ext] lemma ext {x y : 𝕎 R} (h : ∀ n, x.coeff n = y.coeff n) : x = y := begin cases x, cases y, simp only at h, simp [function.funext_iff, h] end lemma ext_iff {x y : 𝕎 R} : x = y ↔ ∀ n, x.coeff n = y.coeff n := ⟨λ h n, by rw h, ext⟩ lemma coeff_mk (x : ℕ → R) : (mk p x).coeff = x := rfl /- These instances are not needed for the rest of the development, but it is interesting to establish early on that `witt_vector p` is a lawful functor. -/ instance : functor (witt_vector p) := { map := λ α β f v, mk p (f ∘ v.coeff), map_const := λ α β a v, mk p (λ _, a) } instance : is_lawful_functor (witt_vector p) := { map_const_eq := λ α β, rfl, id_map := λ α ⟨v, _⟩, rfl, comp_map := λ α β γ f g v, rfl } variables (p) [hp : fact p.prime] [comm_ring R] include hp open mv_polynomial section ring_operations /-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/ def witt_zero : ℕ → mv_polynomial (fin 0 × ℕ) ℤ := witt_structure_int p 0 /-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/ def witt_one : ℕ → mv_polynomial (fin 0 × ℕ) ℤ := witt_structure_int p 1 /-- The polynomials used for defining the addition of the ring of Witt vectors. -/ def witt_add : ℕ → mv_polynomial (fin 2 × ℕ) ℤ := witt_structure_int p (X 0 + X 1) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def witt_nsmul (n : ℕ) : ℕ → mv_polynomial (fin 1 × ℕ) ℤ := witt_structure_int p (n • X 0) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def witt_zsmul (n : ℤ) : ℕ → mv_polynomial (fin 1 × ℕ) ℤ := witt_structure_int p (n • X 0) /-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/ def witt_sub : ℕ → mv_polynomial (fin 2 × ℕ) ℤ := witt_structure_int p (X 0 - X 1) /-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/ def witt_mul : ℕ → mv_polynomial (fin 2 × ℕ) ℤ := witt_structure_int p (X 0 * X 1) /-- The polynomials used for defining the negation of the ring of Witt vectors. -/ def witt_neg : ℕ → mv_polynomial (fin 1 × ℕ) ℤ := witt_structure_int p (-X 0) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def witt_pow (n : ℕ) : ℕ → mv_polynomial (fin 1 × ℕ) ℤ := witt_structure_int p (X 0 ^ n) variable {p} omit hp /-- An auxiliary definition used in `witt_vector.eval`. Evaluates a polynomial whose variables come from the disjoint union of `k` copies of `ℕ`, with a curried evaluation `x`. This can be defined more generally but we use only a specific instance here. -/ def peval {k : ℕ} (φ : mv_polynomial (fin k × ℕ) ℤ) (x : fin k → ℕ → R) : R := aeval (function.uncurry x) φ /-- Let `φ` be a family of polynomials, indexed by natural numbers, whose variables come from the disjoint union of `k` copies of `ℕ`, and let `xᵢ` be a Witt vector for `0 ≤ i < k`. `eval φ x` evaluates `φ` mapping the variable `X_(i, n)` to the `n`th coefficient of `xᵢ`. Instantiating `φ` with certain polynomials defined in `structure_polynomial.lean` establishes the ring operations on `𝕎 R`. For example, `witt_vector.witt_add` is such a `φ` with `k = 2`; evaluating this at `(x₀, x₁)` gives us the sum of two Witt vectors `x₀ + x₁`. -/ def eval {k : ℕ} (φ : ℕ → mv_polynomial (fin k × ℕ) ℤ) (x : fin k → 𝕎 R) : 𝕎 R := mk p $ λ n, peval (φ n) $ λ i, (x i).coeff variables (R) [fact p.prime] instance : has_zero (𝕎 R) := ⟨eval (witt_zero p) ![]⟩ instance : inhabited (𝕎 R) := ⟨0⟩ instance : has_one (𝕎 R) := ⟨eval (witt_one p) ![]⟩ instance : has_add (𝕎 R) := ⟨λ x y, eval (witt_add p) ![x, y]⟩ instance : has_sub (𝕎 R) := ⟨λ x y, eval (witt_sub p) ![x, y]⟩ instance has_nat_scalar : has_smul ℕ (𝕎 R) := ⟨λ n x, eval (witt_nsmul p n) ![x]⟩ instance has_int_scalar : has_smul ℤ (𝕎 R) := ⟨λ n x, eval (witt_zsmul p n) ![x]⟩ instance : has_mul (𝕎 R) := ⟨λ x y, eval (witt_mul p) ![x, y]⟩ instance : has_neg (𝕎 R) := ⟨λ x, eval (witt_neg p) ![x]⟩ instance has_nat_pow : has_pow (𝕎 R) ℕ := ⟨λ x n, eval (witt_pow p n) ![x]⟩ instance : has_nat_cast (𝕎 R) := ⟨nat.unary_cast⟩ instance : has_int_cast (𝕎 R) := ⟨int.cast_def⟩ end ring_operations section witt_structure_simplifications @[simp] lemma witt_zero_eq_zero (n : ℕ) : witt_zero p n = 0 := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_zero, witt_structure_rat, bind₁, aeval_zero', constant_coeff_X_in_terms_of_W, ring_hom.map_zero, alg_hom.map_zero, map_witt_structure_int], end @[simp] lemma witt_one_zero_eq_one : witt_one p 0 = 1 := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_one, witt_structure_rat, X_in_terms_of_W_zero, alg_hom.map_one, ring_hom.map_one, bind₁_X_right, map_witt_structure_int] end @[simp] lemma witt_one_pos_eq_zero (n : ℕ) (hn : 0 < n) : witt_one p n = 0 := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_one, witt_structure_rat, ring_hom.map_zero, alg_hom.map_one, ring_hom.map_one, map_witt_structure_int], revert hn, apply nat.strong_induction_on n, clear n, intros n IH hn, rw X_in_terms_of_W_eq, simp only [alg_hom.map_mul, alg_hom.map_sub, alg_hom.map_sum, alg_hom.map_pow, bind₁_X_right, bind₁_C_right], rw [sub_mul, one_mul], rw [finset.sum_eq_single 0], { simp only [inv_of_eq_inv, one_mul, inv_pow, tsub_zero, ring_hom.map_one, pow_zero], simp only [one_pow, one_mul, X_in_terms_of_W_zero, sub_self, bind₁_X_right] }, { intros i hin hi0, rw [finset.mem_range] at hin, rw [IH _ hin (nat.pos_of_ne_zero hi0), zero_pow (pow_pos hp.1.pos _), mul_zero], }, { rw finset.mem_range, intro, contradiction } end @[simp] lemma witt_add_zero : witt_add p 0 = X (0,0) + X (1,0) := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_add, witt_structure_rat, alg_hom.map_add, ring_hom.map_add, rename_X, X_in_terms_of_W_zero, map_X, witt_polynomial_zero, bind₁_X_right, map_witt_structure_int], end @[simp] lemma witt_sub_zero : witt_sub p 0 = X (0,0) - X (1,0) := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_sub, witt_structure_rat, alg_hom.map_sub, ring_hom.map_sub, rename_X, X_in_terms_of_W_zero, map_X, witt_polynomial_zero, bind₁_X_right, map_witt_structure_int], end @[simp] lemma witt_mul_zero : witt_mul p 0 = X (0,0) * X (1,0) := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_mul, witt_structure_rat, rename_X, X_in_terms_of_W_zero, map_X, witt_polynomial_zero, ring_hom.map_mul, bind₁_X_right, alg_hom.map_mul, map_witt_structure_int] end @[simp] lemma witt_neg_zero : witt_neg p 0 = - X (0,0) := begin apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective, simp only [witt_neg, witt_structure_rat, rename_X, X_in_terms_of_W_zero, map_X, witt_polynomial_zero, ring_hom.map_neg, alg_hom.map_neg, bind₁_X_right, map_witt_structure_int] end @[simp] lemma constant_coeff_witt_add (n : ℕ) : constant_coeff (witt_add p n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [add_zero, ring_hom.map_add, constant_coeff_X], end @[simp] lemma constant_coeff_witt_sub (n : ℕ) : constant_coeff (witt_sub p n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [sub_zero, ring_hom.map_sub, constant_coeff_X], end @[simp] lemma constant_coeff_witt_mul (n : ℕ) : constant_coeff (witt_mul p n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [mul_zero, ring_hom.map_mul, constant_coeff_X], end @[simp] lemma constant_coeff_witt_neg (n : ℕ) : constant_coeff (witt_neg p n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [neg_zero, ring_hom.map_neg, constant_coeff_X], end @[simp] lemma constant_coeff_witt_nsmul (m : ℕ) (n : ℕ): constant_coeff (witt_nsmul p m n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [smul_zero, map_nsmul, constant_coeff_X], end @[simp] lemma constant_coeff_witt_zsmul (z : ℤ) (n : ℕ): constant_coeff (witt_zsmul p z n) = 0 := begin apply constant_coeff_witt_structure_int p _ _ n, simp only [smul_zero, map_zsmul, constant_coeff_X], end end witt_structure_simplifications section coeff variables (p R) @[simp] lemma zero_coeff (n : ℕ) : (0 : 𝕎 R).coeff n = 0 := show (aeval _ (witt_zero p n) : R) = 0, by simp only [witt_zero_eq_zero, alg_hom.map_zero] @[simp] lemma one_coeff_zero : (1 : 𝕎 R).coeff 0 = 1 := show (aeval _ (witt_one p 0) : R) = 1, by simp only [witt_one_zero_eq_one, alg_hom.map_one] @[simp] lemma one_coeff_eq_of_pos (n : ℕ) (hn : 0 < n) : coeff (1 : 𝕎 R) n = 0 := show (aeval _ (witt_one p n) : R) = 0, by simp only [hn, witt_one_pos_eq_zero, alg_hom.map_zero] variables {p R} omit hp @[simp] lemma v2_coeff {p' R'} (x y : witt_vector p' R') (i : fin 2) : (![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i; simp include hp lemma add_coeff (x y : 𝕎 R) (n : ℕ) : (x + y).coeff n = peval (witt_add p n) ![x.coeff, y.coeff] := by simp [(+), eval] lemma sub_coeff (x y : 𝕎 R) (n : ℕ) : (x - y).coeff n = peval (witt_sub p n) ![x.coeff, y.coeff] := by simp [has_sub.sub, eval] lemma mul_coeff (x y : 𝕎 R) (n : ℕ) : (x * y).coeff n = peval (witt_mul p n) ![x.coeff, y.coeff] := by simp [(*), eval] lemma neg_coeff (x : 𝕎 R) (n : ℕ) : (-x).coeff n = peval (witt_neg p n) ![x.coeff] := by simp [has_neg.neg, eval, matrix.cons_fin_one] lemma nsmul_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (witt_nsmul p m n) ![x.coeff] := by simp [has_smul.smul, eval, matrix.cons_fin_one] lemma zsmul_coeff (m : ℤ) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (witt_zsmul p m n) ![x.coeff] := by simp [has_smul.smul, eval, matrix.cons_fin_one] lemma pow_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (x ^ m).coeff n = peval (witt_pow p m n) ![x.coeff] := by simp [has_pow.pow, eval, matrix.cons_fin_one] lemma add_coeff_zero (x y : 𝕎 R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by simp [add_coeff, peval] lemma mul_coeff_zero (x y : 𝕎 R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by simp [mul_coeff, peval] end coeff lemma witt_add_vars (n : ℕ) : (witt_add p n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_sub_vars (n : ℕ) : (witt_sub p n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_mul_vars (n : ℕ) : (witt_mul p n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_neg_vars (n : ℕ) : (witt_neg p n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_nsmul_vars (m : ℕ) (n : ℕ) : (witt_nsmul p m n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_zsmul_vars (m : ℤ) (n : ℕ) : (witt_zsmul p m n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ lemma witt_pow_vars (m : ℕ) (n : ℕ) : (witt_pow p m n).vars ⊆ finset.univ ×ˢ finset.range (n + 1) := witt_structure_int_vars _ _ _ end witt_vector
567d59d619a5822081eb4de3cec0c9fbaa116708
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/category_theory/opposites.lean
dbb2763524303fce037a9e87082ec2d3ee6f23c3
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
15,666
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 -/ import category_theory.equivalence /-! # Opposite categories We provide a category instance on `Cᵒᵖ`. The morphisms `X ⟶ Y` are defined to be the morphisms `unop Y ⟶ unop X` in `C`. Here `Cᵒᵖ` is an irreducible typeclass synonym for `C` (it is the same one used in the algebra library). We also provide various mechanisms for constructing opposite morphisms, functors, and natural transformations. Unfortunately, because we do not have a definitional equality `op (op X) = X`, there are quite a few variations that are needed in practice. -/ universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. open opposite variables {C : Type u₁} section quiver variables [quiver.{v₁} C] lemma quiver.hom.op_inj {X Y : C} : function.injective (quiver.hom.op : (X ⟶ Y) → (op Y ⟶ op X)) := λ _ _ H, congr_arg quiver.hom.unop H lemma quiver.hom.unop_inj {X Y : Cᵒᵖ} : function.injective (quiver.hom.unop : (X ⟶ Y) → (unop Y ⟶ unop X)) := λ _ _ H, congr_arg quiver.hom.op H @[simp] lemma quiver.hom.unop_op {X Y : C} (f : X ⟶ Y) : f.op.unop = f := rfl @[simp] lemma quiver.hom.op_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : f.unop.op = f := rfl end quiver namespace category_theory variables [category.{v₁} C] /-- The opposite category. See https://stacks.math.columbia.edu/tag/001M. -/ instance category.opposite : category.{v₁} Cᵒᵖ := { comp := λ _ _ _ f g, (g.unop ≫ f.unop).op, id := λ X, (𝟙 (unop X)).op } @[simp] lemma op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).op = g.op ≫ f.op := rfl @[simp] lemma op_id {X : C} : (𝟙 X).op = 𝟙 (op X) := rfl @[simp] lemma unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unop = g.unop ≫ f.unop := rfl @[simp] lemma unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) := rfl @[simp] lemma unop_id_op {X : C} : (𝟙 (op X)).unop = 𝟙 X := rfl @[simp] lemma op_id_unop {X : Cᵒᵖ} : (𝟙 (unop X)).op = 𝟙 X := rfl section variables (C) /-- The functor from the double-opposite of a category to the underlying category. -/ @[simps] def op_op : (Cᵒᵖ)ᵒᵖ ⥤ C := { obj := λ X, unop (unop X), map := λ X Y f, f.unop.unop } /-- The functor from a category to its double-opposite. -/ @[simps] def unop_unop : C ⥤ Cᵒᵖᵒᵖ := { obj := λ X, op (op X), map := λ X Y f, f.op.op } /-- The double opposite category is equivalent to the original. -/ @[simps] def op_op_equivalence : Cᵒᵖᵒᵖ ≌ C := { functor := op_op C, inverse := unop_unop C, unit_iso := iso.refl (𝟭 Cᵒᵖᵒᵖ), counit_iso := iso.refl (unop_unop C ⋙ op_op C) } end /-- If `f` is an isomorphism, so is `f.op` -/ instance is_iso_op {X Y : C} (f : X ⟶ Y) [is_iso f] : is_iso f.op := ⟨⟨(inv f).op, ⟨quiver.hom.unop_inj (by tidy), quiver.hom.unop_inj (by tidy)⟩⟩⟩ /-- If `f.op` is an isomorphism `f` must be too. (This cannot be an instance as it would immediately loop!) -/ lemma is_iso_of_op {X Y : C} (f : X ⟶ Y) [is_iso f.op] : is_iso f := ⟨⟨(inv (f.op)).unop, ⟨quiver.hom.op_inj (by simp), quiver.hom.op_inj (by simp)⟩⟩⟩ @[simp] lemma op_inv {X Y : C} (f : X ⟶ Y) [f_iso : is_iso f] : (inv f).op = inv f.op := by { ext, rw [← op_comp, is_iso.inv_hom_id, op_id] } namespace functor section variables {D : Type u₂} [category.{v₂} D] variables {C D} /-- The opposite of a functor, i.e. considering a functor `F : C ⥤ D` as a functor `Cᵒᵖ ⥤ Dᵒᵖ`. In informal mathematics no distinction is made between these. -/ @[simps] protected def op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ := { obj := λ X, op (F.obj (unop X)), map := λ X Y f, (F.map f.unop).op } /-- Given a functor `F : Cᵒᵖ ⥤ Dᵒᵖ` we can take the "unopposite" functor `F : C ⥤ D`. In informal mathematics no distinction is made between these. -/ @[simps] protected def unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D := { obj := λ X, unop (F.obj (op X)), map := λ X Y f, (F.map f.op).unop } /-- The isomorphism between `F.op.unop` and `F`. -/ @[simps] def op_unop_iso (F : C ⥤ D) : F.op.unop ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) /-- The isomorphism between `F.unop.op` and `F`. -/ @[simps] def unop_op_iso (F : Cᵒᵖ ⥤ Dᵒᵖ) : F.unop.op ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) variables (C D) /-- Taking the opposite of a functor is functorial. -/ @[simps] def op_hom : (C ⥤ D)ᵒᵖ ⥤ (Cᵒᵖ ⥤ Dᵒᵖ) := { obj := λ F, (unop F).op, map := λ F G α, { app := λ X, (α.unop.app (unop X)).op, naturality' := λ X Y f, quiver.hom.unop_inj (α.unop.naturality f.unop).symm } } /-- Take the "unopposite" of a functor is functorial. -/ @[simps] def op_inv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ := { obj := λ F, op F.unop, map := λ F G α, quiver.hom.op { app := λ X, (α.app (op X)).unop, naturality' := λ X Y f, quiver.hom.op_inj $ (α.naturality f.op).symm } } variables {C D} /-- Another variant of the opposite of functor, turning a functor `C ⥤ Dᵒᵖ` into a functor `Cᵒᵖ ⥤ D`. In informal mathematics no distinction is made. -/ @[simps] protected def left_op (F : C ⥤ Dᵒᵖ) : Cᵒᵖ ⥤ D := { obj := λ X, unop (F.obj (unop X)), map := λ X Y f, (F.map f.unop).unop } /-- Another variant of the opposite of functor, turning a functor `Cᵒᵖ ⥤ D` into a functor `C ⥤ Dᵒᵖ`. In informal mathematics no distinction is made. -/ @[simps] protected def right_op (F : Cᵒᵖ ⥤ D) : C ⥤ Dᵒᵖ := { obj := λ X, op (F.obj (op X)), map := λ X Y f, (F.map f.op).op } instance {F : C ⥤ D} [full F] : full F.op := { preimage := λ X Y f, (F.preimage f.unop).op } instance {F : C ⥤ D} [faithful F] : faithful F.op := { map_injective' := λ X Y f g h, quiver.hom.unop_inj $ by simpa using map_injective F (quiver.hom.op_inj h) } /-- If F is faithful then the right_op of F is also faithful. -/ instance right_op_faithful {F : Cᵒᵖ ⥤ D} [faithful F] : faithful F.right_op := { map_injective' := λ X Y f g h, quiver.hom.op_inj (map_injective F (quiver.hom.op_inj h)) } /-- If F is faithful then the left_op of F is also faithful. -/ instance left_op_faithful {F : C ⥤ Dᵒᵖ} [faithful F] : faithful F.left_op := { map_injective' := λ X Y f g h, quiver.hom.unop_inj (map_injective F (quiver.hom.unop_inj h)) } /-- The isomorphism between `F.left_op.right_op` and `F`. -/ @[simps] def left_op_right_op_iso (F : C ⥤ Dᵒᵖ) : F.left_op.right_op ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) /-- The isomorphism between `F.right_op.left_op` and `F`. -/ @[simps] def right_op_left_op_iso (F : Cᵒᵖ ⥤ D) : F.right_op.left_op ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) end end functor namespace nat_trans variables {D : Type u₂} [category.{v₂} D] section variables {F G : C ⥤ D} /-- The opposite of a natural transformation. -/ @[simps] protected def op (α : F ⟶ G) : G.op ⟶ F.op := { app := λ X, (α.app (unop X)).op, naturality' := begin tidy, simp_rw [← op_comp, α.naturality] end } @[simp] lemma op_id (F : C ⥤ D) : nat_trans.op (𝟙 F) = 𝟙 (F.op) := rfl /-- The "unopposite" of a natural transformation. -/ @[simps] protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) : G.unop ⟶ F.unop := { app := λ X, (α.app (op X)).unop, naturality' := begin tidy, simp_rw [← unop_comp, α.naturality] end } @[simp] lemma unop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : nat_trans.unop (𝟙 F) = 𝟙 (F.unop) := rfl /-- Given a natural transformation `α : F.op ⟶ G.op`, we can take the "unopposite" of each component obtaining a natural transformation `G ⟶ F`. -/ @[simps] protected def remove_op (α : F.op ⟶ G.op) : G ⟶ F := { app := λ X, (α.app (op X)).unop, naturality' := begin intros X Y f, have := congr_arg quiver.hom.unop (α.naturality f.op), dsimp at this, rw this, end } @[simp] lemma remove_op_id (F : C ⥤ D) : nat_trans.remove_op (𝟙 F.op) = 𝟙 F := rfl end section variables {F G H : C ⥤ Dᵒᵖ} /-- Given a natural transformation `α : F ⟶ G`, for `F G : C ⥤ Dᵒᵖ`, taking `unop` of each component gives a natural transformation `G.left_op ⟶ F.left_op`. -/ @[simps] protected def left_op (α : F ⟶ G) : G.left_op ⟶ F.left_op := { app := λ X, (α.app (unop X)).unop, naturality' := begin intros X Y f, dsimp, simp_rw [← unop_comp, α.naturality] end } @[simp] lemma left_op_id : (𝟙 F : F ⟶ F).left_op = 𝟙 F.left_op := rfl @[simp] lemma left_op_comp (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).left_op = β.left_op ≫ α.left_op := rfl /-- Given a natural transformation `α : F.left_op ⟶ G.left_op`, for `F G : C ⥤ Dᵒᵖ`, taking `op` of each component gives a natural transformation `G ⟶ F`. -/ @[simps] protected def remove_left_op (α : F.left_op ⟶ G.left_op) : G ⟶ F := { app := λ X, (α.app (op X)).op, naturality' := begin intros X Y f, have := congr_arg quiver.hom.op (α.naturality f.op), dsimp at this, erw this end } end section variables {F G H : Cᵒᵖ ⥤ D} /-- Given a natural transformation `α : F ⟶ G`, for `F G : Cᵒᵖ ⥤ D`, taking `op` of each component gives a natural transformation `G.right_op ⟶ F.right_op`. -/ @[simps] protected def right_op (α : F ⟶ G) : G.right_op ⟶ F.right_op := { app := λ X, (α.app _).op, naturality' := begin intros X Y f, dsimp, simp_rw [← op_comp, α.naturality] end } @[simp] lemma right_op_id : (𝟙 F : F ⟶ F).right_op = 𝟙 F.right_op := rfl @[simp] lemma right_op_comp (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).right_op = β.right_op ≫ α.right_op := rfl /-- Given a natural transformation `α : F.right_op ⟶ G.right_op`, for `F G : Cᵒᵖ ⥤ D`, taking `unop` of each component gives a natural transformation `G ⟶ F`. -/ @[simps] protected def remove_right_op (α : F.right_op ⟶ G.right_op) : G ⟶ F := { app := λ X, (α.app X.unop).unop, naturality' := begin intros X Y f, have := congr_arg quiver.hom.unop (α.naturality f.unop), dsimp at this, erw this, end } end end nat_trans namespace iso variables {X Y : C} /-- The opposite isomorphism. -/ @[simps] protected def op (α : X ≅ Y) : op Y ≅ op X := { hom := α.hom.op, inv := α.inv.op, hom_inv_id' := quiver.hom.unop_inj α.inv_hom_id, inv_hom_id' := quiver.hom.unop_inj α.hom_inv_id } /-- The isomorphism obtained from an isomorphism in the opposite category. -/ @[simps] def unop {X Y : Cᵒᵖ} (f : X ≅ Y) : Y.unop ≅ X.unop := { hom := f.hom.unop, inv := f.inv.unop, hom_inv_id' := by simp only [← unop_comp, f.inv_hom_id, unop_id], inv_hom_id' := by simp only [← unop_comp, f.hom_inv_id, unop_id] } @[simp] lemma unop_op {X Y : Cᵒᵖ} (f : X ≅ Y) : f.unop.op = f := by ext; refl @[simp] lemma op_unop {X Y : C} (f : X ≅ Y) : f.op.unop = f := by ext; refl end iso namespace nat_iso variables {D : Type u₂} [category.{v₂} D] variables {F G : C ⥤ D} /-- The natural isomorphism between opposite functors `G.op ≅ F.op` induced by a natural isomorphism between the original functors `F ≅ G`. -/ @[simps] protected def op (α : F ≅ G) : G.op ≅ F.op := { hom := nat_trans.op α.hom, inv := nat_trans.op α.inv, hom_inv_id' := begin ext, dsimp, rw ←op_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←op_comp, rw α.hom_inv_id_app, refl, end } /-- The natural isomorphism between functors `G ≅ F` induced by a natural isomorphism between the opposite functors `F.op ≅ G.op`. -/ @[simps] protected def remove_op (α : F.op ≅ G.op) : G ≅ F := { hom := nat_trans.remove_op α.hom, inv := nat_trans.remove_op α.inv, hom_inv_id' := begin ext, dsimp, rw ←unop_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←unop_comp, rw α.hom_inv_id_app, refl, end } /-- The natural isomorphism between functors `G.unop ≅ F.unop` induced by a natural isomorphism between the original functors `F ≅ G`. -/ @[simps] protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ≅ G) : G.unop ≅ F.unop := { hom := nat_trans.unop α.hom, inv := nat_trans.unop α.inv, hom_inv_id' := begin ext, dsimp, rw ←unop_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←unop_comp, rw α.hom_inv_id_app, refl, end } end nat_iso namespace equivalence variables {D : Type u₂} [category.{v₂} D] /-- An equivalence between categories gives an equivalence between the opposite categories. -/ @[simps] def op (e : C ≌ D) : Cᵒᵖ ≌ Dᵒᵖ := { functor := e.functor.op, inverse := e.inverse.op, unit_iso := (nat_iso.op e.unit_iso).symm, counit_iso := (nat_iso.op e.counit_iso).symm, functor_unit_iso_comp' := λ X, by { apply quiver.hom.unop_inj, dsimp, simp, }, } /-- An equivalence between opposite categories gives an equivalence between the original categories. -/ @[simps] def unop (e : Cᵒᵖ ≌ Dᵒᵖ) : C ≌ D := { functor := e.functor.unop, inverse := e.inverse.unop, unit_iso := (nat_iso.unop e.unit_iso).symm, counit_iso := (nat_iso.unop e.counit_iso).symm, functor_unit_iso_comp' := λ X, by { apply quiver.hom.op_inj, dsimp, simp, }, } end equivalence /-- The equivalence between arrows of the form `A ⟶ B` and `B.unop ⟶ A.unop`. Useful for building adjunctions. Note that this (definitionally) gives variants ``` def op_equiv' (A : C) (B : Cᵒᵖ) : (opposite.op A ⟶ B) ≃ (B.unop ⟶ A) := op_equiv _ _ def op_equiv'' (A : Cᵒᵖ) (B : C) : (A ⟶ opposite.op B) ≃ (B ⟶ A.unop) := op_equiv _ _ def op_equiv''' (A B : C) : (opposite.op A ⟶ opposite.op B) ≃ (B ⟶ A) := op_equiv _ _ ``` -/ @[simps] def op_equiv (A B : Cᵒᵖ) : (A ⟶ B) ≃ (B.unop ⟶ A.unop) := { to_fun := λ f, f.unop, inv_fun := λ g, g.op, left_inv := λ _, rfl, right_inv := λ _, rfl } instance subsingleton_of_unop (A B : Cᵒᵖ) [subsingleton (unop B ⟶ unop A)] : subsingleton (A ⟶ B) := (op_equiv A B).subsingleton instance decidable_eq_of_unop (A B : Cᵒᵖ) [decidable_eq (unop B ⟶ unop A)] : decidable_eq (A ⟶ B) := (op_equiv A B).decidable_eq namespace functor variables (C) variables (D : Type u₂) [category.{v₂} D] /-- The equivalence of functor categories induced by `op` and `unop`. -/ @[simps] def op_unop_equiv : (C ⥤ D)ᵒᵖ ≌ Cᵒᵖ ⥤ Dᵒᵖ := { functor := op_hom _ _, inverse := op_inv _ _, unit_iso := nat_iso.of_components (λ F, F.unop.op_unop_iso.op) begin intros F G f, dsimp [op_unop_iso], rw [(show f = f.unop.op, by simp), ← op_comp, ← op_comp], congr' 1, tidy, end, counit_iso := nat_iso.of_components (λ F, F.unop_op_iso) (by tidy) }. /-- The equivalence of functor categories induced by `left_op` and `right_op`. -/ @[simps] def left_op_right_op_equiv : (Cᵒᵖ ⥤ D)ᵒᵖ ≌ (C ⥤ Dᵒᵖ) := { functor := { obj := λ F, F.unop.right_op, map := λ F G η, η.unop.right_op }, inverse := { obj := λ F, op F.left_op, map := λ F G η, η.left_op.op }, unit_iso := nat_iso.of_components (λ F, F.unop.right_op_left_op_iso.op) begin intros F G η, dsimp, rw [(show η = η.unop.op, by simp), ← op_comp, ← op_comp], congr' 1, tidy, end, counit_iso := nat_iso.of_components (λ F, F.left_op_right_op_iso) (by tidy) } end functor end category_theory
5191faf9b692b864cef86cddb19be17e0e0bc952
0b3933727d99a2f351f5dbe6e24716bb786a6649
/src/metastuff.lean
c84e36a0a5cdbc4046687b32ffe76d8a41d7974a
[]
no_license
Vtec234/lean-sesh
1e770858215279f65aba92b4782b483ab4f09353
d11d7bb0599406e27d3a4d26242aec13d639ecf7
refs/heads/master
1,587,497,515,696
1,558,362,223,000
1,558,362,223,000
169,809,439
2
0
null
null
null
null
UTF-8
Lean
false
false
635
lean
/- Meta stuff: attributes, tactics, etc. -/ /- @[user_attribute] meta def sop_attr: user_attribute := { name := `sop_form, descr := "A simplification lemma that brings expressions to a sum-of-products form." } -/ run_cmd mk_simp_attr `sop_form [`simp] /- @[user_attribute] meta def unfold_attr: user_attribute := { name := `unfold_, descr := "Essentially what unfold should do but doesn't so I use simp instead." } -/ run_cmd mk_simp_attr `unfold_ [`simp] meta def solve_context: tactic unit := `[simp * with unfold_ sop_form, try { simp * with unfold_ sop_form }, done <|> tactic.fail "Cannot prove contexts equal." ]
2cb7ccdc9949b24c98488e8edb0dd04ecb72cb06
b3fced0f3ff82d577384fe81653e47df68bb2fa1
/src/data/list/basic.lean
b1bae3415980dcfa6248f56df7d17d928848ddd9
[ "Apache-2.0" ]
permissive
ratmice/mathlib
93b251ef5df08b6fd55074650ff47fdcc41a4c75
3a948a6a4cd5968d60e15ed914b1ad2f4423af8d
refs/heads/master
1,599,240,104,318
1,572,981,183,000
1,572,981,183,000
219,830,178
0
0
Apache-2.0
1,572,980,897,000
1,572,980,896,000
null
UTF-8
Lean
false
false
218,611
lean
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro Basic properties of lists. -/ import tactic.interactive tactic.mk_iff_of_inductive_prop logic.basic logic.function logic.relator algebra.group order.basic data.list.defs data.nat.basic data.option.basic data.bool data.prod data.fin open function nat namespace list universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} instance : is_left_id (list α) has_append.append [] := ⟨ nil_append ⟩ instance : is_right_id (list α) has_append.append [] := ⟨ append_nil ⟩ instance : is_associative (list α) has_append.append := ⟨ append_assoc ⟩ @[simp] theorem cons_ne_nil (a : α) (l : list α) : a::l ≠ []. theorem head_eq_of_cons_eq {h₁ h₂ : α} {t₁ t₂ : list α} : (h₁::t₁) = (h₂::t₂) → h₁ = h₂ := assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pheq) theorem tail_eq_of_cons_eq {h₁ h₂ : α} {t₁ t₂ : list α} : (h₁::t₁) = (h₂::t₂) → t₁ = t₂ := assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pteq) theorem cons_inj {a : α} : injective (cons a) := assume l₁ l₂, assume Pe, tail_eq_of_cons_eq Pe @[simp] theorem cons_inj' (a : α) {l l' : list α} : a::l = a::l' ↔ l = l' := ⟨λ e, cons_inj e, congr_arg _⟩ /- mem -/ theorem mem_singleton_self (a : α) : a ∈ [a] := mem_cons_self _ _ theorem eq_of_mem_singleton {a b : α} : a ∈ [b] → a = b := assume : a ∈ [b], or.elim (eq_or_mem_of_mem_cons this) (assume : a = b, this) (assume : a ∈ [], absurd this (not_mem_nil a)) @[simp] theorem mem_singleton {a b : α} : a ∈ [b] ↔ a = b := ⟨eq_of_mem_singleton, or.inl⟩ theorem mem_of_mem_cons_of_mem {a b : α} {l : list α} : a ∈ b::l → b ∈ l → a ∈ l := assume ainbl binl, or.elim (eq_or_mem_of_mem_cons ainbl) (assume : a = b, begin subst a, exact binl end) (assume : a ∈ l, this) theorem eq_or_ne_mem_of_mem {a b : α} {l : list α} (h : a ∈ b :: l) : a = b ∨ (a ≠ b ∧ a ∈ l) := classical.by_cases or.inl $ assume : a ≠ b, h.elim or.inl $ assume h, or.inr ⟨this, h⟩ theorem not_mem_append {a : α} {s t : list α} (h₁ : a ∉ s) (h₂ : a ∉ t) : a ∉ s ++ t := mt mem_append.1 $ not_or_distrib.2 ⟨h₁, h₂⟩ theorem ne_nil_of_mem {a : α} {l : list α} (h : a ∈ l) : l ≠ [] := by intro e; rw e at h; cases h theorem mem_split {a : α} {l : list α} (h : a ∈ l) : ∃ s t : list α, l = s ++ a :: t := begin induction l with b l ih, {cases h}, rcases h with rfl | h, { exact ⟨[], l, rfl⟩ }, { rcases ih h with ⟨s, t, rfl⟩, exact ⟨b::s, t, rfl⟩ } end theorem mem_of_ne_of_mem {a y : α} {l : list α} (h₁ : a ≠ y) (h₂ : a ∈ y :: l) : a ∈ l := or.elim (eq_or_mem_of_mem_cons h₂) (λe, absurd e h₁) (λr, r) theorem ne_of_not_mem_cons {a b : α} {l : list α} : a ∉ b::l → a ≠ b := assume nin aeqb, absurd (or.inl aeqb) nin theorem not_mem_of_not_mem_cons {a b : α} {l : list α} : a ∉ b::l → a ∉ l := assume nin nainl, absurd (or.inr nainl) nin theorem not_mem_cons_of_ne_of_not_mem {a y : α} {l : list α} : a ≠ y → a ∉ l → a ∉ y::l := assume p1 p2, not.intro (assume Pain, absurd (eq_or_mem_of_mem_cons Pain) (not_or p1 p2)) theorem ne_and_not_mem_of_not_mem_cons {a y : α} {l : list α} : a ∉ y::l → a ≠ y ∧ a ∉ l := assume p, and.intro (ne_of_not_mem_cons p) (not_mem_of_not_mem_cons p) theorem mem_map_of_mem (f : α → β) {a : α} {l : list α} (h : a ∈ l) : f a ∈ map f l := begin induction l with b l' ih, {cases h}, {rcases h with rfl | h, {exact or.inl rfl}, {exact or.inr (ih h)}} end theorem exists_of_mem_map {f : α → β} {b : β} {l : list α} (h : b ∈ map f l) : ∃ a, a ∈ l ∧ f a = b := begin induction l with c l' ih, {cases h}, {cases (eq_or_mem_of_mem_cons h) with h h, {exact ⟨c, mem_cons_self _ _, h.symm⟩}, {rcases ih h with ⟨a, ha₁, ha₂⟩, exact ⟨a, mem_cons_of_mem _ ha₁, ha₂⟩ }} end @[simp] theorem mem_map {f : α → β} {b : β} {l : list α} : b ∈ map f l ↔ ∃ a, a ∈ l ∧ f a = b := ⟨exists_of_mem_map, λ ⟨a, la, h⟩, by rw [← h]; exact mem_map_of_mem f la⟩ @[simp] theorem mem_map_of_inj {f : α → β} (H : injective f) {a : α} {l : list α} : f a ∈ map f l ↔ a ∈ l := ⟨λ m, let ⟨a', m', e⟩ := exists_of_mem_map m in H e ▸ m', mem_map_of_mem _⟩ @[simp] lemma map_eq_nil {f : α → β} {l : list α} : list.map f l = [] ↔ l = [] := ⟨by cases l; simp only [forall_prop_of_true, map, forall_prop_of_false, not_false_iff], λ h, h.symm ▸ rfl⟩ @[simp] theorem mem_join {a : α} : ∀ {L : list (list α)}, a ∈ join L ↔ ∃ l, l ∈ L ∧ a ∈ l | [] := ⟨false.elim, λ⟨_, h, _⟩, false.elim h⟩ | (c :: L) := by simp only [join, mem_append, @mem_join L, mem_cons_iff, or_and_distrib_right, exists_or_distrib, exists_eq_left] theorem exists_of_mem_join {a : α} {L : list (list α)} : a ∈ join L → ∃ l, l ∈ L ∧ a ∈ l := mem_join.1 theorem mem_join_of_mem {a : α} {L : list (list α)} {l} (lL : l ∈ L) (al : a ∈ l) : a ∈ join L := mem_join.2 ⟨l, lL, al⟩ @[simp] theorem mem_bind {b : β} {l : list α} {f : α → list β} : b ∈ list.bind l f ↔ ∃ a ∈ l, b ∈ f a := iff.trans mem_join ⟨λ ⟨l', h1, h2⟩, let ⟨a, al, fa⟩ := exists_of_mem_map h1 in ⟨a, al, fa.symm ▸ h2⟩, λ ⟨a, al, bfa⟩, ⟨f a, mem_map_of_mem _ al, bfa⟩⟩ theorem exists_of_mem_bind {b : β} {l : list α} {f : α → list β} : b ∈ list.bind l f → ∃ a ∈ l, b ∈ f a := mem_bind.1 theorem mem_bind_of_mem {b : β} {l : list α} {f : α → list β} {a} (al : a ∈ l) (h : b ∈ f a) : b ∈ list.bind l f := mem_bind.2 ⟨a, al, h⟩ lemma bind_map {g : α → list β} {f : β → γ} : ∀(l : list α), list.map f (l.bind g) = l.bind (λa, (g a).map f) | [] := rfl | (a::l) := by simp only [cons_bind, map_append, bind_map l] /- length -/ theorem length_eq_zero {l : list α} : length l = 0 ↔ l = [] := ⟨eq_nil_of_length_eq_zero, λ h, h.symm ▸ rfl⟩ theorem length_pos_of_mem {a : α} : ∀ {l : list α}, a ∈ l → 0 < length l | (b::l) _ := zero_lt_succ _ theorem exists_mem_of_length_pos : ∀ {l : list α}, 0 < length l → ∃ a, a ∈ l | (b::l) _ := ⟨b, mem_cons_self _ _⟩ theorem length_pos_iff_exists_mem {l : list α} : 0 < length l ↔ ∃ a, a ∈ l := ⟨exists_mem_of_length_pos, λ ⟨a, h⟩, length_pos_of_mem h⟩ theorem ne_nil_of_length_pos {l : list α} : 0 < length l → l ≠ [] := λ h1 h2, lt_irrefl 0 ((length_eq_zero.2 h2).subst h1) theorem length_pos_of_ne_nil {l : list α} : l ≠ [] → 0 < length l := λ h, pos_iff_ne_zero.2 $ λ h0, h $ length_eq_zero.1 h0 theorem length_pos_iff_ne_nil {l : list α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ theorem length_eq_one {l : list α} : length l = 1 ↔ ∃ a, l = [a] := ⟨match l with [a], _ := ⟨a, rfl⟩ end, λ ⟨a, e⟩, e.symm ▸ rfl⟩ lemma exists_of_length_succ {n} : ∀ l : list α, l.length = n + 1 → ∃ h t, l = h :: t | [] H := absurd H.symm $ succ_ne_zero n | (h :: t) H := ⟨h, t, rfl⟩ lemma injective_length_iff : injective (list.length : list α → ℕ) ↔ subsingleton α := begin split, { intro h, refine ⟨λ x y, _⟩, suffices : [x] = [y], { simpa using this }, apply h, refl }, { intros hα l1 l2 hl, induction l1 generalizing l2; cases l2, { refl }, { cases hl }, { cases hl }, congr, exactI subsingleton.elim _ _, apply l1_ih, simpa using hl } end lemma injective_length [subsingleton α] : injective (length : list α → ℕ) := injective_length_iff.mpr $ by apply_instance /- set-theoretic notation of lists -/ lemma empty_eq : (∅ : list α) = [] := by refl lemma singleton_eq [decidable_eq α] (x : α) : ({x} : list α) = [x] := by refl lemma insert_neg [decidable_eq α] {x : α} {l : list α} (h : x ∉ l) : has_insert.insert x l = x :: l := if_neg h lemma insert_pos [decidable_eq α] {x : α} {l : list α} (h : x ∈ l) : has_insert.insert x l = l := if_pos h lemma doubleton_eq [decidable_eq α] {x y : α} (h : x ≠ y) : ({x, y} : list α) = [y, x] := by { rw [insert_neg, singleton_eq], show y ∉ [x], rw [mem_singleton], exact h.symm } /- bounded quantifiers over lists -/ theorem forall_mem_nil (p : α → Prop) : ∀ x ∈ @nil α, p x. @[simp] theorem forall_mem_cons' {p : α → Prop} {a : α} {l : list α} : (∀ (x : α), x = a ∨ x ∈ l → p x) ↔ p a ∧ ∀ x ∈ l, p x := by simp only [or_imp_distrib, forall_and_distrib, forall_eq] theorem forall_mem_cons {p : α → Prop} {a : α} {l : list α} : (∀ x ∈ a :: l, p x) ↔ p a ∧ ∀ x ∈ l, p x := by simp only [mem_cons_iff, forall_mem_cons'] theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : list α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 theorem forall_mem_singleton {p : α → Prop} {a : α} : (∀ x ∈ [a], p x) ↔ p a := by simp only [mem_singleton, forall_eq] theorem forall_mem_append {p : α → Prop} {l₁ l₂ : list α} : (∀ x ∈ l₁ ++ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ (∀ x ∈ l₂, p x) := by simp only [mem_append, or_imp_distrib, forall_and_distrib] theorem not_exists_mem_nil (p : α → Prop) : ¬ ∃ x ∈ @nil α, p x. theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : list α) (h : p a) : ∃ x ∈ a :: l, p x := bex.intro a (mem_cons_self _ _) h theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : list α} (h : ∃ x ∈ l, p x) : ∃ x ∈ a :: l, p x := bex.elim h (λ x xl px, bex.intro x (mem_cons_of_mem _ xl) px) theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : list α} (h : ∃ x ∈ a :: l, p x) : p a ∨ ∃ x ∈ l, p x := bex.elim h (λ x xal px, or.elim (eq_or_mem_of_mem_cons xal) (assume : x = a, begin rw ←this, left, exact px end) (assume : x ∈ l, or.inr (bex.intro x this px))) @[simp] theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : list α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := iff.intro or_exists_of_exists_mem_cons (assume h, or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists) /- list subset -/ theorem subset_def {l₁ l₂ : list α} : l₁ ⊆ l₂ ↔ ∀ ⦃a : α⦄, a ∈ l₁ → a ∈ l₂ := iff.rfl theorem subset_append_of_subset_left (l l₁ l₂ : list α) : l ⊆ l₁ → l ⊆ l₁++l₂ := λ s, subset.trans s $ subset_append_left _ _ theorem subset_append_of_subset_right (l l₁ l₂ : list α) : l ⊆ l₂ → l ⊆ l₁++l₂ := λ s, subset.trans s $ subset_append_right _ _ @[simp] theorem cons_subset {a : α} {l m : list α} : a::l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons_iff, or_imp_distrib, forall_and_distrib, forall_eq] theorem cons_subset_of_subset_of_mem {a : α} {l m : list α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ theorem append_subset_of_subset_of_subset {l₁ l₂ l : list α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := λ a h, (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) @[simp] theorem append_subset_iff {l₁ l₂ l : list α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := begin split, { intro h, simp only [subset_def] at *, split; intros; simp* }, { rintro ⟨h1, h2⟩, apply append_subset_of_subset_of_subset h1 h2 } end theorem eq_nil_of_subset_nil : ∀ {l : list α}, l ⊆ [] → l = [] | [] s := rfl | (a::l) s := false.elim $ s $ mem_cons_self a l theorem eq_nil_iff_forall_not_mem {l : list α} : l = [] ↔ ∀ a, a ∉ l := show l = [] ↔ l ⊆ [], from ⟨λ e, e ▸ subset.refl _, eq_nil_of_subset_nil⟩ theorem map_subset {l₁ l₂ : list α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := λ x, by simp only [mem_map, not_and, exists_imp_distrib, and_imp]; exact λ a h e, ⟨a, H h, e⟩ theorem map_subset_iff {l₁ l₂ : list α} (f : α → β) (h : injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := begin refine ⟨_, map_subset f⟩, intros h2 x hx, rcases mem_map.1 (h2 (mem_map_of_mem f hx)) with ⟨x', hx', hxx'⟩, cases h hxx', exact hx' end /- append -/ lemma append_eq_has_append {L₁ L₂ : list α} : list.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_ne_nil_of_ne_nil_left (s t : list α) : s ≠ [] → s ++ t ≠ [] := by induction s; intros; contradiction theorem append_ne_nil_of_ne_nil_right (s t : list α) : t ≠ [] → s ++ t ≠ [] := by induction s; intros; contradiction theorem append_foldl (f : α → β → α) (a : α) (s t : list β) : foldl f a (s ++ t) = foldl f (foldl f a s) t := by {induction s with b s H generalizing a, refl, simp only [foldl, cons_append], rw H _} theorem append_foldr (f : α → β → β) (a : β) (s t : list α) : foldr f a (s ++ t) = foldr f (foldr f a t) s := by {induction s with b s H generalizing a, refl, simp only [foldr, cons_append], rw H _} @[simp] lemma append_eq_nil {p q : list α} : (p ++ q) = [] ↔ p = [] ∧ q = [] := by cases p; simp only [nil_append, cons_append, eq_self_iff_true, true_and, false_and] @[simp] lemma nil_eq_append_iff {a b : list α} : [] = a ++ b ↔ a = [] ∧ b = [] := by rw [eq_comm, append_eq_nil] lemma append_eq_cons_iff {a b c : list α} {x : α} : a ++ b = x :: c ↔ (a = [] ∧ b = x :: c) ∨ (∃a', a = x :: a' ∧ c = a' ++ b) := by cases a; simp only [and_assoc, @eq_comm _ c, nil_append, cons_append, eq_self_iff_true, true_and, false_and, exists_false, false_or, or_false, exists_and_distrib_left, exists_eq_left'] lemma cons_eq_append_iff {a b c : list α} {x : α} : (x :: c : list α) = a ++ b ↔ (a = [] ∧ b = x :: c) ∨ (∃a', a = x :: a' ∧ c = a' ++ b) := by rw [eq_comm, append_eq_cons_iff] lemma append_eq_append_iff {a b c d : list α} : a ++ b = c ++ d ↔ (∃a', c = a ++ a' ∧ b = a' ++ d) ∨ (∃c', a = c ++ c' ∧ d = c' ++ b) := begin induction a generalizing c, case nil { rw nil_append, split, { rintro rfl, left, exact ⟨_, rfl, rfl⟩ }, { rintro (⟨a', rfl, rfl⟩ | ⟨a', H, rfl⟩), {refl}, {rw [← append_assoc, ← H], refl} } }, case cons : a as ih { cases c, { simp only [cons_append, nil_append, false_and, exists_false, false_or, exists_eq_left'], exact eq_comm }, { simp only [cons_append, @eq_comm _ a, ih, and_assoc, and_or_distrib_left, exists_and_distrib_left] } } end @[simp] theorem split_at_eq_take_drop : ∀ (n : ℕ) (l : list α), split_at n l = (take n l, drop n l) | 0 a := rfl | (succ n) [] := rfl | (succ n) (x :: xs) := by simp only [split_at, split_at_eq_take_drop n xs, take, drop] @[simp] theorem take_append_drop : ∀ (n : ℕ) (l : list α), take n l ++ drop n l = l | 0 a := rfl | (succ n) [] := rfl | (succ n) (x :: xs) := congr_arg (cons x) $ take_append_drop n xs -- TODO(Leo): cleanup proof after arith dec proc theorem append_inj : ∀ {s₁ s₂ t₁ t₂ : list α}, s₁ ++ t₁ = s₂ ++ t₂ → length s₁ = length s₂ → s₁ = s₂ ∧ t₁ = t₂ | [] [] t₁ t₂ h hl := ⟨rfl, h⟩ | (a::s₁) [] t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl | [] (b::s₂) t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl.symm | (a::s₁) (b::s₂) t₁ t₂ h hl := list.no_confusion h $ λab hap, let ⟨e1, e2⟩ := @append_inj s₁ s₂ t₁ t₂ hap (succ.inj hl) in by rw [ab, e1, e2]; exact ⟨rfl, rfl⟩ theorem append_inj_left {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length s₁ = length s₂) : t₁ = t₂ := (append_inj h hl).right theorem append_inj_right {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length s₁ = length s₂) : s₁ = s₂ := (append_inj h hl).left theorem append_inj' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length t₁ = length t₂) : s₁ = s₂ ∧ t₁ = t₂ := append_inj h $ @nat.add_right_cancel _ (length t₁) _ $ let hap := congr_arg length h in by simp only [length_append] at hap; rwa [← hl] at hap theorem append_inj_left' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length t₁ = length t₂) : t₁ = t₂ := (append_inj' h hl).right theorem append_inj_right' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length t₁ = length t₂) : s₁ = s₂ := (append_inj' h hl).left theorem append_left_cancel {s t₁ t₂ : list α} (h : s ++ t₁ = s ++ t₂) : t₁ = t₂ := append_inj_left h rfl theorem append_right_cancel {s₁ s₂ t : list α} (h : s₁ ++ t = s₂ ++ t) : s₁ = s₂ := append_inj_right' h rfl theorem append_left_inj {t₁ t₂ : list α} (s) : s ++ t₁ = s ++ t₂ ↔ t₁ = t₂ := ⟨append_left_cancel, congr_arg _⟩ theorem append_right_inj {s₁ s₂ : list α} (t) : s₁ ++ t = s₂ ++ t ↔ s₁ = s₂ := ⟨append_right_cancel, congr_arg _⟩ theorem map_eq_append_split {f : α → β} {l : list α} {s₁ s₂ : list β} (h : map f l = s₁ ++ s₂) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ map f l₁ = s₁ ∧ map f l₂ = s₂ := begin have := h, rw [← take_append_drop (length s₁) l] at this ⊢, rw map_append at this, refine ⟨_, _, rfl, append_inj this _⟩, rw [length_map, length_take, min_eq_left], rw [← length_map f l, h, length_append], apply nat.le_add_right end /- join -/ attribute [simp] join theorem join_eq_nil : ∀ {L : list (list α)}, join L = [] ↔ ∀ l ∈ L, l = [] | [] := iff_of_true rfl (forall_mem_nil _) | (l::L) := by simp only [join, append_eq_nil, join_eq_nil, forall_mem_cons] @[simp] theorem join_append (L₁ L₂ : list (list α)) : join (L₁ ++ L₂) = join L₁ ++ join L₂ := by induction L₁; [refl, simp only [*, join, cons_append, append_assoc]] lemma join_join (l : list (list (list α))) : l.join.join = (l.map join).join := by { induction l, simp, simp [l_ih] } /- repeat -/ @[simp] theorem repeat_succ (a : α) (n) : repeat a (n + 1) = a :: repeat a n := rfl theorem eq_of_mem_repeat {a b : α} : ∀ {n}, b ∈ repeat a n → b = a | (n+1) h := or.elim h id $ @eq_of_mem_repeat _ theorem eq_repeat_of_mem {a : α} : ∀ {l : list α}, (∀ b ∈ l, b = a) → l = repeat a l.length | [] H := rfl | (b::l) H := by cases forall_mem_cons.1 H with H₁ H₂; unfold length repeat; congr; [exact H₁, exact eq_repeat_of_mem H₂] theorem eq_repeat' {a : α} {l : list α} : l = repeat a l.length ↔ ∀ b ∈ l, b = a := ⟨λ h, h.symm ▸ λ b, eq_of_mem_repeat, eq_repeat_of_mem⟩ theorem eq_repeat {a : α} {n} {l : list α} : l = repeat a n ↔ length l = n ∧ ∀ b ∈ l, b = a := ⟨λ h, h.symm ▸ ⟨length_repeat _ _, λ b, eq_of_mem_repeat⟩, λ ⟨e, al⟩, e ▸ eq_repeat_of_mem al⟩ theorem repeat_add (a : α) (m n) : repeat a (m + n) = repeat a m ++ repeat a n := by induction m; simp only [*, zero_add, succ_add, repeat]; split; refl theorem repeat_subset_singleton (a : α) (n) : repeat a n ⊆ [a] := λ b h, mem_singleton.2 (eq_of_mem_repeat h) @[simp] theorem map_const (l : list α) (b : β) : map (function.const α b) l = repeat b l.length := by induction l; [refl, simp only [*, map]]; split; refl theorem eq_of_mem_map_const {b₁ b₂ : β} {l : list α} (h : b₁ ∈ map (function.const α b₂) l) : b₁ = b₂ := by rw map_const at h; exact eq_of_mem_repeat h @[simp] theorem map_repeat (f : α → β) (a : α) (n) : map f (repeat a n) = repeat (f a) n := by induction n; [refl, simp only [*, repeat, map]]; split; refl @[simp] theorem tail_repeat (a : α) (n) : tail (repeat a n) = repeat a n.pred := by cases n; refl @[simp] theorem join_repeat_nil (n : ℕ) : join (repeat [] n) = @nil α := by induction n; [refl, simp only [*, repeat, join, append_nil]] /- bind -/ @[simp] theorem bind_eq_bind {α β} (f : α → list β) (l : list α) : l >>= f = l.bind f := rfl @[simp] theorem bind_append (f : α → list β) (l₁ l₂ : list α) : (l₁ ++ l₂).bind f = l₁.bind f ++ l₂.bind f := append_bind _ _ _ /- concat -/ @[simp] theorem concat_nil (a : α) : concat [] a = [a] := rfl @[simp] theorem concat_cons (a b : α) (l : list α) : concat (a :: l) b = a :: concat l b := rfl @[simp] theorem concat_ne_nil (a : α) (l : list α) : concat l a ≠ [] := by induction l; intro h; contradiction @[simp] theorem concat_append (a : α) (l₁ l₂ : list α) : concat l₁ a ++ l₂ = l₁ ++ a :: l₂ := by induction l₁; simp only [*, cons_append, concat]; split; refl @[simp] theorem concat_eq_append (a : α) (l : list α) : concat l a = l ++ [a] := by induction l; simp only [*, concat]; split; refl @[simp] theorem length_concat (a : α) (l : list α) : length (concat l a) = succ (length l) := by simp only [concat_eq_append, length_append, length] theorem append_concat (a : α) (l₁ l₂ : list α) : l₁ ++ concat l₂ a = concat (l₁ ++ l₂) a := by induction l₂ with b l₂ ih; simp only [concat_eq_append, nil_append, cons_append, append_assoc] /- reverse -/ @[simp] theorem reverse_nil : reverse (@nil α) = [] := rfl local attribute [simp] reverse_core @[simp] theorem reverse_cons (a : α) (l : list α) : reverse (a::l) = reverse l ++ [a] := have aux : ∀ l₁ l₂, reverse_core l₁ l₂ ++ [a] = reverse_core l₁ (l₂ ++ [a]), by intro l₁; induction l₁; intros; [refl, simp only [*, reverse_core, cons_append]], (aux l nil).symm theorem reverse_core_eq (l₁ l₂ : list α) : reverse_core l₁ l₂ = reverse l₁ ++ l₂ := by induction l₁ generalizing l₂; [refl, simp only [*, reverse_core, reverse_cons, append_assoc]]; refl theorem reverse_cons' (a : α) (l : list α) : reverse (a::l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_append (s t : list α) : reverse (s ++ t) = (reverse t) ++ (reverse s) := by induction s; [rw [nil_append, reverse_nil, append_nil], simp only [*, cons_append, reverse_cons, append_assoc]] @[simp] theorem reverse_reverse (l : list α) : reverse (reverse l) = l := by induction l; [refl, simp only [*, reverse_cons, reverse_append]]; refl theorem reverse_injective : injective (@reverse α) := injective_of_left_inverse reverse_reverse @[simp] theorem reverse_inj {l₁ l₂ : list α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ := reverse_injective.eq_iff @[simp] theorem reverse_eq_nil {l : list α} : reverse l = [] ↔ l = [] := @reverse_inj _ l [] theorem concat_eq_reverse_cons (a : α) (l : list α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] @[simp] theorem length_reverse (l : list α) : length (reverse l) = length l := by induction l; [refl, simp only [*, reverse_cons, length_append, length]] @[simp] theorem map_reverse (f : α → β) (l : list α) : map f (reverse l) = reverse (map f l) := by induction l; [refl, simp only [*, map, reverse_cons, map_append]] theorem map_reverse_core (f : α → β) (l₁ l₂ : list α) : map f (reverse_core l₁ l₂) = reverse_core (map f l₁) (map f l₂) := by simp only [reverse_core_eq, map_append, map_reverse] @[simp] theorem mem_reverse {a : α} {l : list α} : a ∈ reverse l ↔ a ∈ l := by induction l; [refl, simp only [*, reverse_cons, mem_append, mem_singleton, mem_cons_iff, not_mem_nil, false_or, or_false, or_comm]] @[simp] theorem reverse_repeat (a : α) (n) : reverse (repeat a n) = repeat a n := eq_repeat.2 ⟨by simp only [length_reverse, length_repeat], λ b h, eq_of_mem_repeat (mem_reverse.1 h)⟩ @[elab_as_eliminator] def reverse_rec_on {C : list α → Sort*} (l : list α) (H0 : C []) (H1 : ∀ (l : list α) (a : α), C l → C (l ++ [a])) : C l := begin rw ← reverse_reverse l, induction reverse l, { exact H0 }, { rw reverse_cons, exact H1 _ _ ih } end /- last -/ @[simp] theorem last_cons {a : α} {l : list α} : ∀ (h₁ : a :: l ≠ nil) (h₂ : l ≠ nil), last (a :: l) h₁ = last l h₂ := by {induction l; intros, contradiction, reflexivity} @[simp] theorem last_append {a : α} (l : list α) (h : l ++ [a] ≠ []) : last (l ++ [a]) h = a := by induction l; [refl, simp only [cons_append, last_cons _ (λ H, cons_ne_nil _ _ (append_eq_nil.1 H).2), *]] theorem last_concat {a : α} (l : list α) (h : concat l a ≠ []) : last (concat l a) h = a := by simp only [concat_eq_append, last_append] @[simp] theorem last_singleton (a : α) (h : [a] ≠ []) : last [a] h = a := rfl @[simp] theorem last_cons_cons (a₁ a₂ : α) (l : list α) (h : a₁::a₂::l ≠ []) : last (a₁::a₂::l) h = last (a₂::l) (cons_ne_nil a₂ l) := rfl theorem last_congr {l₁ l₂ : list α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : last l₁ h₁ = last l₂ h₂ := by subst l₁ /- head(') and tail -/ theorem head_eq_head' [inhabited α] (l : list α) : head l = (head' l).iget := by cases l; refl @[simp] theorem head_cons [inhabited α] (a : α) (l : list α) : head (a::l) = a := rfl @[simp] theorem tail_nil : tail (@nil α) = [] := rfl @[simp] theorem tail_cons (a : α) (l : list α) : tail (a::l) = l := rfl @[simp] theorem head_append [inhabited α] (t : list α) {s : list α} (h : s ≠ []) : head (s ++ t) = head s := by {induction s, contradiction, refl} theorem cons_head_tail [inhabited α] {l : list α} (h : l ≠ []) : (head l)::(tail l) = l := by {induction l, contradiction, refl} /- sublists -/ @[simp] theorem nil_sublist : Π (l : list α), [] <+ l | [] := sublist.slnil | (a :: l) := sublist.cons _ _ a (nil_sublist l) @[refl, simp] theorem sublist.refl : Π (l : list α), l <+ l | [] := sublist.slnil | (a :: l) := sublist.cons2 _ _ a (sublist.refl l) @[trans] theorem sublist.trans {l₁ l₂ l₃ : list α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := sublist.rec_on h₂ (λ_ s, s) (λl₂ l₃ a h₂ IH l₁ h₁, sublist.cons _ _ _ (IH l₁ h₁)) (λl₂ l₃ a h₂ IH l₁ h₁, @sublist.cases_on _ (λl₁ l₂', l₂' = a :: l₂ → l₁ <+ a :: l₃) _ _ h₁ (λ_, nil_sublist _) (λl₁ l₂' a' h₁' e, match a', l₂', e, h₁' with ._, ._, rfl, h₁ := sublist.cons _ _ _ (IH _ h₁) end) (λl₁ l₂' a' h₁' e, match a', l₂', e, h₁' with ._, ._, rfl, h₁ := sublist.cons2 _ _ _ (IH _ h₁) end) rfl) l₁ h₁ @[simp] theorem sublist_cons (a : α) (l : list α) : l <+ a::l := sublist.cons _ _ _ (sublist.refl l) theorem sublist_of_cons_sublist {a : α} {l₁ l₂ : list α} : a::l₁ <+ l₂ → l₁ <+ l₂ := sublist.trans (sublist_cons a l₁) theorem cons_sublist_cons {l₁ l₂ : list α} (a : α) (s : l₁ <+ l₂) : a::l₁ <+ a::l₂ := sublist.cons2 _ _ _ s @[simp] theorem sublist_append_left : Π (l₁ l₂ : list α), l₁ <+ l₁++l₂ | [] l₂ := nil_sublist _ | (a::l₁) l₂ := cons_sublist_cons _ (sublist_append_left l₁ l₂) @[simp] theorem sublist_append_right : Π (l₁ l₂ : list α), l₂ <+ l₁++l₂ | [] l₂ := sublist.refl _ | (a::l₁) l₂ := sublist.cons _ _ _ (sublist_append_right l₁ l₂) theorem sublist_cons_of_sublist (a : α) {l₁ l₂ : list α} : l₁ <+ l₂ → l₁ <+ a::l₂ := sublist.cons _ _ _ theorem sublist_append_of_sublist_left {l l₁ l₂ : list α} (s : l <+ l₁) : l <+ l₁++l₂ := s.trans $ sublist_append_left _ _ theorem sublist_append_of_sublist_right {l l₁ l₂ : list α} (s : l <+ l₂) : l <+ l₁++l₂ := s.trans $ sublist_append_right _ _ theorem sublist_of_cons_sublist_cons {l₁ l₂ : list α} : ∀ {a : α}, a::l₁ <+ a::l₂ → l₁ <+ l₂ | ._ (sublist.cons ._ ._ a s) := sublist_of_cons_sublist s | ._ (sublist.cons2 ._ ._ a s) := s theorem cons_sublist_cons_iff {l₁ l₂ : list α} {a : α} : a::l₁ <+ a::l₂ ↔ l₁ <+ l₂ := ⟨sublist_of_cons_sublist_cons, cons_sublist_cons _⟩ @[simp] theorem append_sublist_append_left {l₁ l₂ : list α} : ∀ l, l++l₁ <+ l++l₂ ↔ l₁ <+ l₂ | [] := iff.rfl | (a::l) := cons_sublist_cons_iff.trans (append_sublist_append_left l) theorem append_sublist_append_of_sublist_right {l₁ l₂ : list α} (h : l₁ <+ l₂) (l) : l₁++l <+ l₂++l := begin induction h with _ _ a _ ih _ _ a _ ih, { refl }, { apply sublist_cons_of_sublist a ih }, { apply cons_sublist_cons a ih } end theorem sublist_or_mem_of_sublist {l l₁ l₂ : list α} {a : α} (h : l <+ l₁ ++ a::l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := begin induction l₁ with b l₁ IH generalizing l, { cases h, { left, exact ‹l <+ l₂› }, { right, apply mem_cons_self } }, { cases h with _ _ _ h _ _ _ h, { exact or.imp_left (sublist_cons_of_sublist _) (IH h) }, { exact (IH h).imp (cons_sublist_cons _) (mem_cons_of_mem _) } } end theorem reverse_sublist {l₁ l₂ : list α} (h : l₁ <+ l₂) : l₁.reverse <+ l₂.reverse := begin induction h with _ _ _ _ ih _ _ a _ ih, {refl}, { rw reverse_cons, exact sublist_append_of_sublist_left ih }, { rw [reverse_cons, reverse_cons], exact append_sublist_append_of_sublist_right ih [a] } end @[simp] theorem reverse_sublist_iff {l₁ l₂ : list α} : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨λ h, by have := reverse_sublist h; simp only [reverse_reverse] at this; assumption, reverse_sublist⟩ @[simp] theorem append_sublist_append_right {l₁ l₂ : list α} (l) : l₁++l <+ l₂++l ↔ l₁ <+ l₂ := ⟨λ h, by have := reverse_sublist h; simp only [reverse_append, append_sublist_append_left, reverse_sublist_iff] at this; assumption, λ h, append_sublist_append_of_sublist_right h l⟩ theorem append_sublist_append {l₁ l₂ r₁ r₂ : list α} (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (append_sublist_append_of_sublist_right hl _).trans ((append_sublist_append_left _).2 hr) theorem subset_of_sublist : Π {l₁ l₂ : list α}, l₁ <+ l₂ → l₁ ⊆ l₂ | ._ ._ sublist.slnil b h := h | ._ ._ (sublist.cons l₁ l₂ a s) b h := mem_cons_of_mem _ (subset_of_sublist s h) | ._ ._ (sublist.cons2 l₁ l₂ a s) b h := match eq_or_mem_of_mem_cons h with | or.inl h := h ▸ mem_cons_self _ _ | or.inr h := mem_cons_of_mem _ (subset_of_sublist s h) end theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := ⟨λ h, subset_of_sublist h (mem_singleton_self _), λ h, let ⟨s, t, e⟩ := mem_split h in e.symm ▸ (cons_sublist_cons _ (nil_sublist _)).trans (sublist_append_right _ _)⟩ theorem eq_nil_of_sublist_nil {l : list α} (s : l <+ []) : l = [] := eq_nil_of_subset_nil $ subset_of_sublist s theorem repeat_sublist_repeat (a : α) {m n} : repeat a m <+ repeat a n ↔ m ≤ n := ⟨λ h, by simpa only [length_repeat] using length_le_of_sublist h, λ h, by induction h; [refl, simp only [*, repeat_succ, sublist.cons]] ⟩ theorem eq_of_sublist_of_length_eq : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | ._ ._ sublist.slnil h := rfl | ._ ._ (sublist.cons l₁ l₂ a s) h := absurd (length_le_of_sublist s) $ not_le_of_gt $ by rw h; apply lt_succ_self | ._ ._ (sublist.cons2 l₁ l₂ a s) h := by rw [length, length] at h; injection h with h; rw eq_of_sublist_of_length_eq s h theorem eq_of_sublist_of_length_le {l₁ l₂ : list α} (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := eq_of_sublist_of_length_eq s (le_antisymm (length_le_of_sublist s) h) theorem sublist_antisymm {l₁ l₂ : list α} (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := eq_of_sublist_of_length_le s₁ (length_le_of_sublist s₂) instance decidable_sublist [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <+ l₂) | [] l₂ := is_true $ nil_sublist _ | (a::l₁) [] := is_false $ λh, list.no_confusion $ eq_nil_of_sublist_nil h | (a::l₁) (b::l₂) := if h : a = b then decidable_of_decidable_of_iff (decidable_sublist l₁ l₂) $ by rw [← h]; exact ⟨cons_sublist_cons _, sublist_of_cons_sublist_cons⟩ else decidable_of_decidable_of_iff (decidable_sublist (a::l₁) l₂) ⟨sublist_cons_of_sublist _, λs, match a, l₁, s, h with | a, l₁, sublist.cons ._ ._ ._ s', h := s' | ._, ._, sublist.cons2 t ._ ._ s', h := absurd rfl h end⟩ /- index_of -/ section index_of variable [decidable_eq α] @[simp] theorem index_of_nil (a : α) : index_of a [] = 0 := rfl theorem index_of_cons (a b : α) (l : list α) : index_of a (b::l) = if a = b then 0 else succ (index_of a l) := rfl theorem index_of_cons_eq {a b : α} (l : list α) : a = b → index_of a (b::l) = 0 := assume e, if_pos e @[simp] theorem index_of_cons_self (a : α) (l : list α) : index_of a (a::l) = 0 := index_of_cons_eq _ rfl @[simp] theorem index_of_cons_ne {a b : α} (l : list α) : a ≠ b → index_of a (b::l) = succ (index_of a l) := assume n, if_neg n theorem index_of_eq_length {a : α} {l : list α} : index_of a l = length l ↔ a ∉ l := begin induction l with b l ih, { exact iff_of_true rfl (not_mem_nil _) }, simp only [length, mem_cons_iff, index_of_cons], split_ifs, { exact iff_of_false (by rintro ⟨⟩) (λ H, H $ or.inl h) }, { simp only [h, false_or], rw ← ih, exact succ_inj' } end @[simp] theorem index_of_of_not_mem {l : list α} {a : α} : a ∉ l → index_of a l = length l := index_of_eq_length.2 theorem index_of_le_length {a : α} {l : list α} : index_of a l ≤ length l := begin induction l with b l ih, {refl}, simp only [length, index_of_cons], by_cases h : a = b, {rw if_pos h, exact nat.zero_le _}, rw if_neg h, exact succ_le_succ ih end theorem index_of_lt_length {a} {l : list α} : index_of a l < length l ↔ a ∈ l := ⟨λh, by_contradiction $ λ al, ne_of_lt h $ index_of_eq_length.2 al, λal, lt_of_le_of_ne index_of_le_length $ λ h, index_of_eq_length.1 h al⟩ end index_of /- nth element -/ theorem nth_le_of_mem : ∀ {a} {l : list α}, a ∈ l → ∃ n h, nth_le l n h = a | a (_ :: l) (or.inl rfl) := ⟨0, succ_pos _, rfl⟩ | a (b :: l) (or.inr m) := let ⟨n, h, e⟩ := nth_le_of_mem m in ⟨n+1, succ_lt_succ h, e⟩ theorem nth_le_nth : ∀ {l : list α} {n} h, nth l n = some (nth_le l n h) | (a :: l) 0 h := rfl | (a :: l) (n+1) h := @nth_le_nth l n _ theorem nth_len_le : ∀ {l : list α} {n}, length l ≤ n → nth l n = none | [] n h := rfl | (a :: l) (n+1) h := nth_len_le (le_of_succ_le_succ h) theorem nth_eq_some {l : list α} {n a} : nth l n = some a ↔ ∃ h, nth_le l n h = a := ⟨λ e, have h : n < length l, from lt_of_not_ge $ λ hn, by rw nth_len_le hn at e; contradiction, ⟨h, by rw nth_le_nth h at e; injection e with e; apply nth_le_mem⟩, λ ⟨h, e⟩, e ▸ nth_le_nth _⟩ theorem nth_of_mem {a} {l : list α} (h : a ∈ l) : ∃ n, nth l n = some a := let ⟨n, h, e⟩ := nth_le_of_mem h in ⟨n, by rw [nth_le_nth, e]⟩ theorem nth_le_mem : ∀ (l : list α) n h, nth_le l n h ∈ l | (a :: l) 0 h := mem_cons_self _ _ | (a :: l) (n+1) h := mem_cons_of_mem _ (nth_le_mem l _ _) theorem nth_mem {l : list α} {n a} (e : nth l n = some a) : a ∈ l := let ⟨h, e⟩ := nth_eq_some.1 e in e ▸ nth_le_mem _ _ _ theorem mem_iff_nth_le {a} {l : list α} : a ∈ l ↔ ∃ n h, nth_le l n h = a := ⟨nth_le_of_mem, λ ⟨n, h, e⟩, e ▸ nth_le_mem _ _ _⟩ theorem mem_iff_nth {a} {l : list α} : a ∈ l ↔ ∃ n, nth l n = some a := mem_iff_nth_le.trans $ exists_congr $ λ n, nth_eq_some.symm @[simp] theorem nth_map (f : α → β) : ∀ l n, nth (map f l) n = (nth l n).map f | [] n := rfl | (a :: l) 0 := rfl | (a :: l) (n+1) := nth_map l n theorem nth_le_map (f : α → β) {l n} (H1 H2) : nth_le (map f l) n H1 = f (nth_le l n H2) := option.some.inj $ by rw [← nth_le_nth, nth_map, nth_le_nth]; refl /-- A version of `nth_le_map` that can be used for rewriting. -/ theorem nth_le_map_rev (f : α → β) {l n} (H) : f (nth_le l n H) = nth_le (map f l) n ((length_map f l).symm ▸ H) := (nth_le_map f _ _).symm @[simp] theorem nth_le_map' (f : α → β) {l n} (H) : nth_le (map f l) n H = f (nth_le l n (length_map f l ▸ H)) := nth_le_map f _ _ @[simp] lemma nth_le_singleton (a : α) {n : ℕ} (hn : n < 1) : nth_le [a] n hn = a := have hn0 : n = 0 := le_zero_iff.1 (le_of_lt_succ hn), by subst hn0; refl lemma nth_le_append : ∀ {l₁ l₂ : list α} {n : ℕ} (hn₁) (hn₂), (l₁ ++ l₂).nth_le n hn₁ = l₁.nth_le n hn₂ | [] _ n hn₁ hn₂ := (not_lt_zero _ hn₂).elim | (a::l) _ 0 hn₁ hn₂ := rfl | (a::l) _ (n+1) hn₁ hn₂ := by simp only [nth_le, cons_append]; exact nth_le_append _ _ @[simp] lemma nth_le_repeat (a : α) {n m : ℕ} (h : m < n) : (list.repeat a n).nth_le m (by rwa list.length_repeat) = a := eq_of_mem_repeat (nth_le_mem _ _ _) lemma nth_append {l₁ l₂ : list α} {n : ℕ} (hn : n < l₁.length) : (l₁ ++ l₂).nth n = l₁.nth n := have hn' : n < (l₁ ++ l₂).length := lt_of_lt_of_le hn (by rw length_append; exact le_add_right _ _), by rw [nth_le_nth hn, nth_le_nth hn', nth_le_append] lemma last_eq_nth_le : ∀ (l : list α) (h : l ≠ []), last l h = l.nth_le (l.length - 1) (sub_lt (length_pos_of_ne_nil h) one_pos) | [] h := rfl | [a] h := by rw [last_singleton, nth_le_singleton] | (a :: b :: l) h := by { rw [last_cons, last_eq_nth_le (b :: l)], refl, exact cons_ne_nil b l } @[simp] lemma nth_concat_length: ∀ (l : list α) (a : α), (l ++ [a]).nth l.length = a | [] a := rfl | (b::l) a := by rw [cons_append, length_cons, nth, nth_concat_length] @[extensionality] theorem ext : ∀ {l₁ l₂ : list α}, (∀n, nth l₁ n = nth l₂ n) → l₁ = l₂ | [] [] h := rfl | (a::l₁) [] h := by have h0 := h 0; contradiction | [] (a'::l₂) h := by have h0 := h 0; contradiction | (a::l₁) (a'::l₂) h := by have h0 : some a = some a' := h 0; injection h0 with aa; simp only [aa, ext (λn, h (n+1))]; split; refl theorem ext_le {l₁ l₂ : list α} (hl : length l₁ = length l₂) (h : ∀n h₁ h₂, nth_le l₁ n h₁ = nth_le l₂ n h₂) : l₁ = l₂ := ext $ λn, if h₁ : n < length l₁ then by rw [nth_le_nth, nth_le_nth, h n h₁ (by rwa [← hl])] else let h₁ := le_of_not_gt h₁ in by { rw [nth_len_le h₁, nth_len_le], rwa [←hl], } @[simp] theorem index_of_nth_le [decidable_eq α] {a : α} : ∀ {l : list α} h, nth_le l (index_of a l) h = a | (b::l) h := by by_cases h' : a = b; simp only [h', if_pos, if_false, index_of_cons, nth_le, @index_of_nth_le l] @[simp] theorem index_of_nth [decidable_eq α] {a : α} {l : list α} (h : a ∈ l) : nth l (index_of a l) = some a := by rw [nth_le_nth, index_of_nth_le (index_of_lt_length.2 h)] theorem nth_le_reverse_aux1 : ∀ (l r : list α) (i h1 h2), nth_le (reverse_core l r) (i + length l) h1 = nth_le r i h2 | [] r i := λh1 h2, rfl | (a :: l) r i := by rw (show i + length (a :: l) = i + 1 + length l, from add_right_comm i (length l) 1); exact λh1 h2, nth_le_reverse_aux1 l (a :: r) (i+1) h1 (succ_lt_succ h2) lemma index_of_inj [decidable_eq α] {l : list α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : index_of x l = index_of y l ↔ x = y := ⟨λ h, have nth_le l (index_of x l) (index_of_lt_length.2 hx) = nth_le l (index_of y l) (index_of_lt_length.2 hy), by simp only [h], by simpa only [index_of_nth_le], λ h, by subst h⟩ theorem nth_le_reverse_aux2 : ∀ (l r : list α) (i : nat) (h1) (h2), nth_le (reverse_core l r) (length l - 1 - i) h1 = nth_le l i h2 | [] r i h1 h2 := absurd h2 (not_lt_zero _) | (a :: l) r 0 h1 h2 := begin have aux := nth_le_reverse_aux1 l (a :: r) 0, rw zero_add at aux, exact aux _ (zero_lt_succ _) end | (a :: l) r (i+1) h1 h2 := begin have aux := nth_le_reverse_aux2 l (a :: r) i, have heq := calc length (a :: l) - 1 - (i + 1) = length l - (1 + i) : by rw add_comm; refl ... = length l - 1 - i : by rw nat.sub_sub, rw [← heq] at aux, apply aux end @[simp] theorem nth_le_reverse (l : list α) (i : nat) (h1 h2) : nth_le (reverse l) (length l - 1 - i) h1 = nth_le l i h2 := nth_le_reverse_aux2 _ _ _ _ _ lemma modify_nth_tail_modify_nth_tail {f g : list α → list α} (m : ℕ) : ∀n (l:list α), (l.modify_nth_tail f n).modify_nth_tail g (m + n) = l.modify_nth_tail (λl, (f l).modify_nth_tail g m) n | 0 l := rfl | (n+1) [] := rfl | (n+1) (a::l) := congr_arg (list.cons a) (modify_nth_tail_modify_nth_tail n l) lemma modify_nth_tail_modify_nth_tail_le {f g : list α → list α} (m n : ℕ) (l : list α) (h : n ≤ m) : (l.modify_nth_tail f n).modify_nth_tail g m = l.modify_nth_tail (λl, (f l).modify_nth_tail g (m - n)) n := begin rcases le_iff_exists_add.1 h with ⟨m, rfl⟩, rw [nat.add_sub_cancel_left, add_comm, modify_nth_tail_modify_nth_tail] end lemma modify_nth_tail_modify_nth_tail_same {f g : list α → list α} (n : ℕ) (l:list α) : (l.modify_nth_tail f n).modify_nth_tail g n = l.modify_nth_tail (g ∘ f) n := by rw [modify_nth_tail_modify_nth_tail_le n n l (le_refl n), nat.sub_self]; refl lemma modify_nth_tail_id : ∀n (l:list α), l.modify_nth_tail id n = l | 0 l := rfl | (n+1) [] := rfl | (n+1) (a::l) := congr_arg (list.cons a) (modify_nth_tail_id n l) theorem remove_nth_eq_nth_tail : ∀ n (l : list α), remove_nth l n = modify_nth_tail tail n l | 0 l := by cases l; refl | (n+1) [] := rfl | (n+1) (a::l) := congr_arg (cons _) (remove_nth_eq_nth_tail _ _) theorem update_nth_eq_modify_nth (a : α) : ∀ n (l : list α), update_nth l n a = modify_nth (λ _, a) n l | 0 l := by cases l; refl | (n+1) [] := rfl | (n+1) (b::l) := congr_arg (cons _) (update_nth_eq_modify_nth _ _) theorem modify_nth_eq_update_nth (f : α → α) : ∀ n (l : list α), modify_nth f n l = ((λ a, update_nth l n (f a)) <$> nth l n).get_or_else l | 0 l := by cases l; refl | (n+1) [] := rfl | (n+1) (b::l) := (congr_arg (cons b) (modify_nth_eq_update_nth n l)).trans $ by cases nth l n; refl theorem nth_modify_nth (f : α → α) : ∀ n (l : list α) m, nth (modify_nth f n l) m = (λ a, if n = m then f a else a) <$> nth l m | n l 0 := by cases l; cases n; refl | n [] (m+1) := by cases n; refl | 0 (a::l) (m+1) := by cases nth l m; refl | (n+1) (a::l) (m+1) := (nth_modify_nth n l m).trans $ by cases nth l m with b; by_cases n = m; simp only [h, if_pos, if_true, if_false, option.map_none, option.map_some, mt succ_inj, not_false_iff] theorem modify_nth_tail_length (f : list α → list α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modify_nth_tail f n l) = length l | 0 l := H _ | (n+1) [] := rfl | (n+1) (a::l) := @congr_arg _ _ _ _ (+1) (modify_nth_tail_length _ _) @[simp] theorem modify_nth_length (f : α → α) : ∀ n l, length (modify_nth f n l) = length l := modify_nth_tail_length _ (λ l, by cases l; refl) @[simp] theorem update_nth_length (l : list α) (n) (a : α) : length (update_nth l n a) = length l := by simp only [update_nth_eq_modify_nth, modify_nth_length] @[simp] theorem nth_modify_nth_eq (f : α → α) (n) (l : list α) : nth (modify_nth f n l) n = f <$> nth l n := by simp only [nth_modify_nth, if_pos] @[simp] theorem nth_modify_nth_ne (f : α → α) {m n} (l : list α) (h : m ≠ n) : nth (modify_nth f m l) n = nth l n := by simp only [nth_modify_nth, if_neg h, id_map'] theorem nth_update_nth_eq (a : α) (n) (l : list α) : nth (update_nth l n a) n = (λ _, a) <$> nth l n := by simp only [update_nth_eq_modify_nth, nth_modify_nth_eq] theorem nth_update_nth_of_lt (a : α) {n} {l : list α} (h : n < length l) : nth (update_nth l n a) n = some a := by rw [nth_update_nth_eq, nth_le_nth h]; refl theorem nth_update_nth_ne (a : α) {m n} (l : list α) (h : m ≠ n) : nth (update_nth l m a) n = nth l n := by simp only [update_nth_eq_modify_nth, nth_modify_nth_ne _ _ h] @[simp] lemma nth_le_update_nth_eq (l : list α) (i : ℕ) (a : α) (h : i < (l.update_nth i a).length) : (l.update_nth i a).nth_le i h = a := by rw [← option.some_inj, ← nth_le_nth, nth_update_nth_eq, nth_le_nth]; simp * at * @[simp] lemma nth_le_update_nth_of_ne {l : list α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.update_nth i a).length) : (l.update_nth i a).nth_le j hj = l.nth_le j (by simpa using hj) := by rw [← option.some_inj, ← list.nth_le_nth, list.nth_update_nth_ne _ _ h, list.nth_le_nth] lemma mem_or_eq_of_mem_update_nth : ∀ {l : list α} {n : ℕ} {a b : α} (h : a ∈ l.update_nth n b), a ∈ l ∨ a = b | [] n a b h := false.elim h | (c::l) 0 a b h := ((mem_cons_iff _ _ _).1 h).elim or.inr (or.inl ∘ mem_cons_of_mem _) | (c::l) (n+1) a b h := ((mem_cons_iff _ _ _).1 h).elim (λ h, h ▸ or.inl (mem_cons_self _ _)) (λ h, (mem_or_eq_of_mem_update_nth h).elim (or.inl ∘ mem_cons_of_mem _) or.inr) section insert_nth variable {a : α} @[simp] lemma insert_nth_nil (a : α) : insert_nth 0 a [] = [a] := rfl lemma length_insert_nth : ∀n as, n ≤ length as → length (insert_nth n a as) = length as + 1 | 0 as h := rfl | (n+1) [] h := (nat.not_succ_le_zero _ h).elim | (n+1) (a'::as) h := congr_arg nat.succ $ length_insert_nth n as (nat.le_of_succ_le_succ h) lemma remove_nth_insert_nth (n:ℕ) (l : list α) : (l.insert_nth n a).remove_nth n = l := by rw [remove_nth_eq_nth_tail, insert_nth, modify_nth_tail_modify_nth_tail_same]; from modify_nth_tail_id _ _ lemma insert_nth_remove_nth_of_ge : ∀n m as, n < length as → m ≥ n → insert_nth m a (as.remove_nth n) = (as.insert_nth (m + 1) a).remove_nth n | 0 0 [] has _ := (lt_irrefl _ has).elim | 0 0 (a::as) has hmn := by simp [remove_nth, insert_nth] | 0 (m+1) (a::as) has hmn := rfl | (n+1) (m+1) (a::as) has hmn := congr_arg (cons a) $ insert_nth_remove_nth_of_ge n m as (nat.lt_of_succ_lt_succ has) (nat.le_of_succ_le_succ hmn) lemma insert_nth_remove_nth_of_le : ∀n m as, n < length as → m ≤ n → insert_nth m a (as.remove_nth n) = (as.insert_nth m a).remove_nth (n + 1) | n 0 (a :: as) has hmn := rfl | (n + 1) (m + 1) (a :: as) has hmn := congr_arg (cons a) $ insert_nth_remove_nth_of_le n m as (nat.lt_of_succ_lt_succ has) (nat.le_of_succ_le_succ hmn) lemma insert_nth_comm (a b : α) : ∀(i j : ℕ) (l : list α) (h : i ≤ j) (hj : j ≤ length l), (l.insert_nth i a).insert_nth (j + 1) b = (l.insert_nth j b).insert_nth i a | 0 j l := by simp [insert_nth] | (i + 1) 0 l := assume h, (nat.not_lt_zero _ h).elim | (i + 1) (j+1) [] := by simp | (i + 1) (j+1) (c::l) := assume h₀ h₁, by simp [insert_nth]; exact insert_nth_comm i j l (nat.le_of_succ_le_succ h₀) (nat.le_of_succ_le_succ h₁) lemma mem_insert_nth {a b : α} : ∀ {n : ℕ} {l : list α} (hi : n ≤ l.length), a ∈ l.insert_nth n b ↔ a = b ∨ a ∈ l | 0 as h := iff.rfl | (n+1) [] h := (nat.not_succ_le_zero _ h).elim | (n+1) (a'::as) h := begin dsimp [list.insert_nth], erw [list.mem_cons_iff, mem_insert_nth (nat.le_of_succ_le_succ h), list.mem_cons_iff, ← or.assoc, or_comm (a = a'), or.assoc] end end insert_nth /- map -/ lemma map_congr {f g : α → β} : ∀ {l : list α}, (∀ x ∈ l, f x = g x) → map f l = map g l | [] _ := rfl | (a::l) h := let ⟨h₁, h₂⟩ := forall_mem_cons.1 h in by rw [map, map, h₁, map_congr h₂] lemma map_eq_map_iff {f g : α → β} {l : list α} : map f l = map g l ↔ (∀ x ∈ l, f x = g x) := begin refine ⟨_, map_congr⟩, intros h x hx, rw [mem_iff_nth_le] at hx, rcases hx with ⟨n, hn, rfl⟩, rw [nth_le_map_rev f, nth_le_map_rev g], congr, exact h end theorem map_concat (f : α → β) (a : α) (l : list α) : map f (concat l a) = concat (map f l) (f a) := by induction l; [refl, simp only [*, concat_eq_append, cons_append, map, map_append]]; split; refl theorem map_id' {f : α → α} (h : ∀ x, f x = x) (l : list α) : map f l = l := by induction l; [refl, simp only [*, map]]; split; refl @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : list β) : foldl f a (map g l) = foldl (λx y, f x (g y)) a l := by revert a; induction l; intros; [refl, simp only [*, map, foldl]] @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : list β) : foldr f a (map g l) = foldr (f ∘ g) a l := by revert a; induction l; intros; [refl, simp only [*, map, foldr]] theorem foldl_hom (f : α → β) (g : α → γ → α) (g' : β → γ → β) (a : α) (h : ∀a x, f (g a x) = g' (f a) x) (l : list γ) : f (foldl g a l) = foldl g' (f a) l := by revert a; induction l; intros; [refl, simp only [*, foldl]] theorem foldr_hom (f : α → β) (g : γ → α → α) (g' : γ → β → β) (a : α) (h : ∀x a, f (g x a) = g' x (f a)) (l : list γ) : f (foldr g a l) = foldr g' (f a) l := by revert a; induction l; intros; [refl, simp only [*, foldr]] theorem eq_nil_of_map_eq_nil {f : α → β} {l : list α} (h : map f l = nil) : l = nil := eq_nil_of_length_eq_zero $ by rw [← length_map f l, h]; refl @[simp] theorem map_join (f : α → β) (L : list (list α)) : map f (join L) = join (map (map f) L) := by induction L; [refl, simp only [*, join, map, map_append]] theorem bind_ret_eq_map (f : α → β) (l : list α) : l.bind (list.ret ∘ f) = map f l := by unfold list.bind; induction l; simp only [map, join, list.ret, cons_append, nil_append, *]; split; refl @[simp] theorem map_eq_map {α β} (f : α → β) (l : list α) : f <$> l = map f l := rfl @[simp] theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) := by cases l; refl @[simp] theorem injective_map_iff {f : α → β} : injective (map f) ↔ injective f := begin split; intros h x y hxy, { suffices : [x] = [y], { simpa using this }, apply h, simp [hxy] }, { induction y generalizing x, simpa using hxy, cases x, simpa using hxy, simp at hxy, simp [y_ih hxy.2, h hxy.1] } end /- map₂ -/ theorem nil_map₂ (f : α → β → γ) (l : list β) : map₂ f [] l = [] := by cases l; refl theorem map₂_nil (f : α → β → γ) (l : list α) : map₂ f l [] = [] := by cases l; refl /- take, drop -/ @[simp] theorem take_zero (l : list α) : take 0 l = [] := rfl @[simp] theorem take_nil : ∀ n, take n [] = ([] : list α) | 0 := rfl | (n+1) := rfl theorem take_cons (n) (a : α) (l : list α) : take (succ n) (a::l) = a :: take n l := rfl @[simp] theorem take_all : ∀ (l : list α), take (length l) l = l | [] := rfl | (a::l) := begin change a :: (take (length l) l) = a :: l, rw take_all end theorem take_all_of_le : ∀ {n} {l : list α}, length l ≤ n → take n l = l | 0 [] h := rfl | 0 (a::l) h := absurd h (not_le_of_gt (zero_lt_succ _)) | (n+1) [] h := rfl | (n+1) (a::l) h := begin change a :: take n l = a :: l, rw [take_all_of_le (le_of_succ_le_succ h)] end @[simp] theorem take_left : ∀ l₁ l₂ : list α, take (length l₁) (l₁ ++ l₂) = l₁ | [] l₂ := rfl | (a::l₁) l₂ := congr_arg (cons a) (take_left l₁ l₂) theorem take_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) : take n (l₁ ++ l₂) = l₁ := by rw ← h; apply take_left theorem take_take : ∀ (n m) (l : list α), take n (take m l) = take (min n m) l | n 0 l := by rw [min_zero, take_zero, take_nil] | 0 m l := by rw [zero_min, take_zero, take_zero] | (succ n) (succ m) nil := by simp only [take_nil] | (succ n) (succ m) (a::l) := by simp only [take, min_succ_succ, take_take n m l]; split; refl @[simp] theorem drop_nil : ∀ n, drop n [] = ([] : list α) | 0 := rfl | (n+1) := rfl @[simp] theorem drop_one : ∀ l : list α, drop 1 l = tail l | [] := rfl | (a :: l) := rfl theorem drop_add : ∀ m n (l : list α), drop (m + n) l = drop m (drop n l) | m 0 l := rfl | m (n+1) [] := (drop_nil _).symm | m (n+1) (a::l) := drop_add m n _ @[simp] theorem drop_left : ∀ l₁ l₂ : list α, drop (length l₁) (l₁ ++ l₂) = l₂ | [] l₂ := rfl | (a::l₁) l₂ := drop_left l₁ l₂ theorem drop_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) : drop n (l₁ ++ l₂) = l₂ := by rw ← h; apply drop_left theorem drop_eq_nth_le_cons : ∀ {n} {l : list α} h, drop n l = nth_le l n h :: drop (n+1) l | 0 (a::l) h := rfl | (n+1) (a::l) h := @drop_eq_nth_le_cons n _ _ @[simp] lemma drop_all (l : list α) : l.drop l.length = [] := calc l.drop l.length = (l ++ []).drop l.length : by simp ... = [] : drop_left _ _ lemma drop_append_of_le_length : ∀ {l₁ l₂ : list α} {n : ℕ}, n ≤ l₁.length → (l₁ ++ l₂).drop n = l₁.drop n ++ l₂ | l₁ l₂ 0 hn := by simp | [] l₂ (n+1) hn := absurd hn dec_trivial | (a::l₁) l₂ (n+1) hn := by rw [drop, cons_append, drop, drop_append_of_le_length (le_of_succ_le_succ hn)] lemma take_append_of_le_length : ∀ {l₁ l₂ : list α} {n : ℕ}, n ≤ l₁.length → (l₁ ++ l₂).take n = l₁.take n | l₁ l₂ 0 hn := by simp | [] l₂ (n+1) hn := absurd hn dec_trivial | (a::l₁) l₂ (n+1) hn := by rw [list.take, list.cons_append, list.take, take_append_of_le_length (le_of_succ_le_succ hn)] @[simp] theorem drop_drop (n : ℕ) : ∀ (m) (l : list α), drop n (drop m l) = drop (n + m) l | m [] := by simp | 0 l := by simp | (m+1) (a::l) := calc drop n (drop (m + 1) (a :: l)) = drop n (drop m l) : rfl ... = drop (n + m) l : drop_drop m l ... = drop (n + (m + 1)) (a :: l) : rfl theorem drop_take : ∀ (m : ℕ) (n : ℕ) (l : list α), drop m (take (m + n) l) = take n (drop m l) | 0 n _ := by simp | (m+1) n nil := by simp | (m+1) n (_::l) := have h: m + 1 + n = (m+n) + 1, by simp, by simpa [take_cons, h] using drop_take m n l theorem modify_nth_tail_eq_take_drop (f : list α → list α) (H : f [] = []) : ∀ n l, modify_nth_tail f n l = take n l ++ f (drop n l) | 0 l := rfl | (n+1) [] := H.symm | (n+1) (b::l) := congr_arg (cons b) (modify_nth_tail_eq_take_drop n l) theorem modify_nth_eq_take_drop (f : α → α) : ∀ n l, modify_nth f n l = take n l ++ modify_head f (drop n l) := modify_nth_tail_eq_take_drop _ rfl theorem modify_nth_eq_take_cons_drop (f : α → α) {n l} (h) : modify_nth f n l = take n l ++ f (nth_le l n h) :: drop (n+1) l := by rw [modify_nth_eq_take_drop, drop_eq_nth_le_cons h]; refl theorem update_nth_eq_take_cons_drop (a : α) {n l} (h : n < length l) : update_nth l n a = take n l ++ a :: drop (n+1) l := by rw [update_nth_eq_modify_nth, modify_nth_eq_take_cons_drop _ h] @[simp] lemma update_nth_eq_nil (l : list α) (n : ℕ) (a : α) : l.update_nth n a = [] ↔ l = [] := by cases l; cases n; simp only [update_nth] section take' variable [inhabited α] @[simp] theorem take'_length : ∀ n l, length (@take' α _ n l) = n | 0 l := rfl | (n+1) l := congr_arg succ (take'_length _ _) @[simp] theorem take'_nil : ∀ n, take' n (@nil α) = repeat (default _) n | 0 := rfl | (n+1) := congr_arg (cons _) (take'_nil _) theorem take'_eq_take : ∀ {n} {l : list α}, n ≤ length l → take' n l = take n l | 0 l h := rfl | (n+1) (a::l) h := congr_arg (cons _) $ take'_eq_take $ le_of_succ_le_succ h @[simp] theorem take'_left (l₁ l₂ : list α) : take' (length l₁) (l₁ ++ l₂) = l₁ := (take'_eq_take (by simp only [length_append, nat.le_add_right])).trans (take_left _ _) theorem take'_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) : take' n (l₁ ++ l₂) = l₁ := by rw ← h; apply take'_left end take' /- foldl, foldr -/ lemma foldl_ext (f g : α → β → α) (a : α) {l : list β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := begin induction l with hd tl ih generalizing a, {refl}, unfold foldl, rw [ih (λ a b bin, H a b $ mem_cons_of_mem _ bin), H a hd (mem_cons_self _ _)] end lemma foldr_ext (f g : α → β → β) (b : β) {l : list α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := begin induction l with hd tl ih, {refl}, simp only [mem_cons_iff, or_imp_distrib, forall_and_distrib, forall_eq] at H, simp only [foldr, ih H.2, H.1] end @[simp] theorem foldl_nil (f : α → β → α) (a : α) : foldl f a [] = a := rfl @[simp] theorem foldl_cons (f : α → β → α) (a : α) (b : β) (l : list β) : foldl f a (b::l) = foldl f (f a b) l := rfl @[simp] theorem foldr_nil (f : α → β → β) (b : β) : foldr f b [] = b := rfl @[simp] theorem foldr_cons (f : α → β → β) (b : β) (a : α) (l : list α) : foldr f b (a::l) = f a (foldr f b l) := rfl @[simp] theorem foldl_append (f : α → β → α) : ∀ (a : α) (l₁ l₂ : list β), foldl f a (l₁++l₂) = foldl f (foldl f a l₁) l₂ | a [] l₂ := rfl | a (b::l₁) l₂ := by simp only [cons_append, foldl_cons, foldl_append (f a b) l₁ l₂] @[simp] theorem foldr_append (f : α → β → β) : ∀ (b : β) (l₁ l₂ : list α), foldr f b (l₁++l₂) = foldr f (foldr f b l₂) l₁ | b [] l₂ := rfl | b (a::l₁) l₂ := by simp only [cons_append, foldr_cons, foldr_append b l₁ l₂] @[simp] theorem foldl_join (f : α → β → α) : ∀ (a : α) (L : list (list β)), foldl f a (join L) = foldl (foldl f) a L | a [] := rfl | a (l::L) := by simp only [join, foldl_append, foldl_cons, foldl_join (foldl f a l) L] @[simp] theorem foldr_join (f : α → β → β) : ∀ (b : β) (L : list (list α)), foldr f b (join L) = foldr (λ l b, foldr f b l) b L | a [] := rfl | a (l::L) := by simp only [join, foldr_append, foldr_join a L, foldr_cons] theorem foldl_reverse (f : α → β → α) (a : α) (l : list β) : foldl f a (reverse l) = foldr (λx y, f y x) a l := by induction l; [refl, simp only [*, reverse_cons, foldl_append, foldl_cons, foldl_nil, foldr]] theorem foldr_reverse (f : α → β → β) (a : β) (l : list α) : foldr f a (reverse l) = foldl (λx y, f y x) a l := let t := foldl_reverse (λx y, f y x) a (reverse l) in by rw reverse_reverse l at t; rwa t @[simp] theorem foldr_eta : ∀ (l : list α), foldr cons [] l = l | [] := rfl | (x::l) := by simp only [foldr_cons, foldr_eta l]; split; refl @[simp] theorem reverse_foldl {l : list α} : reverse (foldl (λ t h, h :: t) [] l) = l := by rw ←foldr_reverse; simp /- scanl -/ lemma length_scanl {β : Type*} {f : α → β → α} : ∀ a l, length (scanl f a l) = l.length + 1 | a [] := rfl | a (x :: l) := by erw [length_cons, length_cons, length_scanl] /- scanr -/ @[simp] theorem scanr_nil (f : α → β → β) (b : β) : scanr f b [] = [b] := rfl @[simp] theorem scanr_aux_cons (f : α → β → β) (b : β) : ∀ (a : α) (l : list α), scanr_aux f b (a::l) = (foldr f b (a::l), scanr f b l) | a [] := rfl | a (x::l) := let t := scanr_aux_cons x l in by simp only [scanr, scanr_aux, t, foldr_cons] @[simp] theorem scanr_cons (f : α → β → β) (b : β) (a : α) (l : list α) : scanr f b (a::l) = foldr f b (a::l) :: scanr f b l := by simp only [scanr, scanr_aux_cons, foldr_cons]; split; refl section foldl_eq_foldr -- foldl and foldr coincide when f is commutative and associative variables {f : α → α → α} (hcomm : commutative f) (hassoc : associative f) include hassoc theorem foldl1_eq_foldr1 : ∀ a b l, foldl f a (l++[b]) = foldr f b (a::l) | a b nil := rfl | a b (c :: l) := by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]; rw hassoc include hcomm theorem foldl_eq_of_comm_of_assoc : ∀ a b l, foldl f a (b::l) = f b (foldl f a l) | a b nil := hcomm a b | a b (c::l) := by simp only [foldl_cons]; rw [← foldl_eq_of_comm_of_assoc, right_comm _ hcomm hassoc]; refl theorem foldl_eq_foldr : ∀ a l, foldl f a l = foldr f a l | a nil := rfl | a (b :: l) := by simp only [foldr_cons, foldl_eq_of_comm_of_assoc hcomm hassoc]; rw (foldl_eq_foldr a l) end foldl_eq_foldr section foldl_eq_foldlr' variables {f : α → β → α} variables hf : ∀ a b c, f (f a b) c = f (f a c) b include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b::l) = f (foldl f a l) b | a b [] := rfl | a b (c :: l) := by rw [foldl,foldl,foldl,← foldl_eq_of_comm',foldl,hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | a [] := rfl | a (b :: l) := by rw [foldl_eq_of_comm' hf,foldr,foldl_eq_foldr']; refl end foldl_eq_foldlr' section foldl_eq_foldlr' variables {f : α → β → β} variables hf : ∀ a b c, f a (f b c) = f b (f a c) include hf theorem foldr_eq_of_comm' : ∀ a b l, foldr f a (b::l) = foldr f (f b a) l | a b [] := rfl | a b (c :: l) := by rw [foldr,foldr,foldr,hf,← foldr_eq_of_comm']; refl end foldl_eq_foldlr' section variables {op : α → α → α} [ha : is_associative α op] [hc : is_commutative α op] local notation a * b := op a b local notation l <*> a := foldl op a l include ha lemma foldl_assoc : ∀ {l : list α} {a₁ a₂}, l <*> (a₁ * a₂) = a₁ * (l <*> a₂) | [] a₁ a₂ := rfl | (a :: l) a₁ a₂ := calc a::l <*> (a₁ * a₂) = l <*> (a₁ * (a₂ * a)) : by simp only [foldl_cons, ha.assoc] ... = a₁ * (a::l <*> a₂) : by rw [foldl_assoc, foldl_cons] lemma foldl_op_eq_op_foldr_assoc : ∀{l : list α} {a₁ a₂}, (l <*> a₁) * a₂ = a₁ * l.foldr (*) a₂ | [] a₁ a₂ := rfl | (a :: l) a₁ a₂ := by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] include hc lemma foldl_assoc_comm_cons {l : list α} {a₁ a₂} : (a₁ :: l) <*> a₂ = a₁ * (l <*> a₂) := by rw [foldl_cons, hc.comm, foldl_assoc] end /- mfoldl, mfoldr -/ section mfoldl_mfoldr variables {m : Type v → Type w} [monad m] @[simp] theorem mfoldl_nil (f : β → α → m β) {b} : mfoldl f b [] = pure b := rfl @[simp] theorem mfoldr_nil (f : α → β → m β) {b} : mfoldr f b [] = pure b := rfl @[simp] theorem mfoldl_cons {f : β → α → m β} {b a l} : mfoldl f b (a :: l) = f b a >>= λ b', mfoldl f b' l := rfl @[simp] theorem mfoldr_cons {f : α → β → m β} {b a l} : mfoldr f b (a :: l) = mfoldr f b l >>= f a := rfl variables [is_lawful_monad m] @[simp] theorem mfoldl_append {f : β → α → m β} : ∀ {b l₁ l₂}, mfoldl f b (l₁ ++ l₂) = mfoldl f b l₁ >>= λ x, mfoldl f x l₂ | _ [] _ := by simp only [nil_append, mfoldl_nil, pure_bind] | _ (_::_) _ := by simp only [cons_append, mfoldl_cons, mfoldl_append, bind_assoc] @[simp] theorem mfoldr_append {f : α → β → m β} : ∀ {b l₁ l₂}, mfoldr f b (l₁ ++ l₂) = mfoldr f b l₂ >>= λ x, mfoldr f x l₁ | _ [] _ := by simp only [nil_append, mfoldr_nil, bind_pure] | _ (_::_) _ := by simp only [mfoldr_cons, cons_append, mfoldr_append, bind_assoc] end mfoldl_mfoldr /- prod and sum -/ -- list.sum was already defined in defs.lean, but we couldn't tag it with `to_additive` yet. attribute [to_additive] list.prod section monoid variables [monoid α] {l l₁ l₂ : list α} {a : α} @[simp, to_additive] theorem prod_nil : ([] : list α).prod = 1 := rfl @[simp, to_additive] theorem prod_cons : (a::l).prod = a * l.prod := calc (a::l).prod = foldl (*) (a * 1) l : by simp only [list.prod, foldl_cons, one_mul, mul_one] ... = _ : foldl_assoc @[simp, to_additive] theorem prod_append : (l₁ ++ l₂).prod = l₁.prod * l₂.prod := calc (l₁ ++ l₂).prod = foldl (*) (foldl (*) 1 l₁ * 1) l₂ : by simp [list.prod] ... = l₁.prod * l₂.prod : foldl_assoc @[simp, to_additive] theorem prod_join {l : list (list α)} : l.join.prod = (l.map list.prod).prod := by induction l; [refl, simp only [*, list.join, map, prod_append, prod_cons]] end monoid @[simp, to_additive] theorem prod_erase [decidable_eq α] [comm_monoid α] {a} : Π {l : list α}, a ∈ l → a * (l.erase a).prod = l.prod | (b::l) h := begin rcases eq_or_ne_mem_of_mem h with rfl | ⟨ne, h⟩, { simp only [list.erase, if_pos, prod_cons] }, { simp only [list.erase, if_neg (mt eq.symm ne), prod_cons, prod_erase h, mul_left_comm a b] } end lemma dvd_prod [comm_semiring α] {a} {l : list α} (ha : a ∈ l) : a ∣ l.prod := let ⟨s, t, h⟩ := mem_split ha in by rw [h, prod_append, prod_cons, mul_left_comm]; exact dvd_mul_right _ _ @[simp] theorem sum_const_nat (m n : ℕ) : sum (list.repeat m n) = m * n := by induction n; [refl, simp only [*, repeat_succ, sum_cons, nat.mul_succ, add_comm]] @[simp] theorem length_join (L : list (list α)) : length (join L) = sum (map length L) := by induction L; [refl, simp only [*, join, map, sum_cons, length_append]] @[simp] theorem length_bind (l : list α) (f : α → list β) : length (list.bind l f) = sum (map (length ∘ f) l) := by rw [list.bind, length_join, map_map] lemma exists_lt_of_sum_lt [decidable_linear_ordered_cancel_comm_monoid β] {l : list α} (f g : α → β) (h : (l.map f).sum < (l.map g).sum) : ∃ x ∈ l, f x < g x := begin induction l with x l, { exfalso, exact lt_irrefl _ h }, { by_cases h' : f x < g x, exact ⟨x, mem_cons_self _ _, h'⟩, rcases l_ih _ with ⟨y, h1y, h2y⟩, refine ⟨y, mem_cons_of_mem x h1y, h2y⟩, simp at h, exact lt_of_add_lt_add_left' (lt_of_lt_of_le h $ add_le_add_right (le_of_not_gt h') _) } end lemma exists_le_of_sum_le [decidable_linear_ordered_cancel_comm_monoid β] {l : list α} (hl : l ≠ []) (f g : α → β) (h : (l.map f).sum ≤ (l.map g).sum) : ∃ x ∈ l, f x ≤ g x := begin cases l with x l, { contradiction }, { by_cases h' : f x ≤ g x, exact ⟨x, mem_cons_self _ _, h'⟩, rcases exists_lt_of_sum_lt f g _ with ⟨y, h1y, h2y⟩, exact ⟨y, mem_cons_of_mem x h1y, le_of_lt h2y⟩, simp at h, exact lt_of_add_lt_add_left' (lt_of_le_of_lt h $ add_lt_add_right (lt_of_not_ge h') _) } end /- lexicographic ordering -/ inductive lex (r : α → α → Prop) : list α → list α → Prop | nil {} {a l} : lex [] (a :: l) | cons {a l₁ l₂} (h : lex l₁ l₂) : lex (a :: l₁) (a :: l₂) | rel {a₁ l₁ a₂ l₂} (h : r a₁ a₂) : lex (a₁ :: l₁) (a₂ :: l₂) namespace lex theorem cons_iff {r : α → α → Prop} [is_irrefl α r] {a l₁ l₂} : lex r (a :: l₁) (a :: l₂) ↔ lex r l₁ l₂ := ⟨λ h, by cases h with _ _ _ _ _ h _ _ _ _ h; [exact h, exact (irrefl_of r a h).elim], lex.cons⟩ instance is_order_connected (r : α → α → Prop) [is_order_connected α r] [is_trichotomous α r] : is_order_connected (list α) (lex r) := ⟨λ l₁, match l₁ with | _, [], c::l₃, nil := or.inr nil | _, [], c::l₃, rel _ := or.inr nil | _, [], c::l₃, cons _ := or.inr nil | _, b::l₂, c::l₃, nil := or.inl nil | a::l₁, b::l₂, c::l₃, rel h := (is_order_connected.conn _ b _ h).imp rel rel | a::l₁, b::l₂, _::l₃, cons h := begin rcases trichotomous_of r a b with ab | rfl | ab, { exact or.inl (rel ab) }, { exact (_match _ l₂ _ h).imp cons cons }, { exact or.inr (rel ab) } end end⟩ instance is_trichotomous (r : α → α → Prop) [is_trichotomous α r] : is_trichotomous (list α) (lex r) := ⟨λ l₁, match l₁ with | [], [] := or.inr (or.inl rfl) | [], b::l₂ := or.inl nil | a::l₁, [] := or.inr (or.inr nil) | a::l₁, b::l₂ := begin rcases trichotomous_of r a b with ab | rfl | ab, { exact or.inl (rel ab) }, { exact (_match l₁ l₂).imp cons (or.imp (congr_arg _) cons) }, { exact or.inr (or.inr (rel ab)) } end end⟩ instance is_asymm (r : α → α → Prop) [is_asymm α r] : is_asymm (list α) (lex r) := ⟨λ l₁, match l₁ with | a::l₁, b::l₂, lex.rel h₁, lex.rel h₂ := asymm h₁ h₂ | a::l₁, b::l₂, lex.rel h₁, lex.cons h₂ := asymm h₁ h₁ | a::l₁, b::l₂, lex.cons h₁, lex.rel h₂ := asymm h₂ h₂ | a::l₁, b::l₂, lex.cons h₁, lex.cons h₂ := by exact _match _ _ h₁ h₂ end⟩ instance is_strict_total_order (r : α → α → Prop) [is_strict_total_order' α r] : is_strict_total_order' (list α) (lex r) := {..is_strict_weak_order_of_is_order_connected} instance decidable_rel [decidable_eq α] (r : α → α → Prop) [decidable_rel r] : decidable_rel (lex r) | l₁ [] := is_false $ λ h, by cases h | [] (b::l₂) := is_true lex.nil | (a::l₁) (b::l₂) := begin haveI := decidable_rel l₁ l₂, refine decidable_of_iff (r a b ∨ a = b ∧ lex r l₁ l₂) ⟨λ h, _, λ h, _⟩, { rcases h with h | ⟨rfl, h⟩, { exact lex.rel h }, { exact lex.cons h } }, { rcases h with _|⟨_,_,_,h⟩|⟨_,_,_,_,h⟩, { exact or.inr ⟨rfl, h⟩ }, { exact or.inl h } } end theorem append_right (r : α → α → Prop) : ∀ {s₁ s₂} t, lex r s₁ s₂ → lex r s₁ (s₂ ++ t) | _ _ t nil := nil | _ _ t (cons h) := cons (append_right _ h) | _ _ t (rel r) := rel r theorem append_left (R : α → α → Prop) {t₁ t₂} (h : lex R t₁ t₂) : ∀ s, lex R (s ++ t₁) (s ++ t₂) | [] := h | (a::l) := cons (append_left l) theorem imp {r s : α → α → Prop} (H : ∀ a b, r a b → s a b) : ∀ l₁ l₂, lex r l₁ l₂ → lex s l₁ l₂ | _ _ nil := nil | _ _ (cons h) := cons (imp _ _ h) | _ _ (rel r) := rel (H _ _ r) theorem to_ne : ∀ {l₁ l₂ : list α}, lex (≠) l₁ l₂ → l₁ ≠ l₂ | _ _ (cons h) e := to_ne h (list.cons.inj e).2 | _ _ (rel r) e := r (list.cons.inj e).1 theorem ne_iff {l₁ l₂ : list α} (H : length l₁ ≤ length l₂) : lex (≠) l₁ l₂ ↔ l₁ ≠ l₂ := ⟨to_ne, λ h, begin induction l₁ with a l₁ IH generalizing l₂; cases l₂ with b l₂, { contradiction }, { apply nil }, { exact (not_lt_of_ge H).elim (succ_pos _) }, { cases classical.em (a = b) with ab ab, { subst b, apply cons, exact IH (le_of_succ_le_succ H) (mt (congr_arg _) h) }, { exact rel ab } } end⟩ end lex --Note: this overrides an instance in core lean instance has_lt' [has_lt α] : has_lt (list α) := ⟨lex (<)⟩ theorem nil_lt_cons [has_lt α] (a : α) (l : list α) : [] < a :: l := lex.nil instance [linear_order α] : linear_order (list α) := linear_order_of_STO' (lex (<)) --Note: this overrides an instance in core lean instance has_le' [linear_order α] : has_le (list α) := preorder.to_has_le _ instance [decidable_linear_order α] : decidable_linear_order (list α) := decidable_linear_order_of_STO' (lex (<)) /- all & any -/ @[simp] theorem all_nil (p : α → bool) : all [] p = tt := rfl @[simp] theorem all_cons (p : α → bool) (a : α) (l : list α) : all (a::l) p = (p a && all l p) := rfl theorem all_iff_forall {p : α → bool} {l : list α} : all l p ↔ ∀ a ∈ l, p a := begin induction l with a l ih, { exact iff_of_true rfl (forall_mem_nil _) }, simp only [all_cons, band_coe_iff, ih, forall_mem_cons] end theorem all_iff_forall_prop {p : α → Prop} [decidable_pred p] {l : list α} : all l (λ a, p a) ↔ ∀ a ∈ l, p a := by simp only [all_iff_forall, bool.of_to_bool_iff] @[simp] theorem any_nil (p : α → bool) : any [] p = ff := rfl @[simp] theorem any_cons (p : α → bool) (a : α) (l : list α) : any (a::l) p = (p a || any l p) := rfl theorem any_iff_exists {p : α → bool} {l : list α} : any l p ↔ ∃ a ∈ l, p a := begin induction l with a l ih, { exact iff_of_false bool.not_ff (not_exists_mem_nil _) }, simp only [any_cons, bor_coe_iff, ih, exists_mem_cons_iff] end theorem any_iff_exists_prop {p : α → Prop} [decidable_pred p] {l : list α} : any l (λ a, p a) ↔ ∃ a ∈ l, p a := by simp [any_iff_exists] theorem any_of_mem {p : α → bool} {a : α} {l : list α} (h₁ : a ∈ l) (h₂ : p a) : any l p := any_iff_exists.2 ⟨_, h₁, h₂⟩ @[priority 500] instance decidable_forall_mem {p : α → Prop} [decidable_pred p] (l : list α) : decidable (∀ x ∈ l, p x) := decidable_of_iff _ all_iff_forall_prop instance decidable_exists_mem {p : α → Prop} [decidable_pred p] (l : list α) : decidable (∃ x ∈ l, p x) := decidable_of_iff _ any_iff_exists_prop /- map for partial functions -/ /-- Partial map. If `f : Π a, p a → β` is a partial function defined on `a : α` satisfying `p`, then `pmap f l h` is essentially the same as `map f l` but is defined only when all members of `l` satisfy `p`, using the proof to apply `f`. -/ @[simp] def pmap {p : α → Prop} (f : Π a, p a → β) : Π l : list α, (∀ a ∈ l, p a) → list β | [] H := [] | (a::l) H := f a (forall_mem_cons.1 H).1 :: pmap l (forall_mem_cons.1 H).2 /-- "Attach" the proof that the elements of `l` are in `l` to produce a new list with the same elements but in the type `{x // x ∈ l}`. -/ def attach (l : list α) : list {x // x ∈ l} := pmap subtype.mk l (λ a, id) theorem pmap_eq_map (p : α → Prop) (f : α → β) (l : list α) (H) : @pmap _ _ p (λ a _, f a) l H = map f l := by induction l; [refl, simp only [*, pmap, map]]; split; refl theorem pmap_congr {p q : α → Prop} {f : Π a, p a → β} {g : Π a, q a → β} (l : list α) {H₁ H₂} (h : ∀ a h₁ h₂, f a h₁ = g a h₂) : pmap f l H₁ = pmap g l H₂ := by induction l with _ _ ih; [refl, rw [pmap, pmap, h, ih]] theorem map_pmap {p : α → Prop} (g : β → γ) (f : Π a, p a → β) (l H) : map g (pmap f l H) = pmap (λ a h, g (f a h)) l H := by induction l; [refl, simp only [*, pmap, map]]; split; refl theorem pmap_eq_map_attach {p : α → Prop} (f : Π a, p a → β) (l H) : pmap f l H = l.attach.map (λ x, f x.1 (H _ x.2)) := by rw [attach, map_pmap]; exact pmap_congr l (λ a h₁ h₂, rfl) theorem attach_map_val (l : list α) : l.attach.map subtype.val = l := by rw [attach, map_pmap]; exact (pmap_eq_map _ _ _ _).trans (map_id l) @[simp] theorem mem_attach (l : list α) : ∀ x, x ∈ l.attach | ⟨a, h⟩ := by have := mem_map.1 (by rw [attach_map_val]; exact h); { rcases this with ⟨⟨_, _⟩, m, rfl⟩, exact m } @[simp] theorem mem_pmap {p : α → Prop} {f : Π a, p a → β} {l H b} : b ∈ pmap f l H ↔ ∃ a (h : a ∈ l), f a (H a h) = b := by simp only [pmap_eq_map_attach, mem_map, mem_attach, true_and, subtype.exists] @[simp] theorem length_pmap {p : α → Prop} {f : Π a, p a → β} {l H} : length (pmap f l H) = length l := by induction l; [refl, simp only [*, pmap, length]] @[simp] lemma length_attach (L : list α) : L.attach.length = L.length := length_pmap /- find -/ section find variables {p : α → Prop} [decidable_pred p] {l : list α} {a : α} @[simp] theorem find_nil (p : α → Prop) [decidable_pred p] : find p [] = none := rfl @[simp] theorem find_cons_of_pos (l) (h : p a) : find p (a::l) = some a := if_pos h @[simp] theorem find_cons_of_neg (l) (h : ¬ p a) : find p (a::l) = find p l := if_neg h @[simp] theorem find_eq_none : find p l = none ↔ ∀ x ∈ l, ¬ p x := begin induction l with a l IH, { exact iff_of_true rfl (forall_mem_nil _) }, rw forall_mem_cons, by_cases h : p a, { simp only [find_cons_of_pos _ h, h, not_true, false_and] }, { rwa [find_cons_of_neg _ h, iff_true_intro h, true_and] } end @[simp] theorem find_some (H : find p l = some a) : p a := begin induction l with b l IH, {contradiction}, by_cases h : p b, { rw find_cons_of_pos _ h at H, cases H, exact h }, { rw find_cons_of_neg _ h at H, exact IH H } end @[simp] theorem find_mem (H : find p l = some a) : a ∈ l := begin induction l with b l IH, {contradiction}, by_cases h : p b, { rw find_cons_of_pos _ h at H, cases H, apply mem_cons_self }, { rw find_cons_of_neg _ h at H, exact mem_cons_of_mem _ (IH H) } end end find /- lookmap -/ section lookmap variables (f : α → option α) @[simp] theorem lookmap_nil : [].lookmap f = [] := rfl @[simp] theorem lookmap_cons_none {a : α} (l : list α) (h : f a = none) : (a :: l).lookmap f = a :: l.lookmap f := by simp [lookmap, h] @[simp] theorem lookmap_cons_some {a b : α} (l : list α) (h : f a = some b) : (a :: l).lookmap f = b :: l := by simp [lookmap, h] theorem lookmap_some : ∀ l : list α, l.lookmap some = l | [] := rfl | (a::l) := rfl theorem lookmap_none : ∀ l : list α, l.lookmap (λ _, none) = l | [] := rfl | (a::l) := congr_arg (cons a) (lookmap_none l) theorem lookmap_congr {f g : α → option α} : ∀ {l : list α}, (∀ a ∈ l, f a = g a) → l.lookmap f = l.lookmap g | [] H := rfl | (a::l) H := begin cases forall_mem_cons.1 H with H₁ H₂, cases h : g a with b, { simp [h, H₁.trans h, lookmap_congr H₂] }, { simp [lookmap_cons_some _ _ h, lookmap_cons_some _ _ (H₁.trans h)] } end theorem lookmap_of_forall_not {l : list α} (H : ∀ a ∈ l, f a = none) : l.lookmap f = l := (lookmap_congr H).trans (lookmap_none l) theorem lookmap_map_eq (g : α → β) (h : ∀ a (b ∈ f a), g a = g b) : ∀ l : list α, map g (l.lookmap f) = map g l | [] := rfl | (a::l) := begin cases h' : f a with b, { simp [h', lookmap_map_eq] }, { simp [lookmap_cons_some _ _ h', h _ _ h'] } end theorem lookmap_id' (h : ∀ a (b ∈ f a), a = b) (l : list α) : l.lookmap f = l := by rw [← map_id (l.lookmap f), lookmap_map_eq, map_id]; exact h theorem length_lookmap (l : list α) : length (l.lookmap f) = length l := by rw [← length_map, lookmap_map_eq _ (λ _, ()), length_map]; simp end lookmap /- filter_map -/ @[simp] theorem filter_map_nil (f : α → option β) : filter_map f [] = [] := rfl @[simp] theorem filter_map_cons_none {f : α → option β} (a : α) (l : list α) (h : f a = none) : filter_map f (a :: l) = filter_map f l := by simp only [filter_map, h] @[simp] theorem filter_map_cons_some (f : α → option β) (a : α) (l : list α) {b : β} (h : f a = some b) : filter_map f (a :: l) = b :: filter_map f l := by simp only [filter_map, h]; split; refl theorem filter_map_eq_map (f : α → β) : filter_map (some ∘ f) = map f := begin funext l, induction l with a l IH, {refl}, simp only [filter_map_cons_some (some ∘ f) _ _ rfl, IH, map_cons], split; refl end theorem filter_map_eq_filter (p : α → Prop) [decidable_pred p] : filter_map (option.guard p) = filter p := begin funext l, induction l with a l IH, {refl}, by_cases pa : p a, { simp only [filter_map, option.guard, IH, if_pos pa, filter_cons_of_pos _ pa], split; refl }, { simp only [filter_map, option.guard, IH, if_neg pa, filter_cons_of_neg _ pa] } end theorem filter_map_filter_map (f : α → option β) (g : β → option γ) (l : list α) : filter_map g (filter_map f l) = filter_map (λ x, (f x).bind g) l := begin induction l with a l IH, {refl}, cases h : f a with b, { rw [filter_map_cons_none _ _ h, filter_map_cons_none, IH], simp only [h, option.none_bind'] }, rw filter_map_cons_some _ _ _ h, cases h' : g b with c; [ rw [filter_map_cons_none _ _ h', filter_map_cons_none, IH], rw [filter_map_cons_some _ _ _ h', filter_map_cons_some, IH] ]; simp only [h, h', option.some_bind'] end theorem map_filter_map (f : α → option β) (g : β → γ) (l : list α) : map g (filter_map f l) = filter_map (λ x, (f x).map g) l := by rw [← filter_map_eq_map, filter_map_filter_map]; refl theorem filter_map_map (f : α → β) (g : β → option γ) (l : list α) : filter_map g (map f l) = filter_map (g ∘ f) l := by rw [← filter_map_eq_map, filter_map_filter_map]; refl theorem filter_filter_map (f : α → option β) (p : β → Prop) [decidable_pred p] (l : list α) : filter p (filter_map f l) = filter_map (λ x, (f x).filter p) l := by rw [← filter_map_eq_filter, filter_map_filter_map]; refl theorem filter_map_filter (p : α → Prop) [decidable_pred p] (f : α → option β) (l : list α) : filter_map f (filter p l) = filter_map (λ x, if p x then f x else none) l := begin rw [← filter_map_eq_filter, filter_map_filter_map], congr, funext x, show (option.guard p x).bind f = ite (p x) (f x) none, by_cases h : p x, { simp only [option.guard, if_pos h, option.some_bind'] }, { simp only [option.guard, if_neg h, option.none_bind'] } end @[simp] theorem filter_map_some (l : list α) : filter_map some l = l := by rw filter_map_eq_map; apply map_id @[simp] theorem mem_filter_map (f : α → option β) (l : list α) {b : β} : b ∈ filter_map f l ↔ ∃ a, a ∈ l ∧ f a = some b := begin induction l with a l IH, { split, { intro H, cases H }, { rintro ⟨_, H, _⟩, cases H } }, cases h : f a with b', { have : f a ≠ some b, {rw h, intro, contradiction}, simp only [filter_map_cons_none _ _ h, IH, mem_cons_iff, or_and_distrib_right, exists_or_distrib, exists_eq_left, this, false_or] }, { have : f a = some b ↔ b = b', { split; intro t, {rw t at h; injection h}, {exact t.symm ▸ h} }, simp only [filter_map_cons_some _ _ _ h, IH, mem_cons_iff, or_and_distrib_right, exists_or_distrib, this, exists_eq_left] } end theorem map_filter_map_of_inv (f : α → option β) (g : β → α) (H : ∀ x : α, (f x).map g = some x) (l : list α) : map g (filter_map f l) = l := by simp only [map_filter_map, H, filter_map_some] theorem filter_map_sublist_filter_map (f : α → option β) {l₁ l₂ : list α} (s : l₁ <+ l₂) : filter_map f l₁ <+ filter_map f l₂ := by induction s with l₁ l₂ a s IH l₁ l₂ a s IH; simp only [filter_map]; cases f a with b; simp only [filter_map, IH, sublist.cons, sublist.cons2] theorem map_sublist_map (f : α → β) {l₁ l₂ : list α} (s : l₁ <+ l₂) : map f l₁ <+ map f l₂ := by rw ← filter_map_eq_map; exact filter_map_sublist_filter_map _ s /- filter -/ section filter variables {p : α → Prop} [decidable_pred p] lemma filter_congr {p q : α → Prop} [decidable_pred p] [decidable_pred q] : ∀ {l : list α}, (∀ x ∈ l, p x ↔ q x) → filter p l = filter q l | [] _ := rfl | (a::l) h := by rw forall_mem_cons at h; by_cases pa : p a; [simp only [filter_cons_of_pos _ pa, filter_cons_of_pos _ (h.1.1 pa), filter_congr h.2], simp only [filter_cons_of_neg _ pa, filter_cons_of_neg _ (mt h.1.2 pa), filter_congr h.2]]; split; refl @[simp] theorem filter_subset (l : list α) : filter p l ⊆ l := subset_of_sublist $ filter_sublist l theorem of_mem_filter {a : α} : ∀ {l}, a ∈ filter p l → p a | (b::l) ain := if pb : p b then have a ∈ b :: filter p l, by simpa only [filter_cons_of_pos _ pb] using ain, or.elim (eq_or_mem_of_mem_cons this) (assume : a = b, begin rw [← this] at pb, exact pb end) (assume : a ∈ filter p l, of_mem_filter this) else begin simp only [filter_cons_of_neg _ pb] at ain, exact (of_mem_filter ain) end theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset l h theorem mem_filter_of_mem {a : α} : ∀ {l}, a ∈ l → p a → a ∈ filter p l | (_::l) (or.inl rfl) pa := by rw filter_cons_of_pos _ pa; apply mem_cons_self | (b::l) (or.inr ain) pa := if pb : p b then by rw [filter_cons_of_pos _ pb]; apply mem_cons_of_mem; apply mem_filter_of_mem ain pa else by rw [filter_cons_of_neg _ pb]; apply mem_filter_of_mem ain pa @[simp] theorem mem_filter {a : α} {l} : a ∈ filter p l ↔ a ∈ l ∧ p a := ⟨λ h, ⟨mem_of_mem_filter h, of_mem_filter h⟩, λ ⟨h₁, h₂⟩, mem_filter_of_mem h₁ h₂⟩ theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a := begin induction l with a l ih, { exact iff_of_true rfl (forall_mem_nil _) }, rw forall_mem_cons, by_cases p a, { rw [filter_cons_of_pos _ h, cons_inj', ih, and_iff_right h] }, { rw [filter_cons_of_neg _ h], refine iff_of_false _ (mt and.left h), intro e, have := filter_sublist l, rw e at this, exact not_lt_of_ge (length_le_of_sublist this) (lt_succ_self _) } end theorem filter_eq_nil {l} : filter p l = [] ↔ ∀ a ∈ l, ¬p a := by simp only [eq_nil_iff_forall_not_mem, mem_filter, not_and] theorem filter_sublist_filter {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ := by rw ← filter_map_eq_filter; exact filter_map_sublist_filter_map _ s theorem filter_of_map (f : β → α) (l) : filter p (map f l) = map f (filter (p ∘ f) l) := by rw [← filter_map_eq_map, filter_filter_map, filter_map_filter]; refl @[simp] theorem filter_filter {q} [decidable_pred q] : ∀ l, filter p (filter q l) = filter (λ a, p a ∧ q a) l | [] := rfl | (a :: l) := by by_cases hp : p a; by_cases hq : q a; simp only [hp, hq, filter, if_true, if_false, true_and, false_and, filter_filter l, eq_self_iff_true] @[simp] lemma filter_true {h : decidable_pred (λ a : α, true)} (l : list α) : @filter α (λ _, true) h l = l := by convert filter_eq_self.2 (λ _ _, trivial) @[simp] lemma filter_false {h : decidable_pred (λ a : α, false)} (l : list α) : @filter α (λ _, false) h l = [] := by convert filter_eq_nil.2 (λ _ _, id) @[simp] theorem span_eq_take_drop (p : α → Prop) [decidable_pred p] : ∀ (l : list α), span p l = (take_while p l, drop_while p l) | [] := rfl | (a::l) := if pa : p a then by simp only [span, if_pos pa, span_eq_take_drop l, take_while, drop_while] else by simp only [span, take_while, drop_while, if_neg pa] @[simp] theorem take_while_append_drop (p : α → Prop) [decidable_pred p] : ∀ (l : list α), take_while p l ++ drop_while p l = l | [] := rfl | (a::l) := if pa : p a then by rw [take_while, drop_while, if_pos pa, if_pos pa, cons_append, take_while_append_drop l] else by rw [take_while, drop_while, if_neg pa, if_neg pa, nil_append] @[simp] theorem countp_nil (p : α → Prop) [decidable_pred p] : countp p [] = 0 := rfl @[simp] theorem countp_cons_of_pos {a : α} (l) (pa : p a) : countp p (a::l) = countp p l + 1 := if_pos pa @[simp] theorem countp_cons_of_neg {a : α} (l) (pa : ¬ p a) : countp p (a::l) = countp p l := if_neg pa theorem countp_eq_length_filter (l) : countp p l = length (filter p l) := by induction l with x l ih; [refl, by_cases (p x)]; [simp only [filter_cons_of_pos _ h, countp, ih, if_pos h], simp only [countp_cons_of_neg _ h, ih, filter_cons_of_neg _ h]]; refl local attribute [simp] countp_eq_length_filter @[simp] theorem countp_append (l₁ l₂) : countp p (l₁ ++ l₂) = countp p l₁ + countp p l₂ := by simp only [countp_eq_length_filter, filter_append, length_append] theorem countp_pos {l} : 0 < countp p l ↔ ∃ a ∈ l, p a := by simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop] theorem countp_le_of_sublist {l₁ l₂} (s : l₁ <+ l₂) : countp p l₁ ≤ countp p l₂ := by simpa only [countp_eq_length_filter] using length_le_of_sublist (filter_sublist_filter s) @[simp] theorem countp_filter {q} [decidable_pred q] (l : list α) : countp p (filter q l) = countp (λ a, p a ∧ q a) l := by simp only [countp_eq_length_filter, filter_filter] end filter /- count -/ section count variable [decidable_eq α] @[simp] theorem count_nil (a : α) : count a [] = 0 := rfl theorem count_cons (a b : α) (l : list α) : count a (b :: l) = if a = b then succ (count a l) else count a l := rfl theorem count_cons' (a b : α) (l : list α) : count a (b :: l) = count a l + (if a = b then 1 else 0) := begin rw count_cons, split_ifs; refl end @[simp] theorem count_cons_self (a : α) (l : list α) : count a (a::l) = succ (count a l) := if_pos rfl @[simp] theorem count_cons_of_ne {a b : α} (h : a ≠ b) (l : list α) : count a (b::l) = count a l := if_neg h theorem count_tail : Π (l : list α) (a : α) (h : 0 < l.length), l.tail.count a = l.count a - ite (a = list.nth_le l 0 h) 1 0 | (_ :: _) a h := by { rw [count_cons], split_ifs; simp } theorem count_le_of_sublist (a : α) {l₁ l₂} : l₁ <+ l₂ → count a l₁ ≤ count a l₂ := countp_le_of_sublist theorem count_le_count_cons (a b : α) (l : list α) : count a l ≤ count a (b :: l) := count_le_of_sublist _ (sublist_cons _ _) theorem count_singleton (a : α) : count a [a] = 1 := if_pos rfl @[simp] theorem count_append (a : α) : ∀ l₁ l₂, count a (l₁ ++ l₂) = count a l₁ + count a l₂ := countp_append @[simp] theorem count_concat (a : α) (l : list α) : count a (concat l a) = succ (count a l) := by rw [concat_eq_append, count_append, count_singleton] theorem count_pos {a : α} {l : list α} : 0 < count a l ↔ a ∈ l := by simp only [count, countp_pos, exists_prop, exists_eq_right'] @[simp] theorem count_eq_zero_of_not_mem {a : α} {l : list α} (h : a ∉ l) : count a l = 0 := by_contradiction $ λ h', h $ count_pos.1 (nat.pos_of_ne_zero h') theorem not_mem_of_count_eq_zero {a : α} {l : list α} (h : count a l = 0) : a ∉ l := λ h', ne_of_gt (count_pos.2 h') h @[simp] theorem count_repeat (a : α) (n : ℕ) : count a (repeat a n) = n := by rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat]; exact λ b m, (eq_of_mem_repeat m).symm theorem le_count_iff_repeat_sublist {a : α} {l : list α} {n : ℕ} : n ≤ count a l ↔ repeat a n <+ l := ⟨λ h, ((repeat_sublist_repeat a).2 h).trans $ have filter (eq a) l = repeat a (count a l), from eq_repeat.2 ⟨by simp only [count, countp_eq_length_filter], λ b m, (of_mem_filter m).symm⟩, by rw ← this; apply filter_sublist, λ h, by simpa only [count_repeat] using count_le_of_sublist a h⟩ @[simp] theorem count_filter {p} [decidable_pred p] {a} {l : list α} (h : p a) : count a (filter p l) = count a l := by simp only [count, countp_filter]; congr; exact set.ext (λ b, and_iff_left_of_imp (λ e, e ▸ h)) end count /- prefix, suffix, infix -/ @[simp] theorem prefix_append (l₁ l₂ : list α) : l₁ <+: l₁ ++ l₂ := ⟨l₂, rfl⟩ @[simp] theorem suffix_append (l₁ l₂ : list α) : l₂ <:+ l₁ ++ l₂ := ⟨l₁, rfl⟩ @[simp] theorem infix_append (l₁ l₂ l₃ : list α) : l₂ <:+: l₁ ++ l₂ ++ l₃ := ⟨l₁, l₃, rfl⟩ theorem nil_prefix (l : list α) : [] <+: l := ⟨l, rfl⟩ theorem nil_suffix (l : list α) : [] <:+ l := ⟨l, append_nil _⟩ @[refl] theorem prefix_refl (l : list α) : l <+: l := ⟨[], append_nil _⟩ @[refl] theorem suffix_refl (l : list α) : l <:+ l := ⟨[], rfl⟩ @[simp] theorem suffix_cons (a : α) : ∀ l, l <:+ a :: l := suffix_append [a] @[simp] theorem prefix_concat (a : α) (l) : l <+: concat l a := by simp only [concat_eq_append, prefix_append] theorem infix_of_prefix {l₁ l₂ : list α} : l₁ <+: l₂ → l₁ <:+: l₂ := λ⟨t, h⟩, ⟨[], t, h⟩ theorem infix_of_suffix {l₁ l₂ : list α} : l₁ <:+ l₂ → l₁ <:+: l₂ := λ⟨t, h⟩, ⟨t, [], by simp only [h, append_nil]⟩ @[refl] theorem infix_refl (l : list α) : l <:+: l := infix_of_prefix $ prefix_refl l theorem nil_infix (l : list α) : [] <:+: l := infix_of_prefix $ nil_prefix l theorem infix_cons {L₁ L₂ : list α} {x : α} : L₁ <:+: L₂ → L₁ <:+: x :: L₂ := λ⟨LP, LS, H⟩, ⟨x :: LP, LS, H ▸ rfl⟩ @[trans] theorem is_prefix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <+: l₂ → l₂ <+: l₃ → l₁ <+: l₃ | l ._ ._ ⟨r₁, rfl⟩ ⟨r₂, rfl⟩ := ⟨r₁ ++ r₂, (append_assoc _ _ _).symm⟩ @[trans] theorem is_suffix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+ l₂ → l₂ <:+ l₃ → l₁ <:+ l₃ | l ._ ._ ⟨l₁, rfl⟩ ⟨l₂, rfl⟩ := ⟨l₂ ++ l₁, append_assoc _ _ _⟩ @[trans] theorem is_infix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+: l₂ → l₂ <:+: l₃ → l₁ <:+: l₃ | l ._ ._ ⟨l₁, r₁, rfl⟩ ⟨l₂, r₂, rfl⟩ := ⟨l₂ ++ l₁, r₁ ++ r₂, by simp only [append_assoc]⟩ theorem sublist_of_infix {l₁ l₂ : list α} : l₁ <:+: l₂ → l₁ <+ l₂ := λ⟨s, t, h⟩, by rw [← h]; exact (sublist_append_right _ _).trans (sublist_append_left _ _) theorem sublist_of_prefix {l₁ l₂ : list α} : l₁ <+: l₂ → l₁ <+ l₂ := sublist_of_infix ∘ infix_of_prefix theorem sublist_of_suffix {l₁ l₂ : list α} : l₁ <:+ l₂ → l₁ <+ l₂ := sublist_of_infix ∘ infix_of_suffix theorem reverse_suffix {l₁ l₂ : list α} : reverse l₁ <:+ reverse l₂ ↔ l₁ <+: l₂ := ⟨λ ⟨r, e⟩, ⟨reverse r, by rw [← reverse_reverse l₁, ← reverse_append, e, reverse_reverse]⟩, λ ⟨r, e⟩, ⟨reverse r, by rw [← reverse_append, e]⟩⟩ theorem reverse_prefix {l₁ l₂ : list α} : reverse l₁ <+: reverse l₂ ↔ l₁ <:+ l₂ := by rw ← reverse_suffix; simp only [reverse_reverse] theorem length_le_of_infix {l₁ l₂ : list α} (s : l₁ <:+: l₂) : length l₁ ≤ length l₂ := length_le_of_sublist $ sublist_of_infix s theorem eq_nil_of_infix_nil {l : list α} (s : l <:+: []) : l = [] := eq_nil_of_sublist_nil $ sublist_of_infix s theorem eq_nil_of_prefix_nil {l : list α} (s : l <+: []) : l = [] := eq_nil_of_infix_nil $ infix_of_prefix s theorem eq_nil_of_suffix_nil {l : list α} (s : l <:+ []) : l = [] := eq_nil_of_infix_nil $ infix_of_suffix s theorem infix_iff_prefix_suffix (l₁ l₂ : list α) : l₁ <:+: l₂ ↔ ∃ t, l₁ <+: t ∧ t <:+ l₂ := ⟨λ⟨s, t, e⟩, ⟨l₁ ++ t, ⟨_, rfl⟩, by rw [← e, append_assoc]; exact ⟨_, rfl⟩⟩, λ⟨._, ⟨t, rfl⟩, ⟨s, e⟩⟩, ⟨s, t, by rw append_assoc; exact e⟩⟩ theorem eq_of_infix_of_length_eq {l₁ l₂ : list α} (s : l₁ <:+: l₂) : length l₁ = length l₂ → l₁ = l₂ := eq_of_sublist_of_length_eq $ sublist_of_infix s theorem eq_of_prefix_of_length_eq {l₁ l₂ : list α} (s : l₁ <+: l₂) : length l₁ = length l₂ → l₁ = l₂ := eq_of_sublist_of_length_eq $ sublist_of_prefix s theorem eq_of_suffix_of_length_eq {l₁ l₂ : list α} (s : l₁ <:+ l₂) : length l₁ = length l₂ → l₁ = l₂ := eq_of_sublist_of_length_eq $ sublist_of_suffix s theorem prefix_of_prefix_length_le : ∀ {l₁ l₂ l₃ : list α}, l₁ <+: l₃ → l₂ <+: l₃ → length l₁ ≤ length l₂ → l₁ <+: l₂ | [] l₂ l₃ h₁ h₂ _ := nil_prefix _ | (a::l₁) (b::l₂) _ ⟨r₁, rfl⟩ ⟨r₂, e⟩ ll := begin injection e with _ e', subst b, rcases prefix_of_prefix_length_le ⟨_, rfl⟩ ⟨_, e'⟩ (le_of_succ_le_succ ll) with ⟨r₃, rfl⟩, exact ⟨r₃, rfl⟩ end theorem prefix_or_prefix_of_prefix {l₁ l₂ l₃ : list α} (h₁ : l₁ <+: l₃) (h₂ : l₂ <+: l₃) : l₁ <+: l₂ ∨ l₂ <+: l₁ := (le_total (length l₁) (length l₂)).imp (prefix_of_prefix_length_le h₁ h₂) (prefix_of_prefix_length_le h₂ h₁) theorem suffix_of_suffix_length_le {l₁ l₂ l₃ : list α} (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) (ll : length l₁ ≤ length l₂) : l₁ <:+ l₂ := reverse_prefix.1 $ prefix_of_prefix_length_le (reverse_prefix.2 h₁) (reverse_prefix.2 h₂) (by simp [ll]) theorem suffix_or_suffix_of_suffix {l₁ l₂ l₃ : list α} (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) : l₁ <:+ l₂ ∨ l₂ <:+ l₁ := (prefix_or_prefix_of_prefix (reverse_prefix.2 h₁) (reverse_prefix.2 h₂)).imp reverse_prefix.1 reverse_prefix.1 theorem infix_of_mem_join : ∀ {L : list (list α)} {l}, l ∈ L → l <:+: join L | (_ :: L) l (or.inl rfl) := infix_append [] _ _ | (l' :: L) l (or.inr h) := is_infix.trans (infix_of_mem_join h) $ infix_of_suffix $ suffix_append _ _ theorem prefix_append_left_inj {l₁ l₂ : list α} (l) : l ++ l₁ <+: l ++ l₂ ↔ l₁ <+: l₂ := exists_congr $ λ r, by rw [append_assoc, append_left_inj] theorem prefix_cons_inj {l₁ l₂ : list α} (a) : a :: l₁ <+: a :: l₂ ↔ l₁ <+: l₂ := prefix_append_left_inj [a] theorem take_prefix (n) (l : list α) : take n l <+: l := ⟨_, take_append_drop _ _⟩ theorem drop_suffix (n) (l : list α) : drop n l <:+ l := ⟨_, take_append_drop _ _⟩ theorem prefix_iff_eq_append {l₁ l₂ : list α} : l₁ <+: l₂ ↔ l₁ ++ drop (length l₁) l₂ = l₂ := ⟨by rintros ⟨r, rfl⟩; rw drop_left, λ e, ⟨_, e⟩⟩ theorem suffix_iff_eq_append {l₁ l₂ : list α} : l₁ <:+ l₂ ↔ take (length l₂ - length l₁) l₂ ++ l₁ = l₂ := ⟨by rintros ⟨r, rfl⟩; simp only [length_append, nat.add_sub_cancel, take_left], λ e, ⟨_, e⟩⟩ theorem prefix_iff_eq_take {l₁ l₂ : list α} : l₁ <+: l₂ ↔ l₁ = take (length l₁) l₂ := ⟨λ h, append_right_cancel $ (prefix_iff_eq_append.1 h).trans (take_append_drop _ _).symm, λ e, e.symm ▸ take_prefix _ _⟩ theorem suffix_iff_eq_drop {l₁ l₂ : list α} : l₁ <:+ l₂ ↔ l₁ = drop (length l₂ - length l₁) l₂ := ⟨λ h, append_left_cancel $ (suffix_iff_eq_append.1 h).trans (take_append_drop _ _).symm, λ e, e.symm ▸ drop_suffix _ _⟩ instance decidable_prefix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <+: l₂) | [] l₂ := is_true ⟨l₂, rfl⟩ | (a::l₁) [] := is_false $ λ ⟨t, te⟩, list.no_confusion te | (a::l₁) (b::l₂) := if h : a = b then @decidable_of_iff _ _ (by rw [← h, prefix_cons_inj]) (decidable_prefix l₁ l₂) else is_false $ λ ⟨t, te⟩, h $ by injection te -- Alternatively, use mem_tails instance decidable_suffix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+ l₂) | [] l₂ := is_true ⟨l₂, append_nil _⟩ | (a::l₁) [] := is_false $ mt (length_le_of_sublist ∘ sublist_of_suffix) dec_trivial | l₁ l₂ := let len1 := length l₁, len2 := length l₂ in if hl : len1 ≤ len2 then decidable_of_iff' (l₁ = drop (len2-len1) l₂) suffix_iff_eq_drop else is_false $ λ h, hl $ length_le_of_sublist $ sublist_of_suffix h @[simp] theorem mem_inits : ∀ (s t : list α), s ∈ inits t ↔ s <+: t | s [] := suffices s = nil ↔ s <+: nil, by simpa only [inits, mem_singleton], ⟨λh, h.symm ▸ prefix_refl [], eq_nil_of_prefix_nil⟩ | s (a::t) := suffices (s = nil ∨ ∃ l ∈ inits t, a :: l = s) ↔ s <+: a :: t, by simpa, ⟨λo, match s, o with | ._, or.inl rfl := ⟨_, rfl⟩ | s, or.inr ⟨r, hr, hs⟩ := let ⟨s, ht⟩ := (mem_inits _ _).1 hr in by rw [← hs, ← ht]; exact ⟨s, rfl⟩ end, λmi, match s, mi with | [], ⟨._, rfl⟩ := or.inl rfl | (b::s), ⟨r, hr⟩ := list.no_confusion hr $ λba (st : s++r = t), or.inr $ by rw ba; exact ⟨_, (mem_inits _ _).2 ⟨_, st⟩, rfl⟩ end⟩ @[simp] theorem mem_tails : ∀ (s t : list α), s ∈ tails t ↔ s <:+ t | s [] := by simp only [tails, mem_singleton]; exact ⟨λh, by rw h; exact suffix_refl [], eq_nil_of_suffix_nil⟩ | s (a::t) := by simp only [tails, mem_cons_iff, mem_tails s t]; exact show s = a :: t ∨ s <:+ t ↔ s <:+ a :: t, from ⟨λo, match s, t, o with | ._, t, or.inl rfl := suffix_refl _ | s, ._, or.inr ⟨l, rfl⟩ := ⟨a::l, rfl⟩ end, λe, match s, t, e with | ._, t, ⟨[], rfl⟩ := or.inl rfl | s, t, ⟨b::l, he⟩ := list.no_confusion he (λab lt, or.inr ⟨l, lt⟩) end⟩ instance decidable_infix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+: l₂) | [] l₂ := is_true ⟨[], l₂, rfl⟩ | (a::l₁) [] := is_false $ λ⟨s, t, te⟩, absurd te $ append_ne_nil_of_ne_nil_left _ _ $ append_ne_nil_of_ne_nil_right _ _ $ λh, list.no_confusion h | l₁ l₂ := decidable_of_decidable_of_iff (list.decidable_bex (λt, l₁ <+: t) (tails l₂)) $ by refine (exists_congr (λt, _)).trans (infix_iff_prefix_suffix _ _).symm; exact ⟨λ⟨h1, h2⟩, ⟨h2, (mem_tails _ _).1 h1⟩, λ⟨h2, h1⟩, ⟨(mem_tails _ _).2 h1, h2⟩⟩ /- sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl theorem map_sublists'_aux (g : list β → list γ) (l : list α) (f r) : map g (sublists'_aux l f r) = sublists'_aux l (g ∘ f) (map g r) := by induction l generalizing f r; [refl, simp only [*, sublists'_aux]] theorem sublists'_aux_append (r' : list (list β)) (l : list α) (f r) : sublists'_aux l f (r ++ r') = sublists'_aux l f r ++ r' := by induction l generalizing f r; [refl, simp only [*, sublists'_aux]] theorem sublists'_aux_eq_sublists' (l f r) : @sublists'_aux α β l f r = map f (sublists' l) ++ r := by rw [sublists', map_sublists'_aux, ← sublists'_aux_append]; refl @[simp] theorem sublists'_cons (a : α) (l : list α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by rw [sublists', sublists'_aux]; simp only [sublists'_aux_eq_sublists', map_id, append_nil]; refl @[simp] theorem mem_sublists' {s t : list α} : s ∈ sublists' t ↔ s <+ t := begin induction t with a t IH generalizing s, { simp only [sublists'_nil, mem_singleton], exact ⟨λ h, by rw h, eq_nil_of_sublist_nil⟩ }, simp only [sublists'_cons, mem_append, IH, mem_map], split; intro h, rcases h with h | ⟨s, h, rfl⟩, { exact sublist_cons_of_sublist _ h }, { exact cons_sublist_cons _ h }, { cases h with _ _ _ h s _ _ h, { exact or.inl h }, { exact or.inr ⟨s, h, rfl⟩ } } end @[simp] theorem length_sublists' : ∀ l : list α, length (sublists' l) = 2 ^ length l | [] := rfl | (a::l) := by simp only [sublists'_cons, length_append, length_sublists' l, length_map, length, pow_succ, mul_succ, mul_zero, zero_add] @[simp] theorem sublists_nil : sublists (@nil α) = [[]] := rfl @[simp] theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] := rfl theorem sublists_aux₁_eq_sublists_aux : ∀ l (f : list α → list β), sublists_aux₁ l f = sublists_aux l (λ ys r, f ys ++ r) | [] f := rfl | (a::l) f := by rw [sublists_aux₁, sublists_aux]; simp only [*, append_assoc] theorem sublists_aux_cons_eq_sublists_aux₁ (l : list α) : sublists_aux l cons = sublists_aux₁ l (λ x, [x]) := by rw [sublists_aux₁_eq_sublists_aux]; refl theorem sublists_aux_eq_foldr.aux {a : α} {l : list α} (IH₁ : ∀ (f : list α → list β → list β), sublists_aux l f = foldr f [] (sublists_aux l cons)) (IH₂ : ∀ (f : list α → list (list α) → list (list α)), sublists_aux l f = foldr f [] (sublists_aux l cons)) (f : list α → list β → list β) : sublists_aux (a::l) f = foldr f [] (sublists_aux (a::l) cons) := begin simp only [sublists_aux, foldr_cons], rw [IH₂, IH₁], congr' 1, induction sublists_aux l cons with _ _ ih, {refl}, simp only [ih, foldr_cons] end theorem sublists_aux_eq_foldr (l : list α) : ∀ (f : list α → list β → list β), sublists_aux l f = foldr f [] (sublists_aux l cons) := suffices _ ∧ ∀ f : list α → list (list α) → list (list α), sublists_aux l f = foldr f [] (sublists_aux l cons), from this.1, begin induction l with a l IH, {split; intro; refl}, exact ⟨sublists_aux_eq_foldr.aux IH.1 IH.2, sublists_aux_eq_foldr.aux IH.2 IH.2⟩ end theorem sublists_aux_cons_cons (l : list α) (a : α) : sublists_aux (a::l) cons = [a] :: foldr (λys r, ys :: (a :: ys) :: r) [] (sublists_aux l cons) := by rw [← sublists_aux_eq_foldr]; refl theorem sublists_aux₁_append : ∀ (l₁ l₂ : list α) (f : list α → list β), sublists_aux₁ (l₁ ++ l₂) f = sublists_aux₁ l₁ f ++ sublists_aux₁ l₂ (λ x, f x ++ sublists_aux₁ l₁ (f ∘ (++ x))) | [] l₂ f := by simp only [sublists_aux₁, nil_append, append_nil] | (a::l₁) l₂ f := by simp only [sublists_aux₁, cons_append, sublists_aux₁_append l₁, append_assoc]; refl theorem sublists_aux₁_concat (l : list α) (a : α) (f : list α → list β) : sublists_aux₁ (l ++ [a]) f = sublists_aux₁ l f ++ f [a] ++ sublists_aux₁ l (λ x, f (x ++ [a])) := by simp only [sublists_aux₁_append, sublists_aux₁, append_assoc, append_nil] theorem sublists_aux₁_bind : ∀ (l : list α) (f : list α → list β) (g : β → list γ), (sublists_aux₁ l f).bind g = sublists_aux₁ l (λ x, (f x).bind g) | [] f g := rfl | (a::l) f g := by simp only [sublists_aux₁, bind_append, sublists_aux₁_bind l] theorem sublists_aux_cons_append (l₁ l₂ : list α) : sublists_aux (l₁ ++ l₂) cons = sublists_aux l₁ cons ++ (do x ← sublists_aux l₂ cons, (++ x) <$> sublists l₁) := begin simp only [sublists, sublists_aux_cons_eq_sublists_aux₁, sublists_aux₁_append, bind_eq_bind, sublists_aux₁_bind], congr, funext x, apply congr_arg _, rw [← bind_ret_eq_map, sublists_aux₁_bind], exact (append_nil _).symm end theorem sublists_append (l₁ l₂ : list α) : sublists (l₁ ++ l₂) = (do x ← sublists l₂, (++ x) <$> sublists l₁) := by simp only [map, sublists, sublists_aux_cons_append, map_eq_map, bind_eq_bind, cons_bind, map_id', append_nil, cons_append, map_id' (λ _, rfl)]; split; refl @[simp] theorem sublists_concat (l : list α) (a : α) : sublists (l ++ [a]) = sublists l ++ map (λ x, x ++ [a]) (sublists l) := by rw [sublists_append, sublists_singleton, bind_eq_bind, cons_bind, cons_bind, nil_bind, map_eq_map, map_eq_map, map_id' (append_nil), append_nil] theorem sublists_reverse (l : list α) : sublists (reverse l) = map reverse (sublists' l) := by induction l with hd tl ih; [refl, simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton, map_eq_map, bind_eq_bind, map_map, cons_bind, append_nil, nil_bind, (∘)]] theorem sublists_eq_sublists' (l : list α) : sublists l = map reverse (sublists' (reverse l)) := by rw [← sublists_reverse, reverse_reverse] theorem sublists'_reverse (l : list α) : sublists' (reverse l) = map reverse (sublists l) := by simp only [sublists_eq_sublists', map_map, map_id' (reverse_reverse)] theorem sublists'_eq_sublists (l : list α) : sublists' l = map reverse (sublists (reverse l)) := by rw [← sublists'_reverse, reverse_reverse] theorem sublists_aux_ne_nil : ∀ (l : list α), [] ∉ sublists_aux l cons | [] := id | (a::l) := begin rw [sublists_aux_cons_cons], refine not_mem_cons_of_ne_of_not_mem (cons_ne_nil _ _).symm _, have := sublists_aux_ne_nil l, revert this, induction sublists_aux l cons; intro, {rwa foldr}, simp only [foldr, mem_cons_iff, false_or, not_or_distrib], exact ⟨ne_of_not_mem_cons this, ih (not_mem_of_not_mem_cons this)⟩ end @[simp] theorem mem_sublists {s t : list α} : s ∈ sublists t ↔ s <+ t := by rw [← reverse_sublist_iff, ← mem_sublists', sublists'_reverse, mem_map_of_inj reverse_injective] @[simp] theorem length_sublists (l : list α) : length (sublists l) = 2 ^ length l := by simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse] theorem map_ret_sublist_sublists (l : list α) : map list.ret l <+ sublists l := reverse_rec_on l (nil_sublist _) $ λ l a IH, by simp only [map, map_append, sublists_concat]; exact ((append_sublist_append_left _).2 $ singleton_sublist.2 $ mem_map.2 ⟨[], mem_sublists.2 (nil_sublist _), by refl⟩).trans ((append_sublist_append_right _).2 IH) /- sublists_len -/ def sublists_len_aux {α β : Type*} : ℕ → list α → (list α → β) → list β → list β | 0 l f r := f [] :: r | (n+1) [] f r := r | (n+1) (a::l) f r := sublists_len_aux (n + 1) l f (sublists_len_aux n l (f ∘ list.cons a) r) def sublists_len {α : Type*} (n : ℕ) (l : list α) : list (list α) := sublists_len_aux n l id [] lemma sublists_len_aux_append {α β γ : Type*} : ∀ (n : ℕ) (l : list α) (f : list α → β) (g : β → γ) (r : list β) (s : list γ), sublists_len_aux n l (g ∘ f) (r.map g ++ s) = (sublists_len_aux n l f r).map g ++ s | 0 l f g r s := rfl | (n+1) [] f g r s := rfl | (n+1) (a::l) f g r s := begin unfold sublists_len_aux, rw [show ((g ∘ f) ∘ list.cons a) = (g ∘ f ∘ list.cons a), by refl, sublists_len_aux_append, sublists_len_aux_append] end lemma sublists_len_aux_eq {α β : Type*} (l : list α) (n) (f : list α → β) (r) : sublists_len_aux n l f r = (sublists_len n l).map f ++ r := by rw [sublists_len, ← sublists_len_aux_append]; refl lemma sublists_len_aux_zero {α : Type*} (l : list α) (f : list α → β) (r) : sublists_len_aux 0 l f r = f [] :: r := by cases l; refl @[simp] lemma sublists_len_zero {α : Type*} (l : list α) : sublists_len 0 l = [[]] := sublists_len_aux_zero _ _ _ @[simp] lemma sublists_len_succ_nil {α : Type*} (n) : sublists_len (n+1) (@nil α) = [] := rfl @[simp] lemma sublists_len_succ_cons {α : Type*} (n) (a : α) (l) : sublists_len (n + 1) (a::l) = sublists_len (n + 1) l ++ (sublists_len n l).map (cons a) := by rw [sublists_len, sublists_len_aux, sublists_len_aux_eq, sublists_len_aux_eq, map_id, append_nil]; refl @[simp] lemma length_sublists_len {α : Type*} : ∀ n (l : list α), length (sublists_len n l) = nat.choose (length l) n | 0 l := by simp | (n+1) [] := by simp | (n+1) (a::l) := by simp [-add_comm, nat.choose, *]; apply add_comm lemma sublists_len_sublist_sublists' {α : Type*} : ∀ n (l : list α), sublists_len n l <+ sublists' l | 0 l := singleton_sublist.2 (mem_sublists'.2 (nil_sublist _)) | (n+1) [] := nil_sublist _ | (n+1) (a::l) := begin rw [sublists_len_succ_cons, sublists'_cons], exact append_sublist_append (sublists_len_sublist_sublists' _ _) (map_sublist_map _ (sublists_len_sublist_sublists' _ _)) end lemma sublists_len_sublist_of_sublist {α : Type*} (n) {l₁ l₂ : list α} (h : l₁ <+ l₂) : sublists_len n l₁ <+ sublists_len n l₂ := begin induction n with n IHn generalizing l₁ l₂, {simp}, induction h with l₁ l₂ a s IH l₁ l₂ a s IH, {refl}, { refine IH.trans _, rw sublists_len_succ_cons, apply sublist_append_left }, { simp [sublists_len_succ_cons], exact append_sublist_append IH (map_sublist_map _ (IHn s)) } end lemma length_of_sublists_len {α : Type*} : ∀ {n} {l l' : list α}, l' ∈ sublists_len n l → length l' = n | 0 l l' (or.inl rfl) := rfl | (n+1) (a::l) l' h := begin rw [sublists_len_succ_cons, mem_append, mem_map] at h, rcases h with h | ⟨l', h, rfl⟩, { exact length_of_sublists_len h }, { exact congr_arg (+1) (length_of_sublists_len h) }, end lemma mem_sublists_len_self {α : Type*} {l l' : list α} (h : l' <+ l) : l' ∈ sublists_len (length l') l := begin induction h with l₁ l₂ a s IH l₁ l₂ a s IH, { exact or.inl rfl }, { cases l₁ with b l₁, { exact or.inl rfl }, { rw [length, sublists_len_succ_cons], exact mem_append_left _ IH } }, { rw [length, sublists_len_succ_cons], exact mem_append_right _ (mem_map.2 ⟨_, IH, rfl⟩) } end @[simp] lemma mem_sublists_len {α : Type*} {n} {l l' : list α} : l' ∈ sublists_len n l ↔ l' <+ l ∧ length l' = n := ⟨λ h, ⟨mem_sublists'.1 (subset_of_sublist (sublists_len_sublist_sublists' _ _) h), length_of_sublists_len h⟩, λ ⟨h₁, h₂⟩, h₂ ▸ mem_sublists_len_self h₁⟩ /- forall₂ -/ section forall₂ variables {r : α → β → Prop} {p : γ → δ → Prop} open relator run_cmd tactic.mk_iff_of_inductive_prop `list.forall₂ `list.forall₂_iff @[simp] theorem forall₂_cons {R : α → β → Prop} {a b l₁ l₂} : forall₂ R (a::l₁) (b::l₂) ↔ R a b ∧ forall₂ R l₁ l₂ := ⟨λ h, by cases h with h₁ h₂; split; assumption, λ ⟨h₁, h₂⟩, forall₂.cons h₁ h₂⟩ theorem forall₂.imp {R S : α → β → Prop} (H : ∀ a b, R a b → S a b) {l₁ l₂} (h : forall₂ R l₁ l₂) : forall₂ S l₁ l₂ := by induction h; constructor; solve_by_elim lemma forall₂.mp {r q s : α → β → Prop} (h : ∀a b, r a b → q a b → s a b) : ∀{l₁ l₂}, forall₂ r l₁ l₂ → forall₂ q l₁ l₂ → forall₂ s l₁ l₂ | [] [] forall₂.nil forall₂.nil := forall₂.nil | (a::l₁) (b::l₂) (forall₂.cons hr hrs) (forall₂.cons hq hqs) := forall₂.cons (h a b hr hq) (forall₂.mp hrs hqs) lemma forall₂.flip : ∀{a b}, forall₂ (flip r) b a → forall₂ r a b | _ _ forall₂.nil := forall₂.nil | (a :: as) (b :: bs) (forall₂.cons h₁ h₂) := forall₂.cons h₁ h₂.flip lemma forall₂_same {r : α → α → Prop} : ∀{l}, (∀x∈l, r x x) → forall₂ r l l | [] _ := forall₂.nil | (a::as) h := forall₂.cons (h _ (mem_cons_self _ _)) (forall₂_same $ assume a ha, h a $ mem_cons_of_mem _ ha) lemma forall₂_refl {r} [is_refl α r] (l : list α) : forall₂ r l l := forall₂_same $ assume a h, is_refl.refl _ _ lemma forall₂_eq_eq_eq : forall₂ ((=) : α → α → Prop) = (=) := begin funext a b, apply propext, split, { assume h, induction h, {refl}, simp only [*]; split; refl }, { assume h, subst h, exact forall₂_refl _ } end @[simp] lemma forall₂_nil_left_iff {l} : forall₂ r nil l ↔ l = nil := ⟨λ H, by cases H; refl, by rintro rfl; exact forall₂.nil⟩ @[simp] lemma forall₂_nil_right_iff {l} : forall₂ r l nil ↔ l = nil := ⟨λ H, by cases H; refl, by rintro rfl; exact forall₂.nil⟩ lemma forall₂_cons_left_iff {a l u} : forall₂ r (a::l) u ↔ (∃b u', r a b ∧ forall₂ r l u' ∧ u = b :: u') := iff.intro (assume h, match u, h with (b :: u'), forall₂.cons h₁ h₂ := ⟨b, u', h₁, h₂, rfl⟩ end) (assume h, match u, h with _, ⟨b, u', h₁, h₂, rfl⟩ := forall₂.cons h₁ h₂ end) lemma forall₂_cons_right_iff {b l u} : forall₂ r u (b::l) ↔ (∃a u', r a b ∧ forall₂ r u' l ∧ u = a :: u') := iff.intro (assume h, match u, h with (b :: u'), forall₂.cons h₁ h₂ := ⟨b, u', h₁, h₂, rfl⟩ end) (assume h, match u, h with _, ⟨b, u', h₁, h₂, rfl⟩ := forall₂.cons h₁ h₂ end) lemma forall₂_and_left {r : α → β → Prop} {p : α → Prop} : ∀l u, forall₂ (λa b, p a ∧ r a b) l u ↔ (∀a∈l, p a) ∧ forall₂ r l u | [] u := by simp only [forall₂_nil_left_iff, forall_prop_of_false (not_mem_nil _), imp_true_iff, true_and] | (a::l) u := by simp only [forall₂_and_left l, forall₂_cons_left_iff, forall_mem_cons, and_assoc, and_comm, and.left_comm, exists_and_distrib_left.symm] @[simp] lemma forall₂_map_left_iff {f : γ → α} : ∀{l u}, forall₂ r (map f l) u ↔ forall₂ (λc b, r (f c) b) l u | [] _ := by simp only [map, forall₂_nil_left_iff] | (a::l) _ := by simp only [map, forall₂_cons_left_iff, forall₂_map_left_iff] @[simp] lemma forall₂_map_right_iff {f : γ → β} : ∀{l u}, forall₂ r l (map f u) ↔ forall₂ (λa c, r a (f c)) l u | _ [] := by simp only [map, forall₂_nil_right_iff] | _ (b::u) := by simp only [map, forall₂_cons_right_iff, forall₂_map_right_iff] lemma left_unique_forall₂ (hr : left_unique r) : left_unique (forall₂ r) | a₀ nil a₁ forall₂.nil forall₂.nil := rfl | (a₀::l₀) (b::l) (a₁::l₁) (forall₂.cons ha₀ h₀) (forall₂.cons ha₁ h₁) := hr ha₀ ha₁ ▸ left_unique_forall₂ h₀ h₁ ▸ rfl lemma right_unique_forall₂ (hr : right_unique r) : right_unique (forall₂ r) | nil a₀ a₁ forall₂.nil forall₂.nil := rfl | (b::l) (a₀::l₀) (a₁::l₁) (forall₂.cons ha₀ h₀) (forall₂.cons ha₁ h₁) := hr ha₀ ha₁ ▸ right_unique_forall₂ h₀ h₁ ▸ rfl lemma bi_unique_forall₂ (hr : bi_unique r) : bi_unique (forall₂ r) := ⟨assume a b c, left_unique_forall₂ hr.1, assume a b c, right_unique_forall₂ hr.2⟩ theorem forall₂_length_eq {R : α → β → Prop} : ∀ {l₁ l₂}, forall₂ R l₁ l₂ → length l₁ = length l₂ | _ _ forall₂.nil := rfl | _ _ (forall₂.cons h₁ h₂) := congr_arg succ (forall₂_length_eq h₂) theorem forall₂_zip {R : α → β → Prop} : ∀ {l₁ l₂}, forall₂ R l₁ l₂ → ∀ {a b}, (a, b) ∈ zip l₁ l₂ → R a b | _ _ (forall₂.cons h₁ h₂) x y (or.inl rfl) := h₁ | _ _ (forall₂.cons h₁ h₂) x y (or.inr h₃) := forall₂_zip h₂ h₃ theorem forall₂_iff_zip {R : α → β → Prop} {l₁ l₂} : forall₂ R l₁ l₂ ↔ length l₁ = length l₂ ∧ ∀ {a b}, (a, b) ∈ zip l₁ l₂ → R a b := ⟨λ h, ⟨forall₂_length_eq h, @forall₂_zip _ _ _ _ _ h⟩, λ h, begin cases h with h₁ h₂, induction l₁ with a l₁ IH generalizing l₂, { cases length_eq_zero.1 h₁.symm, constructor }, { cases l₂ with b l₂; injection h₁ with h₁, exact forall₂.cons (h₂ $ or.inl rfl) (IH h₁ $ λ a b h, h₂ $ or.inr h) } end⟩ theorem forall₂_take {R : α → β → Prop} : ∀ n {l₁ l₂}, forall₂ R l₁ l₂ → forall₂ R (take n l₁) (take n l₂) | 0 _ _ _ := by simp only [forall₂.nil, take] | (n+1) _ _ (forall₂.nil) := by simp only [forall₂.nil, take] | (n+1) _ _ (forall₂.cons h₁ h₂) := by simp [and.intro h₁ h₂, forall₂_take n] theorem forall₂_drop {R : α → β → Prop} : ∀ n {l₁ l₂}, forall₂ R l₁ l₂ → forall₂ R (drop n l₁) (drop n l₂) | 0 _ _ h := by simp only [drop, h] | (n+1) _ _ (forall₂.nil) := by simp only [forall₂.nil, drop] | (n+1) _ _ (forall₂.cons h₁ h₂) := by simp [and.intro h₁ h₂, forall₂_drop n] theorem forall₂_take_append {R : α → β → Prop} (l : list α) (l₁ : list β) (l₂ : list β) (h : forall₂ R l (l₁ ++ l₂)) : forall₂ R (list.take (length l₁) l) l₁ := have h': forall₂ R (take (length l₁) l) (take (length l₁) (l₁ ++ l₂)), from forall₂_take (length l₁) h, by rwa [take_left] at h' theorem forall₂_drop_append {R : α → β → Prop} (l : list α) (l₁ : list β) (l₂ : list β) (h : forall₂ R l (l₁ ++ l₂)) : forall₂ R (list.drop (length l₁) l) l₂ := have h': forall₂ R (drop (length l₁) l) (drop (length l₁) (l₁ ++ l₂)), from forall₂_drop (length l₁) h, by rwa [drop_left] at h' lemma rel_mem (hr : bi_unique r) : (r ⇒ forall₂ r ⇒ iff) (∈) (∈) | a b h [] [] forall₂.nil := by simp only [not_mem_nil] | a b h (a'::as) (b'::bs) (forall₂.cons h₁ h₂) := rel_or (rel_eq hr h h₁) (rel_mem h h₂) lemma rel_map : ((r ⇒ p) ⇒ forall₂ r ⇒ forall₂ p) map map | f g h [] [] forall₂.nil := forall₂.nil | f g h (a::as) (b::bs) (forall₂.cons h₁ h₂) := forall₂.cons (h h₁) (rel_map @h h₂) lemma rel_append : (forall₂ r ⇒ forall₂ r ⇒ forall₂ r) append append | [] [] h l₁ l₂ hl := hl | (a::as) (b::bs) (forall₂.cons h₁ h₂) l₁ l₂ hl := forall₂.cons h₁ (rel_append h₂ hl) lemma rel_join : (forall₂ (forall₂ r) ⇒ forall₂ r) join join | [] [] forall₂.nil := forall₂.nil | (a::as) (b::bs) (forall₂.cons h₁ h₂) := rel_append h₁ (rel_join h₂) lemma rel_bind : (forall₂ r ⇒ (r ⇒ forall₂ p) ⇒ forall₂ p) list.bind list.bind := assume a b h₁ f g h₂, rel_join (rel_map @h₂ h₁) lemma rel_foldl : ((p ⇒ r ⇒ p) ⇒ p ⇒ forall₂ r ⇒ p) foldl foldl | f g hfg _ _ h _ _ forall₂.nil := h | f g hfg x y hxy _ _ (forall₂.cons hab hs) := rel_foldl @hfg (hfg hxy hab) hs lemma rel_foldr : ((r ⇒ p ⇒ p) ⇒ p ⇒ forall₂ r ⇒ p) foldr foldr | f g hfg _ _ h _ _ forall₂.nil := h | f g hfg x y hxy _ _ (forall₂.cons hab hs) := hfg hab (rel_foldr @hfg hxy hs) lemma rel_filter {p : α → Prop} {q : β → Prop} [decidable_pred p] [decidable_pred q] (hpq : (r ⇒ (↔)) p q) : (forall₂ r ⇒ forall₂ r) (filter p) (filter q) | _ _ forall₂.nil := forall₂.nil | (a::as) (b::bs) (forall₂.cons h₁ h₂) := begin by_cases p a, { have : q b, { rwa [← hpq h₁] }, simp only [filter_cons_of_pos _ h, filter_cons_of_pos _ this, forall₂_cons, h₁, rel_filter h₂, and_true], }, { have : ¬ q b, { rwa [← hpq h₁] }, simp only [filter_cons_of_neg _ h, filter_cons_of_neg _ this, rel_filter h₂], }, end theorem filter_map_cons (f : α → option β) (a : α) (l : list α) : filter_map f (a :: l) = option.cases_on (f a) (filter_map f l) (λb, b :: filter_map f l) := begin generalize eq : f a = b, cases b, { rw filter_map_cons_none _ _ eq }, { rw filter_map_cons_some _ _ _ eq }, end lemma rel_filter_map : ((r ⇒ option.rel p) ⇒ forall₂ r ⇒ forall₂ p) filter_map filter_map | f g hfg _ _ forall₂.nil := forall₂.nil | f g hfg (a::as) (b::bs) (forall₂.cons h₁ h₂) := by rw [filter_map_cons, filter_map_cons]; from match f a, g b, hfg h₁ with | _, _, option.rel.none := rel_filter_map @hfg h₂ | _, _, option.rel.some h := forall₂.cons h (rel_filter_map @hfg h₂) end @[to_additive] lemma rel_prod [monoid α] [monoid β] (h : r 1 1) (hf : (r ⇒ r ⇒ r) (*) (*)) : (forall₂ r ⇒ r) prod prod := rel_foldl hf h end forall₂ /- sections -/ theorem mem_sections {L : list (list α)} {f} : f ∈ sections L ↔ forall₂ (∈) f L := begin refine ⟨λ h, _, λ h, _⟩, { induction L generalizing f, {cases mem_singleton.1 h, exact forall₂.nil}, simp only [sections, bind_eq_bind, mem_bind, mem_map] at h, rcases h with ⟨_, _, _, _, rfl⟩, simp only [*, forall₂_cons, true_and] }, { induction h with a l f L al fL fs, {exact or.inl rfl}, simp only [sections, bind_eq_bind, mem_bind, mem_map], exact ⟨_, fs, _, al, rfl, rfl⟩ } end theorem mem_sections_length {L : list (list α)} {f} (h : f ∈ sections L) : length f = length L := forall₂_length_eq (mem_sections.1 h) lemma rel_sections {r : α → β → Prop} : (forall₂ (forall₂ r) ⇒ forall₂ (forall₂ r)) sections sections | _ _ forall₂.nil := forall₂.cons forall₂.nil forall₂.nil | _ _ (forall₂.cons h₀ h₁) := rel_bind (rel_sections h₁) (assume _ _ hl, rel_map (assume _ _ ha, forall₂.cons ha hl) h₀) /- permutations -/ section permutations @[simp] theorem permutations_aux_nil (is : list α) : permutations_aux [] is = [] := by rw [permutations_aux, permutations_aux.rec] @[simp] theorem permutations_aux_cons (t : α) (ts is : list α) : permutations_aux (t :: ts) is = foldr (λy r, (permutations_aux2 t ts r y id).2) (permutations_aux ts (t::is)) (permutations is) := by rw [permutations_aux, permutations_aux.rec]; refl end permutations /- insert -/ section insert variable [decidable_eq α] @[simp] theorem insert_nil (a : α) : insert a nil = [a] := rfl theorem insert.def (a : α) (l : list α) : insert a l = if a ∈ l then l else a :: l := rfl @[simp] theorem insert_of_mem {a : α} {l : list α} (h : a ∈ l) : insert a l = l := by simp only [insert.def, if_pos h] @[simp] theorem insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) : insert a l = a :: l := by simp only [insert.def, if_neg h]; split; refl @[simp] theorem mem_insert_iff {a b : α} {l : list α} : a ∈ insert b l ↔ a = b ∨ a ∈ l := begin by_cases h' : b ∈ l, { simp only [insert_of_mem h'], apply (or_iff_right_of_imp _).symm, exact λ e, e.symm ▸ h' }, simp only [insert_of_not_mem h', mem_cons_iff] end @[simp] theorem suffix_insert (a : α) (l : list α) : l <:+ insert a l := by by_cases a ∈ l; [simp only [insert_of_mem h], simp only [insert_of_not_mem h, suffix_cons]] @[simp] theorem mem_insert_self (a : α) (l : list α) : a ∈ insert a l := mem_insert_iff.2 (or.inl rfl) @[simp] theorem mem_insert_of_mem {a b : α} {l : list α} (h : a ∈ l) : a ∈ insert b l := mem_insert_iff.2 (or.inr h) theorem eq_or_mem_of_mem_insert {a b : α} {l : list α} (h : a ∈ insert b l) : a = b ∨ a ∈ l := mem_insert_iff.1 h @[simp] theorem length_insert_of_mem {a : α} {l : list α} (h : a ∈ l) : length (insert a l) = length l := by rw insert_of_mem h @[simp] theorem length_insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) : length (insert a l) = length l + 1 := by rw insert_of_not_mem h; refl end insert /- erasep -/ section erasep variables {p : α → Prop} [decidable_pred p] @[simp] theorem erasep_nil : [].erasep p = [] := rfl theorem erasep_cons (a : α) (l : list α) : (a :: l).erasep p = if p a then l else a :: l.erasep p := rfl @[simp] theorem erasep_cons_of_pos {a : α} {l : list α} (h : p a) : (a :: l).erasep p = l := by simp [erasep_cons, h] @[simp] theorem erasep_cons_of_neg {a : α} {l : list α} (h : ¬ p a) : (a::l).erasep p = a :: l.erasep p := by simp [erasep_cons, h] theorem erasep_of_forall_not {l : list α} (h : ∀ a ∈ l, ¬ p a) : l.erasep p = l := by induction l with _ _ ih; [refl, simp [h _ (or.inl rfl), ih (forall_mem_of_forall_mem_cons h)]] theorem exists_of_erasep {l : list α} {a} (al : a ∈ l) (pa : p a) : ∃ a l₁ l₂, (∀ b ∈ l₁, ¬ p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.erasep p = l₁ ++ l₂ := begin induction l with b l IH, {cases al}, by_cases pb : p b, { exact ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ }, { rcases al with rfl | al, {exact pb.elim pa}, rcases IH al with ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩, exact ⟨c, b::l₁, l₂, forall_mem_cons.2 ⟨pb, h₁⟩, h₂, by rw h₃; refl, by simp [pb, h₄]⟩ } end theorem exists_or_eq_self_of_erasep (p : α → Prop) [decidable_pred p] (l : list α) : l.erasep p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬ p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.erasep p = l₁ ++ l₂ := begin by_cases h : ∃ a ∈ l, p a, { rcases h with ⟨a, ha, pa⟩, exact or.inr (exists_of_erasep ha pa) }, { simp at h, exact or.inl (erasep_of_forall_not h) } end @[simp] theorem length_erasep_of_mem {l : list α} {a} (al : a ∈ l) (pa : p a) : length (l.erasep p) = pred (length l) := by rcases exists_of_erasep al pa with ⟨_, l₁, l₂, _, _, e₁, e₂⟩; rw e₂; simp [-add_comm, e₁]; refl theorem erasep_append_left {a : α} (pa : p a) : ∀ {l₁ : list α} (l₂), a ∈ l₁ → (l₁++l₂).erasep p = l₁.erasep p ++ l₂ | (x::xs) l₂ h := begin by_cases h' : p x; simp [h'], rw erasep_append_left l₂ (mem_of_ne_of_mem (mt _ h') h), rintro rfl, exact pa end theorem erasep_append_right : ∀ {l₁ : list α} (l₂), (∀ b ∈ l₁, ¬ p b) → (l₁++l₂).erasep p = l₁ ++ l₂.erasep p | [] l₂ h := rfl | (x::xs) l₂ h := by simp [(forall_mem_cons.1 h).1, erasep_append_right _ (forall_mem_cons.1 h).2] theorem erasep_sublist (l : list α) : l.erasep p <+ l := by rcases exists_or_eq_self_of_erasep p l with h | ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩; [rw h, {rw [h₄, h₃], simp}] theorem erasep_subset (l : list α) : l.erasep p ⊆ l := subset_of_sublist (erasep_sublist l) theorem erasep_sublist_erasep {l₁ l₂ : list α} (s : l₁ <+ l₂) : l₁.erasep p <+ l₂.erasep p := begin induction s, case list.sublist.slnil { refl }, case list.sublist.cons : l₁ l₂ a s IH { by_cases h : p a; simp [h], exacts [IH.trans (erasep_sublist _), IH.cons _ _ _] }, case list.sublist.cons2 : l₁ l₂ a s IH { by_cases h : p a; simp [h], exacts [s, IH.cons2 _ _ _] } end theorem mem_of_mem_erasep {a : α} {l : list α} : a ∈ l.erasep p → a ∈ l := @erasep_subset _ _ _ _ _ @[simp] theorem mem_erasep_of_neg {a : α} {l : list α} (pa : ¬ p a) : a ∈ l.erasep p ↔ a ∈ l := ⟨mem_of_mem_erasep, λ al, begin rcases exists_or_eq_self_of_erasep p l with h | ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩, { rwa h }, { rw h₄, rw h₃ at al, have : a ≠ c, {rintro rfl, exact pa.elim h₂}, simpa [this] using al } end⟩ theorem erasep_map (f : β → α) : ∀ (l : list β), (map f l).erasep p = map f (l.erasep (p ∘ f)) | [] := rfl | (b::l) := by by_cases p (f b); simp [h, erasep_map l] @[simp] theorem extractp_eq_find_erasep : ∀ l : list α, extractp p l = (find p l, erasep p l) | [] := rfl | (a::l) := by by_cases pa : p a; simp [extractp, pa, extractp_eq_find_erasep l] end erasep /- erase -/ section erase variable [decidable_eq α] @[simp] theorem erase_nil (a : α) : [].erase a = [] := rfl theorem erase_cons (a b : α) (l : list α) : (b :: l).erase a = if b = a then l else b :: l.erase a := rfl @[simp] theorem erase_cons_head (a : α) (l : list α) : (a :: l).erase a = l := by simp only [erase_cons, if_pos rfl] @[simp] theorem erase_cons_tail {a b : α} (l : list α) (h : b ≠ a) : (b::l).erase a = b :: l.erase a := by simp only [erase_cons, if_neg h]; split; refl theorem erase_eq_erasep (a : α) (l : list α) : l.erase a = l.erasep (eq a) := by { induction l with b l, {refl}, by_cases a = b; [simp [h], simp [h, ne.symm h, *]] } @[simp] theorem erase_of_not_mem {a : α} {l : list α} (h : a ∉ l) : l.erase a = l := by rw [erase_eq_erasep, erasep_of_forall_not]; rintro b h' rfl; exact h h' theorem exists_erase_eq {a : α} {l : list α} (h : a ∈ l) : ∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ := by rcases exists_of_erasep h rfl with ⟨_, l₁, l₂, h₁, rfl, h₂, h₃⟩; rw erase_eq_erasep; exact ⟨l₁, l₂, λ h, h₁ _ h rfl, h₂, h₃⟩ @[simp] theorem length_erase_of_mem {a : α} {l : list α} (h : a ∈ l) : length (l.erase a) = pred (length l) := by rw erase_eq_erasep; exact length_erasep_of_mem h rfl theorem erase_append_left {a : α} {l₁ : list α} (l₂) (h : a ∈ l₁) : (l₁++l₂).erase a = l₁.erase a ++ l₂ := by simp [erase_eq_erasep]; exact erasep_append_left (by refl) l₂ h theorem erase_append_right {a : α} {l₁ : list α} (l₂) (h : a ∉ l₁) : (l₁++l₂).erase a = l₁ ++ l₂.erase a := by rw [erase_eq_erasep, erase_eq_erasep, erasep_append_right]; rintro b h' rfl; exact h h' theorem erase_sublist (a : α) (l : list α) : l.erase a <+ l := by rw erase_eq_erasep; apply erasep_sublist theorem erase_subset (a : α) (l : list α) : l.erase a ⊆ l := subset_of_sublist (erase_sublist a l) theorem erase_sublist_erase (a : α) {l₁ l₂ : list α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a := by simp [erase_eq_erasep]; exact erasep_sublist_erasep h theorem mem_of_mem_erase {a b : α} {l : list α} : a ∈ l.erase b → a ∈ l := @erase_subset _ _ _ _ _ @[simp] theorem mem_erase_of_ne {a b : α} {l : list α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l := by rw erase_eq_erasep; exact mem_erasep_of_neg ab.symm theorem erase_comm (a b : α) (l : list α) : (l.erase a).erase b = (l.erase b).erase a := if ab : a = b then by rw ab else if ha : a ∈ l then if hb : b ∈ l then match l, l.erase a, exists_erase_eq ha, hb with | ._, ._, ⟨l₁, l₂, ha', rfl, rfl⟩, hb := if h₁ : b ∈ l₁ then by rw [erase_append_left _ h₁, erase_append_left _ h₁, erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head] else by rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha', erase_cons_tail _ ab, erase_cons_head] end else by simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)] else by simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)] theorem map_erase [decidable_eq β] {f : α → β} (finj : injective f) {a : α} (l : list α) : map f (l.erase a) = (map f l).erase (f a) := by rw [erase_eq_erasep, erase_eq_erasep, erasep_map]; congr; ext b; simp [finj.eq_iff] theorem map_foldl_erase [decidable_eq β] {f : α → β} (finj : injective f) {l₁ l₂ : list α} : map f (foldl list.erase l₁ l₂) = foldl (λ l a, l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁; [refl, simp only [foldl_cons, map_erase finj, *]] @[simp] theorem count_erase_self (a : α) : ∀ (s : list α), count a (list.erase s a) = pred (count a s) | [] := by simp | (h :: t) := begin rw erase_cons, by_cases p : h = a, { rw [if_pos p, count_cons', if_pos p.symm], simp }, { rw [if_neg p, count_cons', count_cons', if_neg (λ x : a = h, p x.symm), count_erase_self], simp, } end @[simp] theorem count_erase_of_ne {a b : α} (ab : a ≠ b) : ∀ (s : list α), count a (list.erase s b) = count a s | [] := by simp | (x :: xs) := begin rw erase_cons, split_ifs with h, { rw [count_cons', h, if_neg ab], simp }, { rw [count_cons', count_cons', count_erase_of_ne] } end end erase /- diff -/ section diff variable [decidable_eq α] @[simp] theorem diff_nil (l : list α) : l.diff [] = l := rfl @[simp] theorem diff_cons (l₁ l₂ : list α) (a : α) : l₁.diff (a::l₂) = (l₁.erase a).diff l₂ := if h : a ∈ l₁ then by simp only [list.diff, if_pos h] else by simp only [list.diff, if_neg h, erase_of_not_mem h] @[simp] theorem nil_diff (l : list α) : [].diff l = [] := by induction l; [refl, simp only [*, diff_cons, erase_of_not_mem (not_mem_nil _)]] theorem diff_eq_foldl : ∀ (l₁ l₂ : list α), l₁.diff l₂ = foldl list.erase l₁ l₂ | l₁ [] := rfl | l₁ (a::l₂) := (diff_cons l₁ l₂ a).trans (diff_eq_foldl _ _) @[simp] theorem diff_append (l₁ l₂ l₃ : list α) : l₁.diff (l₂ ++ l₃) = (l₁.diff l₂).diff l₃ := by simp only [diff_eq_foldl, foldl_append] @[simp] theorem map_diff [decidable_eq β] {f : α → β} (finj : injective f) {l₁ l₂ : list α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] theorem diff_sublist : ∀ l₁ l₂ : list α, l₁.diff l₂ <+ l₁ | l₁ [] := sublist.refl _ | l₁ (a::l₂) := calc l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ : diff_cons _ _ _ ... <+ l₁.erase a : diff_sublist _ _ ... <+ l₁ : list.erase_sublist _ _ theorem diff_subset (l₁ l₂ : list α) : l₁.diff l₂ ⊆ l₁ := subset_of_sublist $ diff_sublist _ _ theorem mem_diff_of_mem {a : α} : ∀ {l₁ l₂ : list α}, a ∈ l₁ → a ∉ l₂ → a ∈ l₁.diff l₂ | l₁ [] h₁ h₂ := h₁ | l₁ (b::l₂) h₁ h₂ := by rw diff_cons; exact mem_diff_of_mem ((mem_erase_of_ne (ne_of_not_mem_cons h₂)).2 h₁) (not_mem_of_not_mem_cons h₂) theorem diff_sublist_of_sublist : ∀ {l₁ l₂ l₃: list α}, l₁ <+ l₂ → l₁.diff l₃ <+ l₂.diff l₃ | l₁ l₂ [] h := h | l₁ l₂ (a::l₃) h := by simp only [diff_cons, diff_sublist_of_sublist (erase_sublist_erase _ h)] theorem erase_diff_erase_sublist_of_sublist {a : α} : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → (l₂.erase a).diff (l₁.erase a) <+ l₂.diff l₁ | [] l₂ h := erase_sublist _ _ | (b::l₁) l₂ h := if heq : b = a then by simp only [heq, erase_cons_head, diff_cons] else by simpa only [erase_cons_head, erase_cons_tail _ heq, diff_cons, erase_comm a b l₂] using erase_diff_erase_sublist_of_sublist (erase_sublist_erase b h) using_well_founded wf_tacs end diff /- zip & unzip -/ @[simp] theorem zip_cons_cons (a : α) (b : β) (l₁ : list α) (l₂ : list β) : zip (a :: l₁) (b :: l₂) = (a, b) :: zip l₁ l₂ := rfl @[simp] theorem zip_nil_left (l : list α) : zip ([] : list β) l = [] := rfl @[simp] theorem zip_nil_right (l : list α) : zip l ([] : list β) = [] := by cases l; refl @[simp] theorem zip_swap : ∀ (l₁ : list α) (l₂ : list β), (zip l₁ l₂).map prod.swap = zip l₂ l₁ | [] l₂ := (zip_nil_right _).symm | l₁ [] := by rw zip_nil_right; refl | (a::l₁) (b::l₂) := by simp only [zip_cons_cons, map_cons, zip_swap l₁ l₂, prod.swap_prod_mk]; split; refl @[simp] theorem length_zip : ∀ (l₁ : list α) (l₂ : list β), length (zip l₁ l₂) = min (length l₁) (length l₂) | [] l₂ := rfl | l₁ [] := by simp only [length, zip_nil_right, min_zero] | (a::l₁) (b::l₂) := by by simp only [length, zip_cons_cons, length_zip l₁ l₂, min_add_add_right] theorem zip_append : ∀ {l₁ l₂ r₁ r₂ : list α} (h : length l₁ = length l₂), zip (l₁ ++ r₁) (l₂ ++ r₂) = zip l₁ l₂ ++ zip r₁ r₂ | [] l₂ r₁ r₂ h := by simp only [eq_nil_of_length_eq_zero h.symm]; refl | l₁ [] r₁ r₂ h := by simp only [eq_nil_of_length_eq_zero h]; refl | (a::l₁) (b::l₂) r₁ r₂ h := by simp only [cons_append, zip_cons_cons, zip_append (succ_inj h)]; split; refl theorem zip_map (f : α → γ) (g : β → δ) : ∀ (l₁ : list α) (l₂ : list β), zip (l₁.map f) (l₂.map g) = (zip l₁ l₂).map (prod.map f g) | [] l₂ := rfl | l₁ [] := by simp only [map, zip_nil_right] | (a::l₁) (b::l₂) := by simp only [map, zip_cons_cons, zip_map l₁ l₂, prod.map]; split; refl theorem zip_map_left (f : α → γ) (l₁ : list α) (l₂ : list β) : zip (l₁.map f) l₂ = (zip l₁ l₂).map (prod.map f id) := by rw [← zip_map, map_id] theorem zip_map_right (f : β → γ) (l₁ : list α) (l₂ : list β) : zip l₁ (l₂.map f) = (zip l₁ l₂).map (prod.map id f) := by rw [← zip_map, map_id] theorem zip_map' (f : α → β) (g : α → γ) : ∀ (l : list α), zip (l.map f) (l.map g) = l.map (λ a, (f a, g a)) | [] := rfl | (a::l) := by simp only [map, zip_cons_cons, zip_map' l]; split; refl theorem mem_zip {a b} : ∀ {l₁ : list α} {l₂ : list β}, (a, b) ∈ zip l₁ l₂ → a ∈ l₁ ∧ b ∈ l₂ | (_::l₁) (_::l₂) (or.inl rfl) := ⟨or.inl rfl, or.inl rfl⟩ | (a'::l₁) (b'::l₂) (or.inr h) := by split; simp only [mem_cons_iff, or_true, mem_zip h] @[simp] theorem unzip_nil : unzip (@nil (α × β)) = ([], []) := rfl @[simp] theorem unzip_cons (a : α) (b : β) (l : list (α × β)) : unzip ((a, b) :: l) = (a :: (unzip l).1, b :: (unzip l).2) := by rw unzip; cases unzip l; refl theorem unzip_eq_map : ∀ (l : list (α × β)), unzip l = (l.map prod.fst, l.map prod.snd) | [] := rfl | ((a, b) :: l) := by simp only [unzip_cons, map_cons, unzip_eq_map l] theorem unzip_left (l : list (α × β)) : (unzip l).1 = l.map prod.fst := by simp only [unzip_eq_map] theorem unzip_right (l : list (α × β)) : (unzip l).2 = l.map prod.snd := by simp only [unzip_eq_map] theorem unzip_swap (l : list (α × β)) : unzip (l.map prod.swap) = (unzip l).swap := by simp only [unzip_eq_map, map_map]; split; refl theorem zip_unzip : ∀ (l : list (α × β)), zip (unzip l).1 (unzip l).2 = l | [] := rfl | ((a, b) :: l) := by simp only [unzip_cons, zip_cons_cons, zip_unzip l]; split; refl theorem unzip_zip_left : ∀ {l₁ : list α} {l₂ : list β}, length l₁ ≤ length l₂ → (unzip (zip l₁ l₂)).1 = l₁ | [] l₂ h := rfl | l₁ [] h := by rw eq_nil_of_length_eq_zero (eq_zero_of_le_zero h); refl | (a::l₁) (b::l₂) h := by simp only [zip_cons_cons, unzip_cons, unzip_zip_left (le_of_succ_le_succ h)]; split; refl theorem unzip_zip_right {l₁ : list α} {l₂ : list β} (h : length l₂ ≤ length l₁) : (unzip (zip l₁ l₂)).2 = l₂ := by rw [← zip_swap, unzip_swap]; exact unzip_zip_left h theorem unzip_zip {l₁ : list α} {l₂ : list β} (h : length l₁ = length l₂) : unzip (zip l₁ l₂) = (l₁, l₂) := by rw [← @prod.mk.eta _ _ (unzip (zip l₁ l₂)), unzip_zip_left (le_of_eq h), unzip_zip_right (ge_of_eq h)] @[simp] theorem length_revzip (l : list α) : length (revzip l) = length l := by simp only [revzip, length_zip, length_reverse, min_self] @[simp] theorem unzip_revzip (l : list α) : (revzip l).unzip = (l, l.reverse) := unzip_zip (length_reverse l).symm @[simp] theorem revzip_map_fst (l : list α) : (revzip l).map prod.fst = l := by rw [← unzip_left, unzip_revzip] @[simp] theorem revzip_map_snd (l : list α) : (revzip l).map prod.snd = l.reverse := by rw [← unzip_right, unzip_revzip] theorem reverse_revzip (l : list α) : reverse l.revzip = revzip l.reverse := by rw [← zip_unzip.{u u} (revzip l).reverse, unzip_eq_map]; simp; simp [revzip] theorem revzip_swap (l : list α) : (revzip l).map prod.swap = revzip l.reverse := by simp [revzip] /- enum -/ theorem length_enum_from : ∀ n (l : list α), length (enum_from n l) = length l | n [] := rfl | n (a::l) := congr_arg nat.succ (length_enum_from _ _) theorem length_enum : ∀ (l : list α), length (enum l) = length l := length_enum_from _ @[simp] theorem enum_from_nth : ∀ n (l : list α) m, nth (enum_from n l) m = (λ a, (n + m, a)) <$> nth l m | n [] m := rfl | n (a :: l) 0 := rfl | n (a :: l) (m+1) := (enum_from_nth (n+1) l m).trans $ by rw [add_right_comm]; refl @[simp] theorem enum_nth : ∀ (l : list α) n, nth (enum l) n = (λ a, (n, a)) <$> nth l n := by simp only [enum, enum_from_nth, zero_add]; intros; refl @[simp] theorem enum_from_map_snd : ∀ n (l : list α), map prod.snd (enum_from n l) = l | n [] := rfl | n (a :: l) := congr_arg (cons _) (enum_from_map_snd _ _) @[simp] theorem enum_map_snd : ∀ (l : list α), map prod.snd (enum l) = l := enum_from_map_snd _ theorem mem_enum_from {x : α} {i : ℕ} : Π {j : ℕ} (xs : list α), (i, x) ∈ xs.enum_from j → j ≤ i ∧ i < j + xs.length ∧ x ∈ xs | j [] := by simp [enum_from] | j (y :: ys) := by { simp [enum_from,mem_enum_from ys], rintro (h|h), { refine ⟨le_of_eq h.1.symm,h.1 ▸ _,or.inl h.2⟩, apply lt_of_lt_of_le (nat.lt_add_of_pos_right zero_lt_one), apply nat.add_le_add_left, apply nat.le_add_right }, { replace h := mem_enum_from _ h, simp at h, revert h, apply and_implies _ (and_implies id or.inr), intro h, transitivity j+1, apply nat.le_add_right, exact h } } /- product -/ @[simp] theorem nil_product (l : list β) : product (@nil α) l = [] := rfl @[simp] theorem product_cons (a : α) (l₁ : list α) (l₂ : list β) : product (a::l₁) l₂ = map (λ b, (a, b)) l₂ ++ product l₁ l₂ := rfl @[simp] theorem product_nil : ∀ (l : list α), product l (@nil β) = [] | [] := rfl | (a::l) := by rw [product_cons, product_nil]; refl @[simp] theorem mem_product {l₁ : list α} {l₂ : list β} {a : α} {b : β} : (a, b) ∈ product l₁ l₂ ↔ a ∈ l₁ ∧ b ∈ l₂ := by simp only [product, mem_bind, mem_map, prod.ext_iff, exists_prop, and.left_comm, exists_and_distrib_left, exists_eq_left, exists_eq_right] theorem length_product (l₁ : list α) (l₂ : list β) : length (product l₁ l₂) = length l₁ * length l₂ := by induction l₁ with x l₁ IH; [exact (zero_mul _).symm, simp only [length, product_cons, length_append, IH, right_distrib, one_mul, length_map, add_comm]] /- sigma -/ section variable {σ : α → Type*} @[simp] theorem nil_sigma (l : Π a, list (σ a)) : (@nil α).sigma l = [] := rfl @[simp] theorem sigma_cons (a : α) (l₁ : list α) (l₂ : Π a, list (σ a)) : (a::l₁).sigma l₂ = map (sigma.mk a) (l₂ a) ++ l₁.sigma l₂ := rfl @[simp] theorem sigma_nil : ∀ (l : list α), l.sigma (λ a, @nil (σ a)) = [] | [] := rfl | (a::l) := by rw [sigma_cons, sigma_nil]; refl @[simp] theorem mem_sigma {l₁ : list α} {l₂ : Π a, list (σ a)} {a : α} {b : σ a} : sigma.mk a b ∈ l₁.sigma l₂ ↔ a ∈ l₁ ∧ b ∈ l₂ a := by simp only [list.sigma, mem_bind, mem_map, exists_prop, exists_and_distrib_left, and.left_comm, exists_eq_left, heq_iff_eq, exists_eq_right] theorem length_sigma (l₁ : list α) (l₂ : Π a, list (σ a)) : length (l₁.sigma l₂) = (l₁.map (λ a, length (l₂ a))).sum := by induction l₁ with x l₁ IH; [refl, simp only [map, sigma_cons, length_append, length_map, IH, sum_cons]] end /- of_fn -/ theorem length_of_fn_aux {n} (f : fin n → α) : ∀ m h l, length (of_fn_aux f m h l) = length l + m | 0 h l := rfl | (succ m) h l := (length_of_fn_aux m _ _).trans (succ_add _ _) @[simp] theorem length_of_fn {n} (f : fin n → α) : length (of_fn f) = n := (length_of_fn_aux f _ _ _).trans (zero_add _) theorem nth_of_fn_aux {n} (f : fin n → α) (i) : ∀ m h l, (∀ i, nth l i = of_fn_nth_val f (i + m)) → nth (of_fn_aux f m h l) i = of_fn_nth_val f i | 0 h l H := H i | (succ m) h l H := nth_of_fn_aux m _ _ begin intro j, cases j with j, { simp only [nth, of_fn_nth_val, zero_add, dif_pos (show m < n, from h)] }, { simp only [nth, H, succ_add] } end @[simp] theorem nth_of_fn {n} (f : fin n → α) (i) : nth (of_fn f) i = of_fn_nth_val f i := nth_of_fn_aux f _ _ _ _ $ λ i, by simp only [of_fn_nth_val, dif_neg (not_lt.2 (le_add_left n i))]; refl @[simp] theorem nth_le_of_fn {n} (f : fin n → α) (i : fin n) : nth_le (of_fn f) i.1 ((length_of_fn f).symm ▸ i.2) = f i := option.some.inj $ by rw [← nth_le_nth]; simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos i.2] theorem array_eq_of_fn {n} (a : array n α) : a.to_list = of_fn a.read := suffices ∀ {m h l}, d_array.rev_iterate_aux a (λ i, cons) m h l = of_fn_aux (d_array.read a) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, simp only [d_array.rev_iterate_aux, of_fn_aux, IH] end theorem of_fn_zero (f : fin 0 → α) : of_fn f = [] := rfl theorem of_fn_succ {n} (f : fin (succ n) → α) : of_fn f = f 0 :: of_fn (λ i, f i.succ) := suffices ∀ {m h l}, of_fn_aux f (succ m) (succ_le_succ h) l = f 0 :: of_fn_aux (λ i, f i.succ) m h l, from this, begin intros, induction m with m IH generalizing l, {refl}, rw [of_fn_aux, IH], refl end theorem of_fn_nth_le : ∀ l : list α, of_fn (λ i, nth_le l i.1 i.2) = l | [] := rfl | (a::l) := by rw of_fn_succ; congr; simp only [fin.succ_val]; exact of_fn_nth_le l /- disjoint -/ section disjoint theorem disjoint.symm {l₁ l₂ : list α} (d : disjoint l₁ l₂) : disjoint l₂ l₁ | a i₂ i₁ := d i₁ i₂ @[simp] theorem disjoint_comm {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ disjoint l₂ l₁ := ⟨disjoint.symm, disjoint.symm⟩ theorem disjoint_left {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ {a}, a ∈ l₁ → a ∉ l₂ := iff.rfl theorem disjoint_right {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ {a}, a ∈ l₂ → a ∉ l₁ := disjoint_comm theorem disjoint_iff_ne {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] theorem disjoint_of_subset_left {l₁ l₂ l : list α} (ss : l₁ ⊆ l) (d : disjoint l l₂) : disjoint l₁ l₂ | x m₁ := d (ss m₁) theorem disjoint_of_subset_right {l₁ l₂ l : list α} (ss : l₂ ⊆ l) (d : disjoint l₁ l) : disjoint l₁ l₂ | x m m₁ := d m (ss m₁) theorem disjoint_of_disjoint_cons_left {a : α} {l₁ l₂} : disjoint (a::l₁) l₂ → disjoint l₁ l₂ := disjoint_of_subset_left (list.subset_cons _ _) theorem disjoint_of_disjoint_cons_right {a : α} {l₁ l₂} : disjoint l₁ (a::l₂) → disjoint l₁ l₂ := disjoint_of_subset_right (list.subset_cons _ _) @[simp] theorem disjoint_nil_left (l : list α) : disjoint [] l | a := (not_mem_nil a).elim @[simp] theorem singleton_disjoint {l : list α} {a : α} : disjoint [a] l ↔ a ∉ l := by simp only [disjoint, mem_singleton, forall_eq]; refl @[simp] theorem disjoint_singleton {l : list α} {a : α} : disjoint l [a] ↔ a ∉ l := by rw disjoint_comm; simp only [singleton_disjoint] @[simp] theorem disjoint_append_left {l₁ l₂ l : list α} : disjoint (l₁++l₂) l ↔ disjoint l₁ l ∧ disjoint l₂ l := by simp only [disjoint, mem_append, or_imp_distrib, forall_and_distrib] @[simp] theorem disjoint_append_right {l₁ l₂ l : list α} : disjoint l (l₁++l₂) ↔ disjoint l l₁ ∧ disjoint l l₂ := disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_append_left] @[simp] theorem disjoint_cons_left {a : α} {l₁ l₂ : list α} : disjoint (a::l₁) l₂ ↔ a ∉ l₂ ∧ disjoint l₁ l₂ := (@disjoint_append_left _ [a] l₁ l₂).trans $ by simp only [singleton_disjoint] @[simp] theorem disjoint_cons_right {a : α} {l₁ l₂ : list α} : disjoint l₁ (a::l₂) ↔ a ∉ l₁ ∧ disjoint l₁ l₂ := disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_cons_left] theorem disjoint_of_disjoint_append_left_left {l₁ l₂ l : list α} (d : disjoint (l₁++l₂) l) : disjoint l₁ l := (disjoint_append_left.1 d).1 theorem disjoint_of_disjoint_append_left_right {l₁ l₂ l : list α} (d : disjoint (l₁++l₂) l) : disjoint l₂ l := (disjoint_append_left.1 d).2 theorem disjoint_of_disjoint_append_right_left {l₁ l₂ l : list α} (d : disjoint l (l₁++l₂)) : disjoint l l₁ := (disjoint_append_right.1 d).1 theorem disjoint_of_disjoint_append_right_right {l₁ l₂ l : list α} (d : disjoint l (l₁++l₂)) : disjoint l l₂ := (disjoint_append_right.1 d).2 end disjoint /- union -/ section union variable [decidable_eq α] @[simp] theorem nil_union (l : list α) : [] ∪ l = l := rfl @[simp] theorem cons_union (l₁ l₂ : list α) (a : α) : a :: l₁ ∪ l₂ = insert a (l₁ ∪ l₂) := rfl @[simp] theorem mem_union {l₁ l₂ : list α} {a : α} : a ∈ l₁ ∪ l₂ ↔ a ∈ l₁ ∨ a ∈ l₂ := by induction l₁; simp only [nil_union, not_mem_nil, false_or, cons_union, mem_insert_iff, mem_cons_iff, or_assoc, *] theorem mem_union_left {a : α} {l₁ : list α} (h : a ∈ l₁) (l₂ : list α) : a ∈ l₁ ∪ l₂ := mem_union.2 (or.inl h) theorem mem_union_right {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := mem_union.2 (or.inr h) theorem sublist_suffix_of_union : ∀ l₁ l₂ : list α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂ | [] l₂ := ⟨[], by refl, rfl⟩ | (a::l₁) l₂ := let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ in if h : a ∈ l₁ ∪ l₂ then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩ else ⟨a::t, cons_sublist_cons _ s, by simp only [cons_append, cons_union, e, insert_of_not_mem h]; split; refl⟩ theorem suffix_union_right (l₁ l₂ : list α) : l₂ <:+ l₁ ∪ l₂ := (sublist_suffix_of_union l₁ l₂).imp (λ a, and.right) theorem union_sublist_append (l₁ l₂ : list α) : l₁ ∪ l₂ <+ l₁ ++ l₂ := let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ in e ▸ (append_sublist_append_right _).2 s theorem forall_mem_union {p : α → Prop} {l₁ l₂ : list α} : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ (∀ x ∈ l₂, p x) := by simp only [mem_union, or_imp_distrib, forall_and_distrib] theorem forall_mem_of_forall_mem_union_left {p : α → Prop} {l₁ l₂ : list α} (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x := (forall_mem_union.1 h).1 theorem forall_mem_of_forall_mem_union_right {p : α → Prop} {l₁ l₂ : list α} (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x := (forall_mem_union.1 h).2 end union /- inter -/ section inter variable [decidable_eq α] @[simp] theorem inter_nil (l : list α) : [] ∩ l = [] := rfl @[simp] theorem inter_cons_of_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : (a::l₁) ∩ l₂ = a :: (l₁ ∩ l₂) := if_pos h @[simp] theorem inter_cons_of_not_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∉ l₂) : (a::l₁) ∩ l₂ = l₁ ∩ l₂ := if_neg h theorem mem_of_mem_inter_left {l₁ l₂ : list α} {a : α} : a ∈ l₁ ∩ l₂ → a ∈ l₁ := mem_of_mem_filter theorem mem_of_mem_inter_right {l₁ l₂ : list α} {a : α} : a ∈ l₁ ∩ l₂ → a ∈ l₂ := of_mem_filter theorem mem_inter_of_mem_of_mem {l₁ l₂ : list α} {a : α} : a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂ := mem_filter_of_mem @[simp] theorem mem_inter {a : α} {l₁ l₂ : list α} : a ∈ l₁ ∩ l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ := mem_filter theorem inter_subset_left (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₁ := filter_subset _ theorem inter_subset_right (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₂ := λ a, mem_of_mem_inter_right theorem subset_inter {l l₁ l₂ : list α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ := λ a h, mem_inter.2 ⟨h₁ h, h₂ h⟩ theorem inter_eq_nil_iff_disjoint {l₁ l₂ : list α} : l₁ ∩ l₂ = [] ↔ disjoint l₁ l₂ := by simp only [eq_nil_iff_forall_not_mem, mem_inter, not_and]; refl theorem forall_mem_inter_of_forall_left {p : α → Prop} {l₁ : list α} (h : ∀ x ∈ l₁, p x) (l₂ : list α) : ∀ x, x ∈ l₁ ∩ l₂ → p x := ball.imp_left (λ x, mem_of_mem_inter_left) h theorem forall_mem_inter_of_forall_right {p : α → Prop} (l₁ : list α) {l₂ : list α} (h : ∀ x ∈ l₂, p x) : ∀ x, x ∈ l₁ ∩ l₂ → p x := ball.imp_left (λ x, mem_of_mem_inter_right) h end inter /- bag_inter -/ section bag_inter variable [decidable_eq α] @[simp] theorem nil_bag_inter (l : list α) : [].bag_inter l = [] := by cases l; refl @[simp] theorem bag_inter_nil (l : list α) : l.bag_inter [] = [] := by cases l; refl @[simp] theorem cons_bag_inter_of_pos {a} (l₁ : list α) {l₂} (h : a ∈ l₂) : (a :: l₁).bag_inter l₂ = a :: l₁.bag_inter (l₂.erase a) := by cases l₂; exact if_pos h @[simp] theorem cons_bag_inter_of_neg {a} (l₁ : list α) {l₂} (h : a ∉ l₂) : (a :: l₁).bag_inter l₂ = l₁.bag_inter l₂ := begin cases l₂, {simp only [bag_inter_nil]}, simp only [erase_of_not_mem h, list.bag_inter, if_neg h] end @[simp] theorem mem_bag_inter {a : α} : ∀ {l₁ l₂ : list α}, a ∈ l₁.bag_inter l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ | [] l₂ := by simp only [nil_bag_inter, not_mem_nil, false_and] | (b::l₁) l₂ := begin by_cases b ∈ l₂, { rw [cons_bag_inter_of_pos _ h, mem_cons_iff, mem_cons_iff, mem_bag_inter], by_cases ba : a = b, { simp only [ba, h, eq_self_iff_true, true_or, true_and] }, { simp only [mem_erase_of_ne ba, ba, false_or] } }, { rw [cons_bag_inter_of_neg _ h, mem_bag_inter, mem_cons_iff, or_and_distrib_right], symmetry, apply or_iff_right_of_imp, rintro ⟨rfl, h'⟩, exact h.elim h' } end @[simp] theorem count_bag_inter {a : α} : ∀ {l₁ l₂ : list α}, count a (l₁.bag_inter l₂) = min (count a l₁) (count a l₂) | [] l₂ := by simp | l₁ [] := by simp | (h₁ :: l₁) (h₂ :: l₂) := begin simp only [list.bag_inter, list.mem_cons_iff], by_cases p₁ : h₂ = h₁; by_cases p₂ : h₁ = a, { simp only [p₁, p₂, count_bag_inter, min_succ_succ, erase_cons_head, if_true, mem_cons_iff, count_cons_self, true_or, eq_self_iff_true] }, { simp only [p₁, ne.symm p₂, count_bag_inter, count_cons, erase_cons_head, if_true, mem_cons_iff, true_or, eq_self_iff_true, if_false] }, { rw p₂ at p₁, by_cases p₃ : a ∈ l₂, { simp only [p₁, ne.symm p₁, p₂, p₃, erase_cons, count_bag_inter, eq.symm (min_succ_succ _ _), succ_pred_eq_of_pos (count_pos.2 p₃), if_true, mem_cons_iff, false_or, count_cons_self, eq_self_iff_true, if_false, ne.def, not_false_iff, count_erase_self, list.count_cons_of_ne] }, { simp [ne.symm p₁, p₂, p₃] } }, { by_cases p₄ : h₁ ∈ l₂; simp only [ne.symm p₁, ne.symm p₂, p₄, count_bag_inter, if_true, if_false, mem_cons_iff, false_or, eq_self_iff_true, ne.def, not_false_iff,count_erase_of_ne, count_cons_of_ne] } end theorem bag_inter_sublist_left : ∀ l₁ l₂ : list α, l₁.bag_inter l₂ <+ l₁ | [] l₂ := by simp [nil_sublist] | (b::l₁) l₂ := begin by_cases b ∈ l₂; simp [h], { apply cons_sublist_cons, apply bag_inter_sublist_left }, { apply sublist_cons_of_sublist, apply bag_inter_sublist_left } end theorem bag_inter_nil_iff_inter_nil : ∀ l₁ l₂ : list α, l₁.bag_inter l₂ = [] ↔ l₁ ∩ l₂ = [] | [] l₂ := by simp | (b::l₁) l₂ := begin by_cases h : b ∈ l₂; simp [h], exact bag_inter_nil_iff_inter_nil l₁ l₂ end end bag_inter /- pairwise relation (generalized no duplicate) -/ section pairwise run_cmd tactic.mk_iff_of_inductive_prop `list.pairwise `list.pairwise_iff variable {R : α → α → Prop} theorem rel_of_pairwise_cons {a : α} {l : list α} (p : pairwise R (a::l)) : ∀ {a'}, a' ∈ l → R a a' := (pairwise_cons.1 p).1 theorem pairwise_of_pairwise_cons {a : α} {l : list α} (p : pairwise R (a::l)) : pairwise R l := (pairwise_cons.1 p).2 theorem pairwise.imp_of_mem {S : α → α → Prop} {l : list α} (H : ∀ {a b}, a ∈ l → b ∈ l → R a b → S a b) (p : pairwise R l) : pairwise S l := begin induction p with a l r p IH generalizing H; constructor, { exact ball.imp_right (λ x h, H (mem_cons_self _ _) (mem_cons_of_mem _ h)) r }, { exact IH (λ a b m m', H (mem_cons_of_mem _ m) (mem_cons_of_mem _ m')) } end theorem pairwise.imp {S : α → α → Prop} (H : ∀ a b, R a b → S a b) {l : list α} : pairwise R l → pairwise S l := pairwise.imp_of_mem (λ a b _ _, H a b) theorem pairwise.and {S : α → α → Prop} {l : list α} : pairwise (λ a b, R a b ∧ S a b) l ↔ pairwise R l ∧ pairwise S l := ⟨λ h, ⟨h.imp (λ a b h, h.1), h.imp (λ a b h, h.2)⟩, λ ⟨hR, hS⟩, begin clear_, induction hR with a l R1 R2 IH; simp only [pairwise.nil, pairwise_cons] at *, exact ⟨λ b bl, ⟨R1 b bl, hS.1 b bl⟩, IH hS.2⟩ end⟩ theorem pairwise.imp₂ {S : α → α → Prop} {T : α → α → Prop} (H : ∀ a b, R a b → S a b → T a b) {l : list α} (hR : pairwise R l) (hS : pairwise S l) : pairwise T l := (pairwise.and.2 ⟨hR, hS⟩).imp $ λ a b, and.rec (H a b) theorem pairwise.iff_of_mem {S : α → α → Prop} {l : list α} (H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : pairwise R l ↔ pairwise S l := ⟨pairwise.imp_of_mem (λ a b m m', (H m m').1), pairwise.imp_of_mem (λ a b m m', (H m m').2)⟩ theorem pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : list α} : pairwise R l ↔ pairwise S l := pairwise.iff_of_mem (λ a b _ _, H a b) theorem pairwise_of_forall {l : list α} (H : ∀ x y, R x y) : pairwise R l := by induction l; [exact pairwise.nil, simp only [*, pairwise_cons, forall_2_true_iff, and_true]] theorem pairwise.and_mem {l : list α} : pairwise R l ↔ pairwise (λ x y, x ∈ l ∧ y ∈ l ∧ R x y) l := pairwise.iff_of_mem (by simp only [true_and, iff_self, forall_2_true_iff] {contextual := tt}) theorem pairwise.imp_mem {l : list α} : pairwise R l ↔ pairwise (λ x y, x ∈ l → y ∈ l → R x y) l := pairwise.iff_of_mem (by simp only [forall_prop_of_true, iff_self, forall_2_true_iff] {contextual := tt}) theorem pairwise_of_sublist : Π {l₁ l₂ : list α}, l₁ <+ l₂ → pairwise R l₂ → pairwise R l₁ | ._ ._ sublist.slnil h := h | ._ ._ (sublist.cons l₁ l₂ a s) (pairwise.cons i n) := pairwise_of_sublist s n | ._ ._ (sublist.cons2 l₁ l₂ a s) (pairwise.cons i n) := (pairwise_of_sublist s n).cons (ball.imp_left (subset_of_sublist s) i) theorem forall_of_forall_of_pairwise (H : symmetric R) {l : list α} (H₁ : ∀ x ∈ l, R x x) (H₂ : pairwise R l) : ∀ (x ∈ l) (y ∈ l), R x y := begin induction l with a l IH, { exact forall_mem_nil _ }, cases forall_mem_cons.1 H₁ with H₁₁ H₁₂, cases pairwise_cons.1 H₂ with H₂₁ H₂₂, rintro x (rfl | hx) y (rfl | hy), exacts [H₁₁, H₂₁ _ hy, H (H₂₁ _ hx), IH H₁₂ H₂₂ _ hx _ hy] end lemma forall_of_pairwise (H : symmetric R) {l : list α} (hl : pairwise R l) : (∀a∈l, ∀b∈l, a ≠ b → R a b) := forall_of_forall_of_pairwise (λ a b h hne, H (h hne.symm)) (λ _ _ h, (h rfl).elim) (pairwise.imp (λ _ _ h _, h) hl) theorem pairwise_singleton (R) (a : α) : pairwise R [a] := by simp only [pairwise_cons, mem_singleton, forall_prop_of_false (not_mem_nil _), forall_true_iff, pairwise.nil, and_true] theorem pairwise_pair {a b : α} : pairwise R [a, b] ↔ R a b := by simp only [pairwise_cons, mem_singleton, forall_eq, forall_prop_of_false (not_mem_nil _), forall_true_iff, pairwise.nil, and_true] theorem pairwise_append {l₁ l₂ : list α} : pairwise R (l₁++l₂) ↔ pairwise R l₁ ∧ pairwise R l₂ ∧ ∀ x ∈ l₁, ∀ y ∈ l₂, R x y := by induction l₁ with x l₁ IH; [simp only [list.pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_true_iff, and_true, true_and, nil_append], simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons, forall_and_distrib, and_assoc, and.left_comm]] theorem pairwise_append_comm (s : symmetric R) {l₁ l₂ : list α} : pairwise R (l₁++l₂) ↔ pairwise R (l₂++l₁) := have ∀ l₁ l₂ : list α, (∀ (x : α), x ∈ l₁ → ∀ (y : α), y ∈ l₂ → R x y) → (∀ (x : α), x ∈ l₂ → ∀ (y : α), y ∈ l₁ → R x y), from λ l₁ l₂ a x xm y ym, s (a y ym x xm), by simp only [pairwise_append, and.left_comm]; rw iff.intro (this l₁ l₂) (this l₂ l₁) theorem pairwise_middle (s : symmetric R) {a : α} {l₁ l₂ : list α} : pairwise R (l₁ ++ a::l₂) ↔ pairwise R (a::(l₁++l₂)) := show pairwise R (l₁ ++ ([a] ++ l₂)) ↔ pairwise R ([a] ++ l₁ ++ l₂), by rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁), pairwise_append_comm s]; simp only [mem_append, or_comm] theorem pairwise_map (f : β → α) : ∀ {l : list β}, pairwise R (map f l) ↔ pairwise (λ a b : β, R (f a) (f b)) l | [] := by simp only [map, pairwise.nil] | (b::l) := have (∀ a b', b' ∈ l → f b' = a → R (f b) a) ↔ ∀ (b' : β), b' ∈ l → R (f b) (f b'), from forall_swap.trans $ forall_congr $ λ a, forall_swap.trans $ by simp only [forall_eq'], by simp only [map, pairwise_cons, mem_map, exists_imp_distrib, and_imp, this, pairwise_map] theorem pairwise_of_pairwise_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b) {l : list α} (p : pairwise S (map f l)) : pairwise R l := ((pairwise_map f).1 p).imp H theorem pairwise_map_of_pairwise {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b)) {l : list α} (p : pairwise R l) : pairwise S (map f l) := (pairwise_map f).2 $ p.imp H theorem pairwise_filter_map (f : β → option α) {l : list β} : pairwise R (filter_map f l) ↔ pairwise (λ a a' : β, ∀ (b ∈ f a) (b' ∈ f a'), R b b') l := let S (a a' : β) := ∀ (b ∈ f a) (b' ∈ f a'), R b b' in begin simp only [option.mem_def], induction l with a l IH, { simp only [filter_map, pairwise.nil] }, cases e : f a with b, { rw [filter_map_cons_none _ _ e, IH, pairwise_cons], simp only [e, forall_prop_of_false not_false, forall_3_true_iff, true_and] }, rw [filter_map_cons_some _ _ _ e], simp only [pairwise_cons, mem_filter_map, exists_imp_distrib, and_imp, IH, e, forall_eq'], show (∀ (a' : α) (x : β), x ∈ l → f x = some a' → R b a') ∧ pairwise S l ↔ (∀ (a' : β), a' ∈ l → ∀ (b' : α), f a' = some b' → R b b') ∧ pairwise S l, from and_congr ⟨λ h b mb a ma, h a b mb ma, λ h a b mb ma, h b mb a ma⟩ iff.rfl end theorem pairwise_filter_map_of_pairwise {S : β → β → Prop} (f : α → option β) (H : ∀ (a a' : α), R a a' → ∀ (b ∈ f a) (b' ∈ f a'), S b b') {l : list α} (p : pairwise R l) : pairwise S (filter_map f l) := (pairwise_filter_map _).2 $ p.imp H theorem pairwise_filter (p : α → Prop) [decidable_pred p] {l : list α} : pairwise R (filter p l) ↔ pairwise (λ x y, p x → p y → R x y) l := begin rw [← filter_map_eq_filter, pairwise_filter_map], apply pairwise.iff, intros, simp only [option.mem_def, option.guard_eq_some, and_imp, forall_eq'], end theorem pairwise_filter_of_pairwise (p : α → Prop) [decidable_pred p] {l : list α} : pairwise R l → pairwise R (filter p l) := pairwise_of_sublist (filter_sublist _) theorem pairwise_join {L : list (list α)} : pairwise R (join L) ↔ (∀ l ∈ L, pairwise R l) ∧ pairwise (λ l₁ l₂, ∀ (x ∈ l₁) (y ∈ l₂), R x y) L := begin induction L with l L IH, {simp only [join, pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_const, and_self]}, have : (∀ (x : α), x ∈ l → ∀ (y : α) (x_1 : list α), x_1 ∈ L → y ∈ x_1 → R x y) ↔ ∀ (a' : list α), a' ∈ L → ∀ (x : α), x ∈ l → ∀ (y : α), y ∈ a' → R x y := ⟨λ h a b c d e, h c d e a b, λ h c d e a b, h a b c d e⟩, simp only [join, pairwise_append, IH, mem_join, exists_imp_distrib, and_imp, this, forall_mem_cons, pairwise_cons], simp only [and_assoc, and_comm, and.left_comm], end @[simp] theorem pairwise_reverse : ∀ {R} {l : list α}, pairwise R (reverse l) ↔ pairwise (λ x y, R y x) l := suffices ∀ {R l}, @pairwise α R l → pairwise (λ x y, R y x) (reverse l), from λ R l, ⟨λ p, reverse_reverse l ▸ this p, this⟩, λ R l p, by induction p with a l h p IH; [apply pairwise.nil, simpa only [reverse_cons, pairwise_append, IH, pairwise_cons, forall_prop_of_false (not_mem_nil _), forall_true_iff, pairwise.nil, mem_reverse, mem_singleton, forall_eq, true_and] using h] theorem pairwise_iff_nth_le {R} : ∀ {l : list α}, pairwise R l ↔ ∀ i j (h₁ : j < length l) (h₂ : i < j), R (nth_le l i (lt_trans h₂ h₁)) (nth_le l j h₁) | [] := by simp only [pairwise.nil, true_iff]; exact λ i j h, (not_lt_zero j).elim h | (a::l) := begin rw [pairwise_cons, pairwise_iff_nth_le], refine ⟨λ H i j h₁ h₂, _, λ H, ⟨λ a' m, _, λ i j h₁ h₂, H _ _ (succ_lt_succ h₁) (succ_lt_succ h₂)⟩⟩, { cases j with j, {exact (not_lt_zero _).elim h₂}, cases i with i, { exact H.1 _ (nth_le_mem l _ _) }, { exact H.2 _ _ (lt_of_succ_lt_succ h₁) (lt_of_succ_lt_succ h₂) } }, { rcases nth_le_of_mem m with ⟨n, h, rfl⟩, exact H _ _ (succ_lt_succ h) (succ_pos _) } end theorem pairwise_sublists' {R} : ∀ {l : list α}, pairwise R l → pairwise (lex (swap R)) (sublists' l) | _ pairwise.nil := pairwise_singleton _ _ | _ (@pairwise.cons _ _ a l H₁ H₂) := begin simp only [sublists'_cons, pairwise_append, pairwise_map, mem_sublists', mem_map, exists_imp_distrib, and_imp], have IH := pairwise_sublists' H₂, refine ⟨IH, IH.imp (λ l₁ l₂, lex.cons), _⟩, intros l₁ sl₁ x l₂ sl₂ e, subst e, cases l₁ with b l₁, {constructor}, exact lex.rel (H₁ _ $ subset_of_sublist sl₁ $ mem_cons_self _ _) end theorem pairwise_sublists {R} {l : list α} (H : pairwise R l) : pairwise (λ l₁ l₂, lex R (reverse l₁) (reverse l₂)) (sublists l) := by have := pairwise_sublists' (pairwise_reverse.2 H); rwa [sublists'_reverse, pairwise_map] at this /- pairwise reduct -/ variable [decidable_rel R] @[simp] theorem pw_filter_nil : pw_filter R [] = [] := rfl @[simp] theorem pw_filter_cons_of_pos {a : α} {l : list α} (h : ∀ b ∈ pw_filter R l, R a b) : pw_filter R (a::l) = a :: pw_filter R l := if_pos h @[simp] theorem pw_filter_cons_of_neg {a : α} {l : list α} (h : ¬ ∀ b ∈ pw_filter R l, R a b) : pw_filter R (a::l) = pw_filter R l := if_neg h theorem pw_filter_map (f : β → α) : Π (l : list β), pw_filter R (map f l) = map f (pw_filter (λ x y, R (f x) (f y)) l) | [] := rfl | (x :: xs) := if h : ∀ b ∈ pw_filter R (map f xs), R (f x) b then have h' : ∀ (b : β), b ∈ pw_filter (λ (x y : β), R (f x) (f y)) xs → R (f x) (f b), from λ b hb, h _ (by rw [pw_filter_map]; apply mem_map_of_mem _ hb), by rw [map,pw_filter_cons_of_pos h,pw_filter_cons_of_pos h',pw_filter_map,map] else have h' : ¬∀ (b : β), b ∈ pw_filter (λ (x y : β), R (f x) (f y)) xs → R (f x) (f b), from λ hh, h $ λ a ha, by { rw [pw_filter_map,mem_map] at ha, rcases ha with ⟨b,hb₀,hb₁⟩, subst a, exact hh _ hb₀, }, by rw [map,pw_filter_cons_of_neg h,pw_filter_cons_of_neg h',pw_filter_map] theorem pw_filter_sublist : ∀ (l : list α), pw_filter R l <+ l | [] := nil_sublist _ | (x::l) := begin by_cases (∀ y ∈ pw_filter R l, R x y), { rw [pw_filter_cons_of_pos h], exact cons_sublist_cons _ (pw_filter_sublist l) }, { rw [pw_filter_cons_of_neg h], exact sublist_cons_of_sublist _ (pw_filter_sublist l) }, end theorem pw_filter_subset (l : list α) : pw_filter R l ⊆ l := subset_of_sublist (pw_filter_sublist _) theorem pairwise_pw_filter : ∀ (l : list α), pairwise R (pw_filter R l) | [] := pairwise.nil | (x::l) := begin by_cases (∀ y ∈ pw_filter R l, R x y), { rw [pw_filter_cons_of_pos h], exact pairwise_cons.2 ⟨h, pairwise_pw_filter l⟩ }, { rw [pw_filter_cons_of_neg h], exact pairwise_pw_filter l }, end theorem pw_filter_eq_self {l : list α} : pw_filter R l = l ↔ pairwise R l := ⟨λ e, e ▸ pairwise_pw_filter l, λ p, begin induction l with x l IH, {refl}, cases pairwise_cons.1 p with al p, rw [pw_filter_cons_of_pos (ball.imp_left (pw_filter_subset l) al), IH p], end⟩ @[simp] theorem pw_filter_idempotent {l : list α} : pw_filter R (pw_filter R l) = pw_filter R l := pw_filter_eq_self.mpr (pairwise_pw_filter l) theorem forall_mem_pw_filter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z) (a : α) (l : list α) : (∀ b ∈ pw_filter R l, R a b) ↔ (∀ b ∈ l, R a b) := ⟨begin induction l with x l IH, { exact λ _ _, false.elim }, simp only [forall_mem_cons], by_cases (∀ y ∈ pw_filter R l, R x y); dsimp at h, { simp only [pw_filter_cons_of_pos h, forall_mem_cons, and_imp], exact λ r H, ⟨r, IH H⟩ }, { rw [pw_filter_cons_of_neg h], refine λ H, ⟨_, IH H⟩, cases e : find (λ y, ¬ R x y) (pw_filter R l) with k, { refine h.elim (ball.imp_right _ (find_eq_none.1 e)), exact λ y _, not_not.1 }, { have := find_some e, exact (neg_trans (H k (find_mem e))).resolve_right this } } end, ball.imp_left (pw_filter_subset l)⟩ end pairwise /- chain relation (conjunction of R a b ∧ R b c ∧ R c d ...) -/ section chain run_cmd tactic.mk_iff_of_inductive_prop `list.chain `list.chain_iff variable {R : α → α → Prop} theorem rel_of_chain_cons {a b : α} {l : list α} (p : chain R a (b::l)) : R a b := (chain_cons.1 p).1 theorem chain_of_chain_cons {a b : α} {l : list α} (p : chain R a (b::l)) : chain R b l := (chain_cons.1 p).2 theorem chain.imp {S : α → α → Prop} (H : ∀ a b, R a b → S a b) {a : α} {l : list α} (p : chain R a l) : chain S a l := by induction p with _ a b l r p IH; constructor; [exact H _ _ r, exact IH] theorem chain.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {a : α} {l : list α} : chain R a l ↔ chain S a l := ⟨chain.imp (λ a b, (H a b).1), chain.imp (λ a b, (H a b).2)⟩ theorem chain.iff_mem {a : α} {l : list α} : chain R a l ↔ chain (λ x y, x ∈ a :: l ∧ y ∈ l ∧ R x y) a l := ⟨λ p, by induction p with _ a b l r p IH; constructor; [exact ⟨mem_cons_self _ _, mem_cons_self _ _, r⟩, exact IH.imp (λ a b ⟨am, bm, h⟩, ⟨mem_cons_of_mem _ am, mem_cons_of_mem _ bm, h⟩)], chain.imp (λ a b h, h.2.2)⟩ theorem chain_singleton {a b : α} : chain R a [b] ↔ R a b := by simp only [chain_cons, chain.nil, and_true] theorem chain_split {a b : α} {l₁ l₂ : list α} : chain R a (l₁++b::l₂) ↔ chain R a (l₁++[b]) ∧ chain R b l₂ := by induction l₁ with x l₁ IH generalizing a; simp only [*, nil_append, cons_append, chain.nil, chain_cons, and_true, and_assoc] theorem chain_map (f : β → α) {b : β} {l : list β} : chain R (f b) (map f l) ↔ chain (λ a b : β, R (f a) (f b)) b l := by induction l generalizing b; simp only [map, chain.nil, chain_cons, *] theorem chain_of_chain_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b) {a : α} {l : list α} (p : chain S (f a) (map f l)) : chain R a l := ((chain_map f).1 p).imp H theorem chain_map_of_chain {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b)) {a : α} {l : list α} (p : chain R a l) : chain S (f a) (map f l) := (chain_map f).2 $ p.imp H theorem chain_of_pairwise {a : α} {l : list α} (p : pairwise R (a::l)) : chain R a l := begin cases pairwise_cons.1 p with r p', clear p, induction p' with b l r' p IH generalizing a, {exact chain.nil}, simp only [chain_cons, forall_mem_cons] at r, exact chain_cons.2 ⟨r.1, IH r'⟩ end theorem chain_iff_pairwise (tr : transitive R) {a : α} {l : list α} : chain R a l ↔ pairwise R (a::l) := ⟨λ c, begin induction c with b b c l r p IH, {exact pairwise_singleton _ _}, apply IH.cons _, simp only [mem_cons_iff, forall_mem_cons', r, true_and], show ∀ x ∈ l, R b x, from λ x m, (tr r (rel_of_pairwise_cons IH m)), end, chain_of_pairwise⟩ theorem chain'.imp {S : α → α → Prop} (H : ∀ a b, R a b → S a b) {l : list α} (p : chain' R l) : chain' S l := by cases l; [trivial, exact p.imp H] theorem chain'.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : list α} : chain' R l ↔ chain' S l := ⟨chain'.imp (λ a b, (H a b).1), chain'.imp (λ a b, (H a b).2)⟩ theorem chain'.iff_mem : ∀ {l : list α}, chain' R l ↔ chain' (λ x y, x ∈ l ∧ y ∈ l ∧ R x y) l | [] := iff.rfl | (x::l) := ⟨λ h, (chain.iff_mem.1 h).imp $ λ a b ⟨h₁, h₂, h₃⟩, ⟨h₁, or.inr h₂, h₃⟩, chain'.imp $ λ a b h, h.2.2⟩ theorem chain'_singleton (a : α) : chain' R [a] := chain.nil theorem chain'_split {a : α} : ∀ {l₁ l₂ : list α}, chain' R (l₁++a::l₂) ↔ chain' R (l₁++[a]) ∧ chain' R (a::l₂) | [] l₂ := (and_iff_right (chain'_singleton a)).symm | (b::l₁) l₂ := chain_split theorem chain'_map (f : β → α) {l : list β} : chain' R (map f l) ↔ chain' (λ a b : β, R (f a) (f b)) l := by cases l; [refl, exact chain_map _] theorem chain'_of_chain'_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b) {l : list α} (p : chain' S (map f l)) : chain' R l := ((chain'_map f).1 p).imp H theorem chain'_map_of_chain' {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b)) {l : list α} (p : chain' R l) : chain' S (map f l) := (chain'_map f).2 $ p.imp H theorem chain'_of_pairwise : ∀ {l : list α}, pairwise R l → chain' R l | [] _ := trivial | (a::l) h := chain_of_pairwise h theorem chain'_iff_pairwise (tr : transitive R) : ∀ {l : list α}, chain' R l ↔ pairwise R l | [] := (iff_true_intro pairwise.nil).symm | (a::l) := chain_iff_pairwise tr end chain /- no duplicates predicate -/ section nodup @[simp] theorem forall_mem_ne {a : α} {l : list α} : (∀ (a' : α), a' ∈ l → ¬a = a') ↔ a ∉ l := ⟨λ h m, h _ m rfl, λ h a' m e, h (e.symm ▸ m)⟩ @[simp] theorem nodup_nil : @nodup α [] := pairwise.nil @[simp] theorem nodup_cons {a : α} {l : list α} : nodup (a::l) ↔ a ∉ l ∧ nodup l := by simp only [nodup, pairwise_cons, forall_mem_ne] lemma rel_nodup {r : α → β → Prop} (hr : relator.bi_unique r) : (forall₂ r ⇒ (↔)) nodup nodup | _ _ forall₂.nil := by simp only [nodup_nil] | _ _ (forall₂.cons hab h) := by simpa only [nodup_cons] using relator.rel_and (relator.rel_not (rel_mem hr hab h)) (rel_nodup h) theorem nodup_cons_of_nodup {a : α} {l : list α} (m : a ∉ l) (n : nodup l) : nodup (a::l) := nodup_cons.2 ⟨m, n⟩ theorem nodup_singleton (a : α) : nodup [a] := nodup_cons_of_nodup (not_mem_nil a) nodup_nil theorem nodup_of_nodup_cons {a : α} {l : list α} (h : nodup (a::l)) : nodup l := (nodup_cons.1 h).2 theorem not_mem_of_nodup_cons {a : α} {l : list α} (h : nodup (a::l)) : a ∉ l := (nodup_cons.1 h).1 theorem not_nodup_cons_of_mem {a : α} {l : list α} : a ∈ l → ¬ nodup (a :: l) := imp_not_comm.1 not_mem_of_nodup_cons theorem nodup_of_sublist {l₁ l₂ : list α} : l₁ <+ l₂ → nodup l₂ → nodup l₁ := pairwise_of_sublist theorem not_nodup_pair (a : α) : ¬ nodup [a, a] := not_nodup_cons_of_mem $ mem_singleton_self _ theorem nodup_iff_sublist {l : list α} : nodup l ↔ ∀ a, ¬ [a, a] <+ l := ⟨λ d a h, not_nodup_pair a (nodup_of_sublist h d), begin induction l with a l IH; intro h, {exact nodup_nil}, exact nodup_cons_of_nodup (λ al, h a $ cons_sublist_cons _ $ singleton_sublist.2 al) (IH $ λ a s, h a $ sublist_cons_of_sublist _ s) end⟩ theorem nodup_iff_nth_le_inj {l : list α} : nodup l ↔ ∀ i j h₁ h₂, nth_le l i h₁ = nth_le l j h₂ → i = j := pairwise_iff_nth_le.trans ⟨λ H i j h₁ h₂ h, ((lt_trichotomy _ _) .resolve_left (λ h', H _ _ h₂ h' h)) .resolve_right (λ h', H _ _ h₁ h' h.symm), λ H i j h₁ h₂ h, ne_of_lt h₂ (H _ _ _ _ h)⟩ @[simp] theorem nth_le_index_of [decidable_eq α] {l : list α} (H : nodup l) (n h) : index_of (nth_le l n h) l = n := nodup_iff_nth_le_inj.1 H _ _ _ h $ index_of_nth_le $ index_of_lt_length.2 $ nth_le_mem _ _ _ theorem nodup_iff_count_le_one [decidable_eq α] {l : list α} : nodup l ↔ ∀ a, count a l ≤ 1 := nodup_iff_sublist.trans $ forall_congr $ λ a, have [a, a] <+ l ↔ 1 < count a l, from (@le_count_iff_repeat_sublist _ _ a l 2).symm, (not_congr this).trans not_lt theorem nodup_repeat (a : α) : ∀ {n : ℕ}, nodup (repeat a n) ↔ n ≤ 1 | 0 := by simp [nat.zero_le] | 1 := by simp | (n+2) := iff_of_false (λ H, nodup_iff_sublist.1 H a ((repeat_sublist_repeat _).2 (le_add_left 2 n))) (not_le_of_lt $ le_add_left 2 n) @[simp] theorem count_eq_one_of_mem [decidable_eq α] {a : α} {l : list α} (d : nodup l) (h : a ∈ l) : count a l = 1 := le_antisymm (nodup_iff_count_le_one.1 d a) (count_pos.2 h) theorem nodup_of_nodup_append_left {l₁ l₂ : list α} : nodup (l₁++l₂) → nodup l₁ := nodup_of_sublist (sublist_append_left l₁ l₂) theorem nodup_of_nodup_append_right {l₁ l₂ : list α} : nodup (l₁++l₂) → nodup l₂ := nodup_of_sublist (sublist_append_right l₁ l₂) theorem nodup_append {l₁ l₂ : list α} : nodup (l₁++l₂) ↔ nodup l₁ ∧ nodup l₂ ∧ disjoint l₁ l₂ := by simp only [nodup, pairwise_append, disjoint_iff_ne] theorem disjoint_of_nodup_append {l₁ l₂ : list α} (d : nodup (l₁++l₂)) : disjoint l₁ l₂ := (nodup_append.1 d).2.2 theorem nodup_append_of_nodup {l₁ l₂ : list α} (d₁ : nodup l₁) (d₂ : nodup l₂) (dj : disjoint l₁ l₂) : nodup (l₁++l₂) := nodup_append.2 ⟨d₁, d₂, dj⟩ theorem nodup_append_comm {l₁ l₂ : list α} : nodup (l₁++l₂) ↔ nodup (l₂++l₁) := by simp only [nodup_append, and.left_comm, disjoint_comm] theorem nodup_middle {a : α} {l₁ l₂ : list α} : nodup (l₁ ++ a::l₂) ↔ nodup (a::(l₁++l₂)) := by simp only [nodup_append, not_or_distrib, and.left_comm, and_assoc, nodup_cons, mem_append, disjoint_cons_right] theorem nodup_of_nodup_map (f : α → β) {l : list α} : nodup (map f l) → nodup l := pairwise_of_pairwise_map f $ λ a b, mt $ congr_arg f theorem nodup_map_on {f : α → β} {l : list α} (H : ∀x∈l, ∀y∈l, f x = f y → x = y) (d : nodup l) : nodup (map f l) := pairwise_map_of_pairwise _ (by exact λ a b ⟨ma, mb, n⟩ e, n (H a ma b mb e)) (pairwise.and_mem.1 d) theorem nodup_map {f : α → β} {l : list α} (hf : injective f) : nodup l → nodup (map f l) := nodup_map_on (assume x _ y _ h, hf h) theorem nodup_map_iff {f : α → β} {l : list α} (hf : injective f) : nodup (map f l) ↔ nodup l := ⟨nodup_of_nodup_map _, nodup_map hf⟩ @[simp] theorem nodup_attach {l : list α} : nodup (attach l) ↔ nodup l := ⟨λ h, attach_map_val l ▸ nodup_map (λ a b, subtype.eq) h, λ h, nodup_of_nodup_map subtype.val ((attach_map_val l).symm ▸ h)⟩ theorem nodup_pmap {p : α → Prop} {f : Π a, p a → β} {l : list α} {H} (hf : ∀ a ha b hb, f a ha = f b hb → a = b) (h : nodup l) : nodup (pmap f l H) := by rw [pmap_eq_map_attach]; exact nodup_map (λ ⟨a, ha⟩ ⟨b, hb⟩ h, by congr; exact hf a (H _ ha) b (H _ hb) h) (nodup_attach.2 h) theorem nodup_filter (p : α → Prop) [decidable_pred p] {l} : nodup l → nodup (filter p l) := pairwise_filter_of_pairwise p @[simp] theorem nodup_reverse {l : list α} : nodup (reverse l) ↔ nodup l := pairwise_reverse.trans $ by simp only [nodup, ne.def, eq_comm] theorem nodup_erase_eq_filter [decidable_eq α] (a : α) {l} (d : nodup l) : l.erase a = filter (≠ a) l := begin induction d with b l m d IH, {refl}, by_cases b = a, { subst h, rw [erase_cons_head, filter_cons_of_neg], symmetry, rw filter_eq_self, simpa only [ne.def, eq_comm] using m, exact not_not_intro rfl }, { rw [erase_cons_tail _ h, filter_cons_of_pos, IH], exact h } end theorem nodup_erase_of_nodup [decidable_eq α] (a : α) {l} : nodup l → nodup (l.erase a) := nodup_of_sublist (erase_sublist _ _) theorem nodup_diff [decidable_eq α] : ∀ {l₁ l₂ : list α} (h : l₁.nodup), (l₁.diff l₂).nodup | l₁ [] h := h | l₁ (a::l₂) h := by rw diff_cons; exact nodup_diff (nodup_erase_of_nodup _ h) theorem mem_erase_iff_of_nodup [decidable_eq α] {a b : α} {l} (d : nodup l) : a ∈ l.erase b ↔ a ≠ b ∧ a ∈ l := by rw nodup_erase_eq_filter b d; simp only [mem_filter, and_comm] theorem mem_erase_of_nodup [decidable_eq α] {a : α} {l} (h : nodup l) : a ∉ l.erase a := λ H, ((mem_erase_iff_of_nodup h).1 H).1 rfl theorem nodup_join {L : list (list α)} : nodup (join L) ↔ (∀ l ∈ L, nodup l) ∧ pairwise disjoint L := by simp only [nodup, pairwise_join, disjoint_left.symm, forall_mem_ne] theorem nodup_bind {l₁ : list α} {f : α → list β} : nodup (l₁.bind f) ↔ (∀ x ∈ l₁, nodup (f x)) ∧ pairwise (λ (a b : α), disjoint (f a) (f b)) l₁ := by simp only [list.bind, nodup_join, pairwise_map, and_comm, and.left_comm, mem_map, exists_imp_distrib, and_imp]; rw [show (∀ (l : list β) (x : α), f x = l → x ∈ l₁ → nodup l) ↔ (∀ (x : α), x ∈ l₁ → nodup (f x)), from forall_swap.trans $ forall_congr $ λ_, forall_eq'] theorem nodup_product {l₁ : list α} {l₂ : list β} (d₁ : nodup l₁) (d₂ : nodup l₂) : nodup (product l₁ l₂) := nodup_bind.2 ⟨λ a ma, nodup_map (injective_of_left_inverse (λ b, (rfl : (a,b).2 = b))) d₂, d₁.imp $ λ a₁ a₂ n x h₁ h₂, begin rcases mem_map.1 h₁ with ⟨b₁, mb₁, rfl⟩, rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩, exact n rfl end⟩ theorem nodup_sigma {σ : α → Type*} {l₁ : list α} {l₂ : Π a, list (σ a)} (d₁ : nodup l₁) (d₂ : ∀ a, nodup (l₂ a)) : nodup (l₁.sigma l₂) := nodup_bind.2 ⟨λ a ma, nodup_map (λ b b' h, by injection h with _ h; exact eq_of_heq h) (d₂ a), d₁.imp $ λ a₁ a₂ n x h₁ h₂, begin rcases mem_map.1 h₁ with ⟨b₁, mb₁, rfl⟩, rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩, exact n rfl end⟩ theorem nodup_filter_map {f : α → option β} {l : list α} (H : ∀ (a a' : α) (b : β), b ∈ f a → b ∈ f a' → a = a') : nodup l → nodup (filter_map f l) := pairwise_filter_map_of_pairwise f $ λ a a' n b bm b' bm' e, n $ H a a' b' (e ▸ bm) bm' theorem nodup_concat {a : α} {l : list α} (h : a ∉ l) (h' : nodup l) : nodup (concat l a) := by rw concat_eq_append; exact nodup_append_of_nodup h' (nodup_singleton _) (disjoint_singleton.2 h) theorem nodup_insert [decidable_eq α] {a : α} {l : list α} (h : nodup l) : nodup (insert a l) := if h' : a ∈ l then by rw [insert_of_mem h']; exact h else by rw [insert_of_not_mem h', nodup_cons]; split; assumption theorem nodup_union [decidable_eq α] (l₁ : list α) {l₂ : list α} (h : nodup l₂) : nodup (l₁ ∪ l₂) := begin induction l₁ with a l₁ ih generalizing l₂, { exact h }, apply nodup_insert, exact ih h end theorem nodup_inter_of_nodup [decidable_eq α] {l₁ : list α} (l₂) : nodup l₁ → nodup (l₁ ∩ l₂) := nodup_filter _ @[simp] theorem nodup_sublists {l : list α} : nodup (sublists l) ↔ nodup l := ⟨λ h, nodup_of_nodup_map _ (nodup_of_sublist (map_ret_sublist_sublists _) h), λ h, (pairwise_sublists h).imp (λ _ _ h, mt reverse_inj.2 h.to_ne)⟩ @[simp] theorem nodup_sublists' {l : list α} : nodup (sublists' l) ↔ nodup l := by rw [sublists'_eq_sublists, nodup_map_iff reverse_injective, nodup_sublists, nodup_reverse] lemma nodup_sublists_len {α : Type*} (n) {l : list α} (nd : nodup l) : (sublists_len n l).nodup := nodup_of_sublist (sublists_len_sublist_sublists' _ _) (nodup_sublists'.2 nd) lemma diff_eq_filter_of_nodup [decidable_eq α] : ∀ {l₁ l₂ : list α} (hl₁ : l₁.nodup), l₁.diff l₂ = l₁.filter (∉ l₂) | l₁ [] hl₁ := by simp | l₁ (a::l₂) hl₁ := begin rw [diff_cons, diff_eq_filter_of_nodup (nodup_erase_of_nodup _ hl₁), nodup_erase_eq_filter _ hl₁, filter_filter], simp only [mem_cons_iff, not_or_distrib, and.comm], congr end lemma mem_diff_iff_of_nodup [decidable_eq α] {l₁ l₂ : list α} (hl₁ : l₁.nodup) {a : α} : a ∈ l₁.diff l₂ ↔ a ∈ l₁ ∧ a ∉ l₂ := by rw [diff_eq_filter_of_nodup hl₁, mem_filter] lemma nodup_update_nth : ∀ {l : list α} {n : ℕ} {a : α} (hl : l.nodup) (ha : a ∉ l), (l.update_nth n a).nodup | [] n a hl ha := nodup_nil | (b::l) 0 a hl ha := nodup_cons.2 ⟨mt (mem_cons_of_mem _) ha, (nodup_cons.1 hl).2⟩ | (b::l) (n+1) a hl ha := nodup_cons.2 ⟨λ h, (mem_or_eq_of_mem_update_nth h).elim (nodup_cons.1 hl).1 (λ hba, ha (hba ▸ mem_cons_self _ _)), nodup_update_nth (nodup_cons.1 hl).2 (mt (mem_cons_of_mem _) ha)⟩ end nodup /- erase duplicates function -/ section erase_dup variable [decidable_eq α] @[simp] theorem erase_dup_nil : erase_dup [] = ([] : list α) := rfl theorem erase_dup_cons_of_mem' {a : α} {l : list α} (h : a ∈ erase_dup l) : erase_dup (a::l) = erase_dup l := pw_filter_cons_of_neg $ by simpa only [forall_mem_ne] using h theorem erase_dup_cons_of_not_mem' {a : α} {l : list α} (h : a ∉ erase_dup l) : erase_dup (a::l) = a :: erase_dup l := pw_filter_cons_of_pos $ by simpa only [forall_mem_ne] using h @[simp] theorem mem_erase_dup {a : α} {l : list α} : a ∈ erase_dup l ↔ a ∈ l := by simpa only [erase_dup, forall_mem_ne, not_not] using not_congr (@forall_mem_pw_filter α (≠) _ (λ x y z xz, not_and_distrib.1 $ mt (and.rec eq.trans) xz) a l) @[simp] theorem erase_dup_cons_of_mem {a : α} {l : list α} (h : a ∈ l) : erase_dup (a::l) = erase_dup l := erase_dup_cons_of_mem' $ mem_erase_dup.2 h @[simp] theorem erase_dup_cons_of_not_mem {a : α} {l : list α} (h : a ∉ l) : erase_dup (a::l) = a :: erase_dup l := erase_dup_cons_of_not_mem' $ mt mem_erase_dup.1 h theorem erase_dup_sublist : ∀ (l : list α), erase_dup l <+ l := pw_filter_sublist theorem erase_dup_subset : ∀ (l : list α), erase_dup l ⊆ l := pw_filter_subset theorem subset_erase_dup (l : list α) : l ⊆ erase_dup l := λ a, mem_erase_dup.2 theorem nodup_erase_dup : ∀ l : list α, nodup (erase_dup l) := pairwise_pw_filter theorem erase_dup_eq_self {l : list α} : erase_dup l = l ↔ nodup l := pw_filter_eq_self @[simp] theorem erase_dup_idempotent {l : list α} : erase_dup (erase_dup l) = erase_dup l := pw_filter_idempotent theorem erase_dup_append (l₁ l₂ : list α) : erase_dup (l₁ ++ l₂) = l₁ ∪ erase_dup l₂ := begin induction l₁ with a l₁ IH, {refl}, rw [cons_union, ← IH], show erase_dup (a :: (l₁ ++ l₂)) = insert a (erase_dup (l₁ ++ l₂)), by_cases a ∈ erase_dup (l₁ ++ l₂); [ rw [erase_dup_cons_of_mem' h, insert_of_mem h], rw [erase_dup_cons_of_not_mem' h, insert_of_not_mem h]] end end erase_dup /- iota and range(') -/ @[simp] theorem length_range' : ∀ (s n : ℕ), length (range' s n) = n | s 0 := rfl | s (n+1) := congr_arg succ (length_range' _ _) @[simp] theorem mem_range' {m : ℕ} : ∀ {s n : ℕ}, m ∈ range' s n ↔ s ≤ m ∧ m < s + n | s 0 := (false_iff _).2 $ λ ⟨H1, H2⟩, not_le_of_lt H2 H1 | s (succ n) := have m = s → m < s + n + 1, from λ e, e ▸ lt_succ_of_le (le_add_right _ _), have l : m = s ∨ s + 1 ≤ m ↔ s ≤ m, by simpa only [eq_comm] using (@le_iff_eq_or_lt _ _ s m).symm, (mem_cons_iff _ _ _).trans $ by simp only [mem_range', or_and_distrib_left, or_iff_right_of_imp this, l, add_right_comm]; refl theorem map_add_range' (a) : ∀ s n : ℕ, map ((+) a) (range' s n) = range' (a + s) n | s 0 := rfl | s (n+1) := congr_arg (cons _) (map_add_range' (s+1) n) theorem map_sub_range' (a) : ∀ (s n : ℕ) (h : a ≤ s), map (λ x, x - a) (range' s n) = range' (s - a) n | s 0 _ := rfl | s (n+1) h := begin convert congr_arg (cons (s-a)) (map_sub_range' (s+1) n (nat.le_succ_of_le h)), rw nat.succ_sub h, refl, end theorem chain_succ_range' : ∀ s n : ℕ, chain (λ a b, b = succ a) s (range' (s+1) n) | s 0 := chain.nil | s (n+1) := (chain_succ_range' (s+1) n).cons rfl theorem chain_lt_range' (s n : ℕ) : chain (<) s (range' (s+1) n) := (chain_succ_range' s n).imp (λ a b e, e.symm ▸ lt_succ_self _) theorem pairwise_lt_range' : ∀ s n : ℕ, pairwise (<) (range' s n) | s 0 := pairwise.nil | s (n+1) := (chain_iff_pairwise (by exact λ a b c, lt_trans)).1 (chain_lt_range' s n) theorem nodup_range' (s n : ℕ) : nodup (range' s n) := (pairwise_lt_range' s n).imp (λ a b, ne_of_lt) @[simp] theorem range'_append : ∀ s m n : ℕ, range' s m ++ range' (s+m) n = range' s (n+m) | s 0 n := rfl | s (m+1) n := show s :: (range' (s+1) m ++ range' (s+m+1) n) = s :: range' (s+1) (n+m), by rw [add_right_comm, range'_append] theorem range'_sublist_right {s m n : ℕ} : range' s m <+ range' s n ↔ m ≤ n := ⟨λ h, by simpa only [length_range'] using length_le_of_sublist h, λ h, by rw [← nat.sub_add_cancel h, ← range'_append]; apply sublist_append_left⟩ theorem range'_subset_right {s m n : ℕ} : range' s m ⊆ range' s n ↔ m ≤ n := ⟨λ h, le_of_not_lt $ λ hn, lt_irrefl (s+n) $ (mem_range'.1 $ h $ mem_range'.2 ⟨le_add_right _ _, nat.add_lt_add_left hn s⟩).2, λ h, subset_of_sublist (range'_sublist_right.2 h)⟩ theorem nth_range' : ∀ s {m n : ℕ}, m < n → nth (range' s n) m = some (s + m) | s 0 (n+1) _ := rfl | s (m+1) (n+1) h := (nth_range' (s+1) (lt_of_add_lt_add_right h)).trans $ by rw add_right_comm; refl theorem range'_concat (s n : ℕ) : range' s (n + 1) = range' s n ++ [s+n] := by rw add_comm n 1; exact (range'_append s n 1).symm theorem range_core_range' : ∀ s n : ℕ, range_core s (range' s n) = range' 0 (n + s) | 0 n := rfl | (s+1) n := by rw [show n+(s+1) = n+1+s, from add_right_comm n s 1]; exact range_core_range' s (n+1) theorem range_eq_range' (n : ℕ) : range n = range' 0 n := (range_core_range' n 0).trans $ by rw zero_add theorem range_succ_eq_map (n : ℕ) : range (n + 1) = 0 :: map succ (range n) := by rw [range_eq_range', range_eq_range', range', add_comm, ← map_add_range']; congr; exact funext one_add theorem range'_eq_map_range (s n : ℕ) : range' s n = map ((+) s) (range n) := by rw [range_eq_range', map_add_range']; refl @[simp] theorem length_range (n : ℕ) : length (range n) = n := by simp only [range_eq_range', length_range'] theorem pairwise_lt_range (n : ℕ) : pairwise (<) (range n) := by simp only [range_eq_range', pairwise_lt_range'] theorem nodup_range (n : ℕ) : nodup (range n) := by simp only [range_eq_range', nodup_range'] theorem range_sublist {m n : ℕ} : range m <+ range n ↔ m ≤ n := by simp only [range_eq_range', range'_sublist_right] theorem range_subset {m n : ℕ} : range m ⊆ range n ↔ m ≤ n := by simp only [range_eq_range', range'_subset_right] @[simp] theorem mem_range {m n : ℕ} : m ∈ range n ↔ m < n := by simp only [range_eq_range', mem_range', nat.zero_le, true_and, zero_add] @[simp] theorem not_mem_range_self {n : ℕ} : n ∉ range n := mt mem_range.1 $ lt_irrefl _ theorem nth_range {m n : ℕ} (h : m < n) : nth (range n) m = some m := by simp only [range_eq_range', nth_range' _ h, zero_add] theorem range_concat (n : ℕ) : range (succ n) = range n ++ [n] := by simp only [range_eq_range', range'_concat, zero_add] theorem iota_eq_reverse_range' : ∀ n : ℕ, iota n = reverse (range' 1 n) | 0 := rfl | (n+1) := by simp only [iota, range'_concat, iota_eq_reverse_range' n, reverse_append, add_comm]; refl @[simp] theorem length_iota (n : ℕ) : length (iota n) = n := by simp only [iota_eq_reverse_range', length_reverse, length_range'] theorem pairwise_gt_iota (n : ℕ) : pairwise (>) (iota n) := by simp only [iota_eq_reverse_range', pairwise_reverse, pairwise_lt_range'] theorem nodup_iota (n : ℕ) : nodup (iota n) := by simp only [iota_eq_reverse_range', nodup_reverse, nodup_range'] theorem mem_iota {m n : ℕ} : m ∈ iota n ↔ 1 ≤ m ∧ m ≤ n := by simp only [iota_eq_reverse_range', mem_reverse, mem_range', add_comm, lt_succ_iff] theorem reverse_range' : ∀ s n : ℕ, reverse (range' s n) = map (λ i, s + n - 1 - i) (range n) | s 0 := rfl | s (n+1) := by rw [range'_concat, reverse_append, range_succ_eq_map]; simpa only [show s + (n + 1) - 1 = s + n, from rfl, (∘), λ a i, show a - 1 - i = a - succ i, from pred_sub _ _, reverse_singleton, map_cons, nat.sub_zero, cons_append, nil_append, eq_self_iff_true, true_and, map_map] using reverse_range' s n def fin_range (n : ℕ) : list (fin n) := (range n).pmap fin.mk (λ _, list.mem_range.1) @[simp] lemma mem_fin_range {n : ℕ} (a : fin n) : a ∈ fin_range n := mem_pmap.2 ⟨a.1, mem_range.2 a.2, fin.eta _ _⟩ lemma nodup_fin_range (n : ℕ) : (fin_range n).nodup := nodup_pmap (λ _ _ _ _, fin.veq_of_eq) (nodup_range _) @[simp] lemma length_fin_range (n : ℕ) : (fin_range n).length = n := by rw [fin_range, length_pmap, length_range] @[to_additive] theorem prod_range_succ {α : Type u} [monoid α] (f : ℕ → α) (n : ℕ) : ((range n.succ).map f).prod = ((range n).map f).prod * f n := by rw [range_concat, map_append, map_singleton, prod_append, prod_cons, prod_nil, mul_one] /-- `Ico n m` is the list of natural numbers `n ≤ x < m`. (Ico stands for "interval, closed-open".) See also `data/set/intervals.lean` for `set.Ico`, modelling intervals in general preorders, and `multiset.Ico` and `finset.Ico` for `n ≤ x < m` as a multiset or as a finset. @TODO (anyone): Define `Ioo` and `Icc`, state basic lemmas about them. @TODO (anyone): Prove that `finset.Ico` and `set.Ico` agree. @TODO (anyone): Also do the versions for integers? @TODO (anyone): One could generalise even further, defining 'locally finite partial orders', for which `set.Ico a b` is `[finite]`, and 'locally finite total orders', for which there is a list model. -/ def Ico (n m : ℕ) : list ℕ := range' n (m - n) namespace Ico theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, nat.sub_zero, range_eq_range'] @[simp] theorem length (n m : ℕ) : length (Ico n m) = m - n := by dsimp [Ico]; simp only [length_range'] theorem pairwise_lt (n m : ℕ) : pairwise (<) (Ico n m) := by dsimp [Ico]; simp only [pairwise_lt_range'] theorem nodup (n m : ℕ) : nodup (Ico n m) := by dsimp [Ico]; simp only [nodup_range'] @[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m, by simp [Ico, this], begin cases le_total n m with hnm hmn, { rw [nat.add_sub_of_le hnm] }, { rw [nat.sub_eq_zero_of_le hmn, add_zero], exact and_congr_right (assume hnl, iff.intro (assume hln, (not_le_of_gt hln hnl).elim) (assume hlm, lt_of_lt_of_le hlm hmn)) } end theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by simp [Ico, nat.sub_eq_zero_of_le h] theorem map_add (n m k : ℕ) : (Ico n m).map ((+) k) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', nat.add_sub_add_right, add_comm n k] theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : (Ico n m).map (λ x, x - k) = Ico (n - k) (m - k) := begin by_cases h₂ : n < m, { rw [Ico, Ico], rw nat.sub_sub_sub_cancel_right h₁, rw [map_sub_range' _ _ _ h₁] }, { simp at h₂, rw [eq_nil_of_le h₂], rw [eq_nil_of_le (nat.sub_le_sub_right h₂ _)], refl } end @[simp] theorem self_empty {n : ℕ} : Ico n n = [] := eq_nil_of_le (le_refl n) @[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n := iff.intro (assume h, nat.le_of_sub_eq_zero $ by rw [← length, h]; refl) eq_nil_of_le lemma append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : Ico n m ++ Ico m l = Ico n l := begin dunfold Ico, convert range'_append _ _ _, { exact (nat.add_sub_of_le hnm).symm }, { rwa [← nat.add_sub_assoc hnm, nat.sub_add_cancel] } end @[simp] lemma inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := begin apply eq_nil_iff_forall_not_mem.2, intro a, simp only [and_imp, not_and, not_lt, list.mem_inter, list.Ico.mem], intros h₁ h₂ h₃, exfalso, exact not_lt_of_ge h₃ h₂ end @[simp] lemma bag_inter_consecutive (n m l : ℕ) : list.bag_inter (Ico n m) (Ico m l) = [] := (bag_inter_nil_iff_inter_nil _ _).2 (inter_consecutive n m l) @[simp] theorem succ_singleton {n : ℕ} : Ico n (n+1) = [n] := by dsimp [Ico]; simp [nat.add_sub_cancel_left] theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] := by rwa [← succ_singleton, append_consecutive]; exact nat.le_succ _ theorem eq_cons {n m : ℕ} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by rw [← append_consecutive (nat.le_succ n) h, succ_singleton]; refl @[simp] theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by dsimp [Ico]; rw nat.sub_sub_self h; simp theorem chain'_succ (n m : ℕ) : chain' (λa b, b = succ a) (Ico n m) := begin by_cases n < m, { rw [eq_cons h], exact chain_succ_range' _ _ }, { rw [eq_nil_of_le (le_of_not_gt h)], trivial } end @[simp] theorem not_mem_top {n m : ℕ} : m ∉ Ico n m := by simp; intros; refl lemma filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, x < l) = Ico n m := filter_eq_self.2 $ assume k hk, lt_of_lt_of_le (mem.1 hk).2 hml lemma filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, x < l) = [] := filter_eq_nil.2 $ assume k hk, not_lt_of_le $ le_trans hln $ (mem.1 hk).1 lemma filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) : (Ico n m).filter (λ x, x < l) = Ico n l := begin cases le_total n l with hnl hln, { rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] }, { rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] } end @[simp] lemma filter_lt (n m l : ℕ) : (Ico n m).filter (λ x, x < l) = Ico n (min m l) := begin cases le_total m l with hml hlm, { rw [min_eq_left hml, filter_lt_of_top_le hml] }, { rw [min_eq_right hlm, filter_lt_of_ge hlm] } end lemma filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, l ≤ x) = Ico n m := filter_eq_self.2 $ assume k hk, le_trans hln (mem.1 hk).1 lemma filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, l ≤ x) = [] := filter_eq_nil.2 $ assume k hk, not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml) lemma filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) : (Ico n m).filter (λ x, l ≤ x) = Ico l m := begin cases le_total l m with hlm hml, { rw [← append_consecutive hnl hlm, filter_append, filter_le_of_top_le (le_refl l), filter_le_of_le_bot (le_refl l), nil_append] }, { rw [eq_nil_of_le hml, filter_le_of_top_le hml] } end @[simp] lemma filter_le (n m l : ℕ) : (Ico n m).filter (λ x, l ≤ x) = Ico (_root_.max n l) m := begin cases le_total n l with hnl hln, { rw [max_eq_right hnl, filter_le_of_le hnl] }, { rw [max_eq_left hln, filter_le_of_le_bot hln] } end end Ico @[simp] theorem enum_from_map_fst : ∀ n (l : list α), map prod.fst (enum_from n l) = range' n l.length | n [] := rfl | n (a :: l) := congr_arg (cons _) (enum_from_map_fst _ _) @[simp] theorem enum_map_fst (l : list α) : map prod.fst (enum l) = range l.length := by simp only [enum, enum_from_map_fst, range_eq_range'] theorem ilast'_mem : ∀ a l, @ilast' α a l ∈ a :: l | a [] := or.inl rfl | a (b::l) := or.inr (ilast'_mem b l) @[simp] lemma nth_le_attach (L : list α) (i) (H : i < L.attach.length) : (L.attach.nth_le i H).1 = L.nth_le i (length_attach L ▸ H) := calc (L.attach.nth_le i H).1 = (L.attach.map subtype.val).nth_le i (by simpa using H) : by rw nth_le_map' ... = L.nth_le i _ : by congr; apply attach_map_val @[simp] lemma nth_le_range {n} (i) (H : i < (range n).length) : nth_le (range n) i H = i := option.some.inj $ by rw [← nth_le_nth _, nth_range (by simpa using H)] theorem of_fn_eq_pmap {α n} {f : fin n → α} : of_fn f = pmap (λ i hi, f ⟨i, hi⟩) (range n) (λ _, mem_range.1) := by rw [pmap_eq_map_attach]; from ext_le (by simp) (λ i hi1 hi2, by simp at hi1; simp [nth_le_of_fn f ⟨i, hi1⟩]) theorem nodup_of_fn {α n} {f : fin n → α} (hf : function.injective f) : nodup (of_fn f) := by rw of_fn_eq_pmap; from nodup_pmap (λ _ _ _ _ H, fin.veq_of_eq $ hf H) (nodup_range n) section tfae /- tfae: The Following (propositions) Are Equivalent -/ theorem tfae_nil : tfae [] := forall_mem_nil _ theorem tfae_singleton (p) : tfae [p] := by simp [tfae, -eq_iff_iff] theorem tfae_cons_of_mem {a b} {l : list Prop} (h : b ∈ l) : tfae (a::l) ↔ (a ↔ b) ∧ tfae l := ⟨λ H, ⟨H a (by simp) b (or.inr h), λ p hp q hq, H _ (or.inr hp) _ (or.inr hq)⟩, begin rintro ⟨ab, H⟩ p (rfl | hp) q (rfl | hq), { refl }, { exact ab.trans (H _ h _ hq) }, { exact (ab.trans (H _ h _ hp)).symm }, { exact H _ hp _ hq } end⟩ theorem tfae_cons_cons {a b} {l : list Prop} : tfae (a::b::l) ↔ (a ↔ b) ∧ tfae (b::l) := tfae_cons_of_mem (or.inl rfl) theorem tfae_of_forall (b : Prop) (l : list Prop) (h : ∀ a ∈ l, a ↔ b) : tfae l := λ a₁ h₁ a₂ h₂, (h _ h₁).trans (h _ h₂).symm theorem tfae_of_cycle {a b} {l : list Prop} : list.chain (→) a (b::l) → (ilast' b l → a) → tfae (a::b::l) := begin induction l with c l IH generalizing a b; simp only [tfae_cons_cons, tfae_singleton, and_true, chain_cons, chain.nil] at *, { intros a b, exact iff.intro a b }, rintros ⟨ab,⟨bc,ch⟩⟩ la, have := IH ⟨bc,ch⟩ (ab ∘ la), exact ⟨⟨ab, la ∘ (this.2 c (or.inl rfl) _ (ilast'_mem _ _)).1 ∘ bc⟩, this⟩ end theorem tfae.out {l} (h : tfae l) (n₁ n₂) (h₁ : n₁ < list.length l . tactic.exact_dec_trivial) (h₂ : n₂ < list.length l . tactic.exact_dec_trivial) : list.nth_le l n₁ h₁ ↔ list.nth_le l n₂ h₂ := h _ (list.nth_le_mem _ _ _) _ (list.nth_le_mem _ _ _) end tfae lemma rotate_mod (l : list α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] @[simp] lemma rotate_nil (n : ℕ) : ([] : list α).rotate n = [] := by cases n; refl @[simp] lemma rotate_zero (l : list α) : l.rotate 0 = l := by simp [rotate] @[simp] lemma rotate'_nil (n : ℕ) : ([] : list α).rotate' n = [] := by cases n; refl @[simp] lemma rotate'_zero (l : list α) : l.rotate' 0 = l := by cases l; refl lemma rotate'_cons_succ (l : list α) (a : α) (n : ℕ) : (a :: l : list α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] @[simp] lemma length_rotate' : ∀ (l : list α) (n : ℕ), (l.rotate' n).length = l.length | [] n := rfl | (a::l) 0 := rfl | (a::l) (n+1) := by rw [list.rotate', length_rotate' (l ++ [a]) n]; simp lemma rotate'_eq_take_append_drop : ∀ {l : list α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [] n h := by simp [drop_append_of_le_length h] | l 0 h := by simp [take_append_of_le_length h] | (a::l) (n+1) h := have hnl : n ≤ l.length, from le_of_succ_le_succ h, have hnl' : n ≤ (l ++ [a]).length, by rw [length_append, length_cons, list.length, zero_add]; exact (le_of_succ_le h), by rw [rotate'_cons_succ, rotate'_eq_take_append_drop hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp lemma rotate'_rotate' : ∀ (l : list α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | (a::l) 0 m := by simp | [] n m := by simp | (a::l) (n+1) m := by rw [rotate'_cons_succ, rotate'_rotate', add_right_comm, rotate'_cons_succ] @[simp] lemma rotate'_length (l : list α) : rotate' l l.length = l := by rw rotate'_eq_take_append_drop (le_refl _); simp @[simp] lemma rotate'_length_mul (l : list α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 := by simp | (n+1) := calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length : by simp [-rotate'_length, nat.mul_succ, rotate'_rotate'] ... = l : by rw [rotate'_length, rotate'_length_mul] lemma rotate'_mod (l : list α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) : by rw rotate'_length_mul ... = l.rotate' n : by rw [rotate'_rotate', length_rotate', nat.mod_add_div] lemma rotate_eq_rotate' (l : list α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp [length_eq_zero, *] at * else by rw [← rotate'_mod, rotate'_eq_take_append_drop (le_of_lt (nat.mod_lt _ (nat.pos_of_ne_zero h)))]; simp [rotate] lemma rotate_cons_succ (l : list α) (a : α) (n : ℕ) : (a :: l : list α).rotate n.succ = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] @[simp] lemma mem_rotate : ∀ {l : list α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [] _ n := by simp | (a::l) _ 0 := by simp | (a::l) _ (n+1) := by simp [rotate_cons_succ, mem_rotate, or.comm] @[simp] lemma length_rotate (l : list α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] lemma rotate_eq_take_append_drop {l : list α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw rotate_eq_rotate'; exact rotate'_eq_take_append_drop lemma rotate_rotate (l : list α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] @[simp] lemma rotate_length (l : list α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] @[simp] lemma rotate_length_mul (l : list α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] lemma prod_rotate_eq_one_of_prod_eq_one [group α] : ∀ {l : list α} (hl : l.prod = 1) (n : ℕ), (l.rotate n).prod = 1 | [] _ _ := by simp | (a::l) hl n := have n % list.length (a :: l) ≤ list.length (a :: l), from le_of_lt (nat.mod_lt _ dec_trivial), by rw ← list.take_append_drop (n % list.length (a :: l)) (a :: l) at hl; rw [← rotate_mod, rotate_eq_take_append_drop this, list.prod_append, mul_eq_one_iff_inv_eq, ← one_mul (list.prod _)⁻¹, ← hl, list.prod_append, mul_assoc, mul_inv_self, mul_one] section choose variables (p : α → Prop) [decidable_pred p] (l : list α) lemma choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (choose_x p l hp).property lemma choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 lemma choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end choose namespace func variables {a : α} variables {as as1 as2 as3 : list α} localized "notation as ` {` m ` ↦ ` a `}` := list.func.set a as m" in list.func /- set -/ lemma length_set [inhabited α] : ∀ {m : ℕ} {as : list α}, (as {m ↦ a}).length = _root_.max as.length (m+1) | 0 [] := rfl | 0 (a::as) := by {rw max_eq_left, refl, simp [nat.le_add_right]} | (m+1) [] := by simp only [set, nat.zero_max, length, @length_set m] | (m+1) (a::as) := by simp only [set, nat.max_succ_succ, length, @length_set m] @[simp] lemma get_nil [inhabited α] {k : ℕ} : get k [] = default α := by {cases k; refl} lemma get_eq_default_of_le [inhabited α] : ∀ (k : ℕ) {as : list α}, as.length ≤ k → get k as = default α | 0 [] h1 := rfl | 0 (a::as) h1 := by cases h1 | (k+1) [] h1 := rfl | (k+1) (a::as) h1 := begin apply get_eq_default_of_le k, rw ← nat.succ_le_succ_iff, apply h1, end @[simp] lemma get_set [inhabited α] {a : α} : ∀ {k : ℕ} {as : list α}, get k (as {k ↦ a}) = a | 0 as := by {cases as; refl, } | (k+1) as := by {cases as; simp [get_set]} lemma eq_get_of_mem [inhabited α] {a : α} : ∀ {as : list α}, a ∈ as → ∃ n : nat, ∀ d : α, a = (get n as) | [] h := by cases h | (b::as) h := begin rw mem_cons_iff at h, cases h, { existsi 0, intro d, apply h }, { cases eq_get_of_mem h with n h2, existsi (n+1), apply h2 } end lemma mem_get_of_le [inhabited α] : ∀ {n : ℕ} {as : list α}, n < as.length → get n as ∈ as | _ [] h1 := by cases h1 | 0 (a::as) _ := or.inl rfl | (n+1) (a::as) h1 := begin apply or.inr, unfold get, apply mem_get_of_le, apply nat.lt_of_succ_lt_succ h1, end lemma mem_get_of_ne_zero [inhabited α] : ∀ {n : ℕ} {as : list α}, get n as ≠ default α → get n as ∈ as | _ [] h1 := begin exfalso, apply h1, rw get_nil end | 0 (a::as) h1 := or.inl rfl | (n+1) (a::as) h1 := begin unfold get, apply (or.inr (mem_get_of_ne_zero _)), apply h1 end lemma get_set_eq_of_ne [inhabited α] {a : α} : ∀ {as : list α} (k : ℕ) (m : ℕ), m ≠ k → get m (as {k ↦ a}) = get m as | as 0 m h1 := by { cases m, contradiction, cases as; simp only [set, get, get_nil] } | as (k+1) m h1 := begin cases as; cases m, simp only [set, get], { have h3 : get m (nil {k ↦ a}) = default α, { rw [get_set_eq_of_ne k m, get_nil], intro hc, apply h1, simp [hc] }, apply h3 }, simp only [set, get], { apply get_set_eq_of_ne k m, intro hc, apply h1, simp [hc], } end lemma get_map [inhabited α] [inhabited β] {f : α → β} : ∀ {n : ℕ} {as : list α}, n < as.length → get n (as.map f) = f (get n as) | _ [] h := by cases h | 0 (a::as) h := rfl | (n+1) (a::as) h1 := begin have h2 : n < length as, { rw [← nat.succ_le_iff, ← nat.lt_succ_iff], apply h1 }, apply get_map h2, end lemma get_map' [inhabited α] [inhabited β] {f : α → β} {n : ℕ} {as : list α} : f (default α) = (default β) → get n (as.map f) = f (get n as) := begin intro h1, by_cases h2 : n < as.length, { apply get_map h2, }, { rw not_lt at h2, rw [get_eq_default_of_le _ h2, get_eq_default_of_le, h1], rw [length_map], apply h2 } end lemma forall_val_of_forall_mem [inhabited α] {as : list α} {p : α → Prop} : p (default α) → (∀ x ∈ as, p x) → (∀ n, p (get n as)) := begin intros h1 h2 n, by_cases h3 : n < as.length, { apply h2 _ (mem_get_of_le h3) }, { rw not_lt at h3, rw get_eq_default_of_le _ h3, apply h1 } end /- equiv -/ lemma equiv_refl [inhabited α] : equiv as as := λ k, rfl lemma equiv_symm [inhabited α] : equiv as1 as2 → equiv as2 as1 := λ h1 k, (h1 k).symm lemma equiv_trans [inhabited α] : equiv as1 as2 → equiv as2 as3 → equiv as1 as3 := λ h1 h2 k, eq.trans (h1 k) (h2 k) lemma equiv_of_eq [inhabited α] : as1 = as2 → equiv as1 as2 := begin intro h1, rw h1, apply equiv_refl end lemma eq_of_equiv [inhabited α] : ∀ {as1 as2 : list α}, as1.length = as2.length → equiv as1 as2 → as1 = as2 | [] [] h1 h2 := rfl | (_::_) [] h1 h2 := by cases h1 | [] (_::_) h1 h2 := by cases h1 | (a1::as1) (a2::as2) h1 h2 := begin congr, { apply h2 0 }, have h3 : as1.length = as2.length, { simpa [add_left_inj, add_comm, length] using h1 }, apply eq_of_equiv h3, intro m, apply h2 (m+1) end /- neg -/ @[simp] lemma get_neg [inhabited α] [add_group α] {k : ℕ} {as : list α} : @get α ⟨0⟩ k (neg as) = -(@get α ⟨0⟩ k as) := by {unfold neg, rw (@get_map' α α ⟨0⟩), apply neg_zero} @[simp] lemma length_neg [inhabited α] [has_neg α] (as : list α) : (neg as).length = as.length := by simp only [neg, length_map] /- pointwise -/ lemma nil_pointwise [inhabited α] [inhabited β] {f : α → β → γ} : ∀ bs : list β, pointwise f [] bs = bs.map (f $ default α) | [] := rfl | (b::bs) := by simp only [nil_pointwise bs, pointwise, eq_self_iff_true, and_self, map] lemma pointwise_nil [inhabited α] [inhabited β] {f : α → β → γ} : ∀ as : list α, pointwise f as [] = as.map (λ a, f a $ default β) | [] := rfl | (a::as) := by simp only [pointwise_nil as, pointwise, eq_self_iff_true, and_self, list.map] lemma get_pointwise [inhabited α] [inhabited β] [inhabited γ] {f : α → β → γ} (h1 : f (default α) (default β) = default γ) : ∀ (k : nat) (as : list α) (bs : list β), get k (pointwise f as bs) = f (get k as) (get k bs) | k [] [] := by simp only [h1, get_nil, pointwise, get] | 0 [] (b::bs) := by simp only [get_pointwise, get_nil, pointwise, get, nat.nat_zero_eq_zero, map] | (k+1) [] (b::bs) := by { have : get k (map (f $ default α) bs) = f (default α) (get k bs), { simpa [nil_pointwise, get_nil] using (get_pointwise k [] bs) }, simpa [get, get_nil, pointwise, map] } | 0 (a::as) [] := by simp only [get_pointwise, get_nil, pointwise, get, nat.nat_zero_eq_zero, map] | (k+1) (a::as) [] := by simpa [get, get_nil, pointwise, map, pointwise_nil, get_nil] using get_pointwise k as [] | 0 (a::as) (b::bs) := by simp only [pointwise, get] | (k+1) (a::as) (b::bs) := by simp only [pointwise, get, get_pointwise k] lemma length_pointwise [inhabited α] [inhabited β] {f : α → β → γ} : ∀ {as : list α} {bs : list β}, (pointwise f as bs).length = _root_.max as.length bs.length | [] [] := rfl | [] (b::bs) := by simp only [pointwise, length, length_map, max_eq_right (nat.zero_le (length bs + 1))] | (a::as) [] := by simp only [pointwise, length, length_map, max_eq_left (nat.zero_le (length as + 1))] | (a::as) (b::bs) := by simp only [pointwise, length, nat.max_succ_succ, @length_pointwise as bs] /- add -/ @[simp] lemma get_add {α : Type u} [add_monoid α] {k : ℕ} {xs ys : list α} : @get α ⟨0⟩ k (add xs ys) = ( @get α ⟨0⟩ k xs + @get α ⟨0⟩ k ys) := by {apply get_pointwise, apply zero_add} @[simp] lemma length_add {α : Type u} [has_zero α] [has_add α] {xs ys : list α} : (add xs ys).length = _root_.max xs.length ys.length := @length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _ @[simp] lemma nil_add {α : Type u} [add_monoid α] (as : list α) : add [] as = as := begin rw [add, @nil_pointwise α α α ⟨0⟩ ⟨0⟩], apply eq.trans _ (map_id as), congr, ext, have : @default α ⟨0⟩ = 0 := rfl, rw [this, zero_add], refl end @[simp] lemma add_nil {α : Type u} [add_monoid α] (as : list α) : add as [] = as := begin rw [add, @pointwise_nil α α α ⟨0⟩ ⟨0⟩], apply eq.trans _ (map_id as), congr, ext, have : @default α ⟨0⟩ = 0 := rfl, rw [this, add_zero], refl end lemma map_add_map {α : Type u} [add_monoid α] (f g : α → α) {as : list α} : add (as.map f) (as.map g) = as.map (λ x, f x + g x) := begin apply @eq_of_equiv _ (⟨0⟩ : inhabited α), { rw [length_map, length_add, max_eq_left, length_map], apply le_of_eq, rw [length_map, length_map] }, intros m, rw [get_add], by_cases h : m < length as, { repeat {rw [@get_map α α ⟨0⟩ ⟨0⟩ _ _ _ h]} }, rw not_lt at h, repeat {rw [get_eq_default_of_le m]}; try {rw length_map, apply h}, apply zero_add end /- sub -/ @[simp] lemma get_sub {α : Type u} [add_group α] {k : ℕ} {xs ys : list α} : @get α ⟨0⟩ k (sub xs ys) = (@get α ⟨0⟩ k xs - @get α ⟨0⟩ k ys) := by {apply get_pointwise, apply sub_zero} @[simp] lemma length_sub [has_zero α] [has_sub α] {xs ys : list α} : (sub xs ys).length = _root_.max xs.length ys.length := @length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _ @[simp] lemma nil_sub {α : Type} [add_group α] (as : list α) : sub [] as = neg as := begin rw [sub, nil_pointwise], congr, ext, have : @default α ⟨0⟩ = 0 := rfl, rw [this, zero_sub] end @[simp] lemma sub_nil {α : Type} [add_group α] (as : list α) : sub as [] = as := begin rw [sub, pointwise_nil], apply eq.trans _ (map_id as), congr, ext, have : @default α ⟨0⟩ = 0 := rfl, rw [this, sub_zero], refl end end func namespace nat /-- The antidiagonal of a natural number `n` is the list of pairs `(i,j)` such that `i+j = n`. -/ def antidiagonal (n : ℕ) : list (ℕ × ℕ) := (range (n+1)).map (λ i, (i, n - i)) /-- A pair (i,j) is contained in the antidiagonal of `n` if and only if `i+j=n`. -/ @[simp] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := begin rw [antidiagonal, mem_map], split, { rintros ⟨i, hi, rfl⟩, rw [mem_range, lt_succ_iff] at hi, exact add_sub_of_le hi }, { rintro rfl, refine ⟨x.fst, _, _⟩, { rw [mem_range, add_assoc, lt_add_iff_pos_right], exact zero_lt_succ _ }, { exact prod.ext rfl (nat.add_sub_cancel_left _ _) } } end /-- The length of the antidiagonal of `n` is `n+1`. -/ @[simp] lemma length_antidiagonal (n : ℕ) : (antidiagonal n).length = n+1 := by rw [antidiagonal, length_map, length_range] /-- The antidiagonal of `0` is the list `[(0,0)]` -/ @[simp] lemma antidiagonal_zero : antidiagonal 0 = [(0, 0)] := ext_le (length_antidiagonal 0) $ λ n h₁ h₂, begin rw [length_antidiagonal, lt_succ_iff, le_zero_iff] at h₁, subst n, simp [antidiagonal] end /-- The antidiagonal of `n` does not contain duplicate entries. -/ lemma nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) := nodup_map (@injective_of_left_inverse ℕ (ℕ × ℕ) prod.fst (λ i, (i, n-i)) $ λ i, rfl) (nodup_range _) end nat end list theorem option.to_list_nodup {α} : ∀ o : option α, o.to_list.nodup | none := list.nodup_nil | (some x) := list.nodup_singleton x
a7a9b399eace160b8ef33a4a28d13726ba26a25a
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/bracket.lean
33c829021778341ce54a4b3de011b7c997136ce6
[]
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
1,554
lean
/- Copyright (c) 2021 Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Lutz and Oliver Nash. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.PostPort universes u_1 u_2 l namespace Mathlib /-! # Bracket Notation This file provides notation which can be used for the Lie bracket, for the commutator of two subgroups, and for other similar operations. ## Main Definitions * `has_bracket L M` for a binary operation that takes something in `L` and something in `M` and produces something in `M`. Defining an instance of this structure gives access to the notation `⁅ ⁆` ## Notation We introduce the notation `⁅x, y⁆` for the `bracket` of any `has_bracket` structure. Note that these are the Unicode "square with quill" brackets rather than the usual square brackets. -/ /-- The has_bracket class has three intended uses: 1. for certain binary operations on structures, like the product `⁅x, y⁆` of two elements `x`, `y` in a Lie algebra or the commutator of two elements `x` and `y` in a group. 2. for certain actions of one structure on another, like the action `⁅x, m⁆` of an element `x` of a Lie algebra on an element `m` in one of its modules (analogous to `has_scalar` in the associative setting). 3. for binary operations on substructures, like the commutator `⁅H, K⁆` of two subgroups `H` and `K` of a group. -/ class has_bracket (L : Type u_1) (M : Type u_2) where bracket : L → M → M
23e204cbfd75a26a2b90abfc107b680a3eafa316
69bc7d0780be17e452d542a93f9599488f1c0c8e
/9-19-2019.lean
d38898a5c9cd16962de2deb7e7628eb7f48fb5c9
[]
no_license
joek13/cs2102-notes
b7352285b1d1184fae25594f89f5926d74e6d7b4
25bb18788641b20af9cf3c429afe1da9b2f5eafb
refs/heads/master
1,673,461,162,867
1,575,561,090,000
1,575,561,090,000
207,573,549
0
0
null
null
null
null
UTF-8
Lean
false
false
1,600
lean
-- Notes 9-19-2019 /- Abstract data type - a data type accompanied by functions that operate on values of that type Propositions are true or false. -/ namespace mylogic inductive kevin_sullivan_is_daddy : Type | ttt | fff | idk open kevin_sullivan_is_daddy def daddy_and : kevin_sullivan_is_daddy → kevin_sullivan_is_daddy → kevin_sullivan_is_daddy | fff _ := fff | _ fff := fff | ttt ttt := ttt | ttt idk := idk | idk ttt := idk | idk idk := idk /- Terms / representationts Values "joe" → a person named "joe" Flight 66 → some airplane in the world 3/011/III/succ(succ(succ(zero))) → some natural number three -/ /- In defining the natural numbers, we want to define a datatype whose values are these terms. -/ end mylogic namespace mynat inductive knat : Type | zero : knat | succ : knat → knat open knat def one := succ zero def two := succ one def three := succ two def four := succ three #reduce four -- a beautifully simple counting system def increment : knat → knat := λ (x : knat), succ x def decrement : knat → knat | zero := zero | (succ x) := x -- need parentheses so it is interpreted as one argument -- unification algorithm (for pattern matching) def is_zero : knat → bool | zero := tt | _ := ff def keq : knat → knat → bool | zero zero := tt | zero (succ _) := ff | (succ _) zero := ff | (succ x) (succ y) := keq x y -- lean guarantees that recursion will terminate #eval keq three three 3 end mynat
7bc63ce16e6c3a10fdc1980dddb551787b792578
bb31430994044506fa42fd667e2d556327e18dfe
/src/algebra/order/floor.lean
498e145f7f46b464aa8a7603dd07f7f57f9d51f7
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
46,767
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import data.int.lemmas import data.set.intervals.group import data.set.lattice import tactic.abel import tactic.linarith import tactic.positivity /-! # Floor and ceil > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `floor_semiring`: An ordered semiring with natural-valued floor and ceil. * `nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `nat.ceil a`: Least natural `n` such that `a ≤ n`. * `floor_ring`: A linearly ordered ring with integer-valued floor and ceil. * `int.floor a`: Greatest integer `z` such that `z ≤ a`. * `int.ceil a`: Least integer `z` such that `a ≤ z`. * `int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `nat.floor a`. * `⌈a⌉₊` is `nat.ceil a`. * `⌊a⌋` is `int.floor a`. * `⌈a⌉` is `int.ceil a`. The index `₊` in the notations for `nat.floor` and `nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `linear_ordered_ring`/`linear_ordered_semiring` can be relaxed to `order_ring`/`order_semiring` in many lemmas. ## Tags rounding, floor, ceil -/ open set variables {F α β : Type*} /-! ### Floor semiring -/ /-- A `floor_semiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `linear_order`. Please see the above `TODO`. -/ class floor_semiring (α) [ordered_semiring α] := (floor : α → ℕ) (ceil : α → ℕ) (floor_of_neg {a : α} (ha : a < 0) : floor a = 0) (gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a) (gc_ceil : galois_connection ceil coe) instance : floor_semiring ℕ := { floor := id, ceil := id, floor_of_neg := λ a ha, (a.not_lt_zero ha).elim, gc_floor := λ n a ha, by { rw nat.cast_id, refl }, gc_ceil := λ n a, by { rw nat.cast_id, refl } } namespace nat section ordered_semiring variables [ordered_semiring α] [floor_semiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := floor_semiring.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := floor_semiring.ceil @[simp] lemma floor_nat : (nat.floor : ℕ → ℕ) = id := rfl @[simp] lemma ceil_nat : (nat.ceil : ℕ → ℕ) = id := rfl notation `⌊` a `⌋₊` := nat.floor a notation `⌈` a `⌉₊` := nat.ceil a end ordered_semiring section linear_ordered_semiring variables [linear_ordered_semiring α] [floor_semiring α] {a : α} {n : ℕ} lemma le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := floor_semiring.gc_floor ha lemma le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff $ n.cast_nonneg.trans h).2 h lemma floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le $ le_floor_iff ha lemma floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans $ by rw nat.cast_one lemma lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le $ λ h', (le_floor h').not_lt h lemma lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := by exact_mod_cast lt_of_floor_lt h lemma floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl lemma lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt $ nat.lt_succ_self _ lemma lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a @[simp] lemma floor_coe (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff $ λ a, by { rw [le_floor_iff, nat.cast_le], exact n.cast_nonneg } @[simp] lemma floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← nat.cast_zero, floor_coe] @[simp] lemma floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [←nat.cast_one, floor_coe] lemma floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim floor_semiring.floor_of_neg $ by { rintro rfl, exact floor_zero } lemma floor_mono : monotone (floor : α → ℕ) := λ a b h, begin obtain ha | ha := le_total a 0, { rw floor_of_nonpos ha, exact nat.zero_le _ }, { exact le_floor ((floor_le ha).trans h) } end lemma le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := begin obtain ha | ha := le_total a 0, { rw floor_of_nonpos ha, exact iff_of_false (nat.pos_of_ne_zero hn).not_le (not_le_of_lt $ ha.trans_lt $ cast_pos.2 $ nat.pos_of_ne_zero hn) }, { exact le_floor_iff ha } end @[simp] lemma one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := by exact_mod_cast (@le_floor_iff' α _ _ x 1 one_ne_zero) lemma floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le $ le_floor_iff' hn lemma floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by { convert le_floor_iff' nat.one_ne_zero, exact cast_one.symm } lemma pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left (λ ha, lt_irrefl 0 $ by rwa floor_of_nonpos ha at h) lemma lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (nat.cast_lt.2 h).trans_le $ floor_le (pos_of_floor_pos $ (nat.zero_le n).trans_lt h).le lemma floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h lemma floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le $ h.trans_eq $ nat.cast_one.symm @[simp] lemma floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by { rw [←lt_one_iff, ←@cast_one α], exact floor_lt' nat.one_ne_zero } lemma floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [←le_floor_iff ha, ←nat.cast_one, ←nat.cast_add, ←floor_lt ha, nat.lt_add_one_iff, le_antisymm_iff, and.comm] lemma floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← nat.cast_one, ← nat.cast_add, ← floor_lt' (nat.add_one_ne_zero n), nat.lt_add_one_iff, le_antisymm_iff, and.comm] lemma floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (set.Ico n (n+1) : set α), ⌊a⌋₊ = n := λ a ⟨h₀, h₁⟩, (floor_eq_iff $ n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ lemma floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (set.Ico n (n+1) : set α), (⌊a⌋₊ : α) = n := λ x hx, by exact_mod_cast floor_eq_on_Ico n x hx @[simp] lemma preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext $ λ a, floor_eq_zero lemma preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico n (n + 1) := ext $ λ a, floor_eq_iff' hn /-! #### Ceil -/ lemma gc_ceil_coe : galois_connection (ceil : α → ℕ) coe := floor_semiring.gc_ceil @[simp] lemma ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ lemma lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le @[simp] lemma add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← nat.lt_ceil, nat.add_one_le_iff] @[simp] lemma one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, nat.add_one_le_ceil_iff, nat.cast_zero] lemma ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by { rw [ceil_le, nat.cast_add, nat.cast_one], exact (lt_floor_add_one a).le } lemma le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl @[simp] lemma ceil_int_cast {α : Type*} [linear_ordered_ring α] [floor_semiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.to_nat := eq_of_forall_ge_iff $ λ a, by { simp, norm_cast } @[simp] lemma ceil_nat_cast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff $ λ a, by rw [ceil_le, cast_le] lemma ceil_mono : monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l @[simp] lemma ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← nat.cast_zero, ceil_nat_cast] @[simp] lemma ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [←nat.cast_one, ceil_nat_cast] @[simp] lemma ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← le_zero_iff, ceil_le, nat.cast_zero] @[simp] lemma ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] lemma lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (nat.cast_lt.2 h) lemma le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (nat.cast_le.2 h) lemma floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := begin obtain ha | ha := le_total a 0, { rw floor_of_nonpos ha, exact nat.zero_le _ }, { exact cast_le.1 ((floor_le ha).trans $ le_ceil _) } end lemma floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := begin rcases le_or_lt 0 a with ha|ha, { rw floor_lt ha, exact h.trans_le (le_ceil _) }, { rwa [floor_of_nonpos ha.le, lt_ceil, nat.cast_zero] } end lemma ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), nat.lt_add_one_iff, le_antisymm_iff, and.comm] @[simp] lemma preimage_ceil_zero : (nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext $ λ x, ceil_eq_zero lemma preimage_ceil_of_ne_zero (hn : n ≠ 0) : (nat.ceil : α → ℕ) ⁻¹' {n} = Ioc ↑(n - 1) n := ext $ λ x, ceil_eq_iff hn /-! #### Intervals -/ @[simp] lemma preimage_Ioo {a b : α} (ha : 0 ≤ a) : ((coe : ℕ → α) ⁻¹' (set.Ioo a b)) = set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by { ext, simp [floor_lt, lt_ceil, ha] } @[simp] lemma preimage_Ico {a b : α} : ((coe : ℕ → α) ⁻¹' (set.Ico a b)) = set.Ico ⌈a⌉₊ ⌈b⌉₊ := by { ext, simp [ceil_le, lt_ceil] } @[simp] lemma preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : ((coe : ℕ → α) ⁻¹' (set.Ioc a b)) = set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by { ext, simp [floor_lt, le_floor_iff, hb, ha] } @[simp] lemma preimage_Icc {a b : α} (hb : 0 ≤ b) : ((coe : ℕ → α) ⁻¹' (set.Icc a b)) = set.Icc ⌈a⌉₊ ⌊b⌋₊ := by { ext, simp [ceil_le, hb, le_floor_iff] } @[simp] lemma preimage_Ioi {a : α} (ha : 0 ≤ a) : ((coe : ℕ → α) ⁻¹' (set.Ioi a)) = set.Ioi ⌊a⌋₊ := by { ext, simp [floor_lt, ha] } @[simp] lemma preimage_Ici {a : α} : ((coe : ℕ → α) ⁻¹' (set.Ici a)) = set.Ici ⌈a⌉₊ := by { ext, simp [ceil_le] } @[simp] lemma preimage_Iio {a : α} : ((coe : ℕ → α) ⁻¹' (set.Iio a)) = set.Iio ⌈a⌉₊ := by { ext, simp [lt_ceil] } @[simp] lemma preimage_Iic {a : α} (ha : 0 ≤ a) : ((coe : ℕ → α) ⁻¹' (set.Iic a)) = set.Iic ⌊a⌋₊ := by { ext, simp [le_floor_iff, ha] } lemma floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff $ λ b, begin rw [le_floor_iff (add_nonneg ha n.cast_nonneg)], obtain hb | hb := le_total n b, { obtain ⟨d, rfl⟩ := exists_add_of_le hb, rw [nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] }, { obtain ⟨d, rfl⟩ := exists_add_of_le hb, rw [nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)], refine iff_of_true _ le_self_add, exact (le_add_of_nonneg_right $ ha.trans $ le_add_of_nonneg_right d.cast_nonneg) } end lemma floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by { convert floor_add_nat ha 1, exact cast_one.symm } lemma floor_sub_nat [has_sub α] [has_ordered_sub α] [has_exists_add_of_le α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := begin obtain ha | ha := le_total a 0, { rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] }, cases le_total a n, { rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le], exact nat.cast_le.1 ((nat.floor_le ha).trans h) }, { rw [eq_tsub_iff_add_eq_of_le (le_floor h), ←floor_add_nat _, tsub_add_cancel_of_le h], exact le_tsub_of_add_le_left ((add_zero _).trans_le h), } end lemma ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff $ λ b, begin rw [←not_lt, ←not_lt, not_iff_not], rw [lt_ceil], obtain hb | hb := le_or_lt n b, { obtain ⟨d, rfl⟩ := exists_add_of_le hb, rw [nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] }, { exact iff_of_true (lt_add_of_nonneg_of_lt ha $ cast_lt.2 hb) (lt_add_left _ _ _ hb) } end lemma ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by { convert ceil_add_nat ha 1, exact cast_one.symm } lemma ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 $ (nat.lt_succ_self _).trans_le (ceil_add_one ha).ge lemma ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := begin rw [ceil_le, nat.cast_add], exact add_le_add (le_ceil _) (le_ceil _), end end linear_ordered_semiring section linear_ordered_ring variables [linear_ordered_ring α] [floor_semiring α] lemma sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 $ lt_floor_add_one a end linear_ordered_ring section linear_ordered_semifield variables [linear_ordered_semifield α] [floor_semiring α] lemma floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := begin cases le_total a 0 with ha ha, { rw [floor_of_nonpos, floor_of_nonpos ha], { simp }, apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg }, obtain rfl | hn := n.eq_zero_or_pos, { rw [cast_zero, div_zero, nat.div_zero, floor_zero] }, refine (floor_eq_iff _).2 _, { exact div_nonneg ha n.cast_nonneg }, split, { exact cast_div_le.trans (div_le_div_of_le_of_nonneg (floor_le ha) n.cast_nonneg) }, rw [div_lt_iff, add_mul, one_mul, ←cast_mul, ←cast_add, ←floor_lt ha], { exact lt_div_mul_add hn }, { exact (cast_pos.2 hn) } end /-- Natural division is the floor of field division. -/ lemma floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by { convert floor_div_nat (m : α) n, rw m.floor_coe } end linear_ordered_semifield end nat /-- There exists at most one `floor_semiring` structure on a linear ordered semiring. -/ lemma subsingleton_floor_semiring {α} [linear_ordered_semiring α] : subsingleton (floor_semiring α) := begin refine ⟨λ H₁ H₂, _⟩, have : H₁.ceil = H₂.ceil, from funext (λ a, H₁.gc_ceil.l_unique H₂.gc_ceil $ λ n, rfl), have : H₁.floor = H₂.floor, { ext a, cases lt_or_le a 0, { rw [H₁.floor_of_neg, H₂.floor_of_neg]; exact h }, { refine eq_of_forall_le_iff (λ n, _), rw [H₁.gc_floor, H₂.gc_floor]; exact h } }, cases H₁, cases H₂, congr; assumption end /-! ### Floor rings -/ /-- A `floor_ring` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class floor_ring (α) [linear_ordered_ring α] := (floor : α → ℤ) (ceil : α → ℤ) (gc_coe_floor : galois_connection coe floor) (gc_ceil_coe : galois_connection ceil coe) instance : floor_ring ℤ := { floor := id, ceil := id, gc_coe_floor := λ a b, by { rw int.cast_id, refl }, gc_ceil_coe := λ a b, by { rw int.cast_id, refl } } /-- A `floor_ring` constructor from the `floor` function alone. -/ def floor_ring.of_floor (α) [linear_ordered_ring α] (floor : α → ℤ) (gc_coe_floor : galois_connection coe floor) : floor_ring α := { floor := floor, ceil := λ a, -floor (-a), gc_coe_floor := gc_coe_floor, gc_ceil_coe := λ a z, by rw [neg_le, ←gc_coe_floor, int.cast_neg, neg_le_neg_iff] } /-- A `floor_ring` constructor from the `ceil` function alone. -/ def floor_ring.of_ceil (α) [linear_ordered_ring α] (ceil : α → ℤ) (gc_ceil_coe : galois_connection ceil coe) : floor_ring α := { floor := λ a, -ceil (-a), ceil := ceil, gc_coe_floor := λ a z, by rw [le_neg, gc_ceil_coe, int.cast_neg, neg_le_neg_iff], gc_ceil_coe := gc_ceil_coe } namespace int variables [linear_ordered_ring α] [floor_ring α] {z : ℤ} {a : α} /-- `int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := floor_ring.floor /-- `int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := floor_ring.ceil /-- `int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a @[simp] lemma floor_int : (int.floor : ℤ → ℤ) = id := rfl @[simp] lemma ceil_int : (int.ceil : ℤ → ℤ) = id := rfl @[simp] lemma fract_int : (int.fract : ℤ → ℤ) = 0 := funext $ λ x, by simp [fract] notation `⌊` a `⌋` := int.floor a notation `⌈` a `⌉` := int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] lemma floor_ring_floor_eq : @floor_ring.floor = @int.floor := rfl @[simp] lemma floor_ring_ceil_eq : @floor_ring.ceil = @int.ceil := rfl /-! #### Floor -/ lemma gc_coe_floor : galois_connection (coe : ℤ → α) floor := floor_ring.gc_coe_floor lemma le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm lemma floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor lemma floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a lemma floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, int.cast_zero] @[simp] lemma floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] @[simp] lemma floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] lemma floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := begin rw [← @cast_le α, int.cast_zero], exact (floor_le a).trans ha, end lemma lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 $ int.lt_succ_self _ @[simp] lemma lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [int.succ, int.cast_add, int.cast_one] using lt_succ_floor a @[simp] lemma sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) @[simp] lemma floor_int_cast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff $ λ a, by rw [le_floor, int.cast_le] @[simp] lemma floor_nat_cast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff $ λ a, by rw [le_floor, ← cast_coe_nat, cast_le] @[simp] lemma floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_int_cast] @[simp] lemma floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_int_cast] @[mono] lemma floor_mono : monotone (floor : α → ℤ) := gc_coe_floor.monotone_u lemma floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by { convert le_floor, exact cast_one.symm } @[simp] lemma floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff $ λ a, by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, int.cast_sub] lemma floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by { convert floor_add_int a 1, exact cast_one.symm } lemma le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := begin rw [le_floor, int.cast_add], exact add_le_add (floor_le _) (floor_le _), end lemma le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := begin rw [←sub_le_iff_le_add, le_floor, int.cast_sub, sub_le_comm, int.cast_sub, int.cast_one], refine le_trans _ (sub_one_lt_floor _).le, rw [sub_le_iff_le_add', ←add_sub_assoc, sub_le_sub_iff_right], exact floor_le _, end @[simp] lemma floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z @[simp] lemma floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← int.cast_coe_nat, floor_add_int] @[simp] lemma floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← int.cast_coe_nat, floor_int_add] @[simp] lemma floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := eq.trans (by rw [int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) @[simp] lemma floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← int.cast_coe_nat, floor_sub_int] lemma abs_sub_lt_one_of_floor_eq_floor {α : Type*} [linear_ordered_comm_ring α] [floor_ring α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := begin have : a < ⌊a⌋ + 1 := lt_floor_add_one a, have : b < ⌊b⌋ + 1 := lt_floor_add_one b, have : (⌊a⌋ : α) = ⌊b⌋ := int.cast_inj.2 h, have : (⌊a⌋ : α) ≤ a := floor_le a, have : (⌊b⌋ : α) ≤ b := floor_le b, exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ end lemma floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ←int.lt_add_one_iff, floor_lt, int.cast_add, int.cast_one, and.comm] @[simp] lemma floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] lemma floor_eq_on_Ico (n : ℤ) : ∀ a ∈ set.Ico (n : α) (n + 1), ⌊a⌋ = n := λ a ⟨h₀, h₁⟩, floor_eq_iff.mpr ⟨h₀, h₁⟩ lemma floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := λ a ha, congr_arg _ $ floor_eq_on_Ico n a ha @[simp] lemma preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico m (m + 1) := ext $ λ x, floor_eq_iff /-! #### Fractional part -/ @[simp] lemma self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl @[simp] lemma floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel'_right _ _ @[simp] lemma fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ @[simp] lemma fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by { rw fract, simp } @[simp] lemma fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by { rw fract, simp } @[simp] lemma fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by { rw fract, simp } @[simp] lemma fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] @[simp] lemma fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by { rw fract, simp } @[simp] lemma fract_int_nat (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] lemma fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := begin rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ←int.cast_add, int.cast_le], exact le_floor_add _ _, end lemma fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := begin rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left], exact_mod_cast le_floor_add_floor a b, end @[simp] lemma self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ @[simp] lemma fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ @[simp] lemma fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 $ floor_le _ lemma fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 $ sub_one_lt_floor _ @[simp] lemma fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] @[simp] lemma fract_one : fract (1 : α) = 0 := by simp [fract] lemma abs_fract : |int.fract a| = int.fract a := abs_eq_self.mpr $ fract_nonneg a @[simp] lemma abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr $ sub_nonneg.mpr (fract_lt_one a).le @[simp] lemma fract_int_cast (z : ℤ) : fract (z : α) = 0 := by { unfold fract, rw floor_int_cast, exact sub_self _ } @[simp] lemma fract_nat_cast (n : ℕ) : fract (n : α) = 0 := by simp [fract] @[simp] lemma fract_floor (a : α) : fract (⌊a⌋ : α) = 0 := fract_int_cast _ @[simp] lemma floor_fract (a : α) : ⌊fract a⌋ = 0 := by rw [floor_eq_iff, int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩ lemma fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z := ⟨λ h, by { rw ←h, exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩}, begin rintro ⟨h₀, h₁, z, hz⟩, show a - ⌊a⌋ = b, apply eq.symm, rw [eq_sub_iff_add_eq, add_comm, ←eq_sub_iff_add_eq], rw [hz, int.cast_inj, floor_eq_iff, ←hz], clear hz, split; simpa [sub_eq_add_neg, add_assoc] end⟩ lemma fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z := ⟨λ h, ⟨⌊a⌋ - ⌊b⌋, begin unfold fract at h, rw [int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h], end⟩, begin rintro ⟨z, hz⟩, refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, _⟩, rw [eq_add_of_sub_eq hz, add_comm, int.cast_add], exact add_sub_sub_cancel _ _ _, end⟩ @[simp] lemma fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 := fract_eq_iff.trans $ and.assoc.symm.trans $ and_iff_left ⟨0, by simp⟩ @[simp] lemma fract_fract (a : α) : fract (fract a) = fract a := fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩ lemma fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z := ⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by { unfold fract, simp [sub_eq_add_neg], abel }⟩ lemma fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := begin rw fract_eq_iff, split, { rw [le_sub_iff_add_le, zero_add], exact (fract_lt_one x).le, }, refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, _⟩, simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj], conv in (-x) {rw ← floor_add_fract x}, simp [-floor_add_fract], end @[simp] lemma fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := begin simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and], split; rintros ⟨z, hz⟩; use [-z]; simp [← hz], end lemma fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := begin induction b with c hc, use 0, simp, rcases hc with ⟨z, hz⟩, rw [nat.succ_eq_add_one, nat.cast_add, mul_add, mul_add, nat.cast_one, mul_one, mul_one], rcases fract_add (a * c) a with ⟨y, hy⟩, use z - y, rw [int.cast_sub, ←hz, ←hy], abel end lemma preimage_fract (s : set α) : fract ⁻¹' s = ⋃ m : ℤ, (λ x, x - m) ⁻¹' (s ∩ Ico (0 : α) 1) := begin ext x, simp only [mem_preimage, mem_Union, mem_inter_iff], refine ⟨λ h, ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, _⟩, rintro ⟨m, hms, hm0, hm1⟩, obtain rfl : ⌊x⌋ = m, from floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩, exact hms end lemma image_fract (s : set α) : fract '' s = ⋃ m : ℤ, (λ x, x - m) '' s ∩ Ico 0 1 := begin ext x, simp only [mem_image, mem_inter_iff, mem_Union], split, { rintro ⟨y, hy, rfl⟩, exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩ }, { rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩, obtain rfl : ⌊y⌋ = m, from floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩, exact ⟨y, hys, rfl⟩ } end section linear_ordered_field variables {k : Type*} [linear_ordered_field k] [floor_ring k] {b : k} lemma fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b/a) * a ∈ Ico 0 a := ⟨(zero_le_mul_right ha).2 (fract_nonneg (b/a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b/a))⟩ lemma fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) : fract (b/a) * a + ⌊b/a⌋ • a = b := by rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel b ha] lemma sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b := sub_nonneg_of_le $ (le_div_iff hb).1 $ floor_le _ lemma sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b := sub_lt_iff_lt_add.2 $ by { rw [←one_add_mul, ←div_lt_iff hb, add_comm], exact lt_floor_add_one _ } lemma fract_div_nat_cast_eq_div_nat_cast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := begin rcases n.eq_zero_or_pos with rfl | hn, { simp, }, have hn' : 0 < (n : k), { norm_cast, assumption, }, refine fract_eq_iff.mpr ⟨by positivity, _, m / n, _⟩, { simpa only [div_lt_one hn', nat.cast_lt] using m.mod_lt hn, }, { rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne.symm, mul_div_cancel' _ hn'.ne.symm, mul_add, mul_div_cancel' _ hn'.ne.symm], norm_cast, rw [← nat.cast_add, nat.mod_add_div m n], }, end -- TODO Generalise this to allow `n : ℤ` using `int.fmod` instead of `int.mod`. lemma fract_div_int_cast_eq_div_int_cast_mod {m : ℤ} {n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := begin rcases n.eq_zero_or_pos with rfl | hn, { simp, }, replace hn : 0 < (n : k), { norm_cast, assumption, }, have : ∀ {l : ℤ} (hl : 0 ≤ l), fract ((l : k) / n) = ↑(l % n) / n, { intros, obtain ⟨l₀, rfl | rfl⟩ := l.eq_coe_or_neg, { rw [cast_coe_nat, ← coe_nat_mod, cast_coe_nat, fract_div_nat_cast_eq_div_nat_cast_mod], }, { rw [right.nonneg_neg_iff, coe_nat_nonpos_iff] at hl, simp [hl, zero_mod], }, }, obtain ⟨m₀, rfl | rfl⟩ := m.eq_coe_or_neg, { exact this (of_nat_nonneg m₀), }, let q := ⌈↑m₀ / (n : k)⌉, let m₁ := (q * ↑n) -(↑m₀ : ℤ), have hm₁ : 0 ≤ m₁, { simpa [←@cast_le k, ←div_le_iff hn] using floor_ring.gc_ceil_coe.le_u_l _, }, calc fract (↑-↑m₀ / ↑n) = fract (-(m₀ : k) / n) : by push_cast ... = fract ((m₁ : k) / n) : _ ... = ↑(m₁ % (n : ℤ)) / ↑n : this hm₁ ... = ↑(-(↑m₀ : ℤ) % ↑n) / ↑n : _, { rw [← fract_int_add q, ← mul_div_cancel (q : k) (ne_of_gt hn), ← add_div, ← sub_eq_add_neg], push_cast, }, { congr' 2, change ((q * ↑n) -(↑m₀ : ℤ)) % ↑n = _, rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_mod_self], }, end end linear_ordered_field /-! #### Ceil -/ lemma gc_ceil_coe : galois_connection ceil (coe : ℤ → α) := floor_ring.gc_ceil_coe lemma ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z := gc_ceil_coe a z lemma floor_neg : ⌊-a⌋ = -⌈a⌉ := eq_of_forall_le_iff (λ z, by rw [le_neg, ceil_le, le_floor, int.cast_neg, le_neg]) lemma ceil_neg : ⌈-a⌉ = -⌊a⌋ := eq_of_forall_ge_iff (λ z, by rw [neg_le, ceil_le, le_floor, int.cast_neg, neg_le]) lemma lt_ceil : z < ⌈a⌉ ↔ (z : α) < a := lt_iff_lt_of_le_iff_le ceil_le @[simp] lemma add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff] @[simp] lemma one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero] lemma ceil_le_floor_add_one (a : α) : ⌈a⌉ ≤ ⌊a⌋ + 1 := by { rw [ceil_le, int.cast_add, int.cast_one], exact (lt_floor_add_one a).le } lemma le_ceil (a : α) : a ≤ ⌈a⌉ := gc_ceil_coe.le_u_l a @[simp] lemma ceil_int_cast (z : ℤ) : ⌈(z : α)⌉ = z := eq_of_forall_ge_iff $ λ a, by rw [ceil_le, int.cast_le] @[simp] lemma ceil_nat_cast (n : ℕ) : ⌈(n : α)⌉ = n := eq_of_forall_ge_iff $ λ a, by rw [ceil_le, ← cast_coe_nat, cast_le] lemma ceil_mono : monotone (ceil : α → ℤ) := gc_ceil_coe.monotone_l @[simp] lemma ceil_add_int (a : α) (z : ℤ) : ⌈a + z⌉ = ⌈a⌉ + z := by rw [←neg_inj, neg_add', ←floor_neg, ←floor_neg, neg_add', floor_sub_int] @[simp] lemma ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← int.cast_coe_nat, ceil_add_int] @[simp] lemma ceil_add_one (a : α) : ⌈a + 1⌉ = ⌈a⌉ + 1 := by { convert ceil_add_int a (1 : ℤ), exact cast_one.symm } @[simp] lemma ceil_sub_int (a : α) (z : ℤ) : ⌈a - z⌉ = ⌈a⌉ - z := eq.trans (by rw [int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _) @[simp] lemma ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by convert ceil_sub_int a n using 1; simp @[simp] lemma ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel] lemma ceil_lt_add_one (a : α) : (⌈a⌉ : α) < a + 1 := by { rw [← lt_ceil, ← int.cast_one, ceil_add_int], apply lt_add_one } lemma ceil_add_le (a b : α) : ⌈a + b⌉ ≤ ⌈a⌉ + ⌈b⌉ := begin rw [ceil_le, int.cast_add], exact add_le_add (le_ceil _) (le_ceil _), end lemma ceil_add_ceil_le (a b : α) : ⌈a⌉ + ⌈b⌉ ≤ ⌈a + b⌉ + 1 := begin rw [←le_sub_iff_add_le, ceil_le, int.cast_sub, int.cast_add, int.cast_one, le_sub_comm], refine (ceil_lt_add_one _).le.trans _, rw [le_sub_iff_add_le', ←add_assoc, add_le_add_iff_right], exact le_ceil _, end @[simp] lemma ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero] @[simp] lemma ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_int_cast] @[simp] lemma ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_int_cast] lemma ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := by exact_mod_cast ha.trans (le_ceil a) lemma ceil_eq_iff : ⌈a⌉ = z ↔ ↑z - 1 < a ∧ a ≤ z := by rw [←ceil_le, ←int.cast_one, ←int.cast_sub, ←lt_ceil, int.sub_one_lt_iff, le_antisymm_iff, and.comm] @[simp] lemma ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff] lemma ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ set.Ioc (z - 1 : α) z, ⌈a⌉ = z := λ a ⟨h₀, h₁⟩, ceil_eq_iff.mpr ⟨h₀, h₁⟩ lemma ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ set.Ioc (z - 1 : α) z, (⌈a⌉ : α) = z := λ a ha, by exact_mod_cast ceil_eq_on_Ioc z a ha lemma floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ := cast_le.1 $ (floor_le _).trans $ le_ceil _ lemma floor_lt_ceil_of_lt {a b : α} (h : a < b) : ⌊a⌋ < ⌈b⌉ := cast_lt.1 $ (floor_le a).trans_lt $ h.trans_le $ le_ceil b @[simp] lemma preimage_ceil_singleton (m : ℤ) : (ceil : α → ℤ) ⁻¹' {m} = Ioc (m - 1) m := ext $ λ x, ceil_eq_iff lemma fract_eq_zero_or_add_one_sub_ceil (a : α) : fract a = 0 ∨ fract a = a + 1 - (⌈a⌉ : α) := begin cases eq_or_ne (fract a) 0 with ha ha, { exact or.inl ha, }, right, suffices : (⌈a⌉ : α) = ⌊a⌋ + 1, { rw [this, ← self_sub_fract], abel, }, norm_cast, rw ceil_eq_iff, refine ⟨_, _root_.le_of_lt $ by simp⟩, rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff], exact ha.symm.lt_of_le (fract_nonneg a), end lemma ceil_eq_add_one_sub_fract (ha : fract a ≠ 0) : (⌈a⌉ : α) = a + 1 - fract a := by { rw (or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a), abel, } lemma ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : α) - a = 1 - fract a := by { rw (or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a), abel, } /-! #### Intervals -/ @[simp] lemma preimage_Ioo {a b : α} : ((coe : ℤ → α) ⁻¹' (set.Ioo a b)) = set.Ioo ⌊a⌋ ⌈b⌉ := by { ext, simp [floor_lt, lt_ceil] } @[simp] lemma preimage_Ico {a b : α} : ((coe : ℤ → α) ⁻¹' (set.Ico a b)) = set.Ico ⌈a⌉ ⌈b⌉ := by { ext, simp [ceil_le, lt_ceil] } @[simp] lemma preimage_Ioc {a b : α} : ((coe : ℤ → α) ⁻¹' (set.Ioc a b)) = set.Ioc ⌊a⌋ ⌊b⌋ := by { ext, simp [floor_lt, le_floor] } @[simp] lemma preimage_Icc {a b : α} : ((coe : ℤ → α) ⁻¹' (set.Icc a b)) = set.Icc ⌈a⌉ ⌊b⌋ := by { ext, simp [ceil_le, le_floor] } @[simp] lemma preimage_Ioi : ((coe : ℤ → α) ⁻¹' (set.Ioi a)) = set.Ioi ⌊a⌋ := by { ext, simp [floor_lt] } @[simp] lemma preimage_Ici : ((coe : ℤ → α) ⁻¹' (set.Ici a)) = set.Ici ⌈a⌉ := by { ext, simp [ceil_le] } @[simp] lemma preimage_Iio : ((coe : ℤ → α) ⁻¹' (set.Iio a)) = set.Iio ⌈a⌉ := by { ext, simp [lt_ceil] } @[simp] lemma preimage_Iic : ((coe : ℤ → α) ⁻¹' (set.Iic a)) = set.Iic ⌊a⌋ := by { ext, simp [le_floor] } end int open int /-! ### Round -/ section round section linear_ordered_ring variables [linear_ordered_ring α] [floor_ring α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := if 2 * fract x < 1 then ⌊x⌋ else ⌈x⌉ @[simp] lemma round_zero : round (0 : α) = 0 := by simp [round] @[simp] lemma round_one : round (1 : α) = 1 := by simp [round] @[simp] lemma round_nat_cast (n : ℕ) : round (n : α) = n := by simp [round] @[simp] lemma round_int_cast (n : ℤ) : round (n : α) = n := by simp [round] @[simp] lemma round_add_int (x : α) (y : ℤ) : round (x + y) = round x + y := by rw [round, round, int.fract_add_int, int.floor_add_int, int.ceil_add_int, ← apply_ite2, if_t_t] @[simp] lemma round_add_one (a : α) : round (a + 1) = round a + 1 := by { convert round_add_int a 1, exact int.cast_one.symm } @[simp] lemma round_sub_int (x : α) (y : ℤ) : round (x - y) = round x - y := by { rw [sub_eq_add_neg], norm_cast, rw [round_add_int, sub_eq_add_neg] } @[simp] lemma round_sub_one (a : α) : round (a - 1) = round a - 1 := by { convert round_sub_int a 1, exact int.cast_one.symm } @[simp] lemma round_add_nat (x : α) (y : ℕ) : round (x + y) = round x + y := by rw [round, round, fract_add_nat, int.floor_add_nat, int.ceil_add_nat, ← apply_ite2, if_t_t] @[simp] lemma round_sub_nat (x : α) (y : ℕ) : round (x - y) = round x - y := by { rw [sub_eq_add_neg, ← int.cast_coe_nat], norm_cast, rw [round_add_int, sub_eq_add_neg] } @[simp] lemma round_int_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by { rw [add_comm, round_add_int, add_comm] } @[simp] lemma round_nat_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by { rw [add_comm, round_add_nat, add_comm] } lemma abs_sub_round_eq_min (x : α) : |x - round x| = min (fract x) (1 - fract x) := begin simp_rw [round, min_def_lt, two_mul, ← lt_tsub_iff_left], cases lt_or_ge (fract x) (1 - fract x) with hx hx, { rw [if_pos hx, if_pos hx, self_sub_floor, abs_fract], }, { have : 0 < fract x, { replace hx : 0 < fract x + fract x := lt_of_lt_of_le zero_lt_one (tsub_le_iff_left.mp hx), simpa only [← two_mul, zero_lt_mul_left, zero_lt_two] using hx, }, rw [if_neg (not_lt.mpr hx), if_neg (not_lt.mpr hx), abs_sub_comm, ceil_sub_self_eq this.ne.symm, abs_one_sub_fract], }, end lemma round_le (x : α) (z : ℤ) : |x - round x| ≤ |x - z| := begin rw [abs_sub_round_eq_min, min_le_iff], rcases le_or_lt (z : α) x with hx | hx; [left, right], { conv_rhs { rw [abs_eq_self.mpr (sub_nonneg.mpr hx), ← fract_add_floor x, add_sub_assoc], }, simpa only [le_add_iff_nonneg_right, sub_nonneg, cast_le] using le_floor.mpr hx, }, { rw abs_eq_neg_self.mpr (sub_neg.mpr hx).le, conv_rhs { rw ← fract_add_floor x, }, rw [add_sub_assoc, add_comm, neg_add, neg_sub, le_add_neg_iff_add_le, sub_add_cancel, le_sub_comm], norm_cast, exact floor_le_sub_one_iff.mpr hx, }, end end linear_ordered_ring section linear_ordered_field variables [linear_ordered_field α] [floor_ring α] lemma round_eq (x : α) : round x = ⌊x + 1 / 2⌋ := begin simp_rw [round, (by simp only [lt_div_iff', two_pos] : 2 * fract x < 1 ↔ fract x < 1 / 2)], cases lt_or_ge (fract x) (1 / 2) with hx hx, { conv_rhs { rw [← fract_add_floor x, add_assoc, add_left_comm, floor_int_add], }, rw [if_pos hx, self_eq_add_right, floor_eq_iff, cast_zero, zero_add], split; linarith [fract_nonneg x], }, { have : ⌊fract x + 1 / 2⌋ = 1, { rw floor_eq_iff, split; norm_num; linarith [fract_lt_one x], }, rw [if_neg (not_lt.mpr hx), ← fract_add_floor x, add_assoc, add_left_comm, floor_int_add, ceil_add_int, add_comm _ ⌊x⌋, add_right_inj, ceil_eq_iff, this, cast_one, sub_self], split; linarith [fract_lt_one x], }, end @[simp] lemma round_two_inv : round (2⁻¹ : α) = 1 := by simp only [round_eq, ← one_div, add_halves', floor_one] @[simp] lemma round_neg_two_inv : round (-2⁻¹ : α) = 0 := by simp only [round_eq, ← one_div, add_left_neg, floor_zero] @[simp] lemma round_eq_zero_iff {x : α} : round x = 0 ↔ x ∈ Ico (-(1 / 2)) ((1 : α)/2) := begin rw [round_eq, floor_eq_zero_iff, add_mem_Ico_iff_left], norm_num, end lemma abs_sub_round (x : α) : |x - round x| ≤ 1 / 2 := begin rw [round_eq, abs_sub_le_iff], have := floor_le (x + 1 / 2), have := lt_floor_add_one (x + 1 / 2), split; linarith end lemma abs_sub_round_div_nat_cast_eq {m n : ℕ} : |(m : α) / n - round ((m : α) / n)| = ↑(min (m % n) (n - m % n)) / n := begin rcases n.eq_zero_or_pos with rfl | hn, { simp, }, have hn' : 0 < (n : α), { norm_cast, assumption, }, rw [abs_sub_round_eq_min, nat.cast_min, ← min_div_div_right hn'.le, fract_div_nat_cast_eq_div_nat_cast_mod, nat.cast_sub (m.mod_lt hn).le, sub_div, div_self hn'.ne.symm], end end linear_ordered_field end round namespace nat variables [linear_ordered_semiring α] [linear_ordered_semiring β] [floor_semiring α] [floor_semiring β] [ring_hom_class F α β] {a : α} {b : β} include β lemma floor_congr (h : ∀ n : ℕ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋₊ = ⌊b⌋₊ := begin have h₀ : 0 ≤ a ↔ 0 ≤ b := by simpa only [cast_zero] using h 0, obtain ha | ha := lt_or_le a 0, { rw [floor_of_nonpos ha.le, floor_of_nonpos (le_of_not_le $ h₀.not.mp ha.not_le)] }, exact (le_floor $ (h _).1 $ floor_le ha).antisymm (le_floor $ (h _).2 $ floor_le $ h₀.1 ha), end lemma ceil_congr (h : ∀ n : ℕ, a ≤ n ↔ b ≤ n) : ⌈a⌉₊ = ⌈b⌉₊ := (ceil_le.2 $ (h _).2 $ le_ceil _).antisymm $ ceil_le.2 $ (h _).1 $ le_ceil _ lemma map_floor (f : F) (hf : strict_mono f) (a : α) : ⌊f a⌋₊ = ⌊a⌋₊ := floor_congr $ λ n, by rw [←map_nat_cast f, hf.le_iff_le] lemma map_ceil (f : F) (hf : strict_mono f) (a : α) : ⌈f a⌉₊ = ⌈a⌉₊ := ceil_congr $ λ n, by rw [←map_nat_cast f, hf.le_iff_le] end nat namespace int variables [linear_ordered_ring α] [linear_ordered_ring β] [floor_ring α] [floor_ring β] [ring_hom_class F α β] {a : α} {b : β} include β lemma floor_congr (h : ∀ n : ℤ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋ = ⌊b⌋ := (le_floor.2 $ (h _).1 $ floor_le _).antisymm $ le_floor.2 $ (h _).2 $ floor_le _ lemma ceil_congr (h : ∀ n : ℤ, a ≤ n ↔ b ≤ n) : ⌈a⌉ = ⌈b⌉ := (ceil_le.2 $ (h _).2 $ le_ceil _).antisymm $ ceil_le.2 $ (h _).1 $ le_ceil _ lemma map_floor (f : F) (hf : strict_mono f) (a : α) : ⌊f a⌋ = ⌊a⌋ := floor_congr $ λ n, by rw [←map_int_cast f, hf.le_iff_le] lemma map_ceil (f : F) (hf : strict_mono f) (a : α) : ⌈f a⌉ = ⌈a⌉ := ceil_congr $ λ n, by rw [←map_int_cast f, hf.le_iff_le] lemma map_fract (f : F) (hf : strict_mono f) (a : α) : fract (f a) = f (fract a) := by simp_rw [fract, map_sub, map_int_cast, map_floor _ hf] end int namespace int variables [linear_ordered_field α] [linear_ordered_field β] [floor_ring α] [floor_ring β] [ring_hom_class F α β] {a : α} {b : β} include β lemma map_round (f : F) (hf : strict_mono f) (a : α) : round (f a) = round a := by simp_rw [round_eq, ←map_floor _ hf, map_add, one_div, map_inv₀, map_bit0, map_one] end int section floor_ring_to_semiring variables {α} [linear_ordered_ring α] [floor_ring α] /-! #### A floor ring as a floor semiring -/ @[priority 100] -- see Note [lower instance priority] instance _root_.floor_ring.to_floor_semiring : floor_semiring α := { floor := λ a, ⌊a⌋.to_nat, ceil := λ a, ⌈a⌉.to_nat, floor_of_neg := λ a ha, int.to_nat_of_nonpos (int.floor_nonpos ha.le), gc_floor := λ a n ha, by rw [int.le_to_nat_iff (int.floor_nonneg.2 ha), int.le_floor, int.cast_coe_nat], gc_ceil := λ a n, by rw [int.to_nat_le, int.ceil_le, int.cast_coe_nat] } lemma int.floor_to_nat (a : α) : ⌊a⌋.to_nat = ⌊a⌋₊ := rfl lemma int.ceil_to_nat (a : α) : ⌈a⌉.to_nat = ⌈a⌉₊ := rfl @[simp] lemma nat.floor_int : (nat.floor : ℤ → ℕ) = int.to_nat := rfl @[simp] lemma nat.ceil_int : (nat.ceil : ℤ → ℕ) = int.to_nat := rfl variables {a : α} lemma nat.cast_floor_eq_int_floor (ha : 0 ≤ a) : (⌊a⌋₊ : ℤ) = ⌊a⌋ := by rw [←int.floor_to_nat, int.to_nat_of_nonneg (int.floor_nonneg.2 ha)] lemma nat.cast_floor_eq_cast_int_floor (ha : 0 ≤ a) : (⌊a⌋₊ : α) = ⌊a⌋ := by rw [←nat.cast_floor_eq_int_floor ha, int.cast_coe_nat] lemma nat.cast_ceil_eq_int_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : ℤ) = ⌈a⌉ := by { rw [←int.ceil_to_nat, int.to_nat_of_nonneg (int.ceil_nonneg ha)] } lemma nat.cast_ceil_eq_cast_int_ceil (ha : 0 ≤ a) : (⌈a⌉₊ : α) = ⌈a⌉ := by rw [←nat.cast_ceil_eq_int_ceil ha, int.cast_coe_nat] end floor_ring_to_semiring /-- There exists at most one `floor_ring` structure on a given linear ordered ring. -/ lemma subsingleton_floor_ring {α} [linear_ordered_ring α] : subsingleton (floor_ring α) := begin refine ⟨λ H₁ H₂, _⟩, have : H₁.floor = H₂.floor := funext (λ a, H₁.gc_coe_floor.u_unique H₂.gc_coe_floor $ λ _, rfl), have : H₁.ceil = H₂.ceil := funext (λ a, H₁.gc_ceil_coe.l_unique H₂.gc_ceil_coe $ λ _, rfl), cases H₁, cases H₂, congr; assumption end namespace tactic open positivity private lemma int_floor_nonneg [linear_ordered_ring α] [floor_ring α] {a : α} (ha : 0 ≤ a) : 0 ≤ ⌊a⌋ := int.floor_nonneg.2 ha private lemma int_floor_nonneg_of_pos [linear_ordered_ring α] [floor_ring α] {a : α} (ha : 0 < a) : 0 ≤ ⌊a⌋ := int_floor_nonneg ha.le /-- Extension for the `positivity` tactic: `int.floor` is nonnegative if its input is. -/ @[positivity] meta def positivity_floor : expr → tactic strictness | `(⌊%%a⌋) := do strictness_a ← core a, match strictness_a with | positive p := nonnegative <$> mk_app ``int_floor_nonneg_of_pos [p] | nonnegative p := nonnegative <$> mk_app ``int_floor_nonneg [p] | _ := failed end | e := pp e >>= fail ∘ format.bracket "The expression `" "` is not of the form `⌊a⌋`" private lemma nat_ceil_pos [linear_ordered_semiring α] [floor_semiring α] {a : α} : 0 < a → 0 < ⌈a⌉₊ := nat.ceil_pos.2 private lemma int_ceil_pos [linear_ordered_ring α] [floor_ring α] {a : α} : 0 < a → 0 < ⌈a⌉ := int.ceil_pos.2 /-- Extension for the `positivity` tactic: `ceil` and `int.ceil` are positive/nonnegative if their input is. -/ @[positivity] meta def positivity_ceil : expr → tactic strictness | `(⌈%%a⌉₊) := do positive p ← core a, -- We already know `0 ≤ n` for all `n : ℕ` positive <$> mk_app ``nat_ceil_pos [p] | `(⌈%%a⌉) := do strictness_a ← core a, match strictness_a with | positive p := positive <$> mk_app ``int_ceil_pos [p] | nonnegative p := nonnegative <$> mk_app ``int.ceil_nonneg [p] | _ := failed end | e := pp e >>= fail ∘ format.bracket "The expression `" "` is not of the form `⌈a⌉₊` nor `⌈a⌉`" end tactic
8f0dbfa33dfb51a481fd31516652c8056ecc31fa
1446f520c1db37e157b631385707cc28a17a595e
/stage0/src/Init/Util.lean
b71ac3f860f752e85a49973eb35911dd2e7a0ab0
[ "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
3,136
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.Data.String.Basic import Init.Data.ToString universes u v /- debugging helper functions -/ @[neverExtract, extern "lean_dbg_trace"] def dbgTrace {α : Type u} (s : String) (f : Unit → α) : α := f () /- Display the given message if `a` is shared, that is, RC(a) > 1 -/ @[neverExtract, extern "lean_dbg_trace_if_shared"] def dbgTraceIfShared {α : Type u} (s : String) (a : α) : α := a @[extern "lean_dbg_sleep"] def dbgSleep {α : Type u} (ms : UInt32) (f : Unit → α) : α := f () @[extern c inline "#4"] unsafe def unsafeCast {α : Type u} {β : Type v} [inh : @& Inhabited β] (a : α) : β := arbitrary _ @[neverExtract, extern "lean_panic_fn"] constant panic {α : Type u} [Inhabited α] (msg : String) : α := arbitrary _ @[noinline] private def mkPanicMessage (modName : String) (line col : Nat) (msg : String) : String := "PANIC at " ++ modName ++ ":" ++ toString line ++ ":" ++ toString col ++ ": " ++ msg @[neverExtract, inline] def panicWithPos {α : Type u} [Inhabited α] (modName : String) (line col : Nat) (msg : String) : α := panic (mkPanicMessage modName line col msg) -- TODO: should be a macro @[neverExtract, noinline, nospecialize] def unreachable! {α : Type u} [Inhabited α] : α := panic! "unreachable" @[extern "lean_ptr_addr"] unsafe def ptrAddrUnsafe {α : Type u} (a : @& α) : USize := 0 @[inline] unsafe def withPtrAddrUnsafe {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β := k (ptrAddrUnsafe a) @[inline] unsafe def withPtrEqUnsafe {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool := if ptrAddrUnsafe a == ptrAddrUnsafe b then true else k () inductive PtrEqResult {α : Type u} (x y : α) : Type | unknown {} : PtrEqResult | yesEqual (h : x = y) : PtrEqResult @[inline] unsafe def withPtrEqResultUnsafe {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β := if ptrAddrUnsafe a == ptrAddrUnsafe b then k (PtrEqResult.yesEqual lcProof) else k PtrEqResult.unknown @[implementedBy withPtrEqUnsafe] def withPtrEq {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool := k () /-- `withPtrEq` for `DecidableEq` -/ @[inline] def withPtrEqDecEq {α : Type u} (a b : α) (k : Unit → Decidable (a = b)) : Decidable (a = b) := let b := withPtrEq a b (fun _ => toBoolUsing (k ())) (toBoolUsingEqTrue (k ())); condEq b (fun h => isTrue (ofBoolUsingEqTrue h)) (fun h => isFalse (ofBoolUsingEqFalse h)) /-- Similar to `withPtrEq`, but executes the continuation `k` with the "result" of the pointer equality test. -/ @[implementedBy withPtrEqResultUnsafe] def withPtrEqResult {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β := k PtrEqResult.unknown @[implementedBy withPtrAddrUnsafe] def withPtrAddr {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β := k 0
a5e2ea56e516843e076cde43e8c9985e99f967e6
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
/library/init/algebra/ring.lean
9889a368709c97b20aeca363b89c86dea2da93e3
[ "Apache-2.0" ]
permissive
leodemoura/lean_clone
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
cc077554b584d39bab55c360bc12a6fe7957afe6
refs/heads/master
1,610,506,475,484
1,482,348,354,000
1,482,348,543,000
77,091,586
0
0
null
null
null
null
UTF-8
Lean
false
false
8,755
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ prelude import init.algebra.group /- Make sure instances defined in this file have lower priority than the ones defined for concrete structures -/ set_option default_priority 100 universe variable u class distrib (α : Type u) extends has_mul α, has_add α := (left_distrib : ∀ a b c : α, a * (b + c) = (a * b) + (a * c)) (right_distrib : ∀ a b c : α, (a + b) * c = (a * c) + (b * c)) variable {α : Type u} lemma left_distrib [distrib α] (a b c : α) : a * (b + c) = a * b + a * c := distrib.left_distrib a b c def mul_add := @left_distrib lemma right_distrib [distrib α] (a b c : α) : (a + b) * c = a * c + b * c := distrib.right_distrib a b c def add_mul := @right_distrib class mul_zero_class (α : Type u) extends has_mul α, has_zero α := (zero_mul : ∀ a : α, 0 * a = 0) (mul_zero : ∀ a : α, a * 0 = 0) @[simp] lemma zero_mul [mul_zero_class α] (a : α) : 0 * a = 0 := mul_zero_class.zero_mul a @[simp] lemma mul_zero [mul_zero_class α] (a : α) : a * 0 = 0 := mul_zero_class.mul_zero a class zero_ne_one_class (α : Type u) extends has_zero α, has_one α := (zero_ne_one : 0 ≠ (1:α)) lemma zero_ne_one [s: zero_ne_one_class α] : 0 ≠ (1:α) := @zero_ne_one_class.zero_ne_one α s /- semiring -/ structure semiring (α : Type u) extends comm_monoid α renaming mul→add mul_assoc→add_assoc one→zero one_mul→zero_add mul_one→add_zero mul_comm→add_comm, monoid α, distrib α, mul_zero_class α attribute [class] semiring instance add_comm_monoid_of_semiring (α : Type u) [s : semiring α] : add_comm_monoid α := @semiring.to_comm_monoid α s instance monoid_of_semiring (α : Type u) [s : semiring α] : monoid α := @semiring.to_monoid α s instance distrib_of_semiring (α : Type u) [s : semiring α] : distrib α := @semiring.to_distrib α s instance mul_zero_class_of_semiring (α : Type u) [s : semiring α] : mul_zero_class α := @semiring.to_mul_zero_class α s section semiring variables [semiring α] lemma one_add_one_eq_two : 1 + 1 = (2 : α) := begin unfold bit0, reflexivity end lemma ne_zero_of_mul_ne_zero_right {a b : α} (h : a * b ≠ 0) : a ≠ 0 := suppose a = 0, have a * b = 0, by rw [this, zero_mul], h this lemma ne_zero_of_mul_ne_zero_left {a b : α} (h : a * b ≠ 0) : b ≠ 0 := suppose b = 0, have a * b = 0, by rw [this, mul_zero], h this lemma distrib_three_right (a b c d : α) : (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib] end semiring class comm_semiring (α : Type u) extends semiring α, comm_monoid α /- ring -/ structure ring (α : Type u) extends comm_group α renaming mul→add mul_assoc→add_assoc one→zero one_mul→zero_add mul_one→add_zero inv→neg mul_left_inv→add_left_inv mul_comm→add_comm, monoid α, distrib α attribute [class] ring instance to_add_comm_group_of_ring (α : Type u) [s : ring α] : add_comm_group α := @ring.to_comm_group α s instance monoid_of_ring (α : Type u) [s : ring α] : monoid α := @ring.to_monoid α s instance distrib_of_ring (α : Type u) [s : ring α] : distrib α := @ring.to_distrib α s lemma ring.mul_zero [ring α] (a : α) : a * 0 = 0 := have a * 0 + 0 = a * 0 + a * 0, from calc a * 0 + 0 = a * (0 + 0) : by simp ... = a * 0 + a * 0 : by rw left_distrib, show a * 0 = 0, from (add_left_cancel this)^.symm lemma ring.zero_mul [ring α] (a : α) : 0 * a = 0 := have 0 * a + 0 = 0 * a + 0 * a, from calc 0 * a + 0 = (0 + 0) * a : by simp ... = 0 * a + 0 * a : by rewrite right_distrib, show 0 * a = 0, from (add_left_cancel this)^.symm instance ring.to_semiring [s : ring α] : semiring α := { s with mul_zero := ring.mul_zero, zero_mul := ring.zero_mul } lemma neg_mul_eq_neg_mul [s : ring α] (a b : α) : -(a * b) = -a * b := neg_eq_of_add_eq_zero begin rw [-right_distrib, add_right_neg, zero_mul] end lemma neg_mul_eq_mul_neg [s : ring α] (a b : α) : -(a * b) = a * -b := neg_eq_of_add_eq_zero begin rw [-left_distrib, add_right_neg, mul_zero] end @[simp] lemma neg_mul_eq_neg_mul_symm [s : ring α] (a b : α) : - a * b = - (a * b) := eq.symm (neg_mul_eq_neg_mul a b) @[simp] lemma mul_neg_eq_neg_mul_symm [s : ring α] (a b : α) : a * - b = - (a * b) := eq.symm (neg_mul_eq_mul_neg a b) lemma neg_mul_neg [s : ring α] (a b : α) : -a * -b = a * b := by simp lemma neg_mul_comm [s : ring α] (a b : α) : -a * b = a * -b := by simp theorem neg_eq_neg_one_mul [s : ring α] (a : α) : -a = -1 * a := by simp lemma mul_sub_left_distrib [s : ring α] (a b c : α) : a * (b - c) = a * b - a * c := calc a * (b - c) = a * b + a * -c : left_distrib a b (-c) ... = a * b - a * c : by simp def mul_sub := @mul_sub_left_distrib lemma mul_sub_right_distrib [s : ring α] (a b c : α) : (a - b) * c = a * c - b * c := calc (a - b) * c = a * c + -b * c : right_distrib a (-b) c ... = a * c - b * c : by simp def sub_mul := @mul_sub_right_distrib class comm_ring (α : Type u) extends ring α, comm_semigroup α instance comm_ring.to_comm_semiring [s : comm_ring α] : comm_semiring α := { s with mul_zero := mul_zero, zero_mul := zero_mul } section comm_ring variable [comm_ring α] lemma mul_self_sub_mul_self_eq (a b : α) : a * a - b * b = (a + b) * (a - b) := by simp [right_distrib, left_distrib] lemma mul_self_sub_one_eq (a : α) : a * a - 1 = (a + 1) * (a - 1) := by simp [right_distrib, left_distrib] lemma add_mul_self_eq (a b : α) : (a + b) * (a + b) = a*a + 2*a*b + b*b := calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : by simp [right_distrib, left_distrib] ... = a*a + 2*a*b + b*b : by rw one_add_one_eq_two end comm_ring class no_zero_divisors (α : Type u) extends has_mul α, has_zero α := (eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0) lemma eq_zero_or_eq_zero_of_mul_eq_zero [no_zero_divisors α] {a b : α} (h : a * b = 0) : a = 0 ∨ b = 0 := no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero a b h lemma eq_zero_of_mul_self_eq_zero [no_zero_divisors α] {a : α} (h : a * a = 0) : a = 0 := or.elim (eq_zero_or_eq_zero_of_mul_eq_zero h) (assume h', h') (assume h', h') class integral_domain (α : Type u) extends comm_ring α, no_zero_divisors α, zero_ne_one_class α section integral_domain variable [integral_domain α] lemma mul_ne_zero {a b : α} (h₁ : a ≠ 0) (h₂ : b ≠ 0) : a * b ≠ 0 := λ h, or.elim (eq_zero_or_eq_zero_of_mul_eq_zero h) (assume h₃, h₁ h₃) (assume h₄, h₂ h₄) lemma eq_of_mul_eq_mul_right {a b c : α} (ha : a ≠ 0) (h : b * a = c * a) : b = c := have b * a - c * a = 0, from sub_eq_zero_of_eq h, have (b - c) * a = 0, by rw [mul_sub_right_distrib, this], have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right ha, eq_of_sub_eq_zero this lemma eq_of_mul_eq_mul_left {a b c : α} (ha : a ≠ 0) (h : a * b = a * c) : b = c := have a * b - a * c = 0, from sub_eq_zero_of_eq h, have a * (b - c) = 0, by rw [mul_sub_left_distrib, this], have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_left ha, eq_of_sub_eq_zero this lemma eq_zero_of_mul_eq_self_right {a b : α} (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 := have hb : b - 1 ≠ 0, from suppose b - 1 = 0, have b = 0 + 1, from eq_add_of_sub_eq this, have b = 1, by rwa zero_add at this, h₁ this, have a * b - a = 0, by simp [h₂], have a * (b - 1) = 0, by rwa [mul_sub_left_distrib, mul_one], show a = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right hb lemma eq_zero_of_mul_eq_self_left {a b : α} (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 := eq_zero_of_mul_eq_self_right h₁ (by rwa mul_comm at h₂) lemma mul_self_eq_mul_self_iff (a b : α) : a * a = b * b ↔ a = b ∨ a = -b := iff.intro (suppose a * a = b * b, have (a - b) * (a + b) = 0, by rewrite [mul_comm, -mul_self_sub_mul_self_eq, this, sub_self], have a - b = 0 ∨ a + b = 0, from eq_zero_or_eq_zero_of_mul_eq_zero this, or.elim this (suppose a - b = 0, or.inl (eq_of_sub_eq_zero this)) (suppose a + b = 0, or.inr (eq_neg_of_add_eq_zero this))) (suppose a = b ∨ a = -b, or.elim this (suppose a = b, by rewrite this) (suppose a = -b, by rewrite [this, neg_mul_neg])) lemma mul_self_eq_one_iff (a : α) : a * a = 1 ↔ a = 1 ∨ a = -1 := have a * a = 1 * 1 ↔ a = 1 ∨ a = -1, from mul_self_eq_mul_self_iff a 1, by rwa mul_one at this end integral_domain
6b97e99a93b93f157fbc8c0d2236041c7da3d429
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/complex/basic.lean
9b8097b45dcf2b96352f6b7f97fee720126e3d36
[ "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,384
lean
/- Copyright (c) Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import data.complex.module import data.complex.exponential import data.is_R_or_C.basic import topology.algebra.infinite_sum.module import topology.instances.real_vector_space /-! # Normed space structure on `ℂ`. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file gathers basic facts on complex numbers of an analytic nature. ## Main results This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `ℂ`. Notably, in the namespace `complex`, it defines functions: * `re_clm` * `im_clm` * `of_real_clm` * `conj_cle` They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate as continuous `ℝ`-linear maps. The last two are also bundled as linear isometries in `of_real_li` and `conj_lie`. We also register the fact that `ℂ` is an `is_R_or_C` field. -/ assert_not_exists absorbs noncomputable theory namespace complex open_locale complex_conjugate topology instance : has_norm ℂ := ⟨abs⟩ @[simp] lemma norm_eq_abs (z : ℂ) : ‖z‖ = abs z := rfl lemma norm_exp_of_real_mul_I (t : ℝ) : ‖exp (t * I)‖ = 1 := by simp only [norm_eq_abs, abs_exp_of_real_mul_I] instance : normed_add_comm_group ℂ := add_group_norm.to_normed_add_comm_group { map_zero' := map_zero abs, neg' := abs.map_neg, eq_zero_of_map_eq_zero' := λ _, abs.eq_zero.1, ..abs } instance : normed_field ℂ := { norm := abs, dist_eq := λ _ _, rfl, norm_mul' := map_mul abs, .. complex.field, .. complex.normed_add_comm_group } instance : densely_normed_field ℂ := { lt_norm_lt := λ r₁ r₂ h₀ hr, let ⟨x, h⟩ := normed_field.exists_lt_norm_lt ℝ h₀ hr in have this : ‖(‖x‖ : ℂ)‖ = ‖(‖x‖)‖, by simp only [norm_eq_abs, abs_of_real, real.norm_eq_abs], ⟨‖x‖, by rwa [this, norm_norm]⟩ } instance {R : Type*} [normed_field R] [normed_algebra R ℝ] : normed_algebra R ℂ := { norm_smul_le := λ r x, begin rw [norm_eq_abs, norm_eq_abs, ←algebra_map_smul ℝ r x, algebra.smul_def, map_mul, ←norm_algebra_map' ℝ r, coe_algebra_map, abs_of_real], refl, end, to_algebra := complex.algebra } variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E] /-- The module structure from `module.complex_to_real` is a normed space. -/ @[priority 900] -- see Note [lower instance priority] instance _root_.normed_space.complex_to_real : normed_space ℝ E := normed_space.restrict_scalars ℝ ℂ E lemma dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl lemma dist_eq_re_im (z w : ℂ) : dist z w = real.sqrt ((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by { rw [sq, sq], refl } @[simp] lemma dist_mk (x₁ y₁ x₂ y₂ : ℝ) : dist (mk x₁ y₁) (mk x₂ y₂) = real.sqrt ((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) := dist_eq_re_im _ _ lemma dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by rw [dist_eq_re_im, h, sub_self, zero_pow two_pos, zero_add, real.sqrt_sq_eq_abs, real.dist_eq] lemma nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im := nnreal.eq $ dist_of_re_eq h lemma edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by rw [edist_nndist, edist_nndist, nndist_of_re_eq h] lemma dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by rw [dist_eq_re_im, h, sub_self, zero_pow two_pos, add_zero, real.sqrt_sq_eq_abs, real.dist_eq] lemma nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re := nnreal.eq $ dist_of_im_eq h lemma edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by rw [edist_nndist, edist_nndist, nndist_of_im_eq h] lemma dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, real.dist_eq, sub_neg_eq_add, ← two_mul, _root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)] lemma nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * real.nnabs z.im := nnreal.eq $ by rw [← dist_nndist, nnreal.coe_mul, nnreal.coe_two, real.coe_nnabs, dist_conj_self] lemma dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self] lemma nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * real.nnabs z.im := by rw [nndist_comm, nndist_conj_self] @[simp] lemma comap_abs_nhds_zero : filter.comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero lemma norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := abs_of_real _ @[simp] lemma norm_rat (r : ℚ) : ‖(r : ℂ)‖ = |(r : ℝ)| := by { rw ← of_real_rat_cast, exact norm_real _ } @[simp] lemma norm_nat (n : ℕ) : ‖(n : ℂ)‖ = n := abs_of_nat _ @[simp] lemma norm_int {n : ℤ} : ‖(n : ℂ)‖ = |n| := by simp [← rat.cast_coe_int] {single_pass := tt} lemma norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by simp [hn] @[continuity] lemma continuous_abs : continuous abs := continuous_norm @[continuity] lemma continuous_norm_sq : continuous norm_sq := by simpa [← norm_sq_eq_abs] using continuous_abs.pow 2 @[simp, norm_cast] lemma nnnorm_real (r : ℝ) : ‖(r : ℂ)‖₊ = ‖r‖₊ := subtype.ext $ norm_real r @[simp, norm_cast] lemma nnnorm_nat (n : ℕ) : ‖(n : ℂ)‖₊ = n := subtype.ext $ by simp @[simp, norm_cast] lemma nnnorm_int (n : ℤ) : ‖(n : ℂ)‖₊ = ‖n‖₊ := subtype.ext $ by simp only [coe_nnnorm, norm_int, int.norm_eq_abs] lemma nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖₊ = 1 := begin refine (@pow_left_inj nnreal _ _ _ _ zero_le' zero_le' hn.bot_lt).mp _, rw [←nnnorm_pow, h, nnnorm_one, one_pow], end lemma norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖ = 1 := congr_arg coe (nnnorm_eq_one_of_pow_eq_one h hn) lemma equiv_real_prod_apply_le (z : ℂ) : ‖equiv_real_prod z‖ ≤ abs z := by simp [prod.norm_def, abs_re_le_abs, abs_im_le_abs] lemma equiv_real_prod_apply_le' (z : ℂ) : ‖equiv_real_prod z‖ ≤ 1 * abs z := by simpa using equiv_real_prod_apply_le z lemma lipschitz_equiv_real_prod : lipschitz_with 1 equiv_real_prod := by simpa using add_monoid_hom_class.lipschitz_of_bound equiv_real_prod_lm 1 equiv_real_prod_apply_le' lemma antilipschitz_equiv_real_prod : antilipschitz_with (nnreal.sqrt 2) equiv_real_prod := by simpa using add_monoid_hom_class.antilipschitz_of_bound equiv_real_prod_lm abs_le_sqrt_two_mul_max lemma uniform_embedding_equiv_real_prod : uniform_embedding equiv_real_prod := antilipschitz_equiv_real_prod.uniform_embedding lipschitz_equiv_real_prod.uniform_continuous instance : complete_space ℂ := (complete_space_congr uniform_embedding_equiv_real_prod).mpr infer_instance /-- The natural `continuous_linear_equiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }] def equiv_real_prod_clm : ℂ ≃L[ℝ] ℝ × ℝ := equiv_real_prod_lm.to_continuous_linear_equiv_of_bounds 1 (real.sqrt 2) equiv_real_prod_apply_le' (λ p, abs_le_sqrt_two_mul_max (equiv_real_prod.symm p)) instance : proper_space ℂ := (id lipschitz_equiv_real_prod : lipschitz_with 1 equiv_real_prod_clm.to_homeomorph).proper_space /-- The `abs` function on `ℂ` is proper. -/ lemma tendsto_abs_cocompact_at_top : filter.tendsto abs (filter.cocompact ℂ) filter.at_top := tendsto_norm_cocompact_at_top /-- The `norm_sq` function on `ℂ` is proper. -/ lemma tendsto_norm_sq_cocompact_at_top : filter.tendsto norm_sq (filter.cocompact ℂ) filter.at_top := by simpa [mul_self_abs] using tendsto_abs_cocompact_at_top.at_top_mul_at_top tendsto_abs_cocompact_at_top open continuous_linear_map /-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/ def re_clm : ℂ →L[ℝ] ℝ := re_lm.mk_continuous 1 (λ x, by simp [abs_re_le_abs]) @[continuity] lemma continuous_re : continuous re := re_clm.continuous @[simp] lemma re_clm_coe : (coe (re_clm) : ℂ →ₗ[ℝ] ℝ) = re_lm := rfl @[simp] lemma re_clm_apply (z : ℂ) : (re_clm : ℂ → ℝ) z = z.re := rfl /-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/ def im_clm : ℂ →L[ℝ] ℝ := im_lm.mk_continuous 1 (λ x, by simp [abs_im_le_abs]) @[continuity] lemma continuous_im : continuous im := im_clm.continuous @[simp] lemma im_clm_coe : (coe (im_clm) : ℂ →ₗ[ℝ] ℝ) = im_lm := rfl @[simp] lemma im_clm_apply (z : ℂ) : (im_clm : ℂ → ℝ) z = z.im := rfl lemma restrict_scalars_one_smul_right' (x : E) : continuous_linear_map.restrict_scalars ℝ ((1 : ℂ →L[ℂ] ℂ).smul_right x : ℂ →L[ℂ] E) = re_clm.smul_right x + I • im_clm.smul_right x := by { ext ⟨a, b⟩, simp [mk_eq_add_mul_I, add_smul, mul_smul, smul_comm I] } lemma restrict_scalars_one_smul_right (x : ℂ) : continuous_linear_map.restrict_scalars ℝ ((1 : ℂ →L[ℂ] ℂ).smul_right x : ℂ →L[ℂ] ℂ) = x • 1 := by { ext1 z, dsimp, apply mul_comm } /-- The complex-conjugation function from `ℂ` to itself is an isometric linear equivalence. -/ def conj_lie : ℂ ≃ₗᵢ[ℝ] ℂ := ⟨conj_ae.to_linear_equiv, abs_conj⟩ @[simp] lemma conj_lie_apply (z : ℂ) : conj_lie z = conj z := rfl @[simp] lemma conj_lie_symm : conj_lie.symm = conj_lie := rfl lemma isometry_conj : isometry (conj : ℂ → ℂ) := conj_lie.isometry @[simp] lemma dist_conj_conj (z w : ℂ) : dist (conj z) (conj w) = dist z w := isometry_conj.dist_eq z w @[simp] lemma nndist_conj_conj (z w : ℂ) : nndist (conj z) (conj w) = nndist z w := isometry_conj.nndist_eq z w lemma dist_conj_comm (z w : ℂ) : dist (conj z) w = dist z (conj w) := by rw [← dist_conj_conj, conj_conj] lemma nndist_conj_comm (z w : ℂ) : nndist (conj z) w = nndist z (conj w) := subtype.ext $ dist_conj_comm _ _ instance : has_continuous_star ℂ := ⟨conj_lie.continuous⟩ @[continuity] lemma continuous_conj : continuous (conj : ℂ → ℂ) := continuous_star /-- The only continuous ring homomorphisms from `ℂ` to `ℂ` are the identity and the complex conjugation. -/ lemma ring_hom_eq_id_or_conj_of_continuous {f : ℂ →+* ℂ} (hf : continuous f) : f = ring_hom.id ℂ ∨ f = conj := begin refine (real_alg_hom_eq_id_or_conj $ alg_hom.mk' f $ map_real_smul f hf).imp (λ h, _) (λ h, _), all_goals { convert congr_arg alg_hom.to_ring_hom h, ext1, refl, }, end /-- Continuous linear equiv version of the conj function, from `ℂ` to `ℂ`. -/ def conj_cle : ℂ ≃L[ℝ] ℂ := conj_lie @[simp] lemma conj_cle_coe : conj_cle.to_linear_equiv = conj_ae.to_linear_equiv := rfl @[simp] lemma conj_cle_apply (z : ℂ) : conj_cle z = conj z := rfl /-- Linear isometry version of the canonical embedding of `ℝ` in `ℂ`. -/ def of_real_li : ℝ →ₗᵢ[ℝ] ℂ := ⟨of_real_am.to_linear_map, norm_real⟩ lemma isometry_of_real : isometry (coe : ℝ → ℂ) := of_real_li.isometry @[continuity] lemma continuous_of_real : continuous (coe : ℝ → ℂ) := of_real_li.continuous /-- The only continuous ring homomorphism from `ℝ` to `ℂ` is the identity. -/ lemma ring_hom_eq_of_real_of_continuous {f : ℝ →+* ℂ} (h : continuous f) : f = complex.of_real := begin convert congr_arg alg_hom.to_ring_hom (subsingleton.elim (alg_hom.mk' f $ map_real_smul f h) $ algebra.of_id ℝ ℂ), ext1, refl, end /-- Continuous linear map version of the canonical embedding of `ℝ` in `ℂ`. -/ def of_real_clm : ℝ →L[ℝ] ℂ := of_real_li.to_continuous_linear_map @[simp] lemma of_real_clm_coe : (of_real_clm : ℝ →ₗ[ℝ] ℂ) = of_real_am.to_linear_map := rfl @[simp] lemma of_real_clm_apply (x : ℝ) : of_real_clm x = x := rfl noncomputable instance : is_R_or_C ℂ := { re := ⟨complex.re, complex.zero_re, complex.add_re⟩, im := ⟨complex.im, complex.zero_im, complex.add_im⟩, I := complex.I, I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re], I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true], re_add_im_ax := λ z, by simp only [add_monoid_hom.coe_mk, complex.re_add_im, complex.coe_algebra_map, complex.of_real_eq_coe], of_real_re_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re, complex.coe_algebra_map, complex.of_real_eq_coe], of_real_im_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im, complex.coe_algebra_map, complex.of_real_eq_coe], mul_re_ax := λ z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk], mul_im_ax := λ z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im], conj_re_ax := λ z, rfl, conj_im_ax := λ z, rfl, conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk], norm_sq_eq_def_ax := λ z, by simp only [←complex.norm_sq_eq_abs, ←complex.norm_sq_apply, add_monoid_hom.coe_mk, complex.norm_eq_abs], mul_im_I_ax := λ z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im] } lemma _root_.is_R_or_C.re_eq_complex_re : ⇑(is_R_or_C.re : ℂ →+ ℝ) = complex.re := rfl lemma _root_.is_R_or_C.im_eq_complex_im : ⇑(is_R_or_C.im : ℂ →+ ℝ) = complex.im := rfl section complex_order open_locale complex_order lemma eq_coe_norm_of_nonneg {z : ℂ} (hz : 0 ≤ z) : z = ↑‖z‖ := by rw [eq_re_of_real_le hz, is_R_or_C.norm_of_real, _root_.abs_of_nonneg (complex.le_def.2 hz).1] end complex_order end complex namespace is_R_or_C open_locale complex_conjugate local notation `reC` := @is_R_or_C.re ℂ _ local notation `imC` := @is_R_or_C.im ℂ _ local notation `IC` := @is_R_or_C.I ℂ _ local notation `norm_sqC` := @is_R_or_C.norm_sq ℂ _ @[simp] lemma re_to_complex {x : ℂ} : reC x = x.re := rfl @[simp] lemma im_to_complex {x : ℂ} : imC x = x.im := rfl @[simp] lemma I_to_complex : IC = complex.I := rfl @[simp] lemma norm_sq_to_complex {x : ℂ} : norm_sqC x = complex.norm_sq x := rfl section tsum variables {α : Type*} (𝕜 : Type*) [is_R_or_C 𝕜] @[simp] lemma has_sum_conj {f : α → 𝕜} {x : 𝕜} : has_sum (λ x, conj (f x)) x ↔ has_sum f (conj x) := conj_cle.has_sum lemma has_sum_conj' {f : α → 𝕜} {x : 𝕜} : has_sum (λ x, conj (f x)) (conj x) ↔ has_sum f x := conj_cle.has_sum' @[simp] lemma summable_conj {f : α → 𝕜} : summable (λ x, conj (f x)) ↔ summable f := summable_star_iff variables {𝕜} lemma conj_tsum (f : α → 𝕜) : conj (∑' a, f a) = ∑' a, conj (f a) := tsum_star variables (𝕜) @[simp, norm_cast] lemma has_sum_of_real {f : α → ℝ} {x : ℝ} : has_sum (λ x, (f x : 𝕜)) x ↔ has_sum f x := ⟨λ h, by simpa only [is_R_or_C.re_clm_apply, is_R_or_C.of_real_re] using re_clm.has_sum h, of_real_clm.has_sum⟩ @[simp, norm_cast] lemma summable_of_real {f : α → ℝ} : summable (λ x, (f x : 𝕜)) ↔ summable f := ⟨λ h, by simpa only [is_R_or_C.re_clm_apply, is_R_or_C.of_real_re] using re_clm.summable h, of_real_clm.summable⟩ @[norm_cast] lemma of_real_tsum (f : α → ℝ) : (↑(∑' a, f a) : 𝕜) = ∑' a, f a := begin by_cases h : summable f, { exact continuous_linear_map.map_tsum of_real_clm h }, { rw [tsum_eq_zero_of_not_summable h, tsum_eq_zero_of_not_summable ((summable_of_real _).not.mpr h), of_real_zero] } end lemma has_sum_re {f : α → 𝕜} {x : 𝕜} (h : has_sum f x) : has_sum (λ x, re (f x)) (re x) := re_clm.has_sum h lemma has_sum_im {f : α → 𝕜} {x : 𝕜} (h : has_sum f x) : has_sum (λ x, im (f x)) (im x) := im_clm.has_sum h lemma re_tsum {f : α → 𝕜} (h : summable f) : re (∑' a, f a) = ∑' a, re (f a) := re_clm.map_tsum h lemma im_tsum {f : α → 𝕜} (h : summable f) : im (∑' a, f a) = ∑' a, im (f a) := im_clm.map_tsum h variables {𝕜} lemma has_sum_iff (f : α → 𝕜) (c : 𝕜) : has_sum f c ↔ has_sum (λ x, re (f x)) (re c) ∧ has_sum (λ x, im (f x)) (im c) := begin refine ⟨λ h, ⟨has_sum_re _ h, has_sum_im _ h⟩, _⟩, rintro ⟨h₁, h₂⟩, rw ←is_R_or_C.re_add_im c, convert ((has_sum_of_real 𝕜).mpr h₁).add (((has_sum_of_real 𝕜).mpr h₂).mul_right I), simp_rw is_R_or_C.re_add_im, end end tsum end is_R_or_C namespace complex /-! We have to repeat the lemmas about `is_R_or_C.re` and `is_R_or_C.im` as they are not syntactic matches for `complex.re` and `complex.im`. We do not have this problem with `of_real` and `conj`, although we repeat them anyway for discoverability and to avoid the need to unify `𝕜`. -/ section tsum variables {α : Type*} open_locale complex_conjugate @[simp] lemma has_sum_conj {f : α → ℂ} {x : ℂ} : has_sum (λ x, conj (f x)) x ↔ has_sum f (conj x) := is_R_or_C.has_sum_conj _ lemma has_sum_conj' {f : α → ℂ} {x : ℂ} : has_sum (λ x, conj (f x)) (conj x) ↔ has_sum f x := is_R_or_C.has_sum_conj' _ @[simp] lemma summable_conj {f : α → ℂ} : summable (λ x, conj (f x)) ↔ summable f := is_R_or_C.summable_conj _ lemma conj_tsum (f : α → ℂ) : conj (∑' a, f a) = ∑' a, conj (f a) := is_R_or_C.conj_tsum _ @[simp, norm_cast] lemma has_sum_of_real {f : α → ℝ} {x : ℝ} : has_sum (λ x, (f x : ℂ)) x ↔ has_sum f x := is_R_or_C.has_sum_of_real _ @[simp, norm_cast] lemma summable_of_real {f : α → ℝ} : summable (λ x, (f x : ℂ)) ↔ summable f := is_R_or_C.summable_of_real _ @[norm_cast] lemma of_real_tsum (f : α → ℝ) : (↑(∑' a, f a) : ℂ) = ∑' a, f a := is_R_or_C.of_real_tsum _ _ lemma has_sum_re {f : α → ℂ} {x : ℂ} (h : has_sum f x) : has_sum (λ x, (f x).re) x.re := is_R_or_C.has_sum_re _ h lemma has_sum_im {f : α → ℂ} {x : ℂ} (h : has_sum f x) : has_sum (λ x, (f x).im) x.im := is_R_or_C.has_sum_im _ h lemma re_tsum {f : α → ℂ} (h : summable f) : (∑' a, f a).re = ∑' a, (f a).re := is_R_or_C.re_tsum _ h lemma im_tsum {f : α → ℂ} (h : summable f) : (∑' a, f a).im = ∑' a, (f a).im := is_R_or_C.im_tsum _ h lemma has_sum_iff (f : α → ℂ) (c : ℂ) : has_sum f c ↔ has_sum (λ x, (f x).re) c.re ∧ has_sum (λ x, (f x).im) c.im := is_R_or_C.has_sum_iff _ _ end tsum end complex
603682f618fbb92a218bc7f48224efd5feddb649
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/data/complex/exponential.lean
41752c4cd981b81dee30a3ffa88ba34f95319d6a
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
46,013
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import algebra.archimedean import data.nat.choose data.complex.basic import tactic.linarith local attribute [instance, priority 0] classical.prop_decidable local notation `abs'` := _root_.abs open is_absolute_value section open real is_absolute_value finset lemma forall_ge_le_of_forall_le_succ {α : Type*} [preorder α] (f : ℕ → α) {m : ℕ} (h : ∀ n ≥ m, f n.succ ≤ f n) : ∀ {l}, ∀ k ≥ m, k ≤ l → f l ≤ f k := begin assume l k hkm hkl, generalize hp : l - k = p, have : l = k + p := add_comm p k ▸ (nat.sub_eq_iff_eq_add hkl).1 hp, subst this, clear hkl hp, induction p with p ih, { simp }, { exact le_trans (h _ (le_trans hkm (nat.le_add_right _ _))) ih } end variables {α : Type*} {β : Type*} [ring β] [discrete_linear_ordered_field α] [archimedean α] {abv : β → α} [is_absolute_value abv] lemma is_cau_of_decreasing_bounded (f : ℕ → α) {a : α} {m : ℕ} (ham : ∀ n ≥ m, abs (f n) ≤ a) (hnm : ∀ n ≥ m, f n.succ ≤ f n) : is_cau_seq abs f := λ ε ε0, let ⟨k, hk⟩ := archimedean.arch a ε0 in have h : ∃ l, ∀ n ≥ m, a - add_monoid.smul l ε < f n := ⟨k + k + 1, λ n hnm, lt_of_lt_of_le (show a - add_monoid.smul (k + (k + 1)) ε < -abs (f n), from lt_neg.1 $ lt_of_le_of_lt (ham n hnm) (begin rw [neg_sub, lt_sub_iff_add_lt, add_monoid.add_smul], exact add_lt_add_of_le_of_lt hk (lt_of_le_of_lt hk (lt_add_of_pos_left _ ε0)), end)) (neg_le.2 $ (abs_neg (f n)) ▸ le_abs_self _)⟩, let l := nat.find h in have hl : ∀ (n : ℕ), n ≥ m → f n > a - add_monoid.smul l ε := nat.find_spec h, have hl0 : l ≠ 0 := λ hl0, not_lt_of_ge (ham m (le_refl _)) (lt_of_lt_of_le (by have := hl m (le_refl m); simpa [hl0] using this) (le_abs_self (f m))), begin cases classical.not_forall.1 (nat.find_min h (nat.pred_lt hl0)) with i hi, rw [not_imp, not_lt] at hi, existsi i, assume j hj, have hfij : f j ≤ f i := forall_ge_le_of_forall_le_succ f hnm _ hi.1 hj, rw [abs_of_nonpos (sub_nonpos.2 hfij), neg_sub, sub_lt_iff_lt_add'], exact calc f i ≤ a - add_monoid.smul (nat.pred l) ε : hi.2 ... = a - add_monoid.smul l ε + ε : by conv {to_rhs, rw [← nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hl0), succ_smul', sub_add, add_sub_cancel] } ... < f j + ε : add_lt_add_right (hl j (le_trans hi.1 hj)) _ end lemma is_cau_of_mono_bounded (f : ℕ → α) {a : α} {m : ℕ} (ham : ∀ n ≥ m, abs (f n) ≤ a) (hnm : ∀ n ≥ m, f n ≤ f n.succ) : is_cau_seq abs f := begin refine @eq.rec_on (ℕ → α) _ (is_cau_seq abs) _ _ (-⟨_, @is_cau_of_decreasing_bounded _ _ _ (λ n, -f n) a m (by simpa) (by simpa)⟩ : cau_seq α abs).2, ext, exact neg_neg _ end lemma is_cau_series_of_abv_le_cau {f : ℕ → β} {g : ℕ → α} (n : ℕ) : (∀ m, n ≤ m → abv (f m) ≤ g m) → is_cau_seq abs (λ n, (range n).sum g) → is_cau_seq abv (λ n, (range n).sum f) := begin assume hm hg ε ε0, cases hg (ε / 2) (div_pos ε0 (by norm_num)) with i hi, existsi max n i, assume j ji, have hi₁ := hi j (le_trans (le_max_right n i) ji), have hi₂ := hi (max n i) (le_max_right n i), have sub_le := abs_sub_le ((range j).sum g) ((range i).sum g) ((range (max n i)).sum g), have := add_lt_add hi₁ hi₂, rw [abs_sub ((range (max n i)).sum g), add_halves ε] at this, refine lt_of_le_of_lt (le_trans (le_trans _ (le_abs_self _)) sub_le) this, generalize hk : j - max n i = k, clear this hi₂ hi₁ hi ε0 ε hg sub_le, rw nat.sub_eq_iff_eq_add ji at hk, rw hk, clear hk ji j, induction k with k' hi, { simp [abv_zero abv] }, { dsimp at *, rw [nat.succ_add, sum_range_succ, sum_range_succ, add_assoc, add_assoc], refine le_trans (abv_add _ _ _) _, exact add_le_add (hm _ (le_add_of_nonneg_of_le (nat.zero_le _) (le_max_left _ _))) hi }, end lemma is_cau_series_of_abv_cau {f : ℕ → β} : is_cau_seq abs (λ m, (range m).sum (λ n, abv (f n))) → is_cau_seq abv (λ m, (range m).sum f) := is_cau_series_of_abv_le_cau 0 (λ n h, le_refl _) lemma is_cau_geo_series {β : Type*} [field β] {abv : β → α} [is_absolute_value abv] (x : β) (hx1 : abv x < 1) : is_cau_seq abv (λ n, (range n).sum (λ m, x ^ m)) := have hx1' : abv x ≠ 1 := λ h, by simpa [h, lt_irrefl] using hx1, is_cau_series_of_abv_cau begin simp only [abv_pow abv, geom_sum hx1'] {eta := ff}, conv in (_ / _) { rw [← neg_div_neg_eq, neg_sub, neg_sub] }, refine @is_cau_of_mono_bounded _ _ _ _ ((1 : α) / (1 - abv x)) 0 _ _, { assume n hn, rw abs_of_nonneg, refine div_le_div_of_le_of_pos (sub_le_self _ (abv_pow abv x n ▸ abv_nonneg _ _)) (sub_pos.2 hx1), refine div_nonneg (sub_nonneg.2 _) (sub_pos.2 hx1), clear hn, induction n with n ih, { simp }, { rw [_root_.pow_succ, ← one_mul (1 : α)], refine mul_le_mul (le_of_lt hx1) ih (abv_pow abv x n ▸ abv_nonneg _ _) (by norm_num) } }, { assume n hn, refine div_le_div_of_le_of_pos (sub_le_sub_left _ _) (sub_pos.2 hx1), rw [← one_mul (_ ^ n), _root_.pow_succ], exact mul_le_mul_of_nonneg_right (le_of_lt hx1) (pow_nonneg (abv_nonneg _ _) _) } end lemma is_cau_geo_series_const (a : α) {x : α} (hx1 : abs x < 1) : is_cau_seq abs (λ m, (range m).sum (λ n, a * x ^ n)) := have is_cau_seq abs (λ m, a * (range m).sum (λ n, x ^ n)) := (cau_seq.const abs a * ⟨_, is_cau_geo_series x hx1⟩).2, by simpa only [mul_sum] lemma series_ratio_test {f : ℕ → β} (n : ℕ) (r : α) (hr0 : 0 ≤ r) (hr1 : r < 1) (h : ∀ m, n ≤ m → abv (f m.succ) ≤ r * abv (f m)) : is_cau_seq abv (λ m, (range m).sum f) := have har1 : abs r < 1, by rwa abs_of_nonneg hr0, begin refine is_cau_series_of_abv_le_cau n.succ _ (is_cau_geo_series_const (abv (f n.succ) * r⁻¹ ^ n.succ) har1), assume m hmn, cases classical.em (r = 0) with r_zero r_ne_zero, { have m_pos := lt_of_lt_of_le (nat.succ_pos n) hmn, have := h m.pred (nat.le_of_succ_le_succ (by rwa [nat.succ_pred_eq_of_pos m_pos])), simpa [r_zero, nat.succ_pred_eq_of_pos m_pos, pow_succ] }, generalize hk : m - n.succ = k, have r_pos : 0 < r := lt_of_le_of_ne hr0 (ne.symm r_ne_zero), replace hk : m = k + n.succ := (nat.sub_eq_iff_eq_add hmn).1 hk, induction k with k ih generalizing m n, { rw [hk, zero_add, mul_right_comm, ← pow_inv _ _ r_ne_zero, ← div_eq_mul_inv, mul_div_cancel], exact (ne_of_lt (pow_pos r_pos _)).symm }, { have kn : k + n.succ ≥ n.succ, by rw ← zero_add n.succ; exact add_le_add (zero_le _) (by simp), rw [hk, nat.succ_add, pow_succ' r, ← mul_assoc], exact le_trans (by rw mul_comm; exact h _ (nat.le_of_succ_le kn)) (mul_le_mul_of_nonneg_right (ih (k + n.succ) n h kn rfl) hr0) } end lemma sum_range_diag_flip {α : Type*} [add_comm_monoid α] (n : ℕ) (f : ℕ → ℕ → α) : (range n).sum (λ m, (range (m + 1)).sum (λ k, f k (m - k))) = (range n).sum (λ m, (range (n - m)).sum (f m)) := have h₁ : ((range n).sigma (range ∘ nat.succ)).sum (λ (a : Σ m, ℕ), f (a.2) (a.1 - a.2)) = (range n).sum (λ m, (range (m + 1)).sum (λ k, f k (m - k))) := sum_sigma, have h₂ : ((range n).sigma (λ m, range (n - m))).sum (λ a : Σ (m : ℕ), ℕ, f (a.1) (a.2)) = (range n).sum (λ m, sum (range (n - m)) (f m)) := sum_sigma, h₁ ▸ h₂ ▸ sum_bij (λ a _, ⟨a.2, a.1 - a.2⟩) (λ a ha, have h₁ : a.1 < n := mem_range.1 (mem_sigma.1 ha).1, have h₂ : a.2 < nat.succ a.1 := mem_range.1 (mem_sigma.1 ha).2, mem_sigma.2 ⟨mem_range.2 (lt_of_lt_of_le h₂ h₁), mem_range.2 ((nat.sub_lt_sub_right_iff (nat.le_of_lt_succ h₂)).2 h₁)⟩) (λ _ _, rfl) (λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h, have ha : a₁ < n ∧ a₂ ≤ a₁ := ⟨mem_range.1 (mem_sigma.1 ha).1, nat.le_of_lt_succ (mem_range.1 (mem_sigma.1 ha).2)⟩, have hb : b₁ < n ∧ b₂ ≤ b₁ := ⟨mem_range.1 (mem_sigma.1 hb).1, nat.le_of_lt_succ (mem_range.1 (mem_sigma.1 hb).2)⟩, have h : a₂ = b₂ ∧ _ := sigma.mk.inj h, have h' : a₁ = b₁ - b₂ + a₂ := (nat.sub_eq_iff_eq_add ha.2).1 (eq_of_heq h.2), sigma.mk.inj_iff.2 ⟨nat.sub_add_cancel hb.2 ▸ h'.symm ▸ h.1 ▸ rfl, (heq_of_eq h.1)⟩) (λ ⟨a₁, a₂⟩ ha, have ha : a₁ < n ∧ a₂ < n - a₁ := ⟨mem_range.1 (mem_sigma.1 ha).1, (mem_range.1 (mem_sigma.1 ha).2)⟩, ⟨⟨a₂ + a₁, a₁⟩, ⟨mem_sigma.2 ⟨mem_range.2 (nat.lt_sub_right_iff_add_lt.1 ha.2), mem_range.2 (nat.lt_succ_of_le (nat.le_add_left _ _))⟩, sigma.mk.inj_iff.2 ⟨rfl, heq_of_eq (nat.add_sub_cancel _ _).symm⟩⟩⟩) lemma abv_sum_le_sum_abv {γ : Type*} (f : γ → β) (s : finset γ) : abv (s.sum f) ≤ s.sum (abv ∘ f) := by haveI := classical.dec_eq γ; exact finset.induction_on s (by simp [abv_zero abv]) (λ a s has ih, by rw [sum_insert has, sum_insert has]; exact le_trans (abv_add abv _ _) (add_le_add_left ih _)) lemma sum_range_sub_sum_range {α : Type*} [add_comm_group α] {f : ℕ → α} {n m : ℕ} (hnm : n ≤ m) : (range m).sum f - (range n).sum f = ((range m).filter (λ k, n ≤ k)).sum f := begin rw [← sum_sdiff (@filter_subset _ (λ k, n ≤ k) _ (range m)), sub_eq_iff_eq_add, ← eq_sub_iff_add_eq, add_sub_cancel'], refine finset.sum_congr (finset.ext.2 $ λ a, ⟨λ h, by simp at *; finish, λ h, have ham : a < m := lt_of_lt_of_le (mem_range.1 h) hnm, by simp * at *⟩) (λ _ _, rfl), end lemma cauchy_product {a b : ℕ → β} (ha : is_cau_seq abs (λ m, (range m).sum (λ n, abv (a n)))) (hb : is_cau_seq abv (λ m, (range m).sum b)) (ε : α) (ε0 : 0 < ε) : ∃ i : ℕ, ∀ j ≥ i, abv ((range j).sum a * (range j).sum b - (range j).sum (λ n, (range (n + 1)).sum (λ m, a m * b (n - m)))) < ε := let ⟨Q, hQ⟩ := cau_seq.bounded ⟨_, hb⟩ in let ⟨P, hP⟩ := cau_seq.bounded ⟨_, ha⟩ in have hP0 : 0 < P, from lt_of_le_of_lt (abs_nonneg _) (hP 0), have hPε0 : 0 < ε / (2 * P), from div_pos ε0 (mul_pos (show (2 : α) > 0, from by norm_num) hP0), let ⟨N, hN⟩ := cau_seq.cauchy₂ ⟨_, hb⟩ hPε0 in have hQε0 : 0 < ε / (4 * Q), from div_pos ε0 (mul_pos (show (0 : α) < 4, by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))), let ⟨M, hM⟩ := cau_seq.cauchy₂ ⟨_, ha⟩ hQε0 in ⟨2 * (max N M + 1), λ K hK, have h₁ : sum (range K) (λ m, (range (m + 1)).sum (λ k, a k * b (m - k))) = sum (range K) (λ m, sum (range (K - m)) (λ n, a m * b n)), by simpa using sum_range_diag_flip K (λ m n, a m * b n), have h₂ : (λ i, (range (K - i)).sum (λ k, a i * b k)) = (λ i, a i * (range (K - i)).sum b), by simp [finset.mul_sum], have h₃ : (range K).sum (λ i, a i * (range (K - i)).sum b) = (range K).sum (λ i, a i * ((range (K - i)).sum b - (range K).sum b)) + (range K).sum (λ i, a i * (range K).sum b), by rw ← sum_add_distrib; simp [(mul_add _ _ _).symm], have two_mul_two : (4 : α) = 2 * 2, by norm_num, have hQ0 : Q ≠ 0, from λ h, by simpa [h, lt_irrefl] using hQε0, have h2Q0 : 2 * Q ≠ 0, from mul_ne_zero two_ne_zero hQ0, have hε : ε / (2 * P) * P + ε / (4 * Q) * (2 * Q) = ε, by rw [← div_div_eq_div_mul, div_mul_cancel _ (ne.symm (ne_of_lt hP0)), two_mul_two, mul_assoc, ← div_div_eq_div_mul, div_mul_cancel _ h2Q0, add_halves], have hNMK : max N M + 1 < K, from lt_of_lt_of_le (by rw two_mul; exact lt_add_of_pos_left _ (nat.succ_pos _)) hK, have hKN : N < K, from calc N ≤ max N M : le_max_left _ _ ... < max N M + 1 : nat.lt_succ_self _ ... < K : hNMK, have hsumlesum : (range (max N M + 1)).sum (λ i, abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) ≤ (range (max N M + 1)).sum (λ i, abv (a i) * (ε / (2 * P))), from sum_le_sum (λ m hmJ, mul_le_mul_of_nonneg_left (le_of_lt (hN (K - m) K (nat.le_sub_left_of_add_le (le_trans (by rw two_mul; exact add_le_add (le_of_lt (mem_range.1 hmJ)) (le_trans (le_max_left _ _) (le_of_lt (lt_add_one _)))) hK)) (le_of_lt hKN))) (abv_nonneg abv _)), have hsumltP : sum (range (max N M + 1)) (λ n, abv (a n)) < P := calc sum (range (max N M + 1)) (λ n, abv (a n)) = abs (sum (range (max N M + 1)) (λ n, abv (a n))) : eq.symm (abs_of_nonneg (sum_nonneg (λ x h, abv_nonneg abv (a x)))) ... < P : hP (max N M + 1), begin rw [h₁, h₂, h₃, sum_mul, ← sub_sub, sub_right_comm, sub_self, zero_sub, abv_neg abv], refine lt_of_le_of_lt (abv_sum_le_sum_abv _ _) _, suffices : (range (max N M + 1)).sum (λ (i : ℕ), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) + ((range K).sum (λ (i : ℕ), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) -(range (max N M + 1)).sum (λ (i : ℕ), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b))) < ε / (2 * P) * P + ε / (4 * Q) * (2 * Q), { rw hε at this, simpa [abv_mul abv] }, refine add_lt_add (lt_of_le_of_lt hsumlesum (by rw [← sum_mul, mul_comm]; exact (mul_lt_mul_left hPε0).mpr hsumltP)) _, rw sum_range_sub_sum_range (le_of_lt hNMK), exact calc sum ((range K).filter (λ k, max N M + 1 ≤ k)) (λ i, abv (a i) * abv (sum (range (K - i)) b - sum (range K) b)) ≤ sum ((range K).filter (λ k, max N M + 1 ≤ k)) (λ i, abv (a i) * (2 * Q)) : sum_le_sum (λ n hn, begin refine mul_le_mul_of_nonneg_left _ (abv_nonneg _ _), rw sub_eq_add_neg, refine le_trans (abv_add _ _ _) _, rw [two_mul, abv_neg abv], exact add_le_add (le_of_lt (hQ _)) (le_of_lt (hQ _)), end) ... < ε / (4 * Q) * (2 * Q) : by rw [← sum_mul, ← sum_range_sub_sum_range (le_of_lt hNMK)]; refine (mul_lt_mul_right $ by rw two_mul; exact add_pos (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0)) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))).2 (lt_of_le_of_lt (le_abs_self _) (hM _ _ (le_trans (nat.le_succ_of_le (le_max_right _ _)) (le_of_lt hNMK)) (nat.le_succ_of_le (le_max_right _ _)))) end⟩ end open finset open cau_seq namespace complex lemma is_cau_abs_exp (z : ℂ) : is_cau_seq _root_.abs (λ n, (range n).sum (λ m, abs (z ^ m / nat.fact m))) := let ⟨n, hn⟩ := exists_nat_gt (abs z) in have hn0 : (0 : ℝ) < n, from lt_of_le_of_lt (abs_nonneg _) hn, series_ratio_test n (complex.abs z / n) (div_nonneg_of_nonneg_of_pos (complex.abs_nonneg _) hn0) (by rwa [div_lt_iff hn0, one_mul]) (λ m hm, by rw [abs_abs, abs_abs, nat.fact_succ, pow_succ, mul_comm m.succ, nat.cast_mul, ← div_div_eq_div_mul, mul_div_assoc, mul_div_right_comm, abs_mul, abs_div, abs_cast_nat]; exact mul_le_mul_of_nonneg_right (div_le_div_of_le_left (abs_nonneg _) hn0 (nat.cast_le.2 (le_trans hm (nat.le_succ _)))) (abs_nonneg _)) noncomputable theory lemma is_cau_exp (z : ℂ) : is_cau_seq abs (λ n, (range n).sum (λ m, z ^ m / nat.fact m)) := is_cau_series_of_abv_cau (is_cau_abs_exp z) def exp' (z : ℂ) : cau_seq ℂ complex.abs := ⟨λ n, (range n).sum (λ m, z ^ m / nat.fact m), is_cau_exp z⟩ def exp (z : ℂ) : ℂ := lim (exp' z) def sin (z : ℂ) : ℂ := ((exp (-z * I) - exp (z * I)) * I) / 2 def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 def tan (z : ℂ) : ℂ := sin z / cos z def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 def tanh (z : ℂ) : ℂ := sinh z / cosh z end complex namespace real open complex def exp (x : ℝ) : ℝ := (exp x).re def sin (x : ℝ) : ℝ := (sin x).re def cos (x : ℝ) : ℝ := (cos x).re def tan (x : ℝ) : ℝ := (tan x).re def sinh (x : ℝ) : ℝ := (sinh x).re def cosh (x : ℝ) : ℝ := (cosh x).re def tanh (x : ℝ) : ℝ := (tanh x).re end real namespace complex variables (x y : ℂ) @[simp] lemma exp_zero : exp 0 = 1 := lim_eq_of_equiv_const $ λ ε ε0, ⟨1, λ j hj, begin convert ε0, cases j, { exact absurd hj (not_le_of_gt zero_lt_one) }, { dsimp [exp'], induction j with j ih, { dsimp [exp']; simp }, { rw ← ih dec_trivial, simp only [sum_range_succ, pow_succ], simp } } end⟩ lemma exp_add : exp (x + y) = exp x * exp y := show lim (⟨_, is_cau_exp (x + y)⟩ : cau_seq ℂ abs) = lim (show cau_seq ℂ abs, from ⟨_, is_cau_exp x⟩) * lim (show cau_seq ℂ abs, from ⟨_, is_cau_exp y⟩), from have hj : ∀ j : ℕ, (range j).sum (λ m, (x + y) ^ m / m.fact) = (range j).sum (λ i, (range (i + 1)).sum (λ k, x ^ k / k.fact * (y ^ (i - k) / (i - k).fact))), from assume j, finset.sum_congr rfl (λ m hm, begin rw [add_pow, div_eq_mul_inv, sum_mul], refine finset.sum_congr rfl (λ i hi, _), have h₁ : (nat.choose m i : ℂ) ≠ 0 := nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 (nat.choose_pos (nat.le_of_lt_succ (mem_range.1 hi)))), have h₂ := nat.choose_mul_fact_mul_fact (nat.le_of_lt_succ $ finset.mem_range.1 hi), rw [← h₂, nat.cast_mul, nat.cast_mul, mul_inv', mul_inv'], simp only [mul_left_comm (nat.choose m i : ℂ), mul_assoc, mul_left_comm (nat.choose m i : ℂ)⁻¹, mul_comm (nat.choose m i : ℂ)], rw inv_mul_cancel h₁, simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] end), by rw lim_mul_lim; exact eq.symm (lim_eq_lim_of_equiv (by dsimp; simp only [hj]; exact cauchy_product (is_cau_abs_exp x) (is_cau_exp y))) attribute [irreducible] complex.exp lemma exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp(n*x) = (exp x)^n | 0 := by rw [nat.cast_zero, zero_mul, exp_zero, pow_zero] | (nat.succ n) := by rw [pow_succ', nat.cast_add_one, add_mul, exp_add, ←exp_nat_mul, one_mul] lemma exp_ne_zero : exp x ≠ 0 := λ h, @zero_ne_one ℂ _ $ by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp lemma exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← domain.mul_left_inj (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] lemma exp_sub : exp (x - y) = exp x / exp y := by simp [exp_add, exp_neg, div_eq_mul_inv] @[simp] lemma exp_conj : exp (conj x) = conj (exp x) := begin dsimp [exp], rw [← lim_conj], refine congr_arg lim (cau_seq.ext (λ _, _)), dsimp [exp', function.comp, cau_seq_conj], rw ← sum_hom conj, refine sum_congr rfl (λ n hn, _), rw [conj_div, conj_pow, ← of_real_nat_cast, conj_of_real] end @[simp] lemma of_real_exp_of_real_re (x : ℝ) : ((exp x).re : ℂ) = exp x := eq_conj_iff_re.1 $ by rw [← exp_conj, conj_of_real] @[simp] lemma of_real_exp (x : ℝ) : (real.exp x : ℂ) = exp x := of_real_exp_of_real_re _ @[simp] lemma exp_of_real_im (x : ℝ) : (exp x).im = 0 := by rw [← of_real_exp_of_real_re, of_real_im] lemma exp_of_real_re (x : ℝ) : (exp x).re = real.exp x := rfl lemma two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel' _ two_ne_zero' lemma two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel' _ two_ne_zero' @[simp] lemma sinh_zero : sinh 0 = 0 := by simp [sinh] @[simp] lemma sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] private lemma sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring lemma sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := begin rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh], exact sinh_add_aux end @[simp] lemma cosh_zero : cosh 0 = 1 := by simp [cosh] @[simp] lemma cosh_neg : cosh (-x) = cosh x := by simp [cosh, exp_neg] private lemma cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring lemma cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := begin rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh], exact cosh_add_aux end lemma sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sinh_add, sinh_neg, cosh_neg] lemma cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [cosh_add, sinh_neg, cosh_neg] lemma sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← conj_neg, exp_conj, exp_conj, ← conj_sub, sinh, conj_div, conj_two] @[simp] lemma of_real_sinh_of_real_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := eq_conj_iff_re.1 $ by rw [← sinh_conj, conj_of_real] @[simp] lemma of_real_sinh (x : ℝ) : (real.sinh x : ℂ) = sinh x := of_real_sinh_of_real_re _ @[simp] lemma sinh_of_real_im (x : ℝ) : (sinh x).im = 0 := by rw [← of_real_sinh_of_real_re, of_real_im] lemma sinh_of_real_re (x : ℝ) : (sinh x).re = real.sinh x := rfl lemma cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← conj_neg, exp_conj, exp_conj, ← conj_add, cosh, conj_div, conj_two] @[simp] lemma of_real_cosh_of_real_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := eq_conj_iff_re.1 $ by rw [← cosh_conj, conj_of_real] @[simp] lemma of_real_cosh (x : ℝ) : (real.cosh x : ℂ) = cosh x := of_real_cosh_of_real_re _ @[simp] lemma cosh_of_real_im (x : ℝ) : (cosh x).im = 0 := by rw [← of_real_cosh_of_real_re, of_real_im] lemma cosh_of_real_re (x : ℝ) : (cosh x).re = real.cosh x := rfl lemma tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl @[simp] lemma tanh_zero : tanh 0 = 0 := by simp [tanh] @[simp] lemma tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] lemma tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← conj_div, tanh] @[simp] lemma of_real_tanh_of_real_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := eq_conj_iff_re.1 $ by rw [← tanh_conj, conj_of_real] @[simp] lemma of_real_tanh (x : ℝ) : (real.tanh x : ℂ) = tanh x := of_real_tanh_of_real_re _ @[simp] lemma tanh_of_real_im (x : ℝ) : (tanh x).im = 0 := by rw [← of_real_tanh_of_real_re, of_real_im] lemma tanh_of_real_re (x : ℝ) : (tanh x).re = real.tanh x := rfl lemma cosh_add_sinh : cosh x + sinh x = exp x := by rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] lemma sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] lemma cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] lemma cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] @[simp] lemma sin_zero : sin 0 = 0 := by simp [sin] @[simp] lemma sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] lemma two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel' _ two_ne_zero' lemma two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel' _ two_ne_zero' lemma sinh_mul_I : sinh (x * I) = sin x * I := by rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] lemma cosh_mul_I : cosh (x * I) = cos x := by rw [← domain.mul_left_inj (@two_ne_zero' ℂ _ _ _), two_cosh, two_cos, neg_mul_eq_neg_mul] lemma sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← domain.mul_right_inj I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] @[simp] lemma cos_zero : cos 0 = 1 := by simp [cos] @[simp] lemma cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] private lemma cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * (-1) = 2 * (a * c + b * d) := by ring lemma cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] lemma sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sin_add, sin_neg, cos_neg] lemma cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [cos_add, sin_neg, cos_neg] lemma sin_conj : sin (conj x) = conj (sin x) := by rw [← domain.mul_right_inj I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← conj_mul, ← conj_mul, sinh_conj, mul_neg_eq_neg_mul_symm, sinh_neg, sinh_mul_I, mul_neg_eq_neg_mul_symm] @[simp] lemma of_real_sin_of_real_re (x : ℝ) : ((sin x).re : ℂ) = sin x := eq_conj_iff_re.1 $ by rw [← sin_conj, conj_of_real] @[simp] lemma of_real_sin (x : ℝ) : (real.sin x : ℂ) = sin x := of_real_sin_of_real_re _ @[simp] lemma sin_of_real_im (x : ℝ) : (sin x).im = 0 := by rw [← of_real_sin_of_real_re, of_real_im] lemma sin_of_real_re (x : ℝ) : (sin x).re = real.sin x := rfl lemma cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← conj_mul, ← cosh_mul_I, cosh_conj, mul_neg_eq_neg_mul_symm, cosh_neg] @[simp] lemma of_real_cos_of_real_re (x : ℝ) : ((cos x).re : ℂ) = cos x := eq_conj_iff_re.1 $ by rw [← cos_conj, conj_of_real] @[simp] lemma of_real_cos (x : ℝ) : (real.cos x : ℂ) = cos x := of_real_cos_of_real_re _ @[simp] lemma cos_of_real_im (x : ℝ) : (cos x).im = 0 := by rw [← of_real_cos_of_real_re, of_real_im] lemma cos_of_real_re (x : ℝ) : (cos x).re = real.cos x := rfl @[simp] lemma tan_zero : tan 0 = 0 := by simp [tan] lemma tan_eq_sin_div_cos : tan x = sin x / cos x := rfl @[simp] lemma tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] lemma tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← conj_div, tan] @[simp] lemma of_real_tan_of_real_re (x : ℝ) : ((tan x).re : ℂ) = tan x := eq_conj_iff_re.1 $ by rw [← tan_conj, conj_of_real] @[simp] lemma of_real_tan (x : ℝ) : (real.tan x : ℂ) = tan x := of_real_tan_of_real_re _ @[simp] lemma tan_of_real_im (x : ℝ) : (tan x).im = 0 := by rw [← of_real_tan_of_real_re, of_real_im] lemma tan_of_real_re (x : ℝ) : (tan x).re = real.tan x := rfl lemma cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] lemma cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [← neg_mul_eq_neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] lemma sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) lemma cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← pow_two, ← pow_two] lemma cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] lemma sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] lemma cos_square : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left, two_ne_zero', -one_div_eq_inv] lemma sin_square : sin x ^ 2 = 1 - cos x ^ 2 := by { rw [←sin_sq_add_cos_sq x], simp } lemma exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm lemma exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] lemma exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := begin rw [← exp_mul_I, ← exp_mul_I], induction n with n ih, { rw [pow_zero, nat.cast_zero, zero_mul, zero_mul, exp_zero] }, { rw [pow_succ', ih, nat.cast_succ, add_mul, add_mul, one_mul, exp_add] } end end complex namespace real open complex variables (x y : ℝ) @[simp] lemma exp_zero : exp 0 = 1 := by simp [real.exp] lemma exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] lemma exp_nat_mul (x : ℝ) : ∀ n : ℕ, exp(n*x) = (exp x)^n | 0 := by rw [nat.cast_zero, zero_mul, exp_zero, pow_zero] | (nat.succ n) := by rw [pow_succ', nat.cast_add_one, add_mul, exp_add, ←exp_nat_mul, one_mul] lemma exp_ne_zero : exp x ≠ 0 := λ h, exp_ne_zero x $ by rw [exp, ← of_real_inj] at h; simp * at * lemma exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← of_real_inj, exp, of_real_exp_of_real_re, of_real_neg, exp_neg, of_real_inv, of_real_exp] lemma exp_sub : exp (x - y) = exp x / exp y := by simp [exp_add, exp_neg, div_eq_mul_inv] @[simp] lemma sin_zero : sin 0 = 0 := by simp [sin] @[simp] lemma sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] lemma sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← of_real_inj]; simp [sin, sin_add] @[simp] lemma cos_zero : cos 0 = 1 := by simp [cos] @[simp] lemma cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] lemma cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw ← of_real_inj; simp [cos, cos_add] lemma sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sin_add, sin_neg, cos_neg] lemma cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [cos_add, sin_neg, cos_neg] lemma tan_eq_sin_div_cos : tan x = sin x / cos x := if h : complex.cos x = 0 then by simp [sin, cos, tan, *, complex.tan, div_eq_mul_inv] at * else by rw [sin, cos, tan, complex.tan, ← of_real_inj, div_eq_mul_inv, mul_re]; simp [norm_sq, (div_div_eq_div_mul _ _ _).symm, div_self h]; refl @[simp] lemma tan_zero : tan 0 = 0 := by simp [tan] @[simp] lemma tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] lemma sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := of_real_inj.1 $ by simpa using sin_sq_add_cos_sq x lemma sin_sq_le_one : sin x ^ 2 ≤ 1 := by rw ← sin_sq_add_cos_sq x; exact le_add_of_nonneg_right' (pow_two_nonneg _) lemma cos_sq_le_one : cos x ^ 2 ≤ 1 := by rw ← sin_sq_add_cos_sq x; exact le_add_of_nonneg_left' (pow_two_nonneg _) lemma abs_sin_le_one : abs' (sin x) ≤ 1 := (mul_self_le_mul_self_iff (_root_.abs_nonneg (sin x)) (by exact zero_le_one)).2 $ by rw [← _root_.abs_mul, abs_mul_self, mul_one, ← pow_two]; apply sin_sq_le_one lemma abs_cos_le_one : abs' (cos x) ≤ 1 := (mul_self_le_mul_self_iff (_root_.abs_nonneg (cos x)) (by exact zero_le_one)).2 $ by rw [← _root_.abs_mul, abs_mul_self, mul_one, ← pow_two]; apply cos_sq_le_one lemma sin_le_one : sin x ≤ 1 := (abs_le.1 (abs_sin_le_one _)).2 lemma cos_le_one : cos x ≤ 1 := (abs_le.1 (abs_cos_le_one _)).2 lemma neg_one_le_sin : -1 ≤ sin x := (abs_le.1 (abs_sin_le_one _)).1 lemma neg_one_le_cos : -1 ≤ cos x := (abs_le.1 (abs_cos_le_one _)).1 lemma cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw ← of_real_inj; simp [cos_two_mul] lemma sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw ← of_real_inj; simp [sin_two_mul] lemma cos_square : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := of_real_inj.1 $ by simpa using cos_square x lemma sin_square : sin x ^ 2 = 1 - cos x ^ 2 := eq_sub_iff_add_eq.2 $ sin_sq_add_cos_sq _ @[simp] lemma sinh_zero : sinh 0 = 0 := by simp [sinh] @[simp] lemma sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] lemma sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw ← of_real_inj; simp [sinh_add] @[simp] lemma cosh_zero : cosh 0 = 1 := by simp [cosh] @[simp] lemma cosh_neg : cosh (-x) = cosh x := by simp [cosh, exp_neg] lemma cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw ← of_real_inj; simp [cosh, cosh_add] lemma sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sinh_add, sinh_neg, cosh_neg] lemma cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [cosh_add, sinh_neg, cosh_neg] lemma tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := of_real_inj.1 $ by simp [tanh_eq_sinh_div_cosh] @[simp] lemma tanh_zero : tanh 0 = 0 := by simp [tanh] @[simp] lemma tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] open is_absolute_value /- TODO make this private and prove ∀ x -/ lemma add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := calc x + 1 ≤ lim (⟨(λ n : ℕ, ((exp' x) n).re), is_cau_seq_re (exp' x)⟩ : cau_seq ℝ abs') : le_lim (cau_seq.le_of_exists ⟨2, λ j hj, show x + (1 : ℝ) ≤ ((range j).sum (λ m, (x ^ m / m.fact : ℂ))).re, from have h₁ : (((λ m : ℕ, (x ^ m / m.fact : ℂ)) ∘ nat.succ) 0).re = x, by simp, have h₂ : ((x : ℂ) ^ 0 / nat.fact 0).re = 1, by simp, begin rw [← nat.sub_add_cancel hj, sum_range_succ', sum_range_succ', add_re, add_re, h₁, h₂, add_assoc, ← @sum_hom _ _ _ _ _ _ _ complex.re (is_add_group_hom.to_is_add_monoid_hom _)], refine le_add_of_nonneg_of_le (sum_nonneg (λ m hm, _)) (le_refl _), dsimp [-nat.fact_succ], rw [← of_real_pow, ← of_real_nat_cast, ← of_real_div, of_real_re], exact div_nonneg (pow_nonneg hx _) (nat.cast_pos.2 (nat.fact_pos _)), end⟩) ... = exp x : by rw [exp, complex.exp, ← cau_seq_re, lim_re] lemma one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] lemma exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) (λ h, by rw [← neg_neg x, real.exp_neg]; exact inv_pos (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))) @[simp] lemma abs_exp (x : ℝ) : abs' (exp x) = exp x := abs_of_pos (exp_pos _) lemma exp_strict_mono : strict_mono exp := λ x y h, by rw [← sub_add_cancel y x, real.exp_add]; exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) lemma exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strict_mono.lt_iff_lt lemma exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strict_mono.le_iff_le lemma exp_injective : function.injective exp := exp_strict_mono.injective @[simp] lemma exp_eq_one_iff : exp x = 1 ↔ x = 0 := by rw [← exp_zero, exp_injective.eq_iff] lemma one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] lemma exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] end real namespace complex lemma sum_div_fact_le {α : Type*} [discrete_linear_ordered_field α] (n j : ℕ) (hn : 0 < n) : (sum (filter (λ k, n ≤ k) (range j)) (λ m : ℕ, (1 / m.fact : α))) ≤ n.succ * (n.fact * n)⁻¹ := calc (filter (λ k, n ≤ k) (range j)).sum (λ m : ℕ, (1 / m.fact : α)) = (range (j - n)).sum (λ m, 1 / (m + n).fact) : sum_bij (λ m _, m - n) (λ m hm, mem_range.2 $ (nat.sub_lt_sub_right_iff (by simp at hm; tauto)).2 (by simp at hm; tauto)) (λ m hm, by rw nat.sub_add_cancel; simp at *; tauto) (λ a₁ a₂ ha₁ ha₂ h, by rwa [nat.sub_eq_iff_eq_add, ← nat.sub_add_comm, eq_comm, nat.sub_eq_iff_eq_add, add_right_inj, eq_comm] at h; simp at *; tauto) (λ b hb, ⟨b + n, mem_filter.2 ⟨mem_range.2 $ nat.add_lt_of_lt_sub_right (mem_range.1 hb), nat.le_add_left _ _⟩, by rw nat.add_sub_cancel⟩) ... ≤ (range (j - n)).sum (λ m, (nat.fact n * n.succ ^ m)⁻¹) : begin refine sum_le_sum (assume m n, _), rw [one_div_eq_inv, inv_le_inv], { rw [← nat.cast_pow, ← nat.cast_mul, nat.cast_le, add_comm], exact nat.fact_mul_pow_le_fact }, { exact nat.cast_pos.2 (nat.fact_pos _) }, { exact mul_pos (nat.cast_pos.2 (nat.fact_pos _)) (pow_pos (nat.cast_pos.2 (nat.succ_pos _)) _) }, end ... = (nat.fact n)⁻¹ * (range (j - n)).sum (λ m, n.succ⁻¹ ^ m) : by simp [mul_inv', mul_sum.symm, sum_mul.symm, -nat.fact_succ, mul_comm, inv_pow'] ... = (n.succ - n.succ * n.succ⁻¹ ^ (j - n)) / (n.fact * n) : have h₁ : (n.succ : α) ≠ 1, from @nat.cast_one α _ _ ▸ mt nat.cast_inj.1 (mt nat.succ_inj (nat.pos_iff_ne_zero.1 hn)), have h₂ : (n.succ : α) ≠ 0, from nat.cast_ne_zero.2 (nat.succ_ne_zero _), have h₃ : (n.fact * n : α) ≠ 0, from mul_ne_zero (nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 (nat.fact_pos _))) (nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 hn)), have h₄ : (n.succ - 1 : α) = n, by simp, by rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq _ _ h₃, mul_comm _ (n.fact * n : α), ← mul_assoc (n.fact⁻¹ : α), ← mul_inv', h₄, ← mul_assoc (n.fact * n : α), mul_comm (n : α) n.fact, mul_inv_cancel h₃]; simp [mul_add, add_mul, mul_assoc, mul_comm] ... ≤ n.succ / (n.fact * n) : begin refine (div_le_div_right (mul_pos _ _)).2 _, exact nat.cast_pos.2 (nat.fact_pos _), exact nat.cast_pos.2 hn, exact sub_le_self _ (mul_nonneg (nat.cast_nonneg _) (pow_nonneg (inv_nonneg.2 (nat.cast_nonneg _)) _)) end lemma exp_bound {x : ℂ} (hx : abs x ≤ 1) {n : ℕ} (hn : 0 < n) : abs (exp x - (range n).sum (λ m, x ^ m / m.fact)) ≤ abs x ^ n * (n.succ * (n.fact * n)⁻¹) := begin rw [← lim_const ((range n).sum _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs], refine lim_le (cau_seq.le_of_exists ⟨n, λ j hj, _⟩), show abs ((range j).sum (λ m, x ^ m / m.fact) - (range n).sum (λ m, x ^ m / m.fact)) ≤ abs x ^ n * (n.succ * (n.fact * n)⁻¹), rw sum_range_sub_sum_range hj, exact calc abs (((range j).filter (λ k, n ≤ k)).sum (λ m : ℕ, (x ^ m / m.fact : ℂ))) = abs (((range j).filter (λ k, n ≤ k)).sum (λ m : ℕ, (x ^ n * (x ^ (m - n) / m.fact) : ℂ))) : congr_arg abs (sum_congr rfl (λ m hm, by rw [← mul_div_assoc, ← pow_add, nat.add_sub_cancel']; simp at hm; tauto)) ... ≤ sum (filter (λ k, n ≤ k) (range j)) (λ m, abs (x ^ n * (_ / m.fact))) : abv_sum_le_sum_abv _ _ ... ≤ sum (filter (λ k, n ≤ k) (range j)) (λ m, abs x ^ n * (1 / m.fact)) : begin refine sum_le_sum (λ m hm, _), rw [abs_mul, abv_pow abs, abs_div, abs_cast_nat], refine mul_le_mul_of_nonneg_left ((div_le_div_right _).2 _) _, exact nat.cast_pos.2 (nat.fact_pos _), rw abv_pow abs, exact (pow_le_one _ (abs_nonneg _) hx), exact pow_nonneg (abs_nonneg _) _ end ... = abs x ^ n * (((range j).filter (λ k, n ≤ k)).sum (λ m : ℕ, (1 / m.fact : ℝ))) : by simp [abs_mul, abv_pow abs, abs_div, mul_sum.symm] ... ≤ abs x ^ n * (n.succ * (n.fact * n)⁻¹) : mul_le_mul_of_nonneg_left (sum_div_fact_le _ _ hn) (pow_nonneg (abs_nonneg _) _) end lemma abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1) ≤ 2 * abs x := calc abs (exp x - 1) = abs (exp x - (range 1).sum (λ m, x ^ m / m.fact)) : by simp [sum_range_succ] ... ≤ abs x ^ 1 * ((nat.succ 1) * (nat.fact 1 * (1 : ℕ))⁻¹) : exp_bound hx dec_trivial ... = 2 * abs x : by simp [two_mul, mul_two, mul_add, mul_comm] end complex namespace real open complex finset lemma cos_bound {x : ℝ} (hx : abs' x ≤ 1) : abs' (cos x - (1 - x ^ 2 / 2)) ≤ abs' x ^ 4 * (5 / 96) := calc abs' (cos x - (1 - x ^ 2 / 2)) = abs (complex.cos x - (1 - x ^ 2 / 2)) : by rw ← abs_of_real; simp [of_real_bit0, of_real_one, of_real_inv] ... = abs ((complex.exp (x * I) + complex.exp (-x * I) - (2 - x ^ 2)) / 2) : by simp [complex.cos, sub_div, add_div, neg_div, div_self (@two_ne_zero' ℂ _ _ _)] ... = abs (((complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact)) + ((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact)))) / 2) : congr_arg abs (congr_arg (λ x : ℂ, x / 2) begin simp only [sum_range_succ], simp [pow_succ], apply complex.ext; simp [div_eq_mul_inv, norm_sq]; ring end) ... ≤ abs ((complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact)) / 2) + abs ((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact)) / 2) : by rw add_div; exact abs_add _ _ ... = (abs ((complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact))) / 2 + abs ((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact))) / 2) : by simp [complex.abs_div] ... ≤ ((complex.abs (x * I) ^ 4 * (nat.succ 4 * (nat.fact 4 * (4 : ℕ))⁻¹)) / 2 + (complex.abs (-x * I) ^ 4 * (nat.succ 4 * (nat.fact 4 * (4 : ℕ))⁻¹)) / 2) : add_le_add ((div_le_div_right (by norm_num)).2 (exp_bound (by simpa) dec_trivial)) ((div_le_div_right (by norm_num)).2 (exp_bound (by simpa) dec_trivial)) ... ≤ abs' x ^ 4 * (5 / 96) : by norm_num; simp [mul_assoc, mul_comm, mul_left_comm, mul_div_assoc] lemma sin_bound {x : ℝ} (hx : abs' x ≤ 1) : abs' (sin x - (x - x ^ 3 / 6)) ≤ abs' x ^ 4 * (5 / 96) := calc abs' (sin x - (x - x ^ 3 / 6)) = abs (complex.sin x - (x - x ^ 3 / 6)) : by rw ← abs_of_real; simp [of_real_bit0, of_real_one, of_real_inv] ... = abs (((complex.exp (-x * I) - complex.exp (x * I)) * I - (2 * x - x ^ 3 / 3)) / 2) : by simp [complex.sin, sub_div, add_div, neg_div, mul_div_cancel_left _ (@two_ne_zero' ℂ _ _ _), div_div_eq_div_mul, show (3 : ℂ) * 2 = 6, by norm_num] ... = abs ((((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact)) - (complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact))) * I) / 2) : congr_arg abs (congr_arg (λ x : ℂ, x / 2) begin simp only [sum_range_succ], simp [pow_succ], apply complex.ext; simp [div_eq_mul_inv, norm_sq]; ring end) ... ≤ abs ((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact)) * I / 2) + abs (-((complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact)) * I) / 2) : by rw [sub_mul, sub_eq_add_neg, add_div]; exact abs_add _ _ ... = (abs ((complex.exp (x * I) - (range 4).sum (λ m, (x * I) ^ m / m.fact))) / 2 + abs ((complex.exp (-x * I) - (range 4).sum (λ m, (-x * I) ^ m / m.fact))) / 2) : by simp [complex.abs_div, complex.abs_mul] ... ≤ ((complex.abs (x * I) ^ 4 * (nat.succ 4 * (nat.fact 4 * (4 : ℕ))⁻¹)) / 2 + (complex.abs (-x * I) ^ 4 * (nat.succ 4 * (nat.fact 4 * (4 : ℕ))⁻¹)) / 2) : add_le_add ((div_le_div_right (by norm_num)).2 (exp_bound (by simpa) dec_trivial)) ((div_le_div_right (by norm_num)).2 (exp_bound (by simpa) dec_trivial)) ... ≤ abs' x ^ 4 * (5 / 96) : by norm_num; simp [mul_assoc, mul_comm, mul_left_comm, mul_div_assoc] lemma cos_pos_of_le_one {x : ℝ} (hx : abs' x ≤ 1) : 0 < cos x := calc 0 < (1 - x ^ 2 / 2) - abs' x ^ 4 * (5 / 96) : sub_pos.2 $ lt_sub_iff_add_lt.2 (calc abs' x ^ 4 * (5 / 96) + x ^ 2 / 2 ≤ 1 * (5 / 96) + 1 / 2 : add_le_add (mul_le_mul_of_nonneg_right (pow_le_one _ (abs_nonneg _) hx) (by norm_num)) ((div_le_div_right (by norm_num)).2 (by rw [pow_two, ← abs_mul_self, _root_.abs_mul]; exact mul_le_one hx (abs_nonneg _) hx)) ... < 1 : by norm_num) ... ≤ cos x : sub_le.1 (abs_sub_le_iff.1 (cos_bound hx)).2 lemma sin_pos_of_pos_of_le_one {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 1) : 0 < sin x := calc 0 < x - x ^ 3 / 6 - abs' x ^ 4 * (5 / 96) : sub_pos.2 $ lt_sub_iff_add_lt.2 (calc abs' x ^ 4 * (5 / 96) + x ^ 3 / 6 ≤ x * (5 / 96) + x / 6 : add_le_add (mul_le_mul_of_nonneg_right (calc abs' x ^ 4 ≤ abs' x ^ 1 : pow_le_pow_of_le_one (abs_nonneg _) (by rwa _root_.abs_of_nonneg (le_of_lt hx0)) dec_trivial ... = x : by simp [_root_.abs_of_nonneg (le_of_lt (hx0))]) (by norm_num)) ((div_le_div_right (by norm_num)).2 (calc x ^ 3 ≤ x ^ 1 : pow_le_pow_of_le_one (le_of_lt hx0) hx dec_trivial ... = x : pow_one _)) ... < x : by linarith) ... ≤ sin x : sub_le.1 (abs_sub_le_iff.1 (sin_bound (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]))).2 lemma sin_pos_of_pos_of_le_two {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 2) : 0 < sin x := have x / 2 ≤ 1, from div_le_of_le_mul (by norm_num) (by simpa), calc 0 < 2 * sin (x / 2) * cos (x / 2) : mul_pos (mul_pos (by norm_num) (sin_pos_of_pos_of_le_one (half_pos hx0) this)) (cos_pos_of_le_one (by rwa [_root_.abs_of_nonneg (le_of_lt (half_pos hx0))])) ... = sin x : by rw [← sin_two_mul, two_mul, add_halves] lemma cos_one_le : cos 1 ≤ 2 / 3 := calc cos 1 ≤ abs' (1 : ℝ) ^ 4 * (5 / 96) + (1 - 1 ^ 2 / 2) : sub_le_iff_le_add.1 (abs_sub_le_iff.1 (cos_bound (by simp))).1 ... ≤ 2 / 3 : by norm_num lemma cos_one_pos : 0 < cos 1 := cos_pos_of_le_one (by simp) lemma cos_two_neg : cos 2 < 0 := calc cos 2 = cos (2 * 1) : congr_arg cos (mul_one _).symm ... = _ : real.cos_two_mul 1 ... ≤ 2 * (2 / 3) ^ 2 - 1 : sub_le_sub_right (mul_le_mul_of_nonneg_left (by rw [pow_two, pow_two]; exact mul_self_le_mul_self (le_of_lt cos_one_pos) cos_one_le) (by norm_num)) _ ... < 0 : by norm_num end real namespace complex lemma abs_cos_add_sin_mul_I (x : ℝ) : abs (cos x + sin x * I) = 1 := have _ := real.sin_sq_add_cos_sq x, by simp [abs, norm_sq, pow_two, *, sin_of_real_re, cos_of_real_re, mul_re] at * lemma abs_exp_eq_iff_re_eq {x y : ℂ} : abs (exp x) = abs (exp y) ↔ x.re = y.re := by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y, abs_mul, abs_mul, abs_cos_add_sin_mul_I, abs_cos_add_sin_mul_I, ← of_real_exp, ← of_real_exp, abs_of_nonneg (le_of_lt (real.exp_pos _)), abs_of_nonneg (le_of_lt (real.exp_pos _)), mul_one, mul_one]; exact ⟨λ h, real.exp_injective h, congr_arg _⟩ @[simp] lemma abs_exp_of_real (x : ℝ) : abs (exp x) = real.exp x := by rw [← of_real_exp]; exact abs_of_nonneg (le_of_lt (real.exp_pos _)) end complex
db6d71962f85db5e0b9b0c9c3abdb55dba742778
9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e
/src/undergraduate/MAS114/Semester 1/Q07.lean
fe75b66273338b7ad8d01745b78ab0b43d7958cf
[]
no_license
agusakov/lean_lib
c0e9cc29fc7d2518004e224376adeb5e69b5cc1a
f88d162da2f990b87c4d34f5f46bbca2bbc5948e
refs/heads/master
1,642,141,461,087
1,557,395,798,000
1,557,395,798,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
470
lean
import data.set namespace MAS114 namespace exercises_1 namespace Q07 local attribute [instance] classical.prop_decidable lemma L1 (U : Type) (A B : set U) : - (A ∪ B) = (- A) ∩ (- B) := by { simp } lemma L2 (U : Type) (A B : set U) : - (A ∩ B) = (- A) ∪ (- B) := begin ext x, rw[set.mem_union,set.mem_compl_iff,set.mem_compl_iff,set.mem_compl_iff], by_cases hA : (x ∈ A); by_cases hB : (x ∈ B); simp[hA,hB], end end Q07 end exercises_1 end MAS114
f2f7677fc3a864a9be87b60b7e96715d12972619
510e96af568b060ed5858226ad954c258549f143
/data/list/set.lean
bed68793b74b25039257d71998b2f8565dddc8c9
[]
no_license
Shamrock-Frost/library_dev
cb6d1739237d81e17720118f72ba0a6db8a5906b
0245c71e4931d3aceeacf0aea776454f6ee03c9c
refs/heads/master
1,609,481,034,595
1,500,165,215,000
1,500,165,347,000
97,350,162
0
0
null
1,500,164,969,000
1,500,164,969,000
null
UTF-8
Lean
false
false
31,879
lean
/- Copyright (c) 2015 Leonardo de Moura. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad Set-like operations on lists. -/ import data.list.basic data.list.comb .basic .comb open nat function decidable universe variables uu vv variables {α : Type uu} {β : Type vv} namespace list section insert variable [decidable_eq α] @[simp] theorem insert_nil (a : α) : insert a nil = [a] := rfl theorem insert.def (a : α) (l : list α) : insert a l = if a ∈ l then l else concat l a := rfl @[simp] theorem insert_of_mem {a : α} {l : list α} (h : a ∈ l) : insert a l = l := by rw [insert.def, if_pos h] @[simp] theorem insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) : insert a l = concat l a := by rw [insert.def, if_neg h] @[simp] theorem mem_insert_self (a : α) (l : list α) : a ∈ insert a l := if h : a ∈ l then by simp [h] else by simp [h] @[simp] theorem mem_insert_of_mem {a b : α} {l : list α} (h : a ∈ l) : a ∈ insert b l := if h' : b ∈ l then by simp [h, h'] else by simp [h, h'] theorem eq_or_mem_of_mem_insert {a b : α} {l : list α} (h : a ∈ insert b l) : a = b ∨ a ∈ l := if h' : b ∈ l then begin simp [h'] at h, simp [h] end else begin simp [h'] at h, assumption end @[simp] theorem mem_insert_iff (a b : α) (l : list α) : a ∈ insert b l ↔ a = b ∨ a ∈ l := iff.intro eq_or_mem_of_mem_insert (λ h, or.elim h (begin intro h', simp [h'] end) mem_insert_of_mem) @[simp] theorem length_insert_of_mem {a : α} [decidable_eq α] {l : list α} (h : a ∈ l) : length (insert a l) = length l := by simp [h] @[simp] theorem length_insert_of_not_mem {a : α} [decidable_eq α] {l : list α} (h : a ∉ l) : length (insert a l) = length l + 1 := by simp [h] theorem forall_mem_insert_of_forall_mem {p : α → Prop} {a : α} {l : list α} (h₁ : p a) (h₂ : ∀ x ∈ l, p x) : ∀ x ∈ insert a l, p x := if h : a ∈ l then begin simp [h], exact h₂ end else begin simp [h], intros b hb, cases hb with h₃ h₃, {rw h₃, assumption}, exact h₂ _ h₃ end end insert section erase variable [decidable_eq α] @[simp] lemma erase_nil (a : α) : [].erase a = [] := rfl lemma erase_cons (a b : α) (l : list α) : (b :: l).erase a = if b = a then l else b :: l.erase a := rfl @[simp] lemma erase_cons_head (a : α) (l : list α) : (a :: l).erase a = l := by simp [erase_cons, if_pos] @[simp] lemma erase_cons_tail {a b : α} (l : list α) (h : b ≠ a) : (b::l).erase a = b :: l.erase a := by simp [erase_cons, if_neg, h] @[simp] lemma length_erase_of_mem {a : α} : ∀{l:list α}, a ∈ l → length (l.erase a) = pred (length l) | [] h := rfl | [x] h := begin simp at h, simp [h] end | (x::y::xs) h := if h' : x = a then by simp [h', one_add] else have ainyxs : a ∈ y::xs, from or_resolve_right h $ by cc, by simp [h', length_erase_of_mem ainyxs, one_add] @[simp] lemma erase_of_not_mem {a : α} : ∀{l : list α}, a ∉ l → l.erase a = l | [] h := rfl | (x::xs) h := have anex : x ≠ a, from λ aeqx : x = a, absurd (or.inl aeqx.symm) h, have aninxs : a ∉ xs, from λ ainxs : a ∈ xs, absurd (or.inr ainxs) h, by simp [anex, erase_of_not_mem aninxs] lemma erase_append_left {a : α} : ∀ {l₁:list α} (l₂), a ∈ l₁ → (l₁++l₂).erase a = l₁.erase a ++ l₂ | [] l₂ h := absurd h (not_mem_nil a) | (x::xs) l₂ h := if h' : x = a then by simp [h'] else have a ∈ xs, from mem_of_ne_of_mem (assume h, h' h.symm) h, by simp [erase_append_left l₂ this, h'] lemma erase_append_right {a : α} : ∀{l₁ : list α} (l₂), a ∉ l₁ → (l₁++l₂).erase a = l₁ ++ l₂.erase a | [] l₂ h := rfl | (x::xs) l₂ h := if h' : x = a then begin simp [h'] at h, contradiction end else have a ∉ xs, from not_mem_of_not_mem_cons h, by simp [erase_append_right l₂ this, h'] lemma erase_sublist (a : α) : ∀(l : list α), l.erase a <+ l | [] := sublist.refl nil | (x :: xs) := if h : x = a then by simp [h] else begin simp [h], apply cons_sublist_cons, apply erase_sublist xs end lemma erase_subset (a : α) (l : list α) : l.erase a ⊆ l := subset_of_sublist (erase_sublist a l) theorem mem_erase_of_ne_of_mem {a b : α} : ∀ {l : list α}, a ≠ b → a ∈ l → a ∈ l.erase b | [] aneb anil := begin simp at anil, contradiction end | (c :: l) aneb acl := if h : c = b then begin simp [h, aneb] at acl, simp [h, acl] end else begin simp [h], simp at acl, cases acl with h' h', { simp [h'] }, simp [mem_erase_of_ne_of_mem aneb h'] end theorem mem_of_mem_erase {a b : α} : ∀{l:list α}, a ∈ l.erase b → a ∈ l | [] h := begin simp at h, contradiction end | (c :: l) h := if h' : c = b then begin simp [h'] at h, simp [h] end else begin simp [h'] at h, cases h with h'' h'', { simp [h''] }, simp [mem_of_mem_erase h''] end end erase /- disjoint -/ section disjoint def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, (a ∈ l₁ → a ∈ l₂ → false) lemma disjoint_left {l₁ l₂ : list α} : disjoint l₁ l₂ → ∀ {a}, a ∈ l₁ → a ∉ l₂ := λ d, d lemma disjoint_right {l₁ l₂ : list α} : disjoint l₁ l₂ → ∀ {a}, a ∈ l₂ → a ∉ l₁ := λ d a i₂ i₁, d i₁ i₂ lemma disjoint.comm {l₁ l₂ : list α} : disjoint l₁ l₂ → disjoint l₂ l₁ := λ d a i₂ i₁, d i₁ i₂ lemma disjoint_of_subset_left {l₁ l₂ l : list α} : l₁ ⊆ l → disjoint l l₂ → disjoint l₁ l₂ := λ ss d x xinl₁, d (ss xinl₁) lemma disjoint_of_subset_right {l₁ l₂ l : list α} : l₂ ⊆ l → disjoint l₁ l → disjoint l₁ l₂ := λ ss d x xinl xinl₁, d xinl (ss xinl₁) lemma disjoint_of_disjoint_cons_left {a : α} {l₁ l₂} : disjoint (a::l₁) l₂ → disjoint l₁ l₂ := disjoint_of_subset_left (list.subset_cons _ _) lemma disjoint_of_disjoint_cons_right {a : α} {l₁ l₂} : disjoint l₁ (a::l₂) → disjoint l₁ l₂ := disjoint_of_subset_right (list.subset_cons _ _) lemma disjoint_nil_left (l : list α) : disjoint [] l := λ a ab, absurd ab (not_mem_nil a) lemma disjoint_nil_right (l : list α) : disjoint l [] := disjoint.comm (disjoint_nil_left l) lemma disjoint_cons_of_not_mem_of_disjoint {a : α} {l₁ l₂ : list α} : a ∉ l₂ → disjoint l₁ l₂ → disjoint (a::l₁) l₂ := λ nainl₂ d x (xinal₁ : x ∈ a::l₁), or.elim (eq_or_mem_of_mem_cons xinal₁) (λ xeqa : x = a, eq.symm xeqa ▸ nainl₂) (λ xinl₁ : x ∈ l₁, disjoint_left d xinl₁) lemma disjoint_append_of_disjoint_left {l₁ l₂ l : list α} : disjoint l₁ l → disjoint l₂ l → disjoint (l₁++l₂) l := λ d₁ d₂ x h, or.elim (mem_or_mem_of_mem_append h) (@d₁ x) (@d₂ x) lemma disjoint_of_disjoint_append_left_left {l₁ l₂ l : list α} : disjoint (l₁++l₂) l → disjoint l₁ l := disjoint_of_subset_left (list.subset_append_left _ _) lemma disjoint_of_disjoint_append_left_right {l₁ l₂ l : list α} : disjoint (l₁++l₂) l → disjoint l₂ l := disjoint_of_subset_left (list.subset_append_right _ _) lemma disjoint_of_disjoint_append_right_left {l₁ l₂ l : list α} : disjoint l (l₁++l₂) → disjoint l l₁ := disjoint_of_subset_right (list.subset_append_left _ _) lemma disjoint_of_disjoint_append_right_right {l₁ l₂ l : list α} : disjoint l (l₁++l₂) → disjoint l l₂ := disjoint_of_subset_right (list.subset_append_right _ _) end disjoint /- upto -/ def upto : nat → list nat | 0 := [] | (n+1) := n :: upto n @[simp] theorem upto_nil : upto 0 = nil := rfl @[simp] theorem upto_succ (n : nat) : upto (succ n) = n :: upto n := rfl @[simp] theorem length_upto : ∀ n, length (upto n) = n | 0 := rfl | (succ n) := begin rw [upto_succ, length_cons, length_upto] end theorem upto_ne_nil_of_ne_zero {n : ℕ} (h : n ≠ 0) : upto n ≠ nil := suppose upto n = nil, have upto n = upto 0, from upto_nil ▸ this, have n = 0, from calc n = length (upto n) : by rw length_upto ... = length (upto 0) : by rw this ... = 0 : by rw length_upto, h this theorem lt_of_mem_upto : ∀ ⦃n i⦄, i ∈ upto n → i < n | 0 := assume i imem, absurd imem (not_mem_nil _) | (succ n) := assume i imem, or.elim (eq_or_mem_of_mem_cons imem) (λ h, begin rw h, apply lt_succ_self end) (λ h, lt.trans (lt_of_mem_upto h) (lt_succ_self n)) theorem mem_upto_succ_of_mem_upto {n i : nat} : i ∈ upto n → i ∈ upto (succ n) := assume i, mem_cons_of_mem _ i theorem mem_upto_of_lt : ∀ ⦃n i : nat⦄, i < n → i ∈ upto n | 0 := λ i h, absurd h (not_lt_zero i) | (succ n) := λ i h, begin cases nat.lt_or_eq_of_le (le_of_lt_succ h) with ilt ieq, { apply mem_upto_succ_of_mem_upto, apply mem_upto_of_lt ilt }, simp [ieq] end lemma upto_step : ∀ (n : nat), upto (succ n) = (map succ (upto n)) ++ [0] | 0 := rfl | (succ n) := by simp [(upto_step n)^.symm] /- union -/ section union variable [decidable_eq α] @[simp] theorem union_nil (l : list α) : l ∪ [] = l := rfl @[simp] theorem union_cons (l₁ l₂ : list α) (a : α) : l₁ ∪ (a :: l₂) = insert a l₁ ∪ l₂ := rfl theorem mem_or_mem_of_mem_union : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∪ l₂ → a ∈ l₁ ∨ a ∈ l₂ | l₁ [] a h := begin simp at h, simp [h] end | l₁ (b :: l₂) a h := if h' : b ∈ l₂ then begin simp at h, cases mem_or_mem_of_mem_union h with h₀ h₀, { simp at h₀, cases h₀ with h₁ h₁, simp [h₁], simp [h₁] }, simp [h₀] end else begin simp [union_cons] at h, cases mem_or_mem_of_mem_union h with h₀ h₀, { simp at h₀, cases h₀ with h₁ h₁, repeat { simp [h₁] } }, simp [h₀] end theorem mem_union_left {a : α} {l₁ : list α} (h : a ∈ l₁) (l₂ : list α) : a ∈ l₁ ∪ l₂ := begin revert h, generalize l₁ l, induction l₂ with b l₂ ih, { simp, intros, assumption }, intros, apply ih, simp [h] end theorem mem_union_right {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := begin generalize l₁ l, induction l₂ with b l₂ ih, { simp at h, contradiction }, intro l, simp, simp at h, cases h with h₀ h₀, { simp [h₀], apply mem_union_left, simp }, apply ih h₀ end @[simp] theorem mem_union_iff (a : α) (l₁ l₂ : list α) : a ∈ l₁ ∪ l₂ ↔ a ∈ l₁ ∨ a ∈ l₂ := iff.intro mem_or_mem_of_mem_union (λ h, or.elim h (λ h', mem_union_left h' l₂) (mem_union_right l₁)) theorem forall_mem_union {p : α → Prop} {l₁ l₂ : list α} (h₁ : ∀ x ∈ l₁, p x) (h₂ : ∀ x ∈ l₂, p x) : ∀ x ∈ l₁ ∪ l₂, p x := begin intro x, simp, intro h, cases h, { apply h₁, assumption }, apply h₂, assumption end theorem forall_mem_of_forall_mem_union_left {p : α → Prop} {l₁ l₂ : list α} (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x := begin intros x xl₁, apply h, apply mem_union_left xl₁ end theorem forall_mem_of_forall_mem_union_right {p : α → Prop} {l₁ l₂ : list α} (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x := begin intros x xl₂, apply h, apply mem_union_right l₁ xl₂ end end union /- inter -/ section inter variable [decidable_eq α] @[simp] theorem inter_nil (l : list α) : [] ∩ l = [] := rfl @[simp] theorem inter_cons_of_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : (a::l₁) ∩ l₂ = a :: (l₁ ∩ l₂) := if_pos h @[simp] theorem inter_cons_of_not_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∉ l₂) : (a::l₁) ∩ l₂ = l₁ ∩ l₂ := if_neg h theorem mem_of_mem_inter_left : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∩ l₂ → a ∈ l₁ | [] l₂ a i := absurd i (not_mem_nil a) | (b::l₁) l₂ a i := by_cases (λ binl₂ : b ∈ l₂, have aux : a ∈ b :: l₁ ∩ l₂, begin rw [inter_cons_of_mem _ binl₂] at i, exact i end, or.elim (eq_or_mem_of_mem_cons aux) (λ aeqb : a = b, begin rw [aeqb], apply mem_cons_self end) (λ aini, mem_cons_of_mem _ (mem_of_mem_inter_left aini))) (λ nbinl₂ : b ∉ l₂, have ainl₁ : a ∈ l₁, begin rw [inter_cons_of_not_mem _ nbinl₂] at i, exact (mem_of_mem_inter_left i) end, mem_cons_of_mem _ ainl₁) theorem mem_of_mem_inter_right : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∩ l₂ → a ∈ l₂ | [] l₂ a i := absurd i (not_mem_nil _) | (b::l₁) l₂ a i := by_cases (λ binl₂ : b ∈ l₂, have aux : a ∈ b :: l₁ ∩ l₂, begin rw [inter_cons_of_mem _ binl₂] at i, exact i end, or.elim (eq_or_mem_of_mem_cons aux) (λ aeqb : a = b, begin rw [aeqb], exact binl₂ end) (λ aini : a ∈ l₁ ∩ l₂, mem_of_mem_inter_right aini)) (λ nbinl₂ : b ∉ l₂, begin rw [inter_cons_of_not_mem _ nbinl₂] at i, exact (mem_of_mem_inter_right i) end) theorem mem_inter_of_mem_of_mem : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂ | [] l₂ a i₁ i₂ := absurd i₁ (not_mem_nil _) | (b::l₁) l₂ a i₁ i₂ := by_cases (λ binl₂ : b ∈ l₂, or.elim (eq_or_mem_of_mem_cons i₁) (λ aeqb : a = b, begin rw [inter_cons_of_mem _ binl₂, aeqb], apply mem_cons_self end) (λ ainl₁ : a ∈ l₁, begin rw [inter_cons_of_mem _ binl₂], apply mem_cons_of_mem, exact (mem_inter_of_mem_of_mem ainl₁ i₂) end)) (λ nbinl₂ : b ∉ l₂, or.elim (eq_or_mem_of_mem_cons i₁) (λ aeqb : a = b, begin rw aeqb at i₂, exact absurd i₂ nbinl₂ end) (λ ainl₁ : a ∈ l₁, begin rw [inter_cons_of_not_mem _ nbinl₂], exact (mem_inter_of_mem_of_mem ainl₁ i₂) end)) @[simp] theorem mem_inter_iff (a : α) (l₁ l₂ : list α) : a ∈ l₁ ∩ l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ := iff.intro (λ h, and.intro (mem_of_mem_inter_left h) (mem_of_mem_inter_right h)) (λ h, mem_inter_of_mem_of_mem h^.left h^.right) theorem inter_eq_nil_of_disjoint : ∀ {l₁ l₂ : list α}, disjoint l₁ l₂ → l₁ ∩ l₂ = [] | [] l₂ d := rfl | (a::l₁) l₂ d := have aux_eq : l₁ ∩ l₂ = [], from inter_eq_nil_of_disjoint (disjoint_of_disjoint_cons_left d), have nainl₂ : a ∉ l₂, from disjoint_left d (mem_cons_self _ _), by rw [inter_cons_of_not_mem _ nainl₂, aux_eq] theorem forall_mem_inter_of_forall_left {p : α → Prop} {l₁ : list α} (h : ∀ x ∈ l₁, p x) (l₂ : list α) : ∀ x, x ∈ l₁ ∩ l₂ → p x := λ x xl₁l₂, h x (mem_of_mem_inter_left xl₁l₂) theorem forall_mem_inter_of_forall_right {p : α → Prop} (l₁ : list α) {l₂ : list α} (h : ∀ x ∈ l₂, p x) : ∀ x, x ∈ l₁ ∩ l₂ → p x := λ x xl₁l₂, h x (mem_of_mem_inter_right xl₁l₂) end inter /- no duplicates predicate -/ inductive nodup {α : Type uu} : list α → Prop | ndnil : nodup [] | ndcons : ∀ {a : α} {l : list α}, a ∉ l → nodup l → nodup (a::l) section nodup open nodup theorem nodup_nil : @nodup α [] := ndnil theorem nodup_cons {a : α} {l : list α} : a ∉ l → nodup l → nodup (a::l) := λ i n, ndcons i n theorem nodup_singleton (a : α) : nodup [a] := nodup_cons (not_mem_nil a) nodup_nil theorem nodup_of_nodup_cons : ∀ {a : α} {l : list α}, nodup (a::l) → nodup l | a xs (ndcons i n) := n theorem not_mem_of_nodup_cons : ∀ {a : α} {l : list α}, nodup (a::l) → a ∉ l | a xs (ndcons i n) := i theorem not_nodup_cons_of_mem {a : α} {l : list α} : a ∈ l → ¬ nodup (a :: l) := λ ainl d, absurd ainl (not_mem_of_nodup_cons d) theorem nodup_of_sublist : Π {l₁ l₂ : list α}, l₁ <+ l₂ → nodup l₂ → nodup l₁ | ._ ._ sublist.slnil h := h | ._ ._ (sublist.cons l₁ l₂ a s) (ndcons i n) := nodup_of_sublist s n | ._ ._ (sublist.cons2 l₁ l₂ a s) (ndcons i n) := ndcons (λh, i (subset_of_sublist s h)) (nodup_of_sublist s n) theorem not_nodup_cons_of_not_nodup {a : α} {l : list α} : ¬ nodup l → ¬ nodup (a :: l) := mt nodup_of_nodup_cons theorem nodup_of_nodup_append_left {l₁ l₂ : list α} : nodup (l₁++l₂) → nodup l₁ := nodup_of_sublist (sublist_append_left l₁ l₂) theorem nodup_of_nodup_append_right : ∀ {l₁ l₂ : list α}, nodup (l₁++l₂) → nodup l₂ | [] l₂ n := n | (x::xs) l₂ n := nodup_of_nodup_append_right (nodup_of_nodup_cons n) theorem disjoint_of_nodup_append : ∀ {l₁ l₂ : list α}, nodup (l₁++l₂) → disjoint l₁ l₂ | [] l₂ d := disjoint_nil_left l₂ | (x::xs) l₂ d := have nodup (x::(xs++l₂)), from d, have x ∉ xs++l₂, from not_mem_of_nodup_cons this, have nxinl₂ : x ∉ l₂, from not_mem_of_not_mem_append_right this, assume a, suppose a ∈ x::xs, or.elim (eq_or_mem_of_mem_cons this) (suppose a = x, eq.symm this ▸ nxinl₂) (assume ainxs : a ∈ xs, have nodup (x::(xs++l₂)), from d, have nodup (xs++l₂), from nodup_of_nodup_cons this, have disjoint xs l₂, from disjoint_of_nodup_append this, disjoint_left this ainxs) theorem nodup_append_of_nodup_of_nodup_of_disjoint : ∀ {l₁ l₂ : list α}, nodup l₁ → nodup l₂ → disjoint l₁ l₂ → nodup (l₁++l₂) | [] l₂ d₁ d₂ dsj := begin rw [nil_append], exact d₂ end | (x::xs) l₂ d₁ d₂ dsj := have ndxs : nodup xs, from nodup_of_nodup_cons d₁, have disjoint xs l₂, from disjoint_of_disjoint_cons_left dsj, have ndxsl₂ : nodup (xs++l₂), from nodup_append_of_nodup_of_nodup_of_disjoint ndxs d₂ this, have nxinxs : x ∉ xs, from not_mem_of_nodup_cons d₁, have x ∉ l₂, from disjoint_left dsj (mem_cons_self x xs), have x ∉ xs++l₂, from not_mem_append nxinxs this, nodup_cons this ndxsl₂ theorem nodup_app_comm {l₁ l₂ : list α} (d : nodup (l₁++l₂)) : nodup (l₂++l₁) := have d₁ : nodup l₁, from nodup_of_nodup_append_left d, have d₂ : nodup l₂, from nodup_of_nodup_append_right d, have dsj : disjoint l₁ l₂, from disjoint_of_nodup_append d, nodup_append_of_nodup_of_nodup_of_disjoint d₂ d₁ (disjoint.comm dsj) theorem nodup_head {a : α} {l₁ l₂ : list α} (d : nodup (l₁++(a::l₂))) : nodup (a::(l₁++l₂)) := have d₁ : nodup (a::(l₂++l₁)), from nodup_app_comm d, have d₂ : nodup (l₂++l₁), from nodup_of_nodup_cons d₁, have d₃ : nodup (l₁++l₂), from nodup_app_comm d₂, have nain : a ∉ l₂++l₁, from not_mem_of_nodup_cons d₁, have nain₂ : a ∉ l₂, from not_mem_of_not_mem_append_left nain, have nain₁ : a ∉ l₁, from not_mem_of_not_mem_append_right nain, nodup_cons (not_mem_append nain₁ nain₂) d₃ theorem nodup_middle {a : α} {l₁ l₂ : list α} (d : nodup (a::(l₁++l₂))) : nodup (l₁++(a::l₂)) := have d₁ : nodup (l₁++l₂), from nodup_of_nodup_cons d, have nain : a ∉ l₁++l₂, from not_mem_of_nodup_cons d, have disj : disjoint l₁ l₂, from disjoint_of_nodup_append d₁, have d₂ : nodup l₁, from nodup_of_nodup_append_left d₁, have d₃ : nodup l₂, from nodup_of_nodup_append_right d₁, have nain₂ : a ∉ l₂, from not_mem_of_not_mem_append_right nain, have nain₁ : a ∉ l₁, from not_mem_of_not_mem_append_left nain, have d₄ : nodup (a::l₂), from nodup_cons nain₂ d₃, have disj₂ : disjoint l₁ (a::l₂), from disjoint.comm (disjoint_cons_of_not_mem_of_disjoint nain₁ (disjoint.comm disj)), nodup_append_of_nodup_of_nodup_of_disjoint d₂ d₄ disj₂ theorem nodup_map {f : α → β} (inj : injective f) : ∀ {l : list α}, nodup l → nodup (map f l) | [] n := begin apply nodup_nil end | (x::xs) n := have nxinxs : x ∉ xs, from not_mem_of_nodup_cons n, have ndxs : nodup xs, from nodup_of_nodup_cons n, have ndmfxs : nodup (map f xs), from nodup_map ndxs, have nfxinm : f x ∉ map f xs, from λ ab : f x ∈ map f xs, match (exists_of_mem_map ab) with | ⟨(y : α), (yinxs : y ∈ xs), (fyfx : f y = f x)⟩ := have yeqx : y = x, from inj fyfx, begin subst y, contradiction end end, nodup_cons nfxinm ndmfxs theorem nodup_erase_of_nodup [decidable_eq α] (a : α) : ∀ {l}, nodup l → nodup (l.erase a) | [] n := nodup_nil | (b::l) n := by_cases (λ aeqb : b = a, begin rw [aeqb, erase_cons_head], exact (nodup_of_nodup_cons n) end) (λ aneb : b ≠ a, have nbinl : b ∉ l, from not_mem_of_nodup_cons n, have ndl : nodup l, from nodup_of_nodup_cons n, have ndeal : nodup (l.erase a), from nodup_erase_of_nodup ndl, have nbineal : b ∉ l.erase a, from λ i, absurd (erase_subset _ _ i) nbinl, have aux : nodup (b :: l.erase a), from nodup_cons nbineal ndeal, begin rw [erase_cons_tail _ aneb], exact aux end) theorem mem_erase_of_nodup [decidable_eq α] (a : α) : ∀ {l}, nodup l → a ∉ l.erase a | [] n := (not_mem_nil _) | (b::l) n := have ndl : nodup l, from nodup_of_nodup_cons n, have naineal : a ∉ l.erase a, from mem_erase_of_nodup ndl, have nbinl : b ∉ l, from not_mem_of_nodup_cons n, by_cases (λ aeqb : b = a, begin rw [aeqb.symm, erase_cons_head], exact nbinl end) (λ aneb : b ≠ a, have aux : a ∉ b :: l.erase a, from assume ainbeal : a ∈ b :: l.erase a, or.elim (eq_or_mem_of_mem_cons ainbeal) (λ aeqb : a = b, absurd aeqb.symm aneb) (λ aineal : a ∈ l.erase a, absurd aineal naineal), begin rw [erase_cons_tail _ aneb], exact aux end) def erase_dup [decidable_eq α] : list α → list α | [] := [] | (x :: xs) := if x ∈ xs then erase_dup xs else x :: erase_dup xs theorem erase_dup_nil [decidable_eq α] : erase_dup [] = ([] : list α) := rfl theorem erase_dup_cons_of_mem [decidable_eq α] {a : α} {l : list α} : a ∈ l → erase_dup (a::l) = erase_dup l := assume ainl, calc erase_dup (a::l) = if a ∈ l then erase_dup l else a :: erase_dup l : rfl ... = erase_dup l : if_pos ainl theorem erase_dup_cons_of_not_mem [decidable_eq α] {a : α} {l : list α} : a ∉ l → erase_dup (a::l) = a :: erase_dup l := assume nainl, calc erase_dup (a::l) = if a ∈ l then erase_dup l else a :: erase_dup l : rfl ... = a :: erase_dup l : if_neg nainl theorem mem_erase_dup [decidable_eq α] {a : α} : ∀ {l : list α}, a ∈ l → a ∈ erase_dup l | [] h := absurd h (not_mem_nil _) | (b::l) h := by_cases (λ binl : b ∈ l, or.elim (eq_or_mem_of_mem_cons h) (λ aeqb : a = b, begin rw [erase_dup_cons_of_mem binl], rw ←aeqb at binl, exact (mem_erase_dup binl) end) (λ ainl : a ∈ l, begin rw [erase_dup_cons_of_mem binl], exact (mem_erase_dup ainl) end)) (λ nbinl : b ∉ l, or.elim (eq_or_mem_of_mem_cons h) (λ aeqb : a = b, begin rw [erase_dup_cons_of_not_mem nbinl, aeqb], apply mem_cons_self end) (λ ainl : a ∈ l, begin rw [erase_dup_cons_of_not_mem nbinl], exact (or.inr (mem_erase_dup ainl)) end)) theorem erase_dup_sublist [decidable_eq α] : ∀ (l : list α), erase_dup l <+ l | [] := sublist.slnil | (b::l) := if h : b ∈ l then by simp[erase_dup, h]; exact sublist_cons_of_sublist _ (erase_dup_sublist l) else by simp[erase_dup, h]; exact cons_sublist_cons _ (erase_dup_sublist l) theorem mem_of_mem_erase_dup [decidable_eq α] {a : α} : ∀ {l : list α}, a ∈ erase_dup l → a ∈ l | [] h := begin rw [erase_dup_nil] at h, exact h end | (b::l) h := by_cases (λ binl : b ∈ l, have h₁ : a ∈ erase_dup l, begin rw [erase_dup_cons_of_mem binl] at h, exact h end, or.inr (mem_of_mem_erase_dup h₁)) (λ nbinl : b ∉ l, have h₁ : a ∈ b :: erase_dup l, begin rw [erase_dup_cons_of_not_mem nbinl] at h, exact h end, or.elim (eq_or_mem_of_mem_cons h₁) (λ aeqb : a = b, begin rw aeqb, apply mem_cons_self end) (λ ainel : a ∈ erase_dup l, or.inr (mem_of_mem_erase_dup ainel))) @[simp] theorem mem_erase_dup_iff [decidable_eq α] (a : α) (l : list α) : a ∈ erase_dup l ↔ a ∈ l := iff.intro mem_of_mem_erase_dup mem_erase_dup theorem erase_dup_sub [decidable_eq α] (l : list α) : erase_dup l ⊆ l := λ a i, mem_of_mem_erase_dup i theorem sub_erase_dup [decidable_eq α] (l : list α) : l ⊆ erase_dup l := λ a i, mem_erase_dup i theorem nodup_erase_dup [decidable_eq α] : ∀ l : list α, nodup (erase_dup l) | [] := begin rw erase_dup_nil, exact nodup_nil end | (a::l) := by_cases (λ ainl : a ∈ l, begin rw [erase_dup_cons_of_mem ainl], exact (nodup_erase_dup l) end) (λ nainl : a ∉ l, have r : nodup (erase_dup l), from nodup_erase_dup l, have nin : a ∉ erase_dup l, from assume ab : a ∈ erase_dup l, absurd (mem_of_mem_erase_dup ab) nainl, begin rw [erase_dup_cons_of_not_mem nainl], exact (nodup_cons nin r) end) theorem erase_dup_eq_of_nodup [decidable_eq α] : ∀ {l : list α}, nodup l → erase_dup l = l | [] d := rfl | (a::l) d := have nainl : a ∉ l, from not_mem_of_nodup_cons d, have dl : nodup l, from nodup_of_nodup_cons d, by rw [erase_dup_cons_of_not_mem nainl, erase_dup_eq_of_nodup dl] attribute [instance] def decidable_nodup [decidable_eq α] : ∀ (l : list α), decidable (nodup l) | [] := is_true nodup_nil | (a::l) := if h : a ∈ l then is_false (not_nodup_cons_of_mem h) else match (decidable_nodup l) with | (is_true nd) := is_true (nodup_cons h nd) | (is_false d) := is_false (not_nodup_cons_of_not_nodup d) end private def dgen (a : α) : ∀ l, nodup l → nodup (map (λ b : β, (a, b)) l) | [] h := nodup_nil | (x::l) h := have dl : nodup l, from nodup_of_nodup_cons h, have dm : nodup (map (λ b : β, (a, b)) l), from dgen l dl, have nxin : x ∉ l, from not_mem_of_nodup_cons h, have npin : (a, x) ∉ map (λ b, (a, b)) l, from assume pin, absurd (mem_of_mem_map_pair₁ pin) nxin, nodup_cons npin dm theorem nodup_product : ∀ {l₁ : list α} {l₂ : list β}, nodup l₁ → nodup l₂ → nodup (product l₁ l₂) | [] l₂ n₁ n₂ := nodup_nil | (a::l₁) l₂ n₁ n₂ := have nainl₁ : a ∉ l₁, from not_mem_of_nodup_cons n₁, have n₃ : nodup l₁, from nodup_of_nodup_cons n₁, have n₄ : nodup (product l₁ l₂), from nodup_product n₃ n₂, have dm : nodup (map (λ b : β, (a, b)) l₂), from dgen a l₂ n₂, have dsj : disjoint (map (λ b : β, (a, b)) l₂) (product l₁ l₂), from λ p : α × β, match p with | (a₁, b₁) := λ (i₁ : (a₁, b₁) ∈ map (λ b, (a, b)) l₂) (i₂ : (a₁, b₁) ∈ product l₁ l₂), have a₁inl₁ : a₁ ∈ l₁, from mem_of_mem_product_left i₂, have a₁ = a, from eq_of_mem_map_pair₁ i₁, have a ∈ l₁, begin rw ←this, assumption end, absurd this nainl₁ end, nodup_append_of_nodup_of_nodup_of_disjoint dm n₄ dsj theorem nodup_filter (p : α → Prop) [decidable_pred p] : ∀ {l : list α}, nodup l → nodup (filter p l) | [] nd := nodup_nil | (a::l) nd := have nainl : a ∉ l, from not_mem_of_nodup_cons nd, have ndl : nodup l, from nodup_of_nodup_cons nd, have ndf : nodup (filter p l), from nodup_filter ndl, have nainf : a ∉ filter p l, from assume ainf, absurd (mem_of_mem_filter ainf) nainl, by_cases (λ pa : p a, begin rw [filter_cons_of_pos _ pa], exact (nodup_cons nainf ndf) end) (λ npa : ¬ p a, begin rw [filter_cons_of_neg _ npa], exact ndf end) lemma dmap_nodup_of_dinj {p : α → Prop} [h : decidable_pred p] {f : Π a, p a → β} (pdi : dinj p f) : ∀ {l : list α}, nodup l → nodup (dmap p f l) | [] := assume P, nodup.ndnil | (a::l) := assume Pnodup, if pa : p a then begin rw [dmap_cons_of_pos pa], apply nodup_cons, apply (not_mem_dmap_of_dinj_of_not_mem pdi pa), exact not_mem_of_nodup_cons Pnodup, exact dmap_nodup_of_dinj (nodup_of_nodup_cons Pnodup) end else begin rw [dmap_cons_of_neg pa], exact dmap_nodup_of_dinj (nodup_of_nodup_cons Pnodup) end theorem nodup_concat {a : α} {l : list α} (h : a ∉ l) (h' : nodup l) : nodup (concat l a) := begin revert h, induction l with b l ih, { intro h₀, apply nodup_singleton }, intro h₀, rw [concat_cons], apply nodup_cons, { simp, intro h₁, apply h₀, simp, cases h₁ with h₂ h₂, simp [h₂], exact absurd h₂ (not_mem_of_nodup_cons h') }, apply ih, { apply nodup_of_nodup_cons h' }, intro h₁, apply h₀, exact mem_cons_of_mem _ h₁ end theorem nodup_insert [decidable_eq α] {a : α} {l : list α} (h : nodup l) : nodup (insert a l) := if h' : a ∈ l then by simp [h', h] else begin rw [insert_of_not_mem h'], apply nodup_concat, repeat {assumption} end theorem nodup_upto : ∀ n, nodup (upto n) | 0 := nodup_nil | (n+1) := have d : nodup (upto n), from nodup_upto n, have n : n ∉ upto n, from assume i : n ∈ upto n, absurd (lt_of_mem_upto i) (nat.lt_irrefl n), nodup_cons n d theorem nodup_union_of_nodup_of_nodup [decidable_eq α] {l₁ l₂ : list α} (h₁ : nodup l₁) (h₂ : nodup l₂) : nodup (l₁ ∪ l₂) := begin revert h₁, generalize l₁ l, induction l₂ with a l₂ ih, { intros l nodupl, exact nodupl }, intros l nodupl, simp, apply ih, { apply nodup_of_nodup_cons h₂}, apply nodup_insert nodupl end theorem nodup_inter_of_nodup [decidable_eq α] : ∀ {l₁ : list α} (l₂), nodup l₁ → nodup (l₁ ∩ l₂) | [] l₂ d := nodup_nil | (a::l₁) l₂ d := have d₁ : nodup l₁, from nodup_of_nodup_cons d, have d₂ : nodup (l₁ ∩ l₂), from nodup_inter_of_nodup _ d₁, have nainl₁ : a ∉ l₁, from not_mem_of_nodup_cons d, have naini : a ∉ l₁ ∩ l₂, from λ i, absurd (mem_of_mem_inter_left i) nainl₁, by_cases (λ ainl₂ : a ∈ l₂, begin rw [inter_cons_of_mem _ ainl₂], exact (nodup_cons naini d₂) end) (λ nainl₂ : a ∉ l₂, begin rw [inter_cons_of_not_mem _ nainl₂], exact d₂ end) end nodup end list
7499f0dbb7f426bd337575468e2ecb59192a8cb7
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/currying_auto.lean
89d7ee33363e5fc6e6ba766c073172cffaa98826
[]
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
4,485
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.products.bifunctor import Mathlib.PostPort universes u₁ u₂ u₃ v₁ v₂ v₃ namespace Mathlib namespace category_theory /-- The uncurrying functor, taking a functor `C ⥤ (D ⥤ E)` and producing a functor `(C × D) ⥤ E`. -/ def uncurry {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E := functor.mk (fun (F : C ⥤ D ⥤ E) => functor.mk (fun (X : C × D) => functor.obj (functor.obj F (prod.fst X)) (prod.snd X)) fun (X Y : C × D) (f : X ⟶ Y) => nat_trans.app (functor.map F (prod.fst f)) (prod.snd X) ≫ functor.map (functor.obj F (prod.fst Y)) (prod.snd f)) fun (F G : C ⥤ D ⥤ E) (T : F ⟶ G) => nat_trans.mk fun (X : C × D) => nat_trans.app (nat_trans.app T (prod.fst X)) (prod.snd X) /-- The object level part of the currying functor. (See `curry` for the functorial version.) -/ def curry_obj {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] (F : C × D ⥤ E) : C ⥤ D ⥤ E := functor.mk (fun (X : C) => functor.mk (fun (Y : D) => functor.obj F (X, Y)) fun (Y Y' : D) (g : Y ⟶ Y') => functor.map F (𝟙, g)) fun (X X' : C) (f : X ⟶ X') => nat_trans.mk fun (Y : D) => functor.map F (f, 𝟙) /-- The currying functor, taking a functor `(C × D) ⥤ E` and producing a functor `C ⥤ (D ⥤ E)`. -/ def curry {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] : (C × D ⥤ E) ⥤ C ⥤ D ⥤ E := functor.mk (fun (F : C × D ⥤ E) => curry_obj F) fun (F G : C × D ⥤ E) (T : F ⟶ G) => nat_trans.mk fun (X : C) => nat_trans.mk fun (Y : D) => nat_trans.app T (X, Y) @[simp] theorem uncurry.obj_obj {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C ⥤ D ⥤ E} {X : C × D} : functor.obj (functor.obj uncurry F) X = functor.obj (functor.obj F (prod.fst X)) (prod.snd X) := rfl @[simp] theorem uncurry.obj_map {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C ⥤ D ⥤ E} {X : C × D} {Y : C × D} {f : X ⟶ Y} : functor.map (functor.obj uncurry F) f = nat_trans.app (functor.map F (prod.fst f)) (prod.snd X) ≫ functor.map (functor.obj F (prod.fst Y)) (prod.snd f) := rfl @[simp] theorem uncurry.map_app {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C ⥤ D ⥤ E} {G : C ⥤ D ⥤ E} {α : F ⟶ G} {X : C × D} : nat_trans.app (functor.map uncurry α) X = nat_trans.app (nat_trans.app α (prod.fst X)) (prod.snd X) := rfl @[simp] theorem curry.obj_obj_obj {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C × D ⥤ E} {X : C} {Y : D} : functor.obj (functor.obj (functor.obj curry F) X) Y = functor.obj F (X, Y) := rfl @[simp] theorem curry.obj_obj_map {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C × D ⥤ E} {X : C} {Y : D} {Y' : D} {g : Y ⟶ Y'} : functor.map (functor.obj (functor.obj curry F) X) g = functor.map F (𝟙, g) := rfl @[simp] theorem curry.obj_map_app {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C × D ⥤ E} {X : C} {X' : C} {f : X ⟶ X'} {Y : D} : nat_trans.app (functor.map (functor.obj curry F) f) Y = functor.map F (f, 𝟙) := rfl @[simp] theorem curry.map_app_app {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] {F : C × D ⥤ E} {G : C × D ⥤ E} {α : F ⟶ G} {X : C} {Y : D} : nat_trans.app (nat_trans.app (functor.map curry α) X) Y = nat_trans.app α (X, Y) := rfl /-- The equivalence of functor categories given by currying/uncurrying. -/ @[simp] theorem currying_unit_iso_inv_app_app_app {C : Type u₁} [category C] {D : Type u₂} [category D] {E : Type u₃} [category E] (X : C ⥤ D ⥤ E) : ∀ (X_1 : C) (X_2 : D), nat_trans.app (nat_trans.app (nat_trans.app (iso.inv (equivalence.unit_iso currying)) X) X_1) X_2 = 𝟙 := sorry end Mathlib
d907a661c4f58035ed2f19a2c5324859d218ba65
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
/src/algebra/add_torsor.lean
b686b0582392b2b6c0a05400dd3bf6ed1cad4e26
[ "Apache-2.0" ]
permissive
kmill/mathlib
ea5a007b67ae4e9e18dd50d31d8aa60f650425ee
1a419a9fea7b959317eddd556e1bb9639f4dcc05
refs/heads/master
1,668,578,197,719
1,593,629,163,000
1,593,629,163,000
276,482,939
0
0
null
1,593,637,960,000
1,593,637,959,000
null
UTF-8
Lean
false
false
12,435
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov. -/ import algebra.group.prod import algebra.group.type_tags import algebra.pi_instances import data.equiv.basic /-! # Torsors of additive group actions This file defines torsors of additive group actions. ## Notations The group elements are referred to as acting on points. This file defines the notation `+ᵥ` for adding a group element to a point and `-ᵥ` for subtracting two points to produce a group element. ## Implementation notes Affine spaces are the motivating example of torsors of additive group actions. It may be appropriate to refactor in terms of the general definition of group actions, via `to_additive`, when there is a use for multiplicative torsors (currently mathlib only develops the theory of group actions for multiplicative group actions). The variable `G` is an explicit rather than implicit argument to lemmas because otherwise the elaborator sometimes has problems inferring appropriate types and type class instances. ## References * https://en.wikipedia.org/wiki/Principal_homogeneous_space * https://en.wikipedia.org/wiki/Affine_space -/ /-- Type class for the `+ᵥ` notation. -/ class has_vadd (G : Type*) (P : Type*) := (vadd : G → P → P) /-- Type class for the `-ᵥ` notation. -/ class has_vsub (G : Type*) (P : Type*) := (vsub : P → P → G) infix ` +ᵥ `:65 := has_vadd.vadd infix ` -ᵥ `:65 := has_vsub.vsub section prio set_option default_priority 100 -- see Note [default priority] set_option old_structure_cmd true /-- Type class for additive monoid actions. -/ class add_action (G : Type*) (P : Type*) [add_monoid G] extends has_vadd G P := (zero_vadd' : ∀ p : P, (0 : G) +ᵥ p = p) (vadd_assoc' : ∀ (g1 g2 : G) (p : P), g1 +ᵥ (g2 +ᵥ p) = (g1 + g2) +ᵥ p) /-- An `add_torsor G P` gives a structure to the nonempty type `P`, acted on by an `add_group G` with a transitive and free action given by the `+ᵥ` operation and a corresponding subtraction given by the `-ᵥ` operation. In the case of a vector space, it is an affine space. -/ class add_torsor (G : Type*) (P : Type*) [add_group G] extends add_action G P, has_vsub G P := [nonempty : nonempty P] (vsub_vadd' : ∀ (p1 p2 : P), (p1 -ᵥ p2 : G) +ᵥ p2 = p1) (vadd_vsub' : ∀ (g : G) (p : P), g +ᵥ p -ᵥ p = g) end prio /-- An `add_group G` is a torsor for itself. -/ instance add_group_is_add_torsor (G : Type*) [add_group G] : add_torsor G G := { vadd := has_add.add, vsub := has_sub.sub, zero_vadd' := zero_add, vadd_assoc' := λ a b c, (add_assoc a b c).symm, vsub_vadd' := sub_add_cancel, vadd_vsub' := add_sub_cancel } /-- Simplify addition for a torsor for an `add_group G` over itself. -/ @[simp] lemma vadd_eq_add (G : Type*) [add_group G] (g1 g2 : G) : g1 +ᵥ g2 = g1 + g2 := rfl /-- Simplify subtraction for a torsor for an `add_group G` over itself. -/ @[simp] lemma vsub_eq_sub (G : Type*) [add_group G] (g1 g2 : G) : g1 -ᵥ g2 = g1 - g2 := rfl namespace add_action section general variables (G : Type*) {P : Type*} [add_monoid G] [A : add_action G P] include A /-- Adding the zero group element to a point gives the same point. -/ @[simp] lemma zero_vadd (p : P) : (0 : G) +ᵥ p = p := zero_vadd' p /-- Adding two group elements to a point produces the same result as adding their sum. -/ lemma vadd_assoc (g1 g2 : G) (p : P) : g1 +ᵥ (g2 +ᵥ p) = (g1 + g2) +ᵥ p := vadd_assoc' g1 g2 p end general section comm variables (G : Type*) {P : Type*} [add_comm_monoid G] [A : add_action G P] include A /-- Adding two group elements to a point produces the same result in either order. -/ lemma vadd_comm (p : P) (g1 g2 : G) : g1 +ᵥ (g2 +ᵥ p) = g2 +ᵥ (g1 +ᵥ p) := by rw [vadd_assoc, vadd_assoc, add_comm] end comm section group variables {G : Type*} {P : Type*} [add_group G] [A : add_action G P] include A /-- If the same group element added to two points produces equal results, those points are equal. -/ lemma vadd_left_cancel {p1 p2 : P} (g : G) (h : g +ᵥ p1 = g +ᵥ p2) : p1 = p2 := begin have h2 : -g +ᵥ (g +ᵥ p1) = -g +ᵥ (g +ᵥ p2), { rw h }, rwa [vadd_assoc, vadd_assoc, add_left_neg, zero_vadd, zero_vadd] at h2 end @[simp] lemma vadd_left_cancel_iff {p₁ p₂ : P} (g : G) : g +ᵥ p₁ = g +ᵥ p₂ ↔ p₁ = p₂ := ⟨vadd_left_cancel g, λ h, h ▸ rfl⟩ end group end add_action namespace add_torsor open add_action section general variables (G : Type*) {P : Type*} [add_group G] [T : add_torsor G P] include T /-- Adding the result of subtracting from another point produces that point. -/ @[simp] lemma vsub_vadd (p1 p2 : P) : (p1 -ᵥ p2 : G) +ᵥ p2 = p1 := vsub_vadd' p1 p2 /-- Adding a group element then subtracting the original point produces that group element. -/ @[simp] lemma vadd_vsub (g : G) (p : P) : g +ᵥ p -ᵥ p = g := vadd_vsub' g p variable {G} /-- If the same point added to two group elements produces equal results, those group elements are equal. -/ lemma vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +ᵥ p = g2 +ᵥ p) : g1 = g2 := by rw [←vadd_vsub G g1, h, vadd_vsub] @[simp] lemma vadd_right_cancel_iff {g1 g2 : G} (p : P) : g1 +ᵥ p = g2 +ᵥ p ↔ g1 = g2 := ⟨vadd_right_cancel p, λ h, h ▸ rfl⟩ /-- Adding a group element to a point, then subtracting another point, produces the same result as subtracting the points then adding the group element. -/ lemma vadd_vsub_assoc (g : G) (p1 p2 : P) : g +ᵥ p1 -ᵥ p2 = g + (p1 -ᵥ p2) := begin apply vadd_right_cancel p2, rw [vsub_vadd, ←vadd_assoc, vsub_vadd] end variable (G) /-- Subtracting a point from itself produces 0. -/ @[simp] lemma vsub_self (p : P) : p -ᵥ p = (0 : G) := by rw [←zero_add (p -ᵥ p : G), ←vadd_vsub_assoc, vadd_vsub] /-- If subtracting two points produces 0, they are equal. -/ lemma eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -ᵥ p2 = (0 : G)) : p1 = p2 := by rw [←vsub_vadd G p1 p2, h, zero_vadd] /-- Subtracting two points produces 0 if and only if they are equal. -/ @[simp] lemma vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -ᵥ p2 = (0 : G) ↔ p1 = p2 := iff.intro (eq_of_vsub_eq_zero G) (λ h, h ▸ vsub_self G _) /-- Cancellation adding the results of two subtractions. -/ @[simp] lemma vsub_add_vsub_cancel (p1 p2 p3 : P) : (p1 -ᵥ p2 : G) + (p2 -ᵥ p3) = (p1 -ᵥ p3) := begin apply vadd_right_cancel p3, rw [←vadd_assoc, vsub_vadd, vsub_vadd, vsub_vadd] end /-- Subtracting two points in the reverse order produces the negation of subtracting them. -/ @[simp] lemma neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -ᵥ p2) = (p2 -ᵥ p1 : G) := begin refine neg_eq_of_add_eq_zero (vadd_right_cancel p1 _), rw [vsub_add_vsub_cancel, vsub_self], end /-- Subtracting the result of adding a group element produces the same result as subtracting the points and subtracting that group element. -/ lemma vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -ᵥ (g +ᵥ p2) = (p1 -ᵥ p2) - g := by rw [←add_right_inj (p2 -ᵥ p1 : G), vsub_add_vsub_cancel, ←neg_vsub_eq_vsub_rev, vadd_vsub, ←add_sub_assoc, ←neg_vsub_eq_vsub_rev, neg_add_self, zero_sub] /-- Cancellation subtracting the results of two subtractions. -/ @[simp] lemma vsub_sub_vsub_cancel_right (p1 p2 p3 : P) : (p1 -ᵥ p3 : G) - (p2 -ᵥ p3) = (p1 -ᵥ p2) := by rw [←vsub_vadd_eq_vsub_sub, vsub_vadd] /-- The pairwise differences of a set of points. -/ def vsub_set (s : set P) : set G := {g | ∃ x ∈ s, ∃ y ∈ s, g = x -ᵥ y} /-- Each pairwise difference is in the `vsub_set`. -/ lemma vsub_mem_vsub_set {p1 p2 : P} {s : set P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : (p1 -ᵥ p2) ∈ vsub_set G s := ⟨p1, hp1, p2, hp2, rfl⟩ /-- `vsub_set` is contained in `vsub_set` of a larger set. -/ lemma vsub_set_mono {s1 s2 : set P} (h : s1 ⊆ s2) : vsub_set G s1 ⊆ vsub_set G s2 := begin rintros v ⟨p1, hp1, p2, hp2, hv⟩, exact ⟨p1, set.mem_of_mem_of_subset hp1 h, p2, set.mem_of_mem_of_subset hp2 h, hv⟩ end @[simp] lemma vadd_vsub_vadd_cancel_right (v₁ v₂ : G) (p : P) : ((v₁ +ᵥ p) -ᵥ (v₂ +ᵥ p) : G) = v₁ - v₂ := by rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero] end general section comm variables (G : Type*) {P : Type*} [add_comm_group G] [add_torsor G P] /-- Cancellation subtracting the results of two subtractions. -/ @[simp] lemma vsub_sub_vsub_cancel_left (p1 p2 p3 : P) : (p3 -ᵥ p2 : G) - (p3 -ᵥ p1) = (p1 -ᵥ p2) := by rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel] @[simp] lemma vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) : ((v +ᵥ p1) -ᵥ (v +ᵥ p2) : G) = p1 -ᵥ p2 := by rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel'] end comm end add_torsor namespace prod variables {G : Type*} {P : Type*} {G' : Type*} {P' : Type*} [add_group G] [add_group G'] [add_torsor G P] [add_torsor G' P'] instance : add_torsor (G × G') (P × P') := { vadd := λ v p, (v.1 +ᵥ p.1, v.2 +ᵥ p.2), zero_vadd' := λ p, by simp, vadd_assoc' := by simp [add_action.vadd_assoc], vsub := λ p₁ p₂, (p₁.1 -ᵥ p₂.1, p₁.2 -ᵥ p₂.2), nonempty := @prod.nonempty _ _ (add_torsor.nonempty G) (add_torsor.nonempty G'), vsub_vadd' := λ p₁ p₂, show (p₁.1 -ᵥ p₂.1 +ᵥ p₂.1, _) = p₁, by simp, vadd_vsub' := λ v p, show (v.1 +ᵥ p.1 -ᵥ p.1, v.2 +ᵥ p.2 -ᵥ p.2) =v, by simp } @[simp] lemma fst_vadd (v : G × G') (p : P × P') : (v +ᵥ p).1 = v.1 +ᵥ p.1 := rfl @[simp] lemma snd_vadd (v : G × G') (p : P × P') : (v +ᵥ p).2 = v.2 +ᵥ p.2 := rfl @[simp] lemma mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') : (v, v') +ᵥ (p, p') = (v +ᵥ p, v' +ᵥ p') := rfl @[simp] lemma fst_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').1 = p₁.1 -ᵥ p₂.1 := rfl @[simp] lemma snd_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').2 = p₁.2 -ᵥ p₂.2 := rfl @[simp] lemma mk_vsub_mk (p₁ p₂ : P) (p₁' p₂' : P') : ((p₁, p₁') -ᵥ (p₂, p₂') : G × G') = (p₁ -ᵥ p₂, p₁' -ᵥ p₂') := rfl end prod namespace pi universes u v w variables {I : Type u} {fg : I → Type v} [∀ i, add_group (fg i)] {fp : I → Type w} open add_action add_torsor /-- A product of `add_torsor`s is an `add_torsor`. -/ instance [T : ∀ i, add_torsor (fg i) (fp i)] : add_torsor (Π i, fg i) (Π i, fp i) := { vadd := λ g p, λ i, g i +ᵥ p i, zero_vadd' := λ p, funext $ λ i, zero_vadd (fg i) (p i), vadd_assoc' := λ g₁ g₂ p, funext $ λ i, vadd_assoc (fg i) (g₁ i) (g₂ i) (p i), vsub := λ p₁ p₂, λ i, p₁ i -ᵥ p₂ i, nonempty := ⟨λ i, classical.choice (T i).nonempty⟩, vsub_vadd' := λ p₁ p₂, funext $ λ i, vsub_vadd (fg i) (p₁ i) (p₂ i), vadd_vsub' := λ g p, funext $ λ i, vadd_vsub (fg i) (g i) (p i), } /-- Addition in a product of `add_torsor`s. -/ @[simp] lemma vadd_apply [T : ∀ i, add_torsor (fg i) (fp i)] (x : Π i, fg i) (y : Π i, fp i) {i : I} : (x +ᵥ y) i = x i +ᵥ y i := rfl end pi namespace equiv variables (G : Type*) {P : Type*} [add_group G] [add_torsor G P] open add_action add_torsor /-- `v ↦ v +ᵥ p` as an equivalence. -/ def vadd_const (p : P) : G ≃ P := { to_fun := λ v, v +ᵥ p, inv_fun := λ p', p' -ᵥ p, left_inv := λ v, vadd_vsub _ _ _, right_inv := λ p', vsub_vadd _ _ _ } @[simp] lemma coe_vadd_const (p : P) : ⇑(vadd_const G p) = λ v, v+ᵥ p := rfl @[simp] lemma coe_vadd_const_symm (p : P) : ⇑(vadd_const G p).symm = λ p', p' -ᵥ p := rfl variables {G} (P) /-- The permutation given by `p ↦ v +ᵥ p`. -/ def const_vadd (v : G) : equiv.perm P := { to_fun := (+ᵥ) v, inv_fun := (+ᵥ) (-v), left_inv := λ p, by simp [vadd_assoc], right_inv := λ p, by simp [vadd_assoc] } @[simp] lemma coe_const_vadd (v : G) : ⇑(const_vadd P v) = (+ᵥ) v := rfl variable (G) @[simp] lemma const_vadd_zero : const_vadd P (0:G) = 1 := ext $ zero_vadd G variable {G} @[simp] lemma const_vadd_add (v₁ v₂ : G) : const_vadd P (v₁ + v₂) = const_vadd P v₁ * const_vadd P v₂ := ext $ λ p, (vadd_assoc G v₁ v₂ p).symm /-- `equiv.const_vadd` as a homomorphism from `multiplicative G` to `equiv.perm P` -/ def const_vadd_hom : multiplicative G →* equiv.perm P := { to_fun := λ v, const_vadd P v.to_add, map_one' := const_vadd_zero G P, map_mul' := const_vadd_add P } end equiv
2d428211ac66c14b5a34a6da097325f64807af87
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/normed_space/banach_steinhaus.lean
be992f565df5c62849ca8ee6053ba82a65d7cee2
[ "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,389
lean
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import analysis.normed_space.operator_norm import topology.metric_space.baire import topology.algebra.module.basic /-! # The Banach-Steinhaus theorem: Uniform Boundedness Principle Herein we prove the Banach-Steinhaus theorem: any collection of bounded linear maps from a Banach space into a normed space which is pointwise bounded is uniformly bounded. ## TODO For now, we only prove the standard version by appeal to the Baire category theorem. Much more general versions exist (in particular, for maps from barrelled spaces to locally convex spaces), but these are not yet in `mathlib`. -/ open set variables {E F 𝕜 𝕜₂ : Type*} [seminormed_add_comm_group E] [seminormed_add_comm_group F] [nontrivially_normed_field 𝕜] [nontrivially_normed_field 𝕜₂] [normed_space 𝕜 E] [normed_space 𝕜₂ F] {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂] /-- This is the standard Banach-Steinhaus theorem, or Uniform Boundedness Principle. If a family of continuous linear maps from a Banach space into a normed space is pointwise bounded, then the norms of these linear maps are uniformly bounded. -/ theorem banach_steinhaus {ι : Type*} [complete_space E] {g : ι → E →SL[σ₁₂] F} (h : ∀ x, ∃ C, ∀ i, ∥g i x∥ ≤ C) : ∃ C', ∀ i, ∥g i∥ ≤ C' := begin /- sequence of subsets consisting of those `x : E` with norms `∥g i x∥` bounded by `n` -/ let e : ℕ → set E := λ n, (⋂ i : ι, { x : E | ∥g i x∥ ≤ n }), /- each of these sets is closed -/ have hc : ∀ n : ℕ, is_closed (e n), from λ i, is_closed_Inter (λ i, is_closed_le (continuous.norm (g i).cont) continuous_const), /- the union is the entire space; this is where we use `h` -/ have hU : (⋃ n : ℕ, e n) = univ, { refine eq_univ_of_forall (λ x, _), cases h x with C hC, obtain ⟨m, hm⟩ := exists_nat_ge C, exact ⟨e m, mem_range_self m, mem_Inter.mpr (λ i, le_trans (hC i) hm)⟩ }, /- apply the Baire category theorem to conclude that for some `m : ℕ`, `e m` contains some `x` -/ rcases nonempty_interior_of_Union_of_closed hc hU with ⟨m, x, hx⟩, rcases metric.is_open_iff.mp is_open_interior x hx with ⟨ε, ε_pos, hε⟩, obtain ⟨k, hk⟩ := normed_field.exists_one_lt_norm 𝕜, /- show all elements in the ball have norm bounded by `m` after applying any `g i` -/ have real_norm_le : ∀ z : E, z ∈ metric.ball x ε → ∀ i : ι, ∥g i z∥ ≤ m, { intros z hz i, replace hz := mem_Inter.mp (interior_Inter_subset _ (hε hz)) i, apply interior_subset hz }, have εk_pos : 0 < ε / ∥k∥ := div_pos ε_pos (zero_lt_one.trans hk), refine ⟨(m + m : ℕ) / (ε / ∥k∥), λ i, continuous_linear_map.op_norm_le_of_shell ε_pos _ hk _⟩, { exact div_nonneg (nat.cast_nonneg _) εk_pos.le }, intros y le_y y_lt, calc ∥g i y∥ = ∥g i (y + x) - g i x∥ : by rw [continuous_linear_map.map_add, add_sub_cancel] ... ≤ ∥g i (y + x)∥ + ∥g i x∥ : norm_sub_le _ _ ... ≤ m + m : add_le_add (real_norm_le (y + x) (by rwa [add_comm, add_mem_ball_iff_norm]) i) (real_norm_le x (metric.mem_ball_self ε_pos) i) ... = (m + m : ℕ) : (m.cast_add m).symm ... ≤ (m + m : ℕ) * (∥y∥ / (ε / ∥k∥)) : le_mul_of_one_le_right (nat.cast_nonneg _) ((one_le_div $ div_pos ε_pos (zero_lt_one.trans hk)).2 le_y) ... = (m + m : ℕ) / (ε / ∥k∥) * ∥y∥ : (mul_comm_div _ _ _).symm, end open_locale ennreal open ennreal /-- This version of Banach-Steinhaus is stated in terms of suprema of `↑∥⬝∥₊ : ℝ≥0∞` for convenience. -/ theorem banach_steinhaus_supr_nnnorm {ι : Type*} [complete_space E] {g : ι → E →SL[σ₁₂] F} (h : ∀ x, (⨆ i, ↑∥g i x∥₊) < ∞) : (⨆ i, ↑∥g i∥₊) < ∞ := begin have h' : ∀ x : E, ∃ C : ℝ, ∀ i : ι, ∥g i x∥ ≤ C, { intro x, rcases lt_iff_exists_coe.mp (h x) with ⟨p, hp₁, _⟩, refine ⟨p, (λ i, _)⟩, exact_mod_cast calc (∥g i x∥₊ : ℝ≥0∞) ≤ ⨆ j, ∥g j x∥₊ : le_supr _ i ... = p : hp₁ }, cases banach_steinhaus h' with C' hC', refine (supr_le $ λ i, _).trans_lt (@coe_lt_top C'.to_nnreal), rw ←norm_to_nnreal, exact coe_mono (real.to_nnreal_le_to_nnreal $ hC' i), end open_locale topological_space open filter /-- Given a *sequence* of continuous linear maps which converges pointwise and for which the domain is complete, the Banach-Steinhaus theorem is used to guarantee that the limit map is a *continuous* linear map as well. -/ def continuous_linear_map_of_tendsto [complete_space E] [t2_space F] (g : ℕ → E →SL[σ₁₂] F) {f : E → F} (h : tendsto (λ n x, g n x) at_top (𝓝 f)) : E →SL[σ₁₂] F := { to_fun := f, map_add' := (linear_map_of_tendsto _ _ h).map_add', map_smul' := (linear_map_of_tendsto _ _ h).map_smul', cont := begin /- show that the maps are pointwise bounded and apply `banach_steinhaus`-/ have h_point_bdd : ∀ x : E, ∃ C : ℝ, ∀ n : ℕ, ∥g n x∥ ≤ C, { intro x, rcases cauchy_seq_bdd (tendsto_pi_nhds.mp h x).cauchy_seq with ⟨C, C_pos, hC⟩, refine ⟨C + ∥g 0 x∥, (λ n, _)⟩, simp_rw dist_eq_norm at hC, calc ∥g n x∥ ≤ ∥g 0 x∥ + ∥g n x - g 0 x∥ : norm_le_insert' _ _ ... ≤ C + ∥g 0 x∥ : by linarith [hC n 0] }, cases banach_steinhaus h_point_bdd with C' hC', /- show the uniform bound from `banach_steinhaus` is a norm bound of the limit map by allowing "an `ε` of room." -/ refine add_monoid_hom_class.continuous_of_bound (linear_map_of_tendsto _ _ h) C' (λ x, le_of_forall_pos_lt_add (λ ε ε_pos, _)), cases metric.tendsto_at_top.mp (tendsto_pi_nhds.mp h x) ε ε_pos with n hn, have lt_ε : ∥g n x - f x∥ < ε, by {rw ←dist_eq_norm, exact hn n (le_refl n)}, calc ∥f x∥ ≤ ∥g n x∥ + ∥g n x - f x∥ : norm_le_insert _ _ ... < ∥g n∥ * ∥x∥ + ε : by linarith [lt_ε, (g n).le_op_norm x] ... ≤ C' * ∥x∥ + ε : by nlinarith [hC' n, norm_nonneg x], end }
a00436e2692639f545272a5c44e6f255eb4e4ac3
737dc4b96c97368cb66b925eeea3ab633ec3d702
/src/Init/Data/Nat/Div.lean
ef69149895147a35152afc4dbb689cbeb9eb0a48
[ "Apache-2.0" ]
permissive
Bioye97/lean4
1ace34638efd9913dc5991443777b01a08983289
bc3900cbb9adda83eed7e6affeaade7cfd07716d
refs/heads/master
1,690,589,820,211
1,631,051,000,000
1,631,067,598,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,833
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.WF import Init.Data.Nat.Basic namespace Nat private def div_rec_lemma {x y : Nat} : 0 < y ∧ y ≤ x → x - y < x := fun ⟨ypos, ylex⟩ => sub_lt (Nat.lt_of_lt_of_le ypos ylex) ypos private def div.F (x : Nat) (f : ∀ x₁, x₁ < x → Nat → Nat) (y : Nat) : Nat := if h : 0 < y ∧ y ≤ x then f (x - y) (div_rec_lemma h) y + 1 else zero @[extern "lean_nat_div"] protected def div (a b : @& Nat) : Nat := WellFounded.fix lt_wf div.F a b instance : Div Nat := ⟨Nat.div⟩ private theorem div_eq_aux (x y : Nat) : x / y = if h : 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 := congrFun (WellFounded.fix_eq lt_wf div.F x) y theorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 := dif_eq_if (0 < y ∧ y ≤ x) ((x - y) / y + 1) 0 ▸ div_eq_aux x y private theorem div.induction.F.{u} (C : Nat → Nat → Sort u) (ind : ∀ x y, 0 < y ∧ y ≤ x → C (x - y) y → C x y) (base : ∀ x y, ¬(0 < y ∧ y ≤ x) → C x y) (x : Nat) (f : ∀ (x₁ : Nat), x₁ < x → ∀ (y : Nat), C x₁ y) (y : Nat) : C x y := if h : 0 < y ∧ y ≤ x then ind x y h (f (x - y) (div_rec_lemma h) y) else base x y h theorem div.inductionOn.{u} {motive : Nat → Nat → Sort u} (x y : Nat) (ind : ∀ x y, 0 < y ∧ y ≤ x → motive (x - y) y → motive x y) (base : ∀ x y, ¬(0 < y ∧ y ≤ x) → motive x y) : motive x y := WellFounded.fix Nat.lt_wf (div.induction.F motive ind base) x y private def mod.F (x : Nat) (f : ∀ x₁, x₁ < x → Nat → Nat) (y : Nat) : Nat := if h : 0 < y ∧ y ≤ x then f (x - y) (div_rec_lemma h) y else x @[extern "lean_nat_mod"] protected def mod (a b : @& Nat) : Nat := WellFounded.fix lt_wf mod.F a b instance : Mod Nat := ⟨Nat.mod⟩ private theorem mod_eq_aux (x y : Nat) : x % y = if h : 0 < y ∧ y ≤ x then (x - y) % y else x := congrFun (WellFounded.fix_eq lt_wf mod.F x) y theorem mod_eq (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x := dif_eq_if (0 < y ∧ y ≤ x) ((x - y) % y) x ▸ mod_eq_aux x y theorem mod.inductionOn.{u} {motive : Nat → Nat → Sort u} (x y : Nat) (ind : ∀ x y, 0 < y ∧ y ≤ x → motive (x - y) y → motive x y) (base : ∀ x y, ¬(0 < y ∧ y ≤ x) → motive x y) : motive x y := div.inductionOn x y ind base theorem mod_zero (a : Nat) : a % 0 = a := have : (if 0 < 0 ∧ 0 ≤ a then (a - 0) % 0 else a) = a := have h : ¬ (0 < 0 ∧ 0 ≤ a) := fun ⟨h₁, _⟩ => absurd h₁ (Nat.lt_irrefl _) if_neg h (mod_eq a 0).symm ▸ this theorem mod_eq_of_lt {a b : Nat} (h : a < b) : a % b = a := have : (if 0 < b ∧ b ≤ a then (a - b) % b else a) = a := have h' : ¬(0 < b ∧ b ≤ a) := fun ⟨_, h₁⟩ => absurd h₁ (Nat.not_le_of_gt h) if_neg h' (mod_eq a b).symm ▸ this theorem mod_eq_sub_mod {a b : Nat} (h : a ≥ b) : a % b = (a - b) % b := match eq_zero_or_pos b with | Or.inl h₁ => h₁.symm ▸ (Nat.sub_zero a).symm ▸ rfl | Or.inr h₁ => (mod_eq a b).symm ▸ if_pos ⟨h₁, h⟩ theorem mod_lt (x : Nat) {y : Nat} : y > 0 → x % y < y := by induction x, y using mod.inductionOn with | base x y h₁ => intro h₂ have h₁ : ¬ 0 < y ∨ ¬ y ≤ x := Iff.mp (Decidable.not_and_iff_or_not _ _) h₁ match h₁ with | Or.inl h₁ => exact absurd h₂ h₁ | Or.inr h₁ => have hgt : y > x := gt_of_not_le h₁ have heq : x % y = x := mod_eq_of_lt hgt rw [← heq] at hgt exact hgt | ind x y h h₂ => intro h₃ have ⟨_, h₁⟩ := h rw [mod_eq_sub_mod h₁] exact h₂ h₃ theorem mod_le (x y : Nat) : x % y ≤ x := by match Nat.lt_or_ge x y with | Or.inl h₁ => rw [mod_eq_of_lt h₁]; apply Nat.le_refl | Or.inr h₁ => match eq_zero_or_pos y with | Or.inl h₂ => rw [h₂, Nat.mod_zero x]; apply Nat.le_refl | Or.inr h₂ => exact Nat.le_trans (Nat.le_of_lt (mod_lt _ h₂)) h₁ @[simp] theorem zero_mod (b : Nat) : 0 % b = 0 := by rw [mod_eq] have : ¬ (0 < b ∧ b ≤ 0) := by intro ⟨h₁, h₂⟩ exact absurd (Nat.lt_of_lt_of_le h₁ h₂) (Nat.lt_irrefl 0) simp [this] @[simp] theorem mod_self (n : Nat) : n % n = 0 := by rw [mod_eq_sub_mod (Nat.le_refl _), Nat.sub_self, zero_mod] theorem mod_one (x : Nat) : x % 1 = 0 := by have h : x % 1 < 1 := mod_lt x (by decide) have : (y : Nat) → y < 1 → y = 0 := by intro y cases y with | zero => intro h; rfl | succ y => intro h; apply absurd (Nat.lt_of_succ_lt_succ h) (Nat.not_lt_zero y) exact this _ h end Nat
acc6d06e2ccb652350ad82e515a723ed727431cc
22b1ea9c0e32dd3b69f246615ad2eeb0fc1f0c6d
/esp_metrique.lean
ffcd9fc81514ef3f0ff95194ec51b12b1bf2d81a
[]
no_license
FredericLeRoux/LEAN_ESPACES_METRIQUES
fd8dceb718e9911ec8f23d8a009eadc63dae4867
ebab6c37d88988a87b4310b0347db98c2245b902
refs/heads/master
1,601,209,881,189
1,586,336,283,000
1,586,336,283,000
226,517,402
0
1
null
1,575,726,004,000
1,575,725,118,000
null
UTF-8
Lean
false
false
23,378
lean
import tactic import data.real.basic import data.set ------------ -- ESSAIS -- ------------ open set ----------- -- DEBUT -- ----------- /-- Une structure d'espace métrique sur un type X -/ class espace_metrique (X : Type) := (dist : X → X → ℝ) (dist_pos : ∀ x y, dist x y ≥ 0) (sep : ∀ x y, dist x y = 0 ↔ x = y) (sym : ∀ x y, dist x y = dist y x) (triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) open espace_metrique /-- Fonction distance avec le type en argument explicite -/ def dist' (X : Type) [espace_metrique X] : X → X → ℝ := λ x y, dist x y notation `d` := dist notation `d_[` X `]` := dist' X ---------------------------------------------------- section fondements ---------------------------------------------------- variables {X : Type} [espace_metrique X] @[simp] lemma dist_sym (x:X) (y:X) : d x y = d y x := sym x y @[simp] lemma dist_x_x_eq_zero (x:X) : d x x = 0 := (sep x x).2 rfl lemma dist_str_pos {x:X} {y:X} : x ≠ y → d x y > 0 := begin contrapose!, intro d_neg, have d_pos : d x y ≥ 0, from dist_pos x y, have d_zero : d x y = 0, from antisymm d_neg d_pos, exact iff.mp (sep x y) d_zero end /-- `boule x r` est la boule ouverte de centre `x` et de rayon `r` -/ def boule (x : X) (r : ℝ) := {y | dist x y < r} /-- appartenir à une boule équivaut à une inégalité -/ @[simp] lemma mem_boule (x : X) (r : ℝ) (y : X) : y ∈ boule x r ↔ dist x y < r := iff.rfl /-- Une boule de rayon >0 contient son centre --/ lemma centre_mem_boule (x : X) (r : ℝ) : r > 0 → x ∈ boule x r := begin intro r_pos, simpa [boule] -- simplifie et utilise l'hypothèse end /-- Une partie d'un espace métrique `X` est ouverte si elle contient une boule ouverte de rayon strictement positif autour de chacun de ses points. -/ def ouvert (A : set X) := ∀ x ∈ A, ∃ r > 0, boule x r ⊆ A /-- Les boules sont ouvertes -/ lemma boule_est_ouverte : ∀ x : X, ∀ r > 0, ouvert (boule x r) := begin intros x r r_pos y y_in, -- on déroule les définitions, -- on se retrouve avec un point y dans la boule -- de centre x et de rayon r, et on cherche une boule autour de y qui soit incluse -- dans boule x r set ε := r - d x y with hε, use ε, -- le rayon candidat -- OBSOLETE rw exists_prop, split, { -- La ligne suivante peut être remplacée par n'importe laquelle des trois lignes qui la suivent simp [boule] at y_in, --change d x y < r at y_in, --rw mem_boule at y_in, --unfold boule at y_in, rw set.mem_set_of_eq at y_in, linarith only [hε, y_in]}, -- le rayon est bien strictement positif { -- La ligne suivante est optionnelle, elle sert à expliciter le but -- change ∀ z, z ∈ boule y (r - d x y) → z ∈ boule x r, intros z z_in, rw mem_boule at *, have clef : d x z ≤ d x y + d y z, from triangle x y z, linarith only [clef, z_in, y_in, hε]} -- et l'inégalité triangulaire permet de montrer l'inclusion des boules end -- Lemme de théorie des ensembles - finalement non utilisé lemma inclusion_transitive {Y : Type} {A B C : set Y} : A ⊆ B → B ⊆ C → A ⊆ C := begin intros AB BC a a_app_A, exact BC (AB a_app_A), end /-- Une union d'ouverts d'un espace métrique est un ouvert -/ lemma union_ouverts_est_ouvert (I : set (set X)) : (∀ O ∈ I, ouvert O) → ouvert (⋃₀ I) := begin -- Supposons que tous les O dans I sont ouverts. intro O_ouverts, -- Soit x un point d'un des O dans I rintro x ⟨O, O_app_I, x_app_O⟩, -- Comme O est ouvert, il existe r > 0 tel que B(x, r) ⊆ O obtain ⟨r, r_positif, boule_dans_O⟩ : ∃ r > 0, boule x r ⊆ O, from (O_ouverts O) O_app_I x x_app_O, -- Montrons que ce r convient use [r, r_positif], -- Puisque B(x, r) ⊆ O, il suffit de montrer que O ⊆ ⋃₀ I transitivity O, assumption, -- Or O est dans I. exact subset_sUnion_of_mem O_app_I end -- ** variante en λ-calcul - non utilisé lemma union_ouverts_est_ouvert' (I : set (set X)) : (∀ O ∈ I, ouvert O) → ouvert (⋃₀ I) := assume O_ouverts x ⟨O, O_app_I, x_app_O⟩, let ⟨r, r_positif, boule_dans_O⟩ := O_ouverts O O_app_I x x_app_O in ⟨r, r_positif, subset.trans boule_dans_O (subset_sUnion_of_mem O_app_I)⟩ /-- L'intersection de deux ouverts est un ouvert -/ lemma intersection_deux_ouverts_est_ouvert : ∀ O₁ O₂ : set X, ouvert O₁ → ouvert O₂ → ouvert (O₁ ∩ O₂) := begin -- Soit x un point dans l'intersection, rintro O₁ O₂ ouvert_O₁ ouvert_O₂ x ⟨x_app_O₁,x_app_O₂⟩, -- le fait que O₁ et O₂ soient ouverts fournis deux nombres positifs obtain ⟨r₁,r₁_pos,boule_dans_O₁⟩ : ∃ r₁>0, boule x r₁ ⊆ O₁, from ouvert_O₁ x x_app_O₁, obtain ⟨r₂,r₂_pos,boule_dans_O₂⟩ : ∃ r₂>0, boule x r₂ ⊆ O₂, from ouvert_O₂ x x_app_O₂, -- Montrons que le minimum r des deux convient use min r₁ r₂, -- OBSOLETE rw exists_prop, -- Il est bien positif split, by exact lt_min r₁_pos r₂_pos, -- les quatre lignes qui précèdent peuvent être remplacées par : -- use [min r₁ r₂,lt_min r₁_pos r₂_pos] -- Prenons un y dans la boule de rayon r intros y y_app_boule, -- vu le choix de r, on a d x y < r₁ et d x y < r₂ simp [boule] at y_app_boule, -- donc c'est bon split ; tautology -- FIN plus compliquée : -- simp [boule] at y_app_boule, -- rcases y_app_boule with ⟨ineg_1,ineg_2⟩, -- -- il est dans O₁ et dans O₂ -- have y_O₁ : y ∈ O₁, from boule_dans_O₁ ineg_1, -- have y_O₂ : y ∈ O₂, from boule_dans_O₂ ineg_2, -- -- donc dans l'intersection, comme voulu. -- exact and.intro y_O₁ y_O₂, end /-- L'espace total est ouvert -/ lemma total_ouvert : ouvert (univ : set X) := begin intros x hx, use 1, -- OBSOLETE rw exists_prop, split, exact zero_lt_one, exact subset_univ (boule x 1), end /-- L'intersection d'un nombre fini d'ouverts est un ouvert -/ --lemma intersection_ouverts_est_ouvert' --(I : set (set X)) : (finite I) (∀ O ∈ I, ouvert O) → ouvert (⋂₀ I) := --begin --tactic.unfreeze_local_instances, --rcases _inst_2 with ⟨Liste, Liste_exhaustive⟩, --sorry --end --{s : set β} {f : β → set α} (hs : finite s) : --variables (β : Type) --lemma intersection_ouverts_est_ouvert {s: set β} {O : β → set X} (hs: finite s) : -- (∀ i, ouvert (O i)) → ouvert (⋂ i, O i) := --begin -- set.finite.induction_on hs (sorry) (sorry) -- (λ _, by rw bInter_empty; exact total_ouvert) -- (λ a s has hs ih h, by rw bInter_insert; exact -- is_open_inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi)))) --end --lemma is_open_sInter {s : set (set X)} (hs : finite s) : (∀t ∈ s, ouvert t) → ouvert (⋂₀ s) := lemma vide_ouvert : ouvert (∅ : set X) := begin intros x x_in, exfalso, exact x_in, end lemma vide_ouvert' : ouvert (∅ : set X) := assume x x_in, false.elim x_in /-- L'intérieur d'une partie de X est la réunion des ouverts qu'elle contient -/ def Int (E : set X) := ⋃₀ {O : set X | ouvert O ∧ O ⊆ E} /-- Caractérisation métrique de l'intérieur -/ @[simp] lemma interieur_metrique {E : set X} {x : X} : x ∈ Int E ↔ ∃ r>0, boule x r ⊆ E := begin split, -- Pour le sens direct, supposons que x est dans l'intérieur de E intro x_dans_Int, -- Par définition de l'intérieur, il existe un ouvert O inclus dans E et contenant x rcases x_dans_Int with ⟨O, ⟨ouvert_O,O_sub_E⟩ , x_app_O⟩, -- L'ouvert O contient une boule autour de x obtain ⟨r,r_pos,boule_dans_O⟩ : ∃ r>0, boule x r ⊆ O, from ouvert_O x x_app_O, -- Cette boule convient use [r, r_pos], -- puisqu'elle est incluse dans O qui est inclus dans E transitivity O, assumption, assumption, -- VARIANTE : exact subset.trans boule_dans_O O_sub_E, -- On peut aussi écrire : tauto, -- Pour l'autre sens, soit x le centre d'une boule incluse dans E. rintros ⟨ r,r_pos, boule_dans_E⟩, -- Cette boule est un ouvert have ouvert_boule, from boule_est_ouverte x r r_pos, -- et elle contient x have x_mem_boule, from centre_mem_boule x r r_pos, -- donc x est dans l'intérieur de E use boule x r, repeat { split }, assumption, assumption, assumption, -- VARIANTE FIN PLUS COMPLIQUEE : -- la boule est donc incluse dans l'intérieur de E -- let I := {O : set X | ouvert O ∧ O ⊆ E}, -- have boule_mem_I : (boule x r) ∈ I, -- exact and.intro ouvert_boule boule_dans_E, -- have boule_inc_Int : boule x r ⊆ Int E, from subset_sUnion_of_mem boule_mem_I, -- -- qui contient donc x, centre d'une boule incluse dans Int E -- exact boule_inc_Int (centre_mem_boule x r r_pos), end -- Variante moins pratique (?) lemma interieur_metrique' {E : set X} : Int E = { x : X | ∃ r>0, boule x r ⊆ E } := begin -- Nous raisonnons par double inclusion apply subset.antisymm, -- Soit x dans l'intérieur de E intros x x_dans_Int, simp, -- Par définition de l'intérieur, il existe un ouvert O inclus dans E et contenant x rcases x_dans_Int with ⟨O, ⟨ouvert_O,O_sub_E⟩ , x_app_O⟩, -- L'ouvert O contient une boule autour de x obtain ⟨r,r_pos,boule_dans_O⟩ : ∃ r>0, boule x r ⊆ O, from ouvert_O x x_app_O, -- Cette boule convient use [r, r_pos], -- puisqu'elle est incluse dans O qui est inclus dans E transitivity O, assumption, assumption, -- VARIANTE : exact subset.trans boule_dans_O O_sub_E, -- On peut aussi écrire : tauto, -- Pour l'autre sens, soit x le centre d'une boule incluse dans E. rintros x ⟨ r,r_pos, boule_dans_E⟩, -- Cette boule est un ouvert have ouvert_boule, from boule_est_ouverte x r r_pos, -- et elle contient x have x_mem_boule, from centre_mem_boule x r r_pos, -- donc x est dans l'intérieur de E use boule x r, repeat { split }, assumption, assumption, assumption, -- VARIANTE FIN PLUS COMPLIQUEE : -- la boule est donc incluse dans l'intérieur de E -- let I := {O : set X | ouvert O ∧ O ⊆ E}, -- have boule_mem_I : (boule x r) ∈ I, -- exact and.intro ouvert_boule boule_dans_E, -- have boule_inc_Int : boule x r ⊆ Int E, from subset_sUnion_of_mem boule_mem_I, -- -- qui contient donc x, centre d'une boule incluse dans Int E -- exact boule_inc_Int (centre_mem_boule x r r_pos), end def est_voisinage (V : set X) (x : X) := x ∈ Int V -- caractérisation d'un voisinage en termes d'ouverts ? -- caractérisation en terme de boules ? end fondements ---------------------------------------------------- section continuite ---------------------------------------------------- variables {X Y : Type} [espace_metrique X] [espace_metrique Y] -- dans la définition suivante les `d_[X]` et `d_[Y]` sont cosmétiques, `d` seul marche aussi bien def continue_en (f : X → Y) (x₀ : X) := ∀ ε > 0, ∃ δ > 0, ∀ x, d_[X] x₀ x < δ → d_[Y] (f x₀) (f x) < ε def continue (f:X → Y) := ∀ x : X, continue_en f x -- Notations f continue, f continue_au_point x -- caractérisation topologique (ponctuelle, globale) lemma continuite_ouverts (f:X → Y): continue f ↔ ( ∀O, ouvert O → ouvert (f ⁻¹' O) ) := begin -- On raisonne par double implication split, { -- Supposons donc que f vérifie la définition métrique de la continuité -- Soit O un ouvert à l'arrivé, il s'agit de voir que son image réciproque est ouverte -- SOit x un point de l'image réciproque, on cherche un rayon intros cont O O_ouvert x x_dans_reciproque, -- c'est-à-dire tel que f(x) ∈ O change f x ∈ O at x_dans_reciproque, -- Cette ligne est purement psychologique, on peut la retirer -- Puisque O est ouvert, il contient une boule de rayon ε autour de f(x) obtain ⟨ε, ε_positif, boule_dans_O⟩ : ∃ ε > 0, boule (f x) ε ⊆ O, from O_ouvert (f x) x_dans_reciproque, -- L'hypothèse de continuité fournit un δ >0 rcases (cont x) ε ε_positif with ⟨δ , δ_positif, H⟩, -- Montrons que la boule de rayon δ est dans l'image réciproque use [δ, δ_positif], -- pour ceci on prend un point x' dans la boule intros x' hx', -- il s'agit de voir que son image est dans O change f x' ∈ O, -- encore une ligne purement psychologique, Lean n'en a pas besoin -- Pour cela il suffit de voir que f(x') est dans la boule de centre f(x) et de rayon ε, -- puisqu'elle est incluse dans O suffices hh : f x' ∈ boule (f x) ε, from boule_dans_O hh, -- ce qui est donné par la propriété de δ issue de la continuité exact H x' hx' }, { -- Pour l'autre direction, on suppose que l'image réciproque de tout ouvert est un ouvert, -- on prend un point x et un ε > 0 rintros H x ε ε_positif, -- La boule de centre x et de rayon epsilon est un ouvert de Y, have boule_ouverte, from boule_est_ouverte (f x) ε ε_positif, -- donc par hypothèse son image réciproque est un ouvert de X have reciproque_ouvert, from H (boule (f x) ε) boule_ouverte, -- or x appartient à cette image réciproque have x_dans_reciproque: x ∈ f ⁻¹' boule (f x) ε, simpa [boule], -- Il existe donc une boule autour de x incluse dans l'image réciproque de la première boule obtain ⟨δ, δ_positif, H⟩: ∃ δ >0, boule x δ ⊆ f ⁻¹' boule (f x) ε , from reciproque_ouvert x x_dans_reciproque, -- montrons que le rayon de cette boule satisfait la définition métrique de la continuité use [δ , δ_positif], -- On considère donc un point x' tel que d(x,x') < δ intros x' hx', -- Autrement dit, x' est dans la boule B(x,δ), change x' ∈ boule x δ at hx', -- encore une ligne pour rien -- donc son image est dans la première boule exact H hx' } end variables {Z : Type} [espace_metrique Z] /-- La composée de deux applications continues est continue-/ lemma composition_continue (f : X → Y) (g : Y → Z) : (continue f) → (continue g) → continue (g ∘ f) := begin -- Supposons que f et g sont continues intros f_cont g_cont, -- Nous allons utiliser la caractérisation topologique pour montrer la continuité de g ∘ f : rw continuite_ouverts, -- On considère un ouvert O de Z intros O O_ouvert, -- La caractérisation topologique de la continuité de g nous dit que g ⁻¹' O est un ouvert de Y, have ouvert1 : ouvert (g ⁻¹' O), from (((iff.elim_left (continuite_ouverts g)) g_cont) O) O_ouvert, -- La caractérisation topologique de la continuité de f nous dit que f ⁻¹' (g ⁻¹' O) est un ouvert de X, exact (((iff.elim_left (continuite_ouverts f)) f_cont) (g ⁻¹' O)) ouvert1, -- et il est égal à (g ∘ f) ⁻¹' O, CQFD end -- A FAIRE : caractérisation topologique de la continuité ponctuelle par les voisinages, -- et composition ponctuelle def lipschitzienne (k:ℝ) (f: X → Y) := ∀ x₀ x₁ , d_[Y] (f x₀) (f x₁) ≤ ( k * d_[X] x₀ x₁ ) -- A FAIRE : lipschitzien implique continu end continuite ---------------------------------------------------- section fermes ---------------------------------------------------- variables {X:Type} [espace_metrique X] def ferme (F : set X) := ouvert (- F) -- A FAIRE : intersection, union /-- L'adhérence d'une partie de X est l'intersection des fermés qui la contienne -/ def Adh (E : set X) := sInter {F : set X | ferme F ∧ E ⊆ F} -- adhérence et intérieur par passage au complémentaire /-- Caractérisation métrique de l'adhérence -/ @[simp] lemma adherence_metrique {E : set X} {x : X} : x ∈ Adh E ↔ ∀ r>0, boule x r ∩ E ≠ ∅ := begin sorry end end fermes ---------------------------------------------------- section suites ---------------------------------------------------- variables {X:Type} [espace_metrique X] -- variable E : set X -- variable x : E -- #print x def limite_suite (x: ℕ → X) (l : X) := ∀ ε > 0, ∃ N, ∀ n ≥ N, ((d l (x n)) < ε) -- On va voir besoin de "0<2" dans ℝ lemma zero_pp_2 : (0:real) < 2 := begin linarith only [zero_lt_one] end #print zero_pp_2 -- Waou ! open classical local attribute [instance] prop_decidable lemma unicite_limite {x: ℕ → X} {l₁ : X} {l₂ : X} : (limite_suite x l₁) → (limite_suite x l₂) → l₁ = l₂ := begin -- Supposons que la suite (x_n) converge à la fois vers l₁ et l₂ intros H₁ H₂, -- Raisonnons par l'absurde, en supposant l₁ ≠ l₂ by_contradiction lim_non_eg, -- Alors d(l₁, l₂) >0 have dist_limites_pos : 0 < d l₁ l₂, from dist_str_pos lim_non_eg, -- Appelons ε la moitié de cette distance, qui est donc aussi un nombre positif let ε := (d l₁ l₂)/2, have ε_pos : 0 < ε, from div_pos dist_limites_pos zero_pp_2, -- et appliquons la définition de convergence à nos deux limites rcases H₁ ε ε_pos with ⟨ N₁ , HN₁ ⟩, rcases H₂ ε ε_pos with ⟨ N₂ , HN₂ ⟩, -- On obtient deux rangs N₁, N₂, dont on prend le maximum let N := max N₁ N₂, -- La définition de convergence nous donne les deux inégalités d(l₁,x_N )< ε et d(l₂,x_N) < ε have I₁ : d l₁ (x N) < ε, from HN₁ N (le_max_left N₁ N₂), have I₂ : d l₂ (x N) < ε, from HN₂ N (le_max_right N₁ N₂), -- En les combinant à l'inégalité triangulaire entre les trois points impliqué, -- on obtient d(l₁,l₂) < d(l₁,l₂), have egal : d l₁ l₂ = 2 * ε , from eq.symm (@mul_div_cancel' ℝ real.field (d l₁ l₂) 2 two_ne_zero), have Ineg : d l₁ l₂ < d l₁ l₂, from calc d l₁ l₂ ≤ d l₁ (x N) + d (x N) l₂ : (triangle l₁ (x N) l₂) ... ≤ d l₁ (x N) + d l₂ (x N) : by simp -- Linarith se débrouille sans les 3 lignes suivante : -- ... < ε + ε : by linarith -- ... = 2 * ε : eq.symm (two_mul ε) -- ... = d l₁ l₂ : by rw egal, ... < d l₁ l₂ : by linarith, -- ce qui donne la contradiction recherchée. linarith only [Ineg] end -- nom des lemmes trouvés avec la tactique library_search example (ε : ℝ) : 2*ε = ε + ε := two_mul ε example (a : ℝ) (b : ℝ) (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a/b := div_pos h₁ h₂ example (a : ℝ) (b : ℝ) (H : a ≠ 0) : a * (b/a) = b := mul_div_cancel' b H example (a : ℝ) (b : ℝ) (h₁ : a = b) : b = a := eq.symm h₁ example (a : ℝ) (h₁ : a < a) : false := by linarith example : @has_lt.lt real real.has_lt 0 1 := zero_lt_one -- Variante utilisant le lemme suivant : lemma pp_que_tout_pos (l : real) : (∀ ε>0, l ≤ ε) → l ≤ 0 := begin contrapose!, intro H, use l/2, split, linarith, linarith end lemma unicite_limite' {x: ℕ → X} {l₁ : X} {l₂ : X} : (limite_suite x l₁) → (limite_suite x l₂) → l₁ = l₂ := begin intros H1 H2, have H : (∀ ε>0, d l₁ l₂ ≤ ε), intros ε ε_pos, have εs2_pos : ε/2>0, by linarith, have H1', from H1 _ εs2_pos, cases H1' with N₁ PN₁ , have H2', from H2 _ εs2_pos, cases H2' with N₂ PN₂, have HN₁ : max N₁ N₂ ≥ N₁ , by exact le_max_left N₁ N₂, -- library_search have HN₂ : max N₁ N₂ ≥ N₂ , by exact le_max_right N₁ N₂, -- library_search specialize PN₁ _ HN₁ , specialize PN₂ _ HN₂ , have T, from triangle l₁ (x (max N₁ N₂)) l₂, have Dsym, from sym l₂ (x (max N₁ N₂)), exact calc d l₁ l₂ ≤ d l₁ (x (max N₁ N₂)) + d (x (max N₁ N₂)) l₂ : T ... ≤ ε : by linarith, have D , from pp_que_tout_pos (d l₁ l₂) H, -- : (d l₁ l₂) ≤ 0 have D' , from dist_pos l₁ l₂, have D'' , by exact le_antisymm D D', -- d l₁ l₂ =0 exact (sep l₁ l₂).1 D'' end lemma nonvide_ssi_existe_element (A : set X) : A ≠ ∅ ↔ ∃ a : X, a ∈ A := ne_empty_iff_nonempty lemma essai (a : ℝ) (b : ℝ) (c : ℝ) (H1 : a > b) (H2 : b > c) : a > c := begin transitivity b, exact H1, exact H2, end lemma inv_inv2 {ε : ℝ} (ε_nz : ε ≠ 0) : ε = 1 / (1 / ε) := begin have inv_ε_nz : (1/ε) ≠ 0, from one_div_ne_zero ε_nz, have H : ε * (1/ε) = 1, from mul_div_cancel' 1 ε_nz, exact (eq_div_iff_mul_eq ε 1 inv_ε_nz).2 H, end -- critère séquentiel d'adhérence (construire une suite) lemma critere_sequentiel_adherence (E : set X) (l : X) : l ∈ Adh E ↔ ∃ x : ℕ → X, (∀ n, x n ∈ E) ∧ (limite_suite x l) := begin split, -- Pour le sens direct, on prend l dans l'adhérence de E -- et on cherche à construire une suite d'éléments de E qui converge vers l intros Hl, -- Comment éviter d'avoir à introduire cette grosse propriété intermédiaire ? have H1 : ∀ n : ℕ, ∃ x : X, d l x < 1/(n+1) ∧ x ∈ E, intro n, -- have H2, from H 1/(n+1), -- exact adherence_metrique.mpr l Hl, sorry, -- H1 permet de définir une suite (x_n) qui va convenir choose x H using H1, use x, split, -- La suite est bien à valeur dans E, exact λ n, ((H n).2), -- Reste à montrer qu'elle converge vers l intros ε ε_pos, have HN, from exists_nat_gt (1 / ε), cases HN with N HN, use N, intros n Hn, specialize H n, cases H with Hutile Hinutile, have Ineg : N < n+1, by linarith, have Ineg2 : ↑n+(1:ℝ) > ↑N, by exact_mod_cast Ineg, have Ineg3 : ↑n+1 > 1/ε, begin transitivity ↑N, exact Ineg2, exact HN, end, have inv_ε_pos : (1/ε)>0, from one_div_pos_of_pos ε_pos, have Ineg4, by exact one_div_lt_one_div_of_lt inv_ε_pos Ineg3, transitivity 1 / (↑n + 1:ℝ), exact Hutile, have NZ : ε ≠ 0, by linarith, -- have inv_inv_ε : ε = 1/(1/ε), by inv_inv2 NZ, sorry, -- Pour l'autre direction, on suppose l'existence d'une suite -- d'éléments de E convergeant vers l rintro ⟨x,H1,H2⟩, -- On utilise la caractérisation métrique de l'adhérence rw adherence_metrique, rintro r Hr, rw limite_suite at H2, have H, from (H2 r) Hr, -- obtain ⟨N, H3N⟩ : ℕ ,(∀ (n : ℕ), n ≥ N → d l (x n) < r) , from (H2 r) Hr, cases H with N HN, have HNN: N ≥ N, by linarith, specialize HN N HNN, rw← mem_boule at HN, specialize H1 N, rw ne_empty_iff_nonempty, use x N, exact and.intro HN H1 end example (a : ℝ) (b : ℝ) (a_pos : a>0) (a_inf_b : a <b) : 1/a > 1/b := begin exact one_div_lt_one_div_of_lt a_pos a_inf_b end example (x : ℝ) (H : x ≠ 0) : x * (1/x) = 1 := mul_div_cancel' 1 H example (x : ℝ) (y : ℝ) (H : x ≠ 0) : ( y = 1/x ) ↔ ( y * x = 1 ) := eq_div_iff_mul_eq y 1 H -- critère séquentiel de fermeture -- critère séquentiel de continuité end suites ---------------------------------------------------- section sous_espaces_metriques ---------------------------------------------------- ---------------------------------------------------- section distances_equivalentes ---------------------------------------------------- ---------------------------------------------------- section espaces_metriques_produits ---------------------------------------------------- ---------------------------------------------------- section espaces_de_fonctions ----------------------------------------------------
25f2a5a760788f7ae6c766408ff699a9ba321179
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/order/boolean_algebra_auto.lean
44880931d24ce766d844cfa5ce684b064d4744f9
[]
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
6,664
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 Type class hierarchy for Boolean algebras. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.bounded_lattice import Mathlib.PostPort universes u_1 l u v namespace Mathlib /-- Set / lattice complement -/ class has_compl (α : Type u_1) where compl : α → α postfix:0 "ᶜ" => Mathlib.has_compl.compl /-- A boolean algebra is a bounded distributive lattice with a complementation operation `-` such that `x ⊓ - x = ⊥` and `x ⊔ - x = ⊤`. This is a generalization of (classical) logic of propositions, or the powerset lattice. -/ class boolean_algebra (α : Type u_1) extends has_sdiff α, has_compl α, bounded_distrib_lattice α where inf_compl_le_bot : ∀ (x : α), x ⊓ (xᶜ) ≤ ⊥ top_le_sup_compl : ∀ (x : α), ⊤ ≤ x ⊔ (xᶜ) sdiff_eq : ∀ (x y : α), x \ y = x ⊓ (yᶜ) @[simp] theorem inf_compl_eq_bot {α : Type u} {x : α} [boolean_algebra α] : x ⊓ (xᶜ) = ⊥ := bot_unique (boolean_algebra.inf_compl_le_bot x) @[simp] theorem compl_inf_eq_bot {α : Type u} {x : α} [boolean_algebra α] : xᶜ ⊓ x = ⊥ := Eq.trans inf_comm inf_compl_eq_bot @[simp] theorem sup_compl_eq_top {α : Type u} {x : α} [boolean_algebra α] : x ⊔ (xᶜ) = ⊤ := top_unique (boolean_algebra.top_le_sup_compl x) @[simp] theorem compl_sup_eq_top {α : Type u} {x : α} [boolean_algebra α] : xᶜ ⊔ x = ⊤ := Eq.trans sup_comm sup_compl_eq_top theorem is_compl_compl {α : Type u} {x : α} [boolean_algebra α] : is_compl x (xᶜ) := is_compl.of_eq inf_compl_eq_bot sup_compl_eq_top theorem is_compl.compl_eq {α : Type u} {x : α} {y : α} [boolean_algebra α] (h : is_compl x y) : xᶜ = y := Eq.symm (is_compl.right_unique h is_compl_compl) theorem disjoint_compl_right {α : Type u} {x : α} [boolean_algebra α] : disjoint x (xᶜ) := is_compl.disjoint is_compl_compl theorem disjoint_compl_left {α : Type u} {x : α} [boolean_algebra α] : disjoint (xᶜ) x := disjoint.symm disjoint_compl_right theorem sdiff_eq {α : Type u} {x : α} {y : α} [boolean_algebra α] : x \ y = x ⊓ (yᶜ) := boolean_algebra.sdiff_eq x y theorem compl_unique {α : Type u} {x : α} {y : α} [boolean_algebra α] (i : x ⊓ y = ⊥) (s : x ⊔ y = ⊤) : xᶜ = y := is_compl.compl_eq (is_compl.of_eq i s) @[simp] theorem compl_top {α : Type u} [boolean_algebra α] : ⊤ᶜ = ⊥ := is_compl.compl_eq is_compl_top_bot @[simp] theorem compl_bot {α : Type u} [boolean_algebra α] : ⊥ᶜ = ⊤ := is_compl.compl_eq is_compl_bot_top @[simp] theorem compl_compl {α : Type u} [boolean_algebra α] (x : α) : xᶜᶜ = x := is_compl.compl_eq (is_compl.symm is_compl_compl) theorem compl_injective {α : Type u} [boolean_algebra α] : function.injective compl := function.involutive.injective compl_compl @[simp] theorem compl_inj_iff {α : Type u} {x : α} {y : α} [boolean_algebra α] : xᶜ = (yᶜ) ↔ x = y := function.injective.eq_iff compl_injective theorem is_compl.compl_eq_iff {α : Type u} {x : α} {y : α} {z : α} [boolean_algebra α] (h : is_compl x y) : zᶜ = y ↔ z = x := is_compl.compl_eq h ▸ compl_inj_iff @[simp] theorem compl_eq_top {α : Type u} {x : α} [boolean_algebra α] : xᶜ = ⊤ ↔ x = ⊥ := is_compl.compl_eq_iff is_compl_bot_top @[simp] theorem compl_eq_bot {α : Type u} {x : α} [boolean_algebra α] : xᶜ = ⊥ ↔ x = ⊤ := is_compl.compl_eq_iff is_compl_top_bot @[simp] theorem compl_inf {α : Type u} {x : α} {y : α} [boolean_algebra α] : x ⊓ yᶜ = xᶜ ⊔ (yᶜ) := is_compl.compl_eq (is_compl.inf_sup is_compl_compl is_compl_compl) @[simp] theorem compl_sup {α : Type u} {x : α} {y : α} [boolean_algebra α] : x ⊔ yᶜ = xᶜ ⊓ (yᶜ) := is_compl.compl_eq (is_compl.sup_inf is_compl_compl is_compl_compl) theorem compl_le_compl {α : Type u} {x : α} {y : α} [boolean_algebra α] (h : y ≤ x) : xᶜ ≤ (yᶜ) := is_compl.antimono is_compl_compl is_compl_compl h @[simp] theorem compl_le_compl_iff_le {α : Type u} {x : α} {y : α} [boolean_algebra α] : yᶜ ≤ (xᶜ) ↔ x ≤ y := sorry theorem le_compl_of_le_compl {α : Type u} {x : α} {y : α} [boolean_algebra α] (h : y ≤ (xᶜ)) : x ≤ (yᶜ) := sorry theorem compl_le_of_compl_le {α : Type u} {x : α} {y : α} [boolean_algebra α] (h : yᶜ ≤ x) : xᶜ ≤ y := sorry theorem le_compl_iff_le_compl {α : Type u} {x : α} {y : α} [boolean_algebra α] : y ≤ (xᶜ) ↔ x ≤ (yᶜ) := { mp := le_compl_of_le_compl, mpr := le_compl_of_le_compl } theorem compl_le_iff_compl_le {α : Type u} {x : α} {y : α} [boolean_algebra α] : xᶜ ≤ y ↔ yᶜ ≤ x := { mp := compl_le_of_compl_le, mpr := compl_le_of_compl_le } theorem sup_sdiff_same {α : Type u} {x : α} {y : α} [boolean_algebra α] : x ⊔ y \ x = x ⊔ y := sorry theorem sdiff_eq_left {α : Type u} {x : α} {y : α} [boolean_algebra α] (h : x ⊓ y = ⊥) : x \ y = x := sorry theorem sdiff_le_sdiff {α : Type u} {w : α} {x : α} {y : α} {z : α} [boolean_algebra α] (h₁ : w ≤ y) (h₂ : z ≤ x) : w \ x ≤ y \ z := eq.mpr (id (Eq._oldrec (Eq.refl (w \ x ≤ y \ z)) sdiff_eq)) (eq.mpr (id (Eq._oldrec (Eq.refl (w ⊓ (xᶜ) ≤ y \ z)) sdiff_eq)) (inf_le_inf h₁ (compl_le_compl h₂))) @[simp] theorem sdiff_idem_right {α : Type u} {x : α} {y : α} [boolean_algebra α] : x \ y \ y = x \ y := sorry protected instance boolean_algebra_Prop : boolean_algebra Prop := boolean_algebra.mk bounded_distrib_lattice.sup bounded_distrib_lattice.le bounded_distrib_lattice.lt sorry sorry sorry sorry sorry sorry bounded_distrib_lattice.inf sorry sorry sorry sorry bounded_distrib_lattice.top sorry bounded_distrib_lattice.bot sorry Not (fun (p q : Prop) => p ∧ ¬q) sorry sorry sorry protected instance pi.boolean_algebra {α : Type u} {β : Type v} [boolean_algebra β] : boolean_algebra (α → β) := boolean_algebra.mk (fun (ᾰ ᾰ_1 : α → β) (i : α) => boolean_algebra.sup (ᾰ i) (ᾰ_1 i)) partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry (fun (ᾰ ᾰ_1 : α → β) (i : α) => boolean_algebra.inf (ᾰ i) (ᾰ_1 i)) sorry sorry sorry sorry (fun (i : α) => boolean_algebra.top) sorry (fun (i : α) => boolean_algebra.bot) sorry (fun (ᾰ : α → β) (i : α) => boolean_algebra.compl (ᾰ i)) (fun (ᾰ ᾰ_1 : α → β) (i : α) => boolean_algebra.sdiff (ᾰ i) (ᾰ_1 i)) sorry sorry sorry end Mathlib
7170b89f123b5beb9cb87e28ea56c33c6c3fee03
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/02_Dependent_Type_Theory.org.29.lean
30e77ff8079e0574422144c256bb567ac9a456d5
[]
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
211
lean
/- page 25 -/ import standard namespace foo constant A : Type constant a : A constant f : A → A definition fa : A := f a end foo check foo.A check foo.f namespace foo definition ffa : A := f (f a) end foo
31d3eb4b3a0c6b89c027aa2c18805f4d640f0ae0
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/tests/lean/run/nat_bug4.lean
e5e575fa110fe5c1d5d9730f26ca149c1e6e0229
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
477
lean
import standard using num eq_proofs inductive nat : Type := zero : nat, succ : nat → nat namespace nat definition add (x y : nat) : nat := nat.rec x (λn r, succ r) y infixl `+` := add definition mul (n m : nat) := nat.rec zero (fun m x, x + n) m infixl `*` := mul axiom mul_succ_right (n m : nat) : n * succ m = n * m + n open eq theorem small2 (n m l : nat) : n * succ l + m = n * l + n + m := subst (mul_succ_right _ _) (eq.refl (n * succ l + m)) end nat end experiment
28844cb55ed8d7ab9d24bd3852e2da2757dee18e
206422fb9edabf63def0ed2aa3f489150fb09ccb
/src/category_theory/filtered.lean
a2fe067eb7cf271d4645e73203383c13cc5873d5
[ "Apache-2.0" ]
permissive
hamdysalah1/mathlib
b915f86b2503feeae268de369f1b16932321f097
95454452f6b3569bf967d35aab8d852b1ddf8017
refs/heads/master
1,677,154,116,545
1,611,797,994,000
1,611,797,994,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,793
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 category_theory.adjunction.basic 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 v₁ u 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'`. -/ @[simp, reassoc] 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.bUnion (λ X : J, finset.univ.bUnion (λ 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_bUnion, 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 variables {D : Type u₁} [category.{v₁} D] /-- If `C` is filtered, and we have a functor `R : C ⥤ D` with a left adjoint, then `D` is filtered. -/ lemma of_right_adjoint {L : D ⥤ C} {R : C ⥤ D} (h : L ⊣ R) : is_filtered D := { cocone_objs := λ X Y, ⟨_, h.hom_equiv _ _ (left_to_max _ _), h.hom_equiv _ _ (right_to_max _ _), ⟨⟩⟩, cocone_maps := λ X Y f g, ⟨_, h.hom_equiv _ _ (coeq_hom _ _), by rw [← h.hom_equiv_naturality_left, ← h.hom_equiv_naturality_left, coeq_condition]⟩, nonempty := is_filtered.nonempty.map R.obj } /-- If `C` is filtered, and we have a right adjoint functor `R : C ⥤ D`, then `D` is filtered. -/ lemma of_is_right_adjoint (R : C ⥤ D) [is_right_adjoint R] : is_filtered D := of_right_adjoint (adjunction.of_right_adjoint R) /-- Being filtered is preserved by equivalence of categories. -/ lemma of_equivalence (h : C ≌ D) : is_filtered D := of_right_adjoint h.symm.to_adjunction end is_filtered end category_theory
35d1d0a2a28c9d8e15b1d6dc02f4f48fb8ef85ff
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/logic/examples/instances_test.lean
54fdc674d468a4f66b4641dfd09b90683c5e1c54
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,242
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 ..instances open relation open relation.general_operations open relation.iff_ops open eq.ops section theorem test1 (a b : Prop) (H : a ↔ b) (H1 : a) : b := mp H H1 end section theorem test2 (a b c d e : Prop) (H1 : a ↔ b) (H2 : a ∨ c → ¬(d → a)) : b ∨ c → ¬(d → b) := subst iff H1 H2 theorem test3 (a b c d e : Prop) (H1 : a ↔ b) (H2 : a ∨ c → ¬(d → a)) : b ∨ c → ¬(d → b) := H1 ▸ H2 end theorem test4 (a b c d e : Prop) (H1 : a ↔ b) : (a ∨ c → ¬(d → a)) ↔ (b ∨ c → ¬(d → b)) := congruence.infer iff iff (λa, (a ∨ c → ¬(d → a))) H1 section theorem test5 (T : Type) (a b c d : T) (H1 : a = b) (H2 : c = b) (H3 : c = d) : a = d := H1 ⬝ H2⁻¹ ⬝ H3 theorem test6 (a b c d : Prop) (H1 : a ↔ b) (H2 : c ↔ b) (H3 : c ↔ d) : a ↔ d := H1 ⬝ (H2⁻¹ ⬝ H3) theorem test7 (T : Type) (a b c d : T) (H1 : a = b) (H2 : c = b) (H3 : c = d) : a = d := H1 ⬝ H2⁻¹ ⬝ H3 theorem test8 (a b c d : Prop) (H1 : a ↔ b) (H2 : c ↔ b) (H3 : c ↔ d) : a ↔ d := H1 ⬝ H2⁻¹ ⬝ H3 end
4504bf3714030df83f572b2e77128816a1b0c38a
c61b91f85121053c627318ad8fcde30dfb8637d2
/Chapter2/2-8.lean
67277fbc1dcf57fcf1c0ab6aec5e9e068fd8c903
[]
no_license
robkorn/theorem-proving-in-lean-exercises
9e2256360eaf6f8df6cdd8fd656e63dfb04c8cdb
9c51da587105ee047a9db55d52709d881a39be7a
refs/heads/master
1,585,403,341,988
1,540,142,619,000
1,540,142,619,000
148,431,678
2
0
null
null
null
null
UTF-8
Lean
false
false
844
lean
namespace hidden universe u constant list : Type u -> Type u constant cons : Π α : Type u, α → list α → list α constant nil : Π α : Type u, list α constant head : Π α : Type u, list α -> α constant tail : Π α : Type u, list α -> list α constant append : Π α : Type u, list α -> list α -> list α end hidden open list #check list -- Type u_1 -> Type u_1 #check @cons -- Π {α : Type u_1}, α -> list α -> list α #check @nil -- Π {α : Type u_1}, list α #check @head -- Π {α : Type u_1} [_inst_1 : inhabited α], list α -> α #check @tail -- Π {α : Type u_1}, list α -> list α #check @append -- Π {α : Type u_1}, list α -> list α -> list α variable α : Type variable β : α → Type variable a : α variable b : β a #check sigma.mk α b
f3ec39302cd5948134a21adb1ab589671043d3c6
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
/tests/lean/run/sharecommon.lean
27b7970d7267fc8607789e09ba39f712daf4dc34
[ "Apache-2.0" ]
permissive
walterhu1015/lean4
b2c71b688975177402758924eaa513475ed6ce72
2214d81e84646a905d0b20b032c89caf89c737ad
refs/heads/master
1,671,342,096,906
1,599,695,985,000
1,599,695,985,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,981
lean
import Std.ShareCommon open Std def check (b : Bool) : ShareCommonT IO Unit := unless b $ throw $ IO.userError "check failed" unsafe def tst1 : ShareCommonT IO Unit := do let x := [1]; let y := [0].map (fun x => x + 1); check $ ptrAddrUnsafe x != ptrAddrUnsafe y; x ← shareCommonM x; y ← shareCommonM y; check $ ptrAddrUnsafe x == ptrAddrUnsafe y; z ← shareCommonM [2]; x ← shareCommonM x; check $ ptrAddrUnsafe x == ptrAddrUnsafe y; check $ ptrAddrUnsafe x != ptrAddrUnsafe z; IO.println x; IO.println y; IO.println z #eval tst1.run unsafe def tst2 : ShareCommonT IO Unit := do let x := [1, 2]; let y := [0, 1].map (fun x => x + 1); check $ ptrAddrUnsafe x != ptrAddrUnsafe y; x ← shareCommonM x; y ← shareCommonM y; check $ ptrAddrUnsafe x == ptrAddrUnsafe y; z ← shareCommonM [2]; x ← shareCommonM x; check $ ptrAddrUnsafe x == ptrAddrUnsafe y; check $ ptrAddrUnsafe x != ptrAddrUnsafe z; IO.println x; IO.println y; IO.println z #eval tst2.run structure Foo := (x : Nat) (y : Bool) (z : Bool) @[noinline] def mkFoo1 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z } @[noinline] def mkFoo2 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z } unsafe def tst3 : ShareCommonT IO Unit := do let o1 := mkFoo1 10 true; let o2 := mkFoo2 10 true; let o3 := mkFoo2 10 false; check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o2; check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o3; o1 ← shareCommonM o1; o2 ← shareCommonM o2; o3 ← shareCommonM o3; check $ o1.x == 10 && o1.y == true && o1.z == true && o3.z == false && ptrAddrUnsafe o1 == ptrAddrUnsafe o2 && ptrAddrUnsafe o1 != ptrAddrUnsafe o3; IO.println o1.x; pure () #eval tst3.run unsafe def tst4 : ShareCommonT IO Unit := do let x := ["hello"]; let y := ["ello"].map (fun x => "h" ++ x); check $ ptrAddrUnsafe x != ptrAddrUnsafe y; x ← shareCommonM x; y ← shareCommonM y; check $ ptrAddrUnsafe x == ptrAddrUnsafe y; z ← shareCommonM ["world"]; x ← shareCommonM x; check $ ptrAddrUnsafe x == ptrAddrUnsafe y && ptrAddrUnsafe x != ptrAddrUnsafe z; IO.println x; IO.println y; IO.println z #eval tst4.run @[noinline] def mkList1 (x : Nat) : List Nat := List.replicate x x @[noinline] def mkList2 (x : Nat) : List Nat := List.replicate x x @[noinline] def mkArray1 (x : Nat) : Array (List Nat) := #[ mkList1 x, mkList2 x, mkList2 (x+1) ] @[noinline] def mkArray2 (x : Nat) : Array (List Nat) := mkArray1 x unsafe def tst5 : ShareCommonT IO Unit := do let a := mkArray1 3; let b := mkArray2 3; let c := mkArray2 4; IO.println a; IO.println b; IO.println c; check $ ptrAddrUnsafe a != ptrAddrUnsafe b && ptrAddrUnsafe a != ptrAddrUnsafe c && ptrAddrUnsafe (a.get! 0) != ptrAddrUnsafe (a.get! 1) && ptrAddrUnsafe (a.get! 0) != ptrAddrUnsafe (a.get! 2) && ptrAddrUnsafe (b.get! 0) != ptrAddrUnsafe (b.get! 1) && ptrAddrUnsafe (c.get! 0) != ptrAddrUnsafe (c.get! 1); a ← shareCommonM a; b ← shareCommonM b; c ← shareCommonM c; check $ ptrAddrUnsafe a == ptrAddrUnsafe b && ptrAddrUnsafe a != ptrAddrUnsafe c && ptrAddrUnsafe (a.get! 0) == ptrAddrUnsafe (a.get! 1) && ptrAddrUnsafe (a.get! 0) != ptrAddrUnsafe (a.get! 2) && ptrAddrUnsafe (b.get! 0) == ptrAddrUnsafe (b.get! 1) && ptrAddrUnsafe (c.get! 0) == ptrAddrUnsafe (c.get! 1); pure () #eval tst5.run @[noinline] def mkByteArray1 (x : Nat) : ByteArray := let r := ByteArray.empty; let r := r.push x.toUInt8; let r := r.push (x+1).toUInt8; let r := r.push (x+2).toUInt8; r @[noinline] def mkByteArray2 (x : Nat) : ByteArray := mkByteArray1 x unsafe def tst6 (x : Nat) : ShareCommonT IO Unit := do let a := [mkByteArray1 x]; let b := [mkByteArray2 x]; let c := [mkByteArray2 (x+1)]; IO.println a; IO.println b; IO.println c; check $ ptrAddrUnsafe a != ptrAddrUnsafe b; check $ ptrAddrUnsafe a != ptrAddrUnsafe c; a ← shareCommonM a; b ← shareCommonM b; c ← shareCommonM c; check $ ptrAddrUnsafe a == ptrAddrUnsafe b; check $ ptrAddrUnsafe a != ptrAddrUnsafe c; pure () #eval (tst6 2).run
a720c4558ef757bd39d613cde9ace73caf32011e
07c6143268cfb72beccd1cc35735d424ebcb187b
/src/data/list/defs.lean
4c19ac9d6d81ca8d1aa0f47119197393e4516231
[ "Apache-2.0" ]
permissive
khoek/mathlib
bc49a842910af13a3c372748310e86467d1dc766
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
refs/heads/master
1,588,232,063,837
1,587,304,803,000
1,587,304,803,000
176,688,517
0
0
Apache-2.0
1,553,070,585,000
1,553,070,585,000
null
UTF-8
Lean
false
false
19,907
lean
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro Extra definitions on lists. -/ import data.option.defs logic.basic tactic.cache namespace list open function nat universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} /-- Returns whether a list is []. Returns a boolean even if `l = []` is not decidable. -/ def is_nil {α} : list α → bool | [] := tt | _ := ff instance [decidable_eq α] : has_sdiff (list α) := ⟨ list.diff ⟩ /-- Split a list at an index. split_at 2 [a, b, c] = ([a, b], [c]) -/ def split_at : ℕ → list α → list α × list α | 0 a := ([], a) | (succ n) [] := ([], []) | (succ n) (x :: xs) := let (l, r) := split_at n xs in (x :: l, r) def split_on_p_aux {α : Type u} (P : α → Prop) [decidable_pred P] : list α → (list α → list α) → list (list α) | [] f := [f []] | (h :: t) f := if P h then f [] :: split_on_p_aux t id else split_on_p_aux t (λ l, f (h :: l)) /-- Split a list at every element satisfying a predicate. -/ def split_on_p {α : Type u} (P : α → Prop) [decidable_pred P] (l : list α) : list (list α) := split_on_p_aux P l id /-- Split a list at every occurrence of an element. [1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]] -/ def split_on {α : Type u} [decidable_eq α] (a : α) (as : list α) : list (list α) := as.split_on_p (=a) /-- Concatenate an element at the end of a list. concat [a, b] c = [a, b, c] -/ @[simp] def concat : list α → α → list α | [] a := [a] | (b::l) a := b :: concat l a /-- `head' xs` returns the first element of `xs` if `xs` is non-empty; it returns `none` otherwise -/ @[simp] def head' : list α → option α | [] := none | (a :: l) := some a /-- Convert a list into an array (whose length is the length of `l`). -/ def to_array (l : list α) : array l.length α := {data := λ v, l.nth_le v.1 v.2} /-- "inhabited" `nth` function: returns `default` instead of `none` in the case that the index is out of bounds. -/ @[simp] def inth [h : inhabited α] (l : list α) (n : nat) : α := (nth l n).iget /-- Apply a function to the nth tail of `l`. Returns the input without using `f` if the index is larger than the length of the list. modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c] -/ @[simp] def modify_nth_tail (f : list α → list α) : ℕ → list α → list α | 0 l := f l | (n+1) [] := [] | (n+1) (a::l) := a :: modify_nth_tail n l /-- Apply `f` to the head of the list, if it exists. -/ @[simp] def modify_head (f : α → α) : list α → list α | [] := [] | (a::l) := f a :: l /-- Apply `f` to the nth element of the list, if it exists. -/ def modify_nth (f : α → α) : ℕ → list α → list α := modify_nth_tail (modify_head f) def insert_nth (n : ℕ) (a : α) : list α → list α := modify_nth_tail (list.cons a) n section take' variable [inhabited α] def take' : ∀ n, list α → list α | 0 l := [] | (n+1) l := l.head :: take' n l.tail end take' /-- Get the longest initial segment of the list whose members all satisfy `p`. take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2] -/ def take_while (p : α → Prop) [decidable_pred p] : list α → list α | [] := [] | (a::l) := if p a then a :: take_while l else [] /-- `after p xs` is the suffix of `xs` after the first element that satisfies `p`, not including that element. ```lean after (eq 1) [0, 1, 2, 3] = [2, 3] drop_while (not ∘ eq 1) [0, 1, 2, 3] = [1, 2, 3] ``` -/ def after (p : α → Prop) [decidable_pred p] : list α → list α | [] := [] | (x :: xs) := if p x then xs else after xs /-- Fold a function `f` over the list from the left, returning the list of partial results. scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6] -/ def scanl (f : α → β → α) : α → list β → list α | a [] := [a] | a (b::l) := a :: scanl (f a b) l def scanr_aux (f : α → β → β) (b : β) : list α → β × list β | [] := (b, []) | (a::l) := let (b', l') := scanr_aux l in (f a b', b' :: l') /-- Fold a function `f` over the list from the right, returning the list of partial results. scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0] -/ def scanr (f : α → β → β) (b : β) (l : list α) : list β := let (b', l') := scanr_aux f b l in b' :: l' /-- Product of a list. prod [a, b, c] = ((1 * a) * b) * c -/ def prod [has_mul α] [has_one α] : list α → α := foldl (*) 1 /-- Sum of a list. sum [a, b, c] = ((0 + a) + b) + c -/ -- Later this will be tagged with `to_additive`, but this can't be done yet because of import -- dependencies. def sum [has_add α] [has_zero α] : list α → α := foldl (+) 0 def partition_map (f : α → β ⊕ γ) : list α → list β × list γ | [] := ([],[]) | (x::xs) := match f x with | (sum.inr r) := prod.map id (cons r) $ partition_map xs | (sum.inl l) := prod.map (cons l) id $ partition_map xs end /-- `find p l` is the first element of `l` satisfying `p`, or `none` if no such element exists. -/ def find (p : α → Prop) [decidable_pred p] : list α → option α | [] := none | (a::l) := if p a then some a else find l def find_indexes_aux (p : α → Prop) [decidable_pred p] : list α → nat → list nat | [] n := [] | (a::l) n := let t := find_indexes_aux l (succ n) in if p a then n :: t else t /-- `find_indexes p l` is the list of indexes of elements of `l` that satisfy `p`. -/ def find_indexes (p : α → Prop) [decidable_pred p] (l : list α) : list nat := find_indexes_aux p l 0 /-- `lookmap` is a combination of `lookup` and `filter_map`. `lookmap f l` will apply `f : α → option α` to each element of the list, replacing `a → b` at the first value `a` in the list such that `f a = some b`. -/ def lookmap (f : α → option α) : list α → list α | [] := [] | (a::l) := match f a with | some b := b :: l | none := a :: lookmap l end def map_with_index_core (f : ℕ → α → β) : ℕ → list α → list β | k [] := [] | k (a::as) := f k a::(map_with_index_core (k+1) as) def map_with_index (f : ℕ → α → β) (as : list α) : list β := map_with_index_core f 0 as /-- `indexes_of a l` is the list of all indexes of `a` in `l`. indexes_of a [a, b, a, a] = [0, 2, 3] -/ def indexes_of [decidable_eq α] (a : α) : list α → list nat := find_indexes (eq a) /-- Auxilliary definition for `indexes_values`. -/ def indexes_values_aux {α} (f : α → bool) : list α → ℕ → list (ℕ × α) | [] n := [] | (x::xs) n := let ns := indexes_values_aux xs (n+1) in if f x then (n, x)::ns else ns /-- Returns `(l.find_indexes f).zip l`, i.e. pairs of `(n, x)` such that `f x = tt` and `l.nth = some x`, in increasing order of first arguments. -/ def indexes_values {α} (l : list α) (f : α → bool) : list (ℕ × α) := indexes_values_aux f l 0 /-- `countp p l` is the number of elements of `l` that satisfy `p`. -/ def countp (p : α → Prop) [decidable_pred p] : list α → nat | [] := 0 | (x::xs) := if p x then succ (countp xs) else countp xs /-- `count a l` is the number of occurrences of `a` in `l`. -/ def count [decidable_eq α] (a : α) : list α → nat := countp (eq a) /-- `is_prefix l₁ l₂`, or `l₁ <+: l₂`, means that `l₁` is a prefix of `l₂`, that is, `l₂` has the form `l₁ ++ t` for some `t`. -/ def is_prefix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, l₁ ++ t = l₂ /-- `is_suffix l₁ l₂`, or `l₁ <:+ l₂`, means that `l₁` is a suffix of `l₂`, that is, `l₂` has the form `t ++ l₁` for some `t`. -/ def is_suffix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, t ++ l₁ = l₂ /-- `is_infix l₁ l₂`, or `l₁ <:+: l₂`, means that `l₁` is a contiguous substring of `l₂`, that is, `l₂` has the form `s ++ l₁ ++ t` for some `s, t`. -/ def is_infix (l₁ : list α) (l₂ : list α) : Prop := ∃ s t, s ++ l₁ ++ t = l₂ infix ` <+: `:50 := is_prefix infix ` <:+ `:50 := is_suffix infix ` <:+: `:50 := is_infix /-- `inits l` is the list of initial segments of `l`. inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]] -/ @[simp] def inits : list α → list (list α) | [] := [[]] | (a::l) := [] :: map (λt, a::t) (inits l) /-- `tails l` is the list of terminal segments of `l`. tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []] -/ @[simp] def tails : list α → list (list α) | [] := [[]] | (a::l) := (a::l) :: tails l def sublists'_aux : list α → (list α → list β) → list (list β) → list (list β) | [] f r := f [] :: r | (a::l) f r := sublists'_aux l f (sublists'_aux l (f ∘ cons a) r) /-- `sublists' l` is the list of all (non-contiguous) sublists of `l`. It differs from `sublists` only in the order of appearance of the sublists; `sublists'` uses the first element of the list as the MSB, `sublists` uses the first element of the list as the LSB. sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] -/ def sublists' (l : list α) : list (list α) := sublists'_aux l id [] def sublists_aux : list α → (list α → list β → list β) → list β | [] f := [] | (a::l) f := f [a] (sublists_aux l (λys r, f ys (f (a :: ys) r))) /-- `sublists l` is the list of all (non-contiguous) sublists of `l`; cf. `sublists'` for a different ordering. sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] -/ def sublists (l : list α) : list (list α) := [] :: sublists_aux l cons def sublists_aux₁ : list α → (list α → list β) → list β | [] f := [] | (a::l) f := f [a] ++ sublists_aux₁ l (λys, f ys ++ f (a :: ys)) section forall₂ variables {r : α → β → Prop} {p : γ → δ → Prop} inductive forall₂ (R : α → β → Prop) : list α → list β → Prop | nil : forall₂ [] [] | cons {a b l₁ l₂} : R a b → forall₂ l₁ l₂ → forall₂ (a::l₁) (b::l₂) attribute [simp] forall₂.nil end forall₂ def transpose_aux : list α → list (list α) → list (list α) | [] ls := ls | (a::i) [] := [a] :: transpose_aux i [] | (a::i) (l::ls) := (a::l) :: transpose_aux i ls /-- transpose of a list of lists, treated as a matrix. transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]] -/ def transpose : list (list α) → list (list α) | [] := [] | (l::ls) := transpose_aux l (transpose ls) /-- List of all sections through a list of lists. A section of `[L₁, L₂, ..., Lₙ]` is a list whose first element comes from `L₁`, whose second element comes from `L₂`, and so on. -/ def sections : list (list α) → list (list α) | [] := [[]] | (l::L) := bind (sections L) $ λ s, map (λ a, a::s) l section permutations def permutations_aux2 (t : α) (ts : list α) (r : list β) : list α → (list α → β) → list α × list β | [] f := (ts, r) | (y::ys) f := let (us, zs) := permutations_aux2 ys (λx : list α, f (y::x)) in (y :: us, f (t :: y :: us) :: zs) private def meas : (Σ'_:list α, list α) → ℕ × ℕ | ⟨l, i⟩ := (length l + length i, length l) local infix ` ≺ `:50 := inv_image (prod.lex (<) (<)) meas @[elab_as_eliminator] def permutations_aux.rec {C : list α → list α → Sort v} (H0 : ∀ is, C [] is) (H1 : ∀ t ts is, C ts (t::is) → C is [] → C (t::ts) is) : ∀ l₁ l₂, C l₁ l₂ | [] is := H0 is | (t::ts) is := have h1 : ⟨ts, t :: is⟩ ≺ ⟨t :: ts, is⟩, from show prod.lex _ _ (succ (length ts + length is), length ts) (succ (length ts) + length is, length (t :: ts)), by rw nat.succ_add; exact prod.lex.right _ (lt_succ_self _), have h2 : ⟨is, []⟩ ≺ ⟨t :: ts, is⟩, from prod.lex.left _ _ (lt_add_of_pos_left _ (succ_pos _)), H1 t ts is (permutations_aux.rec ts (t::is)) (permutations_aux.rec is []) using_well_founded { dec_tac := tactic.assumption, rel_tac := λ _ _, `[exact ⟨(≺), @inv_image.wf _ _ _ meas (prod.lex_wf lt_wf lt_wf)⟩] } def permutations_aux : list α → list α → list (list α) := @@permutations_aux.rec (λ _ _, list (list α)) (λ is, []) (λ t ts is IH1 IH2, foldr (λy r, (permutations_aux2 t ts r y id).2) IH1 (is :: IH2)) /-- List of all permutations of `l`. permutations [1, 2, 3] = [[1, 2, 3], [2, 1, 3], [3, 2, 1], [2, 3, 1], [3, 1, 2], [1, 3, 2]] -/ def permutations (l : list α) : list (list α) := l :: permutations_aux l [] end permutations def erasep (p : α → Prop) [decidable_pred p] : list α → list α | [] := [] | (a::l) := if p a then l else a :: erasep l def extractp (p : α → Prop) [decidable_pred p] : list α → option α × list α | [] := (none, []) | (a::l) := if p a then (some a, l) else let (a', l') := extractp l in (a', a :: l') def revzip (l : list α) : list (α × α) := zip l l.reverse /-- `product l₁ l₂` is the list of pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂`. product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)] -/ def product (l₁ : list α) (l₂ : list β) : list (α × β) := l₁.bind $ λ a, l₂.map $ prod.mk a /-- `sigma l₁ l₂` is the list of dependent pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂ a`. sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)] -/ protected def sigma {σ : α → Type*} (l₁ : list α) (l₂ : Π a, list (σ a)) : list (Σ a, σ a) := l₁.bind $ λ a, (l₂ a).map $ sigma.mk a def of_fn_aux {n} (f : fin n → α) : ∀ m, m ≤ n → list α → list α | 0 h l := l | (succ m) h l := of_fn_aux m (le_of_lt h) (f ⟨m, h⟩ :: l) def of_fn {n} (f : fin n → α) : list α := of_fn_aux f n (le_refl _) [] def of_fn_nth_val {n} (f : fin n → α) (i : ℕ) : option α := if h : _ then some (f ⟨i, h⟩) else none /-- `disjoint l₁ l₂` means that `l₁` and `l₂` have no elements in common. -/ def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, a ∈ l₁ → a ∈ l₂ → false section pairwise variables (R : α → α → Prop) /-- `pairwise R l` means that all the elements with earlier indexes are `R`-related to all the elements with later indexes. pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3 For example if `R = (≠)` then it asserts `l` has no duplicates, and if `R = (<)` then it asserts that `l` is (strictly) sorted. -/ inductive pairwise : list α → Prop | nil : pairwise [] | cons : ∀ {a : α} {l : list α}, (∀ a' ∈ l, R a a') → pairwise l → pairwise (a::l) variables {R} @[simp] theorem pairwise_cons {a : α} {l : list α} : pairwise R (a::l) ↔ (∀ a' ∈ l, R a a') ∧ pairwise R l := ⟨λ p, by cases p with a l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩ instance decidable_pairwise [decidable_rel R] (l : list α) : decidable (pairwise R l) := by induction l with hd tl ih; [exact is_true pairwise.nil, exactI decidable_of_iff' _ pairwise_cons] end pairwise /-- `pw_filter R l` is a maximal sublist of `l` which is `pairwise R`. `pw_filter (≠)` is the erase duplicates function (cf. `erase_dup`), and `pw_filter (<)` finds a maximal increasing subsequence in `l`. For example, pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4] -/ def pw_filter (R : α → α → Prop) [decidable_rel R] : list α → list α | [] := [] | (x :: xs) := let IH := pw_filter xs in if ∀ y ∈ IH, R x y then x :: IH else IH section chain variable (R : α → α → Prop) /-- `chain R a l` means that `R` holds between adjacent elements of `a::l`. chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d -/ inductive chain : α → list α → Prop | nil {a : α} : chain a [] | cons : ∀ {a b : α} {l : list α}, R a b → chain b l → chain a (b::l) /-- `chain' R l` means that `R` holds between adjacent elements of `l`. chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d -/ def chain' : list α → Prop | [] := true | (a :: l) := chain R a l variable {R} @[simp] theorem chain_cons {a b : α} {l : list α} : chain R a (b::l) ↔ R a b ∧ chain R b l := ⟨λ p, by cases p with _ a b l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩ attribute [simp] chain.nil instance decidable_chain [decidable_rel R] (a : α) (l : list α) : decidable (chain R a l) := by induction l generalizing a; simp only [chain.nil, chain_cons]; resetI; apply_instance instance decidable_chain' [decidable_rel R] (l : list α) : decidable (chain' R l) := by cases l; dunfold chain'; apply_instance end chain /-- `nodup l` means that `l` has no duplicates, that is, any element appears at most once in the list. It is defined as `pairwise (≠)`. -/ def nodup : list α → Prop := pairwise (≠) instance nodup_decidable [decidable_eq α] : ∀ l : list α, decidable (nodup l) := list.decidable_pairwise /-- `erase_dup l` removes duplicates from `l` (taking only the first occurrence). Defined as `pw_filter (≠)`. erase_dup [1, 0, 2, 2, 1] = [0, 2, 1] -/ def erase_dup [decidable_eq α] : list α → list α := pw_filter (≠) /-- `range' s n` is the list of numbers `[s, s+1, ..., s+n-1]`. It is intended mainly for proving properties of `range` and `iota`. -/ @[simp] def range' : ℕ → ℕ → list ℕ | s 0 := [] | s (n+1) := s :: range' (s+1) n def reduce_option {α} : list (option α) → list α := list.filter_map id def map_head {α} (f : α → α) : list α → list α | [] := [] | (x :: xs) := f x :: xs def map_last {α} (f : α → α) : list α → list α | [] := [] | [x] := [f x] | (x :: xs) := x :: map_last xs /-- `ilast' x xs` returns the last element of `xs` if `xs` is non-empty; it returns `x` otherwise -/ @[simp] def ilast' {α} : α → list α → α | a [] := a | a (b::l) := ilast' b l /-- `last' xs` returns the last element of `xs` if `xs` is non-empty; it returns `none` otherwise -/ @[simp] def last' {α} : list α → option α | [] := none | [a] := some a | (b::l) := last' l /-- `rotate l n` rotates the elements of `l` to the left by `n` rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1] -/ def rotate (l : list α) (n : ℕ) : list α := let (l₁, l₂) := list.split_at (n % l.length) l in l₂ ++ l₁ /-- rotate' is the same as `rotate`, but slower. Used for proofs about `rotate`-/ def rotate' : list α → ℕ → list α | [] n := [] | l 0 := l | (a::l) (n+1) := rotate' (l ++ [a]) n section choose variables (p : α → Prop) [decidable_pred p] (l : list α) def choose_x : Π l : list α, Π hp : (∃ a, a ∈ l ∧ p a), { a // a ∈ l ∧ p a } | [] hp := false.elim (exists.elim hp (assume a h, not_mem_nil a h.left)) | (l :: ls) hp := if pl : p l then ⟨l, ⟨or.inl rfl, pl⟩⟩ else let ⟨a, ⟨a_mem_ls, pa⟩⟩ := choose_x ls (hp.imp (λ b ⟨o, h₂⟩, ⟨o.resolve_left (λ e, pl $ e ▸ h₂), h₂⟩)) in ⟨a, ⟨or.inr a_mem_ls, pa⟩⟩ def choose (hp : ∃ a, a ∈ l ∧ p a) : α := choose_x p l hp end choose /-- Filters and maps elements of a list -/ def mmap_filter {m : Type → Type v} [monad m] {α β} (f : α → m (option β)) : list α → m (list β) | [] := return [] | (h :: t) := do b ← f h, t' ← t.mmap_filter, return $ match b with none := t' | (some x) := x::t' end protected def traverse {F : Type u → Type v} [applicative F] {α β : Type*} (f : α → F β) : list α → F (list β) | [] := pure [] | (x :: xs) := list.cons <$> f x <*> traverse xs /-- `get_rest l l₁` returns `some l₂` if `l = l₁ ++ l₂`. If `l₁` is not a prefix of `l`, returns `none` -/ def get_rest [decidable_eq α] : list α → list α → option (list α) | l [] := some l | [] _ := none | (x::l) (y::l₁) := if x = y then get_rest l l₁ else none end list
03d20a78cf79a9adb91ae8fd9dd165402211fc7e
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/coe7.lean
f98c3d8d037906eb80fa72ea0e645ce14d517de0
[ "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
270
lean
import logic namespace experiment constant nat : Type.{1} constant int : Type.{1} constant of_nat : nat → int attribute of_nat [coercion] theorem tst (n : nat) : n = n := have H : true, from trivial, calc n = n : eq.refl _ ... = n : eq.refl _ end experiment
92d0d5e12d0b2ae850a818c326464123df33f2db
c777c32c8e484e195053731103c5e52af26a25d1
/src/analysis/normed/group/add_torsor.lean
169615af036edec2be2b1fc5432eaf16cef56082
[ "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
10,178
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov -/ import analysis.normed.group.basic import linear_algebra.affine_space.affine_subspace import linear_algebra.affine_space.midpoint /-! # Torsors of additive normed group actions. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines torsors of additive normed group actions, with a metric space structure. The motivating case is Euclidean affine spaces. -/ noncomputable theory open_locale nnreal topology open filter /-- A `normed_add_torsor V P` is a torsor of an additive seminormed group action by a `seminormed_add_comm_group V` on points `P`. We bundle the pseudometric space structure and require the distance to be the same as results from the norm (which in fact implies the distance yields a pseudometric space, but bundling just the distance and using an instance for the pseudometric space results in type class problems). -/ class normed_add_torsor (V : out_param $ Type*) (P : Type*) [out_param $ seminormed_add_comm_group V] [pseudo_metric_space P] extends add_torsor V P := (dist_eq_norm' : ∀ (x y : P), dist x y = ‖(x -ᵥ y : V)‖) /-- Shortcut instance to help typeclass inference out. -/ @[priority 100] instance normed_add_torsor.to_add_torsor' {V P : Type*} [normed_add_comm_group V] [metric_space P] [normed_add_torsor V P] : add_torsor V P := normed_add_torsor.to_add_torsor variables {α V P W Q : Type*} [seminormed_add_comm_group V] [pseudo_metric_space P] [normed_add_torsor V P] [normed_add_comm_group W] [metric_space Q] [normed_add_torsor W Q] @[priority 100] instance normed_add_torsor.to_has_isometric_vadd : has_isometric_vadd V P := ⟨λ c, isometry.of_dist_eq $ λ x y, by simp [normed_add_torsor.dist_eq_norm']⟩ /-- A `seminormed_add_comm_group` is a `normed_add_torsor` over itself. -/ @[priority 100] instance seminormed_add_comm_group.to_normed_add_torsor : normed_add_torsor V V := { dist_eq_norm' := dist_eq_norm } /-- A nonempty affine subspace of a `normed_add_torsor` is itself a `normed_add_torsor`. -/ @[nolint fails_quickly] -- Because of the add_torsor.nonempty instance. instance affine_subspace.to_normed_add_torsor {R : Type*} [ring R] [module R V] (s : affine_subspace R P) [nonempty s] : normed_add_torsor s.direction s := { dist_eq_norm' := λ x y, normed_add_torsor.dist_eq_norm' ↑x ↑y, ..affine_subspace.to_add_torsor s } include V section variables (V W) /-- The distance equals the norm of subtracting two points. In this lemma, it is necessary to have `V` as an explicit argument; otherwise `rw dist_eq_norm_vsub` sometimes doesn't work. -/ lemma dist_eq_norm_vsub (x y : P) : dist x y = ‖x -ᵥ y‖ := normed_add_torsor.dist_eq_norm' x y /-- The distance equals the norm of subtracting two points. In this lemma, it is necessary to have `V` as an explicit argument; otherwise `rw dist_eq_norm_vsub'` sometimes doesn't work. -/ lemma dist_eq_norm_vsub' (x y : P) : dist x y = ‖y -ᵥ x‖ := (dist_comm _ _).trans (dist_eq_norm_vsub _ _ _) end lemma dist_vadd_cancel_left (v : V) (x y : P) : dist (v +ᵥ x) (v +ᵥ y) = dist x y := dist_vadd _ _ _ @[simp] lemma dist_vadd_cancel_right (v₁ v₂ : V) (x : P) : dist (v₁ +ᵥ x) (v₂ +ᵥ x) = dist v₁ v₂ := by rw [dist_eq_norm_vsub V, dist_eq_norm, vadd_vsub_vadd_cancel_right] @[simp] lemma dist_vadd_left (v : V) (x : P) : dist (v +ᵥ x) x = ‖v‖ := by simp [dist_eq_norm_vsub V _ x] @[simp] lemma dist_vadd_right (v : V) (x : P) : dist x (v +ᵥ x) = ‖v‖ := by rw [dist_comm, dist_vadd_left] /-- Isometry between the tangent space `V` of a (semi)normed add torsor `P` and `P` given by addition/subtraction of `x : P`. -/ @[simps] def isometry_equiv.vadd_const (x : P) : V ≃ᵢ P := { to_equiv := equiv.vadd_const x, isometry_to_fun := isometry.of_dist_eq $ λ _ _, dist_vadd_cancel_right _ _ _ } @[simp] lemma dist_vsub_cancel_left (x y z : P) : dist (x -ᵥ y) (x -ᵥ z) = dist y z := by rw [dist_eq_norm, vsub_sub_vsub_cancel_left, dist_comm, dist_eq_norm_vsub V] /-- Isometry between the tangent space `V` of a (semi)normed add torsor `P` and `P` given by subtraction from `x : P`. -/ @[simps] def isometry_equiv.const_vsub (x : P) : P ≃ᵢ V := { to_equiv := equiv.const_vsub x, isometry_to_fun := isometry.of_dist_eq $ λ y z, dist_vsub_cancel_left _ _ _ } @[simp] lemma dist_vsub_cancel_right (x y z : P) : dist (x -ᵥ z) (y -ᵥ z) = dist x y := (isometry_equiv.vadd_const z).symm.dist_eq x y lemma dist_vadd_vadd_le (v v' : V) (p p' : P) : dist (v +ᵥ p) (v' +ᵥ p') ≤ dist v v' + dist p p' := by simpa using dist_triangle (v +ᵥ p) (v' +ᵥ p) (v' +ᵥ p') lemma dist_vsub_vsub_le (p₁ p₂ p₃ p₄ : P) : dist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ dist p₁ p₃ + dist p₂ p₄ := by { rw [dist_eq_norm, vsub_sub_vsub_comm, dist_eq_norm_vsub V, dist_eq_norm_vsub V], exact norm_sub_le _ _ } lemma nndist_vadd_vadd_le (v v' : V) (p p' : P) : nndist (v +ᵥ p) (v' +ᵥ p') ≤ nndist v v' + nndist p p' := by simp only [← nnreal.coe_le_coe, nnreal.coe_add, ← dist_nndist, dist_vadd_vadd_le] lemma nndist_vsub_vsub_le (p₁ p₂ p₃ p₄ : P) : nndist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ nndist p₁ p₃ + nndist p₂ p₄ := by simp only [← nnreal.coe_le_coe, nnreal.coe_add, ← dist_nndist, dist_vsub_vsub_le] lemma edist_vadd_vadd_le (v v' : V) (p p' : P) : edist (v +ᵥ p) (v' +ᵥ p') ≤ edist v v' + edist p p' := by { simp only [edist_nndist], apply_mod_cast nndist_vadd_vadd_le } lemma edist_vsub_vsub_le (p₁ p₂ p₃ p₄ : P) : edist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ edist p₁ p₃ + edist p₂ p₄ := by { simp only [edist_nndist], apply_mod_cast nndist_vsub_vsub_le } omit V /-- The pseudodistance defines a pseudometric space structure on the torsor. This is not an instance because it depends on `V` to define a `metric_space P`. -/ def pseudo_metric_space_of_normed_add_comm_group_of_add_torsor (V P : Type*) [seminormed_add_comm_group V] [add_torsor V P] : pseudo_metric_space P := { dist := λ x y, ‖(x -ᵥ y : V)‖, dist_self := λ x, by simp, dist_comm := λ x y, by simp only [←neg_vsub_eq_vsub_rev y x, norm_neg], dist_triangle := begin intros x y z, change ‖x -ᵥ z‖ ≤ ‖x -ᵥ y‖ + ‖y -ᵥ z‖, rw ←vsub_add_vsub_cancel, apply norm_add_le end } /-- The distance defines a metric space structure on the torsor. This is not an instance because it depends on `V` to define a `metric_space P`. -/ def metric_space_of_normed_add_comm_group_of_add_torsor (V P : Type*) [normed_add_comm_group V] [add_torsor V P] : metric_space P := { dist := λ x y, ‖(x -ᵥ y : V)‖, dist_self := λ x, by simp, eq_of_dist_eq_zero := λ x y h, by simpa using h, dist_comm := λ x y, by simp only [←neg_vsub_eq_vsub_rev y x, norm_neg], dist_triangle := begin intros x y z, change ‖x -ᵥ z‖ ≤ ‖x -ᵥ y‖ + ‖y -ᵥ z‖, rw ←vsub_add_vsub_cancel, apply norm_add_le end } include V lemma lipschitz_with.vadd [pseudo_emetric_space α] {f : α → V} {g : α → P} {Kf Kg : ℝ≥0} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (f +ᵥ g) := λ x y, calc edist (f x +ᵥ g x) (f y +ᵥ g y) ≤ edist (f x) (f y) + edist (g x) (g y) : edist_vadd_vadd_le _ _ _ _ ... ≤ Kf * edist x y + Kg * edist x y : add_le_add (hf x y) (hg x y) ... = (Kf + Kg) * edist x y : (add_mul _ _ _).symm lemma lipschitz_with.vsub [pseudo_emetric_space α] {f g : α → P} {Kf Kg : ℝ≥0} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (f -ᵥ g) := λ x y, calc edist (f x -ᵥ g x) (f y -ᵥ g y) ≤ edist (f x) (f y) + edist (g x) (g y) : edist_vsub_vsub_le _ _ _ _ ... ≤ Kf * edist x y + Kg * edist x y : add_le_add (hf x y) (hg x y) ... = (Kf + Kg) * edist x y : (add_mul _ _ _).symm lemma uniform_continuous_vadd : uniform_continuous (λ x : V × P, x.1 +ᵥ x.2) := (lipschitz_with.prod_fst.vadd lipschitz_with.prod_snd).uniform_continuous lemma uniform_continuous_vsub : uniform_continuous (λ x : P × P, x.1 -ᵥ x.2) := (lipschitz_with.prod_fst.vsub lipschitz_with.prod_snd).uniform_continuous @[priority 100] instance normed_add_torsor.to_has_continuous_vadd : has_continuous_vadd V P := { continuous_vadd := uniform_continuous_vadd.continuous } lemma continuous_vsub : continuous (λ x : P × P, x.1 -ᵥ x.2) := uniform_continuous_vsub.continuous lemma filter.tendsto.vsub {l : filter α} {f g : α → P} {x y : P} (hf : tendsto f l (𝓝 x)) (hg : tendsto g l (𝓝 y)) : tendsto (f -ᵥ g) l (𝓝 (x -ᵥ y)) := (continuous_vsub.tendsto (x, y)).comp (hf.prod_mk_nhds hg) section variables [topological_space α] lemma continuous.vsub {f g : α → P} (hf : continuous f) (hg : continuous g) : continuous (f -ᵥ g) := continuous_vsub.comp (hf.prod_mk hg : _) lemma continuous_at.vsub {f g : α → P} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (f -ᵥ g) x := hf.vsub hg lemma continuous_within_at.vsub {f g : α → P} {x : α} {s : set α} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (f -ᵥ g) s x := hf.vsub hg end section variables {R : Type*} [ring R] [topological_space R] [module R V] [has_continuous_smul R V] lemma filter.tendsto.line_map {l : filter α} {f₁ f₂ : α → P} {g : α → R} {p₁ p₂ : P} {c : R} (h₁ : tendsto f₁ l (𝓝 p₁)) (h₂ : tendsto f₂ l (𝓝 p₂)) (hg : tendsto g l (𝓝 c)) : tendsto (λ x, affine_map.line_map (f₁ x) (f₂ x) (g x)) l (𝓝 $ affine_map.line_map p₁ p₂ c) := (hg.smul (h₂.vsub h₁)).vadd h₁ lemma filter.tendsto.midpoint [invertible (2:R)] {l : filter α} {f₁ f₂ : α → P} {p₁ p₂ : P} (h₁ : tendsto f₁ l (𝓝 p₁)) (h₂ : tendsto f₂ l (𝓝 p₂)) : tendsto (λ x, midpoint R (f₁ x) (f₂ x)) l (𝓝 $ midpoint R p₁ p₂) := h₁.line_map h₂ tendsto_const_nhds end
cd455bb353c4d9f9fa04a31ba791e6e8aa9ed27c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/list/forall2_auto.lean
29d7ed8893358aea851f921f9cb5b78aaa491698
[]
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
9,076
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.list.basic import Mathlib.PostPort universes u v w z namespace Mathlib namespace list /- forall₂ -/ theorem forall₂_iff {α : Type u} {β : Type v} (R : α → β → Prop) : ∀ (ᾰ : List α) (ᾰ_1 : List β), forall₂ R ᾰ ᾰ_1 ↔ ᾰ = [] ∧ ᾰ_1 = [] ∨ Exists fun {a : α} => Exists fun {b : β} => Exists fun {l₁ : List α} => Exists fun {l₂ : List β} => R a b ∧ forall₂ R l₁ l₂ ∧ ᾰ = a :: l₁ ∧ ᾰ_1 = b :: l₂ := sorry @[simp] theorem forall₂_cons {α : Type u} {β : Type v} {R : α → β → Prop} {a : α} {b : β} {l₁ : List α} {l₂ : List β} : forall₂ R (a :: l₁) (b :: l₂) ↔ R a b ∧ forall₂ R l₁ l₂ := sorry theorem forall₂.imp {α : Type u} {β : Type v} {R : α → β → Prop} {S : α → β → Prop} (H : ∀ (a : α) (b : β), R a b → S a b) {l₁ : List α} {l₂ : List β} (h : forall₂ R l₁ l₂) : forall₂ S l₁ l₂ := sorry theorem forall₂.mp {α : Type u} {β : Type v} {r : α → β → Prop} {q : α → β → Prop} {s : α → β → Prop} (h : ∀ (a : α) (b : β), r a b → q a b → s a b) {l₁ : List α} {l₂ : List β} : forall₂ r l₁ l₂ → forall₂ q l₁ l₂ → forall₂ s l₁ l₂ := sorry theorem forall₂.flip {α : Type u} {β : Type v} {r : α → β → Prop} {a : List α} {b : List β} : forall₂ (flip r) b a → forall₂ r a b := sorry theorem forall₂_same {α : Type u} {r : α → α → Prop} {l : List α} : (∀ (x : α), x ∈ l → r x x) → forall₂ r l l := sorry theorem forall₂_refl {α : Type u} {r : α → α → Prop} [is_refl α r] (l : List α) : forall₂ r l l := forall₂_same fun (a : α) (h : a ∈ l) => is_refl.refl a theorem forall₂_eq_eq_eq {α : Type u} : forall₂ Eq = Eq := sorry @[simp] theorem forall₂_nil_left_iff {α : Type u} {β : Type v} {r : α → β → Prop} {l : List β} : forall₂ r [] l ↔ l = [] := sorry @[simp] theorem forall₂_nil_right_iff {α : Type u} {β : Type v} {r : α → β → Prop} {l : List α} : forall₂ r l [] ↔ l = [] := sorry theorem forall₂_cons_left_iff {α : Type u} {β : Type v} {r : α → β → Prop} {a : α} {l : List α} {u : List β} : forall₂ r (a :: l) u ↔ ∃ (b : β), ∃ (u' : List β), r a b ∧ forall₂ r l u' ∧ u = b :: u' := sorry theorem forall₂_cons_right_iff {α : Type u} {β : Type v} {r : α → β → Prop} {b : β} {l : List β} {u : List α} : forall₂ r u (b :: l) ↔ ∃ (a : α), ∃ (u' : List α), r a b ∧ forall₂ r u' l ∧ u = a :: u' := sorry theorem forall₂_and_left {α : Type u} {β : Type v} {r : α → β → Prop} {p : α → Prop} (l : List α) (u : List β) : forall₂ (fun (a : α) (b : β) => p a ∧ r a b) l u ↔ (∀ (a : α), a ∈ l → p a) ∧ forall₂ r l u := sorry @[simp] theorem forall₂_map_left_iff {α : Type u} {β : Type v} {γ : Type w} {r : α → β → Prop} {f : γ → α} {l : List γ} {u : List β} : forall₂ r (map f l) u ↔ forall₂ (fun (c : γ) (b : β) => r (f c) b) l u := sorry @[simp] theorem forall₂_map_right_iff {α : Type u} {β : Type v} {γ : Type w} {r : α → β → Prop} {f : γ → β} {l : List α} {u : List γ} : forall₂ r l (map f u) ↔ forall₂ (fun (a : α) (c : γ) => r a (f c)) l u := sorry theorem left_unique_forall₂ {α : Type u} {β : Type v} {r : α → β → Prop} (hr : relator.left_unique r) : relator.left_unique (forall₂ r) := sorry theorem right_unique_forall₂ {α : Type u} {β : Type v} {r : α → β → Prop} (hr : relator.right_unique r) : relator.right_unique (forall₂ r) := sorry theorem bi_unique_forall₂ {α : Type u} {β : Type v} {r : α → β → Prop} (hr : relator.bi_unique r) : relator.bi_unique (forall₂ r) := { left := fun (a : List α) (b : List β) (c : List α) => left_unique_forall₂ (and.left hr), right := fun (a : List α) (b c : List β) => right_unique_forall₂ (and.right hr) } theorem forall₂_length_eq {α : Type u} {β : Type v} {R : α → β → Prop} {l₁ : List α} {l₂ : List β} : forall₂ R l₁ l₂ → length l₁ = length l₂ := sorry theorem forall₂_zip {α : Type u} {β : Type v} {R : α → β → Prop} {l₁ : List α} {l₂ : List β} : forall₂ R l₁ l₂ → ∀ {a : α} {b : β}, (a, b) ∈ zip l₁ l₂ → R a b := sorry theorem forall₂_iff_zip {α : Type u} {β : Type v} {R : α → β → Prop} {l₁ : List α} {l₂ : List β} : forall₂ R l₁ l₂ ↔ length l₁ = length l₂ ∧ ∀ {a : α} {b : β}, (a, b) ∈ zip l₁ l₂ → R a b := sorry theorem forall₂_take {α : Type u} {β : Type v} {R : α → β → Prop} (n : ℕ) {l₁ : List α} {l₂ : List β} : forall₂ R l₁ l₂ → forall₂ R (take n l₁) (take n l₂) := sorry theorem forall₂_drop {α : Type u} {β : Type v} {R : α → β → Prop} (n : ℕ) {l₁ : List α} {l₂ : List β} : forall₂ R l₁ l₂ → forall₂ R (drop n l₁) (drop n l₂) := sorry theorem forall₂_take_append {α : Type u} {β : Type v} {R : α → β → Prop} (l : List α) (l₁ : List β) (l₂ : List β) (h : forall₂ R l (l₁ ++ l₂)) : forall₂ R (take (length l₁) l) l₁ := (fun (h' : forall₂ R (take (length l₁) l) (take (length l₁) (l₁ ++ l₂))) => eq.mp (Eq._oldrec (Eq.refl (forall₂ R (take (length l₁) l) (take (length l₁) (l₁ ++ l₂)))) (take_left l₁ l₂)) h') (forall₂_take (length l₁) h) theorem forall₂_drop_append {α : Type u} {β : Type v} {R : α → β → Prop} (l : List α) (l₁ : List β) (l₂ : List β) (h : forall₂ R l (l₁ ++ l₂)) : forall₂ R (drop (length l₁) l) l₂ := (fun (h' : forall₂ R (drop (length l₁) l) (drop (length l₁) (l₁ ++ l₂))) => eq.mp (Eq._oldrec (Eq.refl (forall₂ R (drop (length l₁) l) (drop (length l₁) (l₁ ++ l₂)))) (drop_left l₁ l₂)) h') (forall₂_drop (length l₁) h) theorem rel_mem {α : Type u} {β : Type v} {r : α → β → Prop} (hr : relator.bi_unique r) : relator.lift_fun r (forall₂ r ⇒ Iff) has_mem.mem has_mem.mem := sorry theorem rel_map {α : Type u} {β : Type v} {γ : Type w} {δ : Type z} {r : α → β → Prop} {p : γ → δ → Prop} : relator.lift_fun (r ⇒ p) (forall₂ r ⇒ forall₂ p) map map := sorry theorem rel_append {α : Type u} {β : Type v} {r : α → β → Prop} : relator.lift_fun (forall₂ r) (forall₂ r ⇒ forall₂ r) append append := sorry theorem rel_join {α : Type u} {β : Type v} {r : α → β → Prop} : relator.lift_fun (forall₂ (forall₂ r)) (forall₂ r) join join := sorry theorem rel_bind {α : Type u} {β : Type v} {γ : Type w} {δ : Type z} {r : α → β → Prop} {p : γ → δ → Prop} : relator.lift_fun (forall₂ r) ((r ⇒ forall₂ p) ⇒ forall₂ p) list.bind list.bind := fun (a : List α) (b : List β) (h₁ : forall₂ r a b) (f : α → List γ) (g : β → List δ) (h₂ : relator.lift_fun r (forall₂ p) f g) => rel_join (rel_map h₂ h₁) theorem rel_foldl {α : Type u} {β : Type v} {γ : Type w} {δ : Type z} {r : α → β → Prop} {p : γ → δ → Prop} : relator.lift_fun (p ⇒ r ⇒ p) (p ⇒ forall₂ r ⇒ p) foldl foldl := sorry theorem rel_foldr {α : Type u} {β : Type v} {γ : Type w} {δ : Type z} {r : α → β → Prop} {p : γ → δ → Prop} : relator.lift_fun (r ⇒ p ⇒ p) (p ⇒ forall₂ r ⇒ p) foldr foldr := sorry theorem rel_filter {α : Type u} {β : Type v} {r : α → β → Prop} {p : α → Prop} {q : β → Prop} [decidable_pred p] [decidable_pred q] (hpq : relator.lift_fun r Iff p q) : relator.lift_fun (forall₂ r) (forall₂ r) (filter p) (filter q) := sorry theorem filter_map_cons {α : Type u} {β : Type v} (f : α → Option β) (a : α) (l : List α) : filter_map f (a :: l) = option.cases_on (f a) (filter_map f l) fun (b : β) => b :: filter_map f l := sorry theorem rel_filter_map {α : Type u} {β : Type v} {γ : Type w} {δ : Type z} {r : α → β → Prop} {p : γ → δ → Prop} : relator.lift_fun (r ⇒ option.rel p) (forall₂ r ⇒ forall₂ p) filter_map filter_map := sorry theorem rel_sum {α : Type u} {β : Type v} {r : α → β → Prop} [add_monoid α] [add_monoid β] (h : r 0 0) (hf : relator.lift_fun r (r ⇒ r) Add.add Add.add) : relator.lift_fun (forall₂ r) r sum sum := rel_foldl hf h end Mathlib
50331bf6ee9e4a7d3321591bb97db23fb9d8011a
02fbe05a45fda5abde7583464416db4366eedfbf
/library/init/data/int/order.lean
3659f655f6646a711cbed06f03949e816d3168c3
[ "Apache-2.0" ]
permissive
jasonrute/lean
cc12807e11f9ac6b01b8951a8bfb9c2eb35a0154
4be962c167ca442a0ec5e84472d7ff9f5302788f
refs/heads/master
1,672,036,664,637
1,601,642,826,000
1,601,642,826,000
260,777,966
0
0
Apache-2.0
1,588,454,819,000
1,588,454,818,000
null
UTF-8
Lean
false
false
36,964
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad The order relation on the integers. -/ prelude import init.data.int.basic init.data.ordering.basic namespace int def nonneg (a : ℤ) : Prop := int.cases_on a (assume n, true) (assume n, false) protected def le (a b : ℤ) : Prop := nonneg (b - a) instance : has_le int := ⟨int.le⟩ protected def lt (a b : ℤ) : Prop := (a + 1) ≤ b instance : has_lt int := ⟨int.lt⟩ def decidable_nonneg (a : ℤ) : decidable (nonneg a) := int.cases_on a (assume a, decidable.true) (assume a, decidable.false) instance decidable_le (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _ instance decidable_lt (a b : ℤ) : decidable (a < b) := decidable_nonneg _ lemma lt_iff_add_one_le (a b : ℤ) : a < b ↔ a + 1 ≤ b := iff.refl _ lemma nonneg.elim {a : ℤ} : nonneg a → ∃ n : ℕ, a = n := int.cases_on a (assume n H, exists.intro n rfl) (assume n', false.elim) lemma nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) := int.cases_on a (assume n, or.inl trivial) (assume n, or.inr trivial) lemma le.intro_sub {a b : ℤ} {n : ℕ} (h : b - a = n) : a ≤ b := show nonneg (b - a), by rw h; trivial local attribute [simp] int.sub_eq_add_neg int.add_assoc int.add_right_neg int.add_left_neg int.zero_add int.add_zero int.neg_add int.neg_neg int.neg_zero lemma le.intro {a b : ℤ} {n : ℕ} (h : a + n = b) : a ≤ b := le.intro_sub (by rw [← h, int.add_comm]; simp) lemma le.dest_sub {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, b - a = n := nonneg.elim h lemma le.dest {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, a + n = b := match (le.dest_sub h) with | ⟨n, h₁⟩ := exists.intro n begin rw [← h₁, int.add_comm], simp end end lemma le.elim {a b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ n : ℕ, a + ↑n = b → P) : P := exists.elim (le.dest h) h' protected lemma le_total (a b : ℤ) : a ≤ b ∨ b ≤ a := or.imp_right (assume H : nonneg (-(b - a)), have -(b - a) = a - b, by simp [int.add_comm], show nonneg (a - b), from this ▸ H) (nonneg_or_nonneg_neg (b - a)) lemma coe_nat_le_coe_nat_of_le {m n : ℕ} (h : m ≤ n) : (↑m : ℤ) ≤ ↑n := match nat.le.dest h with | ⟨k, (hk : m + k = n)⟩ := le.intro (begin rw [← hk], reflexivity end) end lemma le_of_coe_nat_le_coe_nat {m n : ℕ} (h : (↑m : ℤ) ≤ ↑n) : m ≤ n := le.elim h (assume k, assume hk : ↑m + ↑k = ↑n, have m + k = n, from int.coe_nat_inj ((int.coe_nat_add m k).trans hk), nat.le.intro this) lemma coe_nat_le_coe_nat_iff (m n : ℕ) : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := iff.intro le_of_coe_nat_le_coe_nat coe_nat_le_coe_nat_of_le lemma coe_zero_le (n : ℕ) : 0 ≤ (↑n : ℤ) := coe_nat_le_coe_nat_of_le n.zero_le lemma eq_coe_of_zero_le {a : ℤ} (h : 0 ≤ a) : ∃ n : ℕ, a = n := by { have t := le.dest_sub h, simp at t, exact t } lemma eq_succ_of_zero_lt {a : ℤ} (h : 0 < a) : ∃ n : ℕ, a = n.succ := let ⟨n, (h : ↑(1+n) = a)⟩ := le.dest h in ⟨n, by rw nat.add_comm at h; exact h.symm⟩ lemma lt_add_succ (a : ℤ) (n : ℕ) : a < a + ↑(nat.succ n) := le.intro (show a + 1 + n = a + nat.succ n, begin simp [int.coe_nat_eq, int.add_comm, int.add_left_comm], reflexivity end) lemma lt.intro {a b : ℤ} {n : ℕ} (h : a + nat.succ n = b) : a < b := h ▸ lt_add_succ a n lemma lt.dest {a b : ℤ} (h : a < b) : ∃ n : ℕ, a + ↑(nat.succ n) = b := le.elim h (assume n, assume hn : a + 1 + n = b, exists.intro n begin rw [← hn, int.add_assoc, int.add_comm 1], reflexivity end) lemma lt.elim {a b : ℤ} (h : a < b) {P : Prop} (h' : ∀ n : ℕ, a + ↑(nat.succ n) = b → P) : P := exists.elim (lt.dest h) h' lemma coe_nat_lt_coe_nat_iff (n m : ℕ) : (↑n : ℤ) < ↑m ↔ n < m := begin rw [lt_iff_add_one_le, ← int.coe_nat_succ, coe_nat_le_coe_nat_iff], reflexivity end lemma lt_of_coe_nat_lt_coe_nat {m n : ℕ} (h : (↑m : ℤ) < ↑n) : m < n := (coe_nat_lt_coe_nat_iff _ _).mp h lemma coe_nat_lt_coe_nat_of_lt {m n : ℕ} (h : m < n) : (↑m : ℤ) < ↑n := (coe_nat_lt_coe_nat_iff _ _).mpr h /- show that the integers form an ordered additive group -/ protected lemma le_refl (a : ℤ) : a ≤ a := le.intro (int.add_zero a) protected lemma le_trans {a b c : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c := le.elim h₁ (assume n, assume hn : a + n = b, le.elim h₂ (assume m, assume hm : b + m = c, begin apply le.intro, rw [← hm, ← hn, int.add_assoc], reflexivity end)) protected lemma le_antisymm {a b : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ a) : a = b := le.elim h₁ (assume n, assume hn : a + n = b, le.elim h₂ (assume m, assume hm : b + m = a, have a + ↑(n + m) = a + 0, by rw [int.coe_nat_add, ← int.add_assoc, hn, hm, int.add_zero a], have (↑(n + m) : ℤ) = 0, from int.add_left_cancel this, have n + m = 0, from int.coe_nat_inj this, have n = 0, from nat.eq_zero_of_add_eq_zero_right this, show a = b, begin rw [← hn, this, int.coe_nat_zero, int.add_zero a] end)) protected lemma lt_irrefl (a : ℤ) : ¬ a < a := assume : a < a, lt.elim this (assume n, assume hn : a + nat.succ n = a, have a + nat.succ n = a + 0, by rw [hn, int.add_zero], have nat.succ n = 0, from int.coe_nat_inj (int.add_left_cancel this), show false, from nat.succ_ne_zero _ this) protected lemma ne_of_lt {a b : ℤ} (h : a < b) : a ≠ b := (assume : a = b, absurd (begin rewrite this at h, exact h end) (int.lt_irrefl b)) lemma le_of_lt {a b : ℤ} (h : a < b) : a ≤ b := lt.elim h (assume n, assume hn : a + nat.succ n = b, le.intro hn) protected lemma lt_iff_le_and_ne (a b : ℤ) : a < b ↔ (a ≤ b ∧ a ≠ b) := iff.intro (assume h, ⟨le_of_lt h, int.ne_of_lt h⟩) (assume ⟨aleb, aneb⟩, le.elim aleb (assume n, assume hn : a + n = b, have n ≠ 0, from (assume : n = 0, aneb begin rw [← hn, this, int.coe_nat_zero, int.add_zero] end), have n = nat.succ (nat.pred n), from eq.symm (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero this)), lt.intro (begin rewrite this at hn, exact hn end))) lemma lt_succ (a : ℤ) : a < a + 1 := int.le_refl (a + 1) protected lemma add_le_add_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c + a ≤ c + b := le.elim h (assume n, assume hn : a + n = b, le.intro (show c + a + n = c + b, begin rw [int.add_assoc, hn] end)) protected lemma add_lt_add_left {a b : ℤ} (h : a < b) (c : ℤ) : c + a < c + b := iff.mpr (int.lt_iff_le_and_ne _ _) (and.intro (int.add_le_add_left (le_of_lt h) _) (assume heq, int.lt_irrefl b begin rw int.add_left_cancel heq at h, exact h end)) protected lemma mul_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := le.elim ha (assume n, assume hn, le.elim hb (assume m, assume hm, le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], simp [int.zero_add] end))) protected lemma mul_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b := lt.elim ha (assume n, assume hn, lt.elim hb (assume m, assume hm, lt.intro (show 0 + ↑(nat.succ (nat.succ n * m + n)) = a * b, begin rw [← hn, ← hm], simp [int.coe_nat_zero], rw [← int.coe_nat_mul], simp [nat.mul_succ, nat.succ_add] end))) protected lemma zero_lt_one : (0 : ℤ) < 1 := trivial protected lemma lt_iff_le_not_le {a b : ℤ} : a < b ↔ (a ≤ b ∧ ¬ b ≤ a) := begin simp [int.lt_iff_le_and_ne], split; intro h, { cases h with hab hn, split, { assumption }, { intro hba, simp [int.le_antisymm hab hba] at *, contradiction } }, { cases h with hab hn, split, { assumption }, { intro h, simp [*] at * } } end instance : decidable_linear_order int := { le := int.le, le_refl := int.le_refl, le_trans := @int.le_trans, le_antisymm := @int.le_antisymm, lt := int.lt, lt_iff_le_not_le := @int.lt_iff_le_not_le, le_total := int.le_total, decidable_eq := int.decidable_eq, decidable_le := int.decidable_le, decidable_lt := int.decidable_lt } lemma eq_nat_abs_of_zero_le {a : ℤ} (h : 0 ≤ a) : a = nat_abs a := let ⟨n, e⟩ := eq_coe_of_zero_le h in by rw e; refl lemma le_nat_abs {a : ℤ} : a ≤ nat_abs a := or.elim (le_total 0 a) (λh, by rw eq_nat_abs_of_zero_le h; refl) (λh, le_trans h (coe_zero_le _)) lemma neg_succ_lt_zero (n : ℕ) : -[1+ n] < 0 := lt_of_not_ge $ λ h, let ⟨m, h⟩ := eq_coe_of_zero_le h in by contradiction lemma eq_neg_succ_of_lt_zero : ∀ {a : ℤ}, a < 0 → ∃ n : ℕ, a = -[1+ n] | (n : ℕ) h := absurd h (not_lt_of_ge (coe_zero_le _)) | -[1+ n] h := ⟨n, rfl⟩ /- int is an ordered add comm group -/ protected lemma eq_neg_of_eq_neg {a b : ℤ} (h : a = -b) : b = -a := by rw [h, int.neg_neg] protected lemma neg_add_cancel_left (a b : ℤ) : -a + (a + b) = b := by rw [← int.add_assoc, int.add_left_neg, int.zero_add] protected lemma add_neg_cancel_left (a b : ℤ) : a + (-a + b) = b := by rw [← int.add_assoc, int.add_right_neg, int.zero_add] protected lemma add_neg_cancel_right (a b : ℤ) : a + b + -b = a := by rw [int.add_assoc, int.add_right_neg, int.add_zero] protected lemma neg_add_cancel_right (a b : ℤ) : a + -b + b = a := by rw [int.add_assoc, int.add_left_neg, int.add_zero] protected lemma sub_self (a : ℤ) : a - a = 0 := by rw [int.sub_eq_add_neg, int.add_right_neg] protected lemma sub_eq_zero_of_eq {a b : ℤ} (h : a = b) : a - b = 0 := by rw [h, int.sub_self] protected lemma eq_of_sub_eq_zero {a b : ℤ} (h : a - b = 0) : a = b := have 0 + b = b, by rw int.zero_add, have (a - b) + b = b, by rwa h, by rwa [int.sub_eq_add_neg, int.neg_add_cancel_right] at this protected lemma sub_eq_zero_iff_eq {a b : ℤ} : a - b = 0 ↔ a = b := ⟨int.eq_of_sub_eq_zero, int.sub_eq_zero_of_eq⟩ @[simp] protected lemma neg_eq_of_add_eq_zero {a b : ℤ} (h : a + b = 0) : -a = b := by rw [← int.add_zero (-a), ←h, ←int.add_assoc, int.add_left_neg, int.zero_add] protected lemma neg_mul_eq_neg_mul (a b : ℤ) : -(a * b) = -a * b := int.neg_eq_of_add_eq_zero begin rw [← int.distrib_right, int.add_right_neg, int.zero_mul] end protected lemma neg_mul_eq_mul_neg (a b : ℤ) : -(a * b) = a * -b := int.neg_eq_of_add_eq_zero begin rw [← int.distrib_left, int.add_right_neg, int.mul_zero] end @[simp] lemma neg_mul_eq_neg_mul_symm (a b : ℤ) : - a * b = - (a * b) := eq.symm (int.neg_mul_eq_neg_mul a b) @[simp] lemma mul_neg_eq_neg_mul_symm (a b : ℤ) : a * - b = - (a * b) := eq.symm (int.neg_mul_eq_mul_neg a b) protected lemma neg_mul_neg (a b : ℤ) : -a * -b = a * b := by simp protected lemma neg_mul_comm (a b : ℤ) : -a * b = a * -b := by simp protected lemma mul_sub (a b c : ℤ) : a * (b - c) = a * b - a * c := calc a * (b - c) = a * b + a * -c : int.distrib_left a b (-c) ... = a * b - a * c : by simp protected lemma sub_mul (a b c : ℤ) : (a - b) * c = a * c - b * c := calc (a - b) * c = a * c + -b * c : int.distrib_right a (-b) c ... = a * c - b * c : by simp section protected lemma le_of_add_le_add_left {a b c : ℤ} (h : a + b ≤ a + c) : b ≤ c := have -a + (a + b) ≤ -a + (a + c), from int.add_le_add_left h _, begin simp [int.neg_add_cancel_left] at this, assumption end protected lemma lt_of_add_lt_add_left {a b c : ℤ} (h : a + b < a + c) : b < c := have -a + (a + b) < -a + (a + c), from int.add_lt_add_left h _, begin simp [int.neg_add_cancel_left] at this, assumption end protected lemma add_le_add_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a + c ≤ b + c := int.add_comm c a ▸ int.add_comm c b ▸ int.add_le_add_left h c protected theorem add_lt_add_right {a b : ℤ} (h : a < b) (c : ℤ) : a + c < b + c := begin rw [int.add_comm a c, int.add_comm b c], exact (int.add_lt_add_left h c) end protected lemma add_le_add {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d := le_trans (int.add_le_add_right h₁ c) (int.add_le_add_left h₂ b) protected lemma le_add_of_nonneg_right {a b : ℤ} (h : b ≥ 0) : a ≤ a + b := have a + b ≥ a + 0, from int.add_le_add_left h a, by rwa int.add_zero at this protected lemma le_add_of_nonneg_left {a b : ℤ} (h : b ≥ 0) : a ≤ b + a := have 0 + a ≤ b + a, from int.add_le_add_right h a, by rwa int.zero_add at this protected lemma add_lt_add {a b c d : ℤ} (h₁ : a < b) (h₂ : c < d) : a + c < b + d := lt_trans (int.add_lt_add_right h₁ c) (int.add_lt_add_left h₂ b) protected lemma add_lt_add_of_le_of_lt {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c < d) : a + c < b + d := lt_of_le_of_lt (int.add_le_add_right h₁ c) (int.add_lt_add_left h₂ b) protected lemma add_lt_add_of_lt_of_le {a b c d : ℤ} (h₁ : a < b) (h₂ : c ≤ d) : a + c < b + d := lt_of_lt_of_le (int.add_lt_add_right h₁ c) (int.add_le_add_left h₂ b) protected lemma lt_add_of_pos_right (a : ℤ) {b : ℤ} (h : b > 0) : a < a + b := have a + 0 < a + b, from int.add_lt_add_left h a, by rwa [int.add_zero] at this protected lemma lt_add_of_pos_left (a : ℤ) {b : ℤ} (h : b > 0) : a < b + a := have 0 + a < b + a, from int.add_lt_add_right h a, by rwa [int.zero_add] at this protected lemma le_of_add_le_add_right {a b c : ℤ} (h : a + b ≤ c + b) : a ≤ c := int.le_of_add_le_add_left (show b + a ≤ b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end) protected lemma lt_of_add_lt_add_right {a b c : ℤ} (h : a + b < c + b) : a < c := int.lt_of_add_lt_add_left (show b + a < b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end) -- here we start using properties of zero. protected lemma add_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b := int.zero_add (0:ℤ) ▸ (int.add_le_add ha hb) protected lemma add_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a + b := int.zero_add (0:ℤ) ▸ (int.add_lt_add ha hb) protected lemma add_pos_of_pos_of_nonneg {a b : ℤ} (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b := int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_lt_of_le ha hb) protected lemma add_pos_of_nonneg_of_pos {a b : ℤ} (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b := int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_le_of_lt ha hb) protected lemma add_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 := int.zero_add (0:ℤ) ▸ (int.add_le_add ha hb) protected lemma add_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : a + b < 0 := int.zero_add (0:ℤ) ▸ (int.add_lt_add ha hb) protected lemma add_neg_of_neg_of_nonpos {a b : ℤ} (ha : a < 0) (hb : b ≤ 0) : a + b < 0 := int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_lt_of_le ha hb) protected lemma add_neg_of_nonpos_of_neg {a b : ℤ} (ha : a ≤ 0) (hb : b < 0) : a + b < 0 := int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_le_of_lt ha hb) protected lemma lt_add_of_le_of_pos {a b c : ℤ} (hbc : b ≤ c) (ha : 0 < a) : b < c + a := int.add_zero b ▸ int.add_lt_add_of_le_of_lt hbc ha protected lemma sub_add_cancel (a b : ℤ) : a - b + b = a := int.neg_add_cancel_right a b protected lemma add_sub_cancel (a b : ℤ) : a + b - b = a := int.add_neg_cancel_right a b protected lemma add_sub_assoc (a b c : ℤ) : a + b - c = a + (b - c) := by rw [int.sub_eq_add_neg, int.add_assoc, ←int.sub_eq_add_neg] protected lemma neg_le_neg {a b : ℤ} (h : a ≤ b) : -b ≤ -a := have 0 ≤ -a + b, from int.add_left_neg a ▸ int.add_le_add_left h (-a), have 0 + -b ≤ -a + b + -b, from int.add_le_add_right this (-b), by rwa [int.add_neg_cancel_right, int.zero_add] at this protected lemma le_of_neg_le_neg {a b : ℤ} (h : -b ≤ -a) : a ≤ b := suffices -(-a) ≤ -(-b), from begin simp [int.neg_neg] at this, assumption end, int.neg_le_neg h protected lemma nonneg_of_neg_nonpos {a : ℤ} (h : -a ≤ 0) : 0 ≤ a := have -a ≤ -0, by rwa int.neg_zero, int.le_of_neg_le_neg this protected lemma neg_nonpos_of_nonneg {a : ℤ} (h : 0 ≤ a) : -a ≤ 0 := have -a ≤ -0, from int.neg_le_neg h, by rwa int.neg_zero at this protected lemma nonpos_of_neg_nonneg {a : ℤ} (h : 0 ≤ -a) : a ≤ 0 := have -0 ≤ -a, by rwa int.neg_zero, int.le_of_neg_le_neg this protected lemma neg_nonneg_of_nonpos {a : ℤ} (h : a ≤ 0) : 0 ≤ -a := have -0 ≤ -a, from int.neg_le_neg h, by rwa int.neg_zero at this protected lemma neg_lt_neg {a b : ℤ} (h : a < b) : -b < -a := have 0 < -a + b, from int.add_left_neg a ▸ int.add_lt_add_left h (-a), have 0 + -b < -a + b + -b, from int.add_lt_add_right this (-b), by rwa [int.add_neg_cancel_right, int.zero_add] at this protected lemma lt_of_neg_lt_neg {a b : ℤ} (h : -b < -a) : a < b := int.neg_neg a ▸ int.neg_neg b ▸ int.neg_lt_neg h protected lemma pos_of_neg_neg {a : ℤ} (h : -a < 0) : 0 < a := have -a < -0, by rwa int.neg_zero, int.lt_of_neg_lt_neg this protected lemma neg_neg_of_pos {a : ℤ} (h : 0 < a) : -a < 0 := have -a < -0, from int.neg_lt_neg h, by rwa int.neg_zero at this protected lemma neg_of_neg_pos {a : ℤ} (h : 0 < -a) : a < 0 := have -0 < -a, by rwa int.neg_zero, int.lt_of_neg_lt_neg this protected lemma neg_pos_of_neg {a : ℤ} (h : a < 0) : 0 < -a := have -0 < -a, from int.neg_lt_neg h, by rwa int.neg_zero at this protected lemma le_neg_of_le_neg {a b : ℤ} (h : a ≤ -b) : b ≤ -a := begin have h := int.neg_le_neg h, rwa int.neg_neg at h end protected lemma neg_le_of_neg_le {a b : ℤ} (h : -a ≤ b) : -b ≤ a := begin have h := int.neg_le_neg h, rwa int.neg_neg at h end protected lemma lt_neg_of_lt_neg {a b : ℤ} (h : a < -b) : b < -a := begin have h := int.neg_lt_neg h, rwa int.neg_neg at h end protected lemma neg_lt_of_neg_lt {a b : ℤ} (h : -a < b) : -b < a := begin have h := int.neg_lt_neg h, rwa int.neg_neg at h end protected lemma sub_nonneg_of_le {a b : ℤ} (h : b ≤ a) : 0 ≤ a - b := begin have h := int.add_le_add_right h (-b), rwa int.add_right_neg at h end protected lemma le_of_sub_nonneg {a b : ℤ} (h : 0 ≤ a - b) : b ≤ a := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_nonpos_of_le {a b : ℤ} (h : a ≤ b) : a - b ≤ 0 := begin have h := int.add_le_add_right h (-b), rwa int.add_right_neg at h end protected lemma le_of_sub_nonpos {a b : ℤ} (h : a - b ≤ 0) : a ≤ b := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_pos_of_lt {a b : ℤ} (h : b < a) : 0 < a - b := begin have h := int.add_lt_add_right h (-b), rwa int.add_right_neg at h end protected lemma lt_of_sub_pos {a b : ℤ} (h : 0 < a - b) : b < a := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_neg_of_lt {a b : ℤ} (h : a < b) : a - b < 0 := begin have h := int.add_lt_add_right h (-b), rwa int.add_right_neg at h end protected lemma lt_of_sub_neg {a b : ℤ} (h : a - b < 0) : a < b := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma add_le_of_le_neg_add {a b c : ℤ} (h : b ≤ -a + c) : a + b ≤ c := begin have h := int.add_le_add_left h a, rwa int.add_neg_cancel_left at h end protected lemma le_neg_add_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ -a + c := begin have h := int.add_le_add_left h (-a), rwa int.neg_add_cancel_left at h end protected lemma add_le_of_le_sub_left {a b c : ℤ} (h : b ≤ c - a) : a + b ≤ c := begin have h := int.add_le_add_left h a, rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h end protected lemma le_sub_left_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ c - a := begin have h := int.add_le_add_right h (-a), rwa [int.add_comm a b, int.add_neg_cancel_right] at h end protected lemma add_le_of_le_sub_right {a b c : ℤ} (h : a ≤ c - b) : a + b ≤ c := begin have h := int.add_le_add_right h b, rwa int.sub_add_cancel at h end protected lemma le_sub_right_of_add_le {a b c : ℤ} (h : a + b ≤ c) : a ≤ c - b := begin have h := int.add_le_add_right h (-b), rwa int.add_neg_cancel_right at h end protected lemma le_add_of_neg_add_le {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c := begin have h := int.add_le_add_left h b, rwa int.add_neg_cancel_left at h end protected lemma neg_add_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c := begin have h := int.add_le_add_left h (-b), rwa int.neg_add_cancel_left at h end protected lemma le_add_of_sub_left_le {a b c : ℤ} (h : a - b ≤ c) : a ≤ b + c := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.add_comm] at h end protected lemma sub_left_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - b ≤ c := begin have h := int.add_le_add_right h (-b), rwa [int.add_comm b c, int.add_neg_cancel_right] at h end protected lemma le_add_of_sub_right_le {a b c : ℤ} (h : a - c ≤ b) : a ≤ b + c := begin have h := int.add_le_add_right h c, rwa int.sub_add_cancel at h end protected lemma sub_right_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - c ≤ b := begin have h := int.add_le_add_right h (-c), rwa int.add_neg_cancel_right at h end protected lemma le_add_of_neg_add_le_left {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c := begin rw int.add_comm at h, exact int.le_add_of_sub_left_le h end protected lemma neg_add_le_left_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c := begin rw int.add_comm, exact int.sub_left_le_of_le_add h end protected lemma le_add_of_neg_add_le_right {a b c : ℤ} (h : -c + a ≤ b) : a ≤ b + c := begin rw int.add_comm at h, exact int.le_add_of_sub_right_le h end protected lemma neg_add_le_right_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -c + a ≤ b := begin rw int.add_comm at h, exact int.neg_add_le_left_of_le_add h end protected lemma le_add_of_neg_le_sub_left {a b c : ℤ} (h : -a ≤ b - c) : c ≤ a + b := int.le_add_of_neg_add_le_left (int.add_le_of_le_sub_right h) protected lemma neg_le_sub_left_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -a ≤ b - c := begin have h := int.le_neg_add_of_add_le (int.sub_left_le_of_le_add h), rwa int.add_comm at h end protected lemma le_add_of_neg_le_sub_right {a b c : ℤ} (h : -b ≤ a - c) : c ≤ a + b := int.le_add_of_sub_right_le (int.add_le_of_le_sub_left h) protected lemma neg_le_sub_right_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -b ≤ a - c := int.le_sub_left_of_add_le (int.sub_right_le_of_le_add h) protected lemma sub_le_of_sub_le {a b c : ℤ} (h : a - b ≤ c) : a - c ≤ b := int.sub_left_le_of_le_add (int.le_add_of_sub_right_le h) protected lemma sub_le_sub_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c - b ≤ c - a := int.add_le_add_left (int.neg_le_neg h) c protected lemma sub_le_sub_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a - c ≤ b - c := int.add_le_add_right h (-c) protected lemma sub_le_sub {a b c d : ℤ} (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := int.add_le_add hab (int.neg_le_neg hcd) protected lemma add_lt_of_lt_neg_add {a b c : ℤ} (h : b < -a + c) : a + b < c := begin have h := int.add_lt_add_left h a, rwa int.add_neg_cancel_left at h end protected lemma lt_neg_add_of_add_lt {a b c : ℤ} (h : a + b < c) : b < -a + c := begin have h := int.add_lt_add_left h (-a), rwa int.neg_add_cancel_left at h end protected lemma add_lt_of_lt_sub_left {a b c : ℤ} (h : b < c - a) : a + b < c := begin have h := int.add_lt_add_left h a, rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h end protected lemma lt_sub_left_of_add_lt {a b c : ℤ} (h : a + b < c) : b < c - a := begin have h := int.add_lt_add_right h (-a), rwa [int.add_comm a b, int.add_neg_cancel_right] at h end protected lemma add_lt_of_lt_sub_right {a b c : ℤ} (h : a < c - b) : a + b < c := begin have h := int.add_lt_add_right h b, rwa int.sub_add_cancel at h end protected lemma lt_sub_right_of_add_lt {a b c : ℤ} (h : a + b < c) : a < c - b := begin have h := int.add_lt_add_right h (-b), rwa int.add_neg_cancel_right at h end protected lemma lt_add_of_neg_add_lt {a b c : ℤ} (h : -b + a < c) : a < b + c := begin have h := int.add_lt_add_left h b, rwa int.add_neg_cancel_left at h end protected lemma neg_add_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c := begin have h := int.add_lt_add_left h (-b), rwa int.neg_add_cancel_left at h end protected lemma lt_add_of_sub_left_lt {a b c : ℤ} (h : a - b < c) : a < b + c := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.add_comm] at h end protected lemma sub_left_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - b < c := begin have h := int.add_lt_add_right h (-b), rwa [int.add_comm b c, int.add_neg_cancel_right] at h end protected lemma lt_add_of_sub_right_lt {a b c : ℤ} (h : a - c < b) : a < b + c := begin have h := int.add_lt_add_right h c, rwa int.sub_add_cancel at h end protected lemma sub_right_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - c < b := begin have h := int.add_lt_add_right h (-c), rwa int.add_neg_cancel_right at h end protected lemma lt_add_of_neg_add_lt_left {a b c : ℤ} (h : -b + a < c) : a < b + c := begin rw int.add_comm at h, exact int.lt_add_of_sub_left_lt h end protected lemma neg_add_lt_left_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c := begin rw int.add_comm, exact int.sub_left_lt_of_lt_add h end protected lemma lt_add_of_neg_add_lt_right {a b c : ℤ} (h : -c + a < b) : a < b + c := begin rw int.add_comm at h, exact int.lt_add_of_sub_right_lt h end protected lemma neg_add_lt_right_of_lt_add {a b c : ℤ} (h : a < b + c) : -c + a < b := begin rw int.add_comm at h, exact int.neg_add_lt_left_of_lt_add h end protected lemma lt_add_of_neg_lt_sub_left {a b c : ℤ} (h : -a < b - c) : c < a + b := int.lt_add_of_neg_add_lt_left (int.add_lt_of_lt_sub_right h) protected lemma neg_lt_sub_left_of_lt_add {a b c : ℤ} (h : c < a + b) : -a < b - c := begin have h := int.lt_neg_add_of_add_lt (int.sub_left_lt_of_lt_add h), rwa int.add_comm at h end protected lemma lt_add_of_neg_lt_sub_right {a b c : ℤ} (h : -b < a - c) : c < a + b := int.lt_add_of_sub_right_lt (int.add_lt_of_lt_sub_left h) protected lemma neg_lt_sub_right_of_lt_add {a b c : ℤ} (h : c < a + b) : -b < a - c := int.lt_sub_left_of_add_lt (int.sub_right_lt_of_lt_add h) protected lemma sub_lt_of_sub_lt {a b c : ℤ} (h : a - b < c) : a - c < b := int.sub_left_lt_of_lt_add (int.lt_add_of_sub_right_lt h) protected lemma sub_lt_sub_left {a b : ℤ} (h : a < b) (c : ℤ) : c - b < c - a := int.add_lt_add_left (int.neg_lt_neg h) c protected lemma sub_lt_sub_right {a b : ℤ} (h : a < b) (c : ℤ) : a - c < b - c := int.add_lt_add_right h (-c) protected lemma sub_lt_sub {a b c d : ℤ} (hab : a < b) (hcd : c < d) : a - d < b - c := int.add_lt_add hab (int.neg_lt_neg hcd) protected lemma sub_lt_sub_of_le_of_lt {a b c d : ℤ} (hab : a ≤ b) (hcd : c < d) : a - d < b - c := int.add_lt_add_of_le_of_lt hab (int.neg_lt_neg hcd) protected lemma sub_lt_sub_of_lt_of_le {a b c d : ℤ} (hab : a < b) (hcd : c ≤ d) : a - d < b - c := int.add_lt_add_of_lt_of_le hab (int.neg_le_neg hcd) protected lemma sub_le_self (a : ℤ) {b : ℤ} (h : b ≥ 0) : a - b ≤ a := calc a - b = a + -b : rfl ... ≤ a + 0 : int.add_le_add_left (int.neg_nonpos_of_nonneg h) _ ... = a : by rw int.add_zero protected lemma sub_lt_self (a : ℤ) {b : ℤ} (h : b > 0) : a - b < a := calc a - b = a + -b : rfl ... < a + 0 : int.add_lt_add_left (int.neg_neg_of_pos h) _ ... = a : by rw int.add_zero protected lemma add_le_add_three {a b c d e f : ℤ} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a + b + c ≤ d + e + f := begin apply le_trans, apply int.add_le_add, apply int.add_le_add, assumption', apply le_refl end end /- missing facts -/ protected lemma mul_lt_mul_of_pos_left {a b c : ℤ} (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b := have 0 < b - a, from int.sub_pos_of_lt h₁, have 0 < c * (b - a), from int.mul_pos h₂ this, begin rw int.mul_sub at this, exact int.lt_of_sub_pos this end protected lemma mul_lt_mul_of_pos_right {a b c : ℤ} (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c := have 0 < b - a, from int.sub_pos_of_lt h₁, have 0 < (b - a) * c, from int.mul_pos this h₂, begin rw int.sub_mul at this, exact int.lt_of_sub_pos this end protected lemma mul_le_mul_of_nonneg_left {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b := begin by_cases hba : b ≤ a, { simp [le_antisymm hba h₁] }, by_cases hc0 : c ≤ 0, { simp [le_antisymm hc0 h₂, int.zero_mul] }, exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_left (lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left, end protected lemma mul_le_mul_of_nonneg_right {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c := begin by_cases hba : b ≤ a, { simp [le_antisymm hba h₁] }, by_cases hc0 : c ≤ 0, { simp [le_antisymm hc0 h₂, int.mul_zero] }, exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_right (lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left, end -- TODO: there are four variations, depending on which variables we assume to be nonneg protected lemma mul_le_mul {a b c d : ℤ} (hac : a ≤ c) (hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) : a * b ≤ c * d := calc a * b ≤ c * b : int.mul_le_mul_of_nonneg_right hac nn_b ... ≤ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c protected lemma mul_nonpos_of_nonneg_of_nonpos {a b : ℤ} (ha : a ≥ 0) (hb : b ≤ 0) : a * b ≤ 0 := have h : a * b ≤ a * 0, from int.mul_le_mul_of_nonneg_left hb ha, by rwa int.mul_zero at h protected lemma mul_nonpos_of_nonpos_of_nonneg {a b : ℤ} (ha : a ≤ 0) (hb : b ≥ 0) : a * b ≤ 0 := have h : a * b ≤ 0 * b, from int.mul_le_mul_of_nonneg_right ha hb, by rwa int.zero_mul at h protected lemma mul_lt_mul {a b c d : ℤ} (hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d := calc a * b < c * b : int.mul_lt_mul_of_pos_right hac pos_b ... ≤ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c protected lemma mul_lt_mul' {a b c d : ℤ} (h1 : a ≤ c) (h2 : b < d) (h3 : b ≥ 0) (h4 : c > 0) : a * b < c * d := calc a * b ≤ c * b : int.mul_le_mul_of_nonneg_right h1 h3 ... < c * d : int.mul_lt_mul_of_pos_left h2 h4 protected lemma mul_neg_of_pos_of_neg {a b : ℤ} (ha : a > 0) (hb : b < 0) : a * b < 0 := have h : a * b < a * 0, from int.mul_lt_mul_of_pos_left hb ha, by rwa int.mul_zero at h protected lemma mul_neg_of_neg_of_pos {a b : ℤ} (ha : a < 0) (hb : b > 0) : a * b < 0 := have h : a * b < 0 * b, from int.mul_lt_mul_of_pos_right ha hb, by rwa int.zero_mul at h protected lemma mul_le_mul_of_nonpos_right {a b c : ℤ} (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c := have -c ≥ 0, from int.neg_nonneg_of_nonpos hc, have b * -c ≤ a * -c, from int.mul_le_mul_of_nonneg_right h this, have -(b * c) ≤ -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this, int.le_of_neg_le_neg this protected lemma mul_nonneg_of_nonpos_of_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b := have 0 * b ≤ a * b, from int.mul_le_mul_of_nonpos_right ha hb, by rwa int.zero_mul at this protected lemma mul_lt_mul_of_neg_left {a b c : ℤ} (h : b < a) (hc : c < 0) : c * a < c * b := have -c > 0, from int.neg_pos_of_neg hc, have -c * b < -c * a, from int.mul_lt_mul_of_pos_left h this, have -(c * b) < -(c * a), by rwa [← int.neg_mul_eq_neg_mul, ← int.neg_mul_eq_neg_mul] at this, int.lt_of_neg_lt_neg this protected lemma mul_lt_mul_of_neg_right {a b c : ℤ} (h : b < a) (hc : c < 0) : a * c < b * c := have -c > 0, from int.neg_pos_of_neg hc, have b * -c < a * -c, from int.mul_lt_mul_of_pos_right h this, have -(b * c) < -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this, int.lt_of_neg_lt_neg this protected lemma mul_pos_of_neg_of_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : 0 < a * b := have 0 * b < a * b, from int.mul_lt_mul_of_neg_right ha hb, by rwa int.zero_mul at this protected lemma mul_self_le_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b := int.mul_le_mul h2 h2 h1 (le_trans h1 h2) protected lemma mul_self_lt_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b := int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2) /- more facts specific to int -/ theorem of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial theorem coe_succ_pos (n : nat) : (nat.succ n : ℤ) > 0 := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _) theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -n := let ⟨n, h⟩ := eq_coe_of_zero_le (int.neg_nonneg_of_nonpos H) in ⟨n, int.eq_neg_of_eq_neg h.symm⟩ theorem nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : (nat_abs a : ℤ) = a := match a, eq_coe_of_zero_le H with ._, ⟨n, rfl⟩ := rfl end theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : (nat_abs a : ℤ) = -a := by rw [← nat_abs_neg, nat_abs_of_nonneg (int.neg_nonneg_of_nonpos H)] theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b := H theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b := H theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 := int.add_le_add_right H 1 theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b := int.le_of_add_le_add_right H theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b := int.sub_right_lt_of_lt_add $ lt_add_one_of_le H theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b := le_of_lt_add_one $ int.lt_add_of_sub_right_lt H theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 := int.le_sub_right_of_add_le H theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b := int.add_le_of_le_sub_right H theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 := rfl theorem sign_eq_one_of_pos {a : ℤ} (h : 0 < a) : sign a = 1 := match a, eq_succ_of_zero_lt h with ._, ⟨n, rfl⟩ := rfl end theorem sign_eq_neg_one_of_neg {a : ℤ} (h : a < 0) : sign a = -1 := match a, eq_neg_succ_of_lt_zero h with ._, ⟨n, rfl⟩ := rfl end lemma eq_zero_of_sign_eq_zero : Π {a : ℤ}, sign a = 0 → a = 0 | 0 _ := rfl theorem pos_of_sign_eq_one : ∀ {a : ℤ}, sign a = 1 → 0 < a | (n+1:ℕ) _ := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _) theorem neg_of_sign_eq_neg_one : ∀ {a : ℤ}, sign a = -1 → a < 0 | (n+1:ℕ) h := match h with end | 0 h := match h with end | -[1+ n] _ := neg_succ_lt_zero _ theorem sign_eq_one_iff_pos (a : ℤ) : sign a = 1 ↔ 0 < a := ⟨pos_of_sign_eq_one, sign_eq_one_of_pos⟩ theorem sign_eq_neg_one_iff_neg (a : ℤ) : sign a = -1 ↔ a < 0 := ⟨neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg⟩ theorem sign_eq_zero_iff_zero (a : ℤ) : sign a = 0 ↔ a = 0 := ⟨eq_zero_of_sign_eq_zero, λ h, by rw [h, sign_zero]⟩ protected lemma eq_zero_or_eq_zero_of_mul_eq_zero {a b : ℤ} (h : a * b = 0) : a = 0 ∨ b = 0 := match decidable.lt_trichotomy 0 a with | or.inl hlt₁ := match decidable.lt_trichotomy 0 b with | or.inl hlt₂ := have 0 < a * b, from int.mul_pos hlt₁ hlt₂, begin rw h at this, exact absurd this (lt_irrefl _) end | or.inr (or.inl heq₂) := or.inr heq₂.symm | or.inr (or.inr hgt₂) := have 0 > a * b, from int.mul_neg_of_pos_of_neg hlt₁ hgt₂, begin rw h at this, exact absurd this (lt_irrefl _) end end | or.inr (or.inl heq₁) := or.inl heq₁.symm | or.inr (or.inr hgt₁) := match decidable.lt_trichotomy 0 b with | or.inl hlt₂ := have 0 > a * b, from int.mul_neg_of_neg_of_pos hgt₁ hlt₂, begin rw h at this, exact absurd this (lt_irrefl _) end | or.inr (or.inl heq₂) := or.inr heq₂.symm | or.inr (or.inr hgt₂) := have 0 < a * b, from int.mul_pos_of_neg_of_neg hgt₁ hgt₂, begin rw h at this, exact absurd this (lt_irrefl _) end end end protected lemma eq_of_mul_eq_mul_right {a b c : ℤ} (ha : a ≠ 0) (h : b * a = c * a) : b = c := have b * a - c * a = 0, from int.sub_eq_zero_of_eq h, have (b - c) * a = 0, by rw [int.sub_mul, this], have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha, int.eq_of_sub_eq_zero this protected lemma eq_of_mul_eq_mul_left {a b c : ℤ} (ha : a ≠ 0) (h : a * b = a * c) : b = c := have a * b - a * c = 0, from int.sub_eq_zero_of_eq h, have a * (b - c) = 0, by rw [int.mul_sub, this], have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha, int.eq_of_sub_eq_zero this theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 := int.eq_of_mul_eq_mul_right Hpos (by rw [int.one_mul, H]) theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 := int.eq_of_mul_eq_mul_left Hpos (by rw [int.mul_one, H]) end int
77d8407a15715138efdfb897e7c55b8228e7debb
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/nat/choose/central.lean
10b2f90d9849f338735d72391c6b5f968f06b30d
[ "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
5,194
lean
/- Copyright (c) 2021 Patrick Stevens. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Stevens, Thomas Browning -/ import data.nat.choose.basic import tactic.linarith /-! # Central binomial coefficients This file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`). ## Main definition and results * `nat.central_binom`: the central binomial coefficient, `(2 * n).choose n`. * `nat.succ_mul_central_binom_succ`: the inductive relationship between successive central binomial coefficients. * `nat.four_pow_lt_mul_central_binom`: an exponential lower bound on the central binomial coefficient. * `succ_dvd_central_binom`: The result that `n+1 ∣ n.central_binom`, ensuring that the explicit definition of the Catalan numbers is integer-valued. -/ namespace nat /-- The central binomial coefficient, `nat.choose (2 * n) n`. -/ def central_binom (n : ℕ) := (2 * n).choose n lemma central_binom_eq_two_mul_choose (n : ℕ) : central_binom n = (2 * n).choose n := rfl lemma central_binom_pos (n : ℕ) : 0 < central_binom n := choose_pos (nat.le_mul_of_pos_left zero_lt_two) lemma central_binom_ne_zero (n : ℕ) : central_binom n ≠ 0 := (central_binom_pos n).ne' @[simp] lemma central_binom_zero : central_binom 0 = 1 := choose_zero_right _ /-- The central binomial coefficient is the largest binomial coefficient. -/ lemma choose_le_central_binom (r n : ℕ) : choose (2 * n) r ≤ central_binom n := calc (2 * n).choose r ≤ (2 * n).choose (2 * n / 2) : choose_le_middle r (2 * n) ... = (2 * n).choose n : by rw nat.mul_div_cancel_left n zero_lt_two lemma two_le_central_binom (n : ℕ) (n_pos : 0 < n) : 2 ≤ central_binom n := calc 2 ≤ 2 * n : le_mul_of_pos_right n_pos ... = (2 * n).choose 1 : (choose_one_right (2 * n)).symm ... ≤ central_binom n : choose_le_central_binom 1 n /-- An inductive property of the central binomial coefficient. -/ lemma succ_mul_central_binom_succ (n : ℕ) : (n + 1) * central_binom (n + 1) = 2 * (2 * n + 1) * central_binom n := calc (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) : mul_comm _ _ ... = (2 * n + 1).choose n * (2 * n + 2) : by rw [choose_succ_right_eq, choose_mul_succ_eq] ... = 2 * ((2 * n + 1).choose n * (n + 1)) : by ring ... = 2 * ((2 * n + 1).choose n * ((2 * n + 1) - n)) : by rw [two_mul n, add_assoc, nat.add_sub_cancel_left] ... = 2 * ((2 * n).choose n * (2 * n + 1)) : by rw choose_mul_succ_eq ... = (2 * (2 * n + 1)) * (2 * n).choose n : by rw [mul_assoc, mul_comm (2 * n + 1)] /-- An exponential lower bound on the central binomial coefficient. This bound is of interest because it appears in [Tochiori's refinement of Erdős's proof of Bertrand's postulate](tochiori_bertrand). -/ lemma four_pow_lt_mul_central_binom (n : ℕ) (n_big : 4 ≤ n) : 4 ^ n < n * central_binom n := begin induction n using nat.strong_induction_on with n IH, rcases lt_trichotomy n 4 with (hn|rfl|hn), { clear IH, dec_trivial! }, { norm_num [central_binom, choose] }, obtain ⟨n, rfl⟩ : ∃ m, n = m + 1 := nat.exists_eq_succ_of_ne_zero (zero_lt_four.trans hn).ne', calc 4 ^ (n + 1) < 4 * (n * central_binom n) : (mul_lt_mul_left $ zero_lt_four' ℕ).mpr (IH n n.lt_succ_self (nat.le_of_lt_succ hn)) ... ≤ 2 * (2 * n + 1) * central_binom n : by { rw ← mul_assoc, linarith } ... = (n + 1) * central_binom (n + 1) : (succ_mul_central_binom_succ n).symm, end /-- An exponential lower bound on the central binomial coefficient. This bound is weaker than `nat.four_pow_lt_mul_central_binom`, but it is of historical interest because it appears in Erdős's proof of Bertrand's postulate. -/ lemma four_pow_le_two_mul_self_mul_central_binom : ∀ (n : ℕ) (n_pos : 0 < n), 4 ^ n ≤ (2 * n) * central_binom n | 0 pr := (nat.not_lt_zero _ pr).elim | 1 pr := by norm_num [central_binom, choose] | 2 pr := by norm_num [central_binom, choose] | 3 pr := by norm_num [central_binom, choose] | n@(m + 4) _ := calc 4 ^ n ≤ n * central_binom n : (four_pow_lt_mul_central_binom _ le_add_self).le ... ≤ 2 * n * central_binom n : by { rw [mul_assoc], refine le_mul_of_pos_left zero_lt_two } lemma two_dvd_central_binom_succ (n : ℕ) : 2 ∣ central_binom (n + 1) := begin use (n+1+n).choose n, rw [central_binom_eq_two_mul_choose, two_mul, ← add_assoc, choose_succ_succ, choose_symm_add, ← two_mul], end lemma two_dvd_central_binom_of_one_le {n : ℕ} (h : 0 < n) : 2 ∣ central_binom n := begin rw ← nat.succ_pred_eq_of_pos h, exact two_dvd_central_binom_succ n.pred, end /-- A crucial lemma to ensure that Catalan numbers can be defined via their explicit formula `catalan n = n.central_binom / (n + 1)`. -/ lemma succ_dvd_central_binom (n : ℕ) : (n + 1) ∣ n.central_binom := begin have h_s : (n+1).coprime (2*n+1), { rw [two_mul,add_assoc, coprime_add_self_right, coprime_self_add_left], exact coprime_one_left n }, apply h_s.dvd_of_dvd_mul_left, apply dvd_of_mul_dvd_mul_left zero_lt_two, rw [← mul_assoc, ← succ_mul_central_binom_succ, mul_comm], exact mul_dvd_mul_left _ (two_dvd_central_binom_succ n), end end nat
50cc9f4b0bb1159055a96bd114a3178ea2ed00b5
8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3
/src/data/nat/totient.lean
5de8f164eca7080225cdd4b18c4985487173ed7d
[ "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
7,740
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import algebra.big_operators.basic import data.nat.prime import data.zmod.basic /-! # Euler's totient function This file defines [Euler's totient function][https://en.wikipedia.org/wiki/Euler's_totient_function] `nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`. We prove the divisor sum formula, namely that `n` equals `φ` summed over the divisors of `n`. See `sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and `totient_prime_pow`. -/ open finset open_locale big_operators namespace nat /-- Euler's totient function. This counts the number of naturals strictly less than `n` which are coprime with `n`. -/ def totient (n : ℕ) : ℕ := ((range n).filter (nat.coprime n)).card localized "notation `φ` := nat.totient" in nat @[simp] theorem totient_zero : φ 0 = 0 := rfl @[simp] theorem totient_one : φ 1 = 1 := by simp [totient] lemma totient_eq_card_coprime (n : ℕ) : φ n = ((range n).filter (nat.coprime n)).card := rfl lemma totient_le (n : ℕ) : φ n ≤ n := calc totient n ≤ (range n).card : card_filter_le _ _ ... = n : card_range _ lemma totient_pos : ∀ {n : ℕ}, 0 < n → 0 < φ n | 0 := dec_trivial | 1 := by simp [totient] | (n+2) := λ h, card_pos.2 ⟨1, mem_filter.2 ⟨mem_range.2 dec_trivial, coprime_one_right _⟩⟩ open zmod @[simp] lemma _root_.zmod.card_units_eq_totient (n : ℕ) [fact (0 < n)] : fintype.card (units (zmod n)) = φ n := calc fintype.card (units (zmod n)) = fintype.card {x : zmod n // x.val.coprime n} : fintype.card_congr zmod.units_equiv_coprime ... = φ n : begin apply finset.card_congr (λ (a : {x : zmod n // x.val.coprime n}) _, a.1.val), { intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} }, { intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, }, { intros b hb, rw [finset.mem_filter, finset.mem_range] at hb, refine ⟨⟨b, _⟩, finset.mem_univ _, _⟩, { let u := unit_of_coprime b hb.2.symm, exact val_coe_unit_coprime u }, { show zmod.val (b : zmod n) = b, rw [val_nat_cast, nat.mod_eq_of_lt hb.1], } } end lemma totient_mul {m n : ℕ} (h : m.coprime n) : φ (m * n) = φ m * φ n := if hmn0 : m * n = 0 then by cases nat.mul_eq_zero.1 hmn0 with h h; simp only [totient_zero, mul_zero, zero_mul, h] else begin haveI : fact (0 < (m * n)) := ⟨nat.pos_of_ne_zero hmn0⟩, haveI : fact (0 < m) := ⟨nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0⟩, haveI : fact (0 < n) := ⟨nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0⟩, rw [← zmod.card_units_eq_totient, ← zmod.card_units_eq_totient, ← zmod.card_units_eq_totient, fintype.card_congr (units.map_equiv (zmod.chinese_remainder h).to_mul_equiv).to_equiv, fintype.card_congr (@mul_equiv.prod_units (zmod m) (zmod n) _ _).to_equiv, fintype.card_prod] end lemma sum_totient (n : ℕ) : ∑ m in (range n.succ).filter (∣ n), φ m = n := if hn0 : n = 0 then by simp [hn0] else calc ∑ m in (range n.succ).filter (∣ n), φ m = ∑ d in (range n.succ).filter (∣ n), ((range (n / d)).filter (λ m, gcd (n / d) m = 1)).card : eq.symm $ sum_bij (λ d _, n / d) (λ d hd, mem_filter.2 ⟨mem_range.2 $ lt_succ_of_le $ nat.div_le_self _ _, by conv {to_rhs, rw ← nat.mul_div_cancel' (mem_filter.1 hd).2}; simp⟩) (λ _ _, rfl) (λ a b ha hb h, have ha : a * (n / a) = n, from nat.mul_div_cancel' (mem_filter.1 ha).2, have 0 < (n / a), from nat.pos_of_ne_zero (λ h, by simp [*, lt_irrefl] at *), by rw [← nat.mul_left_inj this, ha, h, nat.mul_div_cancel' (mem_filter.1 hb).2]) (λ b hb, have hb : b < n.succ ∧ b ∣ n, by simpa [-range_succ] using hb, have hbn : (n / b) ∣ n, from ⟨b, by rw nat.div_mul_cancel hb.2⟩, have hnb0 : (n / b) ≠ 0, from λ h, by simpa [h, ne.symm hn0] using nat.div_mul_cancel hbn, ⟨n / b, mem_filter.2 ⟨mem_range.2 $ lt_succ_of_le $ nat.div_le_self _ _, hbn⟩, by rw [← nat.mul_left_inj (nat.pos_of_ne_zero hnb0), nat.mul_div_cancel' hb.2, nat.div_mul_cancel hbn]⟩) ... = ∑ d in (range n.succ).filter (∣ n), ((range n).filter (λ m, gcd n m = d)).card : sum_congr rfl (λ d hd, have hd : d ∣ n, from (mem_filter.1 hd).2, have hd0 : 0 < d, from nat.pos_of_ne_zero (λ h, hn0 (eq_zero_of_zero_dvd $ h ▸ hd)), card_congr (λ m hm, d * m) (λ m hm, have hm : m < n / d ∧ gcd (n / d) m = 1, by simpa using hm, mem_filter.2 ⟨mem_range.2 $ nat.mul_div_cancel' hd ▸ (mul_lt_mul_left hd0).2 hm.1, by rw [← nat.mul_div_cancel' hd, gcd_mul_left, hm.2, mul_one]⟩) (λ a b ha hb h, (nat.mul_right_inj hd0).1 h) (λ b hb, have hb : b < n ∧ gcd n b = d, by simpa using hb, ⟨b / d, mem_filter.2 ⟨mem_range.2 ((mul_lt_mul_left (show 0 < d, from hb.2 ▸ hb.2.symm ▸ hd0)).1 (by rw [← hb.2, nat.mul_div_cancel' (gcd_dvd_left _ _), nat.mul_div_cancel' (gcd_dvd_right _ _)]; exact hb.1)), hb.2 ▸ coprime_div_gcd_div_gcd (hb.2.symm ▸ hd0)⟩, hb.2 ▸ nat.mul_div_cancel' (gcd_dvd_right _ _)⟩)) ... = ((filter (∣ n) (range n.succ)).bUnion (λ d, (range n).filter (λ m, gcd n m = d))).card : (card_bUnion (by intros; apply disjoint_filter.2; cc)).symm ... = (range n).card : congr_arg card (finset.ext (λ m, ⟨by finish, λ hm, have h : m < n, from mem_range.1 hm, mem_bUnion.2 ⟨gcd n m, mem_filter.2 ⟨mem_range.2 (lt_succ_of_le (le_of_dvd (lt_of_le_of_lt (zero_le _) h) (gcd_dvd_left _ _))), gcd_dvd_left _ _⟩, mem_filter.2 ⟨hm, rfl⟩⟩⟩)) ... = n : card_range _ /-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/ lemma totient_prime_pow_succ {p : ℕ} (hp : p.prime) (n : ℕ) : φ (p ^ (n + 1)) = p ^ n * (p - 1) := calc φ (p ^ (n + 1)) = ((range (p ^ (n + 1))).filter (coprime (p ^ (n + 1)))).card : totient_eq_card_coprime _ ... = (range (p ^ (n + 1)) \ ((range (p ^ n)).image (* p))).card : congr_arg card begin rw [sdiff_eq_filter], apply filter_congr, simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos, mem_image, not_exists, hp.coprime_iff_not_dvd], intros a ha, split, { rintros hap b _ rfl, exact hap (dvd_mul_left _ _) }, { rintros h ⟨b, rfl⟩, rw [pow_succ] at ha, exact h b (lt_of_mul_lt_mul_left ha (zero_le _)) (mul_comm _ _) } end ... = _ : have h1 : set.inj_on (* p) (range (p ^ n)), from λ x _ y _, (nat.mul_left_inj hp.pos).1, have h2 : (range (p ^ n)).image (* p) ⊆ range (p ^ (n + 1)), from λ a, begin simp only [mem_image, mem_range, exists_imp_distrib], rintros b h rfl, rw [pow_succ'], exact (mul_lt_mul_right hp.pos).2 h end, begin rw [card_sdiff h2, card_image_of_inj_on h1, card_range, card_range, ← one_mul (p ^ n), pow_succ, ← nat.mul_sub_right_distrib, one_mul, mul_comm] end /-- When `p` is prime, then the totient of `p ^ ` is `p ^ (n - 1) * (p - 1)` -/ lemma totient_prime_pow {p : ℕ} (hp : p.prime) {n : ℕ} (hn : 0 < n) : φ (p ^ n) = p ^ (n - 1) * (p - 1) := by rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with ⟨m, rfl⟩; exact totient_prime_pow_succ hp _ lemma totient_prime {p : ℕ} (hp : p.prime) : φ p = p - 1 := by rw [← pow_one p, totient_prime_pow hp]; simp @[simp] lemma totient_two : φ 2 = 1 := (totient_prime prime_two).trans (by norm_num) end nat
9e8bca2241377d4a8846b4854c09692dece887de
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/nested_inductive.lean
b8f9231a561e60be5fd783d5ed3ed3bee0fe3aa5
[ "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
3,346
lean
set_option trace.inductive_compiler.nested.define.failure true set_option max_memory 1000000 inductive {u} vec (A : Type u) : nat -> Type u | vnil : vec 0 | vcons : Pi (n : nat), A -> vec n -> vec (n+1) namespace X1 #print "simple" inductive foo : Type | mk : list foo -> foo end X1 namespace X2 #print "with param" inductive {u} foo (A : Type u) : Type u | mk : A -> list foo -> foo end X2 namespace X3 #print "with indices" inductive {u} foo (A B : Type u) : Type u | mk : A -> B -> vec foo 0 -> foo end X3 namespace X4 #print "with locals in indices" inductive {u} foo (A : Type u) : Type u | mk : Pi (n : nat), A -> vec foo n -> foo end X4 namespace X5 #print "nested-reflexive" inductive {u} foo (A : Type u) : Type u | mk : A -> (Pi (m : nat), vec foo m) -> foo end X5 namespace X6 #print "locals + nested-reflexive locals in indices" inductive {u} foo (A : Type u) : Type u | mk : Pi (n : nat), A -> (Pi (m : nat), vec foo (n + m)) -> foo end X6 namespace X7 #print "many different nestings" inductive {u} foo (A : Type u) : Type u | mk : Pi (n : nat), A -> list A -> prod A A -> (Pi (m : nat), vec foo (n + m)) -> vec foo n -> foo end X7 namespace X8 #print "many different nestings, some sharing" inductive {u} foo (A : Type u) : Type u | mk₁ : Pi (n : nat), A -> (Pi (m : nat), vec (list foo) (n + m)) -> vec foo n -> foo | mk₂ : Pi (n : nat), A -> list A -> prod A A -> (Pi (m : nat), vec foo (n + m)) -> vec foo n -> foo end X8 namespace X9b #print "mutual + nesting" mutual inductive {u} foo, bar with foo : Type u | mk : list (list foo) -> foo with bar : Type u | mk : list foo -> bar end X9b namespace X10 #print "many layers of nesting nested inductive types" inductive wrap (A : Sort*) | mk : A -> wrap inductive box (A : Sort*) | mk : A -> wrap box -> box inductive foo (A : Sort*) | mk : A -> box foo -> foo inductive bar | mk : foo bar -> bar end X10 namespace X11 #print "intro rule that introduces additional nesting" inductive {u} wrap (A : Type u) : Type u | mk : list A -> wrap inductive {u} foo : Type u | mk : wrap foo -> foo end X11 namespace X12 #print "intro rule that introduces a lot of additional nesting" inductive wrap (A : Sort*) : Sort* | mk : list (list A) -> wrap inductive {u} box (A : Type u) : Type u | mk : A -> wrap box -> box end X12 namespace X13 #print "with reducible definitions" attribute [reducible] definition list' := @list inductive wrap (A : Sort*) : Sort* | mk : A -> list' A -> wrap attribute [reducible] definition wrap' := @wrap inductive {u} foo (A : Type u) : Type u | mk : A -> wrap' (list' foo) -> foo end X13 namespace X14 #print "with indices in original" inductive Foo : bool -> Type | mk : list (Foo ff) -> Foo tt end X14 namespace X15 #print "nested inductive propositions eliminating to Prop" universe variable l inductive plist (A : Sort l) : Sort l | nil : plist | cons : A → plist → plist inductive foo (A : Type l) : ℕ → Prop | mk : A → plist (plist (foo 0)) → or (foo 1) (foo 2) → foo 1 end X15 namespace X16 #print "multiply nested inductive propositions" universe variable l inductive wrap (A : Sort l) : Sort l | mk : A -> wrap inductive box (A : Prop) : Prop | mk : A -> wrap box -> box inductive foo (A : Sort*) : Prop | mk : A -> box foo -> foo inductive bar : Prop | mk : foo bar -> bar end X16
9a2bfb424d7f75741936e0bc831245a73c5d0022
46125763b4dbf50619e8846a1371029346f4c3db
/src/tactic/ring.lean
18041ac82a6dcd626866d0ff8c9a8da360835959
[ "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
21,461
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Evaluate expressions in the language of commutative (semi)rings. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . -/ import algebra.group_power tactic.norm_num import tactic.converter.interactive namespace tactic namespace ring def horner {α} [comm_semiring α] (a x : α) (n : ℕ) (b : α) := a * x ^ n + b meta structure cache := (α : expr) (univ : level) (comm_semiring_inst : expr) (red : transparency) meta def ring_m (α : Type) : Type := reader_t cache (state_t (buffer expr) tactic) α meta instance : monad ring_m := by dunfold ring_m; apply_instance meta instance : alternative ring_m := by dunfold ring_m; apply_instance meta def get_cache : ring_m cache := reader_t.read meta def get_atom (n : ℕ) : ring_m expr := reader_t.lift $ (λ es : buffer expr, es.read' n) <$> state_t.get meta def get_transparency : ring_m transparency := cache.red <$> get_cache meta def add_atom (e : expr) : ring_m ℕ := do red ← get_transparency, reader_t.lift ⟨λ es, (do n ← es.iterate failed (λ n e' t, t <|> (is_def_eq e e' red $> n)), return (n, es)) <|> return (es.size, es.push_back e)⟩ meta def lift {α} (m : tactic α) : ring_m α := reader_t.lift (state_t.lift m) meta def ring_m.run (red : transparency) (e : expr) {α} (m : ring_m α) : tactic α := do α ← infer_type e, c ← mk_app ``comm_semiring [α] >>= mk_instance, u ← mk_meta_univ, infer_type α >>= unify (expr.sort (level.succ u)), u ← get_univ_assignment u, prod.fst <$> state_t.run (reader_t.run m ⟨α, u, c, red⟩) mk_buffer meta def cache.cs_app (c : cache) (n : name) : list expr → expr := (@expr.const tt n [c.univ] c.α c.comm_semiring_inst).mk_app meta def ring_m.mk_app (n inst : name) (l : list expr) : ring_m expr := do c ← get_cache, m ← lift $ mk_instance ((expr.const inst [c.univ] : expr) c.α), return $ (@expr.const tt n [c.univ] c.α m).mk_app l meta inductive horner_expr : Type | const (e : expr) : horner_expr | xadd (e : expr) (a : horner_expr) (x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr meta def horner_expr.e : horner_expr → expr | (horner_expr.const e) := e | (horner_expr.xadd e _ _ _ _) := e meta instance : has_coe horner_expr expr := ⟨horner_expr.e⟩ meta def horner_expr.xadd' (c : cache) (a : horner_expr) (x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr := horner_expr.xadd (c.cs_app ``horner [a, x.1, n.1, b]) a x n b open horner_expr meta def horner_expr.to_string : horner_expr → string | (const e) := to_string e | (xadd e a x (_, n) b) := "(" ++ a.to_string ++ ") * (" ++ to_string x.1 ++ ")^" ++ to_string n ++ " + " ++ b.to_string meta def horner_expr.pp : horner_expr → tactic format | (const e) := pp e | (xadd e a x (_, n) b) := do pa ← a.pp, pb ← b.pp, px ← pp x.1, return $ "(" ++ pa ++ ") * (" ++ px ++ ")^" ++ to_string n ++ " + " ++ pb meta instance : has_to_tactic_format horner_expr := ⟨horner_expr.pp⟩ meta def horner_expr.refl_conv (e : horner_expr) : ring_m (horner_expr × expr) := do p ← lift $ mk_eq_refl e, return (e, p) theorem zero_horner {α} [comm_semiring α] (x n b) : @horner α _ 0 x n b = b := by simp [horner] theorem horner_horner {α} [comm_semiring α] (a₁ x n₁ n₂ b n') (h : n₁ + n₂ = n') : @horner α _ (horner a₁ x n₁ 0) x n₂ b = horner a₁ x n' b := by simp [h.symm, horner, pow_add, mul_assoc] meta def eval_horner : horner_expr → expr × ℕ → expr × ℕ → horner_expr → ring_m (horner_expr × expr) | ha@(const a) x n b := do c ← get_cache, if a.to_nat = some 0 then return (b, c.cs_app ``zero_horner [x.1, n.1, b]) else (xadd' c ha x n b).refl_conv | ha@(xadd a a₁ x₁ n₁ b₁) x n b := do c ← get_cache, if x₁.2 = x.2 ∧ b₁.e.to_nat = some 0 then do (n', h) ← lift $ mk_app ``has_add.add [n₁.1, n.1] >>= norm_num, return (xadd' c a₁ x (n', n₁.2 + n.2) b, c.cs_app ``horner_horner [a₁, x.1, n₁.1, n.1, b, n', h]) else (xadd' c ha x n b).refl_conv theorem const_add_horner {α} [comm_semiring α] (k a x n b b') (h : k + b = b') : k + @horner α _ a x n b = horner a x n b' := by simp [h.symm, horner]; cc theorem horner_add_const {α} [comm_semiring α] (a x n b k b') (h : b + k = b') : @horner α _ a x n b + k = horner a x n b' := by simp [h.symm, horner] theorem horner_add_horner_lt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b') (h₁ : n₁ + k = n₂) (h₂ : (a₁ + horner a₂ x k 0 : α) = a') (h₃ : b₁ + b₂ = b') : @horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₁ b' := by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]; cc theorem horner_add_horner_gt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b') (h₁ : n₂ + k = n₁) (h₂ : (horner a₁ x k 0 + a₂ : α) = a') (h₃ : b₁ + b₂ = b') : @horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₂ b' := by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]; cc -- set_option trace.class_instances true -- set_option class.instance_max_depth 128 theorem horner_add_horner_eq {α} [comm_semiring α] (a₁ x n b₁ a₂ b₂ a' b' t) (h₁ : a₁ + a₂ = a') (h₂ : b₁ + b₂ = b') (h₃ : horner a' x n b' = t) : @horner α _ a₁ x n b₁ + horner a₂ x n b₂ = t := by simp [h₃.symm, h₂.symm, h₁.symm, horner, add_mul, mul_comm]; cc meta def eval_add : horner_expr → horner_expr → ring_m (horner_expr × expr) | (const e₁) (const e₂) := do (e, p) ← lift $ mk_app ``has_add.add [e₁, e₂] >>= norm_num, return (const e, p) | he₁@(const e₁) he₂@(xadd e₂ a x n b) := do c ← get_cache, if e₁.to_nat = some 0 then do p ← lift $ mk_app ``zero_add [e₂], return (he₂, p) else do (b', h) ← eval_add he₁ b, return (xadd' c a x n b', c.cs_app ``const_add_horner [e₁, a, x.1, n.1, b, b', h]) | he₁@(xadd e₁ a x n b) he₂@(const e₂) := do c ← get_cache, if e₂.to_nat = some 0 then do p ← lift $ mk_app ``add_zero [e₁], return (he₁, p) else do (b', h) ← eval_add b he₂, return (xadd' c a x n b', c.cs_app ``horner_add_const [a, x.1, n.1, b, e₂, b', h]) | he₁@(xadd e₁ a₁ x₁ n₁ b₁) he₂@(xadd e₂ a₂ x₂ n₂ b₂) := do c ← get_cache, if x₁.2 < x₂.2 then do (b', h) ← eval_add b₁ he₂, return (xadd' c a₁ x₁ n₁ b', c.cs_app ``horner_add_const [a₁, x₁.1, n₁.1, b₁, e₂, b', h]) else if x₁.2 ≠ x₂.2 then do (b', h) ← eval_add he₁ b₂, return (xadd' c a₂ x₂ n₂ b', c.cs_app ``const_add_horner [e₁, a₂, x₂.1, n₂.1, b₂, b', h]) else if n₁.2 < n₂.2 then do let k := n₂.2 - n₁.2, ek ← lift $ expr.of_nat (expr.const `nat []) k, (_, h₁) ← lift $ mk_app ``has_add.add [n₁.1, ek] >>= norm_num, α0 ← lift $ expr.of_nat c.α 0, (a', h₂) ← eval_add a₁ (xadd' c a₂ x₁ (ek, k) (const α0)), (b', h₃) ← eval_add b₁ b₂, return (xadd' c a' x₁ n₁ b', c.cs_app ``horner_add_horner_lt [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃]) else if n₁.2 ≠ n₂.2 then do let k := n₁.2 - n₂.2, ek ← lift $ expr.of_nat (expr.const `nat []) k, (_, h₁) ← lift $ mk_app ``has_add.add [n₂.1, ek] >>= norm_num, α0 ← lift $ expr.of_nat c.α 0, (a', h₂) ← eval_add (xadd' c a₁ x₁ (ek, k) (const α0)) a₂, (b', h₃) ← eval_add b₁ b₂, return (xadd' c a' x₁ n₂ b', c.cs_app ``horner_add_horner_gt [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃]) else do (a', h₁) ← eval_add a₁ a₂, (b', h₂) ← eval_add b₁ b₂, (t, h₃) ← eval_horner a' x₁ n₁ b', return (t, c.cs_app ``horner_add_horner_eq [a₁, x₁.1, n₁.1, b₁, a₂, b₂, a', b', t, h₁, h₂, h₃]) theorem horner_neg {α} [comm_ring α] (a x n b a' b') (h₁ : -a = a') (h₂ : -b = b') : -@horner α _ a x n b = horner a' x n b' := by simp [h₂.symm, h₁.symm, horner]; cc meta def eval_neg : horner_expr → ring_m (horner_expr × expr) | (const e) := do (e', p) ← lift $ mk_app ``has_neg.neg [e] >>= norm_num, return (const e', p) | (xadd e a x n b) := do c ← get_cache, (a', h₁) ← eval_neg a, (b', h₂) ← eval_neg b, p ← ring_m.mk_app ``horner_neg ``comm_ring [a, x.1, n.1, b, a', b', h₁, h₂], return (xadd' c a' x n b', p) theorem horner_const_mul {α} [comm_semiring α] (c a x n b a' b') (h₁ : c * a = a') (h₂ : c * b = b') : c * @horner α _ a x n b = horner a' x n b' := by simp [h₂.symm, h₁.symm, horner, mul_add, mul_assoc] theorem horner_mul_const {α} [comm_semiring α] (a x n b c a' b') (h₁ : a * c = a') (h₂ : b * c = b') : @horner α _ a x n b * c = horner a' x n b' := by simp [h₂.symm, h₁.symm, horner, add_mul, mul_right_comm] meta def eval_const_mul (k : expr) : horner_expr → ring_m (horner_expr × expr) | (const e) := do (e', p) ← lift $ mk_app ``has_mul.mul [k, e] >>= norm_num, return (const e', p) | (xadd e a x n b) := do c ← get_cache, (a', h₁) ← eval_const_mul a, (b', h₂) ← eval_const_mul b, return (xadd' c a' x n b', c.cs_app ``horner_const_mul [k, a, x.1, n.1, b, a', b', h₁, h₂]) theorem horner_mul_horner_zero {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ aa t) (h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa) (h₂ : horner aa x n₂ 0 = t) : horner a₁ x n₁ b₁ * horner a₂ x n₂ 0 = t := by rw [← h₂, ← h₁]; simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc] theorem horner_mul_horner {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ aa haa ab bb t) (h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa) (h₂ : horner aa x n₂ 0 = haa) (h₃ : a₁ * b₂ = ab) (h₄ : b₁ * b₂ = bb) (H : haa + horner ab x n₁ bb = t) : horner a₁ x n₁ b₁ * horner a₂ x n₂ b₂ = t := by rw [← H, ← h₂, ← h₁, ← h₃, ← h₄]; simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc] meta def eval_mul : horner_expr → horner_expr → ring_m (horner_expr × expr) | (const e₁) (const e₂) := do (e', p) ← lift $ mk_app ``has_mul.mul [e₁, e₂] >>= norm_num, return (const e', p) | (const e₁) e₂ := match e₁.to_nat with | (some 0) := do c ← get_cache, α0 ← lift $ expr.of_nat c.α 0, p ← lift $ mk_app ``zero_mul [e₂], return (const α0, p) | (some 1) := do p ← lift $ mk_app ``one_mul [e₂], return (e₂, p) | _ := eval_const_mul e₁ e₂ end | e₁ he₂@(const e₂) := do p₁ ← lift $ mk_app ``mul_comm [e₁, e₂], (e', p₂) ← eval_mul he₂ e₁, p ← lift $ mk_eq_trans p₁ p₂, return (e', p) | he₁@(xadd e₁ a₁ x₁ n₁ b₁) he₂@(xadd e₂ a₂ x₂ n₂ b₂) := do c ← get_cache, if x₁.2 < x₂.2 then do (a', h₁) ← eval_mul a₁ he₂, (b', h₂) ← eval_mul b₁ he₂, return (xadd' c a' x₁ n₁ b', c.cs_app ``horner_mul_const [a₁, x₁.1, n₁.1, b₁, e₂, a', b', h₁, h₂]) else if x₁.2 ≠ x₂.2 then do (a', h₁) ← eval_mul he₁ a₂, (b', h₂) ← eval_mul he₁ b₂, return (xadd' c a' x₂ n₂ b', c.cs_app ``horner_const_mul [e₁, a₂, x₂.1, n₂.1, b₂, a', b', h₁, h₂]) else do (aa, h₁) ← eval_mul he₁ a₂, α0 ← lift $ expr.of_nat c.α 0, (haa, h₂) ← eval_horner aa x₁ n₂ (const α0), if b₂.e.to_nat = some 0 then return (haa, c.cs_app ``horner_mul_horner_zero [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, aa, haa, h₁, h₂]) else do (ab, h₃) ← eval_mul a₁ b₂, (bb, h₄) ← eval_mul b₁ b₂, (t, H) ← eval_add haa (xadd' c ab x₁ n₁ bb), return (t, c.cs_app ``horner_mul_horner [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, aa, haa, ab, bb, t, h₁, h₂, h₃, h₄, H]) theorem horner_pow {α} [comm_semiring α] (a x n m n' a') (h₁ : n * m = n') (h₂ : a ^ m = a') : @horner α _ a x n 0 ^ m = horner a' x n' 0 := by simp [h₁.symm, h₂.symm, horner, mul_pow, pow_mul] meta def eval_pow : horner_expr → expr × ℕ → ring_m (horner_expr × expr) | e (_, 0) := do c ← get_cache, α1 ← lift $ expr.of_nat c.α 1, p ← lift $ mk_app ``pow_zero [e], return (const α1, p) | e (_, 1) := do p ← lift $ mk_app ``pow_one [e], return (e, p) | (const e) (e₂, m) := do (e', p) ← lift $ mk_app ``monoid.pow [e, e₂] >>= norm_num.derive', return (const e', p) | he@(xadd e a x n b) m := do c ← get_cache, let N : expr := expr.const `nat [], match b.e.to_nat with | some 0 := do (n', h₁) ← lift $ mk_app ``has_mul.mul [n.1, m.1] >>= norm_num.derive', (a', h₂) ← eval_pow a m, α0 ← lift $ expr.of_nat c.α 0, return (xadd' c a' x (n', n.2 * m.2) (const α0), c.cs_app ``horner_pow [a, x.1, n.1, m.1, n', a', h₁, h₂]) | _ := do e₂ ← lift $ expr.of_nat N (m.2-1), l ← lift $ mk_app ``monoid.pow [e, e₂], (tl, hl) ← eval_pow he (e₂, m.2-1), (t, p₂) ← eval_mul tl he, hr ← lift $ mk_eq_refl e, p₂ ← ring_m.mk_app ``norm_num.subst_into_prod ``has_mul [l, e, tl, e, t, hl, hr, p₂], p₁ ← lift $ mk_app ``pow_succ' [e, e₂], p ← lift $ mk_eq_trans p₁ p₂, return (t, p) end theorem horner_atom {α} [comm_semiring α] (x : α) : x = horner 1 x 1 0 := by simp [horner] meta def eval_atom (e : expr) : ring_m (horner_expr × expr) := do c ← get_cache, i ← add_atom e, α0 ← lift $ expr.of_nat c.α 0, α1 ← lift $ expr.of_nat c.α 1, n1 ← lift $ expr.of_nat (expr.const `nat []) 1, return (xadd' c (const α1) (e, i) (n1, 1) (const α0), c.cs_app ``horner_atom [e]) lemma subst_into_pow {α} [monoid α] (l r tl tr t) (prl : (l : α) = tl) (prr : (r : ℕ) = tr) (prt : tl ^ tr = t) : l ^ r = t := by simp [prl, prr, prt] lemma unfold_sub {α} [add_group α] (a b c : α) (h : a + -b = c) : a - b = c := h lemma unfold_div {α} [division_ring α] (a b c : α) (h : a * b⁻¹ = c) : a / b = c := h meta def eval : expr → ring_m (horner_expr × expr) | `(%%e₁ + %%e₂) := do (e₁', p₁) ← eval e₁, (e₂', p₂) ← eval e₂, (e', p') ← eval_add e₁' e₂', p ← ring_m.mk_app ``norm_num.subst_into_sum ``has_add [e₁, e₂, e₁', e₂', e', p₁, p₂, p'], return (e', p) | e@`(@has_sub.sub %%α %%P %%e₁ %%e₂) := mcond (succeeds (lift $ mk_app ``comm_ring [α] >>= mk_instance)) (do e₂' ← lift $ mk_app ``has_neg.neg [e₂], e ← lift $ mk_app ``has_add.add [e₁, e₂'], (e', p) ← eval e, p' ← ring_m.mk_app ``unfold_sub ``add_group [e₁, e₂, e', p], return (e', p')) (eval_atom e) | `(- %%e) := do (e₁, p₁) ← eval e, (e₂, p₂) ← eval_neg e₁, p ← ring_m.mk_app ``norm_num.subst_into_neg ``has_neg [e, e₁, e₂, p₁, p₂], return (e₂, p) | `(%%e₁ * %%e₂) := do (e₁', p₁) ← eval e₁, (e₂', p₂) ← eval e₂, (e', p') ← eval_mul e₁' e₂', p ← ring_m.mk_app ``norm_num.subst_into_prod ``has_mul [e₁, e₂, e₁', e₂', e', p₁, p₂, p'], return (e', p) | e@`(has_inv.inv %%_) := (do (e', p) ← lift $ norm_num.derive e <|> refl_conv e, lift $ e'.to_rat, return (const e', p)) <|> eval_atom e | e@`(@has_div.div _ %%inst %%e₁ %%e₂) := mcond (succeeds (do inst' ← ring_m.mk_app ``division_ring_has_div ``division_ring [], lift $ is_def_eq inst inst')) (do e₂' ← lift $ mk_app ``has_inv.inv [e₂], e ← lift $ mk_app ``has_mul.mul [e₁, e₂'], (e', p) ← eval e, p' ← ring_m.mk_app ``unfold_div ``division_ring [e₁, e₂, e', p], return (e', p')) (eval_atom e) | e@`(@has_pow.pow _ _ %%P %%e₁ %%e₂) := do (e₂', p₂) ← lift $ norm_num.derive e₂ <|> refl_conv e₂, match e₂'.to_nat, P with | some k, `(monoid.has_pow) := do (e₁', p₁) ← eval e₁, (e', p') ← eval_pow e₁' (e₂, k), p ← ring_m.mk_app ``subst_into_pow ``monoid [e₁, e₂, e₁', e₂', e', p₁, p₂, p'], return (e', p) | some k, `(nat.has_pow) := do (e₁', p₁) ← eval e₁, (e', p') ← eval_pow e₁' (e₂, k), p₃ ← ring_m.mk_app ``subst_into_pow ``monoid [e₁, e₂, e₁', e₂', e', p₁, p₂, p'], p₄ ← lift $ mk_app ``nat.pow_eq_pow [e₁, e₂] >>= mk_eq_symm, p ← lift $ mk_eq_trans p₄ p₃, return (e', p) | _, _ := eval_atom e end | e := match e.to_nat with | some n := (const e).refl_conv | none := eval_atom e end meta def eval' (red : transparency) (e : expr) : tactic (expr × expr) := ring_m.run red e $ do (e', p) ← eval e, return (e', p) theorem horner_def' {α} [comm_semiring α] (a x n b) : @horner α _ a x n b = x ^ n * a + b := by simp [horner, mul_comm] theorem mul_assoc_rev {α} [semigroup α] (a b c : α) : a * (b * c) = a * b * c := by simp [mul_assoc] theorem pow_add_rev {α} [monoid α] (a : α) (m n : ℕ) : a ^ m * a ^ n = a ^ (m + n) := by simp [pow_add] theorem pow_add_rev_right {α} [monoid α] (a b : α) (m n : ℕ) : b * a ^ m * a ^ n = b * a ^ (m + n) := by simp [pow_add, mul_assoc] theorem add_neg_eq_sub {α} [add_group α] (a b : α) : a + -b = a - b := rfl @[derive has_reflect] inductive normalize_mode | raw | SOP | horner instance : inhabited normalize_mode := ⟨normalize_mode.horner⟩ meta def normalize (red : transparency) (mode := normalize_mode.horner) (e : expr) : tactic (expr × expr) := do pow_lemma ← simp_lemmas.mk.add_simp ``pow_one, let lemmas := match mode with | normalize_mode.SOP := [``horner_def', ``add_zero, ``mul_one, ``mul_add, ``mul_sub, ``mul_assoc_rev, ``pow_add_rev, ``pow_add_rev_right, ``mul_neg_eq_neg_mul_symm, ``add_neg_eq_sub] | normalize_mode.horner := [``horner.equations._eqn_1, ``add_zero, ``one_mul, ``pow_one, ``neg_mul_eq_neg_mul_symm, ``add_neg_eq_sub] | _ := [] end, lemmas ← lemmas.mfoldl simp_lemmas.add_simp simp_lemmas.mk, (_, e', pr) ← ext_simplify_core () {} simp_lemmas.mk (λ _, failed) (λ _ _ _ _ e, do (new_e, pr) ← match mode with | normalize_mode.raw := eval' red | normalize_mode.horner := trans_conv (eval' red) (simplify lemmas []) | normalize_mode.SOP := trans_conv (eval' red) $ trans_conv (simplify lemmas []) $ simp_bottom_up' (λ e, norm_num e <|> pow_lemma.rewrite e) end e, guard (¬ new_e =ₐ e), return ((), new_e, some pr, ff)) (λ _ _ _ _ _, failed) `eq e, return (e', pr) end ring namespace interactive open interactive interactive.types lean.parser open tactic.ring local postfix `?`:9001 := optional /-- Tactic for solving equations in the language of *commutative* (semi)rings. This version of `ring` fails if the target is not an equality that is provable by the axioms of commutative (semi)rings. -/ meta def ring1 (red : parse (tk "!")?) : tactic unit := let transp := if red.is_some then semireducible else reducible in do `(%%e₁ = %%e₂) ← target, ((e₁', p₁), (e₂', p₂)) ← ring_m.run transp e₁ $ prod.mk <$> eval e₁ <*> eval e₂, is_def_eq e₁' e₂', p ← mk_eq_symm p₂ >>= mk_eq_trans p₁, tactic.exact p meta def ring.mode : lean.parser ring.normalize_mode := with_desc "(SOP|raw|horner)?" $ do mode ← ident?, match mode with | none := return ring.normalize_mode.horner | some `horner := return ring.normalize_mode.horner | some `SOP := return ring.normalize_mode.SOP | some `raw := return ring.normalize_mode.raw | _ := failed end /-- Tactic for solving equations in the language of *commutative* (semi)rings. Attempts to prove the goal outright if there is no `at` specifier and the target is an equality, but if this fails it falls back to rewriting all ring expressions into a normal form. When writing a normal form, `ring SOP` will use sum-of-products form instead of horner form. `ring!` will use a more aggressive reducibility setting to identify atoms. -/ meta def ring (red : parse (tk "!")?) (SOP : parse ring.mode) (loc : parse location) : tactic unit := match loc with | interactive.loc.ns [none] := instantiate_mvars_in_target >> ring1 red | _ := failed end <|> do ns ← loc.get_locals, let transp := if red.is_some then semireducible else reducible, tt ← tactic.replace_at (normalize transp SOP) ns loc.include_goal | fail "ring failed to simplify", when loc.include_goal $ try tactic.reflexivity add_hint_tactic "ring" end interactive end tactic namespace conv.interactive open conv interactive open tactic tactic.interactive (ring.mode ring1) open tactic.ring (normalize) local postfix `?`:9001 := optional meta def ring (red : parse (lean.parser.tk "!")?) (SOP : parse ring.mode) : conv unit := let transp := if red.is_some then semireducible else reducible in discharge_eq_lhs (ring1 red) <|> replace_lhs (normalize transp SOP) <|> fail "ring failed to simplify" end conv.interactive
e25e32dd9e6d9ebc32b35adea777dd904c29d851
c777c32c8e484e195053731103c5e52af26a25d1
/src/group_theory/nielsen_schreier.lean
a54d8f0d7a83b4e63d5edbb7f08a1f4f033f3a6e
[ "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
12,152
lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import category_theory.action import combinatorics.quiver.arborescence import combinatorics.quiver.connected_component import group_theory.is_free_group /-! # The Nielsen-Schreier theorem This file proves that a subgroup of a free group is itself free. ## Main result - `subgroup_is_free_of_is_free H`: an instance saying that a subgroup of a free group is free. ## Proof overview The proof is analogous to the proof using covering spaces and fundamental groups of graphs, but we work directly with groupoids instead of topological spaces. Under this analogy, - `is_free_groupoid G` corresponds to saying that a space is a graph. - `End_mul_equiv_subgroup H` plays the role of replacing 'subgroup of fundamental group' with 'fundamental group of covering space'. - `action_groupoid_is_free G A` corresponds to the fact that a covering of a (single-vertex) graph is a graph. - `End_is_free T` corresponds to the fact that, given a spanning tree `T` of a graph, its fundamental group is free (generated by loops from the complement of the tree). ## Implementation notes Our definition of `is_free_groupoid` is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from the generators, but we only consider _groups_ `X`. This simplifies the argument since functor equality is complicated in general, but simple for functors to single object categories. ## References https://ncatlab.org/nlab/show/Nielsen-Schreier+theorem ## Tags free group, free groupoid, Nielsen-Schreier -/ noncomputable theory open_locale classical universes v u open category_theory category_theory.action_category category_theory.single_obj quiver is_free_group as fgp /-- `is_free_groupoid.generators G` is a type synonym for `G`. We think of this as the vertices of the generating quiver of `G` when `G` is free. We can't use `G` directly, since `G` already has a quiver instance from being a groupoid. -/ @[nolint unused_arguments has_nonempty_instance] def is_free_groupoid.generators (G) [groupoid G] := G /-- A groupoid `G` is free when we have the following data: - a quiver on `is_free_groupoid.generators G` (a type synonym for `G`) - a function `of` taking a generating arrow to a morphism in `G` - such that a functor from `G` to any group `X` is uniquely determined by assigning labels in `X` to the generating arrows. This definition is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from `generators`. -/ class is_free_groupoid (G) [groupoid.{v} G] := (quiver_generators : quiver.{v+1} (is_free_groupoid.generators G)) (of : Π {a b : is_free_groupoid.generators G}, (a ⟶ b) → ((show G, from a) ⟶ b)) (unique_lift : ∀ {X : Type v} [group X] (f : labelling (is_free_groupoid.generators G) X), ∃! F : G ⥤ category_theory.single_obj X, ∀ a b (g : a ⟶ b), F.map (of g) = f g) namespace is_free_groupoid attribute [instance] quiver_generators /-- Two functors from a free groupoid to a group are equal when they agree on the generating quiver. -/ @[ext] lemma ext_functor {G} [groupoid.{v} G] [is_free_groupoid G] {X : Type v} [group X] (f g : G ⥤ category_theory.single_obj X) (h : ∀ a b (e : a ⟶ b), f.map (of e) = g.map (of e)) : f = g := let ⟨_, _, u⟩ := @unique_lift G _ _ X _ (λ (a b : generators G) (e : a ⟶ b), g.map (of e)) in trans (u _ h) (u _ (λ _ _ _, rfl)).symm /-- An action groupoid over a free group is free. More generally, one could show that the groupoid of elements over a free groupoid is free, but this version is easier to prove and suffices for our purposes. Analogous to the fact that a covering space of a graph is a graph. (A free groupoid is like a graph, and a groupoid of elements is like a covering space.) -/ instance action_groupoid_is_free {G A : Type u} [group G] [is_free_group G] [mul_action G A] : is_free_groupoid (action_category G A) := { quiver_generators := ⟨λ a b, { e : fgp.generators G // fgp.of e • a.back = b.back }⟩, of := λ a b e, ⟨fgp.of e, e.property⟩, unique_lift := begin introsI X _ f, let f' : fgp.generators G → (A → X) ⋊[mul_aut_arrow] G := λ e, ⟨λ b, @f ⟨(), _⟩ ⟨(), b⟩ ⟨e, smul_inv_smul _ b⟩, fgp.of e⟩, rcases fgp.unique_lift f' with ⟨F', hF', uF'⟩, refine ⟨uncurry F' _, _, _⟩, { suffices : semidirect_product.right_hom.comp F' = monoid_hom.id _, { exact monoid_hom.ext_iff.mp this }, ext, rw [monoid_hom.comp_apply, hF'], refl }, { rintros ⟨⟨⟩, a : A⟩ ⟨⟨⟩, b⟩ ⟨e, h : fgp.of e • a = b⟩, change (F' (fgp.of _)).left _ = _, rw hF', cases (inv_smul_eq_iff.mpr h.symm), refl }, { intros E hE, have : curry E = F', { apply uF', intro e, ext, { convert hE _ _ _, refl }, { refl } }, apply functor.hext, { intro, apply unit.ext }, { refine action_category.cases _, intros, simp only [←this, uncurry_map, curry_apply_left, coe_back, hom_of_pair.val] } }, end } namespace spanning_tree /- In this section, we suppose we have a free groupoid with a spanning tree for its generating quiver. The goal is to prove that the vertex group at the root is free. A picture to have in mind is that we are 'pulling' the endpoints of all the edges of the quiver along the spanning tree to the root. -/ variables {G : Type u} [groupoid.{u} G] [is_free_groupoid G] (T : wide_subquiver (symmetrify $ generators G)) [arborescence T] /-- The root of `T`, except its type is `G` instead of the type synonym `T`. -/ private def root' : G := show T, from root T /-- A path in the tree gives a hom, by composition. -/ -- this has to be marked noncomputable, see issue #451. -- It might be nicer to define this in terms of `compose_path` noncomputable def hom_of_path : Π {a : G}, path (root T) a → (root' T ⟶ a) | _ path.nil := 𝟙 _ | a (path.cons p f) := hom_of_path p ≫ sum.rec_on f.val (λ e, of e) (λ e, inv (of e)) /-- For every vertex `a`, there is a canonical hom from the root, given by the path in the tree. -/ def tree_hom (a : G) : root' T ⟶ a := hom_of_path T default /-- Any path to `a` gives `tree_hom T a`, since paths in the tree are unique. -/ lemma tree_hom_eq {a : G} (p : path (root T) a) : tree_hom T a = hom_of_path T p := by rw [tree_hom, unique.default_eq] @[simp] lemma tree_hom_root : tree_hom T (root' T) = 𝟙 _ := -- this should just be `tree_hom_eq T path.nil`, but Lean treats `hom_of_path` with suspicion. trans (tree_hom_eq T path.nil) rfl /-- Any hom in `G` can be made into a loop, by conjugating with `tree_hom`s. -/ def loop_of_hom {a b : G} (p : a ⟶ b) : End (root' T) := tree_hom T a ≫ p ≫ inv (tree_hom T b) /-- Turning an edge in the spanning tree into a loop gives the indentity loop. -/ lemma loop_of_hom_eq_id {a b : generators G} (e ∈ wide_subquiver_symmetrify T a b) : loop_of_hom T (of e) = 𝟙 (root' T) := begin rw [loop_of_hom, ←category.assoc, is_iso.comp_inv_eq, category.id_comp], cases H, { rw [tree_hom_eq T (path.cons default ⟨sum.inl e, H⟩), hom_of_path], refl }, { rw [tree_hom_eq T (path.cons default ⟨sum.inr e, H⟩), hom_of_path], simp only [is_iso.inv_hom_id, category.comp_id, category.assoc, tree_hom] } end /-- Since a hom gives a loop, any homomorphism from the vertex group at the root extends to a functor on the whole groupoid. -/ @[simps] def functor_of_monoid_hom {X} [monoid X] (f : End (root' T) →* X) : G ⥤ category_theory.single_obj X := { obj := λ _, (), map := λ a b p, f (loop_of_hom T p), map_id' := begin intro a, rw [loop_of_hom, category.id_comp, is_iso.hom_inv_id, ←End.one_def, f.map_one, id_as_one], end, map_comp' := begin intros, rw [comp_as_mul, ←f.map_mul], simp only [is_iso.inv_hom_id_assoc, loop_of_hom, End.mul_def, category.assoc] end } /-- Given a free groupoid and an arborescence of its generating quiver, the vertex group at the root is freely generated by loops coming from generating arrows in the complement of the tree. -/ def End_is_free : is_free_group (End (root' T)) := is_free_group.of_unique_lift ((wide_subquiver_equiv_set_total $ wide_subquiver_symmetrify T)ᶜ : set _) (λ e, loop_of_hom T (of e.val.hom)) begin introsI X _ f, let f' : labelling (generators G) X := λ a b e, if h : e ∈ wide_subquiver_symmetrify T a b then 1 else f ⟨⟨a, b, e⟩, h⟩, rcases unique_lift f' with ⟨F', hF', uF'⟩, refine ⟨F'.map_End _, _, _⟩, { suffices : ∀ {x y} (q : x ⟶ y), F'.map (loop_of_hom T q) = (F'.map q : X), { rintro ⟨⟨a, b, e⟩, h⟩, rw [functor.map_End_apply, this, hF'], exact dif_neg h }, intros, suffices : ∀ {a} (p : path (root' T) a), F'.map (hom_of_path T p) = 1, { simp only [this, tree_hom, comp_as_mul, inv_as_inv, loop_of_hom, inv_one, mul_one, one_mul, functor.map_inv, functor.map_comp] }, intros a p, induction p with b c p e ih, { rw [hom_of_path, F'.map_id, id_as_one] }, rw [hom_of_path, F'.map_comp, comp_as_mul, ih, mul_one], rcases e with ⟨e | e, eT⟩, { rw hF', exact dif_pos (or.inl eT) }, { rw [F'.map_inv, inv_as_inv, inv_eq_one, hF'], exact dif_pos (or.inr eT) } }, { intros E hE, ext, suffices : (functor_of_monoid_hom T E).map x = F'.map x, { simpa only [loop_of_hom, functor_of_monoid_hom_map, is_iso.inv_id, tree_hom_root, category.id_comp, category.comp_id] using this }, congr, apply uF', intros a b e, change E (loop_of_hom T _) = dite _ _ _, split_ifs, { rw [loop_of_hom_eq_id T e h, ←End.one_def, E.map_one] }, { exact hE ⟨⟨a, b, e⟩, h⟩ } } end end spanning_tree /-- Another name for the identity function `G → G`, to help type checking. -/ private def symgen {G : Type u} [groupoid.{v} G] [is_free_groupoid G] : G → symmetrify (generators G) := id /-- If there exists a morphism `a → b` in a free groupoid, then there also exists a zigzag from `a` to `b` in the generating quiver. -/ lemma path_nonempty_of_hom {G} [groupoid.{u u} G] [is_free_groupoid G] {a b : G} : nonempty (a ⟶ b) → nonempty (path (symgen a) (symgen b)) := begin rintro ⟨p⟩, rw [←@weakly_connected_component.eq (generators G), eq_comm, ←free_group.of_injective.eq_iff, ←mul_inv_eq_one], let X := free_group (weakly_connected_component $ generators G), let f : G → X := λ g, free_group.of (weakly_connected_component.mk g), let F : G ⥤ category_theory.single_obj X := single_obj.difference_functor f, change F.map p = ((category_theory.functor.const G).obj ()).map p, congr, ext, rw [functor.const_obj_map, id_as_one, difference_functor_map, mul_inv_eq_one], apply congr_arg free_group.of, apply (weakly_connected_component.eq _ _).mpr, exact ⟨hom.to_path (sum.inr e)⟩, end /-- Given a connected free groupoid, its generating quiver is rooted-connected. -/ instance generators_connected (G) [groupoid.{u u} G] [is_connected G] [is_free_groupoid G] (r : G) : rooted_connected (symgen r) := ⟨λ b, path_nonempty_of_hom (category_theory.nonempty_hom_of_connected_groupoid r b)⟩ /-- A vertex group in a free connected groupoid is free. With some work one could drop the connectedness assumption, by looking at connected components. -/ instance End_is_free_of_connected_free {G} [groupoid G] [is_connected G] [is_free_groupoid G] (r : G) : is_free_group (End r) := spanning_tree.End_is_free $ geodesic_subtree (symgen r) end is_free_groupoid /-- The Nielsen-Schreier theorem: a subgroup of a free group is free. -/ instance subgroup_is_free_of_is_free {G : Type u} [group G] [is_free_group G] (H : subgroup G) : is_free_group H := is_free_group.of_mul_equiv (End_mul_equiv_subgroup H)
7819c83ffdee67cab07e60ee14c348dc17bd1983
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/data/fintype/card.lean
5d97a328669e8a420f12447bfac3d57984308950
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
17,176
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import data.fintype.basic import algebra.big_operators.ring /-! Results about "big operations" over a `fintype`, and consequent results about cardinalities of certain types. ## Implementation note This content had previously been in `data.fintype`, but was moved here to avoid requiring `algebra.big_operators` (and hence many other imports) as a dependency of `fintype`. -/ universes u v variables {α : Type*} {β : Type*} {γ : Type*} open_locale big_operators namespace fintype @[to_additive] lemma prod_bool [comm_monoid α] (f : bool → α) : ∏ b, f b = f tt * f ff := by simp lemma card_eq_sum_ones {α} [fintype α] : fintype.card α = ∑ a : α, 1 := finset.card_eq_sum_ones _ section open finset variables {ι : Type*} [decidable_eq ι] [fintype ι] @[to_additive] lemma prod_extend_by_one [comm_monoid α] (s : finset ι) (f : ι → α) : ∏ i, (if i ∈ s then f i else 1) = ∏ i in s, f i := by rw [← prod_filter, filter_mem_eq_inter, univ_inter] end section variables {M : Type*} [fintype α] [comm_monoid M] @[to_additive] lemma prod_eq_one (f : α → M) (h : ∀ a, f a = 1) : (∏ a, f a) = 1 := finset.prod_eq_one $ λ a ha, h a @[to_additive] lemma prod_congr (f g : α → M) (h : ∀ a, f a = g a) : (∏ a, f a) = ∏ a, g a := finset.prod_congr rfl $ λ a ha, h a @[to_additive] lemma prod_eq_single {f : α → M} (a : α) (h : ∀ x ≠ a, f x = 1) : (∏ x, f x) = f a := finset.prod_eq_single a (λ x _ hx, h x hx) $ λ ha, (ha (finset.mem_univ a)).elim @[to_additive] lemma prod_unique [unique β] (f : β → M) : (∏ x, f x) = f (default β) := by simp only [finset.prod_singleton, univ_unique] /-- If a product of a `finset` of a subsingleton type has a given value, so do the terms in that product. -/ @[to_additive "If a sum of a `finset` of a subsingleton type has a given value, so do the terms in that sum."] lemma eq_of_subsingleton_of_prod_eq {ι : Type*} [subsingleton ι] {s : finset ι} {f : ι → M} {b : M} (h : ∏ i in s, f i = b) : ∀ i ∈ s, f i = b := finset.eq_of_card_le_one_of_prod_eq (finset.card_le_one_of_subsingleton s) h end end fintype open finset section variables {M : Type*} [fintype α] [decidable_eq α] [comm_monoid M] @[to_additive] lemma is_compl.prod_mul_prod {s t : finset α} (h : is_compl s t) (f : α → M) : (∏ i in s, f i) * (∏ i in t, f i) = ∏ i, f i := (finset.prod_union h.disjoint).symm.trans $ by rw [← finset.sup_eq_union, h.sup_eq_top]; refl @[to_additive] lemma finset.prod_mul_prod_compl (s : finset α) (f : α → M) : (∏ i in s, f i) * (∏ i in sᶜ, f i) = ∏ i, f i := is_compl_compl.prod_mul_prod f @[to_additive] lemma finset.prod_compl_mul_prod (s : finset α) (f : α → M) : (∏ i in sᶜ, f i) * (∏ i in s, f i) = ∏ i, f i := is_compl_compl.symm.prod_mul_prod f end @[to_additive] theorem fin.prod_univ_def [comm_monoid β] {n : ℕ} (f : fin n → β) : ∏ i, f i = ((list.fin_range n).map f).prod := by simp [fin.univ_def, finset.fin_range] @[to_additive] theorem fin.prod_of_fn [comm_monoid β] {n : ℕ} (f : fin n → β) : (list.of_fn f).prod = ∏ i, f i := by rw [list.of_fn_eq_map, fin.prod_univ_def] /-- A product of a function `f : fin 0 → β` is `1` because `fin 0` is empty -/ @[simp, to_additive "A sum of a function `f : fin 0 → β` is `0` because `fin 0` is empty"] theorem fin.prod_univ_zero [comm_monoid β] (f : fin 0 → β) : ∏ i, f i = 1 := rfl /-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the product of `f x`, for some `x : fin (n + 1)` times the remaining product -/ theorem fin.prod_univ_succ_above [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) (x : fin (n + 1)) : ∏ i, f i = f x * ∏ i : fin n, f (x.succ_above i) := begin rw [fin.univ_succ_above, finset.prod_insert, finset.prod_image], { intros x _ y _ hxy, exact fin.succ_above_right_inj.mp hxy }, { simp [fin.succ_above_ne] } end /-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the sum of `f x`, for some `x : fin (n + 1)` plus the remaining product -/ theorem fin.sum_univ_succ_above [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) (x : fin (n + 1)) : ∑ i, f i = f x + ∑ i : fin n, f (x.succ_above i) := by apply @fin.prod_univ_succ_above (multiplicative β) attribute [to_additive] fin.prod_univ_succ_above /-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the product of `f 0` plus the remaining product -/ theorem fin.prod_univ_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) : ∏ i, f i = f 0 * ∏ i : fin n, f i.succ := fin.prod_univ_succ_above f 0 /-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the sum of `f 0` plus the remaining product -/ theorem fin.sum_univ_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) : ∑ i, f i = f 0 + ∑ i : fin n, f i.succ := fin.sum_univ_succ_above f 0 attribute [to_additive] fin.prod_univ_succ /-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the product of `f (fin.last n)` plus the remaining product -/ theorem fin.prod_univ_cast_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) : ∏ i, f i = (∏ i : fin n, f i.cast_succ) * f (fin.last n) := by simpa [mul_comm] using fin.prod_univ_succ_above f (fin.last n) /-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)` is the sum of `f (fin.last n)` plus the remaining sum -/ theorem fin.sum_univ_cast_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) : ∑ i, f i = ∑ i : fin n, f i.cast_succ + f (fin.last n) := by apply @fin.prod_univ_cast_succ (multiplicative β) attribute [to_additive] fin.prod_univ_cast_succ @[simp] theorem fintype.card_sigma {α : Type*} (β : α → Type*) [fintype α] [∀ a, fintype (β a)] : fintype.card (sigma β) = ∑ a, fintype.card (β a) := card_sigma _ _ -- FIXME ouch, this should be in the main file. @[simp] theorem fintype.card_sum (α β : Type*) [fintype α] [fintype β] : fintype.card (α ⊕ β) = fintype.card α + fintype.card β := by simp [sum.fintype, fintype.of_equiv_card] @[simp] lemma finset.card_pi [decidable_eq α] {δ : α → Type*} (s : finset α) (t : Π a, finset (δ a)) : (s.pi t).card = ∏ a in s, card (t a) := multiset.card_pi _ _ @[simp] lemma fintype.card_pi_finset [decidable_eq α] [fintype α] {δ : α → Type*} (t : Π a, finset (δ a)) : (fintype.pi_finset t).card = ∏ a, card (t a) := by simp [fintype.pi_finset, card_map] @[simp] lemma fintype.card_pi {β : α → Type*} [decidable_eq α] [fintype α] [f : Π a, fintype (β a)] : fintype.card (Π a, β a) = ∏ a, fintype.card (β a) := fintype.card_pi_finset _ -- FIXME ouch, this should be in the main file. @[simp] lemma fintype.card_fun [decidable_eq α] [fintype α] [fintype β] : fintype.card (α → β) = fintype.card β ^ fintype.card α := by rw [fintype.card_pi, finset.prod_const]; refl @[simp] lemma card_vector [fintype α] (n : ℕ) : fintype.card (vector α n) = fintype.card α ^ n := by rw fintype.of_equiv_card; simp @[simp, to_additive] lemma finset.prod_attach_univ [fintype α] [comm_monoid β] (f : {a : α // a ∈ @univ α _} → β) : ∏ x in univ.attach, f x = ∏ x, f ⟨x, (mem_univ _)⟩ := prod_bij (λ x _, x.1) (λ _ _, mem_univ _) (λ _ _ , by simp) (by simp) (λ b _, ⟨⟨b, mem_univ _⟩, by simp⟩) /-- Taking a product over `univ.pi t` is the same as taking the product over `fintype.pi_finset t`. `univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`, but differ in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and `fintype.pi_finset t` is a `finset (Π a, t a)`. -/ @[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over `fintype.pi_finset t`. `univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`, but differ in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and `fintype.pi_finset t` is a `finset (Π a, t a)`."] lemma finset.prod_univ_pi [decidable_eq α] [fintype α] [comm_monoid β] {δ : α → Type*} {t : Π (a : α), finset (δ a)} (f : (Π (a : α), a ∈ (univ : finset α) → δ a) → β) : ∏ x in univ.pi t, f x = ∏ x in fintype.pi_finset t, f (λ a _, x a) := prod_bij (λ x _ a, x a (mem_univ _)) (by simp) (by simp) (by simp [function.funext_iff] {contextual := tt}) (λ x hx, ⟨λ a _, x a, by simp * at *⟩) /-- The product over `univ` of a sum can be written as a sum over the product of sets, `fintype.pi_finset`. `finset.prod_sum` is an alternative statement when the product is not over `univ` -/ lemma finset.prod_univ_sum [decidable_eq α] [fintype α] [comm_semiring β] {δ : α → Type u_1} [Π (a : α), decidable_eq (δ a)] {t : Π (a : α), finset (δ a)} {f : Π (a : α), δ a → β} : ∏ a, ∑ b in t a, f a b = ∑ p in fintype.pi_finset t, ∏ x, f x (p x) := by simp only [finset.prod_attach_univ, prod_sum, finset.sum_univ_pi] /-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a fintype of cardinality `n` gives `(a + b)^n`. The "good" proof involves expanding along all coordinates using the fact that `x^n` is multilinear, but multilinear maps are only available now over rings, so we give instead a proof reducing to the usual binomial theorem to have a result over semirings. -/ lemma fintype.sum_pow_mul_eq_add_pow (α : Type*) [fintype α] {R : Type*} [comm_semiring R] (a b : R) : ∑ s : finset α, a ^ s.card * b ^ (fintype.card α - s.card) = (a + b) ^ (fintype.card α) := finset.sum_pow_mul_eq_add_pow _ _ _ lemma fin.sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b : R) : ∑ s : finset (fin n), a ^ s.card * b ^ (n - s.card) = (a + b) ^ n := by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b @[to_additive] lemma function.bijective.prod_comp [fintype α] [fintype β] [comm_monoid γ] {f : α → β} (hf : function.bijective f) (g : β → γ) : ∏ i, g (f i) = ∏ i, g i := prod_bij (λ i hi, f i) (λ i hi, mem_univ _) (λ i hi, rfl) (λ i j _ _ h, hf.1 h) $ λ i hi, (hf.2 i).imp $ λ j hj, ⟨mem_univ _, hj.symm⟩ @[to_additive] lemma equiv.prod_comp [fintype α] [fintype β] [comm_monoid γ] (e : α ≃ β) (f : β → γ) : ∏ i, f (e i) = ∏ i, f i := e.bijective.prod_comp f /-- It is equivalent to sum a function over `fin n` or `finset.range n`. -/ @[to_additive] lemma fin.prod_univ_eq_prod_range [comm_monoid α] (f : ℕ → α) (n : ℕ) : ∏ i : fin n, f i = ∏ i in range n, f i := calc (∏ i : fin n, f i) = ∏ i : {x // x ∈ range n}, f i : ((equiv.fin_equiv_subtype n).trans (equiv.subtype_congr_right (λ _, mem_range.symm))).prod_comp (f ∘ coe) ... = ∏ i in range n, f i : by rw [← attach_eq_univ, prod_attach] @[to_additive] lemma finset.prod_fin_eq_prod_range [comm_monoid β] {n : ℕ} (c : fin n → β) : ∏ i, c i = ∏ i in finset.range n, if h : i < n then c ⟨i, h⟩ else 1 := begin rw [← fin.prod_univ_eq_prod_range, finset.prod_congr rfl], rintros ⟨i, hi⟩ _, simp only [fin.coe_eq_val, hi, dif_pos] end @[to_additive] lemma finset.prod_subtype {M : Type*} [comm_monoid M] {p : α → Prop} {F : fintype (subtype p)} {s : finset α} (h : ∀ x, x ∈ s ↔ p x) (f : α → M) : ∏ a in s, f a = ∏ a : subtype p, f a := have (∈ s) = p, from set.ext h, begin rw [← prod_attach, attach_eq_univ], substI p, congr end @[to_additive] lemma finset.prod_fiberwise [decidable_eq β] [fintype β] [comm_monoid γ] (s : finset α) (f : α → β) (g : α → γ) : ∏ b : β, ∏ a in s.filter (λ a, f a = b), g a = ∏ a in s, g a := finset.prod_fiberwise_of_maps_to (λ x _, mem_univ _) _ @[to_additive] lemma fintype.prod_fiberwise [fintype α] [decidable_eq β] [fintype β] [comm_monoid γ] (f : α → β) (g : α → γ) : (∏ b : β, ∏ a : {a // f a = b}, g (a : α)) = ∏ a, g a := begin rw [← (equiv.sigma_preimage_equiv f).prod_comp, ← univ_sigma_univ, prod_sigma], refl end lemma fintype.prod_dite [fintype α] {p : α → Prop} [decidable_pred p] [comm_monoid β] (f : Π (a : α) (ha : p a), β) (g : Π (a : α) (ha : ¬p a), β) : (∏ a, dite (p a) (f a) (g a)) = (∏ a : {a // p a}, f a a.2) * (∏ a : {a // ¬p a}, g a a.2) := begin simp only [prod_dite, attach_eq_univ], congr' 1, { convert (equiv.subtype_congr_right _).prod_comp (λ x : {x // p x}, f x x.2), simp }, { convert (equiv.subtype_congr_right _).prod_comp (λ x : {x // ¬p x}, g x x.2), simp } end section open finset variables {α₁ : Type*} {α₂ : Type*} {M : Type*} [fintype α₁] [fintype α₂] [comm_monoid M] @[to_additive] lemma fintype.prod_sum_type (f : α₁ ⊕ α₂ → M) : (∏ x, f x) = (∏ a₁, f (sum.inl a₁)) * (∏ a₂, f (sum.inr a₂)) := begin classical, let s : finset (α₁ ⊕ α₂) := univ.image sum.inr, rw [← prod_sdiff (subset_univ s), ← @prod_image (α₁ ⊕ α₂) _ _ _ _ _ _ sum.inl, ← @prod_image (α₁ ⊕ α₂) _ _ _ _ _ _ sum.inr], { congr, rw finset.ext_iff, rintro (a|a); { simp only [mem_image, exists_eq, mem_sdiff, mem_univ, exists_false, exists_prop_of_true, not_false_iff, and_self, not_true, and_false], } }, all_goals { intros, solve_by_elim [sum.inl.inj, sum.inr.inj], } end end namespace list lemma prod_take_of_fn [comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) : ((of_fn f).take i).prod = ∏ j in finset.univ.filter (λ (j : fin n), j.val < i), f j := begin have A : ∀ (j : fin n), ¬ ((j : ℕ) < 0) := λ j, not_lt_bot, induction i with i IH, { simp [A] }, by_cases h : i < n, { have : i < length (of_fn f), by rwa [length_of_fn f], rw prod_take_succ _ _ this, have A : ((finset.univ : finset (fin n)).filter (λ j, j.val < i + 1)) = ((finset.univ : finset (fin n)).filter (λ j, j.val < i)) ∪ {(⟨i, h⟩ : fin n)}, by { ext j, simp [nat.lt_succ_iff_lt_or_eq, fin.ext_iff, - add_comm] }, have B : _root_.disjoint (finset.filter (λ (j : fin n), j.val < i) finset.univ) (singleton (⟨i, h⟩ : fin n)), by simp, rw [A, finset.prod_union B, IH], simp }, { have A : (of_fn f).take i = (of_fn f).take i.succ, { rw ← length_of_fn f at h, have : length (of_fn f) ≤ i := not_lt.mp h, rw [take_all_of_le this, take_all_of_le (le_trans this (nat.le_succ _))] }, have B : ∀ (j : fin n), ((j : ℕ) < i.succ) = ((j : ℕ) < i), { assume j, have : (j : ℕ) < i := lt_of_lt_of_le j.2 (not_lt.mp h), simp [this, lt_trans this (nat.lt_succ_self _)] }, simp [← A, B, IH] } end -- `to_additive` does not work on `prod_take_of_fn` because of `0 : ℕ` in the proof. -- Use `multiplicative` instead. lemma sum_take_of_fn [add_comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) : ((of_fn f).take i).sum = ∑ j in finset.univ.filter (λ (j : fin n), j.val < i), f j := @prod_take_of_fn (multiplicative α) _ n f i attribute [to_additive] prod_take_of_fn @[to_additive] lemma prod_of_fn [comm_monoid α] {n : ℕ} {f : fin n → α} : (of_fn f).prod = ∏ i, f i := begin convert prod_take_of_fn f n, { rw [take_all_of_le (le_of_eq (length_of_fn f))] }, { have : ∀ (j : fin n), (j : ℕ) < n := λ j, j.is_lt, simp [this] } end lemma alternating_sum_eq_finset_sum {G : Type*} [add_comm_group G] : ∀ (L : list G), alternating_sum L = ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.is_lt | [] := by { rw [alternating_sum, finset.sum_eq_zero], rintro ⟨i, ⟨⟩⟩ } | (g :: []) := begin show g = ∑ i : fin 1, (-1 : ℤ) ^ (i : ℕ) •ℤ [g].nth_le i i.2, rw [fin.sum_univ_succ], simp, end | (g :: h :: L) := calc g + -h + L.alternating_sum = g + -h + ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.2 : congr_arg _ (alternating_sum_eq_finset_sum _) ... = ∑ i : fin (L.length + 2), (-1 : ℤ) ^ (i : ℕ) •ℤ list.nth_le (g :: h :: L) i _ : begin rw [fin.sum_univ_succ, fin.sum_univ_succ, add_assoc], unfold_coes, simp [nat.succ_eq_add_one, pow_add], refl, end @[to_additive] lemma alternating_prod_eq_finset_prod {G : Type*} [comm_group G] : ∀ (L : list G), alternating_prod L = ∏ i : fin L.length, (L.nth_le i i.2) ^ ((-1 : ℤ) ^ (i : ℕ)) | [] := by { rw [alternating_prod, finset.prod_eq_one], rintro ⟨i, ⟨⟩⟩ } | (g :: []) := begin show g = ∏ i : fin 1, [g].nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ), rw [fin.prod_univ_succ], simp, end | (g :: h :: L) := calc g * h⁻¹ * L.alternating_prod = g * h⁻¹ * ∏ i : fin L.length, L.nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ) : congr_arg _ (alternating_prod_eq_finset_prod _) ... = ∏ i : fin (L.length + 2), list.nth_le (g :: h :: L) i _ ^ (-1 : ℤ) ^ (i : ℕ) : begin rw [fin.prod_univ_succ, fin.prod_univ_succ, mul_assoc], unfold_coes, simp [nat.succ_eq_add_one, pow_add], refl, end end list
133b6df05bb1ce805ac8a5e3e66f417642e1b9ee
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/1862.lean
f6fd57a7032ddcda459881e0f2d0efe59beeaa2b
[ "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
242
lean
class test_neg_neg (R : Type) extends has_neg R, has_one R := (neg_neg : ∀ r : R, -(-r) = r) variable R : Type variable [test_neg_neg R] example : -(-(1:R)) = 1 := begin trace_state, exact test_neg_neg.neg_neg 1, end #check - -(1:R)
ef81d4197b2d388b840815c395ab836515960320
bdb33f8b7ea65f7705fc342a178508e2722eb851
/analysis/measure_theory/measure_space.lean
c89fa06f425bc1cfd38fd5c7fe0dc67b4ed8c3d8
[ "Apache-2.0" ]
permissive
rwbarton/mathlib
939ae09bf8d6eb1331fc2f7e067d39567e10e33d
c13c5ea701bb1eec057e0a242d9f480a079105e9
refs/heads/master
1,584,015,335,862
1,524,142,167,000
1,524,142,167,000
130,614,171
0
0
Apache-2.0
1,548,902,667,000
1,524,437,371,000
Lean
UTF-8
Lean
false
false
21,215
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 Measure spaces -- measures Measures are restricted to a measurable space (associated by the type class `measurable_space`). This allows us to prove equalities between measures by restricting to a generating set of the measurable space. On the other hand, the `μ.measure s` projection (i.e. the measure of `s` on the measure space `μ`) is the _outer_ measure generated by `μ`. This gives us a unrestricted monotonicity rule and it is somehow well-behaved on non-measurable sets. This allows us for the `lebesgue` measure space to have the `borel` measurable space, but still be a complete measure. -/ import data.set order.galois_connection analysis.ennreal analysis.measure_theory.outer_measure noncomputable theory open classical set lattice filter finset function local attribute [instance] prop_decidable universes u v w x namespace measure_theory structure measure_space (α : Type*) [m : measurable_space α] := (measure_of : Π(s : set α), is_measurable s → ennreal) (measure_of_empty : measure_of ∅ is_measurable_empty = 0) (measure_of_Union : ∀{f:ℕ → set α}, ∀h : ∀i, is_measurable (f i), pairwise (disjoint on f) → measure_of (⋃i, f i) (is_measurable_Union h) = (∑i, measure_of (f i) (h i))) namespace measure_space variables {α : Type*} [measurable_space α] (μ : measure_space α) {s s₁ s₂ : set α} /-- Measure projection which is ∞ for non-measurable sets. `measure'` is mainly used to derive the outer measure, for the main `measure` projection. -/ protected def measure' (s : set α) : ennreal := ⨅ h : is_measurable s, μ.measure_of s h protected lemma measure'_eq (h : is_measurable s) : μ.measure' s = μ.measure_of s h := by simp [measure_space.measure', h] protected lemma measure'_empty : μ.measure' ∅ = 0 := by simp [μ.measure'_eq, measure_space.measure_of_empty, is_measurable_empty] protected lemma measure'_Union {f : ℕ → set α} (hd : pairwise (disjoint on f)) (hm : ∀i, is_measurable (f i)) : μ.measure' (⋃i, f i) = (∑i, μ.measure' (f i)) := by simp [μ.measure'_eq, hm, is_measurable_Union hm] {contextual := tt}; from μ.measure_of_Union _ hd protected lemma measure'_union {s₁ s₂ : set α} (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : μ.measure' (s₁ ∪ s₂) = μ.measure' s₁ + μ.measure' s₂ := let s := λn:ℕ, ([s₁, s₂].nth n).get_or_else ∅ in have s0 : s 0 = s₁, from rfl, have s1 : s 1 = s₂, from rfl, have hd : pairwise (disjoint on s), from assume i j h, match i, j, h with | 0, 0, h := (h rfl).elim | 0, (nat.succ 0), h := hd | (nat.succ 0), 0, h := show s₂ ⊓ s₁ = ⊥, by rw [inf_comm]; assumption | (nat.succ 0), (nat.succ 0), h := (h rfl).elim | (nat.succ (nat.succ i)), j, h := begin simp [s, disjoint, (on), option.get_or_else]; exact set.empty_inter _ end | i, (nat.succ (nat.succ j)), h := begin simp [s, disjoint, (on), option.get_or_else]; exact set.inter_empty _ end end, have Un_s : (⋃n, s n) = s₁ ∪ s₂, from subset.antisymm (Union_subset $ assume n, match n with | 0 := subset_union_left _ _ | 1 := subset_union_right _ _ | (nat.succ (nat.succ i)) := empty_subset _ end) (union_subset (subset_Union s 0) (subset_Union s 1)), have hms : ∀n, is_measurable (s n), from assume n, match n with | 0 := h₁ | 1 := h₂ | (nat.succ (nat.succ i)) := is_measurable_empty end, calc μ.measure' (s₁ ∪ s₂) = μ.measure' (⋃n, s n) : by rw [Un_s] ... = (∑n, μ.measure' (s n)) : measure_space.measure'_Union μ hd hms ... = (range (nat.succ (nat.succ 0))).sum (λn, μ.measure' (s n)) : tsum_eq_sum $ assume n hn, match n, hn with | 0, h := by simp at h; contradiction | nat.succ 0, h := by simp at h; contradiction | nat.succ (nat.succ n), h := μ.measure'_empty end ... = μ.measure' s₁ + μ.measure' s₂ : by simp [sum_insert, s0, s1] protected lemma measure'_mono (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) (hs : s₁ ⊆ s₂) : μ.measure' s₁ ≤ μ.measure' s₂ := have hd : s₁ ∩ (s₂ \ s₁) = ∅, from set.ext $ by simp [mem_sdiff] {contextual:=tt}, have hu : s₁ ∪ (s₂ \ s₁) = s₂, from set.ext $ assume x, by by_cases x ∈ s₁; simp [mem_sdiff, h, @hs x] {contextual:=tt}, calc μ.measure' s₁ ≤ μ.measure' s₁ + μ.measure' (s₂ \ s₁) : le_add_of_nonneg_right' ennreal.zero_le ... = μ.measure' (s₁ ∪ (s₂ \ s₁)) : (μ.measure'_union hd h₁ (is_measurable_sdiff h₂ h₁)).symm ... = μ.measure' s₂ : by simp [hu] protected lemma measure'_Union_le_tsum_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) : μ.measure' (⋃i, s i) ≤ (∑i, μ.measure' (s i)) := calc μ.measure' (⋃i, s i) = μ.measure' (⋃i, disjointed s i) : by simp [disjointed_Union] ... = ∑i, μ.measure' (disjointed s i) : μ.measure'_Union disjoint_disjointed $ assume i, is_measurable_disjointed h ... ≤ ∑i, μ.measure' (s i) : ennreal.tsum_le_tsum $ assume i, μ.measure'_mono (is_measurable_disjointed h) (h i) (inter_subset_left _ _) /-- outer measure of a measure -/ protected def to_outer_measure : outer_measure α := outer_measure.of_function μ.measure' μ.measure'_empty /-- Measure projections for a measure space. For measurable sets this returns the measure assigned by the `measure_of` field in `measure_space`. But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and subadditivity for all sets. -/ protected def measure (s : set α) : ennreal := μ.to_outer_measure.measure_of s instance : has_coe_to_fun (measure_space α) := ⟨_, measure_space.measure⟩ protected lemma measure_eq (hs : is_measurable s) : μ s = μ.measure_of s hs := le_antisymm (infi_le_of_le (λn, ⋃h : n = 0, s) $ infi_le_of_le begin simp [set.subset_def] end $ calc (∑i, ⨅ h : is_measurable (⋃ h : i = 0, s), μ.measure_of _ h) = ({0}:finset ℕ).sum (λi, ⨅ h : is_measurable (⋃ h : i = 0, s), μ.measure_of _ h) : tsum_eq_sum $ assume b, begin simp, intro hb, rw [set.Union_neg hb, infi_pos is_measurable_empty, measure_space.measure_of_empty] end ... ≤ μ.measure_of s hs : by simp [hs]) (le_infi $ assume f, le_infi $ assume hf, classical.by_cases (assume : ∀i, is_measurable (f i), calc μ.measure_of s hs = μ.measure' s : by rw [μ.measure'_eq] ... ≤ μ.measure' (⋃i, f i) : μ.measure'_mono hs (is_measurable_Union this) hf ... ≤ ∑ (i : ℕ), μ.measure' (f i) : μ.measure'_Union_le_tsum_nat this) (assume : ¬ ∀i, is_measurable (f i), have ∃i, ¬ is_measurable (f i), by rwa [classical.not_forall] at this, let ⟨i, hi⟩ := this in calc μ.measure_of s hs ≤ μ.measure' (f i) : le_infi $ assume hi', by contradiction ... ≤ ∑ (i : ℕ), μ.measure' (f i) : ennreal.le_tsum)) protected lemma measure_eq_measure' (hs : is_measurable s) : μ s = μ.measure' s := by rwa [μ.measure_eq, μ.measure'_eq] end measure_space section variables {α : Type*} {β : Type*} [measurable_space α] {μ μ₁ μ₂ : measure_space α} {s s₁ s₂ : set α} lemma measure_space_eq_of : ∀{μ₁ μ₂ : measure_space α}, (∀s, ∀h:is_measurable s, μ₁.measure_of s h = μ₂.measure_of s h) → μ₁ = μ₂ | ⟨m₁, e₁, u₁⟩ ⟨m₂, e₂, u₂⟩ h := have m₁ = m₂, from funext $ assume s, funext $ assume hs, h s hs, by simp [this] lemma measure_space_eq (h : ∀s, is_measurable s → μ₁ s = μ₂ s) : μ₁ = μ₂ := measure_space_eq_of $ assume s hs, have μ₁ s = μ₂ s, from h s hs, by simp [measure_space.measure_eq, hs] at this; assumption @[simp] lemma measure_empty : μ ∅ = 0 := μ.to_outer_measure.empty lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.to_outer_measure.mono h lemma measure_Union_le_tsum_nat {s : ℕ → set α} : μ (⋃i, s i) ≤ (∑i, μ (s i)) := μ.to_outer_measure.Union_nat s lemma measure_union (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := by simp only [μ.measure_eq_measure', h₁, h₂, is_measurable_union]; from μ.measure'_union hd h₁ h₂ lemma measure_Union_nat {f : ℕ → set α} (hn : pairwise (disjoint on f)) (h : ∀i, is_measurable (f i)) : μ (⋃i, f i) = (∑i, μ (f i)) := by simp [measure_space.measure_eq, h, is_measurable_Union h, μ.measure_of_Union h hn] lemma measure_bUnion {i : set β} {s : β → set α} (hi : countable i) (hd : pairwise_on i (disjoint on s)) (h : ∀b∈i, is_measurable (s b)) : μ (⋃b∈i, s b) = ∑p:{b // b ∈ i}, μ (s p.val) := let ⟨f, hf⟩ := hi in let g : ℕ → set α := λn, ⋃b (h : b ∈ i) (h : f b = n), s b in have h_gf : ∀b∈i, g (f b) = s b, from assume b hb, le_antisymm (supr_le $ assume b', supr_le $ assume hb', supr_le $ assume hbn, have f b = f b', by simp [hbn], have b = b', from hf _ hb _ hb' this, by simp [this]; exact le_refl _) (le_supr_of_le b $ le_supr_of_le hb $ le_supr_of_le rfl $ le_refl _), have eq₁ : (⋃b∈i, s b) = (⋃i, g i), from le_antisymm (bUnion_subset $ assume b hb, show s b ≤ ⨆n (b:β) (h : b ∈ i) (h : f b = n), s b, from le_supr_of_le (f b) $ le_supr_of_le b $ le_supr_of_le hb $ le_supr_of_le rfl $ le_refl (s b)) (supr_le $ assume n, supr_le $ assume b, supr_le $ assume hb, supr_le $ assume hnb, subset_bUnion_of_mem hb), have hd : pairwise (disjoint on g), from assume n m h, set.eq_empty_of_subset_empty $ calc g n ∩ g m = (⋃b (h : b ∈ i) (h : f b = n) b' (h : b' ∈ i) (h : f b' = m), s b ∩ s b') : by simp [g, inter_distrib_Union_left, inter_distrib_Union_right] ... ⊆ ∅ : bUnion_subset $ assume b hb, Union_subset $ assume hbn, bUnion_subset $ assume b' hb', Union_subset $ assume hbm, have b ≠ b', from assume h_eq, have f b = f b', from congr_arg f h_eq, by simp [hbm, hbn, h] at this; assumption, have s b ∩ s b' = ∅, from hd b hb b' hb' this, by rw [this]; exact subset.refl _, have hm : ∀n, is_measurable (g n), from assume n, by_cases (assume : ∃b∈i, f b = n, let ⟨b, hb, h_eq⟩ := this in have s b = g n, from h_eq ▸ (h_gf b hb).symm, this ▸ h b hb) (assume : ¬ ∃b∈i, f b = n, have g n = ∅, from set.eq_empty_of_subset_empty $ bUnion_subset $ assume b hb, Union_subset $ assume h_eq, (this ⟨b, hb, h_eq⟩).elim, this.symm ▸ is_measurable_empty), calc μ (⋃b∈i, s b) = μ (⋃i, g i) : by rw [eq₁] ... = (∑i, μ (g i)) : measure_Union_nat hd hm ... = (∑p:{b // b ∈ i}, μ (s p.val)) : tsum_eq_tsum_of_ne_zero_bij (λb h, f b.val) (assume ⟨b₁, hb₁⟩ ⟨b₂, hb₂⟩ _ _ h, subtype.eq $ show b₁ = b₂, from hf b₁ hb₁ b₂ hb₂ h) (assume n hn, have g n ≠ ∅, from assume h, by simp [h] at hn; assumption, have ∃b∈i, f b = n, from let ⟨x, hx⟩ := set.exists_mem_of_ne_empty this in by simp at hx; exact let ⟨b, hb, h_eq, _⟩ := hx in ⟨b, hb, h_eq⟩, let ⟨b, hb, h_eq⟩ := this in have g n = s b, from h_eq ▸ h_gf b hb, ⟨⟨b, hb⟩, by simp [this] at hn; assumption, h_eq⟩) (assume ⟨b, hb⟩, by simp [hb, h_gf]) lemma measure_sUnion [encodable β] {s : β → set α} (hd : pairwise (disjoint on s)) (h : ∀b, is_measurable (s b)) : μ (⋃b, s b) = ∑b, μ (s b) := calc μ (⋃b, s b) = μ (⋃b∈(univ:set β), s b) : congr_arg μ $ set.ext $ by simp ... = ∑p:{b:β // true}, μ (s p.val) : measure_bUnion countable_encodable (assume i _ j _, hd i j) (assume b _, h b) ... = ∑b, μ (s b) : @tsum_eq_tsum_of_iso _ _ _ _ _ _ _ (λb, μ (s b)) subtype.val (λb, ⟨b, trivial⟩ : β → {b:β // true}) (λ⟨b, hb⟩, rfl) (λb, rfl) lemma measure_sdiff {s₁ s₂ : set α} (h : s₂ ⊆ s₁) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) (h_fin : μ s₁ < ⊤) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := have hd : disjoint (s₁ \ s₂) s₂, from sdiff_inter_same, have μ s₂ < ⊤, from lt_of_le_of_lt (measure_mono h) h_fin, calc μ (s₁ \ s₂) = (μ (s₁ \ s₂) + μ s₂) - μ s₂ : by rw [ennreal.add_sub_self this] ... = μ (s₁ \ s₂ ∪ s₂) - μ s₂ : by rw [measure_union hd]; simp [is_measurable_sdiff, h₁, h₂] ... = _ : by rw [sdiff_union_same, union_of_subset_right h] lemma measure_Union_eq_supr_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : monotone s) : μ (⋃i, s i) = (⨆i, μ (s i)) := -- TODO: generalize and extract from this proof have ∀i, (range (i + 1)).sum (λi, μ (disjointed s i)) = μ (s i), begin intro i, induction i, case nat.zero { simp [disjointed, nat.not_lt_zero, inter_univ] }, case nat.succ : i ih { rw [range_succ, sum_insert, ih, ←measure_union], { show μ (disjointed s (i + 1) ∪ s i) = μ (s (i + 1)), rw [disjointed_of_mono hs, sdiff_union_same, union_of_subset_right], exact hs (nat.le_succ _) }, { show disjoint (disjointed s (i + 1)) (s i), simp [disjoint, disjointed_of_mono hs], exact sdiff_inter_same }, { exact is_measurable_disjointed h }, { exact h _ }, { exact not_mem_range_self } } end, calc μ (⋃i, s i) = μ (⋃i, disjointed s i) : by rw [disjointed_Union] ... = (∑i, μ (disjointed s i)) : measure_Union_nat (disjoint_disjointed) (assume i, is_measurable_disjointed h) ... = (⨆i, (finset.range i).sum (λi, μ (disjointed s i))) : by rw [ennreal.tsum_eq_supr_nat] ... = (⨆i, (range (i + 1)).sum (λi, μ (disjointed s i))) : le_antisymm (supr_le begin intro i, cases i with j, simp, exact le_supr_of_le j (le_refl _) end) (supr_le $ assume i, le_supr_of_le (i + 1) $ le_refl _) ... = (⨆i, μ (s i)) : congr_arg _ $ funext $ this lemma measure_Inter_eq_infi_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : ∀i j, i ≤ j → s j ⊆ s i) (hfin : μ (s 0) < ⊤) : μ (⋂i, s i) = (⨅i, μ (s i)) := have eq₁ : (⋂i, s i) = (s 0 \ (⋃i, s 0 \ s i)), from set.ext $ begin simp [iff_def], simp [imp_false] {contextual := tt} end, have sub : (⋃i, s 0 \ s i) ⊆ s 0, from Union_subset $ assume i, assume x, by simp {contextual := tt}, have hd : ∀i, is_measurable (s 0 \ s i), from assume i, is_measurable_sdiff (h 0) (h i), have hu : is_measurable (⋃i, s 0 \ s i), from is_measurable_Union hd, have hm : monotone (λ (i : ℕ), s 0 \ s i), from assume i j h, sdiff_subset_sdiff (subset.refl _) (hs i j h), have eq₂ : ∀i, μ (s 0) - (μ (s 0) - μ (s i)) = μ (s i), from assume i, have μ (s i) ≤ μ (s 0), from measure_mono (hs _ _ $ nat.zero_le _), let ⟨r, hr, eqr, _⟩ := ennreal.lt_iff_exists_of_real.mp hfin in let ⟨p, hp, eqp, _⟩ := ennreal.lt_iff_exists_of_real.mp (lt_of_le_of_lt this hfin) in have 0 ≤ r - p, by rw [le_sub_iff_add_le, zero_add, ←ennreal.of_real_le_of_real_iff hp hr, ←eqp, ←eqr]; from this, by simp [eqr, eqp, hp, hr, this, -sub_eq_add_neg, sub_sub_self], calc μ (⋂i, s i) = μ (s 0 \ (⋃i, s 0 \ s i)) : congr_arg _ eq₁ ... = μ (s 0) - μ (⋃i, s 0 \ s i) : by rw [measure_sdiff sub (h 0) hu hfin] ... = μ (s 0) - (⨆i, μ (s 0 \ s i)) : by rw [measure_Union_eq_supr_nat hd hm] ... = (⨅i, μ (s 0) - μ (s 0 \ s i)) : ennreal.sub_supr hfin ... = (⨅i, μ (s i)) : congr_arg _ $ funext $ assume i, by rw [measure_sdiff (hs _ _ (nat.zero_le _)) (h 0) (h i) hfin, eq₂] end def outer_measure.to_measure {α : Type*} (m : outer_measure α) [ms : measurable_space α] (h : ms ≤ m.caratheodory) : measure_space α := { measure_of := λs hs, m.measure_of s, measure_of_empty := m.empty, measure_of_Union := assume s hs hf, m.Union_eq_of_caratheodory (assume i, h _ $ hs i) hf } lemma le_to_outer_measure_caratheodory {α : Type*} [ms : measurable_space α] {μ : measure_space α} : ms ≤ μ.to_outer_measure.caratheodory := assume s hs, outer_measure.caratheodory_is_measurable $ assume t, by_cases (assume : is_measurable t, have hst₁ : is_measurable (t ∩ s), from is_measurable_inter this hs, have hst₂ : is_measurable (t \ s), from is_measurable_sdiff this hs, have t_eq : (t ∩ s) ∪ (t \ s) = t, from set.ext $ assume x, by by_cases x∈s; simp [h], have h : (t ∩ s) ∩ (t \ s) = ∅, from set.ext $ by simp {contextual:=tt}, by rw [← μ.measure_eq_measure' this, ← μ.measure_eq_measure' hst₁, ← μ.measure_eq_measure' hst₂, ← measure_union h hst₁ hst₂, t_eq]) (assume : ¬ is_measurable t, le_infi $ assume h, false.elim $ this h) lemma to_outer_measure_to_measure {α : Type*} [ms : measurable_space α] {μ : measure_space α} : μ.to_outer_measure.to_measure le_to_outer_measure_caratheodory = μ := measure_space_eq $ assume s hs, by rw [μ.measure_eq hs, measure_space.measure_eq _ hs]; exact μ.measure_eq hs namespace measure_space variables {α : Type*} {β : Type*} {γ : Type*} [measurable_space α] [measurable_space β] [measurable_space γ] instance : has_zero (measure_space α) := ⟨{ measure_of := λs hs, 0, measure_of_empty := rfl, measure_of_Union := by simp }⟩ instance : inhabited (measure_space α) := ⟨0⟩ instance : has_add (measure_space α) := ⟨λμ₁ μ₂, { measure_space . measure_of := λs hs, μ₁.measure_of s hs + μ₂.measure_of s hs, measure_of_empty := by simp [measure_space.measure_of_empty], measure_of_Union := assume f hf hd, by simp [measure_space.measure_of_Union, hf, hd, tsum_add] {contextual := tt} }⟩ instance : add_comm_monoid (measure_space α) := { add_comm_monoid . zero := 0, add := (+), add_assoc := assume a b c, measure_space_eq_of $ assume s hs, add_assoc _ _ _, add_comm := assume a b, measure_space_eq_of $ assume s hs, add_comm _ _, zero_add := assume a, measure_space_eq_of $ assume s hs, zero_add _, add_zero := assume a, measure_space_eq_of $ assume s hs, add_zero _ } instance : partial_order (measure_space α) := { partial_order . le := λm₁ m₂, ∀s (hs : is_measurable s), m₁.measure_of s hs ≤ m₂.measure_of s hs, le_refl := assume m s hs, le_refl _, le_trans := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs), le_antisymm := assume m₁ m₂ h₁ h₂, measure_space_eq_of $ assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) } def map (f : α → β) (μ : measure_space α) : measure_space β := if hf : measurable f then { measure_of := λs hs, μ (f ⁻¹' s), measure_of_empty := by simp, measure_of_Union := assume s hs h, have h' : pairwise (disjoint on λ (i : ℕ), f ⁻¹' s i), from assume i j hij, have s i ∩ s j = ∅, from h i j hij, show f ⁻¹' s i ∩ f ⁻¹' s j = ∅, by rw [← preimage_inter, this, preimage_empty], by rw [preimage_Union]; exact measure_Union_nat h' (assume i, hf (s i) (hs i)) } else 0 variables {μ : measure_space α} lemma map_measure {f : α → β} {s : set β} (hf : measurable f) (hs : is_measurable s) : (μ.map f : measure_space β) s = μ (f ⁻¹' s) := by rw [map, dif_pos hf, measure_space.measure_eq _ hs] lemma map_id : map id μ = μ := measure_space_eq $ assume s, map_measure measurable_id lemma map_comp {f : α → β} {g : β → γ} (hf : measurable f) (hg : measurable g) : map (g ∘ f) μ = map g (map f μ) := measure_space_eq $ assume s hs, by rw [map_measure (measurable_comp hf hg) hs, map_measure hg hs, map_measure hf (hg s hs), preimage_comp] /-- The dirac measure. -/ def dirac (a : α) : measure_space α := { measure_of := λs hs, ⨆h:a ∈ s, 1, measure_of_empty := by simp [ennreal.bot_eq_zero], measure_of_Union := assume f hf h, by_cases (assume : ∃i, a ∈ f i, let ⟨i, hi⟩ := this in have ∀j, (a ∈ f j) ↔ (i = j), from assume j, ⟨assume hj, classical.by_contradiction $ assume hij, have eq: f i ∩ f j = ∅, from h i j hij, have a ∈ f i ∩ f j, from ⟨hi, hj⟩, (mem_empty_eq a).mp $ by rwa [← eq], assume h, h ▸ hi⟩, by simp [this]) (by simp [ennreal.bot_eq_zero] {contextual := tt}) } /-- Sum of an indexed family of measures. -/ def sum {ι : Type*} (f : ι → measure_space α) : measure_space α := { measure_of := λs hs, ∑i, f i s, measure_of_empty := by simp, measure_of_Union := assume f hf h, by simp [measure_Union_nat h hf]; rw [ennreal.tsum_comm] } /-- Counting measure on any measurable space. -/ def count : measure_space α := sum dirac end measure_space end measure_theory
6a5a937e86a9c9527b16a00f589a1a30cca5b244
c777c32c8e484e195053731103c5e52af26a25d1
/src/data/real/irrational.lean
c2463026fe0192951de0f3541fad06291e2edd69
[ "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
17,771
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Yury Kudryashov -/ import data.real.sqrt import tactic.interval_cases import ring_theory.algebraic import data.rat.sqrt import ring_theory.int.basic /-! # Irrational real numbers In this file we define a predicate `irrational` on `ℝ`, prove that the `n`-th root of an integer number is irrational if it is not integer, and that `sqrt q` is irrational if and only if `rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q`. We also provide dot-style constructors like `irrational.add_rat`, `irrational.rat_sub` etc. -/ open rat real multiplicity /-- A real number is irrational if it is not equal to any rational number. -/ def irrational (x : ℝ) := x ∉ set.range (coe : ℚ → ℝ) lemma irrational_iff_ne_rational (x : ℝ) : irrational x ↔ ∀ a b : ℤ, x ≠ a / b := by simp only [irrational, rat.forall, cast_mk, not_exists, set.mem_range, cast_coe_int, cast_div, eq_comm] /-- A transcendental real number is irrational. -/ lemma transcendental.irrational {r : ℝ} (tr : transcendental ℚ r) : irrational r := by { rintro ⟨a, rfl⟩, exact tr (is_algebraic_algebra_map a) } /-! ### Irrationality of roots of integer and rational numbers -/ /-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then `x` is irrational. -/ theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = m) (hv : ¬ ∃ y : ℤ, x = y) (hnpos : 0 < n) : irrational x := begin rintros ⟨⟨N, D, P, C⟩, rfl⟩, rw [← cast_pow] at hxr, have c1 : ((D : ℤ) : ℝ) ≠ 0, { rw [int.cast_ne_zero, int.coe_nat_ne_zero], exact ne_of_gt P }, have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1, rw [num_denom', cast_pow, cast_mk, div_pow, div_eq_iff_mul_eq c2, ← int.cast_pow, ← int.cast_pow, ← int.cast_mul, int.cast_inj] at hxr, have hdivn : ↑D ^ n ∣ N ^ n := dvd.intro_left m hxr, rw [← int.dvd_nat_abs, ← int.coe_nat_pow, int.coe_nat_dvd, int.nat_abs_pow, nat.pow_dvd_pow_iff hnpos] at hdivn, obtain rfl : D = 1 := by rw [← nat.gcd_eq_right hdivn, C.gcd_eq_one], refine hv ⟨N, _⟩, rw [num_denom', int.coe_nat_one, mk_eq_div, int.cast_one, div_one, cast_coe_int] end /-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x` is irrational. -/ theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ) [hp : fact p.prime] (hxr : x ^ n = m) (hv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, hm⟩) % n ≠ 0) : irrational x := begin rcases nat.eq_zero_or_pos n with rfl | hnpos, { rw [eq_comm, pow_zero, ← int.cast_one, int.cast_inj] at hxr, simpa [hxr, multiplicity.one_right (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.1.not_dvd_one)), nat.zero_mod] using hv }, refine irrational_nrt_of_notint_nrt _ _ hxr _ hnpos, rintro ⟨y, rfl⟩, rw [← int.cast_pow, int.cast_inj] at hxr, subst m, have : y ≠ 0, { rintro rfl, rw zero_pow hnpos at hm, exact hm rfl }, erw [multiplicity.pow' (nat.prime_iff_prime_int.1 hp.1) (finite_int_iff.2 ⟨hp.1.ne_one, this⟩), nat.mul_mod_right] at hv, exact hv rfl end theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : fact p.prime] (Hpv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, (ne_of_lt hm).symm⟩) % 2 = 1) : irrational (sqrt m) := @irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (ne.symm (ne_of_lt hm)) p hp (sq_sqrt (int.cast_nonneg.2 $ le_of_lt hm)) (by rw Hpv; exact one_ne_zero) theorem nat.prime.irrational_sqrt {p : ℕ} (hp : nat.prime p) : irrational (sqrt p) := @irrational_sqrt_of_multiplicity_odd p (int.coe_nat_pos.2 hp.pos) p ⟨hp⟩ $ by simp [multiplicity_self (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one) : _)]; refl /-- **Irrationality of the Square Root of 2** -/ theorem irrational_sqrt_two : irrational (sqrt 2) := by simpa using nat.prime_two.irrational_sqrt theorem irrational_sqrt_rat_iff (q : ℚ) : irrational (sqrt q) ↔ rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q := if H1 : rat.sqrt q * rat.sqrt q = q then iff_of_false (not_not_intro ⟨rat.sqrt q, by rw [← H1, cast_mul, sqrt_mul_self (cast_nonneg.2 $ rat.sqrt_nonneg q), sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]⟩) (λ h, h.1 H1) else if H2 : 0 ≤ q then iff_of_true (λ ⟨r, hr⟩, H1 $ (exists_mul_self _).1 ⟨r, by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, rat.cast_inj] at hr; rw [← hr]; exact real.sqrt_nonneg _⟩) ⟨H1, H2⟩ else iff_of_false (not_not_intro ⟨0, by rw cast_zero; exact (sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)).symm⟩) (λ h, H2 h.2) instance (q : ℚ) : decidable (irrational (sqrt q)) := decidable_of_iff' _ (irrational_sqrt_rat_iff q) /-! ### Dot-style operations on `irrational` #### Coercion of a rational/integer/natural number is not irrational -/ namespace irrational variable {x : ℝ} /-! #### Irrational number is not equal to a rational/integer/natural number -/ theorem ne_rat (h : irrational x) (q : ℚ) : x ≠ q := λ hq, h ⟨q, hq.symm⟩ theorem ne_int (h : irrational x) (m : ℤ) : x ≠ m := by { rw ← rat.cast_coe_int, exact h.ne_rat _ } theorem ne_nat (h : irrational x) (m : ℕ) : x ≠ m := h.ne_int m theorem ne_zero (h : irrational x) : x ≠ 0 := by exact_mod_cast h.ne_nat 0 theorem ne_one (h : irrational x) : x ≠ 1 := by simpa only [nat.cast_one] using h.ne_nat 1 end irrational @[simp] lemma rat.not_irrational (q : ℚ) : ¬irrational q := λ h, h ⟨q, rfl⟩ @[simp] lemma int.not_irrational (m : ℤ) : ¬irrational m := λ h, h.ne_int m rfl @[simp] lemma nat.not_irrational (m : ℕ) : ¬irrational m := λ h, h.ne_nat m rfl namespace irrational variables (q : ℚ) {x y : ℝ} /-! #### Addition of rational/integer/natural numbers -/ /-- If `x + y` is irrational, then at least one of `x` and `y` is irrational. -/ theorem add_cases : irrational (x + y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx + ry, cast_add rx ry⟩ end theorem of_rat_add (h : irrational (q + x)) : irrational x := h.add_cases.resolve_left q.not_irrational theorem rat_add (h : irrational x) : irrational (q + x) := of_rat_add (-q) $ by rwa [cast_neg, neg_add_cancel_left] theorem of_add_rat : irrational (x + q) → irrational x := add_comm ↑q x ▸ of_rat_add q theorem add_rat (h : irrational x) : irrational (x + q) := add_comm ↑q x ▸ h.rat_add q theorem of_int_add (m : ℤ) (h : irrational (m + x)) : irrational x := by { rw ← cast_coe_int at h, exact h.of_rat_add m } theorem of_add_int (m : ℤ) (h : irrational (x + m)) : irrational x := of_int_add m $ add_comm x m ▸ h theorem int_add (h : irrational x) (m : ℤ) : irrational (m + x) := by { rw ← cast_coe_int, exact h.rat_add m } theorem add_int (h : irrational x) (m : ℤ) : irrational (x + m) := add_comm ↑m x ▸ h.int_add m theorem of_nat_add (m : ℕ) (h : irrational (m + x)) : irrational x := h.of_int_add m theorem of_add_nat (m : ℕ) (h : irrational (x + m)) : irrational x := h.of_add_int m theorem nat_add (h : irrational x) (m : ℕ) : irrational (m + x) := h.int_add m theorem add_nat (h : irrational x) (m : ℕ) : irrational (x + m) := h.add_int m /-! #### Negation -/ theorem of_neg (h : irrational (-x)) : irrational x := λ ⟨q, hx⟩, h ⟨-q, by rw [cast_neg, hx]⟩ protected theorem neg (h : irrational x) : irrational (-x) := of_neg $ by rwa neg_neg /-! #### Subtraction of rational/integer/natural numbers -/ theorem sub_rat (h : irrational x) : irrational (x - q) := by simpa only [sub_eq_add_neg, cast_neg] using h.add_rat (-q) theorem rat_sub (h : irrational x) : irrational (q - x) := by simpa only [sub_eq_add_neg] using h.neg.rat_add q theorem of_sub_rat (h : irrational (x - q)) : irrational x := (of_add_rat (-q) $ by simpa only [cast_neg, sub_eq_add_neg] using h) theorem of_rat_sub (h : irrational (q - x)) : irrational x := of_neg (of_rat_add q (by simpa only [sub_eq_add_neg] using h)) theorem sub_int (h : irrational x) (m : ℤ) : irrational (x - m) := by simpa only [rat.cast_coe_int] using h.sub_rat m theorem int_sub (h : irrational x) (m : ℤ) : irrational (m - x) := by simpa only [rat.cast_coe_int] using h.rat_sub m theorem of_sub_int (m : ℤ) (h : irrational (x - m)) : irrational x := of_sub_rat m $ by rwa rat.cast_coe_int theorem of_int_sub (m : ℤ) (h : irrational (m - x)) : irrational x := of_rat_sub m $ by rwa rat.cast_coe_int theorem sub_nat (h : irrational x) (m : ℕ) : irrational (x - m) := h.sub_int m theorem nat_sub (h : irrational x) (m : ℕ) : irrational (m - x) := h.int_sub m theorem of_sub_nat (m : ℕ) (h : irrational (x - m)) : irrational x := h.of_sub_int m theorem of_nat_sub (m : ℕ) (h : irrational (m - x)) : irrational x := h.of_int_sub m /-! #### Multiplication by rational numbers -/ theorem mul_cases : irrational (x * y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx * ry, cast_mul rx ry⟩ end theorem of_mul_rat (h : irrational (x * q)) : irrational x := h.mul_cases.resolve_right q.not_irrational theorem mul_rat (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x * q) := of_mul_rat q⁻¹ $ by rwa [mul_assoc, ← cast_mul, mul_inv_cancel hq, cast_one, mul_one] theorem of_rat_mul : irrational (q * x) → irrational x := mul_comm x q ▸ of_mul_rat q theorem rat_mul (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (q * x) := mul_comm x q ▸ h.mul_rat hq theorem of_mul_int (m : ℤ) (h : irrational (x * m)) : irrational x := of_mul_rat m $ by rwa cast_coe_int theorem of_int_mul (m : ℤ) (h : irrational (m * x)) : irrational x := of_rat_mul m $ by rwa cast_coe_int theorem mul_int (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (x * m) := by { rw ← cast_coe_int, refine h.mul_rat _, rwa int.cast_ne_zero } theorem int_mul (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (m * x) := mul_comm x m ▸ h.mul_int hm theorem of_mul_nat (m : ℕ) (h : irrational (x * m)) : irrational x := h.of_mul_int m theorem of_nat_mul (m : ℕ) (h : irrational (m * x)) : irrational x := h.of_int_mul m theorem mul_nat (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (x * m) := h.mul_int $ int.coe_nat_ne_zero.2 hm theorem nat_mul (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (m * x) := h.int_mul $ int.coe_nat_ne_zero.2 hm /-! #### Inverse -/ theorem of_inv (h : irrational x⁻¹) : irrational x := λ ⟨q, hq⟩, h $ hq ▸ ⟨q⁻¹, q.cast_inv⟩ protected theorem inv (h : irrational x) : irrational x⁻¹ := of_inv $ by rwa inv_inv /-! #### Division -/ theorem div_cases (h : irrational (x / y)) : irrational x ∨ irrational y := h.mul_cases.imp id of_inv theorem of_rat_div (h : irrational (q / x)) : irrational x := (h.of_rat_mul q).of_inv theorem of_div_rat (h : irrational (x / q)) : irrational x := h.div_cases.resolve_right q.not_irrational theorem rat_div (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (q / x) := h.inv.rat_mul hq theorem div_rat (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x / q) := by { rw [div_eq_mul_inv, ← cast_inv], exact h.mul_rat (inv_ne_zero hq) } theorem of_int_div (m : ℤ) (h : irrational (m / x)) : irrational x := h.div_cases.resolve_left m.not_irrational theorem of_div_int (m : ℤ) (h : irrational (x / m)) : irrational x := h.div_cases.resolve_right m.not_irrational theorem int_div (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (m / x) := h.inv.int_mul hm theorem div_int (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (x / m) := by { rw ← cast_coe_int, refine h.div_rat _, rwa int.cast_ne_zero } theorem of_nat_div (m : ℕ) (h : irrational (m / x)) : irrational x := h.of_int_div m theorem of_div_nat (m : ℕ) (h : irrational (x / m)) : irrational x := h.of_div_int m theorem nat_div (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (m / x) := h.inv.nat_mul hm theorem div_nat (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (x / m) := h.div_int $ by rwa int.coe_nat_ne_zero theorem of_one_div (h : irrational (1 / x)) : irrational x := of_rat_div 1 $ by rwa [cast_one] /-! #### Natural and integerl power -/ theorem of_mul_self (h : irrational (x * x)) : irrational x := h.mul_cases.elim id id theorem of_pow : ∀ n : ℕ, irrational (x^n) → irrational x | 0 := λ h, by { rw pow_zero at h, exact (h ⟨1, cast_one⟩).elim } | (n+1) := λ h, by { rw pow_succ at h, exact h.mul_cases.elim id (of_pow n) } theorem of_zpow : ∀ m : ℤ, irrational (x^m) → irrational x | (n:ℕ) := λ h, by { rw zpow_coe_nat at h, exact h.of_pow _ } | -[1+n] := λ h, by { rw zpow_neg_succ_of_nat at h, exact h.of_inv.of_pow _ } end irrational section polynomial open polynomial open_locale polynomial variables (x : ℝ) (p : ℤ[X]) lemma one_lt_nat_degree_of_irrational_root (hx : irrational x) (p_nonzero : p ≠ 0) (x_is_root : aeval x p = 0) : 1 < p.nat_degree := begin by_contra rid, rcases exists_eq_X_add_C_of_nat_degree_le_one (not_lt.1 rid) with ⟨a, b, rfl⟩, clear rid, have : (a : ℝ) * x = -b, by simpa [eq_neg_iff_add_eq_zero] using x_is_root, rcases em (a = 0) with (rfl|ha), { obtain rfl : b = 0, by simpa, simpa using p_nonzero }, { rw [mul_comm, ← eq_div_iff_mul_eq, eq_comm] at this, refine hx ⟨-b / a, _⟩, assumption_mod_cast, assumption_mod_cast } end end polynomial section variables {q : ℚ} {m : ℤ} {n : ℕ} {x : ℝ} open irrational /-! ### Simplification lemmas about operations -/ @[simp] theorem irrational_rat_add_iff : irrational (q + x) ↔ irrational x := ⟨of_rat_add q, rat_add q⟩ @[simp] theorem irrational_int_add_iff : irrational (m + x) ↔ irrational x := ⟨of_int_add m, λ h, h.int_add m⟩ @[simp] theorem irrational_nat_add_iff : irrational (n + x) ↔ irrational x := ⟨of_nat_add n, λ h, h.nat_add n⟩ @[simp] theorem irrational_add_rat_iff : irrational (x + q) ↔ irrational x := ⟨of_add_rat q, add_rat q⟩ @[simp] theorem irrational_add_int_iff : irrational (x + m) ↔ irrational x := ⟨of_add_int m, λ h, h.add_int m⟩ @[simp] theorem irrational_add_nat_iff : irrational (x + n) ↔ irrational x := ⟨of_add_nat n, λ h, h.add_nat n⟩ @[simp] theorem irrational_rat_sub_iff : irrational (q - x) ↔ irrational x := ⟨of_rat_sub q, rat_sub q⟩ @[simp] theorem irrational_int_sub_iff : irrational (m - x) ↔ irrational x := ⟨of_int_sub m, λ h, h.int_sub m⟩ @[simp] theorem irrational_nat_sub_iff : irrational (n - x) ↔ irrational x := ⟨of_nat_sub n, λ h, h.nat_sub n⟩ @[simp] theorem irrational_sub_rat_iff : irrational (x - q) ↔ irrational x := ⟨of_sub_rat q, sub_rat q⟩ @[simp] theorem irrational_sub_int_iff : irrational (x - m) ↔ irrational x := ⟨of_sub_int m, λ h, h.sub_int m⟩ @[simp] theorem irrational_sub_nat_iff : irrational (x - n) ↔ irrational x := ⟨of_sub_nat n, λ h, h.sub_nat n⟩ @[simp] theorem irrational_neg_iff : irrational (-x) ↔ irrational x := ⟨of_neg, irrational.neg⟩ @[simp] theorem irrational_inv_iff : irrational x⁻¹ ↔ irrational x := ⟨of_inv, irrational.inv⟩ @[simp] theorem irrational_rat_mul_iff : irrational (q * x) ↔ q ≠ 0 ∧ irrational x := ⟨λ h, ⟨rat.cast_ne_zero.1 $ left_ne_zero_of_mul h.ne_zero, h.of_rat_mul q⟩, λ h, h.2.rat_mul h.1⟩ @[simp] theorem irrational_mul_rat_iff : irrational (x * q) ↔ q ≠ 0 ∧ irrational x := by rw [mul_comm, irrational_rat_mul_iff] @[simp] theorem irrational_int_mul_iff : irrational (m * x) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_rat_mul_iff, int.cast_ne_zero] @[simp] theorem irrational_mul_int_iff : irrational (x * m) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_mul_rat_iff, int.cast_ne_zero] @[simp] theorem irrational_nat_mul_iff : irrational (n * x) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_rat_mul_iff, nat.cast_ne_zero] @[simp] theorem irrational_mul_nat_iff : irrational (x * n) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_mul_rat_iff, nat.cast_ne_zero] @[simp] theorem irrational_rat_div_iff : irrational (q / x) ↔ q ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_rat_iff : irrational (x / q) ↔ q ≠ 0 ∧ irrational x := by rw [div_eq_mul_inv, ← cast_inv, irrational_mul_rat_iff, ne.def, inv_eq_zero] @[simp] theorem irrational_int_div_iff : irrational (m / x) ↔ m ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_int_iff : irrational (x / m) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_div_rat_iff, int.cast_ne_zero] @[simp] theorem irrational_nat_div_iff : irrational (n / x) ↔ n ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_nat_iff : irrational (x / n) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_div_rat_iff, nat.cast_ne_zero] /-- There is an irrational number `r` between any two reals `x < r < y`. -/ theorem exists_irrational_btwn {x y : ℝ} (h : x < y) : ∃ r, irrational r ∧ x < r ∧ r < y := let ⟨q, ⟨hq1, hq2⟩⟩ := (exists_rat_btwn ((sub_lt_sub_iff_right (real.sqrt 2)).mpr h)) in ⟨q + real.sqrt 2, irrational_sqrt_two.rat_add _, sub_lt_iff_lt_add.mp hq1, lt_sub_iff_add_lt.mp hq2⟩ end
7bc03db2270b6935a7b842e4fc19f35e3c13b573
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/heqSubst.lean
ec9aff46895d0750c0190197d272847d91702f48
[ "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
83
lean
example (f : α → α) (a b : α) (h : HEq a b) : f a = f b := by subst h rfl
32ddcb0377a2ead447280ea458e591c9cc54c6e0
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/category_theory/subobject/factor_thru.lean
c5f450340f18c37195f13bc004078dc7a3487393
[ "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
7,183
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Scott Morrison -/ import category_theory.subobject.basic import category_theory.preadditive.basic /-! # Factoring through subobjects The predicate `h : P.factors f`, for `P : subobject Y` and `f : X ⟶ Y` asserts the existence of some `P.factor_thru f : X ⟶ (P : C)` making the obvious diagram commute. -/ universes v₁ v₂ u₁ u₂ noncomputable theory open category_theory category_theory.category category_theory.limits variables {C : Type u₁} [category.{v₁} C] {X Y Z : C} variables {D : Type u₂} [category.{v₂} D] namespace category_theory namespace mono_over /-- When `f : X ⟶ Y` and `P : mono_over Y`, `P.factors f` expresses that there exists a factorisation of `f` through `P`. Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`. -/ def factors {X Y : C} (P : mono_over Y) (f : X ⟶ Y) : Prop := ∃ g : X ⟶ (P : C), g ≫ P.arrow = f lemma factors_congr {X : C} {f g : mono_over X} {Y : C} (h : Y ⟶ X) (e : f ≅ g) : f.factors h ↔ g.factors h := ⟨λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.hom)).left, by simp [hu]⟩, λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.inv)).left, by simp [hu]⟩⟩ /-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : mono_over Y`, given the evidence `h : P.factors f` that such a factorisation exists. -/ def factor_thru {X Y : C} (P : mono_over Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ (P : C) := classical.some h end mono_over namespace subobject /-- When `f : X ⟶ Y` and `P : subobject Y`, `P.factors f` expresses that there exists a factorisation of `f` through `P`. Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`. -/ def factors {X Y : C} (P : subobject Y) (f : X ⟶ Y) : Prop := quotient.lift_on' P (λ P, P.factors f) begin rintros P Q ⟨h⟩, apply propext, split, { rintro ⟨i, w⟩, exact ⟨i ≫ h.hom.left, by erw [category.assoc, over.w h.hom, w]⟩, }, { rintro ⟨i, w⟩, exact ⟨i ≫ h.inv.left, by erw [category.assoc, over.w h.inv, w]⟩, }, end @[simp] lemma mk_factors_iff {X Y Z : C} (f : Y ⟶ X) [mono f] (g : Z ⟶ X) : (subobject.mk f).factors g ↔ (mono_over.mk' f).factors g := iff.rfl lemma mk_factors_self (f : X ⟶ Y) [mono f] : (mk f).factors f := ⟨𝟙 _, by simp⟩ lemma factors_iff {X Y : C} (P : subobject Y) (f : X ⟶ Y) : P.factors f ↔ (representative.obj P).factors f := quot.induction_on P $ λ a, mono_over.factors_congr _ (representative_iso _).symm lemma factors_self {X : C} (P : subobject X) : P.factors P.arrow := (factors_iff _ _).mpr ⟨𝟙 P, (by simp)⟩ lemma factors_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) : P.factors (f ≫ P.arrow) := (factors_iff _ _).mpr ⟨f, rfl⟩ lemma factors_of_factors_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) {g : Y ⟶ Z} (h : P.factors g) : P.factors (f ≫ g) := begin revert P, refine quotient.ind' _, intro P, rintro ⟨g, rfl⟩, exact ⟨f ≫ g, by simp⟩, end lemma factors_zero [has_zero_morphisms C] {X Y : C} {P : subobject Y} : P.factors (0 : X ⟶ Y) := (factors_iff _ _).mpr ⟨0, by simp⟩ lemma factors_of_le {Y Z : C} {P Q : subobject Y} (f : Z ⟶ Y) (h : P ≤ Q) : P.factors f → Q.factors f := by { simp only [factors_iff], exact λ ⟨u, hu⟩, ⟨u ≫ of_le _ _ h, by simp [←hu]⟩ } /-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : subobject Y`, given the evidence `h : P.factors f` that such a factorisation exists. -/ def factor_thru {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ P := classical.some ((factors_iff _ _).mp h) @[simp, reassoc] lemma factor_thru_arrow {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) : P.factor_thru f h ≫ P.arrow = f := classical.some_spec ((factors_iff _ _).mp h) @[simp] lemma factor_thru_self {X : C} (P : subobject X) (h) : P.factor_thru P.arrow h = 𝟙 P := by { ext, simp, } @[simp] lemma factor_thru_mk_self (f : X ⟶ Y) [mono f] : (mk f).factor_thru f (mk_factors_self f) = (underlying_iso f).inv := by { ext, simp, } @[simp] lemma factor_thru_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) (h) : P.factor_thru (f ≫ P.arrow) h = f := by { ext, simp, } @[simp] lemma factor_thru_eq_zero [has_zero_morphisms C] {X Y : C} {P : subobject Y} {f : X ⟶ Y} {h : factors P f} : P.factor_thru f h = 0 ↔ f = 0 := begin fsplit, { intro w, replace w := w =≫ P.arrow, simpa using w, }, { rintro rfl, ext, simp, }, end lemma factor_thru_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) (g : Y ⟶ Z) (h : P.factors g) : f ≫ P.factor_thru g h = P.factor_thru (f ≫ g) (factors_of_factors_right f h) := begin apply (cancel_mono P.arrow).mp, simp, end @[simp] lemma factor_thru_zero [has_zero_morphisms C] {X Y : C} {P : subobject Y} (h : P.factors (0 : X ⟶ Y)) : P.factor_thru 0 h = 0 := by simp -- `h` is an explicit argument here so we can use -- `rw factor_thru_le h`, obtaining a subgoal `P.factors f`. -- (While the reverse direction looks plausible as a simp lemma, it seems to be unproductive.) lemma factor_thru_of_le {Y Z : C} {P Q : subobject Y} {f : Z ⟶ Y} (h : P ≤ Q) (w : P.factors f) : Q.factor_thru f (factors_of_le f h w) = P.factor_thru f w ≫ of_le P Q h := by { ext, simp, } section preadditive variables [preadditive C] lemma factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (wf : P.factors f) (wg : P.factors g) : P.factors (f + g) := (factors_iff _ _).mpr ⟨P.factor_thru f wf + P.factor_thru g wg, by simp⟩ -- This can't be a `simp` lemma as `wf` and `wg` may not exist. -- However you can `rw` by it to assert that `f` and `g` factor through `P` separately. lemma factor_thru_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (w : P.factors (f + g)) (wf : P.factors f) (wg : P.factors g) : P.factor_thru (f + g) w = P.factor_thru f wf + P.factor_thru g wg := by { ext, simp, } lemma factors_left_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (w : P.factors (f + g)) (wg : P.factors g) : P.factors f := (factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru g wg, by simp⟩ @[simp] lemma factor_thru_add_sub_factor_thru_right {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (w : P.factors (f + g)) (wg : P.factors g) : P.factor_thru (f + g) w - P.factor_thru g wg = P.factor_thru f (factors_left_of_factors_add f g w wg) := by { ext, simp, } lemma factors_right_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (w : P.factors (f + g)) (wf : P.factors f) : P.factors g := (factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru f wf, by simp⟩ @[simp] lemma factor_thru_add_sub_factor_thru_left {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (w : P.factors (f + g)) (wf : P.factors f) : P.factor_thru (f + g) w - P.factor_thru f wf = P.factor_thru g (factors_right_of_factors_add f g w wf) := by { ext, simp, } end preadditive end subobject end category_theory
6d8c5e68d424857367c90bcb49b69832603b1bf0
053240c7b02e3f5c5b38443de4838535cf11269c
/.config.lean
3d8a04445242afe3b11fc2f4d2725f749539f652
[ "MIT" ]
permissive
MaxWithU/MT1300
f6604733be3c1ec54d57a122fed540940a426a7c
a3c046286d5f618c0e65ce139ece2f1099e0b517
refs/heads/main
1,690,433,774,646
1,631,364,172,000
1,631,364,172,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
266,817
lean
# 2021-08-19 ssr plus, passwall # Automatically generated file; DO NOT EDIT. # OpenWrt Configuration # CONFIG_MODULES=y CONFIG_HAVE_DOT_CONFIG=y # CONFIG_TARGET_sunxi is not set # CONFIG_TARGET_apm821xx is not set # CONFIG_TARGET_ath25 is not set # CONFIG_TARGET_ath79 is not set # CONFIG_TARGET_bcm27xx is not set # CONFIG_TARGET_bcm53xx is not set # CONFIG_TARGET_bcm47xx is not set # CONFIG_TARGET_bcm4908 is not set # CONFIG_TARGET_bcm63xx is not set # CONFIG_TARGET_bmips is not set # CONFIG_TARGET_octeon is not set # CONFIG_TARGET_gemini is not set # CONFIG_TARGET_mpc85xx is not set # CONFIG_TARGET_mxs is not set # CONFIG_TARGET_lantiq is not set # CONFIG_TARGET_malta is not set # CONFIG_TARGET_pistachio is not set # CONFIG_TARGET_mvebu is not set # CONFIG_TARGET_kirkwood is not set # CONFIG_TARGET_mediatek is not set CONFIG_TARGET_ramips=y # CONFIG_TARGET_at91 is not set # CONFIG_TARGET_tegra is not set # CONFIG_TARGET_layerscape is not set # CONFIG_TARGET_imx6 is not set # CONFIG_TARGET_octeontx is not set # CONFIG_TARGET_oxnas is not set # CONFIG_TARGET_armvirt is not set # CONFIG_TARGET_ipq40xx is not set # CONFIG_TARGET_ipq806x is not set # CONFIG_TARGET_ipq807x is not set # CONFIG_TARGET_realtek is not set # CONFIG_TARGET_rockchip is not set # CONFIG_TARGET_arc770 is not set # CONFIG_TARGET_archs38 is not set # CONFIG_TARGET_omap is not set # CONFIG_TARGET_uml is not set # CONFIG_TARGET_zynq is not set # CONFIG_TARGET_x86 is not set # CONFIG_TARGET_ramips_mt7620 is not set CONFIG_TARGET_ramips_mt7621=y # CONFIG_TARGET_ramips_mt76x8 is not set # CONFIG_TARGET_ramips_rt288x is not set # CONFIG_TARGET_ramips_rt305x is not set # CONFIG_TARGET_ramips_rt3883 is not set # CONFIG_TARGET_MULTI_PROFILE is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_adslr_g7 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_afoundry_ew1200 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_alfa-network_quad-e4g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ampedwireless_ally-r1900k is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ampedwireless_ally-00x19k is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-001 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-nv1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac57u is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac65p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac85p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-n56u-b1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-1166dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-2533dhpl is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-600dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_cudy_wr1300 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_cudy_wr2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-1960-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-2640-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-2660-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-853-a3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-853-r1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-860l-b1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-867-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-878-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-882-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-882-r1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_newifi-d2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_pbr-m1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_ra21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_re23s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_rg21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167ghbk2-s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167gs2-b is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167gst2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1750gs is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1750gst2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1750gsv is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1900gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533ghbk-i is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_firefly_firewrt is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gehua_ghl-r-001 is not set CONFIG_TARGET_ramips_mt7621_DEVICE_glinet_gl-mt1300=y # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_hiwifi_hc5962 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax2033gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-dx1167r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-dx1200gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-gx300gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wnpr2600g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a6ns-m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a8004t is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_jhr-ac876m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_q20 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_y2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_lenovo_newifi-d1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_e5600 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7300-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7300-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7500-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea8100-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea8100-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_re6500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_ap-mt7621a-v60 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_mt7621-eval-board is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-750gr3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-760igs is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m11g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m33g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mqmaker_witi is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mtc_wr1201 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_ex6150 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6220 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6260 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6350 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6700-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6800 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6850 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac104 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac124 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wndr3700-v5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netis_wf2881 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_phicomm_k2p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_planex_vr500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_samknows_whitebox-v8 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_sercomm_na502 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_storylink_sap-g3200u3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_telco-electronics_x1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tenbay_t-mb5eu-v01 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_thunder_timecloud is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_totolink_a7000r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_totolink_x5000r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_archer-a6-v3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_archer-c6-v3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_archer-c6u-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_eap235-wall-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re350-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re500-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re650-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x-sfp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_unifi-6-lite is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_unifi-nanohd is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-01-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-64m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wavlink_wl-wn531a6 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_11acnas is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_w2914ns-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_winstars_ws-wn583a6 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-3g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-3g-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-3-pro is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-4 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-4a-gigabit is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-cr660x is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_redmi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaoyu_xy-c5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xzwifi_creativebox-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youhua_wr1200js is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youku_yk-l2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we1326 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we3526 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg2626 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-32m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zio_freezio is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zyxel_nr7101 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zyxel_wap6805 is not set CONFIG_HAS_SUBTARGETS=y CONFIG_HAS_DEVICES=y CONFIG_TARGET_BOARD="ramips" CONFIG_TARGET_SUBTARGET="mt7621" CONFIG_TARGET_PROFILE="DEVICE_glinet_gl-mt1300" CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc" CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_CPU_TYPE="24kc" CONFIG_LINUX_5_4=y CONFIG_DEFAULT_base-files=y CONFIG_DEFAULT_block-mount=y CONFIG_DEFAULT_busybox=y CONFIG_DEFAULT_coremark=y CONFIG_DEFAULT_ddns-scripts_aliyun=y CONFIG_DEFAULT_ddns-scripts_dnspod=y CONFIG_DEFAULT_default-settings=y CONFIG_DEFAULT_dnsmasq-full=y CONFIG_DEFAULT_dropbear=y CONFIG_DEFAULT_firewall=y CONFIG_DEFAULT_fstools=y CONFIG_DEFAULT_iptables=y CONFIG_DEFAULT_iwinfo=y CONFIG_DEFAULT_kmod-crypto-hw-eip93=y CONFIG_DEFAULT_kmod-gpio-button-hotplug=y CONFIG_DEFAULT_kmod-ipt-raw=y CONFIG_DEFAULT_kmod-leds-gpio=y CONFIG_DEFAULT_kmod-mt7615d_dbdc=y CONFIG_DEFAULT_kmod-nf-nathelper=y CONFIG_DEFAULT_kmod-nf-nathelper-extra=y CONFIG_DEFAULT_kmod-usb3=y CONFIG_DEFAULT_libc=y CONFIG_DEFAULT_libgcc=y CONFIG_DEFAULT_libustream-openssl=y CONFIG_DEFAULT_logd=y CONFIG_DEFAULT_luci=y CONFIG_DEFAULT_luci-app-accesscontrol=y CONFIG_DEFAULT_luci-app-arpbind=y CONFIG_DEFAULT_luci-app-autoreboot=y CONFIG_DEFAULT_luci-app-ddns=y CONFIG_DEFAULT_luci-app-filetransfer=y CONFIG_DEFAULT_luci-app-nlbwmon=y CONFIG_DEFAULT_luci-app-ramfree=y CONFIG_DEFAULT_luci-app-ssr-plus=y CONFIG_DEFAULT_luci-app-turboacc=y CONFIG_DEFAULT_luci-app-unblockmusic=y CONFIG_DEFAULT_luci-app-upnp=y CONFIG_DEFAULT_luci-app-vlmcsd=y CONFIG_DEFAULT_luci-app-vsftpd=y CONFIG_DEFAULT_luci-app-wol=y CONFIG_DEFAULT_mtd=y CONFIG_DEFAULT_netifd=y CONFIG_DEFAULT_opkg=y CONFIG_DEFAULT_ppp=y CONFIG_DEFAULT_ppp-mod-pppoe=y CONFIG_DEFAULT_procd=y CONFIG_DEFAULT_swconfig=y CONFIG_DEFAULT_uci=y CONFIG_DEFAULT_uclient-fetch=y CONFIG_DEFAULT_urandom-seed=y CONFIG_HAS_TESTING_KERNEL=y CONFIG_AUDIO_SUPPORT=y CONFIG_GPIO_SUPPORT=y CONFIG_PCI_SUPPORT=y CONFIG_USB_SUPPORT=y CONFIG_RTC_SUPPORT=y CONFIG_USES_DEVICETREE=y CONFIG_USES_INITRAMFS=y CONFIG_USES_SQUASHFS=y CONFIG_USES_MINOR=y CONFIG_HAS_MIPS16=y CONFIG_NAND_SUPPORT=y CONFIG_mipsel=y CONFIG_ARCH="mipsel" # # Target Images # CONFIG_TARGET_ROOTFS_INITRAMFS=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2 is not set CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4 is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ is not set CONFIG_EXTERNAL_CPIO="" # CONFIG_TARGET_INITRAMFS_FORCE is not set # # Root filesystem archives # # CONFIG_TARGET_ROOTFS_CPIOGZ is not set # CONFIG_TARGET_ROOTFS_TARGZ is not set # # Root filesystem images # # CONFIG_TARGET_ROOTFS_EXT4FS is not set CONFIG_TARGET_ROOTFS_SQUASHFS=y CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=1024 CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP=y CONFIG_TARGET_UBIFS_JOURNAL_SIZE="" # # Image Options # # end of Target Images # CONFIG_EXPERIMENTAL is not set # # Global build settings # # CONFIG_JSON_OVERVIEW_IMAGE_INFO is not set # CONFIG_ALL_NONSHARED is not set # CONFIG_ALL_KMODS is not set # CONFIG_ALL is not set # CONFIG_BUILDBOT is not set CONFIG_SIGNED_PACKAGES=y CONFIG_SIGNATURE_CHECK=y # # General build options # # CONFIG_TESTING_KERNEL is not set # CONFIG_DISPLAY_SUPPORT is not set # CONFIG_BUILD_PATENTED is not set # CONFIG_BUILD_NLS is not set CONFIG_SHADOW_PASSWORDS=y # CONFIG_CLEAN_IPKG is not set # CONFIG_IPK_FILES_CHECKSUMS is not set # CONFIG_INCLUDE_CONFIG is not set # CONFIG_REPRODUCIBLE_DEBUG_INFO is not set # CONFIG_COLLECT_KERNEL_DEBUG is not set # # Kernel build options # CONFIG_KERNEL_BUILD_USER="" CONFIG_KERNEL_BUILD_DOMAIN="" CONFIG_KERNEL_PRINTK=y CONFIG_KERNEL_CRASHLOG=y CONFIG_KERNEL_SWAP=y # CONFIG_KERNEL_PROC_STRIPPED is not set CONFIG_KERNEL_DEBUG_FS=y CONFIG_KERNEL_MIPS_FP_SUPPORT=y # CONFIG_KERNEL_PERF_EVENTS is not set # CONFIG_KERNEL_PROFILING is not set # CONFIG_KERNEL_UBSAN is not set # CONFIG_KERNEL_KCOV is not set # CONFIG_KERNEL_TASKSTATS is not set CONFIG_KERNEL_KALLSYMS=y # CONFIG_KERNEL_FTRACE is not set CONFIG_KERNEL_DEBUG_KERNEL=y CONFIG_KERNEL_DEBUG_INFO=y # CONFIG_KERNEL_DYNAMIC_DEBUG is not set # CONFIG_KERNEL_KPROBES is not set CONFIG_KERNEL_AIO=y CONFIG_KERNEL_IO_URING=y CONFIG_KERNEL_FHANDLE=y CONFIG_KERNEL_FANOTIFY=y # CONFIG_KERNEL_BLK_DEV_BSG is not set # CONFIG_KERNEL_HUGETLB_PAGE is not set CONFIG_KERNEL_MAGIC_SYSRQ=y # CONFIG_KERNEL_DEBUG_PINCTRL is not set # CONFIG_KERNEL_DEBUG_GPIO is not set CONFIG_KERNEL_COREDUMP=y CONFIG_KERNEL_ELF_CORE=y # CONFIG_KERNEL_PROVE_LOCKING is not set # CONFIG_KERNEL_LOCKUP_DETECTOR is not set # CONFIG_KERNEL_DETECT_HUNG_TASK is not set # CONFIG_KERNEL_WQ_WATCHDOG is not set # CONFIG_KERNEL_DEBUG_ATOMIC_SLEEP is not set # CONFIG_KERNEL_DEBUG_VM is not set CONFIG_KERNEL_PRINTK_TIME=y # CONFIG_KERNEL_SLABINFO is not set # CONFIG_KERNEL_PROC_PAGE_MONITOR is not set # CONFIG_KERNEL_KEXEC is not set # CONFIG_USE_RFKILL is not set # CONFIG_USE_SPARSE is not set # CONFIG_KERNEL_DEVTMPFS is not set CONFIG_KERNEL_KEYS=y # CONFIG_KERNEL_PERSISTENT_KEYRINGS is not set # CONFIG_KERNEL_KEYS_REQUEST_CACHE is not set # CONFIG_KERNEL_BIG_KEYS is not set CONFIG_KERNEL_CGROUPS=y # CONFIG_KERNEL_CGROUP_DEBUG is not set CONFIG_KERNEL_FREEZER=y # CONFIG_KERNEL_CGROUP_FREEZER is not set # CONFIG_KERNEL_CGROUP_DEVICE is not set # CONFIG_KERNEL_CGROUP_HUGETLB is not set CONFIG_KERNEL_CGROUP_PIDS=y CONFIG_KERNEL_CGROUP_RDMA=y CONFIG_KERNEL_CGROUP_BPF=y CONFIG_KERNEL_CPUSETS=y # CONFIG_KERNEL_PROC_PID_CPUSET is not set CONFIG_KERNEL_CGROUP_CPUACCT=y CONFIG_KERNEL_RESOURCE_COUNTERS=y CONFIG_KERNEL_MM_OWNER=y CONFIG_KERNEL_MEMCG=y CONFIG_KERNEL_MEMCG_SWAP=y # CONFIG_KERNEL_MEMCG_SWAP_ENABLED is not set CONFIG_KERNEL_MEMCG_KMEM=y # CONFIG_KERNEL_CGROUP_PERF is not set CONFIG_KERNEL_CGROUP_SCHED=y CONFIG_KERNEL_FAIR_GROUP_SCHED=y CONFIG_KERNEL_CFS_BANDWIDTH=y CONFIG_KERNEL_RT_GROUP_SCHED=y CONFIG_KERNEL_BLK_CGROUP=y # CONFIG_KERNEL_CFQ_GROUP_IOSCHED is not set CONFIG_KERNEL_BLK_DEV_THROTTLING=y # CONFIG_KERNEL_BLK_DEV_THROTTLING_LOW is not set # CONFIG_KERNEL_DEBUG_BLK_CGROUP is not set # CONFIG_KERNEL_NET_CLS_CGROUP is not set # CONFIG_KERNEL_CGROUP_NET_CLASSID is not set # CONFIG_KERNEL_CGROUP_NET_PRIO is not set CONFIG_KERNEL_NAMESPACES=y CONFIG_KERNEL_UTS_NS=y CONFIG_KERNEL_IPC_NS=y CONFIG_KERNEL_USER_NS=y CONFIG_KERNEL_PID_NS=y CONFIG_KERNEL_NET_NS=y CONFIG_KERNEL_DEVPTS_MULTIPLE_INSTANCES=y CONFIG_KERNEL_POSIX_MQUEUE=y CONFIG_KERNEL_SECCOMP_FILTER=y CONFIG_KERNEL_SECCOMP=y CONFIG_KERNEL_IP_MROUTE=y CONFIG_KERNEL_IPV6=y CONFIG_KERNEL_IPV6_MULTIPLE_TABLES=y CONFIG_KERNEL_IPV6_SUBTREES=y CONFIG_KERNEL_IPV6_MROUTE=y # CONFIG_KERNEL_IPV6_PIMSM_V2 is not set CONFIG_KERNEL_IPV6_SEG6_LWTUNNEL=y # CONFIG_KERNEL_LWTUNNEL_BPF is not set # CONFIG_KERNEL_IP_PNP is not set # # Filesystem ACL and attr support options # # CONFIG_USE_FS_ACL_ATTR is not set # CONFIG_KERNEL_FS_POSIX_ACL is not set # CONFIG_KERNEL_BTRFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_EXT4_FS_POSIX_ACL is not set # CONFIG_KERNEL_F2FS_FS_POSIX_ACL is not set # CONFIG_KERNEL_JFFS2_FS_POSIX_ACL is not set # CONFIG_KERNEL_TMPFS_POSIX_ACL is not set # CONFIG_KERNEL_CIFS_ACL is not set # CONFIG_KERNEL_HFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_HFSPLUS_FS_POSIX_ACL is not set # CONFIG_KERNEL_NFS_ACL_SUPPORT is not set # CONFIG_KERNEL_NFS_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V2_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_REISER_FS_POSIX_ACL is not set # CONFIG_KERNEL_XFS_POSIX_ACL is not set # CONFIG_KERNEL_JFS_POSIX_ACL is not set # end of Filesystem ACL and attr support options # CONFIG_KERNEL_DEVMEM is not set # CONFIG_KERNEL_DEVKMEM is not set CONFIG_KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE=3 # CONFIG_KERNEL_SQUASHFS_XATTR is not set CONFIG_KERNEL_CC_OPTIMIZE_FOR_PERFORMANCE=y # CONFIG_KERNEL_CC_OPTIMIZE_FOR_SIZE is not set # CONFIG_KERNEL_AUDIT is not set # CONFIG_KERNEL_SECURITY is not set # CONFIG_KERNEL_SECURITY_NETWORK is not set # CONFIG_KERNEL_SECURITY_SELINUX is not set # CONFIG_KERNEL_EXT4_FS_SECURITY is not set # CONFIG_KERNEL_F2FS_FS_SECURITY is not set # CONFIG_KERNEL_UBIFS_FS_SECURITY is not set # CONFIG_KERNEL_JFFS2_FS_SECURITY is not set # end of Kernel build options # # Package build options # # CONFIG_DEBUG is not set CONFIG_IPV6=y # # Stripping options # # CONFIG_NO_STRIP is not set # CONFIG_USE_STRIP is not set CONFIG_USE_SSTRIP=y CONFIG_SSTRIP_ARGS="-z" # CONFIG_STRIP_KERNEL_EXPORTS is not set # CONFIG_USE_MKLIBS is not set CONFIG_USE_UCLIBCXX=y # CONFIG_USE_LIBSTDCXX is not set # # Hardening build options # CONFIG_PKG_CHECK_FORMAT_SECURITY=y # CONFIG_PKG_ASLR_PIE_NONE is not set CONFIG_PKG_ASLR_PIE_REGULAR=y # CONFIG_PKG_ASLR_PIE_ALL is not set # CONFIG_PKG_CC_STACKPROTECTOR_NONE is not set CONFIG_PKG_CC_STACKPROTECTOR_REGULAR=y # CONFIG_PKG_CC_STACKPROTECTOR_STRONG is not set # CONFIG_KERNEL_CC_STACKPROTECTOR_NONE is not set CONFIG_KERNEL_CC_STACKPROTECTOR_REGULAR=y # CONFIG_KERNEL_CC_STACKPROTECTOR_STRONG is not set CONFIG_KERNEL_STACKPROTECTOR=y # CONFIG_KERNEL_STACKPROTECTOR_STRONG is not set # CONFIG_PKG_FORTIFY_SOURCE_NONE is not set CONFIG_PKG_FORTIFY_SOURCE_1=y # CONFIG_PKG_FORTIFY_SOURCE_2 is not set # CONFIG_PKG_RELRO_NONE is not set # CONFIG_PKG_RELRO_PARTIAL is not set CONFIG_PKG_RELRO_FULL=y # CONFIG_SELINUX is not set # end of Global build settings # CONFIG_DEVEL is not set # CONFIG_BROKEN is not set CONFIG_BINARY_FOLDER="" CONFIG_DOWNLOAD_FOLDER="" CONFIG_LOCALMIRROR="" CONFIG_AUTOREBUILD=y # CONFIG_AUTOREMOVE is not set CONFIG_BUILD_SUFFIX="" CONFIG_TARGET_ROOTFS_DIR="" # CONFIG_CCACHE is not set CONFIG_CCACHE_DIR="" CONFIG_EXTERNAL_KERNEL_TREE="" CONFIG_KERNEL_GIT_CLONE_URI="" CONFIG_BUILD_LOG_DIR="" CONFIG_EXTRA_OPTIMIZATION="-fno-caller-saves -fno-plt" CONFIG_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_SOFT_FLOAT=y CONFIG_USE_MIPS16=y # CONFIG_EXTRA_TARGET_ARCH is not set CONFIG_EXTRA_BINUTILS_CONFIG_OPTIONS="" CONFIG_EXTRA_GCC_CONFIG_OPTIONS="" # CONFIG_GCC_DEFAULT_PIE is not set # CONFIG_GCC_DEFAULT_SSP is not set # CONFIG_SJLJ_EXCEPTIONS is not set # CONFIG_INSTALL_GFORTRAN is not set CONFIG_GDB=y # CONFIG_GDB_PYTHON is not set CONFIG_USE_MUSL=y CONFIG_SSP_SUPPORT=y CONFIG_BINUTILS_VERSION_2_34=y CONFIG_BINUTILS_VERSION="2.34" CONFIG_GCC_VERSION="8.4.0" # CONFIG_GCC_USE_IREMAP is not set CONFIG_LIBC="musl" CONFIG_TARGET_SUFFIX="musl" # CONFIG_IB is not set # CONFIG_SDK is not set # CONFIG_MAKE_TOOLCHAIN is not set # CONFIG_IMAGEOPT is not set # CONFIG_PREINITOPT is not set CONFIG_TARGET_PREINIT_SUPPRESS_STDERR=y # CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE is not set CONFIG_TARGET_PREINIT_TIMEOUT=2 # CONFIG_TARGET_PREINIT_SHOW_NETMSG is not set # CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG is not set CONFIG_TARGET_PREINIT_IFNAME="" CONFIG_TARGET_PREINIT_IP="192.168.1.1" CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0" CONFIG_TARGET_PREINIT_BROADCAST="192.168.1.255" # CONFIG_INITOPT is not set CONFIG_TARGET_INIT_PATH="/usr/sbin:/usr/bin:/sbin:/bin" CONFIG_TARGET_INIT_ENV="" CONFIG_TARGET_INIT_CMD="/sbin/init" CONFIG_TARGET_INIT_SUPPRESS_STDERR=y # CONFIG_VERSIONOPT is not set CONFIG_PER_FEED_REPO=y CONFIG_FEED_packages=y CONFIG_FEED_luci=y CONFIG_FEED_routing=y CONFIG_FEED_telephony=y # # Base system # # CONFIG_PACKAGE_attendedsysupgrade-common is not set # CONFIG_PACKAGE_auc is not set CONFIG_PACKAGE_base-files=y CONFIG_PACKAGE_block-mount=y # CONFIG_PACKAGE_blockd is not set # CONFIG_PACKAGE_bridge is not set CONFIG_PACKAGE_busybox=y # CONFIG_BUSYBOX_CUSTOM is not set CONFIG_BUSYBOX_DEFAULT_HAVE_DOT_CONFIG=y # CONFIG_BUSYBOX_DEFAULT_DESKTOP is not set # CONFIG_BUSYBOX_DEFAULT_EXTRA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_FEDORA_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_INCLUDE_SUSv2=y CONFIG_BUSYBOX_DEFAULT_LONG_OPTS=y CONFIG_BUSYBOX_DEFAULT_SHOW_USAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_USAGE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_USAGE is not set CONFIG_BUSYBOX_DEFAULT_LFS=y # CONFIG_BUSYBOX_DEFAULT_PAM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVPTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UTMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WTMP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDFILE=y CONFIG_BUSYBOX_DEFAULT_PID_FILE_PATH="/var/run" # CONFIG_BUSYBOX_DEFAULT_BUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALLER is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_NO_USR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG_QUIET is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_APPLETS=y CONFIG_BUSYBOX_DEFAULT_BUSYBOX_EXEC_PATH="/proc/self/exe" # CONFIG_BUSYBOX_DEFAULT_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CLEAN_UP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG_INFO is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG=y # CONFIG_BUSYBOX_DEFAULT_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_PIE is not set # CONFIG_BUSYBOX_DEFAULT_NOMMU is not set # CONFIG_BUSYBOX_DEFAULT_BUILD_LIBBUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LIBBUSYBOX_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INDIVIDUAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHARED_BUSYBOX is not set CONFIG_BUSYBOX_DEFAULT_CROSS_COMPILER_PREFIX="" CONFIG_BUSYBOX_DEFAULT_SYSROOT="" CONFIG_BUSYBOX_DEFAULT_EXTRA_CFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDLIBS="" # CONFIG_BUSYBOX_DEFAULT_USE_PORTABLE_CODE is not set # CONFIG_BUSYBOX_DEFAULT_STACK_OPTIMIZATION_386 is not set # CONFIG_BUSYBOX_DEFAULT_STATIC_LIBGCC is not set CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SYMLINKS=y # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_HARDLINKS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SCRIPT_WRAPPERS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_DONT is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SYMLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_HARDLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set CONFIG_BUSYBOX_DEFAULT_PREFIX="./_install" # CONFIG_BUSYBOX_DEFAULT_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_PESSIMIZE is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_SANITIZE is not set # CONFIG_BUSYBOX_DEFAULT_UNIT_TEST is not set # CONFIG_BUSYBOX_DEFAULT_WERROR is not set # CONFIG_BUSYBOX_DEFAULT_WARN_SIMPLE_MSG is not set CONFIG_BUSYBOX_DEFAULT_NO_DEBUG_LIB=y # CONFIG_BUSYBOX_DEFAULT_DMALLOC is not set # CONFIG_BUSYBOX_DEFAULT_EFENCE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_BSS_TAIL is not set # CONFIG_BUSYBOX_DEFAULT_FLOAT_DURATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_USE_MALLOC is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_ON_STACK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_IN_BSS is not set CONFIG_BUSYBOX_DEFAULT_PASSWORD_MINLEN=6 CONFIG_BUSYBOX_DEFAULT_MD5_SMALL=1 CONFIG_BUSYBOX_DEFAULT_SHA3_SMALL=1 CONFIG_BUSYBOX_DEFAULT_FEATURE_FAST_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_NETWORKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_SERVICES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING=y CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_MAX_LEN=512 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_VI is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_HISTORY=256 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVE_ON_EXIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REVERSE_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAB_COMPLETION=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_USERNAME_COMPLETION is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_FANCY_PROMPT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_LOCALE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_USING_LOCALE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_UNICODE_IN_ENV is not set CONFIG_BUSYBOX_DEFAULT_SUBST_WCHAR=0 CONFIG_BUSYBOX_DEFAULT_LAST_SUPPORTED_WCHAR=0 # CONFIG_BUSYBOX_DEFAULT_UNICODE_COMBINING_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_WIDE_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_BIDI_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_NEUTRAL_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_PRESERVE_BROKEN is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_NON_POSIX_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_CP_MESSAGE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_SENDFILE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_COPYBUF_KB=4 # CONFIG_BUSYBOX_DEFAULT_FEATURE_SKIP_ROOTFS is not set CONFIG_BUSYBOX_DEFAULT_MONOTONIC_SYSCALL=y CONFIG_BUSYBOX_DEFAULT_IOCTL_HEX2STR_ERROR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWIB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_BZ2 is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_GZ=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_Z is not set # CONFIG_BUSYBOX_DEFAULT_AR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_LONG_FILENAMES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_UNCOMPRESS is not set CONFIG_BUSYBOX_DEFAULT_GUNZIP=y CONFIG_BUSYBOX_DEFAULT_ZCAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GUNZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_BUNZIP2=y CONFIG_BUSYBOX_DEFAULT_BZCAT=y # CONFIG_BUSYBOX_DEFAULT_UNLZMA is not set # CONFIG_BUSYBOX_DEFAULT_LZCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_UNXZ is not set # CONFIG_BUSYBOX_DEFAULT_XZCAT is not set # CONFIG_BUSYBOX_DEFAULT_XZ is not set # CONFIG_BUSYBOX_DEFAULT_BZIP2 is not set CONFIG_BUSYBOX_DEFAULT_BZIP2_SMALL=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BZIP2_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_CPIO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_O is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_P is not set # CONFIG_BUSYBOX_DEFAULT_DPKG is not set # CONFIG_BUSYBOX_DEFAULT_DPKG_DEB is not set CONFIG_BUSYBOX_DEFAULT_GZIP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_GZIP_FAST=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LEVELS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_LZOP is not set # CONFIG_BUSYBOX_DEFAULT_UNLZOP is not set # CONFIG_BUSYBOX_DEFAULT_LZOPCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZOP_COMPR_HIGH is not set # CONFIG_BUSYBOX_DEFAULT_RPM is not set # CONFIG_BUSYBOX_DEFAULT_RPM2CPIO is not set CONFIG_BUSYBOX_DEFAULT_TAR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_CREATE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_AUTODETECT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_FROM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_GNU_EXTENSIONS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_TO_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_UNAME_GNAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_NOPRESERVE_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_UNZIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_CDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_BZIP2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LZMA_FAST is not set CONFIG_BUSYBOX_DEFAULT_BASENAME=y CONFIG_BUSYBOX_DEFAULT_CAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATV is not set CONFIG_BUSYBOX_DEFAULT_CHGRP=y CONFIG_BUSYBOX_DEFAULT_CHMOD=y CONFIG_BUSYBOX_DEFAULT_CHOWN=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHOWN_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_CHROOT=y # CONFIG_BUSYBOX_DEFAULT_CKSUM is not set # CONFIG_BUSYBOX_DEFAULT_COMM is not set CONFIG_BUSYBOX_DEFAULT_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_REFLINK is not set CONFIG_BUSYBOX_DEFAULT_CUT=y CONFIG_BUSYBOX_DEFAULT_DATE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_ISOFMT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_NANO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_DD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_SIGNAL_HANDLING=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_THIRD_STATUS_LINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_IBS_OBS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_STATUS is not set CONFIG_BUSYBOX_DEFAULT_DF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DF_FANCY is not set CONFIG_BUSYBOX_DEFAULT_DIRNAME=y # CONFIG_BUSYBOX_DEFAULT_DOS2UNIX is not set # CONFIG_BUSYBOX_DEFAULT_UNIX2DOS is not set CONFIG_BUSYBOX_DEFAULT_DU=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y CONFIG_BUSYBOX_DEFAULT_ECHO=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_ECHO=y CONFIG_BUSYBOX_DEFAULT_ENV=y # CONFIG_BUSYBOX_DEFAULT_EXPAND is not set # CONFIG_BUSYBOX_DEFAULT_UNEXPAND is not set CONFIG_BUSYBOX_DEFAULT_EXPR=y CONFIG_BUSYBOX_DEFAULT_EXPR_MATH_SUPPORT_64=y # CONFIG_BUSYBOX_DEFAULT_FACTOR is not set CONFIG_BUSYBOX_DEFAULT_FALSE=y # CONFIG_BUSYBOX_DEFAULT_FOLD is not set CONFIG_BUSYBOX_DEFAULT_HEAD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_HEAD=y # CONFIG_BUSYBOX_DEFAULT_HOSTID is not set CONFIG_BUSYBOX_DEFAULT_ID=y # CONFIG_BUSYBOX_DEFAULT_GROUPS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALL_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_LINK is not set CONFIG_BUSYBOX_DEFAULT_LN=y # CONFIG_BUSYBOX_DEFAULT_LOGNAME is not set CONFIG_BUSYBOX_DEFAULT_LS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FILETYPES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FOLLOWLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_RECURSIVE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_WIDTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_SORTFILES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_TIMESTAMPS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_USERNAME=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR_IS_DEFAULT=y CONFIG_BUSYBOX_DEFAULT_MD5SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA1SUM is not set CONFIG_BUSYBOX_DEFAULT_SHA256SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA512SUM is not set # CONFIG_BUSYBOX_DEFAULT_SHA3SUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MD5_SHA1_SUM_CHECK=y CONFIG_BUSYBOX_DEFAULT_MKDIR=y CONFIG_BUSYBOX_DEFAULT_MKFIFO=y CONFIG_BUSYBOX_DEFAULT_MKNOD=y CONFIG_BUSYBOX_DEFAULT_MKTEMP=y CONFIG_BUSYBOX_DEFAULT_MV=y CONFIG_BUSYBOX_DEFAULT_NICE=y # CONFIG_BUSYBOX_DEFAULT_NL is not set # CONFIG_BUSYBOX_DEFAULT_NOHUP is not set # CONFIG_BUSYBOX_DEFAULT_NPROC is not set # CONFIG_BUSYBOX_DEFAULT_OD is not set # CONFIG_BUSYBOX_DEFAULT_PASTE is not set # CONFIG_BUSYBOX_DEFAULT_PRINTENV is not set CONFIG_BUSYBOX_DEFAULT_PRINTF=y CONFIG_BUSYBOX_DEFAULT_PWD=y CONFIG_BUSYBOX_DEFAULT_READLINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_READLINK_FOLLOW=y # CONFIG_BUSYBOX_DEFAULT_REALPATH is not set CONFIG_BUSYBOX_DEFAULT_RM=y CONFIG_BUSYBOX_DEFAULT_RMDIR=y CONFIG_BUSYBOX_DEFAULT_SEQ=y # CONFIG_BUSYBOX_DEFAULT_SHRED is not set # CONFIG_BUSYBOX_DEFAULT_SHUF is not set CONFIG_BUSYBOX_DEFAULT_SLEEP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_SLEEP=y CONFIG_BUSYBOX_DEFAULT_SORT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_OPTIMIZE_MEMORY is not set # CONFIG_BUSYBOX_DEFAULT_SPLIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SPLIT_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_STAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FILESYSTEM is not set # CONFIG_BUSYBOX_DEFAULT_STTY is not set # CONFIG_BUSYBOX_DEFAULT_SUM is not set CONFIG_BUSYBOX_DEFAULT_SYNC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYNC_FANCY is not set CONFIG_BUSYBOX_DEFAULT_FSYNC=y # CONFIG_BUSYBOX_DEFAULT_TAC is not set CONFIG_BUSYBOX_DEFAULT_TAIL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_TAIL=y CONFIG_BUSYBOX_DEFAULT_TEE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEE_USE_BLOCK_IO=y CONFIG_BUSYBOX_DEFAULT_TEST=y CONFIG_BUSYBOX_DEFAULT_TEST1=y CONFIG_BUSYBOX_DEFAULT_TEST2=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEST_64=y # CONFIG_BUSYBOX_DEFAULT_TIMEOUT is not set CONFIG_BUSYBOX_DEFAULT_TOUCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_NODEREF is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_SUSV3=y CONFIG_BUSYBOX_DEFAULT_TR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_CLASSES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_EQUIV is not set CONFIG_BUSYBOX_DEFAULT_TRUE=y # CONFIG_BUSYBOX_DEFAULT_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_TTY is not set CONFIG_BUSYBOX_DEFAULT_UNAME=y CONFIG_BUSYBOX_DEFAULT_UNAME_OSNAME="GNU/Linux" # CONFIG_BUSYBOX_DEFAULT_BB_ARCH is not set CONFIG_BUSYBOX_DEFAULT_UNIQ=y # CONFIG_BUSYBOX_DEFAULT_UNLINK is not set # CONFIG_BUSYBOX_DEFAULT_USLEEP is not set # CONFIG_BUSYBOX_DEFAULT_UUDECODE is not set # CONFIG_BUSYBOX_DEFAULT_BASE32 is not set # CONFIG_BUSYBOX_DEFAULT_BASE64 is not set # CONFIG_BUSYBOX_DEFAULT_UUENCODE is not set CONFIG_BUSYBOX_DEFAULT_WC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WC_LARGE is not set # CONFIG_BUSYBOX_DEFAULT_WHO is not set # CONFIG_BUSYBOX_DEFAULT_W is not set # CONFIG_BUSYBOX_DEFAULT_USERS is not set # CONFIG_BUSYBOX_DEFAULT_WHOAMI is not set CONFIG_BUSYBOX_DEFAULT_YES=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PRESERVE_HARDLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_HUMAN_READABLE=y # CONFIG_BUSYBOX_DEFAULT_CHVT is not set CONFIG_BUSYBOX_DEFAULT_CLEAR=y # CONFIG_BUSYBOX_DEFAULT_DEALLOCVT is not set # CONFIG_BUSYBOX_DEFAULT_DUMPKMAP is not set # CONFIG_BUSYBOX_DEFAULT_FGCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_KBD_MODE is not set # CONFIG_BUSYBOX_DEFAULT_LOADFONT is not set # CONFIG_BUSYBOX_DEFAULT_SETFONT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFONT_TEXTUAL_MAP is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_SETFONT_DIR="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_PSF2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_RAW is not set # CONFIG_BUSYBOX_DEFAULT_LOADKMAP is not set # CONFIG_BUSYBOX_DEFAULT_OPENVT is not set CONFIG_BUSYBOX_DEFAULT_RESET=y # CONFIG_BUSYBOX_DEFAULT_RESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RESIZE_PRINT is not set # CONFIG_BUSYBOX_DEFAULT_SETCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETCONSOLE_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_SETKEYCODES is not set # CONFIG_BUSYBOX_DEFAULT_SETLOGCONS is not set # CONFIG_BUSYBOX_DEFAULT_SHOWKEY is not set # CONFIG_BUSYBOX_DEFAULT_PIPE_PROGRESS is not set # CONFIG_BUSYBOX_DEFAULT_RUN_PARTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_FANCY is not set CONFIG_BUSYBOX_DEFAULT_START_STOP_DAEMON=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_FANCY is not set CONFIG_BUSYBOX_DEFAULT_WHICH=y # CONFIG_BUSYBOX_DEFAULT_MINIPS is not set # CONFIG_BUSYBOX_DEFAULT_NUKE is not set # CONFIG_BUSYBOX_DEFAULT_RESUME is not set # CONFIG_BUSYBOX_DEFAULT_RUN_INIT is not set CONFIG_BUSYBOX_DEFAULT_AWK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_LIBM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_GNU_EXTENSIONS=y CONFIG_BUSYBOX_DEFAULT_CMP=y # CONFIG_BUSYBOX_DEFAULT_DIFF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_DIR is not set # CONFIG_BUSYBOX_DEFAULT_ED is not set # CONFIG_BUSYBOX_DEFAULT_PATCH is not set CONFIG_BUSYBOX_DEFAULT_SED=y CONFIG_BUSYBOX_DEFAULT_VI=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_MAX_LEN=1024 # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_8BIT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_COLON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_YANKMARK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SEARCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_REGEX_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_USE_SIGNALS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_DOT_CMD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_READONLY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SETOPTS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SET=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_WIN_RESIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_ASK_TERMINAL=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE_MAX=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_ALLOW_EXEC=y CONFIG_BUSYBOX_DEFAULT_FIND=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRINT0=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MTIME=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MMIN=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PERM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_TYPE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXECUTABLE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_XDEV=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MAXDEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NEWER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_INUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC_PLUS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_USER=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_GROUP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NOT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PAREN=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_SIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRUNE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_QUIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DELETE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EMPTY is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_REGEX=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_CONTEXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_LINKS is not set CONFIG_BUSYBOX_DEFAULT_GREP=y CONFIG_BUSYBOX_DEFAULT_EGREP=y CONFIG_BUSYBOX_DEFAULT_FGREP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_GREP_CONTEXT=y CONFIG_BUSYBOX_DEFAULT_XARGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_CONFIRMATION=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_QUOTES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_TERMOPT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ZERO_TERM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_REPL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_PARALLEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ARGS_FILE is not set # CONFIG_BUSYBOX_DEFAULT_BOOTCHARTD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_CONFIG_FILE is not set CONFIG_BUSYBOX_DEFAULT_HALT=y CONFIG_BUSYBOX_DEFAULT_POWEROFF=y CONFIG_BUSYBOX_DEFAULT_REBOOT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WAIT_FOR_INIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CALL_TELINIT is not set CONFIG_BUSYBOX_DEFAULT_TELINIT_PATH="" # CONFIG_BUSYBOX_DEFAULT_INIT is not set # CONFIG_BUSYBOX_DEFAULT_LINUXRC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_INITTAB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_REMOVED is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_DELAY=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SCTTY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_COREDUMPS is not set CONFIG_BUSYBOX_DEFAULT_INIT_TERMINAL_TYPE="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_MODIFY_CMDLINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SHADOWPASSWDS=y # CONFIG_BUSYBOX_DEFAULT_USE_BB_PWD_GRP is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_SHADOW is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT_SHA is not set # CONFIG_BUSYBOX_DEFAULT_ADD_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_REMOVE_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_ADDGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ADDUSER_TO_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_ADDUSER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_NAMES is not set CONFIG_BUSYBOX_DEFAULT_LAST_ID=0 CONFIG_BUSYBOX_DEFAULT_FIRST_SYSTEM_ID=0 CONFIG_BUSYBOX_DEFAULT_LAST_SYSTEM_ID=0 # CONFIG_BUSYBOX_DEFAULT_CHPASSWD is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEFAULT_PASSWD_ALGO="md5" # CONFIG_BUSYBOX_DEFAULT_CRYPTPW is not set # CONFIG_BUSYBOX_DEFAULT_MKPASSWD is not set # CONFIG_BUSYBOX_DEFAULT_DELUSER is not set # CONFIG_BUSYBOX_DEFAULT_DELGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEL_USER_FROM_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_GETTY is not set CONFIG_BUSYBOX_DEFAULT_LOGIN=y CONFIG_BUSYBOX_DEFAULT_LOGIN_SESSION_AS_CHILD=y # CONFIG_BUSYBOX_DEFAULT_LOGIN_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SECURETTY is not set CONFIG_BUSYBOX_DEFAULT_PASSWD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PASSWD_WEAK_CHECK=y # CONFIG_BUSYBOX_DEFAULT_SU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_CHECKS_SHELLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set # CONFIG_BUSYBOX_DEFAULT_SULOGIN is not set # CONFIG_BUSYBOX_DEFAULT_VLOCK is not set # CONFIG_BUSYBOX_DEFAULT_CHATTR is not set # CONFIG_BUSYBOX_DEFAULT_FSCK is not set # CONFIG_BUSYBOX_DEFAULT_LSATTR is not set # CONFIG_BUSYBOX_DEFAULT_TUNE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE_SMALL is not set # CONFIG_BUSYBOX_DEFAULT_DEPMOD is not set # CONFIG_BUSYBOX_DEFAULT_INSMOD is not set # CONFIG_BUSYBOX_DEFAULT_LSMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set # CONFIG_BUSYBOX_DEFAULT_MODINFO is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_BLACKLIST is not set # CONFIG_BUSYBOX_DEFAULT_RMMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CMDLINE_MODULE_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_2_4_MODULES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_VERSION_CHECKING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOADINKMEM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP_FULL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_TAINTED_MODULE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_TRY_MMAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_ALIAS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_SYMBOLS is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_MODULES_DIR="" CONFIG_BUSYBOX_DEFAULT_DEFAULT_DEPMOD_FILE="" # CONFIG_BUSYBOX_DEFAULT_ACPID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ACPID_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_BLKDISCARD is not set # CONFIG_BUSYBOX_DEFAULT_BLKID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BLKID_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_BLOCKDEV is not set # CONFIG_BUSYBOX_DEFAULT_CAL is not set # CONFIG_BUSYBOX_DEFAULT_CHRT is not set CONFIG_BUSYBOX_DEFAULT_DMESG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DMESG_PRETTY=y # CONFIG_BUSYBOX_DEFAULT_EJECT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EJECT_SCSI is not set # CONFIG_BUSYBOX_DEFAULT_FALLOCATE is not set # CONFIG_BUSYBOX_DEFAULT_FATATTR is not set # CONFIG_BUSYBOX_DEFAULT_FBSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_READMODE is not set # CONFIG_BUSYBOX_DEFAULT_FDFORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FDISK is not set # CONFIG_BUSYBOX_DEFAULT_FDISK_SUPPORT_LARGE_DISKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_WRITABLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AIX_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SGI_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUN_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_OSF_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GPT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_ADVANCED is not set # CONFIG_BUSYBOX_DEFAULT_FINDFS is not set CONFIG_BUSYBOX_DEFAULT_FLOCK=y # CONFIG_BUSYBOX_DEFAULT_FDFLUSH is not set # CONFIG_BUSYBOX_DEFAULT_FREERAMDISK is not set # CONFIG_BUSYBOX_DEFAULT_FSCK_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FSFREEZE is not set # CONFIG_BUSYBOX_DEFAULT_FSTRIM is not set # CONFIG_BUSYBOX_DEFAULT_GETOPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GETOPT_LONG is not set CONFIG_BUSYBOX_DEFAULT_HEXDUMP=y # CONFIG_BUSYBOX_DEFAULT_HD is not set # CONFIG_BUSYBOX_DEFAULT_XXD is not set CONFIG_BUSYBOX_DEFAULT_HWCLOCK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWCLOCK_ADJTIME_FHS is not set # CONFIG_BUSYBOX_DEFAULT_IONICE is not set # CONFIG_BUSYBOX_DEFAULT_IPCRM is not set # CONFIG_BUSYBOX_DEFAULT_IPCS is not set # CONFIG_BUSYBOX_DEFAULT_LAST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LAST_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_LOSETUP is not set # CONFIG_BUSYBOX_DEFAULT_LSPCI is not set # CONFIG_BUSYBOX_DEFAULT_LSUSB is not set # CONFIG_BUSYBOX_DEFAULT_MDEV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_EXEC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_LOAD_FIRMWARE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_DAEMON is not set # CONFIG_BUSYBOX_DEFAULT_MESG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MESG_ENABLE_ONLY_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_MKE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_EXT2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MINIX2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_REISER is not set # CONFIG_BUSYBOX_DEFAULT_MKDOSFS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_VFAT is not set CONFIG_BUSYBOX_DEFAULT_MKSWAP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MKSWAP_UUID is not set # CONFIG_BUSYBOX_DEFAULT_MORE is not set CONFIG_BUSYBOX_DEFAULT_MOUNT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FAKE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_HELPERS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_NFS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_CIFS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FLAGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FSTAB=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_OTHERTAB is not set # CONFIG_BUSYBOX_DEFAULT_MOUNTPOINT is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN_DEPENDENCIES is not set # CONFIG_BUSYBOX_DEFAULT_NSENTER is not set CONFIG_BUSYBOX_DEFAULT_PIVOT_ROOT=y # CONFIG_BUSYBOX_DEFAULT_RDATE is not set # CONFIG_BUSYBOX_DEFAULT_RDEV is not set # CONFIG_BUSYBOX_DEFAULT_READPROFILE is not set # CONFIG_BUSYBOX_DEFAULT_RENICE is not set # CONFIG_BUSYBOX_DEFAULT_REV is not set # CONFIG_BUSYBOX_DEFAULT_RTCWAKE is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPTREPLAY is not set # CONFIG_BUSYBOX_DEFAULT_SETARCH is not set # CONFIG_BUSYBOX_DEFAULT_LINUX32 is not set # CONFIG_BUSYBOX_DEFAULT_LINUX64 is not set # CONFIG_BUSYBOX_DEFAULT_SETPRIV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_DUMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITIES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITY_NAMES is not set # CONFIG_BUSYBOX_DEFAULT_SETSID is not set CONFIG_BUSYBOX_DEFAULT_SWAPON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_DISCARD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_PRI=y CONFIG_BUSYBOX_DEFAULT_SWAPOFF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPONOFF_LABEL is not set CONFIG_BUSYBOX_DEFAULT_SWITCH_ROOT=y # CONFIG_BUSYBOX_DEFAULT_TASKSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TASKSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TASKSET_CPULIST is not set # CONFIG_BUSYBOX_DEFAULT_UEVENT is not set CONFIG_BUSYBOX_DEFAULT_UMOUNT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_UMOUNT_ALL=y # CONFIG_BUSYBOX_DEFAULT_UNSHARE is not set # CONFIG_BUSYBOX_DEFAULT_WALL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MTAB_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_VOLUMEID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BCACHE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BTRFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_CRAMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EROFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXFAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_F2FS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_FAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_HFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ISO9660 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_JFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXRAID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXSWAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LUKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NILFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NTFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_OCFS2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_REISERFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ROMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SQUASHFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SYSV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UBIFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_XFS is not set # CONFIG_BUSYBOX_DEFAULT_ADJTIMEX is not set # CONFIG_BUSYBOX_DEFAULT_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_BC is not set # CONFIG_BUSYBOX_DEFAULT_DC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_LIBM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_BEEP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_FREQ=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_LENGTH_MS=0 # CONFIG_BUSYBOX_DEFAULT_CHAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_NOFAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_TTY_HIFI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_IMPLICIT_CR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SWALLOW_OPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SEND_ESCAPES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_VAR_ABORT_LEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_CLR_ABORT is not set # CONFIG_BUSYBOX_DEFAULT_CONSPY is not set CONFIG_BUSYBOX_DEFAULT_CROND=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_D is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_CALL_SENDMAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_SPECIAL_TIMES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_DIR="/etc" CONFIG_BUSYBOX_DEFAULT_CRONTAB=y # CONFIG_BUSYBOX_DEFAULT_DEVFSD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_MODLOAD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_FG_NP is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_VERBOSE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVFS is not set # CONFIG_BUSYBOX_DEFAULT_DEVMEM is not set # CONFIG_BUSYBOX_DEFAULT_FBSPLASH is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_ERASEALL is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_LOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_UNLOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASHCP is not set # CONFIG_BUSYBOX_DEFAULT_HDPARM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_GET_IDENTITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_GETSET_DMA is not set # CONFIG_BUSYBOX_DEFAULT_HEXEDIT is not set # CONFIG_BUSYBOX_DEFAULT_I2CGET is not set # CONFIG_BUSYBOX_DEFAULT_I2CSET is not set # CONFIG_BUSYBOX_DEFAULT_I2CDUMP is not set # CONFIG_BUSYBOX_DEFAULT_I2CDETECT is not set # CONFIG_BUSYBOX_DEFAULT_I2CTRANSFER is not set # CONFIG_BUSYBOX_DEFAULT_INOTIFYD is not set CONFIG_BUSYBOX_DEFAULT_LESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MAXLINES=9999999 # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_BRACKETS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_FLAGS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MARKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_DASHCMD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_LINENUMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_RAW is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ENV is not set CONFIG_BUSYBOX_DEFAULT_LOCK=y # CONFIG_BUSYBOX_DEFAULT_LSSCSI is not set # CONFIG_BUSYBOX_DEFAULT_MAKEDEVS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_LEAF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_MAN is not set # CONFIG_BUSYBOX_DEFAULT_MICROCOM is not set # CONFIG_BUSYBOX_DEFAULT_MIM is not set # CONFIG_BUSYBOX_DEFAULT_MT is not set # CONFIG_BUSYBOX_DEFAULT_NANDWRITE is not set # CONFIG_BUSYBOX_DEFAULT_NANDDUMP is not set # CONFIG_BUSYBOX_DEFAULT_PARTPROBE is not set # CONFIG_BUSYBOX_DEFAULT_RAIDAUTORUN is not set # CONFIG_BUSYBOX_DEFAULT_READAHEAD is not set # CONFIG_BUSYBOX_DEFAULT_RFKILL is not set # CONFIG_BUSYBOX_DEFAULT_RUNLEVEL is not set # CONFIG_BUSYBOX_DEFAULT_RX is not set # CONFIG_BUSYBOX_DEFAULT_SETFATTR is not set # CONFIG_BUSYBOX_DEFAULT_SETSERIAL is not set CONFIG_BUSYBOX_DEFAULT_STRINGS=y CONFIG_BUSYBOX_DEFAULT_TIME=y # CONFIG_BUSYBOX_DEFAULT_TS is not set # CONFIG_BUSYBOX_DEFAULT_TTYSIZE is not set # CONFIG_BUSYBOX_DEFAULT_UBIATTACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIDETACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIMKVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRMVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRSVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIUPDATEVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRENAME is not set # CONFIG_BUSYBOX_DEFAULT_VOLNAME is not set # CONFIG_BUSYBOX_DEFAULT_WATCHDOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPV6=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNIX_LOCAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_IPV4_ADDRESS is not set CONFIG_BUSYBOX_DEFAULT_VERBOSE_RESOLUTION_ERRORS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TLS_SHA1 is not set # CONFIG_BUSYBOX_DEFAULT_ARP is not set # CONFIG_BUSYBOX_DEFAULT_ARPING is not set CONFIG_BUSYBOX_DEFAULT_BRCTL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_FANCY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_SHOW=y # CONFIG_BUSYBOX_DEFAULT_DNSD is not set # CONFIG_BUSYBOX_DEFAULT_ETHER_WAKE is not set # CONFIG_BUSYBOX_DEFAULT_FTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_WRITE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FTPGET is not set # CONFIG_BUSYBOX_DEFAULT_FTPPUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPGETPUT_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HOSTNAME is not set # CONFIG_BUSYBOX_DEFAULT_DNSDOMAINNAME is not set # CONFIG_BUSYBOX_DEFAULT_HTTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_RANGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SETUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_BASIC_AUTH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_AUTH_MD5 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CGI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ENCODE_URL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ERROR_PAGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_PROXY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_GZIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ETAG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_LAST_MODIFIED is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_DATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ACL_IP is not set CONFIG_BUSYBOX_DEFAULT_IFCONFIG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_STATUS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_SLIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_HW=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_BROADCAST_PLUS=y # CONFIG_BUSYBOX_DEFAULT_IFENSLAVE is not set # CONFIG_BUSYBOX_DEFAULT_IFPLUGD is not set # CONFIG_BUSYBOX_DEFAULT_IFUP is not set # CONFIG_BUSYBOX_DEFAULT_IFDOWN is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_IFSTATE_PATH="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV4 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_MAPPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set # CONFIG_BUSYBOX_DEFAULT_INETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_RPC is not set CONFIG_BUSYBOX_DEFAULT_IP=y # CONFIG_BUSYBOX_DEFAULT_IPADDR is not set # CONFIG_BUSYBOX_DEFAULT_IPLINK is not set # CONFIG_BUSYBOX_DEFAULT_IPROUTE is not set # CONFIG_BUSYBOX_DEFAULT_IPTUNNEL is not set # CONFIG_BUSYBOX_DEFAULT_IPRULE is not set # CONFIG_BUSYBOX_DEFAULT_IPNEIGH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ADDRESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_LINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE_DIR="/etc/iproute2" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_TUNNEL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RULE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_NEIGH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RARE_PROTOCOLS is not set # CONFIG_BUSYBOX_DEFAULT_IPCALC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FAKEIDENTD is not set # CONFIG_BUSYBOX_DEFAULT_NAMEIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NAMEIF_EXTENDED is not set # CONFIG_BUSYBOX_DEFAULT_NBDCLIENT is not set CONFIG_BUSYBOX_DEFAULT_NC=y # CONFIG_BUSYBOX_DEFAULT_NETCAT is not set # CONFIG_BUSYBOX_DEFAULT_NC_SERVER is not set # CONFIG_BUSYBOX_DEFAULT_NC_EXTRA is not set # CONFIG_BUSYBOX_DEFAULT_NC_110_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_NETMSG=y CONFIG_BUSYBOX_DEFAULT_NETSTAT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_WIDE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_PRG=y CONFIG_BUSYBOX_DEFAULT_NSLOOKUP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_BIG=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_NTPD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_SERVER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTP_AUTH is not set CONFIG_BUSYBOX_DEFAULT_PING=y CONFIG_BUSYBOX_DEFAULT_PING6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_PING=y # CONFIG_BUSYBOX_DEFAULT_PSCAN is not set CONFIG_BUSYBOX_DEFAULT_ROUTE=y # CONFIG_BUSYBOX_DEFAULT_SLATTACH is not set # CONFIG_BUSYBOX_DEFAULT_SSL_CLIENT is not set # CONFIG_BUSYBOX_DEFAULT_TC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TC_INGRESS is not set # CONFIG_BUSYBOX_DEFAULT_TCPSVD is not set # CONFIG_BUSYBOX_DEFAULT_UDPSVD is not set # CONFIG_BUSYBOX_DEFAULT_TELNET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_TTYPE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_AUTOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_WIDTH is not set # CONFIG_BUSYBOX_DEFAULT_TELNETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_STANDALONE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_INETD_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_TFTP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PROGRESS_BAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_HPA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_TFTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_GET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_BLOCKSIZE is not set # CONFIG_BUSYBOX_DEFAULT_TFTP_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_TLS is not set CONFIG_BUSYBOX_DEFAULT_TRACEROUTE=y CONFIG_BUSYBOX_DEFAULT_TRACEROUTE6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_VERBOSE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_USE_ICMP is not set # CONFIG_BUSYBOX_DEFAULT_TUNCTL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TUNCTL_UG is not set # CONFIG_BUSYBOX_DEFAULT_VCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_WGET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_STATUSBAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_HTTPS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_OPENSSL is not set # CONFIG_BUSYBOX_DEFAULT_WHOIS is not set # CONFIG_BUSYBOX_DEFAULT_ZCIP is not set # CONFIG_BUSYBOX_DEFAULT_UDHCPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set CONFIG_BUSYBOX_DEFAULT_DHCPD_LEASES_FILE="" # CONFIG_BUSYBOX_DEFAULT_DUMPLEASES is not set # CONFIG_BUSYBOX_DEFAULT_DHCPRELAY is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_ARPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_SANITIZEOPT is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" # CONFIG_BUSYBOX_DEFAULT_UDHCPC6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC3646 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4704 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4833 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC5970 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_PORT is not set CONFIG_BUSYBOX_DEFAULT_UDHCP_DEBUG=0 CONFIG_BUSYBOX_DEFAULT_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80 CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_RFC3397=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_8021Q is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_UDHCPC_CMD_OPTIONS="" # CONFIG_BUSYBOX_DEFAULT_LPD is not set # CONFIG_BUSYBOX_DEFAULT_LPR is not set # CONFIG_BUSYBOX_DEFAULT_LPQ is not set # CONFIG_BUSYBOX_DEFAULT_MAKEMIME is not set # CONFIG_BUSYBOX_DEFAULT_POPMAILDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POPMAILDIR_DELIVERY is not set # CONFIG_BUSYBOX_DEFAULT_REFORMIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REFORMIME_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_SENDMAIL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MIME_CHARSET="" CONFIG_BUSYBOX_DEFAULT_FREE=y # CONFIG_BUSYBOX_DEFAULT_FUSER is not set # CONFIG_BUSYBOX_DEFAULT_IOSTAT is not set CONFIG_BUSYBOX_DEFAULT_KILL=y CONFIG_BUSYBOX_DEFAULT_KILLALL=y # CONFIG_BUSYBOX_DEFAULT_KILLALL5 is not set # CONFIG_BUSYBOX_DEFAULT_LSOF is not set # CONFIG_BUSYBOX_DEFAULT_MPSTAT is not set # CONFIG_BUSYBOX_DEFAULT_NMETER is not set CONFIG_BUSYBOX_DEFAULT_PGREP=y # CONFIG_BUSYBOX_DEFAULT_PKILL is not set CONFIG_BUSYBOX_DEFAULT_PIDOF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_SINGLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_OMIT is not set # CONFIG_BUSYBOX_DEFAULT_PMAP is not set # CONFIG_BUSYBOX_DEFAULT_POWERTOP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POWERTOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_PS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_WIDE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_LONG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_UNUSUAL_SYSTEMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_ADDITIONAL_COLUMNS is not set # CONFIG_BUSYBOX_DEFAULT_PSTREE is not set # CONFIG_BUSYBOX_DEFAULT_PWDX is not set # CONFIG_BUSYBOX_DEFAULT_SMEMCAP is not set CONFIG_BUSYBOX_DEFAULT_BB_SYSCTL=y CONFIG_BUSYBOX_DEFAULT_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_CPU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_DECIMALS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_PROCESS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOPMEM is not set CONFIG_BUSYBOX_DEFAULT_UPTIME=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UPTIME_UTMP_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_WATCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_THREADS is not set # CONFIG_BUSYBOX_DEFAULT_CHPST is not set # CONFIG_BUSYBOX_DEFAULT_SETUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVDIR is not set # CONFIG_BUSYBOX_DEFAULT_SOFTLIMIT is not set # CONFIG_BUSYBOX_DEFAULT_RUNSV is not set # CONFIG_BUSYBOX_DEFAULT_RUNSVDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUNSVDIR_LOG is not set # CONFIG_BUSYBOX_DEFAULT_SV is not set CONFIG_BUSYBOX_DEFAULT_SV_DEFAULT_SERVICE_DIR="" # CONFIG_BUSYBOX_DEFAULT_SVC is not set # CONFIG_BUSYBOX_DEFAULT_SVOK is not set # CONFIG_BUSYBOX_DEFAULT_SVLOGD is not set # CONFIG_BUSYBOX_DEFAULT_CHCON is not set # CONFIG_BUSYBOX_DEFAULT_GETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_GETSEBOOL is not set # CONFIG_BUSYBOX_DEFAULT_LOAD_POLICY is not set # CONFIG_BUSYBOX_DEFAULT_MATCHPATHCON is not set # CONFIG_BUSYBOX_DEFAULT_RUNCON is not set # CONFIG_BUSYBOX_DEFAULT_SELINUXENABLED is not set # CONFIG_BUSYBOX_DEFAULT_SESTATUS is not set # CONFIG_BUSYBOX_DEFAULT_SETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_SETFILES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFILES_CHECK_OPTION is not set # CONFIG_BUSYBOX_DEFAULT_RESTORECON is not set # CONFIG_BUSYBOX_DEFAULT_SETSEBOOL is not set CONFIG_BUSYBOX_DEFAULT_SH_IS_ASH=y # CONFIG_BUSYBOX_DEFAULT_SH_IS_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_SH_IS_NONE is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_ASH is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_HUSH is not set CONFIG_BUSYBOX_DEFAULT_BASH_IS_NONE=y CONFIG_BUSYBOX_DEFAULT_SHELL_ASH=y CONFIG_BUSYBOX_DEFAULT_ASH=y # CONFIG_BUSYBOX_DEFAULT_ASH_OPTIMIZE_FOR_SIZE is not set CONFIG_BUSYBOX_DEFAULT_ASH_INTERNAL_GLOB=y CONFIG_BUSYBOX_DEFAULT_ASH_BASH_COMPAT=y # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_NOT_FOUND_HOOK is not set CONFIG_BUSYBOX_DEFAULT_ASH_JOB_CONTROL=y CONFIG_BUSYBOX_DEFAULT_ASH_ALIAS=y # CONFIG_BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT is not set CONFIG_BUSYBOX_DEFAULT_ASH_EXPAND_PRMT=y # CONFIG_BUSYBOX_DEFAULT_ASH_IDLE_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_ASH_MAIL is not set CONFIG_BUSYBOX_DEFAULT_ASH_ECHO=y CONFIG_BUSYBOX_DEFAULT_ASH_PRINTF=y CONFIG_BUSYBOX_DEFAULT_ASH_TEST=y # CONFIG_BUSYBOX_DEFAULT_ASH_HELP is not set CONFIG_BUSYBOX_DEFAULT_ASH_GETOPTS=y CONFIG_BUSYBOX_DEFAULT_ASH_CMDCMD=y # CONFIG_BUSYBOX_DEFAULT_CTTYHACK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_SHELL_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BRACE_EXPANSION is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LINENO_VAR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_JOB is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TICK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_IF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOOPS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_CASE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_FUNCTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOCAL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_RANDOM_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MODE_X is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_PRINTF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TEST is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_HELP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT_N is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READONLY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_KILL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TRAP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TIMES is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READ is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UNSET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ULIMIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UMASK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_GETOPTS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MEMLEAK is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_64=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_BASE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EXTRA_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_STANDALONE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_NOFORK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_READ_FRAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_HISTFILESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EMBEDDED_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_KLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KLOGD_KLOGCTL is not set CONFIG_BUSYBOX_DEFAULT_LOGGER=y # CONFIG_BUSYBOX_DEFAULT_LOGREAD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOGREAD_REDUCED_LOCKING is not set # CONFIG_BUSYBOX_DEFAULT_SYSLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ROTATE_LOGFILE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REMOTE_LOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_DUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_CFG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_KMSG_SYSLOG is not set # CONFIG_PACKAGE_busybox-selinux is not set CONFIG_PACKAGE_ca-bundle=y # CONFIG_PACKAGE_ca-certificates is not set # CONFIG_PACKAGE_dnsmasq is not set # CONFIG_PACKAGE_dnsmasq-dhcpv6 is not set CONFIG_PACKAGE_dnsmasq-full=y CONFIG_PACKAGE_dnsmasq_full_dhcp=y # CONFIG_PACKAGE_dnsmasq_full_dhcpv6 is not set # CONFIG_PACKAGE_dnsmasq_full_dnssec is not set # CONFIG_PACKAGE_dnsmasq_full_auth is not set CONFIG_PACKAGE_dnsmasq_full_ipset=y # CONFIG_PACKAGE_dnsmasq_full_conntrack is not set # CONFIG_PACKAGE_dnsmasq_full_noid is not set # CONFIG_PACKAGE_dnsmasq_full_broken_rtc is not set CONFIG_PACKAGE_dnsmasq_full_tftp=y CONFIG_PACKAGE_dropbear=y # # Configuration # CONFIG_DROPBEAR_CURVE25519=y # CONFIG_DROPBEAR_ECC is not set CONFIG_DROPBEAR_ED25519=y CONFIG_DROPBEAR_CHACHA20POLY1305=y # CONFIG_DROPBEAR_ZLIB is not set CONFIG_DROPBEAR_DBCLIENT=y CONFIG_DROPBEAR_SCP=y # CONFIG_DROPBEAR_ASKPASS is not set # end of Configuration # CONFIG_PACKAGE_ead is not set CONFIG_PACKAGE_firewall=y # CONFIG_PACKAGE_firewall4 is not set CONFIG_PACKAGE_fstools=y # CONFIG_FSTOOLS_UBIFS_EXTROOT is not set # CONFIG_FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME is not set # CONFIG_FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB is not set CONFIG_PACKAGE_fwtool=y CONFIG_PACKAGE_getrandom=y CONFIG_PACKAGE_jsonfilter=y # CONFIG_PACKAGE_libatomic is not set CONFIG_PACKAGE_libc=y CONFIG_PACKAGE_libgcc=y # CONFIG_PACKAGE_libgomp is not set CONFIG_PACKAGE_libpthread=y CONFIG_PACKAGE_librt=y CONFIG_PACKAGE_libstdcpp=y CONFIG_PACKAGE_logd=y CONFIG_PACKAGE_mtd=y CONFIG_PACKAGE_netifd=y # CONFIG_PACKAGE_nft-qos is not set # CONFIG_PACKAGE_om-watchdog is not set CONFIG_PACKAGE_openwrt-keyring=y CONFIG_PACKAGE_opkg=y CONFIG_PACKAGE_procd=y # # Configuration # # CONFIG_PROCD_SHOW_BOOT is not set # CONFIG_PROCD_ZRAM_TMPFS is not set # end of Configuration # CONFIG_PACKAGE_procd-seccomp is not set # CONFIG_PACKAGE_procd-selinux is not set # CONFIG_PACKAGE_procd-ujail is not set # CONFIG_PACKAGE_procd-ujail-console is not set # CONFIG_PACKAGE_qos-scripts is not set # CONFIG_PACKAGE_refpolicy is not set CONFIG_PACKAGE_resolveip=y CONFIG_PACKAGE_rpcd=y # CONFIG_PACKAGE_rpcd-mod-file is not set # CONFIG_PACKAGE_rpcd-mod-iwinfo is not set # CONFIG_PACKAGE_rpcd-mod-rpcsys is not set # CONFIG_PACKAGE_selinux-policy is not set # CONFIG_PACKAGE_snapshot-tool is not set # CONFIG_PACKAGE_sqm-scripts is not set # CONFIG_PACKAGE_sqm-scripts-extra is not set CONFIG_PACKAGE_swconfig=y CONFIG_PACKAGE_ubox=y CONFIG_PACKAGE_ubus=y CONFIG_PACKAGE_ubusd=y # CONFIG_PACKAGE_ucert is not set # CONFIG_PACKAGE_ucert-full is not set CONFIG_PACKAGE_uci=y CONFIG_PACKAGE_urandom-seed=y # CONFIG_PACKAGE_urngd is not set CONFIG_PACKAGE_usign=y # CONFIG_PACKAGE_uxc is not set # CONFIG_PACKAGE_wireless-tools is not set # CONFIG_PACKAGE_zram-swap is not set # end of Base system # # Administration # # # Zabbix # # CONFIG_PACKAGE_zabbix-agentd is not set # # SSL support # # CONFIG_ZABBIX_OPENSSL is not set # CONFIG_ZABBIX_GNUTLS is not set CONFIG_ZABBIX_NOSSL=y # CONFIG_PACKAGE_zabbix-extra-network is not set # CONFIG_PACKAGE_zabbix-extra-wifi is not set # CONFIG_PACKAGE_zabbix-get is not set # CONFIG_PACKAGE_zabbix-proxy is not set # CONFIG_PACKAGE_zabbix-sender is not set # CONFIG_PACKAGE_zabbix-server is not set # # Database Software # # CONFIG_ZABBIX_MYSQL is not set CONFIG_ZABBIX_POSTGRESQL=y # CONFIG_PACKAGE_zabbix-server-frontend is not set # end of Zabbix # # openwisp # # CONFIG_PACKAGE_openwisp-config-mbedtls is not set # CONFIG_PACKAGE_openwisp-config-nossl is not set # CONFIG_PACKAGE_openwisp-config-openssl is not set # CONFIG_PACKAGE_openwisp-config-wolfssl is not set # end of openwisp # CONFIG_PACKAGE_atop is not set # CONFIG_PACKAGE_backuppc is not set # CONFIG_PACKAGE_debian-archive-keyring is not set # CONFIG_PACKAGE_debootstrap is not set # CONFIG_PACKAGE_gkrellmd is not set CONFIG_PACKAGE_htop=y # CONFIG_PACKAGE_ipmitool is not set # CONFIG_PACKAGE_monit is not set # CONFIG_PACKAGE_monit-nossl is not set # CONFIG_PACKAGE_muninlite is not set # CONFIG_PACKAGE_netatop is not set CONFIG_PACKAGE_netdata=y # CONFIG_PACKAGE_nyx is not set # CONFIG_PACKAGE_schroot is not set # # Configuration # # CONFIG_SCHROOT_BTRFS is not set # CONFIG_SCHROOT_LOOPBACK is not set # CONFIG_SCHROOT_LVM is not set # CONFIG_SCHROOT_UUID is not set # end of Configuration # CONFIG_PACKAGE_sudo is not set # CONFIG_PACKAGE_syslog-ng is not set # end of Administration # # Boot Loaders # # end of Boot Loaders # # Development # # # Libraries # # CONFIG_PACKAGE_libncurses-dev is not set # CONFIG_PACKAGE_libxml2-dev is not set # CONFIG_PACKAGE_zlib-dev is not set # end of Libraries # CONFIG_PACKAGE_ar is not set # CONFIG_PACKAGE_autoconf is not set # CONFIG_PACKAGE_automake is not set # CONFIG_PACKAGE_binutils is not set # CONFIG_PACKAGE_diffutils is not set # CONFIG_PACKAGE_gcc is not set # CONFIG_PACKAGE_gdb is not set # CONFIG_PACKAGE_gdbserver is not set # CONFIG_PACKAGE_gitlab-runner is not set # CONFIG_PACKAGE_libtool-bin is not set # CONFIG_PACKAGE_lpc21isp is not set # CONFIG_PACKAGE_lttng-tools is not set # CONFIG_PACKAGE_m4 is not set # CONFIG_PACKAGE_make is not set # CONFIG_PACKAGE_meson is not set # CONFIG_PACKAGE_ninja is not set # CONFIG_PACKAGE_objdump is not set # CONFIG_PACKAGE_packr is not set # CONFIG_PACKAGE_patch is not set # CONFIG_PACKAGE_pkg-config is not set # CONFIG_PACKAGE_pkgconf is not set # CONFIG_PACKAGE_trace-cmd is not set # CONFIG_PACKAGE_trace-cmd-extra is not set # CONFIG_PACKAGE_valgrind is not set # end of Development # # Extra packages # # CONFIG_PACKAGE_automount is not set # CONFIG_PACKAGE_autosamba is not set # CONFIG_PACKAGE_ipv6helper is not set # CONFIG_PACKAGE_jose is not set # CONFIG_PACKAGE_k3wifi is not set # CONFIG_PACKAGE_libjose is not set # CONFIG_PACKAGE_nginx is not set # CONFIG_PACKAGE_nginx-mod-luci-ssl is not set # CONFIG_PACKAGE_nginx-util is not set # CONFIG_PACKAGE_tang is not set # end of Extra packages # # Firmware # # # ath10k Board-Specific Overrides # # end of ath10k Board-Specific Overrides # CONFIG_PACKAGE_aircard-pcmcia-firmware is not set # CONFIG_PACKAGE_amdgpu-firmware is not set # CONFIG_PACKAGE_ar3k-firmware is not set # CONFIG_PACKAGE_ath10k-board-qca4019 is not set # CONFIG_PACKAGE_ath10k-board-qca9377 is not set # CONFIG_PACKAGE_ath10k-board-qca9887 is not set # CONFIG_PACKAGE_ath10k-board-qca9888 is not set # CONFIG_PACKAGE_ath10k-board-qca988x is not set # CONFIG_PACKAGE_ath10k-board-qca9984 is not set # CONFIG_PACKAGE_ath10k-board-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca6174 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9377 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-htt is not set # CONFIG_PACKAGE_ath11k-firmware-ipq6018 is not set # CONFIG_PACKAGE_ath11k-firmware-ipq8074 is not set # CONFIG_PACKAGE_ath11k-firmware-qca6390 is not set # CONFIG_PACKAGE_ath11k-firmware-qcn9074 is not set # CONFIG_PACKAGE_ath6k-firmware is not set # CONFIG_PACKAGE_ath9k-htc-firmware is not set # CONFIG_PACKAGE_b43legacy-firmware is not set # CONFIG_PACKAGE_bnx2-firmware is not set # CONFIG_PACKAGE_bnx2x-firmware is not set # CONFIG_PACKAGE_brcmfmac-firmware-4329-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-3b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-zero-w is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430a0-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-3b-plus is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-4b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43602a1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366b1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366c0-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-usb is not set # CONFIG_PACKAGE_brcmsmac-firmware is not set # CONFIG_PACKAGE_carl9170-firmware is not set # CONFIG_PACKAGE_cypress-firmware-43012-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43340-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43362-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4339-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43430-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43455-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4354-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4356-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4356-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43570-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-usb is not set # CONFIG_PACKAGE_cypress-firmware-54591-pcie is not set # CONFIG_PACKAGE_cypress-firmware-89459-pcie is not set # CONFIG_PACKAGE_e100-firmware is not set # CONFIG_PACKAGE_edgeport-firmware is not set # CONFIG_PACKAGE_eip197-mini-firmware is not set # CONFIG_PACKAGE_ibt-firmware is not set # CONFIG_PACKAGE_iwl3945-firmware is not set # CONFIG_PACKAGE_iwl4965-firmware is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl100 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl1000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl105 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl135 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2030 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3160 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3168 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5150 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2a is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2b is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6050 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7260 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265d is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8260c is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9260 is not set # CONFIG_PACKAGE_jboot-tools is not set # CONFIG_PACKAGE_libertas-sdio-firmware is not set # CONFIG_PACKAGE_libertas-spi-firmware is not set # CONFIG_PACKAGE_libertas-usb-firmware is not set # CONFIG_PACKAGE_mt7601u-firmware is not set # CONFIG_PACKAGE_mt7622bt-firmware is not set # CONFIG_PACKAGE_mwifiex-pcie-firmware is not set # CONFIG_PACKAGE_mwifiex-sdio-firmware is not set # CONFIG_PACKAGE_mwl8k-firmware is not set # CONFIG_PACKAGE_p54-pci-firmware is not set # CONFIG_PACKAGE_p54-spi-firmware is not set # CONFIG_PACKAGE_p54-usb-firmware is not set # CONFIG_PACKAGE_prism54-firmware is not set # CONFIG_PACKAGE_qtn-firmware is not set # CONFIG_PACKAGE_qtn-proto is not set # CONFIG_PACKAGE_qtn-utils is not set # CONFIG_PACKAGE_r8169-firmware is not set # CONFIG_PACKAGE_radeon-firmware is not set # CONFIG_PACKAGE_rs9113-firmware is not set # CONFIG_PACKAGE_rt2800-pci-firmware is not set # CONFIG_PACKAGE_rt2800-usb-firmware is not set # CONFIG_PACKAGE_rt61-pci-firmware is not set # CONFIG_PACKAGE_rt73-usb-firmware is not set # CONFIG_PACKAGE_rtl8188eu-firmware is not set # CONFIG_PACKAGE_rtl8192ce-firmware is not set # CONFIG_PACKAGE_rtl8192cu-firmware is not set # CONFIG_PACKAGE_rtl8192de-firmware is not set # CONFIG_PACKAGE_rtl8192eu-firmware is not set # CONFIG_PACKAGE_rtl8192se-firmware is not set # CONFIG_PACKAGE_rtl8192su-firmware is not set # CONFIG_PACKAGE_rtl8723au-firmware is not set # CONFIG_PACKAGE_rtl8723bs-firmware is not set # CONFIG_PACKAGE_rtl8723bu-firmware is not set # CONFIG_PACKAGE_rtl8821ae-firmware is not set # CONFIG_PACKAGE_rtl8822be-firmware is not set # CONFIG_PACKAGE_rtl8822ce-firmware is not set # CONFIG_PACKAGE_ti-3410-firmware is not set # CONFIG_PACKAGE_ti-5052-firmware is not set # CONFIG_PACKAGE_wil6210-firmware is not set # CONFIG_PACKAGE_wireless-regdb is not set # CONFIG_PACKAGE_wl12xx-firmware is not set # CONFIG_PACKAGE_wl18xx-firmware is not set # end of Firmware # # Fonts # # # DejaVu # # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuMathTeXGyre is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-ExtraLight is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Italic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Italic is not set # end of DejaVu # end of Fonts # # Kernel modules # # # Block Devices # # CONFIG_PACKAGE_kmod-aoe is not set # CONFIG_PACKAGE_kmod-ata-ahci is not set # CONFIG_PACKAGE_kmod-ata-artop is not set # CONFIG_PACKAGE_kmod-ata-core is not set # CONFIG_PACKAGE_kmod-ata-marvell-sata is not set # CONFIG_PACKAGE_kmod-ata-nvidia-sata is not set # CONFIG_PACKAGE_kmod-ata-pdc202xx-old is not set # CONFIG_PACKAGE_kmod-ata-piix is not set # CONFIG_PACKAGE_kmod-ata-sil is not set # CONFIG_PACKAGE_kmod-ata-sil24 is not set # CONFIG_PACKAGE_kmod-ata-via-sata is not set # CONFIG_PACKAGE_kmod-block2mtd is not set # CONFIG_PACKAGE_kmod-dax is not set # CONFIG_PACKAGE_kmod-dm is not set # CONFIG_PACKAGE_kmod-dm-raid is not set # CONFIG_PACKAGE_kmod-iosched-bfq is not set # CONFIG_PACKAGE_kmod-iscsi-initiator is not set # CONFIG_PACKAGE_kmod-loop is not set # CONFIG_PACKAGE_kmod-md-mod is not set # CONFIG_PACKAGE_kmod-nbd is not set # CONFIG_PACKAGE_kmod-scsi-cdrom is not set CONFIG_PACKAGE_kmod-scsi-core=y # CONFIG_PACKAGE_kmod-scsi-generic is not set # CONFIG_PACKAGE_kmod-scsi-tape is not set # end of Block Devices # # CAN Support # # CONFIG_PACKAGE_kmod-can is not set # end of CAN Support # # Cryptographic API modules # CONFIG_PACKAGE_kmod-crypto-acompress=y CONFIG_PACKAGE_kmod-crypto-aead=y CONFIG_PACKAGE_kmod-crypto-arc4=y CONFIG_PACKAGE_kmod-crypto-authenc=y # CONFIG_PACKAGE_kmod-crypto-cbc is not set CONFIG_PACKAGE_kmod-crypto-ccm=y CONFIG_PACKAGE_kmod-crypto-cmac=y CONFIG_PACKAGE_kmod-crypto-crc32c=y CONFIG_PACKAGE_kmod-crypto-ctr=y # CONFIG_PACKAGE_kmod-crypto-cts is not set # CONFIG_PACKAGE_kmod-crypto-deflate is not set CONFIG_PACKAGE_kmod-crypto-des=y CONFIG_PACKAGE_kmod-crypto-ecb=y # CONFIG_PACKAGE_kmod-crypto-ecdh is not set # CONFIG_PACKAGE_kmod-crypto-echainiv is not set # CONFIG_PACKAGE_kmod-crypto-fcrypt is not set # CONFIG_PACKAGE_kmod-crypto-gcm is not set # CONFIG_PACKAGE_kmod-crypto-gf128 is not set # CONFIG_PACKAGE_kmod-crypto-ghash is not set CONFIG_PACKAGE_kmod-crypto-hash=y CONFIG_PACKAGE_kmod-crypto-hmac=y CONFIG_PACKAGE_kmod-crypto-hw-eip93=y # CONFIG_PACKAGE_kmod-crypto-hw-hifn-795x is not set # CONFIG_PACKAGE_kmod-crypto-hw-padlock is not set # CONFIG_PACKAGE_kmod-crypto-kpp is not set CONFIG_PACKAGE_kmod-crypto-manager=y CONFIG_PACKAGE_kmod-crypto-md4=y CONFIG_PACKAGE_kmod-crypto-md5=y # CONFIG_PACKAGE_kmod-crypto-michael-mic is not set # CONFIG_PACKAGE_kmod-crypto-misc is not set CONFIG_PACKAGE_kmod-crypto-null=y # CONFIG_PACKAGE_kmod-crypto-pcbc is not set # CONFIG_PACKAGE_kmod-crypto-rmd160 is not set CONFIG_PACKAGE_kmod-crypto-rng=y CONFIG_PACKAGE_kmod-crypto-seqiv=y CONFIG_PACKAGE_kmod-crypto-sha1=y CONFIG_PACKAGE_kmod-crypto-sha256=y CONFIG_PACKAGE_kmod-crypto-sha512=y # CONFIG_PACKAGE_kmod-crypto-test is not set CONFIG_PACKAGE_kmod-crypto-user=y # CONFIG_PACKAGE_kmod-crypto-xcbc is not set # CONFIG_PACKAGE_kmod-crypto-xts is not set CONFIG_PACKAGE_kmod-cryptodev=y # end of Cryptographic API modules # # Filesystems # # CONFIG_PACKAGE_kmod-fs-afs is not set # CONFIG_PACKAGE_kmod-fs-antfs is not set # CONFIG_PACKAGE_kmod-fs-autofs4 is not set CONFIG_PACKAGE_kmod-fs-btrfs=y CONFIG_PACKAGE_kmod-fs-cifs=y # CONFIG_PACKAGE_kmod-fs-configfs is not set # CONFIG_PACKAGE_kmod-fs-cramfs is not set CONFIG_PACKAGE_kmod-fs-exfat=y # CONFIG_PACKAGE_kmod-fs-exportfs is not set CONFIG_PACKAGE_kmod-fs-ext4=y # CONFIG_PACKAGE_kmod-fs-f2fs is not set # CONFIG_PACKAGE_kmod-fs-fscache is not set # CONFIG_PACKAGE_kmod-fs-hfs is not set # CONFIG_PACKAGE_kmod-fs-hfsplus is not set # CONFIG_PACKAGE_kmod-fs-isofs is not set # CONFIG_PACKAGE_kmod-fs-jfs is not set # CONFIG_PACKAGE_kmod-fs-ksmbd is not set # CONFIG_PACKAGE_kmod-fs-minix is not set # CONFIG_PACKAGE_kmod-fs-msdos is not set # CONFIG_PACKAGE_kmod-fs-nfs is not set # CONFIG_PACKAGE_kmod-fs-nfs-common is not set # CONFIG_PACKAGE_kmod-fs-nfs-common-rpcsec is not set # CONFIG_PACKAGE_kmod-fs-nfs-v3 is not set # CONFIG_PACKAGE_kmod-fs-nfs-v4 is not set # CONFIG_PACKAGE_kmod-fs-nfsd is not set CONFIG_PACKAGE_kmod-fs-ntfs=y # CONFIG_PACKAGE_kmod-fs-ntfs3 is not set # CONFIG_PACKAGE_kmod-fs-reiserfs is not set # CONFIG_PACKAGE_kmod-fs-squashfs is not set # CONFIG_PACKAGE_kmod-fs-udf is not set # CONFIG_PACKAGE_kmod-fs-vfat is not set # CONFIG_PACKAGE_kmod-fs-xfs is not set # CONFIG_PACKAGE_kmod-fuse is not set # end of Filesystems # # FireWire support # # CONFIG_PACKAGE_kmod-firewire is not set # end of FireWire support # # Hardware Monitoring Support # # CONFIG_PACKAGE_kmod-gl-mifi-mcu is not set # CONFIG_PACKAGE_kmod-hwmon-ad7418 is not set # CONFIG_PACKAGE_kmod-hwmon-adcxx is not set # CONFIG_PACKAGE_kmod-hwmon-ads1015 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7410 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7475 is not set # CONFIG_PACKAGE_kmod-hwmon-core is not set # CONFIG_PACKAGE_kmod-hwmon-dme1737 is not set # CONFIG_PACKAGE_kmod-hwmon-drivetemp is not set # CONFIG_PACKAGE_kmod-hwmon-emc2305 is not set # CONFIG_PACKAGE_kmod-hwmon-gpiofan is not set # CONFIG_PACKAGE_kmod-hwmon-ina209 is not set # CONFIG_PACKAGE_kmod-hwmon-ina2xx is not set # CONFIG_PACKAGE_kmod-hwmon-it87 is not set # CONFIG_PACKAGE_kmod-hwmon-lm63 is not set # CONFIG_PACKAGE_kmod-hwmon-lm75 is not set # CONFIG_PACKAGE_kmod-hwmon-lm77 is not set # CONFIG_PACKAGE_kmod-hwmon-lm85 is not set # CONFIG_PACKAGE_kmod-hwmon-lm90 is not set # CONFIG_PACKAGE_kmod-hwmon-lm92 is not set # CONFIG_PACKAGE_kmod-hwmon-lm95241 is not set # CONFIG_PACKAGE_kmod-hwmon-ltc4151 is not set # CONFIG_PACKAGE_kmod-hwmon-mcp3021 is not set # CONFIG_PACKAGE_kmod-hwmon-pwmfan is not set # CONFIG_PACKAGE_kmod-hwmon-sch5627 is not set # CONFIG_PACKAGE_kmod-hwmon-sht21 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp102 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp103 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp421 is not set # CONFIG_PACKAGE_kmod-hwmon-vid is not set # CONFIG_PACKAGE_kmod-hwmon-w83793 is not set # CONFIG_PACKAGE_kmod-pmbus-core is not set # CONFIG_PACKAGE_kmod-pmbus-zl6100 is not set # end of Hardware Monitoring Support # # I2C support # # CONFIG_PACKAGE_kmod-i2c-algo-bit is not set # CONFIG_PACKAGE_kmod-i2c-algo-pca is not set # CONFIG_PACKAGE_kmod-i2c-algo-pcf is not set # CONFIG_PACKAGE_kmod-i2c-core is not set # CONFIG_PACKAGE_kmod-i2c-designware-pci is not set # CONFIG_PACKAGE_kmod-i2c-gpio is not set # CONFIG_PACKAGE_kmod-i2c-mux is not set # CONFIG_PACKAGE_kmod-i2c-mux-gpio is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca9541 is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca954x is not set # CONFIG_PACKAGE_kmod-i2c-pxa is not set # CONFIG_PACKAGE_kmod-i2c-smbus is not set # CONFIG_PACKAGE_kmod-i2c-tiny-usb is not set # end of I2C support # # Industrial I/O Modules # # CONFIG_PACKAGE_kmod-iio-ad799x is not set # CONFIG_PACKAGE_kmod-iio-am2315 is not set # CONFIG_PACKAGE_kmod-iio-bh1750 is not set # CONFIG_PACKAGE_kmod-iio-bme680 is not set # CONFIG_PACKAGE_kmod-iio-bme680-i2c is not set # CONFIG_PACKAGE_kmod-iio-bme680-spi is not set # CONFIG_PACKAGE_kmod-iio-bmp280 is not set # CONFIG_PACKAGE_kmod-iio-bmp280-i2c is not set # CONFIG_PACKAGE_kmod-iio-bmp280-spi is not set # CONFIG_PACKAGE_kmod-iio-ccs811 is not set # CONFIG_PACKAGE_kmod-iio-core is not set # CONFIG_PACKAGE_kmod-iio-dht11 is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-spi is not set # CONFIG_PACKAGE_kmod-iio-fxos8700 is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-spi is not set # CONFIG_PACKAGE_kmod-iio-hmc5843 is not set # CONFIG_PACKAGE_kmod-iio-htu21 is not set # CONFIG_PACKAGE_kmod-iio-kfifo-buf is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-i2c is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-spi is not set # CONFIG_PACKAGE_kmod-iio-si7020 is not set # CONFIG_PACKAGE_kmod-iio-sps30 is not set # CONFIG_PACKAGE_kmod-iio-st_accel is not set # CONFIG_PACKAGE_kmod-iio-st_accel-i2c is not set # CONFIG_PACKAGE_kmod-iio-st_accel-spi is not set # CONFIG_PACKAGE_kmod-iio-tsl4531 is not set # CONFIG_PACKAGE_kmod-industrialio-triggered-buffer is not set # end of Industrial I/O Modules # # Input modules # # CONFIG_PACKAGE_kmod-hid is not set # CONFIG_PACKAGE_kmod-hid-generic is not set # CONFIG_PACKAGE_kmod-input-core is not set # CONFIG_PACKAGE_kmod-input-evdev is not set # CONFIG_PACKAGE_kmod-input-gpio-encoder is not set # CONFIG_PACKAGE_kmod-input-gpio-keys is not set # CONFIG_PACKAGE_kmod-input-gpio-keys-polled is not set # CONFIG_PACKAGE_kmod-input-joydev is not set # CONFIG_PACKAGE_kmod-input-matrixkmap is not set # CONFIG_PACKAGE_kmod-input-polldev is not set # CONFIG_PACKAGE_kmod-input-touchscreen-ads7846 is not set # CONFIG_PACKAGE_kmod-input-uinput is not set # end of Input modules # # LED modules # # CONFIG_PACKAGE_kmod-input-leds is not set CONFIG_PACKAGE_kmod-leds-gpio=y # CONFIG_PACKAGE_kmod-leds-pca963x is not set # CONFIG_PACKAGE_kmod-leds-uleds is not set # CONFIG_PACKAGE_kmod-ledtrig-activity is not set # CONFIG_PACKAGE_kmod-ledtrig-audio is not set # CONFIG_PACKAGE_kmod-ledtrig-gpio is not set # CONFIG_PACKAGE_kmod-ledtrig-oneshot is not set # CONFIG_PACKAGE_kmod-ledtrig-transient is not set # end of LED modules # # Libraries # CONFIG_PACKAGE_kmod-asn1-decoder=y # CONFIG_PACKAGE_kmod-lib-cordic is not set CONFIG_PACKAGE_kmod-lib-crc-ccitt=y # CONFIG_PACKAGE_kmod-lib-crc-itu-t is not set CONFIG_PACKAGE_kmod-lib-crc16=y CONFIG_PACKAGE_kmod-lib-crc32c=y # CONFIG_PACKAGE_kmod-lib-crc7 is not set # CONFIG_PACKAGE_kmod-lib-crc8 is not set # CONFIG_PACKAGE_kmod-lib-lz4 is not set CONFIG_PACKAGE_kmod-lib-lzo=y CONFIG_PACKAGE_kmod-lib-raid6=y CONFIG_PACKAGE_kmod-lib-textsearch=y CONFIG_PACKAGE_kmod-lib-xor=y CONFIG_PACKAGE_kmod-lib-zlib-deflate=y CONFIG_PACKAGE_kmod-lib-zlib-inflate=y CONFIG_PACKAGE_kmod-lib-zstd=y # end of Libraries # # Native Language Support # CONFIG_PACKAGE_kmod-nls-base=y # CONFIG_PACKAGE_kmod-nls-cp1250 is not set # CONFIG_PACKAGE_kmod-nls-cp1251 is not set # CONFIG_PACKAGE_kmod-nls-cp437 is not set # CONFIG_PACKAGE_kmod-nls-cp775 is not set # CONFIG_PACKAGE_kmod-nls-cp850 is not set # CONFIG_PACKAGE_kmod-nls-cp852 is not set # CONFIG_PACKAGE_kmod-nls-cp862 is not set # CONFIG_PACKAGE_kmod-nls-cp864 is not set # CONFIG_PACKAGE_kmod-nls-cp866 is not set # CONFIG_PACKAGE_kmod-nls-cp932 is not set # CONFIG_PACKAGE_kmod-nls-cp936 is not set # CONFIG_PACKAGE_kmod-nls-cp950 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-1 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-13 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-15 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-2 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-6 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-8 is not set # CONFIG_PACKAGE_kmod-nls-koi8r is not set CONFIG_PACKAGE_kmod-nls-utf8=y # end of Native Language Support # # Netfilter Extensions # # CONFIG_PACKAGE_kmod-arptables is not set # CONFIG_PACKAGE_kmod-br-netfilter is not set # CONFIG_PACKAGE_kmod-ebtables is not set # CONFIG_PACKAGE_kmod-ebtables-ipv4 is not set # CONFIG_PACKAGE_kmod-ebtables-ipv6 is not set # CONFIG_PACKAGE_kmod-ebtables-watchers is not set CONFIG_PACKAGE_kmod-ip6tables=y # CONFIG_PACKAGE_kmod-ip6tables-extra is not set # CONFIG_PACKAGE_kmod-ipt-account is not set # CONFIG_PACKAGE_kmod-ipt-chaos is not set # CONFIG_PACKAGE_kmod-ipt-checksum is not set # CONFIG_PACKAGE_kmod-ipt-cluster is not set # CONFIG_PACKAGE_kmod-ipt-clusterip is not set # CONFIG_PACKAGE_kmod-ipt-compat-xtables is not set # CONFIG_PACKAGE_kmod-ipt-condition is not set CONFIG_PACKAGE_kmod-ipt-conntrack=y # CONFIG_PACKAGE_kmod-ipt-conntrack-extra is not set # CONFIG_PACKAGE_kmod-ipt-conntrack-label is not set CONFIG_PACKAGE_kmod-ipt-core=y # CONFIG_PACKAGE_kmod-ipt-debug is not set # CONFIG_PACKAGE_kmod-ipt-delude is not set # CONFIG_PACKAGE_kmod-ipt-dhcpmac is not set # CONFIG_PACKAGE_kmod-ipt-dnetmap is not set # CONFIG_PACKAGE_kmod-ipt-extra is not set # CONFIG_PACKAGE_kmod-ipt-filter is not set CONFIG_PACKAGE_kmod-ipt-fullconenat=y # CONFIG_PACKAGE_kmod-ipt-fuzzy is not set # CONFIG_PACKAGE_kmod-ipt-geoip is not set # CONFIG_PACKAGE_kmod-ipt-hashlimit is not set # CONFIG_PACKAGE_kmod-ipt-iface is not set # CONFIG_PACKAGE_kmod-ipt-ipmark is not set # CONFIG_PACKAGE_kmod-ipt-ipopt is not set # CONFIG_PACKAGE_kmod-ipt-ipp2p is not set # CONFIG_PACKAGE_kmod-ipt-iprange is not set # CONFIG_PACKAGE_kmod-ipt-ipsec is not set CONFIG_PACKAGE_kmod-ipt-ipset=y # CONFIG_PACKAGE_kmod-ipt-ipv4options is not set # CONFIG_PACKAGE_kmod-ipt-led is not set # CONFIG_PACKAGE_kmod-ipt-length2 is not set # CONFIG_PACKAGE_kmod-ipt-logmark is not set # CONFIG_PACKAGE_kmod-ipt-lscan is not set # CONFIG_PACKAGE_kmod-ipt-lua is not set CONFIG_PACKAGE_kmod-ipt-nat=y # CONFIG_PACKAGE_kmod-ipt-nat-extra is not set # CONFIG_PACKAGE_kmod-ipt-nat6 is not set # CONFIG_PACKAGE_kmod-ipt-nathelper-rtsp is not set # CONFIG_PACKAGE_kmod-ipt-nflog is not set # CONFIG_PACKAGE_kmod-ipt-nfqueue is not set CONFIG_PACKAGE_kmod-ipt-offload=y # CONFIG_PACKAGE_kmod-ipt-physdev is not set # CONFIG_PACKAGE_kmod-ipt-proto is not set # CONFIG_PACKAGE_kmod-ipt-psd is not set # CONFIG_PACKAGE_kmod-ipt-quota2 is not set CONFIG_PACKAGE_kmod-ipt-raw=y # CONFIG_PACKAGE_kmod-ipt-raw6 is not set # CONFIG_PACKAGE_kmod-ipt-rpfilter is not set # CONFIG_PACKAGE_kmod-ipt-rtpengine is not set # CONFIG_PACKAGE_kmod-ipt-sysrq is not set # CONFIG_PACKAGE_kmod-ipt-tarpit is not set # CONFIG_PACKAGE_kmod-ipt-tee is not set CONFIG_PACKAGE_kmod-ipt-tproxy=y # CONFIG_PACKAGE_kmod-ipt-u32 is not set # CONFIG_PACKAGE_kmod-ipt-ulog is not set # CONFIG_PACKAGE_kmod-netatop is not set CONFIG_PACKAGE_kmod-nf-conntrack=y # CONFIG_PACKAGE_kmod-nf-conntrack-netlink is not set CONFIG_PACKAGE_kmod-nf-conntrack6=y CONFIG_PACKAGE_kmod-nf-flow=y CONFIG_PACKAGE_kmod-nf-ipt=y CONFIG_PACKAGE_kmod-nf-ipt6=y # CONFIG_PACKAGE_kmod-nf-ipvs is not set CONFIG_PACKAGE_kmod-nf-nat=y # CONFIG_PACKAGE_kmod-nf-nat6 is not set CONFIG_PACKAGE_kmod-nf-nathelper=y CONFIG_PACKAGE_kmod-nf-nathelper-extra=y CONFIG_PACKAGE_kmod-nf-reject=y CONFIG_PACKAGE_kmod-nf-reject6=y CONFIG_PACKAGE_kmod-nfnetlink=y # CONFIG_PACKAGE_kmod-nfnetlink-log is not set # CONFIG_PACKAGE_kmod-nfnetlink-queue is not set # CONFIG_PACKAGE_kmod-nft-arp is not set # CONFIG_PACKAGE_kmod-nft-bridge is not set # CONFIG_PACKAGE_kmod-nft-core is not set # CONFIG_PACKAGE_kmod-nft-fib is not set # CONFIG_PACKAGE_kmod-nft-nat is not set # CONFIG_PACKAGE_kmod-nft-nat6 is not set # CONFIG_PACKAGE_kmod-nft-netdev is not set # CONFIG_PACKAGE_kmod-nft-offload is not set # CONFIG_PACKAGE_kmod-nft-queue is not set # end of Netfilter Extensions # # Network Devices # # CONFIG_PACKAGE_kmod-3c59x is not set # CONFIG_PACKAGE_kmod-8139cp is not set # CONFIG_PACKAGE_kmod-8139too is not set # CONFIG_PACKAGE_kmod-alx is not set # CONFIG_PACKAGE_kmod-atl1 is not set # CONFIG_PACKAGE_kmod-atl1c is not set # CONFIG_PACKAGE_kmod-atl1e is not set # CONFIG_PACKAGE_kmod-atl2 is not set # CONFIG_PACKAGE_kmod-b44 is not set # CONFIG_PACKAGE_kmod-be2net is not set # CONFIG_PACKAGE_kmod-bnx2 is not set # CONFIG_PACKAGE_kmod-bnx2x is not set # CONFIG_PACKAGE_kmod-dm9000 is not set # CONFIG_PACKAGE_kmod-dummy is not set # CONFIG_PACKAGE_kmod-e100 is not set # CONFIG_PACKAGE_kmod-e1000 is not set # CONFIG_PACKAGE_kmod-et131x is not set # CONFIG_PACKAGE_kmod-ethoc is not set # CONFIG_PACKAGE_kmod-forcedeth is not set # CONFIG_PACKAGE_kmod-hfcmulti is not set # CONFIG_PACKAGE_kmod-hfcpci is not set # CONFIG_PACKAGE_kmod-i40e is not set # CONFIG_PACKAGE_kmod-iavf is not set # CONFIG_PACKAGE_kmod-ifb is not set # CONFIG_PACKAGE_kmod-igb is not set # CONFIG_PACKAGE_kmod-igc is not set # CONFIG_PACKAGE_kmod-ipvlan is not set # CONFIG_PACKAGE_kmod-ixgbe is not set # CONFIG_PACKAGE_kmod-ixgbevf is not set # CONFIG_PACKAGE_kmod-libphy is not set CONFIG_PACKAGE_kmod-macvlan=y # CONFIG_PACKAGE_kmod-mdio-gpio is not set # CONFIG_PACKAGE_kmod-mii is not set # CONFIG_PACKAGE_kmod-mlx4-core is not set # CONFIG_PACKAGE_kmod-mlx5-core is not set # CONFIG_PACKAGE_kmod-natsemi is not set # CONFIG_PACKAGE_kmod-ne2k-pci is not set # CONFIG_PACKAGE_kmod-niu is not set # CONFIG_PACKAGE_kmod-of-mdio is not set # CONFIG_PACKAGE_kmod-pcnet32 is not set # CONFIG_PACKAGE_kmod-phy-bcm84881 is not set # CONFIG_PACKAGE_kmod-phy-broadcom is not set # CONFIG_PACKAGE_kmod-phy-realtek is not set # CONFIG_PACKAGE_kmod-phylink is not set # CONFIG_PACKAGE_kmod-qlcnic is not set # CONFIG_PACKAGE_kmod-r6040 is not set # CONFIG_PACKAGE_kmod-r8125 is not set # CONFIG_PACKAGE_kmod-r8168 is not set # CONFIG_PACKAGE_kmod-r8169 is not set # CONFIG_PACKAGE_kmod-sfc is not set # CONFIG_PACKAGE_kmod-sfc-falcon is not set # CONFIG_PACKAGE_kmod-sfp is not set # CONFIG_PACKAGE_kmod-siit is not set # CONFIG_PACKAGE_kmod-sis190 is not set # CONFIG_PACKAGE_kmod-sis900 is not set # CONFIG_PACKAGE_kmod-skge is not set # CONFIG_PACKAGE_kmod-sky2 is not set # CONFIG_PACKAGE_kmod-solos-pci is not set # CONFIG_PACKAGE_kmod-spi-ks8995 is not set # CONFIG_PACKAGE_kmod-swconfig is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx-mdio is not set # CONFIG_PACKAGE_kmod-switch-ip17xx is not set # CONFIG_PACKAGE_kmod-switch-rtl8306 is not set # CONFIG_PACKAGE_kmod-switch-rtl8366-smi is not set # CONFIG_PACKAGE_kmod-switch-rtl8366rb is not set # CONFIG_PACKAGE_kmod-switch-rtl8366s is not set # CONFIG_PACKAGE_kmod-switch-rtl8367b is not set # CONFIG_PACKAGE_kmod-tg3 is not set # CONFIG_PACKAGE_kmod-tulip is not set # CONFIG_PACKAGE_kmod-via-rhine is not set # CONFIG_PACKAGE_kmod-via-velocity is not set # CONFIG_PACKAGE_kmod-vmxnet3 is not set # end of Network Devices # # Network Support # # CONFIG_PACKAGE_kmod-atm is not set # CONFIG_PACKAGE_kmod-ax25 is not set # CONFIG_PACKAGE_kmod-batman-adv is not set # CONFIG_PACKAGE_kmod-bonding is not set # CONFIG_PACKAGE_kmod-bpf-test is not set # CONFIG_PACKAGE_kmod-dnsresolver is not set # CONFIG_PACKAGE_kmod-fast-classifier is not set # CONFIG_PACKAGE_kmod-fast-classifier-noload is not set # CONFIG_PACKAGE_kmod-fou is not set # CONFIG_PACKAGE_kmod-fou6 is not set # CONFIG_PACKAGE_kmod-geneve is not set # CONFIG_PACKAGE_kmod-gre is not set # CONFIG_PACKAGE_kmod-gre6 is not set # CONFIG_PACKAGE_kmod-ip6-tunnel is not set # CONFIG_PACKAGE_kmod-ipip is not set # CONFIG_PACKAGE_kmod-ipsec is not set # CONFIG_PACKAGE_kmod-iptunnel6 is not set # CONFIG_PACKAGE_kmod-isdn4linux is not set # CONFIG_PACKAGE_kmod-jool is not set # CONFIG_PACKAGE_kmod-l2tp is not set # CONFIG_PACKAGE_kmod-l2tp-eth is not set # CONFIG_PACKAGE_kmod-l2tp-ip is not set # CONFIG_PACKAGE_kmod-macremapper is not set # CONFIG_PACKAGE_kmod-macsec is not set # CONFIG_PACKAGE_kmod-misdn is not set # CONFIG_PACKAGE_kmod-mpls is not set # CONFIG_PACKAGE_kmod-nat46 is not set # CONFIG_PACKAGE_kmod-netem is not set # CONFIG_PACKAGE_kmod-netlink-diag is not set # CONFIG_PACKAGE_kmod-nlmon is not set # CONFIG_PACKAGE_kmod-nsh is not set # CONFIG_PACKAGE_kmod-openvswitch is not set # CONFIG_PACKAGE_kmod-openvswitch-geneve is not set # CONFIG_PACKAGE_kmod-openvswitch-gre is not set # CONFIG_PACKAGE_kmod-openvswitch-vxlan is not set # CONFIG_PACKAGE_kmod-pf-ring is not set # CONFIG_PACKAGE_kmod-pktgen is not set CONFIG_PACKAGE_kmod-ppp=y CONFIG_PACKAGE_kmod-mppe=y # CONFIG_PACKAGE_kmod-ppp-synctty is not set # CONFIG_PACKAGE_kmod-pppoa is not set CONFIG_PACKAGE_kmod-pppoe=y # CONFIG_PACKAGE_kmod-pppol2tp is not set CONFIG_PACKAGE_kmod-pppox=y # CONFIG_PACKAGE_kmod-pptp is not set # CONFIG_PACKAGE_kmod-qca-nss-ecm-noload is not set # CONFIG_PACKAGE_kmod-qca-nss-ecm-premium is not set # CONFIG_PACKAGE_kmod-qca-nss-ecm-premium-noload is not set # CONFIG_PACKAGE_kmod-qca-nss-ecm-standard is not set # CONFIG_PACKAGE_kmod-sched is not set # CONFIG_PACKAGE_kmod-sched-act-vlan is not set # CONFIG_PACKAGE_kmod-sched-bpf is not set # CONFIG_PACKAGE_kmod-sched-cake is not set # CONFIG_PACKAGE_kmod-sched-connmark is not set # CONFIG_PACKAGE_kmod-sched-core is not set # CONFIG_PACKAGE_kmod-sched-ctinfo is not set # CONFIG_PACKAGE_kmod-sched-flower is not set # CONFIG_PACKAGE_kmod-sched-ipset is not set # CONFIG_PACKAGE_kmod-sched-mqprio is not set # CONFIG_PACKAGE_kmod-sctp is not set # CONFIG_PACKAGE_kmod-shortcut-fe is not set # CONFIG_PACKAGE_kmod-shortcut-fe-cm is not set # CONFIG_PACKAGE_kmod-sit is not set CONFIG_PACKAGE_kmod-slhc=y # CONFIG_PACKAGE_kmod-slip is not set CONFIG_PACKAGE_kmod-tcp-bbr=y # CONFIG_PACKAGE_kmod-tcp-hybla is not set # CONFIG_PACKAGE_kmod-trelay is not set CONFIG_PACKAGE_kmod-tun=y # CONFIG_PACKAGE_kmod-veth is not set # CONFIG_PACKAGE_kmod-vxlan is not set # CONFIG_PACKAGE_kmod-wireguard is not set # end of Network Support # # Other modules # # CONFIG_PACKAGE_kmod-6lowpan is not set # CONFIG_PACKAGE_kmod-ath3k is not set # CONFIG_PACKAGE_kmod-bcma is not set # CONFIG_PACKAGE_kmod-bluetooth is not set # CONFIG_PACKAGE_kmod-bluetooth-6lowpan is not set # CONFIG_PACKAGE_kmod-btmrvl is not set # CONFIG_PACKAGE_kmod-button-hotplug is not set # CONFIG_PACKAGE_kmod-dma-ralink is not set # CONFIG_PACKAGE_kmod-echo is not set # CONFIG_PACKAGE_kmod-eeprom-93cx6 is not set # CONFIG_PACKAGE_kmod-eeprom-at24 is not set # CONFIG_PACKAGE_kmod-eeprom-at25 is not set # CONFIG_PACKAGE_kmod-gpio-beeper is not set CONFIG_PACKAGE_kmod-gpio-button-hotplug=y # CONFIG_PACKAGE_kmod-gpio-dev is not set # CONFIG_PACKAGE_kmod-gpio-mcp23s08 is not set # CONFIG_PACKAGE_kmod-gpio-nxp-74hc164 is not set # CONFIG_PACKAGE_kmod-gpio-pca953x is not set # CONFIG_PACKAGE_kmod-gpio-pcf857x is not set # CONFIG_PACKAGE_kmod-hsdma-mtk is not set # CONFIG_PACKAGE_kmod-ikconfig is not set # CONFIG_PACKAGE_kmod-it87-wdt is not set # CONFIG_PACKAGE_kmod-itco-wdt is not set # CONFIG_PACKAGE_kmod-keys-encrypted is not set # CONFIG_PACKAGE_kmod-keys-trusted is not set # CONFIG_PACKAGE_kmod-lp is not set # CONFIG_PACKAGE_kmod-mmc is not set # CONFIG_PACKAGE_kmod-mtd-rw is not set # CONFIG_PACKAGE_kmod-mtdoops is not set # CONFIG_PACKAGE_kmod-mtdram is not set # CONFIG_PACKAGE_kmod-mtdtests is not set # CONFIG_PACKAGE_kmod-parport-pc is not set # CONFIG_PACKAGE_kmod-ppdev is not set # CONFIG_PACKAGE_kmod-pps is not set # CONFIG_PACKAGE_kmod-pps-gpio is not set # CONFIG_PACKAGE_kmod-pps-ldisc is not set # CONFIG_PACKAGE_kmod-ptp is not set # CONFIG_PACKAGE_kmod-random-core is not set # CONFIG_PACKAGE_kmod-rtc-ds1307 is not set # CONFIG_PACKAGE_kmod-rtc-ds1374 is not set # CONFIG_PACKAGE_kmod-rtc-ds1672 is not set # CONFIG_PACKAGE_kmod-rtc-em3027 is not set # CONFIG_PACKAGE_kmod-rtc-isl1208 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2123 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2127 is not set # CONFIG_PACKAGE_kmod-rtc-pcf8563 is not set # CONFIG_PACKAGE_kmod-rtc-pt7c4338 is not set # CONFIG_PACKAGE_kmod-rtc-rs5c372a is not set # CONFIG_PACKAGE_kmod-rtc-rx8025 is not set # CONFIG_PACKAGE_kmod-rtc-s35390a is not set # CONFIG_PACKAGE_kmod-sdhci is not set # CONFIG_PACKAGE_kmod-sdhci-mt7620 is not set # CONFIG_PACKAGE_kmod-serial-8250 is not set # CONFIG_PACKAGE_kmod-serial-8250-exar is not set # CONFIG_PACKAGE_kmod-softdog is not set # CONFIG_PACKAGE_kmod-ssb is not set # CONFIG_PACKAGE_kmod-tpm is not set # CONFIG_PACKAGE_kmod-tpm-i2c-atmel is not set # CONFIG_PACKAGE_kmod-tpm-i2c-infineon is not set # CONFIG_PACKAGE_kmod-w83627hf-wdt is not set # CONFIG_PACKAGE_kmod-zram is not set # end of Other modules # # PCMCIA support # # end of PCMCIA support # # SPI Support # # CONFIG_PACKAGE_kmod-mmc-spi is not set # CONFIG_PACKAGE_kmod-spi-bitbang is not set # CONFIG_PACKAGE_kmod-spi-dev is not set # CONFIG_PACKAGE_kmod-spi-gpio is not set # end of SPI Support # # Sound Support # # CONFIG_PACKAGE_kmod-sound-core is not set # end of Sound Support # # USB Support # # CONFIG_PACKAGE_kmod-chaoskey is not set # CONFIG_PACKAGE_kmod-usb-acm is not set # CONFIG_PACKAGE_kmod-usb-atm is not set # CONFIG_PACKAGE_kmod-usb-cm109 is not set CONFIG_PACKAGE_kmod-usb-core=y # CONFIG_PACKAGE_kmod-usb-dwc2 is not set # CONFIG_PACKAGE_kmod-usb-dwc3 is not set CONFIG_PACKAGE_kmod-usb-ehci=y # CONFIG_PACKAGE_kmod-usb-hid is not set # CONFIG_PACKAGE_kmod-usb-hid-cp2112 is not set # CONFIG_PACKAGE_kmod-usb-ledtrig-usbport is not set # CONFIG_PACKAGE_kmod-usb-net is not set # CONFIG_PACKAGE_kmod-usb-net-aqc111 is not set # CONFIG_PACKAGE_kmod-usb-net-asix is not set # CONFIG_PACKAGE_kmod-usb-net-asix-ax88179 is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-eem is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-ether is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-mbim is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-ncm is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-subset is not set # CONFIG_PACKAGE_kmod-usb-net-dm9601-ether is not set # CONFIG_PACKAGE_kmod-usb-net-hso is not set # CONFIG_PACKAGE_kmod-usb-net-huawei-cdc-ncm is not set # CONFIG_PACKAGE_kmod-usb-net-ipheth is not set # CONFIG_PACKAGE_kmod-usb-net-kalmia is not set # CONFIG_PACKAGE_kmod-usb-net-kaweth is not set # CONFIG_PACKAGE_kmod-usb-net-mcs7830 is not set # CONFIG_PACKAGE_kmod-usb-net-pegasus is not set # CONFIG_PACKAGE_kmod-usb-net-pl is not set # CONFIG_PACKAGE_kmod-usb-net-qmi-wwan is not set # CONFIG_PACKAGE_kmod-usb-net-rndis is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8150 is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8152 is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8152-vendor is not set # CONFIG_PACKAGE_kmod-usb-net-sierrawireless is not set # CONFIG_PACKAGE_kmod-usb-net-smsc95xx is not set # CONFIG_PACKAGE_kmod-usb-net-sr9700 is not set # CONFIG_PACKAGE_kmod-usb-ohci is not set # CONFIG_PACKAGE_kmod-usb-ohci-pci is not set # CONFIG_PACKAGE_kmod-usb-printer is not set # CONFIG_PACKAGE_kmod-usb-serial is not set # CONFIG_PACKAGE_kmod-usb-serial-ark3116 is not set # CONFIG_PACKAGE_kmod-usb-serial-belkin is not set # CONFIG_PACKAGE_kmod-usb-serial-ch341 is not set # CONFIG_PACKAGE_kmod-usb-serial-cp210x is not set # CONFIG_PACKAGE_kmod-usb-serial-cypress-m8 is not set # CONFIG_PACKAGE_kmod-usb-serial-edgeport is not set # CONFIG_PACKAGE_kmod-usb-serial-ftdi is not set # CONFIG_PACKAGE_kmod-usb-serial-garmin is not set # CONFIG_PACKAGE_kmod-usb-serial-ipw is not set # CONFIG_PACKAGE_kmod-usb-serial-keyspan is not set # CONFIG_PACKAGE_kmod-usb-serial-mct is not set # CONFIG_PACKAGE_kmod-usb-serial-mos7720 is not set # CONFIG_PACKAGE_kmod-usb-serial-mos7840 is not set # CONFIG_PACKAGE_kmod-usb-serial-option is not set # CONFIG_PACKAGE_kmod-usb-serial-oti6858 is not set # CONFIG_PACKAGE_kmod-usb-serial-pl2303 is not set # CONFIG_PACKAGE_kmod-usb-serial-qualcomm is not set # CONFIG_PACKAGE_kmod-usb-serial-sierrawireless is not set # CONFIG_PACKAGE_kmod-usb-serial-simple is not set # CONFIG_PACKAGE_kmod-usb-serial-ti-usb is not set # CONFIG_PACKAGE_kmod-usb-serial-visor is not set CONFIG_PACKAGE_kmod-usb-storage=y CONFIG_PACKAGE_kmod-usb-storage-extras=y # CONFIG_PACKAGE_kmod-usb-storage-uas is not set # CONFIG_PACKAGE_kmod-usb-uhci is not set # CONFIG_PACKAGE_kmod-usb-wdm is not set CONFIG_PACKAGE_kmod-usb-xhci-hcd=y CONFIG_PACKAGE_kmod-usb-xhci-mtk=y # CONFIG_PACKAGE_kmod-usb-yealink is not set CONFIG_PACKAGE_kmod-usb2=y # CONFIG_PACKAGE_kmod-usb2-pci is not set CONFIG_PACKAGE_kmod-usb3=y # CONFIG_PACKAGE_kmod-usbip is not set # CONFIG_PACKAGE_kmod-usbip-client is not set # CONFIG_PACKAGE_kmod-usbip-server is not set # CONFIG_PACKAGE_kmod-usbmon is not set # end of USB Support # # Video Support # # CONFIG_PACKAGE_kmod-multimedia-input is not set # CONFIG_PACKAGE_kmod-video-core is not set # end of Video Support # # Virtualization # # end of Virtualization # # Voice over IP # # CONFIG_PACKAGE_kmod-dahdi is not set # end of Voice over IP # # W1 support # # CONFIG_PACKAGE_kmod-w1 is not set # end of W1 support # # WPAN 802.15.4 Support # # CONFIG_PACKAGE_kmod-at86rf230 is not set # CONFIG_PACKAGE_kmod-atusb is not set # CONFIG_PACKAGE_kmod-ca8210 is not set # CONFIG_PACKAGE_kmod-cc2520 is not set # CONFIG_PACKAGE_kmod-fakelb is not set # CONFIG_PACKAGE_kmod-ieee802154 is not set # CONFIG_PACKAGE_kmod-ieee802154-6lowpan is not set # CONFIG_PACKAGE_kmod-mac802154 is not set # CONFIG_PACKAGE_kmod-mrf24j40 is not set # end of WPAN 802.15.4 Support # # Wireless Drivers # # CONFIG_PACKAGE_kmod-acx-mac80211 is not set # CONFIG_PACKAGE_kmod-adm8211 is not set # CONFIG_PACKAGE_kmod-ar5523 is not set # CONFIG_PACKAGE_kmod-ath is not set # CONFIG_PACKAGE_kmod-ath10k is not set # CONFIG_PACKAGE_kmod-ath10k-ct is not set # CONFIG_PACKAGE_kmod-ath10k-ct-smallbuffers is not set # CONFIG_PACKAGE_kmod-ath11k is not set # CONFIG_PACKAGE_kmod-ath5k is not set # CONFIG_PACKAGE_kmod-ath6kl-sdio is not set # CONFIG_PACKAGE_kmod-ath6kl-usb is not set # CONFIG_PACKAGE_kmod-ath9k is not set # CONFIG_PACKAGE_kmod-ath9k-htc is not set # CONFIG_PACKAGE_kmod-b43 is not set # CONFIG_PACKAGE_kmod-b43legacy is not set # CONFIG_PACKAGE_kmod-brcmfmac is not set # CONFIG_PACKAGE_kmod-brcmsmac is not set # CONFIG_PACKAGE_kmod-brcmutil is not set # CONFIG_PACKAGE_kmod-carl9170 is not set # CONFIG_PACKAGE_kmod-cfg80211 is not set # CONFIG_PACKAGE_kmod-hermes is not set # CONFIG_PACKAGE_kmod-hermes-pci is not set # CONFIG_PACKAGE_kmod-hermes-plx is not set # CONFIG_PACKAGE_kmod-ipw2100 is not set # CONFIG_PACKAGE_kmod-ipw2200 is not set # CONFIG_PACKAGE_kmod-iwl-legacy is not set # CONFIG_PACKAGE_kmod-iwl3945 is not set # CONFIG_PACKAGE_kmod-iwl4965 is not set # CONFIG_PACKAGE_kmod-iwlwifi is not set # CONFIG_PACKAGE_kmod-lib80211 is not set # CONFIG_PACKAGE_kmod-libertas-sdio is not set # CONFIG_PACKAGE_kmod-libertas-spi is not set # CONFIG_PACKAGE_kmod-libertas-usb is not set # CONFIG_PACKAGE_kmod-libipw is not set # CONFIG_PACKAGE_kmod-mac80211 is not set # CONFIG_PACKAGE_kmod-mac80211-hwsim is not set # CONFIG_PACKAGE_kmod-mt76 is not set # CONFIG_PACKAGE_kmod-mt7601u is not set # CONFIG_PACKAGE_kmod-mt7603 is not set # CONFIG_PACKAGE_kmod-mt7603e is not set # CONFIG_PACKAGE_kmod-mt7615-firmware is not set CONFIG_PACKAGE_kmod-mt7615d=y CONFIG_MTK_SUPPORT_OPENWRT=y CONFIG_MTK_WIFI_DRIVER=y CONFIG_MTK_FIRST_IF_MT7615E=y # CONFIG_MTK_FIRST_IF_MT7622 is not set # CONFIG_MTK_FIRST_IF_MT7626 is not set # CONFIG_MTK_FIRST_IF_NONE is not set # CONFIG_MTK_SECOND_IF_NONE is not set CONFIG_MTK_SECOND_IF_MT7615E=y CONFIG_MTK_THIRD_IF_NONE=y # CONFIG_MTK_THIRD_IF_MT7615E is not set CONFIG_MTK_RT_FIRST_CARD=7615 CONFIG_MTK_RT_SECOND_CARD=7615 CONFIG_MTK_RT_FIRST_IF_RF_OFFSET=0xc0000 CONFIG_MTK_RT_SECOND_IF_RF_OFFSET=0xc8000 CONFIG_MTK_MT_WIFI=y CONFIG_MTK_MT_WIFI_PATH="mt_wifi" # # WiFi Generic Feature Options # CONFIG_MTK_FIRST_IF_EEPROM_FLASH=y # CONFIG_MTK_FIRST_IF_EEPROM_PROM is not set # CONFIG_MTK_FIRST_IF_EEPROM_EFUSE is not set CONFIG_MTK_RT_FIRST_CARD_EEPROM="flash" CONFIG_MTK_SECOND_IF_EEPROM_FLASH=y # CONFIG_MTK_SECOND_IF_EEPROM_PROM is not set # CONFIG_MTK_SECOND_IF_EEPROM_EFUSE is not set CONFIG_MTK_RT_SECOND_CARD_EEPROM="flash" CONFIG_MTK_MULTI_INF_SUPPORT=y CONFIG_MTK_WIFI_BASIC_FUNC=y CONFIG_MTK_DOT11_N_SUPPORT=y CONFIG_MTK_DOT11_VHT_AC=y CONFIG_MTK_G_BAND_256QAM_SUPPORT=y CONFIG_MTK_BRCM_256QAM_SUPPORT=y CONFIG_MTK_VHT_TXBF_2G_EPIGRAM_IE_SUPPORT=y CONFIG_MTK_TPC_SUPPORT=y CONFIG_MTK_ICAP_SUPPORT=y CONFIG_MTK_SPECTRUM_SUPPORT=y CONFIG_MTK_BACKGROUND_SCAN_SUPPORT=y CONFIG_MTK_SMART_CARRIER_SENSE_SUPPORT=y CONFIG_MTK_MT_DFS_SUPPORT=y CONFIG_MTK_HDR_TRANS_TX_SUPPORT=y CONFIG_MTK_HDR_TRANS_RX_SUPPORT=y CONFIG_MTK_DBDC_MODE=y CONFIG_MTK_MULTI_PROFILE_SUPPORT=y CONFIG_MTK_WSC_INCLUDED=y CONFIG_MTK_WSC_V2_SUPPORT=y CONFIG_MTK_DOT11W_PMF_SUPPORT=y CONFIG_MTK_TXBF_SUPPORT=y # CONFIG_MTK_FAST_NAT_SUPPORT is not set # CONFIG_MTK_FTM_SUPPORT is not set CONFIG_MTK_IGMP_SNOOP_SUPPORT=y CONFIG_MTK_RTMP_FLASH_SUPPORT=y CONFIG_MTK_PRE_CAL_TRX_SET1_SUPPORT=y CONFIG_MTK_RLM_CAL_CACHE_SUPPORT=y CONFIG_MTK_PRE_CAL_TRX_SET2_SUPPORT=y # CONFIG_MTK_RF_LOCKDOWN_SUPPORT is not set # CONFIG_MTK_LINK_TEST_SUPPORT is not set CONFIG_MTK_ATE_SUPPORT=y # CONFIG_MTK_PASSPOINT_R2 is not set # CONFIG_MTK_MBO_SUPPORT is not set CONFIG_MTK_UAPSD=y CONFIG_MTK_TCP_RACK_SUPPORT=y CONFIG_MTK_RED_SUPPORT=y # CONFIG_MTK_FDB_SUPPORT is not set CONFIG_MTK_FIRST_IF_IPAILNA=y # CONFIG_MTK_FIRST_IF_IPAELNA is not set # CONFIG_MTK_FIRST_IF_EPAELNA is not set CONFIG_MTK_SECOND_IF_IPAILNA=y # CONFIG_MTK_SECOND_IF_IPAELNA is not set # CONFIG_MTK_SECOND_IF_EPAELNA is not set # CONFIG_MTK_RLT_MAC is not set # CONFIG_MTK_RTMP_MAC is not set # end of WiFi Generic Feature Options # # WiFi Operation Modes # CONFIG_MTK_WIFI_MODE_AP=y # CONFIG_MTK_WIFI_MODE_STA is not set # CONFIG_MTK_WIFI_MODE_BOTH is not set CONFIG_MTK_MT_AP_SUPPORT=y CONFIG_MTK_WDS_SUPPORT=y CONFIG_MTK_MBSS_SUPPORT=y CONFIG_MTK_APCLI_SUPPORT=y # CONFIG_MTK_APCLI_CERT_SUPPORT is not set CONFIG_MTK_MAC_REPEATER_SUPPORT=y # CONFIG_MTK_MWDS is not set CONFIG_MTK_MUMIMO_SUPPORT=y CONFIG_MTK_MU_RA_SUPPORT=y # CONFIG_MTK_DOT11R_FT_SUPPORT is not set # CONFIG_MTK_DOT11K_RRM_SUPPORT is not set # CONFIG_MTK_CFG80211_SUPPORT is not set # CONFIG_MTK_DSCP_PRI_SUPPORT is not set # CONFIG_MTK_CON_WPS_SUPPORT is not set CONFIG_MTK_MCAST_RATE_SPECIFIC=y CONFIG_MTK_VOW_SUPPORT=y CONFIG_MTK_BAND_STEERING=y CONFIG_MTK_LED_CONTROL_SUPPORT=y # CONFIG_MTK_WLAN_HOOK is not set # CONFIG_MTK_RADIUS_ACCOUNTING_SUPPORT is not set # CONFIG_MTK_GREENAP_SUPPORT is not set CONFIG_MTK_PCIE_ASPM_DYM_CTRL_SUPPORT=y # CONFIG_MTK_COEX_SUPPORT is not set # CONFIG_MTK_EASY_SETUP_SUPPORT is not set # CONFIG_MTK_EVENT_NOTIFIER_SUPPORT is not set # CONFIG_MTK_AIR_MONITOR is not set # CONFIG_MTK_WNM_SUPPORT is not set # CONFIG_MTK_INTERWORKING is not set CONFIG_MTK_LINUX_NET_TXQ_SUPPORT=y # end of WiFi Operation Modes CONFIG_MTK_WIFI_MT_MAC=y CONFIG_MTK_MT_MAC=y # CONFIG_MTK_CHIP_MT7603E is not set CONFIG_MTK_CHIP_MT7615E=y # CONFIG_MTK_CHIP_MT7622 is not set # CONFIG_MTK_CHIP_MT7663E is not set # CONFIG_MTK_CHIP_MT7626 is not set CONFIG_PACKAGE_kmod-mt7615d_dbdc=y # CONFIG_PACKAGE_kmod-mt7615e is not set # CONFIG_PACKAGE_kmod-mt7663-firmware-ap is not set # CONFIG_PACKAGE_kmod-mt7663-firmware-sta is not set # CONFIG_PACKAGE_kmod-mt7663s is not set # CONFIG_PACKAGE_kmod-mt7663u is not set # CONFIG_PACKAGE_kmod-mt76x0e is not set # CONFIG_PACKAGE_kmod-mt76x0u is not set # CONFIG_PACKAGE_kmod-mt76x2 is not set # CONFIG_PACKAGE_kmod-mt76x2e is not set # CONFIG_PACKAGE_kmod-mt76x2u is not set # CONFIG_PACKAGE_kmod-mt7915e is not set # CONFIG_PACKAGE_kmod-mt7921e is not set # CONFIG_PACKAGE_kmod-mwifiex-pcie is not set # CONFIG_PACKAGE_kmod-mwifiex-sdio is not set # CONFIG_PACKAGE_kmod-mwl8k is not set # CONFIG_PACKAGE_kmod-net-prism54 is not set # CONFIG_PACKAGE_kmod-net-rtl8192su is not set # CONFIG_PACKAGE_kmod-owl-loader is not set # CONFIG_PACKAGE_kmod-p54-common is not set # CONFIG_PACKAGE_kmod-p54-pci is not set # CONFIG_PACKAGE_kmod-p54-usb is not set # CONFIG_PACKAGE_kmod-qtn-pcie2 is not set # CONFIG_PACKAGE_kmod-rsi91x is not set # CONFIG_PACKAGE_kmod-rsi91x-sdio is not set # CONFIG_PACKAGE_kmod-rsi91x-usb is not set # CONFIG_PACKAGE_kmod-rt2400-pci is not set # CONFIG_PACKAGE_kmod-rt2500-pci is not set # CONFIG_PACKAGE_kmod-rt2500-usb is not set # CONFIG_PACKAGE_kmod-rt2800-pci is not set # CONFIG_PACKAGE_kmod-rt2800-usb is not set # CONFIG_PACKAGE_kmod-rt2x00-lib is not set # CONFIG_PACKAGE_kmod-rt61-pci is not set # CONFIG_PACKAGE_kmod-rt73-usb is not set # CONFIG_PACKAGE_kmod-rtl8180 is not set # CONFIG_PACKAGE_kmod-rtl8187 is not set # CONFIG_PACKAGE_kmod-rtl8192ce is not set # CONFIG_PACKAGE_kmod-rtl8192cu is not set # CONFIG_PACKAGE_kmod-rtl8192de is not set # CONFIG_PACKAGE_kmod-rtl8192se is not set # CONFIG_PACKAGE_kmod-rtl8723bs is not set # CONFIG_PACKAGE_kmod-rtl8812au-ct is not set # CONFIG_PACKAGE_kmod-rtl8821ae is not set # CONFIG_PACKAGE_kmod-rtl8xxxu is not set # CONFIG_PACKAGE_kmod-rtw88 is not set # CONFIG_PACKAGE_kmod-wil6210 is not set # CONFIG_PACKAGE_kmod-wl12xx is not set # CONFIG_PACKAGE_kmod-wl18xx is not set # CONFIG_PACKAGE_kmod-wlcore is not set # CONFIG_PACKAGE_kmod-zd1211rw is not set # end of Wireless Drivers # end of Kernel modules # # Languages # # # Erlang # # CONFIG_PACKAGE_erlang is not set # CONFIG_PACKAGE_erlang-asn1 is not set # CONFIG_PACKAGE_erlang-compiler is not set # CONFIG_PACKAGE_erlang-crypto is not set # CONFIG_PACKAGE_erlang-erl-interface is not set # CONFIG_PACKAGE_erlang-hipe is not set # CONFIG_PACKAGE_erlang-inets is not set # CONFIG_PACKAGE_erlang-mnesia is not set # CONFIG_PACKAGE_erlang-os_mon is not set # CONFIG_PACKAGE_erlang-public-key is not set # CONFIG_PACKAGE_erlang-reltool is not set # CONFIG_PACKAGE_erlang-runtime-tools is not set # CONFIG_PACKAGE_erlang-snmp is not set # CONFIG_PACKAGE_erlang-ssh is not set # CONFIG_PACKAGE_erlang-ssl is not set # CONFIG_PACKAGE_erlang-syntax-tools is not set # CONFIG_PACKAGE_erlang-tools is not set # CONFIG_PACKAGE_erlang-xmerl is not set # end of Erlang # # Go # # CONFIG_PACKAGE_golang is not set # # Configuration # CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT="" CONFIG_GOLANG_BUILD_CACHE_DIR="" # CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE is not set # end of Configuration # CONFIG_PACKAGE_golang-doc is not set # CONFIG_PACKAGE_golang-github-jedisct1-dnscrypt-proxy2-dev is not set # CONFIG_PACKAGE_golang-github-nextdns-nextdns-dev is not set # CONFIG_PACKAGE_golang-gitlab-yawning-obfs4-dev is not set # CONFIG_PACKAGE_golang-src is not set # CONFIG_PACKAGE_golang-torproject-tor-fw-helper-dev is not set # end of Go # # Lua # # CONFIG_PACKAGE_dkjson is not set # CONFIG_PACKAGE_json4lua is not set # CONFIG_PACKAGE_ldbus is not set CONFIG_PACKAGE_libiwinfo-lua=y # CONFIG_PACKAGE_linotify is not set # CONFIG_PACKAGE_lpeg is not set # CONFIG_PACKAGE_lsqlite3 is not set CONFIG_PACKAGE_lua=y # CONFIG_PACKAGE_lua-argparse is not set # CONFIG_PACKAGE_lua-bencode is not set # CONFIG_PACKAGE_lua-bit32 is not set # CONFIG_PACKAGE_lua-cjson is not set # CONFIG_PACKAGE_lua-copas is not set # CONFIG_PACKAGE_lua-coxpcall is not set # CONFIG_PACKAGE_lua-ev is not set # CONFIG_PACKAGE_lua-examples is not set # CONFIG_PACKAGE_lua-libmodbus is not set # CONFIG_PACKAGE_lua-lzlib is not set # CONFIG_PACKAGE_lua-md5 is not set # CONFIG_PACKAGE_lua-mobdebug is not set # CONFIG_PACKAGE_lua-mosquitto is not set # CONFIG_PACKAGE_lua-openssl is not set # CONFIG_PACKAGE_lua-penlight is not set # CONFIG_PACKAGE_lua-rings is not set # CONFIG_PACKAGE_lua-rs232 is not set # CONFIG_PACKAGE_lua-sha2 is not set # CONFIG_PACKAGE_lua-wsapi-base is not set # CONFIG_PACKAGE_lua-wsapi-xavante is not set # CONFIG_PACKAGE_lua-xavante is not set # CONFIG_PACKAGE_lua5.3 is not set # CONFIG_PACKAGE_luabitop is not set # CONFIG_PACKAGE_luac is not set # CONFIG_PACKAGE_luac5.3 is not set # CONFIG_PACKAGE_luaexpat is not set # CONFIG_PACKAGE_luafilesystem is not set # CONFIG_PACKAGE_luajit is not set # CONFIG_PACKAGE_lualanes is not set # CONFIG_PACKAGE_luaposix is not set # CONFIG_PACKAGE_luarocks is not set # CONFIG_PACKAGE_luasec is not set # CONFIG_PACKAGE_luasoap is not set # CONFIG_PACKAGE_luasocket is not set # CONFIG_PACKAGE_luasocket5.3 is not set # CONFIG_PACKAGE_luasql-mysql is not set # CONFIG_PACKAGE_luasql-pgsql is not set # CONFIG_PACKAGE_luasql-sqlite3 is not set # CONFIG_PACKAGE_luasrcdiet is not set # CONFIG_PACKAGE_luci-lib-fs is not set # CONFIG_PACKAGE_luv is not set # CONFIG_PACKAGE_lyaml is not set # CONFIG_PACKAGE_lzmq is not set # CONFIG_PACKAGE_uuid is not set # end of Lua # # Node.js # # CONFIG_PACKAGE_node is not set # CONFIG_PACKAGE_node-arduino-firmata is not set # CONFIG_PACKAGE_node-cylon is not set # CONFIG_PACKAGE_node-cylon-firmata is not set # CONFIG_PACKAGE_node-cylon-gpio is not set # CONFIG_PACKAGE_node-cylon-i2c is not set # CONFIG_PACKAGE_node-hid is not set # CONFIG_PACKAGE_node-homebridge is not set # CONFIG_PACKAGE_node-javascript-obfuscator is not set # CONFIG_PACKAGE_node-npm is not set # CONFIG_PACKAGE_node-serialport is not set # CONFIG_PACKAGE_node-serialport-bindings is not set # end of Node.js # # PHP7 # # CONFIG_PACKAGE_php7 is not set # end of PHP7 # # PHP8 # # CONFIG_PACKAGE_php8 is not set # end of PHP8 # # Perl # # CONFIG_PACKAGE_perl is not set # end of Perl # # Python # # CONFIG_PACKAGE_libpython3 is not set # CONFIG_PACKAGE_micropython is not set # CONFIG_PACKAGE_micropython-lib is not set # CONFIG_PACKAGE_python-pip-conf is not set # CONFIG_PACKAGE_python3 is not set # CONFIG_PACKAGE_python3-aiohttp is not set # CONFIG_PACKAGE_python3-aiohttp-cors is not set # CONFIG_PACKAGE_python3-apipkg is not set # CONFIG_PACKAGE_python3-apparmor is not set # CONFIG_PACKAGE_python3-appdirs is not set # CONFIG_PACKAGE_python3-asgiref is not set # CONFIG_PACKAGE_python3-asn1crypto is not set # CONFIG_PACKAGE_python3-astral is not set # CONFIG_PACKAGE_python3-async-timeout is not set # CONFIG_PACKAGE_python3-asyncio is not set # CONFIG_PACKAGE_python3-atomicwrites is not set # CONFIG_PACKAGE_python3-attrs is not set # CONFIG_PACKAGE_python3-augeas is not set # CONFIG_PACKAGE_python3-automat is not set # CONFIG_PACKAGE_python3-awscli is not set # CONFIG_PACKAGE_python3-babel is not set # CONFIG_PACKAGE_python3-base is not set # CONFIG_PACKAGE_python3-bcrypt is not set # CONFIG_PACKAGE_python3-bidict is not set # CONFIG_PACKAGE_python3-boto3 is not set # CONFIG_PACKAGE_python3-botocore is not set # CONFIG_PACKAGE_python3-bottle is not set # CONFIG_PACKAGE_python3-cached-property is not set # CONFIG_PACKAGE_python3-cachelib is not set # CONFIG_PACKAGE_python3-cachetools is not set # CONFIG_PACKAGE_python3-certifi is not set # CONFIG_PACKAGE_python3-cffi is not set # CONFIG_PACKAGE_python3-cgi is not set # CONFIG_PACKAGE_python3-cgitb is not set # CONFIG_PACKAGE_python3-chardet is not set # CONFIG_PACKAGE_python3-ciso8601 is not set # CONFIG_PACKAGE_python3-click is not set # CONFIG_PACKAGE_python3-click-log is not set # CONFIG_PACKAGE_python3-codecs is not set # CONFIG_PACKAGE_python3-colorama is not set # CONFIG_PACKAGE_python3-constantly is not set # CONFIG_PACKAGE_python3-contextlib2 is not set # CONFIG_PACKAGE_python3-cryptodome is not set # CONFIG_PACKAGE_python3-cryptodomex is not set # CONFIG_PACKAGE_python3-cryptography is not set # CONFIG_PACKAGE_python3-ctypes is not set # CONFIG_PACKAGE_python3-curl is not set # CONFIG_PACKAGE_python3-dateutil is not set # CONFIG_PACKAGE_python3-dbm is not set # CONFIG_PACKAGE_python3-decimal is not set # CONFIG_PACKAGE_python3-decorator is not set # CONFIG_PACKAGE_python3-defusedxml is not set # CONFIG_PACKAGE_python3-dev is not set # CONFIG_PACKAGE_python3-distro is not set # CONFIG_PACKAGE_python3-distutils is not set # CONFIG_PACKAGE_python3-django is not set # CONFIG_PACKAGE_python3-django-appconf is not set # CONFIG_PACKAGE_python3-django-compressor is not set # CONFIG_PACKAGE_python3-django-cors-headers is not set # CONFIG_PACKAGE_python3-django-etesync-journal is not set # CONFIG_PACKAGE_python3-django-formtools is not set # CONFIG_PACKAGE_python3-django-jsonfield is not set # CONFIG_PACKAGE_python3-django-jsonfield2 is not set # CONFIG_PACKAGE_python3-django-picklefield is not set # CONFIG_PACKAGE_python3-django-postoffice is not set # CONFIG_PACKAGE_python3-django-ranged-response is not set # CONFIG_PACKAGE_python3-django-restframework is not set # CONFIG_PACKAGE_python3-django-restframework39 is not set # CONFIG_PACKAGE_python3-django-simple-captcha is not set # CONFIG_PACKAGE_python3-django-statici18n is not set # CONFIG_PACKAGE_python3-django-webpack-loader is not set # CONFIG_PACKAGE_python3-django1 is not set # CONFIG_PACKAGE_python3-dns is not set # CONFIG_PACKAGE_python3-docker is not set # CONFIG_PACKAGE_python3-dockerpty is not set # CONFIG_PACKAGE_python3-docopt is not set # CONFIG_PACKAGE_python3-docutils is not set # CONFIG_PACKAGE_python3-dotenv is not set # CONFIG_PACKAGE_python3-drf-nested-routers is not set # CONFIG_PACKAGE_python3-email is not set # CONFIG_PACKAGE_python3-engineio is not set # CONFIG_PACKAGE_python3-et_xmlfile is not set # CONFIG_PACKAGE_python3-evdev is not set # CONFIG_PACKAGE_python3-eventlet is not set # CONFIG_PACKAGE_python3-execnet is not set # CONFIG_PACKAGE_python3-flask is not set # CONFIG_PACKAGE_python3-flask-babel is not set # CONFIG_PACKAGE_python3-flask-httpauth is not set # CONFIG_PACKAGE_python3-flask-login is not set # CONFIG_PACKAGE_python3-flask-seasurf is not set # CONFIG_PACKAGE_python3-flask-session is not set # CONFIG_PACKAGE_python3-flask-socketio is not set # CONFIG_PACKAGE_python3-flup is not set # CONFIG_PACKAGE_python3-gdbm is not set # CONFIG_PACKAGE_python3-gmpy2 is not set # CONFIG_PACKAGE_python3-gnupg is not set # CONFIG_PACKAGE_python3-gpiod is not set # CONFIG_PACKAGE_python3-greenlet is not set # CONFIG_PACKAGE_python3-hyperlink is not set # CONFIG_PACKAGE_python3-idna is not set # CONFIG_PACKAGE_python3-ifaddr is not set # CONFIG_PACKAGE_python3-incremental is not set # CONFIG_PACKAGE_python3-influxdb is not set # CONFIG_PACKAGE_python3-iniconfig is not set # CONFIG_PACKAGE_python3-intelhex is not set # CONFIG_PACKAGE_python3-itsdangerous is not set # CONFIG_PACKAGE_python3-jdcal is not set # CONFIG_PACKAGE_python3-jinja2 is not set # CONFIG_PACKAGE_python3-jmespath is not set # CONFIG_PACKAGE_python3-jsonpath-ng is not set # CONFIG_PACKAGE_python3-jsonschema is not set # CONFIG_PACKAGE_python3-lib2to3 is not set # CONFIG_PACKAGE_python3-libmodbus is not set # CONFIG_PACKAGE_python3-libselinux is not set # CONFIG_PACKAGE_python3-libsemanage is not set # CONFIG_PACKAGE_python3-light is not set # # Configuration # # CONFIG_PYTHON3_BLUETOOTH_SUPPORT is not set # CONFIG_PYTHON3_HOST_PIP_CACHE_WORLD_READABLE is not set # end of Configuration # CONFIG_PACKAGE_python3-logging is not set # CONFIG_PACKAGE_python3-lxml is not set # CONFIG_PACKAGE_python3-lzma is not set # CONFIG_PACKAGE_python3-markdown is not set # CONFIG_PACKAGE_python3-markupsafe is not set # CONFIG_PACKAGE_python3-maxminddb is not set # CONFIG_PACKAGE_python3-more-itertools is not set # CONFIG_PACKAGE_python3-msgpack is not set # CONFIG_PACKAGE_python3-multidict is not set # CONFIG_PACKAGE_python3-multiprocessing is not set # CONFIG_PACKAGE_python3-ncurses is not set # CONFIG_PACKAGE_python3-netdisco is not set # CONFIG_PACKAGE_python3-netifaces is not set # CONFIG_PACKAGE_python3-networkx is not set # CONFIG_PACKAGE_python3-newt is not set # CONFIG_PACKAGE_python3-oauthlib is not set # CONFIG_PACKAGE_python3-openpyxl is not set # CONFIG_PACKAGE_python3-openssl is not set # CONFIG_PACKAGE_python3-packaging is not set # CONFIG_PACKAGE_python3-paho-mqtt is not set # CONFIG_PACKAGE_python3-paramiko is not set # CONFIG_PACKAGE_python3-parsley is not set # CONFIG_PACKAGE_python3-passlib is not set # CONFIG_PACKAGE_python3-pillow is not set # CONFIG_PACKAGE_python3-pip is not set # CONFIG_PACKAGE_python3-pkg-resources is not set # CONFIG_PACKAGE_python3-pluggy is not set # CONFIG_PACKAGE_python3-ply is not set # CONFIG_PACKAGE_python3-psutil is not set # CONFIG_PACKAGE_python3-psycopg2 is not set # CONFIG_PACKAGE_python3-py is not set # CONFIG_PACKAGE_python3-pyasn1 is not set # CONFIG_PACKAGE_python3-pyasn1-modules is not set # CONFIG_PACKAGE_python3-pycparser is not set # CONFIG_PACKAGE_python3-pydoc is not set # CONFIG_PACKAGE_python3-pyjwt is not set # CONFIG_PACKAGE_python3-pymysql is not set # CONFIG_PACKAGE_python3-pynacl is not set # CONFIG_PACKAGE_python3-pyodbc is not set # CONFIG_PACKAGE_python3-pyopenssl is not set # CONFIG_PACKAGE_python3-pyotp is not set # CONFIG_PACKAGE_python3-pyparsing is not set # CONFIG_PACKAGE_python3-pyroute2 is not set # CONFIG_PACKAGE_python3-pyrsistent is not set # CONFIG_PACKAGE_python3-pyserial is not set # CONFIG_PACKAGE_python3-pysocks is not set # CONFIG_PACKAGE_python3-pytest is not set # CONFIG_PACKAGE_python3-pytest-forked is not set # CONFIG_PACKAGE_python3-pytest-xdist is not set # CONFIG_PACKAGE_python3-pytz is not set # CONFIG_PACKAGE_python3-qrcode is not set # CONFIG_PACKAGE_python3-rcssmin is not set # CONFIG_PACKAGE_python3-readline is not set # CONFIG_PACKAGE_python3-requests is not set # CONFIG_PACKAGE_python3-requests-oauthlib is not set # CONFIG_PACKAGE_python3-rsa is not set # CONFIG_PACKAGE_python3-ruamel-yaml is not set # CONFIG_PACKAGE_python3-s3transfer is not set # CONFIG_PACKAGE_python3-schedule is not set # CONFIG_PACKAGE_python3-schema is not set # CONFIG_PACKAGE_python3-seafile-ccnet is not set # CONFIG_PACKAGE_python3-seafile-server is not set # CONFIG_PACKAGE_python3-searpc is not set # CONFIG_PACKAGE_python3-sentry-sdk is not set # CONFIG_PACKAGE_python3-sepolgen is not set # CONFIG_PACKAGE_python3-sepolicy is not set # CONFIG_PACKAGE_python3-service-identity is not set # CONFIG_PACKAGE_python3-setuptools is not set # CONFIG_PACKAGE_python3-simplejson is not set # CONFIG_PACKAGE_python3-six is not set # CONFIG_PACKAGE_python3-slugify is not set # CONFIG_PACKAGE_python3-smbus is not set # CONFIG_PACKAGE_python3-socketio is not set # CONFIG_PACKAGE_python3-speedtest-cli is not set # CONFIG_PACKAGE_python3-sqlalchemy is not set # CONFIG_PACKAGE_python3-sqlite3 is not set # CONFIG_PACKAGE_python3-sqlparse is not set # CONFIG_PACKAGE_python3-stem is not set # CONFIG_PACKAGE_python3-sysrepo is not set # CONFIG_PACKAGE_python3-text-unidecode is not set # CONFIG_PACKAGE_python3-texttable is not set # CONFIG_PACKAGE_python3-toml is not set # CONFIG_PACKAGE_python3-tornado is not set # CONFIG_PACKAGE_python3-twisted is not set # CONFIG_PACKAGE_python3-typing-extensions is not set # CONFIG_PACKAGE_python3-ubus is not set # CONFIG_PACKAGE_python3-uci is not set # CONFIG_PACKAGE_python3-unidecode is not set # CONFIG_PACKAGE_python3-unittest is not set # CONFIG_PACKAGE_python3-urllib is not set # CONFIG_PACKAGE_python3-urllib3 is not set # CONFIG_PACKAGE_python3-vobject is not set # CONFIG_PACKAGE_python3-voluptuous is not set # CONFIG_PACKAGE_python3-voluptuous-serialize is not set # CONFIG_PACKAGE_python3-wcwidth is not set # CONFIG_PACKAGE_python3-websocket-client is not set # CONFIG_PACKAGE_python3-werkzeug is not set # CONFIG_PACKAGE_python3-xml is not set # CONFIG_PACKAGE_python3-xmltodict is not set # CONFIG_PACKAGE_python3-yaml is not set # CONFIG_PACKAGE_python3-yarl is not set # CONFIG_PACKAGE_python3-zeroconf is not set # CONFIG_PACKAGE_python3-zipp is not set # CONFIG_PACKAGE_python3-zope-interface is not set # end of Python # # Ruby # # CONFIG_PACKAGE_ruby is not set # end of Ruby # # Tcl # # CONFIG_PACKAGE_tcl is not set # end of Tcl # CONFIG_PACKAGE_chicken-scheme-full is not set # CONFIG_PACKAGE_chicken-scheme-interpreter is not set # CONFIG_PACKAGE_slsh is not set # end of Languages # # Libraries # # # Compression # # CONFIG_PACKAGE_libbz2 is not set # CONFIG_PACKAGE_liblz4 is not set # CONFIG_PACKAGE_liblzma is not set # CONFIG_PACKAGE_libunrar is not set # CONFIG_PACKAGE_libzip-gnutls is not set # CONFIG_PACKAGE_libzip-mbedtls is not set # CONFIG_PACKAGE_libzip-nossl is not set # CONFIG_PACKAGE_libzip-openssl is not set # CONFIG_PACKAGE_libzstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_libmariadb is not set # CONFIG_PACKAGE_libpq is not set # CONFIG_PACKAGE_libpqxx is not set # CONFIG_PACKAGE_libsqlite3 is not set # CONFIG_PACKAGE_pgsqlodbc is not set # CONFIG_PACKAGE_psqlodbca is not set # CONFIG_PACKAGE_psqlodbcw is not set # CONFIG_PACKAGE_redis-cli is not set # CONFIG_PACKAGE_redis-server is not set # CONFIG_PACKAGE_redis-utils is not set # CONFIG_PACKAGE_tdb is not set # CONFIG_PACKAGE_unixodbc is not set # end of Database # # Filesystem # # CONFIG_PACKAGE_libacl is not set CONFIG_PACKAGE_libattr=y # CONFIG_PACKAGE_libfuse is not set # CONFIG_PACKAGE_libfuse3 is not set # CONFIG_PACKAGE_libow is not set # CONFIG_PACKAGE_libow-capi is not set # CONFIG_PACKAGE_libsysfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_libfko is not set CONFIG_PACKAGE_libip4tc=y CONFIG_PACKAGE_libip6tc=y CONFIG_PACKAGE_libxtables=y # CONFIG_PACKAGE_libxtables-nft is not set # end of Firewall # # Instant Messaging # # CONFIG_PACKAGE_quasselc is not set # end of Instant Messaging # # IoT # # CONFIG_PACKAGE_libmraa is not set # CONFIG_PACKAGE_libmraa-python3 is not set # CONFIG_PACKAGE_libupm is not set # CONFIG_PACKAGE_libupm-a110x is not set # CONFIG_PACKAGE_libupm-a110x-python3 is not set # CONFIG_PACKAGE_libupm-abp is not set # CONFIG_PACKAGE_libupm-abp-python3 is not set # CONFIG_PACKAGE_libupm-ad8232 is not set # CONFIG_PACKAGE_libupm-ad8232-python3 is not set # CONFIG_PACKAGE_libupm-adafruitms1438 is not set # CONFIG_PACKAGE_libupm-adafruitms1438-python3 is not set # CONFIG_PACKAGE_libupm-adafruitss is not set # CONFIG_PACKAGE_libupm-adafruitss-python3 is not set # CONFIG_PACKAGE_libupm-adc121c021 is not set # CONFIG_PACKAGE_libupm-adc121c021-python3 is not set # CONFIG_PACKAGE_libupm-adis16448 is not set # CONFIG_PACKAGE_libupm-adis16448-python3 is not set # CONFIG_PACKAGE_libupm-ads1x15 is not set # CONFIG_PACKAGE_libupm-ads1x15-python3 is not set # CONFIG_PACKAGE_libupm-adxl335 is not set # CONFIG_PACKAGE_libupm-adxl335-python3 is not set # CONFIG_PACKAGE_libupm-adxl345 is not set # CONFIG_PACKAGE_libupm-adxl345-python3 is not set # CONFIG_PACKAGE_libupm-adxrs610 is not set # CONFIG_PACKAGE_libupm-adxrs610-python3 is not set # CONFIG_PACKAGE_libupm-am2315 is not set # CONFIG_PACKAGE_libupm-am2315-python3 is not set # CONFIG_PACKAGE_libupm-apa102 is not set # CONFIG_PACKAGE_libupm-apa102-python3 is not set # CONFIG_PACKAGE_libupm-apds9002 is not set # CONFIG_PACKAGE_libupm-apds9002-python3 is not set # CONFIG_PACKAGE_libupm-apds9930 is not set # CONFIG_PACKAGE_libupm-apds9930-python3 is not set # CONFIG_PACKAGE_libupm-at42qt1070 is not set # CONFIG_PACKAGE_libupm-at42qt1070-python3 is not set # CONFIG_PACKAGE_libupm-bh1749 is not set # CONFIG_PACKAGE_libupm-bh1749-python3 is not set # CONFIG_PACKAGE_libupm-bh1750 is not set # CONFIG_PACKAGE_libupm-bh1750-python3 is not set # CONFIG_PACKAGE_libupm-bh1792 is not set # CONFIG_PACKAGE_libupm-bh1792-python3 is not set # CONFIG_PACKAGE_libupm-biss0001 is not set # CONFIG_PACKAGE_libupm-biss0001-python3 is not set # CONFIG_PACKAGE_libupm-bma220 is not set # CONFIG_PACKAGE_libupm-bma220-python3 is not set # CONFIG_PACKAGE_libupm-bma250e is not set # CONFIG_PACKAGE_libupm-bma250e-python3 is not set # CONFIG_PACKAGE_libupm-bmg160 is not set # CONFIG_PACKAGE_libupm-bmg160-python3 is not set # CONFIG_PACKAGE_libupm-bmi160 is not set # CONFIG_PACKAGE_libupm-bmi160-python3 is not set # CONFIG_PACKAGE_libupm-bmm150 is not set # CONFIG_PACKAGE_libupm-bmm150-python3 is not set # CONFIG_PACKAGE_libupm-bmp280 is not set # CONFIG_PACKAGE_libupm-bmp280-python3 is not set # CONFIG_PACKAGE_libupm-bmpx8x is not set # CONFIG_PACKAGE_libupm-bmpx8x-python3 is not set # CONFIG_PACKAGE_libupm-bmx055 is not set # CONFIG_PACKAGE_libupm-bmx055-python3 is not set # CONFIG_PACKAGE_libupm-bno055 is not set # CONFIG_PACKAGE_libupm-bno055-python3 is not set # CONFIG_PACKAGE_libupm-button is not set # CONFIG_PACKAGE_libupm-button-python3 is not set # CONFIG_PACKAGE_libupm-buzzer is not set # CONFIG_PACKAGE_libupm-buzzer-python3 is not set # CONFIG_PACKAGE_libupm-cjq4435 is not set # CONFIG_PACKAGE_libupm-cjq4435-python3 is not set # CONFIG_PACKAGE_libupm-collision is not set # CONFIG_PACKAGE_libupm-collision-python3 is not set # CONFIG_PACKAGE_libupm-curieimu is not set # CONFIG_PACKAGE_libupm-curieimu-python3 is not set # CONFIG_PACKAGE_libupm-cwlsxxa is not set # CONFIG_PACKAGE_libupm-cwlsxxa-python3 is not set # CONFIG_PACKAGE_libupm-dfrec is not set # CONFIG_PACKAGE_libupm-dfrec-python3 is not set # CONFIG_PACKAGE_libupm-dfrorp is not set # CONFIG_PACKAGE_libupm-dfrorp-python3 is not set # CONFIG_PACKAGE_libupm-dfrph is not set # CONFIG_PACKAGE_libupm-dfrph-python3 is not set # CONFIG_PACKAGE_libupm-ds1307 is not set # CONFIG_PACKAGE_libupm-ds1307-python3 is not set # CONFIG_PACKAGE_libupm-ds1808lc is not set # CONFIG_PACKAGE_libupm-ds1808lc-python3 is not set # CONFIG_PACKAGE_libupm-ds18b20 is not set # CONFIG_PACKAGE_libupm-ds18b20-python3 is not set # CONFIG_PACKAGE_libupm-ds2413 is not set # CONFIG_PACKAGE_libupm-ds2413-python3 is not set # CONFIG_PACKAGE_libupm-ecezo is not set # CONFIG_PACKAGE_libupm-ecezo-python3 is not set # CONFIG_PACKAGE_libupm-ecs1030 is not set # CONFIG_PACKAGE_libupm-ecs1030-python3 is not set # CONFIG_PACKAGE_libupm-ehr is not set # CONFIG_PACKAGE_libupm-ehr-python3 is not set # CONFIG_PACKAGE_libupm-eldriver is not set # CONFIG_PACKAGE_libupm-eldriver-python3 is not set # CONFIG_PACKAGE_libupm-electromagnet is not set # CONFIG_PACKAGE_libupm-electromagnet-python3 is not set # CONFIG_PACKAGE_libupm-emg is not set # CONFIG_PACKAGE_libupm-emg-python3 is not set # CONFIG_PACKAGE_libupm-enc03r is not set # CONFIG_PACKAGE_libupm-enc03r-python3 is not set # CONFIG_PACKAGE_libupm-flex is not set # CONFIG_PACKAGE_libupm-flex-python3 is not set # CONFIG_PACKAGE_libupm-gas is not set # CONFIG_PACKAGE_libupm-gas-python3 is not set # CONFIG_PACKAGE_libupm-gp2y0a is not set # CONFIG_PACKAGE_libupm-gp2y0a-python3 is not set # CONFIG_PACKAGE_libupm-gprs is not set # CONFIG_PACKAGE_libupm-gprs-python3 is not set # CONFIG_PACKAGE_libupm-gsr is not set # CONFIG_PACKAGE_libupm-gsr-python3 is not set # CONFIG_PACKAGE_libupm-guvas12d is not set # CONFIG_PACKAGE_libupm-guvas12d-python3 is not set # CONFIG_PACKAGE_libupm-h3lis331dl is not set # CONFIG_PACKAGE_libupm-h3lis331dl-python3 is not set # CONFIG_PACKAGE_libupm-h803x is not set # CONFIG_PACKAGE_libupm-h803x-python3 is not set # CONFIG_PACKAGE_libupm-hcsr04 is not set # CONFIG_PACKAGE_libupm-hcsr04-python3 is not set # CONFIG_PACKAGE_libupm-hdc1000 is not set # CONFIG_PACKAGE_libupm-hdc1000-python3 is not set # CONFIG_PACKAGE_libupm-hdxxvxta is not set # CONFIG_PACKAGE_libupm-hdxxvxta-python3 is not set # CONFIG_PACKAGE_libupm-hka5 is not set # CONFIG_PACKAGE_libupm-hka5-python3 is not set # CONFIG_PACKAGE_libupm-hlg150h is not set # CONFIG_PACKAGE_libupm-hlg150h-python3 is not set # CONFIG_PACKAGE_libupm-hm11 is not set # CONFIG_PACKAGE_libupm-hm11-python3 is not set # CONFIG_PACKAGE_libupm-hmc5883l is not set # CONFIG_PACKAGE_libupm-hmc5883l-python3 is not set # CONFIG_PACKAGE_libupm-hmtrp is not set # CONFIG_PACKAGE_libupm-hmtrp-python3 is not set # CONFIG_PACKAGE_libupm-hp20x is not set # CONFIG_PACKAGE_libupm-hp20x-python3 is not set # CONFIG_PACKAGE_libupm-ht9170 is not set # CONFIG_PACKAGE_libupm-ht9170-python3 is not set # CONFIG_PACKAGE_libupm-htu21d is not set # CONFIG_PACKAGE_libupm-htu21d-python3 is not set # CONFIG_PACKAGE_libupm-hwxpxx is not set # CONFIG_PACKAGE_libupm-hwxpxx-python3 is not set # CONFIG_PACKAGE_libupm-hx711 is not set # CONFIG_PACKAGE_libupm-hx711-python3 is not set # CONFIG_PACKAGE_libupm-ili9341 is not set # CONFIG_PACKAGE_libupm-ili9341-python3 is not set # CONFIG_PACKAGE_libupm-ims is not set # CONFIG_PACKAGE_libupm-ims-python3 is not set # CONFIG_PACKAGE_libupm-ina132 is not set # CONFIG_PACKAGE_libupm-ina132-python3 is not set # CONFIG_PACKAGE_libupm-interfaces is not set # CONFIG_PACKAGE_libupm-interfaces-python3 is not set # CONFIG_PACKAGE_libupm-isd1820 is not set # CONFIG_PACKAGE_libupm-isd1820-python3 is not set # CONFIG_PACKAGE_libupm-itg3200 is not set # CONFIG_PACKAGE_libupm-itg3200-python3 is not set # CONFIG_PACKAGE_libupm-jhd1313m1 is not set # CONFIG_PACKAGE_libupm-jhd1313m1-python3 is not set # CONFIG_PACKAGE_libupm-joystick12 is not set # CONFIG_PACKAGE_libupm-joystick12-python3 is not set # CONFIG_PACKAGE_libupm-kx122 is not set # CONFIG_PACKAGE_libupm-kx122-python3 is not set # CONFIG_PACKAGE_libupm-kxcjk1013 is not set # CONFIG_PACKAGE_libupm-kxcjk1013-python3 is not set # CONFIG_PACKAGE_libupm-kxtj3 is not set # CONFIG_PACKAGE_libupm-kxtj3-python3 is not set # CONFIG_PACKAGE_libupm-l298 is not set # CONFIG_PACKAGE_libupm-l298-python3 is not set # CONFIG_PACKAGE_libupm-l3gd20 is not set # CONFIG_PACKAGE_libupm-l3gd20-python3 is not set # CONFIG_PACKAGE_libupm-lcd is not set # CONFIG_PACKAGE_libupm-lcd-python3 is not set # CONFIG_PACKAGE_libupm-lcdks is not set # CONFIG_PACKAGE_libupm-lcdks-python3 is not set # CONFIG_PACKAGE_libupm-lcm1602 is not set # CONFIG_PACKAGE_libupm-lcm1602-python3 is not set # CONFIG_PACKAGE_libupm-ldt0028 is not set # CONFIG_PACKAGE_libupm-ldt0028-python3 is not set # CONFIG_PACKAGE_libupm-led is not set # CONFIG_PACKAGE_libupm-led-python3 is not set # CONFIG_PACKAGE_libupm-lidarlitev3 is not set # CONFIG_PACKAGE_libupm-lidarlitev3-python3 is not set # CONFIG_PACKAGE_libupm-light is not set # CONFIG_PACKAGE_libupm-light-python3 is not set # CONFIG_PACKAGE_libupm-linefinder is not set # CONFIG_PACKAGE_libupm-linefinder-python3 is not set # CONFIG_PACKAGE_libupm-lis2ds12 is not set # CONFIG_PACKAGE_libupm-lis2ds12-python3 is not set # CONFIG_PACKAGE_libupm-lis3dh is not set # CONFIG_PACKAGE_libupm-lis3dh-python3 is not set # CONFIG_PACKAGE_libupm-lm35 is not set # CONFIG_PACKAGE_libupm-lm35-python3 is not set # CONFIG_PACKAGE_libupm-lol is not set # CONFIG_PACKAGE_libupm-lol-python3 is not set # CONFIG_PACKAGE_libupm-loudness is not set # CONFIG_PACKAGE_libupm-loudness-python3 is not set # CONFIG_PACKAGE_libupm-lp8860 is not set # CONFIG_PACKAGE_libupm-lp8860-python3 is not set # CONFIG_PACKAGE_libupm-lpd8806 is not set # CONFIG_PACKAGE_libupm-lpd8806-python3 is not set # CONFIG_PACKAGE_libupm-lsm303agr is not set # CONFIG_PACKAGE_libupm-lsm303agr-python3 is not set # CONFIG_PACKAGE_libupm-lsm303d is not set # CONFIG_PACKAGE_libupm-lsm303d-python3 is not set # CONFIG_PACKAGE_libupm-lsm303dlh is not set # CONFIG_PACKAGE_libupm-lsm303dlh-python3 is not set # CONFIG_PACKAGE_libupm-lsm6ds3h is not set # CONFIG_PACKAGE_libupm-lsm6ds3h-python3 is not set # CONFIG_PACKAGE_libupm-lsm6dsl is not set # CONFIG_PACKAGE_libupm-lsm6dsl-python3 is not set # CONFIG_PACKAGE_libupm-lsm9ds0 is not set # CONFIG_PACKAGE_libupm-lsm9ds0-python3 is not set # CONFIG_PACKAGE_libupm-m24lr64e is not set # CONFIG_PACKAGE_libupm-m24lr64e-python3 is not set # CONFIG_PACKAGE_libupm-mag3110 is not set # CONFIG_PACKAGE_libupm-mag3110-python3 is not set # CONFIG_PACKAGE_libupm-max30100 is not set # CONFIG_PACKAGE_libupm-max30100-python3 is not set # CONFIG_PACKAGE_libupm-max31723 is not set # CONFIG_PACKAGE_libupm-max31723-python3 is not set # CONFIG_PACKAGE_libupm-max31855 is not set # CONFIG_PACKAGE_libupm-max31855-python3 is not set # CONFIG_PACKAGE_libupm-max44000 is not set # CONFIG_PACKAGE_libupm-max44000-python3 is not set # CONFIG_PACKAGE_libupm-max44009 is not set # CONFIG_PACKAGE_libupm-max44009-python3 is not set # CONFIG_PACKAGE_libupm-max5487 is not set # CONFIG_PACKAGE_libupm-max5487-python3 is not set # CONFIG_PACKAGE_libupm-maxds3231m is not set # CONFIG_PACKAGE_libupm-maxds3231m-python3 is not set # CONFIG_PACKAGE_libupm-maxsonarez is not set # CONFIG_PACKAGE_libupm-maxsonarez-python3 is not set # CONFIG_PACKAGE_libupm-mb704x is not set # CONFIG_PACKAGE_libupm-mb704x-python3 is not set # CONFIG_PACKAGE_libupm-mcp2515 is not set # CONFIG_PACKAGE_libupm-mcp2515-python3 is not set # CONFIG_PACKAGE_libupm-mcp9808 is not set # CONFIG_PACKAGE_libupm-mcp9808-python3 is not set # CONFIG_PACKAGE_libupm-md is not set # CONFIG_PACKAGE_libupm-md-python3 is not set # CONFIG_PACKAGE_libupm-mg811 is not set # CONFIG_PACKAGE_libupm-mg811-python3 is not set # CONFIG_PACKAGE_libupm-mhz16 is not set # CONFIG_PACKAGE_libupm-mhz16-python3 is not set # CONFIG_PACKAGE_libupm-mic is not set # CONFIG_PACKAGE_libupm-mic-python3 is not set # CONFIG_PACKAGE_libupm-micsv89 is not set # CONFIG_PACKAGE_libupm-micsv89-python3 is not set # CONFIG_PACKAGE_libupm-mlx90614 is not set # CONFIG_PACKAGE_libupm-mlx90614-python3 is not set # CONFIG_PACKAGE_libupm-mma7361 is not set # CONFIG_PACKAGE_libupm-mma7361-python3 is not set # CONFIG_PACKAGE_libupm-mma7455 is not set # CONFIG_PACKAGE_libupm-mma7455-python3 is not set # CONFIG_PACKAGE_libupm-mma7660 is not set # CONFIG_PACKAGE_libupm-mma7660-python3 is not set # CONFIG_PACKAGE_libupm-mma8x5x is not set # CONFIG_PACKAGE_libupm-mma8x5x-python3 is not set # CONFIG_PACKAGE_libupm-mmc35240 is not set # CONFIG_PACKAGE_libupm-mmc35240-python3 is not set # CONFIG_PACKAGE_libupm-moisture is not set # CONFIG_PACKAGE_libupm-moisture-python3 is not set # CONFIG_PACKAGE_libupm-mpl3115a2 is not set # CONFIG_PACKAGE_libupm-mpl3115a2-python3 is not set # CONFIG_PACKAGE_libupm-mpr121 is not set # CONFIG_PACKAGE_libupm-mpr121-python3 is not set # CONFIG_PACKAGE_libupm-mpu9150 is not set # CONFIG_PACKAGE_libupm-mpu9150-python3 is not set # CONFIG_PACKAGE_libupm-mq303a is not set # CONFIG_PACKAGE_libupm-mq303a-python3 is not set # CONFIG_PACKAGE_libupm-ms5611 is not set # CONFIG_PACKAGE_libupm-ms5611-python3 is not set # CONFIG_PACKAGE_libupm-ms5803 is not set # CONFIG_PACKAGE_libupm-ms5803-python3 is not set # CONFIG_PACKAGE_libupm-my9221 is not set # CONFIG_PACKAGE_libupm-my9221-python3 is not set # CONFIG_PACKAGE_libupm-nlgpio16 is not set # CONFIG_PACKAGE_libupm-nlgpio16-python3 is not set # CONFIG_PACKAGE_libupm-nmea_gps is not set # CONFIG_PACKAGE_libupm-nmea_gps-python3 is not set # CONFIG_PACKAGE_libupm-nrf24l01 is not set # CONFIG_PACKAGE_libupm-nrf24l01-python3 is not set # CONFIG_PACKAGE_libupm-nrf8001 is not set # CONFIG_PACKAGE_libupm-nrf8001-python3 is not set # CONFIG_PACKAGE_libupm-nunchuck is not set # CONFIG_PACKAGE_libupm-nunchuck-python3 is not set # CONFIG_PACKAGE_libupm-o2 is not set # CONFIG_PACKAGE_libupm-o2-python3 is not set # CONFIG_PACKAGE_libupm-otp538u is not set # CONFIG_PACKAGE_libupm-otp538u-python3 is not set # CONFIG_PACKAGE_libupm-ozw is not set # CONFIG_PACKAGE_libupm-ozw-python3 is not set # CONFIG_PACKAGE_libupm-p9813 is not set # CONFIG_PACKAGE_libupm-p9813-python3 is not set # CONFIG_PACKAGE_libupm-pca9685 is not set # CONFIG_PACKAGE_libupm-pca9685-python3 is not set # CONFIG_PACKAGE_libupm-pn532 is not set # CONFIG_PACKAGE_libupm-pn532-python3 is not set # CONFIG_PACKAGE_libupm-ppd42ns is not set # CONFIG_PACKAGE_libupm-ppd42ns-python3 is not set # CONFIG_PACKAGE_libupm-pulsensor is not set # CONFIG_PACKAGE_libupm-pulsensor-python3 is not set # CONFIG_PACKAGE_libupm-relay is not set # CONFIG_PACKAGE_libupm-relay-python3 is not set # CONFIG_PACKAGE_libupm-rf22 is not set # CONFIG_PACKAGE_libupm-rf22-python3 is not set # CONFIG_PACKAGE_libupm-rfr359f is not set # CONFIG_PACKAGE_libupm-rfr359f-python3 is not set # CONFIG_PACKAGE_libupm-rgbringcoder is not set # CONFIG_PACKAGE_libupm-rgbringcoder-python3 is not set # CONFIG_PACKAGE_libupm-rhusb is not set # CONFIG_PACKAGE_libupm-rhusb-python3 is not set # CONFIG_PACKAGE_libupm-rn2903 is not set # CONFIG_PACKAGE_libupm-rn2903-python3 is not set # CONFIG_PACKAGE_libupm-rotary is not set # CONFIG_PACKAGE_libupm-rotary-python3 is not set # CONFIG_PACKAGE_libupm-rotaryencoder is not set # CONFIG_PACKAGE_libupm-rotaryencoder-python3 is not set # CONFIG_PACKAGE_libupm-rpr220 is not set # CONFIG_PACKAGE_libupm-rpr220-python3 is not set # CONFIG_PACKAGE_libupm-rsc is not set # CONFIG_PACKAGE_libupm-rsc-python3 is not set # CONFIG_PACKAGE_libupm-scam is not set # CONFIG_PACKAGE_libupm-scam-python3 is not set # CONFIG_PACKAGE_libupm-sensortemplate is not set # CONFIG_PACKAGE_libupm-sensortemplate-python3 is not set # CONFIG_PACKAGE_libupm-servo is not set # CONFIG_PACKAGE_libupm-servo-python3 is not set # CONFIG_PACKAGE_libupm-sht1x is not set # CONFIG_PACKAGE_libupm-sht1x-python3 is not set # CONFIG_PACKAGE_libupm-si1132 is not set # CONFIG_PACKAGE_libupm-si1132-python3 is not set # CONFIG_PACKAGE_libupm-si114x is not set # CONFIG_PACKAGE_libupm-si114x-python3 is not set # CONFIG_PACKAGE_libupm-si7005 is not set # CONFIG_PACKAGE_libupm-si7005-python3 is not set # CONFIG_PACKAGE_libupm-slide is not set # CONFIG_PACKAGE_libupm-slide-python3 is not set # CONFIG_PACKAGE_libupm-sm130 is not set # CONFIG_PACKAGE_libupm-sm130-python3 is not set # CONFIG_PACKAGE_libupm-smartdrive is not set # CONFIG_PACKAGE_libupm-smartdrive-python3 is not set # CONFIG_PACKAGE_libupm-speaker is not set # CONFIG_PACKAGE_libupm-speaker-python3 is not set # CONFIG_PACKAGE_libupm-ssd1351 is not set # CONFIG_PACKAGE_libupm-ssd1351-python3 is not set # CONFIG_PACKAGE_libupm-st7735 is not set # CONFIG_PACKAGE_libupm-st7735-python3 is not set # CONFIG_PACKAGE_libupm-stepmotor is not set # CONFIG_PACKAGE_libupm-stepmotor-python3 is not set # CONFIG_PACKAGE_libupm-sx1276 is not set # CONFIG_PACKAGE_libupm-sx1276-python3 is not set # CONFIG_PACKAGE_libupm-sx6119 is not set # CONFIG_PACKAGE_libupm-sx6119-python3 is not set # CONFIG_PACKAGE_libupm-t3311 is not set # CONFIG_PACKAGE_libupm-t3311-python3 is not set # CONFIG_PACKAGE_libupm-t6713 is not set # CONFIG_PACKAGE_libupm-t6713-python3 is not set # CONFIG_PACKAGE_libupm-ta12200 is not set # CONFIG_PACKAGE_libupm-ta12200-python3 is not set # CONFIG_PACKAGE_libupm-tca9548a is not set # CONFIG_PACKAGE_libupm-tca9548a-python3 is not set # CONFIG_PACKAGE_libupm-tcs3414cs is not set # CONFIG_PACKAGE_libupm-tcs3414cs-python3 is not set # CONFIG_PACKAGE_libupm-tcs37727 is not set # CONFIG_PACKAGE_libupm-tcs37727-python3 is not set # CONFIG_PACKAGE_libupm-teams is not set # CONFIG_PACKAGE_libupm-teams-python3 is not set # CONFIG_PACKAGE_libupm-temperature is not set # CONFIG_PACKAGE_libupm-temperature-python3 is not set # CONFIG_PACKAGE_libupm-tex00 is not set # CONFIG_PACKAGE_libupm-tex00-python3 is not set # CONFIG_PACKAGE_libupm-th02 is not set # CONFIG_PACKAGE_libupm-th02-python3 is not set # CONFIG_PACKAGE_libupm-tm1637 is not set # CONFIG_PACKAGE_libupm-tm1637-python3 is not set # CONFIG_PACKAGE_libupm-tmp006 is not set # CONFIG_PACKAGE_libupm-tmp006-python3 is not set # CONFIG_PACKAGE_libupm-tsl2561 is not set # CONFIG_PACKAGE_libupm-tsl2561-python3 is not set # CONFIG_PACKAGE_libupm-ttp223 is not set # CONFIG_PACKAGE_libupm-ttp223-python3 is not set # CONFIG_PACKAGE_libupm-uartat is not set # CONFIG_PACKAGE_libupm-uartat-python3 is not set # CONFIG_PACKAGE_libupm-uln200xa is not set # CONFIG_PACKAGE_libupm-uln200xa-python3 is not set # CONFIG_PACKAGE_libupm-ultrasonic is not set # CONFIG_PACKAGE_libupm-ultrasonic-python3 is not set # CONFIG_PACKAGE_libupm-urm37 is not set # CONFIG_PACKAGE_libupm-urm37-python3 is not set # CONFIG_PACKAGE_libupm-utilities is not set # CONFIG_PACKAGE_libupm-utilities-python3 is not set # CONFIG_PACKAGE_libupm-vcap is not set # CONFIG_PACKAGE_libupm-vcap-python3 is not set # CONFIG_PACKAGE_libupm-vdiv is not set # CONFIG_PACKAGE_libupm-vdiv-python3 is not set # CONFIG_PACKAGE_libupm-veml6070 is not set # CONFIG_PACKAGE_libupm-veml6070-python3 is not set # CONFIG_PACKAGE_libupm-water is not set # CONFIG_PACKAGE_libupm-water-python3 is not set # CONFIG_PACKAGE_libupm-waterlevel is not set # CONFIG_PACKAGE_libupm-waterlevel-python3 is not set # CONFIG_PACKAGE_libupm-wfs is not set # CONFIG_PACKAGE_libupm-wfs-python3 is not set # CONFIG_PACKAGE_libupm-wheelencoder is not set # CONFIG_PACKAGE_libupm-wheelencoder-python3 is not set # CONFIG_PACKAGE_libupm-wt5001 is not set # CONFIG_PACKAGE_libupm-wt5001-python3 is not set # CONFIG_PACKAGE_libupm-xbee is not set # CONFIG_PACKAGE_libupm-xbee-python3 is not set # CONFIG_PACKAGE_libupm-yg1006 is not set # CONFIG_PACKAGE_libupm-yg1006-python3 is not set # CONFIG_PACKAGE_libupm-zfm20 is not set # CONFIG_PACKAGE_libupm-zfm20-python3 is not set # end of IoT # # Languages # # CONFIG_PACKAGE_libyaml is not set # end of Languages # # LibElektra # # CONFIG_PACKAGE_libelektra-boost is not set # CONFIG_PACKAGE_libelektra-core is not set # CONFIG_PACKAGE_libelektra-cpp is not set # CONFIG_PACKAGE_libelektra-crypto is not set # CONFIG_PACKAGE_libelektra-curlget is not set # CONFIG_PACKAGE_libelektra-dbus is not set # CONFIG_PACKAGE_libelektra-extra is not set # CONFIG_PACKAGE_libelektra-lua is not set # CONFIG_PACKAGE_libelektra-plugins is not set # CONFIG_PACKAGE_libelektra-python3 is not set # CONFIG_PACKAGE_libelektra-resolvers is not set # CONFIG_PACKAGE_libelektra-xerces is not set # CONFIG_PACKAGE_libelektra-xml is not set # CONFIG_PACKAGE_libelektra-yajl is not set # CONFIG_PACKAGE_libelektra-yamlcpp is not set # CONFIG_PACKAGE_libelektra-zmq is not set # end of LibElektra # # Networking # # CONFIG_PACKAGE_libdcwproto is not set # CONFIG_PACKAGE_libdcwsocket is not set # CONFIG_PACKAGE_libsctp is not set # CONFIG_PACKAGE_libuhttpd-mbedtls is not set # CONFIG_PACKAGE_libuhttpd-nossl is not set # CONFIG_PACKAGE_libuhttpd-openssl is not set # CONFIG_PACKAGE_libuhttpd-wolfssl is not set # CONFIG_PACKAGE_libulfius-gnutls is not set # CONFIG_PACKAGE_libulfius-nossl is not set # CONFIG_PACKAGE_libunbound is not set # CONFIG_PACKAGE_libuwsc-mbedtls is not set # CONFIG_PACKAGE_libuwsc-nossl is not set # CONFIG_PACKAGE_libuwsc-openssl is not set # CONFIG_PACKAGE_libuwsc-wolfssl is not set # end of Networking # # Qt5 # # CONFIG_PACKAGE_qt5-core is not set # CONFIG_PACKAGE_qt5-network is not set # CONFIG_PACKAGE_qt5-sql is not set # CONFIG_PACKAGE_qt5-xml is not set # CONFIG_PACKAGE_qtbase is not set CONFIG_QT5_INCLUDE_ATOMIC=y # # Select Qtbase Libraries # # # Qtbase Libraries # # end of Select Qtbase Libraries # end of Qt5 # # SSL # # CONFIG_PACKAGE_libgnutls is not set # CONFIG_PACKAGE_libgnutls-dane is not set CONFIG_PACKAGE_libmbedtls=y # CONFIG_LIBMBEDTLS_DEBUG_C is not set # CONFIG_LIBMBEDTLS_HKDF_C is not set # CONFIG_PACKAGE_libnss is not set CONFIG_PACKAGE_libopenssl=y # # Build Options # CONFIG_OPENSSL_OPTIMIZE_SPEED=y CONFIG_OPENSSL_WITH_ASM=y CONFIG_OPENSSL_WITH_DEPRECATED=y # CONFIG_OPENSSL_NO_DEPRECATED is not set CONFIG_OPENSSL_WITH_ERROR_MESSAGES=y # # Protocol Support # CONFIG_OPENSSL_WITH_TLS13=y # CONFIG_OPENSSL_WITH_DTLS is not set # CONFIG_OPENSSL_WITH_NPN is not set CONFIG_OPENSSL_WITH_SRP=y CONFIG_OPENSSL_WITH_CMS=y # # Algorithm Selection # # CONFIG_OPENSSL_WITH_EC2M is not set CONFIG_OPENSSL_WITH_CHACHA_POLY1305=y CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM=y CONFIG_OPENSSL_WITH_PSK=y # # Less commonly used build options # # CONFIG_OPENSSL_WITH_ARIA is not set # CONFIG_OPENSSL_WITH_CAMELLIA is not set # CONFIG_OPENSSL_WITH_IDEA is not set # CONFIG_OPENSSL_WITH_SEED is not set # CONFIG_OPENSSL_WITH_SM234 is not set # CONFIG_OPENSSL_WITH_BLAKE2 is not set # CONFIG_OPENSSL_WITH_MDC2 is not set # CONFIG_OPENSSL_WITH_WHIRLPOOL is not set # CONFIG_OPENSSL_WITH_COMPRESSION is not set # CONFIG_OPENSSL_WITH_RFC3779 is not set # # Engine/Hardware Support # CONFIG_OPENSSL_ENGINE=y CONFIG_OPENSSL_ENGINE_BUILTIN=y CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG=y CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO=y CONFIG_PACKAGE_libopenssl-conf=y # CONFIG_PACKAGE_libopenssl-devcrypto is not set # CONFIG_PACKAGE_libopenssl-gost_engine is not set # CONFIG_PACKAGE_libpolarssl is not set # CONFIG_PACKAGE_libwolfssl is not set # end of SSL # # Sound # # CONFIG_PACKAGE_alsa-ucm-conf is not set # CONFIG_PACKAGE_liblo is not set # end of Sound # # Telephony # # CONFIG_PACKAGE_bcg729 is not set # CONFIG_PACKAGE_dahdi-tools-libtonezone is not set # CONFIG_PACKAGE_gsmlib is not set # CONFIG_PACKAGE_libctb is not set # CONFIG_PACKAGE_libfreetdm is not set # CONFIG_PACKAGE_libiksemel is not set # CONFIG_PACKAGE_libks is not set # CONFIG_PACKAGE_libosip2 is not set # CONFIG_PACKAGE_libpj is not set # CONFIG_PACKAGE_libpjlib-util is not set # CONFIG_PACKAGE_libpjmedia is not set # CONFIG_PACKAGE_libpjnath is not set # CONFIG_PACKAGE_libpjsip is not set # CONFIG_PACKAGE_libpjsip-simple is not set # CONFIG_PACKAGE_libpjsip-ua is not set # CONFIG_PACKAGE_libpjsua is not set # CONFIG_PACKAGE_libpjsua2 is not set # CONFIG_PACKAGE_libre is not set # CONFIG_PACKAGE_librem is not set # CONFIG_PACKAGE_libspandsp is not set # CONFIG_PACKAGE_libspandsp3 is not set # CONFIG_PACKAGE_libsrtp2 is not set # CONFIG_PACKAGE_signalwire-client-c is not set # CONFIG_PACKAGE_sofia-sip is not set # end of Telephony # # libimobiledevice # # CONFIG_PACKAGE_libimobiledevice is not set # CONFIG_PACKAGE_libirecovery is not set # CONFIG_PACKAGE_libplist is not set # CONFIG_PACKAGE_libusbmuxd is not set # end of libimobiledevice # CONFIG_PACKAGE_acsccid is not set # CONFIG_PACKAGE_alsa-lib is not set # CONFIG_PACKAGE_argp-standalone is not set # CONFIG_PACKAGE_bind-libs is not set # CONFIG_PACKAGE_bluez-libs is not set CONFIG_PACKAGE_boost=y # CONFIG_boost-context-exclude is not set # CONFIG_boost-coroutine-exclude is not set # CONFIG_boost-fiber-exclude is not set # # Select Boost Options # # # Boost compilation options. # # CONFIG_boost-compile-visibility-global is not set # CONFIG_boost-compile-visibility-protected is not set CONFIG_boost-compile-visibility-hidden=y # CONFIG_boost-shared-libs is not set # CONFIG_boost-static-libs is not set CONFIG_boost-static-and-shared-libs=y CONFIG_boost-runtime-shared=y CONFIG_boost-variant-release=y # CONFIG_boost-variant-debug is not set # CONFIG_boost-variant-profile is not set # CONFIG_boost-use-name-tags is not set # end of Select Boost Options # # Select Boost libraries # # # Libraries # # CONFIG_boost-libs-all is not set # CONFIG_boost-test-pkg is not set # CONFIG_boost-graph-parallel is not set # CONFIG_PACKAGE_boost-atomic is not set # CONFIG_PACKAGE_boost-chrono is not set # CONFIG_PACKAGE_boost-container is not set # CONFIG_PACKAGE_boost-context is not set # CONFIG_PACKAGE_boost-contract is not set # CONFIG_PACKAGE_boost-coroutine is not set # CONFIG_PACKAGE_boost-date_time is not set # CONFIG_PACKAGE_boost-fiber is not set # CONFIG_PACKAGE_boost-filesystem is not set # CONFIG_PACKAGE_boost-graph is not set # CONFIG_PACKAGE_boost-iostreams is not set # CONFIG_PACKAGE_boost-json is not set # CONFIG_PACKAGE_boost-locale is not set # CONFIG_PACKAGE_boost-log is not set # CONFIG_PACKAGE_boost-math is not set # CONFIG_PACKAGE_boost-nowide is not set CONFIG_PACKAGE_boost-program_options=y # CONFIG_PACKAGE_boost-python3 is not set # CONFIG_PACKAGE_boost-random is not set # CONFIG_PACKAGE_boost-regex is not set # CONFIG_PACKAGE_boost-serialization is not set # CONFIG_PACKAGE_boost-wserialization is not set # CONFIG_PACKAGE_boost-stacktrace is not set CONFIG_PACKAGE_boost-system=y # CONFIG_PACKAGE_boost-thread is not set # CONFIG_PACKAGE_boost-timer is not set # CONFIG_PACKAGE_boost-type_erasure is not set # CONFIG_PACKAGE_boost-wave is not set # end of Select Boost libraries # CONFIG_PACKAGE_cJSON is not set # CONFIG_PACKAGE_ccid is not set # CONFIG_PACKAGE_check is not set # CONFIG_PACKAGE_confuse is not set # CONFIG_PACKAGE_czmq is not set # CONFIG_PACKAGE_dtndht is not set # CONFIG_PACKAGE_getdns is not set # CONFIG_PACKAGE_giflib is not set # CONFIG_PACKAGE_glib2 is not set # CONFIG_PACKAGE_google-authenticator-libpam is not set # CONFIG_PACKAGE_hidapi is not set # CONFIG_PACKAGE_ibrcommon is not set # CONFIG_PACKAGE_ibrdtn is not set # CONFIG_PACKAGE_icu is not set # CONFIG_PACKAGE_icu-data-tools is not set # CONFIG_PACKAGE_icu-full-data is not set # CONFIG_PACKAGE_jansson is not set # CONFIG_PACKAGE_json-glib is not set # CONFIG_PACKAGE_jsoncpp is not set # CONFIG_PACKAGE_knot-libs is not set # CONFIG_PACKAGE_knot-libzscanner is not set # CONFIG_PACKAGE_libaio is not set # CONFIG_PACKAGE_libantlr3c is not set # CONFIG_PACKAGE_libao is not set # CONFIG_PACKAGE_libapparmor is not set # CONFIG_PACKAGE_libapr is not set # CONFIG_PACKAGE_libaprutil is not set # CONFIG_PACKAGE_libarchive is not set # CONFIG_PACKAGE_libarchive-noopenssl is not set # CONFIG_PACKAGE_libasm is not set # CONFIG_PACKAGE_libassuan is not set # CONFIG_PACKAGE_libatasmart is not set # CONFIG_PACKAGE_libaudit is not set # CONFIG_PACKAGE_libauparse is not set # CONFIG_PACKAGE_libavahi-client is not set # CONFIG_PACKAGE_libavahi-compat-libdnssd is not set # CONFIG_PACKAGE_libavahi-dbus-support is not set # CONFIG_PACKAGE_libavahi-nodbus-support is not set # CONFIG_PACKAGE_libbfd is not set CONFIG_PACKAGE_libblkid=y CONFIG_PACKAGE_libblobmsg-json=y CONFIG_PACKAGE_libbpf=y # CONFIG_PACKAGE_libbsd is not set CONFIG_PACKAGE_libcap=y # CONFIG_PACKAGE_libcap-bin is not set # CONFIG_PACKAGE_libcap-ng is not set # CONFIG_PACKAGE_libcares is not set # CONFIG_PACKAGE_libcbor is not set # CONFIG_PACKAGE_libcgroup is not set # CONFIG_PACKAGE_libcharset is not set # CONFIG_PACKAGE_libcoap is not set CONFIG_PACKAGE_libcomerr=y # CONFIG_PACKAGE_libconfig is not set # CONFIG_PACKAGE_libcryptopp is not set # CONFIG_PACKAGE_libctf is not set CONFIG_PACKAGE_libcurl=y # # SSL support # # CONFIG_LIBCURL_MBEDTLS is not set # CONFIG_LIBCURL_WOLFSSL is not set CONFIG_LIBCURL_OPENSSL=y # CONFIG_LIBCURL_GNUTLS is not set # CONFIG_LIBCURL_NOSSL is not set # # Supported protocols # # CONFIG_LIBCURL_DICT is not set CONFIG_LIBCURL_FILE=y CONFIG_LIBCURL_FTP=y # CONFIG_LIBCURL_GOPHER is not set CONFIG_LIBCURL_HTTP=y CONFIG_LIBCURL_COOKIES=y # CONFIG_LIBCURL_IMAP is not set # CONFIG_LIBCURL_LDAP is not set # CONFIG_LIBCURL_POP3 is not set # CONFIG_LIBCURL_RTSP is not set # CONFIG_LIBCURL_SSH2 is not set CONFIG_LIBCURL_NO_SMB="!" # CONFIG_LIBCURL_SMTP is not set # CONFIG_LIBCURL_TELNET is not set # CONFIG_LIBCURL_TFTP is not set # CONFIG_LIBCURL_NGHTTP2 is not set # # Miscellaneous # CONFIG_LIBCURL_PROXY=y # CONFIG_LIBCURL_CRYPTO_AUTH is not set # CONFIG_LIBCURL_TLS_SRP is not set # CONFIG_LIBCURL_LIBIDN2 is not set # CONFIG_LIBCURL_THREADED_RESOLVER is not set # CONFIG_LIBCURL_ZLIB is not set # CONFIG_LIBCURL_ZSTD is not set # CONFIG_LIBCURL_UNIX_SOCKETS is not set # CONFIG_LIBCURL_LIBCURL_OPTION is not set # CONFIG_LIBCURL_VERBOSE is not set # CONFIG_PACKAGE_libdaemon is not set # CONFIG_PACKAGE_libdaq is not set # CONFIG_PACKAGE_libdaq3 is not set # CONFIG_PACKAGE_libdb47 is not set # CONFIG_PACKAGE_libdb47xx is not set # CONFIG_PACKAGE_libdbi is not set # CONFIG_PACKAGE_libdbus is not set # CONFIG_PACKAGE_libdevmapper is not set # CONFIG_PACKAGE_libdevmapper-selinux is not set # CONFIG_PACKAGE_libdmapsharing is not set # CONFIG_PACKAGE_libdnet is not set # CONFIG_PACKAGE_libdouble-conversion is not set # CONFIG_PACKAGE_libdrm is not set # CONFIG_PACKAGE_libdw is not set # CONFIG_PACKAGE_libecdsautil is not set # CONFIG_PACKAGE_libedit is not set CONFIG_PACKAGE_libelf=y # CONFIG_PACKAGE_libesmtp is not set # CONFIG_PACKAGE_libestr is not set CONFIG_PACKAGE_libev=y CONFIG_PACKAGE_libevdev=y # CONFIG_PACKAGE_libevent2 is not set # CONFIG_PACKAGE_libevent2-core is not set # CONFIG_PACKAGE_libevent2-extra is not set # CONFIG_PACKAGE_libevent2-openssl is not set # CONFIG_PACKAGE_libevent2-pthreads is not set # CONFIG_PACKAGE_libexif is not set # CONFIG_PACKAGE_libexpat is not set # CONFIG_PACKAGE_libexslt is not set CONFIG_PACKAGE_libext2fs=y # CONFIG_PACKAGE_libextractor is not set # CONFIG_PACKAGE_libf2fs is not set # CONFIG_PACKAGE_libf2fs-selinux is not set # CONFIG_PACKAGE_libfaad2 is not set # CONFIG_PACKAGE_libfastjson is not set # CONFIG_PACKAGE_libfdisk is not set # CONFIG_PACKAGE_libfdt is not set # CONFIG_PACKAGE_libffi is not set # CONFIG_PACKAGE_libffmpeg-audio-dec is not set # CONFIG_PACKAGE_libffmpeg-custom is not set # CONFIG_PACKAGE_libffmpeg-full is not set # CONFIG_PACKAGE_libffmpeg-mini is not set # CONFIG_PACKAGE_libfido2 is not set # CONFIG_PACKAGE_libflac is not set # CONFIG_PACKAGE_libfmt is not set # CONFIG_PACKAGE_libfreetype is not set # CONFIG_PACKAGE_libfstrm is not set # CONFIG_PACKAGE_libftdi is not set # CONFIG_PACKAGE_libftdi1 is not set # CONFIG_PACKAGE_libgabe is not set # CONFIG_PACKAGE_libgcrypt is not set # CONFIG_PACKAGE_libgd is not set # CONFIG_PACKAGE_libgd-full is not set # CONFIG_PACKAGE_libgdbm is not set # CONFIG_PACKAGE_libgee is not set # CONFIG_PACKAGE_libgmp is not set # CONFIG_PACKAGE_libgnurl is not set # CONFIG_PACKAGE_libgpg-error is not set # CONFIG_PACKAGE_libgpgme is not set # CONFIG_PACKAGE_libgpgmepp is not set # CONFIG_PACKAGE_libgphoto2 is not set # CONFIG_PACKAGE_libgpiod is not set # CONFIG_PACKAGE_libgps is not set # CONFIG_PACKAGE_libh2o is not set # CONFIG_PACKAGE_libh2o-evloop is not set # CONFIG_PACKAGE_libhamlib is not set # CONFIG_PACKAGE_libhavege is not set # CONFIG_PACKAGE_libhiredis is not set # CONFIG_PACKAGE_libhttp-parser is not set # CONFIG_PACKAGE_libhwloc is not set # CONFIG_PACKAGE_libi2c is not set # CONFIG_PACKAGE_libical is not set # CONFIG_PACKAGE_libiconv is not set # CONFIG_PACKAGE_libiconv-full is not set # CONFIG_PACKAGE_libid3tag is not set # CONFIG_PACKAGE_libidn is not set # CONFIG_PACKAGE_libidn2 is not set # CONFIG_PACKAGE_libiio is not set # CONFIG_PACKAGE_libinotifytools is not set # CONFIG_PACKAGE_libinput is not set # CONFIG_PACKAGE_libintl is not set # CONFIG_PACKAGE_libintl-full is not set # CONFIG_PACKAGE_libipfs-http-client is not set # CONFIG_PACKAGE_libiw is not set CONFIG_PACKAGE_libiwinfo=y # CONFIG_PACKAGE_libjpeg-turbo is not set CONFIG_PACKAGE_libjson-c=y # CONFIG_PACKAGE_libkeyutils is not set # CONFIG_PACKAGE_libkmod is not set # CONFIG_PACKAGE_libksba is not set # CONFIG_PACKAGE_libldns is not set # CONFIG_PACKAGE_libleptonica is not set # CONFIG_PACKAGE_libloragw is not set # CONFIG_PACKAGE_libltdl is not set CONFIG_PACKAGE_liblua=y # CONFIG_PACKAGE_liblua5.3 is not set CONFIG_PACKAGE_liblzo=y # CONFIG_PACKAGE_libmad is not set # CONFIG_PACKAGE_libmagic is not set # CONFIG_PACKAGE_libmaxminddb is not set # CONFIG_PACKAGE_libmbim is not set # CONFIG_PACKAGE_libmcrypt is not set # CONFIG_PACKAGE_libmicrohttpd-no-ssl is not set # CONFIG_PACKAGE_libmicrohttpd-ssl is not set # CONFIG_PACKAGE_libmilter-sendmail is not set CONFIG_PACKAGE_libminiupnpc=y # CONFIG_PACKAGE_libmms is not set CONFIG_PACKAGE_libmnl=y # CONFIG_PACKAGE_libmodbus is not set # CONFIG_PACKAGE_libmosquitto-nossl is not set # CONFIG_PACKAGE_libmosquitto-ssl is not set CONFIG_PACKAGE_libmount=y # CONFIG_PACKAGE_libmpdclient is not set # CONFIG_PACKAGE_libmpeg2 is not set # CONFIG_PACKAGE_libmpg123 is not set CONFIG_PACKAGE_libnatpmp=y CONFIG_PACKAGE_libncurses=y # CONFIG_PACKAGE_libndpi is not set # CONFIG_PACKAGE_libneon is not set # CONFIG_PACKAGE_libnet-1.2.x is not set # CONFIG_PACKAGE_libnetconf2 is not set # CONFIG_PACKAGE_libnetfilter-acct is not set # CONFIG_PACKAGE_libnetfilter-conntrack is not set # CONFIG_PACKAGE_libnetfilter-cthelper is not set # CONFIG_PACKAGE_libnetfilter-cttimeout is not set # CONFIG_PACKAGE_libnetfilter-log is not set # CONFIG_PACKAGE_libnetfilter-queue is not set # CONFIG_PACKAGE_libnetsnmp is not set # CONFIG_PACKAGE_libnettle is not set # CONFIG_PACKAGE_libnewt is not set # CONFIG_PACKAGE_libnfnetlink is not set # CONFIG_PACKAGE_libnftnl is not set # CONFIG_PACKAGE_libnghttp2 is not set # CONFIG_PACKAGE_libnl is not set # CONFIG_PACKAGE_libnl-core is not set # CONFIG_PACKAGE_libnl-genl is not set # CONFIG_PACKAGE_libnl-nf is not set # CONFIG_PACKAGE_libnl-route is not set CONFIG_PACKAGE_libnl-tiny=y # CONFIG_PACKAGE_libnopoll is not set # CONFIG_PACKAGE_libnpth is not set # CONFIG_PACKAGE_libnpupnp is not set # CONFIG_PACKAGE_libogg is not set # CONFIG_PACKAGE_liboil is not set # CONFIG_PACKAGE_libopcodes is not set # CONFIG_PACKAGE_libopendkim is not set # CONFIG_PACKAGE_libopenobex is not set # CONFIG_PACKAGE_libopensc is not set # CONFIG_PACKAGE_libopenzwave is not set # CONFIG_PACKAGE_liboping is not set # CONFIG_PACKAGE_libopus is not set # CONFIG_PACKAGE_libopusenc is not set # CONFIG_PACKAGE_libopusfile is not set # CONFIG_PACKAGE_liborcania is not set # CONFIG_PACKAGE_libout123 is not set # CONFIG_PACKAGE_libowipcalc is not set # CONFIG_PACKAGE_libp11 is not set # CONFIG_PACKAGE_libpagekite is not set # CONFIG_PACKAGE_libpam is not set # CONFIG_PACKAGE_libpbc is not set # CONFIG_PACKAGE_libpcap is not set # CONFIG_PACKAGE_libpci is not set # CONFIG_PACKAGE_libpciaccess is not set CONFIG_PACKAGE_libpcre=y # CONFIG_PCRE_JIT_ENABLED is not set # CONFIG_PACKAGE_libpcre16 is not set # CONFIG_PACKAGE_libpcre2 is not set # CONFIG_PACKAGE_libpcre2-16 is not set # CONFIG_PACKAGE_libpcre2-32 is not set # CONFIG_PACKAGE_libpcre32 is not set # CONFIG_PACKAGE_libpcsclite is not set # CONFIG_PACKAGE_libpfring is not set # CONFIG_PACKAGE_libpkcs11-spy is not set # CONFIG_PACKAGE_libpkgconf is not set # CONFIG_PACKAGE_libpng is not set # CONFIG_PACKAGE_libpopt is not set # CONFIG_PACKAGE_libpri is not set # CONFIG_PACKAGE_libprotobuf-c is not set # CONFIG_PACKAGE_libpsl is not set # CONFIG_PACKAGE_libqmi is not set # CONFIG_PACKAGE_libqrencode is not set # CONFIG_PACKAGE_libqrtr-glib is not set # CONFIG_PACKAGE_libradcli is not set # CONFIG_PACKAGE_libradiotap is not set CONFIG_PACKAGE_libreadline=y # CONFIG_PACKAGE_libredblack is not set # CONFIG_PACKAGE_librouteros is not set # CONFIG_PACKAGE_libroxml is not set # CONFIG_PACKAGE_librrd1 is not set # CONFIG_PACKAGE_librtlsdr is not set # CONFIG_PACKAGE_libruby is not set # CONFIG_PACKAGE_libsamplerate is not set # CONFIG_PACKAGE_libsane is not set # CONFIG_PACKAGE_libsasl2 is not set # CONFIG_PACKAGE_libsearpc is not set # CONFIG_PACKAGE_libseccomp is not set # CONFIG_PACKAGE_libselinux is not set # CONFIG_PACKAGE_libsemanage is not set # CONFIG_PACKAGE_libsensors is not set # CONFIG_PACKAGE_libsepol is not set # CONFIG_PACKAGE_libshout is not set # CONFIG_PACKAGE_libshout-full is not set # CONFIG_PACKAGE_libshout-nossl is not set # CONFIG_PACKAGE_libsispmctl is not set # CONFIG_PACKAGE_libslang2 is not set # CONFIG_PACKAGE_libslang2-mod-base64 is not set # CONFIG_PACKAGE_libslang2-mod-chksum is not set # CONFIG_PACKAGE_libslang2-mod-csv is not set # CONFIG_PACKAGE_libslang2-mod-fcntl is not set # CONFIG_PACKAGE_libslang2-mod-fork is not set # CONFIG_PACKAGE_libslang2-mod-histogram is not set # CONFIG_PACKAGE_libslang2-mod-iconv is not set # CONFIG_PACKAGE_libslang2-mod-json is not set # CONFIG_PACKAGE_libslang2-mod-onig is not set # CONFIG_PACKAGE_libslang2-mod-pcre is not set # CONFIG_PACKAGE_libslang2-mod-png is not set # CONFIG_PACKAGE_libslang2-mod-rand is not set # CONFIG_PACKAGE_libslang2-mod-select is not set # CONFIG_PACKAGE_libslang2-mod-slsmg is not set # CONFIG_PACKAGE_libslang2-mod-socket is not set # CONFIG_PACKAGE_libslang2-mod-stats is not set # CONFIG_PACKAGE_libslang2-mod-sysconf is not set # CONFIG_PACKAGE_libslang2-mod-termios is not set # CONFIG_PACKAGE_libslang2-mod-varray is not set # CONFIG_PACKAGE_libslang2-mod-zlib is not set # CONFIG_PACKAGE_libslang2-modules is not set CONFIG_PACKAGE_libsmartcols=y # CONFIG_PACKAGE_libsndfile is not set # CONFIG_PACKAGE_libsoc is not set # CONFIG_PACKAGE_libsocks is not set CONFIG_PACKAGE_libsodium=y # # Configuration # CONFIG_LIBSODIUM_MINIMAL=y # end of Configuration # CONFIG_PACKAGE_libsoup is not set # CONFIG_PACKAGE_libsoxr is not set # CONFIG_PACKAGE_libspeex is not set # CONFIG_PACKAGE_libspeexdsp is not set # CONFIG_PACKAGE_libspice-server is not set CONFIG_PACKAGE_libss=y # CONFIG_PACKAGE_libssh is not set # CONFIG_PACKAGE_libssh2 is not set # CONFIG_PACKAGE_libstoken is not set # CONFIG_PACKAGE_libstrophe is not set # CONFIG_PACKAGE_libsyn123 is not set # CONFIG_PACKAGE_libsysrepo is not set # CONFIG_PACKAGE_libtalloc is not set # CONFIG_PACKAGE_libtasn1 is not set # CONFIG_PACKAGE_libtheora is not set # CONFIG_PACKAGE_libtiff is not set # CONFIG_PACKAGE_libtins is not set CONFIG_PACKAGE_libtirpc=y # CONFIG_PACKAGE_libtorrent-rasterbar is not set CONFIG_PACKAGE_libubox=y # CONFIG_PACKAGE_libubox-lua is not set CONFIG_PACKAGE_libubus=y CONFIG_PACKAGE_libubus-lua=y CONFIG_PACKAGE_libuci=y CONFIG_PACKAGE_libuci-lua=y # CONFIG_PACKAGE_libuci2 is not set CONFIG_PACKAGE_libuclient=y CONFIG_PACKAGE_libudev-zero=y CONFIG_PACKAGE_libudns=y # CONFIG_PACKAGE_libuecc is not set # CONFIG_PACKAGE_libugpio is not set # CONFIG_PACKAGE_libunistring is not set # CONFIG_PACKAGE_libunwind is not set # CONFIG_PACKAGE_libupnp is not set # CONFIG_PACKAGE_libupnpp is not set # CONFIG_PACKAGE_liburcu is not set # CONFIG_PACKAGE_liburing is not set CONFIG_PACKAGE_libusb-1.0=y # CONFIG_PACKAGE_libusb-compat is not set # CONFIG_PACKAGE_libustream-mbedtls is not set CONFIG_PACKAGE_libustream-openssl=y # CONFIG_PACKAGE_libustream-wolfssl is not set CONFIG_PACKAGE_libuuid=y CONFIG_PACKAGE_libuv=y # CONFIG_PACKAGE_libuwifi is not set # CONFIG_PACKAGE_libv4l is not set # CONFIG_PACKAGE_libvorbis is not set # CONFIG_PACKAGE_libvorbisidec is not set # CONFIG_PACKAGE_libvpx is not set # CONFIG_PACKAGE_libwebp is not set CONFIG_PACKAGE_libwebsockets-full=y # CONFIG_PACKAGE_libwebsockets-mbedtls is not set # CONFIG_PACKAGE_libwebsockets-openssl is not set # CONFIG_PACKAGE_libwrap is not set # CONFIG_PACKAGE_libwxbase is not set # CONFIG_PACKAGE_libxerces-c is not set # CONFIG_PACKAGE_libxerces-c-samples is not set # CONFIG_PACKAGE_libxml2 is not set # CONFIG_PACKAGE_libxslt is not set # CONFIG_PACKAGE_libyaml-cpp is not set # CONFIG_PACKAGE_libyang is not set # CONFIG_PACKAGE_libyang-cpp is not set # CONFIG_PACKAGE_libyubikey is not set # CONFIG_PACKAGE_libzmq-curve is not set # CONFIG_PACKAGE_libzmq-nc is not set # CONFIG_PACKAGE_linux-atm is not set # CONFIG_PACKAGE_lmdb is not set # CONFIG_PACKAGE_log4cplus is not set # CONFIG_PACKAGE_loudmouth is not set # CONFIG_PACKAGE_lttng-ust is not set # CONFIG_PACKAGE_minizip is not set # CONFIG_PACKAGE_msgpack-c is not set # CONFIG_PACKAGE_mtdev is not set # CONFIG_PACKAGE_musl-fts is not set # CONFIG_PACKAGE_mxml is not set # CONFIG_PACKAGE_nspr is not set # CONFIG_PACKAGE_oniguruma is not set # CONFIG_PACKAGE_open-isns is not set # CONFIG_PACKAGE_openpgm is not set # CONFIG_PACKAGE_p11-kit is not set # CONFIG_PACKAGE_pixman is not set # CONFIG_PACKAGE_poco is not set # CONFIG_PACKAGE_poco-all is not set # CONFIG_PACKAGE_protobuf is not set # CONFIG_PACKAGE_protobuf-lite is not set # CONFIG_PACKAGE_pthsem is not set # CONFIG_PACKAGE_rblibtorrent is not set # CONFIG_PACKAGE_re2 is not set CONFIG_PACKAGE_rpcd-mod-rrdns=y # CONFIG_PACKAGE_sbc is not set # CONFIG_PACKAGE_serdisplib is not set # CONFIG_PACKAGE_taglib is not set CONFIG_PACKAGE_terminfo=y # CONFIG_PACKAGE_tinycdb is not set # CONFIG_PACKAGE_uclibcxx is not set # CONFIG_PACKAGE_uw-imap is not set # CONFIG_PACKAGE_xmlrpc-c is not set # CONFIG_PACKAGE_xmlrpc-c-client is not set # CONFIG_PACKAGE_xmlrpc-c-server is not set # CONFIG_PACKAGE_yajl is not set # CONFIG_PACKAGE_yubico-pam is not set CONFIG_PACKAGE_zlib=y # # Configuration # CONFIG_ZLIB_OPTIMIZE_SPEED=y # end of Configuration # end of Libraries # # LuCI # # # 1. Collections # CONFIG_PACKAGE_luci=y # CONFIG_PACKAGE_luci-nginx is not set # CONFIG_PACKAGE_luci-ssl-nginx is not set # CONFIG_PACKAGE_luci-ssl-openssl is not set # end of 1. Collections # # 2. Modules # CONFIG_PACKAGE_luci-base=y # CONFIG_LUCI_SRCDIET is not set # # Translations # # CONFIG_LUCI_LANG_hu is not set # CONFIG_LUCI_LANG_pt is not set # CONFIG_LUCI_LANG_no is not set # CONFIG_LUCI_LANG_sk is not set # CONFIG_LUCI_LANG_el is not set # CONFIG_LUCI_LANG_uk is not set # CONFIG_LUCI_LANG_ru is not set # CONFIG_LUCI_LANG_vi is not set # CONFIG_LUCI_LANG_de is not set # CONFIG_LUCI_LANG_ro is not set # CONFIG_LUCI_LANG_ms is not set # CONFIG_LUCI_LANG_pl is not set CONFIG_LUCI_LANG_zh-cn=y # CONFIG_LUCI_LANG_ko is not set # CONFIG_LUCI_LANG_he is not set # CONFIG_LUCI_LANG_zh-tw is not set # CONFIG_LUCI_LANG_tr is not set # CONFIG_LUCI_LANG_sv is not set # CONFIG_LUCI_LANG_ja is not set # CONFIG_LUCI_LANG_pt-br is not set # CONFIG_LUCI_LANG_ca is not set # CONFIG_LUCI_LANG_en is not set # CONFIG_LUCI_LANG_es is not set # CONFIG_LUCI_LANG_cs is not set # CONFIG_LUCI_LANG_fr is not set # CONFIG_LUCI_LANG_it is not set # end of Translations CONFIG_PACKAGE_luci-compat=y CONFIG_PACKAGE_luci-mod-admin-full=y # CONFIG_PACKAGE_luci-mod-failsafe is not set # CONFIG_PACKAGE_luci-mod-rpc is not set # CONFIG_PACKAGE_luci-newapi is not set # end of 2. Modules # # 3. Applications # CONFIG_PACKAGE_luci-app-accesscontrol=y # CONFIG_PACKAGE_luci-app-adblock is not set CONFIG_PACKAGE_luci-app-adbyby-plus=y # CONFIG_PACKAGE_luci-app-advanced-reboot is not set # CONFIG_PACKAGE_luci-app-ahcp is not set # CONFIG_PACKAGE_luci-app-airplay2 is not set # CONFIG_PACKAGE_luci-app-amule is not set # CONFIG_PACKAGE_luci-app-aria2 is not set # CONFIG_PACKAGE_luci-app-arpbind is not set # CONFIG_PACKAGE_luci-app-asterisk is not set # CONFIG_PACKAGE_luci-app-attendedsysupgrade is not set CONFIG_PACKAGE_luci-app-autoreboot=y # CONFIG_PACKAGE_luci-app-baidupcs-web is not set # CONFIG_PACKAGE_luci-app-bcp38 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv4 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv6 is not set # CONFIG_PACKAGE_luci-app-bmx6 is not set CONFIG_PACKAGE_luci-app-cifs-mount=y # CONFIG_PACKAGE_luci-app-cifsd is not set # CONFIG_PACKAGE_luci-app-cjdns is not set # CONFIG_PACKAGE_luci-app-clamav is not set # CONFIG_PACKAGE_luci-app-commands is not set # CONFIG_PACKAGE_luci-app-control-timewol is not set # CONFIG_PACKAGE_luci-app-control-webrestriction is not set # CONFIG_PACKAGE_luci-app-control-weburl is not set # CONFIG_PACKAGE_luci-app-cshark is not set CONFIG_PACKAGE_luci-app-ddns=y # CONFIG_PACKAGE_luci-app-diag-core is not set CONFIG_PACKAGE_luci-app-diskman=y CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs=y CONFIG_PACKAGE_luci-app-diskman_INCLUDE_lsblk=y # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_mdadm is not set # CONFIG_PACKAGE_luci-app-dnscrypt-proxy is not set # CONFIG_PACKAGE_luci-app-dnsforwarder is not set # CONFIG_PACKAGE_luci-app-docker is not set # CONFIG_PACKAGE_luci-app-dump1090 is not set # CONFIG_PACKAGE_luci-app-dynapoint is not set # CONFIG_PACKAGE_luci-app-e2guardian is not set # CONFIG_PACKAGE_luci-app-easymesh is not set # CONFIG_PACKAGE_luci-app-familycloud is not set # CONFIG_PACKAGE_luci-app-fileassistant is not set # CONFIG_PACKAGE_luci-app-filebrowser is not set # CONFIG_PACKAGE_luci-app-filetransfer is not set CONFIG_PACKAGE_luci-app-firewall=y # CONFIG_PACKAGE_luci-app-frpc is not set # CONFIG_PACKAGE_luci-app-frps is not set # CONFIG_PACKAGE_luci-app-fwknopd is not set # CONFIG_PACKAGE_luci-app-guest-wifi is not set # CONFIG_PACKAGE_luci-app-haproxy-tcp is not set # CONFIG_PACKAGE_luci-app-hd-idle is not set # CONFIG_PACKAGE_luci-app-hnet is not set # CONFIG_PACKAGE_luci-app-https-dns-proxy is not set # CONFIG_PACKAGE_luci-app-ipsec-server is not set # CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set # CONFIG_PACKAGE_luci-app-jd-dailybonus is not set # CONFIG_PACKAGE_luci-app-kodexplorer is not set # CONFIG_PACKAGE_luci-app-lxc is not set # CONFIG_PACKAGE_luci-app-minidlna is not set # CONFIG_PACKAGE_luci-app-mjpg-streamer is not set # CONFIG_PACKAGE_luci-app-music-remote-center is not set # CONFIG_PACKAGE_luci-app-mwan3 is not set # CONFIG_PACKAGE_luci-app-mwan3helper is not set # CONFIG_PACKAGE_luci-app-n2n_v2 is not set CONFIG_PACKAGE_luci-app-netdata=y # CONFIG_PACKAGE_luci-app-nfs is not set # CONFIG_PACKAGE_luci-app-nft-qos is not set # CONFIG_PACKAGE_luci-app-nginx-pingos is not set # CONFIG_PACKAGE_luci-app-nlbwmon is not set # CONFIG_PACKAGE_luci-app-noddos is not set # CONFIG_PACKAGE_luci-app-nps is not set # CONFIG_PACKAGE_luci-app-ntpc is not set # CONFIG_PACKAGE_luci-app-ocserv is not set # CONFIG_PACKAGE_luci-app-olsr is not set # CONFIG_PACKAGE_luci-app-olsr-services is not set # CONFIG_PACKAGE_luci-app-olsr-viz is not set # CONFIG_PACKAGE_luci-app-openclash is not set # CONFIG_PACKAGE_luci-app-openvpn is not set # CONFIG_PACKAGE_luci-app-openvpn-server is not set # CONFIG_PACKAGE_luci-app-p910nd is not set # CONFIG_PACKAGE_luci-app-pagekitec is not set CONFIG_PACKAGE_luci-app-passwall=y # # Configuration # # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ChinaDNS_NG=y CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Dns2socks=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Haproxy is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Hysteria is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Kcptun is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_NaiveProxy is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_PDNSD=y CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Libev_Client=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Libev_Server is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Rust_Client is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_Libev_Client=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_Libev_Server is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Simple_Obfs=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_GO is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_Plus=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray_Plugin is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Xray=y # end of Configuration # CONFIG_PACKAGE_luci-app-polipo is not set # CONFIG_PACKAGE_luci-app-pppoe-relay is not set # CONFIG_PACKAGE_luci-app-pppoe-server is not set # CONFIG_PACKAGE_luci-app-pptp-server is not set # CONFIG_PACKAGE_luci-app-privoxy is not set # CONFIG_PACKAGE_luci-app-ps3netsrv is not set # CONFIG_PACKAGE_luci-app-pushbot is not set # CONFIG_PACKAGE_luci-app-qbittorrent is not set CONFIG_PACKAGE_luci-app-qbittorrent_dynamic=y # CONFIG_PACKAGE_luci-app-qos is not set # CONFIG_PACKAGE_luci-app-radicale is not set CONFIG_PACKAGE_luci-app-ramfree=y # CONFIG_PACKAGE_luci-app-rclone is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-webui is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-ng is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_fuse-utils is not set # CONFIG_PACKAGE_luci-app-rp-pppoe-server is not set CONFIG_PACKAGE_luci-app-samba=y # CONFIG_PACKAGE_luci-app-samba4 is not set # CONFIG_PACKAGE_luci-app-shadowsocks-libev is not set # CONFIG_PACKAGE_luci-app-shairplay is not set # CONFIG_PACKAGE_luci-app-siitwizard is not set # CONFIG_PACKAGE_luci-app-simple-adblock is not set # CONFIG_PACKAGE_luci-app-socat is not set # CONFIG_PACKAGE_luci-app-softethervpn is not set # CONFIG_PACKAGE_luci-app-splash is not set # CONFIG_PACKAGE_luci-app-sqm is not set # CONFIG_PACKAGE_luci-app-squid is not set # CONFIG_PACKAGE_luci-app-ssr-mudb-server is not set CONFIG_PACKAGE_luci-app-ssr-plus=y # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_NaiveProxy is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Redsocks2 is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Shadowsocks_Libev_Client is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Shadowsocks_Libev_Server is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Shadowsocks_Rust_Client is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Shadowsocks_Rust_Server is not set CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Libev_Client=y # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Libev_Server is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Simple_Obfs is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_Plugin is not set CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Xray=y # CONFIG_PACKAGE_luci-app-ssrserver-python is not set # CONFIG_PACKAGE_luci-app-statistics is not set # CONFIG_PACKAGE_luci-app-syncdial is not set # CONFIG_PACKAGE_luci-app-syncthing is not set # CONFIG_PACKAGE_luci-app-timecontrol is not set # CONFIG_PACKAGE_luci-app-tinyproxy is not set # CONFIG_PACKAGE_luci-app-transmission is not set # CONFIG_PACKAGE_luci-app-travelmate is not set CONFIG_PACKAGE_luci-app-ttyd=y CONFIG_PACKAGE_luci-app-turboacc=y CONFIG_PACKAGE_TURBOACC_INCLUDE_OFFLOADING=y # CONFIG_PACKAGE_TURBOACC_INCLUDE_SHORTCUT_FE is not set CONFIG_PACKAGE_TURBOACC_INCLUDE_BBR_CCA=y # CONFIG_PACKAGE_TURBOACC_INCLUDE_DNSFORWARDER is not set # CONFIG_PACKAGE_TURBOACC_INCLUDE_DNSPROXY is not set # CONFIG_PACKAGE_luci-app-udpxy is not set # CONFIG_PACKAGE_luci-app-uhttpd is not set # CONFIG_PACKAGE_luci-app-unblockmusic is not set # CONFIG_PACKAGE_luci-app-unblockmusic_INCLUDE_UnblockNeteaseMusic_Go is not set # CONFIG_PACKAGE_luci-app-unblockmusic_INCLUDE_UnblockNeteaseMusic_NodeJS is not set # CONFIG_PACKAGE_luci-app-unbound is not set CONFIG_PACKAGE_luci-app-upnp=y # CONFIG_PACKAGE_luci-app-usb-printer is not set # CONFIG_PACKAGE_luci-app-uugamebooster is not set # CONFIG_PACKAGE_luci-app-v2ray-server is not set # CONFIG_PACKAGE_luci-app-verysync is not set CONFIG_PACKAGE_luci-app-vlmcsd=y # CONFIG_PACKAGE_luci-app-vnstat is not set # CONFIG_PACKAGE_luci-app-vpnbypass is not set # CONFIG_PACKAGE_luci-app-vsftpd is not set # CONFIG_PACKAGE_luci-app-watchcat is not set # CONFIG_PACKAGE_luci-app-webadmin is not set # CONFIG_PACKAGE_luci-app-wifischedule is not set # CONFIG_PACKAGE_luci-app-wireguard is not set # CONFIG_PACKAGE_luci-app-wol is not set # CONFIG_PACKAGE_luci-app-wrtbwmon is not set # CONFIG_PACKAGE_luci-app-xlnetacc is not set CONFIG_PACKAGE_luci-app-zerotier=y # end of 3. Applications # # 4. Themes # # CONFIG_PACKAGE_luci-theme-argon is not set CONFIG_PACKAGE_luci-theme-bootstrap=y # CONFIG_PACKAGE_luci-theme-material is not set # CONFIG_PACKAGE_luci-theme-netgear is not set # end of 4. Themes # # 5. Protocols # # CONFIG_PACKAGE_luci-proto-3g is not set # CONFIG_PACKAGE_luci-proto-bonding is not set # CONFIG_PACKAGE_luci-proto-ipip is not set # CONFIG_PACKAGE_luci-proto-ipv6 is not set # CONFIG_PACKAGE_luci-proto-ncm is not set # CONFIG_PACKAGE_luci-proto-openconnect is not set CONFIG_PACKAGE_luci-proto-ppp=y # CONFIG_PACKAGE_luci-proto-qmi is not set # CONFIG_PACKAGE_luci-proto-relay is not set # CONFIG_PACKAGE_luci-proto-vpnc is not set # CONFIG_PACKAGE_luci-proto-wireguard is not set # end of 5. Protocols # # 6. Libraries # # CONFIG_PACKAGE_luci-lib-dracula is not set # CONFIG_PACKAGE_luci-lib-httpclient is not set # CONFIG_PACKAGE_luci-lib-httpprotoutils is not set CONFIG_PACKAGE_luci-lib-ip=y # CONFIG_PACKAGE_luci-lib-iptparser is not set # CONFIG_PACKAGE_luci-lib-jquery-1-4 is not set # CONFIG_PACKAGE_luci-lib-json is not set CONFIG_PACKAGE_luci-lib-jsonc=y # CONFIG_PACKAGE_luci-lib-luaneightbl is not set CONFIG_PACKAGE_luci-lib-nixio=y # CONFIG_PACKAGE_luci-lib-nixio_notls is not set # CONFIG_PACKAGE_luci-lib-nixio_axtls is not set # CONFIG_PACKAGE_luci-lib-nixio_cyassl is not set CONFIG_PACKAGE_luci-lib-nixio_openssl=y # CONFIG_PACKAGE_luci-lib-px5g is not set # end of 6. Libraries CONFIG_PACKAGE_default-settings=y CONFIG_PACKAGE_luci-i18n-accesscontrol-zh-cn=y CONFIG_PACKAGE_luci-i18n-adbyby-plus-zh-cn=y CONFIG_PACKAGE_luci-i18n-autoreboot-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-ca is not set # CONFIG_PACKAGE_luci-i18n-base-cs is not set # CONFIG_PACKAGE_luci-i18n-base-de is not set # CONFIG_PACKAGE_luci-i18n-base-el is not set # CONFIG_PACKAGE_luci-i18n-base-en is not set # CONFIG_PACKAGE_luci-i18n-base-es is not set # CONFIG_PACKAGE_luci-i18n-base-fr is not set # CONFIG_PACKAGE_luci-i18n-base-he is not set # CONFIG_PACKAGE_luci-i18n-base-hu is not set # CONFIG_PACKAGE_luci-i18n-base-it is not set # CONFIG_PACKAGE_luci-i18n-base-ja is not set # CONFIG_PACKAGE_luci-i18n-base-ko is not set # CONFIG_PACKAGE_luci-i18n-base-ms is not set # CONFIG_PACKAGE_luci-i18n-base-no is not set # CONFIG_PACKAGE_luci-i18n-base-pl is not set # CONFIG_PACKAGE_luci-i18n-base-pt is not set # CONFIG_PACKAGE_luci-i18n-base-pt-br is not set # CONFIG_PACKAGE_luci-i18n-base-ro is not set # CONFIG_PACKAGE_luci-i18n-base-ru is not set # CONFIG_PACKAGE_luci-i18n-base-sk is not set # CONFIG_PACKAGE_luci-i18n-base-sv is not set # CONFIG_PACKAGE_luci-i18n-base-tr is not set # CONFIG_PACKAGE_luci-i18n-base-uk is not set # CONFIG_PACKAGE_luci-i18n-base-vi is not set CONFIG_PACKAGE_luci-i18n-base-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-zh-tw is not set CONFIG_PACKAGE_luci-i18n-cifs-mount-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ddns-bg is not set # CONFIG_PACKAGE_luci-i18n-ddns-ca is not set # CONFIG_PACKAGE_luci-i18n-ddns-cs is not set # CONFIG_PACKAGE_luci-i18n-ddns-de is not set # CONFIG_PACKAGE_luci-i18n-ddns-el is not set # CONFIG_PACKAGE_luci-i18n-ddns-en is not set # CONFIG_PACKAGE_luci-i18n-ddns-es is not set # CONFIG_PACKAGE_luci-i18n-ddns-fr is not set # CONFIG_PACKAGE_luci-i18n-ddns-he is not set # CONFIG_PACKAGE_luci-i18n-ddns-hi is not set # CONFIG_PACKAGE_luci-i18n-ddns-hu is not set # CONFIG_PACKAGE_luci-i18n-ddns-it is not set # CONFIG_PACKAGE_luci-i18n-ddns-ja is not set # CONFIG_PACKAGE_luci-i18n-ddns-ko is not set # CONFIG_PACKAGE_luci-i18n-ddns-mr is not set # CONFIG_PACKAGE_luci-i18n-ddns-ms is not set # CONFIG_PACKAGE_luci-i18n-ddns-no is not set # CONFIG_PACKAGE_luci-i18n-ddns-pl is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt-br is not set # CONFIG_PACKAGE_luci-i18n-ddns-ro is not set # CONFIG_PACKAGE_luci-i18n-ddns-ru is not set # CONFIG_PACKAGE_luci-i18n-ddns-sk is not set # CONFIG_PACKAGE_luci-i18n-ddns-sv is not set # CONFIG_PACKAGE_luci-i18n-ddns-tr is not set # CONFIG_PACKAGE_luci-i18n-ddns-uk is not set # CONFIG_PACKAGE_luci-i18n-ddns-vi is not set CONFIG_PACKAGE_luci-i18n-ddns-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ddns-zh-tw is not set # CONFIG_PACKAGE_luci-i18n-firewall-ca is not set # CONFIG_PACKAGE_luci-i18n-firewall-cs is not set # CONFIG_PACKAGE_luci-i18n-firewall-de is not set # CONFIG_PACKAGE_luci-i18n-firewall-el is not set # CONFIG_PACKAGE_luci-i18n-firewall-en is not set # CONFIG_PACKAGE_luci-i18n-firewall-es is not set # CONFIG_PACKAGE_luci-i18n-firewall-fr is not set # CONFIG_PACKAGE_luci-i18n-firewall-he is not set # CONFIG_PACKAGE_luci-i18n-firewall-hu is not set # CONFIG_PACKAGE_luci-i18n-firewall-it is not set # CONFIG_PACKAGE_luci-i18n-firewall-ja is not set # CONFIG_PACKAGE_luci-i18n-firewall-ko is not set # CONFIG_PACKAGE_luci-i18n-firewall-ms is not set # CONFIG_PACKAGE_luci-i18n-firewall-no is not set # CONFIG_PACKAGE_luci-i18n-firewall-pl is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt-br is not set # CONFIG_PACKAGE_luci-i18n-firewall-ro is not set # CONFIG_PACKAGE_luci-i18n-firewall-ru is not set # CONFIG_PACKAGE_luci-i18n-firewall-sk is not set # CONFIG_PACKAGE_luci-i18n-firewall-sv is not set # CONFIG_PACKAGE_luci-i18n-firewall-tr is not set # CONFIG_PACKAGE_luci-i18n-firewall-uk is not set # CONFIG_PACKAGE_luci-i18n-firewall-vi is not set CONFIG_PACKAGE_luci-i18n-firewall-zh-cn=y # CONFIG_PACKAGE_luci-i18n-firewall-zh-tw is not set CONFIG_PACKAGE_luci-i18n-netdata-zh-cn=y CONFIG_PACKAGE_luci-i18n-passwall-zh-cn=y # CONFIG_PACKAGE_luci-i18n-passwall-zh_Hans is not set CONFIG_PACKAGE_luci-i18n-ramfree-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-ca is not set # CONFIG_PACKAGE_luci-i18n-samba-cs is not set # CONFIG_PACKAGE_luci-i18n-samba-de is not set # CONFIG_PACKAGE_luci-i18n-samba-el is not set # CONFIG_PACKAGE_luci-i18n-samba-en is not set # CONFIG_PACKAGE_luci-i18n-samba-es is not set # CONFIG_PACKAGE_luci-i18n-samba-fr is not set # CONFIG_PACKAGE_luci-i18n-samba-he is not set # CONFIG_PACKAGE_luci-i18n-samba-hu is not set # CONFIG_PACKAGE_luci-i18n-samba-it is not set # CONFIG_PACKAGE_luci-i18n-samba-ja is not set # CONFIG_PACKAGE_luci-i18n-samba-ms is not set # CONFIG_PACKAGE_luci-i18n-samba-no is not set # CONFIG_PACKAGE_luci-i18n-samba-pl is not set # CONFIG_PACKAGE_luci-i18n-samba-pt is not set # CONFIG_PACKAGE_luci-i18n-samba-pt-br is not set # CONFIG_PACKAGE_luci-i18n-samba-ro is not set # CONFIG_PACKAGE_luci-i18n-samba-ru is not set # CONFIG_PACKAGE_luci-i18n-samba-sk is not set # CONFIG_PACKAGE_luci-i18n-samba-sv is not set # CONFIG_PACKAGE_luci-i18n-samba-tr is not set # CONFIG_PACKAGE_luci-i18n-samba-uk is not set # CONFIG_PACKAGE_luci-i18n-samba-vi is not set CONFIG_PACKAGE_luci-i18n-samba-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-zh-tw is not set CONFIG_PACKAGE_luci-i18n-ssr-plus-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ssr-plus-zh_Hans is not set CONFIG_PACKAGE_luci-i18n-ttyd-zh-cn=y CONFIG_PACKAGE_luci-i18n-turboacc-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-ca is not set # CONFIG_PACKAGE_luci-i18n-upnp-cs is not set # CONFIG_PACKAGE_luci-i18n-upnp-de is not set # CONFIG_PACKAGE_luci-i18n-upnp-el is not set # CONFIG_PACKAGE_luci-i18n-upnp-en is not set # CONFIG_PACKAGE_luci-i18n-upnp-es is not set # CONFIG_PACKAGE_luci-i18n-upnp-fr is not set # CONFIG_PACKAGE_luci-i18n-upnp-he is not set # CONFIG_PACKAGE_luci-i18n-upnp-hu is not set # CONFIG_PACKAGE_luci-i18n-upnp-it is not set # CONFIG_PACKAGE_luci-i18n-upnp-ja is not set # CONFIG_PACKAGE_luci-i18n-upnp-ms is not set # CONFIG_PACKAGE_luci-i18n-upnp-no is not set # CONFIG_PACKAGE_luci-i18n-upnp-pl is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt-br is not set # CONFIG_PACKAGE_luci-i18n-upnp-ro is not set # CONFIG_PACKAGE_luci-i18n-upnp-ru is not set # CONFIG_PACKAGE_luci-i18n-upnp-sk is not set # CONFIG_PACKAGE_luci-i18n-upnp-sv is not set # CONFIG_PACKAGE_luci-i18n-upnp-tr is not set # CONFIG_PACKAGE_luci-i18n-upnp-uk is not set # CONFIG_PACKAGE_luci-i18n-upnp-vi is not set CONFIG_PACKAGE_luci-i18n-upnp-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-zh-tw is not set CONFIG_PACKAGE_luci-i18n-vlmcsd-zh-cn=y CONFIG_PACKAGE_luci-i18n-zerotier-zh-cn=y # end of LuCI # # Mail # # CONFIG_PACKAGE_alpine is not set # CONFIG_PACKAGE_bogofilter is not set # CONFIG_PACKAGE_dovecot is not set # CONFIG_PACKAGE_dovecot-pigeonhole is not set # CONFIG_PACKAGE_dovecot-utils is not set # CONFIG_PACKAGE_emailrelay is not set # CONFIG_PACKAGE_exim is not set # CONFIG_PACKAGE_exim-gnutls is not set # CONFIG_PACKAGE_exim-ldap is not set # CONFIG_PACKAGE_exim-openssl is not set # CONFIG_PACKAGE_fdm is not set # CONFIG_PACKAGE_greyfix is not set # CONFIG_PACKAGE_mailsend is not set # CONFIG_PACKAGE_mailsend-nossl is not set # CONFIG_PACKAGE_msmtp is not set # CONFIG_PACKAGE_msmtp-mta is not set # CONFIG_PACKAGE_msmtp-nossl is not set # CONFIG_PACKAGE_msmtp-queue is not set # CONFIG_PACKAGE_mutt is not set # CONFIG_PACKAGE_nail is not set # CONFIG_PACKAGE_opendkim is not set # CONFIG_PACKAGE_opendkim-tools is not set # CONFIG_PACKAGE_postfix is not set # # Select postfix build options # CONFIG_POSTFIX_TLS=y CONFIG_POSTFIX_SASL=y CONFIG_POSTFIX_LDAP=y # CONFIG_POSTFIX_DB is not set CONFIG_POSTFIX_CDB=y CONFIG_POSTFIX_SQLITE=y # CONFIG_POSTFIX_MYSQL is not set # CONFIG_POSTFIX_PGSQL is not set CONFIG_POSTFIX_PCRE=y # CONFIG_POSTFIX_EAI is not set # end of Select postfix build options # CONFIG_PACKAGE_spamc is not set # CONFIG_PACKAGE_spamc-ssl is not set # end of Mail # # Multimedia # # # Streaming # # CONFIG_PACKAGE_oggfwd is not set # end of Streaming # CONFIG_PACKAGE_UnblockNeteaseMusic is not set # CONFIG_PACKAGE_UnblockNeteaseMusic-Go is not set # CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_GOPROXY is not set CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_UPX=y # CONFIG_PACKAGE_ffmpeg is not set # CONFIG_PACKAGE_ffprobe is not set # CONFIG_PACKAGE_fswebcam is not set # CONFIG_PACKAGE_gerbera is not set # CONFIG_PACKAGE_gmediarender is not set # CONFIG_PACKAGE_gphoto2 is not set # CONFIG_PACKAGE_graphicsmagick is not set # CONFIG_PACKAGE_grilo is not set # CONFIG_PACKAGE_grilo-plugins is not set # CONFIG_PACKAGE_gst1-libav is not set # CONFIG_PACKAGE_gstreamer1-libs is not set # CONFIG_PACKAGE_gstreamer1-plugins-bad is not set # CONFIG_PACKAGE_gstreamer1-plugins-base is not set # CONFIG_PACKAGE_gstreamer1-plugins-good is not set # CONFIG_PACKAGE_gstreamer1-plugins-ugly is not set # CONFIG_PACKAGE_gstreamer1-utils is not set # CONFIG_PACKAGE_icecast is not set # CONFIG_PACKAGE_imagemagick is not set # CONFIG_PACKAGE_lcdgrilo is not set # CONFIG_PACKAGE_minidlna is not set # CONFIG_PACKAGE_minisatip is not set # CONFIG_PACKAGE_mjpg-streamer is not set # CONFIG_PACKAGE_motion is not set # CONFIG_PACKAGE_tvheadend is not set # CONFIG_PACKAGE_v4l2rtspserver is not set # CONFIG_PACKAGE_vips is not set # CONFIG_PACKAGE_xupnpd is not set # CONFIG_PACKAGE_youtube-dl is not set # end of Multimedia # # Network # # # BitTorrent # # CONFIG_PACKAGE_mktorrent is not set # CONFIG_PACKAGE_opentracker is not set # CONFIG_PACKAGE_opentracker6 is not set # CONFIG_PACKAGE_qbittorrent is not set # CONFIG_PACKAGE_rtorrent is not set # CONFIG_PACKAGE_rtorrent-rpc is not set # CONFIG_PACKAGE_transmission-cli-openssl is not set # CONFIG_PACKAGE_transmission-daemon-openssl is not set # CONFIG_PACKAGE_transmission-remote-openssl is not set # CONFIG_PACKAGE_transmission-web is not set # CONFIG_PACKAGE_transmission-web-control is not set # end of BitTorrent # # Captive Portals # # CONFIG_PACKAGE_apfree-wifidog is not set # CONFIG_PACKAGE_coova-chilli is not set # CONFIG_PACKAGE_nodogsplash is not set # CONFIG_PACKAGE_opennds is not set # CONFIG_PACKAGE_wifidog is not set # CONFIG_PACKAGE_wifidog-tls is not set # end of Captive Portals # # Cloud Manager # # CONFIG_PACKAGE_rclone-ng is not set # CONFIG_PACKAGE_rclone-webui-react is not set # end of Cloud Manager # # Dial-in/up # # CONFIG_PACKAGE_rp-pppoe-common is not set # CONFIG_PACKAGE_rp-pppoe-relay is not set # CONFIG_PACKAGE_rp-pppoe-server is not set # end of Dial-in/up # # Download Manager # # CONFIG_PACKAGE_ariang is not set # CONFIG_PACKAGE_ariang-nginx is not set # CONFIG_PACKAGE_leech is not set # CONFIG_PACKAGE_webui-aria2 is not set # end of Download Manager # # File Transfer # # CONFIG_PACKAGE_aria2 is not set # CONFIG_PACKAGE_atftp is not set # CONFIG_PACKAGE_atftpd is not set CONFIG_PACKAGE_curl=y # CONFIG_PACKAGE_gnurl is not set # CONFIG_PACKAGE_lftp is not set # CONFIG_PACKAGE_ps3netsrv is not set # CONFIG_PACKAGE_rosy-file-server is not set # CONFIG_PACKAGE_rsync is not set # CONFIG_PACKAGE_rsyncd is not set # CONFIG_PACKAGE_vsftpd is not set # CONFIG_PACKAGE_vsftpd-alt is not set # CONFIG_PACKAGE_vsftpd-tls is not set # CONFIG_PACKAGE_wget-nossl is not set CONFIG_PACKAGE_wget-ssl=y # end of File Transfer # # Filesystem # # CONFIG_PACKAGE_davfs2 is not set # CONFIG_PACKAGE_ksmbd-avahi-service is not set # CONFIG_PACKAGE_ksmbd-server is not set # CONFIG_PACKAGE_ksmbd-utils is not set # CONFIG_PACKAGE_netatalk is not set # CONFIG_PACKAGE_nfs-kernel-server is not set # CONFIG_PACKAGE_owftpd is not set # CONFIG_PACKAGE_owhttpd is not set # CONFIG_PACKAGE_owserver is not set # CONFIG_PACKAGE_sshfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_arptables is not set # CONFIG_PACKAGE_conntrack is not set # CONFIG_PACKAGE_conntrackd is not set # CONFIG_PACKAGE_ebtables is not set # CONFIG_PACKAGE_fwknop is not set # CONFIG_PACKAGE_fwknopd is not set # CONFIG_PACKAGE_ip6tables is not set CONFIG_PACKAGE_iptables=y # CONFIG_IPTABLES_CONNLABEL is not set # CONFIG_IPTABLES_NFTABLES is not set # CONFIG_PACKAGE_iptables-mod-account is not set # CONFIG_PACKAGE_iptables-mod-chaos is not set # CONFIG_PACKAGE_iptables-mod-checksum is not set # CONFIG_PACKAGE_iptables-mod-cluster is not set # CONFIG_PACKAGE_iptables-mod-clusterip is not set # CONFIG_PACKAGE_iptables-mod-condition is not set # CONFIG_PACKAGE_iptables-mod-conntrack-extra is not set # CONFIG_PACKAGE_iptables-mod-delude is not set # CONFIG_PACKAGE_iptables-mod-dhcpmac is not set # CONFIG_PACKAGE_iptables-mod-dnetmap is not set # CONFIG_PACKAGE_iptables-mod-extra is not set # CONFIG_PACKAGE_iptables-mod-filter is not set CONFIG_PACKAGE_iptables-mod-fullconenat=y # CONFIG_PACKAGE_iptables-mod-fuzzy is not set # CONFIG_PACKAGE_iptables-mod-geoip is not set # CONFIG_PACKAGE_iptables-mod-hashlimit is not set # CONFIG_PACKAGE_iptables-mod-iface is not set # CONFIG_PACKAGE_iptables-mod-ipmark is not set # CONFIG_PACKAGE_iptables-mod-ipopt is not set # CONFIG_PACKAGE_iptables-mod-ipp2p is not set # CONFIG_PACKAGE_iptables-mod-iprange is not set # CONFIG_PACKAGE_iptables-mod-ipsec is not set # CONFIG_PACKAGE_iptables-mod-ipv4options is not set # CONFIG_PACKAGE_iptables-mod-led is not set # CONFIG_PACKAGE_iptables-mod-length2 is not set # CONFIG_PACKAGE_iptables-mod-logmark is not set # CONFIG_PACKAGE_iptables-mod-lscan is not set # CONFIG_PACKAGE_iptables-mod-lua is not set # CONFIG_PACKAGE_iptables-mod-nat-extra is not set # CONFIG_PACKAGE_iptables-mod-nflog is not set # CONFIG_PACKAGE_iptables-mod-nfqueue is not set # CONFIG_PACKAGE_iptables-mod-physdev is not set # CONFIG_PACKAGE_iptables-mod-proto is not set # CONFIG_PACKAGE_iptables-mod-psd is not set # CONFIG_PACKAGE_iptables-mod-quota2 is not set # CONFIG_PACKAGE_iptables-mod-rpfilter is not set # CONFIG_PACKAGE_iptables-mod-rtpengine is not set # CONFIG_PACKAGE_iptables-mod-sysrq is not set # CONFIG_PACKAGE_iptables-mod-tarpit is not set # CONFIG_PACKAGE_iptables-mod-tee is not set CONFIG_PACKAGE_iptables-mod-tproxy=y # CONFIG_PACKAGE_iptables-mod-trace is not set # CONFIG_PACKAGE_iptables-mod-u32 is not set # CONFIG_PACKAGE_iptables-mod-ulog is not set # CONFIG_PACKAGE_iptaccount is not set # CONFIG_PACKAGE_iptgeoip is not set # # Select iptgeoip options # # CONFIG_IPTGEOIP_PRESERVE is not set # end of Select iptgeoip options # CONFIG_PACKAGE_miniupnpc is not set CONFIG_PACKAGE_miniupnpd=y # CONFIG_MINIUPNPD_IGDv2 is not set # CONFIG_PACKAGE_natpmpc is not set # CONFIG_PACKAGE_nftables-json is not set # CONFIG_PACKAGE_nftables-nojson is not set # CONFIG_PACKAGE_shorewall is not set # CONFIG_PACKAGE_shorewall-core is not set # CONFIG_PACKAGE_shorewall-lite is not set # CONFIG_PACKAGE_shorewall6 is not set # CONFIG_PACKAGE_shorewall6-lite is not set # CONFIG_PACKAGE_snort is not set # CONFIG_PACKAGE_snort3 is not set # end of Firewall # # Firewall Tunnel # # CONFIG_PACKAGE_iodine is not set # CONFIG_PACKAGE_iodined is not set # end of Firewall Tunnel # # FreeRADIUS (version 3) # # CONFIG_PACKAGE_freeradius3 is not set # CONFIG_PACKAGE_freeradius3-common is not set # CONFIG_PACKAGE_freeradius3-utils is not set # end of FreeRADIUS (version 3) # # IP Addresses and Names # # CONFIG_PACKAGE_aggregate is not set # CONFIG_PACKAGE_announce is not set # CONFIG_PACKAGE_avahi-autoipd is not set # CONFIG_PACKAGE_avahi-daemon-service-http is not set # CONFIG_PACKAGE_avahi-daemon-service-ssh is not set # CONFIG_PACKAGE_avahi-dbus-daemon is not set # CONFIG_PACKAGE_avahi-dnsconfd is not set # CONFIG_PACKAGE_avahi-nodbus-daemon is not set # CONFIG_PACKAGE_avahi-utils is not set # CONFIG_PACKAGE_bind-check is not set # CONFIG_PACKAGE_bind-client is not set # CONFIG_PACKAGE_bind-dig is not set # CONFIG_PACKAGE_bind-dnssec is not set # CONFIG_PACKAGE_bind-host is not set # CONFIG_PACKAGE_bind-nslookup is not set # CONFIG_PACKAGE_bind-rndc is not set # CONFIG_PACKAGE_bind-server is not set # CONFIG_PACKAGE_bind-tools is not set CONFIG_PACKAGE_ddns-scripts=y CONFIG_PACKAGE_ddns-scripts_aliyun=y # CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4 is not set CONFIG_PACKAGE_ddns-scripts_dnspod=y # CONFIG_PACKAGE_ddns-scripts_freedns_42_pl is not set # CONFIG_PACKAGE_ddns-scripts_godaddy.com-v1 is not set # CONFIG_PACKAGE_ddns-scripts_no-ip_com is not set # CONFIG_PACKAGE_ddns-scripts_nsupdate is not set # CONFIG_PACKAGE_ddns-scripts_route53-v1 is not set # CONFIG_PACKAGE_dhcp-forwarder is not set CONFIG_PACKAGE_dns2socks=y # CONFIG_PACKAGE_dnscrypt-proxy is not set # CONFIG_PACKAGE_dnscrypt-proxy-resolvers is not set # CONFIG_PACKAGE_dnsdist is not set # CONFIG_PACKAGE_dnsproxy is not set # CONFIG_DNSPROXY_COMPRESS_GOPROXY is not set CONFIG_DNSPROXY_COMPRESS_UPX=y # CONFIG_PACKAGE_drill is not set # CONFIG_PACKAGE_hostip is not set # CONFIG_PACKAGE_idn is not set # CONFIG_PACKAGE_idn2 is not set # CONFIG_PACKAGE_inadyn is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv6 is not set # CONFIG_PACKAGE_kadnode is not set # CONFIG_PACKAGE_kea-admin is not set # CONFIG_PACKAGE_kea-ctrl is not set # CONFIG_PACKAGE_kea-dhcp-ddns is not set # CONFIG_PACKAGE_kea-dhcp4 is not set # CONFIG_PACKAGE_kea-dhcp6 is not set # CONFIG_PACKAGE_kea-lfc is not set # CONFIG_PACKAGE_kea-libs is not set # CONFIG_PACKAGE_kea-perfdhcp is not set # CONFIG_PACKAGE_kea-shell is not set # CONFIG_PACKAGE_knot is not set # CONFIG_PACKAGE_knot-dig is not set # CONFIG_PACKAGE_knot-host is not set # CONFIG_PACKAGE_knot-keymgr is not set # CONFIG_PACKAGE_knot-nsupdate is not set # CONFIG_PACKAGE_knot-resolver is not set # # Configuration # # CONFIG_PACKAGE_knot-resolver_dnstap is not set # end of Configuration # CONFIG_PACKAGE_knot-tests is not set # CONFIG_PACKAGE_knot-zonecheck is not set # CONFIG_PACKAGE_ldns-examples is not set # CONFIG_PACKAGE_mdns-utils is not set # CONFIG_PACKAGE_mdnsd is not set # CONFIG_PACKAGE_mdnsresponder is not set # CONFIG_PACKAGE_nsd is not set # CONFIG_PACKAGE_nsd-control is not set # CONFIG_PACKAGE_nsd-control-setup is not set # CONFIG_PACKAGE_nsd-nossl is not set # CONFIG_PACKAGE_ohybridproxy is not set # CONFIG_PACKAGE_overture is not set # CONFIG_PACKAGE_pdns is not set # CONFIG_PACKAGE_pdns-ixfrdist is not set # CONFIG_PACKAGE_pdns-recursor is not set # CONFIG_PACKAGE_pdns-tools is not set # CONFIG_PACKAGE_stubby is not set # CONFIG_PACKAGE_tor-hs is not set # CONFIG_PACKAGE_torsocks is not set # CONFIG_PACKAGE_unbound-anchor is not set # CONFIG_PACKAGE_unbound-checkconf is not set # CONFIG_PACKAGE_unbound-control is not set # CONFIG_PACKAGE_unbound-control-setup is not set # CONFIG_PACKAGE_unbound-daemon is not set # CONFIG_PACKAGE_unbound-host is not set # CONFIG_PACKAGE_wsdd2 is not set # CONFIG_PACKAGE_zonestitcher is not set # end of IP Addresses and Names # # Instant Messaging # # CONFIG_PACKAGE_bitlbee is not set # CONFIG_PACKAGE_irssi is not set # CONFIG_PACKAGE_ngircd is not set # CONFIG_PACKAGE_ngircd-nossl is not set # CONFIG_PACKAGE_prosody is not set # CONFIG_PACKAGE_quassel-irssi is not set # CONFIG_PACKAGE_umurmur-mbedtls is not set # CONFIG_PACKAGE_umurmur-openssl is not set # CONFIG_PACKAGE_znc is not set # end of Instant Messaging # # Linux ATM tools # # CONFIG_PACKAGE_atm-aread is not set # CONFIG_PACKAGE_atm-atmaddr is not set # CONFIG_PACKAGE_atm-atmdiag is not set # CONFIG_PACKAGE_atm-atmdump is not set # CONFIG_PACKAGE_atm-atmloop is not set # CONFIG_PACKAGE_atm-atmsigd is not set # CONFIG_PACKAGE_atm-atmswitch is not set # CONFIG_PACKAGE_atm-atmtcp is not set # CONFIG_PACKAGE_atm-awrite is not set # CONFIG_PACKAGE_atm-bus is not set # CONFIG_PACKAGE_atm-debug-tools is not set # CONFIG_PACKAGE_atm-diagnostics is not set # CONFIG_PACKAGE_atm-esi is not set # CONFIG_PACKAGE_atm-ilmid is not set # CONFIG_PACKAGE_atm-ilmidiag is not set # CONFIG_PACKAGE_atm-lecs is not set # CONFIG_PACKAGE_atm-les is not set # CONFIG_PACKAGE_atm-mpcd is not set # CONFIG_PACKAGE_atm-saaldump is not set # CONFIG_PACKAGE_atm-sonetdiag is not set # CONFIG_PACKAGE_atm-svc_recv is not set # CONFIG_PACKAGE_atm-svc_send is not set # CONFIG_PACKAGE_atm-tools is not set # CONFIG_PACKAGE_atm-ttcp_atm is not set # CONFIG_PACKAGE_atm-zeppelin is not set # CONFIG_PACKAGE_br2684ctl is not set # end of Linux ATM tools # # LoRaWAN # # CONFIG_PACKAGE_libloragw-tests is not set # CONFIG_PACKAGE_libloragw-utils is not set # end of LoRaWAN # # NMAP Suite # # CONFIG_PACKAGE_ncat is not set # CONFIG_PACKAGE_ncat-full is not set # CONFIG_PACKAGE_ncat-ssl is not set # CONFIG_PACKAGE_ndiff is not set # CONFIG_PACKAGE_nmap is not set # CONFIG_PACKAGE_nmap-full is not set # CONFIG_PACKAGE_nmap-ssl is not set # CONFIG_PACKAGE_nping is not set # CONFIG_PACKAGE_nping-ssl is not set # end of NMAP Suite # # NTRIP # # CONFIG_PACKAGE_ntripcaster is not set # CONFIG_PACKAGE_ntripclient is not set # CONFIG_PACKAGE_ntripserver is not set # end of NTRIP # # OLSR.org network framework # # CONFIG_PACKAGE_oonf-dlep-proxy is not set # CONFIG_PACKAGE_oonf-dlep-radio is not set # CONFIG_PACKAGE_oonf-init-scripts is not set # CONFIG_PACKAGE_oonf-olsrd2 is not set # end of OLSR.org network framework # # Open vSwitch # # CONFIG_PACKAGE_openvswitch is not set # CONFIG_PACKAGE_openvswitch-ovn-host is not set # CONFIG_PACKAGE_openvswitch-ovn-north is not set # CONFIG_PACKAGE_openvswitch-python3 is not set # CONFIG_PACKAGE_ovsd is not set # end of Open vSwitch # # OpenLDAP # # CONFIG_PACKAGE_libopenldap is not set CONFIG_OPENLDAP_DEBUG=y # CONFIG_OPENLDAP_CRYPT is not set # CONFIG_OPENLDAP_MONITOR is not set # CONFIG_OPENLDAP_DB47 is not set # CONFIG_OPENLDAP_ICU is not set # CONFIG_PACKAGE_openldap-server is not set # CONFIG_PACKAGE_openldap-utils is not set # end of OpenLDAP # # P2P # # CONFIG_PACKAGE_amule is not set # CONFIG_AMULE_CRYPTOPP_STATIC_LINKING is not set # CONFIG_PACKAGE_antileech is not set # end of P2P # # Printing # # CONFIG_PACKAGE_p910nd is not set # end of Printing # # Project V # # CONFIG_PACKAGE_v2ray-plugin is not set # CONFIG_v2ray-plugin_INCLUDE_GOPROXY is not set # end of Project V # # Routing and Redirection # # CONFIG_PACKAGE_babel-pinger is not set # CONFIG_PACKAGE_babeld is not set # CONFIG_PACKAGE_batmand is not set # CONFIG_PACKAGE_bcp38 is not set # CONFIG_PACKAGE_bfdd is not set # CONFIG_PACKAGE_bird1-ipv4 is not set # CONFIG_PACKAGE_bird1-ipv4-uci is not set # CONFIG_PACKAGE_bird1-ipv6 is not set # CONFIG_PACKAGE_bird1-ipv6-uci is not set # CONFIG_PACKAGE_bird1c-ipv4 is not set # CONFIG_PACKAGE_bird1c-ipv6 is not set # CONFIG_PACKAGE_bird1cl-ipv4 is not set # CONFIG_PACKAGE_bird1cl-ipv6 is not set # CONFIG_PACKAGE_bird2 is not set # CONFIG_PACKAGE_bird2c is not set # CONFIG_PACKAGE_bird2cl is not set # CONFIG_PACKAGE_bmx6 is not set # CONFIG_PACKAGE_bmx7 is not set # CONFIG_PACKAGE_cjdns is not set # CONFIG_PACKAGE_cjdns-tests is not set # CONFIG_PACKAGE_dcstad is not set # CONFIG_PACKAGE_dcwapd is not set # CONFIG_PACKAGE_devlink is not set # CONFIG_PACKAGE_frr is not set # CONFIG_PACKAGE_genl is not set # CONFIG_PACKAGE_igmpproxy is not set # CONFIG_PACKAGE_ip-bridge is not set CONFIG_PACKAGE_ip-full=y # CONFIG_PACKAGE_ip-tiny is not set # CONFIG_PACKAGE_lldpd is not set # CONFIG_PACKAGE_mcproxy is not set # CONFIG_PACKAGE_mrmctl is not set # CONFIG_PACKAGE_mwan3 is not set # CONFIG_PACKAGE_nstat is not set # CONFIG_PACKAGE_olsrd is not set # CONFIG_PACKAGE_prince is not set # CONFIG_PACKAGE_quagga is not set # CONFIG_PACKAGE_rdma is not set # CONFIG_PACKAGE_relayd is not set # CONFIG_PACKAGE_smcroute is not set # CONFIG_PACKAGE_ss is not set # CONFIG_PACKAGE_sslh is not set # CONFIG_PACKAGE_tc-full is not set # CONFIG_PACKAGE_tc-mod-iptables is not set # CONFIG_PACKAGE_tc-tiny is not set # CONFIG_PACKAGE_tcpproxy is not set # CONFIG_PACKAGE_udp-broadcast-relay-redux is not set # CONFIG_PACKAGE_vis is not set # CONFIG_PACKAGE_yggdrasil is not set # end of Routing and Redirection # # SSH # # CONFIG_PACKAGE_autossh is not set # CONFIG_PACKAGE_openssh-client is not set # CONFIG_PACKAGE_openssh-client-utils is not set # CONFIG_PACKAGE_openssh-keygen is not set # CONFIG_PACKAGE_openssh-moduli is not set # CONFIG_PACKAGE_openssh-server is not set # CONFIG_PACKAGE_openssh-server-pam is not set # CONFIG_PACKAGE_openssh-sftp-avahi-service is not set # CONFIG_PACKAGE_openssh-sftp-client is not set # CONFIG_PACKAGE_openssh-sftp-server is not set # CONFIG_PACKAGE_sshtunnel is not set # CONFIG_PACKAGE_tmate is not set # end of SSH # # THC-IPv6 attack and analyzing toolkit # # CONFIG_PACKAGE_thc-ipv6-address6 is not set # CONFIG_PACKAGE_thc-ipv6-alive6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6d is not set # CONFIG_PACKAGE_thc-ipv6-denial6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-sniffer6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsdict6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsrevenum6 is not set # CONFIG_PACKAGE_thc-ipv6-dos-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-dump-router6 is not set # CONFIG_PACKAGE_thc-ipv6-exploit6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dns6d is not set # CONFIG_PACKAGE_thc-ipv6-fake-dnsupdate6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mipv6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-fragmentation6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6d is not set # CONFIG_PACKAGE_thc-ipv6-inverse-lookup6 is not set # CONFIG_PACKAGE_thc-ipv6-kill-router6 is not set # CONFIG_PACKAGE_thc-ipv6-ndpexhaust6 is not set # CONFIG_PACKAGE_thc-ipv6-node-query6 is not set # CONFIG_PACKAGE_thc-ipv6-parasite6 is not set # CONFIG_PACKAGE_thc-ipv6-passive-discovery6 is not set # CONFIG_PACKAGE_thc-ipv6-randicmp6 is not set # CONFIG_PACKAGE_thc-ipv6-redir6 is not set # CONFIG_PACKAGE_thc-ipv6-rsmurf6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpees6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpeesmp6 is not set # CONFIG_PACKAGE_thc-ipv6-smurf6 is not set # CONFIG_PACKAGE_thc-ipv6-thcping6 is not set # CONFIG_PACKAGE_thc-ipv6-toobig6 is not set # CONFIG_PACKAGE_thc-ipv6-trace6 is not set # end of THC-IPv6 attack and analyzing toolkit # # Tcpreplay # # CONFIG_PACKAGE_tcpbridge is not set # CONFIG_PACKAGE_tcpcapinfo is not set # CONFIG_PACKAGE_tcpliveplay is not set # CONFIG_PACKAGE_tcpprep is not set # CONFIG_PACKAGE_tcpreplay is not set # CONFIG_PACKAGE_tcpreplay-all is not set # CONFIG_PACKAGE_tcpreplay-edit is not set # CONFIG_PACKAGE_tcprewrite is not set # end of Tcpreplay # # Telephony # # CONFIG_PACKAGE_asterisk is not set # CONFIG_PACKAGE_baresip is not set # CONFIG_PACKAGE_freeswitch is not set # CONFIG_PACKAGE_kamailio is not set # CONFIG_PACKAGE_miax is not set # CONFIG_PACKAGE_pcapsipdump is not set # CONFIG_PACKAGE_restund is not set # CONFIG_PACKAGE_rtpengine is not set # CONFIG_PACKAGE_rtpengine-no-transcode is not set # CONFIG_PACKAGE_rtpengine-recording is not set # CONFIG_PACKAGE_rtpproxy is not set # CONFIG_PACKAGE_sipp is not set # CONFIG_PACKAGE_siproxd is not set # CONFIG_PACKAGE_yate is not set # end of Telephony # # Telephony Lantiq # # end of Telephony Lantiq # # Time Synchronization # # CONFIG_PACKAGE_chrony is not set # CONFIG_PACKAGE_chrony-nts is not set # CONFIG_PACKAGE_htpdate is not set # CONFIG_PACKAGE_linuxptp is not set # CONFIG_PACKAGE_ntp-keygen is not set # CONFIG_PACKAGE_ntp-utils is not set # CONFIG_PACKAGE_ntpclient is not set # CONFIG_PACKAGE_ntpd is not set # CONFIG_PACKAGE_ntpdate is not set # end of Time Synchronization # # VPN # # CONFIG_PACKAGE_chaosvpn is not set # CONFIG_PACKAGE_eoip is not set # CONFIG_PACKAGE_fastd is not set # CONFIG_PACKAGE_libreswan is not set # CONFIG_PACKAGE_n2n-edge is not set # CONFIG_PACKAGE_n2n-supernode is not set # CONFIG_PACKAGE_ocserv is not set # CONFIG_PACKAGE_openconnect is not set # CONFIG_PACKAGE_openfortivpn is not set # CONFIG_PACKAGE_openvpn-easy-rsa is not set # CONFIG_PACKAGE_openvpn-mbedtls is not set # CONFIG_PACKAGE_openvpn-openssl is not set # CONFIG_PACKAGE_openvpn-wolfssl is not set # CONFIG_PACKAGE_pptpd is not set # CONFIG_PACKAGE_softethervpn-base is not set # CONFIG_PACKAGE_softethervpn-bridge is not set # CONFIG_PACKAGE_softethervpn-client is not set # CONFIG_PACKAGE_softethervpn-server is not set # CONFIG_PACKAGE_softethervpn5-bridge is not set # CONFIG_PACKAGE_softethervpn5-client is not set # CONFIG_PACKAGE_softethervpn5-server is not set # CONFIG_PACKAGE_sstp-client is not set # CONFIG_PACKAGE_strongswan is not set # CONFIG_PACKAGE_tailscale is not set # CONFIG_PACKAGE_tailscaled is not set # CONFIG_PACKAGE_tinc is not set # CONFIG_PACKAGE_uanytun is not set # CONFIG_PACKAGE_uanytun-nettle is not set # CONFIG_PACKAGE_uanytun-nocrypt is not set # CONFIG_PACKAGE_uanytun-sslcrypt is not set # CONFIG_PACKAGE_vpnc is not set # CONFIG_PACKAGE_vpnc-scripts is not set # CONFIG_PACKAGE_wireguard-tools is not set # CONFIG_PACKAGE_xl2tpd is not set CONFIG_PACKAGE_zerotier=y # # Configuration # # CONFIG_ZEROTIER_ENABLE_DEBUG is not set # CONFIG_ZEROTIER_ENABLE_SELFTEST is not set # end of Configuration # end of VPN # # Version Control Systems # # CONFIG_PACKAGE_git is not set # CONFIG_PACKAGE_git-http is not set # CONFIG_PACKAGE_subversion-client is not set # CONFIG_PACKAGE_subversion-libs is not set # CONFIG_PACKAGE_subversion-server is not set # end of Version Control Systems # # WWAN # # CONFIG_PACKAGE_adb-enablemodem is not set # CONFIG_PACKAGE_comgt is not set # CONFIG_PACKAGE_comgt-directip is not set # CONFIG_PACKAGE_comgt-ncm is not set # CONFIG_PACKAGE_umbim is not set # CONFIG_PACKAGE_uqmi is not set # end of WWAN # # Web Servers/Proxies # # CONFIG_PACKAGE_apache is not set # CONFIG_PACKAGE_brook is not set # CONFIG_BROOK_COMPRESS_GOPROXY is not set CONFIG_BROOK_COMPRESS_UPX=y # CONFIG_PACKAGE_cgi-io is not set # CONFIG_PACKAGE_clamav is not set # CONFIG_PACKAGE_e2guardian is not set # CONFIG_PACKAGE_etebase is not set # CONFIG_PACKAGE_freshclam is not set # CONFIG_PACKAGE_frpc is not set # CONFIG_PACKAGE_frps is not set # CONFIG_PACKAGE_gateway-go is not set # CONFIG_PACKAGE_gunicorn3 is not set # CONFIG_PACKAGE_haproxy is not set # CONFIG_PACKAGE_haproxy-nossl is not set # CONFIG_PACKAGE_hysteria is not set # CONFIG_PACKAGE_kcptun-client is not set # CONFIG_PACKAGE_kcptun-config is not set # CONFIG_PACKAGE_kcptun-server is not set # CONFIG_PACKAGE_lighttpd is not set CONFIG_PACKAGE_microsocks=y # CONFIG_PACKAGE_naiveproxy is not set # CONFIG_PACKAGE_nginx-all-module is not set # CONFIG_PACKAGE_nginx-mod-luci is not set # CONFIG_PACKAGE_nginx-ssl is not set # CONFIG_PACKAGE_nginx-ssl-util is not set # CONFIG_PACKAGE_nginx-ssl-util-nopcre is not set CONFIG_PACKAGE_pdnsd-alt=y # CONFIG_PACKAGE_polipo is not set # CONFIG_PACKAGE_privoxy is not set # CONFIG_PACKAGE_python3-gunicorn is not set # CONFIG_PACKAGE_radicale is not set # CONFIG_PACKAGE_radicale2 is not set # CONFIG_PACKAGE_radicale2-examples is not set # CONFIG_PACKAGE_redsocks2 is not set # CONFIG_PACKAGE_shadowsocks-libev-config is not set CONFIG_PACKAGE_shadowsocks-libev-ss-local=y CONFIG_PACKAGE_shadowsocks-libev-ss-redir=y # CONFIG_PACKAGE_shadowsocks-libev-ss-rules is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-server is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-tunnel is not set # CONFIG_PACKAGE_shadowsocks-rust-sslocal is not set # CONFIG_PACKAGE_shadowsocks-rust-ssmanager is not set # CONFIG_PACKAGE_shadowsocks-rust-ssserver is not set # CONFIG_PACKAGE_shadowsocks-rust-ssurl is not set CONFIG_PACKAGE_shadowsocksr-libev-ssr-check=y CONFIG_PACKAGE_shadowsocksr-libev-ssr-local=y # CONFIG_PACKAGE_shadowsocksr-libev-ssr-nat is not set CONFIG_PACKAGE_shadowsocksr-libev-ssr-redir=y # CONFIG_PACKAGE_shadowsocksr-libev-ssr-server is not set # CONFIG_PACKAGE_sockd is not set # CONFIG_PACKAGE_socksify is not set # CONFIG_PACKAGE_spawn-fcgi is not set # CONFIG_PACKAGE_squid is not set # CONFIG_PACKAGE_srelay is not set # CONFIG_PACKAGE_tinyproxy is not set # CONFIG_PACKAGE_trojan-go is not set CONFIG_PACKAGE_uhttpd=y # CONFIG_PACKAGE_uhttpd-mod-lua is not set CONFIG_PACKAGE_uhttpd-mod-ubus=y # CONFIG_PACKAGE_uwsgi is not set # end of Web Servers/Proxies # # Wireless # # CONFIG_PACKAGE_aircrack-ng is not set # CONFIG_PACKAGE_airmon-ng is not set # CONFIG_PACKAGE_dynapoint is not set # CONFIG_PACKAGE_hcxdumptool is not set # CONFIG_PACKAGE_hcxtools is not set # CONFIG_PACKAGE_horst is not set # CONFIG_PACKAGE_mt_wifi is not set # CONFIG_PACKAGE_pixiewps is not set # CONFIG_PACKAGE_reaver is not set # CONFIG_PACKAGE_wavemon is not set # CONFIG_PACKAGE_wifischedule is not set # end of Wireless # # WirelessAPD # # CONFIG_PACKAGE_eapol-test is not set # CONFIG_PACKAGE_eapol-test-openssl is not set # CONFIG_PACKAGE_eapol-test-wolfssl is not set # CONFIG_PACKAGE_hostapd is not set # CONFIG_PACKAGE_hostapd-basic is not set # CONFIG_PACKAGE_hostapd-basic-openssl is not set # CONFIG_PACKAGE_hostapd-basic-wolfssl is not set # CONFIG_PACKAGE_hostapd-common is not set # CONFIG_PACKAGE_hostapd-mini is not set # CONFIG_PACKAGE_hostapd-openssl is not set # CONFIG_PACKAGE_hostapd-wolfssl is not set # CONFIG_PACKAGE_hs20-client is not set # CONFIG_PACKAGE_hs20-common is not set # CONFIG_PACKAGE_hs20-server is not set # CONFIG_PACKAGE_wpa-supplicant is not set # CONFIG_WPA_WOLFSSL is not set # CONFIG_DRIVER_WEXT_SUPPORT is not set CONFIG_DRIVER_11N_SUPPORT=y CONFIG_DRIVER_11AC_SUPPORT=y # CONFIG_DRIVER_11AX_SUPPORT is not set # CONFIG_WPA_ENABLE_WEP is not set # CONFIG_PACKAGE_wpa-supplicant-basic is not set # CONFIG_PACKAGE_wpa-supplicant-mini is not set # CONFIG_PACKAGE_wpa-supplicant-openssl is not set # CONFIG_PACKAGE_wpa-supplicant-wolfssl is not set # CONFIG_PACKAGE_wpad is not set # CONFIG_PACKAGE_wpad-basic is not set # CONFIG_PACKAGE_wpad-basic-openssl is not set # CONFIG_PACKAGE_wpad-basic-wolfssl is not set # CONFIG_PACKAGE_wpad-mini is not set # CONFIG_PACKAGE_wpad-openssl is not set # CONFIG_PACKAGE_wpad-wolfssl is not set # end of WirelessAPD # # arp-scan # # CONFIG_PACKAGE_arp-scan is not set # CONFIG_PACKAGE_arp-scan-database is not set # end of arp-scan # CONFIG_PACKAGE_464xlat is not set # CONFIG_PACKAGE_6in4 is not set # CONFIG_PACKAGE_6rd is not set # CONFIG_PACKAGE_6to4 is not set # CONFIG_PACKAGE_UDPspeeder is not set # CONFIG_PACKAGE_acme is not set # CONFIG_PACKAGE_acme-dnsapi is not set # CONFIG_PACKAGE_adblock is not set CONFIG_PACKAGE_adbyby=y # CONFIG_PACKAGE_addrwatch is not set # CONFIG_PACKAGE_adguardhome is not set # CONFIG_PACKAGE_ahcpd is not set # CONFIG_PACKAGE_alfred is not set # CONFIG_PACKAGE_apcupsd is not set # CONFIG_PACKAGE_apcupsd-cgi is not set # CONFIG_PACKAGE_apinger is not set # CONFIG_PACKAGE_atlas-probe is not set # CONFIG_PACKAGE_atlas-sw-probe is not set # CONFIG_PACKAGE_atlas-sw-probe-rpc is not set # CONFIG_PACKAGE_baidupcs-web is not set # CONFIG_BAIDUPCS_WEB_COMPRESS_GOPROXY is not set CONFIG_BAIDUPCS_WEB_COMPRESS_UPX=y # CONFIG_PACKAGE_banip is not set # CONFIG_PACKAGE_batctl-default is not set # CONFIG_PACKAGE_batctl-full is not set # CONFIG_PACKAGE_batctl-tiny is not set # CONFIG_PACKAGE_beanstalkd is not set # CONFIG_PACKAGE_bmon is not set # CONFIG_PACKAGE_boinc is not set # CONFIG_PACKAGE_bpftool-full is not set # CONFIG_PACKAGE_bpftool-minimal is not set # CONFIG_PACKAGE_bwm-ng is not set # CONFIG_PACKAGE_bwping is not set # CONFIG_PACKAGE_chat is not set CONFIG_PACKAGE_chinadns-ng=y # CONFIG_PACKAGE_cifsmount is not set # CONFIG_PACKAGE_coap-server is not set # CONFIG_PACKAGE_conserver is not set # CONFIG_PACKAGE_cshark is not set # CONFIG_PACKAGE_daemonlogger is not set # CONFIG_PACKAGE_darkstat is not set # CONFIG_PACKAGE_dawn is not set # CONFIG_PACKAGE_dhcpcd is not set # CONFIG_PACKAGE_dmapd is not set # CONFIG_PACKAGE_dnscrypt-proxy2 is not set # CONFIG_PACKAGE_dnsforwarder is not set # CONFIG_PACKAGE_dnstap is not set # CONFIG_PACKAGE_dnstop is not set # CONFIG_PACKAGE_ds-lite is not set # CONFIG_PACKAGE_dsmboot is not set # CONFIG_PACKAGE_esniper is not set # CONFIG_PACKAGE_etherwake is not set # CONFIG_PACKAGE_etherwake-nfqueue is not set # CONFIG_PACKAGE_ethtool is not set # CONFIG_PACKAGE_ethtool-full is not set # CONFIG_PACKAGE_fakeidentd is not set # CONFIG_PACKAGE_fakepop is not set # CONFIG_PACKAGE_family-dns is not set # CONFIG_PACKAGE_foolsm is not set # CONFIG_PACKAGE_fping is not set # CONFIG_PACKAGE_generate-ipv6-address is not set # CONFIG_PACKAGE_geth is not set # CONFIG_PACKAGE_git-lfs is not set # CONFIG_PACKAGE_gnunet is not set # CONFIG_PACKAGE_gre is not set # CONFIG_PACKAGE_hnet-full is not set # CONFIG_PACKAGE_hnet-full-l2tp is not set # CONFIG_PACKAGE_hnet-full-secure is not set # CONFIG_PACKAGE_hnetd-nossl is not set # CONFIG_PACKAGE_hnetd-openssl is not set # CONFIG_PACKAGE_httping is not set # CONFIG_PACKAGE_httping-nossl is not set # CONFIG_PACKAGE_https-dns-proxy is not set # CONFIG_PACKAGE_i2pd is not set # CONFIG_PACKAGE_ibrdtn-tools is not set # CONFIG_PACKAGE_ibrdtnd is not set # CONFIG_PACKAGE_ifstat is not set # CONFIG_PACKAGE_iftop is not set # CONFIG_PACKAGE_iiod is not set # CONFIG_PACKAGE_iperf is not set # CONFIG_PACKAGE_iperf3 is not set # CONFIG_PACKAGE_iperf3-ssl is not set # CONFIG_PACKAGE_ipip is not set CONFIG_PACKAGE_ipset=y # CONFIG_PACKAGE_ipset-dns is not set CONFIG_PACKAGE_ipt2socks=y # CONFIG_PACKAGE_iptraf-ng is not set # CONFIG_PACKAGE_iputils-arping is not set # CONFIG_PACKAGE_iputils-clockdiff is not set # CONFIG_PACKAGE_iputils-ping is not set # CONFIG_PACKAGE_iputils-tftpd is not set # CONFIG_PACKAGE_iputils-tracepath is not set # CONFIG_PACKAGE_ipvsadm is not set # CONFIG_PACKAGE_irtt is not set # CONFIG_PACKAGE_iw is not set # CONFIG_PACKAGE_iw-full is not set # CONFIG_PACKAGE_jool-tools is not set # CONFIG_PACKAGE_keepalived is not set # CONFIG_PACKAGE_knxd is not set # CONFIG_PACKAGE_kplex is not set # CONFIG_PACKAGE_krb5-client is not set # CONFIG_PACKAGE_krb5-libs is not set # CONFIG_PACKAGE_krb5-server is not set # CONFIG_PACKAGE_krb5-server-extras is not set CONFIG_PACKAGE_libipset=y # CONFIG_PACKAGE_libndp is not set # CONFIG_PACKAGE_linknx is not set # CONFIG_PACKAGE_lynx is not set # CONFIG_PACKAGE_mac-telnet-client is not set # CONFIG_PACKAGE_mac-telnet-discover is not set # CONFIG_PACKAGE_mac-telnet-ping is not set # CONFIG_PACKAGE_mac-telnet-server is not set # CONFIG_PACKAGE_map is not set # CONFIG_PACKAGE_mbusd is not set # CONFIG_PACKAGE_memcached is not set # CONFIG_PACKAGE_mentohust is not set # CONFIG_PACKAGE_mii-tool is not set # CONFIG_PACKAGE_mikrotik-btest is not set # CONFIG_PACKAGE_mini_snmpd is not set # CONFIG_PACKAGE_minimalist-pcproxy is not set # CONFIG_PACKAGE_miredo is not set # CONFIG_PACKAGE_modemmanager is not set # CONFIG_PACKAGE_mosquitto-client-nossl is not set # CONFIG_PACKAGE_mosquitto-client-ssl is not set # CONFIG_PACKAGE_mosquitto-nossl is not set # CONFIG_PACKAGE_mosquitto-ssl is not set # CONFIG_PACKAGE_mrd6 is not set # CONFIG_PACKAGE_mstpd is not set # CONFIG_PACKAGE_mtk_apcli is not set # CONFIG_PACKAGE_mtr is not set # CONFIG_PACKAGE_nbd is not set # CONFIG_PACKAGE_nbd-server is not set # CONFIG_PACKAGE_ncp is not set # CONFIG_PACKAGE_ndppd is not set # CONFIG_PACKAGE_ndptool is not set # CONFIG_PACKAGE_nebula is not set # CONFIG_PACKAGE_nebula-cert is not set # CONFIG_PACKAGE_net-tools-route is not set # CONFIG_PACKAGE_netcat is not set # CONFIG_PACKAGE_netdiscover is not set # CONFIG_PACKAGE_netifyd is not set # CONFIG_PACKAGE_netperf is not set # CONFIG_PACKAGE_netsniff-ng is not set # CONFIG_PACKAGE_netstinky is not set # CONFIG_PACKAGE_nextdns is not set # CONFIG_PACKAGE_nfdump is not set # CONFIG_PACKAGE_nlbwmon is not set # CONFIG_PACKAGE_noddos is not set # CONFIG_PACKAGE_noping is not set # CONFIG_PACKAGE_npc is not set # CONFIG_PACKAGE_nut is not set # CONFIG_PACKAGE_obfs4proxy is not set # CONFIG_PACKAGE_odhcp6c is not set # CONFIG_PACKAGE_odhcpd is not set # CONFIG_PACKAGE_odhcpd-ipv6only is not set # CONFIG_PACKAGE_ola is not set # CONFIG_PACKAGE_omcproxy is not set # CONFIG_PACKAGE_onionshare-cli is not set # CONFIG_PACKAGE_ooniprobe is not set # CONFIG_PACKAGE_oor is not set # CONFIG_PACKAGE_open-iscsi is not set # CONFIG_PACKAGE_oping is not set # CONFIG_PACKAGE_ostiary is not set # CONFIG_PACKAGE_pagekitec is not set # CONFIG_PACKAGE_pen is not set # CONFIG_PACKAGE_phantap is not set # CONFIG_PACKAGE_pimbd is not set # CONFIG_PACKAGE_pingcheck is not set # CONFIG_PACKAGE_port-mirroring is not set CONFIG_PACKAGE_ppp=y # CONFIG_PACKAGE_ppp-mod-passwordfd is not set # CONFIG_PACKAGE_ppp-mod-pppoa is not set CONFIG_PACKAGE_ppp-mod-pppoe=y # CONFIG_PACKAGE_ppp-mod-pppol2tp is not set # CONFIG_PACKAGE_ppp-mod-pptp is not set # CONFIG_PACKAGE_ppp-mod-radius is not set # CONFIG_PACKAGE_ppp-multilink is not set # CONFIG_PACKAGE_pppdump is not set # CONFIG_PACKAGE_pppoe-discovery is not set # CONFIG_PACKAGE_pppossh is not set # CONFIG_PACKAGE_pppstats is not set # CONFIG_PACKAGE_proto-bonding is not set # CONFIG_PACKAGE_proxychains-ng is not set # CONFIG_PACKAGE_ptunnel-ng is not set # CONFIG_PACKAGE_radsecproxy is not set # CONFIG_PACKAGE_ratched is not set # CONFIG_PACKAGE_ratechecker is not set # CONFIG_PACKAGE_redsocks is not set # CONFIG_PACKAGE_remserial is not set # CONFIG_PACKAGE_restic-rest-server is not set # CONFIG_PACKAGE_rpcapd is not set # CONFIG_PACKAGE_rpcbind is not set # CONFIG_PACKAGE_rssileds is not set # CONFIG_PACKAGE_rsyslog is not set # CONFIG_PACKAGE_safe-search is not set # CONFIG_PACKAGE_samba36-client is not set # CONFIG_PACKAGE_samba36-net is not set CONFIG_PACKAGE_samba36-server=y CONFIG_PACKAGE_SAMBA_MAX_DEBUG_LEVEL=-1 # CONFIG_PACKAGE_samba4-admin is not set # CONFIG_PACKAGE_samba4-client is not set # CONFIG_PACKAGE_samba4-libs is not set # CONFIG_PACKAGE_samba4-server is not set # CONFIG_PACKAGE_samba4-utils is not set # CONFIG_PACKAGE_samplicator is not set # CONFIG_PACKAGE_scapy is not set # CONFIG_PACKAGE_sctp-tools is not set # CONFIG_PACKAGE_seafile-ccnet is not set # CONFIG_PACKAGE_seafile-seahub is not set # CONFIG_PACKAGE_seafile-server is not set # CONFIG_PACKAGE_seafile-server-fuse is not set # CONFIG_PACKAGE_ser2net is not set # CONFIG_PACKAGE_simple-adblock is not set CONFIG_PACKAGE_simple-obfs=y # CONFIG_PACKAGE_simple-obfs-server is not set # # Simple-obfs Compile Configuration # # CONFIG_SIMPLE_OBFS_STATIC_LINK is not set # end of Simple-obfs Compile Configuration # CONFIG_PACKAGE_smartdns is not set # CONFIG_PACKAGE_smbinfo is not set # CONFIG_PACKAGE_snmp-mibs is not set # CONFIG_PACKAGE_snmp-utils is not set # CONFIG_PACKAGE_snmpd is not set # CONFIG_PACKAGE_snmptrapd is not set # CONFIG_PACKAGE_socat is not set # CONFIG_PACKAGE_softflowd is not set # CONFIG_PACKAGE_soloscli is not set # CONFIG_PACKAGE_speedtest-netperf is not set # CONFIG_PACKAGE_spoofer is not set # CONFIG_PACKAGE_ssocks is not set # CONFIG_PACKAGE_ssocksd is not set # CONFIG_PACKAGE_static-neighbor-reports is not set # CONFIG_PACKAGE_stunnel is not set # CONFIG_PACKAGE_switchdev-poller is not set # CONFIG_PACKAGE_tac_plus is not set # CONFIG_PACKAGE_tac_plus-pam is not set # CONFIG_PACKAGE_tayga is not set # CONFIG_PACKAGE_tcpdump is not set # CONFIG_PACKAGE_tcpdump-mini is not set CONFIG_PACKAGE_tcping=y # CONFIG_PACKAGE_tcpping is not set # CONFIG_PACKAGE_tgt is not set # CONFIG_PACKAGE_tmate-ssh-server is not set # CONFIG_PACKAGE_tor is not set # CONFIG_PACKAGE_tor-basic is not set # CONFIG_PACKAGE_tor-fw-helper is not set # CONFIG_PACKAGE_trafficshaper is not set # CONFIG_PACKAGE_travelmate is not set # CONFIG_PACKAGE_trojan is not set CONFIG_PACKAGE_trojan-plus=y # CONFIG_PACKAGE_u2pnpd is not set # CONFIG_PACKAGE_uacme is not set CONFIG_PACKAGE_uclient-fetch=y # CONFIG_PACKAGE_udptunnel is not set # CONFIG_PACKAGE_udpxy is not set # CONFIG_PACKAGE_ulogd is not set # CONFIG_PACKAGE_umdns is not set # CONFIG_PACKAGE_usbip is not set # CONFIG_PACKAGE_uugamebooster is not set # CONFIG_PACKAGE_v2ray-core is not set # CONFIG_PACKAGE_vallumd is not set # CONFIG_PACKAGE_verysync is not set CONFIG_PACKAGE_vlmcsd=y # CONFIG_PACKAGE_vncrepeater is not set # CONFIG_PACKAGE_vnstat is not set # CONFIG_PACKAGE_vnstat2 is not set # CONFIG_PACKAGE_vpn-policy-routing is not set # CONFIG_PACKAGE_vpnbypass is not set # CONFIG_PACKAGE_vti is not set # CONFIG_PACKAGE_vxlan is not set # CONFIG_PACKAGE_wakeonlan is not set # CONFIG_PACKAGE_wg-installer-client is not set # CONFIG_PACKAGE_wg-installer-server is not set # CONFIG_PACKAGE_wol is not set # CONFIG_PACKAGE_wpan-tools is not set # CONFIG_PACKAGE_wwan is not set # CONFIG_PACKAGE_xinetd is not set CONFIG_PACKAGE_xray-core=y # # Xray-core Configuration # # CONFIG_XRAY_CORE_COMPRESS_GOPROXY is not set CONFIG_XRAY_CORE_COMPRESS_UPX=y # end of Xray-core Configuration # CONFIG_PACKAGE_xray-example is not set # CONFIG_PACKAGE_xray-geodata is not set # CONFIG_PACKAGE_xray-plugin is not set # CONFIG_XRAY_PLUGIN_PROVIDE_V2RAY_PLUGIN is not set # CONFIG_XRAY_PLUGIN_COMPRESS_GOPROXY is not set CONFIG_XRAY_PLUGIN_COMPRESS_UPX=y # end of Network # # Sound # # CONFIG_PACKAGE_alsa-utils is not set # CONFIG_PACKAGE_alsa-utils-seq is not set # CONFIG_PACKAGE_alsa-utils-tests is not set # CONFIG_PACKAGE_aserver is not set # CONFIG_PACKAGE_espeak is not set # CONFIG_PACKAGE_faad2 is not set # CONFIG_PACKAGE_fdk-aac is not set # CONFIG_PACKAGE_forked-daapd is not set # CONFIG_PACKAGE_ices is not set # CONFIG_PACKAGE_lame is not set # CONFIG_PACKAGE_lame-lib is not set # CONFIG_PACKAGE_liblo-utils is not set # CONFIG_PACKAGE_madplay is not set # CONFIG_PACKAGE_moc is not set # CONFIG_PACKAGE_mpc is not set # CONFIG_PACKAGE_mpd-avahi-service is not set # CONFIG_PACKAGE_mpd-full is not set # CONFIG_PACKAGE_mpd-mini is not set # CONFIG_PACKAGE_mpg123 is not set # CONFIG_PACKAGE_opus-tools is not set # CONFIG_PACKAGE_pianod is not set # CONFIG_PACKAGE_pianod-client is not set # CONFIG_PACKAGE_portaudio is not set # CONFIG_PACKAGE_pulseaudio-daemon is not set # CONFIG_PACKAGE_pulseaudio-daemon-avahi is not set # CONFIG_PACKAGE_shairplay is not set # CONFIG_PACKAGE_shairport-sync-mbedtls is not set # CONFIG_PACKAGE_shairport-sync-mini is not set # CONFIG_PACKAGE_shairport-sync-openssl is not set # CONFIG_PACKAGE_shine is not set # CONFIG_PACKAGE_sox is not set # CONFIG_PACKAGE_squeezelite-full is not set # CONFIG_PACKAGE_squeezelite-mini is not set # CONFIG_PACKAGE_svox is not set # CONFIG_PACKAGE_upmpdcli is not set # end of Sound # # Utilities # # # AppArmor # # CONFIG_PACKAGE_apparmor-profiles is not set # CONFIG_PACKAGE_apparmor-utils is not set # end of AppArmor # # BigClown # # CONFIG_PACKAGE_bigclown-control-tool is not set # CONFIG_PACKAGE_bigclown-firmware-tool is not set # CONFIG_PACKAGE_bigclown-gateway is not set # CONFIG_PACKAGE_bigclown-mqtt2influxdb is not set # end of BigClown # # Boot Loaders # # CONFIG_PACKAGE_fconfig is not set # CONFIG_PACKAGE_uboot-envtools is not set # end of Boot Loaders # # Compression # # CONFIG_PACKAGE_bsdtar is not set # CONFIG_PACKAGE_bsdtar-noopenssl is not set # CONFIG_PACKAGE_bzip2 is not set # CONFIG_PACKAGE_gzip is not set # CONFIG_PACKAGE_lz4 is not set # CONFIG_PACKAGE_pigz is not set # CONFIG_PACKAGE_unrar is not set CONFIG_PACKAGE_unzip=y # CONFIG_PACKAGE_xz-utils is not set # CONFIG_PACKAGE_zipcmp is not set # CONFIG_PACKAGE_zipmerge is not set # CONFIG_PACKAGE_ziptool is not set # CONFIG_PACKAGE_zstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_mariadb-common is not set # CONFIG_PACKAGE_pgsql-cli is not set # CONFIG_PACKAGE_pgsql-cli-extra is not set # CONFIG_PACKAGE_pgsql-server is not set # CONFIG_PACKAGE_rrdcgi1 is not set # CONFIG_PACKAGE_rrdtool1 is not set # CONFIG_PACKAGE_sqlite3-cli is not set # CONFIG_PACKAGE_unixodbc-tools is not set # end of Database # # Disc # # CONFIG_PACKAGE_autopart is not set # CONFIG_PACKAGE_blkdiscard is not set CONFIG_PACKAGE_blkid=y # CONFIG_PACKAGE_blockdev is not set # CONFIG_PACKAGE_cfdisk is not set # CONFIG_PACKAGE_cgdisk is not set # CONFIG_PACKAGE_eject is not set # CONFIG_PACKAGE_fdisk is not set # CONFIG_PACKAGE_findfs is not set # CONFIG_PACKAGE_fio is not set # CONFIG_PACKAGE_fixparts is not set # CONFIG_PACKAGE_gdisk is not set # CONFIG_PACKAGE_hd-idle is not set # CONFIG_PACKAGE_hdparm is not set CONFIG_PACKAGE_lsblk=y # CONFIG_PACKAGE_lvm2 is not set # CONFIG_PACKAGE_lvm2-selinux is not set # CONFIG_PACKAGE_mdadm is not set # CONFIG_PACKAGE_mtools is not set CONFIG_PACKAGE_parted=y # # Configuration # CONFIG_PARTED_READLINE=y # CONFIG_PARTED_LVM2 is not set # end of Configuration # CONFIG_PACKAGE_partx-utils is not set # CONFIG_PACKAGE_sfdisk is not set # CONFIG_PACKAGE_sgdisk is not set # CONFIG_PACKAGE_uvol is not set # CONFIG_PACKAGE_wipefs is not set # end of Disc # # Editors # # CONFIG_PACKAGE_joe is not set # CONFIG_PACKAGE_joe-extras is not set # CONFIG_PACKAGE_jupp is not set # CONFIG_PACKAGE_mg is not set # CONFIG_PACKAGE_nano is not set # CONFIG_PACKAGE_vim is not set # CONFIG_PACKAGE_vim-full is not set # CONFIG_PACKAGE_vim-fuller is not set # CONFIG_PACKAGE_vim-help is not set # CONFIG_PACKAGE_vim-runtime is not set # CONFIG_PACKAGE_zile is not set # end of Editors # # Encryption # # CONFIG_PACKAGE_ccrypt is not set # CONFIG_PACKAGE_certtool is not set # CONFIG_PACKAGE_cryptsetup is not set # CONFIG_PACKAGE_gnupg is not set # CONFIG_PACKAGE_gnupg2 is not set # CONFIG_PACKAGE_gnupg2-dirmngr is not set # CONFIG_PACKAGE_gnutls-utils is not set # CONFIG_PACKAGE_gpgv is not set # CONFIG_PACKAGE_gpgv2 is not set # CONFIG_PACKAGE_keyctl is not set # CONFIG_PACKAGE_keyutils is not set # CONFIG_PACKAGE_px5g-mbedtls is not set # CONFIG_PACKAGE_px5g-standalone is not set # CONFIG_PACKAGE_px5g-wolfssl is not set # CONFIG_PACKAGE_stoken is not set # end of Encryption # # Filesystem # # CONFIG_PACKAGE_acl is not set # CONFIG_PACKAGE_antfs-mount is not set # CONFIG_PACKAGE_attr is not set # CONFIG_PACKAGE_badblocks is not set CONFIG_PACKAGE_btrfs-progs=y # CONFIG_BTRFS_PROGS_ZSTD is not set # CONFIG_PACKAGE_chattr is not set # CONFIG_PACKAGE_debugfs is not set # CONFIG_PACKAGE_dosfstools is not set # CONFIG_PACKAGE_dumpe2fs is not set # CONFIG_PACKAGE_e2freefrag is not set CONFIG_PACKAGE_e2fsprogs=y # CONFIG_PACKAGE_e4crypt is not set # CONFIG_PACKAGE_exfat-fsck is not set # CONFIG_PACKAGE_exfat-mkfs is not set # CONFIG_PACKAGE_f2fs-tools is not set # CONFIG_PACKAGE_f2fs-tools-selinux is not set # CONFIG_PACKAGE_f2fsck is not set # CONFIG_PACKAGE_f2fsck-selinux is not set # CONFIG_PACKAGE_filefrag is not set # CONFIG_PACKAGE_fstrim is not set # CONFIG_PACKAGE_fuse-utils is not set # CONFIG_PACKAGE_fuse3-utils is not set # CONFIG_PACKAGE_hfsfsck is not set # CONFIG_PACKAGE_lsattr is not set # CONFIG_PACKAGE_mkf2fs is not set # CONFIG_PACKAGE_mkf2fs-selinux is not set # CONFIG_PACKAGE_mkhfs is not set # CONFIG_PACKAGE_ncdu is not set # CONFIG_PACKAGE_nfs-utils is not set # CONFIG_PACKAGE_nfs-utils-libs is not set # CONFIG_PACKAGE_ntfs-3g is not set # CONFIG_PACKAGE_ntfs-3g-low is not set # CONFIG_PACKAGE_ntfs-3g-utils is not set # CONFIG_PACKAGE_ntfs3-mount is not set # CONFIG_PACKAGE_owfs is not set # CONFIG_PACKAGE_owshell is not set # CONFIG_PACKAGE_resize2fs is not set # CONFIG_PACKAGE_squashfs-tools-mksquashfs is not set # CONFIG_PACKAGE_squashfs-tools-unsquashfs is not set # CONFIG_PACKAGE_swap-utils is not set # CONFIG_PACKAGE_sysfsutils is not set # CONFIG_PACKAGE_tune2fs is not set # CONFIG_PACKAGE_xfs-admin is not set # CONFIG_PACKAGE_xfs-fsck is not set # CONFIG_PACKAGE_xfs-growfs is not set # CONFIG_PACKAGE_xfs-mkfs is not set # end of Filesystem # # Image Manipulation # # CONFIG_PACKAGE_libjpeg-turbo-utils is not set # CONFIG_PACKAGE_tiff-utils is not set # end of Image Manipulation # # Microcontroller programming # # CONFIG_PACKAGE_avrdude is not set # CONFIG_PACKAGE_dfu-programmer is not set # CONFIG_PACKAGE_stm32flash is not set # end of Microcontroller programming # # RTKLIB Suite # # CONFIG_PACKAGE_convbin is not set # CONFIG_PACKAGE_pos2kml is not set # CONFIG_PACKAGE_rnx2rtkp is not set # CONFIG_PACKAGE_rtkrcv is not set # CONFIG_PACKAGE_str2str is not set # end of RTKLIB Suite # # Shells # # CONFIG_PACKAGE_bash is not set # CONFIG_PACKAGE_fish is not set # CONFIG_PACKAGE_klish is not set # CONFIG_PACKAGE_mksh is not set # CONFIG_PACKAGE_tcsh is not set # CONFIG_PACKAGE_zsh is not set # end of Shells # # Telephony # # CONFIG_PACKAGE_dahdi-cfg is not set # CONFIG_PACKAGE_dahdi-monitor is not set # CONFIG_PACKAGE_gsm-utils is not set # CONFIG_PACKAGE_sipgrep is not set # CONFIG_PACKAGE_sngrep is not set # end of Telephony # # Terminal # # CONFIG_PACKAGE_agetty is not set # CONFIG_PACKAGE_dvtm is not set # CONFIG_PACKAGE_minicom is not set # CONFIG_PACKAGE_picocom is not set # CONFIG_PACKAGE_rtty-mbedtls is not set # CONFIG_PACKAGE_rtty-nossl is not set # CONFIG_PACKAGE_rtty-openssl is not set # CONFIG_PACKAGE_rtty-wolfssl is not set # CONFIG_PACKAGE_screen is not set # CONFIG_PACKAGE_script-utils is not set # CONFIG_PACKAGE_serialconsole is not set # CONFIG_PACKAGE_setterm is not set # CONFIG_PACKAGE_tio is not set # CONFIG_PACKAGE_tmux is not set CONFIG_PACKAGE_ttyd=y # CONFIG_PACKAGE_wall is not set # end of Terminal # # Virtualization # # end of Virtualization # # Zoneinfo # # CONFIG_PACKAGE_zoneinfo-africa is not set # CONFIG_PACKAGE_zoneinfo-all is not set # CONFIG_PACKAGE_zoneinfo-asia is not set # CONFIG_PACKAGE_zoneinfo-atlantic is not set # CONFIG_PACKAGE_zoneinfo-australia-nz is not set # CONFIG_PACKAGE_zoneinfo-core is not set # CONFIG_PACKAGE_zoneinfo-europe is not set # CONFIG_PACKAGE_zoneinfo-india is not set # CONFIG_PACKAGE_zoneinfo-northamerica is not set # CONFIG_PACKAGE_zoneinfo-pacific is not set # CONFIG_PACKAGE_zoneinfo-poles is not set # CONFIG_PACKAGE_zoneinfo-simple is not set # CONFIG_PACKAGE_zoneinfo-southamerica is not set # end of Zoneinfo # # libimobiledevice # # CONFIG_PACKAGE_idevicerestore is not set # CONFIG_PACKAGE_irecovery is not set # CONFIG_PACKAGE_libimobiledevice-utils is not set # CONFIG_PACKAGE_libusbmuxd-utils is not set # CONFIG_PACKAGE_plistutil is not set # CONFIG_PACKAGE_usbmuxd is not set # end of libimobiledevice # # libselinux tools # # CONFIG_PACKAGE_libselinux-avcstat is not set # CONFIG_PACKAGE_libselinux-compute_av is not set # CONFIG_PACKAGE_libselinux-compute_create is not set # CONFIG_PACKAGE_libselinux-compute_member is not set # CONFIG_PACKAGE_libselinux-compute_relabel is not set # CONFIG_PACKAGE_libselinux-getconlist is not set # CONFIG_PACKAGE_libselinux-getdefaultcon is not set # CONFIG_PACKAGE_libselinux-getenforce is not set # CONFIG_PACKAGE_libselinux-getfilecon is not set # CONFIG_PACKAGE_libselinux-getpidcon is not set # CONFIG_PACKAGE_libselinux-getsebool is not set # CONFIG_PACKAGE_libselinux-getseuser is not set # CONFIG_PACKAGE_libselinux-matchpathcon is not set # CONFIG_PACKAGE_libselinux-policyvers is not set # CONFIG_PACKAGE_libselinux-sefcontext_compile is not set # CONFIG_PACKAGE_libselinux-selabel_digest is not set # CONFIG_PACKAGE_libselinux-selabel_get_digests_all_partial_matches is not set # CONFIG_PACKAGE_libselinux-selabel_lookup is not set # CONFIG_PACKAGE_libselinux-selabel_lookup_best_match is not set # CONFIG_PACKAGE_libselinux-selabel_partial_match is not set # CONFIG_PACKAGE_libselinux-selinux_check_access is not set # CONFIG_PACKAGE_libselinux-selinux_check_securetty_context is not set # CONFIG_PACKAGE_libselinux-selinuxenabled is not set # CONFIG_PACKAGE_libselinux-selinuxexeccon is not set # CONFIG_PACKAGE_libselinux-setenforce is not set # CONFIG_PACKAGE_libselinux-setfilecon is not set # CONFIG_PACKAGE_libselinux-togglesebool is not set # CONFIG_PACKAGE_libselinux-validatetrans is not set # end of libselinux tools # CONFIG_PACKAGE_ack is not set # CONFIG_PACKAGE_acpid is not set # CONFIG_PACKAGE_adb is not set # CONFIG_PACKAGE_ap51-flash is not set # CONFIG_PACKAGE_apk is not set # CONFIG_PACKAGE_at is not set # CONFIG_PACKAGE_atheepmgr is not set # CONFIG_PACKAGE_audit is not set # CONFIG_PACKAGE_audit-utils is not set # CONFIG_PACKAGE_augeas is not set # CONFIG_PACKAGE_augeas-lenses is not set # CONFIG_PACKAGE_augeas-lenses-tests is not set # CONFIG_PACKAGE_bandwidthd is not set # CONFIG_PACKAGE_bandwidthd-pgsql is not set # CONFIG_PACKAGE_bandwidthd-php is not set # CONFIG_PACKAGE_bandwidthd-sqlite is not set # CONFIG_PACKAGE_banhostlist is not set # CONFIG_PACKAGE_bc is not set # CONFIG_PACKAGE_bluelog is not set # CONFIG_PACKAGE_bluez-daemon is not set # CONFIG_PACKAGE_bluez-utils is not set # CONFIG_PACKAGE_bluez-utils-extra is not set # CONFIG_PACKAGE_bluld is not set # CONFIG_PACKAGE_bonniexx is not set # CONFIG_PACKAGE_bottlerocket is not set # CONFIG_PACKAGE_bsdiff is not set # CONFIG_PACKAGE_bspatch is not set # CONFIG_PACKAGE_byobu is not set # CONFIG_PACKAGE_byobu-utils is not set # CONFIG_PACKAGE_cache-domains-mbedtls is not set # CONFIG_PACKAGE_cache-domains-openssl is not set # CONFIG_PACKAGE_cache-domains-wolfssl is not set # CONFIG_PACKAGE_cal is not set # CONFIG_PACKAGE_canutils is not set # CONFIG_PACKAGE_cgroup-tools is not set # CONFIG_PACKAGE_cgroupfs-mount is not set # CONFIG_PACKAGE_checkpolicy is not set # CONFIG_PACKAGE_checksec is not set # CONFIG_PACKAGE_checksec_automator is not set # CONFIG_PACKAGE_chkcon is not set # CONFIG_PACKAGE_cmdpad is not set # CONFIG_PACKAGE_cni is not set # CONFIG_PACKAGE_cni-plugins is not set # CONFIG_PACKAGE_cni-plugins-nft is not set # CONFIG_PACKAGE_coap-client is not set # CONFIG_PACKAGE_collectd is not set # CONFIG_PACKAGE_conmon is not set # CONFIG_PACKAGE_containerd is not set CONFIG_PACKAGE_coremark=y CONFIG_COREMARK_OPTIMIZE_O3=y CONFIG_COREMARK_ENABLE_MULTITHREADING=y CONFIG_COREMARK_NUMBER_OF_THREADS=16 CONFIG_PACKAGE_coreutils=y # CONFIG_PACKAGE_coreutils-b2sum is not set # CONFIG_PACKAGE_coreutils-base32 is not set CONFIG_PACKAGE_coreutils-base64=y # CONFIG_PACKAGE_coreutils-basename is not set # CONFIG_PACKAGE_coreutils-basenc is not set # CONFIG_PACKAGE_coreutils-cat is not set # CONFIG_PACKAGE_coreutils-chcon is not set # CONFIG_PACKAGE_coreutils-chgrp is not set # CONFIG_PACKAGE_coreutils-chmod is not set # CONFIG_PACKAGE_coreutils-chown is not set # CONFIG_PACKAGE_coreutils-chroot is not set # CONFIG_PACKAGE_coreutils-cksum is not set # CONFIG_PACKAGE_coreutils-comm is not set # CONFIG_PACKAGE_coreutils-cp is not set # CONFIG_PACKAGE_coreutils-csplit is not set # CONFIG_PACKAGE_coreutils-cut is not set # CONFIG_PACKAGE_coreutils-date is not set # CONFIG_PACKAGE_coreutils-dd is not set # CONFIG_PACKAGE_coreutils-df is not set # CONFIG_PACKAGE_coreutils-dir is not set # CONFIG_PACKAGE_coreutils-dircolors is not set # CONFIG_PACKAGE_coreutils-dirname is not set # CONFIG_PACKAGE_coreutils-du is not set # CONFIG_PACKAGE_coreutils-echo is not set # CONFIG_PACKAGE_coreutils-env is not set # CONFIG_PACKAGE_coreutils-expand is not set # CONFIG_PACKAGE_coreutils-expr is not set # CONFIG_PACKAGE_coreutils-factor is not set # CONFIG_PACKAGE_coreutils-false is not set # CONFIG_PACKAGE_coreutils-fmt is not set # CONFIG_PACKAGE_coreutils-fold is not set # CONFIG_PACKAGE_coreutils-groups is not set # CONFIG_PACKAGE_coreutils-head is not set # CONFIG_PACKAGE_coreutils-hostid is not set # CONFIG_PACKAGE_coreutils-id is not set # CONFIG_PACKAGE_coreutils-install is not set # CONFIG_PACKAGE_coreutils-join is not set # CONFIG_PACKAGE_coreutils-kill is not set # CONFIG_PACKAGE_coreutils-link is not set # CONFIG_PACKAGE_coreutils-ln is not set # CONFIG_PACKAGE_coreutils-logname is not set # CONFIG_PACKAGE_coreutils-ls is not set # CONFIG_PACKAGE_coreutils-md5sum is not set # CONFIG_PACKAGE_coreutils-mkdir is not set # CONFIG_PACKAGE_coreutils-mkfifo is not set # CONFIG_PACKAGE_coreutils-mknod is not set # CONFIG_PACKAGE_coreutils-mktemp is not set # CONFIG_PACKAGE_coreutils-mv is not set # CONFIG_PACKAGE_coreutils-nice is not set # CONFIG_PACKAGE_coreutils-nl is not set CONFIG_PACKAGE_coreutils-nohup=y # CONFIG_PACKAGE_coreutils-nproc is not set # CONFIG_PACKAGE_coreutils-numfmt is not set # CONFIG_PACKAGE_coreutils-od is not set # CONFIG_PACKAGE_coreutils-paste is not set # CONFIG_PACKAGE_coreutils-pathchk is not set # CONFIG_PACKAGE_coreutils-pinky is not set # CONFIG_PACKAGE_coreutils-pr is not set # CONFIG_PACKAGE_coreutils-printenv is not set # CONFIG_PACKAGE_coreutils-printf is not set # CONFIG_PACKAGE_coreutils-ptx is not set # CONFIG_PACKAGE_coreutils-pwd is not set # CONFIG_PACKAGE_coreutils-readlink is not set # CONFIG_PACKAGE_coreutils-realpath is not set # CONFIG_PACKAGE_coreutils-rm is not set # CONFIG_PACKAGE_coreutils-rmdir is not set # CONFIG_PACKAGE_coreutils-runcon is not set # CONFIG_PACKAGE_coreutils-seq is not set # CONFIG_PACKAGE_coreutils-sha1sum is not set # CONFIG_PACKAGE_coreutils-sha224sum is not set # CONFIG_PACKAGE_coreutils-sha256sum is not set # CONFIG_PACKAGE_coreutils-sha384sum is not set # CONFIG_PACKAGE_coreutils-sha512sum is not set # CONFIG_PACKAGE_coreutils-shred is not set # CONFIG_PACKAGE_coreutils-shuf is not set # CONFIG_PACKAGE_coreutils-sleep is not set # CONFIG_PACKAGE_coreutils-sort is not set # CONFIG_PACKAGE_coreutils-split is not set # CONFIG_PACKAGE_coreutils-stat is not set # CONFIG_PACKAGE_coreutils-stdbuf is not set # CONFIG_PACKAGE_coreutils-stty is not set # CONFIG_PACKAGE_coreutils-sum is not set # CONFIG_PACKAGE_coreutils-sync is not set # CONFIG_PACKAGE_coreutils-tac is not set # CONFIG_PACKAGE_coreutils-tail is not set # CONFIG_PACKAGE_coreutils-tee is not set # CONFIG_PACKAGE_coreutils-test is not set # CONFIG_PACKAGE_coreutils-timeout is not set # CONFIG_PACKAGE_coreutils-touch is not set # CONFIG_PACKAGE_coreutils-tr is not set # CONFIG_PACKAGE_coreutils-true is not set # CONFIG_PACKAGE_coreutils-truncate is not set # CONFIG_PACKAGE_coreutils-tsort is not set # CONFIG_PACKAGE_coreutils-tty is not set # CONFIG_PACKAGE_coreutils-uname is not set # CONFIG_PACKAGE_coreutils-unexpand is not set # CONFIG_PACKAGE_coreutils-uniq is not set # CONFIG_PACKAGE_coreutils-unlink is not set # CONFIG_PACKAGE_coreutils-uptime is not set # CONFIG_PACKAGE_coreutils-users is not set # CONFIG_PACKAGE_coreutils-vdir is not set # CONFIG_PACKAGE_coreutils-wc is not set # CONFIG_PACKAGE_coreutils-who is not set # CONFIG_PACKAGE_coreutils-whoami is not set # CONFIG_PACKAGE_coreutils-yes is not set # CONFIG_PACKAGE_crconf is not set # CONFIG_PACKAGE_crelay is not set # CONFIG_PACKAGE_crun is not set # CONFIG_PACKAGE_csstidy is not set # CONFIG_PACKAGE_ct-bugcheck is not set # CONFIG_PACKAGE_ctop is not set # CONFIG_PACKAGE_dbus is not set # CONFIG_PACKAGE_dbus-utils is not set # CONFIG_PACKAGE_device-observatory is not set # CONFIG_PACKAGE_dfu-util is not set # CONFIG_PACKAGE_digitemp is not set # CONFIG_PACKAGE_digitemp-usb is not set # CONFIG_PACKAGE_dmesg is not set # CONFIG_PACKAGE_docker is not set # CONFIG_PACKAGE_docker-compose is not set # CONFIG_PACKAGE_dockerd is not set # CONFIG_PACKAGE_dropbearconvert is not set # CONFIG_PACKAGE_dtc is not set # CONFIG_PACKAGE_dumb-init is not set # CONFIG_PACKAGE_dump1090 is not set # CONFIG_PACKAGE_ecdsautils is not set # CONFIG_PACKAGE_elektra-kdb is not set # CONFIG_PACKAGE_evtest is not set # CONFIG_PACKAGE_extract is not set # CONFIG_PACKAGE_fdt-utils is not set # CONFIG_PACKAGE_file is not set # CONFIG_PACKAGE_findutils is not set # CONFIG_PACKAGE_findutils-find is not set # CONFIG_PACKAGE_findutils-locate is not set # CONFIG_PACKAGE_findutils-xargs is not set # CONFIG_PACKAGE_flashrom is not set # CONFIG_PACKAGE_flashrom-pci is not set # CONFIG_PACKAGE_flashrom-spi is not set # CONFIG_PACKAGE_flashrom-usb is not set # CONFIG_PACKAGE_flent-tools is not set # CONFIG_PACKAGE_flock is not set # CONFIG_PACKAGE_fritz-caldata is not set # CONFIG_PACKAGE_fritz-tffs is not set # CONFIG_PACKAGE_fritz-tffs-nand is not set # CONFIG_PACKAGE_ftdi_eeprom is not set # CONFIG_PACKAGE_gammu is not set # CONFIG_PACKAGE_gawk is not set # CONFIG_PACKAGE_gddrescue is not set # CONFIG_PACKAGE_getopt is not set # CONFIG_PACKAGE_giflib-utils is not set # CONFIG_PACKAGE_gkermit is not set # CONFIG_PACKAGE_gnuplot is not set # CONFIG_PACKAGE_gpioctl-sysfs is not set # CONFIG_PACKAGE_gpiod-tools is not set # CONFIG_PACKAGE_gpsd is not set # CONFIG_PACKAGE_gpsd-clients is not set # CONFIG_PACKAGE_gpsd-utils is not set # CONFIG_PACKAGE_grep is not set # CONFIG_PACKAGE_hamlib is not set # CONFIG_PACKAGE_haserl is not set # CONFIG_PACKAGE_hashdeep is not set # CONFIG_PACKAGE_haveged is not set # CONFIG_PACKAGE_hplip-common is not set # CONFIG_PACKAGE_hplip-sane is not set # CONFIG_PACKAGE_hub-ctrl is not set # CONFIG_PACKAGE_hwclock is not set # CONFIG_PACKAGE_hwinfo is not set # CONFIG_PACKAGE_hwloc-utils is not set # CONFIG_PACKAGE_i2c-tools is not set # CONFIG_PACKAGE_iconv is not set # CONFIG_PACKAGE_iio-utils is not set # CONFIG_PACKAGE_inotifywait is not set # CONFIG_PACKAGE_inotifywatch is not set # CONFIG_PACKAGE_io is not set # CONFIG_PACKAGE_ipfs-http-client-tests is not set # CONFIG_PACKAGE_irqbalance is not set # CONFIG_PACKAGE_iwcap is not set CONFIG_PACKAGE_iwinfo=y # CONFIG_PACKAGE_jq is not set CONFIG_PACKAGE_jshn=y # CONFIG_PACKAGE_kmod is not set # CONFIG_PACKAGE_lcd4linux-custom is not set # CONFIG_PACKAGE_lcdproc-clients is not set # CONFIG_PACKAGE_lcdproc-drivers is not set # CONFIG_PACKAGE_lcdproc-server is not set # CONFIG_PACKAGE_less is not set # CONFIG_PACKAGE_less-wide is not set CONFIG_PACKAGE_libjson-script=y # CONFIG_PACKAGE_libnetwork is not set # CONFIG_PACKAGE_libxml2-utils is not set # CONFIG_PACKAGE_lm-sensors is not set # CONFIG_PACKAGE_lm-sensors-detect is not set # CONFIG_PACKAGE_logger is not set # CONFIG_PACKAGE_logrotate is not set # CONFIG_PACKAGE_look is not set # CONFIG_PACKAGE_losetup is not set # CONFIG_PACKAGE_lrzsz is not set # CONFIG_PACKAGE_lscpu is not set CONFIG_PACKAGE_lsof=y # CONFIG_PACKAGE_lxc is not set CONFIG_PACKAGE_maccalc=y # CONFIG_PACKAGE_macchanger is not set # CONFIG_PACKAGE_mandoc is not set # CONFIG_PACKAGE_mbedtls-util is not set # CONFIG_PACKAGE_mbim-utils is not set # CONFIG_PACKAGE_mbtools is not set # CONFIG_PACKAGE_mc is not set # CONFIG_PACKAGE_mcookie is not set # CONFIG_PACKAGE_micrond is not set # CONFIG_PACKAGE_mmc-utils is not set # CONFIG_PACKAGE_more is not set # CONFIG_PACKAGE_moreutils is not set # CONFIG_PACKAGE_mosh-client is not set # CONFIG_PACKAGE_mosh-server is not set # CONFIG_PACKAGE_mount-utils is not set # CONFIG_PACKAGE_mpack is not set # CONFIG_PACKAGE_mt-st is not set # CONFIG_PACKAGE_namei is not set # CONFIG_PACKAGE_nand-utils is not set # CONFIG_PACKAGE_naywatch is not set # CONFIG_PACKAGE_netopeer2-cli is not set # CONFIG_PACKAGE_netopeer2-server is not set # CONFIG_PACKAGE_netwhere is not set # CONFIG_PACKAGE_nnn is not set # CONFIG_PACKAGE_nsenter is not set # CONFIG_PACKAGE_nss-utils is not set # CONFIG_PACKAGE_oath-toolkit is not set # CONFIG_PACKAGE_oci-runtime-tool is not set # CONFIG_PACKAGE_open-plc-utils is not set # CONFIG_PACKAGE_open2300 is not set # CONFIG_PACKAGE_openobex is not set # CONFIG_PACKAGE_openobex-apps is not set # CONFIG_PACKAGE_openocd is not set # CONFIG_PACKAGE_opensc-utils is not set CONFIG_PACKAGE_openssl-util=y # CONFIG_PACKAGE_openzwave is not set # CONFIG_PACKAGE_openzwave-config is not set # CONFIG_PACKAGE_owipcalc is not set # CONFIG_PACKAGE_pciids is not set # CONFIG_PACKAGE_pciutils is not set # CONFIG_PACKAGE_pcsc-tools is not set # CONFIG_PACKAGE_pcscd is not set # CONFIG_PACKAGE_podman is not set # CONFIG_PACKAGE_podman-selinux is not set # CONFIG_PACKAGE_policycoreutils is not set # CONFIG_PACKAGE_powertop is not set # CONFIG_PACKAGE_pps-tools is not set # CONFIG_PACKAGE_prlimit is not set # CONFIG_PACKAGE_procps-ng is not set # CONFIG_PACKAGE_progress is not set # CONFIG_PACKAGE_prometheus is not set # CONFIG_PACKAGE_prometheus-node-exporter-lua is not set # CONFIG_PACKAGE_prometheus-statsd-exporter is not set # CONFIG_PACKAGE_pservice is not set # CONFIG_PACKAGE_psmisc is not set # CONFIG_PACKAGE_pv is not set # CONFIG_PACKAGE_qmi-utils is not set # CONFIG_PACKAGE_qrencode is not set # CONFIG_PACKAGE_quota is not set # CONFIG_PACKAGE_ravpower-mcu is not set # CONFIG_PACKAGE_rclone is not set # CONFIG_PACKAGE_readsb is not set # CONFIG_PACKAGE_relayctl is not set # CONFIG_PACKAGE_rename is not set # CONFIG_PACKAGE_restic is not set # CONFIG_PACKAGE_rng-tools is not set # CONFIG_PACKAGE_rtl-ais is not set # CONFIG_PACKAGE_rtl-sdr is not set # CONFIG_PACKAGE_rtl_433 is not set # CONFIG_PACKAGE_runc is not set # CONFIG_PACKAGE_sane-backends is not set # CONFIG_PACKAGE_sane-daemon is not set # CONFIG_PACKAGE_sane-frontends is not set # CONFIG_PACKAGE_secilc is not set # CONFIG_PACKAGE_sed is not set # CONFIG_PACKAGE_selinux-audit2allow is not set # CONFIG_PACKAGE_selinux-chcat is not set # CONFIG_PACKAGE_selinux-semanage is not set # CONFIG_PACKAGE_semodule-utils is not set # CONFIG_PACKAGE_serdisplib-tools is not set # CONFIG_PACKAGE_setools is not set # CONFIG_PACKAGE_setserial is not set # CONFIG_PACKAGE_shadow-utils is not set CONFIG_PACKAGE_shellsync=y # CONFIG_PACKAGE_sipcalc is not set # CONFIG_PACKAGE_sispmctl is not set # CONFIG_PACKAGE_slide-switch is not set # CONFIG_PACKAGE_smartd is not set # CONFIG_PACKAGE_smartd-mail is not set CONFIG_PACKAGE_smartmontools=y # CONFIG_PACKAGE_smartmontools-drivedb is not set # CONFIG_PACKAGE_smstools3 is not set # CONFIG_PACKAGE_sockread is not set # CONFIG_PACKAGE_spi-tools is not set # CONFIG_PACKAGE_spidev-test is not set # CONFIG_PACKAGE_ssdeep is not set # CONFIG_PACKAGE_sshpass is not set # CONFIG_PACKAGE_strace is not set CONFIG_STRACE_NONE=y # CONFIG_STRACE_LIBDW is not set # CONFIG_STRACE_LIBUNWIND is not set # CONFIG_PACKAGE_stress is not set # CONFIG_PACKAGE_stress-ng is not set # CONFIG_PACKAGE_sumo is not set # CONFIG_PACKAGE_syncthing is not set # CONFIG_PACKAGE_sysrepo is not set # CONFIG_PACKAGE_sysrepocfg is not set # CONFIG_PACKAGE_sysrepoctl is not set # CONFIG_PACKAGE_sysstat is not set # CONFIG_PACKAGE_tar is not set # CONFIG_PACKAGE_taskwarrior is not set # CONFIG_PACKAGE_telldus-core is not set # CONFIG_PACKAGE_temperusb is not set # CONFIG_PACKAGE_tesseract is not set # CONFIG_PACKAGE_tini is not set # CONFIG_PACKAGE_tracertools is not set # CONFIG_PACKAGE_tree is not set # CONFIG_PACKAGE_triggerhappy is not set CONFIG_PACKAGE_ubi-utils=y # CONFIG_PACKAGE_ucode is not set # CONFIG_PACKAGE_udns-dnsget is not set # CONFIG_PACKAGE_udns-ex-rdns is not set # CONFIG_PACKAGE_udns-rblcheck is not set # CONFIG_PACKAGE_ugps is not set # CONFIG_PACKAGE_uhubctl is not set # CONFIG_PACKAGE_uledd is not set # CONFIG_PACKAGE_unshare is not set # CONFIG_PACKAGE_usb-modeswitch is not set CONFIG_PACKAGE_usbids=y CONFIG_PACKAGE_usbutils=y # CONFIG_PACKAGE_uuidd is not set # CONFIG_PACKAGE_uuidgen is not set # CONFIG_PACKAGE_uvcdynctrl is not set # CONFIG_PACKAGE_v4l-utils is not set # CONFIG_PACKAGE_view1090 is not set # CONFIG_PACKAGE_viewadsb is not set # CONFIG_PACKAGE_watchcat is not set # CONFIG_PACKAGE_whereis is not set # CONFIG_PACKAGE_which is not set # CONFIG_PACKAGE_whiptail is not set # CONFIG_PACKAGE_whois is not set # CONFIG_PACKAGE_wifitoggle is not set # CONFIG_PACKAGE_wipe is not set # CONFIG_PACKAGE_xsltproc is not set # CONFIG_PACKAGE_xxd is not set # CONFIG_PACKAGE_yanglint is not set # CONFIG_PACKAGE_yara is not set # CONFIG_PACKAGE_ykclient is not set # CONFIG_PACKAGE_ykpers is not set # CONFIG_PACKAGE_yq is not set # end of Utilities # # Xorg # # # Font-Utils # # CONFIG_PACKAGE_fontconfig is not set # end of Font-Utils # end of Xorg CONFIG_OVERRIDE_PKGS="kcptun"
1f377735ffef5e234af4e653a5c49e8c8f72f731
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/blast_cc12.lean
f9486afcee8ace30debab687035085daf15d8f68
[ "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
596
lean
set_option blast.strategy "simple" definition foo1 (a b : nat) (p : Prop) : a = b → (b = a → p) → p := by blast print foo1 definition foo2 (a b c : nat) (p : Prop) : a = b → b = c → (c = a → p) → p := by blast print foo2 definition foo3 (a b c d : nat) (p : Prop) : a ≠ d → (d ≠ a → p) → p := by blast print foo3 attribute not [reducible] definition foo4 (a b c d : nat) (p : Prop) : a ≠ d → (d ≠ a → p) → p := by blast attribute ne [semireducible] definition foo5 (a b c d : nat) (p : Prop) : a ≠ d → (d ≠ a → p) → p := by blast print foo5
bda2a628884701ed0ced8381a41502f0802e930f
31f556cdeb9239ffc2fad8f905e33987ff4feab9
/src/Lean/LocalContext.lean
6d0e2785f46fa5ae7d938408feae5c378610d5f6
[ "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
tobiasgrosser/lean4
ce0fd9cca0feba1100656679bf41f0bffdbabb71
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
refs/heads/master
1,673,103,412,948
1,664,930,501,000
1,664,930,501,000
186,870,185
0
0
Apache-2.0
1,665,129,237,000
1,557,939,901,000
Lean
UTF-8
Lean
false
false
17,126
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 -/ import Lean.Data.PersistentArray import Lean.Expr import Lean.Hygiene namespace Lean /-- A declaration for a LocalContext. This is used to register which free variables are in scope. Each declaration comes with - `index` the position of the decl in the local context - `fvarId` the unique id of the free variables - `userName` the pretty-printable name of the variable - `type` the type. A `cdecl` is a local variable, a `ldecl` is a let-bound free variable with a `value : Expr`. -/ inductive LocalDecl where | cdecl (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo) | ldecl (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (value : Expr) (nonDep : Bool) deriving Inhabited @[export lean_mk_local_decl] def mkLocalDeclEx (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo) : LocalDecl := .cdecl index fvarId userName type bi @[export lean_mk_let_decl] def mkLetDeclEx (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (val : Expr) : LocalDecl := .ldecl index fvarId userName type val false @[export lean_local_decl_binder_info] def LocalDecl.binderInfoEx : LocalDecl → BinderInfo | .cdecl _ _ _ _ bi => bi | _ => BinderInfo.default namespace LocalDecl def isLet : LocalDecl → Bool | cdecl .. => false | ldecl .. => true def index : LocalDecl → Nat | cdecl (index := i) .. => i | ldecl (index := i) .. => i def setIndex : LocalDecl → Nat → LocalDecl | cdecl _ id n t bi, idx => cdecl idx id n t bi | ldecl _ id n t v nd, idx => ldecl idx id n t v nd def fvarId : LocalDecl → FVarId | cdecl (fvarId := id) .. => id | ldecl (fvarId := id) .. => id def userName : LocalDecl → Name | cdecl (userName := n) .. => n | ldecl (userName := n) .. => n def type : LocalDecl → Expr | cdecl (type := t) .. => t | ldecl (type := t) .. => t def setType : LocalDecl → Expr → LocalDecl | cdecl idx id n _ bi, t => cdecl idx id n t bi | ldecl idx id n _ v nd, t => ldecl idx id n t v nd def binderInfo : LocalDecl → BinderInfo | cdecl (bi := bi) .. => bi | ldecl .. => BinderInfo.default def isAuxDecl (d : LocalDecl) : Bool := d.binderInfo.isAuxDecl def value? : LocalDecl → Option Expr | cdecl .. => none | ldecl (value := v) .. => some v def value : LocalDecl → Expr | cdecl .. => panic! "let declaration expected" | ldecl (value := v) .. => v def hasValue : LocalDecl → Bool | cdecl .. => false | ldecl .. => true def setValue : LocalDecl → Expr → LocalDecl | ldecl idx id n t _ nd, v => ldecl idx id n t v nd | d, _ => d def setUserName : LocalDecl → Name → LocalDecl | cdecl index id _ type bi, userName => cdecl index id userName type bi | ldecl index id _ type val nd, userName => ldecl index id userName type val nd def setBinderInfo : LocalDecl → BinderInfo → LocalDecl | cdecl index id n type _, bi => cdecl index id n type bi | ldecl .., _ => panic! "unexpected let declaration" def toExpr (decl : LocalDecl) : Expr := mkFVar decl.fvarId def hasExprMVar : LocalDecl → Bool | cdecl (type := t) .. => t.hasExprMVar | ldecl (type := t) (value := v) .. => t.hasExprMVar || v.hasExprMVar end LocalDecl /-- A LocalContext is an ordered set of local variable declarations. It is used to store the free variables (also known as local constants) that are in scope. When inspecting a goal or expected type in the infoview, the local context is all of the variables above the `⊢` symbol. -/ structure LocalContext where fvarIdToDecl : PersistentHashMap FVarId LocalDecl := {} decls : PersistentArray (Option LocalDecl) := {} deriving Inhabited namespace LocalContext @[export lean_mk_empty_local_ctx] def mkEmpty : Unit → LocalContext := fun _ => {} def empty : LocalContext := {} @[export lean_local_ctx_is_empty] def isEmpty (lctx : LocalContext) : Bool := lctx.fvarIdToDecl.isEmpty /-- Low level API for creating local declarations. It is used to implement actions in the monads `Elab` and `Tactic`. It should not be used directly since the argument `(fvarId : FVarId)` is assumed to be unique. You can create a unique fvarId with `mkFreshFVarId`. -/ @[export lean_local_ctx_mk_local_decl] def mkLocalDecl (lctx : LocalContext) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => let idx := decls.size let decl := LocalDecl.cdecl idx fvarId userName type bi { fvarIdToDecl := map.insert fvarId decl, decls := decls.push decl } /-- Low level API for let declarations. Do not use directly.-/ @[export lean_local_ctx_mk_let_decl] def mkLetDecl (lctx : LocalContext) (fvarId : FVarId) (userName : Name) (type : Expr) (value : Expr) (nonDep := false) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => let idx := decls.size let decl := LocalDecl.ldecl idx fvarId userName type value nonDep { fvarIdToDecl := map.insert fvarId decl, decls := decls.push decl } /-- Low level API for adding a local declaration. Do not use directly. -/ def addDecl (lctx : LocalContext) (newDecl : LocalDecl) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => let idx := decls.size let newDecl := newDecl.setIndex idx { fvarIdToDecl := map.insert newDecl.fvarId newDecl, decls := decls.push newDecl } @[export lean_local_ctx_find] def find? (lctx : LocalContext) (fvarId : FVarId) : Option LocalDecl := lctx.fvarIdToDecl.find? fvarId def findFVar? (lctx : LocalContext) (e : Expr) : Option LocalDecl := lctx.find? e.fvarId! def get! (lctx : LocalContext) (fvarId : FVarId) : LocalDecl := match lctx.find? fvarId with | some d => d | none => panic! "unknown free variable" /-- Gets the declaration for expression `e` in the local context. If `e` is not a free variable or not present then panics. -/ def getFVar! (lctx : LocalContext) (e : Expr) : LocalDecl := lctx.get! e.fvarId! def contains (lctx : LocalContext) (fvarId : FVarId) : Bool := lctx.fvarIdToDecl.contains fvarId /-- Returns true when the lctx contains the free variable `e`. Panics if `e` is not an fvar. -/ def containsFVar (lctx : LocalContext) (e : Expr) : Bool := lctx.contains e.fvarId! def getFVarIds (lctx : LocalContext) : Array FVarId := lctx.decls.foldl (init := #[]) fun r decl? => match decl? with | some decl => r.push decl.fvarId | none => r /-- Return all of the free variables in the given context. -/ def getFVars (lctx : LocalContext) : Array Expr := lctx.getFVarIds.map mkFVar private partial def popTailNoneAux (a : PArray (Option LocalDecl)) : PArray (Option LocalDecl) := if a.size == 0 then a else match a.get! (a.size - 1) with | none => popTailNoneAux a.pop | some _ => a @[export lean_local_ctx_erase] def erase (lctx : LocalContext) (fvarId : FVarId) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => match map.find? fvarId with | none => lctx | some decl => { fvarIdToDecl := map.erase fvarId, decls := popTailNoneAux (decls.set decl.index none) } def pop (lctx : LocalContext): LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => if decls.size == 0 then lctx else match decls.get! (decls.size - 1) with | none => lctx -- unreachable | some decl => { fvarIdToDecl := map.erase decl.fvarId, decls := popTailNoneAux decls.pop } def findFromUserName? (lctx : LocalContext) (userName : Name) : Option LocalDecl := lctx.decls.findSomeRev? fun decl => match decl with | none => none | some decl => if decl.userName == userName then some decl else none def usesUserName (lctx : LocalContext) (userName : Name) : Bool := (lctx.findFromUserName? userName).isSome private partial def getUnusedNameAux (lctx : LocalContext) (suggestion : Name) (i : Nat) : Name × Nat := let curr := suggestion.appendIndexAfter i if lctx.usesUserName curr then getUnusedNameAux lctx suggestion (i + 1) else (curr, i + 1) def getUnusedName (lctx : LocalContext) (suggestion : Name) : Name := let suggestion := suggestion.eraseMacroScopes if lctx.usesUserName suggestion then (getUnusedNameAux lctx suggestion 1).1 else suggestion def lastDecl (lctx : LocalContext) : Option LocalDecl := lctx.decls.get! (lctx.decls.size - 1) def setUserName (lctx : LocalContext) (fvarId : FVarId) (userName : Name) : LocalContext := let decl := lctx.get! fvarId let decl := decl.setUserName userName { fvarIdToDecl := lctx.fvarIdToDecl.insert decl.fvarId decl, decls := lctx.decls.set decl.index decl } def renameUserName (lctx : LocalContext) (fromName : Name) (toName : Name) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => match lctx.findFromUserName? fromName with | none => lctx | some decl => let decl := decl.setUserName toName; { fvarIdToDecl := map.insert decl.fvarId decl, decls := decls.set decl.index decl } /-- Low-level function for updating the local context. Assumptions about `f`, the resulting nested expressions must be definitionally equal to their original values, the `index` nor `fvarId` are modified. -/ @[inline] def modifyLocalDecl (lctx : LocalContext) (fvarId : FVarId) (f : LocalDecl → LocalDecl) : LocalContext := match lctx with | { fvarIdToDecl := map, decls := decls } => match lctx.find? fvarId with | none => lctx | some decl => let decl := f decl { fvarIdToDecl := map.insert decl.fvarId decl decls := decls.set decl.index decl } def setBinderInfo (lctx : LocalContext) (fvarId : FVarId) (bi : BinderInfo) : LocalContext := modifyLocalDecl lctx fvarId fun decl => decl.setBinderInfo bi @[export lean_local_ctx_num_indices] def numIndices (lctx : LocalContext) : Nat := lctx.decls.size def getAt? (lctx : LocalContext) (i : Nat) : Option LocalDecl := lctx.decls.get! i @[specialize] def foldlM [Monad m] (lctx : LocalContext) (f : β → LocalDecl → m β) (init : β) (start : Nat := 0) : m β := lctx.decls.foldlM (init := init) (start := start) fun b decl => match decl with | none => pure b | some decl => f b decl @[specialize] def foldrM [Monad m] (lctx : LocalContext) (f : LocalDecl → β → m β) (init : β) : m β := lctx.decls.foldrM (init := init) fun decl b => match decl with | none => pure b | some decl => f decl b @[specialize] def forM [Monad m] (lctx : LocalContext) (f : LocalDecl → m PUnit) : m PUnit := lctx.decls.forM fun decl => match decl with | none => pure PUnit.unit | some decl => f decl @[specialize] def findDeclM? [Monad m] (lctx : LocalContext) (f : LocalDecl → m (Option β)) : m (Option β) := lctx.decls.findSomeM? fun decl => match decl with | none => pure none | some decl => f decl @[specialize] def findDeclRevM? [Monad m] (lctx : LocalContext) (f : LocalDecl → m (Option β)) : m (Option β) := lctx.decls.findSomeRevM? fun decl => match decl with | none => pure none | some decl => f decl instance : ForIn m LocalContext LocalDecl where forIn lctx init f := lctx.decls.forIn init fun d? b => match d? with | none => return ForInStep.yield b | some d => f d b @[inline] def foldl (lctx : LocalContext) (f : β → LocalDecl → β) (init : β) (start : Nat := 0) : β := Id.run <| lctx.foldlM f init start @[inline] def foldr (lctx : LocalContext) (f : LocalDecl → β → β) (init : β) : β := Id.run <| lctx.foldrM f init def size (lctx : LocalContext) : Nat := lctx.foldl (fun n _ => n+1) 0 @[inline] def findDecl? (lctx : LocalContext) (f : LocalDecl → Option β) : Option β := Id.run <| lctx.findDeclM? f @[inline] def findDeclRev? (lctx : LocalContext) (f : LocalDecl → Option β) : Option β := Id.run <| lctx.findDeclRevM? f partial def isSubPrefixOfAux (a₁ a₂ : PArray (Option LocalDecl)) (exceptFVars : Array Expr) (i j : Nat) : Bool := if i < a₁.size then match a₁[i]! with | none => isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) j | some decl₁ => if exceptFVars.any fun fvar => fvar.fvarId! == decl₁.fvarId then isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) j else if j < a₂.size then match a₂[j]! with | none => isSubPrefixOfAux a₁ a₂ exceptFVars i (j+1) | some decl₂ => if decl₁.fvarId == decl₂.fvarId then isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) (j+1) else isSubPrefixOfAux a₁ a₂ exceptFVars i (j+1) else false else true /-- Given `lctx₁ - exceptFVars` of the form `(x_1 : A_1) ... (x_n : A_n)`, then return true iff there is a local context `B_1* (x_1 : A_1) ... B_n* (x_n : A_n)` which is a prefix of `lctx₂` where `B_i`'s are (possibly empty) sequences of local declarations. -/ def isSubPrefixOf (lctx₁ lctx₂ : LocalContext) (exceptFVars : Array Expr := #[]) : Bool := isSubPrefixOfAux lctx₁.decls lctx₂.decls exceptFVars 0 0 @[inline] def mkBinding (isLambda : Bool) (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr := let b := b.abstract xs xs.size.foldRev (init := b) fun i b => let x := xs[i]! match lctx.findFVar? x with | some (.cdecl _ _ n ty bi) => let ty := ty.abstractRange i xs; if isLambda then Lean.mkLambda n bi ty b else Lean.mkForall n bi ty b | some (.ldecl _ _ n ty val nonDep) => if b.hasLooseBVar 0 then let ty := ty.abstractRange i xs let val := val.abstractRange i xs mkLet n ty val b nonDep else b.lowerLooseBVars 1 1 | none => panic! "unknown free variable" /-- Creates the expression `fun x₁ .. xₙ => b` for free variables `xs = #[x₁, .., xₙ]`, suitably abstracting `b` and the types for each of the `xᵢ`. -/ def mkLambda (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr := mkBinding true lctx xs b /-- Creates the expression `(x₁:α₁) → .. → (xₙ:αₙ) → b` for free variables `xs = #[x₁, .., xₙ]`, suitably abstracting `b` and the types for each of the `xᵢ`, `αᵢ`. -/ def mkForall (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr := mkBinding false lctx xs b @[inline] def anyM [Monad m] (lctx : LocalContext) (p : LocalDecl → m Bool) : m Bool := lctx.decls.anyM fun d => match d with | some decl => p decl | none => pure false @[inline] def allM [Monad m] (lctx : LocalContext) (p : LocalDecl → m Bool) : m Bool := lctx.decls.allM fun d => match d with | some decl => p decl | none => pure true /-- Return `true` if `lctx` contains a local declaration satisfying `p`. -/ @[inline] def any (lctx : LocalContext) (p : LocalDecl → Bool) : Bool := Id.run <| lctx.anyM p /-- Return `true` if all declarations in `lctx` satisfy `p`. -/ @[inline] def all (lctx : LocalContext) (p : LocalDecl → Bool) : Bool := Id.run <| lctx.allM p /-- If option `pp.sanitizeNames` is set to `true`, add tombstone to shadowed local declaration names and ones contains macroscopes. -/ def sanitizeNames (lctx : LocalContext) : StateM NameSanitizerState LocalContext := do let st ← get if !getSanitizeNames st.options then pure lctx else StateT.run' (s := ({} : NameSet)) <| lctx.decls.size.foldRevM (init := lctx) fun i lctx => do match lctx.decls[i]! with | none => pure lctx | some decl => if decl.userName.hasMacroScopes || (← get).contains decl.userName then do modify fun s => s.insert decl.userName let userNameNew ← liftM <| sanitizeName decl.userName pure <| lctx.setUserName decl.fvarId userNameNew else modify fun s => s.insert decl.userName pure lctx end LocalContext /-- Class used to denote that `m` has a local context. -/ class MonadLCtx (m : Type → Type) where getLCtx : m LocalContext export MonadLCtx (getLCtx) instance [MonadLift m n] [MonadLCtx m] : MonadLCtx n where getLCtx := liftM (getLCtx : m _) def LocalDecl.replaceFVarId (fvarId : FVarId) (e : Expr) (d : LocalDecl) : LocalDecl := if d.fvarId == fvarId then d else match d with | .cdecl idx id n type bi => .cdecl idx id n (type.replaceFVarId fvarId e) bi | .ldecl idx id n type val nonDep => .ldecl idx id n (type.replaceFVarId fvarId e) (val.replaceFVarId fvarId e) nonDep def LocalContext.replaceFVarId (fvarId : FVarId) (e : Expr) (lctx : LocalContext) : LocalContext := let lctx := lctx.erase fvarId { fvarIdToDecl := lctx.fvarIdToDecl.map (·.replaceFVarId fvarId e) decls := lctx.decls.map fun localDecl? => localDecl?.map (·.replaceFVarId fvarId e) } end Lean
176fe8db84b7a436bc0b0e4303e039fbaccaa2c2
07c6143268cfb72beccd1cc35735d424ebcb187b
/src/category_theory/limits/shapes/regular_mono.lean
72cf57b2030f37d543eca0909ca3251d09bd00a7
[ "Apache-2.0" ]
permissive
khoek/mathlib
bc49a842910af13a3c372748310e86467d1dc766
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
refs/heads/master
1,588,232,063,837
1,587,304,803,000
1,587,304,803,000
176,688,517
0
0
Apache-2.0
1,553,070,585,000
1,553,070,585,000
null
UTF-8
Lean
false
false
5,528
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.epi_mono import category_theory.limits.shapes.kernels import category_theory.limits.shapes.strong_epi /-! # Definitions and basic properties of regular and normal monomorphisms and epimorphisms. A regular monomorphism is a morphism that is the equalizer of some parallel pair. A normal monomorphism is a morphism that is the kernel of some other morphism. We give the constructions * `split_mono → regular_mono` * `normal_mono → regular_mono`, and * `regular_mono → mono` as well as the dual constructions for regular and normal epimorphisms. Additionally, we give the construction * `regular_epi ⟶ strong_epi`. -/ namespace category_theory open category_theory.limits universes v₁ u₁ variables {C : Type u₁} [𝒞 : category.{v₁} C] include 𝒞 variables {X Y : C} /-- A regular monomorphism is a morphism which is the equalizer of some parallel pair. -/ class regular_mono (f : X ⟶ Y) := (Z : C) (left right : Y ⟶ Z) (w : f ≫ left = f ≫ right) (is_limit : is_limit (fork.of_ι f w)) attribute [reassoc] regular_mono.w /-- Every regular monomorphism is a monomorphism. -/ @[priority 100] instance regular_mono.mono (f : X ⟶ Y) [regular_mono f] : mono f := mono_of_is_limit_parallel_pair regular_mono.is_limit /-- Every split monomorphism is a regular monomorphism. -/ @[priority 100] instance regular_mono.of_split_mono (f : X ⟶ Y) [split_mono f] : regular_mono f := { Z := Y, left := 𝟙 Y, right := retraction f ≫ f, w := by tidy, is_limit := split_mono_equalizes f } /-- If `f` is a regular mono, then any map `k : W ⟶ Y` equalizing `regular_mono.left` and `regular_mono.right` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def regular_mono.lift' {W : C} (f : X ⟶ Y) [regular_mono f] (k : W ⟶ Y) (h : k ≫ (regular_mono.left : Y ⟶ @regular_mono.Z _ _ _ _ f _) = k ≫ regular_mono.right) : {l : W ⟶ X // l ≫ f = k} := fork.is_limit.lift' regular_mono.is_limit _ h section variables [has_zero_morphisms.{v₁} C] /-- A normal monomorphism is a morphism which is the kernel of some morphism. -/ class normal_mono (f : X ⟶ Y) := (Z : C) (g : Y ⟶ Z) (w : f ≫ g = 0) (is_limit : is_limit (kernel_fork.of_ι f w)) /-- Every normal monomorphism is a regular monomorphism. -/ @[priority 100] instance normal_mono.regular_mono (f : X ⟶ Y) [I : normal_mono f] : regular_mono f := { left := I.g, right := 0, w := (by simpa using I.w), ..I } /-- If `f` is a normal mono, then any map `k : W ⟶ Y` such that `k ≫ normal_mono.g = 0` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def normal_mono.lift' {W : C} (f : X ⟶ Y) [normal_mono f] (k : W ⟶ Y) (h : k ≫ normal_mono.g = 0) : {l : W ⟶ X // l ≫ f = k} := kernel_fork.is_limit.lift' normal_mono.is_limit _ h end /-- A regular epimorphism is a morphism which is the coequalizer of some parallel pair. -/ class regular_epi (f : X ⟶ Y) := (W : C) (left right : W ⟶ X) (w : left ≫ f = right ≫ f) (is_colimit : is_colimit (cofork.of_π f w)) attribute [reassoc] regular_epi.w /-- Every regular epimorphism is an epimorphism. -/ @[priority 100] instance regular_epi.epi (f : X ⟶ Y) [regular_epi f] : epi f := epi_of_is_colimit_parallel_pair regular_epi.is_colimit /-- Every split epimorphism is a regular epimorphism. -/ @[priority 100] instance regular_epi.of_split_epi (f : X ⟶ Y) [split_epi f] : regular_epi f := { W := X, left := 𝟙 X, right := f ≫ section_ f, w := by tidy, is_colimit := split_epi_coequalizes f } /-- If `f` is a regular epi, then every morphism `k : X ⟶ W` coequalizing `regular_epi.left` and `regular_epi.right` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def regular_epi.desc' {W : C} (f : X ⟶ Y) [regular_epi f] (k : X ⟶ W) (h : (regular_epi.left : regular_epi.W f ⟶ X) ≫ k = regular_epi.right ≫ k) : {l : Y ⟶ W // f ≫ l = k} := cofork.is_colimit.desc' (regular_epi.is_colimit) _ h @[priority 100] instance strong_epi_of_regular_epi (f : X ⟶ Y) [regular_epi f] : strong_epi f := { epi := by apply_instance, has_lift := begin introsI, have : (regular_epi.left : regular_epi.W f ⟶ X) ≫ u = regular_epi.right ≫ u, { apply (cancel_mono z).1, simp only [category.assoc, h, regular_epi.w_assoc] }, obtain ⟨t, ht⟩ := regular_epi.desc' f u this, exact ⟨t, ht, (cancel_epi f).1 (by simp only [←category.assoc, ht, ←h, arrow.mk_hom, arrow.hom_mk'_right])⟩, end } section variables [has_zero_morphisms.{v₁} C] /-- A normal epimorphism is a morphism which is the cokernel of some morphism. -/ class normal_epi (f : X ⟶ Y) := (W : C) (g : W ⟶ X) (w : g ≫ f = 0) (is_colimit : is_colimit (cokernel_cofork.of_π f w)) /-- Every normal epimorphism is a regular epimorphism. -/ @[priority 100] instance normal_epi.regular_epi (f : X ⟶ Y) [I : normal_epi f] : regular_epi f := { left := I.g, right := 0, w := (by simpa using I.w), ..I } /-- If `f` is a normal epi, then every morphism `k : X ⟶ W` satisfying `normal_epi.g ≫ k = 0` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def normal_epi.desc' {W : C} (f : X ⟶ Y) [normal_epi f] (k : X ⟶ W) (h : normal_epi.g ≫ k = 0) : {l : Y ⟶ W // f ≫ l = k} := cokernel_cofork.is_colimit.desc' (normal_epi.is_colimit) _ h end end category_theory
91a07448aa01a9289cb59ba52f69e01e7c19f22d
e38e95b38a38a99ecfa1255822e78e4b26f65bb0
/src/certigrad/tvec.lean
75ca82bd87195882ed133407ac208c5dcbafeaa5
[ "Apache-2.0" ]
permissive
ColaDrill/certigrad
fefb1be3670adccd3bed2f3faf57507f156fd501
fe288251f623ac7152e5ce555f1cd9d3a20203c2
refs/heads/master
1,593,297,324,250
1,499,903,753,000
1,499,903,753,000
97,075,797
1
0
null
1,499,916,210,000
1,499,916,210,000
null
UTF-8
Lean
false
false
3,161
lean
/- Copyright (c) 2017 Daniel Selsam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Daniel Selsam Properties of dvecs of tensors. We often want to do algebra manipulations on an entire dvec at a time, and this file makes it possible to use standard notation when doing so. -/ import .tensor .dvec .util .graph namespace certigrad namespace tvec def lift0 (f : Π {shape : S}, T shape) : Π (shapes : list S), dvec T shapes | [] := dvec.nil | (shape::shapes) := dvec.cons f (lift0 shapes) instance {shapes : list S} : has_zero (dvec T shapes) := ⟨tvec.lift0 (λ sh, 0) shapes⟩ instance {shapes : list S} : has_one (dvec T shapes) := ⟨tvec.lift0 (λ sh, 1) shapes⟩ def lift1 (f : Π {shape : S}, T shape → T shape) : Π {shapes : list S}, dvec T shapes → dvec T shapes | [] _ := dvec.nil | (shape::shapes) (dvec.cons x xs) := dvec.cons (f x) (lift1 xs) instance {shapes : list S} : has_neg (dvec T shapes) := ⟨@tvec.lift1 (λ sh x, - x) shapes⟩ instance {shapes : list S} : has_inv (dvec T shapes) := ⟨@tvec.lift1 (λ sh x, x⁻¹) shapes⟩ def sqrt {shapes : list S} (xs : dvec T shapes) : dvec T shapes := lift1 @T.sqrt xs def lift2 (f : Π {shape : S}, T shape → T shape → T shape) : Π (shapes : list S), dvec T shapes → dvec T shapes → dvec T shapes | [] _ _ := dvec.nil | (shape::shapes) (dvec.cons x xs) (dvec.cons y ys) := dvec.cons (f x y) (lift2 shapes xs ys) instance {shapes : list S} : has_add (dvec T shapes) := ⟨tvec.lift2 (λ sh x y, x + y) shapes⟩ instance {shapes : list S} : has_mul (dvec T shapes) := ⟨tvec.lift2 (λ sh x y, x * y) shapes⟩ instance {shapes : list S} : has_sub (dvec T shapes) := ⟨tvec.lift2 (λ sh x y, x - y) shapes⟩ instance {shapes : list S} : has_div (dvec T shapes) := ⟨tvec.lift2 (λ sh x y, x / y) shapes⟩ def scalar_mul : Π (shapes : list S), ℝ → dvec T shapes → dvec T shapes | [] α _ := dvec.nil | (shape::shapes) α (dvec.cons x xs) := dvec.cons (α ⬝ x) (scalar_mul shapes α xs) instance {shapes : list S} : has_smul (ℝ) (dvec T shapes) := ⟨tvec.scalar_mul shapes⟩ ----- Build env from dvec def to_env_core : Π (names : list ID) (shapes : list S) (xs : dvec T shapes), env | (name::names) (shape::shapes) (dvec.cons x xs) := env.insert (name, shape) x (to_env_core names shapes xs) | _ _ _ := env.mk def to_env (refs : list reference) (xs : dvec T refs^.p2) : env := to_env_core refs^.p1 refs^.p2 xs -- Build dvec from env def from_env : Π (tgts : list reference) (m : env), dvec T tgts^.p2 | (tgt::tgts) m := (env.get tgt m) ::: (from_env tgts m) | [] _ := ⟦⟧ open list lemma get_from_env {refs : list reference} {idx : ℕ} {ref : reference} (H_at_idx : at_idx refs idx ref) (m : env) : dvec.get ref.2 (from_env refs m) idx = env.get ref m := begin assertv H_elem_at_idx : elem_at_idx refs idx ref := elem_at_idx_of_at_idx H_at_idx, induction H_elem_at_idx with xs x xs idx' x y H_elem_at_idx IH, { dunfold from_env, erw dvec.get.equations._eqn_2, simp }, { dunfold from_env, erw dvec.get.equations._eqn_3, exact IH (at_idx_of_cons H_at_idx) } end end tvec end certigrad
3e888c7ce62f13f6a298b40a55acd94377b8b0d1
fe84e287c662151bb313504482b218a503b972f3
/src/combinatorics/nat_partitions.lean
e7bd83f43204d85b6b86c947bb658bfa4ab97386
[]
no_license
NeilStrickland/lean_lib
91e163f514b829c42fe75636407138b5c75cba83
6a9563de93748ace509d9db4302db6cd77d8f92c
refs/heads/master
1,653,408,198,261
1,652,996,419,000
1,652,996,419,000
181,006,067
4
1
null
null
null
null
UTF-8
Lean
false
false
9,991
lean
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland (This is part of an attempt to formalise some material from a basic undergraduate combinatorics course.) We consider the equation x₀ + ... + xₘ = n, where the variables xᵢ are natural numbers. The set of solutions bijects with the set of (n,m) grid paths, so the number of solutions is (n + m) choose n. There are various possible modifications, where we might impose constraints xᵢ ≥ cᵢ for example. -/ import data.pnat.basic data.finset combinatorics.enumeration namespace combinatorics def inc_list (α : Type) [linear_order α] : Type := { l : list α // l.pairwise has_lt.lt } namespace inc_list variables {α : Type} [linear_order α] instance : has_coe (inc_list α) (list α) := ⟨λ l, l.val⟩ lemma coe_inj {l₀ l₁ : inc_list α} : (l₀ : list α) = (l₁ : list α) → l₀ = l₁ := subtype.eq instance : has_mem α (inc_list α) := ⟨λ a l, a ∈ (l : list α) ⟩ lemma nodup (l : inc_list α) : (l : list α).nodup := list.pairwise.imp (λ a₀ a₁ h, ne_of_lt h) l.property def to_finset (l : inc_list α) : finset α := ⟨(l : list α),l.nodup⟩ def of_finset (s : finset α) : inc_list α := ⟨ s.sort has_le.le, begin have hx := list.pairwise.and (s.sort_sorted has_le.le) (s.sort_nodup has_le.le), have hi : ∀ (a b : α) (h : a ≤ b ∧ a ≠ b), a < b := λ a b h, lt_of_le_of_ne h.1 h.2, exact list.pairwise.imp hi hx, end⟩ lemma to_of_finset (s : finset α) : to_finset (of_finset s) = s := (list.to_finset_eq (s.sort_nodup has_le.le)).trans (s.sort_to_finset has_le.le) lemma of_to_finset (l : inc_list α) : of_finset (to_finset l) = l := coe_inj $ list.eq_of_perm_of_sorted (list.perm_merge_sort _ _) (of_finset (to_finset l)).property l.property def finset_equiv : inc_list α ≃ finset α := { to_fun := to_finset, inv_fun := of_finset, left_inv := of_to_finset, right_inv := to_of_finset } def nil : inc_list α := ⟨[],list.pairwise.nil⟩ def cons (a : α) (l : inc_list α) (h : ∀ b : α, b ∈ l → a < b) : inc_list α := ⟨list.cons a (l : list α),list.pairwise.cons h l.property⟩ def map {β : Type} [linear_order β] (f : α → β) (hf : ∀ a₀ a₁, a₀ < a₁ → f a₀ < f a₁) (l : inc_list α) : (inc_list β) := ⟨ (l : list α).map f, (list.pairwise_map f).mpr (list.pairwise.imp hf l.property) ⟩ end inc_list def nondec_list (α : Type) [linear_order α] : Type := { l : list α // l.pairwise has_le.le } namespace nondec_list variables {α : Type} [linear_order α] instance : has_coe (nondec_list α) (list α) := ⟨λ l, l.val⟩ instance : has_mem α (nondec_list α) := ⟨λ a l, a ∈ (l : list α) ⟩ lemma coe_inj {l₀ l₁ : nondec_list α} : (l₀ : list α) = (l₁ : list α) → l₀ = l₁ := subtype.eq def to_multiset (l : nondec_list α) : multiset α := (l : list α) def of_multiset (s : multiset α) : nondec_list α := ⟨ s.sort has_le.le, s.sort_sorted has_le.le ⟩ lemma to_of_multiset (s : multiset α) : to_multiset (of_multiset s) = s := s.sort_eq has_le.le lemma of_to_multiset (l : nondec_list α) : of_multiset (to_multiset l) = l := coe_inj $ list.eq_of_perm_of_sorted (list.perm_merge_sort _ _) (of_multiset (to_multiset l)).property l.property def multiset_equiv : nondec_list α ≃ multiset α := { to_fun := to_multiset, inv_fun := of_multiset, left_inv := of_to_multiset, right_inv := to_of_multiset } def nil : nondec_list α := ⟨[],list.pairwise.nil⟩ def cons (a : α) (l : nondec_list α) (h : ∀ b : α, b ∈ l → a ≤ b) : nondec_list α := ⟨list.cons a (l : list α),list.pairwise.cons h l.property⟩ def map {β : Type} [linear_order β] (f : α → β) (hf : ∀ a₀ a₁, a₀ ≤ a₁ → f a₀ ≤ f a₁) (l : nondec_list α) : (nondec_list β) := ⟨ (l : list α).map f, (list.pairwise_map f).mpr (list.pairwise.imp hf l.property) ⟩ end nondec_list def acc : list ℕ → list ℕ | [] := [] | (a :: bs) := a :: ((acc bs).map (has_add.add a)) namespace acc def is_nondec : ∀ (l : list ℕ), (acc l).pairwise has_le.le | [] := list.pairwise.nil | (a :: l) := begin rw [acc], apply list.pairwise.cons, { intros x hx, rcases list.mem_map.mp hx with ⟨y,⟨hm,he⟩⟩, rw [← he], exact nat.le_add_right a y }, { let h₀ := λ (a₀ a₁ : ℕ) (h : a₀ ≤ a₁), add_le_add_left h a, let h₁ := list.pairwise.imp h₀ (is_nondec l), exact (list.pairwise_map (has_add.add a)).mpr h₁ } end def nondec (l : list ℕ) : nondec_list ℕ := ⟨acc l, acc.is_nondec l⟩ end acc def diff₀ : list ℕ → list ℕ | [] := [] | [a] := [] | (a :: b :: l) := (b - a) :: (diff₀ (b :: l)) lemma diff₀_add (a : ℕ) : ∀ (l : list ℕ), diff₀ (l.map (has_add.add a)) = diff₀ l | [] := rfl | [b] := by { rw[list.map_singleton], refl } | (b :: c :: l) := begin rw [list.map_cons, list.map_cons, diff₀, diff₀], congr' 1, { exact nat.add_sub_add_left a c b }, { have h := diff₀_add (c :: l), rw [list.map_cons] at h, exact h } end lemma diff₀_acc : ∀ (a : ℕ) (l : list ℕ), diff₀ (acc (a :: l)) = l | a [] := rfl | a (b :: l) := begin rw [acc, acc, list.map_cons, diff₀, add_comm a b, nat.add_sub_cancel b a], rw [add_comm b a], let h := diff₀_add a (b :: ((acc l).map (has_add.add b))), congr' 1, rw [list.map_cons] at h, rw [h], exact diff₀_acc b l, end def diff : list ℕ → list ℕ | [] := [] | (a :: l) := a :: (diff₀ (a :: l)) lemma diff_acc : ∀ (l : list ℕ), diff (acc l) = l | [] := rfl | [a] := rfl | (a :: b :: l) := begin rw [acc, diff], congr' 1, apply diff₀_acc end def pnat_sols (k n : ℕ) := { l : list ℕ+ // l.length = k ∧ (l.map (coe : ℕ+ → ℕ)).sum = n } namespace pnat_sols def nil : pnat_sols 0 0 := ⟨[],⟨rfl,rfl⟩⟩ def cons {k n m : ℕ} (i : ℕ+) (e : (i : ℕ) + n = m) (l : pnat_sols k n) : pnat_sols (k + 1) m := ⟨ i :: l.val, begin split, rw [list.length, l.property.left], rw [list.map, list.sum_cons, l.property.right, e] end ⟩ lemma cons_inj {k n m : ℕ} (i : ℕ+) (e : (i : ℕ) + n = m) : function.injective (cons i e : pnat_sols k n → pnat_sols (k + 1) m) := begin rintros ⟨l₀,⟨hl₀,hs₀⟩⟩ ⟨l₁,⟨hl₁,hs₁⟩⟩ el, apply subtype.eq, change l₀ = l₁, replace el := congr_arg subtype.val el, injection el end def cons' {k n : ℕ} (i : fin n) (l : pnat_sols k (n - 1 - i)) : pnat_sols (k + 1) n := cons (nat.succ_pnat i) ( by { cases n with m, { exact fin.elim0 i}, let i0 : ℕ := i, change (i0 + 1) + ((m + 1) - 1 - i0) = m + 1, have : m + 1 - 1 = m := nat.pred_succ m, rw [this, add_comm, ← add_assoc], have : i0 ≤ m := nat.le_of_lt_succ i.is_lt, rw [nat.sub_add_cancel this] }) l lemma cons'_inj {k n : ℕ} (i : fin n) : function.injective (cons' i : pnat_sols k (n - 1 - i) → pnat_sols (k + 1) n) := λ l₀ l₁ e, cons_inj _ _ e instance enum : ∀ (k n : ℕ), enumeration (pnat_sols k n) | 0 0 := { elems := [nil], nodup := list.nodup_singleton nil, complete := λ l, list.mem_singleton.mpr $ subtype.eq $ list.eq_nil_of_length_eq_zero $ l.property.left } | 0 (n + 1) := { elems := [], nodup := list.nodup_nil, complete := λ ⟨l,⟨hl,hs⟩⟩, begin exfalso, rw [list.eq_nil_of_length_eq_zero hl] at hs, exact (nat.succ_ne_zero n).symm hs, end } | (k + 1) n := { elems := (fin.enum n).elems.bind (λ i, (enum k (n - 1 - i)).elems.map (cons' i)), nodup := begin apply list.nodup_bind.mpr; split, { intros i hi, exact list.nodup.map (cons'_inj i) (enum k (n - 1 - i)).nodup }, { have hd : ∀ (i₀ i₁ : fin n), i₀ ≠ i₁ → list.disjoint ((enum k (n - 1 - i₀)).elems.map (cons' i₀)) ((enum k (n - 1 - i₁)).elems.map (cons' i₁)) := λ i₀ i₁ hn, begin intros l h₀ h₁, rcases list.mem_map.mp h₀ with ⟨l₀,⟨hm₀,he₀⟩⟩, rcases list.mem_map.mp h₁ with ⟨l₁,⟨hm₁,he₁⟩⟩, let he := congr_arg subtype.val (he₀.trans he₁.symm), injection he with hei hel, exact hn (fin.eq_of_veq (nat.succ_pnat_inj hei)), end, apply list.pairwise.imp hd enumeration.nodup } end, complete := λ l, begin rcases l with ⟨l,⟨hl,hs⟩⟩, cases l with i l, { rcases hl }, { rw [list.length] at hl, replace hl := nat.succ_inj'.mp hl, let i0 := (i : ℕ).pred, have hi0 : i = nat.succ_pnat i0 := pnat.eq (nat.succ_pred_eq_of_pos i.pos).symm, rw [list.map, list.sum_cons, hi0, nat.succ_pnat_coe, add_comm, nat.succ_eq_add_one] at hs, have i0_is_lt := nat.lt_of_lt_of_le (i0.lt_succ_self) (nat.le_add_left (i0 + 1) (l.map (coe : ℕ+ → ℕ)).sum), rw [hs] at i0_is_lt, let i1 : fin n := ⟨i0,i0_is_lt⟩, have hi1 : i1 ∈ enumeration.elems := enumeration.complete i1, apply list.mem_bind.mpr, use i1, use hi1, rw [list.mem_map], rw [add_comm, add_comm i0] at hs, let hs1 : n - (1 + i0) = (l.map coe).sum := tsub_eq_of_eq_add_rev hs.symm, rw [← nat.sub_sub] at hs1, use ⟨l,⟨hl,hs1.symm⟩⟩, split, { apply enumeration.complete }, { rw [cons', cons], apply subtype.eq, change list.cons i0.succ_pnat l = list.cons i l, rw [hi0] } } end } /- def to_finset {n k : ℕ} : pnat_sols (k + 1) (n + 1) → { s : finset (fin n) // s.card = k} := sorry -/ end pnat_sols end combinatorics
e2791828596f8e9467dbc879794edcc967805f99
4727251e0cd73359b15b664c3170e5d754078599
/src/topology/uniform_space/compare_reals.lean
6570bd5fc763ded178112a841cfbfa63c0fe69a8
[ "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,833
lean
/- Copyright (c) 2019 Patrick MAssot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import topology.uniform_space.absolute_value import topology.instances.real import topology.instances.rat import topology.uniform_space.completion /-! # Comparison of Cauchy reals and Bourbaki reals In `data.real.basic` real numbers are defined using the so called Cauchy construction (although it is due to Georg Cantor). More precisely, this construction applies to commutative rings equipped with an absolute value with values in a linear ordered field. On the other hand, in the `uniform_space` folder, we construct completions of general uniform spaces, which allows to construct the Bourbaki real numbers. In this file we build uniformly continuous bijections from Cauchy reals to Bourbaki reals and back. This is a cross sanity check of both constructions. Of course those two constructions are variations on the completion idea, simply with different level of generality. Comparing with Dedekind cuts or quasi-morphisms would be of a completely different nature. Note that `metric_space/cau_seq_filter` also relates the notions of Cauchy sequences in metric spaces and Cauchy filters in general uniform spaces, and `metric_space/completion` makes sure the completion (as a uniform space) of a metric space is a metric space. Historical note: mathlib used to define real numbers in an intermediate way, using completion of uniform spaces but extending multiplication in an ad-hoc way. TODO: * Upgrade this isomorphism to a topological ring isomorphism. * Do the same comparison for p-adic numbers ## Implementation notes The heavy work is done in `topology/uniform_space/abstract_completion` which provides an abstract caracterization of completions of uniform spaces, and isomorphisms between them. The only work left here is to prove the uniform space structure coming from the absolute value on ℚ (with values in ℚ, not referring to ℝ) coincides with the one coming from the metric space structure (which of course does use ℝ). ## References * [N. Bourbaki, *Topologie générale*][bourbaki1966] ## Tags real numbers, completion, uniform spaces -/ open set function filter cau_seq uniform_space /-- The metric space uniform structure on ℚ (which presupposes the existence of real numbers) agrees with the one coming directly from (abs : ℚ → ℚ). -/ lemma rat.uniform_space_eq : is_absolute_value.uniform_space (abs : ℚ → ℚ) = metric_space.to_uniform_space' := begin ext s, erw [metric.mem_uniformity_dist, is_absolute_value.mem_uniformity], split ; rintro ⟨ε, ε_pos, h⟩, { use [ε, by exact_mod_cast ε_pos], intros a b hab, apply h, rw [rat.dist_eq, abs_sub_comm] at hab, exact_mod_cast hab }, { obtain ⟨ε', h', h''⟩ : ∃ ε' : ℚ, 0 < ε' ∧ (ε' : ℝ) < ε, from exists_pos_rat_lt ε_pos, use [ε', h'], intros a b hab, apply h, rw [rat.dist_eq, abs_sub_comm], refine lt_trans _ h'', exact_mod_cast hab } end /-- Cauchy reals packaged as a completion of ℚ using the absolute value route. -/ noncomputable def rational_cau_seq_pkg : @abstract_completion ℚ $ is_absolute_value.uniform_space (abs : ℚ → ℚ) := { space := ℝ, coe := (coe : ℚ → ℝ), uniform_struct := by apply_instance, complete := by apply_instance, separation := by apply_instance, uniform_inducing := by { rw rat.uniform_space_eq, exact rat.uniform_embedding_coe_real.to_uniform_inducing }, dense := rat.dense_embedding_coe_real.dense } namespace compare_reals /-- Type wrapper around ℚ to make sure the absolute value uniform space instance is picked up instead of the metric space one. We proved in rat.uniform_space_eq that they are equal, but they are not definitionaly equal, so it would confuse the type class system (and probably also human readers). -/ @[derive comm_ring, derive inhabited] def Q := ℚ instance : uniform_space Q := is_absolute_value.uniform_space (abs : ℚ → ℚ) /-- Real numbers constructed as in Bourbaki. -/ @[derive inhabited] def Bourbakiℝ : Type := completion Q instance bourbaki.uniform_space: uniform_space Bourbakiℝ := completion.uniform_space Q /-- Bourbaki reals packaged as a completion of Q using the general theory. -/ def Bourbaki_pkg : abstract_completion Q := completion.cpkg /-- The equivalence between Bourbaki and Cauchy reals-/ noncomputable def compare_equiv : Bourbakiℝ ≃ ℝ := Bourbaki_pkg.compare_equiv rational_cau_seq_pkg lemma compare_uc : uniform_continuous (compare_equiv) := Bourbaki_pkg.uniform_continuous_compare_equiv _ lemma compare_uc_symm : uniform_continuous (compare_equiv).symm := Bourbaki_pkg.uniform_continuous_compare_equiv_symm _ end compare_reals
951c738f8428257d558307e65403b472d39877a5
e1440579fb0723caf9edf1ed07aee74bbf4f5ce7
/lean-experiments/stumps-learnable/src/stump/stump_pac_lemmas.lean
5febc1d1cca66b79b1c1e7f04e79938de28b6f4d
[ "Apache-2.0" ]
permissive
palmskog/coq-proba
1ecc5b7f399894ea14d6094a31a063280a122099
f73e2780871e2a3dd83b7ce9d3aed19f499f07e5
refs/heads/master
1,599,620,504,720
1,572,960,008,000
1,572,960,008,000
221,326,479
0
0
Apache-2.0
1,573,598,769,000
1,573,598,768,000
null
UTF-8
Lean
false
false
4,826
lean
/- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. -/ import .setup_properties import .algorithm_properties local attribute [instance] classical.prop_decidable open set open measure_theory open well_founded namespace stump variables (μ: probability_measure ℍ) (target: ℍ) (n: ℕ) lemma partition: ∀ θ, θ > 0 → {x : ℍ | ∀ (a: ℍ) (b: bool), (a,b) = label target x → ite b a 0 < θ} = - Icc θ target := begin introv h1, apply ext, intros, unfold Icc, unfold label, unfold rle, simp, split; intros, { simp at *, intros, by_contradiction, simp at a_2, have FOO:= a x tt _ _, { simp at FOO, have BAR: ¬ (θ ≤ x), simp, assumption, contradiction, }, trivial, tidy, }, { by_cases (b = tt), { rw h at *, simp, rw a_2, by_contradiction, simp at a_4, have INEQ1 := a a_4, have INEQ2: ¬ (x > target), {simp,tidy,}, contradiction, }, { simp at h, rw h at *, simp at *, tidy, }, }, end lemma miss_prob: ∀ ε, ∀ θ: nnreal, θ > 0 → μ (Icc θ target) ≥ ε → μ {x : ℍ | ∀ (a: ℍ) (b: bool), (a,b) = label target x → ite b a 0 < θ} ≤ 1 - ε:= begin intros, rw partition, have STO := probability_measure.prob_comp μ (Icc θ target) _, have SWAP: μ (- Icc θ target) = 1 - μ (Icc θ target), { exact lc_nnreal (μ (-Icc θ target)) (μ (Icc θ target)) STO, }, rw SWAP, { apply nnreal_sub_trans, assumption, }, { apply is_measurable_of_is_closed, apply is_closed_Icc, }, assumption, end lemma all_missed: ∀ ε: nnreal, ∀ θ: nnreal, μ (Ioc θ target) ≤ ε → {S: vec ℍ n | error μ target (choose n (label_sample target n S)) > ε} ⊆ {S: vec ℍ n | ∀ (i: dfin (nat.succ n)), ∀ p = label target (kth_projn S i), (if p.snd then p.fst else 0) < θ} := begin intros, conv { congr, congr, funext, rw (error_interval_1 μ target (choose n (label_sample target n S)) (choose_property_1 target n S)), skip, skip, }, rw set_of_subset_set_of, intros, have QENI: not (μ (Ioc (choose n (label_sample target n a_1)) target) ≤ μ (Ioc θ target)), { simp, have BREAK_LEQ: μ (Ioc θ target) < ε ∨ μ (Ioc θ target) = ε, { exact lt_or_eq_of_le a, }, cases BREAK_LEQ, transitivity ε; try {assumption,}, rw BREAK_LEQ, assumption, }, by_cases (p.snd = tt), { have PROP := choose_property_2 target n a_1 i p _ h, { rw h, simp, have INEQ1 := error_mono_interval μ target _ _ PROP _, by_contradiction, simp at a_3, have INEQ2 := error_mono_interval μ target _ _ a_3 _, have INEQ: μ (Ioc (choose n (label_sample target n a_1)) target) ≤ μ (Ioc θ target), { transitivity (μ (Ioc p.fst target)); try {assumption}, }, clear INEQ1 INEQ2, contradiction, apply choose_property_3; try {assumption}, { dunfold label_sample, rw ← kth_projn_map_comm, assumption, }, apply choose_property_1, }, { dunfold label_sample, rw ← kth_projn_map_comm, assumption, }, }, { simp at h, rw h, simp, have INEQ1': 0 ≤ choose n (label_sample target n a_1), { apply choose_property_4, }, have INEQ1 := error_mono_interval μ target _ _ INEQ1' _, clear INEQ1', by_contradiction, simp at a_3, have GEN: θ ≤ 0, { exact le_of_eq a_3, }, have INEQ2 := error_mono_interval μ target _ _ GEN _, clear GEN, have INEQ: μ (Ioc (choose n (label_sample target n a_1)) target) ≤ μ (Ioc θ target), { transitivity (μ (Ioc 0 target)); try {assumption}, }, clear INEQ1 INEQ2, contradiction, tidy, apply choose_property_1, }, end lemma always_succeed: ∀ ε: nnreal, ε > 0 → ∀ n: ℕ, μ (Ioc 0 target) ≤ ε → ∀ S: vec ℍ n, error μ target (choose n (label_sample target n S)) ≤ ε := begin intros, transitivity (μ (Ioc 0 target)); try {assumption}, have HypIN := choose_property_1 target n S, have ERMONO := error_mono μ _ 0 (choose n (label_sample target n S)) _ HypIN, rw ← error_max, assumption, tidy, end end stump
0d950f589ea93925cfe7bbb2be0b12a588388118
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/1703.lean
68c56b7d4cd30fef0ede00e0b6c5d6f26b54103e
[ "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
159
lean
namespace ns structure struct := (index : ℕ) end ns open ns def foo : struct := { ns.struct . index := 1 } def foo2 : struct := { struct . index := 1 }
d6c99cf2713fd875c0ae95e7e011610c6c7374f6
d436468d80b739ba7e06843c4d0d2070e43448e5
/src/data/fintype.lean
edf9043c7f07bb295a95d61adb935476a525c8a2
[ "Apache-2.0" ]
permissive
roro47/mathlib
761fdc002aef92f77818f3fef06bf6ec6fc1a28e
80aa7d52537571a2ca62a3fdf71c9533a09422cf
refs/heads/master
1,599,656,410,625
1,573,649,488,000
1,573,649,488,000
221,452,951
0
0
Apache-2.0
1,573,647,693,000
1,573,647,692,000
null
UTF-8
Lean
false
false
35,075
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Finite types. -/ import data.finset algebra.big_operators data.array.lemmas logic.unique import tactic.wlog universes u v variables {α : Type*} {β : Type*} {γ : Type*} /-- `fintype α` means that `α` is finite, i.e. there are only finitely many distinct elements of type `α`. The evidence of this is a finset `elems` (a list up to permutation without duplicates), together with a proof that everything of type `α` is in the list. -/ class fintype (α : Type*) := (elems : finset α) (complete : ∀ x : α, x ∈ elems) namespace finset variable [fintype α] /-- `univ` is the universal finite set of type `finset α` implied from the assumption `fintype α`. -/ def univ : finset α := fintype.elems α @[simp] theorem mem_univ (x : α) : x ∈ (univ : finset α) := fintype.complete x @[simp] theorem mem_univ_val : ∀ x, x ∈ (univ : finset α).1 := mem_univ @[simp] lemma coe_univ : ↑(univ : finset α) = (set.univ : set α) := by ext; simp theorem subset_univ (s : finset α) : s ⊆ univ := λ a _, mem_univ a theorem eq_univ_iff_forall {s : finset α} : s = univ ↔ ∀ x, x ∈ s := by simp [ext] end finset open finset function namespace fintype instance decidable_pi_fintype {α} {β : α → Type*} [fintype α] [∀a, decidable_eq (β a)] : decidable_eq (Πa, β a) := assume f g, decidable_of_iff (∀ a ∈ fintype.elems α, f a = g a) (by simp [function.funext_iff, fintype.complete]) instance decidable_forall_fintype [fintype α] {p : α → Prop} [decidable_pred p] : decidable (∀ a, p a) := decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp) instance decidable_exists_fintype [fintype α] {p : α → Prop} [decidable_pred p] : decidable (∃ a, p a) := decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp) instance decidable_eq_equiv_fintype [fintype α] [decidable_eq β] : decidable_eq (α ≃ β) := λ a b, decidable_of_iff (a.1 = b.1) ⟨λ h, equiv.ext _ _ (congr_fun h), congr_arg _⟩ instance decidable_injective_fintype [fintype α] [decidable_eq α] [decidable_eq β] : decidable_pred (injective : (α → β) → Prop) := λ x, by unfold injective; apply_instance instance decidable_surjective_fintype [fintype α] [fintype β] [decidable_eq β] : decidable_pred (surjective : (α → β) → Prop) := λ x, by unfold surjective; apply_instance instance decidable_bijective_fintype [fintype α] [decidable_eq α] [fintype β] [decidable_eq β] : decidable_pred (bijective : (α → β) → Prop) := λ x, by unfold bijective; apply_instance instance decidable_left_inverse_fintype [fintype α] [decidable_eq α] (f : α → β) (g : β → α) : decidable (function.right_inverse f g) := show decidable (∀ x, g (f x) = x), by apply_instance instance decidable_right_inverse_fintype [fintype β] [decidable_eq β] (f : α → β) (g : β → α) : decidable (function.left_inverse f g) := show decidable (∀ x, f (g x) = x), by apply_instance /-- Construct a proof of `fintype α` from a universal multiset -/ def of_multiset [decidable_eq α] (s : multiset α) (H : ∀ x : α, x ∈ s) : fintype α := ⟨s.to_finset, by simpa using H⟩ /-- Construct a proof of `fintype α` from a universal list -/ def of_list [decidable_eq α] (l : list α) (H : ∀ x : α, x ∈ l) : fintype α := ⟨l.to_finset, by simpa using H⟩ theorem exists_univ_list (α) [fintype α] : ∃ l : list α, l.nodup ∧ ∀ x : α, x ∈ l := let ⟨l, e⟩ := quotient.exists_rep (@univ α _).1 in by have := and.intro univ.2 mem_univ_val; exact ⟨_, by rwa ← e at this⟩ /-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/ def card (α) [fintype α] : ℕ := (@univ α _).card /-- There is (computably) a bijection between `α` and `fin n` where `n = card α`. Since it is not unique, and depends on which permutation of the universe list is used, the bijection is wrapped in `trunc` to preserve computability. -/ def equiv_fin (α) [fintype α] [decidable_eq α] : trunc (α ≃ fin (card α)) := by unfold card finset.card; exact quot.rec_on_subsingleton (@univ α _).1 (λ l (h : ∀ x:α, x ∈ l) (nd : l.nodup), trunc.mk ⟨λ a, ⟨_, list.index_of_lt_length.2 (h a)⟩, λ i, l.nth_le i.1 i.2, λ a, by simp, λ ⟨i, h⟩, fin.eq_of_veq $ list.nodup_iff_nth_le_inj.1 nd _ _ (list.index_of_lt_length.2 (list.nth_le_mem _ _ _)) h $ by simp⟩) mem_univ_val univ.2 theorem exists_equiv_fin (α) [fintype α] : ∃ n, nonempty (α ≃ fin n) := by haveI := classical.dec_eq α; exact ⟨card α, nonempty_of_trunc (equiv_fin α)⟩ instance (α : Type*) : subsingleton (fintype α) := ⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext, h₁, h₂]⟩ protected def subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : fintype {x // p x} := ⟨⟨multiset.pmap subtype.mk s.1 (λ x, (H x).1), multiset.nodup_pmap (λ a _ b _, congr_arg subtype.val) s.2⟩, λ ⟨x, px⟩, multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩ theorem subtype_card {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) : @card {x // p x} (fintype.subtype s H) = s.card := multiset.card_pmap _ _ _ theorem card_of_subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) [fintype {x // p x}] : card {x // p x} = s.card := by rw ← subtype_card s H; congr /-- Construct a fintype from a finset with the same elements. -/ def of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : fintype p := fintype.subtype s H @[simp] theorem card_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @fintype.card p (of_finset s H) = s.card := fintype.subtype_card s H theorem card_of_finset' {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [fintype p] : fintype.card p = s.card := by rw ← card_of_finset s H; congr /-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/ def of_bijective [fintype α] (f : α → β) (H : function.bijective f) : fintype β := ⟨univ.map ⟨f, H.1⟩, λ b, let ⟨a, e⟩ := H.2 b in e ▸ mem_map_of_mem _ (mem_univ _)⟩ /-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/ def of_surjective [fintype α] [decidable_eq β] (f : α → β) (H : function.surjective f) : fintype β := ⟨univ.image f, λ b, let ⟨a, e⟩ := H b in e ▸ mem_image_of_mem _ (mem_univ _)⟩ noncomputable def of_injective [fintype β] (f : α → β) (H : function.injective f) : fintype α := by letI := classical.dec; exact if hα : nonempty α then by letI := classical.inhabited_of_nonempty hα; exact of_surjective (inv_fun f) (inv_fun_surjective H) else ⟨∅, λ x, (hα ⟨x⟩).elim⟩ /-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/ def of_equiv (α : Type*) [fintype α] (f : α ≃ β) : fintype β := of_bijective _ f.bijective theorem of_equiv_card [fintype α] (f : α ≃ β) : @card β (of_equiv α f) = card α := multiset.card_map _ _ theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α = card β := by rw ← of_equiv_card f; congr theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) := ⟨λ h, ⟨by classical; calc α ≃ fin (card α) : trunc.out (equiv_fin α) ... ≃ fin (card β) : by rw h ... ≃ β : (trunc.out (equiv_fin β)).symm⟩, λ ⟨f⟩, card_congr f⟩ def of_subsingleton (a : α) [subsingleton α] : fintype α := ⟨finset.singleton a, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩ @[simp] theorem univ_of_subsingleton (a : α) [subsingleton α] : @univ _ (of_subsingleton a) = finset.singleton a := rfl @[simp] theorem card_of_subsingleton (a : α) [subsingleton α] : @fintype.card _ (of_subsingleton a) = 1 := rfl lemma card_eq_sum_ones {α} [fintype α] : fintype.card α = (finset.univ : finset α).sum (λ _, 1) := finset.card_eq_sum_ones _ end fintype namespace set /-- Construct a finset enumerating a set `s`, given a `fintype` instance. -/ def to_finset (s : set α) [fintype s] : finset α := ⟨(@finset.univ s _).1.map subtype.val, multiset.nodup_map (λ a b, subtype.eq) finset.univ.2⟩ @[simp] theorem mem_to_finset {s : set α} [fintype s] {a : α} : a ∈ s.to_finset ↔ a ∈ s := by simp [to_finset] @[simp] theorem mem_to_finset_val {s : set α} [fintype s] {a : α} : a ∈ s.to_finset.1 ↔ a ∈ s := mem_to_finset end set lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α := rfl lemma finset.card_univ_diff [fintype α] [decidable_eq α] (s : finset α) : (finset.univ \ s).card = fintype.card α - s.card := finset.card_sdiff (subset_univ s) instance (n : ℕ) : fintype (fin n) := ⟨⟨list.pmap fin.mk (list.range n) (λ a, list.mem_range.1), list.nodup_pmap (λ a _ b _, congr_arg fin.val) (list.nodup_range _)⟩, λ ⟨m, h⟩, list.mem_pmap.2 ⟨m, list.mem_range.2 h, rfl⟩⟩ @[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n := by rw [fin.fintype]; simp [fintype.card, card, univ] @[instance, priority 10] def unique.fintype {α : Type*} [unique α] : fintype α := ⟨finset.singleton (default α), λ x, by rw [unique.eq_default x]; simp⟩ @[simp] lemma univ_unique {α : Type*} [unique α] [f : fintype α] : @finset.univ α _ = {default α} := by rw [subsingleton.elim f (@unique.fintype α _)]; refl instance : fintype empty := ⟨∅, empty.rec _⟩ @[simp] theorem fintype.univ_empty : @univ empty _ = ∅ := rfl @[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl instance : fintype pempty := ⟨∅, pempty.rec _⟩ @[simp] theorem fintype.univ_pempty : @univ pempty _ = ∅ := rfl @[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl instance : fintype unit := fintype.of_subsingleton () @[simp] theorem fintype.univ_unit : @univ unit _ = {()} := rfl @[simp] theorem fintype.card_unit : fintype.card unit = 1 := rfl instance : fintype punit := fintype.of_subsingleton punit.star @[simp] theorem fintype.univ_punit : @univ punit _ = {punit.star} := rfl @[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl instance : fintype bool := ⟨⟨tt::ff::0, by simp⟩, λ x, by cases x; simp⟩ @[simp] theorem fintype.univ_bool : @univ bool _ = {ff, tt} := rfl instance units_int.fintype : fintype (units ℤ) := ⟨{1, -1}, λ x, by cases int.units_eq_one_or x; simp *⟩ instance additive.fintype : Π [fintype α], fintype (additive α) := id instance multiplicative.fintype : Π [fintype α], fintype (multiplicative α) := id @[simp] theorem fintype.card_units_int : fintype.card (units ℤ) = 2 := rfl @[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl def finset.insert_none (s : finset α) : finset (option α) := ⟨none :: s.1.map some, multiset.nodup_cons.2 ⟨by simp, multiset.nodup_map (λ a b, option.some.inj) s.2⟩⟩ @[simp] theorem finset.mem_insert_none {s : finset α} : ∀ {o : option α}, o ∈ s.insert_none ↔ ∀ a ∈ o, a ∈ s | none := iff_of_true (multiset.mem_cons_self _ _) (λ a h, by cases h) | (some a) := multiset.mem_cons.trans $ by simp; refl theorem finset.some_mem_insert_none {s : finset α} {a : α} : some a ∈ s.insert_none ↔ a ∈ s := by simp instance {α : Type*} [fintype α] : fintype (option α) := ⟨univ.insert_none, λ a, by simp⟩ @[simp] theorem fintype.card_option {α : Type*} [fintype α] : fintype.card (option α) = fintype.card α + 1 := (multiset.card_cons _ _).trans (by rw multiset.card_map; refl) instance {α : Type*} (β : α → Type*) [fintype α] [∀ a, fintype (β a)] : fintype (sigma β) := ⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩ @[simp] theorem fintype.card_sigma {α : Type*} (β : α → Type*) [fintype α] [∀ a, fintype (β a)] : fintype.card (sigma β) = univ.sum (λ a, fintype.card (β a)) := card_sigma _ _ instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) := ⟨univ.product univ, λ ⟨a, b⟩, by simp⟩ @[simp] theorem fintype.card_prod (α β : Type*) [fintype α] [fintype β] : fintype.card (α × β) = fintype.card α * fintype.card β := card_product _ _ def fintype.fintype_prod_left {α β} [decidable_eq α] [fintype (α × β)] [nonempty β] : fintype α := ⟨(fintype.elems (α × β)).image prod.fst, assume a, let ⟨b⟩ := ‹nonempty β› in by simp; exact ⟨b, fintype.complete _⟩⟩ def fintype.fintype_prod_right {α β} [decidable_eq β] [fintype (α × β)] [nonempty α] : fintype β := ⟨(fintype.elems (α × β)).image prod.snd, assume b, let ⟨a⟩ := ‹nonempty α› in by simp; exact ⟨a, fintype.complete _⟩⟩ instance (α : Type*) [fintype α] : fintype (ulift α) := fintype.of_equiv _ equiv.ulift.symm @[simp] theorem fintype.card_ulift (α : Type*) [fintype α] : fintype.card (ulift α) = fintype.card α := fintype.of_equiv_card _ instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕ β) := @fintype.of_equiv _ _ (@sigma.fintype _ (λ b, cond b (ulift α) (ulift.{(max u v) v} β)) _ (λ b, by cases b; apply ulift.fintype)) ((equiv.sum_equiv_sigma_bool _ _).symm.trans (equiv.sum_congr equiv.ulift equiv.ulift)) @[simp] theorem fintype.card_sum (α β : Type*) [fintype α] [fintype β] : fintype.card (α ⊕ β) = fintype.card α + fintype.card β := by rw [sum.fintype, fintype.of_equiv_card]; simp lemma fintype.card_le_of_injective [fintype α] [fintype β] (f : α → β) (hf : function.injective f) : fintype.card α ≤ fintype.card β := by haveI := classical.prop_decidable; exact finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h) lemma fintype.card_eq_one_iff [fintype α] : fintype.card α = 1 ↔ (∃ x : α, ∀ y, y = x) := by rw [← fintype.card_unit, fintype.card_eq]; exact ⟨λ ⟨a⟩, ⟨a.symm (), λ y, a.injective (subsingleton.elim _ _)⟩, λ ⟨x, hx⟩, ⟨⟨λ _, (), λ _, x, λ _, (hx _).trans (hx _).symm, λ _, subsingleton.elim _ _⟩⟩⟩ lemma fintype.card_eq_zero_iff [fintype α] : fintype.card α = 0 ↔ (α → false) := ⟨λ h a, have e : α ≃ empty := classical.choice (fintype.card_eq.1 (by simp [h])), (e a).elim, λ h, have e : α ≃ empty := ⟨λ a, (h a).elim, λ a, a.elim, λ a, (h a).elim, λ a, a.elim⟩, by simp [fintype.card_congr e]⟩ lemma fintype.card_pos_iff [fintype α] : 0 < fintype.card α ↔ nonempty α := ⟨λ h, classical.by_contradiction (λ h₁, have fintype.card α = 0 := fintype.card_eq_zero_iff.2 (λ a, h₁ ⟨a⟩), lt_irrefl 0 $ by rwa this at h), λ ⟨a⟩, nat.pos_of_ne_zero (mt fintype.card_eq_zero_iff.1 (λ h, h a))⟩ lemma fintype.card_le_one_iff [fintype α] : fintype.card α ≤ 1 ↔ (∀ a b : α, a = b) := let n := fintype.card α in have hn : n = fintype.card α := rfl, match n, hn with | 0 := λ ha, ⟨λ h, λ a, (fintype.card_eq_zero_iff.1 ha.symm a).elim, λ _, ha ▸ nat.le_succ _⟩ | 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := fintype.card_eq_one_iff.1 ha.symm in by rw [hx a, hx b], λ _, ha ▸ le_refl _⟩ | (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial, (λ h, fintype.card_unit ▸ fintype.card_le_of_injective (λ _, ()) (λ _ _ _, h _ _))⟩ end lemma fintype.exists_ne_of_one_lt_card [fintype α] (h : 1 < fintype.card α) (a : α) : ∃ b : α, b ≠ a := let ⟨b, hb⟩ := classical.not_forall.1 (mt fintype.card_le_one_iff.2 (not_le_of_gt h)) in let ⟨c, hc⟩ := classical.not_forall.1 hb in by haveI := classical.dec_eq α; exact if hba : b = a then ⟨c, by cc⟩ else ⟨b, hba⟩ lemma fintype.injective_iff_surjective [fintype α] {f : α → α} : injective f ↔ surjective f := by haveI := classical.prop_decidable; exact have ∀ {f : α → α}, injective f → surjective f, from λ f hinj x, have h₁ : image f univ = univ := eq_of_subset_of_card_le (subset_univ _) ((card_image_of_injective univ hinj).symm ▸ le_refl _), have h₂ : x ∈ image f univ := h₁.symm ▸ mem_univ _, exists_of_bex (mem_image.1 h₂), ⟨this, λ hsurj, injective_of_has_left_inverse ⟨surj_inv hsurj, left_inverse_of_surjective_of_right_inverse (this (injective_surj_inv _)) (right_inverse_surj_inv _)⟩⟩ lemma fintype.injective_iff_bijective [fintype α] {f : α → α} : injective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.surjective_iff_bijective [fintype α] {f : α → α} : surjective f ↔ bijective f := by simp [bijective, fintype.injective_iff_surjective] lemma fintype.injective_iff_surjective_of_equiv [fintype α] {f : α → β} (e : α ≃ β) : injective f ↔ surjective f := have injective (e.symm ∘ f) ↔ surjective (e.symm ∘ f), from fintype.injective_iff_surjective, ⟨λ hinj, by simpa [function.comp] using surjective_comp e.surjective (this.1 (injective_comp e.symm.injective hinj)), λ hsurj, by simpa [function.comp] using injective_comp e.injective (this.2 (surjective_comp e.symm.surjective hsurj))⟩ instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} := fintype.of_list l.attach l.mem_attach instance multiset.subtype.fintype [decidable_eq α] (s : multiset α) : fintype {x // x ∈ s} := fintype.of_multiset s.attach s.mem_attach instance finset.subtype.fintype (s : finset α) : fintype {x // x ∈ s} := ⟨s.attach, s.mem_attach⟩ instance finset_coe.fintype (s : finset α) : fintype (↑s : set α) := finset.subtype.fintype s @[simp] lemma fintype.card_coe (s : finset α) : fintype.card (↑s : set α) = s.card := card_attach instance plift.fintype (p : Prop) [decidable p] : fintype (plift p) := ⟨if h : p then finset.singleton ⟨h⟩ else ∅, λ ⟨h⟩, by simp [h]⟩ instance Prop.fintype : fintype Prop := ⟨⟨true::false::0, by simp [true_ne_false]⟩, classical.cases (by simp) (by simp)⟩ def set_fintype {α} [fintype α] (s : set α) [decidable_pred s] : fintype s := fintype.subtype (univ.filter (∈ s)) (by simp) instance pi.fintype {α : Type*} {β : α → Type*} [fintype α] [decidable_eq α] [∀a, fintype (β a)] : fintype (Πa, β a) := @fintype.of_equiv _ _ ⟨univ.pi $ λa:α, @univ (β a) _, λ f, finset.mem_pi.2 $ λ a ha, mem_univ _⟩ ⟨λ f a, f a (mem_univ _), λ f a _, f a, λ f, rfl, λ f, rfl⟩ @[simp] lemma fintype.card_pi {β : α → Type*} [fintype α] [decidable_eq α] [f : Π a, fintype (β a)] : fintype.card (Π a, β a) = univ.prod (λ a, fintype.card (β a)) := by letI f' : fintype (Πa∈univ, β a) := ⟨(univ.pi $ λa, univ), assume f, finset.mem_pi.2 $ assume a ha, mem_univ _⟩; exact calc fintype.card (Π a, β a) = fintype.card (Π a ∈ univ, β a) : fintype.card_congr ⟨λ f a ha, f a, λ f a, f a (mem_univ a), λ _, rfl, λ _, rfl⟩ ... = univ.prod (λ a, fintype.card (β a)) : finset.card_pi _ _ @[simp] lemma fintype.card_fun [fintype α] [decidable_eq α] [fintype β] : fintype.card (α → β) = fintype.card β ^ fintype.card α := by rw [fintype.card_pi, finset.prod_const, nat.pow_eq_pow]; refl instance d_array.fintype {n : ℕ} {α : fin n → Type*} [∀n, fintype (α n)] : fintype (d_array n α) := fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) := d_array.fintype instance vector.fintype {α : Type*} [fintype α] {n : ℕ} : fintype (vector α n) := fintype.of_equiv _ (equiv.vector_equiv_fin _ _).symm @[simp] lemma card_vector [fintype α] (n : ℕ) : fintype.card (vector α n) = fintype.card α ^ n := by rw fintype.of_equiv_card; simp instance quotient.fintype [fintype α] (s : setoid α) [decidable_rel ((≈) : α → α → Prop)] : fintype (quotient s) := fintype.of_surjective quotient.mk (λ x, quotient.induction_on x (λ x, ⟨x, rfl⟩)) instance finset.fintype [fintype α] : fintype (finset α) := ⟨univ.powerset, λ x, finset.mem_powerset.2 (finset.subset_univ _)⟩ instance subtype.fintype [fintype α] (p : α → Prop) [decidable_pred p] : fintype {x // p x} := set_fintype _ theorem fintype.card_subtype_le [fintype α] (p : α → Prop) [decidable_pred p] : fintype.card {x // p x} ≤ fintype.card α := by rw fintype.subtype_card; exact card_le_of_subset (subset_univ _) theorem fintype.card_subtype_lt [fintype α] {p : α → Prop} [decidable_pred p] {x : α} (hx : ¬ p x) : fintype.card {x // p x} < fintype.card α := by rw [fintype.subtype_card]; exact finset.card_lt_card ⟨subset_univ _, classical.not_forall.2 ⟨x, by simp [*, set.mem_def]⟩⟩ instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] : fintype (Σ' a, β a) := fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [∀ a, fintype (β a)] [decidable α] : fintype (Σ' a, β a) := if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩ else ⟨∅, λ x, h x.1⟩ instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [fintype α] [∀ a, decidable (β a)] : fintype (Σ' a, β a) := fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩ instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] : fintype (Σ' a, β a) := if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩ instance set.fintype [fintype α] [decidable_eq α] : fintype (set α) := pi.fintype instance pfun_fintype (p : Prop) [decidable p] (α : p → Type*) [Π hp, fintype (α hp)] : fintype (Π hp : p, α hp) := if hp : p then fintype.of_equiv (α hp) ⟨λ a _, a, λ f, f hp, λ _, rfl, λ _, rfl⟩ else ⟨singleton (λ h, (hp h).elim), by simp [hp, function.funext_iff]⟩ def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι), (∀ i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance) | [] f := ⟦λ i, false.elim⟧ | (i::l) f := begin refine quotient.lift_on₂ (f i (list.mem_cons_self _ _)) (quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h))) _ _, exact λ a l, ⟦λ j h, if e : j = i then by rw e; exact a else l _ (h.resolve_left e)⟧, refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _), by_cases e : j = i; simp [e], { subst j, exact h₁ }, { exact h₂ _ _ } end theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] : ∀ (l : list ι) (f : ∀ i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧ | [] f := quotient.sound (λ i h, h.elim) | (i::l) f := begin simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l], refine quotient.sound (λ j h, _), by_cases e : j = i; simp [e], subst j, refl end def quotient.fin_choice {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [S : ∀ i, setoid (α i)] (f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) := quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι, @quotient (Π i ∈ l, α i) (by apply_instance)) finset.univ.1 (λ l, quotient.fin_choice_aux l (λ i _, f i)) (λ a b h, begin have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)), simp [quotient.out_eq] at this, simp [this], let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧, refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)), congr' 1, exact quotient.sound h, end)) (λ f, ⟦λ i, f i (finset.mem_univ _)⟧) (λ a b h, quotient.sound $ λ i, h _ _) theorem quotient.fin_choice_eq {ι : Type*} [fintype ι] [decidable_eq ι] {α : ι → Type*} [∀ i, setoid (α i)] (f : ∀ i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ := begin let q, swap, change quotient.lift_on q _ _ = _, have : q = ⟦λ i h, f i⟧, { dsimp [q], exact quotient.induction_on (@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) }, simp [this], exact setoid.refl _ end @[simp, to_additive] lemma finset.prod_attach_univ [fintype α] [comm_monoid β] (f : {a : α // a ∈ @univ α _} → β) : univ.attach.prod (λ x, f x) = univ.prod (λ x, f ⟨x, (mem_univ _)⟩) := prod_bij (λ x _, x.1) (λ _ _, mem_univ _) (λ _ _ , by simp) (by simp) (λ b _, ⟨⟨b, mem_univ _⟩, by simp⟩) section equiv open list equiv equiv.perm variables [decidable_eq α] [decidable_eq β] def perms_of_list : list α → list (perm α) | [] := [1] | (a :: l) := perms_of_list l ++ l.bind (λ b, (perms_of_list l).map (λ f, swap a b * f)) lemma length_perms_of_list : ∀ l : list α, length (perms_of_list l) = l.length.fact | [] := rfl | (a :: l) := by rw [length_cons, nat.fact_succ]; simp [perms_of_list, length_bind, length_perms_of_list, function.comp, nat.succ_mul] lemma mem_perms_of_list_of_mem : ∀ {l : list α} {f : perm α} (h : ∀ x, f x ≠ x → x ∈ l), f ∈ perms_of_list l | [] f h := list.mem_singleton.2 $ equiv.ext _ _$ λ x, by simp [imp_false, *] at * | (a::l) f h := if hfa : f a = a then mem_append_left _ $ mem_perms_of_list_of_mem (λ x hx, mem_of_ne_of_mem (λ h, by rw h at hx; exact hx hfa) (h x hx)) else have hfa' : f (f a) ≠ f a, from mt (λ h, f.injective h) hfa, have ∀ (x : α), (swap a (f a) * f) x ≠ x → x ∈ l, from λ x hx, have hxa : x ≠ a, from λ h, by simpa [h, mul_apply] using hx, have hfxa : f x ≠ f a, from mt (λ h, f.injective h) hxa, list.mem_of_ne_of_mem hxa (h x (λ h, by simp [h, mul_apply, swap_apply_def] at hx; split_ifs at hx; cc)), suffices f ∈ perms_of_list l ∨ ∃ (b : α), b ∈ l ∧ ∃ g : perm α, g ∈ perms_of_list l ∧ swap a b * g = f, by simpa [perms_of_list], (@or_iff_not_imp_left _ _ (classical.prop_decidable _)).2 (λ hfl, ⟨f a, if hffa : f (f a) = a then mem_of_ne_of_mem hfa (h _ (mt (λ h, f.injective h) hfa)) else this _ $ by simp [mul_apply, swap_apply_def]; split_ifs; cc, ⟨swap a (f a) * f, mem_perms_of_list_of_mem this, by rw [← mul_assoc, mul_def (swap a (f a)) (swap a (f a)), swap_swap, ← equiv.perm.one_def, one_mul]⟩⟩) lemma mem_of_mem_perms_of_list : ∀ {l : list α} {f : perm α}, f ∈ perms_of_list l → ∀ {x}, f x ≠ x → x ∈ l | [] f h := have f = 1 := by simpa [perms_of_list] using h, by rw this; simp | (a::l) f h := (mem_append.1 h).elim (λ h x hx, mem_cons_of_mem _ (mem_of_mem_perms_of_list h hx)) (λ h x hx, let ⟨y, hy, hy'⟩ := list.mem_bind.1 h in let ⟨g, hg₁, hg₂⟩ := list.mem_map.1 hy' in if hxa : x = a then by simp [hxa] else if hxy : x = y then mem_cons_of_mem _ $ by rwa hxy else mem_cons_of_mem _ $ mem_of_mem_perms_of_list hg₁ $ by rw [eq_inv_mul_iff_mul_eq.2 hg₂, mul_apply, swap_inv, swap_apply_def]; split_ifs; cc) lemma mem_perms_of_list_iff {l : list α} {f : perm α} : f ∈ perms_of_list l ↔ ∀ {x}, f x ≠ x → x ∈ l := ⟨mem_of_mem_perms_of_list, mem_perms_of_list_of_mem⟩ lemma nodup_perms_of_list : ∀ {l : list α} (hl : l.nodup), (perms_of_list l).nodup | [] hl := by simp [perms_of_list] | (a::l) hl := have hl' : l.nodup, from nodup_of_nodup_cons hl, have hln' : (perms_of_list l).nodup, from nodup_perms_of_list hl', have hmeml : ∀ {f : perm α}, f ∈ perms_of_list l → f a = a, from λ f hf, not_not.1 (mt (mem_of_mem_perms_of_list hf) (nodup_cons.1 hl).1), by rw [perms_of_list, list.nodup_append, list.nodup_bind, pairwise_iff_nth_le]; exact ⟨hln', ⟨λ _ _, nodup_map (λ _ _, (mul_left_inj _).1) hln', λ i j hj hij x hx₁ hx₂, let ⟨f, hf⟩ := list.mem_map.1 hx₁ in let ⟨g, hg⟩ := list.mem_map.1 hx₂ in have hix : x a = nth_le l i (lt_trans hij hj), by rw [← hf.2, mul_apply, hmeml hf.1, swap_apply_left], have hiy : x a = nth_le l j hj, by rw [← hg.2, mul_apply, hmeml hg.1, swap_apply_left], absurd (hf.2.trans (hg.2.symm)) $ λ h, ne_of_lt hij $ nodup_iff_nth_le_inj.1 hl' i j (lt_trans hij hj) hj $ by rw [← hix, hiy]⟩, λ f hf₁ hf₂, let ⟨x, hx, hx'⟩ := list.mem_bind.1 hf₂ in let ⟨g, hg⟩ := list.mem_map.1 hx' in have hgxa : g⁻¹ x = a, from f.injective $ by rw [hmeml hf₁, ← hg.2]; simp, have hxa : x ≠ a, from λ h, (list.nodup_cons.1 hl).1 (h ▸ hx), (list.nodup_cons.1 hl).1 $ hgxa ▸ mem_of_mem_perms_of_list hg.1 (by rwa [apply_inv_self, hgxa])⟩ def perms_of_finset (s : finset α) : finset (perm α) := quotient.hrec_on s.1 (λ l hl, ⟨perms_of_list l, nodup_perms_of_list hl⟩) (λ a b hab, hfunext (congr_arg _ (quotient.sound hab)) (λ ha hb _, heq_of_eq $ finset.ext.2 $ by simp [mem_perms_of_list_iff,mem_of_perm hab])) s.2 lemma mem_perms_of_finset_iff : ∀ {s : finset α} {f : perm α}, f ∈ perms_of_finset s ↔ ∀ {x}, f x ≠ x → x ∈ s := by rintros ⟨⟨l⟩, hs⟩ f; exact mem_perms_of_list_iff lemma card_perms_of_finset : ∀ (s : finset α), (perms_of_finset s).card = s.card.fact := by rintros ⟨⟨l⟩, hs⟩; exact length_perms_of_list l def fintype_perm [fintype α] : fintype (perm α) := ⟨perms_of_finset (@finset.univ α _), by simp [mem_perms_of_finset_iff]⟩ instance [fintype α] [fintype β] : fintype (α ≃ β) := if h : fintype.card β = fintype.card α then trunc.rec_on_subsingleton (fintype.equiv_fin α) (λ eα, trunc.rec_on_subsingleton (fintype.equiv_fin β) (λ eβ, @fintype.of_equiv _ (perm α) fintype_perm (equiv_congr (equiv.refl α) (eα.trans (eq.rec_on h eβ.symm)) : (α ≃ α) ≃ (α ≃ β)))) else ⟨∅, λ x, false.elim (h (fintype.card_eq.2 ⟨x.symm⟩))⟩ lemma fintype.card_perm [fintype α] : fintype.card (perm α) = (fintype.card α).fact := subsingleton.elim (@fintype_perm α _ _) (@equiv.fintype α α _ _ _ _) ▸ card_perms_of_finset _ lemma fintype.card_equiv [fintype α] [fintype β] (e : α ≃ β) : fintype.card (α ≃ β) = (fintype.card α).fact := fintype.card_congr (equiv_congr (equiv.refl α) e) ▸ fintype.card_perm end equiv namespace fintype section choose open fintype open equiv variables [fintype α] [decidable_eq α] (p : α → Prop) [decidable_pred p] def choose_x (hp : ∃! a : α, p a) : {a // p a} := ⟨finset.choose p univ (by simp; exact hp), finset.choose_property _ _ _⟩ def choose (hp : ∃! a, p a) : α := choose_x p hp lemma choose_spec (hp : ∃! a, p a) : p (choose p hp) := (choose_x p hp).property end choose section bijection_inverse open function variables [fintype α] [decidable_eq α] variables [fintype β] [decidable_eq β] variables {f : α → β} /-- ` `bij_inv f` is the unique inverse to a bijection `f`. This acts as a computable alternative to `function.inv_fun`. -/ def bij_inv (f_bij : bijective f) (b : β) : α := fintype.choose (λ a, f a = b) begin rcases f_bij.right b with ⟨a', fa_eq_b⟩, rw ← fa_eq_b, exact ⟨a', ⟨rfl, (λ a h, f_bij.left h)⟩⟩ end lemma left_inverse_bij_inv (f_bij : bijective f) : left_inverse (bij_inv f_bij) f := λ a, f_bij.left (choose_spec (λ a', f a' = f a) _) lemma right_inverse_bij_inv (f_bij : bijective f) : right_inverse (bij_inv f_bij) f := λ b, choose_spec (λ a', f a' = b) _ lemma bijective_bij_inv (f_bij : bijective f) : bijective (bij_inv f_bij) := ⟨injective_of_left_inverse (right_inverse_bij_inv _), surjective_of_has_right_inverse ⟨f, left_inverse_bij_inv _⟩⟩ end bijection_inverse lemma well_founded_of_trans_of_irrefl [fintype α] (r : α → α → Prop) [is_trans α r] [is_irrefl α r] : well_founded r := by classical; exact have ∀ x y, r x y → (univ.filter (λ z, r z x)).card < (univ.filter (λ z, r z y)).card, from λ x y hxy, finset.card_lt_card $ by simp only [finset.lt_iff_ssubset.symm, lt_iff_le_not_le, finset.le_iff_subset, finset.subset_iff, mem_filter, true_and, mem_univ, hxy]; exact ⟨λ z hzx, trans hzx hxy, not_forall_of_exists_not ⟨x, not_imp.2 ⟨hxy, irrefl x⟩⟩⟩, subrelation.wf this (measure_wf _) lemma preorder.well_founded [fintype α] [preorder α] : well_founded ((<) : α → α → Prop) := well_founded_of_trans_of_irrefl _ @[instance, priority 10] lemma linear_order.is_well_order [fintype α] [linear_order α] : is_well_order α (<) := { wf := preorder.well_founded } end fintype class infinite (α : Type*) : Prop := (not_fintype : fintype α → false) @[simp] lemma not_nonempty_fintype {α : Type*} : ¬nonempty (fintype α) ↔ infinite α := ⟨λf, ⟨λ x, f ⟨x⟩⟩, λ⟨f⟩ ⟨x⟩, f x⟩ namespace infinite lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s := classical.not_forall.1 $ λ h, not_fintype ⟨s, h⟩ instance nonempty (α : Type*) [infinite α] : nonempty α := nonempty_of_exists (exists_not_mem_finset (∅ : finset α)) lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α := ⟨λ I, by exactI not_fintype (fintype.of_injective f hf)⟩ lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α := ⟨λ I, by classical; exactI not_fintype (fintype.of_surjective f hf)⟩ private noncomputable def nat_embedding_aux (α : Type*) [infinite α] : ℕ → α | n := by letI := classical.dec_eq α; exact classical.some (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux m) (λ _, multiset.mem_range.1)).to_finset) private lemma nat_embedding_aux_injective (α : Type*) [infinite α] : function.injective (nat_embedding_aux α) := begin assume m n h, letI := classical.dec_eq α, wlog hmlen : m ≤ n using m n, by_contradiction hmn, have hmn : m < n, from lt_of_le_of_ne hmlen hmn, refine (classical.some_spec (exists_not_mem_finset ((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux α m) (λ _, multiset.mem_range.1)).to_finset)) _, refine multiset.mem_to_finset.2 (multiset.mem_pmap.2 ⟨m, multiset.mem_range.2 hmn, _⟩), rw [h, nat_embedding_aux] end noncomputable def nat_embedding (α : Type*) [infinite α] : ℕ ↪ α := ⟨_, nat_embedding_aux_injective α⟩ end infinite instance nat.infinite : infinite ℕ := ⟨λ ⟨s, hs⟩, not_le_of_gt (nat.lt_succ_self (s.sum id)) $ @finset.single_le_sum _ _ _ id _ _ (λ _ _, nat.zero_le _) _ (hs _)⟩ instance int.infinite : infinite ℤ := infinite.of_injective int.of_nat (λ _ _, int.of_nat_inj)
a97276f85d43740cd655047260d963435aa6fd8a
6b2a480f27775cba4f3ae191b1c1387a29de586e
/group_rep_2/basic_definitions/equiv.lean
0baff08533bec770621f86990124c5d3b0878fab
[]
no_license
Or7ando/group_representation
a681de2e19d1930a1e1be573d6735a2f0b8356cb
9b576984f17764ebf26c8caa2a542d248f1b50d2
refs/heads/master
1,662,413,107,324
1,590,302,389,000
1,590,302,389,000
258,130,829
0
1
null
null
null
null
UTF-8
Lean
false
false
5,569
lean
import basic_definitions.morphism universe variables u v w w' open linear_map namespace equiv_morphism variables {G : Type u} [group G] {R : Type v} [ring R] {M : Type w} [add_comm_group M] [module R M] {M' : Type w'} [add_comm_group M'] [module R M'] /-- an equiv`f : ρ ≃ᵣ π` between representation is a linear equiv `f.ℓ : M(ρ) ≃ₗ[R] M(π)` satisfying `f.ℓ ∘ ρ g = π g ∘ f.ℓ` has function on `linear_map` ! -/ structure G_equiv (ρ : group_representation G R M) (π : group_representation G R M') : Type (max w w') := (ℓ : M ≃ₗ[R] M') (commute : ∀(g : G), ↑ℓ ⊚ ρ g = π g ⊚ ℓ) --- en terme d'élément ! infixr ` ≃ᵣ `:25 := G_equiv @[ext]lemma ext {ρ : group_representation G R M} {ρ' : group_representation G R M'} ( f g : ρ ≃ᵣ ρ') : (f.ℓ) = g.ℓ → f = g := begin intros, cases f,cases g , congr'; try {assumption} end def not_isomorphic (ρ : group_representation G R M) (ρ' : group_representation G R M') := -- more general (ρ ≃ᵣ ρ') → false /-- `is_isomorphic ρ ρ'` when nonempty(ρ ≃ᵣ ρ') -/ def is_isomorphic (ρ : group_representation G R M) (ρ' : group_representation G R M') := nonempty (ρ ≃ᵣ ρ') lemma non_is_isomorphic_eq_not_isomorphic (ρ : group_representation G R M) (ρ' : group_representation G R M') : ¬ (is_isomorphic ρ ρ') → (not_isomorphic ρ ρ') := begin intros, intro,unfold is_isomorphic at *, have : nonempty (ρ ≃ᵣ ρ'), use a_1, trivial, end /-! an equiv`f : ρ ≃ᵣ π` induce a morphism of representation. -/variables {ρ : group_representation G R M} {ρ' : group_representation G R M'} instance : has_coe (ρ ≃ᵣ ρ')(ρ ⟶ᵣ ρ') := ⟨λ f, { ℓ := f.ℓ , commute := f.commute, } ⟩ open_locale classical /-! Let `f : M ≃ₗ[R] M'` a `linear_equiv` and `ρ : G → GL R M` a representation, we can construct a representation `image` and a `representation equiv` -/ open linear_equiv lemma ker_and_range_trivial_to_bijective (f : M →ₗ[R]M') (hyp : ker f = ⊥ ∧ range f = ⊤) : function.bijective f := begin split,refine ker_eq_bot.mp hyp.1, refine range_eq_top.mp hyp.2, end noncomputable def gker (f : M →ₗ[R]M') (certif : ker f = ⊥ ∧ range f = ⊤) : M ≃ M' := { to_fun := f, inv_fun := function.surj_inv (ker_and_range_trivial_to_bijective f certif).2, left_inv := function.left_inverse_surj_inv (ker_and_range_trivial_to_bijective f certif), right_inv := function.right_inverse_surj_inv (ker_and_range_trivial_to_bijective f certif).right, } #where lemma gker_ext (f : M →ₗ[R]M') (hyp : ker f = ⊥ ∧ range f = ⊤) : (gker f hyp).to_fun = f := rfl noncomputable lemma ker_im_equiv'' (f : M →ₗ[R]M') (hyp : ker f = ⊥ ∧ range f = ⊤) : M ≃ₗ[R] M' := { to_fun := f , add := f.map_add , smul := f.map_smul, inv_fun := (gker f hyp).inv_fun , left_inv := begin let g := (gker f hyp).left_inv, erw ← (gker_ext f hyp), exact g end, right_inv := begin let g := (gker f hyp).right_inv, erw ← (gker_ext f hyp), exact g end, } lemma ker_im_equiv_ext'' (f : M →ₗ[R]M') (hyp : ker f = ⊥ ∧ range f = ⊤) : linear_equiv.to_linear_map(ker_im_equiv'' f hyp) = f := begin ext, dunfold ker_im_equiv'', exact rfl, end variables (f : M ≃ₗ[R] M') lemma linear_equiv_compo_id (f : M ≃ₗ[R] M') : (linear_equiv.to_linear_map f) ⊚ (linear_equiv.to_linear_map f.symm) = linear_map.id := begin ext, change (f.to_fun ∘ f.symm.to_fun) x = x, let t := f.6,exact t x, end noncomputable lemma ker_im_equiv' (f : ρ ⟶ᵣ ρ') (hyp : ker f.ℓ = ⊥ ∧ range f.ℓ = ⊤) : M ≃ₗ[R] M' := { to_fun := f.ℓ , add := f.ℓ.map_add , smul := f.ℓ.map_smul, inv_fun := (gker f.ℓ hyp).inv_fun , left_inv := begin let g := (gker f.ℓ hyp).left_inv, erw ← (gker_ext f.ℓ hyp), exact g end, right_inv := begin let g := (gker f.ℓ hyp).right_inv, erw ← (gker_ext f.ℓ hyp), exact g end, } noncomputable lemma ker_im_equiv (f : ρ ⟶ᵣ ρ') (hyp : ker f.ℓ = ⊥ ∧ range f.ℓ = ⊤) : ρ ≃ᵣ ρ' := { ℓ := (ker_im_equiv' f hyp), commute := begin intros, dunfold ker_im_equiv',erw f.commute, exact rfl end } local notation f ` leq ` g := linear_equiv.trans g f @[simp]lemma eq_mul (ρ : group_representation G R M) ( g g' : G) : ρ (g * g') = (ρ g ⊚ ρ g') := begin erw ρ.map_mul, exact rfl, end variables (f : M ≃ₗ[R] M') @[simp] lemma mul_inv (f : M ≃ₗ[R] M') : (f leq f.symm) = linear_equiv.refl R M' := begin ext, rw refl_apply,rw trans_apply, simp, end lemma mul_eq_mul (f g : M ≃ₗ[R] M ) : (f leq g) = f * g := begin ext, exact rfl, end def image (ρ : group_representation G R M) (f : M ≃ₗ[R] M') : group_representation G R M' := { to_fun := λ g, f leq (gr.to_equiv' ρ g) leq f.symm , map_one' := begin ext, dsimp, unfold gr.to_equiv', change (⇑f ∘ (ρ 1) ∘ ⇑(f.symm)) x = x, erw ρ.map_one, simp, end, map_mul' := begin intros g g',ext, dsimp, unfold gr.to_equiv', change (⇑f ∘ (ρ (g * g')) ∘ ⇑(f.symm)) x = _, simp,exact rfl, end } def image_equiv (ρ : group_representation G R M) (f : M ≃ₗ[R] M') : ρ ≃ᵣ (image ρ f) := { ℓ := f, commute := begin intros g, ext, unfold image, simp,exact rfl, end } end equiv_morphism #lint
e05593dcbe5e5fdd999de9fceafecff8c4104123
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/category_theory/isomorphism.lean
fbaca6813a4e69466252bfd81678f9473f523c21
[ "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
16,380
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import category_theory.functor.basic /-! # Isomorphisms > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > https://github.com/leanprover-community/mathlib4/pull/749 > Any changes to this file require a corresponding PR to mathlib4. This file defines isomorphisms between objects of a category. ## Main definitions - `structure iso` : a bundled isomorphism between two objects of a category; - `class is_iso` : an unbundled version of `iso`; note that `is_iso f` is a `Prop`, and only asserts the existence of an inverse. Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it. - `inv f`, for the inverse of a morphism with `[is_iso f]` - `as_iso` : convert from `is_iso` to `iso` (noncomputable); - `of_iso` : convert from `iso` to `is_iso`; - standard operations on isomorphisms (composition, inverse etc) ## Notations - `X ≅ Y` : same as `iso X Y`; - `α ≪≫ β` : composition of two isomorphisms; it is called `iso.trans` ## Tags category, category theory, isomorphism -/ universes v u -- morphism levels before object levels. See note [category_theory universes]. namespace category_theory open category /-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category. The inverse morphism is bundled. See also `category_theory.core` for the category with the same objects and isomorphisms playing the role of morphisms. See <https://stacks.math.columbia.edu/tag/0017>. -/ structure iso {C : Type u} [category.{v} C] (X Y : C) := (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id' : hom ≫ inv = 𝟙 X . obviously) (inv_hom_id' : inv ≫ hom = 𝟙 Y . obviously) restate_axiom iso.hom_inv_id' restate_axiom iso.inv_hom_id' attribute [simp, reassoc] iso.hom_inv_id iso.inv_hom_id infixr ` ≅ `:10 := iso -- type as \cong or \iso variables {C : Type u} [category.{v} C] variables {X Y Z : C} namespace iso @[ext] lemma ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β := suffices α.inv = β.inv, by cases α; cases β; cc, calc α.inv = α.inv ≫ (β.hom ≫ β.inv) : by rw [iso.hom_inv_id, category.comp_id] ... = (α.inv ≫ α.hom) ≫ β.inv : by rw [category.assoc, ←w] ... = β.inv : by rw [iso.inv_hom_id, category.id_comp] /-- Inverse isomorphism. -/ @[symm] def symm (I : X ≅ Y) : Y ≅ X := { hom := I.inv, inv := I.hom, hom_inv_id' := I.inv_hom_id', inv_hom_id' := I.hom_inv_id' } @[simp] lemma symm_hom (α : X ≅ Y) : α.symm.hom = α.inv := rfl @[simp] lemma symm_inv (α : X ≅ Y) : α.symm.inv = α.hom := rfl @[simp] lemma symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) : iso.symm {hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id} = {hom := inv, inv := hom, hom_inv_id' := inv_hom_id, inv_hom_id' := hom_inv_id} := rfl @[simp] lemma symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α := by cases α; refl @[simp] lemma symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β := ⟨λ h, symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, congr_arg symm⟩ lemma nonempty_iso_symm (X Y : C) : nonempty (X ≅ Y) ↔ nonempty (Y ≅ X) := ⟨λ h, ⟨h.some.symm⟩, λ h, ⟨h.some.symm⟩⟩ /-- Identity isomorphism. -/ @[refl, simps] def refl (X : C) : X ≅ X := { hom := 𝟙 X, inv := 𝟙 X } instance : inhabited (X ≅ X) := ⟨iso.refl X⟩ @[simp] lemma refl_symm (X : C) : (iso.refl X).symm = iso.refl X := rfl /-- Composition of two isomorphisms -/ @[trans, simps] def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z := { hom := α.hom ≫ β.hom, inv := β.inv ≫ α.inv } infixr ` ≪≫ `:80 := iso.trans -- type as `\ll \gg`. @[simp] lemma trans_mk {X Y Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) (hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') : iso.trans {hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id} {hom := hom', inv := inv', hom_inv_id' := hom_inv_id', inv_hom_id' := inv_hom_id'} = { hom := hom ≫ hom', inv := inv' ≫ inv, hom_inv_id' := hom_inv_id'', inv_hom_id' := inv_hom_id''} := rfl @[simp] lemma trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm := rfl @[simp] lemma trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') : (α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := by ext; simp only [trans_hom, category.assoc] @[simp] lemma refl_trans (α : X ≅ Y) : (iso.refl X) ≪≫ α = α := by ext; apply category.id_comp @[simp] lemma trans_refl (α : X ≅ Y) : α ≪≫ (iso.refl Y) = α := by ext; apply category.comp_id @[simp] lemma symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = iso.refl Y := ext α.inv_hom_id @[simp] lemma self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = iso.refl X := ext α.hom_inv_id @[simp] lemma symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β := by rw [← trans_assoc, symm_self_id, refl_trans] @[simp] lemma self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β := by rw [← trans_assoc, self_symm_id, refl_trans] lemma inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g := ⟨λ H, by simp [H.symm], λ H, by simp [H]⟩ lemma eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f := (inv_comp_eq α.symm).symm lemma comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom := ⟨λ H, by simp [H.symm], λ H, by simp [H]⟩ lemma eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f := (comp_inv_eq α.symm).symm lemma inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom := have ∀{X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv, from λ X Y f g h, by rw [ext h], ⟨this f.symm g.symm, this f g⟩ lemma hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv := by rw [←eq_inv_comp, comp_id] lemma comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv := by rw [←eq_comp_inv, id_comp] lemma inv_comp_eq_id (α : X ≅ Y) {f : X ⟶ Y} : α.inv ≫ f = 𝟙 Y ↔ f = α.hom := hom_comp_eq_id α.symm lemma comp_inv_eq_id (α : X ≅ Y) {f : X ⟶ Y} : f ≫ α.inv = 𝟙 X ↔ f = α.hom := comp_hom_eq_id α.symm lemma hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv := by { erw [inv_eq_inv α.symm β, eq_comm], refl } end iso /-- `is_iso` typeclass expressing that a morphism is invertible. -/ class is_iso (f : X ⟶ Y) : Prop := (out : ∃ inv : Y ⟶ X, f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y) /-- The inverse of a morphism `f` when we have `[is_iso f]`. -/ noncomputable def inv (f : X ⟶ Y) [I : is_iso f] := classical.some I.1 namespace is_iso @[simp, reassoc] lemma hom_inv_id (f : X ⟶ Y) [I : is_iso f] : f ≫ inv f = 𝟙 X := (classical.some_spec I.1).left @[simp, reassoc] lemma inv_hom_id (f : X ⟶ Y) [I : is_iso f] : inv f ≫ f = 𝟙 Y := (classical.some_spec I.1).right end is_iso open is_iso /-- Reinterpret a morphism `f` with an `is_iso f` instance as an `iso`. -/ noncomputable def as_iso (f : X ⟶ Y) [h : is_iso f] : X ≅ Y := ⟨f, inv f, hom_inv_id f, inv_hom_id f⟩ @[simp] lemma as_iso_hom (f : X ⟶ Y) [is_iso f] : (as_iso f).hom = f := rfl @[simp] lemma as_iso_inv (f : X ⟶ Y) [is_iso f] : (as_iso f).inv = inv f := rfl namespace is_iso @[priority 100] -- see Note [lower instance priority] instance epi_of_iso (f : X ⟶ Y) [is_iso f] : epi f := { left_cancellation := λ Z g h w, -- This is an interesting test case for better rewrite automation. by rw [← is_iso.inv_hom_id_assoc f g, w, is_iso.inv_hom_id_assoc f h] } @[priority 100] -- see Note [lower instance priority] instance mono_of_iso (f : X ⟶ Y) [is_iso f] : mono f := { right_cancellation := λ Z g h w, by rw [← category.comp_id g, ← category.comp_id h, ← is_iso.hom_inv_id f, ← category.assoc, w, ← category.assoc] } @[ext] lemma inv_eq_of_hom_inv_id {f : X ⟶ Y} [is_iso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : inv f = g := begin apply (cancel_epi f).mp, simp [hom_inv_id], end lemma inv_eq_of_inv_hom_id {f : X ⟶ Y} [is_iso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : inv f = g := begin apply (cancel_mono f).mp, simp [inv_hom_id], end @[ext] lemma eq_inv_of_hom_inv_id {f : X ⟶ Y} [is_iso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) : g = inv f := (inv_eq_of_hom_inv_id hom_inv_id).symm lemma eq_inv_of_inv_hom_id {f : X ⟶ Y} [is_iso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) : g = inv f := (inv_eq_of_inv_hom_id inv_hom_id).symm instance id (X : C) : is_iso (𝟙 X) := ⟨⟨𝟙 X, by simp⟩⟩ instance of_iso (f : X ≅ Y) : is_iso f.hom := ⟨⟨f.inv, by simp⟩⟩ instance of_iso_inv (f : X ≅ Y) : is_iso f.inv := is_iso.of_iso f.symm variables {f g : X ⟶ Y} {h : Y ⟶ Z} instance inv_is_iso [is_iso f] : is_iso (inv f) := is_iso.of_iso_inv (as_iso f) /- The following instance has lower priority for the following reason: Suppose we are given `f : X ≅ Y` with `X Y : Type u`. Without the lower priority, typeclass inference cannot deduce `is_iso f.hom` because `f.hom` is defeq to `(λ x, x) ≫ f.hom`, triggering a loop. -/ @[priority 900] instance comp_is_iso [is_iso f] [is_iso h] : is_iso (f ≫ h) := is_iso.of_iso $ (as_iso f) ≪≫ (as_iso h) @[simp] lemma inv_id : inv (𝟙 X) = 𝟙 X := by { ext, simp, } @[simp] lemma inv_comp [is_iso f] [is_iso h] : inv (f ≫ h) = inv h ≫ inv f := by { ext, simp, } @[simp] lemma inv_inv [is_iso f] : inv (inv f) = f := by { ext, simp, } @[simp] lemma iso.inv_inv (f : X ≅ Y) : inv (f.inv) = f.hom := by { ext, simp, } @[simp] lemma iso.inv_hom (f : X ≅ Y) : inv (f.hom) = f.inv := by { ext, simp, } @[simp] lemma inv_comp_eq (α : X ⟶ Y) [is_iso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g := (as_iso α).inv_comp_eq @[simp] lemma eq_inv_comp (α : X ⟶ Y) [is_iso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f := (as_iso α).eq_inv_comp @[simp] lemma comp_inv_eq (α : X ⟶ Y) [is_iso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α := (as_iso α).comp_inv_eq @[simp] lemma eq_comp_inv (α : X ⟶ Y) [is_iso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f := (as_iso α).eq_comp_inv lemma of_is_iso_comp_left {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [is_iso f] [is_iso (f ≫ g)] : is_iso g := by { rw [← id_comp g, ← inv_hom_id f, assoc], apply_instance, } lemma of_is_iso_comp_right {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [is_iso g] [is_iso (f ≫ g)] : is_iso f := by { rw [← comp_id f, ← hom_inv_id g, ← assoc], apply_instance, } lemma of_is_iso_fac_left {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [is_iso f] [hh : is_iso h] (w : f ≫ g = h) : is_iso g := by { rw ← w at hh, haveI := hh, exact of_is_iso_comp_left f g, } lemma of_is_iso_fac_right {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [is_iso g] [hh : is_iso h] (w : f ≫ g = h) : is_iso f := by { rw ← w at hh, haveI := hh, exact of_is_iso_comp_right f g, } end is_iso open is_iso lemma eq_of_inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] (p : inv f = inv g) : f = g := begin apply (cancel_epi (inv f)).1, erw [inv_hom_id, p, inv_hom_id], end lemma is_iso.inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] : inv f = inv g ↔ f = g := iso.inv_eq_inv (as_iso f) (as_iso g) lemma hom_comp_eq_id (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} : g ≫ f = 𝟙 X ↔ f = inv g := (as_iso g).hom_comp_eq_id lemma comp_hom_eq_id (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} : f ≫ g = 𝟙 Y ↔ f = inv g := (as_iso g).comp_hom_eq_id lemma inv_comp_eq_id (g : X ⟶ Y) [is_iso g] {f : X ⟶ Y} : inv g ≫ f = 𝟙 Y ↔ f = g := (as_iso g).inv_comp_eq_id lemma comp_inv_eq_id (g : X ⟶ Y) [is_iso g] {f : X ⟶ Y} : f ≫ inv g = 𝟙 X ↔ f = g := (as_iso g).comp_inv_eq_id lemma is_iso_of_hom_comp_eq_id (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} (h : g ≫ f = 𝟙 X) : is_iso f := by { rw [(hom_comp_eq_id _).mp h], apply_instance } lemma is_iso_of_comp_hom_eq_id (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} (h : f ≫ g = 𝟙 Y) : is_iso f := by { rw [(comp_hom_eq_id _).mp h], apply_instance } namespace iso @[ext] lemma inv_ext {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : f.inv = g := ((hom_comp_eq_id f).1 hom_inv_id).symm @[ext] lemma inv_ext' {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : g = f.inv := (hom_comp_eq_id f).1 hom_inv_id /-! All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`), but with the current design `cancel_mono` is not a good `simp` lemma, because it generates a typeclass search. When we can see syntactically that a morphism is a `mono` or an `epi` because it came from an isomorphism, it's fine to do the cancellation via `simp`. In the longer term, it might be worth exploring making `mono` and `epi` structures, rather than typeclasses, with coercions back to `X ⟶ Y`. Presumably we could write `X ↪ Y` and `X ↠ Y`. -/ @[simp] lemma cancel_iso_hom_left {X Y Z : C} (f : X ≅ Y) (g g' : Y ⟶ Z) : f.hom ≫ g = f.hom ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] lemma cancel_iso_inv_left {X Y Z : C} (f : Y ≅ X) (g g' : Y ⟶ Z) : f.inv ≫ g = f.inv ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] lemma cancel_iso_hom_right {X Y Z : C} (f f' : X ⟶ Y) (g : Y ≅ Z) : f ≫ g.hom = f' ≫ g.hom ↔ f = f' := by simp only [cancel_mono] @[simp] lemma cancel_iso_inv_right {X Y Z : C} (f f' : X ⟶ Y) (g : Z ≅ Y) : f ≫ g.inv = f' ≫ g.inv ↔ f = f' := by simp only [cancel_mono] /- Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward. We would need separate lemmas for each chain length (worse: for each pair of chain lengths). We provide two more lemmas, for case of three morphisms, because this actually comes up in practice, but then stop. -/ @[simp] lemma cancel_iso_hom_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Y ≅ Z) : f ≫ g ≫ h.hom = f' ≫ g' ≫ h.hom ↔ f ≫ g = f' ≫ g' := by simp only [←category.assoc, cancel_mono] @[simp] lemma cancel_iso_inv_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Z ≅ Y) : f ≫ g ≫ h.inv = f' ≫ g' ≫ h.inv ↔ f ≫ g = f' ≫ g' := by simp only [←category.assoc, cancel_mono] end iso namespace functor universes u₁ v₁ u₂ v₂ variables {D : Type u₂} variables [category.{v₂} D] /-- A functor `F : C ⥤ D` sends isomorphisms `i : X ≅ Y` to isomorphisms `F.obj X ≅ F.obj Y` -/ @[simps] def map_iso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y := { hom := F.map i.hom, inv := F.map i.inv, hom_inv_id' := by rw [←map_comp, iso.hom_inv_id, ←map_id], inv_hom_id' := by rw [←map_comp, iso.inv_hom_id, ←map_id] } @[simp] lemma map_iso_symm (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.map_iso i.symm = (F.map_iso i).symm := rfl @[simp] lemma map_iso_trans (F : C ⥤ D) {X Y Z : C} (i : X ≅ Y) (j : Y ≅ Z) : F.map_iso (i ≪≫ j) = (F.map_iso i) ≪≫ (F.map_iso j) := by ext; apply functor.map_comp @[simp] lemma map_iso_refl (F : C ⥤ D) (X : C) : F.map_iso (iso.refl X) = iso.refl (F.obj X) := iso.ext $ F.map_id X instance map_is_iso (F : C ⥤ D) (f : X ⟶ Y) [is_iso f] : is_iso (F.map f) := is_iso.of_iso $ F.map_iso (as_iso f) @[simp] lemma map_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] : F.map (inv f) = inv (F.map f) := by { ext, simp [←F.map_comp], } lemma map_hom_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] : F.map f ≫ F.map (inv f) = 𝟙 (F.obj X) := by simp lemma map_inv_hom (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] : F.map (inv f) ≫ F.map f = 𝟙 (F.obj Y) := by simp end functor end category_theory
aa6f4da0037a3e06126d2c01daa18c6f57df447d
e07b1aca72e83a272dd59d24c6e0fa246034d774
/src/surreal/zfc.lean
1a327340f6e7aeda7bb0dd90b2833bb159e1c3d7
[]
no_license
pedrominicz/learn
637a343bd4f8669d76819ac660a2d2d3e0958710
b79b802a9846c86c21d4b6f3e17af36e7382f0ef
refs/heads/master
1,671,746,990,402
1,670,778,113,000
1,670,778,113,000
265,735,177
1
0
null
null
null
null
UTF-8
Lean
false
false
3,385
lean
import tactic universe u inductive pSet : Type (u+1) | mk : ∀ α : Type u, (α → pSet) → pSet namespace pSet def equiv : pSet → pSet → Prop | (mk α fα) (mk β fβ) := (∀ a, ∃ b, equiv (fα a) (fβ b)) ∧ (∀ b, ∃ a, equiv (fα a) (fβ b)) /- def equiv (x y : pSet) : Prop := pSet.rec (λ α z m ⟨β, B⟩, (∀ a, ∃ b, m a (B b)) ∧ (∀ b, ∃ a, m a (B b))) x y #check @pSet.rec Π {motive : pSet → Sort u}, (Π α (fα : α → pSet), (Π (a : α), motive (fα a)) → motive (mk α fα)) → Π (n : pSet), motive n -/ def equiv' (A B : pSet.{u}) : Prop := begin refine pSet.rec _ A B, refine λ α fα ih, _, rintro ⟨β, fβ⟩, exact (∀ a, ∃ b, ih a (fβ b)) ∧ (∀ b, ∃ a, ih a (fβ b)) end def equiv'' (A B : pSet.{u}) : Prop := begin induction A with α fα ih generalizing B, change α → pSet → Prop at ih, cases B with β fβ, exact (∀ a, ∃ b, ih a (fβ b)) ∧ (∀ b, ∃ a, ih a (fβ b)) end example (A B : pSet.{u}) : equiv A B ↔ equiv' A B := begin split, all_goals { induction A with α fα ih generalizing B, change ∀ a B, _ at ih, cases B with β fβ, rintro ⟨h₁, h₂⟩, split, { clear h₂, rename h₁ h, intro a, specialize h a, cases h with b hb, use b, exact ih a (fβ b) hb }, { clear h₁, rename h₂ h, intro b, specialize h b, cases h with a ha, use a, exact ih a (fβ b) ha } } end example (A B : pSet.{u}) : equiv' A B ↔ equiv'' A B := by tauto theorem equiv.refl (A : pSet.{u}) : equiv A A := begin induction A with α fα ih, change ∀ a, equiv (fα a) (fα a) at ih, exact ⟨λ a, ⟨a, ih a⟩, λ a, ⟨a, ih a⟩⟩ end theorem equiv.rfl : ∀ {A : pSet.{u}}, equiv A A := equiv.refl theorem equiv.symm {A B : pSet.{u}} : equiv A B → equiv B A := begin induction A with α fα ih generalizing B, change ∀ a B, equiv (fα a) B → equiv B (fα a) at ih, cases B with β fβ, rintro ⟨h₁, h₂⟩, split, { clear h₁, rename h₂ h, intro b, specialize h b, cases h with a ha, use a, exact ih a (fβ b) ha }, { clear h₂, rename h₁ h, intro a, specialize h a, cases h with b hb, use b, exact ih a (fβ b) hb } end theorem equiv.trans {A B C : pSet.{u}} (h₁ : equiv A B) (h₂ : equiv B C) : equiv A C := begin induction A with α fα ih generalizing B C, change ∀ a B C, equiv (fα a) B → equiv B C → equiv (fα a) C at ih, cases B with β fβ, cases C with γ fγ, cases h₁ with h₁₁ h₁₂, cases h₂ with h₂₁ h₂₂, split, { clear h₁₂ h₂₂, rename h₁₁ h₁, rename h₂₁ h₂, intro a, specialize h₁ a, cases h₁ with b hb, specialize h₂ b, cases h₂ with c hc, use c, exact ih a (fβ b) (fγ c) hb hc }, { clear h₁₁ h₂₁, rename h₁₂ h₁, rename h₂₂ h₂, intro c, specialize h₂ c, cases h₂ with b hb, specialize h₁ b, cases h₁ with a ha, use a, exact ih a (fβ b) (fγ c) ha hb } end instance setoid : setoid pSet.{u} := ⟨pSet.equiv, equiv.refl, @equiv.symm, @equiv.trans⟩ end pSet def Set : Type (u+1) := quotient pSet.setoid.{u} /- inductive pgame : Type (u+1) | mk : ∀ α β : Type u, (α → pgame) → (β → pgame) → pgame -/
83d81a24af698ca4987dafbd43aaa98f182c4815
cc060cf567f81c404a13ee79bf21f2e720fa6db0
/lean/20170425-congruence.lean
281905f35b3da1f8a143ea8f49392bfe438334fc
[ "Apache-2.0" ]
permissive
semorrison/proof
cf0a8c6957153bdb206fd5d5a762a75958a82bca
5ee398aa239a379a431190edbb6022b1a0aa2c70
refs/heads/master
1,610,414,502,842
1,518,696,851,000
1,518,696,851,000
78,375,937
2
1
null
null
null
null
UTF-8
Lean
false
false
1,728
lean
namespace tactic.interactive open expr tactic private meta def congr_aux : expr → expr → tactic unit | (app f₁ a₁) (app f₂ a₂) := do apply ``(congr), swap, reflexivity <|> swap, congr_aux f₁ f₂ | _ _ := try reflexivity /-- Given a goal of form `f a1 ... an = f' a1' ... an'`, this tactic breaks it down to subgoals `f = f'`, `a1 = a1'`, ... Subgoals provable by reflexivity are dispensed automatically. -/ meta def congruence : tactic unit := do ```(%%lhs = %%rhs) ← target | fail "goal is not an equality", congr_aux lhs rhs /-- Given a goal that equates two structure values, this tactic breaks it down to subgoals equating each pair of fields. -/ meta def congr_struct : tactic unit := do ```(%%lhs = %%rhs) ← target | fail "goal is not an equality", ty ← infer_type lhs, [ctor] ← get_constructors_for ty | fail "equated type is not a structure", tactic.cases lhs, tactic.cases rhs, congruence end tactic.interactive structure X := ( x : unit ) ( y : unit ) lemma test1 ( a b : X ) : a = b := begin congr_struct, -- x y x_1 y_1 : ℕ -- ⊢ x = x_1 -- x y x_1 y_1 : ℕ -- ⊢ y = y_1 { induction x, induction x_1, reflexivity }, { induction y, induction y_1, reflexivity } -- Great! end def f ( a : X ) : X := { x := a.y, y := a.x } lemma test2 ( a : X ) : a = f (f a) := begin congr_struct, -- breaks because cases.lhs messes up the right hand side! end structure Y := ( x : nat ) ( y : nat ) def g ( x : nat ) : Y := { x := x, y := x } def h ( a : Y ) : Y := { x := a.y, y := a.x } lemma test3 ( x : nat ) : g 0 = h ( g 0 ) := begin congr_struct, end
2b396b25347b76fd6091adf421517f94342dbdd7
dc44027cf56929ab978847c471fbb9d769959991
/lean-3.4.2-windows/lib/lean/library/init/version.lean
38c9193194565aeb33387abb4553bd7dcbf449d7
[]
no_license
PrestonTong/LeanIMP
f8862096d5a354aca011673145bf5ad0e0bbbca4
bc69a2af202fc0cdf97e924935c920236132866a
refs/heads/master
1,600,843,830,997
1,575,836,133,000
1,575,836,133,000
225,431,451
0
0
null
null
null
null
UTF-8
Lean
false
false
331
lean
prelude import init.data.nat.basic init.data.string.basic def lean.version : nat × nat × nat := (3, 4, 2) def lean.githash : string := "cbd2b6686ddb566028f5830490fe55c0b3a9a4cb" def lean.is_release : bool := 1 ≠ 0 /-- Additional version description like "nightly-2018-03-11" -/ def lean.special_version_desc : string := ""