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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
229070e02d87ce3f7bcb85bf1ddb022e8da1f1f1 | 85d23ae5fcdcd77981feb67549852ff901e8a583 | /cubes_fin.lean | 6acb93c7d847f3cb794d14f78aed04fc33704218 | [] | no_license | javra/cubes | 5b480abcf1a869335a82b4fb5357ec4d16ab56bc | 734bdf71b9086b0ba9ef7dba3ede0c71f10872cc | refs/heads/master | 1,611,513,591,851 | 1,489,495,303,000 | 1,489,495,303,000 | 84,469,571 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,825 | lean | /- THE CUBE CATEGORY ON fiITE SETS -/
import .cubes .fi
open cmonad fi nat
universes u v
def cfi (n : ℕ) := cmonad (fi n)
/- Projecting at the i-th dimension -/
-- TODO generalize this to arbitrary elementary surjections?
def cproj (b : bool) : Π {m}, fi (m + 1) → cmor (fi (m + 1)) (fi m)
| m fi.zero fi.zero := b
| (m + 1) fi.zero (suc j) := dim j
| (m + 1) (suc i) fi.zero := dim fi.zero
| (m + 1) (suc i) (suc j) := do x <- cproj i j,
dim $ suc x
--TODO simplify this
theorem cproj_self (b : bool) {m} (i : fi (m + 1)) : cproj b i i = b :=
begin
cases i with n n i,
{ cases m, repeat {reflexivity} },
{ induction i with n n i ih_i, simp[cproj],
{ cases n, repeat {simp[cproj], rw cbind_bool} },
{ simp[cproj], rw [ih_i, cbind_bool] } }
end
def cdeg {m} (i : fi (m + 1)) : cmor (fi m) (fi (m + 1)) := dim ∘ deg i
theorem cproj_cdeg {m} {b : bool} (i : fi (m + 1)) : cproj b i ∘c cdeg i = dim :=
begin
apply funext, intro j, change (_ ∘c dim) _ = _, rw cid_right,
cases i with n n i,
{ induction j, reflexivity, reflexivity },
{ induction j with n n j ih_j, reflexivity,
simp[deg, cproj], cases i,
{ cases j, reflexivity, reflexivity },
{ rw ih_j, reflexivity } }
end
/- Lift a cubical morphism by 1 -/
-- TODO generalize this
def clift {n k} (f : cmor (fi n) (fi k)) : cmor (fi (succ n)) (fi (succ k))
| fi.zero := dim fi.zero
| (suc i) := do x <- f i,
dim $ suc x
theorem clift_suc {n k} (f : cmor (fi n) (fi k)) (i : fi n) :
clift f (suc i) = (f i >>= (dim ∘ suc)) :=
by reflexivity
theorem clift_dim {n : ℕ} : clift (@dim (fi n)) = dim :=
begin
apply funext, intro i, cases i, repeat {reflexivity},
end
theorem clift_ccomp {m n o : ℕ} (f : cmor (fi m) (fi n)) (g : cmor (fi n) (fi o)) :
clift (g ∘c f) = (clift g) ∘c (clift f) :=
begin
apply funext, intro i, cases i with n n i, reflexivity,
simp[clift,ccomp], cases (f i) with j, reflexivity, reflexivity,
change (g j >>= _) = clift _ _, rw clift_suc,
end
--TODO generalize to arbitrary projections
theorem cproj_clift {m n : ℕ} (f : cmor (fi m) (fi n)) (b : bool) :
(cproj b fi.zero) ∘c (clift f) = f ∘c (cproj b fi.zero) :=
begin
apply funext, intro i, cases i with n n i,
simp[ccomp, clift], rw [cproj_self, cbind_bool, cbind_dim, cproj_self],
{ cases m, simp[ccomp], cases i,
simp[ccomp, cproj, clift], rw [cbind_dim, cbind_assoc],
cases f i with j, reflexivity, reflexivity, rw cbind_dim, rw cbind_dim,
cases n, cases j, reflexivity }
end
def zero_deg {m : ℕ} : cmor (fi 0) (fi m) := λ i, match i with
end
theorem zero_deg_right {m n : ℕ} (f : cmor (fi m) (fi n)) :
f ∘c zero_deg = zero_deg :=
begin
apply funext, intro i, cases i
end |
ab5bc8ec0179691978ed6759d00d19e8ac4b7dd1 | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /core/default.lean | f46a678ae6f45e6bd718d524c4b864272ba2a63d | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 23 | lean |
import core.data.list
|
27cad3b0f77e70000c3f6d71747714e3b363492c | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/homology/exact.lean | cb4411a7c6047c1b79bcfca0b23848200c40ba58 | [
"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 | 12,656 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.homology.image_to_kernel
/-!
# Exact sequences
In a category with zero morphisms, images, and equalizers we say that `f : A ⟶ B` and `g : B ⟶ C`
are exact if `f ≫ g = 0` and the natural map `image f ⟶ kernel g` is an epimorphism.
In any preadditive category this is equivalent to the homology at `B` vanishing.
However in general it is weaker than other reasonable definitions of exactness,
particularly that
1. the inclusion map `image.ι f` is a kernel of `g` or
2. `image f ⟶ kernel g` is an isomorphism or
3. `image_subobject f = kernel_subobject f`.
However when the category is abelian, these all become equivalent;
these results are found in `category_theory/abelian/exact.lean`.
# Main results
* Suppose that cokernels exist and that `f` and `g` are exact.
If `s` is any kernel fork over `g` and `t` is any cokernel cofork over `f`,
then `fork.ι s ≫ cofork.π t = 0`.
* Precomposing the first morphism with an epimorphism retains exactness.
Postcomposing the second morphism with a monomorphism retains exactness.
* If `f` and `g` are exact and `i` is an isomorphism,
then `f ≫ i.hom` and `i.inv ≫ g` are also exact.
# Future work
* Short exact sequences, split exact sequences, the splitting lemma (maybe only for abelian
categories?)
* Two adjacent maps in a chain complex are exact iff the homology vanishes
-/
universes v v₂ u u₂
open category_theory
open category_theory.limits
variables {V : Type u} [category.{v} V]
variables [has_images V]
namespace category_theory
/--
Two morphisms `f : A ⟶ B`, `g : B ⟶ C` are called exact if `w : f ≫ g = 0` and the natural map
`image_to_kernel f g w : image_subobject f ⟶ kernel_subobject g` is an epimorphism.
In any preadditive category, this is equivalent to `w : f ≫ g = 0` and `homology f g w ≅ 0`.
In an abelian category, this is equivalent to `image_to_kernel f g w` being an isomorphism,
and hence equivalent to the usual definition,
`image_subobject f = kernel_subobject g`.
-/
-- One nice feature of this definition is that we have
-- `epi f → exact g h → exact (f ≫ g) h` and `exact f g → mono h → exact f (g ≫ h)`,
-- which do not necessarily hold in a non-abelian category with the usual definition of `exact`.
structure exact [has_zero_morphisms V] [has_kernels V] {A B C : V} (f : A ⟶ B) (g : B ⟶ C) : Prop :=
(w : f ≫ g = 0)
(epi : epi (image_to_kernel f g w))
-- This works as an instance even though `exact` itself is not a class, as long as the goal is
-- literally of the form `epi (image_to_kernel f g h.w)` (where `h : exact f g`). If the proof of
-- `f ≫ g = 0` looks different, we are out of luck and have to add the instance by hand.
attribute [instance] exact.epi
attribute [reassoc] exact.w
section
variables [has_zero_object V] [preadditive V] [has_kernels V] [has_cokernels V]
open_locale zero_object
/--
In any preadditive category,
composable morphisms `f g` are exact iff they compose to zero and the homology vanishes.
-/
lemma preadditive.exact_iff_homology_zero {A B C : V} (f : A ⟶ B) (g : B ⟶ C) :
exact f g ↔ ∃ w : f ≫ g = 0, nonempty (homology f g w ≅ 0) :=
⟨λ h, ⟨h.w, ⟨cokernel.of_epi _⟩⟩,
λ h, begin
obtain ⟨w, ⟨i⟩⟩ := h,
exact ⟨w, preadditive.epi_of_cokernel_zero ((cancel_mono i.hom).mp (by ext))⟩,
end⟩
lemma preadditive.exact_of_iso_of_exact {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : arrow.mk f₁ ≅ arrow.mk f₂) (β : arrow.mk g₁ ≅ arrow.mk g₂) (p : α.hom.right = β.hom.left)
(h : exact f₁ g₁) :
exact f₂ g₂ :=
begin
rw preadditive.exact_iff_homology_zero at h ⊢,
rcases h with ⟨w₁, ⟨i⟩⟩,
suffices w₂ : f₂ ≫ g₂ = 0, from ⟨w₂, ⟨(homology.map_iso w₁ w₂ α β p).symm.trans i⟩⟩,
rw [← cancel_epi α.hom.left, ← cancel_mono β.inv.right, comp_zero, zero_comp, ← w₁],
simp only [← arrow.mk_hom f₁, ← arrow.left_hom_inv_right α.hom,
← arrow.mk_hom g₁, ← arrow.left_hom_inv_right β.hom, p],
simp only [arrow.mk_hom, is_iso.inv_hom_id_assoc, category.assoc, ← arrow.inv_right,
is_iso.iso.inv_hom]
end
/-- A reformulation of `preadditive.exact_of_iso_of_exact` that does not involve the arrow
category. -/
lemma preadditive.exact_of_iso_of_exact' {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : A₁ ≅ A₂) (β : B₁ ≅ B₂) (γ : C₁ ≅ C₂) (hsq₁ : α.hom ≫ f₂ = f₁ ≫ β.hom)
(hsq₂ : β.hom ≫ g₂ = g₁ ≫ γ.hom)
(h : exact f₁ g₁) :
exact f₂ g₂ :=
preadditive.exact_of_iso_of_exact f₁ g₁ f₂ g₂ (arrow.iso_mk α β hsq₁) (arrow.iso_mk β γ hsq₂) rfl h
lemma preadditive.exact_iff_exact_of_iso {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : arrow.mk f₁ ≅ arrow.mk f₂) (β : arrow.mk g₁ ≅ arrow.mk g₂) (p : α.hom.right = β.hom.left) :
exact f₁ g₁ ↔ exact f₂ g₂ :=
⟨preadditive.exact_of_iso_of_exact _ _ _ _ _ _ p,
preadditive.exact_of_iso_of_exact _ _ _ _ α.symm β.symm
begin
rw ← cancel_mono α.hom.right,
simp only [iso.symm_hom, ← comma.comp_right, α.inv_hom_id],
simp only [p, ←comma.comp_left, arrow.id_right, arrow.id_left, iso.inv_hom_id],
refl
end⟩
end
section
variables [has_zero_morphisms V] [has_kernels V]
lemma comp_eq_zero_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) : f ≫ g = 0 :=
begin
rw [←image_subobject_arrow_comp f, category.assoc],
convert comp_zero,
rw p,
simp,
end
lemma image_to_kernel_is_iso_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) :
is_iso (image_to_kernel f g (comp_eq_zero_of_image_eq_kernel f g p)) :=
begin
refine ⟨⟨subobject.of_le _ _ p.ge, _⟩⟩,
dsimp [image_to_kernel],
simp only [subobject.of_le_comp_of_le, subobject.of_le_refl],
simp,
end
-- We'll prove the converse later, when `V` is abelian.
lemma exact_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) : exact f g :=
{ w := comp_eq_zero_of_image_eq_kernel f g p,
epi := begin
haveI := image_to_kernel_is_iso_of_image_eq_kernel f g p,
apply_instance,
end }
end
variables {A B C D : V} {f : A ⟶ B} {g : B ⟶ C} {h : C ⟶ D}
local attribute [instance] epi_comp
section
variables [has_zero_morphisms V] [has_equalizers V]
lemma exact_comp_hom_inv_comp (i : B ≅ D) (h : exact f g) : exact (f ≫ i.hom) (i.inv ≫ g) :=
begin
refine ⟨by simp [h.w], _⟩,
rw image_to_kernel_comp_hom_inv_comp,
haveI := h.epi,
apply_instance,
end
lemma exact_comp_inv_hom_comp (i : D ≅ B) (h : exact f g) : exact (f ≫ i.inv) (i.hom ≫ g) :=
exact_comp_hom_inv_comp i.symm h
lemma exact_comp_hom_inv_comp_iff (i : B ≅ D) : exact (f ≫ i.hom) (i.inv ≫ g) ↔ exact f g :=
⟨λ h, by simpa using exact_comp_inv_hom_comp i h, exact_comp_hom_inv_comp i⟩
lemma exact_epi_comp (hgh : exact g h) [epi f] : exact (f ≫ g) h :=
begin
refine ⟨by simp [hgh.w], _⟩,
rw image_to_kernel_comp_left,
apply_instance,
end
@[simp]
lemma exact_iso_comp [is_iso f] : exact (f ≫ g) h ↔ exact g h :=
⟨λ w, by { rw ←is_iso.inv_hom_id_assoc f g, exact exact_epi_comp w }, λ w, exact_epi_comp w⟩
lemma exact_comp_mono (hfg : exact f g) [mono h] : exact f (g ≫ h) :=
begin
refine ⟨by simp [hfg.w_assoc], _⟩,
rw image_to_kernel_comp_right f g h hfg.w,
apply_instance,
end
@[simp]
lemma exact_comp_iso [is_iso h] : exact f (g ≫ h) ↔ exact f g :=
⟨λ w, begin
rw [←category.comp_id g, ←is_iso.hom_inv_id h, ←category.assoc],
exactI exact_comp_mono w,
end,
λ w, exact_comp_mono w⟩
lemma exact_kernel_subobject_arrow : exact (kernel_subobject f).arrow f :=
begin
refine ⟨by simp, _⟩,
apply @is_iso.epi_of_iso _ _ _ _ _ _,
exact ⟨⟨factor_thru_image_subobject _, by { ext, simp, }, by { ext, simp, }⟩⟩,
end
lemma exact_kernel_ι : exact (kernel.ι f) f :=
by { rw [←kernel_subobject_arrow', exact_iso_comp], exact exact_kernel_subobject_arrow }
instance (h : exact f g) : epi (factor_thru_kernel_subobject g f h.w) :=
begin
rw ←factor_thru_image_subobject_comp_image_to_kernel,
apply epi_comp,
end
instance (h : exact f g) : epi (kernel.lift g f h.w) :=
begin
rw ←factor_thru_kernel_subobject_comp_kernel_subobject_iso,
apply epi_comp
end
variables (A)
lemma kernel_subobject_arrow_eq_zero_of_exact_zero_left (h : exact (0 : A ⟶ B) g) :
(kernel_subobject g).arrow = 0 :=
begin
rw [←cancel_epi (image_to_kernel (0 : A ⟶ B) g h.w),
←cancel_epi (factor_thru_image_subobject (0 : A ⟶ B))],
simp
end
lemma kernel_ι_eq_zero_of_exact_zero_left (h : exact (0 : A ⟶ B) g) :
kernel.ι g = 0 :=
by { rw ←kernel_subobject_arrow', simp [kernel_subobject_arrow_eq_zero_of_exact_zero_left A h], }
lemma exact_zero_left_of_mono [has_zero_object V] [mono g] : exact (0 : A ⟶ B) g :=
⟨by simp, image_to_kernel_epi_of_zero_of_mono _⟩
end
section has_cokernels
variables [has_zero_morphisms V] [has_equalizers V] [has_cokernels V] (f g)
@[simp, reassoc] lemma kernel_comp_cokernel (h : exact f g) : kernel.ι g ≫ cokernel.π f = 0 :=
begin
rw [←kernel_subobject_arrow', category.assoc],
convert comp_zero,
apply zero_of_epi_comp (image_to_kernel f g h.w) _,
rw [image_to_kernel_arrow_assoc, ←image_subobject_arrow, category.assoc, ←iso.eq_inv_comp],
ext,
simp,
end
lemma comp_eq_zero_of_exact (h : exact f g) {X Y : V} {ι : X ⟶ B} (hι : ι ≫ g = 0) {π : B ⟶ Y}
(hπ : f ≫ π = 0) : ι ≫ π = 0 :=
by rw [←kernel.lift_ι _ _ hι, ←cokernel.π_desc _ _ hπ, category.assoc,
kernel_comp_cokernel_assoc _ _ h, zero_comp, comp_zero]
@[simp, reassoc] lemma fork_ι_comp_cofork_π (h : exact f g) (s : kernel_fork g)
(t : cokernel_cofork f) : fork.ι s ≫ cofork.π t = 0 :=
comp_eq_zero_of_exact f g h (kernel_fork.condition s) (cokernel_cofork.condition t)
end has_cokernels
section
variables [has_zero_object V]
open_locale zero_object
section
variables [has_zero_morphisms V] [has_kernels V]
lemma exact_of_zero {A C : V} (f : A ⟶ 0) (g : 0 ⟶ C) : exact f g :=
begin
obtain rfl : f = 0 := by ext,
obtain rfl : g = 0 := by ext,
fsplit,
{ simp, },
{ exact image_to_kernel_epi_of_zero_of_mono 0, },
end
lemma exact_zero_mono {B C : V} (f : B ⟶ C) [mono f] : exact (0 : (0 ⟶ B)) f :=
⟨by simp, infer_instance⟩
lemma exact_epi_zero {A B : V} (f : A ⟶ B) [epi f] : exact f (0 : (B ⟶ 0)) :=
⟨by simp, infer_instance⟩
end
section
variables [preadditive V]
lemma mono_iff_exact_zero_left [has_kernels V] {B C : V} (f : B ⟶ C) :
mono f ↔ exact (0 : (0 ⟶ B)) f :=
⟨λ h, by exactI exact_zero_mono _,
λ h, preadditive.mono_of_kernel_iso_zero
((kernel_subobject_iso f).symm ≪≫ iso_zero_of_epi_zero (by simpa using h.epi))⟩
lemma epi_iff_exact_zero_right [has_equalizers V] {A B : V} (f : A ⟶ B) :
epi f ↔ exact f (0 : (B ⟶ 0)) :=
⟨λ h, by exactI exact_epi_zero _,
λ h, begin
have e₁ := h.epi,
rw image_to_kernel_zero_right at e₁,
have e₂ : epi (((image_subobject f).arrow ≫ inv (kernel_subobject 0).arrow) ≫
(kernel_subobject 0).arrow) := @epi_comp _ _ _ _ _ _ e₁ _ _,
rw [category.assoc, is_iso.inv_hom_id, category.comp_id] at e₂,
rw [←image_subobject_arrow] at e₂,
resetI,
haveI : epi (image.ι f) := epi_of_epi (image_subobject_iso f).hom (image.ι f),
apply epi_of_epi_image,
end⟩
end
end
namespace functor
variables [has_zero_morphisms V] [has_kernels V] {W : Type u₂} [category.{v₂} W]
variables [has_images W] [has_zero_morphisms W] [has_kernels W]
/-- A functor reflects exact sequences if any composable pair of morphisms that is mapped to an
exact pair is itself exact. -/
class reflects_exact_sequences (F : V ⥤ W) :=
(reflects : ∀ {A B C : V} (f : A ⟶ B) (g : B ⟶ C), exact (F.map f) (F.map g) → exact f g)
lemma exact_of_exact_map (F : V ⥤ W) [reflects_exact_sequences F] {A B C : V} {f : A ⟶ B}
{g : B ⟶ C} (hfg : exact (F.map f) (F.map g)) : exact f g :=
reflects_exact_sequences.reflects f g hfg
end functor
end category_theory
|
fb8387dfdc9a008b2e1f4e7cebbfe8b34dd40380 | 8b147c3d61a55005ca839480a4045e69683f7655 | /locally_nameless.lean | 3a1c770a682058adfde4ed70820be3d5b07a1d06 | [] | no_license | dselsam/unrealistic_compiler | ce69efac0d573642b67f44a63eb5f18cdf596b27 | 70514de492a6a1ed705ad247333ae5b3f8455a83 | refs/heads/master | 1,609,483,664,302 | 1,500,654,169,000 | 1,500,654,169,000 | 97,516,326 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,127 | lean | import .atom data.hash_map
namespace locally_nameless
inductive type : Type
| base : type
| arrow : type → type → type
inductive exp : Type
| var_b : ℕ → exp
| var_f : atom → exp
| const : ℕ → exp
| abs : exp → exp
| app : exp → exp → exp
open exp
def subst_exp (v:atom) (s:exp) : exp → exp
| (var_b n) := var_b n
| (var_f x) := if x = v then s else var_f x
| (const n) := const n
| (abs e) := abs (subst_exp e)
| (app e₁ e₂) := app (subst_exp e₁) (subst_exp e₂)
def fv_exp : exp → list atom
| (var_b nat) := []
| (var_f x) := [x]
| (const n) := []
| (abs e) := fv_exp e
| (app e₁ e₂) := fv_exp e₁ ∪ fv_exp e₂
def open_exp_wrt_exp_core : ℕ → exp → exp → exp
| k s (var_b n) := match has_ordering.cmp n k with
| ordering.lt := var_b n
| ordering.eq := s
| ordering.gt := var_b (n-1)
end
| k s (var_f x) := var_f x
| k s (const n) := const n
| k s (abs e) := abs (open_exp_wrt_exp_core (k+1) s e)
| k s (app e₁ e₂) := app (open_exp_wrt_exp_core k s e₁) (open_exp_wrt_exp_core k s e₂)
def open_exp_wrt_exp (s e : exp) : exp := open_exp_wrt_exp_core 0 s e.
def context : Type := hash_map atom (λ a, exp)
def reduce : exp → option exp
| (app (abs f) a) := have exp.sizeof (open_exp_wrt_exp a f) < exp.sizeof f + (exp.sizeof a + 2), from sorry, reduce (open_exp_wrt_exp a f)
| (abs e) := some (abs e)
| (const n) := some (const n)
| (app _ _) := none
| (var_b n) := none
| (var_f v) := none
#check @reduce.equations._eqn_1
#check @reduce.equations._eqn_2
#check @reduce.equations._eqn_3
#check @reduce.equations._eqn_4
#check @reduce.equations._eqn_5
#check @reduce.equations._eqn_6
#check @reduce.equations._eqn_7
#check @reduce.equations._eqn_8
lemma not_lt_refl : ∀ (n : ℕ), ¬ (n < n) := sorry
example : reduce (app (abs (var_b 0)) (const 5)) = some (const 5) :=
begin
simp [reduce, open_exp_wrt_exp, open_exp_wrt_exp_core, open_exp_wrt_exp_core._match_1, has_ordering.cmp, nat.cmp, not_lt_refl],
end
end locally_nameless
|
020b4c1368f58001b0c46ab8a425796c2ee58361 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/omega.lean | 5d0425d193d1169b00df0a149c9d3816a10dfdcd | [
"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,243 | lean | /-
Test cases for omega. Most of the examples are from John Harrison's
Handbook of Practical Logic and Automated Reasoning.
-/
import data.fintype.basic
import tactic.omega
example (n : ℤ) : n - 1 ≠ n := by omega
example (x : int) : (x = 5 ∨ x = 7) → 2 < x := by omega
example (x : int) : x ≤ -x → x ≤ 0 := by omega
example : ∀ x y : int, (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega
example : ∀ (x y z : int), x < y → y < z → x < z := by omega
example (x y z : int) : x - y ≤ x - z → z ≤ y:= by omega
example (x : int) (h1 : x = -5 ∨ x = 7) (h2 : x = 0) : false := by omega
example : ∀ x : int, 31 * x > 0 → x > 0 := by omega
example (x y : int) : (-x - y < x - y) → (x - y < x + y) → (x > 0 ∧ y > 0) := by omega
example : ∀ (x : int), (x ≥ -1 ∧ x ≤ 1) → (x = -1 ∨ x = 0 ∨ x = 1) := by omega
example : ∀ (x : int), 5 * x = 5 → x = 1 := by omega
example (x y : int) : ∀ z w v : int, x = y → y = z → x = z := by omega
example : ∀ x : int, x < 349 ∨ x > 123 := by omega
example : ∀ x y : int, x ≤ 3 * y → 3 * x ≤ 9 * y := by omega
example (x : int) (h1 : x < 43 ∧ x > 513) : false := by omega
example (x y z w : int) : x ≤ y → y ≤ z → z ≤ w → x ≤ w:= by omega
example (x y z : int) : ∀ w v : int, 100 = x → x = y → y = z → z = w → w = v → v = 100 := by omega
example (x : nat) : 31 * x > 0 → x > 0 := by omega
example (x y : nat) : (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega
example : ∀ (x y z y : nat), ¬(2 * x + 1 = 2 * y) := by omega
example : ∀ (x y : nat), x > 0 → x + y > 0 := by omega
example : ∀ (x : nat), x < 349 ∨ x > 123 := by omega
example : ∀ (x y : nat), (x = 2 ∨ x = 10) → (x = 3 * y) → false := by omega
example (x y : nat) : x ≤ 3 * y → 3 * x ≤ 9 * y := by omega
example (x y z : nat) : (x ≤ y) → (z > y) → (x - z = 0) := by omega
example (x y z : nat) : x - 5 > 122 → y ≤ 127 → y < x := by omega
example : ∀ (x y : nat), x ≤ y ↔ x - y = 0 := by omega
example (k : nat) (h : 1 * 1 + 1 * 1 + 1 = 1 * 1 * k) : k = 3 := by omega
constant nat.prime : ℕ → Prop
example (a b : ℕ) (h : a < b + 1) (ha : a.prime) : a ≤ b := by omega
example (a b c : ℕ) (h : a < b + 1) (ha : c.prime) : a ≤ b := by omega
example (a b : ℕ) (h : a < b + 1) (p : fin a) : a ≤ b := by omega
example : nat.zero = nat.zero := by omega
example : 3 < 4 := by omega
example {X : Type} [fintype X] (n k : ℕ) (hk : k + 1 ≤ n) : n - k = n - (k + 1) + 1 := by omega
example (n : ℕ) (G_C G_L : list ℤ) (hG : G_C.length + G_L.length = n + 1)
(iv : ℕ) (hi : iv < G_C.length) : iv + (G_C.length - iv - 1) + G_L.length = n := by omega
/-
Use `omega T` to specify the domain, where `T = int` or `T = nat`.
-/
example (i : int) (n : nat) (h1 : n = 0) (h2 : i < i) : false := by omega int
example (i : int) (n : nat) (h1 : i = 0) (h2 : n < n) : false := by omega nat
/-
Use `omega manual T` to disable automatic reverts, where `T = int` or `T = nat`.
-/
example (x y z w : int) (h1 : 3 * y ≥ x) (h2 : z > 19 * w) : 3 * x ≤ 9 * y :=
by {revert h1, omega manual int}
example (n : nat) (h1 : n < 34) (i : int) (h2 : i * 9 = -72) : i = -8 :=
by {revert h2, omega manual int}
|
79436b2bea9a8ca44f4fd86ed1dbecd0c7fc3e69 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/homology/chain_complex.lean | b158c0fc9bfbe932f73ed2e4172d1ba8f0e37fce | [] | 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,149 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.int.basic
import Mathlib.category_theory.graded_object
import Mathlib.category_theory.differential_object
import Mathlib.PostPort
universes v u u_1
namespace Mathlib
/-!
# Chain complexes
We define a chain complex in `V` as a differential `ℤ`-graded object in `V`.
This is fancy language for the obvious definition,
and it seems we can use it straightforwardly:
```
example (C : chain_complex V) : C.X 5 ⟶ C.X 6 := C.d 5
```
-/
/--
A `homological_complex V b` for `b : β` is a (co)chain complex graded by `β`,
with differential in grading `b`.
(We use the somewhat cumbersome `homological_complex` to avoid the name conflict with `ℂ`.)
-/
def homological_complex (V : Type u) [category_theory.category V] [category_theory.limits.has_zero_morphisms V] {β : Type} [add_comm_group β] (b : β) :=
category_theory.differential_object (category_theory.graded_object_with_shift b V)
/--
A chain complex in `V` is "just" a differential `ℤ`-graded object in `V`,
with differential graded `-1`.
-/
def chain_complex (V : Type u) [category_theory.category V] [category_theory.limits.has_zero_morphisms V] :=
homological_complex V (-1)
/--
A cochain complex in `V` is "just" a differential `ℤ`-graded object in `V`,
with differential graded `+1`.
-/
def cochain_complex (V : Type u) [category_theory.category V] [category_theory.limits.has_zero_morphisms V] :=
homological_complex V 1
-- The chain groups of a chain complex `C` are accessed as `C.X i`,
-- and the differentials as `C.d i : C.X i ⟶ C.X (i-1)`.
namespace homological_complex
@[simp] theorem d_squared {V : Type u} [category_theory.category V] [category_theory.limits.has_zero_morphisms V] {β : Type} [add_comm_group β] {b : β} (C : homological_complex V b) (i : β) : category_theory.differential_object.d C i ≫ category_theory.differential_object.d C (i + b) = 0 := sorry
/--
A convenience lemma for morphisms of cochain complexes,
picking out one component of the commutation relation.
-/
-- I haven't been able to get this to work with projection notation: `f.comm_at i`
@[simp] theorem comm_at {V : Type u} [category_theory.category V] [category_theory.limits.has_zero_morphisms V] {β : Type} [add_comm_group β] {b : β} {C : homological_complex V b} {D : homological_complex V b} (f : C ⟶ D) (i : β) : category_theory.differential_object.d C i ≫ category_theory.differential_object.hom.f f (i + b) =
category_theory.differential_object.hom.f f i ≫ category_theory.differential_object.d D i := sorry
@[simp] theorem comm {V : Type u} [category_theory.category V] [category_theory.limits.has_zero_morphisms V] {β : Type} [add_comm_group β] {b : β} {C : homological_complex V b} {D : homological_complex V b} (f : C ⟶ D) : category_theory.differential_object.d C ≫
category_theory.functor.map
(category_theory.equivalence.functor (category_theory.shift (category_theory.graded_object_with_shift b V) ^ 1))
(category_theory.differential_object.hom.f f) =
category_theory.differential_object.hom.f f ≫ category_theory.differential_object.d D :=
category_theory.differential_object.hom.comm (category_theory.graded_object_with_shift b V)
(category_theory.graded_object.category_of_graded_objects β) (category_theory.graded_object.has_zero_morphisms β)
(category_theory.graded_object.has_shift b) C D f
/-- The forgetful functor from cochain complexes to graded objects, forgetting the differential. -/
def forget (V : Type u) [category_theory.category V] [category_theory.limits.has_zero_morphisms V] {β : Type} [add_comm_group β] {b : β} : homological_complex V b ⥤ category_theory.graded_object β V :=
category_theory.differential_object.forget (category_theory.graded_object_with_shift b V)
protected instance inhabited {β : Type} [add_comm_group β] {b : β} : Inhabited (homological_complex (category_theory.discrete PUnit) b) :=
{ default := 0 }
|
093d0ab60ab4ef1dc7d2ea790f5deecbdfa37380 | 022547453607c6244552158ff25ab3bf17361760 | /src/algebra/indicator_function.lean | 6ccdfdc408fef5d9b9cb7f1fd977351a64fb8522 | [
"Apache-2.0"
] | permissive | 1293045656/mathlib | 5f81741a7c1ff1873440ec680b3680bfb6b7b048 | 4709e61525a60189733e72a50e564c58d534bed8 | refs/heads/master | 1,687,010,200,553 | 1,626,245,646,000 | 1,626,245,646,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,169 | lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import algebra.group.pi
import group_theory.group_action
import algebra.support
import data.finset.lattice
/-!
# Indicator function
- `indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise.
- `mul_indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `λx, 1`.
## Tags
indicator, characteristic
-/
noncomputable theory
open_locale classical big_operators
open function
variables {α β ι M N : Type*}
namespace set
section has_one
variables [has_one M] [has_one N] {s t : set α} {f g : α → M} {a : α}
/-- `indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/
def indicator {M} [has_zero M] (s : set α) (f : α → M) : α → M := λ x, if x ∈ s then f x else 0
/-- `mul_indicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/
@[to_additive]
def mul_indicator (s : set α) (f : α → M) : α → M := λ x, if x ∈ s then f x else 1
@[simp, to_additive] lemma piecewise_eq_mul_indicator : s.piecewise f 1 = s.mul_indicator f := rfl
@[to_additive] lemma mul_indicator_apply (s : set α) (f : α → M) (a : α) :
mul_indicator s f a = if a ∈ s then f a else 1 := rfl
@[simp, to_additive] lemma mul_indicator_of_mem (h : a ∈ s) (f : α → M) :
mul_indicator s f a = f a := if_pos h
@[simp, to_additive] lemma mul_indicator_of_not_mem (h : a ∉ s) (f : α → M) :
mul_indicator s f a = 1 := if_neg h
@[to_additive] lemma mul_indicator_eq_one_or_self (s : set α) (f : α → M) (a : α) :
mul_indicator s f a = 1 ∨ mul_indicator s f a = f a :=
if h : a ∈ s then or.inr (mul_indicator_of_mem h f) else or.inl (mul_indicator_of_not_mem h f)
@[simp, to_additive] lemma mul_indicator_apply_eq_self :
s.mul_indicator f a = f a ↔ (a ∉ s → f a = 1) :=
ite_eq_left_iff.trans $ by rw [@eq_comm _ (f a)]
@[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f ↔ mul_support f ⊆ s :=
by simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm]
@[to_additive] lemma mul_indicator_eq_self_of_superset (h1 : s.mul_indicator f = f) (h2 : s ⊆ t) :
t.mul_indicator f = f :=
by { rw mul_indicator_eq_self at h1 ⊢, exact subset.trans h1 h2 }
@[simp, to_additive] lemma mul_indicator_apply_eq_one :
mul_indicator s f a = 1 ↔ (a ∈ s → f a = 1) :=
ite_eq_right_iff
@[simp, to_additive] lemma mul_indicator_eq_one :
mul_indicator s f = (λ x, 1) ↔ disjoint (mul_support f) s :=
by simp only [funext_iff, mul_indicator_apply_eq_one, set.disjoint_left, mem_mul_support,
not_imp_not]
@[simp, to_additive] lemma mul_indicator_eq_one' :
mul_indicator s f = 1 ↔ disjoint (mul_support f) s :=
mul_indicator_eq_one
@[simp, to_additive] lemma mul_support_mul_indicator :
function.mul_support (s.mul_indicator f) = s ∩ function.mul_support f :=
ext $ λ x, by simp [function.mem_mul_support, mul_indicator_apply_eq_one]
/-- If a multiplicative indicator function is not equal to one at a point, then that
point is in the set. -/
@[to_additive] lemma mem_of_mul_indicator_ne_one (h : mul_indicator s f a ≠ 1) : a ∈ s :=
not_imp_comm.1 (λ hn, mul_indicator_of_not_mem hn f) h
@[to_additive] lemma eq_on_mul_indicator : eq_on (mul_indicator s f) f s :=
λ x hx, mul_indicator_of_mem hx f
@[to_additive] lemma mul_support_mul_indicator_subset : mul_support (s.mul_indicator f) ⊆ s :=
λ x hx, hx.imp_symm (λ h, mul_indicator_of_not_mem h f)
@[simp, to_additive] lemma mul_indicator_mul_support : mul_indicator (mul_support f) f = f :=
mul_indicator_eq_self.2 subset.rfl
@[simp, to_additive] lemma mul_indicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) :
mul_indicator (range f) g ∘ f = g ∘ f :=
piecewise_range_comp _ _ _
@[to_additive] lemma mul_indicator_congr (h : eq_on f g s) :
mul_indicator s f = mul_indicator s g :=
funext $ λx, by { simp only [mul_indicator], split_ifs, { exact h h_1 }, refl }
@[simp, to_additive] lemma mul_indicator_univ (f : α → M) : mul_indicator (univ : set α) f = f :=
mul_indicator_eq_self.2 $ subset_univ _
@[simp, to_additive] lemma mul_indicator_empty (f : α → M) : mul_indicator (∅ : set α) f = λa, 1 :=
mul_indicator_eq_one.2 $ disjoint_empty _
variable (M)
@[simp, to_additive] lemma mul_indicator_one (s : set α) :
mul_indicator s (λx, (1:M)) = λx, (1:M) :=
mul_indicator_eq_one.2 $ by simp only [mul_support_one, empty_disjoint]
@[simp, to_additive] lemma mul_indicator_one' {s : set α} : s.mul_indicator (1 : α → M) = 1 :=
mul_indicator_one M s
variable {M}
@[to_additive] lemma mul_indicator_mul_indicator (s t : set α) (f : α → M) :
mul_indicator s (mul_indicator t f) = mul_indicator (s ∩ t) f :=
funext $ λx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {contextual := tt}} }
@[simp, to_additive] lemma mul_indicator_inter_mul_support (s : set α) (f : α → M) :
mul_indicator (s ∩ mul_support f) f = mul_indicator s f :=
by rw [← mul_indicator_mul_indicator, mul_indicator_mul_support]
@[to_additive] lemma comp_mul_indicator (h : M → β) (f : α → M) {s : set α} {x : α} :
h (s.mul_indicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x :=
s.apply_piecewise _ _ (λ _, h)
@[to_additive] lemma mul_indicator_comp_right {s : set α} (f : β → α) {g : α → M} {x : β} :
mul_indicator (f ⁻¹' s) (g ∘ f) x = mul_indicator s g (f x) :=
by { simp only [mul_indicator], split_ifs; refl }
@[to_additive] lemma mul_indicator_comp_of_one {g : M → N} (hg : g 1 = 1) :
mul_indicator s (g ∘ f) = g ∘ (mul_indicator s f) :=
begin
funext,
simp only [mul_indicator],
split_ifs; simp [*]
end
@[to_additive] lemma comp_mul_indicator_const (c : M) (f : M → N) (hf : f 1 = 1) :
(λ x, f (s.mul_indicator (λ x, c) x)) = s.mul_indicator (λ x, f c) :=
(mul_indicator_comp_of_one hf).symm
@[to_additive] lemma mul_indicator_preimage (s : set α) (f : α → M) (B : set M) :
(mul_indicator s f)⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) :=
piecewise_preimage s f 1 B
@[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set α) (f : α → M)
{t : set M} (ht : (1:M) ∉ t) :
(mul_indicator s f)⁻¹' t = f ⁻¹' t ∩ s :=
by simp [mul_indicator_preimage, pi.one_def, set.preimage_const_of_not_mem ht]
@[to_additive] lemma mem_range_mul_indicator {r : M} {s : set α} {f : α → M} :
r ∈ range (mul_indicator s f) ↔ (r = 1 ∧ s ≠ univ) ∨ (r ∈ f '' s) :=
by simp [mul_indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm,
@eq_comm _ r 1]
@[to_additive] lemma mul_indicator_rel_mul_indicator {r : M → M → Prop} (h1 : r 1 1)
(ha : a ∈ s → r (f a) (g a)) :
r (mul_indicator s f a) (mul_indicator s g a) :=
by { simp only [mul_indicator], split_ifs with has has, exacts [ha has, h1] }
end has_one
section monoid
variables [mul_one_class M] {s t : set α} {f g : α → M} {a : α}
@[to_additive] lemma mul_indicator_union_mul_inter_apply (f : α → M) (s t : set α) (a : α) :
mul_indicator (s ∪ t) f a * mul_indicator (s ∩ t) f a =
mul_indicator s f a * mul_indicator t f a :=
by by_cases hs : a ∈ s; by_cases ht : a ∈ t; simp *
@[to_additive] lemma mul_indicator_union_mul_inter (f : α → M) (s t : set α) :
mul_indicator (s ∪ t) f * mul_indicator (s ∩ t) f = mul_indicator s f * mul_indicator t f :=
funext $ mul_indicator_union_mul_inter_apply f s t
@[to_additive] lemma mul_indicator_union_of_not_mem_inter (h : a ∉ s ∩ t) (f : α → M) :
mul_indicator (s ∪ t) f a = mul_indicator s f a * mul_indicator t f a :=
by rw [← mul_indicator_union_mul_inter_apply f s t, mul_indicator_of_not_mem h, mul_one]
@[to_additive] lemma mul_indicator_union_of_disjoint (h : disjoint s t) (f : α → M) :
mul_indicator (s ∪ t) f = λa, mul_indicator s f a * mul_indicator t f a :=
funext $ λa, mul_indicator_union_of_not_mem_inter (λ ha, h ha) _
@[to_additive] lemma mul_indicator_mul (s : set α) (f g : α → M) :
mul_indicator s (λa, f a * g a) = λa, mul_indicator s f a * mul_indicator s g a :=
by { funext, simp only [mul_indicator], split_ifs, { refl }, rw mul_one }
@[simp, to_additive] lemma mul_indicator_compl_mul_self_apply (s : set α) (f : α → M) (a : α) :
mul_indicator sᶜ f a * mul_indicator s f a = f a :=
classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha])
@[simp, to_additive] lemma mul_indicator_compl_mul_self (s : set α) (f : α → M) :
mul_indicator sᶜ f * mul_indicator s f = f :=
funext $ mul_indicator_compl_mul_self_apply s f
@[simp, to_additive] lemma mul_indicator_self_mul_compl_apply (s : set α) (f : α → M) (a : α) :
mul_indicator s f a * mul_indicator sᶜ f a = f a :=
classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha])
@[simp, to_additive] lemma mul_indicator_self_mul_compl (s : set α) (f : α → M) :
mul_indicator s f * mul_indicator sᶜ f = f :=
funext $ mul_indicator_self_mul_compl_apply s f
@[to_additive] lemma mul_indicator_mul_eq_left {f g : α → M}
(h : disjoint (mul_support f) (mul_support g)) :
(mul_support f).mul_indicator (f * g) = f :=
begin
refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support,
have : g x = 1, from nmem_mul_support.1 (disjoint_left.1 h hx),
rw [pi.mul_apply, this, mul_one]
end
@[to_additive] lemma mul_indicator_mul_eq_right {f g : α → M}
(h : disjoint (mul_support f) (mul_support g)) :
(mul_support g).mul_indicator (f * g) = g :=
begin
refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support,
have : f x = 1, from nmem_mul_support.1 (disjoint_right.1 h hx),
rw [pi.mul_apply, this, one_mul]
end
/-- `set.mul_indicator` as a `monoid_hom`. -/
@[to_additive "`set.indicator` as an `add_monoid_hom`."]
def mul_indicator_hom {α} (M) [mul_one_class M] (s : set α) : (α → M) →* (α → M) :=
{ to_fun := mul_indicator s,
map_one' := mul_indicator_one M s,
map_mul' := mul_indicator_mul s }
end monoid
section distrib_mul_action
variables {A : Type*} [add_monoid A] [monoid M] [distrib_mul_action M A]
lemma indicator_smul (s : set α) (r : M) (f : α → A) :
indicator s (λ (x : α), r • f x) = λ (x : α), r • indicator s f x :=
by { simp only [indicator], funext, split_ifs, refl, exact (smul_zero r).symm }
end distrib_mul_action
section group
variables {G : Type*} [group G] {s t : set α} {f g : α → G} {a : α}
@[to_additive] lemma mul_indicator_inv' (s : set α) (f : α → G) :
mul_indicator s (f⁻¹) = (mul_indicator s f)⁻¹ :=
(mul_indicator_hom G s).map_inv f
@[to_additive] lemma mul_indicator_inv (s : set α) (f : α → G) :
mul_indicator s (λa, (f a)⁻¹) = λa, (mul_indicator s f a)⁻¹ :=
mul_indicator_inv' s f
lemma indicator_sub {G} [add_group G] (s : set α) (f g : α → G) :
indicator s (λa, f a - g a) = λa, indicator s f a - indicator s g a :=
(indicator_hom G s).map_sub f g
@[to_additive indicator_compl'] lemma mul_indicator_compl (s : set α) (f : α → G) :
mul_indicator sᶜ f = f * (mul_indicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq $ s.mul_indicator_compl_mul_self f
lemma indicator_compl {G} [add_group G] (s : set α) (f : α → G) :
indicator sᶜ f = f - indicator s f :=
by rw [sub_eq_add_neg, indicator_compl']
@[to_additive indicator_diff'] lemma mul_indicator_diff (h : s ⊆ t) (f : α → G) :
mul_indicator (t \ s) f = mul_indicator t f * (mul_indicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq $ by rw [pi.mul_def, ← mul_indicator_union_of_disjoint disjoint_diff.symm f,
diff_union_self, union_eq_self_of_subset_right h]
lemma indicator_diff {G : Type*} [add_group G] {s t : set α} (h : s ⊆ t) (f : α → G) :
indicator (t \ s) f = indicator t f - indicator s f :=
by rw [indicator_diff' h, sub_eq_add_neg]
end group
section comm_monoid
variables [comm_monoid M]
/-- Consider a product of `g i (f i)` over a `finset`. Suppose `g` is a
function such as `pow`, which maps a second argument of `1` to
`1`. Then if `f` is replaced by the corresponding multiplicative indicator
function, the `finset` may be replaced by a possibly larger `finset`
without changing the value of the sum. -/
@[to_additive] lemma prod_mul_indicator_subset_of_eq_one [has_one N] (f : α → N)
(g : α → N → M) {s t : finset α} (h : s ⊆ t) (hg : ∀ a, g a 1 = 1) :
∏ i in s, g i (f i) = ∏ i in t, g i (mul_indicator ↑s f i) :=
begin
rw ← finset.prod_subset h _,
{ apply finset.prod_congr rfl,
intros i hi,
congr,
symmetry,
exact mul_indicator_of_mem hi _ },
{ refine λ i hi hn, _,
convert hg i,
exact mul_indicator_of_not_mem hn _ }
end
/-- Consider a sum of `g i (f i)` over a `finset`. Suppose `g` is a
function such as multiplication, which maps a second argument of 0 to
0. (A typical use case would be a weighted sum of `f i * h i` or `f i
• h i`, where `f` gives the weights that are multiplied by some other
function `h`.) Then if `f` is replaced by the corresponding indicator
function, the `finset` may be replaced by a possibly larger `finset`
without changing the value of the sum. -/
add_decl_doc set.sum_indicator_subset_of_eq_zero
@[to_additive] lemma prod_mul_indicator_subset (f : α → M) {s t : finset α} (h : s ⊆ t) :
∏ i in s, f i = ∏ i in t, mul_indicator ↑s f i :=
prod_mul_indicator_subset_of_eq_one _ (λ a b, b) h (λ _, rfl)
/-- Summing an indicator function over a possibly larger `finset` is
the same as summing the original function over the original
`finset`. -/
add_decl_doc sum_indicator_subset
@[to_additive] lemma mul_indicator_finset_prod (I : finset ι) (s : set α) (f : ι → α → M) :
mul_indicator s (∏ i in I, f i) = ∏ i in I, mul_indicator s (f i) :=
(mul_indicator_hom M s).map_prod _ _
@[to_additive] lemma mul_indicator_finset_bUnion {ι} (I : finset ι)
(s : ι → set α) {f : α → M} : (∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) →
mul_indicator (⋃ i ∈ I, s i) f = λ a, ∏ i in I, mul_indicator (s i) f a :=
begin
refine finset.induction_on I _ _,
{ intro h, funext, simp },
assume a I haI ih hI,
funext,
rw [finset.prod_insert haI, finset.set_bUnion_insert, mul_indicator_union_of_not_mem_inter, ih _],
{ assume i hi j hj hij,
exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij },
simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and],
assume hx a' ha',
refine disjoint_left.1 (hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _) hx,
exact (ne_of_mem_of_not_mem ha' haI).symm
end
end comm_monoid
section mul_zero_class
variables [mul_zero_class M] {s t : set α} {f g : α → M} {a : α}
lemma indicator_mul (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) = λa, indicator s f a * indicator s g a :=
by { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero }
lemma indicator_mul_left (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) a = indicator s f a * g a :=
by { simp only [indicator], split_ifs, { refl }, rw [zero_mul] }
lemma indicator_mul_right (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) a = f a * indicator s g a :=
by { simp only [indicator], split_ifs, { refl }, rw [mul_zero] }
lemma inter_indicator_mul {t1 t2 : set α} (f g : α → M) (x : α) :
(t1 ∩ t2).indicator (λ x, f x * g x) x = t1.indicator f x * t2.indicator g x :=
by { rw [← set.indicator_indicator], simp [indicator] }
end mul_zero_class
section monoid_with_zero
variables [monoid_with_zero M]
lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} :
(s.prod t).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y :=
by simp [indicator, ← ite_and]
end monoid_with_zero
section order
variables [has_one M] [preorder M] {s t : set α} {f g : α → M} {a : α} {y : M}
@[to_additive] lemma mul_indicator_apply_le' (hfg : a ∈ s → f a ≤ y) (hg : a ∉ s → 1 ≤ y) :
mul_indicator s f a ≤ y :=
if ha : a ∈ s then by simpa [ha] using hfg ha else by simpa [ha] using hg ha
@[to_additive] lemma mul_indicator_le' (hfg : ∀ a ∈ s, f a ≤ g a) (hg : ∀ a ∉ s, 1 ≤ g a) :
mul_indicator s f ≤ g :=
λ a, mul_indicator_apply_le' (hfg _) (hg _)
@[to_additive] lemma le_mul_indicator_apply {y} (hfg : a ∈ s → y ≤ g a) (hf : a ∉ s → y ≤ 1) :
y ≤ mul_indicator s g a :=
@mul_indicator_apply_le' α (order_dual M) ‹_› _ _ _ _ _ hfg hf
@[to_additive] lemma le_mul_indicator (hfg : ∀ a ∈ s, f a ≤ g a) (hf : ∀ a ∉ s, f a ≤ 1) :
f ≤ mul_indicator s g :=
λ a, le_mul_indicator_apply (hfg _) (hf _)
@[to_additive indicator_apply_nonneg]
lemma one_le_mul_indicator_apply (h : a ∈ s → 1 ≤ f a) : 1 ≤ mul_indicator s f a :=
le_mul_indicator_apply h (λ _, le_rfl)
@[to_additive indicator_nonneg]
lemma one_le_mul_indicator (h : ∀ a ∈ s, 1 ≤ f a) (a : α) : 1 ≤ mul_indicator s f a :=
one_le_mul_indicator_apply (h a)
@[to_additive] lemma mul_indicator_apply_le_one (h : a ∈ s → f a ≤ 1) : mul_indicator s f a ≤ 1 :=
mul_indicator_apply_le' h (λ _, le_rfl)
@[to_additive] lemma mul_indicator_le_one (h : ∀ a ∈ s, f a ≤ 1) (a : α) :
mul_indicator s f a ≤ 1 :=
mul_indicator_apply_le_one (h a)
@[to_additive] lemma mul_indicator_le_mul_indicator (h : f a ≤ g a) :
mul_indicator s f a ≤ mul_indicator s g a :=
mul_indicator_rel_mul_indicator (le_refl _) (λ _, h)
attribute [mono] mul_indicator_le_mul_indicator indicator_le_indicator
@[to_additive] lemma mul_indicator_le_mul_indicator_of_subset (h : s ⊆ t) (hf : ∀ a, 1 ≤ f a)
(a : α) :
mul_indicator s f a ≤ mul_indicator t f a :=
mul_indicator_apply_le' (λ ha, le_mul_indicator_apply (λ _, le_rfl) (λ hat, (hat $ h ha).elim))
(λ ha, one_le_mul_indicator_apply (λ _, hf _))
@[to_additive] lemma mul_indicator_le_self' (hf : ∀ x ∉ s, 1 ≤ f x) : mul_indicator s f ≤ f :=
mul_indicator_le' (λ _ _, le_refl _) hf
@[to_additive] lemma mul_indicator_Union_apply {ι M} [complete_lattice M] [has_one M]
(h1 : (⊥:M) = 1) (s : ι → set α) (f : α → M) (x : α) :
mul_indicator (⋃ i, s i) f x = ⨆ i, mul_indicator (s i) f x :=
begin
by_cases hx : x ∈ ⋃ i, s i,
{ rw [mul_indicator_of_mem hx],
rw [mem_Union] at hx,
refine le_antisymm _ (supr_le $ λ i, mul_indicator_le_self' (λ x hx, h1 ▸ bot_le) x),
rcases hx with ⟨i, hi⟩,
exact le_supr_of_le i (ge_of_eq $ mul_indicator_of_mem hi _) },
{ rw [mul_indicator_of_not_mem hx],
simp only [mem_Union, not_exists] at hx,
simp [hx, ← h1] }
end
end order
section canonically_ordered_monoid
variables [canonically_ordered_monoid M]
@[to_additive] lemma mul_indicator_le_self (s : set α) (f : α → M) :
mul_indicator s f ≤ f :=
mul_indicator_le_self' $ λ _ _, one_le _
@[to_additive] lemma mul_indicator_apply_le {a : α} {s : set α} {f g : α → M}
(hfg : a ∈ s → f a ≤ g a) :
mul_indicator s f a ≤ g a :=
mul_indicator_apply_le' hfg $ λ _, one_le _
@[to_additive] lemma mul_indicator_le {s : set α} {f g : α → M} (hfg : ∀ a ∈ s, f a ≤ g a) :
mul_indicator s f ≤ g :=
mul_indicator_le' hfg $ λ _ _, one_le _
end canonically_ordered_monoid
end set
@[to_additive] lemma monoid_hom.map_mul_indicator {M N : Type*} [monoid M] [monoid N] (f : M →* N)
(s : set α) (g : α → M) (x : α) :
f (s.mul_indicator g x) = s.mul_indicator (f ∘ g) x :=
congr_fun (set.mul_indicator_comp_of_one f.map_one).symm x
|
95c7df3f64a4c9ff21d8c50f79368092e3bad6f3 | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/data/set/finite.lean | 5c6623bc191abc08d032d846bc15986b48fb7584 | [
"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 | 21,331 | 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
Finite sets.
-/
import logic.function
import data.nat.basic data.fintype data.set.lattice data.set.function
open set lattice function
universes u v w x
variables {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace set
/-- A set is finite if the subtype is a fintype, i.e. there is a
list that enumerates its members. -/
def finite (s : set α) : Prop := nonempty (fintype s)
/-- A set is infinite if it is not finite. -/
def infinite (s : set α) : Prop := ¬ finite s
/-- Construct a fintype from a finset with the same elements. -/
def fintype_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : fintype p :=
fintype.subtype s H
@[simp] theorem card_fintype_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) :
@fintype.card p (fintype_of_finset s H) = s.card :=
fintype.subtype_card s H
theorem card_fintype_of_finset' {p : set α} (s : finset α)
(H : ∀ x, x ∈ s ↔ x ∈ p) [fintype p] : fintype.card p = s.card :=
by rw ← card_fintype_of_finset s H; congr
/-- 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
noncomputable instance finite.fintype {s : set α} (h : finite s) : fintype s :=
classical.choice h
/-- Get a finset from a finite set -/
noncomputable def finite.to_finset {s : set α} (h : finite s) : finset α :=
@set.to_finset _ _ (finite.fintype h)
@[simp] theorem finite.mem_to_finset {s : set α} {h : finite s} {a : α} : a ∈ h.to_finset ↔ a ∈ s :=
@mem_to_finset _ _ (finite.fintype h) _
lemma finite.coe_to_finset {α} {s : set α} (h : finite s) : ↑h.to_finset = s :=
by { ext, apply mem_to_finset }
lemma exists_finset_of_finite {s : set α} (h : finite s) : ∃(s' : finset α), ↑s' = s :=
⟨h.to_finset, h.coe_to_finset⟩
theorem finite.exists_finset {s : set α} : finite s →
∃ s' : finset α, ∀ a : α, a ∈ s' ↔ a ∈ s
| ⟨h⟩ := by exactI ⟨to_finset s, λ _, mem_to_finset⟩
theorem finite.exists_finset_coe {s : set α} (hs : finite s) :
∃ s' : finset α, ↑s' = s :=
let ⟨s', h⟩ := hs.exists_finset in ⟨s', set.ext h⟩
theorem finite_mem_finset (s : finset α) : finite {a | a ∈ s} :=
⟨fintype_of_finset s (λ _, iff.rfl)⟩
theorem finite.of_fintype [fintype α] (s : set α) : finite s :=
by classical; exact ⟨set_fintype s⟩
instance decidable_mem_of_fintype [decidable_eq α] (s : set α) [fintype s] (a) : decidable (a ∈ s) :=
decidable_of_iff _ mem_to_finset
instance fintype_empty : fintype (∅ : set α) :=
fintype_of_finset ∅ $ by simp
theorem empty_card : fintype.card (∅ : set α) = 0 := rfl
@[simp] theorem empty_card' {h : fintype.{u} (∅ : set α)} :
@fintype.card (∅ : set α) h = 0 :=
eq.trans (by congr) empty_card
@[simp] theorem finite_empty : @finite α ∅ := ⟨set.fintype_empty⟩
def fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) : fintype (insert a s : set α) :=
fintype_of_finset ⟨a :: s.to_finset.1,
multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2⟩ $ by simp
theorem card_fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) :
@fintype.card _ (fintype_insert' s h) = fintype.card s + 1 :=
by rw [fintype_insert', card_fintype_of_finset];
simp [finset.card, to_finset]; refl
@[simp] theorem card_insert {a : α} (s : set α)
[fintype s] (h : a ∉ s) {d : fintype.{u} (insert a s : set α)} :
@fintype.card _ d = fintype.card s + 1 :=
by rw ← card_fintype_insert' s h; congr
lemma card_image_of_inj_on {s : set α} [fintype s]
{f : α → β} [fintype (f '' s)] (H : ∀x∈s, ∀y∈s, f x = f y → x = y) :
fintype.card (f '' s) = fintype.card s :=
by haveI := classical.prop_decidable; exact
calc fintype.card (f '' s) = (s.to_finset.image f).card : card_fintype_of_finset' _ (by simp)
... = s.to_finset.card : finset.card_image_of_inj_on
(λ x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy)
... = fintype.card s : (card_fintype_of_finset' _ (λ a, mem_to_finset)).symm
lemma card_image_of_injective (s : set α) [fintype s]
{f : α → β} [fintype (f '' s)] (H : function.injective f) :
fintype.card (f '' s) = fintype.card s :=
card_image_of_inj_on $ λ _ _ _ _ h, H h
instance fintype_insert [decidable_eq α] (a : α) (s : set α) [fintype s] : fintype (insert a s : set α) :=
if h : a ∈ s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)]
else fintype_insert' _ h
@[simp] theorem finite_insert (a : α) {s : set α} : finite s → finite (insert a s)
| ⟨h⟩ := ⟨@set.fintype_insert _ (classical.dec_eq α) _ _ h⟩
lemma to_finset_insert [decidable_eq α] {a : α} {s : set α} (hs : finite s) :
(finite_insert a hs).to_finset = insert a hs.to_finset :=
finset.ext.mpr $ by simp
@[elab_as_eliminator]
theorem finite.induction_on {C : set α → Prop} {s : set α} (h : finite s)
(H0 : C ∅) (H1 : ∀ {a s}, a ∉ s → finite s → C s → C (insert a s)) : C s :=
let ⟨t⟩ := h in by exactI
match s.to_finset, @mem_to_finset _ s _ with
| ⟨l, nd⟩, al := begin
change ∀ a, a ∈ l ↔ a ∈ s at al,
clear _let_match _match t h, revert s nd al,
refine multiset.induction_on l _ (λ a l IH, _); intros s nd al,
{ rw show s = ∅, from eq_empty_iff_forall_not_mem.2 (by simpa using al),
exact H0 },
{ rw ← show insert a {x | x ∈ l} = s, from set.ext (by simpa using al),
cases multiset.nodup_cons.1 nd with m nd',
refine H1 _ ⟨finset.subtype.fintype ⟨l, nd'⟩⟩ (IH nd' (λ _, iff.rfl)),
exact m }
end
end
@[elab_as_eliminator]
theorem finite.dinduction_on {C : ∀s:set α, finite s → Prop} {s : set α} (h : finite s)
(H0 : C ∅ finite_empty)
(H1 : ∀ {a s}, a ∉ s → ∀h:finite s, C s h → C (insert a s) (finite_insert a h)) :
C s h :=
have ∀h:finite s, C s h,
from finite.induction_on h (assume h, H0) (assume a s has hs ih h, H1 has hs (ih _)),
this h
instance fintype_singleton (a : α) : fintype ({a} : set α) :=
fintype_insert' _ (not_mem_empty _)
@[simp] theorem card_singleton (a : α) :
fintype.card ({a} : set α) = 1 :=
by rw [show fintype.card ({a} : set α) = _, from
card_fintype_insert' ∅ (not_mem_empty a)]; refl
@[simp] theorem finite_singleton (a : α) : finite ({a} : set α) :=
⟨set.fintype_singleton _⟩
instance fintype_pure : ∀ a : α, fintype (pure a : set α) :=
set.fintype_singleton
theorem finite_pure (a : α) : finite (pure a : set α) :=
⟨set.fintype_pure a⟩
instance fintype_univ [fintype α] : fintype (@univ α) :=
fintype_of_finset finset.univ $ λ _, iff_true_intro (finset.mem_univ _)
theorem finite_univ [fintype α] : finite (@univ α) := ⟨set.fintype_univ⟩
instance fintype_union [decidable_eq α] (s t : set α) [fintype s] [fintype t] : fintype (s ∪ t : set α) :=
fintype_of_finset (s.to_finset ∪ t.to_finset) $ by simp
theorem finite_union {s t : set α} : finite s → finite t → finite (s ∪ t)
| ⟨hs⟩ ⟨ht⟩ := ⟨@set.fintype_union _ (classical.dec_eq α) _ _ hs ht⟩
instance fintype_sep (s : set α) (p : α → Prop) [fintype s] [decidable_pred p] : fintype ({a ∈ s | p a} : set α) :=
fintype_of_finset (s.to_finset.filter p) $ by simp
instance fintype_inter (s t : set α) [fintype s] [decidable_pred t] : fintype (s ∩ t : set α) :=
set.fintype_sep s t
def fintype_subset (s : set α) {t : set α} [fintype s] [decidable_pred t] (h : t ⊆ s) : fintype t :=
by rw ← inter_eq_self_of_subset_right h; apply_instance
theorem finite_subset {s : set α} : finite s → ∀ {t : set α}, t ⊆ s → finite t
| ⟨hs⟩ t h := ⟨@set.fintype_subset _ _ _ hs (classical.dec_pred t) h⟩
instance fintype_image [decidable_eq β] (s : set α) (f : α → β) [fintype s] : fintype (f '' s) :=
fintype_of_finset (s.to_finset.image f) $ by simp
instance fintype_range [decidable_eq β] (f : α → β) [fintype α] : fintype (range f) :=
fintype_of_finset (finset.univ.image f) $ by simp [range]
theorem finite_range (f : α → β) [fintype α] : finite (range f) :=
by haveI := classical.dec_eq β; exact ⟨by apply_instance⟩
theorem finite_image {s : set α} (f : α → β) : finite s → finite (f '' s)
| ⟨h⟩ := ⟨@set.fintype_image _ _ (classical.dec_eq β) _ _ h⟩
instance fintype_map {α β} [decidable_eq β] :
∀ (s : set α) (f : α → β) [fintype s], fintype (f <$> s) := set.fintype_image
theorem finite_map {α β} {s : set α} :
∀ (f : α → β), finite s → finite (f <$> s) := finite_image
def fintype_of_fintype_image [decidable_eq β] (s : set α)
{f : α → β} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s :=
fintype_of_finset ⟨_, @multiset.nodup_filter_map β α g _
(@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2⟩ $ λ a,
begin
suffices : (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s,
by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc],
rw exists_swap,
suffices : (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s, {simpa [and.comm, and.left_comm, and.assoc]},
simp [I _, (injective_of_partial_inv I).eq_iff]
end
theorem finite_of_finite_image_on {s : set α} {f : α → β} (hi : set.inj_on f s) :
finite (f '' s) → finite s | ⟨h⟩ :=
⟨@fintype.of_injective _ _ h (λa:s, ⟨f a.1, mem_image_of_mem f a.2⟩) $
assume a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext.1 eq⟩
theorem finite_image_iff_on {s : set α} {f : α → β} (hi : inj_on f s) :
finite (f '' s) ↔ finite s :=
⟨finite_of_finite_image_on hi, finite_image _⟩
theorem finite_of_finite_image {s : set α} {f : α → β} (I : set.inj_on f s) :
finite (f '' s) → finite s :=
finite_of_finite_image_on I
theorem finite_preimage {s : set β} {f : α → β}
(I : set.inj_on f (f⁻¹' s)) (h : finite s) : finite (f ⁻¹' s) :=
finite_of_finite_image I (finite_subset h (image_preimage_subset f s))
instance fintype_Union [decidable_eq α] {ι : Type*} [fintype ι]
(f : ι → set α) [∀ i, fintype (f i)] : fintype (⋃ i, f i) :=
fintype_of_finset (finset.univ.bind (λ i, (f i).to_finset)) $ by simp
theorem finite_Union {ι : Type*} [fintype ι] {f : ι → set α} (H : ∀i, finite (f i)) : finite (⋃ i, f i) :=
⟨@set.fintype_Union _ (classical.dec_eq α) _ _ _ (λ i, finite.fintype (H i))⟩
def fintype_bUnion [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) (H : ∀ i ∈ s, fintype (f i)) : fintype (⋃ i ∈ s, f i) :=
by rw bUnion_eq_Union; exact
@set.fintype_Union _ _ _ _ _ (by rintro ⟨i, hi⟩; exact H i hi)
instance fintype_bUnion' [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) [H : ∀ i, fintype (f i)] : fintype (⋃ i ∈ s, f i) :=
fintype_bUnion _ (λ i _, H i)
theorem finite_sUnion {s : set (set α)} (h : finite s) (H : ∀t∈s, finite t) : finite (⋃₀ s) :=
by rw sUnion_eq_Union; haveI := finite.fintype h;
apply finite_Union; simpa using H
theorem finite_bUnion {α} {ι : Type*} {s : set ι} {f : ι → set α} :
finite s → (∀i, finite (f i)) → finite (⋃ i∈s, f i)
| ⟨hs⟩ h := by rw [bUnion_eq_Union]; exactI finite_Union (λ i, h _)
theorem finite_bUnion' {α} {ι : Type*} {s : set ι} (f : ι → set α) :
finite s → (∀i ∈ s, finite (f i)) → finite (⋃ i∈s, f i)
| ⟨hs⟩ h := by { rw [bUnion_eq_Union], exactI finite_Union (λ i, h i.1 i.2) }
instance fintype_lt_nat (n : ℕ) : fintype {i | i < n} :=
fintype_of_finset (finset.range n) $ by simp
instance fintype_le_nat (n : ℕ) : fintype {i | i ≤ n} :=
by simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1)
lemma finite_le_nat (n : ℕ) : finite {i | i ≤ n} := ⟨set.fintype_le_nat _⟩
lemma finite_lt_nat (n : ℕ) : finite {i | i < n} := ⟨set.fintype_lt_nat _⟩
instance fintype_prod (s : set α) (t : set β) [fintype s] [fintype t] : fintype (set.prod s t) :=
fintype_of_finset (s.to_finset.product t.to_finset) $ by simp
lemma finite_prod {s : set α} {t : set β} : finite s → finite t → finite (set.prod s t)
| ⟨hs⟩ ⟨ht⟩ := by exactI ⟨set.fintype_prod s t⟩
def fintype_bind {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) (H : ∀ a ∈ s, fintype (f a)) : fintype (s >>= f) :=
set.fintype_bUnion _ H
instance fintype_bind' {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) [H : ∀ a, fintype (f a)] : fintype (s >>= f) :=
fintype_bind _ _ (λ i _, H i)
theorem finite_bind {α β} {s : set α} {f : α → set β} :
finite s → (∀ a ∈ s, finite (f a)) → finite (s >>= f)
| ⟨hs⟩ H := ⟨@fintype_bind _ _ (classical.dec_eq β) _ hs _ (λ a ha, (H a ha).fintype)⟩
instance fintype_seq {α β : Type u} [decidable_eq β]
(f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f <*> s) :=
by rw seq_eq_bind_map; apply set.fintype_bind'
theorem finite_seq {α β : Type u} {f : set (α → β)} {s : set α} :
finite f → finite s → finite (f <*> s)
| ⟨hf⟩ ⟨hs⟩ := by { haveI := classical.dec_eq β, exactI ⟨set.fintype_seq _ _⟩ }
/-- There are finitely many subsets of a given finite set -/
lemma finite_subsets_of_finite {α : Type u} {a : set α} (h : finite a) : finite {b | b ⊆ a} :=
begin
-- we just need to translate the result, already known for finsets,
-- to the language of finite sets
let s := coe '' ((finset.powerset (finite.to_finset h)).to_set),
have : finite s := finite_image _ (finite_mem_finset _),
have : {b | b ⊆ a} ⊆ s :=
begin
assume b hb,
rw [set.mem_image],
rw [set.mem_set_of_eq] at hb,
let b' : finset α := finite.to_finset (finite_subset h hb),
have : b' ∈ (finset.powerset (finite.to_finset h)).to_set :=
show b' ∈ (finset.powerset (finite.to_finset h)),
by simp [b', finset.subset_iff]; exact hb,
have : coe b' = b := by ext; simp,
exact ⟨b', by assumption, by assumption⟩
end,
exact finite_subset ‹finite s› this
end
lemma exists_min [decidable_linear_order β] (s : set α) (f : α → β) (h1 : finite s)
(h : nonempty s) : ∃ a, a ∈ s ∧ ∀ b ∈ s, f a ≤ f b :=
begin
have := (finite.to_finset h1).exists_min f,
simp at this ⊢, unfreezeI, rcases h with ⟨⟨x, hx⟩⟩,
exact this x hx
end
end set
namespace finset
variables [decidable_eq β]
variables {s t u : finset α} {f : α → β} {a : α}
lemma finite_to_set (s : finset α) : set.finite (↑s : set α) :=
set.finite_mem_finset s
@[simp] lemma coe_bind {f : α → finset β} : ↑(s.bind f) = (⋃x ∈ (↑s : set α), ↑(f x) : set β) :=
by simp [set.ext_iff]
@[simp] lemma coe_to_finset {s : set α} {hs : set.finite s} : ↑(hs.to_finset) = s :=
by simp [set.ext_iff]
@[simp] lemma coe_to_finset' [decidable_eq α] (s : set α) [fintype s] : (↑s.to_finset : set α) = s :=
by ext; simp
end finset
namespace set
lemma finite_subset_Union {s : set α} (hs : finite s)
{ι} {t : ι → set α} (h : s ⊆ ⋃ i, t i) : ∃ I : set ι, finite I ∧ s ⊆ ⋃ i ∈ I, t i :=
begin
unfreezeI, cases hs,
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i, {simpa [subset_def] using h},
refine ⟨range f, finite_range f, _⟩,
rintro x hx,
simp,
exact ⟨_, ⟨_, hx, rfl⟩, hf ⟨x, hx⟩⟩
end
lemma finite_range_ite {p : α → Prop} [decidable_pred p] {f g : α → β} (hf : finite (range f))
(hg : finite (range g)) : finite (range (λ x, if p x then f x else g x)) :=
finite_subset (finite_union hf hg) range_ite_subset
lemma finite_range_const {c : β} : finite (range (λ x : α, c)) :=
finite_subset (finite_singleton c) range_const_subset
lemma range_find_greatest_subset {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ}:
range (λ x, nat.find_greatest (P x) b) ⊆ ↑(finset.range (b + 1)) :=
by { rw range_subset_iff, assume x, simp [nat.lt_succ_iff, nat.find_greatest_le] }
lemma finite_range_find_greatest {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ} :
finite (range (λ x, nat.find_greatest (P x) b)) :=
finite_subset (finset.finite_to_set $ finset.range (b + 1)) range_find_greatest_subset
lemma infinite_univ_nat : infinite (univ : set ℕ) :=
assume (h : finite (univ : set ℕ)),
let ⟨n, hn⟩ := finset.exists_nat_subset_range h.to_finset in
have n ∈ finset.range n, from finset.subset_iff.mpr hn $ by simp,
by simp * at *
lemma not_injective_nat_fintype [fintype α] [decidable_eq α] {f : ℕ → α} : ¬ injective f :=
assume (h : injective f),
have finite (f '' univ),
from finite_subset (finset.finite_to_set $ fintype.elems α) (assume a h, fintype.complete a),
have finite (univ : set ℕ), from finite_of_finite_image (set.inj_on_of_injective _ h) this,
infinite_univ_nat this
lemma not_injective_int_fintype [fintype α] [decidable_eq α] {f : ℤ → α} : ¬ injective f :=
assume hf,
have injective (f ∘ (coe : ℕ → ℤ)), from injective_comp hf $ assume i j, int.of_nat_inj,
not_injective_nat_fintype this
lemma card_lt_card {s t : set α} [fintype s] [fintype t] (h : s ⊂ t) :
fintype.card s < fintype.card t :=
begin
haveI := classical.prop_decidable,
rw [← finset.coe_to_finset' s, ← finset.coe_to_finset' t, finset.coe_ssubset] at h,
rw [card_fintype_of_finset' _ (λ x, mem_to_finset),
card_fintype_of_finset' _ (λ x, mem_to_finset)],
exact finset.card_lt_card h,
end
lemma card_le_of_subset {s t : set α} [fintype s] [fintype t] (hsub : s ⊆ t) :
fintype.card s ≤ fintype.card t :=
calc fintype.card s = s.to_finset.card : set.card_fintype_of_finset' _ (by simp)
... ≤ t.to_finset.card : finset.card_le_of_subset (λ x hx, by simp [set.subset_def, *] at *)
... = fintype.card t : eq.symm (set.card_fintype_of_finset' _ (by simp))
lemma eq_of_subset_of_card_le {s t : set α} [fintype s] [fintype t]
(hsub : s ⊆ t) (hcard : fintype.card t ≤ fintype.card s) : s = t :=
classical.by_contradiction (λ h, lt_irrefl (fintype.card t)
(have fintype.card s < fintype.card t := set.card_lt_card ⟨hsub, h⟩,
by rwa [le_antisymm (card_le_of_subset hsub) hcard] at this))
lemma card_range_of_injective [fintype α] {f : α → β} (hf : injective f)
[fintype (range f)] : fintype.card (range f) = fintype.card α :=
eq.symm $ fintype.card_congr (@equiv.of_bijective _ _ (λ a : α, show range f, from ⟨f a, a, rfl⟩)
⟨λ x y h, hf $ subtype.mk.inj h, λ b, let ⟨a, ha⟩ := b.2 in ⟨a, by simp *⟩⟩)
lemma finite.exists_maximal_wrt [partial_order β]
(f : α → β) (s : set α) (h : set.finite s) : s ≠ ∅ → ∃a∈s, ∀a'∈s, f a ≤ f a' → f a = f a' :=
begin
classical,
refine h.induction_on _ _,
{ assume h, contradiction },
assume a s his _ ih _,
by_cases s = ∅,
{ use a, simp [h] },
rcases ih h with ⟨b, hb, ih⟩,
by_cases f b ≤ f a,
{ refine ⟨a, set.mem_insert _ _, assume c hc hac, le_antisymm hac _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ refl },
{ rwa [← ih c hcs (le_trans h hac)] } },
{ refine ⟨b, set.mem_insert_of_mem _ hb, assume c hc hbc, _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ exact (h hbc).elim },
{ exact ih c hcs hbc } }
end
end set
namespace finset
section preimage
noncomputable def preimage {f : α → β} (s : finset β)
(hf : set.inj_on f (f ⁻¹' ↑s)) : finset α :=
set.finite.to_finset (set.finite_preimage hf (set.finite_mem_finset s))
@[simp] lemma mem_preimage {f : α → β} {s : finset β} {hf : set.inj_on f (f ⁻¹' ↑s)} {x : α} :
x ∈ preimage s hf ↔ f x ∈ s :=
by simp [preimage]
@[simp] lemma coe_preimage {f : α → β} (s : finset β)
(hf : set.inj_on f (f ⁻¹' ↑s)) : (↑(preimage s hf) : set α) = f ⁻¹' ↑s :=
by simp [set.ext_iff]
lemma image_preimage [decidable_eq β] (f : α → β) (s : finset β)
(hf : set.bij_on f (f ⁻¹' s.to_set) s.to_set) :
image f (preimage s (set.inj_on_of_bij_on hf)) = s :=
finset.coe_inj.1 $
suffices f '' (f ⁻¹' ↑s) = ↑s, by simpa,
(set.subset.antisymm (image_preimage_subset _ _) hf.2.2)
end preimage
@[to_additive]
lemma prod_preimage [comm_monoid β] (f : α → γ) (s : finset γ)
(hf : set.bij_on f (f ⁻¹' ↑s) ↑s) (g : γ → β) :
(preimage s (set.inj_on_of_bij_on hf)).prod (g ∘ f) = s.prod g :=
by classical;
calc
(preimage s (set.inj_on_of_bij_on hf)).prod (g ∘ f)
= (image f (preimage s (set.inj_on_of_bij_on hf))).prod g :
begin
rw prod_image,
intros x hx y hy hxy,
apply set.inj_on_of_bij_on hf,
repeat { try { rw mem_preimage at hx hy,
rw [set.mem_preimage, mem_coe] },
assumption },
end
... = s.prod g : by rw image_preimage
end finset
|
e990eb16d34860796201138076c3ae797468c270 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/algebra/geom_sum.lean | 8bf0634dd7fab97a3bedcb559c429047bc7848f3 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 7,399 | lean | /-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
Sums of finite geometric series
-/
import algebra.group_with_zero_power
import algebra.big_operators
universe u
variable {α : Type u}
open finset
open_locale big_operators
/-- Sum of the finite geometric series $\sum_{i=0}^{n-1} x^i$. -/
def geom_series [semiring α] (x : α) (n : ℕ) :=
∑ i in range n, x ^ i
theorem geom_series_def [semiring α] (x : α) (n : ℕ) :
geom_series x n = ∑ i in range n, x ^ i := rfl
@[simp] theorem geom_series_zero [semiring α] (x : α) :
geom_series x 0 = 0 := rfl
@[simp] theorem geom_series_one [semiring α] (x : α) :
geom_series x 1 = 1 :=
by { rw [geom_series_def, sum_range_one, pow_zero] }
/-- Sum of the finite geometric series $\sum_{i=0}^{n-1} x^i y^{n-1-i}$. -/
def geom_series₂ [semiring α] (x y : α) (n : ℕ) :=
∑ i in range n, x ^ i * (y ^ (n - 1 - i))
theorem geom_series₂_def [semiring α] (x y : α) (n : ℕ) :
geom_series₂ x y n = ∑ i in range n, x ^ i * y ^ (n - 1 - i) := rfl
@[simp] theorem geom_series₂_zero [semiring α] (x y : α) :
geom_series₂ x y 0 = 0 := rfl
@[simp] theorem geom_series₂_one [semiring α] (x y : α) :
geom_series₂ x y 1 = 1 :=
by { have : 1 - 1 - 0 = 0 := rfl,
rw [geom_series₂_def, sum_range_one, this, pow_zero, pow_zero, mul_one] }
@[simp] theorem geom_series₂_with_one [semiring α] (x : α) (n : ℕ) :
geom_series₂ x 1 n = geom_series x n :=
sum_congr rfl (λ i _, by { rw [one_pow, mul_one] })
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
protected theorem commute.geom_sum₂_mul_add [semiring α] {x y : α} (h : commute x y) (n : ℕ) :
(geom_series₂ (x + y) y n) * x + y ^ n = (x + y) ^ n :=
begin
let f := λ (m i : ℕ), (x + y) ^ i * y ^ (m - 1 - i),
change (∑ i in range n, (f n) i) * x + y ^ n = (x + y) ^ n,
induction n with n ih,
{ rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] },
{ have f_last : f (n + 1) n = (x + y) ^ n :=
by { dsimp [f],
rw [nat.sub_sub, nat.add_comm, nat.sub_self, pow_zero, mul_one] },
have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i :=
λ i hi, by {
dsimp [f],
have : commute y ((x + y) ^ i) :=
(h.symm.add_right (commute.refl y)).pow_right i,
rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ y (n - 1 - i)],
congr' 2,
rw [nat.add_sub_cancel, nat.sub_sub, add_comm 1 i],
have : i + 1 + (n - (i + 1)) = n := nat.add_sub_of_le (mem_range.mp hi),
rw [add_comm (i + 1)] at this,
rw [← this, nat.add_sub_cancel, add_comm i 1, ← add_assoc,
nat.add_sub_cancel] },
rw [pow_succ (x + y), add_mul, sum_range_succ, f_last, add_mul, add_assoc],
rw [(((commute.refl x).add_right h).pow_right n).eq],
congr' 1,
rw[sum_congr rfl f_succ, ← mul_sum, pow_succ y],
rw[mul_assoc, ← mul_add y, ih] }
end
theorem geom_series₂_self {α : Type*} [comm_ring α] (x : α) (n : ℕ) :
geom_series₂ x x n = n * x ^ (n-1) :=
calc ∑ i in finset.range n, x ^ i * x ^ (n - 1 - i)
= ∑ i in finset.range n, x ^ (i + (n - 1 - i)) : by simp_rw [← pow_add]
... = ∑ i in finset.range n, x ^ (n - 1) : finset.sum_congr rfl
(λ i hi, congr_arg _ $ nat.add_sub_cancel' $ nat.le_pred_of_lt $ finset.mem_range.1 hi)
... = (finset.range n).card •ℕ (x ^ (n - 1)) : finset.sum_const _
... = n * x ^ (n - 1) : by rw [finset.card_range, nsmul_eq_mul]
/-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/
theorem geom_sum₂_mul_add [comm_semiring α] (x y : α) (n : ℕ) :
(geom_series₂ (x + y) y n) * x + y ^ n = (x + y) ^ n :=
(commute.all x y).geom_sum₂_mul_add n
theorem geom_sum_mul_add [semiring α] (x : α) (n : ℕ) :
(geom_series (x + 1) n) * x + 1 = (x + 1) ^ n :=
begin
have := (commute.one_right x).geom_sum₂_mul_add n,
rw [one_pow, geom_series₂_with_one] at this,
exact this
end
theorem geom_sum₂_mul_comm [ring α] {x y : α} (h : commute x y) (n : ℕ) :
(geom_series₂ x y n) * (x - y) = x ^ n - y ^ n :=
begin
have := (h.sub_left (commute.refl y)).geom_sum₂_mul_add n,
rw [sub_add_cancel] at this,
rw [← this, add_sub_cancel]
end
theorem geom_sum₂_mul [comm_ring α] (x y : α) (n : ℕ) :
(geom_series₂ x y n) * (x - y) = x ^ n - y ^ n :=
geom_sum₂_mul_comm (commute.all x y) n
theorem geom_sum_mul [ring α] (x : α) (n : ℕ) :
(geom_series x n) * (x - 1) = x ^ n - 1 :=
begin
have := geom_sum₂_mul_comm (commute.one_right x) n,
rw [one_pow, geom_series₂_with_one] at this,
exact this
end
theorem geom_sum_mul_neg [ring α] (x : α) (n : ℕ) :
(geom_series x n) * (1 - x) = 1 - x ^ n :=
begin
have := congr_arg has_neg.neg (geom_sum_mul x n),
rw [neg_sub, ← mul_neg_eq_neg_mul_symm, neg_sub] at this,
exact this
end
theorem geom_sum [division_ring α] {x : α} (h : x ≠ 1) (n : ℕ) :
(geom_series x n) = (x ^ n - 1) / (x - 1) :=
have x - 1 ≠ 0, by simp [*, -sub_eq_add_neg, sub_eq_iff_eq_add] at *,
by rw [← geom_sum_mul, mul_div_cancel _ this]
theorem geom_sum_Ico_mul [ring α] (x : α) {m n : ℕ} (hmn : m ≤ n) :
(∑ i in finset.Ico m n, x ^ i) * (x - 1) = x^n - x^m :=
by rw [sum_Ico_eq_sub _ hmn, ← geom_series_def, ← geom_series_def, sub_mul,
geom_sum_mul, geom_sum_mul, sub_sub_sub_cancel_right]
theorem geom_sum_Ico_mul_neg [ring α] (x : α) {m n : ℕ} (hmn : m ≤ n) :
(∑ i in finset.Ico m n, x ^ i) * (1 - x) = x^m - x^n :=
by rw [sum_Ico_eq_sub _ hmn, ← geom_series_def, ← geom_series_def, sub_mul,
geom_sum_mul_neg, geom_sum_mul_neg, sub_sub_sub_cancel_left]
theorem geom_sum_Ico [division_ring α] {x : α} (hx : x ≠ 1) {m n : ℕ} (hmn : m ≤ n) :
∑ i in finset.Ico m n, x ^ i = (x ^ n - x ^ m) / (x - 1) :=
by simp only [sum_Ico_eq_sub _ hmn, (geom_series_def _ _).symm, geom_sum hx, div_sub_div_same,
sub_sub_sub_cancel_right]
lemma geom_sum_inv [division_ring α] {x : α} (hx1 : x ≠ 1) (hx0 : x ≠ 0) (n : ℕ) :
(geom_series x⁻¹ n) = (x - 1)⁻¹ * (x - x⁻¹ ^ n * x) :=
have h₁ : x⁻¹ ≠ 1, by rwa [inv_eq_one_div, ne.def, div_eq_iff_mul_eq hx0, one_mul],
have h₂ : x⁻¹ - 1 ≠ 0, from mt sub_eq_zero.1 h₁,
have h₃ : x - 1 ≠ 0, from mt sub_eq_zero.1 hx1,
have h₄ : x * (x ^ n)⁻¹ = (x ^ n)⁻¹ * x :=
nat.rec_on n (by simp)
(λ n h, by rw [pow_succ, mul_inv', ←mul_assoc, h, mul_assoc, mul_inv_cancel hx0, mul_assoc, inv_mul_cancel hx0]),
begin
rw [geom_sum h₁, div_eq_iff_mul_eq h₂, ← domain.mul_right_inj h₃,
← mul_assoc, ← mul_assoc, mul_inv_cancel h₃],
simp [mul_add, add_mul, mul_inv_cancel hx0, mul_assoc, h₄, sub_eq_add_neg, add_comm, add_left_comm],
end
variables {β : Type*}
theorem ring_hom.map_geom_series [semiring α] [semiring β] (x : α) (n : ℕ) (f : α →+* β) :
f (geom_series x n) = geom_series (f x) n :=
by { rw [geom_series_def, geom_series_def, ← finset.sum_hom _ f], simp_rw [f.map_mul, f.map_pow] }
theorem ring_hom.map_geom_series₂ [semiring α] [semiring β] (x y : α) (n : ℕ) (f : α →+* β) :
f (geom_series₂ x y n) = geom_series₂ (f x) (f y) n :=
by { rw [geom_series₂_def, geom_series₂_def, ← finset.sum_hom _ f], simp_rw [f.map_mul, f.map_pow] }
|
287ce30299f34c02a024eb0a3dd77982833c612b | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/Frontend.lean | 080687cae980970ee19ebde3093170217358d929 | [
"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 | 5,148 | 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
-/
import Lean.Elab.Import
import Lean.Elab.Command
import Lean.Util.Profile
import Lean.Server.References
namespace Lean.Elab.Frontend
structure State where
commandState : Command.State
parserState : Parser.ModuleParserState
cmdPos : String.Pos
commands : Array Syntax := #[]
structure Context where
inputCtx : Parser.InputContext
abbrev FrontendM := ReaderT Context $ StateRefT State IO
def setCommandState (commandState : Command.State) : FrontendM Unit :=
modify fun s => { s with commandState := commandState }
@[inline] def runCommandElabM (x : Command.CommandElabM α) : FrontendM α := do
let ctx ← read
let s ← get
let cmdCtx : Command.Context := {
cmdPos := s.cmdPos
fileName := ctx.inputCtx.fileName
fileMap := ctx.inputCtx.fileMap
tacticCache? := none
}
match (← liftM <| EIO.toIO' <| (x cmdCtx).run s.commandState) with
| Except.error e => throw <| IO.Error.userError s!"unexpected internal error: {← e.toMessageData.toString}"
| Except.ok (a, sNew) => setCommandState sNew; return a
def elabCommandAtFrontend (stx : Syntax) : FrontendM Unit := do
runCommandElabM do
Command.elabCommandTopLevel stx
def updateCmdPos : FrontendM Unit := do
modify fun s => { s with cmdPos := s.parserState.pos }
def getParserState : FrontendM Parser.ModuleParserState := do pure (← get).parserState
def getCommandState : FrontendM Command.State := do pure (← get).commandState
def setParserState (ps : Parser.ModuleParserState) : FrontendM Unit := modify fun s => { s with parserState := ps }
def setMessages (msgs : MessageLog) : FrontendM Unit := modify fun s => { s with commandState := { s.commandState with messages := msgs } }
def getInputContext : FrontendM Parser.InputContext := do pure (← read).inputCtx
def processCommand : FrontendM Bool := do
updateCmdPos
let cmdState ← getCommandState
let ictx ← getInputContext
let pstate ← getParserState
let scope := cmdState.scopes.head!
let pmctx := { env := cmdState.env, options := scope.opts, currNamespace := scope.currNamespace, openDecls := scope.openDecls }
match profileit "parsing" scope.opts fun _ => Parser.parseCommand ictx pmctx pstate cmdState.messages with
| (cmd, ps, messages) =>
modify fun s => { s with commands := s.commands.push cmd }
setParserState ps
setMessages messages
elabCommandAtFrontend cmd
pure (Parser.isTerminalCommand cmd)
partial def processCommands : FrontendM Unit := do
let done ← processCommand
unless done do
processCommands
end Frontend
open Frontend
def IO.processCommands (inputCtx : Parser.InputContext) (parserState : Parser.ModuleParserState) (commandState : Command.State) : IO State := do
let (_, s) ← (Frontend.processCommands.run { inputCtx := inputCtx }).run { commandState := commandState, parserState := parserState, cmdPos := parserState.pos }
pure s
def process (input : String) (env : Environment) (opts : Options) (fileName : Option String := none) : IO (Environment × MessageLog) := do
let fileName := fileName.getD "<input>"
let inputCtx := Parser.mkInputContext input fileName
let s ← IO.processCommands inputCtx { : Parser.ModuleParserState } (Command.mkState env {} opts)
pure (s.commandState.env, s.commandState.messages)
builtin_initialize
registerOption `printMessageEndPos { defValue := false, descr := "print end position of each message in addition to start position" }
registerTraceClass `Elab.info
def getPrintMessageEndPos (opts : Options) : Bool :=
opts.getBool `printMessageEndPos false
@[export lean_run_frontend]
def runFrontend
(input : String)
(opts : Options)
(fileName : String)
(mainModuleName : Name)
(trustLevel : UInt32 := 0)
(ileanFileName? : Option String := none)
: IO (Environment × Bool) := do
let inputCtx := Parser.mkInputContext input fileName
let (header, parserState, messages) ← Parser.parseHeader inputCtx
let (env, messages) ← processHeader header opts messages inputCtx trustLevel
let env := env.setMainModule mainModuleName
let mut commandState := Command.mkState env messages opts
if ileanFileName?.isSome then
-- Collect InfoTrees so we can later extract and export their info to the ilean file
commandState := { commandState with infoState.enabled := true }
let s ← IO.processCommands inputCtx parserState commandState
for msg in s.commandState.messages.toList do
IO.print (← msg.toString (includeEndPos := getPrintMessageEndPos opts))
if let some ileanFileName := ileanFileName? then
let trees := s.commandState.infoState.trees.toArray
let references := Lean.Server.findModuleRefs inputCtx.fileMap trees (localVars := false)
let ilean := { module := mainModuleName, references : Lean.Server.Ilean }
IO.FS.writeFile ileanFileName $ Json.compress $ toJson ilean
pure (s.commandState.env, !s.commandState.messages.hasErrors)
end Lean.Elab
|
5c9ca5c1affba1c93059b67128037909e12f5306 | ff5230333a701471f46c57e8c115a073ebaaa448 | /library/init/meta/exceptional.lean | 1edb35b29983f9df70d01bf588a7e49eb9745c95 | [
"Apache-2.0"
] | permissive | stanford-cs242/lean | f81721d2b5d00bc175f2e58c57b710d465e6c858 | 7bd861261f4a37326dcf8d7a17f1f1f330e4548c | refs/heads/master | 1,600,957,431,849 | 1,576,465,093,000 | 1,576,465,093,000 | 225,779,423 | 0 | 3 | Apache-2.0 | 1,575,433,936,000 | 1,575,433,935,000 | null | UTF-8 | Lean | false | false | 1,639 | 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.category.monad init.meta.format init.util
/-
Remark: we use a function that produces a format object as the exception information.
Motivation: the formatting object may be big, and we may create it on demand.
-/
/-- An exceptional is similar to `Result` in Haskell.-/
meta inductive exceptional (α : Type)
| success : α → exceptional
| exception : (options → format) → exceptional
section
open exceptional
variables {α : Type}
variables [has_to_string α]
protected meta def exceptional.to_string : exceptional α → string
| (success a) := to_string a
| (exception .(α) e) := "Exception: " ++ to_string (e options.mk)
meta instance : has_to_string (exceptional α) :=
has_to_string.mk exceptional.to_string
end
namespace exceptional
variables {α β : Type}
protected meta def to_bool : exceptional α → bool
| (success _) := tt
| (exception .(α) _) := ff
protected meta def to_option : exceptional α → option α
| (success a) := some a
| (exception .(α) _) := none
@[inline] protected meta def bind (e₁ : exceptional α) (e₂ : α → exceptional β) : exceptional β :=
exceptional.cases_on e₁
(λ a, e₂ a)
(λ f, exception β f)
@[inline] protected meta def return (a : α) : exceptional α :=
success a
@[inline] meta def fail (f : format) : exceptional α :=
exception α (λ u, f)
end exceptional
meta instance : monad exceptional :=
{pure := @exceptional.return, bind := @exceptional.bind}
|
3f3e05626907afe115905f5cef9f775497a92b95 | 8e381650eb2c1c5361be64ff97e47d956bf2ab9f | /src/sheaves/presheaf_of_rings_extension.lean | 2098f62785644eccb59e354636a9d46000954b9b | [] | no_license | alreadydone/lean-scheme | 04c51ab08eca7ccf6c21344d45d202780fa667af | 52d7624f57415eea27ed4dfa916cd94189221a1c | refs/heads/master | 1,599,418,221,423 | 1,562,248,559,000 | 1,562,248,559,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,671 | lean | /-
Presheaf of rings extension.
https://stacks.math.columbia.edu/tag/009N
-/
import to_mathlib.opens
import sheaves.covering.covering
import sheaves.presheaf_of_rings
import sheaves.presheaf_of_rings_on_basis
import sheaves.stalk_of_rings_on_standard_basis
universes u v w
open topological_space
open lattice
open covering
open stalk_of_rings_on_standard_basis.
section presheaf_of_rings_extension
variables {α : Type u} [topological_space α]
variables {B : set (opens α)} {HB : opens.is_basis B}
variables (Bstd : opens.univ ∈ B ∧ ∀ {U V}, U ∈ B → V ∈ B → U ∩ V ∈ B)
variables (F : presheaf_of_rings_on_basis α HB) (U : opens α)
include Bstd
section presheaf_of_rings_on_basis_extension_is_ring
@[reducible] def Fext :=
{ s : Π (x ∈ U), stalk_of_rings_on_standard_basis Bstd F x //
∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV),
∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧ }
-- Add.
private def Fext_add_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_add Bstd F x).add
private def Fext_add : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U
:= λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩,
⟨λ x Hx, (Fext_add_aux Bstd F x) (s₁ x Hx) (s₂ x Hx),
begin
intros x Hx,
replace Hs₁ := Hs₁ x Hx,
replace Hs₂ := Hs₂ x Hx,
rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩,
rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩,
use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩],
let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁,
let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂,
use [σ₁' + σ₂'],
rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩,
apply funext,
intros Hy,
replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩,
replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩,
rw Hs₁,
rw Hs₂,
refl,
end⟩
instance Fext_has_add : has_add (Fext Bstd F U) :=
{ add := Fext_add Bstd F U }
@[simp] lemma Fext_add.eq (x : α) (Hx : x ∈ U)
: ∀ (a b : Fext Bstd F U), (a + b).val x Hx = (a.val x Hx) + (b.val x Hx) :=
λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl
instance Fext_add_semigroup : add_semigroup (Fext Bstd F U) :=
{ add_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_add Bstd F U }
instance Fext_add_comm_semigroup : add_comm_semigroup (Fext Bstd F U) :=
{ add_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_add_semigroup Bstd F U }
-- Zero.
private def Fext_zero : Fext Bstd F U :=
⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero,
λ x Hx, ⟨opens.univ, Bstd.1, trivial, 0, (λ y Hy, funext $ λ HyU, rfl)⟩⟩
instance Fext_has_zero : has_zero (Fext Bstd F U) :=
{ zero := Fext_zero Bstd F U }
@[simp] lemma Fext_zero.eq (x : α) (Hx : x ∈ U)
: (0 : Fext Bstd F U).val x Hx = (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero := rfl
instance Fext_add_comm_monoid : add_comm_monoid (Fext Bstd F U) :=
{ zero_add := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
add_zero := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_zero Bstd F U,
..Fext_add_comm_semigroup Bstd F U, }
-- Neg.
private def Fext_neg_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_neg Bstd F x).neg
private def Fext_neg : Fext Bstd F U → Fext Bstd F U :=
λ ⟨s, Hs⟩,
⟨λ x Hx, (Fext_neg_aux Bstd F x) (s x Hx),
begin
intros x Hx,
replace Hs := Hs x Hx,
rcases Hs with ⟨V, BV, HxV, σ, Hs⟩,
use [V, BV, HxV, -σ],
rintros y ⟨HyU, HyV⟩,
apply funext,
intros Hy,
replace Hs := Hs y ⟨HyU, HyV⟩,
rw Hs,
refl,
end⟩
instance Fext_has_neg : has_neg (Fext Bstd F U) :=
{ neg := Fext_neg Bstd F U, }
@[simp] lemma Fext_neg.eq (x : α) (Hx : x ∈ U)
: ∀ (a : Fext Bstd F U), (-a).val x Hx = -(a.val x Hx) :=
λ ⟨s, Hs⟩, rfl
instance Fext_add_comm_group : add_comm_group (Fext Bstd F U) :=
{ add_left_neg := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_neg Bstd F U,
..Fext_add_comm_monoid Bstd F U, }
-- Mul.
private def Fext_mul_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_mul Bstd F x).mul
private def Fext_mul : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U
:= λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩,
⟨λ x Hx, (Fext_mul_aux Bstd F x) (s₁ x Hx) (s₂ x Hx),
begin
intros x Hx,
replace Hs₁ := Hs₁ x Hx,
replace Hs₂ := Hs₂ x Hx,
rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩,
rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩,
use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩],
let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁,
let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂,
use [σ₁' * σ₂'],
rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩,
apply funext,
intros Hy,
replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩,
replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩,
rw Hs₁,
rw Hs₂,
refl,
end⟩
instance Fext_has_mul : has_mul (Fext Bstd F U) :=
{ mul := Fext_mul Bstd F U }
@[simp] lemma Fext_mul.eq (x : α) (Hx : x ∈ U)
: ∀ (a b : Fext Bstd F U), (a * b).val x Hx = (a.val x Hx) * (b.val x Hx) :=
λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl
instance Fext_mul_semigroup : semigroup (Fext Bstd F U) :=
{ mul_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_semigroup Bstd F x).mul_assoc,
end,
..Fext_has_mul Bstd F U, }
instance Fext_mul_comm_semigroup : comm_semigroup (Fext Bstd F U) :=
{ mul_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_semigroup Bstd F x).mul_comm,
end,
..Fext_mul_semigroup Bstd F U, }
-- One.
private def Fext_one : Fext Bstd F U :=
⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_one Bstd F x).one,
λ x Hx, ⟨opens.univ, Bstd.1, trivial, 1, (λ y Hy, funext $ λ HyU, rfl)⟩⟩
instance Fext_has_one : has_one (Fext Bstd F U) :=
{ one := Fext_one Bstd F U }
instance Fext_mul_comm_monoid : comm_monoid (Fext Bstd F U) :=
{ one_mul := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).one_mul,
end,
mul_one := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).mul_one,
end,
..Fext_has_one Bstd F U,
..Fext_mul_comm_semigroup Bstd F U, }
-- Ring
instance Fext_comm_ring : comm_ring (Fext Bstd F U) :=
{ left_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
rw Fext_add.eq,
repeat { rw Fext_mul.eq, },
rw Fext_add.eq,
eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).left_distrib,
end,
right_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
rw Fext_add.eq,
repeat { rw Fext_mul.eq, },
rw Fext_add.eq,
eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).right_distrib,
end,
..Fext_add_comm_group Bstd F U,
..Fext_mul_comm_monoid Bstd F U, }
end presheaf_of_rings_on_basis_extension_is_ring
-- F defined in the whole space to F defined on the basis.
def presheaf_of_rings_to_presheaf_of_rings_on_basis
(F : presheaf_of_rings α) : presheaf_of_rings_on_basis α HB :=
{ F := λ U BU, F U,
res := λ U V BU BV HVU, F.res U V HVU,
Hid := λ U BU, F.Hid U,
Hcomp := λ U V W BU BV BW, F.Hcomp U V W,
Fring := λ U BU, F.Fring U,
res_is_ring_hom := λ U V BU BV HVU, F.res_is_ring_hom U V HVU, }
-- F defined on the bases extended to the whole space.
def presheaf_of_rings_on_basis_to_presheaf_of_rings
(F : presheaf_of_rings_on_basis α HB) : presheaf_of_rings α :=
{ F := λ U, {s : Π (x ∈ U), stalk_on_basis F.to_presheaf_on_basis x //
∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV),
∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧},
res := λ U W HWU FU,
{ val := λ x HxW, (FU.val x $ HWU HxW),
property := λ x HxW,
begin
rcases (FU.property x (HWU HxW)) with ⟨V, ⟨BV, ⟨HxV, ⟨σ, HFV⟩⟩⟩⟩,
use [V, BV, HxV, σ],
rintros y ⟨HyW, HyV⟩,
rw (HFV y ⟨HWU HyW, HyV⟩),
end },
Hid := λ U, funext $ λ x, subtype.eq rfl,
Hcomp := λ U V W HWV HVU, funext $ λ x, subtype.eq rfl,
Fring := λ U, Fext_comm_ring Bstd F U,
res_is_ring_hom := λ U V HVU,
{ map_one := rfl,
map_mul := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx,
begin
erw Fext_mul.eq,
refl,
end,
map_add := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx,
begin
erw Fext_add.eq,
refl,
end, } }
notation F `ᵣₑₓₜ`:1 Bstd := presheaf_of_rings_on_basis_to_presheaf_of_rings Bstd F
end presheaf_of_rings_extension
|
d231c6765353959445216c4babbf9ae7a8ccca0e | 4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d | /stage0/src/Lean/Server/FileSource.lean | f12bf73ee994b9e71b7e7153b9979e3f3a03b124 | [
"Apache-2.0"
] | permissive | subfish-zhou/leanprover-zh_CN.github.io | 30b9fba9bd790720bd95764e61ae796697d2f603 | 8b2985d4a3d458ceda9361ac454c28168d920d3f | refs/heads/master | 1,689,709,967,820 | 1,632,503,056,000 | 1,632,503,056,000 | 409,962,097 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,501 | lean | /-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga
-/
import Lean.Data.Lsp
namespace Lean.Lsp
class FileSource (α : Type) where
fileSource : α → DocumentUri
export FileSource (fileSource)
instance : FileSource Location :=
⟨fun l => l.uri⟩
instance : FileSource TextDocumentIdentifier :=
⟨fun i => i.uri⟩
instance : FileSource VersionedTextDocumentIdentifier :=
⟨fun i => i.uri⟩
instance : FileSource TextDocumentEdit :=
⟨fun e => fileSource e.textDocument⟩
instance : FileSource TextDocumentItem :=
⟨fun i => i.uri⟩
instance : FileSource TextDocumentPositionParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource DidOpenTextDocumentParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource DidChangeTextDocumentParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource DidCloseTextDocumentParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource CompletionParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource HoverParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource DeclarationParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource DefinitionParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource TypeDefinitionParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource WaitForDiagnosticsParams :=
⟨fun p => p.uri⟩
instance : FileSource DocumentHighlightParams :=
⟨fun h => fileSource h.toTextDocumentPositionParams⟩
instance : FileSource DocumentSymbolParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource SemanticTokensParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource SemanticTokensRangeParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource PlainGoalParams :=
⟨fun p => fileSource p.textDocument⟩
instance : FileSource PlainTermGoalParams where
fileSource p := fileSource p.textDocument
instance : FileSource RpcConnectParams where
fileSource p := p.uri
instance : FileSource RpcCallParams where
fileSource p := fileSource p.textDocument
instance : FileSource RpcReleaseParams where
fileSource p := p.uri
instance : FileSource RpcKeepAliveParams where
fileSource p := p.uri
end Lean.Lsp
|
11c55a4f957c31d21bc49321dd97baf9e3c36921 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/algebra/gcd_monoid/multiset.lean | 26af4c8b20bc9a7d3f9cce778a1181edabc5c9d2 | [
"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 | 5,096 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import data.multiset.lattice
import algebra.gcd_monoid
/-!
# GCD and LCM operations on multisets
## Main definitions
- `multiset.gcd` - the greatest common denominator of a `multiset` of elements of a `gcd_monoid`
- `multiset.lcm` - the least common multiple of a `multiset` of elements of a `gcd_monoid`
## Implementation notes
TODO: simplify with a tactic and `data.multiset.lattice`
## Tags
multiset, gcd
-/
namespace multiset
variables {α : Type*} [comm_cancel_monoid_with_zero α] [nontrivial α] [gcd_monoid α]
/-! ### lcm -/
section lcm
/-- Least common multiple of a multiset -/
def lcm (s : multiset α) : α := s.fold gcd_monoid.lcm 1
@[simp] lemma lcm_zero : (0 : multiset α).lcm = 1 :=
fold_zero _ _
@[simp] lemma lcm_cons (a : α) (s : multiset α) :
(a ::ₘ s).lcm = gcd_monoid.lcm a s.lcm :=
fold_cons_left _ _ _ _
@[simp] lemma lcm_singleton {a : α} : (a ::ₘ 0).lcm = normalize a := by simp
@[simp] lemma lcm_add (s₁ s₂ : multiset α) : (s₁ + s₂).lcm = gcd_monoid.lcm s₁.lcm s₂.lcm :=
eq.trans (by simp [lcm]) (fold_add _ _ _ _ _)
lemma lcm_dvd {s : multiset α} {a : α} : s.lcm ∣ a ↔ (∀ b ∈ s, b ∣ a) :=
multiset.induction_on s (by simp)
(by simp [or_imp_distrib, forall_and_distrib, lcm_dvd_iff] {contextual := tt})
lemma dvd_lcm {s : multiset α} {a : α} (h : a ∈ s) : a ∣ s.lcm :=
lcm_dvd.1 (dvd_refl _) _ h
lemma lcm_mono {s₁ s₂ : multiset α} (h : s₁ ⊆ s₂) : s₁.lcm ∣ s₂.lcm :=
lcm_dvd.2 $ assume b hb, dvd_lcm (h hb)
@[simp] lemma normalize_lcm (s : multiset α) : normalize (s.lcm) = s.lcm :=
multiset.induction_on s (by simp) $ λ a s IH, by simp
variables [decidable_eq α]
@[simp] lemma lcm_erase_dup (s : multiset α) : (erase_dup s).lcm = s.lcm :=
multiset.induction_on s (by simp) $ λ a s IH, begin
by_cases a ∈ s; simp [IH, h],
unfold lcm,
rw [← cons_erase h, fold_cons_left, ← lcm_assoc, lcm_same],
apply lcm_eq_of_associated_left (associated_normalize _),
end
@[simp] lemma lcm_ndunion (s₁ s₂ : multiset α) :
(ndunion s₁ s₂).lcm = gcd_monoid.lcm s₁.lcm s₂.lcm :=
by { rw [← lcm_erase_dup, erase_dup_ext.2, lcm_erase_dup, lcm_add], simp }
@[simp] lemma lcm_union (s₁ s₂ : multiset α) :
(s₁ ∪ s₂).lcm = gcd_monoid.lcm s₁.lcm s₂.lcm :=
by { rw [← lcm_erase_dup, erase_dup_ext.2, lcm_erase_dup, lcm_add], simp }
@[simp] lemma lcm_ndinsert (a : α) (s : multiset α) :
(ndinsert a s).lcm = gcd_monoid.lcm a s.lcm :=
by { rw [← lcm_erase_dup, erase_dup_ext.2, lcm_erase_dup, lcm_cons], simp }
end lcm
/-! ### gcd -/
section gcd
/-- Greatest common divisor of a multiset -/
def gcd (s : multiset α) : α := s.fold gcd_monoid.gcd 0
@[simp] lemma gcd_zero : (0 : multiset α).gcd = 0 :=
fold_zero _ _
@[simp] lemma gcd_cons (a : α) (s : multiset α) :
(a ::ₘ s).gcd = gcd_monoid.gcd a s.gcd :=
fold_cons_left _ _ _ _
@[simp] lemma gcd_singleton {a : α} : (a ::ₘ 0).gcd = normalize a := by simp
@[simp] lemma gcd_add (s₁ s₂ : multiset α) : (s₁ + s₂).gcd = gcd_monoid.gcd s₁.gcd s₂.gcd :=
eq.trans (by simp [gcd]) (fold_add _ _ _ _ _)
lemma dvd_gcd {s : multiset α} {a : α} : a ∣ s.gcd ↔ (∀ b ∈ s, a ∣ b) :=
multiset.induction_on s (by simp)
(by simp [or_imp_distrib, forall_and_distrib, dvd_gcd_iff] {contextual := tt})
lemma gcd_dvd {s : multiset α} {a : α} (h : a ∈ s) : s.gcd ∣ a :=
dvd_gcd.1 (dvd_refl _) _ h
lemma gcd_mono {s₁ s₂ : multiset α} (h : s₁ ⊆ s₂) : s₂.gcd ∣ s₁.gcd :=
dvd_gcd.2 $ assume b hb, gcd_dvd (h hb)
@[simp] lemma normalize_gcd (s : multiset α) : normalize (s.gcd) = s.gcd :=
multiset.induction_on s (by simp) $ λ a s IH, by simp
theorem gcd_eq_zero_iff (s : multiset α) : s.gcd = 0 ↔ ∀ (x : α), x ∈ s → x = 0 :=
begin
split,
{ intros h x hx,
apply eq_zero_of_zero_dvd,
rw ← h,
apply gcd_dvd hx },
{ apply s.induction_on,
{ simp },
intros a s sgcd h,
simp [h a (mem_cons_self a s), sgcd (λ x hx, h x (mem_cons_of_mem hx))] }
end
variables [decidable_eq α]
@[simp] lemma gcd_erase_dup (s : multiset α) : (erase_dup s).gcd = s.gcd :=
multiset.induction_on s (by simp) $ λ a s IH, begin
by_cases a ∈ s; simp [IH, h],
unfold gcd,
rw [← cons_erase h, fold_cons_left, ← gcd_assoc, gcd_same],
apply (associated_normalize _).gcd_eq_left,
end
@[simp] lemma gcd_ndunion (s₁ s₂ : multiset α) :
(ndunion s₁ s₂).gcd = gcd_monoid.gcd s₁.gcd s₂.gcd :=
by { rw [← gcd_erase_dup, erase_dup_ext.2, gcd_erase_dup, gcd_add], simp }
@[simp] lemma gcd_union (s₁ s₂ : multiset α) :
(s₁ ∪ s₂).gcd = gcd_monoid.gcd s₁.gcd s₂.gcd :=
by { rw [← gcd_erase_dup, erase_dup_ext.2, gcd_erase_dup, gcd_add], simp }
@[simp] lemma gcd_ndinsert (a : α) (s : multiset α) :
(ndinsert a s).gcd = gcd_monoid.gcd a s.gcd :=
by { rw [← gcd_erase_dup, erase_dup_ext.2, gcd_erase_dup, gcd_cons], simp }
end gcd
end multiset
|
6e491d0f4fee6f2a607cdf2b16941c7a4b8423c7 | 95a02f25ddbaf30f9e6fdb8043e6fd3c197ea01c | /src/objects.lean | 349009e24290d6eedc9364b2c2116963c01e6b2f | [
"MIT"
] | permissive | praalhans/lean-abs | b23aad54878c06f5a495dfff63260b72d17e9b99 | 5d23eec7234c880f5ebc0d7b831caf55119edef8 | refs/heads/master | 1,587,416,771,564 | 1,575,885,115,000 | 1,575,885,115,000 | 169,097,861 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,271 | lean | /- Copyright 2019 (c) Hans-Dieter Hiep. All rights reserved. Released under MIT license as described in the file LICENSE. -/
import syntax
universe u
open signature list
/- Fix a signature. We consider an interpretation of reference types and data types. Reference types are interpreted as object identities. Each object identity is associated to a single class name. Equality is decidable for objects. Each record name is uniquely associated to a data type. A data type comprises an inhabited Lean type with decidable equality. The built-in boolean is associated to Lean's bool with false as default. -/
structure datatype :=
(host : Type)
(inhabited_host: inhabited host)
(decidable_host: decidable_eq host)
instance datatype.decidable_eq (d : datatype) :
decidable_eq d.host := d.decidable_host
instance datatype.inhabited_eq (d : datatype) :
inhabited d.host := d.inhabited_host
def datatype.default (d : datatype) : d.host :=
default d.host
class objects (α β : Type) extends signature α :=
(class_of: β → class_name α)
(encodable_object: encodable β)
(decidable_object: decidable_eq β) -- redundant
(data_type: record_name α → datatype)
(data_type_boolean:
(data_type (boolean_name α)).host = bool)
(data_type_boolean_inhabited:
(cast data_type_boolean (data_type (boolean_name α))
.inhabited_host.default) = ff)
open objects
lemma data_type_booleanr {α β : Type} [objects α β] :
bool = (data_type (boolean_name α)).host :=
begin symmetry, apply data_type_boolean end
instance objects.decidable_eq {α β : Type} [objects α β] :
decidable_eq β := decidable_object α β
instance objects.encodable {α β : Type} [objects α β] :
encodable β := encodable_object α β
/- We treat values as being of a type. A value of a reference type is an object of the same class, or null. A value of a data type is a term of the associated type in Lean. -/
@[derive decidable_eq]
inductive value {α β : Type} [objects α β] : type α → Type
| object {c : class_name α} :
{o : β // c = class_of α o} → value (type.ref c)
| null (c : class_name α) :
value (type.ref c)
| term {r : record_name α} :
(data_type r).host → value (type.data r)
/- The default value of a reference type is null, and the default value of a data type is the default in Lean. -/
instance value.inhabited {α β : Type} [objects α β] :
Π{ty : type α}, inhabited (value ty)
| (type.ref c) := ⟨value.null c⟩
| (type.data r) := ⟨value.term (data_type r).default⟩
-- Projection of value to term
def value.unterm {α β : Type} [objects α β]
{r : record_name α} : Π (x : value (type.data r)),
(data_type r).host
| (value.term t) := t
-- Projection of boolean value to bool
def value.unbool {α β : Type} [objects α β] :
Π (x : value (boolean α)), bool
| (value.term t) := cast (data_type_boolean α β) t
-- Projection of value to potential object
def value.unobject {α β : Type} [objects α β]
{c : class_name α} : Π (x : value (type.ref c)), option β
| (value.object o) := o
| (value.null _) := none
def value.not_null {α β : Type} [objects α β]
{c : class_name α} (x : value (type.ref c)) : Prop :=
x ≠ value.null c
-- Projection of not-null value to object identity
def value.the_object {α β : Type} [objects α β]
{c : class_name α} : Π {x : value (type.ref c)},
value.not_null x → β
| (value.object o) _ := o
| (value.null .(c)) G := begin exfalso, apply G, refl end
lemma value.class_of_the_object {α β : Type} [objects α β]
{c : class_name α} {x : value (type.ref c)}
(G : value.not_null x) :
class_of α (value.the_object G) = c :=
begin
cases x,
{unfold value.the_object, apply eq.symm,
simp [coe,lift_t,has_lift_t.lift],
simp [coe_t,has_coe_t.coe,coe_b,has_coe.coe],
exact x_a.property},
{exfalso, apply G, refl}
end
/- Given a list of types, we have a value list of values with matching types. -/
@[derive decidable_eq]
inductive vallist {α β : Type} [objects α β] :
list (type α) → Type
| nil : vallist []
| cons {ty : type α} {l : list (type α)} :
value ty → vallist l → vallist (ty::l)
def vallist.default {α β : Type} [objects α β] :
Π(l : list (type α)), vallist l
| [] := vallist.nil
| (t :: l) := vallist.cons (default (value t))
(vallist.default l)
instance vallist.inhabited {α β : Type} [objects α β]
(l : list (type α)) : inhabited (vallist l) :=
⟨vallist.default l⟩
/- A value list of a single type is just a value. -/
def vallist.single {α β : Type} [objects α β] {ty : type α}
(v : value ty) : vallist [ty] :=
vallist.cons v vallist.nil
/- There is a unique value of a single value list. -/
def vallist.the {α β : Type} [objects α β] {ty : type α} :
vallist [ty] → value ty
| (vallist.cons h vallist.nil) := h
/- A value list of a single type can be appended at the front to form a new value list. -/
def vallist.consl {α β : Type} [objects α β]
{ty : type α} {l : list (type α)}
(h : vallist [ty]) (t : vallist l) : vallist (ty :: l) :=
vallist.cons (h.the) t
/- Given a value list and an index in the list of types, we obtain a value. -/
def vallist.lookup {α β : Type} [objects α β] {ty : type α} :
Π {l : context α}, vallist l → list_at ty l → value ty
| (x :: xs) (vallist.cons v _) (list_at.here .(x) .(xs)) := v
| (x :: xs) (vallist.cons _ ys) (list_at.tail .(x) zs) :=
vallist.lookup ys zs
/- Given a value list and an index and a new value, we obtain a new value list which updates the given index. -/
def vallist.update {α β : Type} [objects α β] {ty : type α} :
Π {l : context α}, vallist l → list_at ty l →
value ty → vallist l
| (x :: xs) (vallist.cons _ tl) (list_at.here .(x) .(xs)) v :=
vallist.cons v tl
| (x :: xs) (vallist.cons v ys) (list_at.tail .(x) zs) w :=
vallist.cons v (vallist.update ys zs w)
/- An interpretation consists of a mapping from constant symbols to values, and from function symbols to functions over value lists to values. -/
class interpret (α β : Type) extends objects α β :=
(interp {args : list (type α)} {result : type α}
{s : symbol_name α} (sym : symbol args result s):
vallist args → value result)
|
7dd75adb57e93b6cd263763b744547a6da62b998 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/group_theory/perm/support.lean | 78fa4c4dc079a0cbedd54b9c37f78396e40e94e0 | [
"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 | 21,064 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import data.finset.card
import data.fintype.basic
import group_theory.perm.basic
/-!
# Support of a permutation
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main definitions
In the following, `f g : equiv.perm α`.
* `equiv.perm.disjoint`: two permutations `f` and `g` are `disjoint` if every element is fixed
either by `f`, or by `g`.
Equivalently, `f` and `g` are `disjoint` iff their `support` are disjoint.
* `equiv.perm.is_swap`: `f = swap x y` for `x ≠ y`.
* `equiv.perm.support`: the elements `x : α` that are not fixed by `f`.
-/
open equiv finset
namespace equiv.perm
variables {α : Type*}
section disjoint
/-- Two permutations `f` and `g` are `disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def disjoint (f g : perm α) := ∀ x, f x = x ∨ g x = x
variables {f g h : perm α}
@[symm] lemma disjoint.symm : disjoint f g → disjoint g f :=
by simp only [disjoint, or.comm, imp_self]
lemma disjoint.symmetric : symmetric (@disjoint α) :=
λ _ _, disjoint.symm
instance : is_symm (perm α) disjoint := ⟨disjoint.symmetric⟩
lemma disjoint_comm : disjoint f g ↔ disjoint g f :=
⟨disjoint.symm, disjoint.symm⟩
lemma disjoint.commute (h : disjoint f g) : commute f g :=
equiv.ext $ λ x, (h x).elim
(λ hf, (h (g x)).elim (λ hg, by simp [mul_apply, hf, hg])
(λ hg, by simp [mul_apply, hf, g.injective hg]))
(λ hg, (h (f x)).elim (λ hf, by simp [mul_apply, f.injective hf, hg])
(λ hf, by simp [mul_apply, hf, hg]))
@[simp] lemma disjoint_one_left (f : perm α) : disjoint 1 f := λ _, or.inl rfl
@[simp] lemma disjoint_one_right (f : perm α) : disjoint f 1 := λ _, or.inr rfl
lemma disjoint_iff_eq_or_eq : disjoint f g ↔ ∀ (x : α), f x = x ∨ g x = x := iff.rfl
@[simp] lemma disjoint_refl_iff : disjoint f f ↔ f = 1 :=
begin
refine ⟨λ h, _, λ h, h.symm ▸ disjoint_one_left 1⟩,
ext x,
cases h x with hx hx;
simp [hx]
end
lemma disjoint.inv_left (h : disjoint f g) : disjoint f⁻¹ g :=
begin
intro x,
rw [inv_eq_iff_eq, eq_comm],
exact h x
end
lemma disjoint.inv_right (h : disjoint f g) : disjoint f g⁻¹ :=
h.symm.inv_left.symm
@[simp] lemma disjoint_inv_left_iff : disjoint f⁻¹ g ↔ disjoint f g :=
begin
refine ⟨λ h, _, disjoint.inv_left⟩,
convert h.inv_left,
exact (inv_inv _).symm
end
@[simp] lemma disjoint_inv_right_iff : disjoint f g⁻¹ ↔ disjoint f g :=
by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm]
lemma disjoint.mul_left (H1 : disjoint f h) (H2 : disjoint g h) :
disjoint (f * g) h :=
λ x, by cases H1 x; cases H2 x; simp *
lemma disjoint.mul_right (H1 : disjoint f g) (H2 : disjoint f h) :
disjoint f (g * h) :=
by { rw disjoint_comm, exact H1.symm.mul_left H2.symm }
lemma disjoint_prod_right (l : list (perm α))
(h : ∀ g ∈ l, disjoint f g) : disjoint f l.prod :=
begin
induction l with g l ih,
{ exact disjoint_one_right _ },
{ rw list.prod_cons,
exact (h _ (list.mem_cons_self _ _)).mul_right (ih (λ g hg, h g (list.mem_cons_of_mem _ hg))) }
end
lemma disjoint_prod_perm {l₁ l₂ : list (perm α)} (hl : l₁.pairwise disjoint)
(hp : l₁ ~ l₂) : l₁.prod = l₂.prod :=
hp.prod_eq' $ hl.imp $ λ f g, disjoint.commute
lemma nodup_of_pairwise_disjoint {l : list (perm α)} (h1 : (1 : perm α) ∉ l)
(h2 : l.pairwise disjoint) : l.nodup :=
begin
refine list.pairwise.imp_of_mem _ h2,
rintros σ - h_mem - h_disjoint rfl,
suffices : σ = 1,
{ rw this at h_mem,
exact h1 h_mem },
exact ext (λ a, (or_self _).mp (h_disjoint a)),
end
lemma pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) :
∀ n : ℕ, (f ^ n) x = x
| 0 := rfl
| (n+1) := by rw [pow_succ', mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self]
lemma zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) :
∀ n : ℤ, (f ^ n) x = x
| (n : ℕ) := pow_apply_eq_self_of_apply_eq_self hfx n
| -[1+ n] := by rw [zpow_neg_succ_of_nat, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx]
lemma pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 := or.inl rfl
| (n+1) := (pow_apply_eq_of_apply_apply_eq_self n).elim
(λ h, or.inr (by rw [pow_succ, mul_apply, h]))
(λ h, or.inl (by rw [pow_succ, mul_apply, h, hffx]))
lemma zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| (n : ℕ) := pow_apply_eq_of_apply_apply_eq_self hffx n
| -[1+ n] := by { rw [zpow_neg_succ_of_nat, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply,
← pow_succ, eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ', @eq_comm _ x, or.comm],
exact pow_apply_eq_of_apply_apply_eq_self hffx _ }
lemma disjoint.mul_apply_eq_iff {σ τ : perm α} (hστ : disjoint σ τ) {a : α} :
(σ * τ) a = a ↔ σ a = a ∧ τ a = a :=
begin
refine ⟨λ h, _, λ h, by rw [mul_apply, h.2, h.1]⟩,
cases hστ a with hσ hτ,
{ exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ },
{ exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ },
end
lemma disjoint.mul_eq_one_iff {σ τ : perm α} (hστ : disjoint σ τ) :
σ * τ = 1 ↔ σ = 1 ∧ τ = 1 :=
by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and_distrib]
lemma disjoint.zpow_disjoint_zpow {σ τ : perm α} (hστ : disjoint σ τ) (m n : ℤ) :
disjoint (σ ^ m) (τ ^ n) :=
λ x, or.imp (λ h, zpow_apply_eq_self_of_apply_eq_self h m)
(λ h, zpow_apply_eq_self_of_apply_eq_self h n) (hστ x)
lemma disjoint.pow_disjoint_pow {σ τ : perm α} (hστ : disjoint σ τ) (m n : ℕ) :
disjoint (σ ^ m) (τ ^ n) :=
hστ.zpow_disjoint_zpow m n
end disjoint
section is_swap
variable [decidable_eq α]
/-- `f.is_swap` indicates that the permutation `f` is a transposition of two elements. -/
def is_swap (f : perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y
@[simp] lemma of_subtype_swap_eq {p : α → Prop} [decidable_pred p]
(x y : subtype p) :
(equiv.swap x y).of_subtype = equiv.swap ↑x ↑y :=
equiv.ext $ λ z, begin
by_cases hz : p z,
{ rw [swap_apply_def, of_subtype_apply_of_mem _ hz],
split_ifs with hzx hzy,
{ simp_rw [hzx, subtype.coe_eta, swap_apply_left], },
{ simp_rw [hzy, subtype.coe_eta, swap_apply_right], },
{ rw swap_apply_of_ne_of_ne, refl,
intro h, apply hzx, rw ← h, refl,
intro h, apply hzy, rw ← h, refl, } },
{ rw [of_subtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne],
intro h, apply hz, rw h, exact subtype.prop x,
intro h, apply hz, rw h, exact subtype.prop y, }
end
lemma is_swap.of_subtype_is_swap {p : α → Prop} [decidable_pred p]
{f : perm (subtype p)} (h : f.is_swap) : (of_subtype f).is_swap :=
let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h in
⟨x, y, by { simp only [ne.def] at hxy, exact hxy.1 },
by { simp only [hxy.2, of_subtype_swap_eq], refl, }⟩
lemma ne_and_ne_of_swap_mul_apply_ne_self {f : perm α} {x y : α}
(hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x :=
begin
simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at *,
by_cases h : f y = x,
{ split; intro; simp only [*, if_true, eq_self_iff_true, not_true, ne.def] at * },
{ split_ifs at hy; cc }
end
end is_swap
section support
section set
variables (p q : perm α)
lemma set_support_inv_eq :
{x | p⁻¹ x ≠ x} = {x | p x ≠ x} :=
begin
ext x,
simp only [set.mem_set_of_eq, ne.def],
rw [inv_def, symm_apply_eq, eq_comm]
end
lemma set_support_apply_mem {p : perm α} {a : α} :
p a ∈ {x | p x ≠ x} ↔ a ∈ {x | p x ≠ x} :=
by simp
lemma set_support_zpow_subset (n : ℤ) :
{x | (p ^ n) x ≠ x} ⊆ {x | p x ≠ x} :=
begin
intros x,
simp only [set.mem_set_of_eq, ne.def],
intros hx H,
simpa [zpow_apply_eq_self_of_apply_eq_self H] using hx
end
lemma set_support_mul_subset :
{x | (p * q) x ≠ x} ⊆ {x | p x ≠ x} ∪ {x | q x ≠ x} :=
begin
intro x,
simp only [perm.coe_mul, function.comp_app, ne.def, set.mem_union, set.mem_set_of_eq],
by_cases hq : q x = x;
simp [hq]
end
end set
variables [decidable_eq α] [fintype α] {f g : perm α}
/-- The `finset` of nonfixed points of a permutation. -/
def support (f : perm α) : finset α := univ.filter (λ x, f x ≠ x)
@[simp] lemma mem_support {x : α} : x ∈ f.support ↔ f x ≠ x :=
by rw [support, mem_filter, and_iff_right (mem_univ x)]
lemma not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp
lemma coe_support_eq_set_support (f : perm α) :
(f.support : set α) = {x | f x ≠ x} :=
by { ext, simp }
@[simp] lemma support_eq_empty_iff {σ : perm α} : σ.support = ∅ ↔ σ = 1 :=
by simp_rw [finset.ext_iff, mem_support, finset.not_mem_empty, iff_false, not_not,
equiv.perm.ext_iff, one_apply]
@[simp] lemma support_one : (1 : perm α).support = ∅ :=
by rw support_eq_empty_iff
@[simp] lemma support_refl : support (equiv.refl α) = ∅ := support_one
lemma support_congr (h : f.support ⊆ g.support)
(h' : ∀ x ∈ g.support, f x = g x) : f = g :=
begin
ext x,
by_cases hx : x ∈ g.support,
{ exact h' x hx },
{ rw [not_mem_support.mp hx, ←not_mem_support],
exact λ H, hx (h H) }
end
lemma support_mul_le (f g : perm α) :
(f * g).support ≤ f.support ⊔ g.support :=
λ x, begin
rw [sup_eq_union, mem_union, mem_support, mem_support,
mem_support, mul_apply, ←not_and_distrib, not_imp_not],
rintro ⟨hf, hg⟩,
rw [hg, hf]
end
lemma exists_mem_support_of_mem_support_prod {l : list (perm α)} {x : α}
(hx : x ∈ l.prod.support) :
∃ f : perm α, f ∈ l ∧ x ∈ f.support :=
begin
contrapose! hx,
simp_rw [mem_support, not_not] at hx ⊢,
induction l with f l ih generalizing hx,
{ refl },
{ rw [list.prod_cons, mul_apply, ih (λ g hg, hx g (or.inr hg)), hx f (or.inl rfl)] },
end
lemma support_pow_le (σ : perm α) (n : ℕ) :
(σ ^ n).support ≤ σ.support :=
λ x h1, mem_support.mpr (λ h2, mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n))
@[simp] lemma support_inv (σ : perm α) : support (σ⁻¹) = σ.support :=
by simp_rw [finset.ext_iff, mem_support, not_iff_not,
(inv_eq_iff_eq).trans eq_comm, iff_self, imp_true_iff]
@[simp]
lemma apply_mem_support {x : α} :
f x ∈ f.support ↔ x ∈ f.support :=
by rw [mem_support, mem_support, ne.def, ne.def, not_iff_not, apply_eq_iff_eq]
@[simp]
lemma pow_apply_mem_support {n : ℕ} {x : α} :
(f ^ n) x ∈ f.support ↔ x ∈ f.support :=
begin
induction n with n ih,
{ refl },
rw [pow_succ, perm.mul_apply, apply_mem_support, ih]
end
@[simp]
lemma zpow_apply_mem_support {n : ℤ} {x : α} :
(f ^ n) x ∈ f.support ↔ x ∈ f.support :=
begin
cases n,
{ rw [int.of_nat_eq_coe, zpow_coe_nat, pow_apply_mem_support] },
{ rw [zpow_neg_succ_of_nat, ← support_inv, ← inv_pow, pow_apply_mem_support] }
end
lemma pow_eq_on_of_mem_support (h : ∀ (x ∈ f.support ∩ g.support), f x = g x)
(k : ℕ) : ∀ (x ∈ f.support ∩ g.support), (f ^ k) x = (g ^ k) x :=
begin
induction k with k hk,
{ simp },
{ intros x hx,
rw [pow_succ', mul_apply, pow_succ', mul_apply, h _ hx, hk],
rwa [mem_inter, apply_mem_support, ←h _ hx, apply_mem_support, ←mem_inter] }
end
lemma disjoint_iff_disjoint_support :
disjoint f g ↔ _root_.disjoint f.support g.support :=
by simp [disjoint_iff_eq_or_eq, disjoint_iff, finset.ext_iff, not_and_distrib]
lemma disjoint.disjoint_support (h : disjoint f g) :
_root_.disjoint f.support g.support :=
disjoint_iff_disjoint_support.1 h
lemma disjoint.support_mul (h : disjoint f g) :
(f * g).support = f.support ∪ g.support :=
begin
refine le_antisymm (support_mul_le _ _) (λ a, _),
rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ←not_and_distrib, not_imp_not],
exact (h a).elim (λ hf h, ⟨hf, f.apply_eq_iff_eq.mp (h.trans hf.symm)⟩)
(λ hg h, ⟨(congr_arg f hg).symm.trans h, hg⟩),
end
lemma support_prod_of_pairwise_disjoint (l : list (perm α)) (h : l.pairwise disjoint) :
l.prod.support = (l.map support).foldr (⊔) ⊥ :=
begin
induction l with hd tl hl,
{ simp },
{ rw [list.pairwise_cons] at h,
have : disjoint hd tl.prod := disjoint_prod_right _ h.left,
simp [this.support_mul, hl h.right] }
end
lemma support_prod_le (l : list (perm α)) :
l.prod.support ≤ (l.map support).foldr (⊔) ⊥ :=
begin
induction l with hd tl hl,
{ simp },
{ rw [list.prod_cons, list.map_cons, list.foldr_cons],
refine (support_mul_le hd tl.prod).trans _,
exact sup_le_sup le_rfl hl }
end
lemma support_zpow_le (σ : perm α) (n : ℤ) :
(σ ^ n).support ≤ σ.support :=
λ x h1, mem_support.mpr (λ h2, mem_support.mp h1 (zpow_apply_eq_self_of_apply_eq_self h2 n))
@[simp] lemma support_swap {x y : α} (h : x ≠ y) : support (swap x y) = {x, y} :=
begin
ext z,
by_cases hx : z = x,
any_goals { simpa [hx] using h.symm },
by_cases hy : z = y;
{ simp [swap_apply_of_ne_of_ne, hx, hy]; cc }
end
lemma support_swap_iff (x y : α) :
support (swap x y) = {x, y} ↔ x ≠ y :=
begin
refine ⟨λ h H, _, support_swap⟩,
subst H,
simp only [swap_self, support_refl, pair_eq_singleton] at h,
have : x ∈ ∅,
{ rw h,
exact mem_singleton.mpr rfl },
simpa
end
lemma support_swap_mul_swap {x y z : α} (h : list.nodup [x, y, z]) :
support (swap x y * swap y z) = {x, y, z} :=
begin
simp only [list.not_mem_nil, and_true, list.mem_cons_iff, not_false_iff, list.nodup_cons,
list.mem_singleton, and_self, list.nodup_nil] at h,
push_neg at h,
apply le_antisymm,
{ convert support_mul_le _ _,
rw [support_swap h.left.left, support_swap h.right],
ext,
simp [or.comm, or.left_comm] },
{ intro,
simp only [mem_insert, mem_singleton],
rintro (rfl | rfl | rfl | _);
simp [swap_apply_of_ne_of_ne, h.left.left, h.left.left.symm, h.left.right, h.left.right.symm,
h.right.symm] }
end
lemma support_swap_mul_ge_support_diff (f : perm α) (x y : α) :
f.support \ {x, y} ≤ (swap x y * f).support :=
begin
intro,
simp only [and_imp, perm.coe_mul, function.comp_app, ne.def, mem_support, mem_insert, mem_sdiff,
mem_singleton],
push_neg,
rintro ha ⟨hx, hy⟩ H,
rw [swap_apply_eq_iff, swap_apply_of_ne_of_ne hx hy] at H,
exact ha H
end
lemma support_swap_mul_eq (f : perm α) (x : α) (h : f (f x) ≠ x) :
(swap x (f x) * f).support = f.support \ {x} :=
begin
by_cases hx : f x = x,
{ simp [hx, sdiff_singleton_eq_erase, not_mem_support.mpr hx, erase_eq_of_not_mem] },
ext z,
by_cases hzx : z = x,
{ simp [hzx] },
by_cases hzf : z = f x,
{ simp [hzf, hx, h, swap_apply_of_ne_of_ne], },
by_cases hzfx : f z = x,
{ simp [ne.symm hzx, hzx, ne.symm hzf, hzfx] },
{ simp [ne.symm hzx, hzx, ne.symm hzf, hzfx, f.injective.ne hzx, swap_apply_of_ne_of_ne] }
end
lemma mem_support_swap_mul_imp_mem_support_ne {x y : α}
(hy : y ∈ support (swap x (f x) * f)) : y ∈ support f ∧ y ≠ x :=
begin
simp only [mem_support, swap_apply_def, mul_apply, f.injective.eq_iff] at *,
by_cases h : f y = x,
{ split; intro; simp only [*, if_true, eq_self_iff_true, not_true, ne.def] at * },
{ split_ifs at hy; cc }
end
lemma disjoint.mem_imp (h : disjoint f g) {x : α} (hx : x ∈ f.support) :
x ∉ g.support :=
disjoint_left.mp h.disjoint_support hx
lemma eq_on_support_mem_disjoint {l : list (perm α)} (h : f ∈ l) (hl : l.pairwise disjoint) :
∀ (x ∈ f.support), f x = l.prod x :=
begin
induction l with hd tl IH,
{ simpa using h },
{ intros x hx,
rw list.pairwise_cons at hl,
rw list.mem_cons_iff at h,
rcases h with rfl|h,
{ rw [list.prod_cons, mul_apply, not_mem_support.mp
((disjoint_prod_right tl hl.left).mem_imp hx)] },
{ rw [list.prod_cons, mul_apply, ←IH h hl.right _ hx, eq_comm, ←not_mem_support],
refine (hl.left _ h).symm.mem_imp _,
simpa using hx } }
end
lemma disjoint.mono {x y : perm α} (h : disjoint f g)
(hf : x.support ≤ f.support) (hg : y.support ≤ g.support) :
disjoint x y :=
begin
rw disjoint_iff_disjoint_support at h ⊢,
exact h.mono hf hg,
end
lemma support_le_prod_of_mem {l : list (perm α)} (h : f ∈ l) (hl : l.pairwise disjoint) :
f.support ≤ l.prod.support :=
begin
intros x hx,
rwa [mem_support, ←eq_on_support_mem_disjoint h hl _ hx, ←mem_support],
end
section extend_domain
variables {β : Type*} [decidable_eq β] [fintype β] {p : β → Prop} [decidable_pred p]
@[simp]
lemma support_extend_domain (f : α ≃ subtype p) {g : perm α} :
support (g.extend_domain f) = g.support.map f.as_embedding :=
begin
ext b,
simp only [exists_prop, function.embedding.coe_fn_mk, to_embedding_apply, mem_map, ne.def,
function.embedding.trans_apply, mem_support],
by_cases pb : p b,
{ rw [extend_domain_apply_subtype _ _ pb],
split,
{ rintro h,
refine ⟨f.symm ⟨b, pb⟩, _, by simp⟩,
contrapose! h,
simp [h] },
{ rintro ⟨a, ha, hb⟩,
contrapose! ha,
obtain rfl : a = f.symm ⟨b, pb⟩,
{ rw eq_symm_apply,
exact subtype.coe_injective hb },
rw eq_symm_apply,
exact subtype.coe_injective ha } },
{ rw [extend_domain_apply_not_subtype _ _ pb],
simp only [not_exists, false_iff, not_and, eq_self_iff_true, not_true],
rintros a ha rfl,
exact pb (subtype.prop _) }
end
lemma card_support_extend_domain (f : α ≃ subtype p) {g : perm α} :
(g.extend_domain f).support.card = g.support.card :=
by simp
end extend_domain
section card
@[simp]
lemma card_support_eq_zero {f : perm α} :
f.support.card = 0 ↔ f = 1 :=
by rw [finset.card_eq_zero, support_eq_empty_iff]
lemma one_lt_card_support_of_ne_one {f : perm α} (h : f ≠ 1) :
1 < f.support.card :=
begin
simp_rw [one_lt_card_iff, mem_support, ←not_or_distrib],
contrapose! h,
ext a,
specialize h (f a) a,
rwa [apply_eq_iff_eq, or_self, or_self] at h,
end
lemma card_support_ne_one (f : perm α) : f.support.card ≠ 1 :=
begin
by_cases h : f = 1,
{ exact ne_of_eq_of_ne (card_support_eq_zero.mpr h) zero_ne_one },
{ exact ne_of_gt (one_lt_card_support_of_ne_one h) },
end
@[simp] lemma card_support_le_one {f : perm α} : f.support.card ≤ 1 ↔ f = 1 :=
by rw [le_iff_lt_or_eq, nat.lt_succ_iff, le_zero_iff, card_support_eq_zero,
or_iff_not_imp_right, imp_iff_right f.card_support_ne_one]
lemma two_le_card_support_of_ne_one {f : perm α} (h : f ≠ 1) :
2 ≤ f.support.card :=
one_lt_card_support_of_ne_one h
lemma card_support_swap_mul {f : perm α} {x : α}
(hx : f x ≠ x) : (swap x (f x) * f).support.card < f.support.card :=
finset.card_lt_card
⟨λ z hz, (mem_support_swap_mul_imp_mem_support_ne hz).left,
λ h, absurd (h (mem_support.2 hx)) (mt mem_support.1 (by simp))⟩
lemma card_support_swap {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 :=
show (swap x y).support.card = finset.card ⟨x ::ₘ y ::ₘ 0, by simp [hxy]⟩,
from congr_arg card $ by simp [support_swap hxy, *, finset.ext_iff]
@[simp]
lemma card_support_eq_two {f : perm α} : f.support.card = 2 ↔ is_swap f :=
begin
split; intro h,
{ obtain ⟨x, t, hmem, hins, ht⟩ := card_eq_succ.1 h,
obtain ⟨y, rfl⟩ := card_eq_one.1 ht,
rw mem_singleton at hmem,
refine ⟨x, y, hmem, _⟩,
ext a,
have key : ∀ b, f b ≠ b ↔ _ := λ b, by rw [←mem_support, ←hins, mem_insert, mem_singleton],
by_cases ha : f a = a,
{ have ha' := not_or_distrib.mp (mt (key a).mpr (not_not.mpr ha)),
rw [ha, swap_apply_of_ne_of_ne ha'.1 ha'.2] },
{ have ha' := (key (f a)).mp (mt f.apply_eq_iff_eq.mp ha),
obtain rfl | rfl := ((key a).mp ha),
{ rw [or.resolve_left ha' ha, swap_apply_left] },
{ rw [or.resolve_right ha' ha, swap_apply_right] } } },
{ obtain ⟨x, y, hxy, rfl⟩ := h,
exact card_support_swap hxy }
end
lemma disjoint.card_support_mul (h : disjoint f g) :
(f * g).support.card = f.support.card + g.support.card :=
begin
rw ←finset.card_disjoint_union,
{ congr,
ext,
simp [h.support_mul] },
{ simpa using h.disjoint_support }
end
lemma card_support_prod_list_of_pairwise_disjoint {l : list (perm α)}
(h : l.pairwise disjoint) :
l.prod.support.card = (l.map (finset.card ∘ support)).sum :=
begin
induction l with a t ih,
{ exact card_support_eq_zero.mpr rfl, },
{ obtain ⟨ha, ht⟩ := list.pairwise_cons.1 h,
rw [list.prod_cons, list.map_cons, list.sum_cons, ←ih ht],
exact (disjoint_prod_right _ ha).card_support_mul }
end
end card
end support
@[simp] lemma support_subtype_perm [decidable_eq α] {s : finset α} (f : perm α) (h) :
(f.subtype_perm h : perm {x // x ∈ s}).support = s.attach.filter (λ x, f x ≠ x) :=
by { ext, simp [subtype.ext_iff] }
end equiv.perm
|
0b5e06c57f7095cf1e158c346f957f7c1ff69d4a | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/data/complex/basic.lean | d214ec8dfc41ae9f6a84a77deb8b66988571eedd | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,113 | lean | /-
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Mario Carneiro
-/
import data.real.sqrt
/-!
# The complex numbers
The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field
of characteristic zero. The result that the complex numbers are algebraically closed, see
`field_theory.algebraic_closure`.
-/
open_locale big_operators
/-! ### Definition and basic arithmmetic -/
/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/
structure complex : Type :=
(re : ℝ) (im : ℝ)
notation `ℂ` := complex
namespace complex
noncomputable instance : decidable_eq ℂ := classical.dec_eq _
/-- The equivalence between the complex numbers and `ℝ × ℝ`. -/
def equiv_real_prod : ℂ ≃ (ℝ × ℝ) :=
{ to_fun := λ z, ⟨z.re, z.im⟩,
inv_fun := λ p, ⟨p.1, p.2⟩,
left_inv := λ ⟨x, y⟩, rfl,
right_inv := λ ⟨x, y⟩, rfl }
@[simp] theorem equiv_real_prod_apply (z : ℂ) : equiv_real_prod z = (z.re, z.im) := rfl
theorem equiv_real_prod_symm_re (x y : ℝ) : (equiv_real_prod.symm (x, y)).re = x := rfl
theorem equiv_real_prod_symm_im (x y : ℝ) : (equiv_real_prod.symm (x, y)).im = y := rfl
@[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z
| ⟨a, b⟩ := rfl
@[ext]
theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w
| ⟨zr, zi⟩ ⟨_, _⟩ rfl rfl := rfl
theorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=
⟨λ H, by simp [H], and.rec ext⟩
instance : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩
@[simp, norm_cast] lemma of_real_re (r : ℝ) : (r : ℂ).re = r := rfl
@[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl
lemma of_real_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl
@[simp, norm_cast] theorem of_real_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w :=
⟨congr_arg re, congr_arg _⟩
instance : has_zero ℂ := ⟨(0 : ℝ)⟩
instance : inhabited ℂ := ⟨0⟩
@[simp] lemma zero_re : (0 : ℂ).re = 0 := rfl
@[simp] lemma zero_im : (0 : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma of_real_zero : ((0 : ℝ) : ℂ) = 0 := rfl
@[simp] theorem of_real_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := of_real_inj
theorem of_real_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr of_real_eq_zero
instance : has_one ℂ := ⟨(1 : ℝ)⟩
@[simp] lemma one_re : (1 : ℂ).re = 1 := rfl
@[simp] lemma one_im : (1 : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl
instance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩
@[simp] lemma add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl
@[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl
@[simp] lemma bit0_re (z : ℂ) : (bit0 z).re = bit0 z.re := rfl
@[simp] lemma bit1_re (z : ℂ) : (bit1 z).re = bit1 z.re := rfl
@[simp] lemma bit0_im (z : ℂ) : (bit0 z).im = bit0 z.im := eq.refl _
@[simp] lemma bit1_im (z : ℂ) : (bit1 z).im = bit0 z.im := add_zero _
@[simp, norm_cast] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=
ext_iff.2 $ by simp
@[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r :=
ext_iff.2 $ by simp [bit0]
@[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r :=
ext_iff.2 $ by simp [bit1]
instance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩
@[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl
@[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl
@[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp
instance : has_sub ℂ := ⟨λ z w, ⟨z.re - w.re, z.im - w.im⟩⟩
instance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩
@[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl
@[simp] lemma mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl
@[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 $ by simp
lemma of_real_mul_re (r : ℝ) (z : ℂ) : (↑r * z).re = r * z.re := by simp
lemma of_real_mul_im (r : ℝ) (z : ℂ) : (↑r * z).im = r * z.im := by simp
lemma of_real_mul' (r : ℝ) (z : ℂ) : (↑r * z) = ⟨r * z.re, r * z.im⟩ :=
ext (of_real_mul_re _ _) (of_real_mul_im _ _)
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
def I : ℂ := ⟨0, 1⟩
@[simp] lemma I_re : I.re = 0 := rfl
@[simp] lemma I_im : I.im = 1 := rfl
@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp
lemma I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ :=
ext_iff.2 $ by simp
lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm
lemma mk_eq_add_mul_I (a b : ℝ) : complex.mk a b = a + b * I :=
ext_iff.2 $ by simp
@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=
ext_iff.2 $ by simp
/-! ### Commutative ring instance and lemmas -/
/- We use a nonstandard formula for the `ℕ` and `ℤ` actions to make sure there is no
diamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity
defined in `data.complex.module.lean`. -/
instance : comm_ring ℂ :=
by refine_struct
{ zero := (0 : ℂ),
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
one := 1,
mul := (*),
zero_add := λ z, by { apply ext_iff.2, simp },
add_zero := λ z, by { apply ext_iff.2, simp },
nsmul := λ n z, ⟨n • z.re - 0 * z.im, n • z.im + 0 * z.re⟩,
npow := @npow_rec _ ⟨(1)⟩ ⟨(*)⟩,
gsmul := λ n z, ⟨n • z.re - 0 * z.im, n • z.im + 0 * z.re⟩ };
intros; try { refl }; apply ext_iff.2; split; simp; {ring1 <|> ring_nf}
/-- This shortcut instance ensures we do not find `ring` via the noncomputable `complex.field`
instance. -/
instance : ring ℂ := by apply_instance
/-- The "real part" map, considered as an additive group homomorphism. -/
def re_add_group_hom : ℂ →+ ℝ :=
{ to_fun := re,
map_zero' := zero_re,
map_add' := add_re }
@[simp] lemma coe_re_add_group_hom : (re_add_group_hom : ℂ → ℝ) = re := rfl
/-- The "imaginary part" map, considered as an additive group homomorphism. -/
def im_add_group_hom : ℂ →+ ℝ :=
{ to_fun := im,
map_zero' := zero_im,
map_add' := add_im }
@[simp] lemma coe_im_add_group_hom : (im_add_group_hom : ℂ → ℝ) = im := rfl
@[simp] lemma I_pow_bit0 (n : ℕ) : I ^ (bit0 n) = (-1) ^ n :=
by rw [pow_bit0', I_mul_I]
@[simp] lemma I_pow_bit1 (n : ℕ) : I ^ (bit1 n) = (-1) ^ n * I :=
by rw [pow_bit1', I_mul_I]
/-! ### Complex conjugation -/
/-- The complex conjugate. -/
def conj : ℂ →+* ℂ :=
begin
refine_struct { to_fun := λ z : ℂ, (⟨z.re, -z.im⟩ : ℂ), .. };
{ intros, ext; simp [add_comm], },
end
@[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl
@[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl
@[simp] lemma conj_of_real (r : ℝ) : conj r = r := ext_iff.2 $ by simp [conj]
@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp
@[simp] lemma conj_bit0 (z : ℂ) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]
@[simp] lemma conj_bit1 (z : ℂ) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]
@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp
@[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z :=
ext_iff.2 $ by simp
lemma conj_involutive : function.involutive conj := conj_conj
lemma conj_bijective : function.bijective conj := conj_involutive.bijective
lemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w :=
conj_bijective.1.eq_iff
@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=
by simpa using @conj_inj z 0
lemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
⟨λ h, ⟨z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)⟩,
λ ⟨h, e⟩, by rw [e, conj_of_real]⟩
lemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩
lemma conj_sub (z z': ℂ) : conj (z - z') = conj z - conj z' := conj.map_sub z z'
lemma conj_one : conj 1 = 1 := by rw conj.map_one
lemma eq_conj_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 :=
⟨λ h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),
λ h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩
instance : star_ring ℂ :=
{ star := λ z, conj z,
star_involutive := λ z, by simp,
star_mul := λ r s, by { ext; simp [mul_comm], },
star_add := by simp, }
/-! ### Norm squared -/
/-- The norm squared function. -/
@[pp_nodot] def norm_sq : monoid_with_zero_hom ℂ ℝ :=
{ to_fun := λ z, z.re * z.re + z.im * z.im,
map_zero' := by simp,
map_one' := by simp,
map_mul' := λ z w, by { dsimp, ring } }
lemma norm_sq_apply (z : ℂ) : norm_sq z = z.re * z.re + z.im * z.im := rfl
@[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r :=
by simp [norm_sq]
lemma norm_sq_eq_conj_mul_self {z : ℂ} : (norm_sq z : ℂ) = conj z * z :=
by { ext; simp [norm_sq, mul_comm], }
@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero
@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one
@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]
lemma norm_sq_nonneg (z : ℂ) : 0 ≤ norm_sq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
lemma norm_sq_eq_zero {z : ℂ} : norm_sq z = 0 ↔ z = 0 :=
⟨λ h, ext
(eq_zero_of_mul_self_add_mul_self_eq_zero h)
(eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),
λ h, h.symm ▸ norm_sq_zero⟩
@[simp] lemma norm_sq_pos {z : ℂ} : 0 < norm_sq z ↔ z ≠ 0 :=
(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)
@[simp] lemma norm_sq_neg (z : ℂ) : norm_sq (-z) = norm_sq z :=
by simp [norm_sq]
@[simp] lemma norm_sq_conj (z : ℂ) : norm_sq (conj z) = norm_sq z :=
by simp [norm_sq]
lemma norm_sq_mul (z w : ℂ) : norm_sq (z * w) = norm_sq z * norm_sq w :=
norm_sq.map_mul z w
lemma norm_sq_add (z w : ℂ) : norm_sq (z + w) =
norm_sq z + norm_sq w + 2 * (z * conj w).re :=
by dsimp [norm_sq]; ring
lemma re_sq_le_norm_sq (z : ℂ) : z.re * z.re ≤ norm_sq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
lemma im_sq_le_norm_sq (z : ℂ) : z.im * z.im ≤ norm_sq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : ℂ) : z * conj z = norm_sq z :=
ext_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]
theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
ext_iff.2 $ by simp [two_mul]
/-- The coercion `ℝ → ℂ` as a `ring_hom`. -/
def of_real : ℝ →+* ℂ := ⟨coe, of_real_one, of_real_mul, of_real_zero, of_real_add⟩
@[simp] lemma of_real_eq_coe (r : ℝ) : of_real r = r := rfl
@[simp] lemma I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]
@[simp] lemma sub_re (z w : ℂ) : (z - w).re = z.re - w.re := rfl
@[simp] lemma sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl
@[simp, norm_cast] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := ext_iff.2 $ by simp
@[simp, norm_cast] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = r ^ n :=
by induction n; simp [*, of_real_mul, pow_succ]
theorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I :=
ext_iff.2 $ by simp [two_mul, sub_eq_add_neg]
lemma norm_sq_sub (z w : ℂ) : norm_sq (z - w) =
norm_sq z + norm_sq w - 2 * (z * conj w).re :=
by rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re, add_comm, add_left_comm, sub_eq_add_neg]
/-! ### Inversion -/
noncomputable instance : has_inv ℂ := ⟨λ z, conj z * ((norm_sq z)⁻¹:ℝ)⟩
theorem inv_def (z : ℂ) : z⁻¹ = conj z * ((norm_sq z)⁻¹:ℝ) := rfl
@[simp] lemma inv_re (z : ℂ) : (z⁻¹).re = z.re / norm_sq z := by simp [inv_def, division_def]
@[simp] lemma inv_im (z : ℂ) : (z⁻¹).im = -z.im / norm_sq z := by simp [inv_def, division_def]
@[simp, norm_cast] lemma of_real_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = r⁻¹ :=
ext_iff.2 $ by simp
protected lemma inv_zero : (0⁻¹ : ℂ) = 0 :=
by rw [← of_real_zero, ← of_real_inv, inv_zero]
protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 :=
by rw [inv_def, ← mul_assoc, mul_conj, ← of_real_mul,
mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]
/-! ### Field instance and lemmas -/
noncomputable instance : field ℂ :=
{ inv := has_inv.inv,
exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩,
mul_inv_cancel := @complex.mul_inv_cancel,
inv_zero := complex.inv_zero,
..complex.comm_ring }
@[simp] lemma I_fpow_bit0 (n : ℤ) : I ^ (bit0 n) = (-1) ^ n :=
by rw [fpow_bit0', I_mul_I]
@[simp] lemma I_fpow_bit1 (n : ℤ) : I ^ (bit1 n) = (-1) ^ n * I :=
by rw [fpow_bit1', I_mul_I]
lemma div_re (z w : ℂ) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]
lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]
@[simp, norm_cast] lemma of_real_div (r s : ℝ) : ((r / s : ℝ) : ℂ) = r / s :=
of_real.map_div r s
@[simp, norm_cast] lemma of_real_fpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n :=
of_real.map_fpow r n
@[simp] lemma div_I (z : ℂ) : z / I = -(z * I) :=
(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]
@[simp] lemma inv_I : I⁻¹ = -I :=
by simp [inv_eq_one_div]
@[simp] lemma norm_sq_inv (z : ℂ) : norm_sq z⁻¹ = (norm_sq z)⁻¹ :=
norm_sq.map_inv' z
@[simp] lemma norm_sq_div (z w : ℂ) : norm_sq (z / w) = norm_sq z / norm_sq w :=
norm_sq.map_div z w
/-! ### Cast lemmas -/
@[simp, norm_cast] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n :=
of_real.map_nat_cast n
@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=
by rw [← of_real_nat_cast, of_real_re]
@[simp, norm_cast] lemma nat_cast_im (n : ℕ) : (n : ℂ).im = 0 :=
by rw [← of_real_nat_cast, of_real_im]
@[simp, norm_cast] theorem of_real_int_cast (n : ℤ) : ((n : ℝ) : ℂ) = n :=
of_real.map_int_cast n
@[simp, norm_cast] lemma int_cast_re (n : ℤ) : (n : ℂ).re = n :=
by rw [← of_real_int_cast, of_real_re]
@[simp, norm_cast] lemma int_cast_im (n : ℤ) : (n : ℂ).im = 0 :=
by rw [← of_real_int_cast, of_real_im]
@[simp, norm_cast] theorem of_real_rat_cast (n : ℚ) : ((n : ℝ) : ℂ) = n :=
of_real.map_rat_cast n
@[simp, norm_cast] lemma rat_cast_re (q : ℚ) : (q : ℂ).re = q :=
by rw [← of_real_rat_cast, of_real_re]
@[simp, norm_cast] lemma rat_cast_im (q : ℚ) : (q : ℂ).im = 0 :=
by rw [← of_real_rat_cast, of_real_im]
/-! ### Characteristic zero -/
instance char_zero_complex : char_zero ℂ :=
char_zero_of_inj_zero $ λ n h,
by rwa [← of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h
/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/
theorem re_eq_add_conj (z : ℂ) : (z.re : ℂ) = (z + conj z) / 2 :=
by simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,
mul_div_cancel_left (z.re:ℂ) two_ne_zero']
/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/
theorem im_eq_sub_conj (z : ℂ) : (z.im : ℂ) = (z - conj(z))/(2 * I) :=
by simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,
mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I ≠ 0)]
/-! ### Absolute value -/
/-- The complex absolute value function, defined as the square root of the norm squared. -/
@[pp_nodot] noncomputable def abs (z : ℂ) : ℝ := (norm_sq z).sqrt
local notation `abs'` := _root_.abs
@[simp, norm_cast] lemma abs_of_real (r : ℝ) : abs r = abs' r :=
by simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]
lemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : abs r = r :=
(abs_of_real _).trans (abs_of_nonneg h)
lemma abs_of_nat (n : ℕ) : complex.abs n = n :=
calc complex.abs n = complex.abs (n:ℝ) : by rw [of_real_nat_cast]
... = _ : abs_of_nonneg (nat.cast_nonneg n)
lemma mul_self_abs (z : ℂ) : abs z * abs z = norm_sq z :=
real.mul_self_sqrt (norm_sq_nonneg _)
@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]
@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]
@[simp] lemma abs_I : abs I = 1 := by simp [abs]
@[simp] lemma abs_two : abs 2 = 2 :=
calc abs 2 = abs (2 : ℝ) : by rw [of_real_bit0, of_real_one]
... = (2 : ℝ) : abs_of_nonneg (by norm_num)
lemma abs_nonneg (z : ℂ) : 0 ≤ abs z :=
real.sqrt_nonneg _
@[simp] lemma abs_eq_zero {z : ℂ} : abs z = 0 ↔ z = 0 :=
(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero
lemma abs_ne_zero {z : ℂ} : abs z ≠ 0 ↔ z ≠ 0 :=
not_congr abs_eq_zero
@[simp] lemma abs_conj (z : ℂ) : abs (conj z) = abs z :=
by simp [abs]
@[simp] lemma abs_mul (z w : ℂ) : abs (z * w) = abs z * abs w :=
by rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl
lemma abs_re_le_abs (z : ℂ) : abs' z.re ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply re_sq_le_norm_sq
lemma abs_im_le_abs (z : ℂ) : abs' z.im ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply im_sq_le_norm_sq
lemma re_le_abs (z : ℂ) : z.re ≤ abs z :=
(abs_le.1 (abs_re_le_abs _)).2
lemma im_le_abs (z : ℂ) : z.im ≤ abs z :=
(abs_le.1 (abs_im_le_abs _)).2
/--
The **triangle inequality** for complex numbers.
-/
lemma abs_add (z w : ℂ) : abs (z + w) ≤ abs z + abs w :=
(mul_self_le_mul_self_iff (abs_nonneg _)
(add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $
begin
rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,
add_right_comm, norm_sq_add, add_le_add_iff_left,
mul_assoc, mul_le_mul_left (@zero_lt_two ℝ _ _)],
simpa [-mul_re] using re_le_abs (z * conj w)
end
instance : is_absolute_value abs :=
{ abv_nonneg := abs_nonneg,
abv_eq_zero := λ _, abs_eq_zero,
abv_add := abs_add,
abv_mul := abs_mul }
open is_absolute_value
@[simp] lemma abs_abs (z : ℂ) : abs' (abs z) = abs z :=
_root_.abs_of_nonneg (abs_nonneg _)
@[simp] lemma abs_pos {z : ℂ} : 0 < abs z ↔ z ≠ 0 := abv_pos abs
@[simp] lemma abs_neg : ∀ z, abs (-z) = abs z := abv_neg abs
lemma abs_sub_comm : ∀ z w, abs (z - w) = abs (w - z) := abv_sub abs
lemma abs_sub_le : ∀ a b c, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs
@[simp] theorem abs_inv : ∀ z, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs
@[simp] theorem abs_div : ∀ z w, abs (z / w) = abs z / abs w := abv_div abs
lemma abs_abs_sub_le_abs_sub : ∀ z w, abs' (abs z - abs w) ≤ abs (z - w) :=
abs_abv_sub_le_abv_sub abs
lemma abs_le_abs_re_add_abs_im (z : ℂ) : abs z ≤ abs' z.re + abs' z.im :=
by simpa [re_add_im] using abs_add z.re (z.im * I)
lemma abs_re_div_abs_le_one (z : ℂ) : abs' (z.re / z.abs) ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }
lemma abs_im_div_abs_le_one (z : ℂ) : abs' (z.im / z.abs) ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }
@[simp, norm_cast] lemma abs_cast_nat (n : ℕ) : abs (n : ℂ) = n :=
by rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]
@[simp, norm_cast] lemma int_cast_abs (n : ℤ) : ↑(abs' n) = abs n :=
by rw [← of_real_int_cast, abs_of_real, int.cast_abs]
lemma norm_sq_eq_abs (x : ℂ) : norm_sq x = abs x ^ 2 :=
by rw [abs, sq, real.mul_self_sqrt (norm_sq_nonneg _)]
/--
We put a partial order on ℂ so that `z ≤ w` exactly if `w - z` is real and nonnegative.
Complex numbers with different imaginary parts are incomparable.
-/
def complex_order : partial_order ℂ :=
{ le := λ z w, ∃ x : ℝ, 0 ≤ x ∧ w = z + x,
le_refl := λ x, ⟨0, by simp⟩,
le_trans := λ x y z h₁ h₂,
begin
obtain ⟨w₁, l₁, rfl⟩ := h₁,
obtain ⟨w₂, l₂, rfl⟩ := h₂,
refine ⟨w₁ + w₂, _, _⟩,
{ linarith, },
{ simp [add_assoc], },
end,
le_antisymm := λ z w h₁ h₂,
begin
obtain ⟨w₁, l₁, rfl⟩ := h₁,
obtain ⟨w₂, l₂, e⟩ := h₂,
have h₃ : w₁ + w₂ = 0,
{ symmetry,
rw add_assoc at e,
apply of_real_inj.mp,
apply add_left_cancel,
convert e; simp, },
have h₄ : w₁ = 0, linarith,
simp [h₄],
end, }
localized "attribute [instance] complex_order" in complex_order
section complex_order
open_locale complex_order
lemma le_def {z w : ℂ} : z ≤ w ↔ ∃ x : ℝ, 0 ≤ x ∧ w = z + x := iff.refl _
lemma lt_def {z w : ℂ} : z < w ↔ ∃ x : ℝ, 0 < x ∧ w = z + x :=
begin
rw [lt_iff_le_not_le],
fsplit,
{ rintro ⟨⟨x, l, rfl⟩, h⟩,
by_cases hx : x = 0,
{ simpa [hx] using h },
{ replace l : 0 < x := l.lt_of_ne (ne.symm hx),
exact ⟨x, l, rfl⟩, } },
{ rintro ⟨x, l, rfl⟩,
fsplit,
{ exact ⟨x, l.le, rfl⟩, },
{ rintro ⟨x', l', e⟩,
rw [add_assoc] at e,
replace e := add_left_cancel (by { convert e, simp }),
norm_cast at e,
linarith, } }
end
@[simp, norm_cast] lemma real_le_real {x y : ℝ} : (x : ℂ) ≤ (y : ℂ) ↔ x ≤ y :=
begin
rw [le_def],
fsplit,
{ rintro ⟨r, l, e⟩,
norm_cast at e,
subst e,
exact le_add_of_nonneg_right l, },
{ intro h,
exact ⟨y - x, sub_nonneg.mpr h, (by simp)⟩, },
end
@[simp, norm_cast] lemma real_lt_real {x y : ℝ} : (x : ℂ) < (y : ℂ) ↔ x < y :=
begin
rw [lt_def],
fsplit,
{ rintro ⟨r, l, e⟩,
norm_cast at e,
subst e,
exact lt_add_of_pos_right x l, },
{ intro h,
exact ⟨y - x, sub_pos.mpr h, (by simp)⟩, },
end
@[simp, norm_cast] lemma zero_le_real {x : ℝ} : (0 : ℂ) ≤ (x : ℂ) ↔ 0 ≤ x := real_le_real
@[simp, norm_cast] lemma zero_lt_real {x : ℝ} : (0 : ℂ) < (x : ℂ) ↔ 0 < x := real_lt_real
/--
With `z ≤ w` iff `w - z` is real and nonnegative, `ℂ` is an ordered ring.
-/
def complex_ordered_comm_ring : ordered_comm_ring ℂ :=
{ zero_le_one := ⟨1, zero_le_one, by simp⟩,
add_le_add_left := λ w z h y,
begin
obtain ⟨x, l, rfl⟩ := h,
exact ⟨x, l, by simp [add_assoc]⟩,
end,
mul_pos := λ z w hz hw,
begin
obtain ⟨zx, lz, rfl⟩ := lt_def.mp hz,
obtain ⟨wx, lw, rfl⟩ := lt_def.mp hw,
norm_cast,
simp only [mul_pos, lz, lw, zero_add],
end,
le_of_add_le_add_left := λ u v z h,
begin
obtain ⟨x, l, e⟩ := h,
rw add_assoc at e,
exact ⟨x, l, add_left_cancel e⟩,
end,
mul_lt_mul_of_pos_left := λ u v z h₁ h₂,
begin
obtain ⟨x₁, l₁, rfl⟩ := lt_def.mp h₁,
obtain ⟨x₂, l₂, rfl⟩ := lt_def.mp h₂,
simp only [mul_add, zero_add],
exact lt_def.mpr ⟨x₂ * x₁, mul_pos l₂ l₁, (by norm_cast)⟩,
end,
mul_lt_mul_of_pos_right := λ u v z h₁ h₂,
begin
obtain ⟨x₁, l₁, rfl⟩ := lt_def.mp h₁,
obtain ⟨x₂, l₂, rfl⟩ := lt_def.mp h₂,
simp only [add_mul, zero_add],
exact lt_def.mpr ⟨x₁ * x₂, mul_pos l₁ l₂, (by norm_cast)⟩,
end,
-- we need more instances here because comm_ring doesn't have zero_add et al as fields,
-- they are derived as lemmas
..(by apply_instance : partial_order ℂ),
..(by apply_instance : comm_ring ℂ),
..(by apply_instance : comm_semiring ℂ),
..(by apply_instance : add_cancel_monoid ℂ) }
localized "attribute [instance] complex_ordered_comm_ring" in complex_order
/--
With `z ≤ w` iff `w - z` is real and nonnegative, `ℂ` is a star ordered ring.
(That is, an ordered ring in which every element of the form `star z * z` is nonnegative.)
In fact, the nonnegative elements are precisely those of this form.
This hold in any `C^*`-algebra, e.g. `ℂ`,
but we don't yet have `C^*`-algebras in mathlib.
-/
def complex_star_ordered_ring : star_ordered_ring ℂ :=
{ star_mul_self_nonneg := λ z,
begin
refine ⟨z.abs^2, pow_nonneg (abs_nonneg z) 2, _⟩,
simp only [has_star.star, of_real_pow, zero_add],
norm_cast,
rw [←norm_sq_eq_abs, norm_sq_eq_conj_mul_self],
end, }
localized "attribute [instance] complex_star_ordered_ring" in complex_order
end complex_order
/-! ### Cauchy sequences -/
theorem is_cau_seq_re (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).re) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)
theorem is_cau_seq_im (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).im) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)
/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_re (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_re f⟩
/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_im (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_im f⟩
lemma is_cau_seq_abs {f : ℕ → ℂ} (hf : is_cau_seq abs f) :
is_cau_seq abs' (abs ∘ f) :=
λ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩
/-- The limit of a Cauchy sequence of complex numbers. -/
noncomputable def lim_aux (f : cau_seq ℂ abs) : ℂ :=
⟨cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)⟩
theorem equiv_lim_aux (f : cau_seq ℂ abs) : f ≈ cau_seq.const abs (lim_aux f) :=
λ ε ε0, (exists_forall_ge_and
(cau_seq.equiv_lim ⟨_, is_cau_seq_re f⟩ _ (half_pos ε0))
(cau_seq.equiv_lim ⟨_, is_cau_seq_im f⟩ _ (half_pos ε0))).imp $
λ i H j ij, begin
cases H _ ij with H₁ H₂,
apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),
dsimp [lim_aux] at *,
have := add_lt_add H₁ H₂,
rwa add_halves at this,
end
noncomputable instance : cau_seq.is_complete ℂ abs :=
⟨λ f, ⟨lim_aux f, equiv_lim_aux f⟩⟩
open cau_seq
lemma lim_eq_lim_im_add_lim_re (f : cau_seq ℂ abs) : lim f =
↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I :=
lim_eq_of_equiv_const $
calc f ≈ _ : equiv_lim_aux f
... = cau_seq.const abs (↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I) :
cau_seq.ext (λ _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))
lemma lim_re (f : cau_seq ℂ abs) : lim (cau_seq_re f) = (lim f).re :=
by rw [lim_eq_lim_im_add_lim_re]; simp
lemma lim_im (f : cau_seq ℂ abs) : lim (cau_seq_im f) = (lim f).im :=
by rw [lim_eq_lim_im_add_lim_re]; simp
lemma is_cau_seq_conj (f : cau_seq ℂ abs) : is_cau_seq abs (λ n, conj (f n)) :=
λ ε ε0, let ⟨i, hi⟩ := f.2 ε ε0 in
⟨i, λ j hj, by rw [← conj.map_sub, abs_conj]; exact hi j hj⟩
/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/
noncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs :=
⟨_, is_cau_seq_conj f⟩
lemma lim_conj (f : cau_seq ℂ abs) : lim (cau_seq_conj f) = conj (lim f) :=
complex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])
(by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)
/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_abs (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_abs f.2⟩
lemma lim_abs (f : cau_seq ℂ abs) : lim (cau_seq_abs f) = abs (lim f) :=
lim_eq_of_equiv_const (λ ε ε0,
let ⟨i, hi⟩ := equiv_lim f ε ε0 in
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩)
@[simp, norm_cast] lemma of_real_prod {α : Type*} (s : finset α) (f : α → ℝ) :
((∏ i in s, f i : ℝ) : ℂ) = ∏ i in s, (f i : ℂ) :=
ring_hom.map_prod of_real _ _
@[simp, norm_cast] lemma of_real_sum {α : Type*} (s : finset α) (f : α → ℝ) :
((∑ i in s, f i : ℝ) : ℂ) = ∑ i in s, (f i : ℂ) :=
ring_hom.map_sum of_real _ _
end complex
|
1b7df030f024ec42b2cddbe134941878668d5194 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Init/System/FilePath.lean | 80cc352c1936cbcd2105146dcfe40c79354fe542 | [
"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 | 4,214 | 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.System.Platform
import Init.Data.String.Basic
import Init.Data.Repr
import Init.Data.ToString.Basic
namespace System
open Platform
structure FilePath where
toString : String
deriving Inhabited, DecidableEq, Hashable
instance : Repr FilePath where
reprPrec p := Repr.addAppParen ("FilePath.mk " ++ repr p.toString)
instance : ToString FilePath where
toString p := p.toString
namespace FilePath
/-- The character that separates directories. In the case where more than one character is possible, `pathSeparator` is the 'ideal' one. -/
def pathSeparator : Char :=
if isWindows then '\\' else '/'
/-- The list of all possible separators. -/
def pathSeparators : List Char :=
if isWindows then ['\\', '/'] else ['/']
/-- File extension character -/
def extSeparator : Char := '.'
def exeExtension : String :=
if isWindows then "exe" else ""
-- TODO: normalize `a/`, `a//b`, etc.
def normalize (p : FilePath) : FilePath := Id.run do
let mut p := p
-- normalize drive letter
if isWindows && p.toString.length >= 2 && (p.toString.get 0).isLower && p.toString.get ⟨1⟩ == ':' then
p := ⟨p.toString.set 0 (p.toString.get 0).toUpper⟩
-- normalize separator
unless pathSeparators.length == 1 do
p := ⟨p.toString.map fun c => if pathSeparators.contains c then pathSeparator else c⟩
return p
-- the following functions follow the names and semantics from Rust's `std::path::Path`
def isAbsolute (p : FilePath) : Bool :=
pathSeparators.contains p.toString.front || (isWindows && p.toString.length > 1 && p.toString.iter.next.curr == ':')
def isRelative (p : FilePath) : Bool :=
!p.isAbsolute
def join (p sub : FilePath) : FilePath :=
if sub.isAbsolute then
sub
else
⟨p.toString ++ pathSeparator.toString ++ sub.toString⟩
instance : Div FilePath where
div := FilePath.join
instance : HDiv FilePath String FilePath where
hDiv p sub := FilePath.join p ⟨sub⟩
private def posOfLastSep (p : FilePath) : Option String.Pos :=
p.toString.revFind pathSeparators.contains
def parent (p : FilePath) : Option FilePath :=
FilePath.mk <$> p.toString.extract {} <$> posOfLastSep p
def fileName (p : FilePath) : Option String :=
let lastPart := match posOfLastSep p with
| some sepPos => p.toString.extract (sepPos + '/') p.toString.endPos
| none => p.toString
if lastPart.isEmpty || lastPart == "." || lastPart == ".." then none else some lastPart
/-- Extracts the stem (non-extension) part of `p.fileName`. -/
def fileStem (p : FilePath) : Option String :=
p.fileName.map fun fname =>
match fname.revPosOf '.' with
| some ⟨0⟩ => fname
| some pos => fname.extract 0 pos
| none => fname
def extension (p : FilePath) : Option String :=
p.fileName.bind fun fname =>
match fname.revPosOf '.' with
| some 0 => none
| some pos => fname.extract (pos + '.') fname.endPos
| none => none
def withFileName (p : FilePath) (fname : String) : FilePath :=
match p.parent with
| none => ⟨fname⟩
| some p => p / fname
def withExtension (p : FilePath) (ext : String) : FilePath :=
match p.fileStem with
| none => p
| some stem => p.withFileName (if ext.isEmpty then stem else stem ++ "." ++ ext)
def components (p : FilePath) : List String :=
p.normalize |>.toString.splitOn pathSeparator.toString
end FilePath
def mkFilePath (parts : List String) : FilePath :=
⟨String.intercalate FilePath.pathSeparator.toString parts⟩
instance : Coe String FilePath where
coe := FilePath.mk
abbrev SearchPath := List FilePath
namespace SearchPath
/-- The character that is used to separate the entries in the $PATH (or %PATH%) environment variable. -/
protected def separator : Char :=
if isWindows then ';' else ':'
def parse (s : String) : SearchPath :=
s.split (fun c => SearchPath.separator == c) |>.map FilePath.mk
def toString (path : SearchPath) : String :=
SearchPath.separator.toString.intercalate (path.map FilePath.toString)
end SearchPath
end System
|
8d7603f3c4e165c27534d2864ac0eeb4b2a1fc30 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/order/pi.lean | bc62e3627bcc2ef4829eca184813847eede74779 | [
"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,071 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import algebra.order.ring.defs
import algebra.ring.pi
import tactic.positivity
/-!
# Pi instances for ordered groups and monoids
This file defines instances for ordered group, monoid, and related structures on Pi types.
-/
universes u v w
variables {ι α β : Type*}
variable {I : Type u} -- The indexing type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
namespace pi
/-- The product of a family of ordered commutative monoids is an ordered commutative monoid. -/
@[to_additive "The product of a family of ordered additive commutative monoids is
an ordered additive commutative monoid."]
instance ordered_comm_monoid {ι : Type*} {Z : ι → Type*} [∀ i, ordered_comm_monoid (Z i)] :
ordered_comm_monoid (Π i, Z i) :=
{ mul_le_mul_left := λ f g w h i, mul_le_mul_left' (w i) _,
..pi.partial_order,
..pi.comm_monoid, }
@[to_additive] instance {ι : Type*} {α : ι → Type*} [Π i, has_le (α i)] [Π i, has_mul (α i)]
[Π i, has_exists_mul_of_le (α i)] :
has_exists_mul_of_le (Π i, α i) :=
⟨λ a b h, ⟨λ i, (exists_mul_of_le $ h i).some, funext $ λ i, (exists_mul_of_le $ h i).some_spec⟩⟩
/-- The product of a family of canonically ordered monoids is a canonically ordered monoid. -/
@[to_additive "The product of a family of canonically ordered additive monoids is
a canonically ordered additive monoid."]
instance {ι : Type*} {Z : ι → Type*} [∀ i, canonically_ordered_monoid (Z i)] :
canonically_ordered_monoid (Π i, Z i) :=
{ le_self_mul := λ f g i, le_self_mul,
..pi.order_bot, ..pi.ordered_comm_monoid, ..pi.has_exists_mul_of_le }
@[to_additive]
instance ordered_cancel_comm_monoid [∀ i, ordered_cancel_comm_monoid $ f i] :
ordered_cancel_comm_monoid (Π i : I, f i) :=
by refine_struct { mul := (*), one := (1 : Π i, f i), le := (≤), lt := (<),
npow := monoid.npow, .. pi.partial_order, .. pi.monoid };
tactic.pi_instance_derive_field
@[to_additive]
instance ordered_comm_group [∀ i, ordered_comm_group $ f i] :
ordered_comm_group (Π i : I, f i) :=
{ mul := (*), one := (1 : Π i, f i), le := (≤), lt := (<),
npow := monoid.npow,
..pi.comm_group,
..pi.ordered_comm_monoid, }
instance [Π i, ordered_semiring (f i)] : ordered_semiring (Π i, f i) :=
{ add_le_add_left := λ a b hab c i, add_le_add_left (hab _) _,
zero_le_one := λ _, zero_le_one,
mul_le_mul_of_nonneg_left := λ a b c hab hc i, mul_le_mul_of_nonneg_left (hab _) $ hc _,
mul_le_mul_of_nonneg_right := λ a b c hab hc i, mul_le_mul_of_nonneg_right (hab _) $ hc _,
..pi.semiring, ..pi.partial_order }
instance [Π i, ordered_comm_semiring (f i)] : ordered_comm_semiring (Π i, f i) :=
{ ..pi.comm_semiring, ..pi.ordered_semiring }
instance [Π i, ordered_ring (f i)] : ordered_ring (Π i, f i) :=
{ mul_nonneg := λ a b ha hb i, mul_nonneg (ha _) (hb _),
..pi.ring, ..pi.ordered_semiring }
instance [Π i, ordered_comm_ring (f i)] : ordered_comm_ring (Π i, f i) :=
{ ..pi.comm_ring, ..pi.ordered_ring }
end pi
namespace function
variables (β) [has_one α] [preorder α] {a : α}
@[to_additive const_nonneg_of_nonneg]
lemma one_le_const_of_one_le (ha : 1 ≤ a) : 1 ≤ const β a := λ _, ha
@[to_additive] lemma const_le_one_of_le_one (ha : a ≤ 1) : const β a ≤ 1 := λ _, ha
variables {β} [nonempty β]
@[simp, to_additive const_nonneg]
lemma one_le_const : 1 ≤ const β a ↔ 1 ≤ a := @const_le_const _ _ _ _ 1 _
@[simp, to_additive const_pos]
lemma one_lt_const : 1 < const β a ↔ 1 < a := @const_lt_const _ _ _ _ 1 a
@[simp, to_additive] lemma const_le_one : const β a ≤ 1 ↔ a ≤ 1 := @const_le_const _ _ _ _ _ 1
@[simp, to_additive] lemma const_lt_one : const β a < 1 ↔ a < 1 := @const_lt_const _ _ _ _ _ 1
end function
namespace tactic
open function positivity
variables (ι) [has_zero α] {a : α}
private lemma function_const_nonneg_of_pos [preorder α] (ha : 0 < a) : 0 ≤ const ι a :=
const_nonneg_of_nonneg _ ha.le
variables [nonempty ι]
private lemma function_const_ne_zero : a ≠ 0 → const ι a ≠ 0 := const_ne_zero.2
private lemma function_const_pos [preorder α] : 0 < a → 0 < const ι a := const_pos.2
/-- Extension for the `positivity` tactic: `function.const` is positive/nonnegative/nonzero if its
input is. -/
@[positivity]
meta def positivity_const : expr → tactic strictness
| `(function.const %%ι %%a) := do
strict_a ← core a,
match strict_a with
| positive p := positive <$> to_expr ``(function_const_pos %%ι %%p)
<|> nonnegative <$> to_expr ``(function_const_nonneg_of_pos %%ι %%p)
| nonnegative p := nonnegative <$> to_expr ``(const_nonneg_of_nonneg %%ι %%p)
| nonzero p := nonzero <$> to_expr ``(function_const_ne_zero %%ι %%p)
end
| e := pp e >>= fail ∘ format.bracket "The expression `" "` is not of the form `function.const ι a`"
end tactic
|
d2af3abc5623536d20d045c4b42eec8278a0f9ee | 359199d7253811b032ab92108191da7336eba86e | /src/instructor/lectures/lecture_13.lean | 3e1c9f0a2c79bc13abf166a0db2737982dd5b42c | [] | no_license | arte-et-marte/my_cs2120f21 | 0bc6215cb5018a3b7c90d9d399a173233f587064 | 91609c3609ad81fda895bee8b97cc76813241e17 | refs/heads/main | 1,693,298,928,348 | 1,634,931,202,000 | 1,634,931,202,000 | 399,946,705 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,487 | lean | /-
UPDATE: Test distributed after class on
Monday. Monday will be a review day. The
test is due back Wednesday before class.
In class Wednesday we will have at least
a short quiz to sanity check what you will
have submitted for the test. We reserve the
right to do follow-on in-person testing if
the results indicate a possible problem.
-/
/-
REVIEW: Last time we focused on the question,
how do we construct a proof of ∃ x, P x.
-- there exists an x that satisfies P, pick value
-- for x and show that x that has the property
To do so, you apply the introduction rule for
exists. It's called exists.intro in Lean. You
apply it to two arguments: a specific value, w,
in place of x, and a proof that that particular
w satisfies the predicate, P, i.e., that there
is a proof of the proposition, P w.
-- w was natural #s, eq proofs (lect 11)
In other words, you can think of a proof of
∃ x, P x, as a pair, ⟨w, pf ⟩, where w is a
witness and pf is a proof of P w.
-/
/-
Today we'll delve deeper into the mysteries
of exists elimination, or how you can *use*
a proof of ∃ x, P x.
Here's the idea: If you have a proof, ex, of
of ∃ (x : X), P x, you can apply exists.elim
to ex, and (after a few more simple maneuvers)
have yourself a specific value, (w : X), and
a proof that w satisfies P, i.e., (pf : P w). -- from a proof ex, get w and pf back
The idea is that you can then uses the values
in your subsequent proof steps.
Why does this rule make sense? Consider a very
simple example. If I tell you there exists some
green ball, you can say, "well, call it b," and
give that we know it's green, we also know that
it satisfies the isGreen _ predicate, so we can
also assume we have a proof of (isGreen b). In
this example, b is a witness to the fact that
some object satisfies the predicate. The proof
then shows for sure that that is so.
-/
/-
There is (exists) a Boolean value, b, that
satisfies the predicate, b && tt = f.
-/
example : ∃ (b : bool), b && tt = ff :=
begin
apply exists.intro ff _, -- plug witness value and a proof that it satisfies the predicate in question
exact rfl, -- eq.refl applied to ff (ff == ff)
end
example :
(∃ (b : bool), b && tt = ff) → (∃ (b : bool), true) := -- then, there exists a bool that satisfies the true predicate
begin
assume h, -- existentially quantified proposition
cases h with v pf,
apply exists.intro v , -- v has the property we care about
trivial, -- trivial knows true has a proof of itself
/-
assume h,
cases h with w pf,
apply exists.intro w,
trivial,
-/
-- tt is the boolean, true is the proposition (true as a proposition - has a proof)
apply exists.intro ff, -- apply intro to witness
exact rfl, -- leaving proof as a subgoal
end
/-
If there's a Boolean value that satisfies
that predicate, then there's a Boolean value.
-/
example :
(exists (b : bool), b && tt = ff) →
(∃ (b : bool), true) :=
begin
assume h, -- assume premise
cases h with w pf, -- eliminate exists
apply exists.intro w, -- introduce exists
trivial, -- the rest is easy
end
example : ∃ (b : bool), true :=
begin
apply exists.intro ff _, -- tt or ff would work as w
exact true.intro,
end
/-
Let's set up some assumptions so that
we can explore their consequences when
it comes to existentially quantified
propositions.
-/
/-
Beachballs! What could be more fun
-/
axioms
(Ball : Type) -- There are balls
(Green : Ball → Prop) -- a Ball can be Green
(Red : Ball → Prop) -- a Ball can be Red
(b1 b2 : Ball) -- b1 and b2 are balls
(b1r : Red b1) -- b1 is red
(b1g : Green b1) -- b1 is green
(b2r : Red b2) -- b2 is red
/-
Translate the propositions into English, then
prove them formally.
If there's a Ball that's Red and Green then
there is a ball that's Red.
-/
example :
(∃ (b : Ball), Red b ∧ Green b) →
(∃ (b : Ball), Red b) :=
begin
assume w,
cases w with b h, -- applying exists.elim, 1st case: assume b of type ball, know that it's red and green
-- cases applying exists.elim which takes a proof of an exists statement and spits out the witness value, predicate proof
-- to prove exists statement, need exists intro rule
apply exists.intro b (and.elim_left h),
assume h,
cases h with b rb_and_gb, -- applying the exists elimination rule, which returns the w and the proof that w satisfies the predicate
apply exists.intro b _,
exact and.elim_left rb_and_gb,
assume h, -- assume there's a red and green ball
cases h with b rg, -- get a name, b, for the ball and a proof about b
apply exists.intro b, -- use b as a witness to the proposition to be proved
exact rg.left, -- the proof it's red is part of that it's red and green
end
/-
If there's a ball, b, that's red or green
then there's a ball, b, that greed or red.
-/
example :
(∃ (b : Ball), Red b ∨ Green b) →
(∃ (b : Ball), Green b ∨ Red b) :=
begin
assume h,
cases h with w pf,
apply exists.intro w _,
apply or.elim pf,
-- tbc
assume h, -- there's ball that's red or green
cases h with w pf, -- name it w with pf a proof of Red w ∨ Green w
apply exists.intro w, -- use w as witness, need proof of Green w ∨ Red d
cases pf, -- basically proof of X ∨ Y → Y ∨ X at this point
exact or.inr pf,
exact or.inl pf,
end
/-
How about this one? Translate it into Enlish. Do
you believe it?
-/
example :
(∃ (b : Ball), Red b ∨ Green b) →
(∃ (b : Ball), Red b) :=
begin
assume h,
cases h with w pf,
apply or.elim pf,
-- 1
assume h1,
apply exists.intro w _,
assumption,
-- 2
-- tbc
cases pf,
apply exists.intro w,
assumption,
apply exists.intro w,
_
end
/-
If there's a red ball then there's a ball that's red or green.
-/
example : -- be sure you can do this one yourself!
(∃ (b : Ball), Red b) →
(∃ (b : Ball), Red b ∨ Green b) :=
begin
--
end
/-
Social Networks
-/
axioms
(Person : Type) -- a person is a type
(Nice : Person → Prop) -- nice is a function from person to prop, given a person, that person is nice
(Likes : Person → Person → Prop) -- a function that takes in 2 people, returns prop that first person likes second person
/-
What does this say, in English? It is true?
-/
example :
-- if there is a person that everyone likes, then each person there is someone that they like
(∃ (p1 : Person), ∀ (p2 : Person), Likes p2 p1) →
(∀ (e : Person), ∃ (s : Person), Likes e s) :=
-- there exists a person that everybody likes
-- for every person there exists someone that they like
-- forwards is true, backwards is not
begin
assume h, -- there exists a person such that...
-- big exists proof, need elim to split it up into component parts
cases h with person1 w,
-- forall statement now, first step assume
assume person2,
-- need person1 (our witness that satisfies pred)
apply exists.intro person1 _,
-- do we see anything that provides a proof of Likes - w!
apply w person2,
assume h,
assume e,
cases h with p pf,
apply exists.intro p _, -- !!! TEST QUESTION !!!
exact pf e,
end
example :
-- If there's a person, p1, who everyone likes,
(∃ (p1 : Person), ∀ (p2 : Person), Likes p2 p1) →
-- then everyone likes someone
(∀ (e : Person), ∃ (s : Person), Likes e s) :=
begin
assume h,
cases h with p pf,
assume e,
apply exists.intro p,
exact (pf e),
end
/-
Write formal expressions for each of the following
English language sentences.
-/
-- Everyone likes him or herself
∀ (p : Person), Likes p p
-- Someone doesn't like him or herself
(∃ p : Person), ¬(Likes p p) -- not takes in a proposition
¬(∀ (p : Person)), Likes p p
-- There is someone likes someone else
∃ (p1 p2 : Person), Likes p1 p2
-- No one likes anyone who dislikes them
¬ (∃ (p : Person) ), ¬(Likes )
-- Everyone likes anyone who is nice
-- No one likes anyone who is not nice
¬ (∃ (p : Person)), ∀ (p2 : Person), ¬ Nice p2 → Likes p p2,
-- there exists a person such that (,) for all people, NOT p does like not nice p2
/-
If everyone who's nice likes someone, then
there is someone whom everyone who is nice
likes.
-/
((∀ p : Person), (∃ p2 : Person), Nice p → Likes p p2) → (∃ (p : Person), ∀ (p2 : Person), Nice p2 → Likes p2 p)
example : ¬(∀ (p : Person), Likes p p) ↔ (∃ (p : Person), ¬(Likes p p)) :=
begin
apply iff.intro _ _,
-- forwards implication proof
assume left, -- have a proof of an exists statement, which we can use elim on
apply exists.intro _
end
example : ¬(∀ (p : Person), Likes p p) → (∃ (p : Person), ¬(Likes p p)) :=
begin
assume h,
have f := classical.em ((∃ (p : Person), ¬(Likes p p))),
cases f,
-- case 1
assumption,
-- want to prove a contradiction, which to build? build h's? how?
have contra : ∀ (p : Person), Likes p p := _, -- set goal
contradiction,
-- case 2
assume p,
-- how to prove Likes p p
have h := classical.em (Likes p p),
cases h,
-- subcase 1
assumption,
-- subcase 2
have contra2 : (∃ (p : Person), ¬(Likes p p)) := exists.intro p h,
contradiction,
end
example : (∃ (p : Person), ¬(Likes p p)) → ¬(∀ (p : Person), Likes p p) :=
begin
assume h,
cases h with p pf,
assume p2,
have f := p2 p,
contradiction,
end
likes. (Is this true or not.)
-/
|
6069f8b446a054f5f3f4a1632b17c257f1a9c13c | a7602958ab456501ff85db8cf5553f7bcab201d7 | /Notes/Logic_and_Proof/Chapter4/4.21.lean | cf97a0723aaa1fba2bb01d506b0d5f0d32b813af | [] | no_license | enlauren/math-logic | 081e2e737c8afb28dbb337968df95ead47321ba0 | 086b6935543d1841f1db92d0e49add1124054c37 | refs/heads/master | 1,594,506,621,950 | 1,558,634,976,000 | 1,558,634,976,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 496 | lean | -- Introducing "show"
-- "show" can let us provide more information than is _necessary_. It lets us
-- tell the lean parser what exactly we are intending to prove at each substep.
variables A B : Prop
example : A ∧ ¬ B → ¬ B ∧ A :=
assume h : A ∧ ¬ B,
show ¬ B ∧ A, from and.intro (and.right h) (and.left h)
-- For example, we'll be really explicit here:
example : A ∧ ¬ B → ¬ B ∧ A :=
assume h,
and.intro
(show not B, from and.right h)
(show A, from and.left h) |
52ccf6a29b3f8c956dc121847db8cb3a296d9a1a | 137c667471a40116a7afd7261f030b30180468c2 | /src/algebra/lie/basic.lean | b01518b644c93c254b102bd580fd02fe0edf7100 | [
"Apache-2.0"
] | permissive | bragadeesh153/mathlib | 46bf814cfb1eecb34b5d1549b9117dc60f657792 | b577bb2cd1f96eb47031878256856020b76f73cd | refs/heads/master | 1,687,435,188,334 | 1,626,384,207,000 | 1,626,384,207,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,642 | lean | /-
Copyright (c) 2019 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import data.bracket
import algebra.algebra.basic
import tactic.noncomm_ring
/-!
# Lie algebras
This file defines Lie rings and Lie algebras over a commutative ring together with their
modules, morphisms and equivalences, as well as various lemmas to make these definitions usable.
## Main definitions
* `lie_ring`
* `lie_algebra`
* `lie_ring_module`
* `lie_module`
* `lie_hom`
* `lie_equiv`
* `lie_module_hom`
* `lie_module_equiv`
## Notation
Working over a fixed commutative ring `R`, we introduce the notations:
* `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras,
* `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras,
* `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`,
* `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`.
## Implementation notes
Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules,
are partially unbundled.
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975)
## Tags
lie bracket, jacobi identity, lie ring, lie algebra, lie module
-/
universes u v w w₁ w₂
/-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the
Jacobi identity. -/
@[protect_proj] class lie_ring (L : Type v) extends add_comm_group L, has_bracket L L :=
(add_lie : ∀ (x y z : L), ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆)
(lie_add : ∀ (x y z : L), ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆)
(lie_self : ∀ (x : L), ⁅x, x⁆ = 0)
(leibniz_lie : ∀ (x y z : L), ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆)
/-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi
identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/
@[protect_proj] class lie_algebra (R : Type u) (L : Type v) [comm_ring R] [lie_ring L]
extends module R L :=
(lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆)
/-- A Lie ring module is an additive group, together with an additive action of a
Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms.
(For representations of Lie *algebras* see `lie_module`.) -/
@[protect_proj] class lie_ring_module (L : Type v) (M : Type w)
[lie_ring L] [add_comm_group M] extends has_bracket L M :=
(add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆)
(lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆)
(leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆)
/-- A Lie module is a module over a commutative ring, together with a linear action of a Lie
algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/
@[protect_proj] class lie_module (R : Type u) (L : Type v) (M : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
[lie_ring_module L M] :=
(smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆)
(lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆)
section basic_properties
variables {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables [add_comm_group N] [module R N] [lie_ring_module L N] [lie_module R L N]
variables (t : R) (x y z : L) (m n : M)
@[simp] lemma add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := lie_ring_module.add_lie x y m
@[simp] lemma lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := lie_ring_module.lie_add x m n
@[simp] lemma smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := lie_module.smul_lie t x m
@[simp] lemma lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := lie_module.lie_smul t x m
lemma leibniz_lie : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := lie_ring_module.leibniz_lie x y m
@[simp] lemma lie_zero : ⁅x, 0⁆ = (0 : M) := (add_monoid_hom.mk' _ (lie_add x)).map_zero
@[simp] lemma zero_lie : ⁅(0 : L), m⁆ = 0 :=
(add_monoid_hom.mk' (λ (x : L), ⁅x, m⁆) (λ x y, add_lie x y m)).map_zero
@[simp] lemma lie_self : ⁅x, x⁆ = 0 := lie_ring.lie_self x
instance lie_ring_self_module : lie_ring_module L L := { ..(infer_instance : lie_ring L) }
@[simp] lemma lie_skew : -⁅y, x⁆ = ⁅x, y⁆ :=
have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0, { rw ← lie_add, apply lie_self, },
by simpa [neg_eq_iff_add_eq_zero] using h
/-- Every Lie algebra is a module over itself. -/
instance lie_algebra_self_module : lie_module R L L :=
{ smul_lie := λ t x m, by rw [←lie_skew, ←lie_skew x m, lie_algebra.lie_smul, smul_neg],
lie_smul := by apply lie_algebra.lie_smul, }
@[simp] lemma neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero, sub_neg_eq_add, ←add_lie], simp, }
@[simp] lemma lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero, sub_neg_eq_add, ←lie_add], simp, }
@[simp] lemma sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ :=
by simp [sub_eq_add_neg]
@[simp] lemma lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ :=
by simp [sub_eq_add_neg]
@[simp] lemma nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ :=
add_monoid_hom.map_nsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ :=
add_monoid_hom.map_nsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _
@[simp] lemma gsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_gsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_gsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_gsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _
@[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ :=
by rw [leibniz_lie, add_sub_cancel]
lemma lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 :=
by { rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie], abel, }
instance lie_ring.int_lie_algebra : lie_algebra ℤ L :=
{ lie_smul := λ n x y, lie_gsmul x y n, }
instance : lie_ring_module L (M →ₗ[R] N) :=
{ bracket := λ x f,
{ to_fun := λ m, ⁅x, f m⁆ - f ⁅x, m⁆,
map_add' := λ m n, by { simp only [lie_add, linear_map.map_add], abel, },
map_smul' := λ t m, by simp only [smul_sub, linear_map.map_smul, lie_smul], },
add_lie := λ x y f, by
{ ext n, simp only [add_lie, linear_map.coe_mk, linear_map.add_apply, linear_map.map_add],
abel, },
lie_add := λ x f g, by
{ ext n, simp only [linear_map.coe_mk, lie_add, linear_map.add_apply], abel, },
leibniz_lie := λ x y f, by
{ ext n,
simp only [lie_lie, linear_map.coe_mk, linear_map.map_sub, linear_map.add_apply, lie_sub],
abel, }, }
@[simp] lemma lie_hom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) :
⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ :=
rfl
instance : lie_module R L (M →ₗ[R] N) :=
{ smul_lie := λ t x f, by
{ ext n,
simp only [smul_sub, smul_lie, linear_map.smul_apply, lie_hom.lie_apply,
linear_map.map_smul], },
lie_smul := λ t x f, by
{ ext n, simp only [smul_sub, linear_map.smul_apply, lie_hom.lie_apply, lie_smul], }, }
end basic_properties
set_option old_structure_cmd true
/-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/
structure lie_hom (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ[R] L' :=
(map_lie' : ∀ {x y : L}, to_fun ⁅x, y⁆ = ⁅to_fun x, to_fun y⁆)
attribute [nolint doc_blame] lie_hom.to_linear_map
notation L ` →ₗ⁅`:25 R:25 `⁆ `:0 L':0 := lie_hom R L L'
namespace lie_hom
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance : has_coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨lie_hom.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ →ₗ⁅R⁆ L₂) := ⟨_, lie_hom.to_fun⟩
initialize_simps_projections lie_hom (to_fun → apply)
@[simp, norm_cast] lemma coe_to_linear_map (f : L₁ →ₗ⁅R⁆ L₂) : ((f : L₁ →ₗ[R] L₂) : L₁ → L₂) = f :=
rfl
@[simp] lemma to_fun_eq_coe (f : L₁ →ₗ⁅R⁆ L₂) : f.to_fun = ⇑f := rfl
@[simp] lemma map_smul (f : L₁ →ₗ⁅R⁆ L₂) (c : R) (x : L₁) : f (c • x) = c • f x :=
linear_map.map_smul (f : L₁ →ₗ[R] L₂) c x
@[simp] lemma map_add (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x + y) = (f x) + (f y) :=
linear_map.map_add (f : L₁ →ₗ[R] L₂) x y
@[simp] lemma map_sub (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x - y) = (f x) - (f y) :=
linear_map.map_sub (f : L₁ →ₗ[R] L₂) x y
@[simp] lemma map_neg (f : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f (-x) = -(f x) :=
linear_map.map_neg (f : L₁ →ₗ[R] L₂) x
@[simp] lemma map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := lie_hom.map_lie' f
@[simp] lemma map_zero (f : L₁ →ₗ⁅R⁆ L₂) : f 0 = 0 := (f : L₁ →ₗ[R] L₂).map_zero
/-- The identity map is a morphism of Lie algebras. -/
def id : L₁ →ₗ⁅R⁆ L₁ :=
{ map_lie' := λ x y, rfl,
.. (linear_map.id : L₁ →ₗ[R] L₁) }
@[simp] lemma coe_id : ((id : L₁ →ₗ⁅R⁆ L₁) : L₁ → L₁) = _root_.id := rfl
lemma id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x := rfl
/-- The constant 0 map is a Lie algebra morphism. -/
instance : has_zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ map_lie' := by simp, ..(0 : L₁ →ₗ[R] L₂)}⟩
@[norm_cast, simp] lemma coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 := rfl
lemma zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 := rfl
/-- The identity map is a Lie algebra morphism. -/
instance : has_one (L₁ →ₗ⁅R⁆ L₁) := ⟨id⟩
@[simp] lemma coe_one : ((1 : (L₁ →ₗ⁅R⁆ L₁)) : L₁ → L₁) = _root_.id := rfl
lemma one_apply (x : L₁) : (1 : (L₁ →ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩
lemma coe_injective : function.injective (λ f : L₁ →ₗ⁅R⁆ L₂, show L₁ → L₂, from f) :=
by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr
@[ext] lemma ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : L₁ →ₗ⁅R⁆ L₂} : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, ext⟩
lemma congr_fun {f g : L₁ →ₗ⁅R⁆ L₂} (h : f = g) (x : L₁) : f x = g x := h ▸ rfl
@[simp] lemma mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) :
(⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f :=
by { ext, refl, }
@[simp] lemma coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl
@[norm_cast, simp] lemma coe_linear_mk (f : L₁ →ₗ[R] L₂) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ[R] L₂) = ⟨f, h₁, h₂⟩ :=
by { ext, refl, }
/-- The composition of morphisms is a morphism. -/
def comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ :=
{ map_lie' := λ x y, by { change f (g ⁅x, y⁆) = ⁅f (g x), f (g y)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
lemma comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) :
f.comp g x = f (g x) := rfl
@[norm_cast, simp]
lemma coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f.comp g : L₁ → L₃) = f ∘ g :=
rfl
@[norm_cast, simp]
lemma coe_linear_map_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) :=
rfl
@[simp] lemma comp_id (f : L₁ →ₗ⁅R⁆ L₂) : f.comp (id : L₁ →ₗ⁅R⁆ L₁) = f :=
by { ext, refl, }
@[simp] lemma id_comp (f : L₁ →ₗ⁅R⁆ L₂) : (id : L₂ →ₗ⁅R⁆ L₂).comp f = f :=
by { ext, refl, }
/-- The inverse of a bijective morphism is a morphism. -/
def inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : L₂ →ₗ⁅R⁆ L₁ :=
{ map_lie' := λ x y,
calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ : by { conv_lhs { rw [←h₂ x, ←h₂ y], }, }
... = g (f ⁅g x, g y⁆) : by rw map_lie
... = ⁅g x, g y⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
end lie_hom
/-- An equivalence of Lie algebras is a morphism which is also a linear equivalence. We could
instead define an equivalence to be a morphism which is also a (plain) equivalence. However it is
more convenient to define via linear equivalence to get `.to_linear_equiv` for free. -/
structure lie_equiv (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ⁅R⁆ L', L ≃ₗ[R] L'
attribute [nolint doc_blame] lie_equiv.to_lie_hom
attribute [nolint doc_blame] lie_equiv.to_linear_equiv
notation L ` ≃ₗ⁅`:50 R `⁆ ` L' := lie_equiv R L L'
namespace lie_equiv
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance has_coe_to_lie_hom : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨to_lie_hom⟩
instance has_coe_to_linear_equiv : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ ≃ₗ⁅R⁆ L₂) := ⟨_, to_fun⟩
@[simp, norm_cast] lemma coe_to_lie_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = e :=
rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) :
((e : L₁ ≃ₗ[R] L₂) : L₁ → L₂) = e := rfl
instance : has_one (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨{ map_lie' := λ x y,
by { change ((1 : L₁→ₗ[R] L₁) ⁅x, y⁆) = ⁅(1 : L₁→ₗ[R] L₁) x, (1 : L₁→ₗ[R] L₁) y⁆, simp, },
..(1 : L₁ ≃ₗ[R] L₁)}⟩
@[simp] lemma one_apply (x : L₁) : (1 : (L₁ ≃ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩
/-- Lie algebra equivalences are reflexive. -/
@[refl]
def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1
@[simp] lemma refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl
/-- Lie algebra equivalences are symmetric. -/
@[symm]
def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ :=
{ ..lie_hom.inverse e.to_lie_hom e.inv_fun e.left_inv e.right_inv,
..e.to_linear_equiv.symm }
@[simp] lemma symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e :=
by { cases e, refl, }
@[simp] lemma apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ :=
{ ..lie_hom.comp e₂.to_lie_hom e₁.to_lie_hom,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma symm_trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₃) :
(e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl
lemma bijective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.bijective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.bijective
lemma injective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.injective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.injective
lemma surjective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.surjective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.surjective
end lie_equiv
section lie_module_morphisms
variables (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) (P : Type w₂)
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [add_comm_group N] [add_comm_group P]
variables [module R M] [module R N] [module R P]
variables [lie_ring_module L M] [lie_ring_module L N] [lie_ring_module L P]
variables [lie_module R L M] [lie_module R L N] [lie_module R L P]
set_option old_structure_cmd true
/-- A morphism of Lie algebra modules is a linear map which commutes with the action of the Lie
algebra. -/
structure lie_module_hom extends M →ₗ[R] N :=
(map_lie' : ∀ {x : L} {m : M}, to_fun ⁅x, m⁆ = ⁅x, to_fun m⁆)
attribute [nolint doc_blame] lie_module_hom.to_linear_map
notation M ` →ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_hom R L M N
namespace lie_module_hom
variables {R L M N P}
instance : has_coe (M →ₗ⁅R,L⁆ N) (M →ₗ[R] N) := ⟨lie_module_hom.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M →ₗ⁅R,L⁆ N) := ⟨_, lie_module_hom.to_fun⟩
@[simp, norm_cast] lemma coe_to_linear_map (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f :=
rfl
@[simp] lemma map_smul (f : M →ₗ⁅R,L⁆ N) (c : R) (x : M) : f (c • x) = c • f x :=
linear_map.map_smul (f : M →ₗ[R] N) c x
@[simp] lemma map_add (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x + y) = (f x) + (f y) :=
linear_map.map_add (f : M →ₗ[R] N) x y
@[simp] lemma map_sub (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x - y) = (f x) - (f y) :=
linear_map.map_sub (f : M →ₗ[R] N) x y
@[simp] lemma map_neg (f : M →ₗ⁅R,L⁆ N) (x : M) : f (-x) = -(f x) :=
linear_map.map_neg (f : M →ₗ[R] N) x
@[simp] lemma map_lie (f : M →ₗ⁅R,L⁆ N) (x : L) (m : M) : f ⁅x, m⁆ = ⁅x, f m⁆ :=
lie_module_hom.map_lie' f
lemma map_lie₂ (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (x : L) (m : M) (n : N) :
⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆ :=
by simp only [sub_add_cancel, map_lie, lie_hom.lie_apply]
@[simp] lemma map_zero (f : M →ₗ⁅R,L⁆ N) : f 0 = 0 :=
linear_map.map_zero (f : M →ₗ[R] N)
/-- The constant 0 map is a Lie module morphism. -/
instance : has_zero (M →ₗ⁅R,L⁆ N) := ⟨{ map_lie' := by simp, ..(0 : M →ₗ[R] N) }⟩
@[norm_cast, simp] lemma coe_zero : ((0 : M →ₗ⁅R,L⁆ N) : M → N) = 0 := rfl
lemma zero_apply (m : M) : (0 : M →ₗ⁅R,L⁆ N) m = 0 := rfl
/-- The identity map is a Lie module morphism. -/
instance : has_one (M →ₗ⁅R,L⁆ M) := ⟨{ map_lie' := by simp, ..(1 : M →ₗ[R] M) }⟩
instance : inhabited (M →ₗ⁅R,L⁆ N) := ⟨0⟩
lemma coe_injective : function.injective (λ f : M →ₗ⁅R,L⁆ N, show M → N, from f) :=
by { rintros ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩, congr, }
@[ext] lemma ext {f g : M →ₗ⁅R,L⁆ N} (h : ∀ m, f m = g m) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : M →ₗ⁅R,L⁆ N} : f = g ↔ ∀ m, f m = g m :=
⟨by { rintro rfl m, refl, }, ext⟩
@[simp] lemma mk_coe (f : M →ₗ⁅R,L⁆ N) (h₁ h₂ h₃) :
(⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) = f :=
by { ext, refl, }
@[simp] lemma coe_mk (f : M → N) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f := rfl
@[norm_cast, simp] lemma coe_linear_mk (f : M →ₗ[R] N) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) : M →ₗ[R] N) = ⟨f, h₁, h₂⟩ :=
by { ext, refl, }
/-- The composition of Lie module morphisms is a morphism. -/
def comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : M →ₗ⁅R,L⁆ P :=
{ map_lie' := λ x m, by { change f (g ⁅x, m⁆) = ⁅x, f (g m)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
lemma comp_apply (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) (m : M) :
f.comp g m = f (g m) := rfl
@[norm_cast, simp] lemma coe_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f.comp g : M → P) = f ∘ g :=
rfl
@[norm_cast, simp] lemma coe_linear_map_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f.comp g : M →ₗ[R] P) = (f : N →ₗ[R] P).comp (g : M →ₗ[R] N) :=
rfl
/-- The inverse of a bijective morphism of Lie modules is a morphism of Lie modules. -/
def inverse (f : M →ₗ⁅R,L⁆ N) (g : N → M)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : N →ₗ⁅R,L⁆ M :=
{ map_lie' := λ x n,
calc g ⁅x, n⁆ = g ⁅x, f (g n)⁆ : by rw h₂
... = g (f ⁅x, g n⁆) : by rw map_lie
... = ⁅x, g n⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
instance : has_add (M →ₗ⁅R,L⁆ N) :=
{ add := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) + (g : M →ₗ[R] N)) }, }
instance : has_sub (M →ₗ⁅R,L⁆ N) :=
{ sub := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) - (g : M →ₗ[R] N)) }, }
instance : has_neg (M →ₗ⁅R,L⁆ N) :=
{ neg := λ f, { map_lie' := by simp, ..(-(f : (M →ₗ[R] N))) }, }
@[norm_cast, simp] lemma coe_add (f g : M →ₗ⁅R,L⁆ N) : ⇑(f + g) = f + g := rfl
lemma add_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f + g) m = f m + g m := rfl
@[norm_cast, simp] lemma coe_sub (f g : M →ₗ⁅R,L⁆ N) : ⇑(f - g) = f - g := rfl
lemma sub_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f - g) m = f m - g m := rfl
@[norm_cast, simp] lemma coe_neg (f : M →ₗ⁅R,L⁆ N) : ⇑(-f) = -f := rfl
lemma neg_apply (f : M →ₗ⁅R,L⁆ N) (m : M) : (-f) m = -(f m) := rfl
instance : add_comm_group (M →ₗ⁅R,L⁆ N) :=
{ zero := 0,
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
nsmul := λ n f, { map_lie' := λ x m, by simp, ..(n • (f : M →ₗ[R] N)) },
nsmul_zero' := λ f, by { ext, simp, },
nsmul_succ' := λ n f, by { ext, simp [nat.succ_eq_one_add, add_nsmul], },
..(coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub :
add_comm_group (M →ₗ⁅R,L⁆ N)) }
instance : has_scalar R (M →ₗ⁅R,L⁆ N) :=
{ smul := λ t f, { map_lie' := by simp, ..(t • (f : M →ₗ[R] N)) }, }
@[norm_cast, simp] lemma coe_smul (t : R) (f : M →ₗ⁅R,L⁆ N) : ⇑(t • f) = t • f := rfl
lemma smul_apply (t : R) (f : M →ₗ⁅R,L⁆ N) (m : M) : (t • f) m = t • (f m) := rfl
instance : module R (M →ₗ⁅R,L⁆ N) :=
function.injective.module R ⟨to_fun, rfl, coe_add⟩ coe_injective coe_smul
end lie_module_hom
/-- An equivalence of Lie algebra modules is a linear equivalence which is also a morphism of
Lie algebra modules. -/
structure lie_module_equiv extends M ≃ₗ[R] N, M →ₗ⁅R,L⁆ N, M ≃ N
attribute [nolint doc_blame] lie_module_equiv.to_equiv
attribute [nolint doc_blame] lie_module_equiv.to_lie_module_hom
attribute [nolint doc_blame] lie_module_equiv.to_linear_equiv
notation M ` ≃ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_equiv R L M N
namespace lie_module_equiv
variables {R L M N P}
instance has_coe_to_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ N) := ⟨to_equiv⟩
instance has_coe_to_lie_module_hom : has_coe (M ≃ₗ⁅R,L⁆ N) (M →ₗ⁅R,L⁆ N) := ⟨to_lie_module_hom⟩
instance has_coe_to_linear_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ₗ[R] N) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M ≃ₗ⁅R,L⁆ N) := ⟨_, to_fun⟩
@[simp] lemma coe_mk (f : M → N) (h₁ h₂ F h₃ h₄ h₅) :
((⟨f, h₁, h₂, F, h₃, h₄, h₅⟩ : M ≃ₗ⁅R,L⁆ N) : M → N) = f := rfl
@[simp, norm_cast] lemma coe_to_lie_module_hom (e : M ≃ₗ⁅R,L⁆ N) :
((e : M →ₗ⁅R,L⁆ N) : M → N) = e := rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : M ≃ₗ⁅R,L⁆ N) : ((e : M ≃ₗ[R] N) : M → N) = e :=
rfl
lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ⁅R,L⁆ N) → M ≃ N) :=
λ ⟨_, _, _, _, _, _, _⟩ ⟨_, _, _, _, _, _, _⟩ h, lie_module_equiv.mk.inj_eq.mpr (equiv.mk.inj h)
@[ext] lemma ext (e₁ e₂ : M ≃ₗ⁅R,L⁆ N) (h : ∀ m, e₁ m = e₂ m) : e₁ = e₂ :=
to_equiv_injective (equiv.ext h)
instance : has_one (M ≃ₗ⁅R,L⁆ M) := ⟨{ map_lie' := λ x m, rfl, ..(1 : M ≃ₗ[R] M) }⟩
@[simp] lemma one_apply (m : M) : (1 : (M ≃ₗ⁅R,L⁆ M)) m = m := rfl
instance : inhabited (M ≃ₗ⁅R,L⁆ M) := ⟨1⟩
/-- Lie module equivalences are reflexive. -/
@[refl] def refl : M ≃ₗ⁅R,L⁆ M := 1
@[simp] lemma refl_apply (m : M) : (refl : M ≃ₗ⁅R,L⁆ M) m = m := rfl
/-- Lie module equivalences are syemmtric. -/
@[symm] def symm (e : M ≃ₗ⁅R,L⁆ N) : N ≃ₗ⁅R,L⁆ M :=
{ ..lie_module_hom.inverse e.to_lie_module_hom e.inv_fun e.left_inv e.right_inv,
..(e : M ≃ₗ[R] N).symm }
@[simp] lemma symm_symm (e : M ≃ₗ⁅R,L⁆ N) : e.symm.symm = e :=
by { cases e, refl, }
@[simp] lemma apply_symm_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie module equivalences are transitive. -/
@[trans] def trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) : M ≃ₗ⁅R,L⁆ P :=
{ ..lie_module_hom.comp e₂.to_lie_module_hom e₁.to_lie_module_hom,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (m : M) :
(e₁.trans e₂) m = e₂ (e₁ m) := rfl
@[simp] lemma symm_trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (p : P) :
(e₁.trans e₂).symm p = e₁.symm (e₂.symm p) := rfl
end lie_module_equiv
end lie_module_morphisms
|
b0be8808ebd84ad145939602a32ccc84c0f86e69 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/measure_theory/prod_group.lean | 07bad1a7c7f91fa96c9c365cbfdc2f5b5607e9ec | [
"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 | 10,808 | lean | /-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.prod
import measure_theory.group
/-!
# Measure theory in the product of groups
In this file we show properties about measure theory in products of topological groups
and properties of iterated integrals in topological groups.
These lemmas show the uniqueness of left invariant measures on locally compact groups, up to
scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos.
The idea of the proof is to use the translation invariance of measures to prove `μ(F) = c * μ(E)`
for two sets `E` and `F`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be
the characteristic functions of `E` and `F`.
Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`
preserves the measure `μ.prod ν`, which means that
```
∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ
```
If we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E)`, we can rewrite the RHS to
`μ(F)`, and the LHS to `c * μ(E)`, where `c = c(ν)` does not depend on `μ`.
Applying this to `μ` and to `ν` gives `μ (F) / μ (E) = ν (F) / ν (E)`, which is the uniqueness up to
scalar multiplication.
The proof in [Halmos] seems to contain an omission in §60 Th. A, see
`measure_theory.measure_lintegral_div_measure` and
https://math.stackexchange.com/questions/3974485/does-right-translation-preserve-finiteness-for-a-left-invariant-measure
-/
noncomputable theory
open topological_space set (hiding prod_eq) function
open_locale classical ennreal
namespace measure_theory
open measure
variables {G : Type*} [topological_space G] [measurable_space G] [second_countable_topology G]
[borel_space G] [group G] [topological_group G]
variables {μ ν : measure G} [sigma_finite ν] [sigma_finite μ]
/-- This condition is part of the definition of a measurable group in [Halmos, §59].
There, the map in this lemma is called `S`. -/
lemma map_prod_mul_eq (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.1, z.1 * z.2)) (μ.prod ν) = μ.prod ν :=
begin
refine (prod_eq _).symm, intros s t hs ht,
simp_rw [map_apply (measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht),
prod_apply ((measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht)),
preimage_preimage],
conv_lhs { congr, skip, funext, rw [mk_preimage_prod_right_fn_eq_if ((*) x), measure_if] },
simp_rw [hν _ ht, lintegral_indicator _ hs, set_lintegral_const, mul_comm]
end
/-- The function we are mapping along is `SR` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_mul_eq_swap (hμ : is_mul_left_invariant μ) :
map (λ z : G × G, (z.2, z.2 * z.1)) (μ.prod ν) = ν.prod μ :=
begin
rw [← prod_swap],
simp_rw [map_map (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)) measurable_swap],
exact map_prod_mul_eq hμ
end
/-- The function we are mapping along is `S⁻¹` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq`. -/
lemma map_prod_inv_mul_eq (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.1, z.1⁻¹ * z.2)) (μ.prod ν) = μ.prod ν :=
(homeomorph.shear_mul_right G).to_measurable_equiv.map_apply_eq_iff_map_symm_apply_eq.mp $
map_prod_mul_eq hν
/-- The function we are mapping along is `S⁻¹R` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_inv_mul_eq_swap (hμ : is_mul_left_invariant μ) :
map (λ z : G × G, (z.2, z.2⁻¹ * z.1)) (μ.prod ν) = ν.prod μ :=
begin
rw [← prod_swap],
simp_rw
[map_map (measurable_snd.prod_mk $ measurable_snd.inv.mul measurable_fst) measurable_swap],
exact map_prod_inv_mul_eq hμ
end
/-- The function we are mapping along is `S⁻¹RSR` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_mul_inv_eq (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod ν) = μ.prod ν :=
begin
let S := (homeomorph.shear_mul_right G).to_measurable_equiv,
suffices : map ((λ z : G × G, (z.2, z.2⁻¹ * z.1)) ∘ (λ z : G × G, (z.2, z.2 * z.1))) (μ.prod ν) =
μ.prod ν,
{ convert this, ext1 ⟨x, y⟩, simp },
simp_rw [← map_map (measurable_snd.prod_mk (measurable_snd.inv.mul measurable_fst))
(measurable_snd.prod_mk (measurable_snd.mul measurable_fst)), map_prod_mul_eq_swap hμ,
map_prod_inv_mul_eq_swap hν]
end
lemma measure_null_of_measure_inv_null (hμ : is_mul_left_invariant μ)
{E : set G} (hE : measurable_set E) (h2E : μ ((λ x, x⁻¹) ⁻¹' E) = 0) : μ E = 0 :=
begin
have hf : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=
(measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,
suffices : map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (E.prod E) = 0,
{ simpa only [map_prod_mul_inv_eq hμ hμ, prod_prod hE hE, mul_eq_zero, or_self] using this },
simp_rw [map_apply hf (hE.prod hE), prod_apply_symm (hf (hE.prod hE)), preimage_preimage,
mk_preimage_prod],
convert lintegral_zero, ext1 x, refine measure_mono_null (inter_subset_right _ _) h2E
end
lemma measure_inv_null (hμ : is_mul_left_invariant μ) {E : set G} (hE : measurable_set E) :
μ ((λ x, x⁻¹) ⁻¹' E) = 0 ↔ μ E = 0 :=
begin
refine ⟨measure_null_of_measure_inv_null hμ hE, _⟩,
intro h2E,
apply measure_null_of_measure_inv_null hμ (measurable_inv hE),
convert h2E using 2,
exact set.inv_inv
end
lemma measurable_measure_mul_right {E : set G} (hE : measurable_set E) :
measurable (λ x, μ ((λ y, y * x) ⁻¹' E)) :=
begin
suffices :
measurable (λ y, μ ((λ x, (x, y)) ⁻¹' ((λ z : G × G, (1, z.1 * z.2)) ⁻¹' set.prod univ E))),
{ convert this, ext1 x, congr' 1 with y : 1, simp },
apply measurable_measure_prod_mk_right,
exact measurable_const.prod_mk (measurable_fst.mul measurable_snd) (measurable_set.univ.prod hE)
end
lemma lintegral_lintegral_mul_inv (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν)
(f : G → G → ℝ≥0∞) (hf : ae_measurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=
begin
have h : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=
(measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,
have h2f : ae_measurable (uncurry $ λ x y, f (y * x) x⁻¹) (μ.prod ν),
{ apply hf.comp_measurable' h (map_prod_mul_inv_eq hμ hν).absolutely_continuous },
simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],
conv_rhs { rw [← map_prod_mul_inv_eq hμ hν] },
symmetry,
exact lintegral_map' (hf.mono' (map_prod_mul_inv_eq hμ hν).absolutely_continuous) h,
end
lemma measure_mul_right_null (hμ : is_mul_left_invariant μ) {E : set G} (hE : measurable_set E)
(y : G) : μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ E = 0 :=
begin
rw [← measure_inv_null hμ hE, ← hμ y⁻¹ (measurable_inv hE),
← measure_inv_null hμ (measurable_mul_const y hE)],
convert iff.rfl using 3, ext x, simp,
end
lemma measure_mul_right_ne_zero (hμ : is_mul_left_invariant μ) {E : set G} (hE : measurable_set E)
(h2E : μ E ≠ 0) (y : G) : μ ((λ x, x * y) ⁻¹' E) ≠ 0 :=
(not_iff_not_of_iff (measure_mul_right_null hμ hE y)).mpr h2E
/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].
Note that if `f` is the characteristic function of a measurable set `F` this states that
`μ F = c * μ E` for a constant `c` that does not depend on `μ`.
There seems to be a gap in the last step of the proof in [Halmos].
In the last line, the equality `g(x⁻¹)ν(Ex⁻¹) = f(x)` holds if we can prove that
`0 < ν(Ex⁻¹) < ∞`. The first inequality follows from §59, Th. D, but I couldn't find the second
inequality. For this reason, we use a compact `E` instead of a measurable `E` as in [Halmos], and
additionally assume that `ν` is a regular measure (we only need that it is finite on compact
sets). -/
lemma measure_lintegral_div_measure [t2_space G] (hμ : is_mul_left_invariant μ)
(hν : is_mul_left_invariant ν) (h2ν : regular ν) {E : set G} (hE : is_compact E) (h2E : ν E ≠ 0)
(f : G → ℝ≥0∞) (hf : measurable f) :
μ E * ∫⁻ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E) ∂ν = ∫⁻ x, f x ∂μ :=
begin
have Em := hE.measurable_set,
symmetry,
set g := λ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E),
have hg : measurable g := (hf.comp measurable_inv).div
((measurable_measure_mul_right Em).comp measurable_inv),
rw [← set_lintegral_one, ← lintegral_indicator _ Em,
← lintegral_lintegral_mul (measurable_const.indicator Em).ae_measurable hg.ae_measurable,
← lintegral_lintegral_mul_inv hμ hν],
swap, { exact (((measurable_const.indicator Em).comp measurable_fst).mul
(hg.comp measurable_snd)).ae_measurable },
have mE : ∀ x : G, measurable (λ y, ((λ z, z * x) ⁻¹' E).indicator (λ z, (1 : ℝ≥0∞)) y) :=
λ x, measurable_const.indicator (measurable_mul_const _ Em),
have : ∀ x y, E.indicator (λ (z : G), (1 : ℝ≥0∞)) (y * x) =
((λ z, z * x) ⁻¹' E).indicator (λ (b : G), 1) y,
{ intros x y, symmetry, convert indicator_comp_right (λ y, y * x), ext1 z, simp },
have h3E : ∀ y, ν ((λ x, x * y) ⁻¹' E) ≠ ∞ :=
λ y, ennreal.lt_top_iff_ne_top.mp (h2ν.lt_top_of_is_compact $
(homeomorph.mul_right _).compact_preimage.mpr hE),
simp_rw [this, lintegral_mul_const _ (mE _), lintegral_indicator _ (measurable_mul_const _ Em),
set_lintegral_one, g, inv_inv,
ennreal.mul_div_cancel' (measure_mul_right_ne_zero hν Em h2E _) (h3E _)]
end
/-- This is roughly the uniqueness (up to a scalar) of left invariant Borel measures on a second
countable locally compact group. The uniqueness of Haar measure is proven from this in
`measure_theory.measure.haar_measure_unique` -/
lemma measure_mul_measure_eq [t2_space G] (hμ : is_mul_left_invariant μ)
(hν : is_mul_left_invariant ν) (h2ν : regular ν) {E F : set G}
(hE : is_compact E) (hF : measurable_set F) (h2E : ν E ≠ 0) : μ E * ν F = ν E * μ F :=
begin
have h1 := measure_lintegral_div_measure hν hν h2ν hE h2E (F.indicator (λ x, 1))
(measurable_const.indicator hF),
have h2 := measure_lintegral_div_measure hμ hν h2ν hE h2E (F.indicator (λ x, 1))
(measurable_const.indicator hF),
rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,
rw [← h1, mul_left_comm, h2],
end
end measure_theory
|
36a8d301363fb10732ad74c9ba8b437cdf362ad4 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/ring_theory/non_zero_divisors.lean | b6401428060401e06f93668c509e8510096e16b8 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,297 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Devon Tuma
-/
import group_theory.submonoid.operations
import group_theory.submonoid.membership
/-!
# Non-zero divisors
In this file we define the submonoid `non_zero_divisors` of a `monoid_with_zero`.
## Notations
This file declares the notation `R⁰` for the submonoid of non-zero-divisors of `R`,
in the locale `non_zero_divisors`. Use the statement `open_locale non_zero_divisors`
to access this notation in your own code.
-/
section non_zero_divisors
/-- The submonoid of non-zero-divisors of a `monoid_with_zero` `R`. -/
def non_zero_divisors (R : Type*) [monoid_with_zero R] : submonoid R :=
{ carrier := {x | ∀ z, z * x = 0 → z = 0},
one_mem' := λ z hz, by rwa mul_one at hz,
mul_mem' := λ x₁ x₂ hx₁ hx₂ z hz,
have z * x₁ * x₂ = 0, by rwa mul_assoc,
hx₁ z $ hx₂ (z * x₁) this }
localized "notation R`⁰`:9000 := non_zero_divisors R" in non_zero_divisors
variables {M M' M₁ : Type*} [monoid_with_zero M] [monoid_with_zero M'] [comm_monoid_with_zero M₁]
lemma non_zero_divisors.ne_zero [nontrivial M] {x} (hx : x ∈ M⁰) : x ≠ 0 :=
λ h, one_ne_zero (hx _ $ (one_mul _).trans h)
lemma non_zero_divisors.coe_ne_zero [nontrivial M] (x : M⁰) : (x : M) ≠ 0 :=
non_zero_divisors.ne_zero x.2
lemma mul_mem_non_zero_divisors {a b : M₁} :
a * b ∈ M₁⁰ ↔ a ∈ M₁⁰ ∧ b ∈ M₁⁰ :=
begin
split,
{ intro h,
split; intros x h'; apply h,
{ rw [←mul_assoc, h', zero_mul] },
{ rw [mul_comm a b, ←mul_assoc, h', zero_mul] } },
{ rintros ⟨ha, hb⟩ x hx,
apply ha,
apply hb,
rw [mul_assoc, hx] },
end
lemma eq_zero_of_ne_zero_of_mul_right_eq_zero [no_zero_divisors M]
{x y : M} (hnx : x ≠ 0) (hxy : y * x = 0) : y = 0 :=
or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx
lemma eq_zero_of_ne_zero_of_mul_left_eq_zero [no_zero_divisors M]
{x y : M} (hnx : x ≠ 0) (hxy : x * y = 0) : y = 0 :=
or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx
lemma mem_non_zero_divisors_iff_ne_zero [no_zero_divisors M] [nontrivial M] {x : M} :
x ∈ M⁰ ↔ x ≠ 0 :=
⟨non_zero_divisors.ne_zero, λ hnx z, eq_zero_of_ne_zero_of_mul_right_eq_zero hnx⟩
lemma monoid_with_zero_hom.map_ne_zero_of_mem_non_zero_divisors [nontrivial M]
(g : monoid_with_zero_hom M M') (hg : function.injective g)
{x : M} (h : x ∈ M⁰) : g x ≠ 0 :=
λ h0, one_ne_zero (h 1 ((one_mul x).symm ▸ (hg (trans h0 g.map_zero.symm))))
lemma ring_hom.map_ne_zero_of_mem_non_zero_divisors {R R' : Type*} [semiring R] [semiring R']
[nontrivial R]
(g : R →+* R') (hg : function.injective g)
{x : R} (h : x ∈ R⁰) : g x ≠ 0 :=
g.to_monoid_with_zero_hom.map_ne_zero_of_mem_non_zero_divisors hg h
lemma monoid_with_zero_hom.map_mem_non_zero_divisors [nontrivial M] [no_zero_divisors M']
(g : monoid_with_zero_hom M M') (hg : function.injective g)
{x : M} (h : x ∈ M⁰) : g x ∈ M'⁰ :=
λ z hz, eq_zero_of_ne_zero_of_mul_right_eq_zero
(g.map_ne_zero_of_mem_non_zero_divisors hg h) hz
lemma ring_hom.map_mem_non_zero_divisors {R R' : Type*} [semiring R] [semiring R']
[nontrivial R] [no_zero_divisors R']
(g : R →+* R') (hg : function.injective g)
{x : R} (h : x ∈ R⁰) : g x ∈ R'⁰ :=
g.to_monoid_with_zero_hom.map_mem_non_zero_divisors hg h
lemma le_non_zero_divisors_of_no_zero_divisors [no_zero_divisors M] {S : submonoid M}
(hS : (0 : M) ∉ S) : S ≤ M⁰ :=
λ x hx y hy, or.rec_on (eq_zero_or_eq_zero_of_mul_eq_zero hy)
(λ h, h) (λ h, absurd (h ▸ hx : (0 : M) ∈ S) hS)
lemma powers_le_non_zero_divisors_of_no_zero_divisors [no_zero_divisors M]
{a : M} (ha : a ≠ 0) : submonoid.powers a ≤ M⁰ :=
le_non_zero_divisors_of_no_zero_divisors (λ h, absurd (h.rec_on (λ _ hn, pow_eq_zero hn)) ha)
lemma monoid_with_zero_hom.map_le_non_zero_divisors_of_injective
[nontrivial M] [no_zero_divisors M']
(f : monoid_with_zero_hom M M') (hf : function.injective f)
{S : submonoid M} (hS : S ≤ M⁰) : S.map ↑f ≤ M'⁰ :=
le_non_zero_divisors_of_no_zero_divisors (λ h, let ⟨x, hx, hx0⟩ := h in
zero_ne_one (hS (hf (trans hx0 (f.map_zero.symm)) ▸ hx : 0 ∈ S) 1 (mul_zero 1)).symm)
lemma ring_hom.map_le_non_zero_divisors_of_injective {R R' : Type*} [semiring R] [semiring R']
[nontrivial R] [no_zero_divisors R']
(f : R →+* R') (hf : function.injective f)
{S : submonoid R} (hS : S ≤ R⁰) : S.map ↑f ≤ R'⁰ :=
f.to_monoid_with_zero_hom.map_le_non_zero_divisors_of_injective hf hS
lemma prod_zero_iff_exists_zero [no_zero_divisors M₁] [nontrivial M₁]
{s : multiset M₁} : s.prod = 0 ↔ ∃ (r : M₁) (hr : r ∈ s), r = 0 :=
begin
split, swap,
{ rintros ⟨r, hrs, rfl⟩,
exact multiset.prod_eq_zero hrs, },
refine multiset.induction _ (λ a s ih, _) s,
{ intro habs,
simpa using habs, },
{ rw multiset.prod_cons,
intro hprod,
replace hprod := eq_zero_or_eq_zero_of_mul_eq_zero hprod,
cases hprod with ha,
{ exact ⟨a, multiset.mem_cons_self a s, ha⟩ },
{ apply (ih hprod).imp _,
rintros b ⟨hb₁, hb₂⟩,
exact ⟨multiset.mem_cons_of_mem hb₁, hb₂⟩, }, },
end
end non_zero_divisors
|
82f601e4580492f28492bb6385aa16d08458106d | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/closed/functor.lean | 33c4e63e9fafc41a9b95053abd2bd4b0081e37a3 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 6,515 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.closed.cartesian
import category_theory.limits.preserves.shapes.binary_products
import category_theory.adjunction.fully_faithful
/-!
# Cartesian closed functors
Define the exponential comparison morphisms for a functor which preserves binary products, and use
them to define a cartesian closed functor: one which (naturally) preserves exponentials.
Define the Frobenius morphism, and show it is an isomorphism iff the exponential comparison is an
isomorphism.
## TODO
Some of the results here are true more generally for closed objects and for closed monoidal
categories, and these could be generalised.
## References
https://ncatlab.org/nlab/show/cartesian+closed+functor
https://ncatlab.org/nlab/show/Frobenius+reciprocity
## Tags
Frobenius reciprocity, cartesian closed functor
-/
namespace category_theory
open category limits cartesian_closed
universes v u u'
variables {C : Type u} [category.{v} C]
variables {D : Type u'} [category.{v} D]
variables [has_finite_products C] [has_finite_products D]
variables (F : C ⥤ D) {L : D ⥤ C}
noncomputable theory
/--
The Frobenius morphism for an adjunction `L ⊣ F` at `A` is given by the morphism
L(FA ⨯ B) ⟶ LFA ⨯ LB ⟶ A ⨯ LB
natural in `B`, where the first morphism is the product comparison and the latter uses the counit
of the adjunction.
We will show that if `C` and `D` are cartesian closed, then this morphism is an isomorphism for all
`A` iff `F` is a cartesian closed functor, i.e. it preserves exponentials.
-/
def frobenius_morphism (h : L ⊣ F) (A : C) :
prod.functor.obj (F.obj A) ⋙ L ⟶ L ⋙ prod.functor.obj A :=
prod_comparison_nat_trans L (F.obj A) ≫ whisker_left _ (prod.functor.map (h.counit.app _))
/--
If `F` is full and faithful and has a left adjoint `L` which preserves binary products, then the
Frobenius morphism is an isomorphism.
-/
instance frobenius_morphism_iso_of_preserves_binary_products (h : L ⊣ F) (A : C)
[preserves_limits_of_shape (discrete walking_pair) L] [full F] [faithful F] :
is_iso (frobenius_morphism F h A) :=
begin
apply nat_iso.is_iso_of_is_iso_app _,
intro B,
dsimp [frobenius_morphism],
apply_instance,
end
variables [cartesian_closed C] [cartesian_closed D]
variables [preserves_limits_of_shape (discrete walking_pair) F]
/--
The exponential comparison map.
`F` is a cartesian closed functor if this is an iso for all `A`.
-/
def exp_comparison (A : C) :
exp A ⋙ F ⟶ F ⋙ exp (F.obj A) :=
transfer_nat_trans (exp.adjunction A) (exp.adjunction (F.obj A)) (prod_comparison_nat_iso F A).inv
lemma exp_comparison_ev (A B : C) :
limits.prod.map (𝟙 (F.obj A)) ((exp_comparison F A).app B) ≫ (ev (F.obj A)).app (F.obj B) =
inv (prod_comparison F _ _) ≫ F.map ((ev _).app _) :=
by convert transfer_nat_trans_counit _ _ (prod_comparison_nat_iso F A).inv B
lemma coev_exp_comparison (A B : C) :
F.map ((coev A).app B) ≫ (exp_comparison F A).app (A ⨯ B) =
(coev _).app (F.obj B) ≫ (exp (F.obj A)).map (inv (prod_comparison F A B)) :=
by convert unit_transfer_nat_trans _ _ (prod_comparison_nat_iso F A).inv B
lemma uncurry_exp_comparison (A B : C) :
uncurry ((exp_comparison F A).app B) = inv (prod_comparison F _ _) ≫ F.map ((ev _).app _) :=
by rw [uncurry_eq, exp_comparison_ev]
/-- The exponential comparison map is natural in `A`. -/
lemma exp_comparison_whisker_left {A A' : C} (f : A' ⟶ A) :
exp_comparison F A ≫ whisker_left _ (pre (F.map f)) =
whisker_right (pre f) _ ≫ exp_comparison F A' :=
begin
ext B,
dsimp,
apply uncurry_injective,
rw [uncurry_natural_left, uncurry_natural_left, uncurry_exp_comparison, uncurry_pre,
prod.map_swap_assoc, ←F.map_id, exp_comparison_ev, ←F.map_id,
←prod_comparison_inv_natural_assoc, ←prod_comparison_inv_natural_assoc, ←F.map_comp,
←F.map_comp, prod_map_pre_app_comp_ev],
end
/--
The functor `F` is cartesian closed (ie preserves exponentials) if each natural transformation
`exp_comparison F A` is an isomorphism
-/
class cartesian_closed_functor :=
(comparison_iso : ∀ A, is_iso (exp_comparison F A))
attribute [instance] cartesian_closed_functor.comparison_iso
lemma frobenius_morphism_mate (h : L ⊣ F) (A : C) :
transfer_nat_trans_self
(h.comp _ _ (exp.adjunction A))
((exp.adjunction (F.obj A)).comp _ _ h)
(frobenius_morphism F h A) = exp_comparison F A :=
begin
rw ←equiv.eq_symm_apply,
ext B : 2,
dsimp [frobenius_morphism, transfer_nat_trans_self, transfer_nat_trans, adjunction.comp],
simp only [id_comp, comp_id],
rw [←L.map_comp_assoc, prod.map_id_comp, assoc, exp_comparison_ev, prod.map_id_comp, assoc,
← F.map_id, ← prod_comparison_inv_natural_assoc, ← F.map_comp, ev_coev,
F.map_id (A ⨯ L.obj B), comp_id],
apply prod.hom_ext,
{ rw [assoc, assoc, ←h.counit_naturality, ←L.map_comp_assoc, assoc,
inv_prod_comparison_map_fst],
simp },
{ rw [assoc, assoc, ←h.counit_naturality, ←L.map_comp_assoc, assoc,
inv_prod_comparison_map_snd],
simp },
end
/--
If the exponential comparison transformation (at `A`) is an isomorphism, then the Frobenius morphism
at `A` is an isomorphism.
-/
def frobenius_morphism_iso_of_exp_comparison_iso (h : L ⊣ F) (A : C)
[i : is_iso (exp_comparison F A)] :
is_iso (frobenius_morphism F h A) :=
begin
rw ←frobenius_morphism_mate F h at i,
exact @@transfer_nat_trans_self_of_iso _ _ _ _ _ i,
end
/--
If the Frobenius morphism at `A` is an isomorphism, then the exponential comparison transformation
(at `A`) is an isomorphism.
-/
def exp_comparison_iso_of_frobenius_morphism_iso (h : L ⊣ F) (A : C)
[i : is_iso (frobenius_morphism F h A)] :
is_iso (exp_comparison F A) :=
by { rw ← frobenius_morphism_mate F h, apply_instance }
/--
If `F` is full and faithful, and has a left adjoint which preserves binary products, then it is
cartesian closed.
TODO: Show the converse, that if `F` is cartesian closed and its left adjoint preserves binary
products, then it is full and faithful.
-/
def cartesian_closed_functor_of_left_adjoint_preserves_binary_products (h : L ⊣ F)
[full F] [faithful F] [preserves_limits_of_shape (discrete walking_pair) L] :
cartesian_closed_functor F :=
{ comparison_iso := λ A, exp_comparison_iso_of_frobenius_morphism_iso F h _ }
end category_theory
|
571d347853eabf8d8a0360a93918f13d15a0bfbc | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/basics/unnamed_1153.lean | 52d1a3eeee2be75ec581419ab3f2556552215d76 | [] | no_license | jamescheuk91/mathematics_in_lean | 09f1f87d2b0dce53464ff0cbe592c568ff59cf5e | 4452499264e2975bca2f42565c0925506ba5dda3 | refs/heads/master | 1,679,716,410,967 | 1,613,957,947,000 | 1,613,957,947,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 200 | lean | import analysis.special_functions.exp_log
open real
variables a b c : ℝ
-- BEGIN
example (h : 1 ≤ a) (h' : b ≤ c) :
2 + a + exp b ≤ 3 * a + exp c :=
by linarith [exp_le_exp.mpr h']
-- END |
895f4cf3a27000cab5988b0677488f2e52b972e0 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /library/init/data/unsigned/basic.lean | 5455772b4b350c92747cb7f1a9a7320d4c4cc34d | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 865 | 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.data.fin.basic
open nat
def unsigned_sz : nat := succ 4294967295
def unsigned := fin unsigned_sz
namespace unsigned
/- We cannot use tactic dec_trivial here because the tactic framework has not been defined yet. -/
private lemma zero_lt_unsigned_sz : 0 < unsigned_sz :=
zero_lt_succ _
/- Later, we define of_nat using mod, the following version is used to define the metaprogramming system. -/
protected def of_nat' (n : nat) : unsigned :=
if h : n < unsigned_sz then fin.mk n h else fin.mk 0 zero_lt_unsigned_sz
def to_nat (c : unsigned) : nat :=
fin.val c
end unsigned
instance : decidable_eq unsigned :=
have decidable_eq (fin unsigned_sz), from fin.decidable_eq _,
this
|
c44969abddfa3350a566e92b4a9a692c03079976 | 856e2e1615a12f95b551ed48fa5b03b245abba44 | /src/data/dfinsupp.lean | 32c24ca6f7cf8ed079f9e4d3d25f3863030fa1ae | [
"Apache-2.0"
] | permissive | pimsp/mathlib | 8b77e1ccfab21703ba8fbe65988c7de7765aa0e5 | 913318ca9d6979686996e8d9b5ebf7e74aae1c63 | refs/heads/master | 1,669,812,465,182 | 1,597,133,610,000 | 1,597,133,610,000 | 281,890,685 | 1 | 0 | null | 1,595,491,577,000 | 1,595,491,576,000 | null | UTF-8 | Lean | false | false | 32,999 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import algebra.pi_instances
import data.set.finite
/-!
# Dependent functions with finite support
For a non-dependent version see `data/finsupp.lean`.
-/
universes u u₁ u₂ v v₁ v₂ v₃ w x y l
open_locale big_operators
variables (ι : Type u) (β : ι → Type v)
namespace dfinsupp
variable [Π i, has_zero (β i)]
structure pre : Type (max u v) :=
(to_fun : Π i, β i)
(pre_support : multiset ι)
(zero : ∀ i, i ∈ pre_support ∨ to_fun i = 0)
instance inhabited_pre : inhabited (pre ι β) :=
⟨⟨λ i, 0, ∅, λ i, or.inr rfl⟩⟩
instance : setoid (pre ι β) :=
{ r := λ x y, ∀ i, x.to_fun i = y.to_fun i,
iseqv := ⟨λ f i, rfl, λ f g H i, (H i).symm,
λ f g h H1 H2 i, (H1 i).trans (H2 i)⟩ }
end dfinsupp
variable {ι}
/-- A dependent function `Π i, β i` with finite support. -/
@[reducible]
def dfinsupp [Π i, has_zero (β i)] : Type* :=
quotient (dfinsupp.setoid ι β)
variable {β}
notation `Π₀` binders `, ` r:(scoped f, dfinsupp f) := r
infix ` →ₚ `:25 := dfinsupp
namespace dfinsupp
section basic
variables [Π i, has_zero (β i)]
variables {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
variables [Π i, has_zero (β₁ i)] [Π i, has_zero (β₂ i)]
instance : has_coe_to_fun (Π₀ i, β i) :=
⟨λ _, Π i, β i, λ f, quotient.lift_on f pre.to_fun $ λ _ _, funext⟩
instance : has_zero (Π₀ i, β i) := ⟨⟦⟨λ i, 0, ∅, λ i, or.inr rfl⟩⟧⟩
instance : inhabited (Π₀ i, β i) := ⟨0⟩
@[simp] lemma zero_apply {i : ι} : (0 : Π₀ i, β i) i = 0 := rfl
@[ext]
lemma ext {f g : Π₀ i, β i} (H : ∀ i, f i = g i) : f = g :=
quotient.induction_on₂ f g (λ _ _ H, quotient.sound H) H
/-- The composition of `f : β₁ → β₂` and `g : Π₀ i, β₁ i` is
`map_range f hf g : Π₀ i, β₂ i`, well defined when `f 0 = 0`. -/
def map_range (f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) : Π₀ i, β₂ i :=
quotient.lift_on g (λ x, ⟦(⟨λ i, f i (x.1 i), x.2,
λ i, or.cases_on (x.3 i) or.inl $ λ H, or.inr $ by rw [H, hf]⟩ : pre ι β₂)⟧) $ λ x y H,
quotient.sound $ λ i, by simp only [H i]
@[simp] lemma map_range_apply
{f : Π i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} {i : ι} :
map_range f hf g i = f i (g i) :=
quotient.induction_on g $ λ x, rfl
/-- Let `f i` be a binary operation `β₁ i → β₂ i → β i` such that `f i 0 0 = 0`.
Then `zip_with f hf` is a binary operation `Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i`. -/
def zip_with (f : Π i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0)
(g₁ : Π₀ i, β₁ i) (g₂ : Π₀ i, β₂ i) : (Π₀ i, β i) :=
begin
refine quotient.lift_on₂ g₁ g₂ (λ x y, ⟦(⟨λ i, f i (x.1 i) (y.1 i), x.2 + y.2,
λ i, _⟩ : pre ι β)⟧) _,
{ cases x.3 i with h1 h1,
{ left, rw multiset.mem_add, left, exact h1 },
cases y.3 i with h2 h2,
{ left, rw multiset.mem_add, right, exact h2 },
right, rw [h1, h2, hf] },
exact λ x₁ x₂ y₁ y₂ H1 H2, quotient.sound $ λ i, by simp only [H1 i, H2 i]
end
@[simp] lemma zip_with_apply
{f : Π i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} {i : ι} :
zip_with f hf g₁ g₂ i = f i (g₁ i) (g₂ i) :=
quotient.induction_on₂ g₁ g₂ $ λ _ _, rfl
end basic
section algebra
instance [Π i, add_monoid (β i)] : has_add (Π₀ i, β i) :=
⟨zip_with (λ _, (+)) (λ _, add_zero 0)⟩
@[simp] lemma add_apply [Π i, add_monoid (β i)] {g₁ g₂ : Π₀ i, β i} {i : ι} :
(g₁ + g₂) i = g₁ i + g₂ i :=
zip_with_apply
instance [Π i, add_monoid (β i)] : add_monoid (Π₀ i, β i) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := λ f g h, ext $ λ i, by simp only [add_apply, add_assoc],
zero_add := λ f, ext $ λ i, by simp only [add_apply, zero_apply, zero_add],
add_zero := λ f, ext $ λ i, by simp only [add_apply, zero_apply, add_zero] }
instance [Π i, add_monoid (β i)] {i : ι} : is_add_monoid_hom (λ g : Π₀ i : ι, β i, g i) :=
{ map_add := λ _ _, add_apply, map_zero := zero_apply }
instance [Π i, add_group (β i)] : has_neg (Π₀ i, β i) :=
⟨λ f, f.map_range (λ _, has_neg.neg) (λ _, neg_zero)⟩
instance [Π i, add_comm_monoid (β i)] : add_comm_monoid (Π₀ i, β i) :=
{ add_comm := λ f g, ext $ λ i, by simp only [add_apply, add_comm],
.. dfinsupp.add_monoid }
@[simp] lemma neg_apply [Π i, add_group (β i)] {g : Π₀ i, β i} {i : ι} : (- g) i = - g i :=
map_range_apply
instance [Π i, add_group (β i)] : add_group (Π₀ i, β i) :=
{ add_left_neg := λ f, ext $ λ i, by simp only [add_apply, neg_apply, zero_apply, add_left_neg],
.. dfinsupp.add_monoid,
.. (infer_instance : has_neg (Π₀ i, β i)) }
@[simp] lemma sub_apply [Π i, add_group (β i)] {g₁ g₂ : Π₀ i, β i} {i : ι} :
(g₁ - g₂) i = g₁ i - g₂ i :=
by rw [sub_eq_add_neg]; simp [sub_eq_add_neg]
instance [Π i, add_comm_group (β i)] : add_comm_group (Π₀ i, β i) :=
{ add_comm := λ f g, ext $ λ i, by simp only [add_apply, add_comm],
..dfinsupp.add_group }
/-- Dependent functions with finite support inherit a semiring action from an action on each
coordinate. -/
def to_has_scalar {γ : Type w} [semiring γ] [Π i, add_comm_group (β i)] [Π i, semimodule γ (β i)] :
has_scalar γ (Π₀ i, β i) :=
⟨λc v, v.map_range (λ _, (•) c) (λ _, smul_zero _)⟩
local attribute [instance] to_has_scalar
@[simp] lemma smul_apply {γ : Type w} [semiring γ] [Π i, add_comm_group (β i)]
[Π i, semimodule γ (β i)] {i : ι} {b : γ} {v : Π₀ i, β i} :
(b • v) i = b • (v i) :=
map_range_apply
/-- Dependent functions with finite support inherit a semimodule structure from such a structure on
each coordinate. -/
def to_semimodule {γ : Type w} [semiring γ] [Π i, add_comm_group (β i)] [Π i, semimodule γ (β i)] :
semimodule γ (Π₀ i, β i) :=
semimodule.of_core {
smul_add := λ c x y, ext $ λ i, by simp only [add_apply, smul_apply, smul_add],
add_smul := λ c x y, ext $ λ i, by simp only [add_apply, smul_apply, add_smul],
one_smul := λ x, ext $ λ i, by simp only [smul_apply, one_smul],
mul_smul := λ r s x, ext $ λ i, by simp only [smul_apply, smul_smul],
.. (infer_instance : has_scalar γ (Π₀ i, β i)) }
end algebra
section filter_and_subtype_domain
/-- `filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/
def filter [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p] (f : Π₀ i, β i) : Π₀ i, β i :=
quotient.lift_on f (λ x, ⟦(⟨λ i, if p i then x.1 i else 0, x.2,
λ i, or.cases_on (x.3 i) or.inl $ λ H, or.inr $ by rw [H, if_t_t]⟩ : pre ι β)⟧) $ λ x y H,
quotient.sound $ λ i, by simp only [H i]
@[simp] lemma filter_apply [Π i, has_zero (β i)]
{p : ι → Prop} [decidable_pred p] {i : ι} {f : Π₀ i, β i} :
f.filter p i = if p i then f i else 0 :=
quotient.induction_on f $ λ x, rfl
lemma filter_apply_pos [Π i, has_zero (β i)]
{p : ι → Prop} [decidable_pred p] {f : Π₀ i, β i} {i : ι} (h : p i) :
f.filter p i = f i :=
by simp only [filter_apply, if_pos h]
lemma filter_apply_neg [Π i, has_zero (β i)]
{p : ι → Prop} [decidable_pred p] {f : Π₀ i, β i} {i : ι} (h : ¬ p i) :
f.filter p i = 0 :=
by simp only [filter_apply, if_neg h]
lemma filter_pos_add_filter_neg [Π i, add_monoid (β i)] {f : Π₀ i, β i}
{p : ι → Prop} [decidable_pred p] :
f.filter p + f.filter (λi, ¬ p i) = f :=
ext $ λ i, by simp only [add_apply, filter_apply]; split_ifs; simp only [add_zero, zero_add]
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p]
(f : Π₀ i, β i) : Π₀ i : subtype p, β i :=
begin
fapply quotient.lift_on f,
{ intro x,
refine ⟦⟨λ i, x.1 (i : ι),
(x.2.filter p).attach.map $ λ j, ⟨j, (multiset.mem_filter.1 j.2).2⟩, _⟩⟧,
refine λ i, or.cases_on (x.3 i) (λ H, _) or.inr,
left, rw multiset.mem_map, refine ⟨⟨i, multiset.mem_filter.2 ⟨H, i.2⟩⟩, _, subtype.eta _ _⟩,
apply multiset.mem_attach },
intros x y H,
exact quotient.sound (λ i, H i)
end
@[simp] lemma subtype_domain_zero [Π i, has_zero (β i)] {p : ι → Prop} [decidable_pred p] :
subtype_domain p (0 : Π₀ i, β i) = 0 :=
rfl
@[simp] lemma subtype_domain_apply [Π i, has_zero (β i)] {p : ι → Prop} [decidable_pred p]
{i : subtype p} {v : Π₀ i, β i} :
(subtype_domain p v) i = v (i.val) :=
quotient.induction_on v $ λ x, rfl
@[simp] lemma subtype_domain_add [Π i, add_monoid (β i)] {p : ι → Prop} [decidable_pred p]
{v v' : Π₀ i, β i} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ λ i, by simp only [add_apply, subtype_domain_apply]
instance subtype_domain.is_add_monoid_hom [Π i, add_monoid (β i)]
{p : ι → Prop} [decidable_pred p] :
is_add_monoid_hom (subtype_domain p : (Π₀ i : ι, β i) → Π₀ i : subtype p, β i) :=
{ map_add := λ _ _, subtype_domain_add, map_zero := subtype_domain_zero }
@[simp]
lemma subtype_domain_neg [Π i, add_group (β i)] {p : ι → Prop} [decidable_pred p] {v : Π₀ i, β i} :
(- v).subtype_domain p = - v.subtype_domain p :=
ext $ λ i, by simp only [neg_apply, subtype_domain_apply]
@[simp] lemma subtype_domain_sub [Π i, add_group (β i)] {p : ι → Prop} [decidable_pred p]
{v v' : Π₀ i, β i} :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ λ i, by simp only [sub_apply, subtype_domain_apply]
end filter_and_subtype_domain
variable [dec : decidable_eq ι]
include dec
section basic
variable [Π i, has_zero (β i)]
omit dec
lemma finite_supp (f : Π₀ i, β i) : set.finite {i | f i ≠ 0} :=
begin
classical,
exact quotient.induction_on f (λ x, x.2.to_finset.finite_to_set.subset (λ i H,
multiset.mem_to_finset.2 ((x.3 i).resolve_right H)))
end
include dec
/-- Create an element of `Π₀ i, β i` from a finset `s` and a function `x`
defined on this `finset`. -/
def mk (s : finset ι) (x : Π i : (↑s : set ι), β (i : ι)) : Π₀ i, β i :=
⟦⟨λ i, if H : i ∈ s then x ⟨i, H⟩ else 0, s.1,
λ i, if H : i ∈ s then or.inl H else or.inr $ dif_neg H⟩⟧
@[simp] lemma mk_apply {s : finset ι} {x : Π i : (↑s : set ι), β i} {i : ι} :
(mk s x : Π i, β i) i = if H : i ∈ s then x ⟨i, H⟩ else 0 :=
rfl
theorem mk_injective (s : finset ι) : function.injective (@mk ι β _ _ s) :=
begin
intros x y H,
ext i,
have h1 : (mk s x : Π i, β i) i = (mk s y : Π i, β i) i, {rw H},
cases i with i hi,
change i ∈ s at hi,
dsimp only [mk_apply, subtype.coe_mk] at h1,
simpa only [dif_pos hi] using h1
end
/-- The function `single i b : Π₀ i, β i` sends `i` to `b`
and all other points to `0`. -/
def single (i : ι) (b : β i) : Π₀ i, β i :=
mk {i} $ λ j, eq.rec_on (finset.mem_singleton.1 j.prop).symm b
@[simp] lemma single_apply {i i' b} :
(single i b : Π₀ i, β i) i' = (if h : i = i' then eq.rec_on h b else 0) :=
begin
dsimp only [single],
by_cases h : i = i',
{ have h1 : i' ∈ ({i} : finset ι) := finset.mem_singleton.2 h.symm,
simp only [mk_apply, dif_pos h, dif_pos h1], refl },
{ have h1 : i' ∉ ({i} : finset ι) := finset.not_mem_singleton.2 (ne.symm h),
simp only [mk_apply, dif_neg h, dif_neg h1] }
end
@[simp] lemma single_zero {i} : (single i 0 : Π₀ i, β i) = 0 :=
quotient.sound $ λ j, if H : j ∈ ({i} : finset _)
then by dsimp only; rw [dif_pos H]; cases finset.mem_singleton.1 H; refl
else dif_neg H
@[simp] lemma single_eq_same {i b} : (single i b : Π₀ i, β i) i = b :=
by simp only [single_apply, dif_pos rfl]
lemma single_eq_of_ne {i i' b} (h : i ≠ i') : (single i b : Π₀ i, β i) i' = 0 :=
by simp only [single_apply, dif_neg h]
/-- Redefine `f i` to be `0`. -/
def erase (i : ι) (f : Π₀ i, β i) : Π₀ i, β i :=
quotient.lift_on f (λ x, ⟦(⟨λ j, if j = i then 0 else x.1 j, x.2,
λ j, or.cases_on (x.3 j) or.inl $ λ H, or.inr $ by simp only [H, if_t_t]⟩ : pre ι β)⟧) $ λ x y H,
quotient.sound $ λ j, if h : j = i then by simp only [if_pos h]
else by simp only [if_neg h, H j]
@[simp] lemma erase_apply {i j : ι} {f : Π₀ i, β i} :
(f.erase i) j = if j = i then 0 else f j :=
quotient.induction_on f $ λ x, rfl
@[simp] lemma erase_same {i : ι} {f : Π₀ i, β i} : (f.erase i) i = 0 :=
by simp
lemma erase_ne {i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i' :=
by simp [h]
end basic
section add_monoid
variable [Π i, add_monoid (β i)]
@[simp] lemma single_add {i : ι} {b₁ b₂ : β i} : single i (b₁ + b₂) = single i b₁ + single i b₂ :=
ext $ assume i',
begin
by_cases h : i = i',
{ subst h, simp only [add_apply, single_eq_same] },
{ simp only [add_apply, single_eq_of_ne h, zero_add] }
end
lemma single_add_erase {i : ι} {f : Π₀ i, β i} : single i (f i) + f.erase i = f :=
ext $ λ i',
if h : i = i'
then by subst h; simp only [add_apply, single_apply, erase_apply, dif_pos rfl, if_pos, add_zero]
else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (ne.symm h), zero_add]
lemma erase_add_single {i : ι} {f : Π₀ i, β i} : f.erase i + single i (f i) = f :=
ext $ λ i',
if h : i = i'
then by subst h; simp only [add_apply, single_apply, erase_apply, dif_pos rfl, if_pos, zero_add]
else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (ne.symm h), add_zero]
protected theorem induction {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i)
(h0 : p 0) (ha : ∀i b (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (single i b + f)) :
p f :=
begin
refine quotient.induction_on f (λ x, _),
cases x with f s H, revert f H,
apply multiset.induction_on s,
{ intros f H, convert h0, ext i, exact (H i).resolve_left id },
intros i s ih f H,
by_cases H1 : i ∈ s,
{ have H2 : ∀ j, j ∈ s ∨ f j = 0,
{ intro j, cases H j with H2 H2,
{ cases multiset.mem_cons.1 H2 with H3 H3,
{ left, rw H3, exact H1 },
{ left, exact H3 } },
right, exact H2 },
have H3 : (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i)
= ⟦{to_fun := f, pre_support := s, zero := H2}⟧,
{ exact quotient.sound (λ i, rfl) },
rw H3, apply ih },
have H2 : p (erase i ⟦{to_fun := f, pre_support := i :: s, zero := H}⟧),
{ dsimp only [erase, quotient.lift_on_beta],
have H2 : ∀ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0,
{ intro j, cases H j with H2 H2,
{ cases multiset.mem_cons.1 H2 with H3 H3,
{ right, exact if_pos H3 },
{ left, exact H3 } },
right, split_ifs; [refl, exact H2] },
have H3 : (⟦{to_fun := λ (j : ι), ite (j = i) 0 (f j),
pre_support := i :: s, zero := _}⟧ : Π₀ i, β i)
= ⟦{to_fun := λ (j : ι), ite (j = i) 0 (f j), pre_support := s, zero := H2}⟧ :=
quotient.sound (λ i, rfl),
rw H3, apply ih },
have H3 : single i _ + _ = (⟦{to_fun := f, pre_support := i :: s, zero := H}⟧ : Π₀ i, β i) :=
single_add_erase,
rw ← H3,
change p (single i (f i) + _),
cases classical.em (f i = 0) with h h,
{ rw [h, single_zero, zero_add], exact H2 },
refine ha _ _ _ _ h H2,
rw erase_same
end
lemma induction₂ {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i)
(h0 : p 0) (ha : ∀i b (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (f + single i b)) :
p f :=
dfinsupp.induction f h0 $ λ i b f h1 h2 h3,
have h4 : f + single i b = single i b + f,
{ ext j, by_cases H : i = j,
{ subst H, simp [h1] },
{ simp [H] } },
eq.rec_on h4 $ ha i b f h1 h2 h3
end add_monoid
@[simp] lemma mk_add [Π i, add_monoid (β i)] {s : finset ι} {x y : Π i : (↑s : set ι), β i} :
mk s (x + y) = mk s x + mk s y :=
ext $ λ i, by simp only [add_apply, mk_apply]; split_ifs; [refl, rw zero_add]
@[simp] lemma mk_zero [Π i, has_zero (β i)] {s : finset ι} :
mk s (0 : Π i : (↑s : set ι), β i.1) = 0 :=
ext $ λ i, by simp only [mk_apply]; split_ifs; refl
@[simp] lemma mk_neg [Π i, add_group (β i)] {s : finset ι} {x : Π i : (↑s : set ι), β i.1} :
mk s (-x) = -mk s x :=
ext $ λ i, by simp only [neg_apply, mk_apply]; split_ifs; [refl, rw neg_zero]
@[simp] lemma mk_sub [Π i, add_group (β i)] {s : finset ι} {x y : Π i : (↑s : set ι), β i.1} :
mk s (x - y) = mk s x - mk s y :=
ext $ λ i, by simp only [sub_apply, mk_apply]; split_ifs; [refl, rw sub_zero]
instance [Π i, add_group (β i)] {s : finset ι} : is_add_group_hom (@mk ι β _ _ s) :=
{ map_add := λ _ _, mk_add }
section
local attribute [instance] to_semimodule
variables (γ : Type w) [semiring γ] [Π i, add_comm_group (β i)] [Π i, semimodule γ (β i)]
include γ
@[simp] lemma mk_smul {s : finset ι} {c : γ} (x : Π i : (↑s : set ι), β i.1) :
mk s (c • x) = c • mk s x :=
ext $ λ i, by simp only [smul_apply, mk_apply]; split_ifs; [refl, rw smul_zero]
@[simp] lemma single_smul {i : ι} {c : γ} {x : β i} :
single i (c • x) = c • single i x :=
ext $ λ i, by simp only [smul_apply, single_apply]; split_ifs; [cases h, rw smul_zero]; refl
variable β
/-- `dfinsupp.mk` as a `linear_map`. -/
def lmk (s : finset ι) : (Π i : (↑s : set ι), β i.1) →ₗ[γ] Π₀ i, β i :=
⟨mk s, λ _ _, mk_add, λ c x, by rw [mk_smul γ x]⟩
/-- `dfinsupp.single` as a `linear_map` -/
def lsingle (i) : β i →ₗ[γ] Π₀ i, β i :=
⟨single i, λ _ _, single_add, λ _ _, single_smul _⟩
variable {β}
@[simp] lemma lmk_apply {s : finset ι} {x} : lmk β γ s x = mk s x := rfl
@[simp] lemma lsingle_apply {i : ι} {x : β i} : lsingle β γ i x = single i x := rfl
end
section support_basic
variables [Π i, has_zero (β i)] [Π i (x : β i), decidable (x ≠ 0)]
/-- Set `{i | f x ≠ 0}` as a `finset`. -/
def support (f : Π₀ i, β i) : finset ι :=
quotient.lift_on f (λ x, x.2.to_finset.filter $ λ i, x.1 i ≠ 0) $
begin
intros x y Hxy,
ext i, split,
{ intro H,
rcases finset.mem_filter.1 H with ⟨h1, h2⟩,
rw Hxy i at h2,
exact finset.mem_filter.2 ⟨multiset.mem_to_finset.2 $ (y.3 i).resolve_right h2, h2⟩ },
{ intro H,
rcases finset.mem_filter.1 H with ⟨h1, h2⟩,
rw ← Hxy i at h2,
exact finset.mem_filter.2 ⟨multiset.mem_to_finset.2 $ (x.3 i).resolve_right h2, h2⟩ },
end
@[simp] theorem support_mk_subset {s : finset ι} {x : Π i : (↑s : set ι), β i.1} :
(mk s x).support ⊆ s :=
λ i H, multiset.mem_to_finset.1 (finset.mem_filter.1 H).1
@[simp] theorem mem_support_to_fun (f : Π₀ i, β i) (i) : i ∈ f.support ↔ f i ≠ 0 :=
begin
refine quotient.induction_on f (λ x, _),
dsimp only [support, quotient.lift_on_beta],
rw [finset.mem_filter, multiset.mem_to_finset],
exact and_iff_right_of_imp (x.3 i).resolve_right
end
theorem eq_mk_support (f : Π₀ i, β i) : f = mk f.support (λ i, f i) :=
begin
change f = mk f.support (λ i, f i.1),
ext i,
by_cases h : f i ≠ 0; [skip, rw [classical.not_not] at h];
simp [h]
end
@[simp] lemma support_zero : (0 : Π₀ i, β i).support = ∅ := rfl
lemma mem_support_iff (f : Π₀ i, β i) : ∀i:ι, i ∈ f.support ↔ f i ≠ 0 :=
f.mem_support_to_fun
@[simp] lemma support_eq_empty {f : Π₀ i, β i} : f.support = ∅ ↔ f = 0 :=
⟨λ H, ext $ by simpa [finset.ext_iff] using H, by simp {contextual:=tt}⟩
instance decidable_zero : decidable_pred (eq (0 : Π₀ i, β i)) :=
λ f, decidable_of_iff _ $ support_eq_empty.trans eq_comm
lemma support_subset_iff {s : set ι} {f : Π₀ i, β i} :
↑f.support ⊆ s ↔ (∀i∉s, f i = 0) :=
by simp [set.subset_def];
exact forall_congr (assume i, @not_imp_comm _ _ (classical.dec _) (classical.dec _))
lemma support_single_ne_zero {i : ι} {b : β i} (hb : b ≠ 0) : (single i b).support = {i} :=
begin
ext j, by_cases h : i = j,
{ subst h, simp [hb] },
simp [ne.symm h, h]
end
lemma support_single_subset {i : ι} {b : β i} : (single i b).support ⊆ {i} :=
support_mk_subset
section map_range_and_zip_with
variables {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
variables [Π i, has_zero (β₁ i)] [Π i, has_zero (β₂ i)]
lemma map_range_def [Π i (x : β₁ i), decidable (x ≠ 0)]
{f : Π i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} :
map_range f hf g = mk g.support (λ i, f i.1 (g i.1)) :=
begin
ext i,
by_cases h : g i ≠ 0; simp at h; simp [h, hf]
end
@[simp] lemma map_range_single {f : Π i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {i : ι} {b : β₁ i} :
map_range f hf (single i b) = single i (f i b) :=
dfinsupp.ext $ λ i', by by_cases i = i'; [{subst i', simp}, simp [h, hf]]
variables [Π i (x : β₁ i), decidable (x ≠ 0)] [Π i (x : β₂ i), decidable (x ≠ 0)]
lemma support_map_range {f : Π i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} :
(map_range f hf g).support ⊆ g.support :=
by simp [map_range_def]
lemma zip_with_def {f : Π i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0}
{g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} :
zip_with f hf g₁ g₂ = mk (g₁.support ∪ g₂.support) (λ i, f i.1 (g₁ i.1) (g₂ i.1)) :=
begin
ext i,
by_cases h1 : g₁ i ≠ 0; by_cases h2 : g₂ i ≠ 0;
simp only [classical.not_not, ne.def] at h1 h2; simp [h1, h2, hf]
end
lemma support_zip_with {f : Π i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0}
{g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
by simp [zip_with_def]
end map_range_and_zip_with
lemma erase_def (i : ι) (f : Π₀ i, β i) :
f.erase i = mk (f.support.erase i) (λ j, f j.1) :=
by { ext j, by_cases h1 : j = i; by_cases h2 : f j ≠ 0; simp at h2; simp [h1, h2] }
@[simp] lemma support_erase (i : ι) (f : Π₀ i, β i) :
(f.erase i).support = f.support.erase i :=
by { ext j, by_cases h1 : j = i; by_cases h2 : f j ≠ 0; simp at h2; simp [h1, h2] }
section filter_and_subtype_domain
variables {p : ι → Prop} [decidable_pred p]
lemma filter_def (f : Π₀ i, β i) :
f.filter p = mk (f.support.filter p) (λ i, f i.1) :=
by ext i; by_cases h1 : p i; by_cases h2 : f i ≠ 0;
simp at h2; simp [h1, h2]
@[simp] lemma support_filter (f : Π₀ i, β i) :
(f.filter p).support = f.support.filter p :=
by ext i; by_cases h : p i; simp [h]
lemma subtype_domain_def (f : Π₀ i, β i) :
f.subtype_domain p = mk (f.support.subtype p) (λ i, f i.1) :=
by ext i; cases i with i hi;
by_cases h1 : p i; by_cases h2 : f i ≠ 0;
try {simp at h2}; dsimp; simp [h1, h2]
@[simp] lemma support_subtype_domain {f : Π₀ i, β i} :
(subtype_domain p f).support = f.support.subtype p :=
by ext i; cases i with i hi;
by_cases h1 : p i; by_cases h2 : f i ≠ 0;
try {simp at h2}; dsimp; simp [h1, h2]
end filter_and_subtype_domain
end support_basic
lemma support_add [Π i, add_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)] {g₁ g₂ : Π₀ i, β i} :
(g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
@[simp] lemma support_neg [Π i, add_group (β i)] [Π i (x : β i), decidable (x ≠ 0)]
{f : Π₀ i, β i} :
support (-f) = support f :=
by ext i; simp
local attribute [instance] dfinsupp.to_semimodule
lemma support_smul {γ : Type w} [ring γ] [Π i, add_comm_group (β i)] [Π i, module γ (β i)]
[Π (i : ι) (x : β i), decidable (x ≠ 0)]
{b : γ} {v : Π₀ i, β i} : (b • v).support ⊆ v.support :=
support_map_range
instance [Π i, has_zero (β i)] [Π i, decidable_eq (β i)] : decidable_eq (Π₀ i, β i) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀i∈f.support, f i = g i))
⟨assume ⟨h₁, h₂⟩, ext $ assume i,
if h : i ∈ f.support then h₂ i h else
have hf : f i = 0, by rwa [f.mem_support_iff, not_not] at h,
have hg : g i = 0, by rwa [h₁, g.mem_support_iff, not_not] at h,
by rw [hf, hg],
by intro h; subst h; simp⟩
section prod_and_sum
variables {γ : Type w}
-- [to_additive sum] for dfinsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g i (f i)` over the support of `f`. -/
def sum [Π i, has_zero (β i)] [Π i (x : β i), decidable (x ≠ 0)] [add_comm_monoid γ]
(f : Π₀ i, β i) (g : Π i, β i → γ) : γ :=
∑ i in f.support, g i (f i)
/-- `prod f g` is the product of `g i (f i)` over the support of `f`. -/
@[to_additive]
def prod [Π i, has_zero (β i)] [Π i (x : β i), decidable (x ≠ 0)] [comm_monoid γ]
(f : Π₀ i, β i) (g : Π i, β i → γ) : γ :=
∏ i in f.support, g i (f i)
@[to_additive]
lemma prod_map_range_index {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
[Π i, has_zero (β₁ i)] [Π i, has_zero (β₂ i)]
[Π i (x : β₁ i), decidable (x ≠ 0)] [Π i (x : β₂ i), decidable (x ≠ 0)] [comm_monoid γ]
{f : Π i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} {h : Π i, β₂ i → γ}
(h0 : ∀i, h i 0 = 1) :
(map_range f hf g).prod h = g.prod (λi b, h i (f i b)) :=
begin
rw [map_range_def],
refine (finset.prod_subset support_mk_subset _).trans _,
{ intros i h1 h2,
dsimp, simp [h1] at h2, dsimp at h2,
simp [h1, h2, h0] },
{ refine finset.prod_congr rfl _,
intros i h1,
simp [h1] }
end
@[to_additive]
lemma prod_zero_index [Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[comm_monoid γ] {h : Π i, β i → γ} : (0 : Π₀ i, β i).prod h = 1 :=
rfl
@[to_additive]
lemma prod_single_index [Π i, has_zero (β i)] [Π i (x : β i), decidable (x ≠ 0)] [comm_monoid γ]
{i : ι} {b : β i} {h : Π i, β i → γ} (h_zero : h i 0 = 1) :
(single i b).prod h = h i b :=
begin
by_cases h : b ≠ 0,
{ simp [dfinsupp.prod, support_single_ne_zero h] },
{ rw [classical.not_not] at h, simp [h, prod_zero_index, h_zero], refl }
end
@[to_additive]
lemma prod_neg_index [Π i, add_group (β i)] [Π i (x : β i), decidable (x ≠ 0)] [comm_monoid γ]
{g : Π₀ i, β i} {h : Π i, β i → γ} (h0 : ∀i, h i 0 = 1) :
(-g).prod h = g.prod (λi b, h i (- b)) :=
prod_map_range_index h0
omit dec
@[simp] lemma sum_apply {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ → Type v₁}
[Π i₁, has_zero (β₁ i₁)] [Π i (x : β₁ i), decidable (x ≠ 0)]
[Π i, add_comm_monoid (β i)]
{f : Π₀ i₁, β₁ i₁} {g : Π i₁, β₁ i₁ → Π₀ i, β i} {i₂ : ι} :
(f.sum g) i₂ = f.sum (λi₁ b, g i₁ b i₂) :=
(f.support.sum_hom (λf : Π₀ i, β i, f i₂)).symm
include dec
lemma support_sum {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ → Type v₁}
[Π i₁, has_zero (β₁ i₁)] [Π i (x : β₁ i), decidable (x ≠ 0)]
[Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
{f : Π₀ i₁, β₁ i₁} {g : Π i₁, β₁ i₁ → Π₀ i, β i} :
(f.sum g).support ⊆ f.support.bind (λi, (g i (f i)).support) :=
have ∀i₁ : ι, f.sum (λ (i : ι₁) (b : β₁ i), (g i b) i₁) ≠ 0 →
(∃ (i : ι₁), f i ≠ 0 ∧ ¬ (g i (f i)) i₁ = 0),
from assume i₁ h,
let ⟨i, hi, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨i, (f.mem_support_iff i).mp hi, ne⟩,
by simpa [finset.subset_iff, mem_support_iff, finset.mem_bind, sum_apply] using this
@[simp] lemma sum_zero [Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[add_comm_monoid γ] {f : Π₀ i, β i} :
f.sum (λi b, (0 : γ)) = 0 :=
finset.sum_const_zero
@[simp] lemma sum_add [Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[add_comm_monoid γ] {f : Π₀ i, β i} {h₁ h₂ : Π i, β i → γ} :
f.sum (λi b, h₁ i b + h₂ i b) = f.sum h₁ + f.sum h₂ :=
finset.sum_add_distrib
@[simp] lemma sum_neg [Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[add_comm_group γ] {f : Π₀ i, β i} {h : Π i, β i → γ} :
f.sum (λi b, - h i b) = - f.sum h :=
f.support.sum_hom (@has_neg.neg γ _)
@[to_additive]
lemma prod_add_index [Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[comm_monoid γ] {f g : Π₀ i, β i}
{h : Π i, β i → γ} (h_zero : ∀i, h i 0 = 1) (h_add : ∀i b₁ b₂, h i (b₁ + b₂) = h i b₁ * h i b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have f_eq : ∏ i in f.support ∪ g.support, h i (f i) = f.prod h,
from (finset.prod_subset (finset.subset_union_left _ _) $
by simp [mem_support_iff, h_zero] {contextual := tt}).symm,
have g_eq : ∏ i in f.support ∪ g.support, h i (g i) = g.prod h,
from (finset.prod_subset (finset.subset_union_right _ _) $
by simp [mem_support_iff, h_zero] {contextual := tt}).symm,
calc ∏ i in (f + g).support, h i ((f + g) i) =
∏ i in f.support ∪ g.support, h i ((f + g) i) :
finset.prod_subset support_add $
by simp [mem_support_iff, h_zero] {contextual := tt}
... = (∏ i in f.support ∪ g.support, h i (f i)) *
(∏ i in f.support ∪ g.support, h i (g i)) :
by simp [h_add, finset.prod_mul_distrib]
... = _ : by rw [f_eq, g_eq]
lemma sum_sub_index [Π i, add_comm_group (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[add_comm_group γ] {f g : Π₀ i, β i}
{h : Π i, β i → γ} (h_sub : ∀i b₁ b₂, h i (b₁ - b₂) = h i b₁ - h i b₂) :
(f - g).sum h = f.sum h - g.sum h :=
have h_zero : ∀i, h i 0 = 0,
from assume i,
have h i (0 - 0) = h i 0 - h i 0, from h_sub i 0 0,
by simpa using this,
have h_neg : ∀i b, h i (- b) = - h i b,
from assume i b,
have h i (0 - b) = h i 0 - h i b, from h_sub i 0 b,
by simpa [h_zero] using this,
have h_add : ∀i b₁ b₂, h i (b₁ + b₂) = h i b₁ + h i b₂,
from assume i b₁ b₂,
have h i (b₁ - (- b₂)) = h i b₁ - h i (- b₂), from h_sub i b₁ (-b₂),
by simpa [h_neg, sub_eq_add_neg] using this,
by simp [sub_eq_add_neg];
simp [@sum_add_index ι β _ γ _ _ _ f (-g) h h_zero h_add];
simp [@sum_neg_index ι β _ γ _ _ _ g h h_zero, h_neg];
simp [@sum_neg ι β _ γ _ _ _ g h]
@[to_additive]
lemma prod_finset_sum_index {γ : Type w} {α : Type x}
[Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[comm_monoid γ]
{s : finset α} {g : α → Π₀ i, β i}
{h : Π i, β i → γ} (h_zero : ∀i, h i 0 = 1) (h_add : ∀i b₁ b₂, h i (b₁ + b₂) = h i b₁ * h i b₂) :
∏ i in s, (g i).prod h = (∑ i in s, g i).prod h :=
begin
classical,
exact finset.induction_on s
(by simp [prod_zero_index])
(by simp [prod_add_index, h_zero, h_add] {contextual := tt})
end
@[to_additive]
lemma prod_sum_index {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ → Type v₁}
[Π i₁, has_zero (β₁ i₁)] [Π i (x : β₁ i), decidable (x ≠ 0)]
[Π i, add_comm_monoid (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[comm_monoid γ]
{f : Π₀ i₁, β₁ i₁} {g : Π i₁, β₁ i₁ → Π₀ i, β i}
{h : Π i, β i → γ} (h_zero : ∀i, h i 0 = 1) (h_add : ∀i b₁ b₂, h i (b₁ + b₂) = h i b₁ * h i b₂) :
(f.sum g).prod h = f.prod (λi b, (g i b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
@[simp] lemma sum_single [Π i, add_comm_monoid (β i)]
[Π i (x : β i), decidable (x ≠ 0)] {f : Π₀ i, β i} :
f.sum single = f :=
begin
apply dfinsupp.induction f, {rw [sum_zero_index]},
intros i b f H hb ih,
rw [sum_add_index, ih, sum_single_index],
all_goals { intros, simp }
end
@[to_additive]
lemma prod_subtype_domain_index [Π i, has_zero (β i)] [Π i (x : β i), decidable (x ≠ 0)]
[comm_monoid γ] {v : Π₀ i, β i} {p : ι → Prop} [decidable_pred p]
{h : Π i, β i → γ} (hp : ∀ x ∈ v.support, p x) :
(v.subtype_domain p).prod (λi b, h i.1 b) = v.prod h :=
finset.prod_bij (λp _, p.val)
(by { dsimp, simp })
(by simp)
(assume ⟨a₀, ha₀⟩ ⟨a₁, ha₁⟩, by simp)
(λ i hi, ⟨⟨i, hp i hi⟩, by simpa using hi, rfl⟩)
omit dec
lemma subtype_domain_sum [Π i, add_comm_monoid (β i)]
{s : finset γ} {h : γ → Π₀ i, β i} {p : ι → Prop} [decidable_pred p] :
(∑ c in s, h c).subtype_domain p = ∑ c in s, (h c).subtype_domain p :=
eq.symm (s.sum_hom _)
lemma subtype_domain_finsupp_sum {δ : γ → Type x} [decidable_eq γ]
[Π c, has_zero (δ c)] [Π c (x : δ c), decidable (x ≠ 0)]
[Π i, add_comm_monoid (β i)]
{p : ι → Prop} [decidable_pred p]
{s : Π₀ c, δ c} {h : Π c, δ c → Π₀ i, β i} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
end prod_and_sum
end dfinsupp
|
359674318a528cf458522c5819abc048248a8f43 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/order/field.lean | 795a5e6f13c5c69bb4ffea7fdee7e93d9efcff8c | [
"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 | 30,081 | lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import algebra.field.basic
import algebra.group_power.order
import algebra.order.ring
import order.bounds
import tactic.monotonicity.basic
/-!
# Linear ordered fields
A linear ordered field is a field equipped with a linear order such that
* addition respects the order: `a ≤ b → c + a ≤ c + b`;
* multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`;
* `0 < 1`.
## Main Definitions
* `linear_ordered_field`: the class of linear ordered fields.
-/
set_option old_structure_cmd true
variable {α : Type*}
/-- A linear ordered field is a field with a linear order respecting the operations. -/
@[protect_proj] class linear_ordered_field (α : Type*) extends linear_ordered_comm_ring α, field α
section linear_ordered_field
variables [linear_ordered_field α] {a b c d e : α}
section
/-- `equiv.mul_left₀` as an order_iso. -/
@[simps {simp_rhs := tt}]
def order_iso.mul_left₀ (a : α) (ha : 0 < a) : α ≃o α :=
{ map_rel_iff' := λ _ _, mul_le_mul_left ha, ..equiv.mul_left₀ a ha.ne' }
/-- `equiv.mul_right₀` as an order_iso. -/
@[simps {simp_rhs := tt}]
def order_iso.mul_right₀ (a : α) (ha : 0 < a) : α ≃o α :=
{ map_rel_iff' := λ _ _, mul_le_mul_right ha, ..equiv.mul_right₀ a ha.ne' }
end
/-!
### Lemmas about pos, nonneg, nonpos, neg
-/
@[simp] lemma inv_pos : 0 < a⁻¹ ↔ 0 < a :=
suffices ∀ a : α, 0 < a → 0 < a⁻¹,
from ⟨λ h, inv_inv₀ a ▸ this _ h, this a⟩,
assume a ha, flip lt_of_mul_lt_mul_left ha.le $ by simp [ne_of_gt ha, zero_lt_one]
@[simp] lemma inv_nonneg : 0 ≤ a⁻¹ ↔ 0 ≤ a :=
by simp only [le_iff_eq_or_lt, inv_pos, zero_eq_inv]
@[simp] lemma inv_lt_zero : a⁻¹ < 0 ↔ a < 0 :=
by simp only [← not_le, inv_nonneg]
@[simp] lemma inv_nonpos : a⁻¹ ≤ 0 ↔ a ≤ 0 :=
by simp only [← not_lt, inv_pos]
lemma one_div_pos : 0 < 1 / a ↔ 0 < a :=
inv_eq_one_div a ▸ inv_pos
lemma one_div_neg : 1 / a < 0 ↔ a < 0 :=
inv_eq_one_div a ▸ inv_lt_zero
lemma one_div_nonneg : 0 ≤ 1 / a ↔ 0 ≤ a :=
inv_eq_one_div a ▸ inv_nonneg
lemma one_div_nonpos : 1 / a ≤ 0 ↔ a ≤ 0 :=
inv_eq_one_div a ▸ inv_nonpos
lemma div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 :=
by simp [division_def, mul_pos_iff]
lemma div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b :=
by simp [division_def, mul_neg_iff]
lemma div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=
by simp [division_def, mul_nonneg_iff]
lemma div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b :=
by simp [division_def, mul_nonpos_iff]
lemma div_pos (ha : 0 < a) (hb : 0 < b) : 0 < a / b :=
div_pos_iff.2 $ or.inl ⟨ha, hb⟩
lemma div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 $ or.inr ⟨ha, hb⟩
lemma div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 $ or.inr ⟨ha, hb⟩
lemma div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 $ or.inl ⟨ha, hb⟩
lemma div_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b :=
div_nonneg_iff.2 $ or.inl ⟨ha, hb⟩
lemma div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=
div_nonneg_iff.2 $ or.inr ⟨ha, hb⟩
lemma div_nonpos_of_nonpos_of_nonneg (ha : a ≤ 0) (hb : 0 ≤ b) : a / b ≤ 0 :=
div_nonpos_iff.2 $ or.inr ⟨ha, hb⟩
lemma div_nonpos_of_nonneg_of_nonpos (ha : 0 ≤ a) (hb : b ≤ 0) : a / b ≤ 0 :=
div_nonpos_iff.2 $ or.inl ⟨ha, hb⟩
/-!
### Relating one division with another term.
-/
lemma le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=
⟨λ h, div_mul_cancel b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le,
λ h, calc
a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc).symm
... ≤ b * (1 / c) : mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le
... = b / c : (div_eq_mul_one_div b c).symm⟩
lemma le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b :=
by rw [mul_comm, le_div_iff hc]
lemma div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b :=
⟨λ h, calc
a = a / b * b : by rw (div_mul_cancel _ (ne_of_lt hb).symm)
... ≤ c * b : mul_le_mul_of_nonneg_right h hb.le,
λ h, calc
a / b = a * (1 / b) : div_eq_mul_one_div a b
... ≤ (c * b) * (1 / b) : mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le
... = (c * b) / b : (div_eq_mul_one_div (c * b) b).symm
... = c : by refine (div_eq_iff (ne_of_gt hb)).mpr rfl⟩
lemma div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c :=
by rw [mul_comm, div_le_iff hb]
lemma lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b :=
lt_iff_lt_of_le_iff_le $ div_le_iff hc
lemma lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b :=
by rw [mul_comm, lt_div_iff hc]
lemma div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c :=
lt_iff_lt_of_le_iff_le (le_div_iff hc)
lemma div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a :=
by rw [mul_comm, div_lt_iff hc]
lemma inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c :=
begin
rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div],
exact div_le_iff' h,
end
lemma inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b :=
by rw [inv_mul_le_iff h, mul_comm]
lemma mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c :=
by rw [mul_comm, inv_mul_le_iff h]
lemma mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b :=
by rw [mul_comm, inv_mul_le_iff' h]
lemma div_self_le_one (a : α) : a / a ≤ 1 :=
if h : a = 0 then by simp [h] else by simp [h]
lemma inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c :=
begin
rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div],
exact div_lt_iff' h,
end
lemma inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b :=
by rw [inv_mul_lt_iff h, mul_comm]
lemma mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c :=
by rw [mul_comm, inv_mul_lt_iff h]
lemma mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b :=
by rw [mul_comm, inv_mul_lt_iff' h]
lemma inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a :=
by { rw [inv_eq_one_div], exact div_le_iff ha }
lemma inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b :=
by { rw [inv_eq_one_div], exact div_le_iff' ha }
lemma inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a :=
by { rw [inv_eq_one_div], exact div_lt_iff ha }
lemma inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b :=
by { rw [inv_eq_one_div], exact div_lt_iff' ha }
lemma div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b :=
⟨λ h, div_mul_cancel b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le,
λ h, calc
a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc)
... ≥ b * (1 / c) : mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le
... = b / c : (div_eq_mul_one_div b c).symm⟩
lemma div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b :=
by rw [mul_comm, div_le_iff_of_neg hc]
lemma le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c :=
by rw [← neg_neg c, mul_neg_eq_neg_mul_symm, div_neg, le_neg,
div_le_iff (neg_pos.2 hc), neg_mul_eq_neg_mul_symm]
lemma le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a :=
by rw [mul_comm, le_div_iff_of_neg hc]
lemma div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b :=
lt_iff_lt_of_le_iff_le $ le_div_iff_of_neg hc
lemma div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b :=
by rw [mul_comm, div_lt_iff_of_neg hc]
lemma lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c :=
lt_iff_lt_of_le_iff_le $ div_le_iff_of_neg hc
lemma lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a :=
by rw [mul_comm, lt_div_iff_of_neg hc]
/-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/
lemma div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c :=
by { rcases eq_or_lt_of_le hb with rfl|hb', simp [hc], rwa [div_le_iff hb'] }
lemma div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 :=
div_le_of_nonneg_of_le_mul hb zero_le_one $ by rwa one_mul
/-!
### Bi-implications of inequalities using inversions
-/
lemma inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ :=
by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul]
/-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/
lemma inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul]
/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`.
See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/
lemma inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv₀]
lemma inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a :=
(inv_le ha ((inv_pos.2 ha).trans_le h)).1 h
lemma le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv₀]
lemma inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv hb ha)
/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`.
See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/
lemma inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv hb ha)
lemma inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a :=
(inv_lt ha ((inv_pos.2 ha).trans h)).1 h
lemma lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le hb ha)
lemma inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
lemma inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv₀]
lemma le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv₀]
lemma inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
lemma inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
lemma lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
lemma inv_lt_one (ha : 1 < a) : a⁻¹ < 1 :=
by rwa [inv_lt ((@zero_lt_one α _ _).trans ha) zero_lt_one, inv_one]
lemma one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ :=
by rwa [lt_inv (@zero_lt_one α _ _) h₁, inv_one]
lemma inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 :=
by rwa [inv_le ((@zero_lt_one α _ _).trans_le ha) zero_lt_one, inv_one]
lemma one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ :=
by rwa [le_inv (@zero_lt_one α _ _) h₁, inv_one]
lemma inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a :=
⟨λ h₁, inv_inv₀ a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩
lemma inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a :=
begin
cases le_or_lt a 0 with ha ha,
{ simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] },
{ simp only [ha.not_le, false_or, inv_lt_one_iff_of_pos ha] }
end
lemma one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 :=
⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv₀ a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩
lemma inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a :=
begin
rcases em (a = 1) with (rfl|ha),
{ simp [le_rfl] },
{ simp only [ne.le_iff_lt (ne.symm ha), ne.le_iff_lt (mt inv_eq_one₀.1 ha), inv_lt_one_iff] }
end
lemma one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 :=
⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv₀ a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩
/-!
### Relating two divisions.
-/
@[mono] lemma div_le_div_of_le (hc : 0 ≤ c) (h : a ≤ b) : a / c ≤ b / c :=
begin
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 hc)
end
-- Not a `mono` lemma b/c `div_le_div` is strictly more general
lemma div_le_div_of_le_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c :=
begin
rw [div_eq_mul_inv, div_eq_mul_inv],
exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha
end
lemma div_le_div_of_le_of_nonneg (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c :=
div_le_div_of_le hc hab
lemma div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c :=
begin
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],
exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc)
end
lemma div_lt_div_of_lt (hc : 0 < c) (h : a < b) : a / c < b / c :=
begin
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],
exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc)
end
lemma div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c :=
begin
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c],
exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc)
end
lemma div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b :=
⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_lt hc, div_le_div_of_le $ hc.le⟩
lemma div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a :=
⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le $ hc.le⟩
lemma div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b :=
lt_iff_lt_of_le_iff_le $ div_le_div_right hc
lemma div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a :=
lt_iff_lt_of_le_iff_le $ div_le_div_right_of_neg hc
lemma div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b :=
by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc]
lemma div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb)
lemma div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) :
a / b < c / d ↔ a * d < c * b :=
by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0]
lemma div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b :=
by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0]
@[mono] lemma div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d :=
by { rw div_le_div_iff (hd.trans_le hbd) hd, exact mul_le_mul hac hbd hd.le hc }
lemma div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) :
a / b < c / d :=
(div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0)
lemma div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) :
a / b < c / d :=
(div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0)
lemma div_lt_div_of_lt_left (hc : 0 < c) (hb : 0 < b) (h : b < a) : c / a < c / b :=
(div_lt_div_left hc (hb.trans h) hb).mpr h
/-!
### Relating one division and involving `1`
-/
lemma div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a :=
by simpa only [div_one] using div_le_div_of_le_left ha zero_lt_one hb
lemma div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a :=
by simpa only [div_one] using div_lt_div_of_lt_left ha zero_lt_one hb
lemma one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a :=
by rw [le_div_iff hb, one_mul]
lemma div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b :=
by rw [div_le_iff hb, one_mul]
lemma one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a :=
by rw [lt_div_iff hb, one_mul]
lemma div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b :=
by rw [div_lt_iff hb, one_mul]
lemma one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b :=
by rw [le_div_iff_of_neg hb, one_mul]
lemma div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a :=
by rw [div_le_iff_of_neg hb, one_mul]
lemma one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b :=
by rw [lt_div_iff_of_neg hb, one_mul]
lemma div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a :=
by rw [div_lt_iff_of_neg hb, one_mul]
lemma one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a :=
by simpa using inv_le ha hb
lemma one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a :=
by simpa using inv_lt ha hb
lemma le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a :=
by simpa using le_inv ha hb
lemma lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a :=
by simpa using lt_inv ha hb
lemma one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a :=
by simpa using inv_le_of_neg ha hb
lemma one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a :=
by simpa using inv_lt_of_neg ha hb
lemma le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a :=
by simpa using le_inv_of_neg ha hb
lemma lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a :=
by simpa using lt_inv_of_neg ha hb
lemma one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b :=
begin
rcases lt_trichotomy b 0 with (hb|rfl|hb),
{ simp [hb, hb.not_lt, one_lt_div_of_neg] },
{ simp [lt_irrefl, zero_le_one] },
{ simp [hb, hb.not_lt, one_lt_div] }
end
lemma one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b :=
begin
rcases lt_trichotomy b 0 with (hb|rfl|hb),
{ simp [hb, hb.not_lt, one_le_div_of_neg] },
{ simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] },
{ simp [hb, hb.not_lt, one_le_div] }
end
lemma div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a :=
begin
rcases lt_trichotomy b 0 with (hb|rfl|hb),
{ simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] },
{ simp [zero_lt_one], },
{ simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] }
end
lemma div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a :=
begin
rcases lt_trichotomy b 0 with (hb|rfl|hb),
{ simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] },
{ simp [zero_le_one], },
{ simp [hb, hb.not_lt, div_le_one, hb.ne.symm] }
end
/-!
### Relating two divisions, involving `1`
-/
lemma one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a :=
by simpa using inv_le_inv_of_le ha h
lemma one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a :=
by rwa [lt_div_iff' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]
lemma one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a :=
by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)]
lemma one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a :=
by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]
lemma le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
lemma lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
lemma le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h
lemma lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
lemma one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a :=
div_le_div_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
lemma one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a :=
div_lt_div_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and
`lt_of_one_div_lt_one_div` -/
lemma one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a :=
by simpa [one_div] using inv_le_inv_of_neg ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
lemma one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a :=
lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)
lemma one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a :=
by rwa [lt_one_div (@zero_lt_one α _ _) h1, one_div_one]
lemma one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a :=
by rwa [le_one_div (@zero_lt_one α _ _) h1, one_div_one]
lemma one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=
suffices 1 / a < 1 / -1, by rwa one_div_neg_one_eq_neg_one at this,
one_div_lt_one_div_of_neg_of_lt h1 h2
lemma one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 :=
suffices 1 / a ≤ 1 / -1, by rwa one_div_neg_one_eq_neg_one at this,
one_div_le_one_div_of_neg_of_le h1 h2
/-!
### Results about halving.
The equalities also hold in fields of characteristic `0`. -/
lemma add_halves (a : α) : a / 2 + a / 2 = a :=
by rw [div_add_div_same, ← two_mul, mul_div_cancel_left a two_ne_zero]
lemma sub_self_div_two (a : α) : a - a / 2 = a / 2 :=
suffices a / 2 + a / 2 - a / 2 = a / 2, by rwa add_halves at this,
by rw [add_sub_cancel]
lemma div_two_sub_self (a : α) : a / 2 - a = - (a / 2) :=
suffices a / 2 - (a / 2 + a / 2) = - (a / 2), by rwa add_halves at this,
by rw [sub_add_eq_sub_sub, sub_self, zero_sub]
lemma add_self_div_two (a : α) : (a + a) / 2 = a :=
by rw [← mul_two, mul_div_cancel a two_ne_zero]
lemma half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two
lemma one_half_pos : (0:α) < 1 / 2 := half_pos zero_lt_one
lemma div_two_lt_of_pos (h : 0 < a) : a / 2 < a :=
by { rw [div_lt_iff (@zero_lt_two α _ _)], exact lt_mul_of_one_lt_right h one_lt_two }
lemma half_lt_self : 0 < a → a / 2 < a := div_two_lt_of_pos
lemma half_le_self (ha_nonneg : 0 ≤ a) : a / 2 ≤ a :=
begin
by_cases h0 : a = 0,
{ simp [h0], },
{ rw ← ne.def at h0,
exact (half_lt_self (lt_of_le_of_ne ha_nonneg h0.symm)).le, },
end
lemma one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one
lemma add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b :=
begin
rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b/2), ← add_assoc, ← sub_eq_add_neg,
← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (@zero_lt_two α _ _)]
end
lemma left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff, mul_two]
lemma add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff, mul_two]
/-- An inequality involving `2`. -/
lemma sub_one_div_inv_le_two (a2 : 2 ≤ a) :
(1 - 1 / a)⁻¹ ≤ 2 :=
begin
-- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a`
refine trans (inv_le_inv_of_le (inv_pos.mpr zero_lt_two) _) (inv_inv₀ (2 : α)).le,
-- move `1 / a` to the left and `1 - 1 / 2 = 1 / 2` to the right to obtain `1 / a ≤ ⅟ 2`
refine trans ((le_sub_iff_add_le.mpr ((_ : _ + 2⁻¹ = _ ).le))) ((sub_le_sub_iff_left 1).mpr _),
{ -- show 2⁻¹ + 2⁻¹ = 1
exact trans (two_mul _).symm (mul_inv_cancel two_ne_zero) },
{ -- take inverses on both sides and use the assumption `2 ≤ a`.
exact (one_div a).le.trans (inv_le_inv_of_le zero_lt_two a2) }
end
/-!
### Miscellaneous lemmas
-/
/-- Pullback a `linear_ordered_field` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.linear_ordered_field {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β] [has_inv β] [has_div β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) :
linear_ordered_field β :=
{ ..hf.linear_ordered_ring f zero one add mul neg sub,
..hf.field f zero one add mul neg sub inv div}
lemma mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) < 0 ↔ a / c < b / d :=
by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero]
alias mul_sub_mul_div_mul_neg_iff ↔ div_lt_div_of_mul_sub_mul_div_neg mul_sub_mul_div_mul_neg
lemma mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d :=
by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos]
alias mul_sub_mul_div_mul_nonpos_iff ↔
div_le_div_of_mul_sub_mul_div_nonpos mul_sub_mul_div_mul_nonpos
lemma mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c :=
begin
rw [← mul_div_assoc] at h,
rwa [mul_comm b, ← div_le_iff hc],
end
lemma div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :
a / (b * e) ≤ c / (d * e) :=
begin
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div],
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
end
lemma exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c : α, b + c < a ∧ 0 < c :=
⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩
lemma exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a :=
begin
have : 0 < a / max (b + 1) 1, from div_pos h (lt_max_iff.2 (or.inr zero_lt_one)),
refine ⟨a / max (b + 1) 1, this, _⟩,
rw [← lt_div_iff this, div_div_cancel' h.ne'],
exact lt_max_iff.2 (or.inl $ lt_add_one _)
end
lemma le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a :=
begin
contrapose! h,
simpa only [and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt]
using exists_add_lt_and_pos_of_lt h,
end
lemma monotone.div_const {β : Type*} [preorder β] {f : β → α} (hf : monotone f)
{c : α} (hc : 0 ≤ c) : monotone (λ x, (f x) / c) :=
by simpa only [div_eq_mul_inv] using hf.mul_const (inv_nonneg.2 hc)
lemma strict_mono.div_const {β : Type*} [preorder β] {f : β → α} (hf : strict_mono f)
{c : α} (hc : 0 < c) :
strict_mono (λ x, (f x) / c) :=
by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_field.to_densely_ordered : densely_ordered α :=
{ dense := λ a₁ a₂ h, ⟨(a₁ + a₂) / 2,
calc a₁ = (a₁ + a₁) / 2 : (add_self_div_two a₁).symm
... < (a₁ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_left h _),
calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_right h _)
... = a₂ : add_self_div_two a₂⟩ }
lemma mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b :=
mul_self_eq_mul_self_iff.trans $ or_iff_left_of_imp $
λ h, by { subst a, have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0, rw [this, neg_zero] }
lemma min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = (min a b) / c :=
eq.symm $ monotone.map_min (λ x y, div_le_div_of_le hc)
lemma max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = (max a b) / c :=
eq.symm $ monotone.map_max (λ x y, div_le_div_of_le hc)
lemma min_div_div_right_of_nonpos {c : α} (hc : c ≤ 0) (a b : α) :
min (a / c) (b / c) = (max a b) / c :=
eq.symm $ @monotone.map_max α (order_dual α) _ _ _ _ _ (λ x y, div_le_div_of_nonpos_of_le hc)
lemma max_div_div_right_of_nonpos {c : α} (hc : c ≤ 0) (a b : α) :
max (a / c) (b / c) = (min a b) / c :=
eq.symm $ @monotone.map_min α (order_dual α) _ _ _ _ _ (λ x y, div_le_div_of_nonpos_of_le hc)
lemma abs_div (a b : α) : |a / b| = |a| / |b| := (abs_hom : α →*₀ α).map_div a b
lemma abs_one_div (a : α) : |1 / a| = 1 / |a| :=
by rw [abs_div, abs_one]
lemma abs_inv (a : α) : |a⁻¹| = (|a|)⁻¹ := (abs_hom : α →*₀ α).map_inv a
-- TODO: add lemmas with `a⁻¹`.
lemma one_div_strict_anti_on : strict_anti_on (λ x : α, 1 / x) (set.Ioi 0) :=
λ x x1 y y1 xy, (one_div_lt_one_div (set.mem_Ioi.mp y1) (set.mem_Ioi.mp x1)).mpr xy
lemma one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :
1 / a ^ n ≤ 1 / a ^ m :=
by refine (one_div_le_one_div _ _).mpr (pow_le_pow a1 mn);
exact pow_pos (zero_lt_one.trans_le a1) _
lemma one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :
1 / a ^ n < 1 / a ^ m :=
by refine (one_div_lt_one_div _ _).mpr (pow_lt_pow a1 mn);
exact pow_pos (trans zero_lt_one a1) _
lemma one_div_pow_mono (a1 : 1 ≤ a) : monotone (λ n : ℕ, order_dual.to_dual 1 / a ^ n) :=
λ m n, one_div_pow_le_one_div_pow_of_le a1
lemma one_div_pow_strict_mono (a1 : 1 < a) : strict_mono (λ n : ℕ, order_dual.to_dual 1 / a ^ n) :=
λ m n, one_div_pow_lt_one_div_pow_of_lt a1
/-! ### Results about `is_lub` and `is_glb` -/
lemma is_lub.mul_left {s : set α} (ha : 0 ≤ a) (hs : is_lub s b) :
is_lub ((λ b, a * b) '' s) (a * b) :=
begin
rcases lt_or_eq_of_le ha with ha | rfl,
{ exact (order_iso.mul_left₀ _ ha).is_lub_image'.2 hs, },
{ simp_rw zero_mul,
rw hs.nonempty.image_const,
exact is_lub_singleton },
end
lemma is_lub.mul_right {s : set α} (ha : 0 ≤ a) (hs : is_lub s b) :
is_lub ((λ b, b * a) '' s) (b * a) :=
by simpa [mul_comm] using hs.mul_left ha
lemma is_glb.mul_left {s : set α} (ha : 0 ≤ a) (hs : is_glb s b) :
is_glb ((λ b, a * b) '' s) (a * b) :=
begin
rcases lt_or_eq_of_le ha with ha | rfl,
{ exact (order_iso.mul_left₀ _ ha).is_glb_image'.2 hs, },
{ simp_rw zero_mul,
rw hs.nonempty.image_const,
exact is_glb_singleton },
end
lemma is_glb.mul_right {s : set α} (ha : 0 ≤ a) (hs : is_glb s b) :
is_glb ((λ b, b * a) '' s) (b * a) :=
by simpa [mul_comm] using hs.mul_left ha
end linear_ordered_field
|
233730fd40ea45d87e0bbc42849c32122bed0c68 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /src/Lean/Compiler/IR/Checker.lean | bce386d275117ae8d6123ca24aa3a22f96d9fa1d | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,574 | 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.Compiler.IR.CompilerM
import Lean.Compiler.IR.Format
namespace Lean.IR.Checker
structure CheckerContext :=
(env : Environment)
(localCtx : LocalContext := {})
(decls : Array Decl)
structure CheckerState :=
(foundVars : IndexSet := {})
abbrev M := ReaderT CheckerContext (ExceptT String (StateT CheckerState Id))
def markIndex (i : Index) : M Unit := do
let s ← get
if s.foundVars.contains i then
throw s!"variable / joinpoint index {i} has already been used"
modify fun s => { s with foundVars := s.foundVars.insert i }
def markVar (x : VarId) : M Unit :=
markIndex x.idx
def markJP (j : JoinPointId) : M Unit :=
markIndex j.idx
def getDecl (c : Name) : M Decl := do
let ctx ← read
match findEnvDecl' ctx.env c ctx.decls with
| none => throw s!"unknown declaration '{c}'"
| some d => pure d
def checkVar (x : VarId) : M Unit := do
let ctx ← read
unless ctx.localCtx.isLocalVar x.idx || ctx.localCtx.isParam x.idx do
throw s!"unknown variable '{x}'"
def checkJP (j : JoinPointId) : M Unit := do
let ctx ← read
unless ctx.localCtx.isJP j.idx do
throw s!"unknown join point '{j}'"
def checkArg (a : Arg) : M Unit :=
match a with
| Arg.var x => checkVar x
| other => pure ()
def checkArgs (as : Array Arg) : M Unit :=
as.forM checkArg
@[inline] def checkEqTypes (ty₁ ty₂ : IRType) : M Unit := do
unless ty₁ == ty₂ do
throw "unexpected type"
@[inline] def checkType (ty : IRType) (p : IRType → Bool) : M Unit := do
unless p ty do
throw s!"unexpected type '{ty}'"
def checkObjType (ty : IRType) : M Unit := checkType ty IRType.isObj
def checkScalarType (ty : IRType) : M Unit := checkType ty IRType.isScalar
def getType (x : VarId) : M IRType := do
let ctx ← read
match ctx.localCtx.getType x with
| some ty => pure ty
| none => throw s!"unknown variable '{x}'"
@[inline] def checkVarType (x : VarId) (p : IRType → Bool) : M Unit := do
let ty ← getType x; checkType ty p
def checkObjVar (x : VarId) : M Unit :=
checkVarType x IRType.isObj
def checkScalarVar (x : VarId) : M Unit :=
checkVarType x IRType.isScalar
def checkFullApp (c : FunId) (ys : Array Arg) : M Unit := do
if c == `hugeFuel then
throw "the auxiliary constant `hugeFuel` cannot be used in code, it is used internally for compiling `partial` definitions"
let decl ← getDecl c
unless ys.size == decl.params.size do
throw s!"incorrect number of arguments to '{c}', {ys.size} provided, {decl.params.size} expected"
checkArgs ys
def checkPartialApp (c : FunId) (ys : Array Arg) : M Unit := do
let decl ← getDecl c
unless ys.size < decl.params.size do
throw s!"too many arguments too partial application '{c}', num. args: {ys.size}, arity: {decl.params.size}"
checkArgs ys
def checkExpr (ty : IRType) : Expr → M Unit
| Expr.pap f ys => checkPartialApp f ys *> checkObjType ty -- partial applications should always produce a closure object
| Expr.ap x ys => checkObjVar x *> checkArgs ys
| Expr.fap f ys => checkFullApp f ys
| Expr.ctor c ys => when (!ty.isStruct && !ty.isUnion && c.isRef) (checkObjType ty) *> checkArgs ys
| Expr.reset _ x => checkObjVar x *> checkObjType ty
| Expr.reuse x i u ys => checkObjVar x *> checkArgs ys *> checkObjType ty
| Expr.box xty x => checkObjType ty *> checkScalarVar x *> checkVarType x (fun t => t == xty)
| Expr.unbox x => checkScalarType ty *> checkObjVar x
| Expr.proj i x => do
let xType ← getType x;
match xType with
| IRType.object => checkObjType ty
| IRType.tobject => checkObjType ty
| IRType.struct _ tys => if h : i < tys.size then checkEqTypes (tys.get ⟨i,h⟩) ty else throw "invalid proj index"
| IRType.union _ tys => if h : i < tys.size then checkEqTypes (tys.get ⟨i,h⟩) ty else throw "invalid proj index"
| other => throw s!"unexpected IR type '{xType}'"
| Expr.uproj _ x => checkObjVar x *> checkType ty (fun t => t == IRType.usize)
| Expr.sproj _ _ x => checkObjVar x *> checkScalarType ty
| Expr.isShared x => checkObjVar x *> checkType ty (fun t => t == IRType.uint8)
| Expr.isTaggedPtr x => checkObjVar x *> checkType ty (fun t => t == IRType.uint8)
| Expr.lit (LitVal.str _) => checkObjType ty
| Expr.lit _ => pure ()
@[inline] def withParams (ps : Array Param) (k : M Unit) : M Unit := do
let ctx ← read
let localCtx ← ps.foldlM (init := ctx.localCtx) fun (ctx : LocalContext) p => do
markVar p.x
pure $ ctx.addParam p
withReader (fun _ => { ctx with localCtx := localCtx }) k
partial def checkFnBody : FnBody → M Unit
| FnBody.vdecl x t v b => do
checkExpr t v;
markVar x;
let ctx ← read
withReader (fun ctx => { ctx with localCtx := ctx.localCtx.addLocal x t v }) (checkFnBody b)
| FnBody.jdecl j ys v b => do
markJP j;
withParams ys (checkFnBody v);
let ctx ← read
withReader (fun ctx => { ctx with localCtx := ctx.localCtx.addJP j ys v }) (checkFnBody b)
| FnBody.set x _ y b => checkVar x *> checkArg y *> checkFnBody b
| FnBody.uset x _ y b => checkVar x *> checkVar y *> checkFnBody b
| FnBody.sset x _ _ y _ b => checkVar x *> checkVar y *> checkFnBody b
| FnBody.setTag x _ b => checkVar x *> checkFnBody b
| FnBody.inc x _ _ _ b => checkVar x *> checkFnBody b
| FnBody.dec x _ _ _ b => checkVar x *> checkFnBody b
| FnBody.del x b => checkVar x *> checkFnBody b
| FnBody.mdata _ b => checkFnBody b
| FnBody.jmp j ys => checkJP j *> checkArgs ys
| FnBody.ret x => checkArg x
| FnBody.case _ x _ alts => checkVar x *> alts.forM (fun alt => checkFnBody alt.body)
| FnBody.unreachable => pure ()
def checkDecl : Decl → M Unit
| Decl.fdecl f xs t b => withParams xs (checkFnBody b)
| Decl.extern f xs t _ => withParams xs (pure ())
end Checker
def checkDecl (decls : Array Decl) (decl : Decl) : CompilerM Unit := do
let env ← getEnv
match (Checker.checkDecl decl { env := env, decls := decls }).run' {} with
| Except.error msg => throw s!"IR check failed at '{decl.name}', error: {msg}"
| other => pure ()
def checkDecls (decls : Array Decl) : CompilerM Unit :=
decls.forM (checkDecl decls)
end IR
end Lean
|
7cb6fd5ae044019a1a103176012888b079314f38 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/pfunctor/multivariate/M.lean | 971657065e9c56d5418c495ddc208c4c37f0d0e1 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 11,517 | lean | /-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Mario Carneiro, Simon Hudon
-/
import data.pfunctor.univariate
import data.pfunctor.multivariate.basic
/-!
# The M construction as a multivariate polynomial functor.
M types are potentially infinite tree-like structures. They are defined
as the greatest fixpoint of a polynomial functor.
## Main definitions
* `M.mk` - constructor
* `M.dest` - destructor
* `M.corec` - corecursor: useful for formulating infinite, productive computations
* `M.bisim` - bisimulation: proof technique to show the equality of infinite objects
## Implementation notes
Dual view of M-types:
* `Mp`: polynomial functor
* `M`: greatest fixed point of a polynomial functor
Specifically, we define the polynomial functor `Mp` as:
* A := a possibly infinite tree-like structure without information in the nodes
* B := given the tree-like structure `t`, `B t` is a valid path
from the root of `t` to any given node.
As a result `Mp.obj α` is made of a dataless tree and a function from
its valid paths to values of `α`
The difference with the polynomial functor of an initial algebra is
that `A` is a possibly infinite tree.
## Reference
* [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019]
-/
universe u
open_locale mvfunctor
namespace mvpfunctor
open typevec
variables {n : ℕ} (P : mvpfunctor.{u} (n+1))
/-- A path from the root of a tree to one of its node -/
inductive M.path : P.last.M → fin2 n → Type u
| root (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : pfunctor.M.dest x = ⟨a, f⟩)
(i : fin2 n) (c : P.drop.B a i) :
M.path x i
| child (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : pfunctor.M.dest x = ⟨a, f⟩)
(j : P.last.B a) (i : fin2 n) (c : M.path (f j) i) :
M.path x i
instance M.path.inhabited (x : P.last.M) {i} [inhabited (P.drop.B x.head i)] :
inhabited (M.path P x i) :=
⟨ M.path.root _ (pfunctor.M.head x) (pfunctor.M.children x)
(pfunctor.M.cases_on' x $
by intros; simp [pfunctor.M.dest_mk]; ext; rw pfunctor.M.children_mk; refl) _
(default _) ⟩
/-- Polynomial functor of the M-type of `P`. `A` is a data-less
possibly infinite tree whereas, for a given `a : A`, `B a` is a valid
path in tree `a` so that `Wp.obj α` is made of a tree and a function
from its valid paths to the values it contains -/
def Mp : mvpfunctor n :=
{ A := P.last.M, B := M.path P }
/-- `n`-ary M-type for `P` -/
def M (α : typevec n) : Type* := P.Mp.obj α
instance mvfunctor_M : mvfunctor P.M := by delta M; apply_instance
instance inhabited_M {α : typevec _}
[I : inhabited P.A]
[Π (i : fin2 n), inhabited (α i)] :
inhabited (P.M α) :=
@obj.inhabited _ (Mp P) _ (@pfunctor.M.inhabited P.last I) _
/-- construct through corecursion the shape of an M-type
without its contents -/
def M.corec_shape {β : Type u}
(g₀ : β → P.A)
(g₂ : Π b : β, P.last.B (g₀ b) → β) :
β → P.last.M :=
pfunctor.M.corec (λ b, ⟨g₀ b, g₂ b⟩)
/-- Proof of type equality as an arrow -/
def cast_dropB {a a' : P.A} (h : a = a') : P.drop.B a ⟹ P.drop.B a' :=
λ i b, eq.rec_on h b
/-- Proof of type equality as a function -/
def cast_lastB {a a' : P.A} (h : a = a') : P.last.B a → P.last.B a' :=
λ b, eq.rec_on h b
/-- Using corecursion, construct the contents of an M-type -/
def M.corec_contents {α : typevec.{u} n} {β : Type u}
(g₀ : β → P.A)
(g₁ : Π b : β, P.drop.B (g₀ b) ⟹ α)
(g₂ : Π b : β, P.last.B (g₀ b) → β) :
Π x b, x = M.corec_shape P g₀ g₂ b → M.path P x ⟹ α
| ._ b h ._ (M.path.root x a f h' i c) :=
have a = g₀ b,
by { rw [h, M.corec_shape, pfunctor.M.dest_corec] at h', cases h', refl },
g₁ b i (P.cast_dropB this i c)
| ._ b h ._ (M.path.child x a f h' j i c) :=
have h₀ : a = g₀ b,
by { rw [h, M.corec_shape, pfunctor.M.dest_corec] at h', cases h', refl },
have h₁ : f j = M.corec_shape P g₀ g₂ (g₂ b (cast_lastB P h₀ j)),
by { rw [h, M.corec_shape, pfunctor.M.dest_corec] at h', cases h', refl },
M.corec_contents (f j) (g₂ b (P.cast_lastB h₀ j)) h₁ i c
/-- Corecursor for M-type of `P` -/
def M.corec' {α : typevec n} {β : Type u}
(g₀ : β → P.A)
(g₁ : Π b : β, P.drop.B (g₀ b) ⟹ α)
(g₂ : Π b : β, P.last.B (g₀ b) → β) :
β → P.M α :=
λ b, ⟨M.corec_shape P g₀ g₂ b, M.corec_contents P g₀ g₁ g₂ _ _ rfl⟩
/-- Corecursor for M-type of `P` -/
def M.corec {α : typevec n} {β : Type u} (g : β → P.obj (α.append1 β)) :
β → P.M α :=
M.corec' P
(λ b, (g b).fst)
(λ b, drop_fun (g b).snd)
(λ b, last_fun (g b).snd)
/-- Implementation of destructor for M-type of `P` -/
def M.path_dest_left {α : typevec n} {x : P.last.M}
{a : P.A} {f : P.last.B a → P.last.M} (h : pfunctor.M.dest x = ⟨a, f⟩)
(f' : M.path P x ⟹ α) :
P.drop.B a ⟹ α :=
λ i c, f' i (M.path.root x a f h i c)
/-- Implementation of destructor for M-type of `P` -/
def M.path_dest_right {α : typevec n} {x : P.last.M}
{a : P.A} {f : P.last.B a → P.last.M} (h : pfunctor.M.dest x = ⟨a, f⟩)
(f' : M.path P x ⟹ α) :
Π j : P.last.B a, M.path P (f j) ⟹ α :=
λ j i c, f' i (M.path.child x a f h j i c)
/-- Destructor for M-type of `P` -/
def M.dest' {α : typevec n} {x : P.last.M}
{a : P.A} {f : P.last.B a → P.last.M} (h : pfunctor.M.dest x = ⟨a, f⟩)
(f' : M.path P x ⟹ α) :
P.obj (α.append1 (P.M α)) :=
⟨a, split_fun (M.path_dest_left P h f') (λ x, ⟨f x, M.path_dest_right P h f' x⟩)⟩
/-- Destructor for M-types -/
def M.dest {α : typevec n} (x : P.M α) : P.obj (α ::: P.M α) :=
M.dest' P (sigma.eta $ pfunctor.M.dest x.fst).symm x.snd
/-- Constructor for M-types -/
def M.mk {α : typevec n} : P.obj (α.append1 (P.M α)) → P.M α :=
M.corec _ (λ i, append_fun id (M.dest P) <$$> i)
theorem M.dest'_eq_dest' {α : typevec n} {x : P.last.M}
{a₁ : P.A} {f₁ : P.last.B a₁ → P.last.M} (h₁ : pfunctor.M.dest x = ⟨a₁, f₁⟩)
{a₂ : P.A} {f₂ : P.last.B a₂ → P.last.M} (h₂ : pfunctor.M.dest x = ⟨a₂, f₂⟩)
(f' : M.path P x ⟹ α) : M.dest' P h₁ f' = M.dest' P h₂ f' :=
by cases h₁.symm.trans h₂; refl
theorem M.dest_eq_dest' {α : typevec n} {x : P.last.M}
{a : P.A} {f : P.last.B a → P.last.M} (h : pfunctor.M.dest x = ⟨a, f⟩)
(f' : M.path P x ⟹ α) : M.dest P ⟨x, f'⟩ = M.dest' P h f' :=
M.dest'_eq_dest' _ _ _ _
theorem M.dest_corec' {α : typevec.{u} n} {β : Type u}
(g₀ : β → P.A)
(g₁ : Π b : β, P.drop.B (g₀ b) ⟹ α)
(g₂ : Π b : β, P.last.B (g₀ b) → β)
(x : β) :
M.dest P (M.corec' P g₀ g₁ g₂ x) =
⟨g₀ x, split_fun (g₁ x) (M.corec' P g₀ g₁ g₂ ∘ (g₂ x))⟩ :=
rfl
theorem M.dest_corec {α : typevec n} {β : Type u} (g : β → P.obj (α.append1 β)) (x : β) :
M.dest P (M.corec P g x) = append_fun id (M.corec P g) <$$> g x :=
begin
transitivity, apply M.dest_corec',
cases g x with a f, dsimp,
rw mvpfunctor.map_eq, congr,
conv { to_rhs, rw [←split_drop_fun_last_fun f, append_fun_comp_split_fun] },
refl
end
lemma M.bisim_lemma {α : typevec n}
{a₁ : (Mp P).A} {f₁ : (Mp P).B a₁ ⟹ α}
{a' : P.A} {f' : (P.B a').drop ⟹ α} {f₁' : (P.B a').last → M P α}
(e₁ : M.dest P ⟨a₁, f₁⟩ = ⟨a', split_fun f' f₁'⟩) :
∃ g₁' (e₁' : pfunctor.M.dest a₁ = ⟨a', g₁'⟩),
f' = M.path_dest_left P e₁' f₁ ∧
f₁' = λ (x : (last P).B a'),
⟨g₁' x, M.path_dest_right P e₁' f₁ x⟩ :=
begin
generalize_hyp ef : @split_fun n _ (append1 α (M P α)) f' f₁' = ff at e₁,
cases e₁' : pfunctor.M.dest a₁ with a₁' g₁',
rw M.dest_eq_dest' _ e₁' at e₁,
cases e₁, exact ⟨_, e₁', split_fun_inj ef⟩,
end
theorem M.bisim {α : typevec n} (R : P.M α → P.M α → Prop)
(h : ∀ x y, R x y → ∃ a f f₁ f₂,
M.dest P x = ⟨a, split_fun f f₁⟩ ∧
M.dest P y = ⟨a, split_fun f f₂⟩ ∧
∀ i, R (f₁ i) (f₂ i))
(x y) (r : R x y) : x = y :=
begin
cases x with a₁ f₁,
cases y with a₂ f₂,
dsimp [Mp] at *,
have : a₁ = a₂, {
refine pfunctor.M.bisim
(λ a₁ a₂, ∃ x y, R x y ∧ x.1 = a₁ ∧ y.1 = a₂) _ _ _
⟨⟨a₁, f₁⟩, ⟨a₂, f₂⟩, r, rfl, rfl⟩,
rintro _ _ ⟨⟨a₁, f₁⟩, ⟨a₂, f₂⟩, r, rfl, rfl⟩,
rcases h _ _ r with ⟨a', f', f₁', f₂', e₁, e₂, h'⟩,
rcases M.bisim_lemma P e₁ with ⟨g₁', e₁', rfl, rfl⟩,
rcases M.bisim_lemma P e₂ with ⟨g₂', e₂', _, rfl⟩,
rw [e₁', e₂'],
exact ⟨_, _, _, rfl, rfl, λ b, ⟨_, _, h' b, rfl, rfl⟩⟩ },
subst this, congr' with i p,
induction p with x a f h' i c x a f h' i c p IH generalizing f₁ f₂;
try {
rcases h _ _ r with ⟨a', f', f₁', f₂', e₁, e₂, h''⟩,
rcases M.bisim_lemma P e₁ with ⟨g₁', e₁', rfl, rfl⟩,
rcases M.bisim_lemma P e₂ with ⟨g₂', e₂', e₃, rfl⟩,
cases h'.symm.trans e₁',
cases h'.symm.trans e₂' },
{ exact (congr_fun (congr_fun e₃ i) c : _) },
{ exact IH _ _ (h'' _) }
end
theorem M.bisim₀ {α : typevec n} (R : P.M α → P.M α → Prop)
(h₀ : equivalence R)
(h : ∀ x y, R x y →
(id ::: quot.mk R) <$$> M.dest _ x = (id ::: quot.mk R) <$$> M.dest _ y)
(x y) (r : R x y) : x = y :=
begin
apply M.bisim P R _ _ _ r, clear r x y,
introv Hr, specialize h _ _ Hr, clear Hr,
rcases M.dest P x with ⟨ax,fx⟩, rcases M.dest P y with ⟨ay,fy⟩,
intro h, rw [map_eq,map_eq] at h, injection h with h₀ h₁, subst ay,
simp at h₁, clear h,
have Hdrop : drop_fun fx = drop_fun fy,
{ replace h₁ := congr_arg drop_fun h₁,
simpa using h₁, },
existsi [ax,drop_fun fx,last_fun fx,last_fun fy],
rw [split_drop_fun_last_fun,Hdrop,split_drop_fun_last_fun],
simp, intro i,
replace h₁ := congr_fun (congr_fun h₁ fin2.fz) i,
simp [(⊚),append_fun,split_fun] at h₁,
replace h₁ := quot.exact _ h₁,
rw relation.eqv_gen_iff_of_equivalence at h₁,
exact h₁, exact h₀
end
theorem M.bisim' {α : typevec n} (R : P.M α → P.M α → Prop)
(h : ∀ x y, R x y →
(id ::: quot.mk R) <$$> M.dest _ x = (id ::: quot.mk R) <$$> M.dest _ y)
(x y) (r : R x y) : x = y :=
begin
have := M.bisim₀ P (eqv_gen R) _ _,
{ solve_by_elim [eqv_gen.rel] },
{ apply eqv_gen.is_equivalence },
{ clear r x y, introv Hr,
have : ∀ x y, R x y → eqv_gen R x y := @eqv_gen.rel _ R,
induction Hr,
{ rw ← quot.factor_mk_eq R (eqv_gen R) this,
rwa [append_fun_comp_id,← mvfunctor.map_map,← mvfunctor.map_map,h] },
all_goals { cc } }
end
theorem M.dest_map {α β : typevec n} (g : α ⟹ β) (x : P.M α) :
M.dest P (g <$$> x) = append_fun g (λ x, g <$$> x) <$$> M.dest P x :=
begin
cases x with a f,
rw map_eq,
conv { to_rhs, rw [M.dest, M.dest', map_eq, append_fun_comp_split_fun] },
reflexivity
end
theorem M.map_dest {α β : typevec n} (g : α ::: P.M α ⟹ β ::: P.M β) (x : P.M α)
(h : ∀ x : P.M α, last_fun g x = (drop_fun g <$$> x : P.M β) ):
g <$$> M.dest P x = M.dest P (drop_fun g <$$> x) :=
begin
rw M.dest_map, congr,
apply eq_of_drop_last_eq; simp,
ext1, apply h
end
end mvpfunctor
|
d705a03e75d0ca959d4ca8579a6912ca1389c560 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/polynomial/ring_division.lean | ebe34e911d82a0afb3173440ba326864cc8cea6a | [
"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 | 41,536 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin
-/
import algebra.char_zero.infinite
import data.polynomial.algebra_map
import data.polynomial.degree.lemmas
import data.polynomial.div
import ring_theory.localization.fraction_ring
import algebra.polynomial.big_operators
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $ R[X] $
## Main definitions
* `polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `polynomial.root_set p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `polynomial.C_leading_coeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
noncomputable theory
open_locale classical polynomial
open finset
namespace polynomial
universes u v w z
variables {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section comm_ring
variables [comm_ring R] {p q : R[X]}
section
variables [semiring S]
lemma nat_degree_pos_of_aeval_root [algebra R S] {p : R[X]} (hp : p ≠ 0)
{z : S} (hz : aeval z p = 0) (inj : ∀ (x : R), algebra_map R S x = 0 → x = 0) :
0 < p.nat_degree :=
nat_degree_pos_of_eval₂_root hp (algebra_map R S) hz inj
lemma degree_pos_of_aeval_root [algebra R S] {p : R[X]} (hp : p ≠ 0)
{z : S} (hz : aeval z p = 0) (inj : ∀ (x : R), algebra_map R S x = 0 → x = 0) :
0 < p.degree :=
nat_degree_pos_iff_degree_pos.mp (nat_degree_pos_of_aeval_root hp hz inj)
lemma mod_by_monic_eq_of_dvd_sub (hq : q.monic) {p₁ p₂ : R[X]}
(h : q ∣ (p₁ - p₂)) :
p₁ %ₘ q = p₂ %ₘ q :=
begin
nontriviality R,
obtain ⟨f, sub_eq⟩ := h,
refine (div_mod_by_monic_unique (p₂ /ₘ q + f) _ hq
⟨_, degree_mod_by_monic_lt _ hq⟩).2,
rw [sub_eq_iff_eq_add.mp sub_eq, mul_add, ← add_assoc, mod_by_monic_add_div _ hq, add_comm]
end
lemma add_mod_by_monic (p₁ p₂ : R[X]) : (p₁ + p₂) %ₘ q = p₁ %ₘ q + p₂ %ₘ q :=
begin
by_cases hq : q.monic,
{ nontriviality R,
exact (div_mod_by_monic_unique (p₁ /ₘ q + p₂ /ₘ q) _ hq
⟨by rw [mul_add, add_left_comm, add_assoc, mod_by_monic_add_div _ hq, ← add_assoc,
add_comm (q * _), mod_by_monic_add_div _ hq],
(degree_add_le _ _).trans_lt (max_lt (degree_mod_by_monic_lt _ hq)
(degree_mod_by_monic_lt _ hq))⟩).2 },
{ simp_rw mod_by_monic_eq_of_not_monic _ hq }
end
lemma smul_mod_by_monic (c : R) (p : R[X]) : (c • p) %ₘ q = c • (p %ₘ q) :=
begin
by_cases hq : q.monic,
{ nontriviality R,
exact (div_mod_by_monic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq
⟨by rw [mul_smul_comm, ← smul_add, mod_by_monic_add_div p hq],
(degree_smul_le _ _).trans_lt (degree_mod_by_monic_lt _ hq)⟩).2 },
{ simp_rw mod_by_monic_eq_of_not_monic _ hq }
end
/-- `_ %ₘ q` as an `R`-linear map. -/
@[simps]
def mod_by_monic_hom (q : R[X]) : R[X] →ₗ[R] R[X] :=
{ to_fun := λ p, p %ₘ q,
map_add' := add_mod_by_monic,
map_smul' := smul_mod_by_monic }
end
section
variables [ring S]
lemma aeval_mod_by_monic_eq_self_of_root [algebra R S]
{p q : R[X]} (hq : q.monic) {x : S} (hx : aeval x q = 0) :
aeval x (p %ₘ q) = aeval x p :=
-- `eval₂_mod_by_monic_eq_self_of_root` doesn't work here as it needs commutativity
by rw [mod_by_monic_eq_sub_mul_div p hq, _root_.map_sub, _root_.map_mul, hx, zero_mul, sub_zero]
end
end comm_ring
section no_zero_divisors
variables [semiring R] [no_zero_divisors R] {p q : R[X]}
instance : no_zero_divisors R[X] :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, begin
rw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero],
refine eq_zero_or_eq_zero_of_mul_eq_zero _,
rw [← leading_coeff_zero, ← leading_coeff_mul, h],
end }
lemma nat_degree_mul (hp : p ≠ 0) (hq : q ≠ 0) : nat_degree (p * q) =
nat_degree p + nat_degree q :=
by rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree (mul_ne_zero hp hq),
with_bot.coe_add, ← degree_eq_nat_degree hp,
← degree_eq_nat_degree hq, degree_mul]
lemma trailing_degree_mul : (p * q).trailing_degree = p.trailing_degree + q.trailing_degree :=
begin
by_cases hp : p = 0,
{ rw [hp, zero_mul, trailing_degree_zero, top_add] },
by_cases hq : q = 0,
{ rw [hq, mul_zero, trailing_degree_zero, add_top] },
rw [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq,
trailing_degree_eq_nat_trailing_degree (mul_ne_zero hp hq),
nat_trailing_degree_mul hp hq, with_top.coe_add],
end
@[simp] lemma nat_degree_pow (p : R[X]) (n : ℕ) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0
then if hn0 : n = 0 then by simp [hp0, hn0]
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else nat_degree_pow'
(by rw [← leading_coeff_pow, ne.def, leading_coeff_eq_zero]; exact pow_ne_zero _ hp0)
lemma degree_le_mul_left (p : R[X]) (hq : q ≠ 0) : degree p ≤ degree (p * q) :=
if hp : p = 0 then by simp only [hp, zero_mul, le_refl]
else by rw [degree_mul, degree_eq_nat_degree hp,
degree_eq_nat_degree hq];
exact with_bot.coe_le_coe.2 (nat.le_add_right _ _)
theorem nat_degree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) :
p.nat_degree ≤ q.nat_degree :=
begin
rcases h1 with ⟨q, rfl⟩, rw mul_ne_zero_iff at h2,
rw [nat_degree_mul h2.1 h2.2], exact nat.le_add_right _ _
end
lemma degree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q :=
begin
rcases h1 with ⟨q, rfl⟩, rw mul_ne_zero_iff at h2,
exact degree_le_mul_left p h2.2,
end
/-- This lemma is useful for working with the `int_degree` of a rational function. -/
lemma nat_degree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0)
(hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) :
(p₁.nat_degree : ℤ) - q₁.nat_degree = (p₂.nat_degree : ℤ) - q₂.nat_degree :=
begin
rw sub_eq_sub_iff_add_eq_add,
norm_cast,
rw [← nat_degree_mul hp₁ hq₂, ← nat_degree_mul hp₂ hq₁, h_eq]
end
lemma nat_degree_eq_zero_of_is_unit (h : is_unit p) : nat_degree p = 0 :=
begin
nontriviality R,
obtain ⟨q, hq⟩ := h.exists_right_inv,
have := nat_degree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq),
rw [hq, nat_degree_one, eq_comm, add_eq_zero_iff] at this,
exact this.1,
end
lemma degree_eq_zero_of_is_unit [nontrivial R] (h : is_unit p) : degree p = 0 :=
le_antisymm (nat_degree_eq_zero_iff_degree_le_zero.mp (nat_degree_eq_zero_of_is_unit h))
(zero_le_degree_iff.mpr h.ne_zero)
theorem is_unit_iff : is_unit p ↔ ∃ r : R, is_unit r ∧ C r = p :=
⟨λ hp, ⟨p.coeff 0, let h := eq_C_of_nat_degree_eq_zero (nat_degree_eq_zero_of_is_unit hp) in
⟨is_unit_C.1 (h ▸ hp), h.symm⟩⟩, λ ⟨r, hr, hrp⟩, hrp ▸ is_unit_C.2 hr⟩
variables [char_zero R]
@[simp] lemma degree_bit0_eq (p : R[X]) : degree (bit0 p) = degree p :=
by rw [bit0_eq_two_mul, degree_mul, (by simp : (2 : R[X]) = C 2),
@polynomial.degree_C R _ _ two_ne_zero, zero_add]
@[simp] lemma nat_degree_bit0_eq (p : R[X]) : nat_degree (bit0 p) = nat_degree p :=
nat_degree_eq_of_degree_eq $ degree_bit0_eq p
@[simp]
lemma nat_degree_bit1_eq (p : R[X]) : nat_degree (bit1 p) = nat_degree p :=
begin
rw bit1,
apply le_antisymm,
convert nat_degree_add_le _ _,
{ simp, },
by_cases h : p.nat_degree = 0,
{ simp [h], },
apply le_nat_degree_of_ne_zero,
intro hh,
apply h,
simp [*, coeff_one, if_neg (ne.symm h)] at *,
end
lemma degree_bit1_eq {p : R[X]} (hp : 0 < degree p) : degree (bit1 p) = degree p :=
begin
rw [bit1, degree_add_eq_left_of_degree_lt, degree_bit0_eq],
rwa [degree_one, degree_bit0_eq]
end
end no_zero_divisors
section no_zero_divisors
variables [comm_semiring R] [no_zero_divisors R] {p q : R[X]}
lemma irreducible_of_monic (hp : p.monic) (hp1 : p ≠ 1) :
irreducible p ↔ ∀ f g : R[X], f.monic → g.monic → f * g = p → f = 1 ∨ g = 1 :=
begin
refine ⟨λ h f g hf hg hp, (h.2 f g hp.symm).elim (or.inl ∘ hf.eq_one_of_is_unit)
(or.inr ∘ hg.eq_one_of_is_unit), λ h, ⟨hp1 ∘ hp.eq_one_of_is_unit, λ f g hfg,
(h (g * C f.leading_coeff) (f * C g.leading_coeff) _ _ _).elim
(or.inr ∘ is_unit_of_mul_eq_one g _) (or.inl ∘ is_unit_of_mul_eq_one f _)⟩⟩,
{ rwa [monic, leading_coeff_mul, leading_coeff_C, ←leading_coeff_mul, mul_comm, ←hfg, ←monic] },
{ rwa [monic, leading_coeff_mul, leading_coeff_C, ←leading_coeff_mul, ←hfg, ←monic] },
{ rw [mul_mul_mul_comm, ←C_mul, ←leading_coeff_mul, ←hfg, hp.leading_coeff, C_1, mul_one,
mul_comm, ←hfg] },
end
lemma root_mul : is_root (p * q) a ↔ is_root p a ∨ is_root q a :=
by simp_rw [is_root, eval_mul, mul_eq_zero]
lemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a :=
root_mul.1 h
end no_zero_divisors
section ring
variables [ring R] [is_domain R] {p q : R[X]}
instance : is_domain R[X] :=
{ ..polynomial.no_zero_divisors,
..polynomial.nontrivial, }
end ring
section comm_ring
variable [comm_ring R]
/-- The multiplicity of `a` as root of a nonzero polynomial `p` is at least `n` iff
`(X - a) ^ n` divides `p`. -/
lemma le_root_multiplicity_iff {p : R[X]} (p0 : p ≠ 0) {a : R} {n : ℕ} :
n ≤ root_multiplicity a p ↔ (X - C a) ^ n ∣ p :=
begin
simp_rw [root_multiplicity, dif_neg p0, nat.le_find_iff, not_not],
refine ⟨λ h, _, λ h m hm, (pow_dvd_pow _ hm).trans h⟩,
cases n, { rw pow_zero, apply one_dvd }, { exact h n n.lt_succ_self },
end
lemma root_multiplicity_le_iff {p : R[X]} (p0 : p ≠ 0) (a : R) (n : ℕ) :
root_multiplicity a p ≤ n ↔ ¬ (X - C a) ^ (n + 1) ∣ p :=
by rw [← (le_root_multiplicity_iff p0).not, not_le, nat.lt_add_one_iff]
lemma pow_root_multiplicity_not_dvd {p : R[X]} (p0 : p ≠ 0) (a : R) :
¬ (X - C a) ^ (root_multiplicity a p + 1) ∣ p :=
by rw [← root_multiplicity_le_iff p0]
/-- The multiplicity of `p + q` is at least the minimum of the multiplicities. -/
lemma root_multiplicity_add {p q : R[X]} (a : R) (hzero : p + q ≠ 0) :
min (root_multiplicity a p) (root_multiplicity a q) ≤ root_multiplicity a (p + q) :=
begin
rw le_root_multiplicity_iff hzero,
have hdivp : (X - C a) ^ root_multiplicity a p ∣ p := pow_root_multiplicity_dvd p a,
have hdivq : (X - C a) ^ root_multiplicity a q ∣ q := pow_root_multiplicity_dvd q a,
exact min_pow_dvd_add hdivp hdivq
end
variables [is_domain R] {p q : R[X]}
section roots
open multiset
@[simp] lemma degree_coe_units (u : R[X]ˣ) :
degree (u : R[X]) = 0 :=
degree_eq_zero_of_is_unit ⟨u, rfl⟩
theorem prime_X_sub_C (r : R) : prime (X - C r) :=
⟨X_sub_C_ne_zero r, not_is_unit_X_sub_C r,
λ _ _, by { simp_rw [dvd_iff_is_root, is_root.def, eval_mul, mul_eq_zero], exact id }⟩
theorem prime_X : prime (X : R[X]) :=
by { convert (prime_X_sub_C (0 : R)), simp }
lemma monic.prime_of_degree_eq_one (hp1 : degree p = 1) (hm : monic p) :
prime p :=
have p = X - C (- p.coeff 0),
by simpa [hm.leading_coeff] using eq_X_add_C_of_degree_eq_one hp1,
this.symm ▸ prime_X_sub_C _
theorem irreducible_X_sub_C (r : R) : irreducible (X - C r) :=
(prime_X_sub_C r).irreducible
theorem irreducible_X : irreducible (X : R[X]) :=
prime.irreducible prime_X
lemma monic.irreducible_of_degree_eq_one (hp1 : degree p = 1) (hm : monic p) :
irreducible p :=
(hm.prime_of_degree_eq_one hp1).irreducible
theorem eq_of_monic_of_associated (hp : p.monic) (hq : q.monic) (hpq : associated p q) : p = q :=
begin
obtain ⟨u, hu⟩ := hpq,
unfold monic at hp hq,
rw eq_C_of_degree_le_zero (le_of_eq $ degree_coe_units _) at hu,
rw [← hu, leading_coeff_mul, hp, one_mul, leading_coeff_C] at hq,
rwa [hq, C_1, mul_one] at hu,
apply_instance,
end
lemma root_multiplicity_mul {p q : R[X]} {x : R} (hpq : p * q ≠ 0) :
root_multiplicity x (p * q) = root_multiplicity x p + root_multiplicity x q :=
begin
have hp : p ≠ 0 := left_ne_zero_of_mul hpq,
have hq : q ≠ 0 := right_ne_zero_of_mul hpq,
rw [root_multiplicity_eq_multiplicity (p * q), dif_neg hpq,
root_multiplicity_eq_multiplicity p, dif_neg hp,
root_multiplicity_eq_multiplicity q, dif_neg hq,
multiplicity.mul' (prime_X_sub_C x)],
end
lemma root_multiplicity_X_sub_C_self {x : R} :
root_multiplicity x (X - C x) = 1 :=
by rw [root_multiplicity_eq_multiplicity, dif_neg (X_sub_C_ne_zero x),
multiplicity.get_multiplicity_self]
lemma root_multiplicity_X_sub_C {x y : R} :
root_multiplicity x (X - C y) = if x = y then 1 else 0 :=
begin
split_ifs with hxy,
{ rw hxy,
exact root_multiplicity_X_sub_C_self },
exact root_multiplicity_eq_zero (mt root_X_sub_C.mp (ne.symm hxy))
end
/-- The multiplicity of `a` as root of `(X - a) ^ n` is `n`. -/
lemma root_multiplicity_X_sub_C_pow (a : R) (n : ℕ) : root_multiplicity a ((X - C a) ^ n) = n :=
begin
induction n with n hn,
{ refine root_multiplicity_eq_zero _,
simp only [eval_one, is_root.def, not_false_iff, one_ne_zero, pow_zero] },
have hzero := pow_ne_zero n.succ (X_sub_C_ne_zero a),
rw pow_succ (X - C a) n at hzero ⊢,
simp only [root_multiplicity_mul hzero, root_multiplicity_X_sub_C_self, hn, nat.one_add]
end
lemma exists_multiset_roots : ∀ {p : R[X]} (hp : p ≠ 0),
∃ s : multiset R, (s.card : with_bot ℕ) ≤ degree p ∧ ∀ a, s.count a = root_multiplicity a p
| p := λ hp, by haveI := classical.prop_decidable (∃ x, is_root p x); exact
if h : ∃ x, is_root p x
then
let ⟨x, hx⟩ := h in
have hpd : 0 < degree p := degree_pos_of_root hp hx,
have hd0 : p /ₘ (X - C x) ≠ 0 :=
λ h, by rw [← mul_div_by_monic_eq_iff_is_root.2 hx, h, mul_zero] at hp; exact hp rfl,
have wf : degree (p /ₘ _) < degree p :=
degree_div_by_monic_lt _ (monic_X_sub_C x) hp
((degree_X_sub_C x).symm ▸ dec_trivial),
let ⟨t, htd, htr⟩ := @exists_multiset_roots (p /ₘ (X - C x)) hd0 in
have hdeg : degree (X - C x) ≤ degree p := begin
rw [degree_X_sub_C, degree_eq_nat_degree hp],
rw degree_eq_nat_degree hp at hpd,
exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd)
end,
have hdiv0 : p /ₘ (X - C x) ≠ 0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x)).1 $
not_lt.2 hdeg,
⟨x ::ₘ t, calc (card (x ::ₘ t) : with_bot ℕ) = t.card + 1 :
by exact_mod_cast card_cons _ _
... ≤ degree p :
by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg,
degree_X_sub_C, add_comm];
exact add_le_add (le_refl (1 : with_bot ℕ)) htd,
begin
assume a,
conv_rhs { rw ← mul_div_by_monic_eq_iff_is_root.mpr hx },
rw [root_multiplicity_mul (mul_ne_zero (X_sub_C_ne_zero x) hdiv0),
root_multiplicity_X_sub_C, ← htr a],
split_ifs with ha,
{ rw [ha, count_cons_self, nat.succ_eq_add_one, add_comm] },
{ rw [count_cons_of_ne ha, zero_add] },
end⟩
else
⟨0, (degree_eq_nat_degree hp).symm ▸ with_bot.coe_le_coe.2 (nat.zero_le _),
by { intro a, rw [count_zero, root_multiplicity_eq_zero (not_exists.mp h a)] }⟩
using_well_founded {dec_tac := tactic.assumption}
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : multiset R :=
if h : p = 0 then ∅ else classical.some (exists_multiset_roots h)
@[simp] lemma roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
lemma card_roots (hp0 : p ≠ 0) : ((roots p).card : with_bot ℕ) ≤ degree p :=
begin
unfold roots,
rw dif_neg hp0,
exact (classical.some_spec (exists_multiset_roots hp0)).1
end
lemma card_roots' (p : R[X]) : p.roots.card ≤ nat_degree p :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
exact with_bot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq $ degree_eq_nat_degree hp0))
end
lemma card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
((p - C a).roots.card : with_bot ℕ) ≤ degree p :=
calc ((p - C a).roots.card : with_bot ℕ) ≤ degree (p - C a) :
card_roots $ mt sub_eq_zero.1 $ λ h, not_le_of_gt hp0 $ h.symm ▸ degree_C_le
... = degree p : by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
lemma card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(p - C a).roots.card ≤ nat_degree p :=
with_bot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq $ degree_eq_nat_degree
(λ h, by simp [*, lt_irrefl] at *)))
@[simp] lemma count_roots (p : R[X]) : p.roots.count a = root_multiplicity a p :=
begin
by_cases hp : p = 0,
{ simp [hp], },
rw [roots, dif_neg hp],
exact (classical.some_spec (exists_multiset_roots hp)).2 a
end
@[simp] lemma mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ is_root p a :=
by rw [← count_pos, count_roots p, root_multiplicity_pos hp]
lemma ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
λ hp, by rwa [hp, roots_zero] at h
lemma is_root_of_mem_roots (h : a ∈ p.roots) : is_root p a :=
(mem_roots $ ne_zero_of_mem_roots h).mp h
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : finset R} (h : Z.val ⊆ p.roots) :
Z.card ≤ p.nat_degree :=
(multiset.card_le_of_le (finset.val_le_iff_val_subset.2 h)).trans (polynomial.card_roots' p)
lemma finite_set_of_is_root {p : R[X]} (hp : p ≠ 0) : set.finite {x | is_root p x} :=
by simpa only [← finset.set_of_mem, mem_to_finset, mem_roots hp]
using p.roots.to_finset.finite_to_set
lemma eq_zero_of_infinite_is_root (p : R[X]) (h : set.infinite {x | is_root p x}) : p = 0 :=
not_imp_comm.mp finite_set_of_is_root h
lemma exists_max_root [linear_order R] (p : R[X]) (hp : p ≠ 0) :
∃ x₀, ∀ x, p.is_root x → x ≤ x₀ :=
set.exists_upper_bound_image _ _ $ finite_set_of_is_root hp
lemma exists_min_root [linear_order R] (p : R[X]) (hp : p ≠ 0) :
∃ x₀, ∀ x, p.is_root x → x₀ ≤ x :=
set.exists_lower_bound_image _ _ $ finite_set_of_is_root hp
lemma eq_of_infinite_eval_eq (p q : R[X]) (h : set.infinite {x | eval x p = eval x q}) : p = q :=
begin
rw [← sub_eq_zero],
apply eq_zero_of_infinite_is_root,
simpa only [is_root, eval_sub, sub_eq_zero]
end
lemma roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots :=
multiset.ext.mpr $ λ r,
by rw [count_add, count_roots, count_roots,
count_roots, root_multiplicity_mul hpq]
lemma roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q :=
begin
rintro ⟨k, rfl⟩,
exact multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
end
@[simp] lemma mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
(mem_roots (show p - C a ≠ 0, from mt sub_eq_zero.1 $ λ h,
not_le_of_gt hp0 $ h.symm ▸ degree_C_le)).trans
(by rw [is_root.def, eval_sub, eval_C, sub_eq_zero])
@[simp] lemma roots_X_sub_C (r : R) : roots (X - C r) = {r} :=
begin
ext s,
rw [count_roots, root_multiplicity_X_sub_C, count_singleton],
end
@[simp] lemma roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp] lemma roots_C (x : R) : (C x).roots = 0 :=
if H : x = 0 then by rw [H, C_0, roots_zero] else multiset.ext.mpr $ λ r,
by rw [count_roots, count_zero, root_multiplicity_eq_zero (not_is_root_C _ _ H)]
@[simp] lemma roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp] lemma roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots :=
by by_cases hp : p = 0; simp only [roots_mul, *, ne.def, mul_eq_zero, C_eq_zero, or_self,
not_false_iff, roots_C, zero_add, mul_zero]
@[simp] lemma roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots :=
by rw [smul_eq_C_mul, roots_C_mul _ ha]
lemma roots_list_prod (L : list R[X]) :
((0 : R[X]) ∉ L) → L.prod.roots = (L : multiset R[X]).bind roots :=
list.rec_on L (λ _, roots_one) $ λ hd tl ih H,
begin
rw [list.mem_cons_iff, not_or_distrib] at H,
rw [list.prod_cons, roots_mul (mul_ne_zero (ne.symm H.1) $ list.prod_ne_zero H.2),
← multiset.cons_coe, multiset.cons_bind, ih H.2]
end
lemma roots_multiset_prod (m : multiset R[X]) :
(0 : R[X]) ∉ m → m.prod.roots = m.bind roots :=
by { rcases m with ⟨L⟩, simpa only [multiset.coe_prod, quot_mk_to_coe''] using roots_list_prod L }
lemma roots_prod {ι : Type*} (f : ι → R[X]) (s : finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind (λ i, roots (f i)) :=
begin
rcases s with ⟨m, hm⟩,
simpa [multiset.prod_eq_zero_iff, bind_map] using roots_multiset_prod (m.map f)
end
@[simp] lemma roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots :=
begin
induction n with n ihn,
{ rw [pow_zero, roots_one, zero_smul, empty_eq_zero] },
{ rcases eq_or_ne p 0 with rfl | hp,
{ rw [zero_pow n.succ_pos, roots_zero, smul_zero] },
{ rw [pow_succ', roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, nat.succ_eq_add_one,
add_smul, one_smul] } }
end
lemma roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • {0} := by rw [roots_pow, roots_X]
lemma roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) : (C a * X ^ n).roots = n • {0} :=
by rw [roots_C_mul _ ha, roots_X_pow]
@[simp] lemma roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • {0} :=
by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
lemma roots_prod_X_sub_C (s : finset R) :
(s.prod (λ a, X - C a)).roots = s.val :=
(roots_prod (λ a, X - C a) s (prod_ne_zero_iff.mpr (λ a _, X_sub_C_ne_zero a))).trans
(by simp_rw [roots_X_sub_C, multiset.bind_singleton, multiset.map_id'])
@[simp] lemma roots_multiset_prod_X_sub_C (s : multiset R) :
(s.map (λ a, X - C a)).prod.roots = s :=
begin
rw [roots_multiset_prod, multiset.bind_map],
{ simp_rw [roots_X_sub_C, multiset.bind_singleton, multiset.map_id'] },
{ rw [multiset.mem_map], rintro ⟨a, -, h⟩, exact X_sub_C_ne_zero a h },
end
@[simp] lemma nat_degree_multiset_prod_X_sub_C_eq_card (s : multiset R):
(s.map (λ a, X - C a)).prod.nat_degree = s.card :=
begin
rw [nat_degree_multiset_prod_of_monic, multiset.map_map],
{ convert multiset.sum_repeat 1 _,
{ convert multiset.map_const _ 1, ext, apply nat_degree_X_sub_C }, { simp } },
{ intros f hf, obtain ⟨a, ha, rfl⟩ := multiset.mem_map.1 hf, exact monic_X_sub_C a },
end
lemma card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
(roots ((X : R[X]) ^ n - C a)).card ≤ n :=
with_bot.coe_le_coe.1 $
calc ((roots ((X : R[X]) ^ n - C a)).card : with_bot ℕ)
≤ degree ((X : R[X]) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a)
... = n : degree_X_pow_sub_C hn a
section nth_roots
/-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/
def nth_roots (n : ℕ) (a : R) : multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp] lemma mem_nth_roots {n : ℕ} (hn : 0 < n) {a x : R} :
x ∈ nth_roots n a ↔ x ^ n = a :=
by rw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a),
is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero]
@[simp] lemma nth_roots_zero (r : R) : nth_roots 0 r = 0 :=
by simp only [empty_eq_zero, pow_zero, nth_roots, ← C_1, ← C_sub, roots_C]
lemma card_nth_roots (n : ℕ) (a : R) :
(nth_roots n a).card ≤ n :=
if hn : n = 0
then if h : (X : R[X]) ^ n - C a = 0
then by simp only [nat.zero_le, nth_roots, roots, h, dif_pos rfl, empty_eq_zero, card_zero]
else with_bot.coe_le_coe.1 (le_trans (card_roots h)
(by { rw [hn, pow_zero, ← C_1, ← ring_hom.map_sub ],
exact degree_C_le }))
else by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a];
exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a)
@[simp]
lemma nth_roots_two_eq_zero_iff {r : R} : nth_roots 2 r = 0 ↔ ¬ is_square r :=
by simp_rw [is_square_iff_exists_sq, eq_zero_iff_forall_not_mem,
mem_nth_roots (by norm_num : 0 < 2), ← not_exists, eq_comm]
/-- The multiset `nth_roots ↑n (1 : R)` as a finset. -/
def nth_roots_finset (n : ℕ) (R : Type*) [comm_ring R] [is_domain R] : finset R :=
multiset.to_finset (nth_roots n (1 : R))
@[simp] lemma mem_nth_roots_finset {n : ℕ} (h : 0 < n) {x : R} :
x ∈ nth_roots_finset n R ↔ x ^ (n : ℕ) = 1 :=
by rw [nth_roots_finset, mem_to_finset, mem_nth_roots h]
@[simp] lemma nth_roots_finset_zero : nth_roots_finset 0 R = ∅ := by simp [nth_roots_finset]
end nth_roots
lemma monic.comp (hp : p.monic) (hq : q.monic) (h : q.nat_degree ≠ 0) : (p.comp q).monic :=
by rw [monic.def, leading_coeff_comp h, monic.def.1 hp, monic.def.1 hq, one_pow, one_mul]
lemma monic.comp_X_add_C (hp : p.monic) (r : R) : (p.comp (X + C r)).monic :=
begin
refine hp.comp (monic_X_add_C _) (λ ha, _),
rw [nat_degree_X_add_C] at ha,
exact one_ne_zero ha
end
lemma monic.comp_X_sub_C (hp : p.monic) (r : R) : (p.comp (X - C r)).monic :=
by simpa using hp.comp_X_add_C (-r)
lemma units_coeff_zero_smul (c : R[X]ˣ) (p : R[X]) :
(c : R[X]).coeff 0 • p = c * p :=
by rw [←polynomial.C_mul', ←polynomial.eq_C_of_degree_eq_zero (degree_coe_units c)]
@[simp] lemma nat_degree_coe_units (u : R[X]ˣ) :
nat_degree (u : R[X]) = 0 :=
nat_degree_eq_of_degree_eq_some (degree_coe_units u)
lemma comp_eq_zero_iff :
p.comp q = 0 ↔ p = 0 ∨ (p.eval (q.coeff 0) = 0 ∧ q = C (q.coeff 0)) :=
begin
split,
{ intro h,
have key : p.nat_degree = 0 ∨ q.nat_degree = 0,
{ rw [←mul_eq_zero, ←nat_degree_comp, h, nat_degree_zero] },
replace key := or.imp eq_C_of_nat_degree_eq_zero eq_C_of_nat_degree_eq_zero key,
cases key,
{ rw [key, C_comp] at h,
exact or.inl (key.trans h) },
{ rw [key, comp_C, C_eq_zero] at h,
exact or.inr ⟨h, key⟩ }, },
{ exact λ h, or.rec (λ h, by rw [h, zero_comp]) (λ h, by rw [h.2, comp_C, h.1, C_0]) h },
end
lemma zero_of_eval_zero [infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 :=
by classical; by_contradiction hp; exact
fintype.false ⟨p.roots.to_finset, λ x, multiset.mem_to_finset.mpr ((mem_roots hp).mpr (h _))⟩
lemma funext [infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q :=
begin
rw ← sub_eq_zero,
apply zero_of_eval_zero,
intro x,
rw [eval_sub, sub_eq_zero, ext],
end
variables [comm_ring T]
/-- The set of distinct roots of `p` in `E`.
If you have a non-separable polynomial, use `polynomial.roots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def root_set (p : T[X]) (S) [comm_ring S] [is_domain S] [algebra T S] : set S :=
(p.map (algebra_map T S)).roots.to_finset
lemma root_set_def (p : T[X]) (S) [comm_ring S] [is_domain S] [algebra T S] :
p.root_set S = (p.map (algebra_map T S)).roots.to_finset :=
rfl
@[simp] lemma root_set_C [comm_ring S] [is_domain S] [algebra T S] (a : T) :
(C a).root_set S = ∅ :=
by rw [root_set_def, map_C, roots_C, multiset.to_finset_zero, finset.coe_empty]
@[simp] lemma root_set_zero (S) [comm_ring S] [is_domain S] [algebra T S] :
(0 : T[X]).root_set S = ∅ :=
by rw [← C_0, root_set_C]
instance root_set_fintype (p : T[X])
(S : Type*) [comm_ring S] [is_domain S] [algebra T S] : fintype (p.root_set S) :=
finset_coe.fintype _
lemma root_set_finite (p : T[X])
(S : Type*) [comm_ring S] [is_domain S] [algebra T S] : (p.root_set S).finite :=
set.to_finite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
lemma bUnion_roots_finite {R S : Type*} [semiring R] [comm_ring S] [is_domain S]
(m : R →+* S) (d : ℕ) {U : set R} (h : U.finite) :
(⋃ (f : R[X]) (hf : f.nat_degree ≤ d ∧ ∀ i, (f.coeff i) ∈ U),
((f.map m).roots.to_finset : set S)).finite :=
set.finite.bUnion begin
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `π` is finite
let π : R[X] → fin (d+1) → R := λ f i, f.coeff i,
refine ((set.finite.pi $ λ e, h).subset $ _).of_finite_image (_ : set.inj_on π _),
{ exact set.image_subset_iff.2 (λ f hf i _, hf.2 i) },
{ refine λ x hx y hy hxy, (ext_iff_nat_degree_le hx.1 hy.1).2 (λ i hi, _),
exact id congr_fun hxy ⟨i, nat.lt_succ_of_le hi⟩ },
end $ λ i hi, finset.finite_to_set _
theorem mem_root_set_iff' {p : T[X]} {S : Type*} [comm_ring S] [is_domain S]
[algebra T S] (hp : p.map (algebra_map T S) ≠ 0) (a : S) :
a ∈ p.root_set S ↔ (p.map (algebra_map T S)).eval a = 0 :=
by { change a ∈ multiset.to_finset _ ↔ _, rw [mem_to_finset, mem_roots hp], refl }
theorem mem_root_set_iff {p : T[X]} (hp : p ≠ 0) {S : Type*} [comm_ring S] [is_domain S]
[algebra T S] [no_zero_smul_divisors T S] (a : S) : a ∈ p.root_set S ↔ aeval a p = 0 :=
begin
rw [mem_root_set_iff', ←eval₂_eq_eval_map],
{ refl },
intro h,
rw ←polynomial.map_zero (algebra_map T S) at h,
exact hp (map_injective _ (no_zero_smul_divisors.algebra_map_injective T S) h)
end
lemma root_set_maps_to {p : T[X]} {S S'} [comm_ring S] [is_domain S] [algebra T S]
[comm_ring S'] [is_domain S'] [algebra T S'] (hp : p.map (algebra_map T S') ≠ 0)
(f : S →ₐ[T] S') : (p.root_set S).maps_to f (p.root_set S') :=
λ x hx, begin
rw [mem_root_set_iff' hp, ← f.comp_algebra_map, ← map_map, eval_map],
erw [eval₂_hom, (mem_root_set_iff' (mt (λ h, _) hp) x).1 hx, _root_.map_zero],
rw [← f.comp_algebra_map, ← map_map, h, polynomial.map_zero],
end
lemma ne_zero_of_mem_root_set {p : T[X]} [comm_ring S] [is_domain S] [algebra T S] {a : S}
(h : a ∈ p.root_set S) : p ≠ 0 :=
λ hf, by rwa [hf, root_set_zero] at h
lemma aeval_eq_zero_of_mem_root_set {p : T[X]} [comm_ring S] [is_domain S] [algebra T S]
[no_zero_smul_divisors T S] {a : S} (hx : a ∈ p.root_set S) : aeval a p = 0 :=
(mem_root_set_iff (ne_zero_of_mem_root_set hx) a).mp hx
end roots
lemma coeff_coe_units_zero_ne_zero (u : R[X]ˣ) :
coeff (u : R[X]) 0 ≠ 0 :=
begin
conv in (0) { rw [← nat_degree_coe_units u] },
rw [← leading_coeff, ne.def, leading_coeff_eq_zero],
exact units.ne_zero _
end
lemma degree_eq_degree_of_associated (h : associated p q) : degree p = degree q :=
let ⟨u, hu⟩ := h in by simp [hu.symm]
lemma degree_eq_one_of_irreducible_of_root (hi : irreducible p) {x : R} (hx : is_root p x) :
degree p = 1 :=
let ⟨g, hg⟩ := dvd_iff_is_root.2 hx in
have is_unit (X - C x) ∨ is_unit g, from hi.is_unit_or_is_unit hg,
this.elim
(λ h, have h₁ : degree (X - C x) = 1, from degree_X_sub_C x,
have h₂ : degree (X - C x) = 0, from degree_eq_zero_of_is_unit h,
by rw h₁ at h₂; exact absurd h₂ dec_trivial)
(λ hgu, by rw [hg, degree_mul, degree_X_sub_C, degree_eq_zero_of_is_unit hgu, add_zero])
/-- Division by a monic polynomial doesn't change the leading coefficient. -/
lemma leading_coeff_div_by_monic_of_monic {R : Type u} [comm_ring R]
{p q : R[X]} (hmonic : q.monic) (hdegree : q.degree ≤ p.degree) :
(p /ₘ q).leading_coeff = p.leading_coeff :=
begin
nontriviality,
have h : q.leading_coeff * (p /ₘ q).leading_coeff ≠ 0,
{ simpa [div_by_monic_eq_zero_iff hmonic, hmonic.leading_coeff, nat.with_bot.one_le_iff_zero_lt]
using hdegree },
nth_rewrite_rhs 0 ←mod_by_monic_add_div p hmonic,
rw [leading_coeff_add_of_degree_lt, leading_coeff_monic_mul hmonic],
rw [degree_mul' h, degree_add_div_by_monic hmonic hdegree],
exact (degree_mod_by_monic_lt p hmonic).trans_le hdegree
end
lemma leading_coeff_div_by_monic_X_sub_C (p : R[X]) (hp : degree p ≠ 0) (a : R) :
leading_coeff (p /ₘ (X - C a)) = leading_coeff p :=
begin
nontriviality,
cases hp.lt_or_lt with hd hd,
{ rw [degree_eq_bot.mp $ (nat.with_bot.lt_zero_iff _).mp hd, zero_div_by_monic] },
refine leading_coeff_div_by_monic_of_monic (monic_X_sub_C a) _,
rwa [degree_X_sub_C, nat.with_bot.one_le_iff_zero_lt]
end
lemma eq_leading_coeff_mul_of_monic_of_dvd_of_nat_degree_le {R} [comm_ring R]
{p q : R[X]} (hp : p.monic) (hdiv : p ∣ q)
(hdeg : q.nat_degree ≤ p.nat_degree) : q = C q.leading_coeff * p :=
begin
obtain ⟨r, hr⟩ := hdiv,
obtain (rfl|hq) := eq_or_ne q 0, {simp},
have rzero : r ≠ 0 := λ h, by simpa [h, hq] using hr,
rw [hr, nat_degree_mul'] at hdeg, swap,
{ rw [hp.leading_coeff, one_mul, leading_coeff_ne_zero], exact rzero },
rw [mul_comm, @eq_C_of_nat_degree_eq_zero _ _ r] at hr,
{ convert hr, convert leading_coeff_C _ using 1, rw [hr, leading_coeff_mul_monic hp] },
{ exact (add_right_inj _).1 (le_antisymm hdeg $ nat.le.intro rfl) },
end
lemma eq_of_monic_of_dvd_of_nat_degree_le {R} [comm_ring R]
{p q : R[X]} (hp : p.monic) (hq : q.monic) (hdiv : p ∣ q)
(hdeg : q.nat_degree ≤ p.nat_degree) : q = p :=
begin
convert eq_leading_coeff_mul_of_monic_of_dvd_of_nat_degree_le hp hdiv hdeg,
rw [hq.leading_coeff, C_1, one_mul],
end
lemma is_coprime_X_sub_C_of_is_unit_sub {R} [comm_ring R] {a b : R}
(h : is_unit (a - b)) : is_coprime (X - C a) (X - C b) :=
⟨-C h.unit⁻¹.val, C h.unit⁻¹.val, by { rw [neg_mul_comm, ← left_distrib, neg_add_eq_sub,
sub_sub_sub_cancel_left, ← C_sub, ← C_mul], convert C_1, exact h.coe_inv_mul }⟩
theorem pairwise_coprime_X_sub_C {K} [field K] {I : Type v} {s : I → K}
(H : function.injective s) : pairwise (is_coprime on (λ i : I, X - C (s i))) :=
λ i j hij, is_coprime_X_sub_C_of_is_unit_sub (sub_ne_zero_of_ne $ H.ne hij).is_unit
lemma monic_prod_multiset_X_sub_C : monic (p.roots.map (λ a, X - C a)).prod :=
monic_multiset_prod_of_monic _ _ (λ a _, monic_X_sub_C a)
lemma prod_multiset_root_eq_finset_root :
(p.roots.map (λ a, X - C a)).prod =
p.roots.to_finset.prod (λ a, (X - C a) ^ root_multiplicity a p) :=
by simp only [count_roots, finset.prod_multiset_map_count]
/-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
lemma prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map (λ a, X - C a)).prod ∣ p :=
begin
rw ← map_dvd_map _ (is_fraction_ring.injective R $ fraction_ring R) monic_prod_multiset_X_sub_C,
rw [prod_multiset_root_eq_finset_root, polynomial.map_prod],
refine finset.prod_dvd_of_coprime (λ a _ b _ h, _) (λ a _, _),
{ simp_rw [polynomial.map_pow, polynomial.map_sub, map_C, map_X],
exact (pairwise_coprime_X_sub_C (is_fraction_ring.injective R $ fraction_ring R) h).pow },
{ exact polynomial.map_dvd _ (pow_root_multiplicity_dvd p a) },
end
/-- A Galois connection. -/
lemma _root_.multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p ≠ 0) (s : multiset R) :
(s.map (λ a, X - C a)).prod ∣ p ↔ s ≤ p.roots :=
⟨λ h, multiset.le_iff_count.2 $ λ r, begin
rw [count_roots, le_root_multiplicity_iff hp, ← multiset.prod_repeat,
← multiset.map_repeat (λ a, X - C a), ← multiset.filter_eq],
exact (multiset.prod_dvd_prod_of_le $ multiset.map_le_map $ s.filter_le _).trans h,
end, λ h, (multiset.prod_dvd_prod_of_le $ multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩
lemma exists_prod_multiset_X_sub_C_mul (p : R[X]) : ∃ q,
(p.roots.map (λ a, X - C a)).prod * q = p ∧
p.roots.card + q.nat_degree = p.nat_degree ∧
q.roots = 0 :=
begin
obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd,
use [q, he.symm],
obtain (rfl|hq) := eq_or_ne q 0,
{ rw mul_zero at he, subst he, simp },
split,
{ conv_rhs { rw he },
rw [monic_prod_multiset_X_sub_C.nat_degree_mul' hq, nat_degree_multiset_prod_X_sub_C_eq_card] },
{ replace he := congr_arg roots he.symm,
rw [roots_mul, roots_multiset_prod_X_sub_C] at he,
exacts [add_right_eq_self.1 he, mul_ne_zero monic_prod_multiset_X_sub_C.ne_zero hq] },
end
/-- A polynomial `p` that has as many roots as its degree
can be written `p = p.leading_coeff * ∏(X - a)`, for `a` in `p.roots`. -/
lemma C_leading_coeff_mul_prod_multiset_X_sub_C (hroots : p.roots.card = p.nat_degree) :
C p.leading_coeff * (p.roots.map (λ a, X - C a)).prod = p :=
(eq_leading_coeff_mul_of_monic_of_dvd_of_nat_degree_le monic_prod_multiset_X_sub_C
p.prod_multiset_X_sub_C_dvd ((nat_degree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm
/-- A monic polynomial `p` that has as many roots as its degree
can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/
lemma prod_multiset_X_sub_C_of_monic_of_roots_card_eq
(hp : p.monic) (hroots : p.roots.card = p.nat_degree) :
(p.roots.map (λ a, X - C a)).prod = p :=
by { convert C_leading_coeff_mul_prod_multiset_X_sub_C hroots, rw [hp.leading_coeff, C_1, one_mul] }
end comm_ring
section
variables {A B : Type*} [comm_ring A] [comm_ring B]
lemma le_root_multiplicity_map {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0) (a : A) :
root_multiplicity a p ≤ root_multiplicity (f a) (p.map f) :=
begin
rw [le_root_multiplicity_iff hmap],
refine trans _ ((map_ring_hom f).map_dvd (pow_root_multiplicity_dvd p a)),
rw [map_pow, map_sub, coe_map_ring_hom, map_X, map_C],
end
lemma eq_root_multiplicity_map {p : A[X]} {f : A →+* B} (hf : function.injective f)
(a : A) : root_multiplicity a p = root_multiplicity (f a) (p.map f) :=
begin
by_cases hp0 : p = 0, { simp only [hp0, root_multiplicity_zero, polynomial.map_zero], },
apply le_antisymm (le_root_multiplicity_map ((polynomial.map_ne_zero_iff hf).mpr hp0) a),
rw [le_root_multiplicity_iff hp0, ← map_dvd_map f hf ((monic_X_sub_C a).pow _),
polynomial.map_pow, polynomial.map_sub, map_X, map_C],
apply pow_root_multiplicity_dvd,
end
lemma count_map_roots [is_domain A] {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0) (b : B) :
(p.roots.map f).count b ≤ root_multiplicity b (p.map f) :=
begin
rw [le_root_multiplicity_iff hmap, ← multiset.prod_repeat, ← multiset.map_repeat (λ a, X - C a)],
rw ← multiset.filter_eq,
refine (multiset.prod_dvd_prod_of_le $ multiset.map_le_map $ multiset.filter_le _ _).trans _,
convert polynomial.map_dvd _ p.prod_multiset_X_sub_C_dvd,
simp only [polynomial.map_multiset_prod, multiset.map_map],
congr, ext1,
simp only [function.comp_app, polynomial.map_sub, map_X, map_C],
end
lemma count_map_roots_of_injective [is_domain A] (p : A[X]) {f : A →+* B}
(hf : function.injective f) (b : B) :
(p.roots.map f).count b ≤ root_multiplicity b (p.map f) :=
begin
by_cases hp0 : p = 0,
{ simp only [hp0, roots_zero, multiset.map_zero,
multiset.count_zero, polynomial.map_zero, root_multiplicity_zero] },
{ exact count_map_roots ((polynomial.map_ne_zero_iff hf).mpr hp0) b },
end
lemma map_roots_le [is_domain A] [is_domain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
p.roots.map f ≤ (p.map f).roots :=
multiset.le_iff_count.2 $ λ b, by { rw count_roots, apply count_map_roots h }
lemma map_roots_le_of_injective [is_domain A] [is_domain B] (p : A[X])
{f : A →+* B} (hf : function.injective f) :
p.roots.map f ≤ (p.map f).roots :=
begin
by_cases hp0 : p = 0, { simp only [hp0, roots_zero, multiset.map_zero, polynomial.map_zero], },
exact map_roots_le ((polynomial.map_ne_zero_iff hf).mpr hp0),
end
lemma card_roots_le_map [is_domain A] [is_domain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
p.roots.card ≤ (p.map f).roots.card :=
by { rw ← p.roots.card_map f, exact multiset.card_le_of_le (map_roots_le h) }
lemma card_roots_le_map_of_injective [is_domain A] [is_domain B] {p : A[X]} {f : A →+* B}
(hf : function.injective f) : p.roots.card ≤ (p.map f).roots.card :=
begin
by_cases hp0 : p = 0, { simp only [hp0, roots_zero, polynomial.map_zero, multiset.card_zero], },
exact card_roots_le_map ((polynomial.map_ne_zero_iff hf).mpr hp0),
end
lemma roots_map_of_injective_of_card_eq_nat_degree [is_domain A] [is_domain B] {p : A[X]}
{f : A →+* B} (hf : function.injective f) (hroots : p.roots.card = p.nat_degree) :
p.roots.map f = (p.map f).roots :=
begin
apply multiset.eq_of_le_of_card_le (map_roots_le_of_injective p hf),
simpa only [multiset.card_map, hroots] using (card_roots' _).trans (nat_degree_map_le f p),
end
end
section
variables [semiring R] [comm_ring S] [is_domain S] (φ : R →+* S)
lemma is_unit_of_is_unit_leading_coeff_of_is_unit_map
{f : R[X]} (hf : is_unit f.leading_coeff) (H : is_unit (map φ f)) :
is_unit f :=
begin
have dz := degree_eq_zero_of_is_unit H,
rw degree_map_eq_of_leading_coeff_ne_zero at dz,
{ rw eq_C_of_degree_eq_zero dz,
refine is_unit.map C _,
convert hf,
rw (degree_eq_iff_nat_degree_eq _).1 dz,
rintro rfl,
simpa using H, },
{ intro h,
have u : is_unit (φ f.leading_coeff) := is_unit.map φ hf,
rw h at u,
simpa using u, }
end
end
section
variables [comm_ring R] [is_domain R] [comm_ring S] [is_domain S] (φ : R →+* S)
/--
A polynomial over an integral domain `R` is irreducible if it is monic and
irreducible after mapping into an integral domain `S`.
A special case of this lemma is that a polynomial over `ℤ` is irreducible if
it is monic and irreducible over `ℤ/pℤ` for some prime `p`.
-/
lemma monic.irreducible_of_irreducible_map (f : R[X])
(h_mon : monic f) (h_irr : irreducible (map φ f)) :
irreducible f :=
begin
refine ⟨h_irr.not_unit ∘ is_unit.map (map_ring_hom φ), λ a b h, _⟩,
dsimp [monic] at h_mon,
have q := (leading_coeff_mul a b).symm,
rw [←h, h_mon] at q,
refine (h_irr.is_unit_or_is_unit $ (congr_arg (map φ) h).trans (polynomial.map_mul φ)).imp _ _;
apply is_unit_of_is_unit_leading_coeff_of_is_unit_map;
apply is_unit_of_mul_eq_one,
{ exact q }, { rw mul_comm, exact q },
end
end
end polynomial
|
f8a8eb6ba65033fb945110f7b13c88c67b7b1cae | 4fa161becb8ce7378a709f5992a594764699e268 | /src/data/set/intervals/image_preimage.lean | 57b85727314e8b3e8fd347623045f1e149afd973 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 12,310 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Patrick Massot
-/
import data.set.intervals.basic
import data.equiv.mul_add
/-!
# (Pre)images of intervals
In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`,
then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove
lemmas about preimages and images of all intervals. We also prove a few lemmas about images under
`x ↦ a * x` and `x ↦ x * a`.
-/
universe u
namespace set
section ordered_add_comm_group
variables {G : Type u} [ordered_add_comm_group G] (a b c : G)
/-!
### Preimages under `x ↦ a + x`
-/
@[simp] lemma preimage_const_add_Ici : (λ x, a + x) ⁻¹' (Ici b) = Ici (b - a) :=
ext $ λ x, sub_le_iff_le_add'.symm
@[simp] lemma preimage_const_add_Ioi : (λ x, a + x) ⁻¹' (Ioi b) = Ioi (b - a) :=
ext $ λ x, sub_lt_iff_lt_add'.symm
@[simp] lemma preimage_const_add_Iic : (λ x, a + x) ⁻¹' (Iic b) = Iic (b - a) :=
ext $ λ x, le_sub_iff_add_le'.symm
@[simp] lemma preimage_const_add_Iio : (λ x, a + x) ⁻¹' (Iio b) = Iio (b - a) :=
ext $ λ x, lt_sub_iff_add_lt'.symm
@[simp] lemma preimage_const_add_Icc : (λ x, a + x) ⁻¹' (Icc b c) = Icc (b - a) (c - a) :=
by simp [← Ici_inter_Iic]
@[simp] lemma preimage_const_add_Ico : (λ x, a + x) ⁻¹' (Ico b c) = Ico (b - a) (c - a) :=
by simp [← Ici_inter_Iio]
@[simp] lemma preimage_const_add_Ioc : (λ x, a + x) ⁻¹' (Ioc b c) = Ioc (b - a) (c - a) :=
by simp [← Ioi_inter_Iic]
@[simp] lemma preimage_const_add_Ioo : (λ x, a + x) ⁻¹' (Ioo b c) = Ioo (b - a) (c - a) :=
by simp [← Ioi_inter_Iio]
/-!
### Preimages under `x ↦ x + a`
-/
@[simp] lemma preimage_add_const_Ici : (λ x, x + a) ⁻¹' (Ici b) = Ici (b - a) :=
ext $ λ x, sub_le_iff_le_add.symm
@[simp] lemma preimage_add_const_Ioi : (λ x, x + a) ⁻¹' (Ioi b) = Ioi (b - a) :=
ext $ λ x, sub_lt_iff_lt_add.symm
@[simp] lemma preimage_add_const_Iic : (λ x, x + a) ⁻¹' (Iic b) = Iic (b - a) :=
ext $ λ x, le_sub_iff_add_le.symm
@[simp] lemma preimage_add_const_Iio : (λ x, x + a) ⁻¹' (Iio b) = Iio (b - a) :=
ext $ λ x, lt_sub_iff_add_lt.symm
@[simp] lemma preimage_add_const_Icc : (λ x, x + a) ⁻¹' (Icc b c) = Icc (b - a) (c - a) :=
by simp [← Ici_inter_Iic]
@[simp] lemma preimage_add_const_Ico : (λ x, x + a) ⁻¹' (Ico b c) = Ico (b - a) (c - a) :=
by simp [← Ici_inter_Iio]
@[simp] lemma preimage_add_const_Ioc : (λ x, x + a) ⁻¹' (Ioc b c) = Ioc (b - a) (c - a) :=
by simp [← Ioi_inter_Iic]
@[simp] lemma preimage_add_const_Ioo : (λ x, x + a) ⁻¹' (Ioo b c) = Ioo (b - a) (c - a) :=
by simp [← Ioi_inter_Iio]
/-!
### Preimages under `x ↦ -x`
-/
@[simp] lemma preimage_neg_Ici : has_neg.neg ⁻¹' (Ici a) = Iic (-a) := ext $ λ x, le_neg
@[simp] lemma preimage_neg_Iic : has_neg.neg ⁻¹' (Iic a) = Ici (-a) := ext $ λ x, neg_le
@[simp] lemma preimage_neg_Ioi : has_neg.neg ⁻¹' (Ioi a) = Iio (-a) := ext $ λ x, lt_neg
@[simp] lemma preimage_neg_Iio : has_neg.neg ⁻¹' (Iio a) = Ioi (-a) := ext $ λ x, neg_lt
@[simp] lemma preimage_neg_Icc : has_neg.neg ⁻¹' (Icc a b) = Icc (-b) (-a) :=
by simp [← Ici_inter_Iic, inter_comm]
@[simp] lemma preimage_neg_Ico : has_neg.neg ⁻¹' (Ico a b) = Ioc (-b) (-a) :=
by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm]
@[simp] lemma preimage_neg_Ioc : has_neg.neg ⁻¹' (Ioc a b) = Ico (-b) (-a) :=
by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
@[simp] lemma preimage_neg_Ioo : has_neg.neg ⁻¹' (Ioo a b) = Ioo (-b) (-a) :=
by simp [← Ioi_inter_Iio, inter_comm]
/-!
### Preimages under `x ↦ x - a`
-/
@[simp] lemma preimage_sub_const_Ici : (λ x, x - a) ⁻¹' (Ici b) = Ici (b + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Ioi : (λ x, x - a) ⁻¹' (Ioi b) = Ioi (b + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Iic : (λ x, x - a) ⁻¹' (Iic b) = Iic (b + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Iio : (λ x, x - a) ⁻¹' (Iio b) = Iio (b + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Icc : (λ x, x - a) ⁻¹' (Icc b c) = Icc (b + a) (c + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Ico : (λ x, x - a) ⁻¹' (Ico b c) = Ico (b + a) (c + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Ioc : (λ x, x - a) ⁻¹' (Ioc b c) = Ioc (b + a) (c + a) :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_sub_const_Ioo : (λ x, x - a) ⁻¹' (Ioo b c) = Ioo (b + a) (c + a) :=
by simp [sub_eq_add_neg]
/-!
### Preimages under `x ↦ a - x`
-/
@[simp] lemma preimage_const_sub_Ici : (λ x, a - x) ⁻¹' (Ici b) = Iic (a - b) :=
ext $ λ x, le_sub
@[simp] lemma preimage_const_sub_Iic : (λ x, a - x) ⁻¹' (Iic b) = Ici (a - b) :=
ext $ λ x, sub_le
@[simp] lemma preimage_const_sub_Ioi : (λ x, a - x) ⁻¹' (Ioi b) = Iio (a - b) :=
ext $ λ x, lt_sub
@[simp] lemma preimage_const_sub_Iio : (λ x, a - x) ⁻¹' (Iio b) = Ioi (a - b) :=
ext $ λ x, sub_lt
@[simp] lemma preimage_const_sub_Icc : (λ x, a - x) ⁻¹' (Icc b c) = Icc (a - c) (a - b) :=
by simp [← Ici_inter_Iic, inter_comm]
@[simp] lemma preimage_const_sub_Ico : (λ x, a - x) ⁻¹' (Ico b c) = Ioc (a - c) (a - b) :=
by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
@[simp] lemma preimage_const_sub_Ioc : (λ x, a - x) ⁻¹' (Ioc b c) = Ico (a - c) (a - b) :=
by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm]
@[simp] lemma preimage_const_sub_Ioo : (λ x, a - x) ⁻¹' (Ioo b c) = Ioo (a - c) (a - b) :=
by simp [← Ioi_inter_Iio, inter_comm]
/-!
### Images under `x ↦ a + x`
-/
@[simp] lemma image_const_add_Ici : (λ x, a + x) '' Ici b = Ici (a + b) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Iic : (λ x, a + x) '' Iic b = Iic (a + b) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Iio : (λ x, a + x) '' Iio b = Iio (a + b) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Ioi : (λ x, a + x) '' Ioi b = Ioi (a + b) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Icc : (λ x, a + x) '' Icc b c = Icc (a + b) (a + c) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Ico : (λ x, a + x) '' Ico b c = Ico (a + b) (a + c) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Ioc : (λ x, a + x) '' Ioc b c = Ioc (a + b) (a + c) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
@[simp] lemma image_const_add_Ioo : (λ x, a + x) '' Ioo b c = Ioo (a + b) (a + c) :=
((equiv.add_left a).image_eq_preimage _).trans $ by simp [add_comm]
/-!
### Images under `x ↦ x + a`
-/
@[simp] lemma image_add_const_Ici : (λ x, x + a) '' Ici b = Ici (a + b) := by simp [add_comm _ a]
@[simp] lemma image_add_const_Iic : (λ x, x + a) '' Iic b = Iic (a + b) := by simp [add_comm _ a]
@[simp] lemma image_add_const_Iio : (λ x, x + a) '' Iio b = Iio (a + b) := by simp [add_comm _ a]
@[simp] lemma image_add_const_Ioi : (λ x, x + a) '' Ioi b = Ioi (a + b) := by simp [add_comm _ a]
@[simp] lemma image_add_const_Icc : (λ x, x + a) '' Icc b c = Icc (a + b) (a + c) :=
by simp [add_comm _ a]
@[simp] lemma image_add_const_Ico : (λ x, x + a) '' Ico b c = Ico (a + b) (a + c) :=
by simp [add_comm _ a]
@[simp] lemma image_add_const_Ioc : (λ x, x + a) '' Ioc b c = Ioc (a + b) (a + c) :=
by simp [add_comm _ a]
@[simp] lemma image_add_const_Ioo : (λ x, x + a) '' Ioo b c = Ioo (a + b) (a + c) :=
by simp [add_comm _ a]
/-!
### Images under `x ↦ -x`
-/
@[simp] lemma image_neg_Ici : has_neg.neg '' (Ici a) = Iic (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Ici _
@[simp] lemma image_neg_Iic : has_neg.neg '' (Iic a) = Ici (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Iic _
@[simp] lemma image_neg_Ioi : has_neg.neg '' (Ioi a) = Iio (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Ioi _
@[simp] lemma image_neg_Iio : has_neg.neg '' (Iio a) = Ioi (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Iio _
@[simp] lemma image_neg_Icc : has_neg.neg '' (Icc a b) = Icc (-b) (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Icc _ _
@[simp] lemma image_neg_Ico : has_neg.neg '' (Ico a b) = Ioc (-b) (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Ico _ _
@[simp] lemma image_neg_Ioc : has_neg.neg '' (Ioc a b) = Ico (-b) (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Ioc _ _
@[simp] lemma image_neg_Ioo : has_neg.neg '' (Ioo a b) = Ioo (-b) (-a) :=
((equiv.neg G).image_eq_preimage _).trans $ preimage_neg_Ioo _ _
/-!
### Images under `x ↦ a - x`
-/
@[simp] lemma image_const_sub_Ici : (λ x, a - x) '' Ici b = Iic (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Iic : (λ x, a - x) '' Iic b = Ici (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Ioi : (λ x, a - x) '' Ioi b = Iio (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Iio : (λ x, a - x) '' Iio b = Ioi (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Icc : (λ x, a - x) '' Icc b c = Icc (a - c) (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Ico : (λ x, a - x) '' Ico b c = Ioc (a - c) (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Ioc : (λ x, a - x) '' Ioc b c = Ico (a - c) (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_const_sub_Ioo : (λ x, a - x) '' Ioo b c = Ioo (a - c) (a - b) :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
/-!
### Images under `x ↦ x - a`
-/
@[simp] lemma image_sub_const_Ici : (λ x, x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Iic : (λ x, x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Ioi : (λ x, x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Iio : (λ x, x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Icc : (λ x, x - a) '' Icc b c = Icc (b - a) (c - a) :=
by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Ico : (λ x, x - a) '' Ico b c = Ico (b - a) (c - a) :=
by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Ioc : (λ x, x - a) '' Ioc b c = Ioc (b - a) (c - a) :=
by simp [sub_eq_neg_add]
@[simp] lemma image_sub_const_Ioo : (λ x, x - a) '' Ioo b c = Ioo (b - a) (c - a) :=
by simp [sub_eq_neg_add]
end ordered_add_comm_group
/-!
### Multiplication in a field
-/
section linear_ordered_field
variables {k : Type u} [linear_ordered_field k]
lemma image_mul_right_Icc' (a b : k) {c : k} (h : 0 < c) :
(λ x, x * c) '' Icc a b = Icc (a * c) (b * c) :=
begin
ext x,
split,
{ rintros ⟨x, hx, rfl⟩,
exact ⟨mul_le_mul_of_nonneg_right hx.1 (le_of_lt h),
mul_le_mul_of_nonneg_right hx.2 (le_of_lt h)⟩ },
{ intro hx,
refine ⟨x / c, _, div_mul_cancel x (ne_of_gt h)⟩,
exact ⟨le_div_of_mul_le h hx.1, div_le_of_le_mul h (mul_comm b c ▸ hx.2)⟩ }
end
lemma image_mul_right_Icc {a b c : k} (hab : a ≤ b) (hc : 0 ≤ c) :
(λ x, x * c) '' Icc a b = Icc (a * c) (b * c) :=
begin
cases eq_or_lt_of_le hc,
{ subst c,
simp [(nonempty_Icc.2 hab).image_const] },
exact image_mul_right_Icc' a b ‹0 < c›
end
lemma image_mul_left_Icc' {a : k} (h : 0 < a) (b c : k) :
((*) a) '' Icc b c = Icc (a * b) (a * c) :=
by { convert image_mul_right_Icc' b c h using 1; simp only [mul_comm _ a] }
lemma image_mul_left_Icc {a b c : k} (ha : 0 ≤ a) (hbc : b ≤ c) :
((*) a) '' Icc b c = Icc (a * b) (a * c) :=
by { convert image_mul_right_Icc hbc ha using 1; simp only [mul_comm _ a] }
end linear_ordered_field
end set
|
80975f0e47179b7f5d8f6ebd2fb00944b99470ec | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /test/equiv_rw.lean | 08909579b78df6c0a67c4c4afcb6c9db5803d802 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,419 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import tactic.equiv_rw
import control.equiv_functor.instances -- these make equiv_rw more powerful!
-- Uncomment this line to observe the steps of constructing appropriate equivalences.
-- set_option trace.equiv_rw_type true
import tactic.equiv_rw
-- This fails if we use `occurs` rather than `kdepends_on` in `equiv_rw_type`.
instance : equiv_functor set :=
{ map := λ α β e s, by { equiv_rw e.symm, assumption, } }
-- Rewriting a hypothesis along an equivalence.
example {α β : Type} (e : α ≃ β)
(f : α → ℕ) (h : ∀ b : β, f (e.symm b) = 0) (i : α) : f i = 0 :=
begin
equiv_rw e at i,
apply h,
end
-- Check that dependent hypotheses are reverted and reintroduced.
example {α β : Type} (e : α ≃ β) (Z : α → Type) (f : Π a, Z a → ℕ)
(h : ∀ (b : β) (x : Z (e.symm b)), f (e.symm b) x = 0)
(i : α) (x : Z i) : f i x = 0 :=
begin
equiv_rw e at i,
guard_hyp i : β,
guard_target f (e.symm i) x = 0,
guard_hyp x : Z ((e.symm) i),
exact h i x,
end
-- Rewriting the goal along an equivalence.
example {α β : Type} (e : α ≃ β) (b : β) : α :=
begin
equiv_rw e,
exact b,
end
-- Fail if the equivalence can't be used.
example {α β γ : Type} (e : β ≃ γ) (a : α) : α :=
begin
success_if_fail { equiv_rw e at a },
success_if_fail { equiv_rw e },
exact a,
end
-- Verify that `equiv_rw` will rewrite under `equiv_functor` instances.
example {α β : Type} (u : unique α) (e : α ≃ β) : β :=
begin
equiv_rw e at u,
apply inhabited.default,
end
example {α β : Type} (p : equiv.perm α) (e : α ≃ β) : equiv.perm β :=
begin
equiv_rw e at p,
exact p,
end
-- We can rewrite the goal under functors.
example {α β : Type} (e : α ≃ β) (b : β) : option α :=
begin
equiv_rw e,
exact some b,
end
-- We can rewrite hypotheses under functors.
example {α β : Type} (e : α ≃ β) (b : option α) : option β :=
begin
equiv_rw e at b,
exact b,
end
-- We can rewrite hypotheses under compositions of functors.
example {α β : Type} (e : α ≃ β) (b : list (list α)) : list β :=
begin
equiv_rw e at b,
exact b.join,
end
-- Check that we can rewrite in the target position of function types.
example {α β γ : Type} (e : α ≃ β) (f : γ → β) : γ → α :=
begin
equiv_rw e,
exact f,
end
-- Check that we can rewrite in the source position of function types.
example {α β γ : Type} (e : α ≃ β) (f : β → γ) : α → γ :=
begin
equiv_rw e,
exact f,
end
-- Rewriting under multiple functors.
example {α β : Type} (e : α ≃ β) (b : β) : list (option α) :=
begin
equiv_rw e,
exact [none, some b],
end
-- Rewriting under multiple functors, including functions.
example {α β γ : Type} (e : α ≃ β) (b : β) : γ → list (option α) :=
begin
equiv_rw e,
exact (λ g, [none, some b]),
end
-- Rewriting in multiple positions.
example {α β : Type*} [has_add β] (e : α ≃ β) : α → α :=
begin
have : (α → α) ≃ _, {
apply equiv.arrow_congr,
apply e,
apply e,
},
equiv_rw e,
exact (@id β),
end
-- Rewriting in multiple positions.
example {α β : Type} [has_add β] (e : α ≃ β) : β → α → α :=
begin
equiv_rw e,
exact (+),
end
-- Rewriting in multiple positions.
example {α β : Type} [has_add β] (e : α ≃ β) : α → α → α :=
begin
equiv_rw e,
exact (+),
end
example {α β γ : Type} (e : α ≃ β) (s : β ⊕ γ) : α ⊕ γ :=
begin
equiv_rw e,
exact s,
end
example {α β γ : Type} (e : α ≃ β) (s : β ⊕ γ) : (α ⊕ γ) × (γ ⊕ α) :=
begin
equiv_rw e,
exact (s, s.swap),
end
example {α β γ : Type} (e : α ≃ β) (s : α ⊕ γ) : (β ⊕ γ) × (γ ⊕ β) :=
begin
equiv_rw e at s,
exact (s, s.swap),
end
example {α β γ : Type} (e : α ≃ β) (s : (α ⊕ γ) × β) : (β ⊕ γ) :=
begin
success_if_fail { equiv_rw e at s {max_depth := 4} },
equiv_rw e at s,
exact s.1,
end
-- Test generating the actual equivalence using `equiv_rw_type`.
example {α β : Type} (e : α ≃ β) (b : β) : α × (ℕ ⊕ ℕ) :=
begin
have e' : α × (ℕ ⊕ ℕ) ≃ _ := by equiv_rw_type e,
apply e'.inv_fun,
exact (b, sum.inl 0)
end
example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : { a // P a }) : β :=
begin
equiv_rw e at h,
exact h.val,
end
example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : ∀ a, P a) (b : β) : { a // P a } :=
begin
equiv_rw e,
use b,
apply h,
end
example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : ∀ a : α, P a) (b : β) : P (e.symm b) :=
begin
equiv_rw e.symm at b,
exact h b,
end
example {α β : Type} (e : α ≃ β) (P : α → Sort*) (h : Π a : α, P a) (b : β) : P (e.symm b) :=
begin
-- this is a bit perverse, as `equiv_rw e.symm at b` is more natural,
-- but this tests rewriting in the argument of a dependent function
equiv_rw e at h,
exact h _,
end
-- a poor example, rewriting in the base of a dependent pair
example {α β : Type} (P : α → Type) (h : Σ a, P a) (e : α ≃ β) : β :=
begin
equiv_rw e at h,
exact h.1
end
-- rewriting in the argument of a dependent function can't be done in one step
example {α β γ : Type} (e : α ≃ β) (P : α → Type*) (h : Π a : α, (P a) × (option α)) (b : β) :
option β :=
begin
equiv_rw e at h,
have t := h b,
equiv_rw e at t,
exact t.2,
end
-- Demonstrate using `equiv_rw` to build new instances of `equiv_functor`
-- Observe that the next three declarations could easily be implemented by a tactic.
-- This has been automated in the `transport` branch,
-- so we won't attempt to write a deriver handler until we join with that.
def semigroup.map {α β : Type} (e : α ≃ β) : semigroup α → semigroup β :=
begin
intro S,
refine_struct { .. },
-- transport data fields using `equiv_rw`
{ have mul := S.mul,
equiv_rw e at mul,
-- This `equiv_rw` performs the following steps:
-- have e' := (equiv.arrow_congr' e (equiv.arrow_congr' e e)),
-- have h := (e'.symm_apply_apply mul).symm,
-- revert h,
-- generalize : (e' mul) = mul',
-- intro h,
-- clear_dependent mul,
-- rename mul' mul,
exact mul,
},
-- transport axioms by simplifying, and applying the original axiom
{ intros, dsimp, simp, apply S.mul_assoc, }
end
example {α β : Type} (e : α ≃ β) (S : semigroup α) :
(semigroup.map e S).mul =
(equiv.arrow_congr' e (equiv.arrow_congr' e e)) has_mul.mul :=
rfl
example {α β : Type} (e : α ≃ β) (S : semigroup α) (x y : β) :
begin
haveI := semigroup.map e S,
exact x * y = e (e.symm x * e.symm y)
end :=
rfl
attribute [ext] semigroup
lemma semigroup.id_map (α : Type) : semigroup.map (equiv.refl α) = id :=
by { ext, refl, }
lemma semigroup.map_map {α β γ : Type} (e : α ≃ β) (f : β ≃ γ) :
semigroup.map (e.trans f) = (semigroup.map f) ∘ (semigroup.map e) :=
by { ext, dsimp [semigroup.map], simp, }
-- TODO (after joining the `transport` branch) create a derive handler for this
instance : equiv_functor semigroup :=
{ map := λ α β e, semigroup.map e,
map_refl' := semigroup.id_map,
map_trans' := λ α β γ e f, semigroup.map_map e f, }
-- Verify that we can now use `equiv_rw` under `semigroup`:
example {α : Type} [I : semigroup α] {β : Type} (e : α ≃ β) : semigroup β :=
begin
equiv_rw e at I,
exact I,
end
-- Now we do `monoid`, to try out a structure with constants.
-- The constructions and proofs here are written as uniformly as possible.
-- This example is the blueprint for the `transport` tactic.
mk_simp_attribute transport_simps "simps useful inside `transport`"
attribute [transport_simps]
eq_rec_constant
cast_eq
equiv.to_fun_as_coe
equiv.arrow_congr'_apply
equiv.symm_apply_apply
equiv.apply_eq_iff_eq_symm_apply
def monoid.map {α β : Type} (e : α ≃ β) (S : monoid α) : monoid β :=
begin
refine_struct { .. },
{ have mul := S.mul, equiv_rw e at mul, exact mul, },
{ try { unfold_projs },
simp only with transport_simps,
have mul_assoc := S.mul_assoc,
equiv_rw e at mul_assoc,
solve_by_elim, },
{ have one := S.one, equiv_rw e at one, exact one, },
{ try { unfold_projs },
simp only with transport_simps,
have one_mul := S.one_mul,
equiv_rw e at one_mul,
solve_by_elim, },
{ try { unfold_projs },
simp only with transport_simps,
have mul_one := S.mul_one,
equiv_rw e at mul_one,
solve_by_elim, },
end
example {α β : Type} (e : α ≃ β) (S : monoid α) :
(monoid.map e S).mul =
(equiv.arrow_congr' e (equiv.arrow_congr' e e)) has_mul.mul :=
rfl
example {α β : Type} (e : α ≃ β) (S : monoid α) (x y : β) :
begin
haveI := monoid.map e S,
exact x * y = e (e.symm x * e.symm y)
end :=
rfl
example {α β : Type} (e : α ≃ β) (S : monoid α) :
begin
haveI := monoid.map e S,
exact (1 : β) = e (1 : α)
end :=
rfl
example
{α : Type} {β : Type}
(m : α → α → α)
(e : α ≃ β) :
β → β → β :=
begin
equiv_rw e at m,
exact m,
end
-- This used to fail because metavariables were getting stuck!
example
{α : Type} {β : Type 2}
(m : α → α → α)
(e : α ≃ β) :
β → β → β :=
begin
equiv_rw e at m,
exact m,
end
|
028ba403b39a7c4d7ebbbcf47381c271a5e33f64 | 6094e25ea0b7699e642463b48e51b2ead6ddc23f | /library/init/logic.lean | 7cdc23c15ae5dd8a3de8ed3a3cd66d0e530c09c0 | [
"Apache-2.0"
] | permissive | gbaz/lean | a7835c4e3006fbbb079e8f8ffe18aacc45adebfb | a501c308be3acaa50a2c0610ce2e0d71becf8032 | refs/heads/master | 1,611,198,791,433 | 1,451,339,111,000 | 1,451,339,111,000 | 48,713,797 | 0 | 0 | null | 1,451,338,939,000 | 1,451,338,939,000 | null | UTF-8 | Lean | false | false | 32,950 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
-/
prelude
import init.datatypes init.reserved_notation init.tactic
definition id [reducible] [unfold_full] {A : Type} (a : A) : A :=
a
/- implication -/
definition implies (a b : Prop) := a → b
lemma implies.trans [trans] {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r :=
assume hp, h₂ (h₁ hp)
definition trivial := true.intro
definition not (a : Prop) := a → false
prefix `¬` := not
definition absurd {a : Prop} {b : Type} (H1 : a) (H2 : ¬a) : b :=
false.rec b (H2 H1)
lemma not.intro [intro!] {a : Prop} (H : a → false) : ¬ a :=
H
theorem mt {a b : Prop} (H1 : a → b) (H2 : ¬b) : ¬a :=
assume Ha : a, absurd (H1 Ha) H2
definition implies.resolve {a b : Prop} (H : a → b) (nb : ¬ b) : ¬ a := assume Ha, nb (H Ha)
/- not -/
theorem not_false : ¬false :=
assume H : false, H
definition non_contradictory (a : Prop) : Prop := ¬¬a
theorem non_contradictory_intro {a : Prop} (Ha : a) : ¬¬a :=
assume Hna : ¬a, absurd Ha Hna
/- false -/
theorem false.elim {c : Prop} (H : false) : c :=
false.rec c H
/- eq -/
notation a = b := eq a b
definition rfl {A : Type} {a : A} : a = a := eq.refl a
-- proof irrelevance is built in
theorem proof_irrel {a : Prop} (H₁ H₂ : a) : H₁ = H₂ :=
rfl
-- Remark: we provide the universe levels explicitly to make sure `eq.drec` has the same type of `eq.rec` in the HoTT library
protected theorem eq.drec.{l₁ l₂} {A : Type.{l₂}} {a : A} {C : Π (x : A), a = x → Type.{l₁}} (h₁ : C a (eq.refl a)) {b : A} (h₂ : a = b) : C b h₂ :=
eq.rec (λh₂ : a = a, show C a h₂, from h₁) h₂ h₂
namespace eq
variables {A : Type}
variables {a b c a': A}
protected theorem drec_on {a : A} {C : Π (x : A), a = x → Type} {b : A} (h₂ : a = b) (h₁ : C a (refl a)) : C b h₂ :=
eq.drec h₁ h₂
theorem subst {P : A → Prop} (H₁ : a = b) (H₂ : P a) : P b :=
eq.rec H₂ H₁
theorem trans (H₁ : a = b) (H₂ : b = c) : a = c :=
subst H₂ H₁
theorem symm : a = b → b = a :=
eq.rec (refl a)
theorem substr {P : A → Prop} (H₁ : b = a) : P a → P b :=
subst (symm H₁)
theorem mp {a b : Type} : (a = b) → a → b :=
eq.rec_on
theorem mpr {a b : Type} : (a = b) → b → a :=
assume H₁ H₂, eq.rec_on (eq.symm H₁) H₂
namespace ops
notation H `⁻¹` := symm H --input with \sy or \-1 or \inv
notation H1 ⬝ H2 := trans H1 H2
notation H1 ▸ H2 := subst H1 H2
notation H1 ▹ H2 := eq.rec H2 H1
end ops
end eq
theorem congr {A B : Type} {f₁ f₂ : A → B} {a₁ a₂ : A} (H₁ : f₁ = f₂) (H₂ : a₁ = a₂) : f₁ a₁ = f₂ a₂ :=
eq.subst H₁ (eq.subst H₂ rfl)
theorem congr_fun {A : Type} {B : A → Type} {f g : Π x, B x} (H : f = g) (a : A) : f a = g a :=
eq.subst H (eq.refl (f a))
theorem congr_arg {A B : Type} {a₁ a₂ : A} (f : A → B) : a₁ = a₂ → f a₁ = f a₂ :=
congr rfl
section
variables {A : Type} {a b c: A}
open eq.ops
theorem trans_rel_left (R : A → A → Prop) (H₁ : R a b) (H₂ : b = c) : R a c :=
H₂ ▸ H₁
theorem trans_rel_right (R : A → A → Prop) (H₁ : a = b) (H₂ : R b c) : R a c :=
H₁⁻¹ ▸ H₂
end
section
variable {p : Prop}
open eq.ops
theorem of_eq_true (H : p = true) : p :=
H⁻¹ ▸ trivial
theorem not_of_eq_false (H : p = false) : ¬p :=
assume Hp, H ▸ Hp
end
attribute eq.subst [subst]
attribute eq.refl [refl]
attribute eq.trans [trans]
attribute eq.symm [symm]
/- ne -/
definition ne [reducible] {A : Type} (a b : A) := ¬(a = b)
notation a ≠ b := ne a b
namespace ne
open eq.ops
variable {A : Type}
variables {a b : A}
theorem intro (H : a = b → false) : a ≠ b := H
theorem elim (H : a ≠ b) : a = b → false := H
theorem irrefl (H : a ≠ a) : false := H rfl
theorem symm (H : a ≠ b) : b ≠ a :=
assume (H₁ : b = a), H (H₁⁻¹)
end ne
theorem false_of_ne {A : Type} {a : A} : a ≠ a → false := ne.irrefl
section
open eq.ops
variables {p : Prop}
theorem ne_false_of_self : p → p ≠ false :=
assume (Hp : p) (Heq : p = false), Heq ▸ Hp
theorem ne_true_of_not : ¬p → p ≠ true :=
assume (Hnp : ¬p) (Heq : p = true), (Heq ▸ Hnp) trivial
theorem true_ne_false : ¬true = false :=
ne_false_of_self trivial
end
infixl ` == `:50 := heq
namespace heq
universe variable u
variables {A B C : Type.{u}} {a a' : A} {b b' : B} {c : C}
theorem to_eq (H : a == a') : a = a' :=
have H₁ : ∀ (Ht : A = A), eq.rec a Ht = a, from
λ Ht, eq.refl a,
heq.rec H₁ H (eq.refl A)
theorem elim {A : Type} {a : A} {P : A → Type} {b : A} (H₁ : a == b)
: P a → P b := eq.rec_on (to_eq H₁)
theorem subst {P : ∀T : Type, T → Prop} : a == b → P A a → P B b :=
heq.rec_on
theorem symm (H : a == b) : b == a :=
heq.rec_on H (refl a)
theorem of_eq (H : a = a') : a == a' :=
eq.subst H (refl a)
theorem trans (H₁ : a == b) (H₂ : b == c) : a == c :=
subst H₂ H₁
theorem of_heq_of_eq (H₁ : a == b) (H₂ : b = b') : a == b' :=
trans H₁ (of_eq H₂)
theorem of_eq_of_heq (H₁ : a = a') (H₂ : a' == b) : a == b :=
trans (of_eq H₁) H₂
definition type_eq (H : a == b) : A = B :=
heq.rec_on H (eq.refl A)
end heq
open eq.ops
theorem eq_rec_heq {A : Type} {P : A → Type} {a a' : A} (H : a = a') (p : P a) : H ▹ p == p :=
eq.drec_on H !heq.refl
theorem heq_of_eq_rec_left {A : Type} {P : A → Type} : ∀ {a a' : A} {p₁ : P a} {p₂ : P a'} (e : a = a') (h₂ : e ▹ p₁ = p₂), p₁ == p₂
| a a p₁ p₂ (eq.refl a) h := eq.rec_on h !heq.refl
theorem heq_of_eq_rec_right {A : Type} {P : A → Type} : ∀ {a a' : A} {p₁ : P a} {p₂ : P a'} (e : a' = a) (h₂ : p₁ = e ▹ p₂), p₁ == p₂
| a a p₁ p₂ (eq.refl a) h := eq.rec_on h !heq.refl
theorem of_heq_true {a : Prop} (H : a == true) : a :=
of_eq_true (heq.to_eq H)
theorem eq_rec_compose : ∀ {A B C : Type} (p₁ : B = C) (p₂ : A = B) (a : A), p₁ ▹ (p₂ ▹ a : B) = (p₂ ⬝ p₁) ▹ a
| A A A (eq.refl A) (eq.refl A) a := calc
eq.refl A ▹ eq.refl A ▹ a = eq.refl A ▹ a : rfl
... = (eq.refl A ⬝ eq.refl A) ▹ a : {proof_irrel (eq.refl A) (eq.refl A ⬝ eq.refl A)}
theorem eq_rec_eq_eq_rec {A₁ A₂ : Type} {p : A₁ = A₂} : ∀ {a₁ : A₁} {a₂ : A₂}, p ▹ a₁ = a₂ → a₁ = p⁻¹ ▹ a₂ :=
eq.drec_on p (λ a₁ a₂ h, eq.drec_on h rfl)
theorem eq_rec_of_heq_left : ∀ {A₁ A₂ : Type} {a₁ : A₁} {a₂ : A₂} (h : a₁ == a₂), heq.type_eq h ▹ a₁ = a₂
| A A a a (heq.refl a) := rfl
theorem eq_rec_of_heq_right {A₁ A₂ : Type} {a₁ : A₁} {a₂ : A₂} (h : a₁ == a₂) : a₁ = (heq.type_eq h)⁻¹ ▹ a₂ :=
eq_rec_eq_eq_rec (eq_rec_of_heq_left h)
attribute heq.refl [refl]
attribute heq.trans [trans]
attribute heq.of_heq_of_eq [trans]
attribute heq.of_eq_of_heq [trans]
attribute heq.symm [symm]
/- and -/
notation a /\ b := and a b
notation a ∧ b := and a b
variables {a b c d : Prop}
attribute and.rec [elim]
attribute and.intro [intro!]
theorem and.elim (H₁ : a ∧ b) (H₂ : a → b → c) : c :=
and.rec H₂ H₁
theorem and.swap : a ∧ b → b ∧ a :=
and.rec (λHa Hb, and.intro Hb Ha)
/- or -/
notation a \/ b := or a b
notation a ∨ b := or a b
attribute or.rec [elim]
namespace or
theorem elim (H₁ : a ∨ b) (H₂ : a → c) (H₃ : b → c) : c :=
or.rec H₂ H₃ H₁
end or
theorem non_contradictory_em (a : Prop) : ¬¬(a ∨ ¬a) :=
assume not_em : ¬(a ∨ ¬a),
have neg_a : ¬a, from
assume pos_a : a, absurd (or.inl pos_a) not_em,
absurd (or.inr neg_a) not_em
theorem or.swap : a ∨ b → b ∨ a := or.rec or.inr or.inl
/- iff -/
definition iff (a b : Prop) := (a → b) ∧ (b → a)
notation a <-> b := iff a b
notation a ↔ b := iff a b
theorem iff.intro : (a → b) → (b → a) → (a ↔ b) := and.intro
attribute iff.intro [intro!]
theorem iff.elim : ((a → b) → (b → a) → c) → (a ↔ b) → c := and.rec
attribute iff.elim [recursor 5] [elim]
theorem iff.elim_left : (a ↔ b) → a → b := and.left
definition iff.mp := @iff.elim_left
theorem iff.elim_right : (a ↔ b) → b → a := and.right
definition iff.mpr := @iff.elim_right
theorem iff.refl [refl] (a : Prop) : a ↔ a :=
iff.intro (assume H, H) (assume H, H)
theorem iff.rfl {a : Prop} : a ↔ a :=
iff.refl a
theorem iff.trans [trans] (H₁ : a ↔ b) (H₂ : b ↔ c) : a ↔ c :=
iff.intro
(assume Ha, iff.mp H₂ (iff.mp H₁ Ha))
(assume Hc, iff.mpr H₁ (iff.mpr H₂ Hc))
theorem iff.symm [symm] (H : a ↔ b) : b ↔ a :=
iff.intro (iff.elim_right H) (iff.elim_left H)
theorem iff.comm : (a ↔ b) ↔ (b ↔ a) :=
iff.intro iff.symm iff.symm
theorem iff.of_eq {a b : Prop} (H : a = b) : a ↔ b :=
eq.rec_on H iff.rfl
theorem not_iff_not_of_iff (H₁ : a ↔ b) : ¬a ↔ ¬b :=
iff.intro
(assume (Hna : ¬ a) (Hb : b), Hna (iff.elim_right H₁ Hb))
(assume (Hnb : ¬ b) (Ha : a), Hnb (iff.elim_left H₁ Ha))
theorem of_iff_true (H : a ↔ true) : a :=
iff.mp (iff.symm H) trivial
theorem not_of_iff_false : (a ↔ false) → ¬a := iff.mp
theorem iff_true_intro (H : a) : a ↔ true :=
iff.intro
(λ Hl, trivial)
(λ Hr, H)
theorem iff_false_intro (H : ¬a) : a ↔ false :=
iff.intro H !false.rec
theorem not_non_contradictory_iff_absurd (a : Prop) : ¬¬¬a ↔ ¬a :=
iff.intro
(λ (Hl : ¬¬¬a) (Ha : a), Hl (non_contradictory_intro Ha))
absurd
theorem imp_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a → b) ↔ (c → d) :=
iff.intro
(λHab Hc, iff.mp H2 (Hab (iff.mpr H1 Hc)))
(λHcd Ha, iff.mpr H2 (Hcd (iff.mp H1 Ha)))
theorem not_not_intro (Ha : a) : ¬¬a :=
assume Hna : ¬a, Hna Ha
theorem not_of_not_not_not (H : ¬¬¬a) : ¬a :=
λ Ha, absurd (not_not_intro Ha) H
theorem not_true [simp] : (¬ true) ↔ false :=
iff_false_intro (not_not_intro trivial)
theorem not_false_iff [simp] : (¬ false) ↔ true :=
iff_true_intro not_false
theorem not_congr [congr] (H : a ↔ b) : ¬a ↔ ¬b :=
iff.intro (λ H₁ H₂, H₁ (iff.mpr H H₂)) (λ H₁ H₂, H₁ (iff.mp H H₂))
theorem ne_self_iff_false [simp] {A : Type} (a : A) : (not (a = a)) ↔ false :=
iff.intro false_of_ne false.elim
theorem eq_self_iff_true [simp] {A : Type} (a : A) : (a = a) ↔ true :=
iff_true_intro rfl
theorem heq_self_iff_true [simp] {A : Type} (a : A) : (a == a) ↔ true :=
iff_true_intro (heq.refl a)
theorem iff_not_self [simp] (a : Prop) : (a ↔ ¬a) ↔ false :=
iff_false_intro (λ H,
have H' : ¬a, from (λ Ha, (iff.mp H Ha) Ha),
H' (iff.mpr H H'))
theorem not_iff_self [simp] (a : Prop) : (¬a ↔ a) ↔ false :=
iff_false_intro (λ H,
have H' : ¬a, from (λ Ha, (iff.mpr H Ha) Ha),
H' (iff.mp H H'))
theorem true_iff_false [simp] : (true ↔ false) ↔ false :=
iff_false_intro (λ H, iff.mp H trivial)
theorem false_iff_true [simp] : (false ↔ true) ↔ false :=
iff_false_intro (λ H, iff.mpr H trivial)
theorem false_of_true_iff_false : (true ↔ false) → false :=
assume H, iff.mp H trivial
/- and simp rules -/
theorem and.imp (H₂ : a → c) (H₃ : b → d) : a ∧ b → c ∧ d :=
and.rec (λHa Hb, and.intro (H₂ Ha) (H₃ Hb))
theorem and_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ∧ b) ↔ (c ∧ d) :=
iff.intro (and.imp (iff.mp H1) (iff.mp H2)) (and.imp (iff.mpr H1) (iff.mpr H2))
theorem and.comm [simp] : a ∧ b ↔ b ∧ a :=
iff.intro and.swap and.swap
theorem and.assoc [simp] : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) :=
iff.intro
(and.rec (λ H' Hc, and.rec (λ Ha Hb, and.intro Ha (and.intro Hb Hc)) H'))
(and.rec (λ Ha, and.rec (λ Hb Hc, and.intro (and.intro Ha Hb) Hc)))
theorem and.left_comm [simp] : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) :=
iff.trans (iff.symm !and.assoc) (iff.trans (and_congr !and.comm !iff.refl) !and.assoc)
theorem and_iff_left {a b : Prop} (Hb : b) : (a ∧ b) ↔ a :=
iff.intro and.left (λHa, and.intro Ha Hb)
theorem and_iff_right {a b : Prop} (Ha : a) : (a ∧ b) ↔ b :=
iff.intro and.right (and.intro Ha)
theorem and_true [simp] (a : Prop) : a ∧ true ↔ a :=
and_iff_left trivial
theorem true_and [simp] (a : Prop) : true ∧ a ↔ a :=
and_iff_right trivial
theorem and_false [simp] (a : Prop) : a ∧ false ↔ false :=
iff_false_intro and.right
theorem false_and [simp] (a : Prop) : false ∧ a ↔ false :=
iff_false_intro and.left
theorem not_and_self [simp] (a : Prop) : (¬a ∧ a) ↔ false :=
iff_false_intro (λ H, and.elim H (λ H₁ H₂, absurd H₂ H₁))
theorem and_not_self [simp] (a : Prop) : (a ∧ ¬a) ↔ false :=
iff_false_intro (λ H, and.elim H (λ H₁ H₂, absurd H₁ H₂))
theorem and_self [simp] (a : Prop) : a ∧ a ↔ a :=
iff.intro and.left (assume H, and.intro H H)
/- or simp rules -/
theorem or.imp (H₂ : a → c) (H₃ : b → d) : a ∨ b → c ∨ d :=
or.rec (λ H, or.inl (H₂ H)) (λ H, or.inr (H₃ H))
theorem or.imp_left (H : a → b) : a ∨ c → b ∨ c :=
or.imp H id
theorem or.imp_right (H : a → b) : c ∨ a → c ∨ b :=
or.imp id H
theorem or_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ∨ b) ↔ (c ∨ d) :=
iff.intro (or.imp (iff.mp H1) (iff.mp H2)) (or.imp (iff.mpr H1) (iff.mpr H2))
theorem or.comm [simp] : a ∨ b ↔ b ∨ a := iff.intro or.swap or.swap
theorem or.assoc [simp] : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) :=
iff.intro
(or.rec (or.imp_right or.inl) (λ H, or.inr (or.inr H)))
(or.rec (λ H, or.inl (or.inl H)) (or.imp_left or.inr))
theorem or.left_comm [simp] : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) :=
iff.trans (iff.symm !or.assoc) (iff.trans (or_congr !or.comm !iff.refl) !or.assoc)
theorem or_true [simp] (a : Prop) : a ∨ true ↔ true :=
iff_true_intro (or.inr trivial)
theorem true_or [simp] (a : Prop) : true ∨ a ↔ true :=
iff_true_intro (or.inl trivial)
theorem or_false [simp] (a : Prop) : a ∨ false ↔ a :=
iff.intro (or.rec id false.elim) or.inl
theorem false_or [simp] (a : Prop) : false ∨ a ↔ a :=
iff.trans or.comm !or_false
theorem or_self [simp] (a : Prop) : a ∨ a ↔ a :=
iff.intro (or.rec id id) or.inl
/- or resolution rulse -/
definition or.resolve_left {a b : Prop} (H : a ∨ b) (na : ¬ a) : b :=
or.elim H (λ Ha, absurd Ha na) id
definition or.neg_resolve_left {a b : Prop} (H : ¬ a ∨ b) (Ha : a) : b :=
or.elim H (λ na, absurd Ha na) id
definition or.resolve_right {a b : Prop} (H : a ∨ b) (nb : ¬ b) : a :=
or.elim H id (λ Hb, absurd Hb nb)
definition or.neg_resolve_right {a b : Prop} (H : a ∨ ¬ b) (Hb : b) : a :=
or.elim H id (λ nb, absurd Hb nb)
/- iff simp rules -/
theorem iff_true [simp] (a : Prop) : (a ↔ true) ↔ a :=
iff.intro (assume H, iff.mpr H trivial) iff_true_intro
theorem true_iff [simp] (a : Prop) : (true ↔ a) ↔ a :=
iff.trans iff.comm !iff_true
theorem iff_false [simp] (a : Prop) : (a ↔ false) ↔ ¬ a :=
iff.intro and.left iff_false_intro
theorem false_iff [simp] (a : Prop) : (false ↔ a) ↔ ¬ a :=
iff.trans iff.comm !iff_false
theorem iff_self [simp] (a : Prop) : (a ↔ a) ↔ true :=
iff_true_intro iff.rfl
theorem iff_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ↔ b) ↔ (c ↔ d) :=
and_congr (imp_congr H1 H2) (imp_congr H2 H1)
/- exists -/
inductive Exists {A : Type} (P : A → Prop) : Prop :=
intro : ∀ (a : A), P a → Exists P
attribute Exists.intro [intro]
definition exists.intro := @Exists.intro
notation `exists` binders `, ` r:(scoped P, Exists P) := r
notation `∃` binders `, ` r:(scoped P, Exists P) := r
attribute Exists.rec [elim]
theorem exists.elim {A : Type} {p : A → Prop} {B : Prop}
(H1 : ∃x, p x) (H2 : ∀ (a : A), p a → B) : B :=
Exists.rec H2 H1
/- 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 [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 [recursor 4] [elim] {A : Type} {p : A → Prop} {b : Prop}
(H2 : ∃!x, p x) (H1 : ∀x, p x → (∀y, p y → y = x) → b) : b :=
exists.elim H2 (λ w Hw, H1 w (and.left Hw) (and.right Hw))
theorem exists_unique_of_exists_of_unique {A : Type} {p : A → Prop}
(Hex : ∃ x, p x) (Hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x :=
exists.elim Hex (λ x px, exists_unique.intro x px (take y, suppose p y, Hunique y x this px))
theorem exists_of_exists_unique {A : Type} {p : A → Prop} (H : ∃! x, p x) : ∃ x, p x :=
exists.elim H (λ x Hx, exists.intro x (and.left Hx))
theorem unique_of_exists_unique {A : Type} {p : A → Prop}
(H : ∃! x, p x) {y₁ y₂ : A} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ :=
exists_unique.elim H
(take x, suppose p x,
assume unique : ∀ y, p y → y = x,
show y₁ = y₂, from eq.trans (unique _ py₁) (eq.symm (unique _ py₂)))
/- exists, forall, exists unique congruences -/
section
variables {A : Type} {p₁ p₂ : A → Prop}
theorem forall_congr [congr] {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∀a, P a) ↔ ∀a, Q a :=
iff.intro (λp a, iff.mp (H a) (p a)) (λq a, iff.mpr (H a) (q a))
theorem exists_imp_exists {A : Type} {P Q : A → Prop} (H : ∀a, (P a → Q a)) (p : ∃a, P a) : ∃a, Q a :=
exists.elim p (λa Hp, exists.intro a (H a Hp))
theorem exists_congr [congr] {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∃a, P a) ↔ ∃a, Q a :=
iff.intro
(exists_imp_exists (λa, iff.mp (H a)))
(exists_imp_exists (λa, iff.mpr (H a)))
theorem exists_unique_congr [congr] (H : ∀ x, p₁ x ↔ p₂ x) : (∃! x, p₁ x) ↔ (∃! x, p₂ x) :=
exists_congr (λx, and_congr (H x) (forall_congr (λy, imp_congr (H y) iff.rfl)))
end
/- decidable -/
inductive decidable [class] (p : Prop) : Type :=
| inl : p → decidable p
| inr : ¬p → decidable p
definition decidable_true [instance] : decidable true :=
decidable.inl trivial
definition decidable_false [instance] : decidable false :=
decidable.inr not_false
-- We use "dependent" if-then-else to be able to communicate the if-then-else condition
-- to the branches
definition dite (c : Prop) [H : decidable c] {A : Type} : (c → A) → (¬ c → A) → A :=
decidable.rec_on H
/- if-then-else -/
definition ite (c : Prop) [H : decidable c] {A : Type} (t e : A) : A :=
decidable.rec_on H (λ Hc, t) (λ Hnc, e)
namespace decidable
variables {p q : Prop}
definition rec_on_true [H : decidable p] {H1 : p → Type} {H2 : ¬p → Type} (H3 : p) (H4 : H1 H3)
: decidable.rec_on H H1 H2 :=
decidable.rec_on H (λh, H4) (λh, !false.rec (h H3))
definition rec_on_false [H : decidable p] {H1 : p → Type} {H2 : ¬p → Type} (H3 : ¬p) (H4 : H2 H3)
: decidable.rec_on H H1 H2 :=
decidable.rec_on H (λh, false.rec _ (H3 h)) (λh, H4)
definition by_cases {q : Type} [C : decidable p] : (p → q) → (¬p → q) → q := !dite
theorem em (p : Prop) [decidable p] : p ∨ ¬p := by_cases or.inl or.inr
theorem by_contradiction [decidable p] (H : ¬p → false) : p :=
if H1 : p then H1 else false.rec _ (H H1)
end decidable
section
variables {p q : Prop}
open decidable
definition decidable_of_decidable_of_iff (Hp : decidable p) (H : p ↔ q) : decidable q :=
if Hp : p then inl (iff.mp H Hp)
else inr (iff.mp (not_iff_not_of_iff H) Hp)
definition decidable_of_decidable_of_eq (Hp : decidable p) (H : p = q) : decidable q :=
decidable_of_decidable_of_iff Hp (iff.of_eq H)
protected definition or.by_cases [decidable p] [decidable q] {A : Type}
(h : p ∨ q) (h₁ : p → A) (h₂ : q → A) : A :=
if hp : p then h₁ hp else
if hq : q then h₂ hq else
false.rec _ (or.elim h hp hq)
end
section
variables {p q : Prop}
open decidable (rec_on inl inr)
definition decidable_and [instance] [decidable p] [decidable q] : decidable (p ∧ q) :=
if hp : p then
if hq : q then inl (and.intro hp hq)
else inr (assume H : p ∧ q, hq (and.right H))
else inr (assume H : p ∧ q, hp (and.left H))
definition decidable_or [instance] [decidable p] [decidable q] : decidable (p ∨ q) :=
if hp : p then inl (or.inl hp) else
if hq : q then inl (or.inr hq) else
inr (or.rec hp hq)
definition decidable_not [instance] [decidable p] : decidable (¬p) :=
if hp : p then inr (absurd hp) else inl hp
definition decidable_implies [instance] [decidable p] [decidable q] : decidable (p → q) :=
if hp : p then
if hq : q then inl (assume H, hq)
else inr (assume H : p → q, absurd (H hp) hq)
else inl (assume Hp, absurd Hp hp)
definition decidable_iff [instance] [decidable p] [decidable q] : decidable (p ↔ q) :=
decidable_and
end
definition decidable_pred [reducible] {A : Type} (R : A → Prop) := Π (a : A), decidable (R a)
definition decidable_rel [reducible] {A : Type} (R : A → A → Prop) := Π (a b : A), decidable (R a b)
definition decidable_eq [reducible] (A : Type) := decidable_rel (@eq A)
definition decidable_ne [instance] {A : Type} [decidable_eq A] (a b : A) : decidable (a ≠ b) :=
decidable_implies
namespace bool
theorem ff_ne_tt : ff = tt → false
| [none]
end bool
open bool
definition is_dec_eq {A : Type} (p : A → A → bool) : Prop := ∀ ⦃x y : A⦄, p x y = tt → x = y
definition is_dec_refl {A : Type} (p : A → A → bool) : Prop := ∀x, p x x = tt
open decidable
protected definition bool.has_decidable_eq [instance] : ∀a b : bool, decidable (a = b)
| ff ff := inl rfl
| ff tt := inr ff_ne_tt
| tt ff := inr (ne.symm ff_ne_tt)
| tt tt := inl rfl
definition decidable_eq_of_bool_pred {A : Type} {p : A → A → bool} (H₁ : is_dec_eq p) (H₂ : is_dec_refl p) : decidable_eq A :=
take x y : A, if Hp : p x y = tt then inl (H₁ Hp)
else inr (assume Hxy : x = y, (eq.subst Hxy Hp) (H₂ y))
theorem decidable_eq_inl_refl {A : Type} [H : decidable_eq A] (a : A) : H a a = inl (eq.refl a) :=
match H a a with
| inl e := rfl
| inr n := absurd rfl n
end
open eq.ops
theorem decidable_eq_inr_neg {A : Type} [H : decidable_eq A] {a b : A} : Π n : a ≠ b, H a b = inr n :=
assume n,
match H a b with
| inl e := absurd e n
| inr n₁ := proof_irrel n n₁ ▸ rfl
end
/- inhabited -/
inductive inhabited [class] (A : Type) : Type :=
mk : A → inhabited A
protected definition inhabited.value {A : Type} : inhabited A → A :=
inhabited.rec (λa, a)
protected definition inhabited.destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A → B) : B :=
inhabited.rec H2 H1
definition default (A : Type) [H : inhabited A] : A :=
inhabited.value H
definition arbitrary [irreducible] (A : Type) [H : inhabited A] : A :=
inhabited.value H
definition Prop.is_inhabited [instance] : inhabited Prop :=
inhabited.mk true
definition inhabited_fun [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) :=
inhabited.rec_on H (λb, inhabited.mk (λa, b))
definition inhabited_Pi [instance] (A : Type) {B : A → Type} [Πx, inhabited (B x)] :
inhabited (Πx, B x) :=
inhabited.mk (λa, !default)
protected definition bool.is_inhabited [instance] : inhabited bool :=
inhabited.mk ff
protected definition pos_num.is_inhabited [instance] : inhabited pos_num :=
inhabited.mk pos_num.one
protected definition num.is_inhabited [instance] : inhabited num :=
inhabited.mk num.zero
inductive nonempty [class] (A : Type) : Prop :=
intro : A → nonempty A
protected definition nonempty.elim {A : Type} {B : Prop} (H1 : nonempty A) (H2 : A → B) : B :=
nonempty.rec H2 H1
theorem nonempty_of_inhabited [instance] {A : Type} [inhabited A] : nonempty A :=
nonempty.intro !default
theorem nonempty_of_exists {A : Type} {P : A → Prop} : (∃x, P x) → nonempty A :=
Exists.rec (λw H, nonempty.intro w)
/- subsingleton -/
inductive subsingleton [class] (A : Type) : Prop :=
intro : (∀ a b : A, a = b) → subsingleton A
protected definition subsingleton.elim {A : Type} [H : subsingleton A] : ∀(a b : A), a = b :=
subsingleton.rec (λp, p) H
definition subsingleton_prop [instance] (p : Prop) : subsingleton p :=
subsingleton.intro (λa b, !proof_irrel)
definition subsingleton_decidable [instance] (p : Prop) : subsingleton (decidable p) :=
subsingleton.intro (λ d₁,
match d₁ with
| inl t₁ := (λ d₂,
match d₂ with
| inl t₂ := eq.rec_on (proof_irrel t₁ t₂) rfl
| inr f₂ := absurd t₁ f₂
end)
| inr f₁ := (λ d₂,
match d₂ with
| inl t₂ := absurd t₂ f₁
| inr f₂ := eq.rec_on (proof_irrel f₁ f₂) rfl
end)
end)
protected theorem rec_subsingleton {p : Prop} [H : decidable p]
{H1 : p → Type} {H2 : ¬p → Type}
[H3 : Π(h : p), subsingleton (H1 h)] [H4 : Π(h : ¬p), subsingleton (H2 h)]
: subsingleton (decidable.rec_on H H1 H2) :=
decidable.rec_on H (λh, H3 h) (λh, H4 h) --this can be proven using dependent version of "by_cases"
theorem if_pos {c : Prop} [H : decidable c] (Hc : c) {A : Type} {t e : A} : (ite c t e) = t :=
decidable.rec
(λ Hc : c, eq.refl (@ite c (decidable.inl Hc) A t e))
(λ Hnc : ¬c, absurd Hc Hnc)
H
theorem if_neg {c : Prop} [H : decidable c] (Hnc : ¬c) {A : Type} {t e : A} : (ite c t e) = e :=
decidable.rec
(λ Hc : c, absurd Hc Hnc)
(λ Hnc : ¬c, eq.refl (@ite c (decidable.inr Hnc) A t e))
H
theorem if_t_t [simp] (c : Prop) [H : decidable c] {A : Type} (t : A) : (ite c t t) = t :=
decidable.rec
(λ Hc : c, eq.refl (@ite c (decidable.inl Hc) A t t))
(λ Hnc : ¬c, eq.refl (@ite c (decidable.inr Hnc) A t t))
H
theorem implies_of_if_pos {c t e : Prop} [decidable c] (h : ite c t e) : c → t :=
assume Hc, eq.rec_on (if_pos Hc) h
theorem implies_of_if_neg {c t e : Prop} [decidable c] (h : ite c t e) : ¬c → e :=
assume Hnc, eq.rec_on (if_neg Hnc) h
theorem if_ctx_congr {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x y u v : A}
(h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) :
ite b x y = ite c u v :=
decidable.rec_on dec_b
(λ hp : b, calc
ite b x y = x : if_pos hp
... = u : h_t (iff.mp h_c hp)
... = ite c u v : if_pos (iff.mp h_c hp))
(λ hn : ¬b, calc
ite b x y = y : if_neg hn
... = v : h_e (iff.mp (not_iff_not_of_iff h_c) hn)
... = ite c u v : if_neg (iff.mp (not_iff_not_of_iff h_c) hn))
theorem if_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x y u v : A}
(h_c : b ↔ c) (h_t : x = u) (h_e : y = v) :
ite b x y = ite c u v :=
@if_ctx_congr A b c dec_b dec_c x y u v h_c (λ h, h_t) (λ h, h_e)
theorem if_ctx_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A}
(h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) :
ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=
@if_ctx_congr A b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x y u v h_c h_t h_e
theorem if_simp_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A}
(h_c : b ↔ c) (h_t : x = u) (h_e : y = v) :
ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=
@if_ctx_simp_congr A b c dec_b x y u v h_c (λ h, h_t) (λ h, h_e)
definition if_true [simp] {A : Type} (t e : A) : (if true then t else e) = t :=
if_pos trivial
definition if_false [simp] {A : Type} (t e : A) : (if false then t else e) = e :=
if_neg not_false
theorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]
(h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) :
ite b x y ↔ ite c u v :=
decidable.rec_on dec_b
(λ hp : b, calc
ite b x y ↔ x : iff.of_eq (if_pos hp)
... ↔ u : h_t (iff.mp h_c hp)
... ↔ ite c u v : iff.of_eq (if_pos (iff.mp h_c hp)))
(λ hn : ¬b, calc
ite b x y ↔ y : iff.of_eq (if_neg hn)
... ↔ v : h_e (iff.mp (not_iff_not_of_iff h_c) hn)
... ↔ ite c u v : iff.of_eq (if_neg (iff.mp (not_iff_not_of_iff h_c) hn)))
theorem if_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]
(h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) :
ite b x y ↔ ite c u v :=
if_ctx_congr_prop h_c (λ h, h_t) (λ h, h_e)
theorem if_ctx_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b]
(h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) :
ite b x y ↔ (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) :=
@if_ctx_congr_prop b c x y u v dec_b (decidable_of_decidable_of_iff dec_b h_c) h_c h_t h_e
theorem if_simp_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b]
(h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) :
ite b x y ↔ (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) :=
@if_ctx_simp_congr_prop b c x y u v dec_b h_c (λ h, h_t) (λ h, h_e)
theorem dif_pos {c : Prop} [H : decidable c] (Hc : c) {A : Type} {t : c → A} {e : ¬ c → A} : dite c t e = t Hc :=
decidable.rec
(λ Hc : c, eq.refl (@dite c (decidable.inl Hc) A t e))
(λ Hnc : ¬c, absurd Hc Hnc)
H
theorem dif_neg {c : Prop} [H : decidable c] (Hnc : ¬c) {A : Type} {t : c → A} {e : ¬ c → A} : dite c t e = e Hnc :=
decidable.rec
(λ Hc : c, absurd Hc Hnc)
(λ Hnc : ¬c, eq.refl (@dite c (decidable.inr Hnc) A t e))
H
theorem dif_ctx_congr {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x : b → A} {u : c → A} {y : ¬b → A} {v : ¬c → A}
(h_c : b ↔ c)
(h_t : ∀ (h : c), x (iff.mpr h_c h) = u h)
(h_e : ∀ (h : ¬c), y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :
(@dite b dec_b A x y) = (@dite c dec_c A u v) :=
decidable.rec_on dec_b
(λ hp : b, calc
dite b x y = x hp : dif_pos hp
... = x (iff.mpr h_c (iff.mp h_c hp)) : proof_irrel
... = u (iff.mp h_c hp) : h_t
... = dite c u v : dif_pos (iff.mp h_c hp))
(λ hn : ¬b, let h_nc : ¬b ↔ ¬c := not_iff_not_of_iff h_c in calc
dite b x y = y hn : dif_neg hn
... = y (iff.mpr h_nc (iff.mp h_nc hn)) : proof_irrel
... = v (iff.mp h_nc hn) : h_e
... = dite c u v : dif_neg (iff.mp h_nc hn))
theorem dif_ctx_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b]
{x : b → A} {u : c → A} {y : ¬b → A} {v : ¬c → A}
(h_c : b ↔ c)
(h_t : ∀ (h : c), x (iff.mpr h_c h) = u h)
(h_e : ∀ (h : ¬c), y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :
(@dite b dec_b A x y) = (@dite c (decidable_of_decidable_of_iff dec_b h_c) A u v) :=
@dif_ctx_congr A b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x u y v h_c h_t h_e
-- Remark: dite and ite are "definitionally equal" when we ignore the proofs.
theorem dite_ite_eq (c : Prop) [decidable c] {A : Type} (t : A) (e : A) : dite c (λh, t) (λh, e) = ite c t e :=
rfl
definition is_true (c : Prop) [decidable c] : Prop :=
if c then true else false
definition is_false (c : Prop) [decidable c] : Prop :=
if c then false else true
definition of_is_true {c : Prop} [H₁ : decidable c] (H₂ : is_true c) : c :=
decidable.rec_on H₁ (λ Hc, Hc) (λ Hnc, !false.rec (if_neg Hnc ▸ H₂))
notation `dec_trivial` := of_is_true trivial
theorem not_of_not_is_true {c : Prop} [decidable c] (H : ¬ is_true c) : ¬ c :=
if Hc : c then absurd trivial (if_pos Hc ▸ H) else Hc
theorem not_of_is_false {c : Prop} [decidable c] (H : is_false c) : ¬ c :=
if Hc : c then !false.rec (if_pos Hc ▸ H) else Hc
theorem of_not_is_false {c : Prop} [decidable c] (H : ¬ is_false c) : c :=
if Hc : c then Hc else absurd trivial (if_neg Hc ▸ H)
-- The following symbols should not be considered in the pattern inference procedure used by
-- heuristic instantiation.
attribute and or not iff ite dite eq ne heq [no_pattern]
-- namespace used to collect congruence rules for "contextual simplification"
namespace contextual
attribute if_ctx_simp_congr [congr]
attribute if_ctx_simp_congr_prop [congr]
attribute dif_ctx_simp_congr [congr]
end contextual
|
36e3acee469d4ca3071161a54620d163d47d6ad5 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0304.lean | f693172e43c7cf33a767b8726610eba340ebcac3 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 144 | lean | example (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=
begin
intro h,
cases h with x hpx,
constructor, left, exact hpx
end
|
aaccf89aa4ab20ebeb52fd68847ab51d605dde8f | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /stage0/src/Lean/Server/FileWorker.lean | 8d2f0bd24d88098ee66fb18b229568bf67168386 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 21,649 | lean | /-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga, Wojciech Nawrocki
-/
import Init.System.IO
import Std.Data.RBMap
import Lean.Environment
import Lean.PrettyPrinter
import Lean.Data.Lsp
import Lean.Data.Json.FromToJson
import Lean.Server.Snapshots
import Lean.Server.Utils
import Lean.Server.AsyncList
/-!
For general server architecture, see `README.md`. For details of IPC communication, see `Watchdog.lean`.
This module implements per-file worker processes.
File processing and requests+notifications against a file should be concurrent for two reasons:
- By the LSP standard, requests should be cancellable.
- Since Lean allows arbitrary user code to be executed during elaboration via the tactic framework,
elaboration can be extremely slow and even not halt in some cases. Users should be able to
work with the file while this is happening, e.g. make new changes to the file or send requests.
To achieve these goals, elaboration is executed in a chain of tasks, where each task corresponds to
the elaboration of one command. When the elaboration of one command is done, the next task is spawned.
On didChange notifications, we search for the task in which the change occured. If we stumble across
a task that has not yet finished before finding the task we're looking for, we terminate it
and start the elaboration there, otherwise we start the elaboration at the task where the change occured.
Requests iterate over tasks until they find the command that they need to answer the request.
In order to not block the main thread, this is done in a request task.
If a task that the request task waits for is terminated, a change occured somewhere before the
command that the request is looking for and the request sends a "content changed" error.
-/
namespace Lean.Server.FileWorker
open Lsp
open IO
open Snapshots
open Lean.Parser.Command
section Utils
private def logSnapContent (s : Snapshot) (text : FileMap) : IO Unit :=
IO.eprintln s!"[{s.beginPos}, {s.endPos}]: `{text.source.extract s.beginPos (s.endPos-1)}`"
inductive TaskError where
| aborted
| eof
| ioError (e : IO.Error)
instance : Coe IO.Error TaskError := ⟨TaskError.ioError⟩
structure CancelToken where
ref : IO.Ref Bool
deriving Inhabited
namespace CancelToken
def new : IO CancelToken :=
CancelToken.mk <$> IO.mkRef false
def check [MonadExceptOf TaskError m] [MonadLiftT (ST RealWorld) m] [Monad m] (tk : CancelToken) : m Unit := do
let c ← tk.ref.get
if c = true then
throw TaskError.aborted
def set (tk : CancelToken) : IO Unit :=
tk.ref.set true
end CancelToken
/-- A document editable in the sense that we track the environment
and parser state after each command so that edits can be applied
without recompiling code appearing earlier in the file. -/
structure EditableDocument where
meta : DocumentMeta
/- The first snapshot is that after the header. -/
headerSnap : Snapshot
/- Subsequent snapshots occur after each command. -/
cmdSnaps : AsyncList TaskError Snapshot
cancelTk : CancelToken
deriving Inhabited
end Utils
open IO
open Std (RBMap RBMap.empty)
open JsonRpc
section ServerM
-- Pending requests are tracked so they can be cancelled
abbrev PendingRequestMap := RBMap RequestID (Task (Except IO.Error Unit)) (fun a b => Decidable.decide (a < b))
structure ServerContext where
hIn : FS.Stream
hOut : FS.Stream
docRef : IO.Ref EditableDocument
pendingRequestsRef : IO.Ref PendingRequestMap
abbrev ServerM := ReaderT ServerContext IO
def updatePendingRequests (map : PendingRequestMap → PendingRequestMap) : ServerM Unit := do
(←read).pendingRequestsRef.modify map
/-- Elaborates the next command after `parentSnap` and emits diagnostics. -/
private def nextCmdSnap (m : DocumentMeta) (parentSnap : Snapshot) (cancelTk : CancelToken) : ExceptT TaskError ServerM Snapshot := do
cancelTk.check
let st ← read
let maybeSnap ← compileNextCmd m.text.source parentSnap
cancelTk.check
let sendDiagnostics (msgLog : MessageLog) : IO Unit := do
let diagnostics ← msgLog.msgs.mapM (msgToDiagnostic m.text)
st.hOut.writeLspNotification {
method := "textDocument/publishDiagnostics"
param := {
uri := m.uri
version? := m.version
diagnostics := diagnostics.toArray
: PublishDiagnosticsParams
}
}
match maybeSnap with
| Sum.inl snap =>
/- NOTE(MH): This relies on the client discarding old diagnostics upon receiving new ones
while prefering newer versions over old ones. The former is necessary because we do
not explicitly clear older diagnostics, while the latter is necessary because we do
not guarantee that diagnostics are emitted in order. Specifically, it may happen that
we interrupted this elaboration task right at this point and a newer elaboration task
emits diagnostics, after which we emit old diagnostics because we did not yet detect
the interrupt. Explicitly clearing diagnostics is difficult for a similar reason,
because we cannot guarantee that no further diagnostics are emitted after clearing
them. -/
sendDiagnostics <| snap.msgLog.add {
fileName := "<ignored>"
pos := m.text.toPosition snap.endPos
severity := MessageSeverity.information
data := "processing..."
}
snap
| Sum.inr msgLog =>
sendDiagnostics msgLog
throw TaskError.eof
/-- Elaborates all commands after `initSnap`, emitting the diagnostics. -/
def unfoldCmdSnaps (m : DocumentMeta) (initSnap : Snapshot) (cancelTk : CancelToken) : ServerM (AsyncList TaskError Snapshot) := do
-- TODO(MH): check for interrupt with increased precision
AsyncList.unfoldAsync (nextCmdSnap m . cancelTk (←read)) initSnap (some fun _ => pure TaskError.aborted)
/-- Compiles the contents of a Lean file. -/
def compileDocument (m : DocumentMeta) : ServerM Unit := do
let headerSnap@⟨_, _, _, SnapshotData.headerData env msgLog opts⟩ ← Snapshots.compileHeader m.text.source
| throwServerError "Internal server error: invalid header snapshot"
let cancelTk ← CancelToken.new
let cmdSnaps ← unfoldCmdSnaps m headerSnap cancelTk
(←read).docRef.set ⟨m, headerSnap, cmdSnaps, cancelTk⟩
/-- Given the new document and `changePos`, the UTF-8 offset of a change into the pre-change source,
updates editable doc state. -/
def updateDocument (newMeta : DocumentMeta) (changePos : String.Pos) : ServerM Unit := do
-- The watchdog only restarts the file worker when the syntax tree of the header changes.
-- If e.g. a newline is deleted, it will not restart this file worker, but we still
-- need to reparse the header so that the offsets are correct.
let st ← read
let oldDoc ← st.docRef.get
let newHeaderSnap ← reparseHeader newMeta.text.source oldDoc.headerSnap
if newHeaderSnap.stx != oldDoc.headerSnap.stx then
throwServerError "Internal server error: header changed but worker wasn't restarted."
let ⟨cmdSnaps, e?⟩ ← oldDoc.cmdSnaps.updateFinishedPrefix
match e? with
-- This case should not be possible. only the main task aborts tasks and ensures that aborted tasks
-- do not show up in `snapshots` of an EditableDocument.
| some TaskError.aborted =>
throwServerError "Internal server error: elab task was aborted while still in use."
| some (TaskError.ioError ioError) => throw ioError
| _ => -- No error or EOF
oldDoc.cancelTk.set
-- NOTE(WN): we invalidate eagerly as `endPos` consumes input greedily. To re-elaborate only
-- when really necessary, we could do a whitespace-aware `Syntax` comparison instead.
let mut validSnaps := cmdSnaps.finishedPrefix.takeWhile (fun s => s.endPos < changePos)
if validSnaps.length = 0 then
let cancelTk ← CancelToken.new
let newCmdSnaps ← unfoldCmdSnaps newMeta newHeaderSnap cancelTk
st.docRef.set ⟨newMeta, newHeaderSnap, newCmdSnaps, cancelTk⟩
else
/- When at least one valid non-header snap exists, it may happen that a change does not fall
within the syntactic range of that last snap but still modifies it by appending tokens.
We check for this here. We do not currently handle crazy grammars in which an appended
token can merge two or more previous commands into one. To do so would require reparsing
the entire file. -/
let mut lastSnap := validSnaps.getLast!
let preLastSnap :=
if validSnaps.length ≥ 2
then validSnaps.get! (validSnaps.length - 2)
else newHeaderSnap
let newLastStx ← parseNextCmd newMeta.text.source preLastSnap
if newLastStx != lastSnap.stx then
validSnaps ← validSnaps.dropLast
lastSnap ← preLastSnap
let cancelTk ← CancelToken.new
let newSnaps ← unfoldCmdSnaps newMeta lastSnap cancelTk
let newCmdSnaps := AsyncList.ofList validSnaps ++ newSnaps
st.docRef.set ⟨newMeta, newHeaderSnap, newCmdSnaps, cancelTk⟩
end ServerM
/- Notifications are handled in the main thread. They may change global worker state
such as the current file contents. -/
section NotificationHandling
def handleDidOpen (p : DidOpenTextDocumentParams) : ServerM Unit :=
let doc := p.textDocument
/- NOTE(WN): `toFileMap` marks line beginnings as immediately following
"\n", which should be enough to handle both LF and CRLF correctly.
This is because LSP always refers to characters by (line, column),
so if we get the line number correct it shouldn't matter that there
is a CR there. -/
compileDocument ⟨doc.uri, doc.version, doc.text.toFileMap⟩
def handleDidChange (p : DidChangeTextDocumentParams) : ServerM Unit := do
let docId := p.textDocument
let changes := p.contentChanges
let oldDoc ← (←read).docRef.get
let some newVersion ← pure docId.version?
| throwServerError "Expected version number"
if newVersion ≤ oldDoc.meta.version then
-- TODO(WN): This happens on restart sometimes.
IO.eprintln s!"Got outdated version number: {newVersion} ≤ {oldDoc.meta.version}"
else if ¬ changes.isEmpty then
let (newDocText, minStartOff) := foldDocumentChanges changes oldDoc.meta.text
updateDocument ⟨docId.uri, newVersion, newDocText⟩ minStartOff
-- TODO(WN): cancel pending requests?
def handleCancelRequest (p : CancelParams) : ServerM Unit := do
updatePendingRequests (fun pendingRequests => pendingRequests.erase p.id)
end NotificationHandling
/- Request handlers are given by `Task`s executed asynchronously. They may be cancelled at any time,
so they should check the cancellation token when possible to handle this cooperatively. Any exceptions
thrown in a handler will be reported to the client as LSP error responses. -/
section RequestHandling
structure RequestError where
code : ErrorCode
message : String
-- TODO(WN): the type is too complicated
abbrev RequestM α := ServerM $ Task $ Except IO.Error $ Except RequestError α
/- Requests that need data from a certain command should traverse the snapshots
by successively getting the next task, meaning that we might need to wait for elaboration.
When that happens, the request should send a "content changed" error to the user
(this way, the server doesn't get bogged down in requests for an old state of the document).
Requests need to manually check for whether their task has been cancelled, so that they
can reply with a RequestCancelled error. -/
partial def handleHover (id : RequestID) (p : HoverParams)
: ServerM (Task (Except IO.Error (Except RequestError (Option Hover)))) := do
let doc ← (←read).docRef.get
let text := doc.meta.text
let hoverPos := text.lspPosToUtf8Pos p.position
let findTask ← doc.cmdSnaps.waitFind? (fun s => s.endPos > hoverPos)
let mkHover (s : String) (f : String.Pos) (t : String.Pos) : Hover :=
{ contents := { kind := MarkupKind.plaintext
value := s }
range? := some { start := text.utf8PosToLspPos f
«end» := text.utf8PosToLspPos t } }
(IO.mapTask · findTask) fun
| Except.error TaskError.aborted =>
pure $ Except.error { code := ErrorCode.contentModified, message := "File changed." }
| Except.error (TaskError.ioError e) =>
throwThe IO.Error e
| Except.error TaskError.eof =>
pure $ Except.ok none
| Except.ok (some snap) => do
/- TODO: FIX -/
let mut infoRanges : Array (Nat × String.Pos × String.Pos × Expr) := #[]
for t in snap.toCmdState.infoState.trees do
/-
if let Elab.InfoTree.ofTermInfo i := t then
match i.stx.getPos, i.stx.getTailPos with
| some pos, some endPos =>
if pos ≤ hoverPos ∧ hoverPos ≤ endPos then
infoRanges := infoRanges.push (endPos - pos, pos, endPos, i.e)
| _, _ => pure ()
-/
pure ()
match infoRanges.getMax? fun a b => a.1 > b.1 with
| some (_, pos, endPos, e) =>
--st.hLog.putStrLn s!"Picked from {infoRanges.size}"
return (Except.ok $ some $ mkHover (toString e) pos endPos
-- Type inference fails
: Except RequestError _)
| none => pure ()
return Except.ok none
| Except.ok none => return Except.ok none
def handleWaitForDiagnostics (id : RequestID) (p : WaitForDiagnosticsParam)
: ServerM (Task (Except IO.Error (Except RequestError WaitForDiagnostics))) := do
let st ← read
let e ← st.docRef.get
let t ← e.cmdSnaps.waitAll
t.map fun _ => Except.ok $ Except.ok WaitForDiagnostics.mk
def rangeOfSyntax (text : FileMap) (stx : Syntax) : Range :=
⟨text.utf8PosToLspPos <| stx.getHeadInfo.get!.pos.get!,
text.utf8PosToLspPos <| stx.getTailPos.get!⟩
partial def handleDocumentSymbol (id : RequestID) (p : DocumentSymbolParams) :
ServerM (Task (Except IO.Error (Except RequestError DocumentSymbolResult))) := do
let st ← read
asTask do
let doc ← st.docRef.get
let ⟨cmdSnaps, end?⟩ ← doc.cmdSnaps.updateFinishedPrefix
let mut stxs := cmdSnaps.finishedPrefix.map (·.stx)
if end?.isNone then
let lastSnap := cmdSnaps.finishedPrefix.getLastD doc.headerSnap
stxs := stxs ++ (← parseAhead doc.meta.text.source lastSnap).toList
let (syms, _) := toDocumentSymbols doc.meta.text stxs
return Except.ok { syms := syms.toArray }
where
toDocumentSymbols (text : FileMap)
| [] => ([], [])
| stx::stxs => match stx with
| `(namespace $id) => sectionLikeToDocumentSymbols text stx stxs (id.getId.toString) SymbolKind.namespace id
| `(section $(id)?) => sectionLikeToDocumentSymbols text stx stxs ((·.getId.toString) <$> id |>.getD "<section>") SymbolKind.namespace (id.getD stx)
| `(end $(id)?) => ([], stx::stxs)
| _ =>
let (syms, stxs') := toDocumentSymbols text stxs
if stx.isOfKind ``Lean.Parser.Command.declaration then
let (name, selection) := match stx with
| `($dm:declModifiers $ak:attrKind instance $[$np:namedPrio]? $[$id:ident$[.{$ls,*}]?]? $sig:declSig $val) =>
((·.getId.toString) <$> id |>.getD s!"instance {sig.reprint.getD ""}", id.getD sig)
| _ => match stx[1][1] with
| `(declId|$id:ident$[.{$ls,*}]?) => (id.getId.toString, id)
| _ => (stx[1][0].isIdOrAtom?.getD "<unknown>", stx[1][0])
(DocumentSymbol.mk {
name := name
kind := SymbolKind.method
range := rangeOfSyntax text stx
selectionRange := rangeOfSyntax text selection
} :: syms, stxs')
else
(syms, stxs')
sectionLikeToDocumentSymbols (text : FileMap) (stx : Syntax) (stxs : List Syntax) (name : String) (kind : SymbolKind) (selection : Syntax) :=
let (syms, stxs') := toDocumentSymbols text stxs
-- discard `end`
let (syms', stxs'') := toDocumentSymbols text (stxs'.drop 1)
let endStx := match stxs' with
| endStx::_ => endStx
| [] => (stx::stxs').getLast!
(DocumentSymbol.mk {
name := name
kind := kind
range := ⟨(rangeOfSyntax text stx).start, (rangeOfSyntax text endStx).«end»⟩
selectionRange := rangeOfSyntax text selection
children? := syms.toArray
} :: syms', stxs'')
end RequestHandling
section MessageHandling
def parseParams (paramType : Type) [FromJson paramType] (params : Json) : ServerM paramType :=
match fromJson? params with
| some parsed => pure parsed
| none => throwServerError s!"Got param with wrong structure: {params.compress}"
def handleNotification (method : String) (params : Json) : ServerM Unit := do
let handle := fun paramType [FromJson paramType] (handler : paramType → ServerM Unit) =>
parseParams paramType params >>= handler
match method with
| "textDocument/didChange" => handle DidChangeTextDocumentParams handleDidChange
| "$/cancelRequest" => handle CancelParams handleCancelRequest
| _ => throwServerError s!"Got unsupported notification method: {method}"
def queueRequest (id : RequestID) (requestTask : Task (Except IO.Error Unit))
: ServerM Unit := do
updatePendingRequests (fun pendingRequests => pendingRequests.insert id requestTask)
def handleRequest (id : RequestID) (method : String) (params : Json)
: ServerM Unit := do
let handle := fun paramType [FromJson paramType] respType [ToJson respType]
(handler : RequestID → paramType → RequestM respType) => do
let st ← read
let p ← parseParams paramType params
let t ← handler id p
let t₁ ← (IO.mapTask · t) fun
| Except.ok (Except.ok resp) =>
st.hOut.writeLspResponse ⟨id, resp⟩
| Except.ok (Except.error e) =>
st.hOut.writeLspResponseError { id := id, code := e.code, message := e.message }
| Except.error e =>
st.hOut.writeLspResponseError { id := id, code := ErrorCode.internalError, message := toString e }
queueRequest id t₁
match method with
| "textDocument/waitForDiagnostics" => handle WaitForDiagnosticsParam WaitForDiagnostics handleWaitForDiagnostics
| "textDocument/hover" => handle HoverParams (Option Hover) handleHover
| "textDocument/documentSymbol" => handle DocumentSymbolParams DocumentSymbolResult handleDocumentSymbol
| _ => throwServerError s!"Got unsupported request: {method}"
end MessageHandling
section MainLoop
partial def mainLoop : ServerM Unit := do
let st ← read
let msg ← st.hIn.readLspMessage
let pendingRequests ← st.pendingRequestsRef.get
let filterFinishedTasks (acc : PendingRequestMap) (id : RequestID) (task : Task (Except IO.Error Unit))
: ServerM PendingRequestMap := do
if (←hasFinished task) then
/- Handler tasks are constructed so that the only possible errors here
are failures of writing a response into the stream. -/
if let Except.error e := task.get then
throwServerError s!"Failed responding to request {id}: {e}"
acc.erase id
else acc
let pendingRequests ← pendingRequests.foldM filterFinishedTasks pendingRequests
st.pendingRequestsRef.set pendingRequests
match msg with
| Message.request id method (some params) =>
handleRequest id method (toJson params)
mainLoop
| Message.notification "exit" none =>
-- should be sufficient to shut down the file worker.
-- references are lost => tasks are marked as cancelled
-- => all tasks eventually quit
()
| Message.notification method (some params) =>
handleNotification method (toJson params)
mainLoop
| _ => throwServerError "Got invalid JSON-RPC message"
end MainLoop
def initAndRunWorker (i o e : FS.Stream) : IO Unit := do
let i ← maybeTee "fwIn.txt" false i
let o ← maybeTee "fwOut.txt" true o
-- TODO(WN): act in accordance with InitializeParams
let _ ← i.readLspRequestAs "initialize" InitializeParams
let ⟨_, param⟩ ← i.readLspNotificationAs "textDocument/didOpen" DidOpenTextDocumentParams
let e ← e.withPrefix s!"[{param.textDocument.uri}] "
let _ ← IO.setStderr e
let ctx : ServerContext := {
hIn := i
hOut := o
-- `openDocument` will not access `docRef`, but set it
docRef := ←IO.mkRef arbitrary
pendingRequestsRef := ←IO.mkRef (RBMap.empty : PendingRequestMap)
}
ReaderT.run (do handleDidOpen param; mainLoop) ctx
@[export lean_server_worker_main]
def workerMain : IO UInt32 := do
let i ← IO.getStdin
let o ← IO.getStdout
let e ← IO.getStderr
try
initAndRunWorker i o e
return 0
catch err =>
e.putStrLn s!"Worker error: {err}"
return 1
end Lean.Server.FileWorker
|
41716e6e96f09886f48da595293f5a105d2527e7 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/monotonicity/basic.lean | 01f8924d87afb56c5e57715550a299d0481c13a1 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 5,453 | lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import order.bounded_lattice
namespace tactic.interactive
open tactic list
open lean lean.parser interactive
open interactive.types
@[derive inhabited]
structure mono_cfg :=
(unify := ff)
@[derive [decidable_eq, has_reflect, inhabited]]
inductive mono_selection : Type
| left : mono_selection
| right : mono_selection
| both : mono_selection
declare_trace mono.relation
section compare
parameter opt : mono_cfg
meta def compare (e₀ e₁ : expr) : tactic unit := do
if opt.unify then do
guard (¬ e₀.is_mvar ∧ ¬ e₁.is_mvar),
unify e₀ e₁
else is_def_eq e₀ e₁
meta def find_one_difference
: list expr → list expr → tactic (list expr × expr × expr × list expr)
| (x :: xs) (y :: ys) :=
do c ← try_core (compare x y),
if c.is_some
then prod.map (cons x) id <$> find_one_difference xs ys
else do
guard (xs.length = ys.length),
mzip_with' compare xs ys,
return ([],x,y,xs)
| xs ys := fail format!"find_one_difference: {xs}, {ys}"
end compare
def last_two {α : Type*} (l : list α) : option (α × α) :=
match l.reverse with
| (x₁ :: x₀ :: _) := some (x₀, x₁)
| _ := none
end
meta def match_imp : expr → tactic (expr × expr)
| `(%%e₀ → %%e₁) :=
do guard (¬ e₁.has_var),
return (e₀,e₁)
| _ := failed
open expr
meta def same_operator : expr → expr → bool
| (app e₀ _) (app e₁ _) :=
let fn₀ := e₀.get_app_fn,
fn₁ := e₁.get_app_fn in
fn₀.is_constant ∧ fn₀.const_name = fn₁.const_name
| (pi _ _ _ _) (pi _ _ _ _) := tt
| _ _ := ff
meta def get_operator (e : expr) : option name :=
guard (¬ e.is_pi) >> pure e.get_app_fn.const_name
meta def monotonicity.check_rel (l r : expr) : tactic (option name) :=
do guard (same_operator l r) <|>
do { fail format!"{l} and {r} should be the f x and f y for some f" },
if l.is_pi then pure none
else pure r.get_app_fn.const_name
@[reducible]
def mono_key := (with_bot name × with_bot name)
open nat
meta def mono_head_candidates : ℕ → list expr → expr → tactic mono_key
| 0 _ h := fail!"Cannot find relation in {h}"
| (succ n) xs h :=
do { (rel,l,r) ← if h.is_arrow
then pure (none,h.binding_domain,h.binding_body)
else guard h.get_app_fn.is_constant >>
prod.mk (some h.get_app_fn.const_name) <$> last_two h.get_app_args,
prod.mk <$> monotonicity.check_rel l r <*> pure rel } <|>
match xs with
| [] := fail format!"oh? {h}"
| (x::xs) := mono_head_candidates n xs (h.pis [x])
end
meta def monotonicity.check (lm_n : name) : tactic mono_key :=
do lm ← mk_const lm_n,
lm_t ← infer_type lm >>= instantiate_mvars,
when_tracing `mono.relation trace!"[mono] Looking for relation in {lm_t}",
let s := simp_lemmas.mk,
s ← s.add_simp ``monotone,
s ← s.add_simp ``strict_mono,
lm_t ← s.dsimplify [] lm_t { fail_if_unchanged := ff },
when_tracing `mono.relation trace!"[mono] Looking for relation in {lm_t} (after unfolding)",
(xs,h) ← open_pis lm_t,
mono_head_candidates 3 xs.reverse h
meta instance : has_to_format mono_selection :=
⟨ λ x, match x with
| mono_selection.left := "left"
| mono_selection.right := "right"
| mono_selection.both := "both"
end ⟩
meta def side : lean.parser mono_selection :=
with_desc "expecting 'left', 'right' or 'both' (default)" $
do some n ← optional ident | pure mono_selection.both,
if n = `left then pure $ mono_selection.left
else if n = `right then pure $ mono_selection.right
else if n = `both then pure $ mono_selection.both
else fail format!"invalid argument: {n}, expecting 'left', 'right' or 'both' (default)"
open function
@[user_attribute]
meta def monotonicity.attr : user_attribute
(native.rb_lmap mono_key (name))
(option mono_key × mono_selection) :=
{ name := `mono
, descr := "monotonicity of function `f` wrt relations `R₀` and `R₁`: R₀ x y → R₁ (f x) (f y)"
, cache_cfg :=
{ dependencies := [],
mk_cache := λ ls,
do ps ← ls.mmap monotonicity.attr.get_param,
let ps := ps.filter_map prod.fst,
pure $ (ps.zip ls).foldl
(flip $ uncurry (λ k n m, m.insert k n))
(native.rb_lmap.mk mono_key _) }
, after_set := some $ λ n prio p,
do { (none,v) ← monotonicity.attr.get_param n | pure (),
k ← monotonicity.check n,
monotonicity.attr.set n (some k,v) p }
, parser := prod.mk none <$> side }
meta def filter_instances (e : mono_selection) (ns : list name) : tactic (list name) :=
ns.mfilter $ λ n,
do d ← user_attribute.get_param_untyped monotonicity.attr n,
(_,d) ← to_expr ``(id %%d) >>= eval_expr (option mono_key × mono_selection),
return (e = d : bool)
meta def get_monotonicity_lemmas (k : expr) (e : mono_selection) : tactic (list name) :=
do ns ← monotonicity.attr.get_cache,
k' ← if k.is_pi
then pure (get_operator k.binding_domain,none)
else do { (x₀,x₁) ← last_two k.get_app_args,
pure (get_operator x₀,some k.get_app_fn.const_name) },
let ns := ns.find_def [] k',
ns' ← filter_instances e ns,
if e ≠ mono_selection.both then (++) ns' <$> filter_instances mono_selection.both ns
else pure ns'
end tactic.interactive
|
e3ce8fd6352820b57072259fbca8b85515e04a9e | aa5a655c05e5359a70646b7154e7cac59f0b4132 | /src/Lean/Data/Name.lean | d946794d32a16454240056442a9f751145862cda | [
"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 | 5,512 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Std.Data.HashSet
import Std.Data.RBMap
import Std.Data.RBTree
namespace Lean
instance : Coe String Name := ⟨Name.mkSimple⟩
namespace Name
@[export lean_name_hash] def hashEx : Name → USize :=
Name.hash
def getPrefix : Name → Name
| anonymous => anonymous
| str p s _ => p
| num p s _ => p
def getRoot : Name → Name
| anonymous => anonymous
| n@(str anonymous _ _) => n
| n@(num anonymous _ _) => n
| str n _ _ => getRoot n
| num n _ _ => getRoot n
def getString! : Name → String
| str _ s _ => s
| _ => unreachable!
def getNumParts : Name → Nat
| anonymous => 0
| str p _ _ => getNumParts p + 1
| num p _ _ => getNumParts p + 1
def updatePrefix : Name → Name → Name
| anonymous, newP => anonymous
| str p s _, newP => Name.mkStr newP s
| num p s _, newP => Name.mkNum newP s
def components' : Name → List Name
| anonymous => []
| str n s _ => Name.mkStr anonymous s :: components' n
| num n v _ => Name.mkNum anonymous v :: components' n
def components (n : Name) : List Name :=
n.components'.reverse
def eqStr : Name → String → Bool
| str anonymous s _, s' => s == s'
| _, _ => false
def replacePrefix : Name → Name → Name → Name
| anonymous, anonymous, newP => newP
| anonymous, _, _ => anonymous
| n@(str p s _), queryP, newP => if n == queryP then newP else Name.mkStr (p.replacePrefix queryP newP) s
| n@(num p s _), queryP, newP => if n == queryP then newP else Name.mkNum (p.replacePrefix queryP newP) s
def isPrefixOf : Name → Name → Bool
| p, anonymous => p == anonymous
| p, n@(num p' _ _) => p == n || isPrefixOf p p'
| p, n@(str p' _ _) => p == n || isPrefixOf p p'
def isSuffixOf : Name → Name → Bool
| anonymous, _ => true
| str p₁ s₁ _, str p₂ s₂ _ => s₁ == s₂ && isSuffixOf p₁ p₂
| num p₁ n₁ _, num p₂ n₂ _ => n₁ == n₂ && isSuffixOf p₁ p₂
| _, _ => false
def lt : Name → Name → Bool
| anonymous, anonymous => false
| anonymous, _ => true
| num p₁ i₁ _, num p₂ i₂ _ => lt p₁ p₂ || (p₁ == p₂ && i₁ < i₂)
| num _ _ _, str _ _ _ => true
| str p₁ n₁ _, str p₂ n₂ _ => lt p₁ p₂ || (p₁ == p₂ && n₁ < n₂)
| _, _ => false
def quickLtAux : Name → Name → Bool
| anonymous, anonymous => false
| anonymous, _ => true
| num n v _, num n' v' _ => v < v' || (v = v' && n.quickLtAux n')
| num _ _ _, str _ _ _ => true
| str n s _, str n' s' _ => s < s' || (s = s' && n.quickLtAux n')
| _, _ => false
def quickLt (n₁ n₂ : Name) : Bool :=
if n₁.hash < n₂.hash then true
else if n₁.hash > n₂.hash then false
else quickLtAux n₁ n₂
/- Alternative HasLt instance. -/
@[inline] protected def hasLtQuick : HasLess Name :=
⟨fun a b => Name.quickLt a b = true⟩
@[inline] instance : DecidableRel (@Less Name Name.hasLtQuick) :=
inferInstanceAs (DecidableRel (fun a b => Name.quickLt a b = true))
/- The frontend does not allow user declarations to start with `_` in any of its parts.
We use name parts starting with `_` internally to create auxiliary names (e.g., `_private`). -/
def isInternal : Name → Bool
| str p s _ => s.get 0 == '_' || isInternal p
| num p _ _ => isInternal p
| _ => false
def isAtomic : Name → Bool
| anonymous => true
| str anonymous _ _ => true
| num anonymous _ _ => true
| _ => false
def isAnonymous : Name → Bool
| anonymous => true
| _ => false
def isStr : Name → Bool
| str .. => true
| _ => false
def isNum : Name → Bool
| num .. => true
| _ => false
end Name
open Std (RBMap RBTree mkRBMap mkRBTree)
def NameMap (α : Type) := Std.RBMap Name α Name.quickLt
@[inline] def mkNameMap (α : Type) : NameMap α := Std.mkRBMap Name α Name.quickLt
namespace NameMap
variable {α : Type}
instance (α : Type) : EmptyCollection (NameMap α) := ⟨mkNameMap α⟩
instance (α : Type) : Inhabited (NameMap α) where
default := {}
def insert (m : NameMap α) (n : Name) (a : α) := Std.RBMap.insert m n a
def contains (m : NameMap α) (n : Name) : Bool := Std.RBMap.contains m n
@[inline] def find? (m : NameMap α) (n : Name) : Option α := Std.RBMap.find? m n
end NameMap
def NameSet := RBTree Name Name.quickLt
namespace NameSet
def empty : NameSet := mkRBTree Name Name.quickLt
instance : EmptyCollection NameSet := ⟨empty⟩
instance : Inhabited NameSet := ⟨{}⟩
def insert (s : NameSet) (n : Name) : NameSet := Std.RBTree.insert s n
def contains (s : NameSet) (n : Name) : Bool := Std.RBMap.contains s n
end NameSet
def NameHashSet := Std.HashSet Name
namespace NameHashSet
@[inline] def empty : NameHashSet := Std.HashSet.empty
instance : EmptyCollection NameHashSet := ⟨empty⟩
instance : Inhabited NameHashSet := ⟨{}⟩
def insert (s : NameHashSet) (n : Name) := Std.HashSet.insert s n
def contains (s : NameHashSet) (n : Name) : Bool := Std.HashSet.contains s n
end NameHashSet
end Lean
open Lean
def String.toName (s : String) : Name :=
let ps := s.splitOn ".";
ps.foldl (fun n p => Name.mkStr n p.trim) Name.anonymous
|
bcee93284ecd33647eb4f153ec3fec2c598f594d | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /order/filter.lean | dfe1e4fc1c0d98d838a34ac29b4d93000c367f2b | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 70,811 | 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
Theory of filters on sets.
-/
import order.complete_lattice order.galois_connection data.set data.finset order.zorn
open lattice set
universes u v w x y
open set classical
local attribute [instance] prop_decidable
namespace lattice
variables {α : Type u} {ι : Sort v}
section
variable [complete_lattice α]
lemma Inf_eq_finite_sets {s : set α} :
Inf s = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t) :=
le_antisymm
(le_infi $ assume t, le_infi $ assume ⟨_, h⟩, Inf_le_Inf h)
(le_Inf $ assume b h, infi_le_of_le {b} $ infi_le_of_le (by simp [h]) $ Inf_le $ by simp)
lemma infi_insert_finset {ι : Type v} {s : finset ι} {f : ι → α} {i : ι} :
(⨅j∈insert i s, f j) = f i ⊓ (⨅j∈s, f j) :=
by simp [infi_or, infi_inf_eq]
lemma infi_empty_finset {ι : Type v} {f : ι → α} : (⨅j∈(∅ : finset ι), f j) = ⊤ :=
by simp
end
lemma inf_left_comm [semilattice_inf α] (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a]
end lattice
namespace set
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} {ι : Sort y}
theorem monotone_inter [preorder β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λx, (f x) ∩ (g x)) :=
assume a b h x ⟨h₁, h₂⟩, ⟨hf h h₁, hg h h₂⟩
theorem monotone_set_of [preorder α] {p : α → β → Prop}
(hp : ∀b, monotone (λa, p a b)) : monotone (λa, {b | p a b}) :=
assume a a' h b, hp b h
end set
section order
variables {α : Type u} (r : α → α → Prop)
local infix `≼` : 50 := r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def directed {ι : Sort v} (f : ι → α) := ∀x y, ∃z, f z ≼ f x ∧ f z ≼ f y
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃z ∈ s, z ≼ x ∧ z ≼ y
lemma directed_on_Union {r} {ι : Sort v} {f : ι → set α} (hd : directed (⊇) f)
(h : ∀x, directed_on r (f x)) : directed_on r (⋃x, f x) :=
by simp [directed_on]; exact
assume a₁ b₁ fb₁ a₂ b₂ fb₂,
let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂,
⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂) in
⟨x, ⟨z, xf⟩, xa₁, xa₂⟩
end order
theorem directed_of_chain {α : Type u} {β : Type v} [preorder β] {f : α → β} {c : set α}
(h : zorn.chain (λa b, f b ≤ f a) c) :
directed (≤) (λx:{a:α // a ∈ c}, f (x.val)) :=
assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
(assume : a = b, by simp [this]; exact ⟨b, hb, le_refl _⟩)
(assume : a ≠ b,
have f b ≤ f a ∨ f a ≤ f b, from h a ha b hb this,
or.elim this
(assume : f b ≤ f a, ⟨⟨b, hb⟩, this, le_refl _⟩)
(assume : f a ≤ f b, ⟨⟨a, ha⟩, le_refl _, this⟩))
structure filter (α : Type u) :=
(sets : set (set α))
(exists_mem_sets : ∃x, x ∈ sets)
(upwards_sets : ∀{x y}, x ∈ sets → x ⊆ y → y ∈ sets)
(directed_sets : directed_on (⊆) sets)
namespace filter
variables {α : Type u} {f g : filter α} {s t : set α}
lemma filter_eq : ∀{f g : filter α}, f.sets = g.sets → f = g
| ⟨a, _, _, _⟩ ⟨._, _, _, _⟩ rfl := rfl
lemma filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
lemma filter.ext : f = g ↔ ∀ s, s ∈ f.sets ↔ s ∈ g.sets :=
by rw [filter_eq_iff, ext_iff]
lemma univ_mem_sets' (h : ∀ a, a ∈ s): s ∈ f.sets :=
let ⟨x, x_in_s⟩ := f.exists_mem_sets in f.upwards_sets x_in_s (assume x _, h x)
lemma univ_mem_sets : univ ∈ f.sets :=
univ_mem_sets' mem_univ
lemma inter_mem_sets (hs : s ∈ f.sets) (ht : t ∈ f.sets) : s ∩ t ∈ f.sets :=
let ⟨z, ⟨z_in_s, z_le_x, z_le_y⟩⟩ := f.directed_sets _ hs _ ht in
f.upwards_sets z_in_s (subset_inter z_le_x z_le_y)
lemma mp_sets (hs : s ∈ f.sets) (h : {x | x ∈ s → x ∈ t} ∈ f.sets) : t ∈ f.sets :=
f.upwards_sets (inter_mem_sets hs h) $ assume x ⟨h₁, h₂⟩, h₂ h₁
lemma Inter_mem_sets {β : Type v} {s : β → set α} {is : set β} (hf : finite is) :
(∀i∈is, s i ∈ f.sets) → (⋂i∈is, s i) ∈ f.sets :=
finite.induction_on hf
(assume hs, by simp [univ_mem_sets])
(assume i is _ hf hi hs,
have h₁ : s i ∈ f.sets, from hs i (by simp),
have h₂ : (⋂x∈is, s x) ∈ f.sets, from hi $ assume a ha, hs _ $ by simp [ha],
by simp [inter_mem_sets h₁ h₂])
lemma exists_sets_subset_iff : (∃t∈f.sets, t ⊆ s) ↔ s ∈ f.sets :=
⟨assume ⟨t, ht, ts⟩, f.upwards_sets ht ts, assume hs, ⟨s, hs, subset.refl _⟩⟩
lemma monotone_mem_sets {f : filter α} : monotone (λs, s ∈ f.sets) :=
assume s t hst h, f.upwards_sets h hst
end filter
namespace tactic.interactive
open tactic interactive
/-- `filter [t1, ⋯, tn]` replaces a goal of the form `s ∈ f.sets`
and terms `h1 : t1 ∈ f.sets, ⋯, tn ∈ f.sets` with `∀x, x ∈ t1 → ⋯ → x ∈ tn → x ∈ s`.
`filter [t1, ⋯, tn] e` is a short form for `{ filter [t1, ⋯, tn], exact e }`.
-/
meta def filter_upwards
(s : parse types.pexpr_list)
(e' : parse $ optional types.texpr) : tactic unit :=
do
s.reverse.mmap (λ e, eapplyc `filter.mp_sets >> eapply e),
eapplyc `filter.univ_mem_sets',
match e' with
| some e := interactive.exact e
| none := skip
end
end tactic.interactive
namespace filter
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
section principal
/-- The principal filter of `s` is the collection of all supersets of `s`. -/
def principal (s : set α) : filter α :=
{ sets := {t | s ⊆ t},
exists_mem_sets := ⟨s, subset.refl _⟩,
upwards_sets := assume x y hx hy, subset.trans hx hy,
directed_sets := assume x hx y hy, ⟨s, subset.refl _, hx, hy⟩ }
instance : inhabited (filter α) :=
⟨principal ∅⟩
@[simp] lemma mem_principal_sets {s t : set α} : s ∈ (principal t).sets ↔ t ⊆ s := iff.rfl
lemma mem_principal_self (s : set α) : s ∈ (principal s).sets := subset.refl _
end principal
section join
/-- The join of a filter of filters is defined by the relation
`s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/
def join (f : filter (filter α)) : filter α :=
{ sets := {s | {t : filter α | s ∈ t.sets} ∈ f.sets},
exists_mem_sets := ⟨univ, by simp [univ_mem_sets]; exact univ_mem_sets⟩,
upwards_sets := assume x y hx xy, f.upwards_sets hx $ assume a h, a.upwards_sets h xy,
directed_sets := assume x hx y hy, ⟨x ∩ y,
by filter_upwards [hx, hy] assume z h₁ h₂, inter_mem_sets h₁ h₂,
inter_subset_left _ _, inter_subset_right _ _⟩ }
@[simp] lemma mem_join_sets {s : set α} {f : filter (filter α)} :
s ∈ (join f).sets ↔ {t | s ∈ filter.sets t} ∈ f.sets := iff.rfl
end join
section lattice
instance : partial_order (filter α) :=
{ le := λf g, g.sets ⊆ f.sets,
le_antisymm := assume a b h₁ h₂, filter_eq $ subset.antisymm h₂ h₁,
le_refl := assume a, subset.refl _,
le_trans := assume a b c h₁ h₂, subset.trans h₂ h₁ }
theorem le_def {f g : filter α} : f ≤ g ↔ ∀ x ∈ g.sets, x ∈ f.sets := iff.rfl
@[simp] lemma le_principal_iff {s : set α} {f : filter α} : f ≤ principal s ↔ s ∈ f.sets :=
show (∀{t}, s ⊆ t → t ∈ f.sets) ↔ s ∈ f.sets,
from ⟨assume h, h (subset.refl s), assume hs t ht, f.upwards_sets hs ht⟩
lemma principal_mono {s t : set α} : principal s ≤ principal t ↔ s ⊆ t :=
by simp
lemma monotone_principal : monotone (principal : set α → filter α) :=
by simp [monotone, principal_mono]; exact assume a b h, h
@[simp] lemma principal_eq_iff_eq {s t : set α} : principal s = principal t ↔ s = t :=
by simp [le_antisymm_iff]; refl
/-- The supremum of filters is the intersection because the ordering
of filters is reverse subset. -/
instance : has_sup (filter α) := ⟨λf g : filter α,
{ sets := f.sets ∩ g.sets,
exists_mem_sets := ⟨univ, by simp [univ_mem_sets]; exact univ_mem_sets⟩,
upwards_sets := assume x y hx xy,
and.imp (assume h, f.upwards_sets h xy) (assume h, g.upwards_sets h xy) hx,
directed_sets := assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∩ y,
⟨inter_mem_sets hx₁ hy₁, inter_mem_sets hx₂ hy₂⟩,
inter_subset_left _ _, inter_subset_right _ _⟩ }⟩
@[simp] lemma mem_sup_sets {f g : filter α} {s : set α} :
s ∈ (f ⊔ g).sets ↔ s ∈ f.sets ∧ s ∈ g.sets := iff.rfl
/-- The infimum of filters is the filter generated by intersections
of elements of the two filters. -/
instance : has_inf (filter α) := ⟨λf g : filter α,
{ sets := {s | ∃ (a ∈ f.sets) (b ∈ g.sets), a ∩ b ⊆ s },
exists_mem_sets := ⟨univ, univ, univ_mem_sets, univ, univ_mem_sets, subset_univ _⟩,
upwards_sets := assume x y ⟨a, ha, b, hb, h⟩ xy,
⟨a, ha, b, hb, subset.trans h xy⟩,
directed_sets := assume x ⟨a₁, ha₁, b₁, hb₁, h₁⟩ y ⟨a₂, ha₂, b₂, hb₂, h₂⟩,
⟨x ∩ y,
⟨_, inter_mem_sets ha₁ ha₂, _, inter_mem_sets hb₁ hb₂,
calc (a₁ ⊓ a₂) ⊓ (b₁ ⊓ b₂) = (a₁ ⊓ b₁) ⊓ (a₂ ⊓ b₂) : by ac_refl
... ≤ x ∩ y : inf_le_inf h₁ h₂ ⟩,
inter_subset_left _ _, inter_subset_right _ _⟩ }⟩
@[simp] lemma mem_inf_sets {f g : filter α} {s : set α} :
s ∈ (f ⊓ g).sets ↔ ∃t₁∈f.sets, ∃t₂∈g.sets, t₁ ∩ t₂ ⊆ s := iff.rfl
lemma mem_inf_sets_of_left {f g : filter α} {s : set α} (h : s ∈ f.sets) : s ∈ (f ⊓ g).sets :=
⟨s, h, univ, univ_mem_sets, inter_subset_left _ _⟩
lemma mem_inf_sets_of_right {f g : filter α} {s : set α} (h : s ∈ g.sets) : s ∈ (f ⊓ g).sets :=
⟨univ, univ_mem_sets, s, h, inter_subset_right _ _⟩
lemma inter_mem_inf_sets {α : Type u} {f g : filter α} {s t : set α}
(hs : s ∈ f.sets) (ht : t ∈ g.sets) : s ∩ t ∈ (f ⊓ g).sets :=
inter_mem_sets (mem_inf_sets_of_left hs) (mem_inf_sets_of_right ht)
instance : has_top (filter α) := ⟨principal univ⟩
@[simp] lemma mem_top_sets_iff {s : set α} : s ∈ (⊤ : filter α).sets ↔ s = univ :=
⟨assume h, top_unique $ h, assume h, h.symm ▸ univ_mem_sets⟩
instance : has_bot (filter α) := ⟨principal ∅⟩
@[simp] lemma mem_bot_sets {s : set α} : s ∈ (⊥ : filter α).sets :=
assume x, false.elim
instance : has_Sup (filter α) := ⟨join ∘ principal⟩
protected lemma le_Sup {s : set (filter α)} {f : filter α} : f ∈ s → f ≤ Sup s :=
assume f_in_s t' h, h f_in_s
protected lemma Sup_le {s : set (filter α)} {f : filter α} : (∀g∈s, g ≤ f) → Sup s ≤ f :=
assume h a ha g hg, h g hg ha
@[simp] lemma mem_Sup_sets {S : set (filter α)} {s : set α} :
s ∈ (Sup S).sets ↔ ∀ f ∈ S, s ∈ (f : filter α).sets :=
by simp [Sup, has_Sup.Sup]; refl
@[simp] lemma join_principal_eq_Sup {s : set (filter α)} : join (principal s) = Sup s := rfl
instance complete_lattice_filter : complete_lattice (filter α) :=
{ sup := (⊔),
le_sup_left := assume a b, inter_subset_left _ _,
le_sup_right := assume a b, inter_subset_right _ _,
sup_le := assume a b c h₁ h₂, subset_inter h₁ h₂,
inf := (⊓),
le_inf := assume f g h fg fh s ⟨a, ha, b, hb, h⟩,
by filter_upwards [fg ha, fh hb] assume x ha hb, h ⟨ha, hb⟩,
inf_le_left := assume f g s, mem_inf_sets_of_left,
inf_le_right := assume f g s, mem_inf_sets_of_right,
top := ⊤,
le_top := assume a, show a ≤ principal univ, by simp [univ_mem_sets],
bot := ⊥,
bot_le := assume a, show a.sets ⊆ {x | ∅ ⊆ x}, by simp; apply subset_univ,
Sup := Sup,
le_Sup := assume s f, filter.le_Sup,
Sup_le := assume s f, filter.Sup_le,
Inf := λs, Sup {x | ∀y∈s, x ≤ y},
le_Inf := assume s a h, filter.le_Sup h,
Inf_le := assume s a ha, filter.Sup_le $ assume b h, h _ ha,
..filter.partial_order }
/- lattice equations -/
lemma empty_in_sets_eq_bot {f : filter α} : ∅ ∈ f.sets ↔ f = ⊥ :=
⟨assume h, bot_unique $ assume s _, f.upwards_sets h (empty_subset s),
assume : f = ⊥, this.symm ▸ mem_bot_sets⟩
lemma inhabited_of_mem_sets {f : filter α} {s : set α} (hf : f ≠ ⊥) (hs : s ∈ f.sets) :
∃x, x ∈ s :=
have ∅ ∉ f.sets, from assume h, hf $ empty_in_sets_eq_bot.mp h,
have s ≠ ∅, from assume h, this (h ▸ hs),
exists_mem_of_ne_empty this
lemma filter_eq_bot_of_not_nonempty {f : filter α} (ne : ¬ nonempty α) : f = ⊥ :=
empty_in_sets_eq_bot.mp $ univ_mem_sets' $ assume x, false.elim (ne ⟨x⟩)
lemma forall_sets_neq_empty_iff_neq_bot {f : filter α} :
(∀ (s : set α), s ∈ f.sets → s ≠ ∅) ↔ f ≠ ⊥ :=
by
simp [(@empty_in_sets_eq_bot α f).symm];
exact ⟨assume h hs, h _ hs rfl, assume h s hs eq, h $ eq ▸ hs⟩
lemma mem_sets_of_neq_bot {f : filter α} {s : set α} (h : f ⊓ principal (-s) = ⊥) : s ∈ f.sets :=
have ∅ ∈ (f ⊓ principal (- s)).sets, from h.symm ▸ mem_bot_sets,
let ⟨s₁, hs₁, s₂, (hs₂ : -s ⊆ s₂), (hs : s₁ ∩ s₂ ⊆ ∅)⟩ := this in
by filter_upwards [hs₁] assume a ha, classical.by_contradiction $ assume ha', hs ⟨ha, hs₂ ha'⟩
lemma infi_sets_eq {f : ι → filter α} (h : directed (≤) f) (ne : nonempty ι) :
(infi f).sets = (⋃ i, (f i).sets) :=
let ⟨i⟩ := ne, u := { filter .
sets := (⋃ i, (f i).sets),
exists_mem_sets := ⟨univ, begin simp, exact ⟨i, univ_mem_sets⟩ end⟩,
directed_sets := directed_on_Union (show directed (≤) f, from h) (assume i, (f i).directed_sets),
upwards_sets := by simpa using assume x y j xf (xy : x ⊆ y),
exists.intro j ((f j).upwards_sets xf xy) } in
subset.antisymm
(show u ≤ infi f, from le_infi $ assume i, le_supr (λi, (f i).sets) i)
(Union_subset $ assume i, infi_le f i)
lemma infi_sets_eq' {f : β → filter α} {s : set β} (h : directed_on (λx y, f x ≤ f y) s) (ne : ∃i, i ∈ s) :
(⨅ i∈s, f i).sets = (⋃ i ∈ s, (f i).sets) :=
let ⟨i, hi⟩ := ne in
calc (⨅ i ∈ s, f i).sets = (⨅ t : {t // t ∈ s}, (f t.val)).sets : by rw [infi_subtype]; refl
... = (⨆ t : {t // t ∈ s}, (f t.val).sets) : infi_sets_eq
(assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end)
⟨⟨i, hi⟩⟩
... = (⨆ t ∈ {t | t ∈ s}, (f t).sets) : by rw [supr_subtype]; refl
lemma Inf_sets_eq_finite {s : set (filter α)} :
(Inf s).sets = (⋃ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t).sets) :=
calc (Inf s).sets = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t).sets : by rw [lattice.Inf_eq_finite_sets]
... = (⨆ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t).sets) : infi_sets_eq'
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∪ y, ⟨finite_union hx₁ hy₁, union_subset hx₂ hy₂⟩,
Inf_le_Inf $ subset_union_left _ _, Inf_le_Inf $ subset_union_right _ _⟩)
⟨∅, by simp⟩
lemma supr_sets_eq {f : ι → filter α} : (supr f).sets = (⋂i, (f i).sets) :=
set.ext $ assume s,
show s ∈ (join (principal {a : filter α | ∃i : ι, a = f i})).sets ↔ s ∈ (⋂i, (f i).sets),
begin
rw [mem_join_sets],
simp, rw [forall_swap],
exact forall_congr (λ i, by simp)
end
@[simp] lemma mem_supr_sets {f : ι → filter α} {s : set α} : s ∈ (supr f).sets ↔ ∀ i, s ∈ (f i).sets :=
by simp [supr_sets_eq]
@[simp] lemma sup_join {f₁ f₂ : filter (filter α)} : (join f₁ ⊔ join f₂) = join (f₁ ⊔ f₂) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq, join]
@[simp] lemma supr_join {ι : Sort w} {f : ι → filter (filter α)} : (⨆x, join (f x)) = join (⨆x, f x) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq, join]
instance : bounded_distrib_lattice (filter α) :=
{ le_sup_inf := assume x y z s,
begin
simp only [and_assoc, mem_inf_sets, mem_sup_sets, exists_prop, exists_imp_distrib, and_imp],
intros hs t₁ ht₁ t₂ ht₂ hts,
exact ⟨s ∪ t₁,
x.upwards_sets hs $ subset_union_left _ _,
y.upwards_sets ht₁ $ subset_union_right _ _,
s ∪ t₂,
x.upwards_sets hs $ subset_union_left _ _,
z.upwards_sets ht₂ $ subset_union_right _ _,
subset.trans (@le_sup_inf (set α) _ _ _ _) (union_subset (subset.refl _) hts)⟩
end,
..filter.complete_lattice_filter }
private lemma infi_finite_distrib {s : set (filter α)} {f : filter α} (h : finite s) :
(⨅ a ∈ s, f ⊔ a) = f ⊔ (Inf s) :=
finite.induction_on h
(by simp only [mem_empty_eq, infi_false, infi_top, Inf_empty, sup_top_eq])
(by intros a s hn hs hi; rw [infi_insert, hi, ← sup_inf_left, Inf_insert])
/- the complementary version with ⨆ g∈s, f ⊓ g does not hold! -/
lemma binfi_sup_eq { f : filter α } {s : set (filter α)} : (⨅ g∈s, f ⊔ g) = f ⊔ Inf s :=
le_antisymm
begin
intros t h,
cases h with h₁ h₂,
rw [Inf_sets_eq_finite] at h₂,
simp [and_assoc] at h₂,
rcases h₂ with ⟨s', hs', hs's, ht'⟩,
have ht : t ∈ (⨅ a ∈ s', f ⊔ a).sets,
{ rw [infi_finite_distrib], exact ⟨h₁, ht'⟩, exact hs' },
clear h₁ ht',
revert ht t,
change (⨅ a ∈ s, f ⊔ a) ≤ (⨅ a ∈ s', f ⊔ a),
apply infi_le_infi2 _,
exact assume i, ⟨i, infi_le_infi2 $ assume h, ⟨hs's h, le_refl _⟩⟩
end
(le_infi $ assume g, le_infi $ assume h, sup_le_sup (le_refl f) $ Inf_le h)
lemma infi_sup_eq { f : filter α } {g : ι → filter α} : (⨅ x, f ⊔ g x) = f ⊔ infi g :=
calc (⨅ x, f ⊔ g x) = (⨅ x (h : ∃i, g i = x), f ⊔ x) : by simp; rw [infi_comm]; simp
... = f ⊔ Inf {x | ∃i, g i = x} : binfi_sup_eq
... = f ⊔ infi g : by rw [Inf_eq_infi]; dsimp; simp; rw [infi_comm]; simp
lemma mem_infi_sets_finset {s : finset α} {f : α → filter β} :
∀t, t ∈ (⨅a∈s, f a).sets ↔ (∃p:α → set β, (∀a∈s, p a ∈ (f a).sets) ∧ (⋂a∈s, p a) ⊆ t) :=
show ∀t, t ∈ (⨅a∈s, f a).sets ↔ (∃p:α → set β, (∀a∈s, p a ∈ (f a).sets) ∧ (⨅a∈s, p a) ≤ t),
begin
refine finset.induction_on s _ _,
{ simp only [finset.not_mem_empty, false_implies_iff, lattice.infi_empty_finset, top_le_iff,
imp_true_iff, mem_top_sets_iff, true_and, exists_const],
exact assume _, iff.refl _ },
{ intros a s has ih t,
simp only [ih, finset.forall_mem_insert, lattice.infi_insert_finset, mem_inf_sets,
exists_prop, iff_iff_implies_and_implies, exists_imp_distrib, and_imp, and_assoc] {contextual := tt},
split,
{ intros t₁ ht₁ t₂ p hp ht₂ ht,
existsi function.update p a t₁,
have : ∀a'∈s, function.update p a t₁ a' = p a',
from assume a' ha',
have a' ≠ a, from assume h, has $ h ▸ ha',
function.update_noteq this,
have eq : (⨅j ∈ s, function.update p a t₁ j) = (⨅j ∈ s, p j),
begin congr, funext b, congr, funext h, apply this, assumption end,
simp only [this, ht₁, hp, function.update_same, true_and, imp_true_iff, eq] {contextual := tt},
exact subset.trans (inter_subset_inter (subset.refl _) ht₂) ht },
from assume p hpa hp ht, ⟨p a, hpa, (⨅j∈s, p j), ⟨⟨p, hp, le_refl _⟩, ht⟩⟩ }
end
/- principal equations -/
@[simp] lemma inf_principal {s t : set α} : principal s ⊓ principal t = principal (s ∩ t) :=
le_antisymm
(by simp; exact ⟨s, subset.refl s, t, subset.refl t, by simp⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp] lemma sup_principal {s t : set α} : principal s ⊔ principal t = principal (s ∪ t) :=
filter_eq $ set.ext $ by simp [union_subset_iff]
@[simp] lemma supr_principal {ι : Sort w} {s : ι → set α} : (⨆x, principal (s x)) = principal (⋃i, s i) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq]; exact (@supr_le_iff (set α) _ _ _ _).symm
lemma principal_univ : principal (univ : set α) = ⊤ := rfl
lemma principal_empty : principal (∅ : set α) = ⊥ := rfl
@[simp] lemma principal_eq_bot_iff {s : set α} : principal s = ⊥ ↔ s = ∅ :=
⟨assume h, principal_eq_iff_eq.mp $ by simp [principal_empty, h], assume h, by simp [*, principal_empty]⟩
lemma inf_principal_eq_bot {f : filter α} {s : set α} (hs : -s ∈ f.sets) : f ⊓ principal s = ⊥ :=
empty_in_sets_eq_bot.mp ⟨_, hs, s, mem_principal_self s, assume x ⟨h₁, h₂⟩, h₁ h₂⟩
end lattice
section map
/-- The forward map of a filter -/
def map (m : α → β) (f : filter α) : filter β :=
{ sets := preimage m ⁻¹' f.sets,
exists_mem_sets := ⟨univ, univ_mem_sets⟩,
upwards_sets := assume s t hs st, f.upwards_sets hs (assume x h, st h),
directed_sets := assume s hs t ht, ⟨s ∩ t, inter_mem_sets hs ht,
inter_subset_left _ _, inter_subset_right _ _⟩ }
@[simp] lemma map_principal {s : set α} {f : α → β} :
map f (principal s) = principal (set.image f s) :=
filter_eq $ set.ext $ assume a, image_subset_iff.symm
variables {f : filter α} {m : α → β} {m' : β → γ} {s : set α} {t : set β}
@[simp] lemma mem_map : t ∈ (map m f).sets ↔ {x | m x ∈ t} ∈ f.sets := iff.rfl
lemma image_mem_map (hs : s ∈ f.sets) : m '' s ∈ (map m f).sets :=
f.upwards_sets hs $ assume x hx, ⟨x, hx, rfl⟩
@[simp] lemma map_id : filter.map id f = f :=
filter_eq $ rfl
@[simp] lemma map_compose : filter.map m' ∘ filter.map m = filter.map (m' ∘ m) :=
funext $ assume _, filter_eq $ rfl
@[simp] lemma map_map : filter.map m' (filter.map m f) = filter.map (m' ∘ m) f :=
congr_fun (@@filter.map_compose m m') f
end map
section vmap
/-- The inverse map of a filter -/
def vmap (m : α → β) (f : filter β) : filter α :=
{ sets := { s | ∃t∈f.sets, m ⁻¹' t ⊆ s },
exists_mem_sets := ⟨univ, univ, univ_mem_sets, by simp⟩,
upwards_sets := assume a b ⟨a', ha', ma'a⟩ ab, ⟨a', ha', subset.trans ma'a ab⟩,
directed_sets := assume a ⟨a', ha₁, ha₂⟩ b ⟨b', hb₁, hb₂⟩,
⟨preimage m (a' ∩ b'),
⟨a' ∩ b', inter_mem_sets ha₁ hb₁, subset.refl _⟩,
subset.trans (preimage_mono $ inter_subset_left _ _) ha₂,
subset.trans (preimage_mono $ inter_subset_right _ _) hb₂⟩ }
end vmap
/-- The cofinite filter is the filter of subsets whose complements
are finite. -/
def cofinite : filter α :=
{ sets := {s | finite (- s)},
exists_mem_sets := ⟨univ, by simp⟩,
upwards_sets := assume s t, assume hs : finite (-s), assume st: s ⊆ t,
finite_subset hs $ @lattice.neg_le_neg (set α) _ _ _ st,
directed_sets := assume s, assume hs : finite (-s), assume t, assume ht : finite (-t),
⟨s ∩ t, by simp [compl_inter, finite_union, ht, hs],
inter_subset_left _ _, inter_subset_right _ _⟩ }
/-- The monadic bind operation on filter is defined the usual way
in terms of `map` and `join`. -/
def bind (f : filter α) (m : α → filter β) : filter β := join (map m f)
instance : monad filter :=
{ bind := @bind,
pure := λ(α : Type u) x, principal {x},
map := @filter.map }
instance : is_lawful_monad filter :=
{ id_map := assume α f, filter_eq rfl,
pure_bind := assume α β a f, by simp [bind, Sup_image],
bind_assoc := assume α β γ f m₁ m₂, filter_eq rfl,
bind_pure_comp_eq_map := assume α β f x, filter_eq $ by simp [bind, join, map, preimage, principal] }
@[simp] lemma pure_def (x : α) : pure x = principal {x} := rfl
@[simp] lemma mem_pure {a : α} {s : set α} : a ∈ s → s ∈ (pure a : filter α).sets :=
by simp; exact id
@[simp] lemma map_def {α β} (m : α → β) (f : filter α) : m <$> f = map m f := rfl
@[simp] lemma bind_def {α β} (f : filter α) (m : α → filter β) : f >>= m = bind f m := rfl
instance : alternative filter :=
{ failure := λα, ⊥,
orelse := λα x y, x ⊔ y }
/- map and vmap equations -/
section map
variables {f f₁ f₂ : filter α} {g g₁ g₂ : filter β} {m : α → β} {m' : β → γ} {s : set α} {t : set β}
@[simp] theorem mem_vmap_sets : s ∈ (vmap m g).sets ↔ ∃t∈g.sets, m ⁻¹' t ⊆ s := iff.rfl
theorem preimage_mem_vmap (ht : t ∈ g.sets) : m ⁻¹' t ∈ (vmap m g).sets :=
⟨t, ht, subset.refl _⟩
lemma vmap_id : vmap id f = f :=
le_antisymm (assume s, preimage_mem_vmap) (assume s ⟨t, ht, hst⟩, f.upwards_sets ht hst)
lemma vmap_vmap_comp {m : γ → β} {n : β → α} : vmap m (vmap n f) = vmap (n ∘ m) f :=
le_antisymm
(assume c ⟨b, hb, (h : preimage (n ∘ m) b ⊆ c)⟩, ⟨preimage n b, preimage_mem_vmap hb, h⟩)
(assume c ⟨b, ⟨a, ha, (h₁ : preimage n a ⊆ b)⟩, (h₂ : preimage m b ⊆ c)⟩,
⟨a, ha, show preimage m (preimage n a) ⊆ c, from subset.trans (preimage_mono h₁) h₂⟩)
@[simp] theorem vmap_principal {t : set β} : vmap m (principal t) = principal (m ⁻¹' t) :=
filter_eq $ set.ext $ assume s,
⟨assume ⟨u, (hu : t ⊆ u), (b : preimage m u ⊆ s)⟩, subset.trans (preimage_mono hu) b,
assume : preimage m t ⊆ s, ⟨t, subset.refl t, this⟩⟩
lemma map_le_iff_le_vmap : map m f ≤ g ↔ f ≤ vmap m g :=
⟨assume h s ⟨t, ht, hts⟩, f.upwards_sets (h ht) hts, assume h s ht, h ⟨_, ht, subset.refl _⟩⟩
lemma gc_map_vmap (m : α → β) : galois_connection (map m) (vmap m) :=
assume f g, map_le_iff_le_vmap
lemma map_mono (h : f₁ ≤ f₂) : map m f₁ ≤ map m f₂ := (gc_map_vmap m).monotone_l h
lemma monotone_map : monotone (map m) | a b := map_mono
lemma vmap_mono (h : g₁ ≤ g₂) : vmap m g₁ ≤ vmap m g₂ := (gc_map_vmap m).monotone_u h
lemma monotone_vmap : monotone (vmap m) | a b := vmap_mono
@[simp] lemma map_bot : map m ⊥ = ⊥ := (gc_map_vmap m).l_bot
@[simp] lemma map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_vmap m).l_sup
@[simp] lemma map_supr {f : ι → filter α} : map m (⨆i, f i) = (⨆i, map m (f i)) :=
(gc_map_vmap m).l_supr
@[simp] lemma vmap_top : vmap m ⊤ = ⊤ := (gc_map_vmap m).u_top
@[simp] lemma vmap_inf : vmap m (g₁ ⊓ g₂) = vmap m g₁ ⊓ vmap m g₂ := (gc_map_vmap m).u_inf
@[simp] lemma vmap_infi {f : ι → filter β} : vmap m (⨅i, f i) = (⨅i, vmap m (f i)) :=
(gc_map_vmap m).u_infi
lemma map_vmap_le : map m (vmap m g) ≤ g := (gc_map_vmap m).decreasing_l_u _
lemma le_vmap_map : f ≤ vmap m (map m f) := (gc_map_vmap m).increasing_u_l _
@[simp] lemma vmap_bot : vmap m ⊥ = ⊥ :=
bot_unique $ assume s _, ⟨∅, by simp, by simp⟩
lemma vmap_sup : vmap m (g₁ ⊔ g₂) = vmap m g₁ ⊔ vmap m g₂ :=
le_antisymm
(assume s ⟨⟨t₁, ht₁, hs₁⟩, ⟨t₂, ht₂, hs₂⟩⟩,
⟨t₁ ∪ t₂,
⟨g₁.upwards_sets ht₁ (subset_union_left _ _), g₂.upwards_sets ht₂ (subset_union_right _ _)⟩,
union_subset hs₁ hs₂⟩)
(sup_le (vmap_mono le_sup_left) (vmap_mono le_sup_right))
lemma le_map_vmap' {f : filter β} {m : α → β} {s : set β}
(hs : s ∈ f.sets) (hm : ∀b∈s, ∃a, m a = b) : f ≤ map m (vmap m f) :=
assume t' ⟨t, ht, (sub : m ⁻¹' t ⊆ m ⁻¹' t')⟩,
by filter_upwards [ht, hs] assume x hxt hxs,
let ⟨y, hy⟩ := hm x hxs in
hy ▸ sub (show m y ∈ t, from hy.symm ▸ hxt)
lemma le_map_vmap {f : filter β} {m : α → β} (hm : ∀x, ∃y, m y = x) : f ≤ map m (vmap m f) :=
le_map_vmap' univ_mem_sets (assume b _, hm b)
lemma vmap_map {f : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) :
vmap m (map m f) = f :=
have ∀s, preimage m (image m s) = s,
from assume s, preimage_image_eq s h,
le_antisymm
(assume s hs, ⟨
image m s,
f.upwards_sets hs $ by simp [this, subset.refl],
by simp [this, subset.refl]⟩)
le_vmap_map
lemma le_of_map_le_map_inj' {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y)
(h : map m f ≤ map m g) : f ≤ g :=
assume t ht, by filter_upwards [hsf, h $ image_mem_map (inter_mem_sets hsg ht)]
assume a has ⟨b, ⟨hbs, hb⟩, h⟩,
have b = a, from hm _ hbs _ has h,
this ▸ hb
lemma le_of_map_le_map_inj_iff {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y) :
map m f ≤ map m g ↔ f ≤ g :=
iff.intro (le_of_map_le_map_inj' hsf hsg hm) map_mono
lemma eq_of_map_eq_map_inj' {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y)
(h : map m f = map m g) : f = g :=
le_antisymm
(le_of_map_le_map_inj' hsf hsg hm $ le_of_eq h)
(le_of_map_le_map_inj' hsg hsf hm $ le_of_eq h.symm)
lemma map_inj {f g : filter α} {m : α → β} (hm : ∀ x y, m x = m y → x = y) (h : map m f = map m g) :
f = g :=
have vmap m (map m f) = vmap m (map m g), by rw h,
by rwa [vmap_map hm, vmap_map hm] at this
lemma vmap_neq_bot {f : filter β} {m : α → β}
(hm : ∀t∈f.sets, ∃a, m a ∈ t) : vmap m f ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp $ assume s ⟨t, ht, t_s⟩,
let ⟨a, (ha : a ∈ preimage m t)⟩ := hm t ht in
neq_bot_of_le_neq_bot (ne_empty_of_mem ha) t_s
lemma vmap_neq_bot_of_surj {f : filter β} {m : α → β}
(hf : f ≠ ⊥) (hm : ∀b, ∃a, m a = b) : vmap m f ≠ ⊥ :=
vmap_neq_bot $ assume t ht,
let
⟨b, (hx : b ∈ t)⟩ := inhabited_of_mem_sets hf ht,
⟨a, (ha : m a = b)⟩ := hm b
in ⟨a, ha.symm ▸ hx⟩
@[simp] lemma map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ :=
⟨by rw [←empty_in_sets_eq_bot, ←empty_in_sets_eq_bot]; exact id,
assume h, by simp [*]⟩
lemma map_ne_bot (hf : f ≠ ⊥) : map m f ≠ ⊥ :=
assume h, hf $ by rwa [map_eq_bot_iff] at h
end map
lemma map_cong {m₁ m₂ : α → β} {f : filter α} (h : {x | m₁ x = m₂ x} ∈ f.sets) :
map m₁ f = map m₂ f :=
have ∀(m₁ m₂ : α → β) (h : {x | m₁ x = m₂ x} ∈ f.sets), map m₁ f ≤ map m₂ f,
begin
intros m₁ m₂ h s hs,
show {x | m₁ x ∈ s} ∈ f.sets,
filter_upwards [h, hs],
simp [subset_def] {contextual := tt}
end,
le_antisymm (this m₁ m₂ h) (this m₂ m₁ $ f.upwards_sets h $ assume x, eq.symm)
-- this is a generic rule for monotone functions:
lemma map_infi_le {f : ι → filter α} {m : α → β} :
map m (infi f) ≤ (⨅ i, map m (f i)) :=
le_infi $ assume i, map_mono $ infi_le _ _
lemma map_infi_eq {f : ι → filter α} {m : α → β} (hf : directed (≤) f) (hι : nonempty ι) :
map m (infi f) = (⨅ i, map m (f i)) :=
le_antisymm
map_infi_le
(assume s (hs : preimage m s ∈ (infi f).sets),
have ∃i, preimage m s ∈ (f i).sets,
by simp [infi_sets_eq hf hι] at hs; assumption,
let ⟨i, hi⟩ := this in
have (⨅ i, map m (f i)) ≤ principal s,
from infi_le_of_le i $ by simp; assumption,
by simp at this; assumption)
lemma map_binfi_eq {ι : Type w} {f : ι → filter α} {m : α → β} {p : ι → Prop}
(h : directed_on (λx y, f x ≤ f y) {x | p x}) (ne : ∃i, p i) :
map m (⨅i (h : p i), f i) = (⨅i (h: p i), map m (f i)) :=
let ⟨i, hi⟩ := ne in
calc map m (⨅i (h : p i), f i) = map m (⨅i:subtype p, f i.val) : by simp [infi_subtype]
... = (⨅i:subtype p, map m (f i.val)) : map_infi_eq
(assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end)
⟨⟨i, hi⟩⟩
... = (⨅i (h : p i), map m (f i)) : by simp [infi_subtype]
lemma map_inf' {f g : filter α} {m : α → β} {t : set α} (htf : t ∈ f.sets) (htg : t ∈ g.sets)
(h : ∀x∈t, ∀y∈t, m x = m y → x = y) : map m (f ⊓ g) = map m f ⊓ map m g :=
begin
refine le_antisymm
(le_inf (map_mono inf_le_left) (map_mono inf_le_right))
(assume s hs, _),
simp [map, mem_inf_sets] at hs ⊢,
rcases hs with ⟨t₁, h₁, t₂, h₂, hs⟩,
refine ⟨m '' (t₁ ∩ t), _, m '' (t₂ ∩ t), _, _⟩,
{ filter_upwards [h₁, htf] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ },
{ filter_upwards [h₂, htg] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ },
{ rw [image_inter_on],
{ refine image_subset_iff.2 _,
exact λ x ⟨⟨h₁, _⟩, h₂, _⟩, hs ⟨h₁, h₂⟩ },
{ exact λ x ⟨_, hx⟩ y ⟨_, hy⟩, h x hx y hy } }
end
lemma map_inf {f g : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) :
map m (f ⊓ g) = map m f ⊓ map m g :=
map_inf' univ_mem_sets univ_mem_sets (assume x _ y _, h x y)
lemma map_eq_vmap_of_inverse {f : filter α} {m : α → β} {n : β → α}
(h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = vmap n f :=
le_antisymm
(assume b ⟨a, ha, (h : preimage n a ⊆ b)⟩, f.upwards_sets ha $
calc a = preimage (n ∘ m) a : by simp [h₂, preimage_id]
... ⊆ preimage m b : preimage_mono h)
(assume b (hb : preimage m b ∈ f.sets),
⟨preimage m b, hb, show preimage (m ∘ n) b ⊆ b, by simp [h₁]; apply subset.refl⟩)
lemma map_swap_eq_vmap_swap {f : filter (α × β)} : prod.swap <$> f = vmap prod.swap f :=
map_eq_vmap_of_inverse prod.swap_swap_eq prod.swap_swap_eq
/- bind equations -/
@[simp] lemma mem_bind_sets {s : set β} {f : filter α} {m : α → filter β} :
s ∈ (bind f m).sets ↔ ∃t ∈ f.sets, ∀x ∈ t, s ∈ (m x).sets :=
calc s ∈ (bind f m).sets ↔ {a | s ∈ (m a).sets} ∈ f.sets : by simp [bind]
... ↔ (∃t ∈ f.sets, t ⊆ {a | s ∈ (m a).sets}) : exists_sets_subset_iff.symm
... ↔ (∃t ∈ f.sets, ∀x ∈ t, s ∈ (m x).sets) : iff.refl _
lemma bind_mono {f : filter α} {g h : α → filter β} (h₁ : {a | g a ≤ h a} ∈ f.sets) :
bind f g ≤ bind f h :=
assume x h₂, show (_ ∈ f.sets), by filter_upwards [h₁, h₂] assume s gh' h', gh' h'
lemma bind_sup {f g : filter α} {h : α → filter β} :
bind (f ⊔ g) h = bind f h ⊔ bind g h :=
by simp [bind]
lemma bind_mono2 {f g : filter α} {h : α → filter β} (h₁ : f ≤ g) :
bind f h ≤ bind g h :=
assume s h', h₁ h'
lemma principal_bind {s : set α} {f : α → filter β} :
(bind (principal s) f) = (⨆x ∈ s, f x) :=
show join (map f (principal s)) = (⨆x ∈ s, f x),
by simp [Sup_image]
lemma seq_mono {β : Type u} {f₁ f₂ : filter (α → β)} {g₁ g₂ : filter α}
(hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ <*> g₁ ≤ f₂ <*> g₂ :=
le_trans (bind_mono2 hf) (bind_mono $ univ_mem_sets' $ assume f, map_mono hg)
@[simp] lemma mem_pure_sets {a : α} {s : set α} :
s ∈ (pure a : filter α).sets ↔ a ∈ s := by simp
@[simp] lemma mem_return_sets {a : α} {s : set α} :
s ∈ (return a : filter α).sets ↔ a ∈ s := mem_pure_sets
lemma infi_neq_bot_of_directed {f : ι → filter α}
(hn : nonempty α) (hd : directed (≤) f) (hb : ∀i, f i ≠ ⊥): (infi f) ≠ ⊥ :=
let ⟨x⟩ := hn in
assume h, have he: ∅ ∈ (infi f).sets, from h.symm ▸ mem_bot_sets,
classical.by_cases
(assume : nonempty ι,
have ∃i, ∅ ∈ (f i).sets,
by rw [infi_sets_eq hd this] at he; simp at he; assumption,
let ⟨i, hi⟩ := this in
hb i $ bot_unique $
assume s _, (f i).upwards_sets hi $ empty_subset _)
(assume : ¬ nonempty ι,
have univ ⊆ (∅ : set α),
begin
rw [←principal_mono, principal_univ, principal_empty, ←h],
exact (le_infi $ assume i, false.elim $ this ⟨i⟩)
end,
this $ mem_univ x)
lemma infi_neq_bot_iff_of_directed {f : ι → filter α}
(hn : nonempty α) (hd : directed (≤) f) : (infi f) ≠ ⊥ ↔ (∀i, f i ≠ ⊥) :=
⟨assume neq_bot i eq_bot, neq_bot $ bot_unique $ infi_le_of_le i $ eq_bot ▸ le_refl _,
infi_neq_bot_of_directed hn hd⟩
lemma mem_infi_sets {f : ι → filter α} (i : ι) : ∀{s}, s ∈ (f i).sets → s ∈ (⨅i, f i).sets :=
show (⨅i, f i) ≤ f i, from infi_le _ _
@[elab_as_eliminator]
lemma infi_sets_induct {f : ι → filter α} {s : set α} (hs : s ∈ (infi f).sets) {p : set α → Prop}
(uni : p univ)
(ins : ∀{i s₁ s₂}, s₁ ∈ (f i).sets → p s₂ → p (s₁ ∩ s₂))
(upw : ∀{s₁ s₂}, s₁ ⊆ s₂ → p s₁ → p s₂) : p s :=
begin
have hs' : s ∈ (Inf {a : filter α | ∃ (i : ι), a = f i}).sets := hs,
rw [Inf_sets_eq_finite] at hs',
simp only [mem_Union] at hs',
rcases hs' with ⟨is, ⟨fin_is, his⟩, hs⟩, revert his s,
refine finite.induction_on fin_is _ (λ fi is fi_ne_is fin_is ih, _); intros his s hs' hs,
{ rw [Inf_empty, mem_top_sets_iff] at hs, subst hs, assumption },
{ rw [Inf_insert] at hs,
rcases hs with ⟨s₁, hs₁, s₂, hs₂, hs⟩,
rcases (his (mem_insert _ _) : ∃i, fi = f i) with ⟨i, rfl⟩,
have hs₂ : p s₂, from
have his : is ⊆ {x | ∃i, x = f i}, from assume i hi, his $ mem_insert_of_mem _ hi,
have infi f ≤ Inf is, from Inf_le_Inf his,
ih his (this hs₂) hs₂,
exact upw hs (ins hs₁ hs₂) }
end
@[simp] lemma pure_neq_bot {α : Type u} {a : α} : pure a ≠ (⊥ : filter α) :=
by simp [pure, has_pure.pure]
/- tendsto -/
/-- `tendsto` is the generic "limit of a function" predicate.
`tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`,
the `f`-preimage of `a` is an `l₁` neighborhood. -/
def tendsto (f : α → β) (l₁ : filter α) (l₂ : filter β) := l₁.map f ≤ l₂
lemma tendsto_def {f : α → β} {l₁ : filter α} {l₂ : filter β} :
tendsto f l₁ l₂ ↔ ∀ s ∈ l₂.sets, f ⁻¹' s ∈ l₁.sets := iff.rfl
lemma tendsto_iff_vmap {f : α → β} {l₁ : filter α} {l₂ : filter β} :
tendsto f l₁ l₂ ↔ l₁ ≤ l₂.vmap f :=
map_le_iff_le_vmap
lemma tendsto_cong {f₁ f₂ : α → β} {l₁ : filter α} {l₂ : filter β}
(h : tendsto f₁ l₁ l₂) (hl : {x | f₁ x = f₂ x} ∈ l₁.sets) : tendsto f₂ l₁ l₂ :=
by rwa [tendsto, ←map_cong hl]
lemma tendsto_id' {x y : filter α} : x ≤ y → tendsto id x y :=
by simp [tendsto] { contextual := tt }
lemma tendsto_id {x : filter α} : tendsto id x x := tendsto_id' $ le_refl x
lemma tendsto.comp {f : α → β} {g : β → γ} {x : filter α} {y : filter β} {z : filter γ}
(hf : tendsto f x y) (hg : tendsto g y z) : tendsto (g ∘ f) x z :=
calc map (g ∘ f) x = map g (map f x) : by rw [map_map]
... ≤ map g y : map_mono hf
... ≤ z : hg
lemma tendsto_le_left {f : α → β} {x y : filter α} {z : filter β}
(h : y ≤ x) : tendsto f x z → tendsto f y z :=
le_trans (map_mono h)
lemma tendsto_le_right {f : α → β} {x : filter α} {y z : filter β}
(h₁ : y ≤ z) (h₂ : tendsto f x y) : tendsto f x z :=
le_trans h₂ h₁
lemma tendsto_map {f : α → β} {x : filter α} : tendsto f x (map f x) := le_refl (map f x)
lemma tendsto_map' {f : β → γ} {g : α → β} {x : filter α} {y : filter γ}
(h : tendsto (f ∘ g) x y) : tendsto f (map g x) y :=
by rwa [tendsto, map_map]
lemma tendsto_vmap {f : α → β} {x : filter β} : tendsto f (vmap f x) x :=
map_vmap_le
lemma tendsto_vmap_iff {f : α → β} {g : β → γ} {a : filter α} {c : filter γ} :
tendsto f a (c.vmap g) ↔ tendsto (g ∘ f) a c :=
⟨assume h, h.comp tendsto_vmap, assume h, map_le_iff_le_vmap.mp $ by rwa [map_map]⟩
lemma tendsto_vmap'' {m : α → β} {f : filter α} {g : filter β} (s : set α)
{i : γ → α} (hs : s ∈ f.sets) (hi : ∀a∈s, ∃c, i c = a)
(h : tendsto (m ∘ i) (vmap i f) g) : tendsto m f g :=
have tendsto m (map i $ vmap i $ f) g,
by rwa [tendsto, ←map_compose] at h,
le_trans (map_mono $ le_map_vmap' hs hi) this
lemma tendsto_inf {f : α → β} {x : filter α} {y₁ y₂ : filter β} :
tendsto f x (y₁ ⊓ y₂) ↔ tendsto f x y₁ ∧ tendsto f x y₂ :=
by simp [tendsto]
lemma tendsto_inf_left {f : α → β} {x₁ x₂ : filter α} {y : filter β}
(h : tendsto f x₁ y) : tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_left) h
lemma tendsto_inf_right {f : α → β} {x₁ x₂ : filter α} {y : filter β}
(h : tendsto f x₂ y) : tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_right) h
lemma tendsto_infi {f : α → β} {x : filter α} {y : ι → filter β} :
tendsto f x (⨅i, y i) ↔ ∀i, tendsto f x (y i) :=
by simp [tendsto]
lemma tendsto_infi' {f : α → β} {x : ι → filter α} {y : filter β} (i : ι) :
tendsto f (x i) y → tendsto f (⨅i, x i) y :=
tendsto_le_left (infi_le _ _)
lemma tendsto_principal {f : α → β} {a : filter α} {s : set β} :
tendsto f a (principal s) ↔ {a | f a ∈ s} ∈ a.sets :=
by simp [tendsto]
lemma tendsto_principal_principal {f : α → β} {s : set α} {t : set β} :
tendsto f (principal s) (principal t) ↔ ∀a∈s, f a ∈ t :=
by simp [tendsto, image_subset_iff]; refl
section lift
/-- A variant on `bind` using a function `g` taking a set
instead of a member of `α`. -/
protected def lift (f : filter α) (g : set α → filter β) :=
⨅s ∈ f.sets, g s
variables {f f₁ f₂ : filter α} {g g₁ g₂ : set α → filter β}
lemma lift_sets_eq (hg : monotone g) : (f.lift g).sets = (⋃t∈f.sets, (g t).sets) :=
infi_sets_eq'
(assume s hs t ht, ⟨s ∩ t, inter_mem_sets hs ht,
hg $ inter_subset_left s t, hg $ inter_subset_right s t⟩)
⟨univ, univ_mem_sets⟩
lemma mem_lift {s : set β} {t : set α} (ht : t ∈ f.sets) (hs : s ∈ (g t).sets) :
s ∈ (f.lift g).sets :=
le_principal_iff.mp $ show f.lift g ≤ principal s,
from infi_le_of_le t $ infi_le_of_le ht $ le_principal_iff.mpr hs
lemma mem_lift_sets (hg : monotone g) {s : set β} :
s ∈ (f.lift g).sets ↔ (∃t∈f.sets, s ∈ (g t).sets) :=
by rw [lift_sets_eq hg]; simp only [mem_Union]
lemma lift_le {f : filter α} {g : set α → filter β} {h : filter β} {s : set α}
(hs : s ∈ f.sets) (hg : g s ≤ h) : f.lift g ≤ h :=
infi_le_of_le s $ infi_le_of_le hs $ hg
lemma le_lift {f : filter α} {g : set α → filter β} {h : filter β}
(hh : ∀s∈f.sets, h ≤ g s) : h ≤ f.lift g :=
le_infi $ assume s, le_infi $ assume hs, hh s hs
lemma lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ :=
infi_le_infi $ assume s, infi_le_infi2 $ assume hs, ⟨hf hs, hg s⟩
lemma lift_mono' (hg : ∀s∈f.sets, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ :=
infi_le_infi $ assume s, infi_le_infi $ assume hs, hg s hs
lemma map_lift_eq {m : β → γ} (hg : monotone g) : map m (f.lift g) = f.lift (map m ∘ g) :=
have monotone (map m ∘ g),
from monotone_comp hg monotone_map,
filter_eq $ set.ext $
by simp [mem_lift_sets, hg, @mem_lift_sets _ _ f _ this]
lemma vmap_lift_eq {m : γ → β} (hg : monotone g) : vmap m (f.lift g) = f.lift (vmap m ∘ g) :=
have monotone (vmap m ∘ g),
from monotone_comp hg monotone_vmap,
filter_eq $ set.ext begin
simp only [hg, @mem_lift_sets _ _ f _ this, vmap, mem_lift_sets, mem_set_of_eq, exists_prop,
function.comp_apply],
exact λ s,
⟨λ ⟨b, ⟨a, ha, hb⟩, hs⟩, ⟨a, ha, b, hb, hs⟩,
λ ⟨a, ha, b, hb, hs⟩, ⟨b, ⟨a, ha, hb⟩, hs⟩⟩
end
theorem vmap_lift_eq2 {m : β → α} {g : set β → filter γ} (hg : monotone g) :
(vmap m f).lift g = f.lift (g ∘ preimage m) :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le (preimage m s) $ infi_le _ ⟨s, hs, subset.refl _⟩)
(le_infi $ assume s, le_infi $ assume ⟨s', hs', (h_sub : preimage m s' ⊆ s)⟩,
infi_le_of_le s' $ infi_le_of_le hs' $ hg h_sub)
lemma map_lift_eq2 {g : set β → filter γ} {m : α → β} (hg : monotone g) :
(map m f).lift g = f.lift (g ∘ image m) :=
le_antisymm
(infi_le_infi2 $ assume s, ⟨image m s,
infi_le_infi2 $ assume hs, ⟨
f.upwards_sets hs $ assume a h, mem_image_of_mem _ h,
le_refl _⟩⟩)
(infi_le_infi2 $ assume t, ⟨preimage m t,
infi_le_infi2 $ assume ht, ⟨ht,
hg $ assume x, assume h : x ∈ m '' preimage m t,
let ⟨y, hy, h_eq⟩ := h in
show x ∈ t, from h_eq ▸ hy⟩⟩)
lemma lift_comm {g : filter β} {h : set α → set β → filter γ} :
f.lift (λs, g.lift (h s)) = g.lift (λt, f.lift (λs, h s t)) :=
le_antisymm
(le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj,
infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi)
(le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj,
infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi)
lemma lift_assoc {h : set β → filter γ} (hg : monotone g) :
(f.lift g).lift h = f.lift (λs, (g s).lift h) :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le t $ infi_le _ $ (mem_lift_sets hg).mpr ⟨_, hs, ht⟩)
(le_infi $ assume t, le_infi $ assume ht,
let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht in
infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le t $ infi_le _ h')
lemma lift_lift_same_le_lift {g : set α → set α → filter β} :
f.lift (λs, f.lift (g s)) ≤ f.lift (λs, g s s) :=
le_infi $ assume s, le_infi $ assume hs, infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le _ hs
lemma lift_lift_same_eq_lift {g : set α → set α → filter β}
(hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)):
f.lift (λs, f.lift (g s)) = f.lift (λs, g s s) :=
le_antisymm
lift_lift_same_le_lift
(le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le (s ∩ t) $
infi_le_of_le (inter_mem_sets hs ht) $
calc g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) : hg₂ (s ∩ t) (inter_subset_left _ _)
... ≤ g s t : hg₁ s (inter_subset_right _ _))
lemma lift_principal {s : set α} (hg : monotone g) :
(principal s).lift g = g s :=
le_antisymm
(infi_le_of_le s $ infi_le _ $ subset.refl _)
(le_infi $ assume t, le_infi $ assume hi, hg hi)
theorem monotone_lift [preorder γ] {f : γ → filter α} {g : γ → set α → filter β}
(hf : monotone f) (hg : monotone g) : monotone (λc, (f c).lift (g c)) :=
assume a b h, lift_mono (hf h) (hg h)
lemma lift_neq_bot_iff (hm : monotone g) : (f.lift g ≠ ⊥) ↔ (∀s∈f.sets, g s ≠ ⊥) :=
classical.by_cases
(assume hn : nonempty β,
calc f.lift g ≠ ⊥ ↔ (⨅s : { s // s ∈ f.sets}, g s.val) ≠ ⊥ : by simp [filter.lift, infi_subtype]
... ↔ (∀s:{ s // s ∈ f.sets}, g s.val ≠ ⊥) :
infi_neq_bot_iff_of_directed hn
(assume ⟨a, ha⟩ ⟨b, hb⟩, ⟨⟨a ∩ b, inter_mem_sets ha hb⟩,
hm $ inter_subset_left _ _, hm $ inter_subset_right _ _⟩)
... ↔ (∀s∈f.sets, g s ≠ ⊥) : ⟨assume h s hs, h ⟨s, hs⟩, assume h ⟨s, hs⟩, h s hs⟩)
(assume hn : ¬ nonempty β,
have h₁ : f.lift g = ⊥, from filter_eq_bot_of_not_nonempty hn,
have h₂ : ∀s, g s = ⊥, from assume s, filter_eq_bot_of_not_nonempty hn,
calc (f.lift g ≠ ⊥) ↔ false : by simp [h₁]
... ↔ (∀s∈f.sets, false) : ⟨false.elim, assume h, h univ univ_mem_sets⟩
... ↔ (∀s∈f.sets, g s ≠ ⊥) : by simp [h₂])
@[simp] lemma lift_const {f : filter α} {g : filter β} : f.lift (λx, g) = g :=
le_antisymm (lift_le univ_mem_sets $ le_refl g) (le_lift $ assume s hs, le_refl g)
@[simp] lemma lift_inf {f : filter α} {g h : set α → filter β} :
f.lift (λx, g x ⊓ h x) = f.lift g ⊓ f.lift h :=
by simp [filter.lift, infi_inf_eq]
@[simp] lemma lift_principal2 {f : filter α} : f.lift principal = f :=
le_antisymm
(assume s hs, mem_lift hs (mem_principal_self s))
(le_infi $ assume s, le_infi $ assume hs, by simp [hs])
lemma lift_infi {f : ι → filter α} {g : set α → filter β}
(hι : nonempty ι) (hg : ∀{s t}, g s ⊓ g t = g (s ∩ t)) : (infi f).lift g = (⨅i, (f i).lift g) :=
le_antisymm
(le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _))
(assume s,
have g_mono : monotone g,
from assume s t h, le_of_inf_eq $ eq.trans hg $ congr_arg g $ inter_eq_self_of_subset_left h,
have ∀t∈(infi f).sets, (⨅ (i : ι), filter.lift (f i) g) ≤ g t,
from assume t ht, infi_sets_induct ht
(let ⟨i⟩ := hι in infi_le_of_le i $ infi_le_of_le univ $ infi_le _ univ_mem_sets)
(assume i s₁ s₂ hs₁ hs₂,
@hg s₁ s₂ ▸ le_inf (infi_le_of_le i $ infi_le_of_le s₁ $ infi_le _ hs₁) hs₂)
(assume s₁ s₂ hs₁ hs₂, le_trans hs₂ $ g_mono hs₁),
begin
rw [lift_sets_eq g_mono],
simp only [mem_Union, exists_imp_distrib],
exact assume t ht hs, this t ht hs
end)
end lift
section lift'
/-- Specialize `lift` to functions `set α → set β`. This can be viewed as
a generalization of `vmap`. -/
protected def lift' (f : filter α) (h : set α → set β) :=
f.lift (principal ∘ h)
variables {f f₁ f₂ : filter α} {h h₁ h₂ : set α → set β}
lemma mem_lift' {t : set α} (ht : t ∈ f.sets) : h t ∈ (f.lift' h).sets :=
le_principal_iff.mp $ show f.lift' h ≤ principal (h t),
from infi_le_of_le t $ infi_le_of_le ht $ le_refl _
lemma mem_lift'_sets (hh : monotone h) {s : set β} : s ∈ (f.lift' h).sets ↔ (∃t∈f.sets, h t ⊆ s) :=
have monotone (principal ∘ h),
from assume a b h, principal_mono.mpr $ hh h,
by simp [filter.lift', @mem_lift_sets α β f _ this]
lemma lift'_le {f : filter α} {g : set α → set β} {h : filter β} {s : set α}
(hs : s ∈ f.sets) (hg : principal (g s) ≤ h) : f.lift' g ≤ h :=
lift_le hs hg
lemma lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ :=
lift_mono hf $ assume s, principal_mono.mpr $ hh s
lemma lift'_mono' (hh : ∀s∈f.sets, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ :=
infi_le_infi $ assume s, infi_le_infi $ assume hs, principal_mono.mpr $ hh s hs
lemma lift'_cong (hh : ∀s∈f.sets, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ :=
le_antisymm (lift'_mono' $ assume s hs, le_of_eq $ hh s hs) (lift'_mono' $ assume s hs, le_of_eq $ (hh s hs).symm)
lemma map_lift'_eq {m : β → γ} (hh : monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) :=
calc map m (f.lift' h) = f.lift (map m ∘ principal ∘ h) :
map_lift_eq $ monotone_comp hh monotone_principal
... = f.lift' (image m ∘ h) : by simp [function.comp, filter.lift']
lemma map_lift'_eq2 {g : set β → set γ} {m : α → β} (hg : monotone g) :
(map m f).lift' g = f.lift' (g ∘ image m) :=
map_lift_eq2 $ monotone_comp hg monotone_principal
theorem vmap_lift'_eq {m : γ → β} (hh : monotone h) :
vmap m (f.lift' h) = f.lift' (preimage m ∘ h) :=
calc vmap m (f.lift' h) = f.lift (vmap m ∘ principal ∘ h) :
vmap_lift_eq $ monotone_comp hh monotone_principal
... = f.lift' (preimage m ∘ h) : by simp [function.comp, filter.lift']
theorem vmap_lift'_eq2 {m : β → α} {g : set β → set γ} (hg : monotone g) :
(vmap m f).lift' g = f.lift' (g ∘ preimage m) :=
vmap_lift_eq2 $ monotone_comp hg monotone_principal
lemma lift'_principal {s : set α} (hh : monotone h) :
(principal s).lift' h = principal (h s) :=
lift_principal $ monotone_comp hh monotone_principal
lemma principal_le_lift' {t : set β} (hh : ∀s∈f.sets, t ⊆ h s) :
principal t ≤ f.lift' h :=
le_infi $ assume s, le_infi $ assume hs, principal_mono.mpr (hh s hs)
theorem monotone_lift' [preorder γ] {f : γ → filter α} {g : γ → set α → set β}
(hf : monotone f) (hg : monotone g) : monotone (λc, (f c).lift' (g c)) :=
assume a b h, lift'_mono (hf h) (hg h)
lemma lift_lift'_assoc {g : set α → set β} {h : set β → filter γ}
(hg : monotone g) (hh : monotone h) :
(f.lift' g).lift h = f.lift (λs, h (g s)) :=
calc (f.lift' g).lift h = f.lift (λs, (principal (g s)).lift h) :
lift_assoc (monotone_comp hg monotone_principal)
... = f.lift (λs, h (g s)) : by simp [lift_principal, hh]
lemma lift'_lift'_assoc {g : set α → set β} {h : set β → set γ}
(hg : monotone g) (hh : monotone h) :
(f.lift' g).lift' h = f.lift' (λs, h (g s)) :=
lift_lift'_assoc hg (monotone_comp hh monotone_principal)
lemma lift'_lift_assoc {g : set α → filter β} {h : set β → set γ}
(hg : monotone g) : (f.lift g).lift' h = f.lift (λs, (g s).lift' h) :=
lift_assoc hg
lemma lift_lift'_same_le_lift' {g : set α → set α → set β} :
f.lift (λs, f.lift' (g s)) ≤ f.lift' (λs, g s s) :=
lift_lift_same_le_lift
lemma lift_lift'_same_eq_lift' {g : set α → set α → set β}
(hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)):
f.lift (λs, f.lift' (g s)) = f.lift' (λs, g s s) :=
lift_lift_same_eq_lift
(assume s, monotone_comp monotone_id $ monotone_comp (hg₁ s) monotone_principal)
(assume t, monotone_comp (hg₂ t) monotone_principal)
lemma lift'_inf_principal_eq {h : set α → set β} {s : set β} :
f.lift' h ⊓ principal s = f.lift' (λt, h t ∩ s) :=
le_antisymm
(le_infi $ assume t, le_infi $ assume ht,
calc filter.lift' f h ⊓ principal s ≤ principal (h t) ⊓ principal s :
inf_le_inf (infi_le_of_le t $ infi_le _ ht) (le_refl _)
... = _ : by simp)
(le_inf
(le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le t $ infi_le_of_le ht $ by simp; exact inter_subset_right _ _)
(infi_le_of_le univ $ infi_le_of_le univ_mem_sets $ by simp; exact inter_subset_left _ _))
lemma lift'_neq_bot_iff (hh : monotone h) : (f.lift' h ≠ ⊥) ↔ (∀s∈f.sets, h s ≠ ∅) :=
calc (f.lift' h ≠ ⊥) ↔ (∀s∈f.sets, principal (h s) ≠ ⊥) :
lift_neq_bot_iff (monotone_comp hh monotone_principal)
... ↔ (∀s∈f.sets, h s ≠ ∅) : by simp [principal_eq_bot_iff]
@[simp] lemma lift'_id {f : filter α} : f.lift' id = f :=
lift_principal2
lemma le_lift' {f : filter α} {h : set α → set β} {g : filter β}
(h_le : ∀s∈f.sets, h s ∈ g.sets) : g ≤ f.lift' h :=
le_infi $ assume s, le_infi $ assume hs, by simp [h_le]; exact h_le s hs
lemma lift_infi' {f : ι → filter α} {g : set α → filter β}
(hι : nonempty ι) (hf : directed (≤) f) (hg : monotone g) : (infi f).lift g = (⨅i, (f i).lift g) :=
le_antisymm
(le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _))
(assume s,
begin
rw [lift_sets_eq hg],
simp only [mem_Union, exists_imp_distrib, infi_sets_eq hf hι],
exact assume t i ht hs, mem_infi_sets i $ mem_lift ht hs
end)
lemma lift'_infi {f : ι → filter α} {g : set α → set β}
(hι : nonempty ι) (hg : ∀{s t}, g s ∩ g t = g (s ∩ t)) : (infi f).lift' g = (⨅i, (f i).lift' g) :=
lift_infi hι $ by simp; apply assume s t, hg
theorem vmap_eq_lift' {f : filter β} {m : α → β} :
vmap m f = f.lift' (preimage m) :=
filter_eq $ set.ext $ by simp [mem_lift'_sets, monotone_preimage, vmap]
end lift'
section prod
variables {s : set α} {t : set β} {f : filter α} {g : filter β}
/- The product filter cannot be defined using the monad structure on filters. For example:
F := do {x <- seq, y <- top, return (x, y)}
hence:
s ∈ F <-> ∃n, [n..∞] × univ ⊆ s
G := do {y <- top, x <- seq, return (x, y)}
hence:
s ∈ G <-> ∀i:ℕ, ∃n, [n..∞] × {i} ⊆ s
Now ⋃i, [i..∞] × {i} is in G but not in F.
As product filter we want to have F as result.
-/
/-- Product of filters. This is the filter generated by cartesian products
of elements of the component filters. -/
protected def prod (f : filter α) (g : filter β) : filter (α × β) :=
f.vmap prod.fst ⊓ g.vmap prod.snd
lemma prod_mem_prod {s : set α} {t : set β} {f : filter α} {g : filter β}
(hs : s ∈ f.sets) (ht : t ∈ g.sets) : set.prod s t ∈ (filter.prod f g).sets :=
inter_mem_inf_sets (preimage_mem_vmap hs) (preimage_mem_vmap ht)
lemma mem_prod_iff {s : set (α×β)} {f : filter α} {g : filter β} :
s ∈ (filter.prod f g).sets ↔ (∃t₁∈f.sets, ∃t₂∈g.sets, set.prod t₁ t₂ ⊆ s) :=
begin
simp [filter.prod],
split,
exact assume ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, h⟩,
⟨s₁, hs₁, s₂, hs₂, subset.trans (inter_subset_inter hts₁ hts₂) h⟩,
exact assume ⟨t₁, ht₁, t₂, ht₂, h⟩,
⟨prod.fst ⁻¹' t₁, ⟨t₁, ht₁, subset.refl _⟩, prod.snd ⁻¹' t₂, ⟨t₂, ht₂, subset.refl _⟩, h⟩
end
lemma tendsto_fst {f : filter α} {g : filter β} : tendsto prod.fst (filter.prod f g) f :=
tendsto_inf_left tendsto_vmap
lemma tendsto_snd {f : filter α} {g : filter β} : tendsto prod.snd (filter.prod f g) g :=
tendsto_inf_right tendsto_vmap
lemma tendsto.prod_mk {f : filter α} {g : filter β} {h : filter γ} {m₁ : α → β} {m₂ : α → γ}
(h₁ : tendsto m₁ f g) (h₂ : tendsto m₂ f h) : tendsto (λx, (m₁ x, m₂ x)) f (filter.prod g h) :=
tendsto_inf.2 ⟨tendsto_vmap_iff.2 h₁, tendsto_vmap_iff.2 h₂⟩
lemma prod_infi_left {f : ι → filter α} {g : filter β} (i : ι) :
filter.prod (⨅i, f i) g = (⨅i, filter.prod (f i) g) :=
by rw [filter.prod, vmap_infi, infi_inf i]; simp [filter.prod]
lemma prod_infi_right {f : filter α} {g : ι → filter β} (i : ι) :
filter.prod f (⨅i, g i) = (⨅i, filter.prod f (g i)) :=
by rw [filter.prod, vmap_infi, inf_infi i]; simp [filter.prod]
lemma prod_mono {f₁ f₂ : filter α} {g₁ g₂ : filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
filter.prod f₁ g₁ ≤ filter.prod f₂ g₂ :=
inf_le_inf (vmap_mono hf) (vmap_mono hg)
lemma prod_vmap_vmap_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
filter.prod (vmap m₁ f₁) (vmap m₂ f₂) = vmap (λp:β₁×β₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) :=
by simp [filter.prod, vmap_vmap_comp]
lemma prod_comm' : filter.prod f g = vmap (prod.swap) (filter.prod g f) :=
by simp [filter.prod, vmap_vmap_comp, function.comp, inf_comm]
lemma prod_comm : filter.prod f g = map (λp:β×α, (p.2, p.1)) (filter.prod g f) :=
by rw [prod_comm', ← map_swap_eq_vmap_swap]; refl
lemma prod_map_map_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
filter.prod (map m₁ f₁) (map m₂ f₂) = map (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) :=
le_antisymm
(assume s hs,
let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs in
filter.upwards_sets _ (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) $
calc set.prod (m₁ '' s₁) (m₂ '' s₂) = (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) '' set.prod s₁ s₂ :
set.prod_image_image_eq
... ⊆ _ : by rwa [image_subset_iff])
((tendsto_fst.comp (le_refl _)).prod_mk (tendsto_snd.comp (le_refl _)))
lemma prod_inf_prod {f₁ f₂ : filter α} {g₁ g₂ : filter β} :
filter.prod f₁ g₁ ⊓ filter.prod f₂ g₂ = filter.prod (f₁ ⊓ f₂) (g₁ ⊓ g₂) :=
by simp only [filter.prod, vmap_inf, inf_comm, inf_assoc, lattice.inf_left_comm]
@[simp] lemma prod_bot1 {f : filter α} : filter.prod f (⊥ : filter β) = ⊥ := by simp [filter.prod]
@[simp] lemma prod_bot2 {g : filter β} : filter.prod (⊥ : filter α) g = ⊥ := by simp [filter.prod]
@[simp] lemma prod_principal_principal {s : set α} {t : set β} :
filter.prod (principal s) (principal t) = principal (set.prod s t) :=
by simp [filter.prod, vmap_principal]; refl
lemma prod_def {f : filter α} {g : filter β} : f.prod g = (f.lift $ λs, g.lift' $ set.prod s) :=
have ∀(s:set α) (t : set β),
principal (set.prod s t) = (principal s).vmap prod.fst ⊓ (principal t).vmap prod.snd,
by simp; intros; refl,
begin
simp [filter.lift', function.comp, this, -vmap_principal, lift_inf],
rw [← vmap_lift_eq monotone_principal, ← vmap_lift_eq monotone_principal],
simp [filter.prod]
end
lemma prod_same_eq : filter.prod f f = f.lift' (λt, set.prod t t) :=
by rw [prod_def];
from lift_lift'_same_eq_lift'
(assume s, set.monotone_prod monotone_const monotone_id)
(assume t, set.monotone_prod monotone_id monotone_const)
lemma mem_prod_same_iff {s : set (α×α)} :
s ∈ (filter.prod f f).sets ↔ (∃t∈f.sets, set.prod t t ⊆ s) :=
by rw [prod_same_eq, mem_lift'_sets]; exact set.monotone_prod monotone_id monotone_id
lemma prod_lift_lift {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → filter β₁} {g₂ : set α₂ → filter β₂}
(hg₁ : monotone g₁) (hg₂ : monotone g₂) :
filter.prod (f₁.lift g₁) (f₂.lift g₂) = f₁.lift (λs, f₂.lift (λt, filter.prod (g₁ s) (g₂ t))) :=
begin
simp only [prod_def],
rw [lift_assoc],
apply congr_arg, funext x,
rw [lift_comm],
apply congr_arg, funext y,
rw [lift'_lift_assoc],
exact hg₂,
exact hg₁
end
lemma prod_lift'_lift' {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → set β₁} {g₂ : set α₂ → set β₂}
(hg₁ : monotone g₁) (hg₂ : monotone g₂) :
filter.prod (f₁.lift' g₁) (f₂.lift' g₂) = f₁.lift (λs, f₂.lift' (λt, set.prod (g₁ s) (g₂ t))) :=
begin
rw [prod_def, lift_lift'_assoc],
apply congr_arg, funext x,
rw [lift'_lift'_assoc],
exact hg₂,
exact set.monotone_prod monotone_const monotone_id,
exact hg₁,
exact (monotone_lift' monotone_const $ monotone_lam $
assume x, set.monotone_prod monotone_id monotone_const)
end
lemma prod_neq_bot {f : filter α} {g : filter β} : filter.prod f g ≠ ⊥ ↔ (f ≠ ⊥ ∧ g ≠ ⊥) :=
calc filter.prod f g ≠ ⊥ ↔ (∀s∈f.sets, g.lift' (set.prod s) ≠ ⊥) :
begin
rw [prod_def, lift_neq_bot_iff],
exact (monotone_lift' monotone_const $ monotone_lam $ assume s, set.monotone_prod monotone_id monotone_const)
end
... ↔ (∀s∈f.sets, ∀t∈g.sets, s ≠ ∅ ∧ t ≠ ∅) :
begin
apply forall_congr, intro s,
apply forall_congr, intro hs,
rw [lift'_neq_bot_iff],
apply forall_congr, intro t,
apply forall_congr, intro ht,
rw [set.prod_neq_empty_iff],
exact set.monotone_prod monotone_const monotone_id
end
... ↔ (∀s∈f.sets, s ≠ ∅) ∧ (∀t∈g.sets, t ≠ ∅) :
⟨assume h, ⟨assume s hs, (h s hs univ univ_mem_sets).left,
assume t ht, (h univ univ_mem_sets t ht).right⟩,
assume ⟨h₁, h₂⟩ s hs t ht, ⟨h₁ s hs, h₂ t ht⟩⟩
... ↔ _ : by simp only [forall_sets_neq_empty_iff_neq_bot]
end prod
/- at_top and at_bot -/
/-- `at_top` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def at_top [preorder α] : filter α := ⨅ a, principal {b | a ≤ b}
/-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def at_bot [preorder α] : filter α := ⨅ a, principal {b | b ≤ a}
lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ (@at_top α _).sets :=
mem_infi_sets a $ subset.refl _
@[simp] lemma at_top_ne_bot [inhabited α] [semilattice_sup α] : (at_top : filter α) ≠ ⊥ :=
infi_neq_bot_of_directed (by apply_instance)
(assume a b, ⟨a ⊔ b, by simp {contextual := tt}⟩)
(assume a, by simp [principal_eq_bot_iff]; exact ne_empty_of_mem (le_refl a))
@[simp] lemma mem_at_top_sets [inhabited α] [semilattice_sup α] {s : set α} :
s ∈ (at_top : filter α).sets ↔ ∃a:α, ∀b≥a, b ∈ s :=
iff.intro
(assume h, infi_sets_induct h ⟨default α, by simp⟩
(assume a s₁ s₂ ha ⟨b, hb⟩, ⟨a ⊔ b,
assume c hc, ⟨ha $ le_trans le_sup_left hc, hb _ $ le_trans le_sup_right hc⟩⟩)
(assume s₁ s₂ h ⟨a, ha⟩, ⟨a, assume b hb, h $ ha _ hb⟩))
(assume ⟨a, h⟩, mem_infi_sets a $ assume x, h x)
lemma map_at_top_eq [inhabited α] [semilattice_sup α] {f : α → β} :
at_top.map f = (⨅a, principal $ f '' {a' | a ≤ a'}) :=
calc map f (⨅a, principal {a' | a ≤ a'}) = (⨅a, map f $ principal {a' | a ≤ a'}) :
map_infi_eq (assume a b, ⟨a ⊔ b, by simp {contextual := tt}⟩) ⟨default α⟩
... = (⨅a, principal $ f '' {a' | a ≤ a'}) : by simp
lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : ∀x, j (i x) = x) :
tendsto (λs:finset γ, s.image j) at_top at_top :=
tendsto_infi.2 $ assume s, tendsto_infi' (s.image i) $ tendsto_principal_principal.2 $
assume t (ht : s.image i ⊆ t),
calc s = (s.image i).image j :
by simp [finset.image_image, (∘), h]; exact finset.image_id.symm
... ⊆ t.image j : finset.image_subset_image ht
/- ultrafilter -/
section ultrafilter
open zorn
variables {f g : filter α}
/-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/
def ultrafilter (f : filter α) := f ≠ ⊥ ∧ ∀g, g ≠ ⊥ → g ≤ f → f ≤ g
lemma ultrafilter_pure {a : α} : ultrafilter (pure a) :=
⟨pure_neq_bot,
assume g hg ha,
have {a} ∈ g.sets, begin simp at ha, assumption end,
show ∀s∈g.sets, {a} ⊆ s, from classical.by_contradiction $
begin
simp only [classical.not_forall, not_imp, exists_imp_distrib, singleton_subset_iff],
exact assume s ⟨hs, hna⟩,
have {a} ∩ s ∈ g.sets, from inter_mem_sets ‹{a} ∈ g.sets› hs,
have ∅ ∈ g.sets, from g.upwards_sets this $
assume x ⟨hxa, hxs⟩, begin simp at hxa; simp [hxa] at hxs, exact hna hxs end,
have g = ⊥, from empty_in_sets_eq_bot.mp this,
hg this
end⟩
lemma ultrafilter_unique (hg : ultrafilter g) (hf : f ≠ ⊥) (h : f ≤ g) : f = g :=
le_antisymm h (hg.right _ hf h)
lemma exists_ultrafilter (h : f ≠ ⊥) : ∃u, u ≤ f ∧ ultrafilter u :=
let
τ := {f' // f' ≠ ⊥ ∧ f' ≤ f},
r : τ → τ → Prop := λt₁ t₂, t₂.val ≤ t₁.val,
⟨a, ha⟩ := inhabited_of_mem_sets h univ_mem_sets,
top : τ := ⟨f, h, le_refl f⟩,
sup : Π(c:set τ), chain r c → τ :=
λc hc, ⟨⨅a:{a:τ // a ∈ insert top c}, a.val.val,
infi_neq_bot_of_directed ⟨a⟩
(directed_of_chain $ chain_insert hc $ assume ⟨b, _, hb⟩ _ _, or.inl hb)
(assume ⟨⟨a, ha, _⟩, _⟩, ha),
infi_le_of_le ⟨top, mem_insert _ _⟩ (le_refl _)⟩
in
have ∀c (hc: chain r c) a (ha : a ∈ c), r a (sup c hc),
from assume c hc a ha, infi_le_of_le ⟨a, mem_insert_of_mem _ ha⟩ (le_refl _),
have (∃ (u : τ), ∀ (a : τ), r u a → r a u),
from zorn (assume c hc, ⟨sup c hc, this c hc⟩) (assume f₁ f₂ f₃ h₁ h₂, le_trans h₂ h₁),
let ⟨uτ, hmin⟩ := this in
⟨uτ.val, uτ.property.right, uτ.property.left, assume g hg₁ hg₂,
hmin ⟨g, hg₁, le_trans hg₂ uτ.property.right⟩ hg₂⟩
lemma le_of_ultrafilter {g : filter α} (hf : ultrafilter f) (h : f ⊓ g ≠ ⊥) :
f ≤ g :=
le_of_inf_eq $ ultrafilter_unique hf h inf_le_left
lemma mem_or_compl_mem_of_ultrafilter (hf : ultrafilter f) (s : set α) :
s ∈ f.sets ∨ - s ∈ f.sets :=
classical.or_iff_not_imp_right.2 $ assume : - s ∉ f.sets,
have f ≤ principal s,
from le_of_ultrafilter hf $ assume h, this $ mem_sets_of_neq_bot $ by simp [*],
by simp at this; assumption
lemma mem_or_mem_of_ultrafilter {s t : set α} (hf : ultrafilter f) (h : s ∪ t ∈ f.sets) :
s ∈ f.sets ∨ t ∈ f.sets :=
(mem_or_compl_mem_of_ultrafilter hf s).imp_right
(assume : -s ∈ f.sets, by filter_upwards [this, h] assume x hnx hx, hx.resolve_left hnx)
lemma mem_of_finite_sUnion_ultrafilter {s : set (set α)} (hf : ultrafilter f) (hs : finite s)
: ⋃₀ s ∈ f.sets → ∃t∈s, t ∈ f.sets :=
finite.induction_on hs (by simp [empty_in_sets_eq_bot, hf.left]) $
λ t s' ht' hs' ih, by simp; exact
assume h, (mem_or_mem_of_ultrafilter hf h).elim
(assume : t ∈ f.sets, ⟨t, or.inl rfl, this⟩)
(assume h, let ⟨t, hts', ht⟩ := ih h in ⟨t, or.inr hts', ht⟩)
lemma mem_of_finite_Union_ultrafilter {is : set β} {s : β → set α}
(hf : ultrafilter f) (his : finite is) (h : (⋃i∈is, s i) ∈ f.sets) : ∃i∈is, s i ∈ f.sets :=
have his : finite (image s is), from finite_image s his,
have h : (⋃₀ image s is) ∈ f.sets, from by simp [sUnion_image]; assumption,
let ⟨t, ⟨i, hi, h_eq⟩, (ht : t ∈ f.sets)⟩ := mem_of_finite_sUnion_ultrafilter hf his h in
⟨i, hi, h_eq.symm ▸ ht⟩
lemma ultrafilter_of_split {f : filter α} (hf : f ≠ ⊥) (h : ∀s, s ∈ f.sets ∨ - s ∈ f.sets) :
ultrafilter f :=
⟨hf, assume g hg g_le s hs, (h s).elim id $
assume : - s ∈ f.sets,
have s ∩ -s ∈ g.sets, from inter_mem_sets hs (g_le this),
by simp [empty_in_sets_eq_bot, hg] at this; contradiction⟩
lemma ultrafilter_map {f : filter α} {m : α → β} (h : ultrafilter f) : ultrafilter (map m f) :=
ultrafilter_of_split (by simp [map_eq_bot_iff, h.left]) $
assume s, show preimage m s ∈ f.sets ∨ - preimage m s ∈ f.sets,
from mem_or_compl_mem_of_ultrafilter h (preimage m s)
/-- Construct an ultrafilter extending a given filter.
The ultrafilter lemma is the assertion that such a filter exists;
we use the axiom of choice to pick one. -/
noncomputable def ultrafilter_of (f : filter α) : filter α :=
if h : f = ⊥ then ⊥ else epsilon (λu, u ≤ f ∧ ultrafilter u)
lemma ultrafilter_of_spec (h : f ≠ ⊥) : ultrafilter_of f ≤ f ∧ ultrafilter (ultrafilter_of f) :=
begin
have h' := epsilon_spec (exists_ultrafilter h),
simp [ultrafilter_of, dif_neg, h],
simp at h',
assumption
end
lemma ultrafilter_of_le : ultrafilter_of f ≤ f :=
if h : f = ⊥ then by simp [ultrafilter_of, dif_pos, h]; exact le_refl _
else (ultrafilter_of_spec h).left
lemma ultrafilter_ultrafilter_of (h : f ≠ ⊥) : ultrafilter (ultrafilter_of f) :=
(ultrafilter_of_spec h).right
lemma ultrafilter_of_ultrafilter (h : ultrafilter f) : ultrafilter_of f = f :=
ultrafilter_unique h (ultrafilter_ultrafilter_of h.left).left ultrafilter_of_le
end ultrafilter
end filter
|
3a4756f161d0d41f433a2cfbb14b1334a614ecc4 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/category_theory/concrete_category/bundled.lean | 0c4545ba6aa5411dbc626ae85200ab51575babb7 | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 1,802 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl, Reid Barton, Sean Leather
Bundled types.
-/
import tactic.doc_commands
/-!
`bundled c` provides a uniform structure for bundling a type equipped with a type class.
We provide `category` instances for these in `unbundled_hom.lean` (for categories with unbundled
homs, e.g. topological spaces) and in `bundled_hom.lean` (for categories with bundled homs, e.g.
monoids).
-/
universes u v
namespace category_theory
variables {c d : Type u → Type v} {α : Type u}
/-- `bundled` is a type bundled with a type class instance for that type. Only
the type class is exposed as a parameter. -/
structure bundled (c : Type u → Type v) : Type (max (u+1) v) :=
(α : Type u)
(str : c α . tactic.apply_instance)
namespace bundled
/-- A generic function for lifting a type equipped with an instance to a bundled object. -/
-- Usually explicit instances will provide their own version of this, e.g. `Mon.of` and `Top.of`.
def of {c : Type u → Type v} (α : Type u) [str : c α] : bundled c := ⟨α, str⟩
instance : has_coe_to_sort (bundled c) :=
{ S := Type u, coe := bundled.α }
/-
`bundled.map` is reducible so that, if we define a category
def Ring : Type (u+1) := induced_category SemiRing (bundled.map @ring.to_semiring)
instance search is able to "see" that a morphism R ⟶ S in Ring is really
a (semi)ring homomorphism from R.α to S.α, and not merely from
`(bundled.map @ring.to_semiring R).α` to `(bundled.map @ring.to_semiring S).α`.
-/
/-- Map over the bundled structure -/
@[reducible] def map (f : Π {α}, c α → d α) (b : bundled c) : bundled d :=
⟨b.α, f b.str⟩
end bundled
end category_theory
|
361b4ebc87ea4b11b0d0667db1d0a961dc9be3f9 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/inner_product_space/orientation.lean | 1ef0aad32c72a23e3d491652ce9621dec10fd7bd | [
"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 | 2,310 | lean | /-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import analysis.inner_product_space.projection
import linear_algebra.orientation
/-!
# Orientations of real inner product spaces.
This file provides definitions and proves lemmas about orientations of real inner product spaces.
## Main definitions
* `orientation.fin_orthonormal_basis` is an orthonormal basis, indexed by `fin n`, with the given
orientation.
-/
noncomputable theory
variables {E : Type*} [inner_product_space ℝ E]
variables {ι : Type*} [fintype ι] [decidable_eq ι]
open finite_dimensional
/-- `basis.adjust_to_orientation`, applied to an orthonormal basis, produces an orthonormal
basis. -/
lemma orthonormal.orthonormal_adjust_to_orientation [nonempty ι] {e : basis ι ℝ E}
(h : orthonormal ℝ e) (x : orientation ℝ E ι) : orthonormal ℝ (e.adjust_to_orientation x) :=
h.orthonormal_of_forall_eq_or_eq_neg (e.adjust_to_orientation_apply_eq_or_eq_neg x)
/-- An orthonormal basis, indexed by `fin n`, with the given orientation. -/
protected def orientation.fin_orthonormal_basis {n : ℕ} (hn : 0 < n) (h : finrank ℝ E = n)
(x : orientation ℝ E (fin n)) : basis (fin n) ℝ E :=
begin
haveI := fin.pos_iff_nonempty.1 hn,
haveI := finite_dimensional_of_finrank (h.symm ▸ hn : 0 < finrank ℝ E),
exact (fin_orthonormal_basis h).adjust_to_orientation x
end
/-- `orientation.fin_orthonormal_basis` is orthonormal. -/
protected lemma orientation.fin_orthonormal_basis_orthonormal {n : ℕ} (hn : 0 < n)
(h : finrank ℝ E = n) (x : orientation ℝ E (fin n)) :
orthonormal ℝ (x.fin_orthonormal_basis hn h) :=
begin
haveI := fin.pos_iff_nonempty.1 hn,
haveI := finite_dimensional_of_finrank (h.symm ▸ hn : 0 < finrank ℝ E),
exact (fin_orthonormal_basis_orthonormal h).orthonormal_adjust_to_orientation _
end
/-- `orientation.fin_orthonormal_basis` gives a basis with the required orientation. -/
@[simp] lemma orientation.fin_orthonormal_basis_orientation {n : ℕ} (hn : 0 < n)
(h : finrank ℝ E = n) (x : orientation ℝ E (fin n)) :
(x.fin_orthonormal_basis hn h).orientation = x :=
begin
haveI := fin.pos_iff_nonempty.1 hn,
exact basis.orientation_adjust_to_orientation _ _
end
|
53b35fc0c01b42d80398ef0a641e9a026aa93b1a | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/limits/pi.lean | 870d341575665e4f1d7fc853e591605157407763 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 4,505 | 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.pi.basic
import category_theory.limits.has_limits
/-!
# Limits in the category of indexed families of objects.
Given a functor `F : J ⥤ Π i, C i` into a category of indexed families,
1. we can assemble a collection of cones over `F ⋙ pi.eval C i` into a cone over `F`
2. if all those cones are limit cones, the assembled cone is a limit cone, and
3. if we have limits for each of `F ⋙ pi.eval C i`, we can produce a
`has_limit F` instance
-/
open category_theory
open category_theory.limits
namespace category_theory.pi
universes v₁ v₂ u₁ u₂
variables {I : Type v₁} {C : I → Type u₁} [Π i, category.{v₁} (C i)]
variables {J : Type v₁} [small_category J]
variables {F : J ⥤ Π i, C i}
/--
A cone over `F : J ⥤ Π i, C i` has as its components cones over each of the `F ⋙ pi.eval C i`.
-/
def cone_comp_eval (c : cone F) (i : I) : cone (F ⋙ pi.eval C i) :=
{ X := c.X i,
π :=
{ app := λ j, c.π.app j i,
naturality' := λ j j' f, congr_fun (c.π.naturality f) i, } }
/--
A cocone over `F : J ⥤ Π i, C i` has as its components cocones over each of the `F ⋙ pi.eval C i`.
-/
def cocone_comp_eval (c : cocone F) (i : I) : cocone (F ⋙ pi.eval C i) :=
{ X := c.X i,
ι :=
{ app := λ j, c.ι.app j i,
naturality' := λ j j' f, congr_fun (c.ι.naturality f) i, } }
/--
Given a family of cones over the `F ⋙ pi.eval C i`, we can assemble these together as a `cone F`.
-/
def cone_of_cone_comp_eval (c : Π i, cone (F ⋙ pi.eval C i)) : cone F :=
{ X := λ i, (c i).X,
π :=
{ app := λ j i, (c i).π.app j,
naturality' := λ j j' f, by { ext i, exact (c i).π.naturality f, } } }
/--
Given a family of cocones over the `F ⋙ pi.eval C i`,
we can assemble these together as a `cocone F`.
-/
def cocone_of_cocone_comp_eval (c : Π i, cocone (F ⋙ pi.eval C i)) : cocone F :=
{ X := λ i, (c i).X,
ι :=
{ app := λ j i, (c i).ι.app j,
naturality' := λ j j' f, by { ext i, exact (c i).ι.naturality f, } } }
/--
Given a family of limit cones over the `F ⋙ pi.eval C i`,
assembling them together as a `cone F` produces a limit cone.
-/
def cone_of_cone_eval_is_limit {c : Π i, cone (F ⋙ pi.eval C i)} (P : Π i, is_limit (c i)) :
is_limit (cone_of_cone_comp_eval c) :=
{ lift := λ s i, (P i).lift (cone_comp_eval s i),
fac' := λ s j,
begin
ext i,
exact (P i).fac (cone_comp_eval s i) j,
end,
uniq' := λ s m w,
begin
ext i,
exact (P i).uniq (cone_comp_eval s i) (m i) (λ j, congr_fun (w j) i)
end }
/--
Given a family of colimit cocones over the `F ⋙ pi.eval C i`,
assembling them together as a `cocone F` produces a colimit cocone.
-/
def cocone_of_cocone_eval_is_colimit
{c : Π i, cocone (F ⋙ pi.eval C i)} (P : Π i, is_colimit (c i)) :
is_colimit (cocone_of_cocone_comp_eval c) :=
{ desc := λ s i, (P i).desc (cocone_comp_eval s i),
fac' := λ s j,
begin
ext i,
exact (P i).fac (cocone_comp_eval s i) j,
end,
uniq' := λ s m w,
begin
ext i,
exact (P i).uniq (cocone_comp_eval s i) (m i) (λ j, congr_fun (w j) i)
end }
section
variables [∀ i, has_limit (F ⋙ pi.eval C i)]
/--
If we have a functor `F : J ⥤ Π i, C i` into a category of indexed families,
and we have limits for each of the `F ⋙ pi.eval C i`,
then `F` has a limit.
-/
lemma has_limit_of_has_limit_comp_eval : has_limit F :=
has_limit.mk
{ cone := cone_of_cone_comp_eval (λ i, limit.cone _),
is_limit := cone_of_cone_eval_is_limit (λ i, limit.is_limit _), }
end
section
variables [∀ i, has_colimit (F ⋙ pi.eval C i)]
/--
If we have a functor `F : J ⥤ Π i, C i` into a category of indexed families,
and colimits exist for each of the `F ⋙ pi.eval C i`,
there is a colimit for `F`.
-/
lemma has_colimit_of_has_colimit_comp_eval : has_colimit F :=
has_colimit.mk
{ cocone := cocone_of_cocone_comp_eval (λ i, colimit.cocone _),
is_colimit := cocone_of_cocone_eval_is_colimit (λ i, colimit.is_colimit _), }
end
/-!
As an example, we can use this to construct particular shapes of limits
in a category of indexed families.
With the addition of
`import category_theory.limits.shapes.types`
we can use:
```
local attribute [instance] has_limit_of_has_limit_comp_eval
example : has_binary_products (I → Type v₁) := ⟨by apply_instance⟩
```
-/
end category_theory.pi
|
f6a5861509d6f59e4e52814f6c77c0d6188ddfdd | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/lie/subalgebra.lean | 7c39d3779ae92eb8ce89edcad0fb39724f649160 | [
"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 | 23,487 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.basic
import ring_theory.noetherian
/-!
# Lie subalgebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and
results.
## Main definitions
* `lie_subalgebra`
* `lie_subalgebra.incl`
* `lie_subalgebra.map`
* `lie_hom.range`
* `lie_equiv.of_injective`
* `lie_equiv.of_eq`
* `lie_equiv.of_subalgebra`
* `lie_equiv.of_subalgebras`
## Tags
lie algebra, lie subalgebra
-/
universes u v w w₁ w₂
section lie_subalgebra
variables (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
/-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie algebra. -/
structure lie_subalgebra extends submodule R L :=
(lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier)
attribute [nolint doc_blame] lie_subalgebra.to_submodule
/-- The zero algebra is a subalgebra of any Lie algebra. -/
instance : has_zero (lie_subalgebra R L) :=
⟨{ lie_mem' := λ x y hx hy, by { rw [((submodule.mem_bot R).1 hx), zero_lie],
exact submodule.zero_mem (0 : submodule R L), },
..(0 : submodule R L) }⟩
instance : inhabited (lie_subalgebra R L) := ⟨0⟩
instance : has_coe (lie_subalgebra R L) (submodule R L) := ⟨lie_subalgebra.to_submodule⟩
namespace lie_subalgebra
instance : set_like (lie_subalgebra R L) L :=
{ coe := λ L', L',
coe_injective' := λ L' L'' h, by { rcases L' with ⟨⟨⟩⟩, rcases L'' with ⟨⟨⟩⟩, congr' } }
instance : add_subgroup_class (lie_subalgebra R L) L :=
{ add_mem := λ L' _ _, L'.add_mem',
zero_mem := λ L', L'.zero_mem',
neg_mem := λ L' x hx, show -x ∈ (L' : submodule R L), from neg_mem hx }
/-- A Lie subalgebra forms a new Lie ring. -/
instance (L' : lie_subalgebra R L) : lie_ring L' :=
{ bracket := λ x y, ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩,
lie_add := by { intros, apply set_coe.ext, apply lie_add, },
add_lie := by { intros, apply set_coe.ext, apply add_lie, },
lie_self := by { intros, apply set_coe.ext, apply lie_self, },
leibniz_lie := by { intros, apply set_coe.ext, apply leibniz_lie, } }
section
variables {R₁ : Type*} [semiring R₁]
/-- A Lie subalgebra inherits module structures from `L`. -/
instance [has_smul R₁ R] [module R₁ L] [is_scalar_tower R₁ R L]
(L' : lie_subalgebra R L) : module R₁ L' :=
L'.to_submodule.module'
instance [has_smul R₁ R] [has_smul R₁ᵐᵒᵖ R] [module R₁ L] [module R₁ᵐᵒᵖ L]
[is_scalar_tower R₁ R L] [is_scalar_tower R₁ᵐᵒᵖ R L] [is_central_scalar R₁ L]
(L' : lie_subalgebra R L) : is_central_scalar R₁ L' :=
L'.to_submodule.is_central_scalar
instance [has_smul R₁ R] [module R₁ L] [is_scalar_tower R₁ R L]
(L' : lie_subalgebra R L) : is_scalar_tower R₁ R L' :=
L'.to_submodule.is_scalar_tower
instance (L' : lie_subalgebra R L) [is_noetherian R L] : is_noetherian R L' :=
is_noetherian_submodule' ↑L'
end
/-- A Lie subalgebra forms a new Lie algebra. -/
instance (L' : lie_subalgebra R L) : lie_algebra R L' :=
{ lie_smul := by { intros, apply set_coe.ext, apply lie_smul } }
variables {R L} (L' : lie_subalgebra R L)
@[simp] protected lemma zero_mem : (0 : L) ∈ L' := zero_mem L'
protected lemma add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' := add_mem
protected lemma sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' := sub_mem
lemma smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' := (L' : submodule R L).smul_mem t h
lemma lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' := L'.lie_mem' hx hy
@[simp] lemma mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : set L) := iff.rfl
@[simp] lemma mem_mk_iff (S : set L) (h₁ h₂ h₃ h₄) {x : L} :
x ∈ (⟨⟨S, h₁, h₂, h₃⟩, h₄⟩ : lie_subalgebra R L) ↔ x ∈ S :=
iff.rfl
@[simp] lemma mem_coe_submodule {x : L} : x ∈ (L' : submodule R L) ↔ x ∈ L' := iff.rfl
lemma mem_coe {x : L} : x ∈ (L' : set L) ↔ x ∈ L' := iff.rfl
@[simp, norm_cast] lemma coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl
lemma ext_iff (x y : L') : x = y ↔ (x : L) = y := subtype.ext_iff
lemma coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 := (ext_iff L' x 0).symm
@[ext] lemma ext (L₁' L₂' : lie_subalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') :
L₁' = L₂' :=
set_like.ext h
lemma ext_iff' (L₁' L₂' : lie_subalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' :=
set_like.ext_iff
@[simp] lemma mk_coe (S : set L) (h₁ h₂ h₃ h₄) :
((⟨⟨S, h₁, h₂, h₃⟩, h₄⟩ : lie_subalgebra R L) : set L) = S := rfl
@[simp] lemma coe_to_submodule_mk (p : submodule R L) (h) :
(({lie_mem' := h, ..p} : lie_subalgebra R L) : submodule R L) = p :=
by { cases p, refl, }
lemma coe_injective : function.injective (coe : lie_subalgebra R L → set L) :=
set_like.coe_injective
@[norm_cast] theorem coe_set_eq (L₁' L₂' : lie_subalgebra R L) :
(L₁' : set L) = L₂' ↔ L₁' = L₂' := set_like.coe_set_eq
lemma to_submodule_injective :
function.injective (coe : lie_subalgebra R L → submodule R L) :=
λ L₁' L₂' h, by { rw set_like.ext'_iff at h, rw ← coe_set_eq, exact h, }
@[simp] lemma coe_to_submodule_eq_iff (L₁' L₂' : lie_subalgebra R L) :
(L₁' : submodule R L) = (L₂' : submodule R L) ↔ L₁' = L₂' :=
to_submodule_injective.eq_iff
@[norm_cast]
lemma coe_to_submodule : ((L' : submodule R L) : set L) = L' := rfl
section lie_module
variables {M : Type w} [add_comm_group M] [lie_ring_module L M]
variables {N : Type w₁} [add_comm_group N] [lie_ring_module L N] [module R N] [lie_module R L N]
/-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module
`M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/
instance : lie_ring_module L' M :=
{ bracket := λ x m, ⁅(x : L), m⁆,
add_lie := λ x y m, add_lie x y m,
lie_add := λ x y m, lie_add x y m,
leibniz_lie := λ x y m, leibniz_lie x y m, }
@[simp] lemma coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ := rfl
variables [module R M] [lie_module R L M]
/-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of
`L`, we may regard `M` as a Lie module of `L'` by restriction. -/
instance : lie_module R L' M :=
{ smul_lie := λ t x m, by simp only [coe_bracket_of_module, smul_lie, submodule.coe_smul_of_tower],
lie_smul := λ t x m, by simp only [coe_bracket_of_module, lie_smul], }
/-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra
`L' ⊆ L`. -/
def _root_.lie_module_hom.restrict_lie (f : M →ₗ⁅R,L⁆ N) (L' : lie_subalgebra R L) : M →ₗ⁅R,L'⁆ N :=
{ map_lie' := λ x m, f.map_lie ↑x m,
.. (f : M →ₗ[R] N)}
@[simp] lemma _root_.lie_module_hom.coe_restrict_lie (f : M →ₗ⁅R,L⁆ N) :
⇑(f.restrict_lie L') = f :=
rfl
end lie_module
/-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/
def incl : L' →ₗ⁅R⁆ L :=
{ map_lie' := λ x y, by { simp only [linear_map.to_fun_eq_coe, submodule.subtype_apply], refl, },
.. (L' : submodule R L).subtype, }
@[simp] lemma coe_incl : ⇑L'.incl = coe := rfl
/-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/
def incl' : L' →ₗ⁅R,L'⁆ L :=
{ map_lie' := λ x y, by simp only [coe_bracket_of_module, linear_map.to_fun_eq_coe,
submodule.subtype_apply, coe_bracket],
.. (L' : submodule R L).subtype, }
@[simp] lemma coe_incl' : ⇑L'.incl' = coe := rfl
end lie_subalgebra
variables {R L} {L₂ : Type w} [lie_ring L₂] [lie_algebra R L₂]
variables (f : L →ₗ⁅R⁆ L₂)
namespace lie_hom
/-- The range of a morphism of Lie algebras is a Lie subalgebra. -/
def range : lie_subalgebra R L₂ :=
{ lie_mem' := λ x y,
show x ∈ f.to_linear_map.range → y ∈ f.to_linear_map.range → ⁅x, y⁆ ∈ f.to_linear_map.range,
by { repeat { rw linear_map.mem_range }, rintros ⟨x', hx⟩ ⟨y', hy⟩, refine ⟨⁅x', y'⁆, _⟩,
rw [←hx, ←hy], change f ⁅x', y'⁆ = ⁅f x', f y'⁆, rw map_lie, },
..(f : L →ₗ[R] L₂).range }
@[simp] lemma range_coe : (f.range : set L₂) = set.range f :=
linear_map.range_coe ↑f
@[simp] lemma mem_range (x : L₂) : x ∈ f.range ↔ ∃ (y : L), f y = x := linear_map.mem_range
lemma mem_range_self (x : L) : f x ∈ f.range := linear_map.mem_range_self f x
/-- We can restrict a morphism to a (surjective) map to its range. -/
def range_restrict : L →ₗ⁅R⁆ f.range :=
{ map_lie' := λ x y, by { apply subtype.ext, exact f.map_lie x y, },
..(f : L →ₗ[R] L₂).range_restrict, }
@[simp] lemma range_restrict_apply (x : L) : f.range_restrict x = ⟨f x, f.mem_range_self x⟩ := rfl
lemma surjective_range_restrict : function.surjective (f.range_restrict) :=
begin
rintros ⟨y, hy⟩,
erw mem_range at hy, obtain ⟨x, rfl⟩ := hy,
use x,
simp only [subtype.mk_eq_mk, range_restrict_apply],
end
/-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/
noncomputable def equiv_range_of_injective (h : function.injective f) : L ≃ₗ⁅R⁆ f.range :=
lie_equiv.of_bijective f.range_restrict ⟨λ x y hxy,
begin
simp only [subtype.mk_eq_mk, range_restrict_apply] at hxy,
exact h hxy,
end, f.surjective_range_restrict⟩
@[simp] lemma equiv_range_of_injective_apply (h : function.injective f) (x : L) :
f.equiv_range_of_injective h x = ⟨f x, mem_range_self f x⟩ :=
rfl
end lie_hom
lemma submodule.exists_lie_subalgebra_coe_eq_iff (p : submodule R L) :
(∃ (K : lie_subalgebra R L), ↑K = p) ↔ ∀ (x y : L), x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p :=
begin
split,
{ rintros ⟨K, rfl⟩ _ _, exact K.lie_mem', },
{ intros h, use { lie_mem' := h, ..p }, exact lie_subalgebra.coe_to_submodule_mk p _, },
end
namespace lie_subalgebra
variables (K K' : lie_subalgebra R L) (K₂ : lie_subalgebra R L₂)
@[simp] lemma incl_range : K.incl.range = K :=
by { rw ← coe_to_submodule_eq_iff, exact (K : submodule R L).range_subtype, }
/-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
codomain. -/
def map : lie_subalgebra R L₂ :=
{ lie_mem' := λ x y hx hy, by
{ erw submodule.mem_map at hx, rcases hx with ⟨x', hx', hx⟩, rw ←hx,
erw submodule.mem_map at hy, rcases hy with ⟨y', hy', hy⟩, rw ←hy,
erw submodule.mem_map,
exact ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩, },
..((K : submodule R L).map (f : L →ₗ[R] L₂)) }
@[simp] lemma mem_map (x : L₂) : x ∈ K.map f ↔ ∃ (y : L), y ∈ K ∧ f y = x := submodule.mem_map
-- TODO Rename and state for homs instead of equivs.
@[simp] lemma mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) :
x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : submodule R L).map (e : L →ₗ[R] L₂) :=
iff.rfl
/-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
domain. -/
def comap : lie_subalgebra R L :=
{ lie_mem' := λ x y hx hy, by
{ suffices : ⁅f x, f y⁆ ∈ K₂, by { simp [this], }, exact K₂.lie_mem hx hy, },
..((K₂ : submodule R L₂).comap (f : L →ₗ[R] L₂)), }
section lattice_structure
open set
instance : partial_order (lie_subalgebra R L) :=
{ le := λ N N', ∀ ⦃x⦄, x ∈ N → x ∈ N', -- Overriding `le` like this gives a better defeq.
..partial_order.lift (coe : lie_subalgebra R L → set L) coe_injective }
lemma le_def : K ≤ K' ↔ (K : set L) ⊆ K' := iff.rfl
@[simp, norm_cast] lemma coe_submodule_le_coe_submodule : (K : submodule R L) ≤ K' ↔ K ≤ K' :=
iff.rfl
instance : has_bot (lie_subalgebra R L) := ⟨0⟩
@[simp] lemma bot_coe : ((⊥ : lie_subalgebra R L) : set L) = {0} := rfl
@[simp] lemma bot_coe_submodule : ((⊥ : lie_subalgebra R L) : submodule R L) = ⊥ := rfl
@[simp] lemma mem_bot (x : L) : x ∈ (⊥ : lie_subalgebra R L) ↔ x = 0 := mem_singleton_iff
instance : has_top (lie_subalgebra R L) :=
⟨{ lie_mem' := λ x y hx hy, mem_univ ⁅x, y⁆,
..(⊤ : submodule R L) }⟩
@[simp] lemma top_coe : ((⊤ : lie_subalgebra R L) : set L) = univ := rfl
@[simp] lemma top_coe_submodule : ((⊤ : lie_subalgebra R L) : submodule R L) = ⊤ := rfl
@[simp] lemma mem_top (x : L) : x ∈ (⊤ : lie_subalgebra R L) := mem_univ x
lemma _root_.lie_hom.range_eq_map : f.range = map f ⊤ :=
by { ext, simp }
instance : has_inf (lie_subalgebra R L) :=
⟨λ K K', { lie_mem' := λ x y hx hy, mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2),
..(K ⊓ K' : submodule R L) }⟩
instance : has_Inf (lie_subalgebra R L) :=
⟨λ S, { lie_mem' := λ x y hx hy, by
{ simp only [submodule.mem_carrier, mem_Inter, submodule.Inf_coe, mem_set_of_eq,
forall_apply_eq_imp_iff₂, exists_imp_distrib] at *,
intros K hK, exact K.lie_mem (hx K hK) (hy K hK), },
..Inf {(s : submodule R L) | s ∈ S} }⟩
@[simp] theorem inf_coe : (↑(K ⊓ K') : set L) = K ∩ K' := rfl
@[simp] lemma Inf_coe_to_submodule (S : set (lie_subalgebra R L)) :
(↑(Inf S) : submodule R L) = Inf {(s : submodule R L) | s ∈ S} := rfl
@[simp] lemma Inf_coe (S : set (lie_subalgebra R L)) : (↑(Inf S) : set L) = ⋂ s ∈ S, (s : set L) :=
begin
rw [← coe_to_submodule, Inf_coe_to_submodule, submodule.Inf_coe],
ext x,
simpa only [mem_Inter, mem_set_of_eq, forall_apply_eq_imp_iff₂, exists_imp_distrib],
end
lemma Inf_glb (S : set (lie_subalgebra R L)) : is_glb S (Inf S) :=
begin
have h : ∀ (K K' : lie_subalgebra R L), (K : set L) ≤ K' ↔ K ≤ K', { intros, exact iff.rfl, },
apply is_glb.of_image h,
simp only [Inf_coe],
exact is_glb_binfi
end
/-- The set of Lie subalgebras of a Lie algebra form a complete lattice.
We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions
than we would otherwise obtain from `complete_lattice_of_Inf`. -/
instance : complete_lattice (lie_subalgebra R L) :=
{ bot := ⊥,
bot_le := λ N _ h, by { rw mem_bot at h, rw h, exact N.zero_mem', },
top := ⊤,
le_top := λ _ _ _, trivial,
inf := (⊓),
le_inf := λ N₁ N₂ N₃ h₁₂ h₁₃ m hm, ⟨h₁₂ hm, h₁₃ hm⟩,
inf_le_left := λ _ _ _, and.left,
inf_le_right := λ _ _ _, and.right,
..complete_lattice_of_Inf _ Inf_glb }
instance : add_comm_monoid (lie_subalgebra R L) :=
{ add := (⊔),
add_assoc := λ _ _ _, sup_assoc,
zero := ⊥,
zero_add := λ _, bot_sup_eq,
add_zero := λ _, sup_bot_eq,
add_comm := λ _ _, sup_comm, }
instance : canonically_ordered_add_monoid (lie_subalgebra R L) :=
{ add_le_add_left := λ a b, sup_le_sup_left,
exists_add_of_le := λ a b h, ⟨b, (sup_eq_right.2 h).symm⟩,
le_self_add := λ a b, le_sup_left,
..lie_subalgebra.add_comm_monoid,
..lie_subalgebra.complete_lattice }
@[simp] lemma add_eq_sup : K + K' = K ⊔ K' := rfl
@[norm_cast, simp] lemma inf_coe_to_submodule :
(↑(K ⊓ K') : submodule R L) = (K : submodule R L) ⊓ (K' : submodule R L) := rfl
@[simp] lemma mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' :=
by rw [← mem_coe_submodule, ← mem_coe_submodule, ← mem_coe_submodule, inf_coe_to_submodule,
submodule.mem_inf]
lemma eq_bot_iff : K = ⊥ ↔ ∀ (x : L), x ∈ K → x = 0 :=
by { rw eq_bot_iff, exact iff.rfl, }
instance subsingleton_of_bot : subsingleton (lie_subalgebra R ↥(⊥ : lie_subalgebra R L)) :=
begin
apply subsingleton_of_bot_eq_top,
ext ⟨x, hx⟩, change x ∈ ⊥ at hx, rw lie_subalgebra.mem_bot at hx, subst hx,
simp only [true_iff, eq_self_iff_true, submodule.mk_eq_zero, mem_bot],
end
lemma subsingleton_bot : subsingleton ↥(⊥ : lie_subalgebra R L) :=
show subsingleton ((⊥ : lie_subalgebra R L) : set L), by simp
variables (R L)
lemma well_founded_of_noetherian [is_noetherian R L] :
well_founded ((>) : lie_subalgebra R L → lie_subalgebra R L → Prop) :=
let f : ((>) : lie_subalgebra R L → lie_subalgebra R L → Prop) →r
((>) : submodule R L → submodule R L → Prop) :=
{ to_fun := coe,
map_rel' := λ N N' h, h, }
in rel_hom_class.well_founded f (is_noetherian_iff_well_founded.mp infer_instance)
variables {R L K K' f}
section nested_subalgebras
variables (h : K ≤ K')
/-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie
algebras. -/
def hom_of_le : K →ₗ⁅R⁆ K' :=
{ map_lie' := λ x y, rfl,
..submodule.of_le h }
@[simp] lemma coe_hom_of_le (x : K) : (hom_of_le h x : L) = x := rfl
lemma hom_of_le_apply (x : K) : hom_of_le h x = ⟨x.1, h x.2⟩ := rfl
lemma hom_of_le_injective : function.injective (hom_of_le h) :=
λ x y, by simp only [hom_of_le_apply, imp_self, subtype.mk_eq_mk, set_like.coe_eq_coe,
subtype.val_eq_coe]
/-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`,
regarded as Lie algebra in its own right. -/
def of_le : lie_subalgebra R K' := (hom_of_le h).range
@[simp] lemma mem_of_le (x : K') : x ∈ of_le h ↔ (x : L) ∈ K :=
begin
simp only [of_le, hom_of_le_apply, lie_hom.mem_range],
split,
{ rintros ⟨y, rfl⟩, exact y.property, },
{ intros h, use ⟨(x : L), h⟩, simp, },
end
lemma of_le_eq_comap_incl : of_le h = K.comap K'.incl :=
by { ext, rw mem_of_le, refl, }
@[simp] lemma coe_of_le : (of_le h : submodule R K') = (submodule.of_le h).range := rfl
/-- Given nested Lie subalgebras `K ⊆ K'`, there is a natural equivalence from `K` to its image in
`K'`. -/
noncomputable def equiv_of_le : K ≃ₗ⁅R⁆ of_le h :=
(hom_of_le h).equiv_range_of_injective (hom_of_le_injective h)
@[simp] lemma equiv_of_le_apply (x : K) :
equiv_of_le h x = ⟨hom_of_le h x, (hom_of_le h).mem_range_self x⟩ :=
rfl
end nested_subalgebras
lemma map_le_iff_le_comap {K : lie_subalgebra R L} {K' : lie_subalgebra R L₂} :
map f K ≤ K' ↔ K ≤ comap f K' := set.image_subset_iff
lemma gc_map_comap : galois_connection (map f) (comap f) := λ K K', map_le_iff_le_comap
end lattice_structure
section lie_span
variables (R L) (s : set L)
/-- The Lie subalgebra of a Lie algebra `L` generated by a subset `s ⊆ L`. -/
def lie_span : lie_subalgebra R L := Inf {N | s ⊆ N}
variables {R L s}
lemma mem_lie_span {x : L} : x ∈ lie_span R L s ↔ ∀ K : lie_subalgebra R L, s ⊆ K → x ∈ K :=
by { change x ∈ (lie_span R L s : set L) ↔ _, erw Inf_coe, exact set.mem_Inter₂, }
lemma subset_lie_span : s ⊆ lie_span R L s :=
by { intros m hm, erw mem_lie_span, intros K hK, exact hK hm, }
lemma submodule_span_le_lie_span : submodule.span R s ≤ lie_span R L s :=
by { rw submodule.span_le, apply subset_lie_span, }
lemma lie_span_le {K} : lie_span R L s ≤ K ↔ s ⊆ K :=
begin
split,
{ exact set.subset.trans subset_lie_span, },
{ intros hs m hm, rw mem_lie_span at hm, exact hm _ hs, },
end
lemma lie_span_mono {t : set L} (h : s ⊆ t) : lie_span R L s ≤ lie_span R L t :=
by { rw lie_span_le, exact set.subset.trans h subset_lie_span, }
lemma lie_span_eq : lie_span R L (K : set L) = K :=
le_antisymm (lie_span_le.mpr rfl.subset) subset_lie_span
lemma coe_lie_span_submodule_eq_iff {p : submodule R L} :
(lie_span R L (p : set L) : submodule R L) = p ↔ ∃ (K : lie_subalgebra R L), ↑K = p :=
begin
rw p.exists_lie_subalgebra_coe_eq_iff, split; intros h,
{ intros x m hm, rw [← h, mem_coe_submodule], exact lie_mem _ (subset_lie_span hm), },
{ rw [← coe_to_submodule_mk p h, coe_to_submodule, coe_to_submodule_eq_iff, lie_span_eq], },
end
variables (R L)
/-- `lie_span` forms a Galois insertion with the coercion from `lie_subalgebra` to `set`. -/
protected def gi : galois_insertion (lie_span R L : set L → lie_subalgebra R L) coe :=
{ choice := λ s _, lie_span R L s,
gc := λ s t, lie_span_le,
le_l_u := λ s, subset_lie_span,
choice_eq := λ s h, rfl }
@[simp] lemma span_empty : lie_span R L (∅ : set L) = ⊥ :=
(lie_subalgebra.gi R L).gc.l_bot
@[simp] lemma span_univ : lie_span R L (set.univ : set L) = ⊤ :=
eq_top_iff.2 $ set_like.le_def.2 $ subset_lie_span
variables {L}
lemma span_union (s t : set L) : lie_span R L (s ∪ t) = lie_span R L s ⊔ lie_span R L t :=
(lie_subalgebra.gi R L).gc.l_sup
lemma span_Union {ι} (s : ι → set L) : lie_span R L (⋃ i, s i) = ⨆ i, lie_span R L (s i) :=
(lie_subalgebra.gi R L).gc.l_supr
end lie_span
end lie_subalgebra
end lie_subalgebra
namespace lie_equiv
variables {R : Type u} {L₁ : Type v} {L₂ : Type w}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_algebra R L₁] [lie_algebra R L₂]
/-- An injective Lie algebra morphism is an equivalence onto its range. -/
noncomputable def of_injective (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) :
L₁ ≃ₗ⁅R⁆ f.range :=
{ map_lie' := λ x y, by { apply set_coe.ext, simpa },
.. linear_equiv.of_injective (f : L₁ →ₗ[R] L₂) $ by rwa [lie_hom.coe_to_linear_map] }
@[simp] lemma of_injective_apply (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) (x : L₁) :
↑(of_injective f h x) = f x := rfl
variables (L₁' L₁'' : lie_subalgebra R L₁) (L₂' : lie_subalgebra R L₂)
/-- Lie subalgebras that are equal as sets are equivalent as Lie algebras. -/
def of_eq (h : (L₁' : set L₁) = L₁'') : L₁' ≃ₗ⁅R⁆ L₁'' :=
{ map_lie' := λ x y, by { apply set_coe.ext, simp, },
..(linear_equiv.of_eq ↑L₁' ↑L₁''
(by {ext x, change x ∈ (L₁' : set L₁) ↔ x ∈ (L₁'' : set L₁), rw h, } )) }
@[simp] lemma of_eq_apply (L L' : lie_subalgebra R L₁) (h : (L : set L₁) = L') (x : L) :
(↑(of_eq L L' h x) : L₁) = x := rfl
variables (e : L₁ ≃ₗ⁅R⁆ L₂)
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def lie_subalgebra_map : L₁'' ≃ₗ⁅R⁆ (L₁''.map e : lie_subalgebra R L₂) :=
{ map_lie' := λ x y, by { apply set_coe.ext, exact lie_hom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, }
..(linear_equiv.submodule_map (e : L₁ ≃ₗ[R] L₂) ↑L₁'') }
@[simp] lemma lie_subalgebra_map_apply (x : L₁'') : ↑(e.lie_subalgebra_map _ x) = e x := rfl
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def of_subalgebras (h : L₁'.map ↑e = L₂') : L₁' ≃ₗ⁅R⁆ L₂' :=
{ map_lie' := λ x y, by { apply set_coe.ext, exact lie_hom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, },
..(linear_equiv.of_submodules (e : L₁ ≃ₗ[R] L₂) ↑L₁' ↑L₂' (by { rw ←h, refl, })) }
@[simp] lemma of_subalgebras_apply (h : L₁'.map ↑e = L₂') (x : L₁') :
↑(e.of_subalgebras _ _ h x) = e x := rfl
@[simp] lemma of_subalgebras_symm_apply (h : L₁'.map ↑e = L₂') (x : L₂') :
↑((e.of_subalgebras _ _ h).symm x) = e.symm x := rfl
end lie_equiv
|
6abc6d475de3d0ab1a9d6dd34e489a386f81bcf0 | da23b545e1653cafd4ab88b3a42b9115a0b1355f | /src/tidy/rewrite_search/strategy/default.lean | b7dbd3aac8a0110237d5045fa22b7b86315d155c | [] | no_license | minchaowu/lean-tidy | 137f5058896e0e81dae84bf8d02b74101d21677a | 2d4c52d66cf07c59f8746e405ba861b4fa0e3835 | refs/heads/master | 1,585,283,406,120 | 1,535,094,033,000 | 1,535,094,033,000 | 145,945,792 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 22 | lean | import .edit_distance
|
b9a6e7756d0a37f966382705379e5fdc4d5cc401 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/library_search/nat.lean | 784bf45f9b33084d91107c7b5e579343d5e463e8 | [
"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 | 2,473 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import tactic.suggest
import data.nat.order.basic
namespace test.library_search
/- Turn off trace messages so they don't pollute the test build: -/
set_option trace.silence_library_search true
/- For debugging purposes, we can display the list of lemmas: -/
-- set_option trace.suggest true
def lt_one (n : ℕ) := n < 1
lemma zero_lt_one (n : ℕ) (h : n = 0) : lt_one n := by subst h; dsimp [lt_one]; simp
-- Verify that calls to solve_by_elim to discharge subgoals use `rfl`
example : lt_one 0 :=
by library_search
example {n m : ℕ} (h : m < n) : m ≤ n - 1 :=
by library_search -- says: `exact nat.le_pred_of_lt h`
example (a b : ℕ) : 0 < a → 0 < b → 0 < a + b :=
by library_search -- says: `exact add_pos`
section synonym
-- Synonym `>` for `<` in the goal
example (a b : ℕ) : 0 < a → 0 < b → a + b > 0 :=
by library_search -- says: `exact add_pos`
-- Synonym `>` for `<` in another part of the goal
example (a b : ℕ) : a > 0 → 0 < b → 0 < a + b :=
by library_search -- says: `exact add_pos`
end synonym
example {a b c : ℕ} (ha : a > 0) (w : b ∣ c) : a * b ∣ a * c :=
by library_search -- exact mul_dvd_mul_left a w
-- We have control of how `library_search` uses `solve_by_elim`.
-- In particular, we can add extra lemmas to the `solve_by_elim` step
-- (i.e. for `library_search` to use to attempt to discharge subgoals
-- after successfully applying a lemma from the library.)
example {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) :=
begin
library_search [add_lt_add], -- Says: `exact max_eq_left_of_lt (add_lt_add h₁ h₂)`
end
-- We can also use attributes:
meta def ex_attr : user_attribute := {
name := `ex,
descr := "A lemma that should be applied by `library_search` when discharging subgoals."
}
run_cmd attribute.register ``ex_attr
attribute [ex] add_lt_add
example {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) :=
begin
library_search with ex, -- Says: `exact max_eq_left_of_lt (add_lt_add h₁ h₂)`
end
example (a b : ℕ) (h : 0 < b) : (a * b) / b = a :=
by library_search -- Says: `exact nat.mul_div_left a h`
example (a b : ℕ) (h : b ≠ 0) : (a * b) / b = a :=
begin
success_if_fail { library_search },
library_search [pos_iff_ne_zero.mpr],
end
end test.library_search
|
58fba58a124bfcfd7e00149a45034109fec46588 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/ring_theory/algebraic.lean | 7a42f575de9463c91733dcef7adbbcfe0b73b536 | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 3,435 | 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 ring_theory.integral_closure
/-!
# Algebraic elements and algebraic extensions
An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial.
An R-algebra is algebraic over R if and only if all its elements are algebraic over R.
The main result in this file proves transitivity of algebraicity:
a tower of algebraic field extensions is algebraic.
-/
universe variables u v
open_locale classical
open polynomial
section
variables (R : Type u) {A : Type v} [comm_ring R] [comm_ring A] [algebra R A]
/-- An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. -/
def is_algebraic (x : A) : Prop :=
∃ p : polynomial R, p ≠ 0 ∧ aeval R A x p = 0
variables {R}
/-- A subalgebra is algebraic if all its elements are algebraic. -/
def subalgebra.is_algebraic (S : subalgebra R A) : Prop := ∀ x ∈ S, is_algebraic R x
variables (R A)
/-- An algebra is algebraic if all its elements are algebraic. -/
def algebra.is_algebraic : Prop := ∀ x : A, is_algebraic R x
variables {R A}
/-- A subalgebra is algebraic if and only if it is algebraic an algebra. -/
lemma subalgebra.is_algebraic_iff (S : subalgebra R A) :
S.is_algebraic ↔ @algebra.is_algebraic R S _ _ (by convert S.algebra) :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
rw [subtype.forall'],
apply forall_congr, rintro ⟨x, hx⟩,
apply exists_congr, intro p,
apply and_congr iff.rfl,
have h : function.injective (S.val) := subtype.val_injective,
conv_rhs { rw [← h.eq_iff, alg_hom.map_zero], },
apply eq_iff_eq_cancel_right.mpr,
symmetry, apply hom_eval₂,
end
/-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/
lemma algebra.is_algebraic_iff : algebra.is_algebraic R A ↔ (⊤ : subalgebra R A).is_algebraic :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
simp only [algebra.mem_top, forall_prop_of_true, iff_self],
end
end
section zero_ne_one
variables (R : Type u) {A : Type v} [nonzero_comm_ring R] [comm_ring A] [algebra R A]
/-- An integral element of an algebra is algebraic.-/
lemma is_integral.is_algebraic {x : A} (h : is_integral R x) : is_algebraic R x :=
by { rcases h with ⟨p, hp, hpx⟩, exact ⟨p, hp.ne_zero, hpx⟩ }
end zero_ne_one
section field
variables (K : Type u) {A : Type v} [discrete_field K] [comm_ring A] [algebra K A]
/-- An element of an algebra over a field is algebraic if and only if it is integral.-/
lemma is_algebraic_iff_is_integral {x : A} :
is_algebraic K x ↔ is_integral K x :=
begin
refine ⟨_, is_integral.is_algebraic K⟩,
rintro ⟨p, hp, hpx⟩,
refine ⟨_, monic_mul_leading_coeff_inv hp, _⟩,
rw [alg_hom.map_mul, hpx, zero_mul],
end
end field
namespace algebra
variables {K : Type*} {L : Type*} {A : Type*}
variables [discrete_field K] [discrete_field L] [comm_ring A]
variables [algebra K L] [algebra L A]
/-- If L is an algebraic field extension of K and A is an algebraic algebra over L,
then A is algebraic over K. -/
lemma is_algebraic_trans (L_alg : is_algebraic K L) (A_alg : is_algebraic L A) :
is_algebraic K (comap K L A) :=
begin
simp only [is_algebraic, is_algebraic_iff_is_integral] at L_alg A_alg ⊢,
exact is_integral_trans L_alg A_alg,
end
end algebra
|
4acd8a5f30d0fc961fd24b43149fb4e6e9bf537d | d0f9af2b0ace5ce352570d61b09019c8ef4a3b96 | /hw2/justin_ngo-hw2.lean | d8afb2758145506b94bb577b5740dfd145896236 | [] | no_license | jngo13/Discrete-Mathematics | 8671540ef2da7c75915d32332dd20c02f001474e | bf674a866e61f60e6e6d128df85fa73819091787 | refs/heads/master | 1,675,615,657,924 | 1,609,142,011,000 | 1,609,142,011,000 | 267,190,341 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,478 | lean | -- Justin Ngo
-- jmn4fms
-- 2/3/20
-- Sullivan 2102-001
/-
UVa CS2102/Sullivan, Spring 2020, Homework #2
This homework assignment is due by noon on Tuesday,
Feb 4. Submit your result through the HW#2 tab under
the Assignments category on Collab. Do so by uploading
a completed version of this file.
The goal of this assignment is to develop and evaluate
your ability to write simple abstract data types in Lean,
comprising both inductive data definitions and definitions
of functions, in several syntactic styles, that operate
on values of such types.
-/
/- [49 points]
#1. In the space after this comment, first define a data
type, dm_bool, as we did in class, with values dm_tt and
dm_ff. We will take the values of this type to represent
the Boolean algebra truth values, true and false. Then
define functions operating on values of type dm_bool that
implement the Boolean functions, not, and, or, nand, xor,
implies, an equiv (iff).
Note: The heads-up announcement of a few days ago mis-stated
the types of these operations as involving values of type
bool. You must use dm_bool throughout. The point is that you
are now seeing how to specify/implement Boolean algebra, not
just to use Boolean algebra functions built in to a language.
Precede each of your function definitions with a comment
presenting the "truth table" for the function to be
defined. Then *after* each function definition, use Lean's
#eval or #reduce command to test it for all possible
combinations of argument values. For example, you should
have four test cases for each binary function, for each of
the four combinations of two Boolean values. You may use
resources such as Wikipedia to learn the truth tables for
each of these functions if you don't already know them.
-/
inductive dm_bool : Type
| dm_tt : dm_bool --first type of dm_bool
| dm_ff : dm_bool --second type of dm_bool
open dm_bool --data type has its own namespace
def b1 := dm_tt
def b2 := dm_ff
/-
NOT
dm_tt := dm_ff
dm_ff := dm_tt
Truth table for Boolean negation (not)
arg res
-------------
dm_tt | dm_ff
dm_ff | dm_tt
-/
def dm_not :dm_bool → dm_bool := --backslash "to" to get the arrow
λ (b : dm_bool), --lamda expression is defined as a function value
--lamda can be pronounced as "a function"
-- ...that takes in an argument b of type bool and returns a function"
match b with
| dm_tt := dm_ff
| dm_ff := dm_tt
end
#reduce dm_not dm_tt
#reduce dm_not dm_ff
/-
AND
Truth table for "and"
b1 b2 res
---------
tt tt tt
tt ff ff
ff tt ff
ff ff ff
-/
def dm_and : dm_bool → dm_bool → dm_bool :=
λ (b1 b2: dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_tt
| dm_tt, dm_ff := dm_ff
| dm_ff, dm_tt := dm_ff
| dm_ff, dm_ff := dm_ff
end
#reduce dm_and dm_tt dm_tt
#reduce dm_and dm_tt dm_ff
#reduce dm_and dm_ff dm_tt
#reduce dm_and dm_ff dm_ff
/-
OR
Truth table for "or"
b1 b2 res
---------
tt tt tt
tt ff tt
ff tt tt
ff ff ff
-/
def dm_or : dm_bool → dm_bool → dm_bool :=
λ (b1 b2 : dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_tt
| dm_tt, dm_ff := dm_tt
| dm_ff, dm_tt := dm_tt
| dm_ff, dm_ff := dm_ff
end
#reduce dm_or dm_tt dm_tt
#reduce dm_or dm_tt dm_ff
#reduce dm_or dm_ff dm_tt
#reduce dm_or dm_ff dm_ff
/-
NAND
Truth table for "nand"
b1 b2 res
---------
tt tt ff
tt ff tt
ff tt tt
ff ff tt
-/
def dm_nand : dm_bool → dm_bool → dm_bool :=
λ (b1 b2 : dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_ff
| dm_tt, dm_ff := dm_tt
| dm_ff, dm_tt := dm_tt
| dm_ff, dm_ff := dm_tt
end
#reduce dm_nand dm_tt dm_tt
#reduce dm_nand dm_tt dm_ff
#reduce dm_nand dm_ff dm_tt
#reduce dm_nand dm_ff dm_ff
/-
XOR
Truth table for "xor"
b1 b2 res
---------
tt tt ff
tt ff tt
ff tt tt
ff ff ff
-/
def dm_xor : dm_bool → dm_bool → dm_bool :=
λ (b1 b2 : dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_ff
| dm_tt, dm_ff := dm_tt
| dm_ff, dm_tt := dm_tt
| dm_ff, dm_ff := dm_ff
end
#reduce dm_xor dm_tt dm_tt
#reduce dm_xor dm_tt dm_ff
#reduce dm_xor dm_ff dm_tt
#reduce dm_xor dm_ff dm_ff
/-
IMPLIES
Truth table for "implies"
b1 b2 res
---------
tt tt tt
tt ff ff
ff tt tt
ff ff tt
-/
def dm_implies : dm_bool → dm_bool → dm_bool :=
λ (b1 b2 : dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_tt
| dm_tt, dm_ff := dm_ff
| dm_ff, dm_tt := dm_tt
| dm_ff, dm_ff := dm_tt
end
#reduce dm_implies dm_tt dm_tt
#reduce dm_implies dm_tt dm_ff
#reduce dm_implies dm_ff dm_tt
#reduce dm_implies dm_ff dm_ff
/-
IFF
Truth table for "implies"
b1 b2 res
---------
tt tt tt
tt ff ff
ff tt ff
ff ff tt
-/
def dm_iff : dm_bool → dm_bool → dm_bool :=
λ (b1 b2 : dm_bool),
match b1, b2 with
| dm_tt, dm_tt := dm_tt
| dm_tt, dm_ff := dm_ff
| dm_ff, dm_tt := dm_ff
| dm_ff, dm_ff := dm_tt
end
#reduce dm_iff dm_tt dm_tt
#reduce dm_iff dm_tt dm_ff
#reduce dm_iff dm_ff dm_tt
#reduce dm_iff dm_ff dm_ff
/- [51 points]
#2. In a separate file called months.lean, define a new
abstract data type. It will define a data type, months,
the values of which are the names of the months. Use all
lower case names for months, e.g., january.
-/
inductive month : Type
| january : month
| february : month
| march : month
| april : month
| may : month
| june : month
| july : month
| august : month
| september : month
| october : month
| november : month
| december : month
open month --data type has its own namespace
/-
Complete your "month" ADT definition with definitions of
two functions, next_month and is_winter_month, as follows.
However, to practice writing functions in different ways,
write each of the two functions in each of the following
styles, adding "prime" marks to the function names so as
to avoid naming conflicts:
- lambda expression (with a match/with expression)
- C-style (with a match/with expression)
- by cases (no explicit match/with expression needed)
-/
/-
A. Given a month as an argument, return the next month in
the sequence of months of the year. E.g., the function
application, (next_month december), will return january.
-/
-- lambda expression (with a match/with expression)
def next_month : month → month :=
λ (m : month),
match m with
| january := february
| february := march
| march := april
| april := may
| may := june
| june := july
| july := august
| august := september
| september := october
| october := november
| november := december
| december := january
end
#reduce next_month january
#reduce next_month february
#reduce next_month march
#reduce next_month april
#reduce next_month may
#reduce next_month june
#reduce next_month july
#reduce next_month august
#reduce next_month september
#reduce next_month october
#reduce next_month november
#reduce next_month december
-- C-style (with a match/with expression)
def next_month' (m: month): month :=
match m with
| january := february
| february := march
| march := april
| april := may
| may := june
| june := july
| july := august
| august := september
| september := october
| october := november
| november := december
| december := january
end
#reduce next_month' january
#reduce next_month' january
#reduce next_month' february
#reduce next_month' march
#reduce next_month' april
#reduce next_month' may
#reduce next_month' june
#reduce next_month' july
#reduce next_month' august
#reduce next_month' september
#reduce next_month' october
#reduce next_month' november
#reduce next_month' december
-- by cases (no explicit match/with expression needed)
def next_month'' : month → month
| january := february
| february := march
| march := april
| april := may
| may := june
| june := july
| july := august
| august := september
| september := october
| october := november
| november := december
| december := january
#reduce next_month'' january
#reduce next_month'' february
#reduce next_month'' march
#reduce next_month'' april
#reduce next_month'' may
#reduce next_month'' june
#reduce next_month'' july
#reduce next_month'' august
#reduce next_month'' september
#reduce next_month'' october
#reduce next_month'' november
#reduce next_month'' december
/-
B. Given a month as an argument, return the dm_bool
value, dm_tt (representing "true"), if the given month
is a winter month (december, january, or february),
and dm_ff otherwise. Do not use more than four pattern
matching rules.
-/
-- lambda expression (with a match/with expression)
def is_winter_month : month → dm_bool :=
λ (m : month),
match m with
| january := dm_tt
| february := dm_tt
| december := dm_tt
| _ := dm_ff
end
#reduce is_winter_month january
#reduce is_winter_month february
#reduce is_winter_month march
#reduce is_winter_month april
#reduce is_winter_month may
#reduce is_winter_month june
#reduce is_winter_month july
#reduce is_winter_month august
#reduce is_winter_month september
#reduce is_winter_month october
#reduce is_winter_month november
#reduce is_winter_month december
-- C-style (with a match/with expression)
def is_winter_month' (m: month) (dm_tt dm_ff: dm_bool): dm_bool:=
match m with
| january := dm_tt
| february := dm_tt
| december := dm_tt
| _ := dm_ff
end
#reduce is_winter_month' january
#reduce is_winter_month' february
#reduce is_winter_month' march
#reduce is_winter_month' april
#reduce is_winter_month' may
#reduce is_winter_month' june
#reduce is_winter_month' july
#reduce is_winter_month' august
#reduce is_winter_month' september
#reduce is_winter_month' october
#reduce is_winter_month' november
#reduce is_winter_month' december
-- by cases (no explicit match/with expression needed)
def is_winter_month'' : month → dm_bool
| january := dm_tt
| february := dm_tt
| december := dm_tt
| _ := dm_ff
#reduce is_winter_month'' january
#reduce is_winter_month'' february
#reduce is_winter_month'' march
#reduce is_winter_month'' april
#reduce is_winter_month'' may
#reduce is_winter_month'' june
#reduce is_winter_month'' july
#reduce is_winter_month'' august
#reduce is_winter_month'' september
#reduce is_winter_month'' october
#reduce is_winter_month'' november
#reduce is_winter_month'' december |
f76b8bd1a80e0d4319c902336b1e36772d571e1f | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/algebra/mul_action.lean | 60959fe853285a376ddb34470ce4638b5680b5dc | [
"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 | 6,763 | 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.constructions
import group_theory.group_action.prod
import group_theory.group_action.basic
import topology.algebra.const_mul_action
/-!
# Continuous monoid action
In this file we define class `has_continuous_smul`. We say `has_continuous_smul M X` if `M` acts on
`X` and the map `(c, x) ↦ c • x` is continuous on `M × X`. We reuse this class for topological
(semi)modules, vector spaces and algebras.
## Main definitions
* `has_continuous_smul M X` : typeclass saying that the map `(c, x) ↦ c • x` is continuous
on `M × X`;
* `homeomorph.smul_of_ne_zero`: if a group with zero `G₀` (e.g., a field) acts on `X` and `c : G₀`
is a nonzero element of `G₀`, then scalar multiplication by `c` is a homeomorphism of `X`;
* `homeomorph.smul`: scalar multiplication by an element of a group `G` acting on `X`
is a homeomorphism of `X`.
* `units.has_continuous_smul`: scalar multiplication by `Mˣ` is continuous when scalar
multiplication by `M` is continuous. This allows `homeomorph.smul` to be used with on monoids
with `G = 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 pointwise
open filter
/-- Class `has_continuous_smul M X` says that the scalar multiplication `(•) : M → X → X`
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 X : Type*) [has_smul M X]
[topological_space M] [topological_space X] : Prop :=
(continuous_smul : continuous (λp : M × X, p.1 • p.2))
export has_continuous_smul (continuous_smul)
/-- Class `has_continuous_vadd M X` says that the additive action `(+ᵥ) : M → X → X`
is continuous in both arguments. We use the same class for all kinds of additive actions,
including (semi)modules and algebras. -/
class has_continuous_vadd (M X : Type*) [has_vadd M X]
[topological_space M] [topological_space X] : Prop :=
(continuous_vadd : continuous (λp : M × X, p.1 +ᵥ p.2))
export has_continuous_vadd (continuous_vadd)
attribute [to_additive] has_continuous_smul
section main
variables {M X Y α : Type*} [topological_space M] [topological_space X] [topological_space Y]
section has_smul
variables [has_smul M X] [has_continuous_smul M X]
@[priority 100, to_additive] instance has_continuous_smul.has_continuous_const_smul :
has_continuous_const_smul M X :=
{ continuous_const_smul := λ _, continuous_smul.comp (continuous_const.prod_mk continuous_id) }
@[to_additive]
lemma filter.tendsto.smul {f : α → M} {g : α → X} {l : filter α} {c : M} {a : X}
(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)
@[to_additive]
lemma filter.tendsto.smul_const {f : α → M} {l : filter α} {c : M}
(hf : tendsto f l (𝓝 c)) (a : X) :
tendsto (λ x, (f x) • a) l (𝓝 (c • a)) :=
hf.smul tendsto_const_nhds
variables {f : Y → M} {g : Y → X} {b : Y} {s : set Y}
@[to_additive]
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
@[to_additive]
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
@[to_additive]
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)
@[continuity, to_additive]
lemma continuous.smul (hf : continuous f) (hg : continuous g) :
continuous (λ x, f x • g x) :=
continuous_smul.comp (hf.prod_mk hg)
/-- If a scalar is central, then its right action is continuous when its left action is. -/
instance has_continuous_smul.op [has_smul Mᵐᵒᵖ X] [is_central_scalar M X] :
has_continuous_smul Mᵐᵒᵖ X :=
⟨ suffices continuous (λ p : M × X, mul_opposite.op p.fst • p.snd),
from this.comp (mul_opposite.continuous_unop.prod_map continuous_id),
by simpa only [op_smul_eq_smul] using (continuous_smul : continuous (λ p : M × X, _)) ⟩
@[to_additive] instance mul_opposite.has_continuous_smul : has_continuous_smul M Xᵐᵒᵖ :=
⟨mul_opposite.continuous_op.comp $ continuous_smul.comp $
continuous_id.prod_map mul_opposite.continuous_unop⟩
end has_smul
section monoid
variables [monoid M] [mul_action M X] [has_continuous_smul M X]
@[to_additive] instance units.has_continuous_smul : has_continuous_smul Mˣ X :=
{ continuous_smul :=
show continuous ((λ p : M × X, p.fst • p.snd) ∘ (λ p : Mˣ × X, (p.1, p.2))),
from continuous_smul.comp ((units.continuous_coe.comp continuous_fst).prod_mk continuous_snd) }
end monoid
@[to_additive]
instance [has_smul M X] [has_smul M Y] [has_continuous_smul M X]
[has_continuous_smul M Y] :
has_continuous_smul M (X × Y) :=
⟨(continuous_fst.smul (continuous_fst.comp continuous_snd)).prod_mk
(continuous_fst.smul (continuous_snd.comp continuous_snd))⟩
@[to_additive]
instance {ι : Type*} {γ : ι → Type*}
[∀ i, topological_space (γ i)] [Π i, has_smul 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)⟩
end main
section lattice_ops
variables {ι : Sort*} {M X : Type*} [topological_space M] [has_smul M X]
@[to_additive] lemma has_continuous_smul_Inf {ts : set (topological_space X)}
(h : Π t ∈ ts, @has_continuous_smul M X _ _ t) :
@has_continuous_smul M X _ _ (Inf ts) :=
{ continuous_smul :=
begin
rw ← @Inf_singleton _ _ ‹topological_space M›,
exact continuous_Inf_rng (λ t ht, continuous_Inf_dom₂ (eq.refl _) ht
(@has_continuous_smul.continuous_smul _ _ _ _ t (h t ht)))
end }
@[to_additive] lemma has_continuous_smul_infi {ts' : ι → topological_space X}
(h : Π i, @has_continuous_smul M X _ _ (ts' i)) :
@has_continuous_smul M X _ _ (⨅ i, ts' i) :=
has_continuous_smul_Inf $ set.forall_range_iff.mpr h
@[to_additive] lemma has_continuous_smul_inf {t₁ t₂ : topological_space X}
[@has_continuous_smul M X _ _ t₁] [@has_continuous_smul M X _ _ t₂] :
@has_continuous_smul M X _ _ (t₁ ⊓ t₂) :=
by { rw inf_eq_infi, refine has_continuous_smul_infi (λ b, _), cases b; assumption }
end lattice_ops
|
5396b26587852553bd4d3dd4d371bc9a0ad6756b | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /tests/lean/show1.lean | 6827a197a55e706dd22557b6e04781e469d0d4f1 | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 383 | lean | import logic bool tactic
using bool eq_proofs tactic
variables a b c : bool
axiom H1 : a = b
axiom H2 : b = c
check show a = c, from H1 ⬝ H2
print "------------"
check have e1 [fact] : a = b, from H1,
have e2 : a = c, by apply trans; apply e1; apply H2,
have e3 : c = a, from e2⁻¹,
have e4 [fact] : b = a, from e1⁻¹,
show b = c, from e1⁻¹ ⬝ e2
|
53063894ac929d30506933be7afeadb0053b8bab | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/array/lemmas.lean | 1c2fe5140c3eb15335217bcda215841b3d3f4a66 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,577 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import control.traversable.equiv
import data.vector.basic
universes u v w
namespace d_array
variables {n : ℕ} {α : fin n → Type u}
instance [∀ i, inhabited (α i)] : inhabited (d_array n α) :=
⟨⟨λ _, default _⟩⟩
end d_array
namespace array
instance {n α} [inhabited α] : inhabited (array n α) :=
d_array.inhabited
theorem to_list_of_heq {n₁ n₂ α} {a₁ : array n₁ α} {a₂ : array n₂ α}
(hn : n₁ = n₂) (ha : a₁ == a₂) : a₁.to_list = a₂.to_list :=
by congr; assumption
/- rev_list -/
section rev_list
variables {n : ℕ} {α : Type u} {a : array n α}
theorem rev_list_reverse_aux : ∀ i (h : i ≤ n) (t : list α),
(a.iterate_aux (λ _, (::)) i h []).reverse_core t = a.rev_iterate_aux (λ _, (::)) i h t
| 0 h t := rfl
| (i+1) h t := rev_list_reverse_aux i _ _
@[simp] theorem rev_list_reverse : a.rev_list.reverse = a.to_list :=
rev_list_reverse_aux _ _ _
@[simp] theorem to_list_reverse : a.to_list.reverse = a.rev_list :=
by rw [←rev_list_reverse, list.reverse_reverse]
end rev_list
/- mem -/
section mem
variables {n : ℕ} {α : Type u} {v : α} {a : array n α}
theorem mem.def : v ∈ a ↔ ∃ i, a.read i = v :=
iff.rfl
theorem mem_rev_list_aux : ∀ {i} (h : i ≤ n),
(∃ (j : fin n), (j : ℕ) < i ∧ read a j = v) ↔ v ∈ a.iterate_aux (λ _, (::)) i h []
| 0 _ := ⟨λ ⟨i, n, _⟩, absurd n i.val.not_lt_zero, false.elim⟩
| (i+1) h := let IH := mem_rev_list_aux (le_of_lt h) in
⟨λ ⟨j, ji1, e⟩, or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ ji1)
(λ ji, list.mem_cons_of_mem _ $ IH.1 ⟨j, ji, e⟩)
(λ je, by simp [d_array.iterate_aux]; apply or.inl; unfold read at e;
have H : j = ⟨i, h⟩ := fin.eq_of_veq je; rwa [←H, e]),
λ m, begin
simp [d_array.iterate_aux, list.mem] at m,
cases m with e m',
exact ⟨⟨i, h⟩, nat.lt_succ_self _, eq.symm e⟩,
exact let ⟨j, ji, e⟩ := IH.2 m' in
⟨j, nat.le_succ_of_le ji, e⟩
end⟩
@[simp] theorem mem_rev_list : v ∈ a.rev_list ↔ v ∈ a :=
iff.symm $ iff.trans
(exists_congr $ λ j, iff.symm $
show j.1 < n ∧ read a j = v ↔ read a j = v,
from and_iff_right j.2)
(mem_rev_list_aux _)
@[simp] theorem mem_to_list : v ∈ a.to_list ↔ v ∈ a :=
by rw ←rev_list_reverse; exact list.mem_reverse.trans mem_rev_list
end mem
/- foldr -/
section foldr
variables {n : ℕ} {α : Type u} {β : Type w} {b : β} {f : α → β → β} {a : array n α}
theorem rev_list_foldr_aux : ∀ {i} (h : i ≤ n),
(d_array.iterate_aux a (λ _, (::)) i h []).foldr f b = d_array.iterate_aux a (λ _, f) i h b
| 0 h := rfl
| (j+1) h := congr_arg (f (read a ⟨j, h⟩)) (rev_list_foldr_aux _)
theorem rev_list_foldr : a.rev_list.foldr f b = a.foldl b f :=
rev_list_foldr_aux _
end foldr
/- foldl -/
section foldl
variables {n : ℕ} {α : Type u} {β : Type w} {b : β} {f : β → α → β} {a : array n α}
theorem to_list_foldl : a.to_list.foldl f b = a.foldl b (function.swap f) :=
by rw [←rev_list_reverse, list.foldl_reverse, rev_list_foldr]
end foldl
/- length -/
section length
variables {n : ℕ} {α : Type u}
theorem rev_list_length_aux (a : array n α) (i h) :
(a.iterate_aux (λ _, (::)) i h []).length = i :=
by induction i; simp [*, d_array.iterate_aux]
@[simp] theorem rev_list_length (a : array n α) : a.rev_list.length = n :=
rev_list_length_aux a _ _
@[simp] theorem to_list_length (a : array n α) : a.to_list.length = n :=
by rw[←rev_list_reverse, list.length_reverse, rev_list_length]
end length
/- nth -/
section nth
variables {n : ℕ} {α : Type u} {a : array n α}
theorem to_list_nth_le_aux (i : ℕ) (ih : i < n) : ∀ j {jh t h'},
(∀ k tl, j + k = i → list.nth_le t k tl = a.read ⟨i, ih⟩) →
(a.rev_iterate_aux (λ _, (::)) j jh t).nth_le i h' = a.read ⟨i, ih⟩
| 0 _ _ _ al := al i _ $ zero_add _
| (j+1) jh t h' al := to_list_nth_le_aux j $ λ k tl hjk,
show list.nth_le (a.read ⟨j, jh⟩ :: t) k tl = a.read ⟨i, ih⟩, from
match k, hjk, tl with
| 0, e, tl := match i, e, ih with ._, rfl, _ := rfl end
| k'+1, _, tl := by simp[list.nth_le]; exact al _ _ (by simp [add_comm, add_assoc, *]; cc)
end
theorem to_list_nth_le (i : ℕ) (h h') : list.nth_le a.to_list i h' = a.read ⟨i, h⟩ :=
to_list_nth_le_aux _ _ _ (λ k tl, absurd tl k.not_lt_zero)
@[simp] theorem to_list_nth_le' (a : array n α) (i : fin n) (h') :
list.nth_le a.to_list i h' = a.read i :=
by cases i; apply to_list_nth_le
theorem to_list_nth {i v} : list.nth a.to_list i = some v ↔ ∃ h, a.read ⟨i, h⟩ = v :=
begin
rw list.nth_eq_some,
have ll := to_list_length a,
split; intro h; cases h with h e; subst v,
{ exact ⟨ll ▸ h, (to_list_nth_le _ _ _).symm⟩ },
{ exact ⟨ll.symm ▸ h, to_list_nth_le _ _ _⟩ }
end
theorem write_to_list {i v} : (a.write i v).to_list = a.to_list.update_nth i v :=
list.ext_le (by simp) $ λ j h₁ h₂, begin
have h₃ : j < n, {simpa using h₁},
rw [to_list_nth_le _ h₃],
refine let ⟨_, e⟩ := list.nth_eq_some.1 _ in e.symm,
by_cases ij : (i : ℕ) = j,
{ subst j, rw [show (⟨(i : ℕ), h₃⟩ : fin _) = i, from fin.eq_of_veq rfl,
array.read_write, list.nth_update_nth_of_lt],
simp [h₃] },
{ rw [list.nth_update_nth_ne _ _ ij, a.read_write_of_ne,
to_list_nth.2 ⟨h₃, rfl⟩],
exact fin.ne_of_vne ij }
end
end nth
/- enum -/
section enum
variables {n : ℕ} {α : Type u} {a : array n α}
theorem mem_to_list_enum {i v} : (i, v) ∈ a.to_list.enum ↔ ∃ h, a.read ⟨i, h⟩ = v :=
by simp [list.mem_iff_nth, to_list_nth, and.comm, and.assoc, and.left_comm]
end enum
/- to_array -/
section to_array
variables {n : ℕ} {α : Type u}
@[simp] theorem to_list_to_array (a : array n α) : a.to_list.to_array == a :=
heq_of_heq_of_eq
(@@eq.drec_on (λ m (e : a.to_list.length = m), (d_array.mk (λ v, a.to_list.nth_le v.1 v.2)) ==
(@d_array.mk m (λ _, α) $ λ v, a.to_list.nth_le v.1 $ e.symm ▸ v.2)) a.to_list_length heq.rfl) $
d_array.ext $ λ ⟨i, h⟩, to_list_nth_le i h _
@[simp] theorem to_array_to_list (l : list α) : l.to_array.to_list = l :=
list.ext_le (to_list_length _) $ λ n h1 h2, to_list_nth_le _ h2 _
end to_array
/- push_back -/
section push_back
variables {n : ℕ} {α : Type u} {v : α} {a : array n α}
lemma push_back_rev_list_aux : ∀ i h h',
d_array.iterate_aux (a.push_back v) (λ _, (::)) i h [] = d_array.iterate_aux a (λ _, (::)) i h' []
| 0 h h' := rfl
| (i+1) h h' := begin
simp [d_array.iterate_aux],
refine ⟨_, push_back_rev_list_aux _ _ _⟩,
dsimp [read, d_array.read, push_back],
rw [dif_neg], refl,
exact ne_of_lt h',
end
@[simp] theorem push_back_rev_list : (a.push_back v).rev_list = v :: a.rev_list :=
begin
unfold push_back rev_list foldl iterate d_array.iterate,
dsimp [d_array.iterate_aux, read, d_array.read, push_back],
rw [dif_pos (eq.refl n)],
apply congr_arg,
apply push_back_rev_list_aux
end
@[simp] theorem push_back_to_list : (a.push_back v).to_list = a.to_list ++ [v] :=
by rw [←rev_list_reverse, ←rev_list_reverse, push_back_rev_list, list.reverse_cons]
@[simp] lemma read_push_back_left (i : fin n) : (a.push_back v).read i.cast_succ = a.read i :=
begin
cases i with i hi,
have : ¬ i = n := ne_of_lt hi,
simp [push_back, this, fin.cast_succ, fin.cast_add, fin.cast_le, fin.cast_lt, read, d_array.read]
end
@[simp] lemma read_push_back_right : (a.push_back v).read (fin.last _) = v :=
begin
cases hn : fin.last n with k hk,
have : k = n := by simpa [fin.eq_iff_veq ] using hn.symm,
simp [push_back, this, fin.cast_succ, fin.cast_add, fin.cast_le, fin.cast_lt, read, d_array.read]
end
end push_back
/- foreach -/
section foreach
variables {n : ℕ} {α : Type u} {β : Type v} {i : fin n} {f : fin n → α → β} {a : array n α}
@[simp] theorem read_foreach : (foreach a f).read i = f i (a.read i) :=
rfl
end foreach
/- map -/
section map
variables {n : ℕ} {α : Type u} {β : Type v} {i : fin n} {f : α → β} {a : array n α}
theorem read_map : (a.map f).read i = f (a.read i) :=
read_foreach
end map
/- map₂ -/
section map₂
variables {n : ℕ} {α : Type u} {i : fin n} {f : α → α → α} {a₁ a₂ : array n α}
@[simp] theorem read_map₂ : (map₂ f a₁ a₂).read i = f (a₁.read i) (a₂.read i) :=
read_foreach
end map₂
end array
namespace equiv
/-- The natural equivalence between length-`n` heterogeneous arrays
and dependent functions from `fin n`. -/
def d_array_equiv_fin {n : ℕ} (α : fin n → Type*) : d_array n α ≃ (Π i, α i) :=
⟨d_array.read, d_array.mk, λ ⟨f⟩, rfl, λ f, rfl⟩
/-- The natural equivalence between length-`n` arrays and functions from `fin n`. -/
def array_equiv_fin (n : ℕ) (α : Type*) : array n α ≃ (fin n → α) :=
d_array_equiv_fin _
/-- The natural equivalence between length-`n` vectors and length-`n` arrays. -/
def vector_equiv_array (α : Type*) (n : ℕ) : vector α n ≃ array n α :=
(vector_equiv_fin _ _).trans (array_equiv_fin _ _).symm
end equiv
namespace array
open function
variable {n : ℕ}
instance : traversable (array n) :=
@equiv.traversable (flip vector n) _ (λ α, equiv.vector_equiv_array α n) _
instance : is_lawful_traversable (array n) :=
@equiv.is_lawful_traversable (flip vector n) _ (λ α, equiv.vector_equiv_array α n) _ _
end array
|
2c17ad81964062b97b2543c6a76bc23914a1d2b0 | a8c03ed21a1bd6fc45901943b79dd6574ea3f0c2 | /examples.lean | 31287ed8e2fd29ad7a90d3b790df23dc4dc80c2d | [] | no_license | gebner/resolution.lean | 716c355fbb5204e5c4d0c5a7f3f3cc825892a2bf | c6fafe06fba1cfad73db68f2aa474b29fe892a2b | refs/heads/master | 1,601,111,444,528 | 1,475,256,701,000 | 1,475,256,701,000 | 67,711,151 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,588 | lean | import prover
open tactic
-- set_option trace.resolution true
namespace tactic.interactive
meta def with_lemmas (ls : types.raw_ident_list) : tactic unit := monad.forM' ls $ λl, do
p ← mk_const l,
t ← infer_type p,
n ← get_unused_name p↣get_app_fn↣const_name none,
tactic.assertv n t p
end tactic.interactive
example : ∀x y : ℕ, x + y = y + x :=
begin with_lemmas nat.succ_add nat.zero_add, intros, induction x, repeat prover_tactic end
example (i) [inhabited i] : nonempty i := begin prover_tactic end
example (i) [nonempty i] : ¬(inhabited i → false) := begin prover_tactic end
example : nonempty ℕ := begin prover_tactic end
example : ¬(inhabited ℕ → false) := begin prover_tactic end
example {a b} : ¬(b ∨ ¬a) ∨ (a → b) := by prover_tactic
example {a} : a ∨ ¬a := by prover_tactic
example {a} : (a ∧ a) ∨ (¬a ∧ ¬a) := by prover_tactic
example (i) (c : i) (p : i → Prop) (f : i → i) :
p c → (∀x, p x → p (f x)) → p (f (f (f c))) := by prover_tactic
example (i) (p : i → Prop) : ∀x, p x → ∃x, p x := by prover_tactic
example (i) [nonempty i] (p : i → i → Prop) : (∀x y, p x y) → ∃x, ∀z, p x z := by prover_tactic
example (i) [nonempty i] (p : i → Prop) : (∀x, p x) → ¬¬∀x, p x := by prover_tactic
-- Requires non-empty domain.
example {i} [nonempty i] (p : i → Prop) :
(∀x y, p x ∨ p y) → ∃x y, p x ∧ p y := by prover_tactic
example (i) (a b : i) (p : i → Prop) (H : a = b) : p b → p a :=
by prover_tactic
example (i) (a b : i) (p : i → Prop) (H : a = b) : p a → p b :=
by prover_tactic
example (i) (a b : i) (p : i → Prop) (H : a = b) : p b = p a :=
by prover_tactic
example (i) (c : i) (p : i → Prop) (f g : i → i) :
p c → (∀x, p x → p (f x)) → (∀x, p x → f x = g x) → f (f c) = g (g c) :=
by prover_tactic
example (i) (p q : i → i → Prop) (a b c d : i) :
(∀x y z, p x y ∧ p y z → p x z) →
(∀x y z, q x y ∧ q y z → q x z) →
(∀x y, q x y → q y x) →
(∀x y, p x y ∨ q x y) →
p a b ∨ q c d :=
by prover_tactic
-- This example from Davis-Putnam actually requires a non-empty domain
example (i) [nonempty i] (f g : i → i → Prop) :
∃x y, ∀z, (f x y → f y z ∧ f z z) ∧ (f x y ∧ g x y → g x z ∧ g z z) :=
by prover_tactic
example (person : Type) [nonempty person] (drinks : person → Prop) :
∃canary, drinks canary → ∀other, drinks other := by prover_tactic
example {p q : ℕ → Prop} {r} : (∀x y, p x ∧ q y ∧ r) -> ∀x, (p x ∧ r ∧ q x) := by prover_tactic
|
d768829903b46ac22addfc011bc0e09e5af4257e | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/topology/algebra/module/weak_dual.lean | 122106d3c27f9c7f38d2304be70ead43ac5428b2 | [
"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 | 11,688 | lean | /-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä, Moritz Doll
-/
import topology.algebra.module.basic
/-!
# Weak dual topology
This file defines the weak topology given two vector spaces `E` and `F` over a commutative semiring
`𝕜` and a bilinear form `B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜`. The weak topology on `E` is the coarsest topology
such that for all `y : F` every map `λ x, B x y` is continuous.
In the case that `F = E →L[𝕜] 𝕜` and `B` being the canonical pairing, we obtain the weak-* topology,
`weak_dual 𝕜 E := (E →L[𝕜] 𝕜)`. Interchanging the arguments in the bilinear form yields the
weak topology `weak_space 𝕜 E := E`.
## Main definitions
The main definitions are the types `weak_bilin B` for the general case and the two special cases
`weak_dual 𝕜 E` and `weak_space 𝕜 E` with the respective topology instances on it.
* Given `B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜`, the type `weak_bilin B` is a type synonym for `E`.
* The instance `weak_bilin.topological_space` is the weak topology induced by the bilinear form `B`.
* `weak_dual 𝕜 E` is a type synonym for `dual 𝕜 E` (when the latter is defined): both are equal to
the type `E →L[𝕜] 𝕜` of continuous linear maps from a module `E` over `𝕜` to the ring `𝕜`.
* The instance `weak_dual.topological_space` is the weak-* topology on `weak_dual 𝕜 E`, i.e., the
coarsest topology making the evaluation maps at all `z : E` continuous.
* `weak_space 𝕜 E` is a type synonym for `E` (when the latter is defined).
* The instance `weak_dual.topological_space` is the weak topology on `E`, i.e., the
coarsest topology such that all `v : dual 𝕜 E` remain continuous.
## Main results
We establish that `weak_bilin B` has the following structure:
* `weak_bilin.has_continuous_add`: The addition in `weak_bilin B` is continuous.
* `weak_bilin.has_continuous_smul`: The scalar multiplication in `weak_bilin B` is continuous.
We prove the following results characterizing the weak topology:
* `eval_continuous`: For any `y : F`, the evaluation mapping `λ x, B x y` is continuous.
* `continuous_of_continuous_eval`: For a mapping to `weak_bilin B` to be continuous,
it suffices that its compositions with pairing with `B` at all points `y : F` is continuous.
* `tendsto_iff_forall_eval_tendsto`: Convergence in `weak_bilin B` can be characterized
in terms of convergence of the evaluations at all points `y : F`.
## Notations
No new notation is introduced.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
weak-star, weak dual, duality
-/
noncomputable theory
open filter
open_locale topological_space
variables {α 𝕜 𝕝 R E F M : Type*}
section weak_topology
/-- The space `E` equipped with the weak topology induced by the bilinear form `B`. -/
@[derive [add_comm_monoid, module 𝕜],
nolint has_nonempty_instance unused_arguments]
def weak_bilin [comm_semiring 𝕜] [add_comm_monoid E] [module 𝕜 E] [add_comm_monoid F]
[module 𝕜 F] (B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜) := E
namespace weak_bilin
instance [comm_semiring 𝕜] [a : add_comm_group E] [module 𝕜 E] [add_comm_monoid F]
[module 𝕜 F] (B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜) : add_comm_group (weak_bilin B) := a
@[priority 100]
instance module' [comm_semiring 𝕜] [comm_semiring 𝕝] [add_comm_group E] [module 𝕜 E]
[add_comm_group F] [module 𝕜 F] [m : module 𝕝 E] (B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜) :
module 𝕝 (weak_bilin B) := m
instance [comm_semiring 𝕜] [comm_semiring 𝕝] [add_comm_group E] [module 𝕜 E]
[add_comm_group F] [module 𝕜 F] [has_smul 𝕝 𝕜] [module 𝕝 E] [s : is_scalar_tower 𝕝 𝕜 E]
(B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜) : is_scalar_tower 𝕝 𝕜 (weak_bilin B) := s
section semiring
variables [topological_space 𝕜] [comm_semiring 𝕜]
variables [add_comm_monoid E] [module 𝕜 E]
variables [add_comm_monoid F] [module 𝕜 F]
variables (B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜)
instance : topological_space (weak_bilin B) :=
topological_space.induced (λ x y, B x y) Pi.topological_space
/-- The coercion `(λ x y, B x y) : E → (F → 𝕜)` is continuous. -/
lemma coe_fn_continuous : continuous (λ (x : weak_bilin B) y, B x y) :=
continuous_induced_dom
lemma eval_continuous (y : F) : continuous (λ x : weak_bilin B, B x y) :=
( continuous_pi_iff.mp (coe_fn_continuous B)) y
lemma continuous_of_continuous_eval [topological_space α] {g : α → weak_bilin B}
(h : ∀ y, continuous (λ a, B (g a) y)) : continuous g :=
continuous_induced_rng.2 (continuous_pi_iff.mpr h)
/-- The coercion `(λ x y, B x y) : E → (F → 𝕜)` is an embedding. -/
lemma embedding {B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜} (hB : function.injective B) :
embedding (λ (x : weak_bilin B) y, B x y) :=
function.injective.embedding_induced $ linear_map.coe_injective.comp hB
theorem tendsto_iff_forall_eval_tendsto {l : filter α} {f : α → (weak_bilin B)} {x : weak_bilin B}
(hB : function.injective B) : tendsto f l (𝓝 x) ↔ ∀ y, tendsto (λ i, B (f i) y) l (𝓝 (B x y)) :=
by rw [← tendsto_pi_nhds, embedding.tendsto_nhds_iff (embedding hB)]
/-- Addition in `weak_space B` is continuous. -/
instance [has_continuous_add 𝕜] : has_continuous_add (weak_bilin B) :=
begin
refine ⟨continuous_induced_rng.2 _⟩,
refine cast (congr_arg _ _) (((coe_fn_continuous B).comp continuous_fst).add
((coe_fn_continuous B).comp continuous_snd)),
ext,
simp only [function.comp_app, pi.add_apply, map_add, linear_map.add_apply],
end
/-- Scalar multiplication by `𝕜` on `weak_bilin B` is continuous. -/
instance [has_continuous_smul 𝕜 𝕜] : has_continuous_smul 𝕜 (weak_bilin B) :=
begin
refine ⟨continuous_induced_rng.2 _⟩,
refine cast (congr_arg _ _) (continuous_fst.smul ((coe_fn_continuous B).comp continuous_snd)),
ext,
simp only [function.comp_app, pi.smul_apply, linear_map.map_smulₛₗ, ring_hom.id_apply,
linear_map.smul_apply],
end
end semiring
section ring
variables [topological_space 𝕜] [comm_ring 𝕜]
variables [add_comm_group E] [module 𝕜 E]
variables [add_comm_group F] [module 𝕜 F]
variables (B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜)
/-- `weak_space B` is a `topological_add_group`, meaning that addition and negation are
continuous. -/
instance [has_continuous_add 𝕜] : topological_add_group (weak_bilin B) :=
{ to_has_continuous_add := by apply_instance,
continuous_neg := begin
refine continuous_induced_rng.2 (continuous_pi_iff.mpr (λ y, _)),
refine cast (congr_arg _ _) (eval_continuous B (-y)),
ext,
simp only [map_neg, function.comp_app, linear_map.neg_apply],
end }
end ring
end weak_bilin
end weak_topology
section weak_star_topology
/-- The canonical pairing of a vector space and its topological dual. -/
def top_dual_pairing (𝕜 E) [comm_semiring 𝕜] [topological_space 𝕜] [has_continuous_add 𝕜]
[add_comm_monoid E] [module 𝕜 E] [topological_space E]
[has_continuous_const_smul 𝕜 𝕜] :
(E →L[𝕜] 𝕜) →ₗ[𝕜] E →ₗ[𝕜] 𝕜 := continuous_linear_map.coe_lm 𝕜
variables [comm_semiring 𝕜] [topological_space 𝕜] [has_continuous_add 𝕜]
variables [has_continuous_const_smul 𝕜 𝕜]
variables [add_comm_monoid E] [module 𝕜 E] [topological_space E]
lemma dual_pairing_apply (v : (E →L[𝕜] 𝕜)) (x : E) : top_dual_pairing 𝕜 E v x = v x := rfl
/-- The weak star topology is the topology coarsest topology on `E →L[𝕜] 𝕜` such that all
functionals `λ v, top_dual_pairing 𝕜 E v x` are continuous. -/
@[derive [add_comm_monoid, module 𝕜, topological_space, has_continuous_add]]
def weak_dual (𝕜 E) [comm_semiring 𝕜] [topological_space 𝕜] [has_continuous_add 𝕜]
[has_continuous_const_smul 𝕜 𝕜] [add_comm_monoid E] [module 𝕜 E] [topological_space E] :=
weak_bilin (top_dual_pairing 𝕜 E)
namespace weak_dual
instance : inhabited (weak_dual 𝕜 E) := continuous_linear_map.inhabited
instance weak_dual.continuous_linear_map_class :
continuous_linear_map_class (weak_dual 𝕜 E) 𝕜 E 𝕜 :=
continuous_linear_map.continuous_semilinear_map_class
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (weak_dual 𝕜 E) (λ _, E → 𝕜) := fun_like.has_coe_to_fun
/-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with
multiplication on `𝕜`, then it acts on `weak_dual 𝕜 E`. -/
instance (M) [monoid M] [distrib_mul_action M 𝕜] [smul_comm_class 𝕜 M 𝕜]
[has_continuous_const_smul M 𝕜] :
mul_action M (weak_dual 𝕜 E) :=
continuous_linear_map.mul_action
/-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with
multiplication on `𝕜`, then it acts distributively on `weak_dual 𝕜 E`. -/
instance (M) [monoid M] [distrib_mul_action M 𝕜] [smul_comm_class 𝕜 M 𝕜]
[has_continuous_const_smul M 𝕜] :
distrib_mul_action M (weak_dual 𝕜 E) :=
continuous_linear_map.distrib_mul_action
/-- If `𝕜` is a topological module over a semiring `R` and scalar multiplication commutes with the
multiplication on `𝕜`, then `weak_dual 𝕜 E` is a module over `R`. -/
instance module' (R) [semiring R] [module R 𝕜] [smul_comm_class 𝕜 R 𝕜]
[has_continuous_const_smul R 𝕜] :
module R (weak_dual 𝕜 E) :=
continuous_linear_map.module
instance (M) [monoid M] [distrib_mul_action M 𝕜] [smul_comm_class 𝕜 M 𝕜]
[has_continuous_const_smul M 𝕜] : has_continuous_const_smul M (weak_dual 𝕜 E) :=
⟨λ m, continuous_induced_rng.2 $ (weak_bilin.coe_fn_continuous (top_dual_pairing 𝕜 E)).const_smul m⟩
/-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with
multiplication on `𝕜`, then it continuously acts on `weak_dual 𝕜 E`. -/
instance (M) [monoid M] [distrib_mul_action M 𝕜] [smul_comm_class 𝕜 M 𝕜]
[topological_space M] [has_continuous_smul M 𝕜] :
has_continuous_smul M (weak_dual 𝕜 E) :=
⟨continuous_induced_rng.2 $ continuous_fst.smul ((weak_bilin.coe_fn_continuous
(top_dual_pairing 𝕜 E)).comp continuous_snd)⟩
lemma coe_fn_continuous : continuous (λ (x : weak_dual 𝕜 E) y, x y) :=
continuous_induced_dom
lemma eval_continuous (y : E) : continuous (λ x : weak_dual 𝕜 E, x y) :=
continuous_pi_iff.mp coe_fn_continuous y
lemma continuous_of_continuous_eval [topological_space α] {g : α → weak_dual 𝕜 E}
(h : ∀ y, continuous (λ a, (g a) y)) : continuous g :=
continuous_induced_rng.2 (continuous_pi_iff.mpr h)
end weak_dual
/-- The weak topology is the topology coarsest topology on `E` such that all
functionals `λ x, top_dual_pairing 𝕜 E v x` are continuous. -/
@[derive [add_comm_monoid, module 𝕜, topological_space, has_continuous_add],
nolint has_nonempty_instance]
def weak_space (𝕜 E) [comm_semiring 𝕜] [topological_space 𝕜] [has_continuous_add 𝕜]
[has_continuous_const_smul 𝕜 𝕜] [add_comm_monoid E] [module 𝕜 E] [topological_space E] :=
weak_bilin (top_dual_pairing 𝕜 E).flip
theorem tendsto_iff_forall_eval_tendsto_top_dual_pairing
{l : filter α} {f : α → weak_dual 𝕜 E} {x : weak_dual 𝕜 E} :
tendsto f l (𝓝 x) ↔
∀ y, tendsto (λ i, top_dual_pairing 𝕜 E (f i) y) l (𝓝 (top_dual_pairing 𝕜 E x y)) :=
weak_bilin.tendsto_iff_forall_eval_tendsto _ continuous_linear_map.coe_injective
end weak_star_topology
|
271b097959d4f3ff578455b7b45ae1ec8adae8a3 | 48eee836fdb5c613d9a20741c17db44c8e12e61c | /src/algebra/theories/default.lean | 88d589d692bb4f9924bf3ff128a27f2687884a98 | [
"Apache-2.0"
] | permissive | fgdorais/lean-universal | 06430443a4abe51e303e602684c2977d1f5c0834 | 9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1 | refs/heads/master | 1,592,479,744,136 | 1,589,473,399,000 | 1,589,473,399,000 | 196,287,552 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 257 | lean | -- Copyright © 2019 François G. Dorais. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
import .basic
import .group
import .loop
import .magma
import .monoid
import .quasigroup
import .semigroup
import .unital
|
3e5d3eae7f9104d0b1bb6b02c2f0f39718ac8ad5 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/geometry/manifold/mfderiv.lean | d67527d09fe5178705afe91484143fa88d579eae | [
"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 | 65,051 | lean | /-
Copyright (c) 2020 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 geometry.manifold.basic_smooth_bundle
/-!
# The derivative of functions between smooth manifolds
Let `M` and `M'` be two smooth manifolds with corners over a field `𝕜` (with respective models with
corners `I` on `(E, H)` and `I'` on `(E', H')`), and let `f : M → M'`. We define the
derivative of the function at a point, within a set or along the whole space, mimicking the API
for (Fréchet) derivatives. It is denoted by `mfderiv I I' f x`, where "m" stands for "manifold" and
"f" for "Fréchet" (as in the usual derivative `fderiv 𝕜 f x`).
## Main definitions
* `unique_mdiff_on I s` : predicate saying that, at each point of the set `s`, a function can have
at most one derivative. This technical condition is important when we define
`mfderiv_within` below, as otherwise there is an arbitrary choice in the derivative,
and many properties will fail (for instance the chain rule). This is analogous to
`unique_diff_on 𝕜 s` in a vector space.
Let `f` be a map between smooth manifolds. The following definitions follow the `fderiv` API.
* `mfderiv I I' f x` : the derivative of `f` at `x`, as a continuous linear map from the tangent
space at `x` to the tangent space at `f x`. If the map is not differentiable, this is `0`.
* `mfderiv_within I I' f s x` : the derivative of `f` at `x` within `s`, as a continuous linear map
from the tangent space at `x` to the tangent space at `f x`. If the map is not differentiable
within `s`, this is `0`.
* `mdifferentiable_at I I' f x` : Prop expressing whether `f` is differentiable at `x`.
* `mdifferentiable_within_at 𝕜 f s x` : Prop expressing whether `f` is differentiable within `s`
at `x`.
* `has_mfderiv_at I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative at `x`.
* `has_mfderiv_within_at I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative
within `s` at `x`.
* `mdifferentiable_on I I' f s` : Prop expressing that `f` is differentiable on the set `s`.
* `mdifferentiable I I' f` : Prop expressing that `f` is differentiable everywhere.
* `tangent_map I I' f` : the derivative of `f`, as a map from the tangent bundle of `M` to the
tangent bundle of `M'`.
We also establish results on the differential of the identity, constant functions, charts, extended
charts. For functions between vector spaces, we show that the usual notions and the manifold notions
coincide.
## Implementation notes
The tangent bundle is constructed using the machinery of topological fiber bundles, for which one
can define bundled morphisms and construct canonically maps from the total space of one bundle to
the total space of another one. One could use this mechanism to construct directly the derivative
of a smooth map. However, we want to define the derivative of any map (and let it be zero if the map
is not differentiable) to avoid proof arguments everywhere. This means we have to go back to the
details of the definition of the total space of a fiber bundle constructed from core, to cook up a
suitable definition of the derivative. It is the following: at each point, we have a preferred chart
(used to identify the fiber above the point with the model vector space in fiber bundles). Then one
should read the function using these preferred charts at `x` and `f x`, and take the derivative
of `f` in these charts.
Due to the fact that we are working in a model with corners, with an additional embedding `I` of the
model space `H` in the model vector space `E`, the charts taking values in `E` are not the original
charts of the manifold, but those ones composed with `I`, called extended charts. We
define `written_in_ext_chart I I' x f` for the function `f` written in the preferred extended charts.
Then the manifold derivative of `f`, at `x`, is just the usual derivative of
`written_in_ext_chart I I' x f`, at the point `(ext_chart_at I x) x`.
There is a subtelty with respect to continuity: if the function is not continuous, then the image
of a small open set around `x` will not be contained in the source of the preferred chart around
`f x`, which means that when reading `f` in the chart one is losing some information. To avoid this,
we include continuity in the definition of differentiablity (which is reasonable since with any
definition, differentiability implies continuity).
*Warning*: the derivative (even within a subset) is a linear map on the whole tangent space. Suppose
that one is given a smooth submanifold `N`, and a function which is smooth on `N` (i.e., its
restriction to the subtype `N` is smooth). Then, in the whole manifold `M`, the property
`mdifferentiable_on I I' f N` holds. However, `mfderiv_within I I' f N` is not uniquely defined
(what values would one choose for vectors that are transverse to `N`?), which can create issues down
the road. The problem here is that knowing the value of `f` along `N` does not determine the
differential of `f` in all directions. This is in contrast to the case where `N` would be an open
subset, or a submanifold with boundary of maximal dimension, where this issue does not appear.
The predicate `unique_mdiff_on I N` indicates that the derivative along `N` is unique if it exists,
and is an assumption in most statements requiring a form of uniqueness.
On a vector space, the manifold derivative and the usual derivative are equal. This means in
particular that they live on the same space, i.e., the tangent space is defeq to the original vector
space. To get this property is a motivation for our definition of the tangent space as a single
copy of the vector space, instead of more usual definitions such as the space of derivations, or
the space of equivalence classes of smooth curves in the manifold.
## Tags
Derivative, manifold
-/
noncomputable theory
open_locale classical topological_space manifold
open set
universe u
section derivatives_definitions
/-!
### Derivative of maps between manifolds
The derivative of a smooth map `f` between smooth manifold `M` and `M'` at `x` is a bounded linear
map from the tangent space to `M` at `x`, to the tangent space to `M'` at `f x`. Since we defined
the tangent space using one specific chart, the formula for the derivative is written in terms of
this specific chart.
We use the names `mdifferentiable` and `mfderiv`, where the prefix letter `m` means "manifold".
-/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H')
{M' : Type*} [topological_space M'] [charted_space H' M']
/-- Predicate ensuring that, at a point and within a set, a function can have at most one
derivative. This is expressed using the preferred chart at the considered point. -/
def unique_mdiff_within_at (s : set M) (x : M) :=
unique_diff_within_at 𝕜 ((ext_chart_at I x).symm ⁻¹' s ∩ range I) ((ext_chart_at I x) x)
/-- Predicate ensuring that, at all points of a set, a function can have at most one derivative. -/
def unique_mdiff_on (s : set M) :=
∀x∈s, unique_mdiff_within_at I s x
/-- Conjugating a function to write it in the preferred charts around `x`. The manifold derivative
of `f` will just be the derivative of this conjugated function. -/
@[simp, mfld_simps] def written_in_ext_chart_at (x : M) (f : M → M') : E → E' :=
(ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm
/-- `mdifferentiable_within_at I I' f s x` indicates that the function `f` between manifolds
has a derivative at the point `x` within the set `s`.
This is a generalization of `differentiable_within_at` to manifolds.
We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by
`f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
this would not mean anything relevant. -/
def mdifferentiable_within_at (f : M → M') (s : set M) (x : M) :=
continuous_within_at f s x ∧
differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f)
((ext_chart_at I x).symm ⁻¹' s ∩ range I) ((ext_chart_at I x) x)
/-- `mdifferentiable_at I I' f x` indicates that the function `f` between manifolds
has a derivative at the point `x`.
This is a generalization of `differentiable_at` to manifolds.
We require continuity in the definition, as otherwise points close to `x` could be sent by
`f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
this would not mean anything relevant. -/
def mdifferentiable_at (f : M → M') (x : M) :=
continuous_at f x ∧
differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f) (range I)
((ext_chart_at I x) x)
/-- `mdifferentiable_on I I' f s` indicates that the function `f` between manifolds
has a derivative within `s` at all points of `s`.
This is a generalization of `differentiable_on` to manifolds. -/
def mdifferentiable_on (f : M → M') (s : set M) :=
∀x ∈ s, mdifferentiable_within_at I I' f s x
/-- `mdifferentiable I I' f` indicates that the function `f` between manifolds
has a derivative everywhere.
This is a generalization of `differentiable` to manifolds. -/
def mdifferentiable (f : M → M') :=
∀x, mdifferentiable_at I I' f x
/-- Prop registering if a local homeomorphism is a local diffeomorphism on its source -/
def local_homeomorph.mdifferentiable (f : local_homeomorph M M') :=
(mdifferentiable_on I I' f f.source) ∧ (mdifferentiable_on I' I f.symm f.target)
variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners I' M']
/-- `has_mfderiv_within_at I I' f s x f'` indicates that the function `f` between manifolds
has, at the point `x` and within the set `s`, the derivative `f'`. Here, `f'` is a continuous linear
map from the tangent space at `x` to the tangent space at `f x`.
This is a generalization of `has_fderiv_within_at` to manifolds (as indicated by the prefix `m`).
The order of arguments is changed as the type of the derivative `f'` depends on the choice of `x`.
We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by
`f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
this would not mean anything relevant. -/
def has_mfderiv_within_at (f : M → M') (s : set M) (x : M)
(f' : tangent_space I x →L[𝕜] tangent_space I' (f x)) :=
continuous_within_at f s x ∧
has_fderiv_within_at (written_in_ext_chart_at I I' x f : E → E') f'
((ext_chart_at I x).symm ⁻¹' s ∩ range I) ((ext_chart_at I x) x)
/-- `has_mfderiv_at I I' f x f'` indicates that the function `f` between manifolds
has, at the point `x`, the derivative `f'`. Here, `f'` is a continuous linear
map from the tangent space at `x` to the tangent space at `f x`.
We require continuity in the definition, as otherwise points close to `x` `s` could be sent by
`f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
this would not mean anything relevant. -/
def has_mfderiv_at (f : M → M') (x : M)
(f' : tangent_space I x →L[𝕜] tangent_space I' (f x)) :=
continuous_at f x ∧
has_fderiv_within_at (written_in_ext_chart_at I I' x f : E → E') f' (range I)
((ext_chart_at I x) x)
/-- Let `f` be a function between two smooth manifolds. Then `mfderiv_within I I' f s x` is the
derivative of `f` at `x` within `s`, as a continuous linear map from the tangent space at `x` to the
tangent space at `f x`. -/
def mfderiv_within (f : M → M') (s : set M) (x : M) : tangent_space I x →L[𝕜] tangent_space I' (f x) :=
if h : mdifferentiable_within_at I I' f s x then
(fderiv_within 𝕜 (written_in_ext_chart_at I I' x f) ((ext_chart_at I x).symm ⁻¹' s ∩ range I)
((ext_chart_at I x) x) : _)
else 0
/-- Let `f` be a function between two smooth manifolds. Then `mfderiv I I' f x` is the derivative of
`f` at `x`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. -/
def mfderiv (f : M → M') (x : M) : tangent_space I x →L[𝕜] tangent_space I' (f x) :=
if h : mdifferentiable_at I I' f x then
(fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : E → E') (range I)
((ext_chart_at I x) x) : _)
else 0
/-- The derivative within a set, as a map between the tangent bundles -/
def tangent_map_within (f : M → M') (s : set M) : tangent_bundle I M → tangent_bundle I' M' :=
λp, ⟨f p.1, (mfderiv_within I I' f s p.1 : tangent_space I p.1 → tangent_space I' (f p.1)) p.2⟩
/-- The derivative, as a map between the tangent bundles -/
def tangent_map (f : M → M') : tangent_bundle I M → tangent_bundle I' M' :=
λp, ⟨f p.1, (mfderiv I I' f p.1 : tangent_space I p.1 → tangent_space I' (f p.1)) p.2⟩
end derivatives_definitions
section derivatives_properties
/-! ### Unique differentiability sets in manifolds -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M] --
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
{M' : Type*} [topological_space M'] [charted_space H' M']
{E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
{H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
{M'' : Type*} [topological_space M''] [charted_space H'' M'']
{f f₀ f₁ : M → M'}
{x : M}
{s t : set M}
{g : M' → M''}
{u : set M'}
lemma unique_mdiff_within_at_univ : unique_mdiff_within_at I univ x :=
begin
unfold unique_mdiff_within_at,
simp only [preimage_univ, univ_inter],
exact I.unique_diff _ (mem_range_self _)
end
variable {I}
lemma unique_mdiff_within_at_iff {s : set M} {x : M} :
unique_mdiff_within_at I s x ↔
unique_diff_within_at 𝕜 ((ext_chart_at I x).symm ⁻¹' s ∩ (ext_chart_at I x).target)
((ext_chart_at I x) x) :=
begin
apply unique_diff_within_at_congr,
rw [nhds_within_inter, nhds_within_inter, nhds_within_ext_chart_target_eq]
end
lemma unique_mdiff_within_at.mono (h : unique_mdiff_within_at I s x) (st : s ⊆ t) :
unique_mdiff_within_at I t x :=
unique_diff_within_at.mono h $ inter_subset_inter (preimage_mono st) (subset.refl _)
lemma unique_mdiff_within_at.inter' (hs : unique_mdiff_within_at I s x) (ht : t ∈ nhds_within x s) :
unique_mdiff_within_at I (s ∩ t) x :=
begin
rw [unique_mdiff_within_at, ext_chart_preimage_inter_eq],
exact unique_diff_within_at.inter' hs (ext_chart_preimage_mem_nhds_within I x ht)
end
lemma unique_mdiff_within_at.inter (hs : unique_mdiff_within_at I s x) (ht : t ∈ 𝓝 x) :
unique_mdiff_within_at I (s ∩ t) x :=
begin
rw [unique_mdiff_within_at, ext_chart_preimage_inter_eq],
exact unique_diff_within_at.inter hs (ext_chart_preimage_mem_nhds I x ht)
end
lemma is_open.unique_mdiff_within_at (xs : x ∈ s) (hs : is_open s) : unique_mdiff_within_at I s x :=
begin
have := unique_mdiff_within_at.inter (unique_mdiff_within_at_univ I) (mem_nhds_sets hs xs),
rwa univ_inter at this
end
lemma unique_mdiff_on.inter (hs : unique_mdiff_on I s) (ht : is_open t) : unique_mdiff_on I (s ∩ t) :=
λx hx, unique_mdiff_within_at.inter (hs _ hx.1) (mem_nhds_sets ht hx.2)
lemma is_open.unique_mdiff_on (hs : is_open s) : unique_mdiff_on I s :=
λx hx, is_open.unique_mdiff_within_at hx hs
lemma unique_mdiff_on_univ : unique_mdiff_on I (univ : set M) :=
is_open_univ.unique_mdiff_on
/- We name the typeclass variables related to `smooth_manifold_with_corners` structure as they are
necessary in lemmas mentioning the derivative, but not in lemmas about differentiability, so we
want to include them or omit them when necessary. -/
variables [Is : smooth_manifold_with_corners I M] [I's : smooth_manifold_with_corners I' M']
[I''s : smooth_manifold_with_corners I'' M'']
{f' f₀' f₁' : tangent_space I x →L[𝕜] tangent_space I' (f x)}
{g' : tangent_space I' (f x) →L[𝕜] tangent_space I'' (g (f x))}
/-- `unique_mdiff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/
theorem unique_mdiff_within_at.eq (U : unique_mdiff_within_at I s x)
(h : has_mfderiv_within_at I I' f s x f') (h₁ : has_mfderiv_within_at I I' f s x f₁') : f' = f₁' :=
U.eq h.2 h₁.2
theorem unique_mdiff_on.eq (U : unique_mdiff_on I s) (hx : x ∈ s)
(h : has_mfderiv_within_at I I' f s x f') (h₁ : has_mfderiv_within_at I I' f s x f₁') : f' = f₁' :=
unique_mdiff_within_at.eq (U _ hx) h h₁
/-!
### General lemmas on derivatives of functions between manifolds
We mimick the API for functions between vector spaces
-/
lemma mdifferentiable_within_at_iff {f : M → M'} {s : set M} {x : M} :
mdifferentiable_within_at I I' f s x ↔
continuous_within_at f s x ∧
differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f)
((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' s) ((ext_chart_at I x) x) :=
begin
refine and_congr iff.rfl (exists_congr $ λ f', _),
rw [inter_comm],
simp only [has_fderiv_within_at, nhds_within_inter, nhds_within_ext_chart_target_eq]
end
include Is I's
lemma mfderiv_within_zero_of_not_mdifferentiable_within_at
(h : ¬ mdifferentiable_within_at I I' f s x) : mfderiv_within I I' f s x = 0 :=
by simp [mfderiv_within, h]
lemma mfderiv_zero_of_not_mdifferentiable_at
(h : ¬ mdifferentiable_at I I' f x) : mfderiv I I' f x = 0 :=
by simp [mfderiv, h]
theorem has_mfderiv_within_at.mono (h : has_mfderiv_within_at I I' f t x f') (hst : s ⊆ t) :
has_mfderiv_within_at I I' f s x f' :=
⟨ continuous_within_at.mono h.1 hst,
has_fderiv_within_at.mono h.2 (inter_subset_inter (preimage_mono hst) (subset.refl _)) ⟩
theorem has_mfderiv_at.has_mfderiv_within_at
(h : has_mfderiv_at I I' f x f') : has_mfderiv_within_at I I' f s x f' :=
⟨ continuous_at.continuous_within_at h.1, has_fderiv_within_at.mono h.2 (inter_subset_right _ _) ⟩
lemma has_mfderiv_within_at.mdifferentiable_within_at (h : has_mfderiv_within_at I I' f s x f') :
mdifferentiable_within_at I I' f s x :=
⟨h.1, ⟨f', h.2⟩⟩
lemma has_mfderiv_at.mdifferentiable_at (h : has_mfderiv_at I I' f x f') :
mdifferentiable_at I I' f x :=
⟨h.1, ⟨f', h.2⟩⟩
@[simp, mfld_simps] lemma has_mfderiv_within_at_univ :
has_mfderiv_within_at I I' f univ x f' ↔ has_mfderiv_at I I' f x f' :=
by simp [has_mfderiv_within_at, has_mfderiv_at, continuous_within_at_univ]
theorem has_mfderiv_at_unique
(h₀ : has_mfderiv_at I I' f x f₀') (h₁ : has_mfderiv_at I I' f x f₁') : f₀' = f₁' :=
begin
rw ← has_mfderiv_within_at_univ at h₀ h₁,
exact (unique_mdiff_within_at_univ I).eq h₀ h₁
end
lemma has_mfderiv_within_at_inter' (h : t ∈ nhds_within x s) :
has_mfderiv_within_at I I' f (s ∩ t) x f' ↔ has_mfderiv_within_at I I' f s x f' :=
begin
rw [has_mfderiv_within_at, has_mfderiv_within_at, ext_chart_preimage_inter_eq,
has_fderiv_within_at_inter', continuous_within_at_inter' h],
exact ext_chart_preimage_mem_nhds_within I x h,
end
lemma has_mfderiv_within_at_inter (h : t ∈ 𝓝 x) :
has_mfderiv_within_at I I' f (s ∩ t) x f' ↔ has_mfderiv_within_at I I' f s x f' :=
begin
rw [has_mfderiv_within_at, has_mfderiv_within_at, ext_chart_preimage_inter_eq,
has_fderiv_within_at_inter, continuous_within_at_inter h],
exact ext_chart_preimage_mem_nhds I x h,
end
lemma has_mfderiv_within_at.union
(hs : has_mfderiv_within_at I I' f s x f') (ht : has_mfderiv_within_at I I' f t x f') :
has_mfderiv_within_at I I' f (s ∪ t) x f' :=
begin
split,
{ exact continuous_within_at.union hs.1 ht.1 },
{ convert has_fderiv_within_at.union hs.2 ht.2,
simp [union_inter_distrib_right] }
end
lemma has_mfderiv_within_at.nhds_within (h : has_mfderiv_within_at I I' f s x f')
(ht : s ∈ nhds_within x t) : has_mfderiv_within_at I I' f t x f' :=
(has_mfderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_mfderiv_within_at.has_mfderiv_at (h : has_mfderiv_within_at I I' f s x f') (hs : s ∈ 𝓝 x) :
has_mfderiv_at I I' f x f' :=
by rwa [← univ_inter s, has_mfderiv_within_at_inter hs, has_mfderiv_within_at_univ] at h
lemma mdifferentiable_within_at.has_mfderiv_within_at (h : mdifferentiable_within_at I I' f s x) :
has_mfderiv_within_at I I' f s x (mfderiv_within I I' f s x) :=
begin
refine ⟨h.1, _⟩,
simp only [mfderiv_within, h, dif_pos] with mfld_simps,
exact differentiable_within_at.has_fderiv_within_at h.2
end
lemma mdifferentiable_within_at.mfderiv_within (h : mdifferentiable_within_at I I' f s x) :
(mfderiv_within I I' f s x) =
fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : _) ((ext_chart_at I x).symm ⁻¹' s ∩ range I)
((ext_chart_at I x) x) :=
by simp [mfderiv_within, h]
lemma mdifferentiable_at.has_mfderiv_at (h : mdifferentiable_at I I' f x) :
has_mfderiv_at I I' f x (mfderiv I I' f x) :=
begin
refine ⟨h.1, _⟩,
simp only [mfderiv, h, dif_pos] with mfld_simps,
exact differentiable_within_at.has_fderiv_within_at h.2
end
lemma mdifferentiable_at.mfderiv (h : mdifferentiable_at I I' f x) :
(mfderiv I I' f x) =
fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : _) (range I) ((ext_chart_at I x) x) :=
by simp [mfderiv, h]
lemma has_mfderiv_at.mfderiv (h : has_mfderiv_at I I' f x f') :
mfderiv I I' f x = f' :=
by { ext, rw has_mfderiv_at_unique h h.mdifferentiable_at.has_mfderiv_at }
lemma has_mfderiv_within_at.mfderiv_within
(h : has_mfderiv_within_at I I' f s x f') (hxs : unique_mdiff_within_at I s x) :
mfderiv_within I I' f s x = f' :=
by { ext, rw hxs.eq h h.mdifferentiable_within_at.has_mfderiv_within_at }
lemma mdifferentiable.mfderiv_within
(h : mdifferentiable_at I I' f x) (hxs : unique_mdiff_within_at I s x) :
mfderiv_within I I' f s x = mfderiv I I' f x :=
begin
apply has_mfderiv_within_at.mfderiv_within _ hxs,
exact h.has_mfderiv_at.has_mfderiv_within_at
end
lemma mfderiv_within_subset (st : s ⊆ t) (hs : unique_mdiff_within_at I s x)
(h : mdifferentiable_within_at I I' f t x) :
mfderiv_within I I' f s x = mfderiv_within I I' f t x :=
((mdifferentiable_within_at.has_mfderiv_within_at h).mono st).mfderiv_within hs
omit Is I's
lemma mdifferentiable_within_at.mono (hst : s ⊆ t)
(h : mdifferentiable_within_at I I' f t x) : mdifferentiable_within_at I I' f s x :=
⟨ continuous_within_at.mono h.1 hst,
differentiable_within_at.mono h.2 (inter_subset_inter (preimage_mono hst) (subset.refl _)) ⟩
lemma mdifferentiable_within_at_univ :
mdifferentiable_within_at I I' f univ x ↔ mdifferentiable_at I I' f x :=
by simp [mdifferentiable_within_at, mdifferentiable_at, continuous_within_at_univ]
lemma mdifferentiable_within_at_inter (ht : t ∈ 𝓝 x) :
mdifferentiable_within_at I I' f (s ∩ t) x ↔ mdifferentiable_within_at I I' f s x :=
begin
rw [mdifferentiable_within_at, mdifferentiable_within_at, ext_chart_preimage_inter_eq,
differentiable_within_at_inter, continuous_within_at_inter ht],
exact ext_chart_preimage_mem_nhds I x ht
end
lemma mdifferentiable_within_at_inter' (ht : t ∈ nhds_within x s) :
mdifferentiable_within_at I I' f (s ∩ t) x ↔ mdifferentiable_within_at I I' f s x :=
begin
rw [mdifferentiable_within_at, mdifferentiable_within_at, ext_chart_preimage_inter_eq,
differentiable_within_at_inter', continuous_within_at_inter' ht],
exact ext_chart_preimage_mem_nhds_within I x ht
end
lemma mdifferentiable_at.mdifferentiable_within_at
(h : mdifferentiable_at I I' f x) : mdifferentiable_within_at I I' f s x :=
mdifferentiable_within_at.mono (subset_univ _) (mdifferentiable_within_at_univ.2 h)
lemma mdifferentiable_within_at.mdifferentiable_at
(h : mdifferentiable_within_at I I' f s x) (hs : s ∈ 𝓝 x) : mdifferentiable_at I I' f x :=
begin
have : s = univ ∩ s, by rw univ_inter,
rwa [this, mdifferentiable_within_at_inter hs, mdifferentiable_within_at_univ] at h,
end
lemma mdifferentiable_on.mono
(h : mdifferentiable_on I I' f t) (st : s ⊆ t) : mdifferentiable_on I I' f s :=
λx hx, (h x (st hx)).mono st
lemma mdifferentiable_on_univ :
mdifferentiable_on I I' f univ ↔ mdifferentiable I I' f :=
by { simp only [mdifferentiable_on, mdifferentiable_within_at_univ] with mfld_simps, refl }
lemma mdifferentiable.mdifferentiable_on
(h : mdifferentiable I I' f) : mdifferentiable_on I I' f s :=
(mdifferentiable_on_univ.2 h).mono (subset_univ _)
lemma mdifferentiable_on_of_locally_mdifferentiable_on
(h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ mdifferentiable_on I I' f (s ∩ u)) : mdifferentiable_on I I' f s :=
begin
assume x xs,
rcases h x xs with ⟨t, t_open, xt, ht⟩,
exact (mdifferentiable_within_at_inter (mem_nhds_sets t_open xt)).1 (ht x ⟨xs, xt⟩)
end
include Is I's
@[simp, mfld_simps] lemma mfderiv_within_univ : mfderiv_within I I' f univ = mfderiv I I' f :=
begin
ext x : 1,
simp only [mfderiv_within, mfderiv] with mfld_simps,
rw mdifferentiable_within_at_univ
end
lemma mfderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_mdiff_within_at I s x) :
mfderiv_within I I' f (s ∩ t) x = mfderiv_within I I' f s x :=
by rw [mfderiv_within, mfderiv_within, ext_chart_preimage_inter_eq,
mdifferentiable_within_at_inter ht, fderiv_within_inter (ext_chart_preimage_mem_nhds I x ht) hs]
omit Is I's
/-! ### Deriving continuity from differentiability on manifolds -/
theorem has_mfderiv_within_at.continuous_within_at
(h : mdifferentiable_within_at I I' f s x) : continuous_within_at f s x :=
h.1
theorem has_mfderiv_at.continuous_at (h : has_mfderiv_at I I' f x f') :
continuous_at f x :=
h.1
lemma mdifferentiable_within_at.continuous_within_at (h : mdifferentiable_within_at I I' f s x) :
continuous_within_at f s x :=
h.1
lemma mdifferentiable_at.continuous_at (h : mdifferentiable_at I I' f x) : continuous_at f x :=
h.1
lemma mdifferentiable_on.continuous_on (h : mdifferentiable_on I I' f s) : continuous_on f s :=
λx hx, (h x hx).continuous_within_at
lemma mdifferentiable.continuous (h : mdifferentiable I I' f) : continuous f :=
continuous_iff_continuous_at.2 $ λx, (h x).continuous_at
include Is I's
lemma tangent_map_within_subset {p : tangent_bundle I M}
(st : s ⊆ t) (hs : unique_mdiff_within_at I s p.1) (h : mdifferentiable_within_at I I' f t p.1) :
tangent_map_within I I' f s p = tangent_map_within I I' f t p :=
by { simp only [tangent_map_within], rw mfderiv_within_subset st hs h }
lemma tangent_map_within_univ :
tangent_map_within I I' f univ = tangent_map I I' f :=
by { ext p : 1, simp only [tangent_map_within, tangent_map] with mfld_simps }
lemma tangent_map_within_eq_tangent_map {p : tangent_bundle I M}
(hs : unique_mdiff_within_at I s p.1) (h : mdifferentiable_at I I' f p.1) :
tangent_map_within I I' f s p = tangent_map I I' f p :=
begin
rw ← mdifferentiable_within_at_univ at h,
rw ← tangent_map_within_univ,
exact tangent_map_within_subset (subset_univ _) hs h,
end
@[simp, mfld_simps] lemma tangent_map_within_tangent_bundle_proj {p : tangent_bundle I M} :
tangent_bundle.proj I' M' (tangent_map_within I I' f s p) = f (tangent_bundle.proj I M p) := rfl
@[simp, mfld_simps] lemma tangent_map_within_proj {p : tangent_bundle I M} :
(tangent_map_within I I' f s p).1 = f p.1 := rfl
@[simp, mfld_simps] lemma tangent_map_tangent_bundle_proj {p : tangent_bundle I M} :
tangent_bundle.proj I' M' (tangent_map I I' f p) = f (tangent_bundle.proj I M p) := rfl
@[simp, mfld_simps] lemma tangent_map_proj {p : tangent_bundle I M} :
(tangent_map I I' f p).1 = f p.1 := rfl
omit Is I's
/-! ### Congruence lemmas for derivatives on manifolds -/
lemma has_mfderiv_within_at.congr_of_mem_nhds_within (h : has_mfderiv_within_at I I' f s x f')
(h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) : has_mfderiv_within_at I I' f₁ s x f' :=
begin
refine ⟨continuous_within_at.congr_of_mem_nhds_within h.1 h₁ hx, _⟩,
apply has_fderiv_within_at.congr_of_mem_nhds_within h.2,
{ have : (ext_chart_at I x).symm ⁻¹' {y | f₁ y = f y} ∈
nhds_within ((ext_chart_at I x) x) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
ext_chart_preimage_mem_nhds_within I x h₁,
apply filter.mem_sets_of_superset this (λy, _),
simp only [hx] with mfld_simps {contextual := tt}},
{ simp only [hx] with mfld_simps },
end
lemma has_mfderiv_within_at.congr_mono (h : has_mfderiv_within_at I I' f s x f')
(ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) :
has_mfderiv_within_at I I' f₁ t x f' :=
(h.mono h₁).congr_of_mem_nhds_within (filter.mem_inf_sets_of_right ht) hx
lemma has_mfderiv_at.congr_of_mem_nhds (h : has_mfderiv_at I I' f x f')
(h₁ : ∀ᶠ y in 𝓝 x, f₁ y = f y) : has_mfderiv_at I I' f₁ x f' :=
begin
rw ← has_mfderiv_within_at_univ at ⊢ h,
apply h.congr_of_mem_nhds_within _ (mem_of_nhds h₁ : _),
rwa nhds_within_univ
end
include Is I's
lemma mdifferentiable_within_at.congr_of_mem_nhds_within
(h : mdifferentiable_within_at I I' f s x) (h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y)
(hx : f₁ x = f x) : mdifferentiable_within_at I I' f₁ s x :=
(h.has_mfderiv_within_at.congr_of_mem_nhds_within h₁ hx).mdifferentiable_within_at
variables (I I')
lemma mdifferentiable_within_at_congr_of_mem_nhds_within
(h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) :
mdifferentiable_within_at I I' f s x ↔ mdifferentiable_within_at I I' f₁ s x :=
begin
split,
{ assume h,
apply h.congr_of_mem_nhds_within h₁ hx },
{ assume h,
apply h.congr_of_mem_nhds_within _ hx.symm,
apply h₁.mono,
intro y,
apply eq.symm }
end
variables {I I'}
lemma mdifferentiable_within_at.congr_mono (h : mdifferentiable_within_at I I' f s x)
(ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : mdifferentiable_within_at I I' f₁ t x :=
(has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at ht hx h₁).mdifferentiable_within_at
lemma mdifferentiable_within_at.congr (h : mdifferentiable_within_at I I' f s x)
(ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : mdifferentiable_within_at I I' f₁ s x :=
(has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at ht hx (subset.refl _)).mdifferentiable_within_at
lemma mdifferentiable_on.congr_mono (h : mdifferentiable_on I I' f s) (h' : ∀x ∈ t, f₁ x = f x)
(h₁ : t ⊆ s) : mdifferentiable_on I I' f₁ t :=
λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
lemma mdifferentiable_at.congr_of_mem_nhds (h : mdifferentiable_at I I' f x)
(hL : ∀ᶠ y in 𝓝 x, f₁ y = f y) : mdifferentiable_at I I' f₁ x :=
((h.has_mfderiv_at).congr_of_mem_nhds hL).mdifferentiable_at
lemma mdifferentiable_within_at.mfderiv_within_congr_mono (h : mdifferentiable_within_at I I' f s x)
(hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_mdiff_within_at I t x) (h₁ : t ⊆ s) :
mfderiv_within I I' f₁ t x = (mfderiv_within I I' f s x : _) :=
(has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at hs hx h₁).mfderiv_within hxt
lemma mfderiv_within_congr_of_mem_nhds_within (hs : unique_mdiff_within_at I s x)
(hL : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) :
mfderiv_within I I' f₁ s x = (mfderiv_within I I' f s x : _) :=
begin
by_cases h : mdifferentiable_within_at I I' f s x,
{ exact ((h.has_mfderiv_within_at).congr_of_mem_nhds_within hL hx).mfderiv_within hs },
{ unfold mfderiv_within,
rw [dif_neg h, dif_neg],
rwa ← mdifferentiable_within_at_congr_of_mem_nhds_within I I' hL hx }
end
lemma mfderiv_congr_of_mem_nhds (hL : ∀ᶠ y in 𝓝 x, f₁ y = f y) :
mfderiv I I' f₁ x = (mfderiv I I' f x : _) :=
begin
have A : f₁ x = f x := (mem_of_nhds hL : _),
rw [← mfderiv_within_univ, ← mfderiv_within_univ],
rw ← nhds_within_univ at hL,
exact mfderiv_within_congr_of_mem_nhds_within (unique_mdiff_within_at_univ I) hL A
end
/-! ### Composition lemmas -/
omit Is I's
lemma written_in_ext_chart_comp (h : continuous_within_at f s x) :
{y | written_in_ext_chart_at I I'' x (g ∘ f) y
= ((written_in_ext_chart_at I' I'' (f x) g) ∘ (written_in_ext_chart_at I I' x f)) y}
∈ nhds_within ((ext_chart_at I x) x) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
begin
apply @filter.mem_sets_of_superset _ _
((f ∘ (ext_chart_at I x).symm)⁻¹' (ext_chart_at I' (f x)).source) _
(ext_chart_preimage_mem_nhds_within I x (h.preimage_mem_nhds_within (ext_chart_at_source_mem_nhds _ _))),
assume y hy,
simp only with mfld_simps,
rw (chart_at H' (f x)).left_inv,
simpa only [] with mfld_simps using hy
end
variable (x)
include Is I's I''s
theorem has_mfderiv_within_at.comp
(hg : has_mfderiv_within_at I' I'' g u (f x) g') (hf : has_mfderiv_within_at I I' f s x f')
(hst : s ⊆ f ⁻¹' u) :
has_mfderiv_within_at I I'' (g ∘ f) s x (g'.comp f') :=
begin
refine ⟨continuous_within_at.comp hg.1 hf.1 hst, _⟩,
have A : has_fderiv_within_at ((written_in_ext_chart_at I' I'' (f x) g) ∘
(written_in_ext_chart_at I I' x f))
(continuous_linear_map.comp g' f' : E →L[𝕜] E'')
((ext_chart_at I x).symm ⁻¹' s ∩ range (I))
((ext_chart_at I x) x),
{ have : (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' (f x)).source)
∈ nhds_within ((ext_chart_at I x) x) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
(ext_chart_preimage_mem_nhds_within I x
(hf.1.preimage_mem_nhds_within (ext_chart_at_source_mem_nhds _ _))),
unfold has_mfderiv_within_at at *,
rw [← has_fderiv_within_at_inter' this, ← ext_chart_preimage_inter_eq] at hf ⊢,
have : written_in_ext_chart_at I I' x f ((ext_chart_at I x) x)
= (ext_chart_at I' (f x)) (f x),
by simp only with mfld_simps,
rw ← this at hg,
apply has_fderiv_within_at.comp ((ext_chart_at I x) x) hg.2 hf.2 _,
assume y hy,
simp only with mfld_simps at hy,
have : f (((chart_at H x).symm : H → M) (I.symm y)) ∈ u := hst hy.1.1,
simp only [hy, this] with mfld_simps },
apply A.congr_of_mem_nhds_within (written_in_ext_chart_comp hf.1),
simp only with mfld_simps
end
/-- The chain rule. -/
theorem has_mfderiv_at.comp
(hg : has_mfderiv_at I' I'' g (f x) g') (hf : has_mfderiv_at I I' f x f') :
has_mfderiv_at I I'' (g ∘ f) x (g'.comp f') :=
begin
rw ← has_mfderiv_within_at_univ at *,
exact has_mfderiv_within_at.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ
end
theorem has_mfderiv_at.comp_has_mfderiv_within_at
(hg : has_mfderiv_at I' I'' g (f x) g') (hf : has_mfderiv_within_at I I' f s x f') :
has_mfderiv_within_at I I'' (g ∘ f) s x (g'.comp f') :=
begin
rw ← has_mfderiv_within_at_univ at *,
exact has_mfderiv_within_at.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ
end
lemma mdifferentiable_within_at.comp
(hg : mdifferentiable_within_at I' I'' g u (f x)) (hf : mdifferentiable_within_at I I' f s x)
(h : s ⊆ f ⁻¹' u) : mdifferentiable_within_at I I'' (g ∘ f) s x :=
begin
rcases hf.2 with ⟨f', hf'⟩,
have F : has_mfderiv_within_at I I' f s x f' := ⟨hf.1, hf'⟩,
rcases hg.2 with ⟨g', hg'⟩,
have G : has_mfderiv_within_at I' I'' g u (f x) g' := ⟨hg.1, hg'⟩,
exact (has_mfderiv_within_at.comp x G F h).mdifferentiable_within_at
end
lemma mdifferentiable_at.comp
(hg : mdifferentiable_at I' I'' g (f x)) (hf : mdifferentiable_at I I' f x) :
mdifferentiable_at I I'' (g ∘ f) x :=
(hg.has_mfderiv_at.comp x hf.has_mfderiv_at).mdifferentiable_at
lemma mfderiv_within_comp
(hg : mdifferentiable_within_at I' I'' g u (f x)) (hf : mdifferentiable_within_at I I' f s x)
(h : s ⊆ f ⁻¹' u) (hxs : unique_mdiff_within_at I s x) :
mfderiv_within I I'' (g ∘ f) s x = (mfderiv_within I' I'' g u (f x)).comp (mfderiv_within I I' f s x) :=
begin
apply has_mfderiv_within_at.mfderiv_within _ hxs,
exact has_mfderiv_within_at.comp x hg.has_mfderiv_within_at hf.has_mfderiv_within_at h
end
lemma mfderiv_comp
(hg : mdifferentiable_at I' I'' g (f x)) (hf : mdifferentiable_at I I' f x) :
mfderiv I I'' (g ∘ f) x = (mfderiv I' I'' g (f x)).comp (mfderiv I I' f x) :=
begin
apply has_mfderiv_at.mfderiv,
exact has_mfderiv_at.comp x hg.has_mfderiv_at hf.has_mfderiv_at
end
lemma mdifferentiable_on.comp
(hg : mdifferentiable_on I' I'' g u) (hf : mdifferentiable_on I I' f s) (st : s ⊆ f ⁻¹' u) :
mdifferentiable_on I I'' (g ∘ f) s :=
λx hx, mdifferentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st
lemma mdifferentiable.comp
(hg : mdifferentiable I' I'' g) (hf : mdifferentiable I I' f) : mdifferentiable I I'' (g ∘ f) :=
λx, mdifferentiable_at.comp x (hg (f x)) (hf x)
lemma tangent_map_within_comp_at (p : tangent_bundle I M)
(hg : mdifferentiable_within_at I' I'' g u (f p.1)) (hf : mdifferentiable_within_at I I' f s p.1)
(h : s ⊆ f ⁻¹' u) (hps : unique_mdiff_within_at I s p.1) :
tangent_map_within I I'' (g ∘ f) s p =
tangent_map_within I' I'' g u (tangent_map_within I I' f s p) :=
begin
simp only [tangent_map_within],
rw mfderiv_within_comp p.1 hg hf h hps,
refl
end
lemma tangent_map_comp_at (p : tangent_bundle I M)
(hg : mdifferentiable_at I' I'' g (f p.1)) (hf : mdifferentiable_at I I' f p.1) :
tangent_map I I'' (g ∘ f) p = tangent_map I' I'' g (tangent_map I I' f p) :=
begin
rcases p with ⟨x, v⟩,
simp only [tangent_map],
rw mfderiv_comp x hg hf,
refl
end
lemma tangent_map_comp (hg : mdifferentiable I' I'' g) (hf : mdifferentiable I I' f) :
tangent_map I I'' (g ∘ f) = (tangent_map I' I'' g) ∘ (tangent_map I I' f) :=
by { ext p : 1, exact tangent_map_comp_at _ (hg _) (hf _) }
end derivatives_properties
section specific_functions
/-! ### Differentiability of specific functions -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
{s : set M} {x : M}
section id
/-! #### Identity -/
lemma has_mfderiv_at_id (x : M) :
has_mfderiv_at I I (@_root_.id M) x (continuous_linear_map.id 𝕜 (tangent_space I x)) :=
begin
refine ⟨continuous_id.continuous_at, _⟩,
have : ∀ᶠ y in nhds_within ((ext_chart_at I x) x) (range (I)),
((ext_chart_at I x) ∘ (ext_chart_at I x).symm) y = id y,
{ apply filter.mem_sets_of_superset (ext_chart_at_target_mem_nhds_within I x),
assume y hy,
simp only [-ext_chart_at, hy] with mfld_simps },
apply has_fderiv_within_at.congr_of_mem_nhds_within (has_fderiv_within_at_id _ _) this,
simp only with mfld_simps
end
theorem has_mfderiv_within_at_id (s : set M) (x : M) :
has_mfderiv_within_at I I (@_root_.id M) s x (continuous_linear_map.id 𝕜 (tangent_space I x)) :=
(has_mfderiv_at_id I x).has_mfderiv_within_at
lemma mdifferentiable_at_id : mdifferentiable_at I I (@_root_.id M) x :=
(has_mfderiv_at_id I x).mdifferentiable_at
lemma mdifferentiable_within_at_id : mdifferentiable_within_at I I (@_root_.id M) s x :=
(mdifferentiable_at_id I).mdifferentiable_within_at
lemma mdifferentiable_id : mdifferentiable I I (@_root_.id M) :=
λx, mdifferentiable_at_id I
lemma mdifferentiable_on_id : mdifferentiable_on I I (@_root_.id M) s :=
(mdifferentiable_id I).mdifferentiable_on
@[simp, mfld_simps] lemma mfderiv_id :
mfderiv I I (@_root_.id M) x = (continuous_linear_map.id 𝕜 (tangent_space I x)) :=
has_mfderiv_at.mfderiv (has_mfderiv_at_id I x)
lemma mfderiv_within_id (hxs : unique_mdiff_within_at I s x) :
mfderiv_within I I (@_root_.id M) s x = (continuous_linear_map.id 𝕜 (tangent_space I x)) :=
begin
rw mdifferentiable.mfderiv_within (mdifferentiable_at_id I) hxs,
exact mfderiv_id I
end
end id
section const
/-! #### Constants -/
variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H')
{M' : Type*} [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M']
{c : M'}
lemma has_mfderiv_at_const (c : M') (x : M) :
has_mfderiv_at I I' (λy : M, c) x
(0 : tangent_space I x →L[𝕜] tangent_space I' c) :=
begin
refine ⟨continuous_const.continuous_at, _⟩,
have : (ext_chart_at I' c) ∘ (λ (y : M), c) ∘ (ext_chart_at I x).symm =
(λy, (ext_chart_at I' c) c) := rfl,
rw [written_in_ext_chart_at, this],
apply has_fderiv_within_at_const
end
theorem has_mfderiv_within_at_const (c : M') (s : set M) (x : M) :
has_mfderiv_within_at I I' (λy : M, c) s x
(0 : tangent_space I x →L[𝕜] tangent_space I' c) :=
(has_mfderiv_at_const I I' c x).has_mfderiv_within_at
lemma mdifferentiable_at_const : mdifferentiable_at I I' (λy : M, c) x :=
(has_mfderiv_at_const I I' c x).mdifferentiable_at
lemma mdifferentiable_within_at_const : mdifferentiable_within_at I I' (λy : M, c) s x :=
(mdifferentiable_at_const I I').mdifferentiable_within_at
lemma mdifferentiable_const : mdifferentiable I I' (λy : M, c) :=
λx, mdifferentiable_at_const I I'
lemma mdifferentiable_on_const : mdifferentiable_on I I' (λy : M, c) s :=
(mdifferentiable_const I I').mdifferentiable_on
@[simp, mfld_simps] lemma mfderiv_const : mfderiv I I' (λy : M, c) x =
(0 : tangent_space I x →L[𝕜] tangent_space I' c) :=
has_mfderiv_at.mfderiv (has_mfderiv_at_const I I' c x)
lemma mfderiv_within_const (hxs : unique_mdiff_within_at I s x) :
mfderiv_within I I' (λy : M, c) s x =
(0 : tangent_space I x →L[𝕜] tangent_space I' c) :=
begin
rw mdifferentiable.mfderiv_within (mdifferentiable_at_const I I') hxs,
{ exact mfderiv_const I I' },
{ apply_instance }
end
end const
section model_with_corners
/-! #### Model with corners -/
lemma model_with_corners.mdifferentiable :
mdifferentiable I (model_with_corners_self 𝕜 E) I :=
begin
simp only [mdifferentiable, mdifferentiable_at] with mfld_simps,
assume x,
refine ⟨I.continuous.continuous_at, _⟩,
have : differentiable_within_at 𝕜 id (range I) (I x) :=
differentiable_at_id.differentiable_within_at,
apply this.congr,
{ simp only with mfld_simps {contextual := tt} },
{ simp only with mfld_simps }
end
lemma model_with_corners.mdifferentiable_on_symm :
mdifferentiable_on (model_with_corners_self 𝕜 E) I I.symm (range I) :=
begin
simp only [mdifferentiable_on, mdifferentiable_within_at] with mfld_simps,
assume x hx,
refine ⟨I.continuous_symm.continuous_at.continuous_within_at, _⟩,
have : differentiable_within_at 𝕜 id (range I) x := differentiable_at_id.differentiable_within_at,
apply this.congr,
{ simp only with mfld_simps {contextual := tt} },
{ simp only [hx] with mfld_simps }
end
end model_with_corners
section charts
variable {e : local_homeomorph M H}
lemma mdifferentiable_at_atlas (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) :
mdifferentiable_at I I e x :=
begin
refine ⟨(e.continuous_on x hx).continuous_at (mem_nhds_sets e.open_source hx), _⟩,
have mem : I ((chart_at H x : M → H) x) ∈
I.symm ⁻¹' ((chart_at H x).symm ≫ₕ e).source ∩ range I,
by simp only [hx] with mfld_simps,
have : (chart_at H x).symm.trans e ∈ times_cont_diff_groupoid ⊤ I :=
has_groupoid.compatible _ (chart_mem_atlas H x) h,
have A : times_cont_diff_on 𝕜 ⊤
(I ∘ ((chart_at H x).symm.trans e) ∘ I.symm)
(I.symm ⁻¹' ((chart_at H x).symm.trans e).source ∩ range I) :=
this.1,
have B := A.differentiable_on le_top (I ((chart_at H x : M → H) x)) mem,
simp only with mfld_simps at B,
rw [inter_comm, differentiable_within_at_inter] at B,
{ simpa only [] with mfld_simps },
{ apply mem_nhds_sets (I.continuous_symm _ (local_homeomorph.open_source _)) mem.1 }
end
lemma mdifferentiable_on_atlas (h : e ∈ atlas H M) :
mdifferentiable_on I I e e.source :=
λx hx, (mdifferentiable_at_atlas I h hx).mdifferentiable_within_at
lemma mdifferentiable_at_atlas_symm (h : e ∈ atlas H M) {x : H} (hx : x ∈ e.target) :
mdifferentiable_at I I e.symm x :=
begin
refine ⟨(e.continuous_on_symm x hx).continuous_at (mem_nhds_sets e.open_target hx), _⟩,
have mem : I x ∈ I.symm ⁻¹' (e.symm ≫ₕ chart_at H (e.symm x)).source ∩ range (I),
by simp only [hx] with mfld_simps,
have : e.symm.trans (chart_at H (e.symm x)) ∈ times_cont_diff_groupoid ⊤ I :=
has_groupoid.compatible _ h (chart_mem_atlas H _),
have A : times_cont_diff_on 𝕜 ⊤
(I ∘ (e.symm.trans (chart_at H (e.symm x))) ∘ I.symm)
(I.symm ⁻¹' (e.symm.trans (chart_at H (e.symm x))).source ∩ range I) :=
this.1,
have B := A.differentiable_on le_top (I x) mem,
simp only with mfld_simps at B,
rw [inter_comm, differentiable_within_at_inter] at B,
{ simpa only [] with mfld_simps },
{ apply (mem_nhds_sets (I.continuous_symm _ (local_homeomorph.open_source _)) mem.1) }
end
lemma mdifferentiable_on_atlas_symm (h : e ∈ atlas H M) :
mdifferentiable_on I I e.symm e.target :=
λx hx, (mdifferentiable_at_atlas_symm I h hx).mdifferentiable_within_at
lemma mdifferentiable_of_mem_atlas (h : e ∈ atlas H M) : e.mdifferentiable I I :=
⟨mdifferentiable_on_atlas I h, mdifferentiable_on_atlas_symm I h⟩
lemma mdifferentiable_chart (x : M) : (chart_at H x).mdifferentiable I I :=
mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)
/-- The derivative of the chart at a base point is the chart of the tangent bundle. -/
lemma tangent_map_chart {p q : tangent_bundle I M} (h : q.1 ∈ (chart_at H p.1).source) :
tangent_map I I (chart_at H p.1) q = (chart_at (H × E) p : tangent_bundle I M → H × E) q :=
begin
dsimp [tangent_map],
rw mdifferentiable_at.mfderiv,
{ refl },
{ exact mdifferentiable_at_atlas _ (chart_mem_atlas _ _) h }
end
/-- The derivative of the inverse of the chart at a base point is the inverse of the chart of the
tangent bundle. -/
lemma tangent_map_chart_symm {p : tangent_bundle I M} {q : H × E}
(h : q.1 ∈ (chart_at H p.1).target) :
tangent_map I I (chart_at H p.1).symm q =
((chart_at (H × E) p).symm : H × E → tangent_bundle I M) q :=
begin
dsimp only [tangent_map],
rw mdifferentiable_at.mfderiv (mdifferentiable_at_atlas_symm _ (chart_mem_atlas _ _) h),
-- a trivial instance is needed after the rewrite, handle it right now.
rotate, { apply_instance },
simp only [chart_at, basic_smooth_bundle_core.chart, topological_fiber_bundle_core.local_triv,
basic_smooth_bundle_core.to_topological_fiber_bundle_core,
topological_fiber_bundle_core.local_triv', tangent_bundle_core, h] with mfld_simps
end
end charts
end specific_functions
section mfderiv_fderiv
/-!
### Relations between vector space derivative and manifold derivative
The manifold derivative `mfderiv`, when considered on the model vector space with its trivial
manifold structure, coincides with the usual Frechet derivative `fderiv`. In this section, we prove
this and related statements.
-/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{f : E → E'} {s : set E} {x : E}
lemma unique_mdiff_within_at_iff_unique_diff_within_at :
unique_mdiff_within_at (model_with_corners_self 𝕜 E) s x ↔ unique_diff_within_at 𝕜 s x :=
by simp [unique_mdiff_within_at]
lemma unique_mdiff_on_iff_unique_diff_on :
unique_mdiff_on (model_with_corners_self 𝕜 E) s ↔ unique_diff_on 𝕜 s :=
by simp [unique_mdiff_on, unique_diff_on, unique_mdiff_within_at_iff_unique_diff_within_at]
@[simp, mfld_simps] lemma written_in_ext_chart_model_space :
written_in_ext_chart_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') x f = f :=
by { ext y, simp only with mfld_simps }
/-- For maps between vector spaces, `mdifferentiable_within_at` and `fdifferentiable_within_at`
coincide -/
theorem mdifferentiable_within_at_iff_differentiable_within_at :
mdifferentiable_within_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x
↔ differentiable_within_at 𝕜 f s x :=
begin
simp only [mdifferentiable_within_at] with mfld_simps,
exact ⟨λH, H.2, λH, ⟨H.continuous_within_at, H⟩⟩
end
/-- For maps between vector spaces, `mdifferentiable_at` and `differentiable_at` coincide -/
theorem mdifferentiable_at_iff_differentiable_at :
mdifferentiable_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f x
↔ differentiable_at 𝕜 f x :=
begin
simp only [mdifferentiable_at, differentiable_within_at_univ] with mfld_simps,
exact ⟨λH, H.2, λH, ⟨H.continuous_at, H⟩⟩
end
/-- For maps between vector spaces, `mdifferentiable_on` and `differentiable_on` coincide -/
theorem mdifferentiable_on_iff_differentiable_on :
mdifferentiable_on (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s
↔ differentiable_on 𝕜 f s :=
by simp only [mdifferentiable_on, differentiable_on,
mdifferentiable_within_at_iff_differentiable_within_at]
/-- For maps between vector spaces, `mdifferentiable` and `differentiable` coincide -/
theorem mdifferentiable_iff_differentiable :
mdifferentiable (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f
↔ differentiable 𝕜 f :=
by simp only [mdifferentiable, differentiable, mdifferentiable_at_iff_differentiable_at]
/-- For maps between vector spaces, `mfderiv_within` and `fderiv_within` coincide -/
theorem mfderiv_within_eq_fderiv_within :
mfderiv_within (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x
= fderiv_within 𝕜 f s x :=
begin
by_cases h : mdifferentiable_within_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x,
{ simp only [mfderiv_within, h, dif_pos] with mfld_simps },
{ simp only [mfderiv_within, h, dif_neg, not_false_iff],
rw [mdifferentiable_within_at_iff_differentiable_within_at,
differentiable_within_at] at h,
change ¬(∃(f' : tangent_space (model_with_corners_self 𝕜 E) x →L[𝕜]
tangent_space (model_with_corners_self 𝕜 E') (f x)),
has_fderiv_within_at f f' s x) at h,
simp only [fderiv_within, h, dif_neg, not_false_iff] }
end
/-- For maps between vector spaces, `mfderiv` and `fderiv` coincide -/
theorem mfderiv_eq_fderiv :
mfderiv (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f x = fderiv 𝕜 f x :=
begin
rw [← mfderiv_within_univ, ← fderiv_within_univ],
exact mfderiv_within_eq_fderiv_within
end
end mfderiv_fderiv
/-! ### Differentiable local homeomorphisms -/
namespace local_homeomorph.mdifferentiable
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{M : Type*} [topological_space M] [charted_space H M]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
{M' : Type*} [topological_space M'] [charted_space H' M']
{E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
{H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
{M'' : Type*} [topological_space M''] [charted_space H'' M'']
{e : local_homeomorph M M'} (he : e.mdifferentiable I I')
{e' : local_homeomorph M' M''}
include he
lemma symm : e.symm.mdifferentiable I' I :=
⟨he.2, he.1⟩
protected lemma mdifferentiable_at {x : M} (hx : x ∈ e.source) :
mdifferentiable_at I I' e x :=
(he.1 x hx).mdifferentiable_at (mem_nhds_sets e.open_source hx)
lemma mdifferentiable_at_symm {x : M'} (hx : x ∈ e.target) :
mdifferentiable_at I' I e.symm x :=
(he.2 x hx).mdifferentiable_at (mem_nhds_sets e.open_target hx)
variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners I' M']
[smooth_manifold_with_corners I'' M'']
lemma symm_comp_deriv {x : M} (hx : x ∈ e.source) :
(mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) =
continuous_linear_map.id 𝕜 (tangent_space I x) :=
begin
have : (mfderiv I I (e.symm ∘ e) x) =
(mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) :=
mfderiv_comp x (he.mdifferentiable_at_symm (e.map_source hx)) (he.mdifferentiable_at hx),
rw ← this,
have : mfderiv I I (_root_.id : M → M) x = continuous_linear_map.id _ _ := mfderiv_id I,
rw ← this,
apply mfderiv_congr_of_mem_nhds,
have : e.source ∈ 𝓝 x := mem_nhds_sets e.open_source hx,
apply filter.mem_sets_of_superset this,
assume p hp,
simp only [hp] with mfld_simps
end
lemma comp_symm_deriv {x : M'} (hx : x ∈ e.target) :
(mfderiv I I' e (e.symm x)).comp (mfderiv I' I e.symm x) =
continuous_linear_map.id 𝕜 (tangent_space I' x) :=
he.symm.symm_comp_deriv hx
/-- The derivative of a differentiable local homeomorphism, as a continuous linear equivalence
between the tangent spaces at `x` and `e x`. -/
protected def mfderiv {x : M} (hx : x ∈ e.source) :
tangent_space I x ≃L[𝕜] tangent_space I' (e x) :=
{ inv_fun := (mfderiv I' I e.symm (e x)),
continuous_to_fun := (mfderiv I I' e x).cont,
continuous_inv_fun := (mfderiv I' I e.symm (e x)).cont,
left_inv := λy, begin
have : (continuous_linear_map.id _ _ : tangent_space I x →L[𝕜] tangent_space I x) y = y := rfl,
conv_rhs { rw [← this, ← he.symm_comp_deriv hx] },
refl
end,
right_inv := λy, begin
have : (continuous_linear_map.id 𝕜 _ :
tangent_space I' (e x) →L[𝕜] tangent_space I' (e x)) y = y := rfl,
conv_rhs { rw [← this, ← he.comp_symm_deriv (e.map_source hx)] },
rw e.left_inv hx,
refl
end,
.. mfderiv I I' e x }
lemma range_mfderiv_eq_univ {x : M} (hx : x ∈ e.source) :
range (mfderiv I I' e x) = univ :=
(he.mfderiv hx).to_linear_equiv.to_equiv.range_eq_univ
lemma trans (he': e'.mdifferentiable I' I'') : (e.trans e').mdifferentiable I I'' :=
begin
split,
{ assume x hx,
simp only with mfld_simps at hx,
exact ((he'.mdifferentiable_at hx.2).comp _
(he.mdifferentiable_at hx.1)).mdifferentiable_within_at },
{ assume x hx,
simp only with mfld_simps at hx,
exact ((he.symm.mdifferentiable_at hx.2).comp _
(he'.symm.mdifferentiable_at hx.1)).mdifferentiable_within_at }
end
end local_homeomorph.mdifferentiable
/-! ### Unique derivative sets in manifolds -/
section unique_mdiff
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
{M' : Type*} [topological_space M'] [charted_space H' M']
{s : set M}
/-- If a set has the unique differential property, then its image under a local
diffeomorphism also has the unique differential property. -/
lemma unique_mdiff_on.unique_mdiff_on_preimage [smooth_manifold_with_corners I' M']
(hs : unique_mdiff_on I s) {e : local_homeomorph M M'} (he : e.mdifferentiable I I') :
unique_mdiff_on I' (e.target ∩ e.symm ⁻¹' s) :=
begin
/- Start from a point `x` in the image, and let `z` be its preimage. Then the unique
derivative property at `x` is expressed through `ext_chart_at I' x`, and the unique
derivative property at `z` is expressed through `ext_chart_at I z`. We will argue that
the composition of these two charts with `e` is a local diffeomorphism in vector spaces,
and therefore preserves the unique differential property thanks to lemma
`has_fderiv_within_at.unique_diff_within_at`, saying that a differentiable function with onto
derivative preserves the unique derivative property.-/
assume x hx,
let z := e.symm x,
have z_source : z ∈ e.source, by simp only [hx.1] with mfld_simps,
have zx : e z = x, by simp only [z, hx.1] with mfld_simps,
let F := ext_chart_at I z,
-- the unique derivative property at `z` is expressed through its preferred chart, that we call `F`.
have B : unique_diff_within_at 𝕜
(F.symm ⁻¹' (s ∩ (e.source ∩ e ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) (F z),
{ have : unique_mdiff_within_at I s z := hs _ hx.2,
have S : e.source ∩ e ⁻¹' ((ext_chart_at I' x).source) ∈ 𝓝 z,
{ apply mem_nhds_sets,
apply e.continuous_on.preimage_open_of_open e.open_source (ext_chart_at_open_source I' x),
simp only [z_source, zx] with mfld_simps },
have := this.inter S,
rw [unique_mdiff_within_at_iff] at this,
exact this },
-- denote by `G` the change of coordinate, i.e., the composition of the two extended charts and
-- of `e`
let G := F.symm ≫ e.to_local_equiv ≫ (ext_chart_at I' x),
-- `G` is differentiable
have Diff : ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)).mdifferentiable I I',
{ have A := mdifferentiable_of_mem_atlas I (chart_mem_atlas H z),
have B := mdifferentiable_of_mem_atlas I' (chart_mem_atlas H' x),
exact A.symm.trans (he.trans B) },
have Mmem : (chart_at H z : M → H) z ∈ ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)).source,
by simp only [z_source, zx] with mfld_simps,
have A : differentiable_within_at 𝕜 G (range I) (F z),
{ refine (Diff.mdifferentiable_at Mmem).2.congr (λp hp, _) _;
simp only [G, F] with mfld_simps },
-- let `G'` be its derivative
let G' := fderiv_within 𝕜 G (range I) (F z),
have D₁ : has_fderiv_within_at G G' (range I) (F z) :=
A.has_fderiv_within_at,
have D₂ : has_fderiv_within_at G G'
(F.symm ⁻¹' (s ∩ (e.source ∩ e ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) (F z),
{ apply D₁.mono,
refine subset.trans (inter_subset_right _ _) _,
simp only [F] with mfld_simps },
-- The derivative `G'` is onto, as it is the derivative of a local diffeomorphism, the composition
-- of the two charts and of `e`.
have C₁ : range (G' : E → E') = univ,
{ have : G' = mfderiv I I' ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)) ((chart_at H z : M → H) z),
by { rw (Diff.mdifferentiable_at Mmem).mfderiv, refl },
rw this,
exact Diff.range_mfderiv_eq_univ Mmem },
have C₂ : closure (range (G' : E → E')) = univ, by rw [C₁, closure_univ],
-- key step: thanks to what we have proved about it, `G` preserves the unique derivative property
have key : unique_diff_within_at 𝕜
(G '' (F.symm ⁻¹' (s ∩ (e.source ∩ e ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target))
(G (F z)) := D₂.unique_diff_within_at B C₂,
have : G (F z) = (ext_chart_at I' x) x, by { dsimp [G, F], simp only [hx.1] with mfld_simps },
rw this at key,
apply key.mono,
show G '' (F.symm ⁻¹' (s ∩ (e.source ∩ e ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) ⊆
(ext_chart_at I' x).symm ⁻¹' e.target ∩ (ext_chart_at I' x).symm ⁻¹' (e.symm ⁻¹' s) ∩
range (I'),
rw image_subset_iff,
rintros p ⟨⟨hp₁, ⟨hp₂, hp₄⟩⟩, hp₃⟩,
simp only [G, hp₂, hp₁, mem_preimage.1 hp₄, -ext_chart_at] with mfld_simps,
exact mem_range_self _
end
/-- If a set in a manifold has the unique derivative property, then its pullback by any extended
chart, in the vector space, also has the unique derivative property. -/
lemma unique_mdiff_on.unique_diff_on (hs : unique_mdiff_on I s) (x : M) :
unique_diff_on 𝕜 ((ext_chart_at I x).target ∩ ((ext_chart_at I x).symm ⁻¹' s)) :=
begin
-- this is just a reformulation of `unique_mdiff_on.unique_mdiff_on_preimage`, using as `e`
-- the local chart at `x`.
assume z hz,
simp only with mfld_simps at hz,
have : (chart_at H x).mdifferentiable I I := mdifferentiable_chart _ _,
have T := (hs.unique_mdiff_on_preimage this) (I.symm z),
simp only [hz.left.left, hz.left.right, hz.right, unique_mdiff_within_at] with mfld_simps at ⊢ T,
convert T using 1,
rw @preimage_comp _ _ _ _ (chart_at H x).symm,
-- it remains to show that `(a ∩ b) ∩ c` = `(b ∩ c) ∩ a`, which finish can do but very slowly
ext p,
split;
{ assume hp, simp only with mfld_simps at hp, simp only [hp] with mfld_simps }
end
/-- When considering functions between manifolds, this statement shows up often. It entails
the unique differential of the pullback in extended charts of the set where the function can
be read in the charts. -/
lemma unique_mdiff_on.unique_diff_on_inter_preimage (hs : unique_mdiff_on I s) (x : M) (y : M')
{f : M → M'} (hf : continuous_on f s) :
unique_diff_on 𝕜 ((ext_chart_at I x).target
∩ ((ext_chart_at I x).symm ⁻¹' (s ∩ f⁻¹' (ext_chart_at I' y).source))) :=
begin
have : unique_mdiff_on I (s ∩ f ⁻¹' (ext_chart_at I' y).source),
{ assume z hz,
apply (hs z hz.1).inter',
apply (hf z hz.1).preimage_mem_nhds_within,
exact mem_nhds_sets (ext_chart_at_open_source I' y) hz.2 },
exact this.unique_diff_on _
end
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
(Z : basic_smooth_bundle_core I M F)
/-- In a smooth fiber bundle constructed from core, the preimage under the projection of a set with
unique differential in the basis also has unique differential. -/
lemma unique_mdiff_on.smooth_bundle_preimage (hs : unique_mdiff_on I s) :
unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F))
(Z.to_topological_fiber_bundle_core.proj ⁻¹' s) :=
begin
/- Using a chart (and the fact that unique differentiability is invariant under charts), we
reduce the situation to the model space, where we can use the fact that products respect
unique differentiability. -/
assume p hp,
replace hp : p.fst ∈ s, by simpa only [] with mfld_simps using hp,
let e₀ := chart_at H p.1,
let e := chart_at (H × F) p,
-- It suffices to prove unique differentiability in a chart
suffices h : unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F))
(e.target ∩ e.symm⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s)),
{ have A : unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F)) (e.symm.target ∩
e.symm.symm ⁻¹' (e.target ∩ e.symm⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s))),
{ apply h.unique_mdiff_on_preimage,
exact (mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)).symm,
apply_instance },
have : p ∈ e.symm.target ∩
e.symm.symm ⁻¹' (e.target ∩ e.symm⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s)),
by simp only [e, hp] with mfld_simps,
apply (A _ this).mono,
assume q hq,
simp only [e, local_homeomorph.left_inv _ hq.1] with mfld_simps at hq,
simp only [hq] with mfld_simps },
-- rewrite the relevant set in the chart as a direct product
have : (λ (p : E × F), (I.symm p.1, p.snd)) ⁻¹' e.target ∩
(λ (p : E × F), (I.symm p.1, p.snd)) ⁻¹' (e.symm ⁻¹' (prod.fst ⁻¹' s)) ∩
range (λ (p : H × F), (I p.1, p.snd))
= set.prod (I.symm ⁻¹' (e₀.target ∩ e₀.symm⁻¹' s) ∩ range I) univ,
{ ext q,
split;
{ assume hq,
simp only [prod_range_univ_eq.symm] with mfld_simps at hq,
simp only [hq, prod_range_univ_eq.symm] with mfld_simps } },
assume q hq,
replace hq : q.1 ∈ (chart_at H p.1).target ∧ ((chart_at H p.1).symm : H → M) q.1 ∈ s,
by simpa only [] with mfld_simps using hq,
simp only [unique_mdiff_within_at, model_with_corners.prod, preimage_inter, this] with mfld_simps,
-- apply unique differentiability of products to conclude
apply unique_diff_on.prod _ unique_diff_on_univ,
{ simp only [hq] with mfld_simps },
{ assume x hx,
have A : unique_mdiff_on I (e₀.target ∩ e₀.symm⁻¹' s),
{ apply hs.unique_mdiff_on_preimage,
exact (mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)),
apply_instance },
simp only [unique_mdiff_on, unique_mdiff_within_at, preimage_inter] with mfld_simps at A,
have B := A (I.symm x) hx.1.1 hx.1.2,
rwa [← preimage_inter, model_with_corners.right_inv _ hx.2] at B }
end
lemma unique_mdiff_on.tangent_bundle_proj_preimage (hs : unique_mdiff_on I s):
unique_mdiff_on I.tangent ((tangent_bundle.proj I M) ⁻¹' s) :=
hs.smooth_bundle_preimage _
end unique_mdiff
|
76553c9ad0f03adbbf71e980746f581dab50d95b | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/linear_algebra/dimension.lean | 02f6931b55c76038c9ad38aa9b71c56ec667e422 | [
"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 | 52,889 | 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, Sander Dahmen, Scott Morrison
-/
import linear_algebra.dfinsupp
import linear_algebra.std_basis
import linear_algebra.isomorphisms
import set_theory.cofinality
import linear_algebra.invariant_basis_number
/-!
# Dimension of modules and vector spaces
## Main definitions
* The rank of a module is defined as `module.rank : cardinal`.
This is defined as the supremum of the cardinalities of linearly independent subsets.
* The rank of a linear map is defined as the rank of its range.
## Main statements
* `linear_map.dim_le_of_injective`: the source of an injective linear map has dimension
at most that of the target.
* `linear_map.dim_le_of_surjective`: the target of a surjective linear map has dimension
at most that of that source.
* `basis_fintype_of_finite_spans`:
the existence of a finite spanning set implies that any basis is finite.
* `infinite_basis_le_maximal_linear_independent`:
if `b` is an infinite basis for a module `M`,
and `s` is a maximal linearly independent set,
then the cardinality of `b` is bounded by the cardinality of `s`.
For modules over rings satisfying the rank condition
* `basis.le_span`:
the cardinality of a basis is bounded by the cardinality of any spanning set
For modules over rings satisfying the strong rank condition
* `linear_independent_le_span`:
For any linearly independent family `v : ι → M`
and any finite spanning set `w : set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
* `linear_independent_le_basis`:
If `b` is a basis for a module `M`,
and `s` is a linearly independent set,
then the cardinality of `s` is bounded by the cardinality of `b`.
For modules over rings with invariant basis number
(including all commutative rings and all noetherian rings)
* `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same
cardinality.
For vector spaces (i.e. modules over a field), we have
* `dim_quotient_add_dim`: if `V₁` is a submodule of `V`, then
`module.rank (V/V₁) + module.rank V₁ = module.rank V`.
* `dim_range_add_dim_ker`: the rank-nullity theorem.
## Implementation notes
There is a naming discrepancy: most of the theorem names refer to `dim`,
even though the definition is of `module.rank`.
This reflects that `module.rank` was originally called `dim`, and only defined for vector spaces.
Many theorems in this file are not universe-generic when they relate dimensions
in different universes. They should be as general as they can be without
inserting `lift`s. The types `V`, `V'`, ... all live in different universes,
and `V₁`, `V₂`, ... all live in the same universe.
-/
noncomputable theory
universes u v v' v'' u₁' w w'
variables {K : Type u} {V V₁ V₂ V₃ : Type v} {V' V'₁ : Type v'} {V'' : Type v''}
variables {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open_locale classical big_operators cardinal
open basis submodule function set
section module
section
variables [semiring K] [add_comm_monoid V] [module K V]
include K
variables (K V)
/-- The rank of a module, defined as a term of type `cardinal`.
We define this as the supremum of the cardinalities of linearly independent subsets.
For a free module over any ring satisfying the strong rank condition
(e.g. left-noetherian rings, commutative rings, and in particular division rings and fields),
this is the same as the dimension of the space (i.e. the cardinality of any basis).
In particular this agrees with the usual notion of the dimension of a vector space.
The definition is marked as protected to avoid conflicts with `_root_.rank`,
the rank of a linear map.
-/
protected def module.rank : cardinal :=
cardinal.sup.{v v} (λ ι : {s : set V // linear_independent K (coe : s → V)}, #ι.1)
end
section
variables {R : Type u} [ring R]
variables {M : Type v} [add_comm_group M] [module R M]
variables {M' : Type v'} [add_comm_group M'] [module R M']
variables {M₁ : Type v} [add_comm_group M₁] [module R M₁]
theorem linear_map.lift_dim_le_of_injective (f : M →ₗ[R] M') (i : injective f) :
cardinal.lift.{v'} (module.rank R M) ≤ cardinal.lift.{ v} (module.rank R M') :=
begin
dsimp [module.rank],
fapply cardinal.lift_sup_le_lift_sup',
{ rintro ⟨s, li⟩,
use f '' s,
convert (li.map' f (linear_map.ker_eq_bot.mpr i)).comp
(equiv.set.image ⇑f s i).symm (equiv.injective _),
ext ⟨-, ⟨x, ⟨h, rfl⟩⟩⟩,
simp, },
{ rintro ⟨s, li⟩,
exact cardinal.lift_mk_le'.mpr ⟨(equiv.set.image f s i).to_embedding⟩, }
end
theorem linear_map.dim_le_of_injective (f : M →ₗ[R] M₁) (i : injective f) :
module.rank R M ≤ module.rank R M₁ :=
cardinal.lift_le.1 (f.lift_dim_le_of_injective i)
theorem dim_le {n : ℕ}
(H : ∀ s : finset M, linear_independent R (λ i : s, (i : M)) → s.card ≤ n) :
module.rank R M ≤ n :=
begin
apply cardinal.sup_le.mpr,
rintro ⟨s, li⟩,
exact linear_independent_bounded_of_finset_linear_independent_bounded H _ li,
end
lemma lift_dim_range_le (f : M →ₗ[R] M') :
cardinal.lift.{v} (module.rank R f.range) ≤ cardinal.lift.{v'} (module.rank R M) :=
begin
dsimp [module.rank],
apply cardinal.lift_sup_le,
rintro ⟨s, li⟩,
apply le_trans,
swap 2,
apply cardinal.lift_le.mpr,
refine (cardinal.le_sup _ ⟨range_splitting f '' s, _⟩),
{ apply linear_independent.of_comp f.range_restrict,
convert li.comp (equiv.set.range_splitting_image_equiv f s) (equiv.injective _) using 1, },
{ exact (cardinal.lift_mk_eq'.mpr ⟨equiv.set.range_splitting_image_equiv f s⟩).ge, },
end
lemma dim_range_le (f : M →ₗ[R] M₁) : module.rank R f.range ≤ module.rank R M :=
by simpa using lift_dim_range_le f
lemma lift_dim_map_le (f : M →ₗ[R] M') (p : submodule R M) :
cardinal.lift.{v} (module.rank R (p.map f)) ≤ cardinal.lift.{v'} (module.rank R p) :=
begin
have h := lift_dim_range_le (f.comp (submodule.subtype p)),
rwa [linear_map.range_comp, range_subtype] at h,
end
lemma dim_map_le (f : M →ₗ[R] M₁) (p : submodule R M) : module.rank R (p.map f) ≤ module.rank R p :=
by simpa using lift_dim_map_le f p
lemma dim_le_of_submodule (s t : submodule R M) (h : s ≤ t) :
module.rank R s ≤ module.rank R t :=
(of_le h).dim_le_of_injective $ assume ⟨x, hx⟩ ⟨y, hy⟩ eq,
subtype.eq $ show x = y, from subtype.ext_iff_val.1 eq
/-- Two linearly equivalent vector spaces have the same dimension, a version with different
universes. -/
theorem linear_equiv.lift_dim_eq (f : M ≃ₗ[R] M') :
cardinal.lift.{v'} (module.rank R M) = cardinal.lift.{v} (module.rank R M') :=
begin
apply le_antisymm,
{ exact f.to_linear_map.lift_dim_le_of_injective f.injective, },
{ exact f.symm.to_linear_map.lift_dim_le_of_injective f.symm.injective, },
end
/-- Two linearly equivalent vector spaces have the same dimension. -/
theorem linear_equiv.dim_eq (f : M ≃ₗ[R] M₁) :
module.rank R M = module.rank R M₁ :=
cardinal.lift_inj.1 f.lift_dim_eq
lemma dim_eq_of_injective (f : M →ₗ[R] M₁) (h : injective f) :
module.rank R M = module.rank R f.range :=
(linear_equiv.of_injective f h).dim_eq
/-- Pushforwards of submodules along a `linear_equiv` have the same dimension. -/
lemma linear_equiv.dim_map_eq (f : M ≃ₗ[R] M₁) (p : submodule R M) :
module.rank R (p.map (f : M →ₗ[R] M₁)) = module.rank R p :=
(f.of_submodule p).dim_eq.symm
variables (R M)
@[simp] lemma dim_top : module.rank R (⊤ : submodule R M) = module.rank R M :=
begin
have : (⊤ : submodule R M) ≃ₗ[R] M := linear_equiv.of_top ⊤ rfl,
rw this.dim_eq,
end
variables {R M}
lemma dim_range_of_surjective (f : M →ₗ[R] M') (h : surjective f) :
module.rank R f.range = module.rank R M' :=
by rw [linear_map.range_eq_top.2 h, dim_top]
lemma dim_submodule_le (s : submodule R M) : module.rank R s ≤ module.rank R M :=
begin
rw ←dim_top R M,
exact dim_le_of_submodule _ _ le_top,
end
lemma linear_map.dim_le_of_surjective (f : M →ₗ[R] M₁) (h : surjective f) :
module.rank R M₁ ≤ module.rank R M :=
begin
rw ←dim_range_of_surjective f h,
apply dim_range_le,
end
theorem dim_quotient_le (p : submodule R M) :
module.rank R p.quotient ≤ module.rank R M :=
(mkq p).dim_le_of_surjective (surjective_quot_mk _)
variables [nontrivial R]
lemma {m} cardinal_lift_le_dim_of_linear_independent
{ι : Type w} {v : ι → M} (hv : linear_independent R v) :
cardinal.lift.{(max v m)} (#ι) ≤ cardinal.lift.{(max w m)} (module.rank R M) :=
begin
apply le_trans,
{ exact cardinal.lift_mk_le.mpr
⟨(equiv.of_injective _ hv.injective).to_embedding⟩, },
{ simp only [cardinal.lift_le],
apply le_trans,
swap,
exact cardinal.le_sup _ ⟨range v, hv.coe_range⟩,
exact le_refl _, },
end
lemma cardinal_lift_le_dim_of_linear_independent'
{ι : Type w} {v : ι → M} (hv : linear_independent R v) :
cardinal.lift.{v} (#ι) ≤ cardinal.lift.{w} (module.rank R M) :=
cardinal_lift_le_dim_of_linear_independent.{u v w 0} hv
lemma cardinal_le_dim_of_linear_independent
{ι : Type v} {v : ι → M} (hv : linear_independent R v) :
#ι ≤ module.rank R M :=
by simpa using cardinal_lift_le_dim_of_linear_independent hv
lemma cardinal_le_dim_of_linear_independent'
{s : set M} (hs : linear_independent R (λ x, x : s → M)) :
#s ≤ module.rank R M :=
cardinal_le_dim_of_linear_independent hs
variables (R M)
@[simp] lemma dim_punit : module.rank R punit = 0 :=
begin
apply le_bot_iff.mp,
apply cardinal.sup_le.mpr,
rintro ⟨s, li⟩,
apply le_bot_iff.mpr,
apply cardinal.mk_emptyc_iff.mpr,
simp only [subtype.coe_mk],
by_contradiction h,
have ne : s.nonempty := ne_empty_iff_nonempty.mp h,
simpa using linear_independent.ne_zero (⟨_, ne.some_mem⟩ : s) li,
end
@[simp] lemma dim_bot : module.rank R (⊥ : submodule R M) = 0 :=
begin
have : (⊥ : submodule R M) ≃ₗ[R] punit := bot_equiv_punit,
rw [this.dim_eq, dim_punit],
end
variables {R M}
/--
Over any nontrivial ring, the existence of a finite spanning set implies that any basis is finite.
-/
-- One might hope that a finite spanning set implies that any linearly independent set is finite.
-- While this is true over a division ring
-- (simply because any linearly independent set can be extended to a basis),
-- I'm not certain what more general statements are possible.
def basis_fintype_of_finite_spans (w : set M) [fintype w] (s : span R w = ⊤)
{ι : Type w} (b : basis ι R M) : fintype ι :=
begin
-- We'll work by contradiction, assuming `ι` is infinite.
apply fintype_of_not_infinite _,
introI i,
-- Let `S` be the union of the supports of `x ∈ w` expressed as linear combinations of `b`.
-- This is a finite set since `w` is finite.
let S : finset ι := finset.univ.sup (λ x : w, (b.repr x).support),
let bS : set M := b '' S,
have h : ∀ x ∈ w, x ∈ span R bS,
{ intros x m,
rw [←b.total_repr x, finsupp.span_image_eq_map_total, submodule.mem_map],
use b.repr x,
simp only [and_true, eq_self_iff_true, finsupp.mem_supported],
change (b.repr x).support ≤ S,
convert (finset.le_sup (by simp : (⟨x, m⟩ : w) ∈ finset.univ)),
refl, },
-- Thus this finite subset of the basis elements spans the entire module.
have k : span R bS = ⊤ := eq_top_iff.2 (le_trans s.ge (span_le.2 h)),
-- Now there is some `x : ι` not in `S`, since `ι` is infinite.
obtain ⟨x, nm⟩ := infinite.exists_not_mem_finset S,
-- However it must be in the span of the finite subset,
have k' : b x ∈ span R bS, { rw k, exact mem_top, },
-- giving the desire contradiction.
refine b.linear_independent.not_mem_span_image _ k',
exact nm,
end
/--
Over any ring `R`, if `b` is a basis for a module `M`,
and `s` is a maximal linearly independent set,
then the union of the supports of `x ∈ s` (when written out in the basis `b`) is all of `b`.
-/
-- From [Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973]
lemma union_support_maximal_linear_independent_eq_range_basis
{ι : Type w} (b : basis ι R M)
{κ : Type w'} (v : κ → M) (i : linear_independent R v) (m : i.maximal) :
(⋃ k, ((b.repr (v k)).support : set ι)) = univ :=
begin
-- If that's not the case,
by_contradiction h,
simp only [←ne.def, ne_univ_iff_exists_not_mem, mem_Union, not_exists_not,
finsupp.mem_support_iff, finset.mem_coe] at h,
-- We have some basis element `b b'` which is not in the support of any of the `v i`.
obtain ⟨b', w⟩ := h,
-- Using this, we'll construct a linearly independent family strictly larger than `v`,
-- by also using this `b b'`.
let v' : option κ → M := λ o, o.elim (b b') v,
have r : range v ⊆ range v',
{ rintro - ⟨k, rfl⟩,
use some k,
refl, },
have r' : b b' ∉ range v,
{ rintro ⟨k, p⟩,
simpa [w] using congr_arg (λ m, (b.repr m) b') p, },
have r'' : range v ≠ range v',
{ intro e,
have p : b b' ∈ range v', { use none, refl, },
rw ←e at p,
exact r' p, },
have inj' : injective v',
{ rintros (_|k) (_|k) z,
{ refl, },
{ exfalso, exact r' ⟨k, z.symm⟩, },
{ exfalso, exact r' ⟨k, z⟩, },
{ congr, exact i.injective z, }, },
-- The key step in the proof is checking that this strictly larger family is linearly independent.
have i' : linear_independent R (coe : range v' → M),
{ rw [linear_independent_subtype_range inj', linear_independent_iff],
intros l z,
rw [finsupp.total_option] at z,
simp only [v', option.elim] at z,
change _ + finsupp.total κ M R v l.some = 0 at z,
-- We have some linear combination of `b b'` and the `v i`, which we want to show is trivial.
-- We'll first show the coefficient of `b b'` is zero,
-- by expressing the `v i` in the basis `b`, and using that the `v i` have no `b b'` term.
have l₀ : l none = 0,
{ rw ←eq_neg_iff_add_eq_zero at z,
replace z := eq_neg_of_eq_neg z,
apply_fun (λ x, b.repr x b') at z,
simp only [repr_self, linear_equiv.map_smul, mul_one, finsupp.single_eq_same, pi.neg_apply,
finsupp.smul_single', linear_equiv.map_neg, finsupp.coe_neg] at z,
erw finsupp.congr_fun (finsupp.apply_total R (b.repr : M →ₗ[R] ι →₀ R) v l.some) b' at z,
simpa [finsupp.total_apply, w] using z, },
-- Then all the other coefficients are zero, because `v` is linear independent.
have l₁ : l.some = 0,
{ rw [l₀, zero_smul, zero_add] at z,
exact linear_independent_iff.mp i _ z, },
-- Finally we put those facts together to show the linear combination is trivial.
ext (_|a),
{ simp only [l₀, finsupp.coe_zero, pi.zero_apply], },
{ erw finsupp.congr_fun l₁ a,
simp only [finsupp.coe_zero, pi.zero_apply], }, },
dsimp [linear_independent.maximal] at m,
specialize m (range v') i' r,
exact r'' m,
end
/--
Over any ring `R`, if `b` is an infinite basis for a module `M`,
and `s` is a maximal linearly independent set,
then the cardinality of `b` is bounded by the cardinality of `s`.
-/
lemma infinite_basis_le_maximal_linear_independent'
{ι : Type w} (b : basis ι R M) [infinite ι]
{κ : Type w'} (v : κ → M) (i : linear_independent R v) (m : i.maximal) :
cardinal.lift.{w'} (#ι) ≤ cardinal.lift.{w} (#κ) :=
begin
let Φ := λ k : κ, (b.repr (v k)).support,
have w₁ : #ι ≤ #(set.range Φ),
{ apply cardinal.le_range_of_union_finset_eq_top,
exact union_support_maximal_linear_independent_eq_range_basis b v i m, },
have w₂ :
cardinal.lift.{w'} (#(set.range Φ)) ≤ cardinal.lift.{w} (#κ) :=
cardinal.mk_range_le_lift,
exact (cardinal.lift_le.mpr w₁).trans w₂,
end
/--
Over any ring `R`, if `b` is an infinite basis for a module `M`,
and `s` is a maximal linearly independent set,
then the cardinality of `b` is bounded by the cardinality of `s`.
-/
-- (See `infinite_basis_le_maximal_linear_independent'` for the more general version
-- where the index types can live in different universes.)
lemma infinite_basis_le_maximal_linear_independent
{ι : Type w} (b : basis ι R M) [infinite ι]
{κ : Type w} (v : κ → M) (i : linear_independent R v) (m : i.maximal) :
#ι ≤ #κ :=
cardinal.lift_le.mp (infinite_basis_le_maximal_linear_independent' b v i m)
lemma complete_lattice.independent.subtype_ne_bot_le_rank [no_zero_smul_divisors R M]
{V : ι → submodule R M} (hV : complete_lattice.independent V) :
cardinal.lift.{v} (#{i : ι // V i ≠ ⊥}) ≤ cardinal.lift.{w} (module.rank R M) :=
begin
set I := {i : ι // V i ≠ ⊥},
have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0:M),
{ intros i,
rw ← submodule.ne_bot_iff,
exact i.prop },
choose v hvV hv using hI,
have : linear_independent R v,
{ exact (hV.comp _ subtype.coe_injective).linear_independent _ hvV hv },
exact cardinal_lift_le_dim_of_linear_independent' this
end
end
section rank_zero
variables {R : Type u} {M : Type v}
variables [ring R] [nontrivial R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M]
lemma dim_zero_iff_forall_zero : module.rank R M = 0 ↔ ∀ x : M, x = 0 :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ contrapose! h,
obtain ⟨x, hx⟩ := h,
suffices : 1 ≤ module.rank R M,
{ intro h, exact lt_irrefl _ (lt_of_lt_of_le cardinal.zero_lt_one (h ▸ this)) },
suffices : linear_independent R (λ (y : ({x} : set M)), ↑y),
{ simpa using (cardinal_le_dim_of_linear_independent this), },
exact linear_independent_singleton hx },
{ have : (⊤ : submodule R M) = ⊥,
{ ext x, simp [h x] },
rw [←dim_top, this, dim_bot] }
end
lemma dim_zero_iff : module.rank R M = 0 ↔ subsingleton M :=
dim_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm
lemma dim_pos_iff_exists_ne_zero : 0 < module.rank R M ↔ ∃ x : M, x ≠ 0 :=
begin
rw ←not_iff_not,
simpa using dim_zero_iff_forall_zero
end
lemma dim_pos_iff_nontrivial : 0 < module.rank R M ↔ nontrivial M :=
dim_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm
lemma dim_pos [h : nontrivial M] : 0 < module.rank R M :=
dim_pos_iff_nontrivial.2 h
end rank_zero
section invariant_basis_number
variables {R : Type u} [ring R] [invariant_basis_number R]
variables {M : Type v} [add_comm_group M] [module R M]
/-- The dimension theorem: if `v` and `v'` are two bases, their index types
have the same cardinalities. -/
theorem mk_eq_mk_of_basis (v : basis ι R M) (v' : basis ι' R M) :
cardinal.lift.{w'} (#ι) = cardinal.lift.{w} (#ι') :=
begin
haveI := nontrivial_of_invariant_basis_number R,
by_cases h : #ι < ω,
{ -- `v` is a finite basis, so by `basis_fintype_of_finite_spans` so is `v'`.
haveI : fintype ι := (cardinal.lt_omega_iff_fintype.mp h).some,
haveI : fintype (range v) := set.fintype_range ⇑v,
haveI := basis_fintype_of_finite_spans _ v.span_eq v',
-- We clean up a little:
rw [cardinal.fintype_card, cardinal.fintype_card],
simp only [cardinal.lift_nat_cast, cardinal.nat_cast_inj],
-- Now we can use invariant basis number to show they have the same cardinality.
apply card_eq_of_lequiv R,
exact (((finsupp.linear_equiv_fun_on_fintype R R ι).symm.trans v.repr.symm) ≪≫ₗ
v'.repr) ≪≫ₗ (finsupp.linear_equiv_fun_on_fintype R R ι'), },
{ -- `v` is an infinite basis,
-- so by `infinite_basis_le_maximal_linear_independent`, `v'` is at least as big,
-- and then applying `infinite_basis_le_maximal_linear_independent` again
-- we see they have the same cardinality.
simp only [not_lt] at h,
haveI : infinite ι := cardinal.infinite_iff.mpr h,
have w₁ :=
infinite_basis_le_maximal_linear_independent' v _ v'.linear_independent v'.maximal,
haveI : infinite ι' := cardinal.infinite_iff.mpr (begin
apply cardinal.lift_le.{w' w}.mp,
have p := (cardinal.lift_le.mpr h).trans w₁,
rw cardinal.lift_omega at ⊢ p,
exact p,
end),
have w₂ :=
infinite_basis_le_maximal_linear_independent' v' _ v.linear_independent v.maximal,
exact le_antisymm w₁ w₂, }
end
/-- Given two basis indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant
basis number property, an equiv `ι ≃ ι' `. -/
def basis.index_equiv (v : basis ι R M) (v' : basis ι' R M) : ι ≃ ι' :=
nonempty.some (cardinal.lift_mk_eq.1 (cardinal.lift_max.2 (mk_eq_mk_of_basis v v')))
theorem mk_eq_mk_of_basis' {ι' : Type w} (v : basis ι R M) (v' : basis ι' R M) :
#ι = #ι' :=
cardinal.lift_inj.1 $ mk_eq_mk_of_basis v v'
end invariant_basis_number
section rank_condition
variables {R : Type u} [ring R] [rank_condition R]
variables {M : Type v} [add_comm_group M] [module R M]
/--
An auxiliary lemma for `basis.le_span`.
If `R` satisfies the rank condition,
then for any finite basis `b : basis ι R M`,
and any finite spanning set `w : set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
lemma basis.le_span'' {ι : Type*} [fintype ι] (b : basis ι R M)
{w : set M} [fintype w] (s : span R w = ⊤) :
fintype.card ι ≤ fintype.card w :=
begin
-- We construct an surjective linear map `(w → R) →ₗ[R] (ι → R)`,
-- by expressing a linear combination in `w` as a linear combination in `ι`.
fapply card_le_of_surjective' R,
{ exact b.repr.to_linear_map.comp (finsupp.total w M R coe), },
{ apply surjective.comp,
apply linear_equiv.surjective,
rw [←linear_map.range_eq_top, finsupp.range_total],
simpa using s, },
end
/--
Another auxiliary lemma for `basis.le_span`, which does not require assuming the basis is finite,
but still assumes we have a finite spanning set.
-/
lemma basis_le_span' {ι : Type*} (b : basis ι R M)
{w : set M} [fintype w] (s : span R w = ⊤) :
#ι ≤ fintype.card w :=
begin
haveI := nontrivial_of_invariant_basis_number R,
haveI := basis_fintype_of_finite_spans w s b,
rw cardinal.fintype_card ι,
simp only [cardinal.nat_cast_le],
exact basis.le_span'' b s,
end
/--
If `R` satisfies the rank condition,
then the cardinality of any basis is bounded by the cardinality of any spanning set.
-/
-- Note that if `R` satisfies the strong rank condition,
-- this also follows from `linear_independent_le_span` below.
theorem basis.le_span {J : set M} (v : basis ι R M)
(hJ : span R J = ⊤) : #(range v) ≤ #J :=
begin
haveI := nontrivial_of_invariant_basis_number R,
casesI fintype_or_infinite J,
{ rw [←cardinal.lift_le, cardinal.mk_range_eq_of_injective v.injective, cardinal.fintype_card J],
convert cardinal.lift_le.{w v}.2 (basis_le_span' v hJ),
simp, },
{ have := cardinal.mk_range_eq_of_injective v.injective,
let S : J → set ι := λ j, ↑(v.repr j).support,
let S' : J → set M := λ j, v '' S j,
have hs : range v ⊆ ⋃ j, S' j,
{ intros b hb,
rcases mem_range.1 hb with ⟨i, hi⟩,
have : span R J ≤ comap v.repr.to_linear_map (finsupp.supported R R (⋃ j, S j)) :=
span_le.2 (λ j hj x hx, ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩),
rw hJ at this,
replace : v.repr (v i) ∈ (finsupp.supported R R (⋃ j, S j)) := this trivial,
rw [v.repr_self, finsupp.mem_supported,
finsupp.support_single_ne_zero one_ne_zero] at this,
{ subst b,
rcases mem_Union.1 (this (finset.mem_singleton_self _)) with ⟨j, hj⟩,
exact mem_Union.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ },
{ apply_instance } },
refine le_of_not_lt (λ IJ, _),
suffices : #(⋃ j, S' j) < #(range v),
{ exact not_le_of_lt this ⟨set.embedding_of_subset _ _ hs⟩ },
refine lt_of_le_of_lt (le_trans cardinal.mk_Union_le_sum_mk
(cardinal.sum_le_sum _ (λ _, cardinal.omega) _)) _,
{ exact λ j, le_of_lt (cardinal.lt_omega_iff_finite.2 $ (finset.finite_to_set _).image _) },
{ simpa } },
end
end rank_condition
section strong_rank_condition
variables {R : Type u} [ring R] [strong_rank_condition R]
variables {M : Type v} [add_comm_group M] [module R M]
open submodule
-- An auxiliary lemma for `linear_independent_le_span'`,
-- with the additional assumption that the linearly independent family is finite.
lemma linear_independent_le_span_aux'
{ι : Type*} [fintype ι] (v : ι → M) (i : linear_independent R v)
(w : set M) [fintype w] (s : range v ≤ span R w) :
fintype.card ι ≤ fintype.card w :=
begin
-- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`,
-- by thinking of `f : ι → R` as a linear combination of the finite family `v`,
-- and expressing that (using the axiom of choice) as a linear combination over `w`.
-- We can do this linearly by constructing the map on a basis.
fapply card_le_of_injective' R,
{ apply finsupp.total,
exact λ i, span.repr R w ⟨v i, s (mem_range_self i)⟩, },
{ intros f g h,
apply_fun finsupp.total w M R coe at h,
simp only [finsupp.total_total, submodule.coe_mk, span.finsupp_total_repr] at h,
rw [←sub_eq_zero, ←linear_map.map_sub] at h,
exact sub_eq_zero.mp (linear_independent_iff.mp i _ h), },
end
/--
If `R` satisfies the strong rank condition,
then any linearly independent family `v : ι → M`
contained in the span of some finite `w : set M`,
is itself finite.
-/
def linear_independent_fintype_of_le_span_fintype
{ι : Type*} (v : ι → M) (i : linear_independent R v)
(w : set M) [fintype w] (s : range v ≤ span R w) : fintype ι :=
fintype_of_finset_card_le (fintype.card w) (λ t, begin
let v' := λ x : (t : set ι), v x,
have i' : linear_independent R v' := i.comp _ subtype.val_injective,
have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s,
simpa using linear_independent_le_span_aux' v' i' w s',
end)
/--
If `R` satisfies the strong rank condition,
then for any linearly independent family `v : ι → M`
contained in the span of some finite `w : set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
lemma linear_independent_le_span' {ι : Type*} (v : ι → M) (i : linear_independent R v)
(w : set M) [fintype w] (s : range v ≤ span R w) :
#ι ≤ fintype.card w :=
begin
haveI : fintype ι := linear_independent_fintype_of_le_span_fintype v i w s,
rw cardinal.fintype_card,
simp only [cardinal.nat_cast_le],
exact linear_independent_le_span_aux' v i w s,
end
/--
If `R` satisfies the strong rank condition,
then for any linearly independent family `v : ι → M`
and any finite spanning set `w : set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
lemma linear_independent_le_span {ι : Type*} (v : ι → M) (i : linear_independent R v)
(w : set M) [fintype w] (s : span R w = ⊤) :
#ι ≤ fintype.card w :=
begin
apply linear_independent_le_span' v i w,
rw s,
exact le_top,
end
/-- A linearly-independent family of vectors in a module over a ring satisfying the strong rank
condition must be finite if the module is Noetherian. -/
noncomputable def fintype_of_is_noetherian_linear_independent [is_noetherian R M]
{v : ι → M} (hi : linear_independent R v) : fintype ι :=
begin
have hfg : (⊤ : submodule R M).fg,
{ exact is_noetherian_def.mp infer_instance ⊤, },
rw submodule.fg_def at hfg,
choose s hs hs' using hfg,
haveI : fintype s := hs.fintype,
apply linear_independent_fintype_of_le_span_fintype v hi s,
simp only [hs', set.subset_univ, submodule.top_coe, set.le_eq_subset],
end
/-- A linearly-independent subset of a module over a ring satisfying the strong rank condition
must be finite if the module is Noetherian. -/
lemma finite_of_is_noetherian_linear_independent [is_noetherian R M]
{s : set M} (hi : linear_independent R (coe : s → M)) : s.finite :=
⟨fintype_of_is_noetherian_linear_independent hi⟩
/--
An auxiliary lemma for `linear_independent_le_basis`:
we handle the case where the basis `b` is infinite.
-/
lemma linear_independent_le_infinite_basis
{ι : Type*} (b : basis ι R M) [infinite ι]
{κ : Type*} (v : κ → M) (i : linear_independent R v) :
#κ ≤ #ι :=
begin
by_contradiction,
rw [not_le, ← cardinal.mk_finset_eq_mk ι] at h,
let Φ := λ k : κ, (b.repr (v k)).support,
obtain ⟨s, w : infinite ↥(Φ ⁻¹' {s})⟩ := cardinal.exists_infinite_fiber Φ h (by apply_instance),
let v' := λ k : Φ ⁻¹' {s}, v k,
have i' : linear_independent R v' := i.comp _ subtype.val_injective,
have w' : fintype (Φ ⁻¹' {s}),
{ apply linear_independent_fintype_of_le_span_fintype v' i' (s.image b),
rintros m ⟨⟨p,⟨rfl⟩⟩,rfl⟩,
simp only [set_like.mem_coe, subtype.coe_mk, finset.coe_image],
apply basis.mem_span_repr_support, },
exactI w.false,
end
/--
Over any ring `R` satisfying the strong rank condition,
if `b` is a basis for a module `M`,
and `s` is a linearly independent set,
then the cardinality of `s` is bounded by the cardinality of `b`.
-/
lemma linear_independent_le_basis
{ι : Type*} (b : basis ι R M)
{κ : Type*} (v : κ → M) (i : linear_independent R v) :
#κ ≤ #ι :=
begin
-- We split into cases depending on whether `ι` is infinite.
cases fintype_or_infinite ι; resetI,
{ -- When `ι` is finite, we have `linear_independent_le_span`,
rw cardinal.fintype_card ι,
haveI : nontrivial R := nontrivial_of_invariant_basis_number R,
rw fintype.card_congr (equiv.of_injective b b.injective),
exact linear_independent_le_span v i (range b) b.span_eq, },
{ -- and otherwise we have `linear_indepedent_le_infinite_basis`.
exact linear_independent_le_infinite_basis b v i, },
end
/-- In an `n`-dimensional space, the rank is at most `m`. -/
lemma basis.card_le_card_of_linear_independent_aux
{R : Type*} [ring R] [strong_rank_condition R]
(n : ℕ) {m : ℕ} (v : fin m → fin n → R) :
linear_independent R v → m ≤ n :=
λ h, by simpa using (linear_independent_le_basis (pi.basis_fun R (fin n)) v h)
/--
Over any ring `R` satisfying the strong rank condition,
if `b` is an infinite basis for a module `M`,
then every maximal linearly independent set has the same cardinality as `b`.
This proof (along with some of the lemmas above) comes from
[Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973]
-/
-- When the basis is not infinite this need not be true!
lemma maximal_linear_independent_eq_infinite_basis
{ι : Type*} (b : basis ι R M) [infinite ι]
{κ : Type*} (v : κ → M) (i : linear_independent R v) (m : i.maximal) :
#κ = #ι :=
begin
apply le_antisymm,
{ exact linear_independent_le_basis b v i, },
{ haveI : nontrivial R := nontrivial_of_invariant_basis_number R,
exact infinite_basis_le_maximal_linear_independent b v i m, }
end
theorem basis.mk_eq_dim'' {ι : Type v} (v : basis ι R M) :
#ι = module.rank R M :=
begin
haveI := nontrivial_of_invariant_basis_number R,
apply le_antisymm,
{ transitivity,
swap,
apply cardinal.le_sup,
exact ⟨set.range v, by { convert v.reindex_range.linear_independent, ext, simp }⟩,
exact (cardinal.mk_range_eq v v.injective).ge, },
{ apply cardinal.sup_le.mpr,
rintro ⟨s, li⟩,
apply linear_independent_le_basis v _ li, },
end
-- By this stage we want to have a complete API for `module.rank`,
-- so we set it `irreducible` here, to keep ourselves honest.
attribute [irreducible] module.rank
theorem basis.mk_range_eq_dim (v : basis ι R M) :
#(range v) = module.rank R M :=
v.reindex_range.mk_eq_dim''
/-- If a vector space has a finite basis, then its dimension (seen as a cardinal) is equal to the
cardinality of the basis. -/
lemma dim_eq_card_basis {ι : Type w} [fintype ι] (h : basis ι R M) :
module.rank R M = fintype.card ι :=
by {haveI := nontrivial_of_invariant_basis_number R,
rw [←h.mk_range_eq_dim, cardinal.fintype_card, set.card_range_of_injective h.injective] }
lemma basis.card_le_card_of_linear_independent {ι : Type*} [fintype ι]
(b : basis ι R M) {ι' : Type*} [fintype ι'] {v : ι' → M} (hv : linear_independent R v) :
fintype.card ι' ≤ fintype.card ι :=
begin
letI := nontrivial_of_invariant_basis_number R,
simpa [dim_eq_card_basis b, cardinal.fintype_card] using
cardinal_lift_le_dim_of_linear_independent' hv
end
lemma basis.card_le_card_of_submodule (N : submodule R M) [fintype ι] (b : basis ι R M)
[fintype ι'] (b' : basis ι' R N) : fintype.card ι' ≤ fintype.card ι :=
b.card_le_card_of_linear_independent (b'.linear_independent.map' N.subtype N.ker_subtype)
lemma basis.card_le_card_of_le
{N O : submodule R M} (hNO : N ≤ O) [fintype ι] (b : basis ι R O) [fintype ι']
(b' : basis ι' R N) : fintype.card ι' ≤ fintype.card ι :=
b.card_le_card_of_linear_independent
(b'.linear_independent.map' (submodule.of_le hNO) (N.ker_of_le O _))
theorem basis.mk_eq_dim (v : basis ι R M) :
cardinal.lift.{v} (#ι) = cardinal.lift.{w} (module.rank R M) :=
begin
haveI := nontrivial_of_invariant_basis_number R,
rw [←v.mk_range_eq_dim, cardinal.mk_range_eq_of_injective v.injective]
end
theorem {m} basis.mk_eq_dim' (v : basis ι R M) :
cardinal.lift.{(max v m)} (#ι) = cardinal.lift.{(max w m)} (module.rank R M) :=
by simpa using v.mk_eq_dim
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
lemma basis.nonempty_fintype_index_of_dim_lt_omega {ι : Type*}
(b : basis ι R M) (h : module.rank R M < cardinal.omega) :
nonempty (fintype ι) :=
by rwa [← cardinal.lift_lt, ← b.mk_eq_dim,
-- ensure `omega` has the correct universe
cardinal.lift_omega, ← cardinal.lift_omega.{u_1 v},
cardinal.lift_lt, cardinal.lt_omega_iff_fintype] at h
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
noncomputable def basis.fintype_index_of_dim_lt_omega {ι : Type*}
(b : basis ι R M) (h : module.rank R M < cardinal.omega) :
fintype ι :=
classical.choice (b.nonempty_fintype_index_of_dim_lt_omega h)
/-- If a module has a finite dimension, all bases are indexed by a finite set. -/
lemma basis.finite_index_of_dim_lt_omega {ι : Type*} {s : set ι}
(b : basis s R M) (h : module.rank R M < cardinal.omega) :
s.finite :=
finite_def.2 (b.nonempty_fintype_index_of_dim_lt_omega h)
lemma dim_span {v : ι → M} (hv : linear_independent R v) :
module.rank R ↥(span R (range v)) = #(range v) :=
begin
haveI := nontrivial_of_invariant_basis_number R,
rw [←cardinal.lift_inj, ← (basis.span hv).mk_eq_dim,
cardinal.mk_range_eq_of_injective (@linear_independent.injective ι R M v _ _ _ _ hv)]
end
lemma dim_span_set {s : set M} (hs : linear_independent R (λ x, x : s → M)) :
module.rank R ↥(span R s) = #s :=
by { rw [← @set_of_mem_eq _ s, ← subtype.range_coe_subtype], exact dim_span hs }
/-- If `N` is a submodule in a free, finitely generated module,
do induction on adjoining a linear independent element to a submodule. -/
def submodule.induction_on_rank [is_domain R] [fintype ι] (b : basis ι R M)
(P : submodule R M → Sort*) (ih : ∀ (N : submodule R M),
(∀ (N' ≤ N) (x ∈ N), (∀ (c : R) (y ∈ N'), c • x + y = (0 : M) → c = 0) → P N') →
P N)
(N : submodule R M) : P N :=
submodule.induction_on_rank_aux b P ih (fintype.card ι) N (λ s hs hli,
by simpa using b.card_le_card_of_linear_independent hli)
/-- If `S` a finite-dimensional ring extension of `R` which is free as an `R`-module,
then the rank of an ideal `I` of `S` over `R` is the same as the rank of `S`.
-/
lemma ideal.rank_eq {R S : Type*} [comm_ring R] [strong_rank_condition R] [ring S] [is_domain S]
[algebra R S] {n m : Type*} [fintype n] [fintype m]
(b : basis n R S) {I : ideal S} (hI : I ≠ ⊥) (c : basis m R I) :
fintype.card m = fintype.card n :=
begin
obtain ⟨a, ha⟩ := submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr hI),
have : linear_independent R (λ i, b i • a),
{ have hb := b.linear_independent,
rw fintype.linear_independent_iff at ⊢ hb,
intros g hg,
apply hb g,
simp only [← smul_assoc, ← finset.sum_smul, smul_eq_zero] at hg,
exact hg.resolve_right ha },
exact le_antisymm
(b.card_le_card_of_linear_independent (c.linear_independent.map' (submodule.subtype I)
(linear_map.ker_eq_bot.mpr subtype.coe_injective)))
(c.card_le_card_of_linear_independent this),
end
variables (R)
@[simp] lemma dim_self : module.rank R R = 1 :=
by rw [←cardinal.lift_inj, ← (basis.singleton punit R).mk_eq_dim, cardinal.mk_punit]
end strong_rank_condition
section division_ring
variables [division_ring K] [add_comm_group V] [module K V] [add_comm_group V₁] [module K V₁]
variables {K V}
/-- If a vector space has a finite dimension, the index set of `basis.of_vector_space` is finite. -/
lemma basis.finite_of_vector_space_index_of_dim_lt_omega (h : module.rank K V < cardinal.omega) :
(basis.of_vector_space_index K V).finite :=
finite_def.2 $ (basis.of_vector_space K V).nonempty_fintype_index_of_dim_lt_omega h
variables [add_comm_group V'] [module K V']
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linear_equiv_of_lift_dim_eq
(cond : cardinal.lift.{v'} (module.rank K V) = cardinal.lift.{v} (module.rank K V')) :
nonempty (V ≃ₗ[K] V') :=
begin
let B := basis.of_vector_space K V,
let B' := basis.of_vector_space K V',
have : cardinal.lift.{v' v} (#_) = cardinal.lift.{v v'} (#_),
by rw [B.mk_eq_dim'', cond, B'.mk_eq_dim''],
exact (cardinal.lift_mk_eq.{v v' 0}.1 this).map (B.equiv B')
end
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linear_equiv_of_dim_eq (cond : module.rank K V = module.rank K V₁) :
nonempty (V ≃ₗ[K] V₁) :=
nonempty_linear_equiv_of_lift_dim_eq $ congr_arg _ cond
section
variables (V V' V₁)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def linear_equiv.of_lift_dim_eq
(cond : cardinal.lift.{v'} (module.rank K V) = cardinal.lift.{v} (module.rank K V')) :
V ≃ₗ[K] V' :=
classical.choice (nonempty_linear_equiv_of_lift_dim_eq cond)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def linear_equiv.of_dim_eq (cond : module.rank K V = module.rank K V₁) : V ≃ₗ[K] V₁ :=
classical.choice (nonempty_linear_equiv_of_dim_eq cond)
end
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem linear_equiv.nonempty_equiv_iff_lift_dim_eq :
nonempty (V ≃ₗ[K] V') ↔
cardinal.lift.{v'} (module.rank K V) = cardinal.lift.{v} (module.rank K V') :=
⟨λ ⟨h⟩, linear_equiv.lift_dim_eq h, λ h, nonempty_linear_equiv_of_lift_dim_eq h⟩
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem linear_equiv.nonempty_equiv_iff_dim_eq :
nonempty (V ≃ₗ[K] V₁) ↔ module.rank K V = module.rank K V₁ :=
⟨λ ⟨h⟩, linear_equiv.dim_eq h, λ h, nonempty_linear_equiv_of_dim_eq h⟩
-- TODO how far can we generalise this?
-- When `s` is finite, we could prove this for any ring satisfying the strong rank condition
-- using `linear_independent_le_span'`
lemma dim_span_le (s : set V) : module.rank K (span K s) ≤ #s :=
begin
obtain ⟨b, hb, hsab, hlib⟩ := exists_linear_independent K s,
convert cardinal.mk_le_mk_of_subset hb,
rw [← hsab, dim_span_set hlib]
end
lemma dim_span_of_finset (s : finset V) :
module.rank K (span K (↑s : set V)) < cardinal.omega :=
calc module.rank K (span K (↑s : set V)) ≤ #(↑s : set V) : dim_span_le ↑s
... = s.card : by rw [cardinal.finset_card, finset.coe_sort_coe]
... < cardinal.omega : cardinal.nat_lt_omega _
theorem dim_prod : module.rank K (V × V₁) = module.rank K V + module.rank K V₁ :=
begin
let b := basis.of_vector_space K V,
let c := basis.of_vector_space K V₁,
rw [← cardinal.lift_inj,
← (basis.prod b c).mk_eq_dim,
cardinal.lift_add, ← cardinal.mk_ulift,
← b.mk_eq_dim, ← c.mk_eq_dim,
← cardinal.mk_ulift, ← cardinal.mk_ulift,
cardinal.add_def (ulift _)],
exact cardinal.lift_inj.1 (cardinal.lift_mk_eq.2
⟨equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm ⟩),
end
section fintype
variable [fintype η]
variables [∀i, add_comm_group (φ i)] [∀i, module K (φ i)]
open linear_map
lemma dim_pi : module.rank K (Πi, φ i) = cardinal.sum (λi, module.rank K (φ i)) :=
begin
let b := assume i, basis.of_vector_space K (φ i),
let this : basis (Σ j, _) K (Π j, φ j) := pi.basis b,
rw [← cardinal.lift_inj, ← this.mk_eq_dim],
simp [← (b _).mk_range_eq_dim]
end
lemma dim_fun {V η : Type u} [fintype η] [add_comm_group V] [module K V] :
module.rank K (η → V) = fintype.card η * module.rank K V :=
by rw [dim_pi, cardinal.sum_const', cardinal.fintype_card]
lemma dim_fun_eq_lift_mul :
module.rank K (η → V) = (fintype.card η : cardinal.{max u₁' v}) *
cardinal.lift.{u₁'} (module.rank K V) :=
by rw [dim_pi, cardinal.sum_const, cardinal.fintype_card, cardinal.lift_nat_cast]
lemma dim_fun' : module.rank K (η → K) = fintype.card η :=
by rw [dim_fun_eq_lift_mul, dim_self, cardinal.lift_one, mul_one, cardinal.nat_cast_inj]
lemma dim_fin_fun (n : ℕ) : module.rank K (fin n → K) = n :=
by simp [dim_fun']
end fintype
end division_ring
section field
variables [field K] [add_comm_group V] [module K V] [add_comm_group V₁] [module K V₁]
variables [add_comm_group V'] [module K V']
variables {K V}
theorem dim_quotient_add_dim (p : submodule K V) :
module.rank K p.quotient + module.rank K p = module.rank K V :=
by classical; exact let ⟨f⟩ := quotient_prod_linear_equiv p in dim_prod.symm.trans f.dim_eq
/-- rank-nullity theorem -/
theorem dim_range_add_dim_ker (f : V →ₗ[K] V₁) :
module.rank K f.range + module.rank K f.ker = module.rank K V :=
begin
haveI := λ (p : submodule K V), classical.dec_eq p.quotient,
rw [← f.quot_ker_equiv_range.dim_eq, dim_quotient_add_dim]
end
lemma dim_eq_of_surjective (f : V →ₗ[K] V₁) (h : surjective f) :
module.rank K V = module.rank K V₁ + module.rank K f.ker :=
by rw [← dim_range_add_dim_ker f, ← dim_range_of_surjective f h]
section
variables [add_comm_group V₂] [module K V₂]
variables [add_comm_group V₃] [module K V₃]
open linear_map
/-- This is mostly an auxiliary lemma for `dim_sup_add_dim_inf_eq`. -/
lemma dim_add_dim_split
(db : V₂ →ₗ[K] V) (eb : V₃ →ₗ[K] V) (cd : V₁ →ₗ[K] V₂) (ce : V₁ →ₗ[K] V₃)
(hde : ⊤ ≤ db.range ⊔ eb.range)
(hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce)
(eq₂ : ∀d e, db d = eb e → (∃c, cd c = d ∧ ce c = e)) :
module.rank K V + module.rank K V₁ = module.rank K V₂ + module.rank K V₃ :=
have hf : surjective (coprod db eb),
begin
refine (range_eq_top.1 $ top_unique $ _),
rwa [← map_top, ← prod_top, map_coprod_prod, ←range_eq_map, ←range_eq_map]
end,
begin
conv {to_rhs, rw [← dim_prod, dim_eq_of_surjective _ hf] },
congr' 1,
apply linear_equiv.dim_eq,
refine linear_equiv.of_bijective _ _ _,
{ refine cod_restrict _ (prod cd (- ce)) _,
{ assume c,
simp only [add_eq_zero_iff_eq_neg, linear_map.prod_apply, mem_ker,
coprod_apply, neg_neg, map_neg, neg_apply],
exact linear_map.ext_iff.1 eq c } },
{ rw [← ker_eq_bot, ker_cod_restrict, ker_prod, hgd, bot_inf_eq] },
{ rw [← range_eq_top, eq_top_iff, range_cod_restrict, ← map_le_iff_le_comap,
map_top, range_subtype],
rintros ⟨d, e⟩,
have h := eq₂ d (-e),
simp only [add_eq_zero_iff_eq_neg, linear_map.prod_apply, mem_ker, set_like.mem_coe,
prod.mk.inj_iff, coprod_apply, map_neg, neg_apply, linear_map.mem_range] at ⊢ h,
assume hde,
rcases h hde with ⟨c, h₁, h₂⟩,
refine ⟨c, h₁, _⟩,
rw [h₂, _root_.neg_neg] }
end
lemma dim_sup_add_dim_inf_eq (s t : submodule K V) :
module.rank K (s ⊔ t : submodule K V) + module.rank K (s ⊓ t : submodule K V) =
module.rank K s + module.rank K t :=
dim_add_dim_split (of_le le_sup_left) (of_le le_sup_right) (of_le inf_le_left) (of_le inf_le_right)
begin
rw [← map_le_map_iff' (ker_subtype $ s ⊔ t), map_sup, map_top,
← linear_map.range_comp, ← linear_map.range_comp, subtype_comp_of_le, subtype_comp_of_le,
range_subtype, range_subtype, range_subtype],
exact le_refl _
end
(ker_of_le _ _ _)
begin ext ⟨x, hx⟩, refl end
begin
rintros ⟨b₁, hb₁⟩ ⟨b₂, hb₂⟩ eq,
have : b₁ = b₂ := congr_arg subtype.val eq,
subst this,
exact ⟨⟨b₁, hb₁, hb₂⟩, rfl, rfl⟩
end
lemma dim_add_le_dim_add_dim (s t : submodule K V) :
module.rank K (s ⊔ t : submodule K V) ≤ module.rank K s + module.rank K t :=
by { rw [← dim_sup_add_dim_inf_eq], exact self_le_add_right _ _ }
end
lemma exists_mem_ne_zero_of_dim_pos {s : submodule K V} (h : 0 < module.rank K s) :
∃ b : V, b ∈ s ∧ b ≠ 0 :=
exists_mem_ne_zero_of_ne_bot $ assume eq, by rw [eq, dim_bot] at h; exact lt_irrefl _ h
section rank
-- TODO This definition, and some of the results about it, could be generalized to arbitrary rings.
/-- `rank f` is the rank of a `linear_map f`, defined as the dimension of `f.range`. -/
def rank (f : V →ₗ[K] V') : cardinal := module.rank K f.range
lemma rank_le_domain (f : V →ₗ[K] V₁) : rank f ≤ module.rank K V :=
by { rw [← dim_range_add_dim_ker f], exact self_le_add_right _ _ }
lemma rank_le_range (f : V →ₗ[K] V₁) : rank f ≤ module.rank K V₁ :=
dim_submodule_le _
lemma rank_add_le (f g : V →ₗ[K] V') : rank (f + g) ≤ rank f + rank g :=
calc rank (f + g) ≤ module.rank K (f.range ⊔ g.range : submodule K V') :
begin
refine dim_le_of_submodule _ _ _,
exact (linear_map.range_le_iff_comap.2 $ eq_top_iff'.2 $
assume x, show f x + g x ∈ (f.range ⊔ g.range : submodule K V'), from
mem_sup.2 ⟨_, ⟨x, rfl⟩, _, ⟨x, rfl⟩, rfl⟩)
end
... ≤ rank f + rank g : dim_add_le_dim_add_dim _ _
@[simp] lemma rank_zero : rank (0 : V →ₗ[K] V') = 0 :=
by rw [rank, linear_map.range_zero, dim_bot]
lemma rank_finset_sum_le {η} (s : finset η) (f : η → V →ₗ[K] V') :
rank (∑ d in s, f d) ≤ ∑ d in s, rank (f d) :=
@finset.sum_hom_rel _ _ _ _ _ (λa b, rank a ≤ b) f (λ d, rank (f d)) s (le_of_eq rank_zero)
(λ i g c h, le_trans (rank_add_le _ _) (add_le_add_left h _))
variables [add_comm_group V''] [module K V'']
lemma rank_comp_le1 (g : V →ₗ[K] V') (f : V' →ₗ[K] V'') : rank (f.comp g) ≤ rank f :=
begin
refine dim_le_of_submodule _ _ _,
rw [linear_map.range_comp],
exact linear_map.map_le_range,
end
variables [add_comm_group V'₁] [module K V'₁]
lemma rank_comp_le2 (g : V →ₗ[K] V') (f : V' →ₗ[K] V'₁) : rank (f.comp g) ≤ rank g :=
by rw [rank, rank, linear_map.range_comp]; exact dim_map_le _ _
end rank
-- TODO The remainder of this file could be generalized to arbitrary rings.
/-- The `ι` indexed basis on `V`, where `ι` is an empty type and `V` is zero-dimensional.
See also `finite_dimensional.fin_basis`.
-/
def basis.of_dim_eq_zero {ι : Type*} [is_empty ι] (hV : module.rank K V = 0) :
basis ι K V :=
begin
haveI : subsingleton V := dim_zero_iff.1 hV,
exact basis.empty _
end
@[simp] lemma basis.of_dim_eq_zero_apply {ι : Type*} [is_empty ι]
(hV : module.rank K V = 0) (i : ι) :
basis.of_dim_eq_zero hV i = 0 :=
rfl
lemma le_dim_iff_exists_linear_independent {c : cardinal} :
c ≤ module.rank K V ↔ ∃ s : set V, #s = c ∧ linear_independent K (coe : s → V) :=
begin
split,
{ intro h,
let t := basis.of_vector_space K V,
rw [← t.mk_eq_dim'', cardinal.le_mk_iff_exists_subset] at h,
rcases h with ⟨s, hst, hsc⟩,
exact ⟨s, hsc, (of_vector_space_index.linear_independent K V).mono hst⟩ },
{ rintro ⟨s, rfl, si⟩,
exact cardinal_le_dim_of_linear_independent si }
end
lemma le_dim_iff_exists_linear_independent_finset {n : ℕ} :
↑n ≤ module.rank K V ↔
∃ s : finset V, s.card = n ∧ linear_independent K (coe : (s : set V) → V) :=
begin
simp only [le_dim_iff_exists_linear_independent, cardinal.mk_eq_nat_iff_finset],
split,
{ rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩,
exact ⟨t, rfl, si⟩ },
{ rintro ⟨s, rfl, si⟩,
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩ }
end
lemma le_rank_iff_exists_linear_independent {c : cardinal} {f : V →ₗ[K] V'} :
c ≤ rank f ↔
∃ s : set V, cardinal.lift.{v'} (#s) = cardinal.lift.{v} c ∧
linear_independent K (λ x : s, f x) :=
begin
rcases f.range_restrict.exists_right_inverse_of_surjective f.range_range_restrict with ⟨g, hg⟩,
have fg : left_inverse f.range_restrict g, from linear_map.congr_fun hg,
refine ⟨λ h, _, _⟩,
{ rcases le_dim_iff_exists_linear_independent.1 h with ⟨s, rfl, si⟩,
refine ⟨g '' s, cardinal.mk_image_eq_lift _ _ fg.injective, _⟩,
replace fg : ∀ x, f (g x) = x, by { intro x, convert congr_arg subtype.val (fg x) },
replace si : linear_independent K (λ x : s, f (g x)),
by simpa only [fg] using si.map' _ (ker_subtype _),
exact si.image_of_comp s g f },
{ rintro ⟨s, hsc, si⟩,
have : linear_independent K (λ x : s, f.range_restrict x),
from linear_independent.of_comp (f.range.subtype) (by convert si),
convert cardinal_le_dim_of_linear_independent this.image,
rw [← cardinal.lift_inj, ← hsc, cardinal.mk_image_eq_of_inj_on_lift],
exact inj_on_iff_injective.2 this.injective }
end
lemma le_rank_iff_exists_linear_independent_finset {n : ℕ} {f : V →ₗ[K] V'} :
↑n ≤ rank f ↔ ∃ s : finset V, s.card = n ∧ linear_independent K (λ x : (s : set V), f x) :=
begin
simp only [le_rank_iff_exists_linear_independent, cardinal.lift_nat_cast,
cardinal.lift_eq_nat_iff, cardinal.mk_eq_nat_iff_finset],
split,
{ rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩,
exact ⟨t, rfl, si⟩ },
{ rintro ⟨s, rfl, si⟩,
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩ }
end
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
lemma dim_le_one_iff : module.rank K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v :=
begin
let b := basis.of_vector_space K V,
split,
{ intro hd,
rw [← b.mk_eq_dim'', cardinal.le_one_iff_subsingleton, subsingleton_coe] at hd,
rcases eq_empty_or_nonempty (of_vector_space_index K V) with hb | ⟨⟨v₀, hv₀⟩⟩,
{ use 0,
have h' : ∀ v : V, v = 0, { simpa [hb, submodule.eq_bot_iff] using b.span_eq.symm },
intro v,
simp [h' v] },
{ use v₀,
have h' : (K ∙ v₀) = ⊤, { simpa [hd.eq_singleton_of_mem hv₀] using b.span_eq },
intro v,
have hv : v ∈ (⊤ : submodule K V) := mem_top,
rwa [←h', mem_span_singleton] at hv } },
{ rintros ⟨v₀, hv₀⟩,
have h : (K ∙ v₀) = ⊤,
{ ext, simp [mem_span_singleton, hv₀] },
rw [←dim_top, ←h],
convert dim_span_le _,
simp }
end
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
lemma dim_submodule_le_one_iff (s : submodule K V) : module.rank K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ :=
begin
simp_rw [dim_le_one_iff, le_span_singleton_iff],
split,
{ rintro ⟨⟨v₀, hv₀⟩, h⟩,
use [v₀, hv₀],
intros v hv,
obtain ⟨r, hr⟩ := h ⟨v, hv⟩,
use r,
simp_rw [subtype.ext_iff, coe_smul, submodule.coe_mk] at hr,
exact hr },
{ rintro ⟨v₀, hv₀, h⟩,
use ⟨v₀, hv₀⟩,
rintro ⟨v, hv⟩,
obtain ⟨r, hr⟩ := h v hv,
use r,
simp_rw [subtype.ext_iff, coe_smul, submodule.coe_mk],
exact hr }
end
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
submodule is contained in its span. -/
lemma dim_submodule_le_one_iff' (s : submodule K V) : module.rank K s ≤ 1 ↔ ∃ v₀, s ≤ K ∙ v₀ :=
begin
rw dim_submodule_le_one_iff,
split,
{ rintros ⟨v₀, hv₀, h⟩,
exact ⟨v₀, h⟩ },
{ rintros ⟨v₀, h⟩,
by_cases hw : ∃ w : V, w ∈ s ∧ w ≠ 0,
{ rcases hw with ⟨w, hw, hw0⟩,
use [w, hw],
rcases mem_span_singleton.1 (h hw) with ⟨r', rfl⟩,
have h0 : r' ≠ 0,
{ rintro rfl,
simpa using hw0 },
rwa span_singleton_smul_eq _ h0 },
{ push_neg at hw,
rw ←submodule.eq_bot_iff at hw,
simp [hw] } }
end
end field
end module
|
69d038bbe361e76b63c819425ece29cf69daf4b5 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/logic/examples/cont.lean | 67e3322b8a5327a55c2b29a8dd22d07b04ba9258 | [
"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,774 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
Formalization of Theorem 1 from the following paper:
"The inconsistency of a Brouwerian continuity
principle with the Curry–Howard interpretation"
by Martín Escardó and Chuangjie Xu
-/
import data.nat
open nat sigma.ops
/- Bounded equality: α and β agree in the first n positions. -/
definition beq (α β : nat → nat) (n : nat) : Prop :=
∀ a, a < n → α a = β a
notation α `=[`:50 n:50 `]` β:50 := beq α β n
lemma pred_beq {α β : nat → nat} {n : nat} : α =[n+1] β → α =[n] β :=
λ h a altn, h a (lt.step altn)
definition continuous (f : (nat → nat) → nat) : Type₁ :=
∀ α, Σ n, ∀ β, α =[n] β → f α = f β
definition zω : nat → nat :=
λ x, zero
definition znkω (n : nat) (k : nat) : nat → nat :=
λ x, if x < n then 0 else k
lemma znkω_succ (n : nat) (k : nat) : znkω (n+1) k 0 = 0 :=
rfl
lemma znkω_bound (n : nat) (k : nat) : znkω n k n = k :=
if_neg !lt.irrefl
lemma zω_eq_znkω (n : nat) (k : nat) : zω =[n] znkω n k :=
λ a altn, begin esimp [zω, znkω], rewrite [if_pos altn] end
section
hypothesis all_continuous : ∀ f, continuous f
definition M (f : (nat → nat) → nat) : nat :=
(all_continuous f zω).1
lemma M_spec (f : (nat → nat) → nat) : ∀ β, zω =[M f] β → f zω = f β :=
(all_continuous f zω).2
definition m := M (λα, zero)
definition f β := M (λα, β (α m))
lemma β0_eq (β : nat → nat) : ∀ α, zω =[f β] α → β 0 = β (α m) :=
λ α, M_spec (λα, β (α m)) α
lemma not_all_continuous : false :=
let β := znkω (M f + 1) 1 in
let α := znkω m (M f + 1) in
assert βeq₁ : zω =[M f + 1] β, from
λ (a : nat) (h : a < M f + 1), begin unfold zω, unfold znkω, rewrite [if_pos h] end,
assert βeq₂ : zω =[M f] β, from pred_beq βeq₁,
assert m_eq_fβ : m = f β, from M_spec f β βeq₂,
assert aux : ∀ α, zω =[m] α → β 0 = β (α m), by rewrite m_eq_fβ at {1}; exact (β0_eq β),
assert zero_eq_one : 0 = 1, from calc
0 = β 0 : by rewrite znkω_succ
... = β (α m) : aux α (zω_eq_znkω m (M f + 1))
... = β (M f + 1) : by rewrite znkω_bound
... = 1 : by rewrite znkω_bound,
by contradiction
end
/-
Additional remarks:
By using the slightly different definition of continuous
∀ α, ∃ n, ∀ β, α =[n] β → f α = f β
i.e., using ∃ instead of Σ, we can assume the following axiom
all_continuous : ∀ f, continuous f
However, the system becomes inconsistent again if we also assume Hilbert's choice,
because with Hilbert's choice we can convert ∃ into Σ
-/
|
df81970563af520c68ac422d1afc9dd012d20d42 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebraic_geometry/prime_spectrum/maximal.lean | 7af181eb1bfb69ce90759f2c525c7b9cdcb05b1e | [
"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,199 | lean | /-
Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import algebraic_geometry.prime_spectrum.basic
import ring_theory.localization.as_subring
/-!
# Maximal spectrum of a commutative ring
The maximal spectrum of a commutative ring is the type of all maximal ideals.
It is naturally a subset of the prime spectrum endowed with the subspace topology.
## Main definitions
* `maximal_spectrum R`: The maximal spectrum of a commutative ring `R`,
i.e., the set of all maximal ideals of `R`.
## Implementation notes
The Zariski topology on the maximal spectrum is defined as the subspace topology induced by the
natural inclusion into the prime spectrum to avoid API duplication for zero loci.
-/
noncomputable theory
open_locale classical
universes u v
variables (R : Type u) [comm_ring R]
/-- The maximal spectrum of a commutative ring `R` is the type of all maximal ideals of `R`. -/
@[ext] structure maximal_spectrum :=
(as_ideal : ideal R)
(is_maximal : as_ideal.is_maximal)
attribute [instance] maximal_spectrum.is_maximal
variable {R}
namespace maximal_spectrum
instance [nontrivial R] : nonempty $ maximal_spectrum R :=
let ⟨I, hI⟩ := ideal.exists_maximal R in ⟨⟨I, hI⟩⟩
/-- The natural inclusion from the maximal spectrum to the prime spectrum. -/
def to_prime_spectrum (x : maximal_spectrum R) : prime_spectrum R :=
⟨x.as_ideal, x.is_maximal.is_prime⟩
lemma to_prime_spectrum_injective : (@to_prime_spectrum R _).injective :=
λ ⟨_, _⟩ ⟨_, _⟩ h, by simpa only [mk.inj_eq] using (prime_spectrum.ext_iff _ _).mp h
open prime_spectrum set
lemma to_prime_spectrum_range :
set.range (@to_prime_spectrum R _) = {x | is_closed ({x} : set $ prime_spectrum R)} :=
begin
simp only [is_closed_singleton_iff_is_maximal],
ext ⟨x, _⟩,
exact ⟨λ ⟨y, hy⟩, hy ▸ y.is_maximal, λ hx, ⟨⟨x, hx⟩, rfl⟩⟩
end
/-- The Zariski topology on the maximal spectrum of a commutative ring is defined as the subspace
topology induced by the natural inclusion into the prime spectrum. -/
instance zariski_topology : topological_space $ maximal_spectrum R :=
prime_spectrum.zariski_topology.induced to_prime_spectrum
instance : t1_space $ maximal_spectrum R :=
⟨λ x, is_closed_induced_iff.mpr
⟨{to_prime_spectrum x}, (is_closed_singleton_iff_is_maximal _).mpr x.is_maximal,
by simpa only [← image_singleton] using preimage_image_eq {x} to_prime_spectrum_injective⟩⟩
lemma to_prime_spectrum_continuous : continuous $ @to_prime_spectrum R _ := continuous_induced_dom
variables (R) [is_domain R] (K : Type v) [field K] [algebra R K] [is_fraction_ring R K]
/-- An integral domain is equal to the intersection of its localizations at all its maximal ideals
viewed as subalgebras of its field of fractions. -/
theorem infi_localization_eq_bot :
(⨅ v : maximal_spectrum R,
localization.subalgebra.of_field K _ v.as_ideal.prime_compl_le_non_zero_divisors) = ⊥ :=
begin
ext x,
rw [algebra.mem_bot, algebra.mem_infi],
split,
{ apply imp_of_not_imp_not,
intros hrange hlocal,
let denom : ideal R := (submodule.span R {1} : submodule R K).colon (submodule.span R {x}),
have hdenom : (1 : R) ∉ denom :=
begin
intro hdenom,
rcases submodule.mem_span_singleton.mp
(submodule.mem_colon.mp hdenom x $ submodule.mem_span_singleton_self x) with ⟨y, hy⟩,
exact hrange ⟨y, by rw [← mul_one $ algebra_map R K y, ← algebra.smul_def, hy, one_smul]⟩
end,
rcases denom.exists_le_maximal (λ h, (h ▸ hdenom) submodule.mem_top) with ⟨max, hmax, hle⟩,
rcases hlocal ⟨max, hmax⟩ with ⟨n, d, hd, rfl⟩,
apply hd (hle $ submodule.mem_colon.mpr $ λ _ hy, _),
rcases submodule.mem_span_singleton.mp hy with ⟨y, rfl⟩,
exact submodule.mem_span_singleton.mpr
⟨y * n, by rw [algebra.smul_def, mul_one, map_mul, smul_comm, algebra.smul_def,
algebra.smul_def, mul_comm $ algebra_map R K d, inv_mul_cancel_right₀ $
(map_ne_zero_iff _ $ no_zero_smul_divisors.algebra_map_injective R K).mpr $
λ h, (h ▸ hd) max.zero_mem]⟩ },
{ rintro ⟨y, rfl⟩ ⟨v, hv⟩,
exact ⟨y, 1, v.ne_top_iff_one.mp hv.ne_top, by rw [map_one, inv_one, mul_one]⟩ }
end
end maximal_spectrum
namespace prime_spectrum
variables (R) [is_domain R] (K : Type v) [field K] [algebra R K] [is_fraction_ring R K]
/-- An integral domain is equal to the intersection of its localizations at all its prime ideals
viewed as subalgebras of its field of fractions. -/
theorem infi_localization_eq_bot :
(⨅ v : prime_spectrum R,
localization.subalgebra.of_field K _ $ v.as_ideal.prime_compl_le_non_zero_divisors) = ⊥ :=
begin
ext x,
rw [algebra.mem_infi],
split,
{ rw [← maximal_spectrum.infi_localization_eq_bot, algebra.mem_infi],
exact λ hx ⟨v, hv⟩, hx ⟨v, hv.is_prime⟩ },
{ rw [algebra.mem_bot],
rintro ⟨y, rfl⟩ ⟨v, hv⟩,
exact ⟨y, 1, v.ne_top_iff_one.mp hv.ne_top, by rw [map_one, inv_one, mul_one]⟩ }
end
end prime_spectrum
|
c767badd8cb57c625be1bb9c8b8778db72476606 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /04_Quantifiers_and_Equality.org.15.lean | d4d9f1815d86904abfc3a020cd7325f8172b6a4e | [] | 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 | 243 | lean | /- page 52 -/
import standard
open eq.ops
-- BEGIN
example (A : Type) (a b : A) (P : A → Prop) (H1 : a = b) (H2 : P a) : P b :=
eq.subst H1 H2
example (A : Type) (a b : A) (P : A → Prop) (H1 : a = b) (H2 : P a) : P b :=
H1 ▸ H2
-- END
|
3b22fbe89e5fdbc93d69299c79bf39e6362154f3 | 8e381650eb2c1c5361be64ff97e47d956bf2ab9f | /src/Kenny/sites/type.lean | fb1d7da080af5da9414b36e07e90f30a5f7e4a70 | [] | no_license | alreadydone/lean-scheme | 04c51ab08eca7ccf6c21344d45d202780fa667af | 52d7624f57415eea27ed4dfa916cd94189221a1c | refs/heads/master | 1,599,418,221,423 | 1,562,248,559,000 | 1,562,248,559,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 949 | lean | import Kenny.sites.basic category_theory.limits.types
universes u v
namespace category_theory
instance has_pullback_Type : has_pullback (Type u) :=
λ F, by apply_instance
instance has_site_Type : has_site (Type u) :=
{ cov := λ α, { S | ∀ x : α, ∃ (f : Σ β, β ⟶ α), ∃ hf : f ∈ S, x ∈ set.range f.2},
iso_mem := λ α β e x, ⟨⟨β, e.1⟩, set.mem_singleton _, e.2 x, congr_fun e.4 x⟩,
comp_mem := λ α S HS F HF x, let ⟨f, hf, p, hfpx⟩ := HS x in
let ⟨g, hg, q, hgqp⟩ := HF f hf p in
⟨⟨g.1, g.2 ≫ f.2⟩, ⟨f, hf, g, hg, rfl⟩, q, hfpx ▸ hgqp ▸ rfl⟩,
pullback_mem := λ α S HS β f x, let ⟨g, hg, p, hgpx⟩ := HS (f x) in
⟨⟨pullback f g.2, pullback.fst f g.2⟩, ⟨g, hg, rfl⟩,
⟨λ v, pullback_diagram.rec_on v x p (f x),
by intros v w h; cases h; dsimp only [pullback_diagram.to_category]; { refl <|> exact hgpx }⟩,
rfl⟩ }
end category_theory
|
44469f62274fadbd313ba38444f8908dfa59c425 | c3e8fac5ab7ca328e55bccf82a0207a97f96678c | /lean/src/brainfuck.lean | 7decdb20dbb1eb7376f5fb0c16d57e73f7cd92df | [
"Unlicense"
] | permissive | Rotsor/brainfuck | 941bb33862ce3e9d61f0454db5ca02942f4b5775 | 3e6f30f298b8ba76d0bc71b8b5a47cedaf2f0b97 | refs/heads/master | 1,619,718,778,100 | 1,532,913,653,000 | 1,532,913,653,000 | 121,682,141 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,388 | lean | import .byte
import .unix
import .ast
import system.io
import .interpreter
import .concrete_syntax
open byte
universes u v
constant brainfuck_interpreter : brainfuck.ast.program
constant is_correct_parse : brainfuck.ast.program -> list byte -> Prop
constant process_equivalent
(process1 : unix.with_coinduction.process)
(process2 : unix.with_coinduction.process) : Prop
constant correct :
∀
(p : brainfuck.ast.program)
(source : list byte),
is_correct_parse p source ->
process_equivalent
(unix.with_coinduction.feed_input
(source ++ [byte.zero])
(brainfuck.interpreter.interpret brainfuck_interpreter))
(brainfuck.interpreter.interpret p)
--def print (b : byte) : process -> process :=
-- λ (p : process) budget input,
--let res := p budget input in
--(b :: res.fst, res.snd)
-- mutual def run_interpreter_from_state, run_interpreter_from_step, run_interpreter_from_ask
-- run_interpreter_from_state (state : machine_state) : process
-- | 0 := λ _input, ([], false)
-- | nat.succ x := execution_step machine_state
-- incorporate_result
-- with
-- run_interpreter_from_step : step_result -> process
-- | terminate := λ _budget _input, ([], true)
-- | ask f := λ budget input, run_interpreter_from_ask input f budget
-- | print (b, s) -> λ budget input, add_byte (run_interpreter_from_state budget input)
-- | step : machine_state -> step_result
-- with
-- run_interpreter_from_ask : byte list -> (byte -> machine_state) -> time_budget -> output
-- | nil -> λ _f _b, ([], false)
-- | b :: input -> λ f budget -> run_interpreter_from_state (f b) budget input
-- def find_matching_paren (program : )
-- tape index
-- double-tape brainfuck
-- left = "<<"
-- right = ">>"
-- brainfuck variant with interleaved named tapes and some extra stuff
namespace spare_tape_lang
variable tape : Type
variable tape_item : tape → Type
inductive instruction : Type
| prim : instruction
| while : tape → list instruction → instruction
| ask : tape → instruction
| print : tape → instruction
| left : instruction
| right : instruction
| case : tape → list (list instruction) → instruction
def program : Type := list (instruction tape)
variable accumulator : tape
def state : Type :=
(∀ (t : tape), ℕ → tape_item t) × program tape
constant trace : program tape → state tape tape_item → state tape tape_item → Type
/- def implements_relation (p : program) : (state → state → Prop) → Prop
:= λ R → ∀ s1 s2, R s1 s2 → ∃ trace p s1 s2 -/
end spare_tape_lang
namespace simple_edsl
-- def program := list char
def char_to_byte : char -> byte
| '+' := 43
| '-' := 45
| '.' := 46
| '<' := 60
| '>' := 62
| ',' := 44
| '[' := 91
| ']' := 93
| _ := 0
open brainfuck.ast
inductive direction : Type
| forward : direction
| backward : direction
def direction.reverse : direction → direction
| direction.forward := direction.backward
| direction.backward := direction.forward
namespace list
def replicate {A : Type} : nat → A → list A
| nat.zero x := []
| (nat.succ n) x := x :: replicate n x
end list
namespace simple_operations
def reset :=
[ instruction.loop [ instruction.minus ] ]
end simple_operations
open simple_operations
namespace opcode
@[reducible]
def opcode := fin 10
def undefined : opcode := 0
def lparen : opcode := 1
def rparen : opcode := 2
def minus : opcode := 3
def plus : opcode := 4
def left : opcode := 5
def right : opcode := 6
def print : opcode := 7
def ask : opcode := 8
def to_byte (x : opcode) : byte :=
fin.mk x.val (nat.le_trans x.is_lt dec_trivial)
end opcode
open opcode (opcode)
/-
-- sparse tape layout:
-- - accumulator
-- - helper
-- - program: 0 everywhere outside of program and after end of program, 1 etc are op. codes
-- - instruction pointer: 2 to the left, 1 at the pointer, 0 to the right
-- - stack: 0 everywhere except:
- 1 at all the opening brackets that we want to match;
- 1 temorarily at the closing bracket we're matching)
-- - toplevel-bracket we're matching
-/
namespace tape_layout
@[reducible]
def period := 10
@[reducible]
def slot := fin period
def helper : slot := 0
def helper2 : slot := 1
def helper3 : slot := 2
def accumulator : slot := 3
def register1 : slot := 4
def data : slot := 5
-- data pointer: 2 to the left, 1 at the pointer, 0 to the right
def data_pointer : slot := 6
def code : slot := 7
def code_pointer : slot := 8
def stack : slot := 9
def top_of_stack : slot := 10
def move (x : slot) :=
list.replicate x.val instruction.left
def unmove (x : slot) :=
list.replicate x.val instruction.right
def focus (x : slot) : program → program :=
λ p, move x ++ p ++ unmove x
def unfocus (x : slot) : program → program :=
λ p, unmove x ++ p ++ move x
def set (x : slot) (b : byte) : program :=
focus x (reset ++ list.replicate b.val instruction.plus)
def while (x : slot) (p : program) : program :=
focus x [ instruction.loop (unfocus x p) ]
def fin_zero {c : nat} : fin (c + 1) :=
{ val := 0, is_lt := nat.zero_lt_succ c }
def remove_zero {A : Type} {c : nat} : (fin (c + 1) → A) → (fin c → A) :=
λ f c, f (fin.succ c)
-- start out focused on x
def match_worker
(todo : slot) (x : slot)
: ∀ (c : nat) (branch : fin (c + 1) → program), program
| nat.zero branch :=
unfocus x (branch fin_zero ++ set todo 0)
| (nat.succ c) branch :=
[ instruction.loop
(
instruction.minus
:: match_worker c (remove_zero branch)
++ unfocus x (focus todo [
instruction.loop (
instruction.minus ::
unfocus todo (branch fin_zero)
)
])
)
]
def destructive_match_
(todo : slot) (x : slot)
(c : nat) (branch : fin (c + 1) → program): program
:=
set todo 1
++ focus x (match_worker todo x c branch)
def if_before_last {A : Type} (true : A) (false : A) :
∀ (c : nat) (f : fin (c + 2)), A
| (nat.succ x) ⟨ nat.zero, _ ⟩ := false
| nat.zero ⟨ nat.zero, _ ⟩ := true
| nat.zero ⟨ nat.succ nat.zero, lt ⟩ := false
| (nat.succ x) ⟨ (nat.succ y), lt ⟩ :=
if_before_last x ⟨ y, nat.le_of_succ_le_succ lt ⟩
| nat.zero ⟨ nat.succ (nat.succ _), lt ⟩ :=
begin
have qq := nat.not_succ_le_zero _ (nat.le_of_succ_le_succ (nat.le_of_succ_le_succ lt)),
contradiction
end
-- uses [helper]
def destructive_if_ (x : slot) (v : byte) (true : program) (false : program) :=
destructive_match_ helper x (v.val + 1) (λ f, if_before_last true false _ f)
def raw_move
(focus_from : program → program)
(unfocus_from : program → program)
(destinations : list (program → program)) : program
:=
list.join (list.map (λ (focus : program → program), focus reset) destinations)
++ focus_from [ instruction.loop (
[ instruction.minus ] ++
unfocus_from (
list.join (list.map (λ (focus : program → program), focus [ instruction.plus ]) destinations)
)) ]
-- uses [helper]
def copy (from_ : slot) (to : slot) : program :=
raw_move (focus from_) (unfocus from_) [focus helper]
++
raw_move (focus helper) (unfocus helper) ((focus from_) :: focus to :: [])
-- uses [helper] and [helper2]
-- the body may modify [x]
def if_ (x : slot) (v : byte) (true : program) (false : program) : program :=
copy x helper2
++ destructive_if_ x v true false
def whileC (x : slot) (compute_cond : program) (p : program) : program :=
compute_cond
++ focus x [ instruction.loop (unfocus x (p ++ compute_cond)) ]
-- uses all 3 helpers
def whileZ (x : slot) (p : program) : program :=
whileC helper3 (
if_ x 0
(focus helper3 (reset ++ [instruction.plus]))
(focus helper3 reset)) p
def advance_raw : direction → program
| direction.forward := list.replicate period instruction.right
| direction.backward := list.replicate period instruction.left
def advance (slots_to_copy : list slot) (d : direction) :=
let copy : slot → program :=
λ s,
advance_raw d
++ focus s reset
++ (advance_raw (direction.reverse d))
++ while s (
[ instruction.minus ]
++ advance_raw d
++ [ instruction.plus ]
++ advance_raw (direction.reverse d)
)
in
list.join (list.map copy slots_to_copy)
++ advance_raw d
end tape_layout
open tape_layout
namespace blergh
def parsed_char_to_opcode : ∀ {x : byte}, brainfuck.concrete_syntax.parsed_char x → opcode
| _ brainfuck.concrete_syntax.parsed_char.lparen := opcode.lparen
| _ brainfuck.concrete_syntax.parsed_char.rparen := opcode.rparen
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.left _) := opcode.left
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.right _) := opcode.right
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.plus _) := opcode.plus
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.minus _) := opcode.minus
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.print _) := opcode.print
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ brainfuck.ast.instruction.ask _) := opcode.ask
| _ (brainfuck.concrete_syntax.parsed_char.simple_instruction _ (brainfuck.ast.instruction.loop _) wtf) :=
begin
have z : false := begin
cases wtf,
end,
contradiction
end
| _ (brainfuck.concrete_syntax.parsed_char.comment _ _) := opcode.undefined
def decode_instruction (x : fin 100) : opcode :=
parsed_char_to_opcode
(brainfuck.concrete_syntax.parse_char
{ val := x.val, is_lt := (nat.le_trans x.is_lt dec_trivial) })
-- read the program and initialize the initial state
def read_program : program :=
let todo := register1 in
(advance [] direction.forward) ++
set todo 1 ++
while todo (
set todo 1
++ focus accumulator [ instruction.ask ]
++ destructive_match_
helper accumulator 99
(λ x,
if x.val = 0
then
set todo 0
else
set code (opcode.to_byte (decode_instruction x)))
++
if_ todo 0
[]
(advance [] direction.forward))
++ (advance [] direction.backward)
++ while todo (advance [] direction.backward)
++ set data_pointer 2
++ set code_pointer 2
++ (advance [] direction.forward)
++ set data_pointer 1
++ set code_pointer 1
def find_paren (d : direction) : program :=
let open_paren : opcode :=
(match d with | direction.forward := opcode.lparen | direction.backward := opcode.rparen end)
in
let close_paren : opcode :=
(match d with | direction.forward := opcode.rparen | direction.backward := opcode.lparen end)
in
let todo : slot := register1 in
(
set stack 1 ++
set top_of_stack 1 ++
set register1 1 ++
while todo (
(if_ code (opcode.to_byte open_paren)
(set stack 1)
(if_ code (opcode.to_byte close_paren)
(set stack 1 ++
advance [] (direction.reverse d)
++ whileZ stack (
advance [] (direction.reverse d))
++
if_ top_of_stack 0
(-- erase the two matching parens and continue
set stack 0
++ whileZ stack (advance [] d)
++ set stack 0)
(
-- erase the two matching parens and finish
set top_of_stack 0
++ set stack 0
++ whileZ stack (advance [] d)
++ set stack 0
++ set todo 0
)
)
[]
))
++
if_ todo 0 [] (advance [todo] d)
))
def src1 : list byte :=
10 :: 43 :: 45 :: 60 :: 62 :: 46 :: 44 :: []
def echo :=
set register1 1 ++
while register1 (
focus accumulator [ instruction.ask ]
++ focus accumulator [ instruction.print ])
end blergh
end simple_edsl
meta def char_to_byte (c : char) : byte :=
if h : c.val < 256 then { val := c.val, is_lt := h }
else 0
def byte_to_char (b : byte) : char :=
{ val := b.val,
valid := begin refine (is_valid_char_range_1 b.val _),
exact ((nat.le_trans b.is_lt dec_trivial))end }
meta def get_byte : io byte :=
io.stdin >>= λ stdin,
io.fs.get_char stdin >>= λ c,
return (char_to_byte c)
meta def run : unix.with_coinduction.process → io unit :=
λ x,
let r s :=
run { state := x.state, initial_state := s, transition := x.transition }
in
match x.transition x.initial_state with
| unix.with_coinduction.step_result.step s :=
r s
| unix.with_coinduction.step_result.ask f :=
get_byte >>=
λ c, r (f c)
| unix.with_coinduction.step_result.print (c, s) :=
io.stdout >>= λ stdout,
io.fs.put_char stdout (byte_to_char c) >>= (λ _, r s)
end
meta def main := run (brainfuck.interpreter.interpret [])
|
a8363d881582836637846e256a0eff79da37c476 | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/match1.lean | af3cacd919b23da7422a333ca89816bdbdc47753 | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,519 | lean | --
#print "---- h1"
def h1 (b : Bool) : Nat :=
match b with
| true => 0
| false => 10
#eval h1 false
#print "---- h2"
def h2 (x : List Nat) : Nat :=
match x with
| [x1, x2] => x1 + x2
| x::xs => x
| _ => 0
#eval h2 [1, 2]
#eval h2 [10, 4, 5]
#eval h2 []
#print "---- h3"
def h3 (x : Array Nat) : Nat :=
match x with
| #[x] => x
| #[x, y] => x + y
| xs => xs.size
#eval h3 #[10]
#eval h3 #[10, 20]
#eval h3 #[10, 20, 30, 40]
#print "---- inv"
inductive Image {α β : Type} (f : α → β) : β → Type
| mk (a : α) : Image f (f a)
def mkImage {α β : Type} (f : α → β) (a : α) : Image f (f a) :=
Image.mk a
def inv {α β : Type} {f : α → β} {b : β} (t : Image f b) : α :=
match b, t with
| _, Image.mk a => a
#eval inv (mkImage Nat.succ 10)
theorem foo {p q} (h : p ∨ q) : q ∨ p :=
match h with
| Or.inl h => Or.inr h
| Or.inr h => Or.inl h
def f (x : Nat × Nat) : Bool × Bool × Bool → Nat :=
match x with
| (a, b) => fun _ => a
structure S :=
(x y z : Nat := 0)
def f1 : S → S :=
fun { x := x, ..} => { y := x }
theorem ex2 : f1 { x := 10 } = { y := 10 } :=
rfl
universes u
inductive Vec (α : Type u) : Nat → Type u
| nil : Vec α 0
| cons {n} (head : α) (tail : Vec α n) : Vec α (n+1)
inductive VecPred {α : Type u} (P : α → Prop) : {n : Nat} → Vec α n → Prop
| nil : VecPred P Vec.nil
| cons {n : Nat} {head : α} {tail : Vec α n} : P head → VecPred P tail → VecPred P (Vec.cons head tail)
theorem ex3 {α : Type u} (P : α → Prop) : {n : Nat} → (v : Vec α (n+1)) → VecPred P v → Exists P
| _, Vec.cons head _, VecPred.cons h _ => ⟨head, h⟩
theorem ex4 {α : Type u} (P : α → Prop) : {n : Nat} → (v : Vec α (n+1)) → VecPred P v → Exists P
| _, Vec.cons head _, VecPred.cons h (w : VecPred P Vec.nil) => ⟨head, h⟩ -- ERROR
axiom someNat : Nat
noncomputable def f2 (x : Nat) := -- must mark as noncomputable since it uses axiom `someNat`
x + someNat
inductive Parity : Nat -> Type
| even (n) : Parity (n + n)
| odd (n) : Parity (Nat.succ (n + n))
axiom nDiv2 (n : Nat) : n % 2 = 0 → n = n/2 + n/2
axiom nDiv2Succ (n : Nat) : n % 2 ≠ 0 → n = Nat.succ (n/2 + n/2)
def parity (n : Nat) : Parity n :=
if h : n % 2 = 0 then
Eq.ndrec (Parity.even (n/2)) (nDiv2 n h).symm
else
Eq.ndrec (Parity.odd (n/2)) (nDiv2Succ n h).symm
partial def natToBin : (n : Nat) → List Bool
| 0 => []
| n => match n, parity n with
| _, Parity.even j => false :: natToBin j
| _, Parity.odd j => true :: natToBin j
#eval natToBin 6
partial def natToBinBad (n : Nat) : List Bool :=
match n, parity n with
| 0, _ => []
| _, Parity.even j => false :: natToBin j
| _, Parity.odd j => true :: natToBin j
partial def natToBin2 (n : Nat) : List Bool :=
match n, parity n with
| _, Parity.even 0 => []
| _, Parity.even j => false :: natToBin j
| _, Parity.odd j => true :: natToBin j
#eval natToBin2 6
#check fun (a, b) => a -- Error type of pattern variable contains metavariables
#check fun (a, b) => (a:Nat) + b
#check fun (a, b) => a && b
#check fun ((a : Nat), (b : Nat)) => a + b
#check fun
| some a, some b => some (a + b : Nat)
| _, _ => none
-- overapplied matcher
#check fun x => (match x with | 0 => id | x+1 => id) x
#check fun
| #[1, 2] => 2
| #[] => 0
| #[3, 4, 5] => 3
| _ => 4
-- underapplied matcher
def g {α} : List α → Nat
| [a] => 1
| _ => 0
#check g.match_1
#check fun (e : Empty) => (nomatch e : False)
|
aa617b265514775915a3e53ef8695153e4bdcbf5 | 5883d9218e6f144e20eee6ca1dab8529fa1a97c0 | /src/db/subst.lean | 9bd050804023b06bbcf78422ea5538ef22b24996 | [] | no_license | spl/alpha-conversion-is-easy | 0d035bc570e52a6345d4890e4d0c9e3f9b8126c1 | ed937fe85d8495daffd9412a5524c77b9fcda094 | refs/heads/master | 1,607,649,280,020 | 1,517,380,240,000 | 1,517,380,240,000 | 52,174,747 | 4 | 0 | null | 1,456,052,226,000 | 1,456,001,163,000 | Lean | UTF-8 | Lean | false | false | 3,492 | lean | /-
This file contains substitution for `db`.
-/
import .type
import data.fin
namespace nat ------------------------------------------------------------------
variables {m n : ℕ}
def lt_add_pos_right_of_lt (p : m < n) (s : ℕ) : m < n + s :=
match s with
| 0 := p
| (succ s) := lt_trans p $ nat.lt_add_of_pos_right $ zero_lt_succ s
end
def lt_of_lt_succ_of_ne : m < succ n → m ≠ n → m < n :=
nat.lt_of_le_and_ne ∘ le_of_lt_succ
end /- namespace -/ nat --------------------------------------------------------
namespace fin ------------------------------------------------------------------
open nat
variables {n : ℕ}
@[simp]
def raise_right (s : ℕ) : fin n → fin (n + s)
| ⟨m, m_lt_n⟩ := ⟨m, lt_add_pos_right_of_lt m_lt_n s⟩
@[simp]
def add_right (s : ℕ) : fin n → fin (n + s)
| ⟨m, m_lt_n⟩ := ⟨m + s, nat.add_lt_add_right m_lt_n s⟩
@[simp]
theorem succ_eq_add_right_1 {N : fin n} : add_right 1 N = fin.succ N :=
by cases N; reflexivity
def shift (s c : ℕ) (N : fin n) : fin (n + s) :=
if N.val < c then raise_right s N else add_right s N
@[simp]
theorem succ_eq_shift_1_0 {N : fin n} : shift 1 0 N = fin.succ N :=
by cases N; reflexivity
end /- namespace -/ fin --------------------------------------------------------
namespace acie -----------------------------------------------------------------
namespace db -------------------------------------------------------------------
open nat
variables {m n : ℕ} -- De Bruijn indices
def subst (m n : ℕ) : Type :=
fin m → db n
@[inline]
def shift.succ_add {s n : ℕ} : db (succ n + s) → db (succ (n + s)) :=
eq.mpr (eq.rec (eq.refl (db (succ (n + s)))) (eq.symm (nat.succ_add n s)))
def shift (s : ℕ) : ∀ {n : ℕ}, ℕ → db n → db (n + s)
| n c (var N) := var (fin.shift s c N)
| n c (app f e) := app (shift c f) (shift c e)
| n c (lam e) := lam (db.shift.succ_add (shift (succ c) e))
def shift_var : db n → db (succ n) :=
shift 1 0
protected
def subst.id (n : ℕ) : subst n n :=
var
protected
def subst.update (F : subst m n) : subst (succ m) (succ n) :=
λ (M : fin (succ m)),
if p : M = 0 then
var 0
else
shift_var (F (fin.pred M p))
protected
def subst.apply : ∀ {m n : ℕ}, subst m n → db m → db n
| m n F (var M) := F M
| m n F (app f e) := app (subst.apply F f) (subst.apply F e)
| m n F (lam e) := lam (subst.apply (subst.update F) e)
theorem subst.update_id_eq : subst.update (subst.id n) = subst.id (succ n) :=
begin
funext M,
simp [subst.update],
cases decidable.em (M = 0),
case or.inl : M_eq_0 {
rw [dif_pos M_eq_0, M_eq_0],
refl
},
case or.inr : M_ne_0 {
rw dif_neg M_ne_0,
simp [subst.id, shift_var, shift, fin.shift],
rw if_neg (nat.not_lt_zero (fin.pred M M_ne_0).val),
cases M with m m_lt_succ_n,
simp [fin.pred],
cases m,
case nat.zero { cases ne.irrefl (fin.vne_of_ne M_ne_0) },
case nat.succ : m { simp [nat.pred_succ], refl }
}
end
theorem subst.id_eq (e : db n) : subst.apply (subst.id n) e = e :=
begin
induction e,
case var : m M { refl },
case app : m f e rf re { rw [subst.apply, rf, re] },
case lam : m e r { rw [subst.apply, subst.update_id_eq, r] }
end
end /- namespace -/ db ---------------------------------------------------------
end /- namespace -/ acie -------------------------------------------------------
|
678b287172487830967547b4f9bebf9c4fa0af5e | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/finsupp/pwo.lean | 572dbef6e3bc1d4adca18250c301d3e946d922cd | [
"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 | 1,375 | lean | /-
Copyright (c) 2022 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best
-/
import data.finsupp.order
import order.well_founded_set
/-!
# Partial well ordering on finsupps
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains the fact that finitely supported functions from a fintype are
partially well ordered when the codomain is a linear order that is well ordered.
It is in a separate file for now so as to not add imports to the file `order.well_founded_set`.
## Main statements
* `finsupp.is_pwo` - finitely supported functions from a fintype are partially well ordered when
the codomain is a linear order that is well ordered
## Tags
Dickson, order, partial well order
-/
/-- A version of **Dickson's lemma** any subset of functions `σ →₀ α` is partially well
ordered, when `σ` is `finite` and `α` is a linear well order.
This version uses finsupps on a finite type as it is intended for use with `mv_power_series`.
-/
lemma finsupp.is_pwo {α σ : Type*} [has_zero α] [linear_order α] [is_well_order α (<)] [finite σ]
(S : set (σ →₀ α)) : S.is_pwo :=
finsupp.equiv_fun_on_finite.symm_image_image S ▸
set.partially_well_ordered_on.image_of_monotone_on (pi.is_pwo _) (λ a b ha hb, id)
|
6da341729f4510b8ed1ed8a775287cd73270500b | 7bc35d4fbdda0c01e9b22a949940ee5cbb9800d0 | /map.lean | cba57340aa51c12904d456776666171d1b4a8141 | [] | no_license | truonghoangle/manifolds | e6c2534dd46579f56ba99a48e2eb7ce51640e7c0 | dcf4815b29ad363ec9712fd00b7756c36cfa7c1c | refs/heads/main | 1,638,501,090,139 | 1,636,918,550,000 | 1,636,918,550,000 | 185,779,631 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,982 | lean | import algebra.module
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
local attribute [instance] classical.prop_decidable
namespace map
protected def has_zero [has_zero β] : has_zero (α → β) := ⟨λ x, 0⟩
lemma zero_def [has_zero β] (x:α) : @has_zero.zero _ map.has_zero x = 0 := rfl
protected def has_one [has_one β] : has_one (α → β ) := ⟨λ x, (1:β) ⟩
lemma one_def [has_one β] (x:α) : @has_one.one _ map.has_one x = 1 := rfl
protected def has_mul [has_mul β] : has_mul (α → β ) := ⟨λ x y, λ z, x z * y z⟩
lemma mul_def [has_mul β] (x y : α→ β) (z:α) : @has_mul.mul _ map.has_mul x y z= (x z) * (y z) := rfl
protected def has_add [has_add β] : has_add(α → β ) := ⟨λ f g, λ z, f z + g z⟩
lemma add_def [has_add β] (x y : α→ β) (z:α) : @has_add.add _ map.has_add x y z = x z + y z := rfl
protected def has_inv [has_inv β] : has_inv (α → β ) := ⟨λ x, λ y, (x y )⁻¹⟩
lemma inv_def [has_inv β] (x : α → β ) (y: α) : @has_inv.inv _ map.has_inv x y = (x y)⁻¹ := rfl
protected def has_neg [has_neg β] : has_neg (α → β ) := ⟨λ x, λ y, -x y⟩
lemma neg_def [has_neg β] (x : α → β ) (y:α) : @has_neg.neg _ map.has_neg x y = - x y := rfl
protected def has_scalar [has_scalar γ β] : has_scalar γ (α → β ) := ⟨λ a x , λ y, a • x y⟩
lemma smul_def [has_scalar γ β] (a:γ) (x : α → β ) (y:α) : @has_scalar.smul _ _ map.has_scalar a x y = a • x y := rfl
protected def semigroup [semigroup β] : semigroup (α → β) :=
{ mul_assoc := by simp [mul_def, mul_assoc],
..map.has_mul }
protected def comm_semigroup [comm_semigroup β] : comm_semigroup (α → β ) :=
{ mul_comm := by { repeat{intro}, ext1, simp [mul_def, mul_comm]}
..map.semigroup }
protected def monoid [monoid β] : monoid (α → β ) :=
{ monoid.
mul := map.has_mul.mul,
mul_assoc := by simp [mul_def, mul_assoc],
one := λ x:α, (1:β),
one_mul := by {intro, ext1, simp [mul_def, map.one_def]},
mul_one := by {intro, ext1, simp [mul_def, map.one_def]} }
protected def comm_monoid [comm_monoid β] : comm_monoid (α→ β) :=
{ ..map.comm_semigroup,
..map.monoid }
protected def group [group β] : group (α→ β ) :=
{ group.
mul := map.has_mul.mul,
mul_assoc := by simp [mul_def, mul_assoc],
one := λ x:α, (1:β),
one_mul := by {intro, ext1, simp [mul_def, map.one_def]},
mul_one := by {intro, ext1, simp [mul_def, map.one_def]},
mul_left_inv := by {intro, ext1, simp [mul_def, inv_def,map.one_def]},
..map.has_inv }
protected def comm_group [comm_group β] : comm_group (α→ β ) :=
{ ..map.group,
..map.comm_semigroup }
protected def add_semigroup [add_semigroup β] : add_semigroup (α → β ) :=
@additive.add_semigroup _ (@map.semigroup _ _ multiplicative.semigroup)
protected def add_comm_semigroup [add_comm_semigroup β] : add_comm_semigroup (α → β ) :=
@additive.add_comm_semigroup _ (@map.comm_semigroup _ _ multiplicative.comm_semigroup)
protected def add_monoid [add_monoid β] : add_monoid (α → β ) :=
@additive.add_monoid _ (@map.monoid _ _ multiplicative.monoid)
protected def add_comm_monoid [add_comm_monoid β] : add_comm_monoid (α → β) :=
@additive.add_comm_monoid _ (@map.comm_monoid _ _ multiplicative.comm_monoid)
protected def add_group [add_group β] : add_group (α → β ) :=
@additive.add_group _ (@map.group _ _ multiplicative.group)
protected def add_comm_group [add_comm_group β] : add_comm_group (α → β ) :=
@additive.add_comm_group _ (@map.comm_group _ _ multiplicative.comm_group)
protected def semiring [semiring β] : semiring (α → β) :=
{ mul := map.has_mul.mul,
mul_assoc := by simp [mul_def, mul_assoc],
one := λ x:α, (1:β),
zero := λ x:α, (0:β),
one_mul := by {intro, ext1, simp [mul_def, map.one_def]},
mul_one := by {intro, ext1, simp [mul_def, map.one_def]},
right_distrib := by {repeat{intro}, ext1, simp [mul_def, add_def, add_mul]},
left_distrib := by {repeat{intro}, ext1, simp [mul_def, add_def, mul_add]},
zero_mul := by {repeat{intro}, ext1, simp [mul_def, zero_def]},
mul_zero := by {repeat{intro}, ext1, simp [mul_def, zero_def]},
..map.has_mul ,
..map.has_add ,
..map.add_comm_monoid }
protected def comm_semiring [comm_semiring β] : comm_semiring (α → β ) :=
{ ..map.semiring,
..map.comm_monoid }
protected def ring [ring β] : ring (α → β ) :=
{ ..map.semiring,
..map.add_comm_group }
protected def comm_ring [comm_ring β] : comm_ring (α→ β ) :=
{ ..map.comm_monoid ,
..map.ring }
protected def mul_action [monoid γ][mul_action γ β] :mul_action γ (α →β ):=
{ one_smul := by {repeat{intro}, simp[smul_def] },
mul_smul := by {repeat{intro},ext1, simp[smul_def,mul_smul] },
..map.has_scalar}
instance add_monoid'[add_monoid β] : add_monoid (α → β) := map.add_monoid
protected def distrib_mul_action [monoid γ] [add_monoid β] [distrib_mul_action γ β] : distrib_mul_action γ (α → β):=
{ smul_add := by {repeat{intro}, ext1,simp[smul_def,add_def,smul_add ]},
smul_zero := by {repeat{intro}, ext1,simp only [smul_def], by library_search},
..map.mul_action}
instance add_comm_monoid'[add_comm_monoid β] : add_comm_monoid(α → β) := map.add_comm_monoid
protected def semimodule [semiring γ] [add_comm_monoid β] [semimodule γ β ]: semimodule γ (α → β):=
{ add_smul := by {repeat{intro}, ext1,simp[smul_def,add_def,add_smul ]},
zero_smul := by {repeat{intro}, ext1,simp only [smul_def], by library_search},
..map.distrib_mul_action}
instance add_comm_group'[add_comm_group β] : add_comm_group(α → β) := map.add_comm_group
protected def module [ring γ][add_comm_group β ] [module γ β] : module γ (α→ β ) :={..map.semimodule}
protected def vector_space [discrete_field γ][add_comm_group β ] [vector_space γ β] : vector_space γ (α→ β ) :={..map.semimodule}
end map
|
c48127a4f669b5323b74cdfee136816ddeb544ae | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/localization/num_denom.lean | b5727660f5d9171f7127278bebeaa8167f74a98d | [
"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 | 3,993 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import ring_theory.localization.fraction_ring
import ring_theory.localization.integer
import ring_theory.unique_factorization_domain
/-!
# Numerator and denominator in a localization
## Implementation notes
See `src/ring_theory/localization/basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variables {R : Type*} [comm_ring R] (M : submonoid R) {S : Type*} [comm_ring S]
variables [algebra R S] {P : Type*} [comm_ring P]
namespace is_fraction_ring
open is_localization
section num_denom
variables (A : Type*) [comm_ring A] [is_domain A] [unique_factorization_monoid A]
variables {K : Type*} [field K] [algebra A K] [is_fraction_ring A K]
lemma exists_reduced_fraction (x : K) :
∃ (a : A) (b : non_zero_divisors A),
(∀ {d}, d ∣ a → d ∣ b → is_unit d) ∧ mk' K a b = x :=
begin
obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (non_zero_divisors A) x,
obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
unique_factorization_monoid.exists_reduced_factors' a b
(mem_non_zero_divisors_iff_ne_zero.mp b_nonzero),
obtain ⟨c'_nonzero, b'_nonzero⟩ := mul_mem_non_zero_divisors.mp b_nonzero,
refine ⟨a', ⟨b', b'_nonzero⟩, @no_factor, _⟩,
refine mul_left_cancel₀
(is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors b_nonzero) _,
simp only [subtype.coe_mk, ring_hom.map_mul, algebra.smul_def] at *,
erw [←hab, mul_assoc, mk'_spec' _ a' ⟨b', b'_nonzero⟩],
end
/-- `f.num x` is the numerator of `x : f.codomain` as a reduced fraction. -/
noncomputable def num (x : K) : A :=
classical.some (exists_reduced_fraction A x)
/-- `f.num x` is the denominator of `x : f.codomain` as a reduced fraction. -/
noncomputable def denom (x : K) : non_zero_divisors A :=
classical.some (classical.some_spec (exists_reduced_fraction A x))
lemma num_denom_reduced (x : K) :
∀ {d}, d ∣ num A x → d ∣ denom A x → is_unit d :=
(classical.some_spec (classical.some_spec (exists_reduced_fraction A x))).1
@[simp] lemma mk'_num_denom (x : K) : mk' K (num A x) (denom A x) = x :=
(classical.some_spec (classical.some_spec (exists_reduced_fraction A x))).2
variables {A}
lemma num_mul_denom_eq_num_iff_eq {x y : K} :
x * algebra_map A K (denom A y) = algebra_map A K (num A y) ↔ x = y :=
⟨λ h, by simpa only [mk'_num_denom] using eq_mk'_iff_mul_eq.mpr h,
λ h, eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom])⟩
lemma num_mul_denom_eq_num_iff_eq' {x y : K} :
y * algebra_map A K (denom A x) = algebra_map A K (num A x) ↔ x = y :=
⟨λ h, by simpa only [eq_comm, mk'_num_denom] using eq_mk'_iff_mul_eq.mpr h,
λ h, eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom])⟩
lemma num_mul_denom_eq_num_mul_denom_iff_eq {x y : K} :
num A y * denom A x = num A x * denom A y ↔ x = y :=
⟨λ h, by simpa only [mk'_num_denom] using mk'_eq_of_eq h,
λ h, by rw h⟩
lemma eq_zero_of_num_eq_zero {x : K} (h : num A x = 0) : x = 0 :=
num_mul_denom_eq_num_iff_eq'.mp (by rw [zero_mul, h, ring_hom.map_zero])
lemma is_integer_of_is_unit_denom {x : K} (h : is_unit (denom A x : A)) : is_integer A x :=
begin
cases h with d hd,
have d_ne_zero : algebra_map A K (denom A x) ≠ 0 :=
is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors (denom A x).2,
use ↑d⁻¹ * num A x,
refine trans _ (mk'_num_denom A x),
rw [ring_hom.map_mul, ring_hom.map_units_inv, hd],
apply mul_left_cancel₀ d_ne_zero,
rw [←mul_assoc, mul_inv_cancel d_ne_zero, one_mul, mk'_spec']
end
lemma is_unit_denom_of_num_eq_zero {x : K} (h : num A x = 0) : is_unit (denom A x : A) :=
num_denom_reduced A x (h.symm ▸ dvd_zero _) dvd_rfl
end num_denom
variables (S)
end is_fraction_ring
|
939df1cacfa8ef9e6ed44bb27cc8766c87783351 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/linear_algebra/adic_completion.lean | e83c0633bbb73a3c437fec460c6ba6d60864f708 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,109 | 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 linear_algebra.smodeq
import ring_theory.ideal.operations
import ring_theory.jacobson_ideal
/-!
# Completion of a module with respect to an ideal.
In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M`
with respect to an ideal `I`:
## Main definitions
- `is_Hausdorff I M`: this says that the intersection of `I^n M` is `0`.
- `is_precomplete I M`: this says that every Cauchy sequence converges.
- `is_adic_complete I M`: this says that `M` is Hausdorff and precomplete.
- `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`.
- `completion I M`: if `I` is finitely generated, then this is the universal complete module (TODO)
with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is
precomplete.
-/
open submodule
variables {R : Type*} [comm_ring R] (I : ideal R)
variables (M : Type*) [add_comm_group M] [module R M]
variables {N : Type*} [add_comm_group N] [module R N]
/-- A module `M` is Hausdorff with respect to an ideal `I` if `⋂ I^n M = 0`. -/
class is_Hausdorff : Prop :=
(haus' : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : submodule R M)]) → x = 0)
/-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/
class is_precomplete : Prop :=
(prec' : ∀ f : ℕ → M,
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : submodule R M)])
/-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/
class is_adic_complete extends is_Hausdorff I M, is_precomplete I M : Prop
variables {I M}
theorem is_Hausdorff.haus (h : is_Hausdorff I M) :
∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : submodule R M)]) → x = 0 := is_Hausdorff.haus'
theorem is_Hausdorff_iff : is_Hausdorff I M ↔
∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : submodule R M)]) → x = 0 :=
⟨is_Hausdorff.haus, λ h, ⟨h⟩⟩
theorem is_precomplete.prec (h : is_precomplete I M) {f : ℕ → M} :
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : submodule R M)] := is_precomplete.prec' _
theorem is_precomplete_iff : is_precomplete I M ↔ ∀ f : ℕ → M,
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : submodule R M)] :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
variables (I M)
/-- The Hausdorffification of a module with respect to an ideal. -/
@[reducible] def Hausdorffification : Type* :=
(⨅ n : ℕ, I ^ n • ⊤ : submodule R M).quotient
/-- The completion of a module with respect to an ideal. This is not necessarily Hausdorff.
In fact, this is only complete if the ideal is finitely generated. -/
def adic_completion : submodule R (Π n : ℕ, (I ^ n • ⊤ : submodule R M).quotient) :=
{ carrier := { f | ∀ {m n} (h : m ≤ n), liftq _ (mkq _)
(by { rw ker_mkq, exact smul_mono (ideal.pow_le_pow h) (le_refl _) }) (f n) = f m },
zero_mem' := λ m n hmn, by rw [pi.zero_apply, pi.zero_apply, linear_map.map_zero],
add_mem' := λ f g hf hg m n hmn, by rw [pi.add_apply, pi.add_apply,
linear_map.map_add, hf hmn, hg hmn],
smul_mem' := λ c f hf m n hmn, by rw [pi.smul_apply, pi.smul_apply, linear_map.map_smul, hf hmn] }
namespace is_Hausdorff
instance bot : is_Hausdorff (⊥ : ideal R) M :=
⟨λ x hx, by simpa only [pow_one ⊥, bot_smul, smodeq.bot] using hx 1⟩
variables {M}
protected theorem subsingleton (h : is_Hausdorff (⊤ : ideal R) M) : subsingleton M :=
⟨λ x y, eq_of_sub_eq_zero $ h.haus (x - y) $ λ n,
by { rw [ideal.top_pow, top_smul], exact smodeq.top }⟩
variables (M)
@[priority 100] instance of_subsingleton [subsingleton M] : is_Hausdorff I M :=
⟨λ x _, subsingleton.elim _ _⟩
variables {I M}
theorem infi_pow_smul (h : is_Hausdorff I M) :
(⨅ n : ℕ, I ^ n • ⊤ : submodule R M) = ⊥ :=
eq_bot_iff.2 $ λ x hx, (mem_bot _).2 $ h.haus x $ λ n, smodeq.zero.2 $
(mem_infi $ λ n : ℕ, I ^ n • ⊤).1 hx n
end is_Hausdorff
namespace Hausdorffification
/-- The canonical linear map to the Hausdorffification. -/
def of : M →ₗ[R] Hausdorffification I M := mkq _
variables {I M}
@[elab_as_eliminator]
lemma induction_on {C : Hausdorffification I M → Prop} (x : Hausdorffification I M)
(ih : ∀ x, C (of I M x)) : C x :=
quotient.induction_on' x ih
variables (I M)
instance : is_Hausdorff I (Hausdorffification I M) :=
⟨λ x, quotient.induction_on' x $ λ x hx, (quotient.mk_eq_zero _).2 $ (mem_infi _).2 $ λ n, begin
have := comap_map_mkq (⨅ n : ℕ, I ^ n • ⊤ : submodule R M) (I ^ n • ⊤),
simp only [sup_of_le_right (infi_le (λ n, (I ^ n • ⊤ : submodule R M)) n)] at this,
rw [← this, map_smul'', mem_comap, map_top, range_mkq, ← smodeq.zero], exact hx n
end⟩
variables {M} [h : is_Hausdorff I N]
include h
/-- universal property of Hausdorffification: any linear map to a Hausdorff module extends to a
unique map from the Hausdorffification. -/
def lift (f : M →ₗ[R] N) : Hausdorffification I M →ₗ[R] N :=
liftq _ f $ map_le_iff_le_comap.1 $ h.infi_pow_smul ▸ le_infi (λ n,
le_trans (map_mono $ infi_le _ n) $ by { rw map_smul'', exact smul_mono (le_refl _) le_top })
theorem lift_of (f : M →ₗ[R] N) (x : M) : lift I f (of I M x) = f x := rfl
theorem lift_comp_of (f : M →ₗ[R] N) : (lift I f).comp (of I M) = f :=
linear_map.ext $ λ _, rfl
/-- Uniqueness of lift. -/
theorem lift_eq (f : M →ₗ[R] N) (g : Hausdorffification I M →ₗ[R] N) (hg : g.comp (of I M) = f) :
g = lift I f :=
linear_map.ext $ λ x, induction_on x $ λ x, by rw [lift_of, ← hg, linear_map.comp_apply]
end Hausdorffification
namespace is_precomplete
instance bot : is_precomplete (⊥ : ideal R) M :=
begin
refine ⟨λ f hf, ⟨f 1, λ n, _⟩⟩, cases n,
{ rw [pow_zero, ideal.one_eq_top, top_smul], exact smodeq.top },
specialize hf (nat.le_add_left 1 n),
rw [pow_one, bot_smul, smodeq.bot] at hf, rw hf
end
instance top : is_precomplete (⊤ : ideal R) M :=
⟨λ f hf, ⟨0, λ n, by { rw [ideal.top_pow, top_smul], exact smodeq.top }⟩⟩
@[priority 100] instance of_subsingleton [subsingleton M] : is_precomplete I M :=
⟨λ f hf, ⟨0, λ n, by rw subsingleton.elim (f n) 0⟩⟩
end is_precomplete
namespace adic_completion
/-- The canonical linear map to the completion. -/
def of : M →ₗ[R] adic_completion I M :=
{ to_fun := λ x, ⟨λ n, mkq _ x, λ m n hmn, rfl⟩,
map_add' := λ x y, rfl,
map_smul' := λ c x, rfl }
@[simp] lemma of_apply (x : M) (n : ℕ) : (of I M x).1 n = mkq _ x := rfl
/-- Linearly evaluating a sequence in the completion at a given input. -/
def eval (n : ℕ) : adic_completion I M →ₗ[R] (I ^ n • ⊤ : submodule R M).quotient :=
{ to_fun := λ f, f.1 n,
map_add' := λ f g, rfl,
map_smul' := λ c f, rfl }
@[simp] lemma coe_eval (n : ℕ) :
(eval I M n : adic_completion I M → (I ^ n • ⊤ : submodule R M).quotient) = λ f, f.1 n := rfl
lemma eval_apply (n : ℕ) (f : adic_completion I M) : eval I M n f = f.1 n := rfl
lemma eval_of (n : ℕ) (x : M) : eval I M n (of I M x) = mkq _ x := rfl
@[simp] lemma eval_comp_of (n : ℕ) : (eval I M n).comp (of I M) = mkq _ := rfl
@[simp] lemma range_eval (n : ℕ) : (eval I M n).range = ⊤ :=
linear_map.range_eq_top.2 $ λ x, quotient.induction_on' x $ λ x, ⟨of I M x, rfl⟩
variables {I M}
@[ext] lemma ext {x y : adic_completion I M} (h : ∀ n, eval I M n x = eval I M n y) : x = y :=
subtype.eq $ funext h
variables (I M)
instance : is_Hausdorff I (adic_completion I M) :=
⟨λ x hx, ext $ λ n, smul_induction_on (smodeq.zero.1 $ hx n)
(λ r hr x _, ((eval I M n).map_smul r x).symm ▸ quotient.induction_on' (eval I M n x)
(λ x, smodeq.zero.2 $ smul_mem_smul hr mem_top))
rfl
(λ _ _ ih1 ih2, by rw [linear_map.map_add, ih1, ih2, linear_map.map_zero, add_zero])
(λ c _ ih, by rw [linear_map.map_smul, ih, linear_map.map_zero, smul_zero])⟩
end adic_completion
namespace is_adic_complete
instance bot : is_adic_complete (⊥ : ideal R) M := {}
protected theorem subsingleton (h : is_adic_complete (⊤ : ideal R) M) : subsingleton M :=
h.1.subsingleton
@[priority 100] instance of_subsingleton [subsingleton M] : is_adic_complete I M := {}
open_locale big_operators
lemma le_jacobson_bot [is_adic_complete I R] : I ≤ (⊥ : ideal R).jacobson :=
begin
intros x hx,
rw [← ideal.neg_mem_iff, ideal.mem_jacobson_bot],
intros y,
rw add_comm,
let f : ℕ → R := geom_sum (x * y),
have hf : ∀ m n, m ≤ n → f m ≡ f n [SMOD I ^ m • (⊤ : submodule R R)],
{ intros m n h,
simp only [f, geom_sum_def, algebra.id.smul_eq_mul, ideal.mul_top, smodeq.sub_mem],
rw [← nat.add_sub_cancel' h, finset.sum_range_add, ← sub_sub, sub_self, zero_sub, neg_mem_iff],
apply submodule.sum_mem,
intros n hn,
rw [mul_pow, pow_add, mul_assoc],
exact ideal.mul_mem_right _ (I ^ m) (ideal.pow_mem_pow hx m) },
obtain ⟨L, hL⟩ := is_precomplete.prec to_is_precomplete hf,
{ rw is_unit_iff_exists_inv,
use L,
rw [← sub_eq_zero, neg_mul_eq_neg_mul_symm],
apply is_Hausdorff.haus (to_is_Hausdorff : is_Hausdorff I R),
intros n,
specialize hL n,
rw [smodeq.sub_mem, algebra.id.smul_eq_mul, ideal.mul_top] at ⊢ hL,
rw sub_zero,
suffices : (1 - x * y) * (f n) - 1 ∈ I ^ n,
{ convert (ideal.sub_mem _ this (ideal.mul_mem_left _ (1 + - (x * y)) hL)) using 1,
ring },
cases n,
{ simp only [ideal.one_eq_top, pow_zero] },
{ dsimp [f],
rw [← neg_sub _ (1:R), neg_mul_eq_neg_mul_symm, mul_geom_sum, neg_sub,
sub_sub, add_comm, ← sub_sub, sub_self, zero_sub, neg_mem_iff, mul_pow],
exact ideal.mul_mem_right _ (I ^ _) (ideal.pow_mem_pow hx _), } },
end
end is_adic_complete
|
e861317a28605bee06443f1081047b624b69cc9d | 8cb37a089cdb4af3af9d8bf1002b417e407a8e9e | /library/system/random.lean | c6e2193bdae570278ef68645846f8e2f18c806e0 | [
"Apache-2.0"
] | permissive | kbuzzard/lean | ae3c3db4bb462d750dbf7419b28bafb3ec983ef7 | ed1788fd674bb8991acffc8fca585ec746711928 | refs/heads/master | 1,620,983,366,617 | 1,618,937,600,000 | 1,618,937,600,000 | 359,886,396 | 1 | 0 | Apache-2.0 | 1,618,936,987,000 | 1,618,936,987,000 | null | UTF-8 | Lean | false | false | 4,113 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
universes u
/-
Basic random number generator support based on the one
available on the Haskell library
-/
/- Interface for random number generators. -/
class random_gen (g : Type u) :=
/- `range` returns the range of values returned by
the generator. -/
(range : g → nat × nat)
/- `next` operation returns a natural number that is uniformly distributed
the range returned by `range` (including both end points),
and a new generator. -/
(next : g → nat × g)
/-
The 'split' operation allows one to obtain two distinct random number
generators. This is very useful in functional programs (for example, when
passing a random number generator down to recursive calls). -/
(split : g → g × g)
/- "Standard" random number generator. -/
structure std_gen :=
(s1 : nat) (s2 : nat)
def std_range := (1, 2147483562)
instance : has_repr std_gen :=
{ repr := λ ⟨s1, s2⟩, "⟨" ++ to_string s1 ++ ", " ++ to_string s2 ++ "⟩" }
def std_next : std_gen → nat × std_gen
| ⟨s1, s2⟩ :=
let k : int := s1 / 53668,
s1' : int := 40014 * ((s1 : int) - k * 53668) - k * 12211,
s1'' : int := if s1' < 0 then s1' + 2147483563 else s1',
k' : int := s2 / 52774,
s2' : int := 40692 * ((s2 : int) - k' * 52774) - k' * 3791,
s2'' : int := if s2' < 0 then s2' + 2147483399 else s2',
z : int := s1'' - s2'',
z' : int := if z < 1 then z + 2147483562 else z % 2147483562
in (z'.to_nat, ⟨s1''.to_nat, s2''.to_nat⟩)
def std_split : std_gen → std_gen × std_gen
| g@⟨s1, s2⟩ :=
let new_s1 := if s1 = 2147483562 then 1 else s1 + 1,
new_s2 := if s2 = 1 then 2147483398 else s2 - 1,
new_g := (std_next g).2,
left_g := std_gen.mk new_s1 new_g.2,
right_g := std_gen.mk new_g.1 new_s2
in (left_g, right_g)
instance : random_gen std_gen :=
{range := λ _, std_range,
next := std_next,
split := std_split}
/-- Return a standard number generator. -/
def mk_std_gen (s : nat := 0) : std_gen :=
let q := s / 2147483562,
s1 := s % 2147483562,
s2 := q % 2147483398 in
⟨s1 + 1, s2 + 1⟩
/-
Auxiliary function for random_nat_val.
Generate random values until we exceed the target magnitude.
`gen_lo` and `gen_mag` are the generator lower bound and magnitude.
The parameter `r` is the "remaining" magnitude.
-/
private def rand_nat_aux {gen : Type u} [random_gen gen] (gen_lo gen_mag : nat) (h : gen_mag > 0) : nat → nat → gen → nat × gen
| 0 v g := (v, g)
| r'@(r+1) v g :=
let (x, g') := random_gen.next g,
v' := v*gen_mag + (x - gen_lo)
in have r' / gen_mag - 1 < r',
begin
by_cases h : (r + 1) / gen_mag = 0,
{ rw [h], simp, apply nat.zero_lt_succ },
{ have : (r + 1) / gen_mag > 0, from nat.pos_of_ne_zero h,
have h₁ : (r + 1) / gen_mag - 1 < (r + 1) / gen_mag, { apply nat.sub_lt, assumption, tactic.comp_val },
have h₂ : (r + 1) / gen_mag ≤ r + 1, { apply nat.div_le_self },
exact lt_of_lt_of_le h₁ h₂ }
end,
rand_nat_aux (r' / gen_mag - 1) v' g'
/-- Generate a random natural number in the interval [lo, hi]. -/
def rand_nat {gen : Type u} [random_gen gen] (g : gen) (lo hi : nat) : nat × gen :=
let lo' := if lo > hi then hi else lo,
hi' := if lo > hi then lo else hi,
(gen_lo, gen_hi) := random_gen.range g,
gen_mag := gen_hi - gen_lo + 1,
/-
Probabilities of the most likely and least likely result
will differ at most by a factor of (1 +- 1/q). Assuming the RandomGen
is uniform, of course
-/
q := 1000,
k := hi' - lo' + 1,
tgt_mag := k * q,
(v, g') := rand_nat_aux gen_lo gen_mag (nat.zero_lt_succ _) tgt_mag 0 g,
v' := lo' + (v % k)
in (v', g')
/-- Generate a random Boolean. -/
def rand_bool {gen : Type u} [random_gen gen] (g : gen) : bool × gen :=
let (v, g') := rand_nat g 0 1
in (v = 1, g')
|
bc743287150846532bd625663b07e4b533b2ba63 | 33340b3a23ca62ef3c8a7f6a2d4e14c07c6d3354 | /dlo/qfree.lean | bdd452ffe8c7a6d604119944791f04f28e76bf4a | [] | no_license | lclem/cooper | 79554e72ced343c64fed24b2d892d24bf9447dfe | 812afc6b158821f2e7dac9c91d3b6123c7a19faf | refs/heads/master | 1,607,554,257,488 | 1,578,694,133,000 | 1,578,694,133,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,299 | lean | import .formula
def qfree : formula_dlo → Prop
| formula_dlo.true := true
| formula_dlo.false := true
| (formula_dlo.atom _) := true
| (formula_dlo.not p) := qfree p
| (formula_dlo.or p q) := qfree p /\ qfree q
| (formula_dlo.and p q) := qfree p /\ qfree q
| (formula_dlo.ex p) := false
def nqfree : formula_dlo → Prop
| ⊤' := true
| ⊥' := true
| A' a := true
| (¬' p) := false
| (p ∨' q) := nqfree p ∧ nqfree q
| (p ∧' q) := nqfree p ∧ nqfree q
| (∃' p) := false
lemma qfree_not_o {p : formula_dlo} : qfree p → qfree (not_o p) :=
begin intro h, cases p; try {trivial <|> assumption} end
lemma qfree_and_o {p q : formula_dlo} : qfree p → qfree q → qfree (and_o p q) :=
begin
intros hp hq, apply cases_and_o;
try { trivial <|> assumption }, apply and.intro hp hq
end
lemma qfree_or_o {p q : formula_dlo} : qfree p → qfree q → qfree (or_o p q) :=
begin
intros hp hq, apply cases_or_o;
try { trivial <|> assumption }, apply and.intro hp hq
end
lemma qfree_disj :
∀ {ps : list (formula_dlo)}, (∀ p ∈ ps, qfree p) → qfree (disj ps)
| [] _ := trivial
| (p::ps) h :=
have hp : qfree p := h _ (or.inl rfl),
have hps : qfree (disj ps) :=
qfree_disj (list.forall_mem_of_forall_mem_cons h),
begin
simp [disj], apply cases_or_o;
try {simp [qfree], constructor};
{trivial <|> assumption}
end
lemma qfree_conj :
∀ {ps : list (formula_dlo)}, (∀ p ∈ ps, qfree p) → qfree (conj ps)
| [] _ := trivial
| (p::ps) h :=
have hp : qfree p := h _ (or.inl rfl),
have hps : qfree (conj ps) :=
qfree_conj (list.forall_mem_of_forall_mem_cons h),
begin
simp [conj], apply cases_and_o;
try {simp [qfree], constructor};
try {trivial <|> assumption},
end
lemma qfree_conj_atom :
∀ {as : list atom_dlo}, qfree (conj_atom as)
| [] := trivial
| (a::as) := qfree_and_o trivial qfree_conj_atom
lemma qfree_of_nqfree : ∀ {p : formula_dlo}, nqfree p → qfree p
| ⊤' h := trivial
| ⊥' h := trivial
| (A' a) h := trivial
| (¬' p) h := by cases h
| (p ∨' q) h :=
begin
cases h with hp hq, apply and.intro;
apply qfree_of_nqfree; assumption
end
| (p ∧' q) h :=
begin
cases h with hp hq, apply and.intro;
apply qfree_of_nqfree; assumption
end
| (∃' p) h := by cases h
|
fc6055e3d6d74f033bf503a8b3b07fba3029b2fa | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/doc_string1.lean | 24f8d1efa197b26351f8d832f9d415222dc9d802 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 704 | lean | /--
Documentation for x
```
#reduce x + x
```
Testing...
-/
def x := 10 + 20
def y := "alo"
open tactic
run_cmd do
d ← doc_string `x,
trace d
run_cmd add_doc_string `y "testing simple doc"
run_cmd do
d ← doc_string `y,
trace d
namespace foo
namespace bla
/--
Documentation for single
testing...
hello
world
-/
inductive single
| unit
end bla
end foo
run_cmd do
trace "--------",
doc_string `foo.bla.single >>= trace
/-- Documentation for constant A
foo -/
constant A : Type
run_cmd doc_string `A >>= trace
/--Documentation for point
test
-/
structure point :=
(x : nat) (y : nat)
run_cmd doc_string `point >>= trace
#print "----------"
|
0d39629a879d8a726d3cb10e24e75b22e9d1e0da | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/polynomial/monic.lean | e04a1006eb560f5b4c6eff812d32bcef79ab899c | [
"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 | 17,814 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.reverse
import algebra.regular.smul
/-!
# Theory of monic polynomials
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We give several tools for proving that polynomials are monic, e.g.
`monic.mul`, `monic.map`, `monic.pow`.
-/
noncomputable theory
open finset
open_locale big_operators classical polynomial
namespace polynomial
universes u v y
variables {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section semiring
variables [semiring R] {p q r : R[X]}
lemma monic_zero_iff_subsingleton : monic (0 : R[X]) ↔ subsingleton R :=
subsingleton_iff_zero_eq_one
lemma not_monic_zero_iff : ¬ monic (0 : R[X]) ↔ (0 : R) ≠ 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
lemma monic_zero_iff_subsingleton' :
monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ (∀ a b : R, a = b) :=
polynomial.monic_zero_iff_subsingleton.trans ⟨by { introI, simp },
λ h, subsingleton_iff.mpr h.2⟩
lemma monic.as_sum (hp : p.monic) :
p = X^(p.nat_degree) + (∑ i in range p.nat_degree, C (p.coeff i) * X^i) :=
begin
conv_lhs { rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] },
suffices : C (p.coeff p.nat_degree) = 1,
{ rw [this, one_mul] },
exact congr_arg C hp
end
lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0 :=
begin
rintro rfl,
rw [monic.def, leading_coeff_zero] at hq,
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp,
exact hp rfl
end
lemma monic.map [semiring S] (f : R →+* S) (hp : monic p) : monic (p.map f) :=
begin
nontriviality,
have : f (leading_coeff p) ≠ 0,
{ rw [show _ = _, from hp, f.map_one],
exact one_ne_zero, },
rw [monic, leading_coeff, coeff_map],
suffices : p.coeff (map f p).nat_degree = 1,
{ simp [this], },
rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f this),
end
lemma monic_C_mul_of_mul_leading_coeff_eq_one {b : R} (hp : b * p.leading_coeff = 1) :
monic (C b * p) :=
by { nontriviality, rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp] }
lemma monic_mul_C_of_leading_coeff_mul_eq_one {b : R} (hp : p.leading_coeff * b = 1) :
monic (p * C b) :=
by { nontriviality, rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp] }
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : monic p :=
decidable.by_cases
(assume H : degree p < n, eq_of_zero_eq_one
(H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
(assume H : ¬degree p < n,
by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])
theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) + p) :=
have H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),
monic_of_degree_le (n+1)
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])
theorem monic_X_add_C (x : R) : monic (X + C x) :=
pow_one (X : R[X]) ▸ monic_X_pow_add degree_C_le
lemma monic.mul (hp : monic p) (hq : monic q) : monic (p * q) :=
if h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;
exact subsingleton.elim _ _
else
have leading_coeff p * leading_coeff q ≠ 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],
by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]
lemma monic.pow (hp : monic p) : ∀ (n : ℕ), monic (p ^ n)
| 0 := monic_one
| (n+1) := by { rw pow_succ, exact hp.mul (monic.pow n) }
lemma monic.add_of_left (hp : monic p) (hpq : degree q < degree p) :
monic (p + q) :=
by rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]
lemma monic.add_of_right (hq : monic q) (hpq : degree p < degree q) :
monic (p + q) :=
by rwa [monic, leading_coeff_add_of_degree_lt hpq]
lemma monic.of_mul_monic_left (hp : p.monic) (hpq : (p * q).monic) : q.monic :=
begin
contrapose! hpq,
rw monic.def at hpq ⊢,
rwa leading_coeff_monic_mul hp,
end
lemma monic.of_mul_monic_right (hq : q.monic) (hpq : (p * q).monic) : p.monic :=
begin
contrapose! hpq,
rw monic.def at hpq ⊢,
rwa leading_coeff_mul_monic hq,
end
namespace monic
@[simp]
lemma nat_degree_eq_zero_iff_eq_one (hp : p.monic) :
p.nat_degree = 0 ↔ p = 1 :=
begin
split; intro h,
swap, { rw h, exact nat_degree_one },
have : p = C (p.coeff 0),
{ rw ← polynomial.degree_le_zero_iff,
rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },
rw this, convert C_1, rw ← h, apply hp,
end
@[simp]
lemma degree_le_zero_iff_eq_one (hp : p.monic) :
p.degree ≤ 0 ↔ p = 1 :=
by rw [←hp.nat_degree_eq_zero_iff_eq_one, nat_degree_eq_zero_iff_degree_le_zero]
lemma nat_degree_mul (hp : p.monic) (hq : q.monic) :
(p * q).nat_degree = p.nat_degree + q.nat_degree :=
begin
nontriviality R,
apply nat_degree_mul',
simp [hp.leading_coeff, hq.leading_coeff]
end
lemma degree_mul_comm (hp : p.monic) (q : R[X]) :
(p * q).degree = (q * p).degree :=
begin
by_cases h : q = 0,
{ simp [h] },
rw [degree_mul', hp.degree_mul],
{ exact add_comm _ _ },
{ rwa [hp.leading_coeff, one_mul, leading_coeff_ne_zero] }
end
lemma nat_degree_mul' (hp : p.monic) (hq : q ≠ 0) :
(p * q).nat_degree = p.nat_degree + q.nat_degree :=
begin
rw [nat_degree_mul', add_comm],
simpa [hp.leading_coeff, leading_coeff_ne_zero]
end
lemma nat_degree_mul_comm (hp : p.monic) (q : R[X]) :
(p * q).nat_degree = (q * p).nat_degree :=
begin
by_cases h : q = 0,
{ simp [h] },
rw [hp.nat_degree_mul' h, polynomial.nat_degree_mul', add_comm],
simpa [hp.leading_coeff, leading_coeff_ne_zero]
end
lemma not_dvd_of_nat_degree_lt (hp : monic p)
(h0 : q ≠ 0) (hl : nat_degree q < nat_degree p) : ¬ p ∣ q :=
begin
rintro ⟨r, rfl⟩,
rw [hp.nat_degree_mul' $ right_ne_zero_of_mul h0] at hl,
exact hl.not_le (nat.le_add_right _ _)
end
lemma not_dvd_of_degree_lt (hp : monic p)
(h0 : q ≠ 0) (hl : degree q < degree p) : ¬ p ∣ q :=
monic.not_dvd_of_nat_degree_lt hp h0 $ nat_degree_lt_nat_degree h0 hl
lemma next_coeff_mul (hp : monic p) (hq : monic q) :
next_coeff (p * q) = next_coeff p + next_coeff q :=
begin
nontriviality,
simp only [← coeff_one_reverse],
rw reverse_mul;
simp [coeff_mul, nat.antidiagonal, hp.leading_coeff, hq.leading_coeff, add_comm]
end
lemma eq_one_of_map_eq_one {S : Type*} [semiring S] [nontrivial S]
(f : R →+* S) (hp : p.monic) (map_eq : p.map f = 1) : p = 1 :=
begin
nontriviality R,
have hdeg : p.degree = 0,
{ rw [← degree_map_eq_of_leading_coeff_ne_zero f _, map_eq, degree_one],
{ rw [hp.leading_coeff, f.map_one],
exact one_ne_zero } },
have hndeg : p.nat_degree = 0 :=
with_bot.coe_eq_coe.mp ((degree_eq_nat_degree hp.ne_zero).symm.trans hdeg),
convert eq_C_of_degree_eq_zero hdeg,
rw [← hndeg, ← polynomial.leading_coeff, hp.leading_coeff, C.map_one]
end
lemma nat_degree_pow (hp : p.monic) (n : ℕ) :
(p ^ n).nat_degree = n * p.nat_degree :=
begin
induction n with n hn,
{ simp },
{ rw [pow_succ, hp.nat_degree_mul (hp.pow n), hn],
ring }
end
end monic
@[simp] lemma nat_degree_pow_X_add_C [nontrivial R] (n : ℕ) (r : R) :
((X + C r) ^ n).nat_degree = n :=
by rw [(monic_X_add_C r).nat_degree_pow, nat_degree_X_add_C, mul_one]
lemma monic.eq_one_of_is_unit (hm : monic p) (hpu : is_unit p) : p = 1 :=
begin
nontriviality R,
obtain ⟨q, h⟩ := hpu.exists_right_inv,
have := hm.nat_degree_mul' (right_ne_zero_of_mul_eq_one h),
rw [h, nat_degree_one, eq_comm, add_eq_zero_iff] at this,
exact hm.nat_degree_eq_zero_iff_eq_one.mp this.1,
end
lemma monic.is_unit_iff (hm : p.monic) : is_unit p ↔ p = 1 :=
⟨hm.eq_one_of_is_unit, λ h, h.symm ▸ is_unit_one⟩
end semiring
section comm_semiring
variables [comm_semiring R] {p : R[X]}
lemma monic_multiset_prod_of_monic (t : multiset ι) (f : ι → R[X])
(ht : ∀ i ∈ t, monic (f i)) :
monic (t.map f).prod :=
begin
revert ht,
refine t.induction_on _ _, { simp },
intros a t ih ht,
rw [multiset.map_cons, multiset.prod_cons],
exact (ht _ (multiset.mem_cons_self _ _)).mul (ih (λ _ hi, ht _ (multiset.mem_cons_of_mem hi)))
end
lemma monic_prod_of_monic (s : finset ι) (f : ι → R[X]) (hs : ∀ i ∈ s, monic (f i)) :
monic (∏ i in s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
lemma monic.next_coeff_multiset_prod (t : multiset ι) (f : ι → R[X])
(h : ∀ i ∈ t, monic (f i)) :
next_coeff (t.map f).prod = (t.map (λ i, next_coeff (f i))).sum :=
begin
revert h,
refine multiset.induction_on t _ (λ a t ih ht, _),
{ simp only [multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, multiset.map_zero,
multiset.prod_zero, multiset.sum_zero, not_false_iff, forall_true_iff],
rw ← C_1, rw next_coeff_C_eq_zero },
{ rw [multiset.map_cons, multiset.prod_cons, multiset.map_cons, multiset.sum_cons,
monic.next_coeff_mul, ih],
exacts [λ i hi, ht i (multiset.mem_cons_of_mem hi), ht a (multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ (λ b bs, ht _ (multiset.mem_cons_of_mem bs))] }
end
lemma monic.next_coeff_prod (s : finset ι) (f : ι → R[X]) (h : ∀ i ∈ s, monic (f i)) :
next_coeff (∏ i in s, f i) = ∑ i in s, next_coeff (f i) :=
monic.next_coeff_multiset_prod s.1 f h
end comm_semiring
section semiring
variables [semiring R]
@[simp]
lemma monic.nat_degree_map [semiring S] [nontrivial S] {P : R[X]} (hmo : P.monic)
(f : R →+* S) : (P.map f).nat_degree = P.nat_degree :=
begin
refine le_antisymm (nat_degree_map_le _ _) (le_nat_degree_of_ne_zero _),
rw [coeff_map, monic.coeff_nat_degree hmo, ring_hom.map_one],
exact one_ne_zero
end
@[simp]
lemma monic.degree_map [semiring S] [nontrivial S] {P : R[X]} (hmo : P.monic)
(f : R →+* S) : (P.map f).degree = P.degree :=
begin
by_cases hP : P = 0,
{ simp [hP] },
{ refine le_antisymm (degree_map_le _ _) _,
rw [degree_eq_nat_degree hP],
refine le_degree_of_ne_zero _,
rw [coeff_map, monic.coeff_nat_degree hmo, ring_hom.map_one],
exact one_ne_zero }
end
section injective
open function
variables [semiring S] {f : R →+* S} (hf : injective f)
include hf
lemma degree_map_eq_of_injective (p : R[X]) : degree (p.map f) = degree p :=
if h : p = 0 then by simp [h]
else degree_map_eq_of_leading_coeff_ne_zero _
(by rw [← f.map_zero]; exact mt hf.eq_iff.1
(mt leading_coeff_eq_zero.1 h))
lemma nat_degree_map_eq_of_injective (p : R[X]) :
nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map_eq_of_injective hf p)
lemma leading_coeff_map' (p : R[X]) :
leading_coeff (p.map f) = f (leading_coeff p) :=
begin
unfold leading_coeff,
rw [coeff_map, nat_degree_map_eq_of_injective hf p],
end
lemma next_coeff_map (p : R[X]) :
(p.map f).next_coeff = f p.next_coeff :=
begin
unfold next_coeff,
rw nat_degree_map_eq_of_injective hf,
split_ifs; simp
end
lemma leading_coeff_of_injective (p : R[X]) :
leading_coeff (p.map f) = f (leading_coeff p) :=
begin
delta leading_coeff,
rw [coeff_map f, nat_degree_map_eq_of_injective hf p]
end
lemma monic_of_injective {p : R[X]} (hp : (p.map f).monic) : p.monic :=
begin
apply hf,
rw [← leading_coeff_of_injective hf, hp.leading_coeff, f.map_one]
end
theorem _root_.function.injective.monic_map_iff {p : R[X]} : p.monic ↔ (p.map f).monic :=
⟨monic.map _, polynomial.monic_of_injective hf⟩
end injective
end semiring
section ring
variables [ring R] {p : R[X]}
theorem monic_X_sub_C (x : R) : monic (X - C x) :=
by simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) :=
by simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) ≤ n, by rwa ←degree_neg p at H)
/-- `X ^ n - a` is monic. -/
lemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : ℕ} (h : n ≠ 0) : (X ^ n - C a).monic :=
begin
obtain ⟨k, hk⟩ := nat.exists_eq_succ_of_ne_zero h,
convert monic_X_pow_sub _,
exact le_trans degree_C_le nat.with_bot.coe_nonneg,
end
lemma not_is_unit_X_pow_sub_one (R : Type*) [comm_ring R] [nontrivial R] (n : ℕ) :
¬ is_unit (X ^ n - 1 : R[X]) :=
begin
intro h,
rcases eq_or_ne n 0 with rfl | hn,
{ simpa using h },
apply hn,
rw [←@nat_degree_one R, ←(monic_X_pow_sub_C _ hn).eq_one_of_is_unit h, nat_degree_X_pow_sub_C],
end
lemma monic.sub_of_left {p q : R[X]} (hp : monic p) (hpq : degree q < degree p) :
monic (p - q) :=
by { rw sub_eq_add_neg, apply hp.add_of_left, rwa degree_neg }
lemma monic.sub_of_right {p q : R[X]}
(hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=
have (-q).coeff (-q).nat_degree = 1 :=
by rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],
by { rw sub_eq_add_neg, apply monic.add_of_right this, rwa degree_neg }
end ring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : R[X]}
@[simp] lemma not_monic_zero : ¬monic (0 : R[X]) :=
not_monic_zero_iff.mp zero_ne_one
end nonzero_semiring
section not_zero_divisor
-- TODO: using gh-8537, rephrase lemmas that involve commutation around `*` using the op-ring
variables [semiring R] {p : R[X]}
lemma monic.mul_left_ne_zero (hp : monic p) {q : R[X]} (hq : q ≠ 0) :
q * p ≠ 0 :=
begin
by_cases h : p = 1,
{ simpa [h] },
rw [ne.def, ←degree_eq_bot, hp.degree_mul, with_bot.add_eq_bot, not_or_distrib, degree_eq_bot],
refine ⟨hq, _⟩,
rw [←hp.degree_le_zero_iff_eq_one, not_le] at h,
refine (lt_trans _ h).ne',
simp
end
lemma monic.mul_right_ne_zero (hp : monic p) {q : R[X]} (hq : q ≠ 0) :
p * q ≠ 0 :=
begin
by_cases h : p = 1,
{ simpa [h] },
rw [ne.def, ←degree_eq_bot, hp.degree_mul_comm, hp.degree_mul, with_bot.add_eq_bot,
not_or_distrib, degree_eq_bot],
refine ⟨hq, _⟩,
rw [←hp.degree_le_zero_iff_eq_one, not_le] at h,
refine (lt_trans _ h).ne',
simp
end
lemma monic.mul_nat_degree_lt_iff (h : monic p) {q : R[X]} :
(p * q).nat_degree < p.nat_degree ↔ p ≠ 1 ∧ q = 0 :=
begin
by_cases hq : q = 0,
{ suffices : 0 < p.nat_degree ↔ p.nat_degree ≠ 0,
{ simpa [hq, ←h.nat_degree_eq_zero_iff_eq_one] },
exact ⟨λ h, h.ne', λ h, lt_of_le_of_ne (nat.zero_le _) h.symm ⟩ },
{ simp [h.nat_degree_mul', hq] }
end
lemma monic.mul_right_eq_zero_iff (h : monic p) {q : R[X]} :
p * q = 0 ↔ q = 0 :=
begin
by_cases hq : q = 0;
simp [h.mul_right_ne_zero, hq]
end
lemma monic.mul_left_eq_zero_iff (h : monic p) {q : R[X]} :
q * p = 0 ↔ q = 0 :=
begin
by_cases hq : q = 0;
simp [h.mul_left_ne_zero, hq]
end
lemma monic.is_regular {R : Type*} [ring R] {p : R[X]} (hp : monic p) : is_regular p :=
begin
split,
{ intros q r h,
rw [←sub_eq_zero, ←hp.mul_right_eq_zero_iff, mul_sub, h, sub_self] },
{ intros q r h,
simp only at h,
rw [←sub_eq_zero, ←hp.mul_left_eq_zero_iff, sub_mul, h, sub_self] }
end
lemma degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]
{k : S} (p : R[X]) (h : is_smul_regular R k) :
(k • p).degree = p.degree :=
begin
refine le_antisymm _ _,
{ rw degree_le_iff_coeff_zero,
intros m hm,
rw degree_lt_iff_coeff_zero at hm,
simp [hm m le_rfl] },
{ rw degree_le_iff_coeff_zero,
intros m hm,
rw degree_lt_iff_coeff_zero at hm,
refine h _,
simpa using hm m le_rfl },
end
lemma nat_degree_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]
{k : S} (p : R[X]) (h : is_smul_regular R k) :
(k • p).nat_degree = p.nat_degree :=
begin
by_cases hp : p = 0,
{ simp [hp] },
rw [←with_bot.coe_eq_coe, ←degree_eq_nat_degree hp, ←degree_eq_nat_degree,
degree_smul_of_smul_regular p h],
contrapose! hp,
rw ←smul_zero k at hp,
exact h.polynomial hp
end
lemma leading_coeff_smul_of_smul_regular {S : Type*} [monoid S] [distrib_mul_action S R]
{k : S} (p : R[X]) (h : is_smul_regular R k) :
(k • p).leading_coeff = k • p.leading_coeff :=
by rw [leading_coeff, leading_coeff, coeff_smul, nat_degree_smul_of_smul_regular p h]
lemma monic_of_is_unit_leading_coeff_inv_smul (h : is_unit p.leading_coeff) :
monic (h.unit⁻¹ • p) :=
begin
rw [monic.def, leading_coeff_smul_of_smul_regular _ (is_smul_regular_of_group _), units.smul_def],
obtain ⟨k, hk⟩ := h,
simp only [←hk, smul_eq_mul, ←units.coe_mul, units.coe_eq_one, inv_mul_eq_iff_eq_mul],
simp [units.ext_iff, is_unit.unit_spec]
end
lemma is_unit_leading_coeff_mul_right_eq_zero_iff (h : is_unit p.leading_coeff) {q : R[X]} :
p * q = 0 ↔ q = 0 :=
begin
split,
{ intro hp,
rw ←smul_eq_zero_iff_eq (h.unit)⁻¹ at hp,
have : (h.unit)⁻¹ • (p * q) = ((h.unit)⁻¹ • p) * q,
{ ext,
simp only [units.smul_def, coeff_smul, coeff_mul, smul_eq_mul, mul_sum],
refine sum_congr rfl (λ x hx, _),
rw ←mul_assoc },
rwa [this, monic.mul_right_eq_zero_iff] at hp,
exact monic_of_is_unit_leading_coeff_inv_smul _ },
{ rintro rfl,
simp }
end
lemma is_unit_leading_coeff_mul_left_eq_zero_iff (h : is_unit p.leading_coeff) {q : R[X]} :
q * p = 0 ↔ q = 0 :=
begin
split,
{ intro hp,
replace hp := congr_arg (* C ↑(h.unit)⁻¹) hp,
simp only [zero_mul] at hp,
rwa [mul_assoc, monic.mul_left_eq_zero_iff] at hp,
refine monic_mul_C_of_leading_coeff_mul_eq_one _,
simp [units.mul_inv_eq_iff_eq_mul, is_unit.unit_spec] },
{ rintro rfl,
rw zero_mul }
end
end not_zero_divisor
end polynomial
|
1884e34119f88d65d09c61a617fcbaedb3b4baeb | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/limits/fubini.lean | e682a6e290b10d06f08985ec155b36cda9349199 | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 8,146 | 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.limits.limits
import category_theory.products.basic
import category_theory.currying
/-!
# A Fubini theorem for categorical limits
We prove that $lim_{J × K} G = lim_J (lim_K G(j, -))$ for a functor `G : J × K ⥤ C`,
when all the appropriate limits exist.
We begin working with a functor `F : J ⥤ K ⥤ C`. We'll write `G : J × K ⥤ C` for the associated
"uncurried" functor.
In the first part, given a coherent family `D` of limit cones over the functors `F.obj j`,
and a cone `c` over `G`, we construct a cone over the cone points of `D`.
We then show that if `c` is a limit cone, the constructed cone is also a limit cone.
In the second part, we state the Fubini theorem in the setting where we have chosen limits
provided by suitable `has_limit` classes.
We construct
`limit_uncurry_iso_limit_comp_lim F : limit (uncurry.obj F) ≅ limit (F ⋙ lim)`
and give simp lemmas characterising it.
For convenience, we also provide
`limit_iso_limit_curry_comp_lim G : limit G ≅ limit ((curry.obj G) ⋙ lim)`
in terms of the uncurried functor.
-/
universes v u
open category_theory
namespace category_theory.limits
variables {J K : Type v} [small_category J] [small_category K]
variables {C : Type u} [category.{v} C]
variables (F : J ⥤ K ⥤ C)
/--
A structure carrying a diagram of cones over the the functors `F.obj j`.
-/
-- We could try introducing a "dependent functor type" to handle this?
structure diagram_of_cones :=
(obj : Π j : J, cone (F.obj j))
(map : Π {j j' : J} (f : j ⟶ j'), (cones.postcompose (F.map f)).obj (obj j) ⟶ obj j')
(id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ . obviously)
(comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃),
(map (f ≫ g)).hom = (map f).hom ≫ (map g).hom . obviously)
variables {F}
/--
Extract the functor `J ⥤ C` consisting of the cone points and the maps between them,
from a `diagram_of_cones`.
-/
@[simps]
def diagram_of_cones.cone_points (D : diagram_of_cones F) :
J ⥤ C :=
{ obj := λ j, (D.obj j).X,
map := λ j j' f, (D.map f).hom,
map_id' := λ j, D.id j,
map_comp' := λ j₁ j₂ j₃ f g, D.comp f g, }
/--
Given a diagram `D` of limit cones over the `F.obj j`, and a cone over `uncurry.obj F`,
we can construct a cone over the diagram consisting of the cone points from `D`.
-/
@[simps]
def cone_of_cone_uncurry
{D : diagram_of_cones F} (Q : Π j, is_limit (D.obj j))
(c : cone (uncurry.obj F)) :
cone (D.cone_points) :=
{ X := c.X,
π :=
{ app := λ j, (Q j).lift
{ X := c.X,
π :=
{ app := λ k, c.π.app (j, k),
naturality' := λ k k' f,
begin
dsimp, simp only [category.id_comp],
have := @nat_trans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f),
dsimp at this,
simp only [category.id_comp, category_theory.functor.map_id, nat_trans.id_app] at this,
exact this,
end } },
naturality' := λ j j' f, (Q j').hom_ext
begin
dsimp,
intro k,
simp only [limits.cone_morphism.w, limits.cones.postcompose_obj_π, limits.is_limit.fac_assoc,
limits.is_limit.fac, nat_trans.comp_app, category.id_comp, category.assoc],
have := @nat_trans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k),
dsimp at this,
simp only [category.id_comp, category.comp_id,
category_theory.functor.map_id, nat_trans.id_app] at this,
exact this,
end, } }.
/--
`cone_of_cone_uncurry Q c` is a limit cone when `c` is a limit cone.`
-/
def cone_of_cone_uncurry_is_limit
{D : diagram_of_cones F} (Q : Π j, is_limit (D.obj j))
{c : cone (uncurry.obj F)} (P : is_limit c) :
is_limit (cone_of_cone_uncurry Q c) :=
{ lift := λ s, P.lift
{ X := s.X,
π :=
{ app := λ p, s.π.app p.1 ≫ (D.obj p.1).π.app p.2,
naturality' := λ p p' f,
begin
dsimp, simp only [category.id_comp, category.assoc],
rcases p with ⟨j, k⟩,
rcases p' with ⟨j', k'⟩,
rcases f with ⟨fj, fk⟩,
dsimp,
slice_rhs 3 4 { rw ←nat_trans.naturality, },
slice_rhs 2 3 { rw ←(D.obj j).π.naturality, },
simp only [functor.const.obj_map, category.id_comp, category.assoc],
have w := (D.map fj).w k',
dsimp at w,
rw ←w,
have n := s.π.naturality fj,
dsimp at n,
simp only [category.id_comp] at n,
rw n,
simp,
end, } },
fac' := λ s j,
begin
apply (Q j).hom_ext,
intro k,
simp,
end,
uniq' := λ s m w,
begin
refine P.uniq { X := s.X, π := _, } m _,
rintro ⟨j, k⟩,
dsimp,
rw [←w j],
simp,
end, }
section
variables (F)
variables [has_limits_of_shape K C]
/--
Given a functor `F : J ⥤ K ⥤ C`, with all needed chosen limits,
we can construct a diagram consisting of the limit cone over each functor `F.obj j`,
and the universal cone morphisms between these.
-/
@[simps]
def diagram_of_cones.mk_of_has_limits : diagram_of_cones F :=
{ obj := λ j, limit.cone (F.obj j),
map := λ j j' f, { hom := lim.map (F.map f), }, }
-- Satisfying the inhabited linter.
instance diagram_of_cones_inhabited : inhabited (diagram_of_cones F) :=
⟨diagram_of_cones.mk_of_has_limits F⟩
@[simp]
lemma diagram_of_cones.mk_of_has_limits_cone_points :
(diagram_of_cones.mk_of_has_limits F).cone_points = (F ⋙ lim) :=
rfl
variables [has_limit (uncurry.obj F)]
variables [has_limit (F ⋙ lim)]
/--
The Fubini theorem for a functor `F : J ⥤ K ⥤ C`,
showing that the limit of `uncurry.obj F` can be computed as
the limit of the limits of the functors `F.obj j`.
-/
def limit_uncurry_iso_limit_comp_lim : limit (uncurry.obj F) ≅ limit (F ⋙ lim) :=
begin
let c := limit.cone (uncurry.obj F),
let P : is_limit c := limit.is_limit _,
let G := diagram_of_cones.mk_of_has_limits F,
let Q : Π j, is_limit (G.obj j) := λ j, limit.is_limit _,
have Q' := cone_of_cone_uncurry_is_limit Q P,
have Q'' := (limit.is_limit (F ⋙ lim)),
exact is_limit.cone_point_unique_up_to_iso Q' Q'',
end
@[simp]
lemma limit_uncurry_iso_limit_comp_lim_hom_π_π {j} {k} :
(limit_uncurry_iso_limit_comp_lim F).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) :=
begin
dsimp [limit_uncurry_iso_limit_comp_lim, is_limit.cone_point_unique_up_to_iso,
is_limit.unique_up_to_iso],
simp,
end
@[simp]
lemma limit_uncurry_iso_limit_comp_lim_inv_π {j} {k} :
(limit_uncurry_iso_limit_comp_lim F).inv ≫ limit.π _ (j, k) = limit.π _ j ≫ limit.π _ k :=
begin
rw [←cancel_epi (limit_uncurry_iso_limit_comp_lim F).hom],
simp,
end
end
section
variables (G : J × K ⥤ C)
variables [has_limits_of_shape K C]
variables [has_limit G]
variables [has_limit ((curry.obj G) ⋙ lim)]
/--
The Fubini theorem for a functor `G : J × K ⥤ C`,
showing that the limit of `G` can be computed as
the limit of the limits of the functors `G.obj (j, _)`.
-/
def limit_iso_limit_curry_comp_lim : limit G ≅ limit ((curry.obj G) ⋙ lim) :=
begin
have i : G ≅ uncurry.obj ((@curry J _ K _ C _).obj G) := currying.symm.unit_iso.app G,
haveI : limits.has_limit (uncurry.obj ((@curry J _ K _ C _).obj G)) :=
has_limit_of_iso i,
transitivity limit (uncurry.obj ((@curry J _ K _ C _).obj G)),
apply has_limit.iso_of_nat_iso i,
exact limit_uncurry_iso_limit_comp_lim ((@curry J _ K _ C _).obj G),
end
@[simp]
lemma limit_iso_limit_curry_comp_lim_hom_π_π {j} {k} :
(limit_iso_limit_curry_comp_lim G).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) :=
begin
dsimp [limit_iso_limit_curry_comp_lim, is_limit.cone_point_unique_up_to_iso,
is_limit.unique_up_to_iso],
simp, dsimp, simp, -- See note [dsimp, simp].
end
@[simp]
lemma limit_iso_limit_curry_comp_lim_inv_π {j} {k} :
(limit_iso_limit_curry_comp_lim G).inv ≫ limit.π _ (j, k) = limit.π _ j ≫ limit.π _ k :=
begin
rw [←cancel_epi (limit_iso_limit_curry_comp_lim G).hom],
simp,
end
end
end category_theory.limits
|
11e8f3d59b45426435d2c11b4eb69a56a400544d | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/sites/sheaf.lean | 3aa38dcce4c4b28f8ed11054d0679ec369ceca57 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 10,663 | lean | /-
Copyright (c) 2020 Kevin Buzzard, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Bhavik Mehta
-/
import category_theory.sites.sheaf_of_types
import category_theory.limits.yoneda
import category_theory.limits.preserves.shapes.equalizers
import category_theory.limits.preserves.shapes.products
import category_theory.concrete_category
/-!
# Sheaves taking values in a category
If C is a category with a Grothendieck topology, we define the notion of a sheaf taking values in
an arbitrary category `A`. We follow the definition in https://stacks.math.columbia.edu/tag/00VR,
noting that the presheaf of sets "defined above" can be seen in the comments between tags 00VQ and
00VR on the page https://stacks.math.columbia.edu/tag/00VL. The advantage of this definition is
that we need no assumptions whatsoever on `A` other than the assumption that the morphisms in `C`
and `A` live in the same universe.
* An `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is defined to be a sheaf (for the topology `J`) iff for
every `X : A`, the type-valued presheaves of sets given by sending `U : Cᵒᵖ` to `Hom_{A}(X, P U)`
are all sheaves of sets, see `category_theory.presheaf.is_sheaf`.
* When `A = Type`, this recovers the basic definition of sheaves of sets, see
`category_theory.is_sheaf_iff_is_sheaf_of_type`.
* An alternate definition when `C` is small, has pullbacks and `A` has products is given by an
equalizer condition `category_theory.presheaf.is_sheaf'`. This is equivalent to the earlier
definition, shown in `category_theory.presheaf.is_sheaf_iff_is_sheaf'`.
* When `A = Type`, this is *definitionally* equal to the equalizer condition for presieves in
`category_theory.sites.sheaf_of_types`.
* When `A` has limits and there is a functor `s : A ⥤ Type` which is faithful, reflects isomorphisms
and preserves limits, then `P : C^op ⥤ A` is a sheaf iff the underlying presheaf of types
`P ⋙ s : C^op ⥤ Type` is a sheaf (`category_theory.presheaf.is_sheaf_iff_is_sheaf_forget`).
Cf https://stacks.math.columbia.edu/tag/0073, which is a weaker version of this statement (it's
only over spaces, not sites) and https://stacks.math.columbia.edu/tag/00YR (a), which
additionally assumes filtered colimits.
-/
universes v v' u' u
noncomputable theory
namespace category_theory
open opposite category_theory category limits sieve classical
namespace presheaf
variables {C : Type u} [category.{v} C]
variables {A : Type u'} [category.{v} A]
variables (J : grothendieck_topology C)
-- We follow https://stacks.math.columbia.edu/tag/00VL definition 00VR
/--
A sheaf of A is a presheaf P : C^op => A such that for every X : A, the
presheaf of types given by sending U : C to Hom_{A}(X, P U) is a sheaf of types.
https://stacks.math.columbia.edu/tag/00VR
-/
def is_sheaf (P : Cᵒᵖ ⥤ A) : Prop :=
∀ X : A, presieve.is_sheaf J (P ⋙ coyoneda.obj (op X))
end presheaf
variables {C : Type u} [category.{v} C]
variables (J : grothendieck_topology C)
variables (A : Type u') [category.{v} A]
/-- The category of sheaves taking values in `A` on a grothendieck topology. -/
@[derive category]
def Sheaf : Type* :=
{P : Cᵒᵖ ⥤ A // presheaf.is_sheaf J P}
/-- The inclusion functor from sheaves to presheaves. -/
@[simps {rhs_md := semireducible}, derive [full, faithful]]
def Sheaf_to_presheaf : Sheaf J A ⥤ (Cᵒᵖ ⥤ A) :=
full_subcategory_inclusion (presheaf.is_sheaf J)
lemma is_sheaf_iff_is_sheaf_of_type (P : Cᵒᵖ ⥤ Type v) :
presheaf.is_sheaf J P ↔ presieve.is_sheaf J P :=
begin
split,
{ intros hP,
refine presieve.is_sheaf_iso J _ (hP punit),
exact iso_whisker_left _ coyoneda.punit_iso ≪≫ P.right_unitor },
{ intros hP X Y S hS z hz,
refine ⟨λ x, (hP S hS).amalgamate (λ Z f hf, z f hf x) _, _, _⟩,
{ intros Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ h,
exact congr_fun (hz g₁ g₂ hf₁ hf₂ h) x },
{ intros Z f hf,
ext x,
apply presieve.is_sheaf_for.valid_glue },
{ intros y hy,
ext x,
apply (hP S hS).is_separated_for.ext,
intros Y' f hf,
rw [presieve.is_sheaf_for.valid_glue _ _ _ hf, ← hy _ hf],
refl } }
end
/--
The category of sheaves taking values in Type is the same as the category of set-valued sheaves.
-/
@[simps]
def Sheaf_equiv_SheafOfTypes : Sheaf J (Type v) ≌ SheafOfTypes J :=
{ functor :=
{ obj := λ S, ⟨S.1, (is_sheaf_iff_is_sheaf_of_type _ _).1 S.2⟩,
map := λ S₁ S₂ f, f },
inverse :=
{ obj := λ S, ⟨S.1, (is_sheaf_iff_is_sheaf_of_type _ _).2 S.2⟩,
map := λ S₁ S₂ f, f },
unit_iso := nat_iso.of_components (λ X, ⟨𝟙 _, 𝟙 _, by tidy, by tidy⟩) (by tidy),
counit_iso := nat_iso.of_components (λ X, ⟨𝟙 _, 𝟙 _, by tidy, by tidy⟩) (by tidy) }
instance : inhabited (Sheaf (⊥ : grothendieck_topology C) (Type v)) :=
⟨(Sheaf_equiv_SheafOfTypes _).inverse.obj (default _)⟩
end category_theory
namespace category_theory
open opposite category_theory category limits sieve classical
namespace presheaf
-- Under here is the equalizer story, which is equivalent if A has products (and doesn't
-- make sense otherwise). It's described in https://stacks.math.columbia.edu/tag/00VL,
-- between 00VQ and 00VR.
variables {C : Type v} [small_category C]
variables {A : Type u} [category.{v} A]
variables (J : grothendieck_topology C)
variables {U : C} (R : presieve U)
variables (P : Cᵒᵖ ⥤ A)
section
variables [has_products A]
/--
The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram
of https://stacks.math.columbia.edu/tag/00VM.
-/
def first_obj : A :=
∏ (λ (f : Σ V, {f : V ⟶ U // R f}), P.obj (op f.1))
/--
The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram
of https://stacks.math.columbia.edu/tag/00VM.
-/
def fork_map : P.obj (op U) ⟶ first_obj R P :=
pi.lift (λ f, P.map f.2.1.op)
variables [has_pullbacks C]
/--
The rightmost object of the fork diagram of https://stacks.math.columbia.edu/tag/00VM, which
contains the data used to check a family of elements for a presieve is compatible.
-/
def second_obj : A :=
∏ (λ (fg : (Σ V, {f : V ⟶ U // R f}) × (Σ W, {g : W ⟶ U // R g})),
P.obj (op (pullback fg.1.2.1 fg.2.2.1)))
/-- The map `pr₀*` of https://stacks.math.columbia.edu/tag/00VM. -/
def first_map : first_obj R P ⟶ second_obj R P :=
pi.lift (λ fg, pi.π _ _ ≫ P.map pullback.fst.op)
/-- The map `pr₁*` of https://stacks.math.columbia.edu/tag/00VM. -/
def second_map : first_obj R P ⟶ second_obj R P :=
pi.lift (λ fg, pi.π _ _ ≫ P.map pullback.snd.op)
lemma w : fork_map R P ≫ first_map R P = fork_map R P ≫ second_map R P :=
begin
apply limit.hom_ext,
rintro ⟨⟨Y, f, hf⟩, ⟨Z, g, hg⟩⟩,
simp only [first_map, second_map, fork_map, limit.lift_π, limit.lift_π_assoc, assoc,
fan.mk_π_app, subtype.coe_mk, subtype.val_eq_coe],
rw [← P.map_comp, ← op_comp, pullback.condition],
simp,
end
/--
An alternative definition of the sheaf condition in terms of equalizers. This is shown to be
equivalent in `category_theory.presheaf.is_sheaf_iff_is_sheaf'`.
-/
def is_sheaf' (P : Cᵒᵖ ⥤ A) : Prop := ∀ (U : C) (R : presieve U) (hR : generate R ∈ J U),
nonempty (is_limit (fork.of_ι _ (w R P)))
/-- (Implementation). An auxiliary lemma to convert between sheaf conditions. -/
def is_sheaf_for_is_sheaf_for' (P : Cᵒᵖ ⥤ A) (s : A ⥤ Type v)
[Π J, preserves_limits_of_shape (discrete J) s] (U : C) (R : presieve U) :
is_limit (s.map_cone (fork.of_ι _ (w R P))) ≃
is_limit (fork.of_ι _ (equalizer.presieve.w (P ⋙ s) R)) :=
begin
apply equiv.trans (is_limit_map_cone_fork_equiv _ _) _,
apply (is_limit.postcompose_hom_equiv _ _).symm.trans (is_limit.equiv_iso_limit _),
{ apply nat_iso.of_components _ _,
{ rintro (_ | _),
{ apply preserves_product.iso s },
{ apply preserves_product.iso s } },
{ rintro _ _ (_ | _),
{ ext : 1,
dsimp [equalizer.presieve.first_map, first_map],
simp only [limit.lift_π, map_lift_pi_comparison, assoc, fan.mk_π_app, functor.map_comp],
erw pi_comparison_comp_π_assoc },
{ ext : 1,
dsimp [equalizer.presieve.second_map, second_map],
simp only [limit.lift_π, map_lift_pi_comparison, assoc, fan.mk_π_app, functor.map_comp],
erw pi_comparison_comp_π_assoc },
{ dsimp,
simp } } },
{ refine fork.ext (iso.refl _) _,
dsimp [equalizer.fork_map, fork_map],
simp }
end
/-- The equalizer definition of a sheaf given by `is_sheaf'` is equivalent to `is_sheaf`. -/
theorem is_sheaf_iff_is_sheaf' :
is_sheaf J P ↔ is_sheaf' J P :=
begin
split,
{ intros h U R hR,
refine ⟨_⟩,
apply coyoneda_jointly_reflects_limits,
intro X,
have q : presieve.is_sheaf_for (P ⋙ coyoneda.obj X) _ := h X.unop _ hR,
rw ←presieve.is_sheaf_for_iff_generate at q,
rw equalizer.presieve.sheaf_condition at q,
replace q := classical.choice q,
apply (is_sheaf_for_is_sheaf_for' _ _ _ _).symm q },
{ intros h U X S hS,
rw equalizer.presieve.sheaf_condition,
refine ⟨_⟩,
refine is_sheaf_for_is_sheaf_for' _ _ _ _ _,
apply is_limit_of_preserves,
apply classical.choice (h _ S _),
simpa }
end
end
section concrete
variables [has_pullbacks C]
/--
For a concrete category `(A, s)` where the forgetful functor `s : A ⥤ Type v` preserves limits and
reflects isomorphisms, and `A` has limits, an `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is a sheaf iff its
underlying `Type`-valued presheaf `P ⋙ s : Cᵒᵖ ⥤ Type` is a sheaf.
Note this lemma applies for "algebraic" categories, eg groups, abelian groups and rings, but not
for the category of topological spaces, topological rings, etc since reflecting isomorphisms doesn't
hold.
-/
lemma is_sheaf_iff_is_sheaf_forget (s : A ⥤ Type v)
[has_limits A] [preserves_limits s] [reflects_isomorphisms s] :
is_sheaf J P ↔ is_sheaf J (P ⋙ s) :=
begin
rw [is_sheaf_iff_is_sheaf', is_sheaf_iff_is_sheaf'],
apply forall_congr (λ U, _),
apply ball_congr (λ R hR, _),
letI : reflects_limits s := reflects_limits_of_reflects_isomorphisms,
have : is_limit (s.map_cone (fork.of_ι _ (w R P))) ≃ is_limit (fork.of_ι _ (w R (P ⋙ s))) :=
is_sheaf_for_is_sheaf_for' P s U R,
rw ←equiv.nonempty_iff_nonempty this,
split,
{ exact nonempty.map (λ t, is_limit_of_preserves s t) },
{ exact nonempty.map (λ t, is_limit_of_reflects s t) }
end
end concrete
end presheaf
end category_theory
|
5144669d5e7a9462c55f6798b7834ec2420756cb | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /category_theory/products.lean | c9e6cd8c5d908e85ffea5d878333b7d59fe2ace7 | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 4,921 | 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 .functor_category
namespace category_theory
universes u₁ v₁ u₂ v₂ u₃ v₃ u₄ v₄
section
variables (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [category.{u₂ v₂} D]
/--
`prod.category C D` gives the cartesian product of two categories.
-/
instance prod.category : category.{(max u₁ u₂) (max v₁ v₂)} (C × D) :=
{ Hom := λ X Y, ((X.1) ⟶ (Y.1)) × ((X.2) ⟶ (Y.2)),
id := λ X, ⟨ 𝟙 (X.1), 𝟙 (X.2) ⟩,
comp := λ _ _ _ f g, (f.1 ≫ g.1, f.2 ≫ g.2),
id_comp := begin /- `obviously'` says: -/ intros, cases X, cases Y, cases f, dsimp at *, simp end,
comp_id := begin /- `obviously'` says: -/ intros, cases X, cases Y, cases f, dsimp at *, simp end,
assoc := begin /- `obviously'` says: -/ intros, cases W, cases X, cases Y, cases Z, cases f, cases g, cases h, dsimp at *, simp end }
end
namespace prod.category
section -- rfl lemmas for prod.category
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D]
include 𝒞 𝒟
@[simp, ematch] lemma id (X : C) (Y : D) : 𝟙 (X, Y) = (𝟙 X, 𝟙 Y) := rfl
@[simp, ematch] lemma comp {P Q R : C} {S T U : D} (f : (P, S) ⟶ (Q, T)) (g : (Q, T) ⟶ (R, U)) : f ≫ g = (f.1 ≫ g.1, f.2 ≫ g.2) := rfl
end
section
variables (C : Type u₁) [𝒞 : category.{u₁ v₁} C] (D : Type u₁) [𝒟 : category.{u₁ v₁} D]
include 𝒞 𝒟
/--
`prod.category.uniform C D` is an additional instance specialised so both factors have the same universe levels. This helps typeclass resolution.
-/
instance uniform : category (C × D) := prod.category C D
end
-- Next we define the natural functors into and out of product categories. For now this doesn't address the universal properties.
/-- `inl C Z` is the functor `X ↦ (X, Z)`. -/
def inl (C : Type u₁) [category.{u₁ v₁} C] {D : Type u₁} [category.{u₁ v₁} D] (Z : D) : C ↝ (C × D) :=
{ obj := λ X, (X, Z),
map := λ X Y f, (f, 𝟙 Z),
map_id := begin /- `obviously'` says: -/ intros, refl end,
map_comp := begin /- `obviously'` says: -/ intros, dsimp, simp end }
/-- `inr D Z` is the functor `X ↦ (Z, X)`. -/
def inr {C : Type u₁} [category.{u₁ v₁} C] (D : Type u₁) [category.{u₁ v₁} D] (Z : C) : D ↝ (C × D) :=
{ obj := λ X, (Z, X),
map := λ X Y f, (𝟙 Z, f),
map_id := begin /- `obviously'` says: -/ intros, refl end,
map_comp := begin /- `obviously'` says: -/ intros, dsimp, simp end }
/-- `fst` is the functor `(X, Y) ↦ X`. -/
def fst (C : Type u₁) [category.{u₁ v₁} C] (Z : C) (D : Type u₁) [category.{u₁ v₁} D] : (C × D) ↝ C :=
{ obj := λ X, X.1,
map := λ X Y f, f.1,
map_id := begin /- `obviously'` says: -/ intros, refl end,
map_comp := begin /- `obviously'` says: -/ intros, refl end }
/-- `snd` is the functor `(X, Y) ↦ Y`. -/
def snd (C : Type u₁) [category.{u₁ v₁} C] (Z : C) (D : Type u₁) [category.{u₁ v₁} D] : (C × D) ↝ D :=
{ obj := λ X, X.2,
map := λ X Y f, f.2,
map_id := begin /- `obviously'` says: -/ intros, refl end,
map_comp := begin /- `obviously'` says: -/ intros, refl end }
end prod.category
variables {A : Type u₁} [𝒜 : category.{u₁ v₁} A] {B : Type u₂} [ℬ : category.{u₂ v₂} B] {C : Type u₃} [𝒞 : category.{u₃ v₃} C] {D : Type u₄} [𝒟 : category.{u₄ v₄} D]
include 𝒜 ℬ 𝒞 𝒟
namespace functor
/-- The cartesion product of two functors. -/
def prod (F : A ↝ B) (G : C ↝ D) : (A × C) ↝ (B × D) :=
{ obj := λ X, (F X.1, G X.2),
map := λ _ _ f, (F.map f.1, G.map f.2),
map_id := begin /- `obviously'` says: -/ intros, cases X, dsimp, rw map_id_lemma, rw map_id_lemma end,
map_comp := begin /- `obviously'` says: -/ intros, cases Z, cases Y, cases X, cases f, cases g, dsimp at *, rw map_comp_lemma, rw map_comp_lemma end }
@[simp, ematch] lemma prod_obj (F : A ↝ B) (G : C ↝ D) (a : A) (c : C) : F.prod G (a, c) = (F a, G c) := rfl
@[simp, ematch] lemma prod_map (F : A ↝ B) (G : C ↝ D) {a a' : A} {c c' : C} (f : (a, c) ⟶ (a', c')) : (F.prod G).map f = (F.map f.1, G.map f.2) := rfl
end functor
namespace nat_trans
/-- The cartesian product of two natural transformations. -/
def prod {F G : A ↝ B} {H I : C ↝ D} (α : F ⟹ G) (β : H ⟹ I) : F.prod H ⟹ G.prod I :=
{ app := λ X, (α X.1, β X.2),
naturality := begin /- `obviously'` says: -/ intros, cases f, cases Y, cases X, dsimp at *, simp, split, rw naturality_lemma, rw naturality_lemma end }
@[simp, ematch] lemma prod_app {F G : A ↝ B} {H I : C ↝ D} (α : F ⟹ G) (β : H ⟹ I) (a : A) (c : C) : α.prod β (a, c) = (α a, β c) := rfl
end nat_trans
end category_theory |
24b083a748849679efdc193146ee44a1201be5b7 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/complex/liouville.lean | e297de7e96bd2040a6931df4be7825d0dfaac749 | [
"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 | 5,713 | lean | /-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import analysis.complex.cauchy_integral
import analysis.calculus.fderiv_analytic
import analysis.normed_space.completion
/-!
# Liouville's theorem
In this file we prove Liouville's theorem: if `f : E → F` is complex differentiable on the whole
space and its range is bounded, then the function is a constant. Various versions of this theorem
are formalized in `differentiable.apply_eq_apply_of_bounded`,
`differentiable.exists_const_forall_eq_of_bounded`, and
`differentiable.exists_eq_const_of_bounded`.
The proof is based on the Cauchy integral formula for the derivative of an analytic function, see
`complex.deriv_eq_smul_circle_integral`.
-/
open topological_space metric set filter asymptotics function measure_theory
open_locale topology filter nnreal real
universes u v
variables {E : Type u} [normed_add_comm_group E] [normed_space ℂ E]
{F : Type v} [normed_add_comm_group F] [normed_space ℂ F]
local postfix `̂`:100 := uniform_space.completion
namespace complex
/-- If `f` is complex differentiable on an open disc with center `c` and radius `R > 0` and is
continuous on its closure, then `f' c` can be represented as an integral over the corresponding
circle.
TODO: add a version for `w ∈ metric.ball c R`.
TODO: add a version for higher derivatives. -/
lemma deriv_eq_smul_circle_integral [complete_space F] {R : ℝ} {c : ℂ} {f : ℂ → F} (hR : 0 < R)
(hf : diff_cont_on_cl ℂ f (ball c R)) :
deriv f c = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z :=
begin
lift R to ℝ≥0 using hR.le,
refine (hf.has_fpower_series_on_ball hR).has_fpower_series_at.deriv.trans _,
simp only [cauchy_power_series_apply, one_div, zpow_neg, pow_one, smul_smul, zpow_two, mul_inv]
end
lemma norm_deriv_le_aux [complete_space F] {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hf : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R :=
begin
have : ∀ z ∈ sphere c R, ‖(z - c) ^ (-2 : ℤ) • f z‖ ≤ C / (R * R),
from λ z (hz : abs (z - c) = R), by simpa [-mul_inv_rev, norm_smul, hz, zpow_two,
←div_eq_inv_mul] using (div_le_div_right (mul_pos hR hR)).2 (hC z hz),
calc ‖deriv f c‖ = ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z‖ :
congr_arg norm (deriv_eq_smul_circle_integral hR hf)
... ≤ R * (C / (R * R)) :
circle_integral.norm_two_pi_I_inv_smul_integral_le_of_norm_le_const hR.le this
... = C / R : by rw [mul_div_left_comm, div_self_mul_self', div_eq_mul_inv]
end
/-- If `f` is complex differentiable on an open disc of radius `R > 0`, is continuous on its
closure, and its values on the boundary circle of this disc are bounded from above by `C`, then the
norm of its derivative at the center is at most `C / R`. -/
lemma norm_deriv_le_of_forall_mem_sphere_norm_le {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hd : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R :=
begin
set e : F →L[ℂ] F̂ := uniform_space.completion.to_complL,
have : has_deriv_at (e ∘ f) (e (deriv f c)) c,
from e.has_fderiv_at.comp_has_deriv_at c
(hd.differentiable_at is_open_ball $ mem_ball_self hR).has_deriv_at,
calc ‖deriv f c‖ = ‖deriv (e ∘ f) c‖ :
by { rw this.deriv, exact (uniform_space.completion.norm_coe _).symm }
... ≤ C / R :
norm_deriv_le_aux hR (e.differentiable.comp_diff_cont_on_cl hd)
(λ z hz, (uniform_space.completion.norm_coe _).trans_le (hC z hz))
end
/-- An auxiliary lemma for Liouville's theorem `differentiable.apply_eq_apply_of_bounded`. -/
lemma liouville_theorem_aux {f : ℂ → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) (z w : ℂ) : f z = f w :=
begin
suffices : ∀ c, deriv f c = 0, from is_const_of_deriv_eq_zero hf this z w,
clear z w, intro c,
obtain ⟨C, C₀, hC⟩ : ∃ C > (0 : ℝ), ∀ z, ‖f z‖ ≤ C,
{ rcases bounded_iff_forall_norm_le.1 hb with ⟨C, hC⟩,
exact ⟨max C 1, lt_max_iff.2 (or.inr zero_lt_one),
λ z, (hC (f z) (mem_range_self _)).trans (le_max_left _ _)⟩ },
refine norm_le_zero_iff.1 (le_of_forall_le_of_dense $ λ ε ε₀, _),
calc ‖deriv f c‖ ≤ C / (C / ε) :
norm_deriv_le_of_forall_mem_sphere_norm_le (div_pos C₀ ε₀) hf.diff_cont_on_cl (λ z _, hC z)
... = ε : div_div_cancel' C₀.lt.ne'
end
end complex
namespace differentiable
open complex
/-- **Liouville's theorem**: a complex differentiable bounded function `f : E → F` is a constant. -/
lemma apply_eq_apply_of_bounded {f : E → F} (hf : differentiable ℂ f) (hb : bounded (range f))
(z w : E) : f z = f w :=
begin
set g : ℂ → F := f ∘ (λ t : ℂ, t • (w - z) + z),
suffices : g 0 = g 1, by simpa [g],
apply liouville_theorem_aux,
exacts [hf.comp ((differentiable_id.smul_const (w - z)).add_const z),
hb.mono (range_comp_subset_range _ _)]
end
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
lemma exists_const_forall_eq_of_bounded {f : E → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) : ∃ c, ∀ z, f z = c :=
⟨f 0, λ z, hf.apply_eq_apply_of_bounded hb _ _⟩
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
lemma exists_eq_const_of_bounded {f : E → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) : ∃ c, f = const E c :=
(hf.exists_const_forall_eq_of_bounded hb).imp $ λ c, funext
end differentiable
|
e800ee234d50de0c49cee4d4c9d4e602eac9fa47 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /src/Std/Data/PersistentHashSet.lean | 790cd4bd1c79798a633b7bb18b81b6d9a9345a16 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,666 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Std.Data.PersistentHashMap
namespace Std
universes u v
structure PersistentHashSet (α : Type u) [BEq α] [Hashable α] :=
(set : PersistentHashMap α Unit)
abbrev PHashSet (α : Type u) [BEq α] [Hashable α] := PersistentHashSet α
namespace PersistentHashSet
variables {α : Type u} [BEq α] [Hashable α]
@[inline] def isEmpty (s : PersistentHashSet α) : Bool :=
s.set.isEmpty
@[inline] def empty : PersistentHashSet α :=
{ set := PersistentHashMap.empty }
instance : Inhabited (PersistentHashSet α) :=
⟨empty⟩
instance : EmptyCollection (PersistentHashSet α) :=
⟨empty⟩
@[inline] def insert (s : PersistentHashSet α) (a : α) : PersistentHashSet α :=
{ set := s.set.insert a () }
@[inline] def erase (s : PersistentHashSet α) (a : α) : PersistentHashSet α :=
{ set := s.set.erase a }
@[inline] def find? (s : PersistentHashSet α) (a : α) : Option α :=
match s.set.findEntry? a with
| some (a, _) => some a
| none => none
@[inline] def contains (s : PersistentHashSet α) (a : α) : Bool :=
s.set.contains a
@[inline] def size (s : PersistentHashSet α) : Nat :=
s.set.size
@[inline] def foldM {β : Type v} {m : Type v → Type v} [Monad m] (f : β → α → m β) (init : β) (s : PersistentHashSet α) : m β :=
s.set.foldlM (init := init) fun d a _ => f d a
@[inline] def fold {β : Type v} (f : β → α → β) (init : β) (s : PersistentHashSet α) : β :=
Id.run $ s.foldM f init
end PersistentHashSet
end Std
|
6d3b6708bb99053890b42fa0bef531ac0c15ca55 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/measure/doubling.lean | c306deac59ea1b22986b8f2247c3efd813d1b734 | [
"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 | 7,275 | lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import analysis.special_functions.log.base
import measure_theory.measure.measure_space_def
/-!
# Uniformly locally doubling measures
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
A uniformly locally doubling measure `μ` on a metric space is a measure for which there exists a
constant `C` such that for all sufficiently small radii `ε`, and for any centre, the measure of a
ball of radius `2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`.
This file records basic facts about uniformly locally doubling measures.
## Main definitions
* `is_unif_loc_doubling_measure`: the definition of a uniformly locally doubling measure (as a
typeclass).
* `is_unif_loc_doubling_measure.doubling_constant`: a function yielding the doubling constant `C`
appearing in the definition of a uniformly locally doubling measure.
-/
noncomputable theory
open set filter metric measure_theory topological_space
open_locale ennreal nnreal topology
/-- A measure `μ` is said to be a uniformly locally doubling measure if there exists a constant `C`
such that for all sufficiently small radii `ε`, and for any centre, the measure of a ball of radius
`2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`.
Note: it is important that this definition makes a demand only for sufficiently small `ε`. For
example we want hyperbolic space to carry the instance `is_unif_loc_doubling_measure volume` but
volumes grow exponentially in hyperbolic space. To be really explicit, consider the hyperbolic plane
of curvature -1, the area of a disc of radius `ε` is `A(ε) = 2π(cosh(ε) - 1)` so
`A(2ε)/A(ε) ~ exp(ε)`. -/
class is_unif_loc_doubling_measure
{α : Type*} [metric_space α] [measurable_space α] (μ : measure α) :=
(exists_measure_closed_ball_le_mul [] :
∃ (C : ℝ≥0), ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closed_ball x (2 * ε)) ≤ C * μ (closed_ball x ε))
namespace is_unif_loc_doubling_measure
variables {α : Type*} [metric_space α] [measurable_space α]
(μ : measure α) [is_unif_loc_doubling_measure μ]
/-- A doubling constant for a uniformly locally doubling measure.
See also `is_unif_loc_doubling_measure.scaling_constant_of`. -/
def doubling_constant : ℝ≥0 := classical.some $ exists_measure_closed_ball_le_mul μ
lemma exists_measure_closed_ball_le_mul' :
∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closed_ball x (2 * ε)) ≤ doubling_constant μ * μ (closed_ball x ε) :=
classical.some_spec $ exists_measure_closed_ball_le_mul μ
lemma exists_eventually_forall_measure_closed_ball_le_mul (K : ℝ) :
∃ (C : ℝ≥0), ∀ᶠ ε in 𝓝[>] 0, ∀ x t (ht : t ≤ K),
μ (closed_ball x (t * ε)) ≤ C * μ (closed_ball x ε) :=
begin
let C := doubling_constant μ,
have hμ : ∀ (n : ℕ), ∀ᶠ ε in 𝓝[>] 0, ∀ x,
μ (closed_ball x (2^n * ε)) ≤ ↑(C^n) * μ (closed_ball x ε),
{ intros n,
induction n with n ih, { simp, },
replace ih := eventually_nhds_within_pos_mul_left (two_pos : 0 < (2 : ℝ)) ih,
refine (ih.and (exists_measure_closed_ball_le_mul' μ)).mono (λ ε hε x, _),
calc μ (closed_ball x (2^(n + 1) * ε))
= μ (closed_ball x (2^n * (2 * ε))) : by rw [pow_succ', mul_assoc]
... ≤ ↑(C^n) * μ (closed_ball x (2 * ε)) : hε.1 x
... ≤ ↑(C^n) * (C * μ (closed_ball x ε)) : ennreal.mul_left_mono (hε.2 x)
... = ↑(C^(n + 1)) * μ (closed_ball x ε) : by rw [← mul_assoc, pow_succ', ennreal.coe_mul], },
rcases lt_or_le K 1 with hK | hK,
{ refine ⟨1, _⟩,
simp only [ennreal.coe_one, one_mul],
exact eventually_mem_nhds_within.mono (λ ε hε x t ht,
measure_mono $ closed_ball_subset_closed_ball (by nlinarith [mem_Ioi.mp hε])), },
{ refine ⟨C^⌈real.logb 2 K⌉₊, ((hμ ⌈real.logb 2 K⌉₊).and eventually_mem_nhds_within).mono
(λ ε hε x t ht, le_trans (measure_mono $ closed_ball_subset_closed_ball _) (hε.1 x))⟩,
refine mul_le_mul_of_nonneg_right (ht.trans _) (mem_Ioi.mp hε.2).le,
conv_lhs { rw ← real.rpow_logb two_pos (by norm_num) (by linarith : 0 < K), },
rw ← real.rpow_nat_cast,
exact real.rpow_le_rpow_of_exponent_le one_le_two (nat.le_ceil (real.logb 2 K)), },
end
/-- A variant of `is_unif_loc_doubling_measure.doubling_constant` which allows for scaling the
radius by values other than `2`. -/
def scaling_constant_of (K : ℝ) : ℝ≥0 :=
max (classical.some $ exists_eventually_forall_measure_closed_ball_le_mul μ K) 1
@[simp] lemma one_le_scaling_constant_of (K : ℝ) : 1 ≤ scaling_constant_of μ K :=
le_max_of_le_right $ le_refl 1
lemma eventually_measure_mul_le_scaling_constant_of_mul (K : ℝ) :
∃ (R : ℝ), 0 < R ∧ ∀ x t r (ht : t ∈ Ioc 0 K) (hr : r ≤ R),
μ (closed_ball x (t * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=
begin
have h := classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul μ K),
rcases mem_nhds_within_Ioi_iff_exists_Ioc_subset.1 h with ⟨R, Rpos, hR⟩,
refine ⟨R, Rpos, λ x t r ht hr, _⟩,
rcases lt_trichotomy r 0 with rneg|rfl|rpos,
{ have : t * r < 0, from mul_neg_of_pos_of_neg ht.1 rneg,
simp only [closed_ball_eq_empty.2 this, measure_empty, zero_le'] },
{ simp only [mul_zero, closed_ball_zero],
refine le_mul_of_one_le_of_le _ le_rfl,
apply ennreal.one_le_coe_iff.2 (le_max_right _ _) },
{ apply (hR ⟨rpos, hr⟩ x t ht.2).trans _,
exact mul_le_mul_right' (ennreal.coe_le_coe.2 (le_max_left _ _)) _ }
end
lemma eventually_measure_le_scaling_constant_mul (K : ℝ) :
∀ᶠ r in 𝓝[>] 0, ∀ x,
μ (closed_ball x (K * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=
begin
filter_upwards [classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul μ K)]
with r hr x,
exact (hr x K le_rfl).trans (mul_le_mul_right' (ennreal.coe_le_coe.2 (le_max_left _ _)) _)
end
lemma eventually_measure_le_scaling_constant_mul' (K : ℝ) (hK : 0 < K) :
∀ᶠ r in 𝓝[>] 0, ∀ x,
μ (closed_ball x r) ≤ scaling_constant_of μ K⁻¹ * μ (closed_ball x (K * r)) :=
begin
convert eventually_nhds_within_pos_mul_left hK (eventually_measure_le_scaling_constant_mul μ K⁻¹),
ext,
simp [inv_mul_cancel_left₀ hK.ne'],
end
/-- A scale below which the doubling measure `μ` satisfies good rescaling properties when one
multiplies the radius of balls by at most `K`, as stated
in `measure_mul_le_scaling_constant_of_mul`. -/
def scaling_scale_of (K : ℝ) : ℝ :=
(eventually_measure_mul_le_scaling_constant_of_mul μ K).some
lemma scaling_scale_of_pos (K : ℝ) : 0 < scaling_scale_of μ K :=
(eventually_measure_mul_le_scaling_constant_of_mul μ K).some_spec.1
lemma measure_mul_le_scaling_constant_of_mul {K : ℝ} {x : α} {t r : ℝ}
(ht : t ∈ Ioc 0 K) (hr : r ≤ scaling_scale_of μ K) :
μ (closed_ball x (t * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=
(eventually_measure_mul_le_scaling_constant_of_mul μ K).some_spec.2 x t r ht hr
end is_unif_loc_doubling_measure
|
0e9c1f07c4adbe6149a1f4db0296de007c68d5bd | d8820d2c92be8052d13f9c8f8c483a6e15c5f566 | /src/M40001/Sqrt2_not_rational.lean | fdf75a6bb3643abf845faf9549817c4c32bc27b3 | [] | no_license | JasonKYi/M4000x_LEAN_formalisation | 4a19b84f6d0fe2e214485b8532e21cd34996c4b1 | 6e99793f2fcbe88596e27644f430e46aa2a464df | refs/heads/master | 1,599,755,414,708 | 1,589,494,604,000 | 1,589,494,604,000 | 221,759,483 | 8 | 1 | null | 1,589,494,605,000 | 1,573,755,201,000 | Lean | UTF-8 | Lean | false | false | 6,529 | lean | import tactic.ring
import tactic.linarith
import data.rat.basic
import data.rat.cast
/- Section
1.4 An Application
-/
/-
We would like prove that there is no rational number whose square is 2 using the techniques introduced earlier.
-/
def even (a : ℤ) := ∃ b : ℤ, a = 2 * b
def odd (a : ℤ) := ∃ b : ℤ, a = 2 * b + 1
lemma not_even_is_odd (n : ℤ) : ¬ even n ↔ odd n :=
begin
split,
intro ha,
have hb : n % 2 = 1,
have hc : n % 2 = 0 ∨ n % 2 = 1,
apply int.mod_two_eq_zero_or_one,
cases hc with hx hy,
exfalso,
apply ha,
existsi n / 2,
rw int.mul_div_cancel_of_mod_eq_zero hx,
assumption,
have hc : (n - 1) % 2 = 0,
have hd : n % 2 = 1 % 2, rw hb, refl,
revert hd,
rw int.mod_eq_mod_iff_mod_sub_eq_zero,
intro h, assumption,
existsi (n - 1) / 2,
rw int.mul_div_cancel_of_mod_eq_zero hc,
simp,
intro ha,
intro hb,
cases ha with x hx,
cases hb with y hy,
have hc : n % 2 = 1,
rw hx, simp, refl,
have hd : n % 2 = 0,
rw hy, simp,
have he : (1 : ℤ) = (0 : ℤ),
rwa [←hc, ←hd],
have hf : ¬ ( (1 : ℤ) = (0 : ℤ)), simp,
exact hf he,
end
lemma gcdeven (n m : ℕ) : 2 ∣ nat.gcd (2 * n) (2 * m) :=
begin
have ha : 2 ∣ 2 * n, existsi n, refl,
have hb : 2 ∣ 2 * m, existsi m, refl,
have hc : (2 ∣ 2 * n) → (2 ∣ 2 * m) → 2 ∣ nat.gcd (2 * n) (2 * m),
exact nat.dvd_gcd,
apply hc,
repeat {assumption},
end
/- Lemma
If $a$ is an integer, then $a$ is even is and only if $a^2$ is even.
-/
lemma times_even
(a : ℤ) : even a ↔ even (a ^ 2) :=
begin
split,
intro h,
have ha : ∃ b : ℤ, a = 2 * b, exact h,
have hb : ∃ b : ℤ, a ^ 2 = 2 * b,
cases ha with x hx,
existsi 2 * x ^ 2,
rw hx,
ring,
exact hb,
intro h,
apply classical.by_contradiction,
intro ha,
have hc : odd a,
rw ←not_even_is_odd a,
assumption,
have hd : odd (a ^ 2),
cases hc with x hx,
existsi 2 * x ^ 2 + 2 * x,
rw hx,
ring,
have he : ¬ even (a ^ 2),
rw not_even_is_odd (a ^ 2),
assumption,
exact he h,
end
/- Theorem
There is no rational number whose square is 2.
-/
theorem rational_not_sqrt_two : ¬ ∃ r : ℚ, r ^ 2 = 2 :=
begin
-- First show that p is even
push_neg,
intro r,
-- Manipulate the fraction to have the properties desired
have h : rat.mk (r.num) (r.denom) = r,
apply rat.num_denom,
rw ←h,
intro hcon,
-- The denominator must not be zero
have hdnot0 : r.denom ≠ 0,
intro ha,
have hb : rat.mk (r.num) (r.denom) ^ 2 = 0,
rw ha,
refl,
convert hb,
rw hcon,
simp,
linarith,
-- The numerator must also not be zero
have hnnot0 : r.num ≠ 0,
intro ha,
have hb : rat.mk (r.num) (r.denom) ^ 2 = 0,
rw ha,
simp, refl,
convert hb,
rw hcon,
simp,
linarith,
-- The fraction is in its lowest terms
have hcop : nat.coprime (int.nat_abs r.num) r.denom,
cases r with ha hb hc hd,
exact hd,
-- Now we can begin the actual proof...
-- First show that r.num ^ 2 is even
have hsqrneven : even (r.num ^ 2),
existsi (r.denom : ℤ) ^ 2,
have ha : r.num ^ 2 = r.num ^ 2 * 1,
simp,
rwa [ha, ←rat.mk_eq],
convert hcon,
repeat {rw pow_two},
rw rat.mul_def,
all_goals {try {simp, apply hdnot0,}},
simp,
-- Now we can use times_even to show r.num is even
have hneven : even r.num, rw times_even, assumption,
-- r.num is even → r.denom ^ 2 is also even
have hsqrdeven : even (r.denom ^ 2),
cases hneven with b ha,
existsi b ^ 2,
have hb : (2 * ↑(r.denom) ^ 2 = 4 * (b ^ 2)) → (↑(r.denom) ^ 2 = 2 * b ^ 2),
have hβ : 4 * b ^ 2 = 2 * 2 * b ^ 2, refl,
rw [hβ, ←sub_eq_zero],
have hγ : 2 * ↑(r.denom) ^ 2 - 2 * 2 * b ^ 2 = 2 * (↑(r.denom) ^ 2 - 2 * b ^ 2), ring,
rw [hγ, mul_eq_zero],
intro hδ,
cases hδ with hδ1 hδ2,
exfalso,
convert hδ1, simp, linarith,
rw ←sub_eq_zero,
assumption,
rw hb,
have hc : 4 * b ^ 2 = (2 * b) ^ 2,
ring,
rw [hc, ←ha],
have hd : ↑r.denom * ↑r.denom = r.denom * r.denom, simp,
have he : rat.mk (r.num ^ 2) (r.denom ^ 2) = 2,
rw ←hcon,
repeat {rw pow_two},
rw rat.mul_def,
repeat {simp, apply hdnot0,},
have hf : rat.mk r.num r.denom = r.num / r.denom,
exact rat.mk_eq_div (r.num) ↑(r.denom),
have hg : 2 * (↑(r.denom) ^ 2) = r.num ^ 2 * 1 → 2 * (↑(r.denom) * ↑(r.denom)) = r.num * r.num,
repeat {rw pow_two},
rw mul_one,
intro hh,
assumption,
rw hg,
rw ←rat.mk_eq,
rw he,
refl,
simp,
rw pow_two,
intro hh,
have hi : r.denom = 0,
have hj : r.denom * r.denom = 0,
rw ←hd,
exact_mod_cast hh,
rw nat.mul_eq_zero at hj,
revert hj,
simp,
exfalso,
exact hdnot0 hi,
have hdeven : even r.denom, rw times_even, assumption,
-- But that means r.num and r.denom are not coprimes
have hncop : ¬ nat.coprime (int.nat_abs (r.num)) (r.denom),
have ha : ¬ nat.coprime (int.nat_abs (r.num)) (r.denom) ↔ nat.gcd (int.nat_abs (r.num)) (r.denom) ≠ 1, refl,
rw ha,
cases hneven with k hk,
cases hdeven with m hm,
rw hk,
have hb : int.nat_abs r.denom = 2 * (int.nat_abs m),
rwa [hm, int.nat_abs_mul],
refl,
have hc : (r.denom : ℕ) = int.nat_abs r.denom, refl,
rwa [hc, hb],
have hd : int.nat_abs (2 * k) = 2 * int.nat_abs k, rw int.nat_abs_mul, refl,
rw hd,
intro he,
have hf : ¬ (2 ∣ nat.gcd (2 * int.nat_abs k) (2 * int.nat_abs m)),
rw he,
simp,
linarith,
have hg : 2 ∣ nat.gcd (2 * int.nat_abs k) (2 * int.nat_abs m),
apply gcdeven,
exact hf hg,
exact hncop hcop,
end |
e64c804e5b0ef9fc981dd788522a8a7c019bdaea | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/opposites.lean | e4d3e2d8e131485305b3623a4b6c0968bdafcce6 | [
"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 | 9,063 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.group.defs
import logic.equiv.defs
import logic.nontrivial
/-!
# Multiplicative opposite and algebraic operations on it
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/644
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define `mul_opposite α = αᵐᵒᵖ` to be the multiplicative opposite of `α`. It inherits
all additive algebraic structures on `α` (in other files), and reverses the order of multipliers in
multiplicative structures, i.e., `op (x * y) = op y * op x`, where `mul_opposite.op` is the
canonical map from `α` to `αᵐᵒᵖ`.
We also define `add_opposite α = αᵃᵒᵖ` to be the additive opposite of `α`. It inherits all
multiplicative algebraic structures on `α` (in other files), and reverses the order of summands in
additive structures, i.e. `op (x + y) = op y + op x`, where `add_opposite.op` is the canonical map
from `α` to `αᵃᵒᵖ`.
## Notation
* `αᵐᵒᵖ = mul_opposite α`
* `αᵃᵒᵖ = add_opposite α`
## Tags
multiplicative opposite, additive opposite
-/
universes u v
open function
/-- Multiplicative opposite of a type. This type inherits all additive structures on `α` and
reverses left and right in multiplication.-/
@[to_additive "Additive opposite of a type. This type inherits all multiplicative structures on
`α` and reverses left and right in addition."]
def mul_opposite (α : Type u) : Type u := α
postfix `ᵐᵒᵖ`:std.prec.max_plus := mul_opposite
postfix `ᵃᵒᵖ`:std.prec.max_plus := add_opposite
variables {α : Type u}
namespace mul_opposite
/-- The element of `mul_opposite α` that represents `x : α`. -/
@[pp_nodot, to_additive "The element of `αᵃᵒᵖ` that represents `x : α`."]
def op : α → αᵐᵒᵖ := id
/-- The element of `α` represented by `x : αᵐᵒᵖ`. -/
@[pp_nodot, to_additive "The element of `α` represented by `x : αᵃᵒᵖ`."]
def unop : αᵐᵒᵖ → α := id
attribute [pp_nodot] add_opposite.op add_opposite.unop
@[simp, to_additive] lemma unop_op (x : α) : unop (op x) = x := rfl
@[simp, to_additive] lemma op_unop (x : αᵐᵒᵖ) : op (unop x) = x := rfl
@[simp, to_additive] lemma op_comp_unop : (op : α → αᵐᵒᵖ) ∘ unop = id := rfl
@[simp, to_additive] lemma unop_comp_op : (unop : αᵐᵒᵖ → α) ∘ op = id := rfl
attribute [irreducible] mul_opposite
/-- A recursor for `mul_opposite`. Use as `induction x using mul_opposite.rec`. -/
@[simp, to_additive "A recursor for `add_opposite`. Use as `induction x using add_opposite.rec`."]
protected def rec {F : Π (X : αᵐᵒᵖ), Sort v} (h : Π X, F (op X)) : Π X, F X :=
λ X, h (unop X)
/-- The canonical bijection between `α` and `αᵐᵒᵖ`. -/
@[to_additive "The canonical bijection between `α` and `αᵃᵒᵖ`.",
simps apply symm_apply { fully_applied := ff }]
def op_equiv : α ≃ αᵐᵒᵖ := ⟨op, unop, unop_op, op_unop⟩
@[to_additive] lemma op_bijective : bijective (op : α → αᵐᵒᵖ) := op_equiv.bijective
@[to_additive] lemma unop_bijective : bijective (unop : αᵐᵒᵖ → α) := op_equiv.symm.bijective
@[to_additive] lemma op_injective : injective (op : α → αᵐᵒᵖ) := op_bijective.injective
@[to_additive] lemma op_surjective : surjective (op : α → αᵐᵒᵖ) := op_bijective.surjective
@[to_additive] lemma unop_injective : injective (unop : αᵐᵒᵖ → α) := unop_bijective.injective
@[to_additive] lemma unop_surjective : surjective (unop : αᵐᵒᵖ → α) := unop_bijective.surjective
@[simp, to_additive] lemma op_inj {x y : α} : op x = op y ↔ x = y := op_injective.eq_iff
@[simp, to_additive] lemma unop_inj {x y : αᵐᵒᵖ} : unop x = unop y ↔ x = y := unop_injective.eq_iff
variable (α)
@[to_additive] instance [nontrivial α] : nontrivial αᵐᵒᵖ := op_injective.nontrivial
@[to_additive] instance [inhabited α] : inhabited αᵐᵒᵖ := ⟨op default⟩
@[to_additive] instance [subsingleton α] : subsingleton αᵐᵒᵖ := unop_injective.subsingleton
@[to_additive] instance [unique α] : unique αᵐᵒᵖ := unique.mk' _
@[to_additive] instance [is_empty α] : is_empty αᵐᵒᵖ := function.is_empty unop
instance [has_zero α] : has_zero αᵐᵒᵖ := { zero := op 0 }
@[to_additive] instance [has_one α] : has_one αᵐᵒᵖ := { one := op 1 }
instance [has_add α] : has_add αᵐᵒᵖ :=
{ add := λ x y, op (unop x + unop y) }
instance [has_sub α] : has_sub αᵐᵒᵖ :=
{ sub := λ x y, op (unop x - unop y) }
instance [has_neg α] : has_neg αᵐᵒᵖ :=
{ neg := λ x, op $ -(unop x) }
instance [has_involutive_neg α] : has_involutive_neg αᵐᵒᵖ :=
{ neg_neg := λ a, unop_injective $ neg_neg _,
..mul_opposite.has_neg α }
@[to_additive] instance [has_mul α] : has_mul αᵐᵒᵖ :=
{ mul := λ x y, op (unop y * unop x) }
@[to_additive] instance [has_inv α] : has_inv αᵐᵒᵖ :=
{ inv := λ x, op $ (unop x)⁻¹ }
@[to_additive] instance [has_involutive_inv α] : has_involutive_inv αᵐᵒᵖ :=
{ inv_inv := λ a, unop_injective $ inv_inv _,
..mul_opposite.has_inv α }
@[to_additive] instance (R : Type*) [has_smul R α] : has_smul R αᵐᵒᵖ :=
{ smul := λ c x, op (c • unop x) }
section
variables (α)
@[simp] lemma op_zero [has_zero α] : op (0 : α) = 0 := rfl
@[simp] lemma unop_zero [has_zero α] : unop (0 : αᵐᵒᵖ) = 0 := rfl
@[simp, to_additive] lemma op_one [has_one α] : op (1 : α) = 1 := rfl
@[simp, to_additive] lemma unop_one [has_one α] : unop (1 : αᵐᵒᵖ) = 1 := rfl
variable {α}
@[simp] lemma op_add [has_add α] (x y : α) : op (x + y) = op x + op y := rfl
@[simp] lemma unop_add [has_add α] (x y : αᵐᵒᵖ) : unop (x + y) = unop x + unop y := rfl
@[simp] lemma op_neg [has_neg α] (x : α) : op (-x) = -op x := rfl
@[simp] lemma unop_neg [has_neg α] (x : αᵐᵒᵖ) : unop (-x) = -unop x := rfl
@[simp, to_additive] lemma op_mul [has_mul α] (x y : α) : op (x * y) = op y * op x := rfl
@[simp, to_additive] lemma unop_mul [has_mul α] (x y : αᵐᵒᵖ) : unop (x * y) = unop y * unop x := rfl
@[simp, to_additive] lemma op_inv [has_inv α] (x : α) : op (x⁻¹) = (op x)⁻¹ := rfl
@[simp, to_additive] lemma unop_inv [has_inv α] (x : αᵐᵒᵖ) : unop (x⁻¹) = (unop x)⁻¹ := rfl
@[simp] lemma op_sub [has_sub α] (x y : α) : op (x - y) = op x - op y := rfl
@[simp] lemma unop_sub [has_sub α] (x y : αᵐᵒᵖ) : unop (x - y) = unop x - unop y := rfl
@[simp, to_additive] lemma op_smul {R : Type*} [has_smul R α] (c : R) (a : α) :
op (c • a) = c • op a := rfl
@[simp, to_additive] lemma unop_smul {R : Type*} [has_smul R α] (c : R) (a : αᵐᵒᵖ) :
unop (c • a) = c • unop a := rfl
end
variable {α}
@[simp] lemma unop_eq_zero_iff [has_zero α] (a : αᵐᵒᵖ) : a.unop = (0 : α) ↔ a = (0 : αᵐᵒᵖ) :=
unop_injective.eq_iff' rfl
@[simp] lemma op_eq_zero_iff [has_zero α] (a : α) : op a = (0 : αᵐᵒᵖ) ↔ a = (0 : α) :=
op_injective.eq_iff' rfl
lemma unop_ne_zero_iff [has_zero α] (a : αᵐᵒᵖ) : a.unop ≠ (0 : α) ↔ a ≠ (0 : αᵐᵒᵖ) :=
not_congr $ unop_eq_zero_iff a
lemma op_ne_zero_iff [has_zero α] (a : α) : op a ≠ (0 : αᵐᵒᵖ) ↔ a ≠ (0 : α) :=
not_congr $ op_eq_zero_iff a
@[simp, to_additive] lemma unop_eq_one_iff [has_one α] (a : αᵐᵒᵖ) : a.unop = 1 ↔ a = 1 :=
unop_injective.eq_iff' rfl
@[simp, to_additive] lemma op_eq_one_iff [has_one α] (a : α) : op a = 1 ↔ a = 1 :=
op_injective.eq_iff' rfl
end mul_opposite
namespace add_opposite
instance [has_one α] : has_one αᵃᵒᵖ := { one := op 1 }
@[simp] lemma op_one [has_one α] : op (1 : α) = 1 := rfl
@[simp] lemma unop_one [has_one α] : unop 1 = (1 : α) := rfl
@[simp] lemma op_eq_one_iff [has_one α] {a : α} : op a = 1 ↔ a = 1 := op_injective.eq_iff' op_one
@[simp] lemma unop_eq_one_iff [has_one α] {a : αᵃᵒᵖ} : unop a = 1 ↔ a = 1 :=
unop_injective.eq_iff' unop_one
instance [has_mul α] : has_mul αᵃᵒᵖ := { mul := λ a b, op (unop a * unop b) }
@[simp] lemma op_mul [has_mul α] (a b : α) : op (a * b) = op a * op b := rfl
@[simp] lemma unop_mul [has_mul α] (a b : αᵃᵒᵖ) : unop (a * b) = unop a * unop b := rfl
instance [has_inv α] : has_inv αᵃᵒᵖ := { inv := λ a, op (unop a)⁻¹ }
instance [has_involutive_inv α] : has_involutive_inv αᵃᵒᵖ :=
{ inv_inv := λ a, unop_injective $ inv_inv _,
..add_opposite.has_inv }
@[simp] lemma op_inv [has_inv α] (a : α) : op a⁻¹ = (op a)⁻¹ := rfl
@[simp] lemma unop_inv [has_inv α] (a : αᵃᵒᵖ) : unop a⁻¹ = (unop a)⁻¹ := rfl
instance [has_div α] : has_div αᵃᵒᵖ := { div := λ a b, op (unop a / unop b) }
@[simp] lemma op_div [has_div α] (a b : α) : op (a / b) = op a / op b := rfl
@[simp] lemma unop_div [has_div α] (a b : α) : unop (a / b) = unop a / unop b := rfl
end add_opposite
|
30235d21ee14252d9188182747dde460820cd493 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Init/Data/Fin/Basic.lean | 2e8d65f9502fe5209b0537e91f48c99bc4223f43 | [
"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 | 3,421 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.Nat.Div
import Init.Data.Nat.Bitwise
import Init.Coe
open Nat
namespace Fin
instance coeToNat {n} : Coe (Fin n) Nat :=
⟨fun v => v.val⟩
def elim0.{u} {α : Sort u} : Fin 0 → α
| ⟨_, h⟩ => absurd h (not_lt_zero _)
def succ : Fin n → Fin n.succ
| ⟨i, h⟩ => ⟨i+1, Nat.succ_lt_succ h⟩
variable {n : Nat}
protected def ofNat {n : Nat} (a : Nat) : Fin n.succ :=
⟨a % (n+1), Nat.mod_lt _ (Nat.zero_lt_succ _)⟩
protected def ofNat' {n : Nat} (a : Nat) (h : n > 0) : Fin n :=
⟨a % n, Nat.mod_lt _ h⟩
private theorem mlt {b : Nat} : {a : Nat} → a < n → b % n < n
| 0, h => Nat.mod_lt _ h
| _+1, h =>
have : n > 0 := Nat.lt_trans (Nat.zero_lt_succ _) h;
Nat.mod_lt _ this
protected def add : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a + b) % n, mlt h⟩
protected def mul : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a * b) % n, mlt h⟩
protected def sub : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a + (n - b)) % n, mlt h⟩
/-!
Remark: mod/div/modn/land/lor can be defined without using (% n), but
we are trying to minimize the number of Nat theorems
needed to boostrap Lean.
-/
protected def mod : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a % b) % n, mlt h⟩
protected def div : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a / b) % n, mlt h⟩
def modn : Fin n → Nat → Fin n
| ⟨a, h⟩, m => ⟨(a % m) % n, mlt h⟩
def land : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.land a b) % n, mlt h⟩
def lor : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.lor a b) % n, mlt h⟩
def xor : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.xor a b) % n, mlt h⟩
def shiftLeft : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a <<< b) % n, mlt h⟩
def shiftRight : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a >>> b) % n, mlt h⟩
instance : Add (Fin n) where
add := Fin.add
instance : Sub (Fin n) where
sub := Fin.sub
instance : Mul (Fin n) where
mul := Fin.mul
instance : Mod (Fin n) where
mod := Fin.mod
instance : Div (Fin n) where
div := Fin.div
instance : AndOp (Fin n) where
and := Fin.land
instance : OrOp (Fin n) where
or := Fin.lor
instance : Xor (Fin n) where
xor := Fin.xor
instance : ShiftLeft (Fin n) where
shiftLeft := Fin.shiftLeft
instance : ShiftRight (Fin n) where
shiftRight := Fin.shiftRight
instance : OfNat (Fin (no_index (n+1))) i where
ofNat := Fin.ofNat i
instance : Inhabited (Fin (no_index (n+1))) where
default := 0
theorem val_ne_of_ne {i j : Fin n} (h : i ≠ j) : val i ≠ val j :=
fun h' => absurd (eq_of_val_eq h') h
theorem modn_lt : ∀ {m : Nat} (i : Fin n), m > 0 → (modn i m).val < m
| _, ⟨_, _⟩, hp => Nat.lt_of_le_of_lt (mod_le _ _) (mod_lt _ hp)
theorem val_lt_of_le (i : Fin b) (h : b ≤ n) : i.val < n :=
Nat.lt_of_lt_of_le i.isLt h
end Fin
instance [GetElem cont Nat elem dom] : GetElem cont (Fin n) elem fun xs i => dom xs i where
getElem xs i h := getElem xs i.1 h
macro_rules
| `(tactic| get_elem_tactic_trivial) => `(tactic| apply Fin.val_lt_of_le; get_elem_tactic_trivial; done)
|
1ada955d46d8a2ca968d48f3b33a27adbe114b95 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1155.lean | c0eaf4bbb48cf0f66033b9a42c0d52cf331cb1c6 | [
"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 | 76 | lean | def sacha : Nat :=
let (v, k) := match 0 with
| (n) => (0, 0)
v + k
|
5ea5ccd19fb3e75020cce643fba3512c3176fb5f | 53f7fd7840fe4979de24f9611c89f2ee1b4fc5dc | /src/basic.lean | 3f62fa7d50849949bc35ae732f57bf8f38b908c7 | [] | no_license | cipher1024/search-trees | 6d1925283c6ce47d84bdf41ca40d8317ff2e64d7 | 0e0ea0ee59f0b0499ebad1ef6f34f09ec9666cde | refs/heads/master | 1,673,300,158,759 | 1,603,984,112,000 | 1,603,984,112,000 | 308,132,998 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,027 | lean |
import tactic.default .tactic
universes u v w
namespace two_three
variables (α : Type u) (β : Type v) {γ : Type w}
inductive tree
| leaf (k : α) (v : β)
| node2 (t₀ : tree) (x : α) (t₁ : tree)
| node3 (t₀ : tree) (x : α) (t₁ : tree) (y : α) (t₂ : tree)
open tree nat
variables {α β}
def first : tree α β → α
| (tree.leaf x _) := x
| (tree.node2 t₀ x _) := first t₀
| (tree.node3 t₀ x _ _ _) := first t₀
def last : tree α β → α
| (tree.leaf x _) := x
| (tree.node2 _ x t₁) := last t₁
| (tree.node3 t₀ x _ _ t₂) := last t₂
section defs
variables [has_le α] [has_lt α]
open tree nat
inductive below : option α → α → Prop
| nil {x} : below none x
| eq {x} : below (some x) x
inductive above : α → option α → Prop
| nil {x} : above x none
| le {x y} : x < y → above x (some y)
inductive sorted' : tree α β → Prop
| leaf {k v} : sorted' (tree.leaf k v)
| node2 {x t₀ t₁} :
last t₀ < x →
x = first t₁ →
sorted' t₀ →
sorted' t₁ →
sorted' (tree.node2 t₀ x t₁)
| node3 {x y t₀ t₁ t₂} :
last t₀ < x →
x = first t₁ →
last t₁ < y →
y = first t₂ →
sorted' t₀ →
sorted' t₁ →
sorted' t₂ →
sorted' (tree.node3 t₀ x t₁ y t₂)
inductive with_height : ℕ → tree α β → Prop
| leaf {k v} : with_height 0 (tree.leaf k v)
| node2 {n x t₀ t₁} :
with_height n t₀ →
with_height n t₁ →
with_height (succ n) (tree.node2 t₀ x t₁)
| node3 {n x y t₀ t₁ t₂} :
with_height n t₀ →
with_height n t₁ →
with_height n t₂ →
with_height (succ n) (tree.node3 t₀ x t₁ y t₂)
end defs
local attribute [simp] first last
variables [linear_order α]
lemma first_le_last_of_sorted {t : tree α β} (h : sorted' t) :
first t ≤ last t :=
begin
induction h; subst_vars; dsimp [first, last],
{ refl },
repeat { solve_by_elim [le_of_lt] <|> transitivity },
end
lemma eq_of_below {x : option α} {y : α} (h : below x y) : x.get_or_else y = y :=
by cases h; refl
lemma above_of_above_of_le {x y : α} {k}
(h : x ≤ y) (h' : above y k) : above x k :=
by cases h'; constructor; solve_by_elim [lt_of_le_of_lt]
@[interactive]
meta def interactive.saturate : tactic unit := do
tactic.interactive.casesm (some ()) [``(above _ (some _)), ``(below (some _) _)],
tactic.find_all_hyps ``(sorted' _) $ λ h, do
{ n ← tactic.get_unused_name `h,
tactic.mk_app ``first_le_last_of_sorted [h] >>= tactic.note n none,
tactic.skip },
tactic.find_all_hyps ``(below _ _) $ λ h, do
{ n ← tactic.get_unused_name `h,
tactic.mk_app ``eq_of_below [h] >>= tactic.note n none,
tactic.skip },
tactic.find_all_hyps ``(¬ _ < _) $ λ h, do
{ tactic.mk_app ``le_of_not_gt [h] >>= tactic.note h.local_pp_name none,
tactic.clear h,
tactic.skip }
@[interactive]
meta def interactive.above : tactic unit := do
tactic.find_hyp ``(above _ _) $ λ h, do
tactic.refine ``(above_of_above_of_le _ %%h),
tactic.interactive.chain_trans
end two_three
|
ab4d03a9a544d9c081956894affb78c79efed1d6 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/528.lean | c664981331c68c4b2bc11f352e7663af690813f4 | [
"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 | 128 | lean | variables {P : bool → Type} {x : P bool.tt} {y : P bool.ff}
example (b : bool) : P b :=
match b with
| tt := x
| ff := y
end
|
b39c83a4937263ff65e73a82c27c5b8825e21928 | 947b78d97130d56365ae2ec264df196ce769371a | /src/Lean/Meta/DiscrTree.lean | 13c84cb609e6b3bb3a92c1652262917162c78d9b | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,368 | 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.Meta.Basic
import Lean.Meta.FunInfo
import Lean.Meta.InferType
namespace Lean
namespace Meta
namespace DiscrTree
/-
(Imperfect) discrimination trees.
We use a hybrid representation.
- A `PersistentHashMap` for the root node which usually contains many children.
- A sorted array of key/node pairs for inner nodes.
The edges are labeled by keys:
- Constant names (and arity). Universe levels are ignored.
- Free variables (and arity). Thus, an entry in the discrimination tree
may reference hypotheses from the local context.
- Literals
- Star/Wildcard. We use them to represent metavariables and terms
we want to ignore. We ignore implicit arguments and proofs.
- Other. We use to represent other kinds of terms (e.g., nested lambda, forall, sort, etc).
We reduce terms using `TransparencyMode.reducible`. Thus, all reducible
definitions in an expression `e` are unfolded before we insert it into the
discrimination tree.
Recall that projections from classes are **NOT** reducible.
For example, the expressions `HasAdd.add α (ringHasAdd ?α ?s) ?x ?x`
and `HasAdd.add Nat Nat.hasAdd a b` generates paths with the following keys
respctively
```
⟨HasAdd.add, 4⟩, *, *, *, *
⟨HasAdd.add, 4⟩, *, *, ⟨a,0⟩, ⟨b,0⟩
```
That is, we don't reduce `HasAdd.add Nat Nat.HasAdd a b` into `Nat.add a b`.
We say the `HasAdd.add` applications are the de-facto canonical forms in
the metaprogramming framework.
Moreover, it is the metaprogrammer's responsibility to re-pack applications such as
`Nat.add a b` into `HasAdd.add Nat Nat.hasAdd a b`.
Remark: we store the arity in the keys
1- To be able to implement the "skip" operation when retrieving "candidate"
unifiers.
2- Distinguish partial applications `f a`, `f a b`, and `f a b c`.
-/
def Key.ctorIdx : Key → Nat
| Key.star => 0
| Key.other => 1
| Key.lit _ => 2
| Key.fvar _ _ => 3
| Key.const _ _ => 4
def Key.lt : Key → Key → Bool
| Key.lit v₁, Key.lit v₂ => v₁ < v₂
| Key.fvar n₁ a₁, Key.fvar n₂ a₂ => Name.quickLt n₁ n₂ || (n₁ == n₂ && a₁ < a₂)
| Key.const n₁ a₁, Key.const n₂ a₂ => Name.quickLt n₁ n₂ || (n₁ == n₂ && a₁ < a₂)
| k₁, k₂ => k₁.ctorIdx < k₂.ctorIdx
instance Key.hasLess : HasLess Key := ⟨fun a b => Key.lt a b⟩
def Key.format : Key → Format
| Key.star => "*"
| Key.other => "◾"
| Key.lit (Literal.natVal v) => fmt v
| Key.lit (Literal.strVal v) => repr v
| Key.const k _ => fmt k
| Key.fvar k _ => fmt k
instance Key.hasFormat : HasFormat Key := ⟨Key.format⟩
def Key.arity : Key → Nat
| Key.const _ a => a
| Key.fvar _ a => a
| _ => 0
instance Trie.inhabited {α} : Inhabited (Trie α) := ⟨Trie.node #[] #[]⟩
def empty {α} : DiscrTree α := { root := {} }
/- The discrimination tree ignores implicit arguments and proofs.
We use the following auxiliary id as a "mark". -/
private def tmpMVarId : MVarId := `_discr_tree_tmp
private def tmpStar := mkMVar tmpMVarId
instance {α} : Inhabited (DiscrTree α) := ⟨{}⟩
/--
Return true iff the argument should be treated as a "wildcard" by the discrimination tree.
- We ignore proofs because of proof irrelevance. It doesn't make sense to try to
index their structure.
- We ignore instance implicit arguments (e.g., `[HasAdd α]`) because they are "morally" canonical.
Moreover, we may have many definitionally equal terms floating around.
Example: `Ring.hasAdd Int Int.isRing` and `Int.hasAdd`.
- We considered ignoring implicit arguments (e.g., `{α : Type}`) since users don't "see" them,
and may not even understand why some simplification rule is not firing.
However, in type class resolution, we have instance such as `Decidable (@Eq Nat x y)`,
where `Nat` is an implicit argument. Thus, we would add the path
```
Decidable -> Eq -> * -> * -> * -> [Nat.decEq]
```
to the discrimination tree IF we ignored the implict `Nat` argument.
This would be BAD since **ALL** decidable equality instances would be in the same path.
So, we index implicit arguments if they are types.
This setting seems sensible for simplification lemmas such as:
```
forall (x y : Unit), (@Eq Unit x y) = true
```
If we ignore the implicit argument `Unit`, the `DiscrTree` will say it is a candidate
simplification lemma for any equality in our goal.
Remark: if users have problems with the solution above, we may provide a `noIndexing` annotation,
and `ignoreArg` would return true for any term of the form `noIndexing t`.
-/
private def ignoreArg (a : Expr) (i : Nat) (infos : Array ParamInfo) : MetaM Bool :=
if h : i < infos.size then
let info := infos.get ⟨i, h⟩;
if info.instImplicit then
pure true
else if info.implicit then
not <$> isType a
else
isProof a
else
isProof a
private partial def pushArgsAux (infos : Array ParamInfo) : Nat → Expr → Array Expr → MetaM (Array Expr)
| i, Expr.app f a _, todo =>
condM (ignoreArg a i infos)
(pushArgsAux (i-1) f (todo.push tmpStar))
(pushArgsAux (i-1) f (todo.push a))
| _, _, todo => pure todo
private partial def whnfEta : Expr → MetaM Expr
| e => do
e ← whnf e;
match e.etaExpandedStrict? with
| some e => whnfEta e
| none => pure e
/-
TODO: add a parameter (wildcardConsts : NameSet) to `DiscrTree.insert`.
Then, `DiscrTree` users may control which symbols should be treated as wildcards.
Different `DiscrTree` users may populate this set using, for example, attributes. -/
private def shouldAddAsStar (constName : Name) : Bool :=
constName == `Nat.zero || constName == `Nat.succ || constName == `Nat.add || constName == `HasAdd.add
private def pushArgs (todo : Array Expr) (e : Expr) : MetaM (Key × Array Expr) := do
e ← whnfEta e;
let fn := e.getAppFn;
let push (k : Key) (nargs : Nat) : MetaM (Key × Array Expr) := do {
info ← getFunInfoNArgs fn nargs;
todo ← pushArgsAux info.paramInfo (nargs-1) e todo;
pure (k, todo)
};
match fn with
| Expr.lit v _ => pure (Key.lit v, todo)
| Expr.const c _ _ =>
if shouldAddAsStar c then
pure (Key.star, todo)
else
let nargs := e.getAppNumArgs;
push (Key.const c nargs) nargs
| Expr.fvar fvarId _ => let nargs := e.getAppNumArgs; push (Key.fvar fvarId nargs) nargs
| Expr.mvar mvarId _ =>
if mvarId == tmpMVarId then
-- We use `tmp to mark implicit arguments and proofs
pure (Key.star, todo)
else condM (isReadOnlyOrSyntheticOpaqueExprMVar mvarId)
(pure (Key.other, todo))
(pure (Key.star, todo))
| _ => pure (Key.other, todo)
partial def mkPathAux : Array Expr → Array Key → MetaM (Array Key)
| todo, keys =>
if todo.isEmpty then
pure keys
else do
let e := todo.back;
let todo := todo.pop;
(k, todo) ← pushArgs todo e;
mkPathAux todo (keys.push k)
private def initCapacity := 8
def mkPath (e : Expr) : MetaM (Array Key) :=
withReducible $ do
let todo : Array Expr := Array.mkEmpty initCapacity;
let keys : Array Key := Array.mkEmpty initCapacity;
mkPathAux (todo.push e) keys
private partial def createNodes {α} (keys : Array Key) (v : α) : Nat → Trie α
| i =>
if h : i < keys.size then
let k := keys.get ⟨i, h⟩;
let c := createNodes (i+1);
Trie.node #[] #[(k, c)]
else
Trie.node #[v] #[]
private def insertVal {α} [HasBeq α] (vs : Array α) (v : α) : Array α :=
if vs.contains v then vs else vs.push v
private partial def insertAux {α} [HasBeq α] (keys : Array Key) (v : α) : Nat → Trie α → Trie α
| i, Trie.node vs cs =>
if h : i < keys.size then
let k := keys.get ⟨i, h⟩;
let c := Id.run $ cs.binInsertM
(fun a b => a.1 < b.1)
(fun ⟨_, s⟩ => let c := insertAux (i+1) s; (k, c)) -- merge with existing
(fun _ => let c := createNodes keys v (i+1); (k, c))
(k, arbitrary _);
Trie.node vs c
else
Trie.node (insertVal vs v) cs
def insertCore {α} [HasBeq α] (d : DiscrTree α) (keys : Array Key) (v : α) : DiscrTree α :=
if keys.isEmpty then panic! "invalid key sequence"
else
let k := keys.get! 0;
match d.root.find? k with
| none =>
let c := createNodes keys v 1;
{ root := d.root.insert k c }
| some c =>
let c := insertAux keys v 1 c;
{ root := d.root.insert k c }
def insert {α} [HasBeq α] (d : DiscrTree α) (e : Expr) (v : α) : MetaM (DiscrTree α) := do
keys ← mkPath e;
pure $ d.insertCore keys v
partial def Trie.format {α} [HasFormat α] : Trie α → Format
| Trie.node vs cs => Format.group $ Format.paren $
"node" ++ (if vs.isEmpty then Format.nil else " " ++ fmt vs)
++ Format.join (cs.toList.map $ fun ⟨k, c⟩ => Format.line ++ Format.paren (fmt k ++ " => " ++ Trie.format c))
instance Trie.hasFormat {α} [HasFormat α] : HasFormat (Trie α) := ⟨Trie.format⟩
partial def format {α} [HasFormat α] (d : DiscrTree α) : Format :=
let (_, r) := d.root.foldl
(fun (p : Bool × Format) k c =>
(false, p.2 ++ (if p.1 then Format.nil else Format.line) ++ Format.paren (fmt k ++ " => " ++ fmt c)))
(true, Format.nil);
Format.group r
instance DiscrTree.hasFormat {α} [HasFormat α] : HasFormat (DiscrTree α) := ⟨format⟩
private def getKeyArgs (e : Expr) (isMatch? : Bool) : MetaM (Key × Array Expr) := do
e ← whnfEta e;
match e.getAppFn with
| Expr.lit v _ => pure (Key.lit v, #[])
| Expr.const c _ _ => let nargs := e.getAppNumArgs; pure (Key.const c nargs, e.getAppRevArgs)
| Expr.fvar fvarId _ => let nargs := e.getAppNumArgs; pure (Key.fvar fvarId nargs, e.getAppRevArgs)
| Expr.mvar mvarId _ =>
if isMatch? then pure (Key.other, #[])
else do
ctx ← read;
if ctx.config.isDefEqStuckEx then
/-
When the configuration flag `isDefEqStuckEx` is set to true,
we want `isDefEq` to throw an exception whenever it tries to assign
a read-only metavariable.
This feature is useful for type class resolution where
we may want to notify the caller that the TC problem may be solveable
later after it assigns `?m`.
The method `DiscrTree.getUnify e` returns candidates `c` that may "unify" with `e`.
That is, `isDefEq c e` may return true. Now, consider `DiscrTree.getUnify d (HasAdd ?m)`
where `?m` is a read-only metavariable, and the discrimination tree contains the keys
`HadAdd Nat` and `HasAdd Int`. If `isDefEqStuckEx` is set to true, we must treat `?m` as
a regular metavariable here, otherwise we return the empty set of candidates.
This is incorrect because it is equivalent to saying that there is no solution even if
the caller assigns `?m` and try again. -/
pure (Key.star, #[])
else
condM (isReadOnlyOrSyntheticOpaqueExprMVar mvarId)
(pure (Key.other, #[]))
(pure (Key.star, #[]))
| _ => pure (Key.other, #[])
private abbrev getMatchKeyArgs (e : Expr) : MetaM (Key × Array Expr) :=
getKeyArgs e true
private abbrev getUnifyKeyArgs (e : Expr) : MetaM (Key × Array Expr) :=
getKeyArgs e false
private partial def getMatchAux {α} : Array Expr → Trie α → Array α → MetaM (Array α)
| todo, Trie.node vs cs, result =>
if todo.isEmpty then pure $ result ++ vs
else if cs.isEmpty then pure result
else do
let e := todo.back;
let todo := todo.pop;
let first := cs.get! 0; /- Recall that `Key.star` is the minimal key -/
(k, args) ← getMatchKeyArgs e;
/- We must always visit `Key.star` edges since they are wildcards.
Thus, `todo` is not used linearly when there is `Key.star` edge
and there is an edge for `k` and `k != Key.star`. -/
let visitStarChild (result : Array α) : MetaM (Array α) := if first.1 == Key.star then getMatchAux todo first.2 result else pure result;
match k with
| Key.star => visitStarChild result
| _ =>
match cs.binSearch (k, arbitrary _) (fun a b => a.1 < b.1) with
| none => visitStarChild result
| some c => do result ← visitStarChild result; getMatchAux (todo ++ args) c.2 result
private def getStarResult {α} (d : DiscrTree α) : Array α :=
let result : Array α := Array.mkEmpty initCapacity;
match d.root.find? Key.star with
| none => result
| some (Trie.node vs _) => result ++ vs
def getMatch {α} (d : DiscrTree α) (e : Expr) : MetaM (Array α) :=
withReducible $ do
let result := getStarResult d;
(k, args) ← getMatchKeyArgs e;
match k with
| Key.star => pure result
| _ =>
match d.root.find? k with
| none => pure result
| some c => getMatchAux args c result
private partial def getUnifyAux {α} : Nat → Array Expr → Trie α → (Array α) → MetaM (Array α)
| skip+1, todo, Trie.node vs cs, result =>
if cs.isEmpty then pure result
else cs.foldlM (fun result ⟨k, c⟩ => getUnifyAux (skip + k.arity) todo c result) result
| 0, todo, Trie.node vs cs, result =>
if todo.isEmpty then pure (result ++ vs)
else if cs.isEmpty then pure result
else do
let e := todo.back;
let todo := todo.pop;
(k, args) ← getUnifyKeyArgs e;
match k with
| Key.star => cs.foldlM (fun result ⟨k, c⟩ => getUnifyAux k.arity todo c result) result
| _ =>
let first := cs.get! 0;
let visitStarChild (result : Array α) : MetaM (Array α) :=
if first.1 == Key.star then getUnifyAux 0 todo first.2 result else pure result;
match cs.binSearch (k, arbitrary _) (fun a b => a.1 < b.1) with
| none => visitStarChild result
| some c => do result ← visitStarChild result; getUnifyAux 0 (todo ++ args) c.2 result
def getUnify {α} (d : DiscrTree α) (e : Expr) : MetaM (Array α) :=
withReducible $ do
(k, args) ← getUnifyKeyArgs e;
match k with
| Key.star => d.root.foldlM (fun result k c => getUnifyAux k.arity #[] c result) #[]
| _ =>
let result := getStarResult d;
match d.root.find? k with
| none => pure result
| some c => getUnifyAux 0 args c result
end DiscrTree
end Meta
end Lean
|
774b6239ad03dccfe343a976a8c9cf3804812e78 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/cases_bug3.lean | c61fbe0a6a1a42cc379bbbb76a39cbdb987dfa1b | [
"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 | 97 | lean | theorem ex {A : Type} : ∀ {a a' : A}, a == a' → a = a'
| a .(a) (heq.refl .(a)) := eq.refl a
|
f81176181092409fcc97fc9da14076bbc7f9bee1 | b794ca1df49bc5a3bd3fd5552eed3bc4f63b8b93 | /src/homework/practice_1.lean | 1c2ab5c3755d79dfed12a6b30ea60e69128a8456 | [] | no_license | akraisinger/cs2120f21 | 8235ac98375e04ffcec504cff5cab7833ee69e54 | 4ef83d7151bb6a284028092aa4f1d509c0eb8237 | refs/heads/main | 1,691,714,771,612 | 1,632,889,465,000 | 1,632,889,465,000 | 399,946,508 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,471 | lean | /-
EQUALITY
-/
/- #1
Suppose that x, y, z, and w are arbitrary objects of some type,
T; and suppose further that we know (have proofs of the facts)
that x = y, y = z, and w = z. Give a very, very short English
proof of the conjecture that z = w. You can use not only the
axioms of equality, but either of the theorems about properties
of equality that we have proven. Hint: There's something about
this question that makes it much easier to answer than it might
at first appear.
-/
/- #2
Give a formal statement of the conjecture (proposition) from
#1 by filling in the "hole" in the following definition. The
def is a keyword. The name you're binding to your proposition
is prop_1. The type of the value is Prop (which is the type of
all propositions in Lean).
-/
def prop_1 : Prop :=
_
/- #3 (extra credit)
Give a formal proof of the proposition from #2 by filling in
the hole in this next definition. Hint: Use Lean's versions of
the axioms and basic theorems concerning equality. They are,
again, called eq.refl, eq.subst, eq.symm, eq.trans.
-/
theorem prop_1_proof : prop_1 :=
begin
_
end
/-
FOR ALL: ∀.
-/
/- #4
Give a very brief explanation in English of the introduction
rule for ∀. For example, suppose you need to prove (∀ x, P x);
what do you do? (I'm being a little informal in leaving out the
type of X.)
-/
/- #5
Suppose you have a proof, let's call it pf, of the proposition,
(∀ x, P x), and you need a proof of P t, for some particular t.
Write an expression then uses the elimination rule for ∀ to get
such a proof. Complete the answer by replacing the underscores
in the following expression: ( _ _ ).
-/
/-
IMPLIES: →
In the "code" that follows, we define two predicates, each
taking one natural number as an argument. We call them ev and
odd. When applied to any value, n, ev yields the proposition
that n is even (n % 2 = 0), while odd yields the proposition
that n is odd (n % 2 = 1).
-/
def ev (n : ℕ) := n % 2 = 0
def odd (n : ℕ) := n % 2 = 1
/- #6
Write a formal version of the proposition that, for *any*
natural number n, *if* n is even, *then* n + 1 is odd. Give
your answer by filling the hole in the following definition.
Hint: put parenthesis around "n + 1" in your answer.
-/
def successor_of_even_is_odd : Prop :=
_
/- #7
Suppose that "its_raining" and "the_streets_are_wet" are
propositions. (We formalize these assumptions as axioms in
what follows. Then give a formal definition of the (larger)
proposition, "if it's raining out then the streets are wet")
by filling in the hole
-/
axioms (raining streets_wet : Prop)
axiom if_raining_then_streets_wet : _
/- #9
Now suppose that in addition, its_raining is true, and
we have a proof of it, pf_its_raining. Again, we again give
you this assumption formally as an axiom below. Finish
the formal proof that the streets must be wet. Hint: here
you are asked to use the elimination rule for →.
-/
axiom pf_raining : raining
example : streets_wet :=
_
/-
AND: ∧
-/
/- #10
In our last class, we proved that "∧ is *commutative*."
That is, for any given *propositions*, P and Q, (P ∧ Q) →
(Q ∧ P). The way we proved it was to *assume* that we're
given such a P, Q, and proof, pq, of (P ∧ Q) -- applying
the introduction rules for ∀ and →). In this context, we
*use* the proof, pq, to derive separate proofs, let's call
them p, a proof of P, and q, a proof of Q. With these in
hand, we then apply the introduction rule for ∧ to put
them back together into a proof of (Q ∧ P). We give you
a formal version of this proof as a reminder, next.
-/
theorem and_commutative : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=
begin
assume P Q pq,
apply and.intro _ _,
exact (and.elim_right pq),
exact (and.elim_left pq),
end
/-
Your task now is to prove the theorem, "∧ is *associative*."
What this means is that for arbitrary propositions, P, Q, and
R, if (P ∧ (Q ∧ R)) is true, then ((P ∧ Q) ∧ R) is true, *and
vice versa*. You just need to prove it in the first direction.
Hint, if you have a proof, p_qr, of (P ∧ (Q ∧ R)), then the
application of and.elim_left will give you a proof of P, and
and.elim_right will give you a proof of (Q ∧ R).
To help you along, we give you the first part of the proof,
including an example of a new Lean tactic called have, which
allows you to give a name to a new value in the middle of a
proof script.
-/
theorem and_associative :
∀ (P Q R : Prop),
(P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) :=
begin
intros P Q R h,
have p : P := and.elim_left h,
end
/- #11
Give an English language proof of the preceding
theorem. Do it by finishing off the following
partial "proof explanation."
Proof. We assume that P, Q, and R are arbitrary
but specific propositions, and that we have a
proof, let's call it p_qr, of (P ∧ (Q ∧ R)) [by
application of ∧ and → introduction.] What now
remains to be proved is ((P ∧ Q) ∧ R). We can
construct a proof of this proposition by applying
_____ to a proof of (P ∧ Q) and a proof of R.
What remains, then, is to obtain these proofs.
But this is easily done by the application of
____ to ____. QED.
-/
/-
Note that Lean includes versions of these
theorems (and many, many, many others) in
its extensive library of formalized maths,
as the following check commands reveal.
Note the difference in naming relative to
the definitions we give in this file.
-/
#check @and.comm
#check @and.assoc |
cbde158a85bbce93c39e84bbacd99e175c4720d0 | 618003631150032a5676f229d13a079ac875ff77 | /src/tactic/omega/nat/neg_elim.lean | d827e916f3d568778ecf7cf66e864042b9a00848 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 4,191 | lean | /- Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
Negation elimination. -/
import tactic.omega.nat.form
namespace omega
namespace nat
open_locale omega.nat
/-- push_neg p returns the result of normalizing ¬ p by
pushing the outermost negation all the way down,
until it reaches either a negation or an atom -/
@[simp] def push_neg : preform → preform
| (p ∨* q) := (push_neg p) ∧* (push_neg q)
| (p ∧* q) := (push_neg p) ∨* (push_neg q)
| (¬*p) := p
| p := ¬* p
lemma push_neg_equiv :
∀ {p : preform}, preform.equiv (push_neg p) (¬* p) :=
begin
preform.induce `[intros v; try {refl}],
{ simp only [classical.not_not, preform.holds, push_neg] },
{ simp only [preform.holds, push_neg, not_or_distrib, ihp v, ihq v] },
{ simp only [preform.holds, push_neg, classical.not_and_distrib, ihp v, ihq v] }
end
/-- NNF transformation -/
def nnf : preform → preform
| (¬* p) := push_neg (nnf p)
| (p ∨* q) := (nnf p) ∨* (nnf q)
| (p ∧* q) := (nnf p) ∧* (nnf q)
| a := a
/-- Asserts that the given preform is in NNF -/
def is_nnf : preform → Prop
| (t =* s) := true
| (t ≤* s) := true
| ¬*(t =* s) := true
| ¬*(t ≤* s) := true
| (p ∨* q) := is_nnf p ∧ is_nnf q
| (p ∧* q) := is_nnf p ∧ is_nnf q
| _ := false
lemma is_nnf_push_neg : ∀ p : preform, is_nnf p → is_nnf (push_neg p) :=
begin
preform.induce `[intro h1; try {trivial}],
{ cases p; try {cases h1}; trivial },
{ cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption },
{ cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }
end
lemma is_nnf_nnf : ∀ p : preform, is_nnf (nnf p) :=
begin
preform.induce `[try {trivial}],
{ apply is_nnf_push_neg _ ih },
{ constructor; assumption },
{ constructor; assumption }
end
lemma nnf_equiv : ∀ {p : preform}, preform.equiv (nnf p) p :=
begin
preform.induce `[intros v; try {refl}; simp only [nnf]],
{ rw push_neg_equiv,
apply not_iff_not_of_iff, apply ih },
{ apply pred_mono_2' (ihp v) (ihq v) },
{ apply pred_mono_2' (ihp v) (ihq v) }
end
@[simp] def neg_elim_core : preform → preform
| (¬* (t =* s)) := (t.add_one ≤* s) ∨* (s.add_one ≤* t)
| (¬* (t ≤* s)) := s.add_one ≤* t
| (p ∨* q) := (neg_elim_core p) ∨* (neg_elim_core q)
| (p ∧* q) := (neg_elim_core p) ∧* (neg_elim_core q)
| p := p
lemma neg_free_neg_elim_core : ∀ p, is_nnf p → (neg_elim_core p).neg_free :=
begin
preform.induce `[intro h1, try {simp only [neg_free, neg_elim_core]}, try {trivial}],
{ cases p; try {cases h1}; try {trivial},
constructor; trivial },
{ cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption },
{ cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }
end
lemma le_and_le_iff_eq {α : Type} [partial_order α] {a b : α} :
(a ≤ b ∧ b ≤ a) ↔ a = b :=
begin
constructor; intro h1,
{ cases h1, apply le_antisymm; assumption },
{ constructor; apply le_of_eq; rw h1 }
end
lemma implies_neg_elim_core : ∀ {p : preform},
preform.implies p (neg_elim_core p) :=
begin
preform.induce `[intros v h, try {apply h}],
{ cases p with t s t s; try {apply h},
{ have : preterm.val v (preterm.add_one t) ≤ preterm.val v s ∨
preterm.val v (preterm.add_one s) ≤ preterm.val v t,
{ rw or.comm,
simpa only [preform.holds, le_and_le_iff_eq.symm,
classical.not_and_distrib, not_le] using h },
simpa only [form.holds, neg_elim_core, int.add_one_le_iff] },
simpa only [preform.holds, not_le, int.add_one_le_iff] using h },
{ simp only [neg_elim_core], cases h;
[{left, apply ihp}, {right, apply ihq}];
assumption },
apply and.imp (ihp _) (ihq _) h
end
/-- Eliminate all negations in a preform -/
def neg_elim : preform → preform := neg_elim_core ∘ nnf
lemma neg_free_neg_elim {p : preform} : (neg_elim p).neg_free :=
neg_free_neg_elim_core _ (is_nnf_nnf _)
lemma implies_neg_elim {p : preform} : preform.implies p (neg_elim p) :=
begin
intros v h1, apply implies_neg_elim_core,
apply (nnf_equiv v).elim_right h1
end
end nat
end omega
|
41614669e35123a9dd440ddf82467e79b88cd5bd | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/ring_theory/polynomial/tower.lean | e62b87ba0803ebcbfef7e03abc862e0ae326a5fb | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,594 | 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.algebra.tower
import data.polynomial.algebra_map
/-!
# Algebra towers for polynomial
This file proves some basic results about the algebra tower structure for the type `polynomial R`.
This structure itself is provided elsewhere as `polynomial.is_scalar_tower`
-/
universes u v w u₁
variables (R : Type u) (S : Type v) (A : Type w) (B : Type u₁)
namespace is_scalar_tower
section semiring
variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B]
variables [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B]
variables [is_scalar_tower R S A] [is_scalar_tower R S B]
variables (R S A) {B}
theorem aeval_apply (x : A) (p : polynomial R) : polynomial.aeval x p =
polynomial.aeval x (polynomial.map (algebra_map R S) p) :=
by rw [polynomial.aeval_def, polynomial.aeval_def, polynomial.eval₂_map, algebra_map_eq R S A]
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A] [comm_semiring B]
variables [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B]
lemma algebra_map_aeval (x : A) (p : polynomial R) :
algebra_map A B (polynomial.aeval x p) = polynomial.aeval (algebra_map A B x) p :=
by rw [polynomial.aeval_def, polynomial.aeval_def, polynomial.hom_eval₂,
←is_scalar_tower.algebra_map_eq]
lemma aeval_eq_zero_of_aeval_algebra_map_eq_zero {x : A} {p : polynomial R}
(h : function.injective (algebra_map A B)) (hp : polynomial.aeval (algebra_map A B x) p = 0) :
polynomial.aeval x p = 0 :=
begin
rw [← algebra_map_aeval, ← (algebra_map A B).map_zero] at hp,
exact h hp,
end
lemma aeval_eq_zero_of_aeval_algebra_map_eq_zero_field {R A B : Type*} [comm_semiring R] [field A]
[comm_semiring B] [nontrivial B] [algebra R A] [algebra R B] [algebra A B] [is_scalar_tower R A B]
{x : A} {p : polynomial R} (h : polynomial.aeval (algebra_map A B x) p = 0) :
polynomial.aeval x p = 0 :=
aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B (algebra_map A B).injective h
end comm_semiring
end is_scalar_tower
namespace subalgebra
open is_scalar_tower
section comm_semiring
variables (R) {S A} [comm_semiring R] [comm_semiring S] [comm_semiring A]
variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A]
@[simp] lemma aeval_coe {S : subalgebra R A} {x : S} {p : polynomial R} :
polynomial.aeval (x : A) p = polynomial.aeval x p :=
(algebra_map_aeval R S A x p).symm
end comm_semiring
end subalgebra
|
d1eb7f47cf56747b57ad46be003411032c4950d0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/ring_theory/polynomial/dickson.lean | c6cb3c157b10882da4ed0779f52c96ecb11d9ab9 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 10,754 | lean | /-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import algebra.char_p.invertible
import data.zmod.basic
import ring_theory.localization.fraction_ring
import ring_theory.polynomial.chebyshev
import ring_theory.ideal.local_ring
/-!
# Dickson polynomials
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`,
with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the
they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)`
with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature,
`dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the
parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`.
When `a=0` they are just the family of monomials `X ^ n`.
## Main definition
* `polynomial.dickson`: the generalised Dickson polynomials.
## Main statements
* `polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for
parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first
kind for `1 : R`.
* `polynomial.dickson_one_one_char_p`, for a prime number `p`, the `p`-th Dickson polynomial of the
first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`.
## References
* [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403]
## TODO
* Redefine `dickson` in terms of `linear_recurrence`.
* Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a
type A Dynkin diagram.
* Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency
matrices of simple connected graphs which annihilate `dickson 2 1`.
-/
noncomputable theory
namespace polynomial
open_locale polynomial
variables {R S : Type*} [comm_ring R] [comm_ring S] (k : ℕ) (a : R)
/-- `dickson` is the `n`the (generalised) Dickson polynomial of the `k`-th kind associated to the
element `a ∈ R`. -/
noncomputable def dickson : ℕ → R[X]
| 0 := 3 - k
| 1 := X
| (n + 2) := X * dickson (n + 1) - (C a) * dickson n
@[simp] lemma dickson_zero : dickson k a 0 = 3 - k := rfl
@[simp] lemma dickson_one : dickson k a 1 = X := rfl
lemma dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k) :=
by simp only [dickson, sq]
@[simp] lemma dickson_add_two (n : ℕ) :
dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n :=
by rw dickson
lemma dickson_of_two_le {n : ℕ} (h : 2 ≤ n) :
dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) :=
begin
obtain ⟨n, rfl⟩ := nat.exists_eq_add_of_le h,
rw add_comm,
exact dickson_add_two k a n
end
variables {R S k a}
lemma map_dickson (f : R →+* S) :
∀ (n : ℕ), map f (dickson k a n) = dickson k (f a) n
| 0 := by simp only [dickson_zero, polynomial.map_sub, polynomial.map_nat_cast,
bit1, bit0, polynomial.map_add, polynomial.map_one]
| 1 := by simp only [dickson_one, map_X]
| (n + 2) :=
begin
simp only [dickson_add_two, polynomial.map_sub, polynomial.map_mul, map_X, map_C],
rw [map_dickson, map_dickson]
end
variable {R}
@[simp] lemma dickson_two_zero :
∀ (n : ℕ), dickson 2 (0 : R) n = X ^ n
| 0 := by { simp only [dickson_zero, pow_zero], norm_num }
| 1 := by simp only [dickson_one, pow_one]
| (n + 2) :=
begin
simp only [dickson_add_two, C_0, zero_mul, sub_zero],
rw [dickson_two_zero, pow_add X (n + 1) 1, mul_comm, pow_one]
end
section dickson
/-!
### A Lambda structure on `ℤ[X]`
Mathlib doesn't currently know what a Lambda ring is.
But once it does, we can endow `ℤ[X]` with a Lambda structure
in terms of the `dickson 1 1` polynomials defined below.
There is exactly one other Lambda structure on `ℤ[X]` in terms of binomial polynomials.
-/
variables {R}
lemma dickson_one_one_eval_add_inv (x y : R) (h : x * y = 1) :
∀ n, (dickson 1 (1 : R) n).eval (x + y) = x ^ n + y ^ n
| 0 := by { simp only [bit0, eval_one, eval_add, pow_zero, dickson_zero], norm_num }
| 1 := by simp only [eval_X, dickson_one, pow_one]
| (n + 2) :=
begin
simp only [eval_sub, eval_mul, dickson_one_one_eval_add_inv, eval_X, dickson_add_two, C_1,
eval_one],
conv_lhs { simp only [pow_succ, add_mul, mul_add, h, ← mul_assoc, mul_comm y x, one_mul] },
ring_exp
end
variables (R)
lemma dickson_one_one_eq_chebyshev_T [invertible (2 : R)] :
∀ n, dickson 1 (1 : R) n = 2 * (chebyshev.T R n).comp (C (⅟2) * X)
| 0 := by { simp only [chebyshev.T_zero, mul_one, one_comp, dickson_zero], norm_num }
| 1 := by rw [dickson_one, chebyshev.T_one, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul,
mul_inv_of_self, C_1, one_mul]
| (n + 2) :=
begin
simp only [dickson_add_two, chebyshev.T_add_two, dickson_one_one_eq_chebyshev_T (n + 1),
dickson_one_one_eq_chebyshev_T n, sub_comp, mul_comp, add_comp, X_comp, bit0_comp, one_comp],
simp only [← C_1, ← C_bit0, ← mul_assoc, ← C_mul, mul_inv_of_self],
rw [C_1, one_mul],
ring
end
lemma chebyshev_T_eq_dickson_one_one [invertible (2 : R)] (n : ℕ) :
chebyshev.T R n = C (⅟2) * (dickson 1 1 n).comp (2 * X) :=
begin
rw dickson_one_one_eq_chebyshev_T,
simp only [comp_assoc, mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul],
rw [inv_of_mul_self, C_1, one_mul, one_mul, comp_X]
end
/-- The `(m * n)`-th Dickson polynomial of the first kind is the composition of the `m`-th and
`n`-th. -/
lemma dickson_one_one_mul (m n : ℕ) :
dickson 1 (1 : R) (m * n) = (dickson 1 1 m).comp (dickson 1 1 n) :=
begin
have h : (1 : R) = int.cast_ring_hom R (1),
simp only [eq_int_cast, int.cast_one],
rw h,
simp only [← map_dickson (int.cast_ring_hom R), ← map_comp],
congr' 1,
apply map_injective (int.cast_ring_hom ℚ) int.cast_injective,
simp only [map_dickson, map_comp, eq_int_cast, int.cast_one,
dickson_one_one_eq_chebyshev_T, chebyshev.T_mul, two_mul, ← add_comp],
simp only [← two_mul, ← comp_assoc],
apply eval₂_congr rfl rfl,
rw [comp_assoc],
apply eval₂_congr rfl _ rfl,
rw [mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul,
inv_of_mul_self, C_1, one_mul]
end
lemma dickson_one_one_comp_comm (m n : ℕ) :
(dickson 1 (1 : R) m).comp (dickson 1 1 n) = (dickson 1 1 n).comp (dickson 1 1 m) :=
by rw [← dickson_one_one_mul, mul_comm, dickson_one_one_mul]
lemma dickson_one_one_zmod_p (p : ℕ) [fact p.prime] :
dickson 1 (1 : zmod p) p = X ^ p :=
begin
-- Recall that `dickson_eval_add_inv` characterises `dickson 1 1 p`
-- as a polynomial that maps `x + x⁻¹` to `x ^ p + (x⁻¹) ^ p`.
-- Since `X ^ p` also satisfies this property in characteristic `p`,
-- we can use a variant on `polynomial.funext` to conclude that these polynomials are equal.
-- For this argument, we need an arbitrary infinite field of characteristic `p`.
obtain ⟨K, _, _, H⟩ : ∃ (K : Type) (_ : field K), by exactI ∃ (_ : char_p K p), infinite K,
{ let K := fraction_ring (polynomial (zmod p)),
let f : zmod p →+* K := (algebra_map _ (fraction_ring _)).comp C,
haveI : char_p K p, { rw ← f.char_p_iff_char_p, apply_instance },
haveI : infinite K :=
infinite.of_injective (algebra_map (polynomial (zmod p)) (fraction_ring (polynomial (zmod p))))
(is_fraction_ring.injective _ _),
refine ⟨K, _, _, _⟩; apply_instance },
resetI,
apply map_injective (zmod.cast_hom (dvd_refl p) K) (ring_hom.injective _),
rw [map_dickson, polynomial.map_pow, map_X],
apply eq_of_infinite_eval_eq,
-- The two polynomials agree on all `x` of the form `x = y + y⁻¹`.
apply @set.infinite.mono _ {x : K | ∃ y, x = y + y⁻¹ ∧ y ≠ 0},
{ rintro _ ⟨x, rfl, hx⟩,
simp only [eval_X, eval_pow, set.mem_set_of_eq, @add_pow_char K _ p,
dickson_one_one_eval_add_inv _ _ (mul_inv_cancel hx), inv_pow, zmod.cast_hom_apply,
zmod.cast_one'] },
-- Now we need to show that the set of such `x` is infinite.
-- If the set is finite, then we will show that `K` is also finite.
{ intro h,
rw ← set.infinite_univ_iff at H,
apply H,
-- To each `x` of the form `x = y + y⁻¹`
-- we `bind` the set of `y` that solve the equation `x = y + y⁻¹`.
-- For every `x`, that set is finite (since it is governed by a quadratic equation).
-- For the moment, we claim that all these sets together cover `K`.
suffices : (set.univ : set K) =
{x : K | ∃ (y : K), x = y + y⁻¹ ∧ y ≠ 0} >>= (λ x, {y | x = y + y⁻¹ ∨ y = 0}),
{ rw this, clear this,
refine h.bUnion (λ x hx, _),
-- The following quadratic polynomial has as solutions the `y` for which `x = y + y⁻¹`.
let φ : K[X] := X ^ 2 - C x * X + 1,
have hφ : φ ≠ 0,
{ intro H,
have : φ.eval 0 = 0, by rw [H, eval_zero],
simpa [eval_X, eval_one, eval_pow, eval_sub, sub_zero, eval_add,
eval_mul, mul_zero, sq, zero_add, one_ne_zero] },
classical,
convert (φ.roots ∪ {0}).to_finset.finite_to_set using 1,
ext1 y,
simp only [multiset.mem_to_finset, set.mem_set_of_eq, finset.mem_coe, multiset.mem_union,
mem_roots hφ, is_root, eval_add, eval_sub, eval_pow, eval_mul, eval_X, eval_C, eval_one,
multiset.mem_singleton],
by_cases hy : y = 0,
{ simp only [hy, eq_self_iff_true, or_true] },
apply or_congr _ iff.rfl,
rw [← mul_left_inj' hy, eq_comm, ← sub_eq_zero, add_mul, inv_mul_cancel hy],
apply eq_iff_eq_cancel_right.mpr,
ring },
-- Finally, we prove the claim that our finite union of finite sets covers all of `K`.
{ apply (set.eq_univ_of_forall _).symm,
intro x,
simp only [exists_prop, set.mem_Union, set.bind_def, ne.def, set.mem_set_of_eq],
by_cases hx : x = 0,
{ simp only [hx, and_true, eq_self_iff_true, inv_zero, or_true],
exact ⟨_, 1, rfl, one_ne_zero⟩ },
{ simp only [hx, or_false, exists_eq_right],
exact ⟨_, rfl, hx⟩ } } }
end
lemma dickson_one_one_char_p (p : ℕ) [fact p.prime] [char_p R p] :
dickson 1 (1 : R) p = X ^ p :=
begin
have h : (1 : R) = zmod.cast_hom (dvd_refl p) R (1),
simp only [zmod.cast_hom_apply, zmod.cast_one'],
rw [h, ← map_dickson (zmod.cast_hom (dvd_refl p) R), dickson_one_one_zmod_p,
polynomial.map_pow, map_X]
end
end dickson
end polynomial
|
d036006f9340ca23b89059ac6410023d17616990 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/local_homeomorph_auto.lean | 41c33c019d05524546cbb6d2a3d3406f6133fe98 | [] | 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 | 55,936 | lean | /-
Copyright (c) 2019 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.equiv.local_equiv
import Mathlib.topology.opens
import Mathlib.PostPort
universes u_5 u_6 l u_1 u_2 u_3 u_4
namespace Mathlib
/-!
# Local homeomorphisms
This file defines homeomorphisms between open subsets of topological spaces. An element `e` of
`local_homeomorph α β` is an extension of `local_equiv α β`, i.e., it is a pair of functions
`e.to_fun` and `e.inv_fun`, inverse of each other on the sets `e.source` and `e.target`.
Additionally, we require that these sets are open, and that the functions are continuous on them.
Equivalently, they are homeomorphisms there.
As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout
instead of `e.to_fun x` and `e.inv_fun x`.
## Main definitions
`homeomorph.to_local_homeomorph`: associating a local homeomorphism to a homeomorphism, with
source = target = univ
`local_homeomorph.symm` : the inverse of a local homeomorphism
`local_homeomorph.trans` : the composition of two local homeomorphisms
`local_homeomorph.refl` : the identity local homeomorphism
`local_homeomorph.of_set`: the identity on a set `s`
`eq_on_source` : equivalence relation describing the "right" notion of equality for local
homeomorphisms
## Implementation notes
Most statements are copied from their local_equiv versions, although some care is required
especially when restricting to subsets, as these should be open subsets.
For design notes, see `local_equiv.lean`.
-/
/-- local homeomorphisms, defined on open subsets of the space -/
structure local_homeomorph (α : Type u_5) (β : Type u_6) [topological_space α] [topological_space β]
extends local_equiv α β where
open_source : is_open (local_equiv.source _to_local_equiv)
open_target : is_open (local_equiv.target _to_local_equiv)
continuous_to_fun :
continuous_on (local_equiv.to_fun _to_local_equiv) (local_equiv.source _to_local_equiv)
continuous_inv_fun :
continuous_on (local_equiv.inv_fun _to_local_equiv) (local_equiv.target _to_local_equiv)
/-- A homeomorphism induces a local homeomorphism on the whole space -/
def homeomorph.to_local_homeomorph {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) : local_homeomorph α β :=
local_homeomorph.mk
(local_equiv.mk (local_equiv.to_fun (equiv.to_local_equiv (homeomorph.to_equiv e)))
(local_equiv.inv_fun (equiv.to_local_equiv (homeomorph.to_equiv e)))
(local_equiv.source (equiv.to_local_equiv (homeomorph.to_equiv e)))
(local_equiv.target (equiv.to_local_equiv (homeomorph.to_equiv e))) sorry sorry sorry sorry)
is_open_univ is_open_univ sorry sorry
namespace local_homeomorph
protected instance has_coe_to_fun {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] : has_coe_to_fun (local_homeomorph α β) :=
has_coe_to_fun.mk (fun (e : local_homeomorph α β) => α → β)
fun (e : local_homeomorph α β) => local_equiv.to_fun (to_local_equiv e)
/-- The inverse of a local homeomorphism -/
protected def symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : local_homeomorph β α :=
mk
(local_equiv.mk (local_equiv.to_fun (local_equiv.symm (to_local_equiv e)))
(local_equiv.inv_fun (local_equiv.symm (to_local_equiv e)))
(local_equiv.source (local_equiv.symm (to_local_equiv e)))
(local_equiv.target (local_equiv.symm (to_local_equiv e))) sorry sorry sorry sorry)
(open_target e) (open_source e) (continuous_inv_fun e) (continuous_to_fun e)
protected theorem continuous_on {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) :
continuous_on (⇑e) (local_equiv.source (to_local_equiv e)) :=
continuous_to_fun e
theorem continuous_on_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) :
continuous_on (⇑(local_homeomorph.symm e)) (local_equiv.target (to_local_equiv e)) :=
continuous_inv_fun e
@[simp] theorem mk_coe {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_equiv α β) (a : is_open (local_equiv.source e)) (b : is_open (local_equiv.target e))
(c : continuous_on (local_equiv.to_fun e) (local_equiv.source e))
(d : continuous_on (local_equiv.inv_fun e) (local_equiv.target e)) : ⇑(mk e a b c d) = ⇑e :=
rfl
@[simp] theorem mk_coe_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_equiv α β) (a : is_open (local_equiv.source e))
(b : is_open (local_equiv.target e))
(c : continuous_on (local_equiv.to_fun e) (local_equiv.source e))
(d : continuous_on (local_equiv.inv_fun e) (local_equiv.target e)) :
⇑(local_homeomorph.symm (mk e a b c d)) = ⇑(local_equiv.symm e) :=
rfl
/- Register a few simp lemmas to make sure that `simp` puts the application of a local
homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/
@[simp] theorem to_fun_eq_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) : local_equiv.to_fun (to_local_equiv e) = ⇑e :=
rfl
@[simp] theorem inv_fun_eq_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) :
local_equiv.inv_fun (to_local_equiv e) = ⇑(local_homeomorph.symm e) :=
rfl
@[simp] theorem coe_coe {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : ⇑(to_local_equiv e) = ⇑e :=
rfl
@[simp] theorem coe_coe_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) :
⇑(local_equiv.symm (to_local_equiv e)) = ⇑(local_homeomorph.symm e) :=
rfl
@[simp] theorem map_source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : α} (h : x ∈ local_equiv.source (to_local_equiv e)) :
coe_fn e x ∈ local_equiv.target (to_local_equiv e) :=
local_equiv.map_source' (to_local_equiv e) h
@[simp] theorem map_target {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : β} (h : x ∈ local_equiv.target (to_local_equiv e)) :
coe_fn (local_homeomorph.symm e) x ∈ local_equiv.source (to_local_equiv e) :=
local_equiv.map_target' (to_local_equiv e) h
@[simp] theorem left_inv {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : α} (h : x ∈ local_equiv.source (to_local_equiv e)) :
coe_fn (local_homeomorph.symm e) (coe_fn e x) = x :=
local_equiv.left_inv' (to_local_equiv e) h
@[simp] theorem right_inv {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : β} (h : x ∈ local_equiv.target (to_local_equiv e)) :
coe_fn e (coe_fn (local_homeomorph.symm e) x) = x :=
local_equiv.right_inv' (to_local_equiv e) h
theorem source_preimage_target {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) :
local_equiv.source (to_local_equiv e) ⊆ ⇑e ⁻¹' local_equiv.target (to_local_equiv e) :=
fun (_x : α) (h : _x ∈ local_equiv.source (to_local_equiv e)) => map_source e h
theorem eq_of_local_equiv_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {e' : local_homeomorph α β}
(h : to_local_equiv e = to_local_equiv e') : e = e' :=
sorry
theorem eventually_left_inverse {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : α}
(hx : x ∈ local_equiv.source (to_local_equiv e)) :
filter.eventually (fun (y : α) => coe_fn (local_homeomorph.symm e) (coe_fn e y) = y) (nhds x) :=
filter.eventually.mono (is_open.eventually_mem (open_source e) hx)
(local_equiv.left_inv' (to_local_equiv e))
theorem eventually_left_inverse' {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : β}
(hx : x ∈ local_equiv.target (to_local_equiv e)) :
filter.eventually (fun (y : α) => coe_fn (local_homeomorph.symm e) (coe_fn e y) = y)
(nhds (coe_fn (local_homeomorph.symm e) x)) :=
eventually_left_inverse e (map_target e hx)
theorem eventually_right_inverse {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : β}
(hx : x ∈ local_equiv.target (to_local_equiv e)) :
filter.eventually (fun (y : β) => coe_fn e (coe_fn (local_homeomorph.symm e) y) = y) (nhds x) :=
filter.eventually.mono (is_open.eventually_mem (open_target e) hx)
(local_equiv.right_inv' (to_local_equiv e))
theorem eventually_right_inverse' {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : α}
(hx : x ∈ local_equiv.source (to_local_equiv e)) :
filter.eventually (fun (y : β) => coe_fn e (coe_fn (local_homeomorph.symm e) y) = y)
(nhds (coe_fn e x)) :=
eventually_right_inverse e (map_source e hx)
theorem eventually_ne_nhds_within {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : α}
(hx : x ∈ local_equiv.source (to_local_equiv e)) :
filter.eventually (fun (x' : α) => coe_fn e x' ≠ coe_fn e x) (nhds_within x (singleton xᶜ)) :=
sorry
theorem image_eq_target_inter_inv_preimage {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {s : set α}
(h : s ⊆ local_equiv.source (to_local_equiv e)) :
⇑e '' s = local_equiv.target (to_local_equiv e) ∩ ⇑(local_homeomorph.symm e) ⁻¹' s :=
local_equiv.image_eq_target_inter_inv_preimage (to_local_equiv e) h
theorem image_inter_source_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set α) :
⇑e '' (s ∩ local_equiv.source (to_local_equiv e)) =
local_equiv.target (to_local_equiv e) ∩
⇑(local_homeomorph.symm e) ⁻¹' (s ∩ local_equiv.source (to_local_equiv e)) :=
image_eq_target_inter_inv_preimage e
(set.inter_subset_right s (local_equiv.source (to_local_equiv e)))
theorem symm_image_eq_source_inter_preimage {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {s : set β}
(h : s ⊆ local_equiv.target (to_local_equiv e)) :
⇑(local_homeomorph.symm e) '' s = local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' s :=
image_eq_target_inter_inv_preimage (local_homeomorph.symm e) h
theorem symm_image_inter_target_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set β) :
⇑(local_homeomorph.symm e) '' (s ∩ local_equiv.target (to_local_equiv e)) =
local_equiv.source (to_local_equiv e) ∩
⇑e ⁻¹' (s ∩ local_equiv.target (to_local_equiv e)) :=
image_inter_source_eq (local_homeomorph.symm e) s
/-- Two local homeomorphisms are equal when they have equal `to_fun`, `inv_fun` and `source`.
It is not sufficient to have equal `to_fun` and `source`, as this only determines `inv_fun` on
the target. This would only be true for a weaker notion of equality, arguably the right one,
called `eq_on_source`. -/
protected theorem ext {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (e' : local_homeomorph α β) (h : ∀ (x : α), coe_fn e x = coe_fn e' x)
(hinv : ∀ (x : β), coe_fn (local_homeomorph.symm e) x = coe_fn (local_homeomorph.symm e') x)
(hs : local_equiv.source (to_local_equiv e) = local_equiv.source (to_local_equiv e')) :
e = e' :=
eq_of_local_equiv_eq (local_equiv.ext h hinv hs)
-- The following lemmas are already simp via local_equiv
@[simp] theorem symm_to_local_equiv {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) :
to_local_equiv (local_homeomorph.symm e) = local_equiv.symm (to_local_equiv e) :=
rfl
theorem symm_source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) :
local_equiv.source (to_local_equiv (local_homeomorph.symm e)) =
local_equiv.target (to_local_equiv e) :=
rfl
theorem symm_target {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) :
local_equiv.target (to_local_equiv (local_homeomorph.symm e)) =
local_equiv.source (to_local_equiv e) :=
rfl
@[simp] theorem symm_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : local_homeomorph.symm (local_homeomorph.symm e) = e :=
sorry
/-- A local homeomorphism is continuous at any point of its source -/
protected theorem continuous_at {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {x : α}
(h : x ∈ local_equiv.source (to_local_equiv e)) : continuous_at (⇑e) x :=
continuous_within_at.continuous_at (local_homeomorph.continuous_on e x h)
(mem_nhds_sets (open_source e) h)
/-- A local homeomorphism inverse is continuous at any point of its target -/
theorem continuous_at_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : β} (h : x ∈ local_equiv.target (to_local_equiv e)) :
continuous_at (⇑(local_homeomorph.symm e)) x :=
local_homeomorph.continuous_at (local_homeomorph.symm e) h
theorem tendsto_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : α} (hx : x ∈ local_equiv.source (to_local_equiv e)) :
filter.tendsto (⇑(local_homeomorph.symm e)) (nhds (coe_fn e x)) (nhds x) :=
sorry
theorem map_nhds_eq {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {x : α} (hx : x ∈ local_equiv.source (to_local_equiv e)) :
filter.map (⇑e) (nhds x) = nhds (coe_fn e x) :=
le_antisymm (local_homeomorph.continuous_at e hx)
(filter.le_map_of_right_inverse (eventually_right_inverse' e hx) (tendsto_symm e hx))
/-- Preimage of interior or interior of preimage coincide for local homeomorphisms, when restricted
to the source. -/
theorem preimage_interior {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set β) :
local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' interior s =
local_equiv.source (to_local_equiv e) ∩ interior (⇑e ⁻¹' s) :=
sorry
theorem preimage_open_of_open {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {s : set β} (hs : is_open s) :
is_open (local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' s) :=
continuous_on.preimage_open_of_open (local_homeomorph.continuous_on e) (open_source e) hs
theorem preimage_open_of_open_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {s : set α} (hs : is_open s) :
is_open (local_equiv.target (to_local_equiv e) ∩ ⇑(local_homeomorph.symm e) ⁻¹' s) :=
continuous_on.preimage_open_of_open (local_homeomorph.continuous_on (local_homeomorph.symm e))
(open_target e) hs
/-- The image of an open set in the source is open. -/
theorem image_open_of_open {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {s : set α} (hs : is_open s)
(h : s ⊆ local_equiv.source (to_local_equiv e)) : is_open (⇑e '' s) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (is_open (⇑e '' s)))
(local_equiv.image_eq_target_inter_inv_preimage (to_local_equiv e) h)))
(continuous_on.preimage_open_of_open (continuous_on_symm e) (open_target e) hs)
/-- The image of the restriction of an open set to the source is open. -/
theorem image_open_of_open' {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) {s : set α} (hs : is_open s) :
is_open (⇑e '' (s ∩ local_equiv.source (to_local_equiv e))) :=
sorry
/-- Restricting a local homeomorphism `e` to `e.source ∩ s` when `s` is open. This is sometimes hard
to use because of the openness assumption, but it has the advantage that when it can
be used then its local_equiv is defeq to local_equiv.restr -/
protected def restr_open {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) (hs : is_open s) : local_homeomorph α β :=
mk
(local_equiv.mk (local_equiv.to_fun (local_equiv.restr (to_local_equiv e) s))
(local_equiv.inv_fun (local_equiv.restr (to_local_equiv e) s))
(local_equiv.source (local_equiv.restr (to_local_equiv e) s))
(local_equiv.target (local_equiv.restr (to_local_equiv e) s)) sorry sorry sorry sorry)
sorry sorry sorry sorry
@[simp] theorem restr_open_to_local_equiv {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set α) (hs : is_open s) :
to_local_equiv (local_homeomorph.restr_open e s hs) = local_equiv.restr (to_local_equiv e) s :=
rfl
-- Already simp via local_equiv
theorem restr_open_source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) (hs : is_open s) :
local_equiv.source (to_local_equiv (local_homeomorph.restr_open e s hs)) =
local_equiv.source (to_local_equiv e) ∩ s :=
rfl
/-- Restricting a local homeomorphism `e` to `e.source ∩ interior s`. We use the interior to make
sure that the restriction is well defined whatever the set s, since local homeomorphisms are by
definition defined on open sets. In applications where `s` is open, this coincides with the
restriction of local equivalences -/
protected def restr {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) : local_homeomorph α β :=
local_homeomorph.restr_open e (interior s) is_open_interior
@[simp] theorem restr_to_local_equiv {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set α) :
to_local_equiv (local_homeomorph.restr e s) =
local_equiv.restr (to_local_equiv e) (interior s) :=
rfl
@[simp] theorem restr_coe {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) : ⇑(local_homeomorph.restr e s) = ⇑e :=
rfl
@[simp] theorem restr_coe_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set α) :
⇑(local_homeomorph.symm (local_homeomorph.restr e s)) = ⇑(local_homeomorph.symm e) :=
rfl
theorem restr_source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) :
local_equiv.source (to_local_equiv (local_homeomorph.restr e s)) =
local_equiv.source (to_local_equiv e) ∩ interior s :=
rfl
theorem restr_target {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) :
local_equiv.target (to_local_equiv (local_homeomorph.restr e s)) =
local_equiv.target (to_local_equiv e) ∩ ⇑(local_homeomorph.symm e) ⁻¹' interior s :=
rfl
theorem restr_source' {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) (hs : is_open s) :
local_equiv.source (to_local_equiv (local_homeomorph.restr e s)) =
local_equiv.source (to_local_equiv e) ∩ s :=
sorry
theorem restr_to_local_equiv' {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : set α) (hs : is_open s) :
to_local_equiv (local_homeomorph.restr e s) = local_equiv.restr (to_local_equiv e) s :=
sorry
theorem restr_eq_of_source_subset {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {s : set α}
(h : local_equiv.source (to_local_equiv e) ⊆ s) : local_homeomorph.restr e s = e :=
sorry
@[simp] theorem restr_univ {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{e : local_homeomorph α β} : local_homeomorph.restr e set.univ = e :=
restr_eq_of_source_subset (set.subset_univ (local_equiv.source (to_local_equiv e)))
theorem restr_source_inter {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : set α) :
local_homeomorph.restr e (local_equiv.source (to_local_equiv e) ∩ s) =
local_homeomorph.restr e s :=
sorry
/-- The identity on the whole space as a local homeomorphism. -/
protected def refl (α : Type u_1) [topological_space α] : local_homeomorph α α :=
homeomorph.to_local_homeomorph (homeomorph.refl α)
@[simp] theorem refl_local_equiv {α : Type u_1} [topological_space α] :
to_local_equiv (local_homeomorph.refl α) = local_equiv.refl α :=
rfl
theorem refl_source {α : Type u_1} [topological_space α] :
local_equiv.source (to_local_equiv (local_homeomorph.refl α)) = set.univ :=
rfl
theorem refl_target {α : Type u_1} [topological_space α] :
local_equiv.target (to_local_equiv (local_homeomorph.refl α)) = set.univ :=
rfl
@[simp] theorem refl_symm {α : Type u_1} [topological_space α] :
local_homeomorph.symm (local_homeomorph.refl α) = local_homeomorph.refl α :=
rfl
@[simp] theorem refl_coe {α : Type u_1} [topological_space α] : ⇑(local_homeomorph.refl α) = id :=
rfl
/-- The identity local equiv on a set `s` -/
def of_set {α : Type u_1} [topological_space α] (s : set α) (hs : is_open s) :
local_homeomorph α α :=
mk
(local_equiv.mk (local_equiv.to_fun (local_equiv.of_set s))
(local_equiv.inv_fun (local_equiv.of_set s)) (local_equiv.source (local_equiv.of_set s))
(local_equiv.target (local_equiv.of_set s)) sorry sorry sorry sorry)
hs hs sorry sorry
@[simp] theorem of_set_to_local_equiv {α : Type u_1} [topological_space α] {s : set α}
(hs : is_open s) : to_local_equiv (of_set s hs) = local_equiv.of_set s :=
rfl
theorem of_set_source {α : Type u_1} [topological_space α] {s : set α} (hs : is_open s) :
local_equiv.source (to_local_equiv (of_set s hs)) = s :=
rfl
theorem of_set_target {α : Type u_1} [topological_space α] {s : set α} (hs : is_open s) :
local_equiv.target (to_local_equiv (of_set s hs)) = s :=
rfl
@[simp] theorem of_set_coe {α : Type u_1} [topological_space α] {s : set α} (hs : is_open s) :
⇑(of_set s hs) = id :=
rfl
@[simp] theorem of_set_symm {α : Type u_1} [topological_space α] {s : set α} (hs : is_open s) :
local_homeomorph.symm (of_set s hs) = of_set s hs :=
rfl
@[simp] theorem of_set_univ_eq_refl {α : Type u_1} [topological_space α] :
of_set set.univ is_open_univ = local_homeomorph.refl α :=
sorry
/-- Composition of two local homeomorphisms when the target of the first and the source of
the second coincide. -/
protected def trans' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ)
(h : local_equiv.target (to_local_equiv e) = local_equiv.source (to_local_equiv e')) :
local_homeomorph α γ :=
mk
(local_equiv.mk
(local_equiv.to_fun (local_equiv.trans' (to_local_equiv e) (to_local_equiv e') h))
(local_equiv.inv_fun (local_equiv.trans' (to_local_equiv e) (to_local_equiv e') h))
(local_equiv.source (local_equiv.trans' (to_local_equiv e) (to_local_equiv e') h))
(local_equiv.target (local_equiv.trans' (to_local_equiv e) (to_local_equiv e') h)) sorry sorry
sorry sorry)
(open_source e) (open_target e') sorry sorry
/-- Composing two local homeomorphisms, by restricting to the maximal domain where their
composition is well defined. -/
protected def trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) : local_homeomorph α γ :=
local_homeomorph.trans'
(local_homeomorph.symm
(local_homeomorph.restr_open (local_homeomorph.symm e)
(local_equiv.source (to_local_equiv e')) (open_source e')))
(local_homeomorph.restr_open e' (local_equiv.target (to_local_equiv e)) (open_target e)) sorry
@[simp] theorem trans_to_local_equiv {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
to_local_equiv (local_homeomorph.trans e e') =
local_equiv.trans (to_local_equiv e) (to_local_equiv e') :=
rfl
@[simp] theorem coe_trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) : ⇑(local_homeomorph.trans e e') = ⇑e' ∘ ⇑e :=
rfl
@[simp] theorem coe_trans_symm {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
⇑(local_homeomorph.symm (local_homeomorph.trans e e')) =
⇑(local_homeomorph.symm e) ∘ ⇑(local_homeomorph.symm e') :=
rfl
theorem trans_symm_eq_symm_trans_symm {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_homeomorph.symm (local_homeomorph.trans e e') =
local_homeomorph.trans (local_homeomorph.symm e') (local_homeomorph.symm e) :=
sorry
/- This could be considered as a simp lemma, but there are many situations where it makes something
simple into something more complicated. -/
theorem trans_source {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.source (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' local_equiv.source (to_local_equiv e') :=
local_equiv.trans_source (to_local_equiv e) (to_local_equiv e')
theorem trans_source' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.source (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.source (to_local_equiv e) ∩
⇑e ⁻¹' (local_equiv.target (to_local_equiv e) ∩ local_equiv.source (to_local_equiv e')) :=
local_equiv.trans_source' (to_local_equiv e) (to_local_equiv e')
theorem trans_source'' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.source (to_local_equiv (local_homeomorph.trans e e')) =
⇑(local_homeomorph.symm e) ''
(local_equiv.target (to_local_equiv e) ∩ local_equiv.source (to_local_equiv e')) :=
local_equiv.trans_source'' (to_local_equiv e) (to_local_equiv e')
theorem image_trans_source {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
⇑e '' local_equiv.source (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.target (to_local_equiv e) ∩ local_equiv.source (to_local_equiv e') :=
local_equiv.image_trans_source (to_local_equiv e) (to_local_equiv e')
theorem trans_target {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.target (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.target (to_local_equiv e') ∩
⇑(local_homeomorph.symm e') ⁻¹' local_equiv.target (to_local_equiv e) :=
rfl
theorem trans_target' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.target (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.target (to_local_equiv e') ∩
⇑(local_homeomorph.symm e') ⁻¹'
(local_equiv.source (to_local_equiv e') ∩ local_equiv.target (to_local_equiv e)) :=
trans_source' (local_homeomorph.symm e') (local_homeomorph.symm e)
theorem trans_target'' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
local_equiv.target (to_local_equiv (local_homeomorph.trans e e')) =
⇑e' '' (local_equiv.source (to_local_equiv e') ∩ local_equiv.target (to_local_equiv e)) :=
trans_source'' (local_homeomorph.symm e') (local_homeomorph.symm e)
theorem inv_image_trans_target {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) :
⇑(local_homeomorph.symm e') ''
local_equiv.target (to_local_equiv (local_homeomorph.trans e e')) =
local_equiv.source (to_local_equiv e') ∩ local_equiv.target (to_local_equiv e) :=
image_trans_source (local_homeomorph.symm e') (local_homeomorph.symm e)
theorem trans_assoc {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph β γ) (e'' : local_homeomorph γ δ) :
local_homeomorph.trans (local_homeomorph.trans e e') e'' =
local_homeomorph.trans e (local_homeomorph.trans e' e'') :=
eq_of_local_equiv_eq
(local_equiv.trans_assoc (to_local_equiv e) (to_local_equiv e') (to_local_equiv e''))
@[simp] theorem trans_refl {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : local_homeomorph.trans e (local_homeomorph.refl β) = e :=
eq_of_local_equiv_eq (local_equiv.trans_refl (to_local_equiv e))
@[simp] theorem refl_trans {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : local_homeomorph.trans (local_homeomorph.refl α) e = e :=
eq_of_local_equiv_eq (local_equiv.refl_trans (to_local_equiv e))
theorem trans_of_set {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {s : set β} (hs : is_open s) :
local_homeomorph.trans e (of_set s hs) = local_homeomorph.restr e (⇑e ⁻¹' s) :=
sorry
theorem trans_of_set' {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {s : set β} (hs : is_open s) :
local_homeomorph.trans e (of_set s hs) =
local_homeomorph.restr e (local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' s) :=
sorry
theorem of_set_trans {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {s : set α} (hs : is_open s) :
local_homeomorph.trans (of_set s hs) e = local_homeomorph.restr e s :=
sorry
theorem of_set_trans' {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) {s : set α} (hs : is_open s) :
local_homeomorph.trans (of_set s hs) e =
local_homeomorph.restr e (local_equiv.source (to_local_equiv e) ∩ s) :=
sorry
@[simp] theorem of_set_trans_of_set {α : Type u_1} [topological_space α] {s : set α}
(hs : is_open s) {s' : set α} (hs' : is_open s') :
local_homeomorph.trans (of_set s hs) (of_set s' hs') = of_set (s ∩ s') (is_open_inter hs hs') :=
sorry
theorem restr_trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (e : local_homeomorph α β)
(e' : local_homeomorph β γ) (s : set α) :
local_homeomorph.trans (local_homeomorph.restr e s) e' =
local_homeomorph.restr (local_homeomorph.trans e e') s :=
eq_of_local_equiv_eq (local_equiv.restr_trans (to_local_equiv e) (to_local_equiv e') (interior s))
/-- `eq_on_source e e'` means that `e` and `e'` have the same source, and coincide there. They
should really be considered the same local equiv. -/
def eq_on_source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (e' : local_homeomorph α β) :=
local_equiv.source (to_local_equiv e) = local_equiv.source (to_local_equiv e') ∧
set.eq_on (⇑e) (⇑e') (local_equiv.source (to_local_equiv e))
theorem eq_on_source_iff {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (e' : local_homeomorph α β) :
eq_on_source e e' ↔ local_equiv.eq_on_source (to_local_equiv e) (to_local_equiv e') :=
iff.rfl
/-- `eq_on_source` is an equivalence relation -/
protected instance setoid {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] : setoid (local_homeomorph α β) :=
setoid.mk eq_on_source sorry
theorem eq_on_source_refl {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) : e ≈ e :=
setoid.refl e
/-- If two local homeomorphisms are equivalent, so are their inverses -/
theorem eq_on_source.symm' {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e') :
local_homeomorph.symm e ≈ local_homeomorph.symm e' :=
local_equiv.eq_on_source.symm' h
/-- Two equivalent local homeomorphisms have the same source -/
theorem eq_on_source.source_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e') :
local_equiv.source (to_local_equiv e) = local_equiv.source (to_local_equiv e') :=
and.left h
/-- Two equivalent local homeomorphisms have the same target -/
theorem eq_on_source.target_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e') :
local_equiv.target (to_local_equiv e) = local_equiv.target (to_local_equiv e') :=
and.left (eq_on_source.symm' h)
/-- Two equivalent local homeomorphisms have coinciding `to_fun` on the source -/
theorem eq_on_source.eq_on {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e') :
set.eq_on (⇑e) (⇑e') (local_equiv.source (to_local_equiv e)) :=
and.right h
/-- Two equivalent local homeomorphisms have coinciding `inv_fun` on the target -/
theorem eq_on_source.symm_eq_on_target {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e') :
set.eq_on (⇑(local_homeomorph.symm e)) (⇑(local_homeomorph.symm e'))
(local_equiv.target (to_local_equiv e)) :=
and.right (eq_on_source.symm' h)
/-- Composition of local homeomorphisms respects equivalence -/
theorem eq_on_source.trans' {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] {e : local_homeomorph α β}
{e' : local_homeomorph α β} {f : local_homeomorph β γ} {f' : local_homeomorph β γ} (he : e ≈ e')
(hf : f ≈ f') : local_homeomorph.trans e f ≈ local_homeomorph.trans e' f' :=
local_equiv.eq_on_source.trans' he hf
/-- Restriction of local homeomorphisms respects equivalence -/
theorem eq_on_source.restr {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{e : local_homeomorph α β} {e' : local_homeomorph α β} (he : e ≈ e') (s : set α) :
local_homeomorph.restr e s ≈ local_homeomorph.restr e' s :=
local_equiv.eq_on_source.restr he (interior s)
/-- Composition of a local homeomorphism and its inverse is equivalent to the restriction of the
identity to the source -/
theorem trans_self_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) :
local_homeomorph.trans e (local_homeomorph.symm e) ≈
of_set (local_equiv.source (to_local_equiv e)) (open_source e) :=
local_equiv.trans_self_symm (to_local_equiv e)
theorem trans_symm_self {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) :
local_homeomorph.trans (local_homeomorph.symm e) e ≈
of_set (local_equiv.target (to_local_equiv e)) (open_target e) :=
trans_self_symm (local_homeomorph.symm e)
theorem eq_of_eq_on_source_univ {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] {e : local_homeomorph α β} {e' : local_homeomorph α β} (h : e ≈ e')
(s : local_equiv.source (to_local_equiv e) = set.univ)
(t : local_equiv.target (to_local_equiv e) = set.univ) : e = e' :=
eq_of_local_equiv_eq
(local_equiv.eq_of_eq_on_source_univ (to_local_equiv e) (to_local_equiv e') h s t)
/-- The product of two local homeomorphisms, as a local homeomorphism on the product space. -/
def prod {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [topological_space α]
[topological_space β] [topological_space γ] [topological_space δ] (e : local_homeomorph α β)
(e' : local_homeomorph γ δ) : local_homeomorph (α × γ) (β × δ) :=
mk
(local_equiv.mk (local_equiv.to_fun (local_equiv.prod (to_local_equiv e) (to_local_equiv e')))
(local_equiv.inv_fun (local_equiv.prod (to_local_equiv e) (to_local_equiv e')))
(local_equiv.source (local_equiv.prod (to_local_equiv e) (to_local_equiv e')))
(local_equiv.target (local_equiv.prod (to_local_equiv e) (to_local_equiv e'))) sorry sorry
sorry sorry)
sorry sorry sorry sorry
@[simp] theorem prod_to_local_equiv {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
to_local_equiv (prod e e') = local_equiv.prod (to_local_equiv e) (to_local_equiv e') :=
rfl
theorem prod_source {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
local_equiv.source (to_local_equiv (prod e e')) =
set.prod (local_equiv.source (to_local_equiv e)) (local_equiv.source (to_local_equiv e')) :=
rfl
theorem prod_target {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
local_equiv.target (to_local_equiv (prod e e')) =
set.prod (local_equiv.target (to_local_equiv e)) (local_equiv.target (to_local_equiv e')) :=
rfl
@[simp] theorem prod_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
⇑(prod e e') = fun (p : α × γ) => (coe_fn e (prod.fst p), coe_fn e' (prod.snd p)) :=
rfl
theorem prod_coe_symm {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
⇑(local_homeomorph.symm (prod e e')) =
fun (p : β × δ) =>
(coe_fn (local_homeomorph.symm e) (prod.fst p),
coe_fn (local_homeomorph.symm e') (prod.snd p)) :=
rfl
@[simp] theorem prod_symm {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
(e : local_homeomorph α β) (e' : local_homeomorph γ δ) :
local_homeomorph.symm (prod e e') = prod (local_homeomorph.symm e) (local_homeomorph.symm e') :=
rfl
@[simp] theorem prod_trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
{η : Type u_5} {ε : Type u_6} [topological_space η] [topological_space ε]
(e : local_homeomorph α β) (f : local_homeomorph β γ) (e' : local_homeomorph δ η)
(f' : local_homeomorph η ε) :
local_homeomorph.trans (prod e e') (prod f f') =
prod (local_homeomorph.trans e f) (local_homeomorph.trans e' f') :=
sorry
/-- Continuity within a set at a point can be read under right composition with a local
homeomorphism, if the point is in its target -/
theorem continuous_within_at_iff_continuous_within_at_comp_right {α : Type u_1} {β : Type u_2}
{γ : Type u_3} [topological_space α] [topological_space β] [topological_space γ]
(e : local_homeomorph α β) {f : β → γ} {s : set β} {x : β}
(h : x ∈ local_equiv.target (to_local_equiv e)) :
continuous_within_at f s x ↔
continuous_within_at (f ∘ ⇑e) (⇑e ⁻¹' s) (coe_fn (local_homeomorph.symm e) x) :=
sorry
/-- Continuity at a point can be read under right composition with a local homeomorphism, if the
point is in its target -/
theorem continuous_at_iff_continuous_at_comp_right {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
{f : β → γ} {x : β} (h : x ∈ local_equiv.target (to_local_equiv e)) :
continuous_at f x ↔ continuous_at (f ∘ ⇑e) (coe_fn (local_homeomorph.symm e) x) :=
sorry
/-- A function is continuous on a set if and only if its composition with a local homeomorphism
on the right is continuous on the corresponding set. -/
theorem continuous_on_iff_continuous_on_comp_right {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
{f : β → γ} {s : set β} (h : s ⊆ local_equiv.target (to_local_equiv e)) :
continuous_on f s ↔ continuous_on (f ∘ ⇑e) (local_equiv.source (to_local_equiv e) ∩ ⇑e ⁻¹' s) :=
sorry
/-- Continuity within a set at a point can be read under left composition with a local
homeomorphism if a neighborhood of the initial point is sent to the source of the local
homeomorphism-/
theorem continuous_within_at_iff_continuous_within_at_comp_left {α : Type u_1} {β : Type u_2}
{γ : Type u_3} [topological_space α] [topological_space β] [topological_space γ]
(e : local_homeomorph α β) {f : γ → α} {s : set γ} {x : γ}
(hx : f x ∈ local_equiv.source (to_local_equiv e))
(h : f ⁻¹' local_equiv.source (to_local_equiv e) ∈ nhds_within x s) :
continuous_within_at f s x ↔ continuous_within_at (⇑e ∘ f) s x :=
sorry
/-- Continuity at a point can be read under left composition with a local homeomorphism if a
neighborhood of the initial point is sent to the source of the local homeomorphism-/
theorem continuous_at_iff_continuous_at_comp_left {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
{f : γ → α} {x : γ} (h : f ⁻¹' local_equiv.source (to_local_equiv e) ∈ nhds x) :
continuous_at f x ↔ continuous_at (⇑e ∘ f) x :=
sorry
/-- A function is continuous on a set if and only if its composition with a local homeomorphism
on the left is continuous on the corresponding set. -/
theorem continuous_on_iff_continuous_on_comp_left {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : local_homeomorph α β)
{f : γ → α} {s : set γ} (h : s ⊆ f ⁻¹' local_equiv.source (to_local_equiv e)) :
continuous_on f s ↔ continuous_on (⇑e ∘ f) s :=
sorry
/-- If a local homeomorphism has source and target equal to univ, then it induces a homeomorphism
between the whole spaces, expressed in this definition. -/
def to_homeomorph_of_source_eq_univ_target_eq_univ {α : Type u_1} {β : Type u_2}
[topological_space α] [topological_space β] (e : local_homeomorph α β)
(h : local_equiv.source (to_local_equiv e) = set.univ)
(h' : local_equiv.target (to_local_equiv e) = set.univ) : α ≃ₜ β :=
homeomorph.mk (equiv.mk ⇑e ⇑(local_homeomorph.symm e) sorry sorry)
@[simp] theorem to_homeomorph_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β)
(h : local_equiv.source (to_local_equiv e) = set.univ)
(h' : local_equiv.target (to_local_equiv e) = set.univ) :
⇑(to_homeomorph_of_source_eq_univ_target_eq_univ e h h') = ⇑e :=
rfl
@[simp] theorem to_homeomorph_symm_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β)
(h : local_equiv.source (to_local_equiv e) = set.univ)
(h' : local_equiv.target (to_local_equiv e) = set.univ) :
⇑(homeomorph.symm (to_homeomorph_of_source_eq_univ_target_eq_univ e h h')) =
⇑(local_homeomorph.symm e) :=
rfl
/-- A local homeomorphism whose source is all of `α` defines an open embedding of `α` into `β`. The
converse is also true; see `open_embedding.to_local_homeomorph`. -/
theorem to_open_embedding {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (h : local_equiv.source (to_local_equiv e) = set.univ) :
open_embedding (local_equiv.to_fun (to_local_equiv e)) :=
sorry
end local_homeomorph
namespace homeomorph
/- Register as simp lemmas that the fields of a local homeomorphism built from a homeomorphism
correspond to the fields of the original homeomorphism. -/
@[simp] theorem to_local_homeomorph_source {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) :
local_equiv.source (local_homeomorph.to_local_equiv (to_local_homeomorph e)) = set.univ :=
rfl
@[simp] theorem to_local_homeomorph_target {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) :
local_equiv.target (local_homeomorph.to_local_equiv (to_local_homeomorph e)) = set.univ :=
rfl
@[simp] theorem to_local_homeomorph_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) : ⇑(to_local_homeomorph e) = ⇑e :=
rfl
@[simp] theorem to_local_homeomorph_coe_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) :
⇑(local_homeomorph.symm (to_local_homeomorph e)) = ⇑(homeomorph.symm e) :=
rfl
@[simp] theorem refl_to_local_homeomorph {α : Type u_1} [topological_space α] :
to_local_homeomorph (homeomorph.refl α) = local_homeomorph.refl α :=
rfl
@[simp] theorem symm_to_local_homeomorph {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ₜ β) :
to_local_homeomorph (homeomorph.symm e) = local_homeomorph.symm (to_local_homeomorph e) :=
rfl
@[simp] theorem trans_to_local_homeomorph {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (e : α ≃ₜ β) (e' : β ≃ₜ γ) :
to_local_homeomorph (homeomorph.trans e e') =
local_homeomorph.trans (to_local_homeomorph e) (to_local_homeomorph e') :=
local_homeomorph.eq_of_local_equiv_eq (equiv.trans_to_local_equiv (to_equiv e) (to_equiv e'))
end homeomorph
namespace open_embedding
/-- An open embedding of `α` into `β`, with `α` nonempty, defines a local equivalence whose source
is all of `α`. This is mainly an auxiliary lemma for the stronger result `to_local_homeomorph`. -/
def to_local_equiv {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) : local_equiv α β :=
set.inj_on.to_local_equiv f set.univ sorry
@[simp] theorem to_local_equiv_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] [Nonempty α] {f : α → β} (h : open_embedding f) :
⇑(to_local_equiv h) = f :=
rfl
@[simp] theorem to_local_equiv_source {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] [Nonempty α] {f : α → β} (h : open_embedding f) :
local_equiv.source (to_local_equiv h) = set.univ :=
rfl
@[simp] theorem to_local_equiv_target {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] [Nonempty α] {f : α → β} (h : open_embedding f) :
local_equiv.target (to_local_equiv h) = set.range f :=
sorry
theorem open_target {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) :
is_open (local_equiv.target (to_local_equiv h)) :=
sorry
theorem continuous_inv_fun {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) :
continuous_on (local_equiv.inv_fun (to_local_equiv h))
(local_equiv.target (to_local_equiv h)) :=
sorry
/-- An open embedding of `α` into `β`, with `α` nonempty, defines a local homeomorphism whose source
is all of `α`. The converse is also true; see `local_homeomorph.to_open_embedding`. -/
def to_local_homeomorph {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) : local_homeomorph α β :=
local_homeomorph.mk (to_local_equiv h) is_open_univ (open_target h) sorry (continuous_inv_fun h)
@[simp] theorem to_local_homeomorph_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] [Nonempty α] {f : α → β} (h : open_embedding f) :
⇑(to_local_homeomorph h) = f :=
rfl
@[simp] theorem source {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) :
local_equiv.source (local_homeomorph.to_local_equiv (to_local_homeomorph h)) = set.univ :=
rfl
@[simp] theorem target {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
[Nonempty α] {f : α → β} (h : open_embedding f) :
local_equiv.target (local_homeomorph.to_local_equiv (to_local_homeomorph h)) = set.range f :=
to_local_equiv_target h
end open_embedding
-- We close and reopen the namespace to avoid
-- picking up the unnecessary `[nonempty α]` typeclass argument
namespace open_embedding
theorem continuous_at_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] {f : α → β} {g : β → γ} (hf : open_embedding f)
{x : α} : continuous_at (g ∘ f) x ↔ continuous_at g (f x) :=
sorry
end open_embedding
namespace topological_space.opens
/-- The inclusion of an open subset `s` of a space `α` into `α` is a local homeomorphism from the
subtype `s` to `α`. -/
def local_homeomorph_subtype_coe {α : Type u_1} [topological_space α] (s : opens α) [Nonempty ↥s] :
local_homeomorph (↥s) α :=
open_embedding.to_local_homeomorph sorry
@[simp] theorem local_homeomorph_subtype_coe_coe {α : Type u_1} [topological_space α] (s : opens α)
[Nonempty ↥s] : ⇑(local_homeomorph_subtype_coe s) = coe :=
rfl
@[simp] theorem local_homeomorph_subtype_coe_source {α : Type u_1} [topological_space α]
(s : opens α) [Nonempty ↥s] :
local_equiv.source (local_homeomorph.to_local_equiv (local_homeomorph_subtype_coe s)) =
set.univ :=
rfl
@[simp] theorem local_homeomorph_subtype_coe_target {α : Type u_1} [topological_space α]
(s : opens α) [Nonempty ↥s] :
local_equiv.target (local_homeomorph.to_local_equiv (local_homeomorph_subtype_coe s)) = ↑s :=
sorry
end topological_space.opens
namespace local_homeomorph
/-- The restriction of a local homeomorphism `e` to an open subset `s` of the domain type produces a
local homeomorphism whose domain is the subtype `s`.-/
def subtype_restr {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : topological_space.opens α) [Nonempty ↥s] :
local_homeomorph (↥s) β :=
local_homeomorph.trans (topological_space.opens.local_homeomorph_subtype_coe s) e
theorem subtype_restr_def {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(e : local_homeomorph α β) (s : topological_space.opens α) [Nonempty ↥s] :
subtype_restr e s =
local_homeomorph.trans (topological_space.opens.local_homeomorph_subtype_coe s) e :=
rfl
@[simp] theorem subtype_restr_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : topological_space.opens α) [Nonempty ↥s] :
⇑(subtype_restr e s) = set.restrict ⇑e ↑s :=
rfl
@[simp] theorem subtype_restr_source {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : local_homeomorph α β) (s : topological_space.opens α) [Nonempty ↥s] :
local_equiv.source (to_local_equiv (subtype_restr e s)) =
coe ⁻¹' local_equiv.source (to_local_equiv e) :=
sorry
/- This lemma characterizes the transition functions of an open subset in terms of the transition
functions of the original space. -/
theorem subtype_restr_symm_trans_subtype_restr {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (s : topological_space.opens α) [Nonempty ↥s] (f : local_homeomorph α β)
(f' : local_homeomorph α β) :
local_homeomorph.trans (local_homeomorph.symm (subtype_restr f s)) (subtype_restr f' s) ≈
local_homeomorph.restr (local_homeomorph.trans (local_homeomorph.symm f) f')
(local_equiv.target (to_local_equiv f) ∩ ⇑(local_homeomorph.symm f) ⁻¹' ↑s) :=
sorry
end Mathlib |
abbaaa496a4a2a4a4e634b448b5e61cab4b898aa | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/geometry/manifold/real_instances.lean | 081c4162a377958f3015ecf1f7df28428ae9cfe6 | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 14,178 | lean | /-
Copyright (c) 2019 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 geometry.manifold.smooth_manifold_with_corners linear_algebra.finite_dimensional
/-!
# Constructing examples of manifolds over ℝ
We introduce the necessary bits to be able to define manifolds modelled over ℝ^n, boundaryless
or with boundary or with corners. As a concrete example, we construct explicitly the manifold with
boundary structure on the real interval [x, y].
More specifically, we introduce
* `euclidean_space n` for a model vector space of dimension `n`.
* `model_with_corners ℝ (euclidean_space n) (euclidean_half_space n)` for the model space used
to define `n`-dimensional real manifolds with boundary
* `model_with_corners ℝ (euclidean_space n) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
## Implementation notes
The manifold structure on the interval [x, y] = Icc x y requires the assumption `x < y`. We
introduce a dummy class `lt_class x y` for this, to make such an assumption available to typeclass
search. This should hopefully not be necessary any more in Lean 4.
-/
noncomputable theory
open set
/--
The space ℝ^n. Note that the name is slightly misleading, as we only need a normed space
structure on ℝ^n, but the one we use here is the sup norm and not the euclidean one -- this is not
a problem for the manifold applications, but should probably be refactored at some point.
-/
def euclidean_space (n : ℕ) : Type := (fin n → ℝ)
/--
The half-space in ℝ^n, used to model manifolds with boundary. We only define it when `1 ≤ n`, as the
definition only makes sense in this case.
-/
def euclidean_half_space (n : ℕ) [has_zero (fin n)] : Type :=
{x : euclidean_space n // 0 ≤ x 0}
/--
The quadrant in ℝ^n, used to model manifolds with corners, made of all vectors with nonnegative
coordinates.
-/
def euclidean_quadrant (n : ℕ) : Type := {x : euclidean_space n // ∀i:fin n, 0 ≤ x i}
section
/- Register class instances for euclidean space and half-space and quadrant -/
local attribute [reducible] euclidean_space euclidean_half_space euclidean_quadrant
variable {n : ℕ}
-- short-circuit type class inference
instance : vector_space ℝ (euclidean_space n) := by apply_instance
instance : normed_group (euclidean_space n) := by apply_instance
instance : normed_space ℝ (euclidean_space n) := by apply_instance
instance [has_zero (fin n)] : topological_space (euclidean_half_space n) := by apply_instance
instance : topological_space (euclidean_quadrant n) := by apply_instance
instance : finite_dimensional ℝ (euclidean_space n) := by apply_instance
@[simp] lemma findim_euclidean_space : finite_dimensional.findim ℝ (euclidean_space n) = n :=
by simp
lemma range_half_space (n : ℕ) [has_zero (fin n)] :
range (λx : euclidean_half_space n, x.val) = {y | 0 ≤ y 0 } :=
by simp
lemma range_quadrant (n : ℕ) :
range (λx : euclidean_quadrant n, x.val) = {y | ∀i:fin n, 0 ≤ y i } :=
by simp
end
/--
Definition of the model with corners (euclidean_space n, euclidean_half_space n), used as a
model for manifolds with boundary.
-/
def model_with_corners_euclidean_half_space (n : ℕ) [has_zero (fin n)] :
model_with_corners ℝ (euclidean_space n) (euclidean_half_space n) :=
{ to_fun := λx, x.val,
inv_fun := λx, ⟨λi, if h : i = 0 then max (x i) 0 else x i, by simp [le_refl]⟩,
source := univ,
target := range (λx : euclidean_half_space n, x.val),
map_source := λx hx, by simpa [-mem_range, mem_range_self] using x.property,
map_target := λx hx, mem_univ _,
left_inv := λ⟨xval, xprop⟩ hx, begin
rw subtype.mk_eq_mk,
ext1 i,
by_cases hi : i = 0;
simp [hi, xprop]
end,
right_inv := λx hx, begin
simp [range_half_space] at hx,
ext1 i,
by_cases hi : i = 0;
simp [hi, hx]
end,
source_eq := rfl,
unique_diff := begin
/- To check that the half-space has the unique differentiability property, we use the criterion
`unique_diff_on_convex`: it suffices to check that it is convex and with nonempty interior. -/
rw range_half_space,
apply unique_diff_on_convex,
show convex {y : euclidean_space n | 0 ≤ y 0},
{ assume x y hx hy a b ha hb hab,
simpa using add_le_add (mul_nonneg' ha hx) (mul_nonneg' hb hy) },
show (interior {y : euclidean_space n | 0 ≤ y 0}).nonempty,
{ use (λi, 1),
rw mem_interior,
refine ⟨(pi (univ : set (fin n)) (λi, (Ioi 0 : set ℝ))), _,
is_open_set_pi finite_univ (λa ha, is_open_Ioi), _⟩,
{ assume x hx,
simp [pi] at hx,
exact le_of_lt (hx 0) },
{ simp only [pi, forall_prop_of_true, mem_univ, mem_Ioi],
assume i,
exact zero_lt_one } }
end,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := begin
apply continuous_subtype_mk,
apply continuous_pi,
assume i,
by_cases h : i = 0,
{ simp only [h, dif_pos],
have : continuous (λx:ℝ, max x 0) := continuous_id.max continuous_const,
exact this.comp (continuous_apply 0) },
{ simp [h],
exact continuous_apply i }
end }
/--
Definition of the model with corners (euclidean_space n, euclidean_quadrant n), used as a
model for manifolds with corners -/
def model_with_corners_euclidean_quadrant (n : ℕ) :
model_with_corners ℝ (euclidean_space n) (euclidean_quadrant n) :=
{ to_fun := λx, x.val,
inv_fun := λx, ⟨λi, max (x i) 0,
λi, by simp [le_refl]⟩,
source := univ,
target := range (λx : euclidean_quadrant n, x.val),
map_source := λx hx, by simpa [-mem_range, mem_range_self] using x.property,
map_target := λx hx, mem_univ _,
left_inv := λ⟨xval, xprop⟩ hx, begin
rw subtype.mk_eq_mk,
ext1 i,
simp [xprop i]
end,
right_inv := λx hx, begin
rw range_quadrant at hx,
ext1 i,
simp [hx i]
end,
source_eq := rfl,
unique_diff := begin
/- To check that the quadrant has the unique differentiability property, we use the criterion
`unique_diff_on_convex`: it suffices to check that it is convex and with nonempty interior. -/
rw range_quadrant,
apply unique_diff_on_convex,
show convex {y : euclidean_space n | ∀ (i : fin n), 0 ≤ y i},
{ assume x y hx hy a b ha hb hab i,
simpa using add_le_add (mul_nonneg' ha (hx i)) (mul_nonneg' hb (hy i)) },
show (interior {y : euclidean_space n | ∀ (i : fin n), 0 ≤ y i}).nonempty,
{ use (λi, 1),
rw mem_interior,
refine ⟨(pi (univ : set (fin n)) (λi, (Ioi 0 : set ℝ))), _,
is_open_set_pi finite_univ (λa ha, is_open_Ioi), _⟩,
{ assume x hx i,
simp [pi] at hx,
exact le_of_lt (hx i) },
{ simp only [pi, forall_prop_of_true, mem_univ, mem_Ioi],
assume i,
exact zero_lt_one } }
end,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := begin
apply continuous_subtype_mk,
apply continuous_pi,
assume i,
have : continuous (λx:ℝ, max x 0) := continuous.max continuous_id continuous_const,
exact this.comp (continuous_apply i)
end }
/--
Dummy class to make an assumption such as `x < y` available to typeclass search. Such an
assumption is used to define a manifold structure on [x, y] when `x < y`. Should be fixed in Lean 4.
-/
def lt_class {α : Type*} [has_lt α] (x y : α) : Prop := x < y
attribute [class] lt_class
/--
The left chart for the topological space [x, y], defined on [x,y) and sending x to 0 in
`euclidean_half_space 1`.
-/
def Icc_left_chart (x y : ℝ) [h : lt_class x y] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | z.val < y},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, z.val - x, sub_nonneg.mpr z.property.1⟩,
inv_fun := λz, ⟨min (z.val 0 + x) y, by simp [le_refl, z.property, le_of_lt h]⟩,
map_source := by simp,
map_target := by { simp, assume z hz, left, linarith },
left_inv := by { rintros ⟨z, hz⟩ h'z, simp at hz h'z, simp [hz, h'z] },
right_inv := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
simp at hz h'z,
have A : x + z 0 ≤ y, by linarith,
rw subsingleton.elim i 0,
simp [A, add_comm],
end,
open_source := begin
have : is_open {z : ℝ | z < y} := is_open_Iio,
exact continuous_subtype_val _ this
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : fin 1 → ℝ | z 0 < y - x} :=
(continuous_apply 0) _ this,
exact continuous_subtype_val _ this
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), z - x) :=
continuous.sub (continuous_pi $ λi, continuous_id) continuous_const,
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, min (z + x) y) :=
(continuous_id.add continuous_const).min continuous_const,
have B : continuous (λz : fin 1 → ℝ, z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
The right chart for the topological space [x, y], defined on (x,y] and sending y to 0 in
`euclidean_half_space 1`.
-/
def Icc_right_chart (x y : ℝ) [h : lt_class x y] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | x < z.val},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, y - z.val, sub_nonneg.mpr z.property.2⟩,
inv_fun := λz, ⟨max (y - z.val 0) x, by simp [le_refl, z.property, le_of_lt h, sub_eq_add_neg]⟩,
map_source := by simp,
map_target := by { simp, assume z hz, left, linarith },
left_inv := by { rintros ⟨z, hz⟩ h'z, simp at hz h'z, simp [hz, h'z, sub_eq_add_neg] },
right_inv := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
simp at hz h'z,
have A : x ≤ y - z 0, by linarith,
rw subsingleton.elim i 0,
simp [A, sub_sub_cancel],
end,
open_source := begin
have : is_open {z : ℝ | x < z} := is_open_Ioi,
exact continuous_subtype_val _ this
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : fin 1 → ℝ | z 0 < y - x} :=
(continuous_apply 0) _ this,
exact continuous_subtype_val _ this
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), y - z) :=
continuous_const.sub (continuous_pi (λi, continuous_id)),
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, max (y - z) x) :=
(continuous_const.sub continuous_id).max continuous_const,
have B : continuous (λz : fin 1 → ℝ, z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
Manifold with boundary structure on [x, y], using only two charts.
-/
instance Icc_manifold (x y : ℝ) [h : lt_class x y] : manifold (euclidean_half_space 1) (Icc x y) :=
{ atlas := {Icc_left_chart x y, Icc_right_chart x y},
chart_at := λz, if z.val < y then Icc_left_chart x y else Icc_right_chart x y,
mem_chart_source := λz, begin
by_cases h' : z.val < y,
{ simp only [h', if_true],
exact h' },
{ simp only [h', if_false],
apply lt_of_lt_of_le h,
simpa using h' }
end,
chart_mem_atlas := λz, by { by_cases h' : z.val < y; simp [h'] } }
/--
The manifold structure on [x, y] is smooth.
-/
instance Icc_smooth_manifold (x y : ℝ) [lt_class x y] :
smooth_manifold_with_corners (model_with_corners_euclidean_half_space 1) (Icc x y) :=
begin
have M : times_cont_diff_on ℝ ⊤ (λz : fin 1 → ℝ, (λi : fin 1, y - x) - z) univ,
{ rw times_cont_diff_on_univ,
exact times_cont_diff.sub times_cont_diff_const times_cont_diff_id },
haveI : has_groupoid (Icc x y)
(times_cont_diff_groupoid ⊤ (model_with_corners_euclidean_half_space 1)) :=
begin
apply has_groupoid_of_pregroupoid,
assume e e' he he',
simp [atlas] at he he',
/- We need to check that any composition of two charts gives a C^∞ function. Each chart can be
either the left chart or the right chart, leaving 4 possibilities that we handle successively.
-/
rcases he with rfl | rfl; rcases he' with rfl | rfl,
{ -- e = right chart, e' = right chart
refine ((mem_groupoid_of_pregroupoid _ _).mpr _).1,
exact symm_trans_mem_times_cont_diff_groupoid _ _ _ },
{ -- e = right chart, e' = left chart
apply M.congr_mono _ (subset_univ _),
assume z hz,
simp [-mem_range, range_half_space, model_with_corners_euclidean_half_space,
local_equiv.trans_source, Icc_left_chart, Icc_right_chart] at hz,
have A : 0 ≤ z 0 := hz.2,
have B : x ≤ y - z 0, by { have := hz.1.1.1, linarith },
ext i,
rw subsingleton.elim i 0,
simp [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, A, B,
sub_right_comm y] },
{ -- e = left chart, e' = right chart
apply M.congr_mono _ (subset_univ _),
assume z hz,
simp [-mem_range, range_half_space, model_with_corners_euclidean_half_space,
local_equiv.trans_source, Icc_left_chart, Icc_right_chart] at hz,
have A : 0 ≤ z 0 := hz.2,
have B : z 0 + x ≤ y, by { have := hz.1.1.1, linarith },
ext i,
rw subsingleton.elim i 0,
simp [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, A, B,
sub_add_eq_sub_sub_swap] },
{ -- e = left chart, e' = left chart
refine ((mem_groupoid_of_pregroupoid _ _).mpr _).1,
exact symm_trans_mem_times_cont_diff_groupoid _ _ _ }
end,
constructor
end
|
9b74b83197d027147577b3b45f8a39d805152e25 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/order/basic.lean | 2e4beb88e5ccde67edc2f7adc28a8d8ebd0cfca0 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,739 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import data.prod
import data.subtype
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `order_dual α` : A type synonym reversing the meaning of all inequalities.
* `as_linear_order α`: A type synonym to promote `partial_order α` to `linear_order α` using
`is_total α (≤)`.
### Transfering orders
- `order.preimage`, `preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `partial_order.lift`, `linear_order.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra classes
- `no_top_order`, `no_bot_order`: An order without a maximal/minimal element.
- `densely_ordered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`has_le.le`) and `<` (`has_lt.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`has_le.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `has_le.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## See also
- `algebra.order.basic` for basic lemmas about orders, and projection notation for orders
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open function
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w} {r : α → α → Prop}
attribute [simp] le_refl
attribute [ext] has_le
alias le_trans ← has_le.le.trans
alias lt_of_le_of_lt ← has_le.le.trans_lt
alias le_antisymm ← has_le.le.antisymm
alias lt_of_le_of_ne ← has_le.le.lt_of_ne
alias lt_of_le_not_le ← has_le.le.lt_of_not_le
alias lt_or_eq_of_le ← has_le.le.lt_or_eq
alias decidable.lt_or_eq_of_le ← has_le.le.lt_or_eq_dec
alias le_of_lt ← has_lt.lt.le
alias lt_trans ← has_lt.lt.trans
alias lt_of_lt_of_le ← has_lt.lt.trans_le
alias ne_of_lt ← has_lt.lt.ne
alias lt_asymm ← has_lt.lt.asymm has_lt.lt.not_lt
alias le_of_eq ← eq.le
attribute [nolint decidable_classical] has_le.le.lt_or_eq_dec
/-- A version of `le_refl` where the argument is implicit -/
lemma le_rfl [preorder α] {x : α} : x ≤ x := le_refl x
@[simp] lemma lt_self_iff_false [preorder α] (x : α) : x < x ↔ false :=
⟨lt_irrefl x, false.elim⟩
namespace eq
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
protected lemma ge [preorder α] {x y : α} (h : x = y) : y ≤ x := h.symm.le
lemma trans_le [preorder α] {x y z : α} (h1 : x = y) (h2 : y ≤ z) : x ≤ z := h1.le.trans h2
lemma not_lt [partial_order α] {x y : α} (h : x = y) : ¬(x < y) := λ h', h'.ne h
lemma not_gt [partial_order α] {x y : α} (h : x = y) : ¬(y < x) := h.symm.not_lt
end eq
namespace has_le.le
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma ge [has_le α] {x y : α} (h : x ≤ y) : y ≥ x := h
lemma trans_eq [preorder α] {x y z : α} (h1 : x ≤ y) (h2 : y = z) : x ≤ z := h1.trans h2.le
lemma lt_iff_ne [partial_order α] {x y : α} (h : x ≤ y) : x < y ↔ x ≠ y := ⟨λ h, h.ne, h.lt_of_ne⟩
lemma le_iff_eq [partial_order α] {x y : α} (h : x ≤ y) : y ≤ x ↔ y = x :=
⟨λ h', h'.antisymm h, eq.le⟩
lemma lt_or_le [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a < c ∨ c ≤ b :=
(lt_or_ge a c).imp id $ λ hc, le_trans hc h
lemma le_or_lt [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c < b :=
(le_or_gt a c).imp id $ λ hc, lt_of_lt_of_le hc h
lemma le_or_le [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b :=
(h.le_or_lt c).elim or.inl (λ h, or.inr $ le_of_lt h)
end has_le.le
namespace has_lt.lt
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma gt [has_lt α] {x y : α} (h : x < y) : y > x := h
protected lemma false [preorder α] {x : α} : x < x → false := lt_irrefl x
lemma ne' [preorder α] {x y : α} (h : x < y) : y ≠ x := h.ne.symm
lemma lt_or_lt [linear_order α] {x y : α} (h : x < y) (z : α) : x < z ∨ z < y :=
(lt_or_ge z y).elim or.inr (λ hz, or.inl $ h.trans_le hz)
end has_lt.lt
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma ge.le [has_le α] {x y : α} (h : x ≥ y) : y ≤ x := h
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma gt.lt [has_lt α] {x y : α} (h : x > y) : y < x := h
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem ge_of_eq [preorder α] {a b : α} (h : a = b) : a ≥ b := h.ge
@[simp, nolint ge_or_gt] -- see Note [nolint_ge]
lemma ge_iff_le [preorder α] {a b : α} : a ≥ b ↔ b ≤ a := iff.rfl
@[simp, nolint ge_or_gt] -- see Note [nolint_ge]
lemma gt_iff_lt [preorder α] {a b : α} : a > b ↔ b < a := iff.rfl
lemma not_le_of_lt [preorder α] {a b : α} (h : a < b) : ¬ b ≤ a := (le_not_le_of_lt h).right
alias not_le_of_lt ← has_lt.lt.not_le
lemma not_lt_of_le [preorder α] {a b : α} (h : a ≤ b) : ¬ b < a := λ hba, hba.not_le h
alias not_lt_of_le ← has_le.le.not_lt
-- See Note [decidable namespace]
protected lemma decidable.le_iff_eq_or_lt [partial_order α] [@decidable_rel α (≤)]
{a b : α} : a ≤ b ↔ a = b ∨ a < b := decidable.le_iff_lt_or_eq.trans or.comm
lemma le_iff_eq_or_lt [partial_order α] {a b : α} : a ≤ b ↔ a = b ∨ a < b :=
le_iff_lt_or_eq.trans or.comm
lemma lt_iff_le_and_ne [partial_order α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨λ h, ⟨le_of_lt h, ne_of_lt h⟩, λ ⟨h1, h2⟩, h1.lt_of_ne h2⟩
-- See Note [decidable namespace]
protected lemma decidable.eq_iff_le_not_lt [partial_order α] [@decidable_rel α (≤)]
{a b : α} : a = b ↔ a ≤ b ∧ ¬ a < b :=
⟨λ h, ⟨h.le, h ▸ lt_irrefl _⟩, λ ⟨h₁, h₂⟩, h₁.antisymm $
decidable.by_contradiction $ λ h₃, h₂ (h₁.lt_of_not_le h₃)⟩
lemma eq_iff_le_not_lt [partial_order α] {a b : α} : a = b ↔ a ≤ b ∧ ¬ a < b :=
by haveI := classical.dec; exact decidable.eq_iff_le_not_lt
lemma eq_or_lt_of_le [partial_order α] {a b : α} (h : a ≤ b) : a = b ∨ a < b := h.lt_or_eq.symm
alias decidable.eq_or_lt_of_le ← has_le.le.eq_or_lt_dec
alias eq_or_lt_of_le ← has_le.le.eq_or_lt
attribute [nolint decidable_classical] has_le.le.eq_or_lt_dec
lemma ne.le_iff_lt [partial_order α] {a b : α} (h : a ≠ b) : a ≤ b ↔ a < b :=
⟨λ h', lt_of_le_of_ne h' h, λ h, h.le⟩
-- See Note [decidable namespace]
protected lemma decidable.ne_iff_lt_iff_le [partial_order α] [@decidable_rel α (≤)]
{a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨λ h, decidable.by_cases le_of_eq (le_of_lt ∘ h.mp), λ h, ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
@[simp] lemma ne_iff_lt_iff_le [partial_order α] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b :=
by haveI := classical.dec; exact decidable.ne_iff_lt_iff_le
lemma lt_of_not_ge' [linear_order α] {a b : α} (h : ¬ b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
lemma lt_iff_not_ge' [linear_order α] {x y : α} : x < y ↔ ¬ y ≤ x := ⟨not_le_of_gt, lt_of_not_ge'⟩
lemma ne.lt_or_lt [linear_order α] {x y : α} (h : x ≠ y) : x < y ∨ y < x := lt_or_gt_of_ne h
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp] lemma lt_or_lt_iff_ne [linear_order α] {x y : α} : x < y ∨ y < x ↔ x ≠ y :=
ne_iff_lt_or_gt.symm
lemma not_lt_iff_eq_or_lt [linear_order α] {a b : α} : ¬ a < b ↔ a = b ∨ b < a :=
not_lt.trans $ decidable.le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl
lemma exists_ge_of_linear [linear_order α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| or.inl h := ⟨_, h, le_rfl⟩
| or.inr h := ⟨_, le_rfl, h⟩
end
lemma lt_imp_lt_of_le_imp_le {β} [linear_order α] [preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_ge' $ λ h', (H h').not_lt h
lemma le_imp_le_iff_lt_imp_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} :
(a ≤ b → c ≤ d) ↔ (d < c → b < a) :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
lemma lt_iff_lt_of_le_iff_le' {β} [preorder α] [preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
lemma lt_iff_lt_of_le_iff_le {β} [linear_order α] [linear_order β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c :=
not_le.symm.trans $ (not_congr H).trans $ not_le
lemma le_iff_le_iff_lt_iff_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, λ H, not_lt.symm.trans $ (not_congr H).trans $ not_lt⟩
lemma eq_of_forall_le_iff [partial_order α] {a b : α}
(H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
lemma le_of_forall_le [preorder α] {a b : α}
(H : ∀ c, c ≤ a → c ≤ b) : a ≤ b :=
H _ le_rfl
lemma le_of_forall_le' [preorder α] {a b : α}
(H : ∀ c, a ≤ c → b ≤ c) : b ≤ a :=
H _ le_rfl
lemma le_of_forall_lt [linear_order α] {a b : α}
(H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt $ λ h, lt_irrefl _ (H _ h)
lemma forall_lt_iff_le [linear_order α] {a b : α} :
(∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, λ h c hca, lt_of_lt_of_le hca h⟩
lemma le_of_forall_lt' [linear_order α] {a b : α}
(H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt $ λ h, lt_irrefl _ (H _ h)
lemma forall_lt_iff_le' [linear_order α] {a b : α} :
(∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', λ h c hac, lt_of_le_of_lt h hac⟩
lemma eq_of_forall_ge_iff [partial_order α] {a b : α}
(H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
/-- monotonicity of `≤` with respect to `→` -/
lemma le_implies_le_of_le_of_le {a b c d : α} [preorder α] (hca : c ≤ a) (hbd : b ≤ d) :
a ≤ b → c ≤ d :=
λ hab, (hca.trans hab).trans hbd
@[ext]
lemma preorder.to_has_le_injective {α : Type*} :
function.injective (@preorder.to_has_le α) :=
λ A B h, begin
cases A, cases B,
injection h with h_le,
have : A_lt = B_lt,
{ funext a b,
dsimp [(≤)] at A_lt_iff_le_not_le B_lt_iff_le_not_le h_le,
simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, h_le], },
congr',
end
@[ext]
lemma partial_order.to_preorder_injective {α : Type*} :
function.injective (@partial_order.to_preorder α) :=
λ A B h, by { cases A, cases B, injection h, congr' }
@[ext]
lemma linear_order.to_partial_order_injective {α : Type*} :
function.injective (@linear_order.to_partial_order α) :=
begin
intros A B h,
cases A, cases B, injection h,
obtain rfl : A_le = B_le := ‹_›, obtain rfl : A_lt = B_lt := ‹_›,
obtain rfl : A_decidable_le = B_decidable_le := subsingleton.elim _ _,
obtain rfl : A_max = B_max := A_max_def.trans B_max_def.symm,
obtain rfl : A_min = B_min := A_min_def.trans B_min_def.symm,
congr
end
theorem preorder.ext {α} {A B : preorder α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by { ext x y, exact H x y }
theorem partial_order.ext {α} {A B : partial_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by { ext x y, exact H x y }
theorem linear_order.ext {α} {A B : linear_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by { ext x y, exact H x y }
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `rel_embedding` (assuming `f`
is injective). -/
@[simp] def order.preimage {α β} (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y)
infix ` ⁻¹'o `:80 := order.preimage
/-- The preimage of a decidable order is decidable. -/
instance order.preimage.decidable {α β} (f : α → β) (s : β → β → Prop) [H : decidable_rel s] :
decidable_rel (f ⁻¹'o s) :=
λ x y, H _ _
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. -/
def order_dual (α : Type*) : Type* := α
namespace order_dual
instance (α : Type*) [h : nonempty α] : nonempty (order_dual α) := h
instance (α : Type*) [h : subsingleton α] : subsingleton (order_dual α) := h
instance (α : Type*) [has_le α] : has_le (order_dual α) := ⟨λ x y : α, y ≤ x⟩
instance (α : Type*) [has_lt α] : has_lt (order_dual α) := ⟨λ x y : α, y < x⟩
instance (α : Type*) [has_zero α] : has_zero (order_dual α) := ⟨(0 : α)⟩
-- `dual_le` and `dual_lt` should not be simp lemmas:
-- they cause a loop since `α` and `order_dual α` are definitionally equal
lemma dual_le [has_le α] {a b : α} :
@has_le.le (order_dual α) _ a b ↔ @has_le.le α _ b a := iff.rfl
lemma dual_lt [has_lt α] {a b : α} :
@has_lt.lt (order_dual α) _ a b ↔ @has_lt.lt α _ b a := iff.rfl
instance (α : Type*) [preorder α] : preorder (order_dual α) :=
{ le_refl := le_refl,
le_trans := λ a b c hab hbc, hbc.trans hab,
lt_iff_le_not_le := λ _ _, lt_iff_le_not_le,
.. order_dual.has_le α,
.. order_dual.has_lt α }
instance (α : Type*) [partial_order α] : partial_order (order_dual α) :=
{ le_antisymm := λ a b hab hba, @le_antisymm α _ a b hba hab, .. order_dual.preorder α }
instance (α : Type*) [linear_order α] : linear_order (order_dual α) :=
{ le_total := λ a b : α, le_total b a,
decidable_le := (infer_instance : decidable_rel (λ a b : α, b ≤ a)),
decidable_lt := (infer_instance : decidable_rel (λ a b : α, b < a)),
min := @max α _,
max := @min α _,
min_def := @linear_order.max_def α _,
max_def := @linear_order.min_def α _,
.. order_dual.partial_order α }
instance : Π [inhabited α], inhabited (order_dual α) := id
theorem preorder.dual_dual (α : Type*) [H : preorder α] :
order_dual.preorder (order_dual α) = H :=
preorder.ext $ λ _ _, iff.rfl
theorem partial_order.dual_dual (α : Type*) [H : partial_order α] :
order_dual.partial_order (order_dual α) = H :=
partial_order.ext $ λ _ _, iff.rfl
theorem linear_order.dual_dual (α : Type*) [H : linear_order α] :
order_dual.linear_order (order_dual α) = H :=
linear_order.ext $ λ _ _, iff.rfl
end order_dual
/-! ### Order instances on the function space -/
instance pi.preorder {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] : preorder (Π i, α i) :=
{ le := λ x y, ∀ i, x i ≤ y i,
le_refl := λ a i, le_refl (a i),
le_trans := λ a b c h₁ h₂ i, le_trans (h₁ i) (h₂ i) }
lemma pi.le_def {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] {x y : Π i, α i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
iff.rfl
lemma pi.lt_def {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] {x y : Π i, α i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i :=
by simp [lt_iff_le_not_le, pi.le_def] {contextual := tt}
lemma le_update_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι]
{x y : Π i, α i} {i : ι} {a : α i} :
x ≤ function.update y i a ↔ x i ≤ a ∧ ∀ j ≠ i, x j ≤ y j :=
function.forall_update_iff _ (λ j z, x j ≤ z)
lemma update_le_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι]
{x y : Π i, α i} {i : ι} {a : α i} :
function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ j ≠ i, x j ≤ y j :=
function.forall_update_iff _ (λ j z, z ≤ y j)
lemma update_le_update_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι]
{x y : Π i, α i} {i : ι} {a b : α i} :
function.update x i a ≤ function.update y i b ↔ a ≤ b ∧ ∀ j ≠ i, x j ≤ y j :=
by simp [update_le_iff] {contextual := tt}
instance pi.partial_order {ι : Type u} {α : ι → Type v} [∀ i, partial_order (α i)] :
partial_order (Π i, α i) :=
{ le_antisymm := λ f g h1 h2, funext (λ b, (h1 b).antisymm (h2 b)),
..pi.preorder }
/-! ### Lifts of order instances -/
/-- Transfer a `preorder` on `β` to a `preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
@[reducible] def preorder.lift {α β} [preorder β] (f : α → β) : preorder α :=
{ le := λ x y, f x ≤ f y,
le_refl := λ a, le_rfl,
le_trans := λ a b c, le_trans,
lt := λ x y, f x < f y,
lt_iff_le_not_le := λ a b, lt_iff_le_not_le }
/-- Transfer a `partial_order` on `β` to a `partial_order` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
@[reducible] def partial_order.lift {α β} [partial_order β] (f : α → β) (inj : injective f) :
partial_order α :=
{ le_antisymm := λ a b h₁ h₂, inj (h₁.antisymm h₂), .. preorder.lift f }
/-- Transfer a `linear_order` on `β` to a `linear_order` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
@[reducible] def linear_order.lift {α β} [linear_order β] (f : α → β) (inj : injective f) :
linear_order α :=
{ le_total := λ x y, le_total (f x) (f y),
decidable_le := λ x y, (infer_instance : decidable (f x ≤ f y)),
decidable_lt := λ x y, (infer_instance : decidable (f x < f y)),
decidable_eq := λ x y, decidable_of_iff _ inj.eq_iff,
.. partial_order.lift f inj }
instance subtype.preorder {α} [preorder α] (p : α → Prop) : preorder (subtype p) :=
preorder.lift (coe : subtype p → α)
@[simp] lemma subtype.mk_le_mk {α} [preorder α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y :=
iff.rfl
@[simp] lemma subtype.mk_lt_mk {α} [preorder α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : subtype p) < ⟨y, hy⟩ ↔ x < y :=
iff.rfl
@[simp, norm_cast] lemma subtype.coe_le_coe {α} [preorder α] {p : α → Prop} {x y : subtype p} :
(x : α) ≤ y ↔ x ≤ y :=
iff.rfl
@[simp, norm_cast] lemma subtype.coe_lt_coe {α} [preorder α] {p : α → Prop} {x y : subtype p} :
(x : α) < y ↔ x < y :=
iff.rfl
instance subtype.partial_order {α} [partial_order α] (p : α → Prop) :
partial_order (subtype p) :=
partial_order.lift coe subtype.coe_injective
/-- A subtype of a linear order is a linear order. We explicitly give the proof of decidable
equality as the existing instance, in order to not have two instances of decidable equality that
are not definitionally equal. -/
instance subtype.linear_order {α} [linear_order α] (p : α → Prop) : linear_order (subtype p) :=
{ decidable_eq := subtype.decidable_eq,
.. linear_order.lift coe subtype.coe_injective }
namespace prod
instance (α : Type u) (β : Type v) [has_le α] [has_le β] : has_le (α × β) :=
⟨λ p q, p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩
lemma le_def {α β : Type*} [has_le α] [has_le β] {x y : α × β} :
x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 := iff.rfl
@[simp] lemma mk_le_mk {α β : Type*} [has_le α] [has_le β] {x₁ x₂ : α} {y₁ y₂ : β} :
(x₁, y₁) ≤ (x₂, y₂) ↔ x₁ ≤ x₂ ∧ y₁ ≤ y₂ :=
iff.rfl
instance (α : Type u) (β : Type v) [preorder α] [preorder β] : preorder (α × β) :=
{ le_refl := λ ⟨a, b⟩, ⟨le_refl a, le_refl b⟩,
le_trans := λ ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩,
⟨le_trans hac hce, le_trans hbd hdf⟩,
.. prod.has_le α β }
/-- The pointwise partial order on a product.
(The lexicographic ordering is defined in order/lexicographic.lean, and the instances are
available via the type synonym `lex α β = α × β`.) -/
instance (α : Type u) (β : Type v) [partial_order α] [partial_order β] :
partial_order (α × β) :=
{ le_antisymm := λ ⟨a, b⟩ ⟨c, d⟩ ⟨hac, hbd⟩ ⟨hca, hdb⟩,
prod.ext (hac.antisymm hca) (hbd.antisymm hdb),
.. prod.preorder α β }
end prod
/-! ### Additional order classes -/
/-- Order without a maximal element. Sometimes called cofinal. -/
class no_top_order (α : Type u) [preorder α] : Prop :=
(no_top : ∀ a : α, ∃ a', a < a')
lemma no_top [preorder α] [no_top_order α] : ∀ a : α, ∃ a', a < a' :=
no_top_order.no_top
instance nonempty_gt {α : Type u} [preorder α] [no_top_order α] (a : α) :
nonempty {x // a < x} :=
nonempty_subtype.2 (no_top a)
/-- `a : α` is a top element of `α` if it is greater than or equal to any other element of `α`.
This predicate is useful, e.g., to make some statements and proofs work in both cases
`[order_top α]` and `[no_top_order α]`. -/
def is_top {α : Type u} [has_le α] (a : α) : Prop := ∀ b, b ≤ a
@[simp] lemma not_is_top {α : Type u} [preorder α] [no_top_order α] (a : α) : ¬is_top a :=
λ h, let ⟨b, hb⟩ := no_top a in hb.not_le (h b)
lemma is_top.unique {α : Type u} [partial_order α] {a b : α} (ha : is_top a) (hb : a ≤ b) :
a = b :=
le_antisymm hb (ha b)
/-- Order without a minimal element. Sometimes called coinitial or dense. -/
class no_bot_order (α : Type u) [preorder α] : Prop :=
(no_bot : ∀ a : α, ∃ a', a' < a)
lemma no_bot [preorder α] [no_bot_order α] : ∀ a : α, ∃ a', a' < a :=
no_bot_order.no_bot
/-- `a : α` is a bottom element of `α` if it is less than or equal to any other element of `α`.
This predicate is useful, e.g., to make some statements and proofs work in both cases
`[order_bot α]` and `[no_bot_order α]`. -/
def is_bot {α : Type u} [has_le α] (a : α) : Prop := ∀ b, a ≤ b
@[simp] lemma not_is_bot {α : Type u} [preorder α] [no_bot_order α] (a : α) : ¬is_bot a :=
λ h, let ⟨b, hb⟩ := no_bot a in hb.not_le (h b)
lemma is_bot.unique {α : Type u} [partial_order α] {a b : α} (ha : is_bot a) (hb : b ≤ a) :
a = b :=
le_antisymm (ha b) hb
instance order_dual.no_top_order (α : Type u) [preorder α] [no_bot_order α] :
no_top_order (order_dual α) :=
⟨λ a, @no_bot α _ _ a⟩
instance order_dual.no_bot_order (α : Type u) [preorder α] [no_top_order α] :
no_bot_order (order_dual α) :=
⟨λ a, @no_top α _ _ a⟩
instance nonempty_lt {α : Type u} [preorder α] [no_bot_order α] (a : α) :
nonempty {x // x < a} :=
nonempty_subtype.2 (no_bot a)
/-- An order is dense if there is an element between any pair of distinct elements. -/
class densely_ordered (α : Type u) [preorder α] : Prop :=
(dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂)
lemma exists_between [preorder α] [densely_ordered α] :
∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ :=
densely_ordered.dense
instance order_dual.densely_ordered (α : Type u) [preorder α] [densely_ordered α] :
densely_ordered (order_dual α) :=
⟨λ a₁ a₂ ha, (@exists_between α _ _ _ _ ha).imp $ λ a, and.symm⟩
lemma le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h : ∀ a, a₂ < a → a₁ ≤ a) :
a₁ ≤ a₂ :=
le_of_not_gt $ λ ha,
let ⟨a, ha₁, ha₂⟩ := exists_between ha in
lt_irrefl a $ lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›)
lemma eq_of_le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀ a, a₂ < a → a₁ ≤ a) : a₁ = a₂ :=
le_antisymm (le_of_forall_le_of_dense h₂) h₁
lemma le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h : ∀ a₃ < a₁, a₃ ≤ a₂) :
a₁ ≤ a₂ :=
le_of_not_gt $ λ ha,
let ⟨a, ha₁, ha₂⟩ := exists_between ha in
lt_irrefl a $ lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a›
lemma eq_of_le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀ a₃ < a₁, a₃ ≤ a₂) : a₁ = a₂ :=
(le_of_forall_ge_of_dense h₂).antisymm h₁
lemma dense_or_discrete [linear_order α] (a₁ a₂ : α) :
(∃ a, a₁ < a ∧ a < a₂) ∨ ((∀ a, a₁ < a → a₂ ≤ a) ∧ (∀ a < a₂, a ≤ a₁)) :=
or_iff_not_imp_left.2 $ λ h,
⟨λ a ha₁, le_of_not_gt $ λ ha₂, h ⟨a, ha₁, ha₂⟩,
λ a ha₂, le_of_not_gt $ λ ha₁, h ⟨a, ha₁, ha₂⟩⟩
variables {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Linear order from a total partial order -/
/-- Type synonym to create an instance of `linear_order` from a `partial_order` and
`is_total α (≤)` -/
def as_linear_order (α : Type u) := α
instance {α} [inhabited α] : inhabited (as_linear_order α) :=
⟨ (default α : α) ⟩
noncomputable instance as_linear_order.linear_order {α} [partial_order α] [is_total α (≤)] :
linear_order (as_linear_order α) :=
{ le_total := @total_of α (≤) _,
decidable_le := classical.dec_rel _,
.. (_ : partial_order α) }
|
6b78ff9ac6de18571af9bca5ec9e53fadadf9e3b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/control/functor_auto.lean | 81fcec16b9f418fe1f4d5cb1cfbf98469afab0b9 | [] | 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 | 11,240 | lean | /-
Copyright (c) 2017 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.ext
import Mathlib.tactic.lint.default
import Mathlib.PostPort
universes u v u_1 u_2 u_3 w
namespace Mathlib
/-!
# Functors
This module provides additional lemmas, definitions, and instances for `functor`s.
## Main definitions
* `const α` is the functor that sends all types to `α`.
* `add_const α` is `const α` but for when `α` has an additive structure.
* `comp F G` for functors `F` and `G` is the functor composition of `F` and `G`.
* `liftp` and `liftr` respectively lift predicates and relations on a type `α`
to `F α`. Terms of `F α` are considered to, in some sense, contain values of type `α`.
## Tags
functor, applicative
-/
theorem functor.map_id {F : Type u → Type v} {α : Type u} [Functor F] [is_lawful_functor F] :
Functor.map id = id :=
funext id_map
theorem functor.map_comp_map {F : Type u → Type v} {α : Type u} {β : Type u} {γ : Type u}
[Functor F] [is_lawful_functor F] (f : α → β) (g : β → γ) :
Functor.map g ∘ Functor.map f = Functor.map (g ∘ f) :=
sorry
theorem functor.ext {F : Type u_1 → Type u_2} {F1 : Functor F} {F2 : Functor F}
[is_lawful_functor F] [is_lawful_functor F]
(H : ∀ (α β : Type u_1) (f : α → β) (x : F α), f <$> x = f <$> x) : F1 = F2 :=
sorry
/-- Introduce the `id` functor. Incidentally, this is `pure` for
`id` as a `monad` and as an `applicative` functor. -/
def id.mk {α : Sort u} : α → id α := id
namespace functor
/-- `const α` is the constant functor, mapping every type to `α`. When
`α` has a monoid structure, `const α` has an `applicative` instance.
(If `α` has an additive monoid structure, see `functor.add_const`.) -/
def const (α : Type u_1) (β : Type u_2) := α
/-- `const.mk` is the canonical map `α → const α β` (the identity), and
it can be used as a pattern to extract this value. -/
def const.mk {α : Type u_1} {β : Type u_2} (x : α) : const α β := x
/-- `const.mk'` is `const.mk` but specialized to map `α` to
`const α punit`, where `punit` is the terminal object in `Type*`. -/
def const.mk' {α : Type u_1} (x : α) : const α PUnit := x
/-- Extract the element of `α` from the `const` functor. -/
def const.run {α : Type u_1} {β : Type u_2} (x : const α β) : α := x
namespace const
protected theorem ext {α : Type u_1} {β : Type u_2} {x : const α β} {y : const α β}
(h : run x = run y) : x = y :=
h
/-- The map operation of the `const γ` functor. -/
protected def map {γ : Type u_1} {α : Type u_2} {β : Type u_3} (f : α → β) (x : const γ β) :
const γ α :=
x
protected instance functor {γ : Type u_1} : Functor (const γ) :=
{ map := const.map, mapConst := fun (α β : Type u_2) => const.map ∘ function.const β }
protected instance is_lawful_functor {γ : Type u_1} : is_lawful_functor (const γ) :=
is_lawful_functor.mk (fun (α : Type u_2) (x : const γ α) => Eq.refl (id <$> x))
fun (α β γ_1 : Type u_2) (g : α → β) (h : β → γ_1) (x : const γ α) => Eq.refl ((h ∘ g) <$> x)
protected instance inhabited {α : Type u_1} {β : Type u_2} [Inhabited α] : Inhabited (const α β) :=
{ default := Inhabited.default }
end const
/-- `add_const α` is a synonym for constant functor `const α`, mapping
every type to `α`. When `α` has a additive monoid structure,
`add_const α` has an `applicative` instance. (If `α` has a
multiplicative monoid structure, see `functor.const`.) -/
def add_const (α : Type u_1) (β : Type u_2) := const α
/-- `add_const.mk` is the canonical map `α → add_const α β`, which is the identity,
where `add_const α β = const α β`. It can be used as a pattern to extract this value. -/
def add_const.mk {α : Type u_1} {β : Type u_2} (x : α) : add_const α β := x
/-- Extract the element of `α` from the constant functor. -/
def add_const.run {α : Type u_1} {β : Type u_2} : add_const α β → α := id
protected instance add_const.functor {γ : Type u_1} : Functor (add_const γ) := const.functor
protected instance add_const.is_lawful_functor {γ : Type u_1} : is_lawful_functor (add_const γ) :=
const.is_lawful_functor
protected instance add_const.inhabited {α : Type u_1} {β : Type u_2} [Inhabited α] :
Inhabited (add_const α β) :=
{ default := Inhabited.default }
/-- `functor.comp` is a wrapper around `function.comp` for types.
It prevents Lean's type class resolution mechanism from trying
a `functor (comp F id)` when `functor F` would do. -/
def comp (F : Type u → Type w) (G : Type v → Type u) (α : Type v) := F (G α)
/-- Construct a term of `comp F G α` from a term of `F (G α)`, which is the same type.
Can be used as a pattern to extract a term of `F (G α)`. -/
def comp.mk {F : Type u → Type w} {G : Type v → Type u} {α : Type v} (x : F (G α)) : comp F G α := x
/-- Extract a term of `F (G α)` from a term of `comp F G α`, which is the same type. -/
def comp.run {F : Type u → Type w} {G : Type v → Type u} {α : Type v} (x : comp F G α) : F (G α) :=
x
namespace comp
protected theorem ext {F : Type u → Type w} {G : Type v → Type u} {α : Type v} {x : comp F G α}
{y : comp F G α} : run x = run y → x = y :=
id
protected instance inhabited {F : Type u → Type w} {G : Type v → Type u} {α : Type v}
[Inhabited (F (G α))] : Inhabited (comp F G α) :=
{ default := Inhabited.default }
/-- The map operation for the composition `comp F G` of functors `F` and `G`. -/
protected def map {F : Type u → Type w} {G : Type v → Type u} [Functor F] [Functor G] {α : Type v}
{β : Type v} (h : α → β) : comp F G α → comp F G β :=
sorry
protected instance functor {F : Type u → Type w} {G : Type v → Type u} [Functor F] [Functor G] :
Functor (comp F G) :=
{ map := comp.map, mapConst := fun (α β : Type v) => comp.map ∘ function.const β }
theorem map_mk {F : Type u → Type w} {G : Type v → Type u} [Functor F] [Functor G] {α : Type v}
{β : Type v} (h : α → β) (x : F (G α)) : h <$> mk x = mk (Functor.map h <$> x) :=
rfl
@[simp] protected theorem run_map {F : Type u → Type w} {G : Type v → Type u} [Functor F]
[Functor G] {α : Type v} {β : Type v} (h : α → β) (x : comp F G α) :
run (h <$> x) = Functor.map h <$> run x :=
rfl
protected theorem id_map {F : Type u → Type w} {G : Type v → Type u} [Functor F] [Functor G]
[is_lawful_functor F] [is_lawful_functor G] {α : Type v} (x : comp F G α) : comp.map id x = x :=
sorry
protected theorem comp_map {F : Type u → Type w} {G : Type v → Type u} [Functor F] [Functor G]
[is_lawful_functor F] [is_lawful_functor G] {α : Type v} {β : Type v} {γ : Type v} (g' : α → β)
(h : β → γ) (x : comp F G α) : comp.map (h ∘ g') x = comp.map h (comp.map g' x) :=
sorry
protected instance is_lawful_functor {F : Type u → Type w} {G : Type v → Type u} [Functor F]
[Functor G] [is_lawful_functor F] [is_lawful_functor G] : is_lawful_functor (comp F G) :=
is_lawful_functor.mk comp.id_map comp.comp_map
theorem functor_comp_id {F : Type u_1 → Type u_2} [AF : Functor F] [is_lawful_functor F] :
comp.functor = AF :=
ext fun (α β : Type u_1) (f : α → β) (x : F α) => rfl
theorem functor_id_comp {F : Type u_1 → Type u_2} [AF : Functor F] [is_lawful_functor F] :
comp.functor = AF :=
ext fun (α β : Type u_1) (f : α → β) (x : F α) => rfl
end comp
namespace comp
/-- The `<*>` operation for the composition of applicative functors. -/
protected def seq {F : Type u → Type w} {G : Type v → Type u} [Applicative F] [Applicative G]
{α : Type v} {β : Type v} : comp F G (α → β) → comp F G α → comp F G β :=
sorry
protected instance has_pure {F : Type u → Type w} {G : Type v → Type u} [Applicative F]
[Applicative G] : Pure (comp F G) :=
{ pure := fun (_x : Type v) (x : _x) => mk (pure (pure x)) }
protected instance has_seq {F : Type u → Type w} {G : Type v → Type u} [Applicative F]
[Applicative G] : Seq (comp F G) :=
{ seq := fun (_x _x_1 : Type v) (f : comp F G (_x → _x_1)) (x : comp F G _x) => comp.seq f x }
@[simp] protected theorem run_pure {F : Type u → Type w} {G : Type v → Type u} [Applicative F]
[Applicative G] {α : Type v} (x : α) : run (pure x) = pure (pure x) :=
idRhs (run (pure x) = run (pure x)) rfl
@[simp] protected theorem run_seq {F : Type u → Type w} {G : Type v → Type u} [Applicative F]
[Applicative G] {α : Type v} {β : Type v} (f : comp F G (α → β)) (x : comp F G α) :
run (f <*> x) = Seq.seq <$> run f <*> run x :=
rfl
protected instance applicative {F : Type u → Type w} {G : Type v → Type u} [Applicative F]
[Applicative G] : Applicative (comp F G) :=
{ toFunctor := { map := comp.map, mapConst := fun (α β : Type v) => comp.map ∘ function.const β },
toPure := { pure := pure }, toSeq := { seq := comp.seq },
toSeqLeft :=
{ seqLeft :=
fun (α β : Type v) (a : comp F G α) (b : comp F G β) =>
comp.seq (comp.map (function.const β) a) b },
toSeqRight :=
{ seqRight :=
fun (α β : Type v) (a : comp F G α) (b : comp F G β) =>
comp.seq (comp.map (function.const α id) a) b } }
end comp
/-- If we consider `x : F α` to, in some sense, contain values of type `α`,
predicate `liftp p x` holds iff every value contained by `x` satisfies `p`. -/
def liftp {F : Type u → Type u} [Functor F] {α : Type u} (p : α → Prop) (x : F α) :=
∃ (u : F (Subtype p)), subtype.val <$> u = x
/-- If we consider `x : F α` to, in some sense, contain values of type `α`, then
`liftr r x y` relates `x` and `y` iff (1) `x` and `y` have the same shape and
(2) we can pair values `a` from `x` and `b` from `y` so that `r a b` holds. -/
def liftr {F : Type u → Type u} [Functor F] {α : Type u} (r : α → α → Prop) (x : F α) (y : F α) :=
∃ (u : F (Subtype fun (p : α × α) => r (prod.fst p) (prod.snd p))),
(fun (t : Subtype fun (p : α × α) => r (prod.fst p) (prod.snd p)) =>
prod.fst (subtype.val t)) <$>
u =
x ∧
(fun (t : Subtype fun (p : α × α) => r (prod.fst p) (prod.snd p)) =>
prod.snd (subtype.val t)) <$>
u =
y
/-- If we consider `x : F α` to, in some sense, contain values of type `α`, then
`supp x` is the set of values of type `α` that `x` contains. -/
def supp {F : Type u → Type u} [Functor F] {α : Type u} (x : F α) : set α :=
set_of fun (y : α) => ∀ {p : α → Prop}, liftp p x → p y
theorem of_mem_supp {F : Type u → Type u} [Functor F] {α : Type u} {x : F α} {p : α → Prop}
(h : liftp p x) (y : α) (H : y ∈ supp x) : p y :=
hy h
end functor
namespace ulift
protected instance functor : Functor ulift :=
{ map := fun (α β : Type u_1) (f : α → β) => up ∘ f ∘ down,
mapConst := fun (α β : Type u_1) => (fun (f : β → α) => up ∘ f ∘ down) ∘ function.const β }
end Mathlib |
a70a9140b6c3a5c2ad8ee4178a5e1eddd9735087 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/measure_theory/ess_sup.lean | 21d78a603208c724224c030a37e8a348fcc5b0fb | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 5,618 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.measure_space
import order.filter.ennreal
/-!
# Essential supremum and infimum
We define the essential supremum and infimum of a function `f : α → β` with respect to a measure
`μ` on `α`. The essential supremum is the infimum of the constants `c : β` such that `f x ≤ c`
almost everywhere.
TODO: The essential supremum of functions `α → ℝ≥0∞` is used in particular to define the norm in
the `L∞` space (see measure_theory/lp_space.lean).
There is a different quantity which is sometimes also called essential supremum: the least
upper-bound among measurable functions of a family of measurable functions (in an almost-everywhere
sense). We do not define that quantity here, which is simply the supremum of a map with values in
`α →ₘ[μ] β` (see measure_theory/ae_eq_fun.lean).
## Main definitions
* `ess_sup f μ := μ.ae.limsup f`
* `ess_inf f μ := μ.ae.liminf f`
-/
open measure_theory filter
open_locale ennreal
variables {α β : Type*} [measurable_space α] {μ : measure α}
section conditionally_complete_lattice
variable [conditionally_complete_lattice β]
/-- Essential supremum of `f` with respect to measure `μ`: the smallest `c : β` such that
`f x ≤ c` a.e. -/
def ess_sup (f : α → β) (μ : measure α) := μ.ae.limsup f
/-- Essential infimum of `f` with respect to measure `μ`: the greatest `c : β` such that
`c ≤ f x` a.e. -/
def ess_inf (f : α → β) (μ : measure α) := μ.ae.liminf f
lemma ess_sup_congr_ae {f g : α → β} (hfg : f =ᵐ[μ] g) : ess_sup f μ = ess_sup g μ :=
limsup_congr hfg
lemma ess_inf_congr_ae {f g : α → β} (hfg : f =ᵐ[μ] g) : ess_inf f μ = ess_inf g μ :=
@ess_sup_congr_ae α (order_dual β) _ _ _ _ _ hfg
end conditionally_complete_lattice
section complete_lattice
variable [complete_lattice β]
@[simp] lemma ess_sup_measure_zero {f : α → β} : ess_sup f 0 = ⊥ :=
le_bot_iff.mp (Inf_le (by simp [set.mem_set_of_eq, eventually_le, ae_iff]))
@[simp] lemma ess_inf_measure_zero {f : α → β} : ess_inf f 0 = ⊤ :=
@ess_sup_measure_zero α (order_dual β) _ _ _
lemma ess_sup_mono_ae {f g : α → β} (hfg : f ≤ᵐ[μ] g) : ess_sup f μ ≤ ess_sup g μ :=
limsup_le_limsup hfg
lemma ess_inf_mono_ae {f g : α → β} (hfg : f ≤ᵐ[μ] g) : ess_inf f μ ≤ ess_inf g μ :=
liminf_le_liminf hfg
lemma ess_sup_const (c : β) (hμ : μ ≠ 0) : ess_sup (λ x : α, c) μ = c :=
begin
haveI hμ_ne_bot : μ.ae.ne_bot := by rwa [ne_bot_iff, ne.def, ae_eq_bot],
exact limsup_const c,
end
lemma ess_sup_le_of_ae_le {f : α → β} (c : β) (hf : f ≤ᵐ[μ] (λ _, c)) : ess_sup f μ ≤ c :=
begin
refine (ess_sup_mono_ae hf).trans _,
by_cases hμ : μ = 0,
{ simp [hμ], },
{ rwa ess_sup_const, },
end
lemma ess_inf_const (c : β) (hμ : μ ≠ 0) : ess_inf (λ x : α, c) μ = c :=
@ess_sup_const α (order_dual β) _ _ _ _ hμ
lemma le_ess_inf_of_ae_le {f : α → β} (c : β) (hf : (λ _, c) ≤ᵐ[μ] f) : c ≤ ess_inf f μ :=
@ess_sup_le_of_ae_le α (order_dual β) _ _ _ _ c hf
lemma ess_sup_const_bot : ess_sup (λ x : α, (⊥ : β)) μ = (⊥ : β) :=
limsup_const_bot
lemma ess_inf_const_top : ess_inf (λ x : α, (⊤ : β)) μ = (⊤ : β) :=
liminf_const_top
lemma order_iso.ess_sup_apply {γ} [complete_lattice γ] (f : α → β) (μ : measure α)
(g : β ≃o γ) :
g (ess_sup f μ) = ess_sup (λ x, g (f x)) μ :=
begin
refine order_iso.limsup_apply g _ _ _ _,
all_goals { is_bounded_default, },
end
lemma order_iso.ess_inf_apply {γ} [complete_lattice γ] (f : α → β) (μ : measure α)
(g : β ≃o γ) :
g (ess_inf f μ) = ess_inf (λ x, g (f x)) μ :=
@order_iso.ess_sup_apply α (order_dual β) _ _ (order_dual γ) _ _ _ g.dual
lemma ess_sup_mono_measure {f : α → β} {μ ν : measure α} (hμν : ν ≪ μ) :
ess_sup f ν ≤ ess_sup f μ :=
begin
refine limsup_le_limsup_of_le (measure.ae_le_iff_absolutely_continuous.mpr hμν) _ _,
all_goals { is_bounded_default, },
end
lemma ess_inf_antimono_measure {f : α → β} {μ ν : measure α} (hμν : μ ≪ ν) :
ess_inf f ν ≤ ess_inf f μ :=
begin
refine liminf_le_liminf_of_le (measure.ae_le_iff_absolutely_continuous.mpr hμν) _ _,
all_goals { is_bounded_default, },
end
end complete_lattice
section complete_linear_order
variable [complete_linear_order β]
lemma ae_lt_of_ess_sup_lt {f : α → β} {x : β} (hf : ess_sup f μ < x) : ∀ᵐ y ∂μ, f y < x :=
filter.eventually_lt_of_limsup_lt hf
lemma ae_lt_of_lt_ess_inf {f : α → β} {x : β} (hf : x < ess_inf f μ) : ∀ᵐ y ∂μ, x < f y :=
@ae_lt_of_ess_sup_lt α (order_dual β) _ _ _ _ _ hf
end complete_linear_order
namespace ennreal
variables {f : α → ℝ≥0∞}
lemma ae_le_ess_sup (f : α → ℝ≥0∞) : ∀ᵐ y ∂μ, f y ≤ ess_sup f μ :=
eventually_le_limsup f
@[simp] lemma ess_sup_eq_zero_iff : ess_sup f μ = 0 ↔ f =ᵐ[μ] 0 :=
limsup_eq_zero_iff
lemma ess_sup_const_mul {a : ℝ≥0∞} : ess_sup (λ (x : α), a * (f x)) μ = a * ess_sup f μ :=
limsup_const_mul
lemma ess_sup_add_le (f g : α → ℝ≥0∞) : ess_sup (f + g) μ ≤ ess_sup f μ + ess_sup g μ :=
limsup_add_le f g
lemma ess_sup_liminf_le {ι} [encodable ι] [linear_order ι] (f : ι → α → ℝ≥0∞) :
ess_sup (λ x, at_top.liminf (λ n, f n x)) μ ≤ at_top.liminf (λ n, ess_sup (λ x, f n x) μ) :=
by { simp_rw ess_sup, exact ennreal.limsup_liminf_le_liminf_limsup (λ a b, f b a), }
end ennreal
|
e3808bb75c141810854a24597f7e70ba3f03ee7c | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/field_theory/adjoin.lean | 6b1f1f673559a60686b8dcb4254e57e0ede4cdfc | [
"Apache-2.0"
] | permissive | LibertasSpZ/mathlib | b9fcd46625eb940611adb5e719a4b554138dade6 | 33f7870a49d7cc06d2f3036e22543e6ec5046e68 | refs/heads/master | 1,672,066,539,347 | 1,602,429,158,000 | 1,602,429,158,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,999 | lean | /-
Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning and Patrick Lutz
-/
import deprecated.subfield
import field_theory.tower
/-!
# Adjoining Elements to Fields
In this file we introduce the notion of adjoining elements to fields.
This isn't quite the same as adjoining elements to rings.
For example, `algebra.adjoin K {x}` might not include `x⁻¹`.
## Main results
- `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining S ∪ T.
- `bot_eq_top_of_dim_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x`
in `E` then `F = E`
## Notation
- `F⟮α⟯`: adjoin a single element `α` to `F`.
-/
namespace field
section adjoin_def
variables (F : Type*) [field F] {E : Type*} [field E] [algebra F E] (S : set E)
/-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/
def adjoin : subalgebra F E :=
{ carrier := field.closure (set.range (algebra_map F E) ∪ S),
one_mem' := is_submonoid.one_mem,
mul_mem' := λ x y, is_submonoid.mul_mem,
zero_mem' := is_add_submonoid.zero_mem,
add_mem' := λ x y, is_add_submonoid.add_mem,
algebra_map_mem' := λ x, field.mem_closure (or.inl (set.mem_range.mpr ⟨x,rfl⟩)) }
lemma adjoin_eq_range_algebra_map_adjoin :
(adjoin F S : set E) = set.range (algebra_map (adjoin F S) E) := (subtype.range_coe).symm
lemma adjoin.algebra_map_mem (x : F) : algebra_map F E x ∈ adjoin F S :=
field.mem_closure (or.inl (set.mem_range_self x))
lemma subset_adjoin_of_subset_left {F : set E} {HF : is_subfield F} {T : set E} (HT : T ⊆ F) :
T ⊆ adjoin F S :=
λ x hx, adjoin.algebra_map_mem F S ⟨x, HT hx⟩
lemma adjoin.range_algebra_map_subset : set.range (algebra_map F E) ⊆ adjoin F S :=
begin
intros x hx,
cases hx with f hf,
rw ← hf,
exact adjoin.algebra_map_mem F S f,
end
instance adjoin.field_coe : has_coe_t F (adjoin F S) :=
{coe := λ x, ⟨algebra_map F E x, adjoin.algebra_map_mem F S x⟩}
lemma subset_adjoin : S ⊆ adjoin F S :=
λ x hx, field.mem_closure (or.inr hx)
instance adjoin.set_coe : has_coe_t S (adjoin F S) :=
{coe := λ x, ⟨x,subset_adjoin F S (subtype.mem x)⟩}
lemma adjoin.mono (T : set E) (h : S ⊆ T) : (adjoin F S : set E) ⊆ adjoin F T :=
field.closure_mono (set.union_subset (set.subset_union_left _ _)
(set.subset_union_of_subset_right h _))
instance adjoin.is_subfield : is_subfield (adjoin F S : set E) := field.closure.is_subfield
--Lean has trouble figuring this out on its own
instance adjoin.is_field : field (adjoin F S) := @is_subfield.field E _ ((adjoin F S) : set E) _
lemma adjoin_contains_field_as_subfield (F : set E) {HF : is_subfield F} : F ⊆ adjoin F S :=
λ x hx, adjoin.algebra_map_mem F S ⟨x, hx⟩
lemma subset_adjoin_of_subset_right {T : set E} (H : T ⊆ S) : T ⊆ adjoin F S :=
begin
intros x hx,
exact subset_adjoin F S (H hx),
end
/-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ⊆ K`. -/
lemma adjoin_subset_subfield {K : set E} [is_subfield K] (HF : set.range (algebra_map F E) ⊆ K)
(HS : S ⊆ K) : (adjoin F S : set E) ⊆ K :=
begin
apply field.closure_subset,
rw set.union_subset_iff,
exact ⟨HF, HS⟩,
end
/-- `S ⊆ adjoin F T` if and only if `adjoin F S ⊆ adjoin F T`. -/
lemma adjoin_subset_iff {T : set E} : S ⊆ adjoin F T ↔ (adjoin F S : set E) ⊆ adjoin F T :=
⟨λ h, adjoin_subset_subfield F S (adjoin.range_algebra_map_subset F T) h,
λ h, set.subset.trans (subset_adjoin F S) h⟩
lemma subfield_subset_adjoin_self {F : set E} {HF : is_subfield F} {T : set E} {HT : T ⊆ F} :
T ⊆ adjoin F S :=
λ x hx, adjoin.algebra_map_mem F S ⟨x,HT hx⟩
lemma adjoin_subset_adjoin_iff {F' : Type*} [field F'] [algebra F' E]
{S S' : set E} : (adjoin F S : set E) ⊆ adjoin F' S' ↔
set.range (algebra_map F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' :=
⟨λ h, ⟨trans (adjoin.range_algebra_map_subset _ _) h, trans (subset_adjoin _ _) h⟩,
λ ⟨hF, hS⟩, field.closure_subset (set.union_subset hF hS)⟩
/-- `F[S][T] = F[S ∪ T]` -/
lemma adjoin_adjoin_left (T : set E) : (adjoin (adjoin F S : set E) T : set E) = adjoin F (S ∪ T) :=
begin
apply set.eq_of_subset_of_subset; rw adjoin_subset_adjoin_iff; split,
{ exact algebra.set_range_subset (adjoin.mono _ _ _ (set.subset_union_left _ _)) },
{ exact subset_adjoin_of_subset_right _ _ (set.subset_union_right _ _) },
{ exact subset_adjoin_of_subset_left _ (adjoin.range_algebra_map_subset _ _) },
{ exact set.union_subset
(subset_adjoin_of_subset_left _ (subset_adjoin _ _))
(subset_adjoin _ _) },
end
/-- `F[S][T] = F[T][S]` -/
lemma adjoin_adjoin_comm (T : set E) :
(adjoin (adjoin F S : set E) T : set E) = (adjoin (adjoin F T : set E) S : set E) :=
by rw [adjoin_adjoin_left, adjoin_adjoin_left, set.union_comm]
/--
Variation on `set.insert` to enable good notation for adjoining elements to fields.
Used to preferentially use `singleton` rather than `insert` when adjoining one element.
-/
--this definition of notation is courtesy of Kyle Miller on zulip
class insert {α : Type*} (s : set α) :=
(insert : α → set α)
@[priority 1000]
instance insert_empty {α : Type*} : insert (∅ : set α) :=
{ insert := λ x, @singleton _ _ set.has_singleton x }
@[priority 900]
instance insert_nonempty {α : Type*} (s : set α) : insert s :=
{ insert := λ x, set.insert x s }
notation K`⟮`:std.prec.max_plus l:(foldr `, ` (h t, insert.insert t h) ∅) `⟯` := adjoin K l
section adjoin_simple
variables (α : E)
lemma mem_adjoin_simple_self : α ∈ F⟮α⟯ :=
subset_adjoin F {α} (set.mem_singleton α)
/-- generator of `F⟮α⟯` -/
def adjoin_simple.gen : F⟮α⟯ := ⟨α, mem_adjoin_simple_self F α⟩
@[simp] lemma adjoin_simple.algebra_map_gen : algebra_map F⟮α⟯ E (adjoin_simple.gen F α) = α := rfl
lemma adjoin_simple_adjoin_simple (β : E) : (F⟮α⟯⟮β⟯ : set E) = (F⟮α, β⟯ : set E) :=
adjoin_adjoin_left _ _ _
lemma adjoin_simple_comm (β : E) : (F⟮α⟯⟮β⟯ : set E) = (F⟮β⟯⟮α⟯ : set E) :=
adjoin_adjoin_comm _ _ _
end adjoin_simple
end adjoin_def
section adjoin_subalgebra_lattice
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E] {α : E} {S : set E}
lemma adjoin_eq_bot (h : S ⊆ (⊥ : subalgebra F E)) : adjoin F S = ⊥ :=
begin
rw eq_bot_iff,
intros x,
rw [subalgebra.mem_coe, subalgebra.mem_coe, algebra.mem_bot],
rw algebra.coe_bot at h,
apply adjoin_subset_subfield _ _ set.subset.rfl h,
end
lemma adjoin_simple_eq_bot (hα : α ∈ ((⊥ : subalgebra F E) : set E)) : F⟮α⟯ = (⊥ : subalgebra F E) :=
adjoin_eq_bot (set.singleton_subset_iff.mpr hα)
lemma adjoin_zero : F⟮0⟯ = (⊥ : subalgebra F E) :=
adjoin_simple_eq_bot (algebra.mem_bot.mpr (is_add_submonoid.zero_mem))
lemma adjoin_one : F⟮1⟯ = (⊥ : subalgebra F E) :=
adjoin_simple_eq_bot (algebra.mem_bot.mpr (is_submonoid.one_mem))
lemma sub_bot_of_adjoin_sub_bot (h : adjoin F S = ⊥) : S ⊆ (⊥ : subalgebra F E) :=
calc S ⊆ adjoin F S : subset_adjoin _ _
... = (⊥ : subalgebra F E) : congr_arg coe h
lemma mem_bot_of_adjoin_simple_sub_bot (h : F⟮α⟯ = ⊥) : α ∈ ((⊥ : subalgebra F E) : set E) :=
set.singleton_subset_iff.mp (sub_bot_of_adjoin_sub_bot h)
lemma adjoin_eq_bot_iff : S ⊆ (⊥ : subalgebra F E) ↔ adjoin F S = ⊥ :=
⟨adjoin_eq_bot, sub_bot_of_adjoin_sub_bot⟩
lemma adjoin_simple_eq_bot_iff : α ∈ (⊥ : subalgebra F E) ↔ F⟮α⟯ = ⊥ :=
⟨adjoin_simple_eq_bot, mem_bot_of_adjoin_simple_sub_bot⟩
section adjoin_dim
open finite_dimensional vector_space
lemma sub_bot_of_adjoin_dim_eq_one (h : dim F (adjoin F S) = 1) : S ⊆ (⊥ : subalgebra F E) :=
by rwa [adjoin_eq_bot_iff, ← subalgebra.dim_eq_one_iff]
lemma mem_bot_of_adjoin_simple_dim_eq_one (h : dim F F⟮α⟯ = 1) : α ∈ ((⊥ : subalgebra F E) : set E) :=
set.singleton_subset_iff.mp (sub_bot_of_adjoin_dim_eq_one h)
lemma adjoin_dim_eq_one_of_sub_bot (h : S ⊆ (⊥ : subalgebra F E)) : dim F (adjoin F S) = 1 :=
by { rw adjoin_eq_bot h, exact subalgebra.dim_bot }
lemma adjoin_simple_dim_eq_one_of_mem_bot (h : α ∈ ((⊥ : subalgebra F E) : set E)) : dim F F⟮α⟯ = 1 :=
adjoin_dim_eq_one_of_sub_bot (set.singleton_subset_iff.mpr h)
lemma adjoin_dim_eq_one_iff : dim F (adjoin F S) = 1 ↔ S ⊆ (⊥ : subalgebra F E) :=
⟨sub_bot_of_adjoin_dim_eq_one, adjoin_dim_eq_one_of_sub_bot⟩
lemma adjoin_simple_dim_eq_one_iff : dim F F⟮α⟯ = 1 ↔ α ∈ (⊥ : subalgebra F E) :=
⟨mem_bot_of_adjoin_simple_dim_eq_one, adjoin_simple_dim_eq_one_of_mem_bot⟩
lemma adjoin_findim_eq_one_iff : findim F (adjoin F S) = 1 ↔ S ⊆ (⊥ : subalgebra F E) :=
by rw [← adjoin_dim_eq_one_iff, subalgebra.dim_eq_one_iff, subalgebra.findim_eq_one_iff]
lemma adjoin_simple_findim_eq_one_iff : findim F F⟮α⟯ = 1 ↔ α ∈ (⊥ : subalgebra F E) :=
by rw [← adjoin_simple_dim_eq_one_iff, subalgebra.dim_eq_one_iff, subalgebra.findim_eq_one_iff]
/-- If `F⟮x⟯` has dimension `1` over `F` for every `x ∈ E` then `F = E`. -/
lemma bot_eq_top_of_dim_adjoin_eq_one (h : ∀ x : E, dim F F⟮x⟯ = 1) : (⊥ : subalgebra F E) = ⊤ :=
by simp [subalgebra.ext_iff, algebra.mem_top, ← adjoin_simple_dim_eq_one_iff, h]
lemma bot_eq_top_of_findim_adjoin_eq_one (h : ∀ x : E, findim F F⟮x⟯ = 1) :
(⊥ : subalgebra F E) = ⊤ :=
by simp [subalgebra.ext_iff, algebra.mem_top, ← adjoin_simple_findim_eq_one_iff, h]
/-- If `F⟮x⟯` has dimension `≤1` over `F` for every `x ∈ E` then `F = E`. -/
lemma bot_eq_top_of_findim_adjoin_le_one [finite_dimensional F E]
(h : ∀ x : E, findim F F⟮x⟯ ≤ 1) : (⊥ : subalgebra F E) = ⊤ :=
begin
have : ∀ x : E, findim F F⟮x⟯ = 1 := λ x, by linarith [h x, show 0 < findim F F⟮x⟯, from findim_pos],
exact bot_eq_top_of_findim_adjoin_eq_one this,
end
end adjoin_dim
end adjoin_subalgebra_lattice
end field
|
bcda730165a7aaeedbacafae585e98acba70ab79 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/print_inductive.lean | d5bcd043b15e2b6de4a89bbf45fcffaf61e121d4 | [
"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 | 44 | lean | #print inductive nat
#print inductive list
|
bfb7781e6e64cdb24299b2328aae1876a0ee6001 | f1b175e38ffc5cc1c7c5551a72d0dbaf70786f83 | /tactic/interactive.lean | 565e02f1af02817625a3004a0f68f90298388463 | [
"Apache-2.0"
] | permissive | mjendrusch/mathlib | df3ae884dd5ce38c7edf452bcbfd3baf4e3a6214 | 5c209edb7eb616a26f64efe3500f2b1ba95b8d55 | refs/heads/master | 1,585,663,284,800 | 1,539,062,055,000 | 1,539,062,055,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,425 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Sebastien Gouezel, Scott Morrison
-/
import data.dlist data.dlist.basic data.prod category.basic
tactic.basic tactic.rcases tactic.generalize_proofs
tactic.split_ifs logic.basic tactic.ext tactic.tauto tactic.replacer
open lean
open lean.parser
local postfix `?`:9001 := optional
local postfix *:9001 := many
namespace tactic
namespace interactive
open interactive interactive.types expr
/--
The `rcases` tactic is the same as `cases`, but with more flexibility in the
`with` pattern syntax to allow for recursive case splitting. The pattern syntax
uses the following recursive grammar:
```
patt ::= (patt_list "|")* patt_list
patt_list ::= id | "_" | "⟨" (patt ",")* patt "⟩"
```
A pattern like `⟨a, b, c⟩ | ⟨d, e⟩` will do a split over the inductive datatype,
naming the first three parameters of the first constructor as `a,b,c` and the
first two of the second constructor `d,e`. If the list is not as long as the
number of arguments to the constructor or the number of constructors, the
remaining variables will be automatically named. If there are nested brackets
such as `⟨⟨a⟩, b | c⟩ | d` then these will cause more case splits as necessary.
If there are too many arguments, such as `⟨a, b, c⟩` for splitting on
`∃ x, ∃ y, p x`, then it will be treated as `⟨a, ⟨b, c⟩⟩`, splitting the last
parameter as necessary.
`rcases` also has special support for quotient types: quotient induction into Prop works like
matching on the constructor `quot.mk`.
`rcases? e` will perform case splits on `e` in the same way as `rcases e`,
but rather than accepting a pattern, it does a maximal cases and prints the
pattern that would produce this case splitting. The default maximum depth is 5,
but this can be modified with `rcases? e : n`.
-/
meta def rcases : parse rcases_parse → tactic unit
| (p, sum.inl ids) := tactic.rcases p ids
| (p, sum.inr depth) := do
patt ← tactic.rcases_hint p depth,
pe ← pp p,
trace $ ↑"snippet: rcases " ++ pe ++ " with " ++ to_fmt patt
/--
The `rintro` tactic is a combination of the `intros` tactic with `rcases` to
allow for destructuring patterns while introducing variables. See `rcases` for
a description of supported patterns. For example, `rintros (a | ⟨b, c⟩) ⟨d, e⟩`
will introduce two variables, and then do case splits on both of them producing
two subgoals, one with variables `a d e` and the other with `b c d e`.
`rintro?` will introduce and case split on variables in the same way as
`rintro`, but will also print the `rintro` invocation that would have the same
result. Like `rcases?`, `rintro? : n` allows for modifying the
depth of splitting; the default is 5.
-/
meta def rintro : parse rintro_parse → tactic unit
| (sum.inl []) := intros []
| (sum.inl l) := tactic.rintro l
| (sum.inr depth) := do
ps ← tactic.rintro_hint depth,
trace $ ↑"snippet: rintro" ++ format.join (ps.map $ λ p,
format.space ++ format.group (p.format tt))
/-- Alias for `rintro`. -/
meta def rintros := rintro
/--
This is a "finishing" tactic modification of `simp`. The tactic `simpa [rules, ...] using e`
will simplify the hypothesis `e` using `rules`, then simplify the goal using `rules`, and
try to close the goal using `assumption`. If `e` is a term instead of a local constant,
it is first added to the local context using `have`.
-/
meta def simpa (use_iota_eqn : parse $ (tk "!")?) (no_dflt : parse only_flag)
(hs : parse simp_arg_list) (attr_names : parse with_ident_list)
(tgt : parse (tk "using" *> texpr)?) (cfg : simp_config_ext := {}) : tactic unit :=
let simp_at (lc) := try (simp use_iota_eqn no_dflt hs attr_names (loc.ns lc) cfg) >> (assumption <|> trivial) in
match tgt with
| none := get_local `this >> simp_at [some `this, none] <|> simp_at [none]
| some e := do
e ← i_to_expr e <|> do {
ty ← target,
e ← i_to_expr_strict ``(%%e : %%ty), -- for positional error messages, don't care about the result
pty ← pp ty, ptgt ← pp e,
-- Fail deliberately, to advise regarding `simp; exact` usage
fail ("simpa failed, 'using' expression type not directly " ++
"inferrable. Try:\n\nsimpa ... using\nshow " ++
to_fmt pty ++ ",\nfrom " ++ ptgt : format) },
match e with
| local_const _ lc _ _ := simp_at [some lc, none]
| e := do
t ← infer_type e,
assertv `this t e >> simp_at [some `this, none]
end
end
/-- `try_for n { tac }` executes `tac` for `n` ticks, otherwise uses `sorry` to close the goal.
Never fails. Useful for debugging. -/
meta def try_for (max : parse parser.pexpr) (tac : itactic) : tactic unit :=
do max ← i_to_expr_strict max >>= tactic.eval_expr nat,
λ s, match _root_.try_for max (tac s) with
| some r := r
| none := (tactic.trace "try_for timeout, using sorry" >> admit) s
end
/-- Multiple subst. `substs x y z` is the same as `subst x, subst y, subst z`. -/
meta def substs (l : parse ident*) : tactic unit :=
l.mmap' (λ h, get_local h >>= tactic.subst) >> try (tactic.reflexivity reducible)
/-- Unfold coercion-related definitions -/
meta def unfold_coes (loc : parse location) : tactic unit :=
unfold [``coe,``lift_t,``has_lift_t.lift,``coe_t,``has_coe_t.coe,``coe_b,``has_coe.coe,
``coe_fn, ``has_coe_to_fun.coe, ``coe_sort, ``has_coe_to_sort.coe] loc
/-- Unfold auxiliary definitions associated with the current declaration. -/
meta def unfold_aux : tactic unit :=
do tgt ← target,
name ← decl_name,
let to_unfold := (tgt.list_names_with_prefix name),
guard (¬ to_unfold.empty),
-- should we be using simp_lemmas.mk_default?
simp_lemmas.mk.dsimplify to_unfold.to_list tgt >>= tactic.change
/-- For debugging only. This tactic checks the current state for any
missing dropped goals and restores them. Useful when there are no
goals to solve but "result contains meta-variables". -/
meta def recover : tactic unit :=
metavariables >>= tactic.set_goals
/-- Like `try { tac }`, but in the case of failure it continues
from the failure state instead of reverting to the original state. -/
meta def continue (tac : itactic) : tactic unit :=
λ s, result.cases_on (tac s)
(λ a, result.success ())
(λ e ref, result.success ())
/-- Move goal `n` to the front. -/
meta def swap (n := 2) : tactic unit :=
do gs ← get_goals,
match gs.nth (n-1) with
| (some g) := set_goals (g :: gs.remove_nth (n-1))
| _ := skip
end
/-- Generalize proofs in the goal, naming them with the provided list. -/
meta def generalize_proofs : parse ident_* → tactic unit :=
tactic.generalize_proofs
/-- Clear all hypotheses starting with `_`, like `_match` and `_let_match`. -/
meta def clear_ : tactic unit := tactic.repeat $ do
l ← local_context,
l.reverse.mfirst $ λ h, do
name.mk_string s p ← return $ local_pp_name h,
guard (s.front = '_'),
cl ← infer_type h >>= is_class, guard (¬ cl),
tactic.clear h
/--
Same as the `congr` tactic, but takes an optional argument which gives
the depth of recursive applications. This is useful when `congr`
is too aggressive in breaking down the goal. For example, given
`⊢ f (g (x + y)) = f (g (y + x))`, `congr'` produces the goals `⊢ x = y`
and `⊢ y = x`, while `congr' 2` produces the intended `⊢ x + y = y + x`. -/
meta def congr' : parse (with_desc "n" small_nat)? → tactic unit
| (some 0) := failed
| o := focus1 (assumption <|> (congr_core >>
all_goals (reflexivity <|> try (congr' (nat.pred <$> o)))))
/--
Acts like `have`, but removes a hypothesis with the same name as
this one. For example if the state is `h : p ⊢ goal` and `f : p → q`,
then after `replace h := f h` the goal will be `h : q ⊢ goal`,
where `have h := f h` would result in the state `h : p, h : q ⊢ goal`.
This can be used to simulate the `specialize` and `apply at` tactics
of Coq. -/
meta def replace (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (q₂ : parse $ (tk ":=" *> texpr)?) : tactic unit :=
do let h := h.get_or_else `this,
old ← try_core (get_local h),
«have» h q₁ q₂,
match old, q₂ with
| none, _ := skip
| some o, some _ := tactic.clear o
| some o, none := swap >> tactic.clear o >> swap
end
/--
`apply_assumption` looks for an assumption of the form `... → ∀ _, ... → head`
where `head` matches the current goal.
alternatively, when encountering an assumption of the form `sg₀ → ¬ sg₁`,
after the main approach failed, the goal is dismissed and `sg₀` and `sg₁`
are made into the new goal.
optional arguments:
- asms: list of rules to consider instead of the local constants
- tac: a tactic to run on each subgoals after applying an assumption; if
this tactic fails, the corresponding assumption will be rejected and
the next one will be attempted.
-/
meta def apply_assumption
(asms : tactic (list expr) := local_context)
(tac : tactic unit := return ()) : tactic unit :=
tactic.apply_assumption asms tac
open nat
meta def mk_assumption_set (no_dflt : bool) (hs : list simp_arg_type) (attr : list name): tactic (list expr) :=
do (hs, gex, hex, all_hyps) ← decode_simp_arg_list hs,
hs ← hs.mmap i_to_expr_for_apply,
l ← attr.mmap $ λ a, attribute.get_instances a,
let l := l.join,
m ← list.mmap mk_const l,
let hs := (hs ++ m).filter $ λ h, expr.const_name h ∉ gex,
hs ← if no_dflt then
return hs
else
do { congr_fun ← mk_const `congr_fun,
congr_arg ← mk_const `congr_arg,
return (congr_fun :: congr_arg :: hs) },
if ¬ no_dflt ∨ all_hyps then do
ctx ← local_context,
return $ hs.append (ctx.filter (λ h, h.local_uniq_name ∉ hex)) -- remove local exceptions
else return hs
/--
`solve_by_elim` calls `apply_assumption` on the main goal to find an assumption whose head matches
and then repeatedly calls `apply_assumption` on the generated subgoals until no subgoals remain,
performing at most `max_rep` recursive steps.
`solve_by_elim` discharges the current goal or fails
`solve_by_elim` performs back-tracking if `apply_assumption` chooses an unproductive assumption
By default, the assumptions passed to apply_assumption are the local context, `congr_fun` and
`congr_arg`.
`solve_by_elim [h₁, h₂, ..., hᵣ]` also applies the named lemmas.
`solve_by_elim with attr₁ ... attrᵣ also applied all lemmas tagged with the specified attributes.
`solve_by_elim only [h₁, h₂, ..., hᵣ]` does not include the local context, `congr_fun`, or `congr_arg`
unless they are explicitly included.
`solve_by_elim [-id]` removes a specified assumption.
optional arguments:
- discharger: a subsidiary tactic to try at each step (e.g. `cc` may be helpful)
- max_rep: number of attempts at discharging generated sub-goals
-/
meta def solve_by_elim (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (opt : by_elim_opt := { }) : tactic unit :=
do asms ← mk_assumption_set no_dflt hs attr_names,
tactic.solve_by_elim { assumptions := return asms ..opt }
/--
`tautology` breaks down assumptions of the form `_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `∃ _, _`
and splits a goal of the form `_ ∧ _`, `_ ↔ _` or `∃ _, _` until it can be discharged
using `reflexivity` or `solve_by_elim`
-/
meta def tautology := tactic.tautology
/-- Shorter name for the tactic `tautology`. -/
meta def tauto := tautology
private meta def generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `eq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def generalize_arg_p : parser (pexpr × name) :=
with_desc "expr = id" $ parser.pexpr 0 >>= generalize_arg_p_aux
lemma {u} generalize_a_aux {α : Sort u}
(h : ∀ x : Sort u, (α → x) → x) : α := h α id
/--
Like `generalize` but also considers assumptions
specified by the user. The user can also specify to
omit the goal.
-/
meta def generalize_hyp (h : parse ident?) (_ : parse $ tk ":")
(p : parse generalize_arg_p)
(l : parse location) :
tactic unit :=
do h' ← get_unused_name `h,
x' ← get_unused_name `x,
g ← if ¬ l.include_goal then
do refine ``(generalize_a_aux _),
some <$> (prod.mk <$> tactic.intro x' <*> tactic.intro h')
else pure none,
n ← l.get_locals >>= tactic.revert_lst,
generalize h () p,
intron n,
match g with
| some (x',h') :=
do tactic.apply h',
tactic.clear h',
tactic.clear x'
| none := return ()
end
/--
Similar to `refine` but generates equality proof obligations
for every discrepancy between the goal and the type of the rule.
-/
meta def convert (sym : parse (with_desc "←" (tk "<-")?)) (r : parse texpr) (n : parse (tk "using" *> small_nat)?) : tactic unit :=
do v ← mk_mvar,
if sym.is_some
then refine ``(eq.mp %%v %%r)
else refine ``(eq.mpr %%v %%r),
gs ← get_goals,
set_goals [v],
congr' n,
gs' ← get_goals,
set_goals $ gs' ++ gs
meta def clean_ids : list name :=
[``id, ``id_rhs, ``id_delta]
/--
Remove identity functions from a term. These are normally
automatically generated with terms like `show t, from p` or
`(p : t)` which translate to some variant on `@id t p` in
order to retain the type. -/
meta def clean (q : parse texpr) : tactic unit :=
do tgt : expr ← target,
e ← i_to_expr_strict ``(%%q : %%tgt),
tactic.exact $ e.replace (λ e n,
match e with
| (app (app (const n _) _) e') :=
if n ∈ clean_ids then some e' else none
| (app (lam _ _ _ (var 0)) e') := some e'
| _ := none
end)
meta def source_fields (missing : list name) (e : pexpr) : tactic (list (name × pexpr)) :=
do e ← to_expr e,
t ← infer_type e,
let struct_n : name := t.get_app_fn.const_name,
fields ← expanded_field_list struct_n,
let exp_fields := fields.filter (λ x, x.2 ∈ missing),
exp_fields.mmap $ λ ⟨p,n⟩,
(prod.mk n ∘ to_pexpr) <$> mk_mapp (n.update_prefix p) [none,some e]
meta def collect_struct' : pexpr → state_t (list $ expr×structure_instance_info) tactic pexpr | e :=
do some str ← pure (e.get_structure_instance_info)
| e.traverse collect_struct',
v ← monad_lift mk_mvar,
modify (list.cons (v,str)),
pure $ to_pexpr v
meta def collect_struct (e : pexpr) : tactic $ pexpr × list (expr×structure_instance_info) :=
prod.map id list.reverse <$> (collect_struct' e).run []
meta def refine_one (str : structure_instance_info) :
tactic $ list (expr×structure_instance_info) :=
do tgt ← target,
let struct_n : name := tgt.get_app_fn.const_name,
exp_fields ← expanded_field_list struct_n,
let missing_f := exp_fields.filter (λ f, (f.2 : name) ∉ str.field_names),
(src_field_names,src_field_vals) ← (@list.unzip name _ ∘ list.join) <$> str.sources.mmap (source_fields $ missing_f.map prod.snd),
let provided := exp_fields.filter (λ f, (f.2 : name) ∈ str.field_names),
let missing_f' := missing_f.filter (λ x, x.2 ∉ src_field_names),
vs ← mk_mvar_list missing_f'.length,
(field_values,new_goals) ← list.unzip <$> (str.field_values.mmap collect_struct : tactic _),
e' ← to_expr $ pexpr.mk_structure_instance
{ struct := some struct_n
, field_names := str.field_names ++ missing_f'.map prod.snd ++ src_field_names
, field_values := field_values ++ vs.map to_pexpr ++ src_field_vals },
tactic.exact e',
gs ← with_enable_tags (
mzip_with (λ (n : name × name) v, do
set_goals [v],
try (interactive.unfold (provided.map $ λ ⟨s,f⟩, f.update_prefix s) (loc.ns [none])),
apply_auto_param
<|> apply_opt_param
<|> (set_main_tag [`_field,n.2,n.1]),
get_goals)
missing_f' vs),
set_goals gs.join,
return new_goals.join
meta def refine_recursively : expr × structure_instance_info → tactic (list expr) | (e,str) :=
do set_goals [e],
rs ← refine_one str,
gs ← get_goals,
gs' ← rs.mmap refine_recursively,
return $ gs'.join ++ gs
/--
`refine_struct { .. }` acts like `refine` but works only with structure instance
literals. It creates a goal for each missing field and tags it with the name of the
field so that `have_field` can be used to generically refer to the field currently
being refined.
As an example, we can use `refine_struct` to automate the construction semigroup
instances:
```
refine_struct ( { .. } : semigroup α ),
-- case semigroup, mul
-- α : Type u,
-- ⊢ α → α → α
-- case semigroup, mul_assoc
-- α : Type u,
-- ⊢ ∀ (a b c : α), a * b * c = a * (b * c)
```
-/
meta def refine_struct : parse texpr → tactic unit | e :=
do (x,xs) ← collect_struct e,
refine x,
gs ← get_goals,
xs' ← xs.mmap refine_recursively,
set_goals (xs'.join ++ gs)
/--
`guard_hyp h := t` fails if the hypothesis `h` does not have type `t`.
We use this tactic for writing tests.
Fixes `guard_hyp` by instantiating meta variables
-/
meta def guard_hyp' (n : parse ident) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_eq h p
meta def guard_hyp_nums (n : ℕ) : tactic unit :=
do k ← local_context,
guard (n = k.length) <|> fail format!"{k.length} hypotheses found"
meta def guard_tags (tags : parse ident*) : tactic unit :=
do (t : list name) ← get_main_tag,
guard (t = tags)
meta def get_current_field : tactic name :=
do [_,field,str] ← get_main_tag,
expr.const_name <$> resolve_name (field.update_prefix str)
meta def field (n : parse ident) (tac : itactic) : tactic unit :=
do gs ← get_goals,
ts ← gs.mmap get_tag,
([g],gs') ← pure $ (list.zip gs ts).partition (λ x, x.snd.nth 1 = some n),
set_goals [g.1],
tac, done,
set_goals $ gs'.map prod.fst
/--
`have_field`, used after `refine_struct _` poses `field` as a local constant
with the type of the field of the current goal:
```
refine_struct ({ .. } : semigroup α),
{ have_field, ... },
{ have_field, ... },
```
behaves like
```
refine_struct ({ .. } : semigroup α),
{ have field := @semigroup.mul, ... },
{ have field := @semigroup.mul_assoc, ... },
```
-/
meta def have_field : tactic unit :=
propagate_tags $
get_current_field
>>= mk_const
>>= note `field none
>> return ()
/-- `apply_field` functions as `have_field, apply field, clear field` -/
meta def apply_field : tactic unit :=
propagate_tags $
get_current_field >>= applyc
/--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times.
`n` is 50 by default. `hs` can contain user attributes: in this case all theorems with this
attribute are added to the list of rules.
example, with or without user attribute:
```
@[user_attribute]
meta def mono_rules : user_attribute :=
{ name := `mono_rules,
descr := "lemmas usable to prove monotonicity" }
attribute [mono_rules] add_le_add mul_le_mul_of_nonneg_right
lemma my_test {a b c d e : real} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules mono_rules
-- any of the following lines would also work:
-- add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3
-- by apply_rules [add_le_add, mul_le_mul_of_nonneg_right]
-- by apply_rules [mono_rules]
```
-/
meta def apply_rules (hs : parse pexpr_list_or_texpr) (n : nat := 50) : tactic unit :=
tactic.apply_rules hs n
meta def return_cast (f : option expr) (t : option (expr × expr))
(es : list (expr × expr × expr))
(e x x' eq_h : expr) :
tactic (option (expr × expr) × list (expr × expr × expr)) :=
(do guard (¬ e.has_var),
unify x x',
u ← mk_meta_univ,
f ← f <|> to_expr ``(@id %%(expr.sort u : expr)),
t' ← infer_type e,
some (f',t) ← pure t | return (some (f,t'), (e,x',eq_h) :: es),
infer_type e >>= is_def_eq t,
unify f f',
return (some (f,t), (e,x',eq_h) :: es)) <|>
return (t, es)
meta def list_cast_of_aux (x : expr) (t : option (expr × expr))
(es : list (expr × expr × expr)) :
expr → tactic (option (expr × expr) × list (expr × expr × expr))
| e@`(cast %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mp %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mpr %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast none t es e x x'
| e@`(@eq.subst %%α %%p %%a %%b %%eq_h %%x') := return_cast p t es e x x' eq_h
| e@`(@eq.substr %%α %%p %%a %%b %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast p t es e x x'
| e@`(@eq.rec %%α %%a %%f %%x' _ %%eq_h) := return_cast f t es e x x' eq_h
| e@`(@eq.rec_on %%α %%a %%f %%b %%eq_h %%x') := return_cast f t es e x x' eq_h
| e := return (t,es)
meta def list_cast_of (x tgt : expr) : tactic (list (expr × expr × expr)) :=
(list.reverse ∘ prod.snd) <$> tgt.mfold (none, []) (λ e i es, list_cast_of_aux x es.1 es.2 e)
private meta def h_generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `heq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def h_generalize_arg_p : parser (pexpr × name) :=
with_desc "expr == id" $ parser.pexpr 0 >>= h_generalize_arg_p_aux
/--
`h_generalize Hx : e == x` matches on `cast _ e` in the goal and replaces it with
`x`. It also adds `Hx : e == x` as an assumption. If `cast _ e` appears multiple
times (not necessarily with the same proof), they are all replaced by `x`. `cast`
`eq.mp`, `eq.mpr`, `eq.subst`, `eq.substr`, `eq.rec` and `eq.rec_on` are all treated
as casts.
`h_generalize Hx : e == x with h` adds hypothesis `α = β` with `e : α, x : β`.
`h_generalize Hx : e == x with _` chooses automatically chooses the name of
assumption `α = β`.
`h_generalize! Hx : e == x` reverts `Hx`.
when `Hx` is omitted, assumption `Hx : e == x` is not added.
-/
meta def h_generalize (rev : parse (tk "!")?)
(h : parse ident_?)
(_ : parse (tk ":"))
(arg : parse h_generalize_arg_p)
(eqs_h : parse ( (tk "with" >> pure <$> ident_) <|> pure [])) :
tactic unit :=
do let (e,n) := arg,
let h' := if h = `_ then none else h,
h' ← (h' : tactic name) <|> get_unused_name ("h" ++ n.to_string : string),
e ← to_expr e,
tgt ← target,
((e,x,eq_h)::es) ← list_cast_of e tgt | fail "no cast found",
interactive.generalize h' () (to_pexpr e, n),
asm ← get_local h',
v ← get_local n,
hs ← es.mmap (λ ⟨e,_⟩, mk_app `eq [e,v]),
(eqs_h.zip [e]).mmap' (λ ⟨h,e⟩, do
h ← if h ≠ `_ then pure h else get_unused_name `h,
() <$ note h none eq_h ),
hs.mmap' (λ h,
do h' ← assert `h h,
tactic.exact asm,
try (rewrite_target h'),
tactic.clear h' ),
when h.is_some (do
(to_expr ``(heq_of_eq_rec_left %%eq_h %%asm)
<|> to_expr ``(heq_of_eq_mp %%eq_h %%asm))
>>= note h' none >> pure ()),
tactic.clear asm,
when rev.is_some (interactive.revert [n])
/-- `choose names using e` assumes that `e` is a hypothesis or expression of the type
`∀x y z, ∃a b c, p x y z a b c`.
It will skolemize `e` and use the names given by `ns` to assign names to the functions resulting
from the existential quantifiers.
Example:
```lean
example (h : ∀n m : ℕ, ∃i j, m = n + i ∨ m + j = n) : true :=
begin
choose i j h using h,
guard_hyp i := ℕ → ℕ → ℕ,
guard_hyp j := ℕ → ℕ → ℕ,
guard_hyp h := ∀ (n m : ℕ), m = n + i n m ∨ m + j n m = n,
trivial
end
```
-/
meta def choose (first : parse ident) (names : parse ident*) (tgt : parse (tk "using" *> texpr)?) :
tactic unit := do
tgt ← match tgt with
| none := get_local `this
| some e := tactic.i_to_expr_strict e
end,
tactic.choose tgt (first :: names),
try (tactic.clear tgt)
end interactive
end tactic
example (h : ∀n m : ℕ, ∃i j, m = n + i ∨ m + j = n) : true :=
begin
choose i j h using show ∀n m : ℕ, ∃i j, m = n + i ∨ m + j = n, from h,
guard_hyp i := ℕ → ℕ → ℕ,
guard_hyp j := ℕ → ℕ → ℕ,
guard_hyp h := ∀ (n m : ℕ), m = n + i n m ∨ m + j n m = n,
trivial
end
|
17030db53bb95502d943d42a2072fa2585279b4e | fa01e273a2a9f22530e6adb1ed7d4f54bb15c8d7 | /src/N2O/Network/Web/HTTP.lean | 04bf97061bcdcfd377295ca9d709bd7d9cb0b30d | [
"LicenseRef-scancode-mit-taylor-variant",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | o89/n2o | 4c99afb11fff0a1e3dae6b3bc8a3b7fc42c314ac | 58c1fbf4ef892ed86bdc6b78ec9ca5a403715c2d | refs/heads/master | 1,670,314,676,229 | 1,669,086,375,000 | 1,669,086,375,000 | 200,506,953 | 16 | 6 | null | null | null | null | UTF-8 | Lean | false | false | 519 | lean | import N2O.Network.Internal
@[extern 2 "lean_set_handler"] constant setHandler (handler : WS → Result) : IO Unit
@[extern 1 "lean_stop_server"] constant stopServer : IO Unit
@[extern 3 "lean_run_server"] constant runServer (addr : String) (port : UInt16) : IO Unit
def canonicalHandler (handler : Handler) (socket : WS) : Result :=
handler socket.toReq socket.question
def startServer (handler : Handler) (addr : String × UInt16) : IO Unit :=
do setHandler (canonicalHandler handler); runServer addr.fst addr.snd
|
2432b7117231e924521eefe40b368f37ee96d3f7 | f3a5af2927397cf346ec0e24312bfff077f00425 | /src/game/world10/level10.lean | 20eb6db69d88a03fef8fde3f4ab3f03818eb060a | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/natural_number_game | 05c39e1586408cfb563d1a12e1085a90726ab655 | f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd | refs/heads/master | 1,688,570,964,990 | 1,636,908,242,000 | 1,636,908,242,000 | 195,403,790 | 277 | 84 | Apache-2.0 | 1,694,547,955,000 | 1,562,328,792,000 | Lean | UTF-8 | Lean | false | false | 330 | lean | import game.world10.level9 -- hide
namespace mynat -- hide
/-
# Inequality world.
## Level 10: `le_succ_self`
Can you find the two-line proof?
-/
/- Lemma
For all naturals $a$, $a\le\operatorname{succ}(a).$
-/
lemma le_succ_self (a : mynat) : a ≤ succ a :=
begin [nat_num_game]
use 1,
refl,
end
end mynat -- hide
|
11d133a4ae8b8cf02e27f27d2687248623466621 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/nestedDo.lean | 5806d98b15bad52579b812bc16256a8cadb9e9e7 | [
"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 | 152 | lean |
def f (x : Nat) : StateM Nat Nat := do
let y ← do
modify (·+1)
let s ← get
pure $ s + x
pure $ y + 1
theorem ex1 : (f 5).run' 2 = 9 :=
rfl
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.