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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6ce06b5b886e9a4ceb592d13773603c53e5cc7ea | 02005f45e00c7ecf2c8ca5db60251bd1e9c860b5 | /src/ring_theory/simple_module.lean | d2ed8d89c0df15a4cabfecb483d4a6a75a7195cd | [
"Apache-2.0"
] | permissive | anthony2698/mathlib | 03cd69fe5c280b0916f6df2d07c614c8e1efe890 | 407615e05814e98b24b2ff322b14e8e3eb5e5d67 | refs/heads/master | 1,678,792,774,873 | 1,614,371,563,000 | 1,614,371,563,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,316 | 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 linear_algebra.basic
import order.atoms
/-!
# Simple Modules
## Main Definitions
* `is_simple_module` indicates that a module has no proper submodules
(the only submodules are `⊥` and `⊤`).
* `is_semisimple_module` indicates that every submodule has a complement, or equivalently,
the module is a direct sum of simple modules.
* A `division_ring` structure on the endomorphism ring of a simple module.
## Main Results
* Schur's Lemma: `bijective_or_eq_zero` shows that a linear map between simple modules
is either bijective or 0, leading to a `division_ring` structure on the endomorphism ring.
## TODO
* Artin-Wedderburn Theory
* Unify with the work on Schur's Lemma in a category theory context
-/
variables (R : Type*) [ring R] (M : Type*) [add_comm_group M] [module R M]
/-- A module is simple when it has only two submodules, `⊥` and `⊤`. -/
abbreviation is_simple_module := (is_simple_lattice (submodule R M))
/-- A module is semisimple when every submodule has a complement, or equivalently, the module
is a direct sum of simple modules. -/
abbreviation is_semisimple_module := (is_complemented (submodule R M))
-- Making this an instance causes the linter to complain of "dangerous instances"
theorem is_simple_module.nontrivial [is_simple_module R M] : nontrivial M :=
⟨⟨0, begin
have h : (⊥ : submodule R M) ≠ ⊤ := bot_ne_top,
contrapose! h,
ext,
simp [submodule.mem_bot,submodule.mem_top, h x],
end⟩⟩
variables {R} {M} {m : submodule R M} {N : Type*} [add_comm_group N] [module R N]
theorem is_simple_module_iff_is_atom :
is_simple_module R m ↔ is_atom m :=
begin
rw ← set.is_simple_lattice_Iic_iff_is_atom,
apply order_iso.is_simple_lattice_iff,
exact submodule.map_subtype.rel_iso m,
end
namespace is_simple_module
variable [hm : is_simple_module R m]
@[simp]
lemma is_atom : is_atom m := is_simple_module_iff_is_atom.1 hm
end is_simple_module
theorem is_semisimple_of_Sup_simples_eq_top
(h : Sup {m : submodule R M | is_simple_module R m} = ⊤) :
is_semisimple_module R M :=
is_complemented_of_Sup_atoms_eq_top (by simp_rw [← h, is_simple_module_iff_is_atom])
namespace is_semisimple_module
variable [is_semisimple_module R M]
theorem Sup_simples_eq_top : Sup {m : submodule R M | is_simple_module R m} = ⊤ :=
begin
simp_rw is_simple_module_iff_is_atom,
exact Sup_atoms_eq_top,
end
instance is_semisimple_submodule {m : submodule R M} : is_semisimple_module R m :=
begin
have f : submodule R m ≃o set.Iic m := submodule.map_subtype.rel_iso m,
exact f.is_complemented_iff.2 is_modular_lattice.is_complemented_Iic,
end
end is_semisimple_module
theorem is_semisimple_iff_top_eq_Sup_simples :
Sup {m : submodule R M | is_simple_module R m} = ⊤ ↔ is_semisimple_module R M :=
⟨is_semisimple_of_Sup_simples_eq_top, by { introI, exact is_semisimple_module.Sup_simples_eq_top }⟩
namespace linear_map
theorem injective_or_eq_zero [is_simple_module R M] (f : M →ₗ[R] N) :
function.injective f ∨ f = 0 :=
begin
rw [← ker_eq_bot, ← ker_eq_top],
apply eq_bot_or_eq_top,
end
theorem injective_of_ne_zero [is_simple_module R M] {f : M →ₗ[R] N} (h : f ≠ 0) :
function.injective f :=
f.injective_or_eq_zero.resolve_right h
theorem surjective_or_eq_zero [is_simple_module R N] (f : M →ₗ[R] N) :
function.surjective f ∨ f = 0 :=
begin
rw [← range_eq_top, ← range_eq_bot, or_comm],
apply eq_bot_or_eq_top,
end
theorem surjective_of_ne_zero [is_simple_module R N] {f : M →ₗ[R] N} (h : f ≠ 0) :
function.surjective f :=
f.surjective_or_eq_zero.resolve_right h
/-- Schur's Lemma for linear maps between (possibly distinct) simple modules -/
theorem bijective_or_eq_zero [is_simple_module R M] [is_simple_module R N]
(f : M →ₗ[R] N) :
function.bijective f ∨ f = 0 :=
begin
by_cases h : f = 0,
{ right,
exact h },
exact or.intro_left _ ⟨injective_of_ne_zero h, surjective_of_ne_zero h⟩,
end
theorem bijective_of_ne_zero [is_simple_module R M] [is_simple_module R N]
{f : M →ₗ[R] N} (h : f ≠ 0):
function.bijective f :=
f.bijective_or_eq_zero.resolve_right h
/-- Schur's Lemma makes the endomorphism ring of a simple module a division ring. -/
noncomputable instance [decidable_eq (module.End R M)] [is_simple_module R M] :
division_ring (module.End R M) :=
{ inv := λ f, if h : f = 0 then 0 else (linear_map.inverse f
(equiv.of_bijective _ (bijective_of_ne_zero h)).inv_fun
(equiv.of_bijective _ (bijective_of_ne_zero h)).left_inv
(equiv.of_bijective _ (bijective_of_ne_zero h)).right_inv),
exists_pair_ne := ⟨0, 1, begin
haveI := is_simple_module.nontrivial R M,
have h := exists_pair_ne M,
contrapose! h,
intros x y,
simp_rw [ext_iff, one_app, zero_apply] at h,
rw [← h x, h y],
end⟩,
mul_inv_cancel := begin
intros a a0,
change (a * (dite _ _ _)) = 1,
ext,
rw [dif_neg a0, mul_eq_comp, one_app, comp_apply],
exact (equiv.of_bijective _ (bijective_of_ne_zero a0)).right_inv x,
end,
inv_zero := dif_pos rfl,
.. (linear_map.endomorphism_ring : ring (module.End R M))}
end linear_map
|
4b5e42b14fd76de155f8e67dc7c32a7d4402d826 | d31b9f832ff922a603f76cf32e0f3aa822640508 | /src/hott/init/meta/simp_attr.lean | 053912376fe07ab3e8336d85bbfae80eb350e701 | [
"Apache-2.0"
] | permissive | javra/hott3 | 6e7a9e72a991a2fae32e5764982e521dca617b16 | cd51f2ab2aa48c1246a188f9b525b30f76c3d651 | refs/heads/master | 1,585,819,679,148 | 1,531,232,382,000 | 1,536,682,965,000 | 154,294,022 | 0 | 0 | Apache-2.0 | 1,540,284,376,000 | 1,540,284,375,000 | null | UTF-8 | Lean | false | false | 1,557 | lean | /-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .support
open tactic expr
namespace hott
private meta def open_pis : expr → tactic (expr × list expr) | e := do
e ← whnf e,
if e.is_pi then do
x ← mk_local' e.binding_name e.binding_info e.binding_domain,
(e, xs) ← open_pis (e.binding_body.instantiate_var x),
return (e, x::xs)
else return (e, [])
private meta def copy_idp_lemma (cn : name) (prio : option ℕ) (pers : bool) : tactic unit := do
let rfl_lemma_name := cn <.> "_idp_to_rfl",
d ← get_decl cn,
(t, xs) ← open_pis d.type,
match t.get_app_fn with
| (const `hott.eq [u]) := do
[A, lhs, rhs] ← return t.get_app_args,
is_idp ← option.is_some <$> try_core (is_def_eq lhs rhs), when is_idp $ do
let t' := pis xs (app_of_list (const ``eq [u.succ]) [A, lhs, rhs]),
let v' := lambdas xs (app_of_list (const ``rfl [u.succ]) [A, lhs]),
add_decl (mk_definition rfl_lemma_name d.univ_params t' v'),
set_basic_attribute `_refl_lemma rfl_lemma_name tt,
set_basic_attribute `simp rfl_lemma_name tt
| _ := skip
end
-- TODO(gabriel): propagate priority & persistence (currently crashes)
@[user_attribute]
meta def hsimp_attr : user_attribute := {
name := `hsimp,
descr := "HoTT simplification lemma (converts idp-lemmas to rfl-lemmas for dsimp)",
after_set := some (λ n prio pers, do
copy_idp_lemma n none pers,
set_basic_attribute `simp n pers none),
}
end hott |
5be47a6ea7be5b4b20b7bc19d91d3e6d9151f58e | 4727251e0cd73359b15b664c3170e5d754078599 | /src/category_theory/epi_mono.lean | 21c763c5e3f33bcfff0d57ea79d8ce2089f14f5d | [
"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 | 8,134 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Scott Morrison
-/
import category_theory.adjunction.basic
import category_theory.opposites
import category_theory.groupoid
/-!
# Facts about epimorphisms and monomorphisms.
The definitions of `epi` and `mono` are in `category_theory.category`,
since they are used by some lemmas for `iso`, which is used everywhere.
-/
universes v₁ v₂ u₁ u₂
namespace category_theory
variables {C : Type u₁} [category.{v₁} C]
instance unop_mono_of_epi {A B : Cᵒᵖ} (f : A ⟶ B) [epi f] : mono f.unop :=
⟨λ Z g h eq, quiver.hom.op_inj ((cancel_epi f).1 (quiver.hom.unop_inj eq))⟩
instance unop_epi_of_mono {A B : Cᵒᵖ} (f : A ⟶ B) [mono f] : epi f.unop :=
⟨λ Z g h eq, quiver.hom.op_inj ((cancel_mono f).1 (quiver.hom.unop_inj eq))⟩
instance op_mono_of_epi {A B : C} (f : A ⟶ B) [epi f] : mono f.op :=
⟨λ Z g h eq, quiver.hom.unop_inj ((cancel_epi f).1 (quiver.hom.op_inj eq))⟩
instance op_epi_of_mono {A B : C} (f : A ⟶ B) [mono f] : epi f.op :=
⟨λ Z g h eq, quiver.hom.unop_inj ((cancel_mono f).1 (quiver.hom.op_inj eq))⟩
section
variables {D : Type u₂} [category.{v₂} D]
lemma left_adjoint_preserves_epi {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G)
{X Y : C} {f : X ⟶ Y} (hf : epi f) : epi (F.map f) :=
begin
constructor,
intros Z g h H,
replace H := congr_arg (adj.hom_equiv X Z) H,
rwa [adj.hom_equiv_naturality_left, adj.hom_equiv_naturality_left,
cancel_epi, equiv.apply_eq_iff_eq] at H
end
lemma right_adjoint_preserves_mono {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G)
{X Y : D} {f : X ⟶ Y} (hf : mono f) : mono (G.map f) :=
begin
constructor,
intros Z g h H,
replace H := congr_arg (adj.hom_equiv Z Y).symm H,
rwa [adj.hom_equiv_naturality_right_symm, adj.hom_equiv_naturality_right_symm,
cancel_mono, equiv.apply_eq_iff_eq] at H
end
instance is_equivalence.epi_map {F : C ⥤ D} [is_left_adjoint F] {X Y : C} {f : X ⟶ Y}
[h : epi f] : epi (F.map f) :=
left_adjoint_preserves_epi (adjunction.of_left_adjoint F) h
instance is_equivalence.mono_map {F : C ⥤ D} [is_right_adjoint F] {X Y : C} {f : X ⟶ Y}
[h : mono f] : mono (F.map f) :=
right_adjoint_preserves_mono (adjunction.of_right_adjoint F) h
lemma faithful_reflects_epi (F : C ⥤ D) [faithful F] {X Y : C} {f : X ⟶ Y}
(hf : epi (F.map f)) : epi f :=
⟨λ Z g h H, F.map_injective $
by rw [←cancel_epi (F.map f), ←F.map_comp, ←F.map_comp, H]⟩
lemma faithful_reflects_mono (F : C ⥤ D) [faithful F] {X Y : C} {f : X ⟶ Y}
(hf : mono (F.map f)) : mono f :=
⟨λ Z g h H, F.map_injective $
by rw [←cancel_mono (F.map f), ←F.map_comp, ←F.map_comp, H]⟩
end
/--
A split monomorphism is a morphism `f : X ⟶ Y` admitting a retraction `retraction f : Y ⟶ X`
such that `f ≫ retraction f = 𝟙 X`.
Every split monomorphism is a monomorphism.
-/
class split_mono {X Y : C} (f : X ⟶ Y) :=
(retraction : Y ⟶ X)
(id' : f ≫ retraction = 𝟙 X . obviously)
/--
A split epimorphism is a morphism `f : X ⟶ Y` admitting a section `section_ f : Y ⟶ X`
such that `section_ f ≫ f = 𝟙 Y`.
(Note that `section` is a reserved keyword, so we append an underscore.)
Every split epimorphism is an epimorphism.
-/
class split_epi {X Y : C} (f : X ⟶ Y) :=
(section_ : Y ⟶ X)
(id' : section_ ≫ f = 𝟙 Y . obviously)
/-- The chosen retraction of a split monomorphism. -/
def retraction {X Y : C} (f : X ⟶ Y) [split_mono f] : Y ⟶ X := split_mono.retraction f
@[simp, reassoc]
lemma split_mono.id {X Y : C} (f : X ⟶ Y) [split_mono f] : f ≫ retraction f = 𝟙 X :=
split_mono.id'
/-- The retraction of a split monomorphism is itself a split epimorphism. -/
instance retraction_split_epi {X Y : C} (f : X ⟶ Y) [split_mono f] : split_epi (retraction f) :=
{ section_ := f }
/-- A split mono which is epi is an iso. -/
lemma is_iso_of_epi_of_split_mono {X Y : C} (f : X ⟶ Y) [split_mono f] [epi f] : is_iso f :=
⟨⟨retraction f, ⟨by simp, by simp [← cancel_epi f]⟩⟩⟩
/--
The chosen section of a split epimorphism.
(Note that `section` is a reserved keyword, so we append an underscore.)
-/
def section_ {X Y : C} (f : X ⟶ Y) [split_epi f] : Y ⟶ X := split_epi.section_ f
@[simp, reassoc]
lemma split_epi.id {X Y : C} (f : X ⟶ Y) [split_epi f] : section_ f ≫ f = 𝟙 Y :=
split_epi.id'
/-- The section of a split epimorphism is itself a split monomorphism. -/
instance section_split_mono {X Y : C} (f : X ⟶ Y) [split_epi f] : split_mono (section_ f) :=
{ retraction := f }
/-- A split epi which is mono is an iso. -/
lemma is_iso_of_mono_of_split_epi {X Y : C} (f : X ⟶ Y) [mono f] [split_epi f] : is_iso f :=
⟨⟨section_ f, ⟨by simp [← cancel_mono f], by simp⟩⟩⟩
/-- Every iso is a split mono. -/
@[priority 100]
noncomputable
instance split_mono.of_iso {X Y : C} (f : X ⟶ Y) [is_iso f] : split_mono f :=
{ retraction := inv f }
/-- Every iso is a split epi. -/
@[priority 100]
noncomputable
instance split_epi.of_iso {X Y : C} (f : X ⟶ Y) [is_iso f] : split_epi f :=
{ section_ := inv f }
/-- Every split mono is a mono. -/
@[priority 100]
instance split_mono.mono {X Y : C} (f : X ⟶ Y) [split_mono f] : mono f :=
{ right_cancellation := λ Z g h w, begin replace w := w =≫ retraction f, simpa using w, end }
/-- Every split epi is an epi. -/
@[priority 100]
instance split_epi.epi {X Y : C} (f : X ⟶ Y) [split_epi f] : epi f :=
{ left_cancellation := λ Z g h w, begin replace w := section_ f ≫= w, simpa using w, end }
/-- Every split mono whose retraction is mono is an iso. -/
lemma is_iso.of_mono_retraction {X Y : C} {f : X ⟶ Y} [split_mono f] [mono $ retraction f]
: is_iso f :=
⟨⟨retraction f, ⟨by simp, (cancel_mono_id $ retraction f).mp (by simp)⟩⟩⟩
/-- Every split epi whose section is epi is an iso. -/
lemma is_iso.of_epi_section {X Y : C} {f : X ⟶ Y} [split_epi f] [epi $ section_ f]
: is_iso f :=
⟨⟨section_ f, ⟨(cancel_epi_id $ section_ f).mp (by simp), by simp⟩⟩⟩
/-- A category where every morphism has a `trunc` retraction is computably a groupoid. -/
-- FIXME this has unnecessarily become noncomputable!
noncomputable
def groupoid.of_trunc_split_mono
(all_split_mono : ∀ {X Y : C} (f : X ⟶ Y), trunc (split_mono f)) :
groupoid.{v₁} C :=
begin
apply groupoid.of_is_iso,
intros X Y f,
trunc_cases all_split_mono f,
trunc_cases all_split_mono (retraction f),
apply is_iso.of_mono_retraction,
end
section
variables (C)
/-- A split mono category is a category in which every monomorphism is split. -/
class split_mono_category :=
(split_mono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [mono f], split_mono f)
/-- A split epi category is a category in which every epimorphism is split. -/
class split_epi_category :=
(split_epi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [epi f], split_epi f)
end
/-- In a category in which every monomorphism is split, every monomorphism splits. This is not an
instance because it would create an instance loop. -/
def split_mono_of_mono [split_mono_category C] {X Y : C} (f : X ⟶ Y) [mono f] : split_mono f :=
split_mono_category.split_mono_of_mono _
/-- In a category in which every epimorphism is split, every epimorphism splits. This is not an
instance because it would create an instance loop. -/
def split_epi_of_epi [split_epi_category C] {X Y : C} (f : X ⟶ Y) [epi f] : split_epi f :=
split_epi_category.split_epi_of_epi _
section
variables {D : Type u₂} [category.{v₂} D]
/-- Split monomorphisms are also absolute monomorphisms. -/
instance {X Y : C} (f : X ⟶ Y) [split_mono f] (F : C ⥤ D) : split_mono (F.map f) :=
{ retraction := F.map (retraction f),
id' := by { rw [←functor.map_comp, split_mono.id, functor.map_id], } }
/-- Split epimorphisms are also absolute epimorphisms. -/
instance {X Y : C} (f : X ⟶ Y) [split_epi f] (F : C ⥤ D) : split_epi (F.map f) :=
{ section_ := F.map (section_ f),
id' := by { rw [←functor.map_comp, split_epi.id, functor.map_id], } }
end
end category_theory
|
07fc52cbc3a6b7614f6fff5f02f1fe9ebc980bed | 4727251e0cd73359b15b664c3170e5d754078599 | /src/linear_algebra/matrix/circulant.lean | 99feb26996f5b9837c7bc73610b74a347787ce55 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 6,836 | lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import linear_algebra.matrix.symmetric
/-!
# Circulant matrices
This file contains the definition and basic results about circulant matrices.
Given a vector `v : n → α` indexed by a type that is endowed with subtraction,
`matrix.circulant v` is the matrix whose `(i, j)`th entry is `v (i - j)`.
## Main results
- `matrix.circulant`: the circulant matrix generated by a given vector `v : n → α`.
- `matrix.circulant_mul`: the product of two circulant matrices `circulant v` and `circulant w` is
the circulant matrix generated by `mul_vec (circulant v) w`.
- `matrix.circulant_mul_comm`: multiplication of circulant matrices commutes when the elements do.
## Implementation notes
`matrix.fin.foo` is the `fin n` version of `matrix.foo`.
Namely, the index type of the circulant matrices in discussion is `fin n`.
## Tags
circulant, matrix
-/
variables {α β m n R : Type*}
namespace matrix
open function
open_locale matrix big_operators
/-- Given the condition `[has_sub n]` and a vector `v : n → α`,
we define `circulant v` to be the circulant matrix generated by `v` of type `matrix n n α`.
The `(i,j)`th entry is defined to be `v (i - j)`. -/
@[simp]
def circulant [has_sub n] (v : n → α) : matrix n n α
| i j := v (i - j)
lemma circulant_col_zero_eq [add_group n] (v : n → α) (i : n) : circulant v i 0 = v i :=
congr_arg v (sub_zero _)
lemma circulant_injective [add_group n] : injective (circulant : (n → α) → matrix n n α) :=
begin
intros v w h,
ext k,
rw [← circulant_col_zero_eq v, ← circulant_col_zero_eq w, h]
end
lemma fin.circulant_injective : ∀ n, injective (λ v : fin n → α, circulant v)
| 0 := dec_trivial
| (n+1) := circulant_injective
@[simp] lemma circulant_inj [add_group n] {v w : n → α} :
circulant v = circulant w ↔ v = w :=
circulant_injective.eq_iff
@[simp] lemma fin.circulant_inj {n} {v w : fin n → α} :
circulant v = circulant w ↔ v = w :=
(fin.circulant_injective n).eq_iff
lemma transpose_circulant [add_group n] (v : n → α) :
(circulant v)ᵀ = circulant (λ i, v (-i)) :=
by ext; simp
lemma conj_transpose_circulant [has_star α] [add_group n] (v : n → α) :
(circulant v)ᴴ = circulant (star (λ i, v (-i))) :=
by ext; simp
lemma fin.transpose_circulant : ∀ {n} (v : fin n → α), (circulant v)ᵀ = circulant (λ i, v (-i))
| 0 := dec_trivial
| (n+1) := transpose_circulant
lemma fin.conj_transpose_circulant [has_star α] :
∀ {n} (v : fin n → α), (circulant v)ᴴ = circulant (star (λ i, v (-i)))
| 0 := dec_trivial
| (n+1) := conj_transpose_circulant
lemma map_circulant [has_sub n] (v : n → α) (f : α → β) :
(circulant v).map f = circulant (λ i, f (v i)) :=
ext $ λ _ _, rfl
lemma circulant_neg [has_neg α] [has_sub n] (v : n → α) :
circulant (- v) = - circulant v :=
ext $ λ _ _, rfl
@[simp] lemma circulant_zero (α n) [has_zero α] [has_sub n] :
circulant 0 = (0 : matrix n n α) :=
ext $ λ _ _, rfl
lemma circulant_add [has_add α] [has_sub n] (v w : n → α) :
circulant (v + w) = circulant v + circulant w :=
ext $ λ _ _, rfl
lemma circulant_sub [has_sub α] [has_sub n] (v w : n → α) :
circulant (v - w) = circulant v - circulant w :=
ext $ λ _ _, rfl
/-- The product of two circulant matrices `circulant v` and `circulant w` is
the circulant matrix generated by `mul_vec (circulant v) w`. -/
lemma circulant_mul [semiring α] [fintype n] [add_group n] (v w : n → α) :
circulant v ⬝ circulant w = circulant (mul_vec (circulant v) w) :=
begin
ext i j,
simp only [mul_apply, mul_vec, circulant, dot_product],
refine fintype.sum_equiv (equiv.sub_right j) _ _ _,
intro x,
simp only [equiv.sub_right_apply, sub_sub_sub_cancel_right],
end
lemma fin.circulant_mul [semiring α] :
∀ {n} (v w : fin n → α), circulant v ⬝ circulant w = circulant (mul_vec (circulant v) w)
| 0 := dec_trivial
| (n+1) := circulant_mul
/-- Multiplication of circulant matrices commutes when the elements do. -/
lemma circulant_mul_comm
[comm_semigroup α] [add_comm_monoid α] [fintype n] [add_comm_group n] (v w : n → α) :
circulant v ⬝ circulant w = circulant w ⬝ circulant v :=
begin
ext i j,
simp only [mul_apply, circulant, mul_comm],
refine fintype.sum_equiv ((equiv.sub_left i).trans (equiv.add_right j)) _ _ _,
intro x,
congr' 2,
{ simp },
{ simp only [equiv.coe_add_right, function.comp_app,
equiv.coe_trans, equiv.sub_left_apply],
abel }
end
lemma fin.circulant_mul_comm [comm_semigroup α] [add_comm_monoid α] :
∀ {n} (v w : fin n → α), circulant v ⬝ circulant w = circulant w ⬝ circulant v
| 0 := dec_trivial
| (n+1) := circulant_mul_comm
/-- `k • circulant v` is another circulant matrix `circulant (k • v)`. -/
lemma circulant_smul [has_sub n] [has_scalar R α] (k : R) (v : n → α) :
circulant (k • v) = k • circulant v :=
by ext; simp
@[simp] lemma circulant_single_one
(α n) [has_zero α] [has_one α] [decidable_eq n] [add_group n] :
circulant (pi.single 0 1 : n → α) = (1 : matrix n n α) :=
by { ext i j, simp [one_apply, pi.single_apply, sub_eq_zero] }
@[simp] lemma circulant_single
(n) [semiring α] [decidable_eq n] [add_group n] [fintype n] (a : α) :
circulant (pi.single 0 a : n → α) = scalar n a :=
begin
ext i j,
simp [pi.single_apply, one_apply, sub_eq_zero],
end
/-- Note we use `↑i = 0` instead of `i = 0` as `fin 0` has no `0`.
This means that we cannot state this with `pi.single` as we did with `matrix.circulant_single`. -/
lemma fin.circulant_ite (α) [has_zero α] [has_one α] :
∀ n, circulant (λ i, ite (↑i = 0) 1 0 : fin n → α) = 1
| 0 := dec_trivial
| (n+1) :=
begin
rw [←circulant_single_one],
congr' with j,
simp only [pi.single_apply, fin.ext_iff],
congr
end
/-- A circulant of `v` is symmetric iff `v` equals its reverse. -/
lemma circulant_is_symm_iff [add_group n] {v : n → α} :
(circulant v).is_symm ↔ ∀ i, v (- i) = v i :=
by rw [is_symm, transpose_circulant, circulant_inj, funext_iff]
lemma fin.circulant_is_symm_iff :
∀ {n} {v : fin n → α}, (circulant v).is_symm ↔ ∀ i, v (- i) = v i
| 0 := λ v, by simp [is_symm.ext_iff, is_empty.forall_iff]
| (n+1) := λ v, circulant_is_symm_iff
/-- If `circulant v` is symmetric, `∀ i j : I, v (- i) = v i`. -/
lemma circulant_is_symm_apply [add_group n] {v : n → α} (h : (circulant v).is_symm) (i : n) :
v (-i) = v i :=
circulant_is_symm_iff.1 h i
lemma fin.circulant_is_symm_apply {n} {v : fin n → α} (h : (circulant v).is_symm) (i : fin n) :
v (-i) = v i :=
fin.circulant_is_symm_iff.1 h i
end matrix
|
9952f51959a37812744e5ad68ef562ded865ef25 | b32d3853770e6eaf06817a1b8c52064baaed0ef1 | /src/super/inferences/clausify.lean | adc0a85513acd50ae024032db2a4321f47966d7f | [] | no_license | gebner/super2 | 4d58b7477b6f7d945d5d866502982466db33ab0b | 9bc5256c31750021ab97d6b59b7387773e54b384 | refs/heads/master | 1,635,021,682,021 | 1,634,886,326,000 | 1,634,886,326,000 | 225,600,688 | 4 | 2 | null | 1,598,209,306,000 | 1,575,371,550,000 | Lean | UTF-8 | Lean | false | false | 617 | lean | import super.prover_state super.cnf
namespace super
meta def clause.clausify' (c : clause) : prover (list clause) := do
s ← state_t.get,
(s, cs) ← state_t.lift $ tactic.using_new_ref s (λ r, do
cs ← c.clausify (λ e, do
s ← tactic.read_ref r,
(e', s) ← (intern_sk_term e).run s,
tactic.write_ref r s,
pure e'),
s ← tactic.read_ref r,
pure (s, cs)),
state_t.put s,
pure cs
meta def preprocessing.clausify : preprocessing_rule | cs :=
list.join <$> cs.mmap (λ c : clause, do
cs ← c.clausify',
if cs.length > 1 then
cs.mmap $ λ c, c.clone
else
pure cs)
end super
|
e4baa30206c25e0bcbf92d02d3374e13aea9fe89 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/suffices.lean | 374a5dc359d1a165dbc58be2994a9e1daca34711 | [
"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 | 143 | lean | variables {a b c : Prop}
theorem foo (Ha : a) (Hab : a → b) (Hbc : b → c) : c :=
suffices b, from Hbc this,
suffices a, from Hab this,
Ha
|
b624689ff2a68672e2f72b8689e6bec1dc47168d | 649957717d58c43b5d8d200da34bf374293fe739 | /src/category_theory/limits/shapes/products.lean | a9a6872bee05faf463ededf20633a4231dc91404 | [
"Apache-2.0"
] | permissive | Vtec234/mathlib | b50c7b21edea438df7497e5ed6a45f61527f0370 | fb1848bbbfce46152f58e219dc0712f3289d2b20 | refs/heads/master | 1,592,463,095,113 | 1,562,737,749,000 | 1,562,737,749,000 | 196,202,858 | 0 | 0 | Apache-2.0 | 1,562,762,338,000 | 1,562,762,337,000 | null | UTF-8 | Lean | false | false | 921 | lean | -- Copyright (c) 2018 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import category_theory.limits.limits
import category_theory.discrete_category
universes v u
open category_theory
namespace category_theory.limits
variables {β : Type v}
variables {C : Type u} [𝒞 : category.{v+1} C]
include 𝒞
-- We don't need an analogue of `pair` (for binary products), `parallel_pair` (for equalizers),
-- or `(co)span`, since we already have `functor.of_function`.
abbreviation fan (f : β → C) := cone (functor.of_function f)
abbreviation cofan (f : β → C) := cocone (functor.of_function f)
def fan.mk {f : β → C} {P : C} (p : Π b, P ⟶ f b) : fan f :=
{ X := P,
π := { app := p } }
def cofan.mk {f : β → C} {P : C} (p : Π b, f b ⟶ P) : cofan f :=
{ X := P,
ι := { app := p } }
end category_theory.limits
|
b70cf1e3f56df79e6ce9a962b3b55468ebd18a30 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/category_theory/equivalence.lean | 553ab35c303aa85ad2ab6a1ce43313ebb4f0b7df | [
"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 | 23,795 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.fully_faithful
import category_theory.full_subcategory
import category_theory.whiskering
import category_theory.essential_image
import tactic.slice
/-!
# Equivalence of categories
An equivalence of categories `C` and `D` is a pair of functors `F : C ⥤ D` and `G : D ⥤ C` such
that `η : 𝟭 C ≅ F ⋙ G` and `ε : G ⋙ F ≅ 𝟭 D`. In many situations, equivalences are a better
notion of "sameness" of categories than the stricter isomorphims of categories.
Recall that one way to express that two functors `F : C ⥤ D` and `G : D ⥤ C` are adjoint is using
two natural transformations `η : 𝟭 C ⟶ F ⋙ G` and `ε : G ⋙ F ⟶ 𝟭 D`, called the unit and the
counit, such that the compositions `F ⟶ FGF ⟶ F` and `G ⟶ GFG ⟶ G` are the identity. Unfortunately,
it is not the case that the natural isomorphisms `η` and `ε` in the definition of an equivalence
automatically give an adjunction. However, it is true that
* if one of the two compositions is the identity, then so is the other, and
* given an equivalence of categories, it is always possible to refine `η` in such a way that the
identities are satisfied.
For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is
a tuple `(F, G, η, ε)` as in the first paragraph such that the composite `F ⟶ FGF ⟶ F` is the
identity. By the remark above, this already implies that the tuple is an "adjoint equivalence",
i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity.
We also define essentially surjective functors and show that a functor is an equivalence if and only
if it is full, faithful and essentially surjective.
## Main definitions
* `equivalence`: bundled (half-)adjoint equivalences of categories
* `is_equivalence`: type class on a functor `F` containing the data of the inverse `G` as well as
the natural isomorphisms `η` and `ε`.
* `ess_surj`: type class on a functor `F` containing the data of the preimages and the isomorphisms
`F.obj (preimage d) ≅ d`.
## Main results
* `equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence
* `equivalence.of_fully_faithfully_ess_surj`: a fully faithful essentially surjective functor is an
equivalence.
## Notations
We write `C ≌ D` (`\backcong`, not to be confused with `≅`/`\cong`) for a bundled equivalence.
-/
namespace category_theory
open category_theory.functor nat_iso category
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ u₁ u₂ u₃
/-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with
a unit and counit which are natural isomorphisms and the triangle law `Fη ≫ εF = 1`, or in other
words the composite `F ⟶ FGF ⟶ F` is the identity.
In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the
composite `G ⟶ GFG ⟶ G` is also the identity.
The triangle equation is written as a family of equalities between morphisms, it is more
complicated if we write it as an equality of natural transformations, because then we would have
to insert natural transformations like `F ⟶ F1`.
See https://stacks.math.columbia.edu/tag/001J
-/
structure equivalence (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D] :=
mk' ::
(functor : C ⥤ D)
(inverse : D ⥤ C)
(unit_iso : 𝟭 C ≅ functor ⋙ inverse)
(counit_iso : inverse ⋙ functor ≅ 𝟭 D)
(functor_unit_iso_comp' : ∀(X : C), functor.map ((unit_iso.hom : 𝟭 C ⟶ functor ⋙ inverse).app X) ≫
counit_iso.hom.app (functor.obj X) = 𝟙 (functor.obj X) . obviously)
restate_axiom equivalence.functor_unit_iso_comp'
infixr ` ≌ `:10 := equivalence
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
namespace equivalence
/-- The unit of an equivalence of categories. -/
abbreviation unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse := e.unit_iso.hom
/-- The counit of an equivalence of categories. -/
abbreviation counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D := e.counit_iso.hom
/-- The inverse of the unit of an equivalence of categories. -/
abbreviation unit_inv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C := e.unit_iso.inv
/-- The inverse of the counit of an equivalence of categories. -/
abbreviation counit_inv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor := e.counit_iso.inv
/- While these abbreviations are convenient, they also cause some trouble,
preventing structure projections from unfolding. -/
@[simp] lemma equivalence_mk'_unit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit = unit_iso.hom := rfl
@[simp] lemma equivalence_mk'_counit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit = counit_iso.hom := rfl
@[simp] lemma equivalence_mk'_unit_inv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit_inv = unit_iso.inv := rfl
@[simp] lemma equivalence_mk'_counit_inv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit_inv = counit_iso.inv := rfl
@[simp] lemma functor_unit_comp (e : C ≌ D) (X : C) :
e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = 𝟙 (e.functor.obj X) :=
e.functor_unit_iso_comp X
@[simp] lemma counit_inv_functor_comp (e : C ≌ D) (X : C) :
e.counit_inv.app (e.functor.obj X) ≫ e.functor.map (e.unit_inv.app X) = 𝟙 (e.functor.obj X) :=
begin
erw [iso.inv_eq_inv
(e.functor.map_iso (e.unit_iso.app X) ≪≫ e.counit_iso.app (e.functor.obj X)) (iso.refl _)],
exact e.functor_unit_comp X
end
lemma counit_inv_app_functor (e : C ≌ D) (X : C) :
e.counit_inv.app (e.functor.obj X) = e.functor.map (e.unit.app X) :=
by { symmetry, erw [←iso.comp_hom_eq_id (e.counit_iso.app _), functor_unit_comp], refl }
lemma counit_app_functor (e : C ≌ D) (X : C) :
e.counit.app (e.functor.obj X) = e.functor.map (e.unit_inv.app X) :=
by { erw [←iso.hom_comp_eq_id (e.functor.map_iso (e.unit_iso.app X)), functor_unit_comp], refl }
/-- The other triangle equality. The proof follows the following proof in Globular:
http://globular.science/1905.001 -/
@[simp] lemma unit_inverse_comp (e : C ≌ D) (Y : D) :
e.unit.app (e.inverse.obj Y) ≫ e.inverse.map (e.counit.app Y) = 𝟙 (e.inverse.obj Y) :=
begin
rw [←id_comp (e.inverse.map _), ←map_id e.inverse, ←counit_inv_functor_comp, map_comp,
←iso.hom_inv_id_assoc (e.unit_iso.app _) (e.inverse.map (e.functor.map _)),
app_hom, app_inv],
slice_lhs 2 3 { erw [e.unit.naturality] },
slice_lhs 1 2 { erw [e.unit.naturality] },
slice_lhs 4 4
{ rw [←iso.hom_inv_id_assoc (e.inverse.map_iso (e.counit_iso.app _)) (e.unit_inv.app _)] },
slice_lhs 3 4 { erw [←map_comp e.inverse, e.counit.naturality],
erw [(e.counit_iso.app _).hom_inv_id, map_id] }, erw [id_comp],
slice_lhs 2 3 { erw [←map_comp e.inverse, e.counit_iso.inv.naturality, map_comp] },
slice_lhs 3 4 { erw [e.unit_inv.naturality] },
slice_lhs 4 5 { erw [←map_comp (e.functor ⋙ e.inverse), (e.unit_iso.app _).hom_inv_id, map_id] },
erw [id_comp],
slice_lhs 3 4 { erw [←e.unit_inv.naturality] },
slice_lhs 2 3 { erw [←map_comp e.inverse, ←e.counit_iso.inv.naturality,
(e.counit_iso.app _).hom_inv_id, map_id] }, erw [id_comp, (e.unit_iso.app _).hom_inv_id], refl
end
@[simp] lemma inverse_counit_inv_comp (e : C ≌ D) (Y : D) :
e.inverse.map (e.counit_inv.app Y) ≫ e.unit_inv.app (e.inverse.obj Y) = 𝟙 (e.inverse.obj Y) :=
begin
erw [iso.inv_eq_inv
(e.unit_iso.app (e.inverse.obj Y) ≪≫ e.inverse.map_iso (e.counit_iso.app Y)) (iso.refl _)],
exact e.unit_inverse_comp Y
end
lemma unit_app_inverse (e : C ≌ D) (Y : D) :
e.unit.app (e.inverse.obj Y) = e.inverse.map (e.counit_inv.app Y) :=
by { erw [←iso.comp_hom_eq_id (e.inverse.map_iso (e.counit_iso.app Y)), unit_inverse_comp], refl }
lemma unit_inv_app_inverse (e : C ≌ D) (Y : D) :
e.unit_inv.app (e.inverse.obj Y) = e.inverse.map (e.counit.app Y) :=
by { symmetry, erw [←iso.hom_comp_eq_id (e.unit_iso.app _), unit_inverse_comp], refl }
@[simp] lemma fun_inv_map (e : C ≌ D) (X Y : D) (f : X ⟶ Y) :
e.functor.map (e.inverse.map f) = e.counit.app X ≫ f ≫ e.counit_inv.app Y :=
(nat_iso.naturality_2 (e.counit_iso) f).symm
@[simp] lemma inv_fun_map (e : C ≌ D) (X Y : C) (f : X ⟶ Y) :
e.inverse.map (e.functor.map f) = e.unit_inv.app X ≫ f ≫ e.unit.app Y :=
(nat_iso.naturality_1 (e.unit_iso) f).symm
section
-- In this section we convert an arbitrary equivalence to a half-adjoint equivalence.
variables {F : C ⥤ D} {G : D ⥤ C} (η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D)
/-- If `η : 𝟭 C ≅ F ⋙ G` is part of a (not necessarily half-adjoint) equivalence, we can upgrade it
to a refined natural isomorphism `adjointify_η η : 𝟭 C ≅ F ⋙ G` which exhibits the properties
required for a half-adjoint equivalence. See `equivalence.mk`. -/
def adjointify_η : 𝟭 C ≅ F ⋙ G :=
calc
𝟭 C ≅ F ⋙ G : η
... ≅ F ⋙ (𝟭 D ⋙ G) : iso_whisker_left F (left_unitor G).symm
... ≅ F ⋙ ((G ⋙ F) ⋙ G) : iso_whisker_left F (iso_whisker_right ε.symm G)
... ≅ F ⋙ (G ⋙ (F ⋙ G)) : iso_whisker_left F (associator G F G)
... ≅ (F ⋙ G) ⋙ (F ⋙ G) : (associator F G (F ⋙ G)).symm
... ≅ 𝟭 C ⋙ (F ⋙ G) : iso_whisker_right η.symm (F ⋙ G)
... ≅ F ⋙ G : left_unitor (F ⋙ G)
lemma adjointify_η_ε (X : C) :
F.map ((adjointify_η η ε).hom.app X) ≫ ε.hom.app (F.obj X) = 𝟙 (F.obj X) :=
begin
dsimp [adjointify_η], simp,
have := ε.hom.naturality (F.map (η.inv.app X)), dsimp at this, rw [this], clear this,
rw [←assoc _ _ (F.map _)],
have := ε.hom.naturality (ε.inv.app $ F.obj X), dsimp at this, rw [this], clear this,
have := (ε.app $ F.obj X).hom_inv_id, dsimp at this, rw [this], clear this,
rw [id_comp], have := (F.map_iso $ η.app X).hom_inv_id, dsimp at this, rw [this]
end
end
/-- Every equivalence of categories consisting of functors `F` and `G` such that `F ⋙ G` and
`G ⋙ F` are naturally isomorphic to identity functors can be transformed into a half-adjoint
equivalence without changing `F` or `G`. -/
protected definition mk (F : C ⥤ D) (G : D ⥤ C)
(η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D) : C ≌ D :=
⟨F, G, adjointify_η η ε, ε, adjointify_η_ε η ε⟩
/-- Equivalence of categories is reflexive. -/
@[refl, simps] def refl : C ≌ C :=
⟨𝟭 C, 𝟭 C, iso.refl _, iso.refl _, λ X, category.id_comp _⟩
instance : inhabited (C ≌ C) :=
⟨refl⟩
/-- Equivalence of categories is symmetric. -/
@[symm, simps] def symm (e : C ≌ D) : D ≌ C :=
⟨e.inverse, e.functor, e.counit_iso.symm, e.unit_iso.symm, e.inverse_counit_inv_comp⟩
variables {E : Type u₃} [category.{v₃} E]
/-- Equivalence of categories is transitive. -/
@[trans, simps] def trans (e : C ≌ D) (f : D ≌ E) : C ≌ E :=
{ functor := e.functor ⋙ f.functor,
inverse := f.inverse ⋙ e.inverse,
unit_iso :=
begin
refine iso.trans e.unit_iso _,
exact iso_whisker_left e.functor (iso_whisker_right f.unit_iso e.inverse) ,
end,
counit_iso :=
begin
refine iso.trans _ f.counit_iso,
exact iso_whisker_left f.inverse (iso_whisker_right e.counit_iso f.functor)
end,
-- We wouldn't have needed to give this proof if we'd used `equivalence.mk`,
-- but we choose to avoid using that here, for the sake of good structure projection `simp`
-- lemmas.
functor_unit_iso_comp' := λ X,
begin
dsimp,
rw [← f.functor.map_comp_assoc, e.functor.map_comp, ←counit_inv_app_functor, fun_inv_map,
iso.inv_hom_id_app_assoc, assoc, iso.inv_hom_id_app, counit_app_functor,
← functor.map_comp],
erw [comp_id, iso.hom_inv_id_app, functor.map_id],
end }
/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic
functor. -/
def fun_inv_id_assoc (e : C ≌ D) (F : C ⥤ E) : e.functor ⋙ e.inverse ⋙ F ≅ F :=
(functor.associator _ _ _).symm ≪≫ iso_whisker_right e.unit_iso.symm F ≪≫ F.left_unitor
@[simp] lemma fun_inv_id_assoc_hom_app (e : C ≌ D) (F : C ⥤ E) (X : C) :
(fun_inv_id_assoc e F).hom.app X = F.map (e.unit_inv.app X) :=
by { dsimp [fun_inv_id_assoc], tidy }
@[simp] lemma fun_inv_id_assoc_inv_app (e : C ≌ D) (F : C ⥤ E) (X : C) :
(fun_inv_id_assoc e F).inv.app X = F.map (e.unit.app X) :=
by { dsimp [fun_inv_id_assoc], tidy }
/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic
functor. -/
def inv_fun_id_assoc (e : C ≌ D) (F : D ⥤ E) : e.inverse ⋙ e.functor ⋙ F ≅ F :=
(functor.associator _ _ _).symm ≪≫ iso_whisker_right e.counit_iso F ≪≫ F.left_unitor
@[simp] lemma inv_fun_id_assoc_hom_app (e : C ≌ D) (F : D ⥤ E) (X : D) :
(inv_fun_id_assoc e F).hom.app X = F.map (e.counit.app X) :=
by { dsimp [inv_fun_id_assoc], tidy }
@[simp] lemma inv_fun_id_assoc_inv_app (e : C ≌ D) (F : D ⥤ E) (X : D) :
(inv_fun_id_assoc e F).inv.app X = F.map (e.counit_inv.app X) :=
by { dsimp [inv_fun_id_assoc], tidy }
/-- If `C` is equivalent to `D`, then `C ⥤ E` is equivalent to `D ⥤ E`. -/
@[simps functor inverse unit_iso counit_iso]
def congr_left (e : C ≌ D) : (C ⥤ E) ≌ (D ⥤ E) :=
equivalence.mk
((whiskering_left _ _ _).obj e.inverse)
((whiskering_left _ _ _).obj e.functor)
(nat_iso.of_components (λ F, (e.fun_inv_id_assoc F).symm) (by tidy))
(nat_iso.of_components (λ F, e.inv_fun_id_assoc F) (by tidy))
/-- If `C` is equivalent to `D`, then `E ⥤ C` is equivalent to `E ⥤ D`. -/
@[simps functor inverse unit_iso counit_iso]
def congr_right (e : C ≌ D) : (E ⥤ C) ≌ (E ⥤ D) :=
equivalence.mk
((whiskering_right _ _ _).obj e.functor)
((whiskering_right _ _ _).obj e.inverse)
(nat_iso.of_components
(λ F, F.right_unitor.symm ≪≫ iso_whisker_left F e.unit_iso ≪≫ functor.associator _ _ _)
(by tidy))
(nat_iso.of_components
(λ F, functor.associator _ _ _ ≪≫ iso_whisker_left F e.counit_iso ≪≫ F.right_unitor)
(by tidy))
section cancellation_lemmas
variables (e : C ≌ D)
/- We need special forms of `cancel_nat_iso_hom_right(_assoc)` and
`cancel_nat_iso_inv_right(_assoc)` for units and counits, because neither `simp` or `rw` will apply
those lemmas in this setting without providing `e.unit_iso` (or similar) as an explicit argument.
We also provide the lemmas for length four compositions, since they're occasionally useful.
(e.g. in proving that equivalences take monos to monos) -/
@[simp] lemma cancel_unit_right {X Y : C}
(f f' : X ⟶ Y) :
f ≫ e.unit.app Y = f' ≫ e.unit.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_unit_inv_right {X Y : C}
(f f' : X ⟶ e.inverse.obj (e.functor.obj Y)) :
f ≫ e.unit_inv.app Y = f' ≫ e.unit_inv.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_counit_right {X Y : D}
(f f' : X ⟶ e.functor.obj (e.inverse.obj Y)) :
f ≫ e.counit.app Y = f' ≫ e.counit.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_counit_inv_right {X Y : D}
(f f' : X ⟶ Y) :
f ≫ e.counit_inv.app Y = f' ≫ e.counit_inv.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_unit_right_assoc {W X X' Y : C}
(f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) :
f ≫ g ≫ e.unit.app Y = f' ≫ g' ≫ e.unit.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma cancel_counit_inv_right_assoc {W X X' Y : D}
(f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) :
f ≫ g ≫ e.counit_inv.app Y = f' ≫ g' ≫ e.counit_inv.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma cancel_unit_right_assoc' {W X X' Y Y' Z : C}
(f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z) (f' : W ⟶ X') (g' : X' ⟶ Y') (h' : Y' ⟶ Z) :
f ≫ g ≫ h ≫ e.unit.app Z = f' ≫ g' ≫ h' ≫ e.unit.app Z ↔ f ≫ g ≫ h = f' ≫ g' ≫ h' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma cancel_counit_inv_right_assoc' {W X X' Y Y' Z : D}
(f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z) (f' : W ⟶ X') (g' : X' ⟶ Y') (h' : Y' ⟶ Z) :
f ≫ g ≫ h ≫ e.counit_inv.app Z = f' ≫ g' ≫ h' ≫ e.counit_inv.app Z ↔ f ≫ g ≫ h = f' ≫ g' ≫ h' :=
by simp only [←category.assoc, cancel_mono]
end cancellation_lemmas
section
-- There's of course a monoid structure on `C ≌ C`,
-- but let's not encourage using it.
-- The power structure is nevertheless useful.
/-- Natural number powers of an auto-equivalence. Use `(^)` instead. -/
def pow_nat (e : C ≌ C) : ℕ → (C ≌ C)
| 0 := equivalence.refl
| 1 := e
| (n+2) := e.trans (pow_nat (n+1))
/-- Powers of an auto-equivalence. Use `(^)` instead. -/
def pow (e : C ≌ C) : ℤ → (C ≌ C)
| (int.of_nat n) := e.pow_nat n
| (int.neg_succ_of_nat n) := e.symm.pow_nat (n+1)
instance : has_pow (C ≌ C) ℤ := ⟨pow⟩
@[simp] lemma pow_zero (e : C ≌ C) : e^(0 : ℤ) = equivalence.refl := rfl
@[simp] lemma pow_one (e : C ≌ C) : e^(1 : ℤ) = e := rfl
@[simp] lemma pow_neg_one (e : C ≌ C) : e^(-1 : ℤ) = e.symm := rfl
-- TODO as necessary, add the natural isomorphisms `(e^a).trans e^b ≅ e^(a+b)`.
-- At this point, we haven't even defined the category of equivalences.
end
end equivalence
/-- A functor that is part of a (half) adjoint equivalence -/
class is_equivalence (F : C ⥤ D) :=
mk' ::
(inverse : D ⥤ C)
(unit_iso : 𝟭 C ≅ F ⋙ inverse)
(counit_iso : inverse ⋙ F ≅ 𝟭 D)
(functor_unit_iso_comp' : ∀ (X : C), F.map ((unit_iso.hom : 𝟭 C ⟶ F ⋙ inverse).app X) ≫
counit_iso.hom.app (F.obj X) = 𝟙 (F.obj X) . obviously)
restate_axiom is_equivalence.functor_unit_iso_comp'
namespace is_equivalence
instance of_equivalence (F : C ≌ D) : is_equivalence F.functor :=
{ ..F }
instance of_equivalence_inverse (F : C ≌ D) : is_equivalence F.inverse :=
is_equivalence.of_equivalence F.symm
open equivalence
/-- To see that a functor is an equivalence, it suffices to provide an inverse functor `G` such that
`F ⋙ G` and `G ⋙ F` are naturally isomorphic to identity functors. -/
protected definition mk {F : C ⥤ D} (G : D ⥤ C)
(η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D) : is_equivalence F :=
⟨G, adjointify_η η ε, ε, adjointify_η_ε η ε⟩
end is_equivalence
namespace functor
/-- Interpret a functor that is an equivalence as an equivalence. -/
def as_equivalence (F : C ⥤ D) [is_equivalence F] : C ≌ D :=
⟨F, is_equivalence.inverse F, is_equivalence.unit_iso, is_equivalence.counit_iso,
is_equivalence.functor_unit_iso_comp⟩
instance is_equivalence_refl : is_equivalence (𝟭 C) :=
is_equivalence.of_equivalence equivalence.refl
/-- The inverse functor of a functor that is an equivalence. -/
def inv (F : C ⥤ D) [is_equivalence F] : D ⥤ C :=
is_equivalence.inverse F
instance is_equivalence_inv (F : C ⥤ D) [is_equivalence F] : is_equivalence F.inv :=
is_equivalence.of_equivalence F.as_equivalence.symm
@[simp] lemma as_equivalence_functor (F : C ⥤ D) [is_equivalence F] :
F.as_equivalence.functor = F := rfl
@[simp] lemma as_equivalence_inverse (F : C ⥤ D) [is_equivalence F] :
F.as_equivalence.inverse = inv F := rfl
@[simp] lemma inv_inv (F : C ⥤ D) [is_equivalence F] :
inv (inv F) = F := rfl
variables {E : Type u₃} [category.{v₃} E]
instance is_equivalence_trans (F : C ⥤ D) (G : D ⥤ E) [is_equivalence F] [is_equivalence G] :
is_equivalence (F ⋙ G) :=
is_equivalence.of_equivalence (equivalence.trans (as_equivalence F) (as_equivalence G))
end functor
namespace equivalence
@[simp]
lemma functor_inv (E : C ≌ D) : E.functor.inv = E.inverse := rfl
@[simp]
lemma inverse_inv (E : C ≌ D) : E.inverse.inv = E.functor := rfl
@[simp]
lemma functor_as_equivalence (E : C ≌ D) : E.functor.as_equivalence = E :=
by { cases E, congr, }
@[simp]
lemma inverse_as_equivalence (E : C ≌ D) : E.inverse.as_equivalence = E.symm :=
by { cases E, congr, }
end equivalence
namespace is_equivalence
@[simp] lemma fun_inv_map (F : C ⥤ D) [is_equivalence F] (X Y : D) (f : X ⟶ Y) :
F.map (F.inv.map f) = F.as_equivalence.counit.app X ≫ f ≫ F.as_equivalence.counit_inv.app Y :=
begin
erw [nat_iso.naturality_2],
refl
end
@[simp] lemma inv_fun_map (F : C ⥤ D) [is_equivalence F] (X Y : C) (f : X ⟶ Y) :
F.inv.map (F.map f) = F.as_equivalence.unit_inv.app X ≫ f ≫ F.as_equivalence.unit.app Y :=
begin
erw [nat_iso.naturality_1],
refl
end
end is_equivalence
namespace equivalence
/--
An equivalence is essentially surjective.
See https://stacks.math.columbia.edu/tag/02C3.
-/
lemma ess_surj_of_equivalence (F : C ⥤ D) [is_equivalence F] : ess_surj F :=
⟨λ Y, ⟨F.inv.obj Y, ⟨F.as_equivalence.counit_iso.app Y⟩⟩⟩
/--
An equivalence is faithful.
See https://stacks.math.columbia.edu/tag/02C3.
-/
@[priority 100] -- see Note [lower instance priority]
instance faithful_of_equivalence (F : C ⥤ D) [is_equivalence F] : faithful F :=
{ map_injective' := λ X Y f g w,
begin
have p := congr_arg (@category_theory.functor.map _ _ _ _ F.inv _ _) w,
simpa only [cancel_epi, cancel_mono, is_equivalence.inv_fun_map] using p
end }.
/--
An equivalence is full.
See https://stacks.math.columbia.edu/tag/02C3.
-/
@[priority 100] -- see Note [lower instance priority]
instance full_of_equivalence (F : C ⥤ D) [is_equivalence F] : full F :=
{ preimage := λ X Y f, F.as_equivalence.unit.app X ≫ F.inv.map f ≫ F.as_equivalence.unit_inv.app Y,
witness' := λ X Y f, F.inv.map_injective $
by simpa only [is_equivalence.inv_fun_map, assoc, iso.inv_hom_id_app_assoc, iso.inv_hom_id_app]
using comp_id _ }
@[simps] private noncomputable def equivalence_inverse (F : C ⥤ D) [full F] [faithful F]
[ess_surj F] : D ⥤ C :=
{ obj := λ X, F.obj_preimage X,
map := λ X Y f, F.preimage ((F.obj_obj_preimage_iso X).hom ≫ f ≫ (F.obj_obj_preimage_iso Y).inv),
map_id' := λ X, begin apply F.map_injective, tidy end,
map_comp' := λ X Y Z f g, by apply F.map_injective; simp }
/--
A functor which is full, faithful, and essentially surjective is an equivalence.
See https://stacks.math.columbia.edu/tag/02C3.
-/
noncomputable def of_fully_faithfully_ess_surj
(F : C ⥤ D) [full F] [faithful F] [ess_surj F] : is_equivalence F :=
is_equivalence.mk (equivalence_inverse F)
(nat_iso.of_components
(λ X, (preimage_iso $ F.obj_obj_preimage_iso $ F.obj X).symm)
(λ X Y f, by { apply F.map_injective, obviously }))
(nat_iso.of_components F.obj_obj_preimage_iso (by tidy))
@[simp] lemma functor_map_inj_iff (e : C ≌ D) {X Y : C} (f g : X ⟶ Y) :
e.functor.map f = e.functor.map g ↔ f = g :=
⟨λ h, e.functor.map_injective h, λ h, h ▸ rfl⟩
@[simp] lemma inverse_map_inj_iff (e : C ≌ D) {X Y : D} (f g : X ⟶ Y) :
e.inverse.map f = e.inverse.map g ↔ f = g :=
functor_map_inj_iff e.symm f g
instance ess_surj_induced_functor {C' : Type*} (e : C' ≃ D) : ess_surj (induced_functor e) :=
{ mem_ess_image := λ Y, ⟨e.symm Y, by simp⟩, }
noncomputable
instance induced_functor_of_equiv {C' : Type*} (e : C' ≃ D) : is_equivalence (induced_functor e) :=
equivalence.of_fully_faithfully_ess_surj _
end equivalence
end category_theory
|
f03959af4603a4badc2e25fd02eff06b1222a738 | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /hott/init/funext.hlean | 92905c4c46dcfba4c7ff0a2e554ef97107521bfc | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 10,554 | hlean | /-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
prelude
import .trunc .equiv .ua
open eq is_trunc sigma function is_equiv equiv prod unit prod.ops lift
/-
We now prove that funext follows from a couple of weaker-looking forms
of function extensionality.
This proof is originally due to Voevodsky; it has since been simplified
by Peter Lumsdaine and Michael Shulman.
-/
definition funext.{l k} :=
Π ⦃A : Type.{l}⦄ {P : A → Type.{k}} (f g : Π x, P x), is_equiv (@apd10 A P f g)
-- Naive funext is the simple assertion that pointwise equal functions are equal.
definition naive_funext :=
Π ⦃A : Type⦄ {P : A → Type} (f g : Πx, P x), (f ~ g) → f = g
-- Weak funext says that a product of contractible types is contractible.
definition weak_funext :=
Π ⦃A : Type⦄ (P : A → Type) [H: Πx, is_contr (P x)], is_contr (Πx, P x)
definition weak_funext_of_naive_funext : naive_funext → weak_funext :=
(λ nf A P (Pc : Πx, is_contr (P x)),
let c := λx, center (P x) in
is_contr.mk c (λ f,
have eq' : (λx, center (P x)) ~ f,
from (λx, center_eq (f x)),
have eq : (λx, center (P x)) = f,
from nf A P (λx, center (P x)) f eq',
eq
)
)
/-
The less obvious direction is that weak_funext implies funext
(and hence all three are logically equivalent). The point is that under weak
funext, the space of "pointwise homotopies" has the same universal property as
the space of paths.
-/
section
universe variables l k
parameters [wf : weak_funext.{l k}] {A : Type.{l}} {B : A → Type.{k}} (f : Π x, B x)
definition is_contr_sigma_homotopy : is_contr (Σ (g : Π x, B x), f ~ g) :=
is_contr.mk (sigma.mk f (homotopy.refl f))
(λ dp, sigma.rec_on dp
(λ (g : Π x, B x) (h : f ~ g),
let r := λ (k : Π x, Σ y, f x = y),
@sigma.mk _ (λg, f ~ g)
(λx, pr1 (k x)) (λx, pr2 (k x)) in
let s := λ g h x, @sigma.mk _ (λy, f x = y) (g x) (h x) in
have t1 : Πx, is_contr (Σ y, f x = y),
from (λx, !is_contr_sigma_eq),
have t2 : is_contr (Πx, Σ y, f x = y),
from !wf,
have t3 : (λ x, @sigma.mk _ (λ y, f x = y) (f x) idp) = s g h,
from @eq_of_is_contr (Π x, Σ y, f x = y) t2 _ _,
have t4 : r (λ x, sigma.mk (f x) idp) = r (s g h),
from ap r t3,
have endt : sigma.mk f (homotopy.refl f) = sigma.mk g h,
from t4,
endt
)
)
local attribute is_contr_sigma_homotopy [instance]
parameters (Q : Π g (h : f ~ g), Type) (d : Q f (homotopy.refl f))
definition homotopy_ind (g : Πx, B x) (h : f ~ g) : Q g h :=
@transport _ (λ gh, Q (pr1 gh) (pr2 gh)) (sigma.mk f (homotopy.refl f)) (sigma.mk g h)
(@eq_of_is_contr _ is_contr_sigma_homotopy _ _) d
local attribute weak_funext [reducible]
local attribute homotopy_ind [reducible]
definition homotopy_ind_comp : homotopy_ind f (homotopy.refl f) = d :=
(@hprop_eq_of_is_contr _ _ _ _ !eq_of_is_contr idp)⁻¹ ▸ idp
end
/- Now the proof is fairly easy; we can just use the same induction principle on both sides. -/
section
universe variables l k
local attribute weak_funext [reducible]
theorem funext_of_weak_funext (wf : weak_funext.{l k}) : funext.{l k} :=
λ A B f g,
let eq_to_f := (λ g' x, f = g') in
let sim2path := homotopy_ind f eq_to_f idp in
assert t1 : sim2path f (homotopy.refl f) = idp,
proof homotopy_ind_comp f eq_to_f idp qed,
assert t2 : apd10 (sim2path f (homotopy.refl f)) = (homotopy.refl f),
proof ap apd10 t1 qed,
have left_inv : apd10 ∘ (sim2path g) ~ id,
proof (homotopy_ind f (λ g' x, apd10 (sim2path g' x) = x) t2) g qed,
have right_inv : (sim2path g) ∘ apd10 ~ id,
from (λ h, eq.rec_on h (homotopy_ind_comp f _ idp)),
is_equiv.adjointify apd10 (sim2path g) left_inv right_inv
definition funext_from_naive_funext : naive_funext → funext :=
compose funext_of_weak_funext weak_funext_of_naive_funext
end
section
universe variables l
private theorem ua_isequiv_postcompose {A B : Type.{l}} {C : Type}
{w : A → B} [H0 : is_equiv w] : is_equiv (@compose C A B w) :=
let w' := equiv.mk w H0 in
let eqinv : A = B := ((@is_equiv.inv _ _ _ (univalence A B)) w') in
let eq' := equiv_of_eq eqinv in
is_equiv.adjointify (@compose C A B w)
(@compose C B A (is_equiv.inv w))
(λ (x : C → B),
have eqretr : eq' = w',
from (@right_inv _ _ (@equiv_of_eq A B) (univalence A B) w'),
have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹,
from inv_eq eq' w' eqretr,
have eqfin : (to_fun eq') ∘ ((to_fun eq')⁻¹ ∘ x) = x,
from (λ p,
(@eq.rec_on Type.{l} A
(λ B' p', Π (x' : C → B'), (to_fun (equiv_of_eq p'))
∘ ((to_fun (equiv_of_eq p'))⁻¹ ∘ x') = x')
B p (λ x', idp))
) eqinv x,
have eqfin' : (to_fun w') ∘ ((to_fun eq')⁻¹ ∘ x) = x,
from eqretr ▸ eqfin,
have eqfin'' : (to_fun w') ∘ ((to_fun w')⁻¹ ∘ x) = x,
from invs_eq ▸ eqfin',
eqfin''
)
(λ (x : C → A),
have eqretr : eq' = w',
from (@right_inv _ _ (@equiv_of_eq A B) (univalence A B) w'),
have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹,
from inv_eq eq' w' eqretr,
have eqfin : (to_fun eq')⁻¹ ∘ ((to_fun eq') ∘ x) = x,
from (λ p, eq.rec_on p idp) eqinv,
have eqfin' : (to_fun eq')⁻¹ ∘ ((to_fun w') ∘ x) = x,
from eqretr ▸ eqfin,
have eqfin'' : (to_fun w')⁻¹ ∘ ((to_fun w') ∘ x) = x,
from invs_eq ▸ eqfin',
eqfin''
)
-- We are ready to prove functional extensionality,
-- starting with the naive non-dependent version.
private definition diagonal [reducible] (B : Type) : Type
:= Σ xy : B × B, pr₁ xy = pr₂ xy
private definition isequiv_src_compose {A B : Type}
: @is_equiv (A → diagonal B)
(A → B)
(compose (pr₁ ∘ pr1)) :=
@ua_isequiv_postcompose _ _ _ (pr₁ ∘ pr1)
(is_equiv.adjointify (pr₁ ∘ pr1)
(λ x, sigma.mk (x , x) idp) (λx, idp)
(λ x, sigma.rec_on x
(λ xy, prod.rec_on xy
(λ b c p, eq.rec_on p idp))))
private definition isequiv_tgt_compose {A B : Type}
: is_equiv (compose (pr₂ ∘ pr1) : (A → diagonal B) → (A → B)) :=
begin
refine @ua_isequiv_postcompose _ _ _ (pr2 ∘ pr1) _,
fapply adjointify,
{ intro b, exact ⟨(b, b), idp⟩},
{ intro b, reflexivity},
{ intro a, induction a with q p, induction q, esimp at *, induction p, reflexivity}
end
theorem nondep_funext_from_ua {A : Type} {B : Type}
: Π {f g : A → B}, f ~ g → f = g :=
(λ (f g : A → B) (p : f ~ g),
let d := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , f x) (eq.refl (f x, f x).1) in
let e := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , g x) (p x) in
let precomp1 := compose (pr₁ ∘ sigma.pr1) in
assert equiv1 : is_equiv precomp1,
from @isequiv_src_compose A B,
assert equiv2 : Π (x y : A → diagonal B), is_equiv (ap precomp1),
from is_equiv.is_equiv_ap precomp1,
have H' : Π (x y : A → diagonal B), pr₁ ∘ pr1 ∘ x = pr₁ ∘ pr1 ∘ y → x = y,
from (λ x y, is_equiv.inv (ap precomp1)),
have eq2 : pr₁ ∘ pr1 ∘ d = pr₁ ∘ pr1 ∘ e,
from idp,
have eq0 : d = e,
from H' d e eq2,
have eq1 : (pr₂ ∘ pr1) ∘ d = (pr₂ ∘ pr1) ∘ e,
from ap _ eq0,
eq1
)
end
-- Now we use this to prove weak funext, which as we know
-- implies (with dependent eta) also the strong dependent funext.
theorem weak_funext_of_ua : weak_funext :=
(λ (A : Type) (P : A → Type) allcontr,
let U := (λ (x : A), lift unit) in
have pequiv : Π (x : A), P x ≃ unit,
from (λ x, @equiv_unit_of_is_contr (P x) (allcontr x)),
have psim : Π (x : A), P x = U x,
from (λ x, eq_of_equiv_lift (pequiv x)),
have p : P = U,
from @nondep_funext_from_ua A Type P U psim,
have tU' : is_contr (A → lift unit),
from is_contr.mk (λ x, up ⋆)
(λ f, nondep_funext_from_ua (λa, by induction (f a) with u;induction u;reflexivity)),
have tU : is_contr (Π x, U x),
from tU',
have tlast : is_contr (Πx, P x),
from p⁻¹ ▸ tU,
tlast)
-- In the following we will proof function extensionality using the univalence axiom
definition funext_of_ua : funext :=
funext_of_weak_funext (@weak_funext_of_ua)
variables {A : Type} {P : A → Type} {f g : Π x, P x}
namespace funext
theorem is_equiv_apd [instance] (f g : Π x, P x) : is_equiv (@apd10 A P f g) :=
funext_of_ua f g
end funext
open funext
definition eq_equiv_homotopy : (f = g) ≃ (f ~ g) :=
equiv.mk apd10 _
definition eq_of_homotopy [reducible] : f ~ g → f = g :=
(@apd10 A P f g)⁻¹
definition apd10_eq_of_homotopy (p : f ~ g) : apd10 (eq_of_homotopy p) = p :=
right_inv apd10 p
definition eq_of_homotopy_apd10 (p : f = g) : eq_of_homotopy (apd10 p) = p :=
left_inv apd10 p
definition eq_of_homotopy_idp (f : Π x, P x) : eq_of_homotopy (λx : A, idpath (f x)) = idpath f :=
is_equiv.left_inv apd10 idp
definition naive_funext_of_ua : naive_funext :=
λ A P f g h, eq_of_homotopy h
protected definition homotopy.rec_on [recursor] {Q : (f ~ g) → Type} (p : f ~ g)
(H : Π(q : f = g), Q (apd10 q)) : Q p :=
right_inv apd10 p ▸ H (eq_of_homotopy p)
protected definition homotopy.rec_on_idp [recursor] {Q : Π{g}, (f ~ g) → Type} {g : Π x, P x} (p : f ~ g) (H : Q (homotopy.refl f)) : Q p :=
homotopy.rec_on p (λq, eq.rec_on q H)
definition eq_of_homotopy_inv {f g : Π x, P x} (H : f ~ g)
: eq_of_homotopy (λx, (H x)⁻¹) = (eq_of_homotopy H)⁻¹ :=
begin
apply homotopy.rec_on_idp H,
rewrite [+eq_of_homotopy_idp]
end
definition eq_of_homotopy_con {f g h : Π x, P x} (H1 : f ~ g) (H2 : g ~ h)
: eq_of_homotopy (λx, H1 x ⬝ H2 x) = eq_of_homotopy H1 ⬝ eq_of_homotopy H2 :=
begin
apply homotopy.rec_on_idp H1,
apply homotopy.rec_on_idp H2,
rewrite [+eq_of_homotopy_idp]
end
|
a014eeaa5ad712a9b25d2171f7dfd07a940fe36f | 32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7 | /stage0/src/Lean/Data/Name.lean | ce82a3001e6bce1a9a80671632afd5816ef811f9 | [
"Apache-2.0"
] | permissive | walterhu1015/lean4 | b2c71b688975177402758924eaa513475ed6ce72 | 2214d81e84646a905d0b20b032c89caf89c737ad | refs/heads/master | 1,671,342,096,906 | 1,599,695,985,000 | 1,599,695,985,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,687 | 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 stringToName : HasCoe String Name :=
⟨mkNameSimple⟩
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 => mkNameStr newP s
| num p s _, newP => mkNameNum newP s
def components' : Name → List Name
| anonymous => []
| str n s _ => mkNameStr anonymous s :: components' n
| num n v _ => mkNameNum 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 mkNameStr (p.replacePrefix queryP newP) s
| n@(num p s _), queryP, newP => if n == queryP then newP else mkNameNum (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 (@HasLess.Less Name Name.hasLtQuick) :=
inferInstanceAs (DecidableRel (fun a b => Name.quickLt a b = true))
def appendAfter : Name → String → Name
| str p s _, suffix => mkNameStr p (s ++ suffix)
| n, suffix => mkNameStr n suffix
def appendIndexAfter : Name → Nat → Name
| str p s _, idx => mkNameStr p (s ++ "_" ++ toString idx)
| n, idx => mkNameStr n ("_" ++ toString idx)
def appendBefore : Name → String → Name
| anonymous, pre => mkNameStr anonymous pre
| str p s _, pre => mkNameStr p (pre ++ s)
| num p n _, pre => mkNameNum (mkNameStr p pre) n
/- 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
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) : HasEmptyc (NameMap α) := ⟨mkNameMap α⟩
instance (α : Type) : Inhabited (NameMap α) := ⟨{}⟩
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 : HasEmptyc NameSet := ⟨empty⟩
instance : Inhabited NameSet := ⟨{}⟩
def insert (s : NameSet) (n : Name) := 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 : HasEmptyc NameHashSet := ⟨empty⟩
instance : Inhabited NameHashSet := ⟨{}⟩
def insert (s : NameHashSet) (n : Name) := s.insert n
def contains (s : NameHashSet) (n : Name) : Bool := s.contains n
end NameHashSet
end Lean
open Lean
def String.toName (s : String) : Name :=
let ps := s.splitOn ".";
ps.foldl (fun n p => mkNameStr n p.trim) Name.anonymous
|
4b329d89f042208138ede045f08e67d2f04fafee | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/combinatorics/derangements/exponential.lean | 484d6d8d0529f46f752b228cc06fa268f1d4c911 | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,888 | lean | /-
Copyright (c) 2021 Henry Swanson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henry Swanson, Patrick Massot
-/
import analysis.normed_space.exponential
import combinatorics.derangements.finite
import order.filter.basic
/-!
# Derangement exponential series
This file proves that the probability of a permutation on n elements being a derangement is 1/e.
The specific lemma is `num_derangements_tendsto_inv_e`.
-/
open filter
open_locale big_operators
open_locale topological_space
theorem num_derangements_tendsto_inv_e :
tendsto (λ n, (num_derangements n : ℝ) / n.factorial) at_top
(𝓝 (real.exp (-1))) :=
begin
-- we show that d(n)/n! is the partial sum of exp(-1), but offset by 1.
-- this isn't entirely obvious, since we have to ensure that asc_factorial and
-- factorial interact in the right way, e.g., that k ≤ n always
let s : ℕ → ℝ := λ n, ∑ k in finset.range n, (-1 : ℝ)^k / k.factorial,
suffices : ∀ n : ℕ, (num_derangements n : ℝ) / n.factorial = s(n+1),
{ simp_rw this,
-- shift the function by 1, and then use the fact that the partial sums
-- converge to the infinite sum
rw tendsto_add_at_top_iff_nat 1,
apply has_sum.tendsto_sum_nat,
-- there's no specific lemma for ℝ that ∑ x^k/k! sums to exp(x), but it's
-- true in more general fields, so use that lemma
rw real.exp_eq_exp_ℝ_ℝ,
exact exp_series_field_has_sum_exp (-1 : ℝ) },
intro n,
rw [← int.cast_coe_nat, num_derangements_sum],
push_cast,
rw finset.sum_div,
-- get down to individual terms
refine finset.sum_congr (refl _) _,
intros k hk,
have h_le : k ≤ n := finset.mem_range_succ_iff.mp hk,
rw [nat.asc_factorial_eq_div, add_sub_cancel_of_le h_le],
push_cast [nat.factorial_dvd_factorial h_le],
field_simp [nat.factorial_ne_zero],
ring,
end
|
0bf2e6716727681a6d842f1c6d2c8d61c66fab3d | 9cba98daa30c0804090f963f9024147a50292fa0 | /time_series/geom3d.lean | c24683fa1763d0ddf586a90eb873361aa776aef1 | [] | no_license | kevinsullivan/phys | dcb192f7b3033797541b980f0b4a7e75d84cea1a | ebc2df3779d3605ff7a9b47eeda25c2a551e011f | refs/heads/master | 1,637,490,575,500 | 1,629,899,064,000 | 1,629,899,064,000 | 168,012,884 | 0 | 3 | null | 1,629,644,436,000 | 1,548,699,832,000 | Lean | UTF-8 | Lean | false | false | 4,207 | lean | import .definitions
import ..geom.geom3d
variables
{tf : time_frame} (ts : time_space tf)
{gf : geom3d_frame} (gs : geom3d_space gf)
{gf2 : geom3d_frame} (gs2 : geom3d_space gf2)
(min_t max_t : time ts)
/-
impossible to write this definition,
-/
definition geom3d_series :=
time_series ts geom3d_space
abbreviation geom3d_frame_series :=
time_series ts geom3d_frame
abbreviation displacement3d_series :=
time_series ts (displacement3d gs)
abbreviation position3d_series :=
time_series ts (position3d gs)
abbreviation orientation3d_series :=
time_series ts (orientation3d gs)
abbreviation rotation3d_series :=
time_series ts (rotation3d gs)
abbreviation pose3d_series :=
time_series ts (pose3d gs)
noncomputable def mk_geom3d_frame_series_empty : geom3d_frame_series ts :=
λt, inhabited.default geom3d_frame
noncomputable def mk_displacement3d_series_empty : displacement3d_series ts gs :=
λt, inhabited.default (displacement3d gs)
noncomputable def mk_position3d_series_empty : position3d_series ts gs :=
λt, inhabited.default (position3d gs)
noncomputable def mk_orientation3d_series_empty : orientation3d_series ts gs :=
λt, inhabited.default (orientation3d gs)
noncomputable def mk_rotation3d_series_empty : rotation3d_series ts gs :=
λt, inhabited.default (rotation3d gs)
noncomputable def mk_pose3d_series_empty : pose3d_series ts gs :=
λt, inhabited.default (pose3d gs)
abbreviation geom3d_frame_discrete :=
discrete_series ts geom3d_frame
abbreviation displacement3d_discrete :=
discrete_series ts (displacement3d gs)
abbreviation position3d_discrete :=
discrete_series ts (position3d gs)
abbreviation orientation3d_discrete :=
discrete_series ts (orientation3d gs)
abbreviation rotation3d_discrete :=
discrete_series ts (rotation3d gs)
abbreviation pose3d_discrete :=
discrete_series ts (pose3d gs)
abbreviation geom3d_transform_discrete :=
discrete_series ts (geom3d_transform gs gs2)
noncomputable def geom3d_transform_discrete.transform_pose3d
{tf : time_frame} {ts : time_space tf}
{gf : geom3d_frame} {gs : geom3d_space gf}
{gf2 : geom3d_frame} {gs2 : geom3d_space gf}
(tr : geom3d_transform_discrete ts gs gs2) :
pose3d_discrete ts gs → pose3d_discrete ts gs2 → pose3d_discrete ts gs2
:=
λpd pd2, pd2.update ⟨tr.head.timestamp,(tr.head.value.transform_pose3d pd.head.value)⟩
noncomputable def geom3d_transform_discrete.transform_pose3d_latest
{tf : time_frame} {ts : time_space tf}
{gf : geom3d_frame} {gs : geom3d_space gf}
{gf2 : geom3d_frame} {gs2 : geom3d_space gf}
(tr : geom3d_transform_discrete ts gs gs2) :
pose3d_discrete ts gs → pose3d_discrete ts gs2 → pose3d_discrete ts gs2
:=
λpd pd2, pd2.update ⟨tr.head.timestamp,(tr.latest.value.transform_pose3d pd.head.value)⟩
notation N`[`T`⬝`O`]` := geom3d_transform_discrete.transform_pose3d_latest
noncomputable def mk_geom3d_frame_discrete_empty : geom3d_frame_discrete ts :=
discrete_series.mk_empty
noncomputable def mk_displacement3d_discrete_empty : displacement3d_discrete ts gs :=
discrete_series.mk_empty
noncomputable def mk_position3d_discrete_empty : position3d_discrete ts gs :=
discrete_series.mk_empty
noncomputable def mk_orientation3d_discrete_empty : orientation3d_discrete ts gs :=
discrete_series.mk_empty
noncomputable def mk_rotation3d_discrete_empty : rotation3d_discrete ts gs :=
discrete_series.mk_empty
noncomputable def mk_pose3d_discrete_empty : pose3d_discrete ts gs :=
discrete_series.mk_empty
noncomputable def mk_geom3d_transform_discrete_empty : geom3d_transform_discrete ts gs gs2 :=
discrete_series.mk_empty
abbreviation geom3d_frame_discrete_ici :=
discrete_series.Ici ts geom3d_frame min_t
abbreviation displacement3d_discrete_ici :=
discrete_series.Ici ts (displacement3d gs) min_t
abbreviation position3d_discrete_ici :=
discrete_series.Ici ts (position3d gs) min_t
abbreviation orientation3d_discrete_ici :=
discrete_series.Ici ts (orientation3d gs) min_t
abbreviation rotation3d_discrete_ici :=
discrete_series.Ici ts (rotation3d gs) min_t
abbreviation pose3d_discrete_ici :=
discrete_series.Ici ts (pose3d gs) min_t |
f8b7a34e09bd18fb4d04931773df05a9a57b8f48 | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /library/data/nat/pairing.lean | 5befe9ef77a6024dd016996314134f05959d6055 | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,517 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Elegant pairing function.
-/
import data.nat.sqrt data.nat.div
open prod decidable
open algebra
namespace nat
definition mkpair (a b : nat) : nat :=
if a < b then b*b + a else a*a + a + b
definition unpair (n : nat) : nat × nat :=
let s := sqrt n in
if n - s*s < s then (n - s*s, s) else (s, n - s*s - s)
theorem mkpair_unpair (n : nat) : mkpair (pr1 (unpair n)) (pr2 (unpair n)) = n :=
let s := sqrt n in
by_cases
(suppose n - s*s < s,
begin
esimp [unpair],
rewrite [if_pos this],
esimp [mkpair],
rewrite [if_pos this, add_sub_of_le (sqrt_lower n)]
end)
(suppose h₁ : ¬ n - s*s < s,
have s ≤ n - s*s, from le_of_not_gt h₁,
assert s + s*s ≤ n - s*s + s*s, from add_le_add_right this (s*s),
assert s*s + s ≤ n, by rewrite [nat.sub_add_cancel (sqrt_lower n) at this,
add.comm at this]; assumption,
have n ≤ s*s + s + s, from sqrt_upper n,
have n - s*s ≤ s + s, from calc
n - s*s ≤ (s*s + s + s) - s*s : nat.sub_le_sub_right this (s*s)
... = (s*s + (s+s)) - s*s : by rewrite add.assoc
... = s + s : by rewrite nat.add_sub_cancel_left,
have n - s*s - s ≤ s, from calc
n - s*s - s ≤ (s + s) - s : nat.sub_le_sub_right this s
... = s : by rewrite nat.add_sub_cancel_left,
assert h₂ : ¬ s < n - s*s - s, from not_lt_of_ge this,
begin
esimp [unpair],
rewrite [if_neg h₁], esimp,
esimp [mkpair],
rewrite [if_neg h₂, nat.sub_sub, add_sub_of_le `s*s + s ≤ n`],
end)
theorem unpair_mkpair (a b : nat) : unpair (mkpair a b) = (a, b) :=
by_cases
(suppose a < b,
assert a ≤ b + b, from calc
a ≤ b : le_of_lt this
... ≤ b+b : !le_add_right,
begin
esimp [mkpair],
rewrite [if_pos `a < b`],
esimp [unpair],
rewrite [sqrt_offset_eq `a ≤ b + b`, nat.add_sub_cancel_left, if_pos `a < b`]
end)
(suppose ¬ a < b,
have b ≤ a, from le_of_not_gt this,
assert a + b ≤ a + a, from add_le_add_left this a,
have a + b ≥ a, from !le_add_right,
assert ¬ a + b < a, from not_lt_of_ge this,
begin
esimp [mkpair],
rewrite [if_neg `¬ a < b`],
esimp [unpair],
rewrite [add.assoc (a * a) a b, sqrt_offset_eq `a + b ≤ a + a`, *nat.add_sub_cancel_left,
if_neg `¬ a + b < a`]
end)
open prod.ops
theorem unpair_lt_aux {n : nat} : n ≥ 1 → (unpair n).1 < n :=
suppose n ≥ 1,
or.elim (eq_or_lt_of_le this)
(suppose 1 = n, by subst n; exact dec_trivial)
(suppose n > 1,
let s := sqrt n in
by_cases
(suppose h : n - s*s < s,
assert n > 0, from lt_of_succ_lt `n > 1`,
assert sqrt n > 0, from sqrt_pos_of_pos this,
assert sqrt n * sqrt n > 0, from mul_pos this this,
begin unfold unpair, rewrite [if_pos h], esimp, exact sub_lt `n > 0` `sqrt n * sqrt n > 0` end)
(suppose ¬ n - s*s < s, begin unfold unpair, rewrite [if_neg this], esimp, apply sqrt_lt `n > 1` end))
theorem unpair_lt : ∀ (n : nat), (unpair n).1 < succ n
| 0 := dec_trivial
| (succ n) :=
have (unpair (succ n)).1 < succ n, from unpair_lt_aux dec_trivial,
lt.step this
end nat
|
efbe12de21d0f2d37cd47d005b3f7c5fc522616b | 1fd908b06e3f9c1252cb2285ada1102623a67f72 | /prop_trunc.lean | 98caafa0a61fb464f042864da6724b026ccc1f2a | [
"Apache-2.0"
] | permissive | avigad/hott3 | 609a002849182721e7c7ae536d9f1e2956d6d4d3 | f64750cd2de7a81e87d4828246d1369d59f16f43 | refs/heads/master | 1,629,027,243,322 | 1,510,946,717,000 | 1,510,946,717,000 | 103,570,461 | 0 | 0 | null | 1,505,415,620,000 | 1,505,415,620,000 | null | UTF-8 | Lean | false | false | 1,965 | lean | /-
Copyright (c) 2015 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Proof of the @[hott] theorem that (is_trunc n A) is a mere proposition
We prove this here to avoid circular dependency of files
We want to use this in .equiv; .equiv is imported by .function and .function is imported by .trunc
-/
import types.pi
universe u
namespace hott
hott_theory
open hott.sigma
namespace is_trunc
@[hott] def is_contr.sigma_char (A : Type u) :
(Σ (center : A), Π (a : A), center = a) ≃ (is_contr A) :=
begin
fapply equiv.MK,
{ intro S, exact (is_contr.mk S.1 S.2)},
{ intro H, cases H with H', cases H' with ce co, exact ⟨ce, co⟩},
{ intro H, cases H with H', cases H' with ce co, exact idp},
{ intro S, cases S, apply idp}
end
@[hott] def is_trunc.pi_char (n : ℕ₋₂) (A : Type u) :
(Π (x y : A), is_trunc n (x = y)) ≃ (is_trunc (n .+1) A) :=
begin
fapply equiv.MK,
{ exact is_trunc_succ_intro},
{ intros H x y, apply is_trunc_eq},
{ intro H, cases H, apply idp},
{ intro P, apply eq_of_homotopy, intro a, apply eq_of_homotopy, intro b,
change is_trunc.mk (to_internal n (a = b)) = P a b,
induction (P a b), apply idp},
end
@[hott] lemma is_prop_is_trunc (n : ℕ₋₂) (A : Type u) : is_prop (is_trunc n A) :=
begin
induction n generalizing A,
{ apply is_trunc_equiv_closed,
{ apply is_contr.sigma_char },
apply is_prop.mk, intros,
fapply sigma_eq, apply x.2,
apply is_prop.elimo', apply pi.is_prop_pi_eq },
{ apply is_trunc_equiv_closed,
apply is_trunc.pi_char,
apply_instance },
end
local attribute [instance] is_prop_is_trunc
@[hott, instance] def is_trunc_succ_is_trunc (n m : ℕ₋₂) (A : Type u) :
is_trunc (n.+1) (is_trunc m A) :=
is_trunc_succ_of_is_prop (is_trunc m A) n
end is_trunc
end hott |
cad8d1e5df0b1e1f6a3305e103be4ff64205679b | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/logic/examples/propositional/deceq.lean | 08b1443a29de7d6a3fdc4fa76a08cec1ec97acfc | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,881 | 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
PropF has decidable equality
-/
import .soundness
open bool decidable nat
namespace PropF
-- Show that PropF has decidable equality
definition equal : PropF → PropF → bool
| (Var x) (Var y) := if x = y then tt else ff
| Bot Bot := tt
| (Conj p₁ p₂) (Conj q₁ q₂) := equal p₁ q₁ && equal p₂ q₂
| (Disj p₁ p₂) (Disj q₁ q₂) := equal p₁ q₁ && equal p₂ q₂
| (Impl p₁ p₂) (Impl q₁ q₂) := equal p₁ q₁ && equal p₂ q₂
| _ _ := ff
lemma equal_refl : ∀ p, equal p p = tt
| (Var x) := if_pos rfl
| Bot := rfl
| (Conj p₁ p₂) := begin change (equal p₁ p₁ && equal p₂ p₂ = tt), rewrite *equal_refl end
| (Disj p₁ p₂) := begin change (equal p₁ p₁ && equal p₂ p₂ = tt), rewrite *equal_refl end
| (Impl p₁ p₂) := begin change (equal p₁ p₁ && equal p₂ p₂ = tt), rewrite *equal_refl end
lemma equal_to_eq : ∀ ⦃p q⦄, equal p q = tt → p = q
| (Var x) (Var y) H :=
if H₁ : x = y then congr_arg Var H₁
else by rewrite [▸ (if x = y then tt else ff) = tt at H, if_neg H₁ at H]; exact (absurd H ff_ne_tt)
| Bot Bot H := rfl
| (Conj p₁ p₂) (Conj q₁ q₂) H :=
by rewrite [equal_to_eq (band_elim_left H), equal_to_eq (band_elim_right H)]
| (Disj p₁ p₂) (Disj q₁ q₂) H :=
by rewrite [equal_to_eq (band_elim_left H), equal_to_eq (band_elim_right H)]
| (Impl p₁ p₂) (Impl q₁ q₂) H :=
by rewrite [equal_to_eq (band_elim_left H), equal_to_eq (band_elim_right H)]
attribute [instance]
lemma has_decidable_eq : decidable_eq PropF :=
decidable_eq_of_bool_pred equal_to_eq equal_refl
end PropF
|
2162efed663100f9788c948af186af2ce9cd0220 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/algebra/pi.lean | 444bd8c915fe547cf780a97e7cdbb1c8b694e670 | [
"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 | 5,202 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.algebra.equiv
/-!
# The R-algebra structure on families of R-algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The R-algebra structure on `Π i : I, A i` when each `A i` is an R-algebra.
## Main defintions
* `pi.algebra`
* `pi.eval_alg_hom`
* `pi.const_alg_hom`
-/
universes u v w
namespace pi
variable {I : Type u} -- The indexing type
variable {R : Type*} -- The scalar type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
variables (I f)
instance algebra {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] :
algebra R (Π i : I, f i) :=
{ commutes' := λ a f, begin ext, simp [algebra.commutes], end,
smul_def' := λ a f, begin ext, simp [algebra.smul_def], end,
..(pi.ring_hom (λ i, algebra_map R (f i)) : R →+* Π i : I, f i) }
lemma algebra_map_def {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] (a : R) :
algebra_map R (Π i, f i) a = (λ i, algebra_map R (f i) a) := rfl
@[simp] lemma algebra_map_apply {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] (a : R) (i : I) :
algebra_map R (Π i, f i) a i = algebra_map R (f i) a := rfl
-- One could also build a `Π i, R i`-algebra structure on `Π i, A i`,
-- when each `A i` is an `R i`-algebra, although I'm not sure that it's useful.
variables {I} (R) (f)
/-- `function.eval` as an `alg_hom`. The name matches `pi.eval_ring_hom`, `pi.eval_monoid_hom`,
etc. -/
@[simps]
def eval_alg_hom {r : comm_semiring R} [Π i, semiring (f i)] [Π i, algebra R (f i)] (i : I) :
(Π i, f i) →ₐ[R] f i :=
{ to_fun := λ f, f i, commutes' := λ r, rfl, .. pi.eval_ring_hom f i}
variables (A B : Type*) [comm_semiring R] [semiring B] [algebra R B]
/-- `function.const` as an `alg_hom`. The name matches `pi.const_ring_hom`, `pi.const_monoid_hom`,
etc. -/
@[simps]
def const_alg_hom : B →ₐ[R] (A → B) :=
{ to_fun := function.const _,
commutes' := λ r, rfl,
.. pi.const_ring_hom A B}
/-- When `R` is commutative and permits an `algebra_map`, `pi.const_ring_hom` is equal to that
map. -/
@[simp] lemma const_ring_hom_eq_algebra_map : const_ring_hom A R = algebra_map R (A → R) :=
rfl
@[simp] lemma const_alg_hom_eq_algebra_of_id : const_alg_hom R A R = algebra.of_id R (A → R) :=
rfl
end pi
/-- A special case of `pi.algebra` for non-dependent types. Lean struggles to elaborate
definitions elsewhere in the library without this, -/
instance function.algebra {R : Type*} (I : Type*) (A : Type*) [comm_semiring R]
[semiring A] [algebra R A] : algebra R (I → A) :=
pi.algebra _ _
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {I : Type*}
variables [comm_semiring R] [semiring A] [semiring B]
variables [algebra R A] [algebra R B]
/-- `R`-algebra homomorphism between the function spaces `I → A` and `I → B`, induced by an
`R`-algebra homomorphism `f` between `A` and `B`. -/
@[simps] protected def comp_left (f : A →ₐ[R] B) (I : Type*) : (I → A) →ₐ[R] (I → B) :=
{ to_fun := λ h, f ∘ h,
commutes' := λ c, by { ext, exact f.commutes' c },
.. f.to_ring_hom.comp_left I }
end alg_hom
namespace alg_equiv
/-- A family of algebra equivalences `Π j, (A₁ j ≃ₐ A₂ j)` generates a
multiplicative equivalence between `Π j, A₁ j` and `Π j, A₂ j`.
This is the `alg_equiv` version of `equiv.Pi_congr_right`, and the dependent version of
`alg_equiv.arrow_congr`.
-/
@[simps apply]
def Pi_congr_right {R ι : Type*} {A₁ A₂ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)]
(e : Π i, A₁ i ≃ₐ[R] A₂ i) : (Π i, A₁ i) ≃ₐ[R] Π i, A₂ i :=
{ to_fun := λ x j, e j (x j),
inv_fun := λ x j, (e j).symm (x j),
commutes' := λ r, by { ext i, simp },
.. @ring_equiv.Pi_congr_right ι A₁ A₂ _ _ (λ i, (e i).to_ring_equiv) }
@[simp]
lemma Pi_congr_right_refl {R ι : Type*} {A : ι → Type*} [comm_semiring R]
[Π i, semiring (A i)] [Π i, algebra R (A i)] :
Pi_congr_right (λ i, (alg_equiv.refl : A i ≃ₐ[R] A i)) = alg_equiv.refl := rfl
@[simp]
lemma Pi_congr_right_symm {R ι : Type*} {A₁ A₂ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)]
(e : Π i, A₁ i ≃ₐ[R] A₂ i) : (Pi_congr_right e).symm = (Pi_congr_right $ λ i, (e i).symm) := rfl
@[simp]
lemma Pi_congr_right_trans {R ι : Type*} {A₁ A₂ A₃ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, semiring (A₃ i)]
[Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)] [Π i, algebra R (A₃ i)]
(e₁ : Π i, A₁ i ≃ₐ[R] A₂ i) (e₂ : Π i, A₂ i ≃ₐ[R] A₃ i) :
(Pi_congr_right e₁).trans (Pi_congr_right e₂) = (Pi_congr_right $ λ i, (e₁ i).trans (e₂ i)) :=
rfl
end alg_equiv
|
b0dc1ce99308af184f6c7cd1bb6b7abdc4de6c9d | 957a80ea22c5abb4f4670b250d55534d9db99108 | /library/init/native/util.lean | 38c47434b755944c3ac8f625fc222947c145bb2f | [
"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 | 1,940 | lean | /-
Copyright (c) 2016 Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jared Roesch
-/
prelude
import init.meta.format
import init.meta.expr
import init.data.string
import init.category.state
import init.native.result
import init.native.internal
import init.native.builtin
meta def is_nat_cases_on (n : name) : bool :=
`nat.cases_on = n
meta def is_cases_on (head : expr) : bool :=
if is_nat_cases_on (expr.const_name head)
then bool.tt
else
match native.is_internal_cases head with
| option.some _ := bool.tt
| option.none :=
match native.get_builtin (expr.const_name head) with
| option.some b :=
match b with
| builtin.cases _ _ := bool.tt
| _ := bool.ff
end
| option.none := bool.ff
end
end
meta definition mk_local (n : name) : expr :=
expr.local_const n n binder_info.default (expr.const n [])
meta def mk_neutral_expr : expr :=
expr.const `_neutral_ []
meta def mk_call : expr → list expr → expr
| head [] := head
| head (e :: es) := mk_call (expr.app head e) es
-- really need to get out of the meta language so I can prove things, I should just have a unit test lemma
meta def under_lambda {M} [monad M] (fresh_name : M name) (action : expr -> M expr) : expr → M expr
| (expr.lam n bi ty body) := do
fresh ← fresh_name,
body' ← under_lambda $ expr.instantiate_var body (mk_local fresh),
return $ expr.lam n bi ty (expr.abstract body' (mk_local fresh))
| e := action e
inductive application_kind
| cases
| constructor
| other
-- I like this pattern of hiding the annoying C++ interfaces
-- behind more typical FP constructs so we can do case analysis instead.
meta def app_kind (head : expr) : application_kind :=
if is_cases_on head
then application_kind.cases
else match native.is_internal_cnstr head with
| some _ := application_kind.constructor
| none := application_kind.other
end
|
16e981eb091849056034e87fdb0137b13c509295 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/linear_algebra/dfinsupp.lean | 2aaa4f83e9b08fa873639c75e6ff090d459132f5 | [
"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 | 20,748 | 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 data.finsupp.to_dfinsupp
import linear_algebra.basis
/-!
# Properties of the module `Π₀ i, M i`
Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i`
is defined in `data.dfinsupp`.
In this file we define `linear_map` versions of various maps:
* `dfinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `dfinsupp.single a` as a linear map;
* `dfinsupp.lmk s : (Π i : (↑s : set ι), M i) →ₗ[R] Π₀ i, M i`: `dfinsupp.single a` as a linear map;
* `dfinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `λ f, f i` as a linear map;
* `dfinsupp.lsum`: `dfinsupp.sum` or `dfinsupp.lift_add_hom` as a `linear_map`;
## Implementation notes
This file should try to mirror `linear_algebra.finsupp` where possible. The API of `finsupp` is
much more developed, but many lemmas in that file should be eligible to copy over.
## Tags
function with finite support, module, linear algebra
-/
variables {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
variables [dec_ι : decidable_eq ι]
namespace dfinsupp
variables [semiring R] [Π i, add_comm_monoid (M i)] [Π i, module R (M i)]
variables [add_comm_monoid N] [module R N]
include dec_ι
/-- `dfinsupp.mk` as a `linear_map`. -/
def lmk (s : finset ι) : (Π i : (↑s : set ι), M i) →ₗ[R] Π₀ i, M i :=
{ to_fun := mk s, map_add' := λ _ _, mk_add, map_smul' := λ c x, mk_smul c x}
/-- `dfinsupp.single` as a `linear_map` -/
def lsingle (i) : M i →ₗ[R] Π₀ i, M i :=
{ to_fun := single i, map_smul' := single_smul, .. dfinsupp.single_add_hom _ _ }
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/
lemma lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄
(h : ∀ i x, φ (single i x) = ψ (single i x)) :
φ = ψ :=
linear_map.to_add_monoid_hom_injective $ add_hom_ext h
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere.
See note [partially-applied ext lemmas].
After apply this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/
@[ext] lemma lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄
(h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) :
φ = ψ :=
lhom_ext $ λ i, linear_map.congr_fun (h i)
omit dec_ι
/-- Interpret `λ (f : Π₀ i, M i), f i` as a linear map. -/
def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i :=
{ to_fun := λ f, f i,
map_add' := λ f g, add_apply f g i,
map_smul' := λ c f, smul_apply c f i}
include dec_ι
@[simp] lemma lmk_apply (s : finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x := rfl
@[simp] lemma lsingle_apply (i : ι) (x : M i) : (lsingle i : _ →ₗ[R] _) x = single i x := rfl
omit dec_ι
@[simp] lemma lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : _ →ₗ[R] _) f = f i := rfl
section lsum
/-- Typeclass inference can't find `dfinsupp.add_comm_monoid` without help for this case.
This instance allows it to be found where it is needed on the LHS of the colon in
`dfinsupp.module_of_linear_map`. -/
instance add_comm_monoid_of_linear_map : add_comm_monoid (Π₀ (i : ι), M i →ₗ[R] N) :=
@dfinsupp.add_comm_monoid _ (λ i, M i →ₗ[R] N) _
/-- Typeclass inference can't find `dfinsupp.module` without help for this case.
This is needed to define `dfinsupp.lsum` below.
The cause seems to be an inability to unify the `Π i, add_comm_monoid (M i →ₗ[R] N)` instance that
we have with the `Π i, has_zero (M i →ₗ[R] N)` instance which appears as a parameter to the
`dfinsupp` type. -/
instance module_of_linear_map [semiring S] [module S N] [smul_comm_class R S N] :
module S (Π₀ (i : ι), M i →ₗ[R] N) :=
@dfinsupp.module _ _ (λ i, M i →ₗ[R] N) _ _ _
variables (S)
include dec_ι
/-- The `dfinsupp` version of `finsupp.lsum`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def lsum [semiring S] [module S N] [smul_comm_class R S N] :
(Π i, M i →ₗ[R] N) ≃ₗ[S] ((Π₀ i, M i) →ₗ[R] N) :=
{ to_fun := λ F,
{ to_fun := sum_add_hom (λ i, (F i).to_add_monoid_hom),
map_add' := (lift_add_hom (λ i, (F i).to_add_monoid_hom)).map_add,
map_smul' := λ c f, by
{ dsimp,
apply dfinsupp.induction f,
{ rw [smul_zero, add_monoid_hom.map_zero, smul_zero] },
{ intros a b f ha hb hf,
rw [smul_add, add_monoid_hom.map_add, add_monoid_hom.map_add, smul_add, hf, ←single_smul,
sum_add_hom_single, sum_add_hom_single, linear_map.to_add_monoid_hom_coe,
linear_map.map_smul], } } },
inv_fun := λ F i, F.comp (lsingle i),
left_inv := λ F, by { ext x y, simp },
right_inv := λ F, by { ext x y, simp },
map_add' := λ F G, by { ext x y, simp },
map_smul' := λ c F, by { ext, simp } }
/-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sum_add_hom`
with `dfinsupp.lsum_apply_apply`. -/
lemma lsum_single [semiring S] [module S N] [smul_comm_class R S N]
(F : Π i, M i →ₗ[R] N) (i) (x : M i) :
lsum S F (single i x) = F i x :=
sum_add_hom_single _ _ _
end lsum
/-! ### Bundled versions of `dfinsupp.map_range`
The names should match the equivalent bundled `finsupp.map_range` definitions.
-/
section map_range
variables {β β₁ β₂: ι → Type*}
variables [Π i, add_comm_monoid (β i)] [Π i, add_comm_monoid (β₁ i)] [Π i, add_comm_monoid (β₂ i)]
variables [Π i, module R (β i)] [Π i, module R (β₁ i)] [Π i, module R (β₂ i)]
lemma map_range_smul (f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0)
(r : R) (hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i):
map_range f hf (r • g) = r • map_range f hf g :=
begin
ext,
simp only [map_range_apply f, coe_smul, pi.smul_apply, hf']
end
/-- `dfinsupp.map_range` as an `linear_map`. -/
@[simps apply]
def map_range.linear_map (f : Π i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] (Π₀ i, β₂ i) :=
{ to_fun := map_range (λ i x, f i x) (λ i, (f i).map_zero),
map_smul' := λ r, map_range_smul _ _ _ (λ i, (f i).map_smul r),
.. map_range.add_monoid_hom (λ i, (f i).to_add_monoid_hom) }
@[simp]
lemma map_range.linear_map_id :
map_range.linear_map (λ i, (linear_map.id : (β₂ i) →ₗ[R] _)) = linear_map.id :=
linear_map.ext map_range_id
lemma map_range.linear_map_comp (f : Π i, β₁ i →ₗ[R] β₂ i) (f₂ : Π i, β i →ₗ[R] β₁ i):
map_range.linear_map (λ i, (f i).comp (f₂ i)) =
(map_range.linear_map f).comp (map_range.linear_map f₂) :=
linear_map.ext $ map_range_comp (λ i x, f i x) (λ i x, f₂ i x) _ _ _
include dec_ι
lemma sum_map_range_index.linear_map
[Π (i : ι) (x : β₁ i), decidable (x ≠ 0)] [Π (i : ι) (x : β₂ i), decidable (x ≠ 0)]
{f : Π i, β₁ i →ₗ[R] β₂ i} {h : Π i, β₂ i →ₗ[R] N} {l : Π₀ i, β₁ i} :
dfinsupp.lsum ℕ h (map_range.linear_map f l) = dfinsupp.lsum ℕ (λ i, (h i).comp (f i)) l :=
by simpa [dfinsupp.sum_add_hom_apply] using
@sum_map_range_index ι N _ _ _ _ _ _ _ _ (λ i, f i) (λ i, by simp) l (λ i, h i) (λ i, by simp)
omit dec_ι
/-- `dfinsupp.map_range.linear_map` as an `linear_equiv`. -/
@[simps apply]
def map_range.linear_equiv (e : Π i, β₁ i ≃ₗ[R] β₂ i) : (Π₀ i, β₁ i) ≃ₗ[R] (Π₀ i, β₂ i) :=
{ to_fun := map_range (λ i x, e i x) (λ i, (e i).map_zero),
inv_fun := map_range (λ i x, (e i).symm x) (λ i, (e i).symm.map_zero),
.. map_range.add_equiv (λ i, (e i).to_add_equiv),
.. map_range.linear_map (λ i, (e i).to_linear_map) }
@[simp]
lemma map_range.linear_equiv_refl :
(map_range.linear_equiv $ λ i, linear_equiv.refl R (β₁ i)) = linear_equiv.refl _ _ :=
linear_equiv.ext map_range_id
lemma map_range.linear_equiv_trans (f : Π i, β i ≃ₗ[R] β₁ i) (f₂ : Π i, β₁ i ≃ₗ[R] β₂ i):
map_range.linear_equiv (λ i, (f i).trans (f₂ i)) =
(map_range.linear_equiv f).trans (map_range.linear_equiv f₂) :=
linear_equiv.ext $ map_range_comp (λ i x, f₂ i x) (λ i x, f i x) _ _ _
@[simp]
lemma map_range.linear_equiv_symm (e : Π i, β₁ i ≃ₗ[R] β₂ i) :
(map_range.linear_equiv e).symm = map_range.linear_equiv (λ i, (e i).symm) := rfl
end map_range
section coprod_map
variables [decidable_eq ι] [Π (x : N), decidable (x ≠ 0)]
/-- Given a family of linear maps `f i : M i →ₗ[R] N`, we can form a linear map
`(Π₀ i, M i) →ₗ[R] N` which sends `x : Π₀ i, M i` to the sum over `i` of `f i` applied to `x i`.
This is the map coming from the universal property of `Π₀ i, M i` as the coproduct of the `M i`.
See also `linear_map.coprod` for the binary product version. -/
noncomputable def coprod_map (f : Π (i : ι), M i →ₗ[R] N) : (Π₀ i, M i) →ₗ[R] N :=
finsupp.lsum ℕ (λ i : ι, linear_map.id) ∘ₗ
(@finsupp_lequiv_dfinsupp ι R N _ _ _ _ _).symm.to_linear_map ∘ₗ
(dfinsupp.map_range.linear_map f)
lemma coprod_map_apply (f : Π (i : ι), M i →ₗ[R] N) (x : Π₀ i, M i) :
coprod_map f x =
finsupp.sum (map_range (λ i, f i) (λ i, linear_map.map_zero _) x).to_finsupp (λ i, id) := rfl
end coprod_map
section basis
/-- The direct sum of free modules is free.
Note that while this is stated for `dfinsupp` not `direct_sum`, the types are defeq. -/
noncomputable def basis {η : ι → Type*} (b : Π i, basis (η i) R (M i)) :
basis (Σ i, η i) R (Π₀ i, M i) :=
basis.of_repr ((map_range.linear_equiv (λ i, (b i).repr)).trans
(sigma_finsupp_lequiv_dfinsupp R).symm)
end basis
end dfinsupp
include dec_ι
namespace submodule
variables [semiring R] [add_comm_monoid N] [module R N]
open dfinsupp
lemma dfinsupp_sum_mem {β : ι → Type*} [Π i, has_zero (β i)]
[Π i (x : β i), decidable (x ≠ 0)] (S : submodule R N)
(f : Π₀ i, β i) (g : Π i, β i → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S :=
dfinsupp_sum_mem S f g h
lemma dfinsupp_sum_add_hom_mem {β : ι → Type*} [Π i, add_zero_class (β i)]
(S : submodule R N) (f : Π₀ i, β i) (g : Π i, β i →+ N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) :
dfinsupp.sum_add_hom g f ∈ S :=
dfinsupp_sum_add_hom_mem S f g h
/-- The supremum of a family of submodules is equal to the range of `dfinsupp.lsum`; that is
every element in the `supr` can be produced from taking a finite number of non-zero elements
of `p i`, coercing them to `N`, and summing them. -/
lemma supr_eq_range_dfinsupp_lsum (p : ι → submodule R N) :
supr p = (dfinsupp.lsum ℕ (λ i, (p i).subtype)).range :=
begin
apply le_antisymm,
{ apply supr_le _,
intros i y hy,
exact ⟨dfinsupp.single i ⟨y, hy⟩, dfinsupp.sum_add_hom_single _ _ _⟩, },
{ rintros x ⟨v, rfl⟩,
exact dfinsupp_sum_add_hom_mem _ v _ (λ i _, (le_supr p i : p i ≤ _) (v i).prop) }
end
/-- The bounded supremum of a family of commutative additive submonoids is equal to the range of
`dfinsupp.sum_add_hom` composed with `dfinsupp.filter_add_monoid_hom`; that is, every element in the
bounded `supr` can be produced from taking a finite number of non-zero elements from the `S i` that
satisfy `p i`, coercing them to `γ`, and summing them. -/
lemma bsupr_eq_range_dfinsupp_lsum (p : ι → Prop)
[decidable_pred p] (S : ι → submodule R N) :
(⨆ i (h : p i), S i) =
((dfinsupp.lsum ℕ (λ i, (S i).subtype)).comp (dfinsupp.filter_linear_map R _ p)).range :=
begin
apply le_antisymm,
{ refine supr₂_le (λ i hi y hy, ⟨dfinsupp.single i ⟨y, hy⟩, _⟩),
rw [linear_map.comp_apply, filter_linear_map_apply, filter_single_pos _ _ hi],
exact dfinsupp.sum_add_hom_single _ _ _, },
{ rintros x ⟨v, rfl⟩,
refine dfinsupp_sum_add_hom_mem _ _ _ (λ i hi, _),
refine mem_supr_of_mem i _,
by_cases hp : p i,
{ simp [hp], },
{ simp [hp] }, }
end
lemma mem_supr_iff_exists_dfinsupp (p : ι → submodule R N) (x : N) :
x ∈ supr p ↔ ∃ f : Π₀ i, p i, dfinsupp.lsum ℕ (λ i, (p i).subtype) f = x :=
set_like.ext_iff.mp (supr_eq_range_dfinsupp_lsum p) x
/-- A variant of `submodule.mem_supr_iff_exists_dfinsupp` with the RHS fully unfolded. -/
lemma mem_supr_iff_exists_dfinsupp' (p : ι → submodule R N) [Π i (x : p i), decidable (x ≠ 0)]
(x : N) :
x ∈ supr p ↔ ∃ f : Π₀ i, p i, f.sum (λ i xi, ↑xi) = x :=
begin
rw mem_supr_iff_exists_dfinsupp,
simp_rw [dfinsupp.lsum_apply_apply, dfinsupp.sum_add_hom_apply],
congr',
end
lemma mem_bsupr_iff_exists_dfinsupp (p : ι → Prop) [decidable_pred p] (S : ι → submodule R N)
(x : N) :
x ∈ (⨆ i (h : p i), S i) ↔
∃ f : Π₀ i, S i, dfinsupp.lsum ℕ (λ i, (S i).subtype) (f.filter p) = x :=
set_like.ext_iff.mp (bsupr_eq_range_dfinsupp_lsum p S) x
open_locale big_operators
omit dec_ι
lemma mem_supr_finset_iff_exists_sum {s : finset ι} (p : ι → submodule R N) (a : N) :
a ∈ (⨆ i ∈ s, p i) ↔ ∃ μ : Π i, p i, ∑ i in s, (μ i : N) = a :=
begin
classical,
rw submodule.mem_supr_iff_exists_dfinsupp',
split; rintro ⟨μ, hμ⟩,
{ use λ i, ⟨μ i, (supr_const_le : _ ≤ p i) (coe_mem $ μ i)⟩,
rw ← hμ, symmetry, apply finset.sum_subset,
{ intro x, contrapose, intro hx,
rw [mem_support_iff, not_ne_iff],
ext, rw [coe_zero, ← mem_bot R], convert coe_mem (μ x),
symmetry, exact supr_neg hx },
{ intros x _ hx, rw [mem_support_iff, not_ne_iff] at hx, rw hx, refl } },
{ refine ⟨dfinsupp.mk s _, _⟩,
{ rintro ⟨i, hi⟩, refine ⟨μ i, _⟩,
rw supr_pos, { exact coe_mem _ }, { exact hi } },
simp only [dfinsupp.sum],
rw [finset.sum_subset support_mk_subset, ← hμ],
exact finset.sum_congr rfl (λ x hx, congr_arg coe $ mk_of_mem hx),
{ intros x _ hx, rw [mem_support_iff, not_ne_iff] at hx, rw hx, refl } }
end
end submodule
namespace complete_lattice
open dfinsupp
section semiring
variables [semiring R] [add_comm_monoid N] [module R N]
/-- Independence of a family of submodules can be expressed as a quantifier over `dfinsupp`s.
This is an intermediate result used to prove
`complete_lattice.independent_of_dfinsupp_lsum_injective` and
`complete_lattice.independent.dfinsupp_lsum_injective`. -/
lemma independent_iff_forall_dfinsupp (p : ι → submodule R N) :
independent p ↔
∀ i (x : p i) (v : Π₀ (i : ι), ↥(p i)), lsum ℕ (λ i, (p i).subtype) (erase i v) = x → x = 0 :=
begin
simp_rw [complete_lattice.independent_def, submodule.disjoint_def,
submodule.mem_bsupr_iff_exists_dfinsupp, exists_imp_distrib, filter_ne_eq_erase],
apply forall_congr (λ i, _),
refine subtype.forall'.trans _,
simp_rw submodule.coe_eq_zero,
refl,
end
/- If `dfinsupp.lsum` applied with `submodule.subtype` is injective then the submodules are
independent. -/
lemma independent_of_dfinsupp_lsum_injective (p : ι → submodule R N)
(h : function.injective (lsum ℕ (λ i, (p i).subtype))) :
independent p :=
begin
rw independent_iff_forall_dfinsupp,
intros i x v hv,
replace hv : lsum ℕ (λ i, (p i).subtype) (erase i v) = lsum ℕ (λ i, (p i).subtype) (single i x),
{ simpa only [lsum_single] using hv, },
have := dfinsupp.ext_iff.mp (h hv) i,
simpa [eq_comm] using this,
end
/- If `dfinsupp.sum_add_hom` applied with `add_submonoid.subtype` is injective then the additive
submonoids are independent. -/
lemma independent_of_dfinsupp_sum_add_hom_injective (p : ι → add_submonoid N)
(h : function.injective (sum_add_hom (λ i, (p i).subtype))) :
independent p :=
begin
rw ←independent_map_order_iso_iff (add_submonoid.to_nat_submodule : add_submonoid N ≃o _),
exact independent_of_dfinsupp_lsum_injective _ h,
end
/-- Combining `dfinsupp.lsum` with `linear_map.to_span_singleton` is the same as `finsupp.total` -/
lemma lsum_comp_map_range_to_span_singleton
[Π (m : R), decidable (m ≠ 0)]
(p : ι → submodule R N) {v : ι → N} (hv : ∀ (i : ι), v i ∈ p i) :
((lsum ℕ) (λ i, (p i).subtype) : _ →ₗ[R] _).comp
((map_range.linear_map
(λ i, linear_map.to_span_singleton R ↥(p i) ⟨v i, hv i⟩) : _ →ₗ[R] _).comp
(finsupp_lequiv_dfinsupp R : (ι →₀ R) ≃ₗ[R] _).to_linear_map) =
finsupp.total ι N R v :=
by { ext, simp }
end semiring
section ring
variables [ring R] [add_comm_group N] [module R N]
/- If `dfinsupp.sum_add_hom` applied with `add_submonoid.subtype` is injective then the additive
subgroups are independent. -/
lemma independent_of_dfinsupp_sum_add_hom_injective' (p : ι → add_subgroup N)
(h : function.injective (sum_add_hom (λ i, (p i).subtype))) :
independent p :=
begin
rw ←independent_map_order_iso_iff (add_subgroup.to_int_submodule : add_subgroup N ≃o _),
exact independent_of_dfinsupp_lsum_injective _ h,
end
/-- The canonical map out of a direct sum of a family of submodules is injective when the submodules
are `complete_lattice.independent`.
Note that this is not generally true for `[semiring R]`, for instance when `A` is the
`ℕ`-submodules of the positive and negative integers.
See `counterexamples/direct_sum_is_internal.lean` for a proof of this fact. -/
lemma independent.dfinsupp_lsum_injective {p : ι → submodule R N}
(h : independent p) : function.injective (lsum ℕ (λ i, (p i).subtype)) :=
begin
-- simplify everything down to binders over equalities in `N`
rw independent_iff_forall_dfinsupp at h,
suffices : (lsum ℕ (λ i, (p i).subtype)).ker = ⊥,
{ -- Lean can't find this without our help
letI : add_comm_group (Π₀ i, p i) := @dfinsupp.add_comm_group _ (λ i, p i) _,
rw linear_map.ker_eq_bot at this, exact this },
rw linear_map.ker_eq_bot',
intros m hm,
ext i : 1,
-- split `m` into the piece at `i` and the pieces elsewhere, to match `h`
rw [dfinsupp.zero_apply, ←neg_eq_zero],
refine h i (-m i) m _,
rwa [←erase_add_single i m, linear_map.map_add, lsum_single, submodule.subtype_apply,
add_eq_zero_iff_eq_neg, ←submodule.coe_neg] at hm,
end
/-- The canonical map out of a direct sum of a family of additive subgroups is injective when the
additive subgroups are `complete_lattice.independent`. -/
lemma independent.dfinsupp_sum_add_hom_injective {p : ι → add_subgroup N}
(h : independent p) : function.injective (sum_add_hom (λ i, (p i).subtype)) :=
begin
rw ←independent_map_order_iso_iff (add_subgroup.to_int_submodule : add_subgroup N ≃o _) at h,
exact h.dfinsupp_lsum_injective,
end
/-- A family of submodules over an additive group are independent if and only iff `dfinsupp.lsum`
applied with `submodule.subtype` is injective.
Note that this is not generally true for `[semiring R]`; see
`complete_lattice.independent.dfinsupp_lsum_injective` for details. -/
lemma independent_iff_dfinsupp_lsum_injective (p : ι → submodule R N) :
independent p ↔ function.injective (lsum ℕ (λ i, (p i).subtype)) :=
⟨independent.dfinsupp_lsum_injective, independent_of_dfinsupp_lsum_injective p⟩
/-- A family of additive subgroups over an additive group are independent if and only if
`dfinsupp.sum_add_hom` applied with `add_subgroup.subtype` is injective. -/
lemma independent_iff_dfinsupp_sum_add_hom_injective (p : ι → add_subgroup N) :
independent p ↔ function.injective (sum_add_hom (λ i, (p i).subtype)) :=
⟨independent.dfinsupp_sum_add_hom_injective, independent_of_dfinsupp_sum_add_hom_injective' p⟩
omit dec_ι
/-- If a family of submodules is `independent`, then a choice of nonzero vector from each submodule
forms a linearly independent family.
See also `complete_lattice.independent.linear_independent'`. -/
lemma independent.linear_independent [no_zero_smul_divisors R N] (p : ι → submodule R N)
(hp : independent p) {v : ι → N} (hv : ∀ i, v i ∈ p i) (hv' : ∀ i, v i ≠ 0) :
linear_independent R v :=
begin
classical,
rw linear_independent_iff,
intros l hl,
let a := dfinsupp.map_range.linear_map
(λ i, linear_map.to_span_singleton R (p i) (⟨v i, hv i⟩)) l.to_dfinsupp,
have ha : a = 0,
{ apply hp.dfinsupp_lsum_injective,
rwa ←lsum_comp_map_range_to_span_singleton _ hv at hl },
ext i,
apply smul_left_injective R (hv' i),
have : l i • v i = a i := rfl,
simp [this, ha],
end
lemma independent_iff_linear_independent_of_ne_zero [no_zero_smul_divisors R N] {v : ι → N}
(h_ne_zero : ∀ i, v i ≠ 0) :
independent (λ i, R ∙ v i) ↔ linear_independent R v :=
⟨λ hv, hv.linear_independent _ (λ i, submodule.mem_span_singleton_self $ v i) h_ne_zero,
λ hv, hv.independent_span_singleton⟩
end ring
end complete_lattice
|
36928ab84305d4594f6b9fd7ef3c237fc601a666 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/convex/basic.lean | d5e0430540d9bb02aad32400597bcdf73e0a2b6d | [
"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 | 41,288 | lean | /-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies
-/
import algebra.order.invertible
import algebra.order.module
import linear_algebra.affine_space.midpoint
import linear_algebra.affine_space.affine_subspace
/-!
# Convex sets and functions in vector spaces
In a 𝕜-vector space, we define the following objects and properties.
* `segment 𝕜 x y`: Closed segment joining `x` and `y`.
* `open_segment 𝕜 x y`: Open segment joining `x` and `y`.
* `convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`.
* `std_simplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `fintype ι`). It is the
intersection of the positive quadrant with the hyperplane `s.sum = 1`.
We also provide various equivalent versions of the definitions above, prove that some specific sets
are convex.
## Notations
We provide the following notation:
* `[x -[𝕜] y] = segment 𝕜 x y` in locale `convex`
## TODO
Generalize all this file to affine spaces.
Should we rename `segment` and `open_segment` to `convex.Icc` and `convex.Ioo`? Should we also
define `clopen_segment`/`convex.Ico`/`convex.Ioc`?
-/
variables {𝕜 E F β : Type*}
open linear_map set
open_locale big_operators classical pointwise
/-! ### Segment -/
section ordered_semiring
variables [ordered_semiring 𝕜] [add_comm_monoid E]
section has_scalar
variables (𝕜) [has_scalar 𝕜 E]
/-- Segments in a vector space. -/
def segment (x y : E) : set E :=
{z : E | ∃ (a b : 𝕜) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), a • x + b • y = z}
/-- Open segment in a vector space. Note that `open_segment 𝕜 x x = {x}` instead of being `∅` when
the base semiring has some element between `0` and `1`. -/
def open_segment (x y : E) : set E :=
{z : E | ∃ (a b : 𝕜) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1), a • x + b • y = z}
localized "notation `[` x ` -[` 𝕜 `] ` y `]` := segment 𝕜 x y" in convex
lemma segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
lemma open_segment_symm (x y : E) :
open_segment 𝕜 x y = open_segment 𝕜 y x :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
lemma open_segment_subset_segment (x y : E) :
open_segment 𝕜 x y ⊆ [x -[𝕜] y] :=
λ z ⟨a, b, ha, hb, hab, hz⟩, ⟨a, b, ha.le, hb.le, hab, hz⟩
lemma segment_subset_iff {x y : E} {s : set E} :
[x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s :=
⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩,
λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩
lemma open_segment_subset_iff {x y : E} {s : set E} :
open_segment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s :=
⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩,
λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩
end has_scalar
open_locale convex
section mul_action_with_zero
variables (𝕜) [mul_action_with_zero 𝕜 E]
lemma left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] :=
⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩
lemma right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] :=
segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x
end mul_action_with_zero
section module
variables (𝕜) [module 𝕜 E]
lemma segment_same (x : E) : [x -[𝕜] x] = {x} :=
set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩,
by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
λ h, mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩
lemma mem_open_segment_of_ne_left_right {x y z : E} (hx : x ≠ z) (hy : y ≠ z)
(hz : z ∈ [x -[𝕜] y]) :
z ∈ open_segment 𝕜 x y :=
begin
obtain ⟨a, b, ha, hb, hab, hz⟩ := hz,
by_cases ha' : a = 0,
{ rw [ha', zero_add] at hab,
rw [ha', hab, zero_smul, one_smul, zero_add] at hz,
exact (hy hz).elim },
by_cases hb' : b = 0,
{ rw [hb', add_zero] at hab,
rw [hb', hab, zero_smul, one_smul, add_zero] at hz,
exact (hx hz).elim },
exact ⟨a, b, ha.lt_of_ne (ne.symm ha'), hb.lt_of_ne (ne.symm hb'), hab, hz⟩,
end
variables {𝕜}
lemma open_segment_subset_iff_segment_subset {x y : E} {s : set E} (hx : x ∈ s) (hy : y ∈ s) :
open_segment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s :=
begin
refine ⟨λ h z hz, _, (open_segment_subset_segment 𝕜 x y).trans⟩,
obtain rfl | hxz := eq_or_ne x z,
{ exact hx },
obtain rfl | hyz := eq_or_ne y z,
{ exact hy },
exact h (mem_open_segment_of_ne_left_right 𝕜 hxz hyz hz),
end
lemma convex.combo_self {a b : 𝕜} (h : a + b = 1) (x : E) : a • x + b • x = x :=
by rw [←add_smul, h, one_smul]
end module
end ordered_semiring
open_locale convex
section ordered_ring
variables [ordered_ring 𝕜]
section add_comm_group
variables (𝕜) [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
section densely_ordered
variables [nontrivial 𝕜] [densely_ordered 𝕜]
@[simp] lemma open_segment_same (x : E) :
open_segment 𝕜 x x = {x} :=
set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩,
by simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
λ (h : z = x), begin
obtain ⟨a, ha₀, ha₁⟩ := densely_ordered.dense (0 : 𝕜) 1 zero_lt_one,
refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel'_right _ _, _⟩,
rw [←add_smul, add_sub_cancel'_right, one_smul, h],
end⟩
end densely_ordered
lemma segment_eq_image (x y : E) : [x -[𝕜] y] = (λ θ : 𝕜, (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, hz⟩,
⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩,
λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1-θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
lemma open_segment_eq_image (x y : E) :
open_segment 𝕜 x y = (λ (θ : 𝕜), (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, hz⟩,
⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩,
λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
lemma segment_eq_image₂ (x y : E) :
[x -[𝕜] y] = (λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1} :=
by simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma open_segment_eq_image₂ (x y : E) :
open_segment 𝕜 x y =
(λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1} :=
by simp only [open_segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma segment_eq_image' (x y : E) :
[x -[𝕜] y] = (λ (θ : 𝕜), x + θ • (y - x)) '' Icc (0 : 𝕜) 1 :=
by { convert segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma open_segment_eq_image' (x y : E) :
open_segment 𝕜 x y = (λ (θ : 𝕜), x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 :=
by { convert open_segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma segment_eq_image_line_map (x y : E) :
[x -[𝕜] y] = affine_map.line_map x y '' Icc (0 : 𝕜) 1 :=
by { convert segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma open_segment_eq_image_line_map (x y : E) :
open_segment 𝕜 x y = affine_map.line_map x y '' Ioo (0 : 𝕜) 1 :=
by { convert open_segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma segment_image (f : E →ₗ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] :=
set.ext (λ x, by simp_rw [segment_eq_image, mem_image, exists_exists_and_eq_and, map_add, map_smul])
@[simp] lemma open_segment_image (f : E →ₗ[𝕜] F) (a b : E) :
f '' open_segment 𝕜 a b = open_segment 𝕜 (f a) (f b) :=
set.ext (λ x, by simp_rw [open_segment_eq_image, mem_image, exists_exists_and_eq_and, map_add,
map_smul])
lemma mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] :=
begin
rw [segment_eq_image', segment_eq_image'],
refine exists_congr (λ θ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
@[simp] lemma mem_open_segment_translate (a : E) {x b c : E} :
a + x ∈ open_segment 𝕜 (a + b) (a + c) ↔ x ∈ open_segment 𝕜 b c :=
begin
rw [open_segment_eq_image', open_segment_eq_image'],
refine exists_congr (λ θ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
lemma segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] :=
set.ext $ λ x, mem_segment_translate 𝕜 a
lemma open_segment_translate_preimage (a b c : E) :
(λ x, a + x) ⁻¹' open_segment 𝕜 (a + b) (a + c) = open_segment 𝕜 b c :=
set.ext $ λ x, mem_open_segment_translate 𝕜 a
lemma segment_translate_image (a b c : E) : (λ x, a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] :=
segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a
lemma open_segment_translate_image (a b c : E) :
(λ x, a + x) '' open_segment 𝕜 b c = open_segment 𝕜 (a + b) (a + c) :=
open_segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a
end add_comm_group
end ordered_ring
section linear_ordered_ring
variables [linear_ordered_ring 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
lemma midpoint_mem_segment [invertible (2 : 𝕜)] (x y : E) :
midpoint 𝕜 x y ∈ [x -[𝕜] y] :=
begin
rw segment_eq_image_line_map,
exact ⟨⅟2, ⟨inv_of_nonneg.mpr zero_le_two, inv_of_le_one one_le_two⟩, rfl⟩,
end
lemma mem_segment_sub_add [invertible (2 : 𝕜)] (x y : E) :
x ∈ [x-y -[𝕜] x+y] :=
begin
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _,
rw midpoint_sub_add
end
lemma mem_segment_add_sub [invertible (2 : 𝕜)] (x y : E) :
x ∈ [x+y -[𝕜] x-y] :=
begin
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _,
rw midpoint_add_sub
end
end add_comm_group
end linear_ordered_ring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
lemma mem_segment_iff_div {x y z : E} : x ∈ [y -[𝕜] z] ↔
∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
use [a, b, ha, hb],
simp * },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
refine ⟨a / (a + b), b / (a + b), div_nonneg ha hab.le, div_nonneg hb hab.le, _, rfl⟩,
rw [← add_div, div_self hab.ne'] }
end
lemma mem_open_segment_iff_div {x y z : E} : x ∈ open_segment 𝕜 y z ↔
∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
use [a, b, ha, hb],
rw [hab, div_one, div_one] },
{ rintro ⟨a, b, ha, hb, rfl⟩,
have hab : 0 < a + b, from add_pos ha hb,
refine ⟨a / (a + b), b / (a + b), div_pos ha hab, div_pos hb hab, _, rfl⟩,
rw [← add_div, div_self hab.ne'] }
end
@[simp] lemma left_mem_open_segment_iff [no_zero_smul_divisors 𝕜 E] {x y : E} :
x ∈ open_segment 𝕜 x y ↔ x = y :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, hx⟩,
refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 _),
rw [hx, ←add_smul, hab, one_smul] },
{ rintro rfl,
rw open_segment_same,
exact mem_singleton _ }
end
@[simp] lemma right_mem_open_segment_iff {x y : E} :
y ∈ open_segment 𝕜 x y ↔ x = y :=
by rw [open_segment_symm, left_mem_open_segment_iff, eq_comm]
end add_comm_group
end linear_ordered_field
/-!
#### Segments in an ordered space
Relates `segment`, `open_segment` and `set.Icc`, `set.Ico`, `set.Ioc`, `set.Ioo`
-/
section ordered_semiring
variables [ordered_semiring 𝕜]
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E]
lemma segment_subset_Icc {x y : E} (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y :=
begin
rintro z ⟨a, b, ha, hb, hab, rfl⟩,
split,
calc
x = a • x + b • x :(convex.combo_self hab _).symm
... ≤ a • x + b • y : add_le_add_left (smul_le_smul_of_nonneg h hb) _,
calc
a • x + b • y
≤ a • y + b • y : add_le_add_right (smul_le_smul_of_nonneg h ha) _
... = y : convex.combo_self hab _,
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E]
lemma open_segment_subset_Ioo {x y : E} (h : x < y) : open_segment 𝕜 x y ⊆ Ioo x y :=
begin
rintro z ⟨a, b, ha, hb, hab, rfl⟩,
split,
calc
x = a • x + b • x : (convex.combo_self hab _).symm
... < a • x + b • y : add_lt_add_left (smul_lt_smul_of_pos h hb) _,
calc
a • x + b • y
< a • y + b • y : add_lt_add_right (smul_lt_smul_of_pos h ha) _
... = y : convex.combo_self hab _,
end
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E] {𝕜}
lemma segment_subset_interval (x y : E) : [x -[𝕜] y] ⊆ interval x y :=
begin
cases le_total x y,
{ rw interval_of_le h,
exact segment_subset_Icc h },
{ rw [interval_of_ge h, segment_symm],
exact segment_subset_Icc h }
end
lemma convex.min_le_combo (x y : E) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
min x y ≤ a • x + b • y :=
(segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).1
lemma convex.combo_le_max (x y : E) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
a • x + b • y ≤ max x y :=
(segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).2
end linear_ordered_add_comm_monoid
end ordered_semiring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
lemma Icc_subset_segment {x y : 𝕜} : Icc x y ⊆ [x -[𝕜] y] :=
begin
rintro z ⟨hxz, hyz⟩,
obtain rfl | h := (hxz.trans hyz).eq_or_lt,
{ rw segment_same,
exact hyz.antisymm hxz },
rw ←sub_nonneg at hxz hyz,
rw ←sub_pos at h,
refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, _, _⟩,
{ rw [←add_div, sub_add_sub_cancel, div_self h.ne'] },
{ rw [smul_eq_mul, smul_eq_mul, ←mul_div_right_comm, ←mul_div_right_comm, ←add_div,
div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] }
end
@[simp] lemma segment_eq_Icc {x y : 𝕜} (h : x ≤ y) : [x -[𝕜] y] = Icc x y :=
(segment_subset_Icc h).antisymm Icc_subset_segment
lemma Ioo_subset_open_segment {x y : 𝕜} : Ioo x y ⊆ open_segment 𝕜 x y :=
λ z hz, mem_open_segment_of_ne_left_right _ hz.1.ne hz.2.ne'
(Icc_subset_segment $ Ioo_subset_Icc_self hz)
@[simp] lemma open_segment_eq_Ioo {x y : 𝕜} (h : x < y) : open_segment 𝕜 x y = Ioo x y :=
(open_segment_subset_Ioo h).antisymm Ioo_subset_open_segment
lemma segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) :=
begin
cases le_total x y,
{ rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] },
{ rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] }
end
lemma open_segment_eq_Ioo' {x y : 𝕜} (hxy : x ≠ y) :
open_segment 𝕜 x y = Ioo (min x y) (max x y) :=
begin
cases hxy.lt_or_lt,
{ rw [open_segment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] },
{ rw [open_segment_symm, open_segment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] }
end
lemma segment_eq_interval (x y : 𝕜) : [x -[𝕜] y] = interval x y :=
segment_eq_Icc' _ _
/-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/
lemma convex.mem_Icc {x y : 𝕜} (h : x ≤ y) {z : 𝕜} :
z ∈ Icc x y ↔ ∃ (a b : 𝕜), 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
rw ←segment_eq_Icc h,
simp_rw [←exists_prop],
refl,
end
/-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints.
-/
lemma convex.mem_Ioo {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ioo x y ↔ ∃ (a b : 𝕜), 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
rw ←open_segment_eq_Ioo h,
simp_rw [←exists_prop],
refl,
end
/-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ioc {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ioc x y ↔ ∃ (a b : 𝕜), 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz),
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rw [hab, one_mul, zero_mul, add_zero] at hz,
exact (hz.1.ne rfl).elim },
{ exact ⟨a, b, ha, hb', hab, rfl⟩ } },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] },
{ exact Ioo_subset_Ioc_self ((convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩) } }
end
/-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ico {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ico x y ↔ ∃ (a b : 𝕜), 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz),
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rw [hab, one_mul, zero_mul, zero_add] at hz,
exact (hz.2.ne rfl).elim },
{ exact ⟨a, b, ha', hb, hab, rfl⟩ } },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] },
{ exact Ioo_subset_Ico_self ((convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩) } }
end
end linear_ordered_field
/-! ### Convexity of sets -/
section ordered_semiring
variables [ordered_semiring 𝕜]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F]
section has_scalar
variables (𝕜) [has_scalar 𝕜 E] [has_scalar 𝕜 F] (s : set E)
/-- Convexity of sets. -/
def convex : Prop :=
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • x + b • y ∈ s
variables {𝕜 s}
lemma convex_iff_segment_subset :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → [x -[𝕜] y] ⊆ s :=
forall₄_congr $ λ x y hx hy, (segment_subset_iff _).symm
lemma convex.segment_subset (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
[x -[𝕜] y] ⊆ s :=
convex_iff_segment_subset.1 h hx hy
lemma convex.open_segment_subset (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
open_segment 𝕜 x y ⊆ s :=
(open_segment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy)
/-- Alternative definition of set convexity, in terms of pointwise set operations. -/
lemma convex_iff_pointwise_add_subset :
convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s :=
iff.intro
begin
rintro hA a b ha hb hab w ⟨au, bv, ⟨u, hu, rfl⟩, ⟨v, hv, rfl⟩, rfl⟩,
exact hA hu hv ha hb hab
end
(λ h x y hx hy a b ha hb hab,
(h ha hb hab) (set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩))
alias convex_iff_pointwise_add_subset ↔ convex.set_combo_subset _
lemma convex_empty : convex 𝕜 (∅ : set E) :=
λ x y, false.elim
lemma convex_univ : convex 𝕜 (set.univ : set E) := λ _ _ _ _ _ _ _ _ _, trivial
lemma convex.inter {t : set E} (hs : convex 𝕜 s) (ht : convex 𝕜 t) : convex 𝕜 (s ∩ t) :=
λ x y (hx : x ∈ s ∩ t) (hy : y ∈ s ∩ t) a b (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
⟨hs hx.left hy.left ha hb hab, ht hx.right hy.right ha hb hab⟩
lemma convex_sInter {S : set (set E)} (h : ∀ s ∈ S, convex 𝕜 s) : convex 𝕜 (⋂₀ S) :=
assume x y hx hy a b ha hb hab s hs,
h s hs (hx s hs) (hy s hs) ha hb hab
lemma convex_Inter {ι : Sort*} {s : ι → set E} (h : ∀ i : ι, convex 𝕜 (s i)) :
convex 𝕜 (⋂ i, s i) :=
(sInter_range s) ▸ convex_sInter $ forall_range_iff.2 h
lemma convex.prod {s : set E} {t : set F} (hs : convex 𝕜 s) (ht : convex 𝕜 t) :
convex 𝕜 (s ×ˢ t) :=
begin
intros x y hx hy a b ha hb hab,
apply mem_prod.2,
exact ⟨hs (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,
ht (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab⟩
end
lemma convex_pi {ι : Type*} {E : ι → Type*} [Π i, add_comm_monoid (E i)]
[Π i, has_scalar 𝕜 (E i)] {s : set ι} {t : Π i, set (E i)} (ht : ∀ i, convex 𝕜 (t i)) :
convex 𝕜 (s.pi t) :=
λ x y hx hy a b ha hb hab i hi, ht i (hx i hi) (hy i hi) ha hb hab
lemma directed.convex_Union {ι : Sort*} {s : ι → set E} (hdir : directed (⊆) s)
(hc : ∀ ⦃i : ι⦄, convex 𝕜 (s i)) :
convex 𝕜 (⋃ i, s i) :=
begin
rintro x y hx hy a b ha hb hab,
rw mem_Union at ⊢ hx hy,
obtain ⟨i, hx⟩ := hx,
obtain ⟨j, hy⟩ := hy,
obtain ⟨k, hik, hjk⟩ := hdir i j,
exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩,
end
lemma directed_on.convex_sUnion {c : set (set E)} (hdir : directed_on (⊆) c)
(hc : ∀ ⦃A : set E⦄, A ∈ c → convex 𝕜 A) :
convex 𝕜 (⋃₀c) :=
begin
rw sUnion_eq_Union,
exact (directed_on_iff_directed.1 hdir).convex_Union (λ A, hc A.2),
end
end has_scalar
section module
variables [module 𝕜 E] [module 𝕜 F] {s : set E}
lemma convex_iff_open_segment_subset :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → open_segment 𝕜 x y ⊆ s :=
convex_iff_segment_subset.trans $ forall₄_congr $ λ x y hx hy,
(open_segment_subset_iff_segment_subset hx hy).symm
lemma convex_iff_forall_pos :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1
→ a • x + b • y ∈ s :=
convex_iff_open_segment_subset.trans $ forall₄_congr $ λ x y hx hy,
open_segment_subset_iff 𝕜
lemma convex_iff_pairwise_pos :
convex 𝕜 s ↔ s.pairwise (λ x y, ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s) :=
begin
refine convex_iff_forall_pos.trans ⟨λ h x hx y hy _, h hx hy, _⟩,
intros h x y hx hy a b ha hb hab,
obtain rfl | hxy := eq_or_ne x y,
{ rwa convex.combo_self hab },
{ exact h hx hy hxy ha hb hab },
end
protected lemma set.subsingleton.convex {s : set E} (h : s.subsingleton) : convex 𝕜 s :=
convex_iff_pairwise_pos.mpr (h.pairwise _)
lemma convex_singleton (c : E) : convex 𝕜 ({c} : set E) :=
subsingleton_singleton.convex
lemma convex.linear_image (hs : convex 𝕜 s) (f : E →ₗ[𝕜] F) : convex 𝕜 (f '' s) :=
begin
intros x y hx hy a b ha hb hab,
obtain ⟨x', hx', rfl⟩ := mem_image_iff_bex.1 hx,
obtain ⟨y', hy', rfl⟩ := mem_image_iff_bex.1 hy,
exact ⟨a • x' + b • y', hs hx' hy' ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩,
end
lemma convex.is_linear_image (hs : convex 𝕜 s) {f : E → F} (hf : is_linear_map 𝕜 f) :
convex 𝕜 (f '' s) :=
hs.linear_image $ hf.mk' f
lemma convex.linear_preimage {s : set F} (hs : convex 𝕜 s) (f : E →ₗ[𝕜] F) :
convex 𝕜 (f ⁻¹' s) :=
begin
intros x y hx hy a b ha hb hab,
rw [mem_preimage, f.map_add, f.map_smul, f.map_smul],
exact hs hx hy ha hb hab,
end
lemma convex.is_linear_preimage {s : set F} (hs : convex 𝕜 s) {f : E → F} (hf : is_linear_map 𝕜 f) :
convex 𝕜 (f ⁻¹' s) :=
hs.linear_preimage $ hf.mk' f
lemma convex.add {t : set E} (hs : convex 𝕜 s) (ht : convex 𝕜 t) : convex 𝕜 (s + t) :=
by { rw ← add_image_prod, exact (hs.prod ht).is_linear_image is_linear_map.is_linear_map_add }
lemma convex.translate (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, z + x) '' s) :=
begin
intros x y hx hy a b ha hb hab,
obtain ⟨x', hx', rfl⟩ := mem_image_iff_bex.1 hx,
obtain ⟨y', hy', rfl⟩ := mem_image_iff_bex.1 hy,
refine ⟨a • x' + b • y', hs hx' hy' ha hb hab, _⟩,
rw [smul_add, smul_add, add_add_add_comm, ←add_smul, hab, one_smul],
end
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_right (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, z + x) ⁻¹' s) :=
begin
intros x y hx hy a b ha hb hab,
have h := hs hx hy ha hb hab,
rwa [smul_add, smul_add, add_add_add_comm, ←add_smul, hab, one_smul] at h,
end
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_left (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, x + z) ⁻¹' s) :=
by simpa only [add_comm] using hs.translate_preimage_right z
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_Iic (r : β) : convex 𝕜 (Iic r) :=
λ x y hx hy a b ha hb hab,
calc
a • x + b • y
≤ a • r + b • r
: add_le_add (smul_le_smul_of_nonneg hx ha) (smul_le_smul_of_nonneg hy hb)
... = r : convex.combo_self hab _
lemma convex_Ici (r : β) : convex 𝕜 (Ici r) :=
@convex_Iic 𝕜 (order_dual β) _ _ _ _ r
lemma convex_Icc (r s : β) : convex 𝕜 (Icc r s) :=
Ici_inter_Iic.subst ((convex_Ici r).inter $ convex_Iic s)
lemma convex_halfspace_le {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w ≤ r} :=
(convex_Iic r).is_linear_preimage h
lemma convex_halfspace_ge {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | r ≤ f w} :=
(convex_Ici r).is_linear_preimage h
lemma convex_hyperplane {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w = r} :=
begin
simp_rw le_antisymm_iff,
exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r),
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_Iio (r : β) : convex 𝕜 (Iio r) :=
begin
intros x y hx hy a b ha hb hab,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [zero_smul, zero_add, hab, one_smul] },
rw mem_Iio at hx hy,
calc
a • x + b • y
< a • r + b • r
: add_lt_add_of_lt_of_le (smul_lt_smul_of_pos hx ha') (smul_le_smul_of_nonneg hy.le hb)
... = r : convex.combo_self hab _
end
lemma convex_Ioi (r : β) : convex 𝕜 (Ioi r) :=
@convex_Iio 𝕜 (order_dual β) _ _ _ _ r
lemma convex_Ioo (r s : β) : convex 𝕜 (Ioo r s) :=
Ioi_inter_Iio.subst ((convex_Ioi r).inter $ convex_Iio s)
lemma convex_Ico (r s : β) : convex 𝕜 (Ico r s) :=
Ici_inter_Iio.subst ((convex_Ici r).inter $ convex_Iio s)
lemma convex_Ioc (r s : β) : convex 𝕜 (Ioc r s) :=
Ioi_inter_Iic.subst ((convex_Ioi r).inter $ convex_Iic s)
lemma convex_halfspace_lt {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w < r} :=
(convex_Iio r).is_linear_preimage h
lemma convex_halfspace_gt {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | r < f w} :=
(convex_Ioi r).is_linear_preimage h
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_interval (r s : β) : convex 𝕜 (interval r s) :=
convex_Icc _ _
end linear_ordered_add_comm_monoid
end module
end add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [ordered_add_comm_monoid β] [module 𝕜 E]
[ordered_smul 𝕜 E] {s : set E} {f : E → β}
lemma monotone_on.convex_le (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x ≤ r} :=
λ x y hx hy a b ha hb hab, ⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans
(max_rec' _ hx.2 hy.2)⟩
lemma monotone_on.convex_lt (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x < r} :=
λ x y hx hy a b ha hb hab, ⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans_lt
(max_rec' _ hx.2 hy.2)⟩
lemma monotone_on.convex_ge (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r ≤ f x} :=
@monotone_on.convex_le 𝕜 (order_dual E) (order_dual β) _ _ _ _ _ _ _ hf.dual hs r
lemma monotone_on.convex_gt (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r < f x} :=
@monotone_on.convex_lt 𝕜 (order_dual E) (order_dual β) _ _ _ _ _ _ _ hf.dual hs r
lemma antitone_on.convex_le (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x ≤ r} :=
@monotone_on.convex_ge 𝕜 E (order_dual β) _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_lt (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x < r} :=
@monotone_on.convex_gt 𝕜 E (order_dual β) _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_ge (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r ≤ f x} :=
@monotone_on.convex_le 𝕜 E (order_dual β) _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_gt (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r < f x} :=
@monotone_on.convex_lt 𝕜 E (order_dual β) _ _ _ _ _ _ _ hf hs r
lemma monotone.convex_le (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_lt (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_ge (hf : monotone f ) (r : β) :
convex 𝕜 {x | r ≤ f x} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_ge convex_univ r)
lemma monotone.convex_gt (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma antitone.convex_le (hf : antitone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_le convex_univ r)
lemma antitone.convex_lt (hf : antitone f) (r : β) :
convex 𝕜 {x | f x < r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_lt convex_univ r)
lemma antitone.convex_ge (hf : antitone f) (r : β) :
convex 𝕜 {x | r ≤ f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_ge convex_univ r)
lemma antitone.convex_gt (hf : antitone f) (r : β) :
convex 𝕜 {x | r < f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_gt convex_univ r)
end linear_ordered_add_comm_monoid
section add_comm_group
variables [add_comm_group E] [module 𝕜 E] {s t : set E}
lemma convex.combo_eq_vadd {a b : 𝕜} {x y : E} (h : a + b = 1) :
a • x + b • y = b • (y - x) + x :=
calc
a • x + b • y = (b • y - b • x) + (a • x + b • x) : by abel
... = b • (y - x) + x : by rw [smul_sub, convex.combo_self h]
lemma convex.sub {s : set (E × E)} (hs : convex 𝕜 s) : convex 𝕜 ((λ x : E × E, x.1 - x.2) '' s) :=
hs.is_linear_image is_linear_map.is_linear_map_sub
lemma convex_segment (x y : E) : convex 𝕜 [x -[𝕜] y] :=
begin
rintro p q ⟨ap, bp, hap, hbp, habp, rfl⟩ ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab,
refine ⟨a * ap + b * aq, a * bp + b * bq,
add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), _, _⟩,
{ rw [add_add_add_comm, ←mul_add, ←mul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
lemma convex_open_segment (a b : E) : convex 𝕜 (open_segment 𝕜 a b) :=
begin
rw convex_iff_open_segment_subset,
rintro p q ⟨ap, bp, hap, hbp, habp, rfl⟩ ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩,
refine ⟨a * ap + b * aq, a * bp + b * bq,
add_pos (mul_pos ha hap) (mul_pos hb haq),
add_pos (mul_pos ha hbp) (mul_pos hb hbq), _, _⟩,
{ rw [add_add_add_comm, ←mul_add, ←mul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
end add_comm_group
end ordered_semiring
section ordered_comm_semiring
variables [ordered_comm_semiring 𝕜]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F] [module 𝕜 E] [module 𝕜 F] {s : set E}
lemma convex.smul (hs : convex 𝕜 s) (c : 𝕜) : convex 𝕜 (c • s) :=
hs.linear_image (linear_map.lsmul _ _ c)
lemma convex.smul_preimage (hs : convex 𝕜 s) (c : 𝕜) : convex 𝕜 ((λ z, c • z) ⁻¹' s) :=
hs.linear_preimage (linear_map.lsmul _ _ c)
lemma convex.affinity (hs : convex 𝕜 s) (z : E) (c : 𝕜) : convex 𝕜 ((λ x, z + c • x) '' s) :=
begin
have h := (hs.smul c).translate z,
rwa [←image_smul, image_image] at h,
end
end add_comm_monoid
end ordered_comm_semiring
section ordered_ring
variables [ordered_ring 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] {s : set E}
lemma convex.add_smul_mem (hs : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s :=
begin
have h : x + t • y = (1 - t) • x + t • (x + y),
{ rw [smul_add, ←add_assoc, ←add_smul, sub_add_cancel, one_smul] },
rw h,
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _),
end
lemma convex.smul_mem_of_zero_mem (hs : convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s :=
by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht
lemma convex.add_smul_sub_mem (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s :=
begin
apply h.segment_subset hx hy,
rw segment_eq_image',
exact mem_image_of_mem _ ht,
end
/-- Affine subspaces are convex. -/
lemma affine_subspace.convex (Q : affine_subspace 𝕜 E) : convex 𝕜 (Q : set E) :=
begin
intros x y hx hy a b ha hb hab,
rw [eq_sub_of_add_eq hab, ← affine_map.line_map_apply_module],
exact affine_map.line_map_mem b hx hy,
end
/--
Applying an affine map to an affine combination of two points yields
an affine combination of the images.
-/
lemma convex.combo_affine_apply {a b : 𝕜} {x y : E} {f : E →ᵃ[𝕜] F} (h : a + b = 1) :
f (a • x + b • y) = a • f x + b • f y :=
begin
simp only [convex.combo_eq_vadd h, ← vsub_eq_sub],
exact f.apply_line_map _ _ _,
end
/-- The preimage of a convex set under an affine map is convex. -/
lemma convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : set F} (hs : convex 𝕜 s) :
convex 𝕜 (f ⁻¹' s) :=
begin
intros x y xs ys a b ha hb hab,
rw [mem_preimage, convex.combo_affine_apply hab],
exact hs xs ys ha hb hab,
end
/-- The image of a convex set under an affine map is convex. -/
lemma convex.affine_image (f : E →ᵃ[𝕜] F) {s : set E} (hs : convex 𝕜 s) :
convex 𝕜 (f '' s) :=
begin
rintro x y ⟨x', ⟨hx', hx'f⟩⟩ ⟨y', ⟨hy', hy'f⟩⟩ a b ha hb hab,
refine ⟨a • x' + b • y', ⟨hs hx' hy' ha hb hab, _⟩⟩,
rw [convex.combo_affine_apply hab, hx'f, hy'f]
end
lemma convex.neg (hs : convex 𝕜 s) : convex 𝕜 ((λ z, -z) '' s) :=
hs.is_linear_image is_linear_map.is_linear_map_neg
lemma convex.neg_preimage (hs : convex 𝕜 s) : convex 𝕜 ((λ z, -z) ⁻¹' s) :=
hs.is_linear_preimage is_linear_map.is_linear_map_neg
end add_comm_group
end ordered_ring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] {s : set E}
/-- Alternative definition of set convexity, using division. -/
lemma convex_iff_div :
convex 𝕜 s ↔ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄,
0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s :=
begin
simp only [convex_iff_segment_subset, subset_def, mem_segment_iff_div],
refine forall₄_congr (λ x y hx hy, ⟨λ H a b ha hb hab, H _ ⟨a, b, ha, hb, hab, rfl⟩, _⟩),
rintro H _ ⟨a, b, ha, hb, hab, rfl⟩,
exact H ha hb hab
end
lemma convex.mem_smul_of_zero_mem (h : convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s)
(hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) :
x ∈ t • s :=
begin
rw mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne',
exact h.smul_mem_of_zero_mem zero_mem hx ⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one ht⟩,
end
lemma convex.add_smul (h_conv : convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) :
(p + q) • s = p • s + q • s :=
begin
obtain rfl | hs := s.eq_empty_or_nonempty,
{ simp_rw [smul_set_empty, add_empty] },
obtain rfl | hp' := hp.eq_or_lt,
{ rw [zero_add, zero_smul_set hs, zero_add] },
obtain rfl | hq' := hq.eq_or_lt,
{ rw [add_zero, zero_smul_set hs, add_zero] },
ext,
split,
{ rintro ⟨v, hv, rfl⟩,
exact ⟨p • v, q • v, smul_mem_smul_set hv, smul_mem_smul_set hv, (add_smul _ _ _).symm⟩ },
{ rintro ⟨v₁, v₂, ⟨v₁₁, h₁₂, rfl⟩, ⟨v₂₁, h₂₂, rfl⟩, rfl⟩,
have hpq := add_pos hp' hq',
exact mem_smul_set.2 ⟨_, h_conv h₁₂ h₂₂ (div_pos hp' hpq).le (div_pos hq' hpq).le
(by rw [←div_self hpq.ne', add_div] : p / (p + q) + q / (p + q) = 1),
by simp only [← mul_smul, smul_add, mul_div_cancel' _ hpq.ne']⟩ }
end
end add_comm_group
end linear_ordered_field
/-!
#### Convex sets in an ordered space
Relates `convex` and `ord_connected`.
-/
section
lemma set.ord_connected.convex_of_chain [ordered_semiring 𝕜] [ordered_add_comm_monoid E]
[module 𝕜 E] [ordered_smul 𝕜 E] {s : set E} (hs : s.ord_connected) (h : zorn.chain (≤) s) :
convex 𝕜 s :=
begin
refine convex_iff_segment_subset.mpr (λ x y hx hy, _),
obtain hxy | hyx := h.total_of_refl hx hy,
{ exact (segment_subset_Icc hxy).trans (hs.out hx hy) },
{ rw segment_symm,
exact (segment_subset_Icc hyx).trans (hs.out hy hx) }
end
lemma set.ord_connected.convex [ordered_semiring 𝕜] [linear_ordered_add_comm_monoid E] [module 𝕜 E]
[ordered_smul 𝕜 E] {s : set E} (hs : s.ord_connected) :
convex 𝕜 s :=
hs.convex_of_chain (zorn.chain_of_trichotomous s)
lemma convex_iff_ord_connected [linear_ordered_field 𝕜] {s : set 𝕜} :
convex 𝕜 s ↔ s.ord_connected :=
begin
simp_rw [convex_iff_segment_subset, segment_eq_interval, ord_connected_iff_interval_subset],
exact forall_congr (λ x, forall_swap)
end
alias convex_iff_ord_connected ↔ convex.ord_connected _
end
/-! #### Convexity of submodules/subspaces -/
section submodule
open submodule
lemma submodule.convex [ordered_semiring 𝕜] [add_comm_monoid E] [module 𝕜 E] (K : submodule 𝕜 E) :
convex 𝕜 (↑K : set E) :=
by { repeat {intro}, refine add_mem _ (smul_mem _ _ _) (smul_mem _ _ _); assumption }
lemma subspace.convex [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] (K : subspace 𝕜 E) :
convex 𝕜 (↑K : set E) :=
K.convex
end submodule
/-! ### Simplex -/
section simplex
variables (𝕜) (ι : Type*) [ordered_semiring 𝕜] [fintype ι]
/-- The standard simplex in the space of functions `ι → 𝕜` is the set of vectors with non-negative
coordinates with total sum `1`. This is the free object in the category of convex spaces. -/
def std_simplex : set (ι → 𝕜) :=
{f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1}
lemma std_simplex_eq_inter :
std_simplex 𝕜 ι = (⋂ x, {f | 0 ≤ f x}) ∩ {f | ∑ x, f x = 1} :=
by { ext f, simp only [std_simplex, set.mem_inter_eq, set.mem_Inter, set.mem_set_of_eq] }
lemma convex_std_simplex : convex 𝕜 (std_simplex 𝕜 ι) :=
begin
refine λ f g hf hg a b ha hb hab, ⟨λ x, _, _⟩,
{ apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] },
{ erw [finset.sum_add_distrib, ← finset.smul_sum, ← finset.smul_sum, hf.2, hg.2,
smul_eq_mul, smul_eq_mul, mul_one, mul_one],
exact hab }
end
variable {ι}
lemma ite_eq_mem_std_simplex (i : ι) : (λ j, ite (i = j) (1:𝕜) 0) ∈ std_simplex 𝕜 ι :=
⟨λ j, by simp only; split_ifs; norm_num, by rw [finset.sum_ite_eq, if_pos (finset.mem_univ _)]⟩
end simplex
|
d235117454eb8c5ecf197feb6023b43cb669dfe9 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/real/pi/leibniz.lean | 51c1e08eca698348482f0642ab021894500d8d15 | [
"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 | 7,736 | lean | /-
Copyright (c) 2020 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import analysis.special_functions.pow
import analysis.special_functions.trigonometric.arctan
/-! ### Leibniz's Series for Pi -/
namespace real
open filter set
open_locale classical big_operators topological_space real
local notation `|`x`|` := abs x
/-- This theorem establishes **Leibniz's series for `π`**: The alternating sum of the reciprocals
of the odd numbers is `π/4`. Note that this is a conditionally rather than absolutely convergent
series. The main tool that this proof uses is the Mean Value Theorem (specifically avoiding the
Fundamental Theorem of Calculus).
Intuitively, the theorem holds because Leibniz's series is the Taylor series of `arctan x`
centered about `0` and evaluated at the value `x = 1`. Therefore, much of this proof consists of
reasoning about a function
`f := arctan x - ∑ i in finset.range k, (-(1:ℝ))^i * x^(2*i+1) / (2*i+1)`,
the difference between `arctan` and the `k`-th partial sum of its Taylor series. Some ingenuity is
required due to the fact that the Taylor series is not absolutely convergent at `x = 1`.
This proof requires a bound on `f 1`, the key idea being that `f 1` can be split as the sum of
`f 1 - f u` and `f u`, where `u` is a sequence of values in [0,1], carefully chosen such that
each of these two terms can be controlled (in different ways).
We begin the proof by (1) introducing that sequence `u` and then proving that another sequence
constructed from `u` tends to `0` at `+∞`. After (2) converting the limit in our goal to an
inequality, we (3) introduce the auxiliary function `f` defined above. Next, we (4) compute the
derivative of `f`, denoted by `f'`, first generally and then on each of two subintervals of [0,1].
We then (5) prove a bound for `f'`, again both generally as well as on each of the two
subintervals. Finally, we (6) apply the Mean Value Theorem twice, obtaining bounds on `f 1 - f u`
and `f u - f 0` from the bounds on `f'` (note that `f 0 = 0`). -/
theorem tendsto_sum_pi_div_four :
tendsto (λ k, ∑ i in finset.range k, ((-(1:ℝ))^i / (2*i+1))) at_top (𝓝 (π/4)) :=
begin
rw [tendsto_iff_norm_tendsto_zero, ← tendsto_zero_iff_norm_tendsto_zero],
-- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence
-- constructed from `u` tends to `0` at `+∞`
let u := λ k : ℕ, (k:nnreal) ^ (-1 / (2 * (k:ℝ) + 1)),
have H : tendsto (λ k : ℕ, (1:ℝ) - (u k) + (u k) ^ (2 * (k:ℝ) + 1)) at_top (𝓝 0),
{ convert (((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add
tendsto_inv_at_top_zero).comp tendsto_coe_nat_at_top_at_top,
{ ext k,
simp only [nnreal.coe_nat_cast, function.comp_app, nnreal.coe_rpow],
rw [← rpow_mul (nat.cast_nonneg k) ((-1)/(2*(k:ℝ)+1)) (2*(k:ℝ)+1),
@div_mul_cancel _ _ _ (2*(k:ℝ)+1)
(by { norm_cast, simp only [nat.succ_ne_zero, not_false_iff] }), rpow_neg_one k,
sub_eq_add_neg] },
{ simp only [add_zero, add_right_neg] } },
-- (2) We convert the limit in our goal to an inequality
refine squeeze_zero_norm _ H,
intro k,
-- Since `k` is now fixed, we henceforth denote `u k` as `U`
let U := u k,
-- (3) We introduce an auxiliary function `f`
let b := λ (i:ℕ) x, (-(1:ℝ))^i * x^(2*i+1) / (2*i+1),
let f := λ x, arctan x - (∑ i in finset.range k, b i x),
suffices f_bound : |f 1 - f 0| ≤ (1:ℝ) - U + U ^ (2 * (k:ℝ) + 1),
{ rw ← norm_neg,
convert f_bound,
simp only [f], simp [b] },
-- We show that `U` is indeed in [0,1]
have hU1 : (U:ℝ) ≤ 1,
{ by_cases hk : k = 0,
{ simpa only [U, hk] using zero_rpow_le_one _ },
{ exact rpow_le_one_of_one_le_of_nonpos (by { norm_cast, exact nat.succ_le_iff.mpr
(nat.pos_of_ne_zero hk) }) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1:ℝ)) (2*k+1)
(neg_neg_iff_pos.mpr zero_lt_one) (by { norm_cast, exact nat.succ_pos' }))) } },
have hU2 := nnreal.coe_nonneg U,
-- (4) We compute the derivative of `f`, denoted by `f'`
let f' := λ x : ℝ, (-x^2) ^ k / (1 + x^2),
have has_deriv_at_f : ∀ x, has_deriv_at f (f' x) x,
{ intro x,
have has_deriv_at_b : ∀ i ∈ finset.range k, (has_deriv_at (b i) ((-x^2)^i) x),
{ intros i hi,
convert has_deriv_at.const_mul ((-1:ℝ)^i / (2*i+1)) (@has_deriv_at.pow _ _ _ _ _ (2*i+1)
(has_deriv_at_id x)),
{ ext y,
simp only [b, id.def],
ring },
{ simp only [nat.add_succ_sub_one, add_zero, mul_one, id.def, nat.cast_bit0, nat.cast_add,
nat.cast_one, nat.cast_mul],
rw [← mul_assoc, @div_mul_cancel _ _ _ (2*(i:ℝ)+1) (by { norm_cast, linarith }),
pow_mul x 2 i, ← mul_pow (-1) (x^2) i],
ring_nf } },
convert (has_deriv_at_arctan x).sub (has_deriv_at.sum has_deriv_at_b),
have g_sum :=
@geom_sum_eq _ _ (-x^2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).ne k,
simp only [geom_sum, f'] at g_sum ⊢,
rw [g_sum, ← neg_add' (x^2) 1, add_comm (x^2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq],
ring },
have hderiv1 : ∀ x ∈ Icc (U:ℝ) 1, has_deriv_within_at f (f' x) (Icc (U:ℝ) 1) x :=
λ x hx, (has_deriv_at_f x).has_deriv_within_at,
have hderiv2 : ∀ x ∈ Icc 0 (U:ℝ), has_deriv_within_at f (f' x) (Icc 0 (U:ℝ)) x :=
λ x hx, (has_deriv_at_f x).has_deriv_within_at,
-- (5) We prove a general bound for `f'` and then more precise bounds on each of two subintervals
have f'_bound : ∀ x ∈ Icc (-1:ℝ) 1, |f' x| ≤ |x|^(2*k),
{ intros x hx,
rw [abs_div, is_absolute_value.abv_pow abs (-x^2) k, abs_neg, is_absolute_value.abv_pow abs x 2,
tactic.ring_exp.pow_e_pf_exp rfl rfl],
refine div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _,
refine le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _,
rw abs_of_nonneg ((add_nonneg zero_le_one (sq_nonneg x)) : (0 : ℝ) ≤ _),
exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : ℝ) ≤ _) },
have hbound1 : ∀ x ∈ Ico (U:ℝ) 1, |f' x| ≤ 1,
{ rintros x ⟨hx_left, hx_right⟩,
have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2*k),
rw [one_pow (2*k), ← abs_of_nonneg (le_trans hU2 hx_left)] at hincr,
rw ← abs_of_nonneg (le_trans hU2 hx_left) at hx_right,
linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] },
have hbound2 : ∀ x ∈ Ico 0 (U:ℝ), |f' x| ≤ U ^ (2*k),
{ rintros x ⟨hx_left, hx_right⟩,
have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2*k),
rw ← abs_of_nonneg hx_left at hincr hx_right,
rw ← abs_of_nonneg hU2 at hU1 hx_right,
linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))] },
-- (6) We twice apply the Mean Value Theorem to obtain bounds on `f` from the bounds on `f'`
have mvt1 :=
norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1),
have mvt2 :=
norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2),
-- The following algebra is enough to complete the proof
calc |f 1 - f 0| = |(f 1 - f U) + (f U - f 0)| : by ring_nf
... ≤ 1 * (1-U) + U^(2*k) * (U - 0) : le_trans (abs_add (f 1 - f U) (f U - f 0))
(add_le_add mvt1 mvt2)
... = 1 - U + U^(2*k) * U : by ring
... = 1 - (u k) + (u k)^(2*(k:ℝ)+1) : by { rw [← pow_succ' (U:ℝ) (2*k)], norm_cast },
end
end real
|
fb25cf7f83a8c171176fc8c6885a4e531afc2717 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/order/semiconj_Sup.lean | 19467ddc999449f71deda4d17eeb218ac50ab756 | [
"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 | 6,001 | 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
-/
import order.conditionally_complete_lattice
import logic.function.conjugate
import order.ord_continuous
import data.equiv.mul_add
/-!
# Semiconjugate by `Sup`
In this file we prove two facts about semiconjugate (families of) functions.
First, if an order isomorphism `fa : α → α` is semiconjugate to an order embedding `fb : β → β` by
`g : α → β`, then `fb` is semiconjugate to `fa` by `y ↦ Sup {x | g x ≤ y}`, see
`semiconj.symm_adjoint`.
Second, consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`,
see `function.Sup_div_semiconj`. In the case of a conditionally complete lattice, a similar
statement holds true under an additional assumption that each set `{(f₁ g)⁻¹ (f₂ g x) | g : G}` is
bounded above, see `function.cSup_div_semiconj`.
The lemmas come from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie
bornee][ghys87:groupes], Proposition 2.1 and 5.4 respectively. In the paper they are formulated for
homeomorphisms of the circle, so in order to apply results from this file one has to lift these
homeomorphisms to the real line first.
-/
variables {α β γ : Type*}
open set
/-- We say that `g : β → α` is an order right adjoint function for `f : α → β` if it sends each `y`
to a least upper bound for `{x | f x ≤ y}`. If `α` is a partial order, and `f : α → β` has
a right adjoint, then this right adjoint is unique. -/
def is_order_right_adjoint [preorder α] [preorder β] (f : α → β) (g : β → α) :=
∀ y, is_lub {x | f x ≤ y} (g y)
lemma is_order_right_adjoint_Sup [complete_lattice α] [preorder β] (f : α → β) :
is_order_right_adjoint f (λ y, Sup {x | f x ≤ y}) :=
λ y, is_lub_Sup _
lemma is_order_right_adjoint_cSup [conditionally_complete_lattice α] [preorder β] (f : α → β)
(hne : ∀ y, ∃ x, f x ≤ y) (hbdd : ∀ y, bdd_above {x | f x ≤ y}) :
is_order_right_adjoint f (λ y, Sup {x | f x ≤ y}) :=
λ y, is_lub_cSup (hne y) (hbdd y)
namespace is_order_right_adjoint
protected lemma unique [partial_order α] [preorder β] {f : α → β} {g₁ g₂ : β → α}
(h₁ : is_order_right_adjoint f g₁) (h₂ : is_order_right_adjoint f g₂) :
g₁ = g₂ :=
funext $ λ y, (h₁ y).unique (h₂ y)
lemma right_mono [preorder α] [preorder β] {f : α → β} {g : β → α}
(h : is_order_right_adjoint f g) :
monotone g :=
λ y₁ y₂ hy, (h y₁).mono (h y₂) $ λ x hx, le_trans hx hy
lemma order_iso_comp [preorder α] [preorder β] [preorder γ] {f : α → β} {g : β → α}
(h : is_order_right_adjoint f g) (e : β ≃o γ) :
is_order_right_adjoint (e ∘ f) (g ∘ e.symm) :=
λ y, by simpa [e.le_symm_apply] using h (e.symm y)
lemma comp_order_iso [preorder α] [preorder β] [preorder γ] {f : α → β} {g : β → α}
(h : is_order_right_adjoint f g) (e : γ ≃o α) :
is_order_right_adjoint (f ∘ e) (e.symm ∘ g) :=
begin
intro y,
change is_lub (e ⁻¹' {x | f x ≤ y}) (e.symm (g y)),
rw [e.is_lub_preimage, e.apply_symm_apply],
exact h y
end
end is_order_right_adjoint
namespace function
/-- If an order automorphism `fa` is semiconjugate to an order embedding `fb` by a function `g`
and `g'` is an order right adjoint of `g` (i.e. `g' y = Sup {x | f x ≤ y}`), then `fb` is
semiconjugate to `fa` by `g'`.
This is a version of Proposition 2.1 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma semiconj.symm_adjoint [partial_order α] [preorder β]
{fa : α ≃o α}
{fb : β ↪o β} {g : α → β}
(h : function.semiconj g fa fb) {g' : β → α} (hg' : is_order_right_adjoint g g') :
function.semiconj g' fb fa :=
begin
refine λ y, (hg' _).unique _,
rw [← fa.surjective.image_preimage {x | g x ≤ fb y}, preimage_set_of_eq],
simp only [h.eq, fb.le_iff_le, fa.left_ord_continuous (hg' _)]
end
variable {G : Type*}
lemma semiconj_of_is_lub [partial_order α] [group G]
(f₁ f₂ : G →* (α ≃o α)) {h : α → α}
(H : ∀ x, is_lub (range (λ g', (f₁ g')⁻¹ (f₂ g' x))) (h x)) (g : G) :
function.semiconj h (f₂ g) (f₁ g) :=
begin
refine λ y, (H _).unique _,
have := (f₁ g).left_ord_continuous (H y),
rw [← range_comp, ← (equiv.mul_right g).surjective.range_comp _] at this,
simpa [(∘)] using this
end
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma Sup_div_semiconj [complete_lattice α] [group G]
(f₁ f₂ : G →* (α ≃o α)) (g : G) :
function.semiconj (λ x, ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_is_lub f₁ f₂ (λ x, is_lub_supr) _
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a conditionally complete lattice by order
isomorphisms. Suppose that each set $s(x)=\{f_1(g)^{-1} (f_2(g)(x)) | g \in G\}$ is bounded above.
Then the map `x ↦ Sup s(x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma cSup_div_semiconj [conditionally_complete_lattice α] [group G]
(f₁ f₂ : G →* (α ≃o α))
(hbdd : ∀ x, bdd_above (range $ λ g, (f₁ g)⁻¹ (f₂ g x))) (g : G) :
function.semiconj (λ x, ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_is_lub f₁ f₂ (λ x, is_lub_cSup (range_nonempty _) (hbdd x)) _
end function
|
07d66f819261b0cb02339318caca452821daad24 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/model_theory/substructures.lean | 7104f63c491a32fefa62c18d275555f5cb9fdc19 | [
"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 | 29,572 | lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import order.closure
import model_theory.semantics
import model_theory.encoding
/-!
# First-Order Substructures
This file defines substructures of first-order structures in a similar manner to the various
substructures appearing in the algebra library.
## Main Definitions
* A `first_order.language.substructure` is defined so that `L.substructure M` is the type of all
substructures of the `L`-structure `M`.
* `first_order.language.substructure.closure` is defined so that if `s : set M`, `closure L s` is
the least substructure of `M` containing `s`.
* `first_order.language.substructure.comap` is defined so that `s.comap f` is the preimage of the
substructure `s` under the homomorphism `f`, as a substructure.
* `first_order.language.substructure.map` is defined so that `s.map f` is the image of the
substructure `s` under the homomorphism `f`, as a substructure.
* `first_order.language.hom.range` is defined so that `f.map` is the range of the
the homomorphism `f`, as a substructure.
* `first_order.language.hom.dom_restrict` and `first_order.language.hom.cod_restrict` restrict
the domain and codomain respectively of first-order homomorphisms to substructures.
* `first_order.language.embedding.dom_restrict` and `first_order.language.embedding.cod_restrict`
restrict the domain and codomain respectively of first-order embeddings to substructures.
* `first_order.language.substructure.inclusion` is the inclusion embedding between substructures.
## Main Results
* `L.substructure M` forms a `complete_lattice`.
-/
universes u v w
namespace first_order
namespace language
variables {L : language.{u v}} {M : Type w} {N P : Type*}
variables [L.Structure M] [L.Structure N] [L.Structure P]
open_locale first_order cardinal
open Structure cardinal
section closed_under
open set
variables {n : ℕ} (f : L.functions n) (s : set M)
/-- Indicates that a set in a given structure is a closed under a function symbol. -/
def closed_under : Prop :=
∀ (x : fin n → M), (∀ i : fin n, x i ∈ s) → fun_map f x ∈ s
variable (L)
@[simp] lemma closed_under_univ : closed_under f (univ : set M) :=
λ _ _, mem_univ _
variables {L f s} {t : set M}
namespace closed_under
lemma inter (hs : closed_under f s) (ht : closed_under f t) :
closed_under f (s ∩ t) :=
λ x h, mem_inter (hs x (λ i, mem_of_mem_inter_left (h i)))
(ht x (λ i, mem_of_mem_inter_right (h i)))
lemma inf (hs : closed_under f s) (ht : closed_under f t) :
closed_under f (s ⊓ t) := hs.inter ht
variables {S : set (set M)}
lemma Inf (hS : ∀ s, s ∈ S → closed_under f s) : closed_under f (Inf S) :=
λ x h s hs, hS s hs x (λ i, h i s hs)
end closed_under
end closed_under
variables (L) (M)
/-- A substructure of a structure `M` is a set closed under application of function symbols. -/
structure substructure :=
(carrier : set M)
(fun_mem : ∀{n}, ∀ (f : L.functions n), closed_under f carrier)
variables {L} {M}
namespace substructure
instance : set_like (L.substructure M) M :=
⟨substructure.carrier, λ p q h, by cases p; cases q; congr'⟩
/-- See Note [custom simps projection] -/
def simps.coe (S : L.substructure M) : set M := S
initialize_simps_projections substructure (carrier → coe)
@[simp]
lemma mem_carrier {s : L.substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s := iff.rfl
/-- Two substructures are equal if they have the same elements. -/
@[ext]
theorem ext {S T : L.substructure M}
(h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h
/-- Copy a substructure replacing `carrier` with a set that is equal to it. -/
protected def copy (S : L.substructure M) (s : set M) (hs : s = S) : L.substructure M :=
{ carrier := s,
fun_mem := λ n f, hs.symm ▸ (S.fun_mem f) }
end substructure
variable {S : L.substructure M}
lemma term.realize_mem {α : Type*} (t : L.term α) (xs : α → M) (h : ∀ a, xs a ∈ S) :
t.realize xs ∈ S :=
begin
induction t with a n f ts ih,
{ exact h a },
{ exact substructure.fun_mem _ _ _ ih }
end
namespace substructure
@[simp] lemma coe_copy {s : set M} (hs : s = S) :
(S.copy s hs : set M) = s := rfl
lemma copy_eq {s : set M} (hs : s = S) : S.copy s hs = S :=
set_like.coe_injective hs
lemma constants_mem (c : L.constants) : ↑c ∈ S :=
mem_carrier.2 (S.fun_mem c _ fin.elim0)
/-- The substructure `M` of the structure `M`. -/
instance : has_top (L.substructure M) :=
⟨{ carrier := set.univ,
fun_mem := λ n f x h, set.mem_univ _ }⟩
instance : inhabited (L.substructure M) := ⟨⊤⟩
@[simp] lemma mem_top (x : M) : x ∈ (⊤ : L.substructure M) := set.mem_univ x
@[simp] lemma coe_top : ((⊤ : L.substructure M) : set M) = set.univ := rfl
/-- The inf of two substructures is their intersection. -/
instance : has_inf (L.substructure M) :=
⟨λ S₁ S₂,
{ carrier := S₁ ∩ S₂,
fun_mem := λ n f, (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩
@[simp]
lemma coe_inf (p p' : L.substructure M) : ((p ⊓ p' : L.substructure M) : set M) = p ∩ p' := rfl
@[simp]
lemma mem_inf {p p' : L.substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
instance : has_Inf (L.substructure M) :=
⟨λ s, { carrier := ⋂ t ∈ s, ↑t,
fun_mem := λ n f, closed_under.Inf begin
rintro _ ⟨t, rfl⟩,
by_cases h : t ∈ s,
{ simpa [h] using t.fun_mem f },
{ simp [h] }
end }⟩
@[simp, norm_cast]
lemma coe_Inf (S : set (L.substructure M)) :
((Inf S : L.substructure M) : set M) = ⋂ s ∈ S, ↑s := rfl
lemma mem_Inf {S : set (L.substructure M)} {x : M} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_Inter₂
lemma mem_infi {ι : Sort*} {S : ι → L.substructure M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i :=
by simp only [infi, mem_Inf, set.forall_range_iff]
@[simp, norm_cast]
lemma coe_infi {ι : Sort*} {S : ι → L.substructure M} : (↑(⨅ i, S i) : set M) = ⋂ i, S i :=
by simp only [infi, coe_Inf, set.bInter_range]
/-- Substructures of a structure form a complete lattice. -/
instance : complete_lattice (L.substructure M) :=
{ le := (≤),
lt := (<),
top := (⊤),
le_top := λ S x hx, mem_top x,
inf := (⊓),
Inf := has_Inf.Inf,
le_inf := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩,
inf_le_left := λ a b x, and.left,
inf_le_right := λ a b x, and.right,
.. complete_lattice_of_Inf (L.substructure M) $ λ s,
is_glb.of_image (λ S T,
show (S : set M) ≤ T ↔ S ≤ T, from set_like.coe_subset_coe) is_glb_binfi }
variable (L)
/-- The `L.substructure` generated by a set. -/
def closure : lower_adjoint (coe : L.substructure M → set M) := ⟨λ s, Inf {S | s ⊆ S},
λ s S, ⟨set.subset.trans (λ x hx, mem_Inf.2 $ λ S hS, hS hx), λ h, Inf_le h⟩⟩
variables {L} {s : set M}
lemma mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.substructure M, s ⊆ S → x ∈ S :=
mem_Inf
/-- The substructure generated by a set includes the set. -/
@[simp]
lemma subset_closure : s ⊆ closure L s := (closure L).le_closure s
lemma not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s :=
λ h, hP (subset_closure h)
@[simp]
lemma closed (S : L.substructure M) : (closure L).closed (S : set M) :=
congr rfl ((closure L).eq_of_le set.subset.rfl (λ x xS, mem_closure.2 (λ T hT, hT xS)))
open set
/-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/
@[simp]
lemma closure_le : closure L s ≤ S ↔ s ⊆ S := (closure L).closure_le_closed_iff_le s S.closed
/-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure L s ≤ closure L t`. -/
lemma closure_mono ⦃s t : set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t :=
(closure L).monotone h
lemma closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S :=
(closure L).eq_of_le h₁ h₂
lemma coe_closure_eq_range_term_realize :
(closure L s : set M) = range (@term.realize L _ _ _ (coe : s → M)) :=
begin
let S : L.substructure M := ⟨range (term.realize coe), λ n f x hx, _⟩,
{ change _ = (S : set M),
rw ← set_like.ext'_iff,
refine closure_eq_of_le (λ x hx, ⟨var ⟨x, hx⟩, rfl⟩) (le_Inf (λ S' hS', _)),
{ rintro _ ⟨t, rfl⟩,
exact t.realize_mem _ (λ i, hS' i.2) } },
{ simp only [mem_range] at *,
refine ⟨func f (λ i, (classical.some (hx i))), _⟩,
simp only [term.realize, λ i, classical.some_spec (hx i)] }
end
instance small_closure [small.{u} s] :
small.{u} (closure L s) :=
begin
rw [← set_like.coe_sort_coe, substructure.coe_closure_eq_range_term_realize],
exact small_range _,
end
lemma mem_closure_iff_exists_term {x : M} :
x ∈ closure L s ↔ ∃ (t : L.term s), t.realize (coe : s → M) = x :=
by rw [← set_like.mem_coe, coe_closure_eq_range_term_realize, mem_range]
lemma lift_card_closure_le_card_term : cardinal.lift.{max u w} (# (closure L s)) ≤ # (L.term s) :=
begin
rw [← set_like.coe_sort_coe, coe_closure_eq_range_term_realize],
rw [← cardinal.lift_id'.{w (max u w)} (# (L.term s))],
exact cardinal.mk_range_le_lift,
end
theorem lift_card_closure_le : cardinal.lift.{u w} (# (closure L s)) ≤
max ℵ₀ (cardinal.lift.{u w} (#s) + cardinal.lift.{w u} (#(Σ i, L.functions i))) :=
begin
rw ←lift_umax,
refine lift_card_closure_le_card_term.trans (term.card_le.trans _),
rw [mk_sum, lift_umax],
end
variable (L)
lemma _root_.set.countable.substructure_closure
[L.countable_functions] (h : s.countable) :
nonempty (encodable (closure L s)) :=
begin
haveI : nonempty (encodable s) := h,
rw [encodable_iff, ← lift_le_aleph_0],
exact lift_card_closure_le_card_term.trans term.card_le_aleph_0,
end
variables {L} (S)
/-- An induction principle for closure membership. If `p` holds for all elements of `s`, and
is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/
@[elab_as_eliminator] lemma closure_induction {p : M → Prop} {x} (h : x ∈ closure L s)
(Hs : ∀ x ∈ s, p x)
(Hfun : ∀ {n : ℕ} (f : L.functions n), closed_under f (set_of p)) : p x :=
(@closure_le L M _ ⟨set_of p, λ n, Hfun⟩ _).2 Hs h
/-- If `s` is a dense set in a structure `M`, `substructure.closure L s = ⊤`, then in order to prove
that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify
that `p` is preserved under function symbols. -/
@[elab_as_eliminator] lemma dense_induction {p : M → Prop} (x : M) {s : set M}
(hs : closure L s = ⊤) (Hs : ∀ x ∈ s, p x)
(Hfun : ∀ {n : ℕ} (f : L.functions n), closed_under f (set_of p)) : p x :=
have ∀ x ∈ closure L s, p x, from λ x hx, closure_induction hx Hs (λ n, Hfun),
by simpa [hs] using this x
variables (L) (M)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : galois_insertion (@closure L M _) coe :=
{ choice := λ s _, closure L s,
gc := (closure L).gc,
le_l_u := λ s, subset_closure,
choice_eq := λ s h, rfl }
variables {L} {M}
/-- Closure of a substructure `S` equals `S`. -/
@[simp] lemma closure_eq : closure L (S : set M) = S := (substructure.gi L M).l_u_eq S
@[simp] lemma closure_empty : closure L (∅ : set M) = ⊥ :=
(substructure.gi L M).gc.l_bot
@[simp] lemma closure_univ : closure L (univ : set M) = ⊤ :=
@coe_top L M _ ▸ closure_eq ⊤
lemma closure_union (s t : set M) : closure L (s ∪ t) = closure L s ⊔ closure L t :=
(substructure.gi L M).gc.l_sup
lemma closure_Union {ι} (s : ι → set M) : closure L (⋃ i, s i) = ⨆ i, closure L (s i) :=
(substructure.gi L M).gc.l_supr
instance small_bot :
small.{u} (⊥ : L.substructure M) :=
begin
rw ← closure_empty,
exact substructure.small_closure
end
/-!
### `comap` and `map`
-/
/-- The preimage of a substructure along a homomorphism is a substructure. -/
@[simps] def comap (φ : M →[L] N) (S : L.substructure N) : L.substructure M :=
{ carrier := (φ ⁻¹' S),
fun_mem := λ n f x hx, begin
rw [mem_preimage, φ.map_fun],
exact S.fun_mem f (φ ∘ x) hx,
end }
@[simp]
lemma mem_comap {S : L.substructure N} {f : M →[L] N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl
lemma comap_comap (S : L.substructure P) (g : N →[L] P) (f : M →[L] N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[simp]
lemma comap_id (S : L.substructure P) : S.comap (hom.id _ _) = S :=
ext (by simp)
/-- The image of a substructure along a homomorphism is a substructure. -/
@[simps] def map (φ : M →[L] N) (S : L.substructure M) : L.substructure N :=
{ carrier := (φ '' S),
fun_mem := λ n f x hx, (mem_image _ _ _).1
⟨fun_map f (λ i, classical.some (hx i)),
S.fun_mem f _ (λ i, (classical.some_spec (hx i)).1),
begin
simp only [hom.map_fun, set_like.mem_coe],
exact congr rfl (funext (λ i, (classical.some_spec (hx i)).2)),
end⟩ }
@[simp]
lemma mem_map {f : M →[L] N} {S : L.substructure M} {y : N} :
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
mem_image_iff_bex
lemma mem_map_of_mem (f : M →[L] N) {S : L.substructure M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
lemma apply_coe_mem_map (f : M →[L] N) (S : L.substructure M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.prop
lemma map_map (g : N →[L] P) (f : M →[L] N) : (S.map f).map g = S.map (g.comp f) :=
set_like.coe_injective $ image_image _ _ _
lemma map_le_iff_le_comap {f : M →[L] N} {S : L.substructure M} {T : L.substructure N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
lemma gc_map_comap (f : M →[L] N) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
lemma map_le_of_le_comap {T : L.substructure N} {f : M →[L] N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
lemma le_comap_of_map_le {T : L.substructure N} {f : M →[L] N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
lemma le_comap_map {f : M →[L] N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
lemma map_comap_le {S : L.substructure N} {f : M →[L] N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
lemma monotone_map {f : M →[L] N} : monotone (map f) :=
(gc_map_comap f).monotone_l
lemma monotone_comap {f : M →[L] N} : monotone (comap f) :=
(gc_map_comap f).monotone_u
@[simp]
lemma map_comap_map {f : M →[L] N} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[simp]
lemma comap_map_comap {S : L.substructure N} {f : M →[L] N} :
((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
lemma map_sup (S T : L.substructure M) (f : M →[L] N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
lemma map_supr {ι : Sort*} (f : M →[L] N) (s : ι → L.substructure M) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
lemma comap_inf (S T : L.substructure N) (f : M →[L] N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
lemma comap_infi {ι : Sort*} (f : M →[L] N) (s : ι → L.substructure N) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp] lemma map_bot (f : M →[L] N) : (⊥ : L.substructure M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma comap_top (f : M →[L] N) : (⊤ : L.substructure N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp] lemma map_id (S : L.substructure M) : S.map (hom.id L M) = S :=
ext (λ x, ⟨λ ⟨_, h, rfl⟩, h, λ h, ⟨_, h, rfl⟩⟩)
lemma map_closure (f : M →[L] N) (s : set M) :
(closure L s).map f = closure L (f '' s) :=
eq.symm $ closure_eq_of_le (set.image_subset f subset_closure) $ map_le_iff_le_comap.2 $
closure_le.2 $ λ x hx, subset_closure ⟨x, hx, rfl⟩
@[simp] lemma closure_image (f : M →[L] N) :
closure L (f '' s) = map f (closure L s) :=
(map_closure f s).symm
section galois_coinsertion
variables {ι : Type*} {f : M →[L] N} (hf : function.injective f)
include hf
/-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/
def gci_map_comap : galois_coinsertion (map f) (comap f) :=
(gc_map_comap f).to_galois_coinsertion
(λ S x, by simp [mem_comap, mem_map, hf.eq_iff])
lemma comap_map_eq_of_injective (S : L.substructure M) : (S.map f).comap f = S :=
(gci_map_comap hf).u_l_eq _
lemma comap_surjective_of_injective : function.surjective (comap f) :=
(gci_map_comap hf).u_surjective
lemma map_injective_of_injective : function.injective (map f) :=
(gci_map_comap hf).l_injective
lemma comap_inf_map_of_injective (S T : L.substructure M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gci_map_comap hf).u_inf_l _ _
lemma comap_infi_map_of_injective (S : ι → L.substructure M) :
(⨅ i, (S i).map f).comap f = infi S :=
(gci_map_comap hf).u_infi_l _
lemma comap_sup_map_of_injective (S T : L.substructure M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gci_map_comap hf).u_sup_l _ _
lemma comap_supr_map_of_injective (S : ι → L.substructure M) :
(⨆ i, (S i).map f).comap f = supr S :=
(gci_map_comap hf).u_supr_l _
lemma map_le_map_iff_of_injective {S T : L.substructure M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gci_map_comap hf).l_le_l_iff
lemma map_strict_mono_of_injective : strict_mono (map f) :=
(gci_map_comap hf).strict_mono_l
end galois_coinsertion
section galois_insertion
variables {ι : Type*} {f : M →[L] N} (hf : function.surjective f)
include hf
/-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/
def gi_map_comap : galois_insertion (map f) (comap f) :=
(gc_map_comap f).to_galois_insertion
(λ S x h, let ⟨y, hy⟩ := hf x in mem_map.2 ⟨y, by simp [hy, h]⟩)
lemma map_comap_eq_of_surjective (S : L.substructure N) : (S.comap f).map f = S :=
(gi_map_comap hf).l_u_eq _
lemma map_surjective_of_surjective : function.surjective (map f) :=
(gi_map_comap hf).l_surjective
lemma comap_injective_of_surjective : function.injective (comap f) :=
(gi_map_comap hf).u_injective
lemma map_inf_comap_of_surjective (S T : L.substructure N) :
(S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(gi_map_comap hf).l_inf_u _ _
lemma map_infi_comap_of_surjective (S : ι → L.substructure N) :
(⨅ i, (S i).comap f).map f = infi S :=
(gi_map_comap hf).l_infi_u _
lemma map_sup_comap_of_surjective (S T : L.substructure N) :
(S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(gi_map_comap hf).l_sup_u _ _
lemma map_supr_comap_of_surjective (S : ι → L.substructure N) :
(⨆ i, (S i).comap f).map f = supr S :=
(gi_map_comap hf).l_supr_u _
lemma comap_le_comap_iff_of_surjective {S T : L.substructure N} :
S.comap f ≤ T.comap f ↔ S ≤ T :=
(gi_map_comap hf).u_le_u_iff
lemma comap_strict_mono_of_surjective : strict_mono (comap f) :=
(gi_map_comap hf).strict_mono_u
end galois_insertion
instance induced_Structure {S : L.substructure M} : L.Structure S :=
{ fun_map := λ n f x, ⟨fun_map f (λ i, x i), S.fun_mem f (λ i, x i) (λ i, (x i).2)⟩,
rel_map := λ n r x, rel_map r (λ i, (x i : M)) }
/-- The natural embedding of an `L.substructure` of `M` into `M`. -/
def subtype (S : L.substructure M) : S ↪[L] M :=
{ to_fun := coe,
inj' := subtype.coe_injective }
@[simp] theorem coe_subtype : ⇑S.subtype = coe := rfl
/-- The equivalence between the maximal substructure of a structure and the structure itself. -/
def top_equiv : (⊤ : L.substructure M) ≃[L] M :=
{ to_fun := subtype ⊤,
inv_fun := λ m, ⟨m, mem_top m⟩,
left_inv := λ m, by simp,
right_inv := λ m, rfl }
@[simp] lemma coe_top_equiv : ⇑(top_equiv : (⊤ : L.substructure M) ≃[L] M) = coe := rfl
/-- A dependent version of `substructure.closure_induction`. -/
@[elab_as_eliminator] lemma closure_induction' (s : set M) {p : Π x, x ∈ closure L s → Prop}
(Hs : ∀ x (h : x ∈ s), p x (subset_closure h))
(Hfun : ∀ {n : ℕ} (f : L.functions n), closed_under f {x | ∃ hx, p x hx})
{x} (hx : x ∈ closure L s) :
p x hx :=
begin
refine exists.elim _ (λ (hx : x ∈ closure L s) (hc : p x hx), hc),
exact closure_induction hx (λ x hx, ⟨subset_closure hx, Hs x hx⟩) @Hfun
end
end substructure
namespace Lhom
open substructure
variables {L' : language} [L'.Structure M] (φ : L →ᴸ L') [φ.is_expansion_on M]
include φ
/-- Reduces the language of a substructure along a language hom. -/
def substructure_reduct : L'.substructure M ↪o L.substructure M :=
{ to_fun := λ S, { carrier := S,
fun_mem := λ n f x hx, begin
have h := S.fun_mem (φ.on_function f) x hx,
simp only [Lhom.map_on_function, substructure.mem_carrier] at h,
exact h,
end },
inj' := λ S T h, begin
simp only [set_like.coe_set_eq] at h,
exact h,
end,
map_rel_iff' := λ S T, iff.rfl }
@[simp] lemma mem_substructure_reduct {x : M} {S : L'.substructure M} :
x ∈ φ.substructure_reduct S ↔ x ∈ S := iff.rfl
@[simp] lemma coe_substructure_reduct {S : L'.substructure M} :
(φ.substructure_reduct S : set M) = ↑S := rfl
end Lhom
namespace substructure
/-- Turns any substructure containing a constant set `A` into a `L[[A]]`-substructure. -/
def with_constants (S : L.substructure M) {A : set M} (h : A ⊆ S) : L[[A]].substructure M :=
{ carrier := S,
fun_mem := λ n f, begin
cases f,
{ exact S.fun_mem f },
{ cases n,
{ exact λ _ _, h f.2 },
{ exact is_empty_elim f } }
end }
variables {A : set M} {s : set M} (h : A ⊆ S)
@[simp] lemma mem_with_constants {x : M} : x ∈ S.with_constants h ↔ x ∈ S := iff.rfl
@[simp] lemma coe_with_constants : (S.with_constants h : set M) = ↑S := rfl
@[simp] lemma reduct_with_constants :
(L.Lhom_with_constants A).substructure_reduct (S.with_constants h) = S :=
by { ext, simp }
lemma subset_closure_with_constants : A ⊆ (closure (L[[A]]) s) :=
begin
intros a ha,
simp only [set_like.mem_coe],
let a' : (L[[A]]).constants := sum.inr ⟨a, ha⟩,
exact constants_mem a',
end
lemma closure_with_constants_eq : (closure (L[[A]]) s) = (closure L (A ∪ s)).with_constants
((A.subset_union_left s).trans subset_closure) :=
begin
refine closure_eq_of_le ((A.subset_union_right s).trans subset_closure) _,
rw ← ((L.Lhom_with_constants A).substructure_reduct).le_iff_le,
simp only [subset_closure, reduct_with_constants, closure_le, Lhom.coe_substructure_reduct,
set.union_subset_iff, and_true],
{ exact subset_closure_with_constants },
{ apply_instance },
{ apply_instance },
end
end substructure
namespace hom
open substructure
/-- The restriction of a first-order hom to a substructure `s ⊆ M` gives a hom `s → N`. -/
@[simps] def dom_restrict (f : M →[L] N) (p : L.substructure M) : p →[L] N :=
f.comp p.subtype.to_hom
/-- A first-order hom `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to a
hom `M → p`. -/
@[simps] def cod_restrict (p : L.substructure N) (f : M →[L] N) (h : ∀c, f c ∈ p) : M →[L] p :=
{ to_fun := λc, ⟨f c, h c⟩,
map_rel' := λ n R x h, f.map_rel R x h }
@[simp] lemma comp_cod_restrict (f : M →[L] N) (g : N →[L] P) (p : L.substructure P)
(h : ∀b, g b ∈ p) :
((cod_restrict p g h).comp f : M →[L] p) = cod_restrict p (g.comp f) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (f : M →[L] N) (p : L.substructure N) (h : ∀b, f b ∈ p) :
p.subtype.to_hom.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- The range of a first-order hom `f : M → N` is a submodule of `N`.
See Note [range copy pattern]. -/
def range (f : M →[L] N) : L.substructure N :=
(map f ⊤).copy (set.range f) set.image_univ.symm
theorem range_coe (f : M →[L] N) :
(range f : set N) = set.range f := rfl
@[simp] theorem mem_range
{f : M →[L] N} {x} : x ∈ range f ↔ ∃ y, f y = x :=
iff.rfl
lemma range_eq_map
(f : M →[L] N) : f.range = map f ⊤ :=
by { ext, simp }
theorem mem_range_self
(f : M →[L] N) (x : M) : f x ∈ f.range := ⟨x, rfl⟩
@[simp] theorem range_id : range (id L M) = ⊤ :=
set_like.coe_injective set.range_id
theorem range_comp (f : M →[L] N) (g : N →[L] P) :
range (g.comp f : M →[L] P) = map g (range f) :=
set_like.coe_injective (set.range_comp g f)
theorem range_comp_le_range (f : M →[L] N) (g : N →[L] P) :
range (g.comp f : M →[L] P) ≤ range g :=
set_like.coe_mono (set.range_comp_subset_range f g)
theorem range_eq_top {f : M →[L] N} :
range f = ⊤ ↔ function.surjective f :=
by rw [set_like.ext'_iff, range_coe, coe_top, set.range_iff_surjective]
lemma range_le_iff_comap {f : M →[L] N} {p : L.substructure N} :
range f ≤ p ↔ comap f p = ⊤ :=
by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range {f : M →[L] N} {p : L.substructure M} :
map f p ≤ range f :=
set_like.coe_mono (set.image_subset_range f p)
/-- The substructure of elements `x : M` such that `f x = g x` -/
def eq_locus (f g : M →[L] N) : substructure L M :=
{ carrier := {x : M | f x = g x},
fun_mem := λ n fn x hx, by
{ have h : f ∘ x = g ∘ x := by { ext, repeat {rw function.comp_apply}, apply hx, },
simp [h], } }
/-- If two `L.hom`s are equal on a set, then they are equal on its substructure closure. -/
lemma eq_on_closure {f g : M →[L] N} {s : set M} (h : set.eq_on f g s) :
set.eq_on f g (closure L s) :=
show closure L s ≤ f.eq_locus g, from closure_le.2 h
lemma eq_of_eq_on_top {f g : M →[L] N} (h : set.eq_on f g (⊤ : substructure L M)) :
f = g :=
ext $ λ x, h trivial
variable {s : set M}
lemma eq_of_eq_on_dense (hs : closure L s = ⊤) {f g : M →[L] N} (h : s.eq_on f g) :
f = g :=
eq_of_eq_on_top $ hs ▸ eq_on_closure h
end hom
namespace embedding
open substructure
/-- The restriction of a first-order embedding to a substructure `s ⊆ M` gives an embedding `s → N`.
-/
def dom_restrict (f : M ↪[L] N) (p : L.substructure M) : p ↪[L] N :=
f.comp p.subtype
@[simp] lemma dom_restrict_apply (f : M ↪[L] N) (p : L.substructure M) (x : p) :
f.dom_restrict p x = f x := rfl
/-- A first-order embedding `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted
to an embedding `M → p`. -/
def cod_restrict (p : L.substructure N) (f : M ↪[L] N) (h : ∀c, f c ∈ p) : M ↪[L] p :=
{ to_fun := f.to_hom.cod_restrict p h,
inj' := λ a b ab, f.injective (subtype.mk_eq_mk.1 ab),
map_fun' := λ n F x, (f.to_hom.cod_restrict p h).map_fun' F x,
map_rel' := λ n r x, begin
simp only,
rw [← p.subtype.map_rel, function.comp.assoc],
change rel_map r ((hom.comp p.subtype.to_hom (f.to_hom.cod_restrict p h)) ∘ x) ↔ _,
rw [hom.subtype_comp_cod_restrict, ← f.map_rel],
refl,
end }
@[simp] theorem cod_restrict_apply (p : L.substructure N) (f : M ↪[L] N) {h} (x : M) :
(cod_restrict p f h x : N) = f x := rfl
@[simp] lemma comp_cod_restrict (f : M ↪[L] N) (g : N ↪[L] P) (p : L.substructure P)
(h : ∀b, g b ∈ p) :
((cod_restrict p g h).comp f : M ↪[L] p) = cod_restrict p (g.comp f) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (f : M ↪[L] N) (p : L.substructure N) (h : ∀b, f b ∈ p) :
p.subtype.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- The equivalence between a substructure `s` and its image `s.map f.to_hom`, where `f` is an
embedding. -/
noncomputable def substructure_equiv_map (f : M ↪[L] N) (s : L.substructure M) :
s ≃[L] s.map f.to_hom :=
{ to_fun := cod_restrict (s.map f.to_hom) (f.dom_restrict s) (λ ⟨m, hm⟩, ⟨m, hm, rfl⟩),
inv_fun := λ n, ⟨classical.some n.2, (classical.some_spec n.2).1⟩,
left_inv := λ ⟨m, hm⟩, subtype.mk_eq_mk.2 (f.injective ((classical.some_spec (cod_restrict
(s.map f.to_hom) (f.dom_restrict s) (λ ⟨m, hm⟩, ⟨m, hm, rfl⟩) ⟨m, hm⟩).2).2)),
right_inv := λ ⟨n, hn⟩, subtype.mk_eq_mk.2 (classical.some_spec hn).2 }
@[simp] lemma substructure_equiv_map_apply (f : M ↪[L] N) (p : L.substructure M) (x : p) :
(f.substructure_equiv_map p x : N) = f x := rfl
/-- The equivalence between the domain and the range of an embedding `f`. -/
noncomputable def equiv_range (f : M ↪[L] N) :
M ≃[L] f.to_hom.range :=
{ to_fun := cod_restrict f.to_hom.range f f.to_hom.mem_range_self,
inv_fun := λ n, classical.some n.2,
left_inv := λ m, f.injective (classical.some_spec (cod_restrict f.to_hom.range f
f.to_hom.mem_range_self m).2),
right_inv := λ ⟨n, hn⟩, subtype.mk_eq_mk.2 (classical.some_spec hn) }
@[simp] lemma equiv_range_apply (f : M ↪[L] N) (x : M) :
(f.equiv_range x : N) = f x := rfl
end embedding
namespace equiv
lemma to_hom_range (f : M ≃[L] N) :
f.to_hom.range = ⊤ :=
begin
ext n,
simp only [hom.mem_range, coe_to_hom, substructure.mem_top, iff_true],
exact ⟨f.symm n, apply_symm_apply _ _⟩
end
end equiv
namespace substructure
/-- The embedding associated to an inclusion of substructures. -/
def inclusion {S T : L.substructure M} (h : S ≤ T) : S ↪[L] T :=
S.subtype.cod_restrict _ (λ x, h x.2)
@[simp] lemma coe_inclusion {S T : L.substructure M} (h : S ≤ T) :
(inclusion h : S → T) = set.inclusion h := rfl
lemma range_subtype (S : L.substructure M) : S.subtype.to_hom.range = S :=
begin
ext x,
simp only [hom.mem_range, embedding.coe_to_hom, coe_subtype],
refine ⟨_, λ h, ⟨⟨x, h⟩, rfl⟩⟩,
rintros ⟨⟨y, hy⟩, rfl⟩,
exact hy,
end
end substructure
end language
end first_order
|
e2d0f87de6b651b207b40350805b7e360161b1cd | 4727251e0cd73359b15b664c3170e5d754078599 | /src/linear_algebra/adic_completion.lean | 63aec8e3625a84295afca284504a1c3c7cf1e9e1 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 10,006 | 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.geom_sum
import linear_algebra.smodeq
import ring_theory.ideal.quotient
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* :=
M ⧸ (⨅ n : ℕ, I ^ n • ⊤ : submodule R M)
/-- 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 : ℕ, (M ⧸ (I ^ n • ⊤ : submodule R M))) :=
{ carrier := { f | ∀ {m n} (h : m ≤ n), liftq _ (mkq _)
(by { rw ker_mkq, exact smul_mono (ideal.pow_le_pow h) le_rfl }) (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_rfl 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] (M ⧸ (I ^ n • ⊤ : submodule R M)) :=
{ 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 → (M ⧸ (I ^ n • ⊤ : submodule R M))) = λ 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))
(λ _ _ ih1 ih2, by rw [linear_map.map_add, ih1, ih2, linear_map.map_zero, add_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 [← add_tsub_cancel_of_le 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],
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, 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
|
e784f08bc071dcc4f6be5e33857488d6df7c2282 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/typeclass_coerce.lean | f3298541d8796f04e6ff8d8a3805bba8bf10f45c | [
"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 | 3,921 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Daniel Selsam, Leonardo de Moura
Declare new, simpler coercion class without the special support for transitivity.
Test that new tabled typeclass resolution deals with loops and diamonds correctly.
-/
set_option synthInstance.checkSynthOrder false
class HasCoerce (a : Type) (b : Type) :=
(coerce : a → b)
def coerce {a b : Type} [HasCoerce a b] : a → b :=
@HasCoerce.coerce a b _
instance coerceTrans {a b c : Type} [HasCoerce a b] [HasCoerce b c] : HasCoerce a c :=
⟨fun x => coerce (coerce x : b)⟩
instance coerceBoolToProp : HasCoerce Bool Prop :=
⟨fun y => y = true⟩
instance coerceDecidableEq (x : Bool) : Decidable (coerce x) :=
inferInstanceAs (Decidable (x = true))
instance coerceSubtype {a : Type} {p : a → Prop} : HasCoerce {x // p x} a :=
⟨Subtype.val⟩
instance liftCoerceFn {a₁ a₂ b₁ b₂ : Type} [HasCoerce a₂ a₁] [HasCoerce b₁ b₂] : HasCoerce (a₁ → b₁) (a₂ → b₂) :=
⟨fun f x => coerce (f (coerce x))⟩
instance liftCoerceFnRange {a b₁ b₂ : Type} [HasCoerce b₁ b₂] : HasCoerce (a → b₁) (a → b₂) :=
⟨fun f x => coerce (f x)⟩
instance liftCoerceFnDom {a₁ a₂ b : Type} [HasCoerce a₂ a₁] : HasCoerce (a₁ → b) (a₂ → b) :=
⟨fun f x => f (coerce x)⟩
instance liftCoercePair {a₁ a₂ b₁ b₂ : Type} [HasCoerce a₁ a₂] [HasCoerce b₁ b₂] : HasCoerce (a₁ × b₁) (a₂ × b₂) :=
⟨fun p => match p with
| (x, y) => (coerce x, coerce y)⟩
instance liftCoercePair₁ {a₁ a₂ b : Type} [HasCoerce a₁ a₂] : HasCoerce (a₁ × b) (a₂ × b) :=
⟨fun p => match p with
| (x, y) => (coerce x, y)⟩
instance liftCoercePair₂ {a b₁ b₂ : Type} [HasCoerce b₁ b₂] : HasCoerce (a × b₁) (a × b₂) :=
⟨fun p => match p with
| (x, y) => (x, coerce y)⟩
instance liftCoerceList {a b : Type} [HasCoerce a b] : HasCoerce (List a) (List b) :=
⟨fun l => List.map (@coerce a b _) l⟩
-- Tests
axiom Bot (α : Type) (n : Nat) : Type
axiom Left (α : Type) (n : Nat) : Type
axiom Right (α : Type) (n : Nat) : Type
axiom Top (α : Type) (n : Nat) : Type
@[instance] axiom BotToTopSucc (α : Type) (n : Nat) : HasCoerce (Bot α n) (Top α n.succ)
@[instance] axiom TopSuccToBot (α : Type) (n : Nat) : HasCoerce (Top α n.succ) (Bot α n)
@[instance] axiom TopToRight (α : Type) (n : Nat) : HasCoerce (Top α n) (Right α n)
@[instance] axiom TopToLeft (α : Type) (n : Nat) : HasCoerce (Top α n) (Left α n)
@[instance] axiom LeftToTop (α : Type) (n : Nat) : HasCoerce (Left α n) (Top α n)
@[instance] axiom RightToTop (α : Type) (n : Nat) : HasCoerce (Right α n) (Top α n)
@[instance] axiom LeftToBot (α : Type) (n : Nat) : HasCoerce (Left α n) (Bot α n)
@[instance] axiom RightToBot (α : Type) (n : Nat) : HasCoerce (Right α n) (Bot α n)
@[instance] axiom BotToLeft (α : Type) (n : Nat) : HasCoerce (Bot α n) (Left α n)
@[instance] axiom BotToRight (α : Type) (n : Nat) : HasCoerce (Bot α n) (Right α n)
#print "-----"
set_option synthInstance.maxSize 256
set_option synthInstance.maxHeartbeats 500000
#synth HasCoerce (Top Unit Nat.zero)
(Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ)
#synth HasCoerce (Top Unit Nat.zero × Top Unit Nat.zero × Top Unit Nat.zero)
(Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ
× Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ
× Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ)
#synth HasCoerce (Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ → Top Unit Nat.zero)
(Top Unit Nat.zero → Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ)
|
aa6ac3661026e02b9b3a39fea220111deb285475 | f5f7e6fae601a5fe3cac7cc3ed353ed781d62419 | /src/algebra/group_power.lean | d8a2c94f62a731704cd64035b1947db34c529df2 | [
"Apache-2.0"
] | permissive | EdAyers/mathlib | 9ecfb2f14bd6caad748b64c9c131befbff0fb4e0 | ca5d4c1f16f9c451cf7170b10105d0051db79e1b | refs/heads/master | 1,626,189,395,845 | 1,555,284,396,000 | 1,555,284,396,000 | 144,004,030 | 0 | 0 | Apache-2.0 | 1,533,727,664,000 | 1,533,727,663,000 | null | UTF-8 | Lean | false | false | 27,218 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
The power operation on monoids and groups. We separate this from group, because it depends on
nat, which in turn depends on other parts of algebra.
We have "pow a n" for natural number powers, and "gpow a i" for integer powers. The notation
a^n is used for the first, but users can locally redefine it to gpow when needed.
Note: power adopts the convention that 0^0=1.
-/
import algebra.char_zero algebra.group algebra.ordered_field
import data.int.basic data.list.basic
universes u v
variable {α : Type u}
@[simp] theorem inv_one [division_ring α] : (1⁻¹ : α) = 1 := by rw [inv_eq_one_div, one_div_one]
@[simp] theorem inv_inv' [discrete_field α] {a:α} : a⁻¹⁻¹ = a :=
by rw [inv_eq_one_div, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_one]
/-- The power operation in a monoid. `a^n = a*a*...*a` n times. -/
def monoid.pow [monoid α] (a : α) : ℕ → α
| 0 := 1
| (n+1) := a * monoid.pow n
def add_monoid.smul [add_monoid α] (n : ℕ) (a : α) : α :=
@monoid.pow (multiplicative α) _ a n
precedence `•`:70
local infix ` • ` := add_monoid.smul
@[priority 5] instance monoid.has_pow [monoid α] : has_pow α ℕ := ⟨monoid.pow⟩
/- monoid -/
section monoid
variables [monoid α] {β : Type u} [add_monoid β]
@[simp] theorem pow_zero (a : α) : a^0 = 1 := rfl
@[simp] theorem add_monoid.zero_smul (a : β) : 0 • a = 0 := rfl
attribute [to_additive add_monoid.zero_smul] pow_zero
theorem pow_succ (a : α) (n : ℕ) : a^(n+1) = a * a^n := rfl
theorem succ_smul (a : β) (n : ℕ) : (n+1)•a = a + n•a := rfl
attribute [to_additive succ_smul] pow_succ
@[simp] theorem pow_one (a : α) : a^1 = a := mul_one _
@[simp] theorem add_monoid.one_smul (a : β) : 1•a = a := add_zero _
attribute [to_additive add_monoid.one_smul] pow_one
theorem pow_mul_comm' (a : α) (n : ℕ) : a^n * a = a * a^n :=
by induction n with n ih; [rw [pow_zero, one_mul, mul_one],
rw [pow_succ, mul_assoc, ih]]
theorem smul_add_comm' : ∀ (a : β) (n : ℕ), n•a + a = a + n•a :=
@pow_mul_comm' (multiplicative β) _
theorem pow_succ' (a : α) (n : ℕ) : a^(n+1) = a^n * a :=
by rw [pow_succ, pow_mul_comm']
theorem succ_smul' (a : β) (n : ℕ) : (n+1)•a = n•a + a :=
by rw [succ_smul, smul_add_comm']
attribute [to_additive succ_smul'] pow_succ'
theorem pow_two (a : α) : a^2 = a * a :=
show a*(a*1)=a*a, by rw mul_one
theorem two_smul (a : β) : 2•a = a + a :=
show a+(a+0)=a+a, by rw add_zero
attribute [to_additive two_smul] pow_two
theorem pow_add (a : α) (m n : ℕ) : a^(m + n) = a^m * a^n :=
by induction n with n ih; [rw [add_zero, pow_zero, mul_one],
rw [pow_succ, ← pow_mul_comm', ← mul_assoc, ← ih, ← pow_succ']]; refl
theorem add_monoid.add_smul : ∀ (a : β) (m n : ℕ), (m + n)•a = m•a + n•a :=
@pow_add (multiplicative β) _
attribute [to_additive add_monoid.add_smul] pow_add
@[simp] theorem one_pow (n : ℕ) : (1 : α)^n = (1:α) :=
by induction n with n ih; [refl, rw [pow_succ, ih, one_mul]]
@[simp] theorem add_monoid.smul_zero (n : ℕ) : n•(0 : β) = (0:β) :=
by induction n with n ih; [refl, rw [succ_smul, ih, zero_add]]
attribute [to_additive add_monoid.smul_zero] one_pow
theorem pow_mul (a : α) (m n : ℕ) : a^(m * n) = (a^m)^n :=
by induction n with n ih; [rw mul_zero, rw [nat.mul_succ, pow_add, pow_succ', ih]]; refl
theorem add_monoid.mul_smul' : ∀ (a : β) (m n : ℕ), m * n • a = n•(m•a) :=
@pow_mul (multiplicative β) _
attribute [to_additive add_monoid.mul_smul'] pow_mul
theorem pow_mul' (a : α) (m n : ℕ) : a^(m * n) = (a^n)^m :=
by rw [mul_comm, pow_mul]
theorem add_monoid.mul_smul (a : β) (m n : ℕ) : m * n • a = m•(n•a) :=
by rw [mul_comm, add_monoid.mul_smul']
attribute [to_additive add_monoid.mul_smul] pow_mul'
@[simp] theorem add_monoid.smul_one [has_one β] : ∀ n : ℕ, n • (1 : β) = n :=
nat.eq_cast _ (add_monoid.zero_smul _) (add_monoid.one_smul _) (add_monoid.add_smul _)
theorem pow_bit0 (a : α) (n : ℕ) : a ^ bit0 n = a^n * a^n := pow_add _ _ _
theorem bit0_smul (a : β) (n : ℕ) : bit0 n • a = n•a + n•a := add_monoid.add_smul _ _ _
attribute [to_additive bit0_smul] pow_bit0
theorem pow_bit1 (a : α) (n : ℕ) : a ^ bit1 n = a^n * a^n * a :=
by rw [bit1, pow_succ', pow_bit0]
theorem bit1_smul : ∀ (a : β) (n : ℕ), bit1 n • a = n•a + n•a + a :=
@pow_bit1 (multiplicative β) _
attribute [to_additive bit1_smul] pow_bit1
theorem pow_mul_comm (a : α) (m n : ℕ) : a^m * a^n = a^n * a^m :=
by rw [←pow_add, ←pow_add, add_comm]
theorem smul_add_comm : ∀ (a : β) (m n : ℕ), m•a + n•a = n•a + m•a :=
@pow_mul_comm (multiplicative β) _
attribute [to_additive smul_add_comm] pow_mul_comm
@[simp] theorem list.prod_repeat (a : α) (n : ℕ) : (list.repeat a n).prod = a ^ n :=
by induction n with n ih; [refl, rw [list.repeat_succ, list.prod_cons, ih]]; refl
@[simp] theorem list.sum_repeat : ∀ (a : β) (n : ℕ), (list.repeat a n).sum = n • a :=
@list.prod_repeat (multiplicative β) _
attribute [to_additive list.sum_repeat] list.prod_repeat
@[simp] lemma units.coe_pow (u : units α) (n : ℕ) : ((u ^ n : units α) : α) = u ^ n :=
by induction n; simp [*, pow_succ]
end monoid
namespace is_monoid_hom
variables {β : Type v} [monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
theorem map_pow (a : α) : ∀(n : ℕ), f (a ^ n) = (f a) ^ n
| 0 := is_monoid_hom.map_one f
| (nat.succ n) := by rw [pow_succ, is_monoid_hom.map_mul f, map_pow n]; refl
end is_monoid_hom
namespace is_add_monoid_hom
variables {β : Type*} [add_monoid α] [add_monoid β] (f : α → β) [is_add_monoid_hom f]
theorem map_smul (a : α) : ∀(n : ℕ), f (n • a) = n • (f a)
| 0 := is_add_monoid_hom.map_zero f
| (nat.succ n) := by rw [succ_smul, is_add_monoid_hom.map_add f, map_smul n]; refl
end is_add_monoid_hom
attribute [to_additive is_add_monoid_hom.map_smul] is_monoid_hom.map_pow
@[simp] theorem nat.pow_eq_pow (p q : ℕ) :
@has_pow.pow _ _ monoid.has_pow p q = p ^ q :=
by induction q with q ih; [refl, rw [nat.pow_succ, pow_succ, mul_comm, ih]]
@[simp] theorem nat.smul_eq_mul (m n : ℕ) : m • n = m * n :=
by induction m with m ih; [rw [add_monoid.zero_smul, zero_mul],
rw [succ_smul', ih, nat.succ_mul]]
/- commutative monoid -/
section comm_monoid
variables [comm_monoid α] {β : Type*} [add_comm_monoid β]
theorem mul_pow (a b : α) (n : ℕ) : (a * b)^n = a^n * b^n :=
by induction n with n ih; [exact (mul_one _).symm,
simp only [pow_succ, ih, mul_assoc, mul_left_comm]]
theorem add_monoid.smul_add : ∀ (a b : β) (n : ℕ), n•(a + b) = n•a + n•b :=
@mul_pow (multiplicative β) _
attribute [to_additive add_monoid.add_smul] mul_pow
instance pow.is_monoid_hom (n : ℕ) : is_monoid_hom ((^ n) : α → α) :=
{ map_mul := λ _ _, mul_pow _ _ _, map_one := one_pow _ }
instance add_monoid.smul.is_add_monoid_hom (n : ℕ) : is_add_monoid_hom (add_monoid.smul n : β → β) :=
{ map_add := λ _ _, add_monoid.smul_add _ _ _, map_zero := add_monoid.smul_zero _ }
attribute [to_additive add_monoid.smul.is_add_monoid_hom] pow.is_monoid_hom
end comm_monoid
section group
variables [group α] {β : Type*} [add_group β]
section nat
@[simp] theorem inv_pow (a : α) (n : ℕ) : (a⁻¹)^n = (a^n)⁻¹ :=
by induction n with n ih; [exact one_inv.symm,
rw [pow_succ', pow_succ, ih, mul_inv_rev]]
@[simp] theorem add_monoid.neg_smul : ∀ (a : β) (n : ℕ), n•(-a) = -(n•a) :=
@inv_pow (multiplicative β) _
attribute [to_additive add_monoid.neg_smul] inv_pow
theorem pow_sub (a : α) {m n : ℕ} (h : m ≥ n) : a^(m - n) = a^m * (a^n)⁻¹ :=
have h1 : m - n + n = m, from nat.sub_add_cancel h,
have h2 : a^(m - n) * a^n = a^m, by rw [←pow_add, h1],
eq_mul_inv_of_mul_eq h2
theorem add_monoid.smul_sub : ∀ (a : β) {m n : ℕ}, m ≥ n → (m - n)•a = m•a - n•a :=
@pow_sub (multiplicative β) _
attribute [to_additive add_monoid.smul_sub] inv_pow
theorem pow_inv_comm (a : α) (m n : ℕ) : (a⁻¹)^m * a^n = a^n * (a⁻¹)^m :=
by rw inv_pow; exact inv_comm_of_comm (pow_mul_comm _ _ _)
theorem add_monoid.smul_neg_comm : ∀ (a : β) (m n : ℕ), m•(-a) + n•a = n•a + m•(-a) :=
@pow_inv_comm (multiplicative β) _
attribute [to_additive add_monoid.smul_neg_comm] pow_inv_comm
end nat
open int
/--
The power operation in a group. This extends `monoid.pow` to negative integers
with the definition `a^(-n) = (a^n)⁻¹`.
-/
def gpow (a : α) : ℤ → α
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
def gsmul (n : ℤ) (a : β) : β :=
@gpow (multiplicative β) _ a n
@[priority 10] instance group.has_pow : has_pow α ℤ := ⟨gpow⟩
local infix ` • `:70 := gsmul
local infix ` •ℕ `:70 := add_monoid.smul
@[simp] theorem gpow_coe_nat (a : α) (n : ℕ) : a ^ (n:ℤ) = a ^ n := rfl
@[simp] theorem gsmul_coe_nat (a : β) (n : ℕ) : (n:ℤ) • a = n •ℕ a := rfl
attribute [to_additive gsmul_coe_nat] gpow_coe_nat
@[simp] theorem gpow_of_nat (a : α) (n : ℕ) : a ^ of_nat n = a ^ n := rfl
@[simp] theorem gsmul_of_nat (a : β) (n : ℕ) : of_nat n • a = n •ℕ a := rfl
attribute [to_additive gsmul_of_nat] gpow_of_nat
@[simp] theorem gpow_neg_succ (a : α) (n : ℕ) : a ^ -[1+n] = (a ^ n.succ)⁻¹ := rfl
@[simp] theorem gsmul_neg_succ (a : β) (n : ℕ) : -[1+n] • a = - (n.succ •ℕ a) := rfl
attribute [to_additive gsmul_neg_succ] gpow_neg_succ
local attribute [ematch] le_of_lt
open nat
@[simp] theorem gpow_zero (a : α) : a ^ (0:ℤ) = 1 := rfl
@[simp] theorem zero_gsmul (a : β) : (0:ℤ) • a = 0 := rfl
attribute [to_additive zero_gsmul] gpow_zero
@[simp] theorem gpow_one (a : α) : a ^ (1:ℤ) = a := mul_one _
@[simp] theorem one_gsmul (a : β) : (1:ℤ) • a = a := add_zero _
attribute [to_additive one_gsmul] gpow_one
@[simp] theorem one_gpow : ∀ (n : ℤ), (1 : α) ^ n = 1
| (n : ℕ) := one_pow _
| -[1+ n] := show _⁻¹=(1:α), by rw [_root_.one_pow, one_inv]
@[simp] theorem gsmul_zero : ∀ (n : ℤ), n • (0 : β) = 0 :=
@one_gpow (multiplicative β) _
attribute [to_additive gsmul_zero] one_gpow
@[simp] theorem gpow_neg (a : α) : ∀ (n : ℤ), a ^ -n = (a ^ n)⁻¹
| (n+1:ℕ) := rfl
| 0 := one_inv.symm
| -[1+ n] := (inv_inv _).symm
@[simp] theorem neg_gsmul : ∀ (a : β) (n : ℤ), -n • a = -(n • a) :=
@gpow_neg (multiplicative β) _
attribute [to_additive neg_gsmul] gpow_neg
theorem gpow_neg_one (x : α) : x ^ (-1:ℤ) = x⁻¹ := congr_arg has_inv.inv $ pow_one x
theorem neg_one_gsmul (x : β) : (-1:ℤ) • x = -x := congr_arg has_neg.neg $ add_monoid.one_smul x
attribute [to_additive neg_one_gsmul] gpow_neg_one
theorem inv_gpow (a : α) : ∀n:ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) := inv_pow a n
| -[1+ n] := congr_arg has_inv.inv $ inv_pow a (n+1)
private lemma gpow_add_aux (a : α) (m n : nat) :
a ^ ((of_nat m) + -[1+n]) = a ^ of_nat m * a ^ -[1+n] :=
or.elim (nat.lt_or_ge m (nat.succ n))
(assume h1 : m < succ n,
have h2 : m ≤ n, from le_of_lt_succ h1,
suffices a ^ -[1+ n-m] = a ^ of_nat m * a ^ -[1+n],
by rwa [of_nat_add_neg_succ_of_nat_of_lt h1],
show (a ^ nat.succ (n - m))⁻¹ = a ^ of_nat m * a ^ -[1+n],
by rw [← succ_sub h2, pow_sub _ (le_of_lt h1), mul_inv_rev, inv_inv]; refl)
(assume : m ≥ succ n,
suffices a ^ (of_nat (m - succ n)) = (a ^ (of_nat m)) * (a ^ -[1+ n]),
by rw [of_nat_add_neg_succ_of_nat_of_ge]; assumption,
suffices a ^ (m - succ n) = a ^ m * (a ^ n.succ)⁻¹, from this,
by rw pow_sub; assumption)
theorem gpow_add (a : α) : ∀ (i j : ℤ), a ^ (i + j) = a ^ i * a ^ j
| (of_nat m) (of_nat n) := pow_add _ _ _
| (of_nat m) -[1+n] := gpow_add_aux _ _ _
| -[1+m] (of_nat n) := by rw [add_comm, gpow_add_aux,
gpow_neg_succ, gpow_of_nat, ← inv_pow, ← pow_inv_comm]
| -[1+m] -[1+n] :=
suffices (a ^ (m + succ (succ n)))⁻¹ = (a ^ m.succ)⁻¹ * (a ^ n.succ)⁻¹, from this,
by rw [← succ_add_eq_succ_add, add_comm, _root_.pow_add, mul_inv_rev]
theorem add_gsmul : ∀ (a : β) (i j : ℤ), (i + j) • a = i • a + j • a :=
@gpow_add (multiplicative β) _
theorem gpow_add_one (a : α) (i : ℤ) : a ^ (i + 1) = a ^ i * a :=
by rw [gpow_add, gpow_one]
theorem add_one_gsmul : ∀ (a : β) (i : ℤ), (i + 1) • a = i • a + a :=
@gpow_add_one (multiplicative β) _
attribute [to_additive add_one_gsmul] gpow_add_one
theorem gpow_one_add (a : α) (i : ℤ) : a ^ (1 + i) = a * a ^ i :=
by rw [gpow_add, gpow_one]
theorem one_add_gsmul : ∀ (a : β) (i : ℤ), (1 + i) • a = a + i • a :=
@gpow_one_add (multiplicative β) _
attribute [to_additive one_add_gsmul] gpow_one_add
theorem gpow_mul_comm (a : α) (i j : ℤ) : a ^ i * a ^ j = a ^ j * a ^ i :=
by rw [← gpow_add, ← gpow_add, add_comm]
theorem gsmul_add_comm : ∀ (a : β) (i j), i • a + j • a = j • a + i • a :=
@gpow_mul_comm (multiplicative β) _
attribute [to_additive gsmul_add_comm] gpow_mul_comm
theorem gpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ) (n : ℕ) := pow_mul _ _ _
| (m : ℕ) -[1+ n] := (gpow_neg _ (m * succ n)).trans $
show (a ^ (m * succ n))⁻¹ = _, by rw pow_mul; refl
| -[1+ m] (n : ℕ) := (gpow_neg _ (succ m * n)).trans $
show (a ^ (m.succ * n))⁻¹ = _, by rw [pow_mul, ← inv_pow]; refl
| -[1+ m] -[1+ n] := (pow_mul a (succ m) (succ n)).trans $
show _ = (_⁻¹^_)⁻¹, by rw [inv_pow, inv_inv]
theorem gsmul_mul' : ∀ (a : β) (m n : ℤ), m * n • a = n • (m • a) :=
@gpow_mul (multiplicative β) _
attribute [to_additive gsmul_mul'] gpow_mul
theorem gpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m :=
by rw [mul_comm, gpow_mul]
theorem gsmul_mul (a : β) (m n : ℤ) : m * n • a = m • (n • a) :=
by rw [mul_comm, gsmul_mul']
attribute [to_additive gsmul_mul] gpow_mul'
theorem gpow_bit0 (a : α) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n := gpow_add _ _ _
theorem bit0_gsmul (a : β) (n : ℤ) : bit0 n • a = n • a + n • a := gpow_add _ _ _
attribute [to_additive bit0_gsmul] gpow_bit0
theorem gpow_bit1 (a : α) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a :=
by rw [bit1, gpow_add]; simp [gpow_bit0]
theorem bit1_gsmul : ∀ (a : β) (n : ℤ), bit1 n • a = n • a + n • a + a :=
@gpow_bit1 (multiplicative β) _
attribute [to_additive bit1_gsmul] gpow_bit1
theorem gsmul_neg (a : β) (n : ℤ) : gsmul n (- a) = - gsmul n a :=
begin
induction n using int.induction_on with z ih z ih,
{ simp },
{ rw [add_comm] {occs := occurrences.pos [1]}, simp [add_gsmul, ih, -add_comm] },
{ rw [sub_eq_add_neg, add_comm] {occs := occurrences.pos [1]},
simp [ih, add_gsmul, neg_gsmul, -add_comm] }
end
attribute [to_additive gsmul_neg] gpow_neg
end group
namespace is_group_hom
variables {β : Type v} [group α] [group β] (f : α → β) [is_group_hom f]
theorem map_pow (a : α) (n : ℕ) : f (a ^ n) = f a ^ n :=
is_monoid_hom.map_pow f a n
theorem map_gpow (a : α) (n : ℤ) : f (a ^ n) = f a ^ n :=
by cases n; [exact is_group_hom.map_pow f _ _,
exact (is_group_hom.map_inv f _).trans (congr_arg _ $ is_group_hom.map_pow f _ _)]
end is_group_hom
namespace is_add_group_hom
variables {β : Type v} [add_group α] [add_group β] (f : α → β) [is_add_group_hom f]
theorem map_smul (a : α) (n : ℕ) : f (n • a) = n • f a :=
is_add_monoid_hom.map_smul f a n
theorem map_gsmul (a : α) (n : ℤ) : f (gsmul n a) = gsmul n (f a) :=
@is_group_hom.map_gpow (multiplicative α) (multiplicative β) _ _ f _ a n
end is_add_group_hom
local infix ` •ℤ `:70 := gsmul
section comm_monoid
variables [comm_group α] {β : Type*} [add_comm_group β]
theorem mul_gpow (a b : α) : ∀ n:ℤ, (a * b)^n = a^n * b^n
| (n : ℕ) := mul_pow a b n
| -[1+ n] := show _⁻¹=_⁻¹*_⁻¹, by rw [mul_pow, mul_inv_rev, mul_comm]
theorem gsmul_add : ∀ (a b : β) (n : ℤ), n •ℤ (a + b) = n •ℤ a + n •ℤ b :=
@mul_gpow (multiplicative β) _
attribute [to_additive gsmul_add] mul_gpow
theorem gsmul_sub : ∀ (a b : β) (n : ℤ), gsmul n (a - b) = gsmul n a - gsmul n b :=
by simp [gsmul_add, gsmul_neg]
instance gpow.is_group_hom (n : ℤ) : is_group_hom ((^ n) : α → α) :=
⟨λ _ _, mul_gpow _ _ n⟩
instance gsmul.is_add_group_hom (n : ℤ) : is_add_group_hom (gsmul n : β → β) :=
⟨λ _ _, gsmul_add _ _ n⟩
attribute [to_additive gsmul.is_add_group_hom] gpow.is_group_hom
end comm_monoid
section group
@[instance]
theorem is_add_group_hom.gsmul
{α β} [add_group α] [add_comm_group β] (f : α → β) [is_add_group_hom f] (z : ℤ) :
is_add_group_hom (λa, gsmul z (f a)) :=
⟨assume a b, by rw [is_add_group_hom.map_add f, gsmul_add]⟩
end group
@[simp] lemma with_bot.coe_smul [add_monoid α] (a : α) (n : ℕ) :
((add_monoid.smul n a : α) : with_bot α) = add_monoid.smul n a :=
by induction n; simp [*, succ_smul]; refl
theorem add_monoid.smul_eq_mul' [semiring α] (a : α) (n : ℕ) : n • a = a * n :=
by induction n with n ih; [rw [add_monoid.zero_smul, nat.cast_zero, mul_zero],
rw [succ_smul', ih, nat.cast_succ, mul_add, mul_one]]
theorem add_monoid.smul_eq_mul [semiring α] (n : ℕ) (a : α) : n • a = n * a :=
by rw [add_monoid.smul_eq_mul', nat.mul_cast_comm]
theorem add_monoid.mul_smul_left [semiring α] (a b : α) (n : ℕ) : n • (a * b) = a * (n • b) :=
by rw [add_monoid.smul_eq_mul', add_monoid.smul_eq_mul', mul_assoc]
theorem add_monoid.mul_smul_assoc [semiring α] (a b : α) (n : ℕ) : n • (a * b) = n • a * b :=
by rw [add_monoid.smul_eq_mul, add_monoid.smul_eq_mul, mul_assoc]
lemma zero_pow [semiring α] : ∀ {n : ℕ}, 0 < n → (0 : α) ^ n = 0
| (n+1) _ := zero_mul _
@[simp] theorem nat.cast_pow [semiring α] (n m : ℕ) : (↑(n ^ m) : α) = ↑n ^ m :=
by induction m with m ih; [exact nat.cast_one, rw [nat.pow_succ, pow_succ', nat.cast_mul, ih]]
@[simp] theorem int.coe_nat_pow (n m : ℕ) : ((n ^ m : ℕ) : ℤ) = n ^ m :=
by induction m with m ih; [exact int.coe_nat_one, rw [nat.pow_succ, pow_succ', int.coe_nat_mul, ih]]
theorem int.nat_abs_pow (n : ℤ) (k : ℕ) : int.nat_abs (n ^ k) = (int.nat_abs n) ^ k :=
by induction k with k ih; [refl, rw [pow_succ', int.nat_abs_mul, nat.pow_succ, ih]]
theorem is_semiring_hom.map_pow {β} [semiring α] [semiring β]
(f : α → β) [is_semiring_hom f] (x : α) (n : ℕ) : f (x ^ n) = f x ^ n :=
by induction n with n ih; [exact is_semiring_hom.map_one f,
rw [pow_succ, pow_succ, is_semiring_hom.map_mul f, ih]]
theorem neg_one_pow_eq_or {R} [ring R] : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1
| 0 := or.inl rfl
| (n+1) := (neg_one_pow_eq_or n).swap.imp
(λ h, by rw [pow_succ, h, neg_one_mul, neg_neg])
(λ h, by rw [pow_succ, h, mul_one])
lemma pow_dvd_pow [comm_semiring α] (a : α) {m n : ℕ} (h : m ≤ n) :
a ^ m ∣ a ^ n := ⟨a ^ (n - m), by rw [← pow_add, nat.add_sub_cancel' h]⟩
theorem gsmul_eq_mul [ring α] (a : α) : ∀ n, n •ℤ a = n * a
| (n : ℕ) := add_monoid.smul_eq_mul _ _
| -[1+ n] := show -(_•_)=-_*_, by rw [neg_mul_eq_neg_mul_symm, add_monoid.smul_eq_mul, nat.cast_succ]
theorem gsmul_eq_mul' [ring α] (a : α) (n : ℤ) : n •ℤ a = a * n :=
by rw [gsmul_eq_mul, int.mul_cast_comm]
theorem mul_gsmul_left [ring α] (a b : α) (n : ℤ) : n •ℤ (a * b) = a * (n •ℤ b) :=
by rw [gsmul_eq_mul', gsmul_eq_mul', mul_assoc]
theorem mul_gsmul_assoc [ring α] (a b : α) (n : ℤ) : n •ℤ (a * b) = n •ℤ a * b :=
by rw [gsmul_eq_mul, gsmul_eq_mul, mul_assoc]
@[simp] theorem int.cast_pow [ring α] (n : ℤ) (m : ℕ) : (↑(n ^ m) : α) = ↑n ^ m :=
by induction m with m ih; [exact int.cast_one,
rw [pow_succ, pow_succ, int.cast_mul, ih]]
lemma neg_one_pow_eq_pow_mod_two [ring α] {n : ℕ} : (-1 : α) ^ n = -1 ^ (n % 2) :=
by rw [← nat.mod_add_div n 2, pow_add, pow_mul]; simp [pow_two]
theorem pow_eq_zero [domain α] {x : α} {n : ℕ} (H : x^n = 0) : x = 0 :=
begin
induction n with n ih,
{ rw pow_zero at H,
rw [← mul_one x, H, mul_zero] },
exact or.cases_on (mul_eq_zero.1 H) id ih
end
theorem pow_ne_zero [domain α] {a : α} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 :=
mt pow_eq_zero h
@[simp] theorem one_div_pow [division_ring α] {a : α} (ha : a ≠ 0) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n :=
by induction n with n ih; [exact (div_one _).symm,
rw [pow_succ', ih, division_ring.one_div_mul_one_div (pow_ne_zero _ ha) ha]]; refl
@[simp] theorem division_ring.inv_pow [division_ring α] {a : α} (ha : a ≠ 0) (n : ℕ) : a⁻¹ ^ n = (a ^ n)⁻¹ :=
by simpa only [inv_eq_one_div] using one_div_pow ha n
@[simp] theorem div_pow [field α] (a : α) {b : α} (hb : b ≠ 0) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n :=
by rw [div_eq_mul_one_div, mul_pow, one_div_pow hb, ← div_eq_mul_one_div]
theorem add_monoid.smul_nonneg [ordered_comm_monoid α] {a : α} (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ n • a
| 0 := le_refl _
| (n+1) := add_nonneg' H (add_monoid.smul_nonneg n)
lemma pow_abs [decidable_linear_ordered_comm_ring α] (a : α) (n : ℕ) : (abs a)^n = abs (a^n) :=
by induction n with n ih; [exact (abs_one).symm,
rw [pow_succ, pow_succ, ih, abs_mul]]
lemma inv_pow' [discrete_field α] (a : α) (n : ℕ) : (a ^ n)⁻¹ = a⁻¹ ^ n :=
by induction n; simp [*, pow_succ, mul_inv', mul_comm]
lemma pow_inv [division_ring α] (a : α) : ∀ n : ℕ, a ≠ 0 → (a^n)⁻¹ = (a⁻¹)^n
| 0 ha := inv_one
| (n+1) ha := by rw [pow_succ, pow_succ', mul_inv_eq (pow_ne_zero _ ha) ha, pow_inv _ ha]
namespace add_monoid
variable [ordered_comm_monoid α]
theorem smul_le_smul {a : α} {n m : ℕ} (ha : 0 ≤ a) (h : n ≤ m) : n • a ≤ m • a :=
let ⟨k, hk⟩ := nat.le.dest h in
calc n • a = n • a + 0 : (add_zero _).symm
... ≤ n • a + k • a : add_le_add_left' (smul_nonneg ha _)
... = m • a : by rw [← hk, add_smul]
lemma smul_le_smul_of_le_right {a b : α} (hab : a ≤ b) : ∀ i : ℕ, i • a ≤ i • b
| 0 := by simp
| (k+1) := add_le_add' hab (smul_le_smul_of_le_right _)
end add_monoid
section linear_ordered_semiring
variable [linear_ordered_semiring α]
theorem pow_pos {a : α} (H : 0 < a) : ∀ (n : ℕ), 0 < a ^ n
| 0 := zero_lt_one
| (n+1) := mul_pos H (pow_pos _)
theorem pow_nonneg {a : α} (H : 0 ≤ a) : ∀ (n : ℕ), 0 ≤ a ^ n
| 0 := zero_le_one
| (n+1) := mul_nonneg H (pow_nonneg _)
theorem pow_lt_pow_of_lt_left {x y : α} {n : ℕ} (Hxy : x < y) (Hxpos : 0 ≤ x) (Hnpos : 0 < n) : x ^ n < y ^ n :=
begin
cases lt_or_eq_of_le Hxpos,
{ rw ←nat.sub_add_cancel Hnpos,
induction (n - 1), { simpa only [pow_one] },
rw [pow_add, pow_add, nat.succ_eq_add_one, pow_one, pow_one],
apply mul_lt_mul ih (le_of_lt Hxy) h (le_of_lt (pow_pos (lt_trans h Hxy) _)) },
{ rw [←h, zero_pow Hnpos], apply pow_pos (by rwa ←h at Hxy : 0 < y),}
end
theorem pow_right_inj {x y : α} {n : ℕ} (Hxpos : 0 ≤ x) (Hypos : 0 ≤ y) (Hnpos : 0 < n) (Hxyn : x ^ n = y ^ n) : x = y :=
begin
rcases lt_trichotomy x y with hxy | rfl | hyx,
{ exact absurd Hxyn (ne_of_lt (pow_lt_pow_of_lt_left hxy Hxpos Hnpos)) },
{ refl },
{ exact absurd Hxyn (ne_of_gt (pow_lt_pow_of_lt_left hyx Hypos Hnpos)) },
end
theorem one_le_pow_of_one_le {a : α} (H : 1 ≤ a) : ∀ (n : ℕ), 1 ≤ a ^ n
| 0 := le_refl _
| (n+1) := by simpa only [mul_one] using mul_le_mul H (one_le_pow_of_one_le n)
zero_le_one (le_trans zero_le_one H)
theorem pow_ge_one_add_mul {a : α} (H : a ≥ 0) :
∀ (n : ℕ), 1 + n • a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| (n+1) := begin
rw [pow_succ', succ_smul'],
refine le_trans _ (mul_le_mul_of_nonneg_right
(pow_ge_one_add_mul n) (add_nonneg zero_le_one H)),
rw [mul_add, mul_one, ← add_assoc, add_le_add_iff_left],
simpa only [one_mul] using mul_le_mul_of_nonneg_right
((le_add_iff_nonneg_right 1).2 (add_monoid.smul_nonneg H n)) H
end
theorem pow_le_pow {a : α} {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m :=
let ⟨k, hk⟩ := nat.le.dest h in
calc a ^ n = a ^ n * 1 : (mul_one _).symm
... ≤ a ^ n * a ^ k : mul_le_mul_of_nonneg_left
(one_le_pow_of_one_le ha _)
(pow_nonneg (le_trans zero_le_one ha) _)
... = a ^ m : by rw [←hk, pow_add]
lemma pow_lt_pow {a : α} {n m : ℕ} (h : 1 < a) (h2 : n < m) : a ^ n < a ^ m :=
begin
have h' : 1 ≤ a := le_of_lt h,
have h'' : 0 < a := lt_trans zero_lt_one h,
cases m, cases h2, rw [pow_succ, ←one_mul (a ^ n)],
exact mul_lt_mul h (pow_le_pow h' (nat.le_of_lt_succ h2)) (pow_pos h'' _) (le_of_lt h'')
end
lemma pow_le_pow_of_le_left {a b : α} (ha : 0 ≤ a) (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i
| 0 := by simp
| (k+1) := mul_le_mul hab (pow_le_pow_of_le_left _) (pow_nonneg ha _) (le_trans ha hab)
lemma lt_of_pow_lt_pow {a b : α} (n : ℕ) (hb : 0 ≤ b) (h : a ^ n < b ^ n) : a < b :=
lt_of_not_ge $ λ hn, not_lt_of_ge (pow_le_pow_of_le_left hb hn _) h
private lemma pow_lt_pow_of_lt_one_aux {a : α} (h : 0 < a) (ha : a < 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k + 1) < a ^ i
| 0 := begin simp, rw ←one_mul (a^i), exact mul_lt_mul ha (le_refl _) (pow_pos h _) zero_le_one end
| (k+1) :=
begin
rw ←one_mul (a^i),
apply mul_lt_mul ha _ _ zero_le_one,
{ apply le_of_lt, apply pow_lt_pow_of_lt_one_aux },
{ show 0 < a ^ (i + (k + 1) + 0), apply pow_pos h }
end
private lemma pow_le_pow_of_le_one_aux {a : α} (h : 0 ≤ a) (ha : a ≤ 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k) ≤ a ^ i
| 0 := by simp
| (k+1) := by rw [←add_assoc, ←one_mul (a^i)];
exact mul_le_mul ha (pow_le_pow_of_le_one_aux _) (pow_nonneg h _) zero_le_one
lemma pow_lt_pow_of_lt_one {a : α} (h : 0 < a) (ha : a < 1)
{i j : ℕ} (hij : i < j) : a ^ j < a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt hij in
by rw hk; exact pow_lt_pow_of_lt_one_aux h ha _ _
lemma pow_le_pow_of_le_one {a : α} (h : 0 ≤ a) (ha : a ≤ 1)
{i j : ℕ} (hij : i ≤ j) : a ^ j ≤ a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hij in
by rw hk; exact pow_le_pow_of_le_one_aux h ha _ _
lemma pow_le_one {x : α} : ∀ (n : ℕ) (h0 : 0 ≤ x) (h1 : x ≤ 1), x ^ n ≤ 1
| 0 h0 h1 := le_refl (1 : α)
| (n+1) h0 h1 := mul_le_one h1 (pow_nonneg h0 _) (pow_le_one n h0 h1)
end linear_ordered_semiring
theorem pow_two_nonneg [linear_ordered_ring α] (a : α) : 0 ≤ a ^ 2 :=
by rw pow_two; exact mul_self_nonneg _
theorem pow_ge_one_add_sub_mul [linear_ordered_ring α]
{a : α} (H : a ≥ 1) (n : ℕ) : 1 + n • (a - 1) ≤ a ^ n :=
by simpa only [add_sub_cancel'_right] using pow_ge_one_add_mul (sub_nonneg.2 H) n
namespace int
lemma units_pow_two (u : units ℤ) : u ^ 2 = 1 :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
lemma units_pow_eq_pow_mod_two (u : units ℤ) (n : ℕ) : u ^ n = u ^ (n % 2) :=
by conv {to_lhs, rw ← nat.mod_add_div n 2}; rw [pow_add, pow_mul, units_pow_two, one_pow, mul_one]
end int
@[simp] lemma neg_square {α} [ring α] (z : α) : (-z)^2 = z^2 :=
by simp [pow, monoid.pow]
lemma div_sq_cancel {α} [field α] {a : α} (ha : a ≠ 0) (b : α) : a^2 * b / a = a * b :=
by rw [pow_two, mul_assoc, mul_div_cancel_left _ ha]
|
5dd849c46f6537ef23edc219dde4244c7715d1b8 | 4da0c8e61fcd6ec3f3be47ee14a038850c03d0c3 | /src/language.lean | f250c54c8e16302cdd2207ee46f335bf630f3a8a | [
"Apache-2.0"
] | permissive | bbentzen/mpl | fcbea60204bc8fd64667e0f76a5cebf4b67fb6ca | bb5066ec51fa11a4b66f440c4f6c9a3d8fb2e0de | refs/heads/master | 1,625,175,849,308 | 1,624,207,634,000 | 1,624,207,634,000 | 142,774,375 | 9 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 577 | lean | /-
Copyright (c) 2018 Bruno Bentzen. All rights reserved.
Released under the Apache License 2.0 (see "License");
Author: Bruno Bentzen
-/
variable σ : nat
/- language definition -/
inductive form : Type
| atom : fin σ → form
| bot : form
| impl : form → form → form
| box : form → form
prefix `#` := form.atom
notation `⊥` := form.bot _
infix `⊃` := form.impl
notation `~`:40 p := form.impl p (form.bot _)
notation p `&` q := ~(p ⊃ ~q)
notation p `∨` q := ~(~p & ~q)
prefix `◻`:80 := form.box
prefix `◇`:80 := λ p, ~(◻ (~ p)) |
c9959e45571a16862cd27e6e2cb295e380c51c03 | 3aad12fe82645d2d3173fbedc2e5c2ba945a4d75 | /src/category/traversable/nursery.lean | c76692860f212be89f1b6590af36539f35492d3d | [] | no_license | seanpm2001/LeanProver-Community_MathLIB-Nursery | 4f88d539cb18d73a94af983092896b851e6640b5 | 0479b31fa5b4d39f41e89b8584c9f5bf5271e8ec | refs/heads/master | 1,688,730,786,645 | 1,572,070,026,000 | 1,572,070,026,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,873 | lean |
import data.list.basic
import category.traversable.instances
universes u v
def foldl (α : Type u) (β : Type v) := α → α
def foldr (α : Type u) (β : Type v) := α → α
instance {α} : applicative (foldr α) :=
{ pure := λ _ _, id,
seq := λ _ _ f x, f ∘ x }
instance {α} : applicative (foldl α) :=
{ pure := λ _ _, id,
seq := λ _ _ f x, x ∘ f }
instance {α} : is_lawful_applicative (foldr α) :=
by refine { .. }; intros; refl
instance {α} : is_lawful_applicative (foldl α) :=
by refine { .. }; intros; refl
def foldr.eval {α β} (x : foldr α β) : α → α := x
def foldl.eval {α β} (x : foldl α β) : α → α := x
def foldl.cons {α β} (x : α) : foldl (list α) β :=
list.cons x
def foldr.cons {α β} (x : α) : foldr (list α) β :=
list.cons x
def foldl.cons' {α} (x : α) : foldl (list α) punit :=
list.cons x
def foldl.lift {α} (x : α → α) : foldl α punit := x
def foldr.lift {α} (x : α → α) : foldr α punit := x
namespace traversable
variables {t : Type u → Type u} [traversable t]
def to_list {α} (x : t α) : list α :=
(foldl.eval (traverse foldl.cons' x) []).reverse
def foldl {α β} (f : α → β → α) (x : α) (xs : t β) : α :=
foldl.eval (traverse (foldl.lift ∘ flip f) xs) x
def foldr {α β} (f : α → β → β) (x : β) (xs : t α) : β :=
foldr.eval (traverse (foldr.lift ∘ f) xs) x
open ulift
def length {α} (xs : t α) : ℕ :=
down $ foldl (λ l _, up $ 1+down l) (up 0) xs
lemma list_foldl_eq {α β} (f : α → β → α) (x : α) (xs : list β) :
foldl f x xs = list.foldl f x xs :=
begin
simp [foldl,foldl.eval,traverse,foldl.lift,(∘),flip,list.foldl],
symmetry,
induction xs generalizing x, refl,
simp [list.traverse,list.foldl,xs_ih,(<*>),(<$>)],
end
lemma list_foldr_eq {α β} (f : α → β → β) (x : β) (xs : list α) :
foldr f x xs = list.foldr f x xs :=
begin
simp [foldr,foldr.eval,traverse,foldr.lift,(∘),flip,list.foldr],
symmetry, induction xs, refl,
simp [list.traverse,list.foldl,xs_ih,(<*>),(<$>)],
end
end traversable
open traversable
lemma list.to_list_eq_self {α} (xs : list α) :
to_list xs = xs :=
begin
simp [traversable.to_list,traverse,foldl.eval],
suffices : ∀ s, (list.traverse foldl.cons' xs s).reverse = s.reverse ++ xs,
{ rw [this], simp },
induction xs; intros s;
simp [list.traverse,pure,(<*>),(<$>),foldl.cons',*],
end
lemma list.length_to_list {α} (xs : list α) :
length (to_list xs) = xs.length :=
by { rw [length,list_foldl_eq,list.to_list_eq_self,← list.foldr_reverse,← list.length_reverse],
generalize : list.reverse xs = l,
induction l; simp *, }
#check @traverse
instance {α : Type u} : traversable (prod.{u u} α) :=
{ map := λ β γ f (x : α × β), prod.mk x.1 $ f x.2,
traverse := λ m _ β γ f (x : α × β), by exactI prod.mk x.1 <$> f x.2 }
|
c1565974c4d0258a24227f67a92cb29c7590530e | dc253be9829b840f15d96d986e0c13520b085033 | /coind_colim.hlean | 7924beffaea7a3f380ce9edac0999a861ec00ee9 | [
"Apache-2.0"
] | permissive | cmu-phil/Spectral | 4ce68e5c1ef2a812ffda5260e9f09f41b85ae0ea | 3b078f5f1de251637decf04bd3fc8aa01930a6b3 | refs/heads/master | 1,685,119,195,535 | 1,684,169,772,000 | 1,684,169,772,000 | 46,450,197 | 42 | 13 | null | 1,505,516,767,000 | 1,447,883,921,000 | Lean | UTF-8 | Lean | false | false | 6,369 | hlean | -- author: Floris van Doorn
import .colimit.seq_colim
open nat seq_colim eq equiv is_equiv is_trunc function
namespace seq_colim
variables {A : ℕ → Type} {f : seq_diagram A}
definition ι0 [reducible] : A 0 → seq_colim f :=
ι f
variable (f)
definition ι0' [reducible] : A 0 → seq_colim f :=
ι f
definition glue0 (a : A 0) : shift_down f (ι0 (f a)) = ι f a :=
glue f a
definition rec_coind_point {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), seq_colim f → Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f (ι0 a))
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)),
P (shift_diag f) x → P f (shift_down f x))
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0),
pathover (P f) (Ps f (ι0 (f a)) !P0) (proof glue f a qed) (P0 f a))
(n : ℕ) : Π{A : ℕ → Type} {f : seq_diagram A} (a : A n), P f (ι f a) :=
begin
induction n with n IH: intro A f a,
{ exact P0 f a },
{ exact Ps f (ι _ a) (IH a) }
end
definition rec_coind_point_succ {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), seq_colim f → Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f (ι0 a))
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)),
P (shift_diag f) x → P f (shift_down f x))
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0),
pathover (P f) (Ps f (ι0 (f a)) !P0) _ (P0 f a))
(n : ℕ) {A : ℕ → Type} {f : seq_diagram A} (a : A (succ n)) :
rec_coind_point P0 Ps Pe (succ n) a = Ps f (ι _ a) (rec_coind_point P0 Ps Pe n a) :=
by reflexivity
definition rec_coind {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), seq_colim f → Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f (ι0 a))
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)),
P (shift_diag f) x → P f (shift_down f x))
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0),
pathover (P f) (Ps f (ι0 (f a)) !P0) (proof glue f a qed) (P0 f a))
{A : ℕ → Type} {f : seq_diagram A} (x : seq_colim f) : P f x :=
begin
induction x,
{ exact rec_coind_point P0 Ps Pe n a },
{ revert A f a, induction n with n IH: intro A f a,
{ exact Pe f a },
{ rewrite [rec_coind_point_succ _ _ _ n, rec_coind_point_succ],
note p := IH _ (shift_diag f) a,
refine change_path _ (pathover_ap _ _ (apo (Ps f) p)),
exact !elim_glue
}},
end
definition rec_coind_pt2 {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), seq_colim f → Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f (ι0 a))
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)),
P (shift_diag f) x → P f (shift_down f x))
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0),
pathover (P f) (Ps f (ι0 (f a)) !P0) _ (P0 f a))
{A : ℕ → Type} {f : seq_diagram A} (x : seq_colim (shift_diag f))
: rec_coind P0 Ps Pe (shift_down f x) = Ps f x (rec_coind P0 Ps Pe x) :=
begin
induction x,
{ reflexivity },
{ apply eq_pathover_dep,
apply hdeg_squareover, esimp,
refine apd_compose2 (rec_coind P0 Ps Pe) _ _ ⬝ _ ⬝ (apd_compose1 (Ps f) _ _)⁻¹,
exact sorry
--refine ap (λx, pathover_of_pathover_ap _ _ (x)) _ ⬝ _ ,
}
end
definition elim_coind_point {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f)
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)), P (shift_diag f) → P f)
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0), Ps f (ι0 (f a)) (P0 _ (f a)) = P0 f a)
(n : ℕ) : Π{A : ℕ → Type} (f : seq_diagram A) (a : A n), P f :=
begin
induction n with n IH: intro A f a,
{ exact P0 f a },
{ exact Ps f (ι _ a) (IH _ a) }
end
definition elim_coind_point_succ {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f)
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)), P (shift_diag f) → P f)
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0), Ps f (ι0 (f a)) (P0 _ (f a)) = P0 f a)
(n : ℕ) {A : ℕ → Type} {f : seq_diagram A} (a : A (succ n)) :
elim_coind_point P0 Ps Pe (succ n) f a =
Ps f (ι _ a) (elim_coind_point P0 Ps Pe n (shift_diag f) a) :=
by reflexivity
definition elim_coind_path {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f)
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)), P (shift_diag f) → P f)
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0), Ps f (ι0 (f a)) (P0 _ (f a)) = P0 f a)
(n : ℕ) : Π{A : ℕ → Type} (f : seq_diagram A) (a : A n),
elim_coind_point P0 Ps Pe (succ n) f (f a) = elim_coind_point P0 Ps Pe n f a :=
begin
induction n with n IH: intro A f a,
{ exact Pe f a },
{ rewrite [elim_coind_point_succ _ _ _ n, elim_coind_point_succ],
note p := IH (shift_diag f) a,
refine ap011 (Ps f) !glue p }
end
definition elim_coind {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f)
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)), P (shift_diag f) → P f)
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0), Ps f (ι0 (f a)) (P0 _ (f a)) = P0 f a)
{A : ℕ → Type} {f : seq_diagram A} (x : seq_colim f) : P f :=
begin
induction x,
{ exact elim_coind_point P0 Ps Pe n f a },
{ exact elim_coind_path P0 Ps Pe n f a },
end
definition elim_coind_pt2 {P : Π⦃A : ℕ → Type⦄ (f : seq_diagram A), Type}
(P0 : Π⦃A⦄ (f : seq_diagram A) (a : A 0), P f)
(Ps : Π⦃A⦄ (f : seq_diagram A) (x : seq_colim (shift_diag f)), P (shift_diag f) → P f)
(Pe : Π⦃A⦄ (f : seq_diagram A) (a : A 0), Ps f (ι0 (f a)) (P0 _ (f a)) = P0 f a)
{A : ℕ → Type} {f : seq_diagram A} (x : seq_colim (shift_diag f))
: elim_coind P0 Ps Pe (shift_down f x) = Ps f x (elim_coind P0 Ps Pe x) :=
begin
induction x,
{ reflexivity },
{ apply eq_pathover, apply hdeg_square,
refine ap_compose (elim_coind P0 Ps Pe) _ _ ⬝ _ ⬝ (ap_eq_ap011 (Ps f) _ _ _)⁻¹,
refine ap02 _ !elim_glue ⬝ !elim_glue ⬝ ap011 (ap011 _) !ap_id⁻¹ !elim_glue⁻¹ }
end
end seq_colim
|
fee082f26a26a573a168538053eb0d7127295c7d | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/tactic/linarith.lean | e8717abd4ebbe787ce469554e150db6ce71f94fd | [
"Apache-2.0"
] | permissive | roro47/mathlib | 761fdc002aef92f77818f3fef06bf6ec6fc1a28e | 80aa7d52537571a2ca62a3fdf71c9533a09422cf | refs/heads/master | 1,599,656,410,625 | 1,573,649,488,000 | 1,573,649,488,000 | 221,452,951 | 0 | 0 | Apache-2.0 | 1,573,647,693,000 | 1,573,647,692,000 | null | UTF-8 | Lean | false | false | 33,000 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
-/
import tactic.ring data.nat.gcd data.list.basic meta.rb_map data.tree
/-!
A tactic for discharging linear arithmetic goals using Fourier-Motzkin elimination.
`linarith` is (in principle) complete for ℚ and ℝ. It is not complete for non-dense orders, i.e. ℤ.
@TODO: investigate storing comparisons in a list instead of a set, for possible efficiency gains
@TODO: delay proofs of denominator normalization and nat casting until after contradiction is found
-/
meta def nat.to_pexpr : ℕ → pexpr
| 0 := ``(0)
| 1 := ``(1)
| n := if n % 2 = 0 then ``(bit0 %%(nat.to_pexpr (n/2))) else ``(bit1 %%(nat.to_pexpr (n/2)))
open native
namespace linarith
section lemmas
lemma int.coe_nat_bit0 (n : ℕ) : (↑(bit0 n : ℕ) : ℤ) = bit0 (↑n : ℤ) := by simp [bit0]
lemma int.coe_nat_bit1 (n : ℕ) : (↑(bit1 n : ℕ) : ℤ) = bit1 (↑n : ℤ) := by simp [bit1, bit0]
lemma int.coe_nat_bit0_mul (n : ℕ) (x : ℕ) : (↑(bit0 n * x) : ℤ) = (↑(bit0 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_bit1_mul (n : ℕ) (x : ℕ) : (↑(bit1 n * x) : ℤ) = (↑(bit1 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_one_mul (x : ℕ) : (↑(1 * x) : ℤ) = 1 * (↑x : ℤ) := by simp
lemma int.coe_nat_zero_mul (x : ℕ) : (↑(0 * x) : ℤ) = 0 * (↑x : ℤ) := by simp
lemma int.coe_nat_mul_bit0 (n : ℕ) (x : ℕ) : (↑(x * bit0 n) : ℤ) = (↑x : ℤ) * (↑(bit0 n) : ℤ) := by simp
lemma int.coe_nat_mul_bit1 (n : ℕ) (x : ℕ) : (↑(x * bit1 n) : ℤ) = (↑x : ℤ) * (↑(bit1 n) : ℤ) := by simp
lemma int.coe_nat_mul_one (x : ℕ) : (↑(x * 1) : ℤ) = (↑x : ℤ) * 1 := by simp
lemma int.coe_nat_mul_zero (x : ℕ) : (↑(x * 0) : ℤ) = (↑x : ℤ) * 0 := by simp
lemma nat_eq_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 = n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 = z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_eq_coe_nat_iff]
lemma nat_le_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 ≤ n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 ≤ z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_le]
lemma nat_lt_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 < n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 < z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_lt]
lemma eq_of_eq_of_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b = 0) : a + b = 0 :=
by simp *
lemma le_of_eq_of_le {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b ≤ 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_eq_of_lt {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b < 0) : a + b < 0 :=
by simp *
lemma le_of_le_of_eq {α} [ordered_semiring α] {a b : α} (ha : a ≤ 0) (hb : b = 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_lt_of_eq {α} [ordered_semiring α] {a b : α} (ha : a < 0) (hb : b = 0) : a + b < 0 :=
by simp *
lemma mul_neg {α} [ordered_ring α] {a b : α} (ha : a < 0) (hb : b > 0) : b * a < 0 :=
have (-b)*a > 0, from mul_pos_of_neg_of_neg (neg_neg_of_pos hb) ha,
neg_of_neg_pos (by simpa)
lemma mul_nonpos {α} [ordered_ring α] {a b : α} (ha : a ≤ 0) (hb : b > 0) : b * a ≤ 0 :=
have (-b)*a ≥ 0, from mul_nonneg_of_nonpos_of_nonpos (le_of_lt (neg_neg_of_pos hb)) ha,
(by simpa)
lemma mul_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b > 0) : b * a = 0 :=
by simp *
lemma eq_of_not_lt_of_not_gt {α} [linear_order α] (a b : α) (h1 : ¬ a < b) (h2 : ¬ b < a) : a = b :=
le_antisymm (le_of_not_gt h2) (le_of_not_gt h1)
lemma add_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 + e2) = t1 + t2 := by simp [left_distrib, *]
lemma sub_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 - e2) = t1 - t2 := by simp [left_distrib, *]
lemma neg_subst {α} [ring α] {n e t : α} (h1 : n * e = t) : n * (-e) = -t := by simp *
private meta def apnn : tactic unit := `[norm_num]
lemma mul_subst {α} [comm_ring α] {n1 n2 k e1 e2 t1 t2 : α} (h1 : n1 * e1 = t1) (h2 : n2 * e2 = t2)
(h3 : n1*n2 = k . apnn) : k * (e1 * e2) = t1 * t2 :=
have h3 : n1 * n2 = k, from h3,
by rw [←h3, mul_comm n1, mul_assoc n2, ←mul_assoc n1, h1, ←mul_assoc n2, mul_comm n2, mul_assoc, h2] -- OUCH
lemma div_subst {α} [field α] {n1 n2 k e1 e2 t1 : α} (h1 : n1 * e1 = t1) (h2 : n2 / e2 = 1) (h3 : n1*n2 = k) :
k * (e1 / e2) = t1 :=
by rw [←h3, mul_assoc, mul_div_comm, h2, ←mul_assoc, h1, mul_comm, one_mul]
end lemmas
section datatypes
@[derive decidable_eq]
inductive ineq
| eq | le | lt
open ineq
def ineq.max : ineq → ineq → ineq
| eq a := a
| le a := a
| lt a := lt
def ineq.is_lt : ineq → ineq → bool
| eq le := tt
| eq lt := tt
| le lt := tt
| _ _ := ff
def ineq.to_string : ineq → string
| eq := "="
| le := "≤"
| lt := "<"
instance : has_to_string ineq := ⟨ineq.to_string⟩
/--
The main datatype for FM elimination.
Variables are represented by natural numbers, each of which has an integer coefficient.
Index 0 is reserved for constants, i.e. `coeffs.find 0` is the coefficient of 1.
The represented term is coeffs.keys.sum (λ i, coeffs.find i * Var[i]).
str determines the direction of the comparison -- is it < 0, ≤ 0, or = 0?
-/
meta structure comp :=
(str : ineq)
(coeffs : rb_map ℕ int)
meta instance : inhabited comp := ⟨⟨ineq.eq, mk_rb_map⟩⟩
meta inductive comp_source
| assump : ℕ → comp_source
| add : comp_source → comp_source → comp_source
| scale : ℕ → comp_source → comp_source
meta def comp_source.flatten : comp_source → rb_map ℕ ℕ
| (comp_source.assump n) := mk_rb_map.insert n 1
| (comp_source.add c1 c2) := (comp_source.flatten c1).add (comp_source.flatten c2)
| (comp_source.scale n c) := (comp_source.flatten c).map (λ v, v * n)
meta def comp_source.to_string : comp_source → string
| (comp_source.assump e) := to_string e
| (comp_source.add c1 c2) := comp_source.to_string c1 ++ " + " ++ comp_source.to_string c2
| (comp_source.scale n c) := to_string n ++ " * " ++ comp_source.to_string c
meta instance comp_source.has_to_format : has_to_format comp_source :=
⟨λ a, comp_source.to_string a⟩
meta structure pcomp :=
(c : comp)
(src : comp_source)
meta def map_lt (m1 m2 : rb_map ℕ int) : bool :=
list.lex (prod.lex (<) (<)) m1.to_list m2.to_list
-- make more efficient
meta def comp.lt (c1 c2 : comp) : bool :=
(c1.str.is_lt c2.str) || (c1.str = c2.str) && map_lt c1.coeffs c2.coeffs
meta instance comp.has_lt : has_lt comp := ⟨λ a b, comp.lt a b⟩
meta instance pcomp.has_lt : has_lt pcomp := ⟨λ p1 p2, p1.c < p2.c⟩
meta instance pcomp.has_lt_dec : decidable_rel ((<) : pcomp → pcomp → Prop) := by apply_instance
meta def comp.coeff_of (c : comp) (a : ℕ) : ℤ :=
c.coeffs.zfind a
meta def comp.scale (c : comp) (n : ℕ) : comp :=
{ c with coeffs := c.coeffs.map ((*) (n : ℤ)) }
meta def comp.add (c1 c2 : comp) : comp :=
⟨c1.str.max c2.str, c1.coeffs.add c2.coeffs⟩
meta def pcomp.scale (c : pcomp) (n : ℕ) : pcomp :=
⟨c.c.scale n, comp_source.scale n c.src⟩
meta def pcomp.add (c1 c2 : pcomp) : pcomp :=
⟨c1.c.add c2.c, comp_source.add c1.src c2.src⟩
meta instance pcomp.to_format : has_to_format pcomp :=
⟨λ p, to_fmt p.c.coeffs ++ to_string p.c.str ++ "0"⟩
meta instance comp.to_format : has_to_format comp :=
⟨λ p, to_fmt p.coeffs⟩
end datatypes
section fm_elim
/-- If c1 and c2 both contain variable a with opposite coefficients,
produces v1, v2, and c such that a has been cancelled in c := v1*c1 + v2*c2 -/
meta def elim_var (c1 c2 : comp) (a : ℕ) : option (ℕ × ℕ × comp) :=
let v1 := c1.coeff_of a,
v2 := c2.coeff_of a in
if v1 * v2 < 0 then
let vlcm := nat.lcm v1.nat_abs v2.nat_abs,
v1' := vlcm / v1.nat_abs,
v2' := vlcm / v2.nat_abs in
some ⟨v1', v2', comp.add (c1.scale v1') (c2.scale v2')⟩
else none
meta def pelim_var (p1 p2 : pcomp) (a : ℕ) : option pcomp :=
do (n1, n2, c) ← elim_var p1.c p2.c a,
return ⟨c, comp_source.add (p1.src.scale n1) (p2.src.scale n2)⟩
meta def comp.is_contr (c : comp) : bool := c.coeffs.empty ∧ c.str = ineq.lt
meta def pcomp.is_contr (p : pcomp) : bool := p.c.is_contr
meta def elim_with_set (a : ℕ) (p : pcomp) (comps : rb_set pcomp) : rb_set pcomp :=
if ¬ p.c.coeffs.contains a then mk_rb_set.insert p else
comps.fold mk_rb_set $ λ pc s,
match pelim_var p pc a with
| some pc := s.insert pc
| none := s
end
/--
The state for the elimination monad.
vars: the set of variables present in comps
comps: a set of comparisons
inputs: a set of pairs of exprs (t, pf), where t is a term and pf is a proof that t {<, ≤, =} 0,
indexed by ℕ.
has_false: stores a pcomp of 0 < 0 if one has been found
TODO: is it more efficient to store comps as a list, to avoid comparisons?
-/
meta structure linarith_structure :=
(vars : rb_set ℕ)
(comps : rb_set pcomp)
@[reducible] meta def linarith_monad :=
state_t linarith_structure (except_t pcomp id)
meta instance : monad linarith_monad := state_t.monad
meta instance : monad_except pcomp linarith_monad :=
state_t.monad_except pcomp
meta def get_vars : linarith_monad (rb_set ℕ) :=
linarith_structure.vars <$> get
meta def get_var_list : linarith_monad (list ℕ) :=
rb_set.to_list <$> get_vars
meta def get_comps : linarith_monad (rb_set pcomp) :=
linarith_structure.comps <$> get
meta def validate : linarith_monad unit :=
do ⟨_, comps⟩ ← get,
match comps.to_list.find (λ p : pcomp, p.is_contr) with
| none := return ()
| some c := throw c
end
meta def update (vars : rb_set ℕ) (comps : rb_set pcomp) : linarith_monad unit :=
state_t.put ⟨vars, comps⟩ >> validate
meta def monad.elim_var (a : ℕ) : linarith_monad unit :=
do vs ← get_vars,
when (vs.contains a) $
do comps ← get_comps,
let cs' := comps.fold mk_rb_set (λ p s, s.union (elim_with_set a p comps)),
update (vs.erase a) cs'
meta def elim_all_vars : linarith_monad unit :=
get_var_list >>= list.mmap' monad.elim_var
end fm_elim
section parse
open ineq tactic
meta def map_of_expr_mul_aux (c1 c2 : rb_map ℕ ℤ) : option (rb_map ℕ ℤ) :=
match c1.keys, c2.keys with
| [0], _ := some $ c2.scale (c1.zfind 0)
| _, [0] := some $ c1.scale (c2.zfind 0)
| [], _ := some mk_rb_map
| _, [] := some mk_rb_map
| _, _ := none
end
meta def list.mfind {α} (tac : α → tactic unit) : list α → tactic α
| [] := failed
| (h::t) := tac h >> return h <|> list.mfind t
meta def rb_map.find_defeq (red : transparency) {v} (m : expr_map v) (e : expr) : tactic v :=
prod.snd <$> list.mfind (λ p, is_def_eq e p.1 red) m.to_list
/--
Turns an expression into a map from ℕ to ℤ, for use in a comp object.
The expr_map ℕ argument identifies which expressions have already been assigned numbers.
Returns a new map.
-/
meta def map_of_expr (red : transparency) : expr_map ℕ → expr → tactic (expr_map ℕ × rb_map ℕ ℤ)
| m e@`(%%e1 * %%e2) :=
(do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
mp ← map_of_expr_mul_aux comp1 comp2,
return (m', mp)) <|>
(do k ← rb_map.find_defeq red m e, return (m, mk_rb_map.insert k 1)) <|>
(let n := m.size + 1 in return (m.insert e n, mk_rb_map.insert n 1))
| m `(%%e1 + %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add comp2)
| m `(%%e1 - %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add (comp2.scale (-1)))
| m `(-%%e) := do (m', comp) ← map_of_expr m e, return (m', comp.scale (-1))
| m e :=
match e.to_int with
| some 0 := return ⟨m, mk_rb_map⟩
| some z := return ⟨m, mk_rb_map.insert 0 z⟩
| none :=
(do k ← rb_map.find_defeq red m e, return (m, mk_rb_map.insert k 1)) <|>
(let n := m.size + 1 in return (m.insert e n, mk_rb_map.insert n 1))
end
meta def parse_into_comp_and_expr : expr → option (ineq × expr)
| `(%%e < 0) := (ineq.lt, e)
| `(%%e ≤ 0) := (ineq.le, e)
| `(%%e = 0) := (ineq.eq, e)
| _ := none
meta def to_comp (red : transparency) (e : expr) (m : expr_map ℕ) : tactic (comp × expr_map ℕ) :=
do (iq, e) ← parse_into_comp_and_expr e,
(m', comp') ← map_of_expr red m e,
return ⟨⟨iq, comp'⟩, m'⟩
meta def to_comp_fold (red : transparency) : expr_map ℕ → list expr →
tactic (list (option comp) × expr_map ℕ)
| m [] := return ([], m)
| m (h::t) :=
(do (c, m') ← to_comp red h m,
(l, mp) ← to_comp_fold m' t,
return (c::l, mp)) <|>
(do (l, mp) ← to_comp_fold m t,
return (none::l, mp))
/--
Takes a list of proofs of props of the form t {<, ≤, =} 0, and creates a linarith_structure.
-/
meta def mk_linarith_structure (red : transparency) (l : list expr) : tactic (linarith_structure × rb_map ℕ (expr × expr)) :=
do pftps ← l.mmap infer_type,
(l', map) ← to_comp_fold red mk_rb_map pftps,
let lz := list.enum $ ((l.zip pftps).zip l').filter_map (λ ⟨a, b⟩, prod.mk a <$> b),
let prmap := rb_map.of_list $ lz.map (λ ⟨n, x⟩, (n, x.1)),
let vars : rb_set ℕ := rb_map.set_of_list $ list.range map.size.succ,
let pc : rb_set pcomp := rb_map.set_of_list $
lz.map (λ ⟨n, x⟩, ⟨x.2, comp_source.assump n⟩),
return (⟨vars, pc⟩, prmap)
meta def linarith_monad.run (red : transparency) {α} (tac : linarith_monad α) (l : list expr) : tactic ((pcomp ⊕ α) × rb_map ℕ (expr × expr)) :=
do (struct, inputs) ← mk_linarith_structure red l,
match (state_t.run (validate >> tac) struct).run with
| (except.ok (a, _)) := return (sum.inr a, inputs)
| (except.error contr) := return (sum.inl contr, inputs)
end
end parse
section prove
open ineq tactic
meta def get_rel_sides : expr → tactic (expr × expr)
| `(%%a < %%b) := return (a, b)
| `(%%a ≤ %%b) := return (a, b)
| `(%%a = %%b) := return (a, b)
| `(%%a ≥ %%b) := return (a, b)
| `(%%a > %%b) := return (a, b)
| _ := failed
meta def mul_expr (n : ℕ) (e : expr) : pexpr :=
if n = 1 then ``(%%e) else
``(%%(nat.to_pexpr n) * %%e)
meta def add_exprs_aux : pexpr → list pexpr → pexpr
| p [] := p
| p [a] := ``(%%p + %%a)
| p (h::t) := add_exprs_aux ``(%%p + %%h) t
meta def add_exprs : list pexpr → pexpr
| [] := ``(0)
| (h::t) := add_exprs_aux h t
meta def find_contr (m : rb_set pcomp) : option pcomp :=
m.keys.find (λ p, p.c.is_contr)
meta def ineq_const_mul_nm : ineq → name
| lt := ``mul_neg
| le := ``mul_nonpos
| eq := ``mul_eq
meta def ineq_const_nm : ineq → ineq → (name × ineq)
| eq eq := (``eq_of_eq_of_eq, eq)
| eq le := (``le_of_eq_of_le, le)
| eq lt := (``lt_of_eq_of_lt, lt)
| le eq := (``le_of_le_of_eq, le)
| le le := (`add_nonpos, le)
| le lt := (`add_neg_of_nonpos_of_neg, lt)
| lt eq := (``lt_of_lt_of_eq, lt)
| lt le := (`add_neg_of_neg_of_nonpos, lt)
| lt lt := (`add_neg, lt)
meta def mk_single_comp_zero_pf (c : ℕ) (h : expr) : tactic (ineq × expr) :=
do tp ← infer_type h,
some (iq, e) ← return $ parse_into_comp_and_expr tp,
if c = 0 then
do e' ← mk_app ``zero_mul [e], return (eq, e')
else if c = 1 then return (iq, h)
else
do nm ← resolve_name (ineq_const_mul_nm iq),
tp ← (prod.snd <$> (infer_type h >>= get_rel_sides)) >>= infer_type,
cpos ← to_expr ``((%%c.to_pexpr : %%tp) > 0),
(_, ex) ← solve_aux cpos `[norm_num, done],
-- e' ← mk_app (ineq_const_mul_nm iq) [h, ex], -- this takes many seconds longer in some examples! why?
e' ← to_expr ``(%%nm %%h %%ex) ff,
return (iq, e')
meta def mk_lt_zero_pf_aux (c : ineq) (pf npf : expr) (coeff : ℕ) : tactic (ineq × expr) :=
do (iq, h') ← mk_single_comp_zero_pf coeff npf,
let (nm, niq) := ineq_const_nm c iq,
n ← resolve_name nm,
e' ← to_expr ``(%%n %%pf %%h'),
return (niq, e')
/--
Takes a list of coefficients [c] and list of expressions, of equal length.
Each expression is a proof of a prop of the form t {<, ≤, =} 0.
Produces a proof that the sum of (c*t) {<, ≤, =} 0, where the comp is as strong as possible.
-/
meta def mk_lt_zero_pf : list ℕ → list expr → tactic expr
| _ [] := fail "no linear hypotheses found"
| [c] [h] := prod.snd <$> mk_single_comp_zero_pf c h
| (c::ct) (h::t) :=
do (iq, h') ← mk_single_comp_zero_pf c h,
prod.snd <$> (ct.zip t).mfoldl (λ pr ce, mk_lt_zero_pf_aux pr.1 pr.2 ce.2 ce.1) (iq, h')
| _ _ := fail "not enough args to mk_lt_zero_pf"
meta def term_of_ineq_prf (prf : expr) : tactic expr :=
do (lhs, _) ← infer_type prf >>= get_rel_sides,
return lhs
meta structure linarith_config :=
(discharger : tactic unit := `[ring])
(restrict_type : option Type := none)
(restrict_type_reflect : reflected restrict_type . apply_instance)
(exfalso : bool := tt)
(transparency : transparency := reducible)
meta def ineq_pf_tp (pf : expr) : tactic expr :=
do (_, z) ← infer_type pf >>= get_rel_sides,
infer_type z
meta def mk_neg_one_lt_zero_pf (tp : expr) : tactic expr :=
to_expr ``((neg_neg_of_pos zero_lt_one : -1 < (0 : %%tp)))
/--
Assumes e is a proof that t = 0. Creates a proof that -t = 0.
-/
meta def mk_neg_eq_zero_pf (e : expr) : tactic expr :=
to_expr ``(neg_eq_zero.mpr %%e)
meta def add_neg_eq_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
do some (iq, tp) ← parse_into_comp_and_expr <$> infer_type h,
match iq with
| ineq.eq := do nep ← mk_neg_eq_zero_pf h, tl ← add_neg_eq_pfs t, return $ h::nep::tl
| _ := list.cons h <$> add_neg_eq_pfs t
end
/--
Takes a list of proofs of propositions of the form t {<, ≤, =} 0,
and tries to prove the goal `false`.
-/
meta def prove_false_by_linarith1 (cfg : linarith_config) : list expr → tactic unit
| [] := fail "no args to linarith"
| l@(h::t) :=
do l' ← add_neg_eq_pfs l,
hz ← ineq_pf_tp h >>= mk_neg_one_lt_zero_pf,
(sum.inl contr, inputs) ← elim_all_vars.run cfg.transparency (hz::l')
| fail "linarith failed to find a contradiction",
let coeffs := inputs.keys.map (λ k, (contr.src.flatten.ifind k)),
let pfs : list expr := inputs.keys.map (λ k, (inputs.ifind k).1),
let zip := (coeffs.zip pfs).filter (λ pr, pr.1 ≠ 0),
let (coeffs, pfs) := zip.unzip,
mls ← zip.mmap (λ pr, do e ← term_of_ineq_prf pr.2, return (mul_expr pr.1 e)),
sm ← to_expr $ add_exprs mls,
tgt ← to_expr ``(%%sm = 0),
(a, b) ← solve_aux tgt (cfg.discharger >> done),
pf ← mk_lt_zero_pf coeffs pfs,
pftp ← infer_type pf,
(_, nep, _) ← rewrite_core b pftp,
pf' ← mk_eq_mp nep pf,
mk_app `lt_irrefl [pf'] >>= exact
end prove
section normalize
open tactic
set_option eqn_compiler.max_steps 50000
meta def rem_neg (prf : expr) : expr → tactic expr
| `(_ ≤ _) := to_expr ``(lt_of_not_ge %%prf)
| `(_ < _) := to_expr ``(le_of_not_gt %%prf)
| `(_ > _) := to_expr ``(le_of_not_gt %%prf)
| `(_ ≥ _) := to_expr ``(lt_of_not_ge %%prf)
| e := failed
meta def rearr_comp : expr → expr → tactic expr
| prf `(%%a ≤ 0) := return prf
| prf `(%%a < 0) := return prf
| prf `(%%a = 0) := return prf
| prf `(%%a ≥ 0) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(%%a > 0) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(0 ≥ %%a) := to_expr ``(show %%a ≤ 0, from %%prf)
| prf `(0 > %%a) := to_expr ``(show %%a < 0, from %%prf)
| prf `(0 = %%a) := to_expr ``(eq.symm %%prf)
| prf `(0 ≤ %%a) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(0 < %%a) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(%%a ≤ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(%%a < %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a = %%b) := to_expr ``(sub_eq_zero.mpr %%prf)
| prf `(%%a > %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a ≥ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(¬ %%t) := do nprf ← rem_neg prf t, tp ← infer_type nprf, rearr_comp nprf tp
| prf _ := fail "couldn't rearrange comp"
meta def is_numeric : expr → option ℚ
| `(%%e1 + %%e2) := (+) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 - %%e2) := has_sub.sub <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 * %%e2) := (*) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 / %%e2) := (/) <$> is_numeric e1 <*> is_numeric e2
| `(-%%e) := rat.neg <$> is_numeric e
| e := e.to_rat
meta def find_cancel_factor : expr → ℕ × tree ℕ
| `(%%e1 + %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 - %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 * %%e2) :=
match is_numeric e1, is_numeric e2 with
| none, none := (1, tree.node 1 tree.nil tree.nil)
| _, _ :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, pd := v1*v2 in
(pd, tree.node pd t1 t2)
end
| `(%%e1 / %%e2) :=
match is_numeric e2 with
| some q := let (v1, t1) := find_cancel_factor e1, n := v1.lcm q.num.nat_abs in
(n, tree.node n t1 (tree.node q.num.nat_abs tree.nil tree.nil))
| none := (1, tree.node 1 tree.nil tree.nil)
end
| `(-%%e) := find_cancel_factor e
| _ := (1, tree.node 1 tree.nil tree.nil)
open tree
meta def mk_prod_prf : ℕ → tree ℕ → expr → tactic expr
| v (node _ lhs rhs) `(%%e1 + %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``add_subst [v1, v2]
| v (node _ lhs rhs) `(%%e1 - %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``sub_subst [v1, v2]
| v (node n lhs@(node ln _ _) rhs) `(%%e1 * %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf ln lhs e1, v2 ← mk_prod_prf (v/ln) rhs e2,
ln' ← tp.of_nat ln, vln' ← tp.of_nat (v/ln), v' ← tp.of_nat v,
ntp ← to_expr ``(%%ln' * %%vln' = %%v'),
(_, npf) ← solve_aux ntp `[norm_num, done],
mk_app ``mul_subst [v1, v2, npf]
| v (node n lhs rhs@(node rn _ _)) `(%%e1 / %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf (v/rn) lhs e1,
rn' ← tp.of_nat rn, vrn' ← tp.of_nat (v/rn), n' ← tp.of_nat n, v' ← tp.of_nat v,
ntp ← to_expr ``(%%rn' / %%e2 = 1),
(_, npf) ← solve_aux ntp `[norm_num, done],
ntp2 ← to_expr ``(%%vrn' * %%n' = %%v'),
(_, npf2) ← solve_aux ntp2 `[norm_num, done],
mk_app ``div_subst [v1, npf, npf2]
| v t `(-%%e) := do v' ← mk_prod_prf v t e, mk_app ``neg_subst [v']
| v _ e :=
do tp ← infer_type e,
v' ← tp.of_nat v,
e' ← to_expr ``(%%v' * %%e),
mk_app `eq.refl [e']
/--
e is a term with rational division. produces a natural number n and a proof that n*e = e',
where e' has no division.
-/
meta def kill_factors (e : expr) : tactic (ℕ × expr) :=
let (n, t) := find_cancel_factor e in
do e' ← mk_prod_prf n t e, return (n, e')
open expr
meta def expr_contains (n : name) : expr → bool
| (const nm _) := nm = n
| (lam _ _ _ bd) := expr_contains bd
| (pi _ _ _ bd) := expr_contains bd
| (app e1 e2) := expr_contains e1 || expr_contains e2
| _ := ff
lemma sub_into_lt {α} [ordered_semiring α] {a b : α} (he : a = b) (hl : a ≤ 0) : b ≤ 0 :=
by rwa he at hl
meta def norm_hyp_aux (h' lhs : expr) : tactic expr :=
do (v, lhs') ← kill_factors lhs,
if v = 1 then return h' else do
(ih, h'') ← mk_single_comp_zero_pf v h',
(_, nep, _) ← infer_type h'' >>= rewrite_core lhs',
mk_eq_mp nep h''
meta def norm_hyp (h : expr) : tactic expr :=
do htp ← infer_type h,
h' ← rearr_comp h htp,
some (c, lhs) ← parse_into_comp_and_expr <$> infer_type h',
if expr_contains `has_div.div lhs then
norm_hyp_aux h' lhs
else return h'
meta def get_contr_lemma_name : expr → option name
| `(%%a < %%b) := return `lt_of_not_ge
| `(%%a ≤ %%b) := return `le_of_not_gt
| `(%%a = %%b) := return ``eq_of_not_lt_of_not_gt
| `(%%a ≠ %%b) := return `not.intro
| `(%%a ≥ %%b) := return `le_of_not_gt
| `(%%a > %%b) := return `lt_of_not_ge
| `(¬ %%a < %%b) := return `not.intro
| `(¬ %%a ≤ %%b) := return `not.intro
| `(¬ %%a = %%b) := return `not.intro
| `(¬ %%a ≥ %%b) := return `not.intro
| `(¬ %%a > %%b) := return `not.intro
| _ := none
-- assumes the input t is of type ℕ. Produces t' of type ℤ such that ↑t = t' and a proof of equality
meta def cast_expr (e : expr) : tactic (expr × expr) :=
do s ← [`int.coe_nat_add, `int.coe_nat_zero, `int.coe_nat_one,
``int.coe_nat_bit0_mul, ``int.coe_nat_bit1_mul, ``int.coe_nat_zero_mul, ``int.coe_nat_one_mul,
``int.coe_nat_mul_bit0, ``int.coe_nat_mul_bit1, ``int.coe_nat_mul_zero, ``int.coe_nat_mul_one,
``int.coe_nat_bit0, ``int.coe_nat_bit1].mfoldl simp_lemmas.add_simp simp_lemmas.mk,
ce ← to_expr ``(↑%%e : ℤ),
simplify s [] ce {fail_if_unchanged := ff}
meta def is_nat_int_coe : expr → option expr
| `((↑(%%n : ℕ) : ℤ)) := some n
| _ := none
meta def mk_coe_nat_nonneg_prf (e : expr) : tactic expr :=
mk_app `int.coe_nat_nonneg [e]
meta def get_nat_comps : expr → list expr
| `(%%a + %%b) := (get_nat_comps a).append (get_nat_comps b)
| `(%%a * %%b) := (get_nat_comps a).append (get_nat_comps b)
| e := match is_nat_int_coe e with
| some e' := [e']
| none := []
end
meta def mk_coe_nat_nonneg_prfs (e : expr) : tactic (list expr) :=
(get_nat_comps e).mmap mk_coe_nat_nonneg_prf
meta def mk_cast_eq_and_nonneg_prfs (pf a b : expr) (ln : name) : tactic (list expr) :=
do (a', prfa) ← cast_expr a,
(b', prfb) ← cast_expr b,
la ← mk_coe_nat_nonneg_prfs a',
lb ← mk_coe_nat_nonneg_prfs b',
pf' ← mk_app ln [pf, prfa, prfb],
return $ pf'::(la.append lb)
meta def mk_int_pfs_of_nat_pf (pf : expr) : tactic (list expr) :=
do tp ← infer_type pf,
match tp with
| `(%%a = %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_eq_subst
| `(%%a ≤ %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_le_subst
| `(%%a < %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_lt_subst
| `(%%a ≥ %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_le_subst
| `(%%a > %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_lt_subst
| `(¬ %%a ≤ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_lt_subst
| `(¬ %%a < %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_le_subst
| `(¬ %%a ≥ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_lt_subst
| `(¬ %%a > %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_le_subst
| _ := fail "mk_int_pfs_of_nat_pf failed: proof is not an inequality"
end
meta def mk_non_strict_int_pf_of_strict_int_pf (pf : expr) : tactic expr :=
do tp ← infer_type pf,
match tp with
| `(%%a < %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) %%pf)
| `(%%a > %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) %%pf)
| `(¬ %%a ≤ %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) (lt_of_not_ge %%pf))
| `(¬ %%a ≥ %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) (lt_of_not_ge %%pf))
| _ := fail "mk_non_strict_int_pf_of_strict_int_pf failed: proof is not an inequality"
end
meta def guard_is_nat_prop : expr → tactic unit
| `(%%a = _) := infer_type a >>= unify `(ℕ)
| `(%%a ≤ _) := infer_type a >>= unify `(ℕ)
| `(%%a < _) := infer_type a >>= unify `(ℕ)
| `(%%a ≥ _) := infer_type a >>= unify `(ℕ)
| `(%%a > _) := infer_type a >>= unify `(ℕ)
| `(¬ %%p) := guard_is_nat_prop p
| _ := failed
meta def guard_is_strict_int_prop : expr → tactic unit
| `(%%a < _) := infer_type a >>= unify `(ℤ)
| `(%%a > _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≤ _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≥ _) := infer_type a >>= unify `(ℤ)
| _ := failed
meta def replace_nat_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_nat_prop,
ls ← mk_int_pfs_of_nat_pf h,
list.append ls <$> replace_nat_pfs t) <|> list.cons h <$> replace_nat_pfs t
meta def replace_strict_int_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_strict_int_prop,
l ← mk_non_strict_int_pf_of_strict_int_pf h,
list.cons l <$> replace_strict_int_pfs t) <|> list.cons h <$> replace_strict_int_pfs t
meta def partition_by_type_aux : rb_lmap expr expr → list expr → tactic (rb_lmap expr expr)
| m [] := return m
| m (h::t) := do tp ← ineq_pf_tp h, partition_by_type_aux (m.insert tp h) t
meta def partition_by_type (l : list expr) : tactic (rb_lmap expr expr) :=
partition_by_type_aux mk_rb_map l
private meta def try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic unit :=
(first $ ls.map $ prove_false_by_linarith1 cfg) <|> fail "linarith failed"
/--
Takes a list of proofs of propositions.
Filters out the proofs of linear (in)equalities,
and tries to use them to prove `false`.
If pref_type is given, starts by working over this type
-/
meta def prove_false_by_linarith (cfg : linarith_config) (pref_type : option expr) (l : list expr) : tactic unit :=
do l' ← replace_nat_pfs l,
l'' ← replace_strict_int_pfs l',
ls ← list.reduce_option <$> l''.mmap (λ h, (do s ← norm_hyp h, return (some s)) <|> return none)
>>= partition_by_type,
pref_type ← (unify pref_type.iget `(ℕ) >> return (some `(ℤ) : option expr)) <|> return pref_type,
match cfg.restrict_type, ls.values, pref_type with
| some rtp, _, _ :=
do m ← mk_mvar, unify `(some %%m : option Type) cfg.restrict_type_reflect, m ← instantiate_mvars m,
prove_false_by_linarith1 cfg (ls.ifind m)
| none, [ls'], _ := prove_false_by_linarith1 cfg ls'
| none, ls', none := try_linarith_on_lists cfg ls'
| none, _, (some t) := prove_false_by_linarith1 cfg (ls.ifind t) <|> try_linarith_on_lists cfg (ls.erase t).values
end
end normalize
end linarith
section
open tactic linarith
open lean lean.parser interactive tactic interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
meta def linarith.elab_arg_list : option (list pexpr) → tactic (list expr)
| none := return []
| (some l) := l.mmap i_to_expr
meta def linarith.preferred_type_of_goal : option expr → tactic (option expr)
| none := return none
| (some e) := some <$> ineq_pf_tp e
/--
linarith.interactive_aux cfg o_goal restrict_hyps args:
* cfg is a linarith_config object
* o_goal : option expr is the local constant corresponding to the former goal, if there was one
* restrict_hyps : bool is tt if `linarith only [...]` was used
* args : option (list pexpr) is the optional list of arguments in `linarith [...]`
-/
meta def linarith.interactive_aux (cfg : linarith_config) :
option expr → bool → option (list pexpr) → tactic unit
| none tt none := fail "linarith only called with no arguments"
| none tt (some l) := l.mmap i_to_expr >>= prove_false_by_linarith cfg none
| (some e) tt l :=
do tp ← ineq_pf_tp e,
list.cons e <$> linarith.elab_arg_list l >>= prove_false_by_linarith cfg (some tp)
| oe ff l :=
do otp ← linarith.preferred_type_of_goal oe,
list.append <$> local_context <*>
(list.filter (λ a, bnot $ expr.is_local_constant a) <$> linarith.elab_arg_list l) >>=
prove_false_by_linarith cfg otp
/--
Tries to prove a goal of `false` by linear arithmetic on hypotheses.
If the goal is a linear (in)equality, tries to prove it by contradiction.
If the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the
hypotheses.
`linarith` will use all relevant hypotheses in the local context.
`linarith [t1, t2, t3]` will add proof terms t1, t2, t3 to the local context.
`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
h1, h2, h3, and proofs t1, t2, t3. It will ignore the rest of the local context.
`linarith!` will use a stronger reducibility setting to identify atoms.
Config options:
`linarith {exfalso := ff}` will fail on a goal that is neither an inequality nor `false`
`linarith {restrict_type := T}` will run only on hypotheses that are inequalities over `T`
`linarith {discharger := tac}` will use `tac` instead of `ring` for normalization.
Options: `ring2`, `ring SOP`, `simp`
-/
meta def tactic.interactive.linarith (red : parse ((tk "!")?))
(restr : parse ((tk "only")?)) (hyps : parse pexpr_list?)
(cfg : linarith_config := {}) : tactic unit :=
let cfg :=
if red.is_some then {cfg with transparency := semireducible, discharger := `[ring!]}
else cfg in
do t ← target,
match get_contr_lemma_name t with
| some nm := seq (applyc nm) $
do t ← intro1, linarith.interactive_aux cfg (some t) restr.is_some hyps
| none := if cfg.exfalso then exfalso >> linarith.interactive_aux cfg none restr.is_some hyps
else fail "linarith failed: target type is not an inequality."
end
end
|
01658a59187447d12e3f96c46e75c8b0a53307ee | 1d265c7dd8cb3d0e1d645a19fd6157a2084c3921 | /src/other/set_exer2.lean | 3cfc118ade6e2dabd9394dcd0c68faf6b4be5efa | [
"MIT"
] | permissive | hanzhi713/lean-proofs | de432372f220d302be09b5ca4227f8986567e4fd | 4d8356a878645b9ba7cb036f87737f3f1e68ede5 | refs/heads/master | 1,585,580,245,658 | 1,553,646,623,000 | 1,553,646,623,000 | 151,342,188 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 4,393 | lean | import data.set
open set
section
variable U : Type
variables A B C : set U
example : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=
begin
assume x,
assume h,
left, exact h.1,
end
example : ∀ x, x ∈ -(A ∪ B) → x ∈ -A :=
begin
assume x,
assume h,
assume xinA,
have : x ∈ A ∪ B,
left, assumption,
contradiction
end
end
section
variable {U : Type}
/- defining "disjoint" -/
def disj (A B : set U) : Prop := ∀ ⦃x⦄, x ∈ A → x ∈ B → false
example (A B : set U) (h : ∀ x, ¬ (x ∈ A ∧ x ∈ B)) :
disj A B :=
assume x,
assume h1 : x ∈ A,
assume h2 : x ∈ B,
have h3 : x ∈ A ∧ x ∈ B, from and.intro h1 h2,
show false, from h x h3
-- notice that we do not have to mention x when applying
-- h : disj A B
example (A B : set U) (h1 : disj A B) (x : U)
(h2 : x ∈ A) (h3 : x ∈ B) :
false :=
h1 h2 h3
-- the same is true of ⊆
example (A B : set U) (x : U) (h : A ⊆ B) (h1 : x ∈ A) :
x ∈ B :=
h h1
example (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A)
(h3 : D ⊆ B) :
disj C D :=
begin
assume x,
assume xinC xinD,
have xinA : x ∈ A := h2 xinC,
have xinB : x ∈ B := h3 xinD,
exact h1 xinA xinB,
end
end
section
variables {I U : Type}
variables {A B : I → set U}
theorem Inter.intro {x : U} (h : ∀ i, x ∈ A i) : x ∈ ⋂ i, A i :=
by simp; assumption
@[elab_simple]
theorem Inter.elim {x : U} (h : x ∈ ⋂ i, A i) (i : I) : x ∈ A i :=
by simp at h; apply h
theorem Union.intro {x : U} (i : I) (h : x ∈ A i) : x ∈ ⋃ i, A i :=
by {simp, existsi i, exact h}
theorem Union.elim {b : Prop} {x : U}
(h₁ : x ∈ ⋃ i, A i) (h₂ : ∀ (i : I), x ∈ A i → b) : b :=
by {simp at h₁, cases h₁ with i h, exact h₂ i h}
-- BEGIN
variables (C : set U)
example : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=
begin
assume x,
assume h,
-- actually, simp * at * here will do the job
apply Inter.intro,
assume i,
split,
show x ∈ A i, from Inter.elim h.1 i,
show x ∈ B i, from Inter.elim h.2 i
end
example : C ∩ (⋃ i, A i) ⊆ ⋃ i, C ∩ A i :=
begin
assume x,
assume h,
-- actually, simp * at * here will do the job
have xinC := h.1,
apply Union.elim h.2,
intros i xinAi,
apply Union.intro i,
exact ⟨xinC, xinAi⟩,
end
-- END
end
section
-- BEGIN
variable {U : Type}
variables A B C : set U
-- For this exercise these two facts are useful
example (h1 : A ⊆ B) (h2 : B ⊆ C) : A ⊆ C :=
subset.trans h1 h2
example : A ⊆ A :=
subset.refl A
example (h : A ⊆ B) : powerset A ⊆ powerset B :=
begin
assume s : set U,
assume h₂ : s ∈ 𝒫 A, -- s is a subset of A, i.e. s ⊆ A, which is x ∈ s → x ∈ A
assume x : U,
assume xinS : x ∈ s,
exact h (h₂ xinS),
end
example (h : powerset A ⊆ powerset B) : A ⊆ B :=
begin
have : A ∈ 𝒫 A,
assume _ _, assumption,
have : A ∈ 𝒫 B := h this,
assumption, -- note : A ∈ 𝒫 B is equivalent to A ⊆ B
end
example : 𝒫 (A ∩ B) = 𝒫 A ∩ 𝒫 B :=
begin
apply set.ext,
assume x,
split,
assume h,
split,
assume a,
assume h1,
have : a ∈ A ∩ B := h h1,
exact this.1,
assume a,
assume h1,
have : a ∈ A ∩ B := h h1,
exact this.2,
assume h,
cases h with xinPa xinPb,
assume a,
assume h1 : a ∈ x,
split,
exact xinPa h1,
exact xinPb h1,
end
end
|
38563ea43f04be683e0b2477a4b3e173174cb6bd | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/ring_theory/polynomial_algebra.lean | 13902e1dce7587e89d669687fd0382820b93c43d | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 11,918 | 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 ring_theory.matrix_algebra
import data.polynomial.algebra_map
/-!
# Algebra isomorphism between matrices of polynomials and polynomials of matrices
Given `[comm_ring R] [ring A] [algebra R A]`
we show `polynomial A ≃ₐ[R] (A ⊗[R] polynomial R)`.
Combining this with the isomorphism `matrix n n A ≃ₐ[R] (A ⊗[R] matrix n n R)` proved earlier
in `ring_theory.matrix_algebra`, we obtain the algebra isomorphism
```
def mat_poly_equiv :
matrix n n (polynomial R) ≃ₐ[R] polynomial (matrix n n R)
```
which is characterized by
```
coeff (mat_poly_equiv m) k i j = coeff (m i j) k
```
We will use this algebra isomorphism to prove the Cayley-Hamilton theorem.
-/
universes u v w
open_locale tensor_product
open polynomial
open tensor_product
open algebra.tensor_product (alg_hom_of_linear_map_tensor_product include_left)
noncomputable theory
variables (R A : Type*)
variables [comm_semiring R]
variables [semiring A] [algebra R A]
namespace poly_equiv_tensor
/--
(Implementation detail).
The bare function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`, on pure tensors.
-/
def to_fun (a : A) (p : polynomial R) : polynomial A :=
p.sum (λ n r, monomial n (a * algebra_map R A r))
/--
(Implementation detail).
The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`,
as a linear map in the second factor.
-/
def to_fun_linear_right (a : A) : polynomial R →ₗ[R] polynomial A :=
{ to_fun := to_fun R A a,
map_smul' := λ r p,
begin
dsimp [to_fun],
rw finsupp.sum_smul_index,
{ dsimp [finsupp.sum],
rw finset.smul_sum,
apply finset.sum_congr rfl,
intros k hk,
rw [monomial_eq_smul_X, monomial_eq_smul_X, algebra.smul_def, ← C_mul', ← C_mul',
← mul_assoc],
congr' 1,
rw [← algebra.commutes, ← algebra.commutes],
simp only [ring_hom.map_mul, polynomial.algebra_map_apply, mul_assoc], },
{ intro i, simp only [ring_hom.map_zero, mul_zero, monomial_zero_right] },
end,
map_add' := λ p q,
begin
simp only [to_fun],
rw finsupp.sum_add_index,
{ simp only [monomial_zero_right, forall_const, ring_hom.map_zero, mul_zero], },
{ intros i r s, simp only [ring_hom.map_add, mul_add, monomial_add], },
end, }
/--
(Implementation detail).
The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`,
as a bilinear function of two arguments.
-/
def to_fun_bilinear : A →ₗ[R] polynomial R →ₗ[R] polynomial A :=
{ to_fun := to_fun_linear_right R A,
map_smul' := by {
intros, unfold to_fun_linear_right,
congr, simp only [linear_map.coe_mk],
unfold to_fun finsupp.sum monomial,
simp_rw [finset.smul_sum, finsupp.smul_single, ← algebra.smul_mul_assoc],
refl },
map_add' := by {
intros, unfold to_fun_linear_right,
congr, simp only [linear_map.coe_mk],
unfold to_fun finsupp.sum monomial,
simp_rw [← finset.sum_add_distrib, ← finsupp.single_add, ← add_mul],
refl } }
/--
(Implementation detail).
The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`,
as a linear map.
-/
def to_fun_linear : A ⊗[R] polynomial R →ₗ[R] polynomial A :=
tensor_product.lift (to_fun_bilinear R A)
-- We apparently need to provide the decidable instance here
-- in order to successfully rewrite by this lemma.
lemma to_fun_linear_mul_tmul_mul_aux_1
(p : polynomial R) (k : ℕ) (h : decidable (¬p.coeff k = 0)) (a : A) :
ite (¬coeff p k = 0) (a * (algebra_map R A) (coeff p k)) 0 = a * (algebra_map R A) (coeff p k) :=
by { classical, split_ifs; simp *, }
lemma to_fun_linear_mul_tmul_mul_aux_2 (k : ℕ) (a₁ a₂ : A) (p₁ p₂ : polynomial R) :
a₁ * a₂ * (algebra_map R A) ((p₁ * p₂).coeff k) =
(finset.nat.antidiagonal k).sum
(λ x, a₁ * (algebra_map R A) (coeff p₁ x.1) * (a₂ * (algebra_map R A) (coeff p₂ x.2))) :=
begin
simp_rw [mul_assoc, algebra.commutes, ←finset.mul_sum, mul_assoc, ←finset.mul_sum],
congr,
simp_rw [algebra.commutes (coeff p₂ _), coeff_mul, ring_hom.map_sum, ring_hom.map_mul],
end
lemma to_fun_linear_mul_tmul_mul (a₁ a₂ : A) (p₁ p₂ : polynomial R) :
(to_fun_linear R A) ((a₁ * a₂) ⊗ₜ[R] p₁ * p₂) =
(to_fun_linear R A) (a₁ ⊗ₜ[R] p₁) * (to_fun_linear R A) (a₂ ⊗ₜ[R] p₂) :=
begin
dsimp [to_fun_linear],
simp only [lift.tmul],
dsimp [to_fun_bilinear, to_fun_linear_right, to_fun],
ext k,
-- TODO This is a bit annoying: the polynomial API is breaking down.
have apply_eq_coeff : ∀ {p : ℕ →₀ R} {n : ℕ}, p n = coeff p n := by { intros, refl },
simp_rw [coeff_sum, coeff_monomial, finsupp.sum, finset.sum_ite_eq', finsupp.mem_support_iff,
ne.def, coeff_mul, finset_sum_coeff, coeff_monomial,
finset.sum_ite_eq', finsupp.mem_support_iff, ne.def,
mul_ite, mul_zero, ite_mul, zero_mul, apply_eq_coeff],
simp_rw [ite_mul_zero_left (¬coeff p₁ _ = 0) (a₁ * (algebra_map R A) (coeff p₁ _))],
simp_rw [ite_mul_zero_right (¬coeff p₂ _ = 0) _ (_ * _)],
simp_rw [to_fun_linear_mul_tmul_mul_aux_1, to_fun_linear_mul_tmul_mul_aux_2],
end
lemma to_fun_linear_algebra_map_tmul_one (r : R) :
(to_fun_linear R A) ((algebra_map R A) r ⊗ₜ[R] 1) = (algebra_map R (polynomial A)) r :=
begin
dsimp [to_fun_linear],
simp only [lift.tmul],
dsimp [to_fun_bilinear, to_fun_linear_right, to_fun],
rw [← C_1, ←monomial_zero_left, monomial, finsupp.sum_single_index],
{ simp, refl, },
{ simp, },
end
/--
(Implementation detail).
The algebra homomorphism `A ⊗[R] polynomial R →ₐ[R] polynomial A`.
-/
def to_fun_alg_hom : A ⊗[R] polynomial R →ₐ[R] polynomial A :=
alg_hom_of_linear_map_tensor_product
(to_fun_linear R A)
(to_fun_linear_mul_tmul_mul R A)
(to_fun_linear_algebra_map_tmul_one R A)
@[simp] lemma to_fun_alg_hom_apply_tmul (a : A) (p : polynomial R) :
to_fun_alg_hom R A (a ⊗ₜ[R] p) = p.sum (λ n r, monomial n (a * (algebra_map R A) r)) :=
by simp [to_fun_alg_hom, to_fun_linear, to_fun_bilinear, to_fun_linear_right, to_fun]
/--
(Implementation detail.)
The bare function `polynomial A → A ⊗[R] polynomial R`.
(We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.)
-/
def inv_fun (p : polynomial A) : A ⊗[R] polynomial R :=
p.eval₂
(include_left : A →ₐ[R] A ⊗[R] polynomial R)
((1 : A) ⊗ₜ[R] (X : polynomial R))
@[simp]
lemma inv_fun_add {p q} : inv_fun R A (p + q) = inv_fun R A p + inv_fun R A q :=
by simp only [inv_fun, eval₂_add]
lemma left_inv (x : A ⊗ polynomial R) :
inv_fun R A ((to_fun_alg_hom R A) x) = x :=
begin
apply tensor_product.induction_on x,
{ simp [inv_fun], },
{ intros a p, dsimp only [inv_fun],
rw [to_fun_alg_hom_apply_tmul, eval₂_sum],
simp_rw [eval₂_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.tmul_pow, one_pow,
algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_mul_tmul,
mul_one, one_mul, ←algebra.commutes, ←algebra.smul_def'', smul_tmul],
rw [finsupp.sum, ←tmul_sum],
conv_rhs { rw [←sum_C_mul_X_eq p], },
simp only [algebra.smul_def''],
refl, },
{ intros p q hp hq,
simp only [alg_hom.map_add, inv_fun_add, hp, hq], },
end
lemma right_inv (x : polynomial A) :
(to_fun_alg_hom R A) (inv_fun R A x) = x :=
begin
apply polynomial.induction_on' x,
{ intros p q hp hq, simp only [inv_fun_add, alg_hom.map_add, hp, hq], },
{ intros n a,
rw [inv_fun, eval₂_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.include_left_apply,
algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.tmul_mul_tmul,
mul_one, one_mul, to_fun_alg_hom_apply_tmul, ←monomial_one_eq_X_pow],
dsimp [monomial],
rw [finsupp.sum_single_index]; simp, }
end
/--
(Implementation detail)
The equivalence, ignoring the algebra structure, `(A ⊗[R] polynomial R) ≃ polynomial A`.
-/
def equiv : (A ⊗[R] polynomial R) ≃ polynomial A :=
{ to_fun := to_fun_alg_hom R A,
inv_fun := inv_fun R A,
left_inv := left_inv R A,
right_inv := right_inv R A, }
end poly_equiv_tensor
open poly_equiv_tensor
/--
The `R`-algebra isomorphism `polynomial A ≃ₐ[R] (A ⊗[R] polynomial R)`.
-/
def poly_equiv_tensor : polynomial A ≃ₐ[R] (A ⊗[R] polynomial R) :=
alg_equiv.symm
{ ..(poly_equiv_tensor.to_fun_alg_hom R A), ..(poly_equiv_tensor.equiv R A) }
@[simp]
lemma poly_equiv_tensor_apply (p : polynomial A) :
poly_equiv_tensor R A p =
p.eval₂ (include_left : A →ₐ[R] A ⊗[R] polynomial R) ((1 : A) ⊗ₜ[R] (X : polynomial R)) :=
rfl
@[simp]
lemma poly_equiv_tensor_symm_apply_tmul (a : A) (p : polynomial R) :
(poly_equiv_tensor R A).symm (a ⊗ₜ p) = p.sum (λ n r, monomial n (a * algebra_map R A r)) :=
begin
simp [poly_equiv_tensor, to_fun_alg_hom, alg_hom_of_linear_map_tensor_product, to_fun_linear],
refl,
end
open matrix
open_locale big_operators
variables {R}
variables {n : Type w} [decidable_eq n] [fintype n]
/--
The algebra isomorphism stating "matrices of polynomials are the same as polynomials of matrices".
(You probably shouldn't attempt to use this underlying definition ---
it's an algebra equivalence, and characterised extensionally by the lemma
`mat_poly_equiv_coeff_apply` below.)
-/
noncomputable def mat_poly_equiv :
matrix n n (polynomial R) ≃ₐ[R] polynomial (matrix n n R) :=
(((matrix_equiv_tensor R (polynomial R) n)).trans
(algebra.tensor_product.comm R _ _)).trans
(poly_equiv_tensor R (matrix n n R)).symm
open finset
lemma mat_poly_equiv_coeff_apply_aux_1 (i j : n) (k : ℕ) (x : R) :
mat_poly_equiv (std_basis_matrix i j $ monomial k x) =
monomial k (std_basis_matrix i j x) :=
begin
simp only [mat_poly_equiv, alg_equiv.trans_apply,
matrix_equiv_tensor_apply_std_basis],
apply (poly_equiv_tensor R (matrix n n R)).injective,
simp only [alg_equiv.apply_symm_apply],
convert algebra.tensor_product.comm_tmul _ _ _ _ _,
simp only [poly_equiv_tensor_apply],
convert eval₂_monomial _ _,
simp only [algebra.tensor_product.tmul_mul_tmul, one_pow, one_mul, matrix.mul_one,
algebra.tensor_product.tmul_pow, algebra.tensor_product.include_left_apply, mul_eq_mul],
rw [monomial_eq_smul_X, ← tensor_product.smul_tmul],
congr' with i' j'; simp
end
lemma mat_poly_equiv_coeff_apply_aux_2
(i j : n) (p : polynomial R) (k : ℕ) :
coeff (mat_poly_equiv (std_basis_matrix i j p)) k =
std_basis_matrix i j (coeff p k) :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, ext,
simp [hp, hq, coeff_add, add_apply, std_basis_matrix_add], },
{ intros k x,
simp only [mat_poly_equiv_coeff_apply_aux_1, coeff_monomial],
split_ifs; { funext, simp, }, }
end
@[simp] lemma mat_poly_equiv_coeff_apply
(m : matrix n n (polynomial R)) (k : ℕ) (i j : n) :
coeff (mat_poly_equiv m) k i j = coeff (m i j) k :=
begin
apply matrix.induction_on' m,
{ simp, },
{ intros p q hp hq, simp [hp, hq], },
{ intros i' j' x,
erw mat_poly_equiv_coeff_apply_aux_2,
dsimp [std_basis_matrix],
split_ifs,
{ rcases h with ⟨rfl, rfl⟩, simp [std_basis_matrix], },
{ simp [std_basis_matrix, h], }, },
end
@[simp] lemma mat_poly_equiv_symm_apply_coeff
(p : polynomial (matrix n n R)) (i j : n) (k : ℕ) :
coeff (mat_poly_equiv.symm p i j) k = coeff p k i j :=
begin
have t : p = mat_poly_equiv
(mat_poly_equiv.symm p) := by simp,
conv_rhs { rw t, },
simp only [mat_poly_equiv_coeff_apply],
end
lemma mat_poly_equiv_smul_one (p : polynomial R) :
mat_poly_equiv (p • 1) = p.map (algebra_map R (matrix n n R)) :=
begin
ext m i j,
simp only [coeff_map, one_apply, algebra_map_matrix_apply, mul_boole,
smul_apply, mat_poly_equiv_coeff_apply],
split_ifs; simp,
end
|
0f3237a668f22bb335134e3e12b8d4ce11111a96 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/typeclass_metas_internal_goals4.lean | e148c87cfa8f5893f896765ca58296493e0ff6b8 | [
"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 | 686 | lean |
class Foo (α β γ : Type) := (u:Unit)
class Bar (α β γ : Type) := (u:Unit)
class Top := (u:Unit)
set_option synthInstance.checkSynthOrder false in
instance FooBarToTop (α β γ : Type) [Foo α β γ] [Bar α β γ] : Top := {u:=()}
instance Foo₁ (β γ : Type) : Foo Unit β γ := {u:=()}
instance Foo₂ (α γ : Type) : Foo α Unit γ := {u:=()}
instance Foo₃ (α β : Type) : Foo α β Unit := {u:=()}
instance Foo₁₂ (γ : Type) : Foo Unit Nat γ := {u:=()}
instance Foo₂₃ (α : Type) : Foo α Unit Nat := {u:=()}
instance Foo₃₁ (β : Type) : Foo Nat β Unit := {u:=()}
instance Bar0 : Bar Unit Int (List Int) := {u:=()}
set_option pp.all true
#synth Top
|
d978338d5558a2e16c5ec61fe6a3f000fd8095f6 | e61a235b8468b03aee0120bf26ec615c045005d2 | /src/Init/Lean/Parser/Term.lean | aa6f64dec165072b877f726676e41c6c9595ad06 | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,297 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Lean.Parser.Parser
import Init.Lean.Parser.Level
namespace Lean
namespace Parser
@[init] def regBuiltinTacticParserAttr : IO Unit :=
let leadingIdentAsSymbol := true;
registerBuiltinParserAttribute `builtinTacticParser `tactic leadingIdentAsSymbol
@[init] def regTacticParserAttribute : IO Unit :=
registerBuiltinDynamicParserAttribute `tacticParser `tactic
@[inline] def tacticParser (rbp : Nat := 0) : Parser :=
categoryParser `tactic rbp
def Tactic.seq : Parser := node `Lean.Parser.Tactic.seq $ sepBy tacticParser "; " true
def Tactic.nonEmptySeq : Parser := node `Lean.Parser.Tactic.seq $ sepBy1 tacticParser "; " true
def darrow : Parser := "=>"
namespace Term
/- Helper functions for defining simple parsers -/
def unicodeInfixR (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser :=
unicodeSymbol sym asciiSym lbp >> termParser (lbp - 1)
def infixR (sym : String) (lbp : Nat) : TrailingParser :=
symbol sym lbp >> termParser (lbp - 1)
def unicodeInfixL (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser :=
unicodeSymbol sym asciiSym lbp >> termParser lbp
def infixL (sym : String) (lbp : Nat) : TrailingParser :=
symbol sym lbp >> termParser lbp
def leadPrec := appPrec - 1
/- Built-in parsers -/
-- NOTE: `checkNoWsBefore` should be used *before* `parser!` so that it is also applied to the generated
-- antiquotation.
def explicitUniv := checkNoWsBefore "no space before '.{'" >> parser! ".{" >> sepBy1 levelParser ", " >> "}"
def namedPattern := checkNoWsBefore "no space before '@'" >> parser! "@" >> termParser appPrec
@[builtinTermParser] def id := parser! ident >> optional (explicitUniv <|> namedPattern)
@[builtinTermParser] def num : Parser := parser! numLit
@[builtinTermParser] def str : Parser := parser! strLit
@[builtinTermParser] def char : Parser := parser! charLit
@[builtinTermParser] def type := parser! symbol "Type" appPrec
@[builtinTermParser] def sort := parser! symbol "Sort" appPrec
@[builtinTermParser] def prop := parser! symbol "Prop" appPrec
@[builtinTermParser] def hole := parser! symbol "_" appPrec
@[builtinTermParser] def namedHole := parser! symbol "?" appPrec >> ident
@[builtinTermParser] def «sorry» := parser! symbol "sorry" appPrec
@[builtinTermParser] def cdot := parser! symbol "·" appPrec
@[builtinTermParser] def emptyC := parser! symbol "∅" appPrec
def typeAscription := parser! " : " >> termParser
def tupleTail := parser! ", " >> sepBy1 termParser ", "
def parenSpecial : Parser := optional (tupleTail <|> typeAscription)
@[builtinTermParser] def paren := parser! symbol "(" appPrec >> optional (termParser >> parenSpecial) >> ")"
@[builtinTermParser] def anonymousCtor := parser! symbol "⟨" appPrec >> sepBy termParser ", " >> "⟩"
def optIdent : Parser := optional (try (ident >> " : "))
@[builtinTermParser] def «if» := parser! symbol "if " leadPrec >> optIdent >> termParser >> " then " >> termParser >> " else " >> termParser
def fromTerm := parser! " from " >> termParser
def haveAssign := parser! " := " >> termParser
@[builtinTermParser] def «have» := parser! symbol "have " leadPrec >> optIdent >> termParser >> (haveAssign <|> fromTerm) >> "; " >> termParser
@[builtinTermParser] def «suffices» := parser! symbol "suffices " leadPrec >> optIdent >> termParser >> fromTerm >> "; " >> termParser
@[builtinTermParser] def «show» := parser! symbol "show " leadPrec >> termParser >> fromTerm
def structInstArrayRef := parser! "[" >> termParser >>"]"
def structInstLVal := (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef)
def structInstField := parser! structInstLVal >> " := " >> termParser
@[builtinTermParser] def structInst := parser! symbol "{" appPrec >> optional (try (termParser >> "with")) >> sepBy structInstField ", " true >> optional ".." >> optional (" : " >> termParser) >> "}"
def typeSpec := parser! " : " >> termParser
def optType : Parser := optional typeSpec
@[builtinTermParser] def subtype := parser! "{" >> ident >> optType >> " // " >> termParser >> "}"
@[builtinTermParser] def listLit := parser! symbol "[" appPrec >> sepBy termParser "," true >> "]"
@[builtinTermParser] def arrayLit := parser! symbol "#[" appPrec >> sepBy termParser "," true >> "]"
@[builtinTermParser] def explicit := parser! symbol "@" appPrec >> termParser appPrec
@[builtinTermParser] def inaccessible := parser! symbol ".(" appPrec >> termParser >> ")"
def binderIdent : Parser := ident <|> hole
def binderType (requireType := false) : Parser := if requireType then group (" : " >> termParser) else optional (" : " >> termParser)
def binderTactic := parser! try (" := " >> " by ") >> Tactic.nonEmptySeq
def binderDefault := parser! " := " >> termParser
def explicitBinder (requireType := false) := parser! "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")"
def implicitBinder (requireType := false) := parser! "{" >> many1 binderIdent >> binderType requireType >> "}"
def instBinder := parser! "[" >> optIdent >> termParser >> "]"
def bracketedBinder (requireType := false) := explicitBinder requireType <|> implicitBinder requireType <|> instBinder
@[builtinTermParser] def depArrow := parser! bracketedBinder true >> checkRBPGreater 25 "expected parentheses around dependent arrow" >> unicodeSymbol " → " " -> " >> termParser
def simpleBinder := parser! many1 binderIdent
@[builtinTermParser] def «forall» := parser! unicodeSymbol "∀" "forall" leadPrec >> many1 (simpleBinder <|> bracketedBinder) >> ", " >> termParser
def funBinder : Parser := implicitBinder <|> instBinder <|> termParser appPrec
@[builtinTermParser] def «fun» := parser! unicodeSymbol "λ" "fun" leadPrec >> many1 funBinder >> darrow >> termParser
def matchAlt : Parser :=
nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $
sepBy1 termParser ", " >> darrow >> termParser
def matchAlts (optionalFirstBar := true) : Parser :=
withPosition $ fun pos =>
(if optionalFirstBar then optional "|" else "|") >>
sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|")
@[builtinTermParser] def «match» := parser! symbol "match " leadPrec >> sepBy1 termParser ", " >> optType >> " with " >> matchAlts
@[builtinTermParser] def «nomatch» := parser! symbol "nomatch " leadPrec >> termParser
@[builtinTermParser] def «parser!» := parser! symbol "parser! " leadPrec >> termParser
@[builtinTermParser] def «tparser!» := parser! symbol "tparser! " leadPrec >> termParser
@[builtinTermParser] def borrowed := parser! symbol "@&" appPrec >> termParser (appPrec - 1)
@[builtinTermParser] def quotedName := parser! nameLit
-- NOTE: syntax quotations are defined in Init.Lean.Parser.Command
@[builtinTermParser] def «match_syntax» := parser! symbol "match_syntax" leadPrec >> termParser >> " with " >> matchAlts
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many bracketedBinder >> optType
def letIdDecl : Parser := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl $ try (letIdLhs >> " := ") >> termParser
def letPatDecl : Parser := node `Lean.Parser.Term.letDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl : Parser := node `Lean.Parser.Term.letDecl $ letIdLhs >> matchAlts false
def letDecl := letIdDecl <|> letPatDecl <|> letEqnsDecl
@[builtinTermParser] def «let» := parser! symbol "let " leadPrec >> letDecl >> "; " >> termParser
@[builtinTermParser] def «let!» := parser! symbol "let! " leadPrec >> letDecl >> "; " >> termParser
def leftArrow : Parser := unicodeSymbol " ← " " <- "
def doLet := parser! "let " >> letDecl
def doId := parser! try (ident >> optType >> leftArrow) >> termParser
def doPat := parser! try (termParser >> leftArrow) >> termParser >> optional (" | " >> termParser)
def doExpr := parser! termParser
def doElem := doLet <|> doId <|> doPat <|> doExpr
def doSeq := sepBy1 doElem "; "
def bracketedDoSeq := parser! "{" >> doSeq >> "}"
@[builtinTermParser] def liftMethod := parser! leftArrow >> termParser
@[builtinTermParser] def «do» := parser! symbol "do " leadPrec >> (bracketedDoSeq <|> doSeq)
@[builtinTermParser] def nativeRefl := parser! "nativeRefl! " >> termParser appPrec
@[builtinTermParser] def nativeDecide := parser! "nativeDecide! " >> termParser appPrec
@[builtinTermParser] def decide := parser! "decide! " >> termParser appPrec
@[builtinTermParser] def not := parser! symbol "¬" appPrec >> termParser 40
@[builtinTermParser] def bnot := parser! symbol "!" appPrec >> termParser 40
@[builtinTermParser] def uminus := parser! "-" >> termParser 100
def namedArgument := parser! try ("(" >> ident >> " := ") >> termParser >> ")"
@[builtinTermParser] def app := tparser! many1 (namedArgument <|> termParser appPrec)
def checkIsSort := checkStackTop (fun stx => stx.isOfKind `Lean.Parser.Term.type || stx.isOfKind `Lean.Parser.Term.sort)
@[builtinTermParser] def sortApp := tparser! checkIsSort >> levelParser appPrec
@[builtinTermParser] def proj := tparser! symbolNoWs "." (appPrec+1) >> (fieldIdx <|> ident)
@[builtinTermParser] def arrow := tparser! unicodeInfixR " → " " -> " 25
@[builtinTermParser] def arrayRef := tparser! symbolNoWs "[" (appPrec+1) >> termParser >>"]"
@[builtinTermParser] def dollar := tparser! try (dollarSymbol >> checkWsBefore "space expected") >> termParser 0
@[builtinTermParser] def dollarProj := tparser! symbol "$." 1 >> (fieldIdx <|> ident)
@[builtinTermParser] def «where» := tparser! symbol " where " 1 >> sepBy1 letDecl (group ("; " >> " where "))
@[builtinTermParser] def fcomp := tparser! infixR " ∘ " 90
@[builtinTermParser] def prod := tparser! infixR " × " 35
@[builtinTermParser] def add := tparser! infixL " + " 65
@[builtinTermParser] def sub := tparser! infixL " - " 65
@[builtinTermParser] def mul := tparser! infixL " * " 70
@[builtinTermParser] def div := tparser! infixL " / " 70
@[builtinTermParser] def mod := tparser! infixL " % " 70
@[builtinTermParser] def modN := tparser! infixL " %ₙ " 70
@[builtinTermParser] def pow := tparser! infixR " ^ " 80
@[builtinTermParser] def le := tparser! unicodeInfixL " ≤ " " <= " 50
@[builtinTermParser] def ge := tparser! unicodeInfixL " ≥ " " >= " 50
@[builtinTermParser] def lt := tparser! infixL " < " 50
@[builtinTermParser] def gt := tparser! infixL " > " 50
@[builtinTermParser] def eq := tparser! infixL " = " 50
@[builtinTermParser] def ne := tparser! infixL " ≠ " 50
@[builtinTermParser] def beq := tparser! infixL " == " 50
@[builtinTermParser] def bne := tparser! infixL " != " 50
@[builtinTermParser] def heq := tparser! unicodeInfixL " ≅ " " ~= " 50
@[builtinTermParser] def equiv := tparser! infixL " ≈ " 50
@[builtinTermParser] def subst := tparser! symbol " ▸ " 75 >> sepBy1 (termParser 75) " ▸ "
@[builtinTermParser] def and := tparser! unicodeInfixR " ∧ " " /\\ " 35
@[builtinTermParser] def or := tparser! unicodeInfixR " ∨ " " \\/ " 30
@[builtinTermParser] def iff := tparser! unicodeInfixL " ↔ " " <-> " 20
@[builtinTermParser] def band := tparser! infixL " && " 35
@[builtinTermParser] def bor := tparser! infixL " || " 30
@[builtinTermParser] def append := tparser! infixL " ++ " 65
@[builtinTermParser] def cons := tparser! infixR " :: " 67
@[builtinTermParser] def orelse := tparser! infixR " <|> " 2
@[builtinTermParser] def orM := tparser! infixR " <||> " 30
@[builtinTermParser] def andM := tparser! infixR " <&&> " 35
@[builtinTermParser] def andthen := tparser! infixR " >> " 60
@[builtinTermParser] def bindOp := tparser! infixR " >>= " 55
@[builtinTermParser] def mapRev := tparser! infixR " <&> " 100
@[builtinTermParser] def seq := tparser! infixL " <*> " 60
@[builtinTermParser] def seqLeft := tparser! infixL " <* " 60
@[builtinTermParser] def seqRight := tparser! infixR " *> " 60
@[builtinTermParser] def map := tparser! infixR " <$> " 100
@[builtinTermParser] def mapConst := tparser! infixR " <$ " 100
@[builtinTermParser] def mapConstRev := tparser! infixR " $> " 100
@[builtinTermParser] def tacticBlock := parser! symbol "begin " appPrec >> Tactic.seq >> "end"
@[builtinTermParser] def byTactic := parser! symbol "by " leadPrec >> Tactic.nonEmptySeq
-- Use `unboxSingleton` trick similar to the one used at Command.lean for `Term.stxQuot`
@[builtinTermParser] def tacticStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(tactic|" appPrec >> sepBy1 tacticParser "; " true true >> ")"
@[builtinTermParser] def levelStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(level|" appPrec >> levelParser >> ")"
@[builtinTermParser] def funBinderStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(funBinder|" appPrec >> funBinder >> ")"
end Term
end Parser
end Lean
|
391b23db580b97c0a0f2a1b4983ede1e66da6c87 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/algebra/ordered/proj_Icc_auto.lean | f18d0ce1bf848d6f9155e27a166889cbef43af66 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,797 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.algebra.ordered
import Mathlib.data.set.intervals.proj_Icc
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
/-!
# Projection onto a closed interval
In this file we prove that the projection `set.proj_Icc f a b h` is a quotient map, and use it
to show that `Icc_extend h f` is continuous if and only if `f` is continuous.
-/
theorem continuous_proj_Icc {α : Type u_1} [topological_space α] [linear_order α] [order_topology α]
{a : α} {b : α} {h : a ≤ b} : continuous (set.proj_Icc a b h) :=
continuous_subtype_mk (fun (x : α) => set.proj_Icc._proof_1 a b h x)
(continuous.max continuous_const (continuous.min continuous_const continuous_id))
theorem quotient_map_proj_Icc {α : Type u_1} [topological_space α] [linear_order α]
[order_topology α] {a : α} {b : α} {h : a ≤ b} : quotient_map (set.proj_Icc a b h) :=
sorry
@[simp] theorem continuous_Icc_extend_iff {α : Type u_1} {β : Type u_2} [topological_space α]
[linear_order α] [order_topology α] [topological_space β] {a : α} {b : α} {h : a ≤ b}
{f : ↥(set.Icc a b) → β} : continuous (set.Icc_extend h f) ↔ continuous f :=
iff.symm (quotient_map.continuous_iff quotient_map_proj_Icc)
theorem continuous.Icc_extend {α : Type u_1} {β : Type u_2} [topological_space α] [linear_order α]
[order_topology α] [topological_space β] {a : α} {b : α} {h : a ≤ b} {f : ↥(set.Icc a b) → β}
(hf : continuous f) : continuous (set.Icc_extend h f) :=
continuous.comp hf continuous_proj_Icc
end Mathlib |
473ff7958f8395c8d6861004b9a4d0b14b2c7fc5 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/run/one.lean | 177d9dc3c094ed90a077320aabe66ec5c9a8f78a | [
"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 | 326 | lean | inductive one.{l} : Type.{max 1 l} :=
unit : one.{l}
set_option pp.universes true
check one
inductive one2.{l} : Type.{max 1 l} :=
unit : one2
check one2
section foo
universe l2
parameter A : Type.{l2}
inductive wrapper.{l} : Type.{max 1 l l2} :=
mk : A → wrapper.{l2 l}
check wrapper
end foo
check wrapper
|
904395a116a2ff7e512a87e4e4bd9f0ea05ecb50 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/linear_algebra/multilinear/tensor_product.lean | 184a514b7acc2c0a1a9d03fb065e1e1e0a92c6ff | [
"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,518 | lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import linear_algebra.multilinear.basic
import linear_algebra.tensor_product
/-!
# Constructions relating multilinear maps and tensor products.
-/
namespace multilinear_map
section dom_coprod
open_locale tensor_product
variables {R ι₁ ι₂ ι₃ ι₄ : Type*}
variables [comm_semiring R]
variables [decidable_eq ι₁] [decidable_eq ι₂][decidable_eq ι₃] [decidable_eq ι₄]
variables {N₁ : Type*} [add_comm_monoid N₁] [module R N₁]
variables {N₂ : Type*} [add_comm_monoid N₂] [module R N₂]
variables {N : Type*} [add_comm_monoid N] [module R N]
/-- Given two multilinear maps `(ι₁ → N) → N₁` and `(ι₂ → N) → N₂`, this produces the map
`(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂` by taking the coproduct of the domain and the tensor product
of the codomain.
This can be thought of as combining `equiv.sum_arrow_equiv_prod_arrow.symm` with
`tensor_product.map`, noting that the two operations can't be separated as the intermediate result
is not a `multilinear_map`.
While this can be generalized to work for dependent `Π i : ι₁, N'₁ i` instead of `ι₁ → N`, doing so
introduces `sum.elim N'₁ N'₂` types in the result which are difficult to work with and not defeq
to the simple case defined here. See [this zulip thread](
https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Instances.20on.20.60sum.2Eelim.20A.20B.20i.60/near/218484619).
-/
@[simps apply]
def dom_coprod
(a : multilinear_map R (λ _ : ι₁, N) N₁) (b : multilinear_map R (λ _ : ι₂, N) N₂) :
multilinear_map R (λ _ : ι₁ ⊕ ι₂, N) (N₁ ⊗[R] N₂) :=
{ to_fun := λ v, a (λ i, v (sum.inl i)) ⊗ₜ b (λ i, v (sum.inr i)),
map_add' := λ v i p q, by cases i; simp [tensor_product.add_tmul, tensor_product.tmul_add],
map_smul' := λ v i c p, by cases i; simp [tensor_product.smul_tmul', tensor_product.tmul_smul] }
/-- A more bundled version of `multilinear_map.dom_coprod` that maps
`((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/
def dom_coprod' :
multilinear_map R (λ _ : ι₁, N) N₁ ⊗[R] multilinear_map R (λ _ : ι₂, N) N₂ →ₗ[R]
multilinear_map R (λ _ : ι₁ ⊕ ι₂, N) (N₁ ⊗[R] N₂) :=
tensor_product.lift $ linear_map.mk₂ R (dom_coprod)
(λ m₁ m₂ n, by { ext, simp only [dom_coprod_apply, tensor_product.add_tmul, add_apply] })
(λ c m n, by { ext, simp only [dom_coprod_apply, tensor_product.smul_tmul', smul_apply] })
(λ m n₁ n₂, by { ext, simp only [dom_coprod_apply, tensor_product.tmul_add, add_apply] })
(λ c m n, by { ext, simp only [dom_coprod_apply, tensor_product.tmul_smul, smul_apply] })
@[simp]
lemma dom_coprod'_apply
(a : multilinear_map R (λ _ : ι₁, N) N₁) (b : multilinear_map R (λ _ : ι₂, N) N₂) :
dom_coprod' (a ⊗ₜ[R] b) = dom_coprod a b := rfl
/-- When passed an `equiv.sum_congr`, `multilinear_map.dom_dom_congr` distributes over
`multilinear_map.dom_coprod`. -/
lemma dom_coprod_dom_dom_congr_sum_congr
(a : multilinear_map R (λ _ : ι₁, N) N₁) (b : multilinear_map R (λ _ : ι₂, N) N₂)
(σa : ι₁ ≃ ι₃) (σb : ι₂ ≃ ι₄) :
(a.dom_coprod b).dom_dom_congr (σa.sum_congr σb) =
(a.dom_dom_congr σa).dom_coprod (b.dom_dom_congr σb) := rfl
end dom_coprod
end multilinear_map
|
13f482ca5dcff5e2a72228aafb8b03ad5167d463 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/analysis/normed_space/operator_norm.lean | cea32ddc746450e2ce8e5f5bf67c66c24e0f8018 | [
"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 | 33,061 | lean | /-
Copyright (c) 2019 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo
Operator norm on the space of continuous linear maps
Define the operator norm on the space of continuous linear maps between normed spaces, and prove
its basic properties. In particular, show that this space is itself a normed space.
-/
import linear_algebra.finite_dimensional
import analysis.normed_space.riesz_lemma
import analysis.asymptotics
noncomputable theory
open_locale classical
variables {𝕜 : Type*} {E : Type*} {F : Type*} {G : Type*}
[normed_group E] [normed_group F] [normed_group G]
open metric continuous_linear_map
lemma exists_pos_bound_of_bound {f : E → F} (M : ℝ) (h : ∀x, ∥f x∥ ≤ M * ∥x∥) :
∃ N, 0 < N ∧ ∀x, ∥f x∥ ≤ N * ∥x∥ :=
⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), λx, calc
∥f x∥ ≤ M * ∥x∥ : h x
... ≤ max M 1 * ∥x∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _) ⟩
section normed_field
/- Most statements in this file require the field to be non-discrete, as this is necessary
to deduce an inequality `∥f x∥ ≤ C ∥x∥` from the continuity of f. However, the other direction always
holds. In this section, we just assume that `𝕜` is a normed field. In the remainder of the file,
it will be non-discrete. -/
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (f : E →ₗ[𝕜] F)
lemma linear_map.lipschitz_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
lipschitz_with (nnreal.of_real C) f :=
lipschitz_with.of_dist_le' $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
theorem linear_map.antilipschitz_of_bound {K : nnreal} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) :
antilipschitz_with K f :=
antilipschitz_with.of_le_mul_dist $
λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
lemma linear_map.uniform_continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
uniform_continuous f :=
(f.lipschitz_of_bound C h).uniform_continuous
lemma linear_map.continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
continuous f :=
(f.lipschitz_of_bound C h).continuous
/-- Construct a continuous linear map from a linear map and a bound on this linear map.
The fact that the norm of the continuous linear map is then controlled is given in
`linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F :=
⟨f, linear_map.continuous_of_bound f C h⟩
/-- Reinterpret a linear map `𝕜 →ₗ[𝕜] E` as a continuous linear map. This construction
is generalized to the case of any finite dimensional domain
in `linear_map.to_continuous_linear_map`. -/
def linear_map.to_continuous_linear_map₁ (f : 𝕜 →ₗ[𝕜] E) : 𝕜 →L[𝕜] E :=
f.mk_continuous (∥f 1∥) $ λ x, le_of_eq $
by { conv_lhs { rw ← mul_one x }, rw [← smul_eq_mul, f.map_smul, norm_smul, mul_comm] }
/-- Construct a continuous linear map from a linear map and the existence of a bound on this linear
map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will
follow automatically in `linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous_of_exists_bound (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F :=
⟨f, let ⟨C, hC⟩ := h in linear_map.continuous_of_bound f C hC⟩
@[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
((f.mk_continuous C h) : E →ₗ[𝕜] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_apply (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) :
f.mk_continuous C h x = f x := rfl
@[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) :
((f.mk_continuous_of_exists_bound h) : E →ₗ[𝕜] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) :
f.mk_continuous_of_exists_bound h x = f x := rfl
@[simp] lemma linear_map.to_continuous_linear_map₁_coe (f : 𝕜 →ₗ[𝕜] E) :
(f.to_continuous_linear_map₁ : 𝕜 →ₗ[𝕜] E) = f :=
rfl
@[simp] lemma linear_map.to_continuous_linear_map₁_apply (f : 𝕜 →ₗ[𝕜] E) (x) :
f.to_continuous_linear_map₁ x = f x :=
rfl
lemma linear_map.continuous_iff_is_closed_ker {f : E →ₗ[𝕜] 𝕜} :
continuous f ↔ is_closed (f.ker : set E) :=
begin
-- the continuity of f obviously implies that its kernel is closed
refine ⟨λh, (continuous_iff_is_closed.1 h) {0} (t1_space.t1 0), λh, _⟩,
-- for the other direction, we assume that the kernel is closed
by_cases hf : ∀x, x ∈ f.ker,
{ -- if `f = 0`, its continuity is obvious
have : (f : E → 𝕜) = (λx, 0), by { ext x, simpa using hf x },
rw this,
exact continuous_const },
{ /- if `f` is not zero, we use an element `x₀ ∉ ker f` such that `∥x₀∥ ≤ 2 ∥x₀ - y∥` for all
`y ∈ ker f`, given by Riesz's lemma, and prove that `2 ∥f x₀∥ / ∥x₀∥` gives a bound on the
operator norm of `f`. For this, start from an arbitrary `x` and note that
`y = x₀ - (f x₀ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `x₀`
and `y` readily gives the conclusion. -/
push_neg at hf,
let r : ℝ := (2 : ℝ)⁻¹,
have : 0 ≤ r, by norm_num [r],
have : r < 1, by norm_num [r],
obtain ⟨x₀, x₀ker, h₀⟩ : ∃ (x₀ : E), x₀ ∉ f.ker ∧ ∀ y ∈ linear_map.ker f, r * ∥x₀∥ ≤ ∥x₀ - y∥,
from riesz_lemma h hf this,
have : x₀ ≠ 0,
{ assume h,
have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero_mem },
exact x₀ker this },
have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], norm_num },
have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥,
{ assume x,
by_cases hx : f x = 0,
{ rw [hx, norm_zero],
apply_rules [mul_nonneg, norm_nonneg, inv_nonneg.2, norm_nonneg] },
{ let y := x₀ - (f x₀ * (f x)⁻¹ ) • x,
have fy_zero : f y = 0, by calc
f y = f x₀ - (f x₀ * (f x)⁻¹ ) * f x : by simp [y]
... = 0 :
by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl },
have A : r * ∥x₀∥ ≤ ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥, from calc
r * ∥x₀∥ ≤ ∥x₀ - y∥ : h₀ _ (linear_map.mem_ker.2 fy_zero)
... = ∥(f x₀ * (f x)⁻¹ ) • x∥ : by { dsimp [y], congr, abel }
... = ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥ :
by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv],
calc
∥f x∥ = (r * ∥x₀∥)⁻¹ * (r * ∥x₀∥) * ∥f x∥ : by rwa [inv_mul_cancel, one_mul]
... ≤ (r * ∥x₀∥)⁻¹ * (∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥) * ∥f x∥ : begin
apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _),
exact inv_nonneg.2 (mul_nonneg (by norm_num) (norm_nonneg _))
end
... = (∥f x∥ ⁻¹ * ∥f x∥) * (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by ring
... = (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ :
by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } },
exact linear_map.continuous_of_bound f _ this }
end
end normed_field
variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [normed_space 𝕜 G]
(c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E)
include 𝕜
/-- A continuous linear map between normed spaces is bounded when the field is nondiscrete.
The continuity ensures boundedness on a ball of some radius `δ`. The nondiscreteness is then
used to rescale any element into an element of norm in `[δ/C, δ]`, whose image has a controlled norm.
The norm control for the original element follows by rescaling. -/
lemma linear_map.bound_of_continuous (f : E →ₗ[𝕜] F) (hf : continuous f) :
∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) :=
begin
have : continuous_at f 0 := continuous_iff_continuous_at.1 hf _,
rcases metric.tendsto_nhds_nhds.1 this 1 zero_lt_one with ⟨ε, ε_pos, hε⟩,
let δ := ε/2,
have δ_pos : δ > 0 := half_pos ε_pos,
have H : ∀{a}, ∥a∥ ≤ δ → ∥f a∥ ≤ 1,
{ assume a ha,
have : dist (f a) (f 0) ≤ 1,
{ apply le_of_lt (hε _),
rw [dist_eq_norm, sub_zero],
exact lt_of_le_of_lt ha (half_lt_self ε_pos) },
simpa using this },
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
refine ⟨δ⁻¹ * ∥c∥, mul_pos (inv_pos.2 δ_pos) (lt_trans zero_lt_one hc), (λx, _)⟩,
by_cases h : x = 0,
{ simp only [h, norm_zero, mul_zero, linear_map.map_zero] },
{ rcases rescale_to_shell hc δ_pos h with ⟨d, hd, dxle, ledx, dinv⟩,
calc ∥f x∥
= ∥f ((d⁻¹ * d) • x)∥ : by rwa [inv_mul_cancel, one_smul]
... = ∥d∥⁻¹ * ∥f (d • x)∥ :
by rw [mul_smul, linear_map.map_smul, norm_smul, normed_field.norm_inv]
... ≤ ∥d∥⁻¹ * 1 :
mul_le_mul_of_nonneg_left (H dxle) (by { rw ← normed_field.norm_inv, exact norm_nonneg _ })
... ≤ δ⁻¹ * ∥c∥ * ∥x∥ : by { rw mul_one, exact dinv } }
end
namespace continuous_linear_map
theorem bound : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) :=
f.to_linear_map.bound_of_continuous f.2
section
open asymptotics filter
theorem is_O_id (l : filter E) : is_O f (λ x, x) l :=
let ⟨M, hMp, hM⟩ := f.bound in is_O_of_le' l hM
theorem is_O_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) :
is_O (λ x', g (f x')) f l :=
(g.is_O_id ⊤).comp_tendsto le_top
theorem is_O_sub (f : E →L[𝕜] F) (l : filter E) (x : E) :
is_O (λ x', f (x' - x)) (λ x', x' - x) l :=
f.is_O_comp _ l
/-- A linear map which is a homothety is a continuous linear map.
Since the field `𝕜` need not have `ℝ` as a subfield, this theorem is not directly deducible from
the corresponding theorem about isometries plus a theorem about scalar multiplication. Likewise
for the other theorems about homotheties in this file.
-/
def of_homothety (f : E →ₗ[𝕜] F) (a : ℝ) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E →L[𝕜] F :=
f.mk_continuous a (λ x, le_of_eq (hf x))
variable (𝕜)
lemma to_span_singleton_homothety (x : E) (c : 𝕜) : ∥linear_map.to_span_singleton 𝕜 E x c∥ = ∥x∥ * ∥c∥ :=
by {rw mul_comm, exact norm_smul _ _}
/-- Given an element `x` of a normed space `E` over a field `𝕜`, the natural continuous
linear map from `E` to the span of `x`.-/
def to_span_singleton (x : E) : 𝕜 →L[𝕜] E :=
of_homothety (linear_map.to_span_singleton 𝕜 E x) ∥x∥ (to_span_singleton_homothety 𝕜 x)
end
section op_norm
open set real
/-- The operator norm of a continuous linear map is the inf of all its bounds. -/
def op_norm := Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥}
instance has_op_norm : has_norm (E →L[𝕜] F) := ⟨op_norm⟩
lemma norm_def : ∥f∥ = Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} := rfl
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : E →L[𝕜] F} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } :=
let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩
lemma bounds_bdd_below {f : E →L[𝕜] F} :
bdd_below { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } :=
⟨0, λ _ ⟨hn, _⟩, hn⟩
lemma op_norm_nonneg : 0 ≤ ∥f∥ :=
lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx)
/-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/
theorem le_op_norm : ∥f x∥ ≤ ∥f∥ * ∥x∥ :=
classical.by_cases
(λ heq : x = 0, by { rw heq, simp })
(λ hne, have hlt : 0 < ∥x∥, from norm_pos_iff.2 hne,
le_mul_of_div_le hlt ((le_Inf _ bounds_nonempty bounds_bdd_below).2
(λ c ⟨_, hc⟩, div_le_of_le_mul hlt (by { rw mul_comm, apply hc }))))
theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c :=
le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg)
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : lipschitz_with ⟨∥f∥, op_norm_nonneg f⟩ f :=
lipschitz_with.of_dist_le_mul $ λ x y,
by { rw [dist_eq_norm, dist_eq_norm, ←map_sub], apply le_op_norm }
lemma ratio_le_op_norm : ∥f x∥ / ∥x∥ ≤ ∥f∥ :=
(or.elim (lt_or_eq_of_le (norm_nonneg _))
(λ hlt, div_le_of_le_mul hlt (by { rw mul_comm, apply le_op_norm }))
(λ heq, by { rw [←heq, div_zero], apply op_norm_nonneg }))
/-- The image of the unit ball under a continuous linear map is bounded. -/
lemma unit_le_op_norm : ∥x∥ ≤ 1 → ∥f x∥ ≤ ∥f∥ :=
mul_one ∥f∥ ▸ f.le_op_norm_of_le
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) :
∥f∥ ≤ M :=
Inf_le _ bounds_bdd_below ⟨hMp, hM⟩
theorem op_norm_le_of_lipschitz {f : E →L[𝕜] F} {K : nnreal} (hf : lipschitz_with K f) :
∥f∥ ≤ K :=
f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ :=
show ∥f + g∥ ≤ (coe : nnreal → ℝ) (⟨_, f.op_norm_nonneg⟩ + ⟨_, g.op_norm_nonneg⟩),
from op_norm_le_of_lipschitz (f.lipschitz.add g.lipschitz)
/-- An operator is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 :=
iff.intro
(λ hn, continuous_linear_map.ext (λ x, norm_le_zero_iff.1
(calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _
... = _ : by rw [hn, zero_mul])))
(λ hf, le_antisymm (Inf_le _ bounds_bdd_below
⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })⟩)
(op_norm_nonneg _))
@[simp] lemma norm_zero : ∥(0 : E →L[𝕜] F)∥ = 0 :=
by rw op_norm_zero_iff
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial
where it is `0`. It means that one can not do better than an inequality in general. -/
lemma norm_id_le : ∥id 𝕜 E∥ ≤ 1 :=
op_norm_le_bound _ zero_le_one (λx, by simp)
/-- If a space is non-trivial, then the norm of the identity equals `1`. -/
lemma norm_id (h : ∃ x : E, x ≠ 0) : ∥id 𝕜 E∥ = 1 :=
le_antisymm norm_id_le $ let ⟨x, hx⟩ := h in
have _ := (id 𝕜 E).ratio_le_op_norm x,
by rwa [id_apply, div_self (ne_of_gt $ norm_pos_iff.2 hx)] at this
@[simp] lemma norm_id_field : ∥id 𝕜 𝕜∥ = 1 :=
norm_id ⟨1, one_ne_zero⟩
@[simp] lemma norm_id_field' : ∥(1 : 𝕜 →L[𝕜] 𝕜)∥ = 1 :=
norm_id_field
lemma op_norm_smul_le : ∥c • f∥ ≤ ∥c∥ * ∥f∥ :=
((c • f).op_norm_le_bound
(mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (λ _,
begin
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end))
lemma op_norm_neg : ∥-f∥ = ∥f∥ := by { rw norm_def, apply congr_arg, ext, simp }
/-- Continuous linear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (E →L[𝕜] F) :=
normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩
instance to_normed_space : normed_space 𝕜 (E →L[𝕜] F) :=
⟨op_norm_smul_le⟩
/-- The operator norm is submultiplicative. -/
lemma op_norm_comp_le (f : E →L[𝕜] F) : ∥h.comp f∥ ≤ ∥h∥ * ∥f∥ :=
(Inf_le _ bounds_bdd_below
⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x,
by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } ⟩)
/-- A continuous linear map is automatically uniformly continuous. -/
protected theorem uniform_continuous : uniform_continuous f :=
f.lipschitz.uniform_continuous
variable {f}
/-- A continuous linear map is an isometry if and only if it preserves the norm. -/
lemma isometry_iff_norm_image_eq_norm :
isometry f ↔ ∀x, ∥f x∥ = ∥x∥ :=
begin
rw isometry_emetric_iff_metric,
split,
{ assume H x,
have := H x 0,
rwa [dist_eq_norm, dist_eq_norm, f.map_zero, sub_zero, sub_zero] at this },
{ assume H x y,
rw [dist_eq_norm, dist_eq_norm, ← f.map_sub, H] }
end
lemma homothety_norm (hE : 0 < vector_space.dim 𝕜 E) (f : E →L[𝕜] F) {a : ℝ} (ha : 0 ≤ a) (hf : ∀x, ∥f x∥ = a * ∥x∥) :
∥f∥ = a :=
begin
refine le_antisymm_iff.mpr ⟨_, _⟩,
{ exact continuous_linear_map.op_norm_le_bound f ha (λ y, le_of_eq (hf y)) },
{ rw continuous_linear_map.norm_def,
apply real.lb_le_Inf _ continuous_linear_map.bounds_nonempty,
cases dim_pos_iff_exists_ne_zero.mp hE with x hx,
intros c h, rw mem_set_of_eq at h,
apply (mul_le_mul_right (norm_pos_iff.mpr hx)).mp,
rw ← hf x, exact h.2 x }
end
lemma to_span_singleton_norm (x : E) : ∥to_span_singleton 𝕜 x∥ = ∥x∥ :=
begin
refine homothety_norm _ _ (norm_nonneg x) (to_span_singleton_homothety 𝕜 x),
rw dim_of_field, exact cardinal.zero_lt_one,
end
variable (f)
theorem uniform_embedding_of_bound {K : nnreal} (hf : ∀ x, ∥x∥ ≤ K * ∥f x∥) :
uniform_embedding f :=
(f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous
/-- If a continuous linear map is a uniform embedding, then it is expands the distances
by a positive factor.-/
theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) :
∃ K, antilipschitz_with K f :=
begin
obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : ε > 0), ∀ {x y : E}, dist (f x) (f y) < ε → dist x y < 1, from
(uniform_embedding_iff.1 hf).2.2 1 zero_lt_one,
let δ := ε/2,
have δ_pos : δ > 0 := half_pos εpos,
have H : ∀{x}, ∥f x∥ ≤ δ → ∥x∥ ≤ 1,
{ assume x hx,
have : dist x 0 ≤ 1,
{ apply le_of_lt,
apply hε,
simp [dist_eq_norm],
exact lt_of_le_of_lt hx (half_lt_self εpos) },
simpa using this },
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
refine ⟨⟨δ⁻¹, _⟩ * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ λx, _⟩,
exact inv_nonneg.2 (le_of_lt δ_pos),
by_cases hx : f x = 0,
{ have : f x = f 0, by { simp [hx] },
have : x = 0 := (uniform_embedding_iff.1 hf).1 this,
simp [this] },
{ rcases rescale_to_shell hc δ_pos hx with ⟨d, hd, dxle, ledx, dinv⟩,
have : ∥f (d • x)∥ ≤ δ, by simpa,
have : ∥d • x∥ ≤ 1 := H this,
calc ∥x∥ = ∥d∥⁻¹ * ∥d • x∥ :
by rwa [← normed_field.norm_inv, ← norm_smul, ← mul_smul, inv_mul_cancel, one_smul]
... ≤ ∥d∥⁻¹ * 1 :
mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _))
... ≤ δ⁻¹ * ∥c∥ * ∥f x∥ :
by rwa [mul_one] }
end
section completeness
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous linear maps with its norm is also
complete. -/
instance [complete_space F] : complete_space (E →L[𝕜] F) :=
begin
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, clear hf,
-- and establish that the evaluation at any point `v : E` is Cauchy.
have cau : ∀ v, cauchy_seq (λ n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∥v∥, λ n, _, _, _⟩,
{ exact mul_nonneg (b0 n) (norm_nonneg _) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `F` is complete)
-- into a function which we call `G`.
choose G hG using λv, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `G` is linear,
let Glin : E →ₗ[𝕜] F :=
{ to_fun := G,
map_add' := λ v w, begin
have A := hG (v + w),
have B := (hG v).add (hG w),
simp only [map_add] at A B,
exact tendsto_nhds_unique filter.at_top_ne_bot A B,
end,
map_smul' := λ c v, begin
have A := hG (c • v),
have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hG v),
simp only [map_smul] at A B,
exact tendsto_nhds_unique filter.at_top_ne_bot A B
end },
-- and that `G` has norm at most `(b 0 + ∥f 0∥)`.
have Gnorm : ∀ v, ∥G v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥,
{ assume v,
have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (norm_nonneg v),
calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel }
... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _
... ≤ b 0 + ∥f 0∥ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto at_top_ne_bot (hG v).norm (eventually_of_forall _ A) },
-- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Gcont := Glin.mk_continuous _ Gnorm,
use Gcont,
-- Our last task is to establish convergence to `G` in norm.
have : ∀ n, ∥f n - Gcont∥ ≤ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (λ v, _),
have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∥v∥,
{ refine eventually_at_top.2 ⟨n, λ m hm, _⟩,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) },
have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Gcont) v∥)) :=
tendsto.norm (tendsto_const_nhds.sub (hG v)),
exact le_of_tendsto at_top_ne_bot B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (λ n, norm_nonneg _) this b_lim,
end
end completeness
section uniformly_extend
variables [complete_space F] (e : E →L[𝕜] G) (h_dense : dense_range e)
section
variables (h_e : uniform_inducing e)
/-- Extension of a continuous linear map `f : E →L[𝕜] F`, with `E` a normed space and `F` a complete
normed space, along a uniform and dense embedding `e : E →L[𝕜] G`. -/
def extend : G →L[𝕜] F :=
/- extension of `f` is continuous -/
have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous,
/- extension of `f` agrees with `f` on the domain of the embedding `e` -/
have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous,
{ to_fun := (h_e.dense_inducing h_dense).extend f,
map_add' :=
begin
refine is_closed_property2 h_dense (is_closed_eq _ _) _,
{ exact cont.comp (continuous_fst.add continuous_snd) },
{ exact (cont.comp continuous_fst).add (cont.comp continuous_snd) },
{ assume x y, rw ← e.map_add, simp only [eq], exact f.map_add _ _ },
end,
map_smul' := λk,
begin
refine is_closed_property h_dense (is_closed_eq _ _) _,
{ exact cont.comp (continuous_const.smul continuous_id) },
{ exact (continuous_const.smul continuous_id).comp cont },
{ assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ },
end,
cont := cont
}
@[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 :=
begin
apply ext,
refine is_closed_property h_dense (is_closed_eq _ _) _,
{ exact (uniform_continuous_uniformly_extend h_e h_dense uniform_continuous_const).continuous },
{ simp only [zero_apply], exact continuous_const },
{ assume x, exact uniformly_extend_of_ind h_e h_dense uniform_continuous_const x }
end
end
section
variables {N : nnreal} (h_e : ∀x, ∥x∥ ≤ N * ∥e x∥)
local notation `ψ` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing
/-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the norm
of the extension of `f` along `e` is bounded by `N * ∥f∥`. -/
lemma op_norm_extend_le : ∥ψ∥ ≤ N * ∥f∥ :=
begin
have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing,
have eq : ∀x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous,
by_cases N0 : 0 ≤ N,
{ refine op_norm_le_bound ψ _ (is_closed_property h_dense (is_closed_le _ _) _),
{ exact mul_nonneg N0 (norm_nonneg _) },
{ exact continuous_norm.comp (cont ψ) },
{ exact continuous_const.mul continuous_norm },
{ assume x,
rw eq,
calc ∥f x∥ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _
... ≤ ∥f∥ * (N * ∥e x∥) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _)
... ≤ N * ∥f∥ * ∥e x∥ : by rw [mul_comm ↑N ∥f∥, mul_assoc] } },
{ have he : ∀ x : E, x = 0,
{ assume x,
have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0),
rw ← norm_le_zero_iff,
exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) },
have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] },
have hψ : ψ = 0, { rw hf, apply extend_zero },
rw [hψ, hf, norm_zero, norm_zero, mul_zero] }
end
end
end uniformly_extend
end op_norm
/-- The norm of the tensor product of a scalar linear map and of an element of a normed space
is the product of the norms. -/
@[simp] lemma smul_right_norm {c : E →L[𝕜] 𝕜} {f : F} :
∥smul_right c f∥ = ∥c∥ * ∥f∥ :=
begin
refine le_antisymm _ _,
{ apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (λx, _),
calc
∥(c x) • f∥ = ∥c x∥ * ∥f∥ : norm_smul _ _
... ≤ (∥c∥ * ∥x∥) * ∥f∥ :
mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _)
... = ∥c∥ * ∥f∥ * ∥x∥ : by ring },
{ by_cases h : ∥f∥ = 0,
{ rw h, simp [norm_nonneg] },
{ have : 0 < ∥f∥ := lt_of_le_of_ne (norm_nonneg _) (ne.symm h),
rw ← le_div_iff this,
apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) this) (λx, _),
rw [div_mul_eq_mul_div, le_div_iff this],
calc ∥c x∥ * ∥f∥ = ∥c x • f∥ : (norm_smul _ _).symm
... = ∥((smul_right c f) : E → F) x∥ : rfl
... ≤ ∥smul_right c f∥ * ∥x∥ : le_op_norm _ _ } },
end
section restrict_scalars
variable (𝕜)
variables {𝕜' : Type*} [normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
{E' : Type*} [normed_group E'] [normed_space 𝕜' E']
{F' : Type*} [normed_group F'] [normed_space 𝕜' F']
local attribute [instance, priority 500] normed_space.restrict_scalars
/-- `𝕜`-linear continuous function induced by a `𝕜'`-linear continuous function when `𝕜'` is a
normed algebra over `𝕜`. -/
def restrict_scalars (f : E' →L[𝕜'] F') : E' →L[𝕜] F' :=
{ cont := f.cont,
..linear_map.restrict_scalars 𝕜 (f.to_linear_map) }
@[simp, norm_cast] lemma restrict_scalars_coe_eq_coe (f : E' →L[𝕜'] F') :
(f.restrict_scalars 𝕜 : E' →ₗ[𝕜] F') = (f : E' →ₗ[𝕜'] F').restrict_scalars 𝕜 := rfl
@[simp, norm_cast squash] lemma restrict_scalars_coe_eq_coe' (f : E' →L[𝕜'] F') :
(f.restrict_scalars 𝕜 : E' → F') = f := rfl
end restrict_scalars
end continuous_linear_map
namespace continuous_linear_equiv
variable (e : E ≃L[𝕜] F)
protected lemma lipschitz : lipschitz_with (nnnorm (e : E →L[𝕜] F)) e :=
(e : E →L[𝕜] F).lipschitz
protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F →L[𝕜] E)) e :=
e.symm.lipschitz.to_right_inverse e.left_inv
theorem is_O_comp {α : Type*} (f : α → E) (l : filter α) :
asymptotics.is_O (λ x', e (f x')) f l :=
(e : E →L[𝕜] F).is_O_comp f l
theorem is_O_sub (l : filter E) (x : E) :
asymptotics.is_O (λ x', e (x' - x)) (λ x', x' - x) l :=
(e : E →L[𝕜] F).is_O_sub l x
theorem is_O_comp_rev {α : Type*} (f : α → E) (l : filter α) :
asymptotics.is_O f (λ x', e (f x')) l :=
(e.symm.is_O_comp _ l).congr_left $ λ _, e.symm_apply_apply _
theorem is_O_sub_rev (l : filter E) (x : E) :
asymptotics.is_O (λ x', x' - x) (λ x', e (x' - x)) l :=
e.is_O_comp_rev _ _
/-- A continuous linear equiv is a uniform embedding. -/
lemma uniform_embedding : uniform_embedding e :=
e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous
lemma one_le_norm_mul_norm_symm (h : ∃ x : E, x ≠ 0) :
1 ≤ ∥(e : E →L[𝕜] F)∥ * ∥(e.symm : F →L[𝕜] E)∥ :=
begin
rw [mul_comm],
convert (e.symm : F →L[𝕜] E).op_norm_comp_le (e : E →L[𝕜] F),
rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id h]
end
lemma norm_pos (h : ∃ x : E, x ≠ 0) : 0 < ∥(e : E →L[𝕜] F)∥ :=
pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one (e.one_le_norm_mul_norm_symm h)) (norm_nonneg _)
lemma norm_symm_pos (h : ∃ x : E, x ≠ 0) : 0 < ∥(e.symm : F →L[𝕜] E)∥ :=
pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one (e.one_le_norm_mul_norm_symm h)) (norm_nonneg _)
lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ :=
(subsingleton_or_exists_ne (0 : E)).imp id (λ hE, e.norm_symm_pos hE)
lemma subsingleton_or_nnnorm_symm_pos : subsingleton E ∨ 0 < (nnnorm $ (e.symm : F →L[𝕜] E)) :=
subsingleton_or_norm_symm_pos e
lemma homothety_inverse (a : ℝ) (ha : 0 < a) (f : E ≃ₗ[𝕜] F) :
(∀ (x : E), ∥f x∥ = a * ∥x∥) → (∀ (y : F), ∥f.symm y∥ = a⁻¹ * ∥y∥) :=
begin
intros hf y,
calc ∥(f.symm) y∥ = a⁻¹ * (a * ∥ (f.symm) y∥) : _
... = a⁻¹ * ∥f ((f.symm) y)∥ : by rw hf
... = a⁻¹ * ∥y∥ : by simp,
rw [← mul_assoc, inv_mul_cancel (ne_of_lt ha).symm, one_mul],
end
variable (𝕜)
/-- A linear equivalence which is a homothety is a continuous linear equivalence. -/
def of_homothety (f : E ≃ₗ[𝕜] F) (a : ℝ) (ha : 0 < a) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E ≃L[𝕜] F :=
{ to_linear_equiv := f,
continuous_to_fun := f.to_linear_map.continuous_of_bound a (λ x, le_of_eq (hf x)),
continuous_inv_fun := f.symm.to_linear_map.continuous_of_bound a⁻¹
(λ x, le_of_eq (homothety_inverse a ha f hf x)) }
lemma to_span_nonzero_singleton_homothety (x : E) (h : x ≠ 0) (c : 𝕜) :
∥linear_equiv.to_span_nonzero_singleton 𝕜 E x h c∥ = ∥x∥ * ∥c∥ :=
continuous_linear_map.to_span_singleton_homothety _ _ _
/-- Given a nonzero element `x` of a normed space `E` over a field `𝕜`, the natural
continuous linear equivalence from `E` to the span of `x`.-/
def to_span_nonzero_singleton (x : E) (h : x ≠ 0) : 𝕜 ≃L[𝕜] (submodule.span 𝕜 ({x} : set E)) :=
of_homothety 𝕜
(linear_equiv.to_span_nonzero_singleton 𝕜 E x h)
∥x∥
(norm_pos_iff.mpr h)
(to_span_nonzero_singleton_homothety 𝕜 x h)
/-- Given a nonzero element `x` of a normed space `E` over a field `𝕜`, the natural continuous
linear map from the span of `x` to `𝕜`.-/
abbreviation coord (x : E) (h : x ≠ 0) : (submodule.span 𝕜 ({x} : set E)) →L[𝕜] 𝕜 :=
(to_span_nonzero_singleton 𝕜 x h).symm
lemma coord_norm (x : E) (h : x ≠ 0) : ∥coord 𝕜 x h∥ = ∥x∥⁻¹ :=
begin
have hx : 0 < ∥x∥ := (norm_pos_iff.mpr h),
refine continuous_linear_map.homothety_norm _ _ (le_of_lt (inv_pos.mpr hx)) _,
{ rw ← finite_dimensional.findim_eq_dim,
rw ← linear_equiv.findim_eq (linear_equiv.to_span_nonzero_singleton 𝕜 E x h),
rw finite_dimensional.findim_of_field,
have : 0 = ((0:nat) : cardinal) := rfl,
rw this, apply cardinal.nat_cast_lt.mpr, norm_num },
{ intros y,
have : (coord 𝕜 x h) y = (to_span_nonzero_singleton 𝕜 x h).symm y := rfl,
rw this, apply homothety_inverse, exact hx, exact to_span_nonzero_singleton_homothety 𝕜 x h, }
end
end continuous_linear_equiv
lemma linear_equiv.uniform_embedding (e : E ≃ₗ[𝕜] F) (h₁ : continuous e) (h₂ : continuous e.symm) :
uniform_embedding e :=
continuous_linear_equiv.uniform_embedding
{ continuous_to_fun := h₁,
continuous_inv_fun := h₂,
.. e }
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound given to the constructor if it is nonnegative. -/
lemma linear_map.mk_continuous_norm_le (f : E →ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
∥f.mk_continuous C h∥ ≤ C :=
continuous_linear_map.op_norm_le_bound _ hC h
|
e41cbff5ae85e368368416bd0b296e1031421319 | 1a61aba1b67cddccce19532a9596efe44be4285f | /hott/hit/torus.hlean | c7dbdabca38e91c8f34ec111a980837d1ff13e0a | [
"Apache-2.0"
] | permissive | eigengrau/lean | 07986a0f2548688c13ba36231f6cdbee82abf4c6 | f8a773be1112015e2d232661ce616d23f12874d0 | refs/heads/master | 1,610,939,198,566 | 1,441,352,386,000 | 1,441,352,494,000 | 41,903,576 | 0 | 0 | null | 1,441,352,210,000 | 1,441,352,210,000 | null | UTF-8 | Lean | false | false | 3,544 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of the torus
-/
import .two_quotient
open two_quotient eq bool unit relation
namespace torus
definition torus_R (x y : unit) := bool
local infix `⬝r`:75 := @e_closure.trans unit torus_R star star star
local postfix `⁻¹ʳ`:(max+10) := @e_closure.symm unit torus_R star star
local notation `[`:max a `]`:0 := @e_closure.of_rel unit torus_R star star a
inductive torus_Q : Π⦃x y : unit⦄, e_closure torus_R x y → e_closure torus_R x y → Type :=
| Qmk : torus_Q ([ff] ⬝r [tt]) ([tt] ⬝r [ff])
definition torus := two_quotient torus_R torus_Q
definition base : torus := incl0 _ _ star
definition loop1 : base = base := incl1 _ _ ff
definition loop2 : base = base := incl1 _ _ tt
definition surf : loop1 ⬝ loop2 = loop2 ⬝ loop1 :=
incl2 _ _ torus_Q.Qmk
-- protected definition rec {P : torus → Type} (Pb : P base) (Pl1 : Pb =[loop1] Pb)
-- (Pl2 : Pb =[loop2] Pb) (Pf : squareover P fill Pl1 Pl1 Pl2 Pl2)
-- (x : torus) : P x :=
-- sorry
-- example {P : torus → Type} (Pb : P base) (Pl1 : Pb =[loop1] Pb) (Pl2 : Pb =[loop2] Pb)
-- (Pf : squareover P fill Pl1 Pl1 Pl2 Pl2) : torus.rec Pb Pl1 Pl2 Pf base = Pb := idp
-- definition rec_loop1 {P : torus → Type} (Pb : P base) (Pl1 : Pb =[loop1] Pb)
-- (Pl2 : Pb =[loop2] Pb) (Pf : squareover P fill Pl1 Pl1 Pl2 Pl2)
-- : apdo (torus.rec Pb Pl1 Pl2 Pf) loop1 = Pl1 :=
-- sorry
-- definition rec_loop2 {P : torus → Type} (Pb : P base) (Pl1 : Pb =[loop1] Pb)
-- (Pl2 : Pb =[loop2] Pb) (Pf : squareover P fill Pl1 Pl1 Pl2 Pl2)
-- : apdo (torus.rec Pb Pl1 Pl2 Pf) loop2 = Pl2 :=
-- sorry
-- definition rec_surf {P : torus → Type} (Pb : P base) (Pl1 : Pb =[loop1] Pb)
-- (Pl2 : Pb =[loop2] Pb) (Pf : squareover P fill Pl1 Pl1 Pl2 Pl2)
-- : cubeover P rfl1 (apds (torus.rec Pb Pl1 Pl2 Pf) fill) Pf
-- (vdeg_squareover !rec_loop2) (vdeg_squareover !rec_loop2)
-- (vdeg_squareover !rec_loop1) (vdeg_squareover !rec_loop1) :=
-- sorry
protected definition elim {P : Type} (Pb : P) (Pl1 : Pb = Pb) (Pl2 : Pb = Pb)
(Ps : Pl1 ⬝ Pl2 = Pl2 ⬝ Pl1) (x : torus) : P :=
begin
induction x,
{ exact Pb},
{ induction s,
{ exact Pl1},
{ exact Pl2}},
{ induction q, exact Ps},
end
protected definition elim_on [reducible] {P : Type} (x : torus) (Pb : P)
(Pl1 : Pb = Pb) (Pl2 : Pb = Pb) (Ps : Pl1 ⬝ Pl2 = Pl2 ⬝ Pl1) : P :=
torus.elim Pb Pl1 Pl2 Ps x
definition elim_loop1 {P : Type} (Pb : P) (Pl1 : Pb = Pb) (Pl2 : Pb = Pb)
(Ps : Pl1 ⬝ Pl2 = Pl2 ⬝ Pl1) : ap (torus.elim Pb Pl1 Pl2 Ps) loop1 = Pl1 :=
!elim_incl1
definition elim_loop2 {P : Type} (Pb : P) (Pl1 : Pb = Pb) (Pl2 : Pb = Pb)
(Ps : Pl1 ⬝ Pl2 = Pl2 ⬝ Pl1) : ap (torus.elim Pb Pl1 Pl2 Ps) loop2 = Pl2 :=
!elim_incl1
theorem elim_surf {P : Type} (Pb : P) (Pl1 : Pb = Pb) (Pl2 : Pb = Pb)
(Ps : Pl1 ⬝ Pl2 = Pl2 ⬝ Pl1)
: square (ap02 (torus.elim Pb Pl1 Pl2 Ps) surf)
Ps
(!ap_con ⬝ (!elim_loop1 ◾ !elim_loop2))
(!ap_con ⬝ (!elim_loop2 ◾ !elim_loop1)) :=
!elim_incl2
end torus
attribute torus.base [constructor]
attribute /-torus.rec-/ torus.elim [unfold 6] [recursor 6]
--attribute torus.elim_type [unfold 9]
attribute /-torus.rec_on-/ torus.elim_on [unfold 2]
--attribute torus.elim_type_on [unfold 6]
|
52f8ca42ef0cce3419c7536f9466d2a1a46d4245 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/order/filter/bases.lean | 1e6d0b3e82a0c3fb5e5e0ab58e793948fa9bf44f | [
"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 | 37,087 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import order.filter.basic
import data.set.countable
/-!
# Filter bases
A filter basis `B : filter_basis α` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element of
the collection. Compared to filters, filter bases do not require that any set containing
an element of `B` belongs to `B`.
A filter basis `B` can be used to construct `B.filter : filter α` such that a set belongs
to `B.filter` if and only if it contains an element of `B`.
Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → set α`,
the proposition `h : filter.is_basis p s` makes sure the range of `s` bounded by `p`
(ie. `s '' set_of p`) defines a filter basis `h.filter_basis`.
If one already has a filter `l` on `α`, `filter.has_basis l p s` (where `p : ι → Prop`
and `s : ι → set α` as above) means that a set belongs to `l` if and
only if it contains some `s i` with `p i`. It implies `h : filter.is_basis p s`, and
`l = h.filter_basis.filter`. The point of this definition is that checking statements
involving elements of `l` often reduces to checking them on the basis elements.
We define a function `has_basis.index (h : filter.has_basis l p s) (t) (ht : t ∈ l)` that returns
some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual
destruction of `h.mem_iff.mpr ht` using `cases` or `let`.
This file also introduces more restricted classes of bases, involving monotonicity or
countability. In particular, for `l : filter α`, `l.is_countably_generated` means
there is a countable set of sets which generates `s`. This is reformulated in term of bases,
and consequences are derived.
## Main statements
* `has_basis.mem_iff`, `has_basis.mem_of_superset`, `has_basis.mem_of_mem` : restate `t ∈ f`
in terms of a basis;
* `basis_sets` : all sets of a filter form a basis;
* `has_basis.inf`, `has_basis.inf_principal`, `has_basis.prod`, `has_basis.prod_self`,
`has_basis.map`, `has_basis.comap` : combinators to construct filters of `l ⊓ l'`,
`l ⊓ 𝓟 t`, `l ×ᶠ l'`, `l ×ᶠ l`, `l.map f`, `l.comap f` respectively;
* `has_basis.le_iff`, `has_basis.ge_iff`, has_basis.le_basis_iff` : restate `l ≤ l'` in terms
of bases.
* `has_basis.tendsto_right_iff`, `has_basis.tendsto_left_iff`, `has_basis.tendsto_iff` : restate
`tendsto f l l'` in terms of bases.
* `is_countably_generated_iff_exists_antimono_basis` : proves a filter is
countably generated if and only if it admis a basis parametrized by a
decreasing sequence of sets indexed by `ℕ`.
* `tendsto_iff_seq_tendsto ` : an abstract version of "sequentially continuous implies continuous".
## Implementation notes
As with `Union`/`bUnion`/`sUnion`, there are three different approaches to filter bases:
* `has_basis l s`, `s : set (set α)`;
* `has_basis l s`, `s : ι → set α`;
* `has_basis l p s`, `p : ι → Prop`, `s : ι → set α`.
We use the latter one because, e.g., `𝓝 x` in an `emetric_space` or in a `metric_space` has a basis
of this form. The other two can be emulated using `s = id` or `p = λ _, true`.
With this approach sometimes one needs to `simp` the statement provided by the `has_basis`
machinery, e.g., `simp only [exists_prop, true_and]` or `simp only [forall_const]` can help
with the case `p = λ _, true`.
-/
open set filter
open_locale filter classical
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*} {ι' : Type*}
/-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure filter_basis (α : Type*) :=
(sets : set (set α))
(nonempty : sets.nonempty)
(inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y)
instance filter_basis.nonempty_sets (B : filter_basis α) : nonempty B.sets := B.nonempty.to_subtype
/-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as
on paper. -/
@[reducible]
instance {α : Type*}: has_mem (set α) (filter_basis α) := ⟨λ U B, U ∈ B.sets⟩
-- For illustration purposes, the filter basis defining (at_top : filter ℕ)
instance : inhabited (filter_basis ℕ) :=
⟨{ sets := range Ici,
nonempty := ⟨Ici 0, mem_range_self 0⟩,
inter_sets := begin
rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩,
refine ⟨Ici (max n m), mem_range_self _, _⟩,
rintros p p_in,
split ; rw mem_Ici at *,
exact le_of_max_le_left p_in,
exact le_of_max_le_right p_in,
end }⟩
/-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/
protected structure filter.is_basis (p : ι → Prop) (s : ι → set α) : Prop :=
(nonempty : ∃ i, p i)
(inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j)
namespace filter
namespace is_basis
/-- Constructs a filter basis from an indexed family of sets satisfying `is_basis`. -/
protected def filter_basis {p : ι → Prop} {s : ι → set α} (h : is_basis p s) : filter_basis α :=
{ sets := s '' set_of p,
nonempty := let ⟨i, hi⟩ := h.nonempty in ⟨s i, mem_image_of_mem s hi⟩,
inter_sets := by { rintros _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩,
rcases h.inter hi hj with ⟨k, hk, hk'⟩,
exact ⟨_, mem_image_of_mem s hk, hk'⟩ } }
variables {p : ι → Prop} {s : ι → set α} (h : is_basis p s)
lemma mem_filter_basis_iff {U : set α} : U ∈ h.filter_basis ↔ ∃ i, p i ∧ s i = U :=
iff.rfl
end is_basis
end filter
namespace filter_basis
/-- The filter associated to a filter basis. -/
protected def filter (B : filter_basis α) : filter α :=
{ sets := {s | ∃ t ∈ B, t ⊆ s},
univ_sets := let ⟨s, s_in⟩ := B.nonempty in ⟨s, s_in, s.subset_univ⟩,
sets_of_superset := λ x y ⟨s, s_in, h⟩ hxy, ⟨s, s_in, set.subset.trans h hxy⟩,
inter_sets := λ x y ⟨s, s_in, hs⟩ ⟨t, t_in, ht⟩,
let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in in
⟨u, u_in, set.subset.trans u_sub $ set.inter_subset_inter hs ht⟩ }
lemma mem_filter_iff (B : filter_basis α) {U : set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U :=
iff.rfl
lemma mem_filter_of_mem (B : filter_basis α) {U : set α} : U ∈ B → U ∈ B.filter:=
λ U_in, ⟨U, U_in, subset.refl _⟩
lemma eq_infi_principal (B : filter_basis α) : B.filter = ⨅ s : B.sets, 𝓟 s :=
begin
have : directed (≥) (λ (s : B.sets), 𝓟 (s : set α)),
{ rintros ⟨U, U_in⟩ ⟨V, V_in⟩,
rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩,
use [W, W_in],
finish },
ext U,
simp [mem_filter_iff, mem_infi this]
end
protected lemma generate (B : filter_basis α) : generate B.sets = B.filter :=
begin
apply le_antisymm,
{ intros U U_in,
rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩,
exact generate_sets.superset (generate_sets.basic V_in) h },
{ rw sets_iff_generate,
apply mem_filter_of_mem }
end
end filter_basis
namespace filter
namespace is_basis
variables {p : ι → Prop} {s : ι → set α}
/-- Constructs a filter from an indexed family of sets satisfying `is_basis`. -/
protected def filter (h : is_basis p s) : filter α := h.filter_basis.filter
protected lemma mem_filter_iff (h : is_basis p s) {U : set α} :
U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U :=
begin
erw [h.filter_basis.mem_filter_iff],
simp only [mem_filter_basis_iff h, exists_prop],
split,
{ rintros ⟨_, ⟨i, pi, rfl⟩, h⟩,
tauto },
{ tauto }
end
lemma filter_eq_generate (h : is_basis p s) : h.filter = generate {U | ∃ i, p i ∧ s i = U} :=
by erw h.filter_basis.generate ; refl
end is_basis
/-- We say that a filter `l` has a basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/
protected structure has_basis (l : filter α) (p : ι → Prop) (s : ι → set α) : Prop :=
(mem_iff' : ∀ (t : set α), t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t)
section same_type
variables {l l' : filter α} {p : ι → Prop} {s : ι → set α} {t : set α} {i : ι}
{p' : ι' → Prop} {s' : ι' → set α} {i' : ι'}
lemma has_basis_generate (s : set (set α)) :
(generate s).has_basis (λ t, finite t ∧ t ⊆ s) (λ t, ⋂₀ t) :=
⟨begin
intro U,
rw mem_generate_iff,
apply exists_congr,
tauto
end⟩
/-- The smallest filter basis containing a given collection of sets. -/
def filter_basis.of_sets (s : set (set α)) : filter_basis α :=
{ sets := sInter '' { t | finite t ∧ t ⊆ s},
nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩,
inter_sets := begin
rintros _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩,
exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩,
by rw sInter_union⟩,
end }
/-- Definition of `has_basis` unfolded with implicit set argument. -/
lemma has_basis.mem_iff (hl : l.has_basis p s) : t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t :=
hl.mem_iff' t
lemma has_basis_iff : l.has_basis p s ↔ ∀ t, t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t :=
⟨λ ⟨h⟩, h, λ h, ⟨h⟩⟩
lemma has_basis.ex_mem (h : l.has_basis p s) : ∃ i, p i :=
let ⟨i, pi, h⟩ := h.mem_iff.mp univ_mem_sets in ⟨i, pi⟩
protected lemma has_basis.nonempty (h : l.has_basis p s) : nonempty ι :=
nonempty_of_exists h.ex_mem
protected lemma is_basis.has_basis (h : is_basis p s) : has_basis h.filter p s :=
⟨λ t, by simp only [h.mem_filter_iff, exists_prop]⟩
lemma has_basis.mem_of_superset (hl : l.has_basis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l :=
(hl.mem_iff).2 ⟨i, hi, ht⟩
lemma has_basis.mem_of_mem (hl : l.has_basis p s) (hi : p i) : s i ∈ l :=
hl.mem_of_superset hi $ subset.refl _
/-- Index of a basis set such that `s i ⊆ t` as an element of `subtype p`. -/
noncomputable def has_basis.index (h : l.has_basis p s) (t : set α) (ht : t ∈ l) :
{i : ι // p i} :=
⟨(h.mem_iff.1 ht).some, (h.mem_iff.1 ht).some_spec.fst⟩
lemma has_basis.property_index (h : l.has_basis p s) (ht : t ∈ l) : p (h.index t ht) :=
(h.index t ht).2
lemma has_basis.set_index_mem (h : l.has_basis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l :=
h.mem_of_mem $ h.property_index _
lemma has_basis.set_index_subset (h : l.has_basis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t :=
(h.mem_iff.1 ht).some_spec.snd
lemma has_basis.is_basis (h : l.has_basis p s) : is_basis p s :=
{ nonempty := let ⟨i, hi, H⟩ := h.mem_iff.mp univ_mem_sets in ⟨i, hi⟩,
inter := λ i j hi hj, by simpa [h.mem_iff]
using l.inter_sets (h.mem_of_mem hi) (h.mem_of_mem hj) }
lemma has_basis.filter_eq (h : l.has_basis p s) : h.is_basis.filter = l :=
by { ext U, simp [h.mem_iff, is_basis.mem_filter_iff] }
lemma has_basis.eq_generate (h : l.has_basis p s) : l = generate { U | ∃ i, p i ∧ s i = U } :=
by rw [← h.is_basis.filter_eq_generate, h.filter_eq]
lemma generate_eq_generate_inter (s : set (set α)) :
generate s = generate (sInter '' { t | finite t ∧ t ⊆ s}) :=
by erw [(filter_basis.of_sets s).generate, ← (has_basis_generate s).filter_eq] ; refl
lemma of_sets_filter_eq_generate (s : set (set α)) : (filter_basis.of_sets s).filter = generate s :=
by rw [← (filter_basis.of_sets s).generate, generate_eq_generate_inter s] ; refl
lemma has_basis.to_has_basis' (hl : l.has_basis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → s' i' ∈ l) : l.has_basis p' s' :=
begin
refine ⟨λ t, ⟨λ ht, _, λ ⟨i', hi', ht⟩, mem_sets_of_superset (h' i' hi') ht⟩⟩,
rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩,
rcases h i hi with ⟨i', hi', hs's⟩,
exact ⟨i', hi', subset.trans hs's ht⟩
end
lemma has_basis.to_has_basis (hl : l.has_basis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.has_basis p' s' :=
hl.to_has_basis' h $ λ i' hi', let ⟨i, hi, hss'⟩ := h' i' hi' in hl.mem_iff.2 ⟨i, hi, hss'⟩
lemma has_basis.to_subset (hl : l.has_basis p s) {t : ι → set α} (h : ∀ i, p i → t i ⊆ s i)
(ht : ∀ i, p i → t i ∈ l) : l.has_basis p t :=
hl.to_has_basis' (λ i hi, ⟨i, hi, h i hi⟩) ht
lemma has_basis.eventually_iff (hl : l.has_basis p s) {q : α → Prop} :
(∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x :=
by simpa using hl.mem_iff
lemma has_basis.frequently_iff (hl : l.has_basis p s) {q : α → Prop} :
(∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x :=
by simp [filter.frequently, hl.eventually_iff]
lemma has_basis.exists_iff (hl : l.has_basis p s) {P : set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) :
(∃ s ∈ l, P s) ↔ ∃ (i) (hi : p i), P (s i) :=
⟨λ ⟨s, hs, hP⟩, let ⟨i, hi, his⟩ := hl.mem_iff.1 hs in ⟨i, hi, mono his hP⟩,
λ ⟨i, hi, hP⟩, ⟨s i, hl.mem_of_mem hi, hP⟩⟩
lemma has_basis.forall_iff (hl : l.has_basis p s) {P : set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) :
(∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) :=
⟨λ H i hi, H (s i) $ hl.mem_of_mem hi,
λ H s hs, let ⟨i, hi, his⟩ := hl.mem_iff.1 hs in mono his (H i hi)⟩
lemma has_basis.ne_bot_iff (hl : l.has_basis p s) :
ne_bot l ↔ (∀ {i}, p i → (s i).nonempty) :=
forall_sets_nonempty_iff_ne_bot.symm.trans $ hl.forall_iff $ λ _ _, nonempty.mono
lemma has_basis.eq_bot_iff (hl : l.has_basis p s) :
l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ :=
not_iff_not.1 $ ne_bot_iff.symm.trans $ hl.ne_bot_iff.trans $
by simp only [not_exists, not_and, ← ne_empty_iff_nonempty]
lemma basis_sets (l : filter α) : l.has_basis (λ s : set α, s ∈ l) id :=
⟨λ t, exists_sets_subset_iff.symm⟩
lemma has_basis_self {l : filter α} {P : set α → Prop} :
has_basis l (λ s, s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t :=
begin
simp only [has_basis_iff, exists_prop, id, and_assoc],
exact forall_congr (λ s, ⟨λ h, h.1, λ h, ⟨h, λ ⟨t, hl, hP, hts⟩, mem_sets_of_superset hl hts⟩⟩)
end
/-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that
`p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/
lemma has_basis.restrict (h : l.has_basis p s) {q : ι → Prop}
(hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) :
l.has_basis (λ i, p i ∧ q i) s :=
begin
refine ⟨λ t, ⟨λ ht, _, λ ⟨i, hpi, hti⟩, h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩,
rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩,
rcases hq i hpi with ⟨j, hpj, hqj, hji⟩,
exact ⟨j, ⟨hpj, hqj⟩, subset.trans hji hti⟩
end
/-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}`
is a basis of `l`. -/
lemma has_basis.restrict_subset (h : l.has_basis p s) {V : set α} (hV : V ∈ l) :
l.has_basis (λ i, p i ∧ s i ⊆ V) s :=
h.restrict $ λ i hi, (h.mem_iff.1 (inter_mem_sets hV (h.mem_of_mem hi))).imp $
λ j hj, ⟨hj.fst, subset_inter_iff.1 hj.snd⟩
lemma has_basis.has_basis_self_subset {p : set α → Prop} (h : l.has_basis (λ s, s ∈ l ∧ p s) id)
{V : set α} (hV : V ∈ l) : l.has_basis (λ s, s ∈ l ∧ p s ∧ s ⊆ V) id :=
by simpa only [and_assoc] using h.restrict_subset hV
theorem has_basis.ge_iff (hl' : l'.has_basis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l :=
⟨λ h i' hi', h $ hl'.mem_of_mem hi',
λ h s hs, let ⟨i', hi', hs⟩ := hl'.mem_iff.1 hs in mem_sets_of_superset (h _ hi') hs⟩
theorem has_basis.le_iff (hl : l.has_basis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i (hi : p i), s i ⊆ t :=
by simp only [le_def, hl.mem_iff]
theorem has_basis.le_basis_iff (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
l ≤ l' ↔ ∀ i', p' i' → ∃ i (hi : p i), s i ⊆ s' i' :=
by simp only [hl'.ge_iff, hl.mem_iff]
lemma has_basis.ext (hl : l.has_basis p s) (hl' : l'.has_basis p' s')
(h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l = l' :=
begin
apply le_antisymm,
{ rw hl.le_basis_iff hl',
simpa using h' },
{ rw hl'.le_basis_iff hl,
simpa using h },
end
lemma has_basis.inf (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
(l ⊓ l').has_basis (λ i : ι × ι', p i.1 ∧ p' i.2) (λ i, s i.1 ∩ s' i.2) :=
⟨begin
intro t,
simp only [mem_inf_sets, exists_prop, hl.mem_iff, hl'.mem_iff],
split,
{ rintros ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, H⟩,
use [(i, i'), ⟨hi, hi'⟩, subset.trans (inter_subset_inter ht ht') H] },
{ rintros ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩,
use [s i, i, hi, subset.refl _, s' i', i', hi', subset.refl _, H] }
end⟩
lemma has_basis_principal (t : set α) : (𝓟 t).has_basis (λ i : unit, true) (λ i, t) :=
⟨λ U, by simp⟩
lemma has_basis.sup (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
(l ⊔ l').has_basis (λ i : ι × ι', p i.1 ∧ p' i.2) (λ i, s i.1 ∪ s' i.2) :=
⟨begin
intros t,
simp only [mem_sup_sets, hl.mem_iff, hl'.mem_iff, prod.exists, union_subset_iff, exists_prop,
and_assoc, exists_and_distrib_left],
simp only [← and_assoc, exists_and_distrib_right, and_comm]
end⟩
lemma has_basis.inf_principal (hl : l.has_basis p s) (s' : set α) :
(l ⊓ 𝓟 s').has_basis p (λ i, s i ∩ s') :=
⟨λ t, by simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_set_of_eq,
mem_inter_iff, and_imp]⟩
lemma has_basis.inf_basis_ne_bot_iff (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
ne_bot (l ⊓ l') ↔ ∀ ⦃i⦄ (hi : p i) ⦃i'⦄ (hi' : p' i'), (s i ∩ s' i').nonempty :=
(hl.inf hl').ne_bot_iff.trans $ by simp [@forall_swap _ ι']
lemma has_basis.inf_ne_bot_iff (hl : l.has_basis p s) :
ne_bot (l ⊓ l') ↔ ∀ ⦃i⦄ (hi : p i) ⦃s'⦄ (hs' : s' ∈ l'), (s i ∩ s').nonempty :=
hl.inf_basis_ne_bot_iff l'.basis_sets
lemma has_basis.inf_principal_ne_bot_iff (hl : l.has_basis p s) {t : set α} :
ne_bot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄ (hi : p i), (s i ∩ t).nonempty :=
(hl.inf_principal t).ne_bot_iff
lemma inf_ne_bot_iff :
ne_bot (l ⊓ l') ↔ ∀ ⦃s : set α⦄ (hs : s ∈ l) ⦃s'⦄ (hs' : s' ∈ l'), (s ∩ s').nonempty :=
l.basis_sets.inf_ne_bot_iff
lemma inf_principal_ne_bot_iff {s : set α} :
ne_bot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).nonempty :=
l.basis_sets.inf_principal_ne_bot_iff
lemma inf_eq_bot_iff {f g : filter α} :
f ⊓ g = ⊥ ↔ ∃ (U ∈ f) (V ∈ g), U ∩ V = ∅ :=
not_iff_not.1 $ ne_bot_iff.symm.trans $ inf_ne_bot_iff.trans $
by simp [← ne_empty_iff_nonempty]
protected lemma disjoint_iff {f g : filter α} :
disjoint f g ↔ ∃ (U ∈ f) (V ∈ g), U ∩ V = ∅ :=
disjoint_iff.trans inf_eq_bot_iff
lemma mem_iff_inf_principal_compl {f : filter α} {s : set α} :
s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ :=
begin
refine not_iff_not.1 ((inf_principal_ne_bot_iff.trans _).symm.trans ne_bot_iff),
exact ⟨λ h hs, by simpa [empty_not_nonempty] using h s hs,
λ hs t ht, inter_compl_nonempty_iff.2 $ λ hts, hs $ mem_sets_of_superset ht hts⟩,
end
lemma not_mem_iff_inf_principal_compl {f : filter α} {s : set α} :
s ∉ f ↔ ne_bot (f ⊓ 𝓟 sᶜ) :=
(not_congr mem_iff_inf_principal_compl).trans ne_bot_iff.symm
lemma mem_iff_disjoint_principal_compl {f : filter α} {s : set α} :
s ∈ f ↔ disjoint f (𝓟 sᶜ) :=
mem_iff_inf_principal_compl.trans disjoint_iff.symm
lemma le_iff_forall_disjoint_principal_compl {f g : filter α} :
f ≤ g ↔ ∀ V ∈ g, disjoint f (𝓟 Vᶜ) :=
forall_congr $ λ _, forall_congr $ λ _, mem_iff_disjoint_principal_compl
lemma le_iff_forall_inf_principal_compl {f g : filter α} :
f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ :=
forall_congr $ λ _, forall_congr $ λ _, mem_iff_inf_principal_compl
lemma inf_ne_bot_iff_frequently_left {f g : filter α} :
ne_bot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x :=
by simpa only [inf_ne_bot_iff, frequently_iff, exists_prop, and_comm]
lemma inf_ne_bot_iff_frequently_right {f g : filter α} :
ne_bot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x :=
by { rw inf_comm, exact inf_ne_bot_iff_frequently_left }
lemma has_basis.eq_binfi (h : l.has_basis p s) :
l = ⨅ i (_ : p i), 𝓟 (s i) :=
eq_binfi_of_mem_sets_iff_exists_mem $ λ t, by simp only [h.mem_iff, mem_principal_sets]
lemma has_basis.eq_infi (h : l.has_basis (λ _, true) s) :
l = ⨅ i, 𝓟 (s i) :=
by simpa only [infi_true] using h.eq_binfi
lemma has_basis_infi_principal {s : ι → set α} (h : directed (≥) s) [nonempty ι] :
(⨅ i, 𝓟 (s i)).has_basis (λ _, true) s :=
⟨begin
refine λ t, (mem_infi (h.mono_comp _ _) t).trans $
by simp only [exists_prop, true_and, mem_principal_sets],
exact λ _ _, principal_mono.2
end⟩
/-- If `s : ι → set α` is an indexed family of sets, then finite intersections of `s i` form a basis
of `⨅ i, 𝓟 (s i)`. -/
lemma has_basis_infi_principal_finite (s : ι → set α) :
(⨅ i, 𝓟 (s i)).has_basis (λ t : set ι, finite t) (λ t, ⋂ i ∈ t, s i) :=
begin
refine ⟨λ U, (mem_infi_finite _).trans _⟩,
simp only [infi_principal_finset, mem_Union, mem_principal_sets, exists_prop,
exists_finite_iff_finset, finset.set_bInter_coe]
end
lemma has_basis_binfi_principal {s : β → set α} {S : set β} (h : directed_on (s ⁻¹'o (≥)) S)
(ne : S.nonempty) :
(⨅ i ∈ S, 𝓟 (s i)).has_basis (λ i, i ∈ S) s :=
⟨begin
refine λ t, (mem_binfi _ ne).trans $ by simp only [mem_principal_sets],
rw [directed_on_iff_directed, ← directed_comp, (∘)] at h ⊢,
apply h.mono_comp _ _,
exact λ _ _, principal_mono.2
end⟩
lemma has_basis_binfi_principal'
(h : ∀ i, p i → ∀ j, p j → ∃ k (h : p k), s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) :
(⨅ i (h : p i), 𝓟 (s i)).has_basis p s :=
filter.has_basis_binfi_principal h ne
lemma has_basis.map (f : α → β) (hl : l.has_basis p s) :
(l.map f).has_basis p (λ i, f '' (s i)) :=
⟨λ t, by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩
lemma has_basis.comap (f : β → α) (hl : l.has_basis p s) :
(l.comap f).has_basis p (λ i, f ⁻¹' (s i)) :=
⟨begin
intro t,
simp only [mem_comap_sets, exists_prop, hl.mem_iff],
split,
{ rintros ⟨t', ⟨i, hi, ht'⟩, H⟩,
exact ⟨i, hi, subset.trans (preimage_mono ht') H⟩ },
{ rintros ⟨i, hi, H⟩,
exact ⟨s i, ⟨i, hi, subset.refl _⟩, H⟩ }
end⟩
lemma comap_has_basis (f : α → β) (l : filter β) :
has_basis (comap f l) (λ s : set β, s ∈ l) (λ s, f ⁻¹' s) :=
⟨λ t, mem_comap_sets⟩
lemma has_basis.prod_self (hl : l.has_basis p s) :
(l ×ᶠ l).has_basis p (λ i, (s i).prod (s i)) :=
⟨begin
intro t,
apply mem_prod_iff.trans,
split,
{ rintros ⟨t₁, ht₁, t₂, ht₂, H⟩,
rcases hl.mem_iff.1 (inter_mem_sets ht₁ ht₂) with ⟨i, hi, ht⟩,
exact ⟨i, hi, λ p ⟨hp₁, hp₂⟩, H ⟨(ht hp₁).1, (ht hp₂).2⟩⟩ },
{ rintros ⟨i, hi, H⟩,
exact ⟨s i, hl.mem_of_mem hi, s i, hl.mem_of_mem hi, H⟩ }
end⟩
lemma mem_prod_self_iff {s} : s ∈ l ×ᶠ l ↔ ∃ t ∈ l, set.prod t t ⊆ s :=
l.basis_sets.prod_self.mem_iff
lemma has_basis.sInter_sets (h : has_basis l p s) :
⋂₀ l.sets = ⋂ i ∈ set_of p, s i :=
begin
ext x,
suffices : (∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i,
by simpa only [mem_Inter, mem_set_of_eq, mem_sInter],
simp_rw h.mem_iff,
split,
{ intros h i hi,
exact h (s i) ⟨i, hi, subset.refl _⟩ },
{ rintros h _ ⟨i, hi, sub⟩,
exact sub (h i hi) },
end
variables [preorder ι] (l p s)
/-- `is_antimono_basis p s` means the image of `s` bounded by `p` is a filter basis
such that `s` is decreasing and `p` is increasing, ie `i ≤ j → p i → p j`. -/
structure is_antimono_basis extends is_basis p s : Prop :=
(decreasing : ∀ {i j}, p i → p j → i ≤ j → s j ⊆ s i)
(mono : monotone p)
/-- We say that a filter `l` has a antimono basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`,
and `s` is decreasing and `p` is increasing, ie `i ≤ j → p i → p j`. -/
structure has_antimono_basis [preorder ι] (l : filter α) (p : ι → Prop) (s : ι → set α)
extends has_basis l p s : Prop :=
(decreasing : ∀ {i j}, p i → p j → i ≤ j → s j ⊆ s i)
(mono : monotone p)
end same_type
section two_types
variables {la : filter α} {pa : ι → Prop} {sa : ι → set α}
{lb : filter β} {pb : ι' → Prop} {sb : ι' → set β} {f : α → β}
lemma has_basis.tendsto_left_iff (hla : la.has_basis pa sa) :
tendsto f la lb ↔ ∀ t ∈ lb, ∃ i (hi : pa i), ∀ x ∈ sa i, f x ∈ t :=
by { simp only [tendsto, (hla.map f).le_iff, image_subset_iff], refl }
lemma has_basis.tendsto_right_iff (hlb : lb.has_basis pb sb) :
tendsto f la lb ↔ ∀ i (hi : pb i), ∀ᶠ x in la, f x ∈ sb i :=
by simp only [tendsto, hlb.ge_iff, mem_map, filter.eventually]
lemma has_basis.tendsto_iff (hla : la.has_basis pa sa) (hlb : lb.has_basis pb sb) :
tendsto f la lb ↔ ∀ ib (hib : pb ib), ∃ ia (hia : pa ia), ∀ x ∈ sa ia, f x ∈ sb ib :=
by simp [hlb.tendsto_right_iff, hla.eventually_iff]
lemma tendsto.basis_left (H : tendsto f la lb) (hla : la.has_basis pa sa) :
∀ t ∈ lb, ∃ i (hi : pa i), ∀ x ∈ sa i, f x ∈ t :=
hla.tendsto_left_iff.1 H
lemma tendsto.basis_right (H : tendsto f la lb) (hlb : lb.has_basis pb sb) :
∀ i (hi : pb i), ∀ᶠ x in la, f x ∈ sb i :=
hlb.tendsto_right_iff.1 H
lemma tendsto.basis_both (H : tendsto f la lb) (hla : la.has_basis pa sa)
(hlb : lb.has_basis pb sb) :
∀ ib (hib : pb ib), ∃ ia (hia : pa ia), ∀ x ∈ sa ia, f x ∈ sb ib :=
(hla.tendsto_iff hlb).1 H
lemma has_basis.prod (hla : la.has_basis pa sa) (hlb : lb.has_basis pb sb) :
(la ×ᶠ lb).has_basis (λ i : ι × ι', pa i.1 ∧ pb i.2) (λ i, (sa i.1).prod (sb i.2)) :=
(hla.comap prod.fst).inf (hlb.comap prod.snd)
lemma has_basis.prod' {la : filter α} {lb : filter β} {ι : Type*} {p : ι → Prop}
{sa : ι → set α} {sb : ι → set β}
(hla : la.has_basis p sa) (hlb : lb.has_basis p sb)
(h_dir : ∀ {i j}, p i → p j → ∃ k, p k ∧ sa k ⊆ sa i ∧ sb k ⊆ sb j) :
(la ×ᶠ lb).has_basis p (λ i, (sa i).prod (sb i)) :=
⟨begin
intros t,
rw mem_prod_iff,
split,
{ rintros ⟨u, u_in, v, v_in, huv⟩,
rcases hla.mem_iff.mp u_in with ⟨i, hi, si⟩,
rcases hlb.mem_iff.mp v_in with ⟨j, hj, sj⟩,
rcases h_dir hi hj with ⟨k, hk, ki, kj⟩,
use [k, hk],
calc
(sa k).prod (sb k) ⊆ (sa i).prod (sb j) : set.prod_mono ki kj
... ⊆ u.prod v : set.prod_mono si sj
... ⊆ t : huv, },
{ rintro ⟨i, hi, h⟩,
exact ⟨sa i, hla.mem_of_mem hi, sb i, hlb.mem_of_mem hi, h⟩ },
end⟩
end two_types
/-- `is_countably_generated f` means `f = generate s` for some countable `s`. -/
def is_countably_generated (f : filter α) : Prop :=
∃ s : set (set α), countable s ∧ f = generate s
/-- `is_countable_basis p s` means the image of `s` bounded by `p` is a countable filter basis. -/
structure is_countable_basis (p : ι → Prop) (s : ι → set α) extends is_basis p s : Prop :=
(countable : countable $ set_of p)
/-- We say that a filter `l` has a countable basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`, and the set
defined by `p` is countable. -/
structure has_countable_basis (l : filter α) (p : ι → Prop) (s : ι → set α)
extends has_basis l p s : Prop :=
(countable : countable $ set_of p)
/-- A countable filter basis `B` on a type `α` is a nonempty countable collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure countable_filter_basis (α : Type*) extends filter_basis α :=
(countable : countable sets)
-- For illustration purposes, the countable filter basis defining (at_top : filter ℕ)
instance nat.inhabited_countable_filter_basis : inhabited (countable_filter_basis ℕ) :=
⟨{ countable := countable_range (λ n, Ici n),
..(default $ filter_basis ℕ),}⟩
lemma antimono_seq_of_seq (s : ℕ → set α) :
∃ t : ℕ → set α, (∀ i j, i ≤ j → t j ⊆ t i) ∧ (⨅ i, 𝓟 $ s i) = ⨅ i, 𝓟 (t i) :=
begin
use λ n, ⋂ m ≤ n, s m, split,
{ exact λ i j hij, bInter_mono' (Iic_subset_Iic.2 hij) (λ n hn, subset.refl _) },
apply le_antisymm; rw le_infi_iff; intro i,
{ rw le_principal_iff, refine (bInter_mem_sets (finite_le_nat _)).2 (λ j hji, _),
rw ← le_principal_iff, apply infi_le_of_le j _, apply le_refl _ },
{ apply infi_le_of_le i _, rw principal_mono, intro a, simp, intro h, apply h, refl },
end
lemma countable_binfi_eq_infi_seq [complete_lattice α] {B : set ι} (Bcbl : countable B)
(Bne : B.nonempty) (f : ι → α) :
∃ (x : ℕ → ι), (⨅ t ∈ B, f t) = ⨅ i, f (x i) :=
begin
rw countable_iff_exists_surjective_to_subtype Bne at Bcbl,
rcases Bcbl with ⟨g, gsurj⟩,
rw infi_subtype',
use (λ n, g n), apply le_antisymm; rw le_infi_iff,
{ intro i, apply infi_le_of_le (g i) _, apply le_refl _ },
{ intros a, rcases gsurj a with ⟨i, rfl⟩, apply infi_le }
end
lemma countable_binfi_eq_infi_seq' [complete_lattice α] {B : set ι} (Bcbl : countable B) (f : ι → α)
{i₀ : ι} (h : f i₀ = ⊤) :
∃ (x : ℕ → ι), (⨅ t ∈ B, f t) = ⨅ i, f (x i) :=
begin
cases B.eq_empty_or_nonempty with hB Bnonempty,
{ rw [hB, infi_emptyset],
use λ n, i₀,
simp [h] },
{ exact countable_binfi_eq_infi_seq Bcbl Bnonempty f }
end
lemma countable_binfi_principal_eq_seq_infi {B : set (set α)} (Bcbl : countable B) :
∃ (x : ℕ → set α), (⨅ t ∈ B, 𝓟 t) = ⨅ i, 𝓟 (x i) :=
countable_binfi_eq_infi_seq' Bcbl 𝓟 principal_univ
namespace is_countably_generated
/-- A set generating a countably generated filter. -/
def generating_set {f : filter α} (h : is_countably_generated f) :=
classical.some h
lemma countable_generating_set {f : filter α} (h : is_countably_generated f) :
countable h.generating_set :=
(classical.some_spec h).1
lemma eq_generate {f : filter α} (h : is_countably_generated f) :
f = generate h.generating_set :=
(classical.some_spec h).2
/-- A countable filter basis for a countably generated filter. -/
def countable_filter_basis {l : filter α} (h : is_countably_generated l) :
countable_filter_basis α :=
{ countable := (countable_set_of_finite_subset h.countable_generating_set).image _,
..filter_basis.of_sets (h.generating_set) }
lemma filter_basis_filter {l : filter α} (h : is_countably_generated l) :
h.countable_filter_basis.to_filter_basis.filter = l :=
begin
conv_rhs { rw h.eq_generate },
apply of_sets_filter_eq_generate,
end
lemma has_countable_basis {l : filter α} (h : is_countably_generated l) :
l.has_countable_basis (λ t, finite t ∧ t ⊆ h.generating_set) (λ t, ⋂₀ t) :=
⟨by convert has_basis_generate _ ; exact h.eq_generate,
countable_set_of_finite_subset h.countable_generating_set⟩
lemma exists_countable_infi_principal {f : filter α} (h : f.is_countably_generated) :
∃ s : set (set α), countable s ∧ f = ⨅ t ∈ s, 𝓟 t :=
begin
let B := h.countable_filter_basis,
use [B.sets, B.countable],
rw ← h.filter_basis_filter,
rw B.to_filter_basis.eq_infi_principal,
rw infi_subtype''
end
lemma exists_seq {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, f = ⨅ i, 𝓟 (x i) :=
begin
rcases cblb.exists_countable_infi_principal with ⟨B, Bcbl, rfl⟩,
exact countable_binfi_principal_eq_seq_infi Bcbl,
end
/-- If `f` is countably generated and `f.has_basis p s`, then `f` admits a decreasing basis
enumerated by natural numbers such that all sets have the form `s i`. More precisely, there is a
sequence `i n` such that `p (i n)` for all `n` and `s (i n)` is a decreasing sequence of sets which
forms a basis of `f`-/
lemma exists_antimono_subbasis {f : filter α} (cblb : f.is_countably_generated)
{p : ι → Prop} {s : ι → set α} (hs : f.has_basis p s) :
∃ x : ℕ → ι, (∀ i, p (x i)) ∧ f.has_antimono_basis (λ _, true) (λ i, s (x i)) :=
begin
rcases cblb.exists_seq with ⟨x', hx'⟩,
have : ∀ i, x' i ∈ f := λ i, hx'.symm ▸ (infi_le (λ i, 𝓟 (x' i)) i) (mem_principal_self _),
let x : ℕ → {i : ι // p i} := λ n, nat.rec_on n (hs.index _ $ this 0)
(λ n xn, (hs.index _ $ inter_mem_sets (this $ n + 1) (hs.mem_of_mem xn.coe_prop))),
have x_mono : ∀ n : ℕ, s (x n.succ) ⊆ s (x n) :=
λ n, subset.trans (hs.set_index_subset _) (inter_subset_right _ _),
replace x_mono : ∀ ⦃i j⦄, i ≤ j → s (x j) ≤ s (x i),
{ refine @monotone_of_monotone_nat (order_dual $ set α) _ _ _,
exact x_mono },
have x_subset : ∀ i, s (x i) ⊆ x' i,
{ rintro (_|i),
exacts [hs.set_index_subset _, subset.trans (hs.set_index_subset _) (inter_subset_left _ _)] },
refine ⟨λ i, x i, λ i, (x i).2, _⟩,
have : (⨅ i, 𝓟 (s (x i))).has_antimono_basis (λ _, true) (λ i, s (x i)) :=
⟨has_basis_infi_principal (directed_of_sup x_mono), λ i j _ _ hij, x_mono hij, monotone_const⟩,
convert this,
exact le_antisymm (le_infi $ λ i, le_principal_iff.2 $ by cases i; apply hs.set_index_mem)
(hx'.symm ▸ le_infi (λ i, le_principal_iff.2 $
this.to_has_basis.mem_iff.2 ⟨i, trivial, x_subset i⟩))
end
/-- A countably generated filter admits a basis formed by a monotonically decreasing sequence of
sets. -/
lemma exists_antimono_basis {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, f.has_antimono_basis (λ _, true) x :=
let ⟨x, hxf, hx⟩ := cblb.exists_antimono_subbasis f.basis_sets in ⟨x, hx⟩
end is_countably_generated
lemma has_countable_basis.is_countably_generated {f : filter α} {p : ι → Prop} {s : ι → set α}
(h : f.has_countable_basis p s) :
f.is_countably_generated :=
⟨{t | ∃ i, p i ∧ s i = t}, h.countable.image s, h.to_has_basis.eq_generate⟩
lemma is_countably_generated_seq (x : ℕ → set α) : is_countably_generated (⨅ i, 𝓟 $ x i) :=
begin
rcases antimono_seq_of_seq x with ⟨y, am, h⟩,
rw h,
use [range y, countable_range _],
rw (has_basis_infi_principal _).eq_generate,
{ simp [range] },
{ exact directed_of_sup am },
{ use 0 },
end
lemma is_countably_generated_of_seq {f : filter α} (h : ∃ x : ℕ → set α, f = ⨅ i, 𝓟 $ x i) :
f.is_countably_generated :=
let ⟨x, h⟩ := h in by rw h ; apply is_countably_generated_seq
lemma is_countably_generated_binfi_principal {B : set $ set α} (h : countable B) :
is_countably_generated (⨅ (s ∈ B), 𝓟 s) :=
is_countably_generated_of_seq (countable_binfi_principal_eq_seq_infi h)
lemma is_countably_generated_iff_exists_antimono_basis {f : filter α} :
is_countably_generated f ↔ ∃ x : ℕ → set α, f.has_antimono_basis (λ _, true) x :=
begin
split,
{ exact λ h, h.exists_antimono_basis },
{ rintros ⟨x, h⟩,
rw h.to_has_basis.eq_infi,
exact is_countably_generated_seq x },
end
lemma is_countably_generated_principal (s : set α) : is_countably_generated (𝓟 s) :=
begin
rw show 𝓟 s = ⨅ i : ℕ, 𝓟 s, by simp,
apply is_countably_generated_seq
end
namespace is_countably_generated
lemma inf {f g : filter α} (hf : is_countably_generated f) (hg : is_countably_generated g) :
is_countably_generated (f ⊓ g) :=
begin
rw is_countably_generated_iff_exists_antimono_basis at hf hg,
rcases hf with ⟨s, hs⟩,
rcases hg with ⟨t, ht⟩,
exact has_countable_basis.is_countably_generated
⟨hs.to_has_basis.inf ht.to_has_basis, set.countable_encodable _⟩
end
lemma inf_principal {f : filter α} (h : is_countably_generated f) (s : set α) :
is_countably_generated (f ⊓ 𝓟 s) :=
h.inf (filter.is_countably_generated_principal s)
lemma exists_antimono_seq' {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, (∀ i j, i ≤ j → x j ⊆ x i) ∧ ∀ {s}, (s ∈ f ↔ ∃ i, x i ⊆ s) :=
let ⟨x, hx⟩ := is_countably_generated_iff_exists_antimono_basis.mp cblb in
⟨x, λ i j, hx.decreasing trivial trivial, λ s, by simp [hx.to_has_basis.mem_iff]⟩
protected lemma comap {l : filter β} (h : l.is_countably_generated) (f : α → β) :
(comap f l).is_countably_generated :=
let ⟨x, hx_mono⟩ := h.exists_antimono_basis in
is_countably_generated_of_seq ⟨_, (hx_mono.to_has_basis.comap _).eq_infi⟩
end is_countably_generated
end filter
|
d5c536b18504bb55130c3dd8194f05dc092225c9 | a721fe7446524f18ba361625fc01033d9c8b7a78 | /src/principia/experimental/oldint/induction.lean | 30d6312ff36a19c4b3fbec41d50ec51e02a7ebb0 | [] | no_license | Sterrs/leaning | 8fd80d1f0a6117a220bb2e57ece639b9a63deadc | 3901cc953694b33adda86cb88ca30ba99594db31 | refs/heads/master | 1,627,023,822,744 | 1,616,515,221,000 | 1,616,515,221,000 | 245,512,190 | 2 | 0 | null | 1,616,429,050,000 | 1,583,527,118,000 | Lean | UTF-8 | Lean | false | false | 1,569 | lean | import .add
import principia.mynat.induction
namespace hidden
namespace oldint
theorem intduction (p : oldint → Prop) :
p 0 → (∀ {n}, p n → p (n + 1)) → (∀ {n}, p n → p (n - 1)) →
∀ n, p n :=
begin
assume h0 hnext hprev,
intro n,
cases n, {
induction n with n hn, {
rwa [mynat.zz, ←coe_nat_eq, zero_nat],
}, {
rw ←coe_nat_eq at hn,
have h := hnext hn,
rwa [←coe_nat_eq], -- magic?
},
}, {
induction n with n hn, {
rw [mynat.zz, ←neg_one],
apply @hprev 0,
assumption,
}, {
rw [←neg_coe_succ, ←mynat.add_one_succ, ←nat_nat_add, neg_distr,
one_nat, ←sub_add_neg],
apply @hprev (-↑(mynat.succ n)),
rwa neg_coe_succ,
},
},
end
open mynat
private theorem one: (1: mynat) = succ 0 := rfl
theorem intduction_from {m : oldint} (p : oldint → Prop):
(∀ {n}, p n → p (n + 1)) → (∀ {n}, p n → p (n - 1)) →
p m → ∀ n, p n :=
begin
assume hnext hprev hex,
suffices : p 0,
apply intduction, repeat {assumption},
cases m, {
revert m,
apply descend_to_zero,
intro m,
assume hsucc,
have := hprev hsucc,
rwa [sub_add_neg, neg_one, ←coe_nat_eq, nat_neg_add, sub_succ_succ,
nat_sub_zero] at this,
}, {
suffices : p (-1), from hnext this,
rw neg_one,
revert m,
apply descend_to_zero,
intro m,
assume hsucc,
have := hnext hsucc,
rwa [←one_nat, neg_nat_add, one, sub_succ_succ, zero_sub_neg,
neg_succ] at this,
},
end
end oldint
end hidden
|
5634d00c91c67410dd645a9c941e96b52daad1a6 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/data/list/defs.lean | 499026619e3d82f04a0e4cbad60cd311d50fff89 | [
"Apache-2.0"
] | permissive | vaibhavkarve/mathlib | a574aaf68c0a431a47fa82ce0637f0f769826bfe | 17f8340912468f49bdc30acdb9a9fa02eeb0473a | refs/heads/master | 1,621,263,802,637 | 1,585,399,588,000 | 1,585,399,588,000 | 250,833,447 | 0 | 0 | Apache-2.0 | 1,585,410,341,000 | 1,585,410,341,000 | null | UTF-8 | Lean | false | false | 21,085 | lean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
Extra definitions on lists.
-/
import data.option.defs logic.basic tactic.cache
namespace list
open function nat
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
/-- Returns whether a list is []. Returns a boolean even if `l = []` is not decidable. -/
def is_nil {α} : list α → bool
| [] := tt
| _ := ff
instance [decidable_eq α] : has_sdiff (list α) :=
⟨ list.diff ⟩
/-- Split a list at an index.
split_at 2 [a, b, c] = ([a, b], [c]) -/
def split_at : ℕ → list α → list α × list α
| 0 a := ([], a)
| (succ n) [] := ([], [])
| (succ n) (x :: xs) := let (l, r) := split_at n xs in (x :: l, r)
def split_on_p_aux {α : Type u} (P : α → Prop) [decidable_pred P] : list α → (list α → list α) → list (list α)
| [] f := [f []]
| (h :: t) f :=
if P h then f [] :: split_on_p_aux t id
else split_on_p_aux t (λ l, f (h :: l))
/-- Split a list at every element satisfying a predicate. -/
def split_on_p {α : Type u} (P : α → Prop) [decidable_pred P] (l : list α) : list (list α) :=
split_on_p_aux P l id
/-- Split a list at every occurrence of an element.
[1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]] -/
def split_on {α : Type u} [decidable_eq α] (a : α) (as : list α) : list (list α) :=
as.split_on_p (=a)
/-- Concatenate an element at the end of a list.
concat [a, b] c = [a, b, c] -/
@[simp] def concat : list α → α → list α
| [] a := [a]
| (b::l) a := b :: concat l a
@[simp] def head' : list α → option α
| [] := none
| (a :: l) := some a
/-- Convert a list into an array (whose length is the length of `l`). -/
def to_array (l : list α) : array l.length α :=
{data := λ v, l.nth_le v.1 v.2}
/-- "inhabited" `nth` function: returns `default` instead of `none` in the case
that the index is out of bounds. -/
@[simp] def inth [h : inhabited α] (l : list α) (n : nat) : α := (nth l n).iget
/-- Apply a function to the nth tail of `l`. Returns the input without
using `f` if the index is larger than the length of the list.
modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c] -/
@[simp] def modify_nth_tail (f : list α → list α) : ℕ → list α → list α
| 0 l := f l
| (n+1) [] := []
| (n+1) (a::l) := a :: modify_nth_tail n l
/-- Apply `f` to the head of the list, if it exists. -/
@[simp] def modify_head (f : α → α) : list α → list α
| [] := []
| (a::l) := f a :: l
/-- Apply `f` to the nth element of the list, if it exists. -/
def modify_nth (f : α → α) : ℕ → list α → list α :=
modify_nth_tail (modify_head f)
def insert_nth (n : ℕ) (a : α) : list α → list α := modify_nth_tail (list.cons a) n
section take'
variable [inhabited α]
def take' : ∀ n, list α → list α
| 0 l := []
| (n+1) l := l.head :: take' n l.tail
end take'
/-- Get the longest initial segment of the list whose members all satisfy `p`.
take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2] -/
def take_while (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then a :: take_while l else []
/-- `after p xs` is the suffix of `xs` after the first element that satisfies
`p`, not including that element.
```lean
after (eq 1) [0, 1, 2, 3] = [2, 3]
drop_while (not ∘ eq 1) [0, 1, 2, 3] = [1, 2, 3]
```
-/
def after (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (x :: xs) := if p x then xs else after xs
/-- Fold a function `f` over the list from the left, returning the list
of partial results.
scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6] -/
def scanl (f : α → β → α) : α → list β → list α
| a [] := [a]
| a (b::l) := a :: scanl (f a b) l
def scanr_aux (f : α → β → β) (b : β) : list α → β × list β
| [] := (b, [])
| (a::l) := let (b', l') := scanr_aux l in (f a b', b' :: l')
/-- Fold a function `f` over the list from the right, returning the list
of partial results.
scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0] -/
def scanr (f : α → β → β) (b : β) (l : list α) : list β :=
let (b', l') := scanr_aux f b l in b' :: l'
/-- Product of a list.
prod [a, b, c] = ((1 * a) * b) * c -/
def prod [has_mul α] [has_one α] : list α → α := foldl (*) 1
/-- Sum of a list.
sum [a, b, c] = ((0 + a) + b) + c -/
-- Later this will be tagged with `to_additive`, but this can't be done yet because of import
-- dependencies.
def sum [has_add α] [has_zero α] : list α → α := foldl (+) 0
def partition_map (f : α → β ⊕ γ) : list α → list β × list γ
| [] := ([],[])
| (x::xs) :=
match f x with
| (sum.inr r) := prod.map id (cons r) $ partition_map xs
| (sum.inl l) := prod.map (cons l) id $ partition_map xs
end
/-- `find p l` is the first element of `l` satisfying `p`, or `none` if no such
element exists. -/
def find (p : α → Prop) [decidable_pred p] : list α → option α
| [] := none
| (a::l) := if p a then some a else find l
def find_indexes_aux (p : α → Prop) [decidable_pred p] : list α → nat → list nat
| [] n := []
| (a::l) n := let t := find_indexes_aux l (succ n) in if p a then n :: t else t
/-- `find_indexes p l` is the list of indexes of elements of `l` that satisfy `p`. -/
def find_indexes (p : α → Prop) [decidable_pred p] (l : list α) : list nat :=
find_indexes_aux p l 0
/-- `lookmap` is a combination of `lookup` and `filter_map`.
`lookmap f l` will apply `f : α → option α` to each element of the list,
replacing `a → b` at the first value `a` in the list such that `f a = some b`. -/
def lookmap (f : α → option α) : list α → list α
| [] := []
| (a::l) :=
match f a with
| some b := b :: l
| none := a :: lookmap l
end
def map_with_index_core (f : ℕ → α → β) : ℕ → list α → list β
| k [] := []
| k (a::as) := f k a::(map_with_index_core (k+1) as)
def map_with_index (f : ℕ → α → β) (as : list α) : list β :=
map_with_index_core f 0 as
/-- `indexes_of a l` is the list of all indexes of `a` in `l`.
indexes_of a [a, b, a, a] = [0, 2, 3] -/
def indexes_of [decidable_eq α] (a : α) : list α → list nat := find_indexes (eq a)
/-- Auxilliary definition for `indexes_values`. -/
def indexes_values_aux {α} (f : α → bool) : list α → ℕ → list (ℕ × α)
| [] n := []
| (x::xs) n := let ns := indexes_values_aux xs (n+1) in if f x then (n, x)::ns else ns
/-- Returns `(l.find_indexes f).zip l`, i.e. pairs of `(n, x)` such that `f x = tt` and
`l.nth = some x`, in increasing order of first arguments. -/
def indexes_values {α} (l : list α) (f : α → bool) : list (ℕ × α) :=
indexes_values_aux f l 0
/-- `countp p l` is the number of elements of `l` that satisfy `p`. -/
def countp (p : α → Prop) [decidable_pred p] : list α → nat
| [] := 0
| (x::xs) := if p x then succ (countp xs) else countp xs
/-- `count a l` is the number of occurrences of `a` in `l`. -/
def count [decidable_eq α] (a : α) : list α → nat := countp (eq a)
/-- `is_prefix l₁ l₂`, or `l₁ <+: l₂`, means that `l₁` is a prefix of `l₂`,
that is, `l₂` has the form `l₁ ++ t` for some `t`. -/
def is_prefix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, l₁ ++ t = l₂
/-- `is_suffix l₁ l₂`, or `l₁ <:+ l₂`, means that `l₁` is a suffix of `l₂`,
that is, `l₂` has the form `t ++ l₁` for some `t`. -/
def is_suffix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, t ++ l₁ = l₂
/-- `is_infix l₁ l₂`, or `l₁ <:+: l₂`, means that `l₁` is a contiguous
substring of `l₂`, that is, `l₂` has the form `s ++ l₁ ++ t` for some `s, t`. -/
def is_infix (l₁ : list α) (l₂ : list α) : Prop := ∃ s t, s ++ l₁ ++ t = l₂
infix ` <+: `:50 := is_prefix
infix ` <:+ `:50 := is_suffix
infix ` <:+: `:50 := is_infix
/-- `inits l` is the list of initial segments of `l`.
inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]] -/
@[simp] def inits : list α → list (list α)
| [] := [[]]
| (a::l) := [] :: map (λt, a::t) (inits l)
/-- `tails l` is the list of terminal segments of `l`.
tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []] -/
@[simp] def tails : list α → list (list α)
| [] := [[]]
| (a::l) := (a::l) :: tails l
def sublists'_aux : list α → (list α → list β) → list (list β) → list (list β)
| [] f r := f [] :: r
| (a::l) f r := sublists'_aux l f (sublists'_aux l (f ∘ cons a) r)
/-- `sublists' l` is the list of all (non-contiguous) sublists of `l`.
It differs from `sublists` only in the order of appearance of the sublists;
`sublists'` uses the first element of the list as the MSB,
`sublists` uses the first element of the list as the LSB.
sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] -/
def sublists' (l : list α) : list (list α) :=
sublists'_aux l id []
def sublists_aux : list α → (list α → list β → list β) → list β
| [] f := []
| (a::l) f := f [a] (sublists_aux l (λys r, f ys (f (a :: ys) r)))
/-- `sublists l` is the list of all (non-contiguous) sublists of `l`; cf. `sublists'`
for a different ordering.
sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] -/
def sublists (l : list α) : list (list α) :=
[] :: sublists_aux l cons
def sublists_aux₁ : list α → (list α → list β) → list β
| [] f := []
| (a::l) f := f [a] ++ sublists_aux₁ l (λys, f ys ++ f (a :: ys))
section forall₂
variables {r : α → β → Prop} {p : γ → δ → Prop}
inductive forall₂ (R : α → β → Prop) : list α → list β → Prop
| nil {} : forall₂ [] []
| cons {a b l₁ l₂} : R a b → forall₂ l₁ l₂ → forall₂ (a::l₁) (b::l₂)
attribute [simp] forall₂.nil
end forall₂
def transpose_aux : list α → list (list α) → list (list α)
| [] ls := ls
| (a::i) [] := [a] :: transpose_aux i []
| (a::i) (l::ls) := (a::l) :: transpose_aux i ls
/-- transpose of a list of lists, treated as a matrix.
transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]] -/
def transpose : list (list α) → list (list α)
| [] := []
| (l::ls) := transpose_aux l (transpose ls)
/-- List of all sections through a list of lists. A section
of `[L₁, L₂, ..., Lₙ]` is a list whose first element comes from
`L₁`, whose second element comes from `L₂`, and so on. -/
def sections : list (list α) → list (list α)
| [] := [[]]
| (l::L) := bind (sections L) $ λ s, map (λ a, a::s) l
section permutations
def permutations_aux2 (t : α) (ts : list α) (r : list β) : list α → (list α → β) → list α × list β
| [] f := (ts, r)
| (y::ys) f := let (us, zs) := permutations_aux2 ys (λx : list α, f (y::x)) in
(y :: us, f (t :: y :: us) :: zs)
private def meas : (Σ'_:list α, list α) → ℕ × ℕ | ⟨l, i⟩ := (length l + length i, length l)
local infix ` ≺ `:50 := inv_image (prod.lex (<) (<)) meas
@[elab_as_eliminator] def permutations_aux.rec {C : list α → list α → Sort v}
(H0 : ∀ is, C [] is)
(H1 : ∀ t ts is, C ts (t::is) → C is [] → C (t::ts) is) : ∀ l₁ l₂, C l₁ l₂
| [] is := H0 is
| (t::ts) is :=
have h1 : ⟨ts, t :: is⟩ ≺ ⟨t :: ts, is⟩, from
show prod.lex _ _ (succ (length ts + length is), length ts) (succ (length ts) + length is, length (t :: ts)),
by rw nat.succ_add; exact prod.lex.right _ _ (lt_succ_self _),
have h2 : ⟨is, []⟩ ≺ ⟨t :: ts, is⟩, from prod.lex.left _ _ _ (lt_add_of_pos_left _ (succ_pos _)),
H1 t ts is (permutations_aux.rec ts (t::is)) (permutations_aux.rec is [])
using_well_founded {
dec_tac := tactic.assumption,
rel_tac := λ _ _, `[exact ⟨(≺), @inv_image.wf _ _ _ meas (prod.lex_wf lt_wf lt_wf)⟩] }
def permutations_aux : list α → list α → list (list α) :=
@@permutations_aux.rec (λ _ _, list (list α)) (λ is, [])
(λ t ts is IH1 IH2, foldr (λy r, (permutations_aux2 t ts r y id).2) IH1 (is :: IH2))
/-- List of all permutations of `l`.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [3, 2, 1],
[2, 3, 1], [3, 1, 2], [1, 3, 2]] -/
def permutations (l : list α) : list (list α) :=
l :: permutations_aux l []
end permutations
def erasep (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then l else a :: erasep l
def extractp (p : α → Prop) [decidable_pred p] : list α → option α × list α
| [] := (none, [])
| (a::l) := if p a then (some a, l) else
let (a', l') := extractp l in (a', a :: l')
def revzip (l : list α) : list (α × α) := zip l l.reverse
/-- `product l₁ l₂` is the list of pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂`.
product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
def product (l₁ : list α) (l₂ : list β) : list (α × β) :=
l₁.bind $ λ a, l₂.map $ prod.mk a
/-- `sigma l₁ l₂` is the list of dependent pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂ a`.
sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
protected def sigma {σ : α → Type*} (l₁ : list α) (l₂ : Π a, list (σ a)) : list (Σ a, σ a) :=
l₁.bind $ λ a, (l₂ a).map $ sigma.mk a
def of_fn_aux {n} (f : fin n → α) : ∀ m, m ≤ n → list α → list α
| 0 h l := l
| (succ m) h l := of_fn_aux m (le_of_lt h) (f ⟨m, h⟩ :: l)
def of_fn {n} (f : fin n → α) : list α :=
of_fn_aux f n (le_refl _) []
def of_fn_nth_val {n} (f : fin n → α) (i : ℕ) : option α :=
if h : _ then some (f ⟨i, h⟩) else none
/-- `disjoint l₁ l₂` means that `l₁` and `l₂` have no elements in common. -/
def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, a ∈ l₁ → a ∈ l₂ → false
section pairwise
variables (R : α → α → Prop)
/-- `pairwise R l` means that all the elements with earlier indexes are
`R`-related to all the elements with later indexes.
pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3
For example if `R = (≠)` then it asserts `l` has no duplicates,
and if `R = (<)` then it asserts that `l` is (strictly) sorted. -/
inductive pairwise : list α → Prop
| nil {} : pairwise []
| cons : ∀ {a : α} {l : list α}, (∀ a' ∈ l, R a a') → pairwise l → pairwise (a::l)
variables {R}
@[simp] theorem pairwise_cons {a : α} {l : list α} :
pairwise R (a::l) ↔ (∀ a' ∈ l, R a a') ∧ pairwise R l :=
⟨λ p, by cases p with a l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩
instance decidable_pairwise [decidable_rel R] (l : list α) : decidable (pairwise R l) :=
by induction l with hd tl ih; [exact is_true pairwise.nil,
exactI decidable_of_iff' _ pairwise_cons]
end pairwise
/-- `pw_filter R l` is a maximal sublist of `l` which is `pairwise R`.
`pw_filter (≠)` is the erase duplicates function (cf. `erase_dup`), and `pw_filter (<)` finds
a maximal increasing subsequence in `l`. For example,
pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4] -/
def pw_filter (R : α → α → Prop) [decidable_rel R] : list α → list α
| [] := []
| (x :: xs) := let IH := pw_filter xs in if ∀ y ∈ IH, R x y then x :: IH else IH
section chain
variable (R : α → α → Prop)
/-- `chain R a l` means that `R` holds between adjacent elements of `a::l`.
chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
inductive chain : α → list α → Prop
| nil {} {a : α} : chain a []
| cons : ∀ {a b : α} {l : list α}, R a b → chain b l → chain a (b::l)
/-- `chain' R l` means that `R` holds between adjacent elements of `l`.
chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
def chain' : list α → Prop
| [] := true
| (a :: l) := chain R a l
variable {R}
@[simp] theorem chain_cons {a b : α} {l : list α} :
chain R a (b::l) ↔ R a b ∧ chain R b l :=
⟨λ p, by cases p with _ a b l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩
attribute [simp] chain.nil
instance decidable_chain [decidable_rel R] (a : α) (l : list α) : decidable (chain R a l) :=
by induction l generalizing a; simp only [chain.nil, chain_cons]; resetI; apply_instance
instance decidable_chain' [decidable_rel R] (l : list α) : decidable (chain' R l) :=
by cases l; dunfold chain'; apply_instance
end chain
/-- `nodup l` means that `l` has no duplicates, that is, any element appears at most
once in the list. It is defined as `pairwise (≠)`. -/
def nodup : list α → Prop := pairwise (≠)
instance nodup_decidable [decidable_eq α] : ∀ l : list α, decidable (nodup l) :=
list.decidable_pairwise
/-- `erase_dup l` removes duplicates from `l` (taking only the first occurrence).
Defined as `pw_filter (≠)`.
erase_dup [1, 0, 2, 2, 1] = [0, 2, 1] -/
def erase_dup [decidable_eq α] : list α → list α := pw_filter (≠)
/-- `range' s n` is the list of numbers `[s, s+1, ..., s+n-1]`.
It is intended mainly for proving properties of `range` and `iota`. -/
@[simp] def range' : ℕ → ℕ → list ℕ
| s 0 := []
| s (n+1) := s :: range' (s+1) n
def reduce_option {α} : list (option α) → list α :=
list.filter_map id
def map_head {α} (f : α → α) : list α → list α
| [] := []
| (x :: xs) := f x :: xs
def map_last {α} (f : α → α) : list α → list α
| [] := []
| [x] := [f x]
| (x :: xs) := x :: map_last xs
/-- `ilast' x xs` returns the last element of `xs` if `xs` is non-empty;
it returns `x` otherwise -/
@[simp] def ilast' {α} : α → list α → α
| a [] := a
| a (b::l) := ilast' b l
/-- `last' xs` returns the last element of `xs` if `xs` is non-empty;
it returns `none` otherwise -/
@[simp] def last' {α} : list α → option α
| [] := none
| [a] := some a
| (b::l) := last' l
/- tfae: The Following (propositions) Are Equivalent -/
def tfae (l : list Prop) : Prop := ∀ x ∈ l, ∀ y ∈ l, x ↔ y
/-- `rotate l n` rotates the elements of `l` to the left by `n`
rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1] -/
def rotate (l : list α) (n : ℕ) : list α :=
let (l₁, l₂) := list.split_at (n % l.length) l in l₂ ++ l₁
/-- rotate' is the same as `rotate`, but slower. Used for proofs about `rotate`-/
def rotate' : list α → ℕ → list α
| [] n := []
| l 0 := l
| (a::l) (n+1) := rotate' (l ++ [a]) n
section choose
variables (p : α → Prop) [decidable_pred p] (l : list α)
def choose_x : Π l : list α, Π hp : (∃ a, a ∈ l ∧ p a), { a // a ∈ l ∧ p a }
| [] hp := false.elim (exists.elim hp (assume a h, not_mem_nil a h.left))
| (l :: ls) hp := if pl : p l then ⟨l, ⟨or.inl rfl, pl⟩⟩ else
let ⟨a, ⟨a_mem_ls, pa⟩⟩ := choose_x ls (hp.imp
(λ b ⟨o, h₂⟩, ⟨o.resolve_left (λ e, pl $ e ▸ h₂), h₂⟩)) in
⟨a, ⟨or.inr a_mem_ls, pa⟩⟩
def choose (hp : ∃ a, a ∈ l ∧ p a) : α := choose_x p l hp
end choose
namespace func
/- Definitions for using lists as finite
representations of functions with domain ℕ. -/
def neg [has_neg α] (as : list α) := as.map (λ a, -a)
variables [inhabited α] [inhabited β]
@[simp] def set (a : α) : list α → ℕ → list α
| (_::as) 0 := a::as
| [] 0 := [a]
| (h::as) (k+1) := h::(set as k)
| [] (k+1) := (default α)::(set ([] : list α) k)
@[simp] def get : ℕ → list α → α
| _ [] := default α
| 0 (a::as) := a
| (n+1) (a::as) := get n as
def equiv (as1 as2 : list α) : Prop :=
∀ (m : nat), get m as1 = get m as2
@[simp] def pointwise (f : α → β → γ) : list α → list β → list γ
| [] [] := []
| [] (b::bs) := map (f $ default α) (b::bs)
| (a::as) [] := map (λ x, f x $ default β) (a::as)
| (a::as) (b::bs) := (f a b)::(pointwise as bs)
def add {α : Type u} [has_zero α] [has_add α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (+)
def sub {α : Type u} [has_zero α] [has_sub α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (@has_sub.sub α _)
end func
/-- Filters and maps elements of a list -/
def mmap_filter {m : Type → Type v} [monad m] {α β} (f : α → m (option β)) :
list α → m (list β)
| [] := return []
| (h :: t) := do b ← f h, t' ← t.mmap_filter, return $
match b with none := t' | (some x) := x::t' end
protected def traverse {F : Type u → Type v} [applicative F] {α β : Type*} (f : α → F β) :
list α → F (list β)
| [] := pure []
| (x :: xs) := list.cons <$> f x <*> traverse xs
/-- `get_rest l l₁` returns `some l₂` if `l = l₁ ++ l₂`.
If `l₁` is not a prefix of `l`, returns `none` -/
def get_rest [decidable_eq α] : list α → list α → option (list α)
| l [] := some l
| [] _ := none
| (x::l) (y::l₁) := if x = y then get_rest l l₁ else none
end list
|
c073a83778cfd36be9e1da5f659474ed8558e781 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Compiler/LCNF/Simp/Main.lean | 50e43769aef1fea16c374ccff08aa18b04ee1451 | [
"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 | 12,516 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.ImplementedByAttr
import Lean.Compiler.LCNF.ElimDead
import Lean.Compiler.LCNF.AlphaEqv
import Lean.Compiler.LCNF.PrettyPrinter
import Lean.Compiler.LCNF.Bind
import Lean.Compiler.LCNF.Simp.FunDeclInfo
import Lean.Compiler.LCNF.Simp.InlineCandidate
import Lean.Compiler.LCNF.Simp.InlineProj
import Lean.Compiler.LCNF.Simp.Used
import Lean.Compiler.LCNF.Simp.DefaultAlt
import Lean.Compiler.LCNF.Simp.SimpValue
import Lean.Compiler.LCNF.Simp.ConstantFold
namespace Lean.Compiler.LCNF
namespace Simp
/--
Return `true` if `c` has only one exit point.
This is a quick approximation. It does not check cases
such as: a `cases` with many but only one alternative is not reachable.
It is only used to avoid the creation of auxiliary join points, and does not need
to be precise.
-/
private partial def oneExitPointQuick (c : Code) : Bool :=
go c
where
go (c : Code) : Bool :=
match c with
| .let _ k | .fun _ k => go k
-- Approximation, the cases may have many unreachable alternatives, and only reachable.
| .cases c => c.alts.size == 1 && go c.alts[0]!.getCode
-- Approximation, we assume that any code containing join points have more than one exit point
| .jp .. | .jmp .. | .unreach .. => false
| .return .. => true
/--
Create a new local function declaration when `info.args.size < info.params.size`.
We use this function to inline/specialize a partial application of a local function.
-/
def specializePartialApp (info : InlineCandidateInfo) : SimpM FunDecl := do
let mut subst := {}
for param in info.params, arg in info.args do
subst := subst.insert param.fvarId arg.toExpr
let mut paramsNew := #[]
for param in info.params[info.args.size:] do
let type ← replaceExprFVars param.type subst (translator := true)
let paramNew ← mkAuxParam type
paramsNew := paramsNew.push paramNew
subst := subst.insert param.fvarId (.fvar paramNew.fvarId)
let code ← info.value.internalize subst
updateFunDeclInfo code
mkAuxFunDecl paramsNew code
/--
Try to inline a join point.
-/
partial def inlineJp? (fvarId : FVarId) (args : Array Arg) : SimpM (Option Code) := do
/- Remark: we don't need to use `findFunDecl'?` here. -/
let some decl ← findFunDecl? fvarId | return none
unless (← shouldInlineLocal decl) do return none
markSimplified
betaReduce decl.params decl.value args
/--
When the configuration flag `etaPoly = true`, we eta-expand
partial applications of functions that take local instances as arguments.
This kind of function is inlined or specialized, and we create new
simplification opportunities by eta-expanding them.
-/
def etaPolyApp? (letDecl : LetDecl) : OptionT SimpM FunDecl := do
guard <| (← read).config.etaPoly
let .const declName us args := letDecl.value | failure
let some info := (← getEnv).find? declName | failure
guard <| hasLocalInst info.type
guard <| !(← Meta.isInstance declName)
let some decl ← getDecl? declName | failure
guard <| decl.getArity > args.size
let params ← mkNewParams letDecl.type
let auxDecl ← mkAuxLetDecl (.const declName us (args ++ params.map (.fvar ·.fvarId)))
let funDecl ← mkAuxFunDecl params (.let auxDecl (.return auxDecl.fvarId))
addFVarSubst letDecl.fvarId funDecl.fvarId
eraseLetDecl letDecl
return funDecl
/--
Similar to `Code.isReturnOf`, but taking the current substitution into account.
-/
def isReturnOf (c : Code) (fvarId : FVarId) : SimpM Bool := do
match c with
| .return fvarId' => match (← normFVar fvarId') with
| .fvar fvarId'' => return fvarId'' == fvarId
| .erased => return false
| _ => return false
def elimVar? (value : LetValue) : SimpM (Option FVarId) := do
let .fvar fvarId #[] := value | return none
return fvarId
mutual
/--
If the value of the given let-declaration is an application that can be inlined,
inline it and simplify the result.
`k` is the "continuation" for the let declaration, if the application is inlined,
it will also be simplified.
Note: `inlineApp?` did not use to be in this mutually recursive declaration.
It used to be invoked by `simp`, and would return `Option Code` that would be
then simplified by `simp`. However, this simpler architecture produced an
exponential blowup in when processing functions such as `Lean.Elab.Deriving.Ord.mkMatch.mkAlts`.
The key problem is that when inlining a declaration we often can reduce the number
of exit points by simplified the inlined code, and then connecting the result to the
continuation `k`. However, this optimization is only possible if we simplify the
inlined code **before** we attach it to the continuation.
-/
partial def inlineApp? (letDecl : LetDecl) (k : Code) : SimpM (Option Code) := do
let some info ← inlineCandidate? letDecl.value | return none
let numArgs := info.args.size
withInlining letDecl.value info.recursive do
let fvarId := letDecl.fvarId
if numArgs < info.arity then
let funDecl ← specializePartialApp info
addFVarSubst fvarId funDecl.fvarId
markSimplified
simp (.fun funDecl k)
else
let code ← betaReduce info.params info.value info.args[:info.arity]
if k.isReturnOf fvarId && numArgs == info.arity then
/- Easy case, the continuation `k` is just returning the result of the application. -/
markSimplified
simp code
else
let code ← simp code
let simpK (result : FVarId) : SimpM Code := do
/- `result` contains the result of the inlined code -/
if numArgs > info.arity then
let decl ← mkAuxLetDecl (.fvar result info.args[info.arity:])
addFVarSubst fvarId decl.fvarId
simp (.let decl k)
else
addFVarSubst fvarId result
simp k
if oneExitPointQuick code then
-- TODO: if `k` is small, we should also inline it here
markSimplified
code.bind fun fvarId' => do
markUsedFVar fvarId'
simpK fvarId'
-- else if info.ifReduce then
-- eraseCode code
-- return none
else
markSimplified
let expectedType ← inferAppType info.fType info.args[:info.arity]
if expectedType.headBeta.isForall then
/-
If `code` returns a function, we create an auxiliary local function declaration (and eta-expand it)
instead of creating a joinpoint that takes a closure as an argument.
-/
let auxFunDecl ← mkAuxFunDecl #[] code
let auxFunDecl ← auxFunDecl.etaExpand
let k ← simpK auxFunDecl.fvarId
attachCodeDecls #[.fun auxFunDecl] k
else
let jpParam ← mkAuxParam expectedType
let jpValue ← simpK jpParam.fvarId
let jpDecl ← mkAuxJpDecl #[jpParam] jpValue
let code ← code.bind fun fvarId => return .jmp jpDecl.fvarId #[.fvar fvarId]
return Code.jp jpDecl code
/--
Simplify the given local function declaration.
-/
partial def simpFunDecl (decl : FunDecl) : SimpM FunDecl := do
let type ← normExpr decl.type
let params ← normParams decl.params
let value ← simp decl.value
decl.update type params value
/--
Try to simplify `cases` of `constructor`
-/
partial def simpCasesOnCtor? (cases : Cases) : SimpM (Option Code) := do
match (← normFVar cases.discr) with
| .erased => mkReturnErased
| .fvar discr =>
let some ctorInfo ← findCtor? discr | return none
let (alt, cases) := cases.extractAlt! ctorInfo.getName
eraseCode (.cases cases)
markSimplified
match alt with
| .default k => simp k
| .alt _ params k =>
match ctorInfo with
| .ctor ctorVal ctorArgs =>
let fields := ctorArgs[ctorVal.numParams:]
for param in params, field in fields do
addSubst param.fvarId field.toExpr
let k ← simp k
eraseParams params
return k
| .natVal 0 => simp k
| .natVal (n+1) =>
let auxDecl ← mkAuxLetDecl (.value (.natVal n))
addFVarSubst params[0]!.fvarId auxDecl.fvarId
let k ← simp k
eraseParams params
return some <| .let auxDecl k
/--
Simplify `code`
-/
partial def simp (code : Code) : SimpM Code := withIncRecDepth do
incVisited
match code with
| .let decl k =>
let baseDecl := decl
let mut decl ← normLetDecl baseDecl
if baseDecl != decl then
markSimplified
if let some value ← simpValue? decl.value then
markSimplified
decl ← decl.updateValue value
if let some decls ← ConstantFold.foldConstants decl then
markSimplified
let k ← simp k
attachCodeDecls decls k
else if let some funDecl ← etaPolyApp? decl then
simp (.fun funDecl k)
else if let some fvarId ← elimVar? decl.value then
/- Eliminate `let _x_i := _x_j;` -/
addFVarSubst decl.fvarId fvarId
eraseLetDecl decl
simp k
else if let some code ← inlineApp? decl k then
eraseLetDecl decl
return code
else if let some (decls, fvarId) ← inlineProjInst? decl.value then
addFVarSubst decl.fvarId fvarId
eraseLetDecl decl
let k ← simp k
attachCodeDecls decls k
else
let k ← simp k
if (← isUsed decl.fvarId) then
markUsedLetDecl decl
return code.updateLet! decl k
else
/- Dead variable elimination -/
eraseLetDecl decl
return k
| .fun decl k | .jp decl k =>
let mut decl := decl
let toBeInlined ← isOnceOrMustInline decl.fvarId
if toBeInlined then
/-
If the declaration will be inlined, it is wasteful to eagerly simplify it.
So, we just normalize it (i.e., apply the substitution to it).
-/
decl ← normFunDecl decl
else
/-
Note that functions in `decl` will be marked as used even if `decl` is not actually used.
They will only be deleted in the next pass. TODO: investigate whether this is a problem.
-/
if code.isFun then
if decl.isEtaExpandCandidate then
/- We must apply substitution before trying to eta-expand, otherwise `inferType` may fail. -/
decl ← normFunDecl decl
/-
We want to eta-expand **before** trying to simplify local function declaration because
eta-expansion creates many optimization opportunities.
-/
decl ← decl.etaExpand
markSimplified
decl ← simpFunDecl decl
let k ← simp k
if (← isUsed decl.fvarId) then
if toBeInlined then
/-
`decl` was supposed to be inlined, but there are still references to it.
Thus, we must all variables in `decl` as used. Recall it was not eagerly simplified.
-/
markUsedFunDecl decl
return code.updateFun! decl k
else
/- Dead function elimination -/
eraseFunDecl decl
return k
| .return fvarId =>
withNormFVarResult (← normFVar fvarId) fun fvarId => do
markUsedFVar fvarId
return code.updateReturn! fvarId
| .unreach type =>
return code.updateUnreach! (← normExpr type)
| .jmp fvarId args =>
withNormFVarResult (← normFVar fvarId) fun fvarId => do
let args ← normArgs args
if let some code ← inlineJp? fvarId args then
simp code
else
markUsedFVar fvarId
args.forM markUsedArg
return code.updateJmp! fvarId args
| .cases c =>
if let some k ← simpCasesOnCtor? c then
return k
else
withNormFVarResult (← normFVar c.discr) fun discr => do
let resultType ← normExpr c.resultType
markUsedFVar discr
let alts ← c.alts.mapMonoM fun alt => do
match alt with
| .alt ctorName ps k =>
if !(k matches .unreach ..) && (← ps.anyM fun p => isInductiveWithNoCtors p.type) then
let type ← k.inferType
eraseCode k
markSimplified
return alt.updateCode (.unreach type)
else
withDiscrCtor discr ctorName ps do
return alt.updateCode (← simp k)
| .default k => return alt.updateCode (← simp k)
let alts ← addDefaultAlt alts
if alts.size == 1 && alts[0]! matches .default .. then
return alts[0]!.getCode
else
return code.updateCases! resultType discr alts
end
|
b3003a46e6066bff09798fa6b81765ce10934806 | 4b846d8dabdc64e7ea03552bad8f7fa74763fc67 | /library/init/meta/smt/rsimp.lean | 97371d0edb5f9f773fdf18b27d12aab5ce5e94fb | [
"Apache-2.0"
] | permissive | pacchiano/lean | 9324b33f3ac3b5c5647285160f9f6ea8d0d767dc | fdadada3a970377a6df8afcd629a6f2eab6e84e8 | refs/heads/master | 1,611,357,380,399 | 1,489,870,101,000 | 1,489,870,101,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,575 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.smt.smt_tactic init.meta.fun_info init.meta.rb_map
open tactic
private meta def add_lemma (m : transparency) (h : name) (hs : hinst_lemmas) : tactic hinst_lemmas :=
(do h ← hinst_lemma.mk_from_decl_core m h tt, return $ hs^.add h) <|> return hs
private meta def to_hinst_lemmas (m : transparency) (ex : name_set) : list name → hinst_lemmas → tactic hinst_lemmas
| [] hs := return hs
| (n::ns) hs :=
if ex^.contains n then to_hinst_lemmas ns hs else
let add n := add_lemma m n hs >>= to_hinst_lemmas ns
in do eqns ← tactic.get_eqn_lemmas_for tt n,
match eqns with
| [] := add n
| _ := mcond (is_prop_decl n) (add n) (to_hinst_lemmas eqns hs >>= to_hinst_lemmas ns)
end
/-- Create a rsimp attribute named `attr_name`, the attribute declaration is named `attr_decl_name`.
The cached hinst_lemmas structure is built using the lemmas marked with simp attribute `simp_attr_name`,
but *not* marked with `ex_attr_name`.
We say `ex_attr_name` is the "exception set". It is useful for excluding lemmas in `simp_attr_name`
which are not good or redundant for ematching. -/
meta def mk_hinst_lemma_attr_from_simp_attr (attr_decl_name attr_name : name) (simp_attr_name : name) (ex_attr_name : name) : command :=
do let t := ```(caching_user_attribute hinst_lemmas),
v ← to_expr ``({name := %%(quote attr_name),
descr := "hinst_lemma attribute derived from '" ++ to_string %%(quote simp_attr_name) ++ "'",
mk_cache := λ ns,
let aux := %%(quote simp_attr_name) in
let ex_attr := %%(quote ex_attr_name) in
do {
hs ← to_hinst_lemmas reducible mk_name_set ns hinst_lemmas.mk,
ss ← attribute.get_instances aux,
ex ← get_name_set_for_attr ex_attr,
to_hinst_lemmas reducible ex ss hs
},
dependencies := [`reducibility, %%(quote simp_attr_name)]} : caching_user_attribute hinst_lemmas),
add_decl (declaration.defn attr_decl_name [] t v reducibility_hints.abbrev ff),
attribute.register attr_decl_name
run_cmd mk_name_set_attr `no_rsimp
run_cmd mk_hinst_lemma_attr_from_simp_attr `rsimp_attr `rsimp `simp `no_rsimp
/- The following lemmas are not needed by rsimp, and they actually hurt performance since they generate a lot of
instances. -/
attribute [no_rsimp]
id.def ne.def not_true not_false_iff ne_self_iff_false eq_self_iff_true heq_self_iff_true iff_not_self not_iff_self
true_iff_false false_iff_true and.comm and.assoc and.left_comm and_true true_and and_false false_and not_and_self and_not_self
and_self or.comm or.assoc or.left_comm or_true true_or or_false false_or or_self iff_true true_iff iff_false false_iff
iff_self implies_true_iff false_implies_iff if_t_t if_true if_false
namespace rsimp
meta def is_value_like : expr → bool
| e :=
if ¬ e^.is_app then ff
else let fn := e^.get_app_fn in
if ¬ fn^.is_constant then ff
else let nargs := e^.get_app_num_args,
fname := fn^.const_name in
if fname = `zero ∧ nargs = 2 then tt
else if fname = `one ∧ nargs = 2 then tt
else if fname = `bit0 ∧ nargs = 3 then is_value_like e^.app_arg
else if fname = `bit1 ∧ nargs = 4 then is_value_like e^.app_arg
else if fname = `char.of_nat ∧ nargs = 1 then is_value_like e^.app_arg
else ff
/-- Return the size of term by considering only explicit arguments. -/
meta def explicit_size : expr → tactic nat
| e :=
if ¬ e^.is_app then return 1
else if is_value_like e then return 1
else fold_explicit_args e 1
(λ n arg, do r ← explicit_size arg, return $ r + n)
/-- Choose smallest element (with respect to explicit_size) in `e`s equivalence class. -/
meta def choose (ccs : cc_state) (e : expr) : tactic expr :=
do sz ← explicit_size e,
p ← ccs^.mfold_eqc e (e, sz) $ λ p e',
if p.2 = 1 then return p
else do {
sz' ← explicit_size e',
if sz' < p.2 then return (e', sz')
else return p
},
return p.1
meta def repr_map := expr_map expr
meta def mk_repr_map := expr_map.mk expr
meta def to_repr_map (ccs : cc_state) : tactic repr_map :=
ccs^.roots^.mfoldl (λ S e, do r ← choose ccs e, return $ S^.insert e r) mk_repr_map
meta def rsimplify (ccs : cc_state) (e : expr) (m : option repr_map := none) : tactic (expr × expr) :=
do m ← match m with
| none := to_repr_map ccs
| some m := return m
end,
r ← simplify_top_down () (λ _ t,
do root ← return $ ccs^.root t,
new_t ← m^.find root,
guard (¬ new_t =ₐ t),
prf ← ccs^.eqv_proof t new_t,
return ((), new_t, prf))
e,
return r.2
structure config :=
(attr_name := `rsimp_attr)
(max_rounds := 8)
open smt_tactic
meta def collect_implied_eqs (cfg : config := {}) (extra := hinst_lemmas.mk) : tactic cc_state :=
do focus1 $ using_smt_with {em_attr := cfg^.attr_name} $
do
add_lemmas_from_facts,
add_lemmas extra,
repeat_at_most cfg^.max_rounds (ematch >> try smt_tactic.close),
(now >> return cc_state.mk)
<|>
to_cc_state
meta def rsimplify_goal (ccs : cc_state) (m : option repr_map := none) : tactic unit :=
do t ← target,
(new_t, pr) ← rsimplify ccs t m,
try (replace_target new_t pr)
meta def rsimplify_at (ccs : cc_state) (h : expr) (m : option repr_map := none) : tactic unit :=
do when (expr.is_local_constant h = ff) (tactic.fail "tactic rsimplify_at failed, the given expression is not a hypothesis"),
htype ← infer_type h,
(new_htype, heq) ← rsimplify ccs htype m,
try $ do assert (expr.local_pp_name h) new_htype,
mk_eq_mp heq h >>= exact,
try $ clear h
end rsimp
open rsimp
namespace tactic
meta def rsimp (cfg : config := {}) (extra := hinst_lemmas.mk) : tactic unit :=
do ccs ← collect_implied_eqs cfg extra,
try $ rsimplify_goal ccs
meta def rsimp_at (h : expr) (cfg : config := {}) (extra := hinst_lemmas.mk) : tactic unit :=
do ccs ← collect_implied_eqs cfg extra,
try $ rsimplify_at ccs h
namespace interactive
/- TODO(Leo): allow user to provide extra lemmas manually -/
meta def rsimp : tactic unit :=
tactic.rsimp
end interactive
end tactic
|
3ff7ced8919f13b40fc122cd7ae18ef816e1168f | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1171.lean | d8a90e5d6ca4547b62276ab607fa3a49d84827d1 | [
"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 | 425 | lean | def Nat.hasDecEq: (a: Nat) → (b: Nat) → Decidable (Eq a b)
| 0, 0 => isTrue rfl
| n+1, 0
| 0, n+1 => isFalse Nat.noConfusion
| n+1, m+1 =>
match h:hasDecEq n m with -- it works without `h:`
| isTrue heq => isTrue (heq ▸ rfl)
| isFalse hne => isFalse (Nat.noConfusion · (λ heq => absurd heq hne))
termination_by _ a b => (a, b)
set_option pp.proofs true
#print Nat.hasDecEq
#print Nat.hasDecEq._unary
|
f5b4b3d70436397e9e3d7757e531fc2d12e772f6 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/set_like/basic.lean | 2176811dcb11fab6a20b6afdd3788573a2c7a078 | [
"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 | 5,891 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import data.set.basic
import tactic.monotonicity.basic
/-!
# Typeclass for types with a set-like extensionality property
The `has_mem` typeclass is used to let terms of a type have elements.
Many instances of `has_mem` have a set-like extensionality property:
things are equal iff they have the same elements. The `set_like`
typeclass provides a unified interface to define a `has_mem` that is
extensional in this way.
The main use of `set_like` is for algebraic subobjects (such as
`submonoid` and `submodule`), whose non-proof data consists only of a
carrier set. In such a situation, the projection to the carrier set
is injective.
In general, a type `A` is `set_like` with elements of type `B` if it
has an injective map to `set B`. This module provides standard
boilerplate for every `set_like`: a `coe_sort`, a `coe` to set, a
`partial_order`, and various extensionality and simp lemmas.
A typical subobject should be declared as:
```
structure my_subobject (X : Type*) [object_typeclass X] :=
(carrier : set X)
(op_mem' : ∀ {x : X}, x ∈ carrier → sorry ∈ carrier)
namespace my_subobject
variables {X : Type*} [object_typeclass X] {x : X}
instance : set_like (my_subobject X) X :=
⟨my_subobject.carrier, λ p q h, by cases p; cases q; congr'⟩
@[simp] lemma mem_carrier {p : my_subobject X} : x ∈ p.carrier ↔ x ∈ (p : set X) := iff.rfl
@[ext] theorem ext {p q : my_subobject X} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := set_like.ext h
/-- Copy of a `my_subobject` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. See Note [range copy pattern]. -/
protected def copy (p : my_subobject X) (s : set X) (hs : s = ↑p) : my_subobject X :=
{ carrier := s,
op_mem' := hs.symm ▸ p.op_mem' }
@[simp] lemma coe_copy (p : my_subobject X) (s : set X) (hs : s = ↑p) :
(p.copy s hs : set X) = s := rfl
lemma copy_eq (p : my_subobject X) (s : set X) (hs : s = ↑p) : p.copy s hs = p :=
set_like.coe_injective hs
end my_subobject
```
An alternative to `set_like` could have been an extensional `has_mem` typeclass:
```
class has_ext_mem (α : out_param $ Type u) (β : Type v) extends has_mem α β :=
(ext_iff : ∀ {s t : β}, s = t ↔ ∀ (x : α), x ∈ s ↔ x ∈ t)
```
While this is equivalent, `set_like` conveniently uses a carrier set projection directly.
## Tags
subobjects
-/
/-- A class to indicate that there is a canonical injection between `A` and `set B`.
This has the effect of giving terms of `A` elements of type `B` (through a `has_mem`
instance) and a compatible coercion to `Type*` as a subtype.
Note: if `set_like.coe` is a projection, implementers should create a simp lemma such as
```
@[simp] lemma mem_carrier {p : my_subobject X} : x ∈ p.carrier ↔ x ∈ (p : set X) := iff.rfl
```
to normalize terms.
-/
@[protect_proj]
class set_like (A : Type*) (B : out_param $ Type*) :=
(coe : A → set B)
(coe_injective' : function.injective coe)
namespace set_like
variables {A : Type*} {B : Type*} [i : set_like A B]
include i
instance : has_coe_t A (set B) := ⟨set_like.coe⟩
@[priority 100]
instance : has_mem B A := ⟨λ x p, x ∈ (p : set B)⟩
-- `dangerous_instance` does not know that `B` is used only as an `out_param`
@[nolint dangerous_instance, priority 100]
instance : has_coe_to_sort A Type* := ⟨λ p, {x : B // x ∈ p}⟩
variables (p q : A)
@[simp, norm_cast] theorem coe_sort_coe : ((p : set B) : Type*) = p := rfl
variables {p q}
protected theorem «exists» {q : p → Prop} :
(∃ x, q x) ↔ (∃ x ∈ p, q ⟨x, ‹_›⟩) := set_coe.exists
protected theorem «forall» {q : p → Prop} :
(∀ x, q x) ↔ (∀ x ∈ p, q ⟨x, ‹_›⟩) := set_coe.forall
theorem coe_injective : function.injective (coe : A → set B) :=
λ x y h, set_like.coe_injective' h
@[simp, norm_cast] theorem coe_set_eq : (p : set B) = q ↔ p = q := coe_injective.eq_iff
theorem ext' (h : (p : set B) = q) : p = q := coe_injective h
theorem ext'_iff : p = q ↔ (p : set B) = q := coe_set_eq.symm
/-- Note: implementers of `set_like` must copy this lemma in order to tag it with `@[ext]`. -/
theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := coe_injective $ set.ext h
theorem ext_iff : p = q ↔ (∀ x, x ∈ p ↔ x ∈ q) := coe_injective.eq_iff.symm.trans set.ext_iff
@[simp] theorem mem_coe {x : B} : x ∈ (p : set B) ↔ x ∈ p := iff.rfl
@[simp, norm_cast] lemma coe_eq_coe {x y : p} : (x : B) = y ↔ x = y := subtype.ext_iff_val.symm
@[simp, norm_cast] lemma coe_mk (x : B) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : B) = x := rfl
@[simp] lemma coe_mem (x : p) : (x : B) ∈ p := x.2
@[simp] protected lemma eta (x : p) (hx : (x : B) ∈ p) : (⟨x, hx⟩ : p) = x := subtype.eta x hx
-- `dangerous_instance` does not know that `B` is used only as an `out_param`
@[nolint dangerous_instance, priority 100]
instance : partial_order A :=
{ le := λ H K, ∀ ⦃x⦄, x ∈ H → x ∈ K,
.. partial_order.lift (coe : A → set B) coe_injective }
lemma le_def {S T : A} : S ≤ T ↔ ∀ ⦃x : B⦄, x ∈ S → x ∈ T := iff.rfl
@[simp, norm_cast]
lemma coe_subset_coe {S T : A} : (S : set B) ⊆ T ↔ S ≤ T := iff.rfl
@[mono] lemma coe_mono : monotone (coe : A → set B) := λ a b, coe_subset_coe.mpr
@[simp, norm_cast]
lemma coe_ssubset_coe {S T : A} : (S : set B) ⊂ T ↔ S < T := iff.rfl
@[mono] lemma coe_strict_mono : strict_mono (coe : A → set B) := λ a b, coe_ssubset_coe.mpr
lemma not_le_iff_exists : ¬(p ≤ q) ↔ ∃ x ∈ p, x ∉ q := set.not_subset
lemma exists_of_lt : p < q → ∃ x ∈ q, x ∉ p := set.exists_of_ssubset
lemma lt_iff_le_and_exists : p < q ↔ p ≤ q ∧ ∃ x ∈ q, x ∉ p :=
by rw [lt_iff_le_not_le, not_le_iff_exists]
end set_like
|
e44aa774dd4f407dad139a3d722725a37030d3b4 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/ring_theory/ideals.lean | bc3c77864cdef573f638cec2fd0227789b4d92ae | [
"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 | 20,013 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import algebra.associated
import linear_algebra.basic
import order.zorn
universes u v
variables {α : Type u} {β : Type v} {a b : α}
open set function
open_locale classical big_operators
namespace ideal
variables [comm_ring α] (I : ideal α)
@[ext] lemma ext {I J : ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J :=
submodule.ext h
theorem eq_top_of_unit_mem
(x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ :=
eq_top_iff.2 $ λ z _, calc
z = z * (y * x) : by simp [h]
... = (z * y) * x : eq.symm $ mul_assoc z y x
... ∈ I : I.mul_mem_left hx
theorem eq_top_of_is_unit_mem {x} (hx : x ∈ I) (h : is_unit x) : I = ⊤ :=
let ⟨y, hy⟩ := is_unit_iff_exists_inv'.1 h in eq_top_of_unit_mem I x y hx hy
theorem eq_top_iff_one : I = ⊤ ↔ (1:α) ∈ I :=
⟨by rintro rfl; trivial,
λ h, eq_top_of_unit_mem _ _ 1 h (by simp)⟩
theorem ne_top_iff_one : I ≠ ⊤ ↔ (1:α) ∉ I :=
not_congr I.eq_top_iff_one
/-- The ideal generated by a subset of a ring -/
def span (s : set α) : ideal α := submodule.span α s
lemma subset_span {s : set α} : s ⊆ span s := submodule.subset_span
lemma span_le {s : set α} {I} : span s ≤ I ↔ s ⊆ I := submodule.span_le
lemma span_mono {s t : set α} : s ⊆ t → span s ≤ span t := submodule.span_mono
@[simp] lemma span_eq : span (I : set α) = I := submodule.span_eq _
@[simp] lemma span_singleton_one : span ({1} : set α) = ⊤ :=
(eq_top_iff_one _).2 $ subset_span $ mem_singleton _
lemma mem_span_insert {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃ a (z ∈ span s), x = a * y + z := submodule.mem_span_insert
lemma mem_span_insert' {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃a, x + a * y ∈ span s := submodule.mem_span_insert'
lemma mem_span_singleton' {x y : α} :
x ∈ span ({y} : set α) ↔ ∃ a, a * y = x := submodule.mem_span_singleton
lemma mem_span_singleton {x y : α} :
x ∈ span ({y} : set α) ↔ y ∣ x :=
mem_span_singleton'.trans $ exists_congr $ λ _, by rw [eq_comm, mul_comm]
lemma span_singleton_le_span_singleton {x y : α} :
span ({x} : set α) ≤ span ({y} : set α) ↔ y ∣ x :=
span_le.trans $ singleton_subset_iff.trans mem_span_singleton
lemma span_eq_bot {s : set α} : span s = ⊥ ↔ ∀ x ∈ s, (x:α) = 0 := submodule.span_eq_bot
lemma span_singleton_eq_bot {x} : span ({x} : set α) = ⊥ ↔ x = 0 := submodule.span_singleton_eq_bot
lemma span_singleton_eq_top {x} : span ({x} : set α) = ⊤ ↔ is_unit x :=
by rw [is_unit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff]
/-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/
@[class] def is_prime (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I
theorem is_prime.mem_or_mem {I : ideal α} (hI : I.is_prime) :
∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2
theorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal α} (hI : I.is_prime)
{x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I :=
hI.2 (h.symm ▸ I.zero_mem)
theorem is_prime.mem_of_pow_mem {I : ideal α} (hI : I.is_prime)
{r : α} (n : ℕ) (H : r^n ∈ I) : r ∈ I :=
begin
induction n with n ih,
{ exact (mt (eq_top_iff_one _).2 hI.1).elim H },
exact or.cases_on (hI.mem_or_mem H) id ih
end
theorem zero_ne_one_of_proper {I : ideal α} (h : I ≠ ⊤) : (0:α) ≠ 1 :=
λ hz, I.ne_top_iff_one.1 h $ hz ▸ I.zero_mem
theorem span_singleton_prime {p : α} (hp : p ≠ 0) :
is_prime (span ({p} : set α)) ↔ prime p :=
by simp [is_prime, prime, span_singleton_eq_top, hp, mem_span_singleton]
/-- An ideal is maximal if it is maximal in the collection of proper ideals. -/
@[class] def is_maximal (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ J, I < J → J = ⊤
theorem is_maximal_iff {I : ideal α} : I.is_maximal ↔
(1:α) ∉ I ∧ ∀ (J : ideal α) x, I ≤ J → x ∉ I → x ∈ J → (1:α) ∈ J :=
and_congr I.ne_top_iff_one $ forall_congr $ λ J,
by rw [lt_iff_le_not_le]; exact
⟨λ H x h hx₁ hx₂, J.eq_top_iff_one.1 $
H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩,
λ H ⟨h₁, h₂⟩, let ⟨x, xJ, xI⟩ := not_subset.1 h₂ in
J.eq_top_iff_one.2 $ H x h₁ xI xJ⟩
theorem is_maximal.eq_of_le {I J : ideal α}
(hI : I.is_maximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J :=
eq_iff_le_not_lt.2 ⟨IJ, λ h, hJ (hI.2 _ h)⟩
theorem is_maximal.exists_inv {I : ideal α}
(hI : I.is_maximal) {x} (hx : x ∉ I) : ∃ y, y * x - 1 ∈ I :=
begin
cases is_maximal_iff.1 hI with H₁ H₂,
rcases mem_span_insert'.1 (H₂ (span (insert x I)) x
(set.subset.trans (subset_insert _ _) subset_span)
hx (subset_span (mem_insert _ _))) with ⟨y, hy⟩,
rw [span_eq, ← neg_mem_iff, add_comm, neg_add', neg_mul_eq_neg_mul] at hy,
exact ⟨-y, hy⟩
end
theorem is_maximal.is_prime {I : ideal α} (H : I.is_maximal) : I.is_prime :=
⟨H.1, λ x y hxy, or_iff_not_imp_left.2 $ λ hx, begin
cases H.exists_inv hx with z hz,
have := I.mul_mem_left hz,
rw [mul_sub, mul_one, mul_comm, mul_assoc] at this,
exact I.neg_mem_iff.1 ((I.add_mem_iff_right $ I.mul_mem_left hxy).1 this)
end⟩
@[priority 100] -- see Note [lower instance priority]
instance is_maximal.is_prime' (I : ideal α) : ∀ [H : I.is_maximal], I.is_prime := is_maximal.is_prime
theorem exists_le_maximal (I : ideal α) (hI : I ≠ ⊤) :
∃ M : ideal α, M.is_maximal ∧ I ≤ M :=
begin
rcases zorn.zorn_partial_order₀ { J : ideal α | J ≠ ⊤ } _ I hI with ⟨M, M0, IM, h⟩,
{ refine ⟨M, ⟨M0, λ J hJ, by_contradiction $ λ J0, _⟩, IM⟩,
cases h J J0 (le_of_lt hJ), exact lt_irrefl _ hJ },
{ intros S SC cC I IS,
refine ⟨Sup S, λ H, _, λ _, le_Sup⟩,
obtain ⟨J, JS, J0⟩ : ∃ J ∈ S, (1 : α) ∈ J,
from (submodule.mem_Sup_of_directed ⟨I, IS⟩ cC.directed_on).1 ((eq_top_iff_one _).1 H),
exact SC JS ((eq_top_iff_one _).2 J0) }
end
theorem mem_span_pair {x y z : α} :
z ∈ span ({x, y} : set α) ↔ ∃ a b, a * x + b * y = z :=
by simp [mem_span_insert, mem_span_singleton', @eq_comm _ _ z]
lemma span_singleton_lt_span_singleton [integral_domain β] {x y : β} :
span ({x} : set β) < span ({y} : set β) ↔ y ≠ 0 ∧ ∃ d : β, ¬ is_unit d ∧ x = y * d :=
by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,
dvd_and_not_dvd_iff]
lemma factors_decreasing [integral_domain β] (b₁ b₂ : β) (h₁ : b₁ ≠ 0) (h₂ : ¬ is_unit b₂) :
span ({b₁ * b₂} : set β) < span {b₁} :=
lt_of_le_not_le (ideal.span_le.2 $ singleton_subset_iff.2 $
ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) $ λ h,
h₂ $ is_unit_of_dvd_one _ $ (mul_dvd_mul_iff_left h₁).1 $
by rwa [mul_one, ← ideal.span_singleton_le_span_singleton]
/-- The quotient `R/I` of a ring `R` by an ideal `I`. -/
def quotient (I : ideal α) := I.quotient
namespace quotient
variables {I} {x y : α}
/-- The map from a ring `R` to a quotient ring `R/I`. -/
def mk (I : ideal α) (a : α) : I.quotient := submodule.quotient.mk a
instance : inhabited (quotient I) := ⟨mk I 37⟩
protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := submodule.quotient.eq I
instance (I : ideal α) : has_one I.quotient := ⟨mk I 1⟩
@[simp] lemma mk_one (I : ideal α) : mk I 1 = 1 := rfl
instance (I : ideal α) : has_mul I.quotient :=
⟨λ a b, quotient.lift_on₂' a b (λ a b, mk I (a * b)) $
λ a₁ a₂ b₁ b₂ h₁ h₂, quot.sound $ begin
refine calc a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ : _
... ∈ I : I.add_mem (I.mul_mem_left h₁) (I.mul_mem_right h₂),
rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁]
end⟩
@[simp] theorem mk_mul : mk I (x * y) = mk I x * mk I y := rfl
instance (I : ideal α) : comm_ring I.quotient :=
{ mul := (*),
one := 1,
mul_assoc := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (mul_assoc a b c),
mul_comm := λ a b, quotient.induction_on₂' a b $
λ a b, congr_arg (mk _) (mul_comm a b),
one_mul := λ a, quotient.induction_on' a $
λ a, congr_arg (mk _) (one_mul a),
mul_one := λ a, quotient.induction_on' a $
λ a, congr_arg (mk _) (mul_one a),
left_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (left_distrib a b c),
right_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (right_distrib a b c),
..submodule.quotient.add_comm_group I }
/-- `ideal.quotient.mk` as a `ring_hom` -/
def mk_hom (I : ideal α) : α →+* I.quotient := ⟨mk I, rfl, λ _ _, rfl, rfl, λ _ _, rfl⟩
lemma mk_eq_mk_hom (I : ideal α) (x : α) : ideal.quotient.mk I x = ideal.quotient.mk_hom I x := rfl
/-- The image of an ideal J under the quotient map `R → R/I`. -/
def map_mk (I J : ideal α) : ideal I.quotient :=
{ carrier := mk I '' J,
zero_mem' := ⟨0, J.zero_mem, rfl⟩,
add_mem' := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩;
exact ⟨x + y, J.add_mem hx hy, rfl⟩,
smul_mem' := by rintro ⟨c⟩ _ ⟨x, hx, rfl⟩;
exact ⟨c * x, J.mul_mem_left hx, rfl⟩ }
@[simp] lemma mk_zero (I : ideal α) : mk I 0 = 0 := rfl
@[simp] lemma mk_add (I : ideal α) (a b : α) : mk I (a + b) = mk I a + mk I b := rfl
@[simp] lemma mk_neg (I : ideal α) (a : α) : mk I (-a : α) = -mk I a := rfl
@[simp] lemma mk_sub (I : ideal α) (a b : α) : mk I (a - b : α) = mk I a - mk I b := rfl
@[simp] lemma mk_pow (I : ideal α) (a : α) (n : ℕ) : mk I (a ^ n : α) = mk I a ^ n :=
(mk_hom I).map_pow a n
lemma mk_prod {ι} (I : ideal α) (s : finset ι) (f : ι → α) :
mk I (∏ i in s, f i) = ∏ i in s, mk I (f i) :=
(mk_hom I).map_prod f s
lemma mk_sum {ι} (I : ideal α) (s : finset ι) (f : ι → α) :
mk I (∑ i in s, f i) = ∑ i in s, mk I (f i) :=
(mk_hom I).map_sum f s
lemma eq_zero_iff_mem {I : ideal α} : mk I a = 0 ↔ a ∈ I :=
by conv {to_rhs, rw ← sub_zero a }; exact quotient.eq'
theorem zero_eq_one_iff {I : ideal α} : (0 : I.quotient) = 1 ↔ I = ⊤ :=
eq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm
theorem zero_ne_one_iff {I : ideal α} : (0 : I.quotient) ≠ 1 ↔ I ≠ ⊤ :=
not_congr zero_eq_one_iff
protected theorem nonzero {I : ideal α} (hI : I ≠ ⊤) : nonzero I.quotient :=
{ zero_ne_one := zero_ne_one_iff.2 hI }
instance (I : ideal α) [hI : I.is_prime] : integral_domain I.quotient :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b,
quotient.induction_on₂' a b $ λ a b hab,
(hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim
(or.inl ∘ eq_zero_iff_mem.2)
(or.inr ∘ eq_zero_iff_mem.2),
..quotient.nonzero hI.1,
..quotient.comm_ring I }
lemma exists_inv {I : ideal α} [hI : I.is_maximal] :
∀ {a : I.quotient}, a ≠ 0 → ∃ b : I.quotient, a * b = 1 :=
begin
rintro ⟨a⟩ h,
cases hI.exists_inv (mt eq_zero_iff_mem.2 h) with b hb,
rw [mul_comm] at hb,
exact ⟨mk _ b, quot.sound hb⟩
end
/-- quotient by maximal ideal is a field. def rather than instance, since users will have
computable inverses in some applications -/
protected noncomputable def field (I : ideal α) [hI : I.is_maximal] : field I.quotient :=
{ inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha),
mul_inv_cancel := λ a (ha : a ≠ 0), show a * dite _ _ _ = _,
by rw dif_neg ha;
exact classical.some_spec (exists_inv ha),
inv_zero := dif_pos rfl,
..quotient.integral_domain I }
variable [comm_ring β]
/-- Given a ring homomorphism `f : α →+* β` sending all elements of an ideal to zero,
lift it to the quotient by this ideal. -/
def lift (S : ideal α) (f : α →+* β) (H : ∀ (a : α), a ∈ S → f a = 0) :
quotient S →+* β :=
{ to_fun := λ x, quotient.lift_on' x f $ λ (a b) (h : _ ∈ _),
eq_of_sub_eq_zero $ by rw [← f.map_sub, H _ h],
map_one' := f.map_one,
map_zero' := f.map_zero,
map_add' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ f.map_add,
map_mul' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ f.map_mul }
@[simp] lemma lift_mk (S : ideal α) (f : α →+* β) (H : ∀ (a : α), a ∈ S → f a = 0) :
lift S f H (mk S a) = f a := rfl
end quotient
section lattice
variables {R : Type u} [comm_ring R]
theorem mem_Inf {s : set (ideal R)} {x : R} :
x ∈ Inf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I :=
⟨λ hx I his, hx I ⟨I, infi_pos his⟩, λ H I ⟨J, hij⟩, hij ▸ λ S ⟨hj, hS⟩, hS ▸ H hj⟩
end lattice
/-- All ideals in a field are trivial. -/
lemma eq_bot_or_top {K : Type u} [field K] (I : ideal K) :
I = ⊥ ∨ I = ⊤ :=
begin
rw classical.or_iff_not_imp_right,
change _ ≠ _ → _,
rw ideal.ne_top_iff_one,
intro h1,
rw eq_bot_iff,
intros r hr,
by_cases H : r = 0, {simpa},
simpa [H, h1] using submodule.smul_mem I r⁻¹ hr,
end
lemma eq_bot_of_prime {K : Type u} [field K] (I : ideal K) [h : I.is_prime] :
I = ⊥ :=
classical.or_iff_not_imp_right.mp I.eq_bot_or_top h.1
end ideal
/-- The set of non-invertible elements of a monoid. -/
def nonunits (α : Type u) [monoid α] : set α := { a | ¬is_unit a }
@[simp] theorem mem_nonunits_iff [comm_monoid α] : a ∈ nonunits α ↔ ¬ is_unit a := iff.rfl
theorem mul_mem_nonunits_right [comm_monoid α] :
b ∈ nonunits α → a * b ∈ nonunits α :=
mt is_unit_of_mul_is_unit_right
theorem mul_mem_nonunits_left [comm_monoid α] :
a ∈ nonunits α → a * b ∈ nonunits α :=
mt is_unit_of_mul_is_unit_left
theorem zero_mem_nonunits [semiring α] : 0 ∈ nonunits α ↔ (0:α) ≠ 1 :=
not_congr is_unit_zero_iff
@[simp] theorem one_not_mem_nonunits [monoid α] : (1:α) ∉ nonunits α :=
not_not_intro is_unit_one
theorem coe_subset_nonunits [comm_ring α] {I : ideal α} (h : I ≠ ⊤) :
(I : set α) ⊆ nonunits α :=
λ x hx hu, h $ I.eq_top_of_is_unit_mem hx hu
lemma exists_max_ideal_of_mem_nonunits [comm_ring α] (h : a ∈ nonunits α) :
∃ I : ideal α, I.is_maximal ∧ a ∈ I :=
begin
have : ideal.span ({a} : set α) ≠ ⊤,
{ intro H, rw ideal.span_singleton_eq_top at H, contradiction },
rcases ideal.exists_le_maximal _ this with ⟨I, Imax, H⟩,
use [I, Imax], apply H, apply ideal.subset_span, exact set.mem_singleton a
end
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A commutative ring is local if it has a unique maximal ideal. Note that
`local_ring` is a predicate. -/
class local_ring (α : Type u) [comm_ring α] extends nonzero α : Prop :=
(is_local : ∀ (a : α), (is_unit a) ∨ (is_unit (1 - a)))
end prio
namespace local_ring
variables [comm_ring α] [local_ring α]
lemma is_unit_or_is_unit_one_sub_self (a : α) :
(is_unit a) ∨ (is_unit (1 - a)) :=
is_local a
lemma is_unit_of_mem_nonunits_one_sub_self (a : α) (h : (1 - a) ∈ nonunits α) :
is_unit a :=
or_iff_not_imp_right.1 (is_local a) h
lemma is_unit_one_sub_self_of_mem_nonunits (a : α) (h : a ∈ nonunits α) :
is_unit (1 - a) :=
or_iff_not_imp_left.1 (is_local a) h
lemma nonunits_add {x y} (hx : x ∈ nonunits α) (hy : y ∈ nonunits α) :
x + y ∈ nonunits α :=
begin
rintros ⟨u, hu⟩,
apply hy,
suffices : is_unit ((↑u⁻¹ : α) * y),
{ rcases this with ⟨s, hs⟩,
use u * s,
convert congr_arg (λ z, (u : α) * z) hs,
rw ← mul_assoc, simp },
rw show (↑u⁻¹ * y) = (1 - ↑u⁻¹ * x),
{ rw eq_sub_iff_add_eq,
replace hu := congr_arg (λ z, (↑u⁻¹ : α) * z) hu.symm,
simpa [mul_add, add_comm] using hu },
apply is_unit_one_sub_self_of_mem_nonunits,
exact mul_mem_nonunits_right hx
end
variable (α)
/-- The ideal of elements that are not units. -/
def maximal_ideal : ideal α :=
{ carrier := nonunits α,
zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,
add_mem' := λ x y hx hy, nonunits_add hx hy,
smul_mem' := λ a x, mul_mem_nonunits_right }
instance maximal_ideal.is_maximal : (maximal_ideal α).is_maximal :=
begin
rw ideal.is_maximal_iff,
split,
{ intro h, apply h, exact is_unit_one },
{ intros I x hI hx H,
erw not_not at hx,
rcases hx with ⟨u,rfl⟩,
simpa using I.smul_mem ↑u⁻¹ H }
end
lemma max_ideal_unique :
∃! I : ideal α, I.is_maximal :=
⟨maximal_ideal α, maximal_ideal.is_maximal α,
λ I hI, hI.eq_of_le (maximal_ideal.is_maximal α).1 $
λ x hx, hI.1 ∘ I.eq_top_of_is_unit_mem hx⟩
variable {α}
@[simp] lemma mem_maximal_ideal (x) :
x ∈ maximal_ideal α ↔ x ∈ nonunits α := iff.rfl
end local_ring
lemma local_of_nonunits_ideal [comm_ring α] (hnze : (0:α) ≠ 1)
(h : ∀ x y ∈ nonunits α, x + y ∈ nonunits α) : local_ring α :=
{ zero_ne_one := hnze,
is_local := λ x, or_iff_not_imp_left.mpr $ λ hx,
begin
by_contra H,
apply h _ _ hx H,
simp [-sub_eq_add_neg, add_sub_cancel'_right]
end}
lemma local_of_unique_max_ideal [comm_ring α] (h : ∃! I : ideal α, I.is_maximal) :
local_ring α :=
local_of_nonunits_ideal
(let ⟨I, Imax, _⟩ := h in (λ (H : 0 = 1), Imax.1 $ I.eq_top_iff_one.2 $ H ▸ I.zero_mem))
$ λ x y hx hy H,
let ⟨I, Imax, Iuniq⟩ := h in
let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx in
let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy in
have xmemI : x ∈ I, from ((Iuniq Ix Ixmax) ▸ Hx),
have ymemI : y ∈ I, from ((Iuniq Iy Iymax) ▸ Hy),
Imax.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A local ring homomorphism is a homomorphism between local rings
such that the image of the maximal ideal of the source is contained within
the maximal ideal of the target. -/
class is_local_ring_hom [semiring α] [semiring β] (f : α →+* β) : Prop :=
(map_nonunit : ∀ a, is_unit (f a) → is_unit a)
end prio
@[simp] lemma is_unit_of_map_unit [semiring α] [semiring β] (f : α →+* β) [is_local_ring_hom f]
(a) (h : is_unit (f a)) : is_unit a :=
is_local_ring_hom.map_nonunit a h
theorem of_irreducible_map [semiring α] [semiring β] (f : α →+* β) [h : is_local_ring_hom f] {x : α}
(hfx : irreducible (f x)) : irreducible x :=
⟨λ h, hfx.1 $ is_unit.map f.to_monoid_hom h, λ p q hx, let ⟨H⟩ := h in
or.imp (H p) (H q) $ hfx.2 _ _ $ f.map_mul p q ▸ congr_arg f hx⟩
section
open local_ring
variables [comm_ring α] [local_ring α] [comm_ring β] [local_ring β]
variables (f : α →+* β) [is_local_ring_hom f]
lemma map_nonunit (a) (h : a ∈ maximal_ideal α) : f a ∈ maximal_ideal β :=
λ H, h $ is_unit_of_map_unit f a H
end
namespace local_ring
variables [comm_ring α] [local_ring α] [comm_ring β] [local_ring β]
variable (α)
/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/
def residue_field := (maximal_ideal α).quotient
noncomputable instance residue_field.field : field (residue_field α) :=
ideal.quotient.field (maximal_ideal α)
noncomputable instance : inhabited (residue_field α) := ⟨37⟩
/-- The quotient map from a local ring to its residue field. -/
def residue : α →+* (residue_field α) :=
ideal.quotient.mk_hom _
namespace residue_field
variables {α β}
/-- The map on residue fields induced by a local homomorphism between local rings -/
noncomputable def map (f : α →+* β) [is_local_ring_hom f] :
residue_field α →+* residue_field β :=
ideal.quotient.lift (maximal_ideal α) ((ideal.quotient.mk_hom _).comp f) $
λ a ha,
begin
erw ideal.quotient.eq_zero_iff_mem,
exact map_nonunit f a ha
end
end residue_field
end local_ring
namespace field
variables [field α]
@[priority 100] -- see Note [lower instance priority]
instance : local_ring α :=
{ is_local := λ a,
if h : a = 0
then or.inr (by rw [h, sub_zero]; exact is_unit_one)
else or.inl $ is_unit_of_mul_eq_one a a⁻¹ $ div_self h }
end field
|
838c3c0f9759c5b73bbd9eb8f52a2d4f6a2db7a5 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/data/equiv/ring.lean | d14dbfe1be5aa0f813a0d2ab39b5505a0bbf9bbd | [
"Apache-2.0"
] | permissive | midfield/mathlib | c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7 | 775edc615ecec631d65b6180dbcc7bc26c3abc26 | refs/heads/master | 1,675,330,551,921 | 1,608,304,514,000 | 1,608,304,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,724 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
-/
import data.equiv.mul_add
import algebra.field
import algebra.opposites
/-!
# (Semi)ring equivs
In this file we define extension of `equiv` called `ring_equiv`, which is a datatype representing an
isomorphism of `semiring`s, `ring`s, `division_ring`s, or `field`s. We also introduce the
corresponding group of automorphisms `ring_aut`.
## Notations
The extended equiv have coercions to functions, and the coercion is the canonical notation when
treating the isomorphism as maps.
## Implementation notes
The fields for `ring_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are
deprecated.
Definition of multiplication in the groups of automorphisms agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with
`category_theory.comp`.
## Tags
equiv, mul_equiv, add_equiv, ring_equiv, mul_aut, add_aut, ring_aut
-/
variables {R : Type*} {S : Type*} {S' : Type*}
set_option old_structure_cmd true
/-- An equivalence between two (semi)rings that preserves the algebraic structure. -/
structure ring_equiv (R S : Type*) [has_mul R] [has_add R] [has_mul S] [has_add S]
extends R ≃ S, R ≃* S, R ≃+ S
infix ` ≃+* `:25 := ring_equiv
/-- The "plain" equivalence of types underlying an equivalence of (semi)rings. -/
add_decl_doc ring_equiv.to_equiv
/-- The equivalence of additive monoids underlying an equivalence of (semi)rings. -/
add_decl_doc ring_equiv.to_add_equiv
/-- The equivalence of multiplicative monoids underlying an equivalence of (semi)rings. -/
add_decl_doc ring_equiv.to_mul_equiv
namespace ring_equiv
section basic
variables [has_mul R] [has_add R] [has_mul S] [has_add S] [has_mul S'] [has_add S']
instance : has_coe_to_fun (R ≃+* S) := ⟨_, ring_equiv.to_fun⟩
@[simp] lemma to_fun_eq_coe_fun (f : R ≃+* S) : f.to_fun = f := rfl
/-- A ring isomorphism preserves multiplication. -/
@[simp] lemma map_mul (e : R ≃+* S) (x y : R) : e (x * y) = e x * e y := e.map_mul' x y
/-- A ring isomorphism preserves addition. -/
@[simp] lemma map_add (e : R ≃+* S) (x y : R) : e (x + y) = e x + e y := e.map_add' x y
/-- Two ring isomorphisms agree if they are defined by the
same underlying function. -/
@[ext] lemma ext {f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g :=
begin
have h₁ : f.to_equiv = g.to_equiv := equiv.ext h,
cases f, cases g, congr,
{ exact (funext h) },
{ exact congr_arg equiv.inv_fun h₁ }
end
protected lemma congr_arg {f : R ≃+* S} : Π {x x' : R}, x = x' → f x = f x'
| _ _ rfl := rfl
protected lemma congr_fun {f g : R ≃+* S} (h : f = g) (x : R) : f x = g x := h ▸ rfl
lemma ext_iff {f g : R ≃+* S} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, ext⟩
instance has_coe_to_mul_equiv : has_coe (R ≃+* S) (R ≃* S) := ⟨ring_equiv.to_mul_equiv⟩
instance has_coe_to_add_equiv : has_coe (R ≃+* S) (R ≃+ S) := ⟨ring_equiv.to_add_equiv⟩
@[norm_cast] lemma coe_mul_equiv (f : R ≃+* S) (a : R) :
(f : R ≃* S) a = f a := rfl
@[norm_cast] lemma coe_add_equiv (f : R ≃+* S) (a : R) :
(f : R ≃+ S) a = f a := rfl
variable (R)
/-- The identity map is a ring isomorphism. -/
@[refl] protected def refl : R ≃+* R := { .. mul_equiv.refl R, .. add_equiv.refl R }
@[simp] lemma refl_apply (x : R) : ring_equiv.refl R x = x := rfl
@[simp] lemma coe_add_equiv_refl : (ring_equiv.refl R : R ≃+ R) = add_equiv.refl R := rfl
@[simp] lemma coe_mul_equiv_refl : (ring_equiv.refl R : R ≃* R) = mul_equiv.refl R := rfl
instance : inhabited (R ≃+* R) := ⟨ring_equiv.refl R⟩
variables {R}
/-- The inverse of a ring isomorphism is a ring isomorphism. -/
@[symm] protected def symm (e : R ≃+* S) : S ≃+* R :=
{ .. e.to_mul_equiv.symm, .. e.to_add_equiv.symm }
/-- See Note [custom simps projection] -/
def simps.inv_fun (e : R ≃+* S) : S → R := e.symm
initialize_simps_projections ring_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp] lemma symm_symm (e : R ≃+* S) : e.symm.symm = e := ext $ λ x, rfl
@[simp] lemma coe_symm_mk (f : R → S) (g h₁ h₂ h₃ h₄) : ⇑(mk f g h₁ h₂ h₃ h₄).symm = g := rfl
/-- Transitivity of `ring_equiv`. -/
@[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' :=
{ .. (e₁.to_mul_equiv.trans e₂.to_mul_equiv), .. (e₁.to_add_equiv.trans e₂.to_add_equiv) }
@[simp] lemma trans_apply {A B C : Type*}
[semiring A] [semiring B] [semiring C] (e : A ≃+* B) (f : B ≃+* C) (a : A) :
e.trans f a = f (e a) := rfl
protected lemma bijective (e : R ≃+* S) : function.bijective e := e.to_equiv.bijective
protected lemma injective (e : R ≃+* S) : function.injective e := e.to_equiv.injective
protected lemma surjective (e : R ≃+* S) : function.surjective e := e.to_equiv.surjective
@[simp] lemma apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.to_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply
lemma image_eq_preimage (e : R ≃+* S) (s : set R) : e '' s = e.symm ⁻¹' s :=
e.to_equiv.image_eq_preimage s
end basic
section comm_semiring
open opposite
variables (R) [comm_semiring R]
/-- A commutative ring is isomorphic to its opposite. -/
def to_opposite : R ≃+* Rᵒᵖ :=
{ map_add' := λ x y, rfl,
map_mul' := λ x y, mul_comm (op y) (op x),
..equiv_to_opposite }
@[simp]
lemma to_opposite_apply (r : R) : to_opposite R r = op r := rfl
@[simp]
lemma to_opposite_symm_apply (r : Rᵒᵖ) : (to_opposite R).symm r = unop r := rfl
end comm_semiring
section semiring
variables [semiring R] [semiring S] (f : R ≃+* S) (x y : R)
/-- A ring isomorphism sends one to one. -/
@[simp] lemma map_one : f 1 = 1 := (f : R ≃* S).map_one
/-- A ring isomorphism sends zero to zero. -/
@[simp] lemma map_zero : f 0 = 0 := (f : R ≃+ S).map_zero
variable {x}
@[simp] lemma map_eq_one_iff : f x = 1 ↔ x = 1 := (f : R ≃* S).map_eq_one_iff
@[simp] lemma map_eq_zero_iff : f x = 0 ↔ x = 0 := (f : R ≃+ S).map_eq_zero_iff
lemma map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := (f : R ≃* S).map_ne_one_iff
lemma map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := (f : R ≃+ S).map_ne_zero_iff
/-- Produce a ring isomorphism from a bijective ring homomorphism. -/
noncomputable def of_bijective (f : R →+* S) (hf : function.bijective f) : R ≃+* S :=
{ .. equiv.of_bijective f hf, .. f }
end semiring
section
variables [ring R] [ring S] (f : R ≃+* S) (x y : R)
@[simp] lemma map_neg : f (-x) = -f x := (f : R ≃+ S).map_neg x
@[simp] lemma map_sub : f (x - y) = f x - f y := (f : R ≃+ S).map_sub x y
@[simp] lemma map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1
end
section semiring_hom
variables [semiring R] [semiring S] [semiring S']
/-- Reinterpret a ring equivalence as a ring homomorphism. -/
def to_ring_hom (e : R ≃+* S) : R →+* S :=
{ .. e.to_mul_equiv.to_monoid_hom, .. e.to_add_equiv.to_add_monoid_hom }
lemma to_ring_hom_injective : function.injective (to_ring_hom : (R ≃+* S) → R →+* S) :=
λ f g h, ring_equiv.ext (ring_hom.ext_iff.1 h)
instance has_coe_to_ring_hom : has_coe (R ≃+* S) (R →+* S) := ⟨ring_equiv.to_ring_hom⟩
@[norm_cast] lemma coe_ring_hom (f : R ≃+* S) (a : R) :
(f : R →+* S) a = f a := rfl
lemma coe_ring_hom_inj_iff {R S : Type*} [semiring R] [semiring S] (f g : R ≃+* S) :
f = g ↔ (f : R →+* S) = g :=
⟨congr_arg _, λ h, ext $ ring_hom.ext_iff.mp h⟩
/-- Reinterpret a ring equivalence as a monoid homomorphism. -/
abbreviation to_monoid_hom (e : R ≃+* S) : R →* S := e.to_ring_hom.to_monoid_hom
/-- Reinterpret a ring equivalence as an `add_monoid` homomorphism. -/
abbreviation to_add_monoid_hom (e : R ≃+* S) : R →+ S := e.to_ring_hom.to_add_monoid_hom
@[simp]
lemma to_ring_hom_refl : (ring_equiv.refl R).to_ring_hom = ring_hom.id R := rfl
@[simp]
lemma to_monoid_hom_refl : (ring_equiv.refl R).to_monoid_hom = monoid_hom.id R := rfl
@[simp]
lemma to_add_monoid_hom_refl : (ring_equiv.refl R).to_add_monoid_hom = add_monoid_hom.id R := rfl
@[simp]
lemma to_ring_hom_apply_symm_to_ring_hom_apply (e : R ≃+* S) :
∀ (y : S), e.to_ring_hom (e.symm.to_ring_hom y) = y :=
e.to_equiv.apply_symm_apply
@[simp]
lemma symm_to_ring_hom_apply_to_ring_hom_apply (e : R ≃+* S) :
∀ (x : R), e.symm.to_ring_hom (e.to_ring_hom x) = x :=
equiv.symm_apply_apply (e.to_equiv)
@[simp]
lemma to_ring_hom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') :
(e₁.trans e₂).to_ring_hom = e₂.to_ring_hom.comp e₁.to_ring_hom := rfl
/--
Construct an equivalence of rings from homomorphisms in both directions, which are inverses.
-/
def of_hom_inv (hom : R →+* S) (inv : S →+* R)
(hom_inv_id : inv.comp hom = ring_hom.id R) (inv_hom_id : hom.comp inv = ring_hom.id S) :
R ≃+* S :=
{ inv_fun := inv,
left_inv := λ x, ring_hom.congr_fun hom_inv_id x,
right_inv := λ x, ring_hom.congr_fun inv_hom_id x,
..hom }
@[simp]
lemma of_hom_inv_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (r : R) :
(of_hom_inv hom inv hom_inv_id inv_hom_id) r = hom r := rfl
@[simp]
lemma of_hom_inv_symm_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (s : S) :
(of_hom_inv hom inv hom_inv_id inv_hom_id).symm s = inv s := rfl
end semiring_hom
end ring_equiv
namespace mul_equiv
/-- Gives a `ring_equiv` from a `mul_equiv` preserving addition.-/
def to_ring_equiv {R : Type*} {S : Type*} [has_add R] [has_add S] [has_mul R] [has_mul S]
(h : R ≃* S) (H : ∀ x y : R, h (x + y) = h x + h y) : R ≃+* S :=
{..h.to_equiv, ..h, ..add_equiv.mk' h.to_equiv H }
end mul_equiv
namespace ring_equiv
variables [has_add R] [has_add S] [has_mul R] [has_mul S]
@[simp] theorem trans_symm (e : R ≃+* S) : e.trans e.symm = ring_equiv.refl R := ext e.3
@[simp] theorem symm_trans (e : R ≃+* S) : e.symm.trans e = ring_equiv.refl S := ext e.4
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected lemma is_integral_domain {A : Type*} (B : Type*) [ring A] [ring B]
(hB : is_integral_domain B) (e : A ≃+* B) : is_integral_domain A :=
{ mul_comm := λ x y, have e.symm (e x * e y) = e.symm (e y * e x), by rw hB.mul_comm, by simpa,
eq_zero_or_eq_zero_of_mul_eq_zero := λ x y hxy,
have e x * e y = 0, by rw [← e.map_mul, hxy, e.map_zero],
(hB.eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).imp (λ hx, by simpa using congr_arg e.symm hx)
(λ hy, by simpa using congr_arg e.symm hy),
exists_pair_ne := ⟨e.symm 0, e.symm 1,
by { haveI : nontrivial B := hB.to_nontrivial, exact e.symm.injective.ne zero_ne_one }⟩ }
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected def integral_domain {A : Type*} (B : Type*) [ring A] [integral_domain B]
(e : A ≃+* B) : integral_domain A :=
{ .. (‹_› : ring A), .. e.is_integral_domain B (integral_domain.to_is_integral_domain B) }
end ring_equiv
namespace equiv
variables (K : Type*) [division_ring K]
/-- In a division ring `K`, the unit group `units K`
is equivalent to the subtype of nonzero elements. -/
-- TODO: this might already exist elsewhere for `group_with_zero`
-- deduplicate or generalize
def units_equiv_ne_zero : units K ≃ {a : K | a ≠ 0} :=
⟨λ a, ⟨a.1, a.ne_zero⟩, λ a, units.mk0 _ a.2, λ ⟨_, _, _, _⟩, units.ext rfl, λ ⟨_, _⟩, rfl⟩
variable {K}
@[simp]
lemma coe_units_equiv_ne_zero (a : units K) :
((units_equiv_ne_zero K a) : K) = a := rfl
end equiv
|
c4d10d21c660b6069ccaa49c2a05dc0c2a7cb063 | f3be49eddff7edf577d3d3666e314d995f7a6357 | /TBA/Exercises/Exercise1.lean | b3446bd80d0c44fd8216fbd2c06caf0c582f128a | [] | no_license | IPDSnelting/tba-2021 | 8b930bcd2f4aae44a2ddc86e72b77f84e6d46e82 | b6390e55b768423d3266969e81d19290129c5914 | refs/heads/master | 1,686,754,693,583 | 1,625,135,602,000 | 1,625,136,365,000 | 355,124,341 | 50 | 7 | null | 1,625,133,762,000 | 1,617,699,824,000 | Lean | UTF-8 | Lean | false | false | 2,805 | lean | -- Let's first prove some simple example lemmas with the logical connectives we learned in the lecture.
section
-- Variables in sections determine the type of certain variables for the remainder of the section, saving us a bit of space.
variable (p q r : Prop)
example : p → p := _
example : p → (q → p) := _
-- Note: `→` associates to the right, so the above proposition is equivalent to
-- `p → q → p`
example : (p → False) → (p → q) := _
example : (p ∨ p) → p := _
example : (p → q → r) → (p ∧ q → r) := _
example : (p ∧ q → r) → (p → q → r) := _
example : p → (p → q) → p ∧ q := _
theorem imp_and : (p → q ∧ r) → (p → q) ∧ (p → r) := _
-- Matching on `And.intro` can quickly become tedious, so you can use the following helper functions from now on:
#check And.left
#check And.right
/- BIIMPLICATION -/
-- Biimplication ("if and only if") is written \iff.
-- It is defined as a data type on the constructor
-- Iff.intro : (A → B) → (B → A) → (A ↔ B)
-- Can you recover the proof for A → B by a match expression?
example (hpq : p ↔ q) : (p → q) := _
-- Like for `And`, we have names for both directions of the biimplication:
#check Iff.mp
#check Iff.mpr
-- Prove the following biimplications using the threorem from above!
-- Note: `↔` is defined to bind less tightly than other connectives such as `∧` or `∨`.
theorem iff_and : (p → q ∧ r) ↔ (p → q) ∧ (p → r) := _
theorem or_and : (p ∨ q → r) ↔ (p → r) ∧ (q → r) := _
theorem iff_and_false : False ↔ p ∧ False := _
/- NEGATION -/
-- Negation is defined by ¬ A := (A → False).
-- How is that a good choice? Let us check some basic properties of negation:
theorem imp_not_not : p → ¬¬p := _
example : ¬(p ∧ ¬p) := _
theorem not_or_not : (¬p ∨ ¬q) → ¬(p ∧ q) := _
-- The following ones are a harder to prove. Don't hesitate to skip them or ask your
-- tutors if you get stuck
example : ¬(p ↔ ¬p) := _
example : ¬¬(¬¬p → p) := _
/- CLASSICAL AXIOMS -/
-- Some tautologies about negation cannot be proven by just assuming the logical
-- connectives as algebraic propositions. Instead, we need to assume these facts
-- as axioms. To have access to these, we need to open a namespace called "Classical".
-- We will learn more about constructive versus classical logic in week 5.
open Classical
-- The following statement is called the _law of excluded middle_.
-- It is assumed as an axiom, which means that it doesn't have to be proved.
#check em p
-- Now use the law of excluded middle to show that the theorem not_or_not is reversible:
theorem not_and : ¬(p ∧ q) → (¬ p ∨ ¬ q) := _
-- Also, we can now deal better with double negations:
example : ¬¬p ↔ p := _
end
|
1b746ce946cd55d891da4898613ccebd61941fac | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/interactive/info_tactic.lean | 9cee3aa86a6dcad84dffe2eb91ab55a933840543 | [
"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 | 406 | lean | open tactic
open lean.parser
open interactive
open interactive.types
meta def fooo (p : parse $ optional $ pexpr_list_or_texpr) : tactic unit := skip
run_cmd add_interactive [`fooo]
example : false :=
begin
fooo,
--^ "command": "info"
fooo ,
--^ "command": "info"
fooo [ ],
--^ "command": "info"
fooo [d] ,
--^ "command": "info"
_root_.fooo none
--^ "command": "info"
end
|
a2b32f5a59ae823bd4ff57141535681ec72c32d5 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/linear_algebra/matrix/determinant.lean | 96afa0d0acd0574ded44d18fbd1f0d61c78a5f89 | [
"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 | 31,780 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Tim Baanen
-/
import data.matrix.pequiv
import data.matrix.block
import data.matrix.notation
import data.fintype.big_operators
import group_theory.perm.fin
import group_theory.perm.sign
import algebra.algebra.basic
import tactic.ring
import linear_algebra.alternating
import linear_algebra.pi
/-!
# Determinant of a matrix
This file defines the determinant of a matrix, `matrix.det`, and its essential properties.
## Main definitions
- `matrix.det`: the determinant of a square matrix, as a sum over permutations
- `matrix.det_row_alternating`: the determinant, as an `alternating_map` in the rows of the matrix
## Main results
- `det_mul`: the determinant of `A ⬝ B` is the product of determinants
- `det_zero_of_row_eq`: the determinant is zero if there is a repeated row
- `det_block_diagonal`: the determinant of a block diagonal matrix is a product
of the blocks' determinants
## Implementation notes
It is possible to configure `simp` to compute determinants. See the file
`test/matrix.lean` for some examples.
-/
universes u v w z
open equiv equiv.perm finset function
namespace matrix
open_locale matrix big_operators
variables {m n : Type*} [decidable_eq n] [fintype n] [decidable_eq m] [fintype m]
variables {R : Type v} [comm_ring R]
local notation `ε ` σ:max := ((sign σ : ℤ) : R)
/-- `det` is an `alternating_map` in the rows of the matrix. -/
def det_row_alternating : alternating_map R (n → R) R n :=
((multilinear_map.mk_pi_algebra R n R).comp_linear_map (linear_map.proj)).alternatization
/-- The determinant of a matrix given by the Leibniz formula. -/
abbreviation det (M : matrix n n R) : R :=
det_row_alternating M
lemma det_apply (M : matrix n n R) :
M.det = ∑ σ : perm n, σ.sign • ∏ i, M (σ i) i :=
multilinear_map.alternatization_apply _ M
-- This is what the old definition was. We use it to avoid having to change the old proofs below
lemma det_apply' (M : matrix n n R) :
M.det = ∑ σ : perm n, ε σ * ∏ i, M (σ i) i :=
by simp [det_apply, units.smul_def]
@[simp] lemma det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i :=
begin
rw det_apply',
refine (finset.sum_eq_single 1 _ _).trans _,
{ intros σ h1 h2,
cases not_forall.1 (mt equiv.ext h2) with x h3,
convert mul_zero _,
apply finset.prod_eq_zero,
{ change x ∈ _, simp },
exact if_neg h3 },
{ simp },
{ simp }
end
@[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 :=
(det_row_alternating : alternating_map R (n → R) R n).map_zero
@[simp] lemma det_one : det (1 : matrix n n R) = 1 :=
by rw [← diagonal_one]; simp [-diagonal_one]
lemma det_is_empty [is_empty n] {A : matrix n n R} : det A = 1 :=
by simp [det_apply]
@[simp] lemma coe_det_is_empty [is_empty n] : (det : matrix n n R → R) = function.const _ 1 :=
by { ext, exact det_is_empty, }
lemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 :=
begin
haveI : is_empty n := fintype.card_eq_zero_iff.mp h,
exact det_is_empty,
end
/-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element.
Although `unique` implies `decidable_eq` and `fintype`, the instances might
not be syntactically equal. Thus, we need to fill in the args explicitly. -/
@[simp]
lemma det_unique {n : Type*} [unique n] [decidable_eq n] [fintype n] (A : matrix n n R) :
det A = A default default :=
by simp [det_apply, univ_unique]
lemma det_eq_elem_of_subsingleton [subsingleton n] (A : matrix n n R) (k : n) :
det A = A k k :=
begin
convert det_unique _,
exact unique_of_subsingleton k
end
lemma det_eq_elem_of_card_eq_one {A : matrix n n R} (h : fintype.card n = 1) (k : n) :
det A = A k k :=
begin
haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le,
exact det_eq_elem_of_subsingleton _ _
end
lemma det_mul_aux {M N : matrix n n R} {p : n → n} (H : ¬bijective p) :
∑ σ : perm n, (ε σ) * ∏ x, (M (σ x) (p x) * N (p x) x) = 0 :=
begin
obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j,
{ rw [← finite.injective_iff_bijective, injective] at H,
push_neg at H,
exact H },
exact sum_involution
(λ σ _, σ * swap i j)
(λ σ _,
have ∏ x, M (σ x) (p x) = ∏ x, M ((σ * swap i j) x) (p x),
from fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]),
by simp [this, sign_swap hij, prod_mul_distrib])
(λ σ _ _, (not_congr mul_swap_eq_iff).mpr hij)
(λ _ _, mem_univ _)
(λ σ _, mul_swap_involutive i j σ)
end
@[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N :=
calc det (M ⬝ N) = ∑ p : n → n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :
by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum,
fintype.pi_finset_univ]; rw [finset.sum_comm]
... = ∑ p in (@univ (n → n) _).filter bijective, ∑ σ : perm n,
ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :
eq.symm $ sum_subset (filter_subset _ _)
(λ f _ hbij, det_mul_aux $ by simpa only [true_and, mem_filter, mem_univ] using hbij)
... = ∑ τ : perm n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (τ i) * N (τ i) i) :
sum_bij (λ p h, equiv.of_bijective p (mem_filter.1 h).2) (λ _ _, mem_univ _)
(λ _ _, rfl) (λ _ _ _ _ h, by injection h)
(λ b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩)
... = ∑ σ : perm n, ∑ τ : perm n, (∏ i, N (σ i) i) * ε τ * (∏ j, M (τ j) (σ j)) :
by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]
... = ∑ σ : perm n, ∑ τ : perm n, (((∏ i, N (σ i) i) * (ε σ * ε τ)) * ∏ i, M (τ i) i) :
sum_congr rfl (λ σ _, fintype.sum_equiv (equiv.mul_right σ⁻¹) _ _
(λ τ,
have ∏ j, M (τ j) (σ j) = ∏ j, M ((τ * σ⁻¹) j) j,
by { rw ← (σ⁻¹ : _ ≃ _).prod_comp, simp only [equiv.perm.coe_mul, apply_inv_self] },
have h : ε σ * ε (τ * σ⁻¹) = ε τ :=
calc ε σ * ε (τ * σ⁻¹) = ε ((τ * σ⁻¹) * σ) :
by { rw [mul_comm, sign_mul (τ * σ⁻¹)], simp only [int.cast_mul, units.coe_mul] }
... = ε τ : by simp only [inv_mul_cancel_right],
by { simp_rw [equiv.coe_mul_right, h], simp only [this] }))
... = det M * det N : by simp only [det_apply', finset.mul_sum, mul_comm, mul_left_comm]
/-- The determinant of a matrix, as a monoid homomorphism. -/
def det_monoid_hom : matrix n n R →* R :=
{ to_fun := det,
map_one' := det_one,
map_mul' := det_mul }
@[simp] lemma coe_det_monoid_hom : (det_monoid_hom : matrix n n R → R) = det := rfl
/-- On square matrices, `mul_comm` applies under `det`. -/
lemma det_mul_comm (M N : matrix m m R) : det (M ⬝ N) = det (N ⬝ M) :=
by rw [det_mul, det_mul, mul_comm]
/-- On square matrices, `mul_left_comm` applies under `det`. -/
lemma det_mul_left_comm (M N P : matrix m m R) : det (M ⬝ (N ⬝ P)) = det (N ⬝ (M ⬝ P)) :=
by rw [←matrix.mul_assoc, ←matrix.mul_assoc, det_mul, det_mul_comm M N, ←det_mul]
/-- On square matrices, `mul_right_comm` applies under `det`. -/
lemma det_mul_right_comm (M N P : matrix m m R) :
det (M ⬝ N ⬝ P) = det (M ⬝ P ⬝ N) :=
by rw [matrix.mul_assoc, matrix.mul_assoc, det_mul, det_mul_comm N P, ←det_mul]
lemma det_units_conj (M : (matrix m m R)ˣ) (N : matrix m m R) :
det (↑M ⬝ N ⬝ ↑M⁻¹ : matrix m m R) = det N :=
by rw [det_mul_right_comm, ←mul_eq_mul, ←mul_eq_mul, units.mul_inv, one_mul]
lemma det_units_conj' (M : (matrix m m R)ˣ) (N : matrix m m R) :
det (↑M⁻¹ ⬝ N ⬝ ↑M : matrix m m R) = det N := det_units_conj M⁻¹ N
/-- Transposing a matrix preserves the determinant. -/
@[simp] lemma det_transpose (M : matrix n n R) : Mᵀ.det = M.det :=
begin
rw [det_apply', det_apply'],
refine fintype.sum_bijective _ inv_involutive.bijective _ _ _,
intros σ,
rw sign_inv,
congr' 1,
apply fintype.prod_equiv σ,
intros,
simp
end
/-- Permuting the columns changes the sign of the determinant. -/
lemma det_permute (σ : perm n) (M : matrix n n R) : matrix.det (λ i, M (σ i)) = σ.sign * M.det :=
((det_row_alternating : alternating_map R (n → R) R n).map_perm M σ).trans
(by simp [units.smul_def])
/-- Permuting rows and columns with the same equivalence has no effect. -/
@[simp]
lemma det_submatrix_equiv_self (e : n ≃ m) (A : matrix m m R) :
det (A.submatrix e e) = det A :=
begin
rw [det_apply', det_apply'],
apply fintype.sum_equiv (equiv.perm_congr e),
intro σ,
rw equiv.perm.sign_perm_congr e σ,
congr' 1,
apply fintype.prod_equiv e,
intro i,
rw [equiv.perm_congr_apply, equiv.symm_apply_apply, submatrix_apply],
end
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because
`matrix.reindex_apply` unfolds `reindex` first.
-/
lemma det_reindex_self (e : m ≃ n) (A : matrix m m R) : det (reindex e e A) = det A :=
det_submatrix_equiv_self e.symm A
/-- The determinant of a permutation matrix equals its sign. -/
@[simp] lemma det_permutation (σ : perm n) :
matrix.det (σ.to_pequiv.to_matrix : matrix n n R) = σ.sign :=
by rw [←matrix.mul_one (σ.to_pequiv.to_matrix : matrix n n R), pequiv.to_pequiv_mul_matrix,
det_permute, det_one, mul_one]
lemma det_smul (A : matrix n n R) (c : R) : det (c • A) = c ^ fintype.card n * det A :=
calc det (c • A) = det (matrix.mul (diagonal (λ _, c)) A) : by rw [smul_eq_diagonal_mul]
... = det (diagonal (λ _, c)) * det A : det_mul _ _
... = c ^ fintype.card n * det A : by simp [card_univ]
@[simp] lemma det_smul_of_tower {α} [monoid α] [distrib_mul_action α R] [is_scalar_tower α R R]
[smul_comm_class α R R] (c : α) (A : matrix n n R) :
det (c • A) = c ^ fintype.card n • det A :=
by rw [←smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul]
lemma det_neg (A : matrix n n R) : det (-A) = (-1) ^ fintype.card n * det A :=
by rw [←det_smul, neg_one_smul]
/-- A variant of `matrix.det_neg` with scalar multiplication by `units ℤ` instead of multiplication
by `R`. -/
lemma det_neg_eq_smul (A : matrix n n R) : det (-A) = (-1 : units ℤ) ^ fintype.card n • det A :=
by rw [←det_smul_of_tower, units.neg_smul, one_smul]
/-- Multiplying each row by a fixed `v i` multiplies the determinant by
the product of the `v`s. -/
lemma det_mul_row (v : n → R) (A : matrix n n R) :
det (of $ λ i j, v j * A i j) = (∏ i, v i) * det A :=
calc det (of $ λ i j, v j * A i j)
= det (A ⬝ diagonal v) : congr_arg det $ by { ext, simp [mul_comm] }
... = (∏ i, v i) * det A : by rw [det_mul, det_diagonal, mul_comm]
/-- Multiplying each column by a fixed `v j` multiplies the determinant by
the product of the `v`s. -/
lemma det_mul_column (v : n → R) (A : matrix n n R) :
det (of $ λ i j, v i * A i j) = (∏ i, v i) * det A :=
multilinear_map.map_smul_univ _ v A
@[simp] lemma det_pow (M : matrix m m R) (n : ℕ) : det (M ^ n) = (det M) ^ n :=
(det_monoid_hom : matrix m m R →* R).map_pow M n
section hom_map
variables {S : Type w} [comm_ring S]
lemma _root_.ring_hom.map_det (f : R →+* S) (M : matrix n n R) :
f M.det = matrix.det (f.map_matrix M) :=
by simp [matrix.det_apply', f.map_sum, f.map_prod]
lemma _root_.ring_equiv.map_det (f : R ≃+* S) (M : matrix n n R) :
f M.det = matrix.det (f.map_matrix M) :=
f.to_ring_hom.map_det _
lemma _root_.alg_hom.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]
(f : S →ₐ[R] T) (M : matrix n n S) :
f M.det = matrix.det (f.map_matrix M) :=
f.to_ring_hom.map_det _
lemma _root_.alg_equiv.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]
(f : S ≃ₐ[R] T) (M : matrix n n S) :
f M.det = matrix.det (f.map_matrix M) :=
f.to_alg_hom.map_det _
end hom_map
@[simp] lemma det_conj_transpose [star_ring R] (M : matrix m m R) : det (Mᴴ) = star (det M) :=
((star_ring_end R).map_det _).symm.trans $ congr_arg star M.det_transpose
section det_zero
/-!
### `det_zero` section
Prove that a matrix with a repeated column has determinant equal to zero.
-/
lemma det_eq_zero_of_row_eq_zero {A : matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=
(det_row_alternating : alternating_map R (n → R) R n).map_coord_zero i (funext h)
lemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 :=
by { rw ← det_transpose, exact det_eq_zero_of_row_eq_zero j h, }
variables {M : matrix n n R} {i j : n}
/-- If a matrix has a repeated row, the determinant will be zero. -/
theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 :=
(det_row_alternating : alternating_map R (n → R) R n).map_eq_zero_of_eq M hij i_ne_j
/-- If a matrix has a repeated column, the determinant will be zero. -/
theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 :=
by { rw [← det_transpose, det_zero_of_row_eq i_ne_j], exact funext hij }
end det_zero
lemma det_update_row_add (M : matrix n n R) (j : n) (u v : n → R) :
det (update_row M j $ u + v) = det (update_row M j u) + det (update_row M j v) :=
(det_row_alternating : alternating_map R (n → R) R n).map_add M j u v
lemma det_update_column_add (M : matrix n n R) (j : n) (u v : n → R) :
det (update_column M j $ u + v) = det (update_column M j u) + det (update_column M j v) :=
begin
rw [← det_transpose, ← update_row_transpose, det_update_row_add],
simp [update_row_transpose, det_transpose]
end
lemma det_update_row_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_row M j $ s • u) = s * det (update_row M j u) :=
(det_row_alternating : alternating_map R (n → R) R n).map_smul M j s u
lemma det_update_column_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_column M j $ s • u) = s * det (update_column M j u) :=
begin
rw [← det_transpose, ← update_row_transpose, det_update_row_smul],
simp [update_row_transpose, det_transpose]
end
lemma det_update_row_smul' (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_row (s • M) j u) = s ^ (fintype.card n - 1) * det (update_row M j u) :=
multilinear_map.map_update_smul _ M j s u
lemma det_update_column_smul' (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_column (s • M) j u) = s ^ (fintype.card n - 1) * det (update_column M j u) :=
begin
rw [← det_transpose, ← update_row_transpose, transpose_smul, det_update_row_smul'],
simp [update_row_transpose, det_transpose]
end
section det_eq
/-! ### `det_eq` section
Lemmas showing the determinant is invariant under a variety of operations.
-/
lemma det_eq_of_eq_mul_det_one {A B : matrix n n R}
(C : matrix n n R) (hC : det C = 1) (hA : A = B ⬝ C) : det A = det B :=
calc det A = det (B ⬝ C) : congr_arg _ hA
... = det B * det C : det_mul _ _
... = det B : by rw [hC, mul_one]
lemma det_eq_of_eq_det_one_mul {A B : matrix n n R}
(C : matrix n n R) (hC : det C = 1) (hA : A = C ⬝ B) : det A = det B :=
calc det A = det (C ⬝ B) : congr_arg _ hA
... = det C * det B : det_mul _ _
... = det B : by rw [hC, one_mul]
lemma det_update_row_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :
det (update_row A i (A i + A j)) = det A :=
by simp [det_update_row_add,
det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)]
lemma det_update_column_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :
det (update_column A i (λ k, A k i + A k j)) = det A :=
by { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],
exact det_update_row_add_self Aᵀ hij }
lemma det_update_row_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :
det (update_row A i (A i + c • A j)) = det A :=
by simp [det_update_row_add, det_update_row_smul,
det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)]
lemma det_update_column_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :
det (update_column A i (λ k, A k i + c • A k j)) = det A :=
by { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],
exact det_update_row_add_smul_self Aᵀ hij c }
lemma det_eq_of_forall_row_eq_smul_add_const_aux
{A B : matrix n n R} {s : finset n} : ∀ (c : n → R) (hs : ∀ i, i ∉ s → c i = 0)
(k : n) (hk : k ∉ s) (A_eq : ∀ i j, A i j = B i j + c i * B k j),
det A = det B :=
begin
revert B,
refine s.induction_on _ _,
{ intros A c hs k hk A_eq,
have : ∀ i, c i = 0,
{ intros i,
specialize hs i,
contrapose! hs,
simp [hs] },
congr,
ext i j,
rw [A_eq, this, zero_mul, add_zero], },
{ intros i s hi ih B c hs k hk A_eq,
have hAi : A i = B i + c i • B k := funext (A_eq i),
rw [@ih (update_row B i (A i)) (function.update c i 0), hAi,
det_update_row_add_smul_self],
{ exact mt (λ h, show k ∈ insert i s, from h ▸ finset.mem_insert_self _ _) hk },
{ intros i' hi',
rw function.update_apply,
split_ifs with hi'i, { refl },
{ exact hs i' (λ h, hi' ((finset.mem_insert.mp h).resolve_left hi'i)) } },
{ exact λ h, hk (finset.mem_insert_of_mem h) },
{ intros i' j',
rw [update_row_apply, function.update_apply],
split_ifs with hi'i,
{ simp [hi'i] },
rw [A_eq, update_row_ne (λ (h : k = i), hk $ h ▸ finset.mem_insert_self k s)] } }
end
/-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/
lemma det_eq_of_forall_row_eq_smul_add_const
{A B : matrix n n R} (c : n → R) (k : n) (hk : c k = 0)
(A_eq : ∀ i j, A i j = B i j + c i * B k j) :
det A = det B :=
det_eq_of_forall_row_eq_smul_add_const_aux c
(λ i, not_imp_comm.mp $ λ hi, finset.mem_erase.mpr
⟨mt (λ (h : i = k), show c i = 0, from h.symm ▸ hk) hi, finset.mem_univ i⟩)
k (finset.not_mem_erase k finset.univ) A_eq
lemma det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : fin (n + 1)) :
∀ (c : fin n → R) (hc : ∀ (i : fin n), k < i.succ → c i = 0)
{M N : matrix (fin n.succ) (fin n.succ) R}
(h0 : ∀ j, M 0 j = N 0 j)
(hsucc : ∀ (i : fin n) j, M i.succ j = N i.succ j + c i * M i.cast_succ j),
det M = det N :=
begin
refine fin.induction _ (λ k ih, _) k;
intros c hc M N h0 hsucc,
{ congr,
ext i j,
refine fin.cases (h0 j) (λ i, _) i,
rw [hsucc, hc i (fin.succ_pos _), zero_mul, add_zero] },
set M' := update_row M k.succ (N k.succ) with hM',
have hM : M = update_row M' k.succ (M' k.succ + c k • M k.cast_succ),
{ ext i j,
by_cases hi : i = k.succ,
{ simp [hi, hM', hsucc, update_row_self] },
rw [update_row_ne hi, hM', update_row_ne hi] },
have k_ne_succ : k.cast_succ ≠ k.succ := (fin.cast_succ_lt_succ k).ne,
have M_k : M k.cast_succ = M' k.cast_succ := (update_row_ne k_ne_succ).symm,
rw [hM, M_k, det_update_row_add_smul_self M' k_ne_succ.symm, ih (function.update c k 0)],
{ intros i hi,
rw [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff] at hi,
rw function.update_apply,
split_ifs with hik, { refl },
exact hc _ (fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (ne.symm hik))) },
{ rwa [hM', update_row_ne (fin.succ_ne_zero _).symm] },
intros i j,
rw function.update_apply,
split_ifs with hik,
{ rw [zero_mul, add_zero, hM', hik, update_row_self] },
rw [hM', update_row_ne ((fin.succ_injective _).ne hik), hsucc],
by_cases hik2 : k < i,
{ simp [hc i (fin.succ_lt_succ_iff.mpr hik2)] },
rw update_row_ne,
apply ne_of_lt,
rwa [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff, ← not_lt]
end
/-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/
lemma det_eq_of_forall_row_eq_smul_add_pred {n : ℕ}
{A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)
(A_zero : ∀ j, A 0 j = B 0 j)
(A_succ : ∀ (i : fin n) j, A i.succ j = B i.succ j + c i * A i.cast_succ j) :
det A = det B :=
det_eq_of_forall_row_eq_smul_add_pred_aux (fin.last _) c
(λ i hi, absurd hi (not_lt_of_ge (fin.le_last _)))
A_zero A_succ
/-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/
lemma det_eq_of_forall_col_eq_smul_add_pred {n : ℕ}
{A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)
(A_zero : ∀ i, A i 0 = B i 0)
(A_succ : ∀ i (j : fin n), A i j.succ = B i j.succ + c j * A i j.cast_succ) :
det A = det B :=
by { rw [← det_transpose A, ← det_transpose B],
exact det_eq_of_forall_row_eq_smul_add_pred c A_zero (λ i j, A_succ j i) }
end det_eq
@[simp] lemma det_block_diagonal {o : Type*} [fintype o] [decidable_eq o] (M : o → matrix n n R) :
(block_diagonal M).det = ∏ k, (M k).det :=
begin
-- Rewrite the determinants as a sum over permutations.
simp_rw [det_apply'],
-- The right hand side is a product of sums, rewrite it as a sum of products.
rw finset.prod_sum,
simp_rw [finset.mem_univ, finset.prod_attach_univ, finset.univ_pi_univ],
-- We claim that the only permutations contributing to the sum are those that
-- preserve their second component.
let preserving_snd : finset (equiv.perm (n × o)) :=
finset.univ.filter (λ σ, ∀ x, (σ x).snd = x.snd),
have mem_preserving_snd : ∀ {σ : equiv.perm (n × o)},
σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd :=
λ σ, finset.mem_filter.trans ⟨λ h, h.2, λ h, ⟨finset.mem_univ _, h⟩⟩,
rw ← finset.sum_subset (finset.subset_univ preserving_snd) _,
-- And that these are in bijection with `o → equiv.perm m`.
rw (finset.sum_bij (λ (σ : ∀ (k : o), k ∈ finset.univ → equiv.perm n) _,
prod_congr_left (λ k, σ k (finset.mem_univ k))) _ _ _ _).symm,
{ intros σ _,
rw mem_preserving_snd,
rintros ⟨k, x⟩,
simp only [prod_congr_left_apply] },
{ intros σ _,
rw [finset.prod_mul_distrib, ←finset.univ_product_univ, finset.prod_product_right],
simp only [sign_prod_congr_left, units.coe_prod, int.cast_prod, block_diagonal_apply_eq,
prod_congr_left_apply] },
{ intros σ σ' _ _ eq,
ext x hx k,
simp only at eq,
have : ∀ k x, prod_congr_left (λ k, σ k (finset.mem_univ _)) (k, x) =
prod_congr_left (λ k, σ' k (finset.mem_univ _)) (k, x) :=
λ k x, by rw eq,
simp only [prod_congr_left_apply, prod.mk.inj_iff] at this,
exact (this k x).1 },
{ intros σ hσ,
rw mem_preserving_snd at hσ,
have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd,
{ intro x, conv_rhs { rw [← perm.apply_inv_self σ x, hσ] } },
have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k),
{ intros k x,
ext,
{ simp only},
{ simp only [hσ] } },
have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k),
{ intros k x,
conv_lhs { rw ← perm.apply_inv_self σ (x, k) },
ext,
{ simp only [apply_inv_self] },
{ simp only [hσ'] } },
refine ⟨λ k _, ⟨λ x, (σ (x, k)).fst, λ x, (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩,
{ intro x,
simp only [mk_apply_eq, inv_apply_self] },
{ intro x,
simp only [mk_inv_apply_eq, apply_inv_self] },
{ apply finset.mem_univ },
{ ext ⟨k, x⟩,
{ simp only [coe_fn_mk, prod_congr_left_apply] },
{ simp only [prod_congr_left_apply, hσ] } } },
{ intros σ _ hσ,
rw mem_preserving_snd at hσ,
obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ,
rw [finset.prod_eq_zero (finset.mem_univ (k, x)), mul_zero],
rw [← @prod.mk.eta _ _ (σ (k, x)), block_diagonal_apply_ne],
exact hkx }
end
/-- The determinant of a 2×2 block matrix with the lower-left block equal to zero is the product of
the determinants of the diagonal blocks. For the generalization to any number of blocks, see
`matrix.det_of_upper_triangular`. -/
@[simp] lemma det_from_blocks_zero₂₁
(A : matrix m m R) (B : matrix m n R) (D : matrix n n R) :
(matrix.from_blocks A B 0 D).det = A.det * D.det :=
begin
classical,
simp_rw det_apply',
convert
(sum_subset (subset_univ ((sum_congr_hom m n).range : set (perm (m ⊕ n))).to_finset) _).symm,
rw sum_mul_sum,
simp_rw univ_product_univ,
rw (sum_bij (λ (σ : perm m × perm n) _, equiv.sum_congr σ.fst σ.snd) _ _ _ _).symm,
{ intros σ₁₂ h,
simp only [],
erw [set.mem_to_finset, monoid_hom.mem_range],
use σ₁₂,
simp only [sum_congr_hom_apply] },
{ simp only [forall_prop_of_true, prod.forall, mem_univ],
intros σ₁ σ₂,
rw fintype.prod_sum_type,
simp_rw [equiv.sum_congr_apply, sum.map_inr, sum.map_inl, from_blocks_apply₁₁,
from_blocks_apply₂₂],
rw mul_mul_mul_comm,
congr,
rw [sign_sum_congr, units.coe_mul, int.cast_mul] },
{ intros σ₁ σ₂ h₁ h₂,
dsimp only [],
intro h,
have h2 : ∀ x, perm.sum_congr σ₁.fst σ₁.snd x = perm.sum_congr σ₂.fst σ₂.snd x,
{ intro x, exact congr_fun (congr_arg to_fun h) x },
simp only [sum.map_inr, sum.map_inl, perm.sum_congr_apply, sum.forall] at h2,
ext,
{ exact h2.left x },
{ exact h2.right x }},
{ intros σ hσ,
erw [set.mem_to_finset, monoid_hom.mem_range] at hσ,
obtain ⟨σ₁₂, hσ₁₂⟩ := hσ,
use σ₁₂,
rw ←hσ₁₂,
simp },
{ intros σ hσ hσn,
have h1 : ¬ (∀ x, ∃ y, sum.inl y = σ (sum.inl x)),
{ by_contradiction,
rw set.mem_to_finset at hσn,
apply absurd (mem_sum_congr_hom_range_of_perm_maps_to_inl _) hσn,
rintros x ⟨a, ha⟩,
rw [←ha], exact h a },
obtain ⟨a, ha⟩ := not_forall.mp h1,
cases hx : σ (sum.inl a) with a2 b,
{ have hn := (not_exists.mp ha) a2,
exact absurd hx.symm hn },
{ rw [finset.prod_eq_zero (finset.mem_univ (sum.inl a)), mul_zero],
rw [hx, from_blocks_apply₂₁], refl }}
end
/-- The determinant of a 2×2 block matrix with the upper-right block equal to zero is the product of
the determinants of the diagonal blocks. For the generalization to any number of blocks, see
`matrix.det_of_lower_triangular`. -/
@[simp] lemma det_from_blocks_zero₁₂
(A : matrix m m R) (C : matrix n m R) (D : matrix n n R) :
(matrix.from_blocks A 0 C D).det = A.det * D.det :=
by rw [←det_transpose, from_blocks_transpose, transpose_zero, det_from_blocks_zero₂₁,
det_transpose, det_transpose]
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column 0. -/
lemma det_succ_column_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :
det A = ∑ i : fin n.succ, (-1) ^ (i : ℕ) * A i 0 *
det (A.submatrix i.succ_above fin.succ) :=
begin
rw [matrix.det_apply, finset.univ_perm_fin_succ, ← finset.univ_product_univ],
simp only [finset.sum_map, equiv.to_embedding_apply, finset.sum_product, matrix.submatrix],
refine finset.sum_congr rfl (λ i _, fin.cases _ (λ i, _) i),
{ simp only [fin.prod_univ_succ, matrix.det_apply, finset.mul_sum,
equiv.perm.decompose_fin_symm_apply_zero, fin.coe_zero, one_mul,
equiv.perm.decompose_fin.symm_sign, equiv.swap_self, if_true, id.def, eq_self_iff_true,
equiv.perm.decompose_fin_symm_apply_succ, fin.succ_above_zero, equiv.coe_refl, pow_zero,
mul_smul_comm, of_apply] },
-- `univ_perm_fin_succ` gives a different embedding of `perm (fin n)` into
-- `perm (fin n.succ)` than the determinant of the submatrix we want,
-- permute `A` so that we get the correct one.
have : (-1 : R) ^ (i : ℕ) = i.cycle_range.sign,
{ simp [fin.sign_cycle_range] },
rw [fin.coe_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm ↑(equiv.perm.sign _),
← det_permute, matrix.det_apply, finset.mul_sum, finset.mul_sum],
-- now we just need to move the corresponding parts to the same place
refine finset.sum_congr rfl (λ σ _, _),
rw [equiv.perm.decompose_fin.symm_sign, if_neg (fin.succ_ne_zero i)],
calc ((-1) * σ.sign : ℤ) • ∏ i', A (equiv.perm.decompose_fin.symm (fin.succ i, σ) i') i'
= ((-1) * σ.sign : ℤ) • (A (fin.succ i) 0 *
∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :
by simp only [fin.prod_univ_succ, fin.succ_above_cycle_range,
equiv.perm.decompose_fin_symm_apply_zero, equiv.perm.decompose_fin_symm_apply_succ]
... = (-1) * (A (fin.succ i) 0 * (σ.sign : ℤ) •
∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :
by simp only [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj,
neg_smul, fin.succ_above_cycle_range],
end
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row 0. -/
lemma det_succ_row_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :
det A = ∑ j : fin n.succ, (-1) ^ (j : ℕ) * A 0 j *
det (A.submatrix fin.succ j.succ_above) :=
by { rw [← det_transpose A, det_succ_column_zero],
refine finset.sum_congr rfl (λ i _, _),
rw [← det_transpose],
simp only [transpose_apply, transpose_submatrix, transpose_transpose] }
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row `i`. -/
lemma det_succ_row {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (i : fin n.succ) :
det A = ∑ j : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *
det (A.submatrix i.succ_above j.succ_above) :=
begin
simp_rw [pow_add, mul_assoc, ← mul_sum],
have : det A = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A,
{ calc det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A :
by simp
... = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A :
by simp [-int.units_mul_self] },
rw [this, mul_assoc],
congr,
rw [← det_permute, det_succ_row_zero],
refine finset.sum_congr rfl (λ j _, _),
rw [mul_assoc, matrix.submatrix, matrix.submatrix],
congr,
{ rw [equiv.perm.inv_def, fin.cycle_range_symm_zero] },
{ ext i' j',
rw [equiv.perm.inv_def, fin.cycle_range_symm_succ] },
end
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column `j`. -/
lemma det_succ_column {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (j : fin n.succ) :
det A = ∑ i : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *
det (A.submatrix i.succ_above j.succ_above) :=
by { rw [← det_transpose, det_succ_row _ j],
refine finset.sum_congr rfl (λ i _, _),
rw [add_comm, ← det_transpose, transpose_apply, transpose_submatrix, transpose_transpose] }
/-- Determinant of 0x0 matrix -/
@[simp] lemma det_fin_zero {A : matrix (fin 0) (fin 0) R} : det A = 1 :=
det_is_empty
/-- Determinant of 1x1 matrix -/
lemma det_fin_one (A : matrix (fin 1) (fin 1) R) : det A = A 0 0 := det_unique A
lemma det_fin_one_of (a : R) : det !![a] = a := det_fin_one _
/-- Determinant of 2x2 matrix -/
lemma det_fin_two (A : matrix (fin 2) (fin 2) R) :
det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 :=
begin
simp [matrix.det_succ_row_zero, fin.sum_univ_succ],
ring
end
@[simp] lemma det_fin_two_of (a b c d : R) :
matrix.det !![a, b; c, d] = a * d - b * c :=
det_fin_two _
/-- Determinant of 3x3 matrix -/
lemma det_fin_three (A : matrix (fin 3) (fin 3) R) :
det A = A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1 - A 0 1 * A 1 0 * A 2 2
+ A 0 1 * A 1 2 * A 2 0 + A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 :=
begin
simp [matrix.det_succ_row_zero, fin.sum_univ_succ],
ring
end
end matrix
|
cd416349c075fdd74d58187d634d457b03f0b28e | ac2987d8c7832fb4a87edb6bee26141facbb6fa0 | /Mathlib/Tactic/Split.lean | 5df7dc319d7cf4a9f25f02155ca880367a8633dc | [
"Apache-2.0"
] | permissive | AurelienSaue/mathlib4 | 52204b9bd9d207c922fe0cf3397166728bb6c2e2 | 84271fe0875bafdaa88ac41f1b5a7c18151bd0d5 | refs/heads/master | 1,689,156,096,545 | 1,629,378,840,000 | 1,629,378,840,000 | 389,648,603 | 0 | 0 | Apache-2.0 | 1,627,307,284,000 | 1,627,307,284,000 | null | UTF-8 | Lean | false | false | 996 | lean | /-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Lean.Meta.Tactic.Apply
import Lean.Elab.Tactic.Basic
import Lean.Elab.SyntheticMVars
def Lean.Meta.split (mvarId : MVarId) : MetaM (List MVarId) := do
withMVarContext mvarId do
checkNotAssigned mvarId `split
let target ← getMVarType' mvarId
matchConstInduct target.getAppFn
(fun _ => throwTacticEx `split mvarId "target is not an inductive datatype")
fun ival us => do
match ival.ctors with
| [ctor] => apply mvarId (mkConst ctor us)
| _ => throwError "split failed, goal must be an inductive type with only one constructor {indentExpr target}"
namespace Lean.Elab
namespace Tactic
open Meta
elab "split" : tactic => withMainContext do
let mvarIds' ← Meta.split (← getMainGoal)
Term.synthesizeSyntheticMVarsNoPostponing
replaceMainGoal mvarIds'
end Tactic
end Lean.Elab
|
9a0c21503869ddb661fe5a8945b9bd232f8e471f | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/homology/complex_shape.lean | bffbd9a898316e5c05efdee31045a93d290d3278 | [
"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 | 6,834 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison
-/
import algebra.group.defs
import logic.relation
/-!
# Shapes of homological complexes
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/635
> Any changes to this file require a corresponding PR to mathlib4.
We define a structure `complex_shape ι` for describing the shapes of homological complexes
indexed by a type `ι`.
This is intended to capture chain complexes and cochain complexes, indexed by either `ℕ` or `ℤ`,
as well as more exotic examples.
Rather than insisting that the indexing type has a `succ` function
specifying where differentials should go,
inside `c : complex_shape` we have `c.rel : ι → ι → Prop`,
and when we define `homological_complex`
we only allow nonzero differentials `d i j` from `i` to `j` if `c.rel i j`.
Further, we require that `{ j // c.rel i j }` and `{ i // c.rel i j }` are subsingletons.
This means that the shape consists of some union of lines, rays, intervals, and circles.
Convenience functions `c.next` and `c.prev` provide these related elements
when they exist, and return their input otherwise.
This design aims to avoid certain problems arising from dependent type theory.
In particular we never have to ensure morphisms `d i : X i ⟶ X (succ i)` compose as
expected (which would often require rewriting by equations in the indexing type).
Instead such identities become separate proof obligations when verifying that a
complex we've constructed is of the desired shape.
If `α` is an `add_right_cancel_semigroup`, then we define `up α : complex_shape α`,
the shape appropriate for cohomology,so `d : X i ⟶ X j` is nonzero only when `j = i + 1`,
as well as `down α : complex_shape α`, appropriate for homology,
so `d : X i ⟶ X j` is nonzero only when `i = j + 1`.
(Later we'll introduce `cochain_complex` and `chain_complex` as abbreviations for
`homological_complex` with one of these shapes baked in.)
-/
open_locale classical
noncomputable theory
/--
A `c : complex_shape ι` describes the shape of a chain complex,
with chain groups indexed by `ι`.
Typically `ι` will be `ℕ`, `ℤ`, or `fin n`.
There is a relation `rel : ι → ι → Prop`,
and we will only allow a non-zero differential from `i` to `j` when `rel i j`.
There are axioms which imply `{ j // c.rel i j }` and `{ i // c.rel i j }` are subsingletons.
This means that the shape consists of some union of lines, rays, intervals, and circles.
Below we define `c.next` and `c.prev` which provide these related elements.
-/
@[ext, nolint has_nonempty_instance]
structure complex_shape (ι : Type*) :=
(rel : ι → ι → Prop)
(next_eq : ∀ {i j j'}, rel i j → rel i j' → j = j')
(prev_eq : ∀ {i i' j}, rel i j → rel i' j → i = i')
namespace complex_shape
variables {ι : Type*}
/--
The complex shape where only differentials from each `X.i` to itself are allowed.
This is mostly only useful so we can describe the relation of "related in `k` steps" below.
-/
@[simps]
def refl (ι : Type*) : complex_shape ι :=
{ rel := λ i j, i = j,
next_eq := λ i j j' w w', w.symm.trans w',
prev_eq := λ i i' j w w', w.trans w'.symm, }
/--
The reverse of a `complex_shape`.
-/
@[simps]
def symm (c : complex_shape ι) : complex_shape ι :=
{ rel := λ i j, c.rel j i,
next_eq := λ i j j' w w', c.prev_eq w w',
prev_eq := λ i i' j w w', c.next_eq w w', }
@[simp]
lemma symm_symm (c : complex_shape ι) : c.symm.symm = c :=
by { ext, simp, }
/--
The "composition" of two `complex_shape`s.
We need this to define "related in k steps" later.
-/
@[simp]
def trans (c₁ c₂ : complex_shape ι) : complex_shape ι :=
{ rel := relation.comp c₁.rel c₂.rel,
next_eq := λ i j j' w w',
begin
obtain ⟨k, w₁, w₂⟩ := w,
obtain ⟨k', w₁', w₂'⟩ := w',
rw c₁.next_eq w₁ w₁' at w₂,
exact c₂.next_eq w₂ w₂',
end,
prev_eq := λ i i' j w w',
begin
obtain ⟨k, w₁, w₂⟩ := w,
obtain ⟨k', w₁', w₂'⟩ := w',
rw c₂.prev_eq w₂ w₂' at w₁,
exact c₁.prev_eq w₁ w₁',
end }
instance subsingleton_next (c : complex_shape ι) (i : ι) :
subsingleton { j // c.rel i j } :=
begin
fsplit,
rintros ⟨j, rij⟩ ⟨k, rik⟩,
congr,
exact c.next_eq rij rik,
end
instance subsingleton_prev (c : complex_shape ι) (j : ι) :
subsingleton { i // c.rel i j } :=
begin
fsplit,
rintros ⟨i, rik⟩ ⟨j, rjk⟩,
congr,
exact c.prev_eq rik rjk,
end
/--
An arbitary choice of index `j` such that `rel i j`, if such exists.
Returns `i` otherwise.
-/
def next (c : complex_shape ι) (i : ι) : ι :=
if h : ∃ j, c.rel i j then h.some else i
/--
An arbitary choice of index `i` such that `rel i j`, if such exists.
Returns `j` otherwise.
-/
def prev (c : complex_shape ι) (j : ι) : ι :=
if h : ∃ i, c.rel i j then h.some else j
lemma next_eq' (c : complex_shape ι) {i j : ι} (h : c.rel i j) : c.next i = j :=
by { apply c.next_eq _ h, dsimp only [next], rw dif_pos, exact Exists.some_spec ⟨j, h⟩, }
lemma prev_eq' (c : complex_shape ι) {i j : ι} (h : c.rel i j) : c.prev j = i :=
by { apply c.prev_eq _ h, dsimp only [prev], rw dif_pos, exact Exists.some_spec ⟨i, h⟩, }
/--
The `complex_shape` allowing differentials from `X i` to `X (i+a)`.
(For example when `a = 1`, a cohomology theory indexed by `ℕ` or `ℤ`)
-/
@[simps]
def up' {α : Type*} [add_right_cancel_semigroup α] (a : α) : complex_shape α :=
{ rel := λ i j , i + a = j,
next_eq := λ i j k hi hj, hi.symm.trans hj,
prev_eq := λ i j k hi hj, add_right_cancel (hi.trans hj.symm), }
/--
The `complex_shape` allowing differentials from `X (j+a)` to `X j`.
(For example when `a = 1`, a homology theory indexed by `ℕ` or `ℤ`)
-/
@[simps]
def down' {α : Type*} [add_right_cancel_semigroup α] (a : α) : complex_shape α :=
{ rel := λ i j , j + a = i,
next_eq := λ i j k hi hj, add_right_cancel (hi.trans (hj.symm)),
prev_eq := λ i j k hi hj, hi.symm.trans hj, }
lemma down'_mk {α : Type*} [add_right_cancel_semigroup α] (a : α)
(i j : α) (h : j + a = i) : (down' a).rel i j := h
/--
The `complex_shape` appropriate for cohomology, so `d : X i ⟶ X j` only when `j = i + 1`.
-/
@[simps]
def up (α : Type*) [add_right_cancel_semigroup α] [has_one α] : complex_shape α :=
up' 1
/--
The `complex_shape` appropriate for homology, so `d : X i ⟶ X j` only when `i = j + 1`.
-/
@[simps]
def down (α : Type*) [add_right_cancel_semigroup α] [has_one α] : complex_shape α :=
down' 1
lemma down_mk {α : Type*} [add_right_cancel_semigroup α] [has_one α]
(i j : α) (h : j + 1 = i) : (down α).rel i j :=
down'_mk (1 : α) i j h
end complex_shape
|
1f01b41fbb3524079305e2896f5ea8a936672c0a | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/connected.lean | 02c407cd882826da9979a17ecdc4063c61a19aaa | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 71,287 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import data.int.succ_pred
import data.nat.succ_pred
import order.partial_sups
import order.succ_pred.relation
import topology.subset_properties
import tactic.congrm
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions, we also have a class stating that the whole space
satisfies that property:
`connected_space`, `totally_disconnected_space`, `totally_separated_space`.
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `is_preconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set function topological_space relation
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [topological_space α]
{s t u v : set α}
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
theorem is_preconnected_singleton {x} : is_preconnected ({x} : set α) :=
is_connected_singleton.is_preconnected
theorem set.subsingleton.is_preconnected {s : set α} (hs : s.subsingleton) :
is_preconnected s :=
hs.induction_on is_preconnected_empty (λ x, is_preconnected_singleton)
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rcases eq_empty_or_nonempty s with (rfl|⟨x, hx⟩),
exacts [is_preconnected_empty, is_preconnected_of_forall x $ λ y, H x hx y],
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected_Union {ι : Sort*} {s : ι → set α} (h₁ : (⋂ i, s i).nonempty)
(h₂ : ∀ i, is_preconnected (s i)) :
is_preconnected (⋃ i, s i) :=
exists.elim h₁ $ λ f hf, is_preconnected_sUnion f _ hf (forall_range_iff.2 h₂)
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_preconnected.union' {s t : set α} (H : (s ∩ t).nonempty)
(hs : is_preconnected s) (ht : is_preconnected t) : is_preconnected (s ∪ t) :=
by { rcases H with ⟨x, hxs, hxt⟩, exact hs.union x hxs hxt ht }
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
/-- The directed sUnion of a set S of preconnected subsets is preconnected. -/
theorem is_preconnected.sUnion_directed {S : set (set α)}
(K : directed_on (⊆) S)
(H : ∀ s ∈ S, is_preconnected s) : is_preconnected (⋃₀ S) :=
begin
rintros u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩,
obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS,
have Hnuv : (r ∩ (u ∩ v)).nonempty,
from H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv)
⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩,
have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v),
from inter_subset_inter_left _ (subset_sUnion_of_mem hrS),
exact Hnuv.mono Kruv
end
/-- The bUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem is_preconnected.bUnion_of_refl_trans_gen {ι : Type*} {t : set ι} {s : ι → set α}
(H : ∀ i ∈ t, is_preconnected (s i))
(K : ∀ i j ∈ t, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t) i j) :
is_preconnected (⋃ n ∈ t, s n) :=
begin
let R := λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t,
have P : ∀ (i j ∈ t), refl_trans_gen R i j →
∃ (p ⊆ t), i ∈ p ∧ j ∈ p ∧ is_preconnected (⋃ j ∈ p, s j),
{ intros i hi j hj h,
induction h,
case refl
{ refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, _⟩,
rw [bUnion_singleton],
exact H i hi },
case tail : j k hij hjk ih
{ obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2,
refine ⟨insert k p, insert_subset.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, _⟩,
rw [bUnion_insert],
refine (H k hj).union' _ hp,
refine hjk.1.mono _,
rw [inter_comm],
refine inter_subset_inter subset.rfl (subset_bUnion_of_mem hjp) } },
refine is_preconnected_of_forall_pair _,
intros x hx y hy,
obtain ⟨i: ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_Union₂.1 hx,
obtain ⟨j: ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_Union₂.1 hy,
obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj),
exact ⟨⋃ j ∈ p, s j, bUnion_subset_bUnion_left hpt, mem_bUnion hip hxi, mem_bUnion hjp hyj, hp⟩
end
/-- The bUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem is_connected.bUnion_of_refl_trans_gen {ι : Type*} {t : set ι} {s : ι → set α}
(ht : t.nonempty)
(H : ∀ i ∈ t, is_connected (s i))
(K : ∀ i j ∈ t, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t) i j) :
is_connected (⋃ n ∈ t, s n) :=
⟨nonempty_bUnion.2 $ ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩,
is_preconnected.bUnion_of_refl_trans_gen (λ i hi, (H i hi).is_preconnected) K⟩
/-- Preconnectedness of the Union of a family of preconnected sets
indexed by the vertices of a preconnected graph,
where two vertices are joined when the corresponding sets intersect. -/
theorem is_preconnected.Union_of_refl_trans_gen {ι : Type*} {s : ι → set α}
(H : ∀ i, is_preconnected (s i))
(K : ∀ i j, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty) i j) :
is_preconnected (⋃ n, s n) :=
by { rw [← bUnion_univ], exact is_preconnected.bUnion_of_refl_trans_gen (λ i _, H i)
(λ i _ j _, by simpa [mem_univ] using K i j) }
theorem is_connected.Union_of_refl_trans_gen {ι : Type*} [nonempty ι] {s : ι → set α}
(H : ∀ i, is_connected (s i))
(K : ∀ i j, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty) i j) :
is_connected (⋃ n, s n) :=
⟨nonempty_Union.2 $ nonempty.elim ‹_› $ λ i : ι, ⟨i, (H _).nonempty⟩,
is_preconnected.Union_of_refl_trans_gen (λ i, (H i).is_preconnected) K⟩
section succ_order
open order
variables [linear_order β] [succ_order β] [is_succ_archimedean β]
/-- The Union of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`)
such that any two neighboring sets meet is preconnected. -/
theorem is_preconnected.Union_of_chain {s : β → set α}
(H : ∀ n, is_preconnected (s n))
(K : ∀ n, (s n ∩ s (succ n)).nonempty) :
is_preconnected (⋃ n, s n) :=
is_preconnected.Union_of_refl_trans_gen H $
λ i j, refl_trans_gen_of_succ _ (λ i _, K i) $ λ i _, by { rw inter_comm, exact K i }
/-- The Union of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`)
such that any two neighboring sets meet is connected. -/
theorem is_connected.Union_of_chain [nonempty β] {s : β → set α}
(H : ∀ n, is_connected (s n))
(K : ∀ n, (s n ∩ s (succ n)).nonempty) :
is_connected (⋃ n, s n) :=
is_connected.Union_of_refl_trans_gen H $
λ i j, refl_trans_gen_of_succ _ (λ i _, K i) $ λ i _, by { rw inter_comm, exact K i }
/-- The Union of preconnected sets indexed by a subset of a type with an archimedean successor
(like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/
theorem is_preconnected.bUnion_of_chain
{s : β → set α} {t : set β} (ht : ord_connected t)
(H : ∀ n ∈ t, is_preconnected (s n))
(K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).nonempty) :
is_preconnected (⋃ n ∈ t, s n) :=
begin
have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t :=
λ i j k hi hj hk, ht.out hi hj (Ico_subset_Icc_self hk),
have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := λ i j k hi hj hk,
ht.out hi hj ⟨hk.1.trans $ le_succ k, succ_le_of_lt hk.2⟩,
have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).nonempty :=
λ i j k hi hj hk, K _ (h1 hi hj hk) (h2 hi hj hk),
refine is_preconnected.bUnion_of_refl_trans_gen H (λ i hi j hj, _),
exact refl_trans_gen_of_succ _ (λ k hk, ⟨h3 hi hj hk, h1 hi hj hk⟩)
(λ k hk, ⟨by { rw [inter_comm], exact h3 hj hi hk }, h2 hj hi hk⟩),
end
/-- The Union of connected sets indexed by a subset of a type with an archimedean successor
(like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/
theorem is_connected.bUnion_of_chain
{s : β → set α} {t : set β} (hnt : t.nonempty) (ht : ord_connected t)
(H : ∀ n ∈ t, is_connected (s n))
(K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).nonempty) :
is_connected (⋃ n ∈ t, s n) :=
⟨nonempty_bUnion.2 $ ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩,
is_preconnected.bUnion_of_chain ht (λ i hi, (H i hi).is_preconnected) K⟩
end succ_order
/-- Theorem of bark and tree :
if a set is within a (pre)connected set and its closure,
then it is (pre)connected as well. -/
theorem is_preconnected.subset_closure {s : set α} {t : set α}
(H : is_preconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) :
is_preconnected t :=
λ u v hu hv htuv ⟨y, hyt, hyu⟩ ⟨z, hzt, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu,
⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv,
⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, Kst hrs, hruv⟩
theorem is_connected.subset_closure {s : set α} {t : set α}
(H : is_connected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s): is_connected t :=
let hsne := H.left,
ht := Kst,
htne := nonempty.mono ht hsne in
⟨nonempty.mono Kst H.left, is_preconnected.subset_closure H.right Kst Ktcs ⟩
/-- The closure of a (pre)connected set is (pre)connected as well. -/
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
is_preconnected.subset_closure H subset_closure $ subset.refl $ closure s
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
is_connected.subset_closure H subset_closure $ subset.refl $ closure s
/-- The image of a (pre)connected set is (pre)connected as well. -/
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
rw [←not_disjoint_iff_nonempty_inter, ←subset_compl_iff_disjoint_right, compl_inter],
intros h',
have xt' : x ∉ t', from (h' xs).resolve_left (absurd xt),
have yt : y ∉ t, from (h' ys).resolve_right (absurd yt'),
have := h _ _ ht.is_open_compl ht'.is_open_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩,
rw ←compl_union at this,
exact this.ne_empty htt'.disjoint_compl_right.inter_eq,
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rw [←not_disjoint_iff_nonempty_inter, ←subset_compl_iff_disjoint_right, compl_inter],
intros h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := h _ _ hu.is_closed_compl hv.is_closed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩,
rw ←compl_union at this,
exact this.ne_empty huv.disjoint_compl_right.inter_eq,
end⟩
lemma inducing.is_preconnected_image [topological_space β] {s : set α} {f : α → β}
(hf : inducing f) : is_preconnected (f '' s) ↔ is_preconnected s :=
begin
refine ⟨λ h, _, λ h, h.image _ hf.continuous.continuous_on⟩,
rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩,
rcases hf.is_open_iff.1 hu' with ⟨u, hu, rfl⟩,
rcases hf.is_open_iff.1 hv' with ⟨v, hv, rfl⟩,
replace huv : f '' s ⊆ u ∪ v, by rwa image_subset_iff,
rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩
with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩,
exact ⟨z, hzs, hzuv⟩
end
/- TODO: The following lemmas about connection of preimages hold more generally for strict maps
(the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/
lemma is_preconnected.preimage_of_open_map [topological_space β] {s : set β}
(hs : is_preconnected s) {f : α → β} (hinj : function.injective f) (hf : is_open_map f)
(hsf : s ⊆ range f) :
is_preconnected (f ⁻¹' s) :=
λ u v hu hv hsuv hsu hsv,
begin
obtain ⟨b, hbs, hbu, hbv⟩ := hs (f '' u) (f '' v) (hf u hu) (hf v hv) _ _ _,
obtain ⟨a, rfl⟩ := hsf hbs,
rw hinj.mem_set_image at hbu hbv,
exact ⟨a, hbs, hbu, hbv⟩,
{ have := image_subset f hsuv,
rwa [set.image_preimage_eq_of_subset hsf, image_union] at this },
{ obtain ⟨x, hx1, hx2⟩ := hsu,
exact ⟨f x, hx1, x, hx2, rfl⟩ },
{ obtain ⟨y, hy1, hy2⟩ := hsv,
exact ⟨f y, hy1, y, hy2, rfl⟩ }
end
lemma is_preconnected.preimage_of_closed_map [topological_space β] {s : set β}
(hs : is_preconnected s) {f : α → β} (hinj : function.injective f) (hf : is_closed_map f)
(hsf : s ⊆ range f) :
is_preconnected (f ⁻¹' s) :=
is_preconnected_closed_iff.2 $ λ u v hu hv hsuv hsu hsv,
begin
obtain ⟨b, hbs, hbu, hbv⟩ :=
is_preconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) _ _ _,
obtain ⟨a, rfl⟩ := hsf hbs,
rw hinj.mem_set_image at hbu hbv,
exact ⟨a, hbs, hbu, hbv⟩,
{ have := image_subset f hsuv,
rwa [set.image_preimage_eq_of_subset hsf, image_union] at this },
{ obtain ⟨x, hx1, hx2⟩ := hsu,
exact ⟨f x, hx1, x, hx2, rfl⟩ },
{ obtain ⟨y, hy1, hy2⟩ := hsv,
exact ⟨f y, hy1, y, hy2, rfl⟩ }
end
lemma is_connected.preimage_of_open_map [topological_space β] {s : set β} (hs : is_connected s)
{f : α → β} (hinj : function.injective f) (hf : is_open_map f) (hsf : s ⊆ range f) :
is_connected (f ⁻¹' s) :=
⟨hs.nonempty.preimage' hsf, hs.is_preconnected.preimage_of_open_map hinj hf hsf⟩
lemma is_connected.preimage_of_closed_map [topological_space β] {s : set β} (hs : is_connected s)
{f : α → β} (hinj : function.injective f) (hf : is_closed_map f) (hsf : s ⊆ range f) :
is_connected (f ⁻¹' s) :=
⟨hs.nonempty.preimage' hsf, hs.is_preconnected.preimage_of_closed_map hinj hf hsf⟩
lemma is_preconnected.subset_or_subset (hu : is_open u) (hv : is_open v) (huv : disjoint u v)
(hsuv : s ⊆ u ∪ v) (hs : is_preconnected s) :
s ⊆ u ∨ s ⊆ v :=
begin
specialize hs u v hu hv hsuv,
obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty,
{ exact or.inr ((set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) },
{ replace hs := mt (hs hsu),
simp_rw [set.not_nonempty_iff_eq_empty, ←set.disjoint_iff_inter_eq_empty,
disjoint_iff_inter_eq_empty.1 huv] at hs,
exact or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) }
end
lemma is_preconnected.subset_left_of_subset_union (hu : is_open u) (hv : is_open v)
(huv : disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).nonempty) (hs : is_preconnected s) :
s ⊆ u :=
disjoint.subset_left_of_subset_union hsuv
begin
by_contra hsv,
rw not_disjoint_iff_nonempty_inter at hsv,
obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv,
exact set.disjoint_iff.1 huv hx,
end
lemma is_preconnected.subset_right_of_subset_union (hu : is_open u) (hv : is_open v)
(huv : disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).nonempty) (hs : is_preconnected s) :
s ⊆ v :=
hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv
theorem is_preconnected.prod [topological_space β] {s : set α} {t : set β}
(hs : is_preconnected s) (ht : is_preconnected t) :
is_preconnected (s ×ˢ t) :=
begin
apply is_preconnected_of_forall_pair,
rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩,
refine ⟨prod.mk a₁ '' t ∪ flip prod.mk b₂ '' s, _,
or.inl ⟨b₁, hb₁, rfl⟩, or.inr ⟨a₂, ha₂, rfl⟩, _⟩,
{ rintro _ (⟨y, hy, rfl⟩|⟨x, hx, rfl⟩),
exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] },
{ exact (ht.image _ (continuous.prod.mk _).continuous_on).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩
⟨a₁, ha₁, rfl⟩ (hs.image _ (continuous_id.prod_mk continuous_const).continuous_on) }
end
theorem is_connected.prod [topological_space β] {s : set α} {t : set β}
(hs : is_connected s) (ht : is_connected t) : is_connected (s ×ˢ t) :=
⟨hs.1.prod ht.1, hs.2.prod ht.2⟩
theorem is_preconnected_univ_pi [Π i, topological_space (π i)] {s : Π i, set (π i)}
(hs : ∀ i, is_preconnected (s i)) :
is_preconnected (pi univ s) :=
begin
rintros u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩,
rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩,
induction I using finset.induction_on with i I hi ihI,
{ refine ⟨g, hgs, ⟨_, hgv⟩⟩, simpa using hI },
{ rw [finset.piecewise_insert] at hI,
have := I.piecewise_mem_set_pi hfs hgs,
refine (hsuv this).elim ihI (λ h, _),
set S := update (I.piecewise f g) i '' (s i),
have hsub : S ⊆ pi univ s,
{ refine image_subset_iff.2 (λ z hz, _),
rwa update_preimage_univ_pi,
exact λ j hj, this j trivial },
have hconn : is_preconnected S,
from (hs i).image _ (continuous_const.update i continuous_id).continuous_on,
have hSu : (S ∩ u).nonempty,
from ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩,
have hSv : (S ∩ v).nonempty,
from ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩,
refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono _,
exact inter_subset_inter_left _ hsub }
end
@[simp] theorem is_connected_univ_pi [Π i, topological_space (π i)] {s : Π i, set (π i)} :
is_connected (pi univ s) ↔ ∀ i, is_connected (s i) :=
begin
simp only [is_connected, ← univ_pi_nonempty_iff, forall_and_distrib, and.congr_right_iff],
refine λ hne, ⟨λ hc i, _, is_preconnected_univ_pi⟩,
rw [← eval_image_univ_pi hne],
exact hc.image _ (continuous_apply _).continuous_on
end
lemma sigma.is_connected_iff [Π i, topological_space (π i)] {s : set (Σ i, π i)} :
is_connected s ↔ ∃ i t, is_connected t ∧ s = sigma.mk i '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain ⟨⟨i, x⟩, hx⟩ := hs.nonempty,
have : s ⊆ range (sigma.mk i),
{ have h : range (sigma.mk i) = sigma.fst ⁻¹' {i}, by { ext, simp },
rw h,
exact is_preconnected.subset_left_of_subset_union
(is_open_sigma_fst_preimage _) (is_open_sigma_fst_preimage {x | x ≠ i})
(set.disjoint_iff.2 $ λ x hx, hx.2 hx.1)
(λ y hy, by simp [classical.em]) ⟨⟨i, x⟩, hx, rfl⟩ hs.2 },
exact ⟨i, sigma.mk i ⁻¹' s,
hs.preimage_of_open_map sigma_mk_injective is_open_map_sigma_mk this,
(set.image_preimage_eq_of_subset this).symm⟩ },
{ rintro ⟨i, t, ht, rfl⟩,
exact ht.image _ continuous_sigma_mk.continuous_on }
end
lemma sigma.is_preconnected_iff [hι : nonempty ι] [Π i, topological_space (π i)]
{s : set (Σ i, π i)} :
is_preconnected s ↔ ∃ i t, is_preconnected t ∧ s = sigma.mk i '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain rfl | h := s.eq_empty_or_nonempty,
{ exact ⟨classical.choice hι, ∅, is_preconnected_empty, (set.image_empty _).symm⟩ },
{ obtain ⟨a, t, ht, rfl⟩ := sigma.is_connected_iff.1 ⟨h, hs⟩,
refine ⟨a, t, ht.is_preconnected, rfl⟩ } },
{ rintro ⟨a, t, ht, rfl⟩,
exact ht.image _ continuous_sigma_mk.continuous_on }
end
lemma sum.is_connected_iff [topological_space β] {s : set (α ⊕ β)} :
is_connected s ↔
(∃ t, is_connected t ∧ s = sum.inl '' t) ∨ ∃ t, is_connected t ∧ s = sum.inr '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ let u : set (α ⊕ β) := range sum.inl,
let v : set (α ⊕ β) := range sum.inr,
have hu : is_open u, exact is_open_range_inl,
obtain ⟨x | x, hx⟩ := hs.nonempty,
{ have h : s ⊆ range sum.inl := is_preconnected.subset_left_of_subset_union
is_open_range_inl is_open_range_inr is_compl_range_inl_range_inr.disjoint
(by simp) ⟨sum.inl x, hx, x, rfl⟩ hs.2,
refine or.inl ⟨sum.inl ⁻¹' s, _, _⟩,
{ exact hs.preimage_of_open_map sum.inl_injective open_embedding_inl.is_open_map h },
{ exact (set.image_preimage_eq_of_subset h).symm } },
{ have h : s ⊆ range sum.inr := is_preconnected.subset_right_of_subset_union
is_open_range_inl is_open_range_inr is_compl_range_inl_range_inr.disjoint
(by simp) ⟨sum.inr x, hx, x, rfl⟩ hs.2,
refine or.inr ⟨sum.inr ⁻¹' s, _, _⟩,
{ exact hs.preimage_of_open_map sum.inr_injective open_embedding_inr.is_open_map h },
{ exact (set.image_preimage_eq_of_subset h).symm } } },
{ rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩),
{ exact ht.image _ continuous_inl.continuous_on },
{ exact ht.image _ continuous_inr.continuous_on } }
end
lemma sum.is_preconnected_iff [topological_space β] {s : set (α ⊕ β)} :
is_preconnected s ↔
(∃ t, is_preconnected t ∧ s = sum.inl '' t) ∨ ∃ t, is_preconnected t ∧ s = sum.inr '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain rfl | h := s.eq_empty_or_nonempty,
{ exact or.inl ⟨∅, is_preconnected_empty, (set.image_empty _).symm⟩ },
obtain ⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩ := sum.is_connected_iff.1 ⟨h, hs⟩,
{ exact or.inl ⟨t, ht.is_preconnected, rfl⟩ },
{ exact or.inr ⟨t, ht.is_preconnected, rfl⟩ } },
{ rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩),
{ exact ht.image _ continuous_inl.continuous_on },
{ exact ht.image _ continuous_inr.continuous_on } }
end
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
/-- Given a set `F` in a topological space `α` and a point `x : α`, the connected
component of `x` in `F` is the connected component of `x` in the subtype `F` seen as
a set in `α`. This definition does not make sense if `x` is not in `F` so we return the
empty set in this case. -/
def connected_component_in (F : set α) (x : α) : set α :=
if h : x ∈ F then coe '' (connected_component (⟨x, h⟩ : F)) else ∅
lemma connected_component_in_eq_image {F : set α} {x : α} (h : x ∈ F) :
connected_component_in F x = coe '' (connected_component (⟨x, h⟩ : F)) :=
dif_pos h
lemma connected_component_in_eq_empty {F : set α} {x : α} (h : x ∉ F) :
connected_component_in F x = ∅ :=
dif_neg h
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem mem_connected_component_in {x : α} {F : set α} (hx : x ∈ F) :
x ∈ connected_component_in F x :=
by simp [connected_component_in_eq_image hx, mem_connected_component, hx]
theorem connected_component_nonempty {x : α} :
(connected_component x).nonempty :=
⟨x, mem_connected_component⟩
theorem connected_component_in_nonempty_iff {x : α} {F : set α} :
(connected_component_in F x).nonempty ↔ x ∈ F :=
by { rw [connected_component_in], split_ifs; simp [connected_component_nonempty, h] }
theorem connected_component_in_subset (F : set α) (x : α) :
connected_component_in F x ⊆ F :=
by { rw [connected_component_in], split_ifs; simp }
theorem is_preconnected_connected_component {x : α} : is_preconnected (connected_component x) :=
is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)
lemma is_preconnected_connected_component_in {x : α} {F : set α} :
is_preconnected (connected_component_in F x) :=
begin
rw [connected_component_in], split_ifs,
{ exact embedding_subtype_coe.to_inducing.is_preconnected_image.mpr
is_preconnected_connected_component },
{ exact is_preconnected_empty },
end
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_connected_component⟩
lemma is_connected_connected_component_in_iff {x : α} {F : set α} :
is_connected (connected_component_in F x) ↔ x ∈ F :=
by simp_rw [← connected_component_in_nonempty_iff, is_connected,
is_preconnected_connected_component_in, and_true]
theorem is_preconnected.subset_connected_component {x : α} {s : set α}
(H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
lemma is_preconnected.subset_connected_component_in {x : α} {F : set α} (hs : is_preconnected s)
(hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connected_component_in F x :=
begin
have : is_preconnected ((coe : F → α) ⁻¹' s),
{ refine embedding_subtype_coe.to_inducing.is_preconnected_image.mp _,
rwa [subtype.image_preimage_coe, inter_eq_left_iff_subset.mpr hsF] },
have h2xs : (⟨x, hsF hxs⟩ : F) ∈ coe ⁻¹' s := by { rw [mem_preimage], exact hxs },
have := this.subset_connected_component h2xs,
rw [connected_component_in_eq_image (hsF hxs)],
refine subset.trans _ (image_subset _ this),
rw [subtype.image_preimage_coe, inter_eq_left_iff_subset.mpr hsF]
end
theorem is_connected.subset_connected_component {x : α} {s : set α}
(H1 : is_connected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
H1.2.subset_connected_component H2
lemma is_preconnected.connected_component_in {x : α} {F : set α} (h : is_preconnected F)
(hx : x ∈ F) : connected_component_in F x = F :=
(connected_component_in_subset F x).antisymm (h.subset_connected_component_in hx subset_rfl)
theorem connected_component_eq {x y : α} (h : y ∈ connected_component x) :
connected_component x = connected_component y :=
eq_of_subset_of_subset
(is_connected_connected_component.subset_connected_component h)
(is_connected_connected_component.subset_connected_component
(set.mem_of_mem_of_subset mem_connected_component
(is_connected_connected_component.subset_connected_component h)))
lemma connected_component_in_eq {x y : α} {F : set α} (h : y ∈ connected_component_in F x) :
connected_component_in F x = connected_component_in F y :=
begin
have hx : x ∈ F := connected_component_in_nonempty_iff.mp ⟨y, h⟩,
simp_rw [connected_component_in_eq_image hx] at h ⊢,
obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h,
simp_rw [subtype.coe_mk, connected_component_in_eq_image hy, connected_component_eq h2y]
end
theorem connected_component_in_univ (x : α) :
connected_component_in univ x = connected_component x :=
subset_antisymm
(is_preconnected_connected_component_in.subset_connected_component $
mem_connected_component_in trivial)
(is_preconnected_connected_component.subset_connected_component_in mem_connected_component $
subset_univ _)
lemma connected_component_disjoint {x y : α} (h : connected_component x ≠ connected_component y) :
disjoint (connected_component x) (connected_component y) :=
set.disjoint_left.2 (λ a h1 h2, h
((connected_component_eq h1).trans (connected_component_eq h2).symm))
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_subset_iff_is_closed.1 $
is_connected_connected_component.closure.subset_connected_component $
subset_closure mem_connected_component
lemma continuous.image_connected_component_subset [topological_space β] {f : α → β}
(h : continuous f) (a : α) : f '' connected_component a ⊆ connected_component (f a) :=
(is_connected_connected_component.image f h.continuous_on).subset_connected_component
((mem_image f (connected_component a) (f a)).2 ⟨a, mem_connected_component, rfl⟩)
lemma continuous.maps_to_connected_component [topological_space β] {f : α → β}
(h : continuous f) (a : α) : maps_to f (connected_component a) (connected_component (f a)) :=
maps_to'.2 $ h.image_connected_component_subset a
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
is_irreducible_irreducible_component.is_connected.subset_connected_component
mem_irreducible_component
@[mono]
lemma connected_component_in_mono (x : α) {F G : set α} (h : F ⊆ G) :
connected_component_in F x ⊆ connected_component_in G x :=
begin
by_cases hx : x ∈ F,
{ rw [connected_component_in_eq_image hx, connected_component_in_eq_image (h hx),
← show (coe : G → α) ∘ inclusion h = coe, by ext ; refl, image_comp],
exact image_subset coe ((continuous_inclusion h).image_connected_component_subset ⟨x, hx⟩) },
{ rw connected_component_in_eq_empty hx,
exact set.empty_subset _ },
end
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
lemma is_connected_univ [connected_space α] : is_connected (univ : set α) :=
⟨univ_nonempty, is_preconnected_univ⟩
lemma is_preconnected_range [topological_space β] [preconnected_space α] {f : α → β}
(h : continuous f) : is_preconnected (range f) :=
@image_univ _ _ f ▸ is_preconnected_univ.image _ h.continuous_on
lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) :
is_connected (range f) :=
⟨range_nonempty f, is_preconnected_range h⟩
lemma dense_range.preconnected_space [topological_space β] [preconnected_space α] {f : α → β}
(hf : dense_range f) (hc : continuous f) :
preconnected_space β :=
⟨hf.closure_eq ▸ (is_preconnected_range hc).closure⟩
lemma connected_space_iff_connected_component :
connected_space α ↔ ∃ x : α, connected_component x = univ :=
begin
split,
{ rintros ⟨h, ⟨x⟩⟩,
exactI ⟨x, eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)⟩ },
{ rintros ⟨x, h⟩,
haveI : preconnected_space α := ⟨by { rw ← h, exact is_preconnected_connected_component }⟩,
exact ⟨⟨x⟩⟩ }
end
lemma preconnected_space_iff_connected_component :
preconnected_space α ↔ ∀ x : α, connected_component x = univ :=
begin
split,
{ intros h x,
exactI (eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)) },
{ intros h,
casesI is_empty_or_nonempty α with hα hα,
{ exact ⟨by { rw (univ_eq_empty_iff.mpr hα), exact is_preconnected_empty }⟩ },
{ exact ⟨by { rw ← h (classical.choice hα), exact is_preconnected_connected_component }⟩ } }
end
@[simp] lemma preconnected_space.connected_component_eq_univ {X : Type*} [topological_space X]
[h : preconnected_space X] (x : X) : connected_component x = univ :=
preconnected_space_iff_connected_component.mp h x
instance [topological_space β] [preconnected_space α] [preconnected_space β] :
preconnected_space (α × β) :=
⟨by { rw ← univ_prod_univ, exact is_preconnected_univ.prod is_preconnected_univ }⟩
instance [topological_space β] [connected_space α] [connected_space β] :
connected_space (α × β) :=
⟨prod.nonempty⟩
instance [Π i, topological_space (π i)] [∀ i, preconnected_space (π i)] :
preconnected_space (Π i, π i) :=
⟨by { rw ← pi_univ univ, exact is_preconnected_univ_pi (λ i, is_preconnected_univ) }⟩
instance [Π i, topological_space (π i)] [∀ i, connected_space (π i)] : connected_space (Π i, π i) :=
⟨classical.nonempty_pi.2 $ λ i, by apply_instance⟩
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2.is_open_compl (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α}
(h : s.nonempty) (h' : is_clopen s) : s = univ :=
by { rw is_clopen_iff at h', exact h'.resolve_left h.ne_empty }
lemma frontier_eq_empty_iff [preconnected_space α] {s : set α} :
frontier s = ∅ ↔ s = ∅ ∨ s = univ :=
is_clopen_iff_frontier_eq_empty.symm.trans is_clopen_iff
lemma nonempty_frontier_iff [preconnected_space α] {s : set α} :
(frontier s).nonempty ↔ s.nonempty ∧ s ≠ univ :=
by simp only [← ne_empty_iff_nonempty, ne.def, frontier_eq_empty_iff, not_or_distrib]
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ := by rwa [← embedding_subtype_coe.to_inducing.is_preconnected_image,
image_univ, subtype.range_coe] }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ to_preconnected_space := subtype.preconnected_space h.is_preconnected,
to_nonempty := h.nonempty.to_subtype }
lemma is_preconnected_iff_preconnected_space {s : set α} :
is_preconnected s ↔ preconnected_space s :=
⟨subtype.preconnected_space,
begin
introI,
simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on
end⟩
lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s :=
⟨subtype.connected_space,
λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem is_preconnected.subset_clopen {s t : set α} (hs : is_preconnected s) (ht : is_clopen t)
(hne : (s ∩ t).nonempty) : s ⊆ t :=
begin
by_contra h,
have : (s ∩ tᶜ).nonempty := inter_compl_nonempty_iff.2 h,
obtain ⟨x, -, hx, hx'⟩ : (s ∩ (t ∩ tᶜ)).nonempty,
from hs t tᶜ ht.is_open ht.compl.is_open (λ x hx, em _) hne this,
exact hx' hx
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem disjoint_or_subset_of_clopen {s t : set α} (hs : is_preconnected s) (ht : is_clopen t) :
disjoint s t ∨ s ⊆ t :=
(disjoint_or_nonempty_inter s t).imp_right $ hs.subset_clopen ht
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
rw is_preconnected_closed_iff at h,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ rw is_preconnected_closed_iff,
intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : disjoint u v),
s ⊆ u ∨ s ⊆ v :=
begin
split,
{ intros h u v hu hv hss huv,
apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss,
rw [huv.inter_eq, inter_empty] },
intro H,
rw is_preconnected_iff_subset_of_disjoint_closed,
intros u v hu hv hss huv,
have H1 := H (u ∩ s) (v ∩ s),
rw [subset_inter_iff, subset_inter_iff] at H1,
simp only [subset.refl, and_true] at H1,
apply H1 (is_closed.inter hu hs) (is_closed.inter hv hs),
{ rw ←inter_distrib_right,
exact subset_inter hss subset.rfl },
{ rwa [disjoint_iff_inter_eq_empty, ←inter_inter_distrib_right, inter_comm] }
end
lemma is_clopen.connected_component_subset {x} (hs : is_clopen s) (hx : x ∈ s) :
connected_component x ⊆ s :=
is_preconnected_connected_component.subset_clopen hs ⟨x, mem_connected_component, hx⟩
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
lemma connected_component_subset_Inter_clopen {x : α} :
connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
subset_Inter $ λ Z, Z.2.1.connected_component_subset Z.2.2
/-- A clopen set is the union of its connected components. -/
lemma is_clopen.bUnion_connected_component_eq {Z : set α} (h : is_clopen Z) :
(⋃ x ∈ Z, connected_component x) = Z :=
subset.antisymm (Union₂_subset $ λ x, h.connected_component_subset) $
λ x hx, mem_Union₂_of_mem hx mem_connected_component
/-- The preimage of a connected component is preconnected if the function has connected fibers
and a subset is closed iff the preimage is. -/
lemma preimage_connected_component_connected [topological_space β] {f : α → β}
(connected_fibers : ∀ t : β, is_connected (f ⁻¹' {t}))
(hcl : ∀ (T : set β), is_closed T ↔ is_closed (f ⁻¹' T)) (t : β) :
is_connected (f ⁻¹' connected_component t) :=
begin
-- The following proof is essentially https://stacks.math.columbia.edu/tag/0377
-- although the statement is slightly different
have hf : surjective f := surjective.of_comp (λ t : β, (connected_fibers t).1),
split,
{ cases hf t with s hs,
use s,
rw [mem_preimage, hs],
exact mem_connected_component },
have hT : is_closed (f ⁻¹' connected_component t) :=
(hcl (connected_component t)).1 is_closed_connected_component,
-- To show it's preconnected we decompose (f ⁻¹' connected_component t) as a subset of two
-- closed disjoint sets in α. We want to show that it's a subset of either.
rw is_preconnected_iff_subset_of_fully_disjoint_closed hT,
intros u v hu hv huv uv_disj,
-- To do this we decompose connected_component t into T₁ and T₂
-- we will show that connected_component t is a subset of either and hence
-- (f ⁻¹' connected_component t) is a subset of u or v
let T₁ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ u},
let T₂ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ v},
have fiber_decomp : ∀ t' ∈ connected_component t, f ⁻¹' {t'} ⊆ u ∨ f ⁻¹' {t'} ⊆ v,
{ intros t' ht',
apply is_preconnected_iff_subset_of_disjoint_closed.1 (connected_fibers t').2 u v hu hv,
{ exact subset.trans (hf.preimage_subset_preimage_iff.2 (singleton_subset_iff.2 ht')) huv },
rw [uv_disj.inter_eq, inter_empty] },
have T₁_u : f ⁻¹' T₁ = (f ⁻¹' connected_component t) ∩ u,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine Union₂_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hau⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exact h },
{ cases (nonempty_of_mem $ mem_inter hau $ h rfl).not_disjoint uv_disj } },
-- This proof is exactly the same as the above (modulo some symmetry)
have T₂_v : f ⁻¹' T₂ = (f ⁻¹' connected_component t) ∩ v,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine Union₂_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hav⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ cases (nonempty_of_mem (mem_inter (h rfl) hav)).not_disjoint uv_disj },
{ exact h } },
-- Now we show T₁, T₂ are closed, cover connected_component t and are disjoint.
have hT₁ : is_closed T₁ := ((hcl T₁).2 (T₁_u.symm ▸ (is_closed.inter hT hu))),
have hT₂ : is_closed T₂ := ((hcl T₂).2 (T₂_v.symm ▸ (is_closed.inter hT hv))),
have T_decomp : connected_component t ⊆ T₁ ∪ T₂,
{ intros t' ht',
rw mem_union t' T₁ T₂,
cases fiber_decomp t' ht' with htu htv,
{ left, exact ⟨ht', htu⟩ },
right, exact ⟨ht', htv⟩ },
have T_disjoint : disjoint T₁ T₂,
{ refine disjoint.of_preimage hf _,
rw [T₁_u, T₂_v, disjoint_iff_inter_eq_empty, ←inter_inter_distrib_left, uv_disj.inter_eq,
inter_empty] },
-- Now we do cases on whether (connected_component t) is a subset of T₁ or T₂ to show
-- that the preimage is a subset of u or v.
cases (is_preconnected_iff_subset_of_fully_disjoint_closed is_closed_connected_component).1
is_preconnected_connected_component T₁ T₂ hT₁ hT₂ T_decomp T_disjoint,
{ left,
rw subset.antisymm_iff at T₁_u,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₁,
{ exact subset.trans (subset.trans this T₁_u.1) (inter_subset_right _ _) },
exact preimage_mono h },
right,
rw subset.antisymm_iff at T₂_v,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₂,
{ exact subset.trans (subset.trans this T₂_v.1) (inter_subset_right _ _) },
exact preimage_mono h,
end
lemma quotient_map.preimage_connected_component [topological_space β] {f : α → β}
(hf : quotient_map f) (h_fibers : ∀ y : β, is_connected (f ⁻¹' {y})) (a : α) :
f ⁻¹' connected_component (f a) = connected_component a :=
((preimage_connected_component_connected h_fibers
(λ _, hf.is_closed_preimage.symm) _).subset_connected_component mem_connected_component).antisymm
(hf.continuous.maps_to_connected_component a)
lemma quotient_map.image_connected_component [topological_space β] {f : α → β}
(hf : quotient_map f) (h_fibers : ∀ y : β, is_connected (f ⁻¹' {y})) (a : α) :
f '' connected_component a = connected_component (f a) :=
by rw [← hf.preimage_connected_component h_fibers, image_preimage_eq _ hf.surjective]
end preconnected
section locally_connected_space
/-- A topological space is **locally connected** if each neighborhood filter admits a basis
of connected *open* sets. Note that it is equivalent to each point having a basis of connected
(non necessarily open) sets but in a non-trivial way, so we choose this definition and prove the
equivalence later in `locally_connected_space_iff_connected_basis`. -/
class locally_connected_space (α : Type*) [topological_space α] : Prop :=
(open_connected_basis : ∀ x, (𝓝 x).has_basis (λ s : set α, is_open s ∧ x ∈ s ∧ is_connected s) id)
lemma locally_connected_space_iff_open_connected_basis : locally_connected_space α ↔
∀ x, (𝓝 x).has_basis (λ s : set α, is_open s ∧ x ∈ s ∧ is_connected s) id :=
⟨@locally_connected_space.open_connected_basis _ _, locally_connected_space.mk⟩
lemma locally_connected_space_iff_open_connected_subsets :
locally_connected_space α ↔ ∀ (x : α) (U ∈ 𝓝 x), ∃ V ⊆ U, is_open V ∧ x ∈ V ∧ is_connected V :=
begin
rw locally_connected_space_iff_open_connected_basis,
congrm ∀ x, (_ : Prop),
split,
{ intros h U hU,
rcases h.mem_iff.mp hU with ⟨V, hV, hVU⟩,
exact ⟨V, hVU, hV⟩ },
{ exact λ h, ⟨λ U, ⟨λ hU, let ⟨V, hVU, hV⟩ := h U hU in ⟨V, hV, hVU⟩,
λ ⟨V, ⟨hV, hxV, _⟩, hVU⟩, mem_nhds_iff.mpr ⟨V, hVU, hV, hxV⟩⟩⟩ }
end
lemma connected_component_in_mem_nhds [locally_connected_space α] {F : set α} {x : α}
(h : F ∈ 𝓝 x) :
connected_component_in F x ∈ 𝓝 x :=
begin
rw (locally_connected_space.open_connected_basis x).mem_iff at h,
rcases h with ⟨s, ⟨h1s, hxs, h2s⟩, hsF⟩,
exact mem_nhds_iff.mpr ⟨s, h2s.is_preconnected.subset_connected_component_in hxs hsF, h1s, hxs⟩
end
lemma is_open.connected_component_in [locally_connected_space α] {F : set α} {x : α}
(hF : is_open F) :
is_open (connected_component_in F x) :=
begin
rw [is_open_iff_mem_nhds],
intros y hy,
rw [connected_component_in_eq hy],
exact connected_component_in_mem_nhds (is_open_iff_mem_nhds.mp hF y $
connected_component_in_subset F x hy)
end
lemma is_open_connected_component [locally_connected_space α] {x : α} :
is_open (connected_component x) :=
begin
rw ← connected_component_in_univ,
exact is_open_univ.connected_component_in
end
lemma is_clopen_connected_component [locally_connected_space α] {x : α} :
is_clopen (connected_component x) :=
⟨is_open_connected_component, is_closed_connected_component⟩
lemma locally_connected_space_iff_connected_component_in_open :
locally_connected_space α ↔ ∀ F : set α, is_open F → ∀ x ∈ F,
is_open (connected_component_in F x) :=
begin
split,
{ introI h,
exact λ F hF x _, hF.connected_component_in },
{ intro h,
rw locally_connected_space_iff_open_connected_subsets,
refine (λ x U hU, ⟨connected_component_in (interior U) x,
(connected_component_in_subset _ _).trans interior_subset, h _ is_open_interior x _,
mem_connected_component_in _, is_connected_connected_component_in_iff.mpr _⟩);
exact (mem_interior_iff_mem_nhds.mpr hU) }
end
lemma locally_connected_space_iff_connected_subsets :
locally_connected_space α ↔ ∀ (x : α) (U ∈ 𝓝 x), ∃ V ∈ 𝓝 x, is_preconnected V ∧ V ⊆ U :=
begin
split,
{ rw locally_connected_space_iff_open_connected_subsets,
intros h x U hxU,
rcases h x U hxU with ⟨V, hVU, hV₁, hxV, hV₂⟩,
exact ⟨V, hV₁.mem_nhds hxV, hV₂.is_preconnected, hVU⟩ },
{ rw locally_connected_space_iff_connected_component_in_open,
refine λ h U hU x hxU, is_open_iff_mem_nhds.mpr (λ y hy, _),
rw connected_component_in_eq hy,
rcases h y U (hU.mem_nhds $ (connected_component_in_subset _ _) hy) with ⟨V, hVy, hV, hVU⟩,
exact filter.mem_of_superset hVy
(hV.subset_connected_component_in (mem_of_mem_nhds hVy) hVU) }
end
lemma locally_connected_space_iff_connected_basis :
locally_connected_space α ↔
∀ x, (𝓝 x).has_basis (λ s : set α, s ∈ 𝓝 x ∧ is_preconnected s) id :=
begin
rw locally_connected_space_iff_connected_subsets,
congrm ∀ x, (_ : Prop),
exact filter.has_basis_self.symm
end
lemma locally_connected_space_of_connected_bases {ι : Type*} (b : α → ι → set α) (p : α → ι → Prop)
(hbasis : ∀ x, (𝓝 x).has_basis (p x) (b x))
(hconnected : ∀ x i, p x i → is_preconnected (b x i)) :
locally_connected_space α :=
begin
rw locally_connected_space_iff_connected_basis,
exact λ x, (hbasis x).to_has_basis
(λ i hi, ⟨b x i, ⟨(hbasis x).mem_of_mem hi, hconnected x i hi⟩, subset_rfl⟩)
(λ s hs, ⟨(hbasis x).index s hs.1,
⟨(hbasis x).property_index hs.1, (hbasis x).set_index_subset hs.1⟩⟩)
end
end locally_connected_space
section totally_disconnected
/-- A set `s` is called totally disconnected if every subset `t ⊆ s` which is preconnected is
a subsingleton, ie either empty or a singleton.-/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → t.subsingleton
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ _ ht _ _ x_in _ _, (ht x_in).elim
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ _ ht _, subsingleton_singleton.anti ht
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
lemma is_preconnected.subsingleton [totally_disconnected_space α]
{s : set α} (h : is_preconnected s) : s.subsingleton :=
totally_disconnected_space.is_totally_disconnected_univ s (subset_univ s) h
instance pi.totally_disconnected_space {α : Type*} {β : α → Type*}
[t₂ : Πa, topological_space (β a)] [∀a, totally_disconnected_space (β a)] :
totally_disconnected_space (Π (a : α), β a) :=
⟨λ t h1 h2,
have this : ∀ a, is_preconnected ((λ x : Π a, β a, x a) '' t),
from λ a, h2.image (λ x, x a) (continuous_apply a).continuous_on,
λ x x_in y y_in, funext $ λ a, (this a).subsingleton ⟨x, x_in, rfl⟩ ⟨y, y_in, rfl⟩⟩
instance prod.totally_disconnected_space [topological_space β]
[totally_disconnected_space α] [totally_disconnected_space β] :
totally_disconnected_space (α × β) :=
⟨λ t h1 h2,
have H1 : is_preconnected (prod.fst '' t), from h2.image prod.fst continuous_fst.continuous_on,
have H2 : is_preconnected (prod.snd '' t), from h2.image prod.snd continuous_snd.continuous_on,
λ x hx y hy, prod.ext
(H1.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩)
(H2.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩)⟩
instance [topological_space β] [totally_disconnected_space α] [totally_disconnected_space β] :
totally_disconnected_space (α ⊕ β) :=
begin
refine ⟨λ s _ hs, _⟩,
obtain (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩) := sum.is_preconnected_iff.1 hs,
{ exact ht.subsingleton.image _ },
{ exact ht.subsingleton.image _ }
end
instance [Π i, topological_space (π i)] [∀ i, totally_disconnected_space (π i)] :
totally_disconnected_space (Σ i, π i) :=
begin
refine ⟨λ s _ hs, _⟩,
obtain rfl | h := s.eq_empty_or_nonempty,
{ exact subsingleton_empty },
{ obtain ⟨a, t, ht, rfl⟩ := sigma.is_connected_iff.1 ⟨h, hs⟩,
exact ht.is_preconnected.subsingleton.image _ }
end
/-- Let `X` be a topological space, and suppose that for all distinct `x,y ∈ X`, there
is some clopen set `U` such that `x ∈ U` and `y ∉ U`. Then `X` is totally disconnected. -/
lemma is_totally_disconnected_of_clopen_set {X : Type*} [topological_space X]
(hX : ∀ {x y : X} (h_diff : x ≠ y), ∃ (U : set X) (h_clopen : is_clopen U), x ∈ U ∧ y ∉ U) :
is_totally_disconnected (set.univ : set X) :=
begin
rintro S - hS,
unfold set.subsingleton,
by_contra' h_contra,
rcases h_contra with ⟨x, hx, y, hy, hxy⟩,
obtain ⟨U, h_clopen, hxU, hyU⟩ := hX hxy,
specialize hS U Uᶜ h_clopen.1 h_clopen.compl.1 (λ a ha, em (a ∈ U)) ⟨x, hx, hxU⟩ ⟨y, hy, hyU⟩,
rw [inter_compl_self, set.inter_empty] at hS,
exact set.not_nonempty_empty hS,
end
/-- A space is totally disconnected iff its connected components are subsingletons. -/
lemma totally_disconnected_space_iff_connected_component_subsingleton :
totally_disconnected_space α ↔ ∀ x : α, (connected_component x).subsingleton :=
begin
split,
{ intros h x,
apply h.1,
{ exact subset_univ _ },
exact is_preconnected_connected_component },
intro h, constructor,
intros s s_sub hs,
rcases eq_empty_or_nonempty s with rfl | ⟨x, x_in⟩,
{ exact subsingleton_empty },
{ exact (h x).anti (hs.subset_connected_component x_in) }
end
/-- A space is totally disconnected iff its connected components are singletons. -/
lemma totally_disconnected_space_iff_connected_component_singleton :
totally_disconnected_space α ↔ ∀ x : α, connected_component x = {x} :=
begin
rw totally_disconnected_space_iff_connected_component_subsingleton,
apply forall_congr (λ x, _),
rw subsingleton_iff_singleton,
exact mem_connected_component
end
/-- The image of a connected component in a totally disconnected space is a singleton. -/
@[simp] lemma continuous.image_connected_component_eq_singleton {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (a : α) :
f '' connected_component a = {f a} :=
(set.subsingleton_iff_singleton $ mem_image_of_mem f mem_connected_component).mp
(is_preconnected_connected_component.image f h.continuous_on).subsingleton
lemma is_totally_disconnected_of_totally_disconnected_space [totally_disconnected_space α]
(s : set α) : is_totally_disconnected s :=
λ t hts ht, totally_disconnected_space.is_totally_disconnected_univ _ t.subset_univ ht
lemma is_totally_disconnected_of_image [topological_space β] {f : α → β} (hf : continuous_on f s)
(hf' : injective f) (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
λ t hts ht x x_in y y_in, hf' $ h _ (image_subset f hts) (ht.image f $ hf.mono hts)
(mem_image_of_mem f x_in) (mem_image_of_mem f y_in)
lemma embedding.is_totally_disconnected [topological_space β] {f : α → β} (hf : embedding f)
{s : set α} (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
is_totally_disconnected_of_image hf.continuous.continuous_on hf.inj h
instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α]
[totally_disconnected_space α] : totally_disconnected_space (subtype p) :=
⟨embedding_subtype_coe.is_totally_disconnected
(is_totally_disconnected_of_totally_disconnected_space _)⟩
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ disjoint u v
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
begin
intros t hts ht x x_in y y_in,
by_contra h,
obtain ⟨u : set α, v : set α, hu : is_open u, hv : is_open v,
hxu : x ∈ u, hyv : y ∈ v, hs : s ⊆ u ∪ v, huv⟩ :=
H x (hts x_in) y (hts y_in) h,
refine (ht _ _ hu hv (hts.trans hs) ⟨x, x_in, hxu⟩ ⟨y, y_in, hyv⟩).ne_empty _,
rw [huv.inter_eq, inter_empty],
end
alias is_totally_disconnected_of_is_totally_separated ← is_totally_separated.is_totally_disconnected
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $
totally_separated_space.is_totally_separated_univ α⟩
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.of_discrete
(α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α :=
⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩
lemma exists_clopen_of_totally_separated {α : Type*} [topological_space α]
[totally_separated_space α] {x y : α} (hxy : x ≠ y) :
∃ (U : set α) (hU : is_clopen U), x ∈ U ∧ y ∈ Uᶜ :=
begin
obtain ⟨U, V, hU, hV, Ux, Vy, f, disj⟩ :=
totally_separated_space.is_totally_separated_univ α x (set.mem_univ x) y (set.mem_univ y) hxy,
have clopen_U := is_clopen_inter_of_disjoint_cover_clopen (is_clopen_univ) f hU hV disj,
rw univ_inter _ at clopen_U,
rw [←set.subset_compl_iff_disjoint_right, subset_compl_comm] at disj,
exact ⟨U, clopen_U, Ux, disj Vy⟩,
end
end totally_separated
section connected_component_setoid
/-- The setoid of connected components of a topological space -/
def connected_component_setoid (α : Type*) [topological_space α] : setoid α :=
⟨λ x y, connected_component x = connected_component y,
⟨λ x, by trivial, λ x y h1, h1.symm, λ x y z h1 h2, h1.trans h2⟩⟩
/-- The quotient of a space by its connected components -/
def connected_components (α : Type u) [topological_space α] :=
quotient (connected_component_setoid α)
instance : has_coe_t α (connected_components α) := ⟨quotient.mk'⟩
namespace connected_components
@[simp] lemma coe_eq_coe {x y : α} :
(x : connected_components α) = y ↔ connected_component x = connected_component y :=
quotient.eq'
lemma coe_ne_coe {x y : α} :
(x : connected_components α) ≠ y ↔ connected_component x ≠ connected_component y :=
not_congr coe_eq_coe
lemma coe_eq_coe' {x y : α} :
(x : connected_components α) = y ↔ x ∈ connected_component y :=
coe_eq_coe.trans ⟨λ h, h ▸ mem_connected_component, λ h, (connected_component_eq h).symm⟩
instance [inhabited α] : inhabited (connected_components α) := ⟨↑(default : α)⟩
instance : topological_space (connected_components α) :=
quotient.topological_space
lemma surjective_coe : surjective (coe : α → connected_components α) := surjective_quot_mk _
lemma quotient_map_coe : quotient_map (coe : α → connected_components α) := quotient_map_quot_mk
@[continuity]
lemma continuous_coe : continuous (coe : α → connected_components α) := quotient_map_coe.continuous
@[simp] lemma range_coe : range (coe : α → connected_components α)= univ :=
surjective_coe.range_eq
end connected_components
variables [topological_space β] [totally_disconnected_space β] {f : α → β}
lemma continuous.image_eq_of_connected_component_eq (h : continuous f) (a b : α)
(hab : connected_component a = connected_component b) : f a = f b :=
singleton_eq_singleton_iff.1 $
h.image_connected_component_eq_singleton a ▸
h.image_connected_component_eq_singleton b ▸ hab ▸ rfl
/--
The lift to `connected_components α` of a continuous map from `α` to a totally disconnected space
-/
def continuous.connected_components_lift (h : continuous f) :
connected_components α → β :=
λ x, quotient.lift_on' x f h.image_eq_of_connected_component_eq
@[continuity] lemma continuous.connected_components_lift_continuous (h : continuous f) :
continuous h.connected_components_lift :=
h.quotient_lift_on' h.image_eq_of_connected_component_eq
@[simp] lemma continuous.connected_components_lift_apply_coe (h : continuous f) (x : α) :
h.connected_components_lift x = f x := rfl
@[simp] lemma continuous.connected_components_lift_comp_coe (h : continuous f) :
h.connected_components_lift ∘ coe = f := rfl
lemma connected_components_lift_unique' {β : Sort*} {g₁ g₂ : connected_components α → β}
(hg : g₁ ∘ (coe : α → connected_components α) = g₂ ∘ coe) :
g₁ = g₂ :=
connected_components.surjective_coe.injective_comp_right hg
lemma continuous.connected_components_lift_unique (h : continuous f)
(g : connected_components α → β) (hg : g ∘ coe = f) : g = h.connected_components_lift :=
connected_components_lift_unique' $ hg.trans h.connected_components_lift_comp_coe.symm
/-- The preimage of a singleton in `connected_components` is the connected component
of an element in the equivalence class. -/
lemma connected_components_preimage_singleton {x : α} :
coe ⁻¹' ({x} : set (connected_components α)) = connected_component x :=
by { ext y, simp [connected_components.coe_eq_coe'] }
/-- The preimage of the image of a set under the quotient map to `connected_components α`
is the union of the connected components of the elements in it. -/
lemma connected_components_preimage_image (U : set α) :
coe ⁻¹' (coe '' U : set (connected_components α)) = ⋃ x ∈ U, connected_component x :=
by simp only [connected_components_preimage_singleton, preimage_Union₂, image_eq_Union]
instance connected_components.totally_disconnected_space :
totally_disconnected_space (connected_components α) :=
begin
rw totally_disconnected_space_iff_connected_component_singleton,
refine connected_components.surjective_coe.forall.2 (λ x, _),
rw [← connected_components.quotient_map_coe.image_connected_component,
← connected_components_preimage_singleton,
image_preimage_eq _ connected_components.surjective_coe],
refine connected_components.surjective_coe.forall.2 (λ y, _),
rw connected_components_preimage_singleton,
exact is_connected_connected_component
end
/-- Functoriality of `connected_components` -/
def continuous.connected_components_map {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : connected_components α → connected_components β :=
continuous.connected_components_lift (continuous_quotient_mk.comp h)
lemma continuous.connected_components_map_continuous {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : continuous h.connected_components_map :=
continuous.connected_components_lift_continuous (continuous_quotient_mk.comp h)
end connected_component_setoid
|
ab1de43333005f446518e8626bdd3278fe0acf4f | 61ccc57f9d72048e493dd6969b56ebd7f0a8f9e8 | /src/analysis/normed_space/banach.lean | 44763e1a518b6cd4b92b51d7bcb83ccc465ec9c2 | [
"Apache-2.0"
] | permissive | jtristan/mathlib | 375b3c8682975df28f79f53efcb7c88840118467 | 8fa8f175271320d675277a672f59ec53abd62f10 | refs/heads/master | 1,651,072,765,551 | 1,588,255,641,000 | 1,588,255,641,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,931 | 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
Banach spaces, i.e., complete vector spaces.
This file contains the Banach open mapping theorem, i.e., the fact that a bijective
bounded linear map between Banach spaces has a bounded inverse.
-/
import topology.metric_space.baire
import analysis.normed_space.bounded_linear_maps
open function metric set filter finset
open_locale classical topological_space
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
(f : E →L[𝕜] F)
include 𝕜
set_option class.instance_max_depth 70
variable [complete_space F]
/--
First step of the proof of the Banach open mapping theorem (using completeness of `F`):
by Baire's theorem, there exists a ball in `E` whose image closure has nonempty interior.
Rescaling everything, it follows that any `y ∈ F` is arbitrarily well approached by
images of elements of norm at most `C * ∥y∥`.
For further use, we will only need such an element whose image
is within distance `∥y∥/2` of `y`, to apply an iterative process. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_approx_preimage_norm_le (surj : surjective f) :
∃C ≥ 0, ∀y, ∃x, dist (f x) y ≤ 1/2 * ∥y∥ ∧ ∥x∥ ≤ C * ∥y∥ :=
begin
haveI : nonempty F := ⟨0⟩,
have A : (⋃n:ℕ, closure (f '' (ball 0 n))) = univ,
{ refine subset.antisymm (subset_univ _) (λy hy, _),
rcases surj y with ⟨x, hx⟩,
rcases exists_nat_gt (∥x∥) with ⟨n, hn⟩,
refine mem_Union.2 ⟨n, subset_closure _⟩,
refine (mem_image _ _ _).2 ⟨x, ⟨_, hx⟩⟩,
rwa [mem_ball, dist_eq_norm, sub_zero] },
have : ∃(n:ℕ) y ε, 0 < ε ∧ ball y ε ⊆ closure (f '' (ball 0 n)) :=
nonempty_interior_of_Union_of_closed (λn, is_closed_closure) A,
rcases this with ⟨n, a, ε, ⟨εpos, H⟩⟩,
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
refine ⟨(ε/2)⁻¹ * ∥c∥ * 2 * n, _, λy, _⟩,
{ refine mul_nonneg (mul_nonneg (mul_nonneg _ (norm_nonneg _)) (by norm_num)) _,
refine inv_nonneg.2 (div_nonneg' (le_of_lt εpos) (by norm_num)),
exact nat.cast_nonneg n },
{ by_cases hy : y = 0,
{ use 0, simp [hy] },
{ rcases rescale_to_shell hc (half_pos εpos) hy with ⟨d, hd, ydle, leyd, dinv⟩,
let δ := ∥d∥ * ∥y∥/4,
have δpos : 0 < δ :=
div_pos (mul_pos (norm_pos_iff.2 hd) (norm_pos_iff.2 hy)) (by norm_num),
have : a + d • y ∈ ball a ε,
by simp [dist_eq_norm, lt_of_le_of_lt ydle (half_lt_self εpos)],
rcases metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₁, z₁im, h₁⟩,
rcases (mem_image _ _ _).1 z₁im with ⟨x₁, hx₁, xz₁⟩,
rw ← xz₁ at h₁,
rw [mem_ball, dist_eq_norm, sub_zero] at hx₁,
have : a ∈ ball a ε, by { simp, exact εpos },
rcases metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₂, z₂im, h₂⟩,
rcases (mem_image _ _ _).1 z₂im with ⟨x₂, hx₂, xz₂⟩,
rw ← xz₂ at h₂,
rw [mem_ball, dist_eq_norm, sub_zero] at hx₂,
let x := x₁ - x₂,
have I : ∥f x - d • y∥ ≤ 2 * δ := calc
∥f x - d • y∥ = ∥f x₁ - (a + d • y) - (f x₂ - a)∥ :
by { congr' 1, simp only [x, f.map_sub], abel }
... ≤ ∥f x₁ - (a + d • y)∥ + ∥f x₂ - a∥ :
norm_sub_le _ _
... ≤ δ + δ : begin
apply add_le_add,
{ rw [← dist_eq_norm, dist_comm], exact le_of_lt h₁ },
{ rw [← dist_eq_norm, dist_comm], exact le_of_lt h₂ }
end
... = 2 * δ : (two_mul _).symm,
have J : ∥f (d⁻¹ • x) - y∥ ≤ 1/2 * ∥y∥ := calc
∥f (d⁻¹ • x) - y∥ = ∥d⁻¹ • f x - (d⁻¹ * d) • y∥ :
by rwa [f.map_smul _, inv_mul_cancel, one_smul]
... = ∥d⁻¹ • (f x - d • y)∥ : by rw [mul_smul, smul_sub]
... = ∥d∥⁻¹ * ∥f x - d • y∥ : by rw [norm_smul, normed_field.norm_inv]
... ≤ ∥d∥⁻¹ * (2 * δ) : begin
apply mul_le_mul_of_nonneg_left I,
rw inv_nonneg,
exact norm_nonneg _
end
... = (∥d∥⁻¹ * ∥d∥) * ∥y∥ /2 : by { simp only [δ], ring }
... = ∥y∥/2 : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hd] }
... = (1/2) * ∥y∥ : by ring,
rw ← dist_eq_norm at J,
have 𝕜 : ∥d⁻¹ • x∥ ≤ (ε / 2)⁻¹ * ∥c∥ * 2 * ↑n * ∥y∥ := calc
∥d⁻¹ • x∥ = ∥d∥⁻¹ * ∥x₁ - x₂∥ : by rw [norm_smul, normed_field.norm_inv]
... ≤ ((ε / 2)⁻¹ * ∥c∥ * ∥y∥) * (n + n) : begin
refine mul_le_mul dinv _ (norm_nonneg _) _,
{ exact le_trans (norm_sub_le _ _) (add_le_add (le_of_lt hx₁) (le_of_lt hx₂)) },
{ apply mul_nonneg (mul_nonneg _ (norm_nonneg _)) (norm_nonneg _),
exact inv_nonneg.2 (le_of_lt (half_pos εpos)) }
end
... = (ε / 2)⁻¹ * ∥c∥ * 2 * ↑n * ∥y∥ : by ring,
exact ⟨d⁻¹ • x, J, 𝕜⟩ } },
end
variable [complete_space E]
/-- The Banach open mapping theorem: if a bounded linear map between Banach spaces is onto, then
any point has a preimage with controlled norm. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem exists_preimage_norm_le (surj : surjective f) :
∃C > 0, ∀y, ∃x, f x = y ∧ ∥x∥ ≤ C * ∥y∥ :=
begin
obtain ⟨C, C0, hC⟩ := exists_approx_preimage_norm_le f surj,
/- Second step of the proof: starting from `y`, we want an exact preimage of `y`. Let `g y` be
the approximate preimage of `y` given by the first step, and `h y = y - f(g y)` the part that
has no preimage yet. We will iterate this process, taking the approximate preimage of `h y`,
leaving only `h^2 y` without preimage yet, and so on. Let `u n` be the approximate preimage
of `h^n y`. Then `u` is a converging series, and by design the sum of the series is a
preimage of `y`. This uses completeness of `E`. -/
choose g hg using hC,
let h := λy, y - f (g y),
have hle : ∀y, ∥h y∥ ≤ (1/2) * ∥y∥,
{ assume y,
rw [← dist_eq_norm, dist_comm],
exact (hg y).1 },
refine ⟨2 * C + 1, by linarith, λy, _⟩,
have hnle : ∀n:ℕ, ∥(h^[n]) y∥ ≤ (1/2)^n * ∥y∥,
{ assume n,
induction n with n IH,
{ simp only [one_div_eq_inv, nat.nat_zero_eq_zero, one_mul, nat.iterate_zero, pow_zero] },
{ rw [nat.iterate_succ'],
apply le_trans (hle _) _,
rw [pow_succ, mul_assoc],
apply mul_le_mul_of_nonneg_left IH,
norm_num } },
let u := λn, g((h^[n]) y),
have ule : ∀n, ∥u n∥ ≤ (1/2)^n * (C * ∥y∥),
{ assume n,
apply le_trans (hg _).2 _,
calc C * ∥(h^[n]) y∥ ≤ C * ((1/2)^n * ∥y∥) : mul_le_mul_of_nonneg_left (hnle n) C0
... = (1 / 2) ^ n * (C * ∥y∥) : by ring },
have sNu : summable (λn, ∥u n∥),
{ refine summable_of_nonneg_of_le (λn, norm_nonneg _) ule _,
exact summable.mul_right _ (summable_geometric (by norm_num) (by norm_num)) },
have su : summable u := summable_of_summable_norm sNu,
let x := tsum u,
have x_ineq : ∥x∥ ≤ (2 * C + 1) * ∥y∥ := calc
∥x∥ ≤ (∑'n, ∥u n∥) : norm_tsum_le_tsum_norm sNu
... ≤ (∑'n, (1/2)^n * (C * ∥y∥)) :
tsum_le_tsum ule sNu (summable.mul_right _ summable_geometric_two)
... = (∑'n, (1/2)^n) * (C * ∥y∥) : by { rw tsum_mul_right, exact summable_geometric_two }
... = 2 * (C * ∥y∥) : by rw tsum_geometric_two
... = 2 * C * ∥y∥ + 0 : by rw [add_zero, mul_assoc]
... ≤ 2 * C * ∥y∥ + ∥y∥ : add_le_add (le_refl _) (norm_nonneg _)
... = (2 * C + 1) * ∥y∥ : by ring,
have fsumeq : ∀n:ℕ, f((finset.range n).sum u) = y - (h^[n]) y,
{ assume n,
induction n with n IH,
{ simp [f.map_zero] },
{ rw [sum_range_succ, f.map_add, IH, nat.iterate_succ'],
simp [u, h, sub_eq_add_neg, add_comm, add_left_comm] } },
have : tendsto (λn, (range n).sum u) at_top (𝓝 x) :=
su.has_sum.tendsto_sum_nat,
have L₁ : tendsto (λn, f((range n).sum u)) at_top (𝓝 (f x)) :=
(f.continuous.tendsto _).comp this,
simp only [fsumeq] at L₁,
have L₂ : tendsto (λn, y - (h^[n]) y) at_top (𝓝 (y - 0)),
{ refine tendsto_const_nhds.sub _,
rw tendsto_iff_norm_tendsto_zero,
simp only [sub_zero],
refine squeeze_zero (λ_, norm_nonneg _) hnle _,
have : 0 = 0 * ∥y∥, by rw zero_mul,
rw this,
refine tendsto.mul _ tendsto_const_nhds,
exact tendsto_pow_at_top_nhds_0_of_lt_1 (by norm_num) (by norm_num) },
have feq : f x = y - 0,
{ apply tendsto_nhds_unique _ L₁ L₂,
simp },
rw sub_zero at feq,
exact ⟨x, feq, x_ineq⟩
end
/-- The Banach open mapping theorem: a surjective bounded linear map between Banach spaces is open. -/
theorem open_mapping (surj : surjective f) : is_open_map f :=
begin
assume s hs,
rcases exists_preimage_norm_le f surj with ⟨C, Cpos, hC⟩,
refine is_open_iff.2 (λy yfs, _),
rcases mem_image_iff_bex.1 yfs with ⟨x, xs, fxy⟩,
rcases is_open_iff.1 hs x xs with ⟨ε, εpos, hε⟩,
refine ⟨ε/C, div_pos εpos Cpos, λz hz, _⟩,
rcases hC (z-y) with ⟨w, wim, wnorm⟩,
have : f (x + w) = z, by { rw [f.map_add, wim, fxy, add_sub_cancel'_right] },
rw ← this,
have : x + w ∈ ball x ε := calc
dist (x+w) x = ∥w∥ : by { rw dist_eq_norm, simp }
... ≤ C * ∥z - y∥ : wnorm
... < C * (ε/C) : begin
apply mul_lt_mul_of_pos_left _ Cpos,
rwa [mem_ball, dist_eq_norm] at hz,
end
... = ε : mul_div_cancel' _ (ne_of_gt Cpos),
exact set.mem_image_of_mem _ (hε this)
end
/-- If a bounded linear map is a bijection, then its inverse is also a bounded linear map. -/
theorem linear_equiv.continuous_symm (e : E ≃ₗ[𝕜] F) (h : continuous e) :
continuous e.symm :=
begin
obtain ⟨M, Mpos, hM⟩ : ∃ M > 0, ∀ (y : F), ∃ (x : E), e x = y ∧ ∥x∥ ≤ M * ∥y∥,
from exists_preimage_norm_le (continuous_linear_map.mk e.to_linear_map h) e.to_equiv.surjective,
refine e.symm.to_linear_map.continuous_of_bound M (λ y, _),
rcases hM y with ⟨x, hx, xnorm⟩,
convert xnorm,
rw ← hx,
apply e.symm_apply_apply
end
/-- Associating to a linear equivalence between Banach spaces a continuous linear equivalence when
the direct map is continuous, thanks to the Banach open mapping theorem that ensures that the
inverse map is also continuous. -/
def linear_equiv.to_continuous_linear_equiv_of_continuous (e : E ≃ₗ[𝕜] F) (h : continuous e) :
E ≃L[𝕜] F :=
{ continuous_to_fun := h,
continuous_inv_fun := e.continuous_symm h,
..e }
|
6dc25c64603590bde35ea52c4d2e4de53a106fb2 | 022215fec0be87ac6243b0f4fa3cc2939361d7d0 | /src/algebraic_geometry/stalks.lean | 5817a9b02506cc331b0cf1566e0befc50c6b67f1 | [
"Apache-2.0"
] | permissive | PaulGustafson/mathlib | 4aa7bc81ca971fdd7b6e50bf3a245fade2978391 | c49ac06ff9fa1371e9b6050a121df618cfd3fb80 | refs/heads/master | 1,590,798,947,521 | 1,559,220,227,000 | 1,559,220,227,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,912 | 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 algebraic_geometry.presheafed_space
import category_theory.instances.Top.stalks
universes v u v' u'
open category_theory
open category_theory.instances
open category_theory.limits
open algebraic_geometry
open topological_space
variables {C : Type u} [𝒞 : category.{v+1} C] [has_colimits.{v} C]
include 𝒞
local attribute [tidy] tactic.op_induction'
open category_theory.instances.Top.presheaf
namespace algebraic_geometry.PresheafedSpace
def stalk (X : PresheafedSpace.{v} C) (x : X) : C := X.𝒪.stalk x
def stalk_map {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) (x : X) : Y.stalk (α x) ⟶ X.stalk x :=
(stalk_functor C (α x)).map (α.c) ≫ X.𝒪.stalk_pushforward C α x
namespace stalk_map
@[simp] lemma id (X : PresheafedSpace.{v} C) (x : X) : stalk_map (𝟙 X) x = 𝟙 (X.stalk x) :=
begin
dsimp [stalk_map],
simp only [stalk_pushforward.id],
rw [←category_theory.functor.map_comp],
convert (stalk_functor C x).map_id X.𝒪,
tidy,
end
.
@[simp] lemma comp {X Y Z : PresheafedSpace.{v} C} (α : X ⟶ Y) (β : Y ⟶ Z) (x : X) :
stalk_map (α ≫ β) x =
(stalk_map β (α x) : Z.stalk (β (α x)) ⟶ Y.stalk (α x)) ≫
(stalk_map α x : Y.stalk (α x) ⟶ X.stalk x) :=
begin
dsimp [stalk, stalk_map, stalk_functor, stalk_pushforward, comp_c],
ext U,
op_induction U,
cases U,
cases U_val,
simp only [colim.ι_map_assoc, colimit.ι_pre_assoc, colimit.ι_pre,
whisker_left.app, whisker_right.app,
functor.map_comp, category.assoc, category_theory.functor.map_id, category.id_comp],
dsimp,
simp only [category_theory.functor.map_id],
-- FIXME Why doesn't simp do this:
erw [category.id_comp, category.id_comp],
end
end stalk_map
end algebraic_geometry.PresheafedSpace
|
bfd4ae682ae0a05bf8ee551f2dbbbbae3c3d80ad | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/pretty_cases_auto.lean | 2043e5f4de41ea96be6016a31b8a416f30b81627 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,955 | lean | /-
Copyright (c) 2020 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.core
import Mathlib.PostPort
namespace Mathlib
/-!
# `pretty_cases` tactic
When using `induction` and `cases`, `pretty_cases` prints a `"Try
this:"` advice that shows how to structure the proof with
`case { ... }` commands. In the following example, we apply induction on a
permutation assumption about lists. `pretty_cases` gives us a proof
skeleton that explicit selects the branches and explicit names the
new local constants:
```lean
example {α} (xs ys : list α) (h : xs ~ ys) : true :=
begin
induction h,
pretty_cases,
-- Try this:
-- case list.perm.nil :
-- { admit },
-- case list.perm.cons : h_x h_l₁ h_l₂ h_a h_ih
-- { admit },
-- case list.perm.swap : h_x h_y h_l
-- { admit },
-- case list.perm.trans : h_l₁ h_l₂ h_l₃ h_a h_a_1 h_ih_a h_ih_a_1
-- { admit },
end
```
## Main definitions
* `pretty_cases_advice` return `pretty_cases` advice without printing it
* `pretty_cases` main tactic
-/
namespace tactic
/-- Query the proof goal and print the skeleton of a proof by cases. -/
namespace interactive
/--
Query the proof goal and print the skeleton of a proof by
cases.
For example, let us consider the following proof:
```lean
example {α} (xs ys : list α) (h : xs ~ ys) : true :=
begin
induction h,
pretty_cases,
-- Try this:
-- case list.perm.nil :
-- { admit },
-- case list.perm.cons : h_x h_l₁ h_l₂ h_a h_ih
-- { admit },
-- case list.perm.swap : h_x h_y h_l
-- { admit },
-- case list.perm.trans : h_l₁ h_l₂ h_l₃ h_a h_a_1 h_ih_a h_ih_a_1
-- { admit },
end
```
The output helps the user layout the cases and rename the
introduced variables.
-/
end Mathlib |
199bb3c2e1b43e3fcb8580801481630514745961 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/import_open_locale2.lean | 5ba9958a3b9d45a6b70a4021c49aaa7fdc4fee5b | [
"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 | 51 | lean | import .import_open_locale1
open_locale classical
|
a0cf821c20a2d1bca4a85b70bb8f40731179cda1 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /src/Lean/LocalContext.lean | 36ca832586b31cf53c4e078ca942e98a173fbbe0 | [
"Apache-2.0"
] | permissive | WojciechKarpiel/lean4 | 7f89706b8e3c1f942b83a2c91a3a00b05da0e65b | f6e1314fa08293dea66a329e05b6c196a0189163 | refs/heads/master | 1,686,633,402,214 | 1,625,821,189,000 | 1,625,821,258,000 | 384,640,886 | 0 | 0 | Apache-2.0 | 1,625,903,617,000 | 1,625,903,026,000 | null | UTF-8 | Lean | false | false | 15,087 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Std.Data.PersistentArray
import Lean.Expr
import Lean.Hygiene
namespace Lean
inductive LocalDecl where
| cdecl (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo)
| ldecl (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (value : Expr) (nonDep : Bool)
deriving Inhabited
@[export lean_mk_local_decl]
def mkLocalDeclEx (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo) : LocalDecl :=
LocalDecl.cdecl index fvarId userName type bi
@[export lean_mk_let_decl]
def mkLetDeclEx (index : Nat) (fvarId : FVarId) (userName : Name) (type : Expr) (val : Expr) : LocalDecl :=
LocalDecl.ldecl index fvarId userName type val false
@[export lean_local_decl_binder_info]
def LocalDecl.binderInfoEx : LocalDecl → BinderInfo
| LocalDecl.cdecl _ _ _ _ bi => bi
| _ => BinderInfo.default
namespace LocalDecl
def isLet : LocalDecl → Bool
| cdecl .. => false
| ldecl .. => true
def index : LocalDecl → Nat
| cdecl (index := i) .. => i
| ldecl (index := i) .. => i
def setIndex : LocalDecl → Nat → LocalDecl
| cdecl _ id n t bi, idx => cdecl idx id n t bi
| ldecl _ id n t v nd, idx => ldecl idx id n t v nd
def fvarId : LocalDecl → FVarId
| cdecl (fvarId := id) .. => id
| ldecl (fvarId := id) .. => id
def userName : LocalDecl → Name
| cdecl (userName := n) .. => n
| ldecl (userName := n) .. => n
def type : LocalDecl → Expr
| cdecl (type := t) .. => t
| ldecl (type := t) .. => t
def setType : LocalDecl → Expr → LocalDecl
| cdecl idx id n _ bi, t => cdecl idx id n t bi
| ldecl idx id n _ v nd, t => ldecl idx id n t v nd
def binderInfo : LocalDecl → BinderInfo
| cdecl (bi := bi) .. => bi
| ldecl .. => BinderInfo.default
def isAuxDecl (d : LocalDecl) : Bool :=
d.binderInfo.isAuxDecl
def value? : LocalDecl → Option Expr
| cdecl .. => none
| ldecl (value := v) .. => some v
def value : LocalDecl → Expr
| cdecl .. => panic! "let declaration expected"
| ldecl (value := v) .. => v
def hasValue : LocalDecl → Bool
| cdecl .. => false
| ldecl .. => true
def setValue : LocalDecl → Expr → LocalDecl
| ldecl idx id n t _ nd, v => ldecl idx id n t v nd
| d, _ => d
def setUserName : LocalDecl → Name → LocalDecl
| cdecl index id _ type bi, userName => cdecl index id userName type bi
| ldecl index id _ type val nd, userName => ldecl index id userName type val nd
def setBinderInfo : LocalDecl → BinderInfo → LocalDecl
| cdecl index id n type _, bi => cdecl index id n type bi
| ldecl .., _ => panic! "unexpected let declaration"
def toExpr (decl : LocalDecl) : Expr :=
mkFVar decl.fvarId
def hasExprMVar : LocalDecl → Bool
| cdecl (type := t) .. => t.hasExprMVar
| ldecl (type := t) (value := v) .. => t.hasExprMVar || v.hasExprMVar
end LocalDecl
open Std (PersistentHashMap PersistentArray PArray)
structure LocalContext where
fvarIdToDecl : PersistentHashMap FVarId LocalDecl := {}
decls : PersistentArray (Option LocalDecl) := {}
deriving Inhabited
namespace LocalContext
@[export lean_mk_empty_local_ctx]
def mkEmpty : Unit → LocalContext := fun _ => {}
def empty : LocalContext := {}
@[export lean_local_ctx_is_empty]
def isEmpty (lctx : LocalContext) : Bool :=
lctx.fvarIdToDecl.isEmpty
/- Low level API for creating local declarations. It is used to implement actions in the monads `Elab` and `Tactic`. It should not be used directly since the argument `(name : Name)` is assumed to be "unique". -/
@[export lean_local_ctx_mk_local_decl]
def mkLocalDecl (lctx : LocalContext) (fvarId : FVarId) (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
let idx := decls.size
let decl := LocalDecl.cdecl idx fvarId userName type bi
{ fvarIdToDecl := map.insert fvarId decl, decls := decls.push decl }
@[export lean_local_ctx_mk_let_decl]
def mkLetDecl (lctx : LocalContext) (fvarId : FVarId) (userName : Name) (type : Expr) (value : Expr) (nonDep := false) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
let idx := decls.size
let decl := LocalDecl.ldecl idx fvarId userName type value nonDep
{ fvarIdToDecl := map.insert fvarId decl, decls := decls.push decl }
/- Low level API -/
def addDecl (lctx : LocalContext) (newDecl : LocalDecl) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
let idx := decls.size
let newDecl := newDecl.setIndex idx
{ fvarIdToDecl := map.insert newDecl.fvarId newDecl, decls := decls.push newDecl }
@[export lean_local_ctx_find]
def find? (lctx : LocalContext) (fvarId : FVarId) : Option LocalDecl :=
lctx.fvarIdToDecl.find? fvarId
def findFVar? (lctx : LocalContext) (e : Expr) : Option LocalDecl :=
lctx.find? e.fvarId!
def get! (lctx : LocalContext) (fvarId : FVarId) : LocalDecl :=
match lctx.find? fvarId with
| some d => d
| none => panic! "unknown free variable"
def getFVar! (lctx : LocalContext) (e : Expr) : LocalDecl :=
lctx.get! e.fvarId!
def contains (lctx : LocalContext) (fvarId : FVarId) : Bool :=
lctx.fvarIdToDecl.contains fvarId
def containsFVar (lctx : LocalContext) (e : Expr) : Bool :=
lctx.contains e.fvarId!
def getFVarIds (lctx : LocalContext) : Array FVarId :=
lctx.decls.foldl (init := #[]) fun r decl? => match decl? with
| some decl => r.push decl.fvarId
| none => r
def getFVars (lctx : LocalContext) : Array Expr :=
lctx.getFVarIds.map mkFVar
private partial def popTailNoneAux (a : PArray (Option LocalDecl)) : PArray (Option LocalDecl) :=
if a.size == 0 then a
else match a.get! (a.size - 1) with
| none => popTailNoneAux a.pop
| some _ => a
@[export lean_local_ctx_erase]
def erase (lctx : LocalContext) (fvarId : FVarId) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
match map.find? fvarId with
| none => lctx
| some decl => { fvarIdToDecl := map.erase fvarId, decls := popTailNoneAux (decls.set decl.index none) }
@[export lean_local_ctx_pop]
def pop (lctx : LocalContext): LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
if decls.size == 0 then lctx
else match decls.get! (decls.size - 1) with
| none => lctx -- unreachable
| some decl => { fvarIdToDecl := map.erase decl.fvarId, decls := popTailNoneAux decls.pop }
@[export lean_local_ctx_find_from_user_name]
def findFromUserName? (lctx : LocalContext) (userName : Name) : Option LocalDecl :=
lctx.decls.findSomeRev? fun decl =>
match decl with
| none => none
| some decl => if decl.userName == userName then some decl else none
@[export lean_local_ctx_uses_user_name]
def usesUserName (lctx : LocalContext) (userName : Name) : Bool :=
(lctx.findFromUserName? userName).isSome
private partial def getUnusedNameAux (lctx : LocalContext) (suggestion : Name) (i : Nat) : Name × Nat :=
let curr := suggestion.appendIndexAfter i
if lctx.usesUserName curr then getUnusedNameAux lctx suggestion (i + 1)
else (curr, i + 1)
@[export lean_local_ctx_get_unused_name]
def getUnusedName (lctx : LocalContext) (suggestion : Name) : Name :=
let suggestion := suggestion.eraseMacroScopes
if lctx.usesUserName suggestion then (getUnusedNameAux lctx suggestion 1).1
else suggestion
@[export lean_local_ctx_last_decl]
def lastDecl (lctx : LocalContext) : Option LocalDecl :=
lctx.decls.get! (lctx.decls.size - 1)
def setUserName (lctx : LocalContext) (fvarId : FVarId) (userName : Name) : LocalContext :=
let decl := lctx.get! fvarId
let decl := decl.setUserName userName
{ fvarIdToDecl := lctx.fvarIdToDecl.insert decl.fvarId decl,
decls := lctx.decls.set decl.index decl }
@[export lean_local_ctx_rename_user_name]
def renameUserName (lctx : LocalContext) (fromName : Name) (toName : Name) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
match lctx.findFromUserName? fromName with
| none => lctx
| some decl =>
let decl := decl.setUserName toName;
{ fvarIdToDecl := map.insert decl.fvarId decl,
decls := decls.set decl.index decl }
/--
Low-level function for updating the local context.
Assumptions about `f`, the resulting nested expressions must be definitionally equal to their original values,
the `index` nor `fvarId` are modified. -/
@[inline] def modifyLocalDecl (lctx : LocalContext) (fvarId : FVarId) (f : LocalDecl → LocalDecl) : LocalContext :=
match lctx with
| { fvarIdToDecl := map, decls := decls } =>
match lctx.find? fvarId with
| none => lctx
| some decl =>
let decl := f decl;
{ fvarIdToDecl := map.insert decl.fvarId decl,
decls := decls.set decl.index decl }
def setBinderInfo (lctx : LocalContext) (fvarId : FVarId) (bi : BinderInfo) : LocalContext :=
modifyLocalDecl lctx fvarId fun decl => decl.setBinderInfo bi
@[export lean_local_ctx_num_indices]
def numIndices (lctx : LocalContext) : Nat :=
lctx.decls.size
@[export lean_local_ctx_get]
def getAt? (lctx : LocalContext) (i : Nat) : Option LocalDecl :=
lctx.decls.get! i
section
universe u v
variable {m : Type u → Type v} [Monad m]
variable {β : Type u}
@[specialize] def foldlM (lctx : LocalContext) (f : β → LocalDecl → m β) (init : β) (start : Nat := 0) : m β :=
lctx.decls.foldlM (init := init) (start := start) fun b decl => match decl with
| none => pure b
| some decl => f b decl
@[specialize] def forM (lctx : LocalContext) (f : LocalDecl → m PUnit) : m PUnit :=
lctx.decls.forM fun decl => match decl with
| none => pure PUnit.unit
| some decl => f decl
@[specialize] def findDeclM? (lctx : LocalContext) (f : LocalDecl → m (Option β)) : m (Option β) :=
lctx.decls.findSomeM? fun decl => match decl with
| none => pure none
| some decl => f decl
@[specialize] def findDeclRevM? (lctx : LocalContext) (f : LocalDecl → m (Option β)) : m (Option β) :=
lctx.decls.findSomeRevM? fun decl => match decl with
| none => pure none
| some decl => f decl
instance : ForIn m LocalContext LocalDecl where
forIn lctx init f := lctx.decls.forIn init fun d? b => match d? with
| none => ForInStep.yield b
| some d => f d b
end
@[inline] def foldl {β} (lctx : LocalContext) (f : β → LocalDecl → β) (init : β) (start : Nat := 0) : β :=
Id.run <| lctx.foldlM f init start
@[inline] def findDecl? {β} (lctx : LocalContext) (f : LocalDecl → Option β) : Option β :=
Id.run <| lctx.findDeclM? f
@[inline] def findDeclRev? {β} (lctx : LocalContext) (f : LocalDecl → Option β) : Option β :=
Id.run <| lctx.findDeclRevM? f
partial def isSubPrefixOfAux (a₁ a₂ : PArray (Option LocalDecl)) (exceptFVars : Array Expr) (i j : Nat) : Bool :=
if i < a₁.size then
match a₁[i] with
| none => isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) j
| some decl₁ =>
if exceptFVars.any fun fvar => fvar.fvarId! == decl₁.fvarId then
isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) j
else if j < a₂.size then
match a₂[j] with
| none => isSubPrefixOfAux a₁ a₂ exceptFVars i (j+1)
| some decl₂ => if decl₁.fvarId == decl₂.fvarId then isSubPrefixOfAux a₁ a₂ exceptFVars (i+1) (j+1) else isSubPrefixOfAux a₁ a₂ exceptFVars i (j+1)
else false
else true
/- Given `lctx₁ - exceptFVars` of the form `(x_1 : A_1) ... (x_n : A_n)`, then return true
iff there is a local context `B_1* (x_1 : A_1) ... B_n* (x_n : A_n)` which is a prefix
of `lctx₂` where `B_i`'s are (possibly empty) sequences of local declarations. -/
def isSubPrefixOf (lctx₁ lctx₂ : LocalContext) (exceptFVars : Array Expr := #[]) : Bool :=
isSubPrefixOfAux lctx₁.decls lctx₂.decls exceptFVars 0 0
@[inline] def mkBinding (isLambda : Bool) (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr :=
let b := b.abstract xs
xs.size.foldRev (init := b) fun i b =>
let x := xs[i]
match lctx.findFVar? x with
| some (LocalDecl.cdecl _ _ n ty bi) =>
let ty := ty.abstractRange i xs;
if isLambda then
Lean.mkLambda n bi ty b
else
Lean.mkForall n bi ty b
| some (LocalDecl.ldecl _ _ n ty val nonDep) =>
if b.hasLooseBVar 0 then
let ty := ty.abstractRange i xs
let val := val.abstractRange i xs
mkLet n ty val b nonDep
else
b.lowerLooseBVars 1 1
| none => panic! "unknown free variable"
def mkLambda (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr :=
mkBinding true lctx xs b
def mkForall (lctx : LocalContext) (xs : Array Expr) (b : Expr) : Expr :=
mkBinding false lctx xs b
section
universe u
variable {m : Type → Type u} [Monad m]
@[inline] def anyM (lctx : LocalContext) (p : LocalDecl → m Bool) : m Bool :=
lctx.decls.anyM fun d => match d with
| some decl => p decl
| none => pure false
@[inline] def allM (lctx : LocalContext) (p : LocalDecl → m Bool) : m Bool :=
lctx.decls.allM fun d => match d with
| some decl => p decl
| none => pure true
end
@[inline] def any (lctx : LocalContext) (p : LocalDecl → Bool) : Bool :=
Id.run <| lctx.anyM p
@[inline] def all (lctx : LocalContext) (p : LocalDecl → Bool) : Bool :=
Id.run <| lctx.allM p
def sanitizeNames (lctx : LocalContext) : StateM NameSanitizerState LocalContext := do
let st ← get
if !getSanitizeNames st.options then pure lctx else
StateT.run' (s := ({} : NameSet)) <|
lctx.decls.size.foldRevM (init := lctx) fun i lctx => do
match lctx.decls[i] with
| none => pure lctx
| some decl =>
if decl.userName.hasMacroScopes || (← get).contains decl.userName then do
modify fun s => s.insert decl.userName
let userNameNew ← liftM <| sanitizeName decl.userName
pure <| lctx.setUserName decl.fvarId userNameNew
else
modify fun s => s.insert decl.userName
pure lctx
end LocalContext
class MonadLCtx (m : Type → Type) where
getLCtx : m LocalContext
export MonadLCtx (getLCtx)
instance (m n) [MonadLift m n] [MonadLCtx m] : MonadLCtx n where
getLCtx := liftM (getLCtx : m _)
def replaceFVarIdAtLocalDecl (fvarId : FVarId) (e : Expr) (d : LocalDecl) : LocalDecl :=
if d.fvarId == fvarId then d
else match d with
| LocalDecl.cdecl idx id n type bi => LocalDecl.cdecl idx id n (type.replaceFVarId fvarId e) bi
| LocalDecl.ldecl idx id n type val nonDep => LocalDecl.ldecl idx id n (type.replaceFVarId fvarId e) (val.replaceFVarId fvarId e) nonDep
end Lean
|
adef3c1b4f034c34b92f2c348c24158c225fec69 | aa5a655c05e5359a70646b7154e7cac59f0b4132 | /tests/lean/derivingRepr.lean | 597bfae37a89ecaf68cfa30afa5f6ccaf2294dfb | [
"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 | 843 | lean | structure Foo where
name : String
val : List Nat
lower : Nat := List.length val
inv : val.length >= lower
flag : Bool
deriving Repr
#eval { name := "Joe", val := List.iota 40, flag := true, inv := by decide! : Foo }
inductive Tree (α : Type) where
| node : List (Tree α) → Bool → Tree α
| leaf : α → Tree α
deriving Repr
#eval Tree.node (List.iota 10 |>.map fun i => Tree.node [Tree.leaf i] (i%2==0)) true
namespace Foo
mutual
inductive Tree (α : Type u) where
| node : TreeList α → Tree α
| leaf : α → Tree α
deriving Repr
inductive TreeList (α : Type u) where
| nil : TreeList α
| cons : Tree α → TreeList α → TreeList α
deriving Repr
end
#eval Tree.node (TreeList.cons (Tree.leaf 30) (TreeList.cons (Tree.leaf 20) (TreeList.cons (Tree.leaf 10) TreeList.nil)))
end Foo
|
10ff151250670845604799faf380f9c102e9af47 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/IO2.lean | a9f6d726a50067e3be83c3340e3c75037fef5407 | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 380 | lean | import system.IO
open list
/- B and unit must be in the same universe
So, we must put B at Type₁ or use poly_unit
since unit is at Type₁
-/
definition for {A : Type} {B : Type} : list A → (A → IO B) → IO poly_unit
| [] f := return poly_unit.star
| (x::xs) f := do f x, for xs f
vm_eval for [1,2,3,4,5] (λ i, do put_str "value: ", put_nat i, put_str "\n")
|
3f5bd535471d5a622df68a44a9abb58742cb0c61 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/computability/halting.lean | 8264fea17b01f669dd01da1a280a7136b2f0fe91 | [
"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 | 14,356 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import computability.partrec_code
/-!
# Computability theory and the halting problem
A universal partial recursive function, Rice's theorem, and the halting problem.
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open encodable denumerable
namespace nat.partrec
open computable part
theorem merge' {f g}
(hf : nat.partrec f) (hg : nat.partrec g) :
∃ h, nat.partrec h ∧ ∀ a,
(∀ x ∈ h a, x ∈ f a ∨ x ∈ g a) ∧
((h a).dom ↔ (f a).dom ∨ (g a).dom) :=
begin
obtain ⟨cf, rfl⟩ := code.exists_code.1 hf,
obtain ⟨cg, rfl⟩ := code.exists_code.1 hg,
have : nat.partrec (λ n,
(nat.rfind_opt (λ k, cf.evaln k n <|> cg.evaln k n))) :=
partrec.nat_iff.1 (partrec.rfind_opt $
primrec.option_orelse.to_comp.comp
(code.evaln_prim.to_comp.comp $ (snd.pair (const cf)).pair fst)
(code.evaln_prim.to_comp.comp $ (snd.pair (const cg)).pair fst)),
refine ⟨_, this, λ n, _⟩,
suffices, refine ⟨this,
⟨λ h, (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, _⟩⟩,
{ intro h, rw nat.rfind_opt_dom,
simp only [dom_iff_mem, code.evaln_complete, option.mem_def] at h,
obtain ⟨x, k, e⟩ | ⟨x, k, e⟩ := h,
{ refine ⟨k, x, _⟩, simp only [e, option.some_orelse, option.mem_def] },
{ refine ⟨k, _⟩,
cases cf.evaln k n with y,
{ exact ⟨x, by simp only [e, option.mem_def, option.none_orelse]⟩ },
{ exact ⟨y, by simp only [option.some_orelse, option.mem_def]⟩ } } },
intros x h,
obtain ⟨k, e⟩ := nat.rfind_opt_spec h,
revert e,
simp only [option.mem_def]; cases e' : cf.evaln k n with y; simp; intro,
{ exact or.inr (code.evaln_sound e) },
{ subst y,
exact or.inl (code.evaln_sound e') }
end
end nat.partrec
namespace partrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
open computable part nat.partrec (code) nat.partrec.code
theorem merge' {f g : α →. σ}
(hf : partrec f) (hg : partrec g) :
∃ k : α →. σ, partrec k ∧ ∀ a,
(∀ x ∈ k a, x ∈ f a ∨ x ∈ g a) ∧
((k a).dom ↔ (f a).dom ∨ (g a).dom) :=
let ⟨k, hk, H⟩ :=
nat.partrec.merge' (bind_decode₂_iff.1 hf) (bind_decode₂_iff.1 hg) in
begin
let k' := λ a, (k (encode a)).bind (λ n, decode σ n),
refine ⟨k', ((nat_iff.2 hk).comp computable.encode).bind
(computable.decode.of_option.comp snd).to₂, λ a, _⟩,
suffices, refine ⟨this,
⟨λ h, (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, _⟩⟩,
{ intro h,
rw bind_dom,
have hk : (k (encode a)).dom :=
(H _).2.2 (by simpa only [encodek₂, bind_some, coe_some] using h),
existsi hk,
simp only [exists_prop, mem_map_iff, mem_coe, mem_bind_iff, option.mem_def] at H,
obtain ⟨a', ha', y, hy, e⟩ | ⟨a', ha', y, hy, e⟩ := (H _).1 _ ⟨hk, rfl⟩;
{ simp only [e.symm, encodek] } },
intros x h', simp only [k', exists_prop, mem_coe, mem_bind_iff, option.mem_def] at h',
obtain ⟨n, hn, hx⟩ := h',
have := (H _).1 _ hn,
simp [mem_decode₂, encode_injective.eq_iff] at this,
obtain ⟨a', ha, rfl⟩ | ⟨a', ha, rfl⟩ := this; simp only [encodek] at hx; rw hx at ha,
{ exact or.inl ha },
exact or.inr ha
end
theorem merge {f g : α →. σ}
(hf : partrec f) (hg : partrec g)
(H : ∀ a (x ∈ f a) (y ∈ g a), x = y) :
∃ k : α →. σ, partrec k ∧ ∀ a x, x ∈ k a ↔ x ∈ f a ∨ x ∈ g a :=
let ⟨k, hk, K⟩ := merge' hf hg in
⟨k, hk, λ a x, ⟨(K _).1 _, λ h, begin
have : (k a).dom := (K _).2.2 (h.imp Exists.fst Exists.fst),
refine ⟨this, _⟩,
cases h with h h; cases (K _).1 _ ⟨this, rfl⟩ with h' h',
{ exact mem_unique h' h },
{ exact (H _ _ h _ h').symm },
{ exact H _ _ h' _ h },
{ exact mem_unique h' h }
end⟩⟩
theorem cond {c : α → bool} {f : α →. σ} {g : α →. σ}
(hc : computable c) (hf : partrec f) (hg : partrec g) :
partrec (λ a, cond (c a) (f a) (g a)) :=
let ⟨cf, ef⟩ := exists_code.1 hf,
⟨cg, eg⟩ := exists_code.1 hg in
((eval_part.comp
(computable.cond hc (const cf) (const cg)) computable.id).bind
((@computable.decode σ _).comp snd).of_option.to₂).of_eq $
λ a, by cases c a; simp [ef, eg, encodek]
theorem sum_cases
{f : α → β ⊕ γ} {g : α → β →. σ} {h : α → γ →. σ}
(hf : computable f) (hg : partrec₂ g) (hh : partrec₂ h) :
@partrec _ σ _ _ (λ a, sum.cases_on (f a) (g a) (h a)) :=
option_some_iff.1 $ (cond
(sum_cases hf (const tt).to₂ (const ff).to₂)
(sum_cases_left hf (option_some_iff.2 hg).to₂ (const option.none).to₂)
(sum_cases_right hf (const option.none).to₂ (option_some_iff.2 hh).to₂))
.of_eq $ λ a, by cases f a; simp only [bool.cond_tt, bool.cond_ff]
end partrec
/-- A computable predicate is one whose indicator function is computable. -/
def computable_pred {α} [primcodable α] (p : α → Prop) :=
∃ [D : decidable_pred p],
by exactI computable (λ a, to_bool (p a))
/-- A recursively enumerable predicate is one which is the domain of a computable partial function.
-/
def re_pred {α} [primcodable α] (p : α → Prop) :=
partrec (λ a, part.assert (p a) (λ _, part.some ()))
theorem computable_pred.of_eq {α} [primcodable α]
{p q : α → Prop}
(hp : computable_pred p) (H : ∀ a, p a ↔ q a) : computable_pred q :=
(funext (λ a, propext (H a)) : p = q) ▸ hp
namespace computable_pred
variables {α : Type*} {σ : Type*}
variables [primcodable α] [primcodable σ]
open nat.partrec (code) nat.partrec.code computable
theorem computable_iff {p : α → Prop} :
computable_pred p ↔ ∃ f : α → bool, computable f ∧ p = λ a, f a :=
⟨λ ⟨D, h⟩, by exactI ⟨_, h, funext $ λ a, propext (to_bool_iff _).symm⟩,
by rintro ⟨f, h, rfl⟩; exact ⟨by apply_instance, by simpa using h⟩⟩
protected theorem not {p : α → Prop}
(hp : computable_pred p) : computable_pred (λ a, ¬ p a) :=
by obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp; exact
⟨by apply_instance,
(cond hf (const ff) (const tt)).of_eq
(λ n, by {dsimp, cases f n; refl})⟩
theorem to_re {p : α → Prop} (hp : computable_pred p) : re_pred p :=
begin
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp,
unfold re_pred,
refine (partrec.cond hf (decidable.partrec.const' (part.some ())) partrec.none).of_eq
(λ n, part.ext $ λ a, _),
cases a, cases f n; simp
end
theorem rice (C : set (ℕ →. ℕ))
(h : computable_pred (λ c, eval c ∈ C))
{f g} (hf : nat.partrec f) (hg : nat.partrec g)
(fC : f ∈ C) : g ∈ C :=
begin
cases h with _ h, resetI,
obtain ⟨c, e⟩ := fixed_point₂ (partrec.cond (h.comp fst)
((partrec.nat_iff.2 hg).comp snd).to₂
((partrec.nat_iff.2 hf).comp snd).to₂).to₂,
simp at e,
by_cases H : eval c ∈ C,
{ simp only [H, if_true] at e, rwa ← e },
{ simp only [H, if_false] at e,
rw e at H, contradiction }
end
theorem rice₂ (C : set code)
(H : ∀ cf cg, eval cf = eval cg → (cf ∈ C ↔ cg ∈ C)) :
computable_pred (λ c, c ∈ C) ↔ C = ∅ ∨ C = set.univ :=
by classical; exact
have hC : ∀ f, f ∈ C ↔ eval f ∈ eval '' C,
from λ f, ⟨set.mem_image_of_mem _, λ ⟨g, hg, e⟩, (H _ _ e).1 hg⟩,
⟨λ h, or_iff_not_imp_left.2 $ λ C0,
set.eq_univ_of_forall $ λ cg,
let ⟨cf, fC⟩ := set.ne_empty_iff_nonempty.1 C0 in
(hC _).2 $ rice (eval '' C) (h.of_eq hC)
(partrec.nat_iff.1 $ eval_part.comp (const cf) computable.id)
(partrec.nat_iff.1 $ eval_part.comp (const cg) computable.id)
((hC _).1 fC),
λ h, by obtain rfl | rfl := h; simp [computable_pred, set.mem_empty_eq];
exact ⟨by apply_instance, computable.const _⟩⟩
theorem halting_problem (n) : ¬ computable_pred (λ c, (eval c n).dom)
| h := rice {f | (f n).dom} h nat.partrec.zero nat.partrec.none trivial
-- Post's theorem on the equivalence of r.e., co-r.e. sets and
-- computable sets. The assumption that p is decidable is required
-- unless we assume Markov's principle or LEM.
@[nolint decidable_classical]
theorem computable_iff_re_compl_re {p : α → Prop} [decidable_pred p] :
computable_pred p ↔ re_pred p ∧ re_pred (λ a, ¬ p a) :=
⟨λ h, ⟨h.to_re, h.not.to_re⟩, λ ⟨h₁, h₂⟩, ⟨‹_›, begin
obtain ⟨k, pk, hk⟩ := partrec.merge
(h₁.map (computable.const tt).to₂)
(h₂.map (computable.const ff).to₂) _,
{ refine partrec.of_eq pk (λ n, part.eq_some_iff.2 _),
rw hk, simp, apply decidable.em },
{ intros a x hx y hy, simp at hx hy, cases hy.1 hx.1 }
end⟩⟩
end computable_pred
namespace nat
open vector part
/-- A simplified basis for `partrec`. -/
inductive partrec' : ∀ {n}, (vector ℕ n →. ℕ) → Prop
| prim {n f} : @primrec' n f → @partrec' n f
| comp {m n f} (g : fin n → vector ℕ m →. ℕ) :
partrec' f → (∀ i, partrec' (g i)) →
partrec' (λ v, m_of_fn (λ i, g i v) >>= f)
| rfind {n} {f : vector ℕ (n+1) → ℕ} : @partrec' (n+1) f →
partrec' (λ v, rfind (λ n, some (f (n ::ᵥ v) = 0)))
end nat
namespace nat.partrec'
open vector partrec computable nat (partrec') nat.partrec'
theorem to_part {n f} (pf : @partrec' n f) : partrec f :=
begin
induction pf,
case nat.partrec'.prim : n f hf { exact hf.to_prim.to_comp },
case nat.partrec'.comp : m n f g _ _ hf hg {
exact (vector_m_of_fn (λ i, hg i)).bind (hf.comp snd) },
case nat.partrec'.rfind : n f _ hf {
have := ((primrec.eq.comp primrec.id (primrec.const 0)).to_comp.comp
(hf.comp (vector_cons.comp snd fst))).to₂.partrec₂,
exact this.rfind },
end
theorem of_eq {n} {f g : vector ℕ n →. ℕ}
(hf : partrec' f) (H : ∀ i, f i = g i) : partrec' g :=
(funext H : f = g) ▸ hf
theorem of_prim {n} {f : vector ℕ n → ℕ} (hf : primrec f) : @partrec' n f :=
prim (nat.primrec'.of_prim hf)
theorem head {n : ℕ} : @partrec' n.succ (@head ℕ n) :=
prim nat.primrec'.head
theorem tail {n f} (hf : @partrec' n f) : @partrec' n.succ (λ v, f v.tail) :=
(hf.comp _ (λ i, @prim _ _ $ nat.primrec'.nth i.succ)).of_eq $
λ v, by simp; rw [← of_fn_nth v.tail]; congr; funext i; simp
protected theorem bind {n f g}
(hf : @partrec' n f) (hg : @partrec' (n+1) g) :
@partrec' n (λ v, (f v).bind (λ a, g (a ::ᵥ v))) :=
(@comp n (n+1) g
(λ i, fin.cases f (λ i v, some (v.nth i)) i) hg
(λ i, begin
refine fin.cases _ (λ i, _) i; simp *,
exact prim (nat.primrec'.nth _)
end)).of_eq $
λ v, by simp [m_of_fn, part.bind_assoc, pure]
protected theorem map {n f} {g : vector ℕ (n+1) → ℕ}
(hf : @partrec' n f) (hg : @partrec' (n+1) g) :
@partrec' n (λ v, (f v).map (λ a, g (a ::ᵥ v))) :=
by simp [(part.bind_some_eq_map _ _).symm];
exact hf.bind hg
/-- Analogous to `nat.partrec'` for `ℕ`-valued functions, a predicate for partial recursive
vector-valued functions.-/
def vec {n m} (f : vector ℕ n → vector ℕ m) :=
∀ i, partrec' (λ v, (f v).nth i)
theorem vec.prim {n m f} (hf : @nat.primrec'.vec n m f) : vec f :=
λ i, prim $ hf i
protected theorem nil {n} : @vec n 0 (λ _, nil) := λ i, i.elim0
protected theorem cons {n m} {f : vector ℕ n → ℕ} {g}
(hf : @partrec' n f) (hg : @vec n m g) :
vec (λ v, f v ::ᵥ g v) :=
λ i, fin.cases (by simp *) (λ i, by simp only [hg i, nth_cons_succ]) i
theorem idv {n} : @vec n n id := vec.prim nat.primrec'.idv
theorem comp' {n m f g} (hf : @partrec' m f) (hg : @vec n m g) :
partrec' (λ v, f (g v)) :=
(hf.comp _ hg).of_eq $ λ v, by simp
theorem comp₁ {n} (f : ℕ →. ℕ) {g : vector ℕ n → ℕ}
(hf : @partrec' 1 (λ v, f v.head)) (hg : @partrec' n g) :
@partrec' n (λ v, f (g v)) :=
by simpa using hf.comp' (partrec'.cons hg partrec'.nil)
theorem rfind_opt {n} {f : vector ℕ (n+1) → ℕ}
(hf : @partrec' (n+1) f) :
@partrec' n (λ v, nat.rfind_opt (λ a, of_nat (option ℕ) (f (a ::ᵥ v)))) :=
((rfind $ (of_prim (primrec.nat_sub.comp (primrec.const 1) primrec.vector_head))
.comp₁ (λ n, part.some (1 - n)) hf)
.bind ((prim nat.primrec'.pred).comp₁ nat.pred hf)).of_eq $
λ v, part.ext $ λ b, begin
simp only [nat.rfind_opt, exists_prop, tsub_eq_zero_iff_le, pfun.coe_val,
part.mem_bind_iff, part.mem_some_iff, option.mem_def, part.mem_coe],
refine exists_congr (λ a,
(and_congr (iff_of_eq _) iff.rfl).trans (and_congr_right (λ h, _))),
{ congr, funext n,
simp only [part.some_inj, pfun.coe_val], cases f (n ::ᵥ v); simp [nat.succ_le_succ]; refl },
{ have := nat.rfind_spec h,
simp only [pfun.coe_val, part.mem_some_iff] at this,
cases f (a ::ᵥ v) with c, {cases this},
rw [← option.some_inj, eq_comm], refl }
end
open nat.partrec.code
theorem of_part : ∀ {n f}, partrec f → @partrec' n f :=
suffices ∀ f, nat.partrec f → @partrec' 1 (λ v, f v.head), from
λ n f hf, begin
let g, swap,
exact (comp₁ g (this g hf) (prim nat.primrec'.encode)).of_eq
(λ i, by dsimp only [g]; simp [encodek, part.map_id']),
end,
λ f hf, begin
obtain ⟨c, rfl⟩ := exists_code.1 hf,
simpa [eval_eq_rfind_opt] using
(rfind_opt $ of_prim $ primrec.encode_iff.2 $ evaln_prim.comp $
(primrec.vector_head.pair (primrec.const c)).pair $
primrec.vector_head.comp primrec.vector_tail)
end
theorem part_iff {n f} : @partrec' n f ↔ partrec f := ⟨to_part, of_part⟩
theorem part_iff₁ {f : ℕ →. ℕ} :
@partrec' 1 (λ v, f v.head) ↔ partrec f :=
part_iff.trans ⟨
λ h, (h.comp $ (primrec.vector_of_fn $
λ i, primrec.id).to_comp).of_eq (λ v, by simp only [id.def, head_of_fn]),
λ h, h.comp vector_head⟩
theorem part_iff₂ {f : ℕ → ℕ →. ℕ} :
@partrec' 2 (λ v, f v.head v.tail.head) ↔ partrec₂ f :=
part_iff.trans ⟨
λ h, (h.comp $ vector_cons.comp fst $
vector_cons.comp snd (const nil)).of_eq (λ v, by simp only [cons_head, cons_tail]),
λ h, h.comp vector_head (vector_head.comp vector_tail)⟩
theorem vec_iff {m n f} : @vec m n f ↔ computable f :=
⟨λ h, by simpa only [of_fn_nth] using vector_of_fn (λ i, to_part (h i)),
λ h i, of_part $ vector_nth.comp h (const i)⟩
end nat.partrec'
|
33baa113c28c57f5a891806d0c4a139533b27f78 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/topology/algebra/uniform_group.lean | 4b789cb3518998d6bdeac67f0e048d3b7694d0cb | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 20,023 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import topology.uniform_space.uniform_embedding
import topology.uniform_space.complete_separated
import topology.algebra.group
import tactic.abel
import deprecated.group
/-!
# Uniform structure on topological groups
* `topological_add_group.to_uniform_space` and `topological_add_group_is_uniform` can be used to
construct a canonical uniformity for a topological add group.
* extension of ℤ-bilinear maps to complete groups (useful for ring completions)
* `add_group_with_zero_nhd`: construct the topological structure from a group with a neighbourhood
around zero. Then with `topological_add_group.to_uniform_space` one can derive a `uniform_space`.
-/
noncomputable theory
open_locale classical uniformity topological_space filter
section uniform_add_group
open filter set
variables {α : Type*} {β : Type*}
/-- A uniform (additive) group is a group in which the addition and negation are
uniformly continuous. -/
class uniform_add_group (α : Type*) [uniform_space α] [add_group α] : Prop :=
(uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2))
theorem uniform_add_group.mk' {α} [uniform_space α] [add_group α]
(h₁ : uniform_continuous (λp:α×α, p.1 + p.2))
(h₂ : uniform_continuous (λp:α, -p)) : uniform_add_group α :=
⟨by simpa only [sub_eq_add_neg] using
h₁.comp (uniform_continuous_fst.prod_mk (h₂.comp uniform_continuous_snd))⟩
variables [uniform_space α] [add_group α] [uniform_add_group α]
lemma uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2) :=
uniform_add_group.uniform_continuous_sub
lemma uniform_continuous.sub [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x - g x) :=
uniform_continuous_sub.comp (hf.prod_mk hg)
lemma uniform_continuous.neg [uniform_space β] {f : β → α}
(hf : uniform_continuous f) : uniform_continuous (λx, - f x) :=
have uniform_continuous (λx, 0 - f x),
from uniform_continuous_const.sub hf,
by simp * at *
lemma uniform_continuous_neg : uniform_continuous (λx:α, - x) :=
uniform_continuous_id.neg
lemma uniform_continuous.add [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x + g x) :=
have uniform_continuous (λx, f x - - g x), from hf.sub hg.neg,
by simp [*, sub_eq_add_neg] at *
lemma uniform_continuous_add : uniform_continuous (λp:α×α, p.1 + p.2) :=
uniform_continuous_fst.add uniform_continuous_snd
@[priority 10]
instance uniform_add_group.to_topological_add_group : topological_add_group α :=
{ continuous_add := uniform_continuous_add.continuous,
continuous_neg := uniform_continuous_neg.continuous }
instance [uniform_space β] [add_group β] [uniform_add_group β] : uniform_add_group (α × β) :=
⟨((uniform_continuous_fst.comp uniform_continuous_fst).sub
(uniform_continuous_fst.comp uniform_continuous_snd)).prod_mk
((uniform_continuous_snd.comp uniform_continuous_fst).sub
(uniform_continuous_snd.comp uniform_continuous_snd))⟩
lemma uniformity_translate (a : α) : (𝓤 α).map (λx:α×α, (x.1 + a, x.2 + a)) = 𝓤 α :=
le_antisymm
(uniform_continuous_id.add uniform_continuous_const)
(calc 𝓤 α =
((𝓤 α).map (λx:α×α, (x.1 + -a, x.2 + -a))).map (λx:α×α, (x.1 + a, x.2 + a)) :
by simp [filter.map_map, (∘)]; exact filter.map_id.symm
... ≤ (𝓤 α).map (λx:α×α, (x.1 + a, x.2 + a)) :
filter.map_mono (uniform_continuous_id.add uniform_continuous_const))
lemma uniform_embedding_translate (a : α) : uniform_embedding (λx:α, x + a) :=
{ comap_uniformity := begin
rw [← uniformity_translate a, comap_map] {occs := occurrences.pos [1]},
rintros ⟨p₁, p₂⟩ ⟨q₁, q₂⟩,
simp [prod.eq_iff_fst_eq_snd_eq] {contextual := tt}
end,
inj := add_left_injective a }
section
variables (α)
lemma uniformity_eq_comap_nhds_zero : 𝓤 α = comap (λx:α×α, x.2 - x.1) (𝓝 (0:α)) :=
begin
rw [nhds_eq_comap_uniformity, filter.comap_comap],
refine le_antisymm (filter.map_le_iff_le_comap.1 _) _,
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invariant uniform_continuous_sub hs
with ⟨t, ht, hts⟩,
refine mem_map.2 (mem_sets_of_superset ht _),
rintros ⟨a, b⟩,
simpa [subset_def] using hts a b a },
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invariant uniform_continuous_add hs
with ⟨t, ht, hts⟩,
refine ⟨_, ht, _⟩,
rintros ⟨a, b⟩, simpa [subset_def] using hts 0 (b - a) a }
end
end
lemma group_separation_rel (x y : α) : (x, y) ∈ separation_rel α ↔ x - y ∈ closure ({0} : set α) :=
have embedding (λa, a + (y - x)), from (uniform_embedding_translate (y - x)).embedding,
show (x, y) ∈ ⋂₀ (𝓤 α).sets ↔ x - y ∈ closure ({0} : set α),
begin
rw [this.closure_eq_preimage_closure_image, uniformity_eq_comap_nhds_zero α, sInter_comap_sets],
simp [mem_closure_iff_nhds, inter_singleton_nonempty, sub_eq_add_neg, add_assoc]
end
lemma uniform_continuous_of_tendsto_zero [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} (hf : is_add_group_hom f) (h : tendsto f (𝓝 0) (𝓝 0)) :
uniform_continuous f :=
begin
have : ((λx:β×β, x.2 - x.1) ∘ (λx:α×α, (f x.1, f x.2))) = (λx:α×α, f (x.2 - x.1)),
{ simp only [hf.map_sub] },
rw [uniform_continuous, uniformity_eq_comap_nhds_zero α, uniformity_eq_comap_nhds_zero β,
tendsto_comap_iff, this],
exact tendsto.comp h tendsto_comap
end
lemma add_monoid_hom.uniform_continuous_of_continuous_at_zero
[uniform_space β] [add_group β] [uniform_add_group β]
(f : α →+ β) (hf : continuous_at f 0) :
uniform_continuous f :=
uniform_continuous_of_tendsto_zero f.is_add_group_hom (by simpa using hf.tendsto)
lemma uniform_continuous_of_continuous [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} (hf : is_add_group_hom f) (h : continuous f) :
uniform_continuous f :=
uniform_continuous_of_tendsto_zero hf $
suffices tendsto f (𝓝 0) (𝓝 (f 0)), by rwa [hf.map_zero] at this,
h.tendsto 0
end uniform_add_group
section topological_add_comm_group
universes u v w x
open filter
variables {G : Type u} [add_comm_group G] [topological_space G] [topological_add_group G]
variable (G)
/-- The right uniformity on a topological group. -/
def topological_add_group.to_uniform_space : uniform_space G :=
{ uniformity := comap (λp:G×G, p.2 - p.1) (𝓝 0),
refl :=
by refine map_le_iff_le_comap.1 (le_trans _ (pure_le_nhds 0));
simp [set.subset_def] {contextual := tt},
symm :=
begin
suffices : tendsto ((λp, -p) ∘ (λp:G×G, p.2 - p.1)) (comap (λp:G×G, p.2 - p.1) (𝓝 0)) (𝓝 (-0)),
{ simpa [(∘), tendsto_comap_iff] },
exact tendsto.comp (tendsto.neg tendsto_id) tendsto_comap
end,
comp :=
begin
intros D H,
rw mem_lift'_sets,
{ rcases H with ⟨U, U_nhds, U_sub⟩,
rcases exists_nhds_zero_half U_nhds with ⟨V, ⟨V_nhds, V_sum⟩⟩,
existsi ((λp:G×G, p.2 - p.1) ⁻¹' V),
have H : (λp:G×G, p.2 - p.1) ⁻¹' V ∈ comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)),
by existsi [V, V_nhds] ; refl,
existsi H,
have comp_rel_sub :
comp_rel ((λp:G×G, p.2 - p.1) ⁻¹' V) ((λp, p.2 - p.1) ⁻¹' V) ⊆ (λp:G×G, p.2 - p.1) ⁻¹' U,
begin
intros p p_comp_rel,
rcases p_comp_rel with ⟨z, ⟨Hz1, Hz2⟩⟩,
simpa [sub_eq_add_neg, add_comm, add_left_comm] using V_sum _ Hz1 _ Hz2
end,
exact set.subset.trans comp_rel_sub U_sub },
{ exact monotone_comp_rel monotone_id monotone_id }
end,
is_open_uniformity :=
begin
intro S,
let S' := λ x, {p : G × G | p.1 = x → p.2 ∈ S},
show is_open S ↔ ∀ (x : G), x ∈ S → S' x ∈ comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)),
rw [is_open_iff_mem_nhds],
refine forall_congr (assume a, forall_congr (assume ha, _)),
rw [← nhds_translation a, mem_comap_sets, mem_comap_sets],
refine exists_congr (assume t, exists_congr (assume ht, _)),
show (λ (y : G), y - a) ⁻¹' t ⊆ S ↔ (λ (p : G × G), p.snd - p.fst) ⁻¹' t ⊆ S' a,
split,
{ rintros h ⟨x, y⟩ hx rfl, exact h hx },
{ rintros h x hx, exact @h (a, x) hx rfl }
end }
section
local attribute [instance] topological_add_group.to_uniform_space
lemma uniformity_eq_comap_nhds_zero' : 𝓤 G = comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)) := rfl
variable {G}
lemma topological_add_group_is_uniform : uniform_add_group G :=
have tendsto
((λp:(G×G), p.1 - p.2) ∘ (λp:(G×G)×(G×G), (p.1.2 - p.1.1, p.2.2 - p.2.1)))
(comap (λp:(G×G)×(G×G), (p.1.2 - p.1.1, p.2.2 - p.2.1)) ((𝓝 0).prod (𝓝 0)))
(𝓝 (0 - 0)) :=
(tendsto_fst.sub tendsto_snd).comp tendsto_comap,
begin
constructor,
rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff,
uniformity_eq_comap_nhds_zero' G, tendsto_comap_iff, prod_comap_comap_eq],
simpa [(∘), sub_eq_add_neg, add_comm, add_left_comm] using this
end
end
lemma to_uniform_space_eq {G : Type*} [u : uniform_space G] [add_comm_group G]
[uniform_add_group G] :
topological_add_group.to_uniform_space G = u :=
begin
ext : 1,
show @uniformity G (topological_add_group.to_uniform_space G) = 𝓤 G,
rw [uniformity_eq_comap_nhds_zero' G, uniformity_eq_comap_nhds_zero G]
end
end topological_add_comm_group
namespace add_comm_group
section Z_bilin
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables [add_comm_group α] [add_comm_group β] [add_comm_group γ]
/- TODO: when modules are changed to have more explicit base ring, then change replace `is_Z_bilin`
by using `is_bilinear_map ℤ` from `tensor_product`. -/
/-- `ℤ`-bilinearity for maps between additive commutative groups. -/
class is_Z_bilin (f : α × β → γ) : Prop :=
(add_left [] : ∀ a a' b, f (a + a', b) = f (a, b) + f (a', b))
(add_right [] : ∀ a b b', f (a, b + b') = f (a, b) + f (a, b'))
variables (f : α × β → γ) [is_Z_bilin f]
lemma is_Z_bilin.comp_hom {g : γ → δ} [add_comm_group δ] (hg : is_add_group_hom g) :
is_Z_bilin (g ∘ f) :=
by constructor; simp [(∘), is_Z_bilin.add_left f, is_Z_bilin.add_right f, hg.map_add]
instance is_Z_bilin.comp_swap : is_Z_bilin (f ∘ prod.swap) :=
⟨λ a a' b, is_Z_bilin.add_right f b a a',
λ a b b', is_Z_bilin.add_left f b b' a⟩
lemma is_Z_bilin.zero_left : ∀ b, f (0, b) = 0 :=
begin
intro b,
apply add_right_eq_self.1,
rw [ ←is_Z_bilin.add_left f, zero_add]
end
lemma is_Z_bilin.zero_right : ∀ a, f (a, 0) = 0 :=
is_Z_bilin.zero_left (f ∘ prod.swap)
lemma is_Z_bilin.zero : f (0, 0) = 0 :=
is_Z_bilin.zero_left f 0
lemma is_Z_bilin.neg_left : ∀ a b, f (-a, b) = -f (a, b) :=
begin
intros a b,
apply eq_of_sub_eq_zero,
rw [sub_eq_add_neg, neg_neg, ←is_Z_bilin.add_left f, neg_add_self, is_Z_bilin.zero_left f]
end
lemma is_Z_bilin.neg_right : ∀ a b, f (a, -b) = -f (a, b) :=
assume a b, is_Z_bilin.neg_left (f ∘ prod.swap) b a
lemma is_Z_bilin.sub_left : ∀ a a' b, f (a - a', b) = f (a, b) - f (a', b) :=
begin
intros,
simp [sub_eq_add_neg],
rw [is_Z_bilin.add_left f, is_Z_bilin.neg_left f]
end
lemma is_Z_bilin.sub_right : ∀ a b b', f (a, b - b') = f (a, b) - f (a,b') :=
assume a b b', is_Z_bilin.sub_left (f ∘ prod.swap) b b' a
end Z_bilin
end add_comm_group
open add_comm_group filter set function
section
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
-- α, β and G are abelian topological groups, G is a uniform space
variables [topological_space α] [add_comm_group α]
variables [topological_space β] [add_comm_group β]
variables {G : Type*} [uniform_space G] [add_comm_group G]
variables {ψ : α × β → G} (hψ : continuous ψ) [ψbilin : is_Z_bilin ψ]
include hψ ψbilin
lemma is_Z_bilin.tendsto_zero_left (x₁ : α) : tendsto ψ (𝓝 (x₁, 0)) (𝓝 0) :=
begin
have := hψ.tendsto (x₁, 0),
rwa [is_Z_bilin.zero_right ψ] at this
end
lemma is_Z_bilin.tendsto_zero_right (y₁ : β) : tendsto ψ (𝓝 (0, y₁)) (𝓝 0) :=
begin
have := hψ.tendsto (0, y₁),
rwa [is_Z_bilin.zero_left ψ] at this
end
end
section
variables {α : Type*} {β : Type*}
variables [topological_space α] [add_comm_group α] [topological_add_group α]
-- β is a dense subgroup of α, inclusion is denoted by e
variables [topological_space β] [add_comm_group β]
variables {e : β → α} (he : is_add_group_hom e) (de : dense_inducing e)
include he de
lemma tendsto_sub_comap_self (x₀ : α) :
tendsto (λt:β×β, t.2 - t.1) (comap (λp:β×β, (e p.1, e p.2)) $ 𝓝 (x₀, x₀)) (𝓝 0) :=
begin
have comm : (λx:α×α, x.2-x.1) ∘ (λt:β×β, (e t.1, e t.2)) = e ∘ (λt:β×β, t.2 - t.1),
{ ext t,
change e t.2 - e t.1 = e (t.2 - t.1),
rwa ← he.map_sub t.2 t.1 },
have lim : tendsto (λ x : α × α, x.2-x.1) (𝓝 (x₀, x₀)) (𝓝 (e 0)),
{ have := (continuous_sub.comp (@continuous_swap α α _ _)).tendsto (x₀, x₀),
simpa [-sub_eq_add_neg, sub_self, eq.symm (he.map_zero)] using this },
have := de.tendsto_comap_nhds_nhds lim comm,
simp [-sub_eq_add_neg, this]
end
end
namespace dense_inducing
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables {G : Type*}
-- β is a dense subgroup of α, inclusion is denoted by e
-- δ is a dense subgroup of γ, inclusion is denoted by f
variables [topological_space α] [add_comm_group α] [topological_add_group α]
variables [topological_space β] [add_comm_group β] [topological_add_group β]
variables [topological_space γ] [add_comm_group γ] [topological_add_group γ]
variables [topological_space δ] [add_comm_group δ] [topological_add_group δ]
variables [uniform_space G] [add_comm_group G] [uniform_add_group G] [separated_space G]
[complete_space G]
variables {e : β → α} (he : is_add_group_hom e) (de : dense_inducing e)
variables {f : δ → γ} (hf : is_add_group_hom f) (df : dense_inducing f)
variables {φ : β × δ → G} (hφ : continuous φ) [bilin : is_Z_bilin φ]
include he de hf df hφ bilin
variables {W' : set G} (W'_nhd : W' ∈ 𝓝 (0 : G))
include W'_nhd
private lemma extend_Z_bilin_aux (x₀ : α) (y₁ : δ) :
∃ U₂ ∈ comap e (𝓝 x₀), ∀ x x' ∈ U₂, φ (x' - x, y₁) ∈ W' :=
begin
let Nx := 𝓝 x₀,
let ee := λ u : β × β, (e u.1, e u.2),
have lim1 : tendsto (λ a : β × β, (a.2 - a.1, y₁)) (comap e Nx ×ᶠ comap e Nx) (𝓝 (0, y₁)),
{ have := tendsto.prod_mk (tendsto_sub_comap_self he de x₀)
(tendsto_const_nhds : tendsto (λ (p : β × β), y₁) (comap ee $ 𝓝 (x₀, x₀)) (𝓝 y₁)),
rw [nhds_prod_eq, prod_comap_comap_eq, ←nhds_prod_eq],
exact (this : _) },
have lim := tendsto.comp (is_Z_bilin.tendsto_zero_right hφ y₁) lim1,
rw tendsto_prod_self_iff at lim,
exact lim W' W'_nhd,
end
private lemma extend_Z_bilin_key (x₀ : α) (y₀ : γ) :
∃ U ∈ comap e (𝓝 x₀), ∃ V ∈ comap f (𝓝 y₀),
∀ x x' ∈ U, ∀ y y' ∈ V, φ (x', y') - φ (x, y) ∈ W' :=
begin
let Nx := 𝓝 x₀,
let Ny := 𝓝 y₀,
let dp := dense_inducing.prod de df,
let ee := λ u : β × β, (e u.1, e u.2),
let ff := λ u : δ × δ, (f u.1, f u.2),
have lim_φ : filter.tendsto φ (𝓝 (0, 0)) (𝓝 0),
{ have := hφ.tendsto (0, 0),
rwa [is_Z_bilin.zero φ] at this },
have lim_φ_sub_sub : tendsto (λ (p : (β × β) × (δ × δ)), φ (p.1.2 - p.1.1, p.2.2 - p.2.1))
((comap ee $ 𝓝 (x₀, x₀)) ×ᶠ (comap ff $ 𝓝 (y₀, y₀))) (𝓝 0),
{ have lim_sub_sub : tendsto (λ (p : (β × β) × δ × δ), (p.1.2 - p.1.1, p.2.2 - p.2.1))
((comap ee (𝓝 (x₀, x₀))) ×ᶠ (comap ff (𝓝 (y₀, y₀)))) (𝓝 0 ×ᶠ 𝓝 0),
{ have := filter.prod_mono (tendsto_sub_comap_self he de x₀) (tendsto_sub_comap_self hf df y₀),
rwa prod_map_map_eq at this },
rw ← nhds_prod_eq at lim_sub_sub,
exact tendsto.comp lim_φ lim_sub_sub },
rcases exists_nhds_zero_quarter W'_nhd with ⟨W, W_nhd, W4⟩,
have : ∃ U₁ ∈ comap e (𝓝 x₀), ∃ V₁ ∈ comap f (𝓝 y₀),
∀ x x' ∈ U₁, ∀ y y' ∈ V₁, φ (x'-x, y'-y) ∈ W,
{ have := tendsto_prod_iff.1 lim_φ_sub_sub W W_nhd,
repeat { rw [nhds_prod_eq, ←prod_comap_comap_eq] at this },
rcases this with ⟨U, U_in, V, V_in, H⟩,
rw [mem_prod_same_iff] at U_in V_in,
rcases U_in with ⟨U₁, U₁_in, HU₁⟩,
rcases V_in with ⟨V₁, V₁_in, HV₁⟩,
existsi [U₁, U₁_in, V₁, V₁_in],
intros x x' x_in x'_in y y' y_in y'_in,
exact H _ _ (HU₁ (mk_mem_prod x_in x'_in)) (HV₁ (mk_mem_prod y_in y'_in)) },
rcases this with ⟨U₁, U₁_nhd, V₁, V₁_nhd, H⟩,
obtain ⟨x₁, x₁_in⟩ : U₁.nonempty :=
((de.comap_nhds_ne_bot _).nonempty_of_mem U₁_nhd),
obtain ⟨y₁, y₁_in⟩ : V₁.nonempty :=
((df.comap_nhds_ne_bot _).nonempty_of_mem V₁_nhd),
rcases (extend_Z_bilin_aux he de hf df hφ W_nhd x₀ y₁) with ⟨U₂, U₂_nhd, HU⟩,
rcases (extend_Z_bilin_aux hf df he de (hφ.comp continuous_swap) W_nhd y₀ x₁)
with ⟨V₂, V₂_nhd, HV⟩,
existsi [U₁ ∩ U₂, inter_mem_sets U₁_nhd U₂_nhd,
V₁ ∩ V₂, inter_mem_sets V₁_nhd V₂_nhd],
rintros x x' ⟨xU₁, xU₂⟩ ⟨x'U₁, x'U₂⟩ y y' ⟨yV₁, yV₂⟩ ⟨y'V₁, y'V₂⟩,
have key_formula : φ(x', y') - φ(x, y) =
φ(x' - x, y₁) + φ(x' - x, y' - y₁) + φ(x₁, y' - y) + φ(x - x₁, y' - y),
{ repeat { rw is_Z_bilin.sub_left φ },
repeat { rw is_Z_bilin.sub_right φ },
apply eq_of_sub_eq_zero,
simp [sub_eq_add_neg], abel },
rw key_formula,
have h₁ := HU x x' xU₂ x'U₂,
have h₂ := H x x' xU₁ x'U₁ y₁ y' y₁_in y'V₁,
have h₃ := HV y y' yV₂ y'V₂,
have h₄ := H x₁ x x₁_in xU₁ y y' yV₁ y'V₁,
exact W4 h₁ h₂ h₃ h₄
end
omit W'_nhd
open dense_inducing
/-- Bourbaki GT III.6.5 Theorem I:
ℤ-bilinear continuous maps from dense images into a complete Hausdorff group extend by continuity.
Note: Bourbaki assumes that α and β are also complete Hausdorff, but this is not necessary. -/
theorem extend_Z_bilin : continuous (extend (de.prod df) φ) :=
begin
refine continuous_extend_of_cauchy _ _,
rintro ⟨x₀, y₀⟩,
split,
{ apply ne_bot.map,
apply comap_ne_bot,
intros U h,
rcases mem_closure_iff_nhds.1 ((de.prod df).dense (x₀, y₀)) U h with ⟨x, x_in, ⟨z, z_x⟩⟩,
existsi z,
cc },
{ suffices : map (λ (p : (β × δ) × (β × δ)), φ p.2 - φ p.1)
(comap (λ (p : (β × δ) × β × δ), ((e p.1.1, f p.1.2), (e p.2.1, f p.2.2)))
(𝓝 (x₀, y₀) ×ᶠ 𝓝 (x₀, y₀))) ≤ 𝓝 0,
by rwa [uniformity_eq_comap_nhds_zero G, prod_map_map_eq, ←map_le_iff_le_comap, filter.map_map,
prod_comap_comap_eq],
intros W' W'_nhd,
have key := extend_Z_bilin_key he de hf df hφ W'_nhd x₀ y₀,
rcases key with ⟨U, U_nhd, V, V_nhd, h⟩,
rw mem_comap_sets at U_nhd,
rcases U_nhd with ⟨U', U'_nhd, U'_sub⟩,
rw mem_comap_sets at V_nhd,
rcases V_nhd with ⟨V', V'_nhd, V'_sub⟩,
rw [mem_map, mem_comap_sets, nhds_prod_eq],
existsi set.prod (set.prod U' V') (set.prod U' V'),
rw mem_prod_same_iff,
simp only [exists_prop],
split,
{ change U' ∈ 𝓝 x₀ at U'_nhd,
change V' ∈ 𝓝 y₀ at V'_nhd,
have := prod_mem_prod U'_nhd V'_nhd,
tauto },
{ intros p h',
simp only [set.mem_preimage, set.prod_mk_mem_set_prod_eq] at h',
rcases p with ⟨⟨x, y⟩, ⟨x', y'⟩⟩,
apply h ; tauto } }
end
end dense_inducing
|
cbaa4d9543dc023f026583532c069cb59785cc42 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/special_functions/exp_deriv.lean | 07d2b5e7aae93d9ca99f0f8a91f75f5f4864db1b | [
"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 | 10,166 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import analysis.calculus.inverse
import analysis.complex.real_deriv
import analysis.special_functions.exp
/-!
# Complex and real exponential
In this file we prove that `complex.exp` and `real.exp` are infinitely smooth functions.
## Tags
exp, derivative
-/
noncomputable theory
open filter asymptotics set function
open_locale classical topological_space
namespace complex
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] [normed_algebra 𝕜 ℂ]
/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/
lemma has_deriv_at_exp (x : ℂ) : has_deriv_at exp (exp x) x :=
begin
rw has_deriv_at_iff_is_o_nhds_zero,
have : (1 : ℕ) < 2 := by norm_num,
refine (is_O.of_bound (‖exp x‖) _).trans_is_o (is_o_pow_id this),
filter_upwards [metric.ball_mem_nhds (0 : ℂ) zero_lt_one],
simp only [metric.mem_ball, dist_zero_right, norm_pow],
exact λ z hz, exp_bound_sq x z hz.le,
end
lemma differentiable_exp : differentiable 𝕜 exp :=
λ x, (has_deriv_at_exp x).differentiable_at.restrict_scalars 𝕜
lemma differentiable_at_exp {x : ℂ} : differentiable_at 𝕜 exp x :=
differentiable_exp x
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
lemma cont_diff_exp : ∀ {n}, cont_diff 𝕜 n exp :=
begin
refine cont_diff_all_iff_nat.2 (λ n, _),
have : cont_diff ℂ ↑n exp,
{ induction n with n ihn,
{ exact cont_diff_zero.2 continuous_exp },
{ rw cont_diff_succ_iff_deriv,
use differentiable_exp,
rwa deriv_exp }, },
exact this.restrict_scalars 𝕜
end
lemma has_strict_deriv_at_exp (x : ℂ) : has_strict_deriv_at exp (exp x) x :=
cont_diff_exp.cont_diff_at.has_strict_deriv_at' (has_deriv_at_exp x) le_rfl
lemma has_strict_fderiv_at_exp_real (x : ℂ) :
has_strict_fderiv_at exp (exp x • (1 : ℂ →L[ℝ] ℂ)) x :=
(has_strict_deriv_at_exp x).complex_to_real_fderiv
lemma is_open_map_exp : is_open_map exp :=
open_map_of_strict_deriv has_strict_deriv_at_exp exp_ne_zero
end complex
section
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] [normed_algebra 𝕜 ℂ]
{f : 𝕜 → ℂ} {f' : ℂ} {x : 𝕜} {s : set 𝕜}
lemma has_strict_deriv_at.cexp (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.exp (f x)) (complex.exp (f x) * f') x :=
(complex.has_strict_deriv_at_exp (f x)).comp x hf
lemma has_deriv_at.cexp (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.exp (f x)) (complex.exp (f x) * f') x :=
(complex.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.cexp (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.exp (f x)) (complex.exp (f x) * f') s x :=
(complex.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cexp (hf : differentiable_within_at 𝕜 f s x)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λ x, complex.exp (f x)) s x = complex.exp (f x) * deriv_within f s x :=
hf.has_deriv_within_at.cexp.deriv_within hxs
@[simp] lemma deriv_cexp (hc : differentiable_at 𝕜 f x) :
deriv (λ x, complex.exp (f x)) x = complex.exp (f x) * deriv f x :=
hc.has_deriv_at.cexp.deriv
end
section
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] [normed_algebra 𝕜 ℂ]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] {f : E → ℂ} {f' : E →L[𝕜] ℂ}
{x : E} {s : set E}
lemma has_strict_fderiv_at.cexp (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.exp (f x)) (complex.exp (f x) • f') x :=
(complex.has_strict_deriv_at_exp (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_within_at.cexp (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.exp (f x)) (complex.exp (f x) • f') s x :=
(complex.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf
lemma has_fderiv_at.cexp (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.exp (f x)) (complex.exp (f x) • f') x :=
has_fderiv_within_at_univ.1 $ hf.has_fderiv_within_at.cexp
lemma differentiable_within_at.cexp (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (λ x, complex.exp (f x)) s x :=
hf.has_fderiv_within_at.cexp.differentiable_within_at
@[simp] lemma differentiable_at.cexp (hc : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (λ x, complex.exp (f x)) x :=
hc.has_fderiv_at.cexp.differentiable_at
lemma differentiable_on.cexp (hc : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (λ x, complex.exp (f x)) s :=
λ x h, (hc x h).cexp
@[simp] lemma differentiable.cexp (hc : differentiable 𝕜 f) :
differentiable 𝕜 (λ x, complex.exp (f x)) :=
λ x, (hc x).cexp
lemma cont_diff.cexp {n} (h : cont_diff 𝕜 n f) :
cont_diff 𝕜 n (λ x, complex.exp (f x)) :=
complex.cont_diff_exp.comp h
lemma cont_diff_at.cexp {n} (hf : cont_diff_at 𝕜 n f x) :
cont_diff_at 𝕜 n (λ x, complex.exp (f x)) x :=
complex.cont_diff_exp.cont_diff_at.comp x hf
lemma cont_diff_on.cexp {n} (hf : cont_diff_on 𝕜 n f s) :
cont_diff_on 𝕜 n (λ x, complex.exp (f x)) s :=
complex.cont_diff_exp.comp_cont_diff_on hf
lemma cont_diff_within_at.cexp {n} (hf : cont_diff_within_at 𝕜 n f s x) :
cont_diff_within_at 𝕜 n (λ x, complex.exp (f x)) s x :=
complex.cont_diff_exp.cont_diff_at.comp_cont_diff_within_at x hf
end
namespace real
variables {x y z : ℝ}
lemma has_strict_deriv_at_exp (x : ℝ) : has_strict_deriv_at exp (exp x) x :=
(complex.has_strict_deriv_at_exp x).real_of_complex
lemma has_deriv_at_exp (x : ℝ) : has_deriv_at exp (exp x) x :=
(complex.has_deriv_at_exp x).real_of_complex
lemma cont_diff_exp {n} : cont_diff ℝ n exp :=
complex.cont_diff_exp.real_of_complex
lemma differentiable_exp : differentiable ℝ exp :=
λx, (has_deriv_at_exp x).differentiable_at
lemma differentiable_at_exp : differentiable_at ℝ exp x :=
differentiable_exp x
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
end real
section
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
lemma has_strict_deriv_at.exp (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.exp (f x)) (real.exp (f x) * f') x :=
(real.has_strict_deriv_at_exp (f x)).comp x hf
lemma has_deriv_at.exp (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.exp (f x)) (real.exp (f x) * f') x :=
(real.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.exp (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.exp (f x)) (real.exp (f x) * f') s x :=
(real.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_exp (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.exp (f x)) s x = real.exp (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.exp.deriv_within hxs
@[simp] lemma deriv_exp (hc : differentiable_at ℝ f x) :
deriv (λx, real.exp (f x)) x = real.exp (f x) * (deriv f x) :=
hc.has_deriv_at.exp.deriv
end
section
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}
{x : E} {s : set E}
lemma cont_diff.exp {n} (hf : cont_diff ℝ n f) :
cont_diff ℝ n (λ x, real.exp (f x)) :=
real.cont_diff_exp.comp hf
lemma cont_diff_at.exp {n} (hf : cont_diff_at ℝ n f x) :
cont_diff_at ℝ n (λ x, real.exp (f x)) x :=
real.cont_diff_exp.cont_diff_at.comp x hf
lemma cont_diff_on.exp {n} (hf : cont_diff_on ℝ n f s) :
cont_diff_on ℝ n (λ x, real.exp (f x)) s :=
real.cont_diff_exp.comp_cont_diff_on hf
lemma cont_diff_within_at.exp {n} (hf : cont_diff_within_at ℝ n f s x) :
cont_diff_within_at ℝ n (λ x, real.exp (f x)) s x :=
real.cont_diff_exp.cont_diff_at.comp_cont_diff_within_at x hf
lemma has_fderiv_within_at.exp (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.exp (f x)) (real.exp (f x) • f') s x :=
(real.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf
lemma has_fderiv_at.exp (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.exp (f x)) (real.exp (f x) • f') x :=
(real.has_deriv_at_exp (f x)).comp_has_fderiv_at x hf
lemma has_strict_fderiv_at.exp (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.exp (f x)) (real.exp (f x) • f') x :=
(real.has_strict_deriv_at_exp (f x)).comp_has_strict_fderiv_at x hf
lemma differentiable_within_at.exp (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.exp (f x)) s x :=
hf.has_fderiv_within_at.exp.differentiable_within_at
@[simp] lemma differentiable_at.exp (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.exp (f x)) x :=
hc.has_fderiv_at.exp.differentiable_at
lemma differentiable_on.exp (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.exp (f x)) s :=
λ x h, (hc x h).exp
@[simp] lemma differentiable.exp (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.exp (f x)) :=
λ x, (hc x).exp
lemma fderiv_within_exp (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.exp (f x)) s x = real.exp (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.exp.fderiv_within hxs
@[simp] lemma fderiv_exp (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.exp (f x)) x = real.exp (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.exp.fderiv
end
|
499fdf7c25a9d28c8540ad20216067edf0907790 | 1437b3495ef9020d5413178aa33c0a625f15f15f | /tactic/norm_num.lean | 8ede7870bdd1d4327186bf2c269168c817c23724 | [
"Apache-2.0"
] | permissive | jean002/mathlib | c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30 | dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd | refs/heads/master | 1,587,027,806,375 | 1,547,306,358,000 | 1,547,306,358,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,825 | lean | /-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Mario Carneiro
Evaluating arithmetic expressions including *, +, -, ^, ≤
-/
import algebra.group_power data.rat data.nat.prime
import tactic.interactive tactic.converter.interactive
universes u v w
namespace expr
protected meta def to_pos_rat : expr → option ℚ
| `(%%e₁ / %%e₂) := do m ← e₁.to_nat, n ← e₂.to_nat, some (rat.mk m n)
| e := do n ← e.to_nat, return (rat.of_int n)
protected meta def to_rat : expr → option ℚ
| `(has_neg.neg %%e) := do q ← e.to_pos_rat, some (-q)
| e := e.to_pos_rat
protected meta def of_rat (α : expr) : ℚ → tactic expr
| ⟨(n:ℕ), d, h, c⟩ := do
e₁ ← expr.of_nat α n,
if d = 1 then return e₁ else
do e₂ ← expr.of_nat α d,
tactic.mk_app ``has_div.div [e₁, e₂]
| ⟨-[1+n], d, h, c⟩ := do
e₁ ← expr.of_nat α (n+1),
e ← (if d = 1 then return e₁ else do
e₂ ← expr.of_nat α d,
tactic.mk_app ``has_div.div [e₁, e₂]),
tactic.mk_app ``has_neg.neg [e]
end expr
namespace tactic
meta def refl_conv (e : expr) : tactic (expr × expr) :=
do p ← mk_eq_refl e, return (e, p)
meta def trans_conv (t₁ t₂ : expr → tactic (expr × expr)) (e : expr) :
tactic (expr × expr) :=
(do (e₁, p₁) ← t₁ e,
(do (e₂, p₂) ← t₂ e₁,
p ← mk_eq_trans p₁ p₂, return (e₂, p)) <|>
return (e₁, p₁)) <|> t₂ e
end tactic
open tactic
namespace norm_num
variable {α : Type u}
lemma subst_into_neg {α} [has_neg α] (a ta t : α) (pra : a = ta) (prt : -ta = t) : -a = t :=
by simp [pra, prt]
theorem bit0_zero [add_group α] : bit0 (0 : α) = 0 := add_zero _
theorem bit1_zero [add_group α] [has_one α] : bit1 (0 : α) = 1 :=
by rw [bit1, bit0_zero, zero_add]
lemma pow_bit0_helper [monoid α] (a t : α) (b : ℕ) (h : a ^ b = t) :
a ^ bit0 b = t * t :=
by simp [pow_bit0, h]
lemma pow_bit1_helper [monoid α] (a t : α) (b : ℕ) (h : a ^ b = t) :
a ^ bit1 b = t * t * a :=
by simp [pow_bit1, h]
lemma lt_add_of_pos_helper [ordered_cancel_comm_monoid α]
(a b c : α) (h : a + b = c) (h₂ : 0 < b) : a < c :=
h ▸ (lt_add_iff_pos_right _).2 h₂
lemma nat_div_helper (a b q r : ℕ) (h : r + q * b = a) (h₂ : r < b) : a / b = q :=
by rw [← h, nat.add_mul_div_right _ _ (lt_of_le_of_lt (nat.zero_le _) h₂),
nat.div_eq_of_lt h₂, zero_add]
lemma int_div_helper (a b q r : ℤ) (h : r + q * b = a) (h₁ : 0 ≤ r) (h₂ : r < b) : a / b = q :=
by rw [← h, int.add_mul_div_right _ _ (ne_of_gt (lt_of_le_of_lt h₁ h₂)),
int.div_eq_zero_of_lt h₁ h₂, zero_add]
lemma nat_mod_helper (a b q r : ℕ) (h : r + q * b = a) (h₂ : r < b) : a % b = r :=
by rw [← h, nat.add_mul_mod_self_right, nat.mod_eq_of_lt h₂]
lemma int_mod_helper (a b q r : ℤ) (h : r + q * b = a) (h₁ : 0 ≤ r) (h₂ : r < b) : a % b = r :=
by rw [← h, int.add_mul_mod_self, int.mod_eq_of_lt h₁ h₂]
meta def eval_pow (simp : expr → tactic (expr × expr)) : expr → tactic (expr × expr)
| `(@has_pow.pow %%α _ %%m %%e₁ %%e₂) :=
match m with
| `(nat.has_pow) :=
mk_app ``nat.pow [e₁, e₂] >>= eval_pow
| `(@monoid.has_pow %%α %%m) :=
mk_app ``monoid.pow [e₁, e₂] >>= eval_pow
| _ := failed
end
| `(monoid.pow %%e₁ 0) := do
p ← mk_app ``pow_zero [e₁],
a ← infer_type e₁,
o ← mk_app ``has_one.one [a],
return (o, p)
| `(monoid.pow %%e₁ 1) := do
p ← mk_app ``pow_one [e₁],
return (e₁, p)
| `(monoid.pow %%e₁ (bit0 %%e₂)) := do
e ← mk_app ``monoid.pow [e₁, e₂],
(e', p) ← simp e,
p' ← mk_app ``norm_num.pow_bit0_helper [e₁, e', e₂, p],
e'' ← to_expr ``(%%e' * %%e'),
return (e'', p')
| `(monoid.pow %%e₁ (bit1 %%e₂)) := do
e ← mk_app ``monoid.pow [e₁, e₂],
(e', p) ← simp e,
p' ← mk_app ``norm_num.pow_bit1_helper [e₁, e', e₂, p],
e'' ← to_expr ``(%%e' * %%e' * %%e₁),
return (e'', p')
| `(nat.pow %%e₁ %%e₂) := do
p₁ ← mk_app ``nat.pow_eq_pow [e₁, e₂],
e ← mk_app ``monoid.pow [e₁, e₂],
(e', p₂) ← simp e,
p ← mk_eq_trans p₁ p₂,
return (e', p)
| _ := failed
meta def prove_pos : instance_cache → expr → tactic (instance_cache × expr)
| c `(has_one.one _) := do (c, p) ← c.mk_app ``zero_lt_one [], return (c, p)
| c `(bit0 %%e) := do (c, p) ← prove_pos c e, (c, p) ← c.mk_app ``bit0_pos [e, p], return (c, p)
| c `(bit1 %%e) := do (c, p) ← prove_pos c e, (c, p) ← c.mk_app ``bit1_pos' [e, p], return (c, p)
| c `(%%e₁ / %%e₂) := do
(c, p₁) ← prove_pos c e₁, (c, p₂) ← prove_pos c e₂,
(c, p) ← c.mk_app ``div_pos_of_pos_of_pos [e₁, e₂, p₁, p₂],
return (c, p)
| c e := failed
meta def prove_lt (simp : expr → tactic (expr × expr)) : instance_cache → expr → expr → tactic (instance_cache × expr)
| c `(- %%e₁) `(- %%e₂) := do
(c, p) ← prove_lt c e₁ e₂,
(c, p) ← c.mk_app ``neg_lt_neg [e₁, e₂, p],
return (c, p)
| c `(- %%e₁) `(has_zero.zero _) := do
(c, p) ← prove_pos c e₁,
(c, p) ← c.mk_app ``neg_neg_of_pos [e₁, p],
return (c, p)
| c `(- %%e₁) e₂ := do
(c, p₁) ← prove_pos c e₁,
(c, me₁) ← c.mk_app ``has_neg.neg [e₁],
(c, p₁) ← c.mk_app ``neg_neg_of_pos [e₁, p₁],
(c, p₂) ← prove_pos c e₂,
(c, z) ← c.mk_app ``has_zero.zero [],
(c, p) ← c.mk_app ``lt_trans [me₁, z, e₂, p₁, p₂],
return (c, p)
| c `(has_zero.zero _) e₂ := prove_pos c e₂
| c e₁ e₂ := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
d ← expr.of_rat c.α (n₂ - n₁),
(c, e₃) ← c.mk_app ``has_add.add [e₁, d],
(e₂', p) ← norm_num e₃,
guard (e₂' =ₐ e₂),
(c, p') ← prove_pos c d,
(c, p) ← c.mk_app ``norm_num.lt_add_of_pos_helper [e₁, d, e₂, p, p'],
return (c, p)
private meta def true_intro (p : expr) : tactic (expr × expr) :=
prod.mk <$> mk_const `true <*> mk_app ``eq_true_intro [p]
private meta def false_intro (p : expr) : tactic (expr × expr) :=
prod.mk <$> mk_const `false <*> mk_app ``eq_false_intro [p]
meta def eval_ineq (simp : expr → tactic (expr × expr)) : expr → tactic (expr × expr)
| `(%%e₁ < %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
if n₁ < n₂ then
do (_, p) ← prove_lt simp c e₁ e₂, true_intro p
else do
(c, p) ← if n₁ = n₂ then c.mk_app ``lt_irrefl [e₁] else
(do (c, p') ← prove_lt simp c e₂ e₁,
c.mk_app ``not_lt_of_gt [e₁, e₂, p']),
false_intro p
| `(%%e₁ ≤ %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
if n₁ ≤ n₂ then do
(c, p) ← if n₁ = n₂ then c.mk_app ``le_refl [e₁] else
(do (c, p') ← prove_lt simp c e₁ e₂,
c.mk_app ``le_of_lt [e₁, e₂, p']),
true_intro p
else do
(c, p) ← prove_lt simp c e₂ e₁,
(c, p) ← c.mk_app ``not_le_of_gt [e₁, e₂, p],
false_intro p
| `(%%e₁ = %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
if n₁ < n₂ then do
(c, p) ← prove_lt simp c e₁ e₂,
(c, p) ← c.mk_app ``ne_of_lt [e₁, e₂, p],
false_intro p
else if n₂ < n₁ then do
(c, p) ← prove_lt simp c e₂ e₁,
(c, p) ← c.mk_app ``ne_of_gt [e₁, e₂, p],
false_intro p
else mk_eq_refl e₁ >>= true_intro
| `(%%e₁ > %%e₂) := mk_app ``has_lt.lt [e₂, e₁] >>= simp
| `(%%e₁ ≥ %%e₂) := mk_app ``has_le.le [e₂, e₁] >>= simp
| `(%%e₁ ≠ %%e₂) := do e ← mk_app ``eq [e₁, e₂], mk_app ``not [e] >>= simp
| _ := failed
meta def eval_div_ext (simp : expr → tactic (expr × expr)) : expr → tactic (expr × expr)
| `(has_inv.inv %%e) := do
c ← infer_type e >>= mk_instance_cache,
(c, p₁) ← c.mk_app ``inv_eq_one_div [e],
(c, o) ← c.mk_app ``has_one.one [],
(c, e') ← c.mk_app ``has_div.div [o, e],
(do (e'', p₂) ← simp e',
p ← mk_eq_trans p₁ p₂,
return (e'', p)) <|> return (e', p₁)
| `(%%e₁ / %%e₂) := do
α ← infer_type e₁,
c ← mk_instance_cache α,
match α with
| `(nat) := do
n₁ ← e₁.to_nat, n₂ ← e₂.to_nat,
q ← expr.of_nat α (n₁ / n₂),
r ← expr.of_nat α (n₁ % n₂),
(c, e₃) ← c.mk_app ``has_mul.mul [q, e₂],
(c, e₃) ← c.mk_app ``has_add.add [r, e₃],
(e₁', p) ← norm_num e₃,
guard (e₁' =ₐ e₁),
(c, p') ← prove_lt simp c r e₂,
p ← mk_app ``norm_num.nat_div_helper [e₁, e₂, q, r, p, p'],
return (q, p)
| `(int) := match e₂ with
| `(- %%e₂') := do
(c, p₁) ← c.mk_app ``int.div_neg [e₁, e₂'],
(c, e) ← c.mk_app ``has_div.div [e₁, e₂'],
(c, e) ← c.mk_app ``has_neg.neg [e],
(e', p₂) ← simp e,
p ← mk_eq_trans p₁ p₂,
return (e', p)
| _ := do
n₁ ← e₁.to_int,
n₂ ← e₂.to_int,
q ← expr.of_rat α $ rat.of_int (n₁ / n₂),
r ← expr.of_rat α $ rat.of_int (n₁ % n₂),
(c, e₃) ← c.mk_app ``has_mul.mul [q, e₂],
(c, e₃) ← c.mk_app ``has_add.add [r, e₃],
(e₁', p) ← norm_num e₃,
guard (e₁' =ₐ e₁),
(c, r0) ← c.mk_app ``has_zero.zero [],
(c, r0) ← c.mk_app ``has_le.le [r0, r],
(_, p₁) ← simp r0,
p₁ ← mk_app ``of_eq_true [p₁],
(c, p₂) ← prove_lt simp c r e₂,
p ← mk_app ``norm_num.int_div_helper [e₁, e₂, q, r, p, p₁, p₂],
return (q, p)
end
| _ := failed
end
| `(%%e₁ % %%e₂) := do
α ← infer_type e₁,
c ← mk_instance_cache α,
match α with
| `(nat) := do
n₁ ← e₁.to_nat, n₂ ← e₂.to_nat,
q ← expr.of_nat α (n₁ / n₂),
r ← expr.of_nat α (n₁ % n₂),
(c, e₃) ← c.mk_app ``has_mul.mul [q, e₂],
(c, e₃) ← c.mk_app ``has_add.add [r, e₃],
(e₁', p) ← norm_num e₃,
guard (e₁' =ₐ e₁),
(c, p') ← prove_lt simp c r e₂,
p ← mk_app ``norm_num.nat_mod_helper [e₁, e₂, q, r, p, p'],
return (r, p)
| `(int) := match e₂ with
| `(- %%e₂') := do
let p₁ := (expr.const ``int.mod_neg []).mk_app [e₁, e₂'],
(c, e) ← c.mk_app ``has_mod.mod [e₁, e₂'],
(e', p₂) ← simp e,
p ← mk_eq_trans p₁ p₂,
return (e', p)
| _ := do
n₁ ← e₁.to_int,
n₂ ← e₂.to_int,
q ← expr.of_rat α $ rat.of_int (n₁ / n₂),
r ← expr.of_rat α $ rat.of_int (n₁ % n₂),
(c, e₃) ← c.mk_app ``has_mul.mul [q, e₂],
(c, e₃) ← c.mk_app ``has_add.add [r, e₃],
(e₁', p) ← norm_num e₃,
guard (e₁' =ₐ e₁),
(c, r0) ← c.mk_app ``has_zero.zero [],
(c, r0) ← c.mk_app ``has_le.le [r0, r],
(_, p₁) ← simp r0,
p₁ ← mk_app ``of_eq_true [p₁],
(c, p₂) ← prove_lt simp c r e₂,
p ← mk_app ``norm_num.int_mod_helper [e₁, e₂, q, r, p, p₁, p₂],
return (r, p)
end
| _ := failed
end
| `(%%e₁ ∣ %%e₂) := do
α ← infer_type e₁,
c ← mk_instance_cache α,
n ← match α with
| `(nat) := return ``nat.dvd_iff_mod_eq_zero
| `(int) := return ``int.dvd_iff_mod_eq_zero
| _ := failed
end,
p₁ ← mk_app ``propext [@expr.const tt n [] e₁ e₂],
(e', p₂) ← simp `(%%e₂ % %%e₁ = 0),
p' ← mk_eq_trans p₁ p₂,
return (e', p')
| _ := failed
lemma not_prime_helper (a b n : ℕ)
(h : a * b = n) (h₁ : 1 < a) (h₂ : 1 < b) : ¬ nat.prime n :=
by rw ← h; exact nat.not_prime_mul h₁ h₂
lemma is_prime_helper (n : ℕ)
(h₁ : 1 < n) (h₂ : nat.min_fac n = n) : nat.prime n :=
nat.prime_def_min_fac.2 ⟨h₁, h₂⟩
lemma min_fac_bit0 (n : ℕ) : nat.min_fac (bit0 n) = 2 :=
by simp [nat.min_fac_eq, show 2 ∣ bit0 n, by simp [bit0_eq_two_mul n]]
def min_fac_helper (n k : ℕ) : Prop :=
0 < k ∧ bit1 k ≤ nat.min_fac (bit1 n)
theorem min_fac_helper.n_pos {n k : ℕ} (h : min_fac_helper n k) : 0 < n :=
nat.pos_iff_ne_zero.2 $ λ e,
by rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2
lemma min_fac_ne_bit0 {n k : ℕ} : nat.min_fac (bit1 n) ≠ bit0 k :=
by rw bit0_eq_two_mul; exact λ e, absurd
((nat.dvd_add_iff_right (by simp [bit0_eq_two_mul n])).2
(dvd_trans ⟨_, e⟩ (nat.min_fac_dvd _)))
dec_trivial
lemma min_fac_helper_0 (n : ℕ) (h : 0 < n) : min_fac_helper n 1 :=
begin
refine ⟨zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm⟩,
refine @lt_of_le_of_ne ℕ _ _ _ (nat.min_fac_pos _) _,
intro e,
have := nat.min_fac_prime _,
{ rw ← e at this, exact nat.not_prime_one this },
{ exact ne_of_gt (nat.bit1_lt h) }
end
lemma min_fac_helper_1 {n k k' : ℕ} (e : k + 1 = k')
(np : nat.min_fac (bit1 n) ≠ bit1 k)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
rw ← e,
refine ⟨nat.succ_pos _,
(lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)
min_fac_ne_bit0.symm : bit0 (k+1) < _)⟩,
{ rw add_right_comm, exact h.2 },
{ rw add_right_comm, exact np.symm }
end
lemma min_fac_helper_2 (n k k' : ℕ) (e : k + 1 = k')
(np : ¬ nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
intro e₁, rw ← e₁ at np,
exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)
end
lemma min_fac_helper_3 (n k k' : ℕ) (e : k + 1 = k')
(nd : bit1 k ∣ bit1 n = false)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
intro e₁, rw [eq_false, ← e₁] at nd,
exact nd (nat.min_fac_dvd _)
end
lemma min_fac_helper_4 (n k : ℕ) (hd : bit1 k ∣ bit1 n = true)
(h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=
by rw eq_true at hd; exact
le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2
lemma min_fac_helper_5 (n k k' : ℕ) (e : bit1 k * bit1 k = k')
(hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=
begin
refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2
⟨nat.bit1_lt h.n_pos, _⟩)).2,
rw ← e at hd,
intros m m2 hm md,
have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),
rw nat.le_sqrt at this,
exact not_le_of_lt hd this
end
meta def prove_non_prime (simp : expr → tactic (expr × expr)) (e : expr) (n d₁ : ℕ) : tactic expr :=
do let e₁ := reflect d₁,
c ← mk_instance_cache `(nat),
(c, p₁) ← prove_lt simp c `(1) e₁,
let d₂ := n / d₁, let e₂ := reflect d₂,
(e', p) ← mk_app ``has_mul.mul [e₁, e₂] >>= norm_num,
guard (e' =ₐ e),
(c, p₂) ← prove_lt simp c `(1) e₂,
return $ (expr.const ``not_prime_helper []).mk_app [e₁, e₂, e, p, p₁, p₂]
meta def prove_min_fac (simp : expr → tactic (expr × expr))
(e₁ : expr) (n1 : ℕ) : expr → expr → tactic (expr × expr)
| e₂ p := do
k ← e₂.to_nat,
let k1 := bit1 k,
e₁1 ← mk_app ``bit1 [e₁],
e₂1 ← mk_app ``bit1 [e₂],
if n1 < k1*k1 then do
c ← mk_instance_cache `(nat),
(c, e') ← c.mk_app ``has_mul.mul [e₂1, e₂1],
(e', p₁) ← norm_num e',
(c, p₂) ← prove_lt simp c e₁1 e',
p' ← mk_app ``min_fac_helper_5 [e₁, e₂, e', p₁, p₂, p],
return (e₁1, p')
else let d := k1.min_fac in
if to_bool (d < k1) then do
(e', p₁) ← norm_num `(%%e₂ + 1),
p₂ ← prove_non_prime simp e₂1 k1 d,
mk_app ``min_fac_helper_2 [e₁, e₂, e', p₁, p₂, p] >>= prove_min_fac e'
else do
(_, p₂) ← simp `((%%e₂1 : ℕ) ∣ %%e₁1),
if k1 ∣ n1 then do
p' ← mk_app ``min_fac_helper_4 [e₁, e₂, p₂, p],
return (e₂1, p')
else do
(e', p₁) ← norm_num `(%%e₂ + 1),
mk_app ``min_fac_helper_3 [e₁, e₂, e', p₁, p₂, p] >>= prove_min_fac e'
meta def eval_prime (simp : expr → tactic (expr × expr)) : expr → tactic (expr × expr)
| `(nat.prime %%e) := do
n ← e.to_nat,
match n with
| 0 := false_intro `(nat.not_prime_zero)
| 1 := false_intro `(nat.not_prime_one)
| _ := let d₁ := n.min_fac in
if d₁ < n then prove_non_prime simp e n d₁ >>= false_intro
else do
let e₁ := reflect d₁,
c ← mk_instance_cache `(nat),
(c, p₁) ← prove_lt simp c `(1) e₁,
(e₁, p) ← simp `(nat.min_fac %%e),
true_intro $ (expr.const ``is_prime_helper []).mk_app [e, p₁, p]
end
| `(nat.min_fac 0) := refl_conv (reflect (0:ℕ))
| `(nat.min_fac 1) := refl_conv (reflect (1:ℕ))
| `(nat.min_fac (bit0 %%e)) := prod.mk `(2) <$> mk_app ``min_fac_bit0 [e]
| `(nat.min_fac (bit1 %%e)) := do
n ← e.to_nat,
c ← mk_instance_cache `(nat),
(c, p) ← prove_pos c e,
mk_app ``min_fac_helper_0 [e, p] >>= prove_min_fac simp e (bit1 n) `(1)
| _ := failed
meta def derive1 (simp : expr → tactic (expr × expr)) (e : expr) :
tactic (expr × expr) :=
norm_num e <|> eval_div_ext simp e <|>
eval_pow simp e <|> eval_ineq simp e <|> eval_prime simp e
meta def derive : expr → tactic (expr × expr) | e :=
do e ← instantiate_mvars e,
(_, e', pr) ←
ext_simplify_core () {} simp_lemmas.mk (λ _, failed) (λ _ _ _ _ _, failed)
(λ _ _ _ _ e,
do (new_e, pr) ← derive1 derive e,
guard (¬ new_e =ₐ e),
return ((), new_e, some pr, tt))
`eq e,
return (e', pr)
end norm_num
namespace tactic.interactive
open norm_num interactive interactive.types
/-- Basic version of `norm_num` that does not call `simp`. -/
meta def norm_num1 (loc : parse location) : tactic unit :=
do ns ← loc.get_locals,
tt ← tactic.replace_at derive ns loc.include_goal
| fail "norm_num failed to simplify",
when loc.include_goal $ try tactic.triv,
when (¬ ns.empty) $ try tactic.contradiction
/-- Normalize numerical expressions. Supports the operations
`+` `-` `*` `/` `^` `<` `≤` over ordered fields (or other
appropriate classes), as well as `-` `/` `%` over `ℤ` and `ℕ`. -/
meta def norm_num (hs : parse simp_arg_list) (l : parse location) : tactic unit :=
repeat1 $ orelse' (norm_num1 l) $
simp_core {} (norm_num1 (loc.ns [none])) ff hs [] l
meta def apply_normed (x : parse texpr) : tactic unit :=
do x₁ ← to_expr x,
(x₂,_) ← derive x₁,
tactic.exact x₂
end tactic.interactive
namespace conv.interactive
open conv interactive tactic.interactive
open norm_num (derive)
meta def norm_num1 : conv unit := replace_lhs derive
meta def norm_num (hs : parse simp_arg_list) : conv unit :=
repeat1 $ orelse' norm_num1 $
simp_core {} norm_num1 ff hs [] (loc.ns [none])
end conv.interactive
|
2a17f73c3bf4269558d53f63079fe8076bf1d74c | 07c6143268cfb72beccd1cc35735d424ebcb187b | /src/data/array/lemmas.lean | c602d213ee0e279683a56f8eb0fa9ca55fd23396 | [
"Apache-2.0"
] | permissive | khoek/mathlib | bc49a842910af13a3c372748310e86467d1dc766 | aa55f8b50354b3e11ba64792dcb06cccb2d8ee28 | refs/heads/master | 1,588,232,063,837 | 1,587,304,803,000 | 1,587,304,803,000 | 176,688,517 | 0 | 0 | Apache-2.0 | 1,553,070,585,000 | 1,553,070,585,000 | null | UTF-8 | Lean | false | false | 8,868 | 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 category.traversable.equiv data.vector2
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.1 < 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 [*]; 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.1 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.1 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.1 = j,
{ subst j, rw [show fin.mk i.val h₃ = 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 _ _ _
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]
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
def d_array_equiv_fin {n : ℕ} (α : fin n → Type*) : d_array n α ≃ (∀ i, α i) :=
⟨d_array.read, d_array.mk, λ ⟨f⟩, rfl, λ f, rfl⟩
def array_equiv_fin (n : ℕ) (α : Type*) : array n α ≃ (fin n → α) :=
d_array_equiv_fin _
def vector_equiv_fin (α : Type*) (n : ℕ) : vector α n ≃ (fin n → α) :=
⟨vector.nth, vector.of_fn, vector.of_fn_nth, λ f, funext $ vector.nth_of_fn f⟩
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
|
652a6f9153f22e0b3dee3a4753d9abd7f2828391 | 54d7e71c3616d331b2ec3845d31deb08f3ff1dea | /library/init/core.lean | 8b7ff90c8499ce4de1e4b14f62f89f214808646d | [
"Apache-2.0"
] | permissive | pachugupta/lean | 6f3305c4292288311cc4ab4550060b17d49ffb1d | 0d02136a09ac4cf27b5c88361750e38e1f485a1a | refs/heads/master | 1,611,110,653,606 | 1,493,130,117,000 | 1,493,167,649,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,432 | 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
notation, basic datatypes and type classes
-/
prelude
notation `Prop` := Sort 0
notation f ` $ `:1 a:0 := f a
/- Logical operations and relations -/
reserve prefix `¬`:40
reserve prefix `~`:40
reserve infixr ` ∧ `:35
reserve infixr ` /\ `:35
reserve infixr ` \/ `:30
reserve infixr ` ∨ `:30
reserve infix ` <-> `:20
reserve infix ` ↔ `:20
reserve infix ` = `:50
reserve infix ` == `:50
reserve infix ` ≠ `:50
reserve infix ` ≈ `:50
reserve infix ` ~ `:50
reserve infix ` ≡ `:50
reserve infixl ` ⬝ `:75
reserve infixr ` ▸ `:75
reserve infixr ` ▹ `:75
/- types and type constructors -/
reserve infixr ` ⊕ `:30
reserve infixr ` × `:35
/- arithmetic operations -/
reserve infixl ` + `:65
reserve infixl ` - `:65
reserve infixl ` * `:70
reserve infixl ` / `:70
reserve infixl ` % `:70
reserve prefix `-`:100
reserve infix ` ^ `:80
reserve infixr ` ∘ `:90 -- input with \comp
reserve infix ` <= `:50
reserve infix ` ≤ `:50
reserve infix ` < `:50
reserve infix ` >= `:50
reserve infix ` ≥ `:50
reserve infix ` > `:50
/- boolean operations -/
reserve infixl ` && `:70
reserve infixl ` || `:65
/- set operations -/
reserve infix ` ∈ `:50
reserve infix ` ∉ `:50
reserve infixl ` ∩ `:70
reserve infixl ` ∪ `:65
reserve infix ` ⊆ `:50
reserve infix ` ⊇ `:50
reserve infix ` ⊂ `:50
reserve infix ` ⊃ `:50
reserve infix ` \ `:70
/- other symbols -/
reserve infix ` ∣ `:50
reserve infixl ` ++ `:65
reserve infixr ` :: `:67
reserve infixl `; `:1
universes u v w
/-- Gadget for optional parameter support. -/
@[reducible] def opt_param (α : Sort u) (default : α) : Sort u :=
α
/-- Gadget for marking output parameters in type classes. -/
@[reducible] def out_param (α : Sort u) : Sort u := α
inductive punit : Sort u
| star : punit
inductive unit : Type
| star : unit
/--
Gadget for defining thunks, thunk parameters have special treatment.
Example: given
def f (s : string) (t : thunk nat) : nat
an application
f "hello" 10
is converted into
f "hello" (λ _, 10)
-/
@[reducible] def thunk (α : Type u) : Type u :=
unit → α
inductive true : Prop
| intro : true
inductive false : Prop
inductive empty : Type
def not (a : Prop) := a → false
prefix `¬` := not
inductive eq {α : Sort u} (a : α) : α → Prop
| refl : eq a
init_quotient
inductive heq {α : Sort u} (a : α) : Π {β : Sort u}, β → Prop
| refl : heq a
structure prod (α : Type u) (β : Type v) :=
(fst : α) (snd : β)
/- Similar to prod, but α and β can be propositions.
We use this type internally to automatically generate the brec_on recursor. -/
structure pprod (α : Sort u) (β : Sort v) :=
(fst : α) (snd : β)
inductive and (a b : Prop) : Prop
| intro : a → b → and
def and.elim_left {a b : Prop} (h : and a b) : a :=
and.rec (λ ha hb, ha) h
def and.left := @and.elim_left
def and.elim_right {a b : Prop} (h : and a b) : b :=
and.rec (λ ha hb, hb) h
def and.right := @and.elim_right
/- eq basic support -/
infix = := eq
attribute [refl] eq.refl
@[pattern] def rfl {α : Sort u} {a : α} : a = a := eq.refl a
@[elab_as_eliminator, subst]
lemma eq.subst {α : Sort u} {P : α → Prop} {a b : α} (h₁ : a = b) (h₂ : P a) : P b :=
eq.rec h₂ h₁
notation h1 ▸ h2 := eq.subst h1 h2
@[trans] lemma eq.trans {α : Sort u} {a b c : α} (h₁ : a = b) (h₂ : b = c) : a = c :=
h₂ ▸ h₁
@[symm] lemma eq.symm {α : Sort u} {a b : α} (h : a = b) : b = a :=
h ▸ rfl
infix == := heq
lemma eq_of_heq {α : Sort u} {a a' : α} (h : a == a') : a = a' :=
have ∀ (α' : Sort u) (a' : α') (h₁ : @heq α a α' a') (h₂ : α = α'), (eq.rec_on h₂ a : α') = a', from
λ (α' : Sort u) (a' : α') (h₁ : @heq α a α' a'), heq.rec_on h₁ (λ h₂ : α = α, rfl),
show (eq.rec_on (eq.refl α) a : α) = a', from
this α a' h (eq.refl α)
/- The following four lemmas could not be automatically generated when the
structures were declared, so we prove them manually here. -/
lemma prod.mk.inj {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → and (x₁ = x₂) (y₁ = y₂) :=
λ h, prod.no_confusion h (λ h₁ h₂, ⟨h₁, h₂⟩)
lemma prod.mk.inj_arrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → Π ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P :=
λ h₁ _ h₂, prod.no_confusion h₁ h₂
lemma pprod.mk.inj {α : Sort u} {β : Sort v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: pprod.mk x₁ y₁ = pprod.mk x₂ y₂ → and (x₁ = x₂) (y₁ = y₂) :=
λ h, pprod.no_confusion h (λ h₁ h₂, ⟨h₁, h₂⟩)
lemma pprod.mk.inj_arrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → Π ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P :=
λ h₁ _ h₂, prod.no_confusion h₁ h₂
inductive sum (α : Type u) (β : Type v)
| inl {} : α → sum
| inr {} : β → sum
inductive psum (α : Sort u) (β : Sort v)
| inl {} : α → psum
| inr {} : β → psum
inductive or (a b : Prop) : Prop
| inl {} : a → or
| inr {} : b → or
def or.intro_left {a : Prop} (b : Prop) (ha : a) : or a b :=
or.inl ha
def or.intro_right (a : Prop) {b : Prop} (hb : b) : or a b :=
or.inr hb
structure sigma {α : Type u} (β : α → Type v) :=
mk :: (fst : α) (snd : β fst)
structure psigma {α : Sort u} (β : α → Sort v) :=
mk :: (fst : α) (snd : β fst)
inductive pos_num : Type
| one : pos_num
| bit1 : pos_num → pos_num
| bit0 : pos_num → pos_num
namespace pos_num
def succ : pos_num → pos_num
| one := bit0 one
| (bit1 n) := bit0 (succ n)
| (bit0 n) := bit1 n
end pos_num
inductive num : Type
| zero : num
| pos : pos_num → num
namespace num
open pos_num
def succ : num → num
| zero := pos one
| (pos p) := pos (pos_num.succ p)
end num
inductive bool : Type
| ff : bool
| tt : bool
/- Remark: subtype must take a Sort instead of Type because of the axiom strong_indefinite_description. -/
structure subtype {α : Sort u} (p : α → Prop) :=
(val : α) (property : p val)
attribute [pp_using_anonymous_constructor] sigma psigma subtype pprod
class inductive decidable (p : Prop)
| is_false : ¬p → decidable
| is_true : p → decidable
@[reducible]
def decidable_pred {α : Sort u} (r : α → Prop) :=
Π (a : α), decidable (r a)
@[reducible]
def decidable_rel {α : Sort u} (r : α → α → Prop) :=
Π (a b : α), decidable (r a b)
@[reducible]
def decidable_eq (α : Sort u) :=
decidable_rel (@eq α)
inductive option (α : Type u)
| none {} : option
| some : α → option
export option (none some)
export bool (ff tt)
inductive list (T : Type u)
| nil {} : list
| cons : T → list → list
notation h :: t := list.cons h t
notation `[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) := l
inductive nat
| zero : nat
| succ : nat → nat
structure unification_constraint :=
{α : Type u} (lhs : α) (rhs : α)
infix ` ≟ `:50 := unification_constraint.mk
infix ` =?= `:50 := unification_constraint.mk
structure unification_hint :=
(pattern : unification_constraint)
(constraints : list unification_constraint)
/- Declare builtin and reserved notation -/
class has_zero (α : Type u) := (zero : α)
class has_one (α : Type u) := (one : α)
class has_add (α : Type u) := (add : α → α → α)
class has_mul (α : Type u) := (mul : α → α → α)
class has_inv (α : Type u) := (inv : α → α)
class has_neg (α : Type u) := (neg : α → α)
class has_sub (α : Type u) := (sub : α → α → α)
class has_div (α : Type u) := (div : α → α → α)
class has_dvd (α : Type u) := (dvd : α → α → Prop)
class has_mod (α : Type u) := (mod : α → α → α)
class has_le (α : Type u) := (le : α → α → Prop)
class has_lt (α : Type u) := (lt : α → α → Prop)
class has_append (α : Type u) := (append : α → α → α)
class has_andthen (α : Type u) := (andthen : α → α → α)
class has_union (α : Type u) := (union : α → α → α)
class has_inter (α : Type u) := (inter : α → α → α)
class has_sdiff (α : Type u) := (sdiff : α → α → α)
class has_subset (α : Type u) := (subset : α → α → Prop)
class has_ssubset (α : Type u) := (ssubset : α → α → Prop)
/- Type classes has_emptyc and has_insert are
used to implement polymorphic notation for collections.
Example: {a, b, c}. -/
class has_emptyc (α : Type u) := (emptyc : α)
class has_insert (α : out_param (Type u)) (γ : Type v) := (insert : α → γ → γ)
/- Type class used to implement the notation { a ∈ c | p a } -/
class has_sep (α : out_param (Type u)) (γ : Type v) :=
(sep : (α → Prop) → γ → γ)
/- Type class for set-like membership -/
class has_mem (α : out_param (Type u)) (γ : Type v) := (mem : α → γ → Prop)
def zero {α : Type u} [has_zero α] : α := has_zero.zero α
def one {α : Type u} [has_one α] : α := has_one.one α
def add {α : Type u} [has_add α] : α → α → α := has_add.add
def mul {α : Type u} [has_mul α] : α → α → α := has_mul.mul
def sub {α : Type u} [has_sub α] : α → α → α := has_sub.sub
def div {α : Type u} [has_div α] : α → α → α := has_div.div
def dvd {α : Type u} [has_dvd α] : α → α → Prop := has_dvd.dvd
def mod {α : Type u} [has_mod α] : α → α → α := has_mod.mod
def neg {α : Type u} [has_neg α] : α → α := has_neg.neg
def inv {α : Type u} [has_inv α] : α → α := has_inv.inv
def le {α : Type u} [has_le α] : α → α → Prop := has_le.le
def lt {α : Type u} [has_lt α] : α → α → Prop := has_lt.lt
def append {α : Type u} [has_append α] : α → α → α := has_append.append
def andthen {α : Type u} [has_andthen α] : α → α → α := has_andthen.andthen
def union {α : Type u} [has_union α] : α → α → α := has_union.union
def inter {α : Type u} [has_inter α] : α → α → α := has_inter.inter
def sdiff {α : Type u} [has_sdiff α] : α → α → α := has_sdiff.sdiff
def subset {α : Type u} [has_subset α] : α → α → Prop := has_subset.subset
def ssubset {α : Type u} [has_ssubset α] : α → α → Prop := has_ssubset.ssubset
@[reducible]
def ge {α : Type u} [has_le α] (a b : α) : Prop := le b a
@[reducible]
def gt {α : Type u} [has_lt α] (a b : α) : Prop := lt b a
@[reducible]
def superset {α : Type u} [has_subset α] (a b : α) : Prop := subset b a
@[reducible]
def ssuperset {α : Type u} [has_ssubset α] (a b : α) : Prop := ssubset b a
def bit0 {α : Type u} [s : has_add α] (a : α) : α := add a a
def bit1 {α : Type u} [s₁ : has_one α] [s₂ : has_add α] (a : α) : α := add (bit0 a) one
attribute [pattern] zero one bit0 bit1 add neg
def insert {α : Type u} {γ : Type v} [has_insert α γ] : α → γ → γ :=
has_insert.insert
/- The empty collection -/
def emptyc {α : Type u} [has_emptyc α] : α :=
has_emptyc.emptyc α
def singleton {α : Type u} {γ : Type v} [has_emptyc γ] [has_insert α γ] (a : α) : γ :=
insert a emptyc
def sep {α : Type u} {γ : Type v} [has_sep α γ] : (α → Prop) → γ → γ :=
has_sep.sep
def mem {α : Type u} {γ : Type v} [has_mem α γ] : α → γ → Prop :=
has_mem.mem
/- num, pos_num instances -/
instance : has_zero num :=
⟨num.zero⟩
instance : has_one num :=
⟨num.pos pos_num.one⟩
instance : has_one pos_num :=
⟨pos_num.one⟩
namespace pos_num
def is_one : pos_num → bool
| one := tt
| _ := ff
def pred : pos_num → pos_num
| one := one
| (bit1 n) := bit0 n
| (bit0 one) := one
| (bit0 n) := bit1 (pred n)
def size : pos_num → pos_num
| one := one
| (bit0 n) := succ (size n)
| (bit1 n) := succ (size n)
def add : pos_num → pos_num → pos_num
| one b := succ b
| a one := succ a
| (bit0 a) (bit0 b) := bit0 (add a b)
| (bit1 a) (bit1 b) := bit0 (succ (add a b))
| (bit0 a) (bit1 b) := bit1 (add a b)
| (bit1 a) (bit0 b) := bit1 (add a b)
end pos_num
instance : has_add pos_num :=
⟨pos_num.add⟩
namespace num
open pos_num
def add : num → num → num
| zero a := a
| b zero := b
| (pos a) (pos b) := pos (pos_num.add a b)
end num
instance : has_add num :=
⟨num.add⟩
def std.priority.default : num := 1000
def std.priority.max : num := 4294967295
/- nat basic instances -/
namespace nat
protected def prio := num.add std.priority.default 100
protected def add : nat → nat → nat
| a zero := a
| a (succ b) := succ (add a b)
/- We mark the following definitions as pattern to make sure they can be used in recursive equations,
and reduced by the equation compiler. -/
attribute [pattern] nat.add nat.add._main
def of_pos_num : pos_num → nat
| pos_num.one := succ zero
| (pos_num.bit0 a) := let r := of_pos_num a in nat.add r r
| (pos_num.bit1 a) := let r := of_pos_num a in succ (nat.add r r)
def of_num : num → nat
| num.zero := zero
| (num.pos p) := of_pos_num p
end nat
instance : has_zero nat := ⟨nat.zero⟩
instance : has_one nat := ⟨nat.succ (nat.zero)⟩
instance : has_add nat := ⟨nat.add⟩
/-
Global declarations of right binding strength
If a module reassigns these, it will be incompatible with other modules that adhere to these
conventions.
When hovering over a symbol, use "C-c C-k" to see how to input it.
-/
def std.prec.max : num := 1024 -- the strength of application, identifiers, (, [, etc.
def std.prec.arrow : num := 25
/-
The next def is "max + 10". It can be used e.g. for postfix operations that should
be stronger than application.
-/
def std.prec.max_plus :=
num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ
(num.succ std.prec.max)))))))))
reserve postfix `⁻¹`:std.prec.max_plus -- input with \sy or \-1 or \inv
infix ∈ := mem
notation a ∉ s := ¬ mem a s
infix + := add
infix * := mul
infix - := sub
infix / := div
infix ∣ := dvd
infix % := mod
prefix - := neg
postfix ⁻¹ := inv
infix <= := le
infix >= := ge
infix ≤ := le
infix ≥ := ge
infix < := lt
infix > := gt
infix ++ := append
infix ; := andthen
notation `∅` := emptyc
infix ∪ := union
infix ∩ := inter
infix ⊆ := subset
infix ⊇ := superset
infix ⊂ := ssubset
infix ⊃ := ssuperset
infix \ := sdiff
notation α × β := prod α β
-- notation for n-ary tuples
/- sizeof -/
class has_sizeof (α : Sort u) :=
(sizeof : α → nat)
def sizeof {α : Sort u} [s : has_sizeof α] : α → nat :=
has_sizeof.sizeof
/-
Declare sizeof instances and lemmas for types declared before has_sizeof.
From now on, the inductive compiler will automatically generate sizeof instances and lemmas.
-/
/- Every type `α` has a default has_sizeof instance that just returns 0 for every element of `α` -/
protected def default.sizeof (α : Sort u) : α → nat
| a := 0
instance default_has_sizeof (α : Sort u) : has_sizeof α :=
⟨default.sizeof α⟩
protected def nat.sizeof : nat → nat
| n := n
instance : has_sizeof nat :=
⟨nat.sizeof⟩
protected def prod.sizeof {α : Type u} {β : Type v} [has_sizeof α] [has_sizeof β] : (prod α β) → nat
| ⟨a, b⟩ := 1 + sizeof a + sizeof b
instance (α : Type u) (β : Type v) [has_sizeof α] [has_sizeof β] : has_sizeof (prod α β) :=
⟨prod.sizeof⟩
protected def sum.sizeof {α : Type u} {β : Type v} [has_sizeof α] [has_sizeof β] : (sum α β) → nat
| (sum.inl a) := 1 + sizeof a
| (sum.inr b) := 1 + sizeof b
instance (α : Type u) (β : Type v) [has_sizeof α] [has_sizeof β] : has_sizeof (sum α β) :=
⟨sum.sizeof⟩
protected def sigma.sizeof {α : Type u} {β : α → Type v} [has_sizeof α] [∀ a, has_sizeof (β a)] : sigma β → nat
| ⟨a, b⟩ := 1 + sizeof a + sizeof b
instance (α : Type u) (β : α → Type v) [has_sizeof α] [∀ a, has_sizeof (β a)] : has_sizeof (sigma β) :=
⟨sigma.sizeof⟩
protected def unit.sizeof : unit → nat
| u := 1
instance : has_sizeof unit := ⟨unit.sizeof⟩
protected def punit.sizeof : punit → nat
| u := 1
instance : has_sizeof punit := ⟨punit.sizeof⟩
protected def bool.sizeof : bool → nat
| b := 1
instance : has_sizeof bool := ⟨bool.sizeof⟩
protected def pos_num.sizeof : pos_num → nat
| p := nat.of_pos_num p
instance : has_sizeof pos_num :=
⟨pos_num.sizeof⟩
protected def num.sizeof : num → nat
| n := nat.of_num n
instance : has_sizeof num :=
⟨num.sizeof⟩
protected def option.sizeof {α : Type u} [has_sizeof α] : option α → nat
| none := 1
| (some a) := 1 + sizeof a
instance (α : Type u) [has_sizeof α] : has_sizeof (option α) :=
⟨option.sizeof⟩
protected def list.sizeof {α : Type u} [has_sizeof α] : list α → nat
| list.nil := 1
| (list.cons a l) := 1 + sizeof a + list.sizeof l
instance (α : Type u) [has_sizeof α] : has_sizeof (list α) :=
⟨list.sizeof⟩
protected def subtype.sizeof {α : Type u} [has_sizeof α] {p : α → Prop} : subtype p → nat
| ⟨a, _⟩ := sizeof a
instance {α : Type u} [has_sizeof α] (p : α → Prop) : has_sizeof (subtype p) :=
⟨subtype.sizeof⟩
lemma nat_add_zero (n : nat) : n + 0 = n := rfl
/- Combinator calculus -/
namespace combinator
universes u₁ u₂ u₃
def I {α : Type u₁} (a : α) := a
def K {α : Type u₁} {β : Type u₂} (a : α) (b : β) := a
def S {α : Type u₁} {β : Type u₂} {γ : Type u₃} (x : α → β → γ) (y : α → β) (z : α) := x z (y z)
end combinator
/- Basic unification hints -/
@[unify] def add_succ_defeq_succ_add_hint (x y z : nat) : unification_hint :=
{ pattern := x + nat.succ y ≟ nat.succ z,
constraints := [z ≟ x + y] }
|
d454d132332738b0585ea60c41108d33475d93c1 | 43390109ab88557e6090f3245c47479c123ee500 | /src/M3P14/order.lean | 497b7a0b945f64d743b523afaff64a3a4b04c1a7 | [
"Apache-2.0"
] | permissive | Ja1941/xena-UROP-2018 | 41f0956519f94d56b8bf6834a8d39473f4923200 | b111fb87f343cf79eca3b886f99ee15c1dd9884b | refs/heads/master | 1,662,355,955,139 | 1,590,577,325,000 | 1,590,577,325,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,525 | lean | import data.nat.prime data.nat.gcd data.nat.modeq data.nat.gcd algebra.group chris_hughes_various.zmod group_theory.order_of_element M3P14.order_zmodn_kmb M3P14.Arithmetic_functions.phi
open zmod nat
@[simp] lemma units.coe_pow {α : Type*} [monoid α] (u : units α) (n : ℕ) : (↑(u ^ n) : α) = u ^ n :=
by induction n; simp [*, _root_.pow_succ]
-- Thanks Chris
lemma order_of_dvd_of_pow_eq_one {d n : ℕ} [pos_nat n] (a : units (zmod n)) (h : a ^ d = 1) : order_of a ∣ d :=
by_contradiction
(λ h₁, nat.find_min _ (show d % order_of a < order_of a,
from nat.mod_lt _ (nat.pos_of_ne_zero (order_of_ne_zero _)))
⟨mt nat.dvd_of_mod_eq_zero h₁, by rwa ← pow_eq_mod_order_of⟩)
/- DEFINITIONS -/
def units_zmod_mk (a n : ℕ ) (h : nat.coprime a n) [pos_nat n] : units (zmod n) :=
{
val := a,
inv := a⁻¹,
val_inv := by rw [mul_inv_eq_gcd n a, coprime.gcd_eq_one h];dsimp;rw zero_add,
inv_val := by rw [mul_comm, mul_inv_eq_gcd n a, coprime.gcd_eq_one h];dsimp;rw zero_add,
}
def order_of_zmod (a n : ℕ) [pos_nat n] : ℕ := if h : nat.coprime a n then @order_of (units (zmod n)) _ _ _ (units_zmod_mk a n h) else 0
def primitive_root (a n : ℕ) [pos_nat n] := coprime a n ∧ order_of_zmod a n = phi n
/- THEOREMS -/
theorem not_coprime_pow_mod (a d n : ℕ) (h1 : a ^ d ≡ 1 [MOD n]) (h2 : ¬coprime a n) : d = 0 := sorry
-- is that true?
theorem zmod_card_pow (a n d : ℕ) (h : coprime a n) [pos_nat n] : a^fintype.card (units (zmod n)) ≡ 1 [MOD n] := sorry
theorem order_zmod_div (a n d : ℕ) [pos_nat n] : a^d ≡ 1 [MOD n] → order_of_zmod a n ∣ d :=
begin
cases (classical.em (nat.coprime a n)),
intro h2,
unfold order_of_zmod,
cases (classical.em (nat.coprime a n)),
{
rw dif_pos h,
rw eq_iff_modeq_nat.symm at h2,
have pow : (units_zmod_mk a n h) ^ d = 1,
{ apply units.ext,
suffices : (↑(units_zmod_mk a n h ^ d) : zmod n) = 1,
simp [this],
have h2' : (↑(a ^ d) : zmod n) = 1,
rw h2,
simp,
rw ←h2',simp,refl,
},
exact order_of_dvd_of_pow_eq_one (units_zmod_mk a n h) pow,
},
exact absurd h h_1,
intro pow,
rw [order_of_zmod, dif_neg h],
suffices : d = 0, simp [this],
exact not_coprime_pow_mod a d n pow h,
end
theorem order_zmod_div_phi_n (a n : ℕ) (h : coprime a n) [pos_nat n] : order_of_zmod a n ∣ phi n :=
begin
have : a ^ (phi n) ≡ 1 [MOD n], from euler_phi_thm a n h,
exact order_zmod_div a n (phi n) this,
end
theorem pow_order_units_zmod_eq_one (a n : ℕ) [pos_nat n] (h : coprime a n) : (units_zmod_mk a n h) ^ order_of (units_zmod_mk a n h) = 1 :=
pow_order_of_eq_one (units_zmod_mk a n h)
theorem pow_order_zmod_eq_one (a n : ℕ) [pos_nat n] : (a : zmod n) ^ order_of_zmod a n = (1 : zmod n) :=
begin
have em : nat.coprime a n ∨ ¬ nat.coprime a n, from (classical.em (nat.coprime a n)),
unfold order_of_zmod,
cases em,
have one_eq : (1 : zmod n) = (1 : units (zmod n)), by simp,
rw [dif_pos em,units_zmod_mk, one_eq,←(pow_order_units_zmod_eq_one a n em)],
show ↑(units_zmod_mk a n em) ^ order_of (units_zmod_mk a n em) = ↑(units_zmod_mk a n em ^ order_of (units_zmod_mk a n em)),
simp,
rw dif_neg em,
refl,
end
theorem primitive_root_existence (n : ℕ) [pos_nat n] : ∃ a : ℕ, (primitive_root a n) ↔ n = 1 ∨ n = 2 ∨ n = 4 ∨ ∃ p r : ℕ, prime p ∧ r > 0 → (n = p^r ∨ n = 2*p^r) := sorry
|
3b4833a5cbc7c757bdd62d1fb99253d7fd03c4d4 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/measure_theory/covering/vitali_family.lean | 192072a166498ec25a05eb65e098a3b5deefe8ac | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 11,207 | lean | /-
Copyright (c) 2021 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 measure_theory.measure.measure_space
/-!
# Vitali families
On a metric space `X` with a measure `μ`, consider for each `x : X` a family of measurable sets with
nonempty interiors, called `sets_at x`. This family is a Vitali family if it satisfies the following
property: consider a (possibly non-measurable) set `s`, and for any `x` in `s` a
subfamily `f x` of `sets_at x` containing sets of arbitrarily small diameter. Then one can extract
a disjoint subfamily covering almost all `s`.
Vitali families are provided by covering theorems such as the Besicovitch covering theorem or the
Vitali covering theorem. They make it possible to formulate general versions of theorems on
differentiations of measure that apply in both contexts.
This file gives the basic definition of Vitali families. More interesting developments of this
notion are deferred to other files:
* constructions of specific Vitali families are provided by the Besicovitch covering theorem, in
`besicovitch.vitali_family`, and by the Vitali covering theorem, in `vitali.vitali_family`.
* The main theorem on differentiation of measures along a Vitali family is proved in
`vitali_family.ae_tendsto_rn_deriv`.
## Main definitions
* `vitali_family μ` is a structure made, for each `x : X`, of a family of sets around `x`, such that
one can extract an almost everywhere disjoint covering from any subfamily containing sets of
arbitrarily small diameters.
Let `v` be such a Vitali family.
* `v.fine_subfamily_on` describes the subfamilies of `v` from which one can extract almost
everywhere disjoint coverings. This property, called
`v.fine_subfamily_on.exists_disjoint_covering_ae`, is essentially a restatement of the definition
of a Vitali family. We also provide an API to use efficiently such a disjoint covering.
* `v.filter_at x` is a filter on sets of `X`, such that convergence with respect to this filter
means convergence when sets in the Vitali family shrink towards `x`.
## References
* [Herbert Federer, Geometric Measure Theory, Chapter 2.8][Federer1996] (Vitali families are called
Vitali relations there)
-/
open measure_theory metric set filter topological_space measure_theory.measure
open_locale filter measure_theory topological_space
variables {α : Type*} [metric_space α]
/-- On a metric space `X` with a measure `μ`, consider for each `x : X` a family of measurable sets
with nonempty interiors, called `sets_at x`. This family is a Vitali family if it satisfies the
following property: consider a (possibly non-measurable) set `s`, and for any `x` in `s` a
subfamily `f x` of `sets_at x` containing sets of arbitrarily small diameter. Then one can extract
a disjoint subfamily covering almost all `s`.
Vitali families are provided by covering theorems such as the Besicovitch covering theorem or the
Vitali covering theorem. They make it possible to formulate general versions of theorems on
differentiations of measure that apply in both contexts.
-/
@[nolint has_inhabited_instance]
structure vitali_family {m : measurable_space α} (μ : measure α) :=
(sets_at : Π (x : α), set (set α))
(measurable_set' : ∀ (x : α), ∀ (a : set α), a ∈ sets_at x → measurable_set a)
(nonempty_interior : ∀ (x : α), ∀ (y : set α), y ∈ sets_at x → (interior y).nonempty)
(nontrivial : ∀ (x : α) (ε > (0 : ℝ)), ∃ y ∈ sets_at x, y ⊆ closed_ball x ε)
(covering : ∀ (s : set α) (f : Π (x : α), set (set α)), (∀ x ∈ s, f x ⊆ sets_at x) →
(∀ (x ∈ s) (ε > (0 : ℝ)), ∃ a ∈ f x, a ⊆ closed_ball x ε) →
∃ (t : set α) (u : α → set α), t ⊆ s ∧ t.pairwise_disjoint u ∧ (∀ x ∈ t, u x ∈ f x)
∧ μ (s \ ⋃ x ∈ t, u x) = 0)
namespace vitali_family
variables {m0 : measurable_space α} {μ : measure α}
include μ
/-- A Vitali family for a measure `μ` is also a Vitali family for any measure absolutely continuous
with respect to `μ`. -/
def mono (v : vitali_family μ) (ν : measure α) (hν : ν ≪ μ) :
vitali_family ν :=
{ sets_at := v.sets_at,
measurable_set' := v.measurable_set',
nonempty_interior := v.nonempty_interior,
nontrivial := v.nontrivial,
covering := λ s f h h', begin
rcases v.covering s f h h' with ⟨t, u, ts, u_disj, uf, μu⟩,
exact ⟨t, u, ts, u_disj, uf, hν μu⟩
end }
/-- Given a Vitali family `v` for a measure `μ`, a family `f` is a fine subfamily on a set `s` if
every point `x` in `s` belongs to arbitrarily small sets in `v.sets_at x ∩ f x`. This is precisely
the subfamilies for which the Vitali family definition ensures that one can extract a disjoint
covering of almost all `s`. -/
def fine_subfamily_on (v : vitali_family μ) (f : α → set (set α)) (s : set α) : Prop :=
∀ x ∈ s, ∀ (ε > 0), ∃ a ∈ v.sets_at x ∩ f x, a ⊆ closed_ball x ε
namespace fine_subfamily_on
variables {v : vitali_family μ} {f : α → set (set α)} {s : set α} (h : v.fine_subfamily_on f s)
include h
theorem exists_disjoint_covering_ae :
∃ (t : set α) (u : α → set α), t ⊆ s ∧ t.pairwise_disjoint u ∧
(∀ x ∈ t, u x ∈ v.sets_at x ∩ f x) ∧ μ (s \ ⋃ x ∈ t, u x) = 0 :=
v.covering s (λ x, v.sets_at x ∩ f x) (λ x hx, inter_subset_left _ _) h
/-- Given `h : v.fine_subfamily_on f s`, then `h.index` is a subset of `s` parametrizing a disjoint
covering of almost every `s`. -/
protected def index : set α :=
h.exists_disjoint_covering_ae.some
/-- Given `h : v.fine_subfamily_on f s`, then `h.covering x` is a set in the family,
for `x ∈ h.index`, such that these sets form a disjoint covering of almost every `s`. -/
protected def covering : α → set α :=
h.exists_disjoint_covering_ae.some_spec.some
lemma index_subset : h.index ⊆ s :=
h.exists_disjoint_covering_ae.some_spec.some_spec.1
lemma covering_disjoint : h.index.pairwise_disjoint h.covering :=
h.exists_disjoint_covering_ae.some_spec.some_spec.2.1
lemma covering_disjoint_subtype : pairwise (disjoint on (λ x : h.index, h.covering x)) :=
(pairwise_subtype_iff_pairwise_set _ _).2 h.covering_disjoint
lemma covering_mem {x : α} (hx : x ∈ h.index) : h.covering x ∈ f x :=
(h.exists_disjoint_covering_ae.some_spec.some_spec.2.2.1 x hx).2
lemma covering_mem_family {x : α} (hx : x ∈ h.index) : h.covering x ∈ v.sets_at x :=
(h.exists_disjoint_covering_ae.some_spec.some_spec.2.2.1 x hx).1
lemma measure_diff_bUnion : μ (s \ ⋃ x ∈ h.index, h.covering x) = 0 :=
h.exists_disjoint_covering_ae.some_spec.some_spec.2.2.2
lemma index_countable [second_countable_topology α] : h.index.countable :=
h.covering_disjoint.countable_of_nonempty_interior
(λ x hx, v.nonempty_interior _ _ (h.covering_mem_family hx))
protected lemma measurable_set_u {x : α} (hx : x ∈ h.index) : measurable_set (h.covering x) :=
v.measurable_set' x _ (h.covering_mem_family hx)
lemma measure_le_tsum_of_absolutely_continuous [second_countable_topology α]
{ρ : measure α} (hρ : ρ ≪ μ) :
ρ s ≤ ∑' (x : h.index), ρ (h.covering x) :=
calc ρ s ≤ ρ ((s \ ⋃ (x ∈ h.index), h.covering x) ∪ (⋃ (x ∈ h.index), h.covering x)) :
measure_mono (by simp only [subset_union_left, diff_union_self])
... ≤ ρ (s \ ⋃ (x ∈ h.index), h.covering x) + ρ (⋃ (x ∈ h.index), h.covering x) :
measure_union_le _ _
... = ∑' (x : h.index), ρ (h.covering x) : by rw [hρ h.measure_diff_bUnion,
measure_bUnion h.index_countable h.covering_disjoint (λ x hx, h.measurable_set_u hx),
zero_add]
lemma measure_le_tsum [second_countable_topology α] :
μ s ≤ ∑' (x : h.index), μ (h.covering x) :=
h.measure_le_tsum_of_absolutely_continuous measure.absolutely_continuous.rfl
end fine_subfamily_on
variable (v : vitali_family μ)
include v
/-- Given a vitali family `v`, then `v.filter_at x` is the filter on `set α` made of those families
that contain all sets of `v.sets_at x` of a sufficiently small diameter. This filter makes it
possible to express limiting behavior when sets in `v.sets_at x` shrink to `x`. -/
def filter_at (x : α) : filter (set α) :=
⨅ (ε ∈ Ioi (0 : ℝ)), 𝓟 {a ∈ v.sets_at x | a ⊆ closed_ball x ε}
lemma mem_filter_at_iff {x : α} {s : set (set α)} :
(s ∈ v.filter_at x) ↔ ∃ (ε > (0 : ℝ)), ∀ a ∈ v.sets_at x, a ⊆ closed_ball x ε → a ∈ s :=
begin
simp only [filter_at, exists_prop, gt_iff_lt],
rw mem_binfi_of_directed,
{ simp only [subset_def, and_imp, exists_prop, mem_sep_eq, mem_Ioi, mem_principal] },
{ simp only [directed_on, exists_prop, ge_iff_le, le_principal_iff, mem_Ioi, order.preimage,
mem_principal],
assume x hx y hy,
refine ⟨min x y, lt_min hx hy,
λ a ha, ⟨ha.1, ha.2.trans (closed_ball_subset_closed_ball (min_le_left _ _))⟩,
λ a ha, ⟨ha.1, ha.2.trans (closed_ball_subset_closed_ball (min_le_right _ _))⟩⟩ },
{ exact ⟨(1 : ℝ), mem_Ioi.2 zero_lt_one⟩ }
end
instance filter_at_ne_bot (x : α) : (v.filter_at x).ne_bot :=
begin
simp only [ne_bot_iff, ←empty_mem_iff_bot, mem_filter_at_iff, not_exists, exists_prop,
mem_empty_eq, and_true, gt_iff_lt, not_and, ne.def, not_false_iff, not_forall],
assume ε εpos,
obtain ⟨w, w_sets, hw⟩ : ∃ (w ∈ v.sets_at x), w ⊆ closed_ball x ε := v.nontrivial x ε εpos,
exact ⟨w, w_sets, hw⟩
end
lemma eventually_filter_at_iff {x : α} {P : set α → Prop} :
(∀ᶠ a in v.filter_at x, P a) ↔ ∃ (ε > (0 : ℝ)), ∀ a ∈ v.sets_at x, a ⊆ closed_ball x ε → P a :=
v.mem_filter_at_iff
lemma eventually_filter_at_mem_sets (x : α) :
∀ᶠ a in v.filter_at x, a ∈ v.sets_at x :=
begin
simp only [eventually_filter_at_iff, exists_prop, and_true, gt_iff_lt,
implies_true_iff] {contextual := tt},
exact ⟨1, zero_lt_one⟩
end
lemma eventually_filter_at_measurable_set (x : α) :
∀ᶠ a in v.filter_at x, measurable_set a :=
by { filter_upwards [v.eventually_filter_at_mem_sets x] with _ ha using v.measurable_set' _ _ ha }
lemma frequently_filter_at_iff {x : α} {P : set α → Prop} :
(∃ᶠ a in v.filter_at x, P a) ↔ ∀ (ε > (0 : ℝ)), ∃ a ∈ v.sets_at x, a ⊆ closed_ball x ε ∧ P a :=
by simp only [filter.frequently, eventually_filter_at_iff, not_exists, exists_prop, not_and,
not_not, not_forall]
lemma eventually_filter_at_subset_of_nhds {x : α} {o : set α} (hx : o ∈ 𝓝 x) :
∀ᶠ a in v.filter_at x, a ⊆ o :=
begin
rw eventually_filter_at_iff,
rcases metric.mem_nhds_iff.1 hx with ⟨ε, εpos, hε⟩,
exact ⟨ε/2, half_pos εpos,
λ a av ha, ha.trans ((closed_ball_subset_ball (half_lt_self εpos)).trans hε)⟩
end
lemma fine_subfamily_on_of_frequently (v : vitali_family μ) (f : α → set (set α)) (s : set α)
(h : ∀ x ∈ s, ∃ᶠ a in v.filter_at x, a ∈ f x) :
v.fine_subfamily_on f s :=
begin
assume x hx ε εpos,
obtain ⟨a, av, ha, af⟩ : ∃ (a : set α) (H : a ∈ v.sets_at x), a ⊆ closed_ball x ε ∧ a ∈ f x :=
v.frequently_filter_at_iff.1 (h x hx) ε εpos,
exact ⟨a, ⟨av, af⟩, ha⟩,
end
end vitali_family
|
f889699849fa6a8793ccfdb8e5ff9fbb078c91d2 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/algebra/big_operators/finprod.lean | c6ee44781047d67451d8c7a88b7175103b99bef9 | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 36,772 | lean | /-
Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov
-/
import algebra.big_operators.order
import algebra.indicator_function
import data.set.pairwise
/-!
# Finite products and sums over types and sets
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than `finset.sum`,
when issues arise with `finset` and `fintype` being data.
## Main definitions
We use the following variables:
* `α`, `β` - types with no structure;
* `s`, `t` - sets
* `M`, `N` - additive or multiplicative commutative monoids
* `f`, `g` - functions
Definitions in this file:
* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.
Zero otherwise.
* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if
it's finite. One otherwise.
## Notation
* `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f`
* `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f`
This notation works for functions `f : p → M`, where `p : Prop`, so the following works:
* `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : set α` : sum over the set `s`;
* `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;
* `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.
## Implementation notes
`finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and
`fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump”
function. In this case the finite set depends on the point and it's convenient to have a definition
that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
## Todo
We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`.
There is work on `fincard` in the pipeline, which returns the cardinality of `X` if it
is finite, and 0 otherwise.
## Tags
finsum, finprod, finite sum, finite product
-/
open function set
/-!
### Definition and relation to `finset.sum` and `finset.prod`
-/
section sort
variables {M N : Type*} {α β ι : Sort*} [comm_monoid M] [comm_monoid N]
open_locale big_operators
section
/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas
with `classical.dec` in their statement. -/
open_locale classical
/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero
otherwise. -/
@[irreducible] noncomputable def finsum {M α} [add_comm_monoid M] (f : α → M) : M :=
if h : finite (support (f ∘ plift.down)) then ∑ i in h.to_finset, f i.down else 0
/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's
finite. One otherwise. -/
@[irreducible, to_additive]
noncomputable def finprod (f : α → M) : M :=
if h : finite (mul_support (f ∘ plift.down)) then ∏ i in h.to_finset, f i.down else 1
end
localized "notation `∑ᶠ` binders `, ` r:(scoped:67 f, finsum f) := r" in big_operators
localized "notation `∏ᶠ` binders `, ` r:(scoped:67 f, finprod f) := r" in big_operators
@[to_additive] lemma finprod_eq_prod_plift_of_mul_support_to_finset_subset
{f : α → M} (hf : finite (mul_support (f ∘ plift.down))) {s : finset (plift α)}
(hs : hf.to_finset ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i.down :=
begin
rw [finprod, dif_pos],
refine finset.prod_subset hs (λ x hx hxf, _),
rwa [hf.mem_to_finset, nmem_mul_support] at hxf
end
@[to_additive] lemma finprod_eq_prod_plift_of_mul_support_subset
{f : α → M} {s : finset (plift α)} (hs : mul_support (f ∘ plift.down) ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i.down :=
finprod_eq_prod_plift_of_mul_support_to_finset_subset
(s.finite_to_set.subset hs) $ λ x hx, by { rw finite.mem_to_finset at hx, exact hs hx }
@[simp, to_additive] lemma finprod_one : ∏ᶠ i : α, (1 : M) = 1 :=
begin
have : mul_support (λ x : plift α, (λ _, 1 : α → M) x.down) ⊆ (∅ : finset (plift α)),
from λ x h, h rfl,
rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_empty]
end
@[to_additive] lemma finprod_of_is_empty [is_empty α] (f : α → M) : ∏ᶠ i, f i = 1 :=
by { rw ← finprod_one, congr }
@[simp, to_additive] lemma finprod_false (f : false → M) : ∏ᶠ i, f i = 1 :=
finprod_of_is_empty _
@[to_additive] lemma finprod_eq_single (f : α → M) (a : α) (ha : ∀ x ≠ a, f x = 1) :
∏ᶠ x, f x = f a :=
begin
have : mul_support (f ∘ plift.down) ⊆ ({plift.up a} : finset (plift α)),
{ intro x, contrapose,
simpa [plift.eq_up_iff_down_eq] using ha x.down },
rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_singleton],
end
@[to_additive] lemma finprod_unique [unique α] (f : α → M) : ∏ᶠ i, f i = f (default α) :=
finprod_eq_single f (default α) $ λ x hx, (hx $ unique.eq_default _).elim
@[simp, to_additive] lemma finprod_true (f : true → M) : ∏ᶠ i, f i = f trivial :=
@finprod_unique M true _ ⟨⟨trivial⟩, λ _, rfl⟩ f
@[to_additive] lemma finprod_eq_dif {p : Prop} [decidable p] (f : p → M) :
∏ᶠ i, f i = if h : p then f h else 1 :=
begin
split_ifs,
{ haveI : unique p := ⟨⟨h⟩, λ _, rfl⟩, exact finprod_unique f },
{ haveI : is_empty p := ⟨h⟩, exact finprod_of_is_empty f }
end
@[to_additive] lemma finprod_eq_if {p : Prop} [decidable p] {x : M} :
∏ᶠ i : p, x = if p then x else 1 :=
finprod_eq_dif (λ _, x)
@[to_additive] lemma finprod_congr {f g : α → M} (h : ∀ x, f x = g x) :
finprod f = finprod g :=
congr_arg _ $ funext h
@[congr, to_additive] lemma finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q)
(hfg : ∀ h : q, f (hpq.mpr h) = g h) :
finprod f = finprod g :=
by { subst q, exact finprod_congr hfg }
attribute [congr] finsum_congr_Prop
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on multipliers. -/
@[to_additive] lemma finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) :
p (∏ᶠ i, f i) :=
begin
rw finprod,
split_ifs,
exacts [finset.prod_induction _ _ hp₁ hp₀ (λ i hi, hp₂ _), hp₀]
end
/-- To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on summands. -/
add_decl_doc finsum_induction
lemma finprod_nonneg {R : Type*} [ordered_comm_semiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) :
0 ≤ ∏ᶠ x, f x :=
finprod_induction (λ x, 0 ≤ x) zero_le_one (λ x y, mul_nonneg) hf
@[to_additive finsum_nonneg]
lemma one_le_finprod' {M : Type*} [ordered_comm_monoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) :
1 ≤ ∏ᶠ i, f i :=
finprod_induction _ le_rfl (λ _ _, one_le_mul) hf
@[to_additive] lemma monoid_hom.map_finprod_plift (f : M →* N) (g : α → M)
(h : finite (mul_support $ g ∘ plift.down)) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
begin
rw [finprod_eq_prod_plift_of_mul_support_subset h.coe_to_finset.ge,
finprod_eq_prod_plift_of_mul_support_subset, f.map_prod],
rw [h.coe_to_finset],
exact mul_support_comp_subset f.map_one (g ∘ plift.down)
end
@[to_additive] lemma monoid_hom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
f.map_finprod_plift g (finite.of_fintype _)
end sort
section type
variables {α β ι M N : Type*} [comm_monoid M] [comm_monoid N]
open_locale big_operators
@[to_additive] lemma finprod_eq_mul_indicator_apply (s : set α)
(f : α → M) (a : α) :
∏ᶠ (h : a ∈ s), f a = mul_indicator s f a :=
by convert finprod_eq_if
@[simp, to_additive] lemma finprod_mem_mul_support (f : α → M) (a : α) :
∏ᶠ (h : f a ≠ 1), f a = f a :=
by rw [← mem_mul_support, finprod_eq_mul_indicator_apply, mul_indicator_mul_support]
@[to_additive] lemma finprod_mem_def (s : set α) (f : α → M) :
∏ᶠ a ∈ s, f a = ∏ᶠ a, mul_indicator s f a :=
finprod_congr $ finprod_eq_mul_indicator_apply s f
@[to_additive] lemma finprod_eq_prod_of_mul_support_subset (f : α → M) {s : finset α}
(h : mul_support f ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i :=
begin
have A : mul_support (f ∘ plift.down) = equiv.plift.symm '' mul_support f,
{ rw mul_support_comp_eq_preimage,
exact (equiv.plift.symm.image_eq_preimage _).symm },
have : mul_support (f ∘ plift.down) ⊆ s.map equiv.plift.symm.to_embedding,
{ rw [A, finset.coe_map], exact image_subset _ h },
rw [finprod_eq_prod_plift_of_mul_support_subset this],
simp
end
@[to_additive] lemma finprod_eq_prod_of_mul_support_to_finset_subset (f : α → M)
(hf : finite (mul_support f)) {s : finset α} (h : hf.to_finset ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i :=
finprod_eq_prod_of_mul_support_subset _ $ λ x hx, h $ hf.mem_to_finset.2 hx
@[to_additive] lemma finprod_def (f : α → M) [decidable (mul_support f).finite] :
∏ᶠ i : α, f i = if h : (mul_support f).finite then ∏ i in h.to_finset, f i else 1 :=
begin
split_ifs,
{ exact finprod_eq_prod_of_mul_support_to_finset_subset _ h (finset.subset.refl _) },
{ rw [finprod, dif_neg],
rw [mul_support_comp_eq_preimage],
exact mt (λ hf, hf.of_preimage equiv.plift.surjective) h}
end
@[to_additive] lemma finprod_of_infinite_mul_support {f : α → M} (hf : (mul_support f).infinite) :
∏ᶠ i, f i = 1 :=
by { classical, rw [finprod_def, dif_neg hf] }
@[to_additive] lemma finprod_eq_prod (f : α → M) (hf : (mul_support f).finite) :
∏ᶠ i : α, f i = ∏ i in hf.to_finset, f i :=
by { classical, rw [finprod_def, dif_pos hf] }
@[to_additive] lemma finprod_eq_prod_of_fintype [fintype α] (f : α → M) :
∏ᶠ i : α, f i = ∏ i, f i :=
finprod_eq_prod_of_mul_support_to_finset_subset _ (finite.of_fintype _) $ finset.subset_univ _
@[to_additive] lemma finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : finset α}
(h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) :
∏ᶠ i (hi : p i), f i = ∏ i in t, f i :=
begin
set s := {x | p x},
have : mul_support (s.mul_indicator f) ⊆ t,
{ rw [set.mul_support_mul_indicator], intros x hx, exact (h hx.2).1 hx.1 },
erw [finprod_mem_def, finprod_eq_prod_of_mul_support_subset _ this],
refine finset.prod_congr rfl (λ x hx, mul_indicator_apply_eq_self.2 $ λ hxs, _),
contrapose! hxs,
exact (h hxs).2 hx
end
@[to_additive] lemma finprod_mem_eq_prod_of_inter_mul_support_eq (f : α → M) {s : set α}
{t : finset α} (h : s ∩ mul_support f = t ∩ mul_support f) :
∏ᶠ i ∈ s, f i = ∏ i in t, f i :=
finprod_cond_eq_prod_of_cond_iff _ $ by simpa [set.ext_iff] using h
@[to_additive] lemma finprod_mem_eq_prod_of_subset (f : α → M) {s : set α} {t : finset α}
(h₁ : s ∩ mul_support f ⊆ t) (h₂ : ↑t ⊆ s) :
∏ᶠ i ∈ s, f i = ∏ i in t, f i :=
finprod_cond_eq_prod_of_cond_iff _ $ λ x hx, ⟨λ h, h₁ ⟨h, hx⟩, λ h, h₂ h⟩
@[to_additive] lemma finprod_mem_eq_prod (f : α → M) {s : set α}
(hf : (s ∩ mul_support f).finite) :
∏ᶠ i ∈ s, f i = ∏ i in hf.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_assoc]
@[to_additive] lemma finprod_mem_eq_prod_filter (f : α → M) (s : set α) [decidable_pred (∈ s)]
(hf : (mul_support f).finite) :
∏ᶠ i ∈ s, f i = ∏ i in finset.filter (∈ s) hf.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_comm, inter_left_comm]
@[to_additive] lemma finprod_mem_eq_to_finset_prod (f : α → M) (s : set α) [fintype s] :
∏ᶠ i ∈ s, f i = ∏ i in s.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [coe_to_finset]
@[to_additive] lemma finprod_mem_eq_finite_to_finset_prod (f : α → M) {s : set α} (hs : s.finite) :
∏ᶠ i ∈ s, f i = ∏ i in hs.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [hs.coe_to_finset]
@[to_additive] lemma finprod_mem_finset_eq_prod (f : α → M) (s : finset α) :
∏ᶠ i ∈ s, f i = ∏ i in s, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl
@[to_additive] lemma finprod_mem_coe_finset (f : α → M) (s : finset α) :
∏ᶠ i ∈ (s : set α), f i = ∏ i in s, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl
@[to_additive] lemma finprod_mem_eq_one_of_infinite {f : α → M} {s : set α}
(hs : (s ∩ mul_support f).infinite) : ∏ᶠ i ∈ s, f i = 1 :=
begin
rw finprod_mem_def,
apply finprod_of_infinite_mul_support,
rwa [← mul_support_mul_indicator] at hs
end
@[to_additive] lemma finprod_mem_inter_mul_support (f : α → M) (s : set α) :
∏ᶠ i ∈ (s ∩ mul_support f), f i = ∏ᶠ i ∈ s, f i :=
by rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support]
@[to_additive] lemma finprod_mem_inter_mul_support_eq (f : α → M) (s t : set α)
(h : s ∩ mul_support f = t ∩ mul_support f) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_support, h, finprod_mem_inter_mul_support]
@[to_additive] lemma finprod_mem_inter_mul_support_eq' (f : α → M) (s t : set α)
(h : ∀ x ∈ mul_support f, x ∈ s ↔ x ∈ t) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i :=
begin
apply finprod_mem_inter_mul_support_eq,
ext x,
exact and_congr_left (h x)
end
@[to_additive] lemma finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @set.univ α, f i = ∏ᶠ i : α, f i :=
finprod_congr $ λ i, finprod_true _
variables {f g : α → M} {a b : α} {s t : set α}
@[to_additive] lemma finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i :=
h₀.symm ▸ (finprod_congr $ λ i, finprod_congr_Prop rfl (h₁ i))
/-!
### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication
-/
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals
the product of `f i` multiplied by the product over `g i`. -/
@[to_additive] lemma finprod_mul_distrib (hf : (mul_support f).finite)
(hg : (mul_support g).finite) :
∏ᶠ i, (f i * g i) = (∏ᶠ i, f i) * ∏ᶠ i, g i :=
begin
classical,
rw [finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_union_left _ _),
finprod_eq_prod_of_mul_support_to_finset_subset _ hg (finset.subset_union_right _ _),
← finset.prod_mul_distrib],
refine finprod_eq_prod_of_mul_support_subset _ _,
simp [mul_support_mul]
end
/-- A more general version of `finprod_mem_mul_distrib` that requires `s ∩ mul_support f` and
`s ∩ mul_support g` instead of `s` to be finite. -/
@[to_additive] lemma finprod_mem_mul_distrib' (hf : (s ∩ mul_support f).finite)
(hg : (s ∩ mul_support g).finite) :
∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i :=
begin
rw [← mul_support_mul_indicator] at hf hg,
simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg]
end
/-- The product of constant one over any set equals one. -/
@[to_additive] lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp
/-- If a function `f` equals one on a set `s`, then the product of `f i` over `i ∈ s` equals one. -/
@[to_additive] lemma finprod_mem_of_eq_on_one (hf : eq_on f 1 s) : ∏ᶠ i ∈ s, f i = 1 :=
by { rw ← finprod_mem_one s, exact finprod_mem_congr rfl hf }
/-- If the product of `f i` over `i ∈ s` is not equal to one, then there is some `x ∈ s`
such that `f x ≠ 1`. -/
@[to_additive] lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) :
∃ x ∈ s, f x ≠ 1 :=
begin
by_contra h', push_neg at h',
exact h (finprod_mem_of_eq_on_one h')
end
/-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i`
over `i ∈ s` times the product of `g i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_mul_distrib (hs : s.finite) :
∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i :=
finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _)
@[to_additive] lemma monoid_hom.map_finprod {f : α → M} (g : M →* N) (hf : (mul_support f).finite) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_plift f $ hf.preimage $ equiv.plift.injective.inj_on _
/-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` and
instead of `s` to be finite. -/
@[to_additive] lemma monoid_hom.map_finprod_mem' {f : α → M} (g : M →* N)
(h₀ : (s ∩ mul_support f).finite) :
g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, (g (f i)) :=
begin
rw [g.map_finprod],
{ simp only [g.map_finprod_Prop] },
{ simpa only [finprod_eq_mul_indicator_apply, mul_support_mul_indicator] }
end
/-- Given a monoid homomorphism `g : M →* N`, and a function `f : α → M`, the value of `g` at the
product of `f i` over `i ∈ s` equals the product of `(g ∘ f) i` over `s`. -/
@[to_additive] lemma monoid_hom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.finite) :
g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) :=
g.map_finprod_mem' (hs.inter_of_left _)
/-!
### `∏ᶠ x ∈ s, f x` and set operations
-/
/-- The product of any function over an empty set is one. -/
@[to_additive] lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp
/-- A set `s` is not empty if the product of some function over `s` is not equal to one. -/
@[to_additive] lemma nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.nonempty :=
ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ finprod_mem_empty
/-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of
`f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i`
over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_union_inter (hs : s.finite) (ht : t.finite) :
(∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
begin
unfreezingI { lift s to finset α using hs, lift t to finset α using ht },
classical,
rw [← finset.coe_union, ← finset.coe_inter],
simp only [finprod_mem_coe_finset, finset.prod_union_inter]
end
/-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be finite. -/
@[to_additive] lemma finprod_mem_union_inter'
(hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) :
(∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
begin
rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t,
← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support,
← finprod_mem_inter_mul_support f (s ∩ t)],
congr' 2,
rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm]
end
/-- A more general version of `finprod_mem_union` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be finite. -/
@[to_additive] lemma finprod_mem_union' (hst : disjoint s t) (hs : (s ∩ mul_support f).finite)
(ht : (t ∩ mul_support f).finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty,
mul_one]
/-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the
product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_union (hst : disjoint s t) (hs : s.finite) (ht : t.finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _)
/-- A more general version of `finprod_mem_union'` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be disjoint -/
@[to_additive] lemma finprod_mem_union'' (hst : disjoint (s ∩ mul_support f) (t ∩ mul_support f))
(hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t,
← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support]
/-- The product of `f i` over `i ∈ {a}` equals `f a`. -/
@[to_additive] lemma finprod_mem_singleton : ∏ᶠ i ∈ ({a} : set α), f i = f a :=
by rw [← finset.coe_singleton, finprod_mem_coe_finset, finset.prod_singleton]
@[simp, to_additive] lemma finprod_cond_eq_left : ∏ᶠ i = a, f i = f a :=
finprod_mem_singleton
@[simp, to_additive] lemma finprod_cond_eq_right : ∏ᶠ i (hi : a = i), f i = f a :=
by simp [@eq_comm _ a]
/-- A more general version of `finprod_mem_insert` that requires `s ∩ mul_support f` instead of
`s` to be finite. -/
@[to_additive] lemma finprod_mem_insert' (f : α → M) (h : a ∉ s)
(hs : (s ∩ mul_support f).finite) :
∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i :=
begin
rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton],
{ rwa disjoint_singleton_left },
{ exact (finite_singleton a).inter_of_left _ }
end
/-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals
`f a` times the product of `f i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.finite) :
∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i :=
finprod_mem_insert' f h $ hs.inter_of_left _
/-- If `f a = 1` for all `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the
product of `f i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) :
∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i :=
begin
refine finprod_mem_inter_mul_support_eq' _ _ _ (λ x hx, ⟨_, or.inr⟩),
rintro (rfl|hxs),
exacts [not_imp_comm.1 h hx, hxs]
end
/-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over
`i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert_one (h : f a = 1) :
∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i :=
finprod_mem_insert_of_eq_one_if_not_mem (λ _, h)
/-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/
@[to_additive] lemma finprod_mem_pair (h : a ≠ b) : ∏ᶠ i ∈ ({a, b} : set α), f i = f a * f b :=
by { rw [finprod_mem_insert, finprod_mem_singleton], exacts [h, finite_singleton b] }
/-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s`
provided that `g` is injective on `s ∩ mul_support (f ∘ g)`. -/
@[to_additive] lemma finprod_mem_image' {s : set β} {g : β → α}
(hg : set.inj_on g (s ∩ mul_support (f ∘ g))) :
∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) :=
begin
classical,
by_cases hs : finite (s ∩ mul_support (f ∘ g)),
{ have hg : ∀ (x ∈ hs.to_finset) (y ∈ hs.to_finset), g x = g y → x = y,
by simpa only [hs.mem_to_finset],
rw [finprod_mem_eq_prod _ hs, ← finset.prod_image hg],
refine finprod_mem_eq_prod_of_inter_mul_support_eq f _,
rw [finset.coe_image, hs.coe_to_finset, ← image_inter_mul_support_eq, inter_assoc,
inter_self] },
{ rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite],
rwa [image_inter_mul_support_eq, infinite_image_iff hg] }
end
/-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s`
provided that `g` is injective on `s`. -/
@[to_additive] lemma finprod_mem_image {β} {s : set β} {g : β → α} (hg : set.inj_on g s) :
∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) :=
finprod_mem_image' $ hg.mono $ inter_subset_left _ _
/-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i`
provided that `g` is injective on `mul_support (f ∘ g)`. -/
@[to_additive] lemma finprod_mem_range' {g : β → α} (hg : set.inj_on g (mul_support (f ∘ g))) :
∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) :=
begin
rw [← image_univ, finprod_mem_image', finprod_mem_univ],
rwa univ_inter
end
/-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i`
provided that `g` is injective. -/
@[to_additive] lemma finprod_mem_range {g : β → α} (hg : injective g) :
∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) :=
finprod_mem_range' (hg.inj_on _)
/-- The product of `f i` over `s : set α` is equal to the product of `g j` over `t : set β`
if there exists a function `e : α → β` such that `e` is bijective from `s` to `t` and for all
`x` in `s` we have `f x = g (e x)`. -/
@[to_additive] lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M}
(e : α → β) (he₀ : set.bij_on e s t) (he₁ : ∀ x ∈ s, f x = g (e x)) :
∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j :=
begin
rw [← set.bij_on.image_eq he₀, finprod_mem_image he₀.2.1],
exact finprod_mem_congr rfl he₁
end
@[to_additive] lemma finprod_set_coe_eq_finprod_mem (s : set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i :=
begin
rw [← finprod_mem_range, subtype.range_coe],
exact subtype.coe_injective
end
@[to_additive] lemma finprod_subtype_eq_finprod_cond (p : α → Prop) :
∏ᶠ j : subtype p, f j = ∏ᶠ i (hi : p i), f i :=
finprod_set_coe_eq_finprod_mem {i | p i}
@[to_additive] lemma finprod_mem_inter_mul_diff' (t : set α) (h : (s ∩ mul_support f).finite) :
(∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i :=
begin
rw [← finprod_mem_union', inter_union_diff],
exacts [λ x hx, hx.2.2 hx.1.2, h.subset (λ x hx, ⟨hx.1.1, hx.2⟩),
h.subset (λ x hx, ⟨hx.1.1, hx.2⟩)],
end
@[to_additive] lemma finprod_mem_inter_mul_diff (t : set α) (h : s.finite) :
(∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i :=
finprod_mem_inter_mul_diff' _ $ h.inter_of_left _
/-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mul_support f` instead of
`t` to be finite. -/
@[to_additive] lemma finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mul_support f).finite) :
(∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst]
/-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s`
times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.finite) :
(∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i :=
finprod_mem_mul_diff' hst (ht.inter_of_left _)
/-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type,
the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i`
of the products of `f a` over `a ∈ t i`. -/
@[to_additive] lemma finprod_mem_Union [fintype ι] {t : ι → set α}
(h : pairwise (disjoint on t)) (ht : ∀ i, (t i).finite) :
∏ᶠ a ∈ (⋃ i : ι, t i), f a = ∏ᶠ i, (∏ᶠ a ∈ t i, f a) :=
begin
unfreezingI { lift t to ι → finset α using ht },
classical,
rw [← bUnion_univ, ← finset.coe_univ, ← finset.coe_bUnion,
finprod_mem_coe_finset, finset.prod_bUnion],
{ simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] },
{ exact λ x _ y _ hxy, finset.disjoint_iff_disjoint_coe.2 (h x y hxy) }
end
/-- Given a family of sets `t : ι → set α`, a finite set `I` in the index type such that all
sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then
the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I`
of the products of `f a` over `a ∈ t i`. -/
@[to_additive] lemma finprod_mem_bUnion {I : set ι} {t : ι → set α}
(h : pairwise_on I (disjoint on t)) (hI : I.finite) (ht : ∀ i ∈ I, (t i).finite) :
∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j :=
begin
haveI := hI.fintype,
rw [← Union_subtype, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem],
exacts [λ x y hxy, h x x.2 y y.2 (subtype.coe_injective.ne hxy), λ b, ht b b.2]
end
/-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a`
over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/
@[to_additive] lemma finprod_mem_sUnion {t : set (set α)} (h : pairwise_on t disjoint)
(ht₀ : t.finite) (ht₁ : ∀ x ∈ t, set.finite x):
∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a :=
by rw [set.sUnion_eq_bUnion, finprod_mem_bUnion h ht₀ ht₁]
/-- If `s : set α` and `t : set β` are finite sets, then the product over `s` commutes
with the product over `t`. -/
@[to_additive] lemma finprod_mem_comm {s : set α} {t : set β}
(f : α → β → M) (hs : s.finite) (ht : t.finite) :
∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j :=
begin
unfreezingI { lift s to finset α using hs, lift t to finset β using ht },
simp only [finprod_mem_coe_finset],
exact finset.prod_comm
end
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on multipliers. -/
@[to_additive] lemma finprod_mem_induction (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p $ f x) :
p (∏ᶠ i ∈ s, f i) :=
finprod_induction _ hp₀ hp₁ $ λ x, finprod_induction _ hp₀ hp₁ $ hp₂ x
lemma finprod_cond_nonneg {R : Type*} [ordered_comm_semiring R] {p : α → Prop} {f : α → R}
(hf : ∀ x, p x → 0 ≤ f x) :
0 ≤ ∏ᶠ x (h : p x), f x :=
finprod_nonneg $ λ x, finprod_nonneg $ hf x
@[to_additive]
lemma single_le_finprod {M : Type*} [ordered_comm_monoid M] (i : α) {f : α → M}
(hf : finite (mul_support f)) (h : ∀ j, 1 ≤ f j) :
f i ≤ ∏ᶠ j, f j :=
by classical;
calc f i ≤ ∏ j in insert i hf.to_finset, f j :
finset.single_le_prod' (λ j hj, h j) (finset.mem_insert_self _ _)
... = ∏ᶠ j, f j :
(finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_insert _ _)).symm
lemma finprod_eq_zero {M₀ : Type*} [comm_monoid_with_zero M₀] (f : α → M₀) (x : α)
(hx : f x = 0) (hf : finite (mul_support f)) :
∏ᶠ x, f x = 0 :=
begin
nontriviality,
rw [finprod_eq_prod f hf],
refine finset.prod_eq_zero (hf.mem_to_finset.2 _) hx,
simp [hx]
end
@[to_additive] lemma finprod_prod_comm (s : finset β) (f : α → β → M)
(h : ∀ b ∈ s, (mul_support (λ a, f a b)).finite) :
∏ᶠ a : α, ∏ b in s, f a b = ∏ b in s, ∏ᶠ a : α, f a b :=
begin
have hU : mul_support (λ a, ∏ b in s, f a b) ⊆
(s.finite_to_set.bUnion (λ b hb, h b (finset.mem_coe.1 hb))).to_finset,
{ rw finite.coe_to_finset,
intros x hx,
simp only [exists_prop, mem_Union, ne.def, mem_mul_support, finset.mem_coe],
contrapose! hx,
rw [mem_mul_support, not_not, finset.prod_congr rfl hx, finset.prod_const_one] },
rw [finprod_eq_prod_of_mul_support_subset _ hU, finset.prod_comm],
refine finset.prod_congr rfl (λ b hb, (finprod_eq_prod_of_mul_support_subset _ _).symm),
intros a ha,
simp only [finite.coe_to_finset, mem_Union],
exact ⟨b, hb, ha⟩
end
@[to_additive] lemma prod_finprod_comm (s : finset α) (f : α → β → M)
(h : ∀ a ∈ s, (mul_support (f a)).finite) :
∏ a in s, ∏ᶠ b : β, f a b = ∏ᶠ b : β, ∏ a in s, f a b :=
(finprod_prod_comm s (λ b a, f a b) h).symm
lemma mul_finsum {R : Type*} [semiring R] (f : α → R) (r : R)
(h : (function.support f).finite) :
r * ∑ᶠ a : α, f a = ∑ᶠ a : α, r * f a :=
(add_monoid_hom.mul_left r).map_finsum h
lemma finsum_mul {R : Type*} [semiring R] (f : α → R) (r : R)
(h : (function.support f).finite) :
(∑ᶠ a : α, f a) * r = ∑ᶠ a : α, f a * r :=
(add_monoid_hom.mul_right r).map_finsum h
@[to_additive] lemma finset.mul_support_of_fiberwise_prod_subset_image [decidable_eq β]
(s : finset α) (f : α → M) (g : α → β) :
mul_support (λ b, (s.filter (λ a, g a = b)).prod f) ⊆ s.image g :=
begin
simp only [finset.coe_image, set.mem_image, finset.mem_coe, function.support_subset_iff],
intros b h,
suffices : (s.filter (λ (a : α), g a = b)).nonempty,
{ simpa only [s.fiber_nonempty_iff_mem_image g b, finset.mem_image, exists_prop], },
exact finset.nonempty_of_prod_ne_one h,
end
/-- Note that `b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd` iff `(a, b) ∈ s` so we can
simplify the right hand side of this lemma. However the form stated here is more useful for
iterating this lemma, e.g., if we have `f : α × β × γ → M`. -/
@[to_additive] lemma finprod_mem_finset_product' [decidable_eq α] [decidable_eq β]
(s : finset (α × β)) (f : α × β → M) :
∏ᶠ ab (h : ab ∈ s), f ab =
∏ᶠ a b (h : b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd), f (a, b) :=
begin
have : ∀ a, ∏ (i : β) in (s.filter (λ ab, prod.fst ab = a)).image prod.snd, f (a, i) =
(finset.filter (λ ab, prod.fst ab = a) s).prod f,
{ intros a, apply finset.prod_bij (λ b _, (a, b)); finish, },
rw finprod_mem_finset_eq_prod,
simp_rw [finprod_mem_finset_eq_prod, this],
rw [finprod_eq_prod_of_mul_support_subset _
(s.mul_support_of_fiberwise_prod_subset_image f prod.fst),
← finset.prod_fiberwise_of_maps_to _ f],
finish,
end
/-- See also `finprod_mem_finset_product'`. -/
@[to_additive] lemma finprod_mem_finset_product (s : finset (α × β)) (f : α × β → M) :
∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : (a, b) ∈ s), f (a, b) :=
by { classical, rw finprod_mem_finset_product', simp, }
@[to_additive] lemma finprod_mem_finset_product₃ {γ : Type*}
(s : finset (α × β × γ)) (f : α × β × γ → M) :
∏ᶠ abc (h : abc ∈ s), f abc = ∏ᶠ a b c (h : (a, b, c) ∈ s), f (a, b, c) :=
by { classical, rw finprod_mem_finset_product', simp_rw finprod_mem_finset_product', simp, }
@[to_additive] lemma finprod_curry (f : α × β → M) (hf : (mul_support f).finite) :
∏ᶠ ab, f ab = ∏ᶠ a b, f (a, b) :=
begin
have h₁ : ∀ a, ∏ᶠ (h : a ∈ hf.to_finset), f a = f a, { simp, },
have h₂ : ∏ᶠ a, f a = ∏ᶠ a (h : a ∈ hf.to_finset), f a, { simp, },
simp_rw [h₂, finprod_mem_finset_product, h₁],
end
@[to_additive] lemma finprod_curry₃ {γ : Type*} (f : α × β × γ → M) (h : (mul_support f).finite) :
∏ᶠ abc, f abc = ∏ᶠ a b c, f (a, b, c) :=
by { rw finprod_curry f h, congr, ext a, rw finprod_curry, simp [h], }
@[to_additive]
lemma finprod_dmem {s : set α} [decidable_pred (∈ s)] (f : (Π (a : α), a ∈ s → M)) :
∏ᶠ (a : α) (h : a ∈ s), f a h = ∏ᶠ (a : α) (h : a ∈ s), if h' : a ∈ s then f a h' else 1 :=
finprod_congr (λ a, finprod_congr (λ ha, (dif_pos ha).symm))
@[to_additive]
lemma finprod_emb_domain' {f : α → β} (hf : function.injective f)
[decidable_pred (∈ set.range f)] (g : α → M) :
∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a :=
begin
simp_rw [← finprod_eq_dif],
rw [finprod_dmem, finprod_mem_range hf, finprod_congr (λ a, _)],
rw [dif_pos (set.mem_range_self a), hf (classical.some_spec (set.mem_range_self a))]
end
@[to_additive]
lemma finprod_emb_domain (f : α ↪ β) [decidable_pred (∈ set.range f)] (g : α → M) :
∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a :=
finprod_emb_domain' f.injective g
end type
|
e5bd5d85c1d8b924a6c0c0ec12f3d858746ce766 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/algebra/ordered_field.lean | 50d3a5c77dbc967df84665ae55eeadc24a106d2b | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,380 | 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.ordered_ring
import algebra.field
/-!
### 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 : α}
/-!
### 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 :=
mul_pos ha (inv_pos.2 hb)
lemma div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
mul_pos_of_neg_of_neg ha (inv_lt_zero.2 hb)
lemma div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
mul_neg_of_neg_of_pos ha (inv_pos.2 hb)
lemma div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
mul_neg_of_pos_of_neg ha (inv_lt_zero.2 hb)
lemma div_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b :=
mul_nonneg ha (inv_nonneg.2 hb)
lemma div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=
mul_nonneg_of_nonpos_of_nonpos ha (inv_nonpos.2 hb)
lemma div_nonpos_of_nonpos_of_nonneg (ha : a ≤ 0) (hb : 0 ≤ b) : a / b ≤ 0 :=
mul_nonpos_of_nonpos_of_nonneg ha (inv_nonneg.2 hb)
lemma div_nonpos_of_nonneg_of_nonpos (ha : 0 ≤ a) (hb : b ≤ 0) : a / b ≤ 0 :=
mul_nonpos_of_nonneg_of_nonpos ha (inv_nonpos.2 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 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_iff_of_nonneg_of_le (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'] }
/-!
### 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]
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 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)
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 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.
-/
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
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 :=
mul_le_mul_of_nonneg_right hab (inv_nonneg.2 hc)
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 :=
(mul_lt_mul_left ha).trans (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]
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 (hb : 0 < b) (h : b < a) (hc : 0 < c) : c / a < c / b :=
(div_lt_div_left hc (hb.trans h) hb).mpr h
/-!
### Relating one division and involving `1`
-/
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 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
/-!
### Miscellaneous lemmas
-/
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 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) :=
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) :=
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 : α) : abs (a / b) = abs a / abs b :=
(abs_hom : monoid_with_zero_hom α α).map_div a b
lemma abs_one_div (a : α) : abs (1 / a) = 1 / abs a :=
by rw [abs_div, abs_one]
lemma abs_inv (a : α) : abs a⁻¹ = (abs a)⁻¹ :=
(abs_hom : monoid_with_zero_hom α α).map_inv' a
end linear_ordered_field
|
aff0b34d23f4ad3b3d80ab99f3cdfb7e4dc27558 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/set_theory/ordinal_auto.lean | 4501f1741f4d226b1889e6940998dd2f4d562b08 | [] | 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 | 49,299 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.set_theory.cardinal
import Mathlib.PostPort
universes u_4 u_5 l u_1 u_2 u_3 u v w
namespace Mathlib
/-!
# Ordinals
Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed
with a total order, where an ordinal is smaller than another one if it embeds into it as an
initial segment (or, equivalently, in any way). This total order is well founded.
## Main definitions
* `initial_seg r s`: type of order embeddings of `r` into `s` for which the range is an initial
segment (i.e., if `b` belongs to the range, then any `b' < b` also belongs to the range).
It is denoted by `r ≼i s`.
* `principal_seg r s`: Type of order embeddings of `r` into `s` for which the range is a principal
segment, i.e., an interval of the form `(-∞, top)` for some element `top`. It is denoted by
`r ≺i s`.
* `ordinal`: the type of ordinals (in a given universe)
* `type r`: given a well-founded order `r`, this is the corresponding ordinal
* `typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal
corresponding to all elements smaller than `a`.
* `enum r o h`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than
the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`.
In other words, the elements of `α` can be enumerated using ordinals up to `type r`.
* `card o`: the cardinality of an ordinal `o`.
* `lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`. For a version
registering additionally that this is an initial segment embedding, see `lift.initial_seg`. For
a version regiserting that it is a principal segment embedding if `u < v`, see
`lift.principal_seg`.
* `omega` is the first infinite ordinal. It is the order type of `ℕ`.
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`. The main properties of addition
(and the other operations on ordinals) are stated and proved in `ordinal_arithmetic.lean`. Here,
we only introduce it and prove its basic properties to deduce the fact that the order on ordinals
is total (and well founded).
* `succ o` is the successor of the ordinal `o`.
* `min`: the minimal element of a nonempty indexed family of ordinals
* `omin` : the minimal element of a nonempty set of ordinals
* `ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality. It is
the canonical way to represent a cardinal with an ordinal.
## Notations
* `r ≼i s`: the type of initial segment embeddings of `r` into `s`.
* `r ≺i s`: the type of principal segment embeddings of `r` into `s`.
* `ω` is a notation for the first infinite ordinal in the locale ordinal.
-/
/-!
### Initial segments
Order embeddings whose range is an initial segment of `s` (i.e., if `b` belongs to the range, then
any `b' < b` also belongs to the range). The type of these embeddings from `r` to `s` is called
`initial_seg r s`, and denoted by `r ≼i s`.
-/
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≼i s` is an order
embedding whose range is an initial segment. That is, whenever `b < f a` in `β` then `b` is in the
range of `f`. -/
structure initial_seg {α : Type u_4} {β : Type u_5} (r : α → α → Prop) (s : β → β → Prop)
extends r ↪r s where
init :
∀ (a : α) (b : β),
s b (coe_fn _to_rel_embedding a) → ∃ (a' : α), coe_fn _to_rel_embedding a' = b
namespace initial_seg
protected instance rel_embedding.has_coe {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} : has_coe (initial_seg r s) (r ↪r s) :=
has_coe.mk to_rel_embedding
protected instance has_coe_to_fun {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} : has_coe_to_fun (initial_seg r s) :=
has_coe_to_fun.mk (fun (_x : initial_seg r s) => α → β)
fun (f : initial_seg r s) (x : α) => coe_fn (↑f) x
@[simp] theorem coe_fn_mk {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : r ↪r s) (o : ∀ (a : α) (b : β), s b (coe_fn f a) → ∃ (a' : α), coe_fn f a' = b) :
⇑(mk f o) = ⇑f :=
rfl
@[simp] theorem coe_fn_to_rel_embedding {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} (f : initial_seg r s) : ⇑(to_rel_embedding f) = ⇑f :=
rfl
@[simp] theorem coe_coe_fn {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : initial_seg r s) : ⇑↑f = ⇑f :=
rfl
theorem init' {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : initial_seg r s) {a : α} {b : β} : s b (coe_fn f a) → ∃ (a' : α), coe_fn f a' = b :=
init f a b
theorem init_iff {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : initial_seg r s) {a : α} {b : β} :
s b (coe_fn f a) ↔ ∃ (a' : α), coe_fn f a' = b ∧ r a' a :=
sorry
/-- An order isomorphism is an initial segment -/
def of_iso {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} (f : r ≃r s) :
initial_seg r s :=
mk ↑f sorry
/-- The identity function shows that `≼i` is reflexive -/
protected def refl {α : Type u_1} (r : α → α → Prop) : initial_seg r r :=
mk (rel_embedding.refl r) sorry
/-- Composition of functions shows that `≼i` is transitive -/
protected def trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : initial_seg r s) (g : initial_seg s t) :
initial_seg r t :=
mk (rel_embedding.trans (to_rel_embedding f) (to_rel_embedding g)) sorry
@[simp] theorem refl_apply {α : Type u_1} {r : α → α → Prop} (x : α) :
coe_fn (initial_seg.refl r) x = x :=
rfl
@[simp] theorem trans_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : initial_seg r s) (g : initial_seg s t) (a : α) :
coe_fn (initial_seg.trans f g) a = coe_fn g (coe_fn f a) :=
rfl
theorem unique_of_extensional {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_extensional β s] : well_founded r → subsingleton (initial_seg r s) :=
sorry
protected instance subsingleton {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] : subsingleton (initial_seg r s) :=
subsingleton.intro fun (a : initial_seg r s) => subsingleton.elim a
protected theorem eq {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : initial_seg r s) (g : initial_seg r s) (a : α) :
coe_fn f a = coe_fn g a :=
eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn f a = coe_fn g a)) (subsingleton.elim f g)))
(Eq.refl (coe_fn g a))
theorem antisymm.aux {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] (f : initial_seg r s) (g : initial_seg s r) : function.left_inverse ⇑g ⇑f :=
initial_seg.eq (initial_seg.trans f g) (initial_seg.refl r)
/-- If we have order embeddings between `α` and `β` whose images are initial segments, and `β`
is a well-order then `α` and `β` are order-isomorphic. -/
def antisymm {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} [is_well_order β s]
(f : initial_seg r s) (g : initial_seg s r) : r ≃r s :=
rel_iso.mk (equiv.mk ⇑f ⇑g sorry sorry) sorry
@[simp] theorem antisymm_to_fun {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : initial_seg r s) (g : initial_seg s r) : ⇑(antisymm f g) = ⇑f :=
rfl
@[simp] theorem antisymm_symm {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : initial_seg r s) (g : initial_seg s r) :
rel_iso.symm (antisymm f g) = antisymm g f :=
rel_iso.injective_coe_fn rfl
theorem eq_or_principal {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : initial_seg r s) :
function.surjective ⇑f ∨ ∃ (b : β), ∀ (x : β), s x b ↔ ∃ (y : α), coe_fn f y = x :=
sorry
/-- Restrict the codomain of an initial segment -/
def cod_restrict {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} (p : set β)
(f : initial_seg r s) (H : ∀ (a : α), coe_fn f a ∈ p) : initial_seg r (subrel s p) :=
mk (rel_embedding.cod_restrict p (↑f) H) sorry
@[simp] theorem cod_restrict_apply {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} (p : set β) (f : initial_seg r s) (H : ∀ (a : α), coe_fn f a ∈ p) (a : α) :
coe_fn (cod_restrict p f H) a = { val := coe_fn f a, property := H a } :=
rfl
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def le_add {α : Type u_1} {β : Type u_2} (r : α → α → Prop) (s : β → β → Prop) :
initial_seg r (sum.lex r s) :=
mk (rel_embedding.mk (function.embedding.mk sum.inl sorry) sorry) sorry
@[simp] theorem le_add_apply {α : Type u_1} {β : Type u_2} (r : α → α → Prop) (s : β → β → Prop)
(a : α) : coe_fn (le_add r s) a = sum.inl a :=
rfl
end initial_seg
/-!
### Principal segments
Order embeddings whose range is a principal segment of `s` (i.e., an interval of the form
`(-∞, top)` for some element `top` of `β`). The type of these embeddings from `r` to `s` is called
`principal_seg r s`, and denoted by `r ≺i s`. Principal segments are in particular initial
segments.
-/
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≺i s` is an order
embedding whose range is an open interval `(-∞, top)` for some element `top` of `β`. Such order
embeddings are called principal segments -/
structure principal_seg {α : Type u_4} {β : Type u_5} (r : α → α → Prop) (s : β → β → Prop)
extends r ↪r s where
top : β
down : ∀ (b : β), s b top ↔ ∃ (a : α), coe_fn _to_rel_embedding a = b
namespace principal_seg
protected instance rel_embedding.has_coe {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} : has_coe (principal_seg r s) (r ↪r s) :=
has_coe.mk to_rel_embedding
protected instance has_coe_to_fun {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} : has_coe_to_fun (principal_seg r s) :=
has_coe_to_fun.mk (fun (_x : principal_seg r s) => α → β) fun (f : principal_seg r s) => ⇑f
@[simp] theorem coe_fn_mk {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : r ↪r s) (t : β) (o : ∀ (b : β), s b t ↔ ∃ (a : α), coe_fn f a = b) : ⇑(mk f t o) = ⇑f :=
rfl
@[simp] theorem coe_fn_to_rel_embedding {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} (f : principal_seg r s) : ⇑(to_rel_embedding f) = ⇑f :=
rfl
@[simp] theorem coe_coe_fn {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : principal_seg r s) : ⇑↑f = ⇑f :=
rfl
theorem down' {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : principal_seg r s) {b : β} : s b (top f) ↔ ∃ (a : α), coe_fn f a = b :=
down f b
theorem lt_top {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(f : principal_seg r s) (a : α) : s (coe_fn f a) (top f) :=
iff.mpr (down' f) (Exists.intro a rfl)
theorem init {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} [is_trans β s]
(f : principal_seg r s) {a : α} {b : β} (h : s b (coe_fn f a)) : ∃ (a' : α), coe_fn f a' = b :=
iff.mp (down' f) (trans h (lt_top f a))
/-- A principal segment is in particular an initial segment. -/
protected instance has_coe_initial_seg {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} [is_trans β s] : has_coe (principal_seg r s) (initial_seg r s) :=
has_coe.mk fun (f : principal_seg r s) => initial_seg.mk (to_rel_embedding f) sorry
theorem coe_coe_fn' {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_trans β s] (f : principal_seg r s) : ⇑↑f = ⇑f :=
rfl
theorem init_iff {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} [is_trans β s]
(f : principal_seg r s) {a : α} {b : β} :
s b (coe_fn f a) ↔ ∃ (a' : α), coe_fn f a' = b ∧ r a' a :=
initial_seg.init_iff ↑f
theorem irrefl {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (f : principal_seg r r) :
False :=
sorry
/-- Composition of a principal segment with an initial segment, as a principal segment -/
def lt_le {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} (f : principal_seg r s) (g : initial_seg s t) : principal_seg r t :=
mk (rel_embedding.trans ↑f ↑g) (coe_fn g (top f)) sorry
@[simp] theorem lt_le_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : principal_seg r s) (g : initial_seg s t) (a : α) :
coe_fn (lt_le f g) a = coe_fn g (coe_fn f a) :=
rel_embedding.trans_apply (↑f) (↑g) a
@[simp] theorem lt_le_top {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : principal_seg r s) (g : initial_seg s t) :
top (lt_le f g) = coe_fn g (top f) :=
rfl
/-- Composition of two principal segments as a principal segment -/
protected def trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} [is_trans γ t] (f : principal_seg r s)
(g : principal_seg s t) : principal_seg r t :=
lt_le f ↑g
@[simp] theorem trans_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} [is_trans γ t] (f : principal_seg r s)
(g : principal_seg s t) (a : α) : coe_fn (principal_seg.trans f g) a = coe_fn g (coe_fn f a) :=
lt_le_apply f (↑g) a
@[simp] theorem trans_top {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} [is_trans γ t] (f : principal_seg r s)
(g : principal_seg s t) : top (principal_seg.trans f g) = coe_fn g (top f) :=
rfl
/-- Composition of an order isomorphism with a principal segment, as a principal segment -/
def equiv_lt {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} (f : r ≃r s) (g : principal_seg s t) : principal_seg r t :=
mk (rel_embedding.trans ↑f ↑g) (top g) sorry
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def lt_equiv {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} (f : principal_seg r s) (g : s ≃r t) : principal_seg r t :=
mk (rel_embedding.trans ↑f ↑g) (coe_fn g (top f)) sorry
@[simp] theorem equiv_lt_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : r ≃r s) (g : principal_seg s t) (a : α) :
coe_fn (equiv_lt f g) a = coe_fn g (coe_fn f a) :=
rel_embedding.trans_apply (↑f) (↑g) a
@[simp] theorem equiv_lt_top {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} (f : r ≃r s) (g : principal_seg s t) :
top (equiv_lt f g) = top g :=
rfl
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
protected instance subsingleton {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] : subsingleton (principal_seg r s) :=
sorry
theorem top_eq {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} [is_well_order γ t] (e : r ≃r s) (f : principal_seg r t)
(g : principal_seg s t) : top f = top g :=
eq.mpr (id (Eq._oldrec (Eq.refl (top f = top g)) (subsingleton.elim f (equiv_lt e g))))
(Eq.refl (top (equiv_lt e g)))
theorem top_lt_top {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} [is_well_order γ t] (f : principal_seg r s)
(g : principal_seg s t) (h : principal_seg r t) : t (top h) (top g) :=
eq.mpr
(id (Eq._oldrec (Eq.refl (t (top h) (top g))) (subsingleton.elim h (principal_seg.trans f g))))
(lt_top g (top f))
/-- Any element of a well order yields a principal segment -/
def of_element {α : Type u_1} (r : α → α → Prop) (a : α) :
principal_seg (subrel r (set_of fun (b : α) => r b a)) r :=
mk (subrel.rel_embedding r (set_of fun (b : α) => r b a)) a sorry
@[simp] theorem of_element_apply {α : Type u_1} (r : α → α → Prop) (a : α)
(b : ↥(set_of fun (b : α) => r b a)) : coe_fn (of_element r a) b = subtype.val b :=
rfl
@[simp] theorem of_element_top {α : Type u_1} (r : α → α → Prop) (a : α) :
top (of_element r a) = a :=
rfl
/-- Restrict the codomain of a principal segment -/
def cod_restrict {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} (p : set β)
(f : principal_seg r s) (H : ∀ (a : α), coe_fn f a ∈ p) (H₂ : top f ∈ p) :
principal_seg r (subrel s p) :=
mk (rel_embedding.cod_restrict p (↑f) H) { val := top f, property := H₂ } sorry
@[simp] theorem cod_restrict_apply {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} (p : set β) (f : principal_seg r s) (H : ∀ (a : α), coe_fn f a ∈ p)
(H₂ : top f ∈ p) (a : α) :
coe_fn (cod_restrict p f H H₂) a = { val := coe_fn f a, property := H a } :=
rfl
@[simp] theorem cod_restrict_top {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
(p : set β) (f : principal_seg r s) (H : ∀ (a : α), coe_fn f a ∈ p) (H₂ : top f ∈ p) :
top (cod_restrict p f H H₂) = { val := top f, property := H₂ } :=
rfl
end principal_seg
/-! ### Properties of initial and principal segments -/
/-- To an initial segment taking values in a well order, one can associate either a principal
segment (if the range is not everything, hence one can take as top the minimum of the complement
of the range) or an order isomorphism (if the range is everything). -/
def initial_seg.lt_or_eq {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : initial_seg r s) : principal_seg r s ⊕ (r ≃r s) :=
dite (function.surjective ⇑f)
(fun (h : function.surjective ⇑f) => sum.inr (rel_iso.of_surjective (↑f) h))
fun (h : ¬function.surjective ⇑f) =>
(fun (h' : ∃ (b : β), ∀ (x : β), s x b ↔ ∃ (y : α), coe_fn f y = x) =>
sum.inl (principal_seg.mk (↑f) (classical.some h') sorry))
sorry
theorem initial_seg.lt_or_eq_apply_left {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} [is_well_order β s] (f : initial_seg r s) (g : principal_seg r s) (a : α) :
coe_fn g a = coe_fn f a :=
initial_seg.eq (↑g) f a
theorem initial_seg.lt_or_eq_apply_right {α : Type u_1} {β : Type u_2} {r : α → α → Prop}
{s : β → β → Prop} [is_well_order β s] (f : initial_seg r s) (g : r ≃r s) (a : α) :
coe_fn g a = coe_fn f a :=
initial_seg.eq (initial_seg.of_iso g) f a
/-- Composition of an initial segment taking values in a well order and a principal segment. -/
def initial_seg.le_lt {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α → α → Prop}
{s : β → β → Prop} {t : γ → γ → Prop} [is_well_order β s] [is_trans γ t] (f : initial_seg r s)
(g : principal_seg s t) : principal_seg r t :=
sorry
@[simp] theorem initial_seg.le_lt_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3}
{r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} [is_well_order β s] [is_trans γ t]
(f : initial_seg r s) (g : principal_seg s t) (a : α) :
coe_fn (initial_seg.le_lt f g) a = coe_fn g (coe_fn f a) :=
sorry
namespace rel_embedding
/-- Given an order embedding into a well order, collapse the order embedding by filling the
gaps, to obtain an initial segment. Here, we construct the collapsed order embedding pointwise,
but the proof of the fact that it is an initial segment will be given in `collapse`. -/
def collapse_F {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : r ↪r s) (a : α) : Subtype fun (b : β) => ¬s (coe_fn f a) b :=
well_founded.fix sorry
fun (a : α) (IH : (y : α) → r y a → Subtype fun (b : β) => ¬s (coe_fn f y) b) =>
let S : set β :=
set_of fun (b : β) => ∀ (a_1 : α) (h : r a_1 a), s (subtype.val (IH a_1 h)) b;
{ val := well_founded.min is_well_order.wf S sorry, property := sorry }
theorem collapse_F.lt {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : r ↪r s) {a : α} {a' : α} :
r a' a → s (subtype.val (collapse_F f a')) (subtype.val (collapse_F f a)) :=
sorry
theorem collapse_F.not_lt {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : r ↪r s) (a : α) {b : β}
(h : ∀ (a' : α), r a' a → s (subtype.val (collapse_F f a')) b) :
¬s b (subtype.val (collapse_F f a)) :=
sorry
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
def collapse {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} [is_well_order β s]
(f : r ↪r s) : initial_seg r s :=
initial_seg.mk (of_monotone (fun (a : α) => subtype.val (collapse_F f a)) sorry) sorry
theorem collapse_apply {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order β s] (f : r ↪r s) (a : α) :
coe_fn (collapse f) a = subtype.val (collapse_F f a) :=
rfl
end rel_embedding
/-! ### Well order on an arbitrary type -/
theorem nonempty_embedding_to_cardinal {σ : Type u} : Nonempty (σ ↪ cardinal) := sorry
/-- An embedding of any type to the set of cardinals. -/
def embedding_to_cardinal {σ : Type u} : σ ↪ cardinal :=
Classical.choice nonempty_embedding_to_cardinal
/-- Any type can be endowed with a well order, obtained by pulling back the well order over
cardinals by some embedding. -/
def well_ordering_rel {σ : Type u} : σ → σ → Prop := ⇑embedding_to_cardinal ⁻¹'o Less
protected instance well_ordering_rel.is_well_order {σ : Type u} :
is_well_order σ well_ordering_rel :=
rel_embedding.is_well_order (rel_embedding.preimage embedding_to_cardinal Less)
/-! ### Definition of ordinals -/
/-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient
of this type. -/
structure Well_order where
α : Type u
r : α → α → Prop
wo : is_well_order α r
namespace Well_order
protected instance inhabited : Inhabited Well_order :=
{ default := mk pempty empty_relation empty_relation.is_well_order }
end Well_order
/-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order
isomorphism. -/
protected instance ordinal.is_equivalent : setoid Well_order :=
setoid.mk (fun (_x : Well_order) => sorry) sorry
/-- `ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/
def ordinal := quotient sorry
namespace ordinal
/-- The order type of a well order is an ordinal. -/
def type {α : Type u_1} (r : α → α → Prop) [wo : is_well_order α r] : ordinal :=
quotient.mk (Well_order.mk α r wo)
/-- The order type of an element inside a well order. For the embedding as a principal segment, see
`typein.principal_seg`. -/
def typein {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (a : α) : ordinal :=
type (subrel r (set_of fun (b : α) => r b a))
theorem type_def {α : Type u_1} (r : α → α → Prop) [wo : is_well_order α r] :
quotient.mk (Well_order.mk α r wo) = type r :=
rfl
@[simp] theorem type_def' {α : Type u_1} (r : α → α → Prop) [is_well_order α r]
{wo : is_well_order α r} : quotient.mk (Well_order.mk α r wo) = type r :=
rfl
theorem type_eq {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] : type r = type s ↔ Nonempty (r ≃r s) :=
quotient.eq
@[simp] theorem type_out (o : ordinal) : type (Well_order.r (quotient.out o)) = o := sorry
theorem induction_on {C : ordinal → Prop} (o : ordinal)
(H : ∀ (α : Type u_1) (r : α → α → Prop) [_inst_1 : is_well_order α r], C (type r)) : C o :=
sorry
/-! ### The order on ordinals -/
/-- Ordinal less-equal is defined such that
well orders `r` and `s` satisfy `type r ≤ type s` if there exists
a function embedding `r` as an initial segment of `s`. -/
protected def le (a : ordinal) (b : ordinal) :=
quotient.lift_on₂ a b (fun (_x : Well_order) => sorry) sorry
protected instance has_le : HasLessEq ordinal := { LessEq := ordinal.le }
theorem type_le {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] : type r ≤ type s ↔ Nonempty (initial_seg r s) :=
iff.rfl
theorem type_le' {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] : type r ≤ type s ↔ Nonempty (r ↪r s) :=
sorry
/-- Ordinal less-than is defined such that
well orders `r` and `s` satisfy `type r < type s` if there exists
a function embedding `r` as a principal segment of `s`. -/
def lt (a : ordinal) (b : ordinal) := quotient.lift_on₂ a b (fun (_x : Well_order) => sorry) sorry
protected instance has_lt : HasLess ordinal := { Less := lt }
@[simp] theorem type_lt {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] : type r < type s ↔ Nonempty (principal_seg r s) :=
iff.rfl
protected instance partial_order : partial_order ordinal :=
partial_order.mk LessEq Less sorry sorry sorry
/-- Given two ordinals `α ≤ β`, then `initial_seg_out α β` is the initial segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def initial_seg_out {α : ordinal} {β : ordinal} (h : α ≤ β) :
initial_seg (Well_order.r (quotient.out α)) (Well_order.r (quotient.out β)) :=
Well_order.cases_on (quotient.out α)
(fun (α_1 : Type u_1) (r : α_1 → α_1 → Prop) (wo : is_well_order α_1 r) =>
Well_order.cases_on (quotient.out β)
fun (α_2 : Type u_1) (r_1 : α_2 → α_2 → Prop) (wo_1 : is_well_order α_2 r_1) =>
Classical.choice)
sorry
/-- Given two ordinals `α < β`, then `principal_seg_out α β` is the principal segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def principal_seg_out {α : ordinal} {β : ordinal} (h : α < β) :
principal_seg (Well_order.r (quotient.out α)) (Well_order.r (quotient.out β)) :=
Well_order.cases_on (quotient.out α)
(fun (α_1 : Type u_1) (r : α_1 → α_1 → Prop) (wo : is_well_order α_1 r) =>
Well_order.cases_on (quotient.out β)
fun (α_2 : Type u_1) (r_1 : α_2 → α_2 → Prop) (wo_1 : is_well_order α_2 r_1) =>
Classical.choice)
sorry
/-- Given two ordinals `α = β`, then `rel_iso_out α β` is the order isomorphism between two
model types for `α` and `β`. -/
def rel_iso_out {α : ordinal} {β : ordinal} (h : α = β) :
Well_order.r (quotient.out α) ≃r Well_order.r (quotient.out β) :=
Well_order.cases_on (quotient.out α)
(fun (α_1 : Type u_1) (r : α_1 → α_1 → Prop) (wo : is_well_order α_1 r) =>
Well_order.cases_on (quotient.out β)
fun (α_2 : Type u_1) (r_1 : α_2 → α_2 → Prop) (wo_1 : is_well_order α_2 r_1) =>
Classical.choice ∘ sorry)
sorry
theorem typein_lt_type {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (a : α) :
typein r a < type r :=
Nonempty.intro (principal_seg.of_element r a)
@[simp] theorem typein_top {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : principal_seg r s) :
typein s (principal_seg.top f) = type r :=
sorry
@[simp] theorem typein_apply {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : initial_seg r s) (a : α) :
typein s (coe_fn f a) = typein r a :=
sorry
@[simp] theorem typein_lt_typein {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {a : α}
{b : α} : typein r a < typein r b ↔ r a b :=
sorry
theorem typein_surj {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {o : ordinal}
(h : o < type r) : ∃ (a : α), typein r a = o :=
sorry
theorem typein_injective {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
function.injective (typein r) :=
injective_of_increasing r Less (typein r) fun (x y : α) => iff.mpr (typein_lt_typein r)
theorem typein_inj {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {a : α} {b : α} :
typein r a = typein r b ↔ a = b :=
function.injective.eq_iff (typein_injective r)
/-! ### Enumerating elements in a well-order with ordinals. -/
/-- `enum r o h` is the `o`-th element of `α` ordered by `r`.
That is, `enum` maps an initial segment of the ordinals, those
less than the order type of `r`, to the elements of `α`. -/
def enum {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (o : ordinal) : o < type r → α :=
quot.rec_on o (fun (_x : Well_order) => sorry) sorry
theorem enum_type {α : Type u_1} {β : Type u_1} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : principal_seg s r) {h : type s < type r} :
enum r (type s) h = principal_seg.top f :=
principal_seg.top_eq (rel_iso.refl s) (Classical.choice h) f
@[simp] theorem enum_typein {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (a : α)
{h : typein r a < type r} : enum r (typein r a) h = a :=
enum_type (principal_seg.of_element r a)
@[simp] theorem typein_enum {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {o : ordinal}
(h : o < type r) : typein r (enum r o h) = o :=
sorry
/-- A well order `r` is order isomorphic to the set of ordinals strictly smaller than the
ordinal version of `r`. -/
def typein_iso {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
r ≃r subrel Less fun (_x : ordinal) => _x < type r :=
rel_iso.mk
(equiv.mk (fun (x : α) => { val := typein r x, property := typein_lt_type r x })
(fun (x : ↥fun (_x : ordinal) => _x < type r) => enum r (subtype.val x) sorry) sorry sorry)
sorry
theorem enum_lt {α : Type u_1} {r : α → α → Prop} [is_well_order α r] {o₁ : ordinal} {o₂ : ordinal}
(h₁ : o₁ < type r) (h₂ : o₂ < type r) : r (enum r o₁ h₁) (enum r o₂ h₂) ↔ o₁ < o₂ :=
sorry
theorem rel_iso_enum' {α : Type u} {β : Type u} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : r ≃r s) (o : ordinal) (hr : o < type r)
(hs : o < type s) : coe_fn f (enum r o hr) = enum s o hs :=
sorry
theorem rel_iso_enum {α : Type u} {β : Type u} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] (f : r ≃r s) (o : ordinal) (hr : o < type r) :
coe_fn f (enum r o hr) =
enum s o
(eq.mpr
((fun (ᾰ ᾰ_1 : ordinal) (e_2 : ᾰ = ᾰ_1) (ᾰ_2 ᾰ_3 : ordinal) (e_3 : ᾰ_2 = ᾰ_3) =>
congr (congr_arg Less e_2) e_3)
o o (Eq.refl o) (type s) (type r) (quotient.sound (Nonempty.intro (rel_iso.symm f))))
hr) :=
sorry
theorem wf : well_founded Less := sorry
protected instance has_well_founded : has_well_founded ordinal := has_well_founded.mk Less wf
/-- Principal segment version of the `typein` function, embedding a well order into
ordinals as a principal segment. -/
def typein.principal_seg {α : Type u} (r : α → α → Prop) [is_well_order α r] :
principal_seg r Less :=
principal_seg.mk (rel_embedding.of_monotone (typein r) sorry) (type r) sorry
@[simp] theorem typein.principal_seg_coe {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
⇑(typein.principal_seg r) = typein r :=
rfl
/-! ### Cardinality of ordinals -/
/-- The cardinal of an ordinal is the cardinal of any
set with that order type. -/
def card (o : ordinal) : cardinal := quot.lift_on o (fun (_x : Well_order) => sorry) sorry
@[simp] theorem card_type {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
card (type r) = cardinal.mk α :=
rfl
theorem card_typein {α : Type u_1} {r : α → α → Prop} [wo : is_well_order α r] (x : α) :
cardinal.mk (Subtype fun (y : α) => r y x) = card (typein r x) :=
rfl
theorem card_le_card {o₁ : ordinal} {o₂ : ordinal} : o₁ ≤ o₂ → card o₁ ≤ card o₂ := sorry
protected instance has_zero : HasZero ordinal :=
{ zero := quotient.mk (Well_order.mk pempty empty_relation empty_relation.is_well_order) }
protected instance inhabited : Inhabited ordinal := { default := 0 }
theorem zero_eq_type_empty : 0 = type empty_relation :=
quotient.sound
(Nonempty.intro
(rel_iso.mk (equiv.symm equiv.empty_equiv_pempty) fun (_x _x_1 : pempty) => iff.rfl))
@[simp] theorem card_zero : card 0 = 0 := rfl
protected theorem zero_le (o : ordinal) : 0 ≤ o := sorry
@[simp] protected theorem le_zero {o : ordinal} : o ≤ 0 ↔ o = 0 := sorry
protected theorem pos_iff_ne_zero {o : ordinal} : 0 < o ↔ o ≠ 0 := sorry
protected instance has_one : HasOne ordinal :=
{ one := quotient.mk (Well_order.mk PUnit empty_relation empty_relation.is_well_order) }
theorem one_eq_type_unit : 1 = type empty_relation :=
quotient.sound
(Nonempty.intro (rel_iso.mk equiv.punit_equiv_punit fun (_x _x_1 : PUnit) => iff.rfl))
@[simp] theorem card_one : card 1 = 1 := rfl
/-! ### Lifting ordinals to a higher universe -/
/-- The universe lift operation for ordinals, which embeds `ordinal.{u}` as
a proper initial segment of `ordinal.{v}` for `v > u`. For the initial segment version,
see `lift.initial_seg`. -/
def lift (o : ordinal) : ordinal := quotient.lift_on o (fun (_x : Well_order) => sorry) sorry
theorem lift_type {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
∃ (wo' : is_well_order (ulift α) (⇑equiv.ulift ⁻¹'o r)),
lift (type r) = type (⇑equiv.ulift ⁻¹'o r) :=
Exists.intro (rel_embedding.is_well_order ↑(rel_iso.preimage equiv.ulift r)) rfl
theorem lift_umax : lift = lift := sorry
theorem lift_id' (a : ordinal) : lift a = a :=
induction_on a
fun (α : Type (max u_1 u_2)) (r : α → α → Prop) (_x : is_well_order α r) =>
quotient.sound (Nonempty.intro (rel_iso.preimage equiv.ulift r))
@[simp] theorem lift_id (a : ordinal) : lift a = a := lift_id'
@[simp] theorem lift_lift (a : ordinal) : lift (lift a) = lift a := sorry
theorem lift_type_le {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] :
lift (type r) ≤ lift (type s) ↔ Nonempty (initial_seg r s) :=
sorry
theorem lift_type_eq {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] : lift (type r) = lift (type s) ↔ Nonempty (r ≃r s) :=
sorry
theorem lift_type_lt {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
[is_well_order α r] [is_well_order β s] :
lift (type r) < lift (type s) ↔ Nonempty (principal_seg r s) :=
sorry
@[simp] theorem lift_le {a : ordinal} {b : ordinal} : lift a ≤ lift b ↔ a ≤ b := sorry
@[simp] theorem lift_inj {a : ordinal} {b : ordinal} : lift a = lift b ↔ a = b := sorry
@[simp] theorem lift_lt {a : ordinal} {b : ordinal} : lift a < lift b ↔ a < b := sorry
@[simp] theorem lift_zero : lift 0 = 0 := sorry
theorem zero_eq_lift_type_empty : 0 = lift (type empty_relation) :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 = lift (type empty_relation))) (Eq.symm zero_eq_type_empty)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 = lift 0)) lift_zero)) (Eq.refl 0))
@[simp] theorem lift_one : lift 1 = 1 := sorry
theorem one_eq_lift_type_unit : 1 = lift (type empty_relation) :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 = lift (type empty_relation))) (Eq.symm one_eq_type_unit)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 = lift 1)) lift_one)) (Eq.refl 1))
@[simp] theorem lift_card (a : ordinal) : cardinal.lift (card a) = card (lift a) :=
induction_on a fun (α : Type u_1) (r : α → α → Prop) (_x : is_well_order α r) => rfl
theorem lift_down' {a : cardinal} {b : ordinal} (h : card b ≤ cardinal.lift a) :
∃ (a' : ordinal), lift a' = b :=
sorry
theorem lift_down {a : ordinal} {b : ordinal} (h : b ≤ lift a) : ∃ (a' : ordinal), lift a' = b :=
lift_down'
(eq.mpr (id (Eq._oldrec (Eq.refl (card b ≤ cardinal.lift (card a))) (lift_card a)))
(card_le_card h))
theorem le_lift_iff {a : ordinal} {b : ordinal} :
b ≤ lift a ↔ ∃ (a' : ordinal), lift a' = b ∧ a' ≤ a :=
sorry
theorem lt_lift_iff {a : ordinal} {b : ordinal} :
b < lift a ↔ ∃ (a' : ordinal), lift a' = b ∧ a' < a :=
sorry
/-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in
`ordinal.{v}` as an initial segment when `u ≤ v`. -/
def lift.initial_seg : initial_seg Less Less :=
initial_seg.mk (rel_embedding.mk (function.embedding.mk lift sorry) sorry) sorry
@[simp] theorem lift.initial_seg_coe : ⇑lift.initial_seg = lift := rfl
/-! ### The first infinite ordinal `omega` -/
/-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/
def omega : ordinal := lift (type Less)
theorem card_omega : card omega = cardinal.omega := rfl
@[simp] theorem lift_omega : lift omega = omega := lift_lift (type Less)
/-!
### Definition and first properties of addition on ordinals
In this paragraph, we introduce the addition on ordinals, and prove just enough properties to
deduce that the order on ordinals is total (and therefore well-founded). Further properties of
the addition, together with properties of the other operations, are proved in
`ordinal_arithmetic.lean`.
-/
/-- `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`. -/
protected instance has_add : Add ordinal :=
{ add := fun (o₁ o₂ : ordinal) => quotient.lift_on₂ o₁ o₂ (fun (_x : Well_order) => sorry) sorry }
@[simp] theorem card_add (o₁ : ordinal) (o₂ : ordinal) : card (o₁ + o₂) = card o₁ + card o₂ :=
induction_on o₁
fun (α : Type u_1) (r : α → α → Prop) (_x : is_well_order α r) =>
induction_on o₂ fun (β : Type u_1) (s : β → β → Prop) (_x_1 : is_well_order β s) => rfl
@[simp] theorem card_nat (n : ℕ) : card ↑n = ↑n := sorry
@[simp] theorem type_add {α : Type u} {β : Type u} (r : α → α → Prop) (s : β → β → Prop)
[is_well_order α r] [is_well_order β s] : type r + type s = type (sum.lex r s) :=
rfl
/-- The ordinal successor is the smallest ordinal larger than `o`.
It is defined as `o + 1`. -/
def succ (o : ordinal) : ordinal := o + 1
theorem succ_eq_add_one (o : ordinal) : succ o = o + 1 := rfl
protected instance add_monoid : add_monoid ordinal := add_monoid.mk Add.add sorry 0 sorry sorry
theorem add_le_add_left {a : ordinal} {b : ordinal} : a ≤ b → ∀ (c : ordinal), c + a ≤ c + b :=
sorry
theorem le_add_right (a : ordinal) (b : ordinal) : a ≤ a + b := sorry
theorem add_le_add_right {a : ordinal} {b : ordinal} : a ≤ b → ∀ (c : ordinal), a + c ≤ b + c :=
sorry
theorem le_add_left (a : ordinal) (b : ordinal) : a ≤ b + a := sorry
theorem lt_succ_self (o : ordinal) : o < succ o := sorry
theorem succ_le {a : ordinal} {b : ordinal} : succ a ≤ b ↔ a < b := sorry
theorem le_total (a : ordinal) (b : ordinal) : a ≤ b ∨ b ≤ a := sorry
protected instance linear_order : linear_order ordinal :=
linear_order.mk partial_order.le partial_order.lt partial_order.le_refl partial_order.le_trans
partial_order.le_antisymm le_total (classical.dec_rel LessEq)
Mathlib.decidable_eq_of_decidable_le Mathlib.decidable_lt_of_decidable_le
protected instance has_lt.lt.is_well_order : is_well_order ordinal Less := is_well_order.mk wf
@[simp] theorem typein_le_typein {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {x : α}
{x' : α} : typein r x ≤ typein r x' ↔ ¬r x' x :=
eq.mpr (id (Eq._oldrec (Eq.refl (typein r x ≤ typein r x' ↔ ¬r x' x)) (Eq.symm (propext not_lt))))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (¬typein r x' < typein r x ↔ ¬r x' x)) (propext (typein_lt_typein r))))
(iff.refl (¬r x' x)))
theorem enum_le_enum {α : Type u_1} (r : α → α → Prop) [is_well_order α r] {o : ordinal}
{o' : ordinal} (ho : o < type r) (ho' : o' < type r) :
¬r (enum r o' ho') (enum r o ho) ↔ o ≤ o' :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (¬r (enum r o' ho') (enum r o ho) ↔ o ≤ o')) (Eq.symm (propext not_lt))))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (¬r (enum r o' ho') (enum r o ho) ↔ ¬o' < o))
(propext (enum_lt ho' ho))))
(iff.refl (¬o' < o)))
/-- `univ.{u v}` is the order type of the ordinals of `Type u` as a member
of `ordinal.{v}` (when `u < v`). It is an inaccessible cardinal. -/
def univ : ordinal := lift (type Less)
theorem univ_id : univ = type Less := lift_id (type Less)
@[simp] theorem lift_univ : lift univ = univ := lift_lift (type Less)
theorem univ_umax : univ = univ := congr_fun lift_umax (type Less)
/-- Principal segment version of the lift operation on ordinals, embedding `ordinal.{u}` in
`ordinal.{v}` as a principal segment when `u < v`. -/
def lift.principal_seg : principal_seg Less Less := principal_seg.mk (↑lift.initial_seg) univ sorry
@[simp] theorem lift.principal_seg_coe : ⇑lift.principal_seg = lift := rfl
@[simp] theorem lift.principal_seg_top : principal_seg.top lift.principal_seg = univ := rfl
theorem lift.principal_seg_top' : principal_seg.top lift.principal_seg = type Less := sorry
/-! ### Minimum -/
/-- The minimal element of a nonempty family of ordinals -/
def min {ι : Sort u_1} (I : Nonempty ι) (f : ι → ordinal) : ordinal :=
well_founded.min wf (set.range f) sorry
theorem min_eq {ι : Sort u_1} (I : Nonempty ι) (f : ι → ordinal) : ∃ (i : ι), min I f = f i := sorry
theorem min_le {ι : Sort u_1} {I : Nonempty ι} (f : ι → ordinal) (i : ι) : min I f ≤ f i :=
le_of_not_gt (well_founded.not_lt_min wf (set.range f) (min._match_1 f I) (set.mem_range_self i))
theorem le_min {ι : Sort u_1} {I : Nonempty ι} {f : ι → ordinal} {a : ordinal} :
a ≤ min I f ↔ ∀ (i : ι), a ≤ f i :=
sorry
/-- The minimal element of a nonempty set of ordinals -/
def omin (S : set ordinal) (H : ∃ (x : ordinal), x ∈ S) : ordinal := min sorry subtype.val
theorem omin_mem (S : set ordinal) (H : ∃ (x : ordinal), x ∈ S) : omin S H ∈ S := sorry
theorem le_omin {S : set ordinal} {H : ∃ (x : ordinal), x ∈ S} {a : ordinal} :
a ≤ omin S H ↔ ∀ (i : ordinal), i ∈ S → a ≤ i :=
iff.trans le_min set_coe.forall
theorem omin_le {S : set ordinal} {H : ∃ (x : ordinal), x ∈ S} {i : ordinal} (h : i ∈ S) :
omin S H ≤ i :=
iff.mp le_omin (le_refl (omin S H)) i h
@[simp] theorem lift_min {ι : Sort u_1} (I : Nonempty ι) (f : ι → ordinal) :
lift (min I f) = min I (lift ∘ f) :=
sorry
end ordinal
/-! ### Representing a cardinal with an ordinal -/
namespace cardinal
/-- The ordinal corresponding to a cardinal `c` is the least ordinal
whose cardinal is `c`. For the order-embedding version, see `ord.order_embedding`. -/
def ord (c : cardinal) : ordinal :=
let ι : Type u_1 → Type (max u_1 0) :=
fun (α : Type u_1) => Subtype fun (r : α → α → Prop) => is_well_order α r;
let F : Type u_1 → ordinal :=
fun (α : Type u_1) =>
ordinal.min sorry fun (i : ι α) => quotient.mk (Well_order.mk α (subtype.val i) sorry);
quot.lift_on c F sorry
def ord_eq_min (α : Type u) :
ord (mk α) =
ordinal.min (ord._proof_1 α)
fun (i : Subtype fun (r : α → α → Prop) => is_well_order α r) =>
quotient.mk (Well_order.mk α (subtype.val i) (subtype.property i)) :=
rfl
theorem ord_eq (α : Type u_1) : ∃ (r : α → α → Prop), Exists (ord (mk α) = ordinal.type r) := sorry
theorem ord_le_type {α : Type u_1} (r : α → α → Prop) [is_well_order α r] :
ord (mk α) ≤ ordinal.type r :=
sorry
theorem ord_le {c : cardinal} {o : ordinal} : ord c ≤ o ↔ c ≤ ordinal.card o := sorry
theorem lt_ord {c : cardinal} {o : ordinal} : o < ord c ↔ ordinal.card o < c := sorry
@[simp] theorem card_ord (c : cardinal) : ordinal.card (ord c) = c := sorry
theorem ord_card_le (o : ordinal) : ord (ordinal.card o) ≤ o :=
iff.mpr ord_le (le_refl (ordinal.card o))
theorem lt_ord_succ_card (o : ordinal) : o < ord (succ (ordinal.card o)) :=
eq.mpr (id (Eq._oldrec (Eq.refl (o < ord (succ (ordinal.card o)))) (propext lt_ord)))
(lt_succ_self (ordinal.card o))
@[simp] theorem ord_le_ord {c₁ : cardinal} {c₂ : cardinal} : ord c₁ ≤ ord c₂ ↔ c₁ ≤ c₂ := sorry
@[simp] theorem ord_lt_ord {c₁ : cardinal} {c₂ : cardinal} : ord c₁ < ord c₂ ↔ c₁ < c₂ := sorry
@[simp] theorem ord_zero : ord 0 = 0 :=
le_antisymm (iff.mpr ord_le (zero_le (ordinal.card 0))) (ordinal.zero_le (ord 0))
@[simp] theorem ord_nat (n : ℕ) : ord ↑n = ↑n := sorry
@[simp] theorem lift_ord (c : cardinal) : ordinal.lift (ord c) = ord (lift c) := sorry
theorem mk_ord_out (c : cardinal) : mk (Well_order.α (quotient.out (ord c))) = c := sorry
theorem card_typein_lt {α : Type u_1} (r : α → α → Prop) [is_well_order α r] (x : α)
(h : ord (mk α) = ordinal.type r) : ordinal.card (ordinal.typein r x) < mk α :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (ordinal.card (ordinal.typein r x) < mk α))
(Eq.symm (propext ord_lt_ord))))
(eq.mpr (id (Eq._oldrec (Eq.refl (ord (ordinal.card (ordinal.typein r x)) < ord (mk α))) h))
(lt_of_le_of_lt (ord_card_le (ordinal.typein r x)) (ordinal.typein_lt_type r x)))
theorem card_typein_out_lt (c : cardinal) (x : Well_order.α (quotient.out (ord c))) :
ordinal.card (ordinal.typein (Well_order.r (quotient.out (ord c))) x) < c :=
sorry
theorem ord_injective : function.injective ord := sorry
/-- The ordinal corresponding to a cardinal `c` is the least ordinal
whose cardinal is `c`. This is the order-embedding version. For the regular function, see `ord`.
-/
def ord.order_embedding : cardinal ↪o ordinal :=
rel_embedding.order_embedding_of_lt_embedding (rel_embedding.of_monotone ord sorry)
@[simp] theorem ord.order_embedding_coe : ⇑ord.order_embedding = ord := rfl
/-- The cardinal `univ` is the cardinality of ordinal `univ`, or
equivalently the cardinal of `ordinal.{u}`, or `cardinal.{u}`,
as an element of `cardinal.{v}` (when `u < v`). -/
def univ : cardinal := lift (mk ordinal)
theorem univ_id : univ = mk ordinal := lift_id (mk ordinal)
@[simp] theorem lift_univ : lift univ = univ := lift_lift (mk ordinal)
theorem univ_umax : univ = univ := congr_fun lift_umax (mk ordinal)
theorem lift_lt_univ (c : cardinal) : lift c < univ := sorry
theorem lift_lt_univ' (c : cardinal) : lift c < univ := sorry
@[simp] theorem ord_univ : ord univ = ordinal.univ := sorry
theorem lt_univ {c : cardinal} : c < univ ↔ ∃ (c' : cardinal), c = lift c' := sorry
theorem lt_univ' {c : cardinal} : c < univ ↔ ∃ (c' : cardinal), c = lift c' := sorry
end cardinal
namespace ordinal
@[simp] theorem card_univ : card univ = cardinal.univ := rfl
end Mathlib |
a0f5263e1acbd9b4b9cc80230fd562657de20640 | aa44b2a5876642f9460205af61a5449b74465655 | /src/polynomial.lean | 5ec16e71838ef992d9c5d7ad0c516bac677b0106 | [] | no_license | robertylewis/mathematica_examples | d129d67de147dc2792dcf0b6b70fac9b2eaf8274 | e317381c49db032accef2a92e7650d029952ad76 | refs/heads/master | 1,632,630,516,240 | 1,631,905,726,000 | 1,631,905,726,000 | 80,952,455 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,273 | lean |
/-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
-/
import mathematica
import tactic.norm_num
import data.real.pi
open expr tactic int
/-!
The examples in this file show how we can use Mathematica to solve polynomial equations
and then verify the results in Lean using the tactic `norm_num`,
which simplifies numeral arithmetic.
-/
/-!
Auxiliary functions about lists.
-/
meta def pexpr_of_list_expr : list expr → pexpr
| [] := ``([])
| (h::t) := ``(%%h::%%(pexpr_of_list_expr t) : list _)
meta def expr_of_list_expr : list expr → tactic expr :=
to_expr ∘ pexpr_of_list_expr
meta def dest_list_fst (e : expr) : tactic expr :=
do _::k::_ ← match_app_of e `list.cons, return k
meta def expr_list_of_list_expr : expr → tactic (list expr)
| (app (app (app (const `list.cons _) _) h) t) :=
do t' ← expr_list_of_list_expr t,
return $ h :: t'
| (app (const `list.nil _) _) := return []
| _ := failed
meta def mk_local_lambdas : expr → tactic (list expr × expr)
| (expr.lam n bi d b) := do
p ← mk_local' n bi d,
(ps, r) ← mk_local_lambdas (expr.instantiate_var b p),
return ((p :: ps), r)
| e := return ([], e)
meta def exists_to_lambda : expr → expr
| (app (app (const `Exists _) _) (lam nm bi tp bod)) := lam nm bi tp (exists_to_lambda bod)
| a := a
/--
This tactic tries to prove a goal of the form `∃ x1 ... xn, _` by asking Mathematica to produce
values `x1 ... xn`. Given these values, it tries to close the goal by calling `norm_num`.
-/
meta def find_sols : tactic unit :=
do lamd ← exists_to_lambda <$> target,
(lcls, bod) ← mk_local_lambdas lamd,
lcls' ← expr_of_list_expr lcls,
sol ← mathematica.run_command_on_2_using
(λ s t, "Solve[ " ++ s ++ "// LeanForm // Activate, " ++ t ++" // LeanForm // Activate, Reals] // LUnrule")
bod lcls' "poly.m",
tp ← infer_type lcls.head,
intes ← to_expr ``(%%sol : list (list %%tp)) >>= dest_list_fst >>= expr_list_of_list_expr,
intes.mmap' existsi,
`[norm_num]
lemma e1 : ∃ x y : ℤ, x*x*x-y=0 ∧ y-8=0 := by find_sols
lemma e2 : ∃ r : ℝ, r+r = 3 := by find_sols
-- no new axioms were added to the environment.
#print axioms
|
8fb3f6b3fb8d7be15e1935166b10986d2baea25c | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/topology/unit_interval.lean | c9182c0dc2f14ead0769127e8ba6dde927bb3a28 | [
"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 | 6,018 | lean | /-
Copyright (c) 2020 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Scott Morrison
-/
import topology.instances.real
import topology.algebra.field
import data.set.intervals.proj_Icc
/-!
# The unit interval, as a topological space
Use `open_locale unit_interval` to turn on the notation `I := set.Icc (0 : ℝ) (1 : ℝ)`.
We provide basic instances, as well as a custom tactic for discharging
`0 ≤ ↑x`, `0 ≤ 1 - ↑x`, `↑x ≤ 1`, and `1 - ↑x ≤ 1` when `x : I`.
-/
noncomputable theory
open_locale classical topological_space filter
open set
/-! ### The unit interval -/
/-- The unit interval `[0,1]` in ℝ. -/
abbreviation unit_interval : set ℝ := set.Icc 0 1
localized "notation `I` := unit_interval" in unit_interval
namespace unit_interval
lemma mem_iff_one_sub_mem {t : ℝ} : t ∈ I ↔ 1 - t ∈ I :=
begin
rw [mem_Icc, mem_Icc],
split ; intro ; split ; linarith
end
instance has_zero : has_zero I := ⟨⟨0, by split ; norm_num⟩⟩
@[simp, norm_cast] lemma coe_zero : ((0 : I) : ℝ) = 0 := rfl
@[simp] lemma mk_zero (h : (0 : ℝ) ∈ Icc (0 : ℝ) 1) : (⟨0, h⟩ : I) = 0 := rfl
@[simp, norm_cast] lemma coe_eq_zero {x : I} : (x : ℝ) = 0 ↔ x = 0 :=
by { symmetry, exact subtype.ext_iff }
instance has_one : has_one I := ⟨⟨1, by split ; norm_num⟩⟩
@[simp, norm_cast] lemma coe_one : ((1 : I) : ℝ) = 1 := rfl
lemma coe_ne_zero {x : I} : (x : ℝ) ≠ 0 ↔ x ≠ 0 :=
not_iff_not.mpr coe_eq_zero
@[simp] lemma mk_one (h : (1 : ℝ) ∈ Icc (0 : ℝ) 1) : (⟨1, h⟩ : I) = 1 := rfl
@[simp, norm_cast] lemma coe_eq_one {x : I} : (x : ℝ) = 1 ↔ x = 1 :=
by { symmetry, exact subtype.ext_iff }
lemma coe_ne_one {x : I} : (x : ℝ) ≠ 1 ↔ x ≠ 1 :=
not_iff_not.mpr coe_eq_one
instance : nonempty I := ⟨0⟩
lemma mul_mem (x y : I) : (x : ℝ) * y ∈ I :=
⟨mul_nonneg x.2.1 y.2.1, (mul_le_mul x.2.2 y.2.2 y.2.1 zero_le_one).trans_eq $ one_mul 1⟩
instance : has_mul I := ⟨λ x y, ⟨x * y, mul_mem x y⟩⟩
@[simp, norm_cast] lemma coe_mul {x y : I} : ((x * y : I) : ℝ) = x * y := rfl
-- todo: we could set up a `linear_ordered_comm_monoid_with_zero I` instance
lemma mul_le_left {x y : I} : x * y ≤ x :=
subtype.coe_le_coe.mp $ (mul_le_mul_of_nonneg_left y.2.2 x.2.1).trans_eq $ mul_one x
lemma mul_le_right {x y : I} : x * y ≤ y :=
subtype.coe_le_coe.mp $ (mul_le_mul_of_nonneg_right x.2.2 y.2.1).trans_eq $ one_mul y
/-- Unit interval central symmetry. -/
def symm : I → I := λ t, ⟨1 - t.val, mem_iff_one_sub_mem.mp t.property⟩
localized "notation `σ` := unit_interval.symm" in unit_interval
@[simp] lemma symm_zero : σ 0 = 1 :=
subtype.ext $ by simp [symm]
@[simp] lemma symm_one : σ 1 = 0 :=
subtype.ext $ by simp [symm]
@[simp] lemma symm_symm (x : I) : σ (σ x) = x :=
subtype.ext $ by simp [symm]
@[simp] lemma coe_symm_eq (x : I) : (σ x : ℝ) = 1 - x := rfl
@[continuity]
lemma continuous_symm : continuous σ :=
by continuity!
instance : connected_space I :=
subtype.connected_space ⟨nonempty_Icc.mpr zero_le_one, is_preconnected_Icc⟩
/-- Verify there is an instance for `compact_space I`. -/
example : compact_space I := by apply_instance
lemma nonneg (x : I) : 0 ≤ (x : ℝ) := x.2.1
lemma one_minus_nonneg (x : I) : 0 ≤ 1 - (x : ℝ) := by simpa using x.2.2
lemma le_one (x : I) : (x : ℝ) ≤ 1 := x.2.2
lemma one_minus_le_one (x : I) : 1 - (x : ℝ) ≤ 1 := by simpa using x.2.1
/-- like `unit_interval.nonneg`, but with the inequality in `I`. -/
lemma nonneg' {t : I} : 0 ≤ t := t.2.1
/-- like `unit_interval.le_one`, but with the inequality in `I`. -/
lemma le_one' {t : I} : t ≤ 1 := t.2.2
lemma mul_pos_mem_iff {a t : ℝ} (ha : 0 < a) : a * t ∈ I ↔ t ∈ set.Icc (0 : ℝ) (1/a) :=
begin
split; rintros ⟨h₁, h₂⟩; split,
{ exact nonneg_of_mul_nonneg_left h₁ ha },
{ rwa [le_div_iff ha, mul_comm] },
{ exact mul_nonneg ha.le h₁ },
{ rwa [le_div_iff ha, mul_comm] at h₂ }
end
lemma two_mul_sub_one_mem_iff {t : ℝ} : 2 * t - 1 ∈ I ↔ t ∈ set.Icc (1/2 : ℝ) 1 :=
by split; rintros ⟨h₁, h₂⟩; split; linarith
end unit_interval
@[simp] lemma proj_Icc_eq_zero {x : ℝ} : proj_Icc (0 : ℝ) 1 zero_le_one x = 0 ↔ x ≤ 0 :=
proj_Icc_eq_left zero_lt_one
@[simp] lemma proj_Icc_eq_one {x : ℝ} : proj_Icc (0 : ℝ) 1 zero_le_one x = 1 ↔ 1 ≤ x :=
proj_Icc_eq_right zero_lt_one
namespace tactic.interactive
/-- A tactic that solves `0 ≤ ↑x`, `0 ≤ 1 - ↑x`, `↑x ≤ 1`, and `1 - ↑x ≤ 1` for `x : I`. -/
meta def unit_interval : tactic unit :=
`[apply unit_interval.nonneg] <|> `[apply unit_interval.one_minus_nonneg] <|>
`[apply unit_interval.le_one] <|> `[apply unit_interval.one_minus_le_one]
end tactic.interactive
section
variables {𝕜 : Type*} [linear_ordered_field 𝕜] [topological_space 𝕜] [topological_ring 𝕜]
/--
The image of `[0,1]` under the homeomorphism `λ x, a * x + b` is `[b, a+b]`.
-/
-- We only need the ordering on `𝕜` here to avoid talking about flipping the interval over.
-- At the end of the day I only care about `ℝ`, so I'm hesitant to put work into generalizing.
lemma affine_homeomorph_image_I (a b : 𝕜) (h : 0 < a) :
affine_homeomorph a b h.ne.symm '' set.Icc 0 1 = set.Icc b (a + b) :=
by simp [h]
/--
The affine homeomorphism from a nontrivial interval `[a,b]` to `[0,1]`.
-/
def Icc_homeo_I (a b : 𝕜) (h : a < b) : set.Icc a b ≃ₜ set.Icc (0 : 𝕜) (1 : 𝕜) :=
begin
let e := homeomorph.image (affine_homeomorph (b-a) a (sub_pos.mpr h).ne.symm) (set.Icc 0 1),
refine (e.trans _).symm,
apply homeomorph.set_congr,
simp [sub_pos.mpr h],
end
@[simp] lemma Icc_homeo_I_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc a b) :
((Icc_homeo_I a b h) x : 𝕜) = (x - a) / (b - a) :=
rfl
@[simp] lemma Icc_homeo_I_symm_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc (0 : 𝕜) (1 : 𝕜)) :
((Icc_homeo_I a b h).symm x : 𝕜) = (b - a) * x + a :=
rfl
end
|
213e8c7d843cb82957eafe0900414bbfb12f7330 | bb31430994044506fa42fd667e2d556327e18dfe | /src/order/succ_pred/interval_succ.lean | 79a635165d2a4eed91dd50cc268f9905e8e1ce30 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 7,010 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import data.set.pairwise
import order.succ_pred.basic
/-!
# Intervals `Ixx (f x) (f (order.succ x))`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove
* `monotone.bUnion_Ico_Ioc_map_succ`: if `α` is a linear archimedean succ order and `β` is a linear
order, then for any monotone function `f` and `m n : α`, the union of intervals
`set.Ioc (f i) (f (order.succ i))`, `m ≤ i < n`, is equal to `set.Ioc (f m) (f n)`;
* `monotone.pairwise_disjoint_on_Ioc_succ`: if `α` is a linear succ order, `β` is a preorder, and
`f : α → β` is a monotone function, then the intervals `set.Ioc (f n) (f (order.succ n))` are
pairwise disjoint.
For the latter lemma, we also prove various order dual versions.
-/
open set order
variables {α β : Type*} [linear_order α]
namespace monotone
/-- If `α` is a linear archimedean succ order and `β` is a linear order, then for any monotone
function `f` and `m n : α`, the union of intervals `set.Ioc (f i) (f (order.succ i))`, `m ≤ i < n`,
is equal to `set.Ioc (f m) (f n)` -/
lemma bUnion_Ico_Ioc_map_succ [succ_order α] [is_succ_archimedean α]
[linear_order β] {f : α → β} (hf : monotone f) (m n : α) :
(⋃ i ∈ Ico m n, Ioc (f i) (f (succ i))) = Ioc (f m) (f n) :=
begin
cases le_total n m with hnm hmn,
{ rw [Ico_eq_empty_of_le hnm, Ioc_eq_empty_of_le (hf hnm), bUnion_empty] },
{ refine succ.rec _ _ hmn,
{ simp only [Ioc_self, Ico_self, bUnion_empty] },
{ intros k hmk ihk,
rw [← Ioc_union_Ioc_eq_Ioc (hf hmk) (hf $ le_succ _), union_comm, ← ihk],
by_cases hk : is_max k,
{ rw [hk.succ_eq, Ioc_self, empty_union] },
{ rw [Ico_succ_right_eq_insert_of_not_is_max hmk hk, bUnion_insert] } } }
end
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ioc (f n) (f (order.succ n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioc_succ [succ_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ioc (f n) (f (succ n)))) :=
(pairwise_disjoint_on _).2 $ λ m n hmn,
disjoint_iff_inf_le.mpr $ λ x ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩, h₂.not_le $ h₁.trans $ hf $ succ_le_of_lt hmn
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ico (f n) (f (order.succ n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ico_succ [succ_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ico (f n) (f (succ n)))) :=
(pairwise_disjoint_on _).2 $ λ m n hmn,
disjoint_iff_inf_le.mpr $ λ x ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩, h₁.not_le $ (hf $ succ_le_of_lt hmn).trans h₂
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ioo (f n) (f (order.succ n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioo_succ [succ_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ioo (f n) (f (succ n)))) :=
hf.pairwise_disjoint_on_Ico_succ.mono $ λ i j h, h.mono Ioo_subset_Ico_self Ioo_subset_Ico_self
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ioc (f order.pred n) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioc_pred [pred_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ioc (f (pred n)) (f n))) :=
by simpa only [(∘), dual_Ico] using hf.dual.pairwise_disjoint_on_Ico_succ
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ico (f order.pred n) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ico_pred [pred_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ico (f (pred n)) (f n))) :=
by simpa only [(∘), dual_Ioc] using hf.dual.pairwise_disjoint_on_Ioc_succ
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then
the intervals `set.Ioo (f order.pred n) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioo_pred [pred_order α] [preorder β] {f : α → β} (hf : monotone f) :
pairwise (disjoint on (λ n, Ioo (f (pred n)) (f n))) :=
by simpa only [(∘), dual_Ioo] using hf.dual.pairwise_disjoint_on_Ioo_succ
end monotone
namespace antitone
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ioc (f (order.succ n)) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioc_succ [succ_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ioc (f (succ n)) (f n))) :=
hf.dual_left.pairwise_disjoint_on_Ioc_pred
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ico (f (order.succ n)) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ico_succ [succ_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ico (f (succ n)) (f n))) :=
hf.dual_left.pairwise_disjoint_on_Ico_pred
/-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ioo (f (order.succ n)) (f n)` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioo_succ [succ_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ioo (f (succ n)) (f n))) :=
hf.dual_left.pairwise_disjoint_on_Ioo_pred
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ioc (f n) (f (order.pred n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioc_pred [pred_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ioc (f n) (f (pred n)))) :=
hf.dual_left.pairwise_disjoint_on_Ioc_succ
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ico (f n) (f (order.pred n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ico_pred [pred_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ico (f n) (f (pred n)))) :=
hf.dual_left.pairwise_disjoint_on_Ico_succ
/-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then
the intervals `set.Ioo (f n) (f (order.pred n))` are pairwise disjoint. -/
lemma pairwise_disjoint_on_Ioo_pred [pred_order α] [preorder β] {f : α → β} (hf : antitone f) :
pairwise (disjoint on (λ n, Ioo (f n) (f (pred n)))) :=
hf.dual_left.pairwise_disjoint_on_Ioo_succ
end antitone
|
b9ec8a4d2c3d0fdcb3f3465d2febe3c4983afcdf | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/inner_product_space/adjoint.lean | fc84943f1dece7fc9a96ffaeec87446f267a4de3 | [
"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 | 13,710 | lean | /-
Copyright (c) 2021 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Heather Macbeth
-/
import analysis.inner_product_space.dual
import analysis.inner_product_space.pi_L2
/-!
# Adjoint of operators on Hilbert spaces
Given an operator `A : E →L[𝕜] F`, where `E` and `F` are Hilbert spaces, its adjoint
`adjoint A : F →L[𝕜] E` is the unique operator such that `⟪x, A y⟫ = ⟪adjoint A x, y⟫` for all
`x` and `y`.
We then use this to put a C⋆-algebra structure on `E →L[𝕜] E` with the adjoint as the star
operation.
This construction is used to define an adjoint for linear maps (i.e. not continuous) between
finite dimensional spaces.
## Main definitions
* `continuous_linear_map.adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] (F →L[𝕜] E)`: the adjoint of a continuous
linear map, bundled as a conjugate-linear isometric equivalence.
* `linear_map.adjoint : (E →ₗ[𝕜] F) ≃ₗ⋆[𝕜] (F →ₗ[𝕜] E)`: the adjoint of a linear map between
finite-dimensional spaces, this time only as a conjugate-linear equivalence, since there is no
norm defined on these maps.
## Implementation notes
* The continuous conjugate-linear version `adjoint_aux` is only an intermediate
definition and is not meant to be used outside this file.
## Tags
adjoint
-/
noncomputable theory
open inner_product_space continuous_linear_map is_R_or_C
open_locale complex_conjugate
variables {𝕜 E F G : Type*} [is_R_or_C 𝕜]
variables [inner_product_space 𝕜 E] [inner_product_space 𝕜 F] [inner_product_space 𝕜 G]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
namespace continuous_linear_map
variables [complete_space E] [complete_space G]
/-- The adjoint, as a continuous conjugate-linear map. This is only meant as an auxiliary
definition for the main definition `adjoint`, where this is bundled as a conjugate-linear isometric
equivalence. -/
def adjoint_aux : (E →L[𝕜] F) →L⋆[𝕜] (F →L[𝕜] E) :=
(continuous_linear_map.compSL _ _ _ _ _ ((to_dual 𝕜 E).symm : normed_space.dual 𝕜 E →L⋆[𝕜] E)).comp
(to_sesq_form : (E →L[𝕜] F) →L[𝕜] F →L⋆[𝕜] normed_space.dual 𝕜 E)
@[simp] lemma adjoint_aux_apply (A : E →L[𝕜] F) (x : F) :
adjoint_aux A x = ((to_dual 𝕜 E).symm : (normed_space.dual 𝕜 E) → E) ((to_sesq_form A) x) := rfl
lemma adjoint_aux_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪adjoint_aux A y, x⟫ = ⟪y, A x⟫ :=
by { simp only [adjoint_aux_apply, to_dual_symm_apply, to_sesq_form_apply_coe, coe_comp',
innerSL_apply_coe]}
lemma adjoint_aux_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, adjoint_aux A y⟫ = ⟪A x, y⟫ :=
by rw [←inner_conj_sym, adjoint_aux_inner_left, inner_conj_sym]
variables [complete_space F]
lemma adjoint_aux_adjoint_aux (A : E →L[𝕜] F) : adjoint_aux (adjoint_aux A) = A :=
begin
ext v,
refine ext_inner_left 𝕜 (λ w, _),
rw [adjoint_aux_inner_right, adjoint_aux_inner_left],
end
@[simp] lemma adjoint_aux_norm (A : E →L[𝕜] F) : ∥adjoint_aux A∥ = ∥A∥ :=
begin
refine le_antisymm _ _,
{ refine continuous_linear_map.op_norm_le_bound _ (norm_nonneg _) (λ x, _),
rw [adjoint_aux_apply, linear_isometry_equiv.norm_map],
exact to_sesq_form_apply_norm_le },
{ nth_rewrite_lhs 0 [←adjoint_aux_adjoint_aux A],
refine continuous_linear_map.op_norm_le_bound _ (norm_nonneg _) (λ x, _),
rw [adjoint_aux_apply, linear_isometry_equiv.norm_map],
exact to_sesq_form_apply_norm_le }
end
/-- The adjoint of a bounded operator from Hilbert space E to Hilbert space F. -/
def adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] (F →L[𝕜] E) :=
linear_isometry_equiv.of_surjective
{ norm_map' := adjoint_aux_norm,
..adjoint_aux }
(λ A, ⟨adjoint_aux A, adjoint_aux_adjoint_aux A⟩)
localized "postfix `†`:1000 := adjoint" in inner_product
/-- The fundamental property of the adjoint. -/
lemma adjoint_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪A† y, x⟫ = ⟪y, A x⟫ :=
adjoint_aux_inner_left A x y
/-- The fundamental property of the adjoint. -/
lemma adjoint_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, A† y⟫ = ⟪A x, y⟫ :=
adjoint_aux_inner_right A x y
/-- The adjoint is involutive -/
@[simp] lemma adjoint_adjoint (A : E →L[𝕜] F) : A†† = A :=
adjoint_aux_adjoint_aux A
/-- The adjoint of the composition of two operators is the composition of the two adjoints
in reverse order. -/
@[simp] lemma adjoint_comp (A : F →L[𝕜] G) (B : E →L[𝕜] F) : (A ∘L B)† = B† ∘L A† :=
begin
ext v,
refine ext_inner_left 𝕜 (λ w, _),
simp only [adjoint_inner_right, continuous_linear_map.coe_comp', function.comp_app],
end
lemma apply_norm_sq_eq_inner_adjoint_left (A : E →L[𝕜] E) (x : E) : ∥A x∥^2 = re ⟪(A† * A) x, x⟫ :=
have h : ⟪(A† * A) x, x⟫ = ⟪A x, A x⟫ := by { rw [←adjoint_inner_left], refl },
by rw [h, ←inner_self_eq_norm_sq _]
lemma apply_norm_eq_sqrt_inner_adjoint_left (A : E →L[𝕜] E) (x : E) :
∥A x∥ = real.sqrt (re ⟪(A† * A) x, x⟫) :=
by rw [←apply_norm_sq_eq_inner_adjoint_left, real.sqrt_sq (norm_nonneg _)]
lemma apply_norm_sq_eq_inner_adjoint_right (A : E →L[𝕜] E) (x : E) : ∥A x∥^2 = re ⟪x, (A† * A) x⟫ :=
have h : ⟪x, (A† * A) x⟫ = ⟪A x, A x⟫ := by { rw [←adjoint_inner_right], refl },
by rw [h, ←inner_self_eq_norm_sq _]
lemma apply_norm_eq_sqrt_inner_adjoint_right (A : E →L[𝕜] E) (x : E) :
∥A x∥ = real.sqrt (re ⟪x, (A† * A) x⟫) :=
by rw [←apply_norm_sq_eq_inner_adjoint_right, real.sqrt_sq (norm_nonneg _)]
/-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫`
for all `x` and `y`. -/
lemma eq_adjoint_iff (A : E →L[𝕜] F) (B : F →L[𝕜] E) :
A = B† ↔ (∀ x y, ⟪A x, y⟫ = ⟪x, B y⟫) :=
begin
refine ⟨λ h x y, by rw [h, adjoint_inner_left], λ h, _⟩,
ext x,
exact ext_inner_right 𝕜 (λ y, by simp only [adjoint_inner_left, h x y])
end
/-- `E →L[𝕜] E` is a star algebra with the adjoint as the star operation. -/
instance : has_star (E →L[𝕜] E) := ⟨adjoint⟩
instance : has_involutive_star (E →L[𝕜] E) := ⟨adjoint_adjoint⟩
instance : star_monoid (E →L[𝕜] E) := ⟨adjoint_comp⟩
instance : star_ring (E →L[𝕜] E) := ⟨linear_isometry_equiv.map_add adjoint⟩
instance : star_module 𝕜 (E →L[𝕜] E) := ⟨linear_isometry_equiv.map_smulₛₗ adjoint⟩
lemma star_eq_adjoint (A : E →L[𝕜] E) : star A = A† := rfl
instance : cstar_ring (E →L[𝕜] E) :=
⟨begin
intros A,
rw [star_eq_adjoint],
refine le_antisymm _ _,
{ calc ∥A† * A∥ ≤ ∥A†∥ * ∥A∥ : op_norm_comp_le _ _
... = ∥A∥ * ∥A∥ : by rw [linear_isometry_equiv.norm_map] },
{ rw [←sq, ←real.sqrt_le_sqrt_iff (norm_nonneg _), real.sqrt_sq (norm_nonneg _)],
refine op_norm_le_bound _ (real.sqrt_nonneg _) (λ x, _),
have := calc
re ⟪(A† * A) x, x⟫ ≤ ∥(A† * A) x∥ * ∥x∥ : re_inner_le_norm _ _
... ≤ ∥A† * A∥ * ∥x∥ * ∥x∥ : mul_le_mul_of_nonneg_right
(le_op_norm _ _) (norm_nonneg _),
calc ∥A x∥ = real.sqrt (re ⟪(A† * A) x, x⟫) : by rw [apply_norm_eq_sqrt_inner_adjoint_left]
... ≤ real.sqrt (∥A† * A∥ * ∥x∥ * ∥x∥) : real.sqrt_le_sqrt this
... = real.sqrt (∥A† * A∥) * ∥x∥
: by rw [mul_assoc, real.sqrt_mul (norm_nonneg _), real.sqrt_mul_self (norm_nonneg _)] }
end⟩
section real
variables {E' : Type*} {F' : Type*} [inner_product_space ℝ E'] [inner_product_space ℝ F']
variables [complete_space E'] [complete_space F']
lemma is_adjoint_pair (A : E' →L[ℝ] F') :
bilin_form.is_adjoint_pair (bilin_form_of_real_inner : bilin_form ℝ E')
(bilin_form_of_real_inner : bilin_form ℝ F') A (A†) :=
λ x y, by simp only [adjoint_inner_right, to_linear_map_eq_coe,
bilin_form_of_real_inner_apply, coe_coe]
end real
end continuous_linear_map
namespace linear_map
variables [finite_dimensional 𝕜 E] [finite_dimensional 𝕜 F] [finite_dimensional 𝕜 G]
local attribute [instance, priority 20] finite_dimensional.complete
/-- The adjoint of an operator from the finite-dimensional inner product space E to the finite-
dimensional inner product space F. -/
def adjoint : (E →ₗ[𝕜] F) ≃ₗ⋆[𝕜] (F →ₗ[𝕜] E) :=
(linear_map.to_continuous_linear_map.trans continuous_linear_map.adjoint.to_linear_equiv).trans
linear_map.to_continuous_linear_map.symm
lemma adjoint_to_continuous_linear_map (A : E →ₗ[𝕜] F) :
A.adjoint.to_continuous_linear_map = A.to_continuous_linear_map.adjoint := rfl
lemma adjoint_eq_to_clm_adjoint (A : E →ₗ[𝕜] F) :
A.adjoint = A.to_continuous_linear_map.adjoint := rfl
/-- The fundamental property of the adjoint. -/
lemma adjoint_inner_left (A : E →ₗ[𝕜] F) (x : E) (y : F) : ⟪adjoint A y, x⟫ = ⟪y, A x⟫ :=
begin
rw [←coe_to_continuous_linear_map A, adjoint_eq_to_clm_adjoint],
exact continuous_linear_map.adjoint_inner_left _ x y,
end
/-- The fundamental property of the adjoint. -/
lemma adjoint_inner_right (A : E →ₗ[𝕜] F) (x : E) (y : F) : ⟪x, adjoint A y⟫ = ⟪A x, y⟫ :=
begin
rw [←coe_to_continuous_linear_map A, adjoint_eq_to_clm_adjoint],
exact continuous_linear_map.adjoint_inner_right _ x y,
end
/-- The adjoint is involutive -/
@[simp] lemma adjoint_adjoint (A : E →ₗ[𝕜] F) : A.adjoint.adjoint = A :=
begin
ext v,
refine ext_inner_left 𝕜 (λ w, _),
rw [adjoint_inner_right, adjoint_inner_left],
end
/-- The adjoint of the composition of two operators is the composition of the two adjoints
in reverse order. -/
@[simp] lemma adjoint_comp (A : F →ₗ[𝕜] G) (B : E →ₗ[𝕜] F) :
(A ∘ₗ B).adjoint = B.adjoint ∘ₗ A.adjoint :=
begin
ext v,
refine ext_inner_left 𝕜 (λ w, _),
simp only [adjoint_inner_right, linear_map.coe_comp, function.comp_app],
end
/-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫`
for all `x` and `y`. -/
lemma eq_adjoint_iff (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) :
A = B.adjoint ↔ (∀ x y, ⟪A x, y⟫ = ⟪x, B y⟫) :=
begin
refine ⟨λ h x y, by rw [h, adjoint_inner_left], λ h, _⟩,
ext x,
exact ext_inner_right 𝕜 (λ y, by simp only [adjoint_inner_left, h x y])
end
/-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫`
for all basis vectors `x` and `y`. -/
lemma eq_adjoint_iff_basis {ι₁ : Type*} {ι₂ : Type*} (b₁ : basis ι₁ 𝕜 E) (b₂ : basis ι₂ 𝕜 F)
(A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) :
A = B.adjoint ↔ (∀ (i₁ : ι₁) (i₂ : ι₂), ⟪A (b₁ i₁), b₂ i₂⟫ = ⟪b₁ i₁, B (b₂ i₂)⟫) :=
begin
refine ⟨λ h x y, by rw [h, adjoint_inner_left], λ h, _⟩,
refine basis.ext b₁ (λ i₁, _),
exact ext_inner_right_basis b₂ (λ i₂, by simp only [adjoint_inner_left, h i₁ i₂]),
end
lemma eq_adjoint_iff_basis_left {ι : Type*} (b : basis ι 𝕜 E) (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) :
A = B.adjoint ↔ (∀ i y, ⟪A (b i), y⟫ = ⟪b i, B y⟫) :=
begin
refine ⟨λ h x y, by rw [h, adjoint_inner_left], λ h, basis.ext b (λ i, _)⟩,
exact ext_inner_right 𝕜 (λ y, by simp only [h i, adjoint_inner_left]),
end
lemma eq_adjoint_iff_basis_right {ι : Type*} (b : basis ι 𝕜 F) (A : E →ₗ[𝕜] F) (B : F →ₗ[𝕜] E) :
A = B.adjoint ↔ (∀ i x, ⟪A x, b i⟫ = ⟪x, B (b i)⟫) :=
begin
refine ⟨λ h x y, by rw [h, adjoint_inner_left], λ h, _⟩,
ext x,
refine ext_inner_right_basis b (λ i, by simp only [h i, adjoint_inner_left]),
end
/-- `E →ₗ[𝕜] E` is a star algebra with the adjoint as the star operation. -/
instance : has_star (E →ₗ[𝕜] E) := ⟨adjoint⟩
instance : has_involutive_star (E →ₗ[𝕜] E) := ⟨adjoint_adjoint⟩
instance : star_monoid (E →ₗ[𝕜] E) := ⟨adjoint_comp⟩
instance : star_ring (E →ₗ[𝕜] E) := ⟨linear_equiv.map_add adjoint⟩
instance : star_module 𝕜 (E →ₗ[𝕜] E) := ⟨linear_equiv.map_smulₛₗ adjoint⟩
lemma star_eq_adjoint (A : E →ₗ[𝕜] E) : star A = A.adjoint := rfl
section real
variables {E' : Type*} {F' : Type*} [inner_product_space ℝ E'] [inner_product_space ℝ F']
variables [finite_dimensional ℝ E'] [finite_dimensional ℝ F']
lemma is_adjoint_pair (A : E' →ₗ[ℝ] F') :
bilin_form.is_adjoint_pair (bilin_form_of_real_inner : bilin_form ℝ E')
(bilin_form_of_real_inner : bilin_form ℝ F') A A.adjoint :=
λ x y, by simp only [adjoint_inner_right, bilin_form_of_real_inner_apply]
end real
end linear_map
namespace matrix
variables {m n : Type*} [fintype m] [decidable_eq m] [fintype n] [decidable_eq n]
open_locale complex_conjugate
/-- The adjoint of the linear map associated to a matrix is the linear map associated to the
conjugate transpose of that matrix. -/
lemma conj_transpose_eq_adjoint (A : matrix m n 𝕜) :
to_lin' A.conj_transpose =
@linear_map.adjoint _ (euclidean_space 𝕜 n) (euclidean_space 𝕜 m) _ _ _ _ _ (to_lin' A) :=
begin
rw @linear_map.eq_adjoint_iff _ (euclidean_space 𝕜 m) (euclidean_space 𝕜 n),
intros x y,
convert dot_product_assoc (conj ∘ (id x : m → 𝕜)) y A using 1,
simp [dot_product, mul_vec, ring_hom.map_sum, ← star_ring_end_apply, mul_comm],
end
end matrix
|
4ed799bf0b8fc1b970e6217ac24a8652bb610892 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/nat/sqrt.lean | 5912f4f42079fe84fbf994a9f0b80d66d5d0fa51 | [
"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 | 9,606 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import data.int.basic
/-!
# Square root of natural numbers
This file defines an efficient binary implementation of the square root function that returns the
unique `r` such that `r * r ≤ n < (r + 1) * (r + 1)`. It takes advantage of the binary
representation by replacing the multiplication by 2 appearing in
`(a + b)^2 = a^2 + 2 * a * b + b^2` by a bitmask manipulation.
## Reference
See [Wikipedia, *Methods of computing square roots*]
[https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)].
-/
namespace nat
theorem sqrt_aux_dec {b} (h : b ≠ 0) : shiftr b 2 < b :=
begin
simp only [shiftr_eq_div_pow],
apply (nat.div_lt_iff_lt_mul' (dec_trivial : 0 < 4)).2,
have := nat.mul_lt_mul_of_pos_left
(dec_trivial : 1 < 4) (nat.pos_of_ne_zero h),
rwa mul_one at this
end
/-- Auxiliary function for `nat.sqrt`. See e.g.
<https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)> -/
def sqrt_aux : ℕ → ℕ → ℕ → ℕ
| b r n := if b0 : b = 0 then r else
let b' := shiftr b 2 in
have b' < b, from sqrt_aux_dec b0,
match (n - (r + b : ℕ) : ℤ) with
| (n' : ℕ) := sqrt_aux b' (div2 r + b) n'
| _ := sqrt_aux b' (div2 r) n
end
/-- `sqrt n` is the square root of a natural number `n`. If `n` is not a
perfect square, it returns the largest `k:ℕ` such that `k*k ≤ n`. -/
@[pp_nodot] def sqrt (n : ℕ) : ℕ :=
match size n with
| 0 := 0
| succ s := sqrt_aux (shiftl 1 (bit0 (div2 s))) 0 n
end
theorem sqrt_aux_0 (r n) : sqrt_aux 0 r n = r :=
by rw sqrt_aux; simp
local attribute [simp] sqrt_aux_0
theorem sqrt_aux_1 {r n b} (h : b ≠ 0) {n'} (h₂ : r + b + n' = n) :
sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r + b) n' :=
by rw sqrt_aux; simp only [h, h₂.symm, int.coe_nat_add, if_false];
rw [add_comm _ (n':ℤ), add_sub_cancel, sqrt_aux._match_1]
theorem sqrt_aux_2 {r n b} (h : b ≠ 0) (h₂ : n < r + b) :
sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r) n :=
begin
rw sqrt_aux; simp only [h, h₂, if_false],
cases int.eq_neg_succ_of_lt_zero
(sub_lt_zero.2 (int.coe_nat_lt_coe_nat_of_lt h₂)) with k e,
rw [e, sqrt_aux._match_1]
end
private def is_sqrt (n q : ℕ) : Prop := q*q ≤ n ∧ n < (q+1)*(q+1)
local attribute [-simp] mul_eq_mul_left_iff mul_eq_mul_right_iff
private lemma sqrt_aux_is_sqrt_lemma (m r n : ℕ)
(h₁ : r*r ≤ n)
(m') (hm : shiftr (2^m * 2^m) 2 = m')
(H1 : n < (r + 2^m) * (r + 2^m) →
is_sqrt n (sqrt_aux m' (r * 2^m) (n - r * r)))
(H2 : (r + 2^m) * (r + 2^m) ≤ n →
is_sqrt n (sqrt_aux m' ((r + 2^m) * 2^m) (n - (r + 2^m) * (r + 2^m)))) :
is_sqrt n (sqrt_aux (2^m * 2^m) ((2*r)*2^m) (n - r*r)) :=
begin
have b0 :=
have b0:_, from ne_of_gt (pow_pos (show 0 < 2, from dec_trivial) m),
nat.mul_ne_zero b0 b0,
have lb : n - r * r < 2 * r * 2^m + 2^m * 2^m ↔
n < (r+2^m)*(r+2^m), {
rw [nat.sub_lt_right_iff_lt_add h₁],
simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc,
add_comm, add_assoc, add_left_comm] },
have re : div2 (2 * r * 2^m) = r * 2^m, {
rw [div2_val, mul_assoc,
nat.mul_div_cancel_left _ (dec_trivial:2>0)] },
cases lt_or_ge n ((r+2^m)*(r+2^m)) with hl hl,
{ rw [sqrt_aux_2 b0 (lb.2 hl), hm, re], apply H1 hl },
{ cases le.dest hl with n' e,
rw [@sqrt_aux_1 (2 * r * 2^m) (n-r*r) (2^m * 2^m) b0 (n - (r + 2^m) * (r + 2^m)),
hm, re, ← right_distrib],
{ apply H2 hl },
apply eq.symm, apply nat.sub_eq_of_eq_add,
rw [← add_assoc, (_ : r*r + _ = _)],
exact (nat.add_sub_cancel' hl).symm,
simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc, add_assoc] },
end
private lemma sqrt_aux_is_sqrt (n) : ∀ m r,
r*r ≤ n → n < (r + 2^(m+1)) * (r + 2^(m+1)) →
is_sqrt n (sqrt_aux (2^m * 2^m) (2*r*2^m) (n - r*r))
| 0 r h₁ h₂ := by apply sqrt_aux_is_sqrt_lemma 0 r n h₁ 0 rfl;
intro h; simp; [exact ⟨h₁, h⟩, exact ⟨h, h₂⟩]
| (m+1) r h₁ h₂ := begin
apply sqrt_aux_is_sqrt_lemma
(m+1) r n h₁ (2^m * 2^m)
(by simp [shiftr, pow_succ, div2_val, mul_comm, mul_left_comm];
repeat {rw @nat.mul_div_cancel_left _ 2 dec_trivial});
intro h,
{ have := sqrt_aux_is_sqrt m r h₁ h,
simpa [pow_succ, mul_comm, mul_assoc] },
{ rw [pow_succ', mul_two, ← add_assoc] at h₂,
have := sqrt_aux_is_sqrt m (r + 2^(m+1)) h h₂,
rwa show (r + 2^(m + 1)) * 2^(m+1) = 2 * (r + 2^(m + 1)) * 2^m,
by simp [pow_succ, mul_comm, mul_left_comm] }
end
private lemma sqrt_is_sqrt (n : ℕ) : is_sqrt n (sqrt n) :=
begin
generalize e : size n = s, cases s with s; simp [e, sqrt],
{ rw [size_eq_zero.1 e, is_sqrt], exact dec_trivial },
{ have := sqrt_aux_is_sqrt n (div2 s) 0 (zero_le _),
simp [show 2^div2 s * 2^div2 s = shiftl 1 (bit0 (div2 s)), by {
generalize: div2 s = x,
change bit0 x with x+x,
rw [one_shiftl, pow_add] }] at this,
apply this,
rw [← pow_add, ← mul_two], apply size_le.1,
rw e, apply (@div_lt_iff_lt_mul _ _ 2 dec_trivial).1,
rw [div2_val], apply lt_succ_self }
end
theorem sqrt_le (n : ℕ) : sqrt n * sqrt n ≤ n :=
(sqrt_is_sqrt n).left
theorem sqrt_le' (n : ℕ) : (sqrt n) ^ 2 ≤ n :=
eq.trans_le (sq (sqrt n)) (sqrt_le n)
theorem lt_succ_sqrt (n : ℕ) : n < succ (sqrt n) * succ (sqrt n) :=
(sqrt_is_sqrt n).right
theorem lt_succ_sqrt' (n : ℕ) : n < (succ (sqrt n)) ^ 2 :=
trans_rel_left (λ i j, i < j) (lt_succ_sqrt n) (sq (succ (sqrt n))).symm
theorem sqrt_le_add (n : ℕ) : n ≤ sqrt n * sqrt n + sqrt n + sqrt n :=
by rw ← succ_mul; exact le_of_lt_succ (lt_succ_sqrt n)
theorem le_sqrt {m n : ℕ} : m ≤ sqrt n ↔ m*m ≤ n :=
⟨λ h, le_trans (mul_self_le_mul_self h) (sqrt_le n),
λ h, le_of_lt_succ $ mul_self_lt_mul_self_iff.2 $
lt_of_le_of_lt h (lt_succ_sqrt n)⟩
theorem le_sqrt' {m n : ℕ} : m ≤ sqrt n ↔ m ^ 2 ≤ n :=
by simpa only [pow_two] using le_sqrt
theorem sqrt_lt {m n : ℕ} : sqrt m < n ↔ m < n*n :=
lt_iff_lt_of_le_iff_le le_sqrt
theorem sqrt_lt' {m n : ℕ} : sqrt m < n ↔ m < n ^ 2 :=
lt_iff_lt_of_le_iff_le le_sqrt'
theorem sqrt_le_self (n : ℕ) : sqrt n ≤ n :=
le_trans (le_mul_self _) (sqrt_le n)
theorem sqrt_le_sqrt {m n : ℕ} (h : m ≤ n) : sqrt m ≤ sqrt n :=
le_sqrt.2 (le_trans (sqrt_le _) h)
@[simp] lemma sqrt_zero : sqrt 0 = 0 :=
by rw [sqrt, size_zero, sqrt._match_1]
theorem sqrt_eq_zero {n : ℕ} : sqrt n = 0 ↔ n = 0 :=
⟨λ h, eq_zero_of_le_zero $ le_of_lt_succ $ (@sqrt_lt n 1).1 $
by rw [h]; exact dec_trivial,
by { rintro rfl, simp }⟩
theorem eq_sqrt {n q} : q = sqrt n ↔ q*q ≤ n ∧ n < (q+1)*(q+1) :=
⟨λ e, e.symm ▸ sqrt_is_sqrt n,
λ ⟨h₁, h₂⟩, le_antisymm (le_sqrt.2 h₁) (le_of_lt_succ $ sqrt_lt.2 h₂)⟩
theorem eq_sqrt' {n q} : q = sqrt n ↔ q ^ 2 ≤ n ∧ n < (q+1) ^ 2 :=
by simpa only [pow_two] using eq_sqrt
theorem le_three_of_sqrt_eq_one {n : ℕ} (h : sqrt n = 1) : n ≤ 3 :=
le_of_lt_succ $ (@sqrt_lt n 2).1 $
by rw [h]; exact dec_trivial
theorem sqrt_lt_self {n : ℕ} (h : 1 < n) : sqrt n < n :=
sqrt_lt.2 $ by
have := nat.mul_lt_mul_of_pos_left h (lt_of_succ_lt h);
rwa [mul_one] at this
theorem sqrt_pos {n : ℕ} : 0 < sqrt n ↔ 0 < n := le_sqrt
theorem sqrt_add_eq (n : ℕ) {a : ℕ} (h : a ≤ n + n) : sqrt (n*n + a) = n :=
le_antisymm
(le_of_lt_succ $ sqrt_lt.2 $ by rw [succ_mul, mul_succ, add_succ, add_assoc];
exact lt_succ_of_le (nat.add_le_add_left h _))
(le_sqrt.2 $ nat.le_add_right _ _)
theorem sqrt_add_eq' (n : ℕ) {a : ℕ} (h : a ≤ n + n) : sqrt (n ^ 2 + a) = n :=
(congr_arg (λ i, sqrt (i + a)) (sq n)).trans (sqrt_add_eq n h)
theorem sqrt_eq (n : ℕ) : sqrt (n*n) = n :=
sqrt_add_eq n (zero_le _)
theorem sqrt_eq' (n : ℕ) : sqrt (n ^ 2) = n :=
sqrt_add_eq' n (zero_le _)
theorem sqrt_succ_le_succ_sqrt (n : ℕ) : sqrt n.succ ≤ n.sqrt.succ :=
le_of_lt_succ $ sqrt_lt.2 $ lt_succ_of_le $ succ_le_succ $
le_trans (sqrt_le_add n) $ add_le_add_right
(by refine add_le_add
(mul_le_mul_right _ _) _; exact le_add_right _ 2) _
theorem exists_mul_self (x : ℕ) :
(∃ n, n * n = x) ↔ sqrt x * sqrt x = x :=
⟨λ ⟨n, hn⟩, by rw [← hn, sqrt_eq], λ h, ⟨sqrt x, h⟩⟩
theorem exists_mul_self' (x : ℕ) :
(∃ n, n ^ 2 = x) ↔ (sqrt x) ^ 2 = x :=
by simpa only [pow_two] using exists_mul_self x
theorem sqrt_mul_sqrt_lt_succ (n : ℕ) : sqrt n * sqrt n < n + 1 :=
lt_succ_iff.mpr (sqrt_le _)
theorem sqrt_mul_sqrt_lt_succ' (n : ℕ) : (sqrt n) ^ 2 < n + 1 :=
lt_succ_iff.mpr (sqrt_le' _)
theorem succ_le_succ_sqrt (n : ℕ) : n + 1 ≤ (sqrt n + 1) * (sqrt n + 1) :=
le_of_pred_lt (lt_succ_sqrt _)
theorem succ_le_succ_sqrt' (n : ℕ) : n + 1 ≤ (sqrt n + 1) ^ 2 :=
le_of_pred_lt (lt_succ_sqrt' _)
/-- There are no perfect squares strictly between m² and (m+1)² -/
theorem not_exists_sq {n m : ℕ} (hl : m * m < n) (hr : n < (m + 1) * (m + 1)) :
¬ ∃ t, t * t = n :=
begin
rintro ⟨t, rfl⟩,
have h1 : m < t, from nat.mul_self_lt_mul_self_iff.mpr hl,
have h2 : t < m + 1, from nat.mul_self_lt_mul_self_iff.mpr hr,
exact (not_lt_of_ge $ le_of_lt_succ h2) h1
end
theorem not_exists_sq' {n m : ℕ} (hl : m ^ 2 < n) (hr : n < (m + 1) ^ 2) :
¬ ∃ t, t ^ 2 = n :=
by simpa only [pow_two]
using not_exists_sq (by simpa only [pow_two] using hl) (by simpa only [pow_two] using hr)
end nat
|
5afd2aa69115aea0f1f51ce3c1c86350f245f47f | 5abe9de35738a0e2931cac47648658509f165c1e | /Semana_2/Semana2.lean | 52b813dc4b1e22965c9e36c8802704e913e27d9b | [] | no_license | AlessandroDangelo/Matem-tica-Discreta-1 | 2d827d50d5c48144e4783e85af6e87d1a515b0b5 | b154612d20d88a9fb173a238aa2a9f8e5375d9f7 | refs/heads/main | 1,680,075,356,062 | 1,617,378,986,000 | 1,617,378,986,000 | 354,065,141 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,104 | lean | variables A B P Q R S : Prop.
lemma exL (H1 : P → Q)
(H2 : R → S) : (P ∨ R) → (Q ∨ S) :=
assume H3 : (P ∨ R),
(or.elim H3
(assume H : P, show Q ∨ S, from (or.intro_left S (H1 (show P, from (H)))))
(assume H : R, show Q ∨ S, from (or.intro_right Q (H2 (show R, from (H)))))).
lemma exM (H1 : Q → R) : (P → Q) → (P → R) :=
assume H2 : (P → Q),
assume H3 : P,
show R, from (H1 (show Q, from (H2 (show P, from (H3))))).
lemma exA (H1 : ¬(A ∨ B)) : ¬A ∧ ¬B :=
and.intro (assume H2 : A, (show false, from (H1 (or.intro_left B H2))))
(assume H3 : B, show false, from (H1(or.intro_right A H3))).
lemma exB (H1 : (¬A) ∧ (¬B)) : ¬ (A ∨ B) :=
assume H2 : A ∨ B,
show false,
from ( (and.elim_left H1)
(or.elim H2
(assume H3 : A, H3)
(assume H4 : B, false.elim (and.elim_right H1 H4)))).
|
8a7a92a08db1a4d99a0a5715ff4147e235886134 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/normed_space/dual_number.lean | fbe680a7fcad0237c07123feee3920dd7f11aa72 | [
"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 | 835 | lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import algebra.dual_number
import analysis.normed_space.triv_sq_zero_ext
/-!
# Results on `dual_number R` related to the norm
These are just restatements of similar statements about `triv_sq_zero_ext R M`.
## Main results
* `exp_eps`
-/
namespace dual_number
open triv_sq_zero_ext
variables (𝕜 : Type*) {R : Type*}
variables [is_R_or_C 𝕜] [normed_comm_ring R] [normed_algebra 𝕜 R]
variables [topological_ring R] [complete_space R] [t2_space R]
@[simp] lemma exp_eps : exp 𝕜 (eps : dual_number R) = 1 + eps :=
exp_inr _ _
@[simp] lemma exp_smul_eps (r : R) : exp 𝕜 (r • eps : dual_number R) = 1 + r • eps :=
by rw [eps, ←inr_smul, exp_inr]
end dual_number
|
ad30d9476a4462a5d86d03fd201898fd3141e168 | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/data/multiset/gcd.lean | 8a4d542d65ddaab1e8440423ef0980652d75ed01 | [
"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 | 5,085 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: 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 gcd_eq_of_associated_left associated_normalize,
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
|
4c03776b0232bfd0df4db6711fcb38b4a9b4b23e | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/category_theory/limits/preserves.lean | caf28ebc60aaea5fe8503cf443bb5d54e9522353 | [
"Apache-2.0"
] | permissive | anrddh/mathlib | 6a374da53c7e3a35cb0298b0cd67824efef362b4 | a4266a01d2dcb10de19369307c986d038c7bb6a6 | refs/heads/master | 1,656,710,827,909 | 1,589,560,456,000 | 1,589,560,456,000 | 264,271,800 | 0 | 0 | Apache-2.0 | 1,589,568,062,000 | 1,589,568,061,000 | null | UTF-8 | Lean | false | false | 11,245 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton
-/
import category_theory.limits.limits
/-!
# Preservation and reflection of (co)limits.
There are various distinct notions of "preserving limits". The one we
aim to capture here is: A functor F : C → D "preserves limits" if it
sends every limit cone in C to a limit cone in D. Informally, F
preserves all the limits which exist in C.
Note that:
* Of course, we do not want to require F to *strictly* take chosen
limit cones of C to chosen limit cones of D. Indeed, the above
definition makes no reference to a choice of limit cones so it makes
sense without any conditions on C or D.
* Some diagrams in C may have no limit. In this case, there is no
condition on the behavior of F on such diagrams. There are other
notions (such as "flat functor") which impose conditions also on
diagrams in C with no limits, but these are not considered here.
In order to be able to express the property of preserving limits of a
certain form, we say that a functor F preserves the limit of a
diagram K if F sends every limit cone on K to a limit cone. This is
vacuously satisfied when K does not admit a limit, which is consistent
with the above definition of "preserves limits".
-/
open category_theory
namespace category_theory.limits
universes v u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [category.{v} C]
variables {D : Type u₂} [category.{v} D]
variables {J : Type v} [small_category J] {K : J ⥤ C}
class preserves_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cone K}, is_limit c → is_limit (F.map_cone c))
class preserves_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cocone K}, is_colimit c → is_colimit (F.map_cocone c))
/-- A functor which preserves limits preserves chosen limits up to isomorphism. -/
def preserves_limit_iso (K : J ⥤ C) [has_limit.{v} K] (F : C ⥤ D) [has_limit.{v} (K ⋙ F)] [preserves_limit K F] :
F.obj (limit K) ≅ limit (K ⋙ F) :=
is_limit.cone_point_unique_up_to_iso (preserves_limit.preserves (limit.is_limit K)) (limit.is_limit (K ⋙ F))
/-- A functor which preserves colimits preserves chosen colimits up to isomorphism. -/
def preserves_colimit_iso (K : J ⥤ C) [has_colimit.{v} K] (F : C ⥤ D) [has_colimit.{v} (K ⋙ F)] [preserves_colimit K F] :
F.obj (colimit K) ≅ colimit (K ⋙ F) :=
is_colimit.cocone_point_unique_up_to_iso (preserves_colimit.preserves (colimit.is_colimit K)) (colimit.is_colimit (K ⋙ F))
class preserves_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves_limit : Π {K : J ⥤ C}, preserves_limit K F)
class preserves_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves_colimit : Π {K : J ⥤ C}, preserves_colimit K F)
class preserves_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_limits_of_shape : Π {J : Type v} [𝒥 : small_category J], by exactI preserves_limits_of_shape J F)
class preserves_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_colimits_of_shape : Π {J : Type v} [𝒥 : small_category J], by exactI preserves_colimits_of_shape J F)
attribute [instance, priority 100] -- see Note [lower instance priority]
preserves_limits_of_shape.preserves_limit preserves_limits.preserves_limits_of_shape
preserves_colimits_of_shape.preserves_colimit preserves_colimits.preserves_colimits_of_shape
instance preserves_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_limits_subsingleton (F : C ⥤ D) : subsingleton (preserves_limits F) :=
by { split, intros, cases a, cases b, cc }
instance preserves_colimits_subsingleton (F : C ⥤ D) : subsingleton (preserves_colimits F) :=
by { split, intros, cases a, cases b, cc }
instance id_preserves_limits : preserves_limits (𝟭 C) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
instance id_preserves_colimits : preserves_colimits (𝟭 C) :=
{ preserves_colimits_of_shape := λ J 𝒥,
{ preserves_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
local attribute [elab_simple] preserves_limit.preserves preserves_colimit.preserves
instance comp_preserves_limit [preserves_limit K F] [preserves_limit (K ⋙ F) G] :
preserves_limit K (F ⋙ G) :=
⟨λ c h, preserves_limit.preserves (preserves_limit.preserves h)⟩
instance comp_preserves_colimit [preserves_colimit K F] [preserves_colimit (K ⋙ F) G] :
preserves_colimit K (F ⋙ G) :=
⟨λ c h, preserves_colimit.preserves (preserves_colimit.preserves h)⟩
end
/-- If F preserves one limit cone for the diagram K,
then it preserves any limit cone for K. -/
def preserves_limit_of_preserves_limit_cone {F : C ⥤ D} {t : cone K}
(h : is_limit t) (hF : is_limit (F.map_cone t)) : preserves_limit K F :=
⟨λ t' h', is_limit.of_iso_limit hF (functor.map_iso _ (is_limit.unique_up_to_iso h h'))⟩
/-- If F preserves one colimit cocone for the diagram K,
then it preserves any colimit cocone for K. -/
def preserves_colimit_of_preserves_colimit_cocone {F : C ⥤ D} {t : cocone K}
(h : is_colimit t) (hF : is_colimit (F.map_cocone t)) : preserves_colimit K F :=
⟨λ t' h', is_colimit.of_iso_colimit hF (functor.map_iso _ (is_colimit.unique_up_to_iso h h'))⟩
/-
A functor F : C → D reflects limits if whenever the image of a cone
under F is a limit cone in D, the cone was already a limit cone in C.
Note that again we do not assume a priori that D actually has any
limits.
-/
class reflects_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cone K}, is_limit (F.map_cone c) → is_limit c)
class reflects_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cocone K}, is_colimit (F.map_cocone c) → is_colimit c)
class reflects_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_limit : Π {K : J ⥤ C}, reflects_limit K F)
class reflects_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_colimit : Π {K : J ⥤ C}, reflects_colimit K F)
class reflects_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_limits_of_shape : Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_limits_of_shape J F)
class reflects_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_colimits_of_shape : Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_colimits_of_shape J F)
instance reflects_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_limits_subsingleton (F : C ⥤ D) : subsingleton (reflects_limits F) :=
by { split, intros, cases a, cases b, cc }
instance reflects_colimits_subsingleton (F : C ⥤ D) : subsingleton (reflects_colimits F) :=
by { split, intros, cases a, cases b, cc }
@[priority 100] -- see Note [lower instance priority]
instance reflects_limit_of_reflects_limits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_limits_of_shape J F] : reflects_limit K F :=
reflects_limits_of_shape.reflects_limit
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimit_of_reflects_colimits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_colimits_of_shape J F] : reflects_colimit K F :=
reflects_colimits_of_shape.reflects_colimit
@[priority 100] -- see Note [lower instance priority]
instance reflects_limits_of_shape_of_reflects_limits (F : C ⥤ D)
[H : reflects_limits F] : reflects_limits_of_shape J F :=
reflects_limits.reflects_limits_of_shape
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimits_of_shape_of_reflects_colimits (F : C ⥤ D)
[H : reflects_colimits F] : reflects_colimits_of_shape J F :=
reflects_colimits.reflects_colimits_of_shape
instance id_reflects_limits : reflects_limits (𝟭 C) :=
{ reflects_limits_of_shape := λ J 𝒥,
{ reflects_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
instance id_reflects_colimits : reflects_colimits (𝟭 C) :=
{ reflects_colimits_of_shape := λ J 𝒥,
{ reflects_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
instance comp_reflects_limit [reflects_limit K F] [reflects_limit (K ⋙ F) G] :
reflects_limit K (F ⋙ G) :=
⟨λ c h, reflects_limit.reflects (reflects_limit.reflects h)⟩
instance comp_reflects_colimit [reflects_colimit K F] [reflects_colimit (K ⋙ F) G] :
reflects_colimit K (F ⋙ G) :=
⟨λ c h, reflects_colimit.reflects (reflects_colimit.reflects h)⟩
end
end category_theory.limits
|
24c2fb3d4b9c33bba2db109aa99183c7260b6f6c | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/category/Group/adjunctions.lean | cbcc757de517887ee0422014e7a8a73abe25c332 | [
"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 | 3,902 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl
-/
import algebra.category.Group.basic
import group_theory.free_abelian_group
/-!
# Adjunctions regarding the category of (abelian) groups
This file contains construction of basic adjunctions concerning the category of groups and the
category of abelian groups.
## Main definitions
* `AddCommGroup.free`: constructs the functor associating to a type `X` the free abelian group with
generators `x : X`.
* `Group.free`: constructs the functor associating to a type `X` the free group with
generators `x : X`.
* `abelianize`: constructs the functor which associates to a group `G` its abelianization `Gᵃᵇ`.
## Main statements
* `AddCommGroup.adj`: proves that `AddCommGroup.free` is the left adjoint of the forgetful functor
from abelian groups to types.
* `Group.adj`: proves that `Group.free` is the left adjoint of the forgetful functor from groups to
types.
* `abelianize_adj`: proves that `abelianize` is left adjoint to the forgetful functor from
abelian groups to groups.
-/
noncomputable theory
universe u
open category_theory
namespace AddCommGroup
open_locale classical
/--
The free functor `Type u ⥤ AddCommGroup` sending a type `X` to the
free abelian group with generators `x : X`.
-/
def free : Type u ⥤ AddCommGroup :=
{ obj := λ α, of (free_abelian_group α),
map := λ X Y, free_abelian_group.map,
map_id' := λ X, add_monoid_hom.ext free_abelian_group.map_id_apply,
map_comp' := λ X Y Z f g, add_monoid_hom.ext free_abelian_group.map_comp_apply, }
@[simp] lemma free_obj_coe {α : Type u} :
(free.obj α : Type u) = (free_abelian_group α) := rfl
@[simp] lemma free_map_coe {α β : Type u} {f : α → β} (x : free_abelian_group α) :
(free.map f) x = f <$> x := rfl
/--
The free-forgetful adjunction for abelian groups.
-/
def adj : free ⊣ forget AddCommGroup.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X G, free_abelian_group.lift.symm,
hom_equiv_naturality_left_symm' :=
by { intros, ext, refl} }
/--
As an example, we now give a high-powered proof that
the monomorphisms in `AddCommGroup` are just the injective functions.
(This proof works in all universes.)
-/
example {G H : AddCommGroup.{u}} (f : G ⟶ H) [mono f] : function.injective f :=
(mono_iff_injective f).1 (right_adjoint_preserves_mono adj (by apply_instance : mono f))
end AddCommGroup
namespace Group
/-- The free functor `Type u ⥤ Group` sending a type `X` to the free group with generators `x : X`.
-/
def free : Type u ⥤ Group :=
{ obj := λ α, of (free_group α),
map := λ X Y, free_group.map,
map_id' := by { intros, ext1, refl },
map_comp' := by { intros, ext1, refl } }
/-- The free-forgetful adjunction for groups.
-/
def adj : free ⊣ forget Group.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X G, free_group.lift.symm,
hom_equiv_naturality_left_symm' := λ X Y G f g, begin ext1, refl end }
end Group
section abelianization
/-- The abelianization functor `Group ⥤ CommGroup` sending a group `G` to its abelianization `Gᵃᵇ`.
-/
def abelianize : Group.{u} ⥤ CommGroup.{u} :=
{ obj := λ G, { α := abelianization G, str := by apply_instance },
map := λ G H f, abelianization.lift ( { to_fun := λ x, abelianization.of (f x),
map_one' := by simp,
map_mul' := by simp } ),
map_id' := by { intros, simp only [monoid_hom.mk_coe, coe_id], ext1, refl },
map_comp' := by { intros, simp only [coe_comp], ext1, refl } }
/-- The abelianization-forgetful adjuction from `Group` to `CommGroup`.-/
def abelianize_adj : abelianize ⊣ forget₂ CommGroup.{u} Group.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ G A, abelianization.lift.symm,
hom_equiv_naturality_left_symm' := λ G H A f g, by { ext1, refl } }
end abelianization
|
4f823769776ee8c20beca2799986f52b76d4ca00 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/tactic/rewrite_search/explain.lean | 37490a29fe49bec63025a0768f379ced00f36620 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,771 | lean | /-
Copyright (c) 2020 Kevin Lacker, Keeley Hoek, Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Lacker, Keeley Hoek, Scott Morrison
-/
import tactic.rewrite_search.types
import tactic.converter.interactive -- Required for us to emit more compact `conv` invocations
/-!
# Tools to extract valid Lean code from a path found by rewrite search.
-/
open interactive interactive.types expr tactic
namespace tactic.rewrite_search
universes u
/--
A `dir_pair` is a pair of items designed to be accessed according to
`dir`, a "direction" defined in the `expr_lens` library.
-/
@[derive inhabited]
structure dir_pair (α : Type u) :=
(l r : α)
namespace dir_pair
open expr_lens
variables {α β : Type} (p : dir_pair α)
/-- Get one side of the pair, picking the side according to the direction. -/
def get : dir → α
| dir.F := p.l
| dir.A := p.r
/-- Set one side of the pair, picking the side according to the direction. -/
def set : dir → α → dir_pair α
| dir.F v := ⟨v, p.r⟩
| dir.A v := ⟨p.l, v⟩
/-- Convert the pair to a list of its elements. -/
def to_list : list α := [p.l, p.r]
/-- Convert the pair to a readable string format. -/
def to_string [has_to_string α] (p : dir_pair α) : string :=
to_string p.l ++ "-" ++ to_string p.r
instance has_to_string [has_to_string α] : has_to_string (dir_pair α) := ⟨to_string⟩
end dir_pair
/-- Helper for getting the nth item in a list of rules -/
private meta def nth_rule (rs : list (expr × bool)) (i : ℕ) : expr × bool := (rs.nth i).iget
/-- Convert a rule into the string of Lean code used to refer to this rule. -/
private meta def pp_rule (r : expr × bool) : tactic string :=
do pp ← pp r.1, return $ (if r.2 then "←" else "") ++ to_string pp
private meta def how.to_rewrite (rs : list (expr × bool)) : how → option (expr × bool)
| h := nth_rule rs h.rule_index
/-- Explain a single rewrite using `nth_rewrite`. -/
private meta def explain_using_location (rs : list (expr × bool)) (s : side) :
how → tactic (option string)
| h := do
rule ← pp_rule $ nth_rule rs h.rule_index,
return $ some ("nth_rewrite_" ++ s.to_xhs ++ " " ++ to_string h.location ++ " " ++ rule)
/-- Explain a list of rewrites using `nth_rewrite`. -/
private meta def using_location.explain_rewrites (rs : list (expr × bool)) (s : side)
(steps : list how) : tactic string :=
do rules ← steps.mmap $ λ h : how, option.to_list <$> explain_using_location rs s h,
return $ string.intercalate ",\n " rules.join
namespace using_conv
/-- `app_addr` represents a tree structure that `conv` tactics use for a rewrite. -/
inductive app_addr
| node (children : dir_pair (option app_addr)) : app_addr
| rw : list ℕ → app_addr
open app_addr
private meta def app_addr.to_string : app_addr → string
| (node c) := "(node " ++ ((c.to_list.filter_map id).map app_addr.to_string).to_string ++ ")"
| (rw rws) := "(rw " ++ rws.to_string ++ ")"
/--
A data structure for the result of a splice operation.
obstructed: There was more of the addr to be added left, but we hit a rw
contained: The added addr was already contained, and did not terminate at an existing rw
new: The added addr terminated at an existing rw or we could create a new one for it
-/
@[derive inhabited]
inductive splice_result
| obstructed
| contained
| new (addr : app_addr)
open splice_result
private meta def pack_splice_result (s : expr_lens.dir) :
splice_result → dir_pair (option app_addr) → splice_result
| (new addr) c := new $ app_addr.node $ c.set s (some addr)
| sr _ := sr
private meta def splice_in_aux (new_rws : list ℕ) :
option app_addr → list expr_lens.dir → splice_result
| (some $ node _) [] := contained
| (some $ node c) (s :: rest) := pack_splice_result s (splice_in_aux (c.get s) rest) c
| (some $ rw _) (_ :: _) := obstructed
| (some $ rw rws) [] := new $ rw (rws ++ new_rws)
| none [] := new $ rw new_rws
| none l := splice_in_aux (some $ node ⟨none, none⟩) l
open expr_lens
private meta def to_congr_form : list expr_lens.dir → tactic (list expr_lens.dir)
| [] := return []
| (dir.F :: (dir.A :: rest)) := do
r ← to_congr_form rest,
return (dir.F :: r)
| (dir.A :: rest) := do
r ← to_congr_form rest,
return (dir.A :: r)
| [dir.F] := fail "app list ends in side.L!"
| (dir.F :: (dir.F :: _)) := fail "app list has repeated side.L!"
/-- Attempt to add new rewrites into the `app_addr` tree. -/
private meta def splice_in (a : option app_addr) (rws : list ℕ) (s : list expr_lens.dir) :
tactic splice_result :=
splice_in_aux rws a <$> to_congr_form s
/-- Construct a single `erw` tactic for the given rules. -/
private meta def build_rw_tactic (rs : list (expr × bool)) (hs : list ℕ) : tactic string :=
do rws ← (hs.map $ nth_rule rs).mmap pp_rule,
return $ "erw [" ++ (string.intercalate ", " rws) ++ "]"
private meta def explain_tree_aux (rs : list (expr × bool)) :
app_addr → tactic (option (list string))
| (app_addr.rw rws) := (λ a, some [a]) <$> build_rw_tactic rs rws
| (app_addr.node ⟨func, arg⟩) := do
sf ← match func with | none := pure none | some func := explain_tree_aux func end,
sa ← match arg with | none := pure none | some arg := explain_tree_aux arg end,
return $ match (sf, sa) with
| (none, none) := none
| (some sf, none) := ["congr"].append sf
| (none, some sa) := ["congr", "skip"].append sa
| (some sf, some sa) := (["congr"].append sf).append (["skip"].append sf)
end
/-- Construct a string of Lean code that does a rewrite for the provided tree. -/
private meta def explain_tree (rs : list (expr × bool)) (tree : app_addr) :
tactic (list string) :=
list.join <$> option.to_list <$> explain_tree_aux rs tree
/--
Gather all rewrites into trees, then generate a line of code for each tree.
The return value has one `conv_x` tactic on each line.
-/
private meta def explanation_lines (rs : list (expr × bool)) (s : side) :
option app_addr → list how → tactic (list string)
| none [] := return []
| (some tree) [] := do
tacs ← explain_tree rs tree,
return $ if tacs.length = 0 then []
else ["conv_" ++ s.to_xhs ++ " { " ++ string.intercalate ", " tacs ++ " }"]
| tree (h :: rest) := do
(new_tree, rest_if_fail) ← match h.addr with
| (some addr) := do
new_tree ← splice_in tree [h.rule_index] addr,
return (some new_tree, list.cons h rest)
| none := do
return (none, rest)
end,
match new_tree with
| some (new new_tree) := explanation_lines new_tree rest
| _ := do
line ← explanation_lines tree [],
lines ← explanation_lines none rest_if_fail,
return $ line ++ lines
end
/-- Explain a list of rewrites using `conv_x` tactics. -/
meta def explain_rewrites (rs : list (expr × bool)) (s : side) (hows : list how) :
tactic string :=
string.intercalate ",\n " <$> explanation_lines rs s none hows
end using_conv
private meta def explain_rewrites_concisely (steps : list (expr × bool)) (needs_refl : bool) :
tactic string :=
do rules ← string.intercalate ", " <$> steps.mmap pp_rule,
return $ "erw [" ++ rules ++ "]" ++ (if needs_refl then ", refl" else "")
/--
Fails if we can't just use rewrite.
Otherwise, returns 'tt' if we need a `refl` at the end.
-/
private meta def check_if_simple_rewrite_succeeds (rewrites : list (expr × bool)) (goal : expr) :
tactic bool :=
lock_tactic_state $ do
m ← mk_meta_var goal,
set_goals [m],
rewrites.mmap' $ λ q, rewrite_target q.1 {symm := q.2, md := semireducible},
(reflexivity reducible >> return ff) <|> (reflexivity >> return tt)
/-- Construct a list of rewrites from a proof unit. -/
meta def proof_unit.rewrites (u : proof_unit) (rs : list (expr × bool)) : list (expr × bool) :=
u.steps.filter_map $ how.to_rewrite rs
/-- Construct an explanation string from a proof unit. -/
meta def proof_unit.explain (u : proof_unit) (rs : list (expr × bool))
(explain_using_conv : bool) : tactic string :=
if explain_using_conv then
using_conv.explain_rewrites rs u.side u.steps
else
using_location.explain_rewrites rs u.side u.steps
private meta def explain_proof_full (rs : list (expr × bool)) (explain_using_conv : bool) :
list proof_unit → tactic string
| [] := return ""
| (u :: rest) := do
-- Don't use transitivity for the last unit, since it must be redundant.
head ← if rest.length = 0 ∨ u.side = side.L then pure [] else (do
n ← infer_type u.proof >>= (λ e, prod.snd <$> (match_eq e <|> match_iff e)) >>= pp,
pure $ ["transitivity " ++ to_string n]),
unit_expl ← u.explain rs explain_using_conv,
rest_expl ← explain_proof_full rest,
let expls := (head ++ [unit_expl, rest_expl]).filter $ λ t, ¬(t.length = 0),
return $ string.intercalate ",\n " expls
private meta def explain_proof_concisely (rules : list (expr × bool)) (proof : expr)
(l : list proof_unit) : tactic string :=
do let rws : list (expr × bool) := list.join $ l.map (λ u, do
(r, s) ← u.rewrites rules,
return (r, if u.side = side.L then s else ¬s)),
goal ← infer_type proof,
needs_refl ← check_if_simple_rewrite_succeeds rws goal,
explain_rewrites_concisely rws needs_refl
/--
Trace a human-readable explanation in Lean code of a proof generated by rewrite search.
Emit it as `"Try this: <code>"` with each successive line of code indented.
-/
meta def explain_search_result (cfg : config) (rules : list (expr × bool)) (proof : expr)
(units : list proof_unit) : tactic unit :=
if units.empty then trace "Try this: exact rfl" else do
explanation ← explain_proof_concisely rules proof units <|>
explain_proof_full rules cfg.explain_using_conv units,
trace $ "Try this: " ++ explanation
end tactic.rewrite_search
|
5dda81608d138ed836e4e389b83f3c350fd262d2 | 958488bc7f3c2044206e0358e56d7690b6ae696c | /lean/tutorials/tutorial4.lean | 817a2d47c9391daa22a47d53ca401fe9328f4f69 | [] | no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 1,692,263,717,723 | 1,691,757,179,000 | 1,691,757,179,000 | 40,361,602 | 3 | 0 | null | 1,679,896,438,000 | 1,438,953,859,000 | Coq | UTF-8 | Lean | false | false | 1,286 | lean | import data.real.basic
import data.int.parity
open nat
example : ∃ (n : ℕ), 8 = 2*n :=
begin
use 4, refl
end
example : ∀ (n : ℕ), (exists (k : ℕ), n = k + 1) → n > 0 :=
begin
intros n H₁, cases H₁ with k H₁, rw H₁, apply succ_pos
end
example : ∀ (a b c : ℤ), a ∣ b → b ∣ c → a ∣ c :=
begin
intros a b c H₁ H₂,
cases H₁ with n H₁, cases H₂ with m H₂, use (n*m), calc
c = b*m : by assumption
... = (a*n)*m : by rw H₁
... = a*(n*m) : by ring
end
example : ∀ (a b c : ℤ), a ∣ b → a ∣ c → a ∣ b + c :=
begin
intros a b c H₁ H₂,
rcases H₁ with ⟨n, H₁⟩, rcases H₂ with ⟨m,H₂⟩, use (n + m),
rw [H₁,H₂], ring
end
example : ∀ (a : ℤ), 0 ∣ a ↔ a = 0 :=
begin
intros a, split; intros H₁,
{ cases H₁ with k H₁, rw H₁, ring },
{ use 0, rw H₁, ring }
end
open function
example : ∀ (f g : ℝ → ℝ), surjective (g ∘ f) → surjective g :=
begin
intros f g H₁ y, cases (H₁ y) with x H₁, use (f x), assumption
end
example : ∀ (f g : ℝ → ℝ), surjective f → surjective g → surjective (g ∘ f) :=
begin
intros f g H₁ H₂ y,
cases (H₂ y) with y' H₂,
cases (H₁ y') with x H₁,
use x, simp, rw H₁, assumption
end
|
e869b9fdd2fb5212d5f198b4ae7565308f263c54 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/module/submodule/basic.lean | 7c376204bdf8f4f671eafb15f8b5ea9b51e2773a | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 16,233 | lean | /-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import algebra.module.linear_map
import algebra.module.equiv
import group_theory.group_action.sub_mul_action
/-!
# Submodules of a module
In this file we define
* `submodule R M` : a subset of a `module` `M` that contains zero and is closed with respect to
addition and scalar multiplication.
* `subspace k M` : an abbreviation for `submodule` assuming that `k` is a `field`.
## Tags
submodule, subspace, linear map
-/
open function
open_locale big_operators
universes u'' u' u v w
variables {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w}
set_option old_structure_cmd true
/-- A submodule of a module is one which is closed under vector operations.
This is a sufficient condition for the subset of vectors in the submodule
to themselves form a module. -/
structure submodule (R : Type u) (M : Type v) [semiring R]
[add_comm_monoid M] [module R M] extends add_submonoid M, sub_mul_action R M : Type v.
/-- Reinterpret a `submodule` as an `add_submonoid`. -/
add_decl_doc submodule.to_add_submonoid
/-- Reinterpret a `submodule` as an `sub_mul_action`. -/
add_decl_doc submodule.to_sub_mul_action
namespace submodule
variables [semiring R] [add_comm_monoid M] [module R M]
instance : set_like (submodule R M) M :=
{ coe := submodule.carrier,
coe_injective' := λ p q h, by cases p; cases q; congr' }
instance : add_submonoid_class (submodule R M) M :=
{ zero_mem := zero_mem',
add_mem := add_mem' }
@[simp] theorem mem_to_add_submonoid (p : submodule R M) (x : M) : x ∈ p.to_add_submonoid ↔ x ∈ p :=
iff.rfl
variables {p q : submodule R M}
@[simp]
lemma mem_mk {S : set M} {x : M} (h₁ h₂ h₃) : x ∈ (⟨S, h₁, h₂, h₃⟩ : submodule R M) ↔ x ∈ S :=
iff.rfl
@[simp] lemma coe_set_mk (S : set M) (h₁ h₂ h₃) :
((⟨S, h₁, h₂, h₃⟩ : submodule R M) : set M) = S := rfl
@[simp]
lemma mk_le_mk {S S' : set M} (h₁ h₂ h₃ h₁' h₂' h₃') :
(⟨S, h₁, h₂, h₃⟩ : submodule R M) ≤ (⟨S', h₁', h₂', h₃'⟩ : submodule R M) ↔ S ⊆ S' := iff.rfl
@[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := set_like.ext h
/-- Copy of a submodule with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (p : submodule R M) (s : set M) (hs : s = ↑p) : submodule R M :=
{ carrier := s,
zero_mem' := hs.symm ▸ p.zero_mem',
add_mem' := λ _ _, hs.symm ▸ p.add_mem',
smul_mem' := hs.symm ▸ p.smul_mem' }
@[simp] lemma coe_copy (S : submodule R M) (s : set M) (hs : s = ↑S) :
(S.copy s hs : set M) = s := rfl
lemma copy_eq (S : submodule R M) (s : set M) (hs : s = ↑S) : S.copy s hs = S :=
set_like.coe_injective hs
theorem to_add_submonoid_injective :
injective (to_add_submonoid : submodule R M → add_submonoid M) :=
λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h)
@[simp] theorem to_add_submonoid_eq : p.to_add_submonoid = q.to_add_submonoid ↔ p = q :=
to_add_submonoid_injective.eq_iff
@[mono] lemma to_add_submonoid_strict_mono :
strict_mono (to_add_submonoid : submodule R M → add_submonoid M) := λ _ _, id
lemma to_add_submonoid_le : p.to_add_submonoid ≤ q.to_add_submonoid ↔ p ≤ q := iff.rfl
@[mono]
lemma to_add_submonoid_mono : monotone (to_add_submonoid : submodule R M → add_submonoid M) :=
to_add_submonoid_strict_mono.monotone
@[simp] theorem coe_to_add_submonoid (p : submodule R M) :
(p.to_add_submonoid : set M) = p := rfl
theorem to_sub_mul_action_injective :
injective (to_sub_mul_action : submodule R M → sub_mul_action R M) :=
λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h)
@[simp] theorem to_sub_mul_action_eq : p.to_sub_mul_action = q.to_sub_mul_action ↔ p = q :=
to_sub_mul_action_injective.eq_iff
@[mono] lemma to_sub_mul_action_strict_mono :
strict_mono (to_sub_mul_action : submodule R M → sub_mul_action R M) := λ _ _, id
@[mono]
lemma to_sub_mul_action_mono : monotone (to_sub_mul_action : submodule R M → sub_mul_action R M) :=
to_sub_mul_action_strict_mono.monotone
@[simp] theorem coe_to_sub_mul_action (p : submodule R M) :
(p.to_sub_mul_action : set M) = p := rfl
end submodule
namespace submodule
section add_comm_monoid
variables [semiring R] [add_comm_monoid M]
-- We can infer the module structure implicitly from the bundled submodule,
-- rather than via typeclass resolution.
variables {module_M : module R M}
variables {p q : submodule R M}
variables {r : R} {x y : M}
variables (p)
@[simp] lemma mem_carrier : x ∈ p.carrier ↔ x ∈ (p : set M) := iff.rfl
@[simp] protected lemma zero_mem : (0 : M) ∈ p := zero_mem _
protected lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := add_mem h₁ h₂
lemma smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h
lemma smul_of_tower_mem [has_smul S R] [has_smul S M] [is_scalar_tower S R M]
(r : S) (h : x ∈ p) : r • x ∈ p :=
p.to_sub_mul_action.smul_of_tower_mem r h
protected lemma sum_mem {t : finset ι} {f : ι → M} : (∀c∈t, f c ∈ p) → (∑ i in t, f i) ∈ p :=
sum_mem
lemma sum_smul_mem {t : finset ι} {f : ι → M} (r : ι → R)
(hyp : ∀ c ∈ t, f c ∈ p) : (∑ i in t, r i • f i) ∈ p :=
sum_mem (λ i hi, smul_mem _ _ (hyp i hi))
@[simp] lemma smul_mem_iff' [group G] [mul_action G M] [has_smul G R] [is_scalar_tower G R M]
(g : G) : g • x ∈ p ↔ x ∈ p :=
p.to_sub_mul_action.smul_mem_iff' g
instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem x.2 y.2⟩⟩
instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩
instance : inhabited p := ⟨0⟩
instance [has_smul S R] [has_smul S M] [is_scalar_tower S R M] :
has_smul S p := ⟨λ c x, ⟨c • x.1, smul_of_tower_mem _ c x.2⟩⟩
instance [has_smul S R] [has_smul S M] [is_scalar_tower S R M] : is_scalar_tower S R p :=
p.to_sub_mul_action.is_scalar_tower
instance
[has_smul S R] [has_smul S M] [is_scalar_tower S R M]
[has_smul Sᵐᵒᵖ R] [has_smul Sᵐᵒᵖ M] [is_scalar_tower Sᵐᵒᵖ R M]
[is_central_scalar S M] : is_central_scalar S p :=
p.to_sub_mul_action.is_central_scalar
protected lemma nonempty : (p : set M).nonempty := ⟨0, p.zero_mem⟩
@[simp] lemma mk_eq_zero {x} (h : x ∈ p) : (⟨x, h⟩ : p) = 0 ↔ x = 0 := subtype.ext_iff_val
variables {p}
@[simp, norm_cast] lemma coe_eq_zero {x : p} : (x : M) = 0 ↔ x = 0 :=
(set_like.coe_eq_coe : (x : M) = (0 : p) ↔ x = 0)
@[simp, norm_cast] lemma coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : p) : M) = 0 := rfl
@[norm_cast] lemma coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • ↑x := rfl
@[simp, norm_cast] lemma coe_smul_of_tower [has_smul S R] [has_smul S M] [is_scalar_tower S R M]
(r : S) (x : p) : ((r • x : p) : M) = r • ↑x := rfl
@[simp, norm_cast] lemma coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl
@[simp] lemma coe_mem (x : p) : (x : M) ∈ p := x.2
variables (p)
instance : add_comm_monoid p :=
{ add := (+), zero := 0, .. p.to_add_submonoid.to_add_comm_monoid }
instance module' [semiring S] [has_smul S R] [module S M] [is_scalar_tower S R M] : module S p :=
by refine {smul := (•), ..p.to_sub_mul_action.mul_action', ..};
{ intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] }
instance : module R p := p.module'
instance no_zero_smul_divisors [no_zero_smul_divisors R M] : no_zero_smul_divisors R p :=
⟨λ c x h,
have c = 0 ∨ (x : M) = 0,
from eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg coe h),
this.imp_right (@subtype.ext_iff _ _ x 0).mpr⟩
/-- Embedding of a submodule `p` to the ambient space `M`. -/
protected def subtype : p →ₗ[R] M :=
by refine {to_fun := coe, ..}; simp [coe_smul]
theorem subtype_apply (x : p) : p.subtype x = x := rfl
@[simp] lemma coe_subtype : ((submodule.subtype p) : p → M) = coe := rfl
lemma injective_subtype : injective p.subtype := subtype.coe_injective
/-- Note the `add_submonoid` version of this lemma is called `add_submonoid.coe_finset_sum`. -/
@[simp] lemma coe_sum (x : ι → p) (s : finset ι) : ↑(∑ i in s, x i) = ∑ i in s, (x i : M) :=
p.subtype.map_sum
section restrict_scalars
variables (S) [semiring S] [module S M] [module R M] [has_smul S R] [is_scalar_tower S R M]
/--
`V.restrict_scalars S` is the `S`-submodule of the `S`-module given by restriction of scalars,
corresponding to `V`, an `R`-submodule of the original `R`-module.
-/
def restrict_scalars (V : submodule R M) : submodule S M :=
{ carrier := V,
zero_mem' := V.zero_mem,
smul_mem' := λ c m h, V.smul_of_tower_mem c h,
add_mem' := λ x y hx hy, V.add_mem hx hy }
@[simp]
lemma coe_restrict_scalars (V : submodule R M) : (V.restrict_scalars S : set M) = V :=
rfl
@[simp]
lemma restrict_scalars_mem (V : submodule R M) (m : M) : m ∈ V.restrict_scalars S ↔ m ∈ V :=
iff.refl _
@[simp]
lemma restrict_scalars_self (V : submodule R M) : V.restrict_scalars R = V :=
set_like.coe_injective rfl
variables (R S M)
lemma restrict_scalars_injective :
function.injective (restrict_scalars S : submodule R M → submodule S M) :=
λ V₁ V₂ h, ext $ set.ext_iff.1 (set_like.ext'_iff.1 h : _)
@[simp] lemma restrict_scalars_inj {V₁ V₂ : submodule R M} :
restrict_scalars S V₁ = restrict_scalars S V₂ ↔ V₁ = V₂ :=
(restrict_scalars_injective S _ _).eq_iff
/-- Even though `p.restrict_scalars S` has type `submodule S M`, it is still an `R`-module. -/
instance restrict_scalars.orig_module (p : submodule R M) :
module R (p.restrict_scalars S) :=
(by apply_instance : module R p)
instance (p : submodule R M) : is_scalar_tower S R (p.restrict_scalars S) :=
{ smul_assoc := λ r s x, subtype.ext $ smul_assoc r s (x : M) }
/-- `restrict_scalars S` is an embedding of the lattice of `R`-submodules into
the lattice of `S`-submodules. -/
@[simps]
def restrict_scalars_embedding : submodule R M ↪o submodule S M :=
{ to_fun := restrict_scalars S,
inj' := restrict_scalars_injective S R M,
map_rel_iff' := λ p q, by simp [set_like.le_def] }
/-- Turning `p : submodule R M` into an `S`-submodule gives the same module structure
as turning it into a type and adding a module structure. -/
@[simps {simp_rhs := tt}]
def restrict_scalars_equiv (p : submodule R M) : p.restrict_scalars S ≃ₗ[R] p :=
{ to_fun := id, inv_fun := id, map_smul' := λ c x, rfl, .. add_equiv.refl p }
end restrict_scalars
end add_comm_monoid
section add_comm_group
variables [ring R] [add_comm_group M]
variables {module_M : module R M}
variables (p p' : submodule R M)
variables {r : R} {x y : M}
instance [module R M] : add_subgroup_class (submodule R M) M :=
{ neg_mem := λ p x, p.to_sub_mul_action.neg_mem,
.. submodule.add_submonoid_class }
protected lemma neg_mem (hx : x ∈ p) : -x ∈ p := neg_mem hx
/-- Reinterpret a submodule as an additive subgroup. -/
def to_add_subgroup : add_subgroup M :=
{ neg_mem' := λ _, p.neg_mem , .. p.to_add_submonoid }
@[simp] lemma coe_to_add_subgroup : (p.to_add_subgroup : set M) = p := rfl
@[simp] lemma mem_to_add_subgroup : x ∈ p.to_add_subgroup ↔ x ∈ p := iff.rfl
include module_M
theorem to_add_subgroup_injective : injective (to_add_subgroup : submodule R M → add_subgroup M)
| p q h := set_like.ext (set_like.ext_iff.1 h : _)
@[simp] theorem to_add_subgroup_eq : p.to_add_subgroup = p'.to_add_subgroup ↔ p = p' :=
to_add_subgroup_injective.eq_iff
@[mono] lemma to_add_subgroup_strict_mono :
strict_mono (to_add_subgroup : submodule R M → add_subgroup M) := λ _ _, id
lemma to_add_subgroup_le : p.to_add_subgroup ≤ p'.to_add_subgroup ↔ p ≤ p' := iff.rfl
@[mono] lemma to_add_subgroup_mono : monotone (to_add_subgroup : submodule R M → add_subgroup M) :=
to_add_subgroup_strict_mono.monotone
omit module_M
protected lemma sub_mem : x ∈ p → y ∈ p → x - y ∈ p := sub_mem
protected lemma neg_mem_iff : -x ∈ p ↔ x ∈ p := neg_mem_iff
protected lemma add_mem_iff_left : y ∈ p → (x + y ∈ p ↔ x ∈ p) := add_mem_cancel_right
protected lemma add_mem_iff_right : x ∈ p → (x + y ∈ p ↔ y ∈ p) := add_mem_cancel_left
protected lemma coe_neg (x : p) : ((-x : p) : M) = -x := add_subgroup_class.coe_neg _
protected lemma coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := add_subgroup_class.coe_sub _ _
lemma sub_mem_iff_left (hy : y ∈ p) : (x - y) ∈ p ↔ x ∈ p :=
by rw [sub_eq_add_neg, p.add_mem_iff_left (p.neg_mem hy)]
lemma sub_mem_iff_right (hx : x ∈ p) : (x - y) ∈ p ↔ y ∈ p :=
by rw [sub_eq_add_neg, p.add_mem_iff_right hx, p.neg_mem_iff]
instance : add_comm_group p :=
{ add := (+), zero := 0, neg := has_neg.neg, ..p.to_add_subgroup.to_add_comm_group }
end add_comm_group
section is_domain
variables [ring R] [is_domain R]
variables [add_comm_group M] [module R M] {b : ι → M}
lemma not_mem_of_ortho {x : M} {N : submodule R M}
(ortho : ∀ (c : R) (y ∈ N), c • x + y = (0 : M) → c = 0) :
x ∉ N :=
by { intro hx, simpa using ortho (-1) x hx }
lemma ne_zero_of_ortho {x : M} {N : submodule R M}
(ortho : ∀ (c : R) (y ∈ N), c • x + y = (0 : M) → c = 0) :
x ≠ 0 :=
mt (λ h, show x ∈ N, from h.symm ▸ N.zero_mem) (not_mem_of_ortho ortho)
end is_domain
section ordered_monoid
variables [semiring R]
/-- A submodule of an `ordered_add_comm_monoid` is an `ordered_add_comm_monoid`. -/
instance to_ordered_add_comm_monoid
{M} [ordered_add_comm_monoid M] [module R M] (S : submodule R M) :
ordered_add_comm_monoid S :=
subtype.coe_injective.ordered_add_comm_monoid coe rfl (λ _ _, rfl) (λ _ _, rfl)
/-- A submodule of a `linear_ordered_add_comm_monoid` is a `linear_ordered_add_comm_monoid`. -/
instance to_linear_ordered_add_comm_monoid
{M} [linear_ordered_add_comm_monoid M] [module R M] (S : submodule R M) :
linear_ordered_add_comm_monoid S :=
subtype.coe_injective.linear_ordered_add_comm_monoid coe rfl (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl)
(λ _ _, rfl)
/-- A submodule of an `ordered_cancel_add_comm_monoid` is an `ordered_cancel_add_comm_monoid`. -/
instance to_ordered_cancel_add_comm_monoid
{M} [ordered_cancel_add_comm_monoid M] [module R M] (S : submodule R M) :
ordered_cancel_add_comm_monoid S :=
subtype.coe_injective.ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl) (λ _ _, rfl)
/-- A submodule of a `linear_ordered_cancel_add_comm_monoid` is a
`linear_ordered_cancel_add_comm_monoid`. -/
instance to_linear_ordered_cancel_add_comm_monoid
{M} [linear_ordered_cancel_add_comm_monoid M] [module R M] (S : submodule R M) :
linear_ordered_cancel_add_comm_monoid S :=
subtype.coe_injective.linear_ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl) (λ _ _, rfl)
(λ _ _, rfl) (λ _ _, rfl)
end ordered_monoid
section ordered_group
variables [ring R]
/-- A submodule of an `ordered_add_comm_group` is an `ordered_add_comm_group`. -/
instance to_ordered_add_comm_group
{M} [ordered_add_comm_group M] [module R M] (S : submodule R M) :
ordered_add_comm_group S :=
subtype.coe_injective.ordered_add_comm_group coe
rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl)
/-- A submodule of a `linear_ordered_add_comm_group` is a
`linear_ordered_add_comm_group`. -/
instance to_linear_ordered_add_comm_group
{M} [linear_ordered_add_comm_group M] [module R M] (S : submodule R M) :
linear_ordered_add_comm_group S :=
subtype.coe_injective.linear_ordered_add_comm_group coe
rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl)
end ordered_group
end submodule
namespace submodule
variables [division_ring S] [semiring R] [add_comm_monoid M] [module R M]
variables [has_smul S R] [module S M] [is_scalar_tower S R M]
variables (p : submodule R M) {s : S} {x y : M}
theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p :=
p.to_sub_mul_action.smul_mem_iff s0
end submodule
/-- Subspace of a vector space. Defined to equal `submodule`. -/
abbreviation subspace (R : Type u) (M : Type v)
[field R] [add_comm_group M] [module R M] :=
submodule R M
|
4d802a83349c214f31571d695ba28f9cada02d35 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Elab/Deriving/Repr.lean | c14736f007dfd2322c06db403094d36495f36468 | [
"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 | 5,127 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Transform
import Lean.Meta.Inductive
import Lean.Elab.Deriving.Basic
import Lean.Elab.Deriving.Util
namespace Lean.Elab.Deriving.Repr
open Lean.Parser.Term
open Meta
open Std
def mkReprHeader (indVal : InductiveVal) : TermElabM Header := do
let header ← mkHeader `Repr 1 indVal
return { header with
binders := header.binders.push (← `(bracketedBinder| (prec : Nat)))
}
def mkBodyForStruct (header : Header) (indVal : InductiveVal) : TermElabM Term := do
let ctorVal ← getConstInfoCtor indVal.ctors.head!
let fieldNames := getStructureFields (← getEnv) indVal.name
let numParams := indVal.numParams
let target := mkIdent header.targetNames[0]!
forallTelescopeReducing ctorVal.type fun xs _ => do
let mut fields ← `(Format.nil)
let mut first := true
if xs.size != numParams + fieldNames.size then
throwError "'deriving Repr' failed, unexpected number of fields in structure"
for i in [:fieldNames.size] do
let fieldName := fieldNames[i]!
let fieldNameLit := Syntax.mkStrLit (toString fieldName)
let x := xs[numParams + i]!
if first then
first := false
else
fields ← `($fields ++ "," ++ Format.line)
if (← isType x <||> isProof x) then
fields ← `($fields ++ $fieldNameLit ++ " := " ++ "_")
else
fields ← `($fields ++ $fieldNameLit ++ " := " ++ repr ($target.$(mkIdent fieldName):ident))
`(Format.bracket "{ " $fields:term " }")
def mkBodyForInduct (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Term := do
let discrs ← mkDiscrs header indVal
let alts ← mkAlts
`(match $[$discrs],* with $alts:matchAlt*)
where
mkAlts : TermElabM (Array (TSyntax ``matchAlt)) := do
let mut alts := #[]
for ctorName in indVal.ctors do
let ctorInfo ← getConstInfoCtor ctorName
let alt ← forallTelescopeReducing ctorInfo.type fun xs _ => do
let mut patterns := #[]
-- add `_` pattern for indices
for _ in [:indVal.numIndices] do
patterns := patterns.push (← `(_))
let mut ctorArgs := #[]
let mut rhs : Term := Syntax.mkStrLit (toString ctorInfo.name)
rhs ← `(Format.text $rhs)
-- add `_` for inductive parameters, they are inaccessible
for _ in [:indVal.numParams] do
ctorArgs := ctorArgs.push (← `(_))
for i in [:ctorInfo.numFields] do
let x := xs[indVal.numParams + i]!
let a := mkIdent (← mkFreshUserName `a)
ctorArgs := ctorArgs.push a
let localDecl ← x.fvarId!.getDecl
if localDecl.binderInfo.isExplicit then
if (← inferType x).isAppOf indVal.name then
rhs ← `($rhs ++ Format.line ++ $(mkIdent auxFunName):ident $a:ident max_prec)
else
rhs ← `($rhs ++ Format.line ++ reprArg $a)
patterns := patterns.push (← `(@$(mkIdent ctorName):ident $ctorArgs:term*))
`(matchAltExpr| | $[$patterns:term],* => Repr.addAppParen (Format.group (Format.nest (if prec >= max_prec then 1 else 2) ($rhs:term))) prec)
alts := alts.push alt
return alts
def mkBody (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Term := do
if isStructure (← getEnv) indVal.name then
mkBodyForStruct header indVal
else
mkBodyForInduct header indVal auxFunName
def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Command := do
let auxFunName := ctx.auxFunNames[i]!
let indVal := ctx.typeInfos[i]!
let header ← mkReprHeader indVal
let mut body ← mkBody header indVal auxFunName
if ctx.usePartial then
let letDecls ← mkLocalInstanceLetDecls ctx `Repr header.argNames
body ← mkLet letDecls body
let binders := header.binders
if ctx.usePartial then
`(private partial def $(mkIdent auxFunName):ident $binders:bracketedBinder* : Format := $body:term)
else
`(private def $(mkIdent auxFunName):ident $binders:bracketedBinder* : Format := $body:term)
def mkMutualBlock (ctx : Context) : TermElabM Syntax := do
let mut auxDefs := #[]
for i in [:ctx.typeInfos.size] do
auxDefs := auxDefs.push (← mkAuxFunction ctx i)
`(mutual
$auxDefs:command*
end)
private def mkReprInstanceCmds (declNames : Array Name) : TermElabM (Array Syntax) := do
let ctx ← mkContext "repr" declNames[0]!
let cmds := #[← mkMutualBlock ctx] ++ (← mkInstanceCmds ctx `Repr declNames)
trace[Elab.Deriving.repr] "\n{cmds}"
return cmds
open Command
def mkReprInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if (← declNames.allM isInductive) && declNames.size > 0 then
let cmds ← liftTermElabM <| mkReprInstanceCmds declNames
cmds.forM elabCommand
return true
else
return false
builtin_initialize
registerDerivingHandler `Repr mkReprInstanceHandler
registerTraceClass `Elab.Deriving.repr
end Lean.Elab.Deriving.Repr
|
7c5f21cfe3a4eb102bf5dace21b55c77d5a69cfa | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/category_theory/reflects_isomorphisms.lean | 25ffddfc2ad6dfde16c4d49e02b9fd8606b1b567 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 1,261 | 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.fully_faithful
open category_theory
namespace category_theory
universes v₁ v₂ u₁ u₂
variables {C : Type u₁} [category.{v₁} C]
section reflects_iso
variables {D : Type u₂} [category.{v₂} D]
/--
Define what it means for a functor `F : C ⥤ D` to reflect isomorphisms: for any
morphism `f : A ⟶ B`, if `F.map f` is an isomorphism then `f` is as well.
Note that we do not assume or require that `F` is faithful.
-/
class reflects_isomorphisms (F : C ⥤ D) :=
(reflects : Π {A B : C} (f : A ⟶ B) [is_iso (F.map f)], is_iso f)
/-- If `F` reflects isos and `F.map f` is an iso, then `f` is an iso. -/
def is_iso_of_reflects_iso {A B : C} (f : A ⟶ B) (F : C ⥤ D)
[is_iso (F.map f)] [reflects_isomorphisms F] :
is_iso f :=
reflects_isomorphisms.reflects F f
@[priority 100]
instance (F : C ⥤ D) [full F] [faithful F] : reflects_isomorphisms F :=
{ reflects := λ X Y f i, by exactI
{ inv := F.preimage (inv (F.map f)),
hom_inv_id' := F.map_injective (by simp),
inv_hom_id' := F.map_injective (by simp), } }
end reflects_iso
end category_theory
|
c9ccc410156a28980c04b5f86f2272d6aaa62fe7 | 1a9d3677cccdaaccacb163507570e75d34043a38 | /src/week_2/Part_A_groups.lean | 5a684905f008719a9695a18a2ddbaf2b66509fa4 | [
"Apache-2.0"
] | permissive | alreadydone/formalising-mathematics | 687d386a72065795e784e270f5c05ea3948b67dd | 65869362cd7a2ac74dd1a97c7f9471835726570b | refs/heads/master | 1,680,260,936,332 | 1,616,563,371,000 | 1,616,563,371,000 | 348,780,769 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,583 | lean | import tactic
/-!
# Groups
Definition and basic properties of a group.
-/
-- Technical note: We work in a namespace `xena` because Lean already has groups.
namespace xena
-- Now our definition of a group will really be called `xena.group`.
/-
## Definition of a group
The `group` class will extend `has_mul`, `has_one` and `has_inv`.
`has_mul G` means that `G` has a multiplication `* : G → G → G`
`has_one G` means that `G` has a `1 : G`
`has_inv G` means that `G` has an `⁻¹ : G → G`
All of `*`, `1` and `⁻¹` are notation for functions -- no axioms yet.
A `group` has all of this notation, and the group axioms too.
Let's now define the group class.
-/
/-- A `group` structure on a type `G` is multiplication, identity and inverse,
plus the usual axioms -/
class group (G : Type) extends has_mul G, has_one G, has_inv G :=
(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))
(one_mul : ∀ (a : G), 1 * a = a)
(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)
/-
Formally, a term of type `group G` is now the following data:
a multiplication, 1, and inverse function,
and proofs that the group axioms are satisfied.
The way to say "let G be a group" is now `(G : Type) [group G]`
The square bracket notation is the notation used for classes.
Formally, it means "put a term of type `group G` into the type class
inference system". In practice this just means "you can use group
notation and axioms in proofs, and Lean will figure out why they're true"
We have been extremely mean with our axioms. Some authors also add
the axioms `mul_one : ∀ (a : G), a * 1 = a`
and `mul_right_inv : ∀ (a : G), a * a⁻¹ = 1`.
But these follow from the three axioms we used. Our first job is
to prove them. As you might imagine, mathematically this is pretty
much the trickiest part, because we have to be careful not to
accidentally assume these axioms when we're proving them.
Here are the four lemmas we will prove next.
`mul_left_cancel : ∀ (a b c : G), a * b = a * c → b = c`
`mul_eq_of_eq_inv_mul {a x y : G} : x = a⁻¹ * y → a * x = y`
`mul_one (a : G) : a * 1 = a`
`mul_right_inv (a : G) : a * a⁻¹ = 1`
-/
-- We're proving things about groups so let's work in the `group` namespace
-- (really this is `xena.group`)
namespace group
-- let `G` be a group.
variables {G : Type} [group G]
/-
We start by proving `mul_left_cancel : ∀ a b c, a * b = a * c → b = c`.
We assume `Habac : a * b = a * c` and deduce `b = c`. I've written
down the maths proof. Your job is to supply the rewrites that are
necessary to justify each step. Each rewrite is either one of
the axioms of a group, or an assumption. A reminder of the axioms:
`mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c)`
`one_mul : ∀ (a : G), 1 * a = a`
`mul_left_inv : ∀ (a : G), a⁻¹ * a = 1`
This proof could be done using rewrites, but I will take this opportunity
to introduce the `calc` tactic.
-/
lemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=
begin
calc b = 1 * b : by rw one_mul
... = (a⁻¹ * a) * b : by rw mul_left_inv -- replace `sorry` with `rw X` as appropriate
... = a⁻¹ * (a * b) : by rw mul_assoc
... = a⁻¹ * (a * c) : by rw Habac
... = (a⁻¹ * a) * c : by rw mul_assoc
... = 1 * c : by rw mul_left_inv
... = c : by rw one_mul
end
/-
Next we prove that if `x = a⁻¹ * y` then `a * x = y`. Remember we are still
missing `mul_one` and `mul_right_inv`. A proof that avoids them is
the following: we want `a * x = y`. Now `apply`ing the previous lemma, it
suffices to prove that `a⁻¹ * (a * x) = a⁻¹ * y.`
Now use associativity and left cancellation on on the left, to reduce
to `h`.
Note that `mul_left_cancel` is a function, and its first input is
called `a`, but you had better give it `a⁻¹` instead.
-/
lemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=
begin
apply mul_left_cancel a⁻¹,
rwa [← mul_assoc, mul_left_inv, one_mul]
end
-- It's a bore to keep introducing variable names.
-- Let `a,b,c,x,y` be elements of `G`.
variables (a b c x y : G)
/-
We can use `mul_eq_of_eq_inv_mul` to prove the two "missing" axioms `mul_one`
and `mul_right_inv`, and then our lives will be much easier. Try `apply`ing it
in the theorems below.
-/
@[simp] theorem mul_one : a * 1 = a :=
begin
apply mul_eq_of_eq_inv_mul, rw mul_left_inv
end
@[simp] theorem mul_right_inv : a * a⁻¹ = 1 :=
begin
apply mul_eq_of_eq_inv_mul, rw mul_one
end
-- Now let's talk about what that `@[simp]` means.
/-
## Lean's simplifier
A human sees `a * a⁻¹` in group theory, and instantly replaces it with `1`.
We are going to train a simple AI called `simp` to do the same thing.
Lean's simplifier `simp` is a "term rewriting system". This means
that if you teach it a bunch of theorems of the form `A = B` or
`P ↔ Q` (by tagging them with the `@[simp]` attribute) and then give
it a complicated goal, like
`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1`
then it will try to use the `rw` tactic as much as it can, using the lemmas
it has been taught, in an attempt to simplify the goal. If it manages
to solve it completely, then great! If it does not, but you feel like
it should have done, you might want to tag more lemmas with `@[simp]`.
`simp` should only be used to completely close goals. We are now
going to train the simplifier to solve the example above (indeed, we are
going to train it to reduce an arbitrary element of a free group into
a unique normal form, so it will solve any equalities which are true
for all groups, like the example above).
## Important note
Lean's simplifier does a series of rewrites, each one replacing something
with something else. But the simplifier will always rewrite from left to right!
If you tell it that `A = B` is a `simp` lemma then it will replace `A`s with
`B`s, but it will never replace `B`s with `A`s. If you tag a proof
of `A = B` with `@[simp]` and you also tag a proof of `B = A` with
`@[simp]`, then the simplifier will get stuck in an infinite loop when
it runs into an `A`! Equality should not be thought of as symmetric here.
Because the simplifier works from left to right, an important
rule of thumb is that if `A = B` is a `simp` lemma, then `B` should
probably be simpler than `A`! In particular, equality should not be
thought of as symmetric here. It is not a coincidence that in
the theorems below
`@[simp] theorem mul_one (a : G) : a * 1 = a`
`@[simp] theorem mul_right_inv (a : G) : a * a⁻¹ = 1`
the right hand side is simpler than the left hand side. It would be a
> disaster to tag `a = a * 1` with the `@[simp]` tag -- can you see why?
Let's train Lean's simplifier! Let's teach it the axioms of a `group` next.
We have already done the axioms, so we have to retrospectively tag
them with the `@[simp]` attribute.
-/
attribute [simp] one_mul mul_left_inv mul_assoc
/-
Now let's teach the simplifier the following five lemmas:
`inv_mul_cancel_left : a⁻¹ * (a * b) = b`
`mul_inv_cancel_left : a * (a⁻¹ * b) = b`
`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`
`one_inv : (1 : G)⁻¹ = 1`
`inv_inv : (a⁻¹)⁻¹ = a`
Note that in each case, the right hand side is simpler
than the left hand side.
Try using the simplifier in your proofs! I will do the
first one for you.
-/
@[simp] lemma inv_mul_cancel_left : a⁻¹ * (a * b) = b :=
begin
rw ← mul_assoc, -- the simplifier wouldn't do it that way
-- so we have to do it manually
simp, -- simplifier takes it from here,
-- rewriting a⁻¹ * a to 1 and then 1 * b to b
end
@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=
begin
rw ← mul_assoc, simp
end
@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
begin
apply mul_left_cancel (a*b),
rw mul_right_inv, simp
end
@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=
begin
apply mul_left_cancel (1:G),
rw [mul_right_inv, one_mul]
end
@[simp] lemma inv_inv : a ⁻¹ ⁻¹ = a :=
begin
apply mul_left_cancel a⁻¹,
rw [mul_left_inv, mul_right_inv]
end
/-
The reason I choose these five lemmas in particular, is that
term rewriting systems are very well understood by computer
scientists, and in particular there is something called the
Knuth-Bendix algorithm, which, given as input the three axioms
for a group which we used, produces a "confluent and noetherian
term rewrite system" that transforms every term into a unique
normal form. The system it produces is precisely the `simp`
lemmas which we haven proven above! See
https://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group
for more information. I won't talk any more about the Knuth-Bendix
algorithm because it's really computer science, and I don't really
understand it, but apparently if you apply it to polynomial rings
then you get Buchberger's algorithm for computing Gröbner bases.
-/
-- Now let's try our example...
example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1 := by simp -- short for begin simp end
-- The simplifier solves it!
-- try your own identities. `simp` will solve them all!
/-
This is everything I wanted to show you about groups and the simplifier today.
You can now either go on to subgroups in Part B, or practice your group
theory skills by proving the lemmas below.
-/
/-
We already proved `mul_eq_of_eq_inv_mul` but there are several other
similar-looking, but slightly different, versions of this. Here
is one.
-/
lemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c⁻¹ :=
begin
rw [← mul_one a, ← mul_right_inv c, ← h], simp
end
lemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=
begin
apply mul_left_cancel b, simpa
end
lemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=
begin
split,
have := @eq_mul_inv_of_mul_eq G _ a b b, rwa ← mul_right_inv,
intro h, rw h, apply one_mul
end
lemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=
begin
split,
have := @eq_inv_mul_of_mul_eq G _ b a a, rwa ← mul_left_inv,
intro h, rw h, apply mul_one
end
lemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=
begin
rw ← one_mul b⁻¹, exact eq_mul_inv_of_mul_eq h
end
lemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a⁻¹ = b :=
begin
rw [← mul_one a⁻¹], rw eq_inv_mul_of_mul_eq h
end
lemma unique_left_id {e : G} (h : ∀ x : G, e * x = x) : e = 1 :=
begin
exact mul_left_eq_self.1 (h e)
end
lemma unique_right_inv {a b : G} (h : a * b = 1) : b = a⁻¹ :=
begin
rw inv_eq_of_mul_eq_one h
end
lemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ x = y :=
begin
split,
{ apply mul_left_cancel },
{ intro hxy,
rwa hxy }
end
-- You don't even need to go into tactic mode (begin/end) to use `calc`:
lemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y :=
calc x = x * 1 : by rw mul_one
... = x * (a * a⁻¹) : by rw mul_right_inv
... = (x * a) * a⁻¹ : by rw mul_assoc
... = (y * a) * a⁻¹ : by rw Habac
... = y * (a * a⁻¹) : by rw mul_assoc
... = y * 1 : by rw mul_right_inv
... = y : by rw mul_one
-- `↔` lemmas are good simp lemmas too.
@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=
begin
split, intro h, rw [←inv_inv a, h, inv_inv],
intro h, rw h
--rw ← mul_left_cancel_iff a, split,
end
theorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=
begin
split, repeat {intro h, rw [←h, inv_inv]}
end
end group
end xena
|
9e40c49ed51adfc897cdf01ba562bfa0d557e4df | ebf7140a9ea507409ff4c994124fa36e79b4ae35 | /src/exercises_sources/thursday/category_theory/exercise5.lean | 3bae7510f848235718a18303a933c0c6dc9e21f9 | [] | no_license | fundou/lftcm2020 | 3e88d58a92755ea5dd49f19c36239c35286ecf5e | 99d11bf3bcd71ffeaef0250caa08ecc46e69b55b | refs/heads/master | 1,685,610,799,304 | 1,624,070,416,000 | 1,624,070,416,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,288 | lean | import category_theory.preadditive
import category_theory.limits.shapes.biproducts
/-!
We prove that biproducts (direct sums) are preserved by any preadditive functor.
This result is not in mathlib, so full marks for the exercise are only achievable if you
contribute to a pull request! :-)
-/
noncomputable theory
open category_theory
open category_theory.limits
namespace category_theory
variables {C : Type*} [category C] [preadditive C]
variables {D : Type*} [category D] [preadditive D]
/-!
In fact, no one has gotten around to defining preadditive functors,
so I'll help you out by doing that first.
-/
structure functor.preadditive (F : C ⥤ D) : Prop :=
(map_zero' : ∀ X Y, F.map (0 : X ⟶ Y) = 0)
(map_add' : ∀ {X Y} (f g : X ⟶ Y), F.map (f + g) = F.map f + F.map g)
variables [has_binary_biproducts C] [has_binary_biproducts D]
def functor.preadditive.preserves_biproducts (F : C ⥤ D) (P : F.preadditive) (X Y : C) :
F.obj (X ⊞ Y) ≅ F.obj X ⊞ F.obj Y :=
sorry
/-!
There are some further hints in
`hints/category_theory/exercise5/`
-/
-- Challenge problem:
-- In fact one could prove a better result,
-- not requiring chosen biproducts in D,
-- just asserting that `F.obj (X ⊞ Y)` is a biproduct of `F.obj X` and `F.obj Y`.
end category_theory
|
4e3127034a191a10a32add3c550aa9431df15c79 | 98beff2e97d91a54bdcee52f922c4e1866a6c9b9 | /src/construction.lean | 1ef9097fa5feec5b92a5fec4c14871db2c5902de | [] | no_license | b-mehta/topos | c3fc43fb04ba16bae1965ce5c26c6461172e5bc6 | c9032b11789e36038bc841a1e2b486972421b983 | refs/heads/master | 1,629,609,492,867 | 1,609,907,263,000 | 1,609,907,263,000 | 240,943,034 | 43 | 3 | null | 1,598,210,062,000 | 1,581,877,668,000 | Lean | UTF-8 | Lean | false | false | 13,365 | lean | import category_theory.limits.shapes.binary_products
import category_theory.limits.preserves.shapes.binary_products
import category_theory.adjunction
import category_theory.monad.adjunction
import category_theory.adjunction.fully_faithful
import category_theory.closed.cartesian
import category.adjunction
universes v₁ v₂ u₁ u₂
namespace category_theory
open limits category
variables {C : Type u₁} {D : Type u₂} [category.{v₁} C] [category.{v₁} D] (i : D ⥤ C)
def coyoneda.ext {X Y : C} (p : Π {Z : C}, (X ⟶ Z) ≃ (Y ⟶ Z))
(n : Π {Z Z' : C} (f : Z ⟶ Z') (g : X ⟶ Z), p (g ≫ f) = p g ≫ f) : X ≅ Y :=
{ hom := p.symm (𝟙 Y),
inv := p (𝟙 X),
hom_inv_id' := by rw [← p.injective.eq_iff, n, p.apply_symm_apply, id_comp],
inv_hom_id' := by rw [← n, id_comp, equiv.apply_symm_apply] }
class in_subcategory (A : C) :=
(witness : D)
(iso : i.obj witness ≅ A)
def witness_in (A : C) [in_subcategory i A] : D := in_subcategory.witness.{v₁} i A
def witness_iso (A : C) [in_subcategory i A] : i.obj (witness_in i A) ≅ A := in_subcategory.iso.
class in_subcategory' [ir : is_right_adjoint i] (A : C) :=
( returning : is_iso (ir.adj.unit.app A) )
def containment_iso (A : C) [ir : is_right_adjoint i] [h : in_subcategory' i A] : A ≅ i.obj ((left_adjoint i).obj A) :=
begin
haveI := h.returning,
exact as_iso (ir.adj.unit.app A),
end
variable {i}
instance inclusion_is_in (B : D) : in_subcategory i (i.obj B) :=
{ witness := B,
iso := iso.refl _ }
noncomputable
instance inclusion_is_in' (B : D) [ir : reflective i] : in_subcategory' i (i.obj B) :=
{ returning :=
begin
haveI := nat_iso.is_iso_app_of_is_iso ir.adj.counit B,
have : ir.adj.unit.app (i.obj B) ≫ i.map (ir.adj.counit.app B) = 𝟙 (i.obj B) := ir.adj.right_triangle_components,
refine ⟨i.map (ir.adj.counit.app B), ir.adj.right_triangle_components, _⟩,
dsimp,
rw [← cancel_mono (i.map (is_right_adjoint.adj.counit.app B)), assoc, this, comp_id, id_comp],
apply is_iso.mono_of_iso,
end }
def unit_iso_of_split_mono [ir : reflective i] (A : C) [split_mono (ir.adj.unit.app A)] : is_iso (ir.adj.unit.app A) :=
begin
let h : i.obj (ir.left.obj A) ⟶ A := retraction (ir.adj.unit.app A),
haveI : is_iso (ir.adj.unit.app (i.obj (ir.left.obj A))) := in_subcategory'.returning,
haveI : split_epi h := ⟨ir.adj.unit.app A, split_mono.id (ir.adj.unit.app A)⟩,
suffices : epi (ir.adj.unit.app A),
refine ⟨h, split_mono.id (ir.adj.unit.app A), _⟩,
resetI,
dsimp,
erw [← cancel_epi (ir.adj.unit.app A), split_mono.id_assoc (ir.adj.unit.app A), comp_id],
suffices : epi (ir.adj.unit.app _ ≫ i.map (ir.left.map h)),
erw [← ir.adj.unit.naturality h, functor.id_map] at this,
resetI,
apply epi_of_epi h,
apply epi_comp,
end
-- Some of the stuff here doesn't need reflectiveness, need to untangle what assumptions are actually used
noncomputable
def in_subcategory_of_has_iso [ir : reflective i] (A : C) (B : D) (h : i.obj B ≅ A) : in_subcategory' i A :=
{ returning :=
begin
apply unit_iso_of_split_mono _,
refine ⟨i.map ((ir.adj.hom_equiv _ _).symm h.inv) ≫ h.hom, _⟩,
simp,
end }
@[reducible]
def equiv_homset_left_of_iso
{X X' : C} (Y : C) (i : X ≅ X') :
(X ⟶ Y) ≃ (X' ⟶ Y) :=
{ to_fun := λ f, i.inv ≫ f,
inv_fun := λ f, i.hom ≫ f,
left_inv := λ f, by simp,
right_inv := λ f, by simp }.
@[reducible]
def equiv_homset_right_of_iso
(X : C) {Y Y' : C} (i : Y ≅ Y') :
(X ⟶ Y) ≃ (X ⟶ Y') :=
{ to_fun := λ f, f ≫ i.hom,
inv_fun := λ f, f ≫ i.inv,
left_inv := λ f, by simp,
right_inv := λ f, by simp }.
variable (i)
noncomputable
def biject_inclusion [ir : reflective i] {A B : C} [in_subcategory' i B] : (A ⟶ B) ≃ (i.obj ((left_adjoint i).obj A) ⟶ B) :=
calc (A ⟶ B) ≃ (A ⟶ i.obj ((left_adjoint i).obj B)) : equiv_homset_right_of_iso _ (containment_iso _ _)
... ≃ ((left_adjoint i).obj A ⟶ (left_adjoint i).obj B) : (ir.adj.hom_equiv _ _).symm
... ≃ (i.obj ((left_adjoint i).obj A) ⟶ i.obj ((left_adjoint i).obj B)) : equiv_of_fully_faithful i
... ≃ (i.obj ((left_adjoint i).obj A) ⟶ B) : equiv_homset_right_of_iso _ (containment_iso _ _).symm
variable {i}
lemma biject_inclusion_natural [ir : reflective i] {A B B' : C} [h : in_subcategory' i B] [h' : in_subcategory' i B'] (f : A ⟶ B) (g : B ⟶ B') :
biject_inclusion i (f ≫ g) = biject_inclusion i f ≫ g :=
begin
dsimp [biject_inclusion, containment_iso],
haveI := h'.returning,
haveI := h.returning,
have : i.map
(((is_right_adjoint.adj.hom_equiv A ((left_adjoint i).obj B')).symm)
((f ≫ g) ≫ is_right_adjoint.adj.unit.app B')) ≫
inv (is_right_adjoint.adj.unit.app B') = (i.map
(((is_right_adjoint.adj.hom_equiv A ((left_adjoint i).obj B)).symm)
(f ≫ is_right_adjoint.adj.unit.app B)) ≫
inv (is_right_adjoint.adj.unit.app B)) ≫
g ↔ _ = _ := (as_iso (ir.adj.unit.app B')).comp_inv_eq,
convert this.2 _, -- this should not be necessary
clear this,
dsimp [as_iso_hom],
erw [assoc, assoc, ir.adj.unit.naturality, assoc, (as_iso _).inv_hom_id_assoc, functor.comp_map, ← functor.map_comp],
rw [← ir.adj.hom_equiv_naturality_right_symm, assoc], refl,
end .
lemma biject_inclusion_natural_left [ir : reflective i] {A A' B : C} [h : in_subcategory' i B] (f : A ⟶ A') (g : A' ⟶ B) :
biject_inclusion i (f ≫ g) = i.map ((left_adjoint i).map f) ≫ biject_inclusion i g :=
begin
dsimp [biject_inclusion],
erw [← i.map_comp_assoc, ← ir.adj.hom_equiv_naturality_left_symm, assoc],
end
lemma biject_inclusion_symm_id_eq [ir : reflective i] (A : C) :
(biject_inclusion i).symm (𝟙 (i.obj ((left_adjoint i).obj A))) = ir.adj.unit.app A :=
begin
rw equiv.symm_apply_eq,
dsimp [biject_inclusion, containment_iso],
rw [ir.adj.hom_equiv_counit],
let η := ir.adj.unit,
let ε := ir.adj.counit,
let L := left_adjoint i,
have : 𝟙 (i.obj ((left_adjoint i).obj A)) = _ ≫ inv (is_right_adjoint.adj.unit.app (i.obj ((left_adjoint i).obj A))) ↔ _ = _ := (as_iso (is_right_adjoint.adj.unit.app (i.obj ((left_adjoint i).obj A)))).eq_comp_inv,
rw this, clear this,
rw [id_comp, as_iso_hom],
change η.app (i.obj (L.obj A)) = i.map (L.map (η.app A ≫ η.app (i.obj (L.obj A))) ≫ ε.app (L.obj (i.obj (L.obj A)))),
rw [L.map_comp, assoc],
haveI := nat_iso.is_iso_app_of_is_iso ε (L.obj A),
erw [ir.adj.left_triangle_components, comp_id, ← cancel_mono (i.map (ε.app (L.obj A))), ir.adj.right_triangle_components,
← i.map_comp, ir.adj.left_triangle_components, i.map_id],
end
lemma biject_inclusion_is_comp_unit [ir : reflective i] {A B : C} [h : in_subcategory' i B] (f : i.obj ((left_adjoint i).obj A) ⟶ B) :
(biject_inclusion i).symm f = ir.adj.unit.app _ ≫ f :=
by rw [← biject_inclusion_symm_id_eq A, (biject_inclusion i).symm_apply_eq,
biject_inclusion_natural _ _, equiv.apply_symm_apply, id_comp]
variables [has_finite_products.{v₁} C] [has_finite_products.{v₁} D] [cartesian_closed C] (i)
class exponential_ideal extends reflective i :=
[ strength (A) {B} [in_subcategory' i B] : in_subcategory' i (A ⟹ B) ]
noncomputable def exponential_ideal_of [z : reflective i]
(h : ∀ (A : C) (B : D), in_subcategory' i (A ⟹ i.obj B)) : exponential_ideal i :=
{ strength := λ A B inst,
begin
resetI,
let ir : is_right_adjoint i := by apply_instance,
let L := ir.left,
let η := ir.adj.unit,
haveI := h A (L.obj B),
let i₁ : B ≅ i.obj (L.obj B) := containment_iso i B,
let i₂ : A ⟹ i.obj (L.obj B) ≅ i.obj (L.obj (A ⟹ (i.obj (L.obj B)))) := containment_iso i (A ⟹ i.obj (L.obj B)),
let : A ⟹ B ≅ i.obj (L.obj (A ⟹ B)),
apply (exp A).map_iso i₁ ≪≫ i₂ ≪≫ (exp A ⋙ L ⋙ i).map_iso i₁.symm,
refine ⟨_⟩,
convert is_iso.of_iso this,
change η.app (A ⟹ B) =
(exp _).map (containment_iso _ _).hom ≫ η.app _ ≫ i.map (L.map ((exp _).map (containment_iso _ _).inv)),
erw η.naturality_assoc,
change η.app (A ⟹ B) = η.app (A ⟹ B) ≫ (exp A ⋙ L ⋙ _).map _ ≫ (exp A ⋙ L ⋙ _).map _,
rw [← (exp A ⋙ L ⋙ _).map_comp, iso.hom_inv_id, functor.map_id],
erw comp_id,
end,
..z }
variables [exponential_ideal i]
noncomputable
def bijection (A B : C) (C' : D) : ((left_adjoint i).obj (A ⨯ B) ⟶ C') ≃ ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B ⟶ C') :=
calc _ ≃ (A ⨯ B ⟶ i.obj C') : _inst_6.to_reflective.adj.hom_equiv _ _
... ≃ (B ⨯ A ⟶ i.obj C') : equiv_homset_left_of_iso _ (limits.prod.braiding _ _)
... ≃ (A ⟶ B ⟹ i.obj C') : (exp.adjunction _).hom_equiv _ _
... ≃ (i.obj ((left_adjoint i).obj A) ⟶ B ⟹ i.obj C') :
begin
apply biject_inclusion i,
apply exponential_ideal.strength,
end
... ≃ (B ⨯ i.obj ((left_adjoint i).obj A) ⟶ i.obj C') : ((exp.adjunction _).hom_equiv _ _).symm
... ≃ (i.obj ((left_adjoint i).obj A) ⨯ B ⟶ i.obj C') : equiv_homset_left_of_iso _ (limits.prod.braiding _ _)
... ≃ (B ⟶ i.obj ((left_adjoint i).obj A) ⟹ i.obj C') : (exp.adjunction _).hom_equiv _ _
... ≃ (i.obj ((left_adjoint i).obj B) ⟶ i.obj ((left_adjoint i).obj A) ⟹ i.obj C') :
begin
apply biject_inclusion _,
apply exponential_ideal.strength,
end
... ≃ (i.obj ((left_adjoint i).obj A) ⨯ i.obj ((left_adjoint i).obj B) ⟶ i.obj C') : ((exp.adjunction _).hom_equiv _ _).symm
... ≃ (i.obj ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B) ⟶ i.obj C') : equiv_homset_left_of_iso _
begin
apply (as_iso (prod_comparison _ _ _)).symm,
haveI : preserves_limits i := _inst_6.to_reflective.adj.right_adjoint_preserves_limits,
apply_instance,
end
... ≃ ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B ⟶ C') : (equiv_of_fully_faithful _).symm
variables {i}
lemma comp_inv_eq {X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ Y) (h : Z ⟶ X) [is_iso f] :
g ≫ inv f = h ↔ g = h ≫ f :=
(as_iso f).comp_inv_eq.
-- @[reassoc] lemma prod_comparison_natural (F : C ⥤ D) {A A' B B' : C} (f : A ⟶ A') (g : B ⟶ B') :
-- F.map (prod.map f g) ≫ prod_comparison F A' B' = prod_comparison F A B ≫ prod.map (F.map f) (F.map g) :=
lemma bijection_id (A B : C) : (bijection i A B _).symm (𝟙 _) = prod_comparison _ _ _ :=
begin
dsimp [bijection],
-- rw [equiv.symm_symm, equiv.symm_symm, equiv.symm_symm],
-- dsimp [equiv_of_fully_faithful],
rw [i.map_id, comp_id, biject_inclusion_is_comp_unit, biject_inclusion_is_comp_unit],
let ir : is_right_adjoint i := by apply_instance,
let L := ir.left,
let adj : L ⊣ i := ir.adj,
let η : _ ⟶ L ⋙ i := adj.unit,
let ε : i ⋙ L ⟶ _ := adj.counit,
change ((adj.hom_equiv (A ⨯ B) (L.obj A ⨯ L.obj B)).symm)
(prod.lift limits.prod.snd limits.prod.fst ≫
cartesian_closed.uncurry (η.app A ≫
cartesian_closed.curry (prod.lift limits.prod.snd limits.prod.fst ≫
cartesian_closed.uncurry (η.app B ≫ cartesian_closed.curry _)))) =
prod_comparison L A B,
rw [uncurry_natural_left, uncurry_curry, uncurry_natural_left, uncurry_curry,
← adjunction.eq_hom_equiv_apply, prod.lift_map_assoc, prod.lift_map_assoc,
comp_id, comp_id, ← assoc, comp_inv_eq, adjunction.hom_equiv_unit, assoc],
apply prod.hom_ext,
rw [assoc, prod.lift_fst, prod.lift_snd, assoc, assoc, prod_comparison, prod_comparison,
prod.lift_fst, ← i.map_comp, prod.lift_fst],
apply η.naturality,
rw [assoc, prod.lift_snd, prod.lift_fst_assoc, assoc, assoc, prod_comparison,
prod_comparison, prod.lift_snd, ← i.map_comp, prod.lift_snd],
apply η.naturality,
end .
lemma bijection_natural (A B : C) (C' C'' : D) (f : ((left_adjoint i).obj (A ⨯ B) ⟶ C')) (g : C' ⟶ C'') : bijection i _ _ _ (f ≫ g) = bijection i _ _ _ f ≫ g :=
begin
have : i.preimage (i.map g) = g := preimage_map g,
conv_rhs {congr, skip, rw ← this},
dsimp [bijection],
rw [← preimage_comp, assoc, ← adjunction.hom_equiv_naturality_right_symm,
is_right_adjoint.adj.hom_equiv_naturality_right, ← assoc,
(exp.adjunction B).hom_equiv_naturality_right, ← biject_inclusion_natural _ _,
← (exp.adjunction (i.obj _)).hom_equiv_naturality_right, assoc,
← (exp.adjunction B).hom_equiv_naturality_right_symm, ← biject_inclusion_natural _ _],
end
open limits.prod
noncomputable
def preserves_pair_of_exponential_ideal (A B : C) : preserves_limit (pair.{v₁} A B) (is_right_adjoint.left i) :=
begin
let ir : is_right_adjoint i := by apply_instance,
let L := ir.left,
let : L.obj (A ⨯ B) ≅ L.obj A ⨯ L.obj B := coyoneda.ext (λ Z, bijection i A B _) (λ _ _ _ _, bijection_natural _ _ _ _ _ _),
have equate : prod_comparison L A B = this.hom := (bijection_id A B).symm,
have : is_iso (prod_comparison L A B),
rw equate, apply_instance,
exactI preserves_pair.of_iso_comparison _ _ _,
end
variable (i)
noncomputable
def preserves_binary_products_of_exponential_ideal : preserves_limits_of_shape (discrete walking_pair) (is_right_adjoint.left i) :=
{ preserves_limit := λ K,
begin
apply preserves_limit_of_iso_diagram _ (diagram_iso_pair K).symm,
apply preserves_pair_of_exponential_ideal,
end }
end category_theory
|
f89b48feb8e3ca806e0da690804ee3df18c04aea | e514e8b939af519a1d5e9b30a850769d058df4e9 | /src/lib_unused/options.lean | 4ea881de10dac682200488a7e4ce5ba586226ae7 | [] | no_license | semorrison/lean-rewrite-search | dca317c5a52e170fb6ffc87c5ab767afb5e3e51a | e804b8f2753366b8957be839908230ee73f9e89f | refs/heads/master | 1,624,051,754,485 | 1,614,160,817,000 | 1,614,160,817,000 | 162,660,605 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 171 | lean | -- meta def options.set_list_bool : options → list (name × bool) → options
-- | o [] := o
-- | o ((n, v) :: rest) := (o.set_bool n v).set_list_bool rest |
5d29bc382109a88d360ab6e774cfcdecac7c87ee | 4727251e0cd73359b15b664c3170e5d754078599 | /src/analysis/normed_space/add_torsor_bases.lean | c8a8e98bf05aa6bb77a7513fa11f3330513d9bc4 | [
"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 | 7,435 | 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 analysis.normed_space.banach
import analysis.normed_space.finite_dimension
import analysis.calculus.affine_map
import analysis.convex.combination
import linear_algebra.affine_space.basis
import linear_algebra.affine_space.finite_dimensional
/-!
# Bases in normed affine spaces.
This file contains results about bases in normed affine spaces.
## Main definitions:
* `continuous_barycentric_coord`
* `is_open_map_barycentric_coord`
* `interior_convex_hull_aff_basis`
* `exists_subset_affine_independent_span_eq_top_of_open`
* `interior_convex_hull_nonempty_iff_aff_span_eq_top`
-/
section barycentric
variables {ι 𝕜 E P : Type*} [nondiscrete_normed_field 𝕜] [complete_space 𝕜]
variables [normed_group E] [normed_space 𝕜 E] [finite_dimensional 𝕜 E]
variables [metric_space P] [normed_add_torsor E P]
variables (b : affine_basis ι 𝕜 P)
@[continuity]
lemma continuous_barycentric_coord (i : ι) : continuous (b.coord i) :=
(b.coord i).continuous_of_finite_dimensional
local attribute [instance] finite_dimensional.complete
lemma is_open_map_barycentric_coord [nontrivial ι] (i : ι) :
is_open_map (b.coord i) :=
(b.coord i).is_open_map (continuous_barycentric_coord b i) (b.surjective_coord i)
lemma smooth_barycentric_coord (b : affine_basis ι 𝕜 E) (i : ι) : cont_diff 𝕜 ⊤ (b.coord i) :=
(⟨b.coord i, continuous_barycentric_coord b i⟩ : E →A[𝕜] 𝕜).cont_diff
end barycentric
open set
/-- Given a finite-dimensional normed real vector space, the interior of the convex hull of an
affine basis is the set of points whose barycentric coordinates are strictly positive with respect
to this basis.
TODO Restate this result for affine spaces (instead of vector spaces) once the definition of
convexity is generalised to this setting. -/
lemma interior_convex_hull_aff_basis {ι E : Type*} [fintype ι] [normed_group E] [normed_space ℝ E]
(b : affine_basis ι ℝ E) :
interior (convex_hull ℝ (range b.points)) = { x | ∀ i, 0 < b.coord i x } :=
begin
cases subsingleton_or_nontrivial ι with h h,
{ -- The zero-dimensional case.
haveI := h,
suffices : range (b.points) = univ, { simp [this], },
refine affine_subspace.eq_univ_of_subsingleton_span_eq_top _ b.tot,
rw ← image_univ,
exact subsingleton.image subsingleton_of_subsingleton b.points, },
{ -- The positive-dimensional case.
haveI : finite_dimensional ℝ E,
{ classical,
obtain ⟨i⟩ := (infer_instance : nonempty ι),
exact finite_dimensional.of_fintype_basis (b.basis_of i), },
have : convex_hull ℝ (range b.points) = ⋂ i, (b.coord i)⁻¹' Ici 0,
{ rw convex_hull_affine_basis_eq_nonneg_barycentric b, ext, simp, },
ext,
simp only [this, interior_Inter_of_fintype, ← is_open_map.preimage_interior_eq_interior_preimage
(is_open_map_barycentric_coord b _) (continuous_barycentric_coord b _),
interior_Ici, mem_Inter, mem_set_of_eq, mem_Ioi, mem_preimage], },
end
variables {V P : Type*} [normed_group V] [normed_space ℝ V] [metric_space P] [normed_add_torsor V P]
include V
open affine_map
/-- Given a set `s` of affine-independent points belonging to an open set `u`, we may extend `s` to
an affine basis, all of whose elements belong to `u`. -/
lemma exists_subset_affine_independent_span_eq_top_of_open {s u : set P} (hu : is_open u)
(hsu : s ⊆ u) (hne : s.nonempty) (h : affine_independent ℝ (coe : s → P)) :
∃ t : set P, s ⊆ t ∧ t ⊆ u ∧ affine_independent ℝ (coe : t → P) ∧ affine_span ℝ t = ⊤ :=
begin
obtain ⟨q, hq⟩ := hne,
obtain ⟨ε, hε, hεu⟩ := metric.is_open_iff.mp hu q (hsu hq),
obtain ⟨t, ht₁, ht₂, ht₃⟩ := exists_subset_affine_independent_affine_span_eq_top h,
let f : P → P := λ y, line_map q y (ε / 2 / (dist y q)),
have hf : ∀ y, f y ∈ u,
{ intros y,
apply hεu,
simp only [metric.mem_ball, f, line_map_apply, dist_vadd_left, norm_smul, real.norm_eq_abs,
dist_eq_norm_vsub V y q],
cases eq_or_ne (∥y -ᵥ q∥) 0 with hyq hyq, { rwa [hyq, mul_zero], },
rw [← norm_pos_iff, norm_norm] at hyq,
calc abs (ε / 2 / ∥y -ᵥ q∥) * ∥y -ᵥ q∥
= ε / 2 / ∥y -ᵥ q∥ * ∥y -ᵥ q∥ : by rw [abs_div, abs_of_pos (half_pos hε), abs_of_pos hyq]
... = ε / 2 : div_mul_cancel _ (ne_of_gt hyq)
... < ε : half_lt_self hε, },
have hεyq : ∀ (y ∉ s), ε / 2 / dist y q ≠ 0,
{ simp only [ne.def, div_eq_zero_iff, or_false, dist_eq_zero, bit0_eq_zero, one_ne_zero,
not_or_distrib, ne_of_gt hε, true_and, not_false_iff],
exact λ y h1 h2, h1 (h2.symm ▸ hq) },
classical,
let w : t → ℝˣ := λ p, if hp : (p : P) ∈ s then 1 else units.mk0 _ (hεyq ↑p hp),
refine ⟨set.range (λ (p : t), line_map q p (w p : ℝ)), _, _, _, _⟩,
{ intros p hp, use ⟨p, ht₁ hp⟩, simp [w, hp], },
{ intros y hy,
simp only [set.mem_range, set_coe.exists, subtype.coe_mk] at hy,
obtain ⟨p, hp, hyq⟩ := hy,
by_cases hps : p ∈ s;
simp only [w, hps, line_map_apply_one, units.coe_mk0, dif_neg, dif_pos, not_false_iff,
units.coe_one, subtype.coe_mk] at hyq;
rw ← hyq;
[exact hsu hps, exact hf p], },
{ exact (ht₂.units_line_map ⟨q, ht₁ hq⟩ w).range, },
{ rw [affine_span_eq_affine_span_line_map_units (ht₁ hq) w, ht₃], },
end
lemma interior_convex_hull_nonempty_iff_aff_span_eq_top [finite_dimensional ℝ V] {s : set V} :
(interior (convex_hull ℝ s)).nonempty ↔ affine_span ℝ s = ⊤ :=
begin
split,
{ rintros ⟨x, hx⟩,
obtain ⟨u, hu₁, hu₂, hu₃⟩ := mem_interior.mp hx,
let t : set V := {x},
obtain ⟨b, hb₁, hb₂, hb₃, hb₄⟩ := exists_subset_affine_independent_span_eq_top_of_open hu₂
(singleton_subset_iff.mpr hu₃) (singleton_nonempty x)
(affine_independent_of_subsingleton ℝ (coe : t → V)),
rw [eq_top_iff, ← hb₄, ← affine_span_convex_hull s],
mono,
exact hb₂.trans hu₁, },
{ intros h,
obtain ⟨t, hts, h_tot, h_ind⟩ := exists_affine_independent ℝ V s,
suffices : (interior (convex_hull ℝ (range (coe : t → V)))).nonempty,
{ rw [subtype.range_coe_subtype, set_of_mem_eq] at this,
apply nonempty.mono _ this,
mono* },
haveI : fintype t := fintype_of_fin_dim_affine_independent ℝ h_ind,
use finset.centroid ℝ (finset.univ : finset t) (coe : t → V),
rw [h, ← @set_of_mem_eq V t, ← subtype.range_coe_subtype] at h_tot,
let b : affine_basis t ℝ V := ⟨coe, h_ind, h_tot⟩,
rw interior_convex_hull_aff_basis b,
have htne : (finset.univ : finset t).nonempty,
{ simpa [finset.univ_nonempty_iff] using
affine_subspace.nonempty_of_affine_span_eq_top ℝ V V h_tot, },
simp [finset.centroid_def, b.coord_apply_combination_of_mem (finset.mem_univ _)
(finset.sum_centroid_weights_eq_one_of_nonempty ℝ (finset.univ : finset t) htne),
finset.centroid_weights_apply, nat.cast_pos, inv_pos, finset.card_pos.mpr htne], },
end
lemma convex.interior_nonempty_iff_affine_span_eq_top [finite_dimensional ℝ V] {s : set V}
(hs : convex ℝ s) : (interior s).nonempty ↔ affine_span ℝ s = ⊤ :=
by rw [← interior_convex_hull_nonempty_iff_aff_span_eq_top, hs.convex_hull_eq]
|
29cd49f613a9b85b80ecbbcb6aed2f98fca6e46e | 38bf3fd2bb651ab70511408fcf70e2029e2ba310 | /src/topology/algebra/ordered.lean | 1430a88afcc1aa79bdc2447b16f294979e544d45 | [
"Apache-2.0"
] | permissive | JaredCorduan/mathlib | 130392594844f15dad65a9308c242551bae6cd2e | d5de80376088954d592a59326c14404f538050a1 | refs/heads/master | 1,595,862,206,333 | 1,570,816,457,000 | 1,570,816,457,000 | 209,134,499 | 0 | 0 | Apache-2.0 | 1,568,746,811,000 | 1,568,746,811,000 | null | UTF-8 | Lean | false | false | 44,565 | 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
Theory of ordered topology.
-/
import order.liminf_limsup
import data.set.intervals
import topology.algebra.group
import topology.constructions
open classical set lattice filter topological_space
local attribute [instance] classical.prop_decidable -- TODO: use "open_locale classical"
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- (Partially) ordered topology
Also called: partially ordered spaces (pospaces).
Usually ordered topology is used for a topology on linear ordered spaces, where the open intervals
are open sets. This is a generalization as for each linear order where open interals are open sets,
the order relation is closed. -/
class ordered_topology (α : Type*) [t : topological_space α] [preorder α] : Prop :=
(is_closed_le' : is_closed (λp:α×α, p.1 ≤ p.2))
instance {α : Type*} : Π [topological_space α], topological_space (order_dual α) := id
section ordered_topology
section preorder
variables [topological_space α] [preorder α] [t : ordered_topology α]
include t
lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_closed {b | f b ≤ g b} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ t.is_closed_le'
lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} :=
is_closed_le continuous_id continuous_const
lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} :=
is_closed_le continuous_const continuous_id
instance : ordered_topology (order_dual α) :=
⟨continuous_swap _ (@ordered_topology.is_closed_le' α _ _ _)⟩
lemma is_closed_Icc {a b : α} : is_closed (Icc a b) :=
is_closed_inter (is_closed_ge' a) (is_closed_le' b)
lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} (hb : b ≠ ⊥)
(hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) (h : {b | f b ≤ g b} ∈ b) :
a₁ ≤ a₂ :=
have tendsto (λb, (f b, g b)) b (nhds (a₁, a₂)),
by rw [nhds_prod_eq]; exact hf.prod_mk hg,
show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2},
from mem_of_closed_of_tendsto hb this t.is_closed_le' h
lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β}
(nt : x ≠ ⊥) (lim : tendsto f x (nhds a)) (h : f ⁻¹' {c | c ≤ b} ∈ x) : a ≤ b :=
le_of_tendsto_of_tendsto nt lim tendsto_const_nhds h
lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β}
(nt : x ≠ ⊥) (lim : tendsto f x (nhds a)) (h : f ⁻¹' {c | b ≤ c} ∈ x) : b ≤ a :=
le_of_tendsto_of_tendsto nt tendsto_const_nhds lim h
@[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
closure {b | f b ≤ g b} = {b | f b ≤ g b} :=
closure_eq_iff_is_closed.mpr $ is_closed_le hf hg
end preorder
section partial_order
variables [topological_space α] [partial_order α] [t : ordered_topology α]
include t
private lemma is_closed_eq : is_closed {p : α × α | p.1 = p.2} :=
by simp [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
instance ordered_topology.to_t2_space : t2_space α :=
{ t2 :=
have is_open {p : α × α | p.1 ≠ p.2}, from is_closed_eq,
assume a b h,
let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in
⟨u, v, hu, hv, ha, hb,
set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩,
have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩,
this rfl⟩ }
end partial_order
section linear_order
variables [topological_space α] [linear_order α] [t : ordered_topology α]
include t
lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_open {b | f b < g b} :=
by simp [lt_iff_not_ge, -not_le]; exact is_closed_le hg hf
lemma is_open_Ioo {a b : α} : is_open (Ioo a b) :=
is_open_and (is_open_lt continuous_const continuous_id) (is_open_lt continuous_id continuous_const)
lemma is_open_Iio {a : α} : is_open (Iio a) :=
is_open_lt continuous_id continuous_const
end linear_order
section decidable_linear_order
variables [topological_space α] [decidable_linear_order α] [t : ordered_topology α] {f g : β → α}
include t
section
variables [topological_space β] (hf : continuous f) (hg : continuous g)
include hf hg
lemma frontier_le_subset_eq : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} :=
assume b ⟨hb₁, hb₂⟩,
le_antisymm
(by simpa [closure_le_eq hf hg] using hb₁)
(not_lt.1 $ assume hb : f b < g b,
have {b | f b < g b} ⊆ interior {b | f b ≤ g b},
from (subset_interior_iff_subset_of_open $ is_open_lt hf hg).mpr $ assume x, le_of_lt,
have b ∈ interior {b | f b ≤ g b}, from this hb,
by exact hb₂ this)
lemma frontier_lt_subset_eq : frontier {b | f b < g b} ⊆ {b | f b = g b} :=
by rw ← frontier_compl;
convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm]
lemma continuous_max : continuous (λb, max (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, g b = f b, from assume b hb, (frontier_le_subset_eq hf hg hb).symm,
continuous_if this hg hf
lemma continuous_min : continuous (λb, min (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb,
continuous_if this hf hg
end
lemma tendsto_max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, max (f b) (g b)) b (nhds (max a₁ a₂)) :=
show tendsto ((λp:α×α, max p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (max a₁ a₂)),
from tendsto.comp
begin
rw [←nhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_max continuous_fst continuous_snd) _
end
(hf.prod_mk hg)
lemma tendsto_min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, min (f b) (g b)) b (nhds (min a₁ a₂)) :=
show tendsto ((λp:α×α, min p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (min a₁ a₂)),
from tendsto.comp
begin
rw [←nhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_min continuous_fst continuous_snd) _
end
(hf.prod_mk hg)
end decidable_linear_order
end ordered_topology
/-- Topologies generated by the open intervals.
This is restricted to linear orders. Only then it is guaranteed that they are also a ordered
topology. -/
class orderable_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop :=
(topology_eq_generate_intervals :
t = generate_from {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}})
section orderable_topology
instance {α : Type*} [topological_space α] [partial_order α] [orderable_topology α] :
orderable_topology (order_dual α) :=
⟨by convert @orderable_topology.topology_eq_generate_intervals α _ _ _;
conv in (_ ∨ _) { rw or.comm }; refl⟩
section partial_order
variables [topological_space α] [partial_order α] [t : orderable_topology α]
include t
lemma is_open_iff_generate_intervals {s : set α} :
is_open s ↔ generate_open {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}} s :=
by rw [t.topology_eq_generate_intervals]; refl
lemma is_open_lt' (a : α) : is_open {b:α | a < b} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩
lemma is_open_gt' (a : α) : is_open {b:α | b < a} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩
lemma lt_mem_nhds {a b : α} (h : a < b) : {b | a < b} ∈ nhds b :=
mem_nhds_sets (is_open_lt' _) h
lemma le_mem_nhds {a b : α} (h : a < b) : {b | a ≤ b} ∈ nhds b :=
(nhds b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma gt_mem_nhds {a b : α} (h : a < b) : {a | a < b} ∈ nhds a :=
mem_nhds_sets (is_open_gt' _) h
lemma ge_mem_nhds {a b : α} (h : a < b) : {a | a ≤ b} ∈ nhds a :=
(nhds a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma nhds_eq_orderable {a : α} :
nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) :=
by rw [t.topology_eq_generate_intervals, nhds_generate_from];
from le_antisymm
(le_inf
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩)
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩))
(le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩,
match s, ha, hs with
| _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h
| _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h
end)
lemma tendsto_orderable {f : β → α} {a : α} {x : filter β} :
tendsto f x (nhds a) ↔ (∀a'<a, {b | a' < f b} ∈ x) ∧ (∀a'>a, {b | a' > f b} ∈ x) :=
by simp [@nhds_eq_orderable α _ _, tendsto_inf, tendsto_infi, tendsto_principal]
/-- Also known as squeeze or sandwich theorem. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α}
(hg : tendsto g b (nhds a)) (hh : tendsto h b (nhds a))
(hgf : {b | g b ≤ f b} ∈ b) (hfh : {b | f b ≤ h b} ∈ b) :
tendsto f b (nhds a) :=
tendsto_orderable.2
⟨assume a' h',
have {b : β | a' < g b} ∈ b, from (tendsto_orderable.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have {b : β | h b < a'} ∈ b, from (tendsto_orderable.1 hh).right a' h',
by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩
lemma nhds_orderable_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
nhds a = (⨅l (h₂ : l < a) u (h₂ : a < u), principal {x | l < x ∧ x < u }) :=
let ⟨u, hu⟩ := hu, ⟨l, hl⟩ := hl in
calc nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) : nhds_eq_orderable
... = (⨅b<a, principal {c | b < c} ⊓ (⨅b>a, principal {c | c < b})) :
binfi_inf hl
... = (⨅l<a, (⨅u>a, principal {c | c < u} ⊓ principal {c | l < c})) :
begin
congr, funext x,
congr, funext hx,
rw [inf_comm],
apply binfi_inf hu
end
... = _ : by simp [inter_comm]; refl
lemma tendsto_orderable_unbounded {f : β → α} {a : α} {x : filter β}
(hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → {b | l < f b ∧ f b < u } ∈ x) :
tendsto f x (nhds a) :=
by rw [nhds_orderable_unbounded hu hl];
from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl,
tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu)
end partial_order
theorem induced_orderable_topology' {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b)
(H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) :
@orderable_topology _ (induced f ta) _ :=
begin
letI := induced f ta,
refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩,
rw [nhds_induced, nhds_generate_from, @nhds_eq_orderable β _ _],
apply le_antisymm,
{ refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _),
rcases hs with ⟨ab, b, rfl|rfl⟩,
{ exact mem_comap_sets.2 ⟨{x | f b < x},
mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ },
{ exact mem_comap_sets.2 ⟨{x | x < f b},
mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ } },
{ rw [← map_le_iff_le_comap],
refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp,
{ rcases H₁ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) },
{ rcases H₂ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } },
end
theorem induced_orderable_topology {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) :
@orderable_topology _ (induced f ta) _ :=
induced_orderable_topology' f @hf
(λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩)
(λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩)
lemma nhds_top_orderable [topological_space α] [order_top α] [orderable_topology α] :
nhds (⊤:α) = (⨅l (h₂ : l < ⊤), principal {x | l < x}) :=
by rw [@nhds_eq_orderable α _ _]; simp [(>)]
lemma nhds_bot_orderable [topological_space α] [order_bot α] [orderable_topology α] :
nhds (⊥:α) = (⨅l (h₂ : ⊥ < l), principal {x | x < l}) :=
by rw [@nhds_eq_orderable α _ _]; simp
section linear_order
variables [topological_space α] [linear_order α] [t : orderable_topology α]
include t
lemma mem_nhds_orderable_dest {a : α} {s : set α} (hs : s ∈ nhds a) :
((∃u, u>a) → ∃u, a < u ∧ ∀b, a ≤ b → b < u → b ∈ s) ∧
((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ≤ a → b ∈ s) :=
let ⟨t₁, ht₁, t₂, ht₂, hts⟩ :=
mem_inf_sets.mp $ by rw [@nhds_eq_orderable α _ _ _] at hs; exact hs in
have ht₁ : ((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ∈ t₁) ∧ (∀b, a ≤ b → b ∈ t₁),
from infi_sets_induct ht₁
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' < a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨max u a', max_lt hu₁ h, assume b hb,
⟨hs₁ $ lt_of_le_of_lt (le_max_right _ _) hb,
hu₂ _ $ lt_of_le_of_lt (le_max_left _ _) hb⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_lt_of_le h hb, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
have ht₂ : ((∃u, u>a) → ∃u, a < u ∧ ∀b, b < u → b ∈ t₂) ∧ (∀b, b ≤ a → b ∈ t₂),
from infi_sets_induct ht₂
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' > a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨min u a', lt_min hu₁ h, assume b hb,
⟨hs₁ $ lt_of_lt_of_le hb (min_le_right _ _),
hu₂ _ $ lt_of_lt_of_le hb (min_le_left _ _)⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_le_of_lt hb h, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
and.intro
(assume hx, let ⟨u, hu, h⟩ := ht₂.left hx in ⟨u, hu, assume b hb hbu, hts ⟨ht₁.right b hb, h _ hbu⟩⟩)
(assume hx, let ⟨l, hl, h⟩ := ht₁.left hx in ⟨l, hl, assume b hbl hb, hts ⟨h _ hbl, ht₂.right b hb⟩⟩)
lemma mem_nhds_unbounded {a : α} {s : set α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
s ∈ nhds a ↔ (∃l u, l < a ∧ a < u ∧ ∀b, l < b → b < u → b ∈ s) :=
let ⟨l, hl'⟩ := hl, ⟨u, hu'⟩ := hu in
have nhds a = (⨅p : {l // l < a} × {u // a < u}, principal {x | p.1.val < x ∧ x < p.2.val }),
by simp [nhds_orderable_unbounded hu hl, infi_subtype, infi_prod],
iff.intro
(assume hs, by rw [this] at hs; from infi_sets_induct hs
⟨l, u, hl', hu', by simp⟩
begin
intro p, rcases p with ⟨⟨l, hl⟩, ⟨u, hu⟩⟩,
simp [set.subset_def],
intros s₁ s₂ hs₁ l' hl' u' hu' hs₂,
letI := classical.DLO α,
refine ⟨max l l', _, min u u', _⟩;
simp [*, lt_min_iff, max_lt_iff] {contextual := tt}
end
(assume s₁ s₂ h ⟨l, u, h₁, h₂, h₃⟩, ⟨l, u, h₁, h₂, assume b hu hl, h $ h₃ _ hu hl⟩))
(assume ⟨l, u, hl, hu, h⟩,
by rw [this]; exact mem_infi_sets ⟨⟨l, hl⟩, ⟨u, hu⟩⟩ (assume b ⟨h₁, h₂⟩, h b h₁ h₂))
lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) :
∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) :=
match dense_or_discrete a₁ a₂ with
| or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂,
assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h,
assume b₁ hb₁ b₂ hb₂,
calc b₁ ≤ a₁ : h₂ _ hb₁
... < a₂ : h
... ≤ b₂ : h₁ _ hb₂⟩
end
instance orderable_topology.to_ordered_topology : ordered_topology α :=
{ is_closed_le' :=
is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂),
have h : a₂ < a₁, from lt_of_not_ge h,
let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in
⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ }
instance orderable_topology.t2_space : t2_space α := by apply_instance
instance orderable_topology.regular_space : regular_space α :=
{ regular := assume s a hs ha,
have -s ∈ nhds a, from mem_nhds_sets hs ha,
let ⟨h₁, h₂⟩ := mem_nhds_orderable_dest this in
have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃l, l < a,
let ⟨l, hl, h⟩ := h₂ h in
match dense_or_discrete l a with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _,
assume c hcs hca, show c < b,
from lt_of_not_ge $ assume hbc, h c (lt_of_lt_of_le hb₁ hbc) (le_of_lt hca) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hb₂) $
assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $
assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩
end)
(assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in
have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃u, u > a,
let ⟨u, hu, h⟩ := h₁ h in
match dense_or_discrete a u with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _,
assume c hcs hca, show c > b,
from lt_of_not_ge $ assume hbc, h c (le_of_lt hca) (lt_of_le_of_lt hbc hb₂) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hb₁) $
assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $
assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩
end)
(assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in
⟨t₁ ∪ t₂, is_open_union ht₁o ht₂o,
assume x hx,
have x ≠ a, from assume eq, ha $ eq ▸ hx,
(ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx),
by rw [←sup_principal, inf_sup_left, ht₁a, ht₂a, bot_sup_eq]⟩,
..orderable_topology.t2_space }
end linear_order
lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) :=
(image_eq_preimage_of_inverse neg_neg neg_neg).symm
lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) :=
funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg)
section topological_add_group
variables [topological_space α] [ordered_comm_group α] [topological_add_group α]
lemma neg_preimage_closure {s : set α} : (λr:α, -r) ⁻¹' closure s = closure ((λr:α, -r) '' s) :=
have (λr:α, -r) ∘ (λr:α, -r) = id, from funext neg_neg,
by rw [preimage_neg]; exact
(subset.antisymm (image_closure_subset_closure_image continuous_neg') $
calc closure ((λ (r : α), -r) '' s) = (λr, -r) '' ((λr, -r) '' closure ((λ (r : α), -r) '' s)) :
by rw [←image_comp, this, image_id]
... ⊆ (λr, -r) '' closure ((λr, -r) '' ((λ (r : α), -r) '' s)) :
mono_image $ image_closure_subset_closure_image continuous_neg'
... = _ : by rw [←image_comp, this, image_id])
end topological_add_group
section order_topology
variables [topological_space α] [topological_space β]
[linear_order α] [linear_order β] [orderable_topology α] [orderable_topology β]
lemma nhds_principal_ne_bot_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) :
nhds a ⊓ principal s ≠ ⊥ :=
let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in
forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht,
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in
let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in
by_cases
(assume h : a = a',
have a ∈ t₁, from mem_of_nhds ht₁,
have a ∈ t₂, from ht₂ $ by rwa [h],
ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩)
(assume : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this.symm,
let ⟨l, hl, hlt₁⟩ := hl ⟨a', this⟩ in
have ∃a'∈s, l < a',
from classical.by_contradiction $ assume : ¬ ∃a'∈s, l < a',
have ∀a'∈s, a' ≤ l, from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩,
have ¬ l < a, from not_lt.2 $ ha.right _ this,
this ‹l < a›,
let ⟨a', ha', ha'l⟩ := this in
have a' ∈ t₁, from hlt₁ _ ‹l < a'› $ ha.left _ ha',
ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩)
lemma nhds_principal_ne_bot_of_is_glb : ∀ {a : α} {s : set α}, is_glb s a → s ≠ ∅ →
nhds a ⊓ principal s ≠ ⊥ :=
@nhds_principal_ne_bot_of_is_lub (order_dual α) _ _ _
lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α}
(hsa : a ∈ upper_bounds s) (hsf : s ∈ f) (hfa : f ⊓ nhds a ≠ ⊥) : is_lub s a :=
⟨hsa, assume b hb,
not_lt.1 $ assume hba,
have s ∩ {a | b < a} ∈ f ⊓ nhds a,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in
have b < b, from lt_of_lt_of_le hxb $ hb _ hxs,
lt_irrefl b this⟩
lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α},
a ∈ lower_bounds s → s ∈ f → f ⊓ nhds a ≠ ⊥ → is_glb s a :=
@is_lub_of_mem_nhds (order_dual α) _ _ _
lemma is_lub_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s ≠ ∅)
(hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_lub (f '' s) b :=
have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs,
have ∀a'∈s, ¬ b < f a',
from assume a' ha' h,
have {x | x < f a'} ∈ nhds b, from mem_nhds_sets (is_open_gt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a < f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm,
have {x | a' < x} ∈ nhds a, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} ∩ t₁ ∈ nhds a, from inter_mem_sets this ht₁,
have ({x | a' < x} ∩ t₁) ∩ s ∈ nhds a ⊓ principal s,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in
have hxa' : f x < f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≤ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁,
lt_irrefl _ (lt_of_le_of_lt ha'x hxa')),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot hb $
mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx)
lemma is_glb_of_is_glb_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ f s a b
(λ x hx y hy, hf y hy x hx)
lemma is_glb_of_is_lub_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma is_lub_of_is_glb_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_lub (f '' s) b :=
@is_glb_of_is_glb_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma mem_closure_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) : a ∈ closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_lub ha hs
lemma mem_of_is_lub_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) (sc : is_closed s) : a ∈ s :=
by rw ←closure_eq_of_is_closed sc; exact mem_closure_of_is_lub ha hs
lemma mem_closure_of_is_glb {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) : a ∈ closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_glb ha hs
lemma mem_of_is_glb_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) (sc : is_closed s) : a ∈ s :=
by rw ←closure_eq_of_is_closed sc; exact mem_closure_of_is_glb ha hs
/-- A compact set is bounded below -/
lemma bdd_below_of_compact {α : Type u} [topological_space α] [linear_order α]
[ordered_topology α] [nonempty α] {s : set α} (hs : compact s) : bdd_below s :=
begin
by_contra H,
letI := classical.DLO α,
rcases @compact_elim_finite_subcover_image α _ _ _ s (λ x, {b | x < b}) hs
(λ x _, is_open_lt continuous_const continuous_id) _ with ⟨t, st, ft, ht⟩,
{ refine H ((bdd_below_finite ft).imp $ λ C hC y hy, _),
rcases mem_bUnion_iff.1 (ht hy) with ⟨x, hx, xy⟩,
exact le_trans (hC _ hx) (le_of_lt xy) },
{ refine λ x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H),
exact λ h, ⟨x, λ y hy, le_of_not_lt (h.imp $ λ ys, ⟨_, hy, ys⟩)⟩ }
end
/-- A compact set is bounded above -/
lemma bdd_above_of_compact {α : Type u} [topological_space α] [linear_order α]
[orderable_topology α] : Π [nonempty α] {s : set α}, compact s → bdd_above s :=
@bdd_below_of_compact (order_dual α) _ _ _
end order_topology
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [orderable_topology α]
[complete_linear_order β] [topological_space β] [orderable_topology β] [nonempty γ]
lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) : Sup s ∈ closure s :=
mem_closure_of_is_lub is_lub_Sup hs
lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) : Inf s ∈ closure s :=
mem_closure_of_is_glb is_glb_Inf hs
lemma Sup_mem_of_is_closed {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) : Sup s ∈ s :=
mem_of_is_lub_of_is_closed is_lub_Sup hs hc
lemma Inf_mem_of_is_closed {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) : Inf s ∈ s :=
mem_of_is_glb_of_is_closed is_glb_Inf hs hc
/-- A continuous monotone function sends supremum to supremum for nonempty sets. -/
lemma Sup_of_continuous' {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (hs : s ≠ ∅) : f (Sup s) = Sup (f '' s) :=
--This is a particular case of the more general is_lub_of_is_lub_of_tendsto
(is_lub_iff_Sup_eq.1
(is_lub_of_is_lub_of_tendsto (λ x hx y hy xy, Cf xy) is_lub_Sup hs $
tendsto_le_left inf_le_left (continuous.tendsto Mf _))).symm
/-- A continuous monotone function sending bot to bot sends supremum to supremum. -/
lemma Sup_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
(fbot : f ⊥ = ⊥) {s : set α} : f (Sup s) = Sup (f '' s) :=
begin
by_cases (s = ∅),
{ simpa [h] },
{ exact Sup_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed supremum to indexed supremum. -/
lemma supr_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) : f (supr g) = supr (f ∘ g) :=
by rw [supr, Sup_of_continuous' Mf Cf
(λ h, range_eq_empty.1 h ‹_›), ← range_comp]; refl
/-- A continuous monotone function sends infimum to infimum for nonempty sets. -/
lemma Inf_of_continuous' {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (hs : s ≠ ∅) : f (Inf s) = Inf (f '' s) :=
(is_glb_iff_Inf_eq.1
(is_glb_of_is_glb_of_tendsto (λ x hx y hy xy, Cf xy) is_glb_Inf hs $
tendsto_le_left inf_le_left (continuous.tendsto Mf _))).symm
/-- A continuous monotone function sending top to top sends infimum to infimum. -/
lemma Inf_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
(ftop : f ⊤ = ⊤) {s : set α} : f (Inf s) = Inf (f '' s) :=
begin
by_cases (s = ∅),
{ simpa [h] },
{ exact Inf_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed infimum to indexed infimum. -/
lemma infi_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) : f (infi g) = infi (f ∘ g) :=
by rw [infi, Inf_of_continuous' Mf Cf
(λ h, range_eq_empty.1 h ‹_›), ← range_comp]; refl
end complete_linear_order
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [topological_space α] [orderable_topology α]
[conditionally_complete_linear_order β] [topological_space β] [orderable_topology β] [nonempty γ]
lemma cSup_mem_closure {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (B : bdd_above s) : Sup s ∈ closure s :=
mem_closure_of_is_lub (is_lub_cSup hs B) hs
lemma cInf_mem_closure {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (B : bdd_below s) : Inf s ∈ closure s :=
mem_closure_of_is_glb (is_glb_cInf hs B) hs
lemma cSup_mem_of_is_closed {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) (B : bdd_above s) : Sup s ∈ s :=
mem_of_is_lub_of_is_closed (is_lub_cSup hs B) hs hc
lemma cInf_mem_of_is_closed {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) (B : bdd_below s) : Inf s ∈ s :=
mem_of_is_glb_of_is_closed (is_glb_cInf hs B) hs hc
/-- A continuous monotone function sends supremum to supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cSup_of_cSup_of_monotone_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (ne : s ≠ ∅) (H : bdd_above s) : f (Sup s) = Sup (f '' s) :=
begin
refine (is_lub_iff_eq_of_is_lub _).1
(is_lub_cSup (mt image_eq_empty.1 ne) (bdd_above_of_bdd_above_of_monotone Cf H)),
refine is_lub_of_is_lub_of_tendsto (λx hx y hy xy, Cf xy) (is_lub_cSup ne H) ne _,
exact tendsto_le_left inf_le_left (continuous.tendsto Mf _)
end
/-- A continuous monotone function sends indexed supremum to indexed supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma csupr_of_csupr_of_monotone_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) (H : bdd_above (range g)) : f (supr g) = supr (f ∘ g) :=
by rw [supr, cSup_of_cSup_of_monotone_of_continuous Mf Cf
(λ h, range_eq_empty.1 h ‹_›) H, ← range_comp]; refl
/-- A continuous monotone function sends infimum to infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cInf_of_cInf_of_monotone_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (ne : s ≠ ∅) (H : bdd_below s) : f (Inf s) = Inf (f '' s) :=
begin
refine (is_glb_iff_eq_of_is_glb _).1
(is_glb_cInf (mt image_eq_empty.1 ne) (bdd_below_of_bdd_below_of_monotone Cf H)),
refine is_glb_of_is_glb_of_tendsto (λx hx y hy xy, Cf xy) (is_glb_cInf ne H) ne _,
exact tendsto_le_left inf_le_left (continuous.tendsto Mf _)
end
/-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cinfi_of_cinfi_of_monotone_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) (H : bdd_below (range g)) : f (infi g) = infi (f ∘ g) :=
by rw [infi, cInf_of_cInf_of_monotone_of_continuous Mf Cf
(λ h, range_eq_empty.1 h ‹_›) H, ← range_comp]; refl
/-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/
lemma exists_forall_le_of_compact_of_continuous {α : Type u} [topological_space α]
(f : α → β) (hf : continuous f) (s : set α) (hs : compact s) (ne_s : s ≠ ∅) :
∃x∈s, ∀y∈s, f x ≤ f y :=
begin
have C : compact (f '' s) := compact_image hs hf,
haveI := has_Inf_to_nonempty β,
have B : bdd_below (f '' s) := bdd_below_of_compact C,
have : Inf (f '' s) ∈ f '' s :=
cInf_mem_of_is_closed (mt image_eq_empty.1 ne_s) (closed_of_compact _ C) B,
rcases (mem_image _ _ _).1 this with ⟨x, xs, hx⟩,
exact ⟨x, xs, λ y hy, hx.symm ▸ cInf_le B ⟨_, hy, rfl⟩⟩
end
/-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/
lemma exists_forall_ge_of_compact_of_continuous {α : Type u} [topological_space α] :
∀ f : α → β, continuous f → ∀ s : set α, compact s → s ≠ ∅ →
∃x∈s, ∀y∈s, f y ≤ f x :=
@exists_forall_le_of_compact_of_continuous (order_dual β) _ _ _ _ _
end conditionally_complete_linear_order
section liminf_limsup
section ordered_topology
variables [semilattice_sup α] [topological_space α] [orderable_topology α]
lemma is_bounded_le_nhds (a : α) : (nhds a).is_bounded (≤) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := ⟨a, show {x : α | x ≤ a} ∈ nhds a, from univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩
end
lemma is_bounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≤) u :=
is_bounded_of_le h (is_bounded_le_nhds a)
lemma is_cobounded_ge_nhds (a : α) : (nhds a).is_cobounded (≥) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_le_nhds a)
lemma is_cobounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≥) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_le_of_tendsto h)
end ordered_topology
section ordered_topology
variables [semilattice_inf α] [topological_space α] [orderable_topology α]
lemma is_bounded_ge_nhds (a : α) : (nhds a).is_bounded (≥) :=
match forall_le_or_exists_lt_inf a with
| or.inl h := ⟨a, show {x : α | a ≤ x} ∈ nhds a, from univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, le_mem_nhds hb⟩
end
lemma is_bounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≥) u :=
is_bounded_of_le h (is_bounded_ge_nhds a)
lemma is_cobounded_le_nhds (a : α) : (nhds a).is_cobounded (≤) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_ge_nhds a)
lemma is_cobounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≤) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_ge_of_tendsto h)
end ordered_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α]
theorem lt_mem_sets_of_Limsup_lt {f : filter α} {b} (h : f.is_bounded (≤)) (l : f.Limsup < b) :
{a | a < b} ∈ f :=
let ⟨c, (h : {a : α | a ≤ c} ∈ f), hcb⟩ :=
exists_lt_of_cInf_lt (ne_empty_iff_exists_mem.2 h) l in
mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
theorem gt_mem_sets_of_Liminf_gt : ∀ {f : filter α} {b}, f.is_bounded (≥) → f.Liminf > b →
{a | a > b} ∈ f :=
@lt_mem_sets_of_Limsup_lt (order_dual α) _
variables [topological_space α] [orderable_topology α]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_Limsup_eq_Liminf {f : filter α} {a : α}
(hl : f.is_bounded (≤)) (hg : f.is_bounded (≥)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f ≤ nhds a :=
tendsto_orderable.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm ▸ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm ▸ hb)
theorem Limsup_nhds (a : α) : Limsup (nhds a) = a :=
cInf_intro (ne_empty_iff_exists_mem.2 $ is_bounded_le_nhds a)
(assume a' (h : {n : α | n ≤ a'} ∈ nhds a), show a ≤ a', from @mem_of_nhds α _ a _ h)
(assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ nhds a), c < b, from
match dense_or_discrete a b with
| or.inl ⟨c, hac, hcb⟩ := ⟨c, ge_mem_nhds hac, hcb⟩
| or.inr ⟨_, h⟩ := ⟨a, (nhds a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
end)
theorem Liminf_nhds : ∀ (a : α), Liminf (nhds a) = a :=
@Limsup_nhds (order_dual α) _ _ _
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Liminf = a :=
have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a),
have hb_le : is_bounded (≤) f, from is_bounded_of_le h (is_bounded_le_nhds a),
le_antisymm
(calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hf hb_le hb_ge
... ≤ (nhds a).Limsup :
Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (nhds a).Liminf : (Liminf_nhds a).symm
... ≤ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) (is_cobounded_of_is_bounded hf hb_le))
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : ∀ {f : filter α} {a : α}, f ≠ ⊥ → f ≤ nhds a → f.Limsup = a :=
@Liminf_eq_of_le_nhds (order_dual α) _ _ _
end conditionally_complete_linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [orderable_topology α]
-- In complete_linear_order, the above theorems take a simpler form
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value -/
theorem tendsto_of_liminf_eq_limsup {f : filter β} {u : β → α} {a : α}
(h : liminf f u = a ∧ limsup f u = a) : tendsto u f (nhds a) :=
le_nhds_of_Limsup_eq_Liminf is_bounded_le_of_top is_bounded_ge_of_bot h.2 h.1
/-- If a function has a limit, then its limsup coincides with its limit-/
theorem limsup_eq_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥)
(h : tendsto u f (nhds a)) : limsup f u = a :=
Limsup_eq_of_le_nhds (map_ne_bot hf) h
/-- If a function has a limit, then its liminf coincides with its limit-/
theorem liminf_eq_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥)
(h : tendsto u f (nhds a)) : liminf f u = a :=
Liminf_eq_of_le_nhds (map_ne_bot hf) h
end complete_linear_order
end liminf_limsup
end orderable_topology
lemma orderable_topology_of_nhds_abs
{α : Type*} [decidable_linear_ordered_comm_group α] [topological_space α]
(h_nhds : ∀a:α, nhds a = (⨅r>0, principal {b | abs (a - b) < r})) : orderable_topology α :=
orderable_topology.mk $ eq_of_nhds_eq_nhds $ assume a:α, le_antisymm_iff.mpr
begin
simp [infi_and, topological_space.nhds_generate_from,
h_nhds, le_infi_iff, -le_principal_iff, and_comm],
refine ⟨λ s ha b hs, _, λ r hr, _⟩,
{ rcases hs with rfl | rfl,
{ refine infi_le_of_le (a - b)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _),
have : a - c < a - b := lt_of_le_of_lt (le_abs_self _) hc,
exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) },
{ refine infi_le_of_le (b - a)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _),
have : abs (c - a) < b - a, {rw abs_sub; simpa using hc},
have : c - a < b - a := lt_of_le_of_lt (le_abs_self _) this,
exact lt_of_add_lt_add_right this } },
{ have h : {b | abs (a + -b) < r} = {b | a - r < b} ∩ {b | b < a + r},
from set.ext (assume b,
by simp [abs_lt, -sub_eq_add_neg, (sub_eq_add_neg _ _).symm,
sub_lt, lt_sub_iff_add_lt, and_comm, sub_lt_iff_lt_add']),
rw [h, ← inf_principal],
apply le_inf _ _,
{ exact infi_le_of_le {b : α | a - r < b} (infi_le_of_le (sub_lt_self a hr) $
infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) },
{ exact infi_le_of_le {b : α | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $
infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } }
end
lemma tendsto_at_top_supr_nat [topological_space α] [complete_linear_order α] [orderable_topology α]
(f : ℕ → α) (hf : monotone f) : tendsto f at_top (nhds (⨆i, f i)) :=
tendsto_orderable.2 $ and.intro
(assume a ha, let ⟨n, hn⟩ := lt_supr_iff.1 ha in
mem_at_top_sets.2 ⟨n, assume i hi, lt_of_lt_of_le hn (hf hi)⟩)
(assume a ha, univ_mem_sets' (assume n, lt_of_le_of_lt (le_supr _ n) ha))
lemma tendsto_at_top_infi_nat [topological_space α] [complete_linear_order α] [orderable_topology α]
(f : ℕ → α) (hf : ∀{n m}, n ≤ m → f m ≤ f n) : tendsto f at_top (nhds (⨅i, f i)) :=
@tendsto_at_top_supr_nat (order_dual α) _ _ _ _ @hf
lemma supr_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [orderable_topology α]
{f : ℕ → α} {a : α} (hf : monotone f) : tendsto f at_top (nhds a) → supr f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_supr_nat f hf)
lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [orderable_topology α]
{f : ℕ → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) : tendsto f at_top (nhds a) → infi f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_infi_nat f hf)
|
44889438f3f765c629eb3927e5a8e2b56cdb6ddf | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/nested_match_bug.lean | 119c6e34fad5f7d1326f9adae8e854c332b9626a | [
"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 | 388 | lean | new_frontend
inductive Term : Type
| app : List Term -> Term
namespace Term
instance : Inhabited Term := ⟨app []⟩
partial def transform (f : Term -> Option Term) : Term -> Term
| t =>
match f t with
| some u => transform f u
| none =>
match t with
| app args =>
let newArgs := args.map (fun arg => transform f arg);
transform f (app newArgs)
end Term
|
7e53f70c2c1c1cd8936265e0f823012a1aedcc4e | 2272e503179a58556187901b8698b789fad7e0c4 | /src/basic.lean | b689d31b7bfb719f44a71975529eeec1079cac87 | [] | no_license | kckennylau/category-theory | f15e582be862379453a5341d83b8cd5ebc686729 | b24962838c7370b5257e38b7648040aec95922bb | refs/heads/master | 1,583,605,043,449 | 1,525,154,882,000 | 1,525,154,882,000 | 127,633,452 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,413 | lean | import algebra.group
import analysis.topology.continuity
import linear_algebra.linear_map_module
import algebra.group_power
universes u v w u₁ v₁ w₁ u₂ v₂ w₂
structure category (α : Type u) : Type (max u v + 1) :=
(Mor : Π x y : α, Type v)
(Comp : Π x y z, Mor y z → Mor x y → Mor x z)
(Id : Π x, Mor x x)
(Hid_left : ∀ x y (f : Mor x y), Comp _ _ _ (Id _) f = f)
(Hid_right : ∀ x y (f : Mor x y), Comp _ _ _ f (Id _) = f)
(Hassoc : ∀ x y z w (f : Mor z w) (g : Mor y z) (h : Mor x y), Comp _ _ _ (Comp _ _ _ f g) h = Comp _ _ _ f (Comp _ _ _ g h))
namespace category
@[reducible] def dual {α : Type u} (C : category α) : category α :=
{ Mor := λ x y, C.Mor y x,
Comp := λ x y z f g, C.Comp z y x g f,
Id := C.Id,
Hid_left := λ x y, C.Hid_right y x,
Hid_right := λ x y, C.Hid_left y x,
Hassoc := λ x y z w f g h, eq.symm $ C.Hassoc w z y x h g f }
@[reducible] def discrete (α : Type u) : category α :=
{ Mor := λ x y, plift $ x = y,
Comp := λ x y z hyz hxy, plift.up $ eq.trans hxy.down hyz.down,
Id := λ x, plift.up $ eq.refl x,
Hid_left := λ x y hxy, by cases hxy; refl,
Hid_right := λ x y hxy, by cases hxy; refl,
Hassoc := λ _ _ _ _ _ _ _, rfl }
namespace cone
variables {α : Type u} (C : category.{u v} α)
@[reducible] def Mor : option α → option α → Type v
| none y := punit
| _ none := ulift empty
| (some x) (some y) := C.Mor x y
@[reducible] def Comp : Π x y z, Mor C y z → Mor C x y → Mor C x z
| none none _ f _ := f
| none _ (some z) _ _ := punit.star
| (some x) (some y) (some z) f g := C.Comp x y z f g
@[reducible] def Id : Π x, Mor C x x
| none := punit.star
| (some x) := C.Id x
@[reducible] def Hid_left : ∀ x y f, Comp C x y y (Id C y) f = f
| none y f := by cases y; cases f; refl
| (some x) (some y) f := C.Hid_left x y f
@[reducible] def Hid_right : ∀ x y f, Comp C x x y f (Id C x) = f
| none y f := by cases y; cases f; refl
| (some x) (some y) f := C.Hid_right x y f
@[reducible] def Hassoc : ∀ x y z w f g h, Comp C x y w (Comp C y z w f g) h = Comp C x z w f (Comp C x y z g h)
| none none z w f g h := by cases z; cases w; refl
| none (some y) (some z) (some w) f g h := rfl
| (some x) (some y) (some z) (some w) f g h := C.Hassoc x y z w f g h
end cone
@[reducible] def cone {α : Type u} (C : category α) : category (option α) :=
{ Mor := cone.Mor C,
Comp := cone.Comp C,
Id := cone.Id C,
Hid_left := cone.Hid_left C,
Hid_right := cone.Hid_right C,
Hassoc := cone.Hassoc C }
structure functor {α β} (C : category.{u v} α) (D : category.{u₁ v₁} β) :=
(F : α → β)
(mor : Π x y, C.Mor x y → D.Mor (F x) (F y))
(Hid : ∀ x, mor x x (C.Id x) = D.Id (F x))
(Hcomp : ∀ x y z f g, D.Comp (F x) (F y) (F z) (mor y z f) (mor x y g) = mor x z (C.Comp x y z f g))
namespace functor
variables {α : Type u} (C : category.{u v} α)
variables {β : Type u₁} (D : category.{u₁ v₁} β)
variables {γ : Type u₂} (E : category.{u₂ v₂} γ)
@[reducible] def id : functor C C :=
{ F := id,
mor := λ x y, id,
Hid := λ x, rfl,
Hcomp := λ x y z f g, rfl }
@[reducible] def comp (F : functor D E) (G : functor C D) : functor C E :=
{ F := F.F ∘ G.F,
mor := λ x y, F.mor (G.F x) (G.F y) ∘ G.mor x y,
Hid := λ x, by simp [G.Hid, F.Hid],
Hcomp := λ x y z f g, by simp [G.Hcomp, F.Hcomp] }
end functor
structure natural_transformation {α β} (C : category.{u v} α) (D : category.{u₁ v₁} β) (F G : functor C D) :=
(mor : Π x : α, D.Mor (F.F x) (G.F x))
(Hcomp : ∀ x y f, D.Comp _ _ _ (mor y) (F.mor _ _ f) = D.Comp _ _ _ (G.mor _ _ f) (mor x))
namespace natural_transformation
@[reducible] def id {α β} (C : category.{u v} α) (D : category.{u₁ v₁} β) (F : functor C D) :
natural_transformation C D F F :=
{ mor := λ x, D.Id _,
Hcomp := λ x y f, (D.Hid_left _ _ _).trans (D.Hid_right _ _ _).symm }
@[reducible] def comp {α β} (C : category.{u v} α) (D : category.{u₁ v₁} β) (F G H : functor C D)
(gh : natural_transformation C D G H)
(fg : natural_transformation C D F G) : natural_transformation C D F H :=
{ mor := λ x, D.Comp _ _ _ (gh.mor x) (fg.mor x),
Hcomp := λ x y f, by rw [D.Hassoc, fg.Hcomp, ← D.Hassoc, gh.Hcomp, D.Hassoc] }
end natural_transformation
end category
|
f5365a0c5ef69be49d2d66e7e6ff6e3fbae9b04a | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/field_theory/is_alg_closed/classification.lean | 029f99b900334ea657ef8cd743dc3fef7f1a731f | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 8,517 | lean | /-
Copyright (c) 2022 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.W.cardinal
import ring_theory.algebraic_independent
import field_theory.is_alg_closed.basic
import field_theory.intermediate_field
import data.polynomial.cardinal
import data.mv_polynomial.cardinal
import data.zmod.algebra
/-!
# Classification of Algebraically closed fields
This file contains results related to classifying algebraically closed fields.
## Main statements
* `is_alg_closed.equiv_of_transcendence_basis` Two fields with the same characteristic and the same
cardinality of transcendence basis are isomorphic.
* `is_alg_closed.ring_equiv_of_cardinal_eq_of_char_eq` Two uncountable algebraically closed fields
are isomorphic if they have the same characteristic and the same cardinality.
-/
universe u
open_locale cardinal polynomial
open cardinal
section algebraic_closure
namespace algebra.is_algebraic
variables (R L : Type u) [comm_ring R] [comm_ring L] [is_domain L] [algebra R L]
variables [no_zero_smul_divisors R L] (halg : algebra.is_algebraic R L)
lemma cardinal_mk_le_sigma_polynomial :
#L ≤ #(Σ p : R[X], { x : L // x ∈ (p.map (algebra_map R L)).roots }) :=
@mk_le_of_injective L (Σ p : R[X], { x : L | x ∈ (p.map (algebra_map R L)).roots })
(λ x : L, let p := classical.indefinite_description _ (halg x) in
⟨p.1, x,
begin
dsimp,
have h : p.1.map (algebra_map R L) ≠ 0,
{ rw [ne.def, ← polynomial.degree_eq_bot, polynomial.degree_map_eq_of_injective
(no_zero_smul_divisors.algebra_map_injective R L), polynomial.degree_eq_bot],
exact p.2.1 },
erw [polynomial.mem_roots h, polynomial.is_root, polynomial.eval_map,
← polynomial.aeval_def, p.2.2],
end⟩) (λ x y, begin
intro h,
simp only at h,
refine (subtype.heq_iff_coe_eq _).1 h.2,
simp only [h.1, iff_self, forall_true_iff]
end)
/--The cardinality of an algebraic extension is at most the maximum of the cardinality
of the base ring or `ℵ₀` -/
lemma cardinal_mk_le_max : #L ≤ max (#R) ℵ₀ :=
calc #L ≤ #(Σ p : R[X], { x : L // x ∈ (p.map (algebra_map R L)).roots }) :
cardinal_mk_le_sigma_polynomial R L halg
... = cardinal.sum (λ p : R[X], #{ x : L | x ∈ (p.map (algebra_map R L)).roots }) :
by rw ← mk_sigma; refl
... ≤ cardinal.sum.{u u} (λ p : R[X], ℵ₀) :
sum_le_sum _ _ $ λ p, (multiset.finite_to_set _).lt_aleph_0.le
... = #R[X] * ℵ₀ : sum_const' _ _
... ≤ max (max (#R[X]) ℵ₀) ℵ₀ : mul_le_max _ _
... ≤ max (max (max (#R) ℵ₀) ℵ₀) ℵ₀ :
max_le_max (max_le_max polynomial.cardinal_mk_le_max le_rfl) le_rfl
... = max (#R) ℵ₀ : by simp only [max_assoc, max_comm ℵ₀, max_left_comm ℵ₀, max_self]
end algebra.is_algebraic
end algebraic_closure
namespace is_alg_closed
section classification
noncomputable theory
variables {R L K : Type*} [comm_ring R]
variables [field K] [algebra R K]
variables [field L] [algebra R L]
variables {ι : Type*} (v : ι → K)
variables {κ : Type*} (w : κ → L)
variables (hv : algebraic_independent R v)
lemma is_alg_closure_of_transcendence_basis [is_alg_closed K] (hv : is_transcendence_basis R v) :
is_alg_closure (algebra.adjoin R (set.range v)) K :=
by letI := ring_hom.domain_nontrivial (algebra_map R K); exact
{ alg_closed := by apply_instance,
algebraic := hv.is_algebraic }
variables (hw : algebraic_independent R w)
/-- setting `R` to be `zmod (ring_char R)` this result shows that if two algebraically
closed fields have equipotent transcendence bases and the same characteristic then they are
isomorphic. -/
def equiv_of_transcendence_basis [is_alg_closed K] [is_alg_closed L] (e : ι ≃ κ)
(hv : is_transcendence_basis R v) (hw : is_transcendence_basis R w) : K ≃+* L :=
begin
letI := is_alg_closure_of_transcendence_basis v hv;
letI := is_alg_closure_of_transcendence_basis w hw;
have e : algebra.adjoin R (set.range v) ≃+* algebra.adjoin R (set.range w),
{ refine hv.1.aeval_equiv.symm.to_ring_equiv.trans _,
refine (alg_equiv.of_alg_hom
(mv_polynomial.rename e)
(mv_polynomial.rename e.symm)
_ _).to_ring_equiv.trans _,
{ ext, simp },
{ ext, simp },
exact hw.1.aeval_equiv.to_ring_equiv },
exact is_alg_closure.equiv_of_equiv K L e
end
end classification
section cardinal
variables {R L K : Type u} [comm_ring R]
variables [field K] [algebra R K] [is_alg_closed K]
variables {ι : Type u} (v : ι → K)
variable (hv : is_transcendence_basis R v)
lemma cardinal_le_max_transcendence_basis (hv : is_transcendence_basis R v) :
#K ≤ max (max (#R) (#ι)) ℵ₀ :=
calc #K ≤ max (#(algebra.adjoin R (set.range v))) ℵ₀ :
by letI := is_alg_closure_of_transcendence_basis v hv;
exact algebra.is_algebraic.cardinal_mk_le_max _ _ is_alg_closure.algebraic
... = max (#(mv_polynomial ι R)) ℵ₀ : by rw [cardinal.eq.2 ⟨(hv.1.aeval_equiv).to_equiv⟩]
... ≤ max (max (max (#R) (#ι)) ℵ₀) ℵ₀ : max_le_max mv_polynomial.cardinal_mk_le_max le_rfl
... = _ : by simp [max_assoc]
/-- If `K` is an uncountable algebraically closed field, then its
cardinality is the same as that of a transcendence basis. -/
lemma cardinal_eq_cardinal_transcendence_basis_of_aleph_0_lt [nontrivial R]
(hv : is_transcendence_basis R v) (hR : #R ≤ ℵ₀) (hK : ℵ₀ < #K) : #K = #ι :=
have ℵ₀ ≤ #ι,
from le_of_not_lt (λ h,
not_le_of_gt hK $ calc
#K ≤ max (max (#R) (#ι)) ℵ₀ : cardinal_le_max_transcendence_basis v hv
... ≤ _ : max_le (max_le hR (le_of_lt h)) le_rfl),
le_antisymm
(calc #K ≤ max (max (#R) (#ι)) ℵ₀ : cardinal_le_max_transcendence_basis v hv
... = #ι : begin
rw [max_eq_left, max_eq_right],
{ exact le_trans hR this },
{ exact le_max_of_le_right this }
end)
(mk_le_of_injective (show function.injective v, from hv.1.injective))
end cardinal
variables {K L : Type} [field K] [field L] [is_alg_closed K] [is_alg_closed L]
/-- Two uncountable algebraically closed fields of characteristic zero are isomorphic
if they have the same cardinality. -/
@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_zero [char_zero K] [char_zero L]
(hK : ℵ₀ < #K) (hKL : #K = #L) : K ≃+* L :=
begin
apply classical.choice,
cases exists_is_transcendence_basis ℤ
(show function.injective (algebra_map ℤ K),
from int.cast_injective) with s hs,
cases exists_is_transcendence_basis ℤ
(show function.injective (algebra_map ℤ L),
from int.cast_injective) with t ht,
have : #s = #t,
{ rw [← cardinal_eq_cardinal_transcendence_basis_of_aleph_0_lt _ hs (le_of_eq mk_int) hK,
← cardinal_eq_cardinal_transcendence_basis_of_aleph_0_lt _ ht (le_of_eq mk_int), hKL],
rwa ← hKL },
cases cardinal.eq.1 this with e,
exact ⟨equiv_of_transcendence_basis _ _ e hs ht⟩
end
private lemma ring_equiv_of_cardinal_eq_of_char_p (p : ℕ) [fact p.prime]
[char_p K p] [char_p L p] (hK : ℵ₀ < #K) (hKL : #K = #L) : K ≃+* L :=
begin
apply classical.choice,
cases exists_is_transcendence_basis (zmod p)
(show function.injective (algebra_map (zmod p) K),
from ring_hom.injective _) with s hs,
cases exists_is_transcendence_basis (zmod p)
(show function.injective (algebra_map (zmod p) L),
from ring_hom.injective _) with t ht,
have : #s = #t,
{ rw [← cardinal_eq_cardinal_transcendence_basis_of_aleph_0_lt _ hs
(lt_aleph_0_of_finite (zmod p)).le hK,
← cardinal_eq_cardinal_transcendence_basis_of_aleph_0_lt _ ht
(lt_aleph_0_of_finite (zmod p)).le, hKL],
rwa ← hKL },
cases cardinal.eq.1 this with e,
exact ⟨equiv_of_transcendence_basis _ _ e hs ht⟩
end
/-- Two uncountable algebraically closed fields are isomorphic
if they have the same cardinality and the same characteristic. -/
@[nolint def_lemma] lemma ring_equiv_of_cardinal_eq_of_char_eq (p : ℕ) [char_p K p] [char_p L p]
(hK : ℵ₀ < #K) (hKL : #K = #L) : K ≃+* L :=
begin
apply classical.choice,
rcases char_p.char_is_prime_or_zero K p with hp | hp,
{ haveI : fact p.prime := ⟨hp⟩,
exact ⟨ring_equiv_of_cardinal_eq_of_char_p p hK hKL⟩ },
{ rw [hp] at *,
resetI,
letI : char_zero K := char_p.char_p_to_char_zero K,
letI : char_zero L := char_p.char_p_to_char_zero L,
exact ⟨ring_equiv_of_cardinal_eq_of_char_zero hK hKL⟩ }
end
end is_alg_closed
|
25092b9e71768f0d4cb9c477c53d70db50ef0120 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /stage0/src/Init/Lean/Elab/Log.lean | f6cbe1159d8be08397223c8ff7ee5c4f075f9218 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 2,771 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Elab.Util
import Init.Lean.Elab.Exception
namespace Lean
namespace Elab
class MonadPosInfo (m : Type → Type) :=
(getFileMap {} : m FileMap)
(getFileName {} : m String)
(getCmdPos {} : m String.Pos)
(addContext {} : MessageData → m MessageData)
export MonadPosInfo (getFileMap getFileName getCmdPos)
class MonadLog (m : Type → Type) extends MonadPosInfo m :=
(logMessage {} : Message → m Unit)
export MonadLog (logMessage)
variables {m : Type → Type} [Monad m]
def getPosition [MonadPosInfo m] (pos : Option String.Pos := none) : m Position := do
fileMap ← getFileMap;
cmdPos ← getCmdPos;
pure $ fileMap.toPosition (pos.getD cmdPos)
def mkMessageAt [MonadPosInfo m] (msgData : MessageData) (severity : MessageSeverity) (pos : Option String.Pos := none) : m Message := do
fileMap ← getFileMap;
fileName ← getFileName;
cmdPos ← getCmdPos;
let pos := fileMap.toPosition (pos.getD cmdPos);
msgData ← MonadPosInfo.addContext msgData;
pure { fileName := fileName, pos := pos, data := msgData, severity := severity }
def getPos [MonadPosInfo m] (stx : Syntax) : m String.Pos :=
match stx.getPos with
| some p => pure p
| none => getCmdPos
def mkMessage [MonadPosInfo m] (msgData : MessageData) (severity : MessageSeverity) (stx : Syntax) : m Message := do
pos ← getPos stx;
mkMessageAt msgData severity pos
def logAt [MonadLog m] (pos : String.Pos) (severity : MessageSeverity) (msgData : MessageData) : m Unit := do
msg ← mkMessageAt msgData severity pos;
logMessage msg
def logInfoAt [MonadLog m] (pos : String.Pos) (msgData : MessageData) : m Unit :=
logAt pos MessageSeverity.information msgData
def log [MonadLog m] (stx : Syntax) (severity : MessageSeverity) (msgData : MessageData) : m Unit := do
pos ← getPos stx;
logAt pos severity msgData
def logError [MonadLog m] (stx : Syntax) (msgData : MessageData) : m Unit :=
log stx MessageSeverity.error msgData
def logWarning [MonadLog m] (stx : Syntax) (msgData : MessageData) : m Unit :=
log stx MessageSeverity.warning msgData
def logInfo [MonadLog m] (stx : Syntax) (msgData : MessageData) : m Unit :=
log stx MessageSeverity.information msgData
def throwError {α} [MonadPosInfo m] [MonadExcept Exception m] (ref : Syntax) (msgData : MessageData) : m α := do
msg ← mkMessage msgData MessageSeverity.error ref; throw (Exception.error msg)
def throwErrorUsingCmdPos {α} [MonadPosInfo m] [MonadExcept Exception m] (msgData : MessageData) : m α := do
cmdPos ← getCmdPos;
msg ← mkMessageAt msgData MessageSeverity.error cmdPos;
throw (Exception.error msg)
end Elab
end Lean
|
a822028fbf53c2d0258942ba872168c962fffcd1 | 4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d | /src/Lean/Meta/Offset.lean | f58ac46369dda0244c37c0df336164fb763f3372 | [
"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 | 6,505 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.LBool
import Lean.Meta.InferType
import Lean.Meta.AppBuilder
namespace Lean.Meta
private abbrev withInstantiatedMVars (e : Expr) (k : Expr → OptionT MetaM α) : OptionT MetaM α := do
let eNew ← instantiateMVars e
if eNew.getAppFn.isMVar then
failure
else
k eNew
/--
Evaluate simple `Nat` expressions.
Remark: this method assumes the given expression has type `Nat`. -/
partial def evalNat : Expr → OptionT MetaM Nat
| Expr.lit (Literal.natVal n) _ => return n
| Expr.mdata _ e _ => evalNat e
| Expr.const `Nat.zero .. => return 0
| e@(Expr.app ..) => visit e
| e@(Expr.mvar ..) => visit e
| _ => failure
where
visit e := do
let f := e.getAppFn
match f with
| Expr.mvar .. => withInstantiatedMVars e evalNat
| Expr.const c _ _ =>
let nargs := e.getAppNumArgs
if c == ``Nat.succ && nargs == 1 then
let v ← evalNat (e.getArg! 0)
return v+1
else if c == ``Nat.add && nargs == 2 then
let v₁ ← evalNat (e.getArg! 0)
let v₂ ← evalNat (e.getArg! 1)
return v₁ + v₂
else if c == ``Nat.sub && nargs == 2 then
let v₁ ← evalNat (e.getArg! 0)
let v₂ ← evalNat (e.getArg! 1)
return v₁ - v₂
else if c == ``Nat.mul && nargs == 2 then
let v₁ ← evalNat (e.getArg! 0)
let v₂ ← evalNat (e.getArg! 1)
return v₁ * v₂
else if c == ``Add.add && nargs == 4 then
let v₁ ← evalNat (e.getArg! 2)
let v₂ ← evalNat (e.getArg! 3)
return v₁ + v₂
else if c == ``Sub.sub && nargs == 4 then
let v₁ ← evalNat (e.getArg! 2)
let v₂ ← evalNat (e.getArg! 3)
return v₁ - v₂
else if c == ``Mul.mul && nargs == 4 then
let v₁ ← evalNat (e.getArg! 2)
let v₂ ← evalNat (e.getArg! 3)
return v₁ * v₂
else if c == ``HAdd.hAdd && nargs == 6 then
let v₁ ← evalNat (e.getArg! 3)
let v₂ ← evalNat (e.getArg! 5)
return v₁ + v₂
else if c == ``HSub.hSub && nargs == 6 then
let v₁ ← evalNat (e.getArg! 4)
let v₂ ← evalNat (e.getArg! 5)
return v₁ - v₂
else if c == ``HMul.hMul && nargs == 6 then
let v₁ ← evalNat (e.getArg! 4)
let v₂ ← evalNat (e.getArg! 5)
return v₁ * v₂
else if c == ``OfNat.ofNat && nargs == 3 then
evalNat (e.getArg! 1)
else
failure
| _ => failure
/- Quick function for converting `e` into `s + k` s.t. `e` is definitionally equal to `Nat.add s k`. -/
private partial def getOffsetAux : Expr → Bool → OptionT MetaM (Expr × Nat)
| e@(Expr.app _ a _), top => do
let f := e.getAppFn
match f with
| Expr.mvar .. => withInstantiatedMVars e (getOffsetAux · top)
| Expr.const c _ _ =>
let nargs := e.getAppNumArgs
if c == ``Nat.succ && nargs == 1 then do
let (s, k) ← getOffsetAux a false
pure (s, k+1)
else if c == ``Nat.add && nargs == 2 then do
let v ← evalNat (e.getArg! 1)
let (s, k) ← getOffsetAux (e.getArg! 0) false
pure (s, k+v)
else if c == ``Add.add && nargs == 4 then do
let v ← evalNat (e.getArg! 3)
let (s, k) ← getOffsetAux (e.getArg! 2) false
pure (s, k+v)
else if c == ``HAdd.hAdd && nargs == 6 then do
let v ← evalNat (e.getArg! 5)
let (s, k) ← getOffsetAux (e.getArg! 4) false
pure (s, k+v)
else if top then failure else pure (e, 0)
| _ => if top then failure else pure (e, 0)
| e, top => if top then failure else pure (e, 0)
private def getOffset (e : Expr) : OptionT MetaM (Expr × Nat) :=
getOffsetAux e true
private partial def isOffset : Expr → OptionT MetaM (Expr × Nat)
| e@(Expr.app _ a _) =>
let f := e.getAppFn
match f with
| Expr.mvar .. => withInstantiatedMVars e isOffset
| Expr.const c _ _ =>
let nargs := e.getAppNumArgs
if (c == ``Nat.succ && nargs == 1) || (c == ``Nat.add && nargs == 2) || (c == ``Add.add && nargs == 4) || (c == ``HAdd.hAdd && nargs == 6) then
getOffset e
else
failure
| _ => failure
| _ => failure
private def isNatZero (e : Expr) : MetaM Bool := do
match (← evalNat e) with
| some v => v == 0
| _ => false
private def mkOffset (e : Expr) (offset : Nat) : MetaM Expr := do
if offset == 0 then
return e
else if (← isNatZero e) then
return mkNatLit offset
else
mkAdd e (mkNatLit offset)
def isDefEqOffset (s t : Expr) : MetaM LBool := do
let ifNatExpr (x : MetaM LBool) : MetaM LBool := do
let type ← inferType s
-- Remark: we use `withNewMCtxDepth` to make sure we don't assing metavariables when performing the `isDefEq` test
if (← withNewMCtxDepth <| Meta.isExprDefEqAux type (mkConst ``Nat)) then
x
else
return LBool.undef
let isDefEq (s t) : MetaM LBool :=
ifNatExpr <| toLBoolM <| Meta.isExprDefEqAux s t
if !(← getConfig).offsetCnstrs then
return LBool.undef
else
match (← isOffset s) with
| some (s, k₁) =>
match (← isOffset t) with
| some (t, k₂) => -- s+k₁ =?= t+k₂
if k₁ == k₂ then
isDefEq s t
else if k₁ < k₂ then
isDefEq s (← mkOffset t (k₂ - k₁))
else
isDefEq (← mkOffset s (k₁ - k₂)) t
| none =>
match (← evalNat t) with
| some v₂ => -- s+k₁ =?= v₂
if v₂ ≥ k₁ then
isDefEq s (mkNatLit <| v₂ - k₁)
else
ifNatExpr <| return LBool.false
| none =>
return LBool.undef
| none =>
match (← evalNat s) with
| some v₁ =>
match (← isOffset t) with
| some (t, k₂) => -- v₁ =?= t+k₂
if v₁ ≥ k₂ then
isDefEq (mkNatLit <| v₁ - k₂) t
else
ifNatExpr <| return LBool.false
| none =>
match (← evalNat t) with
| some v₂ => ifNatExpr <| return (v₁ == v₂).toLBool -- v₁ =?= v₂
| none => return LBool.undef
| none => return LBool.undef
end Lean.Meta
|
39cbf79e05f91f17ba07d3fe59a8ba85d6dadfb1 | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/logic/unnamed_2585.lean | e2444c527d1dc8f471f5096a3e08775379f1166f | [] | 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 | 179 | lean | import data.real.basic
-- BEGIN
variables {α : Type*} [linear_order α]
def converges_to (s : α → ℝ) (a : ℝ) :=
∀ ε > 0, ∃ N, ∀ n ≥ N, abs (s n - a) < ε
-- END |
ef8797d3b7c13136c2bce6768aec458bf2256d63 | d642a6b1261b2cbe691e53561ac777b924751b63 | /src/topology/algebra/ordered.lean | c9b63c6532799d067a44f185885f5faadd531947 | [
"Apache-2.0"
] | permissive | cipher1024/mathlib | fee56b9954e969721715e45fea8bcb95f9dc03fe | d077887141000fefa5a264e30fa57520e9f03522 | refs/heads/master | 1,651,806,490,504 | 1,573,508,694,000 | 1,573,508,694,000 | 107,216,176 | 0 | 0 | Apache-2.0 | 1,647,363,136,000 | 1,508,213,014,000 | Lean | UTF-8 | Lean | false | false | 44,656 | 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
Theory of ordered topology.
-/
import order.liminf_limsup
import data.set.intervals
import topology.algebra.group
import topology.constructions
open classical set lattice filter topological_space
local attribute [instance] classical.prop_decidable -- TODO: use "open_locale classical"
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- (Partially) ordered topology
Also called: partially ordered spaces (pospaces).
Usually ordered topology is used for a topology on linear ordered spaces, where the open intervals
are open sets. This is a generalization as for each linear order where open interals are open sets,
the order relation is closed. -/
class ordered_topology (α : Type*) [t : topological_space α] [preorder α] : Prop :=
(is_closed_le' : is_closed (λp:α×α, p.1 ≤ p.2))
instance {α : Type*} : Π [topological_space α], topological_space (order_dual α) := id
section ordered_topology
section preorder
variables [topological_space α] [preorder α] [t : ordered_topology α]
include t
lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_closed {b | f b ≤ g b} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ t.is_closed_le'
lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} :=
is_closed_le continuous_id continuous_const
lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} :=
is_closed_le continuous_const continuous_id
instance : ordered_topology (order_dual α) :=
⟨continuous_swap _ (@ordered_topology.is_closed_le' α _ _ _)⟩
lemma is_closed_Icc {a b : α} : is_closed (Icc a b) :=
is_closed_inter (is_closed_ge' a) (is_closed_le' b)
lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} (hb : b ≠ ⊥)
(hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) (h : {b | f b ≤ g b} ∈ b) :
a₁ ≤ a₂ :=
have tendsto (λb, (f b, g b)) b (nhds (a₁, a₂)),
by rw [nhds_prod_eq]; exact hf.prod_mk hg,
show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2},
from mem_of_closed_of_tendsto hb this t.is_closed_le' h
lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β}
(nt : x ≠ ⊥) (lim : tendsto f x (nhds a)) (h : f ⁻¹' {c | c ≤ b} ∈ x) : a ≤ b :=
le_of_tendsto_of_tendsto nt lim tendsto_const_nhds h
lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β}
(nt : x ≠ ⊥) (lim : tendsto f x (nhds a)) (h : f ⁻¹' {c | b ≤ c} ∈ x) : b ≤ a :=
le_of_tendsto_of_tendsto nt tendsto_const_nhds lim h
@[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
closure {b | f b ≤ g b} = {b | f b ≤ g b} :=
closure_eq_iff_is_closed.mpr $ is_closed_le hf hg
end preorder
section partial_order
variables [topological_space α] [partial_order α] [t : ordered_topology α]
include t
private lemma is_closed_eq : is_closed {p : α × α | p.1 = p.2} :=
by simp [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
instance ordered_topology.to_t2_space : t2_space α :=
{ t2 :=
have is_open {p : α × α | p.1 ≠ p.2}, from is_closed_eq,
assume a b h,
let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in
⟨u, v, hu, hv, ha, hb,
set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩,
have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩,
this rfl⟩ }
end partial_order
section linear_order
variables [topological_space α] [linear_order α] [t : ordered_topology α]
include t
lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_open {b | f b < g b} :=
by simp [lt_iff_not_ge, -not_le]; exact is_closed_le hg hf
lemma is_open_Ioo {a b : α} : is_open (Ioo a b) :=
is_open_and (is_open_lt continuous_const continuous_id) (is_open_lt continuous_id continuous_const)
lemma is_open_Iio {a : α} : is_open (Iio a) :=
is_open_lt continuous_id continuous_const
lemma is_open_Ioi {a : α} : is_open (Ioi a) :=
is_open_lt continuous_const continuous_id
end linear_order
section decidable_linear_order
variables [topological_space α] [decidable_linear_order α] [t : ordered_topology α] {f g : β → α}
include t
section
variables [topological_space β] (hf : continuous f) (hg : continuous g)
include hf hg
lemma frontier_le_subset_eq : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} :=
assume b ⟨hb₁, hb₂⟩,
le_antisymm
(by simpa [closure_le_eq hf hg] using hb₁)
(not_lt.1 $ assume hb : f b < g b,
have {b | f b < g b} ⊆ interior {b | f b ≤ g b},
from (subset_interior_iff_subset_of_open $ is_open_lt hf hg).mpr $ assume x, le_of_lt,
have b ∈ interior {b | f b ≤ g b}, from this hb,
by exact hb₂ this)
lemma frontier_lt_subset_eq : frontier {b | f b < g b} ⊆ {b | f b = g b} :=
by rw ← frontier_compl;
convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm]
lemma continuous_max : continuous (λb, max (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, g b = f b, from assume b hb, (frontier_le_subset_eq hf hg hb).symm,
continuous_if this hg hf
lemma continuous_min : continuous (λb, min (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb,
continuous_if this hf hg
end
lemma tendsto_max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, max (f b) (g b)) b (nhds (max a₁ a₂)) :=
show tendsto ((λp:α×α, max p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (max a₁ a₂)),
from tendsto.comp
begin
rw [←nhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_max continuous_fst continuous_snd) _
end
(hf.prod_mk hg)
lemma tendsto_min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, min (f b) (g b)) b (nhds (min a₁ a₂)) :=
show tendsto ((λp:α×α, min p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (min a₁ a₂)),
from tendsto.comp
begin
rw [←nhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_min continuous_fst continuous_snd) _
end
(hf.prod_mk hg)
end decidable_linear_order
end ordered_topology
/-- Topologies generated by the open intervals.
This is restricted to linear orders. Only then it is guaranteed that they are also a ordered
topology. -/
class orderable_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop :=
(topology_eq_generate_intervals :
t = generate_from {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}})
section orderable_topology
instance {α : Type*} [topological_space α] [partial_order α] [orderable_topology α] :
orderable_topology (order_dual α) :=
⟨by convert @orderable_topology.topology_eq_generate_intervals α _ _ _;
conv in (_ ∨ _) { rw or.comm }; refl⟩
section partial_order
variables [topological_space α] [partial_order α] [t : orderable_topology α]
include t
lemma is_open_iff_generate_intervals {s : set α} :
is_open s ↔ generate_open {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}} s :=
by rw [t.topology_eq_generate_intervals]; refl
lemma is_open_lt' (a : α) : is_open {b:α | a < b} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩
lemma is_open_gt' (a : α) : is_open {b:α | b < a} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩
lemma lt_mem_nhds {a b : α} (h : a < b) : {b | a < b} ∈ nhds b :=
mem_nhds_sets (is_open_lt' _) h
lemma le_mem_nhds {a b : α} (h : a < b) : {b | a ≤ b} ∈ nhds b :=
(nhds b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma gt_mem_nhds {a b : α} (h : a < b) : {a | a < b} ∈ nhds a :=
mem_nhds_sets (is_open_gt' _) h
lemma ge_mem_nhds {a b : α} (h : a < b) : {a | a ≤ b} ∈ nhds a :=
(nhds a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma nhds_eq_orderable {a : α} :
nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) :=
by rw [t.topology_eq_generate_intervals, nhds_generate_from];
from le_antisymm
(le_inf
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩)
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩))
(le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩,
match s, ha, hs with
| _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h
| _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h
end)
lemma tendsto_orderable {f : β → α} {a : α} {x : filter β} :
tendsto f x (nhds a) ↔ (∀a'<a, {b | a' < f b} ∈ x) ∧ (∀a'>a, {b | a' > f b} ∈ x) :=
by simp [@nhds_eq_orderable α _ _, tendsto_inf, tendsto_infi, tendsto_principal]
/-- Also known as squeeze or sandwich theorem. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α}
(hg : tendsto g b (nhds a)) (hh : tendsto h b (nhds a))
(hgf : {b | g b ≤ f b} ∈ b) (hfh : {b | f b ≤ h b} ∈ b) :
tendsto f b (nhds a) :=
tendsto_orderable.2
⟨assume a' h',
have {b : β | a' < g b} ∈ b, from (tendsto_orderable.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have {b : β | h b < a'} ∈ b, from (tendsto_orderable.1 hh).right a' h',
by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩
lemma nhds_orderable_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
nhds a = (⨅l (h₂ : l < a) u (h₂ : a < u), principal {x | l < x ∧ x < u }) :=
let ⟨u, hu⟩ := hu, ⟨l, hl⟩ := hl in
calc nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) : nhds_eq_orderable
... = (⨅b<a, principal {c | b < c} ⊓ (⨅b>a, principal {c | c < b})) :
binfi_inf hl
... = (⨅l<a, (⨅u>a, principal {c | c < u} ⊓ principal {c | l < c})) :
begin
congr, funext x,
congr, funext hx,
rw [inf_comm],
apply binfi_inf hu
end
... = _ : by simp [inter_comm]; refl
lemma tendsto_orderable_unbounded {f : β → α} {a : α} {x : filter β}
(hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → {b | l < f b ∧ f b < u } ∈ x) :
tendsto f x (nhds a) :=
by rw [nhds_orderable_unbounded hu hl];
from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl,
tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu)
end partial_order
theorem induced_orderable_topology' {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b)
(H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) :
@orderable_topology _ (induced f ta) _ :=
begin
letI := induced f ta,
refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩,
rw [nhds_induced, nhds_generate_from, @nhds_eq_orderable β _ _],
apply le_antisymm,
{ refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _),
rcases hs with ⟨ab, b, rfl|rfl⟩,
{ exact mem_comap_sets.2 ⟨{x | f b < x},
mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ },
{ exact mem_comap_sets.2 ⟨{x | x < f b},
mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ } },
{ rw [← map_le_iff_le_comap],
refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp,
{ rcases H₁ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) },
{ rcases H₂ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } },
end
theorem induced_orderable_topology {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) :
@orderable_topology _ (induced f ta) _ :=
induced_orderable_topology' f @hf
(λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩)
(λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩)
lemma nhds_top_orderable [topological_space α] [order_top α] [orderable_topology α] :
nhds (⊤:α) = (⨅l (h₂ : l < ⊤), principal {x | l < x}) :=
by rw [@nhds_eq_orderable α _ _]; simp [(>)]
lemma nhds_bot_orderable [topological_space α] [order_bot α] [orderable_topology α] :
nhds (⊥:α) = (⨅l (h₂ : ⊥ < l), principal {x | x < l}) :=
by rw [@nhds_eq_orderable α _ _]; simp
section linear_order
variables [topological_space α] [linear_order α] [t : orderable_topology α]
include t
lemma mem_nhds_orderable_dest {a : α} {s : set α} (hs : s ∈ nhds a) :
((∃u, u>a) → ∃u, a < u ∧ ∀b, a ≤ b → b < u → b ∈ s) ∧
((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ≤ a → b ∈ s) :=
let ⟨t₁, ht₁, t₂, ht₂, hts⟩ :=
mem_inf_sets.mp $ by rw [@nhds_eq_orderable α _ _ _] at hs; exact hs in
have ht₁ : ((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ∈ t₁) ∧ (∀b, a ≤ b → b ∈ t₁),
from infi_sets_induct ht₁
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' < a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨max u a', max_lt hu₁ h, assume b hb,
⟨hs₁ $ lt_of_le_of_lt (le_max_right _ _) hb,
hu₂ _ $ lt_of_le_of_lt (le_max_left _ _) hb⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_lt_of_le h hb, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
have ht₂ : ((∃u, u>a) → ∃u, a < u ∧ ∀b, b < u → b ∈ t₂) ∧ (∀b, b ≤ a → b ∈ t₂),
from infi_sets_induct ht₂
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' > a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨min u a', lt_min hu₁ h, assume b hb,
⟨hs₁ $ lt_of_lt_of_le hb (min_le_right _ _),
hu₂ _ $ lt_of_lt_of_le hb (min_le_left _ _)⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_le_of_lt hb h, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
and.intro
(assume hx, let ⟨u, hu, h⟩ := ht₂.left hx in ⟨u, hu, assume b hb hbu, hts ⟨ht₁.right b hb, h _ hbu⟩⟩)
(assume hx, let ⟨l, hl, h⟩ := ht₁.left hx in ⟨l, hl, assume b hbl hb, hts ⟨h _ hbl, ht₂.right b hb⟩⟩)
lemma mem_nhds_unbounded {a : α} {s : set α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
s ∈ nhds a ↔ (∃l u, l < a ∧ a < u ∧ ∀b, l < b → b < u → b ∈ s) :=
let ⟨l, hl'⟩ := hl, ⟨u, hu'⟩ := hu in
have nhds a = (⨅p : {l // l < a} × {u // a < u}, principal {x | p.1.val < x ∧ x < p.2.val }),
by simp [nhds_orderable_unbounded hu hl, infi_subtype, infi_prod],
iff.intro
(assume hs, by rw [this] at hs; from infi_sets_induct hs
⟨l, u, hl', hu', by simp⟩
begin
intro p, rcases p with ⟨⟨l, hl⟩, ⟨u, hu⟩⟩,
simp [set.subset_def],
intros s₁ s₂ hs₁ l' hl' u' hu' hs₂,
letI := classical.DLO α,
refine ⟨max l l', _, min u u', _⟩;
simp [*, lt_min_iff, max_lt_iff] {contextual := tt}
end
(assume s₁ s₂ h ⟨l, u, h₁, h₂, h₃⟩, ⟨l, u, h₁, h₂, assume b hu hl, h $ h₃ _ hu hl⟩))
(assume ⟨l, u, hl, hu, h⟩,
by rw [this]; exact mem_infi_sets ⟨⟨l, hl⟩, ⟨u, hu⟩⟩ (assume b ⟨h₁, h₂⟩, h b h₁ h₂))
lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) :
∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) :=
match dense_or_discrete a₁ a₂ with
| or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂,
assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h,
assume b₁ hb₁ b₂ hb₂,
calc b₁ ≤ a₁ : h₂ _ hb₁
... < a₂ : h
... ≤ b₂ : h₁ _ hb₂⟩
end
instance orderable_topology.to_ordered_topology : ordered_topology α :=
{ is_closed_le' :=
is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂),
have h : a₂ < a₁, from lt_of_not_ge h,
let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in
⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ }
instance orderable_topology.t2_space : t2_space α := by apply_instance
instance orderable_topology.regular_space : regular_space α :=
{ regular := assume s a hs ha,
have -s ∈ nhds a, from mem_nhds_sets hs ha,
let ⟨h₁, h₂⟩ := mem_nhds_orderable_dest this in
have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃l, l < a,
let ⟨l, hl, h⟩ := h₂ h in
match dense_or_discrete l a with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _,
assume c hcs hca, show c < b,
from lt_of_not_ge $ assume hbc, h c (lt_of_lt_of_le hb₁ hbc) (le_of_lt hca) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hb₂) $
assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $
assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩
end)
(assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in
have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃u, u > a,
let ⟨u, hu, h⟩ := h₁ h in
match dense_or_discrete a u with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _,
assume c hcs hca, show c > b,
from lt_of_not_ge $ assume hbc, h c (le_of_lt hca) (lt_of_le_of_lt hbc hb₂) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hb₁) $
assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $
assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩
end)
(assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in
⟨t₁ ∪ t₂, is_open_union ht₁o ht₂o,
assume x hx,
have x ≠ a, from assume eq, ha $ eq ▸ hx,
(ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx),
by rw [←sup_principal, inf_sup_left, ht₁a, ht₂a, bot_sup_eq]⟩,
..orderable_topology.t2_space }
end linear_order
lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) :=
(image_eq_preimage_of_inverse neg_neg neg_neg).symm
lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) :=
funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg)
section topological_add_group
variables [topological_space α] [ordered_comm_group α] [topological_add_group α]
lemma neg_preimage_closure {s : set α} : (λr:α, -r) ⁻¹' closure s = closure ((λr:α, -r) '' s) :=
have (λr:α, -r) ∘ (λr:α, -r) = id, from funext neg_neg,
by rw [preimage_neg]; exact
(subset.antisymm (image_closure_subset_closure_image continuous_neg') $
calc closure ((λ (r : α), -r) '' s) = (λr, -r) '' ((λr, -r) '' closure ((λ (r : α), -r) '' s)) :
by rw [←image_comp, this, image_id]
... ⊆ (λr, -r) '' closure ((λr, -r) '' ((λ (r : α), -r) '' s)) :
mono_image $ image_closure_subset_closure_image continuous_neg'
... = _ : by rw [←image_comp, this, image_id])
end topological_add_group
section order_topology
variables [topological_space α] [topological_space β]
[linear_order α] [linear_order β] [orderable_topology α] [orderable_topology β]
lemma nhds_principal_ne_bot_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) :
nhds a ⊓ principal s ≠ ⊥ :=
let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in
forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht,
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in
let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in
by_cases
(assume h : a = a',
have a ∈ t₁, from mem_of_nhds ht₁,
have a ∈ t₂, from ht₂ $ by rwa [h],
ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩)
(assume : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this.symm,
let ⟨l, hl, hlt₁⟩ := hl ⟨a', this⟩ in
have ∃a'∈s, l < a',
from classical.by_contradiction $ assume : ¬ ∃a'∈s, l < a',
have ∀a'∈s, a' ≤ l, from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩,
have ¬ l < a, from not_lt.2 $ ha.right _ this,
this ‹l < a›,
let ⟨a', ha', ha'l⟩ := this in
have a' ∈ t₁, from hlt₁ _ ‹l < a'› $ ha.left _ ha',
ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩)
lemma nhds_principal_ne_bot_of_is_glb : ∀ {a : α} {s : set α}, is_glb s a → s ≠ ∅ →
nhds a ⊓ principal s ≠ ⊥ :=
@nhds_principal_ne_bot_of_is_lub (order_dual α) _ _ _
lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α}
(hsa : a ∈ upper_bounds s) (hsf : s ∈ f) (hfa : f ⊓ nhds a ≠ ⊥) : is_lub s a :=
⟨hsa, assume b hb,
not_lt.1 $ assume hba,
have s ∩ {a | b < a} ∈ f ⊓ nhds a,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in
have b < b, from lt_of_lt_of_le hxb $ hb _ hxs,
lt_irrefl b this⟩
lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α},
a ∈ lower_bounds s → s ∈ f → f ⊓ nhds a ≠ ⊥ → is_glb s a :=
@is_lub_of_mem_nhds (order_dual α) _ _ _
lemma is_lub_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s ≠ ∅)
(hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_lub (f '' s) b :=
have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs,
have ∀a'∈s, ¬ b < f a',
from assume a' ha' h,
have {x | x < f a'} ∈ nhds b, from mem_nhds_sets (is_open_gt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a < f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm,
have {x | a' < x} ∈ nhds a, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} ∩ t₁ ∈ nhds a, from inter_mem_sets this ht₁,
have ({x | a' < x} ∩ t₁) ∩ s ∈ nhds a ⊓ principal s,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in
have hxa' : f x < f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≤ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁,
lt_irrefl _ (lt_of_le_of_lt ha'x hxa')),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot hb $
mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx)
lemma is_glb_of_is_glb_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ f s a b
(λ x hx y hy, hf y hy x hx)
lemma is_glb_of_is_lub_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma is_lub_of_is_glb_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s ≠ ∅ →
tendsto f (nhds a ⊓ principal s) (nhds b) → is_lub (f '' s) b :=
@is_glb_of_is_glb_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma mem_closure_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) : a ∈ closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_lub ha hs
lemma mem_of_is_lub_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) (sc : is_closed s) : a ∈ s :=
by rw ←closure_eq_of_is_closed sc; exact mem_closure_of_is_lub ha hs
lemma mem_closure_of_is_glb {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) : a ∈ closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_glb ha hs
lemma mem_of_is_glb_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) (sc : is_closed s) : a ∈ s :=
by rw ←closure_eq_of_is_closed sc; exact mem_closure_of_is_glb ha hs
/-- A compact set is bounded below -/
lemma bdd_below_of_compact {α : Type u} [topological_space α] [linear_order α]
[ordered_topology α] [nonempty α] {s : set α} (hs : compact s) : bdd_below s :=
begin
by_contra H,
letI := classical.DLO α,
rcases @compact_elim_finite_subcover_image α _ _ _ s (λ x, {b | x < b}) hs
(λ x _, is_open_lt continuous_const continuous_id) _ with ⟨t, st, ft, ht⟩,
{ refine H ((bdd_below_finite ft).imp $ λ C hC y hy, _),
rcases mem_bUnion_iff.1 (ht hy) with ⟨x, hx, xy⟩,
exact le_trans (hC _ hx) (le_of_lt xy) },
{ refine λ x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H),
exact λ h, ⟨x, λ y hy, le_of_not_lt (h.imp $ λ ys, ⟨_, hy, ys⟩)⟩ }
end
/-- A compact set is bounded above -/
lemma bdd_above_of_compact {α : Type u} [topological_space α] [linear_order α]
[orderable_topology α] : Π [nonempty α] {s : set α}, compact s → bdd_above s :=
@bdd_below_of_compact (order_dual α) _ _ _
end order_topology
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [orderable_topology α]
[complete_linear_order β] [topological_space β] [orderable_topology β] [nonempty γ]
lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) : Sup s ∈ closure s :=
mem_closure_of_is_lub is_lub_Sup hs
lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) : Inf s ∈ closure s :=
mem_closure_of_is_glb is_glb_Inf hs
lemma Sup_mem_of_is_closed {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) : Sup s ∈ s :=
mem_of_is_lub_of_is_closed is_lub_Sup hs hc
lemma Inf_mem_of_is_closed {α : Type u} [topological_space α] [complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) : Inf s ∈ s :=
mem_of_is_glb_of_is_closed is_glb_Inf hs hc
/-- A continuous monotone function sends supremum to supremum for nonempty sets. -/
lemma Sup_of_continuous' {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (hs : s ≠ ∅) : f (Sup s) = Sup (f '' s) :=
--This is a particular case of the more general is_lub_of_is_lub_of_tendsto
(is_lub_iff_Sup_eq.1
(is_lub_of_is_lub_of_tendsto (λ x hx y hy xy, Cf xy) is_lub_Sup hs $
tendsto_le_left inf_le_left (continuous.tendsto Mf _))).symm
/-- A continuous monotone function sending bot to bot sends supremum to supremum. -/
lemma Sup_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
(fbot : f ⊥ = ⊥) {s : set α} : f (Sup s) = Sup (f '' s) :=
begin
by_cases (s = ∅),
{ simpa [h] },
{ exact Sup_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed supremum to indexed supremum. -/
lemma supr_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) : f (supr g) = supr (f ∘ g) :=
by rw [supr, Sup_of_continuous' Mf Cf
(λ h, range_eq_empty.1 h ‹_›), ← range_comp]; refl
/-- A continuous monotone function sends infimum to infimum for nonempty sets. -/
lemma Inf_of_continuous' {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (hs : s ≠ ∅) : f (Inf s) = Inf (f '' s) :=
(is_glb_iff_Inf_eq.1
(is_glb_of_is_glb_of_tendsto (λ x hx y hy xy, Cf xy) is_glb_Inf hs $
tendsto_le_left inf_le_left (continuous.tendsto Mf _))).symm
/-- A continuous monotone function sending top to top sends infimum to infimum. -/
lemma Inf_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
(ftop : f ⊤ = ⊤) {s : set α} : f (Inf s) = Inf (f '' s) :=
begin
by_cases (s = ∅),
{ simpa [h] },
{ exact Inf_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed infimum to indexed infimum. -/
lemma infi_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) : f (infi g) = infi (f ∘ g) :=
by rw [infi, Inf_of_continuous' Mf Cf
(λ h, range_eq_empty.1 h ‹_›), ← range_comp]; refl
end complete_linear_order
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [topological_space α] [orderable_topology α]
[conditionally_complete_linear_order β] [topological_space β] [orderable_topology β] [nonempty γ]
lemma cSup_mem_closure {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (B : bdd_above s) : Sup s ∈ closure s :=
mem_closure_of_is_lub (is_lub_cSup hs B) hs
lemma cInf_mem_closure {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (B : bdd_below s) : Inf s ∈ closure s :=
mem_closure_of_is_glb (is_glb_cInf hs B) hs
lemma cSup_mem_of_is_closed {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) (B : bdd_above s) : Sup s ∈ s :=
mem_of_is_lub_of_is_closed (is_lub_cSup hs B) hs hc
lemma cInf_mem_of_is_closed {α : Type u} [topological_space α] [conditionally_complete_linear_order α] [orderable_topology α]
{s : set α} (hs : s ≠ ∅) (hc : is_closed s) (B : bdd_below s) : Inf s ∈ s :=
mem_of_is_glb_of_is_closed (is_glb_cInf hs B) hs hc
/-- A continuous monotone function sends supremum to supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cSup_of_cSup_of_monotone_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (ne : s ≠ ∅) (H : bdd_above s) : f (Sup s) = Sup (f '' s) :=
begin
refine (is_lub_iff_eq_of_is_lub _).1
(is_lub_cSup (mt image_eq_empty.1 ne) (bdd_above_of_bdd_above_of_monotone Cf H)),
refine is_lub_of_is_lub_of_tendsto (λx hx y hy xy, Cf xy) (is_lub_cSup ne H) ne _,
exact tendsto_le_left inf_le_left (continuous.tendsto Mf _)
end
/-- A continuous monotone function sends indexed supremum to indexed supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma csupr_of_csupr_of_monotone_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) (H : bdd_above (range g)) : f (supr g) = supr (f ∘ g) :=
by rw [supr, cSup_of_cSup_of_monotone_of_continuous Mf Cf
(λ h, range_eq_empty.1 h ‹_›) H, ← range_comp]; refl
/-- A continuous monotone function sends infimum to infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cInf_of_cInf_of_monotone_of_continuous {f : α → β} (Mf : continuous f) (Cf : monotone f)
{s : set α} (ne : s ≠ ∅) (H : bdd_below s) : f (Inf s) = Inf (f '' s) :=
begin
refine (is_glb_iff_eq_of_is_glb _).1
(is_glb_cInf (mt image_eq_empty.1 ne) (bdd_below_of_bdd_below_of_monotone Cf H)),
refine is_glb_of_is_glb_of_tendsto (λx hx y hy xy, Cf xy) (is_glb_cInf ne H) ne _,
exact tendsto_le_left inf_le_left (continuous.tendsto Mf _)
end
/-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cinfi_of_cinfi_of_monotone_of_continuous {f : α → β} {g : γ → α}
(Mf : continuous f) (Cf : monotone f) (H : bdd_below (range g)) : f (infi g) = infi (f ∘ g) :=
by rw [infi, cInf_of_cInf_of_monotone_of_continuous Mf Cf
(λ h, range_eq_empty.1 h ‹_›) H, ← range_comp]; refl
/-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/
lemma exists_forall_le_of_compact_of_continuous {α : Type u} [topological_space α]
(f : α → β) (hf : continuous f) (s : set α) (hs : compact s) (ne_s : s ≠ ∅) :
∃x∈s, ∀y∈s, f x ≤ f y :=
begin
have C : compact (f '' s) := compact_image hs hf,
haveI := has_Inf_to_nonempty β,
have B : bdd_below (f '' s) := bdd_below_of_compact C,
have : Inf (f '' s) ∈ f '' s :=
cInf_mem_of_is_closed (mt image_eq_empty.1 ne_s) (closed_of_compact _ C) B,
rcases (mem_image _ _ _).1 this with ⟨x, xs, hx⟩,
exact ⟨x, xs, λ y hy, hx.symm ▸ cInf_le B ⟨_, hy, rfl⟩⟩
end
/-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/
lemma exists_forall_ge_of_compact_of_continuous {α : Type u} [topological_space α] :
∀ f : α → β, continuous f → ∀ s : set α, compact s → s ≠ ∅ →
∃x∈s, ∀y∈s, f y ≤ f x :=
@exists_forall_le_of_compact_of_continuous (order_dual β) _ _ _ _ _
end conditionally_complete_linear_order
section liminf_limsup
section ordered_topology
variables [semilattice_sup α] [topological_space α] [orderable_topology α]
lemma is_bounded_le_nhds (a : α) : (nhds a).is_bounded (≤) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := ⟨a, show {x : α | x ≤ a} ∈ nhds a, from univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩
end
lemma is_bounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≤) u :=
is_bounded_of_le h (is_bounded_le_nhds a)
lemma is_cobounded_ge_nhds (a : α) : (nhds a).is_cobounded (≥) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_le_nhds a)
lemma is_cobounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≥) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_le_of_tendsto h)
end ordered_topology
section ordered_topology
variables [semilattice_inf α] [topological_space α] [orderable_topology α]
lemma is_bounded_ge_nhds (a : α) : (nhds a).is_bounded (≥) :=
match forall_le_or_exists_lt_inf a with
| or.inl h := ⟨a, show {x : α | a ≤ x} ∈ nhds a, from univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, le_mem_nhds hb⟩
end
lemma is_bounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≥) u :=
is_bounded_of_le h (is_bounded_ge_nhds a)
lemma is_cobounded_le_nhds (a : α) : (nhds a).is_cobounded (≤) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_ge_nhds a)
lemma is_cobounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≤) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_ge_of_tendsto h)
end ordered_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α]
theorem lt_mem_sets_of_Limsup_lt {f : filter α} {b} (h : f.is_bounded (≤)) (l : f.Limsup < b) :
{a | a < b} ∈ f :=
let ⟨c, (h : {a : α | a ≤ c} ∈ f), hcb⟩ :=
exists_lt_of_cInf_lt (ne_empty_iff_exists_mem.2 h) l in
mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
theorem gt_mem_sets_of_Liminf_gt : ∀ {f : filter α} {b}, f.is_bounded (≥) → f.Liminf > b →
{a | a > b} ∈ f :=
@lt_mem_sets_of_Limsup_lt (order_dual α) _
variables [topological_space α] [orderable_topology α]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_Limsup_eq_Liminf {f : filter α} {a : α}
(hl : f.is_bounded (≤)) (hg : f.is_bounded (≥)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f ≤ nhds a :=
tendsto_orderable.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm ▸ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm ▸ hb)
theorem Limsup_nhds (a : α) : Limsup (nhds a) = a :=
cInf_intro (ne_empty_iff_exists_mem.2 $ is_bounded_le_nhds a)
(assume a' (h : {n : α | n ≤ a'} ∈ nhds a), show a ≤ a', from @mem_of_nhds α _ a _ h)
(assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ nhds a), c < b, from
match dense_or_discrete a b with
| or.inl ⟨c, hac, hcb⟩ := ⟨c, ge_mem_nhds hac, hcb⟩
| or.inr ⟨_, h⟩ := ⟨a, (nhds a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
end)
theorem Liminf_nhds : ∀ (a : α), Liminf (nhds a) = a :=
@Limsup_nhds (order_dual α) _ _ _
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Liminf = a :=
have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a),
have hb_le : is_bounded (≤) f, from is_bounded_of_le h (is_bounded_le_nhds a),
le_antisymm
(calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hf hb_le hb_ge
... ≤ (nhds a).Limsup :
Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (nhds a).Liminf : (Liminf_nhds a).symm
... ≤ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) (is_cobounded_of_is_bounded hf hb_le))
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : ∀ {f : filter α} {a : α}, f ≠ ⊥ → f ≤ nhds a → f.Limsup = a :=
@Liminf_eq_of_le_nhds (order_dual α) _ _ _
end conditionally_complete_linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [orderable_topology α]
-- In complete_linear_order, the above theorems take a simpler form
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value -/
theorem tendsto_of_liminf_eq_limsup {f : filter β} {u : β → α} {a : α}
(h : liminf f u = a ∧ limsup f u = a) : tendsto u f (nhds a) :=
le_nhds_of_Limsup_eq_Liminf is_bounded_le_of_top is_bounded_ge_of_bot h.2 h.1
/-- If a function has a limit, then its limsup coincides with its limit-/
theorem limsup_eq_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥)
(h : tendsto u f (nhds a)) : limsup f u = a :=
Limsup_eq_of_le_nhds (map_ne_bot hf) h
/-- If a function has a limit, then its liminf coincides with its limit-/
theorem liminf_eq_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥)
(h : tendsto u f (nhds a)) : liminf f u = a :=
Liminf_eq_of_le_nhds (map_ne_bot hf) h
end complete_linear_order
end liminf_limsup
end orderable_topology
lemma orderable_topology_of_nhds_abs
{α : Type*} [decidable_linear_ordered_comm_group α] [topological_space α]
(h_nhds : ∀a:α, nhds a = (⨅r>0, principal {b | abs (a - b) < r})) : orderable_topology α :=
orderable_topology.mk $ eq_of_nhds_eq_nhds $ assume a:α, le_antisymm_iff.mpr
begin
simp [infi_and, topological_space.nhds_generate_from,
h_nhds, le_infi_iff, -le_principal_iff, and_comm],
refine ⟨λ s ha b hs, _, λ r hr, _⟩,
{ rcases hs with rfl | rfl,
{ refine infi_le_of_le (a - b)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _),
have : a - c < a - b := lt_of_le_of_lt (le_abs_self _) hc,
exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) },
{ refine infi_le_of_le (b - a)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _),
have : abs (c - a) < b - a, {rw abs_sub; simpa using hc},
have : c - a < b - a := lt_of_le_of_lt (le_abs_self _) this,
exact lt_of_add_lt_add_right this } },
{ have h : {b | abs (a + -b) < r} = {b | a - r < b} ∩ {b | b < a + r},
from set.ext (assume b,
by simp [abs_lt, -sub_eq_add_neg, (sub_eq_add_neg _ _).symm,
sub_lt, lt_sub_iff_add_lt, and_comm, sub_lt_iff_lt_add']),
rw [h, ← inf_principal],
apply le_inf _ _,
{ exact infi_le_of_le {b : α | a - r < b} (infi_le_of_le (sub_lt_self a hr) $
infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) },
{ exact infi_le_of_le {b : α | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $
infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } }
end
lemma tendsto_at_top_supr_nat [topological_space α] [complete_linear_order α] [orderable_topology α]
(f : ℕ → α) (hf : monotone f) : tendsto f at_top (nhds (⨆i, f i)) :=
tendsto_orderable.2 $ and.intro
(assume a ha, let ⟨n, hn⟩ := lt_supr_iff.1 ha in
mem_at_top_sets.2 ⟨n, assume i hi, lt_of_lt_of_le hn (hf hi)⟩)
(assume a ha, univ_mem_sets' (assume n, lt_of_le_of_lt (le_supr _ n) ha))
lemma tendsto_at_top_infi_nat [topological_space α] [complete_linear_order α] [orderable_topology α]
(f : ℕ → α) (hf : ∀{n m}, n ≤ m → f m ≤ f n) : tendsto f at_top (nhds (⨅i, f i)) :=
@tendsto_at_top_supr_nat (order_dual α) _ _ _ _ @hf
lemma supr_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [orderable_topology α]
{f : ℕ → α} {a : α} (hf : monotone f) : tendsto f at_top (nhds a) → supr f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_supr_nat f hf)
lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [orderable_topology α]
{f : ℕ → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) : tendsto f at_top (nhds a) → infi f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_infi_nat f hf)
|
b55675ffc07592626df0c737e824d9431fda57b8 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/category/CommRing/basic.lean | 5c492d42ff2c27c4365dcf5d88550c95a1948169 | [
"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 | 8,886 | 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, Yury Kudryashov
-/
import algebra.category.Group.basic
import data.equiv.ring
/-!
# Category instances for semiring, ring, comm_semiring, and comm_ring.
We introduce the bundled categories:
* `SemiRing`
* `Ring`
* `CommSemiRing`
* `CommRing`
along with the relevant forgetful functors between them.
-/
universes u v
open category_theory
/-- The category of semirings. -/
def SemiRing : Type (u+1) := bundled semiring
namespace SemiRing
/-- `ring_hom` doesn't actually assume associativity. This alias is needed to make the category
theory machinery work. We use the same trick in `category_theory.Mon.assoc_monoid_hom`. -/
abbreviation assoc_ring_hom (M N : Type*) [semiring M] [semiring N] := ring_hom M N
instance bundled_hom : bundled_hom assoc_ring_hom :=
⟨λ M N [semiring M] [semiring N], by exactI @ring_hom.to_fun M N _ _,
λ M [semiring M], by exactI @ring_hom.id M _,
λ M N P [semiring M] [semiring N] [semiring P], by exactI @ring_hom.comp M N P _ _ _,
λ M N [semiring M] [semiring N], by exactI @ring_hom.coe_inj M N _ _⟩
attribute [derive [large_category, concrete_category]] SemiRing
instance : has_coe_to_sort SemiRing Type* := bundled.has_coe_to_sort
/-- Construct a bundled SemiRing from the underlying type and typeclass. -/
def of (R : Type u) [semiring R] : SemiRing := bundled.of R
/-- Typecheck a `ring_hom` as a morphism in `SemiRing`. -/
def of_hom {R S : Type u} [semiring R] [semiring S] (f : R →+* S) : of R ⟶ of S := f
instance : inhabited SemiRing := ⟨of punit⟩
instance (R : SemiRing) : semiring R := R.str
@[simp] lemma coe_of (R : Type u) [semiring R] : (SemiRing.of R : Type u) = R := rfl
instance has_forget_to_Mon : has_forget₂ SemiRing Mon :=
bundled_hom.mk_has_forget₂
(λ R hR, @monoid_with_zero.to_monoid R (@semiring.to_monoid_with_zero R hR))
(λ R₁ R₂, ring_hom.to_monoid_hom) (λ _ _ _, rfl)
instance has_forget_to_AddCommMon : has_forget₂ SemiRing AddCommMon :=
-- can't use bundled_hom.mk_has_forget₂, since AddCommMon is an induced category
{ forget₂ :=
{ obj := λ R, AddCommMon.of R,
map := λ R₁ R₂ f, ring_hom.to_add_monoid_hom f } }
end SemiRing
/-- The category of rings. -/
def Ring : Type (u+1) := bundled ring
namespace Ring
instance : bundled_hom.parent_projection @ring.to_semiring := ⟨⟩
attribute [derive [(λ Ring, has_coe_to_sort Ring Type*), large_category, concrete_category]] Ring
/-- Construct a bundled Ring from the underlying type and typeclass. -/
def of (R : Type u) [ring R] : Ring := bundled.of R
/-- Typecheck a `ring_hom` as a morphism in `Ring`. -/
def of_hom {R S : Type u} [ring R] [ring S] (f : R →+* S) : of R ⟶ of S := f
instance : inhabited Ring := ⟨of punit⟩
instance (R : Ring) : ring R := R.str
@[simp] lemma coe_of (R : Type u) [ring R] : (Ring.of R : Type u) = R := rfl
instance has_forget_to_SemiRing : has_forget₂ Ring SemiRing := bundled_hom.forget₂ _ _
instance has_forget_to_AddCommGroup : has_forget₂ Ring AddCommGroup :=
-- can't use bundled_hom.mk_has_forget₂, since AddCommGroup is an induced category
{ forget₂ :=
{ obj := λ R, AddCommGroup.of R,
map := λ R₁ R₂ f, ring_hom.to_add_monoid_hom f } }
end Ring
/-- The category of commutative semirings. -/
def CommSemiRing : Type (u+1) := bundled comm_semiring
namespace CommSemiRing
instance : bundled_hom.parent_projection @comm_semiring.to_semiring := ⟨⟩
attribute [derive [large_category, concrete_category]] CommSemiRing
instance : has_coe_to_sort CommSemiRing Type* := bundled.has_coe_to_sort
/-- Construct a bundled CommSemiRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_semiring R] : CommSemiRing := bundled.of R
/-- Typecheck a `ring_hom` as a morphism in `CommSemiRing`. -/
def of_hom {R S : Type u} [comm_semiring R] [comm_semiring S] (f : R →+* S) : of R ⟶ of S := f
instance : inhabited CommSemiRing := ⟨of punit⟩
instance (R : CommSemiRing) : comm_semiring R := R.str
@[simp] lemma coe_of (R : Type u) [comm_semiring R] : (CommSemiRing.of R : Type u) = R := rfl
instance has_forget_to_SemiRing : has_forget₂ CommSemiRing SemiRing := bundled_hom.forget₂ _ _
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance has_forget_to_CommMon : has_forget₂ CommSemiRing CommMon :=
has_forget₂.mk'
(λ R : CommSemiRing, CommMon.of R) (λ R, rfl)
(λ R₁ R₂ f, f.to_monoid_hom) (by tidy)
end CommSemiRing
/-- The category of commutative rings. -/
def CommRing : Type (u+1) := bundled comm_ring
namespace CommRing
instance : bundled_hom.parent_projection @comm_ring.to_ring := ⟨⟩
attribute [derive [large_category, concrete_category]] CommRing
instance : has_coe_to_sort CommRing Type* := bundled.has_coe_to_sort
/-- Construct a bundled CommRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_ring R] : CommRing := bundled.of R
/-- Typecheck a `ring_hom` as a morphism in `CommRing`. -/
def of_hom {R S : Type u} [comm_ring R] [comm_ring S] (f : R →+* S) : of R ⟶ of S := f
instance : inhabited CommRing := ⟨of punit⟩
instance (R : CommRing) : comm_ring R := R.str
@[simp] lemma coe_of (R : Type u) [comm_ring R] : (CommRing.of R : Type u) = R := rfl
instance has_forget_to_Ring : has_forget₂ CommRing Ring := bundled_hom.forget₂ _ _
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance has_forget_to_CommSemiRing : has_forget₂ CommRing CommSemiRing :=
has_forget₂.mk' (λ R : CommRing, CommSemiRing.of R) (λ R, rfl) (λ R₁ R₂ f, f) (by tidy)
instance : full (forget₂ CommRing CommSemiRing) :=
{ preimage := λ X Y f, f, }
end CommRing
-- This example verifies an improvement possible in Lean 3.8.
-- Before that, to have `add_ring_hom.map_zero` usable by `simp` here,
-- we had to mark all the concrete category `has_coe_to_sort` instances reducible.
-- Now, it just works.
example {R S : CommRing} (i : R ⟶ S) (r : R) (h : r = 0) : i r = 0 :=
by simp [h]
namespace ring_equiv
variables {X Y : Type u}
/-- Build an isomorphism in the category `Ring` from a `ring_equiv` between `ring`s. -/
@[simps] def to_Ring_iso [ring X] [ring Y] (e : X ≃+* Y) : Ring.of X ≅ Ring.of Y :=
{ hom := e.to_ring_hom,
inv := e.symm.to_ring_hom }
/-- Build an isomorphism in the category `CommRing` from a `ring_equiv` between `comm_ring`s. -/
@[simps] def to_CommRing_iso [comm_ring X] [comm_ring Y] (e : X ≃+* Y) :
CommRing.of X ≅ CommRing.of Y :=
{ hom := e.to_ring_hom,
inv := e.symm.to_ring_hom }
end ring_equiv
namespace category_theory.iso
/-- Build a `ring_equiv` from an isomorphism in the category `Ring`. -/
def Ring_iso_to_ring_equiv {X Y : Ring} (i : X ≅ Y) : X ≃+* Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := by tidy,
right_inv := by tidy,
map_add' := by tidy,
map_mul' := by tidy }.
/-- Build a `ring_equiv` from an isomorphism in the category `CommRing`. -/
def CommRing_iso_to_ring_equiv {X Y : CommRing} (i : X ≅ Y) : X ≃+* Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := by tidy,
right_inv := by tidy,
map_add' := by tidy,
map_mul' := by tidy }.
end category_theory.iso
/-- Ring equivalences between `ring`s are the same as (isomorphic to) isomorphisms in `Ring`. -/
def ring_equiv_iso_Ring_iso {X Y : Type u} [ring X] [ring Y] :
(X ≃+* Y) ≅ (Ring.of X ≅ Ring.of Y) :=
{ hom := λ e, e.to_Ring_iso,
inv := λ i, i.Ring_iso_to_ring_equiv, }
/-- Ring equivalences between `comm_ring`s are the same as (isomorphic to) isomorphisms
in `CommRing`. -/
def ring_equiv_iso_CommRing_iso {X Y : Type u} [comm_ring X] [comm_ring Y] :
(X ≃+* Y) ≅ (CommRing.of X ≅ CommRing.of Y) :=
{ hom := λ e, e.to_CommRing_iso,
inv := λ i, i.CommRing_iso_to_ring_equiv, }
instance Ring.forget_reflects_isos : reflects_isomorphisms (forget Ring.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget Ring).map f),
let e : X ≃+* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_Ring_iso).1⟩,
end }
instance CommRing.forget_reflects_isos : reflects_isomorphisms (forget CommRing.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget CommRing).map f),
let e : X ≃+* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_CommRing_iso).1⟩,
end }
-- It would be nice if we could have the following,
-- but it requires making `reflects_isomorphisms_forget₂` an instance,
-- which can cause typeclass loops:
local attribute [priority 50,instance] reflects_isomorphisms_forget₂
example : reflects_isomorphisms (forget₂ Ring AddCommGroup) := by apply_instance
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.